diff options
author | Hans Lambermont <hans@lambermont.dyndns.org> | 2002-10-12 15:37:38 +0400 |
---|---|---|
committer | Hans Lambermont <hans@lambermont.dyndns.org> | 2002-10-12 15:37:38 +0400 |
commit | 12315f4d0e0ae993805f141f64cb8c73c5297311 (patch) | |
tree | 59b45827cd8293cfb727758989c7a74b40183974 /source/gameengine/GamePlayer/common/windows |
Initial revisionv2.25
Diffstat (limited to 'source/gameengine/GamePlayer/common/windows')
9 files changed, 1033 insertions, 0 deletions
diff --git a/source/gameengine/GamePlayer/common/windows/GPW_Canvas.cpp b/source/gameengine/GamePlayer/common/windows/GPW_Canvas.cpp new file mode 100644 index 00000000000..de3f49e867e --- /dev/null +++ b/source/gameengine/GamePlayer/common/windows/GPW_Canvas.cpp @@ -0,0 +1,174 @@ +/** + * $Id$ + * + * ***** BEGIN GPL/BL DUAL LICENSE BLOCK ***** + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. The Blender + * Foundation also sells licenses for use in proprietary software under + * the Blender License. See http://www.blender.org/BL/ for information + * about this. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * + * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV. + * All rights reserved. + * + * The Original Code is: all of this file. + * + * Contributor(s): none yet. + * + * ***** END GPL/BL DUAL LICENSE BLOCK ***** + */ + +#include "GPW_Canvas.h" + +GPW_Canvas::GPW_Canvas(HWND hWnd, HDC hDC, int width, int height) + : GPC_Canvas(width, height), m_hWnd(hWnd), m_hRC(0), m_hDC(hDC) +{ +} + + +GPW_Canvas::~GPW_Canvas() +{ + if (m_hRC) { + ::wglDeleteContext(m_hRC); + } + //if (m_hDC) { + // ::ReleaseDC(m_hWnd, m_hDC); + //} +} + + +void GPW_Canvas::Init() +{ + +// log_entry("GPW_Canvas::Init"); + + /* + * Color and depth bit values are not to be trusted. + * For instance, on TNT2: + * When the screen color depth is set to 16 bit, we get 5 color bits + * and 16 depth bits. + * When the screen color depth is set to 32 bit, we get 8 color bits + * and 24 depth bits. + * Just to be safe, we request high quality settings. + */ + PIXELFORMATDESCRIPTOR pfd = + { + sizeof(PIXELFORMATDESCRIPTOR), // iSize + 1, // iVersion + PFD_DRAW_TO_WINDOW | + PFD_SUPPORT_OPENGL | +// PFD_STEREO | + PFD_DOUBLEBUFFER, // dwFlags + PFD_TYPE_RGBA, // iPixelType + 32, // cColorBits + 0, 0, // cRedBits, cRedShift (ignored) + 0, 0, // cGreenBits, cGreenShift (ignored) + 0, 0, // cBlueBits, cBlueShift (ignored) + 0, 0, // cAlphaBits, cAlphaShift (ignored) + 0, 0, 0, 0, 0, // cAccum_X_Bits + 32, // cDepthBits + 0, // cStencilBits + 0, // cAuxBuffers + PFD_MAIN_PLANE, // iLayerType + 0, // bReserved + 0, // dwLayerMask + 0, // dwVisibleMask + 0 // dwDamageMask + }; + PIXELFORMATDESCRIPTOR match; + + // Look what we get back for this pixel format + int pixelFormat = ::ChoosePixelFormat(m_hDC, &pfd); + if (!pixelFormat) { + DWORD error = ::GetLastError(); + } + ::DescribePixelFormat(m_hDC, pixelFormat, sizeof(match), &match); + + // Activate the pixel format for this context + ::SetPixelFormat(m_hDC, ::ChoosePixelFormat(m_hDC, &match), &match); + + // Create the OpenGL context and make it current + m_hRC = ::wglCreateContext(m_hDC); + ::wglMakeCurrent(m_hDC, m_hRC); + +} + +void GPW_Canvas::SetMousePosition(int x, int y) +{ + POINT point = { x, y }; + if (m_hWnd) + { + ::ClientToScreen(m_hWnd, &point); + ::SetCursorPos(point.x, point.y); + } +} + + +void GPW_Canvas::SetMouseState(RAS_MouseState mousestate) +{ + LPCSTR id; + switch (mousestate) + { + case MOUSE_INVISIBLE: + HideCursor(); + break; + case MOUSE_WAIT: + ::SetCursor(::LoadCursor(0, IDC_WAIT)); + ShowCursor(); + break; + case MOUSE_NORMAL: + ::SetCursor(::LoadCursor(0, IDC_ARROW)); + ShowCursor(); + break; + } +} + + +bool GPW_Canvas::BeginDraw(void) +{ + ::wglMakeCurrent(m_hDC, m_hRC); + // check errors, anyone? + return true; +} + + +void GPW_Canvas::EndDraw(void) +{ + ::wglMakeCurrent(NULL, NULL); +} + +void GPW_Canvas::SwapBuffers(void) +{ + if (m_hDC) { + ::SwapBuffers(m_hDC); + } +} + + +void GPW_Canvas::HideCursor(void) +{ + int count = ::ShowCursor(FALSE); + while (count >= 0) + { + count = ::ShowCursor(FALSE); + } +} + + +void GPW_Canvas::ShowCursor(void) +{ + ::ShowCursor(TRUE); +} + diff --git a/source/gameengine/GamePlayer/common/windows/GPW_Canvas.h b/source/gameengine/GamePlayer/common/windows/GPW_Canvas.h new file mode 100644 index 00000000000..59e3eef5b10 --- /dev/null +++ b/source/gameengine/GamePlayer/common/windows/GPW_Canvas.h @@ -0,0 +1,119 @@ +/** + * $Id$ + * + * ***** BEGIN GPL/BL DUAL LICENSE BLOCK ***** + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. The Blender + * Foundation also sells licenses for use in proprietary software under + * the Blender License. See http://www.blender.org/BL/ for information + * about this. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * + * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV. + * All rights reserved. + * + * The Original Code is: all of this file. + * + * Contributor(s): none yet. + * + * ***** END GPL/BL DUAL LICENSE BLOCK ***** + */ + +#ifndef _GPW_CANVAS_H_ +#define _GPW_CANVAS_H_ + +#ifdef WIN32 +#pragma warning (disable:4786) // suppress stl-MSVC debug info warning +#endif + +#include <iostream> +#include <windows.h> +#include <gl/gl.h> + +#include "GPC_Canvas.h" + + +class GPW_Canvas : public GPC_Canvas +{ +protected: + /** The window handle. */ + HWND m_hWnd; + /** Rendering context. */ + HGLRC m_hRC; + /** Device Context. */ + HDC m_hDC; + +public: + /** + * Constructor. + */ + GPW_Canvas(HWND hWnd, HDC hDC, int width, int height); + + /** + * Destructor. + */ + virtual ~GPW_Canvas(void); + + virtual void Init(void); + + /** + * Moves the cursor to a new location. + * @param x The x-coordinate of the new location. + * @param x The y-coordinate of the new location. + */ + virtual void SetMousePosition(int x, int y); + + /** + * Sets the cursor shape and/or visibility. + * @param mousestate The new state ofthe cursor. + */ + virtual void SetMouseState(RAS_MouseState mousestate); + + bool BeginDraw(void); + void EndDraw(void); + + virtual void SwapBuffers(void); + + virtual HDC GetHDC(void) + { + return m_hDC; + } + + virtual void SetHDC(HDC hDC) + { + if (hDC != m_hDC) { + m_hDC = hDC; + } + } + + virtual HGLRC GetHGLRC(void) + { + return m_hRC; + } + +protected: + /** + * Hides the mouse cursor. + */ + void HideCursor(void); + + /** + * Shows the mouse cursor. + */ + void ShowCursor(void); +}; + + + +#endif // _GPW_CANVAS_H_ diff --git a/source/gameengine/GamePlayer/common/windows/GPW_Engine.cpp b/source/gameengine/GamePlayer/common/windows/GPW_Engine.cpp new file mode 100644 index 00000000000..ff4dca9c50e --- /dev/null +++ b/source/gameengine/GamePlayer/common/windows/GPW_Engine.cpp @@ -0,0 +1,120 @@ +/** + * $Id$ + * + * ***** BEGIN GPL/BL DUAL LICENSE BLOCK ***** + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. The Blender + * Foundation also sells licenses for use in proprietary software under + * the Blender License. See http://www.blender.org/BL/ for information + * about this. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * + * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV. + * All rights reserved. + * + * The Original Code is: all of this file. + * + * Contributor(s): none yet. + * + * ***** END GPL/BL DUAL LICENSE BLOCK ***** + */ + +#pragma warning (disable : 4786) + +#include <assert.h> + +#include "GPC_MouseDevice.h" +#include "GPC_RenderTools.h" +#include "GPC_RawImage.h" + +#include "GPW_Canvas.h" +#include "GPW_Engine.h" +#include "GPW_KeyboardDevice.h" +#include "GPW_System.h" + +#include "SND_DeviceManager.h" + +#include "NG_NetworkScene.h" +#include "NG_LoopBackNetworkDeviceInterface.h" + + +GPW_Engine::GPW_Engine(char *customLoadingAnimationURL, + int foregroundColor, int backgroundColor, int frameRate) : + GPC_Engine(customLoadingAnimationURL, foregroundColor, backgroundColor, + frameRate) +{ +} + + +GPW_Engine::~GPW_Engine() +{ +} + + +bool GPW_Engine::Initialize(HDC hdc, int width, int height) +{ + SND_DeviceManager::Subscribe(); + m_audiodevice = SND_DeviceManager::Instance(); + + m_keyboarddev = new GPW_KeyboardDevice(); + m_mousedev = new GPC_MouseDevice(); + + // constructor only initializes data + m_canvas = new GPW_Canvas(0, hdc, width, height); + m_canvas->Init(); // create the actual visual and rendering context + + // put the Blender logo in the topleft corner + if(m_BlenderLogo != 0) + // adding a banner automatically enables them + m_BlenderLogoId = m_canvas->AddBanner(m_BlenderLogo->Width(), m_BlenderLogo->Height(), + m_BlenderLogo->Width(), m_BlenderLogo->Height(), + m_BlenderLogo->Data(), GPC_Canvas::alignTopLeft); + + // put the Blender3D logo in the bottom right corner + if(m_Blender3DLogo != 0) + // adding a banner automatically enables them + m_Blender3DLogoId = m_canvas->AddBanner(m_Blender3DLogo->Width(), m_Blender3DLogo->Height(), + m_Blender3DLogo->Width(), m_Blender3DLogo->Height(), + m_Blender3DLogo->Data(), GPC_Canvas::alignBottomRight); +#if 0 + // put the NaN logo in the bottom right corner + if(m_NaNLogo != 0) + // adding a banner automatically enables them + m_NaNLogoId = m_canvas->AddBanner(m_NaNLogo->Width(), m_NaNLogo->Height(), + m_NaNLogo->Width(), m_NaNLogo->Height(), + m_NaNLogo->Data(), GPC_Canvas::alignBottomRight); +#endif + // enable the display of all banners + m_canvas->SetBannerDisplayEnabled(true); + + // stuff that must be done after creation of a rendering context + //m_canvas->InitPostRenderingContext(); + + m_rendertools = new GPC_RenderTools(); + + m_networkdev = new NG_LoopBackNetworkDeviceInterface(); + assert(m_networkdev); + + // creation of system needs 'current rendering context', this is taken care + // of by the GPW_Canvas + m_system = new GPW_System(); + +// m_system->SetKeyboardDevice((GPW_KeyboardDevice *)m_keyboarddev); +// m_system->SetMouseDevice(m_mousedev); +// m_system->SetNetworkDevice(m_networkdev); + + m_initialized = true; + + return m_initialized; +} diff --git a/source/gameengine/GamePlayer/common/windows/GPW_Engine.h b/source/gameengine/GamePlayer/common/windows/GPW_Engine.h new file mode 100644 index 00000000000..7fcd6413e1e --- /dev/null +++ b/source/gameengine/GamePlayer/common/windows/GPW_Engine.h @@ -0,0 +1,50 @@ +/** + * $Id$ + * + * ***** BEGIN GPL/BL DUAL LICENSE BLOCK ***** + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. The Blender + * Foundation also sells licenses for use in proprietary software under + * the Blender License. See http://www.blender.org/BL/ for information + * about this. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * + * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV. + * All rights reserved. + * + * The Original Code is: all of this file. + * + * Contributor(s): none yet. + * + * ***** END GPL/BL DUAL LICENSE BLOCK ***** + */ + +#ifndef __GPW_ENGINE_H +#define __GPW_ENGINE_H + + +#include "GPC_Engine.h" + + +class GPW_Engine : public GPC_Engine +{ +public: + GPW_Engine(char *customLoadingAnimation, + int foregroundColor, int backgroundColor, int frameRate); + virtual ~GPW_Engine(); + bool Initialize(HDC hdc, int width, int height); +}; + + +#endif // __GPW_ENGINE_H diff --git a/source/gameengine/GamePlayer/common/windows/GPW_KeyboardDevice.cpp b/source/gameengine/GamePlayer/common/windows/GPW_KeyboardDevice.cpp new file mode 100644 index 00000000000..b9c884af525 --- /dev/null +++ b/source/gameengine/GamePlayer/common/windows/GPW_KeyboardDevice.cpp @@ -0,0 +1,280 @@ +/** + * $Id$ + * + * ***** BEGIN GPL/BL DUAL LICENSE BLOCK ***** + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. The Blender + * Foundation also sells licenses for use in proprietary software under + * the Blender License. See http://www.blender.org/BL/ for information + * about this. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * + * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV. + * All rights reserved. + * + * The Original Code is: all of this file. + * + * Contributor(s): none yet. + * + * ***** END GPL/BL DUAL LICENSE BLOCK ***** + */ + +#include "GPW_KeyboardDevice.h" + + +// Key code values not found in winuser.h +#ifndef VK_MINUS +#define VK_MINUS 0xBD +#endif // VK_MINUS +#ifndef VK_SEMICOLON +#define VK_SEMICOLON 0xBA +#endif // VK_SEMICOLON +#ifndef VK_PERIOD +#define VK_PERIOD 0xBE +#endif // VK_PERIOD +#ifndef VK_COMMA +#define VK_COMMA 0xBC +#endif // VK_COMMA +#ifndef VK_QUOTE +#define VK_QUOTE 0xDE +#endif // VK_QUOTE +#ifndef VK_BACK_QUOTE +#define VK_BACK_QUOTE 0xC0 +#endif // VK_BACK_QUOTE +#ifndef VK_SLASH +#define VK_SLASH 0xBF +#endif // VK_SLASH +#ifndef VK_BACK_SLASH +#define VK_BACK_SLASH 0xDC +#endif // VK_BACK_SLASH +#ifndef VK_EQUALS +#define VK_EQUALS 0xBB +#endif // VK_EQUALS +#ifndef VK_OPEN_BRACKET +#define VK_OPEN_BRACKET 0xDB +#endif // VK_OPEN_BRACKET +#ifndef VK_CLOSE_BRACKET +#define VK_CLOSE_BRACKET 0xDD +#endif // VK_CLOSE_BRACKET + + + +GPW_KeyboardDevice::GPW_KeyboardDevice(void) +{ + m_seperateLeftRight = false; + m_seperateLeftRightInitialized = false; + + m_reverseKeyTranslateTable['A' ] = KX_AKEY ; + m_reverseKeyTranslateTable['B' ] = KX_BKEY ; + m_reverseKeyTranslateTable['C' ] = KX_CKEY ; + m_reverseKeyTranslateTable['D' ] = KX_DKEY ; + m_reverseKeyTranslateTable['E' ] = KX_EKEY ; + m_reverseKeyTranslateTable['F' ] = KX_FKEY ; + m_reverseKeyTranslateTable['G' ] = KX_GKEY ; + m_reverseKeyTranslateTable['H' ] = KX_HKEY ; + m_reverseKeyTranslateTable['I' ] = KX_IKEY ; + m_reverseKeyTranslateTable['J' ] = KX_JKEY ; + m_reverseKeyTranslateTable['K' ] = KX_KKEY ; + m_reverseKeyTranslateTable['L' ] = KX_LKEY ; + m_reverseKeyTranslateTable['M' ] = KX_MKEY ; + m_reverseKeyTranslateTable['N' ] = KX_NKEY ; + m_reverseKeyTranslateTable['O' ] = KX_OKEY ; + m_reverseKeyTranslateTable['P' ] = KX_PKEY ; + m_reverseKeyTranslateTable['Q' ] = KX_QKEY ; + m_reverseKeyTranslateTable['R' ] = KX_RKEY ; + m_reverseKeyTranslateTable['S' ] = KX_SKEY ; + m_reverseKeyTranslateTable['T' ] = KX_TKEY ; + m_reverseKeyTranslateTable['U' ] = KX_UKEY ; + m_reverseKeyTranslateTable['V' ] = KX_VKEY ; + m_reverseKeyTranslateTable['W' ] = KX_WKEY ; + m_reverseKeyTranslateTable['X' ] = KX_XKEY ; + m_reverseKeyTranslateTable['Y' ] = KX_YKEY ; + m_reverseKeyTranslateTable['Z' ] = KX_ZKEY ; + + m_reverseKeyTranslateTable['0' ] = KX_ZEROKEY ; + m_reverseKeyTranslateTable['1' ] = KX_ONEKEY ; + m_reverseKeyTranslateTable['2' ] = KX_TWOKEY ; + m_reverseKeyTranslateTable['3' ] = KX_THREEKEY ; + m_reverseKeyTranslateTable['4' ] = KX_FOURKEY ; + m_reverseKeyTranslateTable['5' ] = KX_FIVEKEY ; + m_reverseKeyTranslateTable['6' ] = KX_SIXKEY ; + m_reverseKeyTranslateTable['7' ] = KX_SEVENKEY ; + m_reverseKeyTranslateTable['8' ] = KX_EIGHTKEY ; + m_reverseKeyTranslateTable['9' ] = KX_NINEKEY ; + + // Middle keyboard area keys + m_reverseKeyTranslateTable[VK_PAUSE ] = KX_PAUSEKEY ; + m_reverseKeyTranslateTable[VK_INSERT ] = KX_INSERTKEY ; + m_reverseKeyTranslateTable[VK_DELETE ] = KX_DELKEY ; + m_reverseKeyTranslateTable[VK_HOME ] = KX_HOMEKEY ; + m_reverseKeyTranslateTable[VK_END ] = KX_ENDKEY ; + m_reverseKeyTranslateTable[VK_PRIOR ] = KX_PAGEUPKEY ; + m_reverseKeyTranslateTable[VK_NEXT ] = KX_PAGEDOWNKEY ; + + // Arrow keys + m_reverseKeyTranslateTable[VK_UP ] = KX_UPARROWKEY ; + m_reverseKeyTranslateTable[VK_DOWN ] = KX_DOWNARROWKEY ; + m_reverseKeyTranslateTable[VK_LEFT ] = KX_LEFTARROWKEY ; + m_reverseKeyTranslateTable[VK_RIGHT ] = KX_RIGHTARROWKEY ; + + // Function keys + m_reverseKeyTranslateTable[VK_F1 ] = KX_F1KEY ; + m_reverseKeyTranslateTable[VK_F2 ] = KX_F2KEY ; + m_reverseKeyTranslateTable[VK_F3 ] = KX_F3KEY ; + m_reverseKeyTranslateTable[VK_F4 ] = KX_F4KEY ; + m_reverseKeyTranslateTable[VK_F5 ] = KX_F5KEY ; + m_reverseKeyTranslateTable[VK_F6 ] = KX_F6KEY ; + m_reverseKeyTranslateTable[VK_F7 ] = KX_F7KEY ; + m_reverseKeyTranslateTable[VK_F8 ] = KX_F8KEY ; + m_reverseKeyTranslateTable[VK_F9 ] = KX_F9KEY ; + m_reverseKeyTranslateTable[VK_F10 ] = KX_F10KEY ; + m_reverseKeyTranslateTable[VK_F11 ] = KX_F11KEY ; + m_reverseKeyTranslateTable[VK_F12 ] = KX_F12KEY ; + + // Numpad keys + m_reverseKeyTranslateTable[VK_NUMPAD0 ] = KX_PAD0 ; + m_reverseKeyTranslateTable[VK_NUMPAD1 ] = KX_PAD1 ; + m_reverseKeyTranslateTable[VK_NUMPAD2 ] = KX_PAD2 ; + m_reverseKeyTranslateTable[VK_NUMPAD3 ] = KX_PAD3 ; + m_reverseKeyTranslateTable[VK_NUMPAD4 ] = KX_PAD4 ; + m_reverseKeyTranslateTable[VK_NUMPAD5 ] = KX_PAD5 ; + m_reverseKeyTranslateTable[VK_NUMPAD6 ] = KX_PAD6 ; + m_reverseKeyTranslateTable[VK_NUMPAD7 ] = KX_PAD7 ; + m_reverseKeyTranslateTable[VK_NUMPAD8 ] = KX_PAD8 ; + m_reverseKeyTranslateTable[VK_NUMPAD9 ] = KX_PAD9 ; + m_reverseKeyTranslateTable[VK_MULTIPLY ] = KX_PADASTERKEY ; + m_reverseKeyTranslateTable[VK_ADD ] = KX_PADPLUSKEY ; + m_reverseKeyTranslateTable[VK_DECIMAL ] = KX_PADPERIOD ; + m_reverseKeyTranslateTable[VK_SUBTRACT ] = KX_PADMINUS ; + m_reverseKeyTranslateTable[VK_DIVIDE ] = KX_PADSLASHKEY ; + m_reverseKeyTranslateTable[VK_SEPARATOR ] = KX_PADENTER ; + + // Other keys + m_reverseKeyTranslateTable[VK_CAPITAL ] = KX_CAPSLOCKKEY ; + m_reverseKeyTranslateTable[VK_ESCAPE ] = KX_ESCKEY ; + m_reverseKeyTranslateTable[VK_TAB ] = KX_TABKEY ; + //m_reverseKeyTranslateTable[VK_RETURN ] = KX_RETKEY ; + m_reverseKeyTranslateTable[VK_SPACE ] = KX_SPACEKEY ; + m_reverseKeyTranslateTable[VK_RETURN ] = KX_LINEFEEDKEY ; + m_reverseKeyTranslateTable[VK_BACK ] = KX_BACKSPACEKEY ; + m_reverseKeyTranslateTable[VK_SEMICOLON ] = KX_SEMICOLONKEY ; + m_reverseKeyTranslateTable[VK_PERIOD ] = KX_PERIODKEY ; + m_reverseKeyTranslateTable[VK_COMMA ] = KX_COMMAKEY ; + m_reverseKeyTranslateTable[VK_QUOTE ] = KX_QUOTEKEY ; + m_reverseKeyTranslateTable[VK_BACK_QUOTE ] = KX_ACCENTGRAVEKEY ; + m_reverseKeyTranslateTable[VK_MINUS ] = KX_MINUSKEY ; + m_reverseKeyTranslateTable[VK_SLASH ] = KX_SLASHKEY ; + m_reverseKeyTranslateTable[VK_BACK_SLASH ] = KX_BACKSLASHKEY ; + m_reverseKeyTranslateTable[VK_EQUALS ] = KX_EQUALKEY ; + m_reverseKeyTranslateTable[VK_OPEN_BRACKET ] = KX_LEFTBRACKETKEY ; + m_reverseKeyTranslateTable[VK_CLOSE_BRACKET ] = KX_RIGHTBRACKETKEY ; + + /* + * Need to handle Ctrl, Alt and Shift keys differently. + * Win32 messages do not discriminate left and right keys. + */ + m_reverseKeyTranslateTable[VK_LCONTROL ] = KX_LEFTCTRLKEY ; + m_reverseKeyTranslateTable[VK_RCONTROL ] = KX_RIGHTCTRLKEY ; + m_reverseKeyTranslateTable[VK_LMENU ] = KX_LEFTALTKEY ; + m_reverseKeyTranslateTable[VK_RMENU ] = KX_RIGHTALTKEY ; + m_reverseKeyTranslateTable[VK_RSHIFT ] = KX_RIGHTSHIFTKEY ; + m_reverseKeyTranslateTable[VK_LSHIFT ] = KX_LEFTSHIFTKEY ; +} + + +GPW_KeyboardDevice::~GPW_KeyboardDevice(void) +{ +} + + +void GPW_KeyboardDevice::ConvertWinEvent(WPARAM wParam, bool isDown) +{ + if ((wParam == VK_SHIFT) || (wParam == VK_MENU) || (wParam == VK_CONTROL)) { + ConvertModifierKey(wParam, isDown); + } + else { + ConvertEvent(wParam, isDown); + } +} + + +void GPW_KeyboardDevice::ConvertModifierKey(WPARAM wParam, bool isDown) +{ + /* + GetKeyState and GetAsyncKeyState only work with Win95, Win98, NT4, + Terminal Server and Windows 2000. + But on WinME it always returns zero. These two functions are simply + skipped by Millenium Edition! + + Official explanation from Microsoft: + Intentionally disabled. + It didn't work all that well on some newer hardware, and worked less + well with the passage of time, so it was fully disabled in ME. + */ + if (!m_seperateLeftRightInitialized && isDown) { + CheckForSeperateLeftRight(wParam); + } + if (m_seperateLeftRight) { + bool down = HIBYTE(::GetKeyState(VK_LSHIFT)) != 0; + ConvertEvent(VK_LSHIFT, down); + down = HIBYTE(::GetKeyState(VK_RSHIFT)) != 0; + ConvertEvent(VK_RSHIFT, down); + down = HIBYTE(::GetKeyState(VK_LMENU)) != 0; + ConvertEvent(VK_LMENU, down); + down = HIBYTE(::GetKeyState(VK_RMENU)) != 0; + ConvertEvent(VK_RMENU, down); + down = HIBYTE(::GetKeyState(VK_LCONTROL)) != 0; + ConvertEvent(VK_LCONTROL, down); + down = HIBYTE(::GetKeyState(VK_RCONTROL)) != 0; + ConvertEvent(VK_RCONTROL, down); + } + else { + bool down = HIBYTE(::GetKeyState(VK_SHIFT)) != 0; + ConvertEvent(VK_LSHIFT, down); + ConvertEvent(VK_RSHIFT, down); + down = HIBYTE(::GetKeyState(VK_MENU)) != 0; + ConvertEvent(VK_LMENU, down); + ConvertEvent(VK_RMENU, down); + down = HIBYTE(::GetKeyState(VK_CONTROL)) != 0; + ConvertEvent(VK_LCONTROL, down); + ConvertEvent(VK_RCONTROL, down); + } +} + + +void GPW_KeyboardDevice::CheckForSeperateLeftRight(WPARAM wParam) +{ + // Check whether this system supports seperate left and right keys + switch (wParam) { + case VK_SHIFT: + m_seperateLeftRight = + (HIBYTE(::GetKeyState(VK_LSHIFT)) != 0) || + (HIBYTE(::GetKeyState(VK_RSHIFT)) != 0) ? + true : false; + break; + case VK_CONTROL: + m_seperateLeftRight = + (HIBYTE(::GetKeyState(VK_LCONTROL)) != 0) || + (HIBYTE(::GetKeyState(VK_RCONTROL)) != 0) ? + true : false; + break; + case VK_MENU: + m_seperateLeftRight = + (HIBYTE(::GetKeyState(VK_LMENU)) != 0) || + (HIBYTE(::GetKeyState(VK_RMENU)) != 0) ? + true : false; + break; + } + m_seperateLeftRightInitialized = true; +} diff --git a/source/gameengine/GamePlayer/common/windows/GPW_KeyboardDevice.h b/source/gameengine/GamePlayer/common/windows/GPW_KeyboardDevice.h new file mode 100644 index 00000000000..663c0ee2563 --- /dev/null +++ b/source/gameengine/GamePlayer/common/windows/GPW_KeyboardDevice.h @@ -0,0 +1,69 @@ +/** + * $Id$ + * + * ***** BEGIN GPL/BL DUAL LICENSE BLOCK ***** + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. The Blender + * Foundation also sells licenses for use in proprietary software under + * the Blender License. See http://www.blender.org/BL/ for information + * about this. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * + * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV. + * All rights reserved. + * + * The Original Code is: all of this file. + * + * Contributor(s): none yet. + * + * ***** END GPL/BL DUAL LICENSE BLOCK ***** + */ + +#ifndef _GPW_KEYBOARDDEVICE_H_ +#define _GPW_KEYBOARDDEVICE_H_ + +#pragma warning (disable : 4786) + +#include <windows.h> + +#include "GPC_KeyboardDevice.h" + +/** + * Win32 implementation of GPC_KeyboardDevice. + * The contructor fills the keyboard code translation map. + * Base class GPC_KeyboardDevice does the rest. + * @see SCA_IInputDevice + */ +class GPW_KeyboardDevice : public GPC_KeyboardDevice +{ +public: + GPW_KeyboardDevice(void); + + virtual ~GPW_KeyboardDevice(void); + + void ConvertWinEvent(WPARAM wParam, bool isDown); + +protected: + + void ConvertModifierKey(WPARAM wParam, bool isDown); + + void CheckForSeperateLeftRight(WPARAM wParam); + + /** Stores the capability of this system to distinguish left and right modifier keys. */ + bool m_seperateLeftRight; + /** Stores the initialization state of the member m_leftRightDistinguishable. */ + bool m_seperateLeftRightInitialized; +}; + +#endif //_GPW_KEYBOARDDEVICE_H_ diff --git a/source/gameengine/GamePlayer/common/windows/GPW_System.cpp b/source/gameengine/GamePlayer/common/windows/GPW_System.cpp new file mode 100644 index 00000000000..ba71e036fc4 --- /dev/null +++ b/source/gameengine/GamePlayer/common/windows/GPW_System.cpp @@ -0,0 +1,93 @@ +/** + * $Id$ + * + * ***** BEGIN GPL/BL DUAL LICENSE BLOCK ***** + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. The Blender + * Foundation also sells licenses for use in proprietary software under + * the Blender License. See http://www.blender.org/BL/ for information + * about this. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * + * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV. + * All rights reserved. + * + * The Original Code is: all of this file. + * + * Contributor(s): none yet. + * + * ***** END GPL/BL DUAL LICENSE BLOCK ***** + * Timing routine taken and modified from KX_BlenderSystem.cpp + */ + +#include <windows.h> + +#include "GPW_System.h" + + +GPW_System::GPW_System(void) +{ + m_freq = 0; + m_lastCount = 0; + m_lastRest = 0; + m_lastTime = 0; +} + + +double GPW_System::GetTimeInSeconds() +{ +#if 0 + double secs = ::GetTickCount(); + secs /= 1000.; + return secs; +#else + + // 03/20/1999 Thomas Hieber: completely redone to get true Millisecond + // accuracy instead of very rough ticks. This routine will also provide + // correct wrap around at the end of "long" + + // m_freq was set to -1, if the current Hardware does not support + // high resolution timers. We will use GetTickCount instead then. + if (m_freq < 0) { + return ::GetTickCount(); + } + + // m_freq is 0, the first time this function is being called. + if (m_freq == 0) { + // Try to determine the frequency of the high resulution timer + if (!::QueryPerformanceFrequency((LARGE_INTEGER*)&m_freq)) { + // There is no such timer.... + m_freq = -1; + return 0; + } + } + + // Retrieve current count + __int64 count = 0; + ::QueryPerformanceCounter((LARGE_INTEGER*)&count); + + // Calculate the time passed since last call, and add the rest of + // those tics that didn't make it into the last reported time. + __int64 delta = 1000*(count-m_lastCount) + m_lastRest; + + m_lastTime += (long)(delta/m_freq); // Save the new value + m_lastRest = delta%m_freq; // Save those ticks not being counted + m_lastCount = count; // Save last count + + // Return a high quality measurement of time + return m_lastTime/1000.0; +#endif +} + + diff --git a/source/gameengine/GamePlayer/common/windows/GPW_System.h b/source/gameengine/GamePlayer/common/windows/GPW_System.h new file mode 100644 index 00000000000..50b005d8342 --- /dev/null +++ b/source/gameengine/GamePlayer/common/windows/GPW_System.h @@ -0,0 +1,62 @@ +/** + * $Id$ + * + * ***** BEGIN GPL/BL DUAL LICENSE BLOCK ***** + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. The Blender + * Foundation also sells licenses for use in proprietary software under + * the Blender License. See http://www.blender.org/BL/ for information + * about this. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * + * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV. + * All rights reserved. + * + * The Original Code is: all of this file. + * + * Contributor(s): none yet. + * + * ***** END GPL/BL DUAL LICENSE BLOCK ***** + * Timing routine taken and modified from KX_BlenderSystem.cpp + */ + +#ifndef _GPW_SYSTEM_H_ +#define _GPW_SYSTEM_H_ + +#pragma warning (disable:4786) // suppress stl-MSVC debug info warning + +#include "GPC_System.h" + +#if defined(__CYGWIN32__) +# define __int64 long long +#endif + + +class GPW_System : public GPC_System +{ +public: + GPW_System(); + + virtual double GetTimeInSeconds(); +protected: + + __int64 m_freq; + __int64 m_lastCount; + __int64 m_lastRest; + long m_lastTime; + +}; + + +#endif //_GPW_SYSTEM_H_ diff --git a/source/gameengine/GamePlayer/common/windows/Makefile b/source/gameengine/GamePlayer/common/windows/Makefile new file mode 100644 index 00000000000..bc8d1da6f9a --- /dev/null +++ b/source/gameengine/GamePlayer/common/windows/Makefile @@ -0,0 +1,66 @@ +# +# $Id$ +# +# ***** BEGIN GPL/BL DUAL LICENSE BLOCK ***** +# +# This program is free software; you can redistribute it and/or +# modify it under the terms of the GNU General Public License +# as published by the Free Software Foundation; either version 2 +# of the License, or (at your option) any later version. The Blender +# Foundation also sells licenses for use in proprietary software under +# the Blender License. See http://www.blender.org/BL/ for information +# about this. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software Foundation, +# Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +# +# The Original Code is Copyright (C) 2001-2002 by NaN Holding BV. +# All rights reserved. +# +# The Original Code is: all of this file. +# +# Contributor(s): none yet. +# +# ***** END GPL/BL DUAL LICENSE BLOCK ***** +# +# +# ATTENTION: this Makefile is only used for win builds! + +LIBNAME = windows +DIR = $(OCGDIR)/gameengine/GamePlayer/common/$(LIBNAME) + +include nan_compile.mk + +CPPFLAGS += -I.. +CPPFLAGS += -I$(NAN_PYTHON)/include/python$(NAN_PYTHON_VERSION) + +CPPFLAGS += -I$(SRCHOME)/gameengine/GameLogic +CPPFLAGS += -I$(SRCHOME)/gameengine/Rasterizer +CPPFLAGS += -I$(SRCHOME)/gameengine/Ketsji +CPPFLAGS += -I$(SRCHOME)/gameengine/SoundSystem +CPPFLAGS += -I$(SRCHOME)/gameengine/Network +CPPFLAGS += -I$(SRCHOME)/gameengine/Network/LoopBackNetwork + +CPPFLAGS += -I$(SRCHOME)/sumo/Fuzzics/include +CPPFLAGS += -I$(SRCHOME)/sumo/include + +CPPFLAGS += -I$(NAN_MOTO)/include +CPPFLAGS += -I$(NAN_STRING)/include +CPPFLAGS += -I$(NAN_BMFONT)/include + +# Blender stuff +CPPFLAGS += -I$(SRCHOME)/blender/blenkernel +CPPFLAGS += -I$(SRCHOME)/blender/blenlib +CPPFLAGS += -I$(SRCHOME)/blender/blenloader +CPPFLAGS += -I$(SRCHOME)/blender/imbuf +CPPFLAGS += -I$(SRCHOME)/blender/makesdna +CPPFLAGS += -I$(SRCHOME)/kernel/gen_system + +CPPFLAGS += -I../../kernel/gen_system + |