2011-02-23 10:52:22 +00:00
|
|
|
/*
|
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,
|
2010-02-12 13:34:04 +00:00
|
|
|
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
2002-10-12 11:37:38 +00:00
|
|
|
*
|
|
|
|
* The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
|
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* The Original Code is: all of this file.
|
|
|
|
*
|
|
|
|
* Contributor(s): none yet.
|
|
|
|
*
|
2008-01-07 19:13:47 +00:00
|
|
|
* ***** END GPL LICENSE BLOCK *****
|
2002-10-12 11:37:38 +00:00
|
|
|
* Blender's Ketsji startpoint
|
|
|
|
*/
|
|
|
|
|
2011-02-25 13:29:48 +00:00
|
|
|
/** \file gameengine/BlenderRoutines/BL_KetsjiEmbedStart.cpp
|
|
|
|
* \ingroup blroutines
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
2004-10-16 11:41:50 +00:00
|
|
|
#include <signal.h>
|
2008-04-16 17:40:59 +00:00
|
|
|
#include <stdlib.h>
|
2009-09-29 21:42:40 +00:00
|
|
|
#include <stdio.h>
|
2004-10-16 11:41:50 +00:00
|
|
|
|
2012-10-15 02:15:07 +00:00
|
|
|
#ifdef _MSC_VER
|
|
|
|
/* don't show stl-warnings */
|
|
|
|
# pragma warning (disable:4786)
|
2002-10-12 11:37:38 +00:00
|
|
|
#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_BlenderCanvas.h"
|
|
|
|
#include "KX_BlenderKeyboardDevice.h"
|
|
|
|
#include "KX_BlenderMouseDevice.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"
|
2012-09-01 21:23:05 +00:00
|
|
|
#include "KX_PythonMain.h"
|
2002-10-12 11:37:38 +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
|
|
|
#include "RAS_GLExtensionManager.h"
|
2002-10-12 11:37:38 +00:00
|
|
|
#include "RAS_OpenGLRasterizer.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"
|
|
|
|
|
2011-05-06 20:18:42 +00:00
|
|
|
#include "BL_System.h"
|
2002-10-12 11:37:38 +00:00
|
|
|
|
2009-06-27 23:54:20 +00:00
|
|
|
#include "GPU_extensions.h"
|
|
|
|
#include "Value.h"
|
|
|
|
|
|
|
|
|
|
|
|
extern "C" {
|
2012-10-15 02:15:07 +00:00
|
|
|
#include "DNA_view3d_types.h"
|
|
|
|
#include "DNA_screen_types.h"
|
|
|
|
#include "DNA_userdef_types.h"
|
|
|
|
#include "DNA_scene_types.h"
|
|
|
|
#include "DNA_windowmanager_types.h"
|
|
|
|
|
|
|
|
#include "BKE_global.h"
|
|
|
|
#include "BKE_report.h"
|
|
|
|
#include "BKE_ipo.h"
|
|
|
|
#include "BKE_main.h"
|
|
|
|
#include "BKE_context.h"
|
|
|
|
|
|
|
|
/* avoid c++ conflict with 'new' */
|
|
|
|
#define new _new
|
|
|
|
#include "BKE_screen.h"
|
|
|
|
#undef new
|
|
|
|
|
|
|
|
#include "MEM_guardedalloc.h"
|
|
|
|
|
|
|
|
#include "BLI_blenlib.h"
|
|
|
|
#include "BLO_readfile.h"
|
|
|
|
|
|
|
|
#include "../../blender/windowmanager/WM_types.h"
|
|
|
|
#include "../../blender/windowmanager/wm_window.h"
|
|
|
|
#include "../../blender/windowmanager/wm_event_system.h"
|
2006-12-16 05:50:38 +00:00
|
|
|
}
|
|
|
|
|
2011-08-07 11:54:58 +00:00
|
|
|
#ifdef WITH_AUDASPACE
|
|
|
|
# include "AUD_C-API.h"
|
|
|
|
# include "AUD_I3DDevice.h"
|
|
|
|
# include "AUD_IDevice.h"
|
|
|
|
#endif
|
2009-06-13 17:25:54 +00:00
|
|
|
|
2008-12-19 00:50:21 +00:00
|
|
|
static BlendFileData *load_game_data(char *filename)
|
|
|
|
{
|
|
|
|
ReportList reports;
|
|
|
|
BlendFileData *bfd;
|
|
|
|
|
|
|
|
BKE_reports_init(&reports, RPT_STORE);
|
|
|
|
bfd= BLO_read_from_file(filename, &reports);
|
|
|
|
|
2002-10-12 11:37:38 +00:00
|
|
|
if (!bfd) {
|
2008-12-19 00:50:21 +00:00
|
|
|
printf("Loading %s failed: ", filename);
|
|
|
|
BKE_reports_print(&reports, RPT_ERROR);
|
2002-10-12 11:37:38 +00:00
|
|
|
}
|
2008-12-19 00:50:21 +00:00
|
|
|
|
|
|
|
BKE_reports_clear(&reports);
|
|
|
|
|
2002-10-12 11:37:38 +00:00
|
|
|
return bfd;
|
|
|
|
}
|
|
|
|
|
2012-09-16 00:22:55 +00:00
|
|
|
static int BL_KetsjiNextFrame(KX_KetsjiEngine *ketsjiengine, bContext *C, wmWindow *win, Scene *scene, ARegion *ar,
|
|
|
|
KX_BlenderKeyboardDevice* keyboarddevice, KX_BlenderMouseDevice* mousedevice, int draw_letterbox)
|
2012-09-01 21:23:05 +00:00
|
|
|
{
|
2012-09-06 02:20:03 +00:00
|
|
|
int exitrequested;
|
|
|
|
|
|
|
|
// first check if we want to exit
|
|
|
|
exitrequested = ketsjiengine->GetExitCode();
|
|
|
|
|
|
|
|
// kick the engine
|
|
|
|
bool render = ketsjiengine->NextFrame();
|
|
|
|
|
|
|
|
if (render) {
|
|
|
|
if (draw_letterbox) {
|
|
|
|
// Clear screen to border color
|
|
|
|
// We do this here since we set the canvas to be within the frames. This means the engine
|
|
|
|
// itself is unaware of the extra space, so we clear the whole region for it.
|
|
|
|
glClearColor(scene->gm.framing.col[0], scene->gm.framing.col[1], scene->gm.framing.col[2], 1.0f);
|
|
|
|
glViewport(ar->winrct.xmin, ar->winrct.ymin,
|
2012-09-15 11:48:20 +00:00
|
|
|
BLI_rcti_size_x(&ar->winrct), BLI_rcti_size_y(&ar->winrct));
|
2012-09-06 02:20:03 +00:00
|
|
|
glClear(GL_COLOR_BUFFER_BIT);
|
|
|
|
}
|
|
|
|
|
|
|
|
// render the frame
|
|
|
|
ketsjiengine->Render();
|
|
|
|
}
|
|
|
|
|
|
|
|
wm_window_process_events_nosleep();
|
|
|
|
|
|
|
|
// test for the ESC key
|
|
|
|
//XXX while (qtest())
|
|
|
|
while (wmEvent *event= (wmEvent *)win->queue.first) {
|
|
|
|
short val = 0;
|
|
|
|
//unsigned short event = 0; //XXX extern_qread(&val);
|
|
|
|
|
|
|
|
if (keyboarddevice->ConvertBlenderEvent(event->type,event->val))
|
|
|
|
exitrequested = KX_EXIT_REQUEST_BLENDER_ESC;
|
|
|
|
|
|
|
|
/* Coordinate conversion... where
|
|
|
|
* should this really be?
|
|
|
|
*/
|
|
|
|
if (event->type == MOUSEMOVE) {
|
|
|
|
/* Note, not nice! XXX 2.5 event hack */
|
|
|
|
val = event->x - ar->winrct.xmin;
|
|
|
|
mousedevice->ConvertBlenderEvent(MOUSEX, val);
|
|
|
|
|
|
|
|
val = ar->winy - (event->y - ar->winrct.ymin) - 1;
|
|
|
|
mousedevice->ConvertBlenderEvent(MOUSEY, val);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
mousedevice->ConvertBlenderEvent(event->type,event->val);
|
|
|
|
}
|
|
|
|
|
|
|
|
BLI_remlink(&win->queue, event);
|
|
|
|
wm_event_free(event);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (win != CTX_wm_window(C)) {
|
|
|
|
exitrequested= KX_EXIT_REQUEST_OUTSIDE; /* window closed while bge runs */
|
|
|
|
}
|
|
|
|
return exitrequested;
|
2012-09-01 21:23:05 +00:00
|
|
|
}
|
|
|
|
|
2013-04-04 23:16:23 +00:00
|
|
|
static struct BL_KetsjiNextFrameState {
|
2013-02-26 21:58:06 +00:00
|
|
|
class KX_KetsjiEngine* ketsjiengine;
|
2012-09-01 21:23:05 +00:00
|
|
|
struct bContext *C;
|
|
|
|
struct wmWindow* win;
|
|
|
|
struct Scene* scene;
|
|
|
|
struct ARegion *ar;
|
|
|
|
KX_BlenderKeyboardDevice* keyboarddevice;
|
|
|
|
KX_BlenderMouseDevice* mousedevice;
|
|
|
|
int draw_letterbox;
|
|
|
|
} ketsjinextframestate;
|
|
|
|
|
2012-09-16 00:22:55 +00:00
|
|
|
static int BL_KetsjiPyNextFrame(void *state0)
|
2012-09-01 21:23:05 +00:00
|
|
|
{
|
|
|
|
BL_KetsjiNextFrameState *state = (BL_KetsjiNextFrameState *) state0;
|
|
|
|
return BL_KetsjiNextFrame(
|
|
|
|
state->ketsjiengine,
|
|
|
|
state->C,
|
|
|
|
state->win,
|
|
|
|
state->scene,
|
|
|
|
state->ar,
|
|
|
|
state->keyboarddevice,
|
|
|
|
state->mousedevice,
|
|
|
|
state->draw_letterbox);
|
|
|
|
}
|
|
|
|
|
2009-10-27 00:25:38 +00:00
|
|
|
extern "C" void StartKetsjiShell(struct bContext *C, struct ARegion *ar, rcti *cam_frame, int always_use_expand_framing)
|
2002-10-12 11:37:38 +00:00
|
|
|
{
|
2009-06-13 20:58:43 +00:00
|
|
|
/* context values */
|
2013-04-18 16:28:39 +00:00
|
|
|
struct wmWindowManager *wm= CTX_wm_manager(C);
|
2009-06-13 20:58:43 +00:00
|
|
|
struct wmWindow *win= CTX_wm_window(C);
|
2010-06-19 10:47:24 +00:00
|
|
|
struct Scene *startscene= CTX_data_scene(C);
|
2009-06-13 20:58:43 +00:00
|
|
|
struct Main* maggie1= CTX_data_main(C);
|
2009-10-27 00:25:38 +00:00
|
|
|
|
2009-10-26 23:00:06 +00:00
|
|
|
|
|
|
|
RAS_Rect area_rect;
|
2009-10-27 00:25:38 +00:00
|
|
|
area_rect.SetLeft(cam_frame->xmin);
|
|
|
|
area_rect.SetBottom(cam_frame->ymin);
|
|
|
|
area_rect.SetRight(cam_frame->xmax);
|
|
|
|
area_rect.SetTop(cam_frame->ymax);
|
2009-10-26 23:00:06 +00:00
|
|
|
|
2002-10-12 11:37:38 +00:00
|
|
|
int exitrequested = KX_EXIT_REQUEST_NO_REQUEST;
|
2006-05-22 21:03:43 +00:00
|
|
|
Main* blenderdata = maggie1;
|
2005-08-23 13:16:02 +00:00
|
|
|
|
2010-06-19 10:47:24 +00:00
|
|
|
char* startscenename = startscene->id.name+2;
|
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));
|
2010-10-18 06:41:16 +00:00
|
|
|
BLI_strncpy(oldsce, G.main->name, sizeof(oldsce));
|
2010-10-31 04:11:39 +00:00
|
|
|
#ifdef WITH_PYTHON
|
2009-06-08 20:08:19 +00:00
|
|
|
resetGamePythonPath(); // need this so running a second time wont use an old blendfiles path
|
2010-10-18 06:41:16 +00:00
|
|
|
setGamePythonPath(G.main->name);
|
2008-10-11 00:56:49 +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();
|
2008-08-19 11:53:24 +00:00
|
|
|
|
|
|
|
PyObject *pyGlobalDict = PyDict_New(); /* python utility storage, spans blend file loading */
|
2009-09-29 21:42:40 +00:00
|
|
|
#endif
|
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);
|
|
|
|
|
2010-08-23 20:53:02 +00:00
|
|
|
// VBO code for derived mesh is not compatible with BGE (couldn't find why), so disable
|
|
|
|
int disableVBO = (U.gameflags & USER_DISABLE_VBO);
|
|
|
|
U.gameflags |= USER_DISABLE_VBO;
|
|
|
|
|
2011-09-11 05:54:07 +00:00
|
|
|
// Globals to be carried on over blender files
|
|
|
|
GlobalSettings gs;
|
|
|
|
gs.matmode= startscene->gm.matmode;
|
|
|
|
gs.glslflag= startscene->gm.flag;
|
|
|
|
|
2002-10-12 11:37:38 +00:00
|
|
|
do
|
|
|
|
{
|
2009-06-27 23:54:20 +00:00
|
|
|
View3D *v3d= CTX_wm_view3d(C);
|
|
|
|
RegionView3D *rv3d= CTX_wm_region_view3d(C);
|
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);
|
2010-02-22 12:25:58 +00:00
|
|
|
bool animation_record = (SYS_GetCommandLineInt(syshandle, "animation_record", 0) != 0);
|
2013-09-11 23:24:45 +00:00
|
|
|
bool displaylists = (SYS_GetCommandLineInt(syshandle, "displaylists", 0) != 0) && GPU_display_list_support();
|
2010-10-31 04:11:39 +00:00
|
|
|
#ifdef WITH_PYTHON
|
2009-01-26 08:34:40 +00:00
|
|
|
bool nodepwarnings = (SYS_GetCommandLineInt(syshandle, "ignore_deprecation_warnings", 0) != 0);
|
2010-06-06 01:15:44 +00:00
|
|
|
#endif
|
2012-12-19 01:48:54 +00:00
|
|
|
// bool novertexarrays = (SYS_GetCommandLineInt(syshandle, "novertexarrays", 0) != 0);
|
2011-01-23 17:25:27 +00:00
|
|
|
bool mouse_state = startscene->gm.flag & GAME_SHOW_MOUSE;
|
2011-08-12 20:53:29 +00:00
|
|
|
bool restrictAnimFPS = startscene->gm.flag & GAME_RESTRICT_ANIM_UPDATES;
|
2011-01-23 17:25:27 +00:00
|
|
|
|
2012-04-05 03:05:02 +00:00
|
|
|
if (animation_record) usefixed= false; /* override since you don't want to run full-speed for sim recording */
|
2010-02-23 09:39:47 +00:00
|
|
|
|
2013-11-04 19:21:07 +00:00
|
|
|
// create the canvas and rasterizer
|
2013-04-18 16:28:39 +00:00
|
|
|
RAS_ICanvas* canvas = new KX_BlenderCanvas(wm, win, area_rect, ar);
|
2011-01-23 17:25:27 +00:00
|
|
|
|
|
|
|
// default mouse state set on render panel
|
|
|
|
if (mouse_state)
|
|
|
|
canvas->SetMouseState(RAS_ICanvas::MOUSE_NORMAL);
|
|
|
|
else
|
|
|
|
canvas->SetMouseState(RAS_ICanvas::MOUSE_INVISIBLE);
|
2013-07-29 22:31:32 +00:00
|
|
|
|
|
|
|
// Setup vsync
|
|
|
|
int previous_vsync = canvas->GetSwapInterval();
|
|
|
|
if (startscene->gm.vsync == VSYNC_ADAPTIVE)
|
|
|
|
canvas->SetSwapInterval(-1);
|
|
|
|
else
|
2013-08-26 08:14:52 +00:00
|
|
|
canvas->SetSwapInterval((startscene->gm.vsync == VSYNC_ON) ? 1 : 0);
|
2013-07-29 22:31:32 +00:00
|
|
|
|
2002-10-12 11:37:38 +00:00
|
|
|
RAS_IRasterizer* rasterizer = NULL;
|
2012-12-18 20:56:25 +00:00
|
|
|
//Don't use displaylists with VBOs
|
|
|
|
//If auto starts using VBOs, make sure to check for that here
|
|
|
|
if (displaylists && startscene->gm.raster_storage != RAS_STORE_VBO)
|
|
|
|
rasterizer = new RAS_ListRasterizer(canvas, true, startscene->gm.raster_storage);
|
2002-10-12 11:37:38 +00:00
|
|
|
else
|
2012-12-18 20:56:25 +00:00
|
|
|
rasterizer = new RAS_OpenGLRasterizer(canvas, startscene->gm.raster_storage);
|
2013-04-14 00:40:24 +00:00
|
|
|
|
|
|
|
RAS_IRasterizer::MipmapOption mipmapval = rasterizer->GetMipmapping();
|
|
|
|
|
2002-10-12 11:37:38 +00:00
|
|
|
|
|
|
|
// 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
|
|
|
|
2009-08-09 21:16:39 +00:00
|
|
|
//
|
2002-10-12 11:37:38 +00:00
|
|
|
// 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->SetRasterizer(rasterizer);
|
|
|
|
ketsjiengine->SetUseFixedTime(usefixed);
|
|
|
|
ketsjiengine->SetTimingDisplay(frameRate, profile, properties);
|
2011-08-12 20:53:29 +00:00
|
|
|
ketsjiengine->SetRestrictAnimationFPS(restrictAnimFPS);
|
Cucumber, first batch of merge - UI changes and custom exit key
---------------------------------------------------------------
This was a test drive to see how painful the merge will be.
Next batches are:
- use desktop option for fullscreen
- multisampling option
- bullet collision mask
- python
- storage (vbo, dl, ...)
- lighting
[lighting still needs review]
[python could use review, although it should be straightforward]
[storage should be tested more I think]
Merged /branches/soc-2011-cucumber:r
36991,37059,37157,37416,37497-37499,37501,37522,39036,40593
36991:
==UI==
* Made some options available in Blender Game that were only available in Blender Render (camera resolution, animation fps)
* Created a panel for the embedded player
* Renamed the FPS option for the standalone player to Refresh Rate
* Moved framing options to display
* Made a button to launch the blender player from within blender (only tested on windows for now)
37059:
==UI==
* Added the option to change the exit key for the BGE. The UI currently just sets a number, and this feature most likely does not work for blenderplayer yet. More work on this to come.
* Removed the physics settings from the scene panel for the BGE.
* Added an Add menu in the logic brick header.
37157:
Making the bake options available in Blender Game
37416:
Making the exit key UI element accept key presses instead of numbers. It still does not work for the Blenderplayer, and it does not limit the input to key presses (other events don't work for exiting)
37497:
Some more work on getting the exit key to work in the Blenderplayer.
Input is now restricted to keyboard events only for the exit key UI.
37498:
Some clean up from the last commit.
The exit key setting affects the Blenderplayer now.
37499:
Cleaning up some duplicate code. Now the reverseTranslateTable for converting blender key codes to ketsji key codes is only defined in BL_BlenderDataConverter.
37501:
Centralizing the exit key methods to the keyboard devices. This should make it easier to get exit key control to the python API.
[37517: committed previously]
37522:
Moved control of the exit key away from the keyboard devices, and moved it to ketsjiengine.
Added setExitKey and getExitKey to the python API
39036:
A couple of the doversions were in the wrong spot. This should fix some issues with the exit key not being set.
[not committed entirely, see below]]
40552: space_logic.py (* fixed an error in space_logic.py *)
40593:
launch blenderplayer from ui not working in OSX fix - by Daniel Stokes and me
########################################################
code left behind (to be included in next commit):
########################################################
{
/* Initialize default values for collision masks */
Object *ob;
for(ob=main->object.first; ob; ob=ob->id.next)
ob->col_group = ob->col_mask = 1;
}
2011-12-20 03:11:56 +00:00
|
|
|
KX_KetsjiEngine::SetExitKey(ConvertKeyCode(startscene->gm.exitkey));
|
2005-08-23 13:16:02 +00:00
|
|
|
|
2011-09-11 05:54:07 +00:00
|
|
|
//set the global settings (carried over if restart/load new files)
|
|
|
|
ketsjiengine->SetGlobalSettings(&gs);
|
|
|
|
|
2010-10-31 04:11:39 +00:00
|
|
|
#ifdef WITH_PYTHON
|
2009-01-26 08:34:40 +00:00
|
|
|
CValue::SetDeprecationWarnings(nodepwarnings);
|
2009-09-29 21:42:40 +00:00
|
|
|
#endif
|
2008-10-10 07:20:42 +00:00
|
|
|
|
|
|
|
//lock frame and camera enabled - storing global values
|
2010-06-19 10:47:24 +00:00
|
|
|
int tmp_lay= startscene->lay;
|
|
|
|
Object *tmp_camera = startscene->camera;
|
2008-10-10 07:20:42 +00:00
|
|
|
|
2012-03-28 05:03:24 +00:00
|
|
|
if (v3d->scenelock==0) {
|
2010-06-19 10:47:24 +00:00
|
|
|
startscene->lay= v3d->lay;
|
|
|
|
startscene->camera= v3d->camera;
|
2008-10-10 07:20:42 +00:00
|
|
|
}
|
|
|
|
|
2002-10-12 11:37:38 +00:00
|
|
|
// some blender stuff
|
2008-09-15 00:11:30 +00:00
|
|
|
float camzoom;
|
2011-05-27 16:20:49 +00:00
|
|
|
int draw_letterbox = 0;
|
2002-10-12 11:37:38 +00:00
|
|
|
|
2012-03-24 07:52:14 +00:00
|
|
|
if (rv3d->persp==RV3D_CAMOB) {
|
|
|
|
if (startscene->gm.framing.type == SCE_GAMEFRAMING_BARS) { /* Letterbox */
|
2009-10-27 00:25:38 +00:00
|
|
|
camzoom = 1.0f;
|
2011-05-27 16:20:49 +00:00
|
|
|
draw_letterbox = 1;
|
2009-10-27 00:25:38 +00:00
|
|
|
}
|
|
|
|
else {
|
2012-03-07 19:42:22 +00:00
|
|
|
camzoom = 1.0f / BKE_screen_view3d_zoom_to_fac(rv3d->camzoom);
|
2009-10-27 00:25:38 +00:00
|
|
|
}
|
2008-09-15 00:11:30 +00:00
|
|
|
}
|
2009-10-27 00:25:38 +00:00
|
|
|
else {
|
2008-09-15 00:11:30 +00:00
|
|
|
camzoom = 2.0;
|
2009-10-27 00:25:38 +00:00
|
|
|
}
|
2008-09-15 00:11:30 +00:00
|
|
|
|
2009-10-27 00:25:38 +00:00
|
|
|
|
2002-10-12 11:37:38 +00:00
|
|
|
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);
|
|
|
|
|
2012-01-16 06:43:58 +00:00
|
|
|
char basedpath[FILE_MAX];
|
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 != "")
|
2013-08-04 18:12:49 +00:00
|
|
|
BLI_strncpy(basedpath, exitstring.ReadPtr(), sizeof(basedpath));
|
2002-10-12 11:37:38 +00:00
|
|
|
|
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
|
2010-03-09 17:36:23 +00:00
|
|
|
BLI_path_abs(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
|
2013-07-23 12:49:30 +00:00
|
|
|
char temppath[FILE_MAX] = "//";
|
|
|
|
BLI_strncpy(temppath + 2, basedpath, FILE_MAX - 2);
|
2002-10-12 11:37:38 +00:00
|
|
|
|
2010-03-09 17:36:23 +00:00
|
|
|
BLI_path_abs(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
|
|
|
|
2012-03-24 07:52:14 +00:00
|
|
|
if (blenderdata) {
|
2010-10-18 06:41:16 +00:00
|
|
|
BLI_strncpy(G.main->name, blenderdata->name, sizeof(G.main->name));
|
2008-10-11 00:56:49 +00:00
|
|
|
BLI_strncpy(pathname, blenderdata->name, sizeof(pathname));
|
2010-10-31 04:11:39 +00:00
|
|
|
#ifdef WITH_PYTHON
|
2010-10-18 06:41:16 +00:00
|
|
|
setGamePythonPath(G.main->name);
|
2009-09-29 21:42:40 +00:00
|
|
|
#endif
|
2008-10-11 00:56:49 +00:00
|
|
|
}
|
2002-10-12 11:37:38 +00:00
|
|
|
}
|
|
|
|
// else forget it, we can't find it
|
|
|
|
else
|
|
|
|
{
|
|
|
|
exitrequested = KX_EXIT_REQUEST_QUIT_GAME;
|
|
|
|
}
|
|
|
|
}
|
2010-02-22 09:22:36 +00:00
|
|
|
|
2010-06-19 10:47:24 +00:00
|
|
|
Scene *scene= bfd ? bfd->curscene : (Scene *)BLI_findstring(&blenderdata->scene, startscenename, offsetof(ID, name) + 2);
|
2004-10-16 11:41:50 +00:00
|
|
|
|
2010-06-19 10:47:24 +00:00
|
|
|
if (scene)
|
2005-08-23 13:16:02 +00:00
|
|
|
{
|
2010-06-19 10:47:24 +00:00
|
|
|
int startFrame = scene->r.cfra;
|
2010-02-22 12:25:58 +00:00
|
|
|
ketsjiengine->SetAnimRecordMode(animation_record, startFrame);
|
2009-06-08 20:08:19 +00:00
|
|
|
|
|
|
|
// Quad buffered needs a special window.
|
2012-03-28 05:03:24 +00:00
|
|
|
if (scene->gm.stereoflag == STEREO_ENABLED) {
|
2010-06-19 10:47:24 +00:00
|
|
|
if (scene->gm.stereomode != RAS_IRasterizer::RAS_STEREO_QUADBUFFERED)
|
|
|
|
rasterizer->SetStereoMode((RAS_IRasterizer::StereoMode) scene->gm.stereomode);
|
2009-12-29 15:47:20 +00:00
|
|
|
|
2010-06-19 10:47:24 +00:00
|
|
|
rasterizer->SetEyeSeparation(scene->gm.eyeseparation);
|
2009-07-20 22:36:56 +00:00
|
|
|
}
|
2009-10-27 00:25:38 +00:00
|
|
|
|
2010-06-19 10:47:24 +00:00
|
|
|
rasterizer->SetBackColor(scene->gm.framing.col[0], scene->gm.framing.col[1], scene->gm.framing.col[2], 0.0f);
|
2005-08-23 13:16:02 +00:00
|
|
|
}
|
2004-10-16 11:41:50 +00:00
|
|
|
|
2002-10-12 11:37:38 +00:00
|
|
|
if (exitrequested != KX_EXIT_REQUEST_QUIT_GAME)
|
|
|
|
{
|
2009-10-27 02:54:25 +00:00
|
|
|
if (rv3d->persp != RV3D_CAMOB)
|
2002-10-12 11:37:38 +00:00
|
|
|
{
|
|
|
|
ketsjiengine->EnableCameraOverride(startscenename);
|
2009-10-27 02:54:25 +00:00
|
|
|
ketsjiengine->SetCameraOverrideUseOrtho((rv3d->persp == RV3D_ORTHO));
|
2010-11-29 20:57:02 +00:00
|
|
|
ketsjiengine->SetCameraOverrideProjectionMatrix(MT_CmMatrix4x4(rv3d->winmat));
|
|
|
|
ketsjiengine->SetCameraOverrideViewMatrix(MT_CmMatrix4x4(rv3d->viewmat));
|
2012-03-24 07:52:14 +00:00
|
|
|
if (rv3d->persp == RV3D_ORTHO)
|
2011-10-20 06:38:45 +00:00
|
|
|
{
|
2013-02-22 01:48:53 +00:00
|
|
|
ketsjiengine->SetCameraOverrideClipping(v3d->near, v3d->far);
|
2011-10-20 06:38:45 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
ketsjiengine->SetCameraOverrideClipping(v3d->near, v3d->far);
|
|
|
|
}
|
2009-06-09 22:56:43 +00:00
|
|
|
ketsjiengine->SetCameraOverrideLens(v3d->lens);
|
2002-10-12 11:37:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// create a scene converter, create and convert the startingscene
|
2009-06-13 13:02:01 +00:00
|
|
|
KX_ISceneConverter* sceneconverter = new KX_BlenderSceneConverter(blenderdata, 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;
|
|
|
|
|
2012-03-24 07:52:14 +00:00
|
|
|
if (GLEW_ARB_multitexture && GLEW_VERSION_1_1)
|
2008-10-04 17:04:23 +00:00
|
|
|
usemat = true;
|
|
|
|
|
2012-03-24 07:52:14 +00:00
|
|
|
if (GPU_glsl_support())
|
2008-10-04 17:04:23 +00:00
|
|
|
useglslmat = true;
|
2012-03-24 07:52:14 +00:00
|
|
|
else if (gs.matmode == GAME_MAT_GLSL)
|
2008-10-04 17:04:23 +00:00
|
|
|
usemat = false;
|
|
|
|
|
2013-11-04 19:21:50 +00:00
|
|
|
if (usemat)
|
2006-01-06 03:46:54 +00:00
|
|
|
sceneconverter->SetMaterials(true);
|
2012-03-24 07:52:14 +00:00
|
|
|
if (useglslmat && (gs.matmode == GAME_MAT_GLSL))
|
2008-10-11 23:48:37 +00:00
|
|
|
sceneconverter->SetGLSLMaterials(true);
|
2012-12-24 03:13:53 +00:00
|
|
|
if (scene->gm.flag & GAME_NO_MATERIAL_CACHING)
|
|
|
|
sceneconverter->SetCacheMaterials(false);
|
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,
|
Merge of first part of changes from the apricot branch, especially
the features that are needed to run the game. Compile tested with
scons, make, but not cmake, that seems to have an issue not related
to these changes. The changes include:
* GLSL support in the viewport and game engine, enable in the game
menu in textured draw mode.
* Synced and merged part of the duplicated blender and gameengine/
gameplayer drawing code.
* Further refactoring of game engine drawing code, especially mesh
storage changed a lot.
* Optimizations in game engine armatures to avoid recomputations.
* A python function to get the framerate estimate in game.
* An option take object color into account in materials.
* An option to restrict shadow casters to a lamp's layers.
* Increase from 10 to 18 texture slots for materials, lamps, word.
An extra texture slot shows up once the last slot is used.
* Memory limit for undo, not enabled by default yet because it
needs the .B.blend to be changed.
* Multiple undo for image painting.
* An offset for dupligroups, so not all objects in a group have to
be at the origin.
2008-09-04 20:51:28 +00:00
|
|
|
startscenename,
|
2010-06-19 10:47:24 +00:00
|
|
|
scene,
|
2010-04-23 22:48:26 +00:00
|
|
|
canvas);
|
2009-09-29 21:42:40 +00:00
|
|
|
|
2010-10-31 04:11:39 +00:00
|
|
|
#ifdef WITH_PYTHON
|
2002-10-12 11:37:38 +00:00
|
|
|
// some python things
|
2010-01-10 22:03:26 +00:00
|
|
|
PyObject *gameLogic, *gameLogic_keys;
|
|
|
|
setupGamePython(ketsjiengine, startscene, blenderdata, pyGlobalDict, &gameLogic, &gameLogic_keys, 0, NULL);
|
2010-10-31 04:11:39 +00:00
|
|
|
#endif // WITH_PYTHON
|
2002-10-12 11:37:38 +00:00
|
|
|
|
2009-04-20 15:06:46 +00:00
|
|
|
//initialize Dome Settings
|
2012-03-24 07:52:14 +00:00
|
|
|
if (scene->gm.stereoflag == STEREO_DOME)
|
2010-06-19 10:47:24 +00:00
|
|
|
ketsjiengine->InitDome(scene->gm.dome.res, scene->gm.dome.mode, scene->gm.dome.angle, scene->gm.dome.resbuf, scene->gm.dome.tilt, scene->gm.dome.warptext);
|
2009-04-20 15:06:46 +00:00
|
|
|
|
2009-09-20 18:35:14 +00:00
|
|
|
// initialize 3D Audio Settings
|
2011-08-07 11:54:58 +00:00
|
|
|
AUD_I3DDevice* dev = AUD_get3DDevice();
|
2012-03-24 07:52:14 +00:00
|
|
|
if (dev)
|
2011-08-07 11:54:58 +00:00
|
|
|
{
|
|
|
|
dev->setSpeedOfSound(scene->audio.speed_of_sound);
|
|
|
|
dev->setDopplerFactor(scene->audio.doppler_factor);
|
|
|
|
dev->setDistanceModel(AUD_DistanceModel(scene->audio.distance_model));
|
|
|
|
}
|
2009-09-20 18:35:14 +00:00
|
|
|
|
2010-07-08 17:47:46 +00:00
|
|
|
// from see blender.c:
|
|
|
|
// FIXME: this version patching should really be part of the file-reading code,
|
|
|
|
// but we still get too many unrelated data-corruption crashes otherwise...
|
|
|
|
if (blenderdata->versionfile < 250)
|
|
|
|
do_versions_ipos_to_animato(blenderdata);
|
|
|
|
|
2002-10-12 11:37:38 +00:00
|
|
|
if (sceneconverter)
|
|
|
|
{
|
|
|
|
// convert and add scene
|
|
|
|
sceneconverter->ConvertScene(
|
|
|
|
startscene,
|
2013-11-04 19:21:07 +00:00
|
|
|
rasterizer,
|
2002-10-12 11:37:38 +00:00
|
|
|
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
|
2010-02-22 12:25:58 +00:00
|
|
|
ketsjiengine->SetAnimFrameRate(FPS);
|
2008-06-17 10:06:38 +00:00
|
|
|
|
2012-09-04 03:26:12 +00:00
|
|
|
#ifdef WITH_PYTHON
|
2012-09-01 21:23:05 +00:00
|
|
|
char *python_main = NULL;
|
|
|
|
pynextframestate.state = NULL;
|
|
|
|
pynextframestate.func = NULL;
|
|
|
|
python_main = KX_GetPythonMain(scene);
|
2012-09-04 03:26:12 +00:00
|
|
|
|
2002-10-12 11:37:38 +00:00
|
|
|
// the mainloop
|
2010-10-09 13:46:34 +00:00
|
|
|
printf("\nBlender Game Engine Started\n");
|
2012-09-01 21:23:05 +00:00
|
|
|
if (python_main) {
|
|
|
|
char *python_code = KX_GetPythonCode(blenderdata, python_main);
|
|
|
|
if (python_code) {
|
|
|
|
ketsjinextframestate.ketsjiengine = ketsjiengine;
|
|
|
|
ketsjinextframestate.C = C;
|
|
|
|
ketsjinextframestate.win = win;
|
|
|
|
ketsjinextframestate.scene = scene;
|
|
|
|
ketsjinextframestate.ar = ar;
|
|
|
|
ketsjinextframestate.keyboarddevice = keyboarddevice;
|
|
|
|
ketsjinextframestate.mousedevice = mousedevice;
|
|
|
|
ketsjinextframestate.draw_letterbox = draw_letterbox;
|
|
|
|
|
|
|
|
pynextframestate.state = &ketsjinextframestate;
|
2012-09-16 04:58:18 +00:00
|
|
|
pynextframestate.func = &BL_KetsjiPyNextFrame;
|
2012-09-01 21:23:05 +00:00
|
|
|
printf("Yielding control to Python script '%s'...\n", python_main);
|
|
|
|
PyRun_SimpleString(python_code);
|
|
|
|
printf("Exit Python script '%s'\n", python_main);
|
|
|
|
MEM_freeN(python_code);
|
2012-09-04 03:26:12 +00:00
|
|
|
}
|
2012-09-01 21:23:05 +00:00
|
|
|
}
|
2012-09-04 03:26:12 +00:00
|
|
|
else
|
|
|
|
#endif /* WITH_PYTHON */
|
|
|
|
{
|
2012-09-01 21:23:05 +00:00
|
|
|
while (!exitrequested)
|
2002-10-12 11:37:38 +00:00
|
|
|
{
|
2012-09-01 21:23:05 +00:00
|
|
|
exitrequested = BL_KetsjiNextFrame(ketsjiengine, C, win, scene, ar, keyboarddevice, mousedevice, draw_letterbox);
|
2010-11-30 21:51:03 +00:00
|
|
|
}
|
2002-10-12 11:37:38 +00:00
|
|
|
}
|
2010-10-09 13:46:34 +00:00
|
|
|
printf("Blender Game Engine Finished\n");
|
2002-10-12 11:37:38 +00:00
|
|
|
exitstring = ketsjiengine->GetExitString();
|
2012-09-04 03:26:12 +00:00
|
|
|
#ifdef WITH_PYTHON
|
2012-09-01 21:23:05 +00:00
|
|
|
if (python_main) MEM_freeN(python_main);
|
2012-09-04 03:26:12 +00:00
|
|
|
#endif /* WITH_PYTHON */
|
2008-10-10 07:20:42 +00:00
|
|
|
|
2012-09-01 21:23:05 +00:00
|
|
|
gs = *(ketsjiengine->GetGlobalSettings());
|
2008-10-10 07:20:42 +00:00
|
|
|
|
2002-10-12 11:37:38 +00:00
|
|
|
// when exiting the mainloop
|
2010-10-31 04:11:39 +00:00
|
|
|
#ifdef WITH_PYTHON
|
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
|
|
|
|
PyObject *gameLogic_keys_new = PyDict_Keys(PyModule_GetDict(gameLogic));
|
2011-09-06 23:46:20 +00:00
|
|
|
const Py_ssize_t numitems= PyList_GET_SIZE(gameLogic_keys_new);
|
|
|
|
Py_ssize_t listIndex;
|
2012-07-21 22:58:08 +00:00
|
|
|
for (listIndex=0; listIndex < numitems; listIndex++) {
|
2012-09-16 04:58:18 +00:00
|
|
|
PyObject *item = PyList_GET_ITEM(gameLogic_keys_new, listIndex);
|
2008-09-23 00:37:19 +00:00
|
|
|
if (!PySequence_Contains(gameLogic_keys, item)) {
|
|
|
|
PyDict_DelItem( PyModule_GetDict(gameLogic), item);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
Py_DECREF(gameLogic_keys_new);
|
|
|
|
gameLogic_keys_new = NULL;
|
2009-09-29 21:42:40 +00:00
|
|
|
#endif
|
2002-10-12 11:37:38 +00:00
|
|
|
ketsjiengine->StopEngine();
|
2010-10-31 04:11:39 +00:00
|
|
|
#ifdef WITH_PYTHON
|
2006-05-14 03:39:07 +00:00
|
|
|
exitGamePythonScripting();
|
2009-09-29 21:42:40 +00:00
|
|
|
#endif
|
2002-10-12 11:37:38 +00:00
|
|
|
networkdevice->Disconnect();
|
|
|
|
}
|
|
|
|
if (sceneconverter)
|
|
|
|
{
|
|
|
|
delete sceneconverter;
|
|
|
|
sceneconverter = NULL;
|
|
|
|
}
|
2009-09-29 21:42:40 +00:00
|
|
|
|
2010-10-31 04:11:39 +00:00
|
|
|
#ifdef WITH_PYTHON
|
2008-09-23 00:37:19 +00:00
|
|
|
Py_DECREF(gameLogic_keys);
|
|
|
|
gameLogic_keys = NULL;
|
2009-09-29 21:42:40 +00:00
|
|
|
#endif
|
2002-10-12 11:37:38 +00:00
|
|
|
}
|
2008-10-10 07:20:42 +00:00
|
|
|
//lock frame and camera enabled - restoring global values
|
2012-03-28 05:03:24 +00:00
|
|
|
if (v3d->scenelock==0) {
|
2010-06-19 10:47:24 +00:00
|
|
|
startscene->lay= tmp_lay;
|
|
|
|
startscene->camera= tmp_camera;
|
2002-10-12 11:37:38 +00:00
|
|
|
}
|
2008-10-10 07:20:42 +00:00
|
|
|
|
2012-03-24 07:52:14 +00:00
|
|
|
if (exitrequested != KX_EXIT_REQUEST_OUTSIDE)
|
2010-11-30 21:51:03 +00:00
|
|
|
{
|
|
|
|
// set the cursor back to normal
|
|
|
|
canvas->SetMouseState(RAS_ICanvas::MOUSE_NORMAL);
|
2013-04-14 00:40:24 +00:00
|
|
|
|
|
|
|
// set mipmap setting back to its original value
|
|
|
|
rasterizer->SetMipmapping(mipmapval);
|
2010-11-30 21:51:03 +00:00
|
|
|
}
|
2002-10-12 11:37:38 +00:00
|
|
|
|
|
|
|
// clean up some stuff
|
|
|
|
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 (canvas)
|
|
|
|
{
|
2013-07-29 22:31:32 +00:00
|
|
|
canvas->SetSwapInterval(previous_vsync); // Set the swap interval back
|
2002-10-12 11:37:38 +00:00
|
|
|
delete canvas;
|
|
|
|
canvas = NULL;
|
2011-08-07 11:54:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// stop all remaining playing sounds
|
|
|
|
AUD_getDevice()->stopAll();
|
2005-03-25 10:33:39 +00:00
|
|
|
|
2002-10-12 11:37:38 +00:00
|
|
|
} while (exitrequested == KX_EXIT_REQUEST_RESTART_GAME || exitrequested == KX_EXIT_REQUEST_START_OTHER_GAME);
|
2009-04-20 15:06:46 +00:00
|
|
|
|
2010-08-23 20:53:02 +00:00
|
|
|
if (!disableVBO)
|
|
|
|
U.gameflags &= ~USER_DISABLE_VBO;
|
|
|
|
|
2002-10-12 11:37:38 +00:00
|
|
|
if (bfd) BLO_blendfiledata_free(bfd);
|
2008-02-23 12:05:28 +00:00
|
|
|
|
2010-10-18 06:41:16 +00:00
|
|
|
BLI_strncpy(G.main->name, oldsce, sizeof(G.main->name));
|
2008-10-11 00:56:49 +00:00
|
|
|
|
2010-10-31 04:11:39 +00:00
|
|
|
#ifdef WITH_PYTHON
|
2009-09-29 21:42:40 +00:00
|
|
|
Py_DECREF(pyGlobalDict);
|
|
|
|
|
2008-02-23 12:05:28 +00:00
|
|
|
// Release Python's GIL
|
|
|
|
PyGILState_Release(gilstate);
|
2009-09-29 21:42:40 +00:00
|
|
|
#endif
|
|
|
|
|
2002-10-12 11:37:38 +00:00
|
|
|
}
|