forked from Ports/perfect_dark
port: net: add some config vars
This commit is contained in:
1 parent
e85cc3b309
commit
95d8b0692f
4 files changed
+72
-7
No files matched your search
@@ -16,5 +16,6 @@ s32 configSave(const char *fname);
|
|||||||
// registers a variable in the config file
|
// registers a variable in the config file
|
||||||
// this should be done before configInit() is called, preferably in a module constructor
|
// this should be done before configInit() is called, preferably in a module constructor
|
||||||
void configRegisterInt(const char *key, s32 *var, s32 min, s32 max);
|
void configRegisterInt(const char *key, s32 *var, s32 min, s32 max);
|
||||||
|
void configRegisterUInt(const char *key, u32 *var, u32 min, u32 max);
|
||||||
void configRegisterFloat(const char *key, f32 *var, f32 min, f32 max);
|
void configRegisterFloat(const char *key, f32 *var, f32 min, f32 max);
|
||||||
void configRegisterString(const char *key, char *var, u32 maxstr);
|
void configRegisterString(const char *key, char *var, u32 maxstr);
|
||||||
@@ -9,6 +9,7 @@
|
|||||||
|
|
||||||
#define NET_MAX_CLIENTS MAX_PLAYERS
|
#define NET_MAX_CLIENTS MAX_PLAYERS
|
||||||
#define NET_MAX_NAME MAX_PLAYERNAME
|
#define NET_MAX_NAME MAX_PLAYERNAME
|
||||||
|
#define NET_MAX_ADDR 256
|
||||||
|
|
||||||
#define NET_BUFSIZE 1440
|
#define NET_BUFSIZE 1440
|
||||||
|
|
||||||
@@ -98,8 +99,12 @@ extern s32 g_NetMode;
|
|||||||
|
|
||||||
// net frame, ticks at 60 fps, starts at 0 when the server is started
|
// net frame, ticks at 60 fps, starts at 0 when the server is started
|
||||||
extern u32 g_NetTick;
|
extern u32 g_NetTick;
|
||||||
extern u32 g_NetInterpTicks;
|
|
||||||
extern u32 g_NetNextSyncId;
|
extern u32 g_NetNextSyncId;
|
||||||
|
|
||||||
|
extern u32 g_NetInterpTicks;
|
||||||
|
extern u32 g_NetServerPort;
|
||||||
|
extern char g_NetLastJoinAddr[NET_MAX_ADDR + 1];
|
||||||
|
|
||||||
extern s32 g_NetDebugDraw;
|
extern s32 g_NetDebugDraw;
|
||||||
|
|
||||||
extern s32 g_NetMaxClients;
|
extern s32 g_NetMaxClients;
|
||||||
|
|||||||
+13
-1
@@ -24,9 +24,11 @@
|
|||||||
|
|
||||||
s32 g_NetMode = NETMODE_NONE;
|
s32 g_NetMode = NETMODE_NONE;
|
||||||
|
|
||||||
u32 g_NetTick = 0;
|
|
||||||
u32 g_NetInterpTicks = 6;
|
u32 g_NetInterpTicks = 6;
|
||||||
|
u32 g_NetServerPort = NET_DEFAULT_PORT;
|
||||||
|
char g_NetLastJoinAddr[NET_MAX_ADDR + 1] = "127.0.0.1:27100";
|
||||||
|
|
||||||
|
u32 g_NetTick = 0;
|
||||||
u32 g_NetNextSyncId = 1;
|
u32 g_NetNextSyncId = 1;
|
||||||
|
|
||||||
s32 g_NetSimPacketLoss = 0;
|
s32 g_NetSimPacketLoss = 0;
|
||||||
@@ -325,6 +327,9 @@ s32 netStartClient(const char *addr)
|
|||||||
return -3;
|
return -3;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// save the address since it appears to be valid
|
||||||
|
strncpy(g_NetLastJoinAddr, addr, NET_MAX_ADDR);
|
||||||
|
|
||||||
// we'll use the whole array to store what we know of other clients
|
// we'll use the whole array to store what we know of other clients
|
||||||
netClientResetAll();
|
netClientResetAll();
|
||||||
|
|
||||||
@@ -786,3 +791,10 @@ Gfx *netDebugRender(Gfx *gdl)
|
|||||||
|
|
||||||
return gdl;
|
return gdl;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
PD_CONSTRUCTOR static void netConfigInit(void)
|
||||||
|
{
|
||||||
|
configRegisterString("Net.LastJoinAddr", g_NetLastJoinAddr, NET_MAX_ADDR);
|
||||||
|
configRegisterUInt("Net.ServerPort", &g_NetServerPort, 0, 0xFFFF);
|
||||||
|
configRegisterUInt("Net.LerpTicks", &g_NetInterpTicks, 0, 600);
|
||||||
|
}
|
||||||
+52
-5
@@ -19,7 +19,7 @@ extern MenuItemHandlerResult menuhandlerMpAdvancedSetup(s32 operation, struct me
|
|||||||
|
|
||||||
static s32 g_NetMenuMaxPlayers = NET_MAX_CLIENTS;
|
static s32 g_NetMenuMaxPlayers = NET_MAX_CLIENTS;
|
||||||
static s32 g_NetMenuPort = NET_DEFAULT_PORT;
|
static s32 g_NetMenuPort = NET_DEFAULT_PORT;
|
||||||
static char g_NetJoinAddr[256] = "127.0.0.1:27100";
|
static char g_NetJoinAddr[NET_MAX_ADDR + 1];
|
||||||
static s32 g_NetJoinAddrPtr = 0;
|
static s32 g_NetJoinAddrPtr = 0;
|
||||||
|
|
||||||
/* host */
|
/* host */
|
||||||
@@ -40,6 +40,22 @@ static MenuItemHandlerResult menuhandlerHostMaxPlayers(s32 operation, struct men
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static MenuItemHandlerResult menuhandlerHostPort(s32 operation, struct menuitem *item, union handlerdata *data)
|
||||||
|
{
|
||||||
|
if (operation == MENUOP_SET) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
static char *menuhandlerHostPortValue(struct menuitem *item)
|
||||||
|
{
|
||||||
|
static char tmp[16];
|
||||||
|
snprintf(tmp, sizeof(tmp), "%u\n", g_NetMenuPort);
|
||||||
|
return tmp;
|
||||||
|
}
|
||||||
|
|
||||||
static MenuItemHandlerResult menuhandlerHostStart(s32 operation, struct menuitem *item, union handlerdata *data)
|
static MenuItemHandlerResult menuhandlerHostStart(s32 operation, struct menuitem *item, union handlerdata *data)
|
||||||
{
|
{
|
||||||
if (operation == MENUOP_SET) {
|
if (operation == MENUOP_SET) {
|
||||||
@@ -61,6 +77,14 @@ struct menuitem g_NetHostMenuItems[] = {
|
|||||||
NET_MAX_CLIENTS,
|
NET_MAX_CLIENTS,
|
||||||
menuhandlerHostMaxPlayers,
|
menuhandlerHostMaxPlayers,
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
MENUITEMTYPE_SELECTABLE,
|
||||||
|
0,
|
||||||
|
MENUITEMFLAG_LITERAL_TEXT,
|
||||||
|
(uintptr_t)"Port\n",
|
||||||
|
(uintptr_t)&menuhandlerHostPortValue,
|
||||||
|
menuhandlerHostPort,
|
||||||
|
},
|
||||||
{
|
{
|
||||||
MENUITEMTYPE_SELECTABLE,
|
MENUITEMTYPE_SELECTABLE,
|
||||||
0,
|
0,
|
||||||
@@ -326,22 +350,45 @@ struct menudialogdef g_NetJoinMenuDialog = {
|
|||||||
|
|
||||||
/* main */
|
/* main */
|
||||||
|
|
||||||
|
static MenuItemHandlerResult menuhandlerHostGame(s32 operation, struct menuitem *item, union handlerdata *data)
|
||||||
|
{
|
||||||
|
if (operation == MENUOP_SET) {
|
||||||
|
g_NetMenuPort = g_NetServerPort;
|
||||||
|
menuPushDialog(&g_NetHostMenuDialog);
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
static MenuItemHandlerResult menuhandlerJoinGame(s32 operation, struct menuitem *item, union handlerdata *data)
|
||||||
|
{
|
||||||
|
if (operation == MENUOP_SET) {
|
||||||
|
if (g_NetJoinAddr[0] == '\0') {
|
||||||
|
strncpy(g_NetJoinAddr, g_NetLastJoinAddr, NET_MAX_ADDR);
|
||||||
|
g_NetJoinAddrPtr = strlen(g_NetJoinAddr);
|
||||||
|
}
|
||||||
|
menuPushDialog(&g_NetJoinMenuDialog);
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
struct menuitem g_NetMenuItems[] = {
|
struct menuitem g_NetMenuItems[] = {
|
||||||
{
|
{
|
||||||
MENUITEMTYPE_SELECTABLE,
|
MENUITEMTYPE_SELECTABLE,
|
||||||
0,
|
0,
|
||||||
MENUITEMFLAG_SELECTABLE_OPENSDIALOG | MENUITEMFLAG_LITERAL_TEXT,
|
MENUITEMFLAG_LITERAL_TEXT,
|
||||||
(uintptr_t)"Host Game\n",
|
(uintptr_t)"Host Game\n",
|
||||||
0,
|
0,
|
||||||
(void *)&g_NetHostMenuDialog,
|
menuhandlerHostGame,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
MENUITEMTYPE_SELECTABLE,
|
MENUITEMTYPE_SELECTABLE,
|
||||||
0,
|
0,
|
||||||
MENUITEMFLAG_SELECTABLE_OPENSDIALOG | MENUITEMFLAG_LITERAL_TEXT,
|
MENUITEMFLAG_LITERAL_TEXT,
|
||||||
(uintptr_t)"Join Game\n",
|
(uintptr_t)"Join Game\n",
|
||||||
0,
|
0,
|
||||||
(void *)&g_NetJoinMenuDialog,
|
menuhandlerJoinGame,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
MENUITEMTYPE_SEPARATOR,
|
MENUITEMTYPE_SEPARATOR,
|
||||||
|
|||||||
Reference in new issue
Block a user