blender/source/gameengine/BlenderRoutines/BL_KetsjiEmbedStart.cpp

684 lines
19 KiB
C++
Raw Normal View History

2002-10-12 11:37:38 +00:00
/**
* $Id$
*
* ***** 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
* 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.
*
* ***** END GPL LICENSE BLOCK *****
2002-10-12 11:37:38 +00:00
* Blender's Ketsji startpoint
*/
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
#include <signal.h>
#include <stdlib.h>
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"
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"
#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"
#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"
#include "BIF_screen.h"
#include "BIF_scrarea.h"
#include "BKE_main.h"
#include "BLI_blenlib.h"
#include "BLO_readfile.h"
#include "DNA_scene_types.h"
/***/
#include "GPU_extensions.h"
#ifdef __cplusplus
extern "C" {
#endif
#include "BSE_headerbuttons.h"
void update_for_newframe();
#ifdef __cplusplus
}
#endif
2002-10-12 11:37:38 +00:00
static BlendFileData *load_game_data(char *filename) {
BlendReadError error;
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,
struct Main* maggie1,
struct SpaceIpo *sipo,
2002-10-12 11:37:38 +00:00
int always_use_expand_framing)
{
int exitrequested = KX_EXIT_REQUEST_NO_REQUEST;
Main* blenderdata = maggie1;
2002-10-12 11:37:38 +00:00
char* startscenename = scenename;
char pathname[160];
strcpy (pathname, blenderdata->name);
2002-10-12 11:37:38 +00:00
STR_String exitstring = "";
BlendFileData *bfd= NULL;
// Acquire Python's GIL (global interpreter lock)
// so we can safely run Python code and API calls
PyGILState_STATE gilstate = PyGILState_Ensure();
PyObject *pyGlobalDict = PyDict_New(); /* python utility storage, spans blend file loading */
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);
bool game2ipo = (SYS_GetCommandLineInt(syshandle, "game2ipo", 0) != 0);
bool displaylists = (SYS_GetCommandLineInt(syshandle, "displaylists", 0) != 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
bool usemat = false, useglslmat = false;
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
if(GLEW_ARB_multitexture && GLEW_VERSION_1_1)
usemat = (SYS_GetCommandLineInt(syshandle, "blender_material", 1) != 0);
if(GPU_extensions_minimum_support())
useglslmat = (SYS_GetCommandLineInt(syshandle, "blender_glsl_material", 1) != 0);
else if(G.fileflags & G_FILE_GAME_MAT_GLSL)
usemat = false;
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;
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
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
}
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();
// 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);
2002-10-12 11:37:38 +00:00
2002-10-12 11:37:38 +00:00
// some blender stuff
MT_CmMatrix4x4 projmat;
MT_CmMatrix4x4 viewmat;
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++)
{
float *projmat_linear = (float*) area->winmat;
projmat.setElem(i, projmat_linear[i]);
}
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);
char basedpath[240];
2002-10-12 11:37:38 +00:00
// base the actuator filename with respect
// to the original file working directory
if (exitstring != "")
strcpy(basedpath, exitstring.Ptr());
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
char temppath[242];
2002-10-12 11:37:38 +00:00
strcpy(temppath, "//");
strcat(temppath, basedpath);
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;
}
// else forget it, we can't find it
else
{
exitrequested = KX_EXIT_REQUEST_QUIT_GAME;
}
}
Scene *blscene = NULL;
if (!bfd)
{
blscene = (Scene*) blenderdata->scene.first;
for (Scene *sce= (Scene*) blenderdata->scene.first; sce; sce= (Scene*) sce->id.next)
{
if (startscenename == (sce->id.name+2))
{
blscene = sce;
break;
}
}
} else {
blscene = bfd->curscene;
}
if (blscene)
{
int startFrame = blscene->r.cfra;
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);
2002-10-12 11:37:38 +00:00
if (exitrequested != KX_EXIT_REQUEST_QUIT_GAME)
{
if (v3d->persp != V3D_CAMOB)
2002-10-12 11:37:38 +00:00
{
ketsjiengine->EnableCameraOverride(startscenename);
ketsjiengine->SetCameraOverrideUseOrtho((v3d->persp == V3D_ORTHO));
2002-10-12 11:37:38 +00:00
ketsjiengine->SetCameraOverrideProjectionMatrix(projmat);
ketsjiengine->SetCameraOverrideViewMatrix(viewmat);
ketsjiengine->SetCameraOverrideClipping(v3d->near, v3d->far);
2002-10-12 11:37:38 +00:00
}
// create a scene converter, create and convert the startingscene
KX_ISceneConverter* sceneconverter = new KX_BlenderSceneConverter(blenderdata,sipo, ketsjiengine);
2002-10-12 11:37:38 +00:00
ketsjiengine->SetSceneConverter(sceneconverter);
sceneconverter->addInitFromFrame=false;
2002-10-12 11:37:38 +00:00
if (always_use_expand_framing)
sceneconverter->SetAlwaysUseExpandFraming(true);
if(usemat && (G.fileflags & G_FILE_GAME_MAT))
sceneconverter->SetMaterials(true);
if(useglslmat && (G.fileflags & G_FILE_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
sceneconverter->SetGLSLMaterials(true);
2002-10-12 11:37:38 +00:00
KX_Scene* startscene = new KX_Scene(keyboarddevice,
mousedevice,
networkdevice,
audiodevice,
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);
PyObject *gameLogic = initGameLogic(ketsjiengine, startscene);
PyDict_SetItemString(dictionaryobject, "GameLogic", gameLogic); // Same as importing the module.
PyDict_SetItemString(PyModule_GetDict(gameLogic), "globalDict", pyGlobalDict); // Same as importing the module.
2002-10-12 11:37:38 +00:00
initGameKeys();
initPythonConstraintBinding();
initMathutils();
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
ketsjiengine->StartEngine(true);
2002-10-12 11:37: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
while (!exitrequested)
{
// first check if we want to exit
exitrequested = ketsjiengine->GetExitCode();
// kick the engine
bool render = ketsjiengine->NextFrame();
2002-10-12 11:37:38 +00:00
if (render)
{
// render the frame
ketsjiengine->Render();
}
2002-10-12 11:37:38 +00:00
// test for the ESC key
while (qtest())
{
short val;
unsigned short event = extern_qread(&val);
if (keyboarddevice->ConvertBlenderEvent(event,val))
exitrequested = KX_EXIT_REQUEST_BLENDER_ESC;
/* Coordinate conversion... where
* should this really be?
*/
if (event==MOUSEX) {
val = val - scrarea_get_win_x(area);
} else if (event==MOUSEY) {
val = scrarea_get_win_height(area) - (val - scrarea_get_win_y(area)) - 1;
}
mousedevice->ConvertBlenderEvent(event,val);
}
}
exitstring = ketsjiengine->GetExitString();
// when exiting the mainloop
// 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
PyDict_Clear(PyModule_GetDict(gameLogic));
PyDict_SetItemString(PyModule_GetDict(gameLogic), "globalDict", pyGlobalDict);
2002-10-12 11:37:38 +00:00
ketsjiengine->StopEngine();
exitGamePythonScripting();
2002-10-12 11:37:38 +00:00
networkdevice->Disconnect();
}
if (sceneconverter)
{
delete sceneconverter;
sceneconverter = NULL;
}
}
// 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;
}
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);
// Release Python's GIL
PyGILState_Release(gilstate);
2002-10-12 11:37:38 +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;
char pathname[160];
strcpy (pathname, maggie->name);
STR_String exitstring = "";
BlendFileData *bfd= NULL;
// 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);
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;
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);
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;
if (!bfd)
{
blscene = (Scene*) maggie->scene.first;
for (Scene *sce= (Scene*) maggie->scene.first; sce; sce= (Scene*) sce->id.next)
{
if (startscenename == (sce->id.name+2))
{
blscene = sce;
break;
}
}
} else {
blscene = bfd->curscene;
}
int cframe = 1, startFrame;
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);
sceneconverter->addInitFromFrame=true;
if (always_use_expand_framing)
sceneconverter->SetAlwaysUseExpandFraming(true);
if(usemat)
sceneconverter->SetMaterials(true);
KX_Scene* startscene = new KX_Scene(keyboarddevice,
mousedevice,
networkdevice,
audiodevice,
startscenename,
blscene);
// some python things
PyObject* dictionaryobject = initGamePythonScripting("Ketsji", psl_Lowest);
ketsjiengine->SetPythonDictionary(dictionaryobject);
initRasterizer(rasterizer, canvas);
PyObject *gameLogic = initGameLogic(ketsjiengine, startscene);
PyDict_SetItemString(dictionaryobject, "GameLogic", gameLogic); // Same as importing the module
initGameKeys();
initPythonConstraintBinding();
initMathutils();
if (sceneconverter)
{
// convert and add scene
sceneconverter->ConvertScene(
startscenename,
startscene,
dictionaryobject,
keyboarddevice,
rendertools,
canvas);
ketsjiengine->AddScene(startscene);
// start the engine
ketsjiengine->StartEngine(false);
ketsjiengine->SetUseFixedTime(true);
ketsjiengine->SetTicRate(
(double) blscene->r.frs_sec /
(double) blscene->r.frs_sec_base);
// 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();
// kick the engine
ketsjiengine->NextFrame();
blscene->r.cfra=blscene->r.cfra+1;
update_for_newframe();
}
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);
if (bfd) BLO_blendfiledata_free(bfd);
// Release Python's GIL
PyGILState_Release(gilstate);
}