Ejemplo n.º 1
0
/** 
 * GfTracks::getFirstUsableTrack
 * 
 * Retrieve the first usable track in the given category, searching in the given direction
 * and skipping the first found if specified
 * 
 * @param   strCatId       Id of the category to search inside of.
 * @param   strFromTrackId Id of the track from which to start the search.
 * @param   nSearchDir     <0 = previous, >0 = next.
 * @param   bSkipFrom      If true, skip the first found track.
 */
GfTrack* GfTracks::getFirstUsableTrack(const std::string& strCatId,
									   const std::string& strFromTrackId,
									   int nSearchDir, bool bSkipFrom) const
{
	// Check and fix nSearchDir.
	nSearchDir = nSearchDir > 0 ? +1 : -1;
	
	// Check category.
	if (!strCatId.empty()
		&& std::find(_pPrivate->vecCatIds.begin(), _pPrivate->vecCatIds.end(), strCatId)
		   == _pPrivate->vecCatIds.end())
	{
		GfLogError("GfTracks::getFirstUsableTrack(1) : No such category %s\n", strCatId.c_str());
		return 0;
	}

	// Retrieve tracks in this category.
	const std::vector<GfTrack*> vecTracksInCat = getTracksInCategory(strCatId);
	if (vecTracksInCat.size() == 0)
	{
		// Should never happen, empty categories are not even created ...
		GfLogError("GfTracks::getFirstUsableTrack : Empty category %s\n", strCatId.c_str());
		return 0;
	}
	
	// Retrieve the index of the specified track to start from, if any.
	int nCurTrackInd = 0;
	if (!strFromTrackId.empty())
	{
		std::vector<GfTrack*>::const_iterator itTrack = vecTracksInCat.begin();
		while (itTrack != vecTracksInCat.end())
		{
			if ((*itTrack)->getId() == strFromTrackId)
			{
				nCurTrackInd = itTrack - vecTracksInCat.begin();
				break;
			}
			itTrack++;
		}
	}
	
	int nTrackInd = nCurTrackInd;
	if (bSkipFrom || !vecTracksInCat[nTrackInd]->isUsable())
	{
		const int nPrevTrackInd = nCurTrackInd;
		do
		{
			nTrackInd =
				(nTrackInd + nSearchDir + vecTracksInCat.size()) % vecTracksInCat.size();
		}
		while (nTrackInd != nPrevTrackInd && !vecTracksInCat[nTrackInd]->isUsable());
	}

	GfTrack* pTrack = 0;
	if (vecTracksInCat[nTrackInd]->isUsable())
		pTrack = vecTracksInCat[nTrackInd];

	return pTrack;
}
Ejemplo n.º 2
0
GfModule* GfModule::load(const std::string& strShLibName)
{
	// Don't load shared libraries twice
	// Warning: Only checked through the give nlibrary file path-name ...
	if (_mapModulesByLibName.find(strShLibName) != _mapModulesByLibName.end())
	{
		GfLogDebug("Not re-loading module %s (already done)\n", strShLibName.c_str());
		return _mapModulesByLibName[strShLibName];
	}

	// Try and open the shared library.
	void* hSOLib = dlopen(strShLibName.c_str());
	if (!hSOLib)
	{
		GfLogError("Failed to load library %s (%s)\n",
				   strShLibName.c_str(), lastDLErrorString().c_str());
		return 0;
	}

	// Try and get the module opening function.
	tModOpenFunc modOpenFunc = (tModOpenFunc)dlsym(hSOLib, pszOpenModuleFuncName);
    if (!modOpenFunc)
    {
		GfLogError("Library %s doesn't export any '%s' function' ; module NOT loaded\n",
				   strShLibName.c_str(), pszOpenModuleFuncName);
		(void)dlclose(hSOLib);
		return 0;
	}

	// Call the module opening function (must instanciate the module and register_ it on success).
	if (modOpenFunc(strShLibName.c_str(), hSOLib))
	{
		GfLogError("Library %s '%s' function call failed ; module NOT loaded\n",
				   strShLibName.c_str(), pszOpenModuleFuncName);
		(void)dlclose(hSOLib);
		return 0;
	}

	// Check if the module was successfully register_ed.
	if (_mapModulesByLibName.find(strShLibName) == _mapModulesByLibName.end())
	{
		GfLogError("Library %s '%s' function failed to register the open module ; NOT loaded\n",
				   strShLibName.c_str(), pszOpenModuleFuncName);
		(void)dlclose(hSOLib);
		return 0;
	}

	// Yesssss !
	GfLogTrace("Module %s loaded\n", strShLibName.c_str());

	return _mapModulesByLibName[strShLibName];
}
Ejemplo n.º 3
0
/*
 * Function
 *	linuxModInfo
 *
 * Description
 *	Retrieve info about the module of given shared library file,
 *	(Load the shared library, then retrieve info about the module (tModInfo struct),
 *	 and finally unload the library).
 *
 * 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
linuxModInfo(unsigned int /* gfid */, const char *sopath, tModList **modlist)
{
	tSOHandle handle;
	tModList *curMod;
	int       infoSts = 0;
	
	/* Try and avoid loading the same module twice (WARNING: Only checks sopath equality !) */
	if ((curMod = GfModIsInList(sopath, *modlist)) != 0)
	{
		GfLogInfo("Module %s already requested\n", sopath);
		GfModMoveToListHead(curMod, modlist); // Force module to be the first in the list.
		return infoSts;
	}
	
	GfLogTrace("Querying 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);
			}
			
			/* Terminate the module */
			infoSts = GfModTerminate(handle, sopath);
		} 
		else 
		{
			GfLogError("linuxModInfo: Module init function failed %s\n", sopath);
			infoSts = -1;
		}
		
		/* Close the DLL whatever happened */
		dlclose(handle);
	} 
	else 
	{
		GfLogError("linuxModInfo: ...  %s\n", dlerror());
		infoSts = -1;
	}
	
	return infoSts;
}
Ejemplo n.º 4
0
bool LegacyMenu::startRace()
{
    // Get the race to start.
    std::string strRaceToStart;
    if (!GfApp().hasOption("startrace", strRaceToStart))
        return false;

    // And run it if there's such a race manager.
    GfRaceManager* pSelRaceMan = GfRaceManagers::self()->getRaceManager(strRaceToStart);
    if (pSelRaceMan) // Should never happen (checked in activate).
    {
        // Initialize the race engine.
        LmRaceEngine().reset();

        // Give the selected race manager to the race engine.
        LmRaceEngine().selectRaceman(pSelRaceMan);

        // Configure the new race (but don't enter the config. menu tree).
        LmRaceEngine().configureRace(/* bInteractive */ false);

        // Start the race engine state automaton
        LmRaceEngine().startNewRace();
    }
	else
	{
        GfLogError("No such race type '%s'\n", strRaceToStart.c_str());

        return false;
    }

    return true;
}
Ejemplo n.º 5
0
/* Free the module interfaces info array */
void GfModInfoFree(tModInfo *array)
{
    if (!array)
		GfLogError("GfModInfoFree: Null pointer\n");

	free(array);
}
Ejemplo n.º 6
0
/* Free the module interfaces info array */
void GfModInfoFreeNC(tModInfoNC *array, int maxItf)
{
    int itfInd;

    if (!array)
    {
		GfLogError("GfModInfoFreeNC: Null pointer\n");
		return;
    }

	for( itfInd = 0; itfInd < maxItf + 1; ++itfInd )
	{
		// Note: the the last item in the list is the template
		//       for the "generated" instances of robots.
 		if( !array[itfInd].name )
		{
			if( itfInd >= maxItf )
				break;
			//Go to the last item of the list
			itfInd = maxItf - 1;
			continue;
		}
		if (array[itfInd].name)
			free(array[itfInd].name);
		if (array[itfInd].desc)
			free(array[itfInd].desc);
	}
	
	free(array);
}
Ejemplo n.º 7
0
void NetClient::SendReadyToStartPacket()
{

    std::string strDName = GetDriverName();
    GfLogTrace("Sending ready to start packet\n");

    PackedBuffer msg;

    try
    {
        msg.pack_ubyte(CLIENTREADYTOSTART_PACKET);
        msg.pack_stdstring(strDName);
    }
//    catch (PackedBufferException &e)
    catch (PackedBufferException)
    {
        GfLogFatal("SendReadyToStartPacket: packed buffer error\n");
    }
    GfLogTrace("SendReadyToStartPacket: packed data length=%d\n",
            msg.length());

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

    if (enet_peer_send (m_pServer, RELIABLECHANNEL, pPacket))
        GfLogError("SendReadyToStartPacket : enet_peer_send failed\n");
}
Ejemplo n.º 8
0
void NetClient::SendServerTimeRequest()
{
    m_packetsendtime = GfTimeClock(); 

    PackedBuffer msg;

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


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

    if (enet_peer_send (m_pServer, UNRELIABLECHANNEL, pPacket))
        GfLogError("SendServerTimeRequest : enet_peer_send failed\n");
}
Ejemplo n.º 9
0
int GfuiMenuScreen::createImageButtonControl(const char* pszName,
											 void* userDataOnPush, tfuiCallback onPush,
											 void* userDataOnFocus, tfuiCallback onFocus, tfuiCallback onFocusLost,
											 bool bFromTemplate,
											 const char* tip,
											 int x, int y, int width, int height)
{
	if (!m_priv->xmlDescParmHdle && !openXMLDescriptor())
		return -1;
	
	if (m_priv->mapControlIds.find(pszName) == m_priv->mapControlIds.end())
	{
		const int nCtrlId =
			::GfuiMenuCreateImageButtonControl(m_priv->menuHdle, m_priv->xmlDescParmHdle, pszName,
											   userDataOnPush, onPush,
											   userDataOnFocus, onFocus, onFocusLost,
											   bFromTemplate,
											   tip, x, y, width, height);
		if (nCtrlId >= 0)
			m_priv->mapControlIds[pszName] = nCtrlId;

		return nCtrlId;
	}

	GfLogError("Failed to create image button control '%s' : duplicate name\n", pszName);
	return -1;
}
Ejemplo n.º 10
0
int GfuiMenuScreen::createTextButtonControl(const char* pszName, void* userDataOnPush,
											tfuiCallback onPush,
											void* userDataOnFocus, tfuiCallback onFocus,
											tfuiCallback onFocusLost,
											bool bFromTemplate,
											const char* tip, const char* text,
											int x, int y, int width, int font, int textHAlign, 
											const float* fgColor, const float* fgFocusColor, const float* fgPushedColor)
{
	if (!m_priv->xmlDescParmHdle && !openXMLDescriptor())
		return -1;
	
	if (m_priv->mapControlIds.find(pszName) == m_priv->mapControlIds.end())
	{
		const int nCtrlId =
			::GfuiMenuCreateTextButtonControl(m_priv->menuHdle, m_priv->xmlDescParmHdle, pszName,
											  userDataOnPush, onPush,
											  userDataOnFocus, onFocus, onFocusLost,
											  bFromTemplate,
											  text, tip, x, y, width, font, textHAlign,
											  fgColor, fgFocusColor, fgPushedColor);
		if (nCtrlId >= 0)
			m_priv->mapControlIds[pszName] = nCtrlId;

		return nCtrlId;
	}

	GfLogError("Failed to create text button control '%s' : duplicate name\n", pszName);
	return -1;
}
Ejemplo n.º 11
0
void cgrMultiTexState::setTexScheme(tfnTexScheme fnTexScheme)
{
	_fnTexScheme = fnTexScheme;
	
	if (!_fnTexScheme)
		GfLogError("cgrMultiTexState MUST be provided a texturing scheme function\n");
}
Ejemplo n.º 12
0
/**
 * Copies something of type tModList into something of type tModListNC
 * This function allocates new space for parts of tModList that are const.
 * @param constArray The source tModList
 * @param maxItf     The max number of interfaces of the module
 */
