Skip to content

Commit

Permalink
UPBGE: Use std::unique_ptr for event managers in SCA_LogicManager.
Browse files Browse the repository at this point in the history
In the same time the replacement of the logic manager into the event manager
is removed in the scene merging as the event manager are deleted just after
the merge of the scene.
  • Loading branch information
panzergame committed Jan 1, 2018
1 parent 48e2862 commit 0414529
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 34 deletions.
4 changes: 0 additions & 4 deletions source/gameengine/GameLogic/SCA_EventManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -71,10 +71,6 @@ class SCA_EventManager
virtual void EndFrame();
virtual bool RegisterSensor(class SCA_ISensor* sensor);
int GetType();
//SG_DList &GetSensors() { return m_sensors; }


void Replace_LogicManager(SCA_LogicManager* logicmgr) { m_logicmgr= logicmgr; }

protected:
EVENT_MANAGER_TYPE m_mgrtype;
Expand Down
23 changes: 10 additions & 13 deletions source/gameengine/GameLogic/SCA_LogicManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,17 +48,12 @@ SCA_LogicManager::SCA_LogicManager()

SCA_LogicManager::~SCA_LogicManager()
{
for (SCA_EventManager *mgr : m_eventmanagers) {
delete mgr;
}

m_eventmanagers.clear();
BLI_assert(m_activeActuators.Empty());
}

void SCA_LogicManager::RegisterEventManager(SCA_EventManager* eventmgr)
{
m_eventmanagers.push_back(eventmgr);
m_eventmanagers.emplace_back(eventmgr);
}


Expand Down Expand Up @@ -160,8 +155,9 @@ void SCA_LogicManager::RegisterToActuator(SCA_IController* controller,SCA_IActua

void SCA_LogicManager::BeginFrame(double curtime, double fixedtime)
{
for (std::vector<SCA_EventManager*>::const_iterator ie=m_eventmanagers.begin(); !(ie==m_eventmanagers.end()); ie++)
(*ie)->NextFrame(curtime, fixedtime);
for (std::unique_ptr<SCA_EventManager>& mgr : m_eventmanagers) {
mgr->NextFrame(curtime, fixedtime);
}

for (SG_QList* obj = (SG_QList*)m_triggeredControllerSet.Remove();
obj != nullptr;
Expand All @@ -181,8 +177,9 @@ void SCA_LogicManager::BeginFrame(double curtime, double fixedtime)

void SCA_LogicManager::UpdateFrame(double curtime)
{
for (std::vector<SCA_EventManager*>::const_iterator ie=m_eventmanagers.begin(); !(ie==m_eventmanagers.end()); ie++)
(*ie)->UpdateFrame();
for (std::unique_ptr<SCA_EventManager>& mgr : m_eventmanagers) {
mgr->UpdateFrame();
}

SG_DList::iterator<SG_QList> io(m_activeActuators);
for (io.begin(); !io.end(); )
Expand Down Expand Up @@ -262,7 +259,7 @@ void SCA_LogicManager::RegisterActionName(const std::string& actname,void* actio

void SCA_LogicManager::EndFrame()
{
for (SCA_EventManager *emgr : m_eventmanagers) {
for (std::unique_ptr<SCA_EventManager>& emgr : m_eventmanagers) {
emgr->EndFrame();
}
}
Expand Down Expand Up @@ -290,10 +287,10 @@ SCA_EventManager* SCA_LogicManager::FindEventManager(int eventmgrtype)
// find an eventmanager of a certain type
SCA_EventManager* eventmgr = nullptr;

for (SCA_EventManager *emgr : m_eventmanagers) {
for (std::unique_ptr<SCA_EventManager>& emgr : m_eventmanagers) {
if (emgr->GetType() == eventmgrtype)
{
eventmgr = emgr;
eventmgr = emgr.get();
break;
}
}
Expand Down
4 changes: 2 additions & 2 deletions source/gameengine/GameLogic/SCA_LogicManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -63,10 +63,11 @@ typedef std::map<class SCA_ISensor*,controllerlist > sensormap_t;
#include "SCA_IActuator.h"
#include "SCA_EventManager.h"

#include <memory>

class SCA_LogicManager
{
std::vector<class SCA_EventManager*> m_eventmanagers;
std::vector<std::unique_ptr<SCA_EventManager> > m_eventmanagers;

// SG_DList: Head of objects having activated actuators
// element: SCA_IObject::m_activeActuators
Expand Down Expand Up @@ -106,7 +107,6 @@ class SCA_LogicManager

void AddTriggeredController(SCA_IController* controller, SCA_ISensor* sensor);
SCA_EventManager* FindEventManager(int eventmgrtype);
std::vector<class SCA_EventManager*> GetEventManagers() { return m_eventmanagers; }

/**
* remove Logic Bricks from the running logicmanager
Expand Down
15 changes: 0 additions & 15 deletions source/gameengine/Ketsji/KX_Scene.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1699,21 +1699,6 @@ bool KX_Scene::MergeScene(KX_Scene *other)
GetFontList()->MergeList(other->GetFontList());
other->GetFontList()->ReleaseAndRemoveAll();

SCA_LogicManager *logicmgr_other = other->GetLogicManager();

std::vector<SCA_EventManager *> evtmgrs = m_logicmgr->GetEventManagers();

for (SCA_EventManager *evtmgr : evtmgrs) {
SCA_EventManager *evtmgr_other = logicmgr_other->FindEventManager(evtmgr->GetType());

if (evtmgr_other) {
// Unlikely but possible one scene has a joystick and not the other.
evtmgr_other->Replace_LogicManager(m_logicmgr);
}

// When merging objects sensors are moved across into the new manager, don't need to do this here.
}

// Grab any timer properties from the other scene.
SCA_TimeEventManager *timemgr_other = other->GetTimeEventManager();
std::vector<EXP_Value *> times = timemgr_other->GetTimeValues();
Expand Down

0 comments on commit 0414529

Please sign in to comment.