Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add ui network settings #590

Merged
merged 7 commits into from
Oct 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions Descent3/config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -930,6 +930,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;
Expand Down Expand Up @@ -991,6 +992,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;
};

Expand Down Expand Up @@ -1026,6 +1031,9 @@ struct toggles_menu {
key_settings_dialog();
SaveControlConfig();
break;
case UID_SHORTCUT_NETSETTINGS:
net_settings_dialog();
break;
}
};
};
Expand Down
58 changes: 58 additions & 0 deletions Descent3/ctlconfig.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -293,6 +293,8 @@
#include "hlsoundlib.h"
#include "ddio.h"
#include "pserror.h"
#include "networking.h"
#include "appdatabase.h"

//////////////////////////////////////////////////////////////////////////////
#define IDV_KCONFIG 10
Expand Down Expand Up @@ -1289,6 +1291,62 @@ void key_settings_dialog() {
wnd.Close();
wnd.Destroy();
}

void net_settings_dialog() {
newuiTiledWindow wnd;
newuiSheet *sheet;
int res;
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);

// Create window
wnd.Create("Network Settings", 0, 0, 384, 256);

// add group
sheet = wnd.GetSheet();
sheet->NewGroup("", 0, 0);

// 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);

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);
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
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();
}

//////////////////////////////////////////////////////////////////////////////
// configure controller new way
struct t_ctlcfgswitchcb_data {
Expand Down
7 changes: 7 additions & 0 deletions Descent3/ctlconfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,12 @@
#define CTLCONFIG_CONTROLLER 1
#define CTLCONFIG_WPNSEL 2

#define CTLCONFIG_PPS_CLIENT_DB_KEY "ClientPPS"


#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
int16_t text; // text string id.
Expand All @@ -76,5 +82,6 @@ void CtlConfig(int mode);
// opens the settings dialogs.
void joystick_settings_dialog();
void key_settings_dialog();
void net_settings_dialog();

#endif
2 changes: 1 addition & 1 deletion Descent3/dedicated_server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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},
Expand Down
23 changes: 5 additions & 18 deletions networking/networking.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -327,6 +327,7 @@ typedef int socklen_t;
#include "game.h"
#include "args.h"
#include "byteswap.h"
#include "ctlconfig.h"

#ifndef WIN32
bool Use_DirectPlay = false;
Expand Down Expand Up @@ -2266,24 +2267,10 @@ void CDECLCALL gethostbynameworker(void *parm)
}

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;
int clientPPS = CFG_NETWORK_CLIENT_PPS_MAX;
Database->read_int(CTLCONFIG_PPS_CLIENT_DB_KEY, &clientPPS);

return clientPPS;
}

// Register the networking library to call your function back
Expand Down
Loading