Compare commits
	
		
			79 Commits
		
	
	
		
			L-CSplash
			...
			SQC-18_Mec
		
	
	| Author | SHA1 | Date | |
|---|---|---|---|
| 
						 | 
					2a4a5e13cc | ||
| 
						 | 
					9b0c4dc594 | ||
| 
						 | 
					602bb84428 | ||
| 
						 | 
					4df7cfbd5d | ||
| 
						 | 
					6e75bec25c | ||
| 
						 | 
					bbfc98ff12 | ||
| 
						 | 
					3249d68e60 | ||
| 
						 | 
					ada9330588 | ||
| 
						 | 
					3da8be6d52 | ||
| 
						 | 
					a95dd02896 | ||
| 
						 | 
					6ce7e62e05 | ||
| 
						 | 
					e2dbf52b17 | ||
| 
						 | 
					53ed811936 | ||
| 
						 | 
					15b4dfefc0 | ||
| 
						 | 
					b50a2f44e2 | ||
| 
						 | 
					4f64be7e0a | ||
| 
						 | 
					b54f8c31e5 | ||
| 
						 | 
					0b07d46dba | ||
| 
						 | 
					c33e6f865c | ||
| 
						 | 
					03be36ecda | ||
| 
						 | 
					aab3301234 | ||
| 
						 | 
					d0c39e49b0 | ||
| 
						 | 
					10fcfed05a | ||
| 
						 | 
					a69e716105 | ||
| 
						 | 
					3f8d860b93 | ||
| 
						 | 
					42d612ad33 | ||
| 
						 | 
					c23d1b2120 | ||
| 
						 | 
					76a7d0218d | ||
| 
						 | 
					e2e66f3b6c | ||
| 
						 | 
					f0bf7d94ce | ||
| 
						 | 
					49c9576757 | ||
| 
						 | 
					e2fa4fea7c | ||
| 
						 | 
					61629b3c8e | ||
| 
						 | 
					8970bc33a1 | ||
| 
						 | 
					c1faaca417 | ||
| 
						 | 
					889884490b | ||
| 
						 | 
					bd817f9f7d | ||
| 
						 | 
					57d60e02a7 | ||
| 
						 | 
					ae201846b1 | ||
| 
						 | 
					1c7523558b | ||
| 
						 | 
					fc4a22e844 | ||
| 
						 | 
					f7b7a7f14d | ||
| 
						 | 
					102153a093 | ||
| 
						 | 
					da594fa3a2 | ||
| 
						 | 
					6a8a505167 | ||
| 
						 | 
					0dded0bc9b | ||
| 
						 | 
					9ef44a3993 | ||
| 
						 | 
					0bc7f29492 | ||
| 
						 | 
					60cc69a407 | ||
| 
						 | 
					05f9658f55 | ||
| 
						 | 
					2f2b49054f | ||
| 
						 | 
					397cf7f00d | ||
| 
						 | 
					8e95899192 | ||
| 
						 | 
					8870550512 | ||
| 
						 | 
					f5a1906877 | ||
| 
						 | 
					9b4defba2a | ||
| 
						 | 
					dd2396e5e4 | ||
| 
						 | 
					c7271f6217 | ||
| 
						 | 
					8ebe7b95fc | ||
| 
						 | 
					4964bc5394 | ||
| 
						 | 
					cf6e58cd95 | ||
| 
						 | 
					ffeb95d953 | ||
| 
						 | 
					2c3abff96f | ||
| 
						 | 
					5e29c9be54 | ||
| 
						 | 
					fc4aa20005 | ||
| 
						 | 
					ecfe5b893b | ||
| 
						 | 
					eea6a30aa5 | ||
| 
						 | 
					9f615db929 | ||
| 
						 | 
					498fb7baf7 | ||
| 
						 | 
					49240635b6 | ||
| 
						 | 
					df5b7960b2 | ||
| 
						 | 
					b943a268ae | ||
| 
						 | 
					590220bc92 | ||
| 
						 | 
					67a49a4cad | ||
| 
						 | 
					0e7b8973e7 | ||
| 
						 | 
					2cb7d4c776 | ||
| 
						 | 
					db0a39f64a | ||
| 
						 | 
					d7e55c8446 | ||
| 
						 | 
					183c5f186a | 
							
								
								
									
										2
									
								
								.gitignore
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										2
									
								
								.gitignore
									
									
									
									
										vendored
									
									
								
							@@ -378,3 +378,5 @@ FodyWeavers.xsd
 | 
				
			|||||||
