Changes between Version 2 and Version 3 of documentation/tutorials/PythonEventSystem
- Timestamp:
- 01/09/08 11:20:58 (10 years ago)
Legend:
- Unmodified
- Added
- Removed
- Modified
-
documentation/tutorials/PythonEventSystem
v2 v3 53 53 PythonInterface::Shutdown should be called after you've released all contexts but before you call Rocket::Shutdown(). This ensures all python objects are released before rocket does its final cleanup. 54 54 55 At this point you'll need to add the relevant Python and Boost::Python build paths to your project and then compile and link your project. 56 55 57 == Step 2: Replacing the Event System == 56 58 57 We can now completely remove the exiting event system from ''RocketInvaders'' as the Python bindings will do all the event management for us. We will however need some way of starting invaders from script. I suggest you do this with an ''autoexec.py'' script, that would look something like this: 59 We can now completely remove the exiting event system from ''RocketInvaders'' as the Python bindings will do all the EventManagement for us. Remove all source and header files that begin with Event. You'll also need to comment out some code in GameElement.cpp and Game.cpp that call the EventManager directly. We'll get back to those later. 60 61 Also remove all the EventManager initialisation from main.cpp as we'll replace it with a new Python script. I suggest you name it ''autoexec.py'' and place it in a ''python'' subfolder. It should look something like this: 58 62 59 63 {{{ 73 77 if (!module) 74 78 { 75 P rintError();79 PyErr_Print(); 76 80 return false; 77 81 } 86 90 }}} 87 91 88 At this point the ''RocketInvaders'' will now run, however you'll get a nasty script error as Python attempts to execute the ''onload'' event in mainmenu.rml. Update the ''onload'' and ''onunload'' events to use Python script which will correctly display and hide the logo. 92 At this point the ''RocketInvaders'' will now run, however you'll get a script import error because ''autoexec'' cannot be found. To fix this we'll need to add the ''python'' folder to our Python search path. 93 94 ''NOTE: On Windows this error will go to stdout, which will not be visible. I suggest you grab a copy of DoAllocConsole() from the pyinvaders sample and drop it into your project. Call DoAllocConsole() at the start of your main function and you'll get a console for reading python error messages.'' 95 96 My PythonInterface::Initialise now looks like this: 97 {{{ 98 bool PythonInterface::Initialise() 99 { 100 // Initialise Python. 101 Py_Initialize(); 102 103 // Setup the Python search path. 104 const char* python_path = Py_GetPath(); 105 char buffer[1024]; 106 snprintf(buffer, 1024, "../samples/invaders/python;%s", python_path); 107 buffer[1023] = '\0'; 108 PySys_SetPath(buffer); 109 110 // Import Rocket. 111 if (!Import("rocket")) 112 return false; 113 114 return true; 115 } 116 }}} 117 118 This will get us further, you should see the main menu load, however you'll notice a python error on your console when Python attempts to execute the old ''onload'' event in mainmenu.rml. Update the ''onload'' and ''onunload'' events to use Python script which will correctly display and hide the logo. 89 119 {{{ 90 120 <body template="window" onload="document.context.LoadDocument('data/logo.rml').Show()" onunload="document.context.logo.Close()">