summaryrefslogtreecommitdiffstats
path: root/game/code/contexts/bootupcontext.cpp
blob: 081151706a2bdc874d37be69e9d3f7f3972c29ff (plain) (blame)
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
//=============================================================================
// Copyright (C) 2002 Radical Entertainment Ltd.  All rights reserved.
//
// File:        bootupcontext.cpp
//
// Description: Implementation of BootupContext.
//
// History:     + Created -- Darwin Chau
//
//=============================================================================

#ifdef RAD_RELEASE
    #ifndef RAD_E3
        #define SHOW_MOVIES
    #endif
#endif

//========================================
// System Includes
//========================================
#include <raddebug.hpp>
#include <radtime.hpp>
#include <raddebugwatch.hpp>
#include <radmovie2.hpp>
#include <p3d/utility.hpp>
#include <p3d/context.hpp>
#include <pddi/pddi.hpp>

//========================================
// Project Includes
//========================================
#include <contexts/bootupcontext.h>

#include <atc/atcmanager.h>
#include <cards/cardgallery.h>
#include <cheats/cheatinputsystem.h>
#include <constants/movienames.h>
#include <contexts/contextenum.h>
#include <data/gamedatamanager.h>
#include <data/memcard/memorycardmanager.h>
#include <gameflow/gameflow.h>
#include <input/inputmanager.h>
#include <interiors/interiormanager.h>
#include <loading/loadingmanager.h>
#include <main/commandlineoptions.h>
#include <memory/leakdetection.h>
#include <memory/srrmemory.h>
#include <mission/gameplaymanager.h>
#include <mission/missionmanager.h>
#include <mission/charactersheet/charactersheetmanager.h>
#include <mission/rewards/rewardsmanager.h>
#include <presentation/presentation.h>
#include <presentation/presevents/presentationevent.h>
#include <presentation/gui/guisystem.h>
#include <presentation/tutorialmanager.h>
#include <render/rendermanager/rendermanager.h>
#include <render/rendermanager/renderlayer.h>
#include <sound/soundmanager.h>
#include <supersprint/supersprintmanager.h>
#include <worldsim/worldphysicsmanager.h>
#include <worldsim/character/charactermanager.h>

#ifdef RAD_GAMECUBE
    #include <main/gamecube_extras/gcmanager.h>
#endif

#ifdef RAD_WIN32
    #include <main/win32platform.h>
    #include <data/config/gameconfigmanager.h>
#endif

//******************************************************************************
//
// Global Data, Local Data, Local Classes
//
//******************************************************************************

// Static pointer to instance of singleton.
BootupContext* BootupContext::spInstance = NULL;

#ifdef RAD_RELEASE
    #ifdef RAD_PS2
        // TC: Edwin (Singh) says that the PS2 TRC requires that the license screen
        //     be displayed for at least 5 seconds.
        //
        const int MINIMUM_LICENSE_SCREEN_DISPLAY_TIME = 5000; // in msec
    #else
        const int MINIMUM_LICENSE_SCREEN_DISPLAY_TIME = 1000; // in msec
    #endif
#else
    const int MINIMUM_LICENSE_SCREEN_DISPLAY_TIME = 1000; // in msec
#endif

//******************************************************************************
//
// Public Member Functions
//
//******************************************************************************

//==============================================================================
// BootupContext::GetInstance
//==============================================================================
//
// Description: - Access point for the BootupContext singleton.  
//              - Creates the BootupContext if needed.
//
// Parameters:	None.
//
// Return:      Pointer to the BootupContext.
//
// Constraints: This is a singleton so only one instance is allowed.
//
//==============================================================================
BootupContext* BootupContext::GetInstance()
{
    if( spInstance == NULL )
    {
        spInstance = new(GMA_PERSISTENT) BootupContext;
        rAssert( spInstance );
    }
    
    return spInstance;
}

