示例#1
0
void GfglFeatures::dumpHardwareInfo() const
{
    GfLogInfo("Video hardware info :\n");
    GfLogInfo("  Vendor   : %s\n", glGetString(GL_VENDOR));
    GfLogInfo("  Renderer : %s\n", glGetString(GL_RENDERER));
    GfLogInfo("  Version  : %s\n", glGetString(GL_VERSION));
}
static void 
RmReadyToRace(void * /* dummy */)
{
   if (GfuiRemoveKey(rmScreenHandle,GFUIK_RETURN,"Ready"))
   {
   		GfLogInfo("<Enter> key for Ready' removed \n");
   }
   else
   {
      GfLogInfo("FAILED to remove <Enter> to Start key \n");
   }

   // The menu changed.
   rmbMenuChanged = true;

   rmPreRacePause = false;

   // Enable the sound
   if (LegacyMenu::self().soundEngine())
   {
      LegacyMenu::self().soundEngine()->mute(false);
   }

   LmRaceEngine().stopPreracePause();
}
// Implementation of IRaceEngine.
void StandardGame::reset(void)
{
	GfLogInfo("Resetting StandardGame race engine.\n");

	// Cleanup everything in case no yet done.
	cleanup();
	
	// Internal init.
	::ReReset();

	// Load and initialize the track loader module.
	const char* pszModName =
		GfParmGetStr(ReSituation::self().data()->_reParam, "Modules", "track", "track");
	GfLogInfo("Loading '%s' track loader ...\n", pszModName);
	GfModule* pmodTrkLoader = GfModule::load("modules/track", pszModName);

	// Check that it implements ITrackLoader.
	if (pmodTrkLoader)
		_piTrkLoader = pmodTrkLoader->getInterface<ITrackLoader>();
	if (pmodTrkLoader && !_piTrkLoader)
	{
		GfModule::unload(pmodTrkLoader);
		return;
	}

	// Initialize GfTracks' track module interface (needed for some track infos).
	GfTracks::self()->setTrackLoader(_piTrkLoader);
}
示例#4
0
static void onHostPlayerReady(tCheckBoxInfo* pInfo)
{
	tRmInfo* reInfo = LmRaceEngine().inData();
	char dname[256];

	int nCars = GfParmGetEltNb(reInfo->params, RM_SECT_DRIVERS);

	NetServerMutexData *pSData = NetGetServer()->LockServerData();
	for (int i=1; i <= nCars; i++) {
		sprintf(dname, "%s/%d", RM_SECT_DRIVERS, i);

		GfLogInfo("Setting driver %d to %d\n", i, pInfo->bChecked);
		if(strcmp(NETWORKROBOT, GfParmGetStr(reInfo->params, dname, RM_ATTR_MODULE, "")) == 0) {
			// Human drive, check if local
			int index = GfParmGetNum(reInfo->params, dname, RM_ATTR_IDX, NULL, 1.0) - 1;

			GfLogInfo("Index %d\n", index);
			if (pSData->m_vecNetworkPlayers[index].client == false)
				NetGetServer()->OverrideDriverReady(i, pInfo->bChecked);
		} else {
			// Robot driver, all are local
			NetGetServer()->OverrideDriverReady(i, pInfo->bChecked);
		}

		bRobotsReady = pInfo->bChecked;
	}
	NetGetServer()->UnlockServerData();

	EnableMenuHostButtons(pInfo->bChecked);
	GfLogInfo("menu ready\n");
}
示例#5
0
bool LegacyMenu::onRaceFinished(bool bEndOfSession)
{
    tRmInfo* pReInfo = _piRaceEngine->inData();

    // Display the results of the session for all the competitors
    // only if this is the end of a session (for all competitors),
    // and if specified by the race mode or if the display mode is "normal".
    if (bEndOfSession
		&& (!strcmp(GfParmGetStr(pReInfo->params, pReInfo->_reRaceName, RM_ATTR_DISPRES, RM_VAL_YES), RM_VAL_YES)
            || pReInfo->_displayMode == RM_DISP_MODE_NORMAL))
	{
        // Create the "Race Engine update state" hook if not already done.
        if (!_hscrReUpdateStateHook)
            _hscrReUpdateStateHook = ::RmInitReUpdateStateHook();

        // This is now the "game" screen.
        _hscrGame = _hscrReUpdateStateHook;

        // Display the results menu (will activate the game screen on exit).
        ::RmShowResults(_hscrGame, _piRaceEngine->inData());

        // Tell the race engine state automaton to stop looping (enter the menu).
        return false;
    }

    GfLogInfo("Not starting Results menu (not end of session, or specified not to, or blind mode).\n");

    return true;
}
示例#6
0
int
RePostRace(void)
{
	int curRaceIdx;
	void *results = ReInfo->results;
	void *params = ReInfo->params;

	// Prepare for next session if any left in the event.
	curRaceIdx = (int)GfParmGetNum(results, RE_SECT_CURRENT, RE_ATTR_CUR_RACE, NULL, 1);
	if (curRaceIdx < GfParmGetEltNb(params, RM_SECT_RACES)) {

		// Next session.
		curRaceIdx++;
		GfLogInfo("Next session will be #%d\n", curRaceIdx);
		GfParmSetNum(results, RE_SECT_CURRENT, RE_ATTR_CUR_RACE, NULL, (tdble)curRaceIdx);
		
		// Update standings in the results file.
		ReUpdateStandings();
		
		return RM_SYNC | RM_NEXT_RACE;
	}

	// No more session in the event : update standings in the results file.
	ReUpdateStandings();

	// Next event if any will start with its first session.
	GfParmSetNum(results, RE_SECT_CURRENT, RE_ATTR_CUR_RACE, NULL, 1);
	
	return RM_SYNC | RM_NEXT_STEP;
}
示例#7
0
void NetServer::SendStartTimePacket(int &startTime)
{
	//Wait RACESTARTDELEAY seconds to start race
	m_racestarttime = GfTimeClock()+RACESTARTDELEAY;

        PackedBuffer msg;

        try
        {
                msg.pack_ubyte(RACESTARTTIME_PACKET);
                msg.pack_double(m_racestarttime);
        }
        catch (PackedBufferException &e)
        {
                GfLogFatal("SendStartTimePacket: packed buffer error\n");
        }
        GfLogTrace("SendStartTimePacket: packed data length=%d\n",
                msg.length());

	ENetPacket * pPacket = enet_packet_create (msg.buffer(), 
                                              msg.length(), 
                                              ENET_PACKET_FLAG_RELIABLE);

	BroadcastPacket(pPacket,RELIABLECHANNEL);

	GfLogInfo("Server Start time is %lf\n",m_racestarttime);
}
示例#8
0
void NetServer::SendFinishTimePacket()
{
	GfLogTrace("Sending finish Time Packet\n");
	
	NetMutexData *pNData = LockNetworkData();
	double time = pNData->m_finishTime;
	UnlockNetworkData();

	GfLogInfo("Server finish time is %lf\n",time);
        
        PackedBuffer msg;

        try
        {
                msg.pack_ubyte(FINISHTIME_PACKET);
                msg.pack_double(time);
        }
        catch (PackedBufferException &e)
        {
                GfLogFatal("SendFinishTimePacket: packed buffer error\n");
        }
        GfLogTrace("SendFinishTimePacket: packed data length=%d\n",
                msg.length());

	ENetPacket * pPacket = enet_packet_create (msg.buffer(), 
                                              msg.length(), 
                                              ENET_PACKET_FLAG_RELIABLE);
	BroadcastPacket(pPacket,RELIABLECHANNEL);
}
示例#9
0
static void
rmCarSettingsMenu(void *pMenu)
{
	int nDriverIdx = NetGetNetwork()->GetDriverIdx();

	if (nDriverIdx > -1) {
		NetDriver driver;
		// char newName[64]; Never used
		char dname[256];

		// check for car change
		GfLogInfo("Car %d changed \n", nDriverIdx);

		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);

		// Garage menu to change clients car
		GfDriver* PCurrentDriver = GfDrivers::self()->getDriver(NETWORKROBOT, idx);

		GarageMenu.setPreviousMenuHandle(racemanMenuHdle);
		GarageMenu.runMenu(LmRaceEngine().race(), PCurrentDriver);
		bGarage = true;
	}
}
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;
}
示例#11
0
const char* GfSetDataDir(const char *pszPath)
{
	if (gfDataDir)
		free(gfDataDir);
	gfDataDir = makeRunTimeDirPath(pszPath);
	GfLogInfo("Data in %s (from %s)\n", gfDataDir, pszPath);
	return gfDataDir;
}
示例#12
0
void LegacyMenu::onLapCompleted(int nLapIndex)
{

    if (nLapIndex <= 0)
        return;

    GfLogInfo("Lap #%d completed.\n", nLapIndex);
}
示例#13
0
const char* GfSetBinDir(const char *pszPath)
{
	if (gfBinDir)
		free(gfBinDir);
	gfBinDir = makeRunTimeDirPath(pszPath);
	GfLogInfo("Executables in %s (from %s)\n", gfBinDir, pszPath);
	return gfBinDir;
}
示例#14
0
void StandardGame::shutdown(void)
{
	GfLogInfo("Shutting down StandardGame race engine.\n");

	cleanup();

	delete _pRace;
}
示例#15
0
const char* GfSetLibDir(const char *pszPath)
{
	if (gfLibDir)
		free(gfLibDir);
	gfLibDir = makeRunTimeDirPath(pszPath);
	GfLogInfo("Libraries in %s (from %s)\n", gfLibDir, pszPath);
	return gfLibDir;
}
示例#16
0
const char* GfSetLocalDir(const char *pszPath)
{
	if (gfLocalDir)
		free(gfLocalDir);
	gfLocalDir = makeRunTimeDirPath(pszPath);
	GfLogInfo("User settings in %s (from %s)\n", gfLocalDir, pszPath);
	return gfLocalDir;
}
示例#17
0
static void
rmNetworkServerDisconnect(void * /* dummy */)
{
	GfLogInfo("Disconnecting all clients\n");
	if (NetGetServer())
		NetGetServer()->Disconnect();

	GfuiScreenActivate(RmRaceSelectMenuHandle);
}
示例#18
0
bool
linuxSetThreadAffinity(int nCPUId)
{
	// MacOS X, FreeBSD, OpenBSD, NetBSD, etc ...
#if defined(__APPLE__) || defined(__FreeBSD__) || defined(__OpenBSD__) || defined(__NetBSD__)
	
	GfLogWarning("Thread affinity not yet implemented on Mac OS X or BSD.\n");
	// TODO.
	
	// Linux, Solaris, AIX ... with NPTL (Native POSIX Threads Library)
#elif defined(linux) || defined(__linux__)
	
	// Get the handle for the current thread.
	pthread_t hCurrThread = pthread_self();
	
	// Determine the affinity mask to set for the current thread.
	cpu_set_t nThreadAffinityMask;
	CPU_ZERO(&nThreadAffinityMask);
	if (nCPUId == GfAffinityAnyCPU)
	{
		// No special affinity on any CPU => set "system" affinity mask
		// (1 bit for each installed CPU).
		for (int nCPUIndex = 0; (unsigned)nCPUIndex < linuxGetNumberOfCPUs(); nCPUIndex++)
		{
			CPU_SET(nCPUIndex, &nThreadAffinityMask);
		}
	}
	else
	{	
		// Affinity on a specified CPU => compute its mask.
		CPU_SET(nCPUId, &nThreadAffinityMask);
	}
	
	// Set the affinity mask for the current thread ("stick" it to the target core).
	if (pthread_setaffinity_np(hCurrThread, sizeof(nThreadAffinityMask), &nThreadAffinityMask))
	{
		GfLogError("Failed to set current pthread (handle=0x%X) affinity on CPU(s) %s (%s)\n",
				   hCurrThread, cpuSet2String(&nThreadAffinityMask).c_str(), strerror(errno));
		return false;
	}
	else
		GfLogInfo("Affinity set on CPU(s) %s for current pthread (handle=0x%X)\n",
				  cpuSet2String(&nThreadAffinityMask).c_str(), hCurrThread);
	
	return true;
	
	// Anything else ... not supported.
#else
	
#warning "linuxspec.cpp::linuxSetThreadAffinity : Unsupported Linux OS"
	GfLogWarning("Thread affinity not yet implemented on this unknown Unix.\n");
	
#endif
	
	return false;
}
示例#19
0
/* Compute Pit stop time */
void
ReCarsUpdateCarPitTime(tCarElt *car)
{
	tSituation *s = ReInfo->s;
	tReCarInfo *info = &(ReInfo->_reCarInfo[car->index]);
	tCarPenalty *penalty;
	int i;

	// GfLogDebug("ReCarsUpdateCarPitTime(%s) : typ=%d, fuel=%f, rep=%d\n",
	// 		   car->_name, car->_pitStopType, car->_pitFuel, car->_pitRepair);

	switch (car->_pitStopType) {
		case RM_PIT_REPAIR:
			info->totalPitTime = 2.0f + fabs((double)(car->_pitFuel)) / 8.0f + (tdble)(fabs((double)(car->_pitRepair))) * 0.007f;
			car->_scheduledEventTime = s->currentTime + info->totalPitTime;
			RePhysicsEngine().reconfigureCar(car);

			for (i=0; i<4; i++) {
				car->_tyreCondition(i) = 1.01f;
				car->_tyreT_in(i) = 50.0f;
				car->_tyreT_mid(i) = 50.0f;
				car->_tyreT_out(i) = 50.0f;
			}
			GfLogInfo("%s in repair pit stop for %.1f s (refueling by %.1f l, repairing by %d).\n",
					  car->_name, info->totalPitTime, car->_pitFuel, car->_pitRepair);
			break;
		case RM_PIT_STOPANDGO:
			penalty = GF_TAILQ_FIRST(&(car->_penaltyList));
			if (penalty && penalty->penalty == RM_PENALTY_10SEC_STOPANDGO)
				info->totalPitTime = 10.0;
			else
				info->totalPitTime = 0.0;
			car->_scheduledEventTime = s->currentTime + info->totalPitTime;

			// Prevent car->_state & RM_CAR_STATE_PIT from being true for a too short delay,
			// in order for the penalty management to detect it.
			if (car->_scheduledEventTime < s->currentTime + RCM_MAX_DT_SIMU)
				car->_scheduledEventTime += RCM_MAX_DT_SIMU;
														 
			GfLogInfo("%s in Stop-and-Go pit stop for %.1f s.\n", car->_name, info->totalPitTime);
			break;
	}
}
示例#20
0
/*
 * Function
 *	linuxModLoad
 *
 * Description
 *	Load the module of given shared library file
 *	(Load the shared library, then retrieve info about the module (tModInfo struct) ;
 *	 the library is NOT unloaded).
 *
 * Parameters
 *	sopath  (in)     path of the shared library file to load
 *	modlist	(in/out) list of module interfaces description structure (may begin empty)
 *
 * Return
 *	0	Ok
 *	-1	error
 *
 * Remarks
 *	* Nothing done if a module with equal shared library file path-name
 *	  already exists in modlist (WARNING: if same shared library file, but with different 
 *	  path-names, like with an absolute and a relative one, the module is loaded again !)
 *	* The loaded module info structure is added at the HEAD of the list (**modlist)
 *	  (not added, but only moved to HEAD, if a module with equal shared library file path-name
 *	   already exists in modlist).
 *	
 */
