static void ResizeStep2(void) { g_CritialSection.Lock(); // Delete all OpenGL textures gTextureManager.CleanUp(); RDP_Cleanup(); // delete our opengl renderer CDeviceBuilder::GetBuilder()->DeleteRender(); // call video extension function with updated width, height (this creates a new OpenGL context) windowSetting.uDisplayWidth = status.gNewResizeWidth; windowSetting.uDisplayHeight = status.gNewResizeHeight; CoreVideo_ResizeWindow(windowSetting.uDisplayWidth, windowSetting.uDisplayHeight); // re-initialize our OpenGL graphics context state bool res = CGraphicsContext::Get()->ResizeInitialize(windowSetting.uDisplayWidth, windowSetting.uDisplayHeight, !windowSetting.bDisplayFullscreen); if (res) { // re-create the OpenGL renderer CDeviceBuilder::GetBuilder()->CreateRender(); CRender::GetRender()->Initialize(); DLParser_Init(); } g_CritialSection.Unlock(); status.ToResize = false; }
EXPORT void CALL RomOpen(void) { #ifdef DEBUGON // _break(); #endif InitConfiguration(); if( g_CritialSection.IsLocked() ) { g_CritialSection.Unlock(); TRACE0("g_CritialSection is locked when game is starting, unlock it now."); } status.bDisableFPS=false; #if defined(__GX__) # ifdef USE_EXPANSION g_dwRamSize = 0x800000; # else g_dwRamSize = 0x400000; # endif #else //__GX__ g_dwRamSize = 0x800000; #endif //!__GX__ #ifdef _DEBUG if( debuggerPause ) { debuggerPause = FALSE; usleep(100 * 1000); } #endif #ifdef USING_THREAD uint32 threadID; for(int i = 0; i < 5; i++) { threadMsg[i] = CreateEvent( NULL, FALSE, FALSE, NULL ); if (threadMsg[i] == NULL) { ErrorMsg( "Error creating thread message events"); return; } } threadFinished = CreateEvent( NULL, FALSE, FALSE, NULL ); if (threadFinished == NULL) { ErrorMsg( "Error creating video thread finished event"); return; } videoThread = CreateThread( NULL, 4096, VideoThreadProc, NULL, NULL, &threadID ); #else StartVideo(); #endif #ifdef __GX__ VIDEO_SetPreRetraceCallback(VI_GX_PreRetraceCallback); #endif // __GX__ }
//=================================== void ConfigDestroy () { s_critsect.Enter(); { for_each(s_dirMonitors.begin(), s_dirMonitors.end(), DestroyDirMonitor_CS()); s_dirMonitors.clear(); } s_critsect.Leave(); // Wait until all directory monitors are deleted asynchronously while (s_dirCount) Sleep(1); }
//=================================== void DirMonitor::TaskComplete ( unsigned bytes, OVERLAPPED * ) { s_critsect.Enter(); { if (m_handle == INVALID_HANDLE_VALUE) { // The monitor is ready to be deleted } // If no bytes read then m_buffer wasn't large enough to hold all the // updates; scan the directory to see which files need to be updated else if (!bytes) { ScanDirectoryForChanges_CS(); } // Otherwise process the file notifications else for (const FILE_NOTIFY_INFORMATION * info = (const FILE_NOTIFY_INFORMATION *) m_buffer;;) { // Validate the structure // DebugMsg(" %u: %.*S\n", info->Action, info->FileNameLength / sizeof(info->FileName[0]), info->FileName); #ifdef ASSERTIONS_ENABLED size_t offset = (size_t) ((const byte *) info - (const byte *) m_buffer); ASSERT(offset < bytes); ASSERT(offset < sizeof_field(DirMonitor, m_buffer)); #endif // Deleting or renaming a file does not cause re-parsing if ((info->Action == FILE_ACTION_REMOVED) || (info->Action == FILE_ACTION_RENAMED_OLD_NAME)) { // DebugMsg("%.*S deleted\n", info->FileNameLength / sizeof(info->FileName[0]), filename); } else { // Convert to lowercase for hash matching wchar filename[MAX_PATH]; StrCopy(filename, min(_countof(filename), info->FileNameLength / sizeof(info->FileName[0]) + 1), info->FileName); CharLowerW(filename); // Reparse if file changed CheckReparseFile_CS(filename); } // Move to next entry if (!info->NextEntryOffset) break; info = (const FILE_NOTIFY_INFORMATION *) ((const byte *) info + info->NextEntryOffset); } WatchDirectory_CS(); } s_critsect.Leave(); }
//--------------------------------------------------------------------------------------- // Static (local) functions static void ChangeWindowStep2() { status.bDisableFPS = true; windowSetting.bDisplayFullscreen = !windowSetting.bDisplayFullscreen; g_CritialSection.Lock(); windowSetting.bDisplayFullscreen = CGraphicsContext::Get()->ToggleFullscreen(); CGraphicsContext::Get()->Clear(CLEAR_COLOR_AND_DEPTH_BUFFER); CGraphicsContext::Get()->UpdateFrame(); CGraphicsContext::Get()->Clear(CLEAR_COLOR_AND_DEPTH_BUFFER); CGraphicsContext::Get()->UpdateFrame(); CGraphicsContext::Get()->Clear(CLEAR_COLOR_AND_DEPTH_BUFFER); CGraphicsContext::Get()->UpdateFrame(); g_CritialSection.Unlock(); status.bDisableFPS = false; status.ToToggleFullScreen = FALSE; }
void StopVideo() { if( CGraphicsContext::Get()->IsWindowed() == false ) { status.ToToggleFullScreen = TRUE; CGraphicsContext::Get()->ToggleFullscreen(); status.ToToggleFullScreen = FALSE; } g_CritialSection.Lock(); status.bGameIsRunning = false; try { // Kill all textures? gTextureManager.RecycleAllTextures(); gTextureManager.CleanUp(); RDP_Cleanup(); CloseExternalTextures(); CDeviceBuilder::GetBuilder()->DeleteRender(); CGraphicsContext::Get()->CleanUp(); CDeviceBuilder::GetBuilder()->DeleteGraphicsContext(); } catch(...) { TRACE0("Some exceptions during RomClosed"); } g_CritialSection.Unlock(); windowSetting.dps = windowSetting.fps = -1; windowSetting.lastSecDlistCount = windowSetting.lastSecFrameCount = 0xFFFFFFFF; status.gDlistCount = status.gFrameCount = 0; #ifndef _XBOX KillTimer(g_GraphicsInfo.hWnd, windowSetting.timer); if( windowSetting.screenSaverStatus ) SystemParametersInfo(SPI_SETSCREENSAVEACTIVE, TRUE, 0, 0); // Enable screen saver #endif DEBUGGER_ONLY({delete surfTlut;});
//=================================== void ConfigMonitorFile (const wchar filename[]) { // Convert to canonical lowercase form wchar fullpath[MAX_PATH]; if (!GetFullPathNameW(filename, _countof(fullpath), fullpath, NULL)) { LOG_OS_LAST_ERROR(L"GetFullPathNameW"); FatalError(); } CharLowerW(fullpath); // Create the directory that contains the file to be watched wchar directory[MAX_PATH]; PathRemoveFileName(directory, _countof(directory), fullpath); if (!PathCreateDirectory(directory)) FatalError(); // Get the filename part filename = PathFindFileNameW(fullpath); s_critsect.Enter(); { // Create a monitor for this directory DirMonitor * dir = FindOrCreateDirectoryMonitor_CS(directory); // Does this file already exist in the monitor's file list? ConfigFile * file; ConfigFileMap::iterator pair = dir->m_files.find(filename); if (pair == dir->m_files.end()) { file = new ConfigFile(fullpath); dir->m_files.insert(ConfigFilePair(file->m_filename, file)); } else { file = pair->second; } // TODO: signal file for reparsing so the callback gets called. } s_critsect.Leave(); }
void ChangeWindowStep2() { #ifndef _XBOX status.bDisableFPS = true; windowSetting.bDisplayFullscreen = 1-windowSetting.bDisplayFullscreen; g_CritialSection.Lock(); windowSetting.bDisplayFullscreen = CGraphicsContext::Get()->ToggleFullscreen(); if( windowSetting.bDisplayFullscreen ) { if( g_GraphicsInfo.hStatusBar != NULL ) { ShowWindow(g_GraphicsInfo.hStatusBar, SW_HIDE); } ShowCursor(FALSE); } else { if( g_GraphicsInfo.hStatusBar != NULL ) { ShowWindow(g_GraphicsInfo.hStatusBar, SW_SHOW); } ShowCursor(TRUE); } CGraphicsContext::Get()->Clear(CLEAR_COLOR_AND_DEPTH_BUFFER); CGraphicsContext::Get()->UpdateFrame(); CGraphicsContext::Get()->Clear(CLEAR_COLOR_AND_DEPTH_BUFFER); CGraphicsContext::Get()->UpdateFrame(); CGraphicsContext::Get()->Clear(CLEAR_COLOR_AND_DEPTH_BUFFER); CGraphicsContext::Get()->UpdateFrame(); g_CritialSection.Unlock(); status.bDisableFPS = false; status.ToToggleFullScreen = FALSE; #endif }
void StopVideo() { if( CGraphicsContext::Get()->IsWindowed() == false ) { status.ToToggleFullScreen = TRUE; CGraphicsContext::Get()->ToggleFullscreen(); status.ToToggleFullScreen = FALSE; } g_CritialSection.Lock(); status.bGameIsRunning = false; try { CloseExternalTextures(); // Kill all textures? gTextureManager.RecycleAllTextures(); gTextureManager.CleanUp(); RDP_Cleanup(); CDeviceBuilder::GetBuilder()->DeleteRender(); CGraphicsContext::Get()->CleanUp(); CDeviceBuilder::GetBuilder()->DeleteGraphicsContext(); } catch(...) { TRACE0("Some exceptions during RomClosed"); } g_CritialSection.Unlock(); windowSetting.dps = windowSetting.fps = -1; windowSetting.lastSecDlistCount = windowSetting.lastSecFrameCount = 0xFFFFFFFF; status.gDlistCount = status.gFrameCount = 0; }
static void UpdateScreenStep2 (void) { status.bVIOriginIsUpdated = false; if( status.ToToggleFullScreen && status.gDlistCount > 0 ) { ChangeWindowStep2(); return; } g_CritialSection.Lock(); if( status.bHandleN64RenderTexture ) g_pFrameBufferManager->CloseRenderTexture(true); g_pFrameBufferManager->SetAddrBeDisplayed(*g_GraphicsInfo.VI_ORIGIN_REG); if( status.gDlistCount == 0 ) { // CPU frame buffer update uint32 width = *g_GraphicsInfo.VI_WIDTH_REG; if( (*g_GraphicsInfo.VI_ORIGIN_REG & (g_dwRamSize-1) ) > width*2 && *g_GraphicsInfo.VI_H_START_REG != 0 && width != 0 ) { SetVIScales(); CRender::GetRender()->DrawFrameBuffer(true); CGraphicsContext::Get()->UpdateFrame(); } g_CritialSection.Unlock(); return; } TXTRBUF_DETAIL_DUMP(TRACE1("VI ORIG is updated to %08X", *g_GraphicsInfo.VI_ORIGIN_REG)); if( currentRomOptions.screenUpdateSetting == SCREEN_UPDATE_AT_VI_UPDATE ) { CGraphicsContext::Get()->UpdateFrame(); DEBUGGER_IF_DUMP( pauseAtNext, TRACE1("Update Screen: VIORIG=%08X", *g_GraphicsInfo.VI_ORIGIN_REG)); DEBUGGER_PAUSE_COUNT_N_WITHOUT_UPDATE(NEXT_FRAME); DEBUGGER_PAUSE_COUNT_N_WITHOUT_UPDATE(NEXT_SET_CIMG); g_CritialSection.Unlock(); return; } TXTRBUF_DETAIL_DUMP(TRACE1("VI ORIG is updated to %08X", *g_GraphicsInfo.VI_ORIGIN_REG)); if( currentRomOptions.screenUpdateSetting == SCREEN_UPDATE_AT_VI_UPDATE_AND_DRAWN ) { if( status.bScreenIsDrawn ) { CGraphicsContext::Get()->UpdateFrame(); DEBUGGER_IF_DUMP( pauseAtNext, TRACE1("Update Screen: VIORIG=%08X", *g_GraphicsInfo.VI_ORIGIN_REG)); } else { DEBUGGER_IF_DUMP( pauseAtNext, TRACE1("Skip Screen Update: VIORIG=%08X", *g_GraphicsInfo.VI_ORIGIN_REG)); } DEBUGGER_PAUSE_COUNT_N_WITHOUT_UPDATE(NEXT_FRAME); DEBUGGER_PAUSE_COUNT_N_WITHOUT_UPDATE(NEXT_SET_CIMG); g_CritialSection.Unlock(); return; } if( currentRomOptions.screenUpdateSetting==SCREEN_UPDATE_AT_VI_CHANGE ) { if( *g_GraphicsInfo.VI_ORIGIN_REG != status.curVIOriginReg ) { if( *g_GraphicsInfo.VI_ORIGIN_REG < status.curDisplayBuffer || *g_GraphicsInfo.VI_ORIGIN_REG > status.curDisplayBuffer+0x2000 ) { status.curDisplayBuffer = *g_GraphicsInfo.VI_ORIGIN_REG; status.curVIOriginReg = status.curDisplayBuffer; //status.curRenderBuffer = NULL; CGraphicsContext::Get()->UpdateFrame(); DEBUGGER_IF_DUMP( pauseAtNext, TRACE1("Update Screen: VIORIG=%08X", *g_GraphicsInfo.VI_ORIGIN_REG)); DEBUGGER_PAUSE_COUNT_N_WITHOUT_UPDATE(NEXT_FRAME); DEBUGGER_PAUSE_COUNT_N_WITHOUT_UPDATE(NEXT_SET_CIMG); } else { status.curDisplayBuffer = *g_GraphicsInfo.VI_ORIGIN_REG; status.curVIOriginReg = status.curDisplayBuffer; DEBUGGER_PAUSE_AND_DUMP_NO_UPDATE(NEXT_FRAME, {DebuggerAppendMsg("Skip Screen Update, closed to the display buffer, VIORIG=%08X", *g_GraphicsInfo.VI_ORIGIN_REG);}); } } else {
bool StartVideo(void) { #ifndef _XBOX SystemParametersInfo(SPI_GETSCREENSAVEACTIVE, 0, &windowSetting.screenSaverStatus, 0); if( windowSetting.screenSaverStatus ) SystemParametersInfo(SPI_SETSCREENSAVEACTIVE, FALSE, 0, 0); // Disable screen saver windowSetting.timer = SetTimer(g_GraphicsInfo.hWnd, 100, 1000, (TIMERPROC)TimerProc); #endif windowSetting.dps = windowSetting.fps = -1; windowSetting.lastSecDlistCount = windowSetting.lastSecFrameCount = 0xFFFFFFFF; g_CritialSection.Lock(); memcpy(&g_curRomInfo.romheader, g_GraphicsInfo.HEADER, sizeof(ROMHeader)); unsigned char *puc = (unsigned char *) &g_curRomInfo.romheader; unsigned int i; unsigned char temp; for (i = 0; i < sizeof(ROMHeader); i += 4) /* byte-swap the ROM header */ { temp = puc[i]; puc[i] = puc[i+3]; puc[i+3] = temp; temp = puc[i+1]; puc[i+1] = puc[i+2]; puc[i+2] = temp; } ROM_GetRomNameFromHeader(g_curRomInfo.szGameName, &g_curRomInfo.romheader); Ini_GetRomOptions(&g_curRomInfo); char *p = g_curRomInfo.szGameName + (lstrlen(g_curRomInfo.szGameName) -1); // -1 to skip null while (p >= g_curRomInfo.szGameName) { if( *p == ':' || *p == '\\' || *p == '/' ) *p = '-'; p--; } GenerateCurrentRomOptions(); status.dwTvSystem = CountryCodeToTVSystem(g_curRomInfo.romheader.nCountryID); if( status.dwTvSystem == TV_SYSTEM_NTSC ) status.fRatio = 0.75f; else status.fRatio = 9/11.0f;; InitExternalTextures(); try { CDeviceBuilder::GetBuilder()->CreateGraphicsContext(); CGraphicsContext::InitWindowInfo(); bool res = CGraphicsContext::Get()->Initialize(g_GraphicsInfo.hWnd, g_GraphicsInfo.hStatusBar, 640, 480, TRUE); if(!res ) { g_CritialSection.Unlock(); return false; } CDeviceBuilder::GetBuilder()->CreateRender(); CRender::GetRender()->Initialize(); DLParser_Init(); status.bGameIsRunning = true; } catch(...) { ErrorMsg("Exception caught while starting video renderer"); throw 0; } g_CritialSection.Unlock(); return true; }
void StartVideo(void) { #ifdef DEBUGON // _break(); #endif windowSetting.dps = windowSetting.fps = -1; windowSetting.lastSecDlistCount = windowSetting.lastSecFrameCount = 0xFFFFFFFF; g_CritialSection.Lock(); memcpy(&g_curRomInfo.romheader, g_GraphicsInfo.HEADER, sizeof(ROMHeader)); #ifndef _BIG_ENDIAN unsigned char *puc = (unsigned char *) &g_curRomInfo.romheader; unsigned int i; unsigned char temp; for (i = 0; i < sizeof(ROMHeader); i += 4) { temp = puc[i]; puc[i] = puc[i+3]; puc[i+3] = temp; temp = puc[i+1]; puc[i+1] = puc[i+2]; puc[i+2] = temp; } #endif //_BIG_ENDIAN ROM_GetRomNameFromHeader(g_curRomInfo.szGameName, &g_curRomInfo.romheader); Ini_GetRomOptions(&g_curRomInfo); char *p = (char *) g_curRomInfo.szGameName + (strlen((char *) g_curRomInfo.szGameName) -1); // -1 to skip null while (p >= (char *) g_curRomInfo.szGameName) { if( *p == ':' || *p == '\\' || *p == '/' ) *p = '-'; p--; } GenerateCurrentRomOptions(); status.dwTvSystem = CountryCodeToTVSystem(g_curRomInfo.romheader.nCountryID); if( status.dwTvSystem == TV_SYSTEM_NTSC ) status.fRatio = 0.75f; else status.fRatio = 9/11.0f;; InitExternalTextures(); try { #ifdef __GX__ CDeviceBuilder::SelectDeviceType(OGL_DEVICE); #endif //__GX__ #ifdef XENON CDeviceBuilder::SelectDeviceType(OGL_DEVICE); #endif CDeviceBuilder::GetBuilder()->CreateGraphicsContext(); CGraphicsContext::InitWindowInfo(); windowSetting.bDisplayFullscreen = FALSE; bool res = CGraphicsContext::Get()->Initialize(0, 0, 640, 480, TRUE); CDeviceBuilder::GetBuilder()->CreateRender(); CRender::GetRender()->Initialize(); if( res ) { DLParser_Init(); } status.bGameIsRunning = true; } catch(...) { ErrorMsg("Error to start video"); throw 0; } g_CritialSection.Unlock(); }