forked from etternagame/etterna
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathStepMania.cpp
1600 lines (1397 loc) · 48.1 KB
/
StepMania.cpp
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
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#include "global.h"
#include "StepMania.h"
// Rage global classes
#include "RageLog.h"
#include "RageTextureManager.h"
#include "RageSoundManager.h"
#include "GameSoundManager.h"
#include "RageInput.h"
#include "RageTimer.h"
#include "RageMath.h"
#include "RageDisplay.h"
#include "RageThreads.h"
#include "LocalizedString.h"
#include "arch/ArchHooks/ArchHooks.h"
#include "arch/LoadingWindow/LoadingWindow.h"
#include "arch/Dialog/Dialog.h"
#include <ctime>
#include "ProductInfo.h"
#include "Screen.h"
#include "InputEventPlus.h"
#include "ScreenDimensions.h"
#include "CodeDetector.h"
#include "CommonMetrics.h"
#include "Game.h"
#include "RageSurface.h"
#include "RageSurface_Load.h"
#include "CommandLineActions.h"
#if !defined(SUPPORT_OPENGL) && !defined(SUPPORT_D3D)
#define SUPPORT_OPENGL
#endif
// StepMania global classes
#include "ThemeManager.h"
#include "NoteSkinManager.h"
#include "PrefsManager.h"
#include "Song.h"
#include "SongManager.h"
#include "CharacterManager.h"
#include "GameState.h"
#include "AnnouncerManager.h"
#include "ProfileManager.h"
#include "MemoryCardManager.h"
#include "ScreenManager.h"
#include "LuaManager.h"
#include "GameManager.h"
#include "FontManager.h"
#include "InputFilter.h"
#include "InputMapper.h"
#include "InputQueue.h"
#include "SongCacheIndex.h"
#include "BannerCache.h"
#include "FilterManager.h"
#include "ScoreManager.h"
//#include "BackgroundCache.h"
#include "RageFileManager.h"
#include "ModelManager.h"
#include "CryptManager.h"
#include "NetworkSyncManager.h"
#include "MessageManager.h"
#include "StatsManager.h"
#include "GameLoop.h"
#include "SpecialFiles.h"
#include "Profile.h"
#include "ActorUtil.h"
#include "ver.h"
#if defined(WIN32)
#include <windows.h>
#endif
void ShutdownGame();
bool HandleGlobalInputs( const InputEventPlus &input );
void HandleInputEvents(float fDeltaTime);
static Preference<bool> g_bAllowMultipleInstances( "AllowMultipleInstances", false );
void StepMania::GetPreferredVideoModeParams( VideoModeParams ¶msOut )
{
// resolution handling code that probably needs fixing
int iWidth = PREFSMAN->m_iDisplayWidth;
if( PREFSMAN->m_bWindowed )
{
//float fRatio = PREFSMAN->m_iDisplayHeight;
//iWidth = PREFSMAN->m_iDisplayHeight * fRatio;
iWidth = static_cast<int>(ceilf(PREFSMAN->m_iDisplayHeight * PREFSMAN->m_fDisplayAspectRatio));
// ceilf causes the width to come out odd when it shouldn't.
// 576 * 1.7778 = 1024.0128, which is rounded to 1025. -Kyz
iWidth-= iWidth % 2;
}
paramsOut = VideoModeParams(
PREFSMAN->m_bWindowed,
iWidth,
PREFSMAN->m_iDisplayHeight,
PREFSMAN->m_iDisplayColorDepth,
PREFSMAN->m_iRefreshRate,
PREFSMAN->m_bVsync,
PREFSMAN->m_bInterlaced,
PREFSMAN->m_bSmoothLines,
PREFSMAN->m_bTrilinearFiltering,
PREFSMAN->m_bAnisotropicFiltering,
CommonMetrics::WINDOW_TITLE,
THEME->GetPathG("Common","window icon"),
PREFSMAN->m_bPAL,
PREFSMAN->m_fDisplayAspectRatio
);
}
static LocalizedString COLOR ("StepMania","color");
static LocalizedString TEXTURE ("StepMania","texture");
static LocalizedString WINDOWED ("StepMania","Windowed");
static LocalizedString FULLSCREEN ("StepMania","Fullscreen");
static LocalizedString ANNOUNCER_ ("StepMania","Announcer");
static LocalizedString VSYNC ("StepMania","Vsync");
static LocalizedString NO_VSYNC ("StepMania","NoVsync");
static LocalizedString SMOOTH_LINES ("StepMania","SmoothLines");
static LocalizedString NO_SMOOTH_LINES ("StepMania","NoSmoothLines");
static RString GetActualGraphicOptionsString()
{
const VideoModeParams ¶ms = (*DISPLAY->GetActualVideoModeParams());
RString sFormat = "%s %s %dx%d %d "+COLOR.GetValue()+" %d "+TEXTURE.GetValue()+" %dHz %s %s";
RString sLog = ssprintf( sFormat,
DISPLAY->GetApiDescription().c_str(),
(params.windowed? WINDOWED : FULLSCREEN).GetValue().c_str(),
params.width,
params.height,
params.bpp,
(int)PREFSMAN->m_iTextureColorDepth,
params.rate,
(params.vsync? VSYNC : NO_VSYNC).GetValue().c_str(),
(PREFSMAN->m_bSmoothLines? SMOOTH_LINES : NO_SMOOTH_LINES).GetValue().c_str() );
return sLog;
}
static void StoreActualGraphicOptions()
{
/* Store the settings that RageDisplay was actually able to use so that
* we don't go through the process of auto-detecting a usable video mode
* every time. */
const VideoModeParams ¶ms = (*DISPLAY->GetActualVideoModeParams());
PREFSMAN->m_bWindowed.Set( params.windowed );
/* If we're windowed, we may have tweaked the width based on the aspect ratio.
* Don't save this new value over the preferred value. */
if( !PREFSMAN->m_bWindowed )
{
PREFSMAN->m_iDisplayWidth .Set( params.width );
PREFSMAN->m_iDisplayHeight .Set( params.height );
}
PREFSMAN->m_iDisplayColorDepth .Set( params.bpp );
if( PREFSMAN->m_iRefreshRate != REFRESH_DEFAULT )
PREFSMAN->m_iRefreshRate.Set( params.rate );
PREFSMAN->m_bVsync .Set( params.vsync );
Dialog::SetWindowed( params.windowed );
}
static RageDisplay *CreateDisplay();
bool StepMania::GetHighResolutionTextures()
{
switch( PREFSMAN->m_HighResolutionTextures )
{
default:
case HighResolutionTextures_Auto:
{
int height = PREFSMAN->m_iDisplayHeight;
return height > THEME->GetMetricI("Common", "ScreenHeight");
}
case HighResolutionTextures_ForceOn:
return true;
case HighResolutionTextures_ForceOff:
return false;
}
}
static void update_centering()
{
DISPLAY->ChangeCentering(
PREFSMAN->m_iCenterImageTranslateX, PREFSMAN->m_iCenterImageTranslateY,
PREFSMAN->m_fCenterImageAddWidth, PREFSMAN->m_fCenterImageAddHeight);
}
static void StartDisplay()
{
if( DISPLAY != NULL )
return; // already started
DISPLAY = CreateDisplay();
update_centering();
TEXTUREMAN = new RageTextureManager;
TEXTUREMAN->SetPrefs(
RageTextureManagerPrefs(
PREFSMAN->m_iTextureColorDepth,
PREFSMAN->m_iMovieColorDepth,
PREFSMAN->m_bDelayedTextureDelete,
PREFSMAN->m_iMaxTextureResolution,
StepMania::GetHighResolutionTextures(),
PREFSMAN->m_bForceMipMaps
)
);
MODELMAN = new ModelManager;
MODELMAN->SetPrefs(
ModelManagerPrefs(
PREFSMAN->m_bDelayedModelDelete
)
);
}
void StepMania::ApplyGraphicOptions()
{
bool bNeedReload = false;
VideoModeParams params;
GetPreferredVideoModeParams( params );
RString sError = DISPLAY->SetVideoMode( params, bNeedReload );
if( sError != "" )
RageException::Throw( "%s", sError.c_str() );
update_centering();
bNeedReload |= TEXTUREMAN->SetPrefs(
RageTextureManagerPrefs(
PREFSMAN->m_iTextureColorDepth,
PREFSMAN->m_iMovieColorDepth,
PREFSMAN->m_bDelayedTextureDelete,
PREFSMAN->m_iMaxTextureResolution,
StepMania::GetHighResolutionTextures(),
PREFSMAN->m_bForceMipMaps
)
);
bNeedReload |= MODELMAN->SetPrefs(
ModelManagerPrefs(
PREFSMAN->m_bDelayedModelDelete
)
);
if( bNeedReload )
TEXTUREMAN->ReloadAll();
StoreActualGraphicOptions();
if( SCREENMAN )
SCREENMAN->SystemMessage( GetActualGraphicOptionsString() );
// Give the input handlers a chance to re-open devices as necessary.
INPUTMAN->WindowReset();
}
static bool CheckVideoDefaultSettings();
void StepMania::ResetPreferences()
{
PREFSMAN->ResetToFactoryDefaults();
SOUNDMAN->SetMixVolume();
CheckVideoDefaultSettings();
ApplyGraphicOptions();
}
/* Shutdown all global singletons. Note that this may be called partway through
* initialization, due to an object failing to initialize, in which case some of
* these may still be NULL. */
void ShutdownGame()
{
/* First, tell SOUNDMAN that we're shutting down. This signals sound drivers to
* stop sounds, which we want to do before any threads that may have started sounds
* are closed; this prevents annoying DirectSound glitches and delays. */
if( SOUNDMAN )
SOUNDMAN->Shutdown();
SAFE_DELETE( SCREENMAN );
SAFE_DELETE( STATSMAN );
SAFE_DELETE( MESSAGEMAN );
SAFE_DELETE( NSMAN );
/* Delete INPUTMAN before the other INPUTFILTER handlers, or an input
* driver may try to send a message to INPUTFILTER after we delete it. */
SAFE_DELETE( INPUTMAN );
SAFE_DELETE( INPUTQUEUE );
SAFE_DELETE( INPUTMAPPER );
SAFE_DELETE( INPUTFILTER );
SAFE_DELETE( MODELMAN );
SAFE_DELETE( PROFILEMAN ); // PROFILEMAN needs the songs still loaded
SAFE_DELETE( CHARMAN );
SAFE_DELETE( CRYPTMAN );
SAFE_DELETE( MEMCARDMAN );
SAFE_DELETE( SONGMAN );
SAFE_DELETE( BANNERCACHE );
//SAFE_DELETE( BACKGROUNDCACHE );
SAFE_DELETE( SONGINDEX );
SAFE_DELETE( SOUND ); // uses GAMESTATE, PREFSMAN
SAFE_DELETE( PREFSMAN );
SAFE_DELETE( GAMESTATE );
SAFE_DELETE( GAMEMAN );
SAFE_DELETE( NOTESKIN );
SAFE_DELETE( THEME );
SAFE_DELETE( ANNOUNCER );
SAFE_DELETE( SOUNDMAN );
SAFE_DELETE( FONT );
SAFE_DELETE( TEXTUREMAN );
SAFE_DELETE( DISPLAY );
Dialog::Shutdown();
SAFE_DELETE( LOG );
SAFE_DELETE( FILEMAN );
SAFE_DELETE( LUA );
SAFE_DELETE( HOOKS );
}
static void HandleException( const RString &sError )
{
if( g_bAutoRestart )
HOOKS->RestartProgram();
// Shut down first, so we exit graphics mode before trying to open a dialog.
ShutdownGame();
// Throw up a pretty error dialog.
Dialog::Error( sError );
Dialog::Shutdown(); // Shut it back down.
}
void StepMania::ResetGame()
{
GAMESTATE->Reset();
if( !THEME->DoesThemeExist( THEME->GetCurThemeName() ) )
{
RString sGameName = GAMESTATE->GetCurrentGame()->m_szName;
if( !THEME->DoesThemeExist(sGameName) )
sGameName = PREFSMAN->m_sDefaultTheme; // was previously "default" -aj
THEME->SwitchThemeAndLanguage( sGameName, THEME->GetCurLanguage(), PREFSMAN->m_bPseudoLocalize );
TEXTUREMAN->DoDelayedDelete();
}
PREFSMAN->SavePrefsToDisk();
}
ThemeMetric<RString> INITIAL_SCREEN ("Common","InitialScreen");
RString StepMania::GetInitialScreen()
{
if(PREFSMAN->m_sTestInitialScreen.Get() != "" &&
SCREENMAN->IsScreenNameValid(PREFSMAN->m_sTestInitialScreen))
{
return PREFSMAN->m_sTestInitialScreen;
}
RString screen_name= INITIAL_SCREEN.GetValue();
if(!SCREENMAN->IsScreenNameValid(screen_name))
{
screen_name= "ScreenInitialScreenIsInvalid";
}
return screen_name;
}
ThemeMetric<RString> SELECT_MUSIC_SCREEN ("Common","SelectMusicScreen");
RString StepMania::GetSelectMusicScreen()
{
return SELECT_MUSIC_SCREEN.GetValue();
}
#if defined(WIN32)
static Preference<int> g_iLastSeenMemory( "LastSeenMemory", 0 );
#endif
static void AdjustForChangedSystemCapabilities()
{
#if defined(WIN32)
// Has the amount of memory changed?
MEMORYSTATUS mem;
GlobalMemoryStatus(&mem);
const int Memory = mem.dwTotalPhys / (1024*1024);
if( g_iLastSeenMemory == Memory )
return;
LOG->Trace( "Memory changed from %i to %i; settings changed", g_iLastSeenMemory.Get(), Memory );
g_iLastSeenMemory.Set( Memory );
// is this assumption outdated? -aj
/* Let's consider 128-meg systems low-memory, and 256-meg systems high-memory.
* Cut off at 192. This is pretty conservative; many 128-meg systems can
* deal with higher memory profile settings, but some can't.
*
* Actually, Windows lops off a meg or two; cut off a little lower to treat
* 192-meg systems as high-memory. */
const bool HighMemory = (Memory >= 190);
const bool LowMemory = (Memory < 100); // 64 and 96-meg systems
/* Two memory-consuming features that we can disable are texture caching and
* preloaded banners. Texture caching can use a lot of memory; disable it for
* low-memory systems. */
PREFSMAN->m_bDelayedTextureDelete.Set( HighMemory );
/* Preloaded banners takes about 9k per song. Although it's smaller than the
* actual song data, it still adds up with a lot of songs.
* Disable it for 64-meg systems. */
PREFSMAN->m_BannerCache.Set( LowMemory ? BNCACHE_OFF:BNCACHE_LOW_RES_PRELOAD );
// might wanna do this for backgrounds, too... -aj
//PREFSMAN->m_BackgroundCache.Set( LowMemory ? BGCACHE_OFF:BGCACHE_LOW_RES_PRELOAD );
PREFSMAN->SavePrefsToDisk();
#endif
}
#if defined(WIN32)
#include "RageDisplay_D3D.h"
#include "archutils/Win32/VideoDriverInfo.h"
#endif
#if defined(SUPPORT_OPENGL)
#include "RageDisplay_OGL.h"
#endif
#if defined(SUPPORT_GLES2)
#include "RageDisplay_GLES2.h"
#endif
#include "RageDisplay_Null.h"
struct VideoCardDefaults
{
RString sDriverRegex;
RString sVideoRenderers;
int iWidth;
int iHeight;
int iDisplayColor;
int iTextureColor;
int iMovieColor;
int iTextureSize;
bool bSmoothLines;
VideoCardDefaults() {}
VideoCardDefaults(
RString sDriverRegex_,
RString sVideoRenderers_,
int iWidth_,
int iHeight_,
int iDisplayColor_,
int iTextureColor_,
int iMovieColor_,
int iTextureSize_,
bool bSmoothLines_
)
{
sDriverRegex = sDriverRegex_;
sVideoRenderers = sVideoRenderers_;
iWidth = iWidth_;
iHeight = iHeight_;
iDisplayColor = iDisplayColor_;
iTextureColor = iTextureColor_;
iMovieColor = iMovieColor_;
iTextureSize = iTextureSize_;
bSmoothLines = bSmoothLines_;
}
} const g_VideoCardDefaults[] =
{
#ifdef _WINDOWS
VideoCardDefaults(
"",
"d3d, opengl",
800,600,
32,32,32,
2048,
true
)
#else
VideoCardDefaults(
"Voodoo *5",
"d3d,opengl", // received 3 reports of opengl crashing. -Chris
640,480,
32,32,32,
2048,
true // accelerated
),
VideoCardDefaults(
"Voodoo|3dfx", // all other Voodoos: some drivers don't identify which one
"d3d,opengl",
640,480,
16,16,16,
256,
false // broken, causes black screen
),
VideoCardDefaults(
"Radeon.* 7|Wonder 7500|ArcadeVGA", // Radeon 7xxx, RADEON Mobility 7500
"d3d,opengl", // movie texture performance is terrible in OpenGL, but fine in D3D.
640,480,
16,16,16,
2048,
true // accelerated
),
VideoCardDefaults(
"GeForce|Radeon|Wonder 9|Quadro",
"opengl,d3d",
640,480,
32,32,32, // 32 bit textures are faster to load
2048,
true // hardware accelerated
),
VideoCardDefaults(
"TNT|Vanta|M64",
"opengl,d3d",
640,480,
16,16,16, // Athlon 1.2+TNT demonstration w/ movies: 70fps w/ 32bit textures, 86fps w/ 16bit textures
2048,
true // hardware accelerated
),
VideoCardDefaults(
"G200|G250|G400",
"d3d,opengl",
640,480,
16,16,16,
2048,
false // broken, causes black screen
),
VideoCardDefaults(
"Savage",
"d3d",
// OpenGL is unusable on my Savage IV with even the latest drivers.
// It draws 30 frames of gibberish then crashes. This happens even with
// simple NeHe demos. -Chris
640,480,
16,16,16,
2048,
false
),
VideoCardDefaults(
"XPERT@PLAY|IIC|RAGE PRO|RAGE LT PRO", // Rage Pro chip, Rage IIC chip
"d3d",
// OpenGL is not hardware accelerated, despite the fact that the
// drivers come with an ICD. Also, the WinXP driver performance
// is terrible and supports only 640. The ATI driver is usable.
// -Chris
320,240, // lower resolution for 60fps. In-box WinXP driver doesn't support 400x300.
16,16,16,
256,
false
),
VideoCardDefaults(
"RAGE MOBILITY-M1",
"d3d,opengl", // Vertex alpha is broken in OpenGL, but not D3D. -Chris
400,300, // lower resolution for 60fps
16,16,16,
256,
false
),
VideoCardDefaults(
"Mobility M3", // ATI Rage Mobility 128 (AKA "M3")
"d3d,opengl", // bad movie texture performance in opengl
640,480,
16,16,16,
1024,
false
),
VideoCardDefaults(
"Intel.*82810|Intel.*82815",
"opengl,d3d",// OpenGL is 50%+ faster than D3D w/ latest Intel drivers. -Chris
512,384, // lower resolution for 60fps
16,16,16,
512,
false
),
VideoCardDefaults(
"Intel*Extreme Graphics",
"d3d", // OpenGL blue screens w/ XP drivers from 6-21-2002
640,480,
16,16,16, // slow at 32bpp
1024,
false
),
VideoCardDefaults(
"Intel.*", /* fallback: all unknown Intel cards to D3D, since Intel is notoriously bad at OpenGL */
"d3d,opengl",
640,480,
16,16,16,
2048,
false
),
VideoCardDefaults(
// Cards that have problems with OpenGL:
// ASSERT fail somewhere in RageDisplay_OpenGL "Trident Video Accelerator CyberBlade"
// bug 764499: ASSERT fail after glDeleteTextures for "SiS 650_651_740"
// bug 764830: ASSERT fail after glDeleteTextures for "VIA Tech VT8361/VT8601 Graphics Controller"
// bug 791950: AV in glsis630!DrvSwapBuffers for "SiS 630/730"
"Trident Video Accelerator CyberBlade|VIA.*VT|SiS 6*",
"d3d,opengl",
640,480,
16,16,16,
2048,
false
),
VideoCardDefaults(
/* Unconfirmed texture problems on this; let's try D3D, since it's
* a VIA/S3 chipset. */
"VIA/S3G KM400/KN400",
"d3d,opengl",
640,480,
16,16,16,
2048,
false
),
VideoCardDefaults(
"OpenGL", // This matches all drivers in Mac and Linux. -Chris
"opengl",
640,480,
16,16,16,
2048,
true // Right now, they've got to have NVidia or ATi Cards anyway..
),
VideoCardDefaults(
// Default graphics settings used for all cards that don't match above.
// This must be the very last entry!
"",
"opengl,d3d",
640,480,
32,32,32,
2048,
false // AA is slow on some cards, so let's selectively enable HW accelerated cards.
)
#endif
};
static RString GetVideoDriverName()
{
#if defined(_WINDOWS)
return GetPrimaryVideoDriverName();
#else
return "OpenGL";
#endif
}
bool CheckVideoDefaultSettings()
{
// Video card changed since last run
RString sVideoDriver = GetVideoDriverName();
LOG->Trace( "Last seen video driver: %s", PREFSMAN->m_sLastSeenVideoDriver.Get().c_str() );
// allow players to opt out of the forced reset when a new video card is detected - mina
static Preference<bool> TKGP("ResetVideoSettingsWithNewGPU", true);
VideoCardDefaults defaults;
unsigned i;
for( i=0; i<ARRAYLEN(g_VideoCardDefaults); i++ )
{
defaults = g_VideoCardDefaults[i];
RString sDriverRegex = defaults.sDriverRegex;
Regex regex( sDriverRegex );
if( regex.Compare(sVideoDriver) )
{
LOG->Trace( "Card matches '%s'.", sDriverRegex.size()? sDriverRegex.c_str():"(unknown card)" );
break;
}
}
if (i >= ARRAYLEN(g_VideoCardDefaults))
{
FAIL_M("Failed to match video driver");
}
bool bSetDefaultVideoParams = false;
if( PREFSMAN->m_sVideoRenderers.Get() == "" )
{
bSetDefaultVideoParams = true;
LOG->Trace( "Applying defaults for %s.", sVideoDriver.c_str() );
}
else if( PREFSMAN->m_sLastSeenVideoDriver.Get() != sVideoDriver )
{
bSetDefaultVideoParams = true;
LOG->Trace( "Video card has changed from %s to %s. Applying new defaults.", PREFSMAN->m_sLastSeenVideoDriver.Get().c_str(), sVideoDriver.c_str() );
}
if( bSetDefaultVideoParams )
{
if (TKGP) {
PREFSMAN->m_sVideoRenderers.Set(defaults.sVideoRenderers);
PREFSMAN->m_iDisplayWidth.Set(defaults.iWidth);
PREFSMAN->m_iDisplayHeight.Set(defaults.iHeight);
PREFSMAN->m_iDisplayColorDepth.Set(defaults.iDisplayColor);
PREFSMAN->m_iTextureColorDepth.Set(defaults.iTextureColor);
PREFSMAN->m_iMovieColorDepth.Set(defaults.iMovieColor);
PREFSMAN->m_iMaxTextureResolution.Set(defaults.iTextureSize);
PREFSMAN->m_bSmoothLines.Set(defaults.bSmoothLines);
// this only worked when we started in fullscreen by default. -aj
//PREFSMAN->m_fDisplayAspectRatio.Set( HOOKS->GetDisplayAspectRatio() );
// now that we start in windowed mode, use the new default aspect ratio.
PREFSMAN->m_fDisplayAspectRatio.Set(PREFSMAN->m_fDisplayAspectRatio);
}
// Update last seen video card
PREFSMAN->m_sLastSeenVideoDriver.Set( GetVideoDriverName() );
}
else if( PREFSMAN->m_sVideoRenderers.Get().CompareNoCase(defaults.sVideoRenderers) )
{
LOG->Warn("Video renderer list has been changed from '%s' to '%s'",
defaults.sVideoRenderers.c_str(), PREFSMAN->m_sVideoRenderers.Get().c_str() );
}
LOG->Info( "Video renderers: '%s'", PREFSMAN->m_sVideoRenderers.Get().c_str() );
return bSetDefaultVideoParams;
}
static LocalizedString ERROR_INITIALIZING_CARD ( "StepMania", "There was an error while initializing your video card." );
static LocalizedString ERROR_DONT_FILE_BUG ( "StepMania", "Please do not file this error as a bug! Use the web page below to troubleshoot this problem." );
static LocalizedString ERROR_VIDEO_DRIVER ( "StepMania", "Video Driver: %s" );
static LocalizedString ERROR_NO_VIDEO_RENDERERS ( "StepMania", "No video renderers attempted." );
static LocalizedString ERROR_INITIALIZING ( "StepMania", "Initializing %s..." );
static LocalizedString ERROR_UNKNOWN_VIDEO_RENDERER ( "StepMania", "Unknown video renderer value: %s" );
RageDisplay *CreateDisplay()
{
/* We never want to bother users with having to decide which API to use.
*
* Some cards simply are too troublesome with OpenGL to ever use it, eg. Voodoos.
* If D3D8 isn't installed on those, complain and refuse to run (by default).
* For others, always use OpenGL. Allow forcing to D3D as an advanced option.
*
* If we're missing acceleration when we load D3D8 due to a card being in the
* D3D list, it means we need drivers and that they do exist.
*
* If we try to load OpenGL and we're missing acceleration, it may mean:
* 1. We're missing drivers, and they just need upgrading.
* 2. The card doesn't have drivers, and it should be using D3D8.
* In other words, it needs an entry in this table.
* 3. The card doesn't have drivers for either. (Sorry, no S3 868s.)
* Can't play.
* In this case, fail to load; don't silently fall back on D3D. We don't want
* people unknowingly using D3D8 with old drivers (and reporting obscure bugs
* due to driver problems). We'll probably get bug reports for all three types.
* #2 is the only case that's actually a bug.
*
* Actually, right now we're falling back. I'm not sure which behavior is better.
*/
//bool bAppliedDefaults = CheckVideoDefaultSettings();
CheckVideoDefaultSettings();
VideoModeParams params;
StepMania::GetPreferredVideoModeParams( params );
RString error = ERROR_INITIALIZING_CARD.GetValue()+"\n\n"+
ERROR_DONT_FILE_BUG.GetValue()+"\n\n"
VIDEO_TROUBLESHOOTING_URL "\n\n"+
ssprintf(ERROR_VIDEO_DRIVER.GetValue(), GetVideoDriverName().c_str())+"\n\n";
vector<RString> asRenderers;
split( PREFSMAN->m_sVideoRenderers, ",", asRenderers, true );
if( asRenderers.empty() )
RageException::Throw( "%s", ERROR_NO_VIDEO_RENDERERS.GetValue().c_str() );
RageDisplay *pRet = NULL;
for( unsigned i=0; i<asRenderers.size(); i++ )
{
RString sRenderer = asRenderers[i];
if( sRenderer.CompareNoCase("opengl")==0 )
{
#if defined(SUPPORT_OPENGL)
pRet = new RageDisplay_Legacy;
#endif
}
else if( sRenderer.CompareNoCase("gles2")==0 )
{
#if defined(SUPPORT_GLES2)
pRet = new RageDisplay_GLES2;
#endif
}
else if( sRenderer.CompareNoCase("d3d")==0 )
{
// TODO: ANGLE/RageDisplay_Modern
#if defined(SUPPORT_D3D)
pRet = new RageDisplay_D3D;
#endif
}
else if( sRenderer.CompareNoCase("null")==0 )
{
return new RageDisplay_Null;
}
else
{
RageException::Throw( ERROR_UNKNOWN_VIDEO_RENDERER.GetValue(), sRenderer.c_str() );
}
if( pRet == NULL )
continue;
RString sError = pRet->Init( params, PREFSMAN->m_bAllowUnacceleratedRenderer );
if( !sError.empty() )
{
error += ssprintf(ERROR_INITIALIZING.GetValue(), sRenderer.c_str())+"\n" + sError;
SAFE_DELETE( pRet );
error += "\n\n\n";
continue;
}
break; // the display is ready to go
}
if( pRet == NULL)
RageException::Throw( "%s", error.c_str() );
return pRet;
}
static void SwitchToLastPlayedGame()
{
const Game *pGame = GAMEMAN->StringToGame( PREFSMAN->GetCurrentGame() );
// If the active game type isn't actually available, revert to the default.
if( pGame == NULL )
pGame = GAMEMAN->GetDefaultGame();
if( !GAMEMAN->IsGameEnabled( pGame ) && pGame != GAMEMAN->GetDefaultGame() )
{
pGame = GAMEMAN->GetDefaultGame();
LOG->Warn( "Default NoteSkin for \"%s\" missing, reverting to \"%s\"",
pGame->m_szName, GAMEMAN->GetDefaultGame()->m_szName );
}
ASSERT( GAMEMAN->IsGameEnabled(pGame) );
StepMania::InitializeCurrentGame( pGame );
}
// This function is meant to only be called during start up.
void StepMania::InitializeCurrentGame( const Game* g )
{
ASSERT( g != NULL );
ASSERT( GAMESTATE != NULL );
ASSERT( ANNOUNCER != NULL );
ASSERT( THEME != NULL );
GAMESTATE->SetCurGame( g );
RString sAnnouncer = PREFSMAN->m_sAnnouncer;
RString sTheme = PREFSMAN->m_sTheme;
RString sGametype = GAMESTATE->GetCurrentGame()->m_szName;
RString sLanguage = PREFSMAN->m_sLanguage;
if( sAnnouncer.empty() )
sAnnouncer = GAMESTATE->GetCurrentGame()->m_szName;
RString argCurGame;
if( GetCommandlineArgument( "game", &argCurGame) && argCurGame != sGametype )
{
Game const* new_game= GAMEMAN->StringToGame(argCurGame);
if(new_game == NULL)
{
LOG->Warn("%s is not a known game type, ignoring.", argCurGame.c_str());
}
else
{
PREFSMAN->SetCurrentGame(sGametype);
GAMESTATE->SetCurGame(new_game);
}
}
// It doesn't matter if sTheme is blank or invalid, THEME->STAL will set
// a selectable theme for us. -Kyz
// process gametype, theme and language command line arguments;
// these change the preferences in order for transparent loading -aj
RString argTheme;
if( GetCommandlineArgument( "theme",&argTheme) && argTheme != sTheme )
{
sTheme = argTheme;
// set theme in preferences too for correct behavior -aj
PREFSMAN->m_sTheme.Set(sTheme);
}
RString argLanguage;
if( GetCommandlineArgument( "language",&argLanguage) )
{
sLanguage = argLanguage;
// set language in preferences too for correct behavior -aj
PREFSMAN->m_sLanguage.Set(sLanguage);
}
// it's OK to call these functions with names that don't exist.
ANNOUNCER->SwitchAnnouncer( sAnnouncer );
THEME->SwitchThemeAndLanguage( sTheme, sLanguage, PREFSMAN->m_bPseudoLocalize );
// Set the input scheme for the new game, and load keymaps.
if( INPUTMAPPER )
{
INPUTMAPPER->SetInputScheme( &g->m_InputScheme );
INPUTMAPPER->ReadMappingsFromDisk();
}
}
static void MountTreeOfZips( const RString &dir )
{
vector<RString> dirs;
dirs.push_back( dir );
while( dirs.size() )
{
RString path = dirs.back();
dirs.pop_back();
if( !IsADirectory(path) )
continue;
vector<RString> zips;
GetDirListing( path + "/*.zip", zips, false, true );
GetDirListing( path + "/*.smzip", zips, false, true );
for( unsigned i = 0; i < zips.size(); ++i )
{
if( !IsAFile(zips[i]) )
continue;
LOG->Trace( "VFS: found %s", zips[i].c_str() );
FILEMAN->Mount( "zip", zips[i], "/" );
}
GetDirListing( path + "/*", dirs, true, true );
}
}
static void WriteLogHeader()
{
LOG->Info("%s%s", PRODUCT_FAMILY, product_version);
LOG->Info( "Compiled %s @ %s (build %s)", version_date, version_time, ::sm_version_git_hash);
time_t cur_time;
time(&cur_time);
struct tm now;
localtime_r( &cur_time, &now );
LOG->Info( "Log starting %.4d-%.2d-%.2d %.2d:%.2d:%.2d",
1900+now.tm_year, now.tm_mon+1, now.tm_mday, now.tm_hour, now.tm_min, now.tm_sec );
LOG->Trace( " " );
if( g_argc > 1 )
{
RString args;
for( int i = 1; i < g_argc; ++i )
{
if( i>1 )
args += " ";
// surround all params with some marker, as they might have whitespace.
// using [[ and ]], as they are not likely to be in the params.
args += ssprintf( "[[%s]]", g_argv[i] );
}
LOG->Info( "Command line args (count=%d): %s", (g_argc - 1), args.c_str());
}
}
static void ApplyLogPreferences()
{
LOG->SetShowLogOutput( PREFSMAN->m_bShowLogOutput );
LOG->SetLogToDisk( PREFSMAN->m_bLogToDisk );
LOG->SetInfoToDisk( true );
LOG->SetUserLogToDisk( true );
LOG->SetFlushing( PREFSMAN->m_bForceLogFlush );
Checkpoints::LogCheckpoints( PREFSMAN->m_bLogCheckpoints );
}
static LocalizedString COULDNT_OPEN_LOADING_WINDOW( "LoadingWindow", "Couldn't open any loading windows." );
int sm_main(int argc, char* argv[])
{
g_RandomNumberGenerator.seed(static_cast<unsigned int>(time(nullptr)));
seed_lua_prng();
RageThreadRegister thread( "Main thread" );
RageException::SetCleanupHandler( HandleException );
SetCommandlineArguments( argc, argv );
// Set up arch hooks first. This may set up crash handling.
HOOKS = ArchHooks::Create();
HOOKS->Init();
LUA = new LuaManager;
HOOKS->RegisterWithLua();
// Initialize the file extension type lists so everything can ask ActorUtil
// what the type of a file is.
ActorUtil::InitFileTypeLists();
// Almost everything uses this to read and write files. Load this early.
FILEMAN = new RageFileManager( argv[0] );
FILEMAN->MountInitialFilesystems();
bool bPortable = DoesFileExist("Portable.ini");
if( !bPortable )