// Save the choosen values in the corresponding parameter file. static void saveSoundOption(void *) { const int BUFSIZE = 1024; char buf[BUFSIZE]; snprintf(buf, BUFSIZE, "%s%s", GetLocalDir(), GR_SOUND_PARM_CFG); void *paramHandle = GfParmReadFile(buf, GFPARM_RMODE_REREAD | GFPARM_RMODE_CREAT); GfParmSetStr(paramHandle, GR_SCT_SOUND, GR_ATT_SOUND_STATE, soundOptionList[curOption]); GfParmSetNum(paramHandle, GR_SCT_SOUND, GR_ATT_SOUND_VOLUME, "%", VolumeValue); GfParmWriteFile(NULL, paramHandle, "sound"); GfParmReleaseHandle(paramHandle); // Write Menu music optons snprintf(buf, BUFSIZE, "%s%s", GetLocalDir(), MM_SOUND_PARM_CFG); paramHandle = GfParmReadFile(buf, GFPARM_RMODE_REREAD | GFPARM_RMODE_CREAT); GfParmSetStr(paramHandle, MM_SCT_SOUND, MM_ATT_SOUND_ENABLE, menuMusicList[curOptionMenuMusic]); GfParmWriteFile(NULL, paramHandle, "sound"); GfParmReleaseHandle(paramHandle); if (curOptionMenuMusic == 1) { startMenuMusic(); } else { stopMenuMusic(); } // Return to previous screen. GfuiScreenActivate(prevHandle); return; }
ReSituation::~ReSituation() { // Free ReInfo memory. if (_pReInfo->results) { if (_pReInfo->mainResults != _pReInfo->results) GfParmReleaseHandle(_pReInfo->mainResults); GfParmReleaseHandle(_pReInfo->results); } if (_pReInfo->_reParam) GfParmReleaseHandle(_pReInfo->_reParam); if (_pReInfo->params != _pReInfo->mainParams) { GfParmReleaseHandle(_pReInfo->params); _pReInfo->params = _pReInfo->mainParams; } // if (_pReInfo->movieCapture.outputBase) // free(_pReInfo->movieCapture.outputBase); free(_pReInfo->s); free(_pReInfo->carList); free(_pReInfo->rules); FREEZ(_pReInfo); // Prepare the singleton for next use. _pSelf = 0; }
/** Add an image background to a screen. @ingroup gui @param scr Screen @param filename file name of the bg image @return None. */ void GfuiScreenAddBgImg(void *scr, const char *filename) { tGfuiScreen *screen = (tGfuiScreen*)scr; void *handle; float screen_gamma; GLbyte *tex; int w,h; const int BUFSIZE = 1024; char buf[BUFSIZE]; if (glIsTexture(screen->bgImage) == GL_TRUE) { glDeleteTextures(1, &screen->bgImage); } snprintf(buf, BUFSIZE, "%s%s", GetLocalDir(), GFSCR_CONF_FILE); handle = GfParmReadFile(buf, GFPARM_RMODE_STD | GFPARM_RMODE_CREAT); screen_gamma = (float)GfParmGetNum(handle, GFSCR_SECT_PROP, GFSCR_ATT_GAMMA, (char*)NULL, 2.0); tex = (GLbyte*)GfImgReadPng(filename, &w, &h, screen_gamma); if (!tex) { GfParmReleaseHandle(handle); return; } glGenTextures(1, &screen->bgImage); glBindTexture(GL_TEXTURE_2D, screen->bgImage); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, w, h, 0, GL_RGBA, GL_UNSIGNED_BYTE, (GLvoid *)(tex)); free(tex); GfParmReleaseHandle(handle); }
int ReRaceEventInit(void) { void *mainParams = ReInfo->mainParams; void *params = ReInfo->params; const bool careerMode = strcmp(GfParmGetStr(ReInfo->mainParams, RM_SECT_SUBFILES, RM_ATTR_HASSUBFILES, RM_VAL_NO), RM_VAL_YES) == 0; /* Career mode : Look if it is necessary to open another file */ if (strcmp(GfParmGetStr(mainParams, RM_SECT_SUBFILES, RM_ATTR_HASSUBFILES, RM_VAL_NO), RM_VAL_YES) == 0) { /* Close previous params */ if (params != mainParams) GfParmReleaseHandle(params); /* Read the new params */ ReInfo->params = GfParmReadFile( GfParmGetStr( ReInfo->mainResults, RE_SECT_CURRENT, RE_ATTR_CUR_FILE, "" ), GFPARM_RMODE_STD ); GfLogTrace("Career : New params file is %s (from main results file)\n", GfParmGetStr( ReInfo->mainResults, RE_SECT_CURRENT, RE_ATTR_CUR_FILE, "")); if (!ReInfo->params) GfLogWarning( "Career : MainResults params weren't read correctly\n" ); /* Close previous results */ if (ReInfo->results != ReInfo->mainResults) { GfParmWriteFile(NULL, ReInfo->results, NULL); GfParmReleaseHandle(ReInfo->results); } /* Read the new results */ ReInfo->results = GfParmReadFile( GfParmGetStr( ReInfo->params, RM_SECT_SUBFILES, RM_ATTR_RESULTSUBFILE, ""), GFPARM_RMODE_STD ); if (!ReInfo->results) GfLogWarning( "Career : New results weren't read correctly\n" ); } // Initialize the race session name. ReInfo->_reRaceName = ReGetCurrentRaceName(); GfLogInfo("Starting new event (%s session)\n", ReInfo->_reRaceName); ReUI().onRaceEventInitializing(); ReInfo->s->_features = RmGetFeaturesList(ReInfo->params); ReTrackInit(); ReEventInitResults(); NoCleanupNeeded = false; const bool bGoOnLooping = ReUI().onRaceEventStarting(careerMode && !ReHumanInGroup()); return (bGoOnLooping ? RM_SYNC : RM_ASYNC) | RM_NEXT_STEP; }
// Read sound configuration. static void readSoundCfg(void) { const char *optionName; int i; char buf[1024]; sprintf(buf, "%s%s", GetLocalDir(), GR_SOUND_PARM_CFG); void *paramHandle = GfParmReadFile(buf, GFPARM_RMODE_REREAD | GFPARM_RMODE_CREAT); optionName = GfParmGetStr(paramHandle, GR_SCT_SOUND, GR_ATT_SOUND_STATE, soundOptionList[0]); for (i = 0; i < nbOptions; i++) { if (strcmp(optionName, soundOptionList[i]) == 0) { curOption = i; break; } } VolumeValue = GfParmGetNum(paramHandle, GR_SCT_SOUND, GR_ATT_SOUND_VOLUME, "%", 100.0f); if (VolumeValue>100.0f) { VolumeValue = 100.0f; } if (VolumeValue < 0.0f) { VolumeValue = 0.0f; } GfParmReleaseHandle(paramHandle); GfuiLabelSetText(scrHandle, SoundOptionId, soundOptionList[curOption]); }
void shutdownCars(void) { int i; GfOut("-- shutdownCars\n"); grShutdownSound(grNbCars); if (grNbCars) { grShutdownBoardCar(); grShutdownSkidmarks(); grShutdownSmoke(); grShudownCarlight(); /* Delete ssg objects */ CarsAnchor->removeAllKids(); ShadowAnchor->removeAllKids(); for (i = 0; i < grNbCars; i++) { ssgDeRefDelete(grCarInfo[i].envSelector); ssgDeRefDelete(grCarInfo[i].shadowBase); ssgDeRefDelete(grCarInfo[i].wheelTexture); if (grCarInfo[i].driverSelectorinsg == false) { delete grCarInfo[i].driverSelector; } } PitsAnchor->removeAllKids(); ThePits = 0; free(grCarInfo); } GfParmReleaseHandle(grHandle); for (i = 0; i < GR_NB_MAX_SCREEN; i++) { grScreens[i]->setCurrentCar(NULL); } }
/* * Function * * * Description * search under drivers/human/tracks/<trackname>/car-<model>-<index>.xml * drivers/human/car-<model>-<index>.xml * drivers/human/tracks/<trackname>/car-<model>.xml * drivers/human/car-<model>.xml * * Parameters * * * Return * * * Remarks * */ static void initTrack(int index, tTrack* track, void *carHandle, void **carParmHandle, tSituation *s) { const char *carname; const int BUFSIZE = 1024; char buf[BUFSIZE]; char sstring[BUFSIZE]; tdble fuel; int idx = index - 1; curTrack = track; snprintf(sstring, BUFSIZE, "Robots/index/%d", index); snprintf(buf, BUFSIZE, "%sdrivers/human/human.xml", GetLocalDir()); void *DrvInfo = GfParmReadFile(buf, GFPARM_RMODE_REREAD | GFPARM_RMODE_CREAT); carname = ""; if (DrvInfo != NULL) { carname = GfParmGetStr(DrvInfo, sstring, "car name", ""); } *carParmHandle = NULL; // If session type is "race" and we have a race setup use it if (s->_raceType == RM_TYPE_RACE) { *carParmHandle = RtParmReadSetup(RACE, "human", index, track->internalname, carname); } // If session type is "qualifying" and we have a qualifying setup use it, use qualifying setup as // fallback if not race setup is available if (s->_raceType == RM_TYPE_QUALIF || (*carParmHandle == NULL && s->_raceType == RM_TYPE_RACE)) { *carParmHandle = RtParmReadSetup(QUALIFYING, "human", index, track->internalname, carname); } // If we have not yet loaded a setup we have not found a fitting one or want to use the practice setup, // so try to load this if (*carParmHandle == NULL) { *carParmHandle = RtParmReadSetup(PRACTICE, "human", index, track->internalname, carname); } // Absolute fallback, nothing found if (*carParmHandle == NULL) { snprintf(sstring, BUFSIZE, "%sdrivers/human/car.xml", GetLocalDir ()); *carParmHandle = GfParmReadFile(sstring, GFPARM_RMODE_REREAD); } if (curTrack->pits.type != TR_PIT_NONE) { snprintf(sstring, BUFSIZE, "%s/%s/%d", HM_SECT_PREF, HM_LIST_DRV, index); HCtx[idx]->NbPitStopProg = (int)GfParmGetNum(PrefHdle, sstring, HM_ATT_NBPITS, (char*)NULL, 0); GfOut("Player: index %d , Pits stops %d\n", index, HCtx[idx]->NbPitStopProg); } else { HCtx[idx]->NbPitStopProg = 0; } fuel = 0.0008 * curTrack->length * (s->_totLaps + 1) / (1.0 + ((tdble)HCtx[idx]->NbPitStopProg)) + 20.0; if (*carParmHandle) { GfParmSetNum(*carParmHandle, SECT_CAR, PRM_FUEL, (char*)NULL, fuel); } Vtarget = curTrack->pits.speedLimit; if (DrvInfo != NULL) { GfParmReleaseHandle(DrvInfo); } }
// Retrieve the NetDriver instance with given index in the human module interface list static int GetHumanDriver(NetDriver &driver,int index) { void *params = GfParmReadFileLocal("drivers/human/human.xml", GFPARM_RMODE_STD); assert(params); char path2[256]; sprintf(path2, "Robots/index/%d",index); if (GfParmExistsSection(params, path2) == 0) return 0; strncpy(driver.name,GfParmGetStr(params, path2, "name",NULL),64); strncpy(driver.sname,GfParmGetStr(params, path2, ROB_ATTR_SNAME, NULL), 64); strncpy(driver.cname,GfParmGetStr(params, path2, ROB_ATTR_CODE, NULL), 4); strncpy(driver.car,GfParmGetStr(params, path2, "car name",NULL),64); strncpy(driver.type,GfParmGetStr(params, path2, "type",NULL),64); strncpy(driver.skilllevel,GfParmGetStr(params, path2, "skill level",NULL),64); driver.racenumber = GfParmGetNum(params, path2, "race number",NULL,1.0); driver.red = GfParmGetNum(params, path2, "red",NULL,1.0); driver.green = GfParmGetNum(params, path2, "green",NULL,1.0); driver.blue = GfParmGetNum(params, path2, "blue",NULL,1.0); strncpy(driver.module,NETWORKROBOT,64); GfParmReleaseHandle(params); return 1; }
static void rmdsClickOnDriver(void * /* dummy */) { char *name; tDrvElt *curDrv; void *robhdle; name = GfuiScrollListGetSelectedElement(scrHandle, selectedScrollList, (void**)&curDrv); if (!name) { name = GfuiScrollListGetSelectedElement(scrHandle, unselectedScrollList, (void**)&curDrv); } if (name) { GfuiLabelSetText(scrHandle, PickDrvNameLabelId, curDrv->name); /* search driver infos */ sprintf(buf, "%sdrivers/%s/%s.xml", GetLocalDir(), curDrv->dname, curDrv->dname); robhdle = GfParmReadFile(buf, GFPARM_RMODE_STD); if (!robhdle) { sprintf(buf, "drivers/%s/%s.xml", curDrv->dname, curDrv->dname); robhdle = GfParmReadFile(buf, GFPARM_RMODE_STD); } if (robhdle != NULL) { sprintf(buf, "%s/%s/%d", ROB_SECT_ROBOTS, ROB_LIST_INDEX, curDrv->index); GfuiLabelSetText(scrHandle, PickDrvCarLabelId, GfParmGetName(curDrv->car)); GfuiLabelSetText(scrHandle, PickDrvCategoryLabelId, GfParmGetStr(curDrv->car, SECT_CAR, PRM_CATEGORY, "")); GfParmReleaseHandle(robhdle); } } }
extern "C" int human(tModInfo *modInfo) { int i; const char *driver; const int BUFSIZE = 1024; char buf[BUFSIZE]; char sstring[BUFSIZE]; memset(modInfo, 0, 10*sizeof(tModInfo)); snprintf(buf, BUFSIZE, "%sdrivers/human/human.xml", GetLocalDir()); void *DrvInfo = GfParmReadFile(buf, GFPARM_RMODE_REREAD | GFPARM_RMODE_CREAT); if (DrvInfo != NULL) { for (i = 0; i < 10; i++) { snprintf(sstring, BUFSIZE, "Robots/index/%d", i+1); driver = GfParmGetStr(DrvInfo, sstring, "name", ""); if (strlen(driver) == 0) { break; } modInfo->name = strdup(driver); /* name of the module (short) */ modInfo->desc = strdup("Joystick controlable driver"); /* description of the module (can be long) */ modInfo->fctInit = InitFuncPt; /* init function */ modInfo->gfId = ROB_IDENT; /* supported framework version */ modInfo->index = i+1; modInfo++; } // Just release in case we got it. GfParmReleaseHandle(DrvInfo); } return 0; }
static void gfuiColorInit(void) { void *hdle; int i, j; char *rgba[4] = {GFSCR_ATTR_RED, GFSCR_ATTR_GREEN, GFSCR_ATTR_BLUE, GFSCR_ATTR_ALPHA}; char *clr[GFUI_COLORNB] = { GFSCR_ELT_BGCOLOR, GFSCR_ELT_TITLECOLOR, GFSCR_ELT_BGBTNFOCUS, GFSCR_ELT_BGBTNCLICK, GFSCR_ELT_BGBTNENABLED, GFSCR_ELT_BGBTNDISABLED, GFSCR_ELT_BTNFOCUS, GFSCR_ELT_BTNCLICK, GFSCR_ELT_BTNENABLED, GFSCR_ELT_BTNDISABLED, GFSCR_ELT_LABELCOLOR, GFSCR_ELT_TIPCOLOR, GFSCR_ELT_MOUSECOLOR1, GFSCR_ELT_MOUSECOLOR2, GFSCR_ELT_HELPCOLOR1, GFSCR_ELT_HELPCOLOR2, GFSCR_ELT_BGSCROLLIST, GFSCR_ELT_SCROLLIST, GFSCR_ELT_BGSELSCROLLIST, GFSCR_ELT_SELSCROLLIST, GFSCR_ELT_EDITCURSORCLR }; sprintf(buf, "%s%s", GetLocalDir(), GFSCR_CONF_FILE); hdle = GfParmReadFile(buf, GFPARM_RMODE_STD | GFPARM_RMODE_CREAT); for (i = 0; i < GFUI_COLORNB; i++) { for (j = 0; j < 4; j++) { sprintf(buf, "%s/%s/%s", GFSCR_SECT_MENUCOL, GFSCR_LIST_COLORS, clr[i]); GfuiColor[i][j] = GfParmGetNum(hdle, buf, rgba[j], (char*)NULL, 1.0); } } GfParmReleaseHandle(hdle); /* Remove the X11/Windows cursor */ if (!GfuiMouseHW) { glutSetCursor(GLUT_CURSOR_NONE); } GfuiMouseVisible = 1; }
// 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); }
void ReRaceAbort() { ReShutdownUpdaters(); RePhysicsEngine().shutdown(); RaceEngine::self().unloadPhysicsEngine(); ReUI().onRaceFinishing(); ReRaceCleanDrivers(); if (NetGetNetwork()) NetGetNetwork()->Disconnect(); FREEZ(ReInfo->_reCarInfo); if (ReInfo->params != ReInfo->mainParams) { GfParmReleaseHandle(ReInfo->params); ReInfo->params = ReInfo->mainParams; } // Return to race configuration step ReStateApply((void*)RE_STATE_CONFIG); }
void ReRaceCleanDrivers(void) { int i; tRobotItf *robot; int nCars; tMemoryPool oldPool = NULL; nCars = ReInfo->s->_ncars; for (i = 0; i < nCars; i++) { robot = ReInfo->s->cars[i]->robot; GfPoolMove( &ReInfo->s->cars[i]->_shutdownMemPool, &oldPool ); if (robot->rbShutdown && !(ReInfo->_displayMode & RM_DISP_MODE_SIMU_SIMU)) { robot->rbShutdown(robot->index); } GfPoolFreePool( &oldPool ); GfParmReleaseHandle(ReInfo->s->cars[i]->_paramsHandle); free(robot); free(ReInfo->s->cars[i]->_curSplitTime); free(ReInfo->s->cars[i]->_bestSplitTime); } RtTeamManagerRelease(); FREEZ(ReInfo->s->cars); ReInfo->s->cars = 0; ReInfo->s->_ncars = 0; GfModUnloadList(&ReRacingRobotsModList); }
void TrackShutdown(void) { tTrackSeg *curSeg; tTrackSeg *nextSeg; tTrackSurface *curSurf; tTrackSurface *nextSurf; tRoadCam *curCam; tRoadCam *nextCam; int xx; if (!theTrack) { return; } nextSeg = theTrack->seg->next; do { curSeg = nextSeg; nextSeg = nextSeg->next; freeSeg(curSeg); } while (curSeg != theTrack->seg); curSurf = theTrack->surfaces; while (curSurf) { nextSurf = curSurf->next; free(curSurf); curSurf = nextSurf; } curCam = theCamList; if (curCam) { do { nextCam = curCam->next; free(curCam); curCam = nextCam; } while (curCam != theCamList); } theCamList = NULL; if (theTrack->pits.driversPits) free(theTrack->pits.driversPits); free(theTrack->graphic.env); if(theTrack->graphic.nb_lights > 0) { for (xx = 0; xx < theTrack->graphic.nb_lights; ++xx) { free(theTrack->graphic.lights[ xx ].onTexture); free(theTrack->graphic.lights[ xx ].offTexture); } free(theTrack->graphic.lights); } free(theTrack->internalname); free(theTrack->filename); if (theTrack->sectors) free(theTrack->sectors); free(theTrack); GfParmReleaseHandle(TrackHandle); theTrack = NULL; }
// Read sound configuration. static void readSoundCfg(void) { const char *optionName; int i; const int BUFSIZE = 1024; char buf[BUFSIZE]; snprintf(buf, BUFSIZE, "%s%s", GetLocalDir(), GR_SOUND_PARM_CFG); void *paramHandle = GfParmReadFile(buf, GFPARM_RMODE_REREAD | GFPARM_RMODE_CREAT); optionName = GfParmGetStr(paramHandle, GR_SCT_SOUND, GR_ATT_SOUND_STATE, soundOptionList[0]); for (i = 0; i < nbOptions; i++) { if (strcmp(optionName, soundOptionList[i]) == 0) { curOption = i; break; } } VolumeValue = GfParmGetNum(paramHandle, GR_SCT_SOUND, GR_ATT_SOUND_VOLUME, "%", 100.0f); if (VolumeValue>100.0f) { VolumeValue = 100.0f; } if (VolumeValue < 0.0f) { VolumeValue = 0.0f; } GfParmReleaseHandle(paramHandle); GfuiLabelSetText(scrHandle, SoundOptionId, soundOptionList[curOption]); // Read Menu music optons snprintf(buf, BUFSIZE, "%s%s", GetLocalDir(), MM_SOUND_PARM_CFG); paramHandle = GfParmReadFile(buf, GFPARM_RMODE_REREAD | GFPARM_RMODE_CREAT); optionName = GfParmGetStr(paramHandle, MM_SCT_SOUND, MM_ATT_SOUND_ENABLE, MM_VAL_SOUND_DISABLED); if (strcmp(optionName, MM_VAL_SOUND_ENABLED) == 0) { GfuiLabelSetText(scrHandle, MenuMusicOptionId, MM_VAL_SOUND_ENABLED); curOptionMenuMusic = 1; } else { GfuiLabelSetText(scrHandle, MenuMusicOptionId, MM_VAL_SOUND_DISABLED); curOptionMenuMusic = 0; } GfParmReleaseHandle(paramHandle); }
void * JoyCalMenuInit(void *prevMenu, void *nextMenu, tCmdInfo *cmd, int maxcmd) { int i; char pszBuf[64]; Cmd = cmd; MaxCmd = maxcmd; PrevMenuHandle = prevMenu; NextMenuHandle = nextMenu; if (ScrHandle) { return ScrHandle; } // Create screen, load menu XML descriptor and create static controls. ScrHandle = GfuiScreenCreate(NULL, NULL, onActivate, NULL, NULL, 1); void *menuXMLDescHdle = GfuiMenuLoad("joystickconfigmenu.xml"); GfuiMenuCreateStaticControls(ScrHandle, menuXMLDescHdle); // Create joystick axis label controls (axis name, axis Id, axis min value, axis max value) for (i = 0; i < NbMaxCalAxis; i++) { sprintf(pszBuf, "%saxislabel", LabName[i]); LabAxisId[i] = GfuiMenuCreateLabelControl(ScrHandle, menuXMLDescHdle, pszBuf); sprintf(pszBuf, "%sminlabel", LabName[i]); LabMinId[i] = GfuiMenuCreateLabelControl(ScrHandle, menuXMLDescHdle, pszBuf); sprintf(pszBuf, "%smaxlabel", LabName[i]); LabMaxId[i] = GfuiMenuCreateLabelControl(ScrHandle, menuXMLDescHdle, pszBuf); } // Create instruction variable label. InstId = GfuiMenuCreateLabelControl(ScrHandle, menuXMLDescHdle, "instructionlabel"); // Create Cancel and Reset buttons. GfuiMenuCreateButtonControl(ScrHandle, menuXMLDescHdle, "resetbutton", NULL, onActivate); if (nextMenu != NULL) { NextBut = GfuiMenuCreateButtonControl(ScrHandle, menuXMLDescHdle, "nextbutton", NULL, onNext); GfuiEnable(ScrHandle, NextBut, GFUI_DISABLE); } else { DoneBut = GfuiMenuCreateButtonControl(ScrHandle, menuXMLDescHdle, "donebutton", NULL, onNext); GfuiEnable(ScrHandle, DoneBut, GFUI_DISABLE); } CancelBut = GfuiMenuCreateButtonControl(ScrHandle, menuXMLDescHdle, "cancelbutton", NULL, onNext); // Close menu XML descriptor. GfParmReleaseHandle(menuXMLDescHdle); // Register keyboard shortcuts. GfuiMenuDefaultKeysAdd(ScrHandle); GfuiAddKey(ScrHandle, GFUIK_ESCAPE, "Next", NULL, onNext, NULL); GfuiAddKey(ScrHandle, GFUIK_RETURN, "Next", NULL, onNext, NULL); return ScrHandle; }
void GfglFeatures::closeConfigFile(void* hparmConfig, bool bWrite) { // Write if specified. if (bWrite) GfParmWriteFile(NULL, hparmConfig, "Screen"); // Close. GfParmReleaseHandle(hparmConfig); }
void gfuiLoadFonts(void) { void *param; int size; int i; int nFontId; snprintf(buf, sizeof(buf), "%s%s", GfLocalDir(), GFSCR_CONF_FILE); param = GfParmReadFile(buf, GFPARM_RMODE_STD | GFPARM_RMODE_CREAT); snprintf(buf, sizeof(buf), "%sdata/fonts/%s", GfDataDir(), GfParmGetStr(param, "Menu Font", "name", "b5.glf")); GfLogTrace("Loading font 'Menu Font' from %s : Sizes", buf); nFontId = GFUI_FONT_BIG; for(i = 0; i < 4; i++, nFontId++) { size = (int)GfParmGetNum(param, "Menu Font", keySize[i], (char*)NULL, 10.0); GfLogTrace(" %d,", size); gfuiFont[nFontId] = new GfuiFontClass(buf); gfuiFont[nFontId]->create(size); } GfLogTrace("\n"); snprintf(buf, sizeof(buf), "%sdata/fonts/%s", GfDataDir(), GfParmGetStr(param, "Console Font", "name", "b7.glf")); GfLogTrace("Loading font 'Console Font' from %s : Sizes", buf); nFontId = GFUI_FONT_BIG_C; for(i = 0; i < 4; i++, nFontId++) { size = (int)GfParmGetNum(param, "Console Font", keySize[i], (char*)NULL, 10.0); GfLogTrace(" %d,", size); gfuiFont[nFontId] = new GfuiFontClass(buf); gfuiFont[nFontId]->create(size); } GfLogTrace("\n"); snprintf(buf, sizeof(buf), "%sdata/fonts/%s", GfDataDir(), GfParmGetStr(param, "Text Font", "name", "b6.glf")); GfLogTrace("Loading font 'Text Font' from %s : Sizes", buf); nFontId = GFUI_FONT_BIG_T; for(i = 0; i < 4; i++, nFontId++) { size = (int)GfParmGetNum(param, "Text Font", keySize[i], (char*)NULL, 10.0); GfLogTrace(" %d,", size); gfuiFont[nFontId] = new GfuiFontClass(buf); gfuiFont[nFontId]->create(size); } GfLogTrace("\n"); snprintf(buf, sizeof(buf), "%sdata/fonts/%s", GfDataDir(), GfParmGetStr(param, "Digital Font", "name", "digital.glf")); GfLogTrace("Loading font 'Digital Font' from %s : Sizes", buf); nFontId = GFUI_FONT_DIGIT; size = (int)GfParmGetNum(param, "Digital Font", keySize[0], (char*)NULL, 8.0); GfLogTrace(" %d\n", size); gfuiFont[nFontId] = new GfuiFontClass(buf); gfuiFont[nFontId]->create(size); GfParmReleaseHandle(param); }
// Read sound configuration. static void readSoundCfg(void) { const char *optionName; int i; char buf[1024]; // Sound interface. sprintf(buf, "%s%s", GfLocalDir(), SND_PARAM_FILE); void *paramHandle = GfParmReadFile(buf, GFPARM_RMODE_REREAD | GFPARM_RMODE_CREAT); optionName = GfParmGetStr(paramHandle, SND_SCT_SOUND, SND_ATT_SOUND_STATE, soundOptionList[0]); for (i = 0; i < nbOptions; i++) { if (strcmp(optionName, soundOptionList[i]) == 0) { curOption = i; break; } } GfuiLabelSetText(scrHandle, SoundOptionId, soundOptionList[curOption]); // Sound volume. VolumeValue = GfParmGetNum(paramHandle, SND_SCT_SOUND, SND_ATT_SOUND_VOLUME, "%", 100.0f); if (VolumeValue>100.0f) { VolumeValue = 100.0f; } else if (VolumeValue < 0.0f) { VolumeValue = 0.0f; } sprintf(buf, "%g", VolumeValue); GfuiEditboxSetString(scrHandle, VolumeValueId, buf); optionName = GfParmGetStr(paramHandle, SND_SCT_MUSIC, SND_ATT_MUSIC_STATE, musicStateList[0]); for (i = 0; i < nbMusicStates; i++) { if (strcmp(optionName, musicStateList[i]) == 0) { curMusicState = i; break; } } GfuiLabelSetText(scrHandle, MusicStateId, musicStateList[curMusicState]); // Music volume. MusicVolumeValue = GfParmGetNum(paramHandle, SND_SCT_MUSIC, SND_ATT_MUSIC_VOLUME, "%", 100.0f); if (MusicVolumeValue>100.0f) { MusicVolumeValue = 100.0f; } else if (MusicVolumeValue < 0.0f) { MusicVolumeValue = 0.0f; } sprintf(buf, "%g", MusicVolumeValue); GfuiEditboxSetString(scrHandle, MusicVolumeValueId, buf); GfParmReleaseHandle(paramHandle); }
bool GfuiMenuScreen::closeXMLDescriptor() { if (m_priv->xmlDescParmHdle) { GfParmReleaseHandle(m_priv->xmlDescParmHdle); m_priv->xmlDescParmHdle = 0; return true; } return false; }
void getUserTextureMaxSize(int &result) { char fnbuf[1024]; sprintf(fnbuf, "%s%s", GetLocalDir(), GR_PARAM_FILE); void *paramHandle = GfParmReadFile(fnbuf, GFPARM_RMODE_REREAD | GFPARM_RMODE_CREAT); result = (int) GfParmGetNum(paramHandle, GR_SCT_GLFEATURES, GR_ATT_TEXTURESIZE, (char*)NULL, (tdble) glTextureMaxSize); if (result > glTextureMaxSize) { result = glTextureMaxSize; } GfParmReleaseHandle(paramHandle); }
static void loadSimuCfg(void) { const char *simuVersionName; const char *multiThreadSchemeName; const char *threadAffinitySchemeName; int i; char buf[1024]; snprintf(buf, sizeof(buf), "%s%s", GfLocalDir(), RACE_ENG_CFG); void *paramHandle = GfParmReadFile(buf, GFPARM_RMODE_REREAD | GFPARM_RMODE_CREAT); // Simulation engine name. simuVersionName = GfParmGetStr(paramHandle, RM_SECT_MODULES, RM_ATTR_MOD_SIMU, SimuVersionList[DefaultSimuVersion]); for (i = 0; i < NbSimuVersions; i++) { if (strcmp(simuVersionName, SimuVersionList[i]) == 0) { CurSimuVersion = i; break; } } // Check if the selected simulation module is there, and fall back to the default one if not. snprintf(buf, sizeof(buf), "%smodules/simu/%s.%s", GfLibDir(), SimuVersionList[CurSimuVersion], DLLEXT); if (!GfFileExists(buf)) { GfLogWarning("User settings %s physics engine module not found ; falling back to %s\n", SimuVersionList[CurSimuVersion], SimuVersionList[DefaultSimuVersion]); CurSimuVersion = DefaultSimuVersion; } // Multi-threading. multiThreadSchemeName = GfParmGetStr(paramHandle, RM_SECT_RACE_ENGINE, RM_ATTR_MULTI_THREADING, MultiThreadSchemeList[0]); for (i = 0; i < NbMultiThreadSchemes; i++) { if (strcmp(multiThreadSchemeName, MultiThreadSchemeList[i]) == 0) { CurMultiThreadScheme = i; break; } } // Thread affinity. threadAffinitySchemeName = GfParmGetStr(paramHandle, RM_SECT_RACE_ENGINE, RM_ATTR_THREAD_AFFINITY, ThreadAffinitySchemeList[0]); for (i = 0; i < NbThreadAffinitySchemes; i++) { if (strcmp(threadAffinitySchemeName, ThreadAffinitySchemeList[i]) == 0) { CurThreadAffinityScheme = i; break; } } GfParmReleaseHandle(paramHandle); GfuiLabelSetText(ScrHandle, SimuVersionId, SimuVersionDispNameList[CurSimuVersion]); GfuiLabelSetText(ScrHandle, MultiThreadSchemeId, MultiThreadSchemeList[CurMultiThreadScheme]); GfuiLabelSetText(ScrHandle, ThreadAffinitySchemeId, ThreadAffinitySchemeList[CurThreadAffinityScheme]); }
/* Race Engine Exit */ void ReShutdown(void) { /* Free previous situation */ if (ReInfo) { ReInfo->_reTrackItf.trkShutdown(); GfModUnloadList(&reEventModList); if (ReInfo->results) { GfParmReleaseHandle(ReInfo->results); } if (ReInfo->_reParam) { GfParmReleaseHandle(ReInfo->_reParam); } FREEZ(ReInfo->s); FREEZ(ReInfo->carList); FREEZ(ReInfo->rules); FREEZ(ReInfo->_reFilename); FREEZ(ReInfo); } }
/* Quit driver config menu (changes must have been saved before if needed) */ static void onQuitPlayerConfig(void * /* dummy */) { // Next time, we'll have to reload the player settings from the files. ReloadValues = 1; // Reset player list tPlayerInfoList::iterator playerIter; for (playerIter = PlayersInfo.begin(); playerIter != PlayersInfo.end(); playerIter++) delete *playerIter; PlayersInfo.clear(); // Close driver and preference params files. GfParmReleaseHandle(PlayerHdle); PlayerHdle = 0; GfParmReleaseHandle(PrefHdle); PrefHdle = 0; // Activate caller screen/menu GfuiScreenActivate(PrevScrHandle); }
static void rmFreeDrvList(void) { tDrvElt *cur; while ((cur = GF_TAILQ_FIRST(&DrvList)) != NULL) { GF_TAILQ_REMOVE(&DrvList, cur, link); free(cur->name); free(cur->dname); GfParmReleaseHandle(cur->car); free(cur); } }
void ReUpdateQualifCurRes(tCarElt *car) { int i; int nCars; int printed; int maxLines; void *carparam; char *carName; const char *race = ReInfo->_reRaceName; void *results = ReInfo->results; const int BUFSIZE = 1024; char buf[BUFSIZE], path[BUFSIZE]; ReResEraseScreen(); maxLines = ReResGetLines(); snprintf(buf, BUFSIZE, "%s on %s - Lap %d", car->_name, ReInfo->track->name, car->_laps); ReResScreenSetTitle(buf); snprintf(buf, BUFSIZE, "cars/%s/%s.xml", car->_carName, car->_carName); carparam = GfParmReadFile(buf, GFPARM_RMODE_STD); carName = GfParmGetName(carparam); printed = 0; snprintf(path, BUFSIZE, "%s/%s/%s/%s", ReInfo->track->name, RE_SECT_RESULTS, race, RE_SECT_RANK); nCars = GfParmGetEltNb(results, path); nCars = MIN(nCars + 1, maxLines); for (i = 1; i < nCars; i++) { snprintf(path, BUFSIZE, "%s/%s/%s/%s/%d", ReInfo->track->name, RE_SECT_RESULTS, race, RE_SECT_RANK, i); if (!printed) { if ((car->_bestLapTime != 0.0) && (car->_bestLapTime < GfParmGetNum(results, path, RE_ATTR_BEST_LAP_TIME, NULL, 0))) { snprintf(buf, BUFSIZE, "%d - %s - %s (%s)", i, GfTime2Str(car->_bestLapTime, 0), car->_name, carName); ReResScreenSetText(buf, i - 1, 1); printed = 1; } } snprintf(buf, BUFSIZE, "%d - %s - %s (%s)", i + printed, GfTime2Str(GfParmGetNum(results, path, RE_ATTR_BEST_LAP_TIME, NULL, 0), 0), GfParmGetStr(results, path, RE_ATTR_NAME, ""), GfParmGetStr(results, path, RE_ATTR_CAR, "")); ReResScreenSetText(buf, i - 1 + printed, 0); } if (!printed) { snprintf(buf, BUFSIZE, "%d - %s - %s (%s)", i, GfTime2Str(car->_bestLapTime, 0), car->_name, carName); ReResScreenSetText(buf, i - 1, 1); } GfParmReleaseHandle(carparam); ReInfo->_refreshDisplay = 1; }
/* Save the choosen values in the corresponding parameter file */ static void SaveSimuVersion(void * /* dummy */) { char buf[1024]; snprintf(buf, 1024, "%s%s", GetLocalDir(), RACE_ENG_CFG); void *paramHandle = GfParmReadFile(buf, GFPARM_RMODE_REREAD | GFPARM_RMODE_CREAT); GfParmSetStr(paramHandle, "Modules", "simu", simuVersionList[curVersion]); GfParmWriteFile(NULL, paramHandle, "raceengine"); GfParmReleaseHandle(paramHandle); /* return to previous screen */ GfuiScreenActivate(prevHandle); return; }
// Save the choosen values in the corresponding parameter file. static void saveSoundOption(void *) { char buf[1024]; sprintf(buf, "%s%s", GetLocalDir(), GR_SOUND_PARM_CFG); void *paramHandle = GfParmReadFile(buf, GFPARM_RMODE_REREAD | GFPARM_RMODE_CREAT); GfParmSetStr(paramHandle, GR_SCT_SOUND, GR_ATT_SOUND_STATE, soundOptionList[curOption]); GfParmSetNum(paramHandle, GR_SCT_SOUND, GR_ATT_SOUND_VOLUME, "%", VolumeValue); GfParmWriteFile(NULL, paramHandle, "sound"); GfParmReleaseHandle(paramHandle); // Return to previous screen. GfuiScreenActivate(prevHandle); return; }
// Sound menu void* SoundMenuInit(void *prevMenu) { // Has screen already been created? if (scrHandle) { return scrHandle; } prevHandle = prevMenu; scrHandle = GfuiScreenCreate((float*)NULL, NULL, onActivate, NULL, (tfuiCallback)NULL, 1); void *param = GfuiMenuLoad("soundconfigmenu.xml"); GfuiMenuCreateStaticControls(scrHandle, param); GfuiMenuCreateButtonControl(scrHandle,param,"soundleftarrow",(void*)-1,changeSoundState); GfuiMenuCreateButtonControl(scrHandle,param,"soundrightarrow",(void*)1,changeSoundState); SoundOptionId = GfuiMenuCreateLabelControl(scrHandle,param,"soundlabel"); GfuiMenuCreateButtonControl(scrHandle,param,"ApplyButton",NULL,saveSoundOption); GfuiMenuCreateButtonControl(scrHandle,param,"CancelButton",prevMenu,GfuiScreenActivate); VolumeValueId = GfuiMenuCreateEditControl(scrHandle,param,"volumeedit",NULL,NULL,changeVolume); //// TODO remove this and uncomment the static controls in 'soundconfigmenu.xml' //// if/when Music is officially included //// HACK to allow CMake option 'OPTION_MENU_MUSIC' to show/hide these menu music labels //GfuiMenuCreateLabelControl(scrHandle,param,"musicstaticlabel"); //GfuiMenuCreateLabelControl(scrHandle,param,"musicstaticvolume"); //// end of code to remove GfuiMenuCreateButtonControl(scrHandle,param,"musicleftarrow",(void*)-1,changeMusicState); GfuiMenuCreateButtonControl(scrHandle,param,"musicrightarrow",(void*)1,changeMusicState); MusicStateId = GfuiMenuCreateLabelControl(scrHandle,param,"musiclabel"); MusicVolumeValueId = GfuiMenuCreateEditControl(scrHandle,param,"musicvolumeedit",NULL,NULL,changeMusicVolume); GfParmReleaseHandle(param); GfuiAddKey(scrHandle, GFUIK_RETURN, "Apply", NULL, saveSoundOption, NULL); GfuiAddKey(scrHandle, GFUIK_ESCAPE, "Cancel", prevMenu, GfuiScreenActivate, NULL); GfuiAddKey(scrHandle, GFUIK_F1, "Help", scrHandle, GfuiHelpScreen, NULL); GfuiAddKey(scrHandle, GFUIK_F12, "Screen-Shot", NULL, GfuiScreenShot, NULL); GfuiAddKey(scrHandle, GFUIK_LEFT, "Previous Option in list", (void*)-1, changeSoundState, NULL); GfuiAddKey(scrHandle, GFUIK_RIGHT, "Next Option in list", (void*)1, changeSoundState, NULL); return scrHandle; }