started netcode playing with basic functionality

This commit is contained in:
2026-01-29 22:51:37 -06:00
parent 3aaf5021cc
commit d29e772272
9 changed files with 288 additions and 4 deletions

48
net/net.h Normal file
View File

@@ -0,0 +1,48 @@
//Troy Rosin
#ifndef __my_net_h__
#define __my_net_h__
#define PORT 36911
#define SERVER "localhost"
#define PACKSZ 1024
enum pack_type{
G_STATE, HOSTS_REQ, NEW_HOST, JOIN_REQ
};
typedef struct packet{
enum pack_type type;
char payload[PACKSZ - sizeof(enum pack_type)];
} packet;
int read_to_buff(char *buff, char *src, Uint32 sz)
{
if(sz%32){
puts("error size must be div by 32");
return 0;
}
for(Uint32 i = 0; i < sz ; i += 4)
{
*((Uint32*)(buff + i)) = SDLNet_Read32((Uint32 *)(src + i));
}
return 1;
}
int write_to_buff(char *buff, char *src, Uint32 sz)
{
if(sz%32){
puts("error size must be div by 32");
return 0;
}
for(Uint32 i = 0; i < sz; i += 4)
{
SDLNet_Write32(*((Uint32*)(src + i)), (Uint32*)(buff + i));
}
return 1;
}
#endif