Superman + Alfred
This commit is contained in:
parent
cfc7f7e01d
commit
e8ca08ecab
@ -72,7 +72,9 @@ void Connection::getPacks(SOCKET sock) {
|
||||
lsPck.clear();
|
||||
}
|
||||
|
||||
void Connection::sendPacks(SOCKET sock, std::unordered_map<uint64_t, Connection*> conns) {
|
||||
void Connection::sendPacks(SOCKET sock, std::unordered_map<uint64_t, Connection*> conns, const uint32_t timer) {
|
||||
static int outs = 0;
|
||||
static Timestamp last = 0;
|
||||
while (!m_output_vector.empty()) {
|
||||
Output out = m_output_vector.front();
|
||||
for (auto& [key, conn] : conns) {
|
||||
@ -83,6 +85,26 @@ void Connection::sendPacks(SOCKET sock, std::unordered_map<uint64_t, Connection*
|
||||
|
||||
sendPackTo<Output>(sock, &out, &m_bufout, conn->getAddr());
|
||||
}
|
||||
++outs;
|
||||
|
||||
[[unlikely]] if (last == 0) // !
|
||||
last = out.timestamp;
|
||||
|
||||
outs += out.timestamp + last;
|
||||
|
||||
if (outs >= 1000) {
|
||||
outs -= 1000;
|
||||
Sync sync;
|
||||
sync.hp = player.get()->GetHP();
|
||||
sync.timestamp = out.timestamp;
|
||||
sync.position = out.position;
|
||||
sync.sid = m_loginfo.sid;
|
||||
sync.timer = timer;
|
||||
sync.timestamp = out.timestamp;
|
||||
sync.ammo = -1;
|
||||
sendPackTo<Sync>(sock, &sync, &m_bufout, &m_addr);
|
||||
}
|
||||
|
||||
m_output_vector.pop_front();
|
||||
}
|
||||
}
|
||||
|
@ -34,7 +34,7 @@ public:
|
||||
sockaddr_in* getAddr() const;
|
||||
|
||||
void getPacks(SOCKET sock);
|
||||
void sendPacks(SOCKET sock, std::unordered_map<uint64_t, Connection*> conns);
|
||||
void sendPacks(SOCKET sock, std::unordered_map<uint64_t, Connection*> conns, const uint32_t timer);
|
||||
|
||||
void Run(World* world);
|
||||
|
||||
|
@ -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);
|
||||
|
@ -5,5 +5,5 @@
|
||||
int main() {
|
||||
Engine engine;
|
||||
engine.SetMaxFps(60);
|
||||
engine.Start("Syndicat Quebecois de la Construction Simulator 2023", 1920, 1080, false);
|
||||
engine.Start("Syndicat Quebecois de la Construction Simulator 2023", 800, 600, false);
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user