//=============================================================================
// BootupContext::StartMovies
//=============================================================================
// Description: Comment
//
// Parameters:  Game Mode (Frontend/In-Game)
//
// Return:      void 
//
//=============================================================================
void BootupContext::StartMovies()
{
#ifndef FINAL
    if( CommandLineOptions::Get( CLO_SKIP_FE ) )
    {
        // enable 'unlock missions' cheat for 'skipfe' commandline option
        //
        GetCheatInputSystem()->SetCheatEnabled( CHEAT_ID_UNLOCK_MISSIONS, true );

        short levelIndex = CommandLineOptions::GetDefaultLevel();

        if( levelIndex == -1 ) // L0 = minigame
        {
            SetGameplayManager( SuperSprintManager::GetInstance() );

            // skip FE and go to mini-game
            //
            GetGameFlow()->SetContext( CONTEXT_SUPERSPRINT_FE );
        }
        else
        {
            SetGameplayManager( MissionManager::GetInstance() );

            // register controller ID [0] for player [0], by default
            //
            GetInputManager()->RegisterControllerID( 0, 0 );

            short missionIndex = CommandLineOptions::GetDefaultMission();
            if( levelIndex == RenderEnums::L1 )
            {
                // special case for level 1 due to tutorial mission being mission 0
                //
                missionIndex++;
            }

            // set level and mission to load for normal gameplay
            //
            GetGameplayManager()->SetLevelIndex( static_cast< RenderEnums::LevelEnum >( levelIndex ) );
            GetGameplayManager()->SetMissionIndex( static_cast< RenderEnums::MissionEnum >( missionIndex ) );

            // skip FE and go to normal gameplay
            //
            GetGameFlow()->SetContext( CONTEXT_LOADING_GAMEPLAY );
        }
    }
    else
#endif // !FINAL
    {
#ifdef SHOW_MOVIES
        if( CommandLineOptions::Get( CLO_SKIP_MOVIE ) )
        {
            // Switch to frontend context.
            GetGameFlow()->SetContext( CONTEXT_FRONTEND );
        }
        else
        {
            FMVEvent* pEvent = 0;

            GetPresentationManager()->QueueFMV( &pEvent, this );
            strcpy( pEvent->fileName, MovieNames::VUGLOGO );
            pEvent->SetRenderLayer( RenderEnums::PresentationSlot );
            pEvent->SetAutoPlay( true );
            pEvent->SetAudioIndex( FMVEvent::AUDIO_INDEX_ENGLISH );
            pEvent->SetClearWhenDone( true );

            GetPresentationManager()->QueueFMV( &pEvent, this );
            strcpy( pEvent->fileName, MovieNames::FOXLOGO );
            pEvent->SetRenderLayer( RenderEnums::PresentationSlot );
            pEvent->SetAutoPlay( true );
            pEvent->SetAudioIndex( FMVEvent::AUDIO_INDEX_ENGLISH );
            pEvent->SetClearWhenDone( true );

			GetPresentationManager()->QueueFMV( &pEvent, this );
            strcpy( pEvent->fileName, MovieNames::GRACIELOGO );
            pEvent->SetRenderLayer( RenderEnums::PresentationSlot );
            pEvent->SetAutoPlay( true );
            pEvent->SetAudioIndex( FMVEvent::AUDIO_INDEX_ENGLISH );
            pEvent->SetClearWhenDone( true );

            GetPresentationManager()->QueueFMV( &pEvent, this );
            strcpy( pEvent->fileName, MovieNames::RADICALLOGO );
            pEvent->SetRenderLayer( RenderEnums::PresentationSlot );
            pEvent->SetAutoPlay( true );
            pEvent->SetAudioIndex( FMVEvent::AUDIO_INDEX_ENGLISH );
            pEvent->SetClearWhenDone( true );

            GetRenderManager()->mpLayer( RenderEnums::GUI )->Chill();
        }
#else
        // Switch to frontend context.
        GetGameFlow()->SetContext( CONTEXT_FRONTEND );
#endif
    }
}

void
BootupContext::StartLoadingSound()
{
    GetSoundManager()->OnBootupStart();

    GetLoadingManager()->AddCallback( this, (void*)GetSoundManager() );
}

#ifdef RAD_WIN32
void BootupContext::LoadConfig()
{
    // Load the config file for the game.
    GameConfigManager* gc = GetGameConfigManager();
    bool success = gc->LoadConfigFile();

    // If we couldn't load the config file, create a new one.
    if( !success )
    {
        Win32Platform::GetInstance()->LoadDefaults();
        gc->SaveConfigFile();
    }
}
#endif

//******************************************************************************
//
// Protected Member Functions
//
//******************************************************************************