/SQCSim2021/cmake/*
 | 
					/SQCSim2021/cmake/*
 | 
				
			||||||
!/SQCSim2021/cmake/CMakeLists.txt
 | 
					!/SQCSim2021/cmake/CMakeLists.txt
 | 
				
			||||||
/SQCSim2021/SQCSim-client
 | 
					/SQCSim2021/SQCSim-client
 | 
				
			||||||
 | 
					SQCSim2021/SQCSim2021.vcxproj.filters
 | 
				
			||||||
 | 
					SQCSim2021/SQCSim2021.vcxproj
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -76,6 +76,7 @@
 | 
				
			|||||||
      <SDLCheck>true</SDLCheck>
 | 
					      <SDLCheck>true</SDLCheck>
 | 
				
			||||||
      <PreprocessorDefinitions>WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
 | 
					      <PreprocessorDefinitions>WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
 | 
				
			||||||
      <ConformanceMode>true</ConformanceMode>
 | 
					      <ConformanceMode>true</ConformanceMode>
 | 
				
			||||||
 | 
					      <LanguageStandard>stdcpp20</LanguageStandard>
 | 
				
			||||||
    </ClCompile>
 | 
					    </ClCompile>
 | 
				
			||||||
    <Link>
 | 
					    <Link>
 | 
				
			||||||
      <SubSystem>Console</SubSystem>
 | 
					      <SubSystem>Console</SubSystem>
 | 
				
			||||||
@@ -90,6 +91,7 @@
 | 
				
			|||||||
      <SDLCheck>true</SDLCheck>
 | 
					      <SDLCheck>true</SDLCheck>
 | 
				
			||||||
      <PreprocessorDefinitions>WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
 | 
					      <PreprocessorDefinitions>WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
 | 
				
			||||||
      <ConformanceMode>true</ConformanceMode>
 | 
					      <ConformanceMode>true</ConformanceMode>
 | 
				
			||||||
 | 
					      <LanguageStandard>stdcpp20</LanguageStandard>
 | 
				
			||||||
    </ClCompile>
 | 
					    </ClCompile>
 | 
				
			||||||
    <Link>
 | 
					    <Link>
 | 
				
			||||||
      <SubSystem>Console</SubSystem>
 | 
					      <SubSystem>Console</SubSystem>
 | 
				
			||||||
@@ -104,6 +106,7 @@
 | 
				
			|||||||
      <SDLCheck>true</SDLCheck>
 | 
					      <SDLCheck>true</SDLCheck>
 | 
				
			||||||
      <PreprocessorDefinitions>_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
 | 
					      <PreprocessorDefinitions>_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
 | 
				
			||||||
      <ConformanceMode>true</ConformanceMode>
 | 
					      <ConformanceMode>true</ConformanceMode>
 | 
				
			||||||
 | 
					      <LanguageStandard>stdcpp20</LanguageStandard>
 | 
				
			||||||
    </ClCompile>
 | 
					    </ClCompile>
 | 
				
			||||||
    <Link>
 | 
					    <Link>
 | 
				
			||||||
      <SubSystem>Console</SubSystem>
 | 
					      <SubSystem>Console</SubSystem>
 | 
				
			||||||
@@ -118,7 +121,7 @@
 | 
				
			|||||||
      <SDLCheck>true</SDLCheck>
 | 
					      <SDLCheck>true</SDLCheck>
 | 
				
			||||||
      <PreprocessorDefinitions>NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
 | 
					      <PreprocessorDefinitions>NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
 | 
				
			||||||
      <ConformanceMode>true</ConformanceMode>
 | 
					      <ConformanceMode>true</ConformanceMode>
 | 
				
			||||||
      <LanguageStandard>stdcpp17</LanguageStandard>
 | 
					      <LanguageStandard>stdcpp20</LanguageStandard>
 | 
				
			||||||
    </ClCompile>
 | 
					    </ClCompile>
 | 
				
			||||||
    <Link>
 | 
					    <Link>
 | 
				
			||||||
      <SubSystem>Console</SubSystem>
 | 
					      <SubSystem>Console</SubSystem>
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -7,11 +7,19 @@ Bullet::Bullet(Vector3f pos, Vector3f dir, uint64_t tid): m_startpos(pos), m_cur
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
Bullet::~Bullet() {}
 | 
					Bullet::~Bullet() {}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
bool Bullet::Update(World* world, float elapsedtime, int perframe) {
 | 
					bool Bullet::Update(World* world, float elapsedtime, int perframe, std::map<uint64_t, Player*> mapPlayer) {
 | 
				
			||||||
	int max = 100 / perframe;
 | 
						int max = 100 / perframe;
 | 
				
			||||||
 | 
						float damage = 0.057f;
 | 
				
			||||||
	for (int x = 0; x < max; ++x) {
 | 
						for (int x = 0; x < max; ++x) {
 | 
				
			||||||
		m_currentpos += m_velocity * elapsedtime;
 | 
							m_currentpos += m_velocity * elapsedtime;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							for (auto& [key, player] : mapPlayer) {
 | 
				
			||||||
 | 
								if ((m_currentpos - player->GetPosition()).Length() < .4f) {
 | 
				
			||||||
 | 
									player->InflictDamage(damage);
 | 
				
			||||||
 | 
									return true;
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		if (!world->ChunkAt(m_currentpos))
 | 
							if (!world->ChunkAt(m_currentpos))
 | 
				
			||||||
			return true;
 | 
								return true;
 | 
				
			||||||
		else if (world->BlockAt(m_currentpos) != BTYPE_AIR) {
 | 
							else if (world->BlockAt(m_currentpos) != BTYPE_AIR) {
 | 
				
			||||||
@@ -20,7 +28,7 @@ bool Bullet::Update(World* world, float elapsedtime, int perframe) {
 | 
				
			|||||||
		}
 | 
							}
 | 
				
			||||||
		else if ((m_currentpos - m_startpos).Length() > VIEW_DISTANCE) return true;
 | 
							else if ((m_currentpos - m_startpos).Length() > VIEW_DISTANCE) return true;
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
						
 | 
				
			||||||
	return false;
 | 
						return false;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -3,8 +3,12 @@
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
#include "define.h"
 | 
					#include "define.h"
 | 
				
			||||||
#include "vector3.h"
 | 
					#include "vector3.h"
 | 
				
			||||||
 | 
					#include <map>
 | 
				
			||||||
 | 
					#include "player.h"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
class World;
 | 
					class World;
 | 
				
			||||||
 | 
					class Player;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
class Bullet {
 | 
					class Bullet {
 | 
				
			||||||
public:
 | 
					public:
 | 
				
			||||||
@@ -12,7 +16,7 @@ public:
 | 
				
			|||||||
	Bullet(Vector3f pos, Vector3f dir, uint64_t tid);
 | 
						Bullet(Vector3f pos, Vector3f dir, uint64_t tid);
 | 
				
			||||||
	~Bullet();
 | 
						~Bullet();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	bool Update(World* world, float elapsedtime, int perframe);
 | 
						bool Update(World* world, float elapsedtime, int perframe, std::map<uint64_t, Player*> m_mapPlayer);
 | 
				
			||||||
	void Transpose(int& x, int& z);
 | 
						void Transpose(int& x, int& z);
 | 
				
			||||||
	Vector3f getPos() const;
 | 
						Vector3f getPos() const;
 | 
				
			||||||
	Vector3f getVel() const;
 | 
						Vector3f getVel() const;
 | 
				
			||||||
@@ -23,6 +27,8 @@ private:
 | 
				
			|||||||
			 m_currentpos, 
 | 
								 m_currentpos, 
 | 
				
			||||||
			 m_velocity;
 | 
								 m_velocity;
 | 
				
			||||||
	uint64_t m_tid = 0;
 | 
						uint64_t m_tid = 0;
 | 
				
			||||||
 | 
						
 | 
				
			||||||
 | 
					
 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#endif // BULLET_H__
 | 
					#endif // BULLET_H__
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -4,8 +4,10 @@
 | 
				
			|||||||
#include <iostream>
 | 
					#include <iostream>
 | 
				
			||||||
#include <chrono>
 | 
					#include <chrono>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#define SRV_PORT 1025
 | 
					#define SRV_PORT 10000
 | 
				
			||||||
#define CLI_PORT 1026
 | 
					#define CLI_PORT 10001
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#define BUFFER_LENGTH 150
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#define CHUNK_SIZE_X  4
 | 
					#define CHUNK_SIZE_X  4
 | 
				
			||||||
#define CHUNK_SIZE_Y  64
 | 
					#define CHUNK_SIZE_Y  64
 | 
				
			||||||
@@ -29,6 +31,8 @@
 | 
				
			|||||||
#define TEXTURE_SIZE 512
 | 
					#define TEXTURE_SIZE 512
 | 
				
			||||||
#define MAX_BULLETS 512
 | 
					#define MAX_BULLETS 512
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#define BULLET_TIME .1
 | 
				
			||||||
 | 
					
 | 
				
			||||||
typedef uint8_t BlockType;
 | 
					typedef uint8_t BlockType;
 | 
				
			||||||
enum BLOCK_TYPE { BTYPE_AIR, BTYPE_DIRT, BTYPE_GRASS, BTYPE_METAL, BTYPE_ICE, BTYPE_LAST };
 | 
					enum BLOCK_TYPE { BTYPE_AIR, BTYPE_DIRT, BTYPE_GRASS, BTYPE_METAL, BTYPE_ICE, BTYPE_LAST };
 | 
				
			||||||
typedef uint64_t Timestamp;
 | 
					typedef uint64_t Timestamp;
 | 
				
			||||||
@@ -42,6 +46,11 @@ typedef uint64_t Timestamp;
 | 
				
			|||||||
#include <cstdio>
 | 
					#include <cstdio>
 | 
				
			||||||
#include <ctime>
 | 
					#include <ctime>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#define flag_t u_long
 | 
				
			||||||
 | 
					#define addrlen_t int
 | 
				
			||||||
 | 
					#define ioctl ioctlsocket
 | 
				
			||||||
 | 
					#define SOCK_NONBLOCK FIONBIO
 | 
				
			||||||
 | 
					#define strcpy strcpy_s
 | 
				
			||||||
#define popen _popen
 | 
					#define popen _popen
 | 
				
			||||||
#define pclose _pclose
 | 
					#define pclose _pclose
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -51,10 +60,13 @@ typedef uint64_t Timestamp;
 | 
				
			|||||||
#include <time.h>
 | 
					#include <time.h>
 | 
				
			||||||
#include <stdio.h>
 | 
					#include <stdio.h>
 | 
				
			||||||
#include <sys/socket.h>
 | 
					#include <sys/socket.h>
 | 
				
			||||||
 | 
					#include <sys/ioctl.h>
 | 
				
			||||||
#include <arpa/inet.h>
 | 
					#include <arpa/inet.h>
 | 
				
			||||||
#include <netinet/in.h>
 | 
					#include <netinet/in.h>
 | 
				
			||||||
#include <cstring>
 | 
					#include <cstring>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#define flag_t unsigned int
 | 
				
			||||||
 | 
					#define addrlen_t unsigned int
 | 
				
			||||||
#define SOCKET int
 | 
					#define SOCKET int
 | 
				
			||||||
#define INVALID_SOCKET -1
 | 
					#define INVALID_SOCKET -1
 | 
				
			||||||
#define closesocket close
 | 
					#define closesocket close
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -1,29 +1,29 @@
 | 
				
			|||||||
#include "netprotocol.h"
 | 
					#include "netprotocol.h"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void netprot::Serialize(Input* in, char* buf[], uint32_t* buflen) {
 | 
					void netprot::Serialize(Input* in, char* buf[], uint32_t* buflen) {
 | 
				
			||||||
	*buf[0] = netprot::PACKET_TYPE::INPUT;
 | 
						*buf[0] = (char)netprot::PACKET_TYPE::INPUT;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	uint64_t time = in->timestamp;
 | 
						uint64_t time = in->timestamp;
 | 
				
			||||||
	uint8_t time8[sizeof(uint64_t)] = {(time >> 56) & 0xFF,
 | 
						uint8_t time8[sizeof(uint64_t)] = {(uint8_t)((time >> 56) & 0xFF),
 | 
				
			||||||
									   (time >> 48) & 0xFF,
 | 
														   (uint8_t)((time >> 48) & 0xFF),
 | 
				
			||||||
									   (time >> 40) & 0xFF,
 | 
														   (uint8_t)((time >> 40) & 0xFF),
 | 
				
			||||||
									   (time >> 32) & 0xFF,
 | 
														   (uint8_t)((time >> 32) & 0xFF),
 | 
				
			||||||
									   (time >> 24) & 0xFF,
 | 
														   (uint8_t)((time >> 24) & 0xFF),
 | 
				
			||||||
									   (time >> 16) & 0xFF,
 | 
														   (uint8_t)((time >> 16) & 0xFF),
 | 
				
			||||||
									   (time >> 8 ) & 0xFF,
 | 
														   (uint8_t)((time >> 8 ) & 0xFF),
 | 
				
			||||||
									    time		& 0xFF};
 | 
														    (uint8_t)(time		  & 0xFF)};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	memcpy(*buf + 1, time8, sizeof(uint64_t));
 | 
						memcpy(*buf + 1, time8, sizeof(uint64_t));
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	uint64_t sid = in->sid;
 | 
						uint64_t sid = in->sid;
 | 
				
			||||||
	uint8_t sid8[sizeof(uint64_t)] = {(sid >> 56) & 0xFF,
 | 
						uint8_t sid8[sizeof(uint64_t)] = {(uint8_t)((sid >> 56) & 0xFF),
 | 
				
			||||||
									  (sid >> 48) & 0xFF,
 | 
														  (uint8_t)((sid >> 48) & 0xFF),
 | 
				
			||||||
									  (sid >> 40) & 0xFF,
 | 
														  (uint8_t)((sid >> 40) & 0xFF),
 | 
				
			||||||
									  (sid >> 32) & 0xFF,
 | 
														  (uint8_t)((sid >> 32) & 0xFF),
 | 
				
			||||||
									  (sid >> 24) & 0xFF,
 | 
														  (uint8_t)((sid >> 24) & 0xFF),
 | 
				
			||||||
									  (sid >> 16) & 0xFF,
 | 
														  (uint8_t)((sid >> 16) & 0xFF),
 | 
				
			||||||
									  (sid >> 8 ) & 0xFF,
 | 
														  (uint8_t)((sid >> 8 ) & 0xFF),
 | 
				
			||||||
									   sid		  & 0xFF};
 | 
														  (uint8_t)( sid		& 0xFF)};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	memcpy(*buf + sizeof(uint64_t) + 1, sid8, sizeof(uint64_t));
 | 
						memcpy(*buf + sizeof(uint64_t) + 1, sid8, sizeof(uint64_t));
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -37,54 +37,140 @@ void netprot::Serialize(Input* in, char* buf[], uint32_t* buflen) {
 | 
				
			|||||||
		keys.shoot    & 0b00000100 |
 | 
							keys.shoot    & 0b00000100 |
 | 
				
			||||||
		keys.block    & 0b00000010 ;
 | 
							keys.block    & 0b00000010 ;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	memcpy(*buf + sizeof(uint64_t) + 2, &keys8, sizeof(uint8_t));
 | 
						memcpy(*buf + sizeof(uint64_t) * 2 + 1, &keys8, sizeof(uint8_t));
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	uint32_t vec[3];
 | 
						uint32_t vec[3];
 | 
				
			||||||
	memcpy(vec, &in->direction, sizeof(Vector3f)); // Pour d<>naturer les floats.
 | 
						memcpy(vec, &in->direction, sizeof(Vector3f)); // Pour d<>naturer les floats.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	uint8_t vec8[3 * sizeof(uint32_t)] = {
 | 
						uint8_t vec8[3 * sizeof(uint32_t)] = {
 | 
				
			||||||
							(vec[0] >> 24) & 0xFF,
 | 
												(uint8_t)((vec[0] >> 24) & 0xFF),
 | 
				
			||||||
							(vec[0] >> 16) & 0xFF,
 | 
												(uint8_t)((vec[0] >> 16) & 0xFF),
 | 
				
			||||||
							(vec[0] >> 8) & 0xFF,
 | 
												(uint8_t)((vec[0] >> 8) & 0xFF),
 | 
				
			||||||
							 vec[0] & 0xFF,
 | 
												 (uint8_t)(vec[0] & 0xFF),
 | 
				
			||||||
						(vec[1] >> 24) & 0xFF,
 | 
											(uint8_t)((vec[1] >> 24) & 0xFF),
 | 
				
			||||||
						(vec[1] >> 16) & 0xFF,
 | 
											(uint8_t)((vec[1] >> 16) & 0xFF),
 | 
				
			||||||
						(vec[1] >> 8) & 0xFF,
 | 
											(uint8_t)((vec[1] >> 8) & 0xFF),
 | 
				
			||||||
						 vec[1] & 0xFF,
 | 
											 (uint8_t)(vec[1] & 0xFF),
 | 
				
			||||||
					(vec[2] >> 24) & 0xFF,
 | 
										 (uint8_t)((vec[2] >> 24) & 0xFF),
 | 
				
			||||||
					(vec[2] >> 16) & 0xFF,
 | 
										 (uint8_t)((vec[2] >> 16) & 0xFF),
 | 
				
			||||||
					(vec[2] >> 8) & 0xFF,
 | 
										(uint8_t)((vec[2] >> 8) & 0xFF),
 | 
				
			||||||
					 vec[2] & 0xFF};
 | 
										 (uint8_t)(vec[2] & 0xFF)};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	memcpy(*buf + sizeof(uint64_t) + 3, vec8, sizeof(uint32_t) * 3);
 | 
						memcpy(*buf + sizeof(uint64_t) * 2 + 2, vec8, sizeof(uint32_t) * 3);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	*buflen = sizeof(uint64_t) + 3 + sizeof(uint32_t) * 3;
 | 
						*buflen = sizeof(uint64_t) * 2 + 2 + sizeof(uint32_t) * 3;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void netprot::Serialize(Output* out, char* buf[], uint32_t* buflen) {
 | 
					void netprot::Serialize(Output* out, char* buf[], uint32_t* buflen) {
 | 
				
			||||||
 | 
						*buf[0] = (char)netprot::PACKET_TYPE::OUTPUT;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						uint64_t time = out->timestamp;
 | 
				
			||||||
 | 
						uint8_t time8[sizeof(uint64_t)] = { (uint8_t)((time >> 56) & 0xFF),
 | 
				
			||||||
 | 
														   (uint8_t)((time >> 48) & 0xFF),
 | 
				
			||||||
 | 
														   (uint8_t)((time >> 40) & 0xFF),
 | 
				
			||||||
 | 
														   (uint8_t)((time >> 32) & 0xFF),
 | 
				
			||||||
 | 
														   (uint8_t)((time >> 24) & 0xFF),
 | 
				
			||||||
 | 
														   (uint8_t)((time >> 16) & 0xFF),
 | 
				
			||||||
 | 
														   (uint8_t)((time >> 8) & 0xFF),
 | 
				
			||||||
 | 
															(uint8_t)(time & 0xFF) };
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						memcpy(*buf + 1, time8, sizeof(uint64_t));
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						uint64_t sid = out->id;
 | 
				
			||||||
 | 
						uint8_t sid8[sizeof(uint64_t)] = { (uint8_t)((sid >> 56) & 0xFF),
 | 
				
			||||||
 | 
														  (uint8_t)((sid >> 48) & 0xFF),
 | 
				
			||||||
 | 
														  (uint8_t)((sid >> 40) & 0xFF),
 | 
				
			||||||
 | 
														  (uint8_t)((sid >> 32) & 0xFF),
 | 
				
			||||||
 | 
														  (uint8_t)((sid >> 24) & 0xFF),
 | 
				
			||||||
 | 
														  (uint8_t)((sid >> 16) & 0xFF),
 | 
				
			||||||
 | 
														  (uint8_t)((sid >> 8) & 0xFF),
 | 
				
			||||||
 | 
														  (uint8_t)(sid & 0xFF) };
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						memcpy(*buf + sizeof(uint64_t) + 1, sid8, sizeof(uint64_t));
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						// TODO: Finir ca.
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void netprot::Serialize(Sync* sync, char* buf[], uint32_t* buflen) {
 | 
					void netprot::Serialize(Sync* sync, char* buf[], uint32_t* buflen) {
 | 
				
			||||||
 | 
						*buf[0] = (char)netprot::PACKET_TYPE::SYNC;
 | 
				
			||||||
 | 
						uint64_t time = sync->timestamp;
 | 
				
			||||||
 | 
						uint8_t stamp8[sizeof(uint64_t)] = { (uint8_t)((time >> 56) & 0xFF),
 | 
				
			||||||
 | 
														   (uint8_t)((time >> 48) & 0xFF),
 | 
				
			||||||
 | 
														   (uint8_t)((time >> 40) & 0xFF),
 | 
				
			||||||
 | 
														   (uint8_t)((time >> 32) & 0xFF),
 | 
				
			||||||
 | 
														   (uint8_t)((time >> 24) & 0xFF),
 | 
				
			||||||
 | 
														   (uint8_t)((time >> 16) & 0xFF),
 | 
				
			||||||
 | 
														   (uint8_t)((time >> 8) & 0xFF),
 | 
				
			||||||
 | 
															(uint8_t)(time & 0xFF) };
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						memcpy(*buf + 1, stamp8, sizeof(uint64_t));
 | 
				
			||||||
	
 | 
						
 | 
				
			||||||
 | 
						uint64_t sid = sync->sid;
 | 
				
			||||||
 | 
						uint8_t sid8[sizeof(uint64_t)] = { (uint8_t)((sid >> 56) & 0xFF),
 | 
				
			||||||
 | 
														  (uint8_t)((sid >> 48) & 0xFF),
 | 
				
			||||||
 | 
														  (uint8_t)((sid >> 40) & 0xFF),
 | 
				
			||||||
 | 
														  (uint8_t)((sid >> 32) & 0xFF),
 | 
				
			||||||
 | 
														  (uint8_t)((sid >> 24) & 0xFF),
 | 
				
			||||||
 | 
														  (uint8_t)((sid >> 16) & 0xFF),
 | 
				
			||||||
 | 
														  (uint8_t)((sid >> 8) & 0xFF),
 | 
				
			||||||
 | 
														  (uint8_t)(sid & 0xFF) };
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						memcpy(*buf + sizeof(uint64_t) + 1, sid8, sizeof(uint64_t));
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						uint32_t timer = sync->timer;
 | 
				
			||||||
 | 
						uint8_t time8[sizeof(uint32_t)] = {(uint8_t)((timer >> 24) & 0xFF),
 | 
				
			||||||
 | 
														   (uint8_t)((timer >> 16) & 0xFF),
 | 
				
			||||||
 | 
														   (uint8_t)((timer >> 8) & 0xFF),
 | 
				
			||||||
 | 
															(uint8_t)(timer & 0xFF) };
 | 
				
			||||||
 | 
						
 | 
				
			||||||
 | 
						memcpy(*buf + sizeof(uint64_t) * 2 + 1, time8, sizeof(uint32_t));
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						uint16_t ammo = sync->ammo;
 | 
				
			||||||
 | 
						uint8_t ammo8[sizeof(uint16_t)] = { (uint8_t)((ammo >> 8) & 0xFF),
 | 
				
			||||||
 | 
															(uint8_t)(ammo & 0xFF) };
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						memcpy(*buf + sizeof(uint64_t) * 2 + sizeof(uint32_t) + 1, ammo8, sizeof(uint16_t));
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						memcpy(*buf + sizeof(uint64_t) * 2 + sizeof(uint32_t) + sizeof(uint16_t) + 1, &sync->hp, sizeof(uint8_t));
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						uint32_t vec[3];
 | 
				
			||||||
 | 
						memcpy(vec, &sync->position, sizeof(Vector3f)); // Pour d<>naturer les floats.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						uint8_t vec8[3 * sizeof(uint32_t)] = {
 | 
				
			||||||
 | 
												(uint8_t)((vec[0] >> 24) & 0xFF),
 | 
				
			||||||
 | 
												(uint8_t)((vec[0] >> 16) & 0xFF),
 | 
				
			||||||
 | 
												(uint8_t)((vec[0] >> 8) & 0xFF),
 | 
				
			||||||
 | 
												 (uint8_t)(vec[0] & 0xFF),
 | 
				
			||||||
 | 
											(uint8_t)((vec[1] >> 24) & 0xFF),
 | 
				
			||||||
 | 
											(uint8_t)((vec[1] >> 16) & 0xFF),
 | 
				
			||||||
 | 
											(uint8_t)((vec[1] >> 8) & 0xFF),
 | 
				
			||||||
 | 
											 (uint8_t)(vec[1] & 0xFF),
 | 
				
			||||||
 | 
										 (uint8_t)((vec[2] >> 24) & 0xFF),
 | 
				
			||||||
 | 
										 (uint8_t)((vec[2] >> 16) & 0xFF),
 | 
				
			||||||
 | 
										(uint8_t)((vec[2] >> 8) & 0xFF),
 | 
				
			||||||
 | 
										 (uint8_t)(vec[2] & 0xFF) };
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						memcpy(*buf + sizeof(uint64_t) * 2 + sizeof(uint32_t) + sizeof(uint16_t) + 2, vec8, sizeof(uint32_t) * 3);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						*buflen = sizeof(uint64_t) * 2 + sizeof(uint32_t) * 4 + sizeof(uint16_t) + 2;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void netprot::Serialize(TeamInfo* tinfo, char* buf[], uint32_t* buflen) {
 | 
					void netprot::Serialize(TeamInfo* tinfo, char* buf[], uint32_t* buflen) {
 | 
				
			||||||
	*buf[0] = netprot::PACKET_TYPE::TEAMINF;
 | 
						*buf[0] = (char)netprot::PACKET_TYPE::TEAMINF;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	size_t namesize = std::strlen(tinfo->name) + 1;
 | 
						size_t namesize = std::strlen(tinfo->name) + 1;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	memcpy(*buf + 1, &tinfo->name, namesize);
 | 
						memcpy(*buf + 1, &tinfo->name, namesize);
 | 
				
			||||||
	uint64_t tid = tinfo->id;
 | 
						uint64_t tid = tinfo->id;
 | 
				
			||||||
	uint8_t tid8[sizeof(uint64_t)] = {
 | 
						uint8_t tid8[sizeof(uint64_t)] = {
 | 
				
			||||||
									   (tid >> 56) & 0xFF,
 | 
														   (uint8_t)((tid >> 56) & 0xFF),
 | 
				
			||||||
									   (tid >> 48) & 0xFF,
 | 
														   (uint8_t)((tid >> 48) & 0xFF),
 | 
				
			||||||
									   (tid >> 40) & 0xFF,
 | 
														   (uint8_t)((tid >> 40) & 0xFF),
 | 
				
			||||||
									   (tid >> 32) & 0xFF,
 | 
														   (uint8_t)((tid >> 32) & 0xFF),
 | 
				
			||||||
									   (tid >> 24) & 0xFF,
 | 
														   (uint8_t)((tid >> 24) & 0xFF),
 | 
				
			||||||
									   (tid >> 16) & 0xFF,
 | 
														   (uint8_t)((tid >> 16) & 0xFF),
 | 
				
			||||||
									   (tid >> 8) & 0xFF,
 | 
														   (uint8_t)((tid >> 8)  & 0xFF),
 | 
				
			||||||
									   tid & 0xFF
 | 
														    (uint8_t)(tid 		 & 0xFF)
 | 
				
			||||||
	};
 | 
						};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	memcpy(*buf + namesize + 2, tid8, sizeof(uint64_t));
 | 
						memcpy(*buf + namesize + 2, tid8, sizeof(uint64_t));
 | 
				
			||||||
@@ -93,35 +179,35 @@ void netprot::Serialize(TeamInfo* tinfo, char* buf[], uint32_t* buflen) {
 | 
				
			|||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void netprot::Serialize(LoginInfo* linfo, char* buf[], uint32_t* buflen) {
 | 
					void netprot::Serialize(LoginInfo* linfo, char* buf[], uint32_t* buflen) {
 | 
				
			||||||
	*buf[0] = netprot::PACKET_TYPE::LOGINF;
 | 
						*buf[0] = (char)netprot::PACKET_TYPE::LOGINF;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	size_t namesize = std::strlen(linfo->name) + 1;
 | 
						size_t namesize = std::strlen(linfo->name) + 1;
 | 
				
			||||||
	
 | 
						
 | 
				
			||||||
	memcpy(*buf + 1, &linfo->name, namesize);
 | 
						memcpy(*buf + 1, &linfo->name, namesize);
 | 
				
			||||||
	uint64_t sid = linfo->sid;
 | 
						uint64_t sid = linfo->sid;
 | 
				
			||||||
	uint8_t sid8[sizeof(uint64_t)] = { 
 | 
						uint8_t sid8[sizeof(uint64_t)] = { 
 | 
				
			||||||
									   (sid >> 56) & 0xFF,
 | 
														   (uint8_t)((sid >> 56) & 0xFF),
 | 
				
			||||||
									   (sid >> 48) & 0xFF,
 | 
														   (uint8_t)((sid >> 48) & 0xFF),
 | 
				
			||||||
									   (sid >> 40) & 0xFF,
 | 
														   (uint8_t)((sid >> 40) & 0xFF),
 | 
				
			||||||
									   (sid >> 32) & 0xFF,
 | 
														   (uint8_t)((sid >> 32) & 0xFF),
 | 
				
			||||||
									   (sid >> 24) & 0xFF,
 | 
														   (uint8_t)((sid >> 24) & 0xFF),
 | 
				
			||||||
									   (sid >> 16) & 0xFF,
 | 
														   (uint8_t)((sid >> 16) & 0xFF),
 | 
				
			||||||
									   (sid >> 8) & 0xFF,
 | 
														   (uint8_t)((sid >> 8)  & 0xFF),
 | 
				
			||||||
									   sid & 0xFF
 | 
														    (uint8_t)(sid 		 & 0xFF)
 | 
				
			||||||
	};
 | 
						};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	memcpy(*buf + namesize + 2, sid8, sizeof(uint64_t));
 | 
						memcpy(*buf + namesize + 2, sid8, sizeof(uint64_t));
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	uint64_t tid = linfo->tid;
 | 
						uint64_t tid = linfo->tid;
 | 
				
			||||||
	uint8_t tid8[sizeof(uint64_t)] = {
 | 
						uint8_t tid8[sizeof(uint64_t)] = {
 | 
				
			||||||
									   (tid >> 56) & 0xFF,
 | 
														   (uint8_t)((tid >> 56) & 0xFF),
 | 
				
			||||||
									   (tid >> 48) & 0xFF,
 | 
														   (uint8_t)((tid >> 48) & 0xFF),
 | 
				
			||||||
									   (tid >> 40) & 0xFF,
 | 
														   (uint8_t)((tid >> 40) & 0xFF),
 | 
				
			||||||
									   (tid >> 32) & 0xFF,
 | 
														   (uint8_t)((tid >> 32) & 0xFF),
 | 
				
			||||||
									   (tid >> 24) & 0xFF,
 | 
														   (uint8_t)((tid >> 24) & 0xFF),
 | 
				
			||||||
									   (tid >> 16) & 0xFF,
 | 
														   (uint8_t)((tid >> 16) & 0xFF),
 | 
				
			||||||
									   (tid >> 8) & 0xFF,
 | 
														   (uint8_t)((tid >> 8)  & 0xFF),
 | 
				
			||||||
									   tid & 0xFF
 | 
														   (uint8_t)(tid 		 & 0xFF)
 | 
				
			||||||
	};
 | 
						};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	memcpy(*buf + namesize + 2 + sizeof(uint64_t), tid8, sizeof(uint64_t));
 | 
						memcpy(*buf + namesize + 2 + sizeof(uint64_t), tid8, sizeof(uint64_t));
 | 
				
			||||||
@@ -130,35 +216,35 @@ void netprot::Serialize(LoginInfo* linfo, char* buf[], uint32_t* buflen) {
 | 
				
			|||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void netprot::Serialize(PlayerInfo* pinfo, char* buf[], uint32_t* buflen) {
 | 
					void netprot::Serialize(PlayerInfo* pinfo, char* buf[], uint32_t* buflen) {
 | 
				
			||||||
	*buf[0] = netprot::PACKET_TYPE::PLAYINF;
 | 
						*buf[0] = (char)netprot::PACKET_TYPE::PLAYINF;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	size_t namesize = std::strlen(pinfo->name) + 1;
 | 
						size_t namesize = std::strlen(pinfo->name) + 1;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	memcpy(*buf + 1, &pinfo->name, namesize);
 | 
						memcpy(*buf + 1, &pinfo->name, namesize);
 | 
				
			||||||
	uint64_t id = pinfo->id;
 | 
						uint64_t id = pinfo->id;
 | 
				
			||||||
	uint8_t id8[sizeof(uint64_t)] = {
 | 
						uint8_t id8[sizeof(uint64_t)] = {
 | 
				
			||||||
									   (id >> 56) & 0xFF,
 | 
														   (uint8_t)((id >> 56) & 0xFF),
 | 
				
			||||||
									   (id >> 48) & 0xFF,
 | 
														   (uint8_t)((id >> 48) & 0xFF),
 | 
				
			||||||
									   (id >> 40) & 0xFF,
 | 
														   (uint8_t)((id >> 40) & 0xFF),
 | 
				
			||||||
									   (id >> 32) & 0xFF,
 | 
														   (uint8_t)((id >> 32) & 0xFF),
 | 
				
			||||||
									   (id >> 24) & 0xFF,
 | 
														   (uint8_t)((id >> 24) & 0xFF),
 | 
				
			||||||
									   (id >> 16) & 0xFF,
 | 
														   (uint8_t)((id >> 16) & 0xFF),
 | 
				
			||||||
									   (id >> 8) & 0xFF,
 | 
														   (uint8_t)((id >> 8)  & 0xFF),
 | 
				
			||||||
									   id & 0xFF
 | 
														    (uint8_t)(id 		& 0xFF)
 | 
				
			||||||
	};
 | 
						};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	memcpy(*buf + namesize + 2, id8, sizeof(uint64_t));
 | 
						memcpy(*buf + namesize + 2, id8, sizeof(uint64_t));
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	uint64_t tid = pinfo->tid;
 | 
						uint64_t tid = pinfo->tid;
 | 
				
			||||||
	uint8_t tid8[sizeof(uint64_t)] = {
 | 
						uint8_t tid8[sizeof(uint64_t)] = {
 | 
				
			||||||
									   (tid >> 56) & 0xFF,
 | 
														   (uint8_t)((tid >> 56) & 0xFF),
 | 
				
			||||||
									   (tid >> 48) & 0xFF,
 | 
														   (uint8_t)((tid >> 48) & 0xFF),
 | 
				
			||||||
									   (tid >> 40) & 0xFF,
 | 
														   (uint8_t)((tid >> 40) & 0xFF),
 | 
				
			||||||
									   (tid >> 32) & 0xFF,
 | 
														   (uint8_t)((tid >> 32) & 0xFF),
 | 
				
			||||||
									   (tid >> 24) & 0xFF,
 | 
														   (uint8_t)((tid >> 24) & 0xFF),
 | 
				
			||||||
									   (tid >> 16) & 0xFF,
 | 
														   (uint8_t)((tid >> 16) & 0xFF),
 | 
				
			||||||
									   (tid >> 8) & 0xFF,
 | 
														   (uint8_t)((tid >> 8)  & 0xFF),
 | 
				
			||||||
									   tid & 0xFF 
 | 
														    (uint8_t)(tid 		 & 0xFF) 
 | 
				
			||||||
	};
 | 
						};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	memcpy(*buf + namesize + 2 + sizeof(uint64_t), tid8, sizeof(uint64_t));
 | 
						memcpy(*buf + namesize + 2 + sizeof(uint64_t), tid8, sizeof(uint64_t));
 | 
				
			||||||
@@ -167,46 +253,46 @@ void netprot::Serialize(PlayerInfo* pinfo, char* buf[], uint32_t* buflen) {
 | 
				
			|||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void netprot::Serialize(GameInfo* ginfo, char* buf[], uint32_t* buflen) {
 | 
					void netprot::Serialize(GameInfo* ginfo, char* buf[], uint32_t* buflen) {
 | 
				
			||||||
	*buf[0] = netprot::PACKET_TYPE::GAMEINFO;
 | 
						*buf[0] = (char)netprot::PACKET_TYPE::GAMEINFO;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	uint64_t game = ginfo->seed;
 | 
						uint64_t game = ginfo->seed;
 | 
				
			||||||
	uint8_t seed8[sizeof(uint64_t)] = {
 | 
						uint8_t seed8[sizeof(uint64_t)] = {
 | 
				
			||||||
									   (game >> 56) & 0xFF,
 | 
														   (uint8_t)((game >> 56) & 0xFF),
 | 
				
			||||||
									   (game >> 48) & 0xFF,
 | 
														   (uint8_t)((game >> 48) & 0xFF),
 | 
				
			||||||
									   (game >> 40) & 0xFF,
 | 
														   (uint8_t)((game >> 40) & 0xFF),
 | 
				
			||||||
									   (game >> 32) & 0xFF,
 | 
														   (uint8_t)((game >> 32) & 0xFF),
 | 
				
			||||||
									   (game >> 24) & 0xFF,
 | 
														   (uint8_t)((game >> 24) & 0xFF),
 | 
				
			||||||
									   (game >> 16) & 0xFF,
 | 
														   (uint8_t)((game >> 16) & 0xFF),
 | 
				
			||||||
									   (game >> 8) & 0xFF,
 | 
														   (uint8_t)((game >> 8)  & 0xFF),
 | 
				
			||||||
									   game & 0xFF
 | 
														    (uint8_t)(game 		  & 0xFF)
 | 
				
			||||||
	};
 | 
						};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	memcpy(*buf + 1, seed8, sizeof(uint64_t));
 | 
						memcpy(*buf + 1, seed8, sizeof(uint64_t));
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	game = ginfo->countdown;
 | 
						game = ginfo->countdown;
 | 
				
			||||||
	uint8_t count8[sizeof(uint64_t)] = {
 | 
						uint8_t count8[sizeof(uint64_t)] = {
 | 
				
			||||||
									   (game >> 56) & 0xFF,
 | 
															(uint8_t)((game >> 56) & 0xFF),
 | 
				
			||||||
									   (game >> 48) & 0xFF,
 | 
														    (uint8_t)((game >> 48) & 0xFF),
 | 
				
			||||||
									   (game >> 40) & 0xFF,
 | 
														    (uint8_t)((game >> 40) & 0xFF),
 | 
				
			||||||
									   (game >> 32) & 0xFF,
 | 
														    (uint8_t)((game >> 32) & 0xFF),
 | 
				
			||||||
									   (game >> 24) & 0xFF,
 | 
														    (uint8_t)((game >> 24) & 0xFF),
 | 
				
			||||||
									   (game >> 16) & 0xFF,
 | 
														    (uint8_t)((game >> 16) & 0xFF),
 | 
				
			||||||
									   (game >> 8) & 0xFF,
 | 
															(uint8_t)((game >> 8)  & 0xFF),
 | 
				
			||||||
									   game & 0xFF
 | 
														     (uint8_t)(game 	   & 0xFF)
 | 
				
			||||||
	};
 | 
						};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	memcpy(*buf + sizeof(uint64_t) + 1, count8, sizeof(uint64_t));
 | 
						memcpy(*buf + sizeof(uint64_t) + 1, count8, sizeof(uint64_t));
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	game = ginfo->countdown;
 | 
						game = ginfo->countdown;
 | 
				
			||||||
	uint8_t gtype8[sizeof(uint64_t)] = {
 | 
						uint8_t gtype8[sizeof(uint64_t)] = {
 | 
				
			||||||
									   (game >> 56) & 0xFF,
 | 
														     (uint8_t)((game >> 56) & 0xFF),
 | 
				
			||||||
									   (game >> 48) & 0xFF,
 | 
														   (uint8_t)((game >> 48) & 0xFF),
 | 
				
			||||||
									   (game >> 40) & 0xFF,
 | 
														   (uint8_t)((game >> 40) & 0xFF),
 | 
				
			||||||
									   (game >> 32) & 0xFF,
 | 
														   (uint8_t)((game >> 32) & 0xFF),
 | 
				
			||||||
									   (game >> 24) & 0xFF,
 | 
														   (uint8_t)((game >> 24) & 0xFF),
 | 
				
			||||||
									   (game >> 16) & 0xFF,
 | 
														   (uint8_t)((game >> 16) & 0xFF),
 | 
				
			||||||
									   (game >> 8) & 0xFF,
 | 
														   (uint8_t)((game >> 8)  & 0xFF),
 | 
				
			||||||
									   game & 0xFF
 | 
														    (uint8_t)(game 		  & 0xFF)
 | 
				
			||||||
	};
 | 
						};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	memcpy(*buf + sizeof(uint64_t) + 1, gtype8, sizeof(uint64_t));
 | 
						memcpy(*buf + sizeof(uint64_t) + 1, gtype8, sizeof(uint64_t));
 | 
				
			||||||
@@ -215,46 +301,46 @@ void netprot::Serialize(GameInfo* ginfo, char* buf[], uint32_t* buflen) {
 | 
				
			|||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void netprot::Serialize(Chat* chat, char* buf[], uint32_t* buflen) {
 | 
					void netprot::Serialize(Chat* chat, char* buf[], uint32_t* buflen) {
 | 
				
			||||||
	*buf[0] = netprot::PACKET_TYPE::CHAT;
 | 
						*buf[0] = (char)netprot::PACKET_TYPE::CHAT;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	uint64_t src = chat->src_id;
 | 
						uint64_t src = chat->src_id;
 | 
				
			||||||
	uint8_t src8[sizeof(uint64_t)] = {
 | 
						uint8_t src8[sizeof(uint64_t)] = {
 | 
				
			||||||
									   (src >> 56) & 0xFF,
 | 
														   (uint8_t)((src >> 56) & 0xFF),
 | 
				
			||||||
									   (src >> 48) & 0xFF,
 | 
														   (uint8_t)((src >> 48) & 0xFF),
 | 
				
			||||||
									   (src >> 40) & 0xFF,
 | 
														   (uint8_t)((src >> 40) & 0xFF),
 | 
				
			||||||
									   (src >> 32) & 0xFF,
 | 
														   (uint8_t)((src >> 32) & 0xFF),
 | 
				
			||||||
									   (src >> 24) & 0xFF,
 | 
														   (uint8_t)((src >> 24) & 0xFF),
 | 
				
			||||||
									   (src >> 16) & 0xFF,
 | 
														   (uint8_t)((src >> 16) & 0xFF),
 | 
				
			||||||
									   (src >> 8) & 0xFF,
 | 
														   (uint8_t)((src >> 8)  & 0xFF),
 | 
				
			||||||
									   src & 0xFF
 | 
														    (uint8_t)(src 		 & 0xFF)
 | 
				
			||||||
	};
 | 
						};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	memcpy(*buf + 1, src8, sizeof(uint64_t));
 | 
						memcpy(*buf + 1, src8, sizeof(uint64_t));
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	uint64_t dst = chat->dest_id;
 | 
						uint64_t dst = chat->dest_id;
 | 
				
			||||||
	uint8_t dst8[sizeof(uint64_t)] = {
 | 
						uint8_t dst8[sizeof(uint64_t)] = {
 | 
				
			||||||
									   (dst >> 56) & 0xFF,
 | 
														   (uint8_t)((dst >> 56) & 0xFF),
 | 
				
			||||||
									   (dst >> 48) & 0xFF,
 | 
														   (uint8_t)((dst >> 48) & 0xFF),
 | 
				
			||||||
									   (dst >> 40) & 0xFF,
 | 
														   (uint8_t)((dst >> 40) & 0xFF),
 | 
				
			||||||
									   (dst >> 32) & 0xFF,
 | 
														   (uint8_t)((dst >> 32) & 0xFF),
 | 
				
			||||||
									   (dst >> 24) & 0xFF,
 | 
														   (uint8_t)((dst >> 24) & 0xFF),
 | 
				
			||||||
									   (dst >> 16) & 0xFF,
 | 
														   (uint8_t)((dst >> 16) & 0xFF),
 | 
				
			||||||
									   (dst >> 8) & 0xFF,
 | 
														   (uint8_t)((dst >> 8)  & 0xFF),
 | 
				
			||||||
									   dst & 0xFF
 | 
														    (uint8_t)(dst 		 & 0xFF)
 | 
				
			||||||
	};
 | 
						};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	memcpy(*buf + 1 + sizeof(uint64_t), dst8, sizeof(uint64_t));
 | 
						memcpy(*buf + 1 + sizeof(uint64_t), dst8, sizeof(uint64_t));
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	uint64_t dstteam = chat->dest_id;
 | 
						uint64_t dstteam = chat->dest_id;
 | 
				
			||||||
	uint8_t dstt8[sizeof(uint64_t)] = {
 | 
						uint8_t dstt8[sizeof(uint64_t)] = {
 | 
				
			||||||
									   (dstteam >> 56) & 0xFF,
 | 
														   (uint8_t)((dstteam >> 56) & 0xFF),
 | 
				
			||||||
									   (dstteam >> 48) & 0xFF,
 | 
														   (uint8_t)((dstteam >> 48) & 0xFF),
 | 
				
			||||||
									   (dstteam >> 40) & 0xFF,
 | 
														   (uint8_t)((dstteam >> 40) & 0xFF),
 | 
				
			||||||
									   (dstteam >> 32) & 0xFF,
 | 
														   (uint8_t)((dstteam >> 32) & 0xFF),
 | 
				
			||||||
									   (dstteam >> 24) & 0xFF,
 | 
														   (uint8_t)((dstteam >> 24) & 0xFF),
 | 
				
			||||||
									   (dstteam >> 16) & 0xFF,
 | 
														   (uint8_t)((dstteam >> 16) & 0xFF),
 | 
				
			||||||
									   (dstteam >> 8) & 0xFF,
 | 
														   (uint8_t)((dstteam >> 8)  & 0xFF),
 | 
				
			||||||
									   dstteam & 0xFF
 | 
														    (uint8_t)(dstteam 		 & 0xFF)
 | 
				
			||||||
	};
 | 
						};
 | 
				
			||||||
	
 | 
						
 | 
				
			||||||
	memcpy(*buf + 1 + sizeof(uint64_t) * 2, dstt8, sizeof(uint64_t));
 | 
						memcpy(*buf + 1 + sizeof(uint64_t) * 2, dstt8, sizeof(uint64_t));
 | 
				
			||||||
@@ -267,7 +353,7 @@ void netprot::Serialize(Chat* chat, char* buf[], uint32_t* buflen) {
 | 
				
			|||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void netprot::Serialize(ErrorLog* errlog, char* buf[], uint32_t* buflen) {
 | 
					void netprot::Serialize(ErrorLog* errlog, char* buf[], uint32_t* buflen) {
 | 
				
			||||||
	*buf[0] = netprot::PACKET_TYPE::ERRLOG;
 | 
						*buf[0] = (char)netprot::PACKET_TYPE::ERRLOG;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	size_t messize = std::strlen(errlog->mess) + 1;
 | 
						size_t messize = std::strlen(errlog->mess) + 1;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -281,7 +367,61 @@ void netprot::Serialize(ErrorLog* errlog, char* buf[], uint32_t* buflen) {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
bool netprot::Deserialize(Input* in, char* buf, const uint32_t buflen) {
 | 
					bool netprot::Deserialize(Input* in, char* buf, const uint32_t buflen) {
 | 
				
			||||||
	return false;
 | 
						if (buflen <= sizeof(Input))
 | 
				
			||||||
 | 
							return false;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						uint8_t diff[sizeof(uint64_t)] = { 0,0,0,0,0,0,0,0 };
 | 
				
			||||||
 | 
						memcpy(diff, &buf[1], sizeof(uint64_t));
 | 
				
			||||||
 | 
						in->timestamp =
 | 
				
			||||||
 | 
							(uint64_t)diff[0] << 56 |
 | 
				
			||||||
 | 
							(uint64_t)diff[1] << 48 |
 | 
				
			||||||
 | 
							(uint64_t)diff[2] << 40 |
 | 
				
			||||||
 | 
							(uint64_t)diff[3] << 32 |
 | 
				
			||||||
 | 
							(uint64_t)diff[4] << 24 |
 | 
				
			||||||
 | 
							(uint64_t)diff[5] << 16 |
 | 
				
			||||||
 | 
							(uint64_t)diff[6] << 8 |
 | 
				
			||||||
 | 
							(uint64_t)diff[7];
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						memcpy(diff, &buf[1 + sizeof(uint64_t)], sizeof(uint64_t));
 | 
				
			||||||
 | 
						in->sid =
 | 
				
			||||||
 | 
							(uint64_t)diff[0] << 56 |
 | 
				
			||||||
 | 
							(uint64_t)diff[1] << 48 |
 | 
				
			||||||
 | 
							(uint64_t)diff[2] << 40 |
 | 
				
			||||||
 | 
							(uint64_t)diff[3] << 32 |
 | 
				
			||||||
 | 
							(uint64_t)diff[4] << 24 |
 | 
				
			||||||
 | 
							(uint64_t)diff[5] << 16 |
 | 
				
			||||||
 | 
							(uint64_t)diff[6] << 8 |
 | 
				
			||||||
 | 
							(uint64_t)diff[7];
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						uint8_t keys = 0;
 | 
				
			||||||
 | 
						memcpy(&keys, &buf[1 + sizeof(uint64_t) * 2], sizeof(uint8_t));
 | 
				
			||||||
 | 
						in->keys.forward	= keys & 0b10000000;
 | 
				
			||||||
 | 
						in->keys.backward	= keys & 0b01000000;
 | 
				
			||||||
 | 
						in->keys.left		= keys & 0b00100000;
 | 
				
			||||||
 | 
						in->keys.right		= keys & 0b00010000;
 | 
				
			||||||
 | 
						in->keys.jump		= keys & 0b00001000;
 | 
				
			||||||
 | 
						in->keys.shoot		= keys & 0b00000100;
 | 
				
			||||||
 | 
						in->keys.block		= keys & 0b00000010;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						uint8_t subvec[3 * sizeof(uint32_t)] = { 0,0,0,0,0,0,0,0,0,0,0,0 };
 | 
				
			||||||
 | 
						memcpy(subvec, &buf[2 + sizeof(uint64_t) * 2], sizeof(uint8_t) * 12);
 | 
				
			||||||
 | 
						uint32_t vec[3] = {
 | 
				
			||||||
 | 
							(uint32_t)subvec[0] << 24 |
 | 
				
			||||||
 | 
							(uint32_t)subvec[1] << 16 |
 | 
				
			||||||
 | 
							(uint32_t)subvec[2] << 8 |
 | 
				
			||||||
 | 
							(uint32_t)subvec[3],
 | 
				
			||||||
 | 
								(uint32_t)subvec[4] << 24 |
 | 
				
			||||||
 | 
								(uint32_t)subvec[5] << 16 |
 | 
				
			||||||
 | 
								(uint32_t)subvec[6] << 8 |
 | 
				
			||||||
 | 
								(uint32_t)subvec[7],
 | 
				
			||||||
 | 
									(uint32_t)subvec[8] << 24 |
 | 
				
			||||||
 | 
									(uint32_t)subvec[9] << 16 |
 | 
				
			||||||
 | 
									(uint32_t)subvec[10] << 8 |
 | 
				
			||||||
 | 
									(uint32_t)subvec[11]};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						memcpy(&in->direction, vec, sizeof(uint32_t) * 3);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						return true;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
bool netprot::Deserialize(Output* out, char* buf, const uint32_t buflen) {
 | 
					bool netprot::Deserialize(Output* out, char* buf, const uint32_t buflen) {
 | 
				
			||||||
@@ -289,7 +429,65 @@ bool netprot::Deserialize(Output* out, char* buf, const uint32_t buflen) {
 | 
				
			|||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
bool netprot::Deserialize(Sync* sync, char* buf, const uint32_t buflen) {
 | 
					bool netprot::Deserialize(Sync* sync, char* buf, const uint32_t buflen) {
 | 
				
			||||||
	return false;
 | 
						if (buflen <= sizeof(Sync))
 | 
				
			||||||
 | 
							return false;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						uint8_t diff[sizeof(uint64_t)] = { 0,0,0,0,0,0,0,0 };
 | 
				
			||||||
 | 
						memcpy(diff, &buf[1], sizeof(uint64_t));
 | 
				
			||||||
 | 
						sync->timestamp =
 | 
				
			||||||
 | 
							(uint64_t)diff[0] << 56 |
 | 
				
			||||||
 | 
							(uint64_t)diff[1] << 48 |
 | 
				
			||||||
 | 
							(uint64_t)diff[2] << 40 |
 | 
				
			||||||
 | 
							(uint64_t)diff[3] << 32 |
 | 
				
			||||||
 | 
							(uint64_t)diff[4] << 24 |
 | 
				
			||||||
 | 
							(uint64_t)diff[5] << 16 |
 | 
				
			||||||
 | 
							(uint64_t)diff[6] << 8 |
 | 
				
			||||||
 | 
							(uint64_t)diff[7];
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						memcpy(diff, &buf[1 + sizeof(uint64_t)], sizeof(uint64_t));
 | 
				
			||||||
 | 
						sync->sid =
 | 
				
			||||||
 | 
							(uint64_t)diff[0] << 56 |
 | 
				
			||||||
 | 
							(uint64_t)diff[1] << 48 |
 | 
				
			||||||
 | 
							(uint64_t)diff[2] << 40 |
 | 
				
			||||||
 | 
							(uint64_t)diff[3] << 32 |
 | 
				
			||||||
 | 
							(uint64_t)diff[4] << 24 |
 | 
				
			||||||
 | 
							(uint64_t)diff[5] << 16 |
 | 
				
			||||||
 | 
							(uint64_t)diff[6] << 8 |
 | 
				
			||||||
 | 
							(uint64_t)diff[7];
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						memcpy(diff, &buf[1 + sizeof(uint64_t) * 2], sizeof(uint32_t));
 | 
				
			||||||
 | 
						sync->timer =
 | 
				
			||||||
 | 
							(uint32_t)diff[0] << 24 |
 | 
				
			||||||
 | 
							(uint32_t)diff[1] << 16 |
 | 
				
			||||||
 | 
							(uint32_t)diff[2] << 8 |
 | 
				
			||||||
 | 
							(uint32_t)diff[3];
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						memcpy(diff, &buf[1 + sizeof(uint64_t) * 2 + sizeof(uint32_t)], sizeof(uint16_t));
 | 
				
			||||||
 | 
						sync->ammo =
 | 
				
			||||||
 | 
							(uint16_t)diff[0] << 8 |
 | 
				
			||||||
 | 
							(uint16_t)diff[1];
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						memcpy(&sync->hp, &buf[1 + sizeof(uint64_t) * 2 + sizeof(uint32_t) + sizeof(uint16_t)], sizeof(uint8_t));
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						uint8_t subvec[3 * sizeof(uint32_t)] = { 0,0,0,0,0,0,0,0,0,0,0,0 };
 | 
				
			||||||
 | 
						memcpy(subvec, &buf[2 + sizeof(uint64_t) * 2 + sizeof(uint32_t) + sizeof(uint16_t)], sizeof(uint8_t) * 12);
 | 
				
			||||||
 | 
						uint32_t vec[3] = {
 | 
				
			||||||
 | 
							(uint32_t)subvec[0] << 24 |
 | 
				
			||||||
 | 
							(uint32_t)subvec[1] << 16 |
 | 
				
			||||||
 | 
							(uint32_t)subvec[2] << 8 |
 | 
				
			||||||
 | 
							(uint32_t)subvec[3],
 | 
				
			||||||
 | 
								(uint32_t)subvec[4] << 24 |
 | 
				
			||||||
 | 
								(uint32_t)subvec[5] << 16 |
 | 
				
			||||||
 | 
								(uint32_t)subvec[6] << 8 |
 | 
				
			||||||
 | 
								(uint32_t)subvec[7],
 | 
				
			||||||
 | 
									(uint32_t)subvec[8] << 24 |
 | 
				
			||||||
 | 
									(uint32_t)subvec[9] << 16 |
 | 
				
			||||||
 | 
									(uint32_t)subvec[10] << 8 |
 | 
				
			||||||
 | 
									(uint32_t)subvec[11] };
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						memcpy(&sync->position, vec, sizeof(uint32_t) * 3);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						return true;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
bool netprot::Deserialize(TeamInfo* tinfo, char* buf, const uint32_t buflen) {
 | 
					bool netprot::Deserialize(TeamInfo* tinfo, char* buf, const uint32_t buflen) {
 | 
				
			||||||
@@ -497,10 +695,246 @@ bool netprot::Deserialize(ErrorLog* errlog, char* buf, const uint32_t buflen) {
 | 
				
			|||||||
	return true;
 | 
						return true;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
netprot::PacketType netprot::getType(char* buf, const uint32_t buflen) {
 | 
					netprot::PACKET_TYPE netprot::getType(char* buf, const uint32_t buflen) {
 | 
				
			||||||
	if (buflen < 1 || 
 | 
						if (buflen < 1 || 
 | 
				
			||||||
		buf[0] >= netprot::PACKET_TYPE::LAST_PACK || 
 | 
							buf[0] >= (char)netprot::PACKET_TYPE::LAST_PACK || 
 | 
				
			||||||
		buf[0] <= netprot::PACKET_TYPE::ERR)
 | 
							buf[0] <= (char)netprot::PACKET_TYPE::ERR)
 | 
				
			||||||
		return netprot::PACKET_TYPE::ERR;
 | 
							return netprot::PACKET_TYPE::ERR;
 | 
				
			||||||
	return buf[0];
 | 
						return (netprot::PACKET_TYPE)buf[0];
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					netprot::Packet netprot::getPack(char* buf, uint32_t buflen) {
 | 
				
			||||||
 | 
						Packet pck = { nullptr, PACKET_TYPE::ERR };
 | 
				
			||||||
 | 
						Input* in = nullptr;
 | 
				
			||||||
 | 
						Output* out = nullptr;
 | 
				
			||||||
 | 
						Sync* sync = nullptr;
 | 
				
			||||||
 | 
						Chat* chat = nullptr;
 | 
				
			||||||
 | 
						GameInfo* ginfo = nullptr;
 | 
				
			||||||
 | 
						ErrorLog* errlog = nullptr;
 | 
				
			||||||
 | 
						LoginInfo* loginf = nullptr;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						switch (getType(buf, buflen)) {
 | 
				
			||||||
 | 
						case PACKET_TYPE::INPUT:
 | 
				
			||||||
 | 
							in = new Input();
 | 
				
			||||||
 | 
							if (netprot::Deserialize(in, buf, buflen)) {
 | 
				
			||||||
 | 
								pck.type = PACKET_TYPE::INPUT;
 | 
				
			||||||
 | 
								pck.ptr = (void*)in;
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							break;
 | 
				
			||||||
 | 
						case PACKET_TYPE::OUTPUT:
 | 
				
			||||||
 | 
							out = new Output();
 | 
				
			||||||
 | 
							if (netprot::Deserialize(out, buf, buflen)) {
 | 
				
			||||||
 | 
								pck.type = PACKET_TYPE::OUTPUT;
 | 
				
			||||||
 | 
								pck.ptr = (void*)out;
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							break;
 | 
				
			||||||
 | 
						case PACKET_TYPE::SYNC:
 | 
				
			||||||
 | 
							sync = new Sync();
 | 
				
			||||||
 | 
							if (netprot::Deserialize(sync, buf, buflen)) {
 | 
				
			||||||
 | 
								pck.type = PACKET_TYPE::SYNC;
 | 
				
			||||||
 | 
								pck.ptr = (void*)sync;
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							break;
 | 
				
			||||||
 | 
						case PACKET_TYPE::CHAT:
 | 
				
			||||||
 | 
							chat = new Chat();
 | 
				
			||||||
 | 
							if (netprot::Deserialize(chat, buf, buflen)) {
 | 
				
			||||||
 | 
								pck.type = PACKET_TYPE::CHAT;
 | 
				
			||||||
 | 
								pck.ptr = (void*)chat;
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							break;
 | 
				
			||||||
 | 
						case PACKET_TYPE::GAMEINFO:
 | 
				
			||||||
 | 
							ginfo = new GameInfo();
 | 
				
			||||||
 | 
							if (netprot::Deserialize(ginfo, buf, buflen)) {
 | 
				
			||||||
 | 
								pck.type = PACKET_TYPE::GAMEINFO;
 | 
				
			||||||
 | 
								pck.ptr = (void*)ginfo;
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							break;
 | 
				
			||||||
 | 
						case PACKET_TYPE::ERRLOG:
 | 
				
			||||||
 | 
							errlog = new ErrorLog();
 | 
				
			||||||
 | 
							if (netprot::Deserialize(errlog, buf, buflen)) {
 | 
				
			||||||
 | 
								pck.type = PACKET_TYPE::ERRLOG;
 | 
				
			||||||
 | 
								pck.ptr = (void*)errlog;
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							break;
 | 
				
			||||||
 | 
						case PACKET_TYPE::LOGINF:
 | 
				
			||||||
 | 
							loginf = new LoginInfo();
 | 
				
			||||||
 | 
							if (netprot::Deserialize(loginf, buf, buflen)) {
 | 
				
			||||||
 | 
								pck.type = PACKET_TYPE::LOGINF;
 | 
				
			||||||
 | 
								pck.ptr = (void*)loginf;
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							break;
 | 
				
			||||||
 | 
						default:
 | 
				
			||||||
 | 
							break;
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						return pck;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					netprot::Packet netprot::getPack(netprot::Buffer* buf) { 
 | 
				
			||||||
 | 
						return netprot::getPack(buf->ptr, buf->len); 
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					bool netprot::emptyPack(netprot::Packet pck) {
 | 
				
			||||||
 | 
						switch (pck.type) {
 | 
				
			||||||
 | 
						case PACKET_TYPE::INPUT:
 | 
				
			||||||
 | 
							delete (Input*)pck.ptr;
 | 
				
			||||||
 | 
							return true;
 | 
				
			||||||
 | 
						case PACKET_TYPE::OUTPUT:
 | 
				
			||||||
 | 
							delete (Output*)pck.ptr;
 | 
				
			||||||
 | 
							return true;
 | 
				
			||||||
 | 
						case PACKET_TYPE::SYNC:
 | 
				
			||||||
 | 
							delete (Sync*)pck.ptr;
 | 
				
			||||||
 | 
							return true;
 | 
				
			||||||
 | 
						case PACKET_TYPE::CHAT:
 | 
				
			||||||
 | 
							delete (Chat*)pck.ptr;
 | 
				
			||||||
 | 
							return true;
 | 
				
			||||||
 | 
						case PACKET_TYPE::GAMEINFO:
 | 
				
			||||||
 | 
							delete (GameInfo*)pck.ptr;
 | 
				
			||||||
 | 
							return true;
 | 
				
			||||||
 | 
						case PACKET_TYPE::ERRLOG:
 | 
				
			||||||
 | 
							delete (ErrorLog*)pck.ptr;
 | 
				
			||||||
 | 
							return true;
 | 
				
			||||||
 | 
						case PACKET_TYPE::LOGINF:
 | 
				
			||||||
 | 
							delete (LoginInfo*)pck.ptr;
 | 
				
			||||||
 | 
							return true;
 | 
				
			||||||
 | 
						default:
 | 
				
			||||||
 | 
							return false;
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					netprot::Packet netprot::makePack(void* ptr, PACKET_TYPE type) {
 | 
				
			||||||
 | 
						Packet pck;
 | 
				
			||||||
 | 
						pck.ptr = ptr;
 | 
				
			||||||
 | 
						pck.type = type;
 | 
				
			||||||
 | 
						return pck;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					std::vector<netprot::Packet> netprot::recvPacks(SOCKET sock, Buffer* buf) {
 | 
				
			||||||
 | 
						std::vector<Packet> lsPck;
 | 
				
			||||||
 | 
						int len = 0, end = 0;
 | 
				
			||||||
 | 
						bool pck_received = false;
 | 
				
			||||||
 | 
						char* cursor = nullptr;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						while (true) {
 | 
				
			||||||
 | 
							while (!pck_received) {
 | 
				
			||||||
 | 
								int bytes = recv(sock, &buf->ptr[len], buf->len - len, 0);
 | 
				
			||||||
 | 
								if (bytes < 0) // si recv() retourne -1; ça veut dire qu'il y a plus rien a lire.
 | 
				
			||||||
 | 
									return lsPck;
 | 
				
			||||||
 | 
								len += bytes;
 | 
				
			||||||
 | 
								// TODO: Voir si on trouve un footer (5 '\0' d'affilee).
 | 
				
			||||||
 | 
								//		 Si oui, mettre l'index du debut du footer dans 
 | 
				
			||||||
 | 
								//		 la variable "end" et mettre pck_received a true.
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							cursor = &buf->ptr[end];
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							lsPck.push_back(getPack(buf));
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							while (*cursor == '\0') {
 | 
				
			||||||
 | 
								cursor++;
 | 
				
			||||||
 | 
								end++;
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							if (cursor) { // mettre le début du prochain paquet au début du buffer.
 | 
				
			||||||
 | 
								memcpy(buf->ptr, cursor, buf->len - end); // et voir s'il y a en un autre
 | 
				
			||||||
 | 
								len = 0;
 | 
				
			||||||
 | 
								pck_received = true;
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					template <>
 | 
				
			||||||
 | 
					void netprot::sendPack<netprot::Packet>(SOCKET sock, Packet* pack, char** buf, uint32_t* buflen) {
 | 
				
			||||||
 | 
						switch (pack->type) {
 | 
				
			||||||
 | 
					        case PACKET_TYPE::INPUT:
 | 
				
			||||||
 | 
								sendPack<Input>(sock, (Input*)pack->ptr, buf, buflen);
 | 
				
			||||||
 | 
								return;
 | 
				
			||||||
 | 
					        case PACKET_TYPE::OUTPUT:
 | 
				
			||||||
 | 
								sendPack<Output>(sock, (Output*)pack->ptr, buf, buflen);
 | 
				
			||||||
 | 
								return;
 | 
				
			||||||
 | 
							case PACKET_TYPE::SYNC:
 | 
				
			||||||
 | 
								sendPack<Sync>(sock, (Sync*)pack->ptr, buf, buflen);
 | 
				
			||||||
 | 
								return;
 | 
				
			||||||
 | 
							case PACKET_TYPE::TEAMINF:
 | 
				
			||||||
 | 
								sendPack<TeamInfo>(sock, (TeamInfo*)pack->ptr, buf, buflen);
 | 
				
			||||||
 | 
								return;
 | 
				
			||||||
 | 
							case PACKET_TYPE::PLAYINF:
 | 
				
			||||||
 | 
								sendPack<PlayerInfo>(sock, (PlayerInfo*)pack->ptr, buf, buflen);
 | 
				
			||||||
 | 
								return;
 | 
				
			||||||
 | 
							case PACKET_TYPE::LOGINF:
 | 
				
			||||||
 | 
								sendPack<LoginInfo>(sock, (LoginInfo*)pack->ptr, buf, buflen);
 | 
				
			||||||
 | 
								return;
 | 
				
			||||||
 | 
							case PACKET_TYPE::CHUNKMOD:
 | 
				
			||||||
 | 
								//sendPack<ChunkMod>(sock, (ChunkMod*)pack->ptr, buf, buflen);
 | 
				
			||||||
 | 
							case PACKET_TYPE::PLAYERMOD:
 | 
				
			||||||
 | 
								//sendPack<PlayerMod>(sock, (PlayerMod*)pack->ptr, buf, buflen);
 | 
				
			||||||
 | 
								return;
 | 
				
			||||||
 | 
							case PACKET_TYPE::PICKUPMOD:
 | 
				
			||||||
 | 
								//sendPack<PickupMod>(sock, (PickupMod*)pack->ptr, buf, buflen);
 | 
				
			||||||
 | 
								return;
 | 
				
			||||||
 | 
							case PACKET_TYPE::GAMEINFO:
 | 
				
			||||||
 | 
								sendPack<GameInfo>(sock, (GameInfo*)pack->ptr, buf, buflen);
 | 
				
			||||||
 | 
								return;
 | 
				
			||||||
 | 
							case PACKET_TYPE::ENDINFO:
 | 
				
			||||||
 | 
								//sendPack<EndInfo>(sock, (EndInfo*)pack->ptr, buf, buflen);
 | 
				
			||||||
 | 
								return;
 | 
				
			||||||
 | 
							case PACKET_TYPE::CHAT:
 | 
				
			||||||
 | 
								sendPack<Chat>(sock, (Chat*)pack->ptr, buf, buflen);
 | 
				
			||||||
 | 
								return;
 | 
				
			||||||
 | 
							case PACKET_TYPE::ERRLOG:
 | 
				
			||||||
 | 
								sendPack<ErrorLog>(sock, (ErrorLog*)pack->ptr, buf, buflen);
 | 
				
			||||||
 | 
								return;
 | 
				
			||||||
 | 
							case PACKET_TYPE::LAST_PACK: [[fallthrough]];
 | 
				
			||||||
 | 
					        case PACKET_TYPE::ERR: [[fallthrough]];
 | 
				
			||||||
 | 
							default:
 | 
				
			||||||
 | 
								return;
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					template <>
 | 
				
			||||||
 | 
					void netprot::sendPackTo<netprot::Packet>(SOCKET sock, Packet* pack, char** buf, uint32_t* buflen, sockaddr_in* sockad) {
 | 
				
			||||||
 | 
						switch (pack->type) {
 | 
				
			||||||
 | 
					        case PACKET_TYPE::INPUT:
 | 
				
			||||||
 | 
								sendPackTo<Input>(sock, (Input*)pack->ptr, buf, buflen, sockad);
 | 
				
			||||||
 | 
								return;
 | 
				
			||||||
 | 
					        case PACKET_TYPE::OUTPUT:
 | 
				
			||||||
 | 
								sendPackTo<Output>(sock, (Output*)pack->ptr, buf, buflen, sockad);
 | 
				
			||||||
 | 
								return;
 | 
				
			||||||
 | 
							case PACKET_TYPE::SYNC:
 | 
				
			||||||
 | 
								sendPackTo<Sync>(sock, (Sync*)pack->ptr, buf, buflen, sockad);
 | 
				
			||||||
 | 
								return;
 | 
				
			||||||
 | 
							case PACKET_TYPE::TEAMINF:
 | 
				
			||||||
 | 
								sendPackTo<TeamInfo>(sock, (TeamInfo*)pack->ptr, buf, buflen, sockad);
 | 
				
			||||||
 | 
								return;
 | 
				
			||||||
 | 
							case PACKET_TYPE::PLAYINF:
 | 
				
			||||||
 | 
								sendPackTo<PlayerInfo>(sock, (PlayerInfo*)pack->ptr, buf, buflen, sockad);
 | 
				
			||||||
 | 
								return;
 | 
				
			||||||
 | 
							case PACKET_TYPE::LOGINF:
 | 
				
			||||||
 | 
								sendPackTo<LoginInfo>(sock, (LoginInfo*)pack->ptr, buf, buflen, sockad);
 | 
				
			||||||
 | 
								return;
 | 
				
			||||||
 | 
							case PACKET_TYPE::CHUNKMOD:
 | 
				
			||||||
 | 
								//sendPackTo<ChunkMod>(sock, (ChunkMod*)pack->ptr, buf, buflen, sockad);
 | 
				
			||||||
 | 
								return;
 | 
				
			||||||
 | 
							case PACKET_TYPE::PLAYERMOD:
 | 
				
			||||||
 | 
								//sendPackTo<PlayerMod>(sock, (PlayerMod*)pack->ptr, buf, buflen, sockad);
 | 
				
			||||||
 | 
								return;
 | 
				
			||||||
 | 
							case PACKET_TYPE::PICKUPMOD:
 | 
				
			||||||
 | 
								//sendPackTo<PickupMod>(sock, (PickupMod*)pack->ptr, buf, buflen, sockad);
 | 
				
			||||||
 | 
								return;
 | 
				
			||||||
 | 
							case PACKET_TYPE::GAMEINFO:
 | 
				
			||||||
 | 
								sendPackTo<GameInfo>(sock, (GameInfo*)pack->ptr, buf, buflen, sockad);
 | 
				
			||||||
 | 
								return;
 | 
				
			||||||
 | 
							case PACKET_TYPE::ENDINFO:
 | 
				
			||||||
 | 
								//sendPackTo<EndInfo>(sock, (EndInfo*)pack->ptr, buf, buflen, sockad);
 | 
				
			||||||
 | 
								return;
 | 
				
			||||||
 | 
							case PACKET_TYPE::CHAT:
 | 
				
			||||||
 | 
								sendPackTo<Chat>(sock, (Chat*)pack->ptr, buf, buflen, sockad);
 | 
				
			||||||
 | 
								return;
 | 
				
			||||||
 | 
							case PACKET_TYPE::ERRLOG:
 | 
				
			||||||
 | 
								sendPackTo<ErrorLog>(sock, (ErrorLog*)pack->ptr, buf, buflen, sockad);
 | 
				
			||||||
 | 
								return;
 | 
				
			||||||
 | 
							case PACKET_TYPE::LAST_PACK: [[fallthrough]];
 | 
				
			||||||
 | 
					        case PACKET_TYPE::ERR: [[fallthrough]];
 | 
				
			||||||
 | 
							default:
 | 
				
			||||||
 | 
								return;
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -1,23 +1,35 @@
 | 
				
			|||||||
#ifndef NETPROTOCOL_H__
 | 
					#ifndef NETPROTOCOL_H__
 | 
				
			||||||
#define NETPROTOCOL_H__
 | 
					#define NETPROTOCOL_H__
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#include "define.h"
 | 
					 | 
				
			||||||
#include <string>
 | 
					#include <string>
 | 
				
			||||||
 | 
					#include "define.h"
 | 
				
			||||||
#include "vector3.h"
 | 
					#include "vector3.h"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/* Protocole Particulier de Partie <EFBFBD> Plusieurs Personnes (PPPPP) */
 | 
					/* Protocole Particulier de Partie a Plusieurs Personnes (PPPPP) */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// Packet: packet[0] = PacketType, packet[1..n-1] = {packet}
 | 
					// Packet: packet[0] = PacketType, packet[1..n-1] = {packet}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
