2011-02-23 10:52:22 +00:00
|
|
|
/*
|
2008-04-16 22:40:48 +00:00
|
|
|
* ***** BEGIN GPL LICENSE BLOCK *****
|
2002-10-12 11:37:38 +00:00
|
|
|
*
|
|
|
|
* 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
|
2008-04-16 22:40:48 +00:00
|
|
|
* of the License, or (at your option) any later version.
|
2002-10-12 11:37:38 +00:00
|
|
|
*
|
|
|
|
* 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,
|
2010-02-12 13:34:04 +00:00
|
|
|
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
2002-10-12 11:37:38 +00:00
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*
|
2008-04-16 22:40:48 +00:00
|
|
|
* ***** END GPL LICENSE BLOCK *****
|
2002-10-12 11:37:38 +00:00
|
|
|
* GHOST Blender Player application implementation file.
|
|
|
|
*/
|
|
|
|
|
2011-02-25 13:35:11 +00:00
|
|
|
/** \file gameengine/GamePlayer/ghost/GPG_Application.cpp
|
|
|
|
* \ingroup player
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
2002-10-12 11:37:38 +00:00
|
|
|
#ifdef WIN32
|
|
|
|
#pragma warning (disable:4786) // suppress stl-MSVC debug info warning
|
2004-06-26 09:15:41 +00:00
|
|
|
#include <windows.h>
|
|
|
|
#endif
|
|
|
|
|
Merge of apricot branch game engine changes into trunk, excluding GLSL.
GLEW
====
Added the GLEW opengl extension library into extern/, always compiled
into Blender now. This is much nicer than doing this kind of extension
management manually, and will be used in the game engine, for GLSL, and
other opengl extensions.
* According to the GLEW website it works on Windows, Linux, Mac OS X,
FreeBSD, Irix, and Solaris. There might still be platform specific
issues due to this commit, so let me know and I'll look into it.
* This means also that all extensions will now always be compiled in,
regardless of the glext.h on the platform where compilation happens.
Game Engine
===========
Refactoring of the use of opengl extensions and other drawing code
in the game engine, and cleaning up some hacks related to GLSL
integration. These changes will be merged into trunk too after this.
The game engine graphics demos & apricot level survived my tests,
but this could use some good testing of course.
For users: please test with the options "Generate Display Lists" and
"Vertex Arrays" enabled, these should be the fastest and are supposed
to be "unreliable", but if that's the case that's probably due to bugs
that can be fixed.
* The game engine now also uses GLEW for extensions, replacing the
custom opengl extensions code that was there. Removes a lot of
#ifdef's, but the runtime checks stay of course.
* Removed the WITHOUT_GLEXT environment variable. This was added to
work around a specific bug and only disabled multitexturing anyway.
It might also have caused a slowdown since it was retrieving the
environment variable for every vertex in immediate mode (bug #13680).
* Refactored the code to allow drawing skinned meshes with vertex
arrays too, removing some specific immediate mode drawing functions
for this that only did extra normal calculation. Now it always splits
vertices of flat faces instead.
* Refactored normal recalculation with some minor optimizations,
required for the above change.
* Removed some outdated code behind the __NLA_OLDDEFORM #ifdef.
* Fixed various bugs in setting of multitexture coordinates and vertex
attributes for vertex arrays. These were not being enabled/disabled
correct according to the opengl spec, leading to crashes. Also tangent
attributes used an immediate mode call for vertex arrays, which can't
work.
* Fixed use of uninitialized variable in RAS_TexVert.
* Exporting skinned meshes was doing O(n^2) lookups for vertices and
deform weights, now uses same trick as regular meshes.
2008-06-17 10:27:34 +00:00
|
|
|
#include "GL/glew.h"
|
Merge of first part of changes from the apricot branch, especially
the features that are needed to run the game. Compile tested with
scons, make, but not cmake, that seems to have an issue not related
to these changes. The changes include:
* GLSL support in the viewport and game engine, enable in the game
menu in textured draw mode.
* Synced and merged part of the duplicated blender and gameengine/
gameplayer drawing code.
* Further refactoring of game engine drawing code, especially mesh
storage changed a lot.
* Optimizations in game engine armatures to avoid recomputations.
* A python function to get the framerate estimate in game.
* An option take object color into account in materials.
* An option to restrict shadow casters to a lamp's layers.
* Increase from 10 to 18 texture slots for materials, lamps, word.
An extra texture slot shows up once the last slot is used.
* Memory limit for undo, not enabled by default yet because it
needs the .B.blend to be changed.
* Multiple undo for image painting.
* An offset for dupligroups, so not all objects in a group have to
be at the origin.
2008-09-04 20:51:28 +00:00
|
|
|
#include "GPU_extensions.h"
|
2002-10-12 11:37:38 +00:00
|
|
|
|
|
|
|
#include "GPG_Application.h"
|
Cucumber, first batch of merge - UI changes and custom exit key
---------------------------------------------------------------
This was a test drive to see how painful the merge will be.
Next batches are:
- use desktop option for fullscreen
- multisampling option
- bullet collision mask
- python
- storage (vbo, dl, ...)
- lighting
[lighting still needs review]
[python could use review, although it should be straightforward]
[storage should be tested more I think]
Merged /branches/soc-2011-cucumber:r
36991,37059,37157,37416,37497-37499,37501,37522,39036,40593
36991:
==UI==
* Made some options available in Blender Game that were only available in Blender Render (camera resolution, animation fps)
* Created a panel for the embedded player
* Renamed the FPS option for the standalone player to Refresh Rate
* Moved framing options to display
* Made a button to launch the blender player from within blender (only tested on windows for now)
37059:
==UI==
* Added the option to change the exit key for the BGE. The UI currently just sets a number, and this feature most likely does not work for blenderplayer yet. More work on this to come.
* Removed the physics settings from the scene panel for the BGE.
* Added an Add menu in the logic brick header.
37157:
Making the bake options available in Blender Game
37416:
Making the exit key UI element accept key presses instead of numbers. It still does not work for the Blenderplayer, and it does not limit the input to key presses (other events don't work for exiting)
37497:
Some more work on getting the exit key to work in the Blenderplayer.
Input is now restricted to keyboard events only for the exit key UI.
37498:
Some clean up from the last commit.
The exit key setting affects the Blenderplayer now.
37499:
Cleaning up some duplicate code. Now the reverseTranslateTable for converting blender key codes to ketsji key codes is only defined in BL_BlenderDataConverter.
37501:
Centralizing the exit key methods to the keyboard devices. This should make it easier to get exit key control to the python API.
[37517: committed previously]
37522:
Moved control of the exit key away from the keyboard devices, and moved it to ketsjiengine.
Added setExitKey and getExitKey to the python API
39036:
A couple of the doversions were in the wrong spot. This should fix some issues with the exit key not being set.
[not committed entirely, see below]]
40552: space_logic.py (* fixed an error in space_logic.py *)
40593:
launch blenderplayer from ui not working in OSX fix - by Daniel Stokes and me
########################################################
code left behind (to be included in next commit):
########################################################
{
/* Initialize default values for collision masks */
Object *ob;
for(ob=main->object.first; ob; ob=ob->id.next)
ob->col_group = ob->col_mask = 1;
}
2011-12-20 03:11:56 +00:00
|
|
|
#include "BL_BlenderDataConversion.h"
|
2002-10-12 11:37:38 +00:00
|
|
|
|
|
|
|
#include <iostream>
|
2005-03-25 10:33:39 +00:00
|
|
|
#include <MT_assert.h>
|
2008-04-16 17:40:59 +00:00
|
|
|
#include <stdlib.h>
|
2002-10-12 11:37:38 +00:00
|
|
|
|
|
|
|
/**********************************
|
|
|
|
* Begin Blender include block
|
|
|
|
**********************************/
|
|
|
|
#ifdef __cplusplus
|
|
|
|
extern "C"
|
|
|
|
{
|
|
|
|
#endif // __cplusplus
|
|
|
|
#include "BLI_blenlib.h"
|
|
|
|
#include "BLO_readfile.h"
|
2006-01-06 03:46:54 +00:00
|
|
|
#include "BKE_global.h"
|
|
|
|
#include "BKE_main.h"
|
2009-09-04 20:03:27 +00:00
|
|
|
#include "BKE_sound.h"
|
2008-09-26 14:54:21 +00:00
|
|
|
#include "IMB_imbuf.h"
|
2008-08-06 04:09:10 +00:00
|
|
|
#include "DNA_scene_types.h"
|
2002-10-12 11:37:38 +00:00
|
|
|
#ifdef __cplusplus
|
|
|
|
}
|
|
|
|
#endif // __cplusplus
|
|
|
|
/**********************************
|
|
|
|
* End Blender include block
|
|
|
|
**********************************/
|
|
|
|
|
|
|
|
|
2011-05-06 20:18:42 +00:00
|
|
|
#include "BL_System.h"
|
2002-10-12 11:37:38 +00:00
|
|
|
#include "KX_KetsjiEngine.h"
|
|
|
|
|
|
|
|
// include files needed by "KX_BlenderSceneConverter.h"
|
2011-05-06 20:18:42 +00:00
|
|
|
#include "CTR_Map.h"
|
2002-10-12 11:37:38 +00:00
|
|
|
#include "SCA_IActuator.h"
|
|
|
|
#include "RAS_MeshObject.h"
|
|
|
|
#include "RAS_OpenGLRasterizer.h"
|
2006-04-02 21:04:20 +00:00
|
|
|
#include "RAS_ListRasterizer.h"
|
2004-04-24 06:40:15 +00:00
|
|
|
#include "RAS_GLExtensionManager.h"
|
2002-10-12 11:37:38 +00:00
|
|
|
#include "KX_PythonInit.h"
|
|
|
|
#include "KX_PyConstraintBinding.h"
|
2006-01-06 03:46:54 +00:00
|
|
|
#include "BL_Material.h" // MAXTEX
|
2002-10-12 11:37:38 +00:00
|
|
|
|
|
|
|
#include "KX_BlenderSceneConverter.h"
|
|
|
|
#include "NG_LoopBackNetworkDeviceInterface.h"
|
2009-09-03 02:55:23 +00:00
|
|
|
|
2002-10-12 11:37:38 +00:00
|
|
|
#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"
|
|
|
|
|
2013-07-19 23:31:45 +00:00
|
|
|
#ifdef WITH_AUDASPACE
|
|
|
|
# include "AUD_C-API.h"
|
|
|
|
# include "AUD_I3DDevice.h"
|
|
|
|
# include "AUD_IDevice.h"
|
|
|
|
#endif
|
|
|
|
|
2002-10-12 11:37:38 +00:00
|
|
|
static void frameTimerProc(GHOST_ITimerTask* task, GHOST_TUns64 time);
|
|
|
|
|
|
|
|
static GHOST_ISystem* fSystem = 0;
|
|
|
|
static const int kTimerFreq = 10;
|
|
|
|
|
Merge of first part of changes from the apricot branch, especially
the features that are needed to run the game. Compile tested with
scons, make, but not cmake, that seems to have an issue not related
to these changes. The changes include:
* GLSL support in the viewport and game engine, enable in the game
menu in textured draw mode.
* Synced and merged part of the duplicated blender and gameengine/
gameplayer drawing code.
* Further refactoring of game engine drawing code, especially mesh
storage changed a lot.
* Optimizations in game engine armatures to avoid recomputations.
* A python function to get the framerate estimate in game.
* An option take object color into account in materials.
* An option to restrict shadow casters to a lamp's layers.
* Increase from 10 to 18 texture slots for materials, lamps, word.
An extra texture slot shows up once the last slot is used.
* Memory limit for undo, not enabled by default yet because it
needs the .B.blend to be changed.
* Multiple undo for image painting.
* An offset for dupligroups, so not all objects in a group have to
be at the origin.
2008-09-04 20:51:28 +00:00
|
|
|
GPG_Application::GPG_Application(GHOST_ISystem* system)
|
|
|
|
: m_startSceneName(""),
|
|
|
|
m_startScene(0),
|
|
|
|
m_maggie(0),
|
2004-07-17 05:28:23 +00:00
|
|
|
m_exitRequested(0),
|
|
|
|
m_system(system),
|
|
|
|
m_mainWindow(0),
|
|
|
|
m_frameTimer(0),
|
|
|
|
m_cursor(GHOST_kStandardCursorFirstCursor),
|
|
|
|
m_engineInitialized(0),
|
|
|
|
m_engineRunning(0),
|
2008-09-16 19:25:35 +00:00
|
|
|
m_isEmbedded(false),
|
2004-07-17 05:28:23 +00:00
|
|
|
m_ketsjiengine(0),
|
|
|
|
m_kxsystem(0),
|
|
|
|
m_keyboard(0),
|
|
|
|
m_mouse(0),
|
2013-11-04 19:21:07 +00:00
|
|
|
m_canvas(0),
|
2004-07-17 05:28:23 +00:00
|
|
|
m_rasterizer(0),
|
|
|
|
m_sceneconverter(0),
|
2009-09-04 20:03:27 +00:00
|
|
|
m_networkdevice(0),
|
Merge of apricot branch game engine changes into trunk, excluding GLSL.
GLEW
====
Added the GLEW opengl extension library into extern/, always compiled
into Blender now. This is much nicer than doing this kind of extension
management manually, and will be used in the game engine, for GLSL, and
other opengl extensions.
* According to the GLEW website it works on Windows, Linux, Mac OS X,
FreeBSD, Irix, and Solaris. There might still be platform specific
issues due to this commit, so let me know and I'll look into it.
* This means also that all extensions will now always be compiled in,
regardless of the glext.h on the platform where compilation happens.
Game Engine
===========
Refactoring of the use of opengl extensions and other drawing code
in the game engine, and cleaning up some hacks related to GLSL
integration. These changes will be merged into trunk too after this.
The game engine graphics demos & apricot level survived my tests,
but this could use some good testing of course.
For users: please test with the options "Generate Display Lists" and
"Vertex Arrays" enabled, these should be the fastest and are supposed
to be "unreliable", but if that's the case that's probably due to bugs
that can be fixed.
* The game engine now also uses GLEW for extensions, replacing the
custom opengl extensions code that was there. Removes a lot of
#ifdef's, but the runtime checks stay of course.
* Removed the WITHOUT_GLEXT environment variable. This was added to
work around a specific bug and only disabled multitexturing anyway.
It might also have caused a slowdown since it was retrieving the
environment variable for every vertex in immediate mode (bug #13680).
* Refactored the code to allow drawing skinned meshes with vertex
arrays too, removing some specific immediate mode drawing functions
for this that only did extra normal calculation. Now it always splits
vertices of flat faces instead.
* Refactored normal recalculation with some minor optimizations,
required for the above change.
* Removed some outdated code behind the __NLA_OLDDEFORM #ifdef.
* Fixed various bugs in setting of multitexture coordinates and vertex
attributes for vertex arrays. These were not being enabled/disabled
correct according to the opengl spec, leading to crashes. Also tangent
attributes used an immediate mode call for vertex arrays, which can't
work.
* Fixed use of uninitialized variable in RAS_TexVert.
* Exporting skinned meshes was doing O(n^2) lookups for vertices and
deform weights, now uses same trick as regular meshes.
2008-06-17 10:27:34 +00:00
|
|
|
m_blendermat(0),
|
2008-08-20 06:11:11 +00:00
|
|
|
m_blenderglslmat(0),
|
|
|
|
m_pyGlobalDictString(0),
|
2008-09-16 19:25:35 +00:00
|
|
|
m_pyGlobalDictString_Length(0)
|
2002-10-12 11:37:38 +00:00
|
|
|
{
|
|
|
|
fSystem = system;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
GPG_Application::~GPG_Application(void)
|
|
|
|
{
|
2012-03-24 07:52:14 +00:00
|
|
|
if (m_pyGlobalDictString) {
|
2008-09-17 01:29:54 +00:00
|
|
|
delete [] m_pyGlobalDictString;
|
2008-09-16 19:25:35 +00:00
|
|
|
m_pyGlobalDictString = 0;
|
|
|
|
m_pyGlobalDictString_Length = 0;
|
|
|
|
}
|
|
|
|
|
2002-10-12 11:37:38 +00:00
|
|
|
exitEngine();
|
|
|
|
fSystem->disposeWindow(m_mainWindow);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2011-09-11 05:54:07 +00:00
|
|
|
bool GPG_Application::SetGameEngineData(struct Main* maggie, Scene *scene, GlobalSettings *gs, int argc, char **argv)
|
2002-10-12 11:37:38 +00:00
|
|
|
{
|
|
|
|
bool result = false;
|
|
|
|
|
Merge of first part of changes from the apricot branch, especially
the features that are needed to run the game. Compile tested with
scons, make, but not cmake, that seems to have an issue not related
to these changes. The changes include:
* GLSL support in the viewport and game engine, enable in the game
menu in textured draw mode.
* Synced and merged part of the duplicated blender and gameengine/
gameplayer drawing code.
* Further refactoring of game engine drawing code, especially mesh
storage changed a lot.
* Optimizations in game engine armatures to avoid recomputations.
* A python function to get the framerate estimate in game.
* An option take object color into account in materials.
* An option to restrict shadow casters to a lamp's layers.
* Increase from 10 to 18 texture slots for materials, lamps, word.
An extra texture slot shows up once the last slot is used.
* Memory limit for undo, not enabled by default yet because it
needs the .B.blend to be changed.
* Multiple undo for image painting.
* An offset for dupligroups, so not all objects in a group have to
be at the origin.
2008-09-04 20:51:28 +00:00
|
|
|
if (maggie != NULL && scene != NULL)
|
2002-10-12 11:37:38 +00:00
|
|
|
{
|
2009-01-04 14:14:06 +00:00
|
|
|
// XXX G.scene = scene;
|
2002-10-12 11:37:38 +00:00
|
|
|
m_maggie = maggie;
|
Merge of first part of changes from the apricot branch, especially
the features that are needed to run the game. Compile tested with
scons, make, but not cmake, that seems to have an issue not related
to these changes. The changes include:
* GLSL support in the viewport and game engine, enable in the game
menu in textured draw mode.
* Synced and merged part of the duplicated blender and gameengine/
gameplayer drawing code.
* Further refactoring of game engine drawing code, especially mesh
storage changed a lot.
* Optimizations in game engine armatures to avoid recomputations.
* A python function to get the framerate estimate in game.
* An option take object color into account in materials.
* An option to restrict shadow casters to a lamp's layers.
* Increase from 10 to 18 texture slots for materials, lamps, word.
An extra texture slot shows up once the last slot is used.
* Memory limit for undo, not enabled by default yet because it
needs the .B.blend to be changed.
* Multiple undo for image painting.
* An offset for dupligroups, so not all objects in a group have to
be at the origin.
2008-09-04 20:51:28 +00:00
|
|
|
m_startSceneName = scene->id.name+2;
|
|
|
|
m_startScene = scene;
|
2002-10-12 11:37:38 +00:00
|
|
|
result = true;
|
|
|
|
}
|
2009-04-20 15:06:46 +00:00
|
|
|
|
|
|
|
/* Python needs these */
|
|
|
|
m_argc= argc;
|
|
|
|
m_argv= argv;
|
2002-10-12 11:37:38 +00:00
|
|
|
|
2011-09-11 05:54:07 +00:00
|
|
|
/* Global Settings */
|
|
|
|
m_globalSettings= gs;
|
|
|
|
|
2002-10-12 11:37:38 +00:00
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2004-12-01 08:35:38 +00:00
|
|
|
#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
|
2011-09-03 02:15:49 +00:00
|
|
|
|| abs(dy) > SCR_SAVE_MOUSE_MOVE_THRESHOLD)
|
2004-12-01 08:35:38 +00:00
|
|
|
{
|
|
|
|
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)
|
|
|
|
{
|
2009-04-20 15:06:46 +00:00
|
|
|
GHOST_IWindow *p = (GHOST_IWindow*) GetWindowLongPtr(hwnd, GWLP_USERDATA);
|
2004-12-01 08:35:38 +00:00
|
|
|
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,
|
Patch [#26799] 2.5x blenderplayer (BGE) anti-aliasing & embedding by Sebastian Korczak (with some small tweaks) + adding GHOST_PRINTF
The patch can also be found in http://codereview.appspot.com/4431072/
##############
This patch fix anti-aliasing (multisampling) implementation for win32 platform. It also gives opportunity to embed blenderplayer inside parent window.
Usage:
blenderplayer.exe -i 123456 -m 16 file.blend
where:
123456 - parent window handler (integer, default: 0)
16 - multisample level (integer, default: 0, max: 16. Put there maximum level you want. If not supported, player will automatically try 15,14,13,...,3,2,1)
##############
This patch was originally created as part of the Burster (aka webplugin) project but benefit any one embedding the bge in a custom OpenGL context. By the way, to embed the BGE in a .Net application is really straightforward now =)
The Multisampling work for blenderplayer as a whole.
Missing functionalities:
- to expose the multisampling to the ui (so far it only works in console)
- window focus and keyboard messages for embedded blenderplayer (supported in their previous patch for 2.49, yet to be ported over)
- handle resizing (to be investigated, indeed the changes in getState() in GHOST_WindowWin32.cpp are going to get in the way of that if I'm not mistaken. To be addressed together.
Doxygen documentation to be added whenever I sort out how to do so. Sorry Nathan too many stuff to deal with at the same time. The sooner this patch gets in, the sooner the missing functionalities can be patched on top of that.
2011-05-04 01:50:17 +00:00
|
|
|
const int stereoMode,
|
|
|
|
const GHOST_TUns16 samples)
|
2004-12-01 08:35:38 +00:00
|
|
|
{
|
|
|
|
bool success = false;
|
|
|
|
|
|
|
|
RECT rc;
|
|
|
|
if (GetWindowRect(parentWindow, &rc))
|
|
|
|
{
|
|
|
|
int windowWidth = rc.right - rc.left;
|
|
|
|
int windowHeight = rc.bottom - rc.top;
|
|
|
|
STR_String title = "";
|
|
|
|
|
|
|
|
m_mainWindow = fSystem->createWindow(title, 0, 0, windowWidth, windowHeight, GHOST_kWindowStateMinimized,
|
Patch [#26799] 2.5x blenderplayer (BGE) anti-aliasing & embedding by Sebastian Korczak (with some small tweaks) + adding GHOST_PRINTF
The patch can also be found in http://codereview.appspot.com/4431072/
##############
This patch fix anti-aliasing (multisampling) implementation for win32 platform. It also gives opportunity to embed blenderplayer inside parent window.
Usage:
blenderplayer.exe -i 123456 -m 16 file.blend
where:
123456 - parent window handler (integer, default: 0)
16 - multisample level (integer, default: 0, max: 16. Put there maximum level you want. If not supported, player will automatically try 15,14,13,...,3,2,1)
##############
This patch was originally created as part of the Burster (aka webplugin) project but benefit any one embedding the bge in a custom OpenGL context. By the way, to embed the BGE in a .Net application is really straightforward now =)
The Multisampling work for blenderplayer as a whole.
Missing functionalities:
- to expose the multisampling to the ui (so far it only works in console)
- window focus and keyboard messages for embedded blenderplayer (supported in their previous patch for 2.49, yet to be ported over)
- handle resizing (to be investigated, indeed the changes in getState() in GHOST_WindowWin32.cpp are going to get in the way of that if I'm not mistaken. To be addressed together.
Doxygen documentation to be added whenever I sort out how to do so. Sorry Nathan too many stuff to deal with at the same time. The sooner this patch gets in, the sooner the missing functionalities can be patched on top of that.
2011-05-04 01:50:17 +00:00
|
|
|
GHOST_kDrawingContextTypeOpenGL, stereoVisual, samples);
|
2004-12-01 08:35:38 +00:00
|
|
|
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);
|
2013-05-13 20:27:05 +00:00
|
|
|
LONG_PTR style = GetWindowLongPtr(ghost_hwnd, GWL_STYLE);
|
|
|
|
LONG_PTR exstyle = GetWindowLongPtr(ghost_hwnd, GWL_EXSTYLE);
|
2004-12-01 08:35:38 +00:00
|
|
|
|
|
|
|
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;
|
2013-05-13 20:27:05 +00:00
|
|
|
SetWindowLongPtr(ghost_hwnd, GWL_STYLE, style);
|
2004-12-01 08:35:38 +00:00
|
|
|
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,
|
Patch [#26799] 2.5x blenderplayer (BGE) anti-aliasing & embedding by Sebastian Korczak (with some small tweaks) + adding GHOST_PRINTF
The patch can also be found in http://codereview.appspot.com/4431072/
##############
This patch fix anti-aliasing (multisampling) implementation for win32 platform. It also gives opportunity to embed blenderplayer inside parent window.
Usage:
blenderplayer.exe -i 123456 -m 16 file.blend
where:
123456 - parent window handler (integer, default: 0)
16 - multisample level (integer, default: 0, max: 16. Put there maximum level you want. If not supported, player will automatically try 15,14,13,...,3,2,1)
##############
This patch was originally created as part of the Burster (aka webplugin) project but benefit any one embedding the bge in a custom OpenGL context. By the way, to embed the BGE in a .Net application is really straightforward now =)
The Multisampling work for blenderplayer as a whole.
Missing functionalities:
- to expose the multisampling to the ui (so far it only works in console)
- window focus and keyboard messages for embedded blenderplayer (supported in their previous patch for 2.49, yet to be ported over)
- handle resizing (to be investigated, indeed the changes in getState() in GHOST_WindowWin32.cpp are going to get in the way of that if I'm not mistaken. To be addressed together.
Doxygen documentation to be added whenever I sort out how to do so. Sorry Nathan too many stuff to deal with at the same time. The sooner this patch gets in, the sooner the missing functionalities can be patched on top of that.
2011-05-04 01:50:17 +00:00
|
|
|
const int stereoMode,
|
|
|
|
const GHOST_TUns16 samples)
|
2004-12-01 08:35:38 +00:00
|
|
|
{
|
Patch [#26799] 2.5x blenderplayer (BGE) anti-aliasing & embedding by Sebastian Korczak (with some small tweaks) + adding GHOST_PRINTF
The patch can also be found in http://codereview.appspot.com/4431072/
##############
This patch fix anti-aliasing (multisampling) implementation for win32 platform. It also gives opportunity to embed blenderplayer inside parent window.
Usage:
blenderplayer.exe -i 123456 -m 16 file.blend
where:
123456 - parent window handler (integer, default: 0)
16 - multisample level (integer, default: 0, max: 16. Put there maximum level you want. If not supported, player will automatically try 15,14,13,...,3,2,1)
##############
This patch was originally created as part of the Burster (aka webplugin) project but benefit any one embedding the bge in a custom OpenGL context. By the way, to embed the BGE in a .Net application is really straightforward now =)
The Multisampling work for blenderplayer as a whole.
Missing functionalities:
- to expose the multisampling to the ui (so far it only works in console)
- window focus and keyboard messages for embedded blenderplayer (supported in their previous patch for 2.49, yet to be ported over)
- handle resizing (to be investigated, indeed the changes in getState() in GHOST_WindowWin32.cpp are going to get in the way of that if I'm not mistaken. To be addressed together.
Doxygen documentation to be added whenever I sort out how to do so. Sorry Nathan too many stuff to deal with at the same time. The sooner this patch gets in, the sooner the missing functionalities can be patched on top of that.
2011-05-04 01:50:17 +00:00
|
|
|
bool ret = startFullScreen(width, height, bpp, frequency, stereoVisual, stereoMode, samples);
|
2004-12-01 08:35:38 +00:00
|
|
|
if (ret)
|
|
|
|
{
|
|
|
|
HWND ghost_hwnd = findGhostWindowHWND(m_mainWindow);
|
|
|
|
if (ghost_hwnd != NULL)
|
|
|
|
{
|
|
|
|
GetCursorPos(&scr_save_mouse_pos);
|
2009-04-20 15:06:46 +00:00
|
|
|
ghost_wnd_proc = (WNDPROC) GetWindowLongPtr(ghost_hwnd, GWLP_WNDPROC);
|
|
|
|
SetWindowLongPtr(ghost_hwnd,GWLP_WNDPROC, (uintptr_t) screenSaverWindowProc);
|
2004-12-01 08:35:38 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|
2002-10-12 11:37:38 +00:00
|
|
|
|
2013-02-24 10:50:33 +00:00
|
|
|
bool GPG_Application::startWindow(
|
|
|
|
STR_String& title,
|
|
|
|
int windowLeft,
|
|
|
|
int windowTop,
|
|
|
|
int windowWidth,
|
|
|
|
int windowHeight,
|
|
|
|
const bool stereoVisual,
|
|
|
|
const int stereoMode,
|
|
|
|
const GHOST_TUns16 samples)
|
2002-10-12 11:37:38 +00:00
|
|
|
{
|
|
|
|
bool success;
|
|
|
|
// Create the main window
|
|
|
|
//STR_String title ("Blender Player - GHOST");
|
|
|
|
m_mainWindow = fSystem->createWindow(title, windowLeft, windowTop, windowWidth, windowHeight, GHOST_kWindowStateNormal,
|
2013-02-24 10:50:33 +00:00
|
|
|
GHOST_kDrawingContextTypeOpenGL, stereoVisual, false, samples);
|
2004-04-11 02:50:02 +00:00
|
|
|
if (!m_mainWindow) {
|
2002-10-12 11:37:38 +00:00
|
|
|
printf("error: could not create main window\n");
|
2004-04-11 02:50:02 +00:00
|
|
|
exit(-1);
|
|
|
|
}
|
2002-10-12 11:37:38 +00:00
|
|
|
|
|
|
|
/* 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);
|
2004-03-22 22:02:18 +00:00
|
|
|
m_mainWindow->setCursorVisibility(false);
|
2002-10-12 11:37:38 +00:00
|
|
|
|
|
|
|
success = initEngine(m_mainWindow, stereoMode);
|
|
|
|
if (success) {
|
|
|
|
success = startEngine();
|
|
|
|
}
|
|
|
|
return success;
|
|
|
|
}
|
|
|
|
|
2013-02-24 10:50:33 +00:00
|
|
|
bool GPG_Application::startEmbeddedWindow(
|
|
|
|
STR_String& title,
|
|
|
|
const GHOST_TEmbedderWindowID parentWindow,
|
|
|
|
const bool stereoVisual,
|
|
|
|
const int stereoMode,
|
|
|
|
const GHOST_TUns16 samples)
|
|
|
|
{
|
Patch [#26799] 2.5x blenderplayer (BGE) anti-aliasing & embedding by Sebastian Korczak (with some small tweaks) + adding GHOST_PRINTF
The patch can also be found in http://codereview.appspot.com/4431072/
##############
This patch fix anti-aliasing (multisampling) implementation for win32 platform. It also gives opportunity to embed blenderplayer inside parent window.
Usage:
blenderplayer.exe -i 123456 -m 16 file.blend
where:
123456 - parent window handler (integer, default: 0)
16 - multisample level (integer, default: 0, max: 16. Put there maximum level you want. If not supported, player will automatically try 15,14,13,...,3,2,1)
##############
This patch was originally created as part of the Burster (aka webplugin) project but benefit any one embedding the bge in a custom OpenGL context. By the way, to embed the BGE in a .Net application is really straightforward now =)
The Multisampling work for blenderplayer as a whole.
Missing functionalities:
- to expose the multisampling to the ui (so far it only works in console)
- window focus and keyboard messages for embedded blenderplayer (supported in their previous patch for 2.49, yet to be ported over)
- handle resizing (to be investigated, indeed the changes in getState() in GHOST_WindowWin32.cpp are going to get in the way of that if I'm not mistaken. To be addressed together.
Doxygen documentation to be added whenever I sort out how to do so. Sorry Nathan too many stuff to deal with at the same time. The sooner this patch gets in, the sooner the missing functionalities can be patched on top of that.
2011-05-04 01:50:17 +00:00
|
|
|
GHOST_TWindowState state = GHOST_kWindowStateNormal;
|
|
|
|
if (parentWindow != 0)
|
|
|
|
state = GHOST_kWindowStateEmbedded;
|
|
|
|
m_mainWindow = fSystem->createWindow(title, 0, 0, 0, 0, state,
|
2013-02-24 10:50:33 +00:00
|
|
|
GHOST_kDrawingContextTypeOpenGL, stereoVisual, false, samples, parentWindow);
|
2008-09-09 21:15:30 +00:00
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
2002-10-12 11:37:38 +00:00
|
|
|
|
|
|
|
|
|
|
|
bool GPG_Application::startFullScreen(
|
2013-02-24 10:50:33 +00:00
|
|
|
int width,
|
|
|
|
int height,
|
|
|
|
int bpp,int frequency,
|
|
|
|
const bool stereoVisual,
|
|
|
|
const int stereoMode,
|
|
|
|
const GHOST_TUns16 samples,
|
|
|
|
bool useDesktop)
|
2002-10-12 11:37:38 +00:00
|
|
|
{
|
|
|
|
bool success;
|
2012-01-11 20:53:22 +00:00
|
|
|
GHOST_TUns32 sysWidth=0, sysHeight=0;
|
|
|
|
fSystem->getMainDisplayDimensions(sysWidth, sysHeight);
|
2002-10-12 11:37:38 +00:00
|
|
|
// Create the main window
|
|
|
|
GHOST_DisplaySetting setting;
|
2012-01-11 20:53:22 +00:00
|
|
|
setting.xPixels = (useDesktop) ? sysWidth : width;
|
|
|
|
setting.yPixels = (useDesktop) ? sysHeight : height;
|
2002-10-12 11:37:38 +00:00
|
|
|
setting.bpp = bpp;
|
|
|
|
setting.frequency = frequency;
|
|
|
|
|
2012-01-11 20:53:22 +00:00
|
|
|
fSystem->beginFullScreen(setting, &m_mainWindow, stereoVisual, samples);
|
2004-03-22 22:02:18 +00:00
|
|
|
m_mainWindow->setCursorVisibility(false);
|
2013-02-24 05:05:29 +00:00
|
|
|
/* note that X11 ignores this (it uses a window internally for fullscreen) */
|
2010-09-14 08:19:42 +00:00
|
|
|
m_mainWindow->setState(GHOST_kWindowStateFullScreen);
|
2002-10-12 11:37:38 +00:00
|
|
|
|
|
|
|
success = initEngine(m_mainWindow, stereoMode);
|
|
|
|
if (success) {
|
|
|
|
success = startEngine();
|
|
|
|
}
|
|
|
|
return success;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2006-07-19 06:39:11 +00:00
|
|
|
|
2002-10-12 11:37:38 +00:00
|
|
|
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;
|
2004-05-02 23:45:03 +00:00
|
|
|
|
|
|
|
case GHOST_kEventWheel:
|
|
|
|
handled = handleWheel(event);
|
|
|
|
break;
|
2002-10-12 11:37:38 +00:00
|
|
|
|
|
|
|
case GHOST_kEventCursorMove:
|
|
|
|
handled = handleCursorMove(event);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case GHOST_kEventKeyDown:
|
|
|
|
handleKey(event, true);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case GHOST_kEventKeyUp:
|
|
|
|
handleKey(event, false);
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
|
|
case GHOST_kEventWindowClose:
|
2011-06-27 14:34:58 +00:00
|
|
|
case GHOST_kEventQuit:
|
2002-10-12 11:37:38 +00:00
|
|
|
m_exitRequested = KX_EXIT_REQUEST_OUTSIDE;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case GHOST_kEventWindowActivate:
|
|
|
|
handled = false;
|
|
|
|
break;
|
|
|
|
case GHOST_kEventWindowDeactivate:
|
|
|
|
handled = false;
|
|
|
|
break;
|
|
|
|
|
2012-08-18 23:46:37 +00:00
|
|
|
// 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();
|
2012-09-16 04:58:18 +00:00
|
|
|
//
|
2012-08-18 23:46:37 +00:00
|
|
|
// // kick the engine
|
|
|
|
// bool renderFrame = m_ketsjiengine->NextFrame();
|
|
|
|
// if (renderFrame)
|
|
|
|
// {
|
|
|
|
// // render the frame
|
|
|
|
// m_ketsjiengine->Render();
|
|
|
|
// }
|
|
|
|
// }
|
|
|
|
// m_exitString = m_ketsjiengine->GetExitString();
|
|
|
|
// }
|
|
|
|
// break;
|
|
|
|
//
|
2002-10-12 11:37:38 +00:00
|
|
|
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());
|
2013-04-12 01:52:30 +00:00
|
|
|
m_ketsjiengine->Resize();
|
2002-10-12 11:37:38 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
handled = false;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return handled;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
int GPG_Application::getExitRequested(void)
|
|
|
|
{
|
|
|
|
return m_exitRequested;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-09-11 05:54:07 +00:00
|
|
|
GlobalSettings* GPG_Application::getGlobalSettings(void)
|
|
|
|
{
|
|
|
|
return m_ketsjiengine->GetGlobalSettings();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2002-10-12 11:37:38 +00:00
|
|
|
|
|
|
|
const STR_String& GPG_Application::getExitString(void)
|
|
|
|
{
|
|
|
|
return m_exitString;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
bool GPG_Application::initEngine(GHOST_IWindow* window, const int stereoMode)
|
|
|
|
{
|
|
|
|
if (!m_engineInitialized)
|
|
|
|
{
|
Merge of first part of changes from the apricot branch, especially
the features that are needed to run the game. Compile tested with
scons, make, but not cmake, that seems to have an issue not related
to these changes. The changes include:
* GLSL support in the viewport and game engine, enable in the game
menu in textured draw mode.
* Synced and merged part of the duplicated blender and gameengine/
gameplayer drawing code.
* Further refactoring of game engine drawing code, especially mesh
storage changed a lot.
* Optimizations in game engine armatures to avoid recomputations.
* A python function to get the framerate estimate in game.
* An option take object color into account in materials.
* An option to restrict shadow casters to a lamp's layers.
* Increase from 10 to 18 texture slots for materials, lamps, word.
An extra texture slot shows up once the last slot is used.
* Memory limit for undo, not enabled by default yet because it
needs the .B.blend to be changed.
* Multiple undo for image painting.
* An offset for dupligroups, so not all objects in a group have to
be at the origin.
2008-09-04 20:51:28 +00:00
|
|
|
GPU_extensions_init();
|
Merge of apricot branch game engine changes into trunk, excluding GLSL.
GLEW
====
Added the GLEW opengl extension library into extern/, always compiled
into Blender now. This is much nicer than doing this kind of extension
management manually, and will be used in the game engine, for GLSL, and
other opengl extensions.
* According to the GLEW website it works on Windows, Linux, Mac OS X,
FreeBSD, Irix, and Solaris. There might still be platform specific
issues due to this commit, so let me know and I'll look into it.
* This means also that all extensions will now always be compiled in,
regardless of the glext.h on the platform where compilation happens.
Game Engine
===========
Refactoring of the use of opengl extensions and other drawing code
in the game engine, and cleaning up some hacks related to GLSL
integration. These changes will be merged into trunk too after this.
The game engine graphics demos & apricot level survived my tests,
but this could use some good testing of course.
For users: please test with the options "Generate Display Lists" and
"Vertex Arrays" enabled, these should be the fastest and are supposed
to be "unreliable", but if that's the case that's probably due to bugs
that can be fixed.
* The game engine now also uses GLEW for extensions, replacing the
custom opengl extensions code that was there. Removes a lot of
#ifdef's, but the runtime checks stay of course.
* Removed the WITHOUT_GLEXT environment variable. This was added to
work around a specific bug and only disabled multitexturing anyway.
It might also have caused a slowdown since it was retrieving the
environment variable for every vertex in immediate mode (bug #13680).
* Refactored the code to allow drawing skinned meshes with vertex
arrays too, removing some specific immediate mode drawing functions
for this that only did extra normal calculation. Now it always splits
vertices of flat faces instead.
* Refactored normal recalculation with some minor optimizations,
required for the above change.
* Removed some outdated code behind the __NLA_OLDDEFORM #ifdef.
* Fixed various bugs in setting of multitexture coordinates and vertex
attributes for vertex arrays. These were not being enabled/disabled
correct according to the opengl spec, leading to crashes. Also tangent
attributes used an immediate mode call for vertex arrays, which can't
work.
* Fixed use of uninitialized variable in RAS_TexVert.
* Exporting skinned meshes was doing O(n^2) lookups for vertices and
deform weights, now uses same trick as regular meshes.
2008-06-17 10:27:34 +00:00
|
|
|
bgl::InitExtensions(true);
|
2004-04-24 06:40:15 +00:00
|
|
|
|
2002-10-12 11:37:38 +00:00
|
|
|
// get and set the preferences
|
|
|
|
SYS_SystemHandle syshandle = SYS_GetSystem();
|
2004-04-24 06:40:15 +00:00
|
|
|
if (!syshandle)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
// SYS_WriteCommandLineInt(syshandle, "fixedtime", 0);
|
2012-09-16 04:58:18 +00:00
|
|
|
// SYS_WriteCommandLineInt(syshandle, "vertexarrays",1);
|
2009-08-18 15:27:48 +00:00
|
|
|
GameData *gm= &m_startScene->gm;
|
2004-08-10 11:34:12 +00:00
|
|
|
bool properties = (SYS_GetCommandLineInt(syshandle, "show_properties", 0) != 0);
|
|
|
|
bool profile = (SYS_GetCommandLineInt(syshandle, "show_profile", 0) != 0);
|
2006-07-19 06:39:11 +00:00
|
|
|
|
2009-08-18 15:27:48 +00:00
|
|
|
bool showPhysics = (gm->flag & GAME_SHOW_PHYSICS);
|
2006-12-26 22:02:31 +00:00
|
|
|
SYS_WriteCommandLineInt(syshandle, "show_physics", showPhysics);
|
|
|
|
|
2013-06-22 09:04:33 +00:00
|
|
|
bool fixed_framerate= (SYS_GetCommandLineInt(syshandle, "fixedtime", (gm->flag & GAME_ENABLE_ALL_FRAMES)) != 0);
|
2004-04-24 06:40:15 +00:00
|
|
|
bool frameRate = (SYS_GetCommandLineInt(syshandle, "show_framerate", 0) != 0);
|
2013-09-11 23:24:45 +00:00
|
|
|
bool useLists = (SYS_GetCommandLineInt(syshandle, "displaylists", gm->flag & GAME_DISPLAY_LISTS) != 0) && GPU_display_list_support();
|
2009-04-20 15:06:46 +00:00
|
|
|
bool nodepwarnings = (SYS_GetCommandLineInt(syshandle, "ignore_deprecation_warnings", 1) != 0);
|
2011-08-12 20:53:29 +00:00
|
|
|
bool restrictAnimFPS = gm->flag & GAME_RESTRICT_ANIM_UPDATES;
|
2008-04-16 17:40:59 +00:00
|
|
|
|
2012-03-24 07:52:14 +00:00
|
|
|
if (GLEW_ARB_multitexture && GLEW_VERSION_1_1)
|
2008-09-13 19:19:51 +00:00
|
|
|
m_blendermat = (SYS_GetCommandLineInt(syshandle, "blender_material", 1) != 0);
|
Merge of first part of changes from the apricot branch, especially
the features that are needed to run the game. Compile tested with
scons, make, but not cmake, that seems to have an issue not related
to these changes. The changes include:
* GLSL support in the viewport and game engine, enable in the game
menu in textured draw mode.
* Synced and merged part of the duplicated blender and gameengine/
gameplayer drawing code.
* Further refactoring of game engine drawing code, especially mesh
storage changed a lot.
* Optimizations in game engine armatures to avoid recomputations.
* A python function to get the framerate estimate in game.
* An option take object color into account in materials.
* An option to restrict shadow casters to a lamp's layers.
* Increase from 10 to 18 texture slots for materials, lamps, word.
An extra texture slot shows up once the last slot is used.
* Memory limit for undo, not enabled by default yet because it
needs the .B.blend to be changed.
* Multiple undo for image painting.
* An offset for dupligroups, so not all objects in a group have to
be at the origin.
2008-09-04 20:51:28 +00:00
|
|
|
|
2012-03-24 07:52:14 +00:00
|
|
|
if (GPU_glsl_support())
|
2008-09-13 19:19:51 +00:00
|
|
|
m_blenderglslmat = (SYS_GetCommandLineInt(syshandle, "blender_glsl_material", 1) != 0);
|
2012-03-24 07:52:14 +00:00
|
|
|
else if (m_globalSettings->matmode == GAME_MAT_GLSL)
|
2008-09-13 19:19:51 +00:00
|
|
|
m_blendermat = false;
|
Merge of first part of changes from the apricot branch, especially
the features that are needed to run the game. Compile tested with
scons, make, but not cmake, that seems to have an issue not related
to these changes. The changes include:
* GLSL support in the viewport and game engine, enable in the game
menu in textured draw mode.
* Synced and merged part of the duplicated blender and gameengine/
gameplayer drawing code.
* Further refactoring of game engine drawing code, especially mesh
storage changed a lot.
* Optimizations in game engine armatures to avoid recomputations.
* A python function to get the framerate estimate in game.
* An option take object color into account in materials.
* An option to restrict shadow casters to a lamp's layers.
* Increase from 10 to 18 texture slots for materials, lamps, word.
An extra texture slot shows up once the last slot is used.
* Memory limit for undo, not enabled by default yet because it
needs the .B.blend to be changed.
* Multiple undo for image painting.
* An offset for dupligroups, so not all objects in a group have to
be at the origin.
2008-09-04 20:51:28 +00:00
|
|
|
|
2004-04-24 06:40:15 +00:00
|
|
|
// create the canvas, rasterizer and rendertools
|
|
|
|
m_canvas = new GPG_Canvas(window);
|
|
|
|
if (!m_canvas)
|
|
|
|
return false;
|
2013-07-29 22:31:32 +00:00
|
|
|
|
|
|
|
if (gm->vsync == VSYNC_ADAPTIVE)
|
|
|
|
m_canvas->SetSwapInterval(-1);
|
|
|
|
else
|
2013-08-26 08:14:52 +00:00
|
|
|
m_canvas->SetSwapInterval((gm->vsync == VSYNC_ON) ? 1 : 0);
|
2013-07-29 22:31:32 +00:00
|
|
|
|
2011-01-23 17:25:27 +00:00
|
|
|
m_canvas->Init();
|
|
|
|
if (gm->flag & GAME_SHOW_MOUSE)
|
2012-09-16 04:58:18 +00:00
|
|
|
m_canvas->SetMouseState(RAS_ICanvas::MOUSE_NORMAL);
|
2006-04-02 21:04:20 +00:00
|
|
|
|
2012-12-18 20:56:25 +00:00
|
|
|
//Don't use displaylists with VBOs
|
|
|
|
//If auto starts using VBOs, make sure to check for that here
|
|
|
|
if (useLists && gm->raster_storage != RAS_STORE_VBO)
|
|
|
|
m_rasterizer = new RAS_ListRasterizer(m_canvas, false, gm->raster_storage);
|
2004-04-24 06:40:15 +00:00
|
|
|
else
|
2012-12-18 20:56:25 +00:00
|
|
|
m_rasterizer = new RAS_OpenGLRasterizer(m_canvas, gm->raster_storage);
|
2008-06-29 21:51:27 +00:00
|
|
|
|
2009-12-31 04:56:23 +00:00
|
|
|
/* Stereo parameters - Eye Separation from the UI - stereomode from the command-line/UI */
|
2004-08-10 11:34:12 +00:00
|
|
|
m_rasterizer->SetStereoMode((RAS_IRasterizer::StereoMode) stereoMode);
|
2009-12-31 04:56:23 +00:00
|
|
|
m_rasterizer->SetEyeSeparation(m_startScene->gm.eyeseparation);
|
|
|
|
|
2004-04-24 06:40:15 +00:00
|
|
|
if (!m_rasterizer)
|
|
|
|
goto initFailed;
|
|
|
|
|
|
|
|
// create the inputdevices
|
|
|
|
m_keyboard = new GPG_KeyboardDevice();
|
|
|
|
if (!m_keyboard)
|
|
|
|
goto initFailed;
|
2002-10-12 11:37:38 +00:00
|
|
|
|
2004-04-24 06:40:15 +00:00
|
|
|
m_mouse = new GPC_MouseDevice();
|
|
|
|
if (!m_mouse)
|
|
|
|
goto initFailed;
|
|
|
|
|
|
|
|
// create a networkdevice
|
|
|
|
m_networkdevice = new NG_LoopBackNetworkDeviceInterface();
|
|
|
|
if (!m_networkdevice)
|
|
|
|
goto initFailed;
|
|
|
|
|
2010-10-16 15:00:04 +00:00
|
|
|
sound_init(m_maggie);
|
2009-09-03 02:55:23 +00:00
|
|
|
|
2004-04-24 06:40:15 +00:00
|
|
|
// 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);
|
2009-09-04 20:03:27 +00:00
|
|
|
|
Cucumber, first batch of merge - UI changes and custom exit key
---------------------------------------------------------------
This was a test drive to see how painful the merge will be.
Next batches are:
- use desktop option for fullscreen
- multisampling option
- bullet collision mask
- python
- storage (vbo, dl, ...)
- lighting
[lighting still needs review]
[python could use review, although it should be straightforward]
[storage should be tested more I think]
Merged /branches/soc-2011-cucumber:r
36991,37059,37157,37416,37497-37499,37501,37522,39036,40593
36991:
==UI==
* Made some options available in Blender Game that were only available in Blender Render (camera resolution, animation fps)
* Created a panel for the embedded player
* Renamed the FPS option for the standalone player to Refresh Rate
* Moved framing options to display
* Made a button to launch the blender player from within blender (only tested on windows for now)
37059:
==UI==
* Added the option to change the exit key for the BGE. The UI currently just sets a number, and this feature most likely does not work for blenderplayer yet. More work on this to come.
* Removed the physics settings from the scene panel for the BGE.
* Added an Add menu in the logic brick header.
37157:
Making the bake options available in Blender Game
37416:
Making the exit key UI element accept key presses instead of numbers. It still does not work for the Blenderplayer, and it does not limit the input to key presses (other events don't work for exiting)
37497:
Some more work on getting the exit key to work in the Blenderplayer.
Input is now restricted to keyboard events only for the exit key UI.
37498:
Some clean up from the last commit.
The exit key setting affects the Blenderplayer now.
37499:
Cleaning up some duplicate code. Now the reverseTranslateTable for converting blender key codes to ketsji key codes is only defined in BL_BlenderDataConverter.
37501:
Centralizing the exit key methods to the keyboard devices. This should make it easier to get exit key control to the python API.
[37517: committed previously]
37522:
Moved control of the exit key away from the keyboard devices, and moved it to ketsjiengine.
Added setExitKey and getExitKey to the python API
39036:
A couple of the doversions were in the wrong spot. This should fix some issues with the exit key not being set.
[not committed entirely, see below]]
40552: space_logic.py (* fixed an error in space_logic.py *)
40593:
launch blenderplayer from ui not working in OSX fix - by Daniel Stokes and me
########################################################
code left behind (to be included in next commit):
########################################################
{
/* Initialize default values for collision masks */
Object *ob;
for(ob=main->object.first; ob; ob=ob->id.next)
ob->col_group = ob->col_mask = 1;
}
2011-12-20 03:11:56 +00:00
|
|
|
KX_KetsjiEngine::SetExitKey(ConvertKeyCode(gm->exitkey));
|
2010-11-05 01:47:55 +00:00
|
|
|
#ifdef WITH_PYTHON
|
2009-01-26 08:34:40 +00:00
|
|
|
CValue::SetDeprecationWarnings(nodepwarnings);
|
2010-11-05 01:47:55 +00:00
|
|
|
#else
|
|
|
|
(void)nodepwarnings;
|
|
|
|
#endif
|
2009-01-26 08:34:40 +00:00
|
|
|
|
2006-05-19 22:55:12 +00:00
|
|
|
m_ketsjiengine->SetUseFixedTime(fixed_framerate);
|
2004-08-10 11:34:12 +00:00
|
|
|
m_ketsjiengine->SetTimingDisplay(frameRate, profile, properties);
|
2011-08-12 20:53:29 +00:00
|
|
|
m_ketsjiengine->SetRestrictAnimationFPS(restrictAnimFPS);
|
2004-04-24 06:40:15 +00:00
|
|
|
|
2011-09-11 05:54:07 +00:00
|
|
|
//set the global settings (carried over if restart/load new files)
|
|
|
|
m_ketsjiengine->SetGlobalSettings(m_globalSettings);
|
|
|
|
|
2004-04-24 06:40:15 +00:00
|
|
|
m_engineInitialized = true;
|
2002-10-12 11:37:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return m_engineInitialized;
|
2004-04-24 06:40:15 +00:00
|
|
|
initFailed:
|
2009-09-04 20:03:27 +00:00
|
|
|
sound_exit();
|
2004-04-24 06:40:15 +00:00
|
|
|
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;
|
2002-10-12 11:37:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
bool GPG_Application::startEngine(void)
|
|
|
|
{
|
|
|
|
if (m_engineRunning) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Temporary hack to disable banner display for NaN approved content.
|
2004-04-24 06:40:15 +00:00
|
|
|
/*
|
2012-09-16 04:58:18 +00:00
|
|
|
m_canvas->SetBannerDisplayEnabled(true);
|
2004-04-24 06:40:15 +00:00
|
|
|
Camera* cam;
|
2009-01-04 14:14:06 +00:00
|
|
|
cam = (Camera*)scene->camera->data;
|
2002-10-12 11:37:38 +00:00
|
|
|
if (cam) {
|
2004-04-24 06:40:15 +00:00
|
|
|
if (((cam->flag) & 48)==48) {
|
|
|
|
m_canvas->SetBannerDisplayEnabled(false);
|
|
|
|
}
|
2002-10-12 11:37:38 +00:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
showError(CString("Camera data invalid."));
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
*/
|
|
|
|
|
|
|
|
// create a scene converter, create and convert the stratingscene
|
2009-06-13 13:02:01 +00:00
|
|
|
m_sceneconverter = new KX_BlenderSceneConverter(m_maggie, m_ketsjiengine);
|
2002-10-12 11:37:38 +00:00
|
|
|
if (m_sceneconverter)
|
|
|
|
{
|
|
|
|
STR_String startscenename = m_startSceneName.Ptr();
|
|
|
|
m_ketsjiengine->SetSceneConverter(m_sceneconverter);
|
2008-09-13 19:19:51 +00:00
|
|
|
|
2002-10-12 11:37:38 +00:00
|
|
|
// if (always_use_expand_framing)
|
|
|
|
// sceneconverter->SetAlwaysUseExpandFraming(true);
|
2013-11-04 19:21:50 +00:00
|
|
|
if (m_blendermat)
|
2006-01-06 03:46:54 +00:00
|
|
|
m_sceneconverter->SetMaterials(true);
|
2012-03-24 07:52:14 +00:00
|
|
|
if (m_blenderglslmat && (m_globalSettings->matmode == GAME_MAT_GLSL))
|
Merge of apricot branch game engine changes into trunk, excluding GLSL.
GLEW
====
Added the GLEW opengl extension library into extern/, always compiled
into Blender now. This is much nicer than doing this kind of extension
management manually, and will be used in the game engine, for GLSL, and
other opengl extensions.
* According to the GLEW website it works on Windows, Linux, Mac OS X,
FreeBSD, Irix, and Solaris. There might still be platform specific
issues due to this commit, so let me know and I'll look into it.
* This means also that all extensions will now always be compiled in,
regardless of the glext.h on the platform where compilation happens.
Game Engine
===========
Refactoring of the use of opengl extensions and other drawing code
in the game engine, and cleaning up some hacks related to GLSL
integration. These changes will be merged into trunk too after this.
The game engine graphics demos & apricot level survived my tests,
but this could use some good testing of course.
For users: please test with the options "Generate Display Lists" and
"Vertex Arrays" enabled, these should be the fastest and are supposed
to be "unreliable", but if that's the case that's probably due to bugs
that can be fixed.
* The game engine now also uses GLEW for extensions, replacing the
custom opengl extensions code that was there. Removes a lot of
#ifdef's, but the runtime checks stay of course.
* Removed the WITHOUT_GLEXT environment variable. This was added to
work around a specific bug and only disabled multitexturing anyway.
It might also have caused a slowdown since it was retrieving the
environment variable for every vertex in immediate mode (bug #13680).
* Refactored the code to allow drawing skinned meshes with vertex
arrays too, removing some specific immediate mode drawing functions
for this that only did extra normal calculation. Now it always splits
vertices of flat faces instead.
* Refactored normal recalculation with some minor optimizations,
required for the above change.
* Removed some outdated code behind the __NLA_OLDDEFORM #ifdef.
* Fixed various bugs in setting of multitexture coordinates and vertex
attributes for vertex arrays. These were not being enabled/disabled
correct according to the opengl spec, leading to crashes. Also tangent
attributes used an immediate mode call for vertex arrays, which can't
work.
* Fixed use of uninitialized variable in RAS_TexVert.
* Exporting skinned meshes was doing O(n^2) lookups for vertices and
deform weights, now uses same trick as regular meshes.
2008-06-17 10:27:34 +00:00
|
|
|
m_sceneconverter->SetGLSLMaterials(true);
|
2012-12-24 03:13:53 +00:00
|
|
|
if (m_startScene->gm.flag & GAME_NO_MATERIAL_CACHING)
|
|
|
|
m_sceneconverter->SetCacheMaterials(false);
|
2002-10-12 11:37:38 +00:00
|
|
|
|
|
|
|
KX_Scene* startscene = new KX_Scene(m_keyboard,
|
|
|
|
m_mouse,
|
|
|
|
m_networkdevice,
|
Merge of first part of changes from the apricot branch, especially
the features that are needed to run the game. Compile tested with
scons, make, but not cmake, that seems to have an issue not related
to these changes. The changes include:
* GLSL support in the viewport and game engine, enable in the game
menu in textured draw mode.
* Synced and merged part of the duplicated blender and gameengine/
gameplayer drawing code.
* Further refactoring of game engine drawing code, especially mesh
storage changed a lot.
* Optimizations in game engine armatures to avoid recomputations.
* A python function to get the framerate estimate in game.
* An option take object color into account in materials.
* An option to restrict shadow casters to a lamp's layers.
* Increase from 10 to 18 texture slots for materials, lamps, word.
An extra texture slot shows up once the last slot is used.
* Memory limit for undo, not enabled by default yet because it
needs the .B.blend to be changed.
* Multiple undo for image painting.
* An offset for dupligroups, so not all objects in a group have to
be at the origin.
2008-09-04 20:51:28 +00:00
|
|
|
startscenename,
|
2010-04-23 22:48:26 +00:00
|
|
|
m_startScene,
|
|
|
|
m_canvas);
|
2002-10-12 11:37:38 +00:00
|
|
|
|
2010-10-31 04:11:39 +00:00
|
|
|
#ifdef WITH_PYTHON
|
2010-01-10 22:03:26 +00:00
|
|
|
// some python things
|
|
|
|
PyObject *gameLogic, *gameLogic_keys;
|
|
|
|
setupGamePython(m_ketsjiengine, startscene, m_maggie, NULL, &gameLogic, &gameLogic_keys, m_argc, m_argv);
|
2010-10-31 04:11:39 +00:00
|
|
|
#endif // WITH_PYTHON
|
2009-04-20 15:06:46 +00:00
|
|
|
|
|
|
|
//initialize Dome Settings
|
2012-03-24 07:52:14 +00:00
|
|
|
if (m_startScene->gm.stereoflag == STEREO_DOME)
|
2009-07-20 20:28:29 +00:00
|
|
|
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);
|
2009-04-20 15:06:46 +00:00
|
|
|
|
2013-07-19 23:31:45 +00:00
|
|
|
// initialize 3D Audio Settings
|
|
|
|
AUD_I3DDevice* dev = AUD_get3DDevice();
|
|
|
|
if (dev)
|
|
|
|
{
|
|
|
|
dev->setSpeedOfSound(m_startScene->audio.speed_of_sound);
|
|
|
|
dev->setDopplerFactor(m_startScene->audio.doppler_factor);
|
|
|
|
dev->setDistanceModel(AUD_DistanceModel(m_startScene->audio.distance_model));
|
|
|
|
}
|
|
|
|
|
2010-11-05 01:47:55 +00:00
|
|
|
#ifdef WITH_PYTHON
|
2008-09-16 19:25:35 +00:00
|
|
|
// Set the GameLogic.globalDict from marshal'd data, so we can
|
|
|
|
// load new blend files and keep data in GameLogic.globalDict
|
2008-09-12 02:15:16 +00:00
|
|
|
loadGamePythonConfig(m_pyGlobalDictString, m_pyGlobalDictString_Length);
|
2012-09-16 04:58:18 +00:00
|
|
|
#endif
|
2002-10-12 11:37:38 +00:00
|
|
|
m_sceneconverter->ConvertScene(
|
|
|
|
startscene,
|
2013-11-04 19:21:07 +00:00
|
|
|
m_rasterizer,
|
2002-10-12 11:37:38 +00:00
|
|
|
m_canvas);
|
|
|
|
m_ketsjiengine->AddScene(startscene);
|
|
|
|
|
|
|
|
// Create a timer that is used to kick the engine
|
|
|
|
if (!m_frameTimer) {
|
|
|
|
m_frameTimer = m_system->installTimer(0, kTimerFreq, frameTimerProc, m_mainWindow);
|
|
|
|
}
|
|
|
|
m_rasterizer->Init();
|
2006-11-30 00:19:27 +00:00
|
|
|
m_ketsjiengine->StartEngine(true);
|
2002-10-12 11:37:38 +00:00
|
|
|
m_engineRunning = true;
|
|
|
|
|
2008-08-06 04:09:10 +00:00
|
|
|
// 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
|
2010-02-22 12:25:58 +00:00
|
|
|
Scene *scene= startscene->GetBlenderScene(); // needed for macro
|
|
|
|
m_ketsjiengine->SetAnimFrameRate(FPS);
|
2002-10-12 11:37:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!m_engineRunning)
|
|
|
|
{
|
|
|
|
stopEngine();
|
|
|
|
}
|
|
|
|
|
|
|
|
return m_engineRunning;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void GPG_Application::stopEngine()
|
|
|
|
{
|
2010-11-05 01:47:55 +00:00
|
|
|
#ifdef WITH_PYTHON
|
2008-09-16 19:25:35 +00:00
|
|
|
// 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.
|
2012-03-24 07:52:14 +00:00
|
|
|
if (m_pyGlobalDictString) {
|
2008-09-17 01:29:54 +00:00
|
|
|
delete [] m_pyGlobalDictString;
|
2008-09-16 19:25:35 +00:00
|
|
|
m_pyGlobalDictString = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
m_pyGlobalDictString_Length = saveGamePythonConfig(&m_pyGlobalDictString);
|
2010-11-05 01:47:55 +00:00
|
|
|
#endif
|
|
|
|
|
2002-10-12 11:37:38 +00:00
|
|
|
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;
|
|
|
|
}
|
2013-08-06 02:05:32 +00:00
|
|
|
|
2002-10-12 11:37:38 +00:00
|
|
|
m_engineRunning = false;
|
|
|
|
}
|
|
|
|
|
2012-08-18 23:46:37 +00:00
|
|
|
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();
|
|
|
|
}
|
2002-10-12 11:37:38 +00:00
|
|
|
|
|
|
|
void GPG_Application::exitEngine()
|
|
|
|
{
|
2011-12-23 07:10:01 +00:00
|
|
|
// We only want to kill the engine if it has been initialized
|
|
|
|
if (!m_engineInitialized)
|
|
|
|
return;
|
|
|
|
|
2009-09-04 20:03:27 +00:00
|
|
|
sound_exit();
|
2002-10-12 11:37:38 +00:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2008-09-26 14:54:21 +00:00
|
|
|
GPU_extensions_exit();
|
|
|
|
|
2013-08-06 02:05:32 +00:00
|
|
|
#ifdef WITH_PYTHON
|
|
|
|
// Call this after we're sure nothing needs Python anymore (e.g., destructors)
|
|
|
|
exitGamePlayerPythonScripting();
|
|
|
|
#endif
|
|
|
|
|
2002-10-12 11:37:38 +00:00
|
|
|
m_exitRequested = 0;
|
|
|
|
m_engineInitialized = false;
|
|
|
|
}
|
|
|
|
|
2004-05-02 23:45:03 +00:00
|
|
|
bool GPG_Application::handleWheel(GHOST_IEvent* event)
|
|
|
|
{
|
|
|
|
bool handled = false;
|
2005-03-25 10:33:39 +00:00
|
|
|
MT_assert(event);
|
2004-05-02 23:45:03 +00:00
|
|
|
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;
|
|
|
|
}
|
2002-10-12 11:37:38 +00:00
|
|
|
|
|
|
|
bool GPG_Application::handleButton(GHOST_IEvent* event, bool isDown)
|
|
|
|
{
|
|
|
|
bool handled = false;
|
2005-03-25 10:33:39 +00:00
|
|
|
MT_assert(event);
|
2002-10-12 11:37:38 +00:00
|
|
|
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;
|
2005-03-25 10:33:39 +00:00
|
|
|
MT_assert(event);
|
2002-10-12 11:37:38 +00:00
|
|
|
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;
|
2005-03-25 10:33:39 +00:00
|
|
|
MT_assert(event);
|
2002-10-12 11:37:38 +00:00
|
|
|
if (m_keyboard)
|
|
|
|
{
|
|
|
|
GHOST_TEventDataPtr eventData = ((GHOST_IEvent*)event)->getData();
|
|
|
|
GHOST_TEventKeyData* keyData = static_cast<GHOST_TEventKeyData*>(eventData);
|
Cucumber, first batch of merge - UI changes and custom exit key
---------------------------------------------------------------
This was a test drive to see how painful the merge will be.
Next batches are:
- use desktop option for fullscreen
- multisampling option
- bullet collision mask
- python
- storage (vbo, dl, ...)
- lighting
[lighting still needs review]
[python could use review, although it should be straightforward]
[storage should be tested more I think]
Merged /branches/soc-2011-cucumber:r
36991,37059,37157,37416,37497-37499,37501,37522,39036,40593
36991:
==UI==
* Made some options available in Blender Game that were only available in Blender Render (camera resolution, animation fps)
* Created a panel for the embedded player
* Renamed the FPS option for the standalone player to Refresh Rate
* Moved framing options to display
* Made a button to launch the blender player from within blender (only tested on windows for now)
37059:
==UI==
* Added the option to change the exit key for the BGE. The UI currently just sets a number, and this feature most likely does not work for blenderplayer yet. More work on this to come.
* Removed the physics settings from the scene panel for the BGE.
* Added an Add menu in the logic brick header.
37157:
Making the bake options available in Blender Game
37416:
Making the exit key UI element accept key presses instead of numbers. It still does not work for the Blenderplayer, and it does not limit the input to key presses (other events don't work for exiting)
37497:
Some more work on getting the exit key to work in the Blenderplayer.
Input is now restricted to keyboard events only for the exit key UI.
37498:
Some clean up from the last commit.
The exit key setting affects the Blenderplayer now.
37499:
Cleaning up some duplicate code. Now the reverseTranslateTable for converting blender key codes to ketsji key codes is only defined in BL_BlenderDataConverter.
37501:
Centralizing the exit key methods to the keyboard devices. This should make it easier to get exit key control to the python API.
[37517: committed previously]
37522:
Moved control of the exit key away from the keyboard devices, and moved it to ketsjiengine.
Added setExitKey and getExitKey to the python API
39036:
A couple of the doversions were in the wrong spot. This should fix some issues with the exit key not being set.
[not committed entirely, see below]]
40552: space_logic.py (* fixed an error in space_logic.py *)
40593:
launch blenderplayer from ui not working in OSX fix - by Daniel Stokes and me
########################################################
code left behind (to be included in next commit):
########################################################
{
/* Initialize default values for collision masks */
Object *ob;
for(ob=main->object.first; ob; ob=ob->id.next)
ob->col_group = ob->col_mask = 1;
}
2011-12-20 03:11:56 +00:00
|
|
|
|
|
|
|
if (m_keyboard->ToNative(keyData->key) == KX_KetsjiEngine::GetExitKey() && !m_keyboard->m_hookesc && !m_isEmbedded) {
|
|
|
|
m_exitRequested = KX_EXIT_REQUEST_OUTSIDE;
|
|
|
|
}
|
2002-10-12 11:37:38 +00:00
|
|
|
m_keyboard->ConvertEvent(keyData->key, isDown);
|
|
|
|
handled = true;
|
|
|
|
}
|
|
|
|
return handled;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static void frameTimerProc(GHOST_ITimerTask* task, GHOST_TUns64 time)
|
|
|
|
{
|
|
|
|
GHOST_IWindow* window = (GHOST_IWindow*)task->getUserData();
|
|
|
|
if (fSystem->validWindow(window)) {
|
|
|
|
window->invalidate();
|
|
|
|
}
|
|
|
|
}
|