Main Page   Namespace List   Class Hierarchy   Compound List   File List   Compound Members   File Members  

logicmain.cpp

Go to the documentation of this file.
00001 // CVS
00002 // $Author: coockie $
00003 // $Date: 2001/02/01 12:25:33 $
00004 // $RCSfile: logicmain_cpp-source.html,v $
00005 // $Revision: 1.2 $
00006 
00007 #ifdef HAVE_CONFIG_H
00008 #include <config.h>
00009 #endif
00010 
00011 #include <stdio.h>
00012 #include <stdlib.h>
00013 
00014 #include "Python.h"
00015 // game engine includes
00016 #include "KX_GlutInputDevice.h"
00017 #include "GlutSystem.h"
00018 #include "SCA_LogicManager.h"
00019 #include "SCA_KeyboardManager.h"
00020 #include "SCA_KeyboardSensor.h"
00021 #include "DebugActuator.h"
00022 #include "SCA_PythonController.h"
00023 
00024 static PyObject* ErrorObject;
00025 
00026 // List of methods defined in the module
00027 
00028 static struct PyMethodDef game_methods[] = {
00029   {"getCurrentController", 
00030    (PyCFunction) SCA_PythonController::sPyGetCurrentController,
00031    METH_VARARGS, SCA_PythonController::sPyGetCurrentController__doc__},
00032   { NULL, (PyCFunction) NULL, 0, NULL }
00033 };
00034 
00035 // Initialization function for the module (*must* be called initGameLogic)
00036 
00037 static char GameLogic_module_documentation[] =
00038 "This is the Python API for the game engine of GameLogic"
00039 ;
00040 
00041 void
00042 initGameLogic()

00043 {
00044   PyObject* m;
00045   PyObject* d;
00046 
00047   // Create the module and add the functions
00048   m = Py_InitModule4("GameLogic", game_methods,
00049                      GameLogic_module_documentation,
00050                      (PyObject*)NULL,PYTHON_API_VERSION);
00051 
00052   // Add some symbolic constants to the module
00053   d = PyModule_GetDict(m);
00054   ErrorObject = PyString_FromString("GameLogic.error");
00055   PyDict_SetItemString(d, "error", ErrorObject);
00056 
00057   // XXXX Add constants here
00058 
00059   // Check for errors
00060   if (PyErr_Occurred())
00061     {
00062       Py_FatalError("can't initialize module GameLogic");
00063     }
00064 }
00065 
00066 int 
00067 main(int argc, char *argv[])

00068 {
00069   char filename[] = "test.py";
00070   FILE* fp = NULL;
00071   // create stuff with new
00072   SCA_IInputDevice* inputdev       = new KX_GlutInputDevice();
00073   SCA_ISystem* system              = NULL;//(inputdev);
00074   SCA_LogicManager* logicmgr       = new SCA_LogicManager();
00075   SCA_KeyboardManager* kbdeventmgr = new SCA_KeyboardManager(logicmgr, system);
00076   SCA_ISensor* keysensor           = new SCA_KeyboardSensor(kbdeventmgr, 'e', 
00077                                                           0, 0, 0 );
00078   SCA_IActuator* actua             = new DebugActuator(NULL);
00079   SCA_PythonController* contr      = NULL;
00080 
00081   Py_SetProgramName("gamelogic");
00082   Py_Initialize();
00083   initGameLogic();
00084 
00085   // create Python controller AFTER initialisation of Python interpreter !!!
00086   contr = new SCA_PythonController(NULL);
00087   logicmgr->RegisterEventManager(kbdeventmgr);
00088   logicmgr->RegisterToSensor(contr, keysensor);
00089   logicmgr->RegisterToActuator(contr, actua);
00090   SCA_PythonController::m_sCurrentController = contr;
00091   contr->AddRef();
00092   
00093   // run test Python script
00094   fp = fopen(filename, "r");
00095   char* buf = (char*)malloc(2024);
00096   size_t bytesread = fread(buf,2024,1,fp);
00097 
00098   PyRun_AnyFile(fp, filename);
00099   Py_Finalize();
00100 
00101   // delete stuff
00102   contr->Release();
00103   actua->Release();
00104   keysensor->Release();
00105   
00106   delete logicmgr;
00107   delete system;
00108   delete inputdev;
00109 
00110   return EXIT_SUCCESS;
00111 }

Generated at Thu Feb 1 13:03:07 2001 for Ketsji Game Engine by doxygen1.2.3 written by Dimitri van Heesch, © 1997-2000