Skip to content

Commit

Permalink
Merge pull request #1185 from Daggolin/qol_fs
Browse files Browse the repository at this point in the history
FS Features
  • Loading branch information
Daggolin authored Apr 7, 2024
2 parents d2afcfe + fda880e commit 065d329
Show file tree
Hide file tree
Showing 22 changed files with 852 additions and 218 deletions.
9 changes: 9 additions & 0 deletions code/client/client.h
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,15 @@ typedef struct {
qhandle_t whiteShader;
qhandle_t consoleShader;
int consoleFont;

// Cursor
qboolean cursorActive;
qhandle_t cursorShader;
int cursorX;
int cursorY;

// Engine menu
int menuFont;
} clientStatic_t;

#define CON_TEXTSIZE 0x30000 //was 32768
Expand Down
3 changes: 3 additions & 0 deletions code/qcommon/common.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1105,6 +1105,9 @@ void Com_Init( char *commandLine ) {

com_homepath = Cvar_Get("com_homepath", "", CVAR_INIT);

// Init network before filesystem
NET_Init();

FS_InitFilesystem (); //uses z_malloc
//re.R_InitWorldEffects(); // this doesn't do much but I want to be sure certain variables are intialized.

Expand Down
51 changes: 34 additions & 17 deletions code/qcommon/files.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2685,6 +2685,29 @@ void FS_Which_f( void ) {
Com_Printf( "File not found: \"%s\"\n", filename );
}

/*
============
FS_Restart_f
============
*/
static qboolean FS_CanRestartInPlace( void ) {
int i;
for ( i = 1; i < MAX_FILE_HANDLES; i++ ) {
// If we have an active filehandle for a module that references a zip file we cannot restart.
if ( fsh[i].fileSize ) {
if ( fsh[i].zipFile ) return qfalse;
}
}
return qtrue;
}
static void FS_Restart_f( void ) {
if ( !FS_CanRestartInPlace() ) {
Com_Printf( "^3WARNING: Cannot restart file system due to active file handles for pk3 files inside of modules.\n" );
return;
}
FS_Restart( qtrue );
}

//===========================================================================

static int QDECL paksort( const void *a, const void *b ) {
Expand All @@ -2704,7 +2727,6 @@ Sets fs_gamedir, adds the directory to the head of the path,
then loads the zip headers
================
*/
#define MAX_PAKFILES 1024
static void FS_AddGameDirectory( const char *path, const char *dir ) {
searchpath_t *sp;
int i;
Expand All @@ -2714,7 +2736,6 @@ static void FS_AddGameDirectory( const char *path, const char *dir ) {
char curpath[MAX_OSPATH + 1], *pakfile;
int numfiles;
char **pakfiles;
char *sorted[MAX_PAKFILES];

// this fixes the case where fs_basepath is the same as fs_cdpath
// which happens on full installs
Expand Down Expand Up @@ -2748,20 +2769,13 @@ static void FS_AddGameDirectory( const char *path, const char *dir ) {

pakfiles = Sys_ListFiles( curpath, ".pk3", NULL, &numfiles, qfalse );

// sort them so that later alphabetic matches override
// earlier ones. This makes pak1.pk3 override pak0.pk3
if ( numfiles > MAX_PAKFILES ) {
numfiles = MAX_PAKFILES;
if ( numfiles > 1 ) {
qsort( pakfiles, numfiles, sizeof(char*), paksort );
}
for ( i = 0 ; i < numfiles ; i++ ) {
sorted[i] = pakfiles[i];
}

qsort( sorted, numfiles, sizeof(char*), paksort );

for ( i = 0 ; i < numfiles ; i++ ) {
pakfile = FS_BuildOSPath( path, dir, sorted[i] );
if ( ( pak = FS_LoadZipFile( pakfile, sorted[i] ) ) == 0 )
pakfile = FS_BuildOSPath( path, dir, pakfiles[i] );
if ( ( pak = FS_LoadZipFile( pakfile, pakfiles[i] ) ) == 0 )
continue;
Q_strncpyz(pak->pakPathname, curpath, sizeof(pak->pakPathname));
// store the game name for downloading
Expand Down Expand Up @@ -2819,13 +2833,14 @@ FS_Shutdown
Frees all resources and closes all files
================
*/
void FS_Shutdown( void ) {
void FS_Shutdown( qboolean keepModuleFiles ) {
searchpath_t *p, *next;
int i;

for(i = 0; i < MAX_FILE_HANDLES; i++) {
if (fsh[i].fileSize) {
FS_FCloseFile(i);
if ( !keepModuleFiles ) FS_FCloseFile(i);
else if ( fsh[i].zipFile ) Com_Error(ERR_FATAL, "FS_Shutdown: tried to keep module files when at least one module file is inside of a pak");
}
}

Expand All @@ -2850,6 +2865,7 @@ void FS_Shutdown( void ) {
Cmd_RemoveCommand( "fdir" );
Cmd_RemoveCommand( "touchFile" );
Cmd_RemoveCommand( "which" );
Cmd_RemoveCommand( "fs_restart" );
}

/*
Expand Down Expand Up @@ -2935,6 +2951,7 @@ void FS_Startup( const char *gameName ) {
Cmd_AddCommand ("fdir", FS_NewDir_f );
Cmd_AddCommand ("touchFile", FS_TouchFile_f );
Cmd_AddCommand ("which", FS_Which_f );
Cmd_AddCommand ("fs_restart", FS_Restart_f );

// print the current search paths
FS_Path_f();
Expand Down Expand Up @@ -2998,10 +3015,10 @@ void FS_InitFilesystem( void ) {
FS_Restart
================
*/
void FS_Restart( void ) {
void FS_Restart( qboolean inPlace ) {

// free anything we currently have loaded
FS_Shutdown();
FS_Shutdown( inPlace );

// try to start up normally
FS_Startup( BASEGAME );
Expand Down
4 changes: 3 additions & 1 deletion code/qcommon/qcommon.h
Original file line number Diff line number Diff line change
Expand Up @@ -445,7 +445,9 @@ issues.
qboolean FS_Initialized();

void FS_InitFilesystem (void);
void FS_Shutdown( void );
void FS_Shutdown( qboolean inPlace = qfalse );

void FS_Restart( qboolean inPlace = qfalse );

qboolean FS_ConditionalRestart( void );

Expand Down
2 changes: 1 addition & 1 deletion code/ui/ui_main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -994,7 +994,7 @@ static qboolean UI_RunMenuScript ( const char **args )
if (uiInfo.modList[uiInfo.modIndex].modName)
{
Cvar_Set( "fs_game", uiInfo.modList[uiInfo.modIndex].modName);
extern void FS_Restart( void );
extern void FS_Restart( qboolean inPlace = qfalse );
FS_Restart();
Cbuf_ExecuteText( EXEC_APPEND, "vid_restart;" );
}
Expand Down
14 changes: 6 additions & 8 deletions codemp/cgame/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -160,14 +160,12 @@ elseif(WIN32)
RUNTIME
DESTINATION "${JKAInstallDir}/OpenJK"
COMPONENT ${JKAMPCoreComponent})
if (WIN64)
# Don't do this on 32-bit Windows to avoid overwriting
# vanilla JKA's DLLs
install(TARGETS ${MPCGame}
RUNTIME
DESTINATION "${JKAInstallDir}/base"
COMPONENT ${JKAMPCoreComponent})
endif()

# Use OpenJK modules as default
install(TARGETS ${MPCGame}
RUNTIME
DESTINATION "${JKAInstallDir}/base"
COMPONENT ${JKAMPCoreComponent})
else()
install(TARGETS ${MPCGame}
LIBRARY
Expand Down
4 changes: 3 additions & 1 deletion codemp/client/cl_input.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -922,7 +922,9 @@ CL_MouseEvent
=================
*/
void CL_MouseEvent( int dx, int dy, int time ) {
if (g_clAutoMapMode && cls.cgameStarted)
if (cls.cursorActive) {
CL_UpdateCursorPosition( dx, dy );
} else if (g_clAutoMapMode && cls.cgameStarted)
{ //automap input
autoMapInput_t *data = (autoMapInput_t *)cl.mSharedMemory;

Expand Down
11 changes: 7 additions & 4 deletions codemp/client/cl_keys.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1361,25 +1361,28 @@ void CL_KeyDownEvent( int key, unsigned time )
return;
}

UIVM_KeyEvent( key, qtrue );
if ( !cls.cursorActive ) UIVM_KeyEvent( key, qtrue );
return;
}

// send the bound action
CL_ParseBinding( key, qtrue, time );
if ( !cls.cursorActive ) CL_ParseBinding( key, qtrue, time );

// distribute the key down event to the appropriate handler
// console
if ( Key_GetCatcher() & KEYCATCH_CONSOLE )
Console_Key( key );
else if ( cls.cursorActive ) {
CL_CursorButton( key );
}
// ui
else if ( Key_GetCatcher() & KEYCATCH_UI ) {
if ( cls.uiStarted )
if ( cls.uiStarted && !cls.cursorActive )
UIVM_KeyEvent( key, qtrue );
}
// cgame
else if ( Key_GetCatcher() & KEYCATCH_CGAME ) {
if ( cls.cgameStarted )
if ( cls.cgameStarted && !cls.cursorActive )
CGVM_KeyEvent( key, qtrue );
}
// chatbox
Expand Down
Loading

0 comments on commit 065d329

Please sign in to comment.