~ubuntu-branches/ubuntu/gutsy/blender/gutsy-security

« back to all changes in this revision

Viewing changes to source/gameengine/GamePlayer/ghost/GPG_ghost.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Florian Ernst
  • Date: 2005-11-06 12:40:03 UTC
  • mfrom: (1.1.2 upstream)
  • Revision ID: james.westby@ubuntu.com-20051106124003-3pgs7tcg5rox96xg
Tags: 2.37a-1.1
* Non-maintainer upload.
* Split out parts of 01_SConstruct_debian.dpatch again: root_build_dir
  really needs to get adjusted before the clean target runs - closes: #333958,
  see #288882 for reference

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/**
2
 
* $Id: GPG_ghost.cpp,v 1.9 2004/04/29 10:51:02 kester Exp $
 
2
* $Id: GPG_ghost.cpp,v 1.15 2004/12/01 08:35:38 kester Exp $
3
3
*
4
4
 * ***** BEGIN GPL/BL DUAL LICENSE BLOCK *****
5
5
 *
85
85
#include "BKE_utildefines.h"
86
86
 
87
87
#ifdef WIN32
88
 
#ifdef NDEBUG
89
88
#include <windows.h>
 
89
#ifdef NDEBUG
90
90
#include <wincon.h>
91
91
#endif // NDEBUG
92
92
#endif // WIN32
96
96
 
97
97
char bprogname[FILE_MAXDIR+FILE_MAXFILE];
98
98
 
 
99
#ifdef WIN32
 
100
typedef enum 
 
101
{
 
102
  SCREEN_SAVER_MODE_NONE = 0,
 
103
  SCREEN_SAVER_MODE_PREVIEW,
 
104
  SCREEN_SAVER_MODE_SAVER,
 
105
  SCREEN_SAVER_MODE_CONFIGURATION,
 
106
  SCREEN_SAVER_MODE_PASSWORD,
 
107
} ScreenSaverMode;
 
108
 
 
109
static ScreenSaverMode scr_saver_mode = SCREEN_SAVER_MODE_NONE;
 
110
static HWND scr_saver_hwnd = NULL;
 
111
 
 
112
static BOOL scr_saver_init(int argc, char **argv) 
 
113
{
 
114
        scr_saver_mode = SCREEN_SAVER_MODE_NONE;
 
115
        scr_saver_hwnd = NULL;
 
116
        BOOL ret = FALSE;
 
117
 
 
118
        int len = ::strlen(argv[0]);
 
119
        if (len > 4 && !::stricmp(".scr", argv[0] + len - 4))
 
120
        {
 
121
                scr_saver_mode = SCREEN_SAVER_MODE_CONFIGURATION;
 
122
                ret = TRUE;
 
123
                if (argc >= 2)
 
124
                {
 
125
                        if (argc >= 3)
 
126
                        {
 
127
                                scr_saver_hwnd = (HWND) ::atoi(argv[2]);
 
128
                        }
 
129
                        if (!::stricmp("/c", argv[1]))
 
130
                        {
 
131
                                scr_saver_mode = SCREEN_SAVER_MODE_CONFIGURATION;
 
132
                                if (scr_saver_hwnd == NULL)
 
133
                                        scr_saver_hwnd = ::GetForegroundWindow();
 
134
                        }
 
135
                        else if (!::stricmp("/s", argv[1]))
 
136
                        {
 
137
                                scr_saver_mode = SCREEN_SAVER_MODE_SAVER;
 
138
                        }
 
139
                        else if (!::stricmp("/a", argv[1]))
 
140
                        {
 
141
                                scr_saver_mode = SCREEN_SAVER_MODE_PASSWORD;
 
142
                        }
 
143
                        else if (!::stricmp("/p", argv[1])
 
144
                                 || !::stricmp("/l", argv[1]))
 
145
                        {
 
146
                                scr_saver_mode = SCREEN_SAVER_MODE_PREVIEW;
 
147
                        }
 
148
                }
 
149
        }
 
150
        return ret;
 
151
}
 
152
 
 
153
#endif /* WIN32 */
 
