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:
authorHans Lambermont <hans@lambermont.dyndns.org>2002-10-12 15:37:38 +0400
committerHans Lambermont <hans@lambermont.dyndns.org>2002-10-12 15:37:38 +0400
commit12315f4d0e0ae993805f141f64cb8c73c5297311 (patch)
tree59b45827cd8293cfb727758989c7a74b40183974 /source/gameengine/GamePlayer/ghost
Initial revisionv2.25
Diffstat (limited to 'source/gameengine/GamePlayer/ghost')
-rw-r--r--source/gameengine/GamePlayer/ghost/GPG_Application.cpp607
-rw-r--r--source/gameengine/GamePlayer/ghost/GPG_Application.h138
-rw-r--r--source/gameengine/GamePlayer/ghost/GPG_Canvas.cpp110
-rw-r--r--source/gameengine/GamePlayer/ghost/GPG_Canvas.h64
-rw-r--r--source/gameengine/GamePlayer/ghost/GPG_KeyboardDevice.cpp156
-rw-r--r--source/gameengine/GamePlayer/ghost/GPG_KeyboardDevice.h57
-rw-r--r--source/gameengine/GamePlayer/ghost/GPG_System.cpp56
-rw-r--r--source/gameengine/GamePlayer/ghost/GPG_System.h56
-rw-r--r--source/gameengine/GamePlayer/ghost/GPG_ghost.cpp597
-rw-r--r--source/gameengine/GamePlayer/ghost/Makefile82
10 files changed, 1923 insertions, 0 deletions
diff --git a/source/gameengine/GamePlayer/ghost/GPG_Application.cpp b/source/gameengine/GamePlayer/ghost/GPG_Application.cpp
new file mode 100644
index 00000000000..07ed803b205
--- /dev/null
+++ b/source/gameengine/GamePlayer/ghost/GPG_Application.cpp
@@ -0,0 +1,607 @@
+/**
+ * $Id$
+ *
+ * ***** BEGIN GPL/BL DUAL LICENSE BLOCK *****
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version. The Blender
+ * Foundation also sells licenses for use in proprietary software under
+ * the Blender License. See http://www.blender.org/BL/ for information
+ * about this.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ *
+ * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
+ * All rights reserved.
+ *
+ * The Original Code is: all of this file.
+ *
+ * Contributor(s): none yet.
+ *
+ * ***** END GPL/BL DUAL LICENSE BLOCK *****
+ * GHOST Blender Player application implementation file.
+ */
+
+#ifdef WIN32
+ #pragma warning (disable:4786) // suppress stl-MSVC debug info warning
+#endif
+
+#include "GPG_Application.h"
+
+#include <iostream>
+#include <assert.h>
+
+/**********************************
+ * Begin Blender include block
+ **********************************/
+#ifdef __cplusplus
+extern "C"
+{
+#endif // __cplusplus
+#include "BLI_blenlib.h"
+#include "BLO_readfile.h"
+#ifdef __cplusplus
+}
+#endif // __cplusplus
+/**********************************
+ * End Blender include block
+ **********************************/
+
+
+#include "SYS_System.h"
+#include "KX_KetsjiEngine.h"
+
+// include files needed by "KX_BlenderSceneConverter.h"
+#include "GEN_Map.h"
+#include "SCA_IActuator.h"
+#include "RAS_MeshObject.h"
+#include "RAS_OpenGLRasterizer.h"
+#include "KX_PythonInit.h"
+#include "KX_PyConstraintBinding.h"
+
+#include "KX_BlenderSceneConverter.h"
+#include "NG_LoopBackNetworkDeviceInterface.h"
+#include "SND_DeviceManager.h"
+
+#include "GPC_MouseDevice.h"
+#include "GPC_RenderTools.h"
+#include "GPG_Canvas.h"
+#include "GPG_KeyboardDevice.h"
+#include "GPG_System.h"
+
+#include "STR_String.h"
+
+#include "GHOST_ISystem.h"
+#include "GHOST_IEvent.h"
+#include "GHOST_IEventConsumer.h"
+#include "GHOST_IWindow.h"
+#include "GHOST_Rect.h"
+
+
+static void frameTimerProc(GHOST_ITimerTask* task, GHOST_TUns64 time);
+
+static GHOST_ISystem* fSystem = 0;
+static const int kTimerFreq = 10;
+
+GPG_Application::GPG_Application(GHOST_ISystem* system, struct Main *maggie, STR_String startSceneName)
+ : m_maggie(maggie), m_startSceneName(startSceneName), m_exitRequested(0),
+ m_system(system), m_mainWindow(0), m_frameTimer(0), m_cursor(GHOST_kStandardCursorFirstCursor),
+ 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),
+ m_engineInitialized(0), m_engineRunning(0), m_ketsjiengine(0)
+{
+ fSystem = system;
+}
+
+
+
+GPG_Application::~GPG_Application(void)
+{
+ exitEngine();
+ fSystem->disposeWindow(m_mainWindow);
+}
+
+
+
+bool GPG_Application::SetGameEngineData(struct Main *maggie, STR_String startSceneName)
+{
+ bool result = false;
+
+ if (maggie != NULL && startSceneName != "")
+ {
+ m_maggie = maggie;
+ m_startSceneName = startSceneName;
+ result = true;
+ }
+
+ return result;
+}
+
+
+
+bool GPG_Application::startWindow(STR_String& title,
+ int windowLeft,
+ int windowTop,
+ int windowWidth,
+ int windowHeight,
+ const bool stereoVisual,
+ const int stereoMode)
+{
+ bool success;
+ // Create the main window
+ //STR_String title ("Blender Player - GHOST");
+ m_mainWindow = fSystem->createWindow(title, windowLeft, windowTop, windowWidth, windowHeight, GHOST_kWindowStateNormal,
+ GHOST_kDrawingContextTypeOpenGL, stereoVisual);
+ if (!m_mainWindow) {
+ printf("error: could not create main window\n");
+ exit(-1);
+ }
+
+ /* Check the size of the client rectangle of the window and resize the window
+ * so that the client rectangle has the size requested.
+ */
+ m_mainWindow->setClientSize(windowWidth, windowHeight);
+
+ success = initEngine(m_mainWindow, stereoMode);
+ if (success) {
+ success = startEngine();
+ }
+ return success;
+}
+
+
+
+bool GPG_Application::startFullScreen(
+ int width,
+ int height,
+ int bpp,int frequency,
+ const bool stereoVisual,
+ const int stereoMode)
+{
+ bool success;
+ // Create the main window
+ GHOST_DisplaySetting setting;
+ setting.xPixels = width;
+ setting.yPixels = height;
+ setting.bpp = bpp;
+ setting.frequency = frequency;
+
+ fSystem->beginFullScreen(setting, &m_mainWindow, stereoVisual);
+
+ success = initEngine(m_mainWindow, stereoMode);
+ if (success) {
+ success = startEngine();
+ }
+ return success;
+}
+
+
+
+bool GPG_Application::StartGameEngine(int stereoMode)
+{
+ bool success = initEngine(m_mainWindow, stereoMode);
+
+ if (success)
+ success = startEngine();
+
+ return success;
+}
+
+
+
+void GPG_Application::StopGameEngine()
+{
+ exitEngine();
+}
+
+
+
+bool GPG_Application::processEvent(GHOST_IEvent* event)
+{
+ bool handled = true;
+
+ switch (event->getType())
+ {
+ case GHOST_kEventUnknown:
+ break;
+
+ case GHOST_kEventButtonDown:
+ handled = handleButton(event, true);
+ break;
+
+ case GHOST_kEventButtonUp:
+ handled = handleButton(event, false);
+ break;
+
+ case GHOST_kEventCursorMove:
+ handled = handleCursorMove(event);
+ break;
+
+ case GHOST_kEventKeyDown:
+ handleKey(event, true);
+ break;
+
+ case GHOST_kEventKeyUp:
+ handleKey(event, false);
+ break;
+
+
+ case GHOST_kEventWindowClose:
+ m_exitRequested = KX_EXIT_REQUEST_OUTSIDE;
+ break;
+
+ case GHOST_kEventWindowActivate:
+ handled = false;
+ break;
+ case GHOST_kEventWindowDeactivate:
+ handled = false;
+ break;
+
+ case GHOST_kEventWindowUpdate:
+ {
+ GHOST_IWindow* window = event->getWindow();
+ if (!m_system->validWindow(window)) break;
+ // Update the state of the game engine
+ if (m_kxsystem && !m_exitRequested)
+ {
+ // Proceed to next frame
+ window->activateDrawingContext();
+
+ // first check if we want to exit
+ m_exitRequested = m_ketsjiengine->GetExitCode();
+
+ // kick the engine
+ m_ketsjiengine->NextFrame();
+
+ // render the frame
+ m_ketsjiengine->Render();
+ }
+ m_exitString = m_ketsjiengine->GetExitString();
+ }
+ break;
+
+ case GHOST_kEventWindowSize:
+ {
+ GHOST_IWindow* window = event->getWindow();
+ if (!m_system->validWindow(window)) break;
+ if (m_canvas) {
+ GHOST_Rect bnds;
+ window->getClientBounds(bnds);
+ m_canvas->Resize(bnds.getWidth(), bnds.getHeight());
+ }
+ }
+ break;
+
+ default:
+ handled = false;
+ break;
+ }
+ return handled;
+}
+
+
+
+int GPG_Application::getExitRequested(void)
+{
+ return m_exitRequested;
+}
+
+
+
+const STR_String& GPG_Application::getExitString(void)
+{
+ return m_exitString;
+}
+
+
+
+bool GPG_Application::initEngine(GHOST_IWindow* window, const int stereoMode)
+{
+ if (!m_engineInitialized)
+ {
+ // get and set the preferences
+ SYS_SystemHandle syshandle = SYS_GetSystem();
+ if (syshandle)
+ {
+ // SYS_WriteCommandLineInt(syshandle, "fixedtime", 0);
+ SYS_WriteCommandLineInt(syshandle, "vertexarrays",1);
+ //bool properties = (SYS_GetCommandLineInt(syshandle, "show_properties", 0) != 0);
+ //bool profile = (SYS_GetCommandLineInt(syshandle, "show_profile", 0) != 0);
+ //bool frameRate = (SYS_GetCommandLineInt(syshandle, "show_framerate", 0) != 0);
+
+ // create the canvas, rasterizer and rendertools
+ m_canvas = new GPG_Canvas(window);
+ if (m_canvas)
+ {
+ m_canvas->Init();
+ m_rendertools = new GPC_RenderTools();
+ if (m_rendertools)
+ {
+ m_rasterizer = new RAS_OpenGLRasterizer(m_canvas);
+ m_rasterizer->SetStereoMode(stereoMode);
+ if (m_rasterizer)
+ {
+ // create the inputdevices
+ m_keyboard = new GPG_KeyboardDevice();
+ if (m_keyboard)
+ {
+ m_mouse = new GPC_MouseDevice();
+ if (m_mouse)
+ {
+ // create a networkdevice
+ m_networkdevice = new NG_LoopBackNetworkDeviceInterface();
+ if (m_networkdevice)
+ {
+ // get an audiodevice
+ SND_DeviceManager::Subscribe();
+ m_audiodevice = SND_DeviceManager::Instance();
+ if (m_audiodevice)
+ {
+ m_audiodevice->UseCD();
+ // create a ketsjisystem (only needed for timing and stuff)
+ m_kxsystem = new GPG_System (m_system);
+ if (m_kxsystem)
+ {
+ // create the ketsjiengine
+ m_ketsjiengine = new KX_KetsjiEngine(m_kxsystem);
+
+ // set the devices
+ m_ketsjiengine->SetKeyboardDevice(m_keyboard);
+ m_ketsjiengine->SetMouseDevice(m_mouse);
+ m_ketsjiengine->SetNetworkDevice(m_networkdevice);
+ m_ketsjiengine->SetCanvas(m_canvas);
+ m_ketsjiengine->SetRenderTools(m_rendertools);
+ m_ketsjiengine->SetRasterizer(m_rasterizer);
+ m_ketsjiengine->SetNetworkDevice(m_networkdevice);
+ m_ketsjiengine->SetAudioDevice(m_audiodevice);
+
+ m_ketsjiengine->SetUseFixedTime(false);
+ //m_ketsjiengine->SetTimingDisplay(frameRate, profile, properties);
+
+ m_engineInitialized = true;
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+
+ return m_engineInitialized;
+}
+
+
+
+bool GPG_Application::startEngine(void)
+{
+ if (m_engineRunning) {
+ return false;
+ }
+
+ // Temporary hack to disable banner display for NaN approved content.
+ /*
+ m_canvas->SetBannerDisplayEnabled(true);
+ Camera* cam;
+ cam = (Camera*)G.scene->camera->data;
+ if (cam) {
+ if (((cam->flag) & 48)==48) {
+ m_canvas->SetBannerDisplayEnabled(false);
+ }
+ }
+ else {
+ showError(CString("Camera data invalid."));
+ return false;
+ }
+ */
+
+ // create a scene converter, create and convert the stratingscene
+ m_sceneconverter = new KX_BlenderSceneConverter(m_maggie, m_ketsjiengine);
+ if (m_sceneconverter)
+ {
+ STR_String startscenename = m_startSceneName.Ptr();
+ m_ketsjiengine->SetSceneConverter(m_sceneconverter);
+
+ // if (always_use_expand_framing)
+ // sceneconverter->SetAlwaysUseExpandFraming(true);
+
+
+ KX_Scene* startscene = new KX_Scene(m_keyboard,
+ m_mouse,
+ m_networkdevice,
+ m_audiodevice,
+ startscenename);
+
+ // some python things
+ PyObject* m_dictionaryobject = initGamePythonScripting("Ketsji", psl_Lowest);
+ m_ketsjiengine->SetPythonDictionary(m_dictionaryobject);
+ initRasterizer(m_rasterizer, m_canvas);
+ initGameLogic(startscene);
+ initGameKeys();
+ initPythonConstraintBinding();
+
+ m_sceneconverter->ConvertScene(
+ startscenename,
+ startscene,
+ m_dictionaryobject,
+ m_keyboard,
+ m_rendertools,
+ m_canvas);
+ m_ketsjiengine->AddScene(startscene);
+
+ // Create a timer that is used to kick the engine
+ if (!m_frameTimer) {
+ m_frameTimer = m_system->installTimer(0, kTimerFreq, frameTimerProc, m_mainWindow);
+ }
+ m_rasterizer->Init();
+ m_ketsjiengine->StartEngine();
+ m_engineRunning = true;
+
+ }
+
+ if (!m_engineRunning)
+ {
+ stopEngine();
+ }
+
+ return m_engineRunning;
+}
+
+
+void GPG_Application::stopEngine()
+{
+ // when exiting the mainloop
+ exitGamePythonScripting();
+ m_ketsjiengine->StopEngine();
+ m_networkdevice->Disconnect();
+
+ if (m_sceneconverter) {
+ delete m_sceneconverter;
+ m_sceneconverter = 0;
+ }
+ if (m_system && m_frameTimer) {
+ m_system->removeTimer(m_frameTimer);
+ m_frameTimer = 0;
+ }
+ m_engineRunning = false;
+}
+
+
+void GPG_Application::exitEngine()
+{
+ if (m_ketsjiengine)
+ {
+ stopEngine();
+ delete m_ketsjiengine;
+ m_ketsjiengine = 0;
+ }
+ if (m_kxsystem)
+ {
+ delete m_kxsystem;
+ m_kxsystem = 0;
+ }
+ if (m_audiodevice)
+ {
+ SND_DeviceManager::Unsubscribe();
+ m_audiodevice = 0;
+ }
+ if (m_networkdevice)
+ {
+ delete m_networkdevice;
+ m_networkdevice = 0;
+ }
+ if (m_mouse)
+ {
+ delete m_mouse;
+ m_mouse = 0;
+ }
+ if (m_keyboard)
+ {
+ delete m_keyboard;
+ m_keyboard = 0;
+ }
+ if (m_rasterizer)
+ {
+ delete m_rasterizer;
+ m_rasterizer = 0;
+ }
+ if (m_rendertools)
+ {
+ delete m_rendertools;
+ m_rendertools = 0;
+ }
+ if (m_canvas)
+ {
+ delete m_canvas;
+ m_canvas = 0;
+ }
+
+ m_exitRequested = 0;
+ m_engineInitialized = false;
+}
+
+
+bool GPG_Application::handleButton(GHOST_IEvent* event, bool isDown)
+{
+ bool handled = false;
+ assert(event);
+ if (m_mouse)
+ {
+ GHOST_TEventDataPtr eventData = ((GHOST_IEvent*)event)->getData();
+ GHOST_TEventButtonData* buttonData = static_cast<GHOST_TEventButtonData*>(eventData);
+ GPC_MouseDevice::TButtonId button;
+ switch (buttonData->button)
+ {
+ case GHOST_kButtonMaskMiddle:
+ button = GPC_MouseDevice::buttonMiddle;
+ break;
+ case GHOST_kButtonMaskRight:
+ button = GPC_MouseDevice::buttonRight;
+ break;
+ case GHOST_kButtonMaskLeft:
+ default:
+ button = GPC_MouseDevice::buttonLeft;
+ break;
+ }
+ m_mouse->ConvertButtonEvent(button, isDown);
+ handled = true;
+ }
+ return handled;
+}
+
+
+bool GPG_Application::handleCursorMove(GHOST_IEvent* event)
+{
+ bool handled = false;
+ assert(event);
+ if (m_mouse && m_mainWindow)
+ {
+ GHOST_TEventDataPtr eventData = ((GHOST_IEvent*)event)->getData();
+ GHOST_TEventCursorData* cursorData = static_cast<GHOST_TEventCursorData*>(eventData);
+ GHOST_TInt32 x, y;
+ m_mainWindow->screenToClient(cursorData->x, cursorData->y, x, y);
+ m_mouse->ConvertMoveEvent(x, y);
+ handled = true;
+ }
+ return handled;
+}
+
+
+bool GPG_Application::handleKey(GHOST_IEvent* event, bool isDown)
+{
+ bool handled = false;
+ assert(event);
+ if (m_keyboard)
+ {
+ GHOST_TEventDataPtr eventData = ((GHOST_IEvent*)event)->getData();
+ GHOST_TEventKeyData* keyData = static_cast<GHOST_TEventKeyData*>(eventData);
+ if (fSystem->getFullScreen()) {
+ if (keyData->key == GHOST_kKeyEsc) {
+ m_exitRequested = KX_EXIT_REQUEST_OUTSIDE;
+ }
+ }
+ m_keyboard->ConvertEvent(keyData->key, isDown);
+ handled = true;
+ }
+ return handled;
+}
+
+
+
+static void frameTimerProc(GHOST_ITimerTask* task, GHOST_TUns64 time)
+{
+ GHOST_IWindow* window = (GHOST_IWindow*)task->getUserData();
+ if (fSystem->validWindow(window)) {
+ window->invalidate();
+ }
+}
diff --git a/source/gameengine/GamePlayer/ghost/GPG_Application.h b/source/gameengine/GamePlayer/ghost/GPG_Application.h
new file mode 100644
index 00000000000..ac502630440
--- /dev/null
+++ b/source/gameengine/GamePlayer/ghost/GPG_Application.h
@@ -0,0 +1,138 @@
+/**
+ * $Id$
+ *
+ * ***** BEGIN GPL/BL DUAL LICENSE BLOCK *****
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version. The Blender
+ * Foundation also sells licenses for use in proprietary software under
+ * the Blender License. See http://www.blender.org/BL/ for information
+ * about this.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ *
+ * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
+ * All rights reserved.
+ *
+ * The Original Code is: all of this file.
+ *
+ * Contributor(s): none yet.
+ *
+ * ***** END GPL/BL DUAL LICENSE BLOCK *****
+ * GHOST Blender Player application declaration file.
+ */
+
+#include "GHOST_IEventConsumer.h"
+
+#include "STR_String.h"
+
+class KX_KetsjiEngine;
+class KX_ISceneConverter;
+class NG_LoopBackNetworkDeviceInterface;
+class SND_IAudioDevice;
+class RAS_IRasterizer;
+class GHOST_IEvent;
+class GHOST_ISystem;
+class GHOST_ITimerTask;
+class GHOST_IWindow;
+class GPC_MouseDevice;
+class GPC_RenderTools;
+class GPG_Canvas;
+class GPG_KeyboardDevice;
+class GPG_System;
+struct Main;
+
+class GPG_Application : public GHOST_IEventConsumer
+{
+public:
+ GPG_Application(GHOST_ISystem* system, struct Main *maggie, STR_String startSceneName);
+ ~GPG_Application(void);
+
+ bool SetGameEngineData(struct Main *maggie, STR_String startSceneName);
+ 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);
+ virtual bool processEvent(GHOST_IEvent* event);
+ int getExitRequested(void);
+ const STR_String& getExitString(void);
+ bool StartGameEngine(int stereoMode);
+ void StopGameEngine();
+
+protected:
+ bool handleButton(GHOST_IEvent* event, bool isDown);
+ bool handleCursorMove(GHOST_IEvent* event);
+ bool handleKey(GHOST_IEvent* event, bool isDown);
+
+ /**
+ * Initializes the game engine.
+ */
+ bool initEngine(GHOST_IWindow* window, int stereoMode);
+
+ /**
+ * Starts the game engine.
+ */
+ bool startEngine(void);
+
+ /**
+ * Stop the game engine.
+ */
+ void stopEngine(void);
+
+ /**
+ * Shuts the game engine down.
+ */
+ void exitEngine(void);
+
+ /* The game data */
+ STR_String m_startSceneName;
+ struct Main* m_maggie;
+
+ /* Exit state. */
+ int m_exitRequested;
+ STR_String m_exitString;
+ /* GHOST system abstraction. */
+ GHOST_ISystem* m_system;
+ /* Main window. */
+ GHOST_IWindow* m_mainWindow;
+ /* Timer to advance frames. */
+ GHOST_ITimerTask* m_frameTimer;
+ /* The cursor shape displayed. */
+ GHOST_TStandardCursor m_cursor;
+
+ /** Engine construction state. */
+ bool m_engineInitialized;
+ /** Engine state. */
+ bool m_engineRunning;
+
+ /** the gameengine itself */
+ KX_KetsjiEngine* m_ketsjiengine;
+ /** The game engine's system abstraction. */
+ GPG_System* m_kxsystem;
+ /** The game engine's keyboard abstraction. */
+ GPG_KeyboardDevice* m_keyboard;
+ /** The game engine's mouse abstraction. */
+ GPC_MouseDevice* m_mouse;
+ /** The game engine's canvas abstraction. */
+ GPG_Canvas* m_canvas;
+ /** The game engine's platform dependent render tools. */
+ GPC_RenderTools* m_rendertools;
+ /** the rasterizer */
+ RAS_IRasterizer* m_rasterizer;
+ /** Converts Blender data files. */
+ KX_ISceneConverter* m_sceneconverter;
+ /** Network interface. */
+ NG_LoopBackNetworkDeviceInterface* m_networkdevice;
+ /** Sound device. */
+ SND_IAudioDevice* m_audiodevice;
+};
+
+
diff --git a/source/gameengine/GamePlayer/ghost/GPG_Canvas.cpp b/source/gameengine/GamePlayer/ghost/GPG_Canvas.cpp
new file mode 100644
index 00000000000..da71d40acc0
--- /dev/null
+++ b/source/gameengine/GamePlayer/ghost/GPG_Canvas.cpp
@@ -0,0 +1,110 @@
+/**
+ * $Id$
+ *
+ * ***** BEGIN GPL/BL DUAL LICENSE BLOCK *****
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version. The Blender
+ * Foundation also sells licenses for use in proprietary software under
+ * the Blender License. See http://www.blender.org/BL/ for information
+ * about this.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ *
+ * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
+ * All rights reserved.
+ *
+ * The Original Code is: all of this file.
+ *
+ * Contributor(s): none yet.
+ *
+ * ***** END GPL/BL DUAL LICENSE BLOCK *****
+ */
+
+#include "GPG_Canvas.h"
+
+#include <assert.h>
+
+#include "GHOST_ISystem.h"
+
+
+GPG_Canvas::GPG_Canvas(GHOST_IWindow* window)
+: GPC_Canvas(0, 0), m_window(window)
+{
+ if (m_window)
+ {
+ GHOST_Rect bnds;
+ m_window->getClientBounds(bnds);
+ this->Resize(bnds.getWidth(), bnds.getHeight());
+ }
+}
+
+
+GPG_Canvas::~GPG_Canvas(void)
+{
+}
+
+
+void GPG_Canvas::Init()
+{
+ if (m_window)
+ {
+ GHOST_TSuccess success;
+ success = m_window->setDrawingContextType(GHOST_kDrawingContextTypeOpenGL);
+ assert(success == GHOST_kSuccess);
+ }
+}
+
+void GPG_Canvas::SetMousePosition(int x, int y)
+{
+ GHOST_ISystem* system = GHOST_ISystem::getSystem();
+ if (system && m_window)
+ {
+ GHOST_TInt32 gx = (GHOST_TInt32)x;
+ GHOST_TInt32 gy = (GHOST_TInt32)y;
+ GHOST_TInt32 cx;
+ GHOST_TInt32 cy;
+ m_window->clientToScreen(gx, gy, cx, cy);
+ system->setCursorPosition(cx, cy);
+ }
+}
+
+
+void GPG_Canvas::SetMouseState(RAS_MouseState mousestate)
+{
+ if (m_window)
+ {
+ switch (mousestate)
+ {
+ case MOUSE_INVISIBLE:
+ m_window->setCursorVisibility(false);
+ break;
+ case MOUSE_WAIT:
+ m_window->setCursorShape(GHOST_kStandardCursorWait);
+ m_window->setCursorVisibility(true);
+ break;
+ case MOUSE_NORMAL:
+ m_window->setCursorShape(GHOST_kStandardCursorRightArrow);
+ m_window->setCursorVisibility(true);
+ break;
+ }
+ }
+}
+
+
+void GPG_Canvas::SwapBuffers()
+{
+ if (m_window)
+ {
+ m_window->swapBuffers();
+ }
+}
diff --git a/source/gameengine/GamePlayer/ghost/GPG_Canvas.h b/source/gameengine/GamePlayer/ghost/GPG_Canvas.h
new file mode 100644
index 00000000000..12ac3701be8
--- /dev/null
+++ b/source/gameengine/GamePlayer/ghost/GPG_Canvas.h
@@ -0,0 +1,64 @@
+/**
+ * $Id$
+ *
+ * ***** BEGIN GPL/BL DUAL LICENSE BLOCK *****
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version. The Blender
+ * Foundation also sells licenses for use in proprietary software under
+ * the Blender License. See http://www.blender.org/BL/ for information
+ * about this.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ *
+ * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
+ * All rights reserved.
+ *
+ * The Original Code is: all of this file.
+ *
+ * Contributor(s): none yet.
+ *
+ * ***** END GPL/BL DUAL LICENSE BLOCK *****
+ */
+
+#ifndef _GPG_CANVAS_H_
+#define _GPG_CANVAS_H_
+
+#ifdef WIN32
+#pragma warning (disable : 4786)
+#endif // WIN32
+
+#include "GPC_Canvas.h"
+
+#include "GHOST_IWindow.h"
+
+
+class GPG_Canvas : public GPC_Canvas
+{
+protected:
+ /** GHOST window. */
+ GHOST_IWindow* m_window;
+
+public:
+ GPG_Canvas(GHOST_IWindow* window);
+ virtual ~GPG_Canvas(void);
+
+ virtual void Init(void);
+ virtual void SetMousePosition(int x, int y);
+ virtual void SetMouseState(RAS_MouseState mousestate);
+ virtual void SwapBuffers();
+
+ bool BeginDraw() { return true;};
+ void EndDraw() {};
+};
+
+#endif // _GPG_CANVAS_H_
diff --git a/source/gameengine/GamePlayer/ghost/GPG_KeyboardDevice.cpp b/source/gameengine/GamePlayer/ghost/GPG_KeyboardDevice.cpp
new file mode 100644
index 00000000000..7971a86bcbc
--- /dev/null
+++ b/source/gameengine/GamePlayer/ghost/GPG_KeyboardDevice.cpp
@@ -0,0 +1,156 @@
+/**
+ * $Id$
+ *
+ * ***** BEGIN GPL/BL DUAL LICENSE BLOCK *****
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version. The Blender
+ * Foundation also sells licenses for use in proprietary software under
+ * the Blender License. See http://www.blender.org/BL/ for information
+ * about this.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ *
+ * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
+ * All rights reserved.
+ *
+ * The Original Code is: all of this file.
+ *
+ * Contributor(s): none yet.
+ *
+ * ***** END GPL/BL DUAL LICENSE BLOCK *****
+ * GHOST Blender Player keyboard device implementation.
+ */
+
+
+#include "GPG_KeyboardDevice.h"
+
+
+GPG_KeyboardDevice::GPG_KeyboardDevice(void)
+{
+ m_reverseKeyTranslateTable[GHOST_kKeyA ] = KX_AKEY ;
+ m_reverseKeyTranslateTable[GHOST_kKeyB ] = KX_BKEY ;
+ m_reverseKeyTranslateTable[GHOST_kKeyC ] = KX_CKEY ;
+ m_reverseKeyTranslateTable[GHOST_kKeyD ] = KX_DKEY ;
+ m_reverseKeyTranslateTable[GHOST_kKeyE ] = KX_EKEY ;
+ m_reverseKeyTranslateTable[GHOST_kKeyF ] = KX_FKEY ;
+ m_reverseKeyTranslateTable[GHOST_kKeyG ] = KX_GKEY ;
+ m_reverseKeyTranslateTable[GHOST_kKeyH ] = KX_HKEY ;
+ m_reverseKeyTranslateTable[GHOST_kKeyI ] = KX_IKEY ;
+ m_reverseKeyTranslateTable[GHOST_kKeyJ ] = KX_JKEY ;
+ m_reverseKeyTranslateTable[GHOST_kKeyK ] = KX_KKEY ;
+ m_reverseKeyTranslateTable[GHOST_kKeyL ] = KX_LKEY ;
+ m_reverseKeyTranslateTable[GHOST_kKeyM ] = KX_MKEY ;
+ m_reverseKeyTranslateTable[GHOST_kKeyN ] = KX_NKEY ;
+ m_reverseKeyTranslateTable[GHOST_kKeyO ] = KX_OKEY ;
+ m_reverseKeyTranslateTable[GHOST_kKeyP ] = KX_PKEY ;
+ m_reverseKeyTranslateTable[GHOST_kKeyQ ] = KX_QKEY ;
+ m_reverseKeyTranslateTable[GHOST_kKeyR ] = KX_RKEY ;
+ m_reverseKeyTranslateTable[GHOST_kKeyS ] = KX_SKEY ;
+ m_reverseKeyTranslateTable[GHOST_kKeyT ] = KX_TKEY ;
+ m_reverseKeyTranslateTable[GHOST_kKeyU ] = KX_UKEY ;
+ m_reverseKeyTranslateTable[GHOST_kKeyV ] = KX_VKEY ;
+ m_reverseKeyTranslateTable[GHOST_kKeyW ] = KX_WKEY ;
+ m_reverseKeyTranslateTable[GHOST_kKeyX ] = KX_XKEY ;
+ m_reverseKeyTranslateTable[GHOST_kKeyY ] = KX_YKEY ;
+ m_reverseKeyTranslateTable[GHOST_kKeyZ ] = KX_ZKEY ;
+
+ m_reverseKeyTranslateTable[GHOST_kKey0 ] = KX_ZEROKEY ;
+ m_reverseKeyTranslateTable[GHOST_kKey1 ] = KX_ONEKEY ;
+ m_reverseKeyTranslateTable[GHOST_kKey2 ] = KX_TWOKEY ;
+ m_reverseKeyTranslateTable[GHOST_kKey3 ] = KX_THREEKEY ;
+ m_reverseKeyTranslateTable[GHOST_kKey4 ] = KX_FOURKEY ;
+ m_reverseKeyTranslateTable[GHOST_kKey5 ] = KX_FIVEKEY ;
+ m_reverseKeyTranslateTable[GHOST_kKey6 ] = KX_SIXKEY ;
+ m_reverseKeyTranslateTable[GHOST_kKey7 ] = KX_SEVENKEY ;
+ m_reverseKeyTranslateTable[GHOST_kKey8 ] = KX_EIGHTKEY ;
+ m_reverseKeyTranslateTable[GHOST_kKey9 ] = KX_NINEKEY ;
+
+ // Middle keyboard area keys
+ m_reverseKeyTranslateTable[GHOST_kKeyPause ] = KX_PAUSEKEY ;
+ m_reverseKeyTranslateTable[GHOST_kKeyInsert ] = KX_INSERTKEY ;
+ m_reverseKeyTranslateTable[GHOST_kKeyDelete ] = KX_DELKEY ;
+ m_reverseKeyTranslateTable[GHOST_kKeyHome ] = KX_HOMEKEY ;
+ m_reverseKeyTranslateTable[GHOST_kKeyEnd ] = KX_ENDKEY ;
+ m_reverseKeyTranslateTable[GHOST_kKeyUpPage ] = KX_PAGEUPKEY ;
+ m_reverseKeyTranslateTable[GHOST_kKeyDownPage ] = KX_PAGEDOWNKEY ;
+
+ // Arrow keys
+ m_reverseKeyTranslateTable[GHOST_kKeyUpArrow ] = KX_UPARROWKEY ;
+ m_reverseKeyTranslateTable[GHOST_kKeyDownArrow ] = KX_DOWNARROWKEY ;
+ m_reverseKeyTranslateTable[GHOST_kKeyLeftArrow ] = KX_LEFTARROWKEY ;
+ m_reverseKeyTranslateTable[GHOST_kKeyRightArrow ] = KX_RIGHTARROWKEY ;
+
+ // Function keys
+ m_reverseKeyTranslateTable[GHOST_kKeyF1 ] = KX_F1KEY ;
+ m_reverseKeyTranslateTable[GHOST_kKeyF2 ] = KX_F2KEY ;
+ m_reverseKeyTranslateTable[GHOST_kKeyF3 ] = KX_F3KEY ;
+ m_reverseKeyTranslateTable[GHOST_kKeyF4 ] = KX_F4KEY ;
+ m_reverseKeyTranslateTable[GHOST_kKeyF5 ] = KX_F5KEY ;
+ m_reverseKeyTranslateTable[GHOST_kKeyF6 ] = KX_F6KEY ;
+ m_reverseKeyTranslateTable[GHOST_kKeyF7 ] = KX_F7KEY ;
+ m_reverseKeyTranslateTable[GHOST_kKeyF8 ] = KX_F8KEY ;
+ m_reverseKeyTranslateTable[GHOST_kKeyF9 ] = KX_F9KEY ;
+ m_reverseKeyTranslateTable[GHOST_kKeyF10 ] = KX_F10KEY ;
+ m_reverseKeyTranslateTable[GHOST_kKeyF11 ] = KX_F11KEY ;
+ m_reverseKeyTranslateTable[GHOST_kKeyF12 ] = KX_F12KEY ;
+
+ // Numpad keys
+ m_reverseKeyTranslateTable[GHOST_kKeyNumpad0 ] = KX_PAD0 ;
+ m_reverseKeyTranslateTable[GHOST_kKeyNumpad1 ] = KX_PAD1 ;
+ m_reverseKeyTranslateTable[GHOST_kKeyNumpad2 ] = KX_PAD2 ;
+ m_reverseKeyTranslateTable[GHOST_kKeyNumpad3 ] = KX_PAD3 ;
+ m_reverseKeyTranslateTable[GHOST_kKeyNumpad4 ] = KX_PAD4 ;
+ m_reverseKeyTranslateTable[GHOST_kKeyNumpad5 ] = KX_PAD5 ;
+ m_reverseKeyTranslateTable[GHOST_kKeyNumpad6 ] = KX_PAD6 ;
+ m_reverseKeyTranslateTable[GHOST_kKeyNumpad7 ] = KX_PAD7 ;
+ m_reverseKeyTranslateTable[GHOST_kKeyNumpad8 ] = KX_PAD8 ;
+ m_reverseKeyTranslateTable[GHOST_kKeyNumpad9 ] = KX_PAD9 ;
+ m_reverseKeyTranslateTable[GHOST_kKeyNumpadAsterisk ] = KX_PADASTERKEY ;
+ m_reverseKeyTranslateTable[GHOST_kKeyNumpadPlus ] = KX_PADPLUSKEY ;
+ m_reverseKeyTranslateTable[GHOST_kKeyNumpadPeriod ] = KX_PADPERIOD ;
+ m_reverseKeyTranslateTable[GHOST_kKeyNumpadMinus ] = KX_PADMINUS ;
+ m_reverseKeyTranslateTable[GHOST_kKeyNumpadSlash ] = KX_PADSLASHKEY ;
+ m_reverseKeyTranslateTable[GHOST_kKeyNumpadEnter ] = KX_PADENTER ;
+
+ // Other keys
+ m_reverseKeyTranslateTable[GHOST_kKeyCapsLock ] = KX_CAPSLOCKKEY ;
+ m_reverseKeyTranslateTable[GHOST_kKeyEsc ] = KX_ESCKEY ;
+ m_reverseKeyTranslateTable[GHOST_kKeyTab ] = KX_TABKEY ;
+ m_reverseKeyTranslateTable[GHOST_kKeySpace ] = KX_SPACEKEY ;
+ m_reverseKeyTranslateTable[GHOST_kKeyEnter ] = KX_RETKEY ;
+ m_reverseKeyTranslateTable[GHOST_kKeyBackSpace ] = KX_BACKSPACEKEY ;
+ m_reverseKeyTranslateTable[GHOST_kKeySemicolon ] = KX_SEMICOLONKEY ;
+ m_reverseKeyTranslateTable[GHOST_kKeyPeriod ] = KX_PERIODKEY ;
+ m_reverseKeyTranslateTable[GHOST_kKeyComma ] = KX_COMMAKEY ;
+ m_reverseKeyTranslateTable[GHOST_kKeyQuote ] = KX_QUOTEKEY ;
+ m_reverseKeyTranslateTable[GHOST_kKeyAccentGrave ] = KX_ACCENTGRAVEKEY ;
+ m_reverseKeyTranslateTable[GHOST_kKeyMinus ] = KX_MINUSKEY ;
+ m_reverseKeyTranslateTable[GHOST_kKeySlash ] = KX_SLASHKEY ;
+ m_reverseKeyTranslateTable[GHOST_kKeyBackslash ] = KX_BACKSLASHKEY ;
+ m_reverseKeyTranslateTable[GHOST_kKeyEqual ] = KX_EQUALKEY ;
+ m_reverseKeyTranslateTable[GHOST_kKeyLeftBracket ] = KX_LEFTBRACKETKEY ;
+ m_reverseKeyTranslateTable[GHOST_kKeyRightBracket ] = KX_RIGHTBRACKETKEY ;
+
+ // Modifier keys.
+ m_reverseKeyTranslateTable[GHOST_kKeyLeftControl ] = KX_LEFTCTRLKEY ;
+ m_reverseKeyTranslateTable[GHOST_kKeyRightControl ] = KX_RIGHTCTRLKEY ;
+ m_reverseKeyTranslateTable[GHOST_kKeyLeftAlt ] = KX_LEFTALTKEY ;
+ m_reverseKeyTranslateTable[GHOST_kKeyRightAlt ] = KX_RIGHTALTKEY ;
+ m_reverseKeyTranslateTable[GHOST_kKeyLeftShift ] = KX_LEFTSHIFTKEY ;
+ m_reverseKeyTranslateTable[GHOST_kKeyRightShift ] = KX_RIGHTSHIFTKEY ;
+}
+
+
+GPG_KeyboardDevice::~GPG_KeyboardDevice(void)
+{
+}
diff --git a/source/gameengine/GamePlayer/ghost/GPG_KeyboardDevice.h b/source/gameengine/GamePlayer/ghost/GPG_KeyboardDevice.h
new file mode 100644
index 00000000000..0b77664f4e5
--- /dev/null
+++ b/source/gameengine/GamePlayer/ghost/GPG_KeyboardDevice.h
@@ -0,0 +1,57 @@
+/**
+ * $Id$
+ *
+ * ***** BEGIN GPL/BL DUAL LICENSE BLOCK *****
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version. The Blender
+ * Foundation also sells licenses for use in proprietary software under
+ * the Blender License. See http://www.blender.org/BL/ for information
+ * about this.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ *
+ * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
+ * All rights reserved.
+ *
+ * The Original Code is: all of this file.
+ *
+ * Contributor(s): none yet.
+ *
+ * ***** END GPL/BL DUAL LICENSE BLOCK *****
+ * GHOST Blender Player keyboard device.
+ */
+
+#ifndef _GPG_KEYBOARDDEVICE_H_
+#define _GPG_KEYBOARDDEVICE_H_
+
+#ifdef WIN32
+#pragma warning (disable : 4786)
+#endif // WIN32
+
+#include "GHOST_Types.h"
+#include "GPC_KeyboardDevice.h"
+
+/**
+ * GHOST implementation of GPC_KeyboardDevice.
+ * The contructor fills the keyboard code translation map.
+ * Base class GPC_KeyboardDevice does the rest.
+ * @see SCA_IInputDevice
+ */
+class GPG_KeyboardDevice : public GPC_KeyboardDevice
+{
+public:
+ GPG_KeyboardDevice(void);
+ virtual ~GPG_KeyboardDevice(void);
+};
+
+#endif //_GPG_KEYBOARDDEVICE_H_
diff --git a/source/gameengine/GamePlayer/ghost/GPG_System.cpp b/source/gameengine/GamePlayer/ghost/GPG_System.cpp
new file mode 100644
index 00000000000..6084505bbba
--- /dev/null
+++ b/source/gameengine/GamePlayer/ghost/GPG_System.cpp
@@ -0,0 +1,56 @@
+/**
+ * $Id$
+ *
+ * ***** BEGIN GPL/BL DUAL LICENSE BLOCK *****
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version. The Blender
+ * Foundation also sells licenses for use in proprietary software under
+ * the Blender License. See http://www.blender.org/BL/ for information
+ * about this.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ *
+ * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
+ * All rights reserved.
+ *
+ * The Original Code is: all of this file.
+ *
+ * Contributor(s): none yet.
+ *
+ * ***** END GPL/BL DUAL LICENSE BLOCK *****
+ * Blender Player system on GHOST.
+ */
+
+#include "GPG_System.h"
+
+#include <assert.h>
+
+#include "GHOST_ISystem.h"
+
+
+GPG_System::GPG_System(GHOST_ISystem* system)
+: m_system(system)
+{
+ assert(m_system);
+}
+
+
+double GPG_System::GetTimeInSeconds()
+{
+ GHOST_TInt64 millis = (GHOST_TInt64)m_system->getMilliSeconds();
+ double time = (double)millis;
+ time /= 1000.;
+ return time;
+}
+
+
diff --git a/source/gameengine/GamePlayer/ghost/GPG_System.h b/source/gameengine/GamePlayer/ghost/GPG_System.h
new file mode 100644
index 00000000000..f0bb186d370
--- /dev/null
+++ b/source/gameengine/GamePlayer/ghost/GPG_System.h
@@ -0,0 +1,56 @@
+/**
+ * $Id$
+ *
+ * ***** BEGIN GPL/BL DUAL LICENSE BLOCK *****
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version. The Blender
+ * Foundation also sells licenses for use in proprietary software under
+ * the Blender License. See http://www.blender.org/BL/ for information
+ * about this.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ *
+ * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
+ * All rights reserved.
+ *
+ * The Original Code is: all of this file.
+ *
+ * Contributor(s): none yet.
+ *
+ * ***** END GPL/BL DUAL LICENSE BLOCK *****
+ * Blender Player system on GHOST.
+ */
+
+#ifndef _GPG_SYSTEM_H_
+#define _GPG_SYSTEM_H_
+
+#ifdef WIN32
+#pragma warning (disable:4786) // suppress stl-MSVC debug info warning
+#endif // WIN32
+
+#include "GPC_System.h"
+
+class GHOST_ISystem;
+
+class GPG_System : public GPC_System
+{
+ GHOST_ISystem* m_system;
+
+public:
+ GPG_System(GHOST_ISystem* system);
+
+ virtual double GetTimeInSeconds();
+};
+
+
+#endif // _GPG_SYSTEM_H_
diff --git a/source/gameengine/GamePlayer/ghost/GPG_ghost.cpp b/source/gameengine/GamePlayer/ghost/GPG_ghost.cpp
new file mode 100644
index 00000000000..df683cb91cf
--- /dev/null
+++ b/source/gameengine/GamePlayer/ghost/GPG_ghost.cpp
@@ -0,0 +1,597 @@
+/**
+* $Id$
+*
+ * ***** BEGIN GPL/BL DUAL LICENSE BLOCK *****
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version. The Blender
+ * Foundation also sells licenses for use in proprietary software under
+ * the Blender License. See http://www.blender.org/BL/ for information
+ * about this.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ *
+ * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
+ * All rights reserved.
+ *
+ * The Original Code is: all of this file.
+ *
+ * Contributor(s): none yet.
+ *
+ * ***** END GPL/BL DUAL LICENSE BLOCK *****
+* Start up of the Blender Player on GHOST.
+*/
+
+#include <iostream>
+#include <math.h>
+
+#ifdef __linux__
+#ifdef __alpha__
+#include <signal.h>
+#endif /* __alpha__ */
+#endif /* __linux__ */
+
+#ifdef __APPLE__
+// Can't use Carbon right now because of double defined type ID (In Carbon.h and DNA_ID.h, sigh)
+//#include <Carbon/Carbon.h>
+//#include <CFBundle.h>
+#endif // __APPLE__
+#include "GEN_messaging.h"
+#include "KX_KetsjiEngine.h"
+
+/**********************************
+* Begin Blender include block
+**********************************/
+#ifdef __cplusplus
+extern "C"
+{
+#endif // __cplusplus
+
+#include "BLI_blenlib.h"
+#include "DNA_scene_types.h"
+#include "BLO_readfile.h"
+
+ int GHOST_HACK_getFirstFile(char buf[]);
+
+#ifdef __cplusplus
+}
+#endif // __cplusplus
+/**********************************
+* End Blender include block
+**********************************/
+
+#include "SYS_System.h"
+#include "GPG_Application.h"
+#include "GPC_PolygonMaterial.h"
+
+#include "GHOST_ISystem.h"
+#include "RAS_IRasterizer.h"
+
+#include "BKE_main.h"
+
+#ifdef WIN32
+#ifdef NDEBUG
+#include <windows.h>
+#include <wincon.h>
+#endif // NDEBUG
+#endif // WIN32
+
+const int kMinWindowWidth = 100;
+const int kMinWindowHeight = 100;
+
+void usage(char* program)
+{
+ char * consoleoption;
+#ifdef _WIN32
+ consoleoption = "-c ";
+#else
+ consoleoption = "";
+#endif
+
+ printf("usage: %s [-p l t w h] [-f fw fh fb ff] %s[-g gamengineoptions] "
+ "-s stereomode filename.blend\n", program, consoleoption);
+ printf(" -p: specify window position\n");
+ printf(" l = window left coordinate\n");
+ printf(" t = window top coordinate\n");
+ printf(" w = window width\n");
+ printf(" h = window height\n");
+ printf(" -f: start game in full screen mode\n");
+ printf(" fw = full screen mode pixel width\n");
+ printf(" fh = full screen mode pixel height\n");
+ printf(" fb = full screen mode bits per pixel\n");
+ printf(" ff = full screen mode frequency\n");
+ printf(" -s: start player in stereo\n");
+ printf(" stereomode = hwpageflip or syncdoubling depending on the type of stereo you want\n");
+#ifdef _WIN32
+ printf(" -c: keep console window open\n");
+#endif
+ printf("\n");
+ printf("example: %s -p 10 10 320 200 -g noaudio c:\\loadtest.blend\n", program);
+}
+
+char *get_filename(int argc, char **argv) {
+#ifdef __APPLE__
+/* On Mac we park the game file (called game.blend) in the application bundle.
+* The executable is located in the bundle as well.
+* Therefore, we can locate the game relative to the executable.
+ */
+ int srclen = ::strlen(argv[0]);
+ int len = 0;
+ char *filename = NULL;
+
+ if (argc > 1) {
+ if (BLI_exists(argv[argc-1])) {
+ len = ::strlen(argv[argc-1]);
+ filename = new char [len + 1];
+ ::strcpy(filename, argv[argc-1]);
+ return(filename);
+ }
+ if (::strncmp(argv[argc-1], "-psn_", 5)==0) {
+ static char firstfilebuf[512];
+ if (GHOST_HACK_getFirstFile(firstfilebuf)) {
+ len = ::strlen(firstfilebuf);
+ filename = new char [len + 1];
+ ::strcpy(filename, firstfilebuf);
+ return(filename);
+ }
+ }
+ }
+
+ srclen -= ::strlen("MacOS/blenderplayer");
+ if (srclen > 0) {
+ len = srclen + ::strlen("Resources/game.blend");
+ filename = new char [len + 1];
+ ::strcpy(filename, argv[0]);
+ ::strcpy(filename + srclen, "Resources/game.blend");
+ //::printf("looking for file: %s\n", filename);
+
+ if (BLI_exists(filename)) {
+ return (filename);
+ }
+ }
+
+ return(NULL);
+#else
+ return (argc>1)?argv[argc-1]:NULL;
+#endif // !_APPLE
+}
+
+BlendFileData *load_game_data(char *progname, char *filename) {
+ BlendReadError error;
+ BlendFileData *bfd;
+
+ /* try to load ourself, will only work if we are a runtime */
+ bfd= BLO_read_from_file(progname, &error);
+
+ if (!bfd) {
+ if (filename) {
+ bfd= BLO_read_from_file(filename, &error);
+ }
+ }
+
+ if (bfd && bfd->type == BLENFILETYPE_BLEND) {
+ BLO_blendfiledata_free(bfd);
+ bfd = NULL;
+ error = BRE_NOT_A_PUBFILE;
+ }
+
+ if (!bfd) {
+ if (filename) {
+ printf("Loading %s failed: %s\n", filename, BLO_bre_as_string(error));
+ }
+ }
+
+ return bfd;
+}
+
+int main(int argc, char** argv)
+{
+ int i;
+ bool error = false;
+ SYS_SystemHandle syshandle = SYS_GetSystem();
+ bool fullScreen = false;
+ bool fullScreenParFound = false;
+ bool windowParFound = false;
+ bool closeConsole = true;
+ int stereomode = RAS_IRasterizer::RAS_STEREO_NOSTEREO;
+ bool stereoWindow = false;
+ bool stereoParFound = false;
+ int windowLeft = 100;
+ int windowTop = 100;
+ int windowWidth = 640;
+ int windowHeight = 480;
+ int fullScreenWidth = 640;
+ int fullScreenHeight= 480;
+ int fullScreenBpp = 16;
+ int fullScreenFrequency = 60;
+
+#ifdef __linux__
+#ifdef __alpha__
+ signal (SIGFPE, SIG_IGN);
+#endif /* __alpha__ */
+#endif /* __linux__ */
+
+#ifdef __APPLE__
+ // Can't use Carbon right now because of double defined type ID (In Carbon.h and DNA_ID.h, sigh)
+ /*
+ IBNibRef nibRef;
+ WindowRef window;
+ OSStatus err;
+
+ // Create a Nib reference passing the name of the nib file (without the .nib extension)
+ // CreateNibReference only searches into the application bundle.
+ err = ::CreateNibReference(CFSTR("main"), &nibRef);
+ if (err) return -1;
+
+ // Once the nib reference is created, set the menu bar. "MainMenu" is the name of the menu bar
+ // object. This name is set in InterfaceBuilder when the nib is created.
+ err = ::SetMenuBarFromNib(nibRef, CFSTR("MenuBar"));
+ if (err) return -1;
+
+ // We don't need the nib reference anymore.
+ ::DisposeNibReference(nibRef);
+ */
+#endif // __APPLE__
+
+ GEN_init_messaging_system();
+
+ // Parse command line options
+#ifndef NDEBUG
+ printf("argv[0] = '%s'\n", argv[0]);
+#endif
+ for (i = 1; (i < argc) && !error; i++)
+ {
+#ifndef NDEBUG
+ printf("argv[%d] = '%s'\n", i, argv[i]);
+#endif
+
+ if (argv[i][0] == '-')
+ {
+ switch (argv[i][1])
+ {
+ case 'g':
+ // Parse game options
+ {
+ i++;
+ if (i < argc)
+ {
+ char* paramname = argv[i];
+ // Check for single value versus assignment
+ if (i+1 < argc && (*(argv[i+1]) == '='))
+ {
+ i++;
+ if (i + 1 < argc)
+ {
+ i++;
+ // Assignment
+ SYS_WriteCommandLineString(syshandle, paramname, argv[i]);
+ }
+ else
+ {
+ error = true;
+ printf("error: argument assignment %s without value.\n", paramname);
+ }
+ }
+ else
+ {
+ SYS_WriteCommandLineInt(syshandle, argv[i], 1);
+ }
+ }
+ }
+ break;
+
+ case 'p':
+ // Parse window position and size options
+ if (argv[i][2] == 0) {
+ i++;
+ if ((i + 4) < argc)
+ {
+ windowLeft = atoi(argv[i++]);
+ windowTop = atoi(argv[i++]);
+ windowWidth = atoi(argv[i++]);
+ windowHeight = atoi(argv[i]);
+ windowParFound = true;
+ }
+ else
+ {
+ error = true;
+ printf("error: too few options for window argument.\n");
+ }
+ }
+ break;
+
+ case 'f':
+ // Parse window position and size options
+ {
+ fullScreen = true;
+ i++;
+ if ((i + 4) < argc)
+ {
+ fullScreenWidth = atoi(argv[i++]);
+ fullScreenHeight = atoi(argv[i++]);
+ fullScreenBpp = atoi(argv[i++]);
+ fullScreenFrequency = atoi(argv[i]);
+ fullScreenParFound = true;
+ }
+ else
+ {
+ error = true;
+ printf("error: too few options for fullscreen argument.\n");
+ }
+ }
+ break;
+ case 'c':
+ i++;
+ closeConsole = false;
+ break;
+ case 's': // stereo
+ i++;
+ if ((i + 1) < argc)
+ {
+ if(!strcmp(argv[i], "nostereo")) // ok, redundant but clear
+ stereomode = RAS_IRasterizer::RAS_STEREO_NOSTEREO;
+
+ // only the hardware pageflip method needs a stereo window
+ if(!strcmp(argv[i], "hwpageflip")) {
+ stereomode = RAS_IRasterizer::RAS_STEREO_QUADBUFFERED;
+ stereoWindow = true;
+ }
+ if(!strcmp(argv[i], "syncdoubling"))
+ stereomode = RAS_IRasterizer::RAS_STEREO_ABOVEBELOW;
+#if 0
+ // future stuff
+ if(strcmp(argv[i], "stencil")
+ stereomode = RAS_STEREO_STENCIL;
+#endif
+
+ i++;
+ stereoParFound = true;
+ }
+ else
+ {
+ error = true;
+ printf("error: too few options for stereo argument.\n");
+ }
+ break;
+ }
+ }
+ else
+ {
+ }
+ }
+
+ if ((windowWidth < kMinWindowWidth) || (windowHeight < kMinWindowHeight))
+ {
+ error = true;
+ printf("error: window size too small.\n");
+ }
+
+ if (error)
+ {
+ usage(argv[0]);
+ }
+ else
+ {
+#ifdef __APPLE__
+ //SYS_WriteCommandLineInt(syshandle, "show_framerate", 1);
+ SYS_WriteCommandLineInt(syshandle, "nomipmap", 1);
+ //fullScreen = false; // Can't use full screen
+#endif
+ if (SYS_GetCommandLineInt(syshandle, "nomipmap", 0))
+ {
+ GPC_PolygonMaterial::SetMipMappingEnabled(0);
+ }
+
+ // Create the system
+ if (GHOST_ISystem::createSystem() == GHOST_kSuccess)
+ {
+ GHOST_ISystem* system = GHOST_ISystem::getSystem();
+ assertd(system);
+
+ // process first batch of events. If the user
+ // drops a file on top off the blenderplayer icon, we
+ // recieve an event with the filename
+
+ system->processEvents(0);
+
+ // this bracket is needed for app (see below) to get out
+ // of scope before GHOST_ISystem::disposeSystem() is called.
+ {
+ int exitcode = KX_EXIT_REQUEST_NO_REQUEST;
+ STR_String exitstring = "";
+ GPG_Application app(system, NULL, exitstring);
+ bool firstTimeRunning = true;
+
+ do
+ {
+ // Read the Blender file
+ char *filename = get_filename(argc, argv);
+ char *titlename;
+ char pathname[160];
+ BlendFileData *bfd;
+
+ // if we got an exitcode 3 (KX_EXIT_REQUEST_START_OTHER_GAME) load a different file
+ if (exitcode == KX_EXIT_REQUEST_START_OTHER_GAME)
+ {
+ char basedpath[160];
+
+ // base the actuator filename with respect
+ // to the original file working directory
+ strcpy(basedpath, exitstring.Ptr());
+ BLI_convertstringcode(basedpath, pathname, 0);
+
+ bfd = load_game_data(NULL, basedpath);
+ }
+ else
+ {
+ bfd = load_game_data(argv[0], filename);
+ }
+
+ //::printf("game data loaded from %s\n", filename);
+
+ if (!bfd) {
+ usage(argv[0]);
+ error = true;
+ exitcode = KX_EXIT_REQUEST_QUIT_GAME;
+ }
+ else
+ {
+#ifdef WIN32
+#ifdef NDEBUG
+ if (closeConsole)
+ {
+ ::FreeConsole(); // Close a console window
+ }
+#endif // NDEBUG
+#endif // WIN32
+ Main *maggie = bfd->main;
+ Scene *scene = bfd->curscene;
+ strcpy (pathname, maggie->name);
+ char *startscenename = scene->id.name + 2;
+
+ titlename = maggie->name;
+
+ // Check whether the game should be displayed full-screen
+ if ((!fullScreenParFound) && (!windowParFound))
+ {
+ // Only use file settings when command line did not override
+ if (scene->r.fullscreen) {
+ //printf("fullscreen option found in Blender file\n");
+ fullScreen = true;
+ fullScreenWidth= scene->r.xplay;
+ fullScreenHeight= scene->r.yplay;
+ fullScreenFrequency= scene->r.freqplay;
+ fullScreenBpp = scene->r.depth;
+ }
+ else
+ {
+ fullScreen = false;
+ windowWidth = scene->r.xplay;
+ windowHeight = scene->r.yplay;
+ }
+ }
+
+
+ // Check whether the game should be displayed in stereo
+ if (!stereoParFound)
+ {
+ if(scene->r.stereomode == RAS_IRasterizer::RAS_STEREO_NOSTEREO) // ok, redundant but clear
+ stereomode = RAS_IRasterizer::RAS_STEREO_NOSTEREO;
+
+ // only the hardware pageflip method needs a stereo window
+ if(scene->r.stereomode == RAS_IRasterizer::RAS_STEREO_QUADBUFFERED) {
+ stereomode = RAS_IRasterizer::RAS_STEREO_QUADBUFFERED;
+ stereoWindow = true;
+ }
+ if(scene->r.stereomode == RAS_IRasterizer::RAS_STEREO_ABOVEBELOW)
+ stereomode = RAS_IRasterizer::RAS_STEREO_ABOVEBELOW;
+#if 0
+ // future stuff
+ if(scene->r.stereomode == RAS_IRasterizer::RAS_STEREO_STENCIL)
+ stereomode = RAS_STEREO_STENCIL;
+#endif
+ }
+
+ // GPG_Application app (system, maggie, startscenename);
+ app.SetGameEngineData(maggie, startscenename);
+
+ if (firstTimeRunning)
+ {
+ firstTimeRunning = false;
+
+ if (fullScreen)
+ {
+ app.startFullScreen(fullScreenWidth, fullScreenHeight, fullScreenBpp, fullScreenFrequency,
+ stereoWindow, stereomode);
+ }
+ else
+ {
+#ifdef __APPLE__
+ // on Mac's we'll show the executable name instead of the 'game.blend' name
+ char tempname[1024], *appstring;
+ ::strcpy(tempname, titlename);
+
+ appstring = strstr(tempname, ".app/");
+ if (appstring) {
+ appstring[2] = 0;
+ titlename = &tempname[0];
+ }
+#endif
+ // Strip the path so that we have the name of the game file
+ STR_String path = titlename;
+#ifndef WIN32
+ vector<STR_String> parts = path.Explode('/');
+#else // WIN32
+ vector<STR_String> parts = path.Explode('\\');
+#endif // WIN32
+ STR_String title;
+ if (parts.size())
+ {
+ title = parts[parts.size()-1];
+ parts = title.Explode('.');
+ if (parts.size() > 1)
+ {
+ title = parts[0];
+ }
+ }
+ else
+ {
+ title = "blenderplayer";
+ }
+ app.startWindow(title, windowLeft, windowTop, windowWidth, windowHeight,
+ stereoWindow, stereomode);
+ }
+ }
+ else
+ {
+ app.StartGameEngine(stereomode);
+ exitcode = KX_EXIT_REQUEST_NO_REQUEST;
+ }
+
+ // Add the application as event consumer
+ system->addEventConsumer(&app);
+
+ // Enter main loop
+ bool run = true;
+ while (run)
+ {
+ system->processEvents(true);
+ system->dispatchEvents();
+ if (exitcode = app.getExitRequested())
+ {
+ run = false;
+ exitstring = app.getExitString();
+ }
+ }
+ app.StopGameEngine();
+ BLO_blendfiledata_free(bfd);
+
+#ifdef __APPLE__
+ if (filename) {
+ delete [] filename;
+ }
+#endif // __APPLE__
+ }
+ } while (exitcode == KX_EXIT_REQUEST_RESTART_GAME || exitcode == KX_EXIT_REQUEST_START_OTHER_GAME);
+ }
+ // Dispose the system
+ GHOST_ISystem::disposeSystem();
+ } else {
+ error = true;
+ printf("error: couldn't create a system.\n");
+ }
+ }
+
+ return error ? -1 : 0;
+}
+
+
diff --git a/source/gameengine/GamePlayer/ghost/Makefile b/source/gameengine/GamePlayer/ghost/Makefile
new file mode 100644
index 00000000000..7e9735a4bd8
--- /dev/null
+++ b/source/gameengine/GamePlayer/ghost/Makefile
@@ -0,0 +1,82 @@
+#
+# $Id$
+#
+# ***** BEGIN GPL/BL DUAL LICENSE BLOCK *****
+#
+# This program is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License
+# as published by the Free Software Foundation; either version 2
+# of the License, or (at your option) any later version. The Blender
+# Foundation also sells licenses for use in proprietary software under
+# the Blender License. See http://www.blender.org/BL/ for information
+# about this.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software Foundation,
+# Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+#
+# The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
+# All rights reserved.
+#
+# The Original Code is: all of this file.
+#
+# Contributor(s): none yet.
+#
+# ***** END GPL/BL DUAL LICENSE BLOCK *****
+#
+# Makefile for GHOST game player
+
+LIBNAME = ghost
+DIR = $(OCGDIR)/gameengine/GamePlayer/ghost
+
+include nan_compile.mk
+
+CCFLAGS += $(LEVEL_1_CPP_WARNINGS)
+
+# OpenGL header files
+CPPFLAGS += -I$(OPENGL_HEADERS)
+CPPFLAGS += -I$(NAN_STRING)/include
+CPPFLAGS += -I$(NAN_BMFONT)/include
+
+CPPFLAGS += -I../../GamePlayer/common
+
+# Game Engine includes
+CPPFLAGS += -I../../Converter
+CPPFLAGS += -I../../Expressions
+CPPFLAGS += -I../../GameLogic
+CPPFLAGS += -I../../Ketsji
+CPPFLAGS += -I../../Ketsji/KXNetwork
+CPPFLAGS += -I../../Network
+CPPFLAGS += -I../../Network/LoopBackNetwork
+CPPFLAGS += -I../../Rasterizer
+CPPFLAGS += -I../../Rasterizer/RAS_OpenGLRasterizer
+CPPFLAGS += -I../../SceneGraph
+CPPFLAGS += -I../../SoundSystem
+CPPFLAGS += -I../../SoundSystem/SND_OpenAL
+
+# Sumo
+CPPFLAGS += -I../../../sumo/Fuzzics/include
+CPPFLAGS += -I../../../sumo/include
+CPPFLAGS += -I$(NAN_MOTO)/include
+
+# Blender includes
+CPPFLAGS += -I../../../blender/blenkernel
+CPPFLAGS += -I../../../blender/blenlib
+CPPFLAGS += -I../../../blender/blenloader
+CPPFLAGS += -I../../../blender/imbuf
+CPPFLAGS += -I../../../blender/makesdna
+CPPFLAGS += -I../../../blender/readblenfile
+
+# kernel? GEN? stuff
+CPPFLAGS += -I../../../kernel/gen_system
+CPPFLAGS += -I../../../kernel/gen_messaging
+
+CPPFLAGS += -I$(NAN_STRING)/include
+CPPFLAGS += -I$(NAN_GHOST)/include
+CPPFLAGS += -I$(NAN_PYTHON)/include/python$(NAN_PYTHON_VERSION)
+