change effects animation calculation
This commit is contained in:
parent
5b1b170165
commit
ce67fd1733
|
@ -8,33 +8,36 @@ function scheduleEvent(func, delay)
|
|||
eventId = eventId + 1
|
||||
local id = eventId
|
||||
local function proxyFunc()
|
||||
if eventsTable[id] then
|
||||
func()
|
||||
eventsTable[id] = nil
|
||||
end
|
||||
if eventsTable[id] then
|
||||
func()
|
||||
eventsTable[id] = nil
|
||||
end
|
||||
end
|
||||
eventsTable[id] = proxyFunc
|
||||
orig.scheduleEvent(proxyFunc, delay)
|
||||
return id
|
||||
end
|
||||
|
||||
-- FIXME: the event function can be collected
|
||||
-- and the dispatcher would call an invalid function, generating an warning
|
||||
function removeEvent(id)
|
||||
if id and eventsTable[id] then
|
||||
eventsTable[id] = nil
|
||||
return true
|
||||
end
|
||||
end
|
||||
|
||||
-- fix original addEvent
|
||||
function addEvent(func)
|
||||
eventId = eventId + 1
|
||||
local id = eventId
|
||||
local function proxyFunc()
|
||||
if eventsTable[id] then
|
||||
func()
|
||||
eventsTable[id] = nil
|
||||
end
|
||||
eventId = eventId + 1
|
||||
local id = eventId
|
||||
local function proxyFunc()
|
||||
if eventsTable[id] then
|
||||
func()
|
||||
eventsTable[id] = nil
|
||||
end
|
||||
eventsTable[id] = proxyFunc
|
||||
orig.addEvent(proxyFunc)
|
||||
return id
|
||||
end
|
||||
eventsTable[id] = proxyFunc
|
||||
orig.addEvent(proxyFunc)
|
||||
return id
|
||||
end
|
|
@ -2,8 +2,7 @@ CenterLabel < Label
|
|||
font: verdana-11px-rounded
|
||||
height: 16
|
||||
align: center
|
||||
anchors.top: parent.verticalCenter
|
||||
anchors.bottom: parent.verticalCenter
|
||||
anchors.verticalCenter: parent.verticalCenter
|
||||
anchors.left: parent.left
|
||||
anchors.right: parent.right
|
||||
|
||||
|
|
|
@ -663,6 +663,7 @@ std::string LuaInterface::functionSourcePath()
|
|||
|
||||
// gets function source path
|
||||
lua_Debug ar;
|
||||
memset(&ar, 0, sizeof(ar));
|
||||
lua_getinfo(L, ">Sn", &ar);
|
||||
if(ar.source) {
|
||||
// scripts coming from files has source beginning with '@'
|
||||
|
|
|
@ -29,31 +29,30 @@
|
|||
|
||||
Effect::Effect() : Thing()
|
||||
{
|
||||
m_lastTicks = g_platform.getTicks();
|
||||
m_finished = false;
|
||||
m_animationStartTicks = 0;
|
||||
}
|
||||
|
||||
void Effect::draw(int x, int y)
|
||||
{
|
||||
if(!m_finished) {
|
||||
if(g_platform.getTicks() - m_lastTicks > 75) {
|
||||
const ThingType& type = getType();
|
||||
if(m_animation+1 == type.animationPhases) {
|
||||
EffectPtr self = asEffect();
|
||||
g_dispatcher.addEvent([self] {
|
||||
g_map.getTile(self->getPosition())->removeEffect(self);
|
||||
});
|
||||
m_finished = true;
|
||||
}
|
||||
else
|
||||
m_animation++;
|
||||
m_lastTicks = g_platform.getTicks();
|
||||
}
|
||||
int animationPhase = (g_platform.getTicks() - m_animationStartTicks) / TICKS_PER_FRAME;
|
||||
|
||||
if(animationPhase < getAnimationPhases()) {
|
||||
m_animation = animationPhase;
|
||||
internalDraw(x, y, 0);
|
||||
}
|
||||
}
|
||||
|
||||
void Effect::startAnimation()
|
||||
{
|
||||
m_animationStartTicks = g_platform.getTicks();
|
||||
|
||||
// schedule removal
|
||||
auto self = asEffect();
|
||||
g_dispatcher.scheduleEvent([self]() {
|
||||
g_map.getTile(self->getPosition())->removeEffect(self);
|
||||
}, TICKS_PER_FRAME * getAnimationPhases());
|
||||
}
|
||||
|
||||
const ThingType& Effect::getType()
|
||||
{
|
||||
return g_thingsType.getEffectType(m_id);
|
||||
|
|
|
@ -28,20 +28,24 @@
|
|||
|
||||
class Effect : public Thing
|
||||
{
|
||||
enum {
|
||||
TICKS_PER_FRAME = 75
|
||||
};
|
||||
|
||||
public:
|
||||
Effect();
|
||||
|
||||
void draw(int x, int y);
|
||||
|
||||
bool finished() { return m_finished; }
|
||||
void startAnimation();
|
||||
void updateAnimation();
|
||||
|
||||
const ThingType& getType();
|
||||
|
||||
EffectPtr asEffect() { return std::static_pointer_cast<Effect>(shared_from_this()); }
|
||||
|
||||
private:
|
||||
int m_lastTicks;
|
||||
bool m_finished;
|
||||
int m_animationStartTicks;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
|
@ -200,7 +200,7 @@ void Map::addThing(const ThingPtr& thing, const Position& pos, int stackPos)
|
|||
tile->addThing(thing, stackPos);
|
||||
|
||||
if(CreaturePtr creature = thing->asCreature())
|
||||
m_creatures[creature ->getId()] = creature;
|
||||
m_creatures[creature->getId()] = creature;
|
||||
}
|
||||
|
||||
ThingPtr Map::getThing(const Position& pos, int stackPos)
|
||||
|
|
|
@ -73,7 +73,6 @@ private:
|
|||
Light m_light;
|
||||
Position m_centralPosition;
|
||||
|
||||
|
||||
FrameBufferPtr m_framebuffer;
|
||||
};
|
||||
|
||||
|
|
|
@ -48,6 +48,7 @@ public:
|
|||
Position getPosition() const { return m_position; }
|
||||
int getStackPriority();
|
||||
virtual const ThingType& getType() = 0;
|
||||
int getAnimationPhases() { return getType().animationPhases; }
|
||||
|
||||
virtual void onIdChange(int) {}
|
||||
virtual void onPositionChange(const Position&) {}
|
||||
|
|
|
@ -72,8 +72,9 @@ void Tile::draw(const Point& p)
|
|||
Rect thisTileRect(p.x, p.y, 32, 32);
|
||||
|
||||
// only render creatures where bottom right is inside our rect
|
||||
if(thisTileRect.contains(creatureRect.bottomRight()))
|
||||
if(thisTileRect.contains(creatureRect.bottomRight())) {
|
||||
creature->draw(p.x + xi*32 - m_drawElevation, p.y + yi*32 - m_drawElevation);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -516,6 +516,7 @@ void ProtocolGame::parseMagicEffect(InputMessage& msg)
|
|||
int effectId = msg.getU8();
|
||||
EffectPtr effect = EffectPtr(new Effect());
|
||||
effect->setId(effectId);
|
||||
effect->startAnimation();
|
||||
|
||||
TilePtr tile = g_map.getTile(pos);
|
||||
tile->addEffect(effect);
|
||||
|
|
|
@ -120,6 +120,7 @@ void OTClient::run()
|
|||
poll();
|
||||
|
||||
while(!m_stopping) {
|
||||
//g_platform.sleep(150);
|
||||
g_platform.updateTicks();
|
||||
frameTicks = g_platform.getTicks();
|
||||
|
||||
|
|
Loading…
Reference in New Issue