namespace netprot {
 | 
					namespace netprot {
 | 
				
			||||||
	typedef uint8_t PacketType;
 | 
						enum class PACKET_TYPE: uint8_t {
 | 
				
			||||||
	enum PACKET_TYPE {
 | 
					 | 
				
			||||||
				ERR, INPUT, OUTPUT, SYNC,
 | 
									ERR, INPUT, OUTPUT, SYNC,
 | 
				
			||||||
				TEAMINF, SELFINF, PLAYINF, LOGINF,
 | 
									TEAMINF, SELFINF, PLAYINF, LOGINF,
 | 
				
			||||||
				CHUNKMOD, PLAYERMOD, PICKUPMOD,
 | 
									CHUNKMOD, PLAYERMOD, PICKUPMOD,
 | 
				
			||||||
				GAMEINFO, ENDINFO , CHAT, ERRLOG,
 | 
									GAMEINFO, ENDINFO , CHAT, ERRLOG,
 | 
				
			||||||
				LAST_PACK
 | 
									LAST_PACK
 | 
				
			||||||
			};
 | 
								};
 | 
				
			||||||
 | 
						
 | 
				
			||||||
 | 
						struct Buffer { // Pour pouvoir rendre l'utilisation des buffers plus clean.
 | 
				
			||||||
 | 
							char* ptr = new char[BUFFER_LENGTH];
 | 
				
			||||||
 | 
							uint32_t len = BUFFER_LENGTH;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							~Buffer() { delete[] ptr; }
 | 
				
			||||||
 | 
							void rstLen() { len = BUFFER_LENGTH; }
 | 
				
