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

View File

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

View File

@ -37,7 +37,6 @@
#include <vector> #include <vector>
class CInstanceManager;
class CEventQueue; class CEventQueue;
class CController; class CController;
class CSoundInterface; class CSoundInterface;
@ -151,7 +150,7 @@ struct ApplicationPrivate;
* *
* \section Creation Creation of other main objects * \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. * CRobotMain and CSoundInterface classes.
* *
* \section Window Window management * \section Window Window management
@ -356,9 +355,6 @@ protected:
protected: protected:
//! Private (SDL-dependent data) //! Private (SDL-dependent data)
ApplicationPrivate* m_private; ApplicationPrivate* m_private;
//! Instance manager
// TODO: to be removed
CInstanceManager* m_iMan;
//! Global event queue //! Global event queue
CEventQueue* m_eventQueue; CEventQueue* m_eventQueue;
//! Graphics engine //! 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/modelmanager.h"
#include "graphics/engine/particle.h" #include "graphics/engine/particle.h"
#include "graphics/engine/planet.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/terrain.h"
#include "graphics/engine/text.h" #include "graphics/engine/text.h"
#include "graphics/engine/water.h" #include "graphics/engine/water.h"
@ -245,6 +245,11 @@ CModelManager* CEngine::GetModelManager()
return m_modelManager.get(); return m_modelManager.get();
} }
CPyroManager* CEngine::GetPyroManager()
{
return m_pyroManager.get();
}
CText* CEngine::GetText() CText* CEngine::GetText()
{ {
return m_text; return m_text;
@ -295,6 +300,7 @@ bool CEngine::Create()
m_size = m_app->GetVideoConfig().size; m_size = m_app->GetVideoConfig().size;
m_modelManager.reset(new CModelManager(this)); m_modelManager.reset(new CModelManager(this));
m_pyroManager.reset(new CPyroManager());
m_lightMan = new CLightManager(this); m_lightMan = new CLightManager(this);
m_text = new CText(this); m_text = new CText(this);
m_particle = new CParticle(this); m_particle = new CParticle(this);
@ -374,7 +380,7 @@ void CEngine::ResetAfterDeviceChanged()
m_text->FlushCache(); m_text->FlushCache();
FlushTextureCache(); FlushTextureCache();
LoadAllTextures(); LoadAllTextures();
} }
@ -489,7 +495,7 @@ bool CEngine::WriteScreenShot(const std::string& fileName, int width, int height
else{ else{
GetLogger()->Error("%s!\n",img.GetError().c_str()); GetLogger()->Error("%s!\n",img.GetError().c_str());
return false; return false;
} }
} }
bool CEngine::GetPause() bool CEngine::GetPause()
@ -2220,7 +2226,7 @@ void CEngine::SetState(int state, const Color& color)
if (state & ENG_RSTATE_FOG) if (state & ENG_RSTATE_FOG)
m_device->SetRenderState(RENDER_STATE_FOG, true); m_device->SetRenderState(RENDER_STATE_FOG, true);
bool second = m_groundSpotVisible || m_dirty; bool second = m_groundSpotVisible || m_dirty;
@ -3011,7 +3017,7 @@ void CEngine::SetTextureAnisotropyLevel(int value)
{ {
if (value < 1) value = 1; if (value < 1) value = 1;
if (value > 16) value = 16; if (value > 16) value = 16;
m_textureAnisotropy = value; m_textureAnisotropy = value;
} }
@ -3294,8 +3300,8 @@ void CEngine::Draw3DScene()
m_app->StartPerformanceCounter(PCNT_RENDER_TERRAIN); m_app->StartPerformanceCounter(PCNT_RENDER_TERRAIN);
// Draw terrain // Draw terrain
m_lightMan->UpdateDeviceLights(ENG_OBJTYPE_TERRAIN); m_lightMan->UpdateDeviceLights(ENG_OBJTYPE_TERRAIN);
UseShadowMapping(true); UseShadowMapping(true);
@ -3359,7 +3365,7 @@ void CEngine::Draw3DScene()
// Draws the shadows , if shadows enabled // Draws the shadows , if shadows enabled
if (m_shadowVisible) if (m_shadowVisible)
DrawShadow(); DrawShadow();
m_app->StopPerformanceCounter(PCNT_RENDER_TERRAIN); m_app->StopPerformanceCounter(PCNT_RENDER_TERRAIN);
@ -5017,17 +5023,17 @@ void CEngine::DrawStats()
pos.y -= height; 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)); 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;
pos.y -= height; pos.y -= height;
str.str(""); str.str("");
str << "Position x: " << std::fixed << std::setprecision(2) << m_statisticPos.x/g_unit; 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)); 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; pos.y -= height;
str.str(""); str.str("");
str << "Position y: " << std::fixed << std::setprecision(2) << m_statisticPos.z/g_unit; 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)); 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() void CEngine::DrawTimer()
{ {
SetState(ENG_RSTATE_TEXT); SetState(ENG_RSTATE_TEXT);
Math::Point pos(0.98f, 0.98f-m_text->GetAscent(FONT_COLOBOT, 15.0f)); 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)); 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/system.h"
#include "app/pausemanager.h"
#include "common/event.h" #include "common/event.h"
#include "common/singleton.h" #include "common/singleton.h"
@ -55,6 +54,7 @@ class CApplication;
class CObject; class CObject;
class CSoundInterface; class CSoundInterface;
class CImage; class CImage;
class CPauseManager;
// Graphics module namespace // Graphics module namespace
@ -71,6 +71,7 @@ class CCloud;
class CLightning; class CLightning;
class CPlanet; class CPlanet;
class CTerrain; class CTerrain;
class CPyroManager;
/** /**
@ -697,6 +698,7 @@ public:
//! Returns the text rendering engine //! Returns the text rendering engine
CText* GetText(); CText* GetText();
CModelManager* GetModelManager(); CModelManager* GetModelManager();
CPyroManager* GetPyroManager();
//! Returns the light manager //! Returns the light manager
CLightManager* GetLightManager(); CLightManager* GetLightManager();
//! Returns the particle manager //! Returns the particle manager
@ -1347,6 +1349,7 @@ protected:
CPlanet* m_planet; CPlanet* m_planet;
CTerrain* m_terrain; CTerrain* m_terrain;
CPauseManager* m_pause; CPauseManager* m_pause;
std::unique_ptr<CPyroManager> m_pyroManager;
//! Last encountered error //! Last encountered error
std::string m_error; std::string m_error;
@ -1524,7 +1527,7 @@ protected:
bool m_debugLights; bool m_debugLights;
bool m_debugDumpLights; bool m_debugDumpLights;
std::string m_timerText; std::string m_timerText;
}; };

View File

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

View File

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

View File

@ -28,9 +28,10 @@
#include "common/event.h" #include "common/event.h"
#include "common/global.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; class CObject;
@ -46,40 +47,7 @@ class CTerrain;
class CCamera; class CCamera;
class CParticle; class CParticle;
class CLight; class CLight;
class CLightManager;
/**
* \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
};
struct PyroBurnPart struct PyroBurnPart
@ -107,15 +75,18 @@ struct PyroLightOper
*/ */
class CPyro class CPyro
{ {
public: protected:
CPyro(); friend class CPyroManager;
~CPyro();
CPyro();
//! Creates pyrotechnic effect //! Creates pyrotechnic effect
bool Create(PyroType type, CObject* obj, float force=1.0f); bool Create(PyroType type, CObject* obj, float force);
//! Destroys the object //! Destroys the object
void DeleteObject(); void DeleteObject();
public:
~CPyro();
//! Indicates whether the pyrotechnic effect is complete //! Indicates whether the pyrotechnic effect is complete
Error IsEnded(); 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 "object/auto/autodestroyer.h"
#include "graphics/engine/pyro_manager.h"
#include "object/object_manager.h" #include "object/object_manager.h"
#include "object/level/parserline.h" #include "object/level/parserline.h"
#include "object/level/parserparam.h" #include "object/level/parserparam.h"
@ -110,7 +112,6 @@ Error CAutoDestroyer::StartAction(int param)
bool CAutoDestroyer::EventProcess(const Event &event) bool CAutoDestroyer::EventProcess(const Event &event)
{ {
CObject* scrap; CObject* scrap;
Gfx::CPyro* pyro;
Math::Vector pos, speed; Math::Vector pos, speed;
Math::Point dim; Math::Point dim;
Ui::CWindow* pw; Ui::CWindow* pw;
@ -168,8 +169,7 @@ bool CAutoDestroyer::EventProcess(const Event &event)
scrap = SearchPlastic(); scrap = SearchPlastic();
if ( scrap != nullptr ) if ( scrap != nullptr )
{ {
pyro = new Gfx::CPyro(); m_engine->GetPyroManager()->Create(Gfx::PT_FRAGT, scrap);
pyro->Create(Gfx::PT_FRAGT, scrap);
} }
m_bExplo = true; m_bExplo = true;
} }

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -25,9 +25,12 @@
#pragma once #pragma once
#include "graphics/engine/camera.h"
#include "graphics/engine/water.h" #include "graphics/engine/water.h"
#include "graphics/engine/engine.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 "app/app.h"
#include "common/event.h" #include "common/event.h"
#include "common/iman.h"
#include "common/restext.h" #include "common/restext.h"
#include "graphics/engine/engine.h" #include "graphics/engine/engine.h"

View File

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