/*
File Name: GOC.cpp
Created By: Andy Odle
Date: July 27, 2009

Description: 
    
    
*/

#include "./source/inc/GOC.h"
#include "./source/PlatformSpecific/inc/GeneralPurposeFunctions.h"
#include "./source/inc/SpriteManager.h"
#include "./source/inc/SoundManager.h"

GOC *GOC::goc_m = NULL;

GOC::GOC()
{
    errorReport_m = new ErrorReport("GOC-ErrorReport");
}

GOC* GOC::goc_i()
{
    if(!goc_m)
    {
        goc_m = new GOC();
    }
    
    return goc_m;
}

#ifdef _WIN32

    void GOC::LoadGOC(HINSTANCE &hinstance_p)
    {
        UniqueNumber::uniqueNumber_i();
        
        SpriteManager::spriteManager_i()->InitilizeSpriteManager(); // Initilze sprite managment.

        SoundManager::soundManager_i()->InitilizeSoundManager(); // Initilize sound managment.
        
        WindowManager::winManager_i()->SetWindowInstance(hinstance_p);
        WindowManager::winManager_i()->CreateWindowWin();
        
        // Start the message pump.
        WindowManager::winManager_i()->ApplicationLoop();  
    }


#else

    void GOC::LoadGOC()
    {
        UniqueNumber::uniqueNumber_i();
        
        SpriteManager::spriteManager_i()->InitilizeSpriteManager(); // Initilze sprite managment.

        SoundManager::soundManager_i()->InitilizeSoundManager(); // Initilize sound managment.   

        WindowManager::winManager_i()->CreateWindow();
        
        WindowManager::winManager_i()->ApplicationLoop();
    }

#endif

int GOC::GetWindowWidth()
{
    Render2D::render2D_i()->GetWidth();
}

int GOC::GetWindowHeight()
{
    Render2D::render2D_i()->GetHeight();
}

void GOC::UnloadGOC()
{
    delete goc_m;
}

ErrorReport *GOC::GetErrorReport()
{
    return errorReport_m;
}

GOC::~GOC()
{
    SoundManager::soundManager_i()->DestroySoundManager(); // Destroy sound managment.

    SpriteManager::spriteManager_i()->DestroySpriteManager(); // Destroy sprite managment.

    delete errorReport_m;
}
