too many things
This commit is contained in:
@@ -1,37 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
#include <optional>
|
||||
#include <td/protocol/command/Commands.h>
|
||||
#include <td/protocol/packet/Packets.h>
|
||||
|
||||
namespace td {
|
||||
namespace game {
|
||||
|
||||
class GameHistory {
|
||||
private:
|
||||
using HistorySizeType = std::uint16_t;
|
||||
|
||||
std::vector<std::optional<protocol::LockStep>> m_History;
|
||||
|
||||
HistorySizeType m_Cursor;
|
||||
|
||||
public:
|
||||
GameHistory();
|
||||
|
||||
void SetLockStep(HistorySizeType a_Index, protocol::LockStep&& a_LockStep);
|
||||
|
||||
const protocol::LockStep& GetLockStep(HistorySizeType a_Index) const;
|
||||
|
||||
bool HasLockStep(HistorySizeType a_Index) const;
|
||||
|
||||
const protocol::LockStep& GetNextStep();
|
||||
|
||||
bool HasNextStep() const;
|
||||
|
||||
void FromPacket(td::protocol::pdata::LockSteps&& a_Steps);
|
||||
|
||||
td::protocol::packets::LockStepsPacket ToPacket(HistorySizeType a_StartIndex);
|
||||
};
|
||||
|
||||
} // namespace game
|
||||
} // namespace td
|
||||
@@ -10,8 +10,11 @@
|
||||
#include <vector>
|
||||
|
||||
namespace td {
|
||||
using Vec2fp = Vec2<FpFloat>;
|
||||
|
||||
namespace game {
|
||||
|
||||
|
||||
struct WalkableTile;
|
||||
|
||||
enum class EffectType : std::uint8_t {
|
||||
@@ -62,11 +65,12 @@ const MobStats* GetMobStats(MobType type, std::uint8_t level);
|
||||
const TowerImmunities& GetMobTowerImmunities(MobType type, std::uint8_t level);
|
||||
const EffectImmunities& GetMobEffectImmunities(MobType type, std::uint8_t level);
|
||||
|
||||
class Mob : public utils::shape::Rectangle {
|
||||
class Mob {
|
||||
protected:
|
||||
float m_Health;
|
||||
|
||||
private:
|
||||
Vec2fp m_Position;
|
||||
MobID m_ID;
|
||||
PlayerID m_Sender;
|
||||
MobLevel m_Level;
|
||||
@@ -89,12 +93,14 @@ class Mob : public utils::shape::Rectangle {
|
||||
|
||||
virtual MobType GetType() const = 0;
|
||||
|
||||
virtual void Tick(std::uint64_t delta, World* world) {}
|
||||
|
||||
virtual bool OnDeath(World* world) {
|
||||
return true;
|
||||
}
|
||||
|
||||
Vec2fp& GetPosition() {
|
||||
return m_Position;
|
||||
}
|
||||
|
||||
MobID GetMobID() const {
|
||||
return m_ID;
|
||||
}
|
||||
@@ -156,15 +162,15 @@ class Mob : public utils::shape::Rectangle {
|
||||
return m_HitCooldown > 0;
|
||||
}
|
||||
|
||||
// returns a float between 0 and 1 excluded
|
||||
float GetTileX() {
|
||||
return GetCenterX() - static_cast<float>(static_cast<std::int32_t>(GetCenterX()));
|
||||
}
|
||||
// // returns a float between 0 and 1 excluded
|
||||
// float GetTileX() {
|
||||
// return GetCenterX() - static_cast<float>(static_cast<std::int32_t>(GetCenterX()));
|
||||
// }
|
||||
|
||||
// returns a float between 0 and 1 excluded
|
||||
float GetTileY() {
|
||||
return GetCenterY() - static_cast<float>(static_cast<std::int32_t>(GetCenterY()));
|
||||
}
|
||||
// // returns a float between 0 and 1 excluded
|
||||
// float GetTileY() {
|
||||
// return GetCenterY() - static_cast<float>(static_cast<std::int32_t>(GetCenterY()));
|
||||
// }
|
||||
|
||||
Direction GetDirection() const {
|
||||
return m_Direction;
|
||||
@@ -176,7 +182,7 @@ class Mob : public utils::shape::Rectangle {
|
||||
protected:
|
||||
void InitMob() {
|
||||
m_Health = static_cast<float>(GetStats()->m_MaxLife);
|
||||
SetSize(GetStats()->m_Size.x, GetStats()->m_Size.y);
|
||||
// SetSize(GetStats()->m_Size.x, GetStats()->m_Size.y);
|
||||
}
|
||||
|
||||
private:
|
||||
@@ -201,9 +207,7 @@ class ConcreteMob : public Mob {
|
||||
|
||||
virtual ~ConcreteMob() {}
|
||||
|
||||
virtual void Tick(std::uint64_t delta, World* world) {}
|
||||
|
||||
virtual constexpr MobType GetType() const {
|
||||
virtual constexpr MobType GetType() const override {
|
||||
return MT;
|
||||
}
|
||||
};
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
#pragma once
|
||||
|
||||
#include <td/simulation/WorldTicker.h>
|
||||
#include <td/game/WorldTypes.h>
|
||||
#include <td/protocol/packet/Packets.h>
|
||||
|
||||
@@ -19,11 +20,10 @@ class World {
|
||||
|
||||
TilePalette m_TilePalette;
|
||||
|
||||
MobList m_Mobs;
|
||||
sim::WorldSnapshot m_CurrentState;
|
||||
|
||||
TowerList m_Towers;
|
||||
|
||||
TeamList m_Teams;
|
||||
private:
|
||||
sim::WorldTicker m_Ticker;
|
||||
|
||||
public:
|
||||
World();
|
||||
@@ -34,8 +34,6 @@ class World {
|
||||
bool LoadMapFromFile(const std::string& fileName);
|
||||
bool SaveMap(const std::string& fileName) const;
|
||||
|
||||
void Tick(std::uint64_t delta);
|
||||
|
||||
void SpawnMobAt(MobID id, MobType type, std::uint8_t level, PlayerID sender, float x, float y, Direction dir);
|
||||
|
||||
TowerPtr PlaceTowerAt(TowerID id, TowerType type, std::int32_t x, std::int32_t y, PlayerID builder);
|
||||
@@ -83,47 +81,49 @@ class World {
|
||||
}
|
||||
|
||||
const MobList& GetMobList() const {
|
||||
return m_Mobs;
|
||||
return m_CurrentState.m_Mobs;
|
||||
}
|
||||
MobList& GetMobList() {
|
||||
return m_Mobs;
|
||||
return m_CurrentState.m_Mobs;
|
||||
}
|
||||
|
||||
const Color* GetTileColor(TilePtr tile) const;
|
||||
|
||||
Team& GetRedTeam() {
|
||||
return m_Teams[static_cast<std::uint8_t>(TeamColor::Red)];
|
||||
return m_CurrentState.m_Teams[static_cast<std::uint8_t>(TeamColor::Red)];
|
||||
}
|
||||
const Team& GetRedTeam() const {
|
||||
return m_Teams[static_cast<std::uint8_t>(TeamColor::Red)];
|
||||
return m_CurrentState.m_Teams[static_cast<std::uint8_t>(TeamColor::Red)];
|
||||
}
|
||||
|
||||
Team& GetBlueTeam() {
|
||||
return m_Teams[static_cast<std::uint8_t>(TeamColor::Blue)];
|
||||
return m_CurrentState.m_Teams[static_cast<std::uint8_t>(TeamColor::Blue)];
|
||||
}
|
||||
const Team& GetBlueTeam() const {
|
||||
return m_Teams[static_cast<std::uint8_t>(TeamColor::Red)];
|
||||
return m_CurrentState.m_Teams[static_cast<std::uint8_t>(TeamColor::Red)];
|
||||
}
|
||||
|
||||
Team& GetTeam(TeamColor team) {
|
||||
return m_Teams[static_cast<std::uint8_t>(team)];
|
||||
return m_CurrentState.m_Teams[static_cast<std::uint8_t>(team)];
|
||||
}
|
||||
const Team& GetTeam(TeamColor team) const {
|
||||
return m_Teams[static_cast<std::uint8_t>(team)];
|
||||
return m_CurrentState.m_Teams[static_cast<std::uint8_t>(team)];
|
||||
}
|
||||
|
||||
const TeamList& GetTeams() const {
|
||||
return m_Teams;
|
||||
return m_CurrentState.m_Teams;
|
||||
}
|
||||
|
||||
const TowerList& GetTowers() const {
|
||||
return m_Towers;
|
||||
return m_CurrentState.m_Towers;
|
||||
}
|
||||
|
||||
TowerPtr GetTowerById(TowerID tower);
|
||||
|
||||
const Player* GetPlayerById(PlayerID id) const;
|
||||
|
||||
void Tick(const protocol::LockStep& a_LockStep, FpFloat a_Delta);
|
||||
|
||||
private:
|
||||
void TickMobs(std::uint64_t delta);
|
||||
void CleanDeadMobs();
|
||||
|
||||
@@ -102,6 +102,8 @@ typedef std::array<Color, 2> SpawnColorPalette;
|
||||
|
||||
typedef std::vector<TowerPtr> TowerList;
|
||||
|
||||
sp::DataBuffer& operator>>(sp::DataBuffer& buffer, TilePtr& tile);
|
||||
|
||||
|
||||
} // namespace game
|
||||
|
||||
|
||||
Reference in New Issue
Block a user