154
 
99
155
void usage(char* program)
100
156
{
101
157
        char * consoleoption;
107
163
        
108
164
        printf("usage:   %s [-w [-p l t w h]] %s[-g gamengineoptions] "
109
165
                "[-s stereomode] filename.blend\n", program, consoleoption);
 
166
        printf("  -h: Prints this command summary\n");
110
167
        printf("  -w: display in a window\n");
111
168
        printf("  -p: specify window position\n");
112
169
        printf("       l = window left coordinate\n");
113
170
        printf("       t = window top coordinate\n");
114
171
        printf("       w = window width\n");
115
172
        printf("       h = window height\n");
116
 
/*      printf("  -f: start game in full screen mode\n");
 
173
        printf("  -f: start game in full screen mode\n");
117
174
        printf("       fw = full screen mode pixel width\n");
118
175
        printf("       fh = full screen mode pixel height\n");
119
176
        printf("       fb = full screen mode bits per pixel\n");
120
 
        printf("       ff = full screen mode frequency\n"); */
 
177
        printf("       ff = full screen mode frequency\n");
121
178
        printf("  -s: start player in stereo\n");
122
 
        printf("       stereomode = hwpageflip or syncdoubling depending on the type of stereo you want\n");
 
179
        printf("       stereomode: hwpageflip       (Quad buffered shutter glasses)\n");
 
180
        printf("                   syncdoubling     (Above Below)\n");
 
181
        printf("                   sidebyside       (Left Right)\n");
 
182
        printf("                   anaglyph         (Red-Blue glasses)\n");
 
183
        printf("                   vinterlace       (Vertical interlace for autostereo display)\n");
 
184
        printf("                             depending on the type of stereo you want\n");
123
185
#ifdef _WIN32
124
186
        printf("  -c: keep console window open\n");
125
187
#endif
 
188
        printf("  -g: game engine options:\n");
 
189
        printf("       Name            Default      Description\n");
 
190
        printf("       ----------------------------------------\n");
 
191
        printf("       fixedtime          0         Do the same timestep each frame \"Enable all frames\"\n");
 
192
        printf("       nomipmap           0         Disable mipmaps\n");
 
193
        printf("       show_framerate     0         Show the frame rate\n");
 
194
        printf("       show_properties    0         Show debug properties\n");
 
195
        printf("       show_profile       0         Show profiling information\n");
 
196
        printf("       vertexarrays       1         Enable vertex arrays\n");
126
197
        printf("\n");
127
198
        printf("example: %s -p 10 10 320 200 -g noaudio c:\\loadtest.blend\n", program);
 
199
        printf("example: %s -g vertexarrays = 0 c:\\loadtest.blend\n", program);
128
200
}
129
201
 
