metaforce/Runtime/MP1/main.cpp

284 lines
7.7 KiB
C++
Raw Normal View History

2015-08-17 05:26:58 +00:00
#include <memory>
2015-08-18 22:51:54 +00:00
#include <boo/boo.hpp>
2015-08-17 05:26:58 +00:00
#include "COsContext.hpp"
#include "CBasics.hpp"
#include "CTweaks.hpp"
2015-08-17 20:33:58 +00:00
#include "CMemory.hpp"
2015-08-17 05:26:58 +00:00
#include "CMemoryCardSys.hpp"
2015-08-17 20:33:58 +00:00
#include "CResFactory.hpp"
#include "CSimplePool.hpp"
2015-08-17 23:46:41 +00:00
#include "Character/CAssetFactory.hpp"
#include "CAi.hpp"
#include "CGameState.hpp"
#include "CInGameTweakManager.hpp"
2015-08-18 05:54:43 +00:00
#include "Particle/CElementGen.hpp"
#include "Character/CAnimData.hpp"
#include "Particle/CDecalManager.hpp"
#include "Graphics/CBooRenderer.hpp"
#include "Audio/CAudioSys.hpp"
#include "Input/CInputGenerator.hpp"
#include "GuiSys/CGuiSys.hpp"
#include "CIOWinManager.hpp"
#include "GuiSys/CSplashScreen.hpp"
#include "CMainFlow.hpp"
#include "GuiSys/CConsoleOutputWindow.hpp"
#include "Audio/CAudioStateWin.hpp"
#include "GameGlobalObjects.hpp"
2015-08-17 05:26:58 +00:00
namespace Retro
2015-08-17 05:26:58 +00:00
{
2015-08-18 05:54:43 +00:00
CMemoryCardSys* g_MemoryCardSys = nullptr;
CResFactory* g_ResFactory = nullptr;
CSimplePool* g_SimplePool = nullptr;
CCharacterFactoryBuilder* g_CharFactoryBuilder = nullptr;
CAiFuncMap* g_AiFuncMap = nullptr;
CGameState* g_GameState = nullptr;
CInGameTweakManager* g_TweakManager = nullptr;
CBooRenderer* g_Renderer = nullptr;
namespace MP1
{
2015-08-18 05:54:43 +00:00
class CGameGlobalObjects
{
2015-08-18 22:51:54 +00:00
CMemoryCardSys m_memoryCardSys;
CResFactory m_resFactory;
CSimplePool m_simplePool;
CCharacterFactoryBuilder m_charFactoryBuilder;
CAiFuncMap m_aiFuncMap;
CGameState m_gameState;
CInGameTweakManager m_tweakManager;
std::unique_ptr<CBooRenderer> m_renderer;
2015-08-18 05:54:43 +00:00
void AddPaksAndFactories()
{
}
void LoadStringTable()
{
}
2015-08-18 22:51:54 +00:00
static CBooRenderer*
AllocateRenderer(IObjectStore& store, COsContext& osctx,
CMemorySys& memSys, CResFactory& resFactory)
2015-08-18 05:54:43 +00:00
{
2015-08-18 22:51:54 +00:00
g_Renderer = new CBooRenderer(store, osctx, memSys, resFactory);
return g_Renderer;
2015-08-18 05:54:43 +00:00
}
2015-08-17 23:46:41 +00:00
2015-08-17 05:26:58 +00:00
public:
2015-08-18 05:54:43 +00:00
CGameGlobalObjects()
: m_simplePool(m_resFactory)
{
2015-08-18 22:51:54 +00:00
g_MemoryCardSys = &m_memoryCardSys;
g_ResFactory = &m_resFactory;
g_SimplePool = &m_simplePool;
g_CharFactoryBuilder = &m_charFactoryBuilder;
g_AiFuncMap = &m_aiFuncMap;
g_GameState = &m_gameState;
g_TweakManager = &m_tweakManager;
2015-08-18 05:54:43 +00:00
}
2015-08-18 22:51:54 +00:00
void PostInitialize(COsContext& osctx, CMemorySys& memSys)
2015-08-18 05:54:43 +00:00
{
AddPaksAndFactories();
LoadStringTable();
m_renderer.reset(AllocateRenderer(m_simplePool, osctx, memSys, m_resFactory));
}
};
class CGameArchitectureSupport
{
2015-08-18 22:51:54 +00:00
CAudioSys m_audioSys;
CInputGenerator m_inputGenerator;
CGuiSys m_guiSys;
CIOWinManager m_ioWinManager;
CSplashScreen m_splashScreen;
CMainFlow m_mainFlow;
CConsoleOutputWindow m_consoleWindow;
CAudioStateWin m_audioStateWin;
2015-08-18 05:54:43 +00:00
public:
2015-08-18 22:51:54 +00:00
CGameArchitectureSupport(COsContext& osctx)
2015-08-18 05:54:43 +00:00
: m_audioSys(0,0,0,0,0)
2015-08-17 20:33:58 +00:00
{
}
2015-08-17 05:26:58 +00:00
};
2015-08-18 22:51:54 +00:00
class CMain : public COsContext
2015-08-17 05:26:58 +00:00
{
2015-08-18 22:51:54 +00:00
CMemorySys m_memSys;
CTweaks m_tweaks;
2015-08-17 20:33:58 +00:00
bool m_run = true;
2015-08-17 05:26:58 +00:00
public:
CMain()
2015-08-18 22:51:54 +00:00
: m_memSys(*this, CMemorySys::GetGameAllocator())
2015-08-17 05:26:58 +00:00
{
OpenWindow("", 0, 0, 640, 480);
}
void InitializeSubsystems()
2015-08-18 05:54:43 +00:00
{
2015-08-18 22:51:54 +00:00
CElementGen::Initialize();
CAnimData::InitializeCache();
CDecalManager::Initialize();
2015-08-18 05:54:43 +00:00
}
void AddWorldPaks()
{
}
void FillInAssetIDs()
2015-08-17 05:26:58 +00:00
{
}
int RsMain(int argc, const char* argv[])
{
2015-08-18 22:51:54 +00:00
TOneStatic<CGameGlobalObjects> globalObjs;
2015-08-17 20:33:58 +00:00
InitializeSubsystems();
globalObjs->PostInitialize(*this, m_memSys);
2015-08-18 05:54:43 +00:00
m_tweaks.RegisterTweaks();
AddWorldPaks();
2015-08-18 22:51:54 +00:00
g_TweakManager->ReadFromMemoryCard("AudioTweaks");
2015-08-18 05:54:43 +00:00
FillInAssetIDs();
2015-08-18 22:51:54 +00:00
TOneStatic<CGameArchitectureSupport> archSupport(*this);
2015-08-17 20:33:58 +00:00
while (m_run)
{
}
2015-08-17 05:26:58 +00:00
return 0;
}
};
}
}
2015-08-18 22:51:54 +00:00
struct WindowCallback : boo::IWindowCallback
{
void mouseDown(const SWindowCoord& coord, EMouseButton button, EModifierKey mods)
{
fprintf(stderr, "Mouse Down %d (%f,%f)\n", button, coord.norm[0], coord.norm[1]);
}
void mouseUp(const SWindowCoord& coord, EMouseButton button, EModifierKey mods)
{
fprintf(stderr, "Mouse Up %d (%f,%f)\n", button, coord.norm[0], coord.norm[1]);
}
void mouseMove(const SWindowCoord& coord)
{
//fprintf(stderr, "Mouse Move (%f,%f)\n", coord.norm[0], coord.norm[1]);
}
void scroll(const SWindowCoord& coord, const SScrollDelta& scroll)
{
fprintf(stderr, "Mouse Scroll (%f,%f) (%f,%f)\n", coord.norm[0], coord.norm[1], scroll.delta[0], scroll.delta[1]);
}
void touchDown(const STouchCoord& coord, uintptr_t tid)
{
//fprintf(stderr, "Touch Down %16lX (%f,%f)\n", tid, coord.coord[0], coord.coord[1]);
}
void touchUp(const STouchCoord& coord, uintptr_t tid)
{
//fprintf(stderr, "Touch Up %16lX (%f,%f)\n", tid, coord.coord[0], coord.coord[1]);
}
void touchMove(const STouchCoord& coord, uintptr_t tid)
{
//fprintf(stderr, "Touch Move %16lX (%f,%f)\n", tid, coord.coord[0], coord.coord[1]);
}
void charKeyDown(unsigned long charCode, EModifierKey mods, bool isRepeat)
{
}
void charKeyUp(unsigned long charCode, EModifierKey mods)
{
}
void specialKeyDown(ESpecialKey key, EModifierKey mods, bool isRepeat)
{
}
void specialKeyUp(ESpecialKey key, EModifierKey mods)
{
}
void modKeyDown(EModifierKey mod, bool isRepeat)
{
}
void modKeyUp(EModifierKey mod)
{
}
};
struct DolphinSmashAdapterCallback : boo::IDolphinSmashAdapterCallback
{
void controllerConnected(unsigned idx, boo::EDolphinControllerType)
{
printf("CONTROLLER %u CONNECTED\n", idx);
}
void controllerDisconnected(unsigned idx, boo::EDolphinControllerType)
{
printf("CONTROLLER %u DISCONNECTED\n", idx);
}
void controllerUpdate(unsigned idx, boo::EDolphinControllerType,
const boo::DolphinControllerState& state)
{
printf("CONTROLLER %u UPDATE %d %d\n", idx, state.m_leftStick[0], state.m_leftStick[1]);
}
};
class ApplicationDeviceFinder : public boo::DeviceFinder
{
std::unique_ptr<boo::DolphinSmashAdapter> smashAdapter = NULL;
DolphinSmashAdapterCallback m_cb;
public:
ApplicationDeviceFinder()
: boo::DeviceFinder({typeid(boo::DolphinSmashAdapter)})
{}
void deviceConnected(boo::DeviceToken& tok)
{
if (!smashAdapter)
{
smashAdapter.reset(dynamic_cast<boo::DolphinSmashAdapter*>(tok.openAndGetDevice()));
smashAdapter->setCallback(&m_cb);
smashAdapter->startRumble(0);
}
}
void deviceDisconnected(boo::DeviceToken&, boo::DeviceBase* device)
{
if (smashAdapter.get() == device)
smashAdapter.reset(nullptr);
}
};
struct ApplicationCallback : boo::IApplicationCallback
{
boo::IWindow* mainWindow = NULL;
ApplicationDeviceFinder devFinder;
WindowCallback windowCallback;
void appLaunched(boo::IApplication* app)
{
mainWindow = app->newWindow("YAY!");
mainWindow->setCallback(&windowCallback);
mainWindow->showWindow();
devFinder.startScanning();
}
void appQuitting(boo::IApplication*)
{
delete mainWindow;
}
void appFilesOpen(boo::IApplication*, const std::vector<std::string>& paths)
{
fprintf(stderr, "OPENING: ");
for (const std::string& path : paths)
fprintf(stderr, "%s ", path.c_str());
fprintf(stderr, "\n");
}
};
2015-08-17 05:26:58 +00:00
int main(int argc, const char* argv[])
{
2015-08-18 23:30:23 +00:00
Retro::TOneStatic<ApplicationCallback> appCB;
2015-08-18 22:51:54 +00:00
std::unique_ptr<boo::IApplication> app =
2015-08-18 23:30:23 +00:00
boo::ApplicationBootstrap(boo::IApplication::PLAT_AUTO, *appCB,
2015-08-18 22:51:54 +00:00
"mp1", "MP1", argc, argv);
2015-08-18 23:30:23 +00:00
Retro::TOneStatic<Retro::MP1::CMain> main;
return main->RsMain(argc, argv);
2015-08-17 05:26:58 +00:00
}