소스 검색

float delta time

dm 7 년 전
부모
커밋
be6af5a452

+ 24 - 0
oxygine/src/oxygine/Clock.cpp

@@ -128,11 +128,35 @@ namespace oxygine
         return (timeMS)_fixedStep;
         return (timeMS)_fixedStep;
     }
     }
 
 
+    float   Clock::doTickF()
+    {
+        if (_counter > 0)
+            return 0;
+
+        if (_srcTime + _fixedStep > _destTime)
+            return 0;
+
+        if (_fixedStep == 0)
+        {
+            float dt = _destTime - _srcTime;
+            _srcTime = _destTime;
+            return dt;
+        }
+
+        _srcTime += _fixedStep;
+        return _fixedStep;
+    }
+
     timeMS Clock::getTime() const
     timeMS Clock::getTime() const
     {
     {
         return (timeMS)_srcTime;
         return (timeMS)_srcTime;
     }
     }
 
 
+    float Clock::getTimeF() const
+    {
+        return _srcTime;
+    }
+
     int Clock::getPauseCounter() const
     int Clock::getPauseCounter() const
     {
     {
         return _counter;
         return _counter;

+ 2 - 0
oxygine/src/oxygine/Clock.h

@@ -12,6 +12,7 @@ namespace oxygine
         ~Clock();
         ~Clock();
 
 
         timeMS  getTime() const;
         timeMS  getTime() const;
+        float   getTimeF() const;
         int     getPauseCounter() const;
         int     getPauseCounter() const;
         int     getFixedStep() const;
         int     getFixedStep() const;
         int     getLastDT() const;
         int     getLastDT() const;
@@ -27,6 +28,7 @@ namespace oxygine
 
 
         void    update(timeMS globalTime = -1);
         void    update(timeMS globalTime = -1);
         timeMS  doTick();
         timeMS  doTick();
+        float   doTickF();
 
 
         std::string dump() const;
         std::string dump() const;
 
 

+ 1 - 1
oxygine/src/oxygine/TouchEvent.h

@@ -26,7 +26,7 @@ namespace oxygine
 
 
         TouchEvent(eventType type, bool Bubbles = true, const Vector2& locPosition = Vector2(0, 0)) : Event(type, Bubbles), localPosition(locPosition), position(locPosition), mouseButton(MouseButton_Touch), pressure(1.0f), index(1), __clickDispatched(false), wheelDirection(0, 0), __localScale(1.0f) {}
         TouchEvent(eventType type, bool Bubbles = true, const Vector2& locPosition = Vector2(0, 0)) : Event(type, Bubbles), localPosition(locPosition), position(locPosition), mouseButton(MouseButton_Touch), pressure(1.0f), index(1), __clickDispatched(false), wheelDirection(0, 0), __localScale(1.0f) {}
 
 
-        /**position in local space for Event::currentTarget Actor*/
+        /**position in local space for Event::currentTarget Actor (in space for actor with added EventCallback)*/
         Vector2 localPosition;
         Vector2 localPosition;
         /**position in local space for Event::target actor*/
         /**position in local space for Event::target actor*/
         Vector2 position;
         Vector2 position;

+ 9 - 3
oxygine/src/oxygine/UpdateState.h

@@ -6,14 +6,20 @@ namespace oxygine
     class UpdateState
     class UpdateState
     {
     {
     public:
     public:
-        UpdateState(): time(0), dt(0), iteration(0) {}
+        UpdateState(): time(0), dt(0), iteration(0), dtf(0){}
 
 
-        /**local time*/
+        /**local time in  milliseconds*/
         timeMS time;
         timeMS time;
 
 
-        /**delta time since last update*/
+        /**local time in  seconds*/
+        float timef;
+
+        /**delta time since last update in milliseconds*/
         timeMS dt;
         timeMS dt;
 
 
+        /*delta time since last update in seconds*/
+        float dtf;
+
         /**current iteration, used with fixed Clock update */
         /**current iteration, used with fixed Clock update */
         int iteration;
         int iteration;
     };
     };

+ 6 - 4
oxygine/src/oxygine/actor/Actor.cpp

@@ -1076,15 +1076,17 @@ namespace oxygine
             us.iteration = 0;
             us.iteration = 0;
             _clock->update();
             _clock->update();
 
 
-            timeMS dt = _clock->doTick();
-            while (dt > 0)
+            float dt = _clock->doTickF();
+            while (dt > 0.0f)
             {
             {
-                us.dt = dt;
+                us.dt = (timeMS)dt;
+                us.dtf = dt;
                 us.time = _clock->getTime();
                 us.time = _clock->getTime();
+                us.timef = _clock->getTimeF();
 
 
                 internalUpdate(us);
                 internalUpdate(us);
 
 
-                dt = _clock->doTick();
+                dt = _clock->doTickF();
                 us.iteration += 1;
                 us.iteration += 1;
             }
             }
         }
         }

+ 0 - 8
oxygine/src/oxygine/actor/Stage.cpp

@@ -127,14 +127,6 @@ namespace oxygine
         return RectF(-getPosition(), s);
         return RectF(-getPosition(), s);
     }
     }
 
 
-    /*
-    bool Stage::handleEvent(const EventState &es)
-    {
-        bool handled = Actor::handleEvent(es);
-        return handled;
-    }
-    */
-
     void Stage::render(const Color* clearColor, const Rect& viewport, const Matrix& view, const Matrix& proj)
     void Stage::render(const Color* clearColor, const Rect& viewport, const Matrix& view, const Matrix& proj)
     {
     {
 
 

+ 0 - 1
oxygine/src/oxygine/dev_tools/TreeInspectorPreview.h

@@ -116,7 +116,6 @@ namespace oxygine
     private:
     private:
         void doUpdate(const UpdateState& us) override;
         void doUpdate(const UpdateState& us) override;
         friend class TreeInspector;
         friend class TreeInspector;
-        //bool _onEvent(const EventState &es);
 
 
         Vector2 render2cache(spActor item, const Vector2& size,  bool child);
         Vector2 render2cache(spActor item, const Vector2& size,  bool child);
 
 

+ 0 - 2
oxygine/src/oxygine/oxygine-forwards.h

@@ -82,7 +82,6 @@ namespace oxygine
     DECLARE_SMART(Object, spObject);
     DECLARE_SMART(Object, spObject);
     DECLARE_SMART(Polygon, spPolygon);
     DECLARE_SMART(Polygon, spPolygon);
     DECLARE_SMART(ProgressBar, spProgressBar);
     DECLARE_SMART(ProgressBar, spProgressBar);
-    DECLARE_SMART(RenderTexture, spRenderTexture);
     DECLARE_SMART(ResAnim, spResAnim);
     DECLARE_SMART(ResAnim, spResAnim);
     DECLARE_SMART(ResBuffer, spResBuffer);
     DECLARE_SMART(ResBuffer, spResBuffer);
     DECLARE_SMART(ResFont, spResFont);
     DECLARE_SMART(ResFont, spResFont);
@@ -107,7 +106,6 @@ namespace oxygine
     class CreateResourceContext;
     class CreateResourceContext;
     class DebugActor;
     class DebugActor;
     class Event;
     class Event;
-    class EventState;
     class Font;
     class Font;
     class IVideoDriver;
     class IVideoDriver;
     class Image;
     class Image;