mirror of
https://github.com/KartKrewDev/RingRacers.git
synced 2025-10-30 08:01:28 +00:00
Rudimentary start on profiles
This commit is contained in:
parent
00a471405d
commit
1789dd1255
8 changed files with 208 additions and 7 deletions
|
|
@ -116,3 +116,4 @@ k_menudraw.c
|
||||||
k_brightmap.c
|
k_brightmap.c
|
||||||
k_terrain.c
|
k_terrain.c
|
||||||
k_director.c
|
k_director.c
|
||||||
|
k_profiles.c
|
||||||
|
|
|
||||||
|
|
@ -1479,6 +1479,10 @@ void D_SRB2Main(void)
|
||||||
//--------------------------------------------------------- CONFIG.CFG
|
//--------------------------------------------------------- CONFIG.CFG
|
||||||
M_FirstLoadConfig(); // WARNING : this do a "COM_BufExecute()"
|
M_FirstLoadConfig(); // WARNING : this do a "COM_BufExecute()"
|
||||||
|
|
||||||
|
// Load Profiles now that default controls have been defined
|
||||||
|
PR_LoadProfiles(); // load control profiles
|
||||||
|
PR_SaveProfiles(); // Test @TODO: remove this lol
|
||||||
|
|
||||||
M_Init();
|
M_Init();
|
||||||
|
|
||||||
#if (defined (__unix__) && !defined (MSDOS)) || defined (UNIXCOMMON) || defined (HAVE_SDL)
|
#if (defined (__unix__) && !defined (MSDOS)) || defined (UNIXCOMMON) || defined (HAVE_SDL)
|
||||||
|
|
|
||||||
|
|
@ -14,6 +14,7 @@
|
||||||
#ifndef __D_MAIN__
|
#ifndef __D_MAIN__
|
||||||
#define __D_MAIN__
|
#define __D_MAIN__
|
||||||
|
|
||||||
|
#include "k_profiles.h" // PR_LoadProfiles()
|
||||||
#include "d_event.h"
|
#include "d_event.h"
|
||||||
#include "w_wad.h" // for MAX_WADFILES
|
#include "w_wad.h" // for MAX_WADFILES
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -935,13 +935,6 @@ void D_RegisterClientCommands(void)
|
||||||
{
|
{
|
||||||
CV_RegisterVar(&cv_kickstartaccel[i]);
|
CV_RegisterVar(&cv_kickstartaccel[i]);
|
||||||
CV_RegisterVar(&cv_shrinkme[i]);
|
CV_RegisterVar(&cv_shrinkme[i]);
|
||||||
CV_RegisterVar(&cv_turnaxis[i]);
|
|
||||||
CV_RegisterVar(&cv_moveaxis[i]);
|
|
||||||
CV_RegisterVar(&cv_brakeaxis[i]);
|
|
||||||
CV_RegisterVar(&cv_aimaxis[i]);
|
|
||||||
CV_RegisterVar(&cv_lookaxis[i]);
|
|
||||||
CV_RegisterVar(&cv_fireaxis[i]);
|
|
||||||
CV_RegisterVar(&cv_driftaxis[i]);
|
|
||||||
CV_RegisterVar(&cv_deadzone[i]);
|
CV_RegisterVar(&cv_deadzone[i]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
90
src/k_profiles.c
Normal file
90
src/k_profiles.c
Normal file
|
|
@ -0,0 +1,90 @@
|
||||||
|
// SONIC ROBO BLAST 2
|
||||||
|
//-----------------------------------------------------------------------------
|
||||||
|
// Copyright (C) 1998-2000 by DooM Legacy Team.
|
||||||
|
// Copyright (C) 1999-2020 by Sonic Team Junior.
|
||||||
|
//
|
||||||
|
// This program is free software distributed under the
|
||||||
|
// terms of the GNU General Public License, version 2.
|
||||||
|
// See the 'LICENSE' file for more details.
|
||||||
|
//-----------------------------------------------------------------------------
|
||||||
|
/// \file k_profiles.c
|
||||||
|
/// \brief implements methods for profiles etc.
|
||||||
|
|
||||||
|
#include "k_profiles.h"
|
||||||
|
|
||||||
|
// List of all the profiles.
|
||||||
|
static profile_t profilesList[MAXPROFILES+1]; // +1 because we're gonna add a default "GUEST' profile.
|
||||||
|
static UINT8 numprofiles = 0; // # of loaded profiles
|
||||||
|
|
||||||
|
profile_t PR_MakeProfile(const char *prname, const char *pname, const UINT16 col, const char *fname, UINT16 fcol, INT32 controlarray[num_gamecontrols][MAXINPUTMAPPING])
|
||||||
|
{
|
||||||
|
profile_t new;
|
||||||
|
|
||||||
|
new.version = PROFILEVER;
|
||||||
|
|
||||||
|
strcpy(new.profilename, prname);
|
||||||
|
|
||||||
|
strcpy(new.playername, pname);
|
||||||
|
new.color = col;
|
||||||
|
|
||||||
|
strcpy(new.follower, fname);
|
||||||
|
new.followercolor = fcol;
|
||||||
|
|
||||||
|
// Copy from gamecontrol directly as we'll be setting controls up directly in the profile.
|
||||||
|
memcpy(new.controls, controlarray, sizeof(new.controls));
|
||||||
|
|
||||||
|
return new;
|
||||||
|
}
|
||||||
|
|
||||||
|
profile_t PR_MakeProfileFromPlayer(const char *prname, const char *pname, const UINT16 col, const char *fname, UINT16 fcol, UINT8 pnum)
|
||||||
|
{
|
||||||
|
// Generate profile using the player's gamecontrol, as we set them directly when making profiles from menus.
|
||||||
|
profile_t new = PR_MakeProfile(prname, pname, col, fname, fcol, gamecontrol[pnum]);
|
||||||
|
|
||||||
|
// Player bound cvars:
|
||||||
|
new.kickstartaccel = cv_kickstartaccel[pnum].value;
|
||||||
|
|
||||||
|
return new;
|
||||||
|
}
|
||||||
|
|
||||||
|
boolean PR_AddProfile(profile_t p)
|
||||||
|
{
|
||||||
|
if (numprofiles < MAXPROFILES)
|
||||||
|
{
|
||||||
|
memcpy(&profilesList[numprofiles], &p, sizeof(profile_t));
|
||||||
|
numprofiles++;
|
||||||
|
|
||||||
|
CONS_Printf("Profile '%s' added\n", p.profilename);
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
void PR_SaveProfiles(void)
|
||||||
|
{
|
||||||
|
FILE *f = NULL;
|
||||||
|
|
||||||
|
f = fopen(PROFILESFILE, "w");
|
||||||
|
if (f != NULL)
|
||||||
|
{
|
||||||
|
fwrite(profilesList, sizeof(profile_t), MAXPROFILES, f);
|
||||||
|
fclose(f);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void PR_LoadProfiles(void)
|
||||||
|
{
|
||||||
|
//FILE *f = NULL;
|
||||||
|
profile_t dprofile = PR_MakeProfile(PROFILEDEFAULTNAME, PROFILEDEFAULTPNAME, PROFILEDEFAULTCOLOR, PROFILEDEFAULTFOLLOWER, PROFILEDEFAULTFOLLOWERCOLOR, gamecontroldefault);
|
||||||
|
PR_AddProfile(dprofile);
|
||||||
|
|
||||||
|
/*f = fopen(PROFILESFILE, "r");
|
||||||
|
|
||||||
|
if (f != NULL)
|
||||||
|
{
|
||||||
|
fread(&profilesList[1], sizeof(profile_t)*(MAXPROFILES), MAXPROFILES, f);
|
||||||
|
fclose(f);
|
||||||
|
}*/
|
||||||
|
}
|
||||||
96
src/k_profiles.h
Normal file
96
src/k_profiles.h
Normal file
|
|
@ -0,0 +1,96 @@
|
||||||
|
// SONIC ROBO BLAST 2
|
||||||
|
//-----------------------------------------------------------------------------
|
||||||
|
// Copyright (C) 1993-1996 by id Software, Inc.
|
||||||
|
// Copyright (C) 1998-2000 by DooM Legacy Team.
|
||||||
|
// Copyright (C) 2011-2016 by Matthew "Inuyasha" Walsh.
|
||||||
|
// Copyright (C) 1999-2018 by Sonic Team Junior.
|
||||||
|
//
|
||||||
|
// This program is free software distributed under the
|
||||||
|
// terms of the GNU General Public License, version 2.
|
||||||
|
// See the 'LICENSE' file for more details.
|
||||||
|
//-----------------------------------------------------------------------------
|
||||||
|
/// \file k_profiles.h
|
||||||
|
/// \brief Control profiles definition
|
||||||
|
|
||||||
|
#ifndef __PROFILES_H__
|
||||||
|
#define __PROFILES_H__
|
||||||
|
|
||||||
|
#include "doomdef.h" // MAXPLAYERNAME
|
||||||
|
//#include "r_skins.h" // SKINNAMESIZE // This cuases stupid issues.
|
||||||
|
#include "g_input.h" // Input related stuff
|
||||||
|
#include "string.h" // strcpy etc
|
||||||
|
#include "g_game.h" // game CVs
|
||||||
|
|
||||||
|
// We have to redefine this because somehow including r_skins.h causes a redefinition of node_t since that's used for both net nodes and BSP nodes too......
|
||||||
|
// And honestly I don't wanna refactor that.
|
||||||
|
#define SKINNAMESIZE 16
|
||||||
|
|
||||||
|
#define PROFILENAMELEN 6
|
||||||
|
#define PROFILEVER 0
|
||||||
|
#define MAXPROFILES 16
|
||||||
|
#define PROFILESFILE "kartprofiles.cfg"
|
||||||
|
|
||||||
|
#define PROFILEDEFAULTNAME "GUEST"
|
||||||
|
#define PROFILEDEFAULTPNAME "Player"
|
||||||
|
#define PROFILEDEFAULTSKIN "sonic"
|
||||||
|
#define PROFILEDEFAULTCOLOR SKINCOLOR_SAPPHIRE
|
||||||
|
#define PROFILEDEFAULTFOLLOWER "none"
|
||||||
|
#define PROFILEDEFAULTFOLLOWERCOLOR 255
|
||||||
|
|
||||||
|
// Man I wish I had more than 16 friends!!
|
||||||
|
|
||||||
|
// profile_t definition (WIP)
|
||||||
|
typedef struct profile_s
|
||||||
|
{
|
||||||
|
|
||||||
|
// Versionning
|
||||||
|
UINT8 version; // Version of the profile, this can be useful for backwards compatibility reading if we ever update the profile structure/format after release.
|
||||||
|
|
||||||
|
// Profile header
|
||||||
|
char profilename[PROFILENAMELEN+1]; // Profile name (not to be confused with player name)
|
||||||
|
|
||||||
|
// Player data
|
||||||
|
char playername[MAXPLAYERNAME+1]; // Player name
|
||||||
|
UINT16 color; // Default player coloUr. ...But for consistency we'll name it color.
|
||||||
|
char follower[SKINNAMESIZE+1]; // Follower
|
||||||
|
UINT16 followercolor; // Follower color
|
||||||
|
|
||||||
|
// Player-specific consvars.
|
||||||
|
// @TODO: List all of those
|
||||||
|
boolean kickstartaccel; // cv_kickstartaccel
|
||||||
|
|
||||||
|
// Finally, control data itself
|
||||||
|
INT32 controls[num_gamecontrols][MAXINPUTMAPPING]; // Lists of all the controls, defined the same way as default inputs in g_input.c
|
||||||
|
} profile_t;
|
||||||
|
|
||||||
|
|
||||||
|
// Functions
|
||||||
|
|
||||||
|
// PR_MakeProfile
|
||||||
|
// Makes a profile from the supplied profile name, player name, colour, follower, followercolour and controls.
|
||||||
|
// The consvar values are left untouched.
|
||||||
|
profile_t PR_MakeProfile(const char *prname, const char *pname, const UINT16 col, const char *fname, UINT16 fcol, INT32 controlarray[num_gamecontrols][MAXINPUTMAPPING]);
|
||||||
|
|
||||||
|
// PR_MakeProfileFromPlayer
|
||||||
|
// Makes a profile_t from the supplied profile name, player name, colour, follower and followercolour.
|
||||||
|
// The last argument is a player number to read cvars from; as for convenience, cvars will be set directly when making a profile (since loading another one will overwrite them, this will be inconsequential)
|
||||||
|
profile_t PR_MakeProfileFromPlayer(const char *prname, const char *pname, const UINT16 col, const char *fname, UINT16 fcol, UINT8 pnum);
|
||||||
|
|
||||||
|
// PR_AddProfile(profile_t p)
|
||||||
|
// Adds a profile to profilesList and increments numprofiles.
|
||||||
|
// Returns true if succesful, false if not.
|
||||||
|
boolean PR_AddProfile(profile_t p);
|
||||||
|
|
||||||
|
// PR_SaveProfiles(void)
|
||||||
|
// Saves all the profiles in profiles.cfg
|
||||||
|
// This does not save profilesList[0] since that's always going to be the default profile.
|
||||||
|
void PR_SaveProfiles(void);
|
||||||
|
|
||||||
|
// PR_LoadProfiles(void)
|
||||||
|
// Loads all the profiles saved in profiles.cfg.
|
||||||
|
// This also loads
|
||||||
|
void PR_LoadProfiles(void);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
@ -2626,6 +2626,19 @@ void V_DrawPaddedTallNum(INT32 x, INT32 y, INT32 flags, INT32 num, INT32 digits)
|
||||||
} while (--digits);
|
} while (--digits);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void V_DrawCenteredThinStringAtFixed(fixed_t x, fixed_t y, INT32 option, const char *string)
|
||||||
|
{
|
||||||
|
x -= (V_ThinStringWidth(string, option) / 2) * FRACUNIT;
|
||||||
|
V_DrawThinStringAtFixed(x, y, option, string);
|
||||||
|
}
|
||||||
|
|
||||||
|
void V_DrawRightAlignedThinStringAtFixed(fixed_t x, fixed_t y, INT32 option, const char *string)
|
||||||
|
{
|
||||||
|
x -= V_ThinStringWidth(string, option) * FRACUNIT;
|
||||||
|
V_DrawThinStringAtFixed(x, y, option, string);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
// Draws a number using the PING font thingy.
|
// Draws a number using the PING font thingy.
|
||||||
// TODO: Merge number drawing functions into one with "font name" selection.
|
// TODO: Merge number drawing functions into one with "font name" selection.
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -291,6 +291,9 @@ void V_DrawRightAlignedThinString(INT32 x, INT32 y, INT32 option, const char *st
|
||||||
|
|
||||||
#define V_DrawThinStringAtFixed( x,y,option,string ) \
|
#define V_DrawThinStringAtFixed( x,y,option,string ) \
|
||||||
V__DrawOneScaleString (x,y,FRACUNIT,option,NULL,TINY_FONT,string)
|
V__DrawOneScaleString (x,y,FRACUNIT,option,NULL,TINY_FONT,string)
|
||||||
|
void V_DrawCenteredThinStringAtFixed(fixed_t x, fixed_t y, INT32 option, const char *string);
|
||||||
|
void V_DrawRightAlignedThinStringAtFixed(fixed_t x, fixed_t y, INT32 option, const char *string);
|
||||||
|
|
||||||
|
|
||||||
// Draws a titlecard font string.
|
// Draws a titlecard font string.
|
||||||
// timer: when the letters start appearing (leave to 0 to disable)
|
// timer: when the letters start appearing (leave to 0 to disable)
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue