]> git.leopard-lacewing.eu Git - cgue_weave.git/commitdiff
Levers and reverting time is now less buggy, but still not perfect
authorLockedLunatic <locked.lunatic@aon.at>
Sat, 25 Jun 2016 09:17:59 +0000 (11:17 +0200)
committerLockedLunatic <locked.lunatic@aon.at>
Sat, 25 Jun 2016 09:17:59 +0000 (11:17 +0200)
Weave/Scene/Door.cpp
Weave/Scene/Lever.cpp
Weave/Scene/Scene.cpp
Weave/Scene/SceneObject.cpp
Weave/Scene/SceneObject.h

index 7e19a69952db650935a9c5c7257100a53b23503b..17ec7187e4a1d71ce54fe651809369942d8e908d 100644 (file)
@@ -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;
index 57879aa6604039ec2f566fe7ace4376aecc17cbc..0ce93d05ba282120a931d2ef14791e869e49985d 100644 (file)
@@ -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
index 5d83d6b8a853e439b4030580d396ec1af72b8ca6..a0ca119106d018fdbddf576f667221aedc3b7566 100644 (file)
@@ -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<Door*> (e.object))
+               {
+                       l->reverseTrigger();
+               }
+               break;
        }
 }
\ No newline at end of file
index dcc88f7ccf115deb79cca286e9b5933028bfea9f..656c828a3c109b6e9086d921c07cb2e0ccea707d 100644 (file)
@@ -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
index 9f81f02947c63d986efe06d946e9619f5b85453f..febf6dabec6c5168a38420ddb83876fc35156cc9 100644 (file)
@@ -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;