migrating save files
This commit is contained in:
@@ -31,23 +31,17 @@ class Team;
|
||||
|
||||
class TeamCastle : public utils::shape::Rectangle {
|
||||
private:
|
||||
const Team* m_Team;
|
||||
float m_Life;
|
||||
public:
|
||||
static constexpr int CastleMaxLife = 1000;
|
||||
|
||||
TeamCastle(const Team* team) : m_Team(team), m_Life(CastleMaxLife) {
|
||||
TeamCastle() : m_Life(CastleMaxLife) {
|
||||
SetWidth(5);
|
||||
SetHeight(5);
|
||||
}
|
||||
|
||||
TeamCastle() : TeamCastle(nullptr) {}
|
||||
|
||||
float GetLife() const { return m_Life; }
|
||||
|
||||
const Team* GetTeam() const { return m_Team; }
|
||||
void SetTeam(const Team* team) { m_Team = team; }
|
||||
|
||||
void SetLife(float life) { m_Life = life; }
|
||||
void Damage(float damage) { m_Life = std::max(0.0f, m_Life - damage); }
|
||||
|
||||
|
||||
@@ -14,7 +14,7 @@ class World {
|
||||
std::vector<Color> m_DecorationPalette;
|
||||
Color m_Background;
|
||||
|
||||
std::unordered_map<ChunkCoord, ChunkPtr> m_Chunks;
|
||||
ChunkList m_Chunks;
|
||||
|
||||
SpawnColorPalette m_SpawnColorPalette;
|
||||
|
||||
@@ -70,7 +70,7 @@ class World {
|
||||
|
||||
TowerPtr GetTower(const Vec2f& position) const; // returns null if no tower is here
|
||||
|
||||
const std::unordered_map<ChunkCoord, ChunkPtr>& GetChunks() const {
|
||||
const ChunkList& GetChunks() const {
|
||||
return m_Chunks;
|
||||
}
|
||||
|
||||
|
||||
@@ -7,14 +7,8 @@
|
||||
|
||||
namespace td {
|
||||
namespace game {
|
||||
struct ChunkCoord {
|
||||
std::int16_t x, y;
|
||||
|
||||
friend bool operator==(const td::game::ChunkCoord& first, const td::game::ChunkCoord& other) {
|
||||
return first.x == other.x && first.y == other.y;
|
||||
}
|
||||
};
|
||||
|
||||
using ChunkCoord = Vec2<std::int16_t>;
|
||||
|
||||
class Game;
|
||||
|
||||
@@ -80,15 +74,17 @@ struct Chunk {
|
||||
typedef std::array<std::uint16_t, ChunkSize> ChunkData;
|
||||
|
||||
// stores index of tile palette
|
||||
ChunkData tiles{0};
|
||||
ChunkPalette palette;
|
||||
ChunkData m_Tiles{0};
|
||||
ChunkPalette m_Palette;
|
||||
|
||||
TileIndex GetTileIndex(std::uint16_t tileNumber) const {
|
||||
TileIndex chunkPaletteIndex = tiles.at(tileNumber);
|
||||
TileIndex chunkPaletteIndex = m_Tiles.at(tileNumber);
|
||||
if (chunkPaletteIndex == 0) // index 0 means empty tile index 1 = first tile
|
||||
return 0;
|
||||
return palette.at(chunkPaletteIndex);
|
||||
return m_Palette.at(chunkPaletteIndex);
|
||||
}
|
||||
|
||||
// TODO: keep data packed
|
||||
};
|
||||
|
||||
typedef std::shared_ptr<Chunk> ChunkPtr;
|
||||
@@ -103,6 +99,8 @@ typedef std::array<Color, 2> SpawnColorPalette;
|
||||
|
||||
typedef std::vector<TowerPtr> TowerList;
|
||||
|
||||
using ChunkList = std::unordered_map<ChunkCoord, ChunkPtr>;
|
||||
|
||||
sp::DataBuffer& operator>>(sp::DataBuffer& buffer, TilePtr& tile);
|
||||
|
||||
|
||||
|
||||
@@ -92,7 +92,7 @@ struct WorldHeader {
|
||||
};
|
||||
|
||||
struct WorldData {
|
||||
std::unordered_map<game::ChunkCoord, game::ChunkPtr> m_Chunks;
|
||||
game::ChunkList m_Chunks;
|
||||
};
|
||||
|
||||
} // namespace pdata
|
||||
|
||||
@@ -6,10 +6,60 @@ namespace sp {
|
||||
|
||||
class DataBuffer;
|
||||
|
||||
// temp
|
||||
template <>
|
||||
void ReadMessage(DataBuffer& a_Buffer, td::protocol::pdata::WorldHeader& a_Header);
|
||||
void ReadMessage(DataBuffer& a_Buffer, td::protocol::pdata::PredictCommand& a_Header);
|
||||
|
||||
template <>
|
||||
void ReadMessage(DataBuffer& a_Buffer, td::protocol::pdata::WorldData& a_WorldData);
|
||||
DataBuffer WriteMessage(const td::protocol::pdata::PredictCommand& a_Header);
|
||||
|
||||
} // namespace sp
|
||||
} // namespace sp
|
||||
|
||||
|
||||
namespace td {
|
||||
|
||||
template <typename T>
|
||||
sp::DataBuffer& operator<<(sp::DataBuffer& a_Buffer, const Vec2<T>& a_Vec) {
|
||||
return a_Buffer << a_Vec.x << a_Vec.y;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
sp::DataBuffer& operator>>(sp::DataBuffer& a_Buffer, Vec2<T>& a_Vec) {
|
||||
return a_Buffer >> a_Vec.x >> a_Vec.y;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
sp::DataBuffer& operator<<(sp::DataBuffer& a_Buffer, const Vec3<T>& a_Vec) {
|
||||
return a_Buffer << a_Vec.x << a_Vec.y << a_Vec.z;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
sp::DataBuffer& operator>>(sp::DataBuffer& a_Buffer, Vec3<T>& a_Vec) {
|
||||
return a_Buffer >> a_Vec.x >> a_Vec.y >> a_Vec.z;
|
||||
}
|
||||
|
||||
|
||||
template <typename T>
|
||||
sp::DataBuffer& operator<<(sp::DataBuffer& a_Buffer, const Vec4<T>& a_Vec) {
|
||||
return a_Buffer << a_Vec.x << a_Vec.y << a_Vec.z << a_Vec.w;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
sp::DataBuffer& operator>>(sp::DataBuffer& a_Buffer, Vec4<T>& a_Vec) {
|
||||
return a_Buffer >> a_Vec.x >> a_Vec.y >> a_Vec.z >> a_Vec.w;
|
||||
}
|
||||
|
||||
|
||||
namespace game {
|
||||
|
||||
sp::DataBuffer& operator<<(sp::DataBuffer& a_Buffer, const TeamCastle& a_Castle);
|
||||
sp::DataBuffer& operator>>(sp::DataBuffer& a_Buffer, TeamCastle& a_Castle);
|
||||
|
||||
sp::DataBuffer& operator<<(sp::DataBuffer& a_Buffer, const ChunkPtr& a_Chunk);
|
||||
sp::DataBuffer& operator>>(sp::DataBuffer& a_Buffer, ChunkPtr& a_Chunk);
|
||||
|
||||
sp::DataBuffer& operator<<(sp::DataBuffer& buffer, const TilePtr& tile);
|
||||
sp::DataBuffer& operator>>(sp::DataBuffer& buffer, TilePtr& tile);
|
||||
|
||||
} // namespace game
|
||||
} // namespace td
|
||||
|
||||
Reference in New Issue
Block a user