-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathmain.cpp
More file actions
153 lines (122 loc) · 4.07 KB
/
Copy pathmain.cpp
File metadata and controls
153 lines (122 loc) · 4.07 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
#include "app.h"
#include "tier0/icommandline.h"
#include "appframework/appframework.h"
#include "materialsystem/imaterialsystem.h"
#include "istudiorender.h"
#include "vphysics_interface.h"
#include "Datacache/imdlcache.h"
#include "datacache/idatacache.h"
#include "filesystem_init.h"
#include "tier1/tier1.h"
#include "tier2/tier2.h"
#include "memdbgoff.h"
IFileSystem* g_pFileSystem;
IStudioRender* g_pStudioRender;
IMDLCache* g_pMDLCache;
class CSteamAppLoader : public CSteamAppSystemGroup
{
public:
virtual bool Create();
virtual bool PreInit();
virtual int Main();
virtual void PostShutdown() {}
virtual void Destroy();
};
int main (int argc, char **argv)
{
CommandLine()->CreateCmdLine( argc, argv );
CSteamAppLoader smaugsteamapp;
CSteamApplication steamapp( &smaugsteamapp );
return steamapp.Run();
}
// Prep ourselves for app system loading
bool CSteamAppLoader::PreInit()
{
// Set up the filesystem
// Make sure we always at least have something?
// Otherwise the next step will close the program
if (!CommandLine()->FindParm("-game"))
CommandLine()->AppendParm("-game", "../hl2");
// Find the route to our gameinfo file
CFSSteamSetupInfo steamInfo;
steamInfo.m_pDirectoryName = NULL;
steamInfo.m_bOnlyUseDirectoryName = false;
steamInfo.m_bToolsMode = true;
steamInfo.m_bSetSteamDLLPath = true;
steamInfo.m_bSteam = g_pFileSystem->IsSteam();
if (FileSystem_SetupSteamEnvironment(steamInfo) != FS_OK)
return false;
// Mount the game
CFSMountContentInfo fsInfo;
fsInfo.m_pFileSystem = g_pFileSystem;
fsInfo.m_bToolsMode = true;
fsInfo.m_pDirectoryName = steamInfo.m_GameInfoPath;
if (FileSystem_MountContent(fsInfo) != FS_OK)
return false;
// Finally, load the search paths for the "GAME" path.
CFSSearchPathsInit searchPathsInit;
searchPathsInit.m_pDirectoryName = steamInfo.m_GameInfoPath;
searchPathsInit.m_pFileSystem = fsInfo.m_pFileSystem;
if (FileSystem_LoadSearchPaths(searchPathsInit) != FS_OK)
return false;
// Add platform to our search path
char platform[MAX_PATH];
Q_strncpy(platform, steamInfo.m_GameInfoPath, MAX_PATH);
Q_StripTrailingSlash(platform);
Q_strncat(platform, "/../platform", MAX_PATH, MAX_PATH);
fsInfo.m_pFileSystem->AddSearchPath(platform, "PLATFORM");
MathLib_Init();
g_pMaterialSystem->SetAdapter(0, 0);
return true;
}
// Load up all our app systems
bool CSteamAppLoader::Create()
{
AppSystemInfo_t appSystems[] =
{
{ "materialsystem.dll", MATERIAL_SYSTEM_INTERFACE_VERSION },
{ "studiorender.dll", STUDIO_RENDER_INTERFACE_VERSION },
{ "vphysics.dll", VPHYSICS_INTERFACE_VERSION }, // Annoyingly, we need vphyiscs as well :P
{ "datacache.dll", DATACACHE_INTERFACE_VERSION },
{ "datacache.dll", MDLCACHE_INTERFACE_VERSION },
{ "", "" } // Required to terminate the list
};
if (!AddSystems(appSystems))
return false;
CreateInterfaceFn factory = GetFactory();
ConnectTier1Libraries(&factory, 1);
ConnectTier2Libraries(&factory, 1);
g_pFileSystem = (IFileSystem*)FindSystem(FILESYSTEM_INTERFACE_VERSION);
g_pMaterialSystem = (IMaterialSystem*)FindSystem(MATERIAL_SYSTEM_INTERFACE_VERSION);
g_pStudioRender = (IStudioRender*)FindSystem(STUDIO_RENDER_INTERFACE_VERSION);
g_pMDLCache = (IMDLCache*)FindSystem(MDLCACHE_INTERFACE_VERSION);
if (!g_pFileSystem || !g_pMaterialSystem || !g_pStudioRender || !g_pMDLCache)
{
Error("Unable to load required library interface!\n");
return false;
}
g_pMaterialSystem->SetShaderAPI("shaderapidx9");
g_pMaterialSystem->Connect(factory);
// Must be done after material system is connected up!
g_pMaterialSystemHardwareConfig = (IMaterialSystemHardwareConfig*)FindSystem(MATERIALSYSTEM_HARDWARECONFIG_INTERFACE_VERSION);
return true;
}
// Disconnect our app systems
void CSteamAppLoader::Destroy()
{
DisconnectTier1Libraries();
DisconnectTier2Libraries();
g_pFileSystem = NULL;
g_pMaterialSystem = NULL;
}
int CSteamAppLoader::Main()
{
g_pMaterialSystem->ModInit();
// Starts up the app and runs the main loop
CImGuiSourceApp* app = new CImGuiSourceApp;
app->Init();
app->Destroy();
delete app;
g_pMaterialSystem->ModShutdown();
return 0;
}