Add proper initializations and remove manual memory management in remaining classes

Except CBot-related stuff of course
master
Piotr Dziwinski 2015-08-14 23:11:24 +02:00
parent 736f90955d
commit efedb44cce
75 changed files with 752 additions and 782 deletions

View File

@ -43,6 +43,6 @@ template<typename T>
inline std::unique_ptr<T[]> MakeUniqueArray(std::size_t size) inline std::unique_ptr<T[]> MakeUniqueArray(std::size_t size)
{ {
//@colobot-lint-exclude NakedNewRule //@colobot-lint-exclude NakedNewRule
return std::unique_ptr<T[]>(new T[size]); return std::unique_ptr<T[]>(new T[size]());
//@end-colobot-lint-exclude //@end-colobot-lint-exclude
} }

View File

@ -45,6 +45,11 @@ CMainMovie::CMainMovie()
m_camera = m_main->GetCamera(); m_camera = m_main->GetCamera();
m_sound = CApplication::GetInstancePointer()->GetSound(); m_sound = CApplication::GetInstancePointer()->GetSound();
m_progress = 0.0f;
m_stopType = MM_NONE;
m_type = MM_NONE;
m_speed = 0.0f;
Flush(); Flush();
} }

View File

@ -25,18 +25,18 @@
#include "level/parser/parser.h" #include "level/parser/parser.h"
CLevelParserLine::CLevelParserLine(std::string command) CLevelParserLine::CLevelParserLine(std::string command)
{ : m_level(nullptr),
m_command = command; m_levelFilename(""),
m_levelFilename = ""; m_lineNumber(0),
m_lineNumber = 0; m_command(command)
} {}
CLevelParserLine::CLevelParserLine(int lineNumber, std::string command) CLevelParserLine::CLevelParserLine(int lineNumber, std::string command)
{ : m_level(nullptr),
m_command = command; m_levelFilename(""),
m_levelFilename = ""; m_lineNumber(lineNumber),
m_lineNumber = lineNumber; m_command(command)
} {}
int CLevelParserLine::GetLineNumber() int CLevelParserLine::GetLineNumber()
{ {

View File

@ -83,6 +83,8 @@ CPlayerProfile::CPlayerProfile(std::string playerName)
GetConfigFile().Save(); GetConfigFile().Save();
m_freegameLoaded = false; m_freegameLoaded = false;
m_freegameBuild = 0;
m_freegameResearch = 0;
for(int i = 0; i < static_cast<int>(LevelCategory::Max); i++) for(int i = 0; i < static_cast<int>(LevelCategory::Max); i++)
{ {

View File

@ -28,14 +28,14 @@
struct LevelInfo struct LevelInfo
{ {
int numTry; int numTry = 0;
bool bPassed; bool bPassed = false;
}; };
struct PlayerApperance struct PlayerApperance
{ {
int face; // face int face = 0; // face
int glasses; // glasses int glasses = 0; // glasses
Gfx::Color colorHair; // hair color Gfx::Color colorHair; // hair color
Gfx::Color colorCombi; // spacesuit volor Gfx::Color colorCombi; // spacesuit volor
Gfx::Color colorBand; // strips color Gfx::Color colorBand; // strips color
@ -48,11 +48,9 @@ struct SavedScene
std::string path; std::string path;
std::string name; std::string name;
SavedScene(std::string _path = "", std::string _name = "") SavedScene(std::string path = "", std::string name = "")
{ : path(path), name(name)
path = _path; {}
name = _name;
}
}; };
class CPlayerProfile class CPlayerProfile

View File

@ -142,7 +142,6 @@ CRobotMain::CRobotMain()
m_engine = Gfx::CEngine::GetInstancePointer(); m_engine = Gfx::CEngine::GetInstancePointer();
m_oldModelManager = m_engine->GetModelManager(); m_oldModelManager = m_engine->GetModelManager();
m_modelManager = MakeUnique<Gfx::CModelManager>();
m_lightMan = m_engine->GetLightManager(); m_lightMan = m_engine->GetLightManager();
m_particle = m_engine->GetParticle(); m_particle = m_engine->GetParticle();
m_water = m_engine->GetWater(); m_water = m_engine->GetWater();
@ -151,23 +150,24 @@ CRobotMain::CRobotMain()
m_planet = m_engine->GetPlanet(); m_planet = m_engine->GetPlanet();
m_pause = CPauseManager::GetInstancePointer(); m_pause = CPauseManager::GetInstancePointer();
m_input = CInput::GetInstancePointer(); m_input = CInput::GetInstancePointer();
m_settings = new CSettings();
m_interface = new Ui::CInterface(); m_modelManager = MakeUnique<Gfx::CModelManager>();
m_terrain = new Gfx::CTerrain(); m_settings = MakeUnique<CSettings>();
m_camera = new Gfx::CCamera(); m_interface = MakeUnique<Ui::CInterface>();
m_displayText = new Ui::CDisplayText(); m_terrain = MakeUnique<Gfx::CTerrain>();
m_movie = new CMainMovie(); m_camera = MakeUnique<Gfx::CCamera>();
m_displayText = MakeUnique<Ui::CDisplayText>();
m_movie = MakeUnique<CMainMovie>();
m_ui = MakeUnique<Ui::CMainUserInterface>(); m_ui = MakeUnique<Ui::CMainUserInterface>();
m_short = new Ui::CMainShort(); m_short = MakeUnique<Ui::CMainShort>();
m_map = new Ui::CMainMap(); m_map = MakeUnique<Ui::CMainMap>();
m_displayInfo = nullptr;
m_objMan = new CObjectManager(m_engine, m_objMan = MakeUnique<CObjectManager>(
m_terrain, m_engine,
m_oldModelManager, m_terrain.get(),
m_modelManager.get(), m_oldModelManager,
m_particle); m_modelManager.get(),
m_particle);
m_time = 0.0f; m_time = 0.0f;
m_gameTime = 0.0f; m_gameTime = 0.0f;
@ -266,7 +266,7 @@ CRobotMain::CRobotMain()
m_showLimit[i].link = 0; m_showLimit[i].link = 0;
} }
m_engine->SetTerrain(m_terrain); m_engine->SetTerrain(m_terrain.get());
m_app->SetMouseMode(MOUSE_ENGINE); m_app->SetMouseMode(MOUSE_ENGINE);
@ -286,55 +286,26 @@ CRobotMain::CRobotMain()
//! Destructor of robot application //! Destructor of robot application
CRobotMain::~CRobotMain() CRobotMain::~CRobotMain()
{ {
delete m_settings;
m_settings = nullptr;
delete m_displayText;
m_displayText = nullptr;
delete m_interface;
m_interface = nullptr;
delete m_terrain;
m_terrain = nullptr;
delete m_camera;
m_camera = nullptr;
delete m_displayText;
m_displayText = nullptr;
delete m_movie;
m_movie = nullptr;
delete m_short;
m_short = nullptr;
delete m_map;
m_map = nullptr;
delete m_objMan;
m_objMan = nullptr;
} }
Gfx::CCamera* CRobotMain::GetCamera() Gfx::CCamera* CRobotMain::GetCamera()
{ {
return m_camera; return m_camera.get();
} }
Gfx::CTerrain* CRobotMain::GetTerrain() Gfx::CTerrain* CRobotMain::GetTerrain()
{ {
return m_terrain; return m_terrain.get();
} }
Ui::CInterface* CRobotMain::GetInterface() Ui::CInterface* CRobotMain::GetInterface()
{ {
return m_interface; return m_interface.get();
} }
Ui::CDisplayText* CRobotMain::GetDisplayText() Ui::CDisplayText* CRobotMain::GetDisplayText()
{ {
return m_displayText; return m_displayText.get();
} }
void CRobotMain::ResetAfterDeviceChanged() void CRobotMain::ResetAfterDeviceChanged()
@ -1415,7 +1386,7 @@ void CRobotMain::StartDisplayInfo(const std::string& filename, int index)
bool soluce = m_ui->GetSceneSoluce(); bool soluce = m_ui->GetSceneSoluce();
m_displayInfo = new Ui::CDisplayInfo(); m_displayInfo = MakeUnique<Ui::CDisplayInfo>();
m_displayInfo->StartDisplayInfo(filename, index, soluce); m_displayInfo->StartDisplayInfo(filename, index, soluce);
m_infoIndex = index; m_infoIndex = index;
@ -1436,8 +1407,7 @@ void CRobotMain::StopDisplayInfo()
m_displayInfo->StopDisplayInfo(); m_displayInfo->StopDisplayInfo();
delete m_displayInfo; m_displayInfo.reset();
m_displayInfo = nullptr;
if (!m_editLock) if (!m_editLock)
{ {
@ -4978,9 +4948,8 @@ CObject* CRobotMain::IOReadScene(std::string filename, std::string filecbot)
assert(obj->Implements(ObjectInterfaceType::Carrier)); // TODO: exception? assert(obj->Implements(ObjectInterfaceType::Carrier)); // TODO: exception?
assert(obj->Implements(ObjectInterfaceType::Old)); assert(obj->Implements(ObjectInterfaceType::Old));
dynamic_cast<CCarrierObject*>(obj)->SetCargo(cargo); dynamic_cast<CCarrierObject*>(obj)->SetCargo(cargo);
CTaskManip* task = new CTaskManip(dynamic_cast<COldObject*>(obj)); auto task = MakeUnique<CTaskManip>(dynamic_cast<COldObject*>(obj));
task->Start(TMO_AUTO, TMA_GRAB); // holds the object! task->Start(TMO_AUTO, TMA_GRAB); // holds the object!
delete task;
} }
if (power != nullptr) if (power != nullptr)

View File

@ -113,9 +113,9 @@ const int MAXNEWSCRIPTNAME = 20;
struct NewScriptName struct NewScriptName
{ {
bool used; bool used = false;
ObjectType type; ObjectType type = OBJECT_NULL;
char name[40]; char name[40] = {0};
}; };
@ -127,14 +127,14 @@ const int MAXSCENE = 999;
struct ShowLimit struct ShowLimit
{ {
bool used; bool used = false;
Math::Vector pos; Math::Vector pos;
float radius; float radius = 0.0f;
int total; int total = 0;
int parti[MAXSHOWPARTI]; int parti[MAXSHOWPARTI] = {0};
CObject* link; CObject* link = nullptr;
float duration; float duration = 0.0f;
float time; float time = 0.0f;
}; };
@ -417,156 +417,156 @@ protected:
protected: protected:
CController* m_ctrl; CController* m_ctrl = nullptr;
CApplication* m_app; CApplication* m_app = nullptr;
CObjectManager* m_objMan; CEventQueue* m_eventQueue = nullptr;
CEventQueue* m_eventQueue; Gfx::CEngine* m_engine = nullptr;
CMainMovie* m_movie; Gfx::CParticle* m_particle = nullptr;
Gfx::CEngine* m_engine; Gfx::CWater* m_water = nullptr;
Gfx::CParticle* m_particle; Gfx::CCloud* m_cloud = nullptr;
Gfx::CWater* m_water; Gfx::CLightning* m_lightning = nullptr;
Gfx::CCloud* m_cloud; Gfx::CPlanet* m_planet = nullptr;
Gfx::CLightning* m_lightning; Gfx::COldModelManager* m_oldModelManager = nullptr;
Gfx::CPlanet* m_planet; Gfx::CLightManager* m_lightMan = nullptr;
Gfx::COldModelManager* m_oldModelManager; CSoundInterface* m_sound = nullptr;
CPauseManager* m_pause = nullptr;
CInput* m_input = nullptr;
std::unique_ptr<CObjectManager> m_objMan;
std::unique_ptr<CMainMovie> m_movie;
std::unique_ptr<Gfx::CModelManager> m_modelManager; std::unique_ptr<Gfx::CModelManager> m_modelManager;
Gfx::CLightManager* m_lightMan; std::unique_ptr<Gfx::CTerrain> m_terrain;
Gfx::CTerrain* m_terrain; std::unique_ptr<Gfx::CCamera> m_camera;
Gfx::CCamera* m_camera;
std::unique_ptr<Ui::CMainUserInterface> m_ui; std::unique_ptr<Ui::CMainUserInterface> m_ui;
Ui::CMainShort* m_short; std::unique_ptr<Ui::CMainShort> m_short;
Ui::CMainMap* m_map; std::unique_ptr<Ui::CMainMap> m_map;
Ui::CInterface* m_interface; std::unique_ptr<Ui::CInterface> m_interface;
Ui::CDisplayText* m_displayText; std::unique_ptr<Ui::CDisplayInfo> m_displayInfo;
Ui::CDisplayInfo* m_displayInfo; std::unique_ptr<Ui::CDisplayText> m_displayText;
CSoundInterface* m_sound; std::unique_ptr<CSettings> m_settings;
CPauseManager* m_pause;
CInput* m_input;
CSettings* m_settings;
//! Progress of loaded player //! Progress of loaded player
std::unique_ptr<CPlayerProfile> m_playerProfile; std::unique_ptr<CPlayerProfile> m_playerProfile;
//! Time since level start, including pause and intro movie //! Time since level start, including pause and intro movie
float m_time; float m_time = 0.0f;
//! Playing time since level start //! Playing time since level start
float m_gameTime; float m_gameTime = 0.0f;
//! Playing time since level start, not dependent on simulation speed //! Playing time since level start, not dependent on simulation speed
float m_gameTimeAbsolute; float m_gameTimeAbsolute = 0.0f;
LevelCategory m_levelCategory; LevelCategory m_levelCategory;
int m_levelChap; int m_levelChap = 0;
int m_levelRank; int m_levelRank = 0;
std::string m_sceneReadPath; std::string m_sceneReadPath;
float m_winDelay; float m_winDelay = 0.0f;
float m_lostDelay; float m_lostDelay = 0.0f;
bool m_fixScene; // scene fixed, no interraction bool m_fixScene = false; // scene fixed, no interraction
CObject* m_base; // OBJECT_BASE exists in mission CObject* m_base = nullptr; // OBJECT_BASE exists in mission
Math::Point m_lastMousePos; Math::Point m_lastMousePos;
CObject* m_selectObject; CObject* m_selectObject = nullptr;
Phase m_phase; Phase m_phase = PHASE_WELCOME1;
int m_cameraRank; int m_cameraRank = 0;
Gfx::Color m_color; Gfx::Color m_color;
bool m_freePhoto; bool m_freePhoto = false;
bool m_cmdEdit; bool m_cmdEdit = false;
bool m_selectInsect; bool m_selectInsect = false;
bool m_showSoluce; bool m_showSoluce = false;
bool m_showAll; bool m_showAll = false;
bool m_cheatRadar; bool m_cheatRadar = false;
bool m_shortCut; bool m_shortCut = false;
std::string m_audioTrack; std::string m_audioTrack;
bool m_audioRepeat; bool m_audioRepeat = false;
std::string m_satcomTrack; std::string m_satcomTrack;
bool m_satcomRepeat; bool m_satcomRepeat = false;
std::string m_editorTrack; std::string m_editorTrack;
bool m_editorRepeat; bool m_editorRepeat = false;
int m_movieInfoIndex; int m_movieInfoIndex = 0;
CObject* m_controller; CObject* m_controller = nullptr;
MissionType m_missionType; MissionType m_missionType = MISSION_NORMAL;
bool m_immediatSatCom; // SatCom immediately? bool m_immediatSatCom = false; // SatCom immediately?
bool m_beginSatCom; // messages SatCom poster? bool m_beginSatCom = false; // messages SatCom poster?
bool m_lockedSatCom; // SatCom locked? bool m_lockedSatCom = false; // SatCom locked?
bool m_movieLock; // movie in progress? bool m_movieLock = false; // movie in progress?
bool m_satComLock; // call of SatCom is possible? bool m_satComLock = false; // call of SatCom is possible?
bool m_editLock; // edition in progress? bool m_editLock = false; // edition in progress?
bool m_editFull; // edition in full screen? bool m_editFull = false; // edition in full screen?
bool m_hilite; bool m_hilite = false;
bool m_trainerPilot; // remote trainer? bool m_trainerPilot = false; // remote trainer?
bool m_friendAim; bool m_friendAim = false;
bool m_resetCreate; bool m_resetCreate = false;
bool m_mapShow; bool m_mapShow = false;
bool m_mapImage; bool m_mapImage = false;
char m_mapFilename[100]; char m_mapFilename[100] = {};
bool m_suspend; bool m_suspend = false;
PauseType m_suspendInitPause; PauseType m_suspendInitPause = PAUSE_NONE;
Gfx::CameraType m_suspendInitCamera; Gfx::CameraType m_suspendInitCamera = Gfx::CAM_TYPE_NULL;
Math::Point m_tooltipPos; Math::Point m_tooltipPos;
std::string m_tooltipName; std::string m_tooltipName;
float m_tooltipTime; float m_tooltipTime = 0.0f;
char m_infoFilename[SATCOM_MAX][100]; // names of text files char m_infoFilename[SATCOM_MAX][100] = {}; // names of text files
CObject* m_infoObject; CObject* m_infoObject = nullptr;
int m_infoIndex; int m_infoIndex = 0;
int m_infoPos[SATCOM_MAX]; int m_infoPos[SATCOM_MAX] = {};
int m_infoUsed; int m_infoUsed = 0;
char m_title[100]; char m_title[100] = {};
char m_resume[500]; char m_resume[500] = {};
char m_scriptName[100]; char m_scriptName[100] = {};
char m_scriptFile[100]; char m_scriptFile[100] = {};
int m_endingWinRank; int m_endingWinRank = 0;
int m_endingLostRank; int m_endingLostRank = 0;
bool m_winTerminate; bool m_winTerminate = false;
float m_globalMagnifyDamage; float m_globalMagnifyDamage = 0.0f;
bool m_exitAfterMission; bool m_exitAfterMission = false;
bool m_codeBattleInit; bool m_codeBattleInit = false;
bool m_codeBattleStarted; bool m_codeBattleStarted = false;
std::map<int, std::string> m_teamNames; std::map<int, std::string> m_teamNames;
NewScriptName m_newScriptName[MAXNEWSCRIPTNAME]; NewScriptName m_newScriptName[MAXNEWSCRIPTNAME];
float m_cameraPan; float m_cameraPan = 0.0f;
float m_cameraZoom; float m_cameraZoom = 0.0f;
EventType m_visitLast; EventType m_visitLast = EVENT_NULL;
CObject* m_visitObject; CObject* m_visitObject = nullptr;
CObject* m_visitArrow; CObject* m_visitArrow = nullptr;
float m_visitTime; float m_visitTime = 0.0f;
float m_visitParticle; float m_visitParticle = 0.0f;
Math::Vector m_visitPos; Math::Vector m_visitPos;
Math::Vector m_visitPosArrow; Math::Vector m_visitPosArrow;
std::vector<std::unique_ptr<CSceneEndCondition>> m_endTake; std::vector<std::unique_ptr<CSceneEndCondition>> m_endTake;
long m_endTakeResearch; long m_endTakeResearch = 0;
float m_endTakeWinDelay; float m_endTakeWinDelay = 0.0f;
float m_endTakeLostDelay; float m_endTakeLostDelay = 0.0f;
std::vector<std::unique_ptr<CAudioChangeCondition>> m_audioChange; std::vector<std::unique_ptr<CAudioChangeCondition>> m_audioChange;
int m_obligatoryTotal; int m_obligatoryTotal = 0;
char m_obligatoryToken[100][20]; char m_obligatoryToken[100][20] = {};
int m_prohibitedTotal; int m_prohibitedTotal = 0;
char m_prohibitedToken[100][20]; char m_prohibitedToken[100][20] = {};
//! Enabled buildings //! Enabled buildings
int m_build; int m_build = 0;
//! Available researches //! Available researches
long m_researchEnable; long m_researchEnable = 0;
//! Done researches for each team //! Done researches for each team
std::map<int, int> m_researchDone; std::map<int, int> m_researchDone;
Error m_missionResult; Error m_missionResult = ERR_OK;
ShowLimit m_showLimit[MAXSHOWLIMIT]; ShowLimit m_showLimit[MAXSHOWLIMIT];
@ -578,18 +578,18 @@ protected:
Gfx::Color m_colorNewGreen; Gfx::Color m_colorNewGreen;
Gfx::Color m_colorRefWater; Gfx::Color m_colorRefWater;
Gfx::Color m_colorNewWater; Gfx::Color m_colorNewWater;
float m_colorShiftWater; float m_colorShiftWater = 0.0f;
bool m_missionTimerEnabled; bool m_missionTimerEnabled = false;
bool m_missionTimerStarted; bool m_missionTimerStarted = false;
float m_missionTimer; float m_missionTimer = 0.0f;
bool m_autosave; bool m_autosave = false;
int m_autosaveInterval; int m_autosaveInterval = 0;
int m_autosaveSlots; int m_autosaveSlots = 0;
float m_autosaveLast; float m_autosaveLast = 0.0f;
int m_shotSaving; int m_shotSaving = 0;
std::deque<CObject*> m_selectionHistory; std::deque<CObject*> m_selectionHistory;
}; };

