29#include "Pac-Man_Evolution.h"
32#include "ResourceManager.h"
34#include "BrainsFactory.h"
35#include "EVNTrainer.h"
38GlobalStatus globalStatus;
41GameField* pGameField =
nullptr;
43Sint32 renderWrapper(Sint32 iMode,
void* pData)
47 switch(globalStatus.iRenderScreen)
50 if(pMenu !=
nullptr) iRet = pMenu->render(iMode);
53 if(pHoF !=
nullptr) iRet = pHoF->render(iMode);
56 if(pGameField !=
nullptr) iRet = pGameField->render(iMode);
61#include "ArtificialNeuralNet.h"
64int main(
int argc,
char* argv[])
66 Sint32 iDone = PME_ENTRY, i;
71 CMem::setLogLevel(CMem::eMemStatsLevel::MSL_NORMAL);
72 atexit(CMem::destroy);
75 Main& mC64 = Main::Instance();
76 Log& mLog = *mC64.ILogMgr().get();
77 mLog.init(GAME_VERSION, LL_HIGH, LM_FILE | LM_STDOUT,
"Pac-Man_Evolution.log");
79 mC64.ITimer().setRate(60, PME_LOGIC_RATE);
80 mC64.IConfigMgr().iMTFriendly = 1;
83 pScreen = mC64.IConfigMgr().get();
84 pScreen->setDriver(CRD_OPENGL);
85 pScreen->setSize(1024, 768);
87 pScreen->setTitle(GAME_VERSION);
88 if(pScreen->show() < 0)
93 pScreen->setRenderCallback(renderWrapper);
94 mC64.IConfigMgr().audioInit(AF_HIGH, AS_16, AM_STEREO);
97 if(ResourceManager::Instance().load() != 0)
99 mC64.IConfigMgr().audioClose();
100 ResourceManager::Terminate();
104 pScreen->setIcon(mC64.IImageMgr().get(ResourceManager::Instance().get(RM_IMG_ICON))->getSurface());
107 pMenu =
new(std::nothrow) Menu();
108 pHoF =
new(std::nothrow) HoF();
109 pGameField =
new(std::nothrow) GameField(&globalStatus);
136 while(iDone != PME_EXIT)
139 if(iDone == PME_ENTRY)
141 mC64.IMusicMgr().get(ResourceManager::Instance().get(RM_MUS_MENU))->play(-1);
142 pScreen->fadeToImage(ResourceManager::Instance().get(RM_IMG_MENU), 500);
143 mC64.ICursorMgr().show();
144 mC64.IGUIMgr().getPanel(ResourceManager::Instance().get(RM_PANEL_MENU))->baseWidget().show();
145 globalStatus.clear();
146 globalStatus.iRenderScreen = PME_SCREEN_MENU;
151 else if((iDone == PME_GAME_STANDARD) || (iDone == PME_GAME_EVOLUTION))
154 mC64.ICursorMgr().hide();
155 mC64.IGUIMgr().getPanel(ResourceManager::Instance().get(RM_PANEL_MENU))->baseWidget().hide();
157 globalStatus.iHighestScore = pHoF->getHighest(iDone);
158 globalStatus.iLowestScore = pHoF->getLowest(iDone);
159 globalStatus.iGameType = iDone;
160 iDone = pGameField->init();
161 while(iDone == PME_LOOP)
163 iDone = pGameField->execute();
164 if(iDone == PME_MAZE_END) iDone = pGameField->nextMaze();
167 pHoF->store(globalStatus.iGameType, globalStatus.iPoints, globalStatus.szName);
172 else if(iDone == PME_GAME_WORKBENCH)
175 mC64.ICursorMgr().hide();
176 mC64.IGUIMgr().getPanel(ResourceManager::Instance().get(RM_PANEL_MENU))->baseWidget().hide();
179 globalStatus.workBench.iExecutions = 1;
180 globalStatus.workBench.iSpeed = 3;
181 globalStatus.workBench.iTime = 0;
182 globalStatus.workBench.iPacManBrain = PME_BRAIN_TYPE_FIXED;
183 globalStatus.workBench.iGhostRedBrain = PME_BRAIN_TYPE_EVOLVED;
184 globalStatus.workBench.iGhostPinkBrain = PME_BRAIN_TYPE_EVOLVED;
185 globalStatus.workBench.iGhostBlueBrain = PME_BRAIN_TYPE_EVOLVED;
186 globalStatus.workBench.iGhostOrangeBrain = PME_BRAIN_TYPE_EVOLVED;
191 mC64.ITimer().setRate(60, PME_LOGIC_RATE * globalStatus.workBench.iSpeed);
193 FILE* fp = fopen(globalStatus.workBench.szOutputCSV,
"wt");
195 while(i < globalStatus.workBench.iExecutions)
197 globalStatus.iHighestScore = pHoF->getHighest(iDone);
198 globalStatus.iLowestScore = pHoF->getLowest(iDone);
199 globalStatus.iGameType = PME_GAME_WORKBENCH;
200 iDone = pGameField->init();
201 while(iDone == PME_LOOP)
203 iDone = pGameField->execute();
204 if(iDone == PME_MAZE_END) iDone = pGameField->nextMaze();
208 fprintf(fp,
"%d,", globalStatus.iPoints);
213 globalStatus.iPoints = 0;
217 mC64.ITimer().setRate(60, PME_LOGIC_RATE);
222 else if(iDone == PME_HOF)
224 pScreen->fadeToImage(ResourceManager::Instance().get(RM_IMG_HOF), 250);
225 mC64.IGUIMgr().getPanel(ResourceManager::Instance().get(RM_PANEL_MENU))->baseWidget().hide();
226 globalStatus.iRenderScreen = PME_SCREEN_HOF;
231 while(mC64.update(&eEvent))
240 case SDL_EVENT_KEY_DOWN:
241 case SDL_EVENT_MOUSE_BUTTON_DOWN:
242 if(globalStatus.iRenderScreen == PME_SCREEN_HOF)
244 pScreen->fadeToImage(ResourceManager::Instance().get(RM_IMG_MENU), 250);
245 mC64.IGUIMgr().getPanel(ResourceManager::Instance().get(RM_PANEL_MENU))->baseWidget().show();
246 globalStatus.iRenderScreen = PME_SCREEN_MENU;
252 if(eEvent.user.code == C64_EVENT_WIDGET) iDone = pMenu->processEvent(*
static_cast<Sint32*
>(eEvent.user.data1), *
static_cast<Sint32*
>(eEvent.user.data2));
259 mC64.ISoundMgr().get(ResourceManager::Instance().get(RM_SND_EXIT))->play();
260 mC64.IMusicMgr().fadeOut(1000);
261 pScreen->fadeToColor(0, 0, 0, 1000);
265 BrainsFactory::Terminate();
266 ResourceManager::Terminate();
267 EVNTrainer::Terminate();
268 mLog.msg(LML_INFO,
"\n [Pac-Man Evolution] Info: game closed.\n");
269 mC64.IConfigMgr().audioClose();
275GlobalStatus::GlobalStatus()
280GlobalStatus::~GlobalStatus()
284Sint32 GlobalStatus::clear()
287 strcpy(szName,
"PacMan");
289 iHighestScore = iLowestScore = 0;
291 workBench.iTraining = 0;
292 workBench.iExecutions = 100;
293 workBench.iSpeed = 20;
295 strcpy(workBench.szOutputCSV,
"workbench.csv");
296 workBench.iPacManBrain = workBench.iGhostRedBrain = workBench.iGhostPinkBrain = PME_OBJECT_NULL;
297 workBench.iGhostBlueBrain = workBench.iGhostOrangeBrain = PME_OBJECT_NULL;