static void Idle2(void) { int mask; int b, i; int index; for (index = 0; index < GFCTRL_JOY_NUMBER; index++) { if (Joystick[index]) { Joystick[index]->read(&b, &JoyAxis[index * GFCTRL_JOY_MAX_AXES]); /* Joystick buttons */ for (i = 0, mask = 1; i < 32; i++, mask *= 2) { if (((b & mask) != 0) && ((JoyButtons[index] & mask) == 0)) { /* Check whether to ignore */ if(Cmd[CalState + CmdOffset].butIgnore == i + 32 * index) break; /* Button fired */ JoyCalAutomaton(); if (CalState >= NbCalSteps) { GfuiApp().eventLoop().setRecomputeCB(0); } GfuiApp().eventLoop().postRedisplay(); JoyButtons[index] = b; return; } } JoyButtons[index] = b; } } /* Let CPU take breath (and fans stay at low and quite speed) */ GfSleep(0.001); }
static void ClientIdle(void) { GfuiIdle(); if (NetIsClient()) { if (!NetGetClient()->TimeSynced()) { NetGetClient()->SendServerTimeRequest(); } if (NetGetClient()->GetRefreshDisplay()) { //Update the screen UpdateNetworkPlayers(); GfuiApp().eventLoop().postRedisplay(); } if (NetGetClient()->PrepareToRace()) { NetGetClient()->SetLocalDrivers(); LmRaceEngine().startNewRace(); } if (!NetGetClient()->IsConnected()) { rmNetworkClientDisconnect(NULL); } GfuiApp().eventLoop().postRedisplay(); } /* Let CPU take breath (and fans stay at low and quiet speed) */ GfSleep(0.001); }
static void MouseCalAutomaton(void) { float axv; switch (CalState) { case 0: case 1: GfctrlMouseGetCurrentState(&MouseInfo); axv = MouseInfo.ax[Cmd[CmdOffset + CalState].ref.index]; if (fabs(axv) < 0.01) { return; /* ignore no move input */ } Cmd[CmdOffset + CalState].max = axv; Cmd[CmdOffset + CalState].pow = 1.0 / axv; break; case 2: case 3: GfctrlMouseGetCurrentState(&MouseInfo); axv = MouseInfo.ax[Cmd[CmdOffset + CalState].ref.index]; if (fabs(axv) < 0.01) { return; /* ignore no move input */ } Cmd[CmdOffset + CalState].max = axv; Cmd[CmdOffset + CalState].pow = 1.0 / axv; break; } CalState++; CalState = GetNextAxis(); GfuiLabelSetText(ScrHandle, InstId, Instructions[CalState]); if (CalState < 4) { GfuiApp().eventLoop().setRecomputeCB(Idle2); } else { GfuiApp().eventLoop().setRecomputeCB(0); GfuiApp().eventLoop().postRedisplay(); } /* Change button appearance when done */ if (CalState == 4) { GfuiEnable(ScrHandle, CancelBut, GFUI_DISABLE); if (DoneBut) GfuiEnable(ScrHandle, DoneBut, GFUI_ENABLE); else GfuiEnable(ScrHandle, NextBut, GFUI_ENABLE); } }
static void onActivate(void * /* dummy */) { int i; int index; int step; // Create and test joysticks ; only keep the up and running ones. for (index = 0; index < GFCTRL_JOY_NUMBER; index++) { Joystick[index] = new jsJoystick(index); if (Joystick[index]->notWorking()) { /* don't configure the joystick */ delete Joystick[index]; Joystick[index] = 0; } } CalState = 0; GfuiLabelSetText(ScrHandle, InstId, Instructions[CalState]); GfuiApp().eventLoop().setRecomputeCB(Idle2); GfuiApp().eventLoop().postRedisplay(); for (index = 0; index < GFCTRL_JOY_NUMBER; index++) { if (Joystick[index]) { Joystick[index]->read(&JoyButtons[index], &JoyAxis[index * GFCTRL_JOY_MAX_AXES]); /* initial value */ } } for (i = 0; i < NbMaxCalAxis; i++) { if (i > 0) { step = i + 2; } else { step = i + 1; } if (Cmd[step + CmdOffset].ref.type == GFCTRL_TYPE_JOY_AXIS) { GfuiLabelSetText(ScrHandle, LabAxisId[i], GfctrlGetNameByRef(GFCTRL_TYPE_JOY_AXIS, Cmd[step + CmdOffset].ref.index)); } else { GfuiLabelSetText(ScrHandle, LabAxisId[i], "---"); } GfuiLabelSetText(ScrHandle, LabMinId[i], ""); GfuiLabelSetText(ScrHandle, LabMaxId[i], ""); } GfuiEnable(ScrHandle, CancelBut, GFUI_ENABLE); if (DoneBut) GfuiEnable(ScrHandle, DoneBut, GFUI_DISABLE); else GfuiEnable(ScrHandle, NextBut, GFUI_DISABLE); }
static void onActivate(void * /* dummy */) { int i; int index; // Create and test joysticks ; only keep the up and running ones. for (index = 0; index < GFCTRL_JOY_NUMBER; index++) { Joystick[index] = new jsJoystick(index); if (Joystick[index]->notWorking()) { /* don't configure the joystick */ delete Joystick[index]; Joystick[index] = 0; } } CalState = 0; AtobAxis = GFCTRL_JOY_NUMBER * GFCTRL_JOY_MAX_AXES;; /* Find commands which are ATOB */ for (i = 0; i <= CMD_END_OF_LIST; i++) { if (Cmd[i].ref.type == GFCTRL_TYPE_JOY_ATOB) { if (AtobAxis > Cmd[i].ref.index) AtobAxis = Cmd[i].ref.index; } } for (AtobCount = 0; AtobCount <= CMD_END_OF_LIST; AtobCount++) { if (Cmd[AtobCount].ref.index == AtobAxis) break; } /* Set label titles */ GfuiLabelSetText(ScrHandle, AtobAxisID, GfctrlGetNameByRef(GFCTRL_TYPE_JOY_ATOB, AtobAxis)); GfuiLabelSetText(ScrHandle, AtobCommandID, "---"); GfuiLabelSetText(ScrHandle, InstId, Instructions[CalState]); GfuiApp().eventLoop().setRecomputeCB(Idle2); GfuiApp().eventLoop().postRedisplay(); for (index = 0; index < GFCTRL_JOY_NUMBER; index++) { if (Joystick[index]) { Joystick[index]->read(&JoyButtons[index], &JoyAxis[index * GFCTRL_JOY_MAX_AXES]); /* initial value */ } } GfuiEnable(ScrHandle, CancelBut, GFUI_ENABLE); if (DoneBut) GfuiEnable(ScrHandle, DoneBut, GFUI_DISABLE); else GfuiEnable(ScrHandle, NextBut, GFUI_DISABLE); }
static void HostServerIdle(void) { GfuiIdle(); if (NetIsServer()) { if (NetGetServer()->GetRaceInfoChanged()) { CheckDriversCategory(); //Send to clients all of the xml files we modified and client needs to reload NetGetServer()->SendFilePacket("drivers/networkhuman/networkhuman.xml"); NetGetServer()->SendFilePacket("config/raceman/networkrace.xml"); NetGetServer()->SendRaceSetupPacket(); NetGetServer()->SendDriversReadyPacket(); NetGetServer()->SetRaceInfoChanged(false); } else { if (NetGetServer()->GetRefreshDisplay()) { UpdateNetworkPlayers(); } } GfuiApp().eventLoop().postRedisplay(); } /* Let CPU take breath (and fans stay at low and quiet speed) */ GfSleep(0.001); }
// Save the choosen values in the corresponding parameter file. static void saveSoundOption(void *) { // Force current edit to loose focus (if one has it) and update associated variable. GfuiUnSelectCurrent(); char buf[1024]; sprintf(buf, "%s%s", GfLocalDir(), SND_PARAM_FILE); void *paramHandle = GfParmReadFile(buf, GFPARM_RMODE_REREAD | GFPARM_RMODE_CREAT); GfParmSetStr(paramHandle, SND_SCT_SOUND, SND_ATT_SOUND_STATE, soundOptionList[curOption]); GfParmSetNum(paramHandle, SND_SCT_SOUND, SND_ATT_SOUND_VOLUME, "%", VolumeValue); GfParmSetStr(paramHandle, SND_SCT_MUSIC, SND_ATT_MUSIC_STATE, musicStateList[curMusicState]); GfParmSetNum(paramHandle, SND_SCT_MUSIC, SND_ATT_MUSIC_VOLUME, "%", MusicVolumeValue); GfParmWriteFile(NULL, paramHandle, "sound"); GfParmReleaseHandle(paramHandle); // Shutdown the user interface. LegacyMenu::self().shutdown(); // Restart the game. GfuiApp().restart(); // Return to previous screen. GfuiScreenActivate(prevHandle); }
static void rmScreenActivate(void * /* dummy */) { // Configure the FPS limiter if active. #ifdef UseFPSLimiter // Get the max. refresh rate from the screen config params file. std::ostringstream ossConfFile; ossConfFile << GfLocalDir() << GFSCR_CONF_FILE; void* hparmScrConf = GfParmReadFile(ossConfFile.str().c_str(), GFPARM_RMODE_STD); FPSLimLastTime = 0.0; FPSLimMaxRate = GfParmGetNum(hparmScrConf, GFSCR_SECT_VALIDPROPS, GFSCR_ATT_MAXREFRESH, NULL, 0.0); if (FPSLimMaxRate) GfLogInfo("FPS limiter is on (%.1f Hz).\n", FPSLimMaxRate); else GfLogInfo("FPS limiter is off.\n"); GfParmReleaseHandle(hparmScrConf); #endif // Configure the event loop. GfuiApp().eventLoop().setRecomputeCB(rmUpdateRaceEngine); GfuiApp().eventLoop().setRedisplayCB(rmRedisplay); // If not paused ... #ifdef STARTPAUSED if ((!rmRacePaused)&&(!rmPreRacePause)) #else if (!rmRacePaused) #endif { // Reset normal sound volume. if (LegacyMenu::self().soundEngine()) LegacyMenu::self().soundEngine()->mute(false); // Resynchronize the race engine. LmRaceEngine().start(); } // Request a redisplay for the next event loop. GfuiApp().eventLoop().postRedisplay(); // The menu changed. rmbMenuChanged = true; }
static void IdleMouseInit(void) { /* Get the center mouse position */ memset(&MouseInfo, 0, sizeof(MouseInfo)); GfctrlMouseGetCurrentState(&MouseInfo); GfctrlMouseInitCenter(); GfuiApp().eventLoop().setRecomputeCB(Idle2); }
static void rmResScreenActivate(void * /* dummy */) { GfLogInfo("Entering Result menu ...\n"); // Configure the event loop. GfuiApp().eventLoop().setRecomputeCB(rmUpdateRaceEngine); GfuiApp().eventLoop().setRedisplayCB(rmResRedisplay); // Resynchronize the race engine. LmRaceEngine().start(); // Request a redisplay for the next event loop. GfuiApp().eventLoop().postRedisplay(); // The menu changed. rmbResMenuChanged = true; }
static void ServerPrepareStartNetworkRace(void * /* dummy */) { NetGetServer()->SetLocalDrivers(); //Tell all clients to prepare to race and wait for response from all clients NetGetServer()->SendPrepareToRacePacket(); //restore the idle function GfuiApp().eventLoop().setRecomputeCB(GfuiIdle); LmRaceEngine().startNewRace(); }
static void rmResRedisplay() { // Redraw the menu part of the GUI if necessary. if (rmbResMenuChanged) GfuiRedraw(); // Really do the display work. if (rmbResMenuChanged) GfuiSwapBuffers(); // The menu changes has now been taken into account. rmbResMenuChanged = false; // Request an redisplay in the next event loop. GfuiApp().eventLoop().postRedisplay(); }
static void onActivate(void * /* dummy */) { CalState = 0; GetNextAxis(); GfuiLabelSetText(ScrHandle, InstId, Instructions[CalState]); if (CalState < 4) { GfuiApp().eventLoop().setRecomputeCB(IdleMouseInit); GfctrlMouseCenter(); } GfuiEnable(ScrHandle, CancelBut, GFUI_ENABLE); if (DoneBut) GfuiEnable(ScrHandle, DoneBut, GFUI_DISABLE); else GfuiEnable(ScrHandle, NextBut, GFUI_DISABLE); }
static void onAccept(void *) { // Store current state of settings to the GL features layer. GfglFeatures::self().select(GfglFeatures::TextureCompression, strcmp(ATextureCompTexts[NCurTextureCompIndex], GFSCR_ATT_TEXTURECOMPRESSION_ENABLED) ? false : true); GfglFeatures::self().select(GfglFeatures::TextureMaxSize, AMaxTextureSizeTexts[NCurMaxTextureSizeIndex]); GfglFeatures::self().select(GfglFeatures::MultiTexturing, strcmp(AMultiTextureTexts[NCurMultiTextureIndex], GFSCR_ATT_MULTITEXTURING_ENABLED) ? false : true); GfglFeatures::self().select(GfglFeatures::MultiSampling, VecMultiSampleTexts[NCurMultiSampleIndex] != GFSCR_ATT_MULTISAMPLING_DISABLED); if (VecMultiSampleTexts[NCurMultiSampleIndex] != GFSCR_ATT_MULTISAMPLING_DISABLED) GfglFeatures::self().select(GfglFeatures::MultiSamplingSamples, (int)pow(2.0, (double)NCurMultiSampleIndex)); GfglFeatures::self().select(GfglFeatures::BumpMapping, strcmp(ABumpMappingTexts[NCurBumpMappingIndex], GFSCR_ATT_BUMPMAPPING_ENABLED) ? false : true); GfglFeatures::self().select(GfglFeatures::AnisotropicFiltering, NCurAnisotropicFilteringIndex); // Store settings from the GL features layer to the screen.xml file. GfglFeatures::self().storeSelection(); // Return to previous screen. GfuiScreenActivate(PrevHandle); // But actually restart the game if the multi-sampling feature settings changed // (we can't change this without re-initializing the video mode). if (GfglFeatures::self().isSelected(GfglFeatures::MultiSampling) != BMultiSamplingWasSelected || GfglFeatures::self().getSelected(GfglFeatures::MultiSamplingSamples) != BPrevMultiSamplingSamples) { // Shutdown the user interface. LegacyMenu::self().shutdown(); // Restart the game. GfuiApp().restart(); } }
static void ShowWaitingToConnectScreen() { GfLogTrace("Entering Network Wait Connection menu.\n"); if (racemanMenuHdle) GfuiScreenRelease(racemanMenuHdle); racemanMenuHdle = GfuiScreenCreate(NULL, NULL, (tfuiCallback) NULL, NULL, (tfuiCallback)NULL, 1); void *mparam = GfuiMenuLoad("networkwaitconnectmenu.xml"); GfuiMenuCreateStaticControls(racemanMenuHdle, mparam); GfuiMenuDefaultKeysAdd(racemanMenuHdle); GfuiScreenActivate(racemanMenuHdle); GfuiApp().eventLoop().postRedisplay(); }
static void OnActivateNetworkHost(void *) { tRmInfo* reInfo = LmRaceEngine().inData(); // Set everyone to the 'not-ready' state bRobotsReady = 0; NetMutexData *pNData = NetGetNetwork()->LockNetworkData(); for (unsigned int i=0;i<pNData->m_vecReadyStatus.size();i++) pNData->m_vecReadyStatus[i] = false; NetGetNetwork()->UnlockNetworkData(); NetGetServer()->SetRaceInfoChanged(true); reInfo->params = GfParmReadFileLocal("config/raceman/networkrace.xml",GFPARM_RMODE_REREAD); assert(reInfo->params); reInfo->_reName = GfParmGetStr(reInfo->params, RM_SECT_HEADER, RM_ATTR_NAME, ""); GfuiApp().eventLoop().setRecomputeCB(HostServerIdle); NetGetServer()->SetRefreshDisplay(true); }
static void OnActivateNetworkClient(void *) { int nDriverIdx = NetGetNetwork()->GetDriverIdx(); if(NetGetNetwork()->IsConnected() && nDriverIdx > -1) { // Menu reactivated after garage menu is done NetDriver driver; char newName[64]; char dname[256]; // check for car change if (bGarage == true ) { bGarage = false; tRmInfo* reInfo = LmRaceEngine().inData(); reInfo->params = GfParmReadFileLocal("config/raceman/networkrace.xml",GFPARM_RMODE_REREAD); reInfo->_reName = GfParmGetStr(reInfo->params, RM_SECT_HEADER, RM_ATTR_NAME, ""); sprintf(dname, "%s/%d", RM_SECT_DRIVERS, nDriverIdx); int idx = GfParmGetNum(reInfo->params, dname, RM_ATTR_IDX, "",0); GfDriver* PCurrentDriver = GfDrivers::self()->getDriver(NETWORKROBOT, idx); strncpy(newName, PCurrentDriver->getCar()->getId().c_str(), sizeof(newName)); GfLogInfo("Client: Index %d changed to %s\n", idx, newName); NetGetNetwork()->SetCarInfo(newName); } else { // Ensure menu system knows about all cars GfDrivers::self()->reload(); // tRmInfo* reInfo = LmRaceEngine().inData(); // Never used LmRaceEngine().race()->load(LmRaceEngine().race()->getManager(), true); } } GfuiApp().eventLoop().setRecomputeCB(ClientIdle); bGarage = false; }
static void Idle2(void) { int index; #if SDL_JOYSTICK /* Check for activity on Joystick buttons */ GfctrlJoyGetCurrentStates(&joyInfo); for (index = 0; index < GFCTRL_JOY_NUMBER * GFCTRL_JOY_MAX_BUTTONS; index++) { if (joyInfo.edgedn[index]) { /* Check whether to ignore */ if(Cmd[CalState + CmdOffset].butIgnore == index) break; /* Button fired */ JoyCalAutomaton(); if (CalState >= NbCalSteps) { GfuiApp().eventLoop().setRecomputeCB(0); } GfuiApp().eventLoop().postRedisplay(); return; } #else int mask; int b, i; for (index = 0; index < GFCTRL_JOY_NUMBER; index++) { if (Joystick[index]) { Joystick[index]->read(&b, &JoyAxis[index * GFCTRL_JOY_MAX_AXES]); /* Joystick buttons */ for (i = 0, mask = 1; i < 32; i++, mask *= 2) { if (((b & mask) != 0) && ((JoyButtons[index] & mask) == 0)) { /* Check whether to ignore */ if(Cmd[CalState + CmdOffset].butIgnore == i + 32 * index) break; /* Button fired */ JoyCalAutomaton(); if (CalState >= NbCalSteps) { GfuiApp().eventLoop().setRecomputeCB(0); } GfuiApp().eventLoop().postRedisplay(); JoyButtons[index] = b; return; } } JoyButtons[index] = b; } #endif } /* Let CPU take breath (and fans stay at low and quite speed) */ GfSleep(0.001); } static void onActivate(void * /* dummy */) { int i; int step; #if SDL_JOYSTICK //joyInfo = GfctrlJoyCreate(); GfctrlJoyGetCurrentStates(&joyInfo); #else int index; // Create and test joysticks ; only keep the up and running ones. for (index = 0; index < GFCTRL_JOY_NUMBER; index++) { Joystick[index] = new jsJoystick(index); if (Joystick[index]->notWorking()) { /* don't configure the joystick */ delete Joystick[index]; Joystick[index] = 0; } } #endif CalState = 0; GfuiLabelSetText(ScrHandle, InstId, Instructions[CalState]); GfuiApp().eventLoop().setRecomputeCB(Idle2); GfuiApp().eventLoop().postRedisplay(); #ifndef SDL_JOYSTICK for (index = 0; index < GFCTRL_JOY_NUMBER; index++) { if (Joystick[index]) { Joystick[index]->read(&JoyButtons[index], &JoyAxis[index * GFCTRL_JOY_MAX_AXES]); /* initial value */ } } #endif for (i = 0; i < NbMaxCalAxis; i++) { if (i > 0) { step = i + 2; } else { step = i + 1; } if (Cmd[step + CmdOffset].ref.type == GFCTRL_TYPE_JOY_AXIS) { GfuiLabelSetText(ScrHandle, LabAxisId[i], GfctrlGetNameByRef(GFCTRL_TYPE_JOY_AXIS, Cmd[step + CmdOffset].ref.index)); } else { GfuiLabelSetText(ScrHandle, LabAxisId[i], "---"); } GfuiLabelSetText(ScrHandle, LabMinId[i], ""); GfuiLabelSetText(ScrHandle, LabMaxId[i], ""); } GfuiEnable(ScrHandle, CancelBut, GFUI_ENABLE); if (DoneBut) GfuiEnable(ScrHandle, DoneBut, GFUI_DISABLE); else GfuiEnable(ScrHandle, NextBut, GFUI_DISABLE); }
void LegacyMenu::quit() { // Quit the event loop next time. GfuiApp().eventLoop().postQuit(); }
static void rmRedisplay() { // Process any pending (human) pit request. const bool bPitRequested = RmCheckPitRequest(); #ifdef UseFPSLimiter // Auto FPS limitation if specified and if not capturing frames. if (FPSLimMaxRate > 0 && !rmMovieCapture.active) { // If too early to refresh graphics, do nothing more than wait a little. const double dCurrentTime = GfTimeClock(); if (dCurrentTime < FPSLimLastTime + 1.0 / FPSLimMaxRate) { // Wait a little, to let the CPU take breath. // Note : Theorical resolution is 1ms, but actual one is from far more // (10-15ms under Windows, even worse under Linux ?) // which explains a lower than expected actual FPS mean. GfSleep(0.001); // Only giving back control to the scheduler gives good results // as for the actual mean FPS, but keeps the CPU 100 % (not very cool). //GfSleep(0.0); // Request an update in the next event loop though. GfuiApp().eventLoop().postRedisplay(); return; } // Otherwise, last update time is now : go on with graphics update. FPSLimLastTime = dCurrentTime; } #endif // Exec the "slow resume race" manager, if needed. #ifdef STARTPAUSED if (!rmPreRacePause) { rmProgressiveTimeModifier.execute(); } #else rmProgressiveTimeModifier.execute(); #endif // Redraw the graphics part of the GUI if requested. const bool bUpdateGraphics = LmRaceEngine().outData()->_displayMode == RM_DISP_MODE_NORMAL && !bPitRequested && LegacyMenu::self().graphicsEngine(); if (bUpdateGraphics) { //GfSchedBeginEvent("raceupdate", "graphics"); LegacyMenu::self().redrawGraphicsView(LmRaceEngine().outData()->s); //GfSchedEndEvent("raceupdate", "graphics"); } // Synchronize the menu with the race messages if any changed. rmUpdateRaceMessages(); // Redraw the menu part of the GUI // (always necessary if the graphics were redrawn first). if (bUpdateGraphics || rmbMenuChanged) GfuiRedraw(); // Really do the display work. if (bUpdateGraphics || rmbMenuChanged) GfuiSwapBuffers(); // The menu changes has now been taken into account. rmbMenuChanged = false; //只要改成任何时候都输出每一帧的RGB信息到PNG,即可输出PNG格式的图片 Add by gaoyu 2015-7-15 // Capture the newly displayed frame if movie capture mode. if (rmMovieCapture.active) rmCaptureScreen();//会自动获取屏幕像素,并保存为png文件 Add by gaoyu 2015-7-15 //rmCaptureScreen(); // Request an redisplay in the next event loop. GfuiApp().eventLoop().postRedisplay(); }
void RmNetworkClientMenu(void * /* dummy */) { GfLogTrace("Entering Network Client menu.\n"); ShowWaitingToConnectScreen(); if (!NetGetClient()) { NetSetServer(false); NetSetClient(true); NetDriver driver; GetHumanDriver(driver,1); driver.client = true; driver.active = true; strcpy(driver.name,g_strDriver.c_str()); if (!NetGetClient()->ConnectToServer((char*)g_strHostIP.c_str(),SPEEDDREAMSPORT,&driver)) { //failed so back to connect menu NetworkClientConnectMenu(NULL); return; } //NetGetClient()->SendDriverInfoPacket(&driver); } if (racemanMenuHdle) GfuiScreenRelease(racemanMenuHdle); racemanMenuHdle = GfuiScreenCreate(NULL, NULL, (tfuiCallback)OnActivateNetworkClient, NULL, (tfuiCallback)NULL, 1); void *mparam = GfuiMenuLoad("networkclientmenu.xml"); GfuiMenuCreateStaticControls(racemanMenuHdle, mparam); GfuiMenuDefaultKeysAdd(racemanMenuHdle); RmSetRacemanMenuHandle(racemanMenuHdle); g_trackHd = GfuiMenuCreateLabelControl(racemanMenuHdle,mparam,"trackname"); g_lapsHd = GfuiMenuCreateLabelControl(racemanMenuHdle,mparam,"lapcountname"); g_catHd = GfuiMenuCreateLabelControl(racemanMenuHdle,mparam,"carcatname"); g_OutlineId = GfuiMenuCreateStaticImageControl(racemanMenuHdle,mparam,"outlineimage"); //Show players for (int i = 0; i < MAXNETWORKPLAYERS; i++) { char buf[1024]; sprintf(buf,"ready%i",i); g_readystatus[i] = GfuiMenuCreateStaticImageControl(racemanMenuHdle,mparam,buf); GfuiVisibilitySet(racemanMenuHdle,g_readystatus[i],false); sprintf(buf,"driver%i",i); g_playerNames[i] = GfuiMenuCreateLabelControl(racemanMenuHdle,mparam,buf); GfuiLabelSetText(racemanMenuHdle,g_playerNames[i],""); sprintf(buf,"car%i",i); g_carNames[i] = GfuiMenuCreateLabelControl(racemanMenuHdle,mparam,buf); GfuiLabelSetText(racemanMenuHdle,g_carNames[i],""); } g_ReadyCheckboxId = GfuiMenuCreateCheckboxControl(racemanMenuHdle, mparam, "playerreadycheckbox", NULL, onClientPlayerReady); g_CarSetupButtonId = GfuiMenuCreateButtonControl(racemanMenuHdle, mparam, "garage", racemanMenuHdle, rmCarSettingsMenu); g_DisconnectButtonId = GfuiMenuCreateButtonControl(racemanMenuHdle, mparam, "disconnect", NULL,rmNetworkClientDisconnect); GfParmReleaseHandle(mparam); UpdateNetworkPlayers(); GfuiScreenActivate(racemanMenuHdle); GfuiApp().eventLoop().setRecomputeCB(ClientIdle); }
bool GfglFeatures::checkBestSupport(int nWidth, int nHeight, int nDepth, bool bAlpha, bool bFullScreen, bool bBump, bool bStereo,int nAniFilt, void* hparmConfig) { // Open the config file if not already done. void* hparm = hparmConfig ? hparmConfig : openConfigFile(); // Get the frame buffer specs that are associated with the detected // Open GL features in the config file, if any. int nDetWidth, nDetHeight, nDetDepth, nDetAni; bool bDetFullScreen, bDetAlpha, bDetBump, bDetStereo; bool bPrevSupportFound = loadSupport(nDetWidth, nDetHeight, nDetDepth, bDetAlpha, bDetFullScreen, bDetBump, bDetStereo,nDetAni, hparm); // Compare with the requested frame buffer specs // and run a new supported feature detection if any diffference. bool bSupportFound = true; if (!bPrevSupportFound || nWidth != nDetWidth || nHeight != nDetHeight || nDepth != nDetDepth || bAlpha != bDetAlpha || bFullScreen != bDetFullScreen || bStereo != bDetStereo || bBump != bDetBump || nAniFilt!= nDetAni) { nDetWidth = nWidth; nDetHeight = nHeight; nDetDepth = nDepth; bDetFullScreen = bFullScreen; bDetAlpha = bAlpha; bDetStereo = bStereo; bDetBump = bBump; nDetAni = nAniFilt; bSupportFound = detectBestSupport(nDetWidth, nDetHeight, nDetDepth, bDetAlpha, bDetFullScreen, bDetBump, bDetStereo, nDetAni); // Store support data in any case. storeSupport(nDetWidth, nDetHeight, nDetDepth, bDetAlpha, bDetFullScreen, bDetBump, bDetStereo,nDetAni, hparm); // If frame buffer specs supported, update relevant user settings and restart. if (bSupportFound) { // Write new user settings about the frame buffer specs // (the detection process might have down-casted them ...). // Note: Sure the specs are in the 'in-test' state here, // otherwise they would not have changed. GfParmSetNum(hparm, GFSCR_SECT_INTESTPROPS, GFSCR_ATT_WIN_X, pszNoUnit, (tdble)nDetWidth); GfParmSetNum(hparm, GFSCR_SECT_INTESTPROPS, GFSCR_ATT_WIN_Y, pszNoUnit, (tdble)nDetHeight); GfParmSetNum(hparm, GFSCR_SECT_INTESTPROPS, GFSCR_ATT_BPP, pszNoUnit, (tdble)nDetDepth); GfParmSetStr(hparm, GFSCR_SECT_INTESTPROPS, GFSCR_ATT_ALPHACHANNEL, bDetAlpha ? GFSCR_VAL_YES : GFSCR_VAL_NO); GfParmSetStr(hparm, GFSCR_SECT_INTESTPROPS, GFSCR_ATT_FSCR, bDetFullScreen ? GFSCR_VAL_YES : GFSCR_VAL_NO); // But make sure they are not validated yet at restart (only next time if OK). GfParmSetStr(hparm, GFSCR_SECT_INTESTPROPS, GFSCR_ATT_TESTSTATE, GFSCR_VAL_TODO); // Write new params to config file. GfParmWriteFile(NULL, hparm, "Screen"); // Close the config file ... closeConfigFile(hparm); // ... as we are restarting ... GfuiApp().restart(); // Next time we pass in this function, loadSupport() will give // the right values for all features ... } } if (!hparmConfig) closeConfigFile(hparm); return bSupportFound; }
/** Generate a help screen. @ingroup gui @param targetScreen The screen to display help for @param returnScreen The screen to return to when exiting @warning The help screen is activated. */ void GfuiHelpScreen(void *targetScreen, void *returnScreen) { // The return screen is the target screen if not specified (0). if (!returnScreen) returnScreen = targetScreen; // Create help screen, load menu XML descriptor and create static controls. void* scrHandle = GfuiScreenCreate(0, 0, onActivate, 0, onDeactivate); void *hmenu = GfuiMenuLoad("helpmenu.xml"); GfuiMenuCreateStaticControls(scrHandle, hmenu); // Get menu properties. const int nXLeftColumn = (int)GfuiMenuGetNumProperty(hmenu, "xLeftColumn", 30); const int nXRightColumn = (int)GfuiMenuGetNumProperty(hmenu, "xRightColumn", 330); const int nNameFieldWidth = (int)GfuiMenuGetNumProperty(hmenu, "nameFieldWidth", 80); const int nLineShift = (int)GfuiMenuGetNumProperty(hmenu, "lineShift", 12); const int nYTopLine = (int)GfuiMenuGetNumProperty(hmenu, "yTopLine", 380); // Create 2 columns table for the keyboard shortcuts explanations int ys = nYTopLine; int yn = nYTopLine; tGfuiScreen *pscrTgt = (tGfuiScreen*)targetScreen; tGfuiKey *curKey = pscrTgt->userKeys; while (curKey) { curKey = curKey->next; // Decide if this key goes on the left of right column. bool bLeft; switch(curKey->key) { case GFUIK_BACKSPACE: case GFUIK_F1: case GFUIK_F2: case GFUIK_F3: case GFUIK_F4: case GFUIK_F5: case GFUIK_F6: case GFUIK_F7: case GFUIK_F8: case GFUIK_F9: case GFUIK_F10: case GFUIK_F11: case GFUIK_F12: case GFUIK_LEFT: case GFUIK_UP: case GFUIK_RIGHT: case GFUIK_DOWN: case GFUIK_PAGEUP: case GFUIK_PAGEDOWN: case GFUIK_HOME: case GFUIK_END: case GFUIK_INSERT: case GFUIK_DELETE: case GFUIK_CLEAR: case GFUIK_PAUSE: bLeft = true; break; default: bLeft = curKey->modifier != GFUIM_NONE; break; } // Determine control coordinates, whether left or right column. int x, y; if (bLeft) { x = nXLeftColumn; y = ys; ys -= nLineShift; } else { x = nXRightColumn; y = yn; yn -= nLineShift; } // Create label controls. GfuiMenuCreateLabelControl(scrHandle, hmenu, "keyName", true, // from template curKey->name, x, y); GfuiMenuCreateLabelControl(scrHandle, hmenu, "keyDesc", true, // from template curKey->descr, x + nNameFieldWidth, y); // Stop if no more keys to explain. if (curKey == pscrTgt->userKeys) curKey = (tGfuiKey*)NULL; } // Create Back button. GfuiMenuCreateButtonControl(scrHandle, hmenu, "backbutton", targetScreen, GfuiScreenReplace); // Create version label. const int versionId = GfuiMenuCreateLabelControl(scrHandle, hmenu, "versionlabel"); GfuiLabelSetText(scrHandle, versionId, GfuiApp().version().c_str()); // Close menu XML descriptor. GfParmReleaseHandle(hmenu); // Add keyboard shortcuts. GfuiAddKey(scrHandle, GFUIK_ESCAPE, "Back to the menu", returnScreen, GfuiScreenReplace, NULL); GfuiAddKey(scrHandle, GFUIK_RETURN, "Back to the menu", returnScreen, GfuiScreenReplace, NULL); if (NRecursions == 0) GfuiAddKey(scrHandle, GFUIK_F1, "Help on Help menu", scrHandle, GfuiHelpScreen, NULL); GfuiAddKey(scrHandle, GFUIK_F12, "Screen-shot", NULL, GfuiScreenShot, NULL); GfuiAddKey(scrHandle, GFUIK_UP, "Select previous entry", NULL, gfuiSelectPrev, NULL); GfuiAddKey(scrHandle, GFUIK_DOWN, "Select next entry", NULL, gfuiSelectNext, NULL); GfuiScreenActivate(scrHandle); }
static void UpdateNetworkPlayers() { GfDriver* newDriver; NetNetwork *pNetwork = NetGetNetwork(); if (pNetwork->GetRefreshDisplay() == false) return; tRmInfo* reInfo = LmRaceEngine().inData(); //Set current driver that camera will look at pNetwork->SetCurrentDriver(); //reload xml file NetGetNetwork()->SetRaceXMLFile("config/raceman/networkrace.xml"); reInfo->params = GfParmReadFileLocal("config/raceman/networkrace.xml",GFPARM_RMODE_REREAD); assert(reInfo->params); reInfo->_reName = GfParmGetStr(reInfo->params, RM_SECT_HEADER, RM_ATTR_NAME, ""); assert(reInfo->_reName); // Scan each of the human drivers to see if they're active in this race if (NetIsServer()) { NetServerMutexData *pSData = NetGetServer()->LockServerData(); assert(pSData); // Ensure that garage menu knows about driver for (unsigned int i=0; i < pSData->m_vecNetworkPlayers.size(); i++) { newDriver = GfDrivers::self()->getDriver(NETWORKROBOT, pSData->m_vecNetworkPlayers[i].idx); if (!newDriver) { GfLogInfo("Driver %s not found, reloading drivers\n", pSData->m_vecNetworkPlayers[i].name); GfDrivers::self()->reload(); LmRaceEngine().race()->load(LmRaceEngine().race()->getManager(), true); break; } } for (unsigned int i=0; i < pSData->m_vecNetworkPlayers.size(); i++) { int k = 1; char path2[256]; pSData->m_vecNetworkPlayers[i].active = false; newDriver = GfDrivers::self()->getDriver(NETWORKROBOT, pSData->m_vecNetworkPlayers[i].idx); // Scan through drivers listed in 'networkrace.xml' while (pSData->m_vecNetworkPlayers[i].active == false) { sprintf(path2, "%s/%d", RM_SECT_DRIVERS, k++); if (GfParmExistsSection(reInfo->params, path2) == 0) { GfLogInfo("UpdateNetworkPlayers: Removing driver %s\n", pSData->m_vecNetworkPlayers[i].name); if (pSData->m_vecNetworkPlayers[i].client) { //need to tell/force client to disconnect } break; } if ((tdble)pSData->m_vecNetworkPlayers[i].idx == GfParmGetNum(reInfo->params, path2, RM_ATTR_IDX, NULL, 1.0) && strcmp(NETWORKROBOT, GfParmGetStr(reInfo->params, path2, RM_ATTR_MODULE, "")) == 0) { pSData->m_vecNetworkPlayers[i].active = true; } } // add or remove from competitor list (for garage menu) GfDriver* activeDriver = LmRaceEngine().race()->getCompetitor(NETWORKROBOT, pSData->m_vecNetworkPlayers[i].idx); if (pSData->m_vecNetworkPlayers[i].active) { if (!activeDriver) LmRaceEngine().race()->appendCompetitor(newDriver); } else { if (activeDriver) LmRaceEngine().race()->removeCompetitor(newDriver); } } NetGetServer()->UnlockServerData(); } else { #if 1 // Client XML files already written to disk - this works but is not the best solution.... GfDrivers::self()->reload(); LmRaceEngine().race()->load(LmRaceEngine().race()->getManager(), true); #endif } //Update track info std::string strTrackPath = GfParmGetStr(reInfo->params, "Tracks/1", RM_ATTR_NAME, ""); std::string strCategory = GfParmGetStr(reInfo->params, "Tracks/1", RM_ATTR_CATEGORY, ""); std::string strTrackName = GetTrackName(strCategory.c_str(),strTrackPath.c_str()); sprintf(buf, "%s", strTrackName.c_str()); GfuiLabelSetText(racemanMenuHdle,g_trackHd,buf); //Store current track - client needs this GfTrack* PCurTrack = GfTracks::self()->getTrackWithName(buf); LmRaceEngine().race()->getManager()->setEventTrack(0, PCurTrack); int laps = (int)GfParmGetNum(reInfo->params, reInfo->_reName,"laps", "", 1); sprintf(buf, "%i", laps); GfuiLabelSetText(racemanMenuHdle,g_lapsHd,buf); GfuiScreenAddBgImg(racemanMenuHdle, GetTrackPreviewFileName(strCategory.c_str(),strTrackPath.c_str()).c_str()); GfuiStaticImageSet(racemanMenuHdle, g_OutlineId, GetTrackOutlineFileName(strCategory.c_str(),strTrackPath.c_str()).c_str()); // Update category info std::string strCarCat; bool bCollisions; NetGetNetwork()->GetHostSettings(strCarCat,bCollisions); GfuiLabelSetText(racemanMenuHdle,g_catHd,strCarCat.c_str()); //fill in player data int nCars = GfParmGetEltNb(reInfo->params, RM_SECT_DRIVERS); char dname[256]; char robpath[256]; float *pColor = &green[0]; bool bEveryoneReadyToRace = true; for (int i = 1; i < nCars+1; i++) { sprintf(dname, "%s/%d", RM_SECT_DRIVERS, i); const char* robot = GfParmGetStr(reInfo->params, dname, RM_ATTR_MODULE, ""); //lookup playerName and car name sprintf(robpath,"drivers/%s/%s.xml",robot,robot); void *pMod = GfParmReadFileLocal(robpath,GFPARM_RMODE_REREAD); if (pMod == NULL) { //try again in other path sprintf(robpath,"drivers/%s/%s.xml",robot,robot); pMod = GfParmReadFile(robpath,GFPARM_RMODE_REREAD); if (pMod == NULL) continue; } assert(pMod); char ppname[256]; int idx = GfParmGetNum(reInfo->params, dname, RM_ATTR_IDX, "",0); sprintf(ppname,"Robots/index/%d",idx); const char* name = GfParmGetStr(pMod, ppname, RM_ATTR_NAME, ""); const char* car = GfParmGetStr(pMod, ppname, "car name", ""); std::string strRealCar = GfCars::self()->getCar(car)->getName(); // WAIT : pNData->m_vecReadyStatus[i-1] ?! // This can only work when _only_ networkhuman drivers in the race // (that is _no_robot_driver_) ; because m_vecReadyStatus is indexed // by the networkhuman drivers list. // TO fix this, 2 solutions: // 1) make the networking module take care of the robot drivers too // (in m_vecReadyStatus, m_vecNetworkPlayers, ...) // 2) make the networking _menu_ only take care of the networkhuman drivers. bool bReady = bRobotsReady; if(strcmp(NETWORKROBOT, GfParmGetStr(reInfo->params, dname, RM_ATTR_MODULE, "")) == 0) { // Write car model, as it may have changed via garage menu if (NetIsServer()) { NetServerMutexData *pSData = NetGetServer()->LockServerData(); strncpy(pSData->m_vecNetworkPlayers[idx-1].car, car, 64); GfLogInfo("idx %d car set to %s\n", idx, car); // also need to write back for garage menu const GfCar* newCar = GfCars::self()->getCar(car); newDriver = GfDrivers::self()->getDriver(NETWORKROBOT, pSData->m_vecNetworkPlayers[idx-1].idx); newDriver->setCar(newCar); NetGetServer()->UnlockServerData(); } //GfLogInfo("idx %d, m_vecReadyStatus.size() %d\n", idx, pNData->m_vecReadyStatus.size()); NetMutexData *pNData = NetGetNetwork()->LockNetworkData(); bReady = pNData->m_vecReadyStatus[idx-1]; NetGetNetwork()->UnlockNetworkData(); } int readyindex = 0; if (bReady) readyindex = 1; else bEveryoneReadyToRace = false; if (strcmp(NetGetNetwork()->GetDriverName(),name)==0) { pColor = &green[0]; g_strCar = strRealCar; //Make sure checkbox matches ready state GfuiCheckboxSetChecked(racemanMenuHdle, g_ReadyCheckboxId, bReady); if (NetGetClient()) EnableMenuClientButtons(bReady); else EnableMenuHostButtons(bReady); } else pColor = &white[0]; GfuiVisibilitySet(racemanMenuHdle,g_readystatus[i-1],true); GfuiStaticImageSetActive(racemanMenuHdle,g_readystatus[i-1],readyindex); GfuiLabelSetColor(racemanMenuHdle, g_playerNames[i-1], pColor); GfuiLabelSetText(racemanMenuHdle,g_playerNames[i-1],name); GfuiLabelSetColor(racemanMenuHdle, g_carNames[i-1], pColor); GfuiLabelSetText(racemanMenuHdle,g_carNames[i-1],strRealCar.c_str()); GfParmReleaseHandle(pMod); } //Clear out rest of table for (int i=nCars;i<MAXNETWORKPLAYERS;i++) { GfuiVisibilitySet(racemanMenuHdle,g_readystatus[i],false); GfuiLabelSetText(racemanMenuHdle,g_playerNames[i],""); GfuiLabelSetText(racemanMenuHdle,g_carNames[i],""); } pNetwork->SetRefreshDisplay(false); GfuiApp().eventLoop().postRedisplay(); if (NetIsClient()) { NetGetClient()->ConnectToClients(); if (!NetGetClient()->TimeSynced()) { NetGetClient()->SendServerTimeRequest(); } } if (NetIsServer()) { if (bEveryoneReadyToRace && nCars > 1) ServerPrepareStartNetworkRace(NULL); } }