Proper CAuto, CBrain, CMotion, CPhysics, CPyro lifetime management

* change manual memory manament to std::unique_ptr
 * create CPyroManager
 * finally get rid of CInstanceManager
master
Piotr Dziwinski 2015-06-22 21:58:58 +02:00
parent 7ae308cc75
commit 8806d1708d
30 changed files with 402 additions and 567 deletions

View File

@ -82,7 +82,6 @@ set(BASE_SOURCES
app/system_other.cpp
common/event.cpp
common/image.cpp
common/iman.cpp
common/key.cpp
common/logger.cpp
common/misc.cpp
@ -109,6 +108,7 @@ set(BASE_SOURCES
graphics/engine/particle.cpp
graphics/engine/planet.cpp
graphics/engine/pyro.cpp
graphics/engine/pyro_manager.cpp
graphics/engine/terrain.cpp
graphics/engine/text.cpp
graphics/engine/water.cpp

View File

@ -26,7 +26,6 @@
#include "app/system.h"
#include "common/logger.h"
#include "common/iman.h"
#include "common/image.h"
#include "common/key.h"
#include "common/pathman.h"
@ -103,7 +102,6 @@ struct ApplicationPrivate
CApplication::CApplication()
{
m_private = new ApplicationPrivate();
m_iMan = new CInstanceManager();
m_pathManager = new CPathManager();
m_eventQueue = new CEventQueue();
m_profile = new CProfile();
@ -181,9 +179,6 @@ CApplication::~CApplication()
delete m_pathManager;
m_pathManager = nullptr;
delete m_iMan;
m_iMan = nullptr;
GetSystemUtils()->DestroyTimeStamp(m_baseTimeStamp);
GetSystemUtils()->DestroyTimeStamp(m_curTimeStamp);
GetSystemUtils()->DestroyTimeStamp(m_lastTimeStamp);

View File

@ -37,7 +37,6 @@
#include <vector>
class CInstanceManager;
class CEventQueue;
class CController;
class CSoundInterface;
@ -151,7 +150,7 @@ struct ApplicationPrivate;
*
* \section Creation Creation of other main objects
*
* The class creates the only instance of CInstanceManager, CEventQueue, CEngine,
* The class creates the only instance of CEventQueue, CEngine,
* CRobotMain and CSoundInterface classes.
*
* \section Window Window management
@ -356,9 +355,6 @@ protected:
protected:
//! Private (SDL-dependent data)
ApplicationPrivate* m_private;
//! Instance manager
// TODO: to be removed
CInstanceManager* m_iMan;
//! Global event queue
CEventQueue* m_eventQueue;
//! Graphics engine

View File

@ -1,115 +0,0 @@
/*
* This file is part of the Colobot: Gold Edition source code
* Copyright (C) 2001-2014, Daniel Roux, EPSITEC SA & TerranovaTeam
* http://epsiteс.ch; http://colobot.info; http://github.com/colobot
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see http://gnu.org/licenses
*/
#include "common/iman.h"
#include <cassert>
template<> CInstanceManager* CSingleton<CInstanceManager>::m_instance = nullptr;
CInstanceManager::CInstanceManager()
{
for (int i = 0; i < CLASS_MAX; i++)
{
m_table[i].maxCount = 0;
m_table[i].usedCount = 0;
m_table[i].instances = nullptr;
}
}
CInstanceManager::~CInstanceManager()
{
Flush();
}
void CInstanceManager::Flush()
{
for (int i = 0; i < CLASS_MAX; i++)
{
delete[] m_table[i].instances;
m_table[i].instances = nullptr;
}
}
void CInstanceManager::Flush(ManagedClassType classType)
{
if (classType < 0 || classType >= CLASS_MAX) return;
if (m_table[classType].instances == nullptr) return;
delete[] m_table[classType].instances;
m_table[classType].instances = nullptr;
}
bool CInstanceManager::AddInstance(ManagedClassType classType, void* instance, int max)
{
if (classType < 0 || classType >= CLASS_MAX) return false;
if (m_table[classType].instances == nullptr)
{
m_table[classType].instances = new void*[max];
m_table[classType].maxCount = max;
m_table[classType].usedCount = 0;
}
if (m_table[classType].usedCount >= m_table[classType].maxCount) return false;
int i = m_table[classType].usedCount++;
m_table[classType].instances[i] = instance;
return true;
}
bool CInstanceManager::DeleteInstance(ManagedClassType classType, void* instance)
{
if (classType < 0 || classType >= CLASS_MAX) return false;
for (int i = 0; i < m_table[classType].usedCount; i++)
{
if (m_table[classType].instances[i] == instance)
m_table[classType].instances[i] = nullptr;
}
Compress(classType);
return true;
}
void* CInstanceManager::SearchInstance(ManagedClassType classType, int rank)
{
if (classType < 0 || classType >= CLASS_MAX) return nullptr;
if (m_table[classType].instances == nullptr) return nullptr;
if (rank >= m_table[classType].usedCount) return nullptr;
return m_table[classType].instances[rank];
}
void CInstanceManager::Compress(ManagedClassType classType)
{
if (classType < 0 || classType >= CLASS_MAX) return;
int j = 0;
for (int i = 0; i < m_table[classType].usedCount; i++)
{
if (m_table[classType].instances[i] != nullptr)
m_table[classType].instances[j++] = m_table[classType].instances[i];
}
m_table[classType].usedCount = j;
}

View File

@ -1,96 +0,0 @@
/*
* This file is part of the Colobot: Gold Edition source code
* Copyright (C) 2001-2014, Daniel Roux, EPSITEC SA & TerranovaTeam
* http://epsiteс.ch; http://colobot.info; http://github.com/colobot
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see http://gnu.org/licenses
*/
/**
* \file common/iman.h
* \brief Instance manager for managed classes
*/
#pragma once
#include "common/singleton.h"
/**
* \enum ManagedClassType
* \brief Type of class managed by CInstanceManager
*/
/*
* TODO: Non-unique classes have already been removed.
* The other class instances along with CInstanceManager will be removed in due course.
*/
enum ManagedClassType
{
//! CPhysics
CLASS_PHYSICS = 0,
//! CBrain
CLASS_BRAIN = 1,
//! Gfx::CPyro
CLASS_PYRO = 2,
//! Maximum (number of managed classes)
CLASS_MAX = 3
};
/**
* \struct ManagedClassInstances
* \brief Instances of class managed by CInstanceManager
*/
struct ManagedClassInstances
{
int maxCount;
int usedCount;
void** instances;
};
/**
* \class CInstanceManager
* \brief Manager for instances of certain classes
*
* Instance manager (often shortened to iMan) allows to register instances of
* classes and search them.
*/
class CInstanceManager : public CSingleton<CInstanceManager>
{
public:
CInstanceManager();
virtual ~CInstanceManager();
//! Remove all managed instances
void Flush();
//! Removes instances of one type of class
void Flush(ManagedClassType classType);
//! Registers new instance of class type
bool AddInstance(ManagedClassType classType, void* instance, int max=1);
//! Deletes the registered instance of class type
bool DeleteInstance(ManagedClassType classType, void* instance);
//! Seeks a class instance of given type
void* SearchInstance(ManagedClassType classType, int rank=0);
protected:
//! Fills holes in instance table
void Compress(ManagedClassType classType);
protected:
ManagedClassInstances m_table[CLASS_MAX];
};

View File

@ -35,7 +35,7 @@
#include "graphics/engine/modelmanager.h"
#include "graphics/engine/particle.h"
#include "graphics/engine/planet.h"
#include "graphics/engine/pyro.h"
#include "graphics/engine/pyro_manager.h"
#include "graphics/engine/terrain.h"
#include "graphics/engine/text.h"
#include "graphics/engine/water.h"
@ -245,6 +245,11 @@ CModelManager* CEngine::GetModelManager()
return m_modelManager.get();
}
CPyroManager* CEngine::GetPyroManager()
{
return m_pyroManager.get();
}
CText* CEngine::GetText()
{
return m_text;
@ -295,6 +300,7 @@ bool CEngine::Create()
m_size = m_app->GetVideoConfig().size;
m_modelManager.reset(new CModelManager(this));
m_pyroManager.reset(new CPyroManager());
m_lightMan = new CLightManager(this);
m_text = new CText(this);
m_particle = new CParticle(this);
@ -374,7 +380,7 @@ void CEngine::ResetAfterDeviceChanged()
m_text->FlushCache();
FlushTextureCache();
LoadAllTextures();
}
@ -489,7 +495,7 @@ bool CEngine::WriteScreenShot(const std::string& fileName, int width, int height
else{
GetLogger()->Error("%s!\n",img.GetError().c_str());
return false;
}
}
}
bool CEngine::GetPause()
@ -2220,7 +2226,7 @@ void CEngine::SetState(int state, const Color& color)
if (state & ENG_RSTATE_FOG)
m_device->SetRenderState(RENDER_STATE_FOG, true);
bool second = m_groundSpotVisible || m_dirty;
@ -3011,7 +3017,7 @@ void CEngine::SetTextureAnisotropyLevel(int value)
{
if (value < 1) value = 1;
if (value > 16) value = 16;
m_textureAnisotropy = value;
}
@ -3294,8 +3300,8 @@ void CEngine::Draw3DScene()
m_app->StartPerformanceCounter(PCNT_RENDER_TERRAIN);
// Draw terrain
// Draw terrain
m_lightMan->UpdateDeviceLights(ENG_OBJTYPE_TERRAIN);
UseShadowMapping(true);
@ -3359,7 +3365,7 @@ void CEngine::Draw3DScene()
// Draws the shadows , if shadows enabled
if (m_shadowVisible)
DrawShadow();
m_app->StopPerformanceCounter(PCNT_RENDER_TERRAIN);
@ -5017,17 +5023,17 @@ void CEngine::DrawStats()
pos.y -= height;
m_text->DrawText(m_fpsText, FONT_COLOBOT, 12.0f, pos, 1.0f, TEXT_ALIGN_LEFT, 0, Color(1.0f, 1.0f, 1.0f, 1.0f));
pos.y -= height;
pos.y -= height;
str.str("");
str << "Position x: " << std::fixed << std::setprecision(2) << m_statisticPos.x/g_unit;
m_text->DrawText(str.str(), FONT_COLOBOT, 12.0f, pos, 1.0f, TEXT_ALIGN_LEFT, 0, Color(1.0f, 1.0f, 1.0f, 1.0f));
pos.y -= height;
str.str("");
str << "Position y: " << std::fixed << std::setprecision(2) << m_statisticPos.z/g_unit;
m_text->DrawText(str.str(), FONT_COLOBOT, 12.0f, pos, 1.0f, TEXT_ALIGN_LEFT, 0, Color(1.0f, 1.0f, 1.0f, 1.0f));
@ -5036,7 +5042,7 @@ void CEngine::DrawStats()
void CEngine::DrawTimer()
{
SetState(ENG_RSTATE_TEXT);
Math::Point pos(0.98f, 0.98f-m_text->GetAscent(FONT_COLOBOT, 15.0f));
m_text->DrawText(m_timerText, FONT_COLOBOT, 15.0f, pos, 1.0f, TEXT_ALIGN_RIGHT, 0, Color(1.0f, 1.0f, 1.0f, 1.0f));
}

View File

@ -26,7 +26,6 @@
#include "app/system.h"
#include "app/pausemanager.h"
#include "common/event.h"
#include "common/singleton.h"
@ -55,6 +54,7 @@ class CApplication;
class CObject;
class CSoundInterface;
class CImage;
class CPauseManager;
// Graphics module namespace
@ -71,6 +71,7 @@ class CCloud;
class CLightning;
class CPlanet;
class CTerrain;
class CPyroManager;
/**
@ -697,6 +698,7 @@ public:
//! Returns the text rendering engine
CText* GetText();
CModelManager* GetModelManager();
CPyroManager* GetPyroManager();
//! Returns the light manager
CLightManager* GetLightManager();
//! Returns the particle manager
@ -1347,6 +1349,7 @@ protected:
CPlanet* m_planet;
CTerrain* m_terrain;
CPauseManager* m_pause;
std::unique_ptr<CPyroManager> m_pyroManager;
//! Last encountered error
std::string m_error;
@ -1524,7 +1527,7 @@ protected:
bool m_debugLights;
bool m_debugDumpLights;
std::string m_timerText;
};

View File

@ -22,7 +22,6 @@
#include "app/app.h"
#include "common/iman.h"
#include "common/logger.h"
#include "graphics/core/device.h"

View File

@ -22,7 +22,6 @@
#include "app/app.h"
#include "common/iman.h"
#include "common/logger.h"
#include "graphics/engine/lightman.h"
@ -42,8 +41,6 @@ namespace Gfx {
CPyro::CPyro()
{
CInstanceManager::GetInstancePointer()->AddInstance(CLASS_PYRO, this, 100);
m_engine = CEngine::GetInstancePointer();
m_main = CRobotMain::GetInstancePointer();
m_terrain = m_main->GetTerrain();
@ -62,7 +59,6 @@ CPyro::CPyro()
CPyro::~CPyro()
{
CInstanceManager::GetInstancePointer()->DeleteInstance(CLASS_PYRO, this);
}
void CPyro::DeleteObject()

View File

@ -28,9 +28,10 @@
#include "common/event.h"
#include "common/global.h"
#include "graphics/engine/engine.h"
#include "graphics/core/color.h"
#include "graphics/engine/pyro_type.h"
#include "object/object.h"
#include "object/object_type.h"
class CObject;
@ -46,40 +47,7 @@ class CTerrain;
class CCamera;
class CParticle;
class CLight;
/**
* \enum PyroType
* \brief Type of pyro effect
*/
enum PyroType
{
PT_NULL = 0,
PT_FRAGT = 1, //! < fragmentation of technical object
PT_FRAGO = 2, //! < fragmentation of organic object
PT_FRAGW = 4, //! < fragmentation of object under water
PT_EXPLOT = 5, //! < explosion of technical object
PT_EXPLOO = 6, //! < explosion of organic object
PT_EXPLOW = 8, //! < explosion of object under water
PT_SHOTT = 9, //! < hit technical object
PT_SHOTH = 10, //! < hit human
PT_SHOTM = 11, //! < hit queen
PT_SHOTW = 12, //! < hit under water
PT_EGG = 13, //! < break the egg
PT_BURNT = 14, //! < burning of technical object
PT_BURNO = 15, //! < burning of organic object
PT_SPIDER = 16, //! < spider explosion
PT_FALL = 17, //! < cargo falling
PT_WPCHECK = 18, //! < indicator reaches
PT_FLCREATE = 19, //! < flag create
PT_FLDELETE = 20, //! < flag destroy
PT_RESET = 21, //! < reset position of the object
PT_WIN = 22, //! < fireworks
PT_LOST = 23, //! < black smoke
PT_DEADG = 24, //! < shooting death
PT_DEADW = 25, //! < drowning death
PT_FINDING = 26, //! < object discovered
};
class CLightManager;
struct PyroBurnPart
@ -107,15 +75,18 @@ struct PyroLightOper
*/
class CPyro
{
public:
CPyro();
~CPyro();
protected:
friend class CPyroManager;
CPyro();
//! Creates pyrotechnic effect
bool Create(PyroType type, CObject* obj, float force=1.0f);
bool Create(PyroType type, CObject* obj, float force);
//! Destroys the object
void DeleteObject();
public:
~CPyro();
//! Indicates whether the pyrotechnic effect is complete
Error IsEnded();

View File

@ -0,0 +1,72 @@
/*
* This file is part of the Colobot: Gold Edition source code
* Copyright (C) 2001-2014, Daniel Roux, EPSITEC SA & TerranovaTeam
* http://epsiteс.ch; http://colobot.info; http://github.com/colobot
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see http://gnu.org/licenses
*/
#include "graphics/engine/pyro_manager.h"
#include "graphics/engine/pyro.h"
namespace Gfx {
Gfx::CPyroManager::CPyroManager()
{}
CPyroManager::~CPyroManager()
{}
void Gfx::CPyroManager::Create(PyroType type, CObject* obj, float force)
{
CPyroUPtr pyroUPtr{new CPyro()};
pyroUPtr->Create(type, obj, force);
m_pyros.insert(std::move(pyroUPtr));
}
void CPyroManager::DeleteAll()
{
for (auto& pyro : m_pyros)
{
pyro->DeleteObject();
}
m_pyros.clear();
}
void Gfx::CPyroManager::CutObjectLink(CObject* obj)
{
for (auto& pyro : m_pyros)
{
pyro->CutObjectLink(obj);
}
}
void Gfx::CPyroManager::EventProcess(const Event& event)
{
auto it = m_pyros.begin();
while (it != m_pyros.end())
{
(*it)->EventProcess(event);
if ((*it)->IsEnded())
{
(*it)->DeleteObject();
it = m_pyros.erase(it);
}
}
}
} // namespace Gfx

View File

@ -0,0 +1,57 @@
/*
* This file is part of the Colobot: Gold Edition source code
* Copyright (C) 2001-2014, Daniel Roux, EPSITEC SA & TerranovaTeam
* http://epsiteс.ch; http://colobot.info; http://github.com/colobot
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see http://gnu.org/licenses
*/
/**
* \file graphics/engine/pyro_manager.h
* \brief Manager for CPyro objects
*/
#pragma once
#include "graphics/engine/pyro_type.h"
#include <memory>
#include <set>
struct Event;
class CObject;
namespace Gfx {
class CPyro;
using CPyroUPtr = std::unique_ptr<CPyro>;
class CPyroManager
{
public:
CPyroManager();
~CPyroManager();
void Create(PyroType type, CObject* obj, float force=1.0f);
void DeleteAll();
void CutObjectLink(CObject* obj);
void EventProcess(const Event& event);
private:
std::set<CPyroUPtr> m_pyros;
};
} // namespace Gfx

View File

@ -0,0 +1,62 @@
/*
* This file is part of the Colobot: Gold Edition source code
* Copyright (C) 2001-2014, Daniel Roux, EPSITEC SA & TerranovaTeam
* http://epsiteс.ch; http://colobot.info; http://github.com/colobot
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see http://gnu.org/licenses
*/
/**
* \file graphics/engine/pyro_type.h
* \brief PyroType enum
*/
#pragma once
namespace Gfx {
/**
* \enum PyroType
* \brief Type of pyro effect
*/
enum PyroType
{
PT_NULL = 0,
PT_FRAGT = 1, //! < fragmentation of technical object
PT_FRAGO = 2, //! < fragmentation of organic object
PT_FRAGW = 4, //! < fragmentation of object under water
PT_EXPLOT = 5, //! < explosion of technical object
PT_EXPLOO = 6, //! < explosion of organic object
PT_EXPLOW = 8, //! < explosion of object under water
PT_SHOTT = 9, //! < hit technical object
PT_SHOTH = 10, //! < hit human
PT_SHOTM = 11, //! < hit queen
PT_SHOTW = 12, //! < hit under water
PT_EGG = 13, //! < break the egg
PT_BURNT = 14, //! < burning of technical object
PT_BURNO = 15, //! < burning of organic object
PT_SPIDER = 16, //! < spider explosion
PT_FALL = 17, //! < cargo falling
PT_WPCHECK = 18, //! < indicator reaches
PT_FLCREATE = 19, //! < flag create
PT_FLDELETE = 20, //! < flag destroy
PT_RESET = 21, //! < reset position of the object
PT_WIN = 22, //! < fireworks
PT_LOST = 23, //! < black smoke
PT_DEADG = 24, //! < shooting death
PT_DEADW = 25, //! < drowning death
PT_FINDING = 26, //! < object discovered
};
} // namespace Gfx

View File

@ -20,6 +20,8 @@
#include "object/auto/autodestroyer.h"
#include "graphics/engine/pyro_manager.h"
#include "object/object_manager.h"
#include "object/level/parserline.h"
#include "object/level/parserparam.h"
@ -110,7 +112,6 @@ Error CAutoDestroyer::StartAction(int param)
bool CAutoDestroyer::EventProcess(const Event &event)
{
CObject* scrap;
Gfx::CPyro* pyro;
Math::Vector pos, speed;
Math::Point dim;
Ui::CWindow* pw;
@ -168,8 +169,7 @@ bool CAutoDestroyer::EventProcess(const Event &event)
scrap = SearchPlastic();
if ( scrap != nullptr )
{
pyro = new Gfx::CPyro();
pyro->Create(Gfx::PT_FRAGT, scrap);
m_engine->GetPyroManager()->Create(Gfx::PT_FRAGT, scrap);
}
m_bExplo = true;
}

View File

@ -20,6 +20,8 @@
#include "object/auto/autoegg.h"
#include "graphics/engine/pyro_manager.h"
#include "math/geometry.h"
#include "object/brain.h"
@ -214,7 +216,6 @@ bool CAutoEgg::EventProcess(const Event &event)
Error CAutoEgg::IsEnded()
{
CObject* alien;
Gfx::CPyro* pyro;
if ( m_phase == AEP_DELAY )
{
@ -237,8 +238,7 @@ Error CAutoEgg::IsEnded()
{
if ( m_progress < 1.0f ) return ERR_CONTINUE;
pyro = new Gfx::CPyro();
pyro->Create(Gfx::PT_EGG, m_object); // exploding egg
m_engine->GetPyroManager()->Create(Gfx::PT_EGG, m_object); // exploding egg
alien->SetZoom(0, 1.0f); // this is a big boy now

View File

@ -22,7 +22,6 @@
#include "app/app.h"
#include "common/iman.h"
#include "common/misc.h"
#include "graphics/core/color.h"
@ -56,8 +55,6 @@ const int MAXTRACERECORD = 1000;
CBrain::CBrain(CObject* object)
{
CInstanceManager::GetInstancePointer()->AddInstance(CLASS_BRAIN, this, 100);
m_object = object;
m_engine = Gfx::CEngine::GetInstancePointer();
m_water = m_engine->GetWater();
@ -124,8 +121,6 @@ CBrain::~CBrain()
delete[] m_traceRecordBuffer;
m_traceRecordBuffer = nullptr;
CInstanceManager::GetInstancePointer()->DeleteInstance(CLASS_BRAIN, this);
}

View File

@ -26,7 +26,7 @@
#include "graphics/core/color.h"
#include "graphics/engine/water.h"
#include "graphics/engine/pyro.h"
#include "graphics/engine/pyro_type.h"
#include "math/point.h"

View File

@ -25,14 +25,13 @@
#include "app/app.h"
#include "common/global.h"
#include "common/iman.h"
#include "common/restext.h"
#include "graphics/engine/lightman.h"
#include "graphics/engine/lightning.h"
#include "graphics/engine/modelmanager.h"
#include "graphics/engine/particle.h"
#include "graphics/engine/pyro.h"
#include "graphics/engine/pyro_manager.h"
#include "graphics/engine/terrain.h"
#include "math/geometry.h"
@ -201,10 +200,6 @@ CObject::CObject(int id)
m_main = CRobotMain::GetInstancePointer();
m_terrain = m_main->GetTerrain();
m_camera = m_main->GetCamera();
m_physics = nullptr;
m_brain = nullptr;
m_motion = nullptr;
m_auto = nullptr;
m_runScript = nullptr;
m_type = OBJECT_FIX;
@ -321,23 +316,12 @@ CObject::CObject(int id)
CObject::~CObject()
{
if ( m_botVar != 0 )
if ( m_botVar != nullptr )
{
m_botVar->SetUserPtr(OBJECTDELETED);
delete m_botVar;
m_botVar = nullptr;
}
delete m_physics;
m_physics = nullptr;
delete m_brain;
m_brain = nullptr;
delete m_motion;
m_motion = nullptr;
delete m_auto;
m_auto = nullptr;
m_app = nullptr;
}
@ -357,9 +341,6 @@ void CObject::DeleteObject(bool bAll)
m_camera->SetControllingObject(0);
}
CInstanceManager* iMan = CInstanceManager::GetInstancePointer();
for (CObject* obj : CObjectManager::GetInstancePointer()->GetAllObjects())
{
obj->DeleteDeselList(this);
@ -388,13 +369,7 @@ void CObject::DeleteObject(bool bAll)
}
}
#endif
for (int i=0 ; i<1000000 ; i++ )
{
Gfx::CPyro* pyro = static_cast<Gfx::CPyro*>(iMan->SearchInstance(CLASS_PYRO, i));
if ( pyro == nullptr ) break;
pyro->CutObjectLink(this); // the object no longer exists
}
m_engine->GetPyroManager()->CutObjectLink(this);
if ( m_bSelect )
{
@ -445,22 +420,22 @@ void CObject::DeleteObject(bool bAll)
m_effectLight = -1;
}
if ( m_physics != 0 )
if ( m_physics != nullptr )
{
m_physics->DeleteObject(bAll);
}
if ( m_brain != 0 )
if ( m_brain != nullptr )
{
m_brain->DeleteObject(bAll);
}
if ( m_motion != 0 )
if ( m_motion != nullptr )
{
m_motion->DeleteObject(bAll);
}
if ( m_auto != 0 )
if ( m_auto != nullptr )
{
m_auto->DeleteObject(bAll);
}
@ -493,38 +468,34 @@ void CObject::DeleteObject(bool bAll)
void CObject::Simplify()
{
if ( m_brain != 0 )
if ( m_brain != nullptr )
{
m_brain->StopProgram();
}
m_main->SaveOneScript(this);
if ( m_physics != 0 )
if ( m_physics != nullptr )
{
m_physics->DeleteObject();
delete m_physics;
m_physics = 0;
m_physics.reset();
}
if ( m_brain != 0 )
if ( m_brain != nullptr )
{
m_brain->DeleteObject();
delete m_brain;
m_brain = 0;
m_brain.reset();
}
if ( m_motion != 0 )
if ( m_motion != nullptr )
{
m_motion->DeleteObject();
delete m_motion;
m_motion = 0;
m_motion.reset();
}
if ( m_auto != 0 )
if ( m_auto != nullptr )
{
m_auto->DeleteObject();
delete m_auto;
m_auto = 0;
m_auto.reset();
}
m_main->CreateShortcuts();
@ -538,7 +509,6 @@ void CObject::Simplify()
bool CObject::ExploObject(ExploType type, float force, float decay)
{
Gfx::PyroType pyroType;
Gfx::CPyro* pyro;
float loss, shield;
if ( type == EXPLO_BURN )
@ -722,12 +692,11 @@ bool CObject::ExploObject(ExploType type, float force, float decay)
loss = 1.0f;
}
pyro = new Gfx::CPyro();
pyro->Create(pyroType, this, loss);
m_engine->GetPyroManager()->Create(pyroType, this, loss);
if ( shield == 0.0f ) // dead?
{
if ( m_brain != 0 )
if ( m_brain != nullptr )
{
m_brain->StopProgram();
}
@ -1335,7 +1304,7 @@ void CObject::SetFloorHeight(float height)
pos = m_objectPart[0].position;
m_terrain->AdjustToFloor(pos);
if ( m_physics != 0 )
if ( m_physics != nullptr )
{
m_physics->SetLand(height == 0.0f);
m_physics->SetMotor(height != 0.0f);
@ -1444,7 +1413,7 @@ void CObject::SetPosition(int part, const Math::Vector &pos)
m_terrain->AdjustToFloor(shPos, true);
m_engine->SetObjectShadowPos(rank, shPos);
if ( m_physics != 0 && m_physics->GetType() == TYPE_FLYING )
if ( m_physics != nullptr && m_physics->GetType() == TYPE_FLYING )
{
height = pos.y-shPos.y;
}
@ -2084,7 +2053,7 @@ bool CObject::CreateShadowCircle(float radius, float intensity,
bool CObject::ReadProgram(Program* program, const char* filename)
{
if ( m_brain != 0 )
if ( m_brain != nullptr )
{
return m_brain->ReadProgram(program, filename);
}
@ -2095,7 +2064,7 @@ bool CObject::ReadProgram(Program* program, const char* filename)
bool CObject::WriteProgram(Program* program, char* filename)
{
if ( m_brain != 0 )
if ( m_brain != nullptr )
{
return m_brain->WriteProgram(program, filename);
}
@ -2393,7 +2362,7 @@ bool CObject::EventProcess(const Event &event)
#endif
}
if ( m_physics != 0 )
if ( m_physics != nullptr )
{
if ( !m_physics->EventProcess(event) ) // object destroyed?
{
@ -2409,7 +2378,7 @@ bool CObject::EventProcess(const Event &event)
}
}
if ( m_auto != 0 )
if ( m_auto != nullptr )
{
m_auto->EventProcess(event);
@ -2417,12 +2386,11 @@ bool CObject::EventProcess(const Event &event)
m_auto->IsEnded() != ERR_CONTINUE )
{
m_auto->DeleteObject();
delete m_auto;
m_auto = 0;
m_auto.reset();
}
}
if ( m_motion != 0 )
if ( m_motion != nullptr )
{
m_motion->EventProcess(event);
}
@ -2460,19 +2428,14 @@ bool CObject::EventFrame(const Event &event)
if ( m_bProxyActivate ) // active if it is near?
{
Gfx::CPyro* pyro;
Math::Vector eye;
float dist;
eye = m_engine->GetLookatPt();
dist = Math::Distance(eye, GetPosition(0));
Math::Vector eye = m_engine->GetLookatPt();
float dist = Math::Distance(eye, GetPosition(0));
if ( dist < m_proxyDistance )
{
m_bProxyActivate = false;
m_main->CreateShortcuts();
m_sound->Play(SOUND_FINDING);
pyro = new Gfx::CPyro();
pyro->Create(Gfx::PT_FINDING, this, 0.0f);
m_engine->GetPyroManager()->Create(Gfx::PT_FINDING, this, 0.0f);
m_main->DisplayError(INFO_FINDING, this);
}
}
@ -2694,7 +2657,7 @@ void CObject::SetViewFromHere(Math::Vector &eye, float &dirH, float &dirV,
// Camera tilts when turning.
upVec = Math::Vector(0.0f, 1.0f, 0.0f);
if ( m_physics != 0 )
if ( m_physics != nullptr )
{
if ( m_physics->GetLand() ) // on ground?
{
@ -2935,17 +2898,17 @@ bool CObject::JostleObject(float force)
m_type == OBJECT_FLAGy ||
m_type == OBJECT_FLAGv ) // flag?
{
if ( m_auto == 0 ) return false;
if ( m_auto == nullptr ) return false;
m_auto->Start(1);
}
else
{
if ( m_auto != 0 ) return false;
if ( m_auto != nullptr ) return false;
m_auto = new CAutoJostle(this);
CAutoJostle* pa = static_cast<CAutoJostle*>(m_auto);
pa->Start(0, force);
std::unique_ptr<CAutoJostle> autoJostle{new CAutoJostle(this)};
autoJostle->Start(0, force);
m_auto = std::move(autoJostle);
}
return true;
@ -3000,7 +2963,7 @@ void CObject::SetVirusMode(bool bEnable)
m_bVirusMode = bEnable;
m_virusTime = 0.0f;
if ( m_bVirusMode && m_brain != 0 )
if ( m_bVirusMode && m_brain != nullptr )
{
if ( !m_brain->IntroduceVirus() ) // tries to infect
{
@ -3093,12 +3056,12 @@ void CObject::SetSelect(bool bMode, bool bDisplayError)
m_bSelect = bMode;
if ( m_physics != 0 )
if ( m_physics != nullptr )
{
m_physics->CreateInterface(m_bSelect);
}
if ( m_auto != 0 )
if ( m_auto != nullptr )
{
m_auto->CreateInterface(m_bSelect);
}
@ -3112,11 +3075,11 @@ void CObject::SetSelect(bool bMode, bool bDisplayError)
}
err = ERR_OK;
if ( m_physics != 0 )
if ( m_physics != nullptr )
{
err = m_physics->GetError();
}
if ( m_auto != 0 )
if ( m_auto != nullptr )
{
err = m_auto->GetError();
}
@ -3154,7 +3117,7 @@ bool CObject::GetSelectable()
void CObject::SetActivity(bool bMode)
{
if ( m_brain != 0 )
if ( m_brain != nullptr )
{
m_brain->SetActivity(bMode);
}
@ -3162,7 +3125,7 @@ void CObject::SetActivity(bool bMode)
bool CObject::GetActivity()
{
if ( m_brain != 0 )
if ( m_brain != nullptr )
{
return m_brain->GetActivity();
}
@ -3340,7 +3303,7 @@ void CObject::SetDead(bool bDead)
{
m_bDead = bDead;
if ( bDead && m_brain != 0 )
if ( bDead && m_brain != nullptr )
{
m_brain->StopProgram(); // stops the current task
}
@ -3475,7 +3438,7 @@ void CObject::SetShowLimitRadius(float radius)
bool CObject::IsProgram()
{
if ( m_brain == 0 ) return false;
if ( m_brain == nullptr ) return false;
return m_brain->IsProgram();
}
@ -3718,48 +3681,48 @@ CBotVar* CObject::GetBotVar()
CPhysics* CObject::GetPhysics()
{
return m_physics;
return m_physics.get();
}
void CObject::SetPhysics(CPhysics* physics)
void CObject::SetPhysics(std::unique_ptr<CPhysics> physics)
{
m_physics = physics;
m_physics = std::move(physics);
}
// Returns the brain associated to the object.
CBrain* CObject::GetBrain()
{
return m_brain;
return m_brain.get();
}
void CObject::SetBrain(CBrain* brain)
void CObject::SetBrain(std::unique_ptr<CBrain> brain)
{
m_brain = brain;
m_brain = std::move(brain);
}
// Returns the movement associated to the object.
CMotion* CObject::GetMotion()
{
return m_motion;
return m_motion.get();
}
void CObject::SetMotion(CMotion* motion)
void CObject::SetMotion(std::unique_ptr<CMotion> motion)
{
m_motion = motion;
m_motion = std::move(motion);
}
// Returns the controller associated to the object.
CAuto* CObject::GetAuto()
{
return m_auto;
return m_auto.get();
}
void CObject::SetAuto(CAuto* automat)
void CObject::SetAuto(std::unique_ptr<CAuto> automat)
{
m_auto = automat;
m_auto = std::move(automat);
}
@ -3837,7 +3800,7 @@ void CObject::DeleteDeselList(CObject* pObj)
bool CObject::GetTraceDown()
{
if (m_motion == nullptr) return false;
CMotionVehicle* mv = dynamic_cast<CMotionVehicle*>(m_motion);
CMotionVehicle* mv = dynamic_cast<CMotionVehicle*>(m_motion.get());
if (mv == nullptr)
{
GetLogger()->Trace("GetTraceDown() invalid m_motion class!\n");
@ -3849,7 +3812,7 @@ bool CObject::GetTraceDown()
void CObject::SetTraceDown(bool bDown)
{
if (m_motion == nullptr) return;
CMotionVehicle* mv = dynamic_cast<CMotionVehicle*>(m_motion);
CMotionVehicle* mv = dynamic_cast<CMotionVehicle*>(m_motion.get());
if (mv == nullptr)
{
GetLogger()->Trace("SetTraceDown() invalid m_motion class!\n");
@ -3861,7 +3824,7 @@ void CObject::SetTraceDown(bool bDown)
int CObject::GetTraceColor()
{
if (m_motion == nullptr) return 0;
CMotionVehicle* mv = dynamic_cast<CMotionVehicle*>(m_motion);
CMotionVehicle* mv = dynamic_cast<CMotionVehicle*>(m_motion.get());
if (mv == nullptr)
{
GetLogger()->Trace("GetTraceColor() invalid m_motion class!\n");
@ -3873,7 +3836,7 @@ int CObject::GetTraceColor()
void CObject::SetTraceColor(int color)
{
if (m_motion == nullptr) return;
CMotionVehicle* mv = dynamic_cast<CMotionVehicle*>(m_motion);
CMotionVehicle* mv = dynamic_cast<CMotionVehicle*>(m_motion.get());
if (mv == nullptr)
{
GetLogger()->Trace("SetTraceColor() invalid m_motion class!\n");
@ -3885,7 +3848,7 @@ void CObject::SetTraceColor(int color)
float CObject::GetTraceWidth()
{
if (m_motion == nullptr) return 0.0f;
CMotionVehicle* mv = dynamic_cast<CMotionVehicle*>(m_motion);
CMotionVehicle* mv = dynamic_cast<CMotionVehicle*>(m_motion.get());
if (mv == nullptr)
{
GetLogger()->Trace("GetTraceWidth() invalid m_motion class!\n");
@ -3897,7 +3860,7 @@ float CObject::GetTraceWidth()
void CObject::SetTraceWidth(float width)
{
if (m_motion == nullptr) return;
CMotionVehicle* mv = dynamic_cast<CMotionVehicle*>(m_motion);
CMotionVehicle* mv = dynamic_cast<CMotionVehicle*>(m_motion.get());
if (mv == nullptr)
{
GetLogger()->Trace("SetTraceWidth() invalid m_motion class!\n");

View File

@ -137,9 +137,15 @@ class CObject
{
friend class CObjectFactory;
friend class CObjectManager;
protected:
CObject(int id);
void DeleteObject(bool bAll=false);
void SetPhysics(std::unique_ptr<CPhysics> physics);
void SetBrain(std::unique_ptr<CBrain> brain);
void SetMotion(std::unique_ptr<CMotion> motion);
void SetAuto(std::unique_ptr<CAuto> automat);
public:
CObject(const CObject&) = delete;
@ -389,13 +395,9 @@ public:
CScript* GetRunScript();
CBotVar* GetBotVar();
CPhysics* GetPhysics();
void SetPhysics(CPhysics* physics);
CBrain* GetBrain();
void SetBrain(CBrain* brain);
CMotion* GetMotion();
void SetMotion(CMotion* motion);
CAuto* GetAuto();
void SetAuto(CAuto* automat);
void SetDefRank(int rank);
int GetDefRank();
@ -442,10 +444,10 @@ protected:
Gfx::CWater* m_water;
Gfx::CCamera* m_camera;
Gfx::CParticle* m_particle;
CPhysics* m_physics;
CBrain* m_brain;
CMotion* m_motion;
CAuto* m_auto;
std::unique_ptr<CPhysics> m_physics;
std::unique_ptr<CBrain> m_brain;
std::unique_ptr<CMotion> m_motion;
std::unique_ptr<CAuto> m_auto;
CRobotMain* m_main;
CSoundInterface* m_sound;
CBotVar* m_botVar;

View File

@ -3483,9 +3483,9 @@ CObjectUPtr CObjectFactory::CreateVehicle(const ObjectCreateParams& params)
if ( type == OBJECT_TOTO )
{
CMotion* motion = new CMotionToto(obj.get());
std::unique_ptr<CMotion> motion{new CMotionToto(obj.get())};
motion->Create(pos, angle, type, 1.0f, m_modelManager);
obj->SetMotion(motion);
obj->SetMotion(std::move(motion));
return obj;
}
@ -3501,15 +3501,6 @@ CObjectUPtr CObjectFactory::CreateVehicle(const ObjectCreateParams& params)
obj->SetToy(toy);
CPhysics* physics = new CPhysics(obj.get());
CBrain* brain = new CBrain(obj.get());
physics->SetBrain(brain);
brain->SetPhysics(physics);
obj->SetPhysics(physics);
obj->SetBrain(brain);
float showLimitRadius = 0.0f;
#if 0
if ( type == OBJECT_MOBILEfc ||
@ -3541,29 +3532,36 @@ CObjectUPtr CObjectFactory::CreateVehicle(const ObjectCreateParams& params)
}
obj->SetShowLimitRadius(showLimitRadius);
CMotion* motion = nullptr;
std::unique_ptr<CPhysics> physics{new CPhysics(obj.get())};
std::unique_ptr<CBrain> brain{new CBrain(obj.get())};
std::unique_ptr<CMotion> motion;
if ( type == OBJECT_HUMAN ||
type == OBJECT_TECH )
{
motion = new CMotionHuman(obj.get());
motion.reset(new CMotionHuman(obj.get()));
}
else if ( type == OBJECT_CONTROLLER )
{
motion = new CMotionDummy(obj.get()); //dummy object
motion.reset(new CMotionDummy(obj.get())); //dummy object
}
else
{
motion = new CMotionVehicle(obj.get());
motion.reset(new CMotionVehicle(obj.get()));
}
physics->SetMotion(motion);
brain->SetMotion(motion);
motion->SetPhysics(physics);
motion->SetBrain(brain);
brain->SetMotion(motion.get());
brain->SetPhysics(physics.get());
motion->SetBrain(brain.get());
motion->SetPhysics(physics.get());
physics->SetBrain(brain.get());
physics->SetMotion(motion.get());
motion->Create(pos, angle, type, power, m_modelManager);
obj->SetMotion(motion);
obj->SetBrain(std::move(brain));
obj->SetMotion(std::move(motion));
obj->SetPhysics(std::move(physics));
return obj;
}
@ -3580,45 +3578,44 @@ CObjectUPtr CObjectFactory::CreateInsect(const ObjectCreateParams& params)
obj->SetType(type);
CPhysics* physics = new CPhysics(obj.get());
CBrain* brain = new CBrain(obj.get());
std::unique_ptr<CPhysics> physics{new CPhysics(obj.get())};
std::unique_ptr<CBrain> brain{new CBrain(obj.get())};
physics->SetBrain(brain);
brain->SetPhysics(physics);
obj->SetPhysics(physics);
obj->SetBrain(brain);
CMotion* motion = nullptr;
std::unique_ptr<CMotion> motion;
if ( type == OBJECT_MOTHER )
{
motion = new CMotionMother(obj.get());
motion.reset(new CMotionMother(obj.get()));
}
if ( type == OBJECT_ANT )
{
motion = new CMotionAnt(obj.get());
motion.reset(new CMotionAnt(obj.get()));
}
if ( type == OBJECT_SPIDER )
{
motion = new CMotionSpider(obj.get());
motion.reset(new CMotionSpider(obj.get()));
}
if ( type == OBJECT_BEE )
{
motion = new CMotionBee(obj.get());
motion.reset(new CMotionBee(obj.get()));
}
if ( type == OBJECT_WORM )
{
motion = new CMotionWorm(obj.get());
motion.reset(new CMotionWorm(obj.get()));
}
assert(motion != nullptr);
physics->SetMotion(motion);
brain->SetMotion(motion);
motion->SetPhysics(physics);
motion->SetBrain(brain);
physics->SetBrain(brain.get());
physics->SetMotion(motion.get());
brain->SetMotion(motion.get());
brain->SetPhysics(physics.get());
motion->SetBrain(brain.get());
motion->SetPhysics(physics.get());
motion->Create(pos, angle, type, 0.0f, m_modelManager);
obj->SetMotion(motion);
obj->SetMotion(std::move(motion));
obj->SetPhysics(std::move(physics));
obj->SetBrain(std::move(brain));
return obj;
}
@ -3627,97 +3624,97 @@ CObjectUPtr CObjectFactory::CreateInsect(const ObjectCreateParams& params)
void CObjectFactory::AddObjectAuto(CObject* obj)
{
CAuto* objAuto = nullptr;
std::unique_ptr<CAuto> objAuto;
auto type = obj->GetType();
if ( type == OBJECT_BASE )
{
objAuto = new CAutoBase(obj);
objAuto.reset(new CAutoBase(obj));
}
if ( type == OBJECT_PORTICO )
{
objAuto = new CAutoPortico(obj);
objAuto.reset(new CAutoPortico(obj));
}
if ( type == OBJECT_DERRICK )
{
objAuto = new CAutoDerrick(obj);
objAuto.reset(new CAutoDerrick(obj));
}
if ( type == OBJECT_FACTORY )
{
objAuto = new CAutoFactory(obj);
objAuto.reset(new CAutoFactory(obj));
}
if ( type == OBJECT_REPAIR )
{
objAuto = new CAutoRepair(obj);
objAuto.reset(new CAutoRepair(obj));
}
if ( type == OBJECT_DESTROYER )
{
objAuto = new CAutoDestroyer(obj);
objAuto.reset(new CAutoDestroyer(obj));
}
if ( type == OBJECT_STATION )
{
objAuto = new CAutoStation(obj);
objAuto.reset(new CAutoStation(obj));
}
if ( type == OBJECT_CONVERT )
{
objAuto = new CAutoConvert(obj);
objAuto.reset(new CAutoConvert(obj));
}
if ( type == OBJECT_TOWER )
{
objAuto = new CAutoTower(obj);
objAuto.reset(new CAutoTower(obj));
}
if ( type == OBJECT_RESEARCH )
{
objAuto = new CAutoResearch(obj);
objAuto.reset(new CAutoResearch(obj));
}
if ( type == OBJECT_RADAR )
{
objAuto = new CAutoRadar(obj);
objAuto.reset(new CAutoRadar(obj));
}
if ( type == OBJECT_INFO )
{
objAuto = new CAutoInfo(obj);
objAuto.reset(new CAutoInfo(obj));
}
if ( type == OBJECT_ENERGY )
{
objAuto = new CAutoEnergy(obj);
objAuto.reset(new CAutoEnergy(obj));
}
if ( type == OBJECT_LABO )
{
objAuto = new CAutoLabo(obj);
objAuto.reset(new CAutoLabo(obj));
}
if ( type == OBJECT_NUCLEAR )
{
objAuto = new CAutoNuclear(obj);
objAuto.reset(new CAutoNuclear(obj));
}
if ( type == OBJECT_PARA )
{
objAuto = new CAutoPara(obj);
objAuto.reset(new CAutoPara(obj));
}
if ( type == OBJECT_SAFE )
{
objAuto = new CAutoSafe(obj);
objAuto.reset(new CAutoSafe(obj));
}
if ( type == OBJECT_HUSTON )
{
objAuto = new CAutoHuston(obj);
objAuto.reset(new CAutoHuston(obj));
}
if ( type == OBJECT_EGG )
{
objAuto = new CAutoEgg(obj);
objAuto.reset(new CAutoEgg(obj));
}
if ( type == OBJECT_NEST )
{
objAuto = new CAutoNest(obj);
objAuto.reset(new CAutoNest(obj));
}
if ( type == OBJECT_ROOT5 )
{
objAuto = new CAutoRoot(obj);
objAuto.reset(new CAutoRoot(obj));
}
if ( type == OBJECT_MUSHROOM2 )
{
objAuto = new CAutoMush(obj);
objAuto.reset(new CAutoMush(obj));
}
if ( type == OBJECT_FLAGb ||
type == OBJECT_FLAGr ||
@ -3725,18 +3722,18 @@ void CObjectFactory::AddObjectAuto(CObject* obj)
type == OBJECT_FLAGy ||
type == OBJECT_FLAGv )
{
objAuto = new CAutoFlag(obj);
objAuto.reset(new CAutoFlag(obj));
}
if ( type == OBJECT_TEEN36 || // trunk?
type == OBJECT_TEEN37 || // boat?
type == OBJECT_TEEN38 ) // fan?
{
objAuto = new CAutoKid(obj);
objAuto.reset(new CAutoKid(obj));
}
if (objAuto != nullptr)
{
obj->SetAuto(objAuto);
objAuto->Init();
obj->SetAuto(std::move(objAuto));
}
}

View File

@ -30,7 +30,6 @@
#include "common/event.h"
#include "common/global.h"
#include "common/iman.h"
#include "common/logger.h"
#include "common/misc.h"
#include "common/profile.h"
@ -48,7 +47,7 @@
#include "graphics/engine/modelmanager.h"
#include "graphics/engine/particle.h"
#include "graphics/engine/planet.h"
#include "graphics/engine/pyro.h"
#include "graphics/engine/pyro_manager.h"
#include "graphics/engine/terrain.h"
#include "graphics/engine/text.h"
#include "graphics/engine/water.h"
@ -496,11 +495,6 @@ void CRobotMain::ChangePhase(Phase phase)
m_cameraZoom = 0.0f;
m_shortCut = true;
CInstanceManager* iMan = CInstanceManager::GetInstancePointer();
iMan->Flush(CLASS_PHYSICS);
iMan->Flush(CLASS_BRAIN);
iMan->Flush(CLASS_PYRO);
Math::Point dim, pos;
// Creates and hide the command console.
@ -1917,17 +1911,7 @@ bool CRobotMain::DeselectObject()
//! Quickly removes all objects
void CRobotMain::DeleteAllObjects()
{
CInstanceManager* iMan = CInstanceManager::GetInstancePointer();
// Removes all pyrotechnic effects in progress.
while (true)
{
Gfx::CPyro* pyro = static_cast<Gfx::CPyro*>(iMan->SearchInstance(CLASS_PYRO, 0));
if (pyro == nullptr) break;
pyro->DeleteObject();
delete pyro;
}
m_engine->GetPyroManager()->DeleteAll();
// Removes the arrow.
if (m_visitArrow != nullptr)
@ -2219,8 +2203,7 @@ bool CRobotMain::DeleteObject()
CObject* obj = GetSelect();
if (obj == nullptr) return false;
Gfx::CPyro* pyro = new Gfx::CPyro();
pyro->Create(Gfx::PT_FRAGT, obj);
m_engine->GetPyroManager()->Create(Gfx::PT_FRAGT, obj);
obj->SetSelect(false); // deselects the object
m_camera->SetType(Gfx::CAM_TYPE_EXPLO);
@ -2623,9 +2606,6 @@ bool CRobotMain::EventFrame(const Event &event)
if (pm != nullptr) pm->FlushObject();
}
CInstanceManager* iMan = CInstanceManager::GetInstancePointer();
CObject* toto = nullptr;
if (!m_freePhoto)
{
@ -2647,19 +2627,7 @@ bool CRobotMain::EventFrame(const Event &event)
obj->EventProcess(event);
}
// Advances pyrotechnic effects.
for (int i = 0; i < 1000000; i++)
{
Gfx::CPyro* pyro = static_cast<Gfx::CPyro*>(iMan->SearchInstance(CLASS_PYRO, i));
if (pyro == nullptr) break;
pyro->EventProcess(event);
if (pyro->IsEnded() != ERR_CONTINUE)
{
pyro->DeleteObject();
delete pyro;
}
}
m_engine->GetPyroManager()->EventProcess(event);
}
// The camera follows the object, because its position
@ -2835,11 +2803,6 @@ void CRobotMain::ScenePerso()
m_lightMan->FlushLights();
m_particle->FlushParticle();
CInstanceManager* iMan = CInstanceManager::GetInstancePointer();
iMan->Flush(CLASS_PHYSICS);
iMan->Flush(CLASS_BRAIN);
iMan->Flush(CLASS_PYRO);
ChangeColor();
@ -3558,8 +3521,7 @@ void CRobotMain::CreateScene(bool soluce, bool fixScene, bool resetObject)
Gfx::PyroType pType = line->GetParam("pyro")->AsPyroType(Gfx::PT_NULL);
if (pType != Gfx::PT_NULL)
{
Gfx::CPyro* pyro = new Gfx::CPyro();
pyro->Create(pType, obj);
m_engine->GetPyroManager()->Create(pType, obj);
}
// Puts information in terminal (OBJECT_INFO).
@ -5416,11 +5378,6 @@ void CRobotMain::ResetCreate()
m_particle->FlushParticle();
m_terrain->FlushBuildingLevel();
CInstanceManager* iMan = CInstanceManager::GetInstancePointer();
iMan->Flush(CLASS_PHYSICS);
iMan->Flush(CLASS_BRAIN);
iMan->Flush(CLASS_PYRO);
m_camera->SetType(Gfx::CAM_TYPE_DIALOG);
try
@ -5434,8 +5391,7 @@ void CRobotMain::ResetCreate()
ResetCap cap = obj->GetResetCap();
if (cap == RESET_NONE) continue;
Gfx::CPyro* pyro = new Gfx::CPyro();
pyro->Create(Gfx::PT_RESET, obj);
m_engine->GetPyroManager()->Create(Gfx::PT_RESET, obj);
}
}
catch (const CLevelParserException& e)

View File

@ -23,14 +23,13 @@
#include "math/geometry.h"
#include "graphics/engine/particle.h"
#include "graphics/engine/pyro.h"
#include "graphics/engine/pyro_manager.h"
#include "graphics/engine/water.h"
#include "object/object_manager.h"
#include "object/motion/motionhuman.h"
#include "physics/physics.h"
#include <boost/concept_check.hpp>
@ -211,8 +210,7 @@ Error CTaskFlag::CreateFlag(int rank)
//pNew->SetZoom(0, 0.0f);
m_sound->Play(SOUND_WAYPOINT, pos);
Gfx::CPyro* pyro = new Gfx::CPyro();
pyro->Create(Gfx::PT_FLCREATE, pNew);
m_engine->GetPyroManager()->Create(Gfx::PT_FLCREATE, pNew);
return ERR_OK;
}
@ -222,7 +220,6 @@ Error CTaskFlag::CreateFlag(int rank)
Error CTaskFlag::DeleteFlag()
{
CObject* pObj;
Gfx::CPyro* pyro;
Math::Vector iPos, oPos;
float iAngle, angle, aLimit, dist;
@ -250,8 +247,8 @@ Error CTaskFlag::DeleteFlag()
}
m_sound->Play(SOUND_WAYPOINT, iPos);
pyro = new Gfx::CPyro();
pyro->Create(Gfx::PT_FLDELETE, pObj);
m_engine->GetPyroManager()->Create(Gfx::PT_FLDELETE, pObj);
return ERR_OK;
}

View File

@ -22,8 +22,6 @@
#include "object/task/taskmanager.h"
#include "common/iman.h"
#include "object/task/taskwait.h"
#include "object/task/taskadvance.h"
#include "object/task/taskturn.h"

View File

@ -21,7 +21,7 @@
#include "object/task/taskmanip.h"
#include "graphics/engine/terrain.h"
#include "graphics/engine/pyro.h"
#include "graphics/engine/pyro_manager.h"
#include "math/geometry.h"
@ -291,7 +291,6 @@ Error CTaskManip::Start(TaskManipOrder order, TaskManipArm arm)
{
ObjectType type;
CObject *front, *other, *power;
Gfx::CPyro *pyro;
float iAngle, dist, len;
float fDist, fAngle, oDist, oAngle, oHeight;
Math::Vector pos, fPos, oPos;
@ -342,8 +341,7 @@ Error CTaskManip::Start(TaskManipOrder order, TaskManipArm arm)
pos.y += 2.0f;
m_object->SetPosition(0, pos); // against the top of jump
pyro = new Gfx::CPyro();
pyro->Create(Gfx::PT_FALL, other); // the ball falls
m_engine->GetPyroManager()->Create(Gfx::PT_FALL, other); // the ball falls
}
m_bBee = true;

View File

@ -20,7 +20,7 @@
#include "object/task/taskspiderexplo.h"
#include "graphics/engine/pyro.h"
#include "graphics/engine/pyro_manager.h"
#include "object/motion/motionspider.h"
@ -82,8 +82,6 @@ Error CTaskSpiderExplo::Start()
Error CTaskSpiderExplo::IsEnded()
{
Gfx::CPyro* pyro;
if ( m_engine->GetPause() ) return ERR_CONTINUE;
if ( m_bError )
@ -94,8 +92,7 @@ Error CTaskSpiderExplo::IsEnded()
if ( m_time < 1.0f ) return ERR_CONTINUE;
pyro = new Gfx::CPyro();
pyro->Create(Gfx::PT_SPIDER, m_object); // the spider explodes (suicide)
m_engine->GetPyroManager()->Create(Gfx::PT_SPIDER, m_object); // the spider explodes (suicide)
Abort();
return ERR_STOP;

View File

@ -22,7 +22,7 @@
#include "object/task/taskterraform.h"
#include "graphics/engine/pyro.h"
#include "graphics/engine/pyro_manager.h"
#include "graphics/engine/particle.h"
#include "graphics/engine/terrain.h"
@ -341,7 +341,6 @@ bool CTaskTerraform::Terraform()
{
CBrain* brain;
CMotion* motion;
Gfx::CPyro* pyro;
ObjectType type;
float dist;
@ -359,8 +358,7 @@ bool CTaskTerraform::Terraform()
dist = Math::Distance(m_terraPos, pObj->GetPosition(0));
if ( dist > 20.0f ) continue;
pyro = new Gfx::CPyro();
pyro->Create(Gfx::PT_FRAGT, pObj);
m_engine->GetPyroManager()->Create(Gfx::PT_FRAGT, pObj);
}
else
{

View File

@ -28,7 +28,7 @@
#include "graphics/engine/camera.h"
#include "graphics/engine/engine.h"
#include "graphics/engine/lightman.h"
#include "graphics/engine/pyro.h"
#include "graphics/engine/pyro_manager.h"
#include "graphics/engine/terrain.h"
#include "graphics/engine/water.h"
@ -2507,7 +2507,6 @@ void CPhysics::FloorAngle(const Math::Vector &pos, Math::Vector &angle)
int CPhysics::ObjectAdapt(const Math::Vector &pos, const Math::Vector &angle)
{
Gfx::CPyro* pyro;
CPhysics* ph;
Math::Matrix matRotate;
Math::Vector iPos, oPos, iiPos, oAngle, oSpeed;
@ -2584,8 +2583,7 @@ int CPhysics::ObjectAdapt(const Math::Vector &pos, const Math::Vector &angle)
if ( distance < 4.0f )
{
m_sound->Play(SOUND_WAYPOINT, m_object->GetPosition(0));
pyro = new Gfx::CPyro();
pyro->Create(Gfx::PT_WPCHECK, pObj);
m_engine->GetPyroManager()->Create(Gfx::PT_WPCHECK, pObj);
}
}
@ -2596,8 +2594,7 @@ int CPhysics::ObjectAdapt(const Math::Vector &pos, const Math::Vector &angle)
if ( distance < 10.0f*1.5f )
{
m_sound->Play(SOUND_WAYPOINT, m_object->GetPosition(0));
pyro = new Gfx::CPyro();
pyro->Create(Gfx::PT_WPCHECK, pObj);
m_engine->GetPyroManager()->Create(Gfx::PT_WPCHECK, pObj);
}
}
@ -2748,8 +2745,6 @@ bool CPhysics::JostleObject(CObject* pObj, float force)
bool CPhysics::ExploOther(ObjectType iType,
CObject *pObj, ObjectType oType, float force)
{
Gfx::CPyro* pyro;
if ( !pObj->GetEnable() ) return true;
JostleObject(pObj, 1.0f); // shakes the object
@ -2758,24 +2753,21 @@ bool CPhysics::ExploOther(ObjectType iType,
(oType == OBJECT_FRET ||
oType == OBJECT_METAL ) )
{
pyro = new Gfx::CPyro();
pyro->Create(Gfx::PT_EXPLOT, pObj); // total destruction
m_engine->GetPyroManager()->Create(Gfx::PT_EXPLOT, pObj); // total destruction
}
if ( force > 50.0f &&
(oType == OBJECT_POWER ||
oType == OBJECT_ATOMIC ) )
{
pyro = new Gfx::CPyro();
pyro->Create(Gfx::PT_FRAGT, pObj); // total destruction
m_engine->GetPyroManager()->Create(Gfx::PT_FRAGT, pObj); // total destruction
}
if ( force > 25.0f &&
(oType == OBJECT_STONE ||
oType == OBJECT_URANIUM ) )
{
pyro = new Gfx::CPyro();
pyro->Create(Gfx::PT_FRAGT, pObj); // total destruction
m_engine->GetPyroManager()->Create(Gfx::PT_FRAGT, pObj); // total destruction
}
if ( force > 25.0f &&
@ -2835,15 +2827,13 @@ bool CPhysics::ExploOther(ObjectType iType,
(oType == OBJECT_MOBILEtg ||
oType == OBJECT_TNT ) )
{
pyro = new Gfx::CPyro();
pyro->Create(Gfx::PT_FRAGT, pObj); // total destruction
m_engine->GetPyroManager()->Create(Gfx::PT_FRAGT, pObj); // total destruction
}
if ( force > 0.0f &&
oType == OBJECT_BOMB )
{
pyro = new Gfx::CPyro();
pyro->Create(Gfx::PT_FRAGT, pObj); // total destruction
m_engine->GetPyroManager()->Create(Gfx::PT_FRAGT, pObj); // total destruction
}
return false;
@ -2856,23 +2846,22 @@ bool CPhysics::ExploOther(ObjectType iType,
int CPhysics::ExploHimself(ObjectType iType, ObjectType oType, float force)
{
Gfx::PyroType type;
Gfx::CPyro* pyro;
if ( force > 10.0f &&
(oType == OBJECT_TNT ||
oType == OBJECT_MOBILEtg ) )
{
Gfx::PyroType type;
if ( iType == OBJECT_HUMAN ) type = Gfx::PT_DEADG;
else type = Gfx::PT_EXPLOT;
pyro = new Gfx::CPyro();
pyro->Create(type, m_object); // total destruction
m_engine->GetPyroManager()->Create(type, m_object); // total destruction
return 2;
}
if ( force > 0.0f &&
oType == OBJECT_BOMB )
{
Gfx::PyroType type;
if ( iType == OBJECT_HUMAN )
{
type = Gfx::PT_DEADG;
@ -2887,8 +2876,7 @@ int CPhysics::ExploHimself(ObjectType iType, ObjectType oType, float force)
{
type = Gfx::PT_EXPLOT;
}
pyro = new Gfx::CPyro();
pyro->Create(type, m_object); // total destruction
m_engine->GetPyroManager()->Create(type, m_object); // total destruction
return 2;
}

View File

@ -25,9 +25,12 @@
#pragma once
#include "graphics/engine/camera.h"
#include "graphics/engine/water.h"
#include "graphics/engine/engine.h"
#include "graphics/engine/pyro.h"
#include "graphics/engine/pyro_type.h"
#include "object/object.h"

View File

@ -23,7 +23,6 @@
#include "app/app.h"
#include "common/event.h"
#include "common/iman.h"
#include "common/restext.h"
#include "graphics/engine/engine.h"

View File

@ -21,7 +21,6 @@
#include "common/config.h"
#include "common/logger.h"
#include "common/image.h"
#include "common/iman.h"
#include "graphics/opengl/gldevice.h"
@ -29,7 +28,6 @@
#include <SDL.h>
#include <SDL_image.h>
#include <unistd.h>
#include <iostream>
#include <map>