cleanup de fichiers en double
This commit is contained in:
		| @@ -30,3 +30,7 @@ void Bullet::Transpose(int& x, int& z) { | ||||
| 	m_startpos.x -= x * CHUNK_SIZE_X; | ||||
| 	m_startpos.z -= z * CHUNK_SIZE_Z; | ||||
| } | ||||
|  | ||||
| Vector3f& Bullet::getPos() { | ||||
| 	return m_currentpos; | ||||
| } | ||||
|   | ||||
| @@ -12,6 +12,7 @@ public: | ||||
|  | ||||
| 	bool Update(World* world, float elapsedtime); | ||||
| 	void Transpose(int& x, int& z); | ||||
| 	Vector3f& getPos(); | ||||
|  | ||||
| private: | ||||
| 	Vector3f m_startpos; | ||||
|   | ||||
| @@ -11,7 +11,7 @@ | ||||
| #define CHUNK_SIZE_Y  64 | ||||
| #define CHUNK_SIZE_Z  4 | ||||
| #define MAX_SELECTION_DISTANCE 5 | ||||
| #define SEED 12345 | ||||
| #define SEED 0 | ||||
| #define COUNTDOWN 300 | ||||
|  | ||||
| #define WORLD_SIZE_X 64 | ||||
|   | ||||
| @@ -13,7 +13,26 @@ void netprot::Serialize(Sync* sync, char* buf[], uint32_t* buflen) { | ||||
| } | ||||
|  | ||||
| void netprot::Serialize(TeamInfo* tinfo, char* buf[], uint32_t* buflen) { | ||||
| 	*buf[0] = netprot::PACKET_TYPE::TEAMINF; | ||||
|  | ||||
| 	size_t namesize = std::strlen(tinfo->name) + 1; | ||||
|  | ||||
| 	memcpy(*buf + 1, &tinfo->name, namesize); | ||||
| 	uint64_t tid = tinfo->id; | ||||
| 	uint8_t tid8[sizeof(uint64_t)] = { | ||||
| 									   (tid >> 56) & 0xFF, | ||||
| 									   (tid >> 48) & 0xFF, | ||||
| 									   (tid >> 40) & 0xFF, | ||||
| 									   (tid >> 32) & 0xFF, | ||||
| 									   (tid >> 24) & 0xFF, | ||||
| 									   (tid >> 16) & 0xFF, | ||||
| 									   (tid >> 8) & 0xFF, | ||||
| 									   tid & 0xFF | ||||
| 	}; | ||||
|  | ||||
| 	memcpy(*buf + namesize + 2, tid8, sizeof(uint64_t)); | ||||
|  | ||||
| 	*buflen = namesize + sizeof(uint64_t) + 2; | ||||
| } | ||||
|  | ||||
| void netprot::Serialize(LoginInfo* linfo, char* buf[], uint32_t* buflen) { | ||||
| @@ -54,7 +73,40 @@ void netprot::Serialize(LoginInfo* linfo, char* buf[], uint32_t* buflen) { | ||||
| } | ||||
|  | ||||
| void netprot::Serialize(PlayerInfo* pinfo, char* buf[], uint32_t* buflen) { | ||||
| 	*buf[0] = netprot::PACKET_TYPE::PLAYINF; | ||||
|  | ||||
| 	size_t namesize = std::strlen(pinfo->name) + 1; | ||||
|  | ||||
| 	memcpy(*buf + 1, &pinfo->name, namesize); | ||||
| 	uint64_t id = pinfo->id; | ||||
| 	uint8_t id8[sizeof(uint64_t)] = { | ||||
| 									   (id >> 56) & 0xFF, | ||||
| 									   (id >> 48) & 0xFF, | ||||
| 									   (id >> 40) & 0xFF, | ||||
| 									   (id >> 32) & 0xFF, | ||||
| 									   (id >> 24) & 0xFF, | ||||
| 									   (id >> 16) & 0xFF, | ||||
| 									   (id >> 8) & 0xFF, | ||||
| 									   id & 0xFF | ||||
| 	}; | ||||
|  | ||||
| 	memcpy(*buf + namesize + 2, id8, sizeof(uint64_t)); | ||||
|  | ||||
| 	uint64_t tid = pinfo->tid; | ||||
| 	uint8_t tid8[sizeof(uint64_t)] = { | ||||
| 									   (tid >> 56) & 0xFF, | ||||
| 									   (tid >> 48) & 0xFF, | ||||
| 									   (tid >> 40) & 0xFF, | ||||
| 									   (tid >> 32) & 0xFF, | ||||
| 									   (tid >> 24) & 0xFF, | ||||
| 									   (tid >> 16) & 0xFF, | ||||
| 									   (tid >> 8) & 0xFF, | ||||
| 									   tid & 0xFF  | ||||
| 	}; | ||||
|  | ||||
| 	memcpy(*buf + namesize + 2 + sizeof(uint64_t), tid8, sizeof(uint64_t)); | ||||
|  | ||||
| 	*buflen = namesize + sizeof(uint64_t) * 2 + 2; | ||||
| } | ||||
|  | ||||
| void netprot::Serialize(GameInfo* ginfo, char* buf[], uint32_t* buflen) { | ||||
| @@ -106,11 +158,67 @@ void netprot::Serialize(GameInfo* ginfo, char* buf[], uint32_t* buflen) { | ||||
| } | ||||
|  | ||||
| void netprot::Serialize(Chat* chat, char* buf[], uint32_t* buflen) { | ||||
| 	*buf[0] = netprot::PACKET_TYPE::CHAT; | ||||
|  | ||||
| 	uint64_t src = chat->src_id; | ||||
| 	uint8_t src8[sizeof(uint64_t)] = { | ||||
| 									   (src >> 56) & 0xFF, | ||||
| 									   (src >> 48) & 0xFF, | ||||
| 									   (src >> 40) & 0xFF, | ||||
| 									   (src >> 32) & 0xFF, | ||||
| 									   (src >> 24) & 0xFF, | ||||
| 									   (src >> 16) & 0xFF, | ||||
| 									   (src >> 8) & 0xFF, | ||||
| 									   src & 0xFF | ||||
| 	}; | ||||
|  | ||||
| 	memcpy(*buf + 1, src8, sizeof(uint64_t)); | ||||
|  | ||||
| 	uint64_t dst = chat->dest_id; | ||||
| 	uint8_t dst8[sizeof(uint64_t)] = { | ||||
| 									   (dst >> 56) & 0xFF, | ||||
| 									   (dst >> 48) & 0xFF, | ||||
| 									   (dst >> 40) & 0xFF, | ||||
| 									   (dst >> 32) & 0xFF, | ||||
| 									   (dst >> 24) & 0xFF, | ||||
| 									   (dst >> 16) & 0xFF, | ||||
| 									   (dst >> 8) & 0xFF, | ||||
| 									   dst & 0xFF | ||||
| 	}; | ||||
|  | ||||
| 	memcpy(*buf + 1 + sizeof(uint64_t), dst8, sizeof(uint64_t)); | ||||
|  | ||||
| 	uint64_t dstteam = chat->dest_id; | ||||
| 	uint8_t dstt8[sizeof(uint64_t)] = { | ||||
| 									   (dstteam >> 56) & 0xFF, | ||||
| 									   (dstteam >> 48) & 0xFF, | ||||
| 									   (dstteam >> 40) & 0xFF, | ||||
| 									   (dstteam >> 32) & 0xFF, | ||||
| 									   (dstteam >> 24) & 0xFF, | ||||
| 									   (dstteam >> 16) & 0xFF, | ||||
| 									   (dstteam >> 8) & 0xFF, | ||||
| 									   dstteam & 0xFF | ||||
| 	}; | ||||
| 	 | ||||
| 	memcpy(*buf + 1 + sizeof(uint64_t) * 2, dstt8, sizeof(uint64_t)); | ||||
|  | ||||
| 	size_t messize = std::strlen(chat->mess) + 1; | ||||
|  | ||||
| 	memcpy(*buf + 1 + sizeof(uint64_t) * 3, &chat->mess, messize); | ||||
|  | ||||
| 	*buflen = messize + sizeof(uint64_t) * 3 + 2; | ||||
| } | ||||
|  | ||||
| void netprot::Serialize(ErrorLog* errlog, char* buf[], uint32_t* buflen) { | ||||
| 	*buf[0] = netprot::PACKET_TYPE::ERRLOG; | ||||
|  | ||||
| 	size_t messize = std::strlen(errlog->mess) + 1; | ||||
|  | ||||
| 	memcpy(*buf + 1, &errlog->mess, messize); | ||||
|  | ||||
| 	memcpy(*buf + 1 + messize, &errlog->is_fatal, sizeof(bool)); | ||||
|  | ||||
| 	*buflen = messize + sizeof(bool) + 1; | ||||
| } | ||||
|  | ||||
|  | ||||
| @@ -128,11 +236,33 @@ bool netprot::Deserialize(Sync* sync, char* buf, const uint32_t buflen) { | ||||
| } | ||||
|  | ||||
| bool netprot::Deserialize(TeamInfo* tinfo, char* buf, const uint32_t buflen) { | ||||
| 	return false; | ||||
| 	if (buflen <= sizeof(LoginInfo)) | ||||
| 		return false; | ||||
|  | ||||
| 	size_t namesize = std::strlen(buf) + 1; | ||||
|  | ||||
| 	if (namesize > 32) | ||||
| 		return false; | ||||
|  | ||||
| 	memcpy(&tinfo->name, &buf[1], namesize); | ||||
|  | ||||
| 	uint8_t diff[sizeof(uint64_t)] = { 0,0,0,0,0,0,0,0 }; | ||||
| 	memcpy(diff, &buf[namesize + 1], sizeof(uint64_t)); | ||||
| 	tinfo->id = | ||||
| 		(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]; | ||||
|  | ||||
| 	return true; | ||||
| } | ||||
|  | ||||
| bool netprot::Deserialize(LoginInfo* linfo, char* buf, const uint32_t buflen) { | ||||
| 	if (buflen < sizeof(LoginInfo) + 3) | ||||
| 	if (buflen <= sizeof(LoginInfo)) | ||||
| 		return false; | ||||
|  | ||||
| 	size_t namesize = std::strlen(buf) + 1; | ||||
| @@ -169,11 +299,44 @@ bool netprot::Deserialize(LoginInfo* linfo, char* buf, const uint32_t buflen) { | ||||
| } | ||||
|  | ||||
| bool netprot::Deserialize(PlayerInfo* pinfo, char* buf, const uint32_t buflen) { | ||||
| 	return false; | ||||
| 	if (buflen <= sizeof(PlayerInfo)) | ||||
| 		return false; | ||||
|  | ||||
| 	size_t namesize = std::strlen(buf) + 1; | ||||
|  | ||||
| 	if (namesize > 32) | ||||
| 		return false; | ||||
|  | ||||
| 	memcpy(&pinfo->name, &buf[1], namesize); | ||||
|  | ||||
| 	uint8_t diff[sizeof(uint64_t)] = { 0,0,0,0,0,0,0,0 }; | ||||
| 	memcpy(diff, &buf[namesize + 1], sizeof(uint64_t)); | ||||
| 	pinfo->id = | ||||
| 		(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[namesize + sizeof(uint64_t) + 1], sizeof(uint64_t)); | ||||
| 	pinfo->tid = | ||||
| 		(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]; | ||||
|  | ||||
| 	return true; | ||||
| } | ||||
|  | ||||
| bool netprot::Deserialize(GameInfo* ginfo, char* buf, const uint32_t buflen) { | ||||
| 	if (buflen < sizeof(GameInfo) + 1) | ||||
| 	if (buflen <= sizeof(GameInfo)) | ||||
| 		return false; | ||||
|  | ||||
| 	uint8_t diff[sizeof(uint64_t)] = { 0,0,0,0,0,0,0,0 }; | ||||
| @@ -214,11 +377,67 @@ bool netprot::Deserialize(GameInfo* ginfo, char* buf, const uint32_t buflen) { | ||||
| } | ||||
|  | ||||
| bool netprot::Deserialize(Chat* chat, char* buf, const uint32_t buflen) { | ||||
| 	return false; | ||||
| 	if (buflen <= sizeof(Chat)) | ||||
| 		return false; | ||||
|  | ||||
| 	uint8_t src[sizeof(uint64_t)] = { 0,0,0,0,0,0,0,0 }; | ||||
| 	memcpy(src, &buf[1], sizeof(uint64_t)); | ||||
| 	chat->src_id = | ||||
| 		(uint64_t)src[0] << 56 | | ||||
| 		(uint64_t)src[1] << 48 | | ||||
| 		(uint64_t)src[2] << 40 | | ||||
| 		(uint64_t)src[3] << 32 | | ||||
| 		(uint64_t)src[4] << 24 | | ||||
| 		(uint64_t)src[5] << 16 | | ||||
| 		(uint64_t)src[6] << 8 | | ||||
| 		(uint64_t)src[7]; | ||||
|  | ||||
| 	uint8_t dst[sizeof(uint64_t)] = { 0,0,0,0,0,0,0,0 }; | ||||
| 	memcpy(dst, &buf[1 + sizeof(uint64_t)], sizeof(uint64_t)); | ||||
| 	chat->dest_id = | ||||
| 		(uint64_t)dst[0] << 56 | | ||||
| 		(uint64_t)dst[1] << 48 | | ||||
| 		(uint64_t)dst[2] << 40 | | ||||
| 		(uint64_t)dst[3] << 32 | | ||||
| 		(uint64_t)dst[4] << 24 | | ||||
| 		(uint64_t)dst[5] << 16 | | ||||
| 		(uint64_t)dst[6] << 8 | | ||||
| 		(uint64_t)dst[7]; | ||||
|  | ||||
| 	uint8_t dstt[sizeof(uint64_t)] = { 0,0,0,0,0,0,0,0 }; | ||||
| 	memcpy(dstt, &buf[1 + sizeof(uint64_t) * 2], sizeof(uint64_t)); | ||||
| 	chat->dest_team_id = | ||||
| 		(uint64_t)dstt[0] << 56 | | ||||
| 		(uint64_t)dstt[1] << 48 | | ||||
| 		(uint64_t)dstt[2] << 40 | | ||||
| 		(uint64_t)dstt[3] << 32 | | ||||
| 		(uint64_t)dstt[4] << 24 | | ||||
| 		(uint64_t)dstt[5] << 16 | | ||||
| 		(uint64_t)dstt[6] << 8 | | ||||
| 		(uint64_t)dstt[7]; | ||||
|  | ||||
| 	size_t messsize = std::strlen(buf + sizeof(uint64_t) * 3) + 1; | ||||
|  | ||||
| 	if (messsize > 140) | ||||
| 		return false; | ||||
|  | ||||
| 	memcpy(&chat->mess, &buf[1 + sizeof(uint64_t) * 3], messsize); | ||||
| 	return true; | ||||
| } | ||||
|  | ||||
| bool netprot::Deserialize(ErrorLog* errlog, char* buf, const uint32_t buflen) { | ||||
| 	return false; | ||||
| 	if (buflen <= sizeof(ErrorLog)) | ||||
| 		return false; | ||||
|  | ||||
| 	size_t messsize = std::strlen(buf) + 1; | ||||
|  | ||||
| 	if (messsize > 140) | ||||
| 		return false; | ||||
|  | ||||
| 	memcpy(&errlog->mess, &buf[1], messsize); | ||||
| 	memcpy(&errlog->is_fatal, &buf[1 + messsize], sizeof(bool)); | ||||
|  | ||||
| 	return true; | ||||
| } | ||||
|  | ||||
| netprot::PacketType netprot::getType(char* buf, const uint32_t buflen) { | ||||
|   | ||||
| @@ -18,9 +18,26 @@ namespace netprot { | ||||
| 				LAST_PACK | ||||
| 			}; | ||||
|  | ||||
| 	struct Keys { | ||||
| 		bool forward,  | ||||
| 			 backward,  | ||||
| 			 left,  | ||||
| 			 right,  | ||||
| 			 jump,  | ||||
| 			 shoot; | ||||
| 	}; | ||||
|  | ||||
| 	struct States { | ||||
| 		bool jumping,  | ||||
| 			 shooting,  | ||||
| 			 hit,  | ||||
| 			 powerup; | ||||
| 	}; | ||||
|  | ||||
| 	struct Input {										// cli -> srv			UDP			~frame | ||||
| 		Timestamp timestamp; | ||||
| 		uint8_t keys; // 0bFBLRJS__ bit-packing de bool. | ||||
| 		uint64_t sid = 0; | ||||
| 		Keys keys; // 0bFBLRJS__ bit-packing de bool. | ||||
| 		Vector3f direction; | ||||
| 	}; | ||||
|  | ||||
| @@ -28,8 +45,8 @@ namespace netprot { | ||||
| 		Timestamp timestamp; | ||||
| 		uint64_t id = 0; | ||||
| 		Vector3f position, | ||||
| 			  direction; | ||||
| 		uint8_t states; // 0bJSH_____ bit-packing de bool. | ||||
| 			     direction; | ||||
| 		States states; // 0bJSH_____ bit-packing de bool. | ||||
| 	}; | ||||
|  | ||||
| 	struct Sync {										// srv -> cli			TCP			~second | ||||
|   | ||||
| @@ -19,18 +19,13 @@ | ||||
|     </ProjectConfiguration> | ||||
|   </ItemGroup> | ||||
|   <ItemGroup> | ||||
|     <ClInclude Include="array2d.h" /> | ||||
|     <ClInclude Include="array3d.h" /> | ||||
|     <ClInclude Include="audio.h" /> | ||||
|     <ClInclude Include="blockinfo.h" /> | ||||
|     <ClInclude Include="bullet.h" /> | ||||
|     <ClInclude Include="chunk.h" /> | ||||
|     <ClInclude Include="connector.h" /> | ||||
|     <ClInclude Include="define.h" /> | ||||
|     <ClInclude Include="engine.h" /> | ||||
|     <ClInclude Include="matrix4.h" /> | ||||
|     <ClInclude Include="openglcontext.h" /> | ||||
|     <ClInclude Include="opensimplex.h" /> | ||||
|     <ClInclude Include="player.h" /> | ||||
|     <ClInclude Include="shader.h" /> | ||||
|     <ClInclude Include="skybox.h" /> | ||||
| @@ -43,14 +38,12 @@ | ||||
|   </ItemGroup> | ||||
|   <ItemGroup> | ||||
|     <ClCompile Include="audio.cpp" /> | ||||
|     <ClCompile Include="blockinfo.cpp" /> | ||||
|     <ClCompile Include="bullet.cpp" /> | ||||
|     <ClCompile Include="chunk.cpp" /> | ||||
|     <ClCompile Include="connector.cpp" /> | ||||
|     <ClCompile Include="engine.cpp" /> | ||||
|     <ClCompile Include="main.cpp" /> | ||||
|     <ClCompile Include="openglcontext.cpp" /> | ||||
|     <ClCompile Include="opensimplex.cpp" /> | ||||
|     <ClCompile Include="player.cpp" /> | ||||
|     <ClCompile Include="shader.cpp" /> | ||||
|     <ClCompile Include="skybox.cpp" /> | ||||
|   | ||||
| @@ -11,12 +11,6 @@ | ||||
|     </Filter> | ||||
|   </ItemGroup> | ||||
|   <ItemGroup> | ||||
|     <ClInclude Include="array3d.h"> | ||||
|       <Filter>Fichiers d%27en-tête</Filter> | ||||
|     </ClInclude> | ||||
|     <ClInclude Include="blockinfo.h"> | ||||
|       <Filter>Fichiers d%27en-tête</Filter> | ||||
|     </ClInclude> | ||||
|     <ClInclude Include="chunk.h"> | ||||
|       <Filter>Fichiers d%27en-tête</Filter> | ||||
|     </ClInclude> | ||||
| @@ -26,12 +20,6 @@ | ||||
|     <ClInclude Include="engine.h"> | ||||
|       <Filter>Fichiers d%27en-tête</Filter> | ||||
|     </ClInclude> | ||||
|     <ClInclude Include="matrix4.h"> | ||||
|       <Filter>Fichiers d%27en-tête</Filter> | ||||
|     </ClInclude> | ||||
|     <ClInclude Include="openglcontext.h"> | ||||
|       <Filter>Fichiers d%27en-tête</Filter> | ||||
|     </ClInclude> | ||||
|     <ClInclude Include="texture.h"> | ||||
|       <Filter>Fichiers d%27en-tête</Filter> | ||||
|     </ClInclude> | ||||
| @@ -44,15 +32,9 @@ | ||||
|     <ClInclude Include="shader.h"> | ||||
|       <Filter>Fichiers d%27en-tête</Filter> | ||||
|     </ClInclude> | ||||
|     <ClInclude Include="tool.h"> | ||||
|       <Filter>Fichiers d%27en-tête</Filter> | ||||
|     </ClInclude> | ||||
|     <ClInclude Include="vertexbuffer.h"> | ||||
|       <Filter>Fichiers d%27en-tête</Filter> | ||||
|     </ClInclude> | ||||
|     <ClInclude Include="array2d.h"> | ||||
|       <Filter>Fichiers d%27en-tête</Filter> | ||||
|     </ClInclude> | ||||
|     <ClInclude Include="skybox.h"> | ||||
|       <Filter>Fichiers d%27en-tête</Filter> | ||||
|     </ClInclude> | ||||
| @@ -65,20 +47,20 @@ | ||||
|     <ClInclude Include="world.h"> | ||||
|       <Filter>Fichiers d%27en-tête</Filter> | ||||
|     </ClInclude> | ||||
|     <ClInclude Include="bullet.h"> | ||||
|       <Filter>Fichiers d%27en-tête</Filter> | ||||
|     </ClInclude> | ||||
|     <ClInclude Include="opensimplex.h"> | ||||
|       <Filter>Fichiers d%27en-tête</Filter> | ||||
|     </ClInclude> | ||||
|     <ClInclude Include="connector.h"> | ||||
|       <Filter>Fichiers d%27en-tête</Filter> | ||||
|     </ClInclude> | ||||
|     <ClInclude Include="openglcontext.h"> | ||||
|       <Filter>Fichiers d%27en-tête</Filter> | ||||
|     </ClInclude> | ||||
|     <ClInclude Include="tool.h"> | ||||
|       <Filter>Fichiers d%27en-tête</Filter> | ||||
|     </ClInclude> | ||||
|     <ClInclude Include="bullet.h"> | ||||
|       <Filter>Fichiers d%27en-tête</Filter> | ||||
|     </ClInclude> | ||||
|   </ItemGroup> | ||||
|   <ItemGroup> | ||||
|     <ClCompile Include="blockinfo.cpp"> | ||||
|       <Filter>Fichiers sources</Filter> | ||||
|     </ClCompile> | ||||
|     <ClCompile Include="chunk.cpp"> | ||||
|       <Filter>Fichiers sources</Filter> | ||||
|     </ClCompile> | ||||
| @@ -103,9 +85,6 @@ | ||||
|     <ClCompile Include="shader.cpp"> | ||||
|       <Filter>Fichiers sources</Filter> | ||||
|     </ClCompile> | ||||
|     <ClCompile Include="tool.cpp"> | ||||
|       <Filter>Fichiers sources</Filter> | ||||
|     </ClCompile> | ||||
|     <ClCompile Include="vertexbuffer.cpp"> | ||||
|       <Filter>Fichiers sources</Filter> | ||||
|     </ClCompile> | ||||
| @@ -121,14 +100,14 @@ | ||||
|     <ClCompile Include="world.cpp"> | ||||
|       <Filter>Fichiers sources</Filter> | ||||
|     </ClCompile> | ||||
|     <ClCompile Include="bullet.cpp"> | ||||
|       <Filter>Fichiers sources</Filter> | ||||
|     </ClCompile> | ||||
|     <ClCompile Include="opensimplex.cpp"> | ||||
|       <Filter>Fichiers sources</Filter> | ||||
|     </ClCompile> | ||||
|     <ClCompile Include="connector.cpp"> | ||||
|       <Filter>Fichiers sources</Filter> | ||||
|     </ClCompile> | ||||
|     <ClCompile Include="tool.cpp"> | ||||
|       <Filter>Fichiers sources</Filter> | ||||
|     </ClCompile> | ||||
|     <ClCompile Include="bullet.cpp"> | ||||
|       <Filter>Fichiers sources</Filter> | ||||
|     </ClCompile> | ||||
|   </ItemGroup> | ||||
| </Project> | ||||
| @@ -1,61 +0,0 @@ | ||||
| #ifndef ARRAY2D_H__ | ||||
| #define ARRAY2D_H__ | ||||
|  | ||||
| #include "define.h" | ||||
|  | ||||
| template <class T> | ||||
| class Array2d { | ||||
|     public: | ||||
|         Array2d(int x, int y); | ||||
|         ~Array2d(); | ||||
|         Array2d(const Array2d& array); | ||||
|  | ||||
|         void Set(int x, int y, T type); | ||||
|         T Get(int x, int y) const; | ||||
|         T Remove(int x, int y); | ||||
|  | ||||
|         void Reset(T type); | ||||
|  | ||||
|     private: | ||||
|         int m_x, m_y; | ||||
|         T* m_array; | ||||
|  | ||||
|         int To1dIndex(int x, int y) const; | ||||
| }; | ||||
|  | ||||
| template <class T> | ||||
| Array2d<T>::Array2d(int x, int y) : m_x(x), m_y(y) { m_array = new T[m_x * m_y]; } | ||||
|  | ||||
| template <class T> | ||||
| Array2d<T>::~Array2d() { delete[] m_array; } | ||||
|  | ||||
| template <class T> | ||||
| Array2d<T>::Array2d(const Array2d<T>& array) : m_x(array.m_x), m_y(array.m_y) { | ||||
|     m_array = new T[m_x * m_y]; | ||||
|     for (int i = 0; i < m_x * m_y; ++i) | ||||
|         m_array[i] = array.m_array[i]; | ||||
| } | ||||
|  | ||||
| template <class T> | ||||
| void Array2d<T>::Set(int x, int y, T type) { m_array[To1dIndex(x, y)] = type; } | ||||
|  | ||||
| template <class T> | ||||
| T Array2d<T>::Get(int x, int y) const { return m_array[To1dIndex(x, y)]; } | ||||
|  | ||||
| template <class T> | ||||
| T Array2d<T>::Remove(int x, int y) {  | ||||
|     T thing = std::move(m_array[To1dIndex(x, y)]); | ||||
|     m_array[To1dIndex(x, y)] = nullptr; | ||||
|     return thing; | ||||
| } | ||||
|  | ||||
| template <class T> | ||||
| void Array2d<T>::Reset(T type) { | ||||
|     for (int i = 0; i < m_x * m_y; ++i) | ||||
|         m_array[i] = type; | ||||
| } | ||||
|  | ||||
| template <class T> | ||||
| int Array2d<T>::To1dIndex(int x, int y) const { return x + (y * m_x); } | ||||
|  | ||||
| #endif // ARRAY2D_H__ | ||||
| @@ -1,55 +0,0 @@ | ||||
| #ifndef ARRAY3D_H__ | ||||
| #define ARRAY3D_H__ | ||||
|  | ||||
| #include "define.h" | ||||
|  | ||||
| template <class T> | ||||
| class Array3d { | ||||
|     public: | ||||
|         Array3d(int x, int y, int z); | ||||
|         ~Array3d(); | ||||
|         Array3d(const Array3d& array); | ||||
|  | ||||
|         void Set(int x, int y, int z, T type); | ||||
|         T Get(int x, int y, int z) const; | ||||
|  | ||||
|         void Reset(T type); | ||||
|  | ||||
|     private: | ||||
|         int m_x, m_y, m_z; | ||||
|         T* m_array; | ||||
|  | ||||
|         int To1dIndex(int x, int y, int z) const; | ||||
| }; | ||||
|  | ||||
| template <class T> | ||||
| Array3d<T>::Array3d(int x, int y, int z) : m_x(x), m_y(y), m_z(z) { m_array = new T[m_x * m_y * m_z]; } | ||||
|  | ||||
| template <class T> | ||||
| Array3d<T>::~Array3d() { delete[] m_array; } | ||||
|  | ||||
| template <class T> | ||||
| Array3d<T>::Array3d(const Array3d<T>& array) : m_x(array.m_x), m_y(array.m_y), m_z(array.m_z) { | ||||
|     m_array = new T[m_x * m_y * m_z]; | ||||
|     for (int i = 0; i < m_x * m_y * m_z; ++i) | ||||
|         m_array[i] = array.m_array[i]; | ||||
| } | ||||
|  | ||||
| template <class T> | ||||
| void Array3d<T>::Set(int x, int y, int z, T type) {  | ||||
|     m_array[To1dIndex(x, y, z)] = type;  | ||||
| } | ||||
|  | ||||
| template <class T> | ||||
| T Array3d<T>::Get(int x, int y, int z) const { return m_array[To1dIndex(x, y, z)]; } | ||||
|         | ||||
| template <class T> | ||||
| void Array3d<T>::Reset(T type) { | ||||
|     for (int i = 0; i < m_x * m_y * m_z; ++i) | ||||
|         m_array[i] = type; | ||||
| } | ||||
|  | ||||
| template <class T> | ||||
| int Array3d<T>::To1dIndex(int x, int y, int z) const { return x + (z * m_x) + (y * m_z * m_x); } | ||||
|  | ||||
| #endif // ARRAY3D_H__ | ||||
| @@ -1,42 +0,0 @@ | ||||
| #include "blockinfo.h" | ||||
| #include <iostream> | ||||
|  | ||||
| BlockInfo::BlockInfo(BlockType type, const std::string& name, float u, float v, float s, int dur) : m_type(type), m_name(name), m_u(u), m_v(v), m_s(s), m_durability(dur) | ||||
| { | ||||
| } | ||||
|  | ||||
| BlockInfo::~BlockInfo() | ||||
| { | ||||
| } | ||||
|  | ||||
| BlockType BlockInfo::GetType() const | ||||
| { | ||||
|     return m_type; | ||||
| } | ||||
|  | ||||
| void BlockInfo::SetDurability(int durability) | ||||
| { | ||||
|     m_durability = durability; | ||||
| } | ||||
|  | ||||
| int BlockInfo::GetDurability() const | ||||
| { | ||||
|     return m_durability; | ||||
| } | ||||
|  | ||||
| void BlockInfo::GetTexture(float& u, float& v, float& s) | ||||
| { | ||||
|     u = m_u; | ||||
|     v = m_v; | ||||
|     s = m_s; | ||||
| } | ||||
|  | ||||
| void BlockInfo::Show() const | ||||
| { | ||||
|     std::cout << "Type: " << m_type << std::endl; | ||||
|     std::cout << "Nom: " << m_name << std::endl; | ||||
|     std::cout << "Durabilite: " << m_durability << std::endl; | ||||
|     std::cout << "Coordonnees Texture: " << m_u << ", " << m_v << ", " << m_s << std::endl; | ||||
| } | ||||
|  | ||||
|  | ||||
| @@ -1,32 +0,0 @@ | ||||
| #ifndef BLOCKINFO_H__ | ||||
| #define BLOCKINFO_H__ | ||||
|  | ||||
| #include <string> | ||||
| #include "define.h" | ||||
|  | ||||
| class BlockInfo | ||||
| { | ||||
|     public: | ||||
|     BlockInfo(BlockType type, const std::string& name, float u, float v, float s, int dur); | ||||
|     ~BlockInfo(); | ||||
|  | ||||
|     BlockType GetType() const; | ||||
|  | ||||
|     void SetDurability(int durability); | ||||
|     int GetDurability() const; | ||||
|  | ||||
|     void GetTexture(float& u, float& v, float& s); | ||||
|  | ||||
|     void Show() const; | ||||
|  | ||||
|     private: | ||||
|     BlockType m_type; | ||||
|     float m_u; | ||||
|     float m_v; | ||||
|     float m_s; | ||||
|     std::string m_name; | ||||
|     int m_durability; | ||||
|  | ||||
| }; | ||||
|  | ||||
| #endif // BLOCKINFO_H__ | ||||
| @@ -1,11 +1,11 @@ | ||||
| #ifndef CHUNK_H__ | ||||
| #define CHUNK_H__ | ||||
| #include "define.h" | ||||
| #include "array3d.h" | ||||
| #include "array2d.h" | ||||
| #include "../SQCSim-common/array2d.h" | ||||
| #include "../SQCSim-common/array3d.h" | ||||
| #include "../SQCSim-common/blockinfo.h" | ||||
| #include "../SQCSim-common/opensimplex.h" | ||||
| #include "vertexbuffer.h" | ||||
| #include "blockinfo.h" | ||||
| #include "opensimplex.h" | ||||
|  | ||||
| class World; | ||||
|  | ||||
|   | ||||
| @@ -1,9 +1,9 @@ | ||||
| #ifndef CONNECTOR_H__ | ||||
| #define CONNECTOR_H__ | ||||
|  | ||||
| #include "define.h" | ||||
| #include "../SQCSim-common/netprotocol.h" | ||||
| #include <stdlib.h> | ||||
| #include "../SQCSim-common/netprotocol.h" | ||||
| #include "define.h" | ||||
|  | ||||
| class Connector { | ||||
| public: | ||||
|   | ||||
| @@ -46,7 +46,7 @@ void Engine::Init() { | ||||
| 	for (int x = 0; x < MAX_BULLETS; ++x) | ||||
| 		m_bullets[x] = nullptr; | ||||
|  | ||||
| 	uint64_t seed = 0; | ||||
| 	uint64_t seed = SEED; | ||||
| 	std::string playname = "La Chienne <20> Jacques"; | ||||
| 	if (NETWORK_TEST) { // Test connexion r<>seau. | ||||
| 		if (!m_conn.Init()) { | ||||
|   | ||||
| @@ -3,7 +3,10 @@ | ||||
|  | ||||
| #include <algorithm> | ||||
| #include <cmath> | ||||
| #include "../SQCSim-common/array2d.h" | ||||
| #include "../SQCSim-common/blockinfo.h" | ||||
| #include "define.h" | ||||
| #include "bullet.h" | ||||
| #include "openglcontext.h" | ||||
| #include "texture.h" | ||||
| #include "transformation.h" | ||||
| @@ -13,10 +16,7 @@ | ||||
| #include "skybox.h" | ||||
| #include "audio.h" | ||||
| #include "textureatlas.h" | ||||
| #include "blockinfo.h" | ||||
| #include "array2d.h" | ||||
| #include "world.h" | ||||
| #include "bullet.h" | ||||
| #include "connector.h" | ||||
|  | ||||
| class Engine : public OpenglContext { | ||||
|   | ||||
| @@ -1,571 +0,0 @@ | ||||
| #ifndef MATRIX4_H__ | ||||
| #define MATRIX4_H__ | ||||
|  | ||||
| #include <ostream> | ||||
| #include <sstream> | ||||
| #include <string> | ||||
|  | ||||
| #include "define.h" | ||||
| #include "../SQCSim-common/vector3.h" | ||||
|  | ||||
| #ifndef M_PI | ||||
| #define M_PI 3.14159265f | ||||
| #endif | ||||
|  | ||||
| #define DEGTORAD(x) ((x * M_PI) / 180.f) | ||||
| #define RADTODEG(x) ((180.f * x) / M_PI) | ||||
|  | ||||
| template <class T> | ||||
| class Matrix4 | ||||
| { | ||||
|     public: | ||||
|         typedef T Type; | ||||
|  | ||||
|     public: | ||||
|         static const Matrix4<T> ZERO; | ||||
|         static const Matrix4<T> IDENTITY; | ||||
|  | ||||
|     public: | ||||
|         Matrix4(); | ||||
|         Matrix4(const T& v); | ||||
|         Matrix4(const Matrix4<T>& m); | ||||
|         Matrix4(const T& m_11, const T& m_12, const T& m_13, const T& m_14, | ||||
|                 const T& m_21, const T& m_22, const T& m_23, const T& m_24, | ||||
|                 const T& m_31, const T& m_32, const T& m_33, const T& m_34, | ||||
|                 const T& m_41, const T& m_42, const T& m_43, const T& m_44); | ||||
|  | ||||
|         const T& Get11() const; | ||||
|         const T& Get12() const; | ||||
|         const T& Get13() const; | ||||
|         const T& Get14() const; | ||||
|         const T& Get21() const; | ||||
|         const T& Get22() const; | ||||
|         const T& Get23() const; | ||||
|         const T& Get24() const; | ||||
|         const T& Get31() const; | ||||
|         const T& Get32() const; | ||||
|         const T& Get33() const; | ||||
|         const T& Get34() const; | ||||
|         const T& Get41() const; | ||||
|         const T& Get42() const; | ||||
|         const T& Get43() const; | ||||
|         const T& Get44() const; | ||||
|  | ||||
|         Matrix4<T>& operator=(const Matrix4<T>& m); | ||||
|  | ||||
|         Matrix4<T> operator+(const Matrix4<T>& m) const; | ||||
|         const Matrix4<T>& operator+=(const Matrix4<T>& m); | ||||
|  | ||||
|         Matrix4<T> operator-(const Matrix4<T>& m) const; | ||||
|         Matrix4<T> operator-() const; | ||||
|         const Matrix4<T>& operator-=(const Matrix4<T>& m); | ||||
|  | ||||
|         Matrix4<T> operator*(const Matrix4<T>& m) const; | ||||
|         Matrix4<T> operator*(const T& v) const; | ||||
|         const Matrix4<T>& operator*=(const Matrix4<T>& m); | ||||
|         const Matrix4<T>& operator*=(const T& v); | ||||
|  | ||||
|         Matrix4<T> operator/(const T& v) const; | ||||
|         const Matrix4<T>& operator/=(const T& v); | ||||
|  | ||||
|         bool operator==(const Matrix4<T>& m) const; | ||||
|         bool operator!=(const Matrix4<T>& m) const; | ||||
|  | ||||
|         void SetZero(); | ||||
|         void SetIdentity(); | ||||
|         void SetPerspectiveProjection(const T& fov, const T& aspect, const T& nearPlane, const T& farPlane); | ||||
|         void SetOrthographicProjection(const T& left, const T& right, const T& bottom, const T& top, const T& nearPlane, const T& farPlane); | ||||
|  | ||||
|         void SetLookAt(const Vector3<T>& eyePosition, const Vector3<T>& lookAtPosition, Vector3<T> upVector = Vector3<T>(T(0), T(1), T(0))); | ||||
|  | ||||
|         bool IsZero() const; | ||||
|         bool IsIdentity() const; | ||||
|  | ||||
|         void ApplyTranslation(const T& x, const T& y, const T& z); | ||||
|         void ApplyRotation(const T& angle, const T& x, const T& y, const T& z); | ||||
|         void ApplyScale(const T& x, const T& y, const T& z); | ||||
|  | ||||
|         Vector3<T> GetTranslation() const; | ||||
|  | ||||
|         const T* GetInternalValues() const; | ||||
|         T* GetInternalValues(); | ||||
|         std::string ToString(const std::string& lineBegin = "|", const std::string& lineEnd = "|\n") const; | ||||
|  | ||||
|     private: | ||||
|         union { | ||||
|             // column-major matrix | ||||
|             struct | ||||
|             { | ||||
|                 T m_11, m_21, m_31, m_41, m_12, m_22, m_32, m_42, m_13, m_23, m_33, m_43, m_14, m_24, m_34, m_44; | ||||
|             }; | ||||
|             T m_values[16]; | ||||
|         }; | ||||
| }; | ||||
|  | ||||
| typedef Matrix4<int> Matrix4i; | ||||
| typedef Matrix4<float> Matrix4f; | ||||
| typedef Matrix4<double> Matrix4d; | ||||
|  | ||||
| template <class T> | ||||
| const Matrix4<T> Matrix4<T>::ZERO = Matrix4<T>(0); | ||||
|  | ||||
| template <class T> | ||||
| const Matrix4<T> Matrix4<T>::IDENTITY = Matrix4<T>( | ||||
|         1, 0, 0, 0, | ||||
|         0, 1, 0, 0, | ||||
|         0, 0, 1, 0, | ||||
|         0, 0, 0, 1); | ||||
|  | ||||
|     template <class T> | ||||
| std::ostream& operator<<(std::ostream& out, const Matrix4<T>& m) | ||||
| { | ||||
|     out << m.ToString(); | ||||
|     return out; | ||||
| } | ||||
|  | ||||
|     template <class T> | ||||
| Matrix4<T>::Matrix4() | ||||
| { | ||||
|     // Leave matrix uninitialized | ||||
| } | ||||
|  | ||||
|     template <class T> | ||||
| Matrix4<T>::Matrix4(const T& v) | ||||
| { | ||||
|     for(int i = 0; i < 16; ++i) | ||||
|         m_values[i] = v; | ||||
| } | ||||
|  | ||||
|     template <class T> | ||||
| Matrix4<T>::Matrix4(const Matrix4<T>& m) | ||||
| { | ||||
|     for(int i = 0; i < 16; ++i) | ||||
|         m_values[i] = m.m_values[i]; | ||||
| } | ||||
|  | ||||
|     template <class T> | ||||
| Matrix4<T>::Matrix4(const T& m_11, const T& m_12, const T& m_13, const T& m_14, | ||||
|         const T& m_21, const T& m_22, const T& m_23, const T& m_24, | ||||
|         const T& m_31, const T& m_32, const T& m_33, const T& m_34, | ||||
|         const T& m_41, const T& m_42, const T& m_43, const T& m_44) | ||||
| { | ||||
|     this->m_11 = m_11; | ||||
|     this->m_12 = m_12; | ||||
|     this->m_13 = m_13; | ||||
|     this->m_14 = m_14; | ||||
|     this->m_21 = m_21; | ||||
|     this->m_22 = m_22; | ||||
|     this->m_23 = m_23; | ||||
|     this->m_24 = m_24; | ||||
|     this->m_31 = m_31; | ||||
|     this->m_32 = m_32; | ||||
|     this->m_33 = m_33; | ||||
|     this->m_34 = m_34; | ||||
|     this->m_41 = m_41; | ||||
|     this->m_42 = m_42; | ||||
|     this->m_43 = m_43; | ||||
|     this->m_44 = m_44; | ||||
| } | ||||
|  | ||||
| template <class T> | ||||
| const T& Matrix4<T>::Get11() const | ||||
| { | ||||
|     return m_11; | ||||
| } | ||||
|  | ||||
| template <class T> | ||||
| const T& Matrix4<T>::Get12() const | ||||
| { | ||||
|     return m_12; | ||||
| } | ||||
|  | ||||
| template <class T> | ||||
| const T& Matrix4<T>::Get13() const | ||||
| { | ||||
|     return m_13; | ||||
| } | ||||
|  | ||||
| template <class T> | ||||
| const T& Matrix4<T>::Get14() const | ||||
| { | ||||
|     return m_14; | ||||
| } | ||||
|  | ||||
| template <class T> | ||||
| const T& Matrix4<T>::Get21() const | ||||
| { | ||||
|     return m_21; | ||||
| } | ||||
|  | ||||
| template <class T> | ||||
| const T& Matrix4<T>::Get22() const | ||||
| { | ||||
|     return m_22; | ||||
| } | ||||
|  | ||||
| template <class T> | ||||
| const T& Matrix4<T>::Get23() const | ||||
| { | ||||
|     return m_23; | ||||
| } | ||||
|  | ||||
| template <class T> | ||||
| const T& Matrix4<T>::Get24() const | ||||
| { | ||||
|     return m_24; | ||||
| } | ||||
|  | ||||
| template <class T> | ||||
| const T& Matrix4<T>::Get31() const | ||||
| { | ||||
|     return m_31; | ||||
| } | ||||
|  | ||||
| template <class T> | ||||
| const T& Matrix4<T>::Get32() const | ||||
| { | ||||
|     return m_32; | ||||
| } | ||||
|  | ||||
| template <class T> | ||||
| const T& Matrix4<T>::Get33() const | ||||
| { | ||||
|     return m_33; | ||||
| } | ||||
|  | ||||
| template <class T> | ||||
| const T& Matrix4<T>::Get34() const | ||||
| { | ||||
|     return m_34; | ||||
| } | ||||
|  | ||||
| template <class T> | ||||
| const T& Matrix4<T>::Get41() const | ||||
| { | ||||
|     return m_41; | ||||
| } | ||||
|  | ||||
| template <class T> | ||||
| const T& Matrix4<T>::Get42() const | ||||
| { | ||||
|     return m_42; | ||||
| } | ||||
|  | ||||
| template <class T> | ||||
| const T& Matrix4<T>::Get43() const | ||||
| { | ||||
|     return m_43; | ||||
| } | ||||
|  | ||||
| template <class T> | ||||
| const T& Matrix4<T>::Get44() const | ||||
| { | ||||
|     return m_44; | ||||
| } | ||||
|  | ||||
|     template <class T> | ||||
| Matrix4<T>& Matrix4<T>::operator=(const Matrix4<T>& m) | ||||
| { | ||||
|     if(this != &m) | ||||
|     { | ||||
|         for(int i = 0; i < 16; ++i) | ||||
|             m_values[i] = m.m_values[i]; | ||||
|     } | ||||
|  | ||||
|     return *this; | ||||
| } | ||||
|  | ||||
| template <class T> | ||||
| Matrix4<T> Matrix4<T>::operator+(const Matrix4<T>& m) const | ||||
| { | ||||
|     return Matrix4<T>( | ||||
|             m_11 + m.m_11, m_12 + m.m_12, m_13 + m.m_13, m_14 + m.m_14, | ||||
|             m_21 + m.m_21, m_22 + m.m_22, m_23 + m.m_23, m_24 + m.m_24, | ||||
|             m_31 + m.m_31, m_32 + m.m_32, m_33 + m.m_33, m_34 + m.m_34, | ||||
|             m_41 + m.m_41, m_42 + m.m_42, m_43 + m.m_43, m_44 + m.m_44); | ||||
| } | ||||
|  | ||||
|     template <class T> | ||||
| const Matrix4<T>& Matrix4<T>::operator+=(const Matrix4<T>& m) | ||||
| { | ||||
|     *this = *this + m; | ||||
|     return *this; | ||||
| } | ||||
|  | ||||
| template <class T> | ||||
| Matrix4<T> Matrix4<T>::operator-(const Matrix4<T>& m) const | ||||
| { | ||||
|     return Matrix4<T>( | ||||
|             m_11 - m.m_11, m_12 - m.m_12, m_13 - m.m_13, m_14 - m.m_14, | ||||
|             m_21 - m.m_21, m_22 - m.m_22, m_23 - m.m_23, m_24 - m.m_24, | ||||
|             m_31 - m.m_31, m_32 - m.m_32, m_33 - m.m_33, m_34 - m.m_34, | ||||
|             m_41 - m.m_41, m_42 - m.m_42, m_43 - m.m_43, m_44 - m.m_44); | ||||
| } | ||||
|  | ||||
| template <class T> | ||||
| Matrix4<T> Matrix4<T>::operator-() const | ||||
| { | ||||
|     return Matrix4<T>( | ||||
|             -m_11, -m_12, -m_13, -m_14, | ||||
|             -m_21, -m_22, -m_23, -m_24, | ||||
|             -m_31, -m_32, -m_33, -m_34, | ||||
|             -m_41, -m_42, -m_43, -m_44); | ||||
| } | ||||
|  | ||||
|     template <class T> | ||||
| const Matrix4<T>& Matrix4<T>::operator-=(const Matrix4<T>& m) | ||||
| { | ||||
|     *this = *this - m; | ||||
|     return *this; | ||||
| } | ||||
|  | ||||
| template <class T> | ||||
| Matrix4<T> Matrix4<T>::operator*(const Matrix4<T>& m) const | ||||
| { | ||||
|     return Matrix4<T>( | ||||
|             m_11 * m.m_11 + m_12 * m.m_21 + m_13 * m.m_31 + m_14 * m.m_41, | ||||
|             m_11 * m.m_12 + m_12 * m.m_22 + m_13 * m.m_32 + m_14 * m.m_42, | ||||
|             m_11 * m.m_13 + m_12 * m.m_23 + m_13 * m.m_33 + m_14 * m.m_43, | ||||
|             m_11 * m.m_14 + m_12 * m.m_24 + m_13 * m.m_34 + m_14 * m.m_44, | ||||
|  | ||||
|             m_21 * m.m_11 + m_22 * m.m_21 + m_23 * m.m_31 + m_24 * m.m_41, | ||||
|             m_21 * m.m_12 + m_22 * m.m_22 + m_23 * m.m_32 + m_24 * m.m_42, | ||||
|             m_21 * m.m_13 + m_22 * m.m_23 + m_23 * m.m_33 + m_24 * m.m_43, | ||||
|             m_21 * m.m_14 + m_22 * m.m_24 + m_23 * m.m_34 + m_24 * m.m_44, | ||||
|  | ||||
|             m_31 * m.m_11 + m_32 * m.m_21 + m_33 * m.m_31 + m_34 * m.m_41, | ||||
|             m_31 * m.m_12 + m_32 * m.m_22 + m_33 * m.m_32 + m_34 * m.m_42, | ||||
|             m_31 * m.m_13 + m_32 * m.m_23 + m_33 * m.m_33 + m_34 * m.m_43, | ||||
|             m_31 * m.m_14 + m_32 * m.m_24 + m_33 * m.m_34 + m_34 * m.m_44, | ||||
|  | ||||
|             m_41 * m.m_11 + m_42 * m.m_21 + m_43 * m.m_31 + m_44 * m.m_41, | ||||
|             m_41 * m.m_12 + m_42 * m.m_22 + m_43 * m.m_32 + m_44 * m.m_42, | ||||
|             m_41 * m.m_13 + m_42 * m.m_23 + m_43 * m.m_33 + m_44 * m.m_43, | ||||
|             m_41 * m.m_14 + m_42 * m.m_24 + m_43 * m.m_34 + m_44 * m.m_44); | ||||
| } | ||||
|  | ||||
| template <class T> | ||||
| Matrix4<T> Matrix4<T>::operator*(const T& v) const | ||||
| { | ||||
|     return Matrix4<T>( | ||||
|             m_11 * v, m_12 * v, m_13 * v, m_14 * v, | ||||
|             m_21 * v, m_22 * v, m_23 * v, m_24 * v, | ||||
|             m_31 * v, m_32 * v, m_33 * v, m_34 * v, | ||||
|             m_41 * v, m_42 * v, m_43 * v, m_44 * v); | ||||
| } | ||||
|  | ||||
|     template <class T> | ||||
| const Matrix4<T>& Matrix4<T>::operator*=(const Matrix4<T>& m) | ||||
| { | ||||
|     *this = *this * m; | ||||
|     return *this; | ||||
| } | ||||
|  | ||||
|     template <class T> | ||||
| const Matrix4<T>& Matrix4<T>::operator*=(const T& v) | ||||
| { | ||||
|     *this = *this * v; | ||||
|     return *this; | ||||
| } | ||||
|  | ||||
| template <class T> | ||||
| Matrix4<T> Matrix4<T>::operator/(const T& v) const | ||||
| { | ||||
|     return Matrix4<T>( | ||||
|             m_11 / v, m_12 / v, m_13 / v, m_14 / v, | ||||
|             m_21 / v, m_22 / v, m_23 / v, m_24 / v, | ||||
|             m_31 / v, m_32 / v, m_33 / v, m_34 / v, | ||||
|             m_41 / v, m_42 / v, m_43 / v, m_44 / v); | ||||
| } | ||||
|  | ||||
|     template <class T> | ||||
| const Matrix4<T>& Matrix4<T>::operator/=(const T& v) | ||||
| { | ||||
|     *this = *this / v; | ||||
|     return *this; | ||||
| } | ||||
|  | ||||
| template <class T> | ||||
| bool Matrix4<T>::operator==(const Matrix4<T>& m) const | ||||
| { | ||||
|     for(int i = 0; i < 16; ++i) | ||||
|         if(m_values[i] != m.m_values[i]) | ||||
|             return false; | ||||
|  | ||||
|     return true; | ||||
| } | ||||
|  | ||||
| template <class T> | ||||
| bool Matrix4<T>::operator!=(const Matrix4<T>& m) const | ||||
| { | ||||
|     return !(*this == m); | ||||
| } | ||||
|  | ||||
|     template <class T> | ||||
| void Matrix4<T>::SetZero() | ||||
| { | ||||
|     *this = ZERO; | ||||
| } | ||||
|  | ||||
|     template <class T> | ||||
| void Matrix4<T>::SetIdentity() | ||||
| { | ||||
|     *this = IDENTITY; | ||||
| } | ||||
|  | ||||
|     template <class T> | ||||
| void Matrix4<T>::SetPerspectiveProjection(const T& fov, const T& aspect, const T& nearPlane, const T& farPlane) | ||||
| { | ||||
|     const float h = T(1) / tan(fov * T(M_PI / 360.f)); | ||||
|     T negDepth = nearPlane - farPlane; | ||||
|  | ||||
|     SetZero(); | ||||
|  | ||||
|     m_11 = h / aspect; | ||||
|     m_22 = h; | ||||
|     m_33 = (farPlane + nearPlane) / negDepth; | ||||
|     m_34 = T(2) * (nearPlane * farPlane) / negDepth; | ||||
|     m_43 = -T(1); | ||||
| } | ||||
|  | ||||
|     template <class T> | ||||
| void Matrix4<T>::SetOrthographicProjection(const T& left, const T& right, const T& bottom, const T& top, const T& nearPlane, const T& farPlane) | ||||
| { | ||||
|     m_11 = T(2) / (right - left); | ||||
|     m_12 = T(0); | ||||
|     m_13 = T(0); | ||||
|     m_14 = -(right + left) / (right - left); | ||||
|  | ||||
|     m_21 = T(0); | ||||
|     m_22 = T(2) / (top - bottom); | ||||
|     m_23 = T(0); | ||||
|     m_24 = -(top + bottom) / (top - bottom); | ||||
|  | ||||
|     m_31 = T(0); | ||||
|     m_32 = T(0); | ||||
|     m_33 = -T(2) / (farPlane - nearPlane); | ||||
|     m_34 = -(farPlane + nearPlane) / (farPlane - nearPlane); | ||||
|  | ||||
|     m_41 = T(0); | ||||
|     m_42 = T(0); | ||||
|     m_43 = T(0); | ||||
|     m_44 = T(1); | ||||
| } | ||||
|  | ||||
|     template <class T> | ||||
| void Matrix4<T>::SetLookAt(const Vector3<T>& eyePosition, const Vector3<T>& lookAtPosition, Vector3<T> upVector) | ||||
| { | ||||
|     Vector3f L = lookAtPosition - eyePosition; | ||||
|     L.Normalize(); | ||||
|  | ||||
|     upVector.Normalize(); | ||||
|     Vector3f S = L.Cross(upVector); | ||||
|     S.Normalize(); | ||||
|  | ||||
|     Vector3f U = S.Cross(L); | ||||
|  | ||||
|     Matrix4<T> M; | ||||
|     M.m_11 = S.x; | ||||
|     M.m_12 = S.y; | ||||
|     M.m_13 = S.z; | ||||
|     M.m_14 = 0; | ||||
|  | ||||
|     M.m_21 = U.x; | ||||
|     M.m_22 = U.y; | ||||
|     M.m_23 = U.z; | ||||
|     M.m_24 = 0; | ||||
|  | ||||
|     M.m_31 = -L.x; | ||||
|     M.m_32 = -L.y; | ||||
|     M.m_33 = -L.z; | ||||
|     M.m_34 = 0; | ||||
|  | ||||
|     M.m_41 = 0; | ||||
|     M.m_42 = 0; | ||||
|     M.m_43 = 0; | ||||
|     M.m_44 = 1.f; | ||||
|  | ||||
|     SetIdentity(); | ||||
|     *this *= M; | ||||
|     ApplyTranslation(-eyePosition.x, -eyePosition.y, -eyePosition.z); | ||||
| } | ||||
|  | ||||
|     template <class T> | ||||
| void Matrix4<T>::ApplyTranslation(const T& x, const T& y, const T& z) | ||||
| { | ||||
|     Matrix4<T> tmp( | ||||
|             1, 0, 0, x, | ||||
|             0, 1, 0, y, | ||||
|             0, 0, 1, z, | ||||
|             0, 0, 0, 1); | ||||
|  | ||||
|     *this *= tmp; | ||||
| } | ||||
|  | ||||
|     template <class T> | ||||
| void Matrix4<T>::ApplyRotation(const T& angle, const T& x, const T& y, const T& z) | ||||
| { | ||||
|     // TODO axis (x, y, z) must be normalized... | ||||
|  | ||||
|     T s = sin(DEGTORAD(angle)); | ||||
|     T c = cos(DEGTORAD(angle)); | ||||
|     T ic = T(1) - c; | ||||
|  | ||||
|     Matrix4<T> tmp( | ||||
|             x * x * ic + c, y * x * ic + (z * s), z * x * ic - (y * s), 0, | ||||
|             x * y * ic - (z * s), y * y * ic + c, z * y * ic + (x * s), 0, | ||||
|             x * z * ic + (y * s), y * z * ic - (x * s), z * z * ic + c, 0, | ||||
|             0, 0, 0, 1); | ||||
|  | ||||
|     *this *= tmp; | ||||
| } | ||||
|  | ||||
|     template <class T> | ||||
| void Matrix4<T>::ApplyScale(const T& x, const T& y, const T& z) | ||||
| { | ||||
|     Matrix4<T> tmp( | ||||
|             x, 0, 0, 0, | ||||
|             0, y, 0, 0, | ||||
|             0, 0, z, 0, | ||||
|             0, 0, 0, 1); | ||||
|  | ||||
|     *this *= tmp; | ||||
| } | ||||
|  | ||||
| template <class T> | ||||
| Vector3<T> Matrix4<T>::GetTranslation() const | ||||
| { | ||||
|     // NOTE: Works only if the matrix doesn't contains scale information (only rotation and translation) | ||||
|     // Reference: http://www.gamedev.net/topic/397751-how-to-get-camera-position/ | ||||
|     T x = -(m_11 * m_14 + m_21 * m_24 + m_31 * m_34); | ||||
|     T y = -(m_12 * m_14 + m_22 * m_24 + m_32 * m_34); | ||||
|     T z = -(m_13 * m_14 + m_23 * m_24 + m_33 * m_34); | ||||
|  | ||||
|     return Vector3<T>(x, y, z); | ||||
| } | ||||
|  | ||||
|     template <class T> | ||||
| T* Matrix4<T>::GetInternalValues() | ||||
| { | ||||
|     return m_values; | ||||
| } | ||||
|  | ||||
| template <class T> | ||||
| const T* Matrix4<T>::GetInternalValues() const | ||||
| { | ||||
|     return m_values; | ||||
| } | ||||
|  | ||||
| template <class T> | ||||
| std::string Matrix4<T>::ToString(const std::string& lineBegin, const std::string& lineEnd) const | ||||
| { | ||||
|     std::ostringstream ss; | ||||
|     ss << lineBegin << m_11 << " " << m_12 << " " << m_13 << " " << m_14 << lineEnd; | ||||
|     ss << lineBegin << m_21 << " " << m_22 << " " << m_23 << " " << m_24 << lineEnd; | ||||
|     ss << lineBegin << m_31 << " " << m_32 << " " << m_33 << " " << m_34 << lineEnd; | ||||
|     ss << lineBegin << m_41 << " " << m_42 << " " << m_43 << " " << m_44 << lineEnd; | ||||
|  | ||||
|     return ss.str(); | ||||
| } | ||||
|  | ||||
| #endif // MATRIX4_H__ | ||||
										
											
												File diff suppressed because it is too large
												Load Diff
											
										
									
								
							| @@ -1,51 +0,0 @@ | ||||
| /** | ||||
|   Open Simple Noise for C++ | ||||
|  | ||||
|   Port to C++ from https://gist.github.com/KdotJPG/b1270127455a94ac5d19 | ||||
|   by Rickard Lundberg, 2019. | ||||
| */ | ||||
| #ifndef _OPENSIMPLEX_H__ | ||||
| #define _OPENSIMPLEX_H__ | ||||
|  | ||||
| #include <cstdint> | ||||
| #include <array> | ||||
|  | ||||
| namespace OpenSimplexNoise | ||||
| { | ||||
|   class Noise | ||||
|   { | ||||
|   public: | ||||
|     Noise(); | ||||
|     Noise(int64_t seed); | ||||
|     //2D Open Simplex Noise. | ||||
|     double eval(const double x, const double y) const; | ||||
|     //3D Open Simplex Noise. | ||||
|     double eval(double x, double y, double z) const; | ||||
|     //4D Open Simplex Noise. | ||||
|     double eval(double x, double y, double z, double w) const; | ||||
|   private: | ||||
|     const double m_stretch2d; | ||||
|     const double m_squish2d; | ||||
|     const double m_stretch3d; | ||||
|     const double m_squish3d; | ||||
|     const double m_stretch4d; | ||||
|     const double m_squish4d; | ||||
|  | ||||
|     const double m_norm2d; | ||||
|     const double m_norm3d; | ||||
|     const double m_norm4d; | ||||
|  | ||||
|     const long m_defaultSeed; | ||||
|  | ||||
|     std::array<short, 256> m_perm; | ||||
|     std::array<short, 256> m_permGradIndex3d; | ||||
|     std::array<char, 16> m_gradients2d; | ||||
|     std::array<char, 72> m_gradients3d; | ||||
|     std::array<char, 256> m_gradients4d; | ||||
|     double extrapolate(int xsb, int ysb, double dx, double dy) const; | ||||
|     double extrapolate(int xsb, int ysb, int zsb, double dx, double dy, double dz) const; | ||||
|     double extrapolate(int xsb, int ysb, int zsb, int wsb, double dx, double dy, double dz, double dw) const; | ||||
|   }; | ||||
| } | ||||
|  | ||||
| #endif // _OPENSIMPLEX_H__ | ||||
| @@ -1,5 +1,5 @@ | ||||
| #ifndef _PLAYER_H__ | ||||
| #define _PLAYER_H__ | ||||
| #ifndef CLI_PLAYER_H__ | ||||
| #define CLI_PLAYER_H__ | ||||
| #include "../SQCSim-common/vector3.h" | ||||
| #include "transformation.h" | ||||
| #include "audio.h" | ||||
|   | ||||
| @@ -1,9 +1,10 @@ | ||||
| #ifndef TRANSFORMATION_H__ | ||||
| #define TRANSFORMATION_H__ | ||||
|  | ||||
| #include "matrix4.h" | ||||
| #include "../SQCSim-common/vector3.h" | ||||
| #include <stack> | ||||
| #include "../SQCSim-common/matrix4.h" | ||||
| #include "../SQCSim-common/vector3.h" | ||||
| #include "define.h" | ||||
|  | ||||
| class Transformation | ||||
| { | ||||
|   | ||||
| @@ -1,8 +1,8 @@ | ||||
| #ifndef VERTEXBUFFER_H__ | ||||
| #define VERTEXBUFFER_H__ | ||||
|  | ||||
| #include "define.h" | ||||
| #include <mutex> | ||||
| #include "define.h" | ||||
|  | ||||
| class VertexBuffer | ||||
| { | ||||
|   | ||||
| @@ -5,14 +5,14 @@ | ||||
| #include <vector> | ||||
| #include <future> | ||||
| #include <thread> | ||||
| #include "define.h" | ||||
| #include "chunk.h" | ||||
| #include "array2d.h" | ||||
| #include "../SQCSim-common/vector3.h" | ||||
| #include "../SQCSim-common/array2d.h" | ||||
| #include "bullet.h" | ||||
| #include "define.h" | ||||
| #include "player.h" | ||||
| #include "chunk.h" | ||||
| #include "transformation.h" | ||||
| #include "shader.h" | ||||
| #include "bullet.h" | ||||
| #include "textureatlas.h" | ||||
|  | ||||
| class Chunk; | ||||
|   | ||||
		Reference in New Issue
	
	Block a user