Example #1
0
	bool InitialiseFramework( PyObject* a_pModule )
	{
		bool bSuccess = false;
		PyObject* pInitialise = GetHandleToPythonFunction( a_pModule, "PyInitialise" );
		if( pInitialise )
		{
			PyObject* pReturnValue = CallPythonFunction( pInitialise, nullptr );
			if( pReturnValue )
			{
				int iWidth; int iHeight; bool bFullscreen; char* windowTitle;

				if (!PyArg_ParseTuple(pReturnValue, "iibs", &iWidth, &iHeight, &bFullscreen, &windowTitle)) 
				{
					ParsePyTupleError( __func__, __LINE__ );
				}
				Py_DECREF(pReturnValue);

				int titleLength = strlen(windowTitle);
				g_pWindowTitle = new char[titleLength+1];
				memcpy(g_pWindowTitle, windowTitle, titleLength);
				g_pWindowTitle[titleLength] = '\0';
				bSuccess = ( Initialise( iWidth, iHeight, bFullscreen, g_pWindowTitle) == 0 );
			}
			Py_XDECREF(pInitialise);
			
		}
		return bSuccess;
	}
bool LMF_CallPythonFunction(PyObject* a_pModule, char* cs_FunctionName){
	bool bSuccess = false;
	PyObject* pFunction = GetHandleToPythonFunction( a_pModule, cs_FunctionName);
	if( pFunction ){
		PyObject* pReturnValue = CallPythonFunction( pFunction, nullptr );
		if( pReturnValue ){
			bSuccess = true;
		}
		Py_XDECREF(pFunction);	
	}
	return bSuccess;
}
Example #3
0
	void ShutdownFramework( PyObject* a_pModule )
	{
		PyObject* pShutdownFunc = GetHandleToPythonFunction( a_pModule, "PyShutdown" );
		if (pShutdownFunc) 
		{
			PyObject* pReturnValue = CallPythonFunction( pShutdownFunc, nullptr );
			if( pReturnValue )
			{
				printf("We have reached the end of the Game! Arguments returned from call: %ld\n", PyInt_AsLong(pReturnValue));
				Py_DECREF(pReturnValue);
			}
			Py_XDECREF(pShutdownFunc);
		}
		Shutdown();
	}
Example #4
0
	void UpdatePython( PyObject* a_pModule, float a_fDeltaTime )
	{
		PyObject* pUpdateFunc = GetHandleToPythonFunction( a_pModule, "PyUpdate" );
		if (pUpdateFunc) 
		{
			PyObject* pDeltaTime = PyFloat_FromDouble( a_fDeltaTime );
			PyObject* pArgs = PyTuple_New(1);
			PyTuple_SetItem( pArgs, 0, pDeltaTime );
			PyObject* pReturnValue = CallPythonFunction( pUpdateFunc, pArgs );
			if( pReturnValue )
			{
				//std::cout << "Updating Python Game Loop" << std::endl;
				Py_DECREF(pReturnValue);
			}
			Py_XDECREF(pUpdateFunc);
		}  
	}
Example #5
0
	void Load( PyObject* a_pModule )
	{
		//"./images/crate_sideup.png", 64.0, 64.0, 0.5, 0.5, 0.0, 0.0, 1.0, 1.0, 255, 255, 255, 255
		float fv2Size[2] = { 64.f, 64.f };
		float fv2Origin[2] = { 0.5f, 0.5f };
		float fv4UVCoords[4] = { 0.f, 0.f, 1.f, 1.f };
		float vColour[4] = { 1.f, 1.f, 1.f, 1.f };

		unsigned int uiSpriteID = CreateSprite( "./images/crate_sideup.png", fv2Size, fv2Origin, fv4UVCoords, SColour(vColour[0]/255, vColour[1]/255, vColour[2]/255, vColour[3]/255) );
	
		PyObject* pLoad = GetHandleToPythonFunction( a_pModule, "PyLoad" );
		if( pLoad )
		{
			PyObject* pReturnValue = CallPythonFunction( pLoad, nullptr );
			if( pReturnValue )
			{
				Py_DECREF(pReturnValue);
			}
			Py_XDECREF(pLoad);
			
		}
	}
			case 108: case 76://l L
				PyTuple_SetItem( pArgs, i, PyLong_FromLong( va_arg(vaItems,long) ) );
				break;
			case 102: case 70://f F
			case 100: case 68://d D
				PyTuple_SetItem( pArgs, i, PyFloat_FromDouble(va_arg(vaItems,double) ) );
				break;
			case 99: case 67://c C
				PyTuple_SetItem( pArgs, i, Py_BuildValue("c",va_arg(vaItems,char) ) );
				break;
			case 115: case 83://s S
				PyTuple_SetItem( pArgs, i, PyString_FromString( va_arg(vaItems,char*) ) );
				break;
			}
		}
	}
	va_end(vaItems);
	//End of passer
	PyObject* pFunction = GetHandleToPythonFunction( a_pModule, cs_FunctionName);
	if( pFunction ){
		PyObject* pReturnValue = CallPythonFunction( pFunction, pArgs );
		if( pReturnValue ){
			bSuccess = true;
		}
		Py_XDECREF(pFunction);	
	}
	return bSuccess;
}
//---------------------------
//------ Luke Monaghan ------
//---------------------------