[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [31907] trunk/blender/source/gameengine/ GamePlayer/ghost/GPG_ghost.cpp: blenderplayer parsing code (better) fix
Dalai Felinto
dfelinto at gmail.com
Mon Sep 13 10:30:59 CEST 2010
Revision: 31907
http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=31907
Author: dfelinto
Date: 2010-09-13 10:30:56 +0200 (Mon, 13 Sep 2010)
Log Message:
-----------
blenderplayer parsing code (better) fix
After last commit I realized that we have a different behavior when running blenderplayer or a runtime. Reason being is that when running blenderplayer the filename is mandatory. While in runtime mode it has no use for it (it can still be passed, but it makes no difference).
I also updated the -h (help) message to be multiplataform and to pass the filename argument only when in blenderplayer mode.
If someone wants to have fun it would be nice to port the blender new parsing code to the gameplayer.
* note: how come "noaudio" is used in the examples but it's not in the options list? *ouch*
I'm leaving as it's in case noaudio get implemented ...
Modified Paths:
--------------
trunk/blender/source/gameengine/GamePlayer/ghost/GPG_ghost.cpp
Modified: trunk/blender/source/gameengine/GamePlayer/ghost/GPG_ghost.cpp
===================================================================
--- trunk/blender/source/gameengine/GamePlayer/ghost/GPG_ghost.cpp 2010-09-13 08:23:55 UTC (rev 31906)
+++ trunk/blender/source/gameengine/GamePlayer/ghost/GPG_ghost.cpp 2010-09-13 08:30:56 UTC (rev 31907)
@@ -161,17 +161,29 @@
#endif /* WIN32 */
-void usage(const char* program)
+void usage(const char* program, bool isBlenderPlayer)
{
const char * consoleoption;
+ const char * filename = "";
+ const char * pathname = "";
+
#ifdef _WIN32
consoleoption = "-c ";
#else
consoleoption = "";
#endif
+
+ if (isBlenderPlayer) {
+ filename = "filename.blend";
+#ifdef _WIN32
+ pathname = "c:\\";
+#else
+ pathname = "//home//user//";
+#endif
+ }
printf("usage: %s [-w [w h l t]] [-f [fw fh fb ff]] %s[-g gamengineoptions] "
- "[-s stereomode] filename.blend\n", program, consoleoption);
+ "[-s stereomode] %s\n", program, consoleoption, filename);
printf(" -h: Prints this command summary\n\n");
printf(" -w: display in a window\n");
printf(" --Optional parameters--\n");
@@ -227,8 +239,8 @@
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);
+ printf("example: %s -w 320 200 10 10 -g noaudio%s%s\n", program, pathname, filename);
+ printf("example: %s -g show_framerate = 0 %s%s\n", program, pathname, filename);
}
static void get_filename(int argc, char **argv, char *filename)
@@ -337,8 +349,8 @@
int fullScreenBpp = 32;
int fullScreenFrequency = 60;
GHOST_TEmbedderWindowID parentWindow = 0;
-
-
+ bool isBlenderPlayer = false;
+ int validArguments=0;
#ifdef __linux__
#ifdef __alpha__
@@ -412,7 +424,14 @@
U.audioformat = 0x24;
U.audiochannels = 2;
- for (i = 1; (i < argc) && !error
+ /* if running blenderplayer the last argument can't be parsed since it has to be the filename. */
+ isBlenderPlayer = !blo_is_a_runtime(argv[0]);
+ if (isBlenderPlayer)
+ validArguments = argc - 1;
+ else
+ validArguments = argc;
+
+ for (i = 1; (i < validArguments) && !error
#ifdef WIN32
&& scr_saver_mode == SCREEN_SAVER_MODE_NONE
#endif
@@ -436,14 +455,14 @@
// Parse game options
{
i++;
- if (i < argc)
+ if (i <= validArguments)
{
char* paramname = argv[i];
// Check for single value versus assignment
- if (i+1 < argc && (*(argv[i+1]) == '='))
+ if (i+1 <= validArguments && (*(argv[i+1]) == '='))
{
i++;
- if (i + 1 < argc)
+ if (i + 1 <= validArguments)
{
i++;
// Assignment
@@ -479,14 +498,14 @@
i++;
fullScreen = true;
fullScreenParFound = true;
- if ((i + 2) < argc && argv[i][0] != '-' && argv[i+1][0] != '-')
+ if ((i + 2) <= validArguments && argv[i][0] != '-' && argv[i+1][0] != '-')
{
fullScreenWidth = atoi(argv[i++]);
fullScreenHeight = atoi(argv[i++]);
- if ((i + 1) < argc && argv[i][0] != '-')
+ if ((i + 1) <= validArguments && argv[i][0] != '-')
{
fullScreenBpp = atoi(argv[i++]);
- if ((i + 1) < argc && argv[i][0] != '-')
+ if ((i + 1) <= validArguments && argv[i][0] != '-')
fullScreenFrequency = atoi(argv[i++]);
}
}
@@ -497,11 +516,11 @@
fullScreen = false;
windowParFound = true;
- if ((i + 2) < argc && argv[i][0] != '-' && argv[i+1][0] != '-')
+ if ((i + 2) <= validArguments && argv[i][0] != '-' && argv[i+1][0] != '-')
{
windowWidth = atoi(argv[i++]);
windowHeight = atoi(argv[i++]);
- if ((i + 2) < argc && argv[i][0] != '-' && argv[i+1][0] != '-')
+ if ((i + 2) <= validArguments && argv[i][0] != '-' && argv[i+1][0] != '-')
{
windowLeft = atoi(argv[i++]);
windowTop = atoi(argv[i++]);
@@ -510,14 +529,19 @@
break;
case 'h':
- usage(argv[0]);
+ usage(argv[0], isBlenderPlayer);
return 0;
break;
#ifndef _WIN32
case 'i':
i++;
- if ( (i + 1) < argc )
- parentWindow = atoi(argv[i++]);
+ if ( (i + 1) <= validArguments )
+ parentWindow = atoi(argv[i++]);
+ else {
+ error = true;
+ printf("error: too few options for parent window argument.\n");
+ }
+
#ifndef NDEBUG
printf("XWindows ID = %d\n", parentWindow);
#endif //NDEBUG
@@ -529,7 +553,7 @@
break;
case 's': // stereo
i++;
- if ((i + 1) < argc)
+ if ((i + 1) <= validArguments)
{
stereomode = (RAS_IRasterizer::StereoMode) atoi(argv[i]);
if (stereomode < RAS_IRasterizer::RAS_STEREO_NOSTEREO || stereomode >= RAS_IRasterizer::RAS_STEREO_MAXSTEREO)
@@ -575,7 +599,7 @@
stereoFlag = STEREO_DOME;
stereomode = RAS_IRasterizer::RAS_STEREO_DOME;
i++;
- if ((i + 1) < argc)
+ if ((i + 1) <= validArguments)
{
if(!strcmp(argv[i], "angle")){
i++;
@@ -631,7 +655,7 @@
if (error )
{
- usage(argv[0]);
+ usage(argv[0], isBlenderPlayer);
return 0;
}
@@ -714,7 +738,7 @@
//::printf("game data loaded from %s\n", filename);
if (!bfd) {
- usage(argv[0]);
+ usage(argv[0], isBlenderPlayer);
error = true;
exitcode = KX_EXIT_REQUEST_QUIT_GAME;
}
More information about the Bf-blender-cvs
mailing list