Superman + Alfred

This commit is contained in:
MarcEricMartel
2023-11-27 16:12:12 -05:00
parent cfc7f7e01d
commit e8ca08ecab
4 changed files with 36 additions and 7 deletions

View File

@@ -1275,14 +1275,19 @@ void Engine::Render(float elapsedTime) {
using namespace std::chrono;
using namespace netprot;
Timestamp tstamp = duration_cast<milliseconds>(high_resolution_clock::now() - m_startTime).count();
static Timestamp last = 0;
Input input;
Sync sync;
uint64_t id = m_conn.getId();
static std::vector<char*> lsPck;
static uint64_t sync_acc = 0;
sync_acc += tstamp;
static int sync_acc = 0;
if (sync_acc >= 1000 || !has_synced) {
if (last == 0)
last = tstamp;
sync_acc += tstamp - last;
if (sync_acc >= 1000) {
sync_acc -= 1000;
sync.sid = id;
sync.timestamp = tstamp;
@@ -1322,13 +1327,15 @@ void Engine::Render(float elapsedTime) {
case SYNC:
if (Deserialize(&sync, pck, &bsize)) {
if (sync.sid != m_conn.getId()) {
std::cout << "syncid be no good.";
std::cout << "syncsid be no good.";
break;
}
if (m_syncs.contains(sync.timestamp)) {
Sync comp = m_syncs[sync.timestamp];
m_player.InflictDamage(sync.hp - comp.hp);
std::cout << "SID: " << sync.sid << "HP: " << sync.hp << " Pos: " << sync.position << std::endl;
Vector3f diff = sync.position - comp.position;
if (diff.Length() > .5)
m_player.Move(diff);