code: add an ability to provide host conn details

isolation_bkp/dynres
Dominik Madarász 2022-07-31 10:46:06 +02:00
parent d8ae0b0d91
commit df9c45468a
5 changed files with 57 additions and 39 deletions

5
cmake_setup.bat 100644
View File

@ -0,0 +1,5 @@
@echo off
REM desktop
cmake -B build -DCMAKE_BUILD_TYPE=Debug -G Ninja
cmake -B build_rel -DCMAKE_BUILD_TYPE=Release -G Ninja

View File

@ -122,9 +122,21 @@ float game_time() {
return (float)zpl_time_rel();
}
void game_init(game_kind play_mode, uint32_t num_viewers, int32_t seed, uint16_t chunk_size, uint16_t chunk_amount, int8_t is_dash_enabled) {
void game_init(const char *ip, uint16_t port, game_kind play_mode, uint32_t num_viewers, int32_t seed, uint16_t chunk_size, uint16_t chunk_amount, int8_t is_dash_enabled) {
game_mode = play_mode;
#ifndef _DEBUG
const char *host_ip = "lab.zakto.pw";
#else
const char *host_ip = "127.0.0.1";
#endif
uint16_t host_port = (port > 0) ? port : 27000;
if (ip != NULL) {
host_ip = ip;
}
if (game_mode != GAMEKIND_HEADLESS) {
platform_init();
@ -139,11 +151,7 @@ void game_init(game_kind play_mode, uint32_t num_viewers, int32_t seed, uint16_t
if (game_mode == GAMEKIND_CLIENT) {
world_setup_pkt_handlers(pkt_reader, mp_cli_pkt_writer);
#ifndef _DEBUG
network_client_connect("lab.zakto.pw", 27000);
#else
network_client_connect("127.0.0.1", 27000);
#endif
network_client_connect(host_ip, host_port);
} else {
stdcpp_set_os_api();
world_setup_pkt_handlers(pkt_reader, game_mode == GAMEKIND_SINGLE ? sp_pkt_writer : mp_pkt_writer);

View File

@ -10,7 +10,7 @@ typedef enum {
FORCE_GAMEKIND_UINT8 = UINT8_MAX
} game_kind;
void game_init(game_kind play_mode, uint32_t num_viewers, int32_t seed, uint16_t chunk_size, uint16_t chunk_amount, int8_t is_dash_enabled);
void game_init(const char *ip, uint16_t port, game_kind play_mode, uint32_t num_viewers, int32_t seed, uint16_t chunk_size, uint16_t chunk_amount, int8_t is_dash_enabled);
void game_shutdown();
void game_request_close();
uint8_t game_is_running();

View File

@ -34,6 +34,8 @@ int main(int argc, char** argv) {
zpl_opts_add(&opts, "r", "random-seed", "generate random world seed", ZPL_OPTS_FLAG);
//zpl_opts_add(&opts, "cs", "chunk-size", "amount of blocks within a chunk (single axis)", ZPL_OPTS_INT);
zpl_opts_add(&opts, "ws", "world-size", "amount of chunks within a world (single axis)", ZPL_OPTS_INT);
zpl_opts_add(&opts, "ip", "host", "host IP address", ZPL_OPTS_STRING);
zpl_opts_add(&opts, "port", "port", "port number", ZPL_OPTS_INT);
uint32_t ok = zpl_opts_compile(&opts, argc, argv);
@ -50,6 +52,8 @@ int main(int argc, char** argv) {
uint16_t num_viewers = (uint16_t)zpl_opts_integer(&opts, "viewer-count", 1);
uint16_t world_size = (uint16_t)zpl_opts_integer(&opts, "world-size", DEFAULT_WORLD_SIZE);
uint16_t chunk_size = DEFAULT_CHUNK_SIZE; //zpl_opts_integer(&opts, "chunk-size", DEFAULT_CHUNK_SIZE);
zpl_string host = zpl_opts_string(&opts, "host", NULL);
uint16_t port = (uint16_t)zpl_opts_integer(&opts, "port", 0);
game_kind play_mode = GAMEKIND_SINGLE;
@ -69,7 +73,7 @@ int main(int argc, char** argv) {
}
sighandler_register();
game_init(play_mode, num_viewers, seed, chunk_size, world_size, is_dash_enabled);
game_init(host, port, play_mode, num_viewers, seed, chunk_size, world_size, is_dash_enabled);
while (game_is_running()) {
profile (PROF_MAIN_LOOP) {
@ -84,6 +88,7 @@ int main(int argc, char** argv) {
game_shutdown();
sighandler_unregister();
zpl_string_free(host);
zpl_opts_free(&opts);
return 0;
}