Compare commits
12 Commits
Author | SHA1 | Date |
---|---|---|
Aadhavan Srinivasan | 5fe24bffd9 | 6 months ago |
Aadhavan Srinivasan | 6e0b7f8394 | 6 months ago |
Aadhavan Srinivasan | 4b7880349d | 6 months ago |
Aadhavan Srinivasan | 14131d8942 | 6 months ago |
Aadhavan Srinivasan | 6331d81ba3 | 6 months ago |
Aadhavan Srinivasan | fa0cadfabf | 6 months ago |
Aadhavan Srinivasan | b113098c7b | 6 months ago |
Aadhavan Srinivasan | ab7b40f778 | 7 months ago |
Aadhavan Srinivasan | 50ed0b89e9 | 7 months ago |
Aadhavan Srinivasan | 1ab22651ae | 7 months ago |
Aadhavan Srinivasan | b6439bf7d5 | 7 months ago |
Aadhavan Srinivasan | 1641cef13b | 7 months ago |
@ -1,3 +1,6 @@
|
||||
[submodule "subprojects/raylib"]
|
||||
path = subprojects/raylib
|
||||
url = https://github.com/raysan5/raylib.git
|
||||
[submodule "subprojects/netpong-serialization"]
|
||||
path = netpong-serialization
|
||||
url = https://gitea.twomorecents.org/Rockingcool/netpong-serialization.git
|
||||
|
@ -1,33 +0,0 @@
|
||||
#ifndef _SERIALIZATION_H
|
||||
#define _SERIALIZATION_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stdbool.h>
|
||||
|
||||
/* Struct used to hold the data that will be sent between sockets */
|
||||
typedef struct {
|
||||
uint16_t pad_x; // X-coordinate of sending paddle
|
||||
uint16_t pad_y; // Y-coordinate of sending paddle
|
||||
uint16_t ball_x; // X-coordinate of ball (only the server fills this in)
|
||||
uint16_t ball_y; // Y-coordinate of ball (only the server fills this in)
|
||||
bool should_quit; // Flag to indicate whether game should be quit or not
|
||||
} Serial_Data;
|
||||
|
||||
/* Create a Serial_Data struct from float values */
|
||||
Serial_Data Serial_create_data(float pad_x, float pad_y, float ball_x, float ball_y, bool should_quit);
|
||||
|
||||
/* Serialize a struct into a byte array, that can be sent through a socket */
|
||||
uint8_t* Serial_serialize(Serial_Data data);
|
||||
|
||||
/* Deserialize a byte array into a struct, and return the struct */
|
||||
Serial_Data Serial_deserialize(uint8_t* serialized);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
@ -0,0 +1 @@
|
||||
Subproject commit c0c7e14aa64ebffc334ad4f08e49bad2591050a4
|
@ -1,87 +0,0 @@
|
||||
#include <stdint.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdbool.h>
|
||||
#include <string.h>
|
||||
#if defined(__unix__) || defined(__unix) || (defined(__APPLE__) && defined(__MACH__))
|
||||
#include <arpa/inet.h>
|
||||
#endif
|
||||
#ifdef _WIN32
|
||||
#include <winsock2.h>
|
||||
#endif
|
||||
#include "includes/serialization.h"
|
||||
|
||||
|
||||
/* Takes in float values, casts them to uint16_t and creates a Serial_Data struct */
|
||||
Serial_Data Serial_create_data(float pad_x, float pad_y, float ball_x, float ball_y, bool should_quit) {
|
||||
Serial_Data data;
|
||||
data.pad_x = (uint16_t)pad_x;
|
||||
data.pad_y = (uint16_t)pad_y;
|
||||
data.ball_x = (uint16_t)ball_x;
|
||||
data.ball_y = (uint16_t)ball_y;
|
||||
data.should_quit = should_quit;
|
||||
return data;
|
||||
}
|
||||
|
||||
/* Serializes a 'Data' struct into a byte array, converted to network-byte order */
|
||||
uint8_t* Serial_serialize(Serial_Data data) {
|
||||
/* Create a pointer that can fit the entire struct */
|
||||
uint8_t* serialized = malloc(sizeof(Serial_Data) + 1);
|
||||
uint8_t* pad_x_ptr;
|
||||
uint8_t* pad_y_ptr;
|
||||
uint8_t* ball_x_ptr;
|
||||
uint8_t* ball_y_ptr;
|
||||
uint8_t* should_quit_ptr;
|
||||
|
||||
memset(serialized, 0, sizeof(Serial_Data) + 1); // Zero out the memory
|
||||
pad_x_ptr = serialized;
|
||||
pad_y_ptr = pad_x_ptr + sizeof(uint16_t);
|
||||
ball_x_ptr = pad_y_ptr + sizeof(uint16_t);
|
||||
ball_y_ptr = ball_x_ptr + sizeof(uint16_t);
|
||||
should_quit_ptr = ball_y_ptr + sizeof(uint16_t);
|
||||
|
||||
*((uint16_t *)pad_x_ptr) = data.pad_x;
|
||||
*((uint16_t *)pad_x_ptr) = htons(*((uint16_t *)pad_x_ptr));
|
||||
|
||||
*((uint16_t *)pad_y_ptr) = data.pad_y;
|
||||
*((uint16_t *)pad_y_ptr) = htons(*((uint16_t *)pad_y_ptr));
|
||||
|
||||
*((uint16_t *)ball_x_ptr) = data.ball_x;
|
||||
*((uint16_t *)ball_x_ptr) = htons(*((uint16_t *)ball_x_ptr));
|
||||
|
||||
*((uint16_t *)ball_y_ptr) = data.ball_y;
|
||||
*((uint16_t *)ball_y_ptr) = htons(*((uint16_t *)ball_y_ptr));
|
||||
|
||||
*((bool *)should_quit_ptr) = data.should_quit;
|
||||
*(should_quit_ptr + sizeof(bool)) = '\0';
|
||||
|
||||
return serialized;
|
||||
}
|
||||
|
||||
/* Deserialize a byte array into a 'Data' struct, converted to host byte order */
|
||||
Serial_Data Serial_deserialize(uint8_t* serialized) {
|
||||
Serial_Data deserialized;
|
||||
/* Use successive chunks of memory address to create pointers to the data */
|
||||
uint8_t* pad_x_ptr = serialized;
|
||||
uint8_t* pad_y_ptr = serialized + sizeof(uint16_t);
|
||||
uint8_t* ball_x_ptr = pad_y_ptr + sizeof(uint16_t);
|
||||
uint8_t* ball_y_ptr = ball_x_ptr + sizeof(uint16_t);
|
||||
uint8_t* should_quit_ptr = ball_y_ptr + sizeof(uint16_t);
|
||||
|
||||
/* Dereference (and cast) the pointers, and store them into the struct */
|
||||
deserialized.pad_x = *((uint16_t *)pad_x_ptr);
|
||||
deserialized.pad_x = ntohs(deserialized.pad_x);
|
||||
|
||||
deserialized.pad_y = *((uint16_t *)pad_y_ptr);
|
||||
deserialized.pad_y = ntohs(deserialized.pad_y);
|
||||
|
||||
deserialized.ball_x = *((uint16_t *)ball_x_ptr);
|
||||
deserialized.ball_x = ntohs(deserialized.ball_x);
|
||||
|
||||
deserialized.ball_y = *((uint16_t *)ball_y_ptr);
|
||||
deserialized.ball_y = ntohs(deserialized.ball_y);
|
||||
|
||||
deserialized.should_quit = *((bool *)should_quit_ptr);
|
||||
|
||||
return deserialized;
|
||||
}
|
||||
|
@ -1,10 +1,10 @@
|
||||
1. Sign Windows executable, to remove 'Unknown Publisher' warnings.
|
||||
2. Add 'install' target to Meson, to allow the user to install the game. This should also copy the .so files to the right locations.
|
||||
3. Use free() to free allocated memory.
|
||||
4. Use the struct to establish a connection, and to start each round (instead of sending strings).
|
||||
5. Figure out how to build statically-linked Mac binary, and create a build script for packaging it.
|
||||
6. Communicate the paddle reset position to the peer, after a round.
|
||||
7. Clean up / refactor the raygui code in main.cpp, that asks user for game mode. Instead of just having a giant blob of code in main.cpp, maybe split it into a function, or move it to another file. It should be easy to split it into a different function, since none of the functions take any specific parameters. The text box function, for example, only takes in the rectangle coordinates, and the text to display. I can move the code to a function, and then pass in any parameters that I need to pass in (I don't think I need to pass many parameters, though).
|
||||
8. Allow the user to specify which paddle they want to control, in multi-player mode.
|
||||
9. Try to make the ball go between screens.
|
||||
10. Change the networking code, so that a single server can connect two clients with each other. The server should provide player 1 with a code, and player 2 can connect with player 1 using that code (essentially like a room).
|
||||
1. Add 'install' target to Meson, to allow the user to install the game. This should also copy the .so files to the right locations.
|
||||
2. Use the struct to establish a connection, and to start each round (instead of sending strings).
|
||||
3. Figure out how to build statically-linked Mac binary, and create a build script for packaging it.
|
||||
4. Communicate the paddle reset position to the peer, after a round.
|
||||
5. Clean up / refactor the raygui code in main.cpp, that asks user for game mode. Instead of just having a giant blob of code in main.cpp, maybe split it into a function, or move it to another file. It should be easy to split it into a different function, since none of the functions take any specific parameters. The text box function, for example, only takes in the rectangle coordinates, and the text to display. I can move the code to a function, and then pass in any parameters that I need to pass in (I don't think I need to pass many parameters, though).
|
||||
6. Allow the user to specify which paddle they want to control, in multi-player mode.
|
||||
7. Try to make the ball go between screens.
|
||||
8. Change the networking code, so that a single server can connect two clients with each other. The server should provide player 1 with a code, and player 2 can connect with player 1 using that code (essentially like a room).
|
||||
9. Create (or find) an icon for the application.
|
||||
10. [This can't really be fixed, since I'd need to purchase a developer certificate] Sign Windows executable, to remove 'Unknown Publisher' warnings.
|
||||
|
Loading…
Reference in New Issue