Début protocole

This commit is contained in:
MarcEricMartel
2023-09-25 08:23:52 -04:00
parent 6b2f7face7
commit 20d15a1559
18 changed files with 308 additions and 104 deletions

View File

@@ -137,6 +137,7 @@
<ClInclude Include="matrix4.h" />
<ClInclude Include="opensimplex.h" />
<ClInclude Include="player.h" />
<ClInclude Include="netprotocol.h" />
<ClInclude Include="vector3.h" />
<ClInclude Include="world.h" />
</ItemGroup>

View File

@@ -48,6 +48,9 @@
<ClInclude Include="vector3.h">
<Filter>Fichiers d%27en-tête</Filter>
</ClInclude>
<ClInclude Include="netprotocol.h">
<Filter>Fichiers d%27en-tête</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<ClCompile Include="world.cpp">

View File

@@ -2,51 +2,53 @@
#define DEFINE_H__
#include <iostream>
#define CHUNK_SIZE_X 16
#define CHUNK_SIZE_Y 128
#define CHUNK_SIZE_Z 16
#define MAX_SELECTION_DISTANCE 5
#define SEED 12345
#include <chrono>
#define SRV_PORT 1025
#define CLI_PORT 1026
#ifdef _DEBUG
#define CHUNK_SIZE_X 4
#define CHUNK_SIZE_Y 64
#define CHUNK_SIZE_Z 4
#define MAX_SELECTION_DISTANCE 5
#define SEED 12345
#define WORLD_SIZE_X 64
#define WORLD_SIZE_Y 64
#define FRAMES_RENDER_CHUNKS 4
#define FRAMES_UPDATE_CHUNKS 4
#define FRAMES_DELETE_CHUNKS 4
#define THREADS_GENERATE_CHUNKS 1
#define THREADS_UPDATE_CHUNKS 1
#define THREADS_DELETE_CHUNKS 1
#define VIEW_DISTANCE 256
#define TEXTURE_SIZE 128
#define MAX_BULLETS 64
#endif
#ifdef NDEBUG
#define WORLD_SIZE_X 16
#define WORLD_SIZE_Y 16
#define FRAMES_RENDER_CHUNKS 1
#define FRAMES_UPDATE_CHUNKS 1
#define FRAMES_DELETE_CHUNKS 1
#define THREADS_GENERATE_CHUNKS 12
#define THREADS_UPDATE_CHUNKS 5
#define THREADS_DELETE_CHUNKS 2
#define VIEW_DISTANCE 1024
#define VIEW_DISTANCE 512
#define TEXTURE_SIZE 512
#define MAX_BULLETS 512
#endif
typedef uint8_t BlockType;
enum BLOCK_TYPE { BTYPE_AIR, BTYPE_DIRT, BTYPE_GRASS, BTYPE_METAL, BTYPE_ICE, BTYPE_LAST };
typedef std::chrono::system_clock::time_point Timestamp;
#ifdef _WIN32
#pragma comment(lib,"wsock32.lib") // Pour pouvoir faire fonctionner le linker sans le vcxproject
#include <Windows.h>
#include <cstdio>
#include <ctime>
#define popen _popen
#define pclose _pclose
#else // Pas _WIN32
#include <unistd.h>
#include <time.h>
#include <stdio.h>
#include <sys/socket.h>
#include <arpa/inet.h>
#include <netinet/in.h>
#define SOCKET int
#define INVALID_SOCKET -1
#define closesocket close
#endif // _WIN32
#endif // DEFINE_H__

View File

@@ -0,0 +1,89 @@
#ifndef NETPROTOCOL_H__
#define NETPROTOCOL_H__
#include "define.h"
#include "vector3.h"
/* Protocole Particulier de Partie <20> Plusieurs Personnes (PPPPP) */
namespace netprot {
typedef uint8_t PacketType;
enum PACKET_TYPE {
ERR, INPUT, OUTPUT, SYNC,
TEAMINF, SELFINF, PLAYINF,
CHUNKMOD, PLAYERMOD, PICKUPMOD,
GAMEINFO, ENDINFO , CHAT
};
typedef struct { // cli -> srv UDP ~frame
Timestamp timestamp;
uint8_t keys; // 0bFBLRJS__
Vector3f direction;
} Input;
typedef struct { // srv -> cli UDP ~frame
Timestamp timestamp;
uint64_t id = 0;
Vector3f position,
direction;
bool is_shooting,
is_jumping;
} Output;
typedef struct { // srv -> cli TCP ~second
Timestamp timestamp;
uint64_t sid = 0,
timer = 0;
uint8_t hp = 0;
uint16_t ammo = 0;
Vector3f position;
} Sync;
typedef struct { // cli <-> srv TCP once
char name[32];
uint64_t id = 0;
} TeamInfo;
typedef struct { // cli <-> srv TCP once
char name[32];
uint64_t sid = 0,
tid = 0;
} SelfInfo;
typedef struct { // cli <-> srv TCP once
char name[32];
uint64_t id = 0,
tid = 0;
} PlayerInfo;
typedef struct {
uint64_t seed;
// uint8_t gameType;
// uint8_t time;
} GameInfo;
typedef struct { // cli <-> srv TCP event
uint64_t src_id = 0,
dest_id = 0,
dest_team_id = 0;
char mess[140]; // Good 'nough for twitr, good 'nough for me.
} Chat;
inline void Serialize(Input* in, char* buf, uint32_t* buflen); // cli
inline void Serialize(Output* out, char* buf, uint32_t* buflen); // srv
inline void Serialize(Sync* sync, char* buf, uint32_t* buflen); // srv
inline void Serialize(TeamInfo* tinfo, char* buf, uint32_t* buflen); // cli/srv
inline void Serialize(SelfInfo* sinfo, char* buf, uint32_t* buflen); // cli/srv
inline void Serialize(PlayerInfo* pinfo, char* buf, uint32_t* buflen); // srv
inline void Serialize(Chat* chat, char* buf, uint32_t* buflen); // cli/srv
inline void Deserialize(Input* in, char* buf, uint32_t* buflen); // srv
inline void Deserialize(Output* out, char* buf, uint32_t* buflen); // cli
inline void Deserialize(Sync* sync, char* buf, uint32_t* buflen); // cli
inline void Deserialize(TeamInfo* tinfo, char* buf, uint32_t* buflen); // cli/srv
inline void Deserialize(SelfInfo* sinfo, char* buf, uint32_t* buflen); // cli/srv
inline void Deserialize(PlayerInfo* spinfoync, char* buf, uint32_t* buflen); // cli
inline void Deserialize(Chat* chat, char* buf, uint32_t* buflen); // srv/cli
inline PacketType getType(char* buf, uint32_t* buflen); // srv/cli
}
#endif