//==============================================================================
// BootupContext::OnStart
//==============================================================================
//
// Description: 
//
// Parameters:  
//
// Return:      
//
//==============================================================================
void BootupContext::OnStart( ContextEnum previousContext )
{
    SetMemoryIdentification( "BootupContext" );
    HeapMgr()->PrepareHeapsFeCleanup();
    HeapMgr()->PrepareHeapsFeSetup();
    HeapMgr()->PushHeap (GMA_PERSISTENT);
#ifdef DEBUGINFO_ENABLED
    DebugInfo::InitializeStaticVariables();
#endif

    MEMTRACK_PUSH_FLAG( "Bootup" );
    GetGameDataManager()->Init();

#ifdef RAD_PS2
    // must load memory card info first, before anything else, since the
    // memory card boot-up check is done right at the beginning
    //
    if( !CommandLineOptions::Get( CLO_SKIP_MEMCHECK ) )
    {
        GetMemoryCardManager()->LoadMemcardInfo();
    }
#endif

    GetGuiSystem()->Init();
    GetGuiSystem()->RegisterUserInputHandlers();

    GetCardGallery()->Init();
    GetCheatInputSystem()->Init();
    GetTutorialManager()->Initialize();
    GetATCManager()->Init();

    GetCharacterSheetManager()->InitCharacterSheet();

    GetPresentationManager()->InitializePlayerDrawable();

#ifdef RAD_GAMECUBE
    //Initialize the GCManager's timers for testing reset and such.
    GCManager::GetInstance()->Init();
#endif

    GetWorldPhysicsManager()->Init();

    GetInteriorManager()->OnBootupStart();

    // TC: for PS2, we shouldn't start loading sound stuff until we get to the
    //     license screen to avoid any synchronous script parsing that could
    //     lock-up the CPU briefly on a GUI prompt screen
    //
//    GetSoundManager()->OnBootupStart();

    GetCharacterManager()->PreLoad();

    // load rewards script
    //
    GetRewardsManager()->LoadScript();

    // preload some data that is common across all levels 
    // MissionScriptLoader::LoadP3DFile hacked to supress their loads in mission scripts
    GetLoadingManager()->AddRequest( FILEHANDLER_PURE3D, "art\\cars\\common.p3d", GMA_DEFAULT, "Global" );
    GetLoadingManager()->AddRequest( FILEHANDLER_PURE3D, "art\\cars\\huskA.p3d", GMA_DEFAULT, "Global");
    GetLoadingManager()->AddRequest( FILEHANDLER_PURE3D, "art\\phonecamera.p3d", GMA_DEFAULT, "Global");
    GetLoadingManager()->AddRequest( FILEHANDLER_PURE3D, "art\\cards.p3d", GMA_DEFAULT, "Global");
    GetLoadingManager()->AddRequest( FILEHANDLER_PURE3D, "art\\wrench.p3d", GMA_DEFAULT, "Global");
    GetLoadingManager()->AddRequest( FILEHANDLER_PURE3D, "art\\missions\\generic\\missgen.p3d", GMA_DEFAULT, "Global");

    //
    // Address any loading requests that the managers have queued up
    //
    GetLoadingManager()->AddCallback( this );

#if defined( RAD_WIN32 ) && defined( SHOW_MOVIES )
    GetInputManager()->GetFEMouse()->SetInGameMode( true );
#endif
}


//==============================================================================
// BootupContext::OnStop
//==============================================================================
//
// Description: 
//
// Parameters:  
//
// Return:      
//
//==============================================================================
void BootupContext::OnStop( ContextEnum nextContext )
{
    rTunePrintf("BootupContext::OnStop... ");

    GetGuiSystem()->UnregisterUserInputHandlers();

    // release GUI bootup
    GetGuiSystem()->HandleMessage( GUI_MSG_RELEASE_BOOTUP );

#if defined( RAD_WIN32 ) && defined( SHOW_MOVIES )
    GetInputManager()->GetFEMouse()->SetInGameMode( false );
#endif


    MEMTRACK_POP_FLAG( "" );

    HeapMgr()->PopHeap ( GMA_PERSISTENT );

    rTunePrintf("Finished\n");
    SetMemoryIdentification( "BootupContext Finished" );
}


//==============================================================================
// BootupContext::OnUpdate
//==============================================================================
//
// Description: 
//
// Parameters:  
//
// Return:      
//
//==============================================================================
void BootupContext::OnUpdate( unsigned int elapsedTime )
{
    if( m_elapsedTime != -1 )
    {
        if( m_elapsedTime > MINIMUM_LICENSE_SCREEN_DISPLAY_TIME &&
            m_bootupLoadCompleted && m_soundLoadCompleted )
        {
            // Tell GUI system to quit out of the boot-up state
            GetGuiSystem()->HandleMessage( GUI_MSG_QUIT_BOOTUP );

            m_elapsedTime = -1;
        }
        else
        {
            m_elapsedTime += elapsedTime;
        }
    }

    // update game data manager
    GetGameDataManager()->Update( elapsedTime );

    GetPresentationManager()->Update( elapsedTime );

    // update GUI system
    GetGuiSystem()->Update( elapsedTime );
}


