Exemplo n.º 1
0
void SoundLibrary2dSDL::TopupBuffer()
{
	if (m_wavOutput)
	{
		static double nextOutputTime = -1.0;
		if (nextOutputTime < 0.0) nextOutputTime = GetHighResTime();
		
		if (GetHighResTime() > nextOutputTime)
		{
			StereoSample buf[5000];
			int samplesPerSecond = g_preferences->GetInt("SoundMixFreq", 44100);
			int samplesPerUpdate = (int)((double)samplesPerSecond / 20.0);
			G_SL2D->m_callback(buf, samplesPerUpdate);
			fwrite(buf, samplesPerUpdate, sizeof(StereoSample), m_wavOutput);
			nextOutputTime += 1.0 / 20.0;
		}
	}
	else {
#ifndef INVOKE_CALLBACK_FROM_SOUND_THREAD
		SDL_LockAudio();
		for (int i = 0; i < m_bufferIsThirsty; i++) {
			m_callback( m_buffer[i].stream, m_buffer[i].len );
		}
		m_bufferIsThirsty = 0;
		SDL_UnlockAudio();
#endif
	}
}
bool Tutorial::AdvanceCurrentChapter()
{
    //
    // If the next chapter timer has been set, move on to the next chapter
    // if the right amount of time has passed

    if( m_nextChapterTimer > 0.0 )
    {
        if( GetHighResTime() >= m_nextChapterTimer )
        {
            TriggerChapter( m_chapter+1 );
        }
        return false;
    }
    
    
    //
    // If a repeat message has been set, say it when the time comes

	if( m_repeatMessage && !g_app->m_sepulveda->IsVisible() )
    {
        if( GetHighResTime() >= m_repeatMessageTimer )
        {
            g_app->m_sepulveda->Say( m_repeatMessage );
            if( m_repeatGesture ) g_app->m_sepulveda->DemoGesture( m_repeatGesture, 2.0 );
            m_repeatMessageTimer = GetHighResTime() + m_repeatPeriod;
        }
    }

    return true;
}
Exemplo n.º 3
0
void App::RenderTitleScreen()
{
    Image *gasMask = g_resource->GetImage( "graphics/gasmask.bmp" );
    
    float windowW = g_windowManager->WindowW();
    float windowH = g_windowManager->WindowH();


    float baseLine = windowH * 0.7f;

    g_renderer->SetBlendMode( Renderer::BlendModeNormal );
    g_renderer->SetDepthBuffer( false, false );
    

    //
    // Render explosions

    static float bombTimer = GetHighResTime() + 1;
    static float bombX = -1;
    
    if( GetHighResTime() > bombTimer )
    {
        bombX = frand(windowW);
        bombTimer = GetHighResTime() + 10 + frand(10);
    }

    if( bombX > 0 )
    {
        Image *blur = g_resource->GetImage( "graphics/explosion.bmp" );
        g_renderer->SetBlendMode( Renderer::BlendModeAdditive );        

        float bombSize = 500;
        Colour col(255,155,155, 255*(bombTimer-GetHighResTime())/10 );
        g_renderer->Blit( blur, bombX, baseLine-300, bombSize, bombSize, col );
    }


    //
    // Render city

    float x = 0;
    
    AppSeedRandom(0);
    
    g_renderer->SetBlendMode( Renderer::BlendModeNormal );        

    g_renderer->RectFill( 0, baseLine, windowW, windowH-baseLine, Black );

    while( x < windowW )
    {        
        float thisW = 50+sfrand(30);
        float thisH = 40+frand(140);

        g_renderer->RectFill( x, baseLine - thisH, thisW, thisH, Black );

        x += thisW;
    }

}
bool Generator::Advance()
{
    if( !m_enabled )
    {
        m_surges.Empty();
        m_throughput = 0.0f;
        m_numThisSecond = 0;

        //
        // Check to see if our control tower has been captured.
        // This can happen if a user captures the control tower, exits the level and saves,
        // then returns to the level.  The tower is captured and cannot be changed, but
        // the m_enabled state of this building has been lost.

        for( int i = 0; i < g_app->m_location->m_buildings.Size(); ++i )
        {
            if( g_app->m_location->m_buildings.ValidIndex(i) )
            {
                Building *building = g_app->m_location->m_buildings[i];
                if( building && building->m_type == TypeControlTower )
                {
                    ControlTower *tower = (ControlTower *) building;
                    if( tower->GetBuildingLink() == m_id.GetUniqueId() &&
                        tower->m_id.GetTeamId() == m_id.GetTeamId() )
                    {
                        m_enabled = true;
                        break;
                    }
                }
            }
        }
    }
    else
    {
        if( GetHighResTime() >= m_timerSync + 1.0f )
        {
            float newAverage = m_numThisSecond;
            m_numThisSecond = 0;
            m_timerSync = GetHighResTime();
            m_throughput = m_throughput * 0.8f + newAverage * 0.2f;
        }

        if( m_throughput > 6.5f )
        {
            GlobalBuilding *gb = g_app->m_globalWorld->GetBuilding( m_id.GetUniqueId(), g_app->m_locationId );
            gb->m_online = true;
        }
    }

    return PowerBuilding::Advance();
}
void InputScroller::MouseDown()
{
	if ( g_inputManager->controlEvent( ControlEclipseLMousePressed ) )
	{
	    m_mouseDownStartTime = GetHighResTime() - INTEGER_INCREMENT_PERIOD;
	}
}
Exemplo n.º 6
0
bool TimeToRender(float _lastRenderTime)
{
#ifndef TESTBED
    if( !g_app->GetClientToServer() ||
        !g_app->GetClientToServer()->m_synchronising  )
    {
        return true;
    }
#else
    if( !g_app->m_gameRunning )
    {
        return true;
    }
#endif


    //
    // If we are connecting to a game
    // Limit the frame rate to 20fps
    // to ensure glFlip doesn't hog the CPU time

    double timeNow = GetHighResTime();
    double timeSinceLastRender = timeNow - _lastRenderTime;

    return( timeSinceLastRender > 0.05f );   
}
Exemplo n.º 7
0
void ConnectingWindow::RenderTimeRemaining( float _fractionDone )
{
    static float s_timeRemaining = 0;
    static float s_timer = 0;

    float timeNow = GetHighResTime();

    if( timeNow > s_timer + 0.5f )
    {
        s_timer = timeNow;
        float timeSoFar = timeNow - m_stageStartTime;
        float timeForOnePercent = timeSoFar/_fractionDone;
        float percentRemaining = 1.0f - _fractionDone;
        s_timeRemaining = percentRemaining * timeForOnePercent;
    }

    if( s_timeRemaining > 0 && s_timeRemaining < 100000 )
    {
        int minutes = int(s_timeRemaining / 60.0f);
        int seconds = s_timeRemaining - minutes * 60;

		char caption[512];
		sprintf( caption, LANGUAGEPHRASE("dialog_state_time_remaining") );
		LPREPLACEINTEGERFLAG( 'M', minutes, caption );
		char number[32];
		sprintf( number, "%02d", seconds );
		LPREPLACESTRINGFLAG( 'S', number, caption );
        g_renderer->TextCentreSimple( m_x + m_w/2, m_y + m_h - 60, White, 14, caption );
    }
}
void Demo2Tutorial::HandleSquadDeath()
{
    //
    // Ensure the currently running task is a fully functioning squad

    Task *currentTask = g_app->m_taskManager->GetCurrentTask();

    if( !currentTask || currentTask->m_type != GlobalResearch::TypeSquad )
    {
        // If the player deselected by accident, reselect now
        for( int i = 0; i < g_app->m_taskManager->m_tasks.Size(); ++i )
        {
            Task *task = g_app->m_taskManager->m_tasks[i];
            if( task &&
                task->m_type == GlobalResearch::TypeSquad )
            {
                g_app->m_taskManager->SelectTask( task->m_id );
                return;
            }
        }

        // There are no squad tasks running.
        g_app->m_sepulveda->ShutUp();
        g_app->m_sepulveda->Say( "launchpad_tutorial_9_error" );
        m_chapter = 2;
        m_nextChapterTimer = GetHighResTime() + 5;
    }
}
DemoEndSequence::DemoEndSequence()
{
    m_timer = GetHighResTime();
    m_newDarwinianTimer = 20.0f;
    m_endDialogCreated = false;

    if( !g_app->IsSinglePlayer() )
    {
        m_newDarwinianTimer = 0.0f;
    }


    //
    // Delete the saved mission file

    if( g_app->IsSinglePlayer() )
    {
        char *missionFilename = g_app->m_location->m_levelFile->m_missionFilename;
        char saveFilename[256];
        sprintf( saveFilename, "%susers/%s/%s", g_app->GetProfileDirectory(), g_app->m_userProfileName, missionFilename );    
        DeleteThisFile( saveFilename );

        //
        // Delete the game file 

        sprintf( saveFilename, "%susers/%s/game_demo2.txt", g_app->GetProfileDirectory(), g_app->m_userProfileName );
        DeleteThisFile( saveFilename );
    }

    g_app->m_levelReset = true;
    
}
void Tutorial::RepeatMessage( char *_stringId, float _repeatPeriod, char *_gestureDemo )
{
    if( m_repeatMessage )
    {
        delete m_repeatMessage;
        m_repeatMessage = NULL;
    }

    if( m_repeatGesture )
    {
        delete m_repeatGesture;
        m_repeatGesture = NULL;
    }

    if( _stringId )
    {
        m_repeatMessage = strdup( _stringId );
        m_repeatPeriod = _repeatPeriod;
        m_repeatMessageTimer = GetHighResTime() + m_repeatPeriod;
    }

    if( _gestureDemo )
    {
        m_repeatGesture = strdup( _gestureDemo );    
    }
}
void SoulLoader::Run()
{
    g_app->m_soundSystem->TriggerOtherEvent( NULL, "LoaderSoul", SoundSourceBlueprint::TypeMusic );

    while( !g_inputManager->controlEvent( ControlSkipMessage ) )
    {
        if( g_app->m_requestQuit ) break;
        glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );

        float oldTime = m_time;
        m_time = GetHighResTime();
        float timeThisFrame = m_time - oldTime;

        AdvanceAllSpirits( timeThisFrame );
        RenderAllSpirits();
        RenderMessage( timeThisFrame );

        g_windowManager->Flip();
		g_inputManager->Advance();
        g_inputManager->PollForEvents();
        Sleep(1);

        AdvanceSound();
    }

    g_app->m_soundSystem->StopAllSounds( WorldObjectId(), "Music LoaderSoul" );
}
Exemplo n.º 12
0
void EarthData::LoadCoastlines()
{
    double startTime = GetHighResTime();

    m_islands.EmptyAndDelete();

    int numIslands = 0;

    char coastFile[1024];
    if( g_preferences->GetInt(PREFS_GRAPHICS_LOWRESWORLD) == 0 )
    {
        strcpy(coastFile, "data/earth/coastlines.dat");
    }
    else
    {
        strcpy(coastFile, "data/earth/coastlines-low.dat");
    }

    TextReader *coastlines = g_fileSystem->GetTextReader( coastFile );
    AppAssert( coastlines && coastlines->IsOpen() );
    Island *island = NULL;
    
    while( coastlines->ReadLine() )
    {        
        char *line = coastlines->GetRestOfLine();
        if( line[0] == 'b' )
        {
            if( island )
            {           
                m_islands.PutData( island );                  
            }
            island = new Island();
            ++numIslands;
        }
        else
        {
            float longitude, latitude;
            sscanf( line, "%f %f", &longitude, &latitude );
            island->m_points.PutData( new Vector3<float>( longitude, latitude, 0.0f ) );            
        }
    }

    delete coastlines;

    double totalTime = GetHighResTime() - startTime;
    AppDebugOut( "Parsing Coastline data (%d islands) : %dms\n", numIslands, int( totalTime * 1000.0f ) );
}
	void MouseUp()
	{
		if (stricmp(m_name, LANGUAGEPHRASE("editor_generate")) == 0)
		{
			LandscapeDef *def = &g_app->m_location->m_levelFile->m_landscape;
			g_app->m_location->m_landscape.Init(def);
		}
		else if (stricmp(m_name, LANGUAGEPHRASE("editor_randomise")) == 0)
		{
			m_def->m_randomSeed = (int)(GetHighResTime() * 1000.0f);
			InputField *randomSeed = (InputField *)m_parent->GetButton(LANGUAGEPHRASE("editor_seed"));
			if (randomSeed)
			{
				randomSeed->Refresh();
			}
			LandscapeDef *def = &g_app->m_location->m_levelFile->m_landscape;
			g_app->m_location->m_landscape.Init(def);
		}
        else if( stricmp(m_name, LANGUAGEPHRASE("editor_delete")) == 0 )
        {
            int tileId = ((LandscapeTileEditWindow *) m_parent)->m_tileId;
            g_app->m_location->m_landscape.DeleteTile( tileId );
            EclRemoveWindow( m_parent->m_name );
        }
        else if( stricmp(m_name, LANGUAGEPHRASE("editor_clone")) == 0 )
        {
            Vector3 rayStart;
	        Vector3 rayDir;
	        g_app->m_camera->GetClickRay(g_app->m_renderer->ScreenW()/2, g_app->m_renderer->ScreenH()/2, &rayStart, &rayDir);
            Vector3 _pos;
            g_app->m_location->m_landscape.RayHit( rayStart, rayDir, &_pos );

            LandscapeDef *landscapeDef = &(g_app->m_location->m_levelFile->m_landscape);
    	    LandscapeTile *tile = new LandscapeTile();
    	    g_app->m_location->m_levelFile->m_landscape.m_tiles.PutDataAtEnd(tile);
            tile->m_size = m_def->m_size;
            tile->m_posX = _pos.x - tile->m_size/2;
            tile->m_posY = m_def->m_posY;
            tile->m_posZ = _pos.z - tile->m_size/2;
            tile->m_fractalDimension = m_def->m_fractalDimension;
            tile->m_heightScale = m_def->m_heightScale;
            tile->m_desiredHeight = m_def->m_desiredHeight;
            tile->m_randomSeed = m_def->m_randomSeed;
            tile->m_lowlandSmoothingFactor = m_def->m_lowlandSmoothingFactor;
            tile->m_generationMethod = m_def->m_generationMethod;

		    LandscapeDef *def = &g_app->m_location->m_levelFile->m_landscape;
            g_app->m_location->m_landscape.Init(def);

        }
        else if( stricmp(m_name, LANGUAGEPHRASE("editor_guidegrid")) == 0 )
        {
            int tileId = ((LandscapeTileEditWindow *) m_parent)->m_tileId;
            LandscapeGuideGridWindow *guide = new LandscapeGuideGridWindow(LANGUAGEPHRASE("editor_guidegrid"), tileId );
            guide->SetSize( 300, 300 );
            guide->SetPosition( m_parent->m_x + m_parent->m_w + 10, m_parent->m_y );
            EclRegisterWindow( guide, m_parent );
        }
	}
