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

« back to all changes in this revision

Viewing changes to source/gameengine/GamePlayer/ghost/GPG_Application.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_Application.cpp,v 1.7 2004/05/02 23:45:03 kester Exp $
 
2
 * $Id: GPG_Application.cpp,v 1.14 2005/03/25 10:33:36 kester Exp $
3
3
 *
4
4
 * ***** BEGIN GPL/BL DUAL LICENSE BLOCK *****
5
5
 *
37
37
 
38
38
#ifdef WIN32
39
39
        #pragma warning (disable:4786) // suppress stl-MSVC debug info warning
 
40
        #include <windows.h>
 
41
#endif
 
42
 
 
43
#ifdef __APPLE__
 
44
#include <OpenGL/gl.h>
 
45
#include <OpenGL/glu.h>
 
46
#else
 
47
#include <GL/gl.h>
 
48
#include <GL/glu.h>
40
49
#endif
41
50
 
42
51
#include "GPG_Application.h"
43
52
 
44
53
#include <iostream>
45
 
#include <assert.h>
 
54
#include <MT_assert.h>
46
55
 
47
56
/**********************************
48
57
 * Begin Blender include block
99
108
static const int kTimerFreq = 10;
100
109
 
101
110
GPG_Application::GPG_Application(GHOST_ISystem* system, struct Main *maggie, STR_String startSceneName)
102
 
        : m_maggie(maggie), m_startSceneName(startSceneName), m_exitRequested(0),
103
 
          m_system(system), m_mainWindow(0), m_frameTimer(0), m_cursor(GHOST_kStandardCursorFirstCursor),
104
 
          m_mouse(0), m_keyboard(0), m_rasterizer(0), m_canvas(0), m_rendertools(0), m_kxsystem(0), m_networkdevice(0), m_audiodevice(0), m_sceneconverter(0),
105
 
          m_engineInitialized(0), m_engineRunning(0), m_ketsjiengine(0)
 
111
        : m_startSceneName(startSceneName), 
 
112
          m_maggie(maggie), 
 
113
          m_exitRequested(0),
 
114
          m_system(system), 
 
115
          m_mainWindow(0), 
 
116
          m_frameTimer(0), 
 
117
          m_cursor(GHOST_kStandardCursorFirstCursor),
 
118
          m_engineInitialized(0), 
 
119
          m_engineRunning(0), 
 
120
          m_ketsjiengine(0),
 
121
          m_kxsystem(0), 
 
122
          m_keyboard(0), 
 
123
          m_mouse(0), 
 
124
          m_canvas(0), 
 
125
          m_rendertools(0), 
 
126
          m_rasterizer(0), 
 
127
          m_sceneconverter(0),
 
128
          m_networkdevice(0), 
 
129
          m_audiodevice(0)
106
130
{
107
131
        fSystem = system;
108
132
}
132
156
}
133
157
 
134
158
 
 
159
#ifdef WIN32
 
160
#define SCR_SAVE_MOUSE_MOVE_THRESHOLD 15
 
161
 
 
162
static HWND found_ghost_window_hwnd;
 
163
static GHOST_IWindow* ghost_window_to_find;
 
164
static WNDPROC ghost_wnd_proc;
 
165
static POINT scr_save_mouse_pos;
 
166
 
 
167
static LRESULT CALLBACK screenSaverWindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
 
168
{
 
169
        BOOL close = FALSE;
 
170
        switch (uMsg)
 
171
        {
 
172
                case WM_MOUSEMOVE:
 
173
                { 
 
174
                        POINT pt; 
 
175
                        GetCursorPos(&pt);
 
176
                        LONG dx = scr_save_mouse_pos.x - pt.x;
 
177
                        LONG dy = scr_save_mouse_pos.y - pt.y;
 
178
                        if (abs(dx) > SCR_SAVE_MOUSE_MOVE_THRESHOLD
 
179
                            || abs(dy) > SCR_SAVE_MOUSE_MOVE_THRESHOLD)
 
180
                        {
 
181
                                close = TRUE;
 
182
                        }
 
183
                        scr_save_mouse_pos = pt;
 
184
                        break;
 
185
                }
 
186
                case WM_LBUTTONDOWN: 
 
187
                case WM_MBUTTONDOWN: 
 
188
                case WM_RBUTTONDOWN: 
 
189
                case WM_KEYDOWN:
 
190
                        close = TRUE;
 
191
        }
 
192
        if (close)
 
193
                PostMessage(hwnd,WM_CLOSE,0,0);
 
194
        return CallWindowProc(ghost_wnd_proc, hwnd, uMsg, wParam, lParam);
 
195
}
 
196
 
 
197
BOOL CALLBACK findGhostWindowHWNDProc(HWND hwnd, LPARAM lParam)
 
198
{
 
199
        GHOST_IWindow *p = (GHOST_IWindow*) GetWindowLong(hwnd, GWL_USERDATA);
 
200
        BOOL ret = TRUE;
 
201
        if (p == ghost_window_to_find)
 
202
        {
 
203
                found_ghost_window_hwnd = hwnd;
 
204
                ret = FALSE;
 
205
        }
 
206
        return ret;
 
207
}
 
208
 
 
209
static HWND findGhostWindowHWND(GHOST_IWindow* window)
 
210
{
 
211
        found_ghost_window_hwnd = NULL;
 
212
        ghost_window_to_find = window;
 
213
        EnumWindows(findGhostWindowHWNDProc, NULL);
 
214
        return found_ghost_window_hwnd;
 
215
}
 
216
 
 
217
bool GPG_Application::startScreenSaverPreview(
 
218
        HWND parentWindow,
 
219
        const bool stereoVisual,
 
220
        const int stereoMode)
 
221
{
 
222
        bool success = false;
 
223
 
 
224
        RECT rc;
 
225
        if (GetWindowRect(parentWindow, &rc))
 
226
        {
 
227
                int windowWidth = rc.right - rc.left;
 
228
                int windowHeight = rc.bottom - rc.top;
 
229
                STR_String title = "";
 
230
                                                        
 
231
                m_mainWindow = fSystem->createWindow(title, 0, 0, windowWidth, windowHeight, GHOST_kWindowStateMinimized,
 
232
                        GHOST_kDrawingContextTypeOpenGL, stereoVisual);
 
233
                if (!m_mainWindow) {
 
234
                        printf("error: could not create main window\n");
 
235
                        exit(-1);
 
236
                }
 
237
 
 
238
                HWND ghost_hwnd = findGhostWindowHWND(m_mainWindow);
 
239
                if (!ghost_hwnd) {
 
240
                        printf("error: could find main window\n");
 
241
                        exit(-1);
 
242
                }
 
243
 
 
244
                SetParent(ghost_hwnd, parentWindow);
 
245
                LONG style = GetWindowLong(ghost_hwnd, GWL_STYLE);
 
246
                LONG exstyle = GetWindowLong(ghost_hwnd, GWL_EXSTYLE);
 
247
 
 
248
                RECT adjrc = { 0, 0, windowWidth, windowHeight };
 
249
                AdjustWindowRectEx(&adjrc, style, FALSE, exstyle);
 
250
 
 
251
                style = (style & (~(WS_POPUP|WS_OVERLAPPEDWINDOW|WS_OVERLAPPED|WS_CAPTION|WS_SYSMENU|WS_THICKFRAME|WS_MINIMIZEBOX|WS_MAXIMIZEBOX|WS_TILEDWINDOW ))) | WS_CHILD;
 
252
                SetWindowLong(ghost_hwnd, GWL_STYLE, style);
 
253
                SetWindowPos(ghost_hwnd, NULL, adjrc.left, adjrc.top, 0, 0, SWP_NOZORDER|SWP_NOSIZE|SWP_NOACTIVATE);
 
254
 
 
255
                /* Check the size of the client rectangle of the window and resize the window
 
256
                 * so that the client rectangle has the size requested.
 
257
                 */
 
