2002-10-12 11:37:38 +00:00
|
|
|
/**
|
|
|
|
* $Id$
|
|
|
|
*
|
2008-01-07 19:13:47 +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-01-07 19:13:47 +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,
|
|
|
|
* 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.
|
|
|
|
*
|
2008-01-07 19:13:47 +00:00
|
|
|
* ***** END GPL LICENSE BLOCK *****
|
2002-10-12 11:37:38 +00:00
|
|
|
* Blender's Ketsji startpoint
|
|
|
|
*/
|
|
|
|
|
2002-11-25 15:29:57 +00:00
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
#include <config.h>
|
|
|
|
#endif
|
|
|
|
|
2004-10-16 11:41:50 +00:00
|
|
|
#include <signal.h>
|
2008-04-16 17:40:59 +00:00
|
|
|
#include <stdlib.h>
|
2004-10-16 11:41:50 +00:00
|
|
|
|
2002-10-12 11:37:38 +00:00
|
|
|
#ifdef WIN32
|
|
|
|
// don't show stl-warnings
|
|
|
|
#pragma warning (disable:4786)
|
|
|
|
#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"
|
2006-01-16 22:27:30 +00:00
|
|
|
|
2002-10-12 11:37:38 +00:00
|
|
|
#include "KX_BlenderGL.h"
|
|
|
|
#include "KX_BlenderCanvas.h"
|
|
|
|
#include "KX_BlenderKeyboardDevice.h"
|
|
|
|
#include "KX_BlenderMouseDevice.h"
|
|
|
|
#include "KX_BlenderRenderTools.h"
|
|
|
|
#include "KX_BlenderSystem.h"
|
2006-01-06 03:46:54 +00:00
|
|
|
#include "BL_Material.h"
|
2002-10-12 11:37:38 +00:00
|
|
|
|
|
|
|
#include "KX_KetsjiEngine.h"
|
|
|
|
#include "KX_BlenderSceneConverter.h"
|
|
|
|
#include "KX_PythonInit.h"
|
|
|
|
#include "KX_PyConstraintBinding.h"
|
|
|
|
|
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 "RAS_GLExtensionManager.h"
|
2002-10-12 11:37:38 +00:00
|
|
|
#include "RAS_OpenGLRasterizer.h"
|
|
|
|
#include "RAS_VAOpenGLRasterizer.h"
|
2006-04-02 21:04:20 +00:00
|
|
|
#include "RAS_ListRasterizer.h"
|
2002-10-12 11:37:38 +00:00
|
|
|
|
|
|
|
#include "NG_LoopBackNetworkDeviceInterface.h"
|
|
|
|
#include "SND_DeviceManager.h"
|
|
|
|
|
|
|
|
#include "SYS_System.h"
|
|
|
|
|
|
|
|
/***/
|
|
|
|
|
|
|
|
#include "DNA_view3d_types.h"
|
|
|
|
#include "DNA_screen_types.h"
|
|
|
|
#include "BKE_global.h"
|
2008-10-11 00:56:49 +00:00
|
|
|
#include "BKE_utildefines.h"
|
2008-01-01 19:20:49 +00:00
|
|
|
//XXX #include "BIF_screen.h"
|
|
|
|
//XXX #include "BIF_scrarea.h"
|
2002-10-12 11:37:38 +00:00
|
|
|
|
|
|
|
#include "BKE_main.h"
|
|
|
|
#include "BLI_blenlib.h"
|
|
|
|
#include "BLO_readfile.h"
|
|
|
|
#include "DNA_scene_types.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"
|
|
|
|
|
2006-12-16 05:50:38 +00:00
|
|
|
#ifdef __cplusplus
|
|
|
|
extern "C" {
|
|
|
|
#endif
|
2008-01-01 19:20:49 +00:00
|
|
|
//XXX #include "BSE_headerbuttons.h"
|
2006-12-16 05:50:38 +00:00
|
|
|
void update_for_newframe();
|
|
|
|
#ifdef __cplusplus
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2002-10-12 11:37:38 +00:00
|
|
|
static BlendFileData *load_game_data(char *filename) {
|
|
|
|
BlendReadError error;
|
2008-08-18 23:48:59 +00:00
|
|
|
BlendFileData *bfd= BLO_read_from_file(filename, &error);
|
2002-10-12 11:37:38 +00:00
|
|
|
if (!bfd) {
|
|
|
|
printf("Loading %s failed: %s\n", filename, BLO_bre_as_string(error));
|
|
|
|
}
|
|
|
|
return bfd;
|
|
|
|
}
|
|
|
|
|
|
|
|
extern "C" void StartKetsjiShell(struct ScrArea *area,
|
|
|
|
char* scenename,
|
2006-05-22 21:03:43 +00:00
|
|
|
struct Main* maggie1,
|
2005-08-23 13:16:02 +00:00
|
|
|
struct SpaceIpo *sipo,
|
2002-10-12 11:37:38 +00:00
|
|
|
int always_use_expand_framing)
|
|
|
|
{
|
|
|
|
int exitrequested = KX_EXIT_REQUEST_NO_REQUEST;
|
2005-08-23 13:16:02 +00:00
|
|
|
|
2006-05-22 21:03:43 +00:00
|
|
|
Main* blenderdata = maggie1;
|
2005-08-23 13:16:02 +00:00
|
|
|
|
2002-10-12 11:37:38 +00:00
|
|
|
char* startscenename = scenename;
|
2008-10-11 00:56:49 +00:00
|
|
|
char pathname[FILE_MAXDIR+FILE_MAXFILE], oldsce[FILE_MAXDIR+FILE_MAXFILE];
|
2002-10-12 11:37:38 +00:00
|
|
|
STR_String exitstring = "";
|
|
|
|
BlendFileData *bfd= NULL;
|
2006-01-06 03:46:54 +00:00
|
|
|
|
2008-10-11 00:56:49 +00:00
|
|
|
BLI_strncpy(pathname, blenderdata->name, sizeof(pathname));
|
|
|
|
BLI_strncpy(oldsce, G.sce, sizeof(oldsce));
|
|
|
|
setGamePythonPath(G.sce);
|
|
|
|
|
2008-02-23 12:05:28 +00:00
|
|
|
// Acquire Python's GIL (global interpreter lock)
|
|
|
|
// so we can safely run Python code and API calls
|
|
|
|
PyGILState_STATE gilstate = PyGILState_Ensure();
|
2008-08-19 11:53:24 +00:00
|
|
|
|
|
|
|
PyObject *pyGlobalDict = PyDict_New(); /* python utility storage, spans blend file loading */
|
2004-10-16 11:41:50 +00:00
|
|
|
|
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);
|
|
|
|
|
2002-10-12 11:37:38 +00:00
|
|
|
do
|
|
|
|
{
|
|
|
|
View3D *v3d= (View3D*) area->spacedata.first;
|
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
|
|
|
|
2002-10-12 11:37:38 +00:00
|
|
|
// get some preferences
|
|
|
|
SYS_SystemHandle syshandle = SYS_GetSystem();
|
|
|
|
bool properties = (SYS_GetCommandLineInt(syshandle, "show_properties", 0) != 0);
|
|
|
|
bool usefixed = (SYS_GetCommandLineInt(syshandle, "fixedtime", 0) != 0);
|
|
|
|
bool profile = (SYS_GetCommandLineInt(syshandle, "show_profile", 0) != 0);
|
|
|
|
bool frameRate = (SYS_GetCommandLineInt(syshandle, "show_framerate", 0) != 0);
|
2005-08-23 13:16:02 +00:00
|
|
|
bool game2ipo = (SYS_GetCommandLineInt(syshandle, "game2ipo", 0) != 0);
|
2006-04-02 21:04:20 +00:00
|
|
|
bool displaylists = (SYS_GetCommandLineInt(syshandle, "displaylists", 0) != 0);
|
2005-08-23 13:16:02 +00:00
|
|
|
|
2002-10-12 11:37:38 +00:00
|
|
|
// create the canvas, rasterizer and rendertools
|
|
|
|
RAS_ICanvas* canvas = new KX_BlenderCanvas(area);
|
|
|
|
canvas->SetMouseState(RAS_ICanvas::MOUSE_INVISIBLE);
|
|
|
|
RAS_IRenderTools* rendertools = new KX_BlenderRenderTools();
|
|
|
|
RAS_IRasterizer* rasterizer = NULL;
|
|
|
|
|
2008-06-29 21:51:27 +00:00
|
|
|
if(displaylists) {
|
|
|
|
if (GLEW_VERSION_1_1)
|
|
|
|
rasterizer = new RAS_ListRasterizer(canvas, true, true);
|
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
|
|
|
else
|
2007-11-06 18:39:16 +00:00
|
|
|
rasterizer = new RAS_ListRasterizer(canvas);
|
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
|
|
|
}
|
2008-06-29 21:51:27 +00:00
|
|
|
else if (GLEW_VERSION_1_1)
|
|
|
|
rasterizer = new RAS_VAOpenGLRasterizer(canvas, false);
|
2002-10-12 11:37:38 +00:00
|
|
|
else
|
|
|
|
rasterizer = new RAS_OpenGLRasterizer(canvas);
|
|
|
|
|
|
|
|
// create the inputdevices
|
|
|
|
KX_BlenderKeyboardDevice* keyboarddevice = new KX_BlenderKeyboardDevice();
|
|
|
|
KX_BlenderMouseDevice* mousedevice = new KX_BlenderMouseDevice();
|
|
|
|
|
|
|
|
// create a networkdevice
|
|
|
|
NG_NetworkDeviceInterface* networkdevice = new
|
|
|
|
NG_LoopBackNetworkDeviceInterface();
|
|
|
|
|
2008-09-28 03:07:13 +00:00
|
|
|
//
|
|
|
|
SYS_SystemHandle hSystem = SYS_GetSystem();
|
|
|
|
bool noaudio = SYS_GetCommandLineInt(hSystem,"noaudio",0);
|
|
|
|
|
|
|
|
if (noaudio)/*(noaudio) intrr: disable game engine audio (openal) */
|
|
|
|
SND_DeviceManager::SetDeviceType(snd_e_dummydevice);
|
|
|
|
|
2002-10-12 11:37:38 +00:00
|
|
|
// get an audiodevice
|
|
|
|
SND_DeviceManager::Subscribe();
|
|
|
|
SND_IAudioDevice* audiodevice = SND_DeviceManager::Instance();
|
|
|
|
audiodevice->UseCD();
|
|
|
|
|
|
|
|
// create a ketsji/blendersystem (only needed for timing and stuff)
|
|
|
|
KX_BlenderSystem* kxsystem = new KX_BlenderSystem();
|
|
|
|
|
|
|
|
// create the ketsjiengine
|
|
|
|
KX_KetsjiEngine* ketsjiengine = new KX_KetsjiEngine(kxsystem);
|
|
|
|
|
|
|
|
// set the devices
|
|
|
|
ketsjiengine->SetKeyboardDevice(keyboarddevice);
|
|
|
|
ketsjiengine->SetMouseDevice(mousedevice);
|
|
|
|
ketsjiengine->SetNetworkDevice(networkdevice);
|
|
|
|
ketsjiengine->SetCanvas(canvas);
|
|
|
|
ketsjiengine->SetRenderTools(rendertools);
|
|
|
|
ketsjiengine->SetRasterizer(rasterizer);
|
|
|
|
ketsjiengine->SetNetworkDevice(networkdevice);
|
|
|
|
ketsjiengine->SetAudioDevice(audiodevice);
|
|
|
|
ketsjiengine->SetUseFixedTime(usefixed);
|
|
|
|
ketsjiengine->SetTimingDisplay(frameRate, profile, properties);
|
2005-08-23 13:16:02 +00:00
|
|
|
|
2008-10-10 07:20:42 +00:00
|
|
|
|
|
|
|
//lock frame and camera enabled - storing global values
|
|
|
|
int tmp_lay= G.scene->lay;
|
|
|
|
Object *tmp_camera = G.scene->camera;
|
|
|
|
|
|
|
|
if (G.vd->scenelock==0){
|
|
|
|
G.scene->lay= v3d->lay;
|
|
|
|
G.scene->camera= v3d->camera;
|
|
|
|
}
|
|
|
|
|
2005-08-23 13:16:02 +00:00
|
|
|
|
2002-10-12 11:37:38 +00:00
|
|
|
// some blender stuff
|
|
|
|
MT_CmMatrix4x4 projmat;
|
|
|
|
MT_CmMatrix4x4 viewmat;
|
2008-09-15 00:11:30 +00:00
|
|
|
float camzoom;
|
2002-10-12 11:37:38 +00:00
|
|
|
int i;
|
|
|
|
|
|
|
|
for (i = 0; i < 16; i++)
|
|
|
|
{
|
|
|
|
float *viewmat_linear= (float*) v3d->viewmat;
|
|
|
|
viewmat.setElem(i, viewmat_linear[i]);
|
|
|
|
}
|
|
|
|
for (i = 0; i < 16; i++)
|
|
|
|
{
|
2008-01-17 17:15:44 +00:00
|
|
|
float *projmat_linear; //XXX = (float*) area->winmat;
|
2002-10-12 11:37:38 +00:00
|
|
|
projmat.setElem(i, projmat_linear[i]);
|
|
|
|
}
|
|
|
|
|
2008-09-15 00:11:30 +00:00
|
|
|
if(v3d->persp==V3D_CAMOB) {
|
|
|
|
camzoom = (1.41421 + (v3d->camzoom / 50.0));
|
|
|
|
camzoom *= camzoom;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
camzoom = 2.0;
|
|
|
|
|
2002-10-12 11:37:38 +00:00
|
|
|
camzoom = 4.0 / camzoom;
|
|
|
|
|
|
|
|
ketsjiengine->SetDrawType(v3d->drawtype);
|
|
|
|
ketsjiengine->SetCameraZoom(camzoom);
|
|
|
|
|
|
|
|
// if we got an exitcode 3 (KX_EXIT_REQUEST_START_OTHER_GAME) load a different file
|
|
|
|
if (exitrequested == KX_EXIT_REQUEST_START_OTHER_GAME || exitrequested == KX_EXIT_REQUEST_RESTART_GAME)
|
|
|
|
{
|
|
|
|
exitrequested = KX_EXIT_REQUEST_NO_REQUEST;
|
|
|
|
if (bfd) BLO_blendfiledata_free(bfd);
|
|
|
|
|
2008-03-30 16:18:01 +00:00
|
|
|
char basedpath[240];
|
2002-10-12 11:37:38 +00:00
|
|
|
// base the actuator filename with respect
|
|
|
|
// to the original file working directory
|
2008-10-11 00:56:49 +00:00
|
|
|
|
2002-10-12 11:37:38 +00:00
|
|
|
if (exitstring != "")
|
|
|
|
strcpy(basedpath, exitstring.Ptr());
|
|
|
|
|
2008-10-11 00:56:49 +00:00
|
|
|
// load relative to the last loaded file, this used to be relative
|
|
|
|
// to the first file but that makes no sense, relative paths in
|
|
|
|
// blend files should be relative to that file, not some other file
|
|
|
|
// that happened to be loaded first
|
2008-05-04 11:09:30 +00:00
|
|
|
BLI_convertstringcode(basedpath, pathname);
|
2002-10-12 11:37:38 +00:00
|
|
|
bfd = load_game_data(basedpath);
|
|
|
|
|
|
|
|
// if it wasn't loaded, try it forced relative
|
|
|
|
if (!bfd)
|
|
|
|
{
|
|
|
|
// just add "//" in front of it
|
2008-03-30 16:18:01 +00:00
|
|
|
char temppath[242];
|
2002-10-12 11:37:38 +00:00
|
|
|
strcpy(temppath, "//");
|
|
|
|
strcat(temppath, basedpath);
|
|
|
|
|
2008-05-04 11:09:30 +00:00
|
|
|
BLI_convertstringcode(temppath, pathname);
|
2002-10-12 11:37:38 +00:00
|
|
|
bfd = load_game_data(temppath);
|
|
|
|
}
|
|
|
|
|
|
|
|
// if we got a loaded blendfile, proceed
|
|
|
|
if (bfd)
|
|
|
|
{
|
|
|
|
blenderdata = bfd->main;
|
|
|
|
startscenename = bfd->curscene->id.name + 2;
|
2008-10-11 00:56:49 +00:00
|
|
|
|
|
|
|
if(blenderdata) {
|
|
|
|
BLI_strncpy(G.sce, blenderdata->name, sizeof(G.sce));
|
|
|
|
BLI_strncpy(pathname, blenderdata->name, sizeof(pathname));
|
|
|
|
}
|
2002-10-12 11:37:38 +00:00
|
|
|
}
|
|
|
|
// else forget it, we can't find it
|
|
|
|
else
|
|
|
|
{
|
|
|
|
exitrequested = KX_EXIT_REQUEST_QUIT_GAME;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-10-16 11:41:50 +00:00
|
|
|
Scene *blscene = NULL;
|
|
|
|
if (!bfd)
|
|
|
|
{
|
2006-05-22 21:03:43 +00:00
|
|
|
blscene = (Scene*) blenderdata->scene.first;
|
|
|
|
for (Scene *sce= (Scene*) blenderdata->scene.first; sce; sce= (Scene*) sce->id.next)
|
2004-10-16 11:41:50 +00:00
|
|
|
{
|
|
|
|
if (startscenename == (sce->id.name+2))
|
|
|
|
{
|
|
|
|
blscene = sce;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
blscene = bfd->curscene;
|
|
|
|
}
|
|
|
|
|
2005-08-23 13:16:02 +00:00
|
|
|
if (blscene)
|
|
|
|
{
|
|
|
|
int startFrame = blscene->r.cfra;
|
|
|
|
ketsjiengine->SetGame2IpoMode(game2ipo,startFrame);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2004-10-16 11:41:50 +00:00
|
|
|
// Quad buffered needs a special window.
|
|
|
|
if (blscene->r.stereomode != RAS_IRasterizer::RAS_STEREO_QUADBUFFERED)
|
|
|
|
rasterizer->SetStereoMode((RAS_IRasterizer::StereoMode) blscene->r.stereomode);
|
|
|
|
|
2002-10-12 11:37:38 +00:00
|
|
|
if (exitrequested != KX_EXIT_REQUEST_QUIT_GAME)
|
|
|
|
{
|
2008-04-16 08:48:49 +00:00
|
|
|
if (v3d->persp != V3D_CAMOB)
|
2002-10-12 11:37:38 +00:00
|
|
|
{
|
|
|
|
ketsjiengine->EnableCameraOverride(startscenename);
|
2008-04-16 08:48:49 +00:00
|
|
|
ketsjiengine->SetCameraOverrideUseOrtho((v3d->persp == V3D_ORTHO));
|
2002-10-12 11:37:38 +00:00
|
|
|
ketsjiengine->SetCameraOverrideProjectionMatrix(projmat);
|
|
|
|
ketsjiengine->SetCameraOverrideViewMatrix(viewmat);
|
2008-09-15 00:11:30 +00:00
|
|
|
ketsjiengine->SetCameraOverrideClipping(v3d->near, v3d->far);
|
2002-10-12 11:37:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// create a scene converter, create and convert the startingscene
|
2006-05-22 21:03:43 +00:00
|
|
|
KX_ISceneConverter* sceneconverter = new KX_BlenderSceneConverter(blenderdata,sipo, ketsjiengine);
|
2002-10-12 11:37:38 +00:00
|
|
|
ketsjiengine->SetSceneConverter(sceneconverter);
|
2006-12-16 05:50:38 +00:00
|
|
|
sceneconverter->addInitFromFrame=false;
|
2002-10-12 11:37:38 +00:00
|
|
|
if (always_use_expand_framing)
|
|
|
|
sceneconverter->SetAlwaysUseExpandFraming(true);
|
2008-09-13 19:19:51 +00:00
|
|
|
|
2008-10-04 17:04:23 +00:00
|
|
|
bool usemat = false, useglslmat = false;
|
|
|
|
|
|
|
|
if(GLEW_ARB_multitexture && GLEW_VERSION_1_1)
|
|
|
|
usemat = true;
|
|
|
|
|
|
|
|
if(GPU_extensions_minimum_support())
|
|
|
|
useglslmat = true;
|
|
|
|
else if(G.fileflags & G_FILE_GAME_MAT_GLSL)
|
|
|
|
usemat = false;
|
|
|
|
|
2008-10-11 23:48:37 +00:00
|
|
|
if(usemat && (G.fileflags & G_FILE_GAME_MAT))
|
2006-01-06 03:46:54 +00:00
|
|
|
sceneconverter->SetMaterials(true);
|
2008-10-11 23:48:37 +00:00
|
|
|
if(useglslmat && (G.fileflags & G_FILE_GAME_MAT_GLSL))
|
|
|
|
sceneconverter->SetGLSLMaterials(true);
|
2006-01-06 03:46:54 +00:00
|
|
|
|
2002-10-12 11:37:38 +00:00
|
|
|
KX_Scene* startscene = new KX_Scene(keyboarddevice,
|
|
|
|
mousedevice,
|
|
|
|
networkdevice,
|
|
|
|
audiodevice,
|
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,
|
|
|
|
blscene);
|
2002-10-12 11:37:38 +00:00
|
|
|
|
|
|
|
// some python things
|
|
|
|
PyObject* dictionaryobject = initGamePythonScripting("Ketsji", psl_Lowest);
|
|
|
|
ketsjiengine->SetPythonDictionary(dictionaryobject);
|
|
|
|
initRasterizer(rasterizer, canvas);
|
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
|
|
|
PyObject *gameLogic = initGameLogic(ketsjiengine, startscene);
|
2008-08-19 11:53:24 +00:00
|
|
|
PyDict_SetItemString(PyModule_GetDict(gameLogic), "globalDict", pyGlobalDict); // Same as importing the module.
|
2008-09-23 00:37:19 +00:00
|
|
|
PyObject *gameLogic_keys = PyDict_Keys(PyModule_GetDict(gameLogic));
|
|
|
|
PyDict_SetItemString(dictionaryobject, "GameLogic", gameLogic); // Same as importing the module.
|
|
|
|
|
2002-10-12 11:37:38 +00:00
|
|
|
initGameKeys();
|
|
|
|
initPythonConstraintBinding();
|
2008-08-05 22:26:00 +00:00
|
|
|
initMathutils();
|
VideoTexture module.
The only compilation system that works for sure is the MSVC project files. I've tried my best to
update the other compilation system but I count on the community to check and fix them.
This is Zdeno Miklas video texture plugin ported to trunk.
The original plugin API is maintained (can be found here http://home.scarlet.be/~tsi46445/blender/blendVideoTex.html)
EXCEPT for the following:
The module name is changed to VideoTexture (instead of blendVideoTex).
A new (and only) video source is now available: VideoFFmpeg()
You must pass 1 to 4 arguments when you create it (you can use named arguments):
VideoFFmpeg(file) : play a video file
VideoFFmpeg(file, capture, rate, width, height) : start a live video capture
file:
In the first form, file is a video file name, relative to startup directory.
It can also be a URL, FFmpeg will happily stream a video from a network source.
In the second form, file is empty or is a hint for the format of the video capture.
In Windows, file is ignored and should be empty or not specified.
In Linux, ffmpeg supports two types of device: VideoForLinux and DV1394.
The user specifies the type of device with the file parameter:
[<device_type>][:<standard>]
<device_type> : 'v4l' for VideoForLinux, 'dv1394' for DV1394; default to 'v4l'
<standard> : 'pal', 'secam' or 'ntsc', default to 'ntsc'
The driver name is constructed automatically from the device types:
v4l : /dev/video<capture>
dv1394: /dev/dv1394/<capture>
If you have different driver name, you can specify the driver name explicitely
instead of device type. Examples of valid file parameter:
/dev/v4l/video0:pal
/dev/ieee1394/1:ntsc
dv1394:ntsc
v4l:pal
:secam
capture:
Defines the index number of the capture source, starting from 0. The first capture device is always 0.
The VideoTexutre modules knows that you want to start a live video capture when you set this parameter to a number >= 0. Setting this parameter < 0 indicates a video file playback. Default value is -1.
rate:
the capture frame rate, by default 25 frames/sec
width:
height:
Width and height of the video capture in pixel, default value 0.
In Windows you must specify these values and they must fit with the capture device capability.
For example, if you have a webcam that can capture at 160x120, 320x240 or 640x480,
you must specify one of these couple of values or the opening of the video source will fail.
In Linux, default values are provided by the VideoForLinux driver if you don't specify width and height.
Simple example
**************
1. Texture definition script:
import VideoTexture
contr = GameLogic.getCurrentController()
obj = contr.getOwner()
if not hasattr(GameLogic, 'video'):
matID = VideoTexture.materialID(obj, 'MAVideoMat')
GameLogic.video = VideoTexture.Texture(obj, matID)
GameLogic.vidSrc = VideoTexture.VideoFFmpeg('trailer_400p.ogg')
# Streaming is also possible:
#GameLogic.vidSrc = VideoTexture.VideoFFmpeg('http://10.32.1.10/trailer_400p.ogg')
GameLogic.vidSrc.repeat = -1
# If the video dimensions are not a power of 2, scaling must be done before
# sending the texture to the GPU. This is done by default with gluScaleImage()
# but you can also use a faster, but less precise, scaling by setting scale
# to True. Best approach is to convert the video offline and set the dimensions right.
GameLogic.vidSrc.scale = True
# FFmpeg always delivers the video image upside down, so flipping is enabled automatically
#GameLogic.vidSrc.flip = True
if contr.getSensors()[0].isPositive():
GameLogic.video.source = GameLogic.vidSrc
GameLogic.vidSrc.play()
2. Texture refresh script:
obj = GameLogic.getCurrentController().getOwner()
if hasattr(GameLogic, 'video') != 0:
GameLogic.video.refresh(True)
You can download this demo here:
http://home.scarlet.be/~tsi46445/blender/VideoTextureDemo.blend
http://home.scarlet.be/~tsi46445/blender/trailer_400p.ogg
2008-10-31 22:35:52 +00:00
|
|
|
initVideoTexture();
|
2002-10-12 11:37:38 +00:00
|
|
|
|
|
|
|
if (sceneconverter)
|
|
|
|
{
|
|
|
|
// convert and add scene
|
|
|
|
sceneconverter->ConvertScene(
|
|
|
|
startscenename,
|
|
|
|
startscene,
|
|
|
|
dictionaryobject,
|
|
|
|
keyboarddevice,
|
|
|
|
rendertools,
|
|
|
|
canvas);
|
|
|
|
ketsjiengine->AddScene(startscene);
|
|
|
|
|
|
|
|
// init the rasterizer
|
|
|
|
rasterizer->Init();
|
|
|
|
|
|
|
|
// start the engine
|
2006-11-30 00:19:27 +00:00
|
|
|
ketsjiengine->StartEngine(true);
|
2002-10-12 11:37:38 +00:00
|
|
|
|
2008-06-17 10:06:38 +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
|
|
|
|
ketsjiengine->SetAnimFrameRate( (((double) blscene->r.frs_sec) / blscene->r.frs_sec_base) );
|
|
|
|
|
2002-10-12 11:37:38 +00:00
|
|
|
// the mainloop
|
2008-09-25 17:43:06 +00:00
|
|
|
printf("\nBlender Game Engine Started\n\n");
|
2002-10-12 11:37:38 +00:00
|
|
|
while (!exitrequested)
|
|
|
|
{
|
|
|
|
// first check if we want to exit
|
|
|
|
exitrequested = ketsjiengine->GetExitCode();
|
|
|
|
|
|
|
|
// kick the engine
|
2006-12-02 22:25:47 +00:00
|
|
|
bool render = ketsjiengine->NextFrame();
|
2002-10-12 11:37:38 +00:00
|
|
|
|
2006-12-02 22:25:47 +00:00
|
|
|
if (render)
|
|
|
|
{
|
|
|
|
// render the frame
|
|
|
|
ketsjiengine->Render();
|
|
|
|
}
|
2002-10-12 11:37:38 +00:00
|
|
|
|
|
|
|
// test for the ESC key
|
2008-01-01 19:20:49 +00:00
|
|
|
while (0) //XXX while (qtest())
|
2002-10-12 11:37:38 +00:00
|
|
|
{
|
|
|
|
short val;
|
2008-01-01 19:20:49 +00:00
|
|
|
unsigned short event = 0; //XXX extern_qread(&val);
|
2002-10-12 11:37:38 +00:00
|
|
|
|
|
|
|
if (keyboarddevice->ConvertBlenderEvent(event,val))
|
|
|
|
exitrequested = KX_EXIT_REQUEST_BLENDER_ESC;
|
|
|
|
|
|
|
|
/* Coordinate conversion... where
|
|
|
|
* should this really be?
|
|
|
|
*/
|
|
|
|
if (event==MOUSEX) {
|
2008-01-01 19:20:49 +00:00
|
|
|
val = 0;//XXX val - scrarea_get_win_x(area);
|
2002-10-12 11:37:38 +00:00
|
|
|
} else if (event==MOUSEY) {
|
2008-01-01 19:20:49 +00:00
|
|
|
val = 0;//XXX scrarea_get_win_height(area) - (val - scrarea_get_win_y(area)) - 1;
|
2002-10-12 11:37:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
mousedevice->ConvertBlenderEvent(event,val);
|
|
|
|
}
|
|
|
|
}
|
2008-09-25 17:43:06 +00:00
|
|
|
printf("\nBlender Game Engine Finished\n\n");
|
2002-10-12 11:37:38 +00:00
|
|
|
exitstring = ketsjiengine->GetExitString();
|
2008-10-10 07:20:42 +00:00
|
|
|
|
|
|
|
|
2002-10-12 11:37:38 +00:00
|
|
|
// when exiting the mainloop
|
2008-07-14 00:47:07 +00:00
|
|
|
|
|
|
|
// Clears the dictionary by hand:
|
|
|
|
// This prevents, extra references to global variables
|
|
|
|
// inside the GameLogic dictionary when the python interpreter is finalized.
|
|
|
|
// which allows the scene to safely delete them :)
|
|
|
|
// see: (space.c)->start_game
|
2008-09-23 00:37:19 +00:00
|
|
|
|
|
|
|
//PyDict_Clear(PyModule_GetDict(gameLogic));
|
|
|
|
|
|
|
|
// Keep original items, means python plugins will autocomplete members
|
|
|
|
int listIndex;
|
|
|
|
PyObject *gameLogic_keys_new = PyDict_Keys(PyModule_GetDict(gameLogic));
|
|
|
|
for (listIndex=0; listIndex < PyList_Size(gameLogic_keys_new); listIndex++) {
|
|
|
|
PyObject* item = PyList_GET_ITEM(gameLogic_keys_new, listIndex);
|
|
|
|
if (!PySequence_Contains(gameLogic_keys, item)) {
|
|
|
|
PyDict_DelItem( PyModule_GetDict(gameLogic), item);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
Py_DECREF(gameLogic_keys_new);
|
|
|
|
gameLogic_keys_new = NULL;
|
2008-07-14 00:47:07 +00:00
|
|
|
|
2002-10-12 11:37:38 +00:00
|
|
|
ketsjiengine->StopEngine();
|
2006-05-14 03:39:07 +00:00
|
|
|
exitGamePythonScripting();
|
2002-10-12 11:37:38 +00:00
|
|
|
networkdevice->Disconnect();
|
|
|
|
}
|
|
|
|
if (sceneconverter)
|
|
|
|
{
|
|
|
|
delete sceneconverter;
|
|
|
|
sceneconverter = NULL;
|
|
|
|
}
|
2008-09-23 00:37:19 +00:00
|
|
|
|
|
|
|
Py_DECREF(gameLogic_keys);
|
|
|
|
gameLogic_keys = NULL;
|
2002-10-12 11:37:38 +00:00
|
|
|
}
|
2008-10-10 07:20:42 +00:00
|
|
|
//lock frame and camera enabled - restoring global values
|
|
|
|
if (G.vd->scenelock==0){
|
|
|
|
G.scene->lay= tmp_lay;
|
|
|
|
G.scene->camera= tmp_camera;
|
2002-10-12 11:37:38 +00:00
|
|
|
}
|
2008-10-10 07:20:42 +00:00
|
|
|
|
2002-10-12 11:37:38 +00:00
|
|
|
// set the cursor back to normal
|
|
|
|
canvas->SetMouseState(RAS_ICanvas::MOUSE_NORMAL);
|
|
|
|
|
|
|
|
// clean up some stuff
|
|
|
|
audiodevice->StopCD();
|
|
|
|
|
|
|
|
if (ketsjiengine)
|
|
|
|
{
|
|
|
|
delete ketsjiengine;
|
|
|
|
ketsjiengine = NULL;
|
|
|
|
}
|
|
|
|
if (kxsystem)
|
|
|
|
{
|
|
|
|
delete kxsystem;
|
|
|
|
kxsystem = NULL;
|
|
|
|
}
|
|
|
|
if (networkdevice)
|
|
|
|
{
|
|
|
|
delete networkdevice;
|
|
|
|
networkdevice = NULL;
|
|
|
|
}
|
|
|
|
if (keyboarddevice)
|
|
|
|
{
|
|
|
|
delete keyboarddevice;
|
|
|
|
keyboarddevice = NULL;
|
|
|
|
}
|
|
|
|
if (mousedevice)
|
|
|
|
{
|
|
|
|
delete mousedevice;
|
|
|
|
mousedevice = NULL;
|
|
|
|
}
|
|
|
|
if (rasterizer)
|
|
|
|
{
|
|
|
|
delete rasterizer;
|
|
|
|
rasterizer = NULL;
|
|
|
|
}
|
|
|
|
if (rendertools)
|
|
|
|
{
|
|
|
|
delete rendertools;
|
|
|
|
rendertools = NULL;
|
|
|
|
}
|
|
|
|
if (canvas)
|
|
|
|
{
|
|
|
|
delete canvas;
|
|
|
|
canvas = NULL;
|
|
|
|
}
|
2005-03-25 10:33:39 +00:00
|
|
|
SND_DeviceManager::Unsubscribe();
|
|
|
|
|
2002-10-12 11:37:38 +00:00
|
|
|
} while (exitrequested == KX_EXIT_REQUEST_RESTART_GAME || exitrequested == KX_EXIT_REQUEST_START_OTHER_GAME);
|
|
|
|
|
|
|
|
if (bfd) BLO_blendfiledata_free(bfd);
|
2008-02-23 12:05:28 +00:00
|
|
|
|
2008-10-11 00:56:49 +00:00
|
|
|
BLI_strncpy(G.sce, oldsce, sizeof(G.sce));
|
|
|
|
|
2008-02-23 12:05:28 +00:00
|
|
|
// Release Python's GIL
|
|
|
|
PyGILState_Release(gilstate);
|
2002-10-12 11:37:38 +00:00
|
|
|
}
|
2006-11-30 00:19:27 +00:00
|
|
|
|
|
|
|
extern "C" void StartKetsjiShellSimulation(struct ScrArea *area,
|
|
|
|
char* scenename,
|
|
|
|
struct Main* maggie,
|
|
|
|
struct SpaceIpo *sipo,
|
|
|
|
int always_use_expand_framing)
|
|
|
|
{
|
|
|
|
int exitrequested = KX_EXIT_REQUEST_NO_REQUEST;
|
|
|
|
|
|
|
|
Main* blenderdata = maggie;
|
|
|
|
|
|
|
|
char* startscenename = scenename;
|
2008-10-11 00:56:49 +00:00
|
|
|
char pathname[FILE_MAXDIR+FILE_MAXFILE];
|
2006-11-30 00:19:27 +00:00
|
|
|
STR_String exitstring = "";
|
|
|
|
|
2008-10-11 00:56:49 +00:00
|
|
|
BLI_strncpy(pathname, blenderdata->name, sizeof(pathname));
|
2006-11-30 00:19:27 +00:00
|
|
|
|
2008-02-23 12:05:28 +00:00
|
|
|
// Acquire Python's GIL (global interpreter lock)
|
|
|
|
// so we can safely run Python code and API calls
|
|
|
|
PyGILState_STATE gilstate = PyGILState_Ensure();
|
|
|
|
|
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);
|
2006-11-30 00:19:27 +00:00
|
|
|
|
|
|
|
do
|
|
|
|
{
|
|
|
|
|
|
|
|
// get some preferences
|
|
|
|
SYS_SystemHandle syshandle = SYS_GetSystem();
|
|
|
|
bool properties = (SYS_GetCommandLineInt(syshandle, "show_properties", 0) != 0);
|
|
|
|
bool usefixed = (SYS_GetCommandLineInt(syshandle, "fixedtime", 0) != 0);
|
|
|
|
bool profile = (SYS_GetCommandLineInt(syshandle, "show_profile", 0) != 0);
|
|
|
|
bool frameRate = (SYS_GetCommandLineInt(syshandle, "show_framerate", 0) != 0);
|
|
|
|
bool game2ipo = true;//(SYS_GetCommandLineInt(syshandle, "game2ipo", 0) != 0);
|
|
|
|
bool displaylists = (SYS_GetCommandLineInt(syshandle, "displaylists", 0) != 0);
|
|
|
|
bool usemat = false;
|
|
|
|
|
|
|
|
// create the canvas, rasterizer and rendertools
|
|
|
|
RAS_ICanvas* canvas = new KX_BlenderCanvas(area);
|
|
|
|
//canvas->SetMouseState(RAS_ICanvas::MOUSE_INVISIBLE);
|
|
|
|
RAS_IRenderTools* rendertools = new KX_BlenderRenderTools();
|
|
|
|
RAS_IRasterizer* rasterizer = NULL;
|
|
|
|
|
2008-06-29 21:51:27 +00:00
|
|
|
if(displaylists) {
|
|
|
|
if (GLEW_VERSION_1_1)
|
|
|
|
rasterizer = new RAS_ListRasterizer(canvas, true, true);
|
|
|
|
else
|
|
|
|
rasterizer = new RAS_ListRasterizer(canvas);
|
|
|
|
}
|
|
|
|
else if (GLEW_VERSION_1_1)
|
|
|
|
rasterizer = new RAS_VAOpenGLRasterizer(canvas, false);
|
2006-11-30 00:19:27 +00:00
|
|
|
else
|
|
|
|
rasterizer = new RAS_OpenGLRasterizer(canvas);
|
|
|
|
|
|
|
|
// create the inputdevices
|
|
|
|
KX_BlenderKeyboardDevice* keyboarddevice = new KX_BlenderKeyboardDevice();
|
|
|
|
KX_BlenderMouseDevice* mousedevice = new KX_BlenderMouseDevice();
|
|
|
|
|
|
|
|
// create a networkdevice
|
|
|
|
NG_NetworkDeviceInterface* networkdevice = new
|
|
|
|
NG_LoopBackNetworkDeviceInterface();
|
|
|
|
|
|
|
|
// get an audiodevice
|
|
|
|
SND_DeviceManager::Subscribe();
|
|
|
|
SND_IAudioDevice* audiodevice = SND_DeviceManager::Instance();
|
|
|
|
audiodevice->UseCD();
|
|
|
|
|
|
|
|
// create a ketsji/blendersystem (only needed for timing and stuff)
|
|
|
|
KX_BlenderSystem* kxsystem = new KX_BlenderSystem();
|
|
|
|
|
|
|
|
// create the ketsjiengine
|
|
|
|
KX_KetsjiEngine* ketsjiengine = new KX_KetsjiEngine(kxsystem);
|
|
|
|
|
|
|
|
Scene *blscene = NULL;
|
2008-10-11 00:56:49 +00:00
|
|
|
|
|
|
|
blscene = (Scene*) maggie->scene.first;
|
|
|
|
for (Scene *sce= (Scene*) maggie->scene.first; sce; sce= (Scene*) sce->id.next)
|
2006-11-30 00:19:27 +00:00
|
|
|
{
|
2008-10-11 00:56:49 +00:00
|
|
|
if (startscenename == (sce->id.name+2))
|
2006-11-30 00:19:27 +00:00
|
|
|
{
|
2008-10-11 00:56:49 +00:00
|
|
|
blscene = sce;
|
|
|
|
break;
|
2006-11-30 00:19:27 +00:00
|
|
|
}
|
|
|
|
}
|
2008-10-11 00:56:49 +00:00
|
|
|
|
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
|
|
|
int cframe = 1, startFrame;
|
2006-11-30 00:19:27 +00:00
|
|
|
if (blscene)
|
|
|
|
{
|
|
|
|
cframe=blscene->r.cfra;
|
|
|
|
startFrame = blscene->r.sfra;
|
|
|
|
blscene->r.cfra=startFrame;
|
|
|
|
update_for_newframe();
|
|
|
|
ketsjiengine->SetGame2IpoMode(game2ipo,startFrame);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Quad buffered needs a special window.
|
|
|
|
if (blscene->r.stereomode != RAS_IRasterizer::RAS_STEREO_QUADBUFFERED)
|
|
|
|
rasterizer->SetStereoMode((RAS_IRasterizer::StereoMode) blscene->r.stereomode);
|
|
|
|
|
|
|
|
if (exitrequested != KX_EXIT_REQUEST_QUIT_GAME)
|
|
|
|
{
|
|
|
|
// create a scene converter, create and convert the startingscene
|
|
|
|
KX_ISceneConverter* sceneconverter = new KX_BlenderSceneConverter(maggie,sipo, ketsjiengine);
|
|
|
|
ketsjiengine->SetSceneConverter(sceneconverter);
|
2006-12-16 05:50:38 +00:00
|
|
|
sceneconverter->addInitFromFrame=true;
|
|
|
|
|
2006-11-30 00:19:27 +00:00
|
|
|
if (always_use_expand_framing)
|
|
|
|
sceneconverter->SetAlwaysUseExpandFraming(true);
|
|
|
|
|
|
|
|
if(usemat)
|
|
|
|
sceneconverter->SetMaterials(true);
|
|
|
|
|
|
|
|
KX_Scene* startscene = new KX_Scene(keyboarddevice,
|
|
|
|
mousedevice,
|
|
|
|
networkdevice,
|
|
|
|
audiodevice,
|
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,
|
|
|
|
blscene);
|
|
|
|
|
2006-11-30 00:19:27 +00:00
|
|
|
// some python things
|
|
|
|
PyObject* dictionaryobject = initGamePythonScripting("Ketsji", psl_Lowest);
|
|
|
|
ketsjiengine->SetPythonDictionary(dictionaryobject);
|
|
|
|
initRasterizer(rasterizer, canvas);
|
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
|
|
|
PyObject *gameLogic = initGameLogic(ketsjiengine, startscene);
|
2008-07-14 00:47:07 +00:00
|
|
|
PyDict_SetItemString(dictionaryobject, "GameLogic", gameLogic); // Same as importing the module
|
2006-11-30 00:19:27 +00:00
|
|
|
initGameKeys();
|
|
|
|
initPythonConstraintBinding();
|
2008-08-05 22:26:00 +00:00
|
|
|
initMathutils();
|
2008-11-10 22:17:40 +00:00
|
|
|
initVideoTexture();
|
2006-11-30 00:19:27 +00:00
|
|
|
|
|
|
|
if (sceneconverter)
|
|
|
|
{
|
|
|
|
// convert and add scene
|
|
|
|
sceneconverter->ConvertScene(
|
|
|
|
startscenename,
|
|
|
|
startscene,
|
|
|
|
dictionaryobject,
|
|
|
|
keyboarddevice,
|
|
|
|
rendertools,
|
|
|
|
canvas);
|
|
|
|
ketsjiengine->AddScene(startscene);
|
|
|
|
|
|
|
|
// start the engine
|
|
|
|
ketsjiengine->StartEngine(false);
|
2007-01-07 04:54:29 +00:00
|
|
|
|
|
|
|
ketsjiengine->SetUseFixedTime(true);
|
|
|
|
|
== Core ==
This adds fractional FPS support to blender and should finally
make NTSC work correctly.
NTSC has an FPS of 30.0/1.001 which is approximately 29.97 FPS.
Therefore, it is not enough to simply make frs_sec a float, since
you can't represent this accurately enough.
I added a seperate variable frs_sec_base and FPS is now
frs_sec / frs_sec_base.
I changed all the places, where frs_sec was used to my best knowledge.
For convenience sake, I added several macros, that should make life
easier in the future:
FRA2TIME(a) : convert frame number to a double precision time in seconds
TIME2FRA(a) : the same in the opposite direction
FPS : return current FPS as a double precision number
(last resort)
This closes bug #6715
Standard framerates not supported / breaks sync -- 23.967 29.967 etc.
https://projects.blender.org/tracker/?func=detail&aid=6715&group_id=9&atid=125
Please give this heavy testing with NTSC files, quicktime in/export
and the python interface.
Errors are most probably only spotted on longer timelines, so that is
also important.
The patch was tested by Troy Sobotka and me, so it most probably should
work out of the box, but wider testing is important, since errors are
very subtle.
Enjoy!
2007-10-21 15:42:08 +00:00
|
|
|
ketsjiengine->SetTicRate(
|
|
|
|
(double) blscene->r.frs_sec /
|
|
|
|
(double) blscene->r.frs_sec_base);
|
2006-11-30 00:19:27 +00:00
|
|
|
|
|
|
|
// the mainloop
|
|
|
|
while ((blscene->r.cfra<=blscene->r.efra)&&(!exitrequested))
|
|
|
|
{
|
|
|
|
printf("frame %i\n",blscene->r.cfra);
|
|
|
|
// first check if we want to exit
|
|
|
|
exitrequested = ketsjiengine->GetExitCode();
|
2006-12-16 05:50:38 +00:00
|
|
|
|
2006-11-30 00:19:27 +00:00
|
|
|
// kick the engine
|
|
|
|
ketsjiengine->NextFrame();
|
|
|
|
blscene->r.cfra=blscene->r.cfra+1;
|
|
|
|
update_for_newframe();
|
2006-12-16 05:50:38 +00:00
|
|
|
|
2006-11-30 00:19:27 +00:00
|
|
|
}
|
|
|
|
exitstring = ketsjiengine->GetExitString();
|
|
|
|
}
|
|
|
|
if (sceneconverter)
|
|
|
|
{
|
|
|
|
delete sceneconverter;
|
|
|
|
sceneconverter = NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
blscene->r.cfra=cframe;
|
|
|
|
// set the cursor back to normal
|
|
|
|
canvas->SetMouseState(RAS_ICanvas::MOUSE_NORMAL);
|
|
|
|
|
|
|
|
// clean up some stuff
|
|
|
|
audiodevice->StopCD();
|
|
|
|
if (ketsjiengine)
|
|
|
|
{
|
|
|
|
delete ketsjiengine;
|
|
|
|
ketsjiengine = NULL;
|
|
|
|
}
|
|
|
|
if (kxsystem)
|
|
|
|
{
|
|
|
|
delete kxsystem;
|
|
|
|
kxsystem = NULL;
|
|
|
|
}
|
|
|
|
if (networkdevice)
|
|
|
|
{
|
|
|
|
delete networkdevice;
|
|
|
|
networkdevice = NULL;
|
|
|
|
}
|
|
|
|
if (keyboarddevice)
|
|
|
|
{
|
|
|
|
delete keyboarddevice;
|
|
|
|
keyboarddevice = NULL;
|
|
|
|
}
|
|
|
|
if (mousedevice)
|
|
|
|
{
|
|
|
|
delete mousedevice;
|
|
|
|
mousedevice = NULL;
|
|
|
|
}
|
|
|
|
SND_DeviceManager::Unsubscribe();
|
|
|
|
|
|
|
|
} while (exitrequested == KX_EXIT_REQUEST_RESTART_GAME || exitrequested == KX_EXIT_REQUEST_START_OTHER_GAME);
|
2008-02-23 12:05:28 +00:00
|
|
|
|
|
|
|
// Release Python's GIL
|
|
|
|
PyGILState_Release(gilstate);
|
== Core ==
This adds fractional FPS support to blender and should finally
make NTSC work correctly.
NTSC has an FPS of 30.0/1.001 which is approximately 29.97 FPS.
Therefore, it is not enough to simply make frs_sec a float, since
you can't represent this accurately enough.
I added a seperate variable frs_sec_base and FPS is now
frs_sec / frs_sec_base.
I changed all the places, where frs_sec was used to my best knowledge.
For convenience sake, I added several macros, that should make life
easier in the future:
FRA2TIME(a) : convert frame number to a double precision time in seconds
TIME2FRA(a) : the same in the opposite direction
FPS : return current FPS as a double precision number
(last resort)
This closes bug #6715
Standard framerates not supported / breaks sync -- 23.967 29.967 etc.
https://projects.blender.org/tracker/?func=detail&aid=6715&group_id=9&atid=125
Please give this heavy testing with NTSC files, quicktime in/export
and the python interface.
Errors are most probably only spotted on longer timelines, so that is
also important.
The patch was tested by Troy Sobotka and me, so it most probably should
work out of the box, but wider testing is important, since errors are
very subtle.
Enjoy!
2007-10-21 15:42:08 +00:00
|
|
|
}
|