working on making game lobbies and joining them

This commit is contained in:
2026-01-31 18:42:43 -06:00
parent 89c9a7681b
commit 47987ca439
14 changed files with 227 additions and 280 deletions

View File

@@ -5,6 +5,7 @@
#include <SDL2/SDL.h>
extern SDL_Point mouse_pos;
#define TITLE 0
#define START 1

View File

@@ -7,6 +7,8 @@
#define START_GAME_BUTTON 2
extern int over_object;
extern int lobby_has_name;
char *get_this_name(int i);

View File

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