From 6bae3004c3a9870309f4228bf943f740e7b5447f Mon Sep 17 00:00:00 2001 From: Christian Baumann Date: Mon, 16 Sep 2024 22:58:25 +0200 Subject: [PATCH 1/4] Add connection speed settings --- Descent3/config.cpp | 8 ++++++ Descent3/ctlconfig.cpp | 58 +++++++++++++++++++++++++++++++++++++++ Descent3/ctlconfig.h | 12 ++++++++ networking/networking.cpp | 25 ++++++----------- 4 files changed, 87 insertions(+), 16 deletions(-) diff --git a/Descent3/config.cpp b/Descent3/config.cpp index 8d69d709..b02f02d4 100644 --- a/Descent3/config.cpp +++ b/Descent3/config.cpp @@ -929,6 +929,7 @@ struct sound_menu { #define UID_SHORTCUT_JOYSETTINGS 0x1000 #define UID_SHORTCUT_KEYSETTINGS 0x1001 #define UID_SHORTCUT_FORCEFEED 0x1002 +#define UID_SHORTCUT_NETSETTINGS 0x1003 struct toggles_menu { newuiSheet *sheet; @@ -990,6 +991,10 @@ struct toggles_menu { if (ff_found) { sheet->AddLongButton(TXT_CFG_CONFIGFORCEFEEDBACK, UID_SHORTCUT_FORCEFEED); } + + sheet->NewGroup("Misc", 110, ff_found ? 200 : 190); + sheet->AddLongButton("Network Settings", UID_SHORTCUT_NETSETTINGS); + return sheet; }; @@ -1025,6 +1030,9 @@ struct toggles_menu { key_settings_dialog(); SaveControlConfig(); break; + case UID_SHORTCUT_NETSETTINGS: + net_settings_dialog(); + break; } }; }; diff --git a/Descent3/ctlconfig.cpp b/Descent3/ctlconfig.cpp index 0338d0f6..2bbd5f32 100644 --- a/Descent3/ctlconfig.cpp +++ b/Descent3/ctlconfig.cpp @@ -292,6 +292,8 @@ #include "D3ForceFeedback.h" #include "hlsoundlib.h" #include "ddio.h" +#include "networking.h" +#include "appdatabase.h" ////////////////////////////////////////////////////////////////////////////// #define IDV_KCONFIG 10 @@ -1288,6 +1290,62 @@ void key_settings_dialog() { wnd.Close(); wnd.Destroy(); } + +void net_settings_dialog() { + newuiTiledWindow wnd; + newuiSheet *sheet; + int res; + int *connectionSpeedIndex; + int nwRecommendPPS = nw_ReccomendPPS(); + + LOG_DEBUG.printf("Load network settings. PPS:%d.", nwRecommendPPS); + + // Create window + wnd.Create("Network Settings", 0, 0, 384, 256); + + // add group "Connection Speed" + sheet = wnd.GetSheet(); + sheet->NewGroup("Connection Speed", 0, 0); + + connectionSpeedIndex = sheet->AddFirstRadioButton(Cfg_Connection_Speed_List[0].name); + for (int i = 1; i < CTLCONFIG_CONNECTION_SPEED_LIST_SIZE; i++) { + sheet->AddRadioButton(Cfg_Connection_Speed_List[i].name); + } + + // pre-select connection speed button + for (int i = 0; i < CTLCONFIG_CONNECTION_SPEED_LIST_SIZE; i++) { + if (Cfg_Connection_Speed_List[i].pps == nwRecommendPPS) { + *connectionSpeedIndex = i; + break; + } + } + + // add group "window ctrl buttons" + sheet->NewGroup(NULL, 180, 160, NEWUI_ALIGN_HORIZ); + sheet->AddButton(TXT_OK, UID_OK); + sheet->AddButton(TXT_CANCEL, UID_CANCEL); + + // render + wnd.Open(); + do { + res = wnd.DoUI(); + + if (res == NEWUIRES_FORCEQUIT) { + break; + } + } while (res != UID_OK && res != UID_CANCEL); + + if (res == UID_OK) { + // save changes + LOG_DEBUG.printf("Write Connection Speed: %s, PPS:%d.", Cfg_Connection_Speed_List[*connectionSpeedIndex].name, + Cfg_Connection_Speed_List[*connectionSpeedIndex].pps); + Database->write(CTLCONFIG_CONNECTION_SPEED_DB_KEY, Cfg_Connection_Speed_List[*connectionSpeedIndex].name, + strlen(Cfg_Connection_Speed_List[*connectionSpeedIndex].name)); + } + wnd.Close(); + wnd.Destroy(); +} + ////////////////////////////////////////////////////////////////////////////// // configure controller new way struct t_ctlcfgswitchcb_data { diff --git a/Descent3/ctlconfig.h b/Descent3/ctlconfig.h index 30934bf1..1e4c05b4 100644 --- a/Descent3/ctlconfig.h +++ b/Descent3/ctlconfig.h @@ -59,6 +59,17 @@ #define CTLCONFIG_CONTROLLER 1 #define CTLCONFIG_WPNSEL 2 +#define CTLCONFIG_CONNECTION_SPEED_DB_KEY "ConnectionSpeed" + +struct t_cfg_connection_speed { + int pps; + const char *name; +}; + +#define CTLCONFIG_CONNECTION_SPEED_LIST_SIZE 5 +static const t_cfg_connection_speed Cfg_Connection_Speed_List[CTLCONFIG_CONNECTION_SPEED_LIST_SIZE] = { + {7, "56K"}, {8, "ISDN"}, {12, "Fast"}, {20, "Lan"}, {30, "Lan+"}}; + struct t_cfg_element { int16_t fn_id; // -1 = group start int16_t text; // text string id. @@ -76,5 +87,6 @@ void CtlConfig(int mode); // opens the settings dialogs. void joystick_settings_dialog(); void key_settings_dialog(); +void net_settings_dialog(); #endif diff --git a/networking/networking.cpp b/networking/networking.cpp index 31807915..ae1072e7 100644 --- a/networking/networking.cpp +++ b/networking/networking.cpp @@ -328,7 +328,7 @@ typedef int socklen_t; #include "game.h" #include "args.h" #include "byteswap.h" - +#include "ctlconfig.h" #ifdef WIN32 #include "directplay.h" #endif @@ -2279,21 +2279,14 @@ int nw_ReccomendPPS() { static char szconnspeed[100]; int len = 99; strcpy(szconnspeed, ""); - Database->read("ConnectionSpeed", szconnspeed, &len); - if (stricmp(szconnspeed, "28K") == 0) - return 5; - else if (stricmp(szconnspeed, "33K") == 0) - return 6; - else if (stricmp(szconnspeed, "56K") == 0) - return 7; - else if (stricmp(szconnspeed, "ISDN") == 0) - return 8; - else if (stricmp(szconnspeed, "Cable") == 0) - return 9; - else if (stricmp(szconnspeed, "Fast") == 0) - return 12; - else - return 7; + Database->read(CTLCONFIG_CONNECTION_SPEED_DB_KEY, szconnspeed, &len); + + for (int i = 0; i < CTLCONFIG_CONNECTION_SPEED_LIST_SIZE; i++) { + if (stricmp(szconnspeed, Cfg_Connection_Speed_List[i].name) == 0) + return Cfg_Connection_Speed_List[i].pps; + } + + return 8; } // Register the networking library to call your function back From ed43d436b2805c321cf4fe50d48a9eeff71c8871 Mon Sep 17 00:00:00 2001 From: Christian Baumann Date: Mon, 16 Sep 2024 23:28:47 +0200 Subject: [PATCH 2/4] increase dedicated max pps --- Descent3/dedicated_server.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Descent3/dedicated_server.cpp b/Descent3/dedicated_server.cpp index 86c8dbeb..72540a7a 100644 --- a/Descent3/dedicated_server.cpp +++ b/Descent3/dedicated_server.cpp @@ -160,7 +160,7 @@ extern char PXO_hosted_lobby_name[]; // the dedicated server static cvar_entry CVars[] = { - {"PPS", CVAR_TYPE_INT, &Netgame.packets_per_second, 2, 20, CVAR_GAMEINIT}, // 0 + {"PPS", CVAR_TYPE_INT, &Netgame.packets_per_second, 2, 40, CVAR_GAMEINIT}, // 0 {"TimeLimit", CVAR_TYPE_INT, &Netgame.timelimit, 0, 10000, CVAR_GAMEINIT}, {"KillGoal", CVAR_TYPE_INT, &Netgame.killgoal, 0, 10000, CVAR_GAMEINIT}, {"RespawnTime", CVAR_TYPE_INT, &Netgame.respawn_time, 0, 10000, CVAR_GAMEINIT}, From 060060074436e92bc54bd99f47919670d1697a3c Mon Sep 17 00:00:00 2001 From: Christian Baumann Date: Tue, 17 Sep 2024 20:32:13 +0200 Subject: [PATCH 3/4] rename fast to adsl --- Descent3/ctlconfig.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Descent3/ctlconfig.h b/Descent3/ctlconfig.h index 1e4c05b4..4c32abb3 100644 --- a/Descent3/ctlconfig.h +++ b/Descent3/ctlconfig.h @@ -68,7 +68,7 @@ struct t_cfg_connection_speed { #define CTLCONFIG_CONNECTION_SPEED_LIST_SIZE 5 static const t_cfg_connection_speed Cfg_Connection_Speed_List[CTLCONFIG_CONNECTION_SPEED_LIST_SIZE] = { - {7, "56K"}, {8, "ISDN"}, {12, "Fast"}, {20, "Lan"}, {30, "Lan+"}}; + {7, "56K"}, {8, "ISDN"}, {12, "ADSL"}, {20, "Lan"}, {30, "Lan+"}}; struct t_cfg_element { int16_t fn_id; // -1 = group start From 4137feed4e0f5350319d315f0bf054122e7a42aa Mon Sep 17 00:00:00 2001 From: Christian Baumann Date: Sat, 21 Sep 2024 20:29:36 +0200 Subject: [PATCH 4/4] pps slider --- Descent3/ctlconfig.cpp | 36 ++++++++++++++++++------------------ Descent3/ctlconfig.h | 11 +++-------- networking/networking.cpp | 14 ++++---------- 3 files changed, 25 insertions(+), 36 deletions(-) diff --git a/Descent3/ctlconfig.cpp b/Descent3/ctlconfig.cpp index 2bbd5f32..461758bf 100644 --- a/Descent3/ctlconfig.cpp +++ b/Descent3/ctlconfig.cpp @@ -1295,7 +1295,11 @@ void net_settings_dialog() { newuiTiledWindow wnd; newuiSheet *sheet; int res; - int *connectionSpeedIndex; + int16_t curpos; + int16_t *pps_client_current_t; + tSliderSettings slider_set; + + int cfg_range = CFG_NETWORK_CLIENT_PPS_MAX - CFG_NETWORK_CLIENT_PPS_MIN; int nwRecommendPPS = nw_ReccomendPPS(); LOG_DEBUG.printf("Load network settings. PPS:%d.", nwRecommendPPS); @@ -1303,22 +1307,17 @@ void net_settings_dialog() { // Create window wnd.Create("Network Settings", 0, 0, 384, 256); - // add group "Connection Speed" + // add group sheet = wnd.GetSheet(); - sheet->NewGroup("Connection Speed", 0, 0); + sheet->NewGroup("", 0, 0); - connectionSpeedIndex = sheet->AddFirstRadioButton(Cfg_Connection_Speed_List[0].name); - for (int i = 1; i < CTLCONFIG_CONNECTION_SPEED_LIST_SIZE; i++) { - sheet->AddRadioButton(Cfg_Connection_Speed_List[i].name); - } + // slider setup + slider_set.min_val.i = CFG_NETWORK_CLIENT_PPS_MIN; + slider_set.max_val.i = CFG_NETWORK_CLIENT_PPS_MAX; + slider_set.type = SLIDER_UNITS_INT; + curpos = CALC_SLIDER_POS_INT(nwRecommendPPS, &slider_set, cfg_range); - // pre-select connection speed button - for (int i = 0; i < CTLCONFIG_CONNECTION_SPEED_LIST_SIZE; i++) { - if (Cfg_Connection_Speed_List[i].pps == nwRecommendPPS) { - *connectionSpeedIndex = i; - break; - } - } + pps_client_current_t = sheet->AddSlider("PPS", cfg_range, curpos, &slider_set); // add group "window ctrl buttons" sheet->NewGroup(NULL, 180, 160, NEWUI_ALIGN_HORIZ); @@ -1337,10 +1336,11 @@ void net_settings_dialog() { if (res == UID_OK) { // save changes - LOG_DEBUG.printf("Write Connection Speed: %s, PPS:%d.", Cfg_Connection_Speed_List[*connectionSpeedIndex].name, - Cfg_Connection_Speed_List[*connectionSpeedIndex].pps); - Database->write(CTLCONFIG_CONNECTION_SPEED_DB_KEY, Cfg_Connection_Speed_List[*connectionSpeedIndex].name, - strlen(Cfg_Connection_Speed_List[*connectionSpeedIndex].name)); + nwRecommendPPS = CALC_SLIDER_INT_VALUE(*pps_client_current_t, CFG_NETWORK_CLIENT_PPS_MIN, CFG_NETWORK_CLIENT_PPS_MAX, cfg_range); + + LOG_DEBUG.printf("Write network client pps %d.", nwRecommendPPS); + + Database->write(CTLCONFIG_PPS_CLIENT_DB_KEY, nwRecommendPPS); } wnd.Close(); wnd.Destroy(); diff --git a/Descent3/ctlconfig.h b/Descent3/ctlconfig.h index 4c32abb3..bdb6bf98 100644 --- a/Descent3/ctlconfig.h +++ b/Descent3/ctlconfig.h @@ -59,16 +59,11 @@ #define CTLCONFIG_CONTROLLER 1 #define CTLCONFIG_WPNSEL 2 -#define CTLCONFIG_CONNECTION_SPEED_DB_KEY "ConnectionSpeed" +#define CTLCONFIG_PPS_CLIENT_DB_KEY "ClientPPS" -struct t_cfg_connection_speed { - int pps; - const char *name; -}; -#define CTLCONFIG_CONNECTION_SPEED_LIST_SIZE 5 -static const t_cfg_connection_speed Cfg_Connection_Speed_List[CTLCONFIG_CONNECTION_SPEED_LIST_SIZE] = { - {7, "56K"}, {8, "ISDN"}, {12, "ADSL"}, {20, "Lan"}, {30, "Lan+"}}; +#define CFG_NETWORK_CLIENT_PPS_MIN 7 +#define CFG_NETWORK_CLIENT_PPS_MAX 30 struct t_cfg_element { int16_t fn_id; // -1 = group start diff --git a/networking/networking.cpp b/networking/networking.cpp index 6de10feb..ea5f0082 100644 --- a/networking/networking.cpp +++ b/networking/networking.cpp @@ -328,6 +328,7 @@ typedef int socklen_t; #include "args.h" #include "byteswap.h" #include "pstring.h" +#include "ctlconfig.h" #ifndef WIN32 bool Use_DirectPlay = false; @@ -2268,17 +2269,10 @@ void CDECLCALL gethostbynameworker(void *parm) } int nw_ReccomendPPS() { - static char szconnspeed[100]; - int len = 99; - strcpy(szconnspeed, ""); - Database->read(CTLCONFIG_CONNECTION_SPEED_DB_KEY, szconnspeed, &len); + int clientPPS = CFG_NETWORK_CLIENT_PPS_MAX; + Database->read_int(CTLCONFIG_PPS_CLIENT_DB_KEY, &clientPPS); - for (int i = 0; i < CTLCONFIG_CONNECTION_SPEED_LIST_SIZE; i++) { - if (stricmp(szconnspeed, Cfg_Connection_Speed_List[i].name) == 0) - return Cfg_Connection_Speed_List[i].pps; - } - - return 8; + return clientPPS; } // Register the networking library to call your function back