From 7e4dc00d71d955d20364630d7f171701e14eff39 Mon Sep 17 00:00:00 2001 From: Rodrigo Verdiani Date: Sat, 27 Dec 2025 19:58:55 -0300 Subject: [PATCH] feat(network): add and initialize SDL_net lib --- CMakeLists.txt | 7 +++++-- app.c | 6 ++++++ network.c | 21 +++++++++++++++++++++ network.h | 13 +++++++++++++ 4 files changed, 45 insertions(+), 2 deletions(-) create mode 100644 network.c create mode 100644 network.h diff --git a/CMakeLists.txt b/CMakeLists.txt index 6734179..29d5981 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -5,6 +5,7 @@ set(CMAKE_C_STANDARD 11) set(CMAKE_CXX_STANDARD 17) find_package(SDL3 CONFIG REQUIRED) +find_package(SDL3_net REQUIRED) set(IMGUI_DIR "thirdparty/imgui") set(BINDINGS_DIR "thirdparty/dear_bindings") @@ -42,7 +43,9 @@ add_executable(tibia bitmap.c bitmap.h objects.c - objects.h) + objects.h + network.c + network.h) target_include_directories(tibia PRIVATE ${IMGUI_DIR} @@ -50,4 +53,4 @@ target_include_directories(tibia PRIVATE ${BINDINGS_DIR} ) -target_link_libraries(tibia SDL3::SDL3) +target_link_libraries(tibia SDL3::SDL3 SDL3_net::SDL3_net) diff --git a/app.c b/app.c index 3dddee1..64096cd 100644 --- a/app.c +++ b/app.c @@ -3,6 +3,7 @@ #include "render.h" #include "input.h" #include "gui.h" +#include "network.h" void App_Init(App_t *app) { app->isRunning = false; @@ -33,6 +34,10 @@ void App_Init(App_t *app) { return; } + if (!Network_Init()) { + return; + } + app->isRunning = true; } @@ -44,6 +49,7 @@ void App_Run(App_t *app) { } void App_Shutdown(const App_t* app) { + Network_Shutdown(); Objects_Destroy(&app->graphics); Map_Destroy(&app->map); Bitmap_Destroy(&app->bitmap); diff --git a/network.c b/network.c new file mode 100644 index 0000000..02ebbf3 --- /dev/null +++ b/network.c @@ -0,0 +1,21 @@ +// +// Created by rov on 12/27/25. +// + +#include "network.h" + +#include +#include + +bool Network_Init() { + if (!NET_Init()) { + SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_ERROR, "Error", "Failed to initialize SDL_net.", NULL); + return false; + } + + return true; +} + +void Network_Shutdown() { + NET_Quit(); +} diff --git a/network.h b/network.h new file mode 100644 index 0000000..b819199 --- /dev/null +++ b/network.h @@ -0,0 +1,13 @@ +// +// Created by rov on 12/27/25. +// + +#ifndef TIBIA_NETWORK_H +#define TIBIA_NETWORK_H + +#include + +bool Network_Init(); +void Network_Shutdown(); + +#endif //TIBIA_NETWORK_H \ No newline at end of file