130
202
char *get_filename(int argc, char **argv) {
212
284
        int i;
213
285
        bool error = false;
214
286
        SYS_SystemHandle syshandle = SYS_GetSystem();
215
 
        bool fullScreen = true;
216
 
        bool fullScreenParFound = true;
 
287
        bool fullScreen = false;
 
288
        bool fullScreenParFound = false;
217
289
        bool windowParFound = false;
218
290
        bool closeConsole = true;
219
 
        int stereomode = RAS_IRasterizer::RAS_STEREO_NOSTEREO;
 
291
        RAS_IRasterizer::StereoMode stereomode = RAS_IRasterizer::RAS_STEREO_NOSTEREO;
220
292
        bool stereoWindow = false;
221
293
        bool stereoParFound = false;
222
294
        int windowLeft = 100;
225
297
        int windowHeight = 480;
226
298
        GHOST_TUns32 fullScreenWidth = 0;
227
299
        GHOST_TUns32 fullScreenHeight= 0;
228
 
        int fullScreenBpp = 16;
 
300
        int fullScreenBpp = 32;
229
301
        int fullScreenFrequency = 60;
230
302
        
231
303
#ifdef __linux__
258
330
#endif // __APPLE__
259
331
        
260
332
        GEN_init_messaging_system();
261
 
        
 
333
 
262
334
        // Parse command line options
263
335
#ifndef NDEBUG
264
336
        printf("argv[0] = '%s'\n", argv[0]);
265
337
#endif
266
 
        for (i = 1; (i < argc) && !error; i++)
 
338
 
 
339
 
 
340
#ifdef WIN32
 
341
        if (scr_saver_init(argc, argv))
 
342
        {
 
343
                switch (scr_saver_mode)
 
344
                {
 
345
                case SCREEN_SAVER_MODE_CONFIGURATION:
 
346
                        MessageBox(scr_saver_hwnd, "This screen saver has no options that you can set", "Screen Saver", MB_OK);
 
347
                        break;
 
348
                case SCREEN_SAVER_MODE_PASSWORD:
 
349
                        /* This is W95 only, which we currently do not support.
 
350
                           Fall-back to normal screen saver behaviour in that case... */
 
351
                case SCREEN_SAVER_MODE_SAVER:
 
352
                        fullScreen = true;
 
353
                        fullScreenParFound = true;
 
354
                        break;
 
355
 
 
356
                case SCREEN_SAVER_MODE_PREVIEW:
 
357
                        /* This will actually be handled somewhere below... */
 
358
                        break;
 
359
                }
 
360
        }
 
361
#endif
 
362
        for (i = 1; (i < argc) && !error 
 
363
#ifdef WIN32
 
364
                && scr_saver_mode == SCREEN_SAVER_MODE_NONE
 
365
#endif
 
366
                ;)
 
367
 
267
368
        {
268
369
#ifndef NDEBUG
269
 
                printf("argv[%d] = '%s'\n", i, argv[i]);
 
370
                printf("argv[%d] = '%s'   , %i\n", i, argv[i],argc);
270
371
#endif
271
 
                
272
372
                if (argv[i][0] == '-')
273
373
                {
274
374
                        switch (argv[i][1])
288
388
                                                        {
289
389
                                                                i++;
290
390
                                                                // Assignment
 
391
                                                                SYS_WriteCommandLineInt(syshandle, paramname, atoi(argv[i]));
 
392
                                                                SYS_WriteCommandLineFloat(syshandle, paramname, atof(argv[i]));
291
393
                                                                SYS_WriteCommandLineString(syshandle, paramname, argv[i]);
 
394
#ifndef NDEBUG
 
395
                                                                printf("%s = '%s'\n", paramname, argv[i]);
 
396
#endif
 
397
                                                                i++;
292
398
                                                        }
293
399
                                                        else
294
400
                                                        {
298
404
                                                }
299
405
                                                else
300
406
                                                {
301
 
                                                        SYS_WriteCommandLineInt(syshandle, argv[i], 1);
 
407
                                                        SYS_WriteCommandLineInt(syshandle, argv[i++], 1);
302
408
                                                }
303
409
                                        }
304
410
                                }
313
419
                                                windowLeft = atoi(argv[i++]);
314
420
                                                windowTop = atoi(argv[i++]);
315
421
                                                windowWidth = atoi(argv[i++]);
316
 
                                                windowHeight = atoi(argv[i]);
 
422
                                                windowHeight = atoi(argv[i++]);
317
423
                                                windowParFound = true;
318
424
                                        }
319
425
                                        else
321
427
                                                error = true;
322
428
                                                printf("error: too few options for window argument.\n");
323
429
                                        }
324
 
                                }
325
 
                                break;
 
430
                                } else { /* mac specific */
326
431
                                
 
432
                    if (strncmp(argv[i], "-psn_", 5)==0) 
 
433
                        i++; /* skip process serial number */
 
434
                                }
 
435
                                break;
 
436
                        case 'f':
 
