Switched scene update to state event

This commit is contained in:
2023-03-01 09:40:57 -08:00
parent 1d26228cb5
commit b9625e7f14
10 changed files with 438 additions and 473 deletions

View File

@ -36,8 +36,8 @@ void Scene::update() {
// TODO: Cleanup old scene items
// TODO: Tick scene items(?)
this->eventSceneUpdate.invoke();
if(!this->game->timeManager.isPaused) this->eventSceneUnpausedUpdate.invoke();
this->eventSceneUpdate.invoke(game->timeManager.delta);
if(!this->game->timeManager.isPaused) this->eventSceneUnpausedUpdate.invoke(game->timeManager.delta);
}
SceneItem * Scene::createSceneItem() {

View File

@ -21,7 +21,7 @@ namespace Dawn {
template<class T>
T * _sceneForwardGetComponent(SceneItem *item);
class Scene : public StateOwner {
class Scene {
private:
sceneitemid_t nextId;
std::map<sceneitemid_t, SceneItem*> items;
@ -30,8 +30,8 @@ namespace Dawn {
public:
DawnGame *game;
ScenePhysicsManager *physics;
Event<> eventSceneUpdate;
Event<> eventSceneUnpausedUpdate;
StateEvent<float_t> eventSceneUpdate;
StateEvent<float_t> eventSceneUnpausedUpdate;
/**
* Construct a new Scene instance.

View File

@ -22,10 +22,10 @@ void AnimationController::addAnimation(Animation *animation) {
void AnimationController::onStart() {
SceneItemComponent::onStart();
useEventLegacy([&]{
useEvent([&](float_t delta){
auto it = this->animations.begin();
while(it != this->animations.end()) {
(*it)->tick(this->getGame()->timeManager.delta);
(*it)->tick(delta);
++it;
}
}, getScene()->eventSceneUnpausedUpdate);

View File

@ -28,11 +28,11 @@ ExampleSpin::ExampleSpin(SceneItem *item) :
}
void ExampleSpin::onStart() {
useEventLegacy([&]{
useEvent([&](float_t delta){
auto quat = this->transform->getLocalRotation();
quat = glm::rotate(quat, getGame()->timeManager.delta, glm::vec3(0, 1, 0));
quat = glm::rotate(quat, getGame()->timeManager.delta / 2.0f, glm::vec3(1, 0, 0));
quat = glm::rotate(quat, getGame()->timeManager.delta / 4.0f, glm::vec3(0, 0, 1));
quat = glm::rotate(quat, delta, glm::vec3(0, 1, 0));
quat = glm::rotate(quat, delta / 2.0f, glm::vec3(1, 0, 0));
quat = glm::rotate(quat, delta / 4.0f, glm::vec3(0, 0, 1));
this->transform->setLocalRotation(quat);
}, getScene()->eventSceneUnpausedUpdate);
}

View File

@ -14,13 +14,13 @@ SubSceneController::SubSceneController(SceneItem *i) : SceneItemComponent(i) {
void SubSceneController::onStart() {
auto myScene = this->getScene();
useEventLegacy([&]{
useEvent([&](float_t d){
if(!this->onlyUpdateUnpaused) return;
if(this->subScene == nullptr) return;
this->subScene->update();
}, myScene->eventSceneUnpausedUpdate);
useEventLegacy([&]{
useEvent([&](float_t d){
if(this->onlyUpdateUnpaused) return;
if(this->subScene == nullptr) return;
this->subScene->update();

View File

@ -67,7 +67,7 @@ void UICanvas::onStart() {
}, this->currentMenu);
// Scene Update
useEventLegacy([&]{
useEvent([&](float_t delta){
if(this->currentMenu == nullptr) return;
this->currentMenu->onTick();
}, getScene()->eventSceneUpdate);