Previously Member::Draw() called Sprite::Update() which called 
SpriteAnimation::Update() which called CalculateWait().
Thus it was frame rate dependent of how often RandomSync() gets called, which 
results for different random seeds for different players.
---
 src/character/body.cpp   |   13 +++++++++++--
 src/character/body.h     |    1 +
 src/character/member.cpp |   36 ++++++++++++++++++++----------------
 src/character/member.h   |    7 +++++--
 src/game/game.cpp        |   10 +++++++---
 5 files changed, 44 insertions(+), 23 deletions(-)

diff --git a/src/character/body.cpp b/src/character/body.cpp
index c64585a..4a2e59c 100644
--- a/src/character/body.cpp
+++ b/src/character/body.cpp
@@ -451,6 +451,15 @@ void Body::Build()
   need_rebuild = false;
 }
 
+void Body::RefreshSprites()
+{
+  for (int layer=0;layer < (int)current_clothe->GetLayers().size() ;layer++) {
+    Member* member = current_clothe->GetLayers()[layer];
+    if (member->GetName() != "weapon")
+      member->RefreshSprite(direction);
+  }
+}
+
 std::string Body::GetFrameLoop() const
 {
   char str[32];
@@ -472,7 +481,7 @@ void Body::GetRelativeHandPosition(Point2i& result) const
 
 void Body::DrawWeaponMember(const Point2i& _pos)
 {
-  weapon_member->Draw(_pos, _pos.x + GetSize().x/2, int(direction));
+  weapon_member->Draw(_pos, _pos.x + GetSize().x/2, direction);
 }
 
 void Body::Draw(const Point2i& _pos)
@@ -492,7 +501,7 @@ void Body::Draw(const Point2i& _pos)
        draw_weapon_member++;
       }
     } else {
-      current_clothe->GetLayers()[layer]->Draw(_pos, _pos.x + GetSize().x/2, 
int(direction));
+      current_clothe->GetLayers()[layer]->Draw(_pos, _pos.x + GetSize().x/2, 
direction);
     }
   }
 
diff --git a/src/character/body.h b/src/character/body.h
index df025df..e07b702 100644
--- a/src/character/body.h
+++ b/src/character/body.h
@@ -135,6 +135,7 @@ public:
   uint GetMovementDuration() const;
   uint GetFrame() const { return current_frame; };
   uint GetFrameCount() const;
+  void RefreshSprites();
 
   void StartWalk();
   void StopWalk();
diff --git a/src/character/member.cpp b/src/character/member.cpp
index 4b147f1..9622c56 100644
--- a/src/character/member.cpp
+++ b/src/character/member.cpp
@@ -160,25 +160,27 @@ void Member::RotateSprite()
   spr->RefreshSurface();
 }
 