437
                                i++;
 
438
                                fullScreen = true;
 
439
                                fullScreenParFound = true;
 
440
                                if ((i + 2) < argc && argv[i][0] != '-' && argv[i+1][0] != '-')
 
441
                                {
 
442
                                        fullScreenWidth = atoi(argv[i++]);
 
443
                                        fullScreenHeight = atoi(argv[i++]);
 
444
                                        if ((i + 1) < argc && argv[i][0] != '-')
 
445
                                        {
 
446
                                                fullScreenBpp = atoi(argv[i++]);
 
447
                                                if ((i + 1) < argc && argv[i][0] != '-')
 
448
                                                        fullScreenFrequency = atoi(argv[i++]);
 
449
                                        }
 
450
                                }
 
451
                                break;
327
452
                        case 'w':
328
453
                                // Parse window position and size options
329
454
                                {
330
455
                                        fullScreen = false;
331
 
                                                fullScreenParFound = true;
 
456
                                        fullScreenParFound = true;
332
457
                                        i++;
333
458
                                }
334
459
                                break;
 
460
                        case 'h':
 
461
                                usage(argv[0]);
 
462
                                return 0;
 
463
                                break;
335
464
                        case 'c':
336
465
                                i++;
337
466
                                closeConsole = false;
340
469
                                i++;
341
470
                                if ((i + 1) < argc)
342
471
                                {
 
472
                                        stereomode = (RAS_IRasterizer::StereoMode) atoi(argv[i]);
 
473
                                        if (stereomode < RAS_IRasterizer::RAS_STEREO_NOSTEREO || stereomode >= RAS_IRasterizer::RAS_STEREO_MAXSTEREO)
 
474
                                                stereomode = RAS_IRasterizer::RAS_STEREO_NOSTEREO;
 
475
                                        
343
476
                                        if(!strcmp(argv[i], "nostereo"))  // ok, redundant but clear
344
477
                                                stereomode = RAS_IRasterizer::RAS_STEREO_NOSTEREO;
345
478
                                        
350
483
                                        }
351
484
                                        if(!strcmp(argv[i], "syncdoubling"))
352
485
                                                stereomode = RAS_IRasterizer::RAS_STEREO_ABOVEBELOW;
 
486
                                        
 
487
                                        if(!strcmp(argv[i], "anaglyph"))
 
488
                                                stereomode = RAS_IRasterizer::RAS_STEREO_ANAGLYPH;
 
489
                                        
 
490
                                        if(!strcmp(argv[i], "sidebyside"))
 
491
                                                stereomode = RAS_IRasterizer::RAS_STEREO_SIDEBYSIDE;
 
492
                                        
 
493
                                        if(!strcmp(argv[i], "vinterlace"))
 
494
                                                stereomode = RAS_IRasterizer::RAS_STEREO_VINTERLACE;
 
495
                                        
353
496
#if 0
354
497
                                        // future stuff
355
498
                                        if(strcmp(argv[i], "stencil")
365
508
                                        printf("error: too few options for stereo argument.\n");
366
509
                                }
367
510
                                break;
 
511
                        default:
 
512
                                printf("Unkown argument: %s\n", argv[i++]);
 
513
                                break;
368
514
                        }
369
515
                }
370
516
                else
371
517
                {
 
518
                        i++;
372
519
                }
373
520
        }
374
521
        
383
530
                usage(argv[0]);
384
531
        }
385
532
        else
 
533
#ifdef WIN32
 
534
                if (scr_saver_mode != SCREEN_SAVER_MODE_CONFIGURATION)
 
