"desynchronize" animations patch

Discussions about developing

Moderators: Main Administator, Global Moderator

Post Reply
porges_
Xmoto Player
Xmoto Player
Posts: 3
Joined: Mon Jun 04, 2007 12:00 am

"desynchronize" animations patch

Post by porges_ » Mon Jun 04, 2007 12:04 am

Hi, I got annoyed at the fact that all the wreckers spun the same, so I made this patch to fix it. I ended up changing more than I wanted to because information about the entity state had to be passed from the entity through the renderer to the texture fetcher. However, I tried to keep my changes small, and the patch works the way it is supposed to. Perhaps this could be incorporated into the next version of Xmoto? :)

Here is the patch:

Code: Select all

diff -Naur xmoto-0.2.7/src/Renderer.cpp xmoto-0.2.7-1/src/Renderer.cpp
--- xmoto-0.2.7/src/Renderer.cpp        2007-03-16 06:52:11.000000000 +1300
+++ xmoto-0.2.7-1/src/Renderer.cpp      2007-06-04 11:14:18.000000000 +1200
@@ -1089,14 +1089,14 @@
        p[3] += pSprite->DynamicPosition();
 
         if(v_spriteType->getBlendMode() == SPRITE_BLENDMODE_ADDITIVE) {
-          _RenderAdditiveBlendedSection(v_spriteType->getTexture(),p[0],p[1],p[2],p[3]);      
+          _RenderAdditiveBlendedSection(v_spriteType->getTextureWithOffset(pSprite->FrameOffset()),p[0],p[1],p[2],p[3]);      
         }
         else {
 #ifdef ENABLE_OPENGL
           glEnable(GL_ALPHA_TEST);
           glAlphaFunc(GL_GEQUAL,0.5f);      
 #endif
-          _RenderAlphaBlendedSection(v_spriteType->getTexture(),p[0],p[1],p[2],p[3]);      
+          _RenderAlphaBlendedSection(v_spriteType->getTextureWithOffset(pSprite->FrameOffset()),p[0],p[1],p[2],p[3]);      
 #ifdef ENABLE_OPENGL
           glDisable(GL_ALPHA_TEST);
 #endif
diff -Naur xmoto-0.2.7/src/Theme.cpp xmoto-0.2.7-1/src/Theme.cpp
--- xmoto-0.2.7/src/Theme.cpp   2007-03-16 06:52:11.000000000 +1300
+++ xmoto-0.2.7-1/src/Theme.cpp 2007-06-04 11:25:13.000000000 +1200
@@ -595,24 +595,28 @@
 Sprite::~Sprite() {
 }
 
-vapp::Texture* Sprite::getTexture(bool bSmall, bool bClamp, vapp::FilterMode eFilterMode) {
+vapp::Texture* Sprite::getTextureWithOffset(unsigned char offset, bool bSmall, bool bClamp, vapp::FilterMode eFilterMode) {
   vapp::Texture* v_currentTexture;
 
-  v_currentTexture = getCurrentTexture();
+  v_currentTexture = getCurrentTexture(offset);
   if(v_currentTexture == NULL) {
-    v_currentTexture = m_associated_theme->loadTexture(getCurrentTextureFileName(),
+    v_currentTexture = m_associated_theme->loadTexture(getCurrentTextureFileName(offset),
                    bSmall,
                    bClamp,
                    eFilterMode);
     if(v_currentTexture == NULL) { 
-      throw Exception("Unable to load texture '" + getCurrentTextureFileName() + "'");
+      throw Exception("Unable to load texture '" + getCurrentTextureFileName(offset) + "'");
     }
-    setCurrentTexture(v_currentTexture);
+    setCurrentTexture(v_currentTexture, offset);
   }
 
   return v_currentTexture;
 }
 
+vapp::Texture* Sprite::getTexture(bool bSmall, bool bClamp, vapp::FilterMode eFilterMode) {
+  return getTextureWithOffset(0, bSmall, bClamp, eFilterMode);
+}
+
 SpriteBlendMode Sprite::getBlendMode() {
   return m_blendmode;
 }
@@ -641,20 +645,21 @@
   return THEME_ANIMATION_SPRITE_FILE_DIR;
 }
 
-vapp::Texture* AnimationSprite::getCurrentTexture() {
+vapp::Texture* AnimationSprite::getCurrentTexture(unsigned char offset) {
   if(m_frames.size() == 0) {return NULL;}
-  return m_frames[getCurrentFrame()]->getTexture();
+  return m_frames[(getCurrentFrame()+offset) % m_frames.size()]->getTexture();
 }
 
-std::string AnimationSprite::getCurrentTextureFileName() {
+
+std::string AnimationSprite::getCurrentTextureFileName(unsigned char offset) {
   char v_num[3];
-  snprintf(v_num, 3, "%02i", getCurrentFrame() % 100); // max 100 frames by animation
+  snprintf(v_num, 3, "%02i", ((getCurrentFrame() + offset) % m_frames.size()) % 100); // max 100 frames by animation
 
   return getFileDir() + "/" + m_fileBase + std::string(v_num) + std::string(".") + m_fileExtension;
 }
 
-void AnimationSprite::setCurrentTexture(vapp::Texture *p_texture) {
-  m_frames[getCurrentFrame()]->setTexture(p_texture);
+void AnimationSprite::setCurrentTexture(vapp::Texture *p_texture, unsigned char offset) {
+  m_frames[(getCurrentFrame()+offset) % m_frames.size()]->setTexture(p_texture);
 }
 
 int AnimationSprite::getCurrentFrame() {
@@ -872,15 +877,15 @@
 SimpleFrameSprite::~SimpleFrameSprite() {
 }
 
-vapp::Texture* SimpleFrameSprite::getCurrentTexture() {
+vapp::Texture* SimpleFrameSprite::getCurrentTexture(unsigned char offset /* ignored */) {
   return m_texture;
 }
 
-std::string SimpleFrameSprite::getCurrentTextureFileName() {
+std::string SimpleFrameSprite::getCurrentTextureFileName(unsigned char offset /* ignored */) {
   return getFileDir() + "/" + m_fileName;
 }
 
-void SimpleFrameSprite::setCurrentTexture(vapp::Texture *p_texture) {
+void SimpleFrameSprite::setCurrentTexture(vapp::Texture *p_texture, unsigned char offset /* ignored */) {
   m_texture = p_texture;
 }
 
diff -Naur xmoto-0.2.7/src/Theme.h xmoto-0.2.7-1/src/Theme.h
--- xmoto-0.2.7/src/Theme.h     2007-03-16 06:52:11.000000000 +1300
+++ xmoto-0.2.7-1/src/Theme.h   2007-06-04 11:26:27.000000000 +1200
@@ -145,11 +145,12 @@
      only the first time that getTexture is called for a given sprite
   */
   vapp::Texture* getTexture(bool bSmall=false, bool bClamp=false, vapp::FilterMode eFilterMode = vapp::FM_LINEAR);
+  vapp::Texture* getTextureWithOffset(unsigned char offset, bool bSmall=false, bool bClamp=false, vapp::FilterMode eFilterMode = vapp::FM_LINEAR);
 
  protected:
-  virtual vapp::Texture* getCurrentTexture() = 0;
-  virtual std::string getCurrentTextureFileName() = 0;
-  virtual void setCurrentTexture(vapp::Texture *p_texture) = 0;
+  virtual vapp::Texture* getCurrentTexture(unsigned char offset) = 0;
+  virtual std::string getCurrentTextureFileName(unsigned char offset) = 0;
+  virtual void setCurrentTexture(vapp::Texture *p_texture, unsigned char offset) = 0;
   virtual std::string getFileDir();
   enum SpriteType m_type;
 
@@ -165,9 +166,9 @@
   virtual ~SimpleFrameSprite();
 
  protected:
-  vapp::Texture* getCurrentTexture();
-  std::string getCurrentTextureFileName();
-  void setCurrentTexture(vapp::Texture *p_texture);
+  vapp::Texture* getCurrentTexture(unsigned char offset);
+  std::string getCurrentTextureFileName(unsigned char offset);
+  void setCurrentTexture(vapp::Texture *p_texture, unsigned char offset);
 
  private:
   std::string m_fileName;
@@ -239,8 +240,9 @@
 
  protected:
   vapp::Texture* getCurrentTexture();
-  std::string getCurrentTextureFileName();
-  void setCurrentTexture(vapp::Texture *p_texture);
+  vapp::Texture * getCurrentTexture(unsigned char offset);
+  std::string getCurrentTextureFileName(unsigned char offset);
+  void setCurrentTexture(vapp::Texture *p_texture, unsigned char offset);
   std::string getFileDir();
 
  private:
diff -Naur xmoto-0.2.7/src/xmscene/Entity.cpp xmoto-0.2.7-1/src/xmscene/Entity.cpp
--- xmoto-0.2.7/src/xmscene/Entity.cpp  2007-03-16 06:52:09.000000000 +1300
+++ xmoto-0.2.7-1/src/xmscene/Entity.cpp        2007-06-04 11:42:56.000000000 +1200
@@ -38,11 +38,19 @@
   m_isToTake    = false;
   m_BBox.reset();
   m_isBBoxDirty = true;
+
+  m_frameOffset = CHAR_MAX;
 }
 
 Entity::~Entity() {
 }
 
+unsigned char Entity::FrameOffset() {
+  if (m_frameOffset == CHAR_MAX) //save entropy to delay heat death of the universe
+    m_frameOffset = rand()%85;   //85 should be enough, 100 is max frames anyway
+  return m_frameOffset;
+}
+
 void Entity::loadToPlay() {
   m_dynamicPosition = m_initialPosition;
   /* make every entity alive */
diff -Naur xmoto-0.2.7/src/xmscene/Entity.h xmoto-0.2.7-1/src/xmscene/Entity.h
--- xmoto-0.2.7/src/xmscene/Entity.h    2007-03-16 06:52:09.000000000 +1300
+++ xmoto-0.2.7-1/src/xmscene/Entity.h  2007-06-04 11:46:48.000000000 +1200
@@ -56,6 +56,7 @@
   float Width() const;
   float Height() const;
   float DrawAngle() const;
+  unsigned char FrameOffset();
   bool  DrawReversed() const;
   const TColor& Color() const;
   std::string SpriteName() const; /* PlayerStart, Flower, EndOfLevel, Bird, ... */
@@ -103,6 +104,7 @@
   bool        m_doesKill;
   bool        m_doesMakeWin;
   bool        m_isToTake;
+  unsigned char        m_frameOffset;
   /* Use to know if a script shall update the pos of the entity*/
   bool        m_isAlive;
   TColor      m_color;

porges_
Xmoto Player
Xmoto Player
Posts: 3
Joined: Mon Jun 04, 2007 12:00 am

Post by porges_ » Mon Jun 04, 2007 4:44 am

Also, I changed it to show up wreckers in the minimap. A nice alarmingly yellow colour :)

Code: Select all

--- xmoto-0.2.7/src/Renderer.cpp        2007-03-16 06:52:11.000000000 +1300
+++ xmoto-0.2.7-1/src/Renderer.cpp      2007-06-04 14:11:15.000000000 +1200
@@ -416,11 +416,17 @@
     for(int i=0;i<Entities>DynamicPosition().x),
                         LEVEL_TO_SCREEN_Y(Entities[i]->DynamicPosition().y));
-      if(Entities[i]->DoesMakeWin()) {
-        getParent()->getDrawLib()->drawCircle(entityPos, 3, 0, MAKE_COLOR(255,0,255,255), 0);
-      }
-      else if(Entities[i]->IsToTake()) {
-        getParent()->getDrawLib()->drawCircle(entityPos, 3, 0, MAKE_COLOR(255,0,0,255), 0);
+      switch(Entities[i]->Speciality()) {
+        case ET_MAKEWIN:
+          getParent()->getDrawLib()->drawCircle(entityPos, 3, 0, MAKE_COLOR(255,0,255,255), 0);
+          break;
+        case ET_ISTOTAKE:
+          getParent()->getDrawLib()->drawCircle(entityPos, 3, 0, MAKE_COLOR(255,0,0,255), 0);
+          break;
+        case ET_KILL:
+          getParent()->getDrawLib()->drawCircle(entityPos, 3, 0, MAKE_COLOR(255,255,0,255), 0);
+          break;
+        default: break;
       }
     }

porges_
Xmoto Player
Xmoto Player
Posts: 3
Joined: Mon Jun 04, 2007 12:00 am

Post by porges_ » Sun Jun 10, 2007 12:38 am

No comments?

User avatar
aspegic500
Main Administator
Main Administator
Posts: 735
Joined: Thu Apr 06, 2006 4:53 pm

Post by aspegic500 » Sun Jun 10, 2007 8:48 am

hi, personnally, i'm not really fan. If i resumize, you change the animation synchronisation. You could send a message on the "message tab" to give your email so that we can discuss about it.

User avatar
avova
Xmoto-Player Advanced
Posts: 240
Joined: Sun Mar 18, 2007 4:10 pm

Post by avova » Mon Aug 27, 2007 1:27 am

Aspegic,could you accept the patch for showing wreckers in the minimap ?? its needed, imho

User avatar
aspegic500
Main Administator
Main Administator
Posts: 735
Joined: Thu Apr 06, 2006 4:53 pm

Post by aspegic500 » Mon Aug 27, 2007 8:03 am

issue created on http://todo.xmoto.tuxfamily.org
next time, just add it yourself if you want to be sure it is traced. (some messages of this forum could be never read)

User avatar
-slim-shady-
Xmoto Player
Xmoto Player
Posts: 12
Joined: Mon Sep 28, 2009 3:16 am
Location: Some Where But Nowhere
Contact:

hi

Post by -slim-shady- » Mon Sep 28, 2009 3:48 am

Where do you put the codes in
Me Da Bomb & you are Not!!!!!!!!!!!!!!!!

Go Here: http://www.slimshady.host22.com

unnheulu
Administrator
Administrator
Posts: 616
Joined: Sat Oct 04, 2008 9:04 am

Post by unnheulu » Mon Sep 28, 2009 4:08 pm

TBH shady, if you don't know its not worth the bother to you.
Image

User avatar
-slim-shady-
Xmoto Player
Xmoto Player
Posts: 12
Joined: Mon Sep 28, 2009 3:16 am
Location: Some Where But Nowhere
Contact:

Post by -slim-shady- » Mon Sep 28, 2009 8:37 pm

hey i aint gonna learn with people like YOU So Can You Please Tell Me
Me Da Bomb & you are Not!!!!!!!!!!!!!!!!

Go Here: http://www.slimshady.host22.com

User avatar
Gaivota
Xmoto-Player Advanced
Posts: 233
Joined: Thu Apr 05, 2007 3:01 pm

Post by Gaivota » Mon Sep 28, 2009 9:26 pm

Google can teach you how to patch.
Anyway you wont succeed, because the patch is for a version which is some years old, and the patch wont work on recent versions. So just stop wasting your time trying.

gaivota

User avatar
-slim-shady-
Xmoto Player
Xmoto Player
Posts: 12
Joined: Mon Sep 28, 2009 3:16 am
Location: Some Where But Nowhere
Contact:

Post by -slim-shady- » Tue Sep 29, 2009 3:45 am

dude i looked and i could not find any thing useful [smilie=row1_25.gif] [smilie=row1_13.gif]



man just tell me how and ill stop asking
Me Da Bomb & you are Not!!!!!!!!!!!!!!!!

Go Here: http://www.slimshady.host22.com

User avatar
Gaivota
Xmoto-Player Advanced
Posts: 233
Joined: Thu Apr 05, 2007 3:01 pm

Post by Gaivota » Tue Sep 29, 2009 11:26 am

man just tell me how and ill stop asking
in sourcetree, "patch -p0 < patchfile"

User avatar
-slim-shady-
Xmoto Player
Xmoto Player
Posts: 12
Joined: Mon Sep 28, 2009 3:16 am
Location: Some Where But Nowhere
Contact:

Post by -slim-shady- » Tue Sep 29, 2009 8:32 pm

where is that
Me Da Bomb & you are Not!!!!!!!!!!!!!!!!

Go Here: http://www.slimshady.host22.com

unnheulu
Administrator
Administrator
Posts: 616
Joined: Sat Oct 04, 2008 9:04 am

Post by unnheulu » Wed Sep 30, 2009 2:56 pm

Go to the root of the source code directory and then type the command (if your on linux and the xmoto source dir is in your home directory type):

Code: Select all

cd ~/xmoto 5.2/ /*(or whatever the directory name is)*/
patch -p0 < patchfile
Image

Post Reply

Return to “Developer's side”

Who is online

Users browsing this forum: No registered users and 1 guest