added supprt of initalize controllers

This commit is contained in:
Andrei Yankovich 2021-06-15 16:04:18 +03:00
parent db42acdb70
commit ad221f815d
6 changed files with 51 additions and 2 deletions

View File

@ -108,6 +108,7 @@ void ClientApp::start(const QString &lvl) {
}
_engine->setWorld(data.model);
_engine->start();
}
QList<QFileInfo> ClientApp::availablePlugins() const {

View File

@ -15,7 +15,7 @@ class IAI
{
public:
IAI();
virtual ~IAI() = default;
/**
* @brief startAI This method must be run ai.

View File

@ -6,6 +6,7 @@
#include "iground.h"
#include "defaultcontrol.h"
#include "worldstatus.h"
#include "iai.h"
IWorld::IWorld() {
@ -35,6 +36,14 @@ void IWorld::render(unsigned int tbfMsec) {
}
}
void IWorld::initPlayerControl(IControl *control) {
auto controlObject = dynamic_cast<DefaultControl*>(control);
if (controlObject) {
connect(controlObject, &DefaultControl::backToMenu, this, &IWorld::handleStop);
}
}
bool IWorld::start() {
_player->setposition({0,0,0});
_player->setSpeed(0);
@ -77,7 +86,6 @@ bool IWorld::init() {
_userInterface = initUserInterface();
_backgroundAI = initBackGroundAI();
if (!isInit()) {
QuasarAppUtils::Params::log("Failed to init world implementation.");
deinit();
@ -91,6 +99,9 @@ bool IWorld::init() {
return false;
}
initPlayerControl(_userInterface);
initPlayerControl(dynamic_cast<IControl*>(_backgroundAI));
generateGround();
worldChanged(*_worldRules->begin());
@ -122,6 +133,11 @@ void IWorld::deinit() {
_userInterface = nullptr;
}
if (_backgroundAI) {
delete _backgroundAI;
_backgroundAI = nullptr;
}
clearItems();
_hdrMap = "";
@ -182,6 +198,10 @@ void IWorld::setTap(bool newTap) {
_tap = newTap;
}
IAI *IWorld::backgroundAI() const {
return _backgroundAI;
}
IControl *IWorld::userInterface() const {
return _userInterface;
}

View File

@ -124,6 +124,13 @@ public:
*/
virtual QVector3D initCameraPosition() = 0;
/**
* @brief initPlayerControl This method should be configure all connections of @a control object.
* @brief control This is control object
* @note override this method if you have own IControl object.
*/
virtual void initPlayerControl(IControl* control);
/**
* @brief start This method will be invoked when user click start button.
* @note The Default implementation reset all positions for all objects.
@ -188,6 +195,12 @@ public:
*/
void setWorldStatus(int newWorldStatus);
/**
* @brief backgroundAI This method return current backgroundAI.
* @return Raw pointer to background AI object
*/
IAI *backgroundAI() const;
signals:
/**
* @brief sigGameFinished This signal emit when game are finished

View File

@ -152,6 +152,16 @@ int Engine::prepareLvlProgress() const {
return _prepareLvlProgress;
}
bool Engine::start() const {
if (!_currentWorld)
return false;
if (!_currentWorld->isInit())
return false;
return _currentWorld->start();
}
void Engine::setPrepareLvlProgress(int newPrepareLvlProgress) {
if (_prepareLvlProgress == newPrepareLvlProgress)
return;

View File

@ -91,6 +91,11 @@ public:
*/
int prepareLvlProgress() const;
/**
* @brief start This method run current lvl
* @return true if lvl started successful.
*/
bool start() const;
private slots: