cleaned things up a bit, looks good to start implementing the rpg mechs
This commit is contained in:
@@ -49,6 +49,13 @@ void SceneComponent::dispose() {
|
||||
this->item.reset();
|
||||
}
|
||||
|
||||
bool_t SceneComponent::isInitialized() {
|
||||
return Flag::isOn<uint_fast8_t>(
|
||||
sceneComponentState,
|
||||
SCENE_COMPONENT_STATE_INIT
|
||||
);
|
||||
}
|
||||
|
||||
std::shared_ptr<SceneItem> SceneComponent::getItem() {
|
||||
return this->item.lock();
|
||||
}
|
||||
|
@@ -47,6 +47,13 @@ namespace Dawn {
|
||||
*/
|
||||
void dispose();
|
||||
|
||||
/**
|
||||
* Returns whether this scene component is initialized.
|
||||
*
|
||||
* @return Whether this scene component is initialized.
|
||||
*/
|
||||
bool_t isInitialized();
|
||||
|
||||
/**
|
||||
* Returns the scene item that this scene component belongs to.
|
||||
*
|
||||
|
@@ -25,8 +25,28 @@ std::shared_ptr<Scene> SceneItem::getScene() {
|
||||
|
||||
void SceneItem::init() {
|
||||
auto sharedThis = shared_from_this();
|
||||
for(auto &component : components) {
|
||||
component->init(sharedThis);
|
||||
|
||||
// Loop until all components initialized...
|
||||
while(true) {
|
||||
// Create copy of the components, components may chose to add more components
|
||||
// but those sub components will not be initialized at this time.
|
||||
auto components = this->components;
|
||||
for(auto &component : components) {
|
||||
if(component->isInitialized()) continue;
|
||||
component->init(sharedThis);
|
||||
}
|
||||
|
||||
// If they are all initalized we are fine.
|
||||
components = this->components;
|
||||
bool_t allInitialized = std::all_of(
|
||||
components.begin(),
|
||||
components.end(),
|
||||
[](auto &component) {
|
||||
return component->isInitialized();
|
||||
}
|
||||
);
|
||||
|
||||
if(allInitialized) break;
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user