void AntHill::Initialise( Building *_template )
{
    Building::Initialise( _template );

    m_numAntsInside = ((AntHill *) _template)->m_numAntsInside;

    m_spawnTimer = GetHighResTime() + 5.0f;
}
void Officer::SetPreviousMode()
{
    static float lastOrderSet = 0.0f;

    float timeNow = GetHighResTime();
    int researchLevel = g_app->m_globalWorld->m_research->CurrentLevel( GlobalResearch::TypeOfficer );

    if( timeNow > lastOrderSet + 0.3f )
    {
        lastOrderSet = timeNow;

        switch( researchLevel )
        {
            case 0 :
            case 1 :
            case 2 :
                m_orders = OrderNone;
                break;

            case 3 :
                if      ( m_orders == OrderNone )       m_orders = OrderFollow;
                else if ( m_orders == OrderFollow )     m_orders = OrderNone;
                else if ( m_orders == OrderGoto )       m_orders = OrderNone;
                break;

            case 4 :
                if      ( m_orders == OrderNone )
                {
                    m_orders = OrderFollow;
                    m_absorb = true;
                }
                else if ( m_orders == OrderFollow && !m_absorb )    m_orders = OrderNone;
                else if ( m_orders == OrderFollow && m_absorb )
                {
                                                                    m_orders = OrderFollow;
                                                                    m_absorb = false;
                }
                else if ( m_orders == OrderGoto )                   m_orders = OrderNone;
                break;
        }

        CancelOrderSounds();

        switch( m_orders )
        {
            case OrderNone:     g_app->m_soundSystem->TriggerEntityEvent( this, "SetOrderNone" );       break;
            case OrderGoto:     g_app->m_soundSystem->TriggerEntityEvent( this, "SetOrderGoto" );       break;
            case OrderFollow:
                if( m_absorb )  g_app->m_soundSystem->TriggerEntityEvent( this, "SetOrderAbsorb" );
                else            g_app->m_soundSystem->TriggerEntityEvent( this, "SetOrderFollow" );
                break;
        }

        m_buildingId = -1;
    }
}
Exemplo n.º 16
0
SoundSystem::SoundSystem()
:   m_timeSync(0.0f),
    m_channels(NULL),
    m_numChannels(0),
    m_numMusicChannels(0),
    m_interface(NULL),
    m_propagateBlueprints(false)
{
    AppSeedRandom( (unsigned int) GetHighResTime() );
}
Exemplo n.º 17
0
void EclRender ()
{

    bool maximiseRender = false;

    //
    // Render any maximised Window?

    if( strcmp( maximisedWindow, "None" ) != 0 )
    {
        EclWindow *maximised = EclGetWindow( maximisedWindow );
        if( maximised )
        {
            maximised->Render( true );
            maximiseRender = true;
        }
        else
        {
            EclUnMaximise();
        }
    }

    if( !maximiseRender )
    {
        for ( int i = windows.Size() - 1; i >= 0; --i )
        {
            EclWindow *window = windows.GetData(i);
            bool hasFocus = ( strcmp ( window->m_name, windowFocus ) == 0 );
            
            START_PROFILE( window->m_name );
            window->Render( hasFocus );
            END_PROFILE( window->m_name );
        }
    }


    //
    // Render the tooltip

    if( tooltipTimer > 0.0f && tooltipCallback )
    {
        EclWindow *window = EclGetWindow();
        if( window )
        {
            EclButton *button = window->GetButton( EclGetCurrentButton() );
            {
                if( button )
                {
                    float timer = GetHighResTime() - tooltipTimer;
                    tooltipCallback( window, button, timer );
                }
            }
        }
    }
}
Exemplo n.º 18
0
void DumpSyncLogs( char *syncId )
{
    static float s_lastDump = 0.0f;
    if( GetHighResTime() > s_lastDump + 10.0f )
    {
        s_lastDump = GetHighResTime();

        char filename[256];
        sprintf( filename, "synclog %s c%d.txt", 
                            syncId, 
                            g_app->GetClientToServer()->m_clientId );
        
        if( !DoesFileExist( filename ) )
        {
            DumpSyncRandLog( filename );
            DumpWorldToSyncLog( filename );

            AppDebugOut( "SYNCERROR log dumped to '%s'\n", filename );
        }
    }
}
Exemplo n.º 19
0
void UpdateAdvanceTime()
{
    double realTime = GetHighResTime();
	g_advanceTime = float(realTime - g_gameTime);
	if (g_advanceTime > 0.25f)
	{
		g_advanceTime = 0.25f;
	}
	g_gameTime = realTime;
    g_predictionTime = float(realTime - g_lastServerAdvance) - 0.1f;
    g_predictionTime = min( g_predictionTime, 1.0f );
}
bool StartSequence::Advance()
{
    static bool started = false;
    if( GetHighResTime() > m_startTime && !started )
    {
        started = true;
        g_app->m_soundSystem->TriggerOtherEvent( NULL, "StartSequence", SoundSourceBlueprint::TypeMusic );
	    g_app->m_camera->SetDebugMode(Camera::DebugModeAuto);
        g_app->m_camera->RequestMode(Camera::ModeSphereWorldIntro);
    }

    g_inputManager->PollForEvents();

	if( !g_eventHandler->WindowHasFocus() )
    {
		Sleep(1);
		g_app->m_userInput->Advance();
		return false;
    }

    if( g_inputManager->controlEvent( ControlSkipMessage ) ||
		g_app->m_requestQuit ||
		( GetHighResTime() - m_startTime ) > 90 )
    {
        g_app->m_soundSystem->StopAllSounds( WorldObjectId(), "Music StartSequence" );
        return true;
    }

    g_app->m_userInput->Advance();
    g_app->m_camera->Advance();
    g_app->m_soundSystem->Advance();
#ifdef PROFILER_ENABLED
	g_app->m_profiler->Advance();
#endif // PROFILER_ENABLED

    g_app->m_renderer->Render();

    return false;
}
Exemplo n.º 21
0
void SoundLibrary2dWin32::TopupBuffer()
{
	if (m_wavOutput)
	{
		static double nextOutputTime = -1.0;
		if (nextOutputTime < 0.0) nextOutputTime = GetHighResTime();
		
		if (GetHighResTime() > nextOutputTime)
		{
			StereoSample buf[5000];
			int samplesPerSecond = g_prefsManager->GetInt("SoundMixFreq", 44100);
			int samplesPerUpdate = (int)((double)samplesPerSecond / 20.0);
			g_soundLibrary2d->m_callback(buf, samplesPerUpdate);
			fwrite(buf, samplesPerUpdate, sizeof(StereoSample), m_wavOutput);
			nextOutputTime += 1.0 / 20.0;
		}
	}
	else
	{
		while (m_fillsRequested)
		{
			SoundLib2dBuf *buf = &m_buffers[m_nextBuffer];

			g_soundLibrary2d->m_callback(buf->m_buffer, g_soundLibrary2d->m_samplesPerBuffer);

			int result = waveOutWrite(s_device, &buf->m_header, sizeof(WAVEHDR));
			if (result != MMSYSERR_NOERROR)
			{
				break;
			}
			else
			{
				m_nextBuffer++;
				m_nextBuffer %= m_numBuffers;
				m_fillsRequested--;
			}
		}
	}
}
Exemplo n.º 22
0
bool City::Update()
{
    double realTimeNow = GetHighResTime();
    if( realTimeNow > m_nukeCountTimer )
    {
        g_app->GetWorld()->GetNumNukers( m_objectId, &m_numNukesInFlight, &m_numNukesInQueue );
        m_nukeCountTimer = realTimeNow + 2;
    }


    // deliberately don't call WorldObject::Update

    return false;
}
Exemplo n.º 23
0
void Tutorial::Update()
{
    //
    // If the world is not yet initialised, do that now

    if( !m_worldInitialised )
    {
        InitialiseWorld();
    }

    
    //
    // Is it time to run the next chapter?

    if( m_nextChapter != -1 && GetHighResTime() >= m_nextChapterTimer )
    {
        //
        // Reset everything for the start of a new chapter

        m_currentChapter = m_nextChapter;
        m_nextChapter = -1;
        m_messageTimer = GetHighResTime();
                
        SetObjectHighlight();

        SetupCurrentChapter();
    }

    
    //
    // Advance the current chapter

    if( m_currentChapter > -1 )
    {
        UpdateCurrentChapter();
    }
}
Exemplo n.º 24
0
void EarthData::LoadBorders()
{
    double startTime = GetHighResTime();
    
    m_borders.EmptyAndDelete();

    int numIslands = 0;    
    Island *island = NULL;

    TextReader *international = g_fileSystem->GetTextReader( "data/earth/international.dat" );
    AppAssert( international && international->IsOpen() );

    while( international->ReadLine() )
    {
        char *line = international->GetRestOfLine();        
        if( line[0] == 'b' )
        {
            if( island )
            {
                m_borders.PutData( island );                  
                ++numIslands;
            }
            island = new Island();            
        }
        else
        {
            float longitude, latitude;
            sscanf( line, "%f %f", &longitude, &latitude );
            island->m_points.PutData( new Vector3<float>( longitude, latitude, 0.0f ) );
        }
    }
    
    delete international;

    double totalTime = GetHighResTime() - startTime;
    AppDebugOut( "Parsing International data (%d islands) : %dms\n", numIslands, int( totalTime * 1000.0f ) );
}
void BandwidthCounter::Count( unsigned _numBytes )
{
	const double interval = 5.0;
	double now = GetHighResTime();
	double period = now - m_since;

	if( period > interval )
	{
		m_rate = m_count / period;
		m_count = 0;
		m_since = now;
	}

	m_count += _numBytes;
}
void Tutorial::SetChapter( int _chapter )
{
    if( _chapter == 0 )
    {
        m_chapter = 0;
    }
    else if( _chapter > 0 )
    {
        m_chapter = _chapter-1;
        m_nextChapterTimer = GetHighResTime() + 3;
    }
    else
    {
        m_chapter = -1;
    }
}
Exemplo n.º 27
0
void Tutorial::RunNextChapter( float _pause, int _chapter )
{
    if( m_nextChapter != -1 ) 
    {
        // We are already waiting to start the next chapter
        return;
    }

    if( _chapter == -1 )
    {
        _chapter = m_currentChapter + 1;
    }

    m_nextChapter = _chapter;
    m_nextChapterTimer = GetHighResTime() + _pause;
}
void DirectSoundChannel::UpdateSimulatedPlayCursor(long _playCursor)
{
	double timeNow = GetHighResTime();

	if (_playCursor < 0)
	{
		double timeSinceLastUpdate = timeNow - m_lastUpdate;
		m_simulatedPlayCursor += timeSinceLastUpdate * (double)m_freq * 2.0;
		m_simulatedPlayCursor %= m_numBufferSamples * 2;
		m_simulatedPlayCursor &= 0xfffffffe;
	}
	else
	{
		m_simulatedPlayCursor = _playCursor;
	}

	m_lastUpdate = timeNow;
}
bool Demo2Tutorial::IsPlayerBusy()
{
    float timeNow = GetHighResTime();

    //
    // See if we are doing squaddie things

    if( g_app->m_location->GetMyTeam() )
    {
        Unit *currentUnit = g_app->m_location->GetMyTeam()->GetMyUnit();
        if( currentUnit && currentUnit->m_troopType == Entity::TypeInsertionSquadie )
        {
            if( g_inputManager->controlEvent( ControlUnitPrimaryFireTarget ) )
            {
                // We are firing lasers
                s_playerBusyTimer = timeNow;
                return true;
            }

            Vector3 wayPoint = currentUnit->GetWayPoint();
            if( g_app->m_location->m_entityGrid->AreEnemiesPresent( wayPoint.x, wayPoint.z, 100, 2 ) )
            {
                // Enemies near our squaddie waypoint
                s_playerBusyTimer = timeNow;
                return true;
            }
        }
    }


    //
    // Under timer?

    if( timeNow < s_playerBusyTimer + 3.0f )
    {
        return true;
    }


    //
    // The player isn't busy

    return false;
}
SoulLoader::SoulLoader()
:   Loader()
{
    float fov = 20.0f;
    float nearPlane = 1.0f;
    float farPlane = 10000.0f;
    float screenW = g_app->m_renderer->ScreenW();
    float screenH = g_app->m_renderer->ScreenH();

	glMatrixMode(GL_PROJECTION);
	glLoadIdentity();
	gluPerspective(fov, screenW / screenH, nearPlane, farPlane);
    glMatrixMode(GL_MODELVIEW);
    glLoadIdentity();

    Vector3 pos(0,0,0);
	Vector3 front(0,0,-1);
	Vector3 up(0,1,0);
    Vector3 forwards = pos + front;
	gluLookAt(pos.x, pos.y, pos.z,
              forwards.x, forwards.y, forwards.z,
              up.x, up.y, up.z);

    glDisable( GL_CULL_FACE );
    glDisable( GL_TEXTURE_2D );
    glEnable( GL_BLEND );
    glBlendFunc( GL_SRC_ALPHA, GL_ONE );
    glDisable( GL_LIGHTING );
    glDisable( GL_DEPTH_TEST );

    float fogCol[] = {  0, 0, 0, 0 };

    glFogf      ( GL_FOG_DENSITY, 1.0f );
    glFogf      ( GL_FOG_START, 50.0f );
    glFogf      ( GL_FOG_END, 1500.0f );
    glFogfv     ( GL_FOG_COLOR, fogCol );
    glFogi      ( GL_FOG_MODE, GL_LINEAR );
    glEnable    ( GL_FOG );

    m_spawnTimer = 0.0f;
    m_time = GetHighResTime();
    m_startTime = m_time;
}