/* ==================== StudioGetAnim ==================== */ static mstudioanim_t *Mod_StudioGetAnim( model_t *m_pSubModel, mstudioseqdesc_t *pseqdesc ) { mstudioseqgroup_t *pseqgroup; fs_offset_t filesize; byte *buf; cache_user_t *paSequences; pseqgroup = (mstudioseqgroup_t *)((byte *)mod_studiohdr + mod_studiohdr->seqgroupindex) + pseqdesc->seqgroup; if( pseqdesc->seqgroup == 0 ) return (mstudioanim_t *)((byte *)mod_studiohdr + pseqdesc->animindex); paSequences = (cache_user_t *)m_pSubModel->submodels; if( paSequences == NULL ) { paSequences = (cache_user_t *)Mem_Alloc( com_studiocache, MAXSTUDIOGROUPS * sizeof( cache_user_t )); m_pSubModel->submodels = (void *)paSequences; } // check for already loaded if( !paSequences[pseqdesc->seqgroup].data ) { string filepath, modelname, modelpath; FS_FileBase( m_pSubModel->name, modelname ); FS_ExtractFilePath( m_pSubModel->name, modelpath ); Q_snprintf( filepath, sizeof( filepath ), "%s/%s%i%i.mdl", modelpath, modelname, pseqdesc->seqgroup / 10, pseqdesc->seqgroup % 10 ); buf = FS_LoadFile( filepath, &filesize, false ); if( !buf || !filesize ) Host_Error( "StudioGetAnim: can't load %s\n", filepath ); else if( IDSEQGRPHEADER != *(uint *)buf ) Host_Error( "StudioGetAnim: %s is corrupted\n", filepath ); MsgDev( D_INFO, "loading: %s\n", filepath ); paSequences[pseqdesc->seqgroup].data = Mem_Alloc( com_studiocache, filesize ); Q_memcpy( paSequences[pseqdesc->seqgroup].data, buf, (size_t)filesize ); Mem_Free( buf ); } return (mstudioanim_t *)((byte *)paSequences[pseqdesc->seqgroup].data + pseqdesc->animindex); }
/* ================= Host_InitCommon ================= */ void Host_InitCommon( const char* moduleName, const char* cmdLine, const char *progname, qboolean bChangeGame ) { char dev_level[4]; char szTemp[MAX_SYSPATH]; string szRootPath; #ifdef _WIN32 MEMORYSTATUS lpBuffer; lpBuffer.dwLength = sizeof( MEMORYSTATUS ); GlobalMemoryStatus( &lpBuffer ); #endif #ifndef __ANDROID__ if( !(SDL_GetBasePath()) ) Sys_Error( "couldn't determine current directory" ); Q_strncpy(host.rootdir, SDL_GetBasePath(), sizeof(host.rootdir)); if( host.rootdir[Q_strlen( host.rootdir ) - 1] == '/' ) host.rootdir[Q_strlen( host.rootdir ) - 1] = 0; #else Q_strncpy(host.rootdir, GAMEPATH, sizeof(host.rootdir)); #endif #ifdef _WIN32 host.oldFilter = SetUnhandledExceptionFilter( Sys_Crash ); host.hInst = GetModuleHandle( NULL ); #endif host.change_game = bChangeGame; host.state = HOST_INIT; // initialzation started host.developer = host.old_developer = 0; CRT_Init(); // init some CRT functions // some commands may turn engine into infinity loop, // e.g. xash.exe +game xash -game xash // so we clearing all cmd_args, but leave dbg states as well if( cmdLine ) Sys_ParseCommandLine( cmdLine ); #ifdef _WIN32 SetErrorMode( SEM_FAILCRITICALERRORS ); // no abort/retry/fail errors #endif host.mempool = Mem_AllocPool( "Zone Engine" ); if( Sys_CheckParm( "-console" )) host.developer = 1; if( Sys_CheckParm( "-dev" )) { if( Sys_GetParmFromCmdLine( "-dev", dev_level )) { if( Q_isdigit( dev_level )) host.developer = abs( Q_atoi( dev_level )); else host.developer++; // -dev == 1, -dev -console == 2 } else host.developer++; // -dev == 1, -dev -console == 2 } host.type = HOST_NORMAL; // predict state host.con_showalways = true; #ifdef PANDORA if( Sys_CheckParm( "-noshouldermb" )) noshouldermb = 1; #endif #ifdef __ANDROID__ if (chdir(host.rootdir) == 0) MsgDev(D_INFO,"%s is working directory now",host.rootdir); else MsgDev(D_ERROR,"%s is not exists",host.rootdir); #else // we can specified custom name, from Sys_NewInstance if( SDL_GetBasePath() && !host.change_game ) { Q_strncpy( szTemp, SDL_GetBasePath(), sizeof(szTemp) ); FS_FileBase( szTemp, SI.ModuleName ); } if(moduleName) Q_strncpy(SI.ModuleName, moduleName, sizeof(SI.ModuleName)); FS_ExtractFilePath( SI.ModuleName, szRootPath ); if( Q_stricmp( host.rootdir, szRootPath )) { Q_strncpy( host.rootdir, szRootPath, sizeof( host.rootdir )); #ifdef _WIN32 SetCurrentDirectory( host.rootdir ); #else chdir( host.rootdir ); #endif } #endif if( SI.ModuleName[0] == '#' ) host.type = HOST_DEDICATED; // determine host type if( progname[0] == '#' ) { Q_strncpy( SI.ModuleName, progname + 1, sizeof( SI.ModuleName )); host.type = HOST_DEDICATED; } else Q_strncpy( SI.ModuleName, progname, sizeof( SI.ModuleName )); if( host.type == HOST_DEDICATED ) { // check for duplicate dedicated server host.hMutex = SDL_CreateMutex( ); if( !host.hMutex ) { MSGBOX( "Dedicated server already running" ); Sys_Quit(); return; } Sys_MergeCommandLine( cmdLine ); SDL_DestroyMutex( host.hMutex ); host.hMutex = SDL_CreateSemaphore( 0 ); if( host.developer < 3 ) host.developer = 3; // otherwise we see empty console } else { // don't show console as default if( host.developer < D_WARN ) host.con_showalways = false; } host.old_developer = host.developer; Con_CreateConsole(); // first text message into console or log MsgDev( D_NOTE, "Sys_LoadLibrary: Loading xash.dll - ok\n" ); // startup cmds and cvars subsystem Cmd_Init(); Cvar_Init(); // share developer level across all dlls Q_snprintf( dev_level, sizeof( dev_level ), "%i", host.developer ); Cvar_Get( "developer", dev_level, CVAR_INIT, "current developer level" ); Cmd_AddCommand( "exec", Host_Exec_f, "execute a script file" ); Cmd_AddCommand( "memlist", Host_MemStats_f, "prints memory pool information" ); FS_Init(); Image_Init(); Sound_Init(); FS_LoadGameInfo( NULL ); Q_strncpy( host.gamefolder, GI->gamefolder, sizeof( host.gamefolder )); if( GI->secure ) { // clear all developer levels when game is protected Cvar_FullSet( "developer", "0", CVAR_INIT ); host.developer = host.old_developer = 0; host.con_showalways = false; } HPAK_Init(); IN_Init(); Key_Init(); }