SQC-15_online #1
| @@ -72,7 +72,9 @@ void Connection::getPacks(SOCKET sock) { | |||||||
| 		lsPck.clear(); | 		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()) { | 	while (!m_output_vector.empty()) { | ||||||
| 		Output out = m_output_vector.front(); | 		Output out = m_output_vector.front(); | ||||||
| 		for (auto& [key, conn] : conns) { | 		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()); | 			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(); | 		m_output_vector.pop_front(); | ||||||
| 	} | 	} | ||||||
| } | } | ||||||
|   | |||||||
| @@ -34,7 +34,7 @@ public: | |||||||
| 	sockaddr_in* getAddr() const; | 	sockaddr_in* getAddr() const; | ||||||
|  |  | ||||||
| 	void getPacks(SOCKET sock); | 	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); | 	void Run(World* world); | ||||||
|  |  | ||||||
|   | |||||||
| @@ -1275,14 +1275,19 @@ void Engine::Render(float elapsedTime) { | |||||||
| 			using namespace std::chrono; | 			using namespace std::chrono; | ||||||
| 			using namespace netprot; | 			using namespace netprot; | ||||||
| 			Timestamp tstamp = duration_cast<milliseconds>(high_resolution_clock::now() - m_startTime).count(); | 			Timestamp tstamp = duration_cast<milliseconds>(high_resolution_clock::now() - m_startTime).count(); | ||||||
|  | 			static Timestamp last = 0; | ||||||
| 			Input input; | 			Input input; | ||||||
| 			Sync sync; | 			Sync sync; | ||||||
| 			uint64_t id = m_conn.getId(); | 			uint64_t id = m_conn.getId(); | ||||||
| 			static std::vector<char*> lsPck; | 			static std::vector<char*> lsPck; | ||||||
| 			static uint64_t sync_acc = 0; | 			static int sync_acc = 0; | ||||||
| 			sync_acc += tstamp; |  | ||||||
|  |  | ||||||
| 			if (sync_acc >= 1000 || !has_synced) { | 			if (last == 0) | ||||||
|  | 				last = tstamp; | ||||||
|  |  | ||||||
|  | 			sync_acc += tstamp - last; | ||||||
|  |  | ||||||
|  | 			if (sync_acc >= 1000) { | ||||||
| 				sync_acc -= 1000; | 				sync_acc -= 1000; | ||||||
| 				sync.sid = id; | 				sync.sid = id; | ||||||
| 				sync.timestamp = tstamp; | 				sync.timestamp = tstamp; | ||||||
| @@ -1322,13 +1327,15 @@ void Engine::Render(float elapsedTime) { | |||||||
| 				case SYNC: | 				case SYNC: | ||||||
| 					if (Deserialize(&sync, pck, &bsize)) { | 					if (Deserialize(&sync, pck, &bsize)) { | ||||||
| 						if (sync.sid != m_conn.getId()) { | 						if (sync.sid != m_conn.getId()) { | ||||||
| 							std::cout << "syncid be no good."; | 							std::cout << "syncsid be no good."; | ||||||
| 							break; | 							break; | ||||||
| 						} | 						} | ||||||
| 						if (m_syncs.contains(sync.timestamp)) { | 						if (m_syncs.contains(sync.timestamp)) { | ||||||
| 							Sync comp = m_syncs[sync.timestamp]; | 							Sync comp = m_syncs[sync.timestamp]; | ||||||
| 							m_player.InflictDamage(sync.hp - comp.hp); | 							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; | 							Vector3f diff = sync.position - comp.position; | ||||||
| 							if (diff.Length() > .5) | 							if (diff.Length() > .5) | ||||||
| 								m_player.Move(diff); | 								m_player.Move(diff); | ||||||
|   | |||||||
| @@ -5,5 +5,5 @@ | |||||||
| int main() { | int main() { | ||||||
|     Engine engine; |     Engine engine; | ||||||
|     engine.SetMaxFps(60); |     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); | ||||||
| } | } | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user