View File

@ -70,14 +70,16 @@ struct Matrix
float m[16]; float m[16];
//! Creates the indentity matrix //! Creates the indentity matrix
inline Matrix() Matrix()
: m()
{ {
LoadIdentity(); LoadIdentity();
} }
//! Creates the matrix from 1D array //! Creates the matrix from 1D array
/** \a m matrix values in column-major order */ /** \a m matrix values in column-major order */
inline explicit Matrix(const float (&_m)[16]) explicit Matrix(const float (&_m)[16])
: m()
{ {
for (int i = 0; i < 16; ++i) for (int i = 0; i < 16; ++i)
m[i] = _m[i]; m[i] = _m[i];
@ -88,7 +90,8 @@ struct Matrix
* The array's first index is row, second is column. * The array's first index is row, second is column.
* \param m array with values * \param m array with values
*/ */
inline explicit Matrix(const float (&_m)[4][4]) explicit Matrix(const float (&_m)[4][4])
: m()
{ {
for (int c = 0; c < 4; ++c) for (int c = 0; c < 4; ++c)
{ {
@ -105,7 +108,7 @@ struct Matrix
* \param col column (1 to 4) * \param col column (1 to 4)
* \param value value * \param value value
*/ */
inline void Set(int row, int col, float value) void Set(int row, int col, float value)
{ {
m[(col-1)*4+(row-1)] = value; m[(col-1)*4+(row-1)] = value;
} }
@ -116,20 +119,20 @@ struct Matrix
* \param col column (1 to 4) * \param col column (1 to 4)
* \returns value * \returns value
*/ */
inline float Get(int row, int col) float Get(int row, int col)
{ {
return m[(col-1)*4+(row-1)]; return m[(col-1)*4+(row-1)];
} }
//! Loads the zero matrix //! Loads the zero matrix
inline void LoadZero() void LoadZero()
{ {
for (int i = 0; i < 16; ++i) for (int i = 0; i < 16; ++i)
m[i] = 0.0f; m[i] = 0.0f;
} }
//! Loads the identity matrix //! Loads the identity matrix
inline void LoadIdentity() void LoadIdentity()
{ {
LoadZero(); LoadZero();
/* (1,1) */ m[0 ] = 1.0f; /* (1,1) */ m[0 ] = 1.0f;
@ -139,13 +142,13 @@ struct Matrix
} }
//! Returns the struct cast to \c float* array; use with care! //! Returns the struct cast to \c float* array; use with care!
inline float* Array() float* Array()
{ {
return reinterpret_cast<float*>(this); return reinterpret_cast<float*>(this);
} }
//! Transposes the matrix //! Transposes the matrix
inline void Transpose() void Transpose()
{ {
/* (2,1) <-> (1,2) */ Swap(m[1 ], m[4 ]); /* (2,1) <-> (1,2) */ Swap(m[1 ], m[4 ]);
/* (3,1) <-> (1,3) */ Swap(m[2 ], m[8 ]); /* (3,1) <-> (1,3) */ Swap(m[2 ], m[8 ]);
@ -157,7 +160,7 @@ struct Matrix
//! Calculates the determinant of the matrix //! Calculates the determinant of the matrix
/** \returns the determinant */ /** \returns the determinant */
inline float Det() const float Det() const
{ {
float result = 0.0f; float result = 0.0f;
for (int i = 0; i < 4; ++i) for (int i = 0; i < 4; ++i)
@ -173,7 +176,7 @@ struct Matrix
* \param c column (0 to 3) * \param c column (0 to 3)
* \returns the cofactor * \returns the cofactor
*/ */
inline float Cofactor(int r, int c) const float Cofactor(int r, int c) const
{ {
assert(r >= 0 && r <= 3); assert(r >= 0 && r <= 3);
assert(c >= 0 && c <= 3); assert(c >= 0 && c <= 3);
@ -356,7 +359,7 @@ struct Matrix
* The determinant of the matrix must not be zero. * The determinant of the matrix must not be zero.
* \returns the inverted matrix * \returns the inverted matrix
*/ */
inline Matrix Inverse() const Matrix Inverse() const
{ {
float d = Det(); float d = Det();
assert(! IsZero(d)); assert(! IsZero(d));
@ -380,7 +383,7 @@ struct Matrix
* \param right right-hand matrix * \param right right-hand matrix
* \returns multiplication result * \returns multiplication result
*/ */
inline Matrix Multiply(const Matrix &right) const Matrix Multiply(const Matrix &right) const
{ {
float result[16] = { 0.0f }; float result[16] = { 0.0f };

View File

@ -98,26 +98,26 @@ protected:
void UpdateInterface(float rTime); void UpdateInterface(float rTime);
protected: protected:
CEventQueue* m_eventQueue; CEventQueue* m_eventQueue = nullptr;
Gfx::CEngine* m_engine; Gfx::CEngine* m_engine = nullptr;
Gfx::CParticle* m_particle; Gfx::CParticle* m_particle = nullptr;
Gfx::CTerrain* m_terrain; Gfx::CTerrain* m_terrain = nullptr;
Gfx::CWater* m_water; Gfx::CWater* m_water = nullptr;
Gfx::CCloud* m_cloud; Gfx::CCloud* m_cloud = nullptr;
Gfx::CPlanet* m_planet; Gfx::CPlanet* m_planet = nullptr;
Gfx::CLightning* m_lightning; Gfx::CLightning* m_lightning = nullptr;
Gfx::CCamera* m_camera; Gfx::CCamera* m_camera = nullptr;
Ui::CInterface* m_interface; Ui::CInterface* m_interface = nullptr;
CRobotMain* m_main; CRobotMain* m_main = nullptr;
COldObject* m_object; COldObject* m_object = nullptr;
CSoundInterface* m_sound; CSoundInterface* m_sound = nullptr;
ObjectType m_type; ObjectType m_type = OBJECT_NULL;
bool m_bBusy; bool m_bBusy = false;
bool m_bMotor; bool m_bMotor = false;
float m_time; float m_time = 0.0f;
float m_lastUpdateTime; float m_lastUpdateTime = 0.0f;
float m_progressTime; float m_progressTime = 0.0f;
float m_progressTotal; float m_progressTotal = 0.0f;
}; };

View File

@ -95,21 +95,21 @@ protected:
void EndTransit(); void EndTransit();
protected: protected:
AutoBasePhase m_phase; AutoBasePhase m_phase = ABP_WAIT;
bool m_bOpen; bool m_bOpen = false;
float m_progress; float m_progress = 0.0f;
float m_speed; float m_speed = 0.0f;
float m_lastParticle; float m_lastParticle = 0.0f;
float m_lastMotorParticle; float m_lastMotorParticle = 0.0f;
float m_fogStart; float m_fogStart = 0.0f;
float m_deepView; float m_deepView = 0.0f;
Math::Vector m_pos; Math::Vector m_pos;
Math::Vector m_posSound; Math::Vector m_posSound;
Math::Vector m_finalPos; Math::Vector m_finalPos;
Math::Vector m_lastPos; Math::Vector m_lastPos;
int m_param; int m_param = 0;
int m_soundChannel; int m_soundChannel = 0;
int m_partiChannel[8]; int m_partiChannel[8] = {};
std::string m_bgBack; std::string m_bgBack;
std::string m_bgName; std::string m_bgName;

View File

@ -62,12 +62,12 @@ protected:
void CreateMetal(); void CreateMetal();
protected: protected:
AutoConvertPhase m_phase; AutoConvertPhase m_phase = ACP_STOP;
float m_progress; float m_progress = 0.0f;
float m_speed; float m_speed = 0.0f;
float m_timeVirus; float m_timeVirus = 0.0f;
float m_lastParticle; float m_lastParticle = 0.0f;
bool m_bSoundClose; bool m_bSoundClose = false;
int m_soundChannel; int m_soundChannel = 0;
}; };

View File

@ -62,14 +62,14 @@ protected:
bool ExistKey(); bool ExistKey();
protected: protected:
AutoDerrickPhase m_phase; AutoDerrickPhase m_phase = ADP_WAIT;
float m_progress; float m_progress = 0.0f;
float m_speed; float m_speed = 0.0f;
float m_timeVirus; float m_timeVirus = 0.0f;
float m_lastParticle; float m_lastParticle = 0.0f;
float m_lastTrack; float m_lastTrack = 0.0f;
Math::Vector m_cargoPos; Math::Vector m_cargoPos;
int m_soundChannel; int m_soundChannel = 0;
bool m_bSoundFall; bool m_bSoundFall = false;
}; };

View File

@ -62,11 +62,11 @@ protected:
void EnableInterface(Ui::CWindow *pw, EventType event, bool bState); void EnableInterface(Ui::CWindow *pw, EventType event, bool bState);
protected: protected:
AutoDestroyerPhase m_phase; AutoDestroyerPhase m_phase = ADEP_WAIT;
float m_progress; float m_progress = 0.0f;
float m_speed; float m_speed = 0.0f;
float m_timeVirus; float m_timeVirus = 0.0f;
float m_lastParticle; float m_lastParticle = 0.0f;
bool m_bExplo; bool m_bExplo = false;
}; };

View File

@ -65,12 +65,12 @@ protected:
CObject* SearchAlien(); CObject* SearchAlien();
protected: protected:
ObjectType m_type; ObjectType m_type = OBJECT_NULL;
float m_value; float m_value = 0.0f;
std::string m_alienProgramName; std::string m_alienProgramName;
int m_param; int m_param = 0;
AutoEggPhase m_phase; AutoEggPhase m_phase = AEP_NULL;
float m_progress; float m_progress = 0.0f;
float m_speed; float m_speed = 0.0f;
}; };

View File

@ -70,12 +70,12 @@ protected:
void SoundManip(float time, float amplitude, float frequency); void SoundManip(float time, float amplitude, float frequency);
protected: protected:
AutoFactoryPhase m_phase; AutoFactoryPhase m_phase = AFP_WAIT;
float m_progress; float m_progress = 0.0f;
float m_speed; float m_speed = 0.0f;
float m_lastParticle; float m_lastParticle = 0.0f;
Math::Vector m_cargoPos; Math::Vector m_cargoPos;
int m_channelSound; int m_channelSound = 0;
std::string m_program; std::string m_program;
}; };

View File

@ -40,10 +40,8 @@ public:
Error GetError(); Error GetError();
protected: protected:
float m_strong = 0.0f;
protected: int m_param = 0;
float m_strong; float m_progress = 0.0f;
int m_param;
float m_progress;
}; };

View File

@ -30,12 +30,12 @@
struct HustonLens struct HustonLens
{ {
int parti; int parti = 0;
Gfx::ParticleType type; Gfx::ParticleType type = {};
Math::Vector pos; Math::Vector pos;
float dim; float dim = 0.0f;
float total; float total = 0.0f;
float off; float off = 0.0f;
}; };
@ -59,11 +59,9 @@ public:
bool CreateInterface(bool bSelect); bool CreateInterface(bool bSelect);
protected: protected:
float m_progress = 0.0f;
protected: float m_speed = 0.0f;
float m_progress;
float m_speed;
HustonLens m_lens[HUSTONMAXLENS]; HustonLens m_lens[HUSTONMAXLENS];
int m_lensTotal; int m_lensTotal = 0;
}; };