			||||||
 | 
						};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						struct Packet { // Pour pouvoir recevoir les paquets du recv() sans avoir à les aiguiller dans la même thread.
 | 
				
			||||||
 | 
							void* ptr = nullptr; // Notez que le pointeur doit être supprimé séparément lorsqu'il n'est plus utile.
 | 
				
			||||||
 | 
							PACKET_TYPE type = PACKET_TYPE::ERR;
 | 
				
			||||||
 | 
						};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	struct Keys {
 | 
						struct Keys {
 | 
				
			||||||
		bool forward, 
 | 
							bool forward, 
 | 
				
			||||||
@@ -33,7 +45,11 @@ namespace netprot {
 | 
				
			|||||||
		bool jumping, 
 | 
							bool jumping, 
 | 
				
			||||||
			 shooting, 
 | 
								 shooting, 
 | 
				
			||||||
			 hit, 
 | 
								 hit, 
 | 
				
			||||||
			 powerup;
 | 
								 powerup,
 | 
				
			||||||
 | 
								 dead,
 | 
				
			||||||
 | 
								 still,
 | 
				
			||||||
 | 
							     jumpshot,
 | 
				
			||||||
 | 
								 running;
 | 
				
			||||||
	};
 | 
						};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	struct Input {										// cli -> srv			UDP			~frame
 | 
						struct Input {										// cli -> srv			UDP			~frame
 | 
				
			||||||
@@ -58,29 +74,39 @@ namespace netprot {
 | 
				
			|||||||
		uint16_t ammo = 0;
 | 
							uint16_t ammo = 0;
 | 
				
			||||||
		uint8_t hp = 0;
 | 
							uint8_t hp = 0;
 | 
				
			||||||
		Vector3f position;
 | 
							Vector3f position;
 | 
				
			||||||
 | 
							Sync() {}
 | 
				
			||||||
 | 
							Sync(Sync* sync) : timestamp(sync->timestamp), sid(sync->sid), timer(sync->timer), ammo(sync->ammo), hp(sync->hp), position(sync->position) {}
 | 
				
			||||||
	};
 | 
						};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	struct TeamInfo {									// cli <-> srv			TCP			once
 | 
						struct TeamInfo {									// cli <-> srv			TCP			once
 | 
				
			||||||
		char name[32];
 | 
							char name[32];
 | 
				
			||||||
		uint64_t id = 0;
 | 
							uint64_t id = 0;
 | 
				
			||||||
 | 
							TeamInfo() {}
 | 
				
			||||||
 | 
							TeamInfo(TeamInfo* tem) : id(tem->id) { strcpy(tem->name, name); }
 | 
				
			||||||
	};
 | 
						};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	struct LoginInfo {									// cli <-> srv			TCP			once
 | 
						struct LoginInfo {									// cli <-> srv			TCP			once
 | 
				
			||||||
		char name[32];
 | 
							char name[32];
 | 
				
			||||||
		uint64_t sid = 0, 
 | 
							uint64_t sid = 0, 
 | 
				
			||||||
			     tid = 0;
 | 
								     tid = 0;
 | 
				
			||||||
 | 
							LoginInfo() {}
 | 
				
			||||||
 | 
							LoginInfo(LoginInfo* ply): sid(ply->sid), tid(ply->tid) { strcpy(ply->name, name); }
 | 
				
			||||||
	};
 | 
						};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	struct PlayerInfo {									// cli <-> srv			TCP			once
 | 
						struct PlayerInfo {									// cli <-> srv			TCP			once
 | 
				
			||||||
		char name[32];
 | 
							char name[32];
 | 
				
			||||||
		uint64_t id = 0,
 | 
							uint64_t id = 0,
 | 
				
			||||||
				 tid = 0;
 | 
									 tid = 0;
 | 
				
			||||||
 | 
							PlayerInfo() {}
 | 
				
			||||||
 | 
							PlayerInfo(PlayerInfo* log) : id(log->id), tid(log->tid) { strcpy(log->name, name); }
 | 
				
			||||||
	};
 | 
						};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	struct GameInfo {									// cli <-> srv			TCP			event (before game start)/ once
 | 
						struct GameInfo {									// cli <-> srv			TCP			event (before game start)/ once
 | 
				
			||||||
		uint64_t seed;
 | 
							uint64_t seed;
 | 
				
			||||||
		uint32_t countdown;
 | 
							uint32_t countdown;
 | 
				
			||||||
		uint8_t gameType; // TOOD: enum.
 | 
							uint8_t gameType; // TODD: enum.
 | 
				
			||||||
 | 
							GameInfo() {}
 | 
				
			||||||
 | 
							GameInfo(GameInfo* gam) : seed(gam->seed), countdown(gam->countdown), gameType(gam->gameType) {}
 | 
				
			||||||
	};
 | 
						};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	struct Chat {										// cli <-> srv			TCP			event
 | 
						struct Chat {										// cli <-> srv			TCP			event
 | 
				
			||||||
@@ -88,11 +114,15 @@ namespace netprot {
 | 
				
			|||||||
			dest_id = 0,
 | 
								dest_id = 0,
 | 
				
			||||||
			dest_team_id = 0;
 | 
								dest_team_id = 0;
 | 
				
			||||||
		char mess[140]; // Good 'nough for twitr, good 'nough for me.
 | 
							char mess[140]; // Good 'nough for twitr, good 'nough for me.
 | 
				
			||||||
 | 
							Chat() {}
 | 
				
			||||||
 | 
							Chat(Chat* cha) : src_id(cha->src_id), dest_id(cha->dest_id), dest_team_id(cha->dest_team_id) { strcpy(cha->mess, mess); }
 | 
				
			||||||
	};
 | 
						};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	struct ErrorLog {									// srv -> cli			TCP			event
 | 
						struct ErrorLog {									// srv -> cli			TCP			event
 | 
				
			||||||
		char mess[140];
 | 
							char mess[140];
 | 
				
			||||||
		bool is_fatal;
 | 
							bool is_fatal;
 | 
				
			||||||
 | 
							ErrorLog() {};
 | 
				
			||||||
 | 
							ErrorLog(ErrorLog* err) : is_fatal(err->is_fatal) { strcpy(err->mess, mess); }
 | 
				
			||||||
	};
 | 
						};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	void Serialize(Input* in, char* buf[], uint32_t* buflen); // cli
 | 
						void Serialize(Input* in, char* buf[], uint32_t* buflen); // cli
 | 
				
			||||||
@@ -115,6 +145,61 @@ namespace netprot {
 | 
				
			|||||||
	bool Deserialize(Chat* chat, char* buf, const uint32_t buflen); // srv/cli
 | 
						bool Deserialize(Chat* chat, char* buf, const uint32_t buflen); // srv/cli
 | 
				
			||||||
	bool Deserialize(ErrorLog* errlog, char* buf, const uint32_t buflen); // srv
 | 
						bool Deserialize(ErrorLog* errlog, char* buf, const uint32_t buflen); // srv
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	PacketType getType(char* buf, uint32_t buflen); // srv/cli
 | 
						PACKET_TYPE getType(char* buf, uint32_t buflen);
 | 
				
			||||||
} 
 | 
					
 | 
				
			||||||
 | 
						Packet getPack(char* buf, uint32_t buflen);
 | 
				
			||||||
 | 
						Packet getPack(Buffer* buf);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						bool emptyPack(Packet pck);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						Packet makePack(void* ptr, PACKET_TYPE type); // Pour pouvoir faire une liste de stock a supprimer sans avoir a en faire une pour chaque type.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						template <class T> void sendPack(SOCKET sock, T* pack, char** buf, uint32_t* buflen);
 | 
				
			||||||
 | 
						template <class T> void sendPackTo(SOCKET sock, T* pack, char** buf, uint32_t* buflen, sockaddr_in* sockad);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						template <class T> void sendPack(SOCKET sock, T* pack, Buffer* buf);
 | 
				
			||||||
 | 
						template <class T> void sendPackTo(SOCKET sock, T* pack, Buffer* buf, sockaddr_in* sockad);
 | 
				
			||||||
 | 
						
 | 
				
			||||||
 | 
						std::vector<Packet> recvPacks(SOCKET sock, Buffer* buf);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						template <class T>
 | 
				
			||||||
 | 
						void sendPack(SOCKET sock, T* pack, char** buf, uint32_t* buflen) {
 | 
				
			||||||
 | 
							netprot::Serialize(pack, buf, buflen);
 | 
				
			||||||
 | 
							memset(&buf[*buflen], '\0', sizeof(uint64_t) + sizeof(uint8_t));
 | 
				
			||||||
 | 
							buflen += (sizeof(uint64_t) + sizeof(uint8_t));
 | 
				
			||||||
 | 
							send(sock, *buf, *buflen, 0);
 | 
				
			||||||
 | 
							*buflen = BUFFER_LENGTH;
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						template <class T>
 | 
				
			||||||
 | 
						void sendPackTo(SOCKET sock, T* pack, char** buf, uint32_t* buflen, sockaddr_in* sockad) {
 | 
				
			||||||
 | 
							sockaddr_in addr = *sockad;
 | 
				
			||||||
 | 
							netprot::Serialize(pack, buf, buflen);
 | 
				
			||||||
 | 
							memset(&buf[*buflen], '\0', sizeof(uint64_t) + sizeof(uint8_t));
 | 
				
			||||||
 | 
							buflen += (sizeof(uint64_t) + sizeof(uint8_t));
 | 
				
			||||||
 | 
							sendto(sock, *buf, *buflen, 0, (sockaddr*)&addr, sizeof(addr));
 | 
				
			||||||
 | 
							*buflen = BUFFER_LENGTH;
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						template <class T>
 | 
				
			||||||
 | 
						void sendPack(SOCKET sock, T* pack, Buffer* buf) {
 | 
				
			||||||
 | 
							netprot::Serialize(pack, &buf->ptr, &buf->len);
 | 
				
			||||||
 | 
							memset(&buf->ptr[buf->len], '\0', sizeof(uint64_t) + sizeof(uint8_t));
 | 
				
			||||||
 | 
							buf->len += sizeof(uint64_t) + sizeof(uint8_t);
 | 
				
			||||||
 | 
							send(sock, buf->ptr, buf->len, 0);
 | 
				
			||||||
 | 
							buf->rstLen();
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						template <class T>
 | 
				
			||||||
 | 
						void sendPackTo(SOCKET sock, T* pack, Buffer* buf, sockaddr_in* sockad) {
 | 
				
			||||||
 | 
							sockaddr_in addr = *sockad;
 | 
				
			||||||
 | 
							netprot::Serialize(pack, &buf->ptr, &buf->len);
 | 
				
			||||||
 | 
							memset(&buf->ptr[buf->len], '\0', sizeof(uint64_t) + sizeof(uint8_t));
 | 
				
			||||||
 | 
							buf->len += sizeof(uint64_t) + sizeof(uint8_t);
 | 
				
			||||||
 | 
							sendto(sock, buf->ptr, buf->len, 0, (sockaddr*)&addr, sizeof(addr));
 | 
				
			||||||
 | 
							buf->rstLen();
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					};
 | 
				
			||||||
#endif
 | 
					#endif
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -4,10 +4,12 @@
 | 
				
			|||||||
Player::Player(const Vector3f& position, float rotX, float rotY) : m_position(position), m_rotX(rotX), m_rotY(rotY) {
 | 
					Player::Player(const Vector3f& position, float rotX, float rotY) : m_position(position), m_rotX(rotX), m_rotY(rotY) {
 | 
				
			||||||
	m_velocity = Vector3f(0, 0, 0);
 | 
						m_velocity = Vector3f(0, 0, 0);
 | 
				
			||||||
	m_airborne = true;
 | 
						m_airborne = true;
 | 
				
			||||||
	m_hp = 0.75f; //TODO: Remettre <20> 1.0f
 | 
						m_hp = 1.0f; //TODO: Remettre <20> 1.0f
 | 
				
			||||||
	m_username = "Zelda Bee-Bop56";
 | 
						m_username = "Zelda Bee-Bop56";
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					Player::~Player() {}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void Player::TurnLeftRight(float value) {
 | 
					void Player::TurnLeftRight(float value) {
 | 
				
			||||||
	m_rotY += value;
 | 
						m_rotY += value;
 | 
				
			||||||
	if (m_rotY > 360) m_rotY = 0;
 | 
						if (m_rotY > 360) m_rotY = 0;
 | 
				
			||||||
@@ -165,7 +167,7 @@ Player::Sound Player::ApplyPhysics(Vector3f input, World* world, float elapsedTi
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
	m_position += m_velocity;
 | 
						m_position += m_velocity;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	static float bobbingtime = 0; // Gestion de la cam<61>ra
 | 
						static float bobbingtime = 0; // Gestion de la cam<61>ra
 | 
				
			||||||
	static bool leftright = false;
 | 
						static bool leftright = false;
 | 
				
			||||||
	static bool isStep = false;
 | 
						static bool isStep = false;
 | 
				
			||||||
	if (bobbingtime <= 360.f)
 | 
						if (bobbingtime <= 360.f)
 | 
				
			||||||
@@ -206,3 +208,29 @@ void Player::Teleport(int& x, int& z) {
 | 
				
			|||||||
	m_position.x -= x * CHUNK_SIZE_X;
 | 
						m_position.x -= x * CHUNK_SIZE_X;
 | 
				
			||||||
	m_position.z -= z * CHUNK_SIZE_Z;
 | 
						m_position.z -= z * CHUNK_SIZE_Z;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					bool Player::AmIDead()
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
						return m_hp <= 0;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					void Player::InflictDamage(float hitPoints)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						m_hp -= hitPoints;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if (AmIDead())
 | 
				
			||||||
 | 
						{ // Quand le joueur est mort.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					uint64_t Player::getId() const { return id; }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					Vector3f Player::InterpolatePosition(const Vector3f& vec1, const Vector3f& vec2, const Timestamp& tim1, const Timestamp& tim2, const Timestamp& now) {
 | 
				
			||||||
 | 
						return Vector3f();
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -12,6 +12,8 @@ public:
 | 
				
			|||||||
	enum Sound { NOSOUND, STEP, FALL };
 | 
						enum Sound { NOSOUND, STEP, FALL };
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	Player(const Vector3f& position, float rotX = 0, float rotY = 0);
 | 
						Player(const Vector3f& position, float rotX = 0, float rotY = 0);
 | 
				
			||||||
 | 
						~Player();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	void TurnLeftRight(float value);
 | 
						void TurnLeftRight(float value);
 | 
				
			||||||
	void TurnTopBottom(float value);
 | 
						void TurnTopBottom(float value);
 | 
				
			||||||
	Vector3f GetInput(bool front, bool back, bool left, bool right, bool jump, bool dash, float elapsedTime);
 | 
						Vector3f GetInput(bool front, bool back, bool left, bool right, bool jump, bool dash, float elapsedTime);
 | 
				
			||||||
@@ -26,12 +28,19 @@ public:
 | 
				
			|||||||
	float GetHP() const;
 | 
						float GetHP() const;
 | 
				
			||||||
	void Teleport(int& x, int& z);
 | 
						void Teleport(int& x, int& z);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						bool AmIDead();
 | 
				
			||||||
 | 
						void InflictDamage(float hitPoints);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
private:
 | 
					private:
 | 
				
			||||||
 | 
						uint64_t getId() const;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					protected:
 | 
				
			||||||
	Vector3f m_position;
 | 
						Vector3f m_position;
 | 
				
			||||||
	Vector3f m_velocity;
 | 
						Vector3f m_velocity;
 | 
				
			||||||
	Vector3f m_direction;
 | 
						Vector3f m_direction;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	std::string m_username;
 | 
						std::string m_username;
 | 
				
			||||||
 | 
						uint64_t id = 0;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	float m_rotX = 0; 
 | 
						float m_rotX = 0; 
 | 
				
			||||||
	float m_rotY = 0;
 | 
						float m_rotY = 0;
 | 
				
			||||||
@@ -40,6 +49,9 @@ private:
 | 
				
			|||||||
	float m_hp;
 | 
						float m_hp;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	bool m_airborne;
 | 
						bool m_airborne;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						Vector3f InterpolatePosition(const Vector3f& vec1, const Vector3f& vec2, const Timestamp& tim1, const Timestamp& tim2, const Timestamp& now);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
#endif //_PLAYER_H__
 | 
					#endif //_PLAYER_H__
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -6,6 +6,12 @@ World::~World() {}
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
Array2d<Chunk*>& World::GetChunks() { return m_chunks; }
 | 
					Array2d<Chunk*>& World::GetChunks() { return m_chunks; }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					void World::BuildWorld() {
 | 
				
			||||||
 | 
						for (int x = 0; x < WORLD_SIZE_X; ++x)
 | 
				
			||||||
 | 
							for (int y = 0; y < WORLD_SIZE_Y; ++y)
 | 
				
			||||||
 | 
								m_chunks.Set(x, y, new Chunk(x + m_center[0], y + m_center[1], m_seed));
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void World::SetSeed(uint64_t seed) {
 | 
					void World::SetSeed(uint64_t seed) {
 | 
				
			||||||
	m_seed = seed;
 | 
						m_seed = seed;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -21,6 +21,7 @@ public:
 | 
				
			|||||||
	~World();
 | 
						~World();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	Array2d<Chunk*>& GetChunks();
 | 
						Array2d<Chunk*>& GetChunks();
 | 
				
			||||||
 | 
						void BuildWorld();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	void SetSeed(uint64_t seed);
 | 
						void SetSeed(uint64_t seed);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -45,7 +46,7 @@ private:
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
	unsigned int m_center[2] = { UINT16_MAX / 2 - WORLD_SIZE_X, UINT16_MAX / 2 - WORLD_SIZE_Y };
 | 
						unsigned int m_center[2] = { UINT16_MAX / 2 - WORLD_SIZE_X, UINT16_MAX / 2 - WORLD_SIZE_Y };
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	void UpdateChunk(int& updates, unsigned int chx, unsigned int chy, BlockInfo* blockinfo[BTYPE_LAST]);
 | 
						//void UpdateChunk(int& updates, unsigned int chx, unsigned int chy, BlockInfo* blockinfo[BTYPE_LAST]);
 | 
				
			||||||
	void UpdateWorld(const Vector3f& player, BlockInfo* blockinfo[BTYPE_LAST]);
 | 
						void UpdateWorld(const Vector3f& player, BlockInfo* blockinfo[BTYPE_LAST]);
 | 
				
			||||||
	void TransposeWorld(Vector3f& player, Bullet* bullets[MAX_BULLETS]);
 | 
						void TransposeWorld(Vector3f& player, Bullet* bullets[MAX_BULLETS]);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -76,6 +76,7 @@
 | 
				
			|||||||
      <SDLCheck>true</SDLCheck>
 | 
					      <SDLCheck>true</SDLCheck>
 | 
				
			||||||
      <PreprocessorDefinitions>WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
 | 
					      <PreprocessorDefinitions>WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
 | 
				
			||||||
      <ConformanceMode>true</ConformanceMode>
 | 
					      <ConformanceMode>true</ConformanceMode>
 | 
				
			||||||
 | 
					      <LanguageStandard>stdcpp20</LanguageStandard>
 | 
				
			||||||
    </ClCompile>
 | 
					    </ClCompile>
 | 
				
			||||||
    <Link>
 | 
					    <Link>
 | 
				
			||||||
      <SubSystem>Console</SubSystem>
 | 
					      <SubSystem>Console</SubSystem>
 | 
				
			||||||
@@ -90,7 +91,7 @@
 | 
				
			|||||||
      <SDLCheck>true</SDLCheck>
 | 
					      <SDLCheck>true</SDLCheck>
 | 
				
			||||||
      <PreprocessorDefinitions>WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
 | 
					      <PreprocessorDefinitions>WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
 | 
				
			||||||
      <ConformanceMode>true</ConformanceMode>
 | 
					      <ConformanceMode>true</ConformanceMode>
 | 
				
			||||||
      <LanguageStandard>Default</LanguageStandard>
 | 
					      <LanguageStandard>stdcpp20</LanguageStandard>
 | 
				
			||||||
    </ClCompile>
 | 
					    </ClCompile>
 | 
				
			||||||
    <Link>
 | 
					    <Link>
 | 
				
			||||||
      <SubSystem>Console</SubSystem>
 | 
					      <SubSystem>Console</SubSystem>
 | 
				
			||||||
@@ -105,6 +106,7 @@
 | 
				
			|||||||
      <SDLCheck>true</SDLCheck>
 | 
					      <SDLCheck>true</SDLCheck>
 | 
				
			||||||
      <PreprocessorDefinitions>_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
 | 
					      <PreprocessorDefinitions>_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
 | 
				
			||||||
      <ConformanceMode>true</ConformanceMode>
 | 
					      <ConformanceMode>true</ConformanceMode>
 | 
				
			||||||
 | 
					      <LanguageStandard>stdcpp20</LanguageStandard>
 | 
				
			||||||
    </ClCompile>
 | 
					    </ClCompile>
 | 
				
			||||||
    <Link>
 | 
					    <Link>
 | 
				
			||||||
      <SubSystem>Console</SubSystem>
 | 
					      <SubSystem>Console</SubSystem>
 | 
				
			||||||
@@ -119,6 +121,7 @@
 | 
				
			|||||||
      <SDLCheck>true</SDLCheck>
 | 
					      <SDLCheck>true</SDLCheck>
 | 
				
			||||||
      <PreprocessorDefinitions>NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
 | 
					      <PreprocessorDefinitions>NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
 | 
				
			||||||
      <ConformanceMode>true</ConformanceMode>
 | 
					      <ConformanceMode>true</ConformanceMode>
 | 
				
			||||||
 | 
					      <LanguageStandard>stdcpp20</LanguageStandard>
 | 
				
			||||||
    </ClCompile>
 | 
					    </ClCompile>
 | 
				
			||||||
    <Link>
 | 
					    <Link>
 | 
				
			||||||
      <SubSystem>Console</SubSystem>
 | 
					      <SubSystem>Console</SubSystem>
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 3.18.4)
 | 
				
			|||||||
project(SQCSim-Server VERSION 0.1)
 | 
					project(SQCSim-Server VERSION 0.1)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
add_compile_options("-Wno-narrowing")
 | 
					add_compile_options("-Wno-narrowing")
 | 
				
			||||||
set(CMAKE_CXX_STANDARD 17)
 | 
					set(CMAKE_CXX_STANDARD 20)
 | 
				
			||||||
set(CMAKE_STANDARD_REQUIRED True)
 | 
					set(CMAKE_STANDARD_REQUIRED True)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "../out")
 | 
					set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "../out")
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -4,8 +4,8 @@
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
Connection::Connection(SOCKET sock, 
 | 
					Connection::Connection(SOCKET sock, 
 | 
				
			||||||
					   sockaddr_in sockaddr, 
 | 
										   sockaddr_in sockaddr, 
 | 
				
			||||||
					   netprot::LoginInfo log, 
 | 
										   LoginInfo log, 
 | 
				
			||||||
					   netprot::PlayerInfo play):
 | 
										   PlayerInfo play):
 | 
				
			||||||
	m_sock(sock), 
 | 
						m_sock(sock), 
 | 
				
			||||||
	m_addr(sockaddr), 
 | 
						m_addr(sockaddr), 
 | 
				
			||||||
	m_loginfo(log), 
 | 
						m_loginfo(log), 
 | 
				
			||||||
@@ -13,9 +13,7 @@ Connection::Connection(SOCKET sock,
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
Connection::~Connection() {
 | 
					Connection::~Connection() { closesocket(m_sock); }
 | 
				
			||||||
	closesocket(m_sock);
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
uint64_t Connection::GetHash(bool self) const { return self? m_loginfo.sid: m_playinfo.id; }
 | 
					uint64_t Connection::GetHash(bool self) const { return self? m_loginfo.sid: m_playinfo.id; }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -23,19 +21,17 @@ uint64_t Connection::GetTeamHash() const { return m_loginfo.tid; }
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
std::string Connection::GetName() const { return m_loginfo.name; }
 | 
					std::string Connection::GetName() const { return m_loginfo.name; }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void Connection::AddInput(netprot::Input in) {
 | 
					void Connection::AddInput(Input in) { m_input_manifest.insert({ in.timestamp, in }); }
 | 
				
			||||||
	m_input_manifest.insert({ in.timestamp, in });
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
netprot::Output* Connection::getOutput(Timestamp time) {
 | 
					Output* Connection::getOutput(Timestamp time) {
 | 
				
			||||||
	auto out = m_output_manifest.find(time);
 | 
						auto out = m_output_manifest.find(time);
 | 
				
			||||||
	if (out != m_output_manifest.end())
 | 
						if (out != m_output_manifest.end())
 | 
				
			||||||
		return &out->second;
 | 
							return &out->second;
 | 
				
			||||||
	return nullptr;
 | 
						return nullptr;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
netprot::Sync Connection::getSync(Timestamp time) {
 | 
					Sync Connection::getSync(Timestamp time) {
 | 
				
			||||||
	netprot::Sync sync;
 | 
						Sync sync;
 | 
				
			||||||
	auto out = m_output_manifest.find(time);
 | 
						auto out = m_output_manifest.find(time);
 | 
				
			||||||
	if (out != m_output_manifest.end()) {
 | 
						if (out != m_output_manifest.end()) {
 | 
				
			||||||
		sync.timestamp = out->second.timestamp;
 | 
							sync.timestamp = out->second.timestamp;
 | 
				
			||||||
@@ -45,10 +41,15 @@ netprot::Sync Connection::getSync(Timestamp time) {
 | 
				
			|||||||
	return sync;
 | 
						return sync;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					SOCKET Connection::getSock() const { return m_sock; }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					PlayerInfo* Connection::getInfo() const { return (PlayerInfo*)&m_playinfo; }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					sockaddr_in* Connection::getAddr() const { return (sockaddr_in*)&m_addr; }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void Connection::CleanInputManifest(Timestamp time) {
 | 
					void Connection::CleanInputManifest(Timestamp time) {
 | 
				
			||||||
	auto wat = m_input_manifest.find(time);
 | 
						auto wat = m_input_manifest.find(time);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	while (wat != m_input_manifest.begin())
 | 
						while (wat != m_input_manifest.begin())
 | 
				
			||||||
		m_input_manifest.erase(wat--);
 | 
							m_input_manifest.erase(wat--);
 | 
				
			||||||
	
 | 
					 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -8,35 +8,40 @@
 | 
				
			|||||||
#include "../SQCSim-common/netprotocol.h"
 | 
					#include "../SQCSim-common/netprotocol.h"
 | 
				
			||||||
#include "define.h"
 | 
					#include "define.h"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					using namespace netprot;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
class Connection {
 | 
					class Connection {
 | 
				
			||||||
public:
 | 
					public:
 | 
				
			||||||
	Connection(
 | 
						Connection(
 | 
				
			||||||
		SOCKET sock,
 | 
							SOCKET sock,
 | 
				
			||||||
		sockaddr_in sockaddr,
 | 
							sockaddr_in sockaddr,
 | 
				
			||||||
		netprot::LoginInfo log,
 | 
							LoginInfo log,
 | 
				
			||||||
		netprot::PlayerInfo play);
 | 
							PlayerInfo play);
 | 
				
			||||||
	~Connection();
 | 
						~Connection();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	Player* player = nullptr;
 | 
						std::unique_ptr<Player> player = nullptr;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	uint64_t GetHash(bool self = true) const;
 | 
						uint64_t GetHash(bool self = true) const;
 | 
				
			||||||
	uint64_t GetTeamHash() const;
 | 
						uint64_t GetTeamHash() const;
 | 
				
			||||||
	std::string GetName() const;
 | 
						std::string GetName() const;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	void AddInput(netprot::Input in);
 | 
						void AddInput(Input in);
 | 
				
			||||||
	netprot::Output* getOutput(Timestamp time);
 | 
						Output* getOutput(Timestamp time);
 | 
				
			||||||
	netprot::Sync getSync(Timestamp time);
 | 
						Sync getSync(Timestamp time);
 | 
				
			||||||
 | 
						SOCKET getSock() const;
 | 
				
			||||||
 | 
						PlayerInfo* getInfo() const;
 | 
				
			||||||
 | 
						sockaddr_in* getAddr() const;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	void CleanInputManifest(Timestamp time);
 | 
						void CleanInputManifest(Timestamp time);
 | 
				
			||||||
private:
 | 
					private:
 | 
				
			||||||
	std::map<Timestamp, netprot::Input> m_input_manifest;
 | 
						std::map<Timestamp, Input> m_input_manifest;
 | 
				
			||||||
	std::map<Timestamp, netprot::Output> m_output_manifest;
 | 
						std::map<Timestamp, Output> m_output_manifest;
 | 
				
			||||||
	std::map<Timestamp, netprot::Chat> m_chatlog;
 | 
						std::map<Timestamp, Chat> m_chatlog;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	SOCKET m_sock;
 | 
						SOCKET m_sock;
 | 
				
			||||||
	sockaddr_in m_addr;
 | 
						sockaddr_in m_addr;
 | 
				
			||||||
	netprot::LoginInfo m_loginfo;
 | 
						LoginInfo m_loginfo;
 | 
				
			||||||
	netprot::PlayerInfo m_playinfo;
 | 
						PlayerInfo m_playinfo;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
#endif
 | 
					#endif
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -9,9 +9,6 @@
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
#define MAX_CONNECTIONS 16
 | 
					#define MAX_CONNECTIONS 16
 | 
				
			||||||
#define ID_LIST_SIZE 127
 | 
					#define ID_LIST_SIZE 127
 | 
				
			||||||
#define BUFFER_LENGTH 150
 | 
					#define SRV_MANUAL_SETUP true
 | 
				
			||||||
 | 
					 | 
				
			||||||
typedef unsigned char LogDest;
 | 
					 | 
				
			||||||
enum LOG_DEST { CONSOLE, LOGFILE, LOG_LAST };
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
#endif
 | 
					#endif
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -1,9 +1,8 @@
 | 
				
			|||||||
#include "server.h"
 | 
					#include "server.h"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
int main() {
 | 
					int main() {
 | 
				
			||||||
	Server* server = new Server();
 | 
						std::unique_ptr<Server> server = std::make_unique<Server>();
 | 
				
			||||||
	if (server->Init() == 0)
 | 
						if (server->Init() == 0)
 | 
				
			||||||
		if (server->Ready() == 0)
 | 
							if (server->Ready() == 0)
 | 
				
			||||||
			server->Run();
 | 
								server->Run();
 | 
				
			||||||
	delete server;
 | 
					 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
@@ -1,6 +1,6 @@
 | 
				
			|||||||
#include "server.h"
 | 
					#include "server.h"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
Server::Server(LogDest log) {
 | 
					Server::Server(LOG_DEST log) {
 | 
				
			||||||
	m_log = log;
 | 
						m_log = log;
 | 
				
			||||||
	if (log == LOG_DEST::LOGFILE) {
 | 
						if (log == LOG_DEST::LOGFILE) {
 | 
				
			||||||
		m_logfile = std::ofstream("server.log", std::ofstream::out);
 | 
							m_logfile = std::ofstream("server.log", std::ofstream::out);
 | 
				
			||||||
@@ -17,7 +17,10 @@ Server::~Server() {
 | 
				
			|||||||
	if (m_sock_udp)
 | 
						if (m_sock_udp)
 | 
				
			||||||
		closesocket(m_sock_udp);
 | 
							closesocket(m_sock_udp);
 | 
				
			||||||
	if (m_sock_tcp)
 | 
						if (m_sock_tcp)
 | 
				
			||||||
		closesocket(m_sock_tcp);
 | 
							closesocket(m_sock_tcp);	
 | 
				
			||||||
 | 
						for (const auto& [key, player] : m_players)
 | 
				
			||||||
 | 
								closesocket(player->getSock());
 | 
				
			||||||
 | 
							m_players.clear();
 | 
				
			||||||
#ifdef _WIN32
 | 
					#ifdef _WIN32
 | 
				
			||||||
	WSACleanup();
 | 
						WSACleanup();
 | 
				
			||||||
#endif
 | 
					#endif
 | 
				
			||||||
@@ -65,70 +68,105 @@ int Server::Init() {
 | 
				
			|||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
int Server::Ready() {
 | 
					int Server::Ready() {
 | 
				
			||||||
 | 
						int nbrjoueurs = 0, 
 | 
				
			||||||
 | 
							nbrconn = 0;
 | 
				
			||||||
 | 
						bool readystart = false;
 | 
				
			||||||
 | 
						do {
 | 
				
			||||||
 | 
							Log("Entrez la duree de la partie: ", false, false);
 | 
				
			||||||
 | 
							std::cin.getline(m_buf.ptr, BUFFER_LENGTH);
 | 
				
			||||||
 | 
							try {	
 | 
				
			||||||
 | 
								m_game.countdown = std::stoi(m_buf.ptr);
 | 
				
			||||||
 | 
							} catch(const std::exception& e) {
 | 
				
			||||||
 | 
								Log(e.what(), true, false);
 | 
				
			||||||
 | 
								m_game.countdown = 0;
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
						} while (m_game.countdown < 1);
 | 
				
			||||||
 | 
						do {
 | 
				
			||||||
 | 
							Log("Entrez le seed de la partie: ", false, false);
 | 
				
			||||||
 | 
							std::cin.getline(m_buf.ptr, BUFFER_LENGTH);
 | 
				
			||||||
 | 
							try {	
 | 
				
			||||||
 | 
								m_game.seed = std::stoi(m_buf.ptr);
 | 
				
			||||||
 | 
							} catch(const std::exception& e) {
 | 
				
			||||||
 | 
								Log(e.what(), true, false);
 | 
				
			||||||
 | 
								m_game.seed = 0;
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
						} while (m_game.seed < 1);
 | 
				
			||||||
 | 
						do {
 | 
				
			||||||
 | 
							Log("Entrez le nombre de joueurs: ", false, false);
 | 
				
			||||||
 | 
							std::cin.getline(m_buf.ptr, BUFFER_LENGTH);
 | 
				
			||||||
 | 
							try {	
 | 
				
			||||||
 | 
								nbrjoueurs = std::stoi(m_buf.ptr);
 | 
				
			||||||
 | 
							} catch(const std::exception& e) {
 | 
				
			||||||
 | 
								Log(e.what(), true, false);
 | 
				
			||||||
 | 
								nbrjoueurs = 0;
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							if (nbrjoueurs <= 0 || nbrjoueurs > MAX_CONNECTIONS)
 | 
				
			||||||
 | 
								Log("Nombre de joueurs invalide.", true, false);
 | 
				
			||||||
 | 
						} while (nbrjoueurs <= 0 || nbrjoueurs > MAX_CONNECTIONS);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						m_game.gameType = 1;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if (listen(m_sock_tcp, MAX_CONNECTIONS) < 0) {
 | 
						if (listen(m_sock_tcp, MAX_CONNECTIONS) < 0) {
 | 
				
			||||||
		Log("<EFBFBD>coute sur le port TCP.", true, true);
 | 
							Log("Ecoute sur le port TCP.", true, true);
 | 
				
			||||||
		return 1;
 | 
							return 1;
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	char* buf = new char[150];
 | 
					 | 
				
			||||||
	uint32_t buflen = 150;
 | 
					 | 
				
			||||||
	bool readystart = false;
 | 
					 | 
				
			||||||
	srand(time(NULL));
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	Log("<EFBFBD> l'<27>coute sur le port: " + std::to_string(SRV_PORT), false, false);
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	buildIdList(ID_LIST_SIZE);
 | 
						buildIdList(ID_LIST_SIZE);
 | 
				
			||||||
 | 
						
 | 
				
			||||||
	m_game.countdown = 360;
 | 
						Log("A l'ecoute sur le port: " + std::to_string(SRV_PORT), false, false);
 | 
				
			||||||
	m_game.gameType = 1;
 | 
						
 | 
				
			||||||
	m_game.seed = 9370707;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	while (!readystart) {
 | 
						while (!readystart) {
 | 
				
			||||||
		sockaddr_in sockad;
 | 
							sockaddr_in sockad;
 | 
				
			||||||
		unsigned int addrlen = sizeof(sockad);
 | 
							addrlen_t addrlen = sizeof(sockad);
 | 
				
			||||||
		SOCKET sock = accept(m_sock_tcp, (sockaddr*)&sockad, &addrlen);
 | 
							SOCKET sock = accept(m_sock_tcp, (sockaddr*)&sockad, &addrlen);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		if (sock < 0)
 | 
							if (sock < 0)
 | 
				
			||||||
			Log("Erreur de connexion", true, false);
 | 
								Log("Erreur de connexion", true, false);
 | 
				
			||||||
		else if (sock > 0) {
 | 
							else if (sock > 0) {
 | 
				
			||||||
			std::string str = "Nouvelle connection provenant de: ";
 | 
								std::string str = "Nouvelle connexion provenant de: ";
 | 
				
			||||||
			char* strbuf = new char[BUFFER_LENGTH];
 | 
								str.append(inet_ntop(AF_INET, &sockad.sin_addr, m_buf.ptr, m_buf.len)).append(": ").append(std::to_string(sockad.sin_port));
 | 
				
			||||||
			uint32_t strbuflen = BUFFER_LENGTH;
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
			str.append(inet_ntop(AF_INET, &sockad.sin_addr, strbuf, strbuflen)).append(": ").append(std::to_string(sockad.sin_port));
 | 
								if (recv(sock, m_buf.ptr, m_buf.len, 0) > 0) {
 | 
				
			||||||
 | 
									PlayerInfo play;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
			if (recv(sock, buf, buflen, 0) > 0) {
 | 
									Packet pck = getPack(&m_buf);
 | 
				
			||||||
				netprot::LoginInfo log;
 | 
									if (pck.type != PACKET_TYPE::LOGINF) {
 | 
				
			||||||
				netprot::PlayerInfo play;
 | 
										Log("Paquet invalide.", true, false);
 | 
				
			||||||
				if (netprot::Deserialize(&log, buf, buflen)) {
 | 
										if (pck.type != PACKET_TYPE::ERR)
 | 
				
			||||||
					log.sid = getUniqueId();
 | 
											netprot::emptyPack(pck); 
 | 
				
			||||||
 | 
										continue; // Passer au prochain appel si c'est pas un LoginInfo ou un LoginInfo invalide qui rentre.
 | 
				
			||||||
					log.tid = 0;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
					str.append(" Nom: ").append(log.name); 
 | 
					 | 
				
			||||||
					Log(str, false, false);
 | 
					 | 
				
			||||||
					str = "";
 | 
					 | 
				
			||||||
					
 | 
					 | 
				
			||||||
					str.append(log.name).append(" SID: [").append(std::to_string(log.sid).append("]"));
 | 
					 | 
				
			||||||
					Log(str, false, false);
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
					//netprot::Serialize(&log, &buf, &buflen);
 | 
					 | 
				
			||||||
					//send(sock, buf, buflen, 0);
 | 
					 | 
				
			||||||
					//buflen = 150;
 | 
					 | 
				
			||||||
					sendPack<netprot::LoginInfo>(sock, &log, &buf, &buflen);
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
					play.id = getUniqueId();
 | 
					 | 
				
			||||||
					memcpy(play.name, log.name, std::strlen(log.name) + 1);
 | 
					 | 
				
			||||||
					play.tid = log.tid;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
					//netprot::Serialize(&m_game, &buf, &buflen);
 | 
					 | 
				
			||||||
					//send(sock, buf, buflen, 0);
 | 
					 | 
				
			||||||
					sendPack<netprot::GameInfo>(sock, &m_game, &buf, &buflen);
 | 
					 | 
				
			||||||
					Connection* conn = new Connection(sock, sockad, log, play);
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
					m_players[log.sid] = conn;
 | 
					 | 
				
			||||||
					readystart = true;
 | 
					 | 
				
			||||||
				}
 | 
									}
 | 
				
			||||||
 | 
									LoginInfo* log = (LoginInfo*)pck.ptr;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
									log->sid = getUniqueId();
 | 
				
			||||||
 | 
									log->tid = 0; // TODO: À changer si on implemente un mode en equipe.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
									Log(str.append(" Nom: ").append(log->name), false, false);
 | 
				
			||||||
 | 
									str.clear();
 | 
				
			||||||
 | 
										
 | 
				
			||||||
 | 
									Log(str.append(log->name).append(" SID: [").append(std::to_string(log->sid).append("]")), false, false);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
									sendPack<LoginInfo>(sock, log, &m_buf.ptr, &m_buf.len);
 | 
				
			||||||
 | 
									
 | 
				
			||||||
 | 
									play.id = getUniqueId();
 | 
				
			||||||
 | 
									strcpy(play.name, log->name);
 | 
				
			||||||
 | 
									
 | 
				
			||||||
 | 
									play.tid = log->tid;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
									sendPack<GameInfo>(sock, &m_game, &m_buf.ptr, &m_buf.len);
 | 
				
			||||||
 | 
									std::unique_ptr<Connection> conn = std::make_unique<Connection>(sock, sockad, *log, play);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
									for (auto& [key, player] : m_players) {
 | 
				
			||||||
 | 
										sendPack<PlayerInfo>(player->getSock(), &play, &m_buf); // Envoyer les infos de joueur distant aux joueurs d<>j<EFBFBD> connect<63>s		
 | 
				
			||||||
 | 
										sendPack<PlayerInfo>(sock, player->getInfo(), &m_buf); // et envoyer les infos des joueurs distants au nouveau joueur.
 | 
				
			||||||
 | 
									}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
									m_players[log->sid] = std::move(conn);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
									delete log;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
									if (++nbrconn >= nbrjoueurs)
 | 
				
			||||||
 | 
										readystart = true;
 | 
				
			||||||
			}
 | 
								}
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
@@ -136,14 +174,61 @@ int Server::Ready() {
 | 
				
			|||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void Server::Run() {
 | 
					void Server::Run() {
 | 
				
			||||||
 | 
						Input in;
 | 
				
			||||||
 | 
						sockaddr_in sockad;
 | 
				
			||||||
 | 
						addrlen_t socklen = sizeof(sockad);
 | 
				
			||||||
 | 
						
 | 
				
			||||||
 | 
						Log("Debut de la partie...", false, false);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	Log("Partie en cours...", false, false);
 | 
						m_world = std::make_unique<World>();
 | 
				
			||||||
 | 
						m_world->SetSeed(m_game.seed);
 | 
				
			||||||
 | 
						m_world->GetChunks().Reset(nullptr);
 | 
				
			||||||
 | 
						m_world->BuildWorld();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						for (auto& [key, conn] : m_players) { // Creation des instances de joueurs et premier sync.
 | 
				
			||||||
 | 
							conn->player = std::make_unique<Player>(Vector3f(8.5f, CHUNK_SIZE_Y + 1.8f, 8.5f));
 | 
				
			||||||
 | 
							Sync sync;
 | 
				
			||||||
 | 
							sync.position = conn->player->GetPosition();
 | 
				
			||||||
 | 
							sync.hp = conn->player->GetHP();
 | 
				
			||||||
 | 
							sync.sid = key;
 | 
				
			||||||
 | 
							sync.ammo = 0;
 | 
				
			||||||
 | 
							sync.timestamp = 0;
 | 
				
			||||||
 | 
							sync.timer = m_game.countdown;
 | 
				
			||||||
 | 
							sendPack<Sync>(conn->getSock(), &sync, &m_buf);
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						while (true) {
 | 
				
			||||||
 | 
							if (recvfrom(m_sock_udp, m_buf.ptr, m_buf.len, 0, (sockaddr*)&sockad, &socklen) > 0) {
 | 
				
			||||||
 | 
								Packet pck = getPack(&m_buf);
 | 
				
			||||||
 | 
								switch (pck.type) {
 | 
				
			||||||
 | 
									using enum netprot::PACKET_TYPE;
 | 
				
			||||||
 | 
					            	case ERR:			std::puts("ERROR!");		break;
 | 
				
			||||||
 | 
					                case INPUT:			std::puts("INPUT!");		break;
 | 
				
			||||||
 | 
					                case OUTPUT:		std::puts("OUTPUT!");		break;
 | 
				
			||||||
 | 
									case SYNC:			std::puts("SYNC!");			break;
 | 
				
			||||||
 | 
					                case TEAMINF:		std::puts("TEAMINF!");		break;
 | 
				
			||||||
 | 
					                case SELFINF:		std::puts("SELFINF!");		break;
 | 
				
			||||||
 | 
					                case PLAYINF:		std::puts("PLAYINF!");		break;
 | 
				
			||||||
 | 
					                case LOGINF:		std::puts("LOGINF!");		break;
 | 
				
			||||||
 | 
					                case CHUNKMOD:		std::puts("CHUNKMOD!");		break;
 | 
				
			||||||
 | 
					                case PLAYERMOD:		std::puts("PLAYERMOD!");	break;
 | 
				
			||||||
 | 
					                case PICKUPMOD:		std::puts("PICKUPMOD!");	break;
 | 
				
			||||||
 | 
					                case GAMEINFO:		std::puts("GAMEINFO!");		break;
 | 
				
			||||||
 | 
					                case ENDINFO:		std::puts("ENDINFO!");		break;
 | 
				
			||||||
 | 
					                case CHAT:			std::puts("CHAT!");			break;
 | 
				
			||||||
 | 
					                case ERRLOG:		std::puts("ERRLOG!");		break;
 | 
				
			||||||
 | 
									case LAST_PACK:									[[falltrough]];
 | 
				
			||||||
 | 
									default:			std::puts("wtf?!");			break;
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
								netprot::emptyPack(pck);
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
inline std::string Server::LogTimestamp() {
 | 
					inline std::string Server::LogTimestamp() {
 | 
				
			||||||
	time_t rawtime;
 | 
						time_t rawtime;
 | 
				
			||||||
	struct tm timeinfo;
 | 
						tm timeinfo;
 | 
				
			||||||
	char buffer[80];
 | 
						char buffer[50];
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	time(&rawtime);
 | 
						time(&rawtime);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -161,30 +246,39 @@ inline std::string Server::LogTimestamp() {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
void Server::Log(std::string str, bool is_error = false, bool is_fatal = false) {
 | 
					void Server::Log(std::string str, bool is_error = false, bool is_fatal = false) {
 | 
				
			||||||
	switch (m_log) {
 | 
						switch (m_log) {
 | 
				
			||||||
	case LOG_DEST::LOGFILE:
 | 
							using enum LOG_DEST; // C++20!
 | 
				
			||||||
		m_logfile << LogTimestamp() << (is_fatal ? "FATAL " : "") << (is_error ? "ERROR " : "") << str << std::endl;
 | 
							case LOGFILE:
 | 
				
			||||||
		break;
 | 
								m_logfile << LogTimestamp() << (is_fatal ? "FATAL " : "") << (is_error ? "ERROR " : "") << str << std::endl;
 | 
				
			||||||
	case LOG_DEST::CONSOLE:
 | 
								break;
 | 
				
			||||||
	default:
 | 
							case CONSOLE: [[fallthrough]]; // Pour dire que c'est voulu que ça traverse vers le case en dessous (C++17!)
 | 
				
			||||||
		std::cout << LogTimestamp() << (is_fatal ? "FATAL " : "") << (is_error ? "ERROR " : "") << str << std::endl;
 | 
							default:
 | 
				
			||||||
		break;
 | 
								std::cout << LogTimestamp() << (is_fatal ? "FATAL " : "") << (is_error ? "ERROR " : "") << str << std::endl;
 | 
				
			||||||
 | 
								break;
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if (is_fatal) {
 | 
						if (is_fatal) {
 | 
				
			||||||
 | 
							if (m_logfile.is_open())
 | 
				
			||||||
 | 
								m_logfile.close();
 | 
				
			||||||
		if (m_sock_udp)
 | 
							if (m_sock_udp)
 | 
				
			||||||
			closesocket(m_sock_udp);
 | 
								closesocket(m_sock_udp);
 | 
				
			||||||
		if (m_sock_tcp)
 | 
							if (m_sock_tcp)
 | 
				
			||||||
			closesocket(m_sock_tcp);
 | 
								closesocket(m_sock_tcp);
 | 
				
			||||||
 | 
							for (const auto& [key, player] : m_players) {
 | 
				
			||||||
 | 
								closesocket(player->getSock());
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							m_players.clear();
 | 
				
			||||||
#ifdef _WIN32
 | 
					#ifdef _WIN32
 | 
				
			||||||
		WSACleanup();
 | 
							WSACleanup();
 | 
				
			||||||
#endif
 | 
					#endif
 | 
				
			||||||
 | 
							exit(-1);
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void Server::buildIdList(size_t size) {
 | 
					void Server::buildIdList(size_t size) {
 | 
				
			||||||
	std::set<uint64_t> lst;
 | 
						std::set<uint64_t> lst;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	do lst.insert(((uint64_t)rand() << 25) % 8675309); // EIGHT SIX SEVENFIVE THREE AUGHT NIIIIIIiIIiiIiINE!
 | 
						srand(time(NULL));
 | 
				
			||||||
 | 
						do lst.insert(((uint64_t)rand() << 32 | rand()));
 | 
				
			||||||
	while (lst.size() < size);
 | 
						while (lst.size() < size);
 | 
				
			||||||
	
 | 
						
 | 
				
			||||||
	m_ids = std::vector<uint64_t>(lst.begin(), lst.end());
 | 
						m_ids = std::vector<uint64_t>(lst.begin(), lst.end());
 | 
				
			||||||
@@ -195,133 +289,3 @@ uint64_t Server::getUniqueId() {
 | 
				
			|||||||
	m_ids.pop_back();
 | 
						m_ids.pop_back();
 | 
				
			||||||
	return id;
 | 
						return id;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					 | 
				
			||||||
// Test serialize/deserialize:
 | 
					 | 
				
			||||||
/*
 | 
					 | 
				
			||||||
	netprot::LoginInfo log, log2;
 | 
					 | 
				
			||||||
	std::cout << "Nom? ";
 | 
					 | 
				
			||||||
	std::cin.getline(log.name, 32); // NO! STD::CIN >> VARIABLE;! EVEEEEEERRRR!!!
 | 
					 | 
				
			||||||
	log.sid = 12345;
 | 
					 | 
				
			||||||
	char* buf = new char[150];
 | 
					 | 
				
			||||||
	uint32_t buflen = 150;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	netprot::Serialize(&log, &buf, &buflen);
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	bool is_work = netprot::Deserialize(&log2, buf, buflen);
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	std::string str;
 | 
					 | 
				
			||||||
	str.append(is_work ? "Y " : "N ").append(log2.name).append(": ").append(std::to_string(log2.sid));
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	Log(str, false, false);
 | 
					 | 
				
			||||||
*/
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
///* Recevoir paquet */
 | 
					 | 
				
			||||||
//while (true) {
 | 
					 | 
				
			||||||
//	char buffer[2048];
 | 
					 | 
				
			||||||
//	sockaddr_in client;
 | 
					 | 
				
			||||||
//
 | 
					 | 
				
			||||||
//#ifdef _WIN32 // Mais pourquoi?
 | 
					 | 
				
			||||||
//	int clen = sizeof(client);
 | 
					 | 
				
			||||||
//#else
 | 
					 | 
				
			||||||
//	unsigned int clen = sizeof(client);
 | 
					 | 
				
			||||||
//#endif
 | 
					 | 
				
			||||||
//
 | 
					 | 
				
			||||||
//	int count = recvfrom(socket_udp, buffer, sizeof(buffer) - 1, 0, (sockaddr*)&client, &clen);
 | 
					 | 
				
			||||||
//
 | 
					 | 
				
			||||||
//	if (count < 0) {
 | 
					 | 
				
			||||||
//		Log("Erreur de reception de paquet.", socket_udp);
 | 
					 | 
				
			||||||
//		return 4;
 | 
					 | 
				
			||||||
//	}
 | 
					 | 
				
			||||||
//
 | 
					 | 
				
			||||||
//	buffer[count] = '\0';
 | 
					 | 
				
			||||||
//
 | 
					 | 
				
			||||||
//	/* G<>rer le paquet re<72>u */
 | 
					 | 
				
			||||||
//	std::string commande(buffer);
 | 
					 | 
				
			||||||
//
 | 
					 | 
				
			||||||
//	if (commande.find("echo ") == 0) {													/*		ECHO		*/
 | 
					 | 
				
			||||||
//		std::string::size_type pos = commande.find(' ');
 | 
					 | 
				
			||||||
//		std::string parametres = commande.substr(pos + 1);
 | 
					 | 
				
			||||||
//
 | 
					 | 
				
			||||||
//		sendto(socket_udp, parametres.c_str(), parametres.length(), 0, (const sockaddr*)&client, sizeof(client));
 | 
					 | 
				
			||||||
//	}
 | 
					 | 
				
			||||||
//	else if (commande.find("date ") == 0) {												/*		DATE		*/
 | 
					 | 
				
			||||||
//		time_t rawtime;
 | 
					 | 
				
			||||||
//		struct tm* timeinfo = new tm();
 | 
					 | 
				
			||||||
//		char tbuffer[80];
 | 
					 | 
				
			||||||
//
 | 
					 | 
				
			||||||
//		time(&rawtime);
 | 
					 | 
				
			||||||
//
 | 
					 | 
				
			||||||
//#ifdef _WIN32
 | 
					 | 
				
			||||||
//		localtime_s(timeinfo, &rawtime);
 | 
					 | 
				
			||||||
//#else
 | 
					 | 
				
			||||||
//		localtime_r(&rawtime, timeinfo);
 | 
					 | 
				
			||||||
//#endif
 | 
					 | 
				
			||||||
//
 | 
					 | 
				
			||||||
//		strftime(tbuffer, 80, "%a %b %e %T %G", timeinfo);
 | 
					 | 
				
			||||||
//
 | 
					 | 
				
			||||||
//		sendto(socket_udp, tbuffer, sizeof(tbuffer), 0, (const sockaddr*)&client, sizeof(client));
 | 
					 | 
				
			||||||
//		delete timeinfo;
 | 
					 | 
				
			||||||
//	}
 | 
					 | 
				
			||||||
//	else if (commande.find("ping ") == 0) {												/*		PING		*/
 | 
					 | 
				
			||||||
//		sendto(socket_udp, "pong", sizeof("pong"), 0, (const sockaddr*)&client, sizeof(client));
 | 
					 | 
				
			||||||
//	}
 | 
					 | 
				
			||||||
//	else if (commande.find("usager ") == 0) {											/*		USAGER		*/
 | 
					 | 
				
			||||||
//		std::string user;
 | 
					 | 
				
			||||||
//
 | 
					 | 
				
			||||||
//#ifdef _WIN32
 | 
					 | 
				
			||||||
//		wchar_t userbuf[30];
 | 
					 | 
				
			||||||
//		DWORD usersize = 30;
 | 
					 | 
				
			||||||
//
 | 
					 | 
				
			||||||
//		GetUserNameW(userbuf, &usersize);
 | 
					 | 
				
			||||||
//
 | 
					 | 
				
			||||||
//		std::wstring wuser = userbuf;
 | 
					 | 
				
			||||||
//		user = std::string(wuser.begin(), wuser.end());
 | 
					 | 
				
			||||||
//#else
 | 
					 | 
				
			||||||
//		char ptr[30];
 | 
					 | 
				
			||||||
//		getlogin_r(ptr, sizeof(ptr) - 1);
 | 
					 | 
				
			||||||
//		user = std::string(ptr);
 | 
					 | 
				
			||||||
//#endif
 | 
					 | 
				
			||||||
//
 | 
					 | 
				
			||||||
//		sendto(socket_udp, user.c_str(), user.length(), 0, (const sockaddr*)&client, sizeof(client));
 | 
					 | 
				
			||||||
//	}
 | 
					 | 
				
			||||||
//	else if (commande.find("exec ") == 0) {												/*		EXEC		*/
 | 
					 | 
				
			||||||
//		std::string::size_type pos = commande.find(' ');
 | 
					 | 
				
			||||||
//		std::string parametres = commande.substr(pos + 1);
 | 
					 | 
				
			||||||
//
 | 
					 | 
				
			||||||
//		FILE* pipe = nullptr;
 | 
					 | 
				
			||||||
//		char buffer[301]; // 300 caract<63>res + '\0'
 | 
					 | 
				
			||||||
//		std::string reponse;
 | 
					 | 
				
			||||||
//
 | 
					 | 
				
			||||||
//		pipe = popen(parametres.c_str(), "r");
 | 
					 | 
				
			||||||
//
 | 
					 | 
				
			||||||
//		if (!pipe)
 | 
					 | 
				
			||||||
//			reponse = "Erreur de commande!";
 | 
					 | 
				
			||||||
//		else while (!feof(pipe)) {
 | 
					 | 
				
			||||||
//			if (fgets(buffer, sizeof(buffer) - 1, pipe))
 | 
					 | 
				
			||||||
//				reponse += buffer;
 | 
					 | 
				
			||||||
//		}
 | 
					 | 
				
			||||||
//
 | 
					 | 
				
			||||||
//		if (pipe)
 | 
					 | 
				
			||||||
//			pclose(pipe);
 | 
					 | 
				
			||||||
//
 | 
					 | 
				
			||||||
//		if (reponse.length() > 300)
 | 
					 | 
				
			||||||
//			reponse = reponse.substr(0, 300);
 | 
					 | 
				
			||||||
//		else if (reponse.length() < 1)
 | 
					 | 
				
			||||||
//			reponse = "OK!";
 | 
					 | 
				
			||||||
//
 | 
					 | 
				
			||||||
//		sendto(socket_udp, reponse.c_str(), reponse.length(), 0, (const sockaddr*)&client, sizeof(client));
 | 
					 | 
				
			||||||
//	}
 | 
					 | 
				
			||||||
//	else if (commande.find("bye ") == 0) {											/*		BYE			*/
 | 
					 | 
				
			||||||
//		Log("", 0); // Message d'erreur pas de message d'erreur!
 | 
					 | 
				
			||||||
//		return 0;
 | 
					 | 
				
			||||||
//	}
 | 
					 | 
				
			||||||
//	else sendto(socket_udp, "huh?", sizeof("huh?"), 0, (const sockaddr*)&client, sizeof(client));		/*			DEFAULT			 */
 | 
					 | 
				
			||||||
//}
 | 
					 | 
				
			||||||
//
 | 
					 | 
				
			||||||
///* Ce bout de code ne devrait theoriquement jamais etre atteint, mais au cas. */
 | 
					 | 
				
			||||||
//Log("", 0);
 | 
					 | 
				
			||||||
//return 0;
 | 
					 | 
				
			||||||
//return false;
 | 
					 | 
				
			||||||
//}
 | 
					 | 
				
			||||||
//
 | 
					 | 
				
			||||||
 
 | 
				
			|||||||
@@ -10,9 +10,13 @@
 | 
				
			|||||||
#include "define.h"
 | 
					#include "define.h"
 | 
				
			||||||
#include "connection.h"
 | 
					#include "connection.h"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					using namespace netprot;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
class Server {
 | 
					class Server {
 | 
				
			||||||
public:
 | 
					public:
 | 
				
			||||||
	Server(LogDest log = LOG_DEST::CONSOLE);
 | 
						enum LOG_DEST: unsigned char { CONSOLE, LOGFILE, LOG_LAST };
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						Server(LOG_DEST log = LOG_DEST::CONSOLE);
 | 
				
			||||||
	~Server();
 | 
						~Server();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	int Init();
 | 
						int Init();
 | 
				
			||||||
@@ -20,35 +24,31 @@ public:
 | 
				
			|||||||
	void Run();
 | 
						void Run();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
private:
 | 
					private:
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#ifdef _WIN32
 | 
					#ifdef _WIN32
 | 
				
			||||||
	WSADATA m_wsaData;
 | 
						WSADATA m_wsaData;
 | 
				
			||||||
#endif
 | 
					#endif
 | 
				
			||||||
	SOCKET m_sock_udp = 0,
 | 
						SOCKET m_sock_udp = 0,
 | 
				
			||||||
		   m_sock_tcp = 0;
 | 
							   m_sock_tcp = 0;
 | 
				
			||||||
	LogDest m_log;
 | 
						LOG_DEST m_log;
 | 
				
			||||||
	std::ofstream m_logfile;
 | 
						std::ofstream m_logfile;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	std::map<uint64_t, Connection*> m_players;
 | 
						Buffer m_buf;
 | 
				
			||||||
	std::map <Timestamp, netprot::Chat> m_chatlog;
 | 
					 | 
				
			||||||
	std::vector<uint64_t> m_ids;
 | 
					 | 
				
			||||||
	netprot::GameInfo m_game;
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
	World* m_world = nullptr;
 | 
						std::map<uint64_t, std::unique_ptr<Connection>> m_players;
 | 
				
			||||||
 | 
						std::map <Timestamp, Chat> m_chatlog;
 | 
				
			||||||
 | 
						std::vector<uint64_t> m_ids;
 | 
				
			||||||
 | 
						GameInfo m_game;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						std::unique_ptr<World> m_world = nullptr;
 | 
				
			||||||
 | 
						const bool m_manual_setup = SRV_MANUAL_SETUP;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	std::string LogTimestamp();
 | 
						std::string LogTimestamp();
 | 
				
			||||||
	void Log(std::string str, bool is_error, bool is_fatal);
 | 
						void Log(std::string str, bool is_error, bool is_fatal);
 | 
				
			||||||
	void buildIdList(size_t size);
 | 
						void buildIdList(size_t size);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	uint64_t getUniqueId(); 
 | 
						uint64_t getUniqueId(); 	
 | 
				
			||||||
	template <class T> void sendPack(SOCKET sock, T* pack, char** buf, uint32_t* buflen);
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
template <class T>
 | 
					 | 
				
			||||||
void Server::sendPack(SOCKET sock, T* pack, char** buf, uint32_t* buflen) {
 | 
					 | 
				
			||||||
	netprot::Serialize(pack, buf, buflen);
 | 
					 | 
				
			||||||
	send(sock, *buf, *buflen, 0);
 | 
					 | 
				
			||||||
	*buflen = BUFFER_LENGTH;
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
#endif
 | 
					#endif
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -25,13 +25,14 @@
 | 
				
			|||||||
    <ClInclude Include="engine.h" />
 | 
					    <ClInclude Include="engine.h" />
 | 
				
			||||||
    <ClInclude Include="mesh.h" />
 | 
					    <ClInclude Include="mesh.h" />
 | 
				
			||||||
    <ClInclude Include="openglcontext.h" />
 | 
					    <ClInclude Include="openglcontext.h" />
 | 
				
			||||||
 | 
					    <ClInclude Include="remoteplayer.h" />
 | 
				
			||||||
    <ClInclude Include="shader.h" />
 | 
					    <ClInclude Include="shader.h" />
 | 
				
			||||||
    <ClInclude Include="skybox.h" />
 | 
					    <ClInclude Include="skybox.h" />
 | 
				
			||||||
    <ClInclude Include="texture.h" />
 | 
					    <ClInclude Include="texture.h" />
 | 
				
			||||||
    <ClInclude Include="textureatlas.h" />
 | 
					    <ClInclude Include="textureatlas.h" />
 | 
				
			||||||
    <ClInclude Include="tool.h" />
 | 
					    <ClInclude Include="tool.h" />
 | 
				
			||||||
    <ClInclude Include="vertexbuffer.h" />
 | 
					    <ClInclude Include="vertexbuffer.h" />
 | 
				
			||||||
    <ClInclude Include="worldrenderer.h" />
 | 
					    <ClInclude Include="renderer.h" />
 | 
				
			||||||
  </ItemGroup>
 | 
					  </ItemGroup>
 | 
				
			||||||
  <ItemGroup>
 | 
					  <ItemGroup>
 | 
				
			||||||
    <ClCompile Include="audio.cpp" />
 | 
					    <ClCompile Include="audio.cpp" />
 | 
				
			||||||
@@ -40,13 +41,14 @@
 | 
				
			|||||||
    <ClCompile Include="main.cpp" />
 | 
					    <ClCompile Include="main.cpp" />
 | 
				
			||||||
    <ClCompile Include="mesh.cpp" />
 | 
					    <ClCompile Include="mesh.cpp" />
 | 
				
			||||||
    <ClCompile Include="openglcontext.cpp" />
 | 
					    <ClCompile Include="openglcontext.cpp" />
 | 
				
			||||||
 | 
					    <ClCompile Include="remoteplayer.cpp" />
 | 
				
			||||||
    <ClCompile Include="shader.cpp" />
 | 
					    <ClCompile Include="shader.cpp" />
 | 
				
			||||||
    <ClCompile Include="skybox.cpp" />
 | 
					    <ClCompile Include="skybox.cpp" />
 | 
				
			||||||
    <ClCompile Include="texture.cpp" />
 | 
					    <ClCompile Include="texture.cpp" />
 | 
				
			||||||
    <ClCompile Include="textureatlas.cpp" />
 | 
					    <ClCompile Include="textureatlas.cpp" />
 | 
				
			||||||
    <ClCompile Include="tool.cpp" />
 | 
					    <ClCompile Include="tool.cpp" />
 | 
				
			||||||
    <ClCompile Include="vertexbuffer.cpp" />
 | 
					    <ClCompile Include="vertexbuffer.cpp" />
 | 
				
			||||||
    <ClCompile Include="worldrenderer.cpp" />
 | 
					    <ClCompile Include="renderer.cpp" />
 | 
				
			||||||
  </ItemGroup>
 | 
					  </ItemGroup>
 | 
				
			||||||
  <ItemGroup>
 | 
					  <ItemGroup>
 | 
				
			||||||
    <ProjectReference Include="..\SQCSim-common\SQCSim-common.vcxproj">
 | 
					    <ProjectReference Include="..\SQCSim-common\SQCSim-common.vcxproj">
 | 
				
			||||||
@@ -130,7 +132,7 @@
 | 
				
			|||||||
      <WarningLevel>Level3</WarningLevel>
 | 
					      <WarningLevel>Level3</WarningLevel>
 | 
				
			||||||
      <Optimization>Disabled</Optimization>
 | 
					      <Optimization>Disabled</Optimization>
 | 
				
			||||||
      <PreprocessorDefinitions>WIN32;_DEBUG;_CONSOLE;NOMINMAX;%(PreprocessorDefinitions)</PreprocessorDefinitions>
 | 
					      <PreprocessorDefinitions>WIN32;_DEBUG;_CONSOLE;NOMINMAX;%(PreprocessorDefinitions)</PreprocessorDefinitions>
 | 
				
			||||||
      <LanguageStandard>stdcpp17</LanguageStandard>
 | 
					      <LanguageStandard>stdcpp20</LanguageStandard>
 | 
				
			||||||
    </ClCompile>
 | 
					    </ClCompile>
 | 
				
			||||||
    <Link>
 | 
					    <Link>
 | 
				
			||||||
      <SubSystem>Console</SubSystem>
 | 
					      <SubSystem>Console</SubSystem>
 | 
				
			||||||
@@ -145,7 +147,7 @@
 | 
				
			|||||||
      <WarningLevel>Level3</WarningLevel>
 | 
					      <WarningLevel>Level3</WarningLevel>
 | 
				
			||||||
      <Optimization>Disabled</Optimization>
 | 
					      <Optimization>Disabled</Optimization>
 | 
				
			||||||
      <PreprocessorDefinitions>WIN32;_DEBUG;_CONSOLE;NOMINMAX;%(PreprocessorDefinitions)</PreprocessorDefinitions>
 | 
					      <PreprocessorDefinitions>WIN32;_DEBUG;_CONSOLE;NOMINMAX;%(PreprocessorDefinitions)</PreprocessorDefinitions>
 | 
				
			||||||
      <LanguageStandard>stdcpp17</LanguageStandard>
 | 
					      <LanguageStandard>stdcpp20</LanguageStandard>
 | 
				
			||||||
    </ClCompile>
 | 
					    </ClCompile>
 | 
				
			||||||
    <Link>
 | 
					    <Link>
 | 
				
			||||||
      <SubSystem>Console</SubSystem>
 | 
					      <SubSystem>Console</SubSystem>
 | 
				
			||||||
@@ -162,7 +164,7 @@
 | 
				
			|||||||
      <FunctionLevelLinking>true</FunctionLevelLinking>
 | 
					      <FunctionLevelLinking>true</FunctionLevelLinking>
 | 
				
			||||||
      <IntrinsicFunctions>true</IntrinsicFunctions>
 | 
					      <IntrinsicFunctions>true</IntrinsicFunctions>
 | 
				
			||||||
      <PreprocessorDefinitions>WIN32;NDEBUG;_CONSOLE;NOMINMAX;%(PreprocessorDefinitions)</PreprocessorDefinitions>
 | 
					      <PreprocessorDefinitions>WIN32;NDEBUG;_CONSOLE;NOMINMAX;%(PreprocessorDefinitions)</PreprocessorDefinitions>
 | 
				
			||||||
      <LanguageStandard>stdcpp17</LanguageStandard>
 | 
					      <LanguageStandard>stdcpp20</LanguageStandard>
 | 
				
			||||||
      <InlineFunctionExpansion>AnySuitable</InlineFunctionExpansion>
 | 
					      <InlineFunctionExpansion>AnySuitable</InlineFunctionExpansion>
 | 
				
			||||||
      <FavorSizeOrSpeed>Speed</FavorSizeOrSpeed>
 | 
					      <FavorSizeOrSpeed>Speed</FavorSizeOrSpeed>
 | 
				
			||||||
      <FloatingPointModel>Fast</FloatingPointModel>
 | 
					      <FloatingPointModel>Fast</FloatingPointModel>
 | 
				
			||||||
@@ -184,7 +186,7 @@
 | 
				
			|||||||
      <FunctionLevelLinking>true</FunctionLevelLinking>
 | 
					      <FunctionLevelLinking>true</FunctionLevelLinking>
 | 
				
			||||||
      <IntrinsicFunctions>true</IntrinsicFunctions>
 | 
					      <IntrinsicFunctions>true</IntrinsicFunctions>
 | 
				
			||||||
      <PreprocessorDefinitions>WIN32;NDEBUG;_CONSOLE;NOMINMAX;%(PreprocessorDefinitions)</PreprocessorDefinitions>
 | 
					      <PreprocessorDefinitions>WIN32;NDEBUG;_CONSOLE;NOMINMAX;%(PreprocessorDefinitions)</PreprocessorDefinitions>
 | 
				
			||||||
      <LanguageStandard>stdcpp17</LanguageStandard>
 | 
					      <LanguageStandard>stdcpp20</LanguageStandard>
 | 
				
			||||||
      <InlineFunctionExpansion>AnySuitable</InlineFunctionExpansion>
 | 
					      <InlineFunctionExpansion>AnySuitable</InlineFunctionExpansion>
 | 
				
			||||||
      <FavorSizeOrSpeed>Speed</FavorSizeOrSpeed>
 | 
					      <FavorSizeOrSpeed>Speed</FavorSizeOrSpeed>
 | 
				
			||||||
      <FloatingPointModel>Fast</FloatingPointModel>
 | 
					      <FloatingPointModel>Fast</FloatingPointModel>
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -47,7 +47,10 @@
 | 
				
			|||||||
    <ClInclude Include="mesh.h">
 | 
					    <ClInclude Include="mesh.h">
 | 
				
			||||||
      <Filter>Fichiers d%27en-tête</Filter>
 | 
					      <Filter>Fichiers d%27en-tête</Filter>
 | 
				
			||||||
    </ClInclude>
 | 
					    </ClInclude>
 | 
				
			||||||
    <ClInclude Include="worldrenderer.h">
 | 
					    <ClInclude Include="renderer.h">
 | 
				
			||||||
 | 
					      <Filter>Fichiers d%27en-tête</Filter>
 | 
				
			||||||
 | 
					    </ClInclude>
 | 
				
			||||||
 | 
					    <ClInclude Include="remoteplayer.h">
 | 
				
			||||||
      <Filter>Fichiers d%27en-tête</Filter>
 | 
					      <Filter>Fichiers d%27en-tête</Filter>
 | 
				
			||||||
    </ClInclude>
 | 
					    </ClInclude>
 | 
				
			||||||
  </ItemGroup>
 | 
					  </ItemGroup>
 | 
				
			||||||
@@ -88,7 +91,10 @@
 | 
				
			|||||||
    <ClCompile Include="mesh.cpp">
 | 
					    <ClCompile Include="mesh.cpp">
 | 
				
			||||||
      <Filter>Fichiers sources</Filter>
 | 
					      <Filter>Fichiers sources</Filter>
 | 
				
			||||||
    </ClCompile>
 | 
					    </ClCompile>
 | 
				
			||||||
    <ClCompile Include="worldrenderer.cpp">
 | 
					    <ClCompile Include="renderer.cpp">
 | 
				
			||||||
 | 
					      <Filter>Fichiers sources</Filter>
 | 
				
			||||||
 | 
					    </ClCompile>
 | 
				
			||||||
 | 
					    <ClCompile Include="remoteplayer.cpp">
 | 
				
			||||||
      <Filter>Fichiers sources</Filter>
 | 
					      <Filter>Fichiers sources</Filter>
 | 
				
			||||||
    </ClCompile>
 | 
					    </ClCompile>
 | 
				
			||||||
  </ItemGroup>
 | 
					  </ItemGroup>
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -2,7 +2,7 @@ cmake_minimum_required(VERSION 3.18.4)
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
project(SQCSim-Client VERSION 0.8)
 | 
					project(SQCSim-Client VERSION 0.8)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
set(CMAKE_CXX_STANDARD 17)
 | 
					set(CMAKE_CXX_STANDARD 20)
 | 
				
			||||||
set(CMAKE_STANDARD_REQUIRED True)
 | 
					set(CMAKE_STANDARD_REQUIRED True)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
set(CMAKE_BUILD_DIRECTORY "./build")
 | 
					set(CMAKE_BUILD_DIRECTORY "./build")
 | 
				
			||||||
@@ -50,7 +50,8 @@ add_executable(SQCSim-client
 | 
				
			|||||||
			"../textureatlas.cpp"
 | 
								"../textureatlas.cpp"
 | 
				
			||||||
			"../tool.cpp"
 | 
								"../tool.cpp"
 | 
				
			||||||
			"../vertexbuffer.cpp"
 | 
								"../vertexbuffer.cpp"
 | 
				
			||||||
			"../worldrenderer.cpp"
 | 
								"../renderer.cpp"
 | 
				
			||||||
 | 
								"../remoteplayer.cpp"
 | 
				
			||||||
			"../main.cpp"
 | 
								"../main.cpp"
 | 
				
			||||||
			)
 | 
								)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -42,7 +42,7 @@ int Connector::Init() {
 | 
				
			|||||||
	return 0;
 | 
						return 0;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
int Connector::Connect(char* srv_addr, std::string name) {
 | 
					int Connector::Connect(const char* srv_addr, std::string name) {
 | 
				
			||||||
	sockaddr_in add;
 | 
						sockaddr_in add;
 | 
				
			||||||
	m_srvsockaddr.sin_family = AF_INET;
 | 
						m_srvsockaddr.sin_family = AF_INET;
 | 
				
			||||||
	m_srvsockaddr.sin_port = htons(SRV_PORT);
 | 
						m_srvsockaddr.sin_port = htons(SRV_PORT);
 | 
				
			||||||
@@ -54,44 +54,60 @@ int Connector::Connect(char* srv_addr, std::string name) {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
	if (connect(m_sock_tcp, (sockaddr*)&m_srvsockaddr, sizeof(m_srvsockaddr)) < 0) {
 | 
						if (connect(m_sock_tcp, (sockaddr*)&m_srvsockaddr, sizeof(m_srvsockaddr)) < 0) {
 | 
				
			||||||
		std::cout << "<EFBFBD>chec de la connexion." << std::endl;
 | 
							std::cout << "<EFBFBD>chec de la connexion." << std::endl;
 | 
				
			||||||
 | 
							return 2;
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	char* buf = new char[150];
 | 
						flag_t flag = 1;
 | 
				
			||||||
	uint32_t buflen = 150;
 | 
						if (ioctl(m_sock_tcp, SOCK_NONBLOCK, &flag) < 0) {
 | 
				
			||||||
 | 
							std::cout << "Impossible de mettre le socket en mode non-bloquant." << std::endl;
 | 
				
			||||||
 | 
							return 3;
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						netprot::Buffer bf;
 | 
				
			||||||
	netprot::LoginInfo log;
 | 
						netprot::LoginInfo log;
 | 
				
			||||||
	memcpy(&log.name, name.c_str(), name.size() + 1);
 | 
						strcpy(log.name, name.c_str());
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	netprot::Serialize(&log, &buf, &buflen);
 | 
						netprot::sendPack(m_sock_tcp, &log, &bf);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	int se = send(m_sock_tcp, buf, buflen, 0);
 | 
						bool ready = false;
 | 
				
			||||||
 | 
						int errors = 0;
 | 
				
			||||||
 | 
						std::vector<netprot::Packet> lsPck;
 | 
				
			||||||
 | 
						while (!ready) {
 | 
				
			||||||
 | 
							lsPck = netprot::recvPacks(m_sock_tcp, &bf);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	delete[] buf;
 | 
							for (auto& pck : lsPck) {
 | 
				
			||||||
	buf = new char[150] {0};
 | 
								bool bypass_delete = false;
 | 
				
			||||||
	buflen = 150;
 | 
								netprot::PlayerInfo* pl = nullptr;
 | 
				
			||||||
	int rpack = 0;
 | 
								switch (pck.type) {
 | 
				
			||||||
 | 
									using enum netprot::PACKET_TYPE;
 | 
				
			||||||
	while (rpack < 2) {
 | 
								case LOGINF:
 | 
				
			||||||
		recv(m_sock_tcp, buf, buflen, 0);
 | 
									m_loginfo = netprot::LoginInfo((netprot::LoginInfo*)pck.ptr);
 | 
				
			||||||
 | 
									break;
 | 
				
			||||||
		switch (netprot::getType(buf, buflen)) {
 | 
								case GAMEINFO:
 | 
				
			||||||
		case netprot::PACKET_TYPE::LOGINF:
 | 
									m_gameinfo = netprot::GameInfo((netprot::GameInfo*)pck.ptr);
 | 
				
			||||||
			if (!netprot::Deserialize(&m_loginfo, buf, buflen)) {
 | 
									break;
 | 
				
			||||||
				std::cout << "Packet LoginInfo invalide." << std::endl;
 | 
								case PLAYINF:
 | 
				
			||||||
				return 2;
 | 
									pl = (netprot::PlayerInfo*)pck.ptr;
 | 
				
			||||||
 | 
									m_players[pl->id] = pl;
 | 
				
			||||||
 | 
									bypass_delete = true;
 | 
				
			||||||
 | 
									break;
 | 
				
			||||||
 | 
								case TEAMINF:
 | 
				
			||||||
 | 
									// TODO: Faire dequoi avec TeamInfo si on fini par avoir des teams.
 | 
				
			||||||
 | 
									break;
 | 
				
			||||||
 | 
								case SYNC:
 | 
				
			||||||
 | 
									m_origin = netprot::Sync((netprot::Sync*)pck.ptr);
 | 
				
			||||||
 | 
									ready = true;
 | 
				
			||||||
 | 
									break;
 | 
				
			||||||
 | 
								default:
 | 
				
			||||||
 | 
									errors++;
 | 
				
			||||||
 | 
									break;
 | 
				
			||||||
			}
 | 
								}
 | 
				
			||||||
			++rpack;
 | 
								if (!bypass_delete)
 | 
				
			||||||
			break;
 | 
									netprot::emptyPack(pck);
 | 
				
			||||||
		case netprot::PACKET_TYPE::GAMEINFO:
 | 
					 | 
				
			||||||
			if (!netprot::Deserialize(&m_gameinfo, buf, buflen)) {
 | 
					 | 
				
			||||||
				std::cout << "Packet GameInfo invalide." << std::endl;
 | 
					 | 
				
			||||||
				return 3;
 | 
					 | 
				
			||||||
			}
 | 
					 | 
				
			||||||
			++rpack;
 | 
					 | 
				
			||||||
			break;
 | 
					 | 
				
			||||||
		default:
 | 
					 | 
				
			||||||
			std::cout << "Packet invalide." << std::endl;
 | 
					 | 
				
			||||||
			break;
 | 
					 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
 | 
							lsPck.clear();
 | 
				
			||||||
 | 
							if (errors > 100)
 | 
				
			||||||
 | 
								return 4;
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	return 0;
 | 
						return 0;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
@@ -99,3 +115,5 @@ int Connector::Connect(char* srv_addr, std::string name) {
 | 
				
			|||||||
uint64_t Connector::getId() const { return m_loginfo.sid; }
 | 
					uint64_t Connector::getId() const { return m_loginfo.sid; }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
unsigned int Connector::getSeed() const { return m_gameinfo.seed; }
 | 
					unsigned int Connector::getSeed() const { return m_gameinfo.seed; }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					netprot::Sync Connector::getOrigin() const { return m_origin; }
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -11,26 +11,32 @@ public:
 | 
				
			|||||||
	~Connector();
 | 
						~Connector();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	int Init();
 | 
						int Init();
 | 
				
			||||||
	int Connect(char* srv_addr, std::string name);
 | 
						int Connect(const char* srv_addr, std::string name);
 | 
				
			||||||
	uint64_t getId() const;
 | 
						uint64_t getId() const;
 | 
				
			||||||
	unsigned int getSeed() const;
 | 
						unsigned int getSeed() const;
 | 
				
			||||||
 | 
						netprot::Sync getOrigin() const;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	//void SendInput();
 | 
						//void SendInput();
 | 
				
			||||||
	//int Sync();
 | 
						//int Sync();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						SOCKET m_sock_udp = 0,
 | 
				
			||||||
 | 
							m_sock_tcp = 0;
 | 
				
			||||||
 | 
						sockaddr_in m_srvsockaddr;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						// void updateRemotePlayers(std::map<RemotePlayers> rplayers);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						std::map<uint64_t, netprot::PlayerInfo> m_players;
 | 
				
			||||||
private:
 | 
					private:
 | 
				
			||||||
#ifdef _WIN32
 | 
					#ifdef _WIN32
 | 
				
			||||||
	WSADATA m_wsaData;
 | 
						WSADATA m_wsaData;
 | 
				
			||||||
#endif
 | 
					#endif
 | 
				
			||||||
	std::map<Timestamp, netprot::Input> m_inputmanifest;
 | 
						std::map<Timestamp, netprot::Input> m_inputmanifest;
 | 
				
			||||||
	std::map<uint64_t, netprot::PlayerInfo> m_players;
 | 
					 | 
				
			||||||
	std::map<uint64_t, netprot::TeamInfo> m_teams;
 | 
						std::map<uint64_t, netprot::TeamInfo> m_teams;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	netprot::LoginInfo m_loginfo;
 | 
						netprot::LoginInfo m_loginfo;
 | 
				
			||||||
	netprot::GameInfo m_gameinfo;
 | 
						netprot::GameInfo m_gameinfo;
 | 
				
			||||||
 | 
						netprot::Sync m_origin;
 | 
				
			||||||
	sockaddr_in m_srvsockaddr;
 | 
					 | 
				
			||||||
	SOCKET m_sock_udp = 0,
 | 
					 | 
				
			||||||
		   m_sock_tcp = 0;
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
#endif
 | 
					#endif
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -20,7 +20,6 @@
 | 
				
			|||||||
#include <climits>
 | 
					#include <climits>
 | 
				
			||||||
#endif
 | 
					#endif
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#define NETWORK_TEST false
 | 
					 | 
				
			||||||
#define SRV_ADDR "127.0.0.1"
 | 
					#define SRV_ADDR "127.0.0.1"
 | 
				
			||||||
#define COUNTDOWN 300
 | 
					#define COUNTDOWN 300
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -5,8 +5,6 @@
 | 
				
			|||||||
#include <thread>
 | 
					#include <thread>
 | 
				
			||||||
#include <queue>
 | 
					#include <queue>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
// Define a structure to represent notifications
 | 
					// Define a structure to represent notifications
 | 
				
			||||||
struct Notification {
 | 
					struct Notification {
 | 
				
			||||||
	std::string message;
 | 
						std::string message;
 | 
				
			||||||
@@ -281,8 +279,11 @@ void Engine::Init() {
 | 
				
			|||||||
		abort();
 | 
							abort();
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						uint64_t seed = SEED;
 | 
				
			||||||
 | 
						char ch;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	glDisable(GL_FRAMEBUFFER_SRGB);
 | 
						glDisable(GL_FRAMEBUFFER_SRGB);
 | 
				
			||||||
	glEnable(GL_DEPTH_TEST);
 | 
						glEnable(GL_DEPTH_TEST); 
 | 
				
			||||||
	glEnable(GL_STENCIL_TEST);
 | 
						glEnable(GL_STENCIL_TEST);
 | 
				
			||||||
	glEnable(GL_POINT_SMOOTH);
 | 
						glEnable(GL_POINT_SMOOTH);
 | 
				
			||||||
	glEnable(GL_BLEND);
 | 
						glEnable(GL_BLEND);
 | 
				
			||||||
@@ -310,31 +311,59 @@ void Engine::Init() {
 | 
				
			|||||||
	// Array pour les balles.
 | 
						// Array pour les balles.
 | 
				
			||||||
	for (int x = 0; x < MAX_BULLETS; ++x) {
 | 
						for (int x = 0; x < MAX_BULLETS; ++x) {
 | 
				
			||||||
		m_bullets[x] = nullptr;
 | 
							m_bullets[x] = nullptr;
 | 
				
			||||||
		m_whoosh[x] = nullptr; // = m_audio.m_engine.m_audio.m_engine->addSoundSourceFromFile(AUDIO_PATH "noise.ogg", irrklang::ESM_AUTO_DETECT, false);
 | 
							m_whoosh[x] = nullptr;
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	uint64_t seed = SEED;
 | 
							std::cout << "Jouer en ligne? [o/N] ";
 | 
				
			||||||
	std::string playname = "La Chienne <20> Jacques";
 | 
							std::cin >> ch;
 | 
				
			||||||
	if (NETWORK_TEST) { // Test connexion r<>seau.
 | 
							std::cout << std::endl;
 | 
				
			||||||
		if (!m_conn.Init()) {
 | 
					
 | 
				
			||||||
			if (!m_conn.Connect(SRV_ADDR, playname)) {
 | 
							if (ch == 'o' || ch == 'O') {
 | 
				
			||||||
				// setup jeu en r<>seau.
 | 
								char* input = new char[32];
 | 
				
			||||||
				std::cout << "ID re<72>u du serveur: " << std::to_string(m_conn.getId()) << "!" << std::endl;
 | 
								std::string playname, srvname;
 | 
				
			||||||
				std::cout << "Seed re<72>u du serveur: " << std::to_string(m_conn.getSeed()) << "!" << std::endl;
 | 
					
 | 
				
			||||||
				seed = m_conn.getSeed();
 | 
								while (playname.size() < 1) {
 | 
				
			||||||
 | 
									std::cout << "Veuillez entrer un nom de joueur: ";
 | 
				
			||||||
 | 
									std::cin.ignore();
 | 
				
			||||||
 | 
									std::cin.getline(input, 32);
 | 
				
			||||||
 | 
									std::cout << std::endl;
 | 
				
			||||||
 | 
									playname = input;
 | 
				
			||||||
 | 
									if (playname.size() < 1 || playname.size() > 32)
 | 
				
			||||||
 | 
										std::puts("Nom invalide.");
 | 
				
			||||||
			}
 | 
								}
 | 
				
			||||||
			else std::cout << "Erreur de connexion." << std::endl;
 | 
								while (srvname.size() < 1) {
 | 
				
			||||||
 | 
									std::cout << "Veuillez entrer une adresse de serveur: ";
 | 
				
			||||||
 | 
									std::cin.getline(input, 32);
 | 
				
			||||||
 | 
									std::cout << std::endl;
 | 
				
			||||||
 | 
									srvname = input;
 | 
				
			||||||
 | 
									if (srvname.size() < 1 || srvname.size() > 32)
 | 
				
			||||||
 | 
										std::puts("Adresse serveur invalide.");
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
								delete[] input;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
								if (!m_conn.Init()) {
 | 
				
			||||||
 | 
									if (!m_conn.Connect(srvname.c_str(), playname)) {
 | 
				
			||||||
 | 
										// setup jeu en reseau.
 | 
				
			||||||
 | 
										std::cout << "ID recu du serveur: " << std::to_string(m_conn.getId()) << "!" << std::endl;
 | 
				
			||||||
 | 
										std::cout << "Seed recu du serveur: " << std::to_string(m_conn.getSeed()) << "!" << std::endl;
 | 
				
			||||||
 | 
										m_player = Player(m_conn.getOrigin().position);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
										for (auto& [key, player] : m_conn.m_players)
 | 
				
			||||||
 | 
											m_players[key] = new RemotePlayer(player);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
										seed = m_conn.getSeed();
 | 
				
			||||||
 | 
										m_networkgame = true;
 | 
				
			||||||
 | 
									}
 | 
				
			||||||
 | 
									else std::cout << "Erreur de connexion." << std::endl;
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
								else std::cout << "Erreur de creation de socket." << std::endl;
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
		else std::cout << "Erreur de cr<63>ation de socket." << std::endl;
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
	m_world.SetSeed(seed);
 | 
						m_world.SetSeed(seed);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	// Init Chunks
 | 
						// Init Chunks
 | 
				
			||||||
	m_world.GetChunks().Reset(nullptr);
 | 
						m_world.GetChunks().Reset(nullptr);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	// Gestion de souris.
 | 
						// Gestion de souris.
 | 
				
			||||||
	CenterMouse();
 | 
						CenterMouse();
 | 
				
			||||||
	HideCursor();
 | 
						HideCursor();
 | 
				
			||||||
@@ -346,7 +375,10 @@ void Engine::LoadResource() {
 | 
				
			|||||||
	LoadTexture(m_skybox.GetTexture(), TEXTURE_PATH "skybox.png", true);
 | 
						LoadTexture(m_skybox.GetTexture(), TEXTURE_PATH "skybox.png", true);
 | 
				
			||||||
	LoadTexture(m_textureCrosshair, TEXTURE_PATH "cross.bmp", true);
 | 
						LoadTexture(m_textureCrosshair, TEXTURE_PATH "cross.bmp", true);
 | 
				
			||||||
	LoadTexture(m_textureFont, TEXTURE_PATH "font.bmp", true);
 | 
						LoadTexture(m_textureFont, TEXTURE_PATH "font.bmp", true);
 | 
				
			||||||
	LoadTexture(m_textureGun, TEXTURE_PATH "gun01.png", true);
 | 
						LoadTexture(m_textureGun, TEXTURE_PATH "gun01.png", false);
 | 
				
			||||||
 | 
						LoadTexture(m_texturePovGun, TEXTURE_PATH "GUN.png", false);
 | 
				
			||||||
 | 
						LoadTexture(m_textureSoloMultiMenu, TEXTURE_PATH "single_multi.png", false);
 | 
				
			||||||
 | 
						LoadTexture(m_textureTitle, TEXTURE_PATH "title.png", false);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	LoadTexture(MenuTitleTexture, MENU_ITEM_PATH "test.png");
 | 
						LoadTexture(MenuTitleTexture, MENU_ITEM_PATH "test.png");
 | 
				
			||||||
	LoadTexture(MenuBGTexture, MENU_ITEM_PATH "test.png");
 | 
						LoadTexture(MenuBGTexture, MENU_ITEM_PATH "test.png");
 | 
				
			||||||
@@ -388,6 +420,12 @@ void Engine::LoadResource() {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
void Engine::UnloadResource() {}
 | 
					void Engine::UnloadResource() {}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					void Engine::InstantDamage()
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
						m_player.InflictDamage(0.10f);
 | 
				
			||||||
 | 
						m_damage = false;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void Engine::SystemNotification(std::string systemLog) {
 | 
					void Engine::SystemNotification(std::string systemLog) {
 | 
				
			||||||
	std::string message = "";
 | 
						std::string message = "";
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -403,7 +441,6 @@ void Engine::KillNotification(Player killer, Player killed) {
 | 
				
			|||||||
	DisplayNotification(message);
 | 
						DisplayNotification(message);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					 | 
				
			||||||
void Engine::DisplayNotification(std::string message) {
 | 
					void Engine::DisplayNotification(std::string message) {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if (message.length() > 45) {
 | 
						if (message.length() > 45) {
 | 
				
			||||||
@@ -413,23 +450,28 @@ void Engine::DisplayNotification(std::string message) {
 | 
				
			|||||||
	Notification newNotification;
 | 
						Notification newNotification;
 | 
				
			||||||
	newNotification.message = message;
 | 
						newNotification.message = message;
 | 
				
			||||||
	newNotification.displayStartTime = m_time;
 | 
						newNotification.displayStartTime = m_time;
 | 
				
			||||||
	
 | 
					
 | 
				
			||||||
	notifications.push_back(newNotification);
 | 
						notifications.push_back(newNotification);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// Add a method to process the notification queue
 | 
					// Add a method to process the notification queue
 | 
				
			||||||
void Engine::ProcessNotificationQueue() {
 | 
					void Engine::ProcessNotificationQueue() {
 | 
				
			||||||
	m_textureFont.Bind();
 | 
						//PrintText(fPosX, fUsernamePosY, ss.str(), 1.5f);
 | 
				
			||||||
	float scale = GetScale();
 | 
						//float fPosX = (Width() / 100.0f) * scaleX;
 | 
				
			||||||
	unsigned int xOffset = Width() - Width() * 0.26;
 | 
						//float fPosY = Height() - (Height() * 0.05) * scaleY;
 | 
				
			||||||
	unsigned int yOffset = Height() - (Height() / 2.2);
 | 
					
 | 
				
			||||||
 | 
						m_textureFont.Bind();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						auto [scaleX, scaleY] = GetScale();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						float xOffset = (Width() / 1.5f) * scaleX;
 | 
				
			||||||
 | 
						float yOffset = (Height() / 1.2f) * scaleY;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	// Iterate through the notifications and display them
 | 
					 | 
				
			||||||
	for (auto it = notifications.begin(); it != notifications.end(); ) {
 | 
						for (auto it = notifications.begin(); it != notifications.end(); ) {
 | 
				
			||||||
		float timeSinceDisplay = m_time - it->displayStartTime;
 | 
							float timeSinceDisplay = m_time - it->displayStartTime;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		// Display the notification message with vertical offset
 | 
							float y = yOffset - (20.0f * scaleX * (it - notifications.begin()));
 | 
				
			||||||
		unsigned int y = yOffset - (static_cast<unsigned int>(scale * 20) * (it - notifications.begin()));
 | 
					
 | 
				
			||||||
		glDisable(GL_STENCIL_TEST);
 | 
							glDisable(GL_STENCIL_TEST);
 | 
				
			||||||
		glDisable(GL_DEPTH_TEST);
 | 
							glDisable(GL_DEPTH_TEST);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -444,8 +486,8 @@ void Engine::ProcessNotificationQueue() {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
		glMatrixMode(GL_MODELVIEW);
 | 
							glMatrixMode(GL_MODELVIEW);
 | 
				
			||||||
		glPushMatrix();
 | 
							glPushMatrix();
 | 
				
			||||||
		
 | 
					
 | 
				
			||||||
		PrintText(xOffset, y, scale, it->message);
 | 
							PrintText(xOffset, y, it->message);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		glBlendFunc(GL_CONSTANT_COLOR, GL_ONE_MINUS_CONSTANT_COLOR);
 | 
							glBlendFunc(GL_CONSTANT_COLOR, GL_ONE_MINUS_CONSTANT_COLOR);
 | 
				
			||||||
		glBlendEquation(GL_FUNC_SUBTRACT);
 | 
							glBlendEquation(GL_FUNC_SUBTRACT);
 | 
				
			||||||
@@ -455,39 +497,89 @@ void Engine::ProcessNotificationQueue() {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
		glMatrixMode(GL_PROJECTION);
 | 
							glMatrixMode(GL_PROJECTION);
 | 
				
			||||||
		glPopMatrix();
 | 
							glPopMatrix();
 | 
				
			||||||
 | 
					 | 
				
			||||||
		glMatrixMode(GL_MODELVIEW);
 | 
							glMatrixMode(GL_MODELVIEW);
 | 
				
			||||||
		glPopMatrix();
 | 
							glPopMatrix();
 | 
				
			||||||
		// Check if it's time to remove the notification (display for 2 seconds)
 | 
					
 | 
				
			||||||
		if (timeSinceDisplay >= 4.0f) {
 | 
							if (timeSinceDisplay >= 4.0f) {
 | 
				
			||||||
			it = notifications.erase(it);  // Remove the notification
 | 
								it = notifications.erase(it);
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
		else {
 | 
							else {
 | 
				
			||||||
			++it;
 | 
								++it;
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	
 | 
					 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
void Engine::DisplayCrosshair() {
 | 
					void Engine::DisplayCrosshair() {
 | 
				
			||||||
	m_textureCrosshair.Bind();
 | 
						m_textureCrosshair.Bind();
 | 
				
			||||||
	static const int crossSize = 32;
 | 
						static const int crossSize = 32;
 | 
				
			||||||
	glLoadIdentity();
 | 
						glLoadIdentity();
 | 
				
			||||||
	glTranslated(Width() / 2 - crossSize / 2, Height() / 2 - crossSize / 2, 0);
 | 
						glTranslated(Width() / 2 - crossSize / 2, Height() / 2 - crossSize / 2, 0);
 | 
				
			||||||
	glBegin(GL_QUADS);
 | 
						glBegin(GL_QUADS);
 | 
				
			||||||
		glTexCoord2f(0, 0);
 | 
						glTexCoord2f(0, 0);
 | 
				
			||||||
		glVertex2i(0, 0);
 | 
						glVertex2i(0, 0);
 | 
				
			||||||
		glTexCoord2f(1, 0);
 | 
						glTexCoord2f(1, 0);
 | 
				
			||||||
		glVertex2i(crossSize, 0);
 | 
						glVertex2i(crossSize, 0);
 | 
				
			||||||
		glTexCoord2f(1, 1);
 | 
						glTexCoord2f(1, 1);
 | 
				
			||||||
		glVertex2i(crossSize, crossSize);
 | 
						glVertex2i(crossSize, crossSize);
 | 
				
			||||||
		glTexCoord2f(0, 1);
 | 
						glTexCoord2f(0, 1);
 | 
				
			||||||
		glVertex2i(0, crossSize);
 | 
						glVertex2i(0, crossSize);
 | 
				
			||||||
	glEnd();
 | 
						glEnd();
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					void Engine::DisplayPovGun() {
 | 
				
			||||||
 | 
						// Setter le blend function, tout ce qui sera noir sera transparent
 | 
				
			||||||
 | 
						glDisable(GL_STENCIL_TEST);
 | 
				
			||||||
 | 
						glDisable(GL_DEPTH_TEST);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
 | 
				
			||||||
 | 
						glBlendEquation(GL_FUNC_ADD);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						glMatrixMode(GL_PROJECTION);
 | 
				
			||||||
 | 
						glPushMatrix();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						glLoadIdentity();
 | 
				
			||||||
 | 
						glOrtho(0, Width(), 0, Height(), -1, 1);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						glMatrixMode(GL_MODELVIEW);
 | 
				
			||||||
 | 
						glPushMatrix();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						float scaleX = (Width()) / BASE_WIDTH;
 | 
				
			||||||
 | 
						float scaleY = (Height()) / BASE_HEIGHT;
 | 
				
			||||||
 | 
						float baseXOffset = 0.4958 * BASE_WIDTH;
 | 
				
			||||||
 | 
						float baseWidth = 0.4688 * BASE_WIDTH;
 | 
				
			||||||
 | 
						float baseHeight = 0.5787 * BASE_HEIGHT;
 | 
				
			||||||
 | 
						float xTranslation = baseXOffset * scaleX;
 | 
				
			||||||
 | 
						float quadWidth = baseWidth * scaleX;
 | 
				
			||||||
 | 
						float quadHeight = baseHeight * scaleY;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						m_texturePovGun.Bind();
 | 
				
			||||||
 | 
						glLoadIdentity();
 | 
				
			||||||
 | 
						glTranslated(xTranslation, 0, 0);
 | 
				
			||||||
 | 
						glBegin(GL_QUADS);
 | 
				
			||||||
 | 
						glTexCoord2f(0, 0);
 | 
				
			||||||
 | 
						glVertex2i(0, 0);
 | 
				
			||||||
 | 
						glTexCoord2f(1, 0);
 | 
				
			||||||
 | 
						glVertex2i(quadWidth, 0);
 | 
				
			||||||
 | 
						glTexCoord2f(1, 1);
 | 
				
			||||||
 | 
						glVertex2i(quadWidth, quadHeight);
 | 
				
			||||||
 | 
						glTexCoord2f(0, 1);
 | 
				
			||||||
 | 
						glVertex2i(0, quadHeight);
 | 
				
			||||||
 | 
						glEnd();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						// Reset du blend function
 | 
				
			||||||
 | 
						glBlendFunc(GL_CONSTANT_COLOR, GL_ONE_MINUS_CONSTANT_COLOR);
 | 
				
			||||||
 | 
						glBlendEquation(GL_FUNC_SUBTRACT);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						glEnable(GL_STENCIL_TEST);
 | 
				
			||||||
 | 
						glEnable(GL_DEPTH_TEST);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						glMatrixMode(GL_PROJECTION);
 | 
				
			||||||
 | 
						glPopMatrix();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						glMatrixMode(GL_MODELVIEW);
 | 
				
			||||||
 | 
						glPopMatrix();
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void Engine::DisplayCurrentItem() {
 | 
					void Engine::DisplayCurrentItem() {
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -495,55 +587,68 @@ void Engine::DisplayCurrentItem() {
 | 
				
			|||||||
void Engine::DisplayHud(int timer) {
 | 
					void Engine::DisplayHud(int timer) {
 | 
				
			||||||
	glBindTexture(GL_TEXTURE_2D, 0);
 | 
						glBindTexture(GL_TEXTURE_2D, 0);
 | 
				
			||||||
	glLoadIdentity();
 | 
						glLoadIdentity();
 | 
				
			||||||
	glDisable(GL_BLEND);
 | 
						glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
 | 
				
			||||||
 | 
						auto [scaleX, scaleY] = GetScale();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						float fBackPosX = (Width() / 25.0f) * scaleX;
 | 
				
			||||||
 | 
						float fBackPosY = (Height() - (Height() * 0.815) * scaleY);
 | 
				
			||||||
 | 
						float fBackWidth = (Width() / 4.0f) * scaleX;
 | 
				
			||||||
 | 
						float fBackHeight = (Height() / 5.5f) * scaleY;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						glColor4f(1.0f, 1.0f, 1.0f, 0.2f);
 | 
				
			||||||
 | 
						glBegin(GL_QUADS);
 | 
				
			||||||
 | 
						glVertex2f(fBackPosX, fBackPosY);
 | 
				
			||||||
 | 
						glVertex2f(fBackPosX + fBackWidth, fBackPosY);
 | 
				
			||||||
 | 
						glVertex2f(fBackPosX + fBackWidth, fBackPosY + fBackHeight);
 | 
				
			||||||
 | 
						glVertex2f(fBackPosX, fBackPosY + fBackHeight);
 | 
				
			||||||
 | 
						glEnd();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						// HP Bar
 | 
				
			||||||
 | 
						float fBarWidth = (Width() / 4.0f) * scaleX;
 | 
				
			||||||
 | 
						float fBarHeight = (Height() / 25.0f) * scaleY;
 | 
				
			||||||
 | 
						float fPosX = (Width() / 25.0f) * scaleX;
 | 
				
			||||||
 | 
						float fBarPosY = (Height() - (Height() * 0.775) * scaleY);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	// Barre HP
 | 
					 | 
				
			||||||
	float fBarWidth = Width() / 4;
 | 
					 | 
				
			||||||
	float fBarHeight = Height() / 25;
 | 
					 | 
				
			||||||
	float fPosX = Width() / 20;
 | 
					 | 
				
			||||||
	float fPosY = Height() - (Height() - (fBarHeight * 4));
 | 
					 | 
				
			||||||
	float playerHp = m_player.GetHP();
 | 
						float playerHp = m_player.GetHP();
 | 
				
			||||||
	float facteurOmbrage = m_displayInfo ? 0.5f : 1.0f;
 | 
						float facteurOmbrage = m_displayInfo ? 0.5f : 1.0f;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	// Arri<EFBFBD>re-plan (Barre HP)
 | 
						// HP Bar Background
 | 
				
			||||||
	glColor3f(1.0f * facteurOmbrage, 1.0f * facteurOmbrage, 1.0f * facteurOmbrage);
 | 
						glColor3f(1.0f * facteurOmbrage, 1.0f * facteurOmbrage, 1.0f * facteurOmbrage);
 | 
				
			||||||
	glBegin(GL_QUADS);
 | 
						glBegin(GL_QUADS);
 | 
				
			||||||
		glVertex2f(fPosX, fPosY - fBarHeight);				// Bas-Gauche
 | 
						glVertex2f(fPosX, fBarPosY - fBarHeight);
 | 
				
			||||||
		glVertex2f(fPosX + fBarWidth, fPosY - fBarHeight);  // Bas-Droite
 | 
						glVertex2f(fPosX + fBarWidth, fBarPosY - fBarHeight);
 | 
				
			||||||
		glVertex2f(fPosX + fBarWidth, fPosY);				// Haut-Droite
 | 
						glVertex2f(fPosX + fBarWidth, fBarPosY);
 | 
				
			||||||
		glVertex2f(fPosX, fPosY);							// Haut-Gauche
 | 
						glVertex2f(fPosX, fBarPosY);
 | 
				
			||||||
	glEnd();
 | 
						glEnd();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	//TODO: Associer avec m<EFBFBD>chanique de vie du joueur
 | 
						//TODO: Associer avec mechanique de vie du joueur
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	// Barre HP
 | 
						// Barre HP
 | 
				
			||||||
	glColor3f(0.0f * facteurOmbrage, 1.0f * facteurOmbrage, 0.0f * facteurOmbrage);
 | 
						glColor3f(0.0f * facteurOmbrage, 1.0f * facteurOmbrage, 0.0f * facteurOmbrage);
 | 
				
			||||||
	glBegin(GL_QUADS);
 | 
						glBegin(GL_QUADS);
 | 
				
			||||||
		glVertex2f(fPosX, fPosY - fBarHeight);							// Bas-Gauche
 | 
						glVertex2f(fPosX, fBarPosY - fBarHeight);
 | 
				
			||||||
		glVertex2f(fPosX + fBarWidth * playerHp, fPosY - fBarHeight);	// Bas-Droite
 | 
						glVertex2f(fPosX + fBarWidth * playerHp, fBarPosY - fBarHeight);
 | 
				
			||||||
		glVertex2f(fPosX + fBarWidth * playerHp, fPosY);				// Haut-Droite
 | 
						glVertex2f(fPosX + fBarWidth * playerHp, fBarPosY);
 | 
				
			||||||
		glVertex2f(fPosX, fPosY);										// Haut-Gauche
 | 
						glVertex2f(fPosX, fBarPosY);
 | 
				
			||||||
	glEnd();
 | 
						glEnd();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	// Barre <20>quip
 | 
						// Equip Bar
 | 
				
			||||||
	glEnable(GL_BLEND);
 | 
						glEnable(GL_BLEND);
 | 
				
			||||||
	glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
 | 
						glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
 | 
				
			||||||
	glColor3f(1.0f * facteurOmbrage, 1.0f * facteurOmbrage, 1.0f * facteurOmbrage);
 | 
						glColor3f(1.0f * facteurOmbrage, 1.0f * facteurOmbrage, 1.0f * facteurOmbrage);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						float fEquipWidth = (Width() * 0.175f) * scaleX;
 | 
				
			||||||
 | 
						float fEquipHeight = (fEquipWidth / 2.5) * scaleY;
 | 
				
			||||||
 | 
						float fEquipPosY = (Height() - (Height() * 0.765) * scaleY);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						glTranslatef(fPosX, fEquipPosY, 0);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	m_textureGun.Bind();
 | 
						m_textureGun.Bind();
 | 
				
			||||||
 | 
					 | 
				
			||||||
	float margin = Width() * 0.05;
 | 
					 | 
				
			||||||
	float itemWidth = Width() * 0.33;
 | 
					 | 
				
			||||||
	float itemHeight = itemWidth / 2.208;
 | 
					 | 
				
			||||||
	float startX = Width() - itemWidth - margin;
 | 
					 | 
				
			||||||
	float startY = margin;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	glTranslated(startX, startY, 0);
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	glBegin(GL_QUADS);
 | 
						glBegin(GL_QUADS);
 | 
				
			||||||
	glTexCoord2f(1, 0); glVertex2i(0, 0);
 | 
						glTexCoord2f(0, 0); glVertex2i(0, 0);
 | 
				
			||||||
	glTexCoord2f(0, 0); glVertex2i(itemWidth, 0);
 | 
						glTexCoord2f(1, 0); glVertex2i(fEquipWidth, 0);
 | 
				
			||||||
	glTexCoord2f(0, 1); glVertex2i(itemWidth, itemHeight);
 | 
						glTexCoord2f(1, 1); glVertex2i(fEquipWidth, fEquipHeight);
 | 
				
			||||||
	glTexCoord2f(1, 1); glVertex2i(0, itemHeight);
 | 
						glTexCoord2f(0, 1); glVertex2i(0, fEquipHeight);
 | 
				
			||||||
	glEnd();
 | 
						glEnd();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	//glDisable(GL_BLEND);
 | 
						//glDisable(GL_BLEND);
 | 
				
			||||||
@@ -551,54 +656,161 @@ void Engine::DisplayHud(int timer) {
 | 
				
			|||||||
	// Username
 | 
						// Username
 | 
				
			||||||
	glEnable(GL_BLEND);
 | 
						glEnable(GL_BLEND);
 | 
				
			||||||
	glBlendFunc(GL_SRC_ALPHA, GL_ONE);
 | 
						glBlendFunc(GL_SRC_ALPHA, GL_ONE);
 | 
				
			||||||
 | 
					 | 
				
			||||||
	glColor3f(1.0f, 1.0f, 1.0f);
 | 
						glColor3f(1.0f, 1.0f, 1.0f);
 | 
				
			||||||
	float scale = GetScale();
 | 
					
 | 
				
			||||||
	m_textureFont.Bind();
 | 
						m_textureFont.Bind();
 | 
				
			||||||
	std::ostringstream ss;
 | 
						std::ostringstream ss;
 | 
				
			||||||
	ss << m_player.GetUsername();
 | 
						float fUsernamePosY = fBarPosY - (fBarHeight * 2) * scaleY;
 | 
				
			||||||
	PrintText(fPosX, fPosY, scale, ss.str());
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
	//Countdown
 | 
						ss.str("");
 | 
				
			||||||
 | 
						ss << m_player.GetUsername();
 | 
				
			||||||
 | 
						PrintText(fPosX, fUsernamePosY, ss.str(), 1.5f);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						ss.str("");
 | 
				
			||||||
 | 
						ss << m_player.GetHP() * 100 << "%";
 | 
				
			||||||
 | 
						PrintText(fPosX * 6.25, fUsernamePosY, ss.str(), 1.5f);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						// Countdown
 | 
				
			||||||
	ss.str("");
 | 
						ss.str("");
 | 
				
			||||||
	ss << "Time: " << (int)(timer / 60) << ":" << std::setw(2) << std::setfill('0') << timer % 60;
 | 
						ss << "Time: " << (int)(timer / 60) << ":" << std::setw(2) << std::setfill('0') << timer % 60;
 | 
				
			||||||
	PrintText(Width() - Width() * 0.15, Height() - (Height() / 19.2), scale, ss.str());
 | 
						PrintText(Width() - (Width() * 0.2f) * scaleX, Height() - (Height() * 0.1) * scaleY, ss.str(), 2.0f);
 | 
				
			||||||
	
 | 
					 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void Engine::DisplayInfo(float elapsedTime, BlockType bloc) {
 | 
					void Engine::DisplayInfo(float elapsedTime, BlockType bloc) {
 | 
				
			||||||
	// Bind de la texture pour le font
 | 
					 | 
				
			||||||
	m_textureFont.Bind();
 | 
						m_textureFont.Bind();
 | 
				
			||||||
	std::ostringstream ss;
 | 
						std::ostringstream ss;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	float scale = GetScale();
 | 
						auto [scaleX, scaleY] = GetScale();
 | 
				
			||||||
	unsigned int x = Width() / 25;
 | 
					
 | 
				
			||||||
 | 
						float fPosX = (Width() / 100.0f) * scaleX;
 | 
				
			||||||
 | 
						float fPosY = Height() - (Height() * 0.05) * scaleY;
 | 
				
			||||||
 | 
						float charSize = 20 + (24 - 20) * (Width() - 1600) / (1920 - 1600);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	ss << " Fps : " << GetFps(elapsedTime);
 | 
						ss << " Fps : " << GetFps(elapsedTime);
 | 
				
			||||||
	PrintText(x, Height() - (Height() / 19.2), scale, ss.str());
 | 
						PrintText(fPosX, fPosY, ss.str());
 | 
				
			||||||
	ss.str("");
 | 
						ss.str("");
 | 
				
			||||||
 | 
						fPosY -= charSize;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	ss << " Rendered Chunks : " << m_renderCount;
 | 
						ss << " Rendered Chunks : " << m_renderCount;
 | 
				
			||||||
	PrintText(x, Height() - (Height() / 13.7), scale, ss.str());
 | 
						PrintText(fPosX, fPosY, ss.str());
 | 
				
			||||||
	ss.str("");
 | 
						ss.str("");
 | 
				
			||||||
 | 
						fPosY -= charSize;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	ss << " To-Be-Deleted Chunks : " << m_world.GettbDeleted();
 | 
						ss << " To-Be-Deleted Chunks : " << m_world.GettbDeleted();
 | 
				
			||||||
	PrintText(x, Height() - (Height() / 10.7), scale, ss.str());
 | 
						PrintText(fPosX, fPosY, ss.str());
 | 
				
			||||||
	ss.str("");
 | 
						ss.str("");
 | 
				
			||||||
	ss << " Velocity  : " << m_player.GetVelocity(); // IMPORTANT : on utilise l <20> operateur << pour afficher la position
 | 
						fPosY -= charSize;
 | 
				
			||||||
	PrintText(x, Height() / 48, scale, ss.str());
 | 
					
 | 
				
			||||||
 | 
						float fPosYJump = ((Height() - (Height() * 0.9f)) * scaleY);
 | 
				
			||||||
 | 
						fPosY = fPosYJump;
 | 
				
			||||||
 | 
						fPosY -= charSize;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						ss << " Velocity  : " << m_player.GetVelocity();
 | 
				
			||||||
 | 
						PrintText(fPosX, fPosY, ss.str());
 | 
				
			||||||
	ss.str("");
 | 
						ss.str("");
 | 
				
			||||||
 | 
						fPosY -= charSize;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	ss << " Direction : " << m_player.GetDirection();
 | 
						ss << " Direction : " << m_player.GetDirection();
 | 
				
			||||||
	PrintText(x, Height() / 24, scale, ss.str());
 | 
						PrintText(fPosX, fPosY, ss.str());
 | 
				
			||||||
	ss.str("");
 | 
						ss.str("");
 | 
				
			||||||
 | 
						fPosY -= charSize;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	ss << " Position  : " << m_player.GetPosition();
 | 
						ss << " Position  : " << m_player.GetPosition();
 | 
				
			||||||
	PrintText(x, Height() / 16, scale, ss.str());
 | 
						PrintText(fPosX, fPosY, ss.str());
 | 
				
			||||||
	ss.str("");
 | 
						ss.str("");
 | 
				
			||||||
 | 
						fPosY -= charSize;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	ss << " Block  : ";
 | 
						ss << " Block  : ";
 | 
				
			||||||
 | 
					 | 
				
			||||||
	if (bloc == BTYPE_LAST)
 | 
						if (bloc == BTYPE_LAST)
 | 
				
			||||||
		ss << "Weapon.";
 | 
							ss << "Weapon";
 | 
				
			||||||
	else ss << (int)bloc;
 | 
						else
 | 
				
			||||||
 | 
							ss << (int)bloc;
 | 
				
			||||||
 | 
						PrintText(fPosX, fPosYJump, ss.str());
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	PrintText(x, Height() / 12, scale, ss.str());
 | 
					void Engine::DisplaySingleOrMultiplayerMenu() {
 | 
				
			||||||
 | 
						glEnable(GL_BLEND);
 | 
				
			||||||
 | 
						glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
 | 
				
			||||||
 | 
						glBlendEquation(GL_FUNC_ADD);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						glDisable(GL_STENCIL_TEST);
 | 
				
			||||||
 | 
						glDisable(GL_DEPTH_TEST);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						glMatrixMode(GL_PROJECTION);
 | 
				
			||||||
 | 
						glPushMatrix();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						glLoadIdentity();
 | 
				
			||||||
 | 
						glOrtho(0, Width(), 0, Height(), -1, 1);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						glMatrixMode(GL_MODELVIEW);
 | 
				
			||||||
 | 
						glPushMatrix();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						auto [scaleX, scaleY] = GetScale();
 | 
				
			||||||
 | 
						float fBackPosX = 0.0f;
 | 
				
			||||||
 | 
						float fBackPosY = 0.0f;
 | 
				
			||||||
 | 
						float fBackWidth = Width();
 | 
				
			||||||
 | 
						float fBackHeight = Height();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						m_textureSoloMultiMenu.Bind();
 | 
				
			||||||
 | 
						glBegin(GL_QUADS);
 | 
				
			||||||
 | 
						glTexCoord2f(0.0f, 0.0f); glVertex2f(fBackPosX, fBackPosY);
 | 
				
			||||||
 | 
						glTexCoord2f(1.0f, 0.0f); glVertex2f(fBackWidth, fBackPosY);
 | 
				
			||||||
 | 
						glTexCoord2f(1.0f, 1.0f); glVertex2f(fBackWidth, fBackHeight);       
 | 
				
			||||||
 | 
						glTexCoord2f(0.0f, 1.0f); glVertex2f(fBackPosX, fBackHeight);   
 | 
				
			||||||
 | 
						glEnd();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						float centerX = (Width() / 2.0f);
 | 
				
			||||||
 | 
						float centerY = (Height() / 2.0f);
 | 
				
			||||||
 | 
						float titleWidth = (centerX * 1.85f) * scaleX;
 | 
				
			||||||
 | 
						float titleHeight = (centerY * 1.85f) * scaleY;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						// Solo game indicator
 | 
				
			||||||
 | 
						m_textureTitle.Bind();
 | 
				
			||||||
 | 
						glBegin(GL_QUADS);
 | 
				
			||||||
 | 
						glTexCoord2f(0.0f, 0.0f); glVertex2f(centerX, centerY); 
 | 
				
			||||||
 | 
						glTexCoord2f(1.0f, 0.0f); glVertex2f(titleWidth, centerY);
 | 
				
			||||||
 | 
						glTexCoord2f(1.0f, 1.0f); glVertex2f(titleWidth, titleHeight); 
 | 
				
			||||||
 | 
						glTexCoord2f(0.0f, 1.0f); glVertex2f(centerX, titleHeight);
 | 
				
			||||||
 | 
						glEnd();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						glBindTexture(GL_TEXTURE_2D, 0);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						// Solo game indicator
 | 
				
			||||||
 | 
						float fPosX = (centerX * 1.1f) * scaleX;
 | 
				
			||||||
 | 
						float fPosXWidth = (centerX * 1.75f) * scaleX;
 | 
				
			||||||
 | 
						float soloPosY = (centerY * 0.75f) * scaleY;
 | 
				
			||||||
 | 
						float soloHeight = (centerY * 0.9f) * scaleY;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						glColor4f(1.0f, 1.0f, 1.0f, 0.5f);
 | 
				
			||||||
 | 
						glBegin(GL_QUADS);
 | 
				
			||||||
 | 
						glTexCoord2f(0.0f, 0.0f); glVertex2f(fPosX, soloPosY); 
 | 
				
			||||||
 | 
						glTexCoord2f(1.0f, 0.0f); glVertex2f(fPosXWidth, soloPosY); 
 | 
				
			||||||
 | 
						glTexCoord2f(1.0f, 1.0f); glVertex2f(fPosXWidth, soloHeight); 
 | 
				
			||||||
 | 
						glTexCoord2f(0.0f, 1.0f); glVertex2f(fPosX, soloHeight);
 | 
				
			||||||
 | 
						glEnd();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						// Multiplayer game indicator
 | 
				
			||||||
 | 
						float multiPosY = (centerY * 0.5f) * scaleY;
 | 
				
			||||||
 | 
						float multiHeight = (centerY * 0.65f) * scaleY;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						glBegin(GL_QUADS);
 | 
				
			||||||
 | 
						glTexCoord2f(0.0f, 0.0f); glVertex2f(fPosX, multiPosY);
 | 
				
			||||||
 | 
						glTexCoord2f(1.0f, 0.0f); glVertex2f(fPosXWidth, multiPosY); 
 | 
				
			||||||
 | 
						glTexCoord2f(1.0f, 1.0f); glVertex2f(fPosXWidth, multiHeight);
 | 
				
			||||||
 | 
						glTexCoord2f(0.0f, 1.0f); glVertex2f(fPosX, multiHeight); 
 | 
				
			||||||
 | 
						glEnd();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						// TODO: Add SOLO / MULTIPLAYER text with font
 | 
				
			||||||
 | 
						glColor4f(1.0f, 1.0f, 1.0f, 1.0f);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						glEnable(GL_STENCIL_TEST);
 | 
				
			||||||
 | 
						glEnable(GL_DEPTH_TEST);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						glMatrixMode(GL_PROJECTION);
 | 
				
			||||||
 | 
						glPopMatrix();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						glMatrixMode(GL_MODELVIEW);
 | 
				
			||||||
 | 
						glPopMatrix();
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void Engine::DrawHud(float elapsedTime, BlockType bloc) {
 | 
					void Engine::DrawHud(float elapsedTime, BlockType bloc) {
 | 
				
			||||||
@@ -621,13 +833,12 @@ void Engine::DrawHud(float elapsedTime, BlockType bloc) {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
	int timer = GetCountdown(elapsedTime);
 | 
						int timer = GetCountdown(elapsedTime);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	// Appel de la fonction pour l'affichage de notifications
 | 
					 | 
				
			||||||
	if (m_keyK) {
 | 
						if (m_keyK) {
 | 
				
			||||||
		SystemNotification(m_messageNotification);
 | 
							SystemNotification(m_messageNotification);
 | 
				
			||||||
		m_keyK = false;
 | 
							m_keyK = false;
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	if (m_keyL) {
 | 
						if (m_keyL) {
 | 
				
			||||||
		
 | 
					
 | 
				
			||||||
		KillNotification(m_player, m_player);
 | 
							KillNotification(m_player, m_player);
 | 
				
			||||||
		m_keyL = false;
 | 
							m_keyL = false;
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
@@ -644,7 +855,6 @@ void Engine::DrawHud(float elapsedTime, BlockType bloc) {
 | 
				
			|||||||
		DisplayCrosshair();
 | 
							DisplayCrosshair();
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	// Reset du blend function
 | 
					 | 
				
			||||||
	glBlendFunc(GL_CONSTANT_COLOR, GL_ONE_MINUS_CONSTANT_COLOR);
 | 
						glBlendFunc(GL_CONSTANT_COLOR, GL_ONE_MINUS_CONSTANT_COLOR);
 | 
				
			||||||
	glBlendEquation(GL_FUNC_SUBTRACT);
 | 
						glBlendEquation(GL_FUNC_SUBTRACT);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -658,34 +868,40 @@ void Engine::DrawHud(float elapsedTime, BlockType bloc) {
 | 
				
			|||||||
	glPopMatrix();
 | 
						glPopMatrix();
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void Engine::PrintText(float x, float y, float scale, const std::string& t) {
 | 
					void Engine::PrintText(float x, float y, const std::string& t, float charSizeMultiplier) {
 | 
				
			||||||
 | 
						auto [scaleX, scaleY] = GetScale();
 | 
				
			||||||
 | 
						float scale = std::min(scaleX, scaleY);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						float baseCharSize = 20 + (24 - 20) * (Width() - 1600) / (1920 - 1600);
 | 
				
			||||||
 | 
						float charSize = baseCharSize * charSizeMultiplier;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	glLoadIdentity();
 | 
						glLoadIdentity();
 | 
				
			||||||
	glTranslated(x, y, 0);
 | 
						glTranslated(x, y, 0);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	for (unsigned int i = 0; i < t.length(); ++i) {
 | 
						for (unsigned int i = 0; i < t.length(); ++i) {
 | 
				
			||||||
		float left = (float)((t[i] - 32) % 16) / 16.f;
 | 
							float left = (float)((t[i] - 32) % 16) / 16.f;
 | 
				
			||||||
		float top = (float)((t[i] - 32) / 16) / 16.f;
 | 
							float top = (float)((t[i] - 32) / 16) / 16.f;
 | 
				
			||||||
		top += .5f;
 | 
							top += 0.5f;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		glBegin(GL_QUADS);
 | 
							glBegin(GL_QUADS);
 | 
				
			||||||
			glTexCoord2f(left, 1.f - top - .0625f);			 glVertex2f(0, 0);
 | 
							glTexCoord2f(left, 1.f - top - .0625f);          glVertex2f(0, 0);
 | 
				
			||||||
			glTexCoord2f(left + .0625f, 1.f - top - .0625f); glVertex2f(12 * scale, 0);
 | 
							glTexCoord2f(left + .0625f, 1.f - top - .0625f); glVertex2f(charSize * scale, 0);
 | 
				
			||||||
			glTexCoord2f(left + .0625f, 1.f - top);			 glVertex2f(12 * scale, 12 * scale);
 | 
							glTexCoord2f(left + .0625f, 1.f - top);          glVertex2f(charSize * scale, charSize * scale);
 | 
				
			||||||
			glTexCoord2f(left, 1.f - top);					 glVertex2f(0, 12 * scale);
 | 
							glTexCoord2f(left, 1.f - top);                   glVertex2f(0, charSize * scale);
 | 
				
			||||||
		glEnd();
 | 
							glEnd();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		glTranslated(8 * scale, 0, 0);
 | 
							glTranslated(0.5555f * charSize * scale, 0, 0);
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
float Engine::GetScale() const {
 | 
					std::pair<float, float> Engine::GetScale() const {
 | 
				
			||||||
	float widthRatio = Width() / BASE_WIDTH;
 | 
						float widthRatio = static_cast<float>(Width()) / BASE_WIDTH;
 | 
				
			||||||
	float heightRatio = Height() / BASE_HEIGHT;
 | 
						float heightRatio = static_cast<float>(Height()) / BASE_HEIGHT;
 | 
				
			||||||
 | 
						return { widthRatio, heightRatio };
 | 
				
			||||||
	return (widthRatio + heightRatio) / 2.0f;
 | 
					 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
int Engine::GetFps(float elapsedTime) const { return 1 / elapsedTime; }
 | 
					int Engine::GetFps(float elapsedTime) const { return 1 / elapsedTime; }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
int Engine::GetCountdown(float elapsedTime) {
 | 
					int Engine::GetCountdown(float elapsedTime) {
 | 
				
			||||||
	if (m_resetcountdown)
 | 
						if (m_resetcountdown)
 | 
				
			||||||
	{
 | 
						{
 | 
				
			||||||
@@ -694,7 +910,7 @@ int Engine::GetCountdown(float elapsedTime) {
 | 
				
			|||||||
	}
 | 
						}
 | 
				
			||||||
	if (m_countdown < m_time)
 | 
						if (m_countdown < m_time)
 | 
				
			||||||
		Stop();
 | 
							Stop();
 | 
				
			||||||
	if(!m_stopcountdown)
 | 
						if (!m_stopcountdown)
 | 
				
			||||||
		m_time += elapsedTime;
 | 
							m_time += elapsedTime;
 | 
				
			||||||
	return m_countdown - (int)m_time;
 | 
						return m_countdown - (int)m_time;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
@@ -748,8 +964,8 @@ void Engine::Render(float elapsedTime) {
 | 
				
			|||||||
				break;
 | 
									break;
 | 
				
			||||||
			default: break;
 | 
								default: break;
 | 
				
			||||||
			}
 | 
								}
 | 
				
			||||||
			m_audio.Update3DAudio(m_player.GetPOV(), m_player.GetDirection(), m_player.GetVelocity()); // Ajustement du positionnement 3D avec les coordonn<EFBFBD>es du joueur et
 | 
								m_audio.Update3DAudio(m_player.GetPOV(), m_player.GetDirection(), m_player.GetVelocity()); // Ajustement du positionnement 3D avec les coordonnees du joueur et
 | 
				
			||||||
			// son vecteur de v<EFBFBD>locit<EFBFBD> (pour l'effet Doppler)
 | 
								// son vecteur de velocite (pour l'effet Doppler)
 | 
				
			||||||
			pollTime = 0;
 | 
								pollTime = 0;
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -773,10 +989,18 @@ void Engine::Render(float elapsedTime) {
 | 
				
			|||||||
						m_bullets[x] = new Bullet(m_player.GetPOV() + m_player.GetDirection(), m_player.GetDirection());
 | 
											m_bullets[x] = new Bullet(m_player.GetPOV() + m_player.GetDirection(), m_player.GetDirection());
 | 
				
			||||||
						break;
 | 
											break;
 | 
				
			||||||
					}
 | 
										}
 | 
				
			||||||
					else if (x == MAX_BULLETS - 1) { // S'il y a pas d'espace dans l'array, prendre la place de la premi<EFBFBD>re balle de l'array.
 | 
										else if (x == MAX_BULLETS - 1) { // S'il y a pas d'espace dans l'array, prendre la place de la première balle de l'array.
 | 
				
			||||||
						m_bullets[0]->~Bullet();
 | 
											m_bullets[0]->~Bullet();
 | 
				
			||||||
						m_bullets[0] = new Bullet(m_player.GetPOV() + m_player.GetDirection(), m_player.GetDirection());
 | 
											m_bullets[0] = new Bullet(m_player.GetPOV() + m_player.GetDirection(), m_player.GetDirection());
 | 
				
			||||||
					}
 | 
										}
 | 
				
			||||||
 | 
									bulletTime = BULLET_TIME;
 | 
				
			||||||
 | 
									m_audio.Create3DAudioObj(m_powpow, AUDIO_PATH "pow.wav", m_player.GetPOV(), m_player.GetDirection() * 10, false, .5f);
 | 
				
			||||||
 | 
									if (m_flash) { // Coupe le rendering et affiche un frame blanc, pour simuler un flash.
 | 
				
			||||||
 | 
										glClearColor(.8f, .8f, .8f, 1.f);
 | 
				
			||||||
 | 
										glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
 | 
				
			||||||
 | 
										glClearColor(0.f, 0.f, 0.f, 1.f);
 | 
				
			||||||
 | 
										return;
 | 
				
			||||||
 | 
									}
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	else if (m_mouseR)
 | 
						else if (m_mouseR)
 | 
				
			||||||
@@ -784,8 +1008,8 @@ void Engine::Render(float elapsedTime) {
 | 
				
			|||||||
	
 | 
						
 | 
				
			||||||
	for (int x = 0; x < MAX_BULLETS; ++x) { // Array de bullets en jeu.
 | 
						for (int x = 0; x < MAX_BULLETS; ++x) { // Array de bullets en jeu.
 | 
				
			||||||
		if (m_bullets[x]) {
 | 
							if (m_bullets[x]) {
 | 
				
			||||||
			for (int b = 0; b < BULLET_UPDATES_PER_FRAME; ++b)
 | 
								for (int b = 0; b < BULLET_UPDATES_PER_FRAME; ++b) {
 | 
				
			||||||
				if (m_bullets[x]->Update(&m_world, elapsedTime, BULLET_UPDATES_PER_FRAME)) {
 | 
									if (m_bullets[x]->Update(&m_world, elapsedTime, BULLET_UPDATES_PER_FRAME, m_players)) {
 | 
				
			||||||
					m_bullets[x]->~Bullet();
 | 
										m_bullets[x]->~Bullet();
 | 
				
			||||||
					if (m_whoosh[x])
 | 
										if (m_whoosh[x])
 | 
				
			||||||
						m_whoosh[x]->drop();
 | 
											m_whoosh[x]->drop();
 | 
				
			||||||
@@ -796,19 +1020,27 @@ void Engine::Render(float elapsedTime) {
 | 
				
			|||||||
				else if (!m_whoosh[x]) {
 | 
									else if (!m_whoosh[x]) {
 | 
				
			||||||
					m_whoosh[x] = m_audio.Create3DAudioObj(m_whoosh[x], AUDIO_PATH "noise.wav", m_bullets[x]->getPos(), m_bullets[x]->getVel(), true, (m_bullets[x]->getPos() - m_player.GetPosition()).Length());
 | 
										m_whoosh[x] = m_audio.Create3DAudioObj(m_whoosh[x], AUDIO_PATH "noise.wav", m_bullets[x]->getPos(), m_bullets[x]->getVel(), true, (m_bullets[x]->getPos() - m_player.GetPosition()).Length());
 | 
				
			||||||
				}
 | 
									}
 | 
				
			||||||
				else m_audio.Render3DAudioObj(m_whoosh[x], m_bullets[x]->getPos(), m_bullets[x]->getVel(), 5 - (m_bullets[x]->getPos() - m_player.GetPosition()).Length());			
 | 
									else {
 | 
				
			||||||
 | 
										Vector3f pos = m_bullets[x]->getPos(), vel = m_bullets[x]->getVel();
 | 
				
			||||||
 | 
										m_audio.Render3DAudioObj(m_whoosh[x], pos, vel, 5 - (m_bullets[x]->getPos() - m_player.GetPosition()).Length());
 | 
				
			||||||
 | 
									}
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		m_wrenderer.RenderWorld(&m_world, m_renderCount, m_player.GetPosition(), m_player.GetDirection(), all, m_shader01, m_textureAtlas);
 | 
							m_renderer.RenderWorld(&m_world, m_renderCount, m_player.GetPosition(), m_player.GetDirection(), all, m_shader01, m_textureAtlas);
 | 
				
			||||||
		m_world.Update(m_bullets, m_player.GetPosition(), m_blockinfo);
 | 
							m_world.Update(m_bullets, m_player.GetPosition(), m_blockinfo);
 | 
				
			||||||
		m_wrenderer.UpdateWorld(&m_world, m_player.GetPosition(), m_blockinfo);
 | 
							m_renderer.UpdateMesh(&m_world, m_player.GetPosition(), m_blockinfo);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		if (m_isSkybox) m_skybox.Render(skybox);
 | 
							if (m_isSkybox) m_skybox.Render(skybox);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		ProcessNotificationQueue();
 | 
					 | 
				
			||||||
		DrawHud(elapsedTime, bloc);
 | 
							DrawHud(elapsedTime, bloc);
 | 
				
			||||||
 | 
							DisplayPovGun();
 | 
				
			||||||
 | 
							ProcessNotificationQueue();
 | 
				
			||||||
 | 
							if (m_damage)
 | 
				
			||||||
 | 
							{
 | 
				
			||||||
 | 
								InstantDamage();
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
		static bool fell = false;
 | 
							static bool fell = false;
 | 
				
			||||||
		if (m_player.GetPosition().y < 1.7f && !fell) {
 | 
							if (m_player.GetPosition().y < 1.7f && !fell) {
 | 
				
			||||||
			m_audio.Create3DAudioObj(m_scream, AUDIO_PATH "scream.wav", m_player.GetPOV(), m_player.GetVelocity(), false,1.f);
 | 
								m_audio.Create3DAudioObj(m_scream, AUDIO_PATH "scream.wav", m_player.GetPOV(), m_player.GetVelocity(), false,1.f);
 | 
				
			||||||
@@ -819,6 +1051,28 @@ void Engine::Render(float elapsedTime) {
 | 
				
			|||||||
			fell = false;
 | 
								fell = false;
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							if (m_networkgame) {
 | 
				
			||||||
 | 
								static char* buf = new char[BUFFER_LENGTH];
 | 
				
			||||||
 | 
								uint32_t buflen = BUFFER_LENGTH;
 | 
				
			||||||
 | 
								netprot::Input input;
 | 
				
			||||||
 | 
								//sockaddr_in addr = m_conn.m_srvsockaddr;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
								input.direction = m_player.GetDirection();
 | 
				
			||||||
 | 
								input.sid = m_conn.getId();
 | 
				
			||||||
 | 
								input.timestamp = 12345;
 | 
				
			||||||
 | 
								input.keys.forward = m_keyW;
 | 
				
			||||||
 | 
								input.keys.backward = m_keyS;
 | 
				
			||||||
 | 
								input.keys.left = m_keyA;
 | 
				
			||||||
 | 
								input.keys.right = m_keyD;
 | 
				
			||||||
 | 
								input.keys.jump = m_keySpace;
 | 
				
			||||||
 | 
								input.keys.block = m_mouseR;
 | 
				
			||||||
 | 
								input.keys.shoot = m_mouseL;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
								//netprot::Serialize(&input, &buf, &buflen);
 | 
				
			||||||
 | 
								//sendto(m_conn.m_sock_udp, buf, buflen, 0, (sockaddr*)&addr, sizeof(addr));
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
								netprot::sendPackTo<netprot::Input>(m_conn.m_sock_udp, &input, &buf, &buflen, &m_conn.m_srvsockaddr);
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	else if (m_gamestate == GameState::MAIN_MENU || m_gamestate == GameState::OPTIONS)
 | 
						else if (m_gamestate == GameState::MAIN_MENU || m_gamestate == GameState::OPTIONS)
 | 
				
			||||||
	{
 | 
						{
 | 
				
			||||||
@@ -869,7 +1123,7 @@ void Engine::KeyPressEvent(unsigned char key) {
 | 
				
			|||||||
		break;
 | 
							break;
 | 
				
			||||||
	case 10: // K - Debugging DisplayNotification()
 | 
						case 10: // K - Debugging DisplayNotification()
 | 
				
			||||||
		m_keyK = true;
 | 
							m_keyK = true;
 | 
				
			||||||
		m_messageNotification = "notifications systeme peuvent <EFBFBD>tre affich<EFBFBD>";
 | 
							m_messageNotification = "notifications systeme peuvent etre affichees";
 | 
				
			||||||
		break;
 | 
							break;
 | 
				
			||||||
	case 11: // L - Debugging DisplayNotification()
 | 
						case 11: // L - Debugging DisplayNotification()
 | 
				
			||||||
		m_keyL = true;
 | 
							m_keyL = true;
 | 
				
			||||||
@@ -882,12 +1136,14 @@ void Engine::KeyPressEvent(unsigned char key) {
 | 
				
			|||||||
		break;
 | 
							break;
 | 
				
			||||||
	case 8: // I - Ignorer
 | 
						case 8: // I - Ignorer
 | 
				
			||||||
		break;
 | 
							break;
 | 
				
			||||||
 | 
						case 9: // J - InstantDamage
 | 
				
			||||||
 | 
							m_damage = true;
 | 
				
			||||||
	case 15: // P - Ignorer
 | 
						case 15: // P - Ignorer
 | 
				
			||||||
		break;
 | 
							break;
 | 
				
			||||||
	case 17: // R - Ignorer
 | 
						case 17: // R - Ignorer
 | 
				
			||||||
		break;
 | 
							break;
 | 
				
			||||||
	case 19: // T - Ignorer
 | 
						case 19: // T - Ignorer
 | 
				
			||||||
		break; 
 | 
							break;
 | 
				
			||||||
	case 24: // Y - Ignorer
 | 
						case 24: // Y - Ignorer
 | 
				
			||||||
		break;
 | 
							break;
 | 
				
			||||||
	case 255: // Fn - Ignorer
 | 
						case 255: // Fn - Ignorer
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -18,7 +18,8 @@
 | 
				
			|||||||
#include "audio.h"
 | 
					#include "audio.h"
 | 
				
			||||||
#include "textureatlas.h"
 | 
					#include "textureatlas.h"
 | 
				
			||||||
#include "connector.h"
 | 
					#include "connector.h"
 | 
				
			||||||
#include "worldrenderer.h"
 | 
					#include "renderer.h"
 | 
				
			||||||
 | 
					#include "remoteplayer.h"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
class Engine : public OpenglContext {
 | 
					class Engine : public OpenglContext {
 | 
				
			||||||
public:
 | 
					public:
 | 
				
			||||||
@@ -38,23 +39,26 @@ public:
 | 
				
			|||||||
    virtual void MouseReleaseEvent(const MOUSE_BUTTON &button, int x, int y);
 | 
					    virtual void MouseReleaseEvent(const MOUSE_BUTTON &button, int x, int y);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
private:
 | 
					private:
 | 
				
			||||||
    float GetScale() const;
 | 
					    std::pair<float, float> GetScale() const;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    int GetFps(float elapsedTime) const;
 | 
					    int GetFps(float elapsedTime) const;
 | 
				
			||||||
    int GetCountdown(float elapsedTime);
 | 
					    int GetCountdown(float elapsedTime);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    bool LoadTexture(Texture& texture, const std::string& filename, bool useMipmaps = true, bool stopOnError = true);
 | 
					    bool LoadTexture(Texture& texture, const std::string& filename, bool useMipmaps = true, bool stopOnError = true);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    void InstantDamage();
 | 
				
			||||||
    void SystemNotification(std::string systemLog);
 | 
					    void SystemNotification(std::string systemLog);
 | 
				
			||||||
    void KillNotification(Player killer, Player killed);
 | 
					    void KillNotification(Player killer, Player killed);
 | 
				
			||||||
    void DisplayNotification(std::string message);
 | 
					    void DisplayNotification(std::string message);
 | 
				
			||||||
    void ProcessNotificationQueue();
 | 
					    void ProcessNotificationQueue();
 | 
				
			||||||
    void DisplayCrosshair();
 | 
					    void DisplayCrosshair();
 | 
				
			||||||
 | 
					    void DisplayPovGun();
 | 
				
			||||||
    void DisplayCurrentItem();
 | 
					    void DisplayCurrentItem();
 | 
				
			||||||
    void DisplayHud(int timer);
 | 
					    void DisplayHud(int timer);
 | 
				
			||||||
    void DisplayInfo(float elapsedTime, BlockType bloc);
 | 
					    void DisplayInfo(float elapsedTime, BlockType bloc);
 | 
				
			||||||
 | 
					    void DisplaySingleOrMultiplayerMenu();
 | 
				
			||||||
    void DrawHud(float elapsedTime, BlockType bloc);
 | 
					    void DrawHud(float elapsedTime, BlockType bloc);
 | 
				
			||||||
    void PrintText(float x, float y, float scale, const std::string& t);
 | 
					    void PrintText(float x, float y, const std::string& t, float charSizeMultiplier = 1.0f);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    Connector m_conn;
 | 
					    Connector m_conn;
 | 
				
			||||||
    Shader m_shader01;
 | 
					    Shader m_shader01;
 | 
				
			||||||
@@ -62,12 +66,15 @@ private:
 | 
				
			|||||||
    TextureAtlas m_textureAtlas = TextureAtlas(BTYPE_LAST);
 | 
					    TextureAtlas m_textureAtlas = TextureAtlas(BTYPE_LAST);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    World m_world = World();
 | 
					    World m_world = World();
 | 
				
			||||||
    WorldRenderer m_wrenderer = WorldRenderer();
 | 
					    Renderer m_renderer = Renderer();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    Texture m_textureSkybox;
 | 
					 | 
				
			||||||
    Texture m_textureFont;
 | 
					 | 
				
			||||||
    Texture m_textureCrosshair;
 | 
					    Texture m_textureCrosshair;
 | 
				
			||||||
 | 
					    Texture m_textureFont;
 | 
				
			||||||
    Texture m_textureGun;
 | 
					    Texture m_textureGun;
 | 
				
			||||||
 | 
					    Texture m_texturePovGun;
 | 
				
			||||||
 | 
					    Texture m_textureSkybox;
 | 
				
			||||||
 | 
					    Texture m_textureSoloMultiMenu;
 | 
				
			||||||
 | 
					    Texture m_textureTitle;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    Skybox m_skybox;
 | 
					    Skybox m_skybox;
 | 
				
			||||||
    Audio m_audio = Audio(AUDIO_PATH "start.wav");
 | 
					    Audio m_audio = Audio(AUDIO_PATH "start.wav");
 | 
				
			||||||
@@ -80,8 +87,10 @@ private:
 | 
				
			|||||||
    
 | 
					    
 | 
				
			||||||
    Bullet* m_bullets[MAX_BULLETS];
 | 
					    Bullet* m_bullets[MAX_BULLETS];
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    std::map<uint64_t, Player*> m_players;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    //Menu
 | 
					    //Menu
 | 
				
			||||||
    enum class GameState { MAIN_MENU, OPTIONS, QUIT, NEWG, PLAY };
 | 
					    enum class GameState: uint8_t { MAIN_MENU, OPTIONS, QUIT, NEWG, PLAY };
 | 
				
			||||||
    GameState m_gamestate = GameState::MAIN_MENU;
 | 
					    GameState m_gamestate = GameState::MAIN_MENU;
 | 
				
			||||||
    Texture MenuTitleTexture;
 | 
					    Texture MenuTitleTexture;
 | 
				
			||||||
    Texture MenuBGTexture;
 | 
					    Texture MenuBGTexture;
 | 
				
			||||||
@@ -99,6 +108,8 @@ private:
 | 
				
			|||||||
    int m_renderCount = 0;
 | 
					    int m_renderCount = 0;
 | 
				
			||||||
    int m_countdown = COUNTDOWN;
 | 
					    int m_countdown = COUNTDOWN;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    bool m_damage = false;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    bool m_wireframe = false;
 | 
					    bool m_wireframe = false;
 | 
				
			||||||
    bool m_isSkybox = true;
 | 
					    bool m_isSkybox = true;
 | 
				
			||||||
    bool m_block = false;
 | 
					    bool m_block = false;
 | 
				
			||||||
@@ -107,6 +118,7 @@ private:
 | 
				
			|||||||
    bool m_displayHud = true;
 | 
					    bool m_displayHud = true;
 | 
				
			||||||
    bool m_displayInfo = false;
 | 
					    bool m_displayInfo = false;
 | 
				
			||||||
    bool m_resetcountdown = false;
 | 
					    bool m_resetcountdown = false;
 | 
				
			||||||
 | 
					    bool m_soloMultiChoiceMade = true;
 | 
				
			||||||
    bool m_stopcountdown = false;
 | 
					    bool m_stopcountdown = false;
 | 
				
			||||||
    
 | 
					    
 | 
				
			||||||
    bool m_keyK = false;
 | 
					    bool m_keyK = false;
 | 
				
			||||||
@@ -125,6 +137,8 @@ private:
 | 
				
			|||||||
    float m_mousemx = 0;
 | 
					    float m_mousemx = 0;
 | 
				
			||||||
    float m_mousemy = 0;
 | 
					    float m_mousemy = 0;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    bool m_networkgame = false;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    std::string m_messageNotification = "";
 | 
					    std::string m_messageNotification = "";
 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
							
								
								
									
										
											BIN
										
									
								
								SQCSim2021/media/audio/whitenoise.ogg
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										
											BIN
										
									
								
								SQCSim2021/media/audio/whitenoise.ogg
									
									
									
									
									
										Normal file
									
								
							
										
											Binary file not shown.
										
									
								
							
							
								
								
									
										
											BIN
										
									
								
								SQCSim2021/media/textures/BrouillonbackgroundMenu.png
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										
											BIN
										
									
								
								SQCSim2021/media/textures/BrouillonbackgroundMenu.png
									
									
									
									
									
										Normal file
									
								
							
										
											Binary file not shown.
										
									
								
							| 
		 After Width: | Height: | Size: 6.5 MiB  | 
							
								
								
									
										
											BIN
										
									
								
								SQCSim2021/media/textures/single_multi.png
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										
											BIN
										
									
								
								SQCSim2021/media/textures/single_multi.png
									
									
									
									
									
										Normal file
									
								
							
										
											Binary file not shown.
										
									
								
							| 
		 After Width: | Height: | Size: 1.3 MiB  | 
							
								
								
									
										
											BIN
										
									
								
								SQCSim2021/media/textures/skybox2.png
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										
											BIN
										
									
								
								SQCSim2021/media/textures/skybox2.png
									
									
									
									
									
										Normal file
									
								
							
										
											Binary file not shown.
										
									
								
							| 
		 After Width: | Height: | Size: 4.3 MiB  | 
							
								
								
									
										
											BIN
										
									
								
								SQCSim2021/media/textures/title.png
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										
											BIN
										
									
								
								SQCSim2021/media/textures/title.png
									
									
									
									
									
										Normal file
									
								
							
										
											Binary file not shown.
										
									
								
							| 
		 After Width: | Height: | Size: 30 KiB  | 
							
								
								
									
										70
									
								
								SQCSim2021/remoteplayer.cpp
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										70
									
								
								SQCSim2021/remoteplayer.cpp
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,70 @@
 | 
				
			|||||||
 | 
					#include "remoteplayer.h"
 | 
				
			||||||
 | 
					#include <iostream>
 | 
				
			||||||
 | 
					#include <cstring>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					RemotePlayer::RemotePlayer(netprot::PlayerInfo pinfo) : Player(Vector3f(0, 0, 0), 0, 0), m_pinfo(pinfo), m_aminacc(0.0f), m_animstate(Anim::STILL), m_team_id(0), current(), previous() {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					void RemotePlayer::Init() {
 | 
				
			||||||
 | 
						
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					void RemotePlayer::Feed(const netprot::Output out) {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						current.position = out.position;
 | 
				
			||||||
 | 
						current.direction = out.direction;
 | 
				
			||||||
 | 
						current.states = out.states;
 | 
				
			||||||
 | 
						current.id = out.id;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						//a revoir pour le jump et le shoot en meme temps lorsque les test seront possible	
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if (current.position != previous.position)
 | 
				
			||||||
 | 
						{
 | 
				
			||||||
 | 
							Vector3f positionDelta = current.position - previous.position;
 | 
				
			||||||
 | 
							m_position = current.position + positionDelta;
 | 
				
			||||||
 | 
							m_direction = current.direction;		
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if(current.direction != previous.direction)
 | 
				
			||||||
 | 
						{
 | 
				
			||||||
 | 
							m_direction = current.direction;
 | 
				
			||||||
 | 
							current.direction = current.direction;
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if (current.states.shooting) {
 | 
				
			||||||
 | 
							//true;
 | 
				
			||||||
 | 
							m_animstate = Anim::SHOOTING;
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						else if (current.states.jumping) {
 | 
				
			||||||
 | 
							//true;
 | 
				
			||||||
 | 
							m_animstate = Anim::JUMPING;
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						else if (current.states.dead) {
 | 
				
			||||||
 | 
							//true;
 | 
				
			||||||
 | 
							m_animstate = Anim::DEAD;
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						else if(current.states.powerup){
 | 
				
			||||||
 | 
							//true;
 | 
				
			||||||
 | 
							m_animstate = Anim::POWERUP;
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						else if (current.states.still) {
 | 
				
			||||||
 | 
							//true;
 | 
				
			||||||
 | 
							m_animstate = Anim::STILL;
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						else if (current.states.running) {
 | 
				
			||||||
 | 
							//true;
 | 
				
			||||||
 | 
							m_animstate = Anim::RUNNING;
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						
 | 
				
			||||||
 | 
						previous.direction = current.direction;
 | 
				
			||||||
 | 
						previous.position = current.position;
 | 
				
			||||||
 | 
						previous.states = current.states;
 | 
				
			||||||
 | 
						previous.id = current.id;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
							
								
								
									
										26
									
								
								SQCSim2021/remoteplayer.h
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										26
									
								
								SQCSim2021/remoteplayer.h
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,26 @@
 | 
				
			|||||||
 | 
					#ifndef REMOTEPLAYER_H__
 | 
				
			||||||
 | 
					#define REMOTEPLAYER_H__
 | 
				
			||||||
 | 
					#include "../SQCSim-common/player.h"
 | 
				
			||||||
 | 
					#include "../SQCSim-common/netprotocol.h"
 | 
				
			||||||
 | 
					#include "define.h"
 | 
				
			||||||
 | 
					#include "textureatlas.h"
 | 
				
			||||||
 | 
					#include "shader.h"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					class RemotePlayer : public Player {
 | 
				
			||||||
 | 
					public:
 | 
				
			||||||
 | 
						enum Anim { STILL = 1, RUNNING = 2, JUMPING = 4, SHOOTING = 8, POWERUP = 16,  DEAD = 32 };
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						RemotePlayer(netprot::PlayerInfo pinfo);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						void Init();
 | 
				
			||||||
 | 
						void Feed(const netprot::Output out);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					private:
 | 
				
			||||||
 | 
						netprot::Output current, previous;
 | 
				
			||||||
 | 
						netprot::PlayerInfo m_pinfo;
 | 
				
			||||||
 | 
						float m_aminacc;
 | 
				
			||||||
 | 
						Anim m_animstate;
 | 
				
			||||||
 | 
						uint64_t m_team_id;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					};
 | 
				
			||||||
 | 
					#endif
 | 
				
			||||||
@@ -1,13 +1,13 @@
 | 
				
			|||||||
#include "worldrenderer.h"
 | 
					#include "renderer.h"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
WorldRenderer::WorldRenderer() {
 | 
					Renderer::Renderer() {
 | 
				
			||||||
	m_meshes.Reset(nullptr);
 | 
						m_meshes.Reset(nullptr);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
WorldRenderer::~WorldRenderer() {
 | 
					Renderer::~Renderer() {
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void WorldRenderer::RenderWorld(World* origin, int& rendercount, const Vector3f& player_pos, const Vector3f& player_dir, Transformation& world, Shader& shader, TextureAtlas& atlas) {
 | 
					void Renderer::RenderWorld(World* origin, int& rendercount, const Vector3f& player_pos, const Vector3f& player_dir, Transformation& world, Shader& shader, TextureAtlas& atlas) const {
 | 
				
			||||||
	rendercount = 0;
 | 
						rendercount = 0;
 | 
				
			||||||
	Vector3f angle;
 | 
						Vector3f angle;
 | 
				
			||||||
	Vector3f cursor;
 | 
						Vector3f cursor;
 | 
				
			||||||
@@ -18,7 +18,7 @@ void WorldRenderer::RenderWorld(World* origin, int& rendercount, const Vector3f&
 | 
				
			|||||||
	direct.Normalize();
 | 
						direct.Normalize();
 | 
				
			||||||
	pos.y = 1;
 | 
						pos.y = 1;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	static Vector3<unsigned int> renderManifest[VIEW_DISTANCE * 8]; // Nombre de Chunks maximal à être rendus.
 | 
						static Vector3<unsigned int> renderManifest[VIEW_DISTANCE * 8]; // Nombre de Chunks maximal <EFBFBD> <20>tre rendus.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	//for (int dist = VIEW_DISTANCE; dist >= 0; dist -= CHUNK_SIZE_X) {
 | 
						//for (int dist = VIEW_DISTANCE; dist >= 0; dist -= CHUNK_SIZE_X) {
 | 
				
			||||||
	for (int dist = 0; dist <= VIEW_DISTANCE; dist += CHUNK_SIZE_X) {
 | 
						for (int dist = 0; dist <= VIEW_DISTANCE; dist += CHUNK_SIZE_X) {
 | 
				
			||||||
@@ -27,18 +27,18 @@ void WorldRenderer::RenderWorld(World* origin, int& rendercount, const Vector3f&
 | 
				
			|||||||
		int echantillons;
 | 
							int echantillons;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		if (dist > VIEW_DISTANCE * .1f) {
 | 
							if (dist > VIEW_DISTANCE * .1f) {
 | 
				
			||||||
			sinus = .00872653549f; // sin(1/2 degré)
 | 
								sinus = .00872653549f; // sin(1/2 degr<EFBFBD>)
 | 
				
			||||||
			cosinus = .99996192306; // cos(1/2 degré)
 | 
								cosinus = .99996192306; // cos(1/2 degr<EFBFBD>)
 | 
				
			||||||
			echantillons = 180;
 | 
								echantillons = 180;
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
		//else {//if (dist > VIEW_DISTANCE * .3f) {
 | 
							//else {//if (dist > VIEW_DISTANCE * .3f) {
 | 
				
			||||||
		//	sinus = .01151891831f; // sin(2/3 degré)
 | 
							//	sinus = .01151891831f; // sin(2/3 degr<EFBFBD>)
 | 
				
			||||||
		//	cosinus = .99993365506; // cos(2/3 degré)
 | 
							//	cosinus = .99993365506; // cos(2/3 degr<EFBFBD>)
 | 
				
			||||||
		//	echantillons = 120;
 | 
							//	echantillons = 120;
 | 
				
			||||||
		//}
 | 
							//}
 | 
				
			||||||
		//else if (dist > VIEW_DISTANCE * .2f) {
 | 
							//else if (dist > VIEW_DISTANCE * .2f) {
 | 
				
			||||||
		//	sinus = .01745240643; // sin(1 degré)
 | 
							//	sinus = .01745240643; // sin(1 degr<EFBFBD>)
 | 
				
			||||||
		//	cosinus = .99984769515; // cos(1 degré)
 | 
							//	cosinus = .99984769515; // cos(1 degr<EFBFBD>)
 | 
				
			||||||
		//	echantillons = 90;
 | 
							//	echantillons = 90;
 | 
				
			||||||
		//}
 | 
							//}
 | 
				
			||||||
		//else if (dist > VIEW_DISTANCE * .1f) {
 | 
							//else if (dist > VIEW_DISTANCE * .1f) {
 | 
				
			||||||
@@ -72,7 +72,7 @@ void WorldRenderer::RenderWorld(World* origin, int& rendercount, const Vector3f&
 | 
				
			|||||||
				bool valide = true;
 | 
									bool valide = true;
 | 
				
			||||||
				unsigned int chx, chy;
 | 
									unsigned int chx, chy;
 | 
				
			||||||
				origin->ChunkAt(cursor)->GetPosition(chx, chy);
 | 
									origin->ChunkAt(cursor)->GetPosition(chx, chy);
 | 
				
			||||||
				for (int index = 0; index < rendercount; ++index) // Permet de vérifier seulement contre celles ajoutées dans la frame, et ne pas avoir à refaire l'array à chaque frame.
 | 
									for (int index = 0; index < rendercount; ++index) // Permet de v<EFBFBD>rifier seulement contre celles ajout<EFBFBD>es dans la frame, et ne pas avoir <EFBFBD> refaire l'array <EFBFBD> chaque frame.
 | 
				
			||||||
					if (renderManifest[index].x == chx && renderManifest[index].z == chy)
 | 
										if (renderManifest[index].x == chx && renderManifest[index].z == chy)
 | 
				
			||||||
						valide = false;
 | 
											valide = false;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -107,7 +107,7 @@ void WorldRenderer::RenderWorld(World* origin, int& rendercount, const Vector3f&
 | 
				
			|||||||
	glStencilFunc(GL_GREATER, 1, 0xFF);
 | 
						glStencilFunc(GL_GREATER, 1, 0xFF);
 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void WorldRenderer::UpdateWorld(World* origin, const Vector3f& player, BlockInfo* blockinfo[BTYPE_LAST]) {
 | 
					void Renderer::UpdateMesh(World* origin, const Vector3f& player, BlockInfo* blockinfo[BTYPE_LAST]) {
 | 
				
			||||||
	int cx = player.x;
 | 
						int cx = player.x;
 | 
				
			||||||
	int cy = player.z;
 | 
						int cy = player.z;
 | 
				
			||||||
	static int frameUpdate = 2;
 | 
						static int frameUpdate = 2;
 | 
				
			||||||
@@ -212,3 +212,10 @@ void WorldRenderer::UpdateWorld(World* origin, const Vector3f& player, BlockInfo
 | 
				
			|||||||
	}
 | 
						}
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					void Renderer::RenderPlayer(Player* player, Transformation tran) const {
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					void Renderer::RenderPlayer(RemotePlayer* rplayer, const Vector3f& player_pos, const Vector3f& player_dir) const {
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
							
								
								
									
										30
									
								
								SQCSim2021/renderer.h
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										30
									
								
								SQCSim2021/renderer.h
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,30 @@
 | 
				
			|||||||
 | 
					#ifndef RENDERER_H__
 | 
				
			||||||
 | 
					#define RENDERER_H__
 | 
				
			||||||
 | 
					#include <future>
 | 
				
			||||||
 | 
					#include <thread>
 | 
				
			||||||
 | 
					#include "../SQCSim-common/world.h"
 | 
				
			||||||
 | 
					#include "../SQCSim-common/transformation.h"
 | 
				
			||||||
 | 
					#include "define.h"
 | 
				
			||||||
 | 
					#include "mesh.h"
 | 
				
			||||||
 | 
					#include "textureatlas.h"
 | 
				
			||||||
 | 
					#include "shader.h"
 | 
				
			||||||
 | 
					#include "remoteplayer.h"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					class Renderer {
 | 
				
			||||||
 | 
					private:
 | 
				
			||||||
 | 
						Array2d<Mesh*> m_meshes = Array2d<Mesh*>(WORLD_SIZE_X, WORLD_SIZE_Y);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						TextureAtlas* m_playertext = nullptr;
 | 
				
			||||||
 | 
						Shader* m_playershader = nullptr;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					public:
 | 
				
			||||||
 | 
						Renderer();
 | 
				
			||||||
 | 
						~Renderer();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						void UpdateMesh(World* origin, const Vector3f& player, BlockInfo* blockinfo[BTYPE_LAST]);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						void RenderWorld(World* origin, int& rendercount, const Vector3f& player_pos, const Vector3f& player_dir, Transformation& world, Shader& shader, TextureAtlas& atlas) const;
 | 
				
			||||||
 | 
						void RenderPlayer(Player* player, Transformation tran) const;
 | 
				
			||||||
 | 
						void RenderPlayer(RemotePlayer* rplayer, const Vector3f& player_pos, const Vector3f& player_dir) const;
 | 
				
			||||||
 | 
					};
 | 
				
			||||||
 | 
					#endif
 | 
				
			||||||
@@ -8,30 +8,30 @@ void Skybox::Init(float size){
 | 
				
			|||||||
	int count = 0;
 | 
						int count = 0;
 | 
				
			||||||
	VertexBuffer::VertexData* vd = new VertexBuffer::VertexData[24];
 | 
						VertexBuffer::VertexData* vd = new VertexBuffer::VertexData[24];
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	vd[count++] = VertexBuffer::VertexData(size, -size, size, 1.f, 1.f, 1.f, 0.f, .5f);
 | 
						vd[count++] = VertexBuffer::VertexData(-size, -size, size, 1.f, 1.f, 1.f, .25f, .5f); 
 | 
				
			||||||
	vd[count++] = VertexBuffer::VertexData(-size, -size, size, 1.f, 1.f, 1.f, .25f, .5f);
 | 
						vd[count++] = VertexBuffer::VertexData(-size, size, size, 1.f, 1.f, 1.f, .25f, .75f); 
 | 
				
			||||||
 | 
						vd[count++] = VertexBuffer::VertexData(size, size, size, 1.f, 1.f, 1.f, 0.f, .75f);   
 | 
				
			||||||
 | 
						vd[count++] = VertexBuffer::VertexData(size, -size, size, 1.f, 1.f, 1.f, 0.f, .5f);   
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						vd[count++] = VertexBuffer::VertexData(-size, -size, -size, 1.f, 1.f, 1.f, .5f, .5f); 
 | 
				
			||||||
 | 
						vd[count++] = VertexBuffer::VertexData(-size, size, -size, 1.f, 1.f, 1.f, .5f, .75f); 
 | 
				
			||||||
 | 
						vd[count++] = VertexBuffer::VertexData(-size, size, size, 1.f, 1.f, 1.f, .25f, .75f); 
 | 
				
			||||||
 | 
						vd[count++] = VertexBuffer::VertexData(-size, -size, size, 1.f, 1.f, 1.f, .25f, .5f); 
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						vd[count++] = VertexBuffer::VertexData(size, -size, -size, 1.f, 1.f, 1.f, .75f, .5f); 
 | 
				
			||||||
 | 
						vd[count++] = VertexBuffer::VertexData(size, size, -size, 1.f, 1.f, 1.f, .75f, .75f); 
 | 
				
			||||||
 | 
						vd[count++] = VertexBuffer::VertexData(-size, size, -size, 1.f, 1.f, 1.f, .5f, .75f); 
 | 
				
			||||||
 | 
						vd[count++] = VertexBuffer::VertexData(-size, -size, -size, 1.f, 1.f, 1.f, .5f, .5f); 
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						vd[count++] = VertexBuffer::VertexData(size, -size, size, 1.f, 1.f, 1.f, 1.f, .5f);   
 | 
				
			||||||
 | 
						vd[count++] = VertexBuffer::VertexData(size, size, size, 1.f, 1.f, 1.f, 1.f, .75f);   
 | 
				
			||||||
 | 
						vd[count++] = VertexBuffer::VertexData(size, size, -size, 1.f, 1.f, 1.f, .75f, .75f); 
 | 
				
			||||||
 | 
						vd[count++] = VertexBuffer::VertexData(size, -size, -size, 1.f, 1.f, 1.f, .75f, .5f); 
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						vd[count++] = VertexBuffer::VertexData(size, size, size, 1.f, 1.f, 1.f, .25f, 1.f);  
 | 
				
			||||||
	vd[count++] = VertexBuffer::VertexData(-size, size, size, 1.f, 1.f, 1.f, .25f, .75f);
 | 
						vd[count++] = VertexBuffer::VertexData(-size, size, size, 1.f, 1.f, 1.f, .25f, .75f);
 | 
				
			||||||
	vd[count++] = VertexBuffer::VertexData(size, size, size, 1.f, 1.f, 1.f, 0.f, .75f);
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	vd[count++] = VertexBuffer::VertexData(-size, -size, size, 1.f, 1.f, 1.f, .25f, .5f);
 | 
					 | 
				
			||||||
	vd[count++] = VertexBuffer::VertexData(-size, -size, -size, 1.f, 1.f, 1.f, .5f, .5f);
 | 
					 | 
				
			||||||
	vd[count++] = VertexBuffer::VertexData(-size, size, -size, 1.f, 1.f, 1.f, .5f, .75f);
 | 
						vd[count++] = VertexBuffer::VertexData(-size, size, -size, 1.f, 1.f, 1.f, .5f, .75f);
 | 
				
			||||||
	vd[count++] = VertexBuffer::VertexData(-size, size, size, 1.f, 1.f, 1.f, .25f, .75f);
 | 
						vd[count++] = VertexBuffer::VertexData(size, size, -size, 1.f, 1.f, 1.f, .5f, 1.f);  
 | 
				
			||||||
 | 
					 | 
				
			||||||
	vd[count++] = VertexBuffer::VertexData(-size, -size, -size, 1.f, 1.f, 1.f, .5f, .5f);
 | 
					 | 
				
			||||||
	vd[count++] = VertexBuffer::VertexData(size, -size, -size, 1.f, 1.f, 1.f, .75f, .5f);
 | 
					 | 
				
			||||||
	vd[count++] = VertexBuffer::VertexData(size, size, -size, 1.f, 1.f, 1.f, .75f, .75f);
 | 
					 | 
				
			||||||
	vd[count++] = VertexBuffer::VertexData(-size, size, -size, 1.f, 1.f, 1.f, .5f, .75f);
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	vd[count++] = VertexBuffer::VertexData(size, -size, -size, 1.f, 1.f, 1.f, .75f, .5f);
 | 
					 | 
				
			||||||
	vd[count++] = VertexBuffer::VertexData(size, -size, size, 1.f, 1.f, 1.f, 1.f, .5f);
 | 
					 | 
				
			||||||
	vd[count++] = VertexBuffer::VertexData(size, size, size, 1.f, 1.f, 1.f, 1.f, .75f);
 | 
					 | 
				
			||||||
	vd[count++] = VertexBuffer::VertexData(size, size, -size, 1.f, 1.f, 1.f, .75f, .75f);
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	vd[count++] = VertexBuffer::VertexData(size, size, -size, 1.f, 1.f, 1.f, .25f, 1.f);
 | 
					 | 
				
			||||||
	vd[count++] = VertexBuffer::VertexData(size, size, size, 1.f, 1.f, 1.f, .5f, 1.f);
 | 
					 | 
				
			||||||
	vd[count++] = VertexBuffer::VertexData(-size, size, size, 1.f, 1.f, 1.f, .5f, .75f);
 | 
					 | 
				
			||||||
	vd[count++] = VertexBuffer::VertexData(-size, size, -size, 1.f, 1.f, 1.f, .25f, .75f);
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
	vd[count++] = VertexBuffer::VertexData(-size, -size, size, 1.f, 1.f, 1.f, .5f, .25f);
 | 
						vd[count++] = VertexBuffer::VertexData(-size, -size, size, 1.f, 1.f, 1.f, .5f, .25f);
 | 
				
			||||||
	vd[count++] = VertexBuffer::VertexData(size, -size, size, 1.f, 1.f, 1.f, .75f, .25f);
 | 
						vd[count++] = VertexBuffer::VertexData(size, -size, size, 1.f, 1.f, 1.f, .75f, .25f);
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -1,23 +0,0 @@
 | 
				
			|||||||
#ifndef WORLDRENDERER_H__
 | 
					 | 
				
			||||||
#define WORLDRENDERER_H__
 | 
					 | 
				
			||||||
#include <future>
 | 
					 | 
				
			||||||
#include <thread>
 | 
					 | 
				
			||||||
#include "../SQCSim-common/world.h"
 | 
					 | 
				
			||||||
#include "../SQCSim-common/transformation.h"
 | 
					 | 
				
			||||||
#include "define.h"
 | 
					 | 
				
			||||||
#include "mesh.h"
 | 
					 | 
				
			||||||
#include "textureatlas.h"
 | 
					 | 
				
			||||||
#include "shader.h"
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
class WorldRenderer {
 | 
					 | 
				
			||||||
private:
 | 
					 | 
				
			||||||
	Array2d<Mesh*> m_meshes = Array2d<Mesh*>(WORLD_SIZE_X, WORLD_SIZE_Y);
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
public:
 | 
					 | 
				
			||||||
	WorldRenderer();
 | 
					 | 
				
			||||||
	~WorldRenderer();
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	void RenderWorld(World* origin, int& rendercount, const Vector3f& player_pos, const Vector3f& player_dir, Transformation& world, Shader& shader, TextureAtlas& atlas);
 | 
					 | 
				
			||||||
	void UpdateWorld(World* origin, const Vector3f& player, BlockInfo* blockinfo[BTYPE_LAST]);
 | 
					 | 
				
			||||||
};
 | 
					 | 
				
			||||||
#endif
 | 
					 | 
				
			||||||
		Reference in New Issue
	
	Block a user