Created
January 21, 2019 04:49
-
-
Save cleak/fab5103c154c9d1469a91e9a5cdbf14d to your computer and use it in GitHub Desktop.
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
class SceneManager { | |
public: | |
SceneManager() { | |
null_vtable_ = GetVtable(&null_object_); | |
} | |
void Add(SceneObject* obj) { | |
SceneObject_VTable* vtable = GetVtable(obj); | |
if (vtable->update != null_vtable_->update) { | |
update_fns_.insert({ vtable->update, obj }); | |
} | |
if (vtable->late_update != null_vtable_->late_update) { | |
late_update_fns_.insert({ vtable->late_update, obj }); | |
} | |
if (vtable->physics_update != null_vtable_->physics_update) { | |
physics_update_fns_.insert({ vtable->physics_update, obj }); | |
} | |
if (vtable->draw_immediate != null_vtable_->draw_immediate) { | |
draw_immediate_fns_.insert({ vtable->draw_immediate, obj }); | |
} | |
} | |
void UpdateAll() { | |
for (auto& fn : update_fns_) { | |
fn.first(fn.second); | |
} | |
} | |
void LateUpdateAll() { | |
for (auto& fn : late_update_fns_) { | |
fn.first(fn.second); | |
} | |
} | |
void PhysicsUpdateAll() { | |
for (auto& fn : physics_update_fns_) { | |
fn.first(fn.second); | |
} | |
} | |
void DrawImmediateAll() { | |
for (auto& fn : draw_immediate_fns_) { | |
fn.first(fn.second); | |
} | |
} | |
private: | |
SceneObject null_object_; | |
SceneObject_VTable* null_vtable_; | |
std::set<SceneObject*> objects_; | |
std::set<std::pair<UpdateFn*, void*>, CompareUpdateFns> update_fns_; | |
std::set<std::pair<UpdateFn*, void*>, CompareUpdateFns> late_update_fns_; | |
std::set<std::pair<UpdateFn*, void*>, CompareUpdateFns> physics_update_fns_; | |
std::set<std::pair<UpdateFn*, void*>, CompareUpdateFns> draw_immediate_fns_; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment