The position of water waves must not depend on how often the waves get drawn.
Especially not since an optimization does not draw the waves if they are not 
visible.
The position of the waves is game relevant as it determines how high the water 
is at specific x positions.
The height of the water influences the game:
For example determines the water height when a footbomb will fly slower due to 
water resistance and thus when the footbomb will explode.
---
 src/map/water.cpp |    9 +++++++--
 src/map/water.h   |    1 +
 2 files changed, 8 insertions(+), 2 deletions(-)

diff --git a/src/map/water.cpp b/src/map/water.cpp
index 31cb94f..3dde859 100644
--- a/src/map/water.cpp
+++ b/src/map/water.cpp
@@ -37,6 +37,7 @@ const uint GO_UP_TIME = 1; // min
 const uint GO_UP_STEP = 15; // pixels
 const uint GO_UP_OSCILLATION_TIME = 30; // seconds
 const uint GO_UP_OSCILLATION_NBR = 30; // amplitude
+const uint MS_BETWEEN_SHIFTS = 40;
 const double DEGREE = static_cast<double>(2*M_PI/360.0);
 const float t = (GO_UP_OSCILLATION_TIME*1000.0);
 const float a = GO_UP_STEP/t;
@@ -154,6 +155,12 @@ void Water::Refresh()
 
   height_mvt = 0;
 
+  uint now = Time::GetInstance()->Read();
+  if (next_wave_shift <= now) {
+    shift1 += 4*DEGREE;
+    next_wave_shift += MS_BETWEEN_SHIFTS;
+  }
+
   // Height Calculation:
   Time * global_time = Time::GetInstance();
   if (time_raise < global_time->Read())
@@ -247,8 +254,6 @@ void Water::Draw()
     angle2 += 4*DEGREE;
   }
 
-  shift1 += 4*DEGREE;
-
   SDL_UnlockSurface(bottom.GetSurface());
   SDL_UnlockSurface(pattern.GetSurface());
   SDL_UnlockSurface(surface.GetSurface());
diff --git a/src/map/water.h b/src/map/water.h
index 23d90bd..99a9655 100644
--- a/src/map/water.h
+++ b/src/map/water.h
@@ -48,6 +48,7 @@ private:
   Surface wpattern;
   std::string water_type;
   uint       m_last_preview_redraw;
+  uint next_wave_shift;
 
   void Init();
 
-- 
1.5.4.3


_______________________________________________
Wormux-dev mailing list
Wormux-dev@gna.org
https://mail.gna.org/listinfo/wormux-dev

Répondre à