258
                m_mainWindow->setClientSize(windowWidth, windowHeight);
 
259
 
 
260
                success = initEngine(m_mainWindow, stereoMode);
 
261
                if (success) {
 
262
                        success = startEngine();
 
263
                }
 
264
 
 
265
        }
 
266
        return success;
 
267
}
 
268
 
 
269
bool GPG_Application::startScreenSaverFullScreen(
 
270
                int width,
 
271
                int height,
 
272
                int bpp,int frequency,
 
273
                const bool stereoVisual,
 
274
                const int stereoMode)
 
275
{
 
276
        bool ret = startFullScreen(width, height, bpp, frequency, stereoVisual, stereoMode);
 
277
        if (ret)
 
278
        {
 
279
                HWND ghost_hwnd = findGhostWindowHWND(m_mainWindow);
 
280
                if (ghost_hwnd != NULL)
 
281
                {
 
282
                        GetCursorPos(&scr_save_mouse_pos);
 
283
                        ghost_wnd_proc = (WNDPROC) GetWindowLong(ghost_hwnd, GWL_WNDPROC);
 
284
                        SetWindowLong(ghost_hwnd,GWL_WNDPROC, (LONG) screenSaverWindowProc);
 
285
                }
 
286
        }
 
287
        return ret;
 
288
}
 
