-
-
Notifications
You must be signed in to change notification settings - Fork 184
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
UPBGE: Implement python component manager.
Previously the inexistance of a python component manager forced in KX_Scene to iterate over all the object to ask for a component update. The implementation of a manager with a registering mechanism help to avoid this iteration and optimize as much as possible the case where a scene doesn't update any components.
- Loading branch information
1 parent
904ca9b
commit 76aff7a
Showing
6 changed files
with
87 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
#include "KX_PythonComponentManager.h" | ||
#include "KX_PythonComponent.h" | ||
#include "KX_GameObject.h" | ||
|
||
KX_PythonComponentManager::KX_PythonComponentManager() | ||
{ | ||
} | ||
|
||
KX_PythonComponentManager::~KX_PythonComponentManager() | ||
{ | ||
} | ||
|
||
void KX_PythonComponentManager::RegisterObject(KX_GameObject *gameobj) | ||
{ | ||
// Always register only once an object. | ||
m_objects.push_back(gameobj); | ||
} | ||
|
||
void KX_PythonComponentManager::UnregisterObject(KX_GameObject *gameobj) | ||
{ | ||
std::vector<KX_GameObject *>::iterator it = std::find(m_objects.begin(), m_objects.end(), gameobj); | ||
if (it != m_objects.end()) { | ||
m_objects.erase(it); | ||
} | ||
} | ||
|
||
void KX_PythonComponentManager::UpdateComponents() | ||
{ | ||
/* Update object components, we copy the object pointer in a second list to make | ||
* sure that we iterate on a list which will not be modified, indeed components | ||
* can add objects in theirs update. | ||
*/ | ||
const std::vector<KX_GameObject *> objects = m_objects; | ||
for (KX_GameObject *gameobj : objects) { | ||
gameobj->UpdateComponents(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
#ifndef __KX_PYTHON_COMPONENT_H__ | ||
#define __KX_PYTHON_COMPONENT_H__ | ||
|
||
#include <vector> | ||
|
||
class KX_GameObject; | ||
|
||
class KX_PythonComponentManager | ||
{ | ||
private: | ||
std::vector<KX_GameObject *> m_objects; | ||
|
||
public: | ||
KX_PythonComponentManager(); | ||
~KX_PythonComponentManager(); | ||
|
||
void RegisterObject(KX_GameObject *gameobj); | ||
void UnregisterObject(KX_GameObject *gameobj); | ||
|
||
void UpdateComponents(); | ||
}; | ||
|
||
#endif // __KX_PYTHON_COMPONENT_H__ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters