summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAldrik Ramaekers <aldrik@amftech.nl>2023-04-30 16:20:49 +0200
committerAldrik Ramaekers <aldrik@amftech.nl>2023-04-30 16:20:49 +0200
commit784b123af41337c57535b80c15fe13b62dfc1e66 (patch)
tree1446494c60ae372f1a4f66d72a56c33af74f1b59
parent9e70ced6b48d627f236af8ea8366c6ed73748ab1 (diff)
work
-rw-r--r--.vscode/c_cpp_properties.json23
-rw-r--r--.vscode/launch.json16
-rw-r--r--Makefile2
-rw-r--r--build/data/maps/map1.datbin6408 -> 6408 bytes
-rw-r--r--build/zombies.exebin1949153 -> 1947553 bytes
-rw-r--r--data/maps/map1.datbin6408 -> 6408 bytes
-rw-r--r--include/objects.h5
-rw-r--r--project-base.code-workspace73
-rw-r--r--src/bullets.c2
-rw-r--r--src/drops.c2
-rw-r--r--src/game.c30
-rw-r--r--src/objects.c5
-rw-r--r--src/pathfinding.c2
-rw-r--r--src/players.c33
14 files changed, 20 insertions, 173 deletions
diff --git a/.vscode/c_cpp_properties.json b/.vscode/c_cpp_properties.json
deleted file mode 100644
index 0b83e43..0000000
--- a/.vscode/c_cpp_properties.json
+++ /dev/null
@@ -1,23 +0,0 @@
-{
- "configurations": [
- {
- "name": "Win32",
- "includePath": [
- "${workspaceFolder}/**",
- "C:\\mingw\\mingw64\\x86_64-w64-mingw32\\include",
- "C:\\Users\\aldri\\Desktop\\Vault\\Projects\\project-base\\src"
- ],
- "defines": [
- "_DEBUG",
- "UNICODE",
- "_UNICODE"
- ],
- "windowsSdkVersion": "10.0.19041.0",
- "compilerPath": "C:\\mingw\\mingw64\\bin\\gcc.exe",
- "cStandard": "c17",
- "cppStandard": "c++17",
- "intelliSenseMode": "windows-gcc-x64"
- }
- ],
- "version": 4
-} \ No newline at end of file
diff --git a/.vscode/launch.json b/.vscode/launch.json
deleted file mode 100644
index 7c697de..0000000
--- a/.vscode/launch.json
+++ /dev/null
@@ -1,16 +0,0 @@
-{
- // Use IntelliSense to learn about possible attributes.
- // Hover to view descriptions of existing attributes.
- // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
- "version": "0.2.0",
- "configurations": [
- {
- "type": "by-gdb",
- "request": "launch",
- "name": "Launch(gdb)",
- "program": "build/zombies.exe ",
- "programArgs": "-ip 127.0.0.1 -port 27015",
- "cwd": "${workspaceRoot}"
- }
- ]
-} \ No newline at end of file
diff --git a/Makefile b/Makefile
index e7bede5..8af8a4e 100644
--- a/Makefile
+++ b/Makefile
@@ -2,6 +2,6 @@ main:
rm -rf "build/"
mkdir -p "build/"
cp -a "data/." "build/data"
- gcc -m64 -g -DMODE_DEBUG main.c -o build/zombies.exe -lprojectbase-debug
+ gcc -m64 -g -DMODE_DEBUG main.c -o build/zombies.exe
./build/zombies.exe -ip 127.0.0.1 -port 27015
diff --git a/build/data/maps/map1.dat b/build/data/maps/map1.dat
index 959171c..956b184 100644
--- a/build/data/maps/map1.dat
+++ b/build/data/maps/map1.dat
Binary files differ
diff --git a/build/zombies.exe b/build/zombies.exe
index cd30d67..79c0304 100644
--- a/build/zombies.exe
+++ b/build/zombies.exe
Binary files differ
diff --git a/data/maps/map1.dat b/data/maps/map1.dat
index 959171c..956b184 100644
--- a/data/maps/map1.dat
+++ b/data/maps/map1.dat
Binary files differ
diff --git a/include/objects.h b/include/objects.h
index 50cd6f9..d586838 100644
--- a/include/objects.h
+++ b/include/objects.h
@@ -5,6 +5,8 @@
#include "map.h"
+#define MAX_OBJECTS 1000
+
typedef struct t_vec3f {
float x,y,z;
} vec3f;
@@ -29,8 +31,7 @@ typedef struct t_box {
vec2f br_u;
} box;
-int max_objects = 150;
-object objects[150];
+object objects[MAX_OBJECTS];
object get_object_at_tile(float x, float y);
void create_objects();
diff --git a/project-base.code-workspace b/project-base.code-workspace
deleted file mode 100644
index de91c68..0000000
--- a/project-base.code-workspace
+++ /dev/null
@@ -1,73 +0,0 @@
-{
- "folders": [
- {
- "path": "../project-base"
- },
- {
- "path": "."
- }
- ],
- "settings": {
- "files.associations": {
- "*.ejs": "html",
- "render_cpu.c": "cpp",
- "render.c": "cpp",
- "interface.c": "cpp",
- "iosfwd": "c",
- "sdl.h": "c",
- "*.rc": "c",
- "cjson.c": "cpp",
- "cmath": "c",
- "mono.c": "cpp",
- "xutility": "c",
- "initializer_list": "c",
- "type_traits": "c",
- "*.rh": "c",
- "algorithm": "c",
- "limits": "c",
- "popup_window.h": "c",
- "wingdi.h": "c",
- "info_png.h": "c",
- "project_base.h": "c",
- "cstdlib": "c",
- "array": "cpp",
- "deque": "cpp",
- "fstream": "cpp",
- "iterator": "cpp",
- "list": "cpp",
- "memory": "cpp",
- "sstream": "cpp",
- "system_error": "cpp",
- "utility": "cpp",
- "vector": "cpp",
- "xhash": "cpp",
- "xlocale": "cpp",
- "xlocnum": "cpp",
- "xmemory": "cpp",
- "xstring": "cpp",
- "atomic": "cpp",
- "*.tcc": "cpp",
- "string": "cpp",
- "string_view": "cpp",
- "objects.h": "c",
- "map.h": "c",
- "zombies.h": "c",
- "math.h": "c",
- "math_helper.h": "c",
- "xiosbase": "c",
- "pathfinding.h": "c",
- "unordered_map": "c",
- "players.h": "c",
- "allocator.h": "c",
- "protocol.h": "c",
- "queue": "cpp",
- "streambuf": "c",
- "game.h": "c",
- "bullets.h": "c",
- "guns.h": "c",
- "iphlpapi.h": "c",
- "asset_defs.h": "c",
- "sprite.h": "c"
- }
- }
-} \ No newline at end of file
diff --git a/src/bullets.c b/src/bullets.c
index fb56a12..ff96db9 100644
--- a/src/bullets.c
+++ b/src/bullets.c
@@ -75,7 +75,7 @@ bool check_if_bullet_collided_with_object(bullet* b, platform_window* window) {
bool result = false;
float dist_of_closest_intersect = __FLT_MAX__;
- for (int i = 0; i < max_objects; i++) {
+ for (int i = 0; i < MAX_OBJECTS; i++) {
object o = objects[i];
if (!o.active) continue;
if (b->position.z <= o.h + o.size.z && b->position.z >= o.h) {
diff --git a/src/drops.c b/src/drops.c
index 9c04509..9c4b48c 100644
--- a/src/drops.c
+++ b/src/drops.c
@@ -63,7 +63,7 @@ void draw_drops(platform_window* window) {
//render_box_with_outline(full_box, rgba(218,112,214, alpha));
renderer->render_image_tint(img_drop, full_box.tl_u.x, full_box.tl_u.y,
full_box.br_d.x - full_box.tl_d.x, full_box.br_d.y - full_box.tr_u.y, rgba(218,112,214, alpha));
-
+
int drop_h = full_box.br_d.y - full_box.tr_d.y;
int icon_size = full_box.tr_d.x - full_box.tl_d.x;
diff --git a/src/game.c b/src/game.c
index 268513d..332c069 100644
--- a/src/game.c
+++ b/src/game.c
@@ -22,7 +22,6 @@ void start_server(char* port) {
static u32 get_session_id() {
u64 time = platform_get_time(TIME_FULL, TIME_NS);
return (((time * 2654435789U) + time) * 2654435789U) + platform_get_processid();
-
}
void connect_to_server(char* ip, char* port) {
@@ -39,7 +38,6 @@ void connect_to_server(char* ip, char* port) {
log_infox("Session id: %u", player_id);
if (global_state.server) {
- player_id = player_id;
spawn_player(player_id, (network_client){0, false, 0, "Host"});
global_state.network_state = CONNECTED;
}
@@ -59,7 +57,7 @@ void load_map() {
outgoing_allocator = create_allocator(MAX_NETWORK_BUFFER_SIZE);
messages_to_send_queue_mutex = mutex_create();
- for (int i = 0; i < 3; i++) {
+ for (int i = 0; i < 1; i++) {
thread send_thread = thread_start(network_send_thread, 0);
thread_detach(&send_thread);
}
@@ -119,10 +117,8 @@ static void set_ping_for_player(protocol_generic_message* msg) {
for (int i = 0; i < MAX_PLAYERS; i++) {
player p = players[i];
- if (!p.client.is_connected) continue;
- if (!p.active) continue;
if (p.client.ConnectSocket == msg->client.ConnectSocket) {
- players[i].ping = diff;
+ players[i].ping = diff;
return;
}
}
@@ -215,22 +211,6 @@ void update_server(platform_window* window) {
}
}
-static void apply_user_list(protocol_user_list* msg_players) {
- player* p = get_player_by_id(player_id);
- player copy;
- if (p) copy = *p;
- memcpy(players, msg_players->players, sizeof(players));
-
- // These properties are simulated locally so dont overwrite.
- if (p) {
- p->playerx = copy.playerx;
- p->playery = copy.playery;
- p->gunx = copy.gunx;
- p->guny = copy.guny;
- p->gun_height = copy.gun_height;
- }
-}
-
static void load_bullets_into_existing_list(protocol_bullets_list* msg_bullets) {
for (int i = 0; i < max_bullets; i++) {
if (bullets[i].active) continue;
@@ -260,25 +240,21 @@ void update_client(platform_window* window) {
} break;
case MESSAGE_USER_LIST: {
- if (global_state.server) break; // players are simulated on server so dont overwrite data.
protocol_user_list* msg_players = (protocol_user_list*)msg;
- apply_user_list(msg_players);
+ memcpy(players, msg_players->players, sizeof(players));
} break;
case MESSAGE_ZOMBIE_LIST: {
- if (global_state.server) break; // zombies are simulated on server so dont overwrite data.
protocol_zombie_list* msg_zombies = (protocol_zombie_list*)msg;
memcpy(zombies, msg_zombies->zombies, sizeof(zombies));
} break;
case MESSAGE_BULLET_LIST: {
- if (global_state.server) break; // bullets are simulated on server so dont overwrite data.
protocol_bullets_list* msg_bullets = (protocol_bullets_list*)msg;
load_bullets_into_existing_list(msg_bullets);
} break;
case MESSAGE_DROP_LIST: {
- if (global_state.server) break; // drops are simulated on server so dont overwrite data.
protocol_drop_list* msg_drops = (protocol_drop_list*)msg;
memcpy(drops, msg_drops->drops, sizeof(drops));
} break;
diff --git a/src/objects.c b/src/objects.c
index fdb0daa..c8a150c 100644
--- a/src/objects.c
+++ b/src/objects.c
@@ -30,7 +30,7 @@ void render_quad_with_outline(vec2f tl, vec2f tr, vec2f bl, vec2f br, color c) {
}
object get_object_at_tile(float x, float y) {
- for (int i = 0; i < max_objects; i++) {
+ for (int i = 0; i < MAX_OBJECTS; i++) {
object o = objects[i];
if (!o.active) continue;
if (x >= o.position.x && x < o.position.x + o.size.x && y >= o.position.y && y < o.position.y + o.size.y) return o;
@@ -59,7 +59,7 @@ void draw_objects_at_row(platform_window* window, int row) {
}
void create_box(float x, float y, float h, image* img) {
- for (int i = 0; i < max_objects; i++) {
+ for (int i = 0; i < MAX_OBJECTS; i++) {
object o = objects[i];
if (o.active) continue;
@@ -75,6 +75,7 @@ void create_box(float x, float y, float h, image* img) {
void create_objects() {
// rechts naar links op map.
+
for (int i = MAP_SIZE_X-1; i >= 0; i--) {
create_box(i, 0, 0, img_obj_wall1);
create_box(i, MAP_SIZE_Y-1, 0, img_obj_wall1);
diff --git a/src/pathfinding.c b/src/pathfinding.c
index f3fa354..63741e7 100644
--- a/src/pathfinding.c
+++ b/src/pathfinding.c
@@ -7,7 +7,7 @@ static float distance_between(vec2f v1, vec2f v2)
bool can_walk_at(float x, float y)
{
- for (int i = 0; i < max_objects; i++) {
+ for (int i = 0; i < MAX_OBJECTS; i++) {
object o = objects[i];
if (!o.active) continue;
if (x >= o.position.x && x < o.position.x + o.size.x && y >= o.position.y && y < o.position.y + o.size.y) return false;
diff --git a/src/players.c b/src/players.c
index 8009b79..f3c7c6e 100644
--- a/src/players.c
+++ b/src/players.c
@@ -120,7 +120,7 @@ object check_if_player_collided_with_object(platform_window* window, player p) {
map_info info = get_map_info(window);
float player_size = get_player_size(window);
- for (int i = 0; i < max_objects; i++) {
+ for (int i = 0; i < MAX_OBJECTS; i++) {
object o = objects[i];
if (!o.active) continue;
@@ -182,36 +182,20 @@ void take_player_input(platform_window* window) {
#endif
if (keyboard_is_key_down(KEY_W)) {
- //if (!global_state.server)
- {
- network_message message = create_protocol_user_moved(MOVE_UP, player_id);
+ network_message message = create_protocol_user_moved(MOVE_UP, player_id);
add_message_to_outgoing_queuex(message, *global_state.client);
- }
- //move_user(window, player_id, MOVE_UP, update_delta);
}
if (keyboard_is_key_down(KEY_S)) {
- //if (!global_state.server)
- {
- network_message message = create_protocol_user_moved(MOVE_DOWN, player_id);
+ network_message message = create_protocol_user_moved(MOVE_DOWN, player_id);
add_message_to_outgoing_queuex(message, *global_state.client);
- }
- //move_user(window, player_id, MOVE_DOWN, update_delta);
}
if (keyboard_is_key_down(KEY_A)) {
- //if (!global_state.server)
- {
- network_message message = create_protocol_user_moved(MOVE_LEFT, player_id);
- add_message_to_outgoing_queuex(message, *global_state.client);
- }
- //move_user(window, player_id, MOVE_LEFT, update_delta);
+ network_message message = create_protocol_user_moved(MOVE_LEFT, player_id);
+ add_message_to_outgoing_queuex(message, *global_state.client);
}
if (keyboard_is_key_down(KEY_D)) {
- //if (!global_state.server)
- {
- network_message message = create_protocol_user_moved(MOVE_RIGHT, player_id);
- add_message_to_outgoing_queuex(message, *global_state.client);
- }
- //move_user(window, player_id, MOVE_RIGHT, update_delta);
+ network_message message = create_protocol_user_moved(MOVE_RIGHT, player_id);
+ add_message_to_outgoing_queuex(message, *global_state.client);
}
// Send gun position
@@ -225,9 +209,6 @@ void take_player_input(platform_window* window) {
float gun_offset_x = (get_player_size_in_tile()/2) + dirx;
float gun_offset_y = (get_player_size_in_tile()/2) + diry;
- //p->gunx = p->playerx + gun_offset_x;
- //p->guny = p->playery + gun_offset_y;
-
add_message_to_outgoing_queuex(create_protocol_user_look(player_id, gun_offset_x, gun_offset_y), *global_state.client);
}