From e5922e37e44a76aaa3139c9ecfa060cb9161d4dc Mon Sep 17 00:00:00 2001 From: LockedLunatic Date: Sat, 25 Jun 2016 11:17:59 +0200 Subject: [PATCH] Levers and reverting time is now less buggy, but still not perfect --- Weave/Scene/Door.cpp | 24 ++++++++++++++++--- Weave/Scene/Lever.cpp | 48 +++++++++++++++++++++++-------------- Weave/Scene/Scene.cpp | 12 ++++++++-- Weave/Scene/SceneObject.cpp | 13 ++++++---- Weave/Scene/SceneObject.h | 1 + 5 files changed, 71 insertions(+), 27 deletions(-) diff --git a/Weave/Scene/Door.cpp b/Weave/Scene/Door.cpp index 7e19a69..17ec718 100644 --- a/Weave/Scene/Door.cpp +++ b/Weave/Scene/Door.cpp @@ -1,4 +1,5 @@ #include "Door.h" +#include "Scene.h" Door::Door(std::string modelpath, std::string texturepath) : Level(modelpath, texturepath), angle(0), axis(vec3(0, 1, 0)), duration(0), speed(0), time(0) @@ -26,7 +27,11 @@ void Door::setup(float _angle, vec3 _axis, float _duration) void Door::trigger() { - //TODO add event + if (!timeresistant) + { + mainScene->addEvent(this, 3); + } + if (speed == 0) { if (time == 0) @@ -46,10 +51,23 @@ void Door::trigger() void Door::reverseTrigger() { - + if (speed == 0) + { + if (time == 0) + { + speed = -1; + } + else + { + speed = 1; + } + } + else + { + speed = -speed; + } } -//TODO overwrite update void Door::update(float deltaT) { time = time + speed * deltaT; diff --git a/Weave/Scene/Lever.cpp b/Weave/Scene/Lever.cpp index 57879aa..0ce93d0 100644 --- a/Weave/Scene/Lever.cpp +++ b/Weave/Scene/Lever.cpp @@ -21,36 +21,48 @@ void Lever::setup(Door* object) void Lever::trigger() { - turned = !turned; - - if (!timeresistant) + if (!isinanimation()) { - mainScene->addEvent(this, 2); - } + turned = !turned; - if (turned) - { - this->startanimation((uint)0, 1.0f); - for (auto i = recipients.cbegin(); i != recipients.cend(); ++i) + if (!timeresistant) { - (*i)->trigger(); + mainScene->addEvent(this, 2); } - Message::info("Sesam öffne dich!"); - } - else - { - this->startanimation((uint)0, -1.0f); - for (auto i = recipients.cbegin(); i != recipients.cend(); ++i) + if (turned) { - (*i)->trigger(); + this->startanimation((uint)0, 1.0f); + for (auto i = recipients.cbegin(); i != recipients.cend(); ++i) + { + (*i)->trigger(); + } + + Message::info("Sesam öffne dich!"); } + else + { + this->startanimation((uint)0, -1.0f); + for (auto i = recipients.cbegin(); i != recipients.cend(); ++i) + { + (*i)->trigger(); + } - Message::info("Sesam schließe dich!"); + Message::info("Sesam schließe dich!"); + } } } void Lever::reverseTrigger() { turned = !turned; + + if (turned) + { + this->startanimation((uint)0, -1.0f); + } + else + { + this->startanimation((uint)0, 1.0f); + } } \ No newline at end of file diff --git a/Weave/Scene/Scene.cpp b/Weave/Scene/Scene.cpp index 5d83d6b..a0ca119 100644 --- a/Weave/Scene/Scene.cpp +++ b/Weave/Scene/Scene.cpp @@ -625,13 +625,13 @@ void Scene::revertEvent(TimeEvent e) { case 0: //forward Animation ended - e.object->startanimation((uint) 0, -1.0f); + e.object->startanimation((uint) 0, 1.0f); e.object->setanimationtime(e.time - currenttime); break; case 1: //reverse Animation ended - e.object->startanimation((uint) 0, 1.0f); + e.object->startanimation((uint) 0, -1.0f); e.object->setanimationtime(e.time - currenttime); break; @@ -642,5 +642,13 @@ void Scene::revertEvent(TimeEvent e) l->reverseTrigger(); } break; + + case 3: + //Door triggered + if (Door* l = dynamic_cast (e.object)) + { + l->reverseTrigger(); + } + break; } } \ No newline at end of file diff --git a/Weave/Scene/SceneObject.cpp b/Weave/Scene/SceneObject.cpp index dcc88f7..656c828 100644 --- a/Weave/Scene/SceneObject.cpp +++ b/Weave/Scene/SceneObject.cpp @@ -379,11 +379,11 @@ void SceneObject::setanimationtime(float _time) { if (animationSpeed >= 0) { - AnimationTime = _time; + AnimationTime = model->animationduration - _time; } else { - AnimationTime = model->animationduration - _time; + AnimationTime = _time; } } @@ -408,7 +408,7 @@ void SceneObject::updateAnimation(float deltaT) AnimationTime = 0; animationSpeed = 0; - if (!timeresistant) + if (!timeresistant && deltaT > 0) { mainScene->addEvent(this, 1); } @@ -425,11 +425,16 @@ void SceneObject::updateAnimation(float deltaT) AnimationTime = model->animationduration - 0.01f; animationSpeed = 0; - if (!timeresistant) + if (!timeresistant && deltaT > 0) { mainScene->addEvent(this, 0); } } } } +} + +bool SceneObject::isinanimation() +{ + return animationSpeed != 0; } \ No newline at end of file diff --git a/Weave/Scene/SceneObject.h b/Weave/Scene/SceneObject.h index 9f81f02..febf6da 100644 --- a/Weave/Scene/SceneObject.h +++ b/Weave/Scene/SceneObject.h @@ -88,6 +88,7 @@ public: virtual void startanimation(uint index, float speed); virtual void setanimationtime(float time); virtual void setAnimationLoop(bool loop); + bool isinanimation(); bool timeresistant = false; bool ignore; -- 2.47.3