289
 
 
290
#endif
135
291
 
136
292
bool GPG_Application::startWindow(STR_String& title,
137
293
        int windowLeft,
327
483
                        return false;
328
484
                
329
485
                // SYS_WriteCommandLineInt(syshandle, "fixedtime", 0);
330
 
                SYS_WriteCommandLineInt(syshandle, "vertexarrays",1);           
331
 
                //bool properties       = (SYS_GetCommandLineInt(syshandle, "show_properties", 0) != 0);
332
 
                //bool profile = (SYS_GetCommandLineInt(syshandle, "show_profile", 0) != 0);
 
486
                // SYS_WriteCommandLineInt(syshandle, "vertexarrays",1);                
 
487
                bool properties = (SYS_GetCommandLineInt(syshandle, "show_properties", 0) != 0);
 
488
                bool profile = (SYS_GetCommandLineInt(syshandle, "show_profile", 0) != 0);
333
489
                bool frameRate = (SYS_GetCommandLineInt(syshandle, "show_framerate", 0) != 0);
334
490
                bool useVertexArrays = SYS_GetCommandLineInt(syshandle,"vertexarrays",1) != 0;
335
491
                // create the canvas, rasterizer and rendertools
346
502
                        m_rasterizer = new RAS_VAOpenGLRasterizer(m_canvas);
347
503
                else
348
504
                        m_rasterizer = new RAS_OpenGLRasterizer(m_canvas);
349
 
                m_rasterizer->SetStereoMode(stereoMode);
 
505
                m_rasterizer->SetStereoMode((RAS_IRasterizer::StereoMode) stereoMode);
350
506
                if (!m_rasterizer)
351
507
                        goto initFailed;
352
508
                                                
391
547
                m_ketsjiengine->SetTimingDisplay(frameRate, false, false);
392
548
 
393
549
                m_ketsjiengine->SetUseFixedTime(false);
394
 
                //m_ketsjiengine->SetTimingDisplay(frameRate, profile, properties);
 
550
                m_ketsjiengine->SetTimingDisplay(frameRate, profile, properties);
395
551
 
396
552
                m_engineInitialized = true;
397
553
        }
459
615
                        startscenename);
460
616
                
461
617
                // some python things
462
 
                PyObject* m_dictionaryobject = initGamePythonScripting("Ketsji", psl_Lowest);
 
618
                PyObject* m_dictionaryobject = initGamePlayerPythonScripting("Ketsji", psl_Lowest);
463
619
                m_ketsjiengine->SetPythonDictionary(m_dictionaryobject);
464
620
                initRasterizer(m_rasterizer, m_canvas);
465
621
                initGameLogic(startscene);
569
725
bool GPG_Application::handleWheel(GHOST_IEvent* event)
570
726
{
571
727
        bool handled = false;
572
 
        assert(event);
 
728
        MT_assert(event);
573
729
        if (m_mouse) 
574
730
        {
575
731
                GHOST_TEventDataPtr eventData = ((GHOST_IEvent*)event)->getData();
588
744
bool GPG_Application::handleButton(GHOST_IEvent* event, bool isDown)
589
745
{
590
746
        bool handled = false;
591
 
        assert(event);
 
747
        MT_assert(event);
592
748
        if (m_mouse) 
593
749
        {
594
750
                GHOST_TEventDataPtr eventData = ((GHOST_IEvent*)event)->getData();
617
773
bool GPG_Application::handleCursorMove(GHOST_IEvent* event)
618
774
{
619
775
        bool handled = false;
620
 
        assert(event);
 
776
        MT_assert(event);
621
777
        if (m_mouse && m_mainWindow)
622
778
        {
623
779
                GHOST_TEventDataPtr eventData = ((GHOST_IEvent*)event)->getData();
634
790
bool GPG_Application::handleKey(GHOST_IEvent* event, bool isDown)
635
791
{
636
792
        bool handled = false;
637
 
        assert(event);
 
793
        MT_assert(event);
638
794
        if (m_keyboard)
639
795
        {
640
796
                GHOST_TEventDataPtr eventData = ((GHOST_IEvent*)event)->getData();