From 5d1a76ae7725af998c6ee46adfe492c68ee1d34f Mon Sep 17 00:00:00 2001 From: Daniel Karbach Date: Thu, 27 Dec 2012 15:52:42 +0100 Subject: [PATCH] switched geometric scalars from floating to fixed --- src/app/Application.cpp | 4 +-- src/app/State.h | 6 ++-- src/battle/BattleState.cpp | 2 +- src/battle/BattleState.h | 2 +- src/battle/states/PerformAttacks.cpp | 2 +- src/battle/states/PerformAttacks.h | 2 +- src/battle/states/RunState.cpp | 2 +- src/battle/states/RunState.h | 2 +- src/battle/states/SelectAttackType.cpp | 2 +- src/battle/states/SelectAttackType.h | 2 +- src/battle/states/SelectIkari.cpp | 2 +- src/battle/states/SelectIkari.h | 2 +- src/battle/states/SelectItem.cpp | 2 +- src/battle/states/SelectItem.h | 2 +- src/battle/states/SelectMoveAction.cpp | 2 +- src/battle/states/SelectMoveAction.h | 2 +- src/battle/states/SelectSpell.cpp | 2 +- src/battle/states/SelectSpell.h | 2 +- src/battle/states/SelectTarget.cpp | 2 +- src/battle/states/SelectTarget.h | 2 +- src/battle/states/SwapHeroes.cpp | 2 +- src/battle/states/SwapHeroes.h | 2 +- src/graphics/Camera.cpp | 9 +++--- src/graphics/Camera.h | 7 +++-- src/graphics/ColorFade.cpp | 2 +- src/graphics/ColorFade.h | 2 +- src/main.cpp | 12 ++++---- src/map/Entity.cpp | 23 ++++++++------- src/map/Entity.h | 19 ++++++------ src/map/MapState.cpp | 41 +++++++++++++------------- src/map/MapState.h | 9 +++--- src/map/TransitionState.cpp | 2 +- src/map/TransitionState.h | 2 +- src/menu/CapsuleChangeMenu.cpp | 2 +- src/menu/CapsuleChangeMenu.h | 2 +- src/menu/CapsuleFeedMenu.cpp | 2 +- src/menu/CapsuleFeedMenu.h | 2 +- src/menu/CapsuleMenu.cpp | 2 +- src/menu/CapsuleMenu.h | 2 +- src/menu/CapsuleNameMenu.cpp | 2 +- src/menu/CapsuleNameMenu.h | 2 +- src/menu/ChangeHero.cpp | 2 +- src/menu/ChangeHero.h | 2 +- src/menu/ConfigMenu.cpp | 2 +- src/menu/ConfigMenu.h | 2 +- src/menu/EquipMenu.cpp | 2 +- src/menu/EquipMenu.h | 2 +- src/menu/InventoryMenu.cpp | 2 +- src/menu/InventoryMenu.h | 2 +- src/menu/PartyMenu.cpp | 2 +- src/menu/PartyMenu.h | 2 +- src/menu/ScenarioMenu.cpp | 2 +- src/menu/ScenarioMenu.h | 2 +- src/menu/SelectHero.cpp | 2 +- src/menu/SelectHero.h | 2 +- src/menu/SpellMenu.cpp | 2 +- src/menu/SpellMenu.h | 2 +- src/menu/StatusMenu.cpp | 2 +- src/menu/StatusMenu.h | 2 +- 59 files changed, 119 insertions(+), 111 deletions(-) diff --git a/src/app/Application.cpp b/src/app/Application.cpp index 0a5f5e7..76d98ef 100644 --- a/src/app/Application.cpp +++ b/src/app/Application.cpp @@ -175,8 +175,8 @@ void Application::HandleEvents() { void Application::UpdateWorld(Uint32 deltaT) { if (!CurrentState()) return; for (Uint32 i(0); i < deltaT && !StateChangePending(); ++i) { - CurrentState()->PhysicsTimers().Update(0.001f); - CurrentState()->UpdateWorld(0.001f); + CurrentState()->PhysicsTimers().Update(1); + CurrentState()->UpdateWorld(1); } } diff --git a/src/app/State.h b/src/app/State.h index 19b6fe0..0b8d51f 100644 --- a/src/app/State.h +++ b/src/app/State.h @@ -31,7 +31,7 @@ public: /// Handle interactive events such as input and timers. virtual void HandleEvents(const Input &) = 0; /// Update the time-dependant world representation. - virtual void UpdateWorld(float deltaT) = 0; + virtual void UpdateWorld(Uint32 deltaMs) = 0; /// Draw a picture of the world. virtual void Render(SDL_Surface *) = 0; @@ -70,12 +70,12 @@ public: /// Timers handle intended for graphics, sync'ed with world time. /// These timers are only updated for the stack top and thus appear paused /// when the state is visible (roughly). - Timers &PhysicsTimers() { return physicsTimers; } + Timers &PhysicsTimers() { return physicsTimers; } private: Application *ctrl; Timers graphicsTimers; - Timers physicsTimers; + Timers physicsTimers; }; diff --git a/src/battle/BattleState.cpp b/src/battle/BattleState.cpp index 8218c10..cfac62d 100644 --- a/src/battle/BattleState.cpp +++ b/src/battle/BattleState.cpp @@ -389,7 +389,7 @@ void BattleState::HandleEvents(const Input &input) { } -void BattleState::UpdateWorld(float deltaT) { +void BattleState::UpdateWorld(Uint32 deltaT) { } diff --git a/src/battle/BattleState.h b/src/battle/BattleState.h index 5258895..d242371 100644 --- a/src/battle/BattleState.h +++ b/src/battle/BattleState.h @@ -52,7 +52,7 @@ public: public: virtual void HandleEvents(const app::Input &); - virtual void UpdateWorld(float deltaT); + virtual void UpdateWorld(Uint32 deltaT); virtual void Render(SDL_Surface *); public: diff --git a/src/battle/states/PerformAttacks.cpp b/src/battle/states/PerformAttacks.cpp index f930de9..2f750b2 100644 --- a/src/battle/states/PerformAttacks.cpp +++ b/src/battle/states/PerformAttacks.cpp @@ -217,7 +217,7 @@ void PerformAttacks::ResetAnimation() { } -void PerformAttacks::UpdateWorld(float deltaT) { +void PerformAttacks::UpdateWorld(Uint32 deltaT) { } diff --git a/src/battle/states/PerformAttacks.h b/src/battle/states/PerformAttacks.h index de20f76..adbf3ba 100644 --- a/src/battle/states/PerformAttacks.h +++ b/src/battle/states/PerformAttacks.h @@ -30,7 +30,7 @@ public: public: virtual void HandleEvents(const app::Input &); - virtual void UpdateWorld(float deltaT); + virtual void UpdateWorld(Uint32 deltaT); virtual void Render(SDL_Surface *); private: diff --git a/src/battle/states/RunState.cpp b/src/battle/states/RunState.cpp index afbbe53..956fa13 100644 --- a/src/battle/states/RunState.cpp +++ b/src/battle/states/RunState.cpp @@ -52,7 +52,7 @@ void RunState::HandleEvents(const Input &input) { } -void RunState::UpdateWorld(float deltaT) { +void RunState::UpdateWorld(Uint32 deltaT) { } diff --git a/src/battle/states/RunState.h b/src/battle/states/RunState.h index cdf7881..f21280e 100644 --- a/src/battle/states/RunState.h +++ b/src/battle/states/RunState.h @@ -24,7 +24,7 @@ public: public: virtual void HandleEvents(const app::Input &); - virtual void UpdateWorld(float deltaT); + virtual void UpdateWorld(Uint32 deltaT); virtual void Render(SDL_Surface *); private: diff --git a/src/battle/states/SelectAttackType.cpp b/src/battle/states/SelectAttackType.cpp index 9f6e561..0dd5bc4 100644 --- a/src/battle/states/SelectAttackType.cpp +++ b/src/battle/states/SelectAttackType.cpp @@ -121,7 +121,7 @@ void SelectAttackType::HandleEvents(const Input &input) { } } -void SelectAttackType::UpdateWorld(float deltaT) { +void SelectAttackType::UpdateWorld(Uint32 deltaT) { } diff --git a/src/battle/states/SelectAttackType.h b/src/battle/states/SelectAttackType.h index c096fa0..c8f6e99 100644 --- a/src/battle/states/SelectAttackType.h +++ b/src/battle/states/SelectAttackType.h @@ -23,7 +23,7 @@ public: public: virtual void HandleEvents(const app::Input &); - virtual void UpdateWorld(float deltaT); + virtual void UpdateWorld(Uint32 deltaT); virtual void Render(SDL_Surface *); private: diff --git a/src/battle/states/SelectIkari.cpp b/src/battle/states/SelectIkari.cpp index 4bfea03..4b8c5b8 100644 --- a/src/battle/states/SelectIkari.cpp +++ b/src/battle/states/SelectIkari.cpp @@ -93,7 +93,7 @@ void SelectIkari::HandleEvents(const Input &input) { } } -void SelectIkari::UpdateWorld(float deltaT) { +void SelectIkari::UpdateWorld(Uint32 deltaT) { } diff --git a/src/battle/states/SelectIkari.h b/src/battle/states/SelectIkari.h index ca08732..e665c69 100644 --- a/src/battle/states/SelectIkari.h +++ b/src/battle/states/SelectIkari.h @@ -24,7 +24,7 @@ public: public: virtual void HandleEvents(const app::Input &); - virtual void UpdateWorld(float deltaT); + virtual void UpdateWorld(Uint32 deltaT); virtual void Render(SDL_Surface *); private: diff --git a/src/battle/states/SelectItem.cpp b/src/battle/states/SelectItem.cpp index b643116..acebefa 100644 --- a/src/battle/states/SelectItem.cpp +++ b/src/battle/states/SelectItem.cpp @@ -92,7 +92,7 @@ void SelectItem::HandleEvents(const Input &input) { } } -void SelectItem::UpdateWorld(float deltaT) { +void SelectItem::UpdateWorld(Uint32 deltaT) { } diff --git a/src/battle/states/SelectItem.h b/src/battle/states/SelectItem.h index 97863e2..2bf4d59 100644 --- a/src/battle/states/SelectItem.h +++ b/src/battle/states/SelectItem.h @@ -23,7 +23,7 @@ public: public: virtual void HandleEvents(const app::Input &); - virtual void UpdateWorld(float deltaT); + virtual void UpdateWorld(Uint32 deltaT); virtual void Render(SDL_Surface *); private: diff --git a/src/battle/states/SelectMoveAction.cpp b/src/battle/states/SelectMoveAction.cpp index 74e8628..b77f98c 100644 --- a/src/battle/states/SelectMoveAction.cpp +++ b/src/battle/states/SelectMoveAction.cpp @@ -68,7 +68,7 @@ void SelectMoveAction::HandleEvents(const Input &input) { } } -void SelectMoveAction::UpdateWorld(float deltaT) { +void SelectMoveAction::UpdateWorld(Uint32 deltaT) { } diff --git a/src/battle/states/SelectMoveAction.h b/src/battle/states/SelectMoveAction.h index 069f98d..0e973d4 100644 --- a/src/battle/states/SelectMoveAction.h +++ b/src/battle/states/SelectMoveAction.h @@ -23,7 +23,7 @@ public: public: virtual void HandleEvents(const app::Input &); - virtual void UpdateWorld(float deltaT); + virtual void UpdateWorld(Uint32 deltaT); virtual void Render(SDL_Surface *); private: diff --git a/src/battle/states/SelectSpell.cpp b/src/battle/states/SelectSpell.cpp index e15fa2e..8c0c4da 100644 --- a/src/battle/states/SelectSpell.cpp +++ b/src/battle/states/SelectSpell.cpp @@ -93,7 +93,7 @@ void SelectSpell::HandleEvents(const Input &input) { } } -void SelectSpell::UpdateWorld(float deltaT) { +void SelectSpell::UpdateWorld(Uint32 deltaT) { } diff --git a/src/battle/states/SelectSpell.h b/src/battle/states/SelectSpell.h index 93734a3..8ad19f1 100644 --- a/src/battle/states/SelectSpell.h +++ b/src/battle/states/SelectSpell.h @@ -23,7 +23,7 @@ public: public: virtual void HandleEvents(const app::Input &); - virtual void UpdateWorld(float deltaT); + virtual void UpdateWorld(Uint32 deltaT); virtual void Render(SDL_Surface *); private: diff --git a/src/battle/states/SelectTarget.cpp b/src/battle/states/SelectTarget.cpp index 1644c2e..a0955b2 100644 --- a/src/battle/states/SelectTarget.cpp +++ b/src/battle/states/SelectTarget.cpp @@ -75,7 +75,7 @@ void SelectTarget::HandleEvents(const Input &input) { } } -void SelectTarget::UpdateWorld(float deltaT) { +void SelectTarget::UpdateWorld(Uint32 deltaT) { } diff --git a/src/battle/states/SelectTarget.h b/src/battle/states/SelectTarget.h index 542e0e4..8970260 100644 --- a/src/battle/states/SelectTarget.h +++ b/src/battle/states/SelectTarget.h @@ -24,7 +24,7 @@ public: public: virtual void HandleEvents(const app::Input &); - virtual void UpdateWorld(float deltaT); + virtual void UpdateWorld(Uint32 deltaT); virtual void Render(SDL_Surface *); private: diff --git a/src/battle/states/SwapHeroes.cpp b/src/battle/states/SwapHeroes.cpp index 9bde2b3..da2342b 100644 --- a/src/battle/states/SwapHeroes.cpp +++ b/src/battle/states/SwapHeroes.cpp @@ -110,7 +110,7 @@ void SwapHeroes::MoveLeft() { } -void SwapHeroes::UpdateWorld(float deltaT) { +void SwapHeroes::UpdateWorld(Uint32 deltaT) { } diff --git a/src/battle/states/SwapHeroes.h b/src/battle/states/SwapHeroes.h index 14d0d72..7ebf3f5 100644 --- a/src/battle/states/SwapHeroes.h +++ b/src/battle/states/SwapHeroes.h @@ -23,7 +23,7 @@ public: public: virtual void HandleEvents(const app::Input &); - virtual void UpdateWorld(float deltaT); + virtual void UpdateWorld(Uint32 deltaT); virtual void Render(SDL_Surface *); private: diff --git a/src/graphics/Camera.cpp b/src/graphics/Camera.cpp index ee87e3f..ad44c04 100644 --- a/src/graphics/Camera.cpp +++ b/src/graphics/Camera.cpp @@ -2,17 +2,18 @@ #include +using math::Fixed; using math::Vector; namespace graphics { -Camera::Camera(int width, int height, const Vector *target) +Camera::Camera(int width, int height, const Vector > *target) : target(target), halfWidth(width / 2), halfHeight(height / 2) { } -void Camera::SetTarget(const Vector *t) { +void Camera::SetTarget(const Vector > *t) { target = t; } @@ -20,8 +21,8 @@ void Camera::SetTarget(const Vector *t) { Vector Camera::CalculateOffset() const { if (target) { return Vector( - (target->X() - halfWidth) * -1, - (target->Y() - halfHeight) * -1); + (target->X().Int() - halfWidth) * -1, + (target->Y().Int() - halfHeight) * -1); } else { return Vector(); } diff --git a/src/graphics/Camera.h b/src/graphics/Camera.h index 6067bab..4b2216b 100644 --- a/src/graphics/Camera.h +++ b/src/graphics/Camera.h @@ -1,6 +1,7 @@ #ifndef GRAPHICS_CAMERA_H_ #define GRAPHICS_CAMERA_H_ +#include "../math/Fixed.h" #include "../math/Vector.h" namespace graphics { @@ -8,17 +9,17 @@ namespace graphics { class Camera { public: - Camera(int width, int height, const math::Vector *target); + Camera(int width, int height, const math::Vector > *target); ~Camera() { } public: void Resize(int w, int h) { halfWidth = w / 2; halfHeight = h / 2; } - void SetTarget(const math::Vector *t); + void SetTarget(const math::Vector > *t); math::Vector CalculateOffset() const; private: - const math::Vector *target; + const math::Vector > *target; int halfWidth; int halfHeight; diff --git a/src/graphics/ColorFade.cpp b/src/graphics/ColorFade.cpp index 45cd605..72bf409 100644 --- a/src/graphics/ColorFade.cpp +++ b/src/graphics/ColorFade.cpp @@ -94,7 +94,7 @@ void ColorFade::HandleEvents(const Input &input) { } -void ColorFade::UpdateWorld(float deltaT) { +void ColorFade::UpdateWorld(Uint32 deltaT) { if (interactive) { slave->UpdateWorld(deltaT); } diff --git a/src/graphics/ColorFade.h b/src/graphics/ColorFade.h index b3e98bd..3396ba3 100644 --- a/src/graphics/ColorFade.h +++ b/src/graphics/ColorFade.h @@ -21,7 +21,7 @@ public: public: virtual void HandleEvents(const app::Input &); - virtual void UpdateWorld(float deltaT); + virtual void UpdateWorld(Uint32 deltaT); virtual void Render(SDL_Surface *); private: diff --git a/src/main.cpp b/src/main.cpp index a890871..05f3d8a 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -17,6 +17,7 @@ #include "common/Script.h" #include "common/Spell.h" #include "common/Stats.h" +#include "math/Fixed.h" #include "math/Vector.h" #include "graphics/CharSelect.h" #include "graphics/ComplexAnimation.h" @@ -63,6 +64,7 @@ using common::GameConfig; using common::GameState; using common::Hero; using common::Spell; +using math::Fixed; using math::Vector; using graphics::Texture; using loader::Caster; @@ -87,7 +89,7 @@ int main(int argc, char **argv) { const int width = 512; const int height = 448; - const float walkSpeed = 128.0f; + const Fixed<8> walkSpeed = Fixed<8>(1, 8); bool battle(false); @@ -278,17 +280,17 @@ int main(int argc, char **argv) { gameState.heroes[3].SetEquipment(Hero::EQUIP_RING, caster.GetItem("rocketRingItem")); gameState.heroes[3].SetEquipment(Hero::EQUIP_JEWEL, caster.GetItem("krakenRockItem")); - gameState.heroes[0].MapEntity().Position() = Vector(64, 128); + gameState.heroes[0].MapEntity().Position() = Vector >(64, 128); - gameState.heroes[1].MapEntity().Position() = Vector(64, 128); + gameState.heroes[1].MapEntity().Position() = Vector >(64, 128); gameState.heroes[1].MapEntity().SetFlags(Entity::FLAG_NONBLOCKING); gameState.heroes[0].MapEntity().AddFollower(&gameState.heroes[1].MapEntity()); - gameState.heroes[2].MapEntity().Position() = Vector(64, 128); + gameState.heroes[2].MapEntity().Position() = Vector >(64, 128); gameState.heroes[2].MapEntity().SetFlags(Entity::FLAG_NONBLOCKING); gameState.heroes[1].MapEntity().AddFollower(&gameState.heroes[2].MapEntity()); - gameState.heroes[3].MapEntity().Position() = Vector(64, 128); + gameState.heroes[3].MapEntity().Position() = Vector >(64, 128); gameState.heroes[3].MapEntity().SetFlags(Entity::FLAG_NONBLOCKING); gameState.heroes[2].MapEntity().AddFollower(&gameState.heroes[3].MapEntity()); diff --git a/src/map/Entity.cpp b/src/map/Entity.cpp index fd2cc68..93530f1 100644 --- a/src/map/Entity.cpp +++ b/src/map/Entity.cpp @@ -11,6 +11,7 @@ using battle::Monster; using battle::PartyLayout; using graphics::Animation; using graphics::Sprite; +using math::Fixed; using math::Vector; using loader::FieldDescription; using loader::Interpreter; @@ -40,7 +41,7 @@ void Entity::SetOrientation(Orientation o) { } } -void Entity::SetSpeed(float s) { +void Entity::SetSpeed(Fixed<8> s) { speed = s; UpdateVelocity(); } @@ -98,22 +99,22 @@ void Entity::SetAnimation(const graphics::Animation *a) { void Entity::UpdateVelocity() { - if (speed == 0.0f) { - velocity = Vector(); + if (speed == 0) { + velocity = Vector >(); return; } switch (orientation) { case ORIENTATION_NORTH: - velocity = Vector(0.0f, -speed); + velocity = Vector >(0, -speed); break; case ORIENTATION_EAST: - velocity = Vector(speed, 0.0f); + velocity = Vector >(speed, 0); break; case ORIENTATION_SOUTH: - velocity = Vector(0.0f, speed); + velocity = Vector >(0, speed); break; case ORIENTATION_WEST: - velocity = Vector(-speed, 0.0f); + velocity = Vector >(-speed, 0); break; } } @@ -121,12 +122,12 @@ void Entity::UpdateVelocity() { bool Entity::TileLock(const math::Vector &tileSize) const { // TODO: change position to point to the top-left corner of a tile - Vector tilePosition(position); + Vector tilePosition(ToInt(position)); return (tilePosition.X() % tileSize.X() == 0) && (tilePosition.Y() % tileSize.Y() == 0); } -void Entity::Update(float deltaT) { +void Entity::Update(Uint32 deltaT) { position += velocity * deltaT; } @@ -134,9 +135,9 @@ void Entity::Update(float deltaT) { void Entity::Render(SDL_Surface *dest, const Vector &offset) const { // TODO: configurable sprite offsets if (runner.Running()) { - runner.Draw(dest, offset + position + spriteOffset); + runner.Draw(dest, offset + ToInt(position) + spriteOffset); } else { - sprite->Draw(dest, offset + position + spriteOffset, CanTurn() ? orientation : 0); + sprite->Draw(dest, offset + ToInt(position) + spriteOffset, CanTurn() ? orientation : 0); } } diff --git a/src/map/Entity.h b/src/map/Entity.h index be3197d..d68861c 100644 --- a/src/map/Entity.h +++ b/src/map/Entity.h @@ -3,6 +3,7 @@ #include "../battle/fwd.h" #include "../battle/Monster.h" +#include "../math/Fixed.h" #include "../math/Vector.h" #include "../graphics/fwd.h" #include "../graphics/Animation.h" @@ -38,12 +39,12 @@ public: public: /// Pixel resolved position of the entity's top left corner on the map. - math::Vector &Position() { return position; } - const math::Vector &Position() const { return position; } + math::Vector > &Position() { return position; } + const math::Vector > &Position() const { return position; } /// Velocity of the entity in pixels per second. - math::Vector &Velocity() { return velocity; } - const math::Vector &Velocity() const { return velocity; } + math::Vector > &Velocity() { return velocity; } + const math::Vector > &Velocity() const { return velocity; } /// Offset of the entity's sprite's to left corner relative to Position(). math::Vector &SpriteOffset() { return spriteOffset; } @@ -79,7 +80,7 @@ public: Orientation GetOrientation() const { return orientation; } /// Set the entity's speed in pixels per second. /// This speed is then combined with the orientation to form a velocity. - void SetSpeed(float); + void SetSpeed(math::Fixed<8>); /// Change to a natural, relaxed animation state (row offset 0). void SetHandsFree(); @@ -127,7 +128,7 @@ public: bool TileLock(const math::Vector &tileSize) const; /// Integrate this entity's physical properties over given time interval. - void Update(float deltaT); + void Update(Uint32 deltaT); void Render(SDL_Surface *, const math::Vector &offset) const; @@ -148,10 +149,10 @@ private: graphics::AnimationRunner runner; math::Vector spriteOffset; math::Vector tilePosition; - math::Vector position; - math::Vector velocity; + math::Vector > position; + math::Vector > velocity; Orientation orientation; - float speed; + math::Fixed<8> speed; int flags; }; diff --git a/src/map/MapState.cpp b/src/map/MapState.cpp index 121dfbc..51e9986 100644 --- a/src/map/MapState.cpp +++ b/src/map/MapState.cpp @@ -18,6 +18,7 @@ using app::Application; using app::Input; using battle::BattleState; using common::GameConfig; +using math::Fixed; using math::Vector; using graphics::ColorFade; using menu::PartyMenu; @@ -90,7 +91,7 @@ void MapState::HandleEvents(const Input &input) { } } -void MapState::UpdateWorld(float deltaT) { +void MapState::UpdateWorld(Uint32 deltaT) { if (controlled && controlled->TileLock(map->Tileset()->Size())) { OnTileLock(); } @@ -102,7 +103,7 @@ void MapState::UpdateWorld(float deltaT) { void MapState::OnTileLock() { if (moveTimer.Running() && !moveTimer.JustHit()) return; - Vector nowLock(controlled->Position()); + Vector nowLock(ToInt(controlled->Position())); bool event(false); if (nowLock != lastLock) { event = OnGridLock(); @@ -134,11 +135,11 @@ void MapState::OnTileLock() { controlled->SetHandsFree(); } } else { - controlled->SetSpeed(0.0f); + controlled->SetSpeed(0); StopFollowers(*controlled); if (!moveTimer.Running()) { int tileSize((controlled->GetOrientation() % 2) ? map->Tileset()->Width() : map->Tileset()->Height()); - moveTimer = PhysicsTimers().StartInterval(tileSize/walkingSpeed); + moveTimer = PhysicsTimers().StartInterval(tileSize/walkingSpeed.Int()); } pushed = 0; } @@ -147,12 +148,12 @@ void MapState::OnTileLock() { } } } else { - controlled->SetSpeed(0.0f); + controlled->SetSpeed(0); StopFollowers(*controlled); controlled->StopAnimation(); moveTimer.Clear(); if (pushed) { - pushed->SetSpeed(0.0f); + pushed->SetSpeed(0); pushed = 0; } } @@ -162,10 +163,10 @@ void MapState::OnTileLock() { bool MapState::CheckBlocking() { if (pushed) { - pushed->SetSpeed(0.0f); + pushed->SetSpeed(0); pushed = 0; } - const Tile *tile(map->TileAt(controlled->Position())); + const Tile *tile(map->TileAt(ToInt(controlled->Position()))); Vector direction; switch (nextDirection) { case Entity::ORIENTATION_NORTH: @@ -199,11 +200,11 @@ bool MapState::CheckBlocking() { default: return false; } - Vector nextTilePosition(direction + controlled->Position()); + Vector nextTilePosition(direction + ToInt(controlled->Position())); Vector nextTileCoords(map->TileCoordinates(nextTilePosition)); for (std::vector::const_iterator i(entities.begin()), end(entities.end()); i != end; ++i) { const Entity &e(**i); - if (map->TileCoordinates(e.Position()) != nextTileCoords) continue; + if (map->TileCoordinates(ToInt(e.Position())) != nextTileCoords) continue; if (!e.Blocking()) continue; if (!pushing || !e.Pushable()) return true; if (CheckBlocking(nextTilePosition, Entity::Orientation(nextDirection))) return true; @@ -250,7 +251,7 @@ bool MapState::CheckBlocking(const Vector &position, Entity::Orientation di Vector nextTileCoords(map->TileCoordinates(directionVector + position)); for (std::vector::const_iterator i(entities.begin()), end(entities.end()); i != end; ++i) { const Entity &e(**i); - if (map->TileCoordinates(e.Position()) == nextTileCoords && e.Blocking()) { + if (map->TileCoordinates(ToInt(e.Position())) == nextTileCoords && e.Blocking()) { return true; } } @@ -278,7 +279,7 @@ void MapState::LockEntities() { } bool MapState::CheckMonster() { - Vector coords(map->TileCoordinates(controlled->Position())); + Vector coords(map->TileCoordinates(ToInt(controlled->Position()))); Vector neighbor[4]; neighbor[0] = Vector(coords.X(), coords.Y() - 1); // N neighbor[1] = Vector(coords.X() + 1, coords.Y()); // E @@ -287,10 +288,10 @@ bool MapState::CheckMonster() { for (int i(0); i < 4; ++i) { for (std::vector::iterator e(entities.begin()), end(entities.end()); e != end; ++e) { - if ((*e)->Hostile() && map->TileCoordinates((*e)->Position()) == neighbor[i]) { + if ((*e)->Hostile() && map->TileCoordinates(ToInt((*e)->Position())) == neighbor[i]) { // TODO: check for turn advantage, see #26 // TODO: other transition - BattleState *battleState(new BattleState(game, map->BattleBackgroundAt((*e)->Position()), (*e)->PartyLayout())); + BattleState *battleState(new BattleState(game, map->BattleBackgroundAt(ToInt((*e)->Position())), (*e)->PartyLayout())); for (int i(0); i < 4; ++i) { if (game->state->party[i]) { battleState->AddHero(*game->state->party[i]); @@ -321,7 +322,7 @@ bool MapState::CheckMonster() { } bool MapState::CheckLockTrigger() { - Trigger *trigger(map->TriggerAt(Vector(controlled->Position()))); + Trigger *trigger(map->TriggerAt(ToInt(controlled->Position()))); if (!trigger || trigger->GetType() != Trigger::TYPE_CONTACT) return false; RunTrigger(*trigger); return true; @@ -340,7 +341,7 @@ void MapState::OnMove(bool realMove) { } bool MapState::CheckMoveTrigger() { - Trigger *trigger(map->TriggerAt(Vector(controlled->Position()))); + Trigger *trigger(map->TriggerAt(ToInt(controlled->Position()))); if (!trigger || int(trigger->GetType()) != nextDirection) return false; RunTrigger(*trigger); return true; @@ -357,8 +358,8 @@ void MapState::UpdateFollower(Entity &e) { Entity &f(*e.Follower()); UpdateFollower(f); - Vector coords(map->TileCoordinates(e.Position())); - Vector fCoords(map->TileCoordinates(f.Position())); + Vector coords(map->TileCoordinates(ToInt(e.Position()))); + Vector fCoords(map->TileCoordinates(ToInt(f.Position()))); Vector direction(coords - fCoords); if (direction.Y() < 0) { @@ -378,14 +379,14 @@ void MapState::UpdateFollower(Entity &e) { f.SetSpeed(walkingSpeed); f.StartAnimation(*this); } else { - f.SetSpeed(0.0f); + f.SetSpeed(0); f.StopAnimation(); } } void MapState::StopFollowers(Entity &e) { for (Entity *f(e.Follower()); f; f = f->Follower()) { - f->SetSpeed(0.0f); + f->SetSpeed(0); f->StopAnimation(); } } diff --git a/src/map/MapState.h b/src/map/MapState.h index 5bbd6f8..89d235d 100644 --- a/src/map/MapState.h +++ b/src/map/MapState.h @@ -7,6 +7,7 @@ #include "../common/fwd.h" #include "../common/ScriptHost.h" #include "../common/ScriptRunner.h" +#include "../math/Fixed.h" #include "../math/Vector.h" #include "../graphics/Camera.h" @@ -25,14 +26,14 @@ public: public: virtual void HandleEvents(const app::Input &); - virtual void UpdateWorld(float deltaT); + virtual void UpdateWorld(Uint32 deltaT); virtual void Render(SDL_Surface *); public: void AddEntity(Entity *e) { entities.push_back(e); } void ControlEntity(Entity *e) { controlled = e; camera.SetTarget(&e->Position()); } - void SetWalkingSpeed(float s) { walkingSpeed = s; } + void SetWalkingSpeed(math::Fixed<8> s) { walkingSpeed = s; } void Transition(Map *, const math::Vector &coordinates); @@ -80,11 +81,11 @@ private: Entity *controlled; Entity *pushed; common::ScriptRunner runner; - app::Timer moveTimer; + app::Timer moveTimer; math::Vector lastLock; graphics::Camera camera; std::vector entities; - float walkingSpeed; + math::Fixed<8> walkingSpeed; int nextDirection; bool afterLock; bool skipLock; diff --git a/src/map/TransitionState.cpp b/src/map/TransitionState.cpp index 7ea3588..cb26df5 100644 --- a/src/map/TransitionState.cpp +++ b/src/map/TransitionState.cpp @@ -45,7 +45,7 @@ void TransitionState::HandleEvents(const Input &input) { } -void TransitionState::UpdateWorld(float deltaT) { +void TransitionState::UpdateWorld(Uint32 deltaT) { } diff --git a/src/map/TransitionState.h b/src/map/TransitionState.h index 9f2cd19..293cdb2 100644 --- a/src/map/TransitionState.h +++ b/src/map/TransitionState.h @@ -16,7 +16,7 @@ public: public: virtual void HandleEvents(const app::Input &); - virtual void UpdateWorld(float deltaT); + virtual void UpdateWorld(Uint32 deltaT); virtual void Render(SDL_Surface *); private: diff --git a/src/menu/CapsuleChangeMenu.cpp b/src/menu/CapsuleChangeMenu.cpp index de94929..c19f0f5 100644 --- a/src/menu/CapsuleChangeMenu.cpp +++ b/src/menu/CapsuleChangeMenu.cpp @@ -105,7 +105,7 @@ void CapsuleChangeMenu::PreviousClass() { } -void CapsuleChangeMenu::UpdateWorld(float deltaT) { +void CapsuleChangeMenu::UpdateWorld(Uint32 deltaT) { } diff --git a/src/menu/CapsuleChangeMenu.h b/src/menu/CapsuleChangeMenu.h index 354cb61..2667595 100644 --- a/src/menu/CapsuleChangeMenu.h +++ b/src/menu/CapsuleChangeMenu.h @@ -18,7 +18,7 @@ public: public: virtual void HandleEvents(const app::Input &); - virtual void UpdateWorld(float deltaT); + virtual void UpdateWorld(Uint32 deltaT); virtual void Render(SDL_Surface *); void RenderClasses(SDL_Surface *, const math::Vector &) const; diff --git a/src/menu/CapsuleFeedMenu.cpp b/src/menu/CapsuleFeedMenu.cpp index 43324c7..085c73d 100644 --- a/src/menu/CapsuleFeedMenu.cpp +++ b/src/menu/CapsuleFeedMenu.cpp @@ -149,7 +149,7 @@ void CapsuleFeedMenu::FeedSelected() { } -void CapsuleFeedMenu::UpdateWorld(float deltaT) { +void CapsuleFeedMenu::UpdateWorld(Uint32 deltaT) { } diff --git a/src/menu/CapsuleFeedMenu.h b/src/menu/CapsuleFeedMenu.h index 3ea8c1a..5d8fbe6 100644 --- a/src/menu/CapsuleFeedMenu.h +++ b/src/menu/CapsuleFeedMenu.h @@ -19,7 +19,7 @@ public: public: virtual void HandleEvents(const app::Input &); - virtual void UpdateWorld(float deltaT); + virtual void UpdateWorld(Uint32 deltaT); virtual void Render(SDL_Surface *); public: diff --git a/src/menu/CapsuleMenu.cpp b/src/menu/CapsuleMenu.cpp index 67afd57..e50215c 100644 --- a/src/menu/CapsuleMenu.cpp +++ b/src/menu/CapsuleMenu.cpp @@ -83,7 +83,7 @@ void CapsuleMenu::HandleEvents(const Input &input) { } } -void CapsuleMenu::UpdateWorld(float deltaT) { +void CapsuleMenu::UpdateWorld(Uint32 deltaT) { } diff --git a/src/menu/CapsuleMenu.h b/src/menu/CapsuleMenu.h index 8f80637..0ddb2e8 100644 --- a/src/menu/CapsuleMenu.h +++ b/src/menu/CapsuleMenu.h @@ -17,7 +17,7 @@ public: public: virtual void HandleEvents(const app::Input &); - virtual void UpdateWorld(float deltaT); + virtual void UpdateWorld(Uint32 deltaT); virtual void Render(SDL_Surface *); void RenderBackground(SDL_Surface *screen) const; diff --git a/src/menu/CapsuleNameMenu.cpp b/src/menu/CapsuleNameMenu.cpp index 2bdad28..0dc21cc 100644 --- a/src/menu/CapsuleNameMenu.cpp +++ b/src/menu/CapsuleNameMenu.cpp @@ -129,7 +129,7 @@ void CapsuleNameMenu::StoreName() { } } -void CapsuleNameMenu::UpdateWorld(float deltaT) { +void CapsuleNameMenu::UpdateWorld(Uint32 deltaT) { } diff --git a/src/menu/CapsuleNameMenu.h b/src/menu/CapsuleNameMenu.h index f85d11c..4630c0a 100644 --- a/src/menu/CapsuleNameMenu.h +++ b/src/menu/CapsuleNameMenu.h @@ -19,7 +19,7 @@ public: public: virtual void HandleEvents(const app::Input &); - virtual void UpdateWorld(float deltaT); + virtual void UpdateWorld(Uint32 deltaT); virtual void Render(SDL_Surface *); public: diff --git a/src/menu/ChangeHero.cpp b/src/menu/ChangeHero.cpp index 0c1ed4a..69f79c4 100644 --- a/src/menu/ChangeHero.cpp +++ b/src/menu/ChangeHero.cpp @@ -68,7 +68,7 @@ void ChangeHero::HandleEvents(const Input &input) { } -void ChangeHero::UpdateWorld(float deltaT) { +void ChangeHero::UpdateWorld(Uint32 deltaT) { } diff --git a/src/menu/ChangeHero.h b/src/menu/ChangeHero.h index ca5f64b..c046af3 100644 --- a/src/menu/ChangeHero.h +++ b/src/menu/ChangeHero.h @@ -17,7 +17,7 @@ public: public: virtual void HandleEvents(const app::Input &); - virtual void UpdateWorld(float deltaT); + virtual void UpdateWorld(Uint32 deltaT); virtual void Render(SDL_Surface *); public: diff --git a/src/menu/ConfigMenu.cpp b/src/menu/ConfigMenu.cpp index e96c76b..8445e82 100644 --- a/src/menu/ConfigMenu.cpp +++ b/src/menu/ConfigMenu.cpp @@ -98,7 +98,7 @@ void ConfigMenu::HandleEvents(const Input &input) { } } -void ConfigMenu::UpdateWorld(float deltaT) { +void ConfigMenu::UpdateWorld(Uint32 deltaT) { } diff --git a/src/menu/ConfigMenu.h b/src/menu/ConfigMenu.h index f5e31c1..cdee9fc 100644 --- a/src/menu/ConfigMenu.h +++ b/src/menu/ConfigMenu.h @@ -16,7 +16,7 @@ public: public: virtual void HandleEvents(const app::Input &); - virtual void UpdateWorld(float deltaT); + virtual void UpdateWorld(Uint32 deltaT); virtual void Render(SDL_Surface *); public: diff --git a/src/menu/EquipMenu.cpp b/src/menu/EquipMenu.cpp index 494c25a..8e50966 100644 --- a/src/menu/EquipMenu.cpp +++ b/src/menu/EquipMenu.cpp @@ -157,7 +157,7 @@ void EquipMenu::HandleEvents(const Input &input) { } } -void EquipMenu::UpdateWorld(float deltaT) { +void EquipMenu::UpdateWorld(Uint32 deltaT) { } diff --git a/src/menu/EquipMenu.h b/src/menu/EquipMenu.h index ffa7a83..992afd7 100644 --- a/src/menu/EquipMenu.h +++ b/src/menu/EquipMenu.h @@ -17,7 +17,7 @@ public: public: virtual void HandleEvents(const app::Input &); - virtual void UpdateWorld(float deltaT); + virtual void UpdateWorld(Uint32 deltaT); virtual void Render(SDL_Surface *); public: diff --git a/src/menu/InventoryMenu.cpp b/src/menu/InventoryMenu.cpp index 95ca746..9a4bf13 100644 --- a/src/menu/InventoryMenu.cpp +++ b/src/menu/InventoryMenu.cpp @@ -137,7 +137,7 @@ void InventoryMenu::HandleEvents(const Input &input) { } } -void InventoryMenu::UpdateWorld(float deltaT) { +void InventoryMenu::UpdateWorld(Uint32 deltaT) { } diff --git a/src/menu/InventoryMenu.h b/src/menu/InventoryMenu.h index 11acf46..780bacb 100644 --- a/src/menu/InventoryMenu.h +++ b/src/menu/InventoryMenu.h @@ -17,7 +17,7 @@ public: public: virtual void HandleEvents(const app::Input &); - virtual void UpdateWorld(float deltaT); + virtual void UpdateWorld(Uint32 deltaT); virtual void Render(SDL_Surface *); int Width() const; diff --git a/src/menu/PartyMenu.cpp b/src/menu/PartyMenu.cpp index 577772e..46e271b 100644 --- a/src/menu/PartyMenu.cpp +++ b/src/menu/PartyMenu.cpp @@ -126,7 +126,7 @@ void PartyMenu::HandleEvents(const Input &input) { } } -void PartyMenu::UpdateWorld(float deltaT) { +void PartyMenu::UpdateWorld(Uint32 deltaT) { } diff --git a/src/menu/PartyMenu.h b/src/menu/PartyMenu.h index a009c33..934369e 100644 --- a/src/menu/PartyMenu.h +++ b/src/menu/PartyMenu.h @@ -19,7 +19,7 @@ public: public: virtual void HandleEvents(const app::Input &); - virtual void UpdateWorld(float deltaT); + virtual void UpdateWorld(Uint32 deltaT); virtual void Render(SDL_Surface *); public: diff --git a/src/menu/ScenarioMenu.cpp b/src/menu/ScenarioMenu.cpp index a86f9a9..92c5101 100644 --- a/src/menu/ScenarioMenu.cpp +++ b/src/menu/ScenarioMenu.cpp @@ -75,7 +75,7 @@ void ScenarioMenu::HandleEvents(const Input &input) { } } -void ScenarioMenu::UpdateWorld(float deltaT) { +void ScenarioMenu::UpdateWorld(Uint32 deltaT) { } diff --git a/src/menu/ScenarioMenu.h b/src/menu/ScenarioMenu.h index 3e99ef0..886046c 100644 --- a/src/menu/ScenarioMenu.h +++ b/src/menu/ScenarioMenu.h @@ -17,7 +17,7 @@ public: public: virtual void HandleEvents(const app::Input &); - virtual void UpdateWorld(float deltaT); + virtual void UpdateWorld(Uint32 deltaT); virtual void Render(SDL_Surface *); int Width() const; diff --git a/src/menu/SelectHero.cpp b/src/menu/SelectHero.cpp index e573d32..ffc21a3 100644 --- a/src/menu/SelectHero.cpp +++ b/src/menu/SelectHero.cpp @@ -105,7 +105,7 @@ const Resources &SelectHero::Res() const { } -void SelectHero::UpdateWorld(float deltaT) { +void SelectHero::UpdateWorld(Uint32 deltaT) { } diff --git a/src/menu/SelectHero.h b/src/menu/SelectHero.h index 7789190..8f7f9f4 100644 --- a/src/menu/SelectHero.h +++ b/src/menu/SelectHero.h @@ -21,7 +21,7 @@ public: public: virtual void HandleEvents(const app::Input &); - virtual void UpdateWorld(float deltaT); + virtual void UpdateWorld(Uint32 deltaT); virtual void Render(SDL_Surface *); private: diff --git a/src/menu/SpellMenu.cpp b/src/menu/SpellMenu.cpp index af743cc..09ca56c 100644 --- a/src/menu/SpellMenu.cpp +++ b/src/menu/SpellMenu.cpp @@ -145,7 +145,7 @@ void SpellMenu::HandleEvents(const Input &input) { } } -void SpellMenu::UpdateWorld(float deltaT) { +void SpellMenu::UpdateWorld(Uint32 deltaT) { } diff --git a/src/menu/SpellMenu.h b/src/menu/SpellMenu.h index 42dbfbb..4bfcb01 100644 --- a/src/menu/SpellMenu.h +++ b/src/menu/SpellMenu.h @@ -17,7 +17,7 @@ public: public: virtual void HandleEvents(const app::Input &); - virtual void UpdateWorld(float deltaT); + virtual void UpdateWorld(Uint32 deltaT); virtual void Render(SDL_Surface *); public: diff --git a/src/menu/StatusMenu.cpp b/src/menu/StatusMenu.cpp index 09c9405..49695dc 100644 --- a/src/menu/StatusMenu.cpp +++ b/src/menu/StatusMenu.cpp @@ -81,7 +81,7 @@ void StatusMenu::HandleEvents(const Input &input) { } } -void StatusMenu::UpdateWorld(float deltaT) { +void StatusMenu::UpdateWorld(Uint32 deltaT) { } diff --git a/src/menu/StatusMenu.h b/src/menu/StatusMenu.h index eaf1017..6ef8189 100644 --- a/src/menu/StatusMenu.h +++ b/src/menu/StatusMenu.h @@ -17,7 +17,7 @@ public: public: virtual void HandleEvents(const app::Input &); - virtual void UpdateWorld(float deltaT); + virtual void UpdateWorld(Uint32 deltaT); virtual void Render(SDL_Surface *); public: -- 2.39.2