tModInfoNC *GfModInfoDuplicate(const tModInfo *constArray, int maxItf)
{
    int itfInd;

    // Allocate target array.
    tModInfoNC *array = (tModInfoNC*)calloc(maxItf + 1, sizeof(tModInfoNC));
    if (!constArray)
        GfLogError("GfModInfoAllocate: Failed to allocate tModInfoNC array (maxItf=%d)\n", maxItf);

    // Copy constArray to array (null name indicates unused interface = end of useful array).
    memset(array, 0, (maxItf+1)*sizeof(tModInfo));
    for( itfInd = 0; itfInd < maxItf + 1; ++itfInd )
    {
		// Note: the the last item in the list is the template
		//       for the "generated" instances of robots.
        if( !constArray[itfInd].name )
		{
			if( itfInd >= maxItf )
				break;
			// Go to the last item of the list
			itfInd = maxItf - 1;
			continue;
		}
        array[itfInd].name    = constArray[itfInd].name ? strdup(constArray[itfInd].name) : 0;
        array[itfInd].desc    = constArray[itfInd].desc ? strdup(constArray[itfInd].desc) : 0;
        array[itfInd].fctInit = constArray[itfInd].fctInit;
        array[itfInd].gfId    = constArray[itfInd].gfId;
        array[itfInd].index   = constArray[itfInd].index;
        array[itfInd].prio    = constArray[itfInd].prio;
        array[itfInd].magic   = constArray[itfInd].magic;
    }

    return array;
}
Ejemplo n.º 13
0
void ReSituation::setPitCommand(int nCarIndex, const tCarPitCmd *pPitCmd)
{
	lock("updateCarPitCmd");

	// Retrieve the car in situation with 'nCarIndex' index.
	//GfLogDebug("ReSituation::updateCarPitCmd(i=%d)\n", nCarIndex);
	tCarElt* pCurrCar = 0;
	for (int nCarInd = 0; nCarInd < _pReInfo->s->_ncars; nCarInd++)
	{
		if (_pReInfo->s->cars[nCarInd]->index == nCarIndex)
		{
			// Found : update its pit command information from pit menu data.
			pCurrCar = _pReInfo->s->cars[nCarInd];
			pCurrCar->_pitFuel = pPitCmd->fuel;
			pCurrCar->_pitRepair = pPitCmd->repair;
			pCurrCar->_pitStopType = pPitCmd->stopType;
			break;
		}
	}
	
	// Compute and set pit time.
	if (pCurrCar)
		ReCarsUpdateCarPitTime(pCurrCar);
	else
		GfLogError("Failed to retrieve car with index %d when computing pit time\n", nCarIndex);
	
	unlock("setRaceMessage");
}
Ejemplo n.º 14
0
static int 
createImageButton(void* hscr, void* hparm, const char* pszPath,
				  void* userDataOnPush, tfuiCallback onPush,
				  void* userDataOnFocus, tfuiCallback onFocus, tfuiCallback onFocusLost,
				  bool bFromTemplate = false,
				  const char* tip = GFUI_TPL_TIP,
				  int x = GFUI_TPL_X, int y = GFUI_TPL_Y,
				  int width = GFUI_TPL_WIDTH, int height = GFUI_TPL_HEIGHT)
{
	if (strcmp(GfParmGetStr(hparm, pszPath, GFMNU_ATTR_TYPE, ""), GFMNU_TYPE_IMAGE_BUTTON))
	{
		GfLogError("Failed to create image button control '%s' : section not found or not an '%s'\n",
				   pszPath, GFMNU_TYPE_IMAGE_BUTTON);
		return -1;
	}
        
	const char* pszTip =
		bFromTemplate && tip != GFUI_TPL_TIP
		? tip : GfParmGetStr(hparm, pszPath, GFMNU_ATTR_TIP, "");
	const int nX = 
		bFromTemplate && x != GFUI_TPL_X
		? x : (int)GfParmGetNum(hparm, pszPath, GFMNU_ATTR_X, NULL, 0);
	const int nY = 
		bFromTemplate && y != GFUI_TPL_Y
		? y : (int)GfParmGetNum(hparm, pszPath, GFMNU_ATTR_Y, NULL, 0);
	int nWidth = 
		bFromTemplate && width != GFUI_TPL_WIDTH
		? width : (int)GfParmGetNum(hparm, pszPath, GFMNU_ATTR_WIDTH, NULL, 0);
	int nHeight = 
		bFromTemplate && height != GFUI_TPL_HEIGHT
		? height : (int)GfParmGetNum(hparm, pszPath, GFMNU_ATTR_HEIGHT, NULL, 0);

	if (strlen(pszTip) > 0)
	{
		tMenuCallbackInfo * cbinfo = (tMenuCallbackInfo*)calloc(1, sizeof(tMenuCallbackInfo));
		cbinfo->screen = hscr;
		cbinfo->labelId = GfuiTipCreate(hscr, pszTip, strlen(pszTip));
		GfuiVisibilitySet(hscr, cbinfo->labelId, GFUI_INVISIBLE);

		// TODO: In this case, we crudely overwrite onFocus/onFocusLost !
		userDataOnFocus = (void*)cbinfo;
		onFocus = onFocusShowTip;
		onFocusLost = onFocusLostHideTip;
	}

	const char* pszDisabledImage = GfParmGetStr(hparm, pszPath, GFMNU_ATTR_IMAGE_DISABLED, "");
	const char* pszEnabledImage = GfParmGetStr(hparm, pszPath, GFMNU_ATTR_IMAGE_ENABLED, "");
	const char* pszFocusedImage = GfParmGetStr(hparm, pszPath, GFMNU_ATTR_IMAGE_FOCUSED, "");
	const char* pszPushedImage = GfParmGetStr(hparm, pszPath, GFMNU_ATTR_IMAGE_PUSHED, "");

	int butId =
		GfuiGrButtonCreate(hscr,
						   pszDisabledImage, pszEnabledImage, pszFocusedImage, pszPushedImage,
						   nX, nY, nWidth, nHeight, GFUI_MIRROR_NONE, true, GFUI_MOUSE_UP,
						   userDataOnPush, onPush,
						   userDataOnFocus, onFocus, onFocusLost);

	return butId;
}
Ejemplo n.º 15
0
/* Allocate the module interfaces info array */
tModInfo *GfModInfoAllocate(int maxItf)
{
    tModInfo *array = (tModInfo*)calloc(maxItf+1, sizeof(tModInfo));
    if (!array)
        GfLogError("GfModInfoAllocate: Failed to allocate tModInfo array (maxItf=%d)\n", maxItf);

    return array;
}
Ejemplo n.º 16
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;
}
Ejemplo n.º 17
0
int 
GfuiMenuCreateEditControl(void* hscr, void* hparm, const char* pszName,
						  void* userDataOnFocus, tfuiCallback onFocus, tfuiCallback onFocusLost)
{
	std::string strControlPath(GFMNU_SECT_DYNAMIC_CONTROLS"/");
	strControlPath += pszName;

	const char* pszType = GfParmGetStr(hparm, strControlPath.c_str(), GFMNU_ATTR_TYPE, "");
	if (strcmp(pszType, GFMNU_TYPE_EDIT_BOX))
	{
		GfLogError("Failed to create control '%s' : section not found or not an '%s' \n",
				   pszName, GFMNU_TYPE_EDIT_BOX);
		return -1;
	}

	// TODO : Add real support for tips (the onFocus/onFocusLost system is already used
	//        for user input management)
	//         const char* pszTip = GfParmGetStr(hparm, pszName, GFMNU_ATTR_TIP, "");
	//         if (strlen(pszTip) > 0)
	//         {
	//                 tMenuCallbackInfo * cbinfo = (tMenuCallbackInfo*)calloc(1, sizeof(tMenuCallbackInfo));
	//                 cbinfo->screen = hscr;
	//                 cbinfo->labelId = GfuiTipCreate(hscr, pszTip, strlen(pszTip));
	//                 GfuiVisibilitySet(hscr, cbinfo->labelId, GFUI_INVISIBLE);
	//
	//                 // TODO: In this case, we simply ignore onFocus/onFocusLost !
	//                 userDataOnFocus = (void*)cbinfo;
	//                 onFocus = onFocusShowTip;
	//                 onFocusLost = onFocusLostHideTip;
	//         }

	const char* pszText = GfParmGetStr(hparm, strControlPath.c_str(), GFMNU_ATTR_TEXT, "");
	const int x = (int)GfParmGetNum(hparm, strControlPath.c_str(), GFMNU_ATTR_X, NULL, 0.0);
	const int y = (int)GfParmGetNum(hparm, strControlPath.c_str(), GFMNU_ATTR_Y, NULL, 0.0);
	const char* pszFontName = GfParmGetStr(hparm, strControlPath.c_str(), GFMNU_ATTR_FONT, "");
	const int font = gfuiMenuGetFontId(pszFontName);
	const int width = (int)GfParmGetNum(hparm, strControlPath.c_str(), GFMNU_ATTR_WIDTH, NULL, 0.0);
	const int maxlen = (int)GfParmGetNum(hparm, strControlPath.c_str(), GFMNU_ATTR_MAX_LEN, NULL, 0.0);
	const char* pszAlignH = GfParmGetStr(hparm, strControlPath.c_str(), GFMNU_ATTR_H_ALIGN, "");
	const int align = gfuiMenuGetAlignment(pszAlignH);

	const GfuiColor c = getControlColor(hparm, strControlPath.c_str(), GFMNU_ATTR_COLOR);
	const GfuiColor fc = getControlColor(hparm, strControlPath.c_str(), GFMNU_ATTR_COLOR_FOCUSED);
	const GfuiColor dc = getControlColor(hparm, strControlPath.c_str(), GFMNU_ATTR_COLOR_DISABLED);
	const GfuiColor bc = getControlColor(hparm, strControlPath.c_str(), GFMNU_ATTR_BG_COLOR);
	const GfuiColor bfc = getControlColor(hparm, strControlPath.c_str(), GFMNU_ATTR_BG_COLOR_FOCUSED);
	const GfuiColor bdc = getControlColor(hparm, strControlPath.c_str(), GFMNU_ATTR_BG_COLOR_DISABLED);

	int id = GfuiEditboxCreate(hscr, pszText, font, x, y, width, maxlen, align,
							   userDataOnFocus, onFocus, onFocusLost);

	GfuiEditboxSetColors(hscr, id, c, fc, dc);
	GfuiEditboxSetBGColors(hscr, id, bc, bfc, bdc);

	return id;
}
Ejemplo n.º 18
0
NetServer::NetServer()
{
	if (enet_initialize () != 0)
    {
        GfLogError ("An error occurred while initializing ENet.\n");
		assert(false);
    }

	m_strClass = "server";
}
Ejemplo n.º 19
0
GfuiEventLoop& GfuiApplication::eventLoop()
{
	if (!_pEventLoop)
	{
		GfLogError("GfuiApplication has no event loop ; exiting\n");
		exit(1);
	}
	
    return *dynamic_cast<GfuiEventLoop*>(_pEventLoop);
}
Ejemplo n.º 20
0
int 
GfuiMenuCreateProgressbarControl(void* hscr, void* hparm, const char* pszName)
{
	std::string strControlPath(GFMNU_SECT_DYNAMIC_CONTROLS"/");
	strControlPath += pszName;
	
	const std::string strType = GfParmGetStr(hparm, strControlPath.c_str(), GFMNU_ATTR_TYPE, "");
	if (strType != GFMNU_TYPE_PROGRESS_BAR)
	{
		GfLogError("Failed to create control '%s' : section not found or not an '%s' \n",
				   pszName, GFMNU_TYPE_PROGRESS_BAR);
		return -1;
	}
	
	const char* pszImage =
		GfParmGetStr(hparm, strControlPath.c_str(), GFMNU_ATTR_IMAGE, "data/img/progressbar.png");
	const char* pszBgImage =
		GfParmGetStr(hparm, strControlPath.c_str(), GFMNU_ATTR_BG_IMAGE, "data/img/progressbar-bg.png");
	
	const float* aOutlineColor = 0;
	const GfuiColor color = getControlColor(hparm, strControlPath.c_str(), GFMNU_ATTR_COLOR);
	if (color.alpha)
		aOutlineColor = color.toFloatRGBA();

	const int x = (int)GfParmGetNum(hparm, strControlPath.c_str(), GFMNU_ATTR_X, NULL, 0.0);
	const int y = (int)GfParmGetNum(hparm, strControlPath.c_str(), GFMNU_ATTR_Y, NULL, 0.0);
	const int w = (int)GfParmGetNum(hparm, strControlPath.c_str(), GFMNU_ATTR_WIDTH, NULL, 100.0);
	const int h = (int)GfParmGetNum(hparm, strControlPath.c_str(), GFMNU_ATTR_HEIGHT, NULL, 20.0);
	
	const float min = GfParmGetNum(hparm, strControlPath.c_str(), GFMNU_ATTR_MIN, NULL, 0.0);
	const float max = GfParmGetNum(hparm, strControlPath.c_str(), GFMNU_ATTR_MAX, NULL, 100.0);
	const float value = GfParmGetNum(hparm, strControlPath.c_str(), GFMNU_ATTR_VALUE, NULL, 50.0);
	
	const char* pszTip = GfParmGetStr(hparm, strControlPath.c_str(), GFMNU_ATTR_TIP, "");
	
	void* userDataOnFocus = 0;
	tfuiCallback onFocus = 0;
	tfuiCallback onFocusLost = 0;
	if (strlen(pszTip) > 0)
	{
		tMenuCallbackInfo * cbinfo = (tMenuCallbackInfo*)calloc(1, sizeof(tMenuCallbackInfo));
		cbinfo->screen = hscr;
		cbinfo->labelId = GfuiTipCreate(hscr, pszTip, strlen(pszTip));
		GfuiVisibilitySet(hscr, cbinfo->labelId, GFUI_INVISIBLE);
		
		userDataOnFocus = (void*)cbinfo;
		onFocus = onFocusShowTip;
		onFocusLost = onFocusLostHideTip;
	}

	int id = GfuiProgressbarCreate(hscr, x, y, w, h, pszBgImage, pszImage, aOutlineColor,
								   min, max, value, userDataOnFocus, onFocus, onFocusLost);
	
	return id;
}
Ejemplo n.º 21
0
NetClient::NetClient()
{
    if (enet_initialize () != 0)
        GfLogError ("An error occurred while initializing ENet.\n");

    m_strClass = "client";
    m_pServer = NULL;
    m_pClient = NULL;
    m_pHost = NULL;
    m_eClientAccepted = PROCESSINGCLIENT;
}
Ejemplo n.º 22
0
bool GfTrack::load() const
{
	// Check if the track loader is ready.
	ITrackLoader* piTrackLoader = GfTracks::self()->getTrackLoader();
    if (!piTrackLoader)
	{
		GfLogError("Track loader not yet initialized ; failed to load any track\n");
        return false;
    }
	
    // Load track data from the XML file.
    tTrack* pTrack = piTrackLoader->load(_strDescFile.c_str());
    if (!pTrack)
	{
		GfLogWarning("Unusable track %s : failed to build track data from %s\n",
					 _strId.c_str(), _strDescFile.c_str());
        return false;
    }

	// Check if the track 3D model file exists.
	std::ostringstream ossFileName;
	ossFileName << "tracks/" << _strCatId << '/' << _strId << '/'
				<< (pTrack->graphic.model3d ? pTrack->graphic.model3d : "track.ac");
    if (!GfFileExists(ossFileName.str().c_str()))
	{
		GfLogWarning("Unusable track %s : could not find 3D model %s\n",
					 _strId.c_str(), ossFileName.str().c_str());
        return false;
    }

	// All right now : let's read last needed infos.
	_strName = pTrack->name;
	_strDesc = pTrack->descr;
	_strAuthors = pTrack->authors;
	_fLength = pTrack->length;
	_fWidth = pTrack->width;
	_nMaxPitSlots = pTrack->pits.nMaxPits;

    // Unload track data.
    piTrackLoader->unload();

	// Now, the track seems usable (hm ... OK, we didn't check the 3D file contents ...).
	_bUsable = true;
	
	return true;
}
Ejemplo n.º 23
0
int GfuiMenuScreen::createProgressbarControl(const char* pszName)
{
	if (!m_priv->xmlDescParmHdle && !openXMLDescriptor())
		return -1;
	
	if (m_priv->mapControlIds.find(pszName) == m_priv->mapControlIds.end())
	{
		const int nCtrlId =
			::GfuiMenuCreateProgressbarControl(m_priv->menuHdle, m_priv->xmlDescParmHdle, pszName);
		if (nCtrlId >= 0)
			m_priv->mapControlIds[pszName] = nCtrlId;

		return nCtrlId;
	}

	GfLogError("Failed to create progress-bar control '%s' : duplicate name\n", pszName);
	return -1;
}
Ejemplo n.º 24
0
bool NetServer::Start(int port)
{
	SetRaceInfoChanged(true);
	m_bPrepareToRace = false;
	m_bBeginRace = false;

	m_timePhysics = -2.0;
	m_sendCarDataTime = 0.0;
	m_sendCtrlTime = 0.0;


    /* Bind the server to the default localhost.     */
    /* A specific host address can be specified by   */
    /* enet_address_set_host (& address, "x.x.x.x"); */

    m_address.host = ENET_HOST_ANY;
    /* Bind the server to port*/
    m_address.port = port;

	assert(m_pServer ==NULL);

	GfLogInfo ("Starting network server : Listening on port %d.\n", port);
	
     #if (ENET_VERSION >= 0x010300)
        m_pServer = enet_host_create (& m_address /* the address to bind the server host to */, 
                                      MAXNETWORKPLAYERS,
                                      2,     /* assume tha maximum number of channels is allowed*/
                                      0      /* assume any amount of incoming bandwidth */,
                                      0      /* assume any amount of outgoing bandwidth */);
    #else
        m_pServer = enet_host_create (& m_address /* the address to bind the server host to */, 
                                      MAXNETWORKPLAYERS,
                                      0      /* assume any amount of incoming bandwidth */,
                                      0      /* assume any amount of outgoing bandwidth */);
    #endif
    if (m_pServer == NULL)
    {
        GfLogError ("An error occurred while trying to create an ENet server host.\n");
		return false;
    }

	m_pHost = m_pServer;
	return true;
}
Ejemplo n.º 25
0
bool GfModule::register_(GfModule* pModule) // Can't use 'register' as it is a C++ keyword.
{
	bool bStatus = false;
	
	if (pModule)
	{
		if (_mapModulesByLibName.find(pModule->getSharedLibName()) != _mapModulesByLibName.end())
		{
			GfLogError("Can only register 1 module from %s\n", pModule->getSharedLibName().c_str());
		}
		else
		{
			_mapModulesByLibName[pModule->getSharedLibName()] = pModule;
			bStatus = true;
		}
	}

	return bStatus;
}
Ejemplo n.º 26
0
bool 
GfuiMenuCreateStaticControls(void* hscr, void* hparm)
{
	if (!hparm)
	{
		GfLogError("Failed to create static controls (XML menu descriptor not yet loaded)\n");
		return false;
	}

    char buf[32];

    for (int i = 1; i <= GfParmGetEltNb(hparm, GFMNU_SECT_STATIC_CONTROLS); i++)
    {
		snprintf(buf, sizeof(buf), GFMNU_SECT_STATIC_CONTROLS"/%d", i);
		const char* pszType = GfParmGetStr(hparm, buf, GFMNU_ATTR_TYPE, "");
    
		if (!strcmp(pszType, GFMNU_TYPE_LABEL))
		{
			createLabel(hscr, hparm, buf);
		}
		else if (!strcmp(pszType, GFMNU_TYPE_STATIC_IMAGE))
		{
			createStaticImage(hscr, hparm, buf);
		}
		else if (!strcmp(pszType, GFMNU_TYPE_BACKGROUND_IMAGE))
		{
			createBackgroundImage(hscr, hparm, buf);
		}
		else
		{
			GfLogWarning("Failed to create static control '%s' of unknown type '%s'\n",
						 buf, pszType);
		}
    }
	 
	 // while not truly a static control (visually), each menu/screen can have
	 // background music. As 'GfuiMenuCreateStaticControls()' is called on load
	 // of each menu, this was deemed the least intrusive place to add the
	 // music filename to the screen's struct.
	 createMusic(hscr,hparm);
    return true;
}
Ejemplo n.º 27
0
int GfuiMenuScreen::createCheckboxControl(const char* pszName,
										  void* userData, tfuiCheckboxCallback onChange)
{
	if (!m_priv->xmlDescParmHdle && !openXMLDescriptor())
		return -1;
	
	if (m_priv->mapControlIds.find(pszName) == m_priv->mapControlIds.end())
	{
		const int nCtrlId = 
			::GfuiMenuCreateCheckboxControl(m_priv->menuHdle, m_priv->xmlDescParmHdle, pszName,
											userData, onChange);
		if (nCtrlId >= 0)
			m_priv->mapControlIds[pszName] = nCtrlId;

		return nCtrlId;
	}

	GfLogError("Failed to create check-box control '%s' : duplicate name\n", pszName);
	return -1;
}
Ejemplo n.º 28
0
bool GfModule::unregister(GfModule* pModule)
{
	bool bStatus = false;
	
	if (pModule)
	{
		if (_mapModulesByLibName.find(pModule->getSharedLibName()) == _mapModulesByLibName.end())
		{
			GfLogError("Can't unregister module in %s (not yet registered)\n", 
					   pModule->getSharedLibName().c_str());
		}
		else
		{
			_mapModulesByLibName.erase(pModule->getSharedLibName());
			bStatus = true;
		}
	}

	return bStatus;
}
Ejemplo n.º 29
0
int 
GfuiMenuCreateScrollListControl(void* hscr, void* hparm, const char* pszName,void* userData, tfuiCallback onSelect)
{
	std::string strControlPath(GFMNU_SECT_DYNAMIC_CONTROLS"/");
	strControlPath += pszName;

	const char* pszType = GfParmGetStr(hparm, strControlPath.c_str(), GFMNU_ATTR_TYPE, "");
	if (strcmp(pszType, GFMNU_TYPE_SCROLL_LIST))
	{
		GfLogError("Failed to create control '%s' : section not found or not a '%s' \n",
				   pszName, GFMNU_TYPE_SCROLL_LIST);
		return -1;
	}

	const int x = (int)GfParmGetNum(hparm, strControlPath.c_str(), GFMNU_ATTR_X, NULL, 0.0);
	const int y = (int)GfParmGetNum(hparm, strControlPath.c_str(), GFMNU_ATTR_Y, NULL, 0.0);
	const int w = (int)GfParmGetNum(hparm, strControlPath.c_str(), GFMNU_ATTR_WIDTH, NULL, 100.0);
	const int h = (int)GfParmGetNum(hparm, strControlPath.c_str(), GFMNU_ATTR_HEIGHT, NULL, 100.0);
        
	const char* pszFontName = GfParmGetStr(hparm, strControlPath.c_str(), GFMNU_ATTR_FONT, "");
	const int font = gfuiMenuGetFontId(pszFontName);

	const char* pszScrollBarPos =
		GfParmGetStr(hparm, strControlPath.c_str(), GFMNU_ATTR_SCROLLBAR_POS, "none");
	const int scrollbarPos = gfuiMenuGetScrollBarPosition(pszScrollBarPos);
	const int scrollbarWidth =
		(int)GfParmGetNum(hparm, strControlPath.c_str(), GFMNU_ATTR_SCROLLBAR_WIDTH, NULL, 20.0);
	const int scrollBarButHeight =
		(int)GfParmGetNum(hparm, strControlPath.c_str(), GFMNU_ATTR_SCROLLBAR_BUTTONS_HEIGHT, NULL, 20.0);

	const GfuiColor c = getControlColor(hparm, pszName, GFMNU_ATTR_COLOR);
	const GfuiColor sc = getControlColor(hparm, pszName, GFMNU_ATTR_COLOR_SELECTED);
        
	int id = GfuiScrollListCreate(hscr, font, x, y, w, h,
								  scrollbarPos, scrollbarWidth, scrollBarButHeight,
								  userData, onSelect);

	GfuiScrollListSetColors(hscr, id, c, sc);

	return id;
}
Ejemplo n.º 30
0
void GfuiEventLoop::injectKeyboardEvent(int code, int modifier, int state,
										int unicode, int x, int y)
{
#ifndef WIN32
	// Hard-coded Alt+Enter shortcut, to enable the user to quit/re-enter
	// the full-screen mode ; as in SDL's full screen mode, events never reach
	// the Window Manager, we need this trick for the user to enjoy
	// its WM keyboard shortcuts (didn't find any other way yet).
	if (code == SDLK_RETURN	&& (modifier & KMOD_ALT) && state == 0)
	{
		if (!GfScrToggleFullScreen())
			GfLogError("Failed to toggle on/off the full-screen mode\n");
	}
	else
#endif
	{
		SDL_GetMouseState(&x, &y);
		GfEventLoop::injectKeyboardEvent(code, modifier, state, unicode, x, y);
	}
	//printf("Key %x State %x mod %x\n", code, state, modifier);
}