-
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Also, improved A LOT the entrypoint, the CLI argument handling, the Makefile structure (+ some bugs fixed there as well), etc.
- Loading branch information
1 parent
809c693
commit d018524
Showing
9 changed files
with
202 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,6 @@ | ||
[submodule "vendor/raylib"] | ||
path = vendor/raylib | ||
url = https://github.com/raysan5/raylib | ||
[submodule "vendor/nbnet"] | ||
path = vendor/nbnet | ||
url = https://github.com/nathhB/nbnet |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -23,7 +23,7 @@ | |
VERSION = 0 | ||
PATCHLEVEL = 1 | ||
SUBLEVEL = 0 | ||
EXTRAVERSION = | ||
EXTRAVERSION = -alpha1 | ||
# Quiet | ||
Q = @ | ||
# Debug | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -23,4 +23,4 @@ | |
|
||
#include <sk_defines.h> | ||
|
||
u8 sk_client_run(void); | ||
u8 sk_client_run(const char *ip); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
/* | ||
* GNU Sparky --- A 5v5 character-based libre tactical shooter | ||
* Copyright (C) 2024 Wasym A. Alonso | ||
* | ||
* This file is part of Sparky. | ||
* | ||
* Sparky is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* Sparky is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with Sparky. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
|
||
#pragma once | ||
|
||
#include <sk_defines.h> | ||
|
||
#define NBN_LogTrace(...) TraceLog(LOG_TRACE, __VA_ARGS__) | ||
#define NBN_LogDebug(...) TraceLog(LOG_DEBUG, __VA_ARGS__) | ||
#define NBN_LogInfo(...) TraceLog(LOG_INFO, __VA_ARGS__) | ||
#define NBN_LogWarning(...) TraceLog(LOG_WARNING, __VA_ARGS__) | ||
#define NBN_LogError(...) TraceLog(LOG_ERROR, __VA_ARGS__) | ||
|
||
u8 sk_server_run(void); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
/* | ||
* GNU Sparky --- A 5v5 character-based libre tactical shooter | ||
* Copyright (C) 2024 Wasym A. Alonso | ||
* | ||
* This file is part of Sparky. | ||
* | ||
* Sparky is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* Sparky is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with Sparky. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
|
||
#include <raylib.h> | ||
#include <signal.h> | ||
#include <sk_server.h> | ||
|
||
#define NBNET_IMPL | ||
#include <nbnet.h> | ||
#include <net_drivers/udp.h> | ||
|
||
#if defined(_WIN32) || defined(_WIN64) | ||
#include <windows.h> | ||
#include <winsock2.h> | ||
#include <synchapi.h> | ||
#else | ||
#include <time.h> | ||
#endif | ||
|
||
static volatile u8 running = 1; | ||
|
||
static inline void __handle_interrupt(int signum) { | ||
if (signum == SIGINT) running = 0; | ||
} | ||
|
||
static void __wait_next_tick(double t) { | ||
#if defined(_WIN32) || defined(_WIN64) | ||
Sleep(1000 * t); | ||
#else | ||
long ns_t = 1e9 * t; | ||
struct timespec ts = { | ||
.tv_sec = ns_t / (long) (1e9 - 1), | ||
.tv_nsec = ns_t % (long) (1e9 - 1) | ||
}; | ||
nanosleep(&ts, &ts); | ||
#endif | ||
} | ||
|
||
static inline u8 __shutdown(void) { | ||
NBN_GameServer_Stop(); | ||
TraceLog(LOG_INFO, "%s closed successfully", SK_SERVER_NAME); | ||
return 0; | ||
} | ||
|
||
u8 sk_server_run(void) { | ||
TraceLog(LOG_INFO, "Initializing %s", SK_SERVER_NAME); | ||
NBN_UDP_Register(); | ||
if (NBN_GameServer_StartEx(SK_SERVER_NAME, SK_SERVER_PORT, 1) == -1) { | ||
TraceLog(LOG_ERROR, "Unable to start the server"); | ||
return 1; | ||
} | ||
// TODO: register msgs | ||
double dt = 1 / SK_SERVER_TICK_RATE; | ||
signal(SIGINT, __handle_interrupt); | ||
while (running) { | ||
__wait_next_tick(dt); | ||
} | ||
return __shutdown(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters