Пример #1
0
//[-------------------------------------------------------]
//[ Protected virtual PLCore::FrontendImpl functions      ]
//[-------------------------------------------------------]
int Frontend::Run(const String &sExecutableFilename, const Array<String> &lstArguments)
{
	// Get traditional C-arguments
	int argc = 1 + lstArguments.GetNumOfElements();
	char **argv = new char *[argc];
	{ // Fill C-arguments
		{ // First one is the executable filename
			const char *pszExecutableFilename = sExecutableFilename.GetUTF8();
			const uint32 nNumOfExecutableFilenameBytes = UTF8Tools::GetNumOfStringBytes(pszExecutableFilename);
			argv[0] = new char[nNumOfExecutableFilenameBytes + 1];	// +1 for the terminating zero
			MemoryManager::Copy(argv[0], pszExecutableFilename, nNumOfExecutableFilenameBytes);
			argv[0][nNumOfExecutableFilenameBytes] = '\0';	// The terminating zero
		}

		// ... and now the arguments...
		for (uint32 i=0; i<lstArguments.GetNumOfElements(); i++) {
			const char *pszArgument = lstArguments[i].GetUTF8();
			const uint32 nNumOfArgumentBytes = UTF8Tools::GetNumOfStringBytes(pszArgument);
			argv[i + 1] = new char[nNumOfArgumentBytes + 1];	// +1 for the terminating zero
			MemoryManager::Copy(argv[i + 1], pszArgument, nNumOfArgumentBytes);
			argv[i + 1][nNumOfArgumentBytes] = '\0';	// The terminating zero
		}
	}

	// Create the Qt application instance on the C runtime stack
	QApplication cQApplication(argc, argv);

	// Set application icon
	cQApplication.setWindowIcon(QIcon(":/pl_icon.png"));

	// Create the mouse cursors
	m_pQCursorBlank = new QCursor(Qt::BlankCursor);

	// Create and set the main window
	FrontendMainWindow *pFrontendMainWindow = new FrontendMainWindow(*this);

	// Run the Qt application
	const int nResult = cQApplication.exec();

	// Destroy the main window
	delete pFrontendMainWindow;

	// Delete the mouse cursors
	delete m_pQCursorBlank;
	m_pQCursorBlank = nullptr;

	// Cleanup traditional C-arguments
	for (int i=0; i<argc; i++)
		delete argv[i];
	delete [] argv;

	// Done
	return nResult;
}
Пример #2
0
/**
*  @brief
*    Creates view planes using vertices and a view position
*/
bool PlaneSet::CreateViewPlanes(const Array<Vector3> &lstVertices, const Vector3 &vViewPosition)
{
	// Are there enough vertices provided?
	const uint32 nNumOfVertices = lstVertices.GetNumOfElements();
	if (nNumOfVertices >= 3) {
		// Check whether there are enough planes
		if (GetNumOfPlanes() < nNumOfVertices+1)
			GetList().Resize(nNumOfVertices+1);

		// Check whether there are not to much planes
		while (GetNumOfPlanes() > nNumOfVertices+1)
			RemovePlane(GetNumOfPlanes()-1);

		// Near plane
		m_lstPlane[0].ComputeND(lstVertices[0], lstVertices[1], lstVertices[2]);

		// Side planes
		for (uint32 i=0; i<nNumOfVertices; i++)
			m_lstPlane[i+1].ComputeND(vViewPosition, lstVertices[i], lstVertices[(i+1) % nNumOfVertices]);

		// Done
		return true;
	} else {
		// Error!
		return false;
	}
}
Пример #3
0
void Script::GetAssociatedFilenames(Array<String> &lstFilenames)
{
	// We want to have a list of script filenames which were included within this script
	// -> It appears that there's no "easy" way in Lua to get this kind of information :/

	// Contains "Application", "Interaction" and so on (no final filenames)
	Array<String> lstRequire;

	// Get a list of loaded "require"-files
	{ // -> The files loaded within a Lua script by using "require" can be accessed by using the
		//    global control table variable "_LOADED". See http://www.lua.org/pil/8.1.html for details.
		lua_getfield(m_pLuaState, LUA_REGISTRYINDEX, "_LOADED");
		if (lua_istable(m_pLuaState, -1)) {
			lua_pushnil(m_pLuaState);
			while (lua_next(m_pLuaState, -2)) {
				if (lua_isstring(m_pLuaState, -2))
					lstRequire.Add(lua_tostring(m_pLuaState, -2));
				lua_pop(m_pLuaState, 1);
			}
		}

		// Pop the table from the Lua stack
		lua_pop(m_pLuaState, 1);
	}

	// Get the content of "package.path" used by "require" to search for a Lua loader
	// -> The content looks like "?.lua;C:\SomePath\?.lua;"
	const String sPackagePath = GetGlobalVariable("path", "package");

	// Iterate over the "require"-list
	const String sToReplace = "?.";
	for (uint32 i=0; i<lstRequire.GetNumOfElements(); i++) {
		// Get the current "require"
		const String sRequire = lstRequire[i] + '.';

		// Get the index of the first ";" within the package path
		int nPreviousIndex = 0;
		int nIndex = sPackagePath.IndexOf(';');
		while (nIndex>-1) {
			// Get current package search path, we now have e.g. "C:\SomePath\?.lua"
			String sFilename = sPackagePath.GetSubstring(nPreviousIndex, nIndex-nPreviousIndex);

			// Replace "?." with the "require"-name
			sFilename.Replace(sToReplace, sRequire);

			// Does this file exist?
			if (File(sFilename).Exists()) {
				// We found a match!
				lstFilenames.Add(sFilename);

				// Get us out of the while-loop
				nIndex = -1;
			} else {
				// Get the index of the next ";" within the package path
				nPreviousIndex = nIndex + 1;
				nIndex = sPackagePath.IndexOf(';', nPreviousIndex);
			}
		}
	}
}
Пример #4
0
/**
*  @brief
*    Calculates the sphere surrounding the enclosed area
*/
void PlaneSet::CalculateSphere(Sphere &cSphere) const
{
	// Init sphere
	cSphere.SetPos();
	cSphere.SetRadius();

	// Find all plane intersection points
	Vector3 vD;
	Array<Vector3> lstPoints;
	for (uint32 nP1=0; nP1<m_lstPlane.GetNumOfElements(); nP1++) {
		const Plane &cP1 = m_lstPlane[nP1];
		for (uint32 nP2=0; nP2<m_lstPlane.GetNumOfElements(); nP2++) {
			const Plane cP2 = m_lstPlane[nP2];
			if (nP2 != nP1) {
				for (uint32 nP3=0; nP3<m_lstPlane.GetNumOfElements(); nP3++) {
					const Plane &cP3 = m_lstPlane[nP3];
					if (nP3 != nP1 && nP3 != nP2) {
						Vector3 vRes;
						if (Intersect::PlanePlanePlane(cP1, cP2, cP3, vRes)) {
							lstPoints.Add(vRes);
							vD += vRes;
						}
					}
				}
			}
		}
	}

	// Get sphere position and radius
	if (lstPoints.GetNumOfElements()) {
		vD /= static_cast<float>(lstPoints.GetNumOfElements());
		cSphere.SetPos(vD);
		float fMaxLength = 0.0f;
		for (uint32 i=0; i<lstPoints.GetNumOfElements(); i++) {
			const Vector3 &vP = lstPoints[i];
			const float fLength = (vP-vD).GetLength();
			if (fLength > fMaxLength)
				fMaxLength = fLength;
		}
		cSphere.SetRadius(fMaxLength);
	}
}
Пример #5
0
//[-------------------------------------------------------]
//[ Public virtual PLSound::Buffer functions              ]
//[-------------------------------------------------------]
bool Buffer::LoadBuffer(const String &sFilename, bool bStream)
{
	// Check parameter
	if (sFilename.GetLength()) {
		// Unload old sound buffer
		Unload();

		// Load buffer
		m_bStream = bStream;
		if (m_bStream) {
			m_sFilename = sFilename;

			// Done
			return true;
		} else {
			// Create the buffer
			alGenBuffers(1, &m_nBuffer);
			ALuint nError = alGetError();
			if (nError == AL_NO_ERROR) {
				// Try to load ogg
				m_sFilename = sFilename;
				File *pFile = OpenFile();
				if (pFile) {
					ALsizei nFreq;
					ALenum  nFormat;
					Array<uint8> lstBufferData;
					if (LoadOGG(pFile, lstBufferData, nFormat, nFreq)) {
						// Fill buffer
						alBufferData(m_nBuffer, nFormat, &lstBufferData[0], lstBufferData.GetNumOfElements(), nFreq);
						nError = alGetError();
						if (nError == AL_NO_ERROR)
							return true; // Done
						else
							PL_LOG(Error, String("alBufferData: ") + alGetString(nError))
					} else {
						// Check whether this is a wav file
						const String sExtension = Url(sFilename).GetExtension();
						if (sExtension == "wav") {
							// Try to load wav
							if (LoadWav(pFile, lstBufferData, nFormat, nFreq)) {
								// Fill buffer
								alBufferData(m_nBuffer, nFormat, &lstBufferData[0], lstBufferData.GetNumOfElements(), nFreq);
								nError = alGetError();
								if (nError == AL_NO_ERROR)
									return true; // Done
								else
									PL_LOG(Error, String("alBufferData: ") + alGetString(nError))
							} else {
								delete pFile;
							}
						} else {
							delete pFile;
						}
					}
Пример #6
0
/**
*  @brief
*    Parses the found header files in the given include path for pl_class..pl_class_end blocks
*/
void PLPluginInfo::ParseIncludeFiles(const String &sIncludePath)
{
	// Check if path exists and if it points to a directory
	FileObject cIncFile(sIncludePath);
	if (cIncFile.Exists() && cIncFile.IsDirectory()) {
		// Get all header files from the include directory
		Array<String> lstFiles;
		Find(lstFiles, sIncludePath, "*.h", true);

		// Parse each header file
		for (uint32 i=0; i<lstFiles.GetNumOfElements(); i++)
			ParseFile(lstFiles[i]);
	}
}
Пример #7
0
bool ContextLinux::QueryDisplayModes(Array<const PLRenderer::DisplayMode*> &lstDisplayModeList)
{
	bool bResult = false;	// Error by default

	// Clear old list of display modes
	for (uint32 i=0; i<lstDisplayModeList.GetNumOfElements(); i++)
		delete lstDisplayModeList[i];
	lstDisplayModeList.Clear();

	// Get list of display modes
	PL_LOG(Info, "Query available display modes")

	// Get XRR screen configuration (don't forget "XRRFreeScreenConfigInfo()" if you no longer need it)
	const int nScreen = XDefaultScreen(m_pDisplay);
	XRRScreenConfiguration *pXRRScreenConfiguration = XRRGetScreenInfo(m_pDisplay, RootWindow(m_pDisplay, nScreen));

	// Get specific configuration information out of our screen configuration
	int nNumOfModes = 0;
	XRRScreenSize *pXRRScreenSize = XRRConfigSizes(pXRRScreenConfiguration, &nNumOfModes);

	// Loop through all modes
	for (int nMode=0; nMode<nNumOfModes; nMode++) {
		// First at all, we're only interested in some of the settings - as a result, we really should check if there's
		// already a display mode within our list with the interesting settings of the current found display mode
		bool bNewMode = true;
		for (uint32 i=0; i<lstDisplayModeList.GetNumOfElements(); i++) {
			const PLRenderer::DisplayMode *pDisplayMode = lstDisplayModeList[i];
			if (pDisplayMode->vSize.x == pXRRScreenSize[nMode].width && pDisplayMode->vSize.y == pXRRScreenSize[nMode].height) {
				// We already have such a display mode within our list!
				bNewMode = false;

				// Get us out of this loop right now!
				i = lstDisplayModeList.GetNumOfElements();
			}
		}
		if (bNewMode) {
			// Get required information
			PLRenderer::DisplayMode *pDisplayMode = new PLRenderer::DisplayMode;
			pDisplayMode->vSize.x	  = pXRRScreenSize[nMode].width;
			pDisplayMode->vSize.y	  = pXRRScreenSize[nMode].height;
			pDisplayMode->nColorBits  = XDefaultDepth(m_pDisplay, nScreen);

			// [TODO] Under Linux there is currently no real 32 bit visual (RGBA)
			// only 24 bit (RGB) which is equal to 32 bit in RGB (without alpha value)
			if (pDisplayMode->nColorBits == 24)
				pDisplayMode->nColorBits = 32;
			pDisplayMode->nFrequency = 0;

			// Give out a log message
			String sTemp;
			if (pDisplayMode->nFrequency) {
				sTemp = String::Format("Found: %dx%dx%d %d Hz", pDisplayMode->vSize.x, pDisplayMode->vSize.y, pDisplayMode->nColorBits, pDisplayMode->nFrequency);
			} else {
				sTemp = String::Format("Found: %dx%dx%d", pDisplayMode->vSize.x, pDisplayMode->vSize.y, pDisplayMode->nColorBits);
			}

			// Add found display mode to list
			PL_LOG(Info, sTemp)
			lstDisplayModeList.Add(pDisplayMode);
		}
	}

	// Was at least one display mode found?
	if (lstDisplayModeList.GetNumOfElements())
		bResult = true; // Success! :D
	else
		PL_LOG(Error, "No available & supported display modes found!")

	// Free XRR screen configuration
	XRRFreeScreenConfigInfo(pXRRScreenConfiguration);

	// Done
	return bResult;
}