Browse Source

increase entity movement speed if queue gets to long

Kolja Strohm 1 month ago
parent
commit
382c06f44d
3 changed files with 15 additions and 7 deletions
  1. 12 5
      FactoryCraft/Entity.cpp
  2. 1 0
      FactoryCraft/Entity.h
  3. 2 2
      FactoryCraft/Main.cpp

+ 12 - 5
FactoryCraft/Entity.cpp

@@ -15,7 +15,8 @@ Entity::Entity(const EntityType* zType,
     : FactoryCraftModel(),
       id(id),
       zType(zType),
-      playerControlled(0)
+      playerControlled(0),
+      frameLength(0.f)
 {
     pos = position;
     setModelDaten(model);
@@ -40,11 +41,8 @@ void Entity::api(char* message)
             frame.rotation = *(float*)(message += 4);
             frame.duration = *(float*)(message += 4);
             cs.lock();
+            frameLength += frame.duration;
             frames.add(frame);
-            if (frames.getEintragAnzahl() > 10)
-            {
-                frames.remove(0);
-            }
             cs.unlock();
             break;
         }
@@ -54,7 +52,16 @@ void Entity::api(char* message)
 bool Entity::tick(double time)
 {
     double totalTime = time;
+    if (frameLength > 1.f)
+    {
+        totalTime *= 1.5f;
+    }
     cs.lock();
+    frameLength -= totalTime;
+    if (frameLength < 0.f)
+    {
+        frameLength = 0.f;
+    }
     while (totalTime > 0)
     {
         if (currentFrame.duration <= 0)

+ 1 - 0
FactoryCraft/Entity.h

@@ -26,6 +26,7 @@ private:
     Framework::Critical cs;
     MovementFrame currentFrame;
     Framework::Array<MovementFrame> frames;
+    double frameLength;
 
 public:
     Entity(const EntityType* zType,

+ 2 - 2
FactoryCraft/Main.cpp

@@ -93,8 +93,8 @@ int KSGStart Framework::Start(Framework::Startparam p)
     }
 
     BlockType* type = new BlockType(
-        26, 1, ModelInfo("cube", "fluids.ltdb/water.png", 0, 6), 10, 1); // block type to render
-    Block* b = type->createBlock(Vec3<float>(0, 0, 0));
+        26, 1, ModelInfo("cube", "fluids.ltdb/water.png", 0, 6), 10, 1); //
+block type to render Block* b = type->createBlock(Vec3<float>(0, 0, 0));
     unsigned char light[] = {255, 255, 255, 255, 255, 255};
     b->setLightData(TOP, light);
     b->setLightData(NORTH, light);