heum well
This commit is contained in:
		| @@ -47,19 +47,19 @@ PlayerInfo* Connection::getInfo() const { return (PlayerInfo*)&m_playinfo; } | ||||
|  | ||||
| sockaddr_in* Connection::getAddr() const { return (sockaddr_in*)&m_addr; } | ||||
|  | ||||
| void Connection::getPacks() { | ||||
| void Connection::getPacks(SOCKET sock) { | ||||
| 	std::vector<char*> lsPck; | ||||
| 	Input in; | ||||
| 	while (true) { | ||||
| 		lsPck = recvPacksFrom(m_sock, m_buf, m_addr); | ||||
| 		lsPck = recvPacksFrom(sock, &m_buf, m_addr); | ||||
|  | ||||
| 		for (auto& pck : lsPck) { | ||||
| 			uint32_t bsize = m_buf->len - (pck - m_buf->ptr); | ||||
| 			uint32_t bsize = m_buf.len - (pck - m_buf.ptr); | ||||
| 			switch (netprot::getType(pck, 1)) { | ||||
| 				using enum netprot::PACKET_TYPE; | ||||
| 			case INPUT: | ||||
| 				if (Deserialize(&in, pck, &bsize)) | ||||
| 					m_input_manifest.insert({ in.timestamp, in }); | ||||
| 					m_input_manifest[in.timestamp] = in; | ||||
| 				break; | ||||
| 			default: break; | ||||
| 			} | ||||
| @@ -68,7 +68,17 @@ void Connection::getPacks() { | ||||
| 	} | ||||
| } | ||||
|  | ||||
| std::thread Connection::Start(){ return std::thread(getPacks); } | ||||
| void Connection::sendPacks(SOCKET sock, std::unordered_map<uint64_t, Connection*> conns) { | ||||
| 	while (m_last_out < m_output_manifest.size()) { | ||||
| 		Output out = m_output_manifest.at(m_last_out++); | ||||
|  | ||||
| 		for (auto& [key, conn] : conns) { | ||||
| 			if (m_playinfo.id == conn->GetHash(true)) | ||||
| 				continue; | ||||
| 			sendPackTo<Output>(sock, &out, &m_bufout, conn->getAddr()); | ||||
| 		} | ||||
| 	} | ||||
| } | ||||
|  | ||||
| void Connection::Run(World* world) { | ||||
| 	Input in, last; | ||||
| @@ -78,17 +88,27 @@ void Connection::Run(World* world) { | ||||
| 	if (m_input_manifest.size() < 2) | ||||
| 		return; | ||||
|  | ||||
| 	in = m_input_manifest.at(m_input_manifest.size()); | ||||
| 	last = m_input_manifest.at(m_input_manifest.size() - 1); | ||||
| 	while (m_last_in < m_input_manifest.size()) { | ||||
| 		in = m_input_manifest.at(m_last_in + 1); | ||||
| 		last = m_input_manifest.at(m_last_in); | ||||
|  | ||||
| 	el = (float)(in.timestamp - last.timestamp) / 1000.; | ||||
| 		el = (float)(in.timestamp - last.timestamp) / 1000.; | ||||
| 		player.get()->SetDirection(in.direction); | ||||
| 		player.get()->ApplyPhysics(player.get()->GetInput(in.keys.forward,  | ||||
| 														  in.keys.backward,  | ||||
| 														  in.keys.left,  | ||||
| 														  in.keys.right,  | ||||
| 														  in.keys.jump, false, el), world, el); | ||||
|  | ||||
| 	player.get()->SetDirection(in.direction); | ||||
| 	player.get()->ApplyPhysics(player.get()->GetInput(in.keys.forward, in.keys.backward, in.keys.left, in.keys.right, in.keys.jump, false, el), world, el); | ||||
| 		out.position = player.get()->GetPosition(); | ||||
| 		out.direction = in.direction; | ||||
| 		out.timestamp = in.timestamp; | ||||
| 		out.id = m_playinfo.id; | ||||
|  | ||||
| 	out.position = player.get()->GetPosition(); | ||||
| 	out.direction = in.direction; | ||||
| 	out.timestamp = in.timestamp; | ||||
| 		m_output_manifest[out.timestamp] = out; | ||||
|  | ||||
| 		++m_last_in; | ||||
| 	} | ||||
| } | ||||
|  | ||||
| void Connection::CleanInputManifest(Timestamp time) { | ||||
|   | ||||
		Reference in New Issue
	
	Block a user