Commit 2f55dd130c886376a45c9d0054dbd987cc055155

  • avatar
  • Bertram <bertram @ceg…el.net>
  • Thu Oct 15 01:38:18 CEST 2009
Speed code unification part 3: Made the client handle the speed in tiles per second in TMWserv.

While I was on it, I tweaked the default speed value to its final 6 tiles per second value,
which seems to be nice to me.

Another notice, the server does already send speed value to the player.

The keyboard movement protocol is one step ahead Release Candidate, enjoy ;)
src/being.cpp
(29 / 13)
  
5858#define BEING_EFFECTS_FILE "effects.xml"
5959#define HAIR_FILE "hair.xml"
6060
61int Being::mNumberOfHairstyles = 1;
61static const int DEFAULT_BEING_WIDTH = 32;
62static const int DEFAULT_BEING_HEIGHT = 32;
63extern const int MILLISECONDS_IN_A_TICK;
6264
63static const int DEFAULT_WIDTH = 32;
64static const int DEFAULT_HEIGHT = 32;
6565
66int Being::mNumberOfHairstyles = 1;
67
6668Being::Being(int id, int job, Map *map):
6769#ifdef EATHENA_SUPPORT
6870 mWalkTime(0),
8989 mChildParticleEffects(&mStatusParticleEffects, false),
9090 mMustResetParticles(false),
9191#ifdef TMWSERV_SUPPORT
92 mWalkSpeed(100),
92 mWalkSpeed(6.0f), // default speed in tile per second
9393#else
9494 mWalkSpeed(150),
9595#endif
527527 mDest : Vector(mPath.front().x,
528528 mPath.front().y);
529529
530 // The Vector representing the difference between current position
531 // and the next destination path node.
530532 Vector dir = dest - mPos;
531 const float length = dir.length();
532533
534 const float nominalLength = dir.length();
535
533536 // When we've not reached our destination, move to it.
534 if (length > 0.0f)
537 if (nominalLength > 0.0f && mWalkSpeed > 0.0f)
535538 {
536 const float speed = mWalkSpeed / 100.0f;
537539
540 // The private mWalkSpeed member is the speed in tiles per second.
541 // We translate it into pixels per tick,
542 // because the logic is called every ticks.
543 const float speedInTicks = ((float)DEFAULT_TILE_SIDE_LENGTH * mWalkSpeed)
544 / 1000 * (float)MILLISECONDS_IN_A_TICK;
545
546 // The deplacement of a point along a vector is calculated
547 // using the Unit Vector (â) multiplied by the point speed.
548 // â = a / ||a|| (||a|| is the a length.)
549 // Then, diff = (dir/||dir||)*speed, or (dir / ||dir|| / 1/speed).
550 Vector diff = (dir / (nominalLength / speedInTicks));
551
538552 // Test if we don't miss the destination by a move too far:
539 if ((dir / (length / speed)).length() > dir.length())
553 if (diff.length() > nominalLength)
540554 {
541555 setPosition(mPos + dir);
542556
561561 }
562562 // Otherwise, go to it using the nominal speed.
563563 else
564 setPosition(mPos + (dir / (length / speed)));
564 setPosition(mPos + diff);
565565
566566 if (mAction != WALK)
567567 setAction(WALK);
796796 break;
797797
798798 if (base)
799 return std::max(base->getWidth(), DEFAULT_WIDTH);
799 return std::max(base->getWidth(), DEFAULT_BEING_WIDTH);
800800 else
801 return DEFAULT_WIDTH;
801 return DEFAULT_BEING_WIDTH;
802802}
803803
804804int Being::getHeight() const
810810 break;
811811
812812 if (base)
813 return std::max(base->getHeight(), DEFAULT_HEIGHT);
813 return std::max(base->getHeight(), DEFAULT_BEING_HEIGHT);
814814 else
815 return DEFAULT_HEIGHT;
815 return DEFAULT_BEING_HEIGHT;
816816}
817817
818818void Being::setTargetAnimation(SimpleAnimation* animation)
src/being.h
(16 / 4)
  
259259 virtual Type getType() const { return UNKNOWN; }
260260
261261 /**
262 * Sets the walk speed (in pixels per second).
262 * Sets the walk speed.
263 * in pixels per second for eAthena,
264 * in tiles per second for TMWserv.
263265 */
264 void setWalkSpeed(int speed) { mWalkSpeed = speed; }
266 void setWalkSpeed(float speed) { mWalkSpeed = speed; }
265267
266 int getWalkSpeed() const { return mWalkSpeed; }
268 /**
269 * Gets the walk speed.
270 * in pixels per second for eAthena,
271 * in tiles per second for TMWserv (0.1 precision).
272 */
273 float getWalkSpeed() const { return mWalkSpeed; }
267274
268275 /**
269276 * Sets the sprite id.
575575 /** Speech Bubble components */
576576 SpeechBubble *mSpeechBubble;
577577
578 int mWalkSpeed; /**< Walking speed (pixels/sec) */
578 /**
579 * Walk speed.
580 * In pixels per second for eAthena,
581 * In tiles per second (0.1 precision) for TMWserv.
582 */
583 float mWalkSpeed;
579584
580585 Vector mPos;
581586 Vector mDest;
src/game.h
(1 / 0)
  
2929extern std::string map_path;
3030extern volatile int fps;
3131extern volatile int tick_time;
32extern const int MILLISECONDS_IN_A_TICK;
3233
3334class WindowMenu;
3435
  
4141extern volatile int tick_time;
4242
4343/**
44 * The used side-length for tiles
45 */
46const int DEFAULT_TILE_SIDE_LENGTH = 32;
47
48/**
4449 * A location on a tile map. Used for pathfinding, open list.
4550 */
4651struct Location
src/map.h
(2 / 0)
  
4343typedef MapSprites::iterator MapSprite;
4444typedef std::vector<MapLayer*> Layers;
4545
46extern const int DEFAULT_TILE_SIDE_LENGTH;
47
4648/**
4749 * A meta tile stores additional information about a location on a tile map.
4850 * This is information that doesn't need to be repeated for each tile in each
  
203203 }
204204 if (speed)
205205 {
206 /* The speed on the server is the cost of moving from one tile to
207 * the next. Beings get 1000 cost units per second. The speed is
208 * transferred as devided by 10, so that slower speeds fit in a
209 * byte. Here we convert the speed to pixels per second.
210 */
211 const float tilesPerSecond = 100.0f / speed;
212 being->setWalkSpeed((int) (tilesPerSecond * 32));
206 // The being's speed is transfered in tiles per second * 10
207 // to keep it transferable in a Byte.
208 // We set it back to tiles per second and in a float.
209 being->setWalkSpeed((float) speed / 10);
213210 }
214211
215212 // Ignore messages from the server for the local player