Compare commits
4 Commits
871caf9056
...
8ad5dad046
| Author | SHA1 | Date | |
|---|---|---|---|
| 8ad5dad046 | |||
| ec1344bc37 | |||
| d0dc4408ba | |||
| cc8a87368e |
@@ -6,6 +6,7 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
|
#include <array>
|
||||||
#include <cassert>
|
#include <cassert>
|
||||||
#include <cstdint>
|
#include <cstdint>
|
||||||
#include <cstring>
|
#include <cstring>
|
||||||
|
|||||||
@@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
#include <optional>
|
#include <optional>
|
||||||
#include <td/protocol/command/Commands.h>
|
#include <td/protocol/command/Commands.h>
|
||||||
|
#include <td/protocol/packet/Packets.h>
|
||||||
|
|
||||||
namespace td {
|
namespace td {
|
||||||
namespace game {
|
namespace game {
|
||||||
@@ -10,47 +11,26 @@ class GameHistory {
|
|||||||
private:
|
private:
|
||||||
using HistorySizeType = std::uint16_t;
|
using HistorySizeType = std::uint16_t;
|
||||||
|
|
||||||
std::vector<std::optional<protocol::LockStep>> m_History {std::numeric_limits<HistorySizeType>::max()};
|
std::vector<std::optional<protocol::LockStep>> m_History;
|
||||||
|
|
||||||
HistorySizeType m_Cursor = 0;
|
HistorySizeType m_Cursor;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
GameHistory(){}
|
GameHistory();
|
||||||
|
|
||||||
void SetLockStep(HistorySizeType a_Index, protocol::LockStep&& a_LockStep) {
|
void SetLockStep(HistorySizeType a_Index, protocol::LockStep&& a_LockStep);
|
||||||
m_History[a_Index] = std::move(a_LockStep);
|
|
||||||
}
|
|
||||||
|
|
||||||
const protocol::LockStep& GetLockStep(HistorySizeType a_Index) const {
|
const protocol::LockStep& GetLockStep(HistorySizeType a_Index) const;
|
||||||
return *m_History[a_Index];
|
|
||||||
}
|
|
||||||
|
|
||||||
bool HasLockStep(HistorySizeType a_Index) const {
|
bool HasLockStep(HistorySizeType a_Index) const;
|
||||||
return m_History[a_Index].has_value();
|
|
||||||
}
|
|
||||||
|
|
||||||
const protocol::LockStep& GetNextStep() {
|
const protocol::LockStep& GetNextStep();
|
||||||
return GetLockStep(m_Cursor++);
|
|
||||||
}
|
|
||||||
|
|
||||||
bool HasNextStep() const {
|
bool HasNextStep() const;
|
||||||
return HasLockStep(m_Cursor);
|
|
||||||
}
|
|
||||||
|
|
||||||
void FromPacket(td::protocol::pdata::LockSteps&& a_Steps) {
|
void FromPacket(td::protocol::pdata::LockSteps&& a_Steps);
|
||||||
for (int i = 0; i < LOCKSTEP_BUFFER_SIZE; i++) {
|
|
||||||
protocol::LockStep& step = a_Steps.m_LockSteps[i];
|
|
||||||
SetLockStep(i + a_Steps.m_FirstFrameNumber, std::move(step));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
td::protocol::packets::LockSteps ToPacket(HistorySizeType a_StartIndex) {
|
td::protocol::packets::LockSteps ToPacket(HistorySizeType a_StartIndex);
|
||||||
std::array<protocol::LockStep, LOCKSTEP_BUFFER_SIZE> steps;
|
|
||||||
for (int i = 0; i < LOCKSTEP_BUFFER_SIZE; i++) {
|
|
||||||
steps[i] = GetLockStep(a_StartIndex + i);
|
|
||||||
}
|
|
||||||
return {{a_StartIndex, std::move(steps)}};
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace game
|
} // namespace game
|
||||||
|
|||||||
@@ -1,10 +1,10 @@
|
|||||||
#include <iostream>
|
#include <iostream>
|
||||||
// #include <td/protocol/packet/PacketVisitor.h>
|
// #include <td/protocol/packet/PacketVisitor.h>
|
||||||
|
#include <td/game/GameHistory.h>
|
||||||
#include <td/protocol/command/CommandDispatcher.h>
|
#include <td/protocol/command/CommandDispatcher.h>
|
||||||
#include <td/protocol/command/CommandFactory.h>
|
#include <td/protocol/command/CommandFactory.h>
|
||||||
#include <td/protocol/command/CommandSerializer.h>
|
#include <td/protocol/command/CommandSerializer.h>
|
||||||
#include <td/protocol/command/CommandVisitor.h>
|
#include <td/protocol/command/CommandVisitor.h>
|
||||||
#include <td/game/GameHistory.h>
|
|
||||||
|
|
||||||
class Test : public td::protocol::CommandVisitor {};
|
class Test : public td::protocol::CommandVisitor {};
|
||||||
|
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
#include <td/common/VarInt.h>
|
#include <td/common/VarInt.h>
|
||||||
|
|
||||||
#include <td/common/DataBuffer.h>
|
|
||||||
#include <stdexcept>
|
#include <stdexcept>
|
||||||
|
#include <td/common/DataBuffer.h>
|
||||||
|
|
||||||
namespace td {
|
namespace td {
|
||||||
|
|
||||||
|
|||||||
44
src/td/game/GameHistory.cpp
Normal file
44
src/td/game/GameHistory.cpp
Normal file
@@ -0,0 +1,44 @@
|
|||||||
|
#include <td/game/GameHistory.h>
|
||||||
|
|
||||||
|
namespace td {
|
||||||
|
namespace game {
|
||||||
|
|
||||||
|
GameHistory::GameHistory() : m_History(std::numeric_limits<HistorySizeType>::max()), m_Cursor(0) {}
|
||||||
|
|
||||||
|
void GameHistory::SetLockStep(HistorySizeType a_Index, protocol::LockStep&& a_LockStep) {
|
||||||
|
m_History[a_Index] = std::move(a_LockStep);
|
||||||
|
}
|
||||||
|
|
||||||
|
const protocol::LockStep& GameHistory::GetLockStep(HistorySizeType a_Index) const {
|
||||||
|
return *m_History[a_Index];
|
||||||
|
}
|
||||||
|
|
||||||
|
bool GameHistory::HasLockStep(HistorySizeType a_Index) const {
|
||||||
|
return m_History[a_Index].has_value();
|
||||||
|
}
|
||||||
|
|
||||||
|
const protocol::LockStep& GameHistory::GetNextStep() {
|
||||||
|
return GetLockStep(m_Cursor++);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool GameHistory::HasNextStep() const {
|
||||||
|
return HasLockStep(m_Cursor);
|
||||||
|
}
|
||||||
|
|
||||||
|
void GameHistory::FromPacket(td::protocol::pdata::LockSteps&& a_Steps) {
|
||||||
|
for (int i = 0; i < LOCKSTEP_BUFFER_SIZE; i++) {
|
||||||
|
protocol::LockStep& step = a_Steps.m_LockSteps[i];
|
||||||
|
SetLockStep(i + a_Steps.m_FirstFrameNumber, std::move(step));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
td::protocol::packets::LockSteps GameHistory::ToPacket(HistorySizeType a_StartIndex) {
|
||||||
|
std::array<protocol::LockStep, LOCKSTEP_BUFFER_SIZE> steps;
|
||||||
|
for (int i = 0; i < LOCKSTEP_BUFFER_SIZE; i++) {
|
||||||
|
steps[i] = GetLockStep(a_StartIndex + i);
|
||||||
|
}
|
||||||
|
return {{a_StartIndex, std::move(steps)}};
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace game
|
||||||
|
} // namespace td
|
||||||
@@ -1,6 +1,7 @@
|
|||||||
add_rules("mode.debug", "mode.release")
|
add_rules("mode.debug", "mode.release")
|
||||||
|
|
||||||
add_requires("fpm")
|
add_requires("fpm")
|
||||||
|
set_languages("c++17")
|
||||||
|
|
||||||
target("Tower-Defense2")
|
target("Tower-Defense2")
|
||||||
add_includedirs("include", {public = true})
|
add_includedirs("include", {public = true})
|
||||||
|
|||||||
Reference in New Issue
Block a user