<commit_before>#include <NetClient.h>
#include <hydra/component/meshcomponent.hpp>

void NetClient::_sendUpdatePacket() {
	if (this->_np.entptr) {
		ClientUpdatePacket cpup;
		Hydra::Component::TransformComponent* tc = this->_np.entptr->getComponent<Hydra::Component::TransformComponent>();
		cpup.ti.pos = tc->getPosition();
		cpup.ti.scale = tc->getScale();
		cpup.ti.rot = tc->getRotation();
		cpup.h.type = PacketType::ClientUpdate;
		cpup.h.len = sizeof(ClientUpdatePacket);

		this->_tcp.send(&cpup, cpup.h.len);
	}
}
HYDRA_API void NetClient::sendEntity(Hydra::World::IEntity * ent) {
	nlohmann::json json;
	ent->serialize(json);
	std::vector<uint8_t> vec = json.to_msgpack(json);
	ClientSpawnEntityPacket* packet = new ClientSpawnEntityPacket();
	packet->h.type = PacketType::ClientSpawnEntity;
	packet->size = vec.size();
	packet->h.len = packet->getSize();

	char* result = new char[sizeof(ClientSpawnEntityPacket) + vec.size() * sizeof(uint8_t)];
	
	memcpy(result, packet, sizeof(ClientSpawnEntityPacket));
	memcpy(result + sizeof(ClientSpawnEntityPacket), vec.data(), vec.size() * sizeof(uint8_t));

	this->_tcp.send(result, sizeof(ClientSpawnEntityPacket) + vec.size() * sizeof(uint8_t));
	//this->_tcp.send(packet, sizeof(ClientSpawnEntityPacket)); // DATA SNED
	//this->_tcp.send(vec.data(), vec.size() * sizeof(uint8_t)); // DATA SKJICJIK

	delete[] result;
	delete packet;
}

void NetClient::_resolvePackets(Hydra::World::IWorld* world) {
	std::vector<Packet*> packets = this->_tcp.receiveData();
	Hydra::Component::TransformComponent* tc;
	std::vector<std::shared_ptr<Hydra::World::IEntity>> children;
	std::shared_ptr<Hydra::World::IEntity> ent;
	for (size_t i = 0; i < packets.size(); i++) {
		switch (packets[i]->h.type) {
		case PacketType::ServerInitialize:
			children = world->getWorldRoot()->getChildren();
			for (size_t i = 0; i < children.size(); i++) {
				if (children[i]->getName() == "Player") {
					this->_np.entptr = children[i].get();
					break;
				}
			}
			this->_np.entID = ((ServerInitializePacket*)packets[i])->entityid;
			this->_np.entptr->setID(this->_np.entID);
			tc = this->_np.entptr->getComponent<Hydra::Component::TransformComponent>();
			tc->setPosition(((ServerInitializePacket*)packets[i])->ti.pos);
			tc->setRotation(((ServerInitializePacket*)packets[i])->ti.rot);
			tc->setScale(((ServerInitializePacket*)packets[i])->ti.scale);
			//ent = world->createEntity("JagArEttSkott");
			//ent->addComponent<Hydra::Component::TransformComponent>();
			//this->_sendEntity(ent.get()); // KOLLAR SPAWN ENTITYPACKET OM DET FUNGERAR GUCCI
			break;

		case PacketType::ServerUpdate: 
			this->_updateWorld(world, packets[i]);
			break;<commit_msg>show client and server plz<commit_after>#include <NetClient.h>
#include <hydra/component/meshcomponent.hpp>

void NetClient::_sendUpdatePacket() {
	if (this->_np.entptr) {
		ClientUpdatePacket cpup;
		Hydra::Component::TransformComponent* tc = this->_np.entptr->getComponent<Hydra::Component::TransformComponent>();
		cpup.ti.pos = tc->getPosition();
		cpup.ti.scale = tc->getScale();
		cpup.ti.rot = tc->getRotation();
		cpup.h.type = PacketType::ClientUpdate;
		cpup.h.len = sizeof(ClientUpdatePacket);

		this->_tcp.send(&cpup, cpup.h.len);
	}
}
HYDRA_API void NetClient::sendEntity(Hydra::World::IEntity * ent) {
	nlohmann::json json;
	ent->serialize(json);
	std::vector<uint8_t> vec = json.to_msgpack(json);
	ClientSpawnEntityPacket* packet = new ClientSpawnEntityPacket();
	packet->h.type = PacketType::ClientSpawnEntity;
	packet->size = vec.size();
	packet->h.len = packet->getSize();

	char* result = new char[sizeof(ClientSpawnEntityPacket) + vec.size() * sizeof(uint8_t)];
	
	memcpy(result, packet, sizeof(ClientSpawnEntityPacket));
	memcpy(result + sizeof(ClientSpawnEntityPacket), vec.data(), vec.size() * sizeof(uint8_t));

	this->_tcp.send(result, sizeof(ClientSpawnEntityPacket) + vec.size() * sizeof(uint8_t));
	//this->_tcp.send(packet, sizeof(ClientSpawnEntityPacket)); // DATA SNED
	//this->_tcp.send(vec.data(), vec.size() * sizeof(uint8_t)); // DATA SKJICJIK

	delete[] result;
	delete packet;
}

void NetClient::_resolvePackets(Hydra::World::IWorld* world) {
	std::vector<Packet*> packets = this->_tcp.receiveData();
	Hydra::Component::TransformComponent* tc;
	std::vector<std::shared_ptr<Hydra::World::IEntity>> children;
	std::shared_ptr<Hydra::World::IEntity> ent;
	for (size_t i = 0; i < packets.size(); i++) {
		switch (packets[i]->h.type) {
		case PacketType::ServerInitialize:
			children = world->getWorldRoot()->getChildren();
			for (size_t i = 0; i < children.size(); i++) {
				if (children[i]->getName() == "Player") {
					this->_np.entptr = children[i].get();
					break;
				}
			}
			this->_np.entID = ((ServerInitializePacket*)packets[i])->entityid;
			this->_np.entptr->setID(this->_np.entID);
			tc = this->_np.entptr->getComponent<Hydra::Component::TransformComponent>();
			tc->setPosition(((ServerInitializePacket*)packets[i])->ti.pos);
			tc->setRotation(((ServerInitializePacket*)packets[i])->ti.rot);
			tc->setScale(((ServerInitializePacket*)packets[i])->ti.scale);
			//ent = world->createEntity("JagArEttSkott");
			//ent->addComponent<Hydra::Component::TransformComponent>();
			//this->_sendEntity(ent.get()); // KOLLAR SPAWN ENTITYPACKET OM DET FUNGERAR GUCCI
			break;

		case PacketType::ServerUpdate:
			if(i == packets.size() - 1)
				this->_updateWorld(world, packets[i]);
			break;
{'fraction_non_alphanumeric': 0.18315557190143436, 'fraction_numerical': 0.002758367046708349, 'mean_word_length': 5.641025641025641, 'pattern_counts': {'":': 0, '<': 27, '<?xml version=': 0, '>': 99, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2862922', 'n_tokens_mistral': 2014, 'n_tokens_neox': 1894, 'n_words': 284}