crash fix, add server beat
This commit is contained in:
parent
5faa903e18
commit
11bb365dce
|
@ -26,6 +26,7 @@
|
||||||
#include "map.h"
|
#include "map.h"
|
||||||
#include "tile.h"
|
#include "tile.h"
|
||||||
#include "item.h"
|
#include "item.h"
|
||||||
|
#include "game.h"
|
||||||
|
|
||||||
#include <framework/graphics/graphics.h>
|
#include <framework/graphics/graphics.h>
|
||||||
#include <framework/core/eventdispatcher.h>
|
#include <framework/core/eventdispatcher.h>
|
||||||
|
@ -161,7 +162,7 @@ void Creature::walk(const Position& position, bool inverse)
|
||||||
|
|
||||||
if(inverse) {
|
if(inverse) {
|
||||||
Position positionDelta = m_position - position;
|
Position positionDelta = m_position - position;
|
||||||
m_walkOffset = Point(positionDelta.x * 32, positionDelta.y * 32);
|
m_walkOffset = Point(positionDelta.x * Map::NUM_TILE_PIXELS, positionDelta.y * Map::NUM_TILE_PIXELS);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
m_walkOffset = Point(0, 0);
|
m_walkOffset = Point(0, 0);
|
||||||
|
@ -178,6 +179,7 @@ void Creature::walk(const Position& position, bool inverse)
|
||||||
|
|
||||||
float walkTime = 1000.0 * (float)groundSpeed / m_speed;
|
float walkTime = 1000.0 * (float)groundSpeed / m_speed;
|
||||||
walkTime = (walkTime == 0) ? 1000 : walkTime;
|
walkTime = (walkTime == 0) ? 1000 : walkTime;
|
||||||
|
walkTime = std::ceil(walkTime / g_game.getServerBeat()) * g_game.getServerBeat();
|
||||||
|
|
||||||
bool sameWalk = m_walking && !m_inverseWalking && inverse;
|
bool sameWalk = m_walking && !m_inverseWalking && inverse;
|
||||||
m_inverseWalking = inverse;
|
m_inverseWalking = inverse;
|
||||||
|
@ -237,9 +239,9 @@ void Creature::updateWalk()
|
||||||
m_walkOffset.x = -totalPixelsWalked;
|
m_walkOffset.x = -totalPixelsWalked;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(totalPixelsWalked == 32 || m_type->dimensions[ThingType::AnimationPhases] == 0)
|
if(totalPixelsWalked == 32 || m_type->dimensions[ThingType::AnimationPhases] <= 1)
|
||||||
m_animation = 0;
|
m_animation = 0;
|
||||||
else if(m_type->dimensions[ThingType::AnimationPhases] > 0)
|
else if(m_type->dimensions[ThingType::AnimationPhases] > 1)
|
||||||
m_animation = 1 + totalPixelsWalked * 4 / Map::NUM_TILE_PIXELS % (m_type->dimensions[ThingType::AnimationPhases] - 1);
|
m_animation = 1 + totalPixelsWalked * 4 / Map::NUM_TILE_PIXELS % (m_type->dimensions[ThingType::AnimationPhases] - 1);
|
||||||
|
|
||||||
if(g_clock.ticks() > m_walkEnd)
|
if(g_clock.ticks() > m_walkEnd)
|
||||||
|
@ -250,16 +252,9 @@ void Creature::updateWalk()
|
||||||
|
|
||||||
void Creature::cancelWalk(Otc::Direction direction)
|
void Creature::cancelWalk(Otc::Direction direction)
|
||||||
{
|
{
|
||||||
if(m_walking) {
|
|
||||||
auto self = asCreature();
|
|
||||||
g_dispatcher.scheduleEvent([=]() {
|
|
||||||
if(!self->m_walking)
|
|
||||||
self->m_animation = 0;
|
|
||||||
}, m_walkTimePerPixel * 2);
|
|
||||||
}
|
|
||||||
|
|
||||||
m_walking = false;
|
m_walking = false;
|
||||||
m_walkStart = 0;
|
m_walkStart = 0;
|
||||||
|
m_animation = 0;
|
||||||
m_walkOffset = Point(0, 0);
|
m_walkOffset = Point(0, 0);
|
||||||
setDirection(direction);
|
setDirection(direction);
|
||||||
}
|
}
|
||||||
|
|
|
@ -55,6 +55,9 @@ public:
|
||||||
|
|
||||||
bool isOnline() { return m_online; }
|
bool isOnline() { return m_online; }
|
||||||
|
|
||||||
|
void setServerBeat(int serverBeat) { m_serverBeat = serverBeat; }
|
||||||
|
int getServerBeat() { return m_serverBeat; }
|
||||||
|
|
||||||
LocalPlayerPtr getLocalPlayer() { return m_localPlayer; }
|
LocalPlayerPtr getLocalPlayer() { return m_localPlayer; }
|
||||||
ProtocolGamePtr getProtocolGame() { return m_protocolGame; }
|
ProtocolGamePtr getProtocolGame() { return m_protocolGame; }
|
||||||
|
|
||||||
|
@ -62,6 +65,7 @@ private:
|
||||||
LocalPlayerPtr m_localPlayer;
|
LocalPlayerPtr m_localPlayer;
|
||||||
ProtocolGamePtr m_protocolGame;
|
ProtocolGamePtr m_protocolGame;
|
||||||
bool m_online;
|
bool m_online;
|
||||||
|
int m_serverBeat;
|
||||||
};
|
};
|
||||||
|
|
||||||
extern Game g_game;
|
extern Game g_game;
|
||||||
|
|
|
@ -269,6 +269,7 @@ void ProtocolGame::parsePlayerLogin(InputMessage& msg)
|
||||||
|
|
||||||
m_localPlayer = LocalPlayerPtr(new LocalPlayer);
|
m_localPlayer = LocalPlayerPtr(new LocalPlayer);
|
||||||
m_localPlayer->setId(playerId);
|
m_localPlayer->setId(playerId);
|
||||||
|
g_game.setServerBeat(playerDrawSpeed);
|
||||||
m_localPlayer->setDrawSpeed(playerDrawSpeed);
|
m_localPlayer->setDrawSpeed(playerDrawSpeed);
|
||||||
m_localPlayer->setCanReportBugs(playerCanReportBugs);
|
m_localPlayer->setCanReportBugs(playerCanReportBugs);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue