started netcode playing with basic functionality
This commit is contained in:
48
net/net.h
Normal file
48
net/net.h
Normal 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
|
||||
Reference in New Issue
Block a user