44
55#include " stdafx.h"
66#include " EngineAPI.h"
7+ #include " XR_IOConsole.h"
78
89#include " xrCore/ModuleLookup.hpp"
910
10- extern xr_token* vid_quality_token;
11+ extern xr_vector< xr_token> vid_quality_token;
1112
1213// ////////////////////////////////////////////////////////////////////
1314// Construction/Destruction
@@ -32,25 +33,20 @@ CEngineAPI::CEngineAPI()
3233
3334CEngineAPI::~CEngineAPI ()
3435{
35- // destroy quality token here
36- if (vid_quality_token)
37- {
38- xr_free (vid_quality_token);
39- vid_quality_token = NULL ;
40- }
36+ vid_quality_token.clear ();
4137}
4238
43- extern u32 renderer_value; // con cmd
44-
4539bool is_enough_address_space_available ()
4640{
4741 SYSTEM_INFO system_info;
4842 GetSystemInfo (&system_info);
4943 return (*(u32 *)&system_info.lpMaximumApplicationAddress ) > 0x90000000 ;
5044}
5145
52- void CEngineAPI::InitializeNotDedicated ()
46+ void CEngineAPI::SetupCurrentRenderer ()
5347{
48+ GEnv.CurrentRenderer = -1 ;
49+
5450 if (psDeviceFlags.test (rsR4))
5551 {
5652 if (hRenderR4->exist ())
@@ -87,30 +83,51 @@ void CEngineAPI::InitializeNotDedicated()
8783 GEnv.SetupCurrentRenderer = GEnv.SetupR2 ;
8884 }
8985 else
86+ {
9087 psDeviceFlags.set (rsR2, false );
88+ psDeviceFlags.set (rsR1, true );
89+ }
90+ }
91+
92+ if (psDeviceFlags.test (rsR1))
93+ {
94+ if (hRenderR2->exist ())
95+ {
96+ GEnv.CurrentRenderer = 1 ;
97+ GEnv.SetupCurrentRenderer = GEnv.SetupR1 ;
98+ }
99+ else
100+ psDeviceFlags.set (rsR1, false );
91101 }
92102}
93103
94104void CEngineAPI::InitializeRenderers ()
95- {
96- if (!GEnv.isDedicatedServer )
97- InitializeNotDedicated ();
105+ {
106+ SetupCurrentRenderer ();
98107
99- if (!psDeviceFlags.test (rsR4|rsR3|rsR2))
108+ if (GEnv.SetupCurrentRenderer == nullptr
109+ && vid_quality_token[0 ].id != -1 )
100110 {
101- R_ASSERT (hRenderR1);
102- renderer_value = 0 ; // con cmd
103- GEnv.CurrentRenderer = 1 ;
104- GEnv.SetupCurrentRenderer = GEnv.SetupR1 ;
111+ // if engine failed to load renderer
112+ // but there is at least one available
113+ // then try again
114+ string32 buf;
115+ xr_sprintf (buf, " renderer %s" , vid_quality_token[0 ].name );
116+ Console->Execute (buf);
117+
118+ // Second attempt
119+ InitializeRenderers ();
105120 }
106121
107122 // ask current renderer to setup GlobalEnv
108- R_ASSERT (GEnv.SetupCurrentRenderer );
123+ R_ASSERT2 (GEnv.SetupCurrentRenderer , " Can't setup renderer " );
109124 GEnv.SetupCurrentRenderer ();
110125}
111126
112127void CEngineAPI::Initialize (void )
113128{
129+ InitializeRenderers ();
130+
114131 hGame = std::make_unique<XRay::Module>(" xrGame" );
115132 R_ASSERT2 (hGame, " Game DLL raised exception during loading or there is no game DLL at all" );
116133
@@ -159,20 +176,18 @@ void CEngineAPI::CreateRendererList()
159176{
160177 hRenderR1 = std::make_unique<XRay::Module>(" xrRender_R1" );
161178
162- if (GEnv.isDedicatedServer )
179+ xr_vector<xr_token> modes;
180+ // load only R1 for dedicated server,
181+ // but if it's unavailable, then try other renderers
182+ if (GEnv.isDedicatedServer && hRenderR1->exist ())
163183 {
164- vid_quality_token = xr_alloc<xr_token>(2 );
165-
166- vid_quality_token[0 ].id = 0 ;
167- vid_quality_token[0 ].name = xr_strdup (" renderer_r1" );
168-
169- vid_quality_token[1 ].id = -1 ;
170- vid_quality_token[1 ].name = nullptr ;
171-
184+ modes.push_back (xr_token (" renderer_r1" , 0 ));
185+ modes.push_back (xr_token (nullptr , -1 ));
186+ vid_quality_token = std::move (modes);
172187 return ;
173188 }
174189
175- if (vid_quality_token != nullptr )
190+ if (!vid_quality_token. empty () )
176191 return ;
177192
178193 // Hide "d3d10.dll not found" message box for XP
@@ -185,127 +200,40 @@ void CEngineAPI::CreateRendererList()
185200 // Restore error handling
186201 SetErrorMode (0 );
187202
188- bool bSupports_r2 = false ;
189- bool bSupports_r2_5 = false ;
190- bool bSupports_r3 = false ;
191- bool bSupports_r4 = false ;
192-
193- if (strstr (Core.Params , " -perfhud_hack" ))
203+ if (hRenderR1->exist ())
194204 {
195- bSupports_r2 = true ;
196- bSupports_r2_5 = true ;
197- bSupports_r3 = true ;
198- bSupports_r4 = true ;
205+ modes.push_back (xr_token (" renderer_r1" , 0 ));
199206 }
200- else
207+
208+ if (hRenderR2->exist ())
201209 {
202- if (hRenderR2->exist ())
203- {
204- bSupports_r2 = true ;
205- if (GEnv.CheckR2 && GEnv.CheckR2 ())
206- bSupports_r2_5 = true ;
207- }
208- if (hRenderR3->exist ())
209- {
210- if (GEnv.CheckR3 && GEnv.CheckR3 ())
211- bSupports_r3 = true ;
212- else
213- hRenderR3->close ();
214- }
215- if (hRenderR4->exist ())
216- {
217- if (GEnv.CheckR4 && GEnv.CheckR4 ())
218- bSupports_r4 = true ;
219- else
220- hRenderR4->close ();
221- }
210+ modes.push_back (xr_token (" renderer_r2a" , 1 ));
211+ modes.push_back (xr_token (" renderer_r2" , 2 ));
212+ if (GEnv.CheckR2 && GEnv.CheckR2 ())
213+ modes.push_back (xr_token (" renderer_r2.5" , 3 ));
222214 }
223215
224- bool proceed = true ;
225- xr_vector<pcstr> tmp;
226- tmp.push_back (" renderer_r1" );
227- if (proceed &= bSupports_r2, proceed)
216+ if (hRenderR3->exist ())
228217 {
229- tmp.push_back (" renderer_r2a" );
230- tmp.push_back (" renderer_r2" );
218+ if (GEnv.CheckR3 && GEnv.CheckR3 ())
219+ modes.push_back (xr_token (" renderer_r3" , 4 ));
220+ else
221+ hRenderR3->close ();
231222 }
232- if (proceed &= bSupports_r2_5, proceed)
233- tmp.push_back (" renderer_r2.5" );
234- if (proceed &= bSupports_r3, proceed)
235- tmp.push_back (" renderer_r3" );
236- if (proceed &= bSupports_r4, proceed)
237- tmp.push_back (" renderer_r4" );
238- u32 _cnt = tmp.size () + 1 ;
239- vid_quality_token = xr_alloc<xr_token>(_cnt);
240-
241- vid_quality_token[_cnt - 1 ].id = -1 ;
242- vid_quality_token[_cnt - 1 ].name = NULL ;
243-
244- Msg (" Available render modes[%d]:" , tmp.size ());
245- for (u32 i = 0 ; i < tmp.size (); ++i)
223+
224+ if (hRenderR4->exist ())
246225 {
247- vid_quality_token[i].id = i;
248- vid_quality_token[i].name = tmp[i];
249- Msg (" [%s]" , tmp[i]);
226+ if (GEnv.CheckR4 && GEnv.CheckR4 ())
227+ modes.push_back (xr_token (" renderer_r4" , 5 ));
228+ else
229+ hRenderR4->close ();
250230 }
231+ modes.push_back (xr_token (nullptr , -1 ));
251232
252- /*
253- if(vid_quality_token != NULL) return;
254-
255- D3DCAPS9 caps;
256- CHW _HW;
257- _HW.CreateD3D ();
258- _HW.pD3D->GetDeviceCaps (D3DADAPTER_DEFAULT,D3DDEVTYPE_HAL,&caps);
259- _HW.DestroyD3D ();
260- u16 ps_ver_major = u16 ( u32(u32(caps.PixelShaderVersion)&u32(0xf << 8ul))>>8 );
261-
262- xr_vector<LPCSTR> _tmp;
263- u32 i = 0;
264- for(; i<5; ++i)
265- {
266- bool bBreakLoop = false;
267- switch (i)
268- {
269- case 3: //"renderer_r2.5"
270- if (ps_ver_major < 3)
271- bBreakLoop = true;
272- break;
273- case 4: //"renderer_r_dx10"
274- bBreakLoop = true;
275- break;
276- default: ;
277- }
233+ Msg (" Available render modes[%d]:" , modes.size ());
234+ for (auto & mode : modes)
235+ if (mode.name )
236+ Log (mode.name );
278237
279- if (bBreakLoop) break;
280-
281- _tmp.push_back (NULL);
282- LPCSTR val = NULL;
283- switch (i)
284- {
285- case 0: val ="renderer_r1"; break;
286- case 1: val ="renderer_r2a"; break;
287- case 2: val ="renderer_r2"; break;
288- case 3: val ="renderer_r2.5"; break;
289- case 4: val ="renderer_r_dx10"; break; // -)
290- }
291- _tmp.back() = xr_strdup(val);
292- }
293- u32 _cnt = _tmp.size()+1;
294- vid_quality_token = xr_alloc<xr_token>(_cnt);
295-
296- vid_quality_token[_cnt-1].id = -1;
297- vid_quality_token[_cnt-1].name = NULL;
298-
299- #ifdef DEBUG
300- Msg("Available render modes[%d]:",_tmp.size());
301- #endif // DEBUG
302- for(u32 i=0; i<_tmp.size();++i)
303- {
304- vid_quality_token[i].id = i;
305- vid_quality_token[i].name = _tmp[i];
306- #ifdef DEBUG
307- Msg ("[%s]",_tmp[i]);
308- #endif // DEBUG
309- }
310- */
238+ vid_quality_token = std::move (modes);
311239}
0 commit comments