View File

@ -44,10 +44,10 @@ private:
void Start(int param) override; void Start(int param) override;
protected: protected:
float m_force; float m_force = 0.0f;
float m_progress; float m_progress = 0.0f;
float m_speed; float m_speed = 0.0f;
float m_lastParticle; float m_lastParticle = 0.0f;
Error m_error; Error m_error = ERR_OK;
}; };

View File

@ -66,13 +66,13 @@ protected:
void SoundManip(float time, float amplitude, float frequency); void SoundManip(float time, float amplitude, float frequency);
protected: protected:
AutoLaboPhase m_phase; AutoLaboPhase m_phase = ALAP_WAIT;
float m_progress; float m_progress = 0.0f;
float m_speed; float m_speed = 0.0f;
float m_timeVirus; float m_timeVirus = 0.0f;
float m_lastParticle; float m_lastParticle = 0.0f;
ResearchType m_research; ResearchType m_research = {};
int m_partiRank[3]; int m_partiRank[3] = {};
int m_partiSphere; int m_partiSphere = 0;
int m_soundChannel; int m_soundChannel = 0;
}; };

View File

@ -56,9 +56,9 @@ protected:
bool SearchTarget(); bool SearchTarget();
protected: protected:
AutoMushPhase m_phase; AutoMushPhase m_phase = AMP_WAIT;
float m_progress; float m_progress = 0.0f;
float m_speed; float m_speed = 0.0f;
float m_lastParticle; float m_lastParticle = 0.0f;
}; };

View File

@ -56,10 +56,10 @@ protected:
CObject* SearchCargo(); CObject* SearchCargo();
protected: protected:
AutoNestPhase m_phase; AutoNestPhase m_phase = ANP_WAIT;
float m_progress; float m_progress = 0.0f;
float m_speed; float m_speed = 0.0f;
float m_lastParticle; float m_lastParticle = 0.0f;
Math::Vector m_cargoPos; Math::Vector m_cargoPos;
}; };

View File

@ -61,12 +61,12 @@ protected:
void CreatePower(); void CreatePower();
protected: protected:
AutoNuclearPlantPhase m_phase; AutoNuclearPlantPhase m_phase = ANUP_STOP;
float m_progress; float m_progress = 0.0f;
float m_speed; float m_speed = 0.0f;
float m_timeVirus; float m_timeVirus = 0.0f;
float m_lastParticle; float m_lastParticle = 0.0f;
Math::Vector m_pos; Math::Vector m_pos;
int m_channelSound; int m_channelSound = 0;
}; };

View File

@ -57,16 +57,16 @@ protected:
void UpdateTrackMapping(float left, float right); void UpdateTrackMapping(float left, float right);
protected: protected:
AutoPorticoPhase m_phase; AutoPorticoPhase m_phase = APOP_WAIT;
float m_progress; float m_progress = 0.0f;
float m_speed; float m_speed = 0.0f;
float m_cameraProgress; float m_cameraProgress = 0.0f;
float m_cameraSpeed; float m_cameraSpeed = 0.0f;
float m_lastParticle; float m_lastParticle = 0.0f;
Math::Vector m_finalPos; Math::Vector m_finalPos;
Math::Vector m_startPos; Math::Vector m_startPos;
float m_posTrack; float m_posTrack = 0.0f;
int m_param; int m_param = 0;
int m_soundChannel; int m_soundChannel = 0;
}; };

View File

