void GameLoop() { ProcessAsyncSaveFinish(); /* autosave game? */ if (_do_autosave) { _do_autosave = false; DoAutosave(); SetWindowDirty(WC_STATUS_BAR, 0); } /* switch game mode? */ if (_switch_mode != SM_NONE) { SwitchToMode(_switch_mode); _switch_mode = SM_NONE; } IncreaseSpriteLRU(); InteractiveRandom(); extern int _caret_timer; _caret_timer += 3; CursorTick(); #ifdef ENABLE_NETWORK /* Check for UDP stuff */ if (_network_available) NetworkUDPGameLoop(); if (_networking && !IsGeneratingWorld()) { /* Multiplayer */ NetworkGameLoop(); } else { if (_network_reconnect > 0 && --_network_reconnect == 0) { /* This means that we want to reconnect to the last host * We do this here, because it means that the network is really closed */ NetworkClientConnectGame(NetworkAddress(_settings_client.network.last_host, _settings_client.network.last_port), COMPANY_SPECTATOR); } /* Singleplayer */ StateGameLoop(); } /* Check chat messages roughly once a second. */ static uint check_message = 0; if (++check_message > 1000 / MILLISECONDS_PER_TICK) { check_message = 0; NetworkChatMessageLoop(); } #else StateGameLoop(); #endif /* ENABLE_NETWORK */ if (!_pause_mode && HasBit(_display_opt, DO_FULL_ANIMATION)) DoPaletteAnimations(); if (!_pause_mode || _game_mode == GM_EDITOR || _settings_game.construction.command_pause_level > CMDPL_NO_CONSTRUCTION) MoveAllTextEffects(); InputLoop(); _sound_driver->MainLoop(); MusicLoop(); }
/** * Really handle the abortion, i.e. clean up some of the mess */ void HandleGeneratingWorldAbortion() { /* Clean up - in SE create an empty map, otherwise, go to intro menu */ _switch_mode = (_game_mode == GM_EDITOR) ? SM_EDITOR : SM_MENU; if (_gw.abortp != NULL) _gw.abortp(); CleanupGeneration(); if (_gw.thread != NULL) _gw.thread->Exit(); SwitchToMode(_switch_mode); }
void UIDirect3D9Window::SetRefreshRate(double Rate, int ModeIndex) { if (m_timer && qFuzzyCompare(Rate + 1.0f, m_refreshRate + 1.0f)) return; m_refreshRate = Rate; if (ModeIndex > -1) SwitchToMode(ModeIndex); // NB this will also update m_refreshRate LOG(VB_GENERAL, LOG_INFO, QString("Setting display rate to %1 (interval %2us)") .arg(m_refreshRate).arg(1000000.0f / m_refreshRate)); SetFrameCount(5000.0 / m_refreshRate); if (m_timer) m_timer->SetInterval(1000000.0f / m_refreshRate); else m_timer = new UITimer(1000000.0f / m_refreshRate); }
/* * Initializes VGA for a graphical color mode. */ static void VGAInit() { // Fill in some general details of the video mode. BIT.Video.ModeInfo.Mode = MODE_640_480_16; BIT.Video.ModeInfo.PhysBasePtr = 0xA0000; BIT.Video.ModeInfo.XResolution = 640; BIT.Video.ModeInfo.YResolution = 480; // Set the bits per pixel and the number of planes for the mode. BIT.Video.ModeInfo.BitsPerPixel = 4; BIT.Video.ModeInfo.NumberOfPlanes = 4; // The bytes between lines and the bytes per scan line. BIT.Video.ModeInfo.BytesBetweenLines = 0; BIT.Video.ModeInfo.BytesPerScanLine = (640 * 4) / 8; // And the mode is supported by hardware, is a graphical mode and is VGA compatible. BIT.Video.ModeInfo.ModeAttributes = HARDWARE_INIT | GRAPHICAL_MODE | VGA_COMPATIBLE; // Go to the 320*200*256 colors mode. SwitchToMode(MODE_640_480_16, &BIT.Video.ModeInfo); }
void VideoDriver_Dedicated::MainLoop() { uint32 cur_ticks = GetTime(); uint32 next_tick = cur_ticks + MILLISECONDS_PER_TICK; /* Signal handlers */ #if defined(UNIX) || defined(PSP) signal(SIGTERM, DedicatedSignalHandler); signal(SIGINT, DedicatedSignalHandler); signal(SIGQUIT, DedicatedSignalHandler); #endif /* Load the dedicated server stuff */ _is_network_server = true; _network_dedicated = true; _current_company = _local_company = COMPANY_SPECTATOR; /* If SwitchMode is SM_LOAD_GAME, it means that the user used the '-g' options */ if (_switch_mode != SM_LOAD_GAME) { StartNewGameWithoutGUI(GENERATE_NEW_SEED); SwitchToMode(_switch_mode); _switch_mode = SM_NONE; } else { _switch_mode = SM_NONE; /* First we need to test if the savegame can be loaded, else we will end up playing the * intro game... */ if (!SafeLoad(_file_to_saveload.name, _file_to_saveload.mode, GM_NORMAL, BASE_DIR)) { /* Loading failed, pop out.. */ DEBUG(net, 0, "Loading requested map failed, aborting"); _networking = false; } else { /* We can load this game, so go ahead */ SwitchToMode(SM_LOAD_GAME); } } /* Done loading, start game! */ if (!_networking) { DEBUG(net, 0, "Dedicated server could not be started, aborting"); return; } while (!_exit_game) { uint32 prev_cur_ticks = cur_ticks; // to check for wrapping InteractiveRandom(); // randomness if (!_dedicated_forks) DedicatedHandleKeyInput(); cur_ticks = GetTime(); _realtime_tick += cur_ticks - prev_cur_ticks; if (cur_ticks >= next_tick || cur_ticks < prev_cur_ticks || _ddc_fastforward) { next_tick = cur_ticks + MILLISECONDS_PER_TICK; GameLoop(); UpdateWindows(); } /* Don't sleep when fast forwarding (for desync debugging) */ if (!_ddc_fastforward) CSleep(1); } }
/* * Initializes VBE for a graphical mode. * If something fails, automatically reverts to VGA. */ static void VBEInit() { VBECntrlrInfo_t *VBECntrlrInfo = (VBECntrlrInfo_t*)BIT.Video.VBECntrlrInfo; // If mode number is below 0x0102, then, revert. if(VBECntrlrInfo->Version < 0x0102) { OutputRevert(); return; } // Get the segment and the offset of the list of the modes. uint16_t Segment = VBECntrlrInfo->VideoModesFar & 0xFFFF0000; uint16_t Offset = VBECntrlrInfo->VideoModesFar & 0x0000FFFF; // Make flat pointer, from segment and offset = (segment * 0x10) + offset; uint16_t *VideoModesFlat = (uint16_t*) ((Segment * 0x10) + Offset); uint16_t Mode = *VideoModesFlat++; uint32_t Entries = 0; // Keep looping till we reach the End of Entries. do { // So we got one more entry. Entries++; // Get the mode into Mode, and move on to the next video mode. Mode = *VideoModesFlat++; } while(Mode != 0xFFFF); // Allocate some memory from the Base Bitmap to hold all the mode information. BIT.Video.VBEModeInfo = (uint32_t)PMMAllocContigFrames(BASE_BITMAP, ((sizeof(VBEModeInfo_t) * Entries) + 0xFFF) / 0x1000); // If we failed to allocate enough space, simply revert back. if(!BIT.Video.VBEModeInfo) { OutputRevert(); return; } // Get mode information from VBE, and the number of entries in BIT.Video.VBEModeInfoN. BIT.Video.VBEModeInfoN = VideoAPIFunc(VIDEO_VBE_GET_MODES, BIT.Video.VBEModeInfo); // Parse the VBEModeInfo[] array, and clean it out for usable modes. ParseVBEInfo(); // If no mode was defined "usable", then revert. if(!BIT.Video.VBEModeInfoN) { OutputRevert(); return; } // Parse EDID Information. if(BIT.Video.VideoFlags & EDID_PRESENT) { // Do a checksum on the EDID structure. uint8_t *EDID = (uint8_t*)&BIT.Video.EDIDInfo, Checksum = 0; for(uint32_t i = 0; i < sizeof(EDIDInfo_t); i++) { Checksum += EDID[i]; } // Only if checksum passes, use EDID information. if(!Checksum) ParseEDIDInfo(); } // Calculate the montior's preference for every mode. CalculateMonitorPreference(); // Get the best mode from VBEModeInfo[] array - and then switch to it. BIT.Video.ModeInfo = FindBestVBEMode(); // If the best mode also has score 0, then revert. if(!BIT.Video.ModeInfo.Score) { OutputRevert(); return; } // Switch to the mode. if(SwitchToMode(BIT.Video.ModeInfo.Mode, &BIT.Video.ModeInfo)) { OutputRevert(); return; } }
BOOL CATOLECRList::DetectStringLen(BSTR ID) { // переключаем устройство в режим выбора if (SwitchToMode(ID, 0, OpCode, &m_ErrorCode) == FALSE) { // не удалось выйти в режим выбора // запрашиваем код состояния BYTE mode = 0, subMode = 0, flags = 0; if (GetStateCode(ID, mode, subMode, flags, &m_ErrorCode) == FALSE) return FALSE; // если находимся в режиме регистрации if (mode == 1) { // отменяем чек InitCmd(); m_Cmd[m_Len] = 0x59; m_Len++; PassCmd(ID, m_Cmd, m_Len, m_Rsp, m_RspLen, &m_ErrorCode); if (m_ErrorCode == FALSE) return FALSE; // повторно выходим в режим выбора if (SwitchToMode(ID, 0, OpCode, &m_ErrorCode) == FALSE) return FALSE; } else return FALSE; } // получаем тип устройcтва InitCmd(); m_Cmd[m_Len] = 0xA5; m_Len++; PassCmd(m_Connections[0].m_ID, m_Cmd, m_Len, m_Rsp, m_RspLen, &m_ErrorCode); if ((m_ErrorCode != E_TIMEOUT) && (m_Rsp[0] == 0)) { // определяем модель устройства switch (m_Rsp[3]) { case 14: case 15: // Феликс Р-Ф, Феликс 02-К m_HardwareType = HW_TYPE_FELIX_R_F; m_dwMaxStringLen = 20; m_dwStringLen = 20; m_dwTapeWidth = 120 - 5; m_dwBarcodeWidth = 1; m_CutterSupported = FALSE; break; case 20: case 23: // Торнадо, Меркурий m_HardwareType = HW_TYPE_MERCURY_114_1; m_dwMaxStringLen = 48; m_dwStringLen = 39; m_dwTapeWidth = 464 - 33; m_dwBarcodeWidth = 3; m_CutterSupported = TRUE; break; case 24: // Феликс Р-К m_HardwareType = HW_TYPE_FELIX_R_K; m_dwMaxStringLen = 38; m_dwStringLen = 32; m_dwTapeWidth = 320 - 40; m_dwBarcodeWidth = 2; m_CutterSupported = FALSE; break; case 31: // FPrint-03K m_HardwareType = HW_TYPE_FRPINT_03K; m_dwMaxStringLen = 32; m_dwStringLen = 32; m_dwTapeWidth = 320 - 40; m_dwBarcodeWidth = 2; m_CutterSupported = FALSE; break; case 30: // FPrint-02K m_HardwareType = HW_TYPE_FRPINT_02K; m_dwMaxStringLen = 56; m_dwStringLen = 40; m_dwTapeWidth = 200; m_dwBarcodeWidth = 1; m_CutterSupported = TRUE; break; case 32: // FPrint-88K m_HardwareType = HW_TYPE_FRPINT_88K; m_dwMaxStringLen = 56; m_dwStringLen = 42; m_dwTapeWidth = 340; m_dwBarcodeWidth = 2; m_CutterSupported = TRUE; break; case 47: // FPrint-55K case 35: // FPrint-5200K m_HardwareType = HW_TYPE_FRPINT_5200K; m_dwMaxStringLen = 36; m_dwStringLen = 36; m_dwTapeWidth = 360 - 40; m_dwBarcodeWidth = 2; m_CutterSupported = TRUE; break; case 52: // FPrint-22K m_HardwareType = HW_TYPE_FRPINT_22K; m_dwMaxStringLen = 48; m_dwStringLen = 48; m_dwTapeWidth = 390; m_dwBarcodeWidth = 2; m_CutterSupported = TRUE; break; case 53: // FPrint-77ПТК m_HardwareType = HW_TYPE_FRPINT_77PTK; m_dwMaxStringLen = 57; m_dwStringLen = 48; m_dwTapeWidth = 390; m_dwBarcodeWidth = 2; m_CutterSupported = TRUE; break; } return TRUE; } else return FALSE; }