static int
linuxModLoad(unsigned int /* gfid */, const char *sopath, tModList **modlist)
{
	tSOHandle handle;
	tModList* curMod;
	
	/* Try and avoid loading the same module twice (WARNING: Only checks sopath equality !) */
	if ((curMod = GfModIsInList(sopath, *modlist)) != 0)
	{
		GfLogInfo("Module %s already loaded\n", sopath);
		GfModMoveToListHead(curMod, modlist); // Force module to be the first in the list.
		return 0;
	}
	
	GfLogInfo("Loading module %s\n", sopath);
	
	/* Load the shared library */
	handle = dlopen(sopath, RTLD_LAZY);
	if (handle)
	{
		/* Initialize the module */
		if (GfModInitialize(handle, sopath, GfIdAny, &curMod) == 0)
		{
			if (curMod) /* Retained against GfIdAny */
				// Add the loaded module at the head of the list (no sort by priority).
				GfModAddInList(curMod, modlist, /* priosort */ 0);
		}
		else 
		{
			dlclose(handle);
			GfLogError("linuxModLoad: Module init function failed %s\n", sopath);
			return -1;
		}
	}
	else
	{
		GfLogError("linuxModLoad: ...  %s\n", dlerror());
		return -1;
	}
	
	return 0;
}
示例#21
0
double NetServer::WaitForRaceStart()
{
	int startTime;
	SendStartTimePacket(startTime);
	GfLogInfo("Server waiting to start the race\n");


	double time = GfTimeClock()-m_racestarttime;

	return time;
}
示例#22
0
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;
}
示例#23
0
int
ReNetworkWaitReady()
{
	// No wait if not an online race.
	if (!NetGetNetwork())
		return RM_SYNC | RM_NEXT_STEP;

	// If network race, wait for other players and start when the server tells to
	bool bWaitFinished = false;
	if (NetGetClient())
	{
		NetGetClient()->SendReadyToStartPacket();
		ReInfo->s->currentTime = NetGetClient()->WaitForRaceStart();
		GfLogInfo("Client beginning race in %lf seconds!\n", - ReInfo->s->currentTime);
		bWaitFinished = true;
	}
	
	else if (NetGetServer())
	{
		if (NetGetServer()->ClientsReadyToRace())
		{
			ReInfo->s->currentTime = NetGetServer()->WaitForRaceStart();
			GfLogInfo("Server beginning race in %lf seconds!\n", - ReInfo->s->currentTime);
			bWaitFinished = true;
		}
	}

	if (bWaitFinished)
	{
		ReSituation::self().setRaceMessage("", -1/*always*/, /*big=*/true);
		return RM_SYNC | RM_NEXT_STEP;
	}
	else
	{
		ReSituation::self().setRaceMessage("Waiting for online players",
										   -1/*always*/, /*big=*/true);
		return RM_ASYNC;
	}
}
示例#24
0
bool LegacyMenu::onRaceEventStarting(bool careerNonHumanGroup)
{
    tRmInfo* pReInfo = _piRaceEngine->inData();
    if (GfParmGetEltNb(pReInfo->params, RM_SECT_TRACKS) > 1)
	{
        if (!careerNonHumanGroup)
		{
            ::RmNextEventMenu();

            return false; // Tell the race engine state automaton to stop looping (enter the menu).
        }
		else
		{
            GfLogInfo("Not starting Next Event menu, because there is no human in the race");
            return true;
        }
    }

    GfLogInfo("Not starting Next Event menu, as only one track to race on.\n");

    return true; // Tell the race engine state automaton to go on looping.
}
static void
rmToggleMovieCapture(void * /* dummy */)
{
    if (!rmMovieCapture.enabled) 
    {
		GfLogWarning("Movie capture is not enabled : command ignored\n");
		return;
    }
    
    if (!(LmRaceEngine().outData()->_displayMode & RM_DISP_MODE_NORMAL))
    {
		GfLogWarning("Movie capture is available only in normal display mode : command ignored\n");
		return;
    }
    
    rmMovieCapture.active = !rmMovieCapture.active;
    if (rmMovieCapture.active)
	{
		// Try and change the race engine scheduling scheme for movie capture.
		if (LmRaceEngine().setSchedulingSpecs(rmMovieCapture.simuRate, rmMovieCapture.frameRate))
		{
			rmMovieCapture.currentFrame = 0;
			rmMovieCapture.currentCapture++;
			GfLogInfo("Starting movie capture\n");
		}
		else
		{
			// Not supported (multi-threaded mode).
			rmMovieCapture.active = false;
			GfLogWarning("Movie capture not supported in multi-threaded mode : command ignored\n");
		}
    }
	else
	{
		GfLogInfo("Stopping movie capture\n");
		LmRaceEngine().setSchedulingSpecs(1.0 / RCM_MAX_DT_SIMU);
		LmRaceEngine().start(); // Resynchronize the race engine.
    }
}
示例#26
0
/*
* Function
*	linuxGetNumberOfCPUs
*
* Description
*	Retrieve the actual number of CPUs in the system
*       Note that a core is considered here as a "CPU", and an Intel hyper-threaded processor
*       will report twice as many "CPUs" as actual cores ...
*
* Parameters
*	None
*
* Return
*	The number of CPUs in the system
*
* Remarks
*       WARNING: Not tested under platforms other than Linux : Mac OS X, BSD, Solaris, AIX.
*	
*/
unsigned linuxGetNumberOfCPUs()
{
	static unsigned nCPUs = 0;
	
	if (nCPUs == 0)
	{
		
		// MacOS X, FreeBSD, OpenBSD, NetBSD, etc ...
#if defined(__APPLE__) || defined(__FreeBSD__) || defined(__OpenBSD__) || defined(__NetBSD__)
		
		nt mib[4];
		size_t len; 
		
		// Set the mib for hw.ncpu
		
		// Get the number of CPUs from the system
		// 1) Try HW_AVAILCPU first.
		mib[0] = CTL_HW;
		mib[1] = HW_AVAILCPU;  // alternatively, try HW_NCPU;
		sysctl(mib, 2, &nCPUs, &len, NULL, 0);
		
		if (nCPUs < 1) 
		{
			// 2) Try alternatively HW_NCPU.
			mib[1] = HW_NCPU;
			sysctl(mib, 2, &nCPUs, &len, NULL, 0);
		}
		
		// Linux, Solaris, AIX
#elif defined(linux) || defined(__linux__)
		
		nCPUs = (unsigned)sysconf(_SC_NPROCESSORS_ONLN);
		
		// Anything else ... not supported.
#else
		
#warning "Unsupported Linux OS"
		
#endif
		
		if (nCPUs < 1)
		{
			GfLogWarning("Could not get the number of CPUs here ; assuming only 1\n");
			nCPUs = 1;
		}
		else
			GfLogInfo("Detected %d CPUs\n", nCPUs);
	}
	
	return nCPUs;
}
static void
rmInitMovieCapture()
{
	// Don't do it twice.
	if (rmMovieCapture.outputBase)
		return;

	// But do it the first time.
	char buf[256];
	snprintf(buf, sizeof(buf), "%s%s", GfLocalDir(), RACE_ENG_CFG);

	void* hparmRaceEng = GfParmReadFile(buf, GFPARM_RMODE_REREAD | GFPARM_RMODE_CREAT);

	rmMovieCapture.enabled =
		strcmp(GfParmGetStr(hparmRaceEng, RM_SECT_MOVIE_CAPTURE, RM_ATT_CAPTURE_ENABLE,
							RM_VAL_NO),
			   RM_VAL_NO) ? true : false;
	rmMovieCapture.active = false;
	if (!rmMovieCapture.enabled)
	{
		rmMovieCapture.outputBase = 0;
		GfLogInfo("Movie capture disabled (see raceengine.xml)\n");
	}
	else
	{
		rmMovieCapture.frameRate =
			GfParmGetNum(hparmRaceEng, RM_SECT_MOVIE_CAPTURE, RM_ATT_CAPTURE_FPS, NULL, 25.0);
		rmMovieCapture.simuRate = 1.0 / RCM_MAX_DT_SIMU;
		char pszDefOutputBase[256];
		snprintf(pszDefOutputBase, sizeof(pszDefOutputBase), "%s%s",
				 GfLocalDir(), GfParmGetStr(hparmRaceEng, RM_SECT_MOVIE_CAPTURE,
											RM_ATT_CAPTURE_OUT_DIR, "captures"));
		rmMovieCapture.outputBase = strdup(pszDefOutputBase);
		GfDirCreate(pszDefOutputBase); // In case not already done.
		GfLogInfo("Movie capture enabled (%.0f FPS, PNG frames in %s)\n", 
				  rmMovieCapture.frameRate, rmMovieCapture.outputBase);
	}
}
示例#28
0
void ReSituationUpdater::stop()
{
	GfLogInfo("Stopping race engine.\n");

	// Lock the race engine data.
	ReSituation::self().lock("ReSituationUpdater::stop");

	// Reset the running flags.
	ReSituation::self().data()->_reRunning = 0;
	ReSituation::self().data()->s->_raceState |= RM_RACE_PAUSED;
		
	// Unlock the race engine data.
	ReSituation::self().unlock("ReSituationUpdater::stop");
}
示例#29
0
/* Prepare to open the pit menu when back in the main updater (thread) */
static void
reCarsSchedulePitMenu(tCarElt *car)
{
	// Do nothing if one car is already scheduled for the pit menu
	// (this one will have to wait for the current one exiting from the menu)
	if (ReInfo->_rePitRequester)
	{
		GfLogInfo("%s would like to pit, but the pit menu is already in use.\n", car->_name);
		return;
	}

	// Otherwise, "post" a pit menu request for this car.
	ReInfo->_rePitRequester = car;
}
示例#30
0
void SDScreens::changeScreen(long p)
{
    switch (p) 
    {
        case SD_NEXT_SCREEN:
            m_CurrentScreenIndex = (m_CurrentScreenIndex + 1) % m_NbActiveScreens;
            break;
        case SD_PREV_SCREEN:
            m_CurrentScreenIndex = (m_CurrentScreenIndex - 1 + m_NbActiveScreens) % m_NbActiveScreens;
            break;
    }
    
    GfLogInfo("Changing current screen to #%d (out of %d)\n", m_CurrentScreenIndex, m_NbActiveScreens);
}