@ -57,12 +57,12 @@ protected:
void ChargeObject(float rTime); void ChargeObject(float rTime);
protected: protected:
AutoPowerCaptorPhase m_phase; AutoPowerCaptorPhase m_phase = APAP_WAIT;
float m_progress; float m_progress = 0.0f;
float m_speed; float m_speed = 0.0f;
float m_timeVirus; float m_timeVirus = 0.0f;
float m_lastParticle; float m_lastParticle = 0.0f;
Math::Vector m_pos; Math::Vector m_pos;
int m_channelSound; int m_channelSound = 0;
}; };

View File

@ -65,12 +65,12 @@ protected:
CObject* SearchPower(); CObject* SearchPower();
protected: protected:
AutoPowerPlantPhase m_phase; AutoPowerPlantPhase m_phase = AENP_STOP;
float m_progress; float m_progress = 0.0f;
float m_speed; float m_speed = 0.0;
float m_timeVirus; float m_timeVirus = 0.0f;
float m_lastUpdateTime; float m_lastUpdateTime = 0.0f;
float m_lastParticle; float m_lastParticle = 0.0f;
int m_partiSphere; int m_partiSphere = 0;
}; };

View File

@ -47,14 +47,14 @@ protected:
CObject* SearchVehicle(); CObject* SearchVehicle();
protected: protected:
float m_progress; float m_progress = 0.0f;
float m_speed; float m_speed = 0.0f;
float m_timeVirus; float m_timeVirus = 0.0f;
float m_lastUpdateTime; float m_lastUpdateTime = 0.0f;
float m_lastParticle; float m_lastParticle = 0.0f;
int m_soundChannel; int m_soundChannel = 0;
Math::Vector m_cargoPos; Math::Vector m_cargoPos;
bool m_bLastVirus; bool m_bLastVirus = false;
float m_energyVirus; float m_energyVirus = 0.0f;
}; };

View File

@ -54,14 +54,14 @@ protected:
bool SearchEnemy(Math::Vector &pos); bool SearchEnemy(Math::Vector &pos);
protected: protected:
AutoRadarPhase m_phase; AutoRadarPhase m_phase = ARAP_WAIT;
float m_progress; float m_progress = 0.0f;
float m_speed; float m_speed = 0.0f;
float m_aTime; float m_aTime = 0.0f;
float m_timeVirus; float m_timeVirus = 0.0f;
float m_lastParticle; float m_lastParticle =0.0f;
float m_angle; float m_angle = 0.0f;
float m_start; float m_start = 0.0f;
int m_totalDetect; int m_totalDetect = 0;
}; };

View File

@ -59,10 +59,10 @@ protected:
CObject* SearchVehicle(); CObject* SearchVehicle();
protected: protected:
AutoRepairPhase m_phase; AutoRepairPhase m_phase = ARP_WAIT;
float m_progress; float m_progress = 0.0f;
float m_speed; float m_speed = 0.0f;
float m_timeVirus; float m_timeVirus = 0.0f;
float m_lastParticle; float m_lastParticle = 0.0f;
}; };

View File

@ -59,14 +59,14 @@ protected:
void FireStopUpdate(float progress, bool bLightOn); void FireStopUpdate(float progress, bool bLightOn);
protected: protected:
AutoResearchPhase m_phase; AutoResearchPhase m_phase = ALP_WAIT;
float m_progress; float m_progress = 0.0f;
float m_speed; float m_speed = 0.0f;
float m_timeVirus; float m_timeVirus = 0.0f;
float m_lastUpdateTime; float m_lastUpdateTime = 0.0f;
float m_lastParticle; float m_lastParticle = 0.0f;
ResearchType m_research; ResearchType m_research = {};
int m_partiStop[6]; int m_partiStop[6] = {};
int m_channelSound; int m_channelSound = 0;
}; };

View File

@ -41,7 +41,7 @@ public:
protected: protected:
protected: protected:
float m_lastParticle; float m_lastParticle = 0.0f;
Math::Vector m_center; Math::Vector m_center;
}; };

View File

@ -62,17 +62,17 @@ protected:
void FireStopUpdate(float progress, bool bLightOn); void FireStopUpdate(float progress, bool bLightOn);
protected: protected:
AutoTowerPhase m_phase; AutoTowerPhase m_phase = ATP_WAIT;
float m_progress; float m_progress = 0.0f;
float m_speed; float m_speed = 0.0f;
float m_timeVirus; float m_timeVirus = 0.0f;
float m_lastUpdateTime; float m_lastUpdateTime = 0.0f;
float m_lastParticle; float m_lastParticle = 0.0f;
Math::Vector m_targetPos; Math::Vector m_targetPos;
float m_angleYactual; float m_angleYactual = 0.0f;
float m_angleZactual; float m_angleZactual = 0.0f;
float m_angleYfinal; float m_angleYfinal = 0.0f;
float m_angleZfinal; float m_angleZfinal = 0.0f;
int m_partiStop[4]; int m_partiStop[4] = {};
}; };

View File

@ -61,18 +61,18 @@ protected:
CObject* SearchVehicle(); CObject* SearchVehicle();
protected: protected:
AutoVaultPhase m_phase; AutoVaultPhase m_phase = ASAP_WAIT;
float m_progress; float m_progress = 0.0f;
float m_speed; float m_speed = 0.0f;
float m_timeVirus; float m_timeVirus = 0.0f;
float m_lastParticle; float m_lastParticle = 0.0f;
int m_channelSound; int m_channelSound = 0;
bool m_bLock; bool m_bLock = false;
int m_countKeys; int m_countKeys = 0;
float m_actualAngle; float m_actualAngle = 0.0f;
float m_finalAngle; float m_finalAngle = 0.0f;
bool m_bKey[4]; bool m_bKey[4] = {};
Math::Vector m_keyPos[4]; Math::Vector m_keyPos[4];
int m_keyParti[4]; int m_keyParti[4] = {};
}; };

View File

@ -19,7 +19,7 @@
#include "object/implementation/power_container_impl.h" #include "object/implementation/power_container_impl.h"
CPowerContainerObjectImpl::CPowerContainerObjectImpl(ObjectInterfaceTypes& types, CObject* object) CPowerContainerObjectImpl::CPowerContainerObjectImpl(ObjectInterfaceTypes& types)
: CPowerContainerObject(types) : CPowerContainerObject(types)
, m_energyLevel(1.0f) , m_energyLevel(1.0f)
{} {}

View File

@ -26,7 +26,7 @@ class CObject;
class CPowerContainerObjectImpl : public CPowerContainerObject class CPowerContainerObjectImpl : public CPowerContainerObject
{ {
public: public:
explicit CPowerContainerObjectImpl(ObjectInterfaceTypes& types, CObject* object); explicit CPowerContainerObjectImpl(ObjectInterfaceTypes& types);
virtual ~CPowerContainerObjectImpl(); virtual ~CPowerContainerObjectImpl();
void SetEnergyLevel(float level) override; void SetEnergyLevel(float level) override;

View File

@ -42,16 +42,20 @@
#include <iomanip> #include <iomanip>
CProgrammableObjectImpl::CProgrammableObjectImpl(ObjectInterfaceTypes& types, CObject* object) CProgrammableObjectImpl::CProgrammableObjectImpl(ObjectInterfaceTypes& types, CObject* object)
: CProgrammableObject(types) : CProgrammableObject(types),
, m_object(object) m_object(object),
, m_activity(true) m_activity(true),
, m_cmdLine() m_cmdLine(),
, m_program() m_program(),
, m_currentProgram(nullptr) m_currentProgram(nullptr),
, m_activeVirus(false) m_activeVirus(false),
, m_scriptRun(nullptr) m_scriptRun(nullptr),
, m_soluceName("") m_soluceName(""),
, m_traceRecord(false) m_traceRecord(false),
m_traceOper(TO_STOP),
m_traceAngle(0.0f),
m_traceColor(TraceColor::Default),
m_traceRecordIndex(0)
{ {
//assert(m_object->Implements(ObjectInterfaceType::TaskExecutor)); //assert(m_object->Implements(ObjectInterfaceType::TaskExecutor));
} }
@ -208,11 +212,10 @@ Program* CProgrammableObjectImpl::CloneProgram(Program* program)
Program* newprog = AddProgram(); Program* newprog = AddProgram();
// TODO: Is there any reason CScript doesn't have a function to get the program code directly? // TODO: Is there any reason CScript doesn't have a function to get the program code directly?
Ui::CEdit* edit = new Ui::CEdit(); auto edit = MakeUnique<Ui::CEdit>();
edit->SetMaxChar(Ui::EDITSTUDIOMAX); edit->SetMaxChar(Ui::EDITSTUDIOMAX);
program->script->PutScript(edit, ""); program->script->PutScript(edit.get(), "");
newprog->script->GetScript(edit); newprog->script->GetScript(edit.get());
delete edit;
return newprog; return newprog;
} }

View File

@ -40,8 +40,8 @@ enum TraceOper
struct TraceRecord struct TraceRecord
{ {
TraceOper oper; TraceOper oper = TO_STOP;
float param; float param = 0.0f;
}; };
class CProgrammableObjectImpl : public CProgrammableObject class CProgrammableObjectImpl : public CProgrammableObject

View File

