diff options
author | Dalai Felinto <dfelinto@gmail.com> | 2018-04-16 15:07:42 +0300 |
---|---|---|
committer | Dalai Felinto <dfelinto@gmail.com> | 2018-04-17 18:51:28 +0300 |
commit | 159806140fd33e6ddab951c0f6f180cfbf927d38 (patch) | |
tree | da076be3baa4d987fb5935e220a3d901c926e0e7 /source/gameengine/GamePlayer | |
parent | 28b996a9d2090efdd74115a653629ef9d7d871f7 (diff) |
Removing Blender Game Engine from Blender 2.8
Folders removed entirely:
* //extern/recastnavigation
* //intern/decklink
* //intern/moto
* //source/blender/editors/space_logic
* //source/blenderplayer
* //source/gameengine
This includes DNA data and any reference to the BGE code in Blender itself.
We are bumping the subversion.
Pending tasks:
* Tile/clamp code in image editor draw code.
* Viewport drawing code (so much of this will go away because of BI removal
that we can wait until then to remove this.
Diffstat (limited to 'source/gameengine/GamePlayer')
18 files changed, 0 insertions, 4052 deletions
diff --git a/source/gameengine/GamePlayer/CMakeLists.txt b/source/gameengine/GamePlayer/CMakeLists.txt deleted file mode 100644 index e77609985dc..00000000000 --- a/source/gameengine/GamePlayer/CMakeLists.txt +++ /dev/null @@ -1,27 +0,0 @@ -# ***** BEGIN GPL 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. -# -# 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -# -# The Original Code is Copyright (C) 2006, Blender Foundation -# All rights reserved. -# -# The Original Code is: all of this file. -# -# Contributor(s): Jacques Beaurain. -# -# ***** END GPL LICENSE BLOCK ***** - -add_subdirectory(common) -add_subdirectory(ghost) diff --git a/source/gameengine/GamePlayer/common/CMakeLists.txt b/source/gameengine/GamePlayer/common/CMakeLists.txt deleted file mode 100644 index e6c980de566..00000000000 --- a/source/gameengine/GamePlayer/common/CMakeLists.txt +++ /dev/null @@ -1,75 +0,0 @@ -# ***** BEGIN GPL 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. -# -# 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -# -# The Original Code is Copyright (C) 2006, Blender Foundation -# All rights reserved. -# -# The Original Code is: all of this file. -# -# Contributor(s): Jacques Beaurain. -# -# ***** END GPL LICENSE BLOCK ***** - -set(INC - . - ../ghost - ../../BlenderRoutines - ../../Converter - ../../Expressions - ../../GameLogic - ../../Ketsji - ../../Network - ../../Network/LoopBackNetwork - ../../Physics/common - ../../Rasterizer - ../../Rasterizer/RAS_OpenGLRasterizer - ../../SceneGraph - ../../../blender - ../../../blender/blenfont - ../../../blender/blenkernel - ../../../blender/blenlib - ../../../blender/blenloader - ../../../blender/gpu - ../../../blender/imbuf - ../../../blender/makesdna - ../../../../intern/container - ../../../../intern/ghost - ../../../../intern/glew-mx - ../../../../intern/guardedalloc - ../../../../intern/string -) - -set(INC_SYS - ../../../../intern/moto/include - ${GLEW_INCLUDE_PATH} - ${PYTHON_INCLUDE_DIRS} - ${PNG_INCLUDE_DIRS} - ${ZLIB_INCLUDE_DIRS} -) - -set(SRC - GPC_Canvas.cpp - GPC_KeyboardDevice.cpp - GPC_MouseDevice.cpp - - GPC_Canvas.h - GPC_KeyboardDevice.h - GPC_MouseDevice.h -) - -add_definitions(${GL_DEFINITIONS}) - -blender_add_lib_nolist(ge_player_common "${SRC}" "${INC}" "${INC_SYS}") diff --git a/source/gameengine/GamePlayer/common/GPC_Canvas.cpp b/source/gameengine/GamePlayer/common/GPC_Canvas.cpp deleted file mode 100644 index 2b355407d46..00000000000 --- a/source/gameengine/GamePlayer/common/GPC_Canvas.cpp +++ /dev/null @@ -1,168 +0,0 @@ -/* - * ***** BEGIN GPL 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. - * - * 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, 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 LICENSE BLOCK ***** - */ - -/** \file gameengine/GamePlayer/common/GPC_Canvas.cpp - * \ingroup player - */ - - -#include "RAS_IPolygonMaterial.h" -#include "GPC_Canvas.h" - -#include "DNA_scene_types.h" -#include "DNA_space_types.h" - -#include "BKE_image.h" -#include "MEM_guardedalloc.h" - - -GPC_Canvas::GPC_Canvas( - int width, - int height -) : - m_width(width), - m_height(height) -{ - // initialize area so that it's available for game logic on frame 1 (ImageViewport) - m_displayarea.m_x1 = 0; - m_displayarea.m_y1 = 0; - m_displayarea.m_x2 = width; - m_displayarea.m_y2 = height; - m_frame = 1; - - glGetIntegerv(GL_VIEWPORT, (GLint*)m_viewport); -} - - -GPC_Canvas::~GPC_Canvas() -{ -} - - -void GPC_Canvas::Resize(int width, int height) -{ - m_width = width; - m_height = height; - - // initialize area so that it's available for game logic on frame 1 (ImageViewport) - m_displayarea.m_x1 = 0; - m_displayarea.m_y1 = 0; - m_displayarea.m_x2 = width; - m_displayarea.m_y2 = height; -} - - -void GPC_Canvas::ClearColor(float r, float g, float b, float a) -{ - ::glClearColor(r,g,b,a); -} - -void GPC_Canvas::SetViewPort(int x1, int y1, int x2, int y2) -{ - /* x1 and y1 are the min pixel coordinate (e.g. 0) - x2 and y2 are the max pixel coordinate - the width,height is calculated including both pixels - therefore: max - min + 1 - */ - - /* XXX, nasty, this needs to go somewhere else, - * but where... definitely need to clean up this - * whole canvas/rendertools mess. - */ - glEnable(GL_SCISSOR_TEST); - - m_viewport[0] = x1; - m_viewport[1] = y1; - m_viewport[2] = x2-x1 + 1; - m_viewport[3] = y2-y1 + 1; - - glViewport(x1,y1,x2-x1 + 1,y2-y1 + 1); - glScissor(x1,y1,x2-x1 + 1,y2-y1 + 1); -} - -void GPC_Canvas::UpdateViewPort(int x1, int y1, int x2, int y2) -{ - m_viewport[0] = x1; - m_viewport[1] = y1; - m_viewport[2] = x2; - m_viewport[3] = y2; -} - -const int *GPC_Canvas::GetViewPort() -{ -#ifdef DEBUG - // If we're in a debug build, we might as well make sure our values don't differ - // from what the gpu thinks we have. This could lead to nasty, hard to find bugs. - int viewport[4]; - glGetIntegerv(GL_VIEWPORT, viewport); - assert(viewport[0] == m_viewport[0]); - assert(viewport[1] == m_viewport[1]); - assert(viewport[2] == m_viewport[2]); - assert(viewport[3] == m_viewport[3]); -#endif - - return m_viewport; -} - -void GPC_Canvas::ClearBuffer( - int type -) { - - int ogltype = 0; - if (type & RAS_ICanvas::COLOR_BUFFER ) - ogltype |= GL_COLOR_BUFFER_BIT; - if (type & RAS_ICanvas::DEPTH_BUFFER ) - ogltype |= GL_DEPTH_BUFFER_BIT; - - ::glClear(ogltype); -} - - void -GPC_Canvas:: -MakeScreenShot( - const char* filename -) { - // copy image data - unsigned int dumpsx = GetWidth(); - unsigned int dumpsy = GetHeight(); - unsigned int *pixels = (unsigned int *)MEM_mallocN(sizeof(int) * dumpsx * dumpsy, "pixels"); - - if (!pixels) { - std::cout << "Cannot allocate pixels array" << std::endl; - return; - } - - glReadPixels(0, 0, dumpsx, dumpsy, GL_RGBA, GL_UNSIGNED_BYTE, pixels); - - // initialize image file format data - ImageFormatData *im_format = (ImageFormatData *)MEM_mallocN(sizeof(ImageFormatData), "im_format"); - BKE_imformat_defaults(im_format); - - /* save_screenshot() frees dumprect and im_format */ - save_screenshot(filename, dumpsx, dumpsy, pixels, im_format); -} - diff --git a/source/gameengine/GamePlayer/common/GPC_Canvas.h b/source/gameengine/GamePlayer/common/GPC_Canvas.h deleted file mode 100644 index 688ed8ac0f4..00000000000 --- a/source/gameengine/GamePlayer/common/GPC_Canvas.h +++ /dev/null @@ -1,147 +0,0 @@ -/* - * ***** BEGIN GPL 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. - * - * 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, 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 LICENSE BLOCK ***** - */ - -/** \file GPC_Canvas.h - * \ingroup player - */ - -#ifndef __GPC_CANVAS_H__ -#define __GPC_CANVAS_H__ - -#include "RAS_ICanvas.h" -#include "RAS_Rect.h" - -#ifdef WIN32 -# pragma warning (disable:4786) // suppress stl-MSVC debug info warning -# include <windows.h> -#endif /* WIN32 */ - -#include "GPU_glew.h" - -#include <map> - - -class GPC_Canvas : public RAS_ICanvas -{ -protected: - - /** Width of the context. */ - int m_width; - /** Height of the context. */ - int m_height; - /** Rect that defines the area used for rendering, - * relative to the context */ - RAS_Rect m_displayarea; - - int m_viewport[4]; - -public: - - GPC_Canvas(int width, int height); - - virtual ~GPC_Canvas(); - - void Resize(int width, int height); - - virtual void ResizeWindow(int width, int height) {} - - virtual void GetDisplayDimensions(int &width, int &height) {} - - /** - * \section Methods inherited from abstract base class RAS_ICanvas. - */ - - int - GetWidth( - ) const { - return m_width; - } - - int - GetHeight( - ) const { - return m_height; - } - - const - RAS_Rect & - GetDisplayArea( - ) const { - return m_displayarea; - }; - - void - SetDisplayArea( - RAS_Rect *rect - ) { - m_displayarea= *rect; - }; - - RAS_Rect & - GetWindowArea( - ) { - return m_displayarea; - } - - void - BeginFrame( - ) {}; - - /** - * Draws overlay banners and progress bars. - */ - void - EndFrame( - ) {}; - - void SetViewPort(int x1, int y1, int x2, int y2); - void UpdateViewPort(int x1, int y1, int x2, int y2); - const int *GetViewPort(); - - void ClearColor(float r, float g, float b, float a); - - /** - * \section Methods inherited from abstract base class RAS_ICanvas. - * Semantics are not yet honored. - */ - - void SetMouseState(RAS_MouseState mousestate) - { - // not yet - } - - void SetMousePosition(int x, int y) - { - // not yet - } - - virtual void MakeScreenShot(const char* filename); - - void ClearBuffer(int type); -}; - -#endif /* __GPC_CANVAS_H__ */ diff --git a/source/gameengine/GamePlayer/common/GPC_KeyboardDevice.cpp b/source/gameengine/GamePlayer/common/GPC_KeyboardDevice.cpp deleted file mode 100644 index 0821d1d3b23..00000000000 --- a/source/gameengine/GamePlayer/common/GPC_KeyboardDevice.cpp +++ /dev/null @@ -1,128 +0,0 @@ -/* - * ***** BEGIN GPL 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. - * - * 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, 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 LICENSE BLOCK ***** - */ - -/** \file gameengine/GamePlayer/common/GPC_KeyboardDevice.cpp - * \ingroup player - */ - - -#include "GPC_KeyboardDevice.h" - -#include <cstdlib> - -/** - * NextFrame toggles currentTable with previousTable, - * and copies relevant event information from previous to current table - * (pressed keys need to be remembered). - */ -void GPC_KeyboardDevice::NextFrame() -{ - SCA_IInputDevice::NextFrame(); - - // Now convert justpressed key events into regular (active) keyevents - int previousTable = 1-m_currentTable; - for (int keyevent= KX_BEGINKEY; keyevent<= KX_ENDKEY;keyevent++) - { - SCA_InputEvent& oldevent = m_eventStatusTables[previousTable][keyevent]; - if (oldevent.m_status == SCA_InputEvent::KX_JUSTACTIVATED || - oldevent.m_status == SCA_InputEvent::KX_ACTIVE ) - { - m_eventStatusTables[m_currentTable][keyevent] = oldevent; - m_eventStatusTables[m_currentTable][keyevent].m_status = SCA_InputEvent::KX_ACTIVE; - //m_eventStatusTables[m_currentTable][keyevent].m_status = SCA_InputEvent::KX_JUSTACTIVATED; - } - } -} - - - -/** - * ConvertBPEvent translates Windows keyboard events into ketsji kbd events. - * Extra event information is stored, like ramp-mode (just released/pressed) - */ -bool GPC_KeyboardDevice::ConvertEvent(int incode, int val, unsigned int unicode) -{ - bool result = false; - - // convert event - KX_EnumInputs kxevent = this->ToNative(incode); - - // only process it, if it's a key - if (kxevent >= KX_BEGINKEY && kxevent <= KX_ENDKEY) - { - int previousTable = 1-m_currentTable; - - if (val > 0) - { - if (kxevent == SCA_IInputDevice::KX_ESCKEY && val != 0 && !m_hookesc) - result = true; - - // todo: convert val ?? - m_eventStatusTables[m_currentTable][kxevent].m_eventval = val ; //??? - m_eventStatusTables[m_currentTable][kxevent].m_unicode = unicode ; - - switch (m_eventStatusTables[previousTable][kxevent].m_status) - { - case SCA_InputEvent::KX_JUSTACTIVATED: - case SCA_InputEvent::KX_ACTIVE: - { - m_eventStatusTables[m_currentTable][kxevent].m_status = SCA_InputEvent::KX_ACTIVE; - break; - } - - case SCA_InputEvent::KX_NO_INPUTSTATUS: - default: - { - m_eventStatusTables[m_currentTable][kxevent].m_status = SCA_InputEvent::KX_JUSTACTIVATED; - } - } - - } else - { - - switch (m_eventStatusTables[previousTable][kxevent].m_status) - { - case SCA_InputEvent::KX_JUSTACTIVATED: - case SCA_InputEvent::KX_ACTIVE: - { - m_eventStatusTables[m_currentTable][kxevent].m_status = SCA_InputEvent::KX_JUSTRELEASED; - break; - } - default: - { - m_eventStatusTables[m_currentTable][kxevent].m_status = SCA_InputEvent::KX_NO_INPUTSTATUS; - } - } - } - } - return result; -} - -void GPC_KeyboardDevice::HookEscape() -{ - m_hookesc = true; -} diff --git a/source/gameengine/GamePlayer/common/GPC_KeyboardDevice.h b/source/gameengine/GamePlayer/common/GPC_KeyboardDevice.h deleted file mode 100644 index d9842a42e0a..00000000000 --- a/source/gameengine/GamePlayer/common/GPC_KeyboardDevice.h +++ /dev/null @@ -1,90 +0,0 @@ -/* - * ***** BEGIN GPL 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. - * - * 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, 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 LICENSE BLOCK ***** - */ - -/** \file GPC_KeyboardDevice.h - * \ingroup player - */ - -#ifndef __GPC_KEYBOARDDEVICE_H__ -#define __GPC_KEYBOARDDEVICE_H__ - -#ifdef WIN32 -#pragma warning (disable:4786) -#endif /* WIN32 */ - -#include "SCA_IInputDevice.h" - -#include <map> - - -/** - * System independent implementation of SCA_IInputDevice. - * System dependent keyboard devices need only to inherit this class - * and fill the m_reverseKeyTranslateTable key translation map. - * \see SCA_IInputDevice - */ - -class GPC_KeyboardDevice : public SCA_IInputDevice -{ -protected: - - /** - * This map converts system dependent keyboard codes into Ketsji codes. - * System dependent keyboard codes are stored as ints. - */ - std::map<int, KX_EnumInputs> m_reverseKeyTranslateTable; - short m_exitkey; - -public: - bool m_hookesc; - GPC_KeyboardDevice() - : m_hookesc(false) - { - } - - virtual ~GPC_KeyboardDevice(void) - { - } - - virtual bool IsPressed(SCA_IInputDevice::KX_EnumInputs inputcode) - { - return false; - } - - virtual void NextFrame(); - - virtual KX_EnumInputs ToNative(int incode) - { - return m_reverseKeyTranslateTable[incode]; - } - - virtual bool ConvertEvent(int incode, int val, unsigned int unicode); - - virtual void HookEscape(); -}; - -#endif /* __GPC_KEYBOARDDEVICE_H__ */ diff --git a/source/gameengine/GamePlayer/common/GPC_MouseDevice.cpp b/source/gameengine/GamePlayer/common/GPC_MouseDevice.cpp deleted file mode 100644 index 94045d532af..00000000000 --- a/source/gameengine/GamePlayer/common/GPC_MouseDevice.cpp +++ /dev/null @@ -1,214 +0,0 @@ -/* - * ***** BEGIN GPL 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. - * - * 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, 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 LICENSE BLOCK ***** - */ - -/** \file gameengine/GamePlayer/common/GPC_MouseDevice.cpp - * \ingroup player - */ - - -#include "GPC_MouseDevice.h" - -GPC_MouseDevice::GPC_MouseDevice() -{ - -} -GPC_MouseDevice::~GPC_MouseDevice() -{ - -} - -/** - * IsPressed gives boolean information about mouse status, true if pressed, false if not. - */ -bool GPC_MouseDevice::IsPressed(SCA_IInputDevice::KX_EnumInputs inputcode) -{ - const SCA_InputEvent & inevent = m_eventStatusTables[m_currentTable][inputcode]; - bool pressed = (inevent.m_status == SCA_InputEvent::KX_JUSTACTIVATED || - inevent.m_status == SCA_InputEvent::KX_ACTIVE); - return pressed; -} - - -/** - * NextFrame toggles currentTable with previousTable, - * and copies relevant event information from previous to current table - * (pressed keys need to be remembered). - */ -void GPC_MouseDevice::NextFrame() -{ - SCA_IInputDevice::NextFrame(); - - // Convert just pressed events into regular (active) events - int previousTable = 1-m_currentTable; - for (int mouseevent= KX_BEGINMOUSE; mouseevent< KX_ENDMOUSEBUTTONS; mouseevent++) { - SCA_InputEvent& oldevent = m_eventStatusTables[previousTable][mouseevent]; - if (oldevent.m_status == SCA_InputEvent::KX_JUSTACTIVATED || - oldevent.m_status == SCA_InputEvent::KX_ACTIVE) - { - m_eventStatusTables[m_currentTable][mouseevent] = oldevent; - m_eventStatusTables[m_currentTable][mouseevent].m_status = SCA_InputEvent::KX_ACTIVE; - } - } - for (int mousemove= KX_ENDMOUSEBUTTONS; mousemove< KX_ENDMOUSE; mousemove++) { - SCA_InputEvent& oldevent = m_eventStatusTables[previousTable][mousemove]; - m_eventStatusTables[m_currentTable][mousemove] = oldevent; - if (oldevent.m_status == SCA_InputEvent::KX_JUSTACTIVATED || - oldevent.m_status == SCA_InputEvent::KX_ACTIVE) - { - m_eventStatusTables[m_currentTable][mousemove].m_status = SCA_InputEvent::KX_JUSTRELEASED; - } - else { - if (oldevent.m_status == SCA_InputEvent::KX_JUSTRELEASED) { - m_eventStatusTables[m_currentTable][mousemove].m_status = SCA_InputEvent::KX_NO_INPUTSTATUS; - } - } - } -} - - -bool GPC_MouseDevice::ConvertButtonEvent(TButtonId button, bool isDown) -{ - bool result = false; - - switch (button) - { - case buttonLeft: - result = ConvertEvent(KX_LEFTMOUSE, isDown, 0); - break; - case buttonMiddle: - result = ConvertEvent(KX_MIDDLEMOUSE, isDown, 0); - break; - case buttonRight: - result = ConvertEvent(KX_RIGHTMOUSE, isDown, 0); - break; - case buttonWheelUp: - result = ConvertEvent(KX_WHEELUPMOUSE, isDown, 0); - break; - case buttonWheelDown: - result = ConvertEvent(KX_WHEELDOWNMOUSE, isDown, 0); - break; - default: - // Should not happen! - break; - } - - return result; -} - -/** - * Splits combined button and x,y cursor move events into separate Ketsji - * x and y move and button events. - */ -bool GPC_MouseDevice::ConvertButtonEvent(TButtonId button, bool isDown, int x, int y) -{ - // First update state tables for cursor move. - bool result = ConvertMoveEvent(x, y); - - // Now update for button state. - if (result) { - result = ConvertButtonEvent(button, isDown); - } - - return result; -} - -/** - * Splits combined x,y move into separate Ketsji x and y move events. - */ -bool GPC_MouseDevice::ConvertMoveEvent(int x, int y) -{ - bool result; - - // Convert to local coordinates? - result = ConvertEvent(KX_MOUSEX, x, 0); - if (result) { - result = ConvertEvent(KX_MOUSEY, y, 0); - } - - return result; -} - - -bool GPC_MouseDevice::ConvertEvent(KX_EnumInputs kxevent, int eventval, unsigned int unicode) -{ - bool result = true; - - // Only process it, if it's a mouse event - if (kxevent > KX_BEGINMOUSE && kxevent < KX_ENDMOUSE) { - int previousTable = 1-m_currentTable; - - if (eventval > 0) { - m_eventStatusTables[m_currentTable][kxevent].m_eventval = eventval; - - switch (m_eventStatusTables[previousTable][kxevent].m_status) - { - case SCA_InputEvent::KX_ACTIVE: - case SCA_InputEvent::KX_JUSTACTIVATED: - { - m_eventStatusTables[m_currentTable][kxevent].m_status = SCA_InputEvent::KX_ACTIVE; - break; - } - case SCA_InputEvent::KX_JUSTRELEASED: - { - if ( kxevent > KX_BEGINMOUSEBUTTONS && kxevent < KX_ENDMOUSEBUTTONS) - { - m_eventStatusTables[m_currentTable][kxevent].m_status = SCA_InputEvent::KX_JUSTACTIVATED; - } else - { - m_eventStatusTables[m_currentTable][kxevent].m_status = SCA_InputEvent::KX_ACTIVE; - - } - break; - } - default: - { - m_eventStatusTables[m_currentTable][kxevent].m_status = SCA_InputEvent::KX_JUSTACTIVATED; - } - } - - } - else { - switch (m_eventStatusTables[previousTable][kxevent].m_status) - { - case SCA_InputEvent::KX_JUSTACTIVATED: - case SCA_InputEvent::KX_ACTIVE: - { - m_eventStatusTables[m_currentTable][kxevent].m_status = SCA_InputEvent::KX_JUSTRELEASED; - break; - } - default: - { - m_eventStatusTables[m_currentTable][kxevent].m_status = SCA_InputEvent::KX_NO_INPUTSTATUS; - } - } - } - } - else { - result = false; - } - return result; -} diff --git a/source/gameengine/GamePlayer/common/GPC_MouseDevice.h b/source/gameengine/GamePlayer/common/GPC_MouseDevice.h deleted file mode 100644 index 24922197723..00000000000 --- a/source/gameengine/GamePlayer/common/GPC_MouseDevice.h +++ /dev/null @@ -1,103 +0,0 @@ -/* - * ***** BEGIN GPL 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. - * - * 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, 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 LICENSE BLOCK ***** - */ - -/** \file GPC_MouseDevice.h - * \ingroup player - */ - -#ifndef __GPC_MOUSEDEVICE_H__ -#define __GPC_MOUSEDEVICE_H__ - -#ifdef WIN32 -#pragma warning (disable:4786) -#endif /* WIN32 */ - -#include "SCA_IInputDevice.h" - - -/** - * Generic Ketsji mouse device. - * \see SCA_IInputDevice - */ -class GPC_MouseDevice : public SCA_IInputDevice -{ -public: - /** - * Button identifier. - */ - typedef enum { - buttonLeft, - buttonMiddle, - buttonRight, - buttonWheelUp, - buttonWheelDown - } TButtonId; - - GPC_MouseDevice(); - virtual ~GPC_MouseDevice(void); - - virtual bool IsPressed(SCA_IInputDevice::KX_EnumInputs inputcode); - virtual void NextFrame(); - - /** - * Call this routine to update the mouse device when a button state changes. - * \param button Which button state changes. - * \param isDown The new state of the button. - * \return Indication as to whether the event was processed. - */ - virtual bool ConvertButtonEvent(TButtonId button, bool isDown); - - /** - * Call this routine to update the mouse device when a button state and - * cursor position changes at the same time (e.g. in Win32 messages). - * \param button Which button state changes. - * \param isDown The new state of the button. - * \param x Position x-coordinate of the cursor at the time of the state change. - * \param y Position y-coordinate of the cursor at the time of the state change. - * \return Indication as to whether the event was processed. - */ - virtual bool ConvertButtonEvent(TButtonId button, bool isDown, int x, int y); - - /** - * Call this routine to update the mouse device when the cursor has moved. - * \param x Position x-coordinate of the cursor. - * \param y Position y-coordinate of the cursor. - * \return Indication as to whether the event was processed. - */ - virtual bool ConvertMoveEvent(int x, int y); - -protected: - /** - * This routine converts a single mouse event to a Ketsji mouse event. - * \param kxevent Ketsji event code. - * \param eventval Value for this event. - * \return Indication as to whether the event was processed. - */ - virtual bool ConvertEvent(KX_EnumInputs kxevent, int eventval, unsigned int unicode); -}; - -#endif /* __GPC_MOUSEDEVICE_H__ */ diff --git a/source/gameengine/GamePlayer/ghost/CMakeLists.txt b/source/gameengine/GamePlayer/ghost/CMakeLists.txt deleted file mode 100644 index 5bce9fcd248..00000000000 --- a/source/gameengine/GamePlayer/ghost/CMakeLists.txt +++ /dev/null @@ -1,112 +0,0 @@ -# ***** BEGIN GPL 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. -# -# 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -# -# The Original Code is Copyright (C) 2006, Blender Foundation -# All rights reserved. -# -# The Original Code is: all of this file. -# -# Contributor(s): Jacques Beaurain. -# -# ***** END GPL LICENSE BLOCK ***** - -set(INC - . - ../common - ../../BlenderRoutines - ../../Converter - ../../Expressions - ../../GameLogic - ../../Ketsji - ../../Network - ../../Network/LoopBackNetwork - ../../Physics/common - ../../Rasterizer - ../../Rasterizer/RAS_OpenGLRasterizer - ../../SceneGraph - ../../../blender - ../../../blender/blenfont - ../../../blender/blenkernel - ../../../blender/blenlib - ../../../blender/blenloader - ../../../blender/blentranslation - ../../../blender/depsgraph - ../../../blender/gpu - ../../../blender/imbuf - ../../../blender/makesdna - ../../../blender/makesrna - ../../../../intern/container - ../../../../intern/ghost - ../../../../intern/glew-mx - ../../../../intern/guardedalloc - ../../../../intern/string - ../../../../intern/memutil -) - -set(INC_SYS - ../../../../intern/moto/include - ${GLEW_INCLUDE_PATH} - ${PYTHON_INCLUDE_DIRS} - ${BOOST_INCLUDE_DIR} -) - -set(SRC - GPG_Application.cpp - GPG_Canvas.cpp - GPG_KeyboardDevice.cpp - GPG_System.cpp - GPG_ghost.cpp - - GPG_Application.h - GPG_Canvas.h - GPG_KeyboardDevice.h - GPG_System.h -) - -add_definitions(${GL_DEFINITIONS}) - -if(WIN32) - blender_include_dirs(../../../../intern/utfconv) -endif() - -if(WITH_INPUT_NDOF) - add_definitions(-DWITH_INPUT_NDOF) -endif(WITH_INPUT_NDOF) - -if(WITH_CODEC_FFMPEG) - add_definitions(-DWITH_FFMPEG) -endif() - -if(WITH_INTERNATIONAL) - add_definitions(-DWITH_INTERNATIONAL) -endif() - -if(WITH_AUDASPACE) - add_definitions(-DWITH_AUDASPACE) - - list(APPEND INC_SYS - ${AUDASPACE_C_INCLUDE_DIRS} - ) -endif() - -if(WITH_SDL AND WITH_SDL_DYNLOAD) - list(APPEND INC - ../../../../extern/sdlew/include - ) - add_definitions(-DWITH_SDL_DYNLOAD) -endif() - -blender_add_lib_nolist(ge_player_ghost "${SRC}" "${INC}" "${INC_SYS}") diff --git a/source/gameengine/GamePlayer/ghost/GPG_Application.cpp b/source/gameengine/GamePlayer/ghost/GPG_Application.cpp deleted file mode 100644 index 1b6b6defdf9..00000000000 --- a/source/gameengine/GamePlayer/ghost/GPG_Application.cpp +++ /dev/null @@ -1,998 +0,0 @@ -/* - * ***** BEGIN GPL 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. - * - * 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, 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 LICENSE BLOCK ***** - * GHOST Blender Player application implementation file. - */ - -/** \file gameengine/GamePlayer/ghost/GPG_Application.cpp - * \ingroup player - */ - - -#ifdef WIN32 -# pragma warning (disable:4786) // suppress stl-MSVC debug info warning -# include <windows.h> -#endif - -#include "GPU_glew.h" -#include "GPU_extensions.h" -#include "GPU_init_exit.h" - -#include "GPG_Application.h" -#include "BL_BlenderDataConversion.h" - -#include <iostream> -#include <MT_assert.h> -#include <stdlib.h> - -/********************************** - * Begin Blender include block - **********************************/ -#ifdef __cplusplus -extern "C" -{ -#endif // __cplusplus -#include "BLI_blenlib.h" -#include "BLO_readfile.h" -#include "BKE_global.h" -#include "BKE_main.h" -#include "BKE_sound.h" -#include "IMB_imbuf.h" -#include "DNA_scene_types.h" -#ifdef __cplusplus -} -#endif // __cplusplus -/********************************** - * End Blender include block - **********************************/ - - -#include "BL_System.h" -#include "KX_KetsjiEngine.h" - -// include files needed by "KX_BlenderSceneConverter.h" -#include "CTR_Map.h" -#include "SCA_IActuator.h" -#include "RAS_MeshObject.h" -#include "RAS_OpenGLRasterizer.h" -#include "RAS_ListRasterizer.h" -#include "KX_PythonInit.h" -#include "KX_PyConstraintBinding.h" -#include "BL_Material.h" // MAXTEX - -#include "KX_BlenderSceneConverter.h" -#include "NG_LoopBackNetworkDeviceInterface.h" - -#include "GPC_MouseDevice.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" - -#ifdef WITH_AUDASPACE -# include <AUD_Device.h> -#endif - -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) - : m_startSceneName(""), - m_startScene(0), - m_maggie(0), - m_kxStartScene(NULL), - m_exitRequested(0), - m_system(system), - m_mainWindow(0), - m_frameTimer(0), - m_cursor(GHOST_kStandardCursorFirstCursor), - m_engineInitialized(0), - m_engineRunning(0), - m_isEmbedded(false), - m_ketsjiengine(0), - m_kxsystem(0), - m_keyboard(0), - m_mouse(0), - m_canvas(0), - m_rasterizer(0), - m_sceneconverter(0), - m_networkdevice(0), - m_blendermat(0), - m_blenderglslmat(0), - m_pyGlobalDictString(0), - m_pyGlobalDictString_Length(0) -{ - fSystem = system; -} - - - -GPG_Application::~GPG_Application(void) -{ - if (m_pyGlobalDictString) { - delete [] m_pyGlobalDictString; - m_pyGlobalDictString = 0; - m_pyGlobalDictString_Length = 0; - } - - exitEngine(); - fSystem->disposeWindow(m_mainWindow); -} - - - -bool GPG_Application::SetGameEngineData(struct Main* maggie, Scene *scene, GlobalSettings *gs, int argc, char **argv) -{ - bool result = false; - - if (maggie != NULL && scene != NULL) - { -// XXX G.scene = scene; - m_maggie = maggie; - m_startSceneName = scene->id.name+2; - m_startScene = scene; - result = true; - } - - /* Python needs these */ - m_argc= argc; - m_argv= argv; - - /* Global Settings */ - m_globalSettings= gs; - - return result; -} - - -#ifdef WIN32 -#define SCR_SAVE_MOUSE_MOVE_THRESHOLD 15 - -static HWND found_ghost_window_hwnd; -static GHOST_IWindow* ghost_window_to_find; -static WNDPROC ghost_wnd_proc; -static POINT scr_save_mouse_pos; - -static LRESULT CALLBACK screenSaverWindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam) -{ - BOOL close = false; - switch (uMsg) - { - case WM_MOUSEMOVE: - { - POINT pt; - GetCursorPos(&pt); - LONG dx = scr_save_mouse_pos.x - pt.x; - LONG dy = scr_save_mouse_pos.y - pt.y; - if (abs(dx) > SCR_SAVE_MOUSE_MOVE_THRESHOLD - || abs(dy) > SCR_SAVE_MOUSE_MOVE_THRESHOLD) - { - close = true; - } - scr_save_mouse_pos = pt; - break; - } - case WM_LBUTTONDOWN: - case WM_MBUTTONDOWN: - case WM_RBUTTONDOWN: - case WM_KEYDOWN: - close = true; - } - if (close) - PostMessage(hwnd,WM_CLOSE,0,0); - return CallWindowProc(ghost_wnd_proc, hwnd, uMsg, wParam, lParam); -} - -BOOL CALLBACK findGhostWindowHWNDProc(HWND hwnd, LPARAM lParam) -{ - GHOST_IWindow *p = (GHOST_IWindow*) GetWindowLongPtr(hwnd, GWLP_USERDATA); - BOOL ret = true; - if (p == ghost_window_to_find) - { - found_ghost_window_hwnd = hwnd; - ret = false; - } - return ret; -} - -static HWND findGhostWindowHWND(GHOST_IWindow* window) -{ - found_ghost_window_hwnd = NULL; - ghost_window_to_find = window; - EnumWindows(findGhostWindowHWNDProc, NULL); - return found_ghost_window_hwnd; -} - -bool GPG_Application::startScreenSaverPreview( - HWND parentWindow, - const bool stereoVisual, - const int stereoMode, - const GHOST_TUns16 samples) -{ - bool success = false; - - RECT rc; - if (GetWindowRect(parentWindow, &rc)) - { - int windowWidth = rc.right - rc.left; - int windowHeight = rc.bottom - rc.top; - STR_String title = ""; - GHOST_GLSettings glSettings = {0}; - - if (stereoVisual) { - glSettings.flags |= GHOST_glStereoVisual; - } - glSettings.numOfAASamples = samples; - - m_mainWindow = fSystem->createWindow(title, 0, 0, windowWidth, windowHeight, GHOST_kWindowStateMinimized, - GHOST_kDrawingContextTypeOpenGL, glSettings); - if (!m_mainWindow) { - printf("error: could not create main window\n"); - exit(-1); - } - - HWND ghost_hwnd = findGhostWindowHWND(m_mainWindow); - if (!ghost_hwnd) { - printf("error: could find main window\n"); - exit(-1); - } - - SetParent(ghost_hwnd, parentWindow); - LONG_PTR style = GetWindowLongPtr(ghost_hwnd, GWL_STYLE); - LONG_PTR exstyle = GetWindowLongPtr(ghost_hwnd, GWL_EXSTYLE); - - RECT adjrc = { 0, 0, windowWidth, windowHeight }; - AdjustWindowRectEx(&adjrc, style, false, exstyle); - - style = (style & (~(WS_POPUP|WS_OVERLAPPEDWINDOW|WS_OVERLAPPED|WS_CAPTION|WS_SYSMENU|WS_THICKFRAME|WS_MINIMIZEBOX|WS_MAXIMIZEBOX|WS_TILEDWINDOW ))) | WS_CHILD; - SetWindowLongPtr(ghost_hwnd, GWL_STYLE, style); - SetWindowPos(ghost_hwnd, NULL, adjrc.left, adjrc.top, 0, 0, SWP_NOZORDER|SWP_NOSIZE|SWP_NOACTIVATE); - - /* 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::startScreenSaverFullScreen( - int width, - int height, - int bpp,int frequency, - const bool stereoVisual, - const int stereoMode, - const GHOST_TUns16 samples) -{ - bool ret = startFullScreen(width, height, bpp, frequency, stereoVisual, stereoMode, 0, samples); - if (ret) - { - HWND ghost_hwnd = findGhostWindowHWND(m_mainWindow); - if (ghost_hwnd != NULL) - { - GetCursorPos(&scr_save_mouse_pos); - ghost_wnd_proc = (WNDPROC) GetWindowLongPtr(ghost_hwnd, GWLP_WNDPROC); - SetWindowLongPtr(ghost_hwnd,GWLP_WNDPROC, (uintptr_t) screenSaverWindowProc); - } - } - return ret; -} - -#endif - -bool GPG_Application::startWindow( - STR_String& title, - int windowLeft, - int windowTop, - int windowWidth, - int windowHeight, - const bool stereoVisual, - const int stereoMode, - const int alphaBackground, - const GHOST_TUns16 samples) -{ - GHOST_GLSettings glSettings = {0}; - bool success; - // Create the main window - //STR_String title ("Blender Player - GHOST"); - if (stereoVisual) - glSettings.flags |= GHOST_glStereoVisual; - if (alphaBackground) - glSettings.flags |= GHOST_glAlphaBackground; - glSettings.numOfAASamples = samples; - - m_mainWindow = fSystem->createWindow(title, windowLeft, windowTop, windowWidth, windowHeight, GHOST_kWindowStateNormal, - GHOST_kDrawingContextTypeOpenGL, glSettings); - 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); - m_mainWindow->setCursorVisibility(false); - - success = initEngine(m_mainWindow, stereoMode); - if (success) { - success = startEngine(); - } - return success; -} - -bool GPG_Application::startEmbeddedWindow( - STR_String& title, - const GHOST_TEmbedderWindowID parentWindow, - const bool stereoVisual, - const int stereoMode, - const int alphaBackground, - const GHOST_TUns16 samples) -{ - GHOST_TWindowState state = GHOST_kWindowStateNormal; - GHOST_GLSettings glSettings = {0}; - - if (stereoVisual) - glSettings.flags |= GHOST_glStereoVisual; - if (alphaBackground) - glSettings.flags |= GHOST_glAlphaBackground; - glSettings.numOfAASamples = samples; - - if (parentWindow != 0) - state = GHOST_kWindowStateEmbedded; - m_mainWindow = fSystem->createWindow(title, 0, 0, 0, 0, state, - GHOST_kDrawingContextTypeOpenGL, glSettings, parentWindow); - - if (!m_mainWindow) { - printf("error: could not create main window\n"); - exit(-1); - } - m_isEmbedded = true; - - bool 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, - const int alphaBackground, - const GHOST_TUns16 samples, - bool useDesktop) -{ - bool success; - GHOST_TUns32 sysWidth=0, sysHeight=0; - fSystem->getMainDisplayDimensions(sysWidth, sysHeight); - // Create the main window - GHOST_DisplaySetting setting; - setting.xPixels = (useDesktop) ? sysWidth : width; - setting.yPixels = (useDesktop) ? sysHeight : height; - setting.bpp = bpp; - setting.frequency = frequency; - - fSystem->beginFullScreen(setting, &m_mainWindow, stereoVisual, alphaBackground, samples); - m_mainWindow->setCursorVisibility(false); - /* note that X11 ignores this (it uses a window internally for fullscreen) */ - m_mainWindow->setState(GHOST_kWindowStateFullScreen); - - 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_kEventWheel: - handled = handleWheel(event); - 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: - case GHOST_kEventQuit: - m_exitRequested = KX_EXIT_REQUEST_OUTSIDE; - break; - - case GHOST_kEventWindowActivate: - handled = false; - break; - case GHOST_kEventWindowDeactivate: - handled = false; - break; - - // The player now runs as often as it can (repsecting vsync and fixedtime). - // This allows the player to break 100fps, but this code is being left here - // as reference. (see EngineNextFrame) - //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 - // bool renderFrame = m_ketsjiengine->NextFrame(); - // if (renderFrame) - // { - // // 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()); - m_ketsjiengine->Resize(); - } - } - break; - - default: - handled = false; - break; - } - return handled; -} - - - -int GPG_Application::getExitRequested(void) -{ - return m_exitRequested; -} - - -GlobalSettings* GPG_Application::getGlobalSettings(void) -{ - return m_ketsjiengine->GetGlobalSettings(); -} - - - -const STR_String& GPG_Application::getExitString(void) -{ - return m_exitString; -} - - - -bool GPG_Application::initEngine(GHOST_IWindow* window, const int stereoMode) -{ - if (!m_engineInitialized) - { - GPU_init(); - - // get and set the preferences - SYS_SystemHandle syshandle = SYS_GetSystem(); - if (!syshandle) - return false; - - // SYS_WriteCommandLineInt(syshandle, "fixedtime", 0); - // SYS_WriteCommandLineInt(syshandle, "vertexarrays",1); - GameData *gm= &m_startScene->gm; - bool properties = (SYS_GetCommandLineInt(syshandle, "show_properties", 0) != 0); - bool profile = (SYS_GetCommandLineInt(syshandle, "show_profile", 0) != 0); - - bool showPhysics = (gm->flag & GAME_SHOW_PHYSICS); - SYS_WriteCommandLineInt(syshandle, "show_physics", showPhysics); - - bool fixed_framerate= (SYS_GetCommandLineInt(syshandle, "fixedtime", (gm->flag & GAME_ENABLE_ALL_FRAMES)) != 0); - bool frameRate = (SYS_GetCommandLineInt(syshandle, "show_framerate", 0) != 0); - bool useLists = false; // (SYS_GetCommandLineInt(syshandle, "displaylists", gm->flag & GAME_DISPLAY_LISTS) != 0) && GPU_display_list_support(); - bool nodepwarnings = (SYS_GetCommandLineInt(syshandle, "ignore_deprecation_warnings", 1) != 0); - bool restrictAnimFPS = (gm->flag & GAME_RESTRICT_ANIM_UPDATES) != 0; - - m_blendermat = (SYS_GetCommandLineInt(syshandle, "blender_material", 1) != 0); - m_blenderglslmat = (SYS_GetCommandLineInt(syshandle, "blender_glsl_material", 1) != 0); - - // create the canvas, rasterizer and rendertools - m_canvas = new GPG_Canvas(window); - if (!m_canvas) - return false; - - if (gm->vsync == VSYNC_ADAPTIVE) - m_canvas->SetSwapInterval(-1); - else - m_canvas->SetSwapInterval((gm->vsync == VSYNC_ON) ? 1 : 0); - - m_canvas->Init(); - if (gm->flag & GAME_SHOW_MOUSE) - m_canvas->SetMouseState(RAS_ICanvas::MOUSE_NORMAL); - - RAS_STORAGE_TYPE raster_storage = RAS_AUTO_STORAGE; - - if (gm->raster_storage == RAS_STORE_VBO) { - raster_storage = RAS_VBO; - } - else if (gm->raster_storage == RAS_STORE_VA) { - raster_storage = RAS_VA; - } - //Don't use displaylists with VBOs - //If auto starts using VBOs, make sure to check for that here - if (useLists && raster_storage != RAS_VBO) - m_rasterizer = new RAS_ListRasterizer(m_canvas, true, raster_storage); - else - m_rasterizer = new RAS_OpenGLRasterizer(m_canvas, raster_storage); - - /* Stereo parameters - Eye Separation from the UI - stereomode from the command-line/UI */ - m_rasterizer->SetStereoMode((RAS_IRasterizer::StereoMode) stereoMode); - m_rasterizer->SetEyeSeparation(m_startScene->gm.eyeseparation); - - if (!m_rasterizer) - goto initFailed; - - m_rasterizer->PrintHardwareInfo(); - - // create the inputdevices - m_keyboard = new GPG_KeyboardDevice(); - if (!m_keyboard) - goto initFailed; - - m_mouse = new GPC_MouseDevice(); - if (!m_mouse) - goto initFailed; - - // create a networkdevice - m_networkdevice = new NG_LoopBackNetworkDeviceInterface(); - if (!m_networkdevice) - goto initFailed; - - BKE_sound_init(m_maggie); - - // create a ketsjisystem (only needed for timing and stuff) - m_kxsystem = new GPG_System (m_system); - if (!m_kxsystem) - goto initFailed; - - // 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->SetRasterizer(m_rasterizer); - - KX_KetsjiEngine::SetExitKey(ConvertKeyCode(gm->exitkey)); -#ifdef WITH_PYTHON - CValue::SetDeprecationWarnings(nodepwarnings); -#else - (void)nodepwarnings; -#endif - - m_ketsjiengine->SetUseFixedTime(fixed_framerate); - m_ketsjiengine->SetTimingDisplay(frameRate, profile, properties); - m_ketsjiengine->SetRestrictAnimationFPS(restrictAnimFPS); - - //set the global settings (carried over if restart/load new files) - m_ketsjiengine->SetGlobalSettings(m_globalSettings); - m_ketsjiengine->SetRender(true); - - m_engineInitialized = true; - } - - return m_engineInitialized; -initFailed: - BKE_sound_exit(); - delete m_kxsystem; - delete m_networkdevice; - delete m_mouse; - delete m_keyboard; - delete m_rasterizer; - delete m_canvas; - m_canvas = NULL; - m_rasterizer = NULL; - m_keyboard = NULL; - m_mouse = NULL; - m_networkdevice = NULL; - m_kxsystem = NULL; - return false; -} - - - -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*)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 m_kxStartScenename = m_startSceneName.Ptr(); - m_ketsjiengine->SetSceneConverter(m_sceneconverter); - - // if (always_use_expand_framing) - // sceneconverter->SetAlwaysUseExpandFraming(true); - if (m_blendermat) - m_sceneconverter->SetMaterials(true); - if (m_blenderglslmat && (m_globalSettings->matmode == GAME_MAT_GLSL)) - m_sceneconverter->SetGLSLMaterials(true); - if (m_startScene->gm.flag & GAME_NO_MATERIAL_CACHING) - m_sceneconverter->SetCacheMaterials(false); - - m_kxStartScene = new KX_Scene(m_keyboard, - m_mouse, - m_networkdevice, - m_kxStartScenename, - m_startScene, - m_canvas); - -#ifdef WITH_PYTHON - // some python things - PyObject *gameLogic, *gameLogic_keys; - setupGamePython(m_ketsjiengine, m_kxStartScene, m_maggie, NULL, &gameLogic, &gameLogic_keys, m_argc, m_argv); -#endif // WITH_PYTHON - - //initialize Dome Settings - if (m_startScene->gm.stereoflag == STEREO_DOME) - m_ketsjiengine->InitDome(m_startScene->gm.dome.res, m_startScene->gm.dome.mode, m_startScene->gm.dome.angle, m_startScene->gm.dome.resbuf, m_startScene->gm.dome.tilt, m_startScene->gm.dome.warptext); - - // initialize 3D Audio Settings - AUD_Device* device = BKE_sound_get_device(); - AUD_Device_setSpeedOfSound(device, m_startScene->audio.speed_of_sound); - AUD_Device_setDopplerFactor(device, m_startScene->audio.doppler_factor); - AUD_Device_setDistanceModel(device, AUD_DistanceModel(m_startScene->audio.distance_model)); - -#ifdef WITH_PYTHON - // Set the GameLogic.globalDict from marshal'd data, so we can - // load new blend files and keep data in GameLogic.globalDict - loadGamePythonConfig(m_pyGlobalDictString, m_pyGlobalDictString_Length); -#endif - m_sceneconverter->ConvertScene( - m_kxStartScene, - m_rasterizer, - m_canvas); - m_ketsjiengine->AddScene(m_kxStartScene); - - // 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(true); - m_engineRunning = true; - - // Set the animation playback rate for ipo's and actions - // the framerate below should patch with FPS macro defined in blendef.h - // Could be in StartEngine set the framerate, we need the scene to do this - Scene *scene= m_kxStartScene->GetBlenderScene(); // needed for macro - m_ketsjiengine->SetAnimFrameRate(FPS); - } - - if (!m_engineRunning) - { - stopEngine(); - } - - return m_engineRunning; -} - - -void GPG_Application::stopEngine() -{ -#ifdef WITH_PYTHON - // GameLogic.globalDict gets converted into a buffer, and sorted in - // m_pyGlobalDictString so we can restore after python has stopped - // and started between .blend file loads. - if (m_pyGlobalDictString) { - delete [] m_pyGlobalDictString; - m_pyGlobalDictString = 0; - } - - m_pyGlobalDictString_Length = saveGamePythonConfig(&m_pyGlobalDictString); -#endif - - 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::EngineNextFrame() -{ - // Update the state of the game engine - if (m_kxsystem && !m_exitRequested) - { - // Proceed to next frame - if (m_mainWindow) - m_mainWindow->activateDrawingContext(); - - // first check if we want to exit - m_exitRequested = m_ketsjiengine->GetExitCode(); - - // kick the engine - bool renderFrame = m_ketsjiengine->NextFrame(); - if (renderFrame && m_mainWindow) - { - // render the frame - m_ketsjiengine->Render(); - } - } - m_exitString = m_ketsjiengine->GetExitString(); -} - -void GPG_Application::exitEngine() -{ - // We only want to kill the engine if it has been initialized - if (!m_engineInitialized) - return; - - BKE_sound_exit(); - if (m_ketsjiengine) - { - stopEngine(); - delete m_ketsjiengine; - m_ketsjiengine = 0; - } - if (m_kxsystem) - { - delete m_kxsystem; - m_kxsystem = 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_canvas) - { - delete m_canvas; - m_canvas = 0; - } - - GPU_exit(); - -#ifdef WITH_PYTHON - // Call this after we're sure nothing needs Python anymore (e.g., destructors) - exitGamePlayerPythonScripting(); -#endif - - m_exitRequested = 0; - m_engineInitialized = false; -} - -bool GPG_Application::handleWheel(GHOST_IEvent* event) -{ - bool handled = false; - MT_assert(event); - if (m_mouse) - { - GHOST_TEventDataPtr eventData = ((GHOST_IEvent*)event)->getData(); - GHOST_TEventWheelData* wheelData = static_cast<GHOST_TEventWheelData*>(eventData); - GPC_MouseDevice::TButtonId button; - if (wheelData->z > 0) - button = GPC_MouseDevice::buttonWheelUp; - else - button = GPC_MouseDevice::buttonWheelDown; - m_mouse->ConvertButtonEvent(button, true); - handled = true; - } - return handled; -} - -bool GPG_Application::handleButton(GHOST_IEvent* event, bool isDown) -{ - bool handled = false; - MT_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; - MT_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; - MT_assert(event); - if (m_keyboard) - { - GHOST_TEventDataPtr eventData = ((GHOST_IEvent*)event)->getData(); - GHOST_TEventKeyData* keyData = static_cast<GHOST_TEventKeyData*>(eventData); - unsigned int unicode = keyData->utf8_buf[0] ? BLI_str_utf8_as_unicode(keyData->utf8_buf) : keyData->ascii; - - if (m_keyboard->ToNative(keyData->key) == KX_KetsjiEngine::GetExitKey() && !m_keyboard->m_hookesc && !m_isEmbedded) { - m_exitRequested = KX_EXIT_REQUEST_OUTSIDE; - } - m_keyboard->ConvertEvent(keyData->key, isDown, unicode); - 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 deleted file mode 100644 index e757cc10e32..00000000000 --- a/source/gameengine/GamePlayer/ghost/GPG_Application.h +++ /dev/null @@ -1,181 +0,0 @@ -/* - * ***** BEGIN GPL 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. - * - * 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, 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 LICENSE BLOCK ***** - */ - -/** \file GPG_Application.h - * \ingroup player - * \brief GHOST Blender Player application declaration file. - */ - -#include "GHOST_IEventConsumer.h" -#include "STR_String.h" - -#ifdef WIN32 -#include <wtypes.h> -#endif - -#include "KX_KetsjiEngine.h" - -class KX_KetsjiEngine; -class KX_Scene; -class KX_ISceneConverter; -class NG_LoopBackNetworkDeviceInterface; -class RAS_IRasterizer; -class GHOST_IEvent; -class GHOST_ISystem; -class GHOST_ITimerTask; -class GHOST_IWindow; -class GPC_MouseDevice; -class GPG_Canvas; -class GPG_KeyboardDevice; -class GPG_System; -struct Main; -struct Scene; - -class GPG_Application : public GHOST_IEventConsumer -{ -public: - GPG_Application(GHOST_ISystem* system); - ~GPG_Application(void); - - bool SetGameEngineData(struct Main* maggie, struct Scene* scene, GlobalSettings* gs, int argc, char** argv); - bool startWindow(STR_String& title, - int windowLeft, int windowTop, - int windowWidth, int windowHeight, - const bool stereoVisual, const int stereoMode, const int alphaBackground=0, const GHOST_TUns16 samples=0); - bool startFullScreen(int width, int height, - int bpp, int frequency, - const bool stereoVisual, const int stereoMode, const int alphaBackground = 0, - const GHOST_TUns16 samples=0, bool useDesktop=false); - bool startEmbeddedWindow(STR_String& title, const GHOST_TEmbedderWindowID parent_window, - const bool stereoVisual, const int stereoMode, const int alphaBackground=0, const GHOST_TUns16 samples=0); -#ifdef WIN32 - bool startScreenSaverFullScreen(int width, int height, - int bpp, int frequency, - const bool stereoVisual, const int stereoMode, const GHOST_TUns16 samples=0); - bool startScreenSaverPreview(HWND parentWindow, - const bool stereoVisual, const int stereoMode, const GHOST_TUns16 samples=0); -#endif - - virtual bool processEvent(GHOST_IEvent* event); - int getExitRequested(void); - const STR_String& getExitString(void); - GlobalSettings* getGlobalSettings(void); - - inline KX_Scene *GetStartScene() const - { - return m_kxStartScene; - } - - bool StartGameEngine(int stereoMode); - void StopGameEngine(); - void EngineNextFrame(); - -protected: - bool handleWheel(GHOST_IEvent* event); - 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); - short m_exitkey; - - /* The game data */ - STR_String m_startSceneName; - struct Scene* m_startScene; - struct Main* m_maggie; - KX_Scene *m_kxStartScene; - - /* Exit state. */ - int m_exitRequested; - STR_String m_exitString; - GlobalSettings* m_globalSettings; - - /* 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; - /** Running on embedded window */ - bool m_isEmbedded; - - /** 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 rasterizer */ - RAS_IRasterizer* m_rasterizer; - /** Converts Blender data files. */ - KX_ISceneConverter* m_sceneconverter; - /** Network interface. */ - NG_LoopBackNetworkDeviceInterface* m_networkdevice; - - bool m_blendermat; - bool m_blenderglslmat; - - /* - * GameLogic.globalDict as a string so that loading new blend files can use the same dict. - * Do this because python starts/stops when loading blend files. - */ - char* m_pyGlobalDictString; - int m_pyGlobalDictString_Length; - - /* argc and argv need to be passed on to python */ - int m_argc; - char** m_argv; -}; diff --git a/source/gameengine/GamePlayer/ghost/GPG_Canvas.cpp b/source/gameengine/GamePlayer/ghost/GPG_Canvas.cpp deleted file mode 100644 index 09eb1691dae..00000000000 --- a/source/gameengine/GamePlayer/ghost/GPG_Canvas.cpp +++ /dev/null @@ -1,177 +0,0 @@ -/* - * ***** BEGIN GPL 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. - * - * 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, 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 LICENSE BLOCK ***** - */ - -/** \file gameengine/GamePlayer/ghost/GPG_Canvas.cpp - * \ingroup player - */ - - -#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) - { - m_window->setDrawingContextType(GHOST_kDrawingContextTypeOpenGL); - assert(m_window->getDrawingContextType() == GHOST_kDrawingContextTypeOpenGL); - } -} - -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) -{ - m_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_kStandardCursorDefault); - m_window->setCursorVisibility(true); - break; - } - } -} - - -void GPG_Canvas::SwapBuffers() -{ - if (m_window) - { - m_window->swapBuffers(); - } -} - -void GPG_Canvas::SetSwapInterval(int interval) -{ - if (m_window) - m_window->setSwapInterval(interval); -} - -bool GPG_Canvas::GetSwapInterval(int& intervalOut) -{ - if (m_window) - return (bool)m_window->getSwapInterval(intervalOut); - - return false; -} - -void GPG_Canvas::GetDisplayDimensions(int &width, int &height) - { - unsigned int uiwidth; - unsigned int uiheight; - - GHOST_ISystem *system = GHOST_ISystem::getSystem(); - system->getMainDisplayDimensions(uiwidth, uiheight); - - width = uiwidth; - height = uiheight; -} - -void GPG_Canvas::ResizeWindow(int width, int height) -{ - if (m_window->getState() == GHOST_kWindowStateFullScreen) - { - GHOST_ISystem* system = GHOST_ISystem::getSystem(); - GHOST_DisplaySetting setting; - setting.xPixels = width; - setting.yPixels = height; - //XXX allow these to be changed or kept from previous state - setting.bpp = 32; - setting.frequency = 60; - - system->updateFullScreen(setting, &m_window); - } - - m_window->setClientSize(width, height); - - Resize(width, height); -} - -void GPG_Canvas::SetFullScreen(bool enable) -{ - if (enable) - m_window->setState(GHOST_kWindowStateFullScreen); - else - m_window->setState(GHOST_kWindowStateNormal); -} - -bool GPG_Canvas::GetFullScreen() -{ - return m_window->getState() == GHOST_kWindowStateFullScreen; -} - -float GPG_Canvas::GetMouseNormalizedX(int x) -{ - return float(x)/this->GetWidth(); -} - -float GPG_Canvas::GetMouseNormalizedY(int y) -{ - return float(y)/this->GetHeight(); -} diff --git a/source/gameengine/GamePlayer/ghost/GPG_Canvas.h b/source/gameengine/GamePlayer/ghost/GPG_Canvas.h deleted file mode 100644 index 18afbf6cd9e..00000000000 --- a/source/gameengine/GamePlayer/ghost/GPG_Canvas.h +++ /dev/null @@ -1,76 +0,0 @@ -/* - * ***** BEGIN GPL 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. - * - * 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, 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 LICENSE BLOCK ***** - */ - -/** \file GPG_Canvas.h - * \ingroup player - */ - -#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(); - virtual void SetSwapInterval(int interval); - virtual bool GetSwapInterval(int& intervalOut); - - virtual int GetMouseX(int x) { return x; } - virtual int GetMouseY(int y) { return y; } - virtual float GetMouseNormalizedX(int x); - virtual float GetMouseNormalizedY(int y); - - virtual void GetDisplayDimensions(int &width, int &height); - - virtual void ResizeWindow(int width, int height); - virtual void SetFullScreen(bool enable); - virtual bool GetFullScreen(); - - 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 deleted file mode 100644 index eefaa3730cf..00000000000 --- a/source/gameengine/GamePlayer/ghost/GPG_KeyboardDevice.cpp +++ /dev/null @@ -1,165 +0,0 @@ -/* - * ***** BEGIN GPL 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. - * - * 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, 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 LICENSE BLOCK ***** - * GHOST Blender Player keyboard device implementation. - */ - -/** \file gameengine/GamePlayer/ghost/GPG_KeyboardDevice.cpp - * \ingroup player - */ - - -#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 ; - m_reverseKeyTranslateTable[GHOST_kKeyF13 ] = KX_F13KEY ; - m_reverseKeyTranslateTable[GHOST_kKeyF14 ] = KX_F14KEY ; - m_reverseKeyTranslateTable[GHOST_kKeyF15 ] = KX_F15KEY ; - m_reverseKeyTranslateTable[GHOST_kKeyF16 ] = KX_F16KEY ; - m_reverseKeyTranslateTable[GHOST_kKeyF17 ] = KX_F17KEY ; - m_reverseKeyTranslateTable[GHOST_kKeyF18 ] = KX_F18KEY ; - m_reverseKeyTranslateTable[GHOST_kKeyF19 ] = KX_F19KEY ; - - - // 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_kKeyPlus ] = KX_PLUSKEY ; - 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 ; - - m_reverseKeyTranslateTable[GHOST_kKeyOS ] = KX_OSKEY ; - - // 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 deleted file mode 100644 index ff8d56db40a..00000000000 --- a/source/gameengine/GamePlayer/ghost/GPG_KeyboardDevice.h +++ /dev/null @@ -1,56 +0,0 @@ -/* - * ***** BEGIN GPL 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. - * - * 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, 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 LICENSE BLOCK ***** - */ - -/** \file GPG_KeyboardDevice.h - * \ingroup player - * \brief 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 deleted file mode 100644 index 669ab0532d9..00000000000 --- a/source/gameengine/GamePlayer/ghost/GPG_System.cpp +++ /dev/null @@ -1,53 +0,0 @@ -/* - * ***** BEGIN GPL 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. - * - * 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, 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 LICENSE BLOCK ***** - * Blender Player system on GHOST. - */ - -/** \file gameengine/GamePlayer/ghost/GPG_System.cpp - * \ingroup player - */ - - -#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.0; - return time; -} - - diff --git a/source/gameengine/GamePlayer/ghost/GPG_System.h b/source/gameengine/GamePlayer/ghost/GPG_System.h deleted file mode 100644 index 1ec7a06d1cf..00000000000 --- a/source/gameengine/GamePlayer/ghost/GPG_System.h +++ /dev/null @@ -1,54 +0,0 @@ -/* - * ***** BEGIN GPL 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. - * - * 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, 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 LICENSE BLOCK ***** - */ - -/** \file GPG_System.h - * \ingroup player - * \brief 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 "KX_ISystem.h" - -class GHOST_ISystem; - -class GPG_System : public KX_ISystem -{ - 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 deleted file mode 100644 index 998058193bb..00000000000 --- a/source/gameengine/GamePlayer/ghost/GPG_ghost.cpp +++ /dev/null @@ -1,1228 +0,0 @@ -/* - * ***** BEGIN GPL 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. - * - * 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, 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 LICENSE BLOCK ***** - * Start up of the Blender Player on GHOST. - */ - -/** \file gameengine/GamePlayer/ghost/GPG_ghost.cpp - * \ingroup player - */ - - -#include <iostream> -#include <math.h> - -#ifdef __linux__ -#ifdef __alpha__ -#include <signal.h> -#endif /* __alpha__ */ -#endif /* __linux__ */ - -#include "KX_KetsjiEngine.h" -#include "KX_PythonInit.h" -#include "KX_PythonMain.h" -#include "KX_PyConstraintBinding.h" // for PHY_SetActiveEnvironment - -/********************************** - * Begin Blender include block - **********************************/ -#ifdef __cplusplus -extern "C" -{ -#endif // __cplusplus -#include "MEM_guardedalloc.h" -#include "MEM_CacheLimiterC-Api.h" - -#include "BLI_threads.h" -#include "BLI_mempool.h" -#include "BLI_blenlib.h" - -#include "DNA_scene_types.h" -#include "DNA_userdef_types.h" -#include "DNA_genfile.h" - -#include "BLO_readfile.h" -#include "BLO_runtime.h" - -#include "BKE_appdir.h" -#include "BKE_blender.h" -#include "BKE_global.h" -#include "BKE_icons.h" -#include "BKE_image.h" -#include "BKE_node.h" -#include "BKE_report.h" -#include "BKE_library.h" -#include "BKE_library_remap.h" -#include "BKE_modifier.h" -#include "BKE_material.h" -#include "BKE_text.h" -#include "BKE_sound.h" - -#include "DEG_depsgraph.h" - -#include "IMB_imbuf.h" -#include "IMB_moviecache.h" - -#ifdef __APPLE__ - int GHOST_HACK_getFirstFile(char buf[]); -#endif - -// For BLF -#include "BLF_api.h" -#include "BLT_translation.h" -#include "BLT_lang.h" -extern int datatoc_bfont_ttf_size; -extern char datatoc_bfont_ttf[]; -extern int datatoc_bmonofont_ttf_size; -extern char datatoc_bmonofont_ttf[]; - -#ifdef __cplusplus -} -#endif // __cplusplus - -#include "GPU_draw.h" - -/********************************** - * End Blender include block - **********************************/ - -#include "BL_System.h" -#include "GPG_Application.h" - -#include "GHOST_ISystem.h" -#include "RAS_IRasterizer.h" - -#include "BKE_main.h" - -#include "RNA_define.h" - -#ifdef WIN32 -# include <windows.h> -# if !defined(DEBUG) -# include <wincon.h> -# endif // !defined(DEBUG) -# if defined(_MSC_VER) && defined(_M_X64) -# include <math.h> /* needed for _set_FMA3_enable */ -# endif -# include "utfconv.h" -#endif // WIN32 - -#ifdef WITH_SDL_DYNLOAD -# include "sdlew.h" -#endif - -const int kMinWindowWidth = 100; -const int kMinWindowHeight = 100; - -static void mem_error_cb(const char *errorStr) -{ - fprintf(stderr, "%s", errorStr); - fflush(stderr); -} - -// library.c will only free window managers with a callback function. -// We don't actually use a wmWindowManager, but loading a blendfile -// loads wmWindows, so we need to free those. -static void wm_free(bContext *C, wmWindowManager *wm) -{ - BLI_freelistN(&wm->windows); -} - -#ifdef WIN32 -typedef enum { - SCREEN_SAVER_MODE_NONE = 0, - SCREEN_SAVER_MODE_PREVIEW, - SCREEN_SAVER_MODE_SAVER, - SCREEN_SAVER_MODE_CONFIGURATION, - SCREEN_SAVER_MODE_PASSWORD, -} ScreenSaverMode; - -static ScreenSaverMode scr_saver_mode = SCREEN_SAVER_MODE_NONE; -static HWND scr_saver_hwnd = NULL; - -static BOOL scr_saver_init(int argc, char **argv) -{ - scr_saver_mode = SCREEN_SAVER_MODE_NONE; - scr_saver_hwnd = NULL; - BOOL ret = false; - - int len = ::strlen(argv[0]); - if (len > 4 && !::stricmp(".scr", argv[0] + len - 4)) - { - scr_saver_mode = SCREEN_SAVER_MODE_CONFIGURATION; - ret = true; - if (argc >= 2) - { - if (argc >= 3) - { - scr_saver_hwnd = (HWND) ::atoi(argv[2]); - } - if (!::stricmp("/c", argv[1])) - { - scr_saver_mode = SCREEN_SAVER_MODE_CONFIGURATION; - if (scr_saver_hwnd == NULL) - scr_saver_hwnd = ::GetForegroundWindow(); - } - else if (!::stricmp("/s", argv[1])) - { - scr_saver_mode = SCREEN_SAVER_MODE_SAVER; - } - else if (!::stricmp("/a", argv[1])) - { - scr_saver_mode = SCREEN_SAVER_MODE_PASSWORD; - } - else if (!::stricmp("/p", argv[1]) - || !::stricmp("/l", argv[1])) - { - scr_saver_mode = SCREEN_SAVER_MODE_PREVIEW; - } - } - } - return ret; -} - -#endif /* WIN32 */ - -static void usage(const char* program, bool isBlenderPlayer) -{ - const char * consoleoption; - const char * example_filename = ""; - const char * example_pathname = ""; - -#ifdef _WIN32 - consoleoption = "[-c] "; -#else - consoleoption = ""; -#endif - - if (isBlenderPlayer) { - example_filename = "filename.blend"; -#ifdef _WIN32 - example_pathname = "c:\\"; -#else - example_pathname = "/home/user/"; -#endif - } - printf("\n"); - printf("usage: %s [--options] %s\n\n", program, example_filename); - printf("Available options are: [-w [w h l t]] [-f [fw fh fb ff]] %s[-g gamengineoptions] ", consoleoption); - printf("[-s stereomode] [-m aasamples]\n"); - printf("Optional parameters must be passed in order.\n"); - printf("Default values are set in the blend file.\n\n"); - printf(" -h: Prints this command summary\n\n"); - printf(" -w: display in a window\n"); - printf(" --Optional parameters--\n"); - printf(" w = window width\n"); - printf(" h = window height\n"); - printf(" l = window left coordinate\n"); - printf(" t = window top coordinate\n"); - printf(" Note: To define 'w' or 'h', both must be used."); - printf("Also, to define 'l' or 't', all four parameters must be used.\n"); - printf(" Example: -w or -w 500 300 or -w 500 300 0 0\n\n"); - printf(" -f: start game in fullscreen mode\n"); - printf(" --Optional parameters--\n"); - printf(" fw = fullscreen mode pixel width (use 0 to detect automatically)\n"); - printf(" fh = fullscreen mode pixel height (use 0 to detect automatically)\n"); - printf(" fb = fullscreen mode bits per pixel (default unless set in the blend file: 32)\n"); - printf(" ff = fullscreen mode frequency (default unless set in the blend file: 60)\n"); - printf(" Note: To define 'fw'' or 'fh'', both must be used.\n"); - printf(" Example: -f or -f 1024 768 or -f 0 0 16 or -f 1024 728 16 30\n\n"); - printf(" -s: start player in stereoscopy mode (requires 3D capable hardware)\n"); - printf(" stereomode: nostereo (default unless stereo is set in the blend file)\n"); - printf(" anaglyph (Red-Blue glasses)\n"); - printf(" sidebyside (Left Right)\n"); - printf(" syncdoubling (Above Below)\n"); - printf(" 3dtvtopbottom (Squashed Top-Bottom for passive glasses)\n"); - printf(" interlace (Interlace horizontally)\n"); - printf(" vinterlace (Vertical interlace for autostereo display)\n"); - printf(" hwpageflip (Quad buffered shutter glasses)\n"); - printf(" Example: -s sidebyside or -s vinterlace\n\n"); - printf(" -D: start player in dome mode\n"); - printf(" --Optional parameters--\n"); - printf(" angle = field of view in degrees\n"); - printf(" tilt = tilt angle in degrees\n"); - printf(" warpdata = a file to use for warping the image (absolute path)\n"); - printf(" mode: fisheye (Fisheye)\n"); - printf(" truncatedfront (Front-Truncated)\n"); - printf(" truncatedrear (Rear-Truncated)\n"); - printf(" cubemap (Cube Map)\n"); - printf(" sphericalpanoramic (Spherical Panoramic)\n"); - printf(" Example: -D or -D mode cubemap\n\n"); - printf(" -m: maximum anti-aliasing (eg. 2,4,8,16)\n\n"); - printf(" -i: parent window's ID\n\n"); -#ifdef _WIN32 - printf(" -c: keep console window open\n\n"); -#endif - printf(" -d: turn debugging on\n\n"); - printf(" -g: game engine options:\n\n"); - printf(" Name Default Description\n"); - printf(" ------------------------------------------------------------------------\n"); - printf(" fixedtime 0 \"Enable all frames\"\n"); - printf(" nomipmap 0 Disable mipmaps\n"); - printf(" show_framerate 0 Show the frame rate\n"); - printf(" show_properties 0 Show debug properties\n"); - printf(" show_profile 0 Show profiling information\n"); - printf(" blender_material 0 Enable material settings\n"); - printf(" ignore_deprecation_warnings 1 Ignore deprecation warnings\n"); - printf("\n"); - printf(" - : all arguments after this are ignored, allowing python to access them from sys.argv\n"); - printf("\n"); - printf("example: %s -w 320 200 10 10 -g noaudio %s%s\n", program, example_pathname, example_filename); - printf("example: %s -g show_framerate = 0 %s%s\n", program, example_pathname, example_filename); - printf("example: %s -i 232421 -m 16 %s%s\n\n", program, example_pathname, example_filename); -} - -static void get_filename(int argc, char **argv, char *filename) -{ -#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 *gamefile = NULL; - - filename[0] = '\0'; - - if (argc > 1) { - if (BLI_exists(argv[argc-1])) { - BLI_strncpy(filename, argv[argc-1], FILE_MAX); - } - if (::strncmp(argv[argc-1], "-psn_", 5)==0) { - static char firstfilebuf[512]; - if (GHOST_HACK_getFirstFile(firstfilebuf)) { - BLI_strncpy(filename, firstfilebuf, FILE_MAX); - } - } - } - - srclen -= ::strlen("MacOS/blenderplayer"); - if (srclen > 0) { - len = srclen + ::strlen("Resources/game.blend"); - gamefile = new char [len + 1]; - ::strcpy(gamefile, argv[0]); - ::strcpy(gamefile + srclen, "Resources/game.blend"); - //::printf("looking for file: %s\n", filename); - - if (BLI_exists(gamefile)) - BLI_strncpy(filename, gamefile, FILE_MAX); - - delete [] gamefile; - } - -#else - filename[0] = '\0'; - - if (argc > 1) - BLI_strncpy(filename, argv[argc-1], FILE_MAX); -#endif // !_APPLE -} - -static BlendFileData *load_game_data(const char *progname, char *filename = NULL, char *relativename = NULL) -{ - ReportList reports; - BlendFileData *bfd = NULL; - - BKE_reports_init(&reports, RPT_STORE); - - /* try to load ourself, will only work if we are a runtime */ - if (BLO_is_a_runtime(progname)) { - bfd= BLO_read_runtime(progname, &reports); - if (bfd) { - bfd->type= BLENFILETYPE_RUNTIME; - BLI_strncpy(bfd->main->name, progname, sizeof(bfd->main->name)); - } - } else { - bfd= BLO_read_from_file(progname, &reports, BLO_READ_SKIP_NONE); - } - - if (!bfd && filename) { - bfd = load_game_data(filename); - if (!bfd) { - printf("Loading %s failed: ", filename); - BKE_reports_print(&reports, RPT_ERROR); - } - } - - BKE_reports_clear(&reports); - - return bfd; -} - -static bool GPG_NextFrame(GHOST_ISystem* system, GPG_Application *app, int &exitcode, STR_String &exitstring, GlobalSettings *gs) -{ - bool run = true; - system->processEvents(false); - system->dispatchEvents(); - app->EngineNextFrame(); - if ((exitcode = app->getExitRequested())) { - run = false; - exitstring = app->getExitString(); - *gs = *app->getGlobalSettings(); - } - return run; -} - -struct GPG_NextFrameState { - GHOST_ISystem* system; - GPG_Application *app; - GlobalSettings *gs; -} gpg_nextframestate; - -static int GPG_PyNextFrame(void *state0) -{ - GPG_NextFrameState *state = (GPG_NextFrameState *) state0; - int exitcode; - STR_String exitstring; - bool run = GPG_NextFrame(state->system, state->app, exitcode, exitstring, state->gs); - if (run) return 0; - else { - if (exitcode) - fprintf(stderr, "Exit code %d: %s\n", exitcode, exitstring.ReadPtr()); - return 1; - } -} - -int main( - int argc, -#ifdef WIN32 - char **UNUSED(argv_c) -#else - char **argv -#endif - ) -{ - int i; - int argc_py_clamped= argc; /* use this so python args can be added after ' - ' */ - bool error = false; - SYS_SystemHandle syshandle = SYS_GetSystem(); - bool fullScreen = false; - bool fullScreenParFound = false; - bool windowParFound = false; -#ifdef WIN32 - bool closeConsole = true; -#endif - RAS_IRasterizer::StereoMode stereomode = RAS_IRasterizer::RAS_STEREO_NOSTEREO; - bool stereoWindow = false; - bool stereoParFound = false; - int stereoFlag = STEREO_NOSTEREO; - int domeFov = -1; - int domeTilt = -200; - int domeMode = 0; - char* domeWarp = NULL; - Text *domeText = NULL; - int windowLeft = 100; - int windowTop = 100; - int windowWidth = 640; - int windowHeight = 480; - GHOST_TUns32 fullScreenWidth = 0; - GHOST_TUns32 fullScreenHeight= 0; - int fullScreenBpp = 32; - int fullScreenFrequency = 60; - GHOST_TEmbedderWindowID parentWindow = 0; - bool isBlenderPlayer = false; //true when lauching from blender or command line. false for bundled player - int validArguments=0; - bool samplesParFound = false; - GHOST_TUns16 aasamples = 0; - int alphaBackground = 0; - -#ifdef WIN32 - char **argv; - int argv_num; - - /* We delay loading of openmp so we can set the policy here. */ -# if defined(_MSC_VER) - _putenv_s("OMP_WAIT_POLICY", "PASSIVE"); -# endif - - /* FMA3 support in the 2013 CRT is broken on Vista and Windows 7 RTM (fixed in SP1). Just disable it. */ -# if defined(_MSC_VER) && defined(_M_X64) - _set_FMA3_enable(0); -# endif - - /* Win32 Unicode Args */ - /* NOTE: cannot use guardedalloc malloc here, as it's not yet initialized - * (it depends on the args passed in, which is what we're getting here!) - */ - { - wchar_t **argv_16 = CommandLineToArgvW(GetCommandLineW(), &argc); - argv = (char**)malloc(argc * sizeof(char *)); - for (argv_num = 0; argv_num < argc; argv_num++) { - argv[argv_num] = alloc_utf_8_from_16(argv_16[argv_num], 0); - } - LocalFree(argv_16); - } -#endif /* WIN32 */ - -#ifdef __linux__ -#ifdef __alpha__ - signal (SIGFPE, SIG_IGN); -#endif /* __alpha__ */ -#endif /* __linux__ */ - -#ifdef WITH_SDL_DYNLOAD - sdlewInit(); -#endif - - BKE_appdir_program_path_init(argv[0]); - BKE_tempdir_init(NULL); - - // We don't use threads directly in the BGE, but we need to call this so things like - // freeing up GPU_Textures works correctly. - BLI_threadapi_init(); - - DNA_sdna_current_init(); - - RNA_init(); - - init_nodesystem(); - - BKE_blender_globals_init(); - - // We load our own G.main, so free the one that BKE_blender_globals_init() gives us - BKE_main_free(G.main); - G.main = NULL; - - MEM_CacheLimiter_set_disabled(true); - IMB_init(); - BKE_images_init(); - BKE_modifier_init(); - DEG_register_node_types(); - -#ifdef WITH_FFMPEG - IMB_ffmpeg_init(); -#endif - - // Setup builtin font for BLF (mostly copied from creator.c, wm_init_exit.c and interface_style.c) - BLF_init(); - BLT_lang_init(); - BLT_lang_set(""); - - BLF_load_mem("default", (unsigned char*)datatoc_bfont_ttf, datatoc_bfont_ttf_size); - if (blf_mono_font == -1) - blf_mono_font = BLF_load_mem_unique("monospace", (unsigned char*)datatoc_bmonofont_ttf, datatoc_bmonofont_ttf_size); - - // Parse command line options -#if defined(DEBUG) - printf("argv[0] = '%s'\n", argv[0]); -#endif - -#ifdef WIN32 - if (scr_saver_init(argc, argv)) - { - switch (scr_saver_mode) - { - case SCREEN_SAVER_MODE_CONFIGURATION: - MessageBox(scr_saver_hwnd, "This screen saver has no options that you can set", "Screen Saver", MB_OK); - break; - case SCREEN_SAVER_MODE_PASSWORD: - /* This is W95 only, which we currently do not support. - * Fall-back to normal screen saver behavior in that case... */ - case SCREEN_SAVER_MODE_SAVER: - fullScreen = true; - fullScreenParFound = true; - break; - - case SCREEN_SAVER_MODE_PREVIEW: - /* This will actually be handled somewhere below... */ - break; - } - } -#endif - // XXX add the ability to change this values to the command line parsing. - U.mixbufsize = 2048; - U.audiodevice = 2; - U.audiorate = 44100; - U.audioformat = 0x24; - U.audiochannels = 2; - - // XXX this one too - U.anisotropic_filter = 2; - // enable fast mipmap generation - U.use_gpu_mipmap = 1; - - BKE_sound_init_once(); - - // Initialize a default material for meshes without materials. - init_def_material(); - - BKE_library_callback_free_window_manager_set(wm_free); - - /* if running blenderplayer the last argument can't be parsed since it has to be the filename. else it is bundled */ - isBlenderPlayer = !BLO_is_a_runtime(argv[0]); - if (isBlenderPlayer) - validArguments = argc - 1; - else - validArguments = argc; - - - /* Parsing command line arguments (can be set from WM_OT_blenderplayer_start) */ -#if defined(DEBUG) - printf("Parsing command line arguments...\n"); - printf("Num of arguments is: %i\n", validArguments-1); //-1 because i starts at 1 -#endif - - for (i = 1; (i < validArguments) && !error -#ifdef WIN32 - && scr_saver_mode == SCREEN_SAVER_MODE_NONE -#endif - ;) - - { -#if defined(DEBUG) - printf("argv[%d] = '%s'\n", i, argv[i]); -#endif - if (argv[i][0] == '-') - { - /* ignore all args after " - ", allow python to have own args */ - if (argv[i][1]=='\0') { - argc_py_clamped= i; - break; - } - - switch (argv[i][1]) - { - case 'g': //game engine options (show_framerate, fixedtime, etc) - { - i++; - if (i <= validArguments) - { - char* paramname = argv[i]; - // Check for single value versus assignment - if (i+1 <= validArguments && (*(argv[i+1]) == '=')) - { - i++; - if (i + 1 <= validArguments) - { - i++; - // Assignment - SYS_WriteCommandLineInt(syshandle, paramname, atoi(argv[i])); - SYS_WriteCommandLineFloat(syshandle, paramname, atof(argv[i])); - SYS_WriteCommandLineString(syshandle, paramname, argv[i]); -#if defined(DEBUG) - printf("%s = '%s'\n", paramname, argv[i]); -#endif - i++; - } - else - { - error = true; - printf("error: argument assignment %s without value.\n", paramname); - } - } - else - { -// SYS_WriteCommandLineInt(syshandle, argv[i++], 1); - } - } - break; - } - case 'd': //debug on - { - i++; - G.debug |= G_DEBUG; - MEM_set_memory_debug(); -#ifndef NDEBUG - BLI_mempool_set_memory_debug(); -#endif - break; - } - case 'f': //fullscreen mode - { - i++; - fullScreen = true; - fullScreenParFound = true; - if ((i + 2) <= validArguments && argv[i][0] != '-' && argv[i+1][0] != '-') - { - fullScreenWidth = atoi(argv[i++]); - fullScreenHeight = atoi(argv[i++]); - if ((i + 1) <= validArguments && argv[i][0] != '-') - { - fullScreenBpp = atoi(argv[i++]); - if ((i + 1) <= validArguments && argv[i][0] != '-') - fullScreenFrequency = atoi(argv[i++]); - } - } - else if ((i + 1) <= validArguments && argv[i][0] != '-' && argv[i+1][0] != '-') - { - error = true; - printf("error: to define fullscreen width or height, both options must be used.\n"); - } - break; - } - case 'w': //display in a window - { - i++; - fullScreen = false; - windowParFound = true; - - // Parse window position and size options - if ((i + 2) <= validArguments && argv[i][0] != '-' && argv[i+1][0] != '-') - { - windowWidth = atoi(argv[i++]); - windowHeight = atoi(argv[i++]); - - if ((i + 2) <= validArguments && argv[i][0] != '-' && argv[i+1][0] != '-') - { - windowLeft = atoi(argv[i++]); - windowTop = atoi(argv[i++]); - } - else if ((i + 1) <= validArguments && argv[i][0] != '-' && argv[i+1][0] != '-') - { - error = true; - printf("error: to define the window left or right coordinates, both options must be used.\n"); - } - } - else if ((i + 1) <= validArguments && argv[i][0] != '-' && argv[i+1][0] != '-') - { - error = true; - printf("error: to define the window's width or height, both options must be used.\n"); - } - break; - } - case 'h': //display help - { - usage(argv[0], isBlenderPlayer); - return 0; - break; - } - case 'i': //parent window ID - { - i++; - if ( (i + 1) <= validArguments ) - parentWindow = (GHOST_TEmbedderWindowID)atoll(argv[i++]); - else { - error = true; - printf("error: too few options for parent window argument.\n"); - } -#if defined(DEBUG) - printf("XWindows ID = %d\n", parentWindow); -#endif // defined(DEBUG) - break; - } - case 'm': //maximum anti-aliasing (eg. 2,4,8,16) - { - i++; - samplesParFound = true; - if ((i+1) <= validArguments ) - aasamples = atoi(argv[i++]); - else - { - error = true; - printf("error: No argument supplied for -m"); - } - break; - } - case 'c': //keep console (windows only) - { - i++; -#ifdef WIN32 - closeConsole = false; -#endif - break; - } - case 's': //stereo mode - { - i++; - if ((i + 1) <= validArguments) - { - stereoParFound = true; - stereoFlag = STEREO_ENABLED; - - if (!strcmp(argv[i], "nostereo")) // may not be redundant if the file has different setting - { - stereomode = RAS_IRasterizer::RAS_STEREO_NOSTEREO; - stereoFlag = STEREO_NOSTEREO; - } - - // only the hardware pageflip method needs a stereo window - else if (!strcmp(argv[i], "hwpageflip")) { - stereomode = RAS_IRasterizer::RAS_STEREO_QUADBUFFERED; - stereoWindow = true; - } - else if (!strcmp(argv[i], "syncdoubling")) - stereomode = RAS_IRasterizer::RAS_STEREO_ABOVEBELOW; - - else if (!strcmp(argv[i], "3dtvtopbottom")) - stereomode = RAS_IRasterizer::RAS_STEREO_3DTVTOPBOTTOM; - - else if (!strcmp(argv[i], "anaglyph")) - stereomode = RAS_IRasterizer::RAS_STEREO_ANAGLYPH; - - else if (!strcmp(argv[i], "sidebyside")) - stereomode = RAS_IRasterizer::RAS_STEREO_SIDEBYSIDE; - - else if (!strcmp(argv[i], "interlace")) - stereomode = RAS_IRasterizer::RAS_STEREO_INTERLACED; - - else if (!strcmp(argv[i], "vinterlace")) - stereomode = RAS_IRasterizer::RAS_STEREO_VINTERLACE; - -#if 0 -// // future stuff -// else if (!strcmp(argv[i], "stencil") -// stereomode = RAS_STEREO_STENCIL; -#endif - else - { - error = true; - printf("error: stereomode '%s' unrecognized.\n", argv[i]); - } - - i++; - } - else - { - error = true; - printf("error: too few options for stereo argument.\n"); - } - break; - } - case 'D': //dome mode - { - stereoFlag = STEREO_DOME; - stereomode = RAS_IRasterizer::RAS_STEREO_DOME; - i++; - if ((i + 1) <= validArguments) - { - if (!strcmp(argv[i], "angle")) { - i++; - domeFov = atoi(argv[i++]); - } - if (!strcmp(argv[i], "tilt")) { - i++; - domeTilt = atoi(argv[i++]); - } - if (!strcmp(argv[i], "warpdata")) { - i++; - domeWarp = argv[i++]; - } - if (!strcmp(argv[i], "mode")) { - i++; - if (!strcmp(argv[i], "fisheye")) - domeMode = DOME_FISHEYE; - - else if (!strcmp(argv[i], "truncatedfront")) - domeMode = DOME_TRUNCATED_FRONT; - - else if (!strcmp(argv[i], "truncatedrear")) - domeMode = DOME_TRUNCATED_REAR; - - else if (!strcmp(argv[i], "cubemap")) - domeMode = DOME_ENVMAP; - - else if (!strcmp(argv[i], "sphericalpanoramic")) - domeMode = DOME_PANORAM_SPH; - - else - printf("error: %s is not a valid dome mode.\n", argv[i]); - } - i++; - } - break; - } - case 'a': // allow window to blend with display background - { - i++; - alphaBackground = 1; - break; - } - default: //not recognized - { - printf("Unknown argument: %s\n", argv[i++]); - break; - } - } - } - else - { - i++; - } - } - - if ((windowWidth < kMinWindowWidth) || (windowHeight < kMinWindowHeight)) - { - error = true; - printf("error: window size too small.\n"); - } - - if (error ) - { - usage(argv[0], isBlenderPlayer); - return 0; - } - -#ifdef WIN32 - if (scr_saver_mode != SCREEN_SAVER_MODE_CONFIGURATION) -#endif - { - // Create the system - if (GHOST_ISystem::createSystem() == GHOST_kSuccess) { - GHOST_ISystem* system = GHOST_ISystem::getSystem(); - assertd(system); - - if (!fullScreenWidth || !fullScreenHeight) - system->getMainDisplayDimensions(fullScreenWidth, fullScreenHeight); - // process first batch of events. If the user - // drops a file on top off the blenderplayer icon, we - // receive 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); - bool firstTimeRunning = true; - char filename[FILE_MAX]; - char pathname[FILE_MAX]; - char *titlename; - - get_filename(argc_py_clamped, argv, filename); - if (filename[0]) - BLI_path_cwd(filename, sizeof(filename)); - - - // fill the GlobalSettings with the first scene files - // those may change during the game and persist after using Game Actuator - GlobalSettings gs; - - do { - // Read the Blender file - 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[FILE_MAX]; - - // base the actuator filename relative to the last file - BLI_strncpy(basedpath, exitstring.Ptr(), sizeof(basedpath)); - BLI_path_abs(basedpath, pathname); - - bfd = load_game_data(basedpath); - - if (!bfd) { - // just add "//" in front of it - char temppath[FILE_MAX] = "//"; - BLI_strncpy(temppath + 2, basedpath, FILE_MAX - 2); - - BLI_path_abs(temppath, pathname); - bfd = load_game_data(temppath); - } - } - else { - bfd = load_game_data(BKE_appdir_program_path(), filename[0]? filename: NULL); - } - -#if defined(DEBUG) - printf("Game data loaded from %s\n", filename); -#endif - - if (!bfd) { - usage(argv[0], isBlenderPlayer); - error = true; - exitcode = KX_EXIT_REQUEST_QUIT_GAME; - } - else { - /* Setting options according to the blend file if not overriden in the command line */ -#ifdef WIN32 -#if !defined(DEBUG) - if (closeConsole) { - system->toggleConsole(0); // Close a console window - } -#endif // !defined(DEBUG) -#endif // WIN32 - Main *maggie = bfd->main; - Scene *scene = bfd->curscene; - G.main = maggie; - - if (firstTimeRunning) { - G.fileflags = bfd->fileflags; - - gs.matmode= scene->gm.matmode; - gs.glslflag= scene->gm.flag; - } - - //Seg Fault; icon.c gIcons == 0 - BKE_icons_init(1); - - 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->gm.playerflag & GAME_PLAYER_FULLSCREEN)) { - //printf("fullscreen option found in Blender file\n"); - fullScreen = true; - fullScreenWidth= scene->gm.xplay; - fullScreenHeight= scene->gm.yplay; - fullScreenFrequency= scene->gm.freqplay; - fullScreenBpp = scene->gm.depth; - } - else - { - fullScreen = false; - windowWidth = scene->gm.xplay; - windowHeight = scene->gm.yplay; - } - } - - - // Check whether the game should be displayed in stereo (dome included) - if (!stereoParFound) { - // Only use file settings when command line did not override - if (scene->gm.stereoflag == STEREO_ENABLED) { - stereomode = (RAS_IRasterizer::StereoMode) scene->gm.stereomode; - if (stereomode == RAS_IRasterizer::RAS_STEREO_QUADBUFFERED) - stereoWindow = true; - } - } - else { - scene->gm.stereoflag = STEREO_ENABLED; - } - - if (!samplesParFound) - aasamples = scene->gm.aasamples; - - // Dome specific settings - if (stereoFlag == STEREO_DOME) { - stereomode = RAS_IRasterizer::RAS_STEREO_DOME; - scene->gm.stereoflag = STEREO_DOME; - if (domeFov > 89) - scene->gm.dome.angle = domeFov; - if (domeTilt > -180) - scene->gm.dome.tilt = domeTilt; - if (domeMode > 0) - scene->gm.dome.mode = domeMode; - if (domeWarp) { - //XXX to do: convert relative to absolute path - domeText= BKE_text_load(G.main, domeWarp, ""); - if (!domeText) - printf("error: invalid warpdata text file - %s\n", domeWarp); - else - scene->gm.dome.warptext = domeText; - } - } - - // GPG_Application app (system, maggie, startscenename); - app.SetGameEngineData(maggie, scene, &gs, argc, argv); /* this argc cant be argc_py_clamped, since python uses it */ - BLI_strncpy(pathname, maggie->name, sizeof(pathname)); - if (G.main != maggie) { - BLI_strncpy(G.main->name, maggie->name, sizeof(G.main->name)); - } -#ifdef WITH_PYTHON - setGamePythonPath(G.main->name); -#endif - if (firstTimeRunning) { - firstTimeRunning = false; - - if (fullScreen) { -#ifdef WIN32 - if (scr_saver_mode == SCREEN_SAVER_MODE_SAVER) - { - app.startScreenSaverFullScreen(fullScreenWidth, fullScreenHeight, fullScreenBpp, fullScreenFrequency, - stereoWindow, stereomode, aasamples); - } - else -#endif - { - app.startFullScreen(fullScreenWidth, fullScreenHeight, fullScreenBpp, fullScreenFrequency, - stereoWindow, stereomode, alphaBackground, aasamples, (scene->gm.playerflag & GAME_PLAYER_DESKTOP_RESOLUTION)); - } - } - 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"; - } -#ifdef WIN32 - if (scr_saver_mode == SCREEN_SAVER_MODE_PREVIEW) - { - app.startScreenSaverPreview(scr_saver_hwnd, stereoWindow, stereomode, aasamples); - } - else -#endif - { - if (parentWindow != 0) - app.startEmbeddedWindow(title, parentWindow, stereoWindow, stereomode, aasamples); - else - app.startWindow(title, windowLeft, windowTop, windowWidth, windowHeight, - stereoWindow, stereomode, alphaBackground, aasamples); - - if (SYS_GetCommandLineInt(syshandle, "nomipmap", 0)) { - GPU_set_mipmap(0); - } - - GPU_set_anisotropic(U.anisotropic_filter); - GPU_set_gpu_mipmapping(U.use_gpu_mipmap); - } - } - } - 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; - char *python_main = NULL; - pynextframestate.state = NULL; - pynextframestate.func = NULL; -#ifdef WITH_PYTHON - python_main = KX_GetPythonMain(scene); -#endif // WITH_PYTHON - if (python_main) { - char *python_code = KX_GetPythonCode(maggie, python_main); - if (python_code) { -#ifdef WITH_PYTHON - // Set python environement variable. - KX_Scene *startscene = app.GetStartScene(); - KX_SetActiveScene(startscene); - PHY_SetActiveEnvironment(startscene->GetPhysicsEnvironment()); - - gpg_nextframestate.system = system; - gpg_nextframestate.app = &app; - gpg_nextframestate.gs = &gs; - pynextframestate.state = &gpg_nextframestate; - pynextframestate.func = &GPG_PyNextFrame; - - printf("Yielding control to Python script '%s'...\n", python_main); - PyRun_SimpleString(python_code); - printf("Exit Python script '%s'\n", python_main); -#endif // WITH_PYTHON - MEM_freeN(python_code); - } - else { - fprintf(stderr, "ERROR: cannot yield control to Python: no Python text data-block named '%s'\n", python_main); - } - } - else { - while (run) { - run = GPG_NextFrame(system, &app, exitcode, exitstring, &gs); - } - } - app.StopGameEngine(); - - /* 'app' is freed automatic when out of scope. - * removal is needed else the system will free an already freed value */ - system->removeEventConsumer(&app); - - BLO_blendfiledata_free(bfd); - /* G.main == bfd->main, it gets referenced in free_nodesystem so we can't have a dangling pointer */ - G.main = NULL; - if (python_main) MEM_freeN(python_main); - } - } while (exitcode == KX_EXIT_REQUEST_RESTART_GAME || exitcode == KX_EXIT_REQUEST_START_OTHER_GAME); - } - - // Seg Fault; icon.c gIcons == 0 - BKE_icons_free(); - - // Dispose the system - GHOST_ISystem::disposeSystem(); - } - else { - error = true; - printf("error: couldn't create a system.\n"); - } - } - - /* refer to WM_exit_ext() and BKE_blender_free(), - * these are not called in the player but we need to match some of there behavior here, - * if the order of function calls or blenders state isn't matching that of blender proper, - * we may get troubles later on */ - - free_nodesystem(); - - // Cleanup - RNA_exit(); - BLF_exit(); - -#ifdef WITH_INTERNATIONAL - BLF_free_unifont(); - BLF_free_unifont_mono(); - BLT_lang_free(); -#endif - - IMB_exit(); - BKE_images_exit(); - DEG_free_node_types(); - IMB_moviecache_destruct(); - - SYS_DeleteSystem(syshandle); - - int totblock= MEM_get_memory_blocks_in_use(); - if (totblock!=0) { - printf("Error Totblock: %d\n",totblock); - MEM_set_error_callback(mem_error_cb); - MEM_printmemlist(); - } - - BKE_tempdir_session_purge(); - -#ifdef WIN32 - while (argv_num) { - free(argv[--argv_num]); - } - free(argv); - argv = NULL; -#endif - - return error ? -1 : 0; -} |