28#include "ResourceManager.h"
29#include "Pac-Man_Evolution.h"
32extern unsigned char pme_icon[];
33extern int pme_icon_size;
36ResourceManager* ResourceManager::mInstance =
nullptr;
39ResourceManager& ResourceManager::Instance()
41 if(!mInstance) mInstance =
new(std::nothrow) ResourceManager;
46void ResourceManager::Terminate()
48 if(mInstance)
delete mInstance;
52ResourceManager::ResourceManager()
55 guiMenu = guiGame = 0;
56 fntConsole = fntInfo = fntScore = 0;
57 musMenu[0] = musMenu[1] = musMenu[2] = 0;
58 musGame[0] = musGame[1] = musGame[2] = musGame[3] = 0;
59 sndThunder = sndClickOK = sndClickCancel = sndClickCancel2 = sndExit = 0;
60 sndGameAbort = sndGameOver = sndGameStarting = sndGamePlayerDeath = sndGameEatPellet = sndGameEatPelletPower = sndGameEatGhost = 0;
61 imgIcon = imgMenu = imgHallOfFame = 0;
63 sprPacman = sprGhostRed = sprGhostPink = sprGhostBlue = sprGhostOrange = sprTargets = 0;
64 sprPellet = sprPelletPower = 0;
67ResourceManager::~ResourceManager()
73Sint32 ResourceManager::load()
75 Sint32 bErrorFlag = 0;
76 Main& mC64 = Main::Instance();
77 ImageMgr& mImage = mC64.IImageMgr();
78 SpriteMgr& mSprite = mC64.ISpriteMgr();
79 FontMgr& mFont = Main::Instance().IFontMgr();
80 SoundMgr& mSound = Main::Instance().ISoundMgr();
81 MusicMgr& mMusic = Main::Instance().IMusicMgr();
86 fntConsole = mFont.load(PME_RESOURCES,
"console");
89 mC64.ILogMgr().get()->msg(LML_CRITICAL,
" [ResourceManager] Critical: could not load the console font.\n");
93 if(fntInfo <= 0 && bErrorFlag == 0)
95 fntInfo = mFont.load(PME_RESOURCES,
"info");
98 mC64.ILogMgr().get()->msg(LML_CRITICAL,
" [ResourceManager] Critical: could not load the info font.\n");
102 if(fntScore <= 0 && bErrorFlag == 0)
104 fntScore = mFont.load(PME_RESOURCES,
"score");
107 mC64.ILogMgr().get()->msg(LML_CRITICAL,
" [ResourceManager] Critical: could not load the score font.\n");
113 if(guiMenu <= 0 && bErrorFlag == 0)
115 guiMenu = mC64.IGUIMgr().create(
"menu");
118 mC64.ILogMgr().get()->msg(LML_CRITICAL,
" [ResourceManager] Critical: could not create the menu panel.\n");
123 Panel* myPanel = mC64.IGUIMgr().getPanel(guiMenu);
124 myPanel->baseWidget().setSize(200, 250);
125 myPanel->baseWidget().setPosition(PH_CENTER, PH_CENTERD + 50);
126 myPanel->baseWidget().setBorderWidth(0);
127 myPanel->baseWidget().features(WIDGET_FEATURE_BGDISABLE);
130 myPanel->createWidget(
"Exit", WT_BUTTON, ID_EXIT);
131 myPanel->getWidget(ID_EXIT)->setKey(SDLK_ESCAPE);
132 myPanel->getWidget(ID_EXIT)->setText(
"");
133 myPanel->getWidget(ID_EXIT)->setBgSprite(PME_RESOURCES,
"widget_exit");
134 myPanel->getWidget(ID_EXIT)->setPosition(PH_CENTER, PH_BOTTOMD);
136 myPanel->createWidget(
"StandardGame", WT_BUTTON, ID_STANDARDGAME);
137 myPanel->getWidget(ID_STANDARDGAME)->setKey(SDLK_s);
138 myPanel->getWidget(ID_STANDARDGAME)->setText(
"");
139 myPanel->getWidget(ID_STANDARDGAME)->setBgSprite(PME_RESOURCES,
"widget_game_standard");
140 myPanel->getWidget(ID_STANDARDGAME)->setPosition(PH_CENTER, PH_TOP);
142 myPanel->createWidget(
"EvolutionGame", WT_BUTTON, ID_EVOLUTIONGAME);
143 myPanel->getWidget(ID_EVOLUTIONGAME)->setKey(SDLK_e);
144 myPanel->getWidget(ID_EVOLUTIONGAME)->setText(
"");
145 myPanel->getWidget(ID_EVOLUTIONGAME)->setBgSprite(PME_RESOURCES,
"widget_game_evolution");
146 myPanel->getWidget(ID_EVOLUTIONGAME)->setPosition(PH_CENTER, PH_TOP + 50);
148 #ifdef PME_WORKBENCH_ENABLED
149 myPanel->createWidget(
"Workbench", WT_BUTTON, ID_WORKBENCHGAME);
150 myPanel->getWidget(ID_WORKBENCHGAME)->setKey(SDLK_w);
151 myPanel->getWidget(ID_WORKBENCHGAME)->setText(
"");
152 myPanel->getWidget(ID_WORKBENCHGAME)->setBgSprite(PME_RESOURCES,
"widget_game_workbench");
153 myPanel->getWidget(ID_WORKBENCHGAME)->setPosition(PH_CENTER, PH_TOP + 100);
156 myPanel->createWidget(
"HoF", WT_BUTTON, ID_HALLOFFAME);
157 myPanel->getWidget(ID_HALLOFFAME)->setKey(SDLK_h);
158 myPanel->getWidget(ID_HALLOFFAME)->setText(
"");
159 myPanel->getWidget(ID_HALLOFFAME)->setBgSprite(PME_RESOURCES,
"widget_hof");
160 #ifdef PME_WORKBENCH_ENABLED
161 myPanel->getWidget(ID_HALLOFFAME)->setPosition(PH_CENTER, PH_TOP + 150);
163 myPanel->getWidget(ID_HALLOFFAME)->setPosition(PH_CENTER, PH_TOP + 100);
169 if(guiGame <= 0 && bErrorFlag == 0)
171 guiGame = mC64.IGUIMgr().create(
"game");
174 mC64.ILogMgr().get()->msg(LML_CRITICAL,
" [ResourceManager] Critical: could not create the game panel.\n");
179 Panel* myPanel = mC64.IGUIMgr().getPanel(guiGame);
180 myPanel->baseWidget().setSize(300, 250);
181 myPanel->baseWidget().setPosition(PH_CENTER, PH_CENTER);
182 myPanel->baseWidget().setBorderWidth(0);
183 myPanel->baseWidget().features(WIDGET_FEATURE_BGFIT);
184 myPanel->baseWidget().setBgImage(PME_RESOURCES,
"messageEnd_bg");
187 myPanel->createWidget(
"GameLabel", WT_LABEL, ID_GAME_LABEL);
188 myPanel->getWidget(ID_GAME_LABEL)->setFont(get(RM_FONT_SCORE));
189 myPanel->getWidget(ID_GAME_LABEL)->setText(
"Game Aborted");
190 myPanel->getWidget(ID_GAME_LABEL)->setPosition(PH_CENTER, PH_TOP + 20);
191 myPanel->getWidget(ID_GAME_LABEL)->features(WIDGET_FEATURE_BGDISABLE);
193 myPanel->createWidget(
"GameEnterName", WT_TEXTBOX, ID_GAME_ENTERNAME);
194 myPanel->getWidget(ID_GAME_ENTERNAME)->setSize(200, 48);
195 myPanel->getWidget(ID_GAME_ENTERNAME)->setMargin(5, 20, 0, 20);
196 myPanel->getWidget(ID_GAME_ENTERNAME)->setPosition(PH_CENTER, PH_CENTER);
197 myPanel->getWidget(ID_GAME_ENTERNAME)->setFont(fntInfo);
198 myPanel->getWidget(ID_GAME_ENTERNAME)->setText(
"PacMan");
199 myPanel->getWidget(ID_GAME_ENTERNAME)->setBgSprite(PME_RESOURCES,
"widget_input");
201 myPanel->createWidget(
"GameClose", WT_BUTTON, ID_GAME_CLOSE);
202 myPanel->getWidget(ID_GAME_CLOSE)->setKey(SDLK_RETURN);
203 myPanel->getWidget(ID_GAME_CLOSE)->setText(
"");
204 myPanel->getWidget(ID_GAME_CLOSE)->setBgSprite(PME_RESOURCES,
"widget_close");
205 myPanel->getWidget(ID_GAME_CLOSE)->setPosition(PH_CENTER, PH_BOTTOMD + 25);
210 if(musMenu[0] <= 0 && bErrorFlag == 0)
212 musMenu[0] = mMusic.load(PME_RESOURCES,
"menu_1");
215 mC64.ILogMgr().get()->msg(LML_CRITICAL,
" [ResourceManager] Critical: could not load the menu_1 music.\n");
219 if(musMenu[1] <= 0 && bErrorFlag == 0)
221 musMenu[1] = mMusic.load(PME_RESOURCES,
"menu_2");
224 mC64.ILogMgr().get()->msg(LML_CRITICAL,
" [ResourceManager] Critical: could not load the menu_2 music.\n");
228 if(musMenu[2] <= 0 && bErrorFlag == 0)
230 musMenu[2] = mMusic.load(PME_RESOURCES,
"menu_3");
233 mC64.ILogMgr().get()->msg(LML_CRITICAL,
" [ResourceManager] Critical: could not load the menu_3 music.\n");
237 if(musGame[0] <= 0 && bErrorFlag == 0)
239 musGame[0] = mMusic.load(PME_RESOURCES,
"game_1");
242 mC64.ILogMgr().get()->msg(LML_CRITICAL,
" [ResourceManager] Critical: could not load the game_1 music.\n");
246 if(musGame[1] <= 0 && bErrorFlag == 0)
248 musGame[1] = mMusic.load(PME_RESOURCES,
"game_2");
251 mC64.ILogMgr().get()->msg(LML_CRITICAL,
" [ResourceManager] Critical: could not load the game_2 music.\n");
255 if(musGame[2] <= 0 && bErrorFlag == 0)
257 musGame[2] = mMusic.load(PME_RESOURCES,
"game_3");
260 mC64.ILogMgr().get()->msg(LML_CRITICAL,
" [ResourceManager] Critical: could not load the game_3 music.\n");
264 if(musGame[3] <= 0 && bErrorFlag == 0)
266 musGame[3] = mMusic.load(PME_RESOURCES,
"game_4");
269 mC64.ILogMgr().get()->msg(LML_CRITICAL,
" [ResourceManager] Critical: could not load the game_4 music.\n");
275 if(sndThunder <= 0 && bErrorFlag == 0)
277 sndThunder = mSound.load(PME_RESOURCES,
"thunder");
280 mC64.ILogMgr().get()->msg(LML_CRITICAL,
" [ResourceManager] Critical: could not load the thunder sound.\n");
284 if(sndClickOK <= 0 && bErrorFlag == 0)
286 sndClickOK = mSound.load(PME_RESOURCES,
"click_ok");
289 mC64.ILogMgr().get()->msg(LML_CRITICAL,
" [ResourceManager] Critical: could not load the click_ok sound.\n");
293 if(sndClickCancel <= 0 && bErrorFlag == 0)
295 sndClickCancel = mSound.load(PME_RESOURCES,
"click_cancel");
296 if(sndClickCancel < 0)
298 mC64.ILogMgr().get()->msg(LML_CRITICAL,
" [ResourceManager] Critical: could not load the click_cancel sound.\n");
302 if(sndClickCancel2 <= 0 && bErrorFlag == 0)
304 sndClickCancel2 = mSound.load(PME_RESOURCES,
"click_cancel2");
305 if(sndClickCancel2 < 0)
307 mC64.ILogMgr().get()->msg(LML_CRITICAL,
" [ResourceManager] Critical: could not load the click_cancel2 sound.\n");
311 if(sndExit <= 0 && bErrorFlag == 0)
313 sndExit = mSound.load(PME_RESOURCES,
"exit");
316 mC64.ILogMgr().get()->msg(LML_CRITICAL,
" [ResourceManager] Critical: could not load the exit sound.\n");
320 if(sndGameAbort <= 0 && bErrorFlag == 0)
322 sndGameAbort = mSound.load(PME_RESOURCES,
"game_abort");
325 mC64.ILogMgr().get()->msg(LML_CRITICAL,
" [ResourceManager] Critical: could not load the game_abort sound.\n");
329 if(sndGameOver <= 0 && bErrorFlag == 0)
331 sndGameOver = mSound.load(PME_RESOURCES,
"game_over");
334 mC64.ILogMgr().get()->msg(LML_CRITICAL,
" [ResourceManager] Critical: could not load the game_over sound.\n");
338 if(sndGameStarting <= 0 && bErrorFlag == 0)
340 sndGameStarting = mSound.load(PME_RESOURCES,
"game_starting");
341 if(sndGameStarting < 0)
343 mC64.ILogMgr().get()->msg(LML_CRITICAL,
" [ResourceManager] Critical: could not load the game_starting sound.\n");
347 if(sndGamePlayerDeath <= 0 && bErrorFlag == 0)
349 sndGamePlayerDeath = mSound.load(PME_RESOURCES,
"game_player_death");
350 if(sndGamePlayerDeath < 0)
352 mC64.ILogMgr().get()->msg(LML_CRITICAL,
" [ResourceManager] Critical: could not load the game_player_death sound.\n");
356 if(sndGameEatPellet <= 0 && bErrorFlag == 0)
358 sndGameEatPellet = mSound.load(PME_RESOURCES,
"game_eat_pellet");
359 if(sndGameEatPellet < 0)
361 mC64.ILogMgr().get()->msg(LML_CRITICAL,
" [ResourceManager] Critical: could not load the game_eat_pellet sound.\n");
365 if(sndGameEatPelletPower <= 0 && bErrorFlag == 0)
367 sndGameEatPelletPower = mSound.load(PME_RESOURCES,
"game_eat_pellet_power");
368 if(sndGameEatPelletPower < 0)
370 mC64.ILogMgr().get()->msg(LML_CRITICAL,
" [ResourceManager] Critical: could not load the game_eat_pellet_power sound.\n");
374 if(sndGameEatGhost <= 0 && bErrorFlag == 0)
376 sndGameEatGhost = mSound.load(PME_RESOURCES,
"game_player_eat_ghost");
377 if(sndGameEatGhost < 0)
379 mC64.ILogMgr().get()->msg(LML_CRITICAL,
" [ResourceManager] Critical: could not load the game_player_eat_ghost sound.\n");
385 if(imgIcon <= 0 && bErrorFlag == 0)
387 imgIcon = mImage.load(pme_icon, pme_icon_size,
"PME-icon");
390 mC64.ILogMgr().get()->msg(LML_CRITICAL,
" [ResourceManager] Critical: could not create the PME Icon.\n");
394 if(imgMenu <= 0 && bErrorFlag == 0)
396 imgMenu = mImage.load(PME_RESOURCES,
"menu_bg");
399 mC64.ILogMgr().get()->msg(LML_CRITICAL,
" [ResourceManager] Critical: could not load the Menu BG.\n");
403 if(imgHallOfFame <= 0 && bErrorFlag == 0)
405 imgHallOfFame = mImage.load(PME_RESOURCES,
"hof_bg");
406 if(imgHallOfFame < 0)
408 mC64.ILogMgr().get()->msg(LML_CRITICAL,
" [ResourceManager] Critical: could not load the HallOfFame BG.\n");
414 if(curArrow <= 0 && bErrorFlag == 0)
416 curArrow = mC64.ICursorMgr().load(PME_RESOURCES,
"cursor");
419 mC64.ILogMgr().get()->msg(LML_CRITICAL,
" [ResourceManager] Critical: could not load the cursor.\n");
424 mC64.ICursorMgr().select(curArrow);
425 mC64.ICursorMgr().hide();
430 if(sprPacman <= 0 && bErrorFlag == 0)
432 sprPacman = mSprite.load(PME_RESOURCES,
"pacman");
435 mC64.ILogMgr().get()->msg(LML_CRITICAL,
" [ResourceManager] Critical: could not load the pacman sprite.\n");
439 if(sprGhostRed <= 0 && bErrorFlag == 0)
441 sprGhostRed = mSprite.load(PME_RESOURCES,
"ghost_red");
444 mC64.ILogMgr().get()->msg(LML_CRITICAL,
" [ResourceManager] Critical: could not load the ghost_red sprite.\n");
448 if(sprGhostPink <= 0 && bErrorFlag == 0)
450 sprGhostPink = mSprite.load(PME_RESOURCES,
"ghost_pink");
453 mC64.ILogMgr().get()->msg(LML_CRITICAL,
" [ResourceManager] Critical: could not load the ghost_pink sprite.\n");
457 if(sprGhostBlue <= 0 && bErrorFlag == 0)
459 sprGhostBlue = mSprite.load(PME_RESOURCES,
"ghost_blue");
462 mC64.ILogMgr().get()->msg(LML_CRITICAL,
" [ResourceManager] Critical: could not load the ghost_blue sprite.\n");
466 if(sprGhostOrange <= 0 && bErrorFlag == 0)
468 sprGhostOrange = mSprite.load(PME_RESOURCES,
"ghost_orange");
469 if(sprGhostOrange < 0)
471 mC64.ILogMgr().get()->msg(LML_CRITICAL,
" [ResourceManager] Critical: could not load the ghost_orange sprite.\n");
475 if(sprPellet <= 0 && bErrorFlag == 0)
477 sprPellet = mSprite.load(PME_RESOURCES,
"pellet");
480 mC64.ILogMgr().get()->msg(LML_CRITICAL,
" [ResourceManager] Critical: could not load the pellet sprite.\n");
484 if(sprPelletPower <= 0 && bErrorFlag == 0)
486 sprPelletPower = mSprite.load(PME_RESOURCES,
"pellet_power");
487 if(sprPelletPower < 0)
489 mC64.ILogMgr().get()->msg(LML_CRITICAL,
" [ResourceManager] Critical: could not load the pellet_power sprite.\n");
493 if(sprTargets <= 0 && bErrorFlag == 0)
495 sprTargets = mSprite.load(PME_RESOURCES,
"targets");
498 mC64.ILogMgr().get()->msg(LML_CRITICAL,
" [ResourceManager] Critical: could not load the targets sprite.\n");
504 auto hitime = std::chrono::high_resolution_clock::now().time_since_epoch().count();
505 Main::Instance().ITool().randSeedMWC((Sint32)hitime);
506 Main::Instance().ITool().randSeedWELL((Sint32)hitime);
519Sint32 ResourceManager::free()
521 Main& mC64 = Main::Instance();
523 if(sprPacman > 0) mC64.ISpriteMgr().close(sprPacman);
525 if(sprGhostRed > 0) mC64.ISpriteMgr().close(sprGhostRed);
527 if(sprGhostPink > 0) mC64.ISpriteMgr().close(sprGhostPink);
529 if(sprGhostBlue > 0) mC64.ISpriteMgr().close(sprGhostBlue);
531 if(sprGhostOrange > 0) mC64.ISpriteMgr().close(sprGhostOrange);
533 if(sprPellet > 0) mC64.ISpriteMgr().close(sprPellet);
535 if(sprPelletPower > 0) mC64.ISpriteMgr().close(sprPelletPower);
537 if(sprTargets > 0) mC64.ISpriteMgr().close(sprTargets);
540 if(curArrow > 0) mC64.ICursorMgr().close(curArrow);
543 if(imgIcon > 0) mC64.IImageMgr().close(imgIcon);
545 if(imgMenu > 0) mC64.IImageMgr().close(imgMenu);
547 if(imgHallOfFame > 0) mC64.IImageMgr().close(imgHallOfFame);
550 if(sndThunder > 0) mC64.ISoundMgr().close(sndThunder);
552 if(sndClickOK > 0) mC64.ISoundMgr().close(sndClickOK);
554 if(sndClickCancel2 > 0) mC64.ISoundMgr().close(sndClickCancel2);
556 if(sndClickCancel > 0) mC64.ISoundMgr().close(sndClickCancel);
558 if(sndExit > 0) mC64.ISoundMgr().close(sndExit);
560 if(sndGameAbort > 0) mC64.ISoundMgr().close(sndGameAbort);
562 if(sndGameOver > 0) mC64.ISoundMgr().close(sndGameOver);
564 if(sndGameStarting > 0) mC64.ISoundMgr().close(sndGameStarting);
566 if(sndGamePlayerDeath > 0) mC64.ISoundMgr().close(sndGamePlayerDeath);
567 sndGamePlayerDeath = 0;
568 if(sndGameEatPellet > 0) mC64.ISoundMgr().close(sndGameEatPellet);
569 sndGameEatPellet = 0;
570 if(sndGameEatPelletPower > 0) mC64.ISoundMgr().close(sndGameEatPelletPower);
571 sndGameEatPelletPower = 0;
572 if(sndGameEatGhost > 0) mC64.ISoundMgr().close(sndGameEatGhost);
575 if(musMenu[0] > 0) mC64.IMusicMgr().close(musMenu[0]);
577 if(musMenu[1] > 0) mC64.IMusicMgr().close(musMenu[1]);
579 if(musMenu[2] > 0) mC64.IMusicMgr().close(musMenu[2]);
581 if(musGame[0] > 0) mC64.IMusicMgr().close(musGame[0]);
583 if(musGame[1] > 0) mC64.IMusicMgr().close(musGame[1]);
585 if(musGame[2] > 0) mC64.IMusicMgr().close(musGame[2]);
587 if(musGame[3] > 0) mC64.IMusicMgr().close(musGame[3]);
590 if(fntConsole > 0) mC64.IFontMgr().close(fntConsole);
592 if(fntInfo > 0) mC64.IFontMgr().close(fntInfo);
594 if(fntScore > 0) mC64.IFontMgr().close(fntScore);
597 if(guiMenu > 0) mC64.IGUIMgr().close(guiMenu);
600 if(guiGame > 0) mC64.IGUIMgr().close(guiGame);
606Sint32 ResourceManager::get(Sint32 iID)
const
608 SpriteMgr& mSprite = Main::Instance().ISpriteMgr();
613 case RM_PANEL_MENU:
return guiMenu;
614 case RM_PANEL_GAME:
return guiGame;
616 case RM_FONT_CONSOLE:
return fntConsole;
617 case RM_FONT_INFO:
return fntInfo;
618 case RM_FONT_SCORE:
return fntScore;
620 case RM_MUS_MENU:
return musMenu[Main::Instance().ITool().randMWC() % 3];
621 case RM_MUS_GAME:
return musGame[Main::Instance().ITool().randMWC() % 4];
623 case RM_SND_THUNDER:
return sndThunder;
624 case RM_SND_CLICKOK:
return sndClickOK;
625 case RM_SND_CLICKCANCEL:
return sndClickCancel;
626 case RM_SND_CLICKCANCEL2:
return sndClickCancel2;
627 case RM_SND_EXIT:
return sndExit;
628 case RM_SND_GAMEABORT:
return sndGameAbort;
629 case RM_SND_GAMEOVER:
return sndGameOver;
630 case RM_SND_GAMESTARTING:
return sndGameStarting;
631 case RM_SND_GAMEPLAYERDEATH:
return sndGamePlayerDeath;
632 case RM_SND_GAMEEATPELLET:
return sndGameEatPellet;
633 case RM_SND_GAMEEATPELLETPOWER:
return sndGameEatPelletPower;
634 case RM_SND_GAMEEATGHOST:
return sndGameEatGhost;
636 case RM_IMG_ICON:
return imgIcon;
637 case RM_IMG_MENU:
return imgMenu;
638 case RM_IMG_HOF:
return imgHallOfFame;
642 iTmp = mSprite.child(sprPacman);
643 Sprite* pSpr = mSprite.get(sprPacman);
644 if(bPacManDeathAnim == 0) pSpr->setAnimRange(SPR_STATE_NORMAL, 10, 12);
645 else pSpr->setAnimRange(SPR_STATE_NORMAL, 0, 12);
648 case RM_SPR_GHOSTRED:
return mSprite.child(sprGhostRed);
649 case RM_SPR_GHOSTPINK:
return mSprite.child(sprGhostPink);
650 case RM_SPR_GHOSTBLUE:
return mSprite.child(sprGhostBlue);
651 case RM_SPR_GHOSTORANGE:
return mSprite.child(sprGhostOrange);
652 case RM_SPR_PELLET:
return sprPellet;
653 case RM_SPR_PELLETPOWER:
return mSprite.child(sprPelletPower);
654 case RM_SPR_TARGETS:
return mSprite.child(sprTargets);
656 default:
return PME_BREAK;
660Sint32 ResourceManager::setPacManDeathAnim(Sint32 bFlag)
662 if(bFlag <= 0) bPacManDeathAnim = 0;
663 else bPacManDeathAnim = 1;