535
#endif
386
536
        {
387
537
#ifdef __APPLE__
388
538
                //SYS_WriteCommandLineInt(syshandle, "show_framerate", 1);
400
550
                        GHOST_ISystem* system = GHOST_ISystem::getSystem();
401
551
                        assertd(system);
402
552
                        
403
 
                        system->getMainDisplayDimensions(fullScreenWidth, fullScreenHeight);
 
553
                        if (!fullScreenWidth || !fullScreenHeight)
 
554
                                system->getMainDisplayDimensions(fullScreenWidth, fullScreenHeight);
404
555
                        // process first batch of events. If the user
405
556
                        // drops a file on top off the blenderplayer icon, we 
406
557
                        // recieve an event with the filename
488
639
                                                // Check whether the game should be displayed in stereo
489
640
                                                if (!stereoParFound)
490
641
                                                {
491
 
                                                        if(scene->r.stereomode == RAS_IRasterizer::RAS_STEREO_NOSTEREO)  // ok, redundant but clear
492
 
                                                                stereomode = RAS_IRasterizer::RAS_STEREO_NOSTEREO;
493
 
                                                        
494
 
                                                        // only the hardware pageflip method needs a stereo window
495
 
                                                        if(scene->r.stereomode == RAS_IRasterizer::RAS_STEREO_QUADBUFFERED) {
496
 
                                                                stereomode = RAS_IRasterizer::RAS_STEREO_QUADBUFFERED;
 
642
                                                        stereomode = (RAS_IRasterizer::StereoMode) scene->r.stereomode;
 
643
                                                        if (stereomode == RAS_IRasterizer::RAS_STEREO_QUADBUFFERED)
497
644
                                                                stereoWindow = true;
498
 
                                                        }
499
 
                                                        if(scene->r.stereomode == RAS_IRasterizer::RAS_STEREO_ABOVEBELOW)
500
 
                                                                stereomode = RAS_IRasterizer::RAS_STEREO_ABOVEBELOW;
501
 
#if 0
502
 
                                                        // future stuff
503
 
                                                        if(scene->r.stereomode == RAS_IRasterizer::RAS_STEREO_STENCIL)
504
 
                                                                stereomode = RAS_STEREO_STENCIL;
505
 
#endif
506
645
                                                }
507
646
                                                
508
647
                                                //                                      GPG_Application app (system, maggie, startscenename);
514
653
                                                        
515
654
                                                        if (fullScreen)
516
655
                                                        {
517
 
                                                                app.startFullScreen(fullScreenWidth, fullScreenHeight, fullScreenBpp, fullScreenFrequency,
518
 
                                                                        stereoWindow, stereomode);
 
656
#ifdef WIN32
 
657
                                                                if (scr_saver_mode == SCREEN_SAVER_MODE_SAVER)
 
658
                                                                {
 
659
                                                                        app.startScreenSaverFullScreen(fullScreenWidth, fullScreenHeight, fullScreenBpp, fullScreenFrequency,
 
660
                                                                                stereoWindow, stereomode);
 
661
                                                                }
 
662
                                                                else
 
663
#endif
 
664
                                                                {
 
665
                                                                        app.startFullScreen(fullScreenWidth, fullScreenHeight, fullScreenBpp, fullScreenFrequency,
 
666
                                                                                stereoWindow, stereomode);
 
667
                                                                }
519
668
                                                        }
520
669
                                                        else
521
670
                                                        {
551
700
                                                                {
552
701
                                                                        title = "blenderplayer";
553
702
                                                                }
554
 
                                                                app.startWindow(title, windowLeft, windowTop, windowWidth, windowHeight,
555
 
                                                                        stereoWindow, stereomode);
 
703
#ifdef WIN32
 
704
                                                                if (scr_saver_mode == SCREEN_SAVER_MODE_PREVIEW)
 
705
                                                                {
 
706
                                                                        app.startScreenSaverPreview(scr_saver_hwnd, stereoWindow, stereomode);
 
707
                                                                }
 
708
                                                                else
 
709
#endif
 
710
                                                                {
 
711
                                                                        app.startWindow(title, windowLeft, windowTop, windowWidth, windowHeight,
 
712
                                                                                stereoWindow, stereomode);
 
713
                                                                }
556
714
                                                        }
557
715
                                                }
558
716
                                                else