pps slider

This commit is contained in:
Christian Baumann 2024-09-21 20:29:36 +02:00
parent 5f26094f80
commit 4137feed4e
3 changed files with 25 additions and 36 deletions

View File

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

View File

@ -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

View File

@ -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