//==============================================================================
// BootupContext::OnSuspend
//==============================================================================
//
// Description: 
//
// Parameters:  
//
// Return:      
//
//==============================================================================
void BootupContext::OnSuspend()
{
}


//==============================================================================
// BootupContext::OnResume
//==============================================================================
//
// Description: 
//
// Parameters:  
//
// Return:      
//
//==============================================================================
void BootupContext::OnResume()
{
}


//==============================================================================
// BootupContext::OnHandleEvent
//==============================================================================
//
// Description: 
//
// Parameters:  
//
// Return:      
//
//==============================================================================
void BootupContext::OnHandleEvent( EventEnum id, void* pEventData )
{
}

//=============================================================================
// BootupContext::OnProcessRequestsComplete
//=============================================================================
// Description: Called when startup loading is done
//
// Parameters:  pUserData - unused
//
// Return:      void 
//
//=============================================================================
void BootupContext::OnProcessRequestsComplete( void* pUserData )
{
    if( pUserData == GetSoundManager() )
    {
        // set flag indicating all sound loads have completed
        //
        m_soundLoadCompleted = true;
    }
    else
    {
        // set flag indicating all bootup loads (except for sound) have completed
        //
        m_bootupLoadCompleted = true;
    }

    //
    // Tell the sound manager to do some processing, now that the scripts
    // are sure to have been loaded.
    //
    // NOTE: I've moved this here since this call triggers a CPU-hogging
    // bit of dialog script postprocessing.  That processing should be pulled out
    // and done offline, but until then, do this somewhere where
    // it won't starve the completion of FMVs. -- Esan
    //
    if( m_bootupLoadCompleted && m_soundLoadCompleted )
    {
        GetSoundManager()->OnBootupComplete();

        GetInputManager()->ToggleRumble( false );
    }
}

//=============================================================================
// BootupContext::OnPresentationEventBegin
//=============================================================================
// Description: Comment
//
// Parameters:  ( PresentationEvent* pEvent )
//
// Return:      void 
//
//=============================================================================
void BootupContext::OnPresentationEventBegin( PresentationEvent* pEvent )
{
}

//=============================================================================
// BootupContext::OnPresentationEventLoadComplete
//=============================================================================
// Description: Comment
//
// Parameters:  ( PresentationEvent* pEvent )
//
// Return:      void 
//
//=============================================================================
void BootupContext::OnPresentationEventLoadComplete( PresentationEvent* pEvent )
{
}


//=============================================================================
// BootupContext::OnPresentationEventEnd
//=============================================================================
// Description: Comment
//
// Parameters:  ( PresentationEvent* pEvent )
//
// Return:      void 
//
//=============================================================================
void BootupContext::OnPresentationEventEnd( PresentationEvent* pEvent )
{
    if( GetPresentationManager()->IsQueueEmpty() )
    {
        GetRenderManager()->mpLayer( RenderEnums::GUI )->Warm();

        // Switch to frontend context.
        GetGameFlow()->SetContext( CONTEXT_FRONTEND );
    }
}

//******************************************************************************
//
// Private Member Functions
//
//******************************************************************************


//==============================================================================
// BootupContext::BootupContext
//==============================================================================
//
// Description: 
//
// Parameters:  
//
// Return:      
//
//==============================================================================// 
BootupContext::BootupContext()
:   m_elapsedTime( -1 ),
    m_bootupLoadCompleted( false ),
    m_soundLoadCompleted( false ),
    m_pSharedShader( 0 )
{
    m_pSharedShader = p3d::device->NewShader("simple");
    rAssert( m_pSharedShader );
    m_pSharedShader->AddRef();
}


//==============================================================================
// BootupContext::~BootupContext
//==============================================================================
//
// Description: 
//
// Parameters:  
//
// Return:      
//
//==============================================================================// 
BootupContext::~BootupContext()
{
    // Too bad we can't use tEntity::Release() since is
    //a pddi object.
    if( m_pSharedShader != 0 )
    {
        m_pSharedShader->Release();
        m_pSharedShader = 0;
    }
    spInstance = NULL;
}