<commit_before>//
//  SwingGame.cpp
//  SwingGame
//
//  Created by <NAME> on 26/09/2014.
//  Copyright (c) 2014 tbrier. All rights reserved.
//

// =============================================================================
// Include Files
// -----------------------------------------------------------------------------
#include "CSwingGame.hpp"
#include "CTextFrontEnd.hpp"
#include "CTextureBank.hpp"
#include "CLevel.hpp"
#include "GameOptions.hpp"
#include "DebugOptions.hpp"
#include "SystemUtilities.hpp"
#include <sstream>

// =============================================================================
// Static members
// -----------------------------------------------------------------------------
bool                        CSwingGame::smExitRequested = false;
EGameState                  CSwingGame::smGameState = kGameStateFrontEnd;
std::list<CUpdateable *>    CSwingGame::smTheUpdateables;
std::list<CUpdateable *>    CSwingGame::smTheUpdateablesToAdd;
std::list<CUpdateable *>    CSwingGame::smTheUpdateablesToRemove;
std::list<CRenderable *>    CSwingGame::smTheRenderables;
CGameLocation               *CSwingGame::smCurrentLocation = NULL;

// =============================================================================
// Non member variables
// -----------------------------------------------------------------------------
#if SG_DEBUG
CDebugHelper *theDebugHelper;
#endif

// =============================================================================
// CSwingGame constructor/destructor
// -----------------------------------------------------------------------------
CSwingGame::CSwingGame() :  mWindowTitle("SwingGame v0.0"),
                            mWindow(NULL),
                            mFPS(0),
                            mUPS(0),
                            mExitCode(EXIT_SUCCESS)
{
    
}

CSwingGame::~CSwingGame()
{
    
}

// =============================================================================
// SwingGame::Init
// Initialise the game
// -----------------------------------------------------------------------------
void CSwingGame::Init()
{
    // Create the game window
    mWindow = new CWindow(GameOptions::windowWidth,
                          GameOptions::windowHeight,
                          mWindowTitle);
    
    // Enter the front end menu
    GoToLocation(kGameLocationFrontEnd);
    
    // Initialise other systems
    SystemUtilities::Init(mWindow);
    InitSFML(mWindow);
    
    // Create and register any lifetime updateables
#if SG_DEBUG
    theDebugHelper = new CDebugHelper();
    RegisterUpdateable(theDebugHelper);
#endif
}

// =============================================================================
// SwingGame::Run
// Enter the main loop, returns program exit code
// -----------------------------------------------------------------------------
int CSwingGame::Run()
{
    CClock theClock;
    
    while (mWindow->isOpen())
    {
        CTime elapsedTime = theClock.restart();
        
        static CTime accumulatingTime;
        accumulatingTime += elapsedTime;
        
        ProcessEvents();
        
        Update(elapsedTime);
        
        // Only render if vsync is off or enough time has past
        if (!GameOptions::doVsync
            || accumulatingTime.asSeconds() >= 1.0f / GameOptions::maxFPS)
        {
            accumulatingTime = CTime::Zero;
            Render();
        }
    }
    
    return mExitCode;
}

// =============================================================================
// SwingGame::Cleanup
// Cleanup before quitting
// -----------------------------------------------------------------------------
void CSwingGame::Cleanup()
{
    SAFE_DELETE(mWindow);
    SAFE_DELETE(smCurrentLocation);
#if SG_DEBUG
    SAFE_DELETE(theDebugHelper);
#endif
    TextUtilities::Cleanup();
    CTextureBank::Cleanup();
}
<commit_msg>Use a seperate clock for update time and vsync Will make it easier to limit update rate<commit_after>//
//  SwingGame.cpp
//  SwingGame
//
//  Created by <NAME> on 26/09/2014.
//  Copyright (c) 2014 tbrier. All rights reserved.
//

// =============================================================================
// Include Files
// -----------------------------------------------------------------------------
#include "CSwingGame.hpp"
#include "CTextFrontEnd.hpp"
#include "CTextureBank.hpp"
#include "CLevel.hpp"
#include "GameOptions.hpp"
#include "DebugOptions.hpp"
#include "SystemUtilities.hpp"
#include <sstream>

// =============================================================================
// Static members
// -----------------------------------------------------------------------------
bool                        CSwingGame::smExitRequested = false;
EGameState                  CSwingGame::smGameState = kGameStateFrontEnd;
std::list<CUpdateable *>    CSwingGame::smTheUpdateables;
std::list<CUpdateable *>    CSwingGame::smTheUpdateablesToAdd;
std::list<CUpdateable *>    CSwingGame::smTheUpdateablesToRemove;
std::list<CRenderable *>    CSwingGame::smTheRenderables;
CGameLocation               *CSwingGame::smCurrentLocation = NULL;

// =============================================================================
// Non member variables
// -----------------------------------------------------------------------------
#if SG_DEBUG
CDebugHelper *theDebugHelper;
#endif

// =============================================================================
// CSwingGame constructor/destructor
// -----------------------------------------------------------------------------
CSwingGame::CSwingGame() :  mWindowTitle("SwingGame v0.0"),
                            mWindow(NULL),
                            mFPS(0),
                            mUPS(0),
                            mExitCode(EXIT_SUCCESS)
{
    
}

CSwingGame::~CSwingGame()
{
    
}

// =============================================================================
// SwingGame::Init
// Initialise the game
// -----------------------------------------------------------------------------
void CSwingGame::Init()
{
    // Create the game window
    mWindow = new CWindow(GameOptions::windowWidth,
                          GameOptions::windowHeight,
                          mWindowTitle);
    
    // Enter the front end menu
    GoToLocation(kGameLocationFrontEnd);
    
    // Initialise other systems
    SystemUtilities::Init(mWindow);
    InitSFML(mWindow);
    
    // Create and register any lifetime updateables
#if SG_DEBUG
    theDebugHelper = new CDebugHelper();
    RegisterUpdateable(theDebugHelper);
#endif
}

// =============================================================================
// SwingGame::Run
// Enter the main loop, returns program exit code
// -----------------------------------------------------------------------------
int CSwingGame::Run()
{
    CClock  theUpdateClock;
    CClock  theRenderClock;
    CTime   timeSinceLastRender = CTime::Zero;
    
    while (mWindow->isOpen())
    {
        ProcessEvents();
        
        CTime timeSinceLastUpdate = theUpdateClock.restart();
        Update(timeSinceLastUpdate);
        
        // Only render if vsync is off or enough time has past
        timeSinceLastRender += theRenderClock.restart();
        if (!GameOptions::doVsync
            || timeSinceLastRender.asSeconds() >= 1.0f / GameOptions::maxFPS)
        {
            timeSinceLastRender = CTime::Zero;
            Render();
        }
    }
    
    return mExitCode;
}

// =============================================================================
// SwingGame::Cleanup
// Cleanup before quitting
// -----------------------------------------------------------------------------
void CSwingGame::Cleanup()
{
    SAFE_DELETE(mWindow);
    SAFE_DELETE(smCurrentLocation);
#if SG_DEBUG
    SAFE_DELETE(theDebugHelper);
#endif
    TextUtilities::Cleanup();
    CTextureBank::Cleanup();
}

{'fraction_non_alphanumeric': 0.355794806839772, 'fraction_numerical': 0.004559848005066498, 'mean_word_length': 1.8515709642470206, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 19, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5177149', 'n_tokens_mistral': 1900, 'n_tokens_neox': 1798, 'n_words': 356}