@ -31,8 +31,8 @@ struct Program
{ {
std::unique_ptr<CScript> script; std::unique_ptr<CScript> script;
std::string filename; std::string filename;
bool readOnly; bool readOnly = false;
bool runnable; bool runnable = false;
}; };
/** /**

View File

@ -39,7 +39,9 @@ const float START_TIME = 1000.0f; // beginning of the relative time
// Object's constructor. // Object's constructor.
CMotionAnt::CMotionAnt(COldObject* object) : CMotion(object) CMotionAnt::CMotionAnt(COldObject* object)
: CMotion(object),
m_armAngles()
{ {
m_armMember = START_TIME; m_armMember = START_TIME;
m_armTimeAbs = START_TIME; m_armTimeAbs = START_TIME;

View File

@ -38,7 +38,9 @@ const float START_TIME = 1000.0f; // beginning of the relative time
// Object's constructor. // Object's constructor.
CMotionBee::CMotionBee(COldObject* object) : CMotion(object) CMotionBee::CMotionBee(COldObject* object)
: CMotion(object),
m_armAngles()
{ {
m_armMember = START_TIME; m_armMember = START_TIME;
m_armTimeAbs = START_TIME; m_armTimeAbs = START_TIME;

View File

@ -50,7 +50,9 @@ const float START_TIME = 1000.0f; // beginning of the relative time
// Object's constructor. // Object's constructor.
CMotionHuman::CMotionHuman(COldObject* object) : CMotion(object) CMotionHuman::CMotionHuman(COldObject* object)
: CMotion(object),
m_armAngles()
{ {
m_partiReactor = -1; m_partiReactor = -1;
m_armMember = START_TIME; m_armMember = START_TIME;

View File

@ -38,7 +38,9 @@ const float START_TIME = 1000.0f; // beginning of the relative time
// Object's constructor. // Object's constructor.
CMotionQueen::CMotionQueen(COldObject* object) : CMotion(object) CMotionQueen::CMotionQueen(COldObject* object)
: CMotion(object),
m_armAngles()
{ {
m_armMember = START_TIME; m_armMember = START_TIME;
m_armTimeAbs = START_TIME; m_armTimeAbs = START_TIME;

View File

@ -39,7 +39,9 @@ const float START_TIME = 1000.0f; // beginning of the relative time
// Object's constructor. // Object's constructor.
CMotionSpider::CMotionSpider(COldObject* object) : CMotion(object) CMotionSpider::CMotionSpider(COldObject* object)
: CMotion(object),
m_armAngles()
{ {
m_armMember = START_TIME; m_armMember = START_TIME;
m_armTimeAbs = START_TIME; m_armTimeAbs = START_TIME;

View File

@ -48,16 +48,11 @@
// Object's constructor. // Object's constructor.
CMotionVehicle::CMotionVehicle(COldObject* object) : CMotion(object) CMotionVehicle::CMotionVehicle(COldObject* object)
: CMotion(object),
m_wheelTurn(),
m_flyPaw()
{ {
for (int i = 0; i < 4; i++)
{
m_wheelTurn[i] = 0.0f;
}
for (int i = 0; i < 3; i++)
{
m_flyPaw[i] = 0.0f;
}
m_posTrackLeft = 0.0f; m_posTrackLeft = 0.0f;
m_posTrackRight = 0.0f; m_posTrackRight = 0.0f;
m_partiReactor = -1; m_partiReactor = -1;

View File

@ -47,7 +47,9 @@ const int WORM_PART = 7; // number of parts of a worm
// Object's constructor. // Object's constructor.
CMotionWorm::CMotionWorm(COldObject* object) : CMotion(object) CMotionWorm::CMotionWorm(COldObject* object)
: CMotion(object),
m_armAngles()
{ {
m_timeUp = 18.0f; m_timeUp = 18.0f;
m_timeDown = 18.0f; m_timeDown = 18.0f;
@ -62,6 +64,7 @@ CMotionWorm::CMotionWorm(COldObject* object) : CMotion(object)
m_armCirSpeed = 0.0f; m_armCirSpeed = 0.0f;
m_armLastAction = -1; m_armLastAction = -1;
m_specAction = -1; m_specAction = -1;
m_specTime = 0.0f;
m_lastParticle = 0.0f; m_lastParticle = 0.0f;
m_bArmStop = false; m_bArmStop = false;
} }

View File

@ -19,6 +19,7 @@
#include "object/object_manager.h" #include "object/object_manager.h"
#include "common/make_unique.h"
#include "math/all.h" #include "math/all.h"
@ -43,7 +44,7 @@ CObjectManager::CObjectManager(Gfx::CEngine* engine,
Gfx::COldModelManager* oldModelManager, Gfx::COldModelManager* oldModelManager,
Gfx::CModelManager* modelManager, Gfx::CModelManager* modelManager,
Gfx::CParticle* particle) Gfx::CParticle* particle)
: m_objectFactory(new CObjectFactory(engine, terrain, oldModelManager, modelManager, particle)) : m_objectFactory(MakeUnique<CObjectFactory>(engine, terrain, oldModelManager, modelManager, particle))
, m_nextId(0) , m_nextId(0)
, m_shouldCleanRemovedObjects(false) , m_shouldCleanRemovedObjects(false)
{ {

View File

@ -75,20 +75,21 @@ const float VIRUS_DELAY = 60.0f; // duration of virus infection
// Object's constructor. // Object's constructor.
COldObject::COldObject(int id) COldObject::COldObject(int id)
: CObject(id, OBJECT_NULL) : CObject(id, OBJECT_NULL),
, CInteractiveObject(m_implementedInterfaces) CInteractiveObject(m_implementedInterfaces),
, CTransportableObject(m_implementedInterfaces) CTransportableObject(m_implementedInterfaces),
, CTaskExecutorObjectImpl(m_implementedInterfaces, this) CTaskExecutorObjectImpl(m_implementedInterfaces, this),
, CProgrammableObjectImpl(m_implementedInterfaces, this) CProgrammableObjectImpl(m_implementedInterfaces, this),
, CJostleableObject(m_implementedInterfaces) CJostleableObject(m_implementedInterfaces),
, CCarrierObject(m_implementedInterfaces) CCarrierObject(m_implementedInterfaces),
, CPoweredObject(m_implementedInterfaces) CPoweredObject(m_implementedInterfaces),
, CJetFlyingObject(m_implementedInterfaces) CJetFlyingObject(m_implementedInterfaces),
, CControllableObject(m_implementedInterfaces) CControllableObject(m_implementedInterfaces),
, CPowerContainerObjectImpl(m_implementedInterfaces, this) CPowerContainerObjectImpl(m_implementedInterfaces),
, CRangedObject(m_implementedInterfaces) CRangedObject(m_implementedInterfaces),
, CTraceDrawingObject(m_implementedInterfaces) CTraceDrawingObject(m_implementedInterfaces),
, CShieldedAutoRegenObject(m_implementedInterfaces) CShieldedAutoRegenObject(m_implementedInterfaces),
m_partiSel()
{ {
// A bit of a hack since we don't have subclasses yet, set externally in SetProgrammable() // A bit of a hack since we don't have subclasses yet, set externally in SetProgrammable()
m_implementedInterfaces[static_cast<int>(ObjectInterfaceType::Programmable)] = false; m_implementedInterfaces[static_cast<int>(ObjectInterfaceType::Programmable)] = false;
@ -111,7 +112,9 @@ COldObject::COldObject(int id)
m_option = 0; m_option = 0;
m_name = ""; m_name = "";
m_shadowLight = -1; m_shadowLight = -1;
m_shadowHeight = 0.0f;
m_effectLight = -1; m_effectLight = -1;
m_effectHeight = 0.0f;
m_linVibration = Math::Vector(0.0f, 0.0f, 0.0f); m_linVibration = Math::Vector(0.0f, 0.0f, 0.0f);
m_cirVibration = Math::Vector(0.0f, 0.0f, 0.0f); m_cirVibration = Math::Vector(0.0f, 0.0f, 0.0f);
m_tilt = Math::Vector(0.0f, 0.0f, 0.0f); m_tilt = Math::Vector(0.0f, 0.0f, 0.0f);

View File

@ -51,16 +51,16 @@ const int OBJECTMAXPART = 40;
struct ObjectPart struct ObjectPart
{ {
bool bUsed; bool bUsed = false;
int object; // number of the object in CEngine int object = -1; // number of the object in CEngine
int parentPart; // number of father part int parentPart = -1; // number of father part
int masterParti; // master canal of the particle int masterParti = -1; // master canal of the particle
Math::Vector position; Math::Vector position;
Math::Vector angle; Math::Vector angle;
Math::Vector zoom; Math::Vector zoom;
bool bTranslate; bool bTranslate = false;
bool bRotate; bool bRotate = false;
bool bZoom; bool bZoom = false;
Math::Matrix matTranslate; Math::Matrix matTranslate;
Math::Matrix matRotate; Math::Matrix matRotate;
Math::Matrix matTransform; Math::Matrix matTransform;

View File

@ -255,8 +255,14 @@ enum class CAutoInfo::Phase : unsigned int
// Object's constructor. // Object's constructor.
CAutoInfo::CAutoInfo(CExchangePost* object) CAutoInfo::CAutoInfo(CExchangePost* object)
: CAuto(object) : CAuto(object),
, m_exchangePost(object) m_exchangePost(object),
m_phase(Phase::Wait),
m_progress(0.0f),
m_speed(0.0f),
m_timeVirus(0.0f),
m_lastParticle(0.0f),
m_lastVirus(0.0f)
{ {
Init(); Init();
} }

View File

@ -74,17 +74,17 @@ public:
virtual bool Abort(); virtual bool Abort();
protected: protected:
Gfx::CEngine* m_engine; Gfx::CEngine* m_engine = nullptr;
Gfx::CLightManager* m_lightMan; Gfx::CLightManager* m_lightMan = nullptr;
Gfx::CParticle* m_particle; Gfx::CParticle* m_particle = nullptr;
Gfx::CTerrain* m_terrain; Gfx::CTerrain* m_terrain = nullptr;
Gfx::CWater* m_water; Gfx::CWater* m_water = nullptr;
Gfx::CCamera* m_camera; Gfx::CCamera* m_camera = nullptr;
CRobotMain* m_main; CRobotMain* m_main = nullptr;
CSoundInterface* m_sound; CSoundInterface* m_sound = nullptr;
COldObject* m_object; COldObject* m_object = nullptr;
CProgrammableObject* m_programmable; CProgrammableObject* m_programmable = nullptr;
CMotion* m_motion; CMotion* m_motion = nullptr;
CPhysics* m_physics; CPhysics* m_physics = nullptr;
}; };

View File

@ -40,15 +40,13 @@ public:
Error IsEnded(); Error IsEnded();
protected: protected:
float m_totalLength = 0.0f;
protected: float m_advanceLength = 0.0f;
float m_totalLength; float m_direction = 0.0f;
float m_advanceLength; float m_timeLimit = 0.0f;
float m_direction;
float m_timeLimit;
Math::Vector m_startPos; Math::Vector m_startPos;
float m_lastDist; float m_lastDist = 0.0f;
float m_fixTime; float m_fixTime = 0.0f;
bool m_bError; bool m_bError = 0.0f;
}; };

View File

@ -70,23 +70,23 @@ protected:
void DeleteMark(Math::Vector pos, float radius); void DeleteMark(Math::Vector pos, float radius);
protected: protected:
ObjectType m_type; // type of construction ObjectType m_type = OBJECT_NULL; // type of construction
CObject* m_metal; // transforms metal object CObject* m_metal = nullptr; // transforms metal object
CObject* m_power; // the vehicle battery CObject* m_power = nullptr; // the vehicle battery
CObject* m_building; // building built CObject* m_building = nullptr; // building built
TaskBuildPhase m_phase; // phase of the operation TaskBuildPhase m_phase = TBP_STOP; // phase of the operation
bool m_bError; // true -> operation impossible bool m_bError = false; // true -> operation impossible
bool m_bBuild; // true -> building built bool m_bBuild = false; // true -> building built
bool m_bBlack; // true -> lights black -> white bool m_bBlack = false; // true -> lights black -> white
float m_time; // absolute time float m_time = 0.0f; // absolute time
float m_lastParticle; // time of generation last particle float m_lastParticle = 0.0f; // time of generation last particle
float m_progress; // progression (0..1) float m_progress = 0.0f; // progression (0..1)
float m_speed; // speed of progression float m_speed = 0.0f; // speed of progression
float m_angleY; // rotation angle of the vehicle float m_angleY = 0.0f; // rotation angle of the vehicle
float m_angleZ; // angle of rotation of the gun float m_angleZ = 0.0f; // angle of rotation of the gun
Math::Vector m_buildingPos; // initial position of the building Math::Vector m_buildingPos; // initial position of the building
float m_buildingHeight; // height of the building float m_buildingHeight = 0.0f; // height of the building
int m_lightRank[TBMAXLIGHT]; // lights for the effects int m_lightRank[TBMAXLIGHT] = {}; // lights for the effects
int m_soundChannel; int m_soundChannel = 0;
}; };

View File

@ -39,6 +39,7 @@ public:
protected: protected:
void DeleteMark(); void DeleteMark();
protected: protected:
bool m_bExecuted; bool m_bExecuted = false;
}; };

View File

@ -39,17 +39,15 @@ public:
bool Abort(); bool Abort();
protected: protected:
float m_delay = 0.0f;
protected: float m_progress = 0.0f;
float m_delay; bool m_bError = false;
float m_progress; bool m_bRay = false;
bool m_bError; bool m_bOrganic = false;
bool m_bRay; float m_time = 0.0f;
bool m_bOrganic; float m_speed = 0.0f;
float m_time; float m_lastParticle = 0.0f;
float m_speed; float m_lastSound = 0.0f;
float m_lastParticle; int m_soundChannel = 0;
float m_lastSound;
int m_soundChannel;
}; };

View File

@ -54,13 +54,13 @@ protected:
protected: protected:
Math::Vector m_impact; Math::Vector m_impact;
TaskFireAnt m_phase; TaskFireAnt m_phase = TFA_NULL;
float m_progress; float m_progress = 0.0f;
float m_speed; float m_speed = 0.0f;
float m_angle; float m_angle = 0.0f;
bool m_bError; bool m_bError = false;
bool m_bFire; bool m_bFire = false;
float m_time; float m_time = 0.0f;
float m_lastParticle; float m_lastParticle = 0.0f;
}; };

View File

@ -56,8 +56,8 @@ protected:
int CountObject(ObjectType type); int CountObject(ObjectType type);
protected: protected:
TaskFlagOrder m_order; TaskFlagOrder m_order = TFL_CREATE;
float m_time; float m_time = 0.0f;
bool m_bError; bool m_bError = false;
}; };

View File

@ -21,6 +21,7 @@
#include "object/task/taskgoto.h" #include "object/task/taskgoto.h"
#include "common/event.h" #include "common/event.h"
#include "common/make_unique.h"
#include "graphics/engine/terrain.h" #include "graphics/engine/terrain.h"
#include "graphics/engine/water.h" #include "graphics/engine/water.h"
@ -1965,7 +1966,7 @@ bool CTaskGoto::BitmapOpen()
BitmapClose(); BitmapClose();
m_bmSize = static_cast<int>(3200.0f/BM_DIM_STEP); m_bmSize = static_cast<int>(3200.0f/BM_DIM_STEP);
m_bmArray = new unsigned char[m_bmSize*m_bmSize/8*2](); m_bmArray = MakeUniqueArray<unsigned char>(m_bmSize*m_bmSize/8*2);
m_bmOffset = m_bmSize/2; m_bmOffset = m_bmSize/2;
m_bmLine = m_bmSize/8; m_bmLine = m_bmSize/8;
@ -1982,8 +1983,7 @@ bool CTaskGoto::BitmapOpen()
bool CTaskGoto::BitmapClose() bool CTaskGoto::BitmapClose()
{ {
delete[] m_bmArray; m_bmArray.reset();
m_bmArray = 0;
return true; return true;
} }

View File

@ -26,6 +26,8 @@
#include "math/vector.h" #include "math/vector.h"
#include <memory>
class CObject; class CObject;
@ -118,44 +120,44 @@ protected:
protected: protected:
Math::Vector m_goal; Math::Vector m_goal;
Math::Vector m_goalObject; Math::Vector m_goalObject;
float m_angle; float m_angle = 0.0f;
float m_altitude; float m_altitude = 0.0f;
TaskGotoCrash m_crashMode; TaskGotoCrash m_crashMode = TGC_DEFAULT;
TaskGotoGoal m_goalMode; TaskGotoGoal m_goalMode = TGG_DEFAULT;
TaskGotoPhase m_phase; TaskGotoPhase m_phase = TGP_ADVANCE;
int m_try; int m_try = 0;
Error m_error; Error m_error = ERR_OK;
bool m_bTake; bool m_bTake = false;
float m_stopLength; // braking distance float m_stopLength = 0.0f; // braking distance
float m_time; float m_time = 0.0f;
Math::Vector m_pos; Math::Vector m_pos;
bool m_bWorm; bool m_bWorm = false;
bool m_bApprox; bool m_bApprox = false;
float m_wormLastTime; float m_wormLastTime = 0.0f;
float m_lastDistance; float m_lastDistance = 0.0f;
int m_bmSize; // width or height of the table int m_bmSize = 0; // width or height of the table
int m_bmOffset; // m_bmSize/2 int m_bmOffset = 0; // m_bmSize/2
int m_bmLine; // increment line m_bmSize/8 int m_bmLine = 0; // increment line m_bmSize/8
unsigned char* m_bmArray; // bit table std::unique_ptr<unsigned char[]> m_bmArray; // bit table
int m_bmMinX, m_bmMinY; int m_bmMinX = 0, m_bmMinY = 0;
int m_bmMaxX, m_bmMaxY; int m_bmMaxX = 0, m_bmMaxY = 0;
int m_bmTotal; // number of points in m_bmPoints int m_bmTotal = 0; // number of points in m_bmPoints
int m_bmIndex; // index in m_bmPoints int m_bmIndex = 0; // index in m_bmPoints
Math::Vector m_bmPoints[MAXPOINTS+2]; Math::Vector m_bmPoints[MAXPOINTS+2];
char m_bmIter[MAXPOINTS+2]; char m_bmIter[MAXPOINTS+2] = {};
int m_bmIterCounter; int m_bmIterCounter = 0;
CObject* m_bmCargoObject; CObject* m_bmCargoObject = nullptr;
float m_bmFinalMove; // final advance distance float m_bmFinalMove = 0.0f; // final advance distance
float m_bmFinalDist; // effective distance to advance float m_bmFinalDist = 0.0f; // effective distance to advance
Math::Vector m_bmFinalPos; // initial position before advance Math::Vector m_bmFinalPos; // initial position before advance
float m_bmTimeLimit; float m_bmTimeLimit = 0.0f;
int m_bmStep; int m_bmStep = 0;
Math::Vector m_bmWatchDogPos; Math::Vector m_bmWatchDogPos;
float m_bmWatchDogTime; float m_bmWatchDogTime = 0.0f;
Math::Vector m_leakPos; // initial position leak Math::Vector m_leakPos; // initial position leak
float m_leakDelay; float m_leakDelay = 0.0f;
float m_leakTime; float m_leakTime = 0.0f;
bool m_bLeakRecede; bool m_bLeakRecede = false;
}; };

View File

@ -39,15 +39,13 @@ public:
bool Abort(); bool Abort();
protected: protected:
float m_progress = 0.0f;
float m_speed = 0.0f;
float m_initialDirV = 0.0f; // initial direction
float m_finalDirV = 0.0f; // direction to reach
float m_initialDirH = 0.0f; // initial direction
float m_finalDirH = 0.0f; // direction to reach
protected: bool m_aimImpossible = false; // set to true if impossible aim was set
float m_progress;
float m_speed;
float m_initialDirV; // initial direction
float m_finalDirV; // direction to reach
float m_initialDirH; // initial direction
float m_finalDirH; // direction to reach
bool m_aimImpossible; // set to true if impossible aim was set
}; };

View File

@ -42,9 +42,9 @@ protected:
CExchangePost* FindExchangePost(float power); CExchangePost* FindExchangePost(float power);
protected: protected:
float m_progress; float m_progress = 0.0f;
float m_speed; float m_speed = 0.0f;
float m_time; float m_time = 0.0f;
bool m_error; bool m_error = false;
}; };

View File

@ -20,6 +20,8 @@
#include "object/task/taskmanager.h" #include "object/task/taskmanager.h"
#include "common/make_unique.h"
#include "object/old_object.h" #include "object/old_object.h"
#include "object/task/taskadvance.h" #include "object/task/taskadvance.h"
@ -42,99 +44,95 @@
// Object's constructor. // Object's constructor.
CTaskManager::CTaskManager(COldObject* object) CTaskManager::CTaskManager(COldObject* object)
: m_object(object),
m_bPilot(false)
{ {
m_task = nullptr;
m_object = object;
m_bPilot = false;
} }
// Object's destructor. // Object's destructor.
CTaskManager::~CTaskManager() CTaskManager::~CTaskManager()
{ {
delete m_task;
} }
template<typename TaskType, typename... Args>
Error CTaskManager::StartTask(Args&&... args)
{
auto task = MakeUnique<TaskType>(m_object);
auto* taskPtr = task.get();
m_task = std::move(task);
return taskPtr->Start(std::forward<Args>(args)...);
}
// Waits for a while. // Waits for a while.
Error CTaskManager::StartTaskWait(float time) Error CTaskManager::StartTaskWait(float time)
{ {
m_task = new CTaskWait(m_object); return StartTask<CTaskWait>(time);
return (static_cast<CTaskWait*>(m_task))->Start(time);
} }
// Advance straight ahead a certain distance. // Advance straight ahead a certain distance.
Error CTaskManager::StartTaskAdvance(float length) Error CTaskManager::StartTaskAdvance(float length)
{ {
m_task = new CTaskAdvance(m_object); return StartTask<CTaskAdvance>(length);
return (static_cast<CTaskAdvance*>(m_task))->Start(length);
} }
// Turns through an certain angle. // Turns through an certain angle.
Error CTaskManager::StartTaskTurn(float angle) Error CTaskManager::StartTaskTurn(float angle)
{ {
m_task = new CTaskTurn(m_object); return StartTask<CTaskTurn>(angle);
return (static_cast<CTaskTurn*>(m_task))->Start(angle);
} }
// Reaches a given position. // Reaches a given position.
Error CTaskManager::StartTaskGoto(Math::Vector pos, float altitude, TaskGotoGoal goalMode, TaskGotoCrash crashMode) Error CTaskManager::StartTaskGoto(Math::Vector pos, float altitude, TaskGotoGoal goalMode, TaskGotoCrash crashMode)
{ {
m_task = new CTaskGoto(m_object); return StartTask<CTaskGoto>(pos, altitude, goalMode, crashMode);
return (static_cast<CTaskGoto*>(m_task))->Start(pos, altitude, goalMode, crashMode);
} }
// Move the manipulator arm. // Move the manipulator arm.
Error CTaskManager::StartTaskTake() Error CTaskManager::StartTaskTake()
{ {
m_task = new CTaskTake(m_object); return StartTask<CTaskTake>();
return (static_cast<CTaskTake*>(m_task))->Start();
} }
// Move the manipulator arm. // Move the manipulator arm.
Error CTaskManager::StartTaskManip(TaskManipOrder order, TaskManipArm arm) Error CTaskManager::StartTaskManip(TaskManipOrder order, TaskManipArm arm)
{ {
m_task = new CTaskManip(m_object); return StartTask<CTaskManip>(order, arm);
return (static_cast<CTaskManip*>(m_task))->Start(order, arm);
} }
// Puts or removes a flag. // Puts or removes a flag.
Error CTaskManager::StartTaskFlag(TaskFlagOrder order, int rank) Error CTaskManager::StartTaskFlag(TaskFlagOrder order, int rank)
{ {
m_task = new CTaskFlag(m_object); return StartTask<CTaskFlag>(order, rank);
return (static_cast<CTaskFlag*>(m_task))->Start(order, rank);
} }
// Builds a building. // Builds a building.
Error CTaskManager::StartTaskBuild(ObjectType type) Error CTaskManager::StartTaskBuild(ObjectType type)
{ {
m_task = new CTaskBuild(m_object); return StartTask<CTaskBuild>(type);
return (static_cast<CTaskBuild*>(m_task))->Start(type);
} }
// Probe the ground. // Probe the ground.
Error CTaskManager::StartTaskSearch() Error CTaskManager::StartTaskSearch()
{ {
m_task = new CTaskSearch(m_object); return StartTask<CTaskSearch>();
return (static_cast<CTaskSearch*>(m_task))->Start();
} }
// Delete mark on ground // Delete mark on ground
Error CTaskManager::StartTaskDeleteMark() Error CTaskManager::StartTaskDeleteMark()
{ {
m_task = new CTaskDeleteMark(m_object); return StartTask<CTaskDeleteMark>();
return (static_cast<CTaskDeleteMark*>(m_task))->Start();
} }
@ -142,46 +140,42 @@ Error CTaskManager::StartTaskDeleteMark()
Error CTaskManager::StartTaskInfo(const char *name, float value, float power, bool bSend) Error CTaskManager::StartTaskInfo(const char *name, float value, float power, bool bSend)
{ {
m_task = new CTaskInfo(m_object); return StartTask<CTaskInfo>(name, value, power, bSend);
return (static_cast<CTaskInfo*>(m_task))->Start(name, value, power, bSend);
} }
// Terraforms the ground. // Terraforms the ground.
Error CTaskManager::StartTaskTerraform() Error CTaskManager::StartTaskTerraform()
{ {
m_task = new CTaskTerraform(m_object); return StartTask<CTaskTerraform>();
return (static_cast<CTaskTerraform*>(m_task))->Start();
} }
// Changes the pencil. // Changes the pencil.
Error CTaskManager::StartTaskPen(bool bDown, TraceColor color) Error CTaskManager::StartTaskPen(bool bDown, TraceColor color)
{ {
m_task = new CTaskPen(m_object); return StartTask<CTaskPen>(bDown, color);
return (static_cast<CTaskPen*>(m_task))->Start(bDown, color);
} }
// Recovers a ruin. // Recovers a ruin.
Error CTaskManager::StartTaskRecover() Error CTaskManager::StartTaskRecover()
{ {
m_task = new CTaskRecover(m_object); return StartTask<CTaskRecover>();
return (static_cast<CTaskRecover*>(m_task))->Start();
} }
// Deploys the shield. // Deploys the shield.
Error CTaskManager::StartTaskShield(TaskShieldMode mode, float delay) Error CTaskManager::StartTaskShield(TaskShieldMode mode, float delay)
{ {
if ( mode == TSM_UP || mode == TSM_START ) if (mode == TSM_UP || mode == TSM_START)
{ {
m_task = new CTaskShield(m_object); return StartTask<CTaskShield>(mode, delay);
return (static_cast<CTaskShield*>(m_task))->Start(mode, delay);
} }
else if ( m_task != 0 ) else if (m_task != nullptr)
{ {
return (static_cast<CTaskShield*>(m_task))->Start(mode, delay); // TODO: is this static_cast really safe?
return (static_cast<CTaskShield*>(m_task.get()))->Start(mode, delay);
} }
return ERR_UNKNOWN; return ERR_UNKNOWN;
} }
@ -190,33 +184,29 @@ Error CTaskManager::StartTaskShield(TaskShieldMode mode, float delay)
Error CTaskManager::StartTaskFire(float delay) Error CTaskManager::StartTaskFire(float delay)
{ {
m_bPilot = true; m_bPilot = true; // TODO: this is set here, but never unset - is this right?
m_task = new CTaskFire(m_object); return StartTask<CTaskFire>(delay);
return (static_cast<CTaskFire*>(m_task))->Start(delay);
} }
// Shoots with the ant. // Shoots with the ant.
Error CTaskManager::StartTaskFireAnt(Math::Vector impact) Error CTaskManager::StartTaskFireAnt(Math::Vector impact)
{ {
m_task = new CTaskFireAnt(m_object); return StartTask<CTaskFireAnt>(impact);
return (static_cast<CTaskFireAnt*>(m_task))->Start(impact);
} }
// Adjusts higher. // Adjusts higher.
Error CTaskManager::StartTaskGunGoal(float dirV, float dirH) Error CTaskManager::StartTaskGunGoal(float dirV, float dirH)
{ {
m_task = new CTaskGunGoal(m_object); return StartTask<CTaskGunGoal>(dirV, dirH);
return (static_cast<CTaskGunGoal*>(m_task))->Start(dirV, dirH);
} }
// Suicide of the spider. // Suicide of the spider.
Error CTaskManager::StartTaskSpiderExplo() Error CTaskManager::StartTaskSpiderExplo()
{ {
m_task = new CTaskSpiderExplo(m_object); return StartTask<CTaskSpiderExplo>();
return (static_cast<CTaskSpiderExplo*>(m_task))->Start();
} }
@ -224,7 +214,9 @@ Error CTaskManager::StartTaskSpiderExplo()
bool CTaskManager::EventProcess(const Event &event) bool CTaskManager::EventProcess(const Event &event)
{ {
if ( m_task == 0 ) return false; if (m_task == nullptr)
return false;
return m_task->EventProcess(event); return m_task->EventProcess(event);
} }
@ -233,7 +225,9 @@ bool CTaskManager::EventProcess(const Event &event)
Error CTaskManager::IsEnded() Error CTaskManager::IsEnded()
{ {
if ( m_task == 0 ) return ERR_UNKNOWN; if (m_task == nullptr)
return ERR_UNKNOWN;
return m_task->IsEnded(); return m_task->IsEnded();
} }
@ -242,7 +236,9 @@ Error CTaskManager::IsEnded()
bool CTaskManager::IsBusy() bool CTaskManager::IsBusy()
{ {
if ( m_task == 0 ) return false; if (m_task == nullptr)
return false;
return m_task->IsBusy(); return m_task->IsBusy();
} }
@ -260,6 +256,8 @@ bool CTaskManager::IsPilot()
bool CTaskManager::Abort() bool CTaskManager::Abort()
{ {
if ( m_task == 0 ) return false; if (m_task == nullptr)
return false;
return m_task->Abort(); return m_task->Abort();
} }

View File

@ -29,6 +29,7 @@
#include "object/task/taskmanip.h" #include "object/task/taskmanip.h"
#include "object/task/taskshield.h" #include "object/task/taskshield.h"
#include <memory>
class CTaskManager class CTaskManager
@ -64,7 +65,11 @@ public:
bool Abort(); bool Abort();
protected: protected:
CTask* m_task; template<typename TaskType, typename... Args>
COldObject* m_object; Error StartTask(Args&&... args);
bool m_bPilot;
protected:
std::unique_ptr<CTask> m_task;
COldObject* m_object = nullptr;
bool m_bPilot = false;
}; };

View File

@ -82,25 +82,25 @@ protected:
void SoundManip(float time, float amplitude=1.0f, float frequency=1.0f); void SoundManip(float time, float amplitude=1.0f, float frequency=1.0f);
protected: protected:
TaskManipOrder m_order; TaskManipOrder m_order = TMO_AUTO;
TaskManipArm m_arm; TaskManipArm m_arm = TMA_NEUTRAL;
TaskManipHand m_hand; TaskManipHand m_hand = TMH_OPEN;
int m_step; int m_step = 0;
float m_speed; float m_speed = 0.0f;
float m_progress; float m_progress = 0.0f;
float m_initialAngle[5]; float m_initialAngle[5] = {};
float m_finalAngle[5]; float m_finalAngle[5] = {};
float m_height; float m_height = 0.0f;
float m_advanceLength; float m_advanceLength = 0.0f;
float m_energy; float m_energy = 0.0f;
bool m_bError; bool m_bError = false;
bool m_bTurn; bool m_bTurn = false;
bool m_bSubm; bool m_bSubm = false;
bool m_bBee; bool m_bBee = false;
float m_angle; float m_angle = false;
float m_move; float m_move = false;
Math::Vector m_targetPos; Math::Vector m_targetPos;
float m_timeLimit; float m_timeLimit = false;
ObjectType m_cargoType; ObjectType m_cargoType = OBJECT_NULL;
}; };

View File

@ -57,16 +57,16 @@ protected:
int ColorToRank(TraceColor color); int ColorToRank(TraceColor color);
protected: protected:
bool m_bError; bool m_bError = false;
TaskPenPhase m_phase; TaskPenPhase m_phase = TPP_UP;
float m_progress; float m_progress = 0.0f;
float m_delay; float m_delay = 0.0f;
float m_time; float m_time = 0.0f;
float m_lastParticle; float m_lastParticle = 0.0f;
Math::Vector m_supportPos; Math::Vector m_supportPos;
float m_timeUp; float m_timeUp = 0.0f;
float m_oldAngle; float m_oldAngle = 0.0f;
float m_newAngle; float m_newAngle = 0.0f;
float m_timeDown; float m_timeDown = 0.0f;
}; };

View File

@ -55,16 +55,16 @@ protected:
CObject* SearchRuin(); CObject* SearchRuin();
protected: protected:
TaskRecoverPhase m_phase; TaskRecoverPhase m_phase = TRP_TURN;
float m_progress; float m_progress = 0.0f;
float m_speed; float m_speed = 0.0f;
float m_time; float m_time = 0.0f;
float m_angle; float m_angle = 0.0f;
float m_lastParticle; float m_lastParticle = 0.0f;
bool m_bError; bool m_bError = false;
CObject* m_ruin; CObject* m_ruin = nullptr;
CObject* m_metal; CObject* m_metal = nullptr;
Math::Vector m_recoverPos; Math::Vector m_recoverPos;
int m_soundChannel; int m_soundChannel = 0;
}; };

View File

@ -61,14 +61,14 @@ protected:
void DeleteMark(ObjectType type); void DeleteMark(ObjectType type);
protected: protected:
TaskSearchHand m_hand; TaskSearchHand m_hand = TSH_UP;
TaskSearchPhase m_phase; TaskSearchPhase m_phase = TSP_DOWN;
float m_progress; float m_progress = 0.0f;
float m_speed; float m_speed = 0.0f;
float m_time; float m_time = 0.0f;
float m_lastParticle; float m_lastParticle = 0.0f;
float m_initialAngle[3]; float m_initialAngle[3] = {};
float m_finalAngle[3]; float m_finalAngle[3] = {};
bool m_bError; bool m_bError = false;
}; };

View File

@ -71,19 +71,19 @@ protected:
float GetRadius(); float GetRadius();
protected: protected:
TaskShieldPhase m_phase; TaskShieldPhase m_phase = TS_UP1;
float m_progress; float m_progress = 0.0f;
float m_speed; float m_speed = 0.0f;
float m_time; float m_time = 0.0f;
float m_delay; float m_delay = 0.0f;
float m_lastParticle; float m_lastParticle = 0.0f;
float m_lastRay; float m_lastRay = 0.0f;
float m_lastIncrease; float m_lastIncrease = 0.0f;
float m_energyUsed; float m_energyUsed = 0.0f;
bool m_bError; bool m_bError = false;
Math::Vector m_shieldPos; Math::Vector m_shieldPos;
int m_rankSphere; int m_rankSphere = 0;
int m_soundChannel; int m_soundChannel = 0;
int m_effectLight; int m_effectLight = 0;
}; };

View File

@ -39,9 +39,7 @@ public:
bool Abort(); bool Abort();
protected: protected:
float m_time = 0.0f;
protected: bool m_bError = false;
float m_time;
bool m_bError;
}; };

View File

@ -64,15 +64,15 @@ protected:
bool IsFreeDeposeObject(Math::Vector pos); bool IsFreeDeposeObject(Math::Vector pos);
protected: protected:
TaskTakeOrder m_order; TaskTakeOrder m_order = TTO_TAKE;
TaskTakeArm m_arm; TaskTakeArm m_arm = TTA_NEUTRAL;
int m_step; int m_step = 0;
float m_speed; float m_speed = 0.0f;
float m_progress; float m_progress = 0.0f;
float m_height; float m_height = 0.0f;
bool m_bError; bool m_bError = false;
bool m_bTurn; bool m_bTurn = false;
float m_angle; float m_angle = 0.0f;
ObjectType m_cargoType; ObjectType m_cargoType = OBJECT_NULL;
}; };

View File

@ -53,13 +53,13 @@ protected:
bool Terraform(); bool Terraform();
protected: protected:
TaskTerraPhase m_phase; TaskTerraPhase m_phase = TTP_CHARGE;
float m_progress; float m_progress = 0.0f;
float m_speed; float m_speed = 0.0f;
float m_time; float m_time = 0.0f;
float m_lastParticle; float m_lastParticle = 0.0f;
int m_soundChannel; int m_soundChannel = 0;
bool m_bError; bool m_bError = false;
Math::Vector m_terraPos; Math::Vector m_terraPos;
}; };

View File

@ -38,12 +38,10 @@ public:
Error IsEnded(); Error IsEnded();
protected: protected:
float m_angle = 0.0f;
protected: float m_startAngle = 0.0f;
float m_angle; float m_finalAngle = 0.0f;
float m_startAngle; bool m_bLeft = false;
float m_finalAngle; bool m_bError = false;
bool m_bLeft;
bool m_bError;
}; };

View File

@ -38,10 +38,8 @@ public:
Error IsEnded(); Error IsEnded();
protected: protected:
float m_waitTime = 0.0f;
protected: float m_passTime = 0.0f;
float m_waitTime; bool m_bEnded = false;
float m_passTime;
bool m_bEnded;
}; };

View File

@ -118,6 +118,7 @@ CPhysics::CPhysics(COldObject* object)
m_fallingHeight = 0.0f; m_fallingHeight = 0.0f;
m_minFallingHeight = 20.0f; m_minFallingHeight = 20.0f;
m_fallDamageFraction = 0.007f; m_fallDamageFraction = 0.007f;
m_floorLevel = 0.0f;
} }
// Object's destructor. // Object's destructor.

View File

@ -66,12 +66,9 @@ CScript::CScript(COldObject* object)
m_interface = m_main->GetInterface(); m_interface = m_main->GetInterface();
m_pause = CPauseManager::GetInstancePointer(); m_pause = CPauseManager::GetInstancePointer();
m_botProg = nullptr;
m_ipf = CBOT_IPF; m_ipf = CBOT_IPF;
m_errMode = ERM_STOP; m_errMode = ERM_STOP;
m_len = 0; m_len = 0;
m_script = nullptr;
m_bRun = false; m_bRun = false;
m_bStepMode = false; m_bStepMode = false;
m_bCompile = false; m_bCompile = false;
@ -86,12 +83,6 @@ CScript::CScript(COldObject* object)
CScript::~CScript() CScript::~CScript()
{ {
delete m_botProg;
m_botProg = nullptr;
delete[] m_script;
m_script = nullptr;
m_len = 0; m_len = 0;
} }
@ -106,7 +97,7 @@ void CScript::PutScript(Ui::CEdit* edit, const char* name)
} }
else else
{ {
edit->SetText(m_script); edit->SetText(m_script.get());
edit->SetCursor(m_cursor2, m_cursor1); edit->SetCursor(m_cursor2, m_cursor1);
edit->ShowSelect(); edit->ShowSelect();
} }
@ -117,17 +108,12 @@ void CScript::PutScript(Ui::CEdit* edit, const char* name)
bool CScript::GetScript(Ui::CEdit* edit) bool CScript::GetScript(Ui::CEdit* edit)
{ {
int len; int len = edit->GetTextLength();
m_script = MakeUniqueArray<char>(len+1);
delete[] m_script; edit->GetText(m_script.get(), len+1);
m_script = nullptr;
len = edit->GetTextLength();
m_script = new char[len+1];
edit->GetText(m_script, len+1);
edit->GetCursor(m_cursor2, m_cursor1); edit->GetCursor(m_cursor2, m_cursor1);
m_len = strlen(m_script); m_len = strlen(m_script.get());
if ( !CheckToken() ) if ( !CheckToken() )
{ {
@ -159,9 +145,7 @@ bool CScript::GetCompile()
bool CScript::IsEmpty() bool CScript::IsEmpty()
{ {
int i; for (int i = 0; i < m_len; i++)
for ( i=0 ; i<m_len ; i++ )
{ {
if ( m_script[i] != ' ' && if ( m_script[i] != ' ' &&
m_script[i] != '\n' ) return false; m_script[i] != '\n' ) return false;
@ -194,7 +178,7 @@ bool CScript::CheckToken()
used[i] = 0; // token not used used[i] = 0; // token not used
} }
allBt = CBotToken::CompileTokens(m_script, error); allBt = CBotToken::CompileTokens(m_script.get(), error);
bt = allBt; bt = allBt;
while ( bt != 0 ) while ( bt != 0 )
{ {
@ -259,17 +243,16 @@ bool CScript::Compile()
if ( IsEmpty() ) // program exist? if ( IsEmpty() ) // program exist?
{ {
delete m_botProg; m_botProg.reset();
m_botProg = 0;
return true; return true;
} }
if ( m_botProg == 0 ) if (m_botProg == nullptr)
{ {
m_botProg = new CBotProgram(m_object->GetBotVar()); m_botProg = MakeUnique<CBotProgram>(m_object->GetBotVar());
} }
if ( m_botProg->Compile(m_script, liste, this) ) if ( m_botProg->Compile(m_script.get(), liste, this) )
{ {
if ( liste.GetSize() == 0 ) if ( liste.GetSize() == 0 )
{ {
@ -344,7 +327,7 @@ void CScript::SetStepMode(bool bStep)
bool CScript::Run() bool CScript::Run()
{ {
if( m_botProg == 0 ) return false; if (m_botProg == nullptr) return false;
if ( m_script == nullptr || m_len == 0 ) return false; if ( m_script == nullptr || m_len == 0 ) return false;
if ( m_mainFunction[0] == 0 ) return false; if ( m_mainFunction[0] == 0 ) return false;
@ -368,7 +351,7 @@ bool CScript::Run()
bool CScript::Continue() bool CScript::Continue()
{ {
if( m_botProg == 0 ) return true; if (m_botProg == nullptr) return true;
if ( !m_bRun ) return true; if ( !m_bRun ) return true;
if ( m_bStepMode ) // step by step mode? if ( m_bStepMode ) // step by step mode?
@ -440,7 +423,7 @@ bool CScript::Continue()
bool CScript::Step() bool CScript::Step()
{ {
if( m_botProg == 0 ) return true; if (m_botProg == nullptr) return true;
if ( !m_bRun ) return true; if ( !m_bRun ) return true;
if ( !m_bStepMode ) return false; if ( !m_bStepMode ) return false;
@ -490,7 +473,7 @@ void CScript::Stop()
m_taskExecutor->StopForegroundTask(); m_taskExecutor->StopForegroundTask();
if( m_botProg != 0 ) if (m_botProg != nullptr)
{ {
m_botProg->Stop(); m_botProg->Stop();
} }
@ -521,7 +504,7 @@ bool CScript::GetCursor(int &cursor1, int &cursor2)
cursor1 = cursor2 = 0; cursor1 = cursor2 = 0;
if( m_botProg == 0 ) return false; if (m_botProg == nullptr) return false;
if ( !m_bRun ) return false; if ( !m_bRun ) return false;
m_botProg->GetRunPos(funcName, cursor1, cursor2); m_botProg->GetRunPos(funcName, cursor1, cursor2);
@ -631,7 +614,7 @@ void CScript::UpdateList(Ui::CList* list)
const char *progName, *funcName; const char *progName, *funcName;
int total, select, level, cursor1, cursor2, rank; int total, select, level, cursor1, cursor2, rank;
if( m_botProg == 0 ) return; if (m_botProg == nullptr) return;
total = list->GetTotal(); total = list->GetTotal();
select = list->GetSelect(); select = list->GetSelect();
@ -800,7 +783,7 @@ bool CScript::IntroduceVirus()
int found[11*2]; int found[11*2];
for ( int i=0 ; i<11 ; i++ ) for ( int i=0 ; i<11 ; i++ )
{ {
int start = SearchToken(m_script, names[i*2]); int start = SearchToken(m_script.get(), names[i*2]);
if ( start != -1 ) if ( start != -1 )
{ {
found[iFound++] = i*2; found[iFound++] = i*2;
@ -813,14 +796,13 @@ bool CScript::IntroduceVirus()
int start = found[i+1]; int start = found[i+1];
i = found[i+0]; i = found[i+0];
char* newScript = new char[m_len+strlen(names[i+1])+1]; auto newScript = MakeUniqueArray<char>(m_len + strlen(names[i+1]) + 1);
strcpy(newScript, m_script); strcpy(newScript.get(), m_script.get());
delete[] m_script; m_script = std::move(newScript);
m_script = newScript;
DeleteToken(m_script, start, strlen(names[i])); DeleteToken(m_script.get(), start, strlen(names[i]));
InsertToken(m_script, start, names[i+1]); InsertToken(m_script.get(), start, names[i+1]);
m_len = strlen(m_script); m_len = strlen(m_script.get());
Compile(); // recompile with the virus Compile(); // recompile with the virus
return true; return true;
@ -1000,8 +982,7 @@ bool CScript::ReadScript(const char* filename)
if (!CResourceManager::Exists(filename)) return false; if (!CResourceManager::Exists(filename)) return false;
delete[] m_script; m_script.reset();
m_script = nullptr;
edit = m_interface->CreateEdit(Math::Point(0.0f, 0.0f), Math::Point(0.0f, 0.0f), 0, EVENT_EDIT9); edit = m_interface->CreateEdit(Math::Point(0.0f, 0.0f), Math::Point(0.0f, 0.0f), 0, EVENT_EDIT9);
edit->SetMaxChar(Ui::EDITSTUDIOMAX); edit->SetMaxChar(Ui::EDITSTUDIOMAX);
@ -1016,18 +997,16 @@ bool CScript::ReadScript(const char* filename)
bool CScript::WriteScript(const char* filename) bool CScript::WriteScript(const char* filename)
{ {
Ui::CEdit* edit;
if ( m_script == nullptr ) if ( m_script == nullptr )
{ {
CResourceManager::Remove(filename); CResourceManager::Remove(filename);
return false; return false;
} }
edit = m_interface->CreateEdit(Math::Point(0.0f, 0.0f), Math::Point(0.0f, 0.0f), 0, EVENT_EDIT9); Ui::CEdit* edit = m_interface->CreateEdit(Math::Point(0.0f, 0.0f), Math::Point(0.0f, 0.0f), 0, EVENT_EDIT9);
edit->SetMaxChar(Ui::EDITSTUDIOMAX); edit->SetMaxChar(Ui::EDITSTUDIOMAX);
edit->SetAutoIndent(m_engine->GetEditIndentMode()); edit->SetAutoIndent(m_engine->GetEditIndentMode());
edit->SetText(m_script); edit->SetText(m_script.get());
edit->WriteText(filename); edit->WriteText(filename);
m_interface->DeleteControl(EVENT_EDIT9); m_interface->DeleteControl(EVENT_EDIT9);
return true; return true;
@ -1044,7 +1023,7 @@ bool CScript::ReadStack(FILE *file)
fRead(&m_ipf, sizeof(int), 1, file); fRead(&m_ipf, sizeof(int), 1, file);
fRead(&m_errMode, sizeof(int), 1, file); fRead(&m_errMode, sizeof(int), 1, file);
if ( m_botProg == 0 ) return false; if (m_botProg == nullptr) return false;
if ( !m_botProg->RestoreState(file) ) return false; if ( !m_botProg->RestoreState(file) ) return false;
m_bRun = true; m_bRun = true;
@ -1073,7 +1052,7 @@ bool CScript::Compare(CScript* other)
{ {
if ( m_len != other->m_len ) return false; if ( m_len != other->m_len ) return false;
return ( strcmp(m_script, other->m_script) == 0 ); return ( strcmp(m_script.get(), other->m_script.get()) == 0 );
} }

View File

@ -28,6 +28,7 @@
#include "common/global.h" #include "common/global.h"
#include <memory>
#include <string> #include <string>
@ -101,31 +102,31 @@ protected:
bool Compile(); bool Compile();
protected: protected:
COldObject* m_object; COldObject* m_object = nullptr;
CTaskExecutorObject* m_taskExecutor; CTaskExecutorObject* m_taskExecutor = nullptr;
Gfx::CEngine* m_engine; Gfx::CEngine* m_engine = nullptr;
Ui::CInterface* m_interface; Ui::CInterface* m_interface = nullptr;
CBotProgram* m_botProg; std::unique_ptr<CBotProgram> m_botProg;
CRobotMain* m_main; CRobotMain* m_main = nullptr;
Gfx::CTerrain* m_terrain; Gfx::CTerrain* m_terrain = nullptr;
Gfx::CWater* m_water; Gfx::CWater* m_water = nullptr;
CPauseManager* m_pause; CPauseManager* m_pause = nullptr;
int m_ipf; // number of instructions/second int m_ipf = 0; // number of instructions/second
int m_errMode; // what to do in case of error int m_errMode = 0; // what to do in case of error
int m_len; // length of the script (without <0>) int m_len = 0; // length of the script (without <0>)
char* m_script; // script ends with <0> std::unique_ptr<char[]> m_script; // script ends with <0>
bool m_bRun; // program during execution? bool m_bRun = false; // program during execution?
bool m_bStepMode; // step by step bool m_bStepMode = false; // step by step
bool m_bContinue; // external function to continue bool m_bContinue = false; // external function to continue
bool m_bCompile; // compilation ok? bool m_bCompile = false; // compilation ok?
char m_title[50]; // script title char m_title[50] = {}; // script title
char m_mainFunction[50]; char m_mainFunction[50] = {};
char m_filename[50]; // file name char m_filename[50] = {}; // file name
char m_token[50]; // missing instruction char m_token[50] = {}; // missing instruction
int m_error; // error (0=ok) int m_error = 0; // error (0=ok)
int m_cursor1; int m_cursor1 = 0;
int m_cursor2; int m_cursor2 = 0;
float m_returnValue; float m_returnValue = 0.0f;
}; };

View File

@ -38,7 +38,8 @@ class LightManagerUT : public testing::Test
protected: protected:
LightManagerUT() : LightManagerUT() :
m_engine(nullptr), m_engine(nullptr),
m_device(nullptr) m_device(nullptr),
m_maxLightsCount(0)
{} {}
~LightManagerUT() NOEXCEPT ~LightManagerUT() NOEXCEPT
{} {}