-void Member::Draw(const Point2i & _pos, int flip_center, int direction)
+void Member::RefreshSprite(BodyDirection direction)
 {
-  ASSERT(name != "weapon" && type!="weapon");
-
-  Point2i posi((int)pos.x, (int)pos.y);
-  posi += _pos;
+  // The sprite pointer may be invalid at the weapon sprite.
+  ASSERT(name != "weapon" && type != "weapon");
+  ASSERT(parent != NULL || type == "body");
 
-  if(direction == 1)
-  {
+  if (direction == DIRECTION_RIGHT) {
     spr->SetRotation_rad(angle_rad);
-    spr->Scale(scale.x,scale.y);
-  }
-  else
-  {
-    spr->Scale(-scale.x,scale.y);
+    spr->Scale(scale.x, scale.y);
+  } else {
+    spr->Scale(-scale.x, scale.y);
     spr->SetRotation_rad(-angle_rad);
-    posi.x = 2 * flip_center - posi.x - spr->GetWidth();
   }
 
+  spr->SetAlpha(alpha);
+  spr->Update();
+}
+
+void Member::Draw(const Point2i & _pos, int flip_center, BodyDirection 
direction)
+{
+  ASSERT(name != "weapon" && type != "weapon");
   ASSERT(parent != NULL || type == "body");
   if(parent == NULL && type != "body")
   {
@@ -186,8 +188,10 @@ void Member::Draw(const Point2i & _pos, int flip_center, 
int direction)
     return;
   }
 
-  spr->SetAlpha(alpha);
-  spr->Update();
+  Point2i posi((int)pos.x, (int)pos.y);
+  posi += _pos;
+  if (direction == DIRECTION_LEFT)
+    posi.x = 2 * flip_center - posi.x - spr->GetWidth();
   spr->Draw(posi);
 }
 
@@ -349,7 +353,7 @@ WeaponMember::~WeaponMember()
 {
 }
 
-void WeaponMember::Draw(const Point2i & /*_pos*/, int /*flip_center*/, int 
/*direction*/)
+void WeaponMember::Draw(const Point2i & /*_pos*/, int /*flip_center*/, 
BodyDirection /*direction*/)
 {
   if (!ActiveCharacter().IsDead() && Game::GetInstance()->ReadState() != 
Game::END_TURN)
     {
diff --git a/src/character/member.h b/src/character/member.h
index 01bd9b4..dba77a2 100644
--- a/src/character/member.h
+++ b/src/character/member.h
@@ -23,6 +23,7 @@
 #include <map>
 #include <vector>
 #include <WORMUX_point.h>
+#include "character/body.h"
 
 typedef std::vector<Point2f> v_attached;
 
@@ -63,13 +64,15 @@ public:
   Member(const xmlNode* xml, const std::string& main_folder);
   Member(const Member& m);
 
-  virtual void Draw(const Point2i & _pos, int flip_x, int direction);
+  virtual void Draw(const Point2i & _pos, int flip_x, BodyDirection direction);
 
   void RotateSprite();
   void ResetMovement();
   void ApplySqueleton(Member* parent_member);
   void ApplyMovement(const member_mvt& mvt, std::vector<class c_junction>& 
skel_lst);
   void SetAngle(const double &angle);
+  void RefreshSprite(BodyDirection direction);
+
   void SetPos(const Point2f &pos);
 
   const Sprite& GetSprite() const;
@@ -92,7 +95,7 @@ class WeaponMember : public Member
 public:
   WeaponMember();
   ~WeaponMember();
-  void Draw(const Point2i & _pos, int flip_x, int direction);
+  void Draw(const Point2i & _pos, int flip_x, BodyDirection direction);
 };
 
 #endif //MEMBER_H
diff --git a/src/game/game.cpp b/src/game/game.cpp
index d71d866..f295456 100644
--- a/src/game/game.cpp
+++ b/src/game/game.cpp
@@ -521,8 +521,10 @@ void Game::MainLoop()
       // For example the switch of characters can make it necessary to rebuild 
the body.
       // If no cacluate frame action is sheduled the frame calculation will be 
skipped and the bodies don't get build.
       // As the draw method needs builded characters we need to build here
-      FOR_ALL_CHARACTERS(team,character)
+      FOR_ALL_CHARACTERS(team,character) {
         character->GetBody()->Build();
+        character->GetBody()->RefreshSprites();
+      }
 
 
       if (Network::GetInstance()->IsTurnMaster()) {
@@ -569,8 +571,10 @@ void Game::MainLoop()
 
       // Build the characters if necessary so that it does not need to happen 
while drawing.
       // The build can become necessary again when for example weapons change 
the movement.
-      FOR_ALL_CHARACTERS(team,character)
-             character->GetBody()->Build();
+      FOR_ALL_CHARACTERS(team,character) {
+        character->GetBody()->Build();
+        character->GetBody()->RefreshSprites();
+      }
     } else {
       SDL_Delay(1);
     }
-- 
1.6.0.4


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

Répondre à