DOMO ARIGATO, MISUTA ROBOTO :trollface:
This commit is contained in:
		| @@ -47,6 +47,50 @@ PlayerInfo* Connection::getInfo() const { return (PlayerInfo*)&m_playinfo; } | ||||
|  | ||||
| sockaddr_in* Connection::getAddr() const { return (sockaddr_in*)&m_addr; } | ||||
|  | ||||
| void Connection::getPacks() { | ||||
| 	std::vector<char*> lsPck; | ||||
| 	Input in; | ||||
| 	while (true) { | ||||
| 		lsPck = recvPacksFrom(m_sock, m_buf, m_addr); | ||||
|  | ||||
| 		for (auto& pck : lsPck) { | ||||
| 			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 }); | ||||
| 				break; | ||||
| 			default: break; | ||||
| 			} | ||||
| 		} | ||||
| 		lsPck.clear(); | ||||
| 	} | ||||
| } | ||||
|  | ||||
| std::thread Connection::Start(){ return std::thread(getPacks); } | ||||
|  | ||||
| void Connection::Run(World* world) { | ||||
| 	Input in, last; | ||||
| 	Output out; | ||||
| 	float el; | ||||
|  | ||||
| 	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); | ||||
|  | ||||
| 	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); | ||||
|  | ||||
| 	out.position = player.get()->GetPosition(); | ||||
| 	out.direction = in.direction; | ||||
| 	out.timestamp = in.timestamp; | ||||
| } | ||||
|  | ||||
| void Connection::CleanInputManifest(Timestamp time) { | ||||
| 	auto wat = m_input_manifest.find(time); | ||||
|  | ||||
|   | ||||
		Reference in New Issue
	
	Block a user