int main(int argc, char** argv) { char mess[100], *string1; uint16 saverResult; int loop1, loop2, framesRun, framesPerSec = 0; bool fWaitToSend; BAM_WorldEnderPopup *pWEPop; FILE *pFile; // Nothing *pNothing1 = new Nothing; // NothingMore *pNothingMore1 = new NothingMore; // Dummy *pDummy1 = new Dummy(0x1234); // pNothing1->SetValue(0x1234); // pNothingMore1->SetValue(0x5678); // pDummy1->SetValue(0x90ab); // Unit *pUnit = new Unit(TRUE); // Unit unit1(TRUE); /* Jay - here's the code for the test case you said you wanted to try next: pFile = fopen("unit1.dat", "wb"); fwrite(&unit1, 1, sizeof(unit1), pFile); fclose(pFile); */ /* pFile = fopen("unit1.dat", "rb"); fread(&unit1, 1, sizeof(unit1), pFile); fclose(pFile); */ time_t startTime, timeDif, lastTime; time(&startTime); lastTime = startTime; // disable critical error handler _harderr(critical_error_handler); AInitializePlatform(); #ifndef NDEBUG printf("\n\n&ReportFreeMem==0x%08X\n", (int)ReportFreeMem); #endif #ifdef OS_DOS printf("\nBLOOD & MAGIC Copyright (C) 1996 by Tachyon Studios Inc..\n"); printf("Developed by Tachyon Studios for Interplay Productions.\n"); printf("BLOOD & MAGIC, FORGOTTEN REALMS and the TSR LOGO are Trademarks\n"); printf("owned by TSR, Inc and are used under license.\n"); printf("\nCompiled %s %s\n", __DATE__, __TIME__); printf("%dk free after platform initialization\n", AAvailMem() / 1024); if(AAvailMem() < MIN_MEM_REQ) { printf("\nWARNING: Free XMS memory is low (<%dk)!\nBAM may not run reliably\n", MIN_MEM_REQ / 1000); sleep(4); } #endif // short-circuit any command line args // argc = 1; if(argc > 1 && (!memcmp(argv[1], "?", 2) || !memcmp(argv[1], "-HELP", 6))) { // printf("Format: BAM [mapNum] [-NOINTRO] [-NOFOG] [-SIDEx] [-NOWIN] [-NET] [-SHOWOFF]\n"); return(0); } // if the seed is the same, the sequence will repeat. cool! // ASeedRandom(41); // for repeatability of bugs // ASeedRandom2(41); // for repeatability of bugs ASeedRandom(startTime); // for genuine randomness ASeedRandom2(startTime); // for genuine randomness // If you ever don't want to see unfreed memory, like for demos, // then uncomment this. // extern bool fPrintUnfreedPtrs; // fPrintUnfreedPtrs = FALSE; TRACK_MEM("Mono"); pMono = new Mono; // if we really must allocate this on the fly instead of // having it global, then we must tell the memmgr not to save it. ASetSaveStatus(AGetGrip(pMono), FALSE); // also, we don't want this to be purged on a restore. ASetPurgeStatus(AGetGrip(pMono), FALSE); pMono->SetWindow(0, 7, 79, 12); pMono->Clear(); pMono->Out("Monochrome output initialized\n"); #ifndef NDBEUG pMono->Out("&ReportFreeMem==0x%08X\n", (int)ReportFreeMem); sleep(4); #endif pMono->Out("EventMgr initializing\n"); TRACK_MEM("EventMgr"); new EventMgr; // we are going to update ticks when we want to. AAutoUpdateTicks(FALSE); pMono->Out("ContextMgr initializing\n"); TRACK_MEM("ContextMgr"); new ContextMgr; pMono->Out("ResMgr initializing\n"); TRACK_MEM("ResMgr"); new ResourceMgr(TRUE); // NOTE - IT IS HIGHLY RECOMMENDED THAT YOU INIT THE SOUND MANAGER // BEFORE THE GRAPH MANAGER. If you don't, streamed sounds will // stop and start during restore because of the busy loop in graph // manager that happens when the palette fades up. pMono->Out("SoundMgr initializing\n"); TRACK_MEM("SndMgr"); new SoundMgr; pSoundMgr->Init(); // BUGBUG! If we bind w/ DOS4GW/Pro we will crash here! //setup smacker sound stuff SmackSoundUseSOS3((u16)pSoundMgr->hDigiDriverHandle,0); pMono->Out("GraphMgr initializing\n"); TRACK_MEM("GraphMgr"); pGraphMgr = new GraphicsMgr(MODEX_320X400); pMono->Out("%dk free after platform initialization\n", AAvailMem() / 1024); // Debugger debug1, debug2; // debug1.OpenWindow(0, 0, 79, 10); // debug2.OpenWindow(40, 11, 79, 21); // for(loop1 = 0; loop1 < 25; loop1++) // { // pMono->Out("\n%d", loop1); // } // sleep(2); TRACK_MEM("FontMgr"); pFontMgr = new FontMgr; // default font pFontMgr->SetRes(9050); // default font color pFontMgr->ForeColor(TEXT_DEFAULT); pFontMgr->colors[FNT_BACK_COLOR] = CI_SKIP; #ifdef OS_MAC // #include "menubar.hpp" // DS9MenuBar* pMenuBar; // TRACK_MEM("menuBar"); pMenuBar = new DS9MenuBar; TRACK_MEM("Mouse"); new Mouse; #else TRACK_MEM("Mouse"); new MouseInt; #endif if(pMouse->hideCount == 999) { // init error ShutDownSoundMgr(); APrintUnfreedPtrs(FALSE); exit(1); } pMouse->Init(0,0,SCREEN_WIDTH-1,SCREEN_HEIGHT-1); pMouse->SetRes(RES_ANIM, POINTER_RES, 1); pMouse->Hide(); //let bamroom show it at room change time. // this is our global data saver AtSave(GlobalSave); // create the application instance TRACK_MEM("BAM App"); pBam = new BAM_Application; bGlobal.gBam = pBam->gSelf; pBam->msgMask = E_MOUSE_DOWN | E_MOUSE_UP | E_KEY_DOWN; // command-line options parsed here memcpy(pBam->scenarioName, "9110", 5); // default scenario pBam->fNoIntro = FALSE; pBam->fDefaultScenario = FALSE; pBam->fUseFog = TRUE; pBam->fUseWinLose = TRUE; pBam->playerSide = SIDE1; pBam->fMapEdit = FALSE; pBam->playerTypes[SIDE0] = PLAYER_NONE; pBam->playerTypes[SIDE1] = PLAYER_LOCAL; pBam->playerTypes[SIDE2] = PLAYER_NONE; pBam->playerTypes[SIDE3] = PLAYER_NONE; pBam->playerTypes[SIDE4] = PLAYER_NONE; { FILE *pPentiumFile; pPentiumFile = fopen("PENTIUM.VAN", "rb"); if(pPentiumFile) { fclose(pPentiumFile); fPentium = TRUE; } } for(loop1 = 1; loop1 < argc; loop1++) { strcpy(mess, argv[loop1]); string1 = mess; do { *string1 = (char) toupper(*string1); string1++; } while(*string1); if(mess[0] == '-') { // #ifdef ENABLE_EDITOR // if(!memcmp(mess, "-EDIT", 5)) // turn on edit mode // pBam->fMapEdit = TRUE; // #endif if(!memcmp(mess, "-NOINTRO", 9)) // turn off opening cinematic pBam->fNoIntro = TRUE; else if(!memcmp(mess, "-NOWIN", 6)) // turn on win/lose conditions pBam->fUseWinLose = FALSE; else if(!memcmp(mess, "-NOFOG", 6)) // turn off fog pBam->fUseFog = FALSE; else if(!memcmp(mess, "-NET", 4)) // network play { pBam->fNetworkTest = TRUE; bGlobal.storyLine = NETGAME; ASeedRandom(42); // need sync'ed RNGs } else if(!memcmp(mess, "-PENTIUM", 8)) { fPentium = TRUE; } else if(!memcmp(mess, "-MUSIC", 6)) { bGlobal.altMusicNum = atoi(mess + 6); } else if(!memcmp(mess, "-AIUNITS", 8)) { bGlobal.aiUnitMultiplier = atoi(mess + 8); } else if(!memcmp(mess, "-AI", 3)) { bGlobal.aiOveride = atoi(mess + 3); } else if(!memcmp(mess, "-FRENCH", 7)) { SetLanguage(LANG_FRENCH); } else if(!memcmp(mess, "-GERMAN", 7)) { SetLanguage(LANG_GERMAN); } else if(!memcmp(mess, "-ENGLISH", 8)) { SetLanguage(LANG_ENGLISH); } else if(!memcmp(mess, "-SHOWOFF", 8)) // storefront demo mode { bGlobal.storyLine = SHOW_OFF; } else if(!memcmp(mess, "-HACKRES", 8)) // allow single resource replacement { pResMgr->fSearchStuffsFirst = FALSE; } else if(!memcmp(mess, "-SIDE", 5)) // set player side (1 or 2) { switch(mess[5]) { case '0': pBam->playerSide = SIDE0; pBam->playerTypes[SIDE1] = PLAYER_NONE; pBam->playerTypes[SIDE2] = PLAYER_NONE; break; case '1': pBam->playerSide = SIDE1; pBam->playerTypes[SIDE1] = PLAYER_LOCAL; pBam->playerTypes[SIDE2] = PLAYER_NONE; break; case '2': pBam->playerSide = SIDE2; pBam->playerTypes[SIDE1] = PLAYER_NONE; pBam->playerTypes[SIDE2] = PLAYER_LOCAL; break; default: pMono->Out("Invalid option to command line arg -SIDEx\n"); break; } } } else if(atoi(argv[loop1])) { memcpy(pBam->scenarioName, argv[loop1], 8); pBam->fDefaultScenario = TRUE; } } #ifdef ENABLE_EDITOR if(pBam->fMapEdit) // if editor mode, then turn off fog pBam->fUseFog = FALSE; pBam->fShowTileNums = TRUE; #endif // initialize game start, pBam->Activate(TRUE); pContextMgr->msgMask = E_MOUSE_DOWN | E_MOUSE_UP | E_KEY_DOWN; #ifdef COUNT_FRAMES FrameCounter fps; #endif // COUNT_FRAMES TRACK_MEM("TCommMgr"); new TCommMgr; if(pBam->fNetworkTest) // if set up network from command line { // TNetwork *pComm; // TModem *pComm; TComm::ERROR errVal; int int1; // pMono->Out("New TCommMgr\n"); // TRACK_MEM("TCommMgr"); pCommMgr = new TCommMgr; //it isn't an object -no gSelf TRACK_MEM("TNetwork"); pComm = new TNetwork; // pComm = new TModem; // ((TModem*) pComm)->SetPort(3); // ((TModem*) pComm)->SetBaud(19200); #ifdef OS_MAC int commInitArg = 0; // ignored by DOS/TIGRE // player 1 is caller, player two is listener // at least for now, using command line args to specify direction if (pBam->playerTypes[SIDE1] == PLAYER_LOCAL) { commInitArg = TCommMacintosh::kATalkCaller; } else { commInitArg = TCommMacintosh::kATalkListener; } pCommMgr->Init(pComm, commInitArg); #else pCommMgr->SetUserAbortFn ((pIntFnInt) CycleConnection); pCommMgr->Init(pComm); #endif pMono->Out("Attempting connection...\n"); int1 = (int)pCommMgr->Connect(); errVal = (TComm::ERROR)int1; if(errVal != TComm::ALL_OK) { pMono->Out("Main() - error, commMgr->Connect() failed\n"); sleep(1); pBam->fNetworkTest = FALSE; } else { pMono->Out("Main() - connection established\n"); pBam->playerTypes[(pBam->playerSide == SIDE1)? SIDE2: SIDE1] = pCommMgr->GetUserID(); pMono->Out("User ID==%d\n", pCommMgr->GetUserID()); // sleep(2); } } pMono->Out("TIGRE engine initialized\n"); ReportFreeMem(); // side1 and side2 MUST have a player setting of some kind if(pBam->playerTypes[SIDE1] == PLAYER_NONE) pBam->playerTypes[SIDE1] = PLAYER_COMPUTER; if(pBam->playerTypes[SIDE2] == PLAYER_NONE) pBam->playerTypes[SIDE2] = PLAYER_COMPUTER; // initial room if(pBam->fDefaultScenario) { SetDefaults(pBam->scenarioName); bGlobal.roomMgr.NewRoom(BR_WORLD); // skip everything, go to game } else if(bGlobal.storyLine == SHOW_OFF) { bGlobal.roomMgr.NewRoom(BR_WORLD); // skip everything, go to game } else if(pBam->fNoIntro) bGlobal.roomMgr.NewRoom(BR_MENU); // skip intro, go to story selector else bGlobal.roomMgr.NewRoom(BR_CINE); // skip nothing bGlobal.roomMgr.CheckRoomChange(); #ifdef OS_MAC #include "menubar.hpp" DS9MenuBar *pMenuBar; TRACK_MEM("menuBar"); MenuBar.Init(); #endif ticks_t currTicks = ATicks(); int snapShot = 0; // anti-piracy stuff pFile = fopen("HMICARDS.386", "rb"); if(!pFile) bGlobal.antiPiracyCrashFlag &= 0xFFFFF0FF; else { for(loop1 = 0; loop1 < 5; loop1++) { char string1[128]; unsigned long lineCheck1, lineCheck2; fread(string1, 32, 1, pFile); // camoflage string fread(string1, 128, 1, pFile); // encrypted string fread(&lineCheck1, sizeof(lineCheck1), 1, pFile); // line checksum // verify checksum for(lineCheck2 = 0, loop2 = 0; loop2 < 128; loop2++) lineCheck2 = lineCheck2 + string1[loop2]; lineCheck2 ^= 0xF61E22C9; if(lineCheck1 != lineCheck2) { // failure - set the delayed crash flag fclose(pFile); bGlobal.antiPiracyCrashFlag &= 0xFFFFF0FF; } } fclose(pFile); } //======================================================================= //MAIN GAME LOOP //======================================================================= ReportFreeMem(); enum timerTags {TIMER_CYC_PER_FRAME = 0, TIMER_UPDATE_TICKS, TIMER_CONTEXT_CYCLE, TIMER_ANIMATE, TIMER_SYNC_SEND, TIMER_SYNC_RECV, TIMER_MAX}; DebugTimer timers[TIMER_MAX]; while (!pContextMgr->fQuitting) { #ifndef NDEBUG timers[TIMER_CYC_PER_FRAME].Start(); #endif #ifdef DEBUG_BIG_NET pMono->Out("main loop().."); #endif // our own exceptional ptrs pBam = ADerefAs(BAM_Application, bGlobal.gBam); if (bGlobal.gWorld) { pWorld = ADerefAs(World, bGlobal.gWorld); } else { pWorld = NULL; } #ifdef DEBUG_BIG_NET pMono->Out("roomMgr.cycle().."); #endif bGlobal.roomMgr.Cycle(); //fps.Count(); #ifdef DEBUG_BIG_NET pMono->Out("memMgr.cycle().."); #endif pMemMgr->Cycle(); #ifndef OLD_MOUSE_INTERRUPT_HANDLER // // MDB - Modified the mouse interrupt handler. // MouseHandler( FALSE ); #endif #ifndef NDEBUG //mem_check(); #endif #ifdef DEBUG_BIG_NET pMono->Out("roomMgr.CheckRoomChange().."); #endif bGlobal.roomMgr.CheckRoomChange(); #ifndef OLD_MOUSE_INTERRUPT_HANDLER // // MDB - Modified the mouse interrupt handler. // MouseHandler( FALSE ); #endif //if snap is on lets handle tick updates ourself if(bGlobal.gSnap && pSnap->snapOn) { //if snap just toggled on if(!snapShot) { snapShot++; currTicks = ATicks(); } else { currTicks += 2; } ASetTicks(currTicks); } else { snapShot = 0; //reset #ifdef DEBUG_BIG_NET pMono->Out("EventMgr->Publish().."); #endif // add local actions to actionPool2 pEventMgr->PublishNext(); #ifndef OLD_MOUSE_INTERRUPT_HANDLER // // MDB - Modified the mouse interrupt handler. // MouseHandler( FALSE ); #endif if(pWorld) { // wait for next tick to occur, because otherwise there's no point. // note: UpdateTicks() cannot be trusted to change, in case of Pause() currTicks = ATicks(); // #ifndef NDEBUG // BamDebug.Out("main() - update tick counter (curr=%d)\n", // currTicks); // #endif #ifndef NDEBUG timers[TIMER_UPDATE_TICKS].Start(); #endif UpdateTicks(); // did the tick counter fail to increment? if(ATicks() == currTicks) { // loop on clock() delta, then resume. A tick will have changed by // then or else we're in Pause() mode, so who cares. clock_t currClock = clock(); while(currClock == clock()) { #ifndef OLD_MOUSE_INTERRUPT_HANDLER MouseHandler( FALSE ); #endif }; // try again - if it fails again, assume Pause() and don't worry UpdateTicks(); } // if we skipped over a tick somehow.. if(ATicks() > currTicks + 1) { // #ifndef NDEBUG // BamDebug.Out("main() WARNING: ATicks() advanced by %d! - retarding\n", // ATicks() - currTicks); // #endif // dont allow the tick counter to increment by more than 1 // tick per frame, or we may get out of sync with the // remote machine ASetTicks(currTicks + 1); } #ifndef NDEBUG timers[TIMER_UPDATE_TICKS].Stop(); #endif // #ifndef NDEBUG // BamDebug.Out("ATicks() == %d\n", ATicks()); // #endif // sync1 - send actionPool2 to remote #ifndef NDEBUG timers[TIMER_SYNC_SEND].Start(); #endif fWaitToSend = FALSE; if(pCommMgr && pCommMgr->totalPacketsWaiting) fWaitToSend = TRUE; if(!pWorld->SyncSend()) { #ifndef OLD_MOUSE_INTERRUPT_HANDLER MouseHandler( FALSE ); #endif //pWorld->AITakeOver(); if(!pBam->fWorldEnderPopupExists) { TRACK_MEM("BAM_WorldEnderPopup"); pWEPop = new BAM_WorldEnderPopup; pWEPop->Setup(); pBam->fWorldEnderPopupExists = TRUE; } } #ifndef NDEBUG timers[TIMER_SYNC_SEND].Stop(); #endif // process actionPool1 pWorld->ProcessActions(); #ifndef OLD_MOUSE_INTERRUPT_HANDLER MouseHandler( FALSE ); #endif } else { #ifndef NDEBUG timers[TIMER_UPDATE_TICKS].Start(); #endif UpdateTicks(); #ifndef NDEBUG timers[TIMER_UPDATE_TICKS].Stop(); #endif } if(bGlobal.storyLine == NETGAME && !bGlobal.netDisconnect) { pCommMgr->EnQueueData(); #ifndef OLD_MOUSE_INTERRUPT_HANDLER MouseHandler( FALSE ); #endif } } #ifdef DEBUG_BIG_NET pMono->Out("contextMgr.cycle().."); #endif #ifndef NDEBUG timers[TIMER_CONTEXT_CYCLE].Start(); #endif pContextMgr->Cycle(); #ifndef NDEBUG timers[TIMER_CONTEXT_CYCLE].Stop(); #endif #ifndef OLD_MOUSE_INTERRUPT_HANDLER MouseHandler( FALSE ); #endif if(bGlobal.storyLine == NETGAME && !bGlobal.netDisconnect) { pCommMgr->EnQueueData(); #ifndef OLD_MOUSE_INTERRUPT_HANDLER MouseHandler( FALSE ); #endif } #ifdef DEBUG_BIG_NET pMono->Out("GraphMgr->Animate().."); #endif #ifndef NDEBUG timers[TIMER_ANIMATE].Start(); #endif pGraphMgr->Animate(); #ifndef NDEBUG timers[TIMER_ANIMATE].Stop(); #endif #ifndef OLD_MOUSE_INTERRUPT_HANDLER MouseHandler( FALSE ); #endif if(bGlobal.storyLine == NETGAME && !bGlobal.netDisconnect) { pCommMgr->EnQueueData(); #ifndef OLD_MOUSE_INTERRUPT_HANDLER MouseHandler( FALSE ); #endif } #ifdef DEBUG_BIG_NET pMono->Out("soundMgr.cycle().."); #endif pSoundMgr->Cycle(); // current frame now done // gather cmds from remote for next frame, then prepare to run it if(pWorld) { pWorld->currFrame++; // sync2 - add remote actions to local actions in actionPool2 #ifndef NDEBUG timers[TIMER_SYNC_RECV].Start(); #endif if(!pWorld->SyncReceive()) { #ifndef OLD_MOUSE_INTERRUPT_HANDLER MouseHandler( FALSE ); #endif //pWorld->AITakeOver(); if(!pBam->fWorldEnderPopupExists) { TRACK_MEM("BAM_WorldEnderPopup"); pWEPop = new BAM_WorldEnderPopup; pWEPop->Setup(); pBam->fWorldEnderPopupExists = TRUE; } } // sync3 - swap action pools pWorld->SwapActionPools(); #ifndef NDEBUG timers[TIMER_SYNC_RECV].Stop(); #endif } if(bGlobal.gSnap && pSnap->snapOn) { pSnap->SnapScreen(); } if(netRestoreNum || netSaveNum) { //this means we're in a netgame save or restore //we don't run the eventmgr to keep both sides in sync //and we set the restore number here, after the context cycle, //to insure the otherside has had time to be notified of this if(netRestoreNum) restoreNum = netRestoreNum; //our one net save game if(netSaveNum) { saveNum = netSaveNum; netSerialNum = ARandom(99999); sprintf(saveMessage,"%d",netSerialNum); } } if (saveNum) { pMemMgr->Dump((uint16) (100 + saveNum), "Save Dump", TRUE); saverResult = saveMgr.Save((uint16) saveNum, bGlobal.versionNum, bGlobal.versionSubNum, bGlobal.buildID, saveMessage); if (saverResult) { sprintf(mess, "save failed. error #%d", saverResult); APanic(mess); } netSaveNum = 0; //reset this after save saveNum = 0; } if (restoreNum) { saverResult = saveMgr.Restore((uint16) restoreNum, bGlobal.versionNum, bGlobal.versionSubNum, bGlobal.buildID); if (saverResult) { // sprintf(mess, "restore failed. error #%d", saverResult); BamDebug.Out("Restore failed! Error %d\n", saverResult); // APanic(mess); } pMemMgr->Dump((uint16) (200 + restoreNum), "Restore Dump", TRUE); netRestoreNum = 0; //reset this after restore restoreNum = 0; bGlobal.roomMgr.Cycle(); // frantic temporary debugging measure pBam = ADerefAs(BAM_Application, bGlobal.gBam); if (bGlobal.gWorld) { pWorld = ADerefAs(World, bGlobal.gWorld); pWorld->Save(AFTER_RESTORE); } else { pWorld = NULL; } bGlobal.roomMgr.Cycle(); pMemMgr->Cycle(); pSoundMgr->Cycle(); if(pWorld) { pBam->fPauseWorld = TRUE; //force ResumeTicks() to be called in PauseWorld pWorld->Pause(FALSE, TRUE); pBam->PauseWorld(); } else bGlobal.roomMgr.curRoom->Pause(FALSE, TRUE); #ifndef OLD_MOUSE_INTERRUPT_HANDLER MouseHandler( FALSE ); #endif } if(pWorld) if(pBam->fPauseWorld != pWorld->fIsPaused) pBam->PauseWorld(); #ifdef DEBUG_BIG_NET pMono->Out("main loop() done\n"); #endif #ifndef NDEBUG timers[TIMER_CYC_PER_FRAME].Stop(); #endif #ifndef NDEBUG pMono->SaveWindow(); pMono->Goto(24, 1); pMono->Out("CpF%5d UTick%5d CmC%5d GmA%5d Tx%4d:%dp@%4db]%c Rx[%4d]", timers[TIMER_CYC_PER_FRAME].duration, timers[TIMER_UPDATE_TICKS].duration, timers[TIMER_CONTEXT_CYCLE].duration, timers[TIMER_ANIMATE].duration, timers[TIMER_SYNC_SEND].duration, pCommMgr->pComm->totalPacketsSent, pCommMgr->pComm->totalBytesSent, fWaitToSend? 'W': 'w', timers[TIMER_SYNC_RECV].duration); pMono->Goto(25, 1); time(&timeDif); if(timeDif != lastTime) { lastTime = timeDif; framesPerSec = AMin(framesRun, 99); framesRun = 0; } else framesRun++; timeDif -= startTime; pMono->Out("%05dkt %05dkl %02d:%02d:%02d %2dFPS", pMemMgr->AvailMem() / 1024, pMemMgr->LargestAlloc() / 1024, timeDif / 3600, (timeDif / 60) % 60, timeDif % 60, framesPerSec); if(pWorld) { pMono->Goto(25, 32); pMono->Out("r%d g%d 0x%08x", pWorld->tileResNum, ALoad(RES_TILELIB, pWorld->tileResNum), AGetResData(ALoad(RES_TILELIB, pWorld->tileResNum))); } pCommMgr->pComm->totalBytesSent = 0; pCommMgr->pComm->totalPacketsSent = 0; pMono->RestoreWindow(); #endif #ifndef OLD_MOUSE_INTERRUPT_HANDLER MouseHandler( FALSE ); #endif } //=================================== LoadExitQuote(); //=================================== // get rid of our current room bGlobal.roomMgr.DeleteCurRoom(); // shut down communications if(pCommMgr) { pCommMgr->Disconnect(); pCommMgr->DiscardData(); delete pCommMgr; //its destructor will delete pComm pCommMgr = NULL; } if(bGlobal.gSnap) ADelete(bGlobal.gSnap); ADelete(bGlobal.gBam); // all actors should be removed from graphmgr, do one more // animate to clear lists. pGraphMgr->Animate(); ADelete(pContextMgr->gSelf); // TSound exitSound; // exitSound.Play(667); // while(exitSound.IsPlaying()) // pSoundMgr->Cycle(); // storm the office! kill all managers! ADelete(pGraphMgr->gSelf); ADelete(pFontMgr->gSelf); ADelete(pSoundMgr->gSelf); ADelete(pResMgr->gSelf); ADelete(pEventMgr->gSelf); ADelete(pMouse->gSelf); delete pMono; // DESTROY_MGR_CAREFUL(GraphicsMgr, pGraphMgr); // DESTROY_MGR_CAREFUL(Mono, pMono); // DESTROY_MGR_CAREFUL(FontMgr, pFontMgr); // DESTROY_MGR_CAREFUL(SoundMgr, pSoundMgr); // DESTROY_MGR(pResMgr); // DESTROY_MGR(pContextMgr); // DESTROY_MGR_CAREFUL(EventMgr, pEventMgr); #ifdef INTERACTIVE_DEMO DPMI dpmi; char *pScreen = (char *)dpmi.RealToProtected(0xB8000000); // kludge - remove "Installer" from data for(loop1 = 0; loop1 < 9; loop1++) MSG_DEMO_ENGL[86 + loop1 * 2] = ' '; memcpy(pScreen, (char *)MSG_DEMO_ENGL, 4000); while(!kbhit()); getch(); #endif system("mode co80"); // yeah, mega-cheesy I know. It's a bug patch. -Van printf("\n%s\n",exitMessage); printf("%s\n",exitAuthor); return 0; }
int main(int argc,char *argv[]) { char *t; if(timeBeginPeriod(1)!=TIMERR_NOERROR) { AddLogText("Error setting timer granularity to 1ms.",1); } if(!FCEUI_Initialize()) goto doexito; srand(GetTickCount()); // rand() is used for some GUI sillyness. fceu_hInstance=GetModuleHandle(0); GetBaseDirectory(); sprintf(TempArray,"%s\\fceu98.cfg",BaseDirectory); LoadConfig(TempArray); t=ParseArgies(argc,argv); /* Bleh, need to find a better place for this. */ { palyo&=1; FCEUI_SetVidSystem(palyo); genie&=1; FCEUI_SetGameGenie(genie); fullscreen&=1; soundo&=1; FCEUI_SetSoundVolume(soundvolume); FCEUI_SetSoundQuality(soundquality); } ParseGIInput(NULL); /* Since a game doesn't have to be loaded before the GUI can be used, make sure the temporary input type variables are set. */ CreateDirs(); SetDirs(); DoVideoConfigFix(); DoTimingConfigFix(); if(eoptions&EO_CPALETTE) FCEUI_SetPaletteArray(cpalette); if(!t) fullscreen=0; CreateMainWindow(); if(!InitDInput()) goto doexito; if(!DriverInitialize()) goto doexito; InitSpeedThrottle(); UpdateMenu(); if(t) ALoad(t); else if(eoptions&EO_FOAFTERSTART) LoadNewGamey(hAppWnd, 0); doloopy: UpdateFCEUWindow(); if(GI) { while(GI) { uint8 *gfx; int32 *sound; int32 ssize; FCEUI_Emulate(&gfx, &sound, &ssize, 0); xbsave = gfx; FCEUD_Update(gfx, sound, ssize); } xbsave = NULL; RedrawWindow(hAppWnd,0,0,RDW_ERASE|RDW_INVALIDATE); StopSound(); } Sleep(50); if(!exiting) goto doloopy; doexito: DriverKill(); timeEndPeriod(1); FCEUI_Kill(); return(0); }
void MakeChar::Setup() { BAM_Guy *pGuy; BAM_Button *pButton; uchar *pback; CelHeader *pbackCH; int x; uint rNumBord; //====================================================== // setup background cel filled with black TRACK_MEM("MakeChar background cel"); gback = ACreateCel(&rNumBack,0,0,320,400,CI_BLACK,100); pback = AGetResData(gback); pbackCH = (CelHeader*)pback; // copy this anim into the dynamic cel that we will use gbackAnim = ALoad(RES_ANIM,8150); CopyCel(pbackCH,0,0,RES_ANIM,8150,1,FALSE); pGuy = &back; pGuy->SetRes(RES_CEL,rNumBack); pGuy->SetPos(0,0); pGuy->SetContext(gSelf); pGuy->Setup(CT_ROST); pGuy->SetPri(100); //pal.FadeToBlack(); pal.Load(8150); // pick a gender catagory switch (ARandom(3)) { case 0: bGlobal.curCat = G_MEN; break; case 1: bGlobal.curCat = G_WOMEN; break; case 2: bGlobal.curCat = G_OTHER; break; } //====================================================== // lets copy in all the borders and boundaries into the background gPortBord = ALoad(RES_ANIM,8154); rNumBord = 8154; CopyCel((CelHeader*)pback,108,67,RES_ANIM,rNumBord,3,TRUE); // Name Frame CopyCel((CelHeader*)pback,108,92,RES_ANIM,rNumBord,1,TRUE); // Portrait Frame CopyCel((CelHeader*)pback,157,92,RES_ANIM,rNumBord,4,TRUE); // Arrow Buttons Frame CopyCel((CelHeader*)pback,108,191,RES_ANIM,rNumBord,5,TRUE); // Gender Buttons Frame CopyCel((CelHeader*)pback,108,222,RES_ANIM,rNumBord,6,TRUE); // Name Buttons Frame CopyCel((CelHeader*)pback,108,253,RES_ANIM,rNumBord,7,TRUE); // 'Done' Button Frame CopyCel((CelHeader*)pback,21,281,RES_ANIM,rNumBord,10,TRUE); // Option Button Frame //============================================= // Write the necessary text into the background pFontMgr->SetRes(9050); SetFontColors(CI_SKIP,64,74); pTxt = sqbMakeChar.Load(MAKECHAR_SQB,1); ASetString(206, 99, pTxt, (uchar *)pbackCH, pbackCH->width, NULL); pTxt = sqbMakeChar.Load(MAKECHAR_SQB,2); ASetString(206, 116, pTxt, (uchar *)pbackCH, pbackCH->width, NULL); pTxt = sqbMakeChar.Load(MAKECHAR_SQB,3); ASetString(206, 133, pTxt, (uchar *)pbackCH, pbackCH->width, NULL); pTxt = sqbMakeChar.Load(MAKECHAR_SQB,4); ASetString(206, 150, pTxt, (uchar *)pbackCH, pbackCH->width, NULL); pTxt = sqbMakeChar.Load(MAKECHAR_SQB,5); ASetString( 70, 198, pTxt, (uchar *)pbackCH, pbackCH->width, NULL); pTxt = sqbMakeChar.Load(MAKECHAR_SQB,6); ASetString( 82, 229, pTxt, (uchar *)pbackCH, pbackCH->width, NULL); pFontMgr->SetRes(9052); SetFontColors(CI_SKIP,93,76,74,74,48,CI_BLACK); pTxt = sqbMakeChar.Load(MAKECHAR_SQB,7); pFontMgr->SetString(0,330, pTxt, (uchar *)pbackCH, pbackCH->width, NULL, DG_JUST_CENTER); SetFontColors(CI_SKIP,45,46,47,49,50,CI_BLACK); pTxt = sqbMakeChar.Load(MAKECHAR_SQB,8); pFontMgr->SetString(0,372, pTxt, (uchar *)pbackCH, pbackCH->width, NULL, DG_JUST_CENTER); pFontMgr->SetRes(9050); SetFontColors(CI_SKIP,64,74); switch(bGlobal.curCat) { case G_MEN: sqbRes = MEN_SQB; if(!maxMenNameNum) maxMenNameNum = atoi(sqbMakeChar.Load(MEN_SQB,1)); //add 2 to num to get zero based random num past first sqb used above curNameNum = MyRandom(maxMenNameNum,curNameNum) + 2; break; case G_WOMEN: sqbRes = WOMEN_SQB; if(!maxWomenNameNum) maxWomenNameNum = atoi(sqbMakeChar.Load(WOMEN_SQB,1)); curNameNum = MyRandom(maxWomenNameNum,curNameNum) + 2; break; case G_OTHER: sqbRes = OTHER_SQB; if(!maxOtherNameNum) maxOtherNameNum = atoi(sqbMakeChar.Load(OTHER_SQB,1)); curNameNum = MyRandom(maxOtherNameNum,curNameNum) + 2; break; } pTxt = sqbMakeChar.Load(sqbRes,curNameNum); TRACK_MEM("NameText"); gNameText = AMalloc(20); char *pText = ADerefAs(char, gNameText); strcpy(bGlobal.curName,pTxt); strcpy(pText,pTxt); BAM_Box *pBox = &nameBox; pBox->SetColors(CI_SKIP,64,74,64,74,64,74,155,142); pBox->Create(111, 71, 105, 15, 200, gNameText, 16, gSelf, rNumBack,0,0); pBox->SetupReplies(REPLY_DESELECTED); // let us know when text changes //pBox->Select(TRUE); //makes the box edit active //====================================================== // setup current portrait -randomly init. LoadCover(); LoadFace(); LoadBody(); LoadBanner(); //====================================================== // lets setup up all the buttons uint32 posY[4] = { 95, 112, 129, 146 }; for(x=0; x<4; x++) { // create left arrow button pButton = &leftArrowB[x]; pButton->Create(159, posY[x], 200, RES_ANIM, 8156, 1, gSelf); pButton->SetupReplies(REPLY_DESELECTED); pButton->fIsToggle = FALSE; // click-type button pButton->SetOwnerCel(rNumBack); // draws itself into this DCEL, instead of being drawn by Animate() directly pButton->Select(FALSE); // set button to unselected state - will cause drawing into master cel // create right arrow button pButton = &rightArrowB[x]; pButton->Create(180, posY[x], 200, RES_ANIM, 8157, 1, gSelf); pButton->SetupReplies(REPLY_DESELECTED); pButton->fIsToggle = FALSE; // click-type button pButton->SetOwnerCel(rNumBack); // draws itself into this DCEL, instead of being drawn by Animate() directly pButton->Select(FALSE); // set button to unselected state - will cause drawing into master cel } // disk button pButton = &diskB; pButton->Create(23, 285, 200, RES_ANIM, 129, 1, gSelf); pButton->SetupReplies(REPLY_DESELECTED); pButton->fIsToggle = FALSE; // click-type button pButton->SetOwnerCel(rNumBack); // draws itself into this DCEL, instead of being drawn by Animate() directly pButton->Select(FALSE); // set button to unselected state - will cause drawing into master cel pButton = &randomCharB; pButton->Create(159, 163, 200, RES_ANIM, 8158, 1, gSelf); pButton->SetupReplies(REPLY_DESELECTED); pButton->fIsToggle = FALSE; // click-type button pButton->SetOwnerCel(rNumBack); // draws itself into this DCEL, instead of being drawn by Animate() directly pButton->SetTextJustify(DG_JUST_CENTER, DG_JUST_CENTER); pTxt = sqbMakeChar.Load(MAKECHAR_SQB,9); pButton->SetCelText(1, pTxt); pButton->SetColors(1, 93, 90); // inactive colors pButton->SetCelText(2, pTxt); pButton->SetColors(2, 155, 142); // active colors pButton->Draw(); pButton->Select(FALSE); // set button to unselected state - will cause drawing into master cel pButton = &manB; pButton->Create(110, 194, 200, RES_ANIM, 8158, 1, gSelf); pButton->SetupReplies(REPLY_ACTIVATED | REPLY_DEACTIVATED); pButton->fIsToggle = TRUE; // click-type button pButton->SetOwnerCel(rNumBack); // draws itself into this DCEL, instead of being drawn by Animate() directly pButton->SetTextJustify(DG_JUST_CENTER, DG_JUST_CENTER); pTxt = sqbMakeChar.Load(MAKECHAR_SQB,10); pButton->SetCelText(1, pTxt); pButton->SetColors(1, 93, 90); // inactive colors pButton->SetCelText(2, pTxt); pButton->SetColors(2, 155, 142); // active colors pButton->Draw(); if(bGlobal.curCat == G_MEN) pButton->Select(TRUE); // set button to unselected state - will cause drawing into master cel else pButton->Select(FALSE); // set button to unselected state - will cause drawing into master cel pButton = &womanB; pButton->Create(152, 194, 200, RES_ANIM, 8158, 1, gSelf); pButton->SetupReplies(REPLY_ACTIVATED | REPLY_DEACTIVATED); pButton->fIsToggle = TRUE; // click-type button pButton->SetOwnerCel(rNumBack); // draws itself into this DCEL, instead of being drawn by Animate() directly pButton->SetTextJustify(DG_JUST_CENTER, DG_JUST_CENTER); pTxt = sqbMakeChar.Load(MAKECHAR_SQB,11); pButton->SetCelText(1, pTxt); pButton->SetColors(1, 93, 90); // inactive colors pButton->SetCelText(2, pTxt); pButton->SetColors(2, 155, 142); // active colors pButton->Draw(); if(bGlobal.curCat == G_WOMEN) pButton->Select(TRUE); // set button to unselected state - will cause drawing into master cel else pButton->Select(FALSE); // set button to unselected state - will cause drawing into master cel pButton = &otherB; pButton->Create(194, 194, 200, RES_ANIM, 8158, 1, gSelf); pButton->SetupReplies(REPLY_ACTIVATED | REPLY_DEACTIVATED); pButton->fIsToggle = TRUE; // click-type button pButton->SetOwnerCel(rNumBack); // draws itself into this DCEL, instead of being drawn by Animate() directly pButton->SetTextJustify(DG_JUST_CENTER, DG_JUST_CENTER); pTxt = sqbMakeChar.Load(MAKECHAR_SQB,12); pButton->SetCelText(1, pTxt); pButton->SetColors(1, 93, 90); // inactive colors pButton->SetCelText(2, pTxt); pButton->SetColors(2, 155, 142); // active colors pButton->Draw(); if(bGlobal.curCat == G_OTHER) pButton->Select(TRUE); // set button to unselected state - will cause drawing into master cel else pButton->Select(FALSE); // set button to unselected state - will cause drawing into master cel pButton = &customNameB; pButton->Create(110, 225, 200, RES_ANIM, 8158, 1, gSelf); pButton->SetupReplies(REPLY_DESELECTED); pButton->fIsToggle = FALSE; // click-type button pButton->SetOwnerCel(rNumBack); // draws itself into this DCEL, instead of being drawn by Animate() directly pButton->SetTextJustify(DG_JUST_CENTER, DG_JUST_CENTER); pTxt = sqbMakeChar.Load(MAKECHAR_SQB,13); pButton->SetCelText(1, pTxt); pButton->SetColors(1, 93, 90); // inactive colors pButton->SetCelText(2, pTxt); pButton->SetColors(2, 155, 142); // active colors pButton->Draw(); pButton->Select(FALSE); // set button to unselected state - will cause drawing into master cel pButton = &randomNameB; pButton->Create(152, 225, 200, RES_ANIM, 8158, 1, gSelf); pButton->SetupReplies(REPLY_DESELECTED); pButton->fIsToggle = FALSE; // click-type button pButton->SetOwnerCel(rNumBack); // draws itself into this DCEL, instead of being drawn by Animate() directly pButton->SetTextJustify(DG_JUST_CENTER, DG_JUST_CENTER); pTxt = sqbMakeChar.Load(MAKECHAR_SQB,9); pButton->SetCelText(1, pTxt); pButton->SetColors(1, 93, 90); // inactive colors pButton->SetCelText(2, pTxt); pButton->SetColors(2, 155, 142); // active colors pButton->Draw(); pButton->Select(FALSE); // set button to unselected state - will cause drawing into master cel pButton = &doneB; pButton->Create(110, 256, 200, RES_ANIM, 8158, 1, gSelf); pButton->SetupReplies(REPLY_DESELECTED); pButton->fIsToggle = FALSE; // click-type button pButton->SetOwnerCel(rNumBack); // draws itself into this DCEL, instead of being drawn by Animate() directly pButton->SetTextJustify(DG_JUST_CENTER, DG_JUST_CENTER); pTxt = sqbMakeChar.Load(MAKECHAR_SQB,14); pButton->SetCelText(1, pTxt); pButton->SetColors(1, 93, 90); // inactive colors pButton->SetCelText(2, pTxt); pButton->SetColors(2, 155, 142); // active colors pButton->Draw(); pButton->Select(FALSE); // set button to unselected state - will cause drawing into master cel BAM_Room::Setup(); pGraphMgr->Animate(); pal.FadeUp(); }
int WINAPI WinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow ) { MSG uMsg; memset(&uMsg,0,sizeof(uMsg)); winClass.lpszClassName = "MY_WINDOWS_CLASS"; winClass.cbSize = sizeof(WNDCLASSEX); winClass.style = CS_HREDRAW | CS_VREDRAW; winClass.lpfnWndProc = WndProc; winClass.hInstance = hInstance; winClass.hIcon = LoadIcon(hInstance, MAKEINTRESOURCE(IDI_ICON1)); winClass.hIconSm = LoadIcon(hInstance, MAKEINTRESOURCE(IDI_ICON1)); winClass.hCursor = LoadCursor(NULL, IDC_ARROW); winClass.lpszMenuName = MAKEINTRESOURCE(IDC_CV); winClass.hbrBackground = (HBRUSH)GetStockObject(BLACK_BRUSH); winClass.cbClsExtra = 0; winClass.cbWndExtra = 0; OpenConsole(); if( !RegisterClassEx(&winClass) ) return E_FAIL; GetINIPath(); LoadSettings(); pcejin.aspectRatio = GetPrivateProfileInt("Video", "aspectratio", 0, IniName); pcejin.windowSize = GetPrivateProfileInt("Video", "pcejin.windowSize", 1, IniName); WndX = GetPrivateProfileInt("Main", "WndX", 0, IniName); WndY = GetPrivateProfileInt("Main", "WndY", 0, IniName); g_hWnd = CreateWindowEx( NULL, "MY_WINDOWS_CLASS", pcejin.versionName.c_str(), WS_OVERLAPPEDWINDOW | WS_VISIBLE, WndX, WndY, 256, 232, NULL, NULL, hInstance, NULL ); if( g_hWnd == NULL ) return E_FAIL; ScaleScreen(pcejin.windowSize); soundInit(); LoadIniSettings(); InitSpeedThrottle(); RecentROMs.SetGUI_hWnd(g_hWnd); RecentROMs.SetID(RECENTROM_START); RecentROMs.SetMenuID(ID_FILE_RECENTROM); RecentROMs.SetType("ROM"); RecentROMs.MakeRecentMenu(hInstance); RecentROMs.GetRecentItemsFromIni(IniName, "General"); RecentMovies.SetGUI_hWnd(g_hWnd); RecentMovies.SetID(RECENTMOVIE_START); RecentMovies.SetMenuID(ID_MOVIE_RECENT); RecentMovies.SetType("Movie"); RecentMovies.MakeRecentMenu(hInstance); RecentMovies.GetRecentItemsFromIni(IniName, "General"); RecentLua.SetGUI_hWnd(g_hWnd); RecentLua.SetID(RECENTLUA_START); RecentLua.SetMenuID(ID_LUA_RECENT); RecentLua.SetType("Lua"); RecentLua.MakeRecentMenu(hInstance); RecentLua.GetRecentItemsFromIni(IniName, "General"); DirectDrawInit(); InitCustomControls(); InitCustomKeys(&CustomKeys); LoadHotkeyConfig(); LoadInputConfig(); DragAcceptFiles(g_hWnd, true); extern void Agg_init(); Agg_init(); if (osd) {delete osd; osd =NULL; } osd = new OSDCLASS(-1); di_init(); DWORD wmTimerRes; TIMECAPS tc; if (timeGetDevCaps(&tc, sizeof(TIMECAPS))== TIMERR_NOERROR) { wmTimerRes = std::min(std::max(tc.wPeriodMin, (UINT)1), tc.wPeriodMax); timeBeginPeriod (wmTimerRes); } else { wmTimerRes = 5; timeBeginPeriod (wmTimerRes); } if (KeyInDelayMSec == 0) { DWORD dwKeyboardDelay; SystemParametersInfo(SPI_GETKEYBOARDDELAY, 0, &dwKeyboardDelay, 0); KeyInDelayMSec = 250 * (dwKeyboardDelay + 1); } if (KeyInRepeatMSec == 0) { DWORD dwKeyboardSpeed; SystemParametersInfo(SPI_GETKEYBOARDSPEED, 0, &dwKeyboardSpeed, 0); KeyInRepeatMSec = (int)(1000.0/(((30.0-2.5)/31.0)*dwKeyboardSpeed+2.5)); } if (KeyInRepeatMSec < (int)wmTimerRes) KeyInRepeatMSec = (int)wmTimerRes; if (KeyInDelayMSec < KeyInRepeatMSec) KeyInDelayMSec = KeyInRepeatMSec; hKeyInputTimer = timeSetEvent (KeyInRepeatMSec, 0, KeyInputTimer, 0, TIME_PERIODIC); ShowWindow( g_hWnd, nCmdShow ); UpdateWindow( g_hWnd ); initialize(); if (lpCmdLine[0])ParseCmdLine(lpCmdLine, g_hWnd); if (RecentROMs.GetAutoLoad() && (!skipAutoLoadROM)) { ALoad(RecentROMs.GetRecentItem(0).c_str()); } //Intentionally does not prompt for a game if no game specified, user should be forced to autoload roms as well, for this to work properly if (RecentMovies.GetAutoLoad() && (!skipAutoLoadMovie)) { LoadMovie(RecentMovies.GetRecentItem(0).c_str(), 1, false, false); } if (RecentLua.GetAutoLoad() && (!skipAutoLoadLua)) { char temp [1024]; strcpy(temp, RecentLua.GetRecentItem(0).c_str()); HWND hDlg = CreateDialog(g_hInstance, MAKEINTRESOURCE(IDD_LUA), g_hWnd, (DLGPROC) LuaScriptProc); SendDlgItemMessage(hDlg,IDC_EDIT_LUAPATH,WM_SETTEXT,0,(LPARAM)temp); } while( uMsg.message != WM_QUIT ) { if( PeekMessage( &uMsg, NULL, 0, 0, PM_REMOVE ) ) { TranslateMessage( &uMsg ); DispatchMessage( &uMsg ); } else { emulate(); render(); } if(!pcejin.started) Sleep(1); } // shutDown(); timeEndPeriod (wmTimerRes); CloseAllToolWindows(); UnregisterClass( "MY_WINDOWS_CLASS", winClass.hInstance ); return uMsg.wParam; }
LRESULT CALLBACK WndProc(HWND hWnd, UINT Message, WPARAM wParam, LPARAM lParam) { int wmId, wmEvent; HWND hDlg; switch(Message) { case WM_KEYDOWN: if(wParam != VK_PAUSE) break; // case WM_SYSKEYDOWN: case WM_CUSTKEYDOWN: { int modifiers = GetModifiers(wParam); if(!HandleKeyMessage(wParam,lParam, modifiers)) return 0; break; } case WM_KEYUP: if(wParam != VK_PAUSE) break; case WM_SYSKEYUP: case WM_CUSTKEYUP: { int modifiers = GetModifiers(wParam); HandleKeyUp(wParam, lParam, modifiers); } break; case WM_SIZE: switch(wParam) { case SIZE_MINIMIZED: break; case SIZE_MAXIMIZED: pcejin.maximized = true; break; case SIZE_RESTORED: pcejin.maximized = false; break; default: break; } return 0; case WM_MOVE: RECT rect; GetWindowRect(hWnd,&rect); WndX = rect.left; WndY = rect.top; return 0; case WM_DROPFILES: { char filename[MAX_PATH] = ""; DragQueryFile((HDROP)wParam,0,filename,MAX_PATH); DragFinish((HDROP)wParam); std::string fileDropped = filename; //------------------------------------------------------- //Check if mcm file, if so auto-convert and play //------------------------------------------------------- if (!(fileDropped.find(".mcm") == std::string::npos) && (fileDropped.find(".mcm") == fileDropped.length()-4)) { if (!pcejin.romLoaded) //If no ROM is loaded, prompt for one { soundDriver->pause(); LoadGame(); pcejin.tempUnPause(); } if (pcejin.romLoaded && !(fileDropped.find(".mcm") == std::string::npos)) LoadMCM(fileDropped.c_str(), true); } //------------------------------------------------------- //Check if Movie file //------------------------------------------------------- else if (!(fileDropped.find(".mc2") == std::string::npos) && (fileDropped.find(".mc2") == fileDropped.length()-4)) { if (!pcejin.romLoaded) //If no ROM is loaded, prompt for one { soundDriver->pause(); LoadGame(); pcejin.tempUnPause(); } if (pcejin.romLoaded && !(fileDropped.find(".mc2") == std::string::npos)) { LoadMovie(fileDropped.c_str(), 1, false, false); RecentMovies.UpdateRecentItems(fileDropped); } } //------------------------------------------------------- //Check if Savestate file //------------------------------------------------------- else if (!(fileDropped.find(".nc") == std::string::npos)) { if (fileDropped.find(".nc") == fileDropped.length()-4) { if ((fileDropped[fileDropped.length()-1] >= '0' && fileDropped[fileDropped.length()-1] <= '9')) { MDFNSS_Load(filename, NULL); UpdateToolWindows(); } } } //------------------------------------------------------- //Check if Lua script file //------------------------------------------------------- else if (!(fileDropped.find(".lua") == std::string::npos) && (fileDropped.find(".lua") == fileDropped.length()-4)) //ROM is already loaded and .dsm in filename { if(LuaScriptHWnds.size() < 16) { char temp [1024]; strcpy(temp, fileDropped.c_str()); HWND IsScriptFileOpen(const char* Path); RecentLua.UpdateRecentItems(fileDropped); if(!IsScriptFileOpen(temp)) { HWND hDlg = CreateDialog(g_hInstance, MAKEINTRESOURCE(IDD_LUA), hWnd, (DLGPROC) LuaScriptProc); SendDlgItemMessage(hDlg,IDC_EDIT_LUAPATH,WM_SETTEXT,0,(LPARAM)temp); } } } //------------------------------------------------------- //Check if watchlist file //------------------------------------------------------- else if (!(fileDropped.find(".wch") == std::string::npos) && (fileDropped.find(".wch") == fileDropped.length()-4)) //ROM is already loaded and .dsm in filename { if(!RamWatchHWnd) { RamWatchHWnd = CreateDialog(g_hInstance, MAKEINTRESOURCE(IDD_RAMWATCH), hWnd, (DLGPROC) RamWatchProc); } else SetForegroundWindow(RamWatchHWnd); Load_Watches(true, fileDropped.c_str()); } //------------------------------------------------------- //Else load it as a ROM //------------------------------------------------------- else { ALoad(fileDropped.c_str()); } } return 0; case WM_ENTERMENULOOP: soundDriver->pause(); EnableMenuItem(GetMenu(hWnd), IDM_RECORD_MOVIE, MF_BYCOMMAND | (movieMode == MOVIEMODE_INACTIVE && pcejin.romLoaded) ? MF_ENABLED : MF_GRAYED); EnableMenuItem(GetMenu(hWnd), IDM_PLAY_MOVIE, MF_BYCOMMAND | (movieMode == MOVIEMODE_INACTIVE && pcejin.romLoaded) ? MF_ENABLED : MF_GRAYED); EnableMenuItem(GetMenu(hWnd), IDM_STOPMOVIE, MF_BYCOMMAND | (movieMode != MOVIEMODE_INACTIVE) ? MF_ENABLED : MF_GRAYED); EnableMenuItem(GetMenu(hWnd), IDM_RESTARTMOVIE, MF_BYCOMMAND | (movieMode != MOVIEMODE_INACTIVE) ? MF_ENABLED : MF_GRAYED); EnableMenuItem(GetMenu(hWnd), IDM_FILE_STOPAVI, MF_BYCOMMAND | (DRV_AviIsRecording()) ? MF_ENABLED : MF_GRAYED); EnableMenuItem(GetMenu(hWnd), IDM_FILE_RECORDAVI, MF_BYCOMMAND | (!DRV_AviIsRecording()) ? MF_ENABLED : MF_GRAYED); //Window Size checkMenu(IDC_WINDOW1X, ((pcejin.windowSize==1))); checkMenu(IDC_WINDOW2X, ((pcejin.windowSize==2))); checkMenu(IDC_WINDOW3X, ((pcejin.windowSize==3))); checkMenu(IDC_WINDOW4X, ((pcejin.windowSize==4))); checkMenu(IDC_ASPECT, ((pcejin.aspectRatio))); checkMenu(ID_VIEW_FRAMECOUNTER,Hud.FrameCounterDisplay); checkMenu(ID_VIEW_DISPLAYINPUT,Hud.ShowInputDisplay); checkMenu(ID_VIEW_DISPLAYSTATESLOTS,Hud.DisplayStateSlots); checkMenu(ID_VIEW_DISPLAYLAG,Hud.ShowLagFrameCounter); checkMenu(IDM_MUTE,soundDriver->userMute); break; case WM_EXITMENULOOP: pcejin.tempUnPause(); break; case WM_CLOSE: { SaveIniSettings(); PostQuitMessage(0); } case WM_DESTROY: { PostQuitMessage(0); } // HANDLE_MSG(hWnd, WM_DESTROY, OnDestroy); // HANDLE_MSG(hWnd, WM_PAINT, OnPaint); // HANDLE_MSG(hwnd, WM_COMMAND, OnCommand); case WM_COMMAND: //Recent ROMs if(wParam >= RECENTROM_START && wParam <= RECENTROM_START + RecentROMs.MAX_RECENT_ITEMS - 1) { ALoad(RecentROMs.GetRecentItem(wParam - RECENTROM_START).c_str()); break; } else if (wParam == RecentROMs.GetClearID()) { RecentROMs.ClearRecentItems(); break; } else if (wParam == RecentROMs.GetAutoloadID()) { RecentROMs.FlipAutoLoad(); break; } //Recent Movies if(wParam >= RECENTMOVIE_START && wParam <= RECENTMOVIE_START + RecentMovies.MAX_RECENT_ITEMS - 1) { strcpy(Tmp_Str, RecentMovies.GetRecentItem(wParam - RECENTMOVIE_START).c_str()); RecentMovies.UpdateRecentItems(Tmp_Str); //WIN32_StartMovieReplay(Str_Tmp); break; } else if (wParam == RecentMovies.GetClearID()) { RecentMovies.ClearRecentItems(); break; } else if (wParam == RecentMovies.GetAutoloadID()) { RecentMovies.FlipAutoLoad(); break; } //Recent Lua if(wParam >= RECENTLUA_START && wParam <= RECENTLUA_START + RecentLua.MAX_RECENT_ITEMS - 1) { if(LuaScriptHWnds.size() < 16) { char temp [1024]; strcpy(temp, RecentLua.GetRecentItem(wParam - RECENTLUA_START).c_str()); HWND IsScriptFileOpen(const char* Path); RecentLua.UpdateRecentItems(temp); if(!IsScriptFileOpen(temp)) { HWND hDlg = CreateDialog(g_hInstance, MAKEINTRESOURCE(IDD_LUA), hWnd, (DLGPROC) LuaScriptProc); SendDlgItemMessage(hDlg,IDC_EDIT_LUAPATH,WM_SETTEXT,0,(LPARAM)temp); } } break; } else if (wParam == RecentLua.GetClearID()) { RecentLua.ClearRecentItems(); break; } else if (wParam == RecentLua.GetAutoloadID()) { RecentLua.FlipAutoLoad(); break; } wmId = LOWORD(wParam); wmEvent = HIWORD(wParam); // Parse the menu selections: switch (wmId) { case IDC_WINDOW1X: pcejin.windowSize=1; ScaleScreen(pcejin.windowSize); break; case IDC_WINDOW2X: pcejin.windowSize=2; ScaleScreen(pcejin.windowSize); break; case IDC_WINDOW3X: pcejin.windowSize=3; ScaleScreen(pcejin.windowSize); break; case IDC_WINDOW4X: pcejin.windowSize=4; ScaleScreen(pcejin.windowSize); break; case IDC_ASPECT: pcejin.aspectRatio ^= 1; ScaleScreen(pcejin.windowSize); break; case IDM_EXIT: SaveIniSettings(); PostQuitMessage(0); break; case IDM_RESET: PCE_Power(); break; case IDM_OPEN_ROM: soundDriver->pause(); LoadGame(); pcejin.tempUnPause(); break; case IDM_RECORD_MOVIE: soundDriver->pause(); MovieRecordTo(); pcejin.tempUnPause(); return 0; case IDM_PLAY_MOVIE: soundDriver->pause(); Replay_LoadMovie(); pcejin.tempUnPause(); return 0; case IDM_INPUT_CONFIG: soundDriver->pause(); DialogBox(g_hInstance, MAKEINTRESOURCE(IDD_INPUTCONFIG), hWnd, DlgInputConfig); pcejin.tempUnPause(); // RunInputConfig(); break; case IDM_HOTKEY_CONFIG: { soundDriver->pause(); DialogBox(g_hInstance, MAKEINTRESOURCE(IDD_KEYCUSTOM), hWnd, DlgHotkeyConfig); pcejin.tempUnPause(); } break; case IDM_BIOS_CONFIG: soundDriver->pause(); DialogBox(g_hInstance, MAKEINTRESOURCE(IDD_BIOS), hWnd, (DLGPROC) BiosSettingsDlgProc); // DialogBox(g_hInstance, MAKEINTRESOURCE(IDD_KEYCUSTOM), hWnd, BiosSettingsDlgProc); pcejin.tempUnPause(); break; case ID_VIEW_FRAMECOUNTER: Hud.FrameCounterDisplay ^= true; WritePrivateProfileBool("Display", "FrameCounter", Hud.FrameCounterDisplay, IniName); return 0; case ID_VIEW_DISPLAYINPUT: Hud.ShowInputDisplay ^= true; WritePrivateProfileBool("Display", "Display Input", Hud.ShowInputDisplay, IniName); osd->clear(); return 0; case ID_VIEW_DISPLAYSTATESLOTS: Hud.DisplayStateSlots ^= true; WritePrivateProfileBool("Display", "Display State Slots", Hud.DisplayStateSlots, IniName); osd->clear(); return 0; case ID_VIEW_DISPLAYLAG: Hud.ShowLagFrameCounter ^= true; WritePrivateProfileBool("Display", "Display Lag Counter", Hud.ShowLagFrameCounter, IniName); osd->clear(); return 0; case IDC_NEW_LUA_SCRIPT: if(LuaScriptHWnds.size() < 16) { CreateDialog(g_hInstance, MAKEINTRESOURCE(IDD_LUA), g_hWnd, (DLGPROC) LuaScriptProc); } break; case IDM_CONVERT_MCM: ConvertMCM(hWnd); break; case IDM_MUTE: soundDriver->doUserMute(); break; case IDM_STOPMOVIE: StopMovie(); return 0; break; case IDM_RESTARTMOVIE: PCE_Power(); ResetFrameCount(); movieMode = MOVIEMODE_PLAY; movie_readonly = true; return 0; break; case ID_RAM_SEARCH: if(!RamSearchHWnd) { InitRamSearch(); RamSearchHWnd = CreateDialog(winClass.hInstance, MAKEINTRESOURCE(IDD_RAMSEARCH), hWnd, (DLGPROC) RamSearchProc); } else SetForegroundWindow(RamSearchHWnd); break; case ID_RAM_WATCH: if(!RamWatchHWnd) { RamWatchHWnd = CreateDialog(winClass.hInstance, MAKEINTRESOURCE(IDD_RAMWATCH), hWnd, (DLGPROC) RamWatchProc); } else SetForegroundWindow(RamWatchHWnd); return 0; case IDM_MEMORY: if (!RegWndClass("MemView_ViewBox", MemView_ViewBoxProc, 0, sizeof(CMemView*))) return 0; OpenToolWindow(new CMemView()); return 0; case IDM_ABOUT: soundDriver->pause(); DialogBox(winClass.hInstance, MAKEINTRESOURCE(IDD_ABOUTBOX), hWnd, About); pcejin.tempUnPause(); break; case IDM_FILE_RECORDAVI: soundDriver->pause(); RecordAvi(); pcejin.tempUnPause(); break; case IDM_FILE_STOPAVI: StopAvi(); break; } break; } return DefWindowProc(hWnd, Message, wParam, lParam); }
void Init_Loaded() { ALoad(working_file.c_str(), NULL, true); std::printf("ROM Loaded.\n"); std::printf("Starting playback..\n"); }
void WinLose::Setup(grip gPal,bool fadeup) { BAM_Guy *pGuy; BAM_Button *pButton; uchar *pback; CelHeader *pbackAnimCH,*pbackCH; int i,portNum; prevFont = pFontMgr->curFontNum; pFontMgr->SetRes(9050); //====================================================== //pResMgr->Dump(); //pMemMgr->Dump(1, "Start WinLose::Setup"); if(bGlobal.storyLine == NETGAME && !bGlobal.netDisconnect) mode = M_MODELESS; else mode = M_MODAL; oldMouseResType = pMouse->GetResType(); oldMouseResNum = pMouse->GetResNum(); oldMouseCel = pMouse->GetCel(); pMouse->SetRes(RES_ANIM,POINTER_RES,1); oldMouseLimits.Copy(&pMouse->mouseLimits); TRACK_MEM("WinLose: background anim"); gbackAnim = ALoad(RES_ANIM,50); pbackAnimCH = (CelHeader*) AGetResData(gbackAnim); // os-mac stuff is for this screen to be centered. since // the blue/grey fadeTo doesn't work the first time in and // it looks funny to have the screen in the top left #ifdef OS_MAC extern bool startup_game; int xCoord; int yCoord; if (startup_game) { xCoord = 160 - (pbackAnimCH->width/2); yCoord = 200 - (pbackAnimCH->height/2); rback.Set(xCoord,yCoord,xCoord-1+pbackAnimCH->width,yCoord-1+pbackAnimCH->height); } else //rback.Set(0,0,pbackAnimCH->width-1,pbackAnimCH->height-1); rback.Set(WINLOSE_WIN_X+0,WINLOSE_WIN_Y+0,WINLOSE_WIN_X+pbackAnimCH->width-1,WINLOSE_WIN_Y+pbackAnimCH->height-1); #else //rback.Set(0,0,pbackAnimCH->width-1,pbackAnimCH->height-1); rback.Set(WINLOSE_WIN_X+0,WINLOSE_WIN_Y+0,WINLOSE_WIN_X+pbackAnimCH->width-1,WINLOSE_WIN_Y+pbackAnimCH->height-1); #endif //====================================================== // setup background cel filled with black TRACK_MEM("WinLose: background cel"); gback = ACreateCel(&rNumBack,0,0,pbackAnimCH->width,pbackAnimCH->height,CI_BLACK,WINLOSE_BASE_PRI); pback = AGetResData(gback); pbackCH = (CelHeader*)pback; //copy backAnim into our dynamic cel -this way we can still write direct CopyCel(pbackCH,0,0,RES_ANIM,50,1,FALSE); pGuy = &back; pGuy->SetRes(RES_CEL,rNumBack); #ifdef OS_MAC if(startup_game) pGuy->SetPos(xCoord,yCoord); else pGuy->SetPos(WINLOSE_WIN_X,WINLOSE_WIN_Y); #else pGuy->SetPos(WINLOSE_WIN_X,WINLOSE_WIN_Y); #endif pGuy->SetContext(gSelf); pGuy->Setup(CT_ROST); pGuy->SetPri(WINLOSE_BASE_PRI); pGuy = &topBorder; pGuy->SetRes(RES_ANIM,116,5); pGuy->SetPos(0,0); pGuy->SetContext(gSelf); pGuy->Setup(CT_ROST); pGuy->SetPri(WINLOSE_BASE_PRI-20); pGuy = &sideBorder; pGuy->SetRes(RES_ANIM,118,1); pGuy->SetPos(0,25); pGuy->SetContext(gSelf); pGuy->Setup(CT_ROST); pGuy->SetPri(WINLOSE_BASE_PRI-19); pMouse->SetLimits(&rback); //need to get these new interface pieces onto the screen BEFORE //the do the screen capture and fade down AAnimate(); //====================================================== // 0 percent fade down -just remaps colors to blue-gray range. fadeTo.Setup(320,400,WINLOSE_BASE_PRI - 10,gSelf,gPal,0,&rback); //=============================================================== char winText[100],loseText[100]; int winNum,loseNum; sqbRes = WINLOSE_SQB; // load generic "front-end" used in all phrases pTxt = sqbWinLose.Load(sqbRes,1); strcpy(winText,pTxt); pTxt = sqbWinLose.Load(sqbRes,2); strcpy(loseText,pTxt); struct WinningCondition *pWinCon; //defaults winNum = atoi(pBam->scenarioName); loseNum = winNum + 1; if((bGlobal.storyLine == LEGEND && winNum != 9410) || bGlobal.storyLine == NETGAME) { winNum = 10; loseNum = 20; for(i=0;i<MAX_WINCONS;i++) { pWinCon = &pWorld->winCons[i]; if(pWinCon->targetSpec == BUILDING && pWinCon->structSpec == FUNC_KEEP) { if(pWinCon->ownerSide == pBam->playerSide) winNum = 11; if(pWinCon->ownerSide == ((pBam->playerSide==SIDE1)?SIDE2:SIDE1)) loseNum = 21; } } } pTxt = sqbWinLose.Load(sqbRes,winNum); strcat(winText," "); strcat(winText,pTxt); pTxt = sqbWinLose.Load(sqbRes,loseNum); strcat(loseText," "); strcat(loseText,pTxt); pBam->voiceChains = 0; pBam->voice1.Stop(); pBam->LaunchVoice(WINLOSE_SQB,winNum,WINLOSE_SQB,loseNum); //================================================== SetFontColors(CI_SKIP,94,102,94,102,156,144); int savePoint; savePoint = pFontMgr->point; pFontMgr->point = 14; ASetString(85, 48, winText, pback,102, NULL); ASetString(85, 137, loseText,pback,102, NULL); pFontMgr->point = savePoint; //================================================== //copy borders into background cel if(bGlobal.storyLine != LEGEND && bGlobal.storyLine != NETGAME) { CopyCel(pbackCH,35, 35,RES_ANIM,50,2,TRUE); // Portrait Border 1 CopyCel(pbackCH,35,123,RES_ANIM,50,2,TRUE); // Portrait Border 2 } else { CopyCel(pbackCH,35,77,RES_ANIM,50,2,TRUE); // Portrait Border 2 } if(bGlobal.storyLine == STORYLINE4) { CopyCel(pbackCH,35,212,RES_ANIM,50,4,TRUE); // 'Done' button frame CopyCel(pbackCH,92,212,RES_ANIM,50,3,TRUE); // 'Undone' button frame } else { CopyCel(pbackCH,64,212,RES_ANIM,50,3,TRUE); // 'Done' w/undone button frame } if(bGlobal.storyLine != LEGEND && bGlobal.storyLine != NETGAME) { portNum = GetPortraitAnim(bGlobal.chooseSide,TRUE); CopyCel(pbackCH,37,38,RES_ANIM,portNum,3,TRUE); //VICTORY CopyCel(pbackCH,37,126,RES_ANIM,portNum,2,TRUE); //DEFEAT } else { //Load portrait CopyCel(pbackCH,37,80,RES_ANIM,bGlobal.curBodyAnim,1,TRUE); // Body CopyCel(pbackCH,37,80,RES_ANIM,bGlobal.curFaceAnim,1,TRUE); // Face CopyCel(pbackCH,37,80,RES_ANIM,bGlobal.curCoverAnim,1,TRUE); // Cover } pButton = &buttonDone; if(bGlobal.storyLine == STORYLINE4) #ifdef OS_MAC if(startup_game) pButton->Create(37+xCoord, 215+yCoord, WINLOSE_BASE_PRI + 1, RES_ANIM, 8158, 1, gSelf, xCoord, yCoord); else pButton->Create(WINLOSE_WIN_X+37, WINLOSE_WIN_Y+215, WINLOSE_BASE_PRI + 1, RES_ANIM, 8158, 1, gSelf, WINLOSE_WIN_X, WINLOSE_WIN_Y); #else pButton->Create(WINLOSE_WIN_X+37, WINLOSE_WIN_Y+215, WINLOSE_BASE_PRI + 1, RES_ANIM, 8158, 1, gSelf, WINLOSE_WIN_X, WINLOSE_WIN_Y); #endif else #ifdef OS_MAC if(startup_game)