Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCampbell Barton <ideasman42@gmail.com>2009-04-20 13:13:59 +0400
committerCampbell Barton <ideasman42@gmail.com>2009-04-20 13:13:59 +0400
commitdee32d0b3f409007f5a392668068b92c3810026a (patch)
tree3127ac9c88ea9d783282d3bf8ed5ba8f2a40eb43 /source/gameengine/GamePlayer
parent9078ce5da209bcfd31c60b55118076359ce7244f (diff)
BGE Python API
- initialize pythons sys.argv in the blenderplayer - ignore all arguments after a single " - " in the blenderplayer (like in blender), so args can be passed to the game. - add a utility function PyOrientationTo() - to take a Py euler, quat or 3x3 matrix and convert into a C++ MT_Matrix3x3. - add utility function ConvertPythonToMesh to get a RAS_MeshObject from a KX_MeshProxy or a name. - Added error prefix arguments to ConvertPythonToGameObject, ConvertPythonToMesh and PyOrientationTo so the error messages can include what function they came from. - deprecated brick.getOwner() for the "owner" attribute.
Diffstat (limited to 'source/gameengine/GamePlayer')
-rw-r--r--source/gameengine/GamePlayer/ghost/GPG_Application.cpp8
-rw-r--r--source/gameengine/GamePlayer/ghost/GPG_Application.h6
-rw-r--r--source/gameengine/GamePlayer/ghost/GPG_ghost.cpp13
3 files changed, 22 insertions, 5 deletions
diff --git a/source/gameengine/GamePlayer/ghost/GPG_Application.cpp b/source/gameengine/GamePlayer/ghost/GPG_Application.cpp
index 0ecbbea3af6..907ba99e63b 100644
--- a/source/gameengine/GamePlayer/ghost/GPG_Application.cpp
+++ b/source/gameengine/GamePlayer/ghost/GPG_Application.cpp
@@ -151,7 +151,7 @@ GPG_Application::~GPG_Application(void)
-bool GPG_Application::SetGameEngineData(struct Main* maggie, Scene *scene)
+bool GPG_Application::SetGameEngineData(struct Main* maggie, Scene *scene, int argc, char **argv)
{
bool result = false;
@@ -163,6 +163,10 @@ bool GPG_Application::SetGameEngineData(struct Main* maggie, Scene *scene)
m_startScene = scene;
result = true;
}
+
+ /* Python needs these */
+ m_argc= argc;
+ m_argv= argv;
return result;
}
@@ -681,7 +685,7 @@ bool GPG_Application::startEngine(void)
// some python things
- PyObject* dictionaryobject = initGamePlayerPythonScripting("Ketsji", psl_Lowest, m_maggie);
+ PyObject* dictionaryobject = initGamePlayerPythonScripting("Ketsji", psl_Lowest, m_maggie, m_argc, m_argv);
m_ketsjiengine->SetPythonDictionary(dictionaryobject);
initRasterizer(m_rasterizer, m_canvas);
PyObject *gameLogic = initGameLogic(m_ketsjiengine, startscene);
diff --git a/source/gameengine/GamePlayer/ghost/GPG_Application.h b/source/gameengine/GamePlayer/ghost/GPG_Application.h
index 38408f919b4..845686f5770 100644
--- a/source/gameengine/GamePlayer/ghost/GPG_Application.h
+++ b/source/gameengine/GamePlayer/ghost/GPG_Application.h
@@ -58,7 +58,7 @@ public:
GPG_Application(GHOST_ISystem* system);
~GPG_Application(void);
- bool SetGameEngineData(struct Main* maggie, struct Scene* scene);
+ bool SetGameEngineData(struct Main* maggie, struct Scene* scene, int argc, char** argv);
bool startWindow(STR_String& title, int windowLeft, int windowTop, int windowWidth, int windowHeight,
const bool stereoVisual, const int stereoMode);
bool startFullScreen(int width, int height, int bpp, int frequency, const bool stereoVisual, const int stereoMode);
@@ -154,5 +154,9 @@ protected:
*/
char* m_pyGlobalDictString;
int m_pyGlobalDictString_Length;
+
+ /* argc and argv need to be passed on to python */
+ int m_argc;
+ char** m_argv;
};
diff --git a/source/gameengine/GamePlayer/ghost/GPG_ghost.cpp b/source/gameengine/GamePlayer/ghost/GPG_ghost.cpp
index a41446ad88c..64e70ce37c3 100644
--- a/source/gameengine/GamePlayer/ghost/GPG_ghost.cpp
+++ b/source/gameengine/GamePlayer/ghost/GPG_ghost.cpp
@@ -206,6 +206,8 @@ void usage(const char* program)
printf(" blender_material 0 Enable material settings\n");
printf(" ignore_deprecation_warnings 1 Ignore deprecation warnings\n");
printf("\n");
+ printf(" - : all arguments after this are ignored, allowing python to access them from sys.argv\n");
+ printf("\n");
printf("example: %s -w 320 200 10 10 -g noaudio c:\\loadtest.blend\n", program);
printf("example: %s -g show_framerate = 0 c:\\loadtest.blend\n", program);
}
@@ -293,6 +295,7 @@ static BlendFileData *load_game_data(char *progname, char *filename = NULL, char
int main(int argc, char** argv)
{
int i;
+ int argc_py_clamped= argc; /* use this so python args can be added after ' - ' */
bool error = false;
SYS_SystemHandle syshandle = SYS_GetSystem();
bool fullScreen = false;
@@ -393,6 +396,12 @@ int main(int argc, char** argv)
#endif
if (argv[i][0] == '-')
{
+ /* ignore all args after " - ", allow python to have own args */
+ if (argv[i][1]=='\0') {
+ argc_py_clamped= i;
+ break;
+ }
+
switch (argv[i][1])
{
case 'g':
@@ -596,7 +605,7 @@ int main(int argc, char** argv)
char pathname[FILE_MAXDIR + FILE_MAXFILE];
char *titlename;
- get_filename(argc, argv, filename);
+ get_filename(argc_py_clamped, argv, filename);
if(filename[0])
BLI_convertstringcwd(filename);
@@ -691,7 +700,7 @@ int main(int argc, char** argv)
}
// GPG_Application app (system, maggie, startscenename);
- app.SetGameEngineData(maggie, scene);
+ app.SetGameEngineData(maggie, scene, argc, argv); /* this argc cant be argc_py_clamped, since python uses it */
BLI_strncpy(pathname, maggie->name, sizeof(pathname));
BLI_strncpy(G.sce, maggie->name, sizeof(G.sce));