2002-10-12 11:37:38 +00:00
|
|
|
/*
|
|
|
|
* $Id$
|
|
|
|
*
|
2008-04-16 22:40:48 +00:00
|
|
|
* ***** BEGIN GPL LICENSE BLOCK *****
|
2002-10-12 11:37:38 +00:00
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
2008-04-16 22:40:48 +00:00
|
|
|
* of the License, or (at your option) any later version.
|
2002-10-12 11:37:38 +00:00
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software Foundation,
|
|
|
|
* 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-04-16 22:40:48 +00:00
|
|
|
* ***** END GPL LICENSE BLOCK *****
|
2002-10-12 11:37:38 +00:00
|
|
|
* The engine ties all game modules together.
|
|
|
|
*/
|
2002-11-25 15:29:57 +00:00
|
|
|
|
2002-10-12 11:37:38 +00:00
|
|
|
#ifdef WIN32
|
|
|
|
#pragma warning (disable : 4786)
|
|
|
|
#endif //WIN32
|
|
|
|
|
|
|
|
#include <iostream>
|
|
|
|
|
|
|
|
#include "KX_KetsjiEngine.h"
|
|
|
|
|
|
|
|
#include "ListValue.h"
|
|
|
|
#include "IntValue.h"
|
|
|
|
#include "VectorValue.h"
|
|
|
|
#include "BoolValue.h"
|
|
|
|
#include "FloatValue.h"
|
|
|
|
|
|
|
|
#define KX_NUM_ITERATIONS 4
|
|
|
|
#include "RAS_BucketManager.h"
|
|
|
|
#include "RAS_Rect.h"
|
|
|
|
#include "RAS_IRasterizer.h"
|
|
|
|
#include "RAS_IRenderTools.h"
|
|
|
|
#include "RAS_ICanvas.h"
|
|
|
|
#include "STR_String.h"
|
|
|
|
#include "MT_Vector3.h"
|
|
|
|
#include "MT_Transform.h"
|
|
|
|
#include "SCA_IInputDevice.h"
|
|
|
|
#include "KX_Scene.h"
|
|
|
|
#include "MT_CmMatrix4x4.h"
|
|
|
|
#include "KX_Camera.h"
|
2008-07-10 12:47:20 +00:00
|
|
|
#include "KX_Light.h"
|
2002-10-12 11:37:38 +00:00
|
|
|
#include "KX_PythonInit.h"
|
|
|
|
#include "KX_PyConstraintBinding.h"
|
|
|
|
#include "PHY_IPhysicsEnvironment.h"
|
2004-10-16 11:41:50 +00:00
|
|
|
#include "SumoPhysicsEnvironment.h"
|
2002-10-12 11:37:38 +00:00
|
|
|
|
|
|
|
#include "SND_Scene.h"
|
|
|
|
#include "SND_IAudioDevice.h"
|
|
|
|
|
|
|
|
#include "NG_NetworkScene.h"
|
|
|
|
#include "NG_NetworkDeviceInterface.h"
|
|
|
|
|
|
|
|
#include "KX_WorldInfo.h"
|
|
|
|
#include "KX_ISceneConverter.h"
|
|
|
|
#include "KX_TimeCategoryLogger.h"
|
|
|
|
|
|
|
|
#include "RAS_FramingManager.h"
|
2008-06-17 10:06:38 +00:00
|
|
|
#include "stdio.h"
|
2002-10-12 11:37:38 +00:00
|
|
|
|
|
|
|
// If define: little test for Nzc: guarded drawing. If the canvas is
|
|
|
|
// not valid, skip rendering this frame.
|
|
|
|
//#define NZC_GUARDED_OUTPUT
|
2006-05-10 02:04:21 +00:00
|
|
|
#define DEFAULT_LOGIC_TIC_RATE 60.0
|
|
|
|
#define DEFAULT_PHYSICS_TIC_RATE 60.0
|
2002-10-12 11:37:38 +00:00
|
|
|
|
|
|
|
const char KX_KetsjiEngine::m_profileLabels[tc_numCategories][15] = {
|
|
|
|
"Physics:", // tc_physics
|
|
|
|
"Logic", // tc_logic
|
|
|
|
"Network:", // tc_network
|
|
|
|
"Scenegraph:", // tc_scenegraph
|
|
|
|
"Sound:", // tc_sound
|
|
|
|
"Rasterizer:", // tc_rasterizer
|
|
|
|
"Services:", // tc_services
|
|
|
|
"Overhead:", // tc_overhead
|
|
|
|
"Outside:" // tc_outside
|
|
|
|
};
|
|
|
|
|
2004-10-16 11:41:50 +00:00
|
|
|
double KX_KetsjiEngine::m_ticrate = DEFAULT_LOGIC_TIC_RATE;
|
2008-06-17 10:06:38 +00:00
|
|
|
double KX_KetsjiEngine::m_anim_framerate = 25.0;
|
2005-12-18 19:10:26 +00:00
|
|
|
double KX_KetsjiEngine::m_suspendedtime = 0.0;
|
|
|
|
double KX_KetsjiEngine::m_suspendeddelta = 0.0;
|
Merge of first part of changes from the apricot branch, especially
the features that are needed to run the game. Compile tested with
scons, make, but not cmake, that seems to have an issue not related
to these changes. The changes include:
* GLSL support in the viewport and game engine, enable in the game
menu in textured draw mode.
* Synced and merged part of the duplicated blender and gameengine/
gameplayer drawing code.
* Further refactoring of game engine drawing code, especially mesh
storage changed a lot.
* Optimizations in game engine armatures to avoid recomputations.
* A python function to get the framerate estimate in game.
* An option take object color into account in materials.
* An option to restrict shadow casters to a lamp's layers.
* Increase from 10 to 18 texture slots for materials, lamps, word.
An extra texture slot shows up once the last slot is used.
* Memory limit for undo, not enabled by default yet because it
needs the .B.blend to be changed.
* Multiple undo for image painting.
* An offset for dupligroups, so not all objects in a group have to
be at the origin.
2008-09-04 20:51:28 +00:00
|
|
|
double KX_KetsjiEngine::m_average_framerate = 0.0;
|
2005-12-18 19:10:26 +00:00
|
|
|
|
2002-10-12 11:37:38 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Constructor of the Ketsji Engine
|
|
|
|
*/
|
|
|
|
KX_KetsjiEngine::KX_KetsjiEngine(KX_ISystem* system)
|
2004-10-16 11:41:50 +00:00
|
|
|
: m_canvas(NULL),
|
2004-03-22 22:02:18 +00:00
|
|
|
m_rasterizer(NULL),
|
2004-10-16 11:41:50 +00:00
|
|
|
m_kxsystem(system),
|
|
|
|
m_rendertools(NULL),
|
|
|
|
m_sceneconverter(NULL),
|
|
|
|
m_networkdevice(NULL),
|
|
|
|
m_audiodevice(NULL),
|
|
|
|
m_pythondictionary(NULL),
|
|
|
|
m_keyboarddevice(NULL),
|
|
|
|
m_mousedevice(NULL),
|
|
|
|
|
|
|
|
m_propertiesPresent(false),
|
|
|
|
|
2004-03-22 22:02:18 +00:00
|
|
|
m_bInitialized(false),
|
2004-10-16 11:41:50 +00:00
|
|
|
m_activecam(0),
|
|
|
|
m_bFixedTime(false),
|
|
|
|
|
|
|
|
m_firstframe(true),
|
|
|
|
|
2006-01-12 06:30:01 +00:00
|
|
|
m_frameTime(0.f),
|
|
|
|
m_clockTime(0.f),
|
|
|
|
m_previousClockTime(0.f),
|
|
|
|
|
2002-10-12 11:37:38 +00:00
|
|
|
|
2004-10-16 11:41:50 +00:00
|
|
|
m_exitcode(KX_EXIT_REQUEST_NO_REQUEST),
|
|
|
|
m_exitstring(""),
|
|
|
|
|
|
|
|
m_drawingmode(5),
|
|
|
|
m_cameraZoom(1.0),
|
|
|
|
|
|
|
|
m_overrideCam(false),
|
|
|
|
m_overrideCamUseOrtho(false),
|
2008-09-15 00:11:30 +00:00
|
|
|
m_overrideCamNear(0.0),
|
|
|
|
m_overrideCamFar(0.0),
|
2002-10-12 11:37:38 +00:00
|
|
|
|
2004-10-16 11:41:50 +00:00
|
|
|
m_stereo(false),
|
|
|
|
m_curreye(0),
|
2002-10-12 11:37:38 +00:00
|
|
|
|
2004-10-16 11:41:50 +00:00
|
|
|
m_logger(NULL),
|
|
|
|
|
2002-10-12 11:37:38 +00:00
|
|
|
// Set up timing info display variables
|
2004-10-16 11:41:50 +00:00
|
|
|
m_show_framerate(false),
|
|
|
|
m_show_profile(false),
|
|
|
|
m_showProperties(false),
|
|
|
|
m_showBackground(false),
|
|
|
|
m_show_debug_properties(false),
|
2002-10-12 11:37:38 +00:00
|
|
|
|
2008-07-29 15:48:31 +00:00
|
|
|
m_game2ipo(false),
|
|
|
|
|
2002-10-12 11:37:38 +00:00
|
|
|
// Default behavior is to hide the cursor every frame.
|
2004-10-16 11:41:50 +00:00
|
|
|
m_hideCursor(false),
|
2002-10-12 11:37:38 +00:00
|
|
|
|
2004-10-16 11:41:50 +00:00
|
|
|
m_overrideFrameColor(false),
|
|
|
|
m_overrideFrameColorR(0.0),
|
|
|
|
m_overrideFrameColorG(0.0),
|
|
|
|
m_overrideFrameColorB(0.0)
|
|
|
|
{
|
|
|
|
// Initialize the time logger
|
|
|
|
m_logger = new KX_TimeCategoryLogger (25);
|
2002-10-12 11:37:38 +00:00
|
|
|
|
2004-10-16 11:41:50 +00:00
|
|
|
for (int i = tc_first; i < tc_numCategories; i++)
|
|
|
|
m_logger->AddCategory((KX_TimeCategory)i);
|
|
|
|
|
2002-10-12 11:37:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Destructor of the Ketsji Engine, release all memory
|
|
|
|
*/
|
|
|
|
KX_KetsjiEngine::~KX_KetsjiEngine()
|
|
|
|
{
|
2004-10-16 11:41:50 +00:00
|
|
|
delete m_logger;
|
2002-10-12 11:37:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void KX_KetsjiEngine::SetKeyboardDevice(SCA_IInputDevice* keyboarddevice)
|
|
|
|
{
|
2005-03-25 10:33:39 +00:00
|
|
|
MT_assert(keyboarddevice);
|
2002-10-12 11:37:38 +00:00
|
|
|
m_keyboarddevice = keyboarddevice;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void KX_KetsjiEngine::SetMouseDevice(SCA_IInputDevice* mousedevice)
|
|
|
|
{
|
2005-03-25 10:33:39 +00:00
|
|
|
MT_assert(mousedevice);
|
2002-10-12 11:37:38 +00:00
|
|
|
m_mousedevice = mousedevice;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void KX_KetsjiEngine::SetNetworkDevice(NG_NetworkDeviceInterface* networkdevice)
|
|
|
|
{
|
2005-03-25 10:33:39 +00:00
|
|
|
MT_assert(networkdevice);
|
2002-10-12 11:37:38 +00:00
|
|
|
m_networkdevice = networkdevice;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void KX_KetsjiEngine::SetAudioDevice(SND_IAudioDevice* audiodevice)
|
|
|
|
{
|
2005-03-25 10:33:39 +00:00
|
|
|
MT_assert(audiodevice);
|
2002-10-12 11:37:38 +00:00
|
|
|
m_audiodevice = audiodevice;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void KX_KetsjiEngine::SetCanvas(RAS_ICanvas* canvas)
|
|
|
|
{
|
2005-03-25 10:33:39 +00:00
|
|
|
MT_assert(canvas);
|
2002-10-12 11:37:38 +00:00
|
|
|
m_canvas = canvas;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void KX_KetsjiEngine::SetRenderTools(RAS_IRenderTools* rendertools)
|
|
|
|
{
|
2005-03-25 10:33:39 +00:00
|
|
|
MT_assert(rendertools);
|
2002-10-12 11:37:38 +00:00
|
|
|
m_rendertools = rendertools;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void KX_KetsjiEngine::SetRasterizer(RAS_IRasterizer* rasterizer)
|
|
|
|
{
|
2005-03-25 10:33:39 +00:00
|
|
|
MT_assert(rasterizer);
|
2002-10-12 11:37:38 +00:00
|
|
|
m_rasterizer = rasterizer;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-07-14 00:47:07 +00:00
|
|
|
/*
|
|
|
|
* At the moment the GameLogic module is imported into 'pythondictionary' after this function is called.
|
|
|
|
* if this function ever changes to assign a copy, make sure the game logic module is imported into this dictionary before hand.
|
|
|
|
*/
|
2002-10-12 11:37:38 +00:00
|
|
|
void KX_KetsjiEngine::SetPythonDictionary(PyObject* pythondictionary)
|
|
|
|
{
|
2005-03-25 10:33:39 +00:00
|
|
|
MT_assert(pythondictionary);
|
2002-10-12 11:37:38 +00:00
|
|
|
m_pythondictionary = pythondictionary;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void KX_KetsjiEngine::SetSceneConverter(KX_ISceneConverter* sceneconverter)
|
|
|
|
{
|
2005-03-25 10:33:39 +00:00
|
|
|
MT_assert(sceneconverter);
|
2002-10-12 11:37:38 +00:00
|
|
|
m_sceneconverter = sceneconverter;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Ketsji Init(), Initializes datastructures and converts data from
|
|
|
|
* Blender into Ketsji native (realtime) format also sets up the
|
|
|
|
* graphics context
|
|
|
|
*/
|
2006-11-30 00:19:27 +00:00
|
|
|
void KX_KetsjiEngine::StartEngine(bool clearIpo)
|
2002-10-12 11:37:38 +00:00
|
|
|
{
|
2006-12-03 01:16:17 +00:00
|
|
|
m_clockTime = m_kxsystem->GetTimeInSeconds();
|
|
|
|
m_frameTime = m_kxsystem->GetTimeInSeconds();
|
|
|
|
m_previousClockTime = m_kxsystem->GetTimeInSeconds();
|
2006-01-12 06:30:01 +00:00
|
|
|
|
2002-10-12 11:37:38 +00:00
|
|
|
m_firstframe = true;
|
|
|
|
m_bInitialized = true;
|
2004-10-16 11:41:50 +00:00
|
|
|
m_ticrate = DEFAULT_LOGIC_TIC_RATE;
|
2006-05-10 00:05:49 +00:00
|
|
|
|
2006-01-12 06:30:01 +00:00
|
|
|
if (m_game2ipo)
|
|
|
|
{
|
2006-11-30 00:19:27 +00:00
|
|
|
m_sceneconverter->ResetPhysicsObjectsAnimationIpo(clearIpo);
|
2006-05-10 00:05:49 +00:00
|
|
|
m_sceneconverter->WritePhysicsObjectToAnimationIpo(m_currentFrame);
|
2006-01-12 06:30:01 +00:00
|
|
|
}
|
2005-08-22 18:31:19 +00:00
|
|
|
|
2002-10-12 11:37:38 +00:00
|
|
|
}
|
|
|
|
|
2008-09-14 00:32:18 +00:00
|
|
|
void KX_KetsjiEngine::ClearFrame()
|
2002-10-12 11:37:38 +00:00
|
|
|
{
|
2008-09-14 00:32:18 +00:00
|
|
|
// clear unless we're drawing overlapping stereo
|
|
|
|
if(m_rasterizer->InterlacedStereo() &&
|
|
|
|
m_rasterizer->GetEye() == RAS_IRasterizer::RAS_STEREO_RIGHTEYE)
|
|
|
|
return;
|
2002-10-12 11:37:38 +00:00
|
|
|
|
2008-09-14 00:32:18 +00:00
|
|
|
// clear the viewports with the background color of the first scene
|
|
|
|
bool doclear = false;
|
|
|
|
KX_SceneList::iterator sceneit;
|
|
|
|
RAS_Rect clearvp, area, viewport;
|
2002-10-12 11:37:38 +00:00
|
|
|
|
2008-09-14 00:32:18 +00:00
|
|
|
for (sceneit = m_scenes.begin(); sceneit != m_scenes.end(); sceneit++)
|
|
|
|
{
|
|
|
|
KX_Scene* scene = *sceneit;
|
|
|
|
//const RAS_FrameSettings &framesettings = scene->GetFramingType();
|
|
|
|
list<class KX_Camera*>* cameras = scene->GetCameras();
|
2002-10-12 11:37:38 +00:00
|
|
|
|
2008-09-14 00:32:18 +00:00
|
|
|
list<KX_Camera*>::iterator it;
|
|
|
|
for(it = cameras->begin(); it != cameras->end(); it++)
|
|
|
|
{
|
2008-09-18 01:46:28 +00:00
|
|
|
GetSceneViewport(scene, (*it), area, viewport);
|
2008-09-14 00:32:18 +00:00
|
|
|
|
|
|
|
if(!doclear) {
|
|
|
|
clearvp = viewport;
|
|
|
|
doclear = true;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
if(viewport.GetLeft() < clearvp.GetLeft())
|
|
|
|
clearvp.SetLeft(viewport.GetLeft());
|
|
|
|
if(viewport.GetBottom() < clearvp.GetBottom())
|
|
|
|
clearvp.SetBottom(viewport.GetBottom());
|
|
|
|
if(viewport.GetRight() > clearvp.GetRight())
|
|
|
|
clearvp.SetRight(viewport.GetRight());
|
|
|
|
if(viewport.GetTop() > clearvp.GetTop())
|
|
|
|
clearvp.SetTop(viewport.GetTop());
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if(doclear) {
|
|
|
|
KX_Scene* firstscene = *m_scenes.begin();
|
|
|
|
SetBackGround(firstscene->GetWorldInfo());
|
|
|
|
|
|
|
|
m_canvas->SetViewPort(clearvp.GetLeft(), clearvp.GetBottom(),
|
|
|
|
clearvp.GetRight(), clearvp.GetTop());
|
|
|
|
m_rasterizer->ClearColorBuffer();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
bool KX_KetsjiEngine::BeginFrame()
|
|
|
|
{
|
|
|
|
// set the area used for rendering (stereo can assign only a subset)
|
|
|
|
m_rasterizer->SetRenderArea();
|
2002-10-12 11:37:38 +00:00
|
|
|
|
|
|
|
if (m_canvas->BeginDraw())
|
|
|
|
{
|
2008-09-14 00:32:18 +00:00
|
|
|
ClearFrame();
|
2002-10-12 11:37:38 +00:00
|
|
|
|
2008-09-14 00:32:18 +00:00
|
|
|
m_rasterizer->BeginFrame(m_drawingmode , m_kxsystem->GetTimeInSeconds());
|
|
|
|
m_rendertools->BeginFrame(m_rasterizer);
|
|
|
|
|
|
|
|
return true;
|
2002-10-12 11:37:38 +00:00
|
|
|
}
|
|
|
|
|
2008-09-14 00:32:18 +00:00
|
|
|
return false;
|
2002-10-12 11:37:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void KX_KetsjiEngine::EndFrame()
|
|
|
|
{
|
|
|
|
// Show profiling info
|
|
|
|
m_logger->StartLog(tc_overhead, m_kxsystem->GetTimeInSeconds(), true);
|
|
|
|
if (m_show_framerate || m_show_profile || (m_show_debug_properties && m_propertiesPresent))
|
|
|
|
{
|
|
|
|
RenderDebugProperties();
|
|
|
|
}
|
Merge of first part of changes from the apricot branch, especially
the features that are needed to run the game. Compile tested with
scons, make, but not cmake, that seems to have an issue not related
to these changes. The changes include:
* GLSL support in the viewport and game engine, enable in the game
menu in textured draw mode.
* Synced and merged part of the duplicated blender and gameengine/
gameplayer drawing code.
* Further refactoring of game engine drawing code, especially mesh
storage changed a lot.
* Optimizations in game engine armatures to avoid recomputations.
* A python function to get the framerate estimate in game.
* An option take object color into account in materials.
* An option to restrict shadow casters to a lamp's layers.
* Increase from 10 to 18 texture slots for materials, lamps, word.
An extra texture slot shows up once the last slot is used.
* Memory limit for undo, not enabled by default yet because it
needs the .B.blend to be changed.
* Multiple undo for image painting.
* An offset for dupligroups, so not all objects in a group have to
be at the origin.
2008-09-04 20:51:28 +00:00
|
|
|
|
|
|
|
m_average_framerate = m_logger->GetAverage();
|
|
|
|
if (m_average_framerate < 1e-6)
|
|
|
|
m_average_framerate = 1e-6;
|
|
|
|
m_average_framerate = 1.0/m_average_framerate;
|
|
|
|
|
2002-10-12 11:37:38 +00:00
|
|
|
// Go to next profiling measurement, time spend after this call is shown in the next frame.
|
|
|
|
m_logger->NextMeasurement(m_kxsystem->GetTimeInSeconds());
|
|
|
|
|
|
|
|
m_logger->StartLog(tc_rasterizer, m_kxsystem->GetTimeInSeconds(), true);
|
|
|
|
m_rasterizer->EndFrame();
|
|
|
|
// swap backbuffer (drawing into this buffer) <-> front/visible buffer
|
|
|
|
m_rasterizer->SwapBuffers();
|
|
|
|
m_rendertools->EndFrame(m_rasterizer);
|
2006-12-02 22:25:47 +00:00
|
|
|
|
2002-10-12 11:37:38 +00:00
|
|
|
|
|
|
|
m_canvas->EndDraw();
|
|
|
|
}
|
|
|
|
|
2006-12-02 22:25:47 +00:00
|
|
|
//#include "PIL_time.h"
|
|
|
|
//#include "LinearMath/btQuickprof.h"
|
2002-10-12 11:37:38 +00:00
|
|
|
|
2006-12-02 22:25:47 +00:00
|
|
|
|
|
|
|
bool KX_KetsjiEngine::NextFrame()
|
2002-10-12 11:37:38 +00:00
|
|
|
{
|
2006-12-02 22:25:47 +00:00
|
|
|
|
|
|
|
// static hidden::Clock sClock;
|
|
|
|
|
|
|
|
m_logger->StartLog(tc_services, m_kxsystem->GetTimeInSeconds(),true);
|
|
|
|
|
|
|
|
//float dt = sClock.getTimeMicroseconds() * 0.000001f;
|
|
|
|
//sClock.reset();
|
|
|
|
|
|
|
|
if (m_bFixedTime)
|
|
|
|
m_clockTime += 1./m_ticrate;
|
|
|
|
else
|
|
|
|
{
|
|
|
|
|
|
|
|
// m_clockTime += dt;
|
|
|
|
m_clockTime = m_kxsystem->GetTimeInSeconds();
|
|
|
|
}
|
2005-07-16 21:47:54 +00:00
|
|
|
|
2006-01-12 06:30:01 +00:00
|
|
|
double deltatime = m_clockTime - m_frameTime;
|
2006-02-13 06:28:35 +00:00
|
|
|
if (deltatime<0.f)
|
|
|
|
{
|
|
|
|
printf("problem with clock\n");
|
|
|
|
deltatime = 0.f;
|
|
|
|
m_clockTime = 0.f;
|
|
|
|
m_frameTime = 0.f;
|
|
|
|
}
|
2002-10-12 11:37:38 +00:00
|
|
|
|
2006-12-02 22:25:47 +00:00
|
|
|
|
2004-10-16 11:41:50 +00:00
|
|
|
// Compute the number of logic frames to do each update (fixed tic bricks)
|
2006-01-12 06:30:01 +00:00
|
|
|
int frames =int(deltatime*m_ticrate);
|
2006-12-02 22:25:47 +00:00
|
|
|
// if (frames>1)
|
|
|
|
// printf("****************************************");
|
|
|
|
// printf("dt = %f, deltatime = %f, frames = %d\n",dt, deltatime,frames);
|
2006-01-12 06:30:01 +00:00
|
|
|
|
|
|
|
// if (!frames)
|
2006-12-02 22:25:47 +00:00
|
|
|
// PIL_sleep_ms(1);
|
2004-10-16 11:41:50 +00:00
|
|
|
|
2002-10-12 11:37:38 +00:00
|
|
|
KX_SceneList::iterator sceneit;
|
2006-02-13 06:28:35 +00:00
|
|
|
int frameOut = 5;
|
2004-10-16 11:41:50 +00:00
|
|
|
|
2006-02-13 06:28:35 +00:00
|
|
|
if (frames>frameOut)
|
|
|
|
{
|
2006-12-02 22:25:47 +00:00
|
|
|
|
|
|
|
// printf("framedOut: %d\n",frames);
|
2006-02-13 06:28:35 +00:00
|
|
|
m_frameTime+=(frames-frameOut)*(1.0/m_ticrate);
|
|
|
|
frames = frameOut;
|
|
|
|
}
|
2006-12-02 22:25:47 +00:00
|
|
|
|
|
|
|
|
|
|
|
bool doRender = frames>0;
|
|
|
|
|
2004-11-22 10:19:19 +00:00
|
|
|
while (frames)
|
2004-10-16 11:41:50 +00:00
|
|
|
{
|
2006-12-02 22:25:47 +00:00
|
|
|
|
2005-07-16 21:47:54 +00:00
|
|
|
|
2006-12-02 23:27:23 +00:00
|
|
|
m_frameTime += 1.0/m_ticrate;
|
2006-01-12 06:30:01 +00:00
|
|
|
|
2004-11-06 04:58:10 +00:00
|
|
|
for (sceneit = m_scenes.begin();sceneit != m_scenes.end(); ++sceneit)
|
2004-10-16 11:41:50 +00:00
|
|
|
// for each scene, call the proceed functions
|
|
|
|
{
|
|
|
|
KX_Scene* scene = *sceneit;
|
|
|
|
|
|
|
|
/* Suspension holds the physics and logic processing for an
|
|
|
|
* entire scene. Objects can be suspended individually, and
|
|
|
|
* the settings for that preceed the logic and physics
|
|
|
|
* update. */
|
2002-10-12 11:37:38 +00:00
|
|
|
m_logger->StartLog(tc_logic, m_kxsystem->GetTimeInSeconds(), true);
|
2006-12-16 05:50:38 +00:00
|
|
|
|
|
|
|
m_sceneconverter->resetNoneDynamicObjectToIpo();//this is for none dynamic objects with ipo
|
|
|
|
|
2004-10-16 11:41:50 +00:00
|
|
|
scene->UpdateObjectActivity();
|
|
|
|
|
|
|
|
if (!scene->IsSuspended())
|
|
|
|
{
|
2005-12-18 19:10:26 +00:00
|
|
|
// if the scene was suspended recalcutlate the delta tu "curtime"
|
|
|
|
m_suspendedtime = scene->getSuspendedTime();
|
|
|
|
if (scene->getSuspendedTime()!=0.0)
|
2006-01-12 06:30:01 +00:00
|
|
|
scene->setSuspendedDelta(scene->getSuspendedDelta()+m_clockTime-scene->getSuspendedTime());
|
2005-12-18 19:10:26 +00:00
|
|
|
m_suspendeddelta = scene->getSuspendedDelta();
|
|
|
|
|
2005-12-31 21:59:56 +00:00
|
|
|
|
2004-10-16 11:41:50 +00:00
|
|
|
m_logger->StartLog(tc_network, m_kxsystem->GetTimeInSeconds(), true);
|
2006-01-12 06:30:01 +00:00
|
|
|
scene->GetNetworkScene()->proceed(m_frameTime);
|
2004-10-16 11:41:50 +00:00
|
|
|
|
2005-12-31 21:59:56 +00:00
|
|
|
m_logger->StartLog(tc_scenegraph, m_kxsystem->GetTimeInSeconds(), true);
|
2006-01-12 06:30:01 +00:00
|
|
|
scene->UpdateParents(m_frameTime);
|
2005-12-31 21:59:56 +00:00
|
|
|
|
|
|
|
m_logger->StartLog(tc_physics, m_kxsystem->GetTimeInSeconds(), true);
|
2004-10-16 11:41:50 +00:00
|
|
|
// set Python hooks for each scene
|
|
|
|
PHY_SetActiveEnvironment(scene->GetPhysicsEnvironment());
|
|
|
|
PHY_SetActiveScene(scene);
|
|
|
|
|
2004-11-22 10:19:19 +00:00
|
|
|
scene->GetPhysicsEnvironment()->endFrame();
|
|
|
|
|
2004-11-06 12:31:56 +00:00
|
|
|
// Update scenegraph after physics step. This maps physics calculations
|
|
|
|
// into node positions.
|
|
|
|
m_logger->StartLog(tc_scenegraph, m_kxsystem->GetTimeInSeconds(), true);
|
2006-01-12 06:30:01 +00:00
|
|
|
scene->UpdateParents(m_frameTime);
|
2004-11-06 12:31:56 +00:00
|
|
|
|
2004-10-16 11:41:50 +00:00
|
|
|
// Process sensors, and controllers
|
|
|
|
m_logger->StartLog(tc_logic, m_kxsystem->GetTimeInSeconds(), true);
|
2006-01-12 06:30:01 +00:00
|
|
|
scene->LogicBeginFrame(m_frameTime);
|
2004-10-16 11:41:50 +00:00
|
|
|
|
|
|
|
// Scenegraph needs to be updated again, because Logic Controllers
|
|
|
|
// can affect the local matrices.
|
|
|
|
m_logger->StartLog(tc_scenegraph, m_kxsystem->GetTimeInSeconds(), true);
|
2006-01-12 06:30:01 +00:00
|
|
|
scene->UpdateParents(m_frameTime);
|
2004-10-16 11:41:50 +00:00
|
|
|
|
|
|
|
// Process actuators
|
|
|
|
|
|
|
|
// Do some cleanup work for this logic frame
|
|
|
|
m_logger->StartLog(tc_logic, m_kxsystem->GetTimeInSeconds(), true);
|
2006-01-12 06:30:01 +00:00
|
|
|
scene->LogicUpdateFrame(m_frameTime, true);
|
2006-12-02 22:25:47 +00:00
|
|
|
|
2004-10-16 11:41:50 +00:00
|
|
|
scene->LogicEndFrame();
|
|
|
|
|
|
|
|
// Actuators can affect the scenegraph
|
|
|
|
m_logger->StartLog(tc_scenegraph, m_kxsystem->GetTimeInSeconds(), true);
|
2006-01-12 06:30:01 +00:00
|
|
|
scene->UpdateParents(m_frameTime);
|
2004-11-22 10:19:19 +00:00
|
|
|
|
2005-12-31 21:59:56 +00:00
|
|
|
m_logger->StartLog(tc_physics, m_kxsystem->GetTimeInSeconds(), true);
|
2004-11-22 10:19:19 +00:00
|
|
|
scene->GetPhysicsEnvironment()->beginFrame();
|
|
|
|
|
|
|
|
// Perform physics calculations on the scene. This can involve
|
|
|
|
// many iterations of the physics solver.
|
2006-01-12 06:30:01 +00:00
|
|
|
scene->GetPhysicsEnvironment()->proceedDeltaTime(m_frameTime,1.0/m_ticrate);//m_deltatimerealDeltaTime);
|
2005-08-22 18:31:19 +00:00
|
|
|
|
2006-01-12 06:30:01 +00:00
|
|
|
m_logger->StartLog(tc_scenegraph, m_kxsystem->GetTimeInSeconds(), true);
|
|
|
|
scene->UpdateParents(m_frameTime);
|
|
|
|
|
|
|
|
|
2005-08-23 13:16:02 +00:00
|
|
|
if (m_game2ipo)
|
2006-12-16 05:50:38 +00:00
|
|
|
{
|
2006-05-10 00:05:49 +00:00
|
|
|
m_sceneconverter->WritePhysicsObjectToAnimationIpo(++m_currentFrame);
|
2005-08-23 13:16:02 +00:00
|
|
|
}
|
2005-08-22 18:31:19 +00:00
|
|
|
|
2005-12-18 19:10:26 +00:00
|
|
|
scene->setSuspendedTime(0.0);
|
2004-10-16 11:41:50 +00:00
|
|
|
} // suspended
|
2005-12-18 19:10:26 +00:00
|
|
|
else
|
|
|
|
if(scene->getSuspendedTime()==0.0)
|
2006-01-12 06:30:01 +00:00
|
|
|
scene->setSuspendedTime(m_clockTime);
|
2004-10-16 11:41:50 +00:00
|
|
|
|
|
|
|
DoSound(scene);
|
2006-12-02 22:25:47 +00:00
|
|
|
|
2004-10-16 11:41:50 +00:00
|
|
|
m_logger->StartLog(tc_services, m_kxsystem->GetTimeInSeconds(), true);
|
|
|
|
}
|
2002-10-12 11:37:38 +00:00
|
|
|
|
2004-10-16 11:41:50 +00:00
|
|
|
// update system devices
|
|
|
|
m_logger->StartLog(tc_logic, m_kxsystem->GetTimeInSeconds(), true);
|
|
|
|
if (m_keyboarddevice)
|
|
|
|
m_keyboarddevice->NextFrame();
|
|
|
|
|
|
|
|
if (m_mousedevice)
|
|
|
|
m_mousedevice->NextFrame();
|
|
|
|
|
|
|
|
if (m_networkdevice)
|
|
|
|
m_networkdevice->NextFrame();
|
|
|
|
|
|
|
|
if (m_audiodevice)
|
|
|
|
m_audiodevice->NextFrame();
|
|
|
|
|
|
|
|
// scene management
|
|
|
|
ProcessScheduledScenes();
|
2004-11-22 10:19:19 +00:00
|
|
|
|
|
|
|
frames--;
|
2002-10-12 11:37:38 +00:00
|
|
|
}
|
|
|
|
|
2006-12-02 22:25:47 +00:00
|
|
|
bool bUseAsyncLogicBricks= false;//true;
|
2004-11-22 10:19:19 +00:00
|
|
|
|
2006-01-18 06:04:11 +00:00
|
|
|
if (bUseAsyncLogicBricks)
|
2006-01-12 06:30:01 +00:00
|
|
|
{
|
|
|
|
// Logic update sub frame: this will let some logic bricks run at the
|
|
|
|
// full frame rate.
|
|
|
|
for (sceneit = m_scenes.begin();sceneit != m_scenes.end(); ++sceneit)
|
|
|
|
// for each scene, call the proceed functions
|
2004-11-22 10:19:19 +00:00
|
|
|
{
|
2006-01-12 06:30:01 +00:00
|
|
|
KX_Scene* scene = *sceneit;
|
|
|
|
|
|
|
|
if (!scene->IsSuspended())
|
|
|
|
{
|
|
|
|
// if the scene was suspended recalcutlate the delta tu "curtime"
|
|
|
|
m_suspendedtime = scene->getSuspendedTime();
|
|
|
|
if (scene->getSuspendedTime()!=0.0)
|
|
|
|
scene->setSuspendedDelta(scene->getSuspendedDelta()+m_clockTime-scene->getSuspendedTime());
|
|
|
|
m_suspendeddelta = scene->getSuspendedDelta();
|
|
|
|
|
|
|
|
// set Python hooks for each scene
|
|
|
|
PHY_SetActiveEnvironment(scene->GetPhysicsEnvironment());
|
|
|
|
PHY_SetActiveScene(scene);
|
|
|
|
|
|
|
|
m_logger->StartLog(tc_scenegraph, m_kxsystem->GetTimeInSeconds(), true);
|
|
|
|
scene->UpdateParents(m_clockTime);
|
|
|
|
|
|
|
|
// Perform physics calculations on the scene. This can involve
|
|
|
|
// many iterations of the physics solver.
|
|
|
|
m_logger->StartLog(tc_physics, m_kxsystem->GetTimeInSeconds(), true);
|
|
|
|
scene->GetPhysicsEnvironment()->proceedDeltaTime(m_clockTime,0.f);
|
|
|
|
// Update scenegraph after physics step. This maps physics calculations
|
|
|
|
// into node positions.
|
|
|
|
m_logger->StartLog(tc_scenegraph, m_kxsystem->GetTimeInSeconds(), true);
|
|
|
|
scene->UpdateParents(m_clockTime);
|
|
|
|
|
|
|
|
// Do some cleanup work for this logic frame
|
|
|
|
m_logger->StartLog(tc_logic, m_kxsystem->GetTimeInSeconds(), true);
|
|
|
|
scene->LogicUpdateFrame(m_clockTime, false);
|
2004-11-22 10:19:19 +00:00
|
|
|
|
2006-01-12 06:30:01 +00:00
|
|
|
// Actuators can affect the scenegraph
|
|
|
|
m_logger->StartLog(tc_scenegraph, m_kxsystem->GetTimeInSeconds(), true);
|
|
|
|
scene->UpdateParents(m_clockTime);
|
|
|
|
|
|
|
|
scene->setSuspendedTime(0.0);
|
|
|
|
} // suspended
|
|
|
|
else
|
|
|
|
if(scene->getSuspendedTime()==0.0)
|
|
|
|
scene->setSuspendedTime(m_clockTime);
|
2004-11-22 10:19:19 +00:00
|
|
|
|
2006-01-12 06:30:01 +00:00
|
|
|
DoSound(scene);
|
2004-11-22 10:19:19 +00:00
|
|
|
|
2006-01-12 06:30:01 +00:00
|
|
|
m_logger->StartLog(tc_services, m_kxsystem->GetTimeInSeconds(), true);
|
|
|
|
}
|
2004-11-22 10:19:19 +00:00
|
|
|
}
|
2006-01-12 06:30:01 +00:00
|
|
|
|
|
|
|
|
|
|
|
m_previousClockTime = m_clockTime;
|
2004-11-22 10:19:19 +00:00
|
|
|
|
2002-10-12 11:37:38 +00:00
|
|
|
// Start logging time spend outside main loop
|
|
|
|
m_logger->StartLog(tc_outside, m_kxsystem->GetTimeInSeconds(), true);
|
2006-12-02 22:25:47 +00:00
|
|
|
|
|
|
|
return doRender;
|
2002-10-12 11:37:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void KX_KetsjiEngine::Render()
|
|
|
|
{
|
|
|
|
KX_Scene* firstscene = *m_scenes.begin();
|
|
|
|
const RAS_FrameSettings &framesettings = firstscene->GetFramingType();
|
|
|
|
|
|
|
|
m_logger->StartLog(tc_rasterizer, m_kxsystem->GetTimeInSeconds(), true);
|
|
|
|
|
|
|
|
// hiding mouse cursor each frame
|
|
|
|
// (came back when going out of focus and then back in again)
|
|
|
|
if (m_hideCursor)
|
|
|
|
m_canvas->SetMouseState(RAS_ICanvas::MOUSE_INVISIBLE);
|
|
|
|
|
|
|
|
// clear the entire game screen with the border color
|
|
|
|
// only once per frame
|
|
|
|
m_canvas->BeginDraw();
|
|
|
|
if (m_drawingmode == RAS_IRasterizer::KX_TEXTURED) {
|
|
|
|
m_canvas->SetViewPort(0, 0, m_canvas->GetWidth(), m_canvas->GetHeight());
|
|
|
|
if (m_overrideFrameColor)
|
|
|
|
{
|
|
|
|
// Do not use the framing bar color set in the Blender scenes
|
|
|
|
m_canvas->ClearColor(
|
|
|
|
m_overrideFrameColorR,
|
|
|
|
m_overrideFrameColorG,
|
|
|
|
m_overrideFrameColorB,
|
|
|
|
1.0
|
|
|
|
);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// Use the framing bar color set in the Blender scenes
|
|
|
|
m_canvas->ClearColor(
|
|
|
|
framesettings.BarRed(),
|
|
|
|
framesettings.BarGreen(),
|
|
|
|
framesettings.BarBlue(),
|
|
|
|
1.0
|
|
|
|
);
|
|
|
|
}
|
|
|
|
// clear the -whole- viewport
|
2008-09-14 00:32:18 +00:00
|
|
|
m_canvas->ClearBuffer(RAS_ICanvas::COLOR_BUFFER|RAS_ICanvas::DEPTH_BUFFER);
|
2002-10-12 11:37:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
m_rasterizer->SetEye(RAS_IRasterizer::RAS_STEREO_LEFTEYE);
|
|
|
|
|
|
|
|
// BeginFrame() sets the actual drawing area. You can use a part of the window
|
|
|
|
if (!BeginFrame())
|
|
|
|
return;
|
|
|
|
|
|
|
|
KX_SceneList::iterator sceneit;
|
|
|
|
for (sceneit = m_scenes.begin();sceneit != m_scenes.end(); sceneit++)
|
|
|
|
// for each scene, call the proceed functions
|
|
|
|
{
|
|
|
|
KX_Scene* scene = *sceneit;
|
2006-01-06 03:46:54 +00:00
|
|
|
KX_Camera* cam = scene->GetActiveCamera();
|
2002-10-12 11:37:38 +00:00
|
|
|
// pass the scene's worldsettings to the rasterizer
|
|
|
|
SetWorldSettings(scene->GetWorldInfo());
|
|
|
|
|
2008-07-10 12:47:20 +00:00
|
|
|
// shadow buffers
|
|
|
|
RenderShadowBuffers(scene);
|
|
|
|
|
2006-01-06 03:46:54 +00:00
|
|
|
// Avoid drawing the scene with the active camera twice when it's viewport is enabled
|
2008-03-21 22:44:12 +00:00
|
|
|
if(cam && !cam->GetViewport())
|
2006-01-06 03:46:54 +00:00
|
|
|
{
|
|
|
|
if (scene->IsClearingZBuffer())
|
|
|
|
m_rasterizer->ClearDepthBuffer();
|
|
|
|
|
|
|
|
m_rendertools->SetAuxilaryClientInfo(scene);
|
|
|
|
|
|
|
|
// do the rendering
|
|
|
|
RenderFrame(scene, cam);
|
|
|
|
}
|
|
|
|
|
2008-02-15 23:12:03 +00:00
|
|
|
list<class KX_Camera*>* cameras = scene->GetCameras();
|
2006-01-06 03:46:54 +00:00
|
|
|
|
|
|
|
// Draw the scene once for each camera with an enabled viewport
|
2008-02-15 23:12:03 +00:00
|
|
|
list<KX_Camera*>::iterator it = cameras->begin();
|
2006-01-06 03:46:54 +00:00
|
|
|
while(it != cameras->end())
|
|
|
|
{
|
|
|
|
if((*it)->GetViewport())
|
|
|
|
{
|
|
|
|
if (scene->IsClearingZBuffer())
|
|
|
|
m_rasterizer->ClearDepthBuffer();
|
|
|
|
|
|
|
|
m_rendertools->SetAuxilaryClientInfo(scene);
|
|
|
|
|
|
|
|
// do the rendering
|
|
|
|
RenderFrame(scene, (*it));
|
|
|
|
}
|
|
|
|
|
|
|
|
it++;
|
|
|
|
}
|
2002-10-12 11:37:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// only one place that checks for stereo
|
|
|
|
if(m_rasterizer->Stereo())
|
|
|
|
{
|
|
|
|
m_rasterizer->SetEye(RAS_IRasterizer::RAS_STEREO_RIGHTEYE);
|
|
|
|
|
|
|
|
if (!BeginFrame())
|
|
|
|
return;
|
|
|
|
|
|
|
|
KX_SceneList::iterator sceneit;
|
|
|
|
for (sceneit = m_scenes.begin();sceneit != m_scenes.end(); sceneit++)
|
|
|
|
// for each scene, call the proceed functions
|
|
|
|
{
|
|
|
|
KX_Scene* scene = *sceneit;
|
2006-01-06 03:46:54 +00:00
|
|
|
KX_Camera* cam = scene->GetActiveCamera();
|
2002-10-12 11:37:38 +00:00
|
|
|
|
|
|
|
// pass the scene's worldsettings to the rasterizer
|
|
|
|
SetWorldSettings(scene->GetWorldInfo());
|
|
|
|
|
|
|
|
if (scene->IsClearingZBuffer())
|
|
|
|
m_rasterizer->ClearDepthBuffer();
|
|
|
|
|
|
|
|
//pass the scene, for picking and raycasting (shadows)
|
|
|
|
m_rendertools->SetAuxilaryClientInfo(scene);
|
|
|
|
|
|
|
|
// do the rendering
|
2006-01-06 03:46:54 +00:00
|
|
|
//RenderFrame(scene);
|
|
|
|
RenderFrame(scene, cam);
|
2002-10-12 11:37:38 +00:00
|
|
|
}
|
|
|
|
} // if(m_rasterizer->Stereo())
|
|
|
|
|
|
|
|
EndFrame();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void KX_KetsjiEngine::RequestExit(int exitrequestmode)
|
|
|
|
{
|
|
|
|
m_exitcode = exitrequestmode;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void KX_KetsjiEngine::SetNameNextGame(const STR_String& nextgame)
|
|
|
|
{
|
|
|
|
m_exitstring = nextgame;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
int KX_KetsjiEngine::GetExitCode()
|
|
|
|
{
|
|
|
|
// if a gameactuator has set an exitcode or if there are no scenes left
|
|
|
|
if (!m_exitcode)
|
|
|
|
{
|
|
|
|
if (m_scenes.begin()==m_scenes.end())
|
|
|
|
m_exitcode = KX_EXIT_REQUEST_NO_SCENES_LEFT;
|
|
|
|
}
|
|
|
|
|
|
|
|
return m_exitcode;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const STR_String& KX_KetsjiEngine::GetExitString()
|
|
|
|
{
|
|
|
|
return m_exitstring;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void KX_KetsjiEngine::DoSound(KX_Scene* scene)
|
|
|
|
{
|
|
|
|
m_logger->StartLog(tc_sound, m_kxsystem->GetTimeInSeconds(), true);
|
|
|
|
|
|
|
|
KX_Camera* cam = scene->GetActiveCamera();
|
2004-03-22 22:02:18 +00:00
|
|
|
if (!cam)
|
|
|
|
return;
|
2002-10-12 11:37:38 +00:00
|
|
|
MT_Point3 listenerposition = cam->NodeGetWorldPosition();
|
|
|
|
MT_Vector3 listenervelocity = cam->GetLinearVelocity();
|
|
|
|
MT_Matrix3x3 listenerorientation = cam->NodeGetWorldOrientation();
|
|
|
|
|
|
|
|
SND_Scene* soundscene = scene->GetSoundScene();
|
|
|
|
soundscene->SetListenerTransform(
|
|
|
|
listenerposition,
|
|
|
|
listenervelocity,
|
|
|
|
listenerorientation);
|
|
|
|
|
|
|
|
soundscene->Proceed();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void KX_KetsjiEngine::SetBackGround(KX_WorldInfo* wi)
|
|
|
|
{
|
|
|
|
if (wi->hasWorld())
|
|
|
|
{
|
|
|
|
if (m_drawingmode == RAS_IRasterizer::KX_TEXTURED)
|
|
|
|
{
|
|
|
|
m_rasterizer->SetBackColor(
|
|
|
|
wi->getBackColorRed(),
|
|
|
|
wi->getBackColorGreen(),
|
|
|
|
wi->getBackColorBlue(),
|
|
|
|
0.0
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void KX_KetsjiEngine::SetWorldSettings(KX_WorldInfo* wi)
|
|
|
|
{
|
|
|
|
if (wi->hasWorld())
|
|
|
|
{
|
2006-01-06 03:46:54 +00:00
|
|
|
// ...
|
|
|
|
m_rasterizer->SetAmbientColor(
|
|
|
|
wi->getAmbientColorRed(),
|
|
|
|
wi->getAmbientColorGreen(),
|
|
|
|
wi->getAmbientColorBlue()
|
|
|
|
);
|
|
|
|
|
2002-10-12 11:37:38 +00:00
|
|
|
if (m_drawingmode == RAS_IRasterizer::KX_TEXTURED)
|
|
|
|
{
|
|
|
|
if (wi->hasMist())
|
|
|
|
{
|
|
|
|
m_rasterizer->SetFog(
|
|
|
|
wi->getMistStart(),
|
|
|
|
wi->getMistDistance(),
|
|
|
|
wi->getMistColorRed(),
|
|
|
|
wi->getMistColorGreen(),
|
|
|
|
wi->getMistColorBlue()
|
|
|
|
);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
m_rasterizer->DisableFog();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void KX_KetsjiEngine::SetDrawType(int drawingmode)
|
|
|
|
{
|
|
|
|
m_drawingmode = drawingmode;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void KX_KetsjiEngine::EnableCameraOverride(const STR_String& forscene)
|
|
|
|
{
|
|
|
|
m_overrideCam = true;
|
|
|
|
m_overrideSceneName = forscene;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void KX_KetsjiEngine::SetCameraZoom(float camzoom)
|
|
|
|
{
|
|
|
|
m_cameraZoom = camzoom;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void KX_KetsjiEngine::SetCameraOverrideUseOrtho(bool useOrtho)
|
|
|
|
{
|
|
|
|
m_overrideCamUseOrtho = useOrtho;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void KX_KetsjiEngine::SetCameraOverrideProjectionMatrix(const MT_CmMatrix4x4& mat)
|
|
|
|
{
|
|
|
|
m_overrideCamProjMat = mat;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void KX_KetsjiEngine::SetCameraOverrideViewMatrix(const MT_CmMatrix4x4& mat)
|
|
|
|
{
|
|
|
|
m_overrideCamViewMat = mat;
|
|
|
|
}
|
|
|
|
|
2008-09-15 00:11:30 +00:00
|
|
|
void KX_KetsjiEngine::SetCameraOverrideClipping(float near, float far)
|
|
|
|
{
|
|
|
|
m_overrideCamNear = near;
|
|
|
|
m_overrideCamFar = far;
|
|
|
|
}
|
|
|
|
|
2008-09-18 01:46:28 +00:00
|
|
|
void KX_KetsjiEngine::GetSceneViewport(KX_Scene *scene, KX_Camera* cam, RAS_Rect& area, RAS_Rect& viewport)
|
2002-10-12 11:37:38 +00:00
|
|
|
{
|
|
|
|
// In this function we make sure the rasterizer settings are upto
|
|
|
|
// date. We compute the viewport so that logic
|
|
|
|
// using this information is upto date.
|
|
|
|
|
|
|
|
// Note we postpone computation of the projection matrix
|
|
|
|
// so that we are using the latest camera position.
|
2008-09-14 00:32:18 +00:00
|
|
|
if (cam->GetViewport()) {
|
|
|
|
RAS_Rect userviewport;
|
2002-10-12 11:37:38 +00:00
|
|
|
|
2008-09-14 00:32:18 +00:00
|
|
|
userviewport.SetLeft(cam->GetViewportLeft());
|
|
|
|
userviewport.SetBottom(cam->GetViewportBottom());
|
|
|
|
userviewport.SetRight(cam->GetViewportRight());
|
|
|
|
userviewport.SetTop(cam->GetViewportTop());
|
2002-10-12 11:37:38 +00:00
|
|
|
|
2008-09-14 00:32:18 +00:00
|
|
|
// Don't do bars on user specified viewport
|
|
|
|
RAS_FrameSettings settings = scene->GetFramingType();
|
|
|
|
if(settings.FrameType() == RAS_FrameSettings::e_frame_bars)
|
|
|
|
settings.SetFrameType(RAS_FrameSettings::e_frame_extend);
|
2008-03-21 22:44:12 +00:00
|
|
|
|
2008-09-14 00:32:18 +00:00
|
|
|
RAS_FramingManager::ComputeViewport(
|
|
|
|
scene->GetFramingType(),
|
|
|
|
userviewport,
|
|
|
|
viewport
|
|
|
|
);
|
|
|
|
|
|
|
|
area = userviewport;
|
2006-01-06 03:46:54 +00:00
|
|
|
}
|
|
|
|
else if ( m_overrideCam || (scene->GetName() != m_overrideSceneName) || m_overrideCamUseOrtho ) {
|
2002-10-12 11:37:38 +00:00
|
|
|
RAS_FramingManager::ComputeViewport(
|
|
|
|
scene->GetFramingType(),
|
|
|
|
m_canvas->GetDisplayArea(),
|
|
|
|
viewport
|
|
|
|
);
|
2008-09-14 00:32:18 +00:00
|
|
|
|
|
|
|
area = m_canvas->GetDisplayArea();
|
2002-10-12 11:37:38 +00:00
|
|
|
} else {
|
|
|
|
viewport.SetLeft(0);
|
|
|
|
viewport.SetBottom(0);
|
|
|
|
viewport.SetRight(int(m_canvas->GetWidth()));
|
|
|
|
viewport.SetTop(int(m_canvas->GetHeight()));
|
|
|
|
|
2008-09-14 00:32:18 +00:00
|
|
|
area = m_canvas->GetDisplayArea();
|
|
|
|
}
|
2008-07-10 12:47:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void KX_KetsjiEngine::RenderShadowBuffers(KX_Scene *scene)
|
|
|
|
{
|
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
|
|
|
CListValue *objectlist = scene->GetObjectList();
|
2008-07-10 12:47:20 +00:00
|
|
|
int i, drawmode;
|
|
|
|
|
Merge of first part of changes from the apricot branch, especially
the features that are needed to run the game. Compile tested with
scons, make, but not cmake, that seems to have an issue not related
to these changes. The changes include:
* GLSL support in the viewport and game engine, enable in the game
menu in textured draw mode.
* Synced and merged part of the duplicated blender and gameengine/
gameplayer drawing code.
* Further refactoring of game engine drawing code, especially mesh
storage changed a lot.
* Optimizations in game engine armatures to avoid recomputations.
* A python function to get the framerate estimate in game.
* An option take object color into account in materials.
* An option to restrict shadow casters to a lamp's layers.
* Increase from 10 to 18 texture slots for materials, lamps, word.
An extra texture slot shows up once the last slot is used.
* Memory limit for undo, not enabled by default yet because it
needs the .B.blend to be changed.
* Multiple undo for image painting.
* An offset for dupligroups, so not all objects in a group have to
be at the origin.
2008-09-04 20:51:28 +00:00
|
|
|
m_rendertools->SetAuxilaryClientInfo(scene);
|
|
|
|
|
|
|
|
for(i=0; i<objectlist->GetCount(); i++) {
|
|
|
|
KX_GameObject *gameobj = (KX_GameObject*)objectlist->GetValue(i);
|
|
|
|
|
|
|
|
if(!gameobj->IsLight())
|
|
|
|
continue;
|
|
|
|
|
|
|
|
KX_LightObject *light = (KX_LightObject*)gameobj;
|
2008-07-10 12:47:20 +00:00
|
|
|
|
|
|
|
light->Update();
|
|
|
|
|
|
|
|
if(m_drawingmode == RAS_IRasterizer::KX_TEXTURED && light->HasShadowBuffer()) {
|
|
|
|
/* make temporary camera */
|
|
|
|
RAS_CameraData camdata = RAS_CameraData();
|
|
|
|
KX_Camera *cam = new KX_Camera(scene, scene->m_callbacks, camdata, false);
|
|
|
|
cam->SetName("__shadow__cam__");
|
2002-10-12 11:37:38 +00:00
|
|
|
|
2008-07-10 12:47:20 +00:00
|
|
|
MT_Transform camtrans;
|
|
|
|
|
|
|
|
/* switch drawmode for speed */
|
|
|
|
drawmode = m_rasterizer->GetDrawingMode();
|
|
|
|
m_rasterizer->SetDrawingMode(RAS_IRasterizer::KX_SHADOW);
|
|
|
|
|
|
|
|
/* binds framebuffer object, sets up camera .. */
|
|
|
|
light->BindShadowBuffer(m_rasterizer, cam, camtrans);
|
|
|
|
|
|
|
|
/* update scene */
|
|
|
|
scene->UpdateMeshTransformations();
|
|
|
|
scene->CalculateVisibleMeshes(m_rasterizer, cam, light->GetShadowLayer());
|
|
|
|
|
|
|
|
/* render */
|
|
|
|
m_rasterizer->ClearDepthBuffer();
|
|
|
|
scene->RenderBuckets(camtrans, m_rasterizer, m_rendertools);
|
|
|
|
|
|
|
|
/* unbind framebuffer object, restore drawmode, free camera */
|
|
|
|
light->UnbindShadowBuffer(m_rasterizer);
|
|
|
|
m_rasterizer->SetDrawingMode(drawmode);
|
|
|
|
cam->Release();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2002-10-12 11:37:38 +00:00
|
|
|
|
|
|
|
// update graphics
|
2006-01-06 03:46:54 +00:00
|
|
|
void KX_KetsjiEngine::RenderFrame(KX_Scene* scene, KX_Camera* cam)
|
2002-10-12 11:37:38 +00:00
|
|
|
{
|
2008-09-15 00:11:30 +00:00
|
|
|
bool override_camera;
|
2008-09-14 00:32:18 +00:00
|
|
|
RAS_Rect viewport, area;
|
2008-05-24 08:34:04 +00:00
|
|
|
float left, right, bottom, top, nearfrust, farfrust, focallength;
|
2004-07-20 12:07:06 +00:00
|
|
|
const float ortho = 100.0;
|
2006-01-06 03:46:54 +00:00
|
|
|
// KX_Camera* cam = scene->GetActiveCamera();
|
2004-03-22 22:02:18 +00:00
|
|
|
|
|
|
|
if (!cam)
|
|
|
|
return;
|
2008-09-14 00:32:18 +00:00
|
|
|
|
2008-09-18 01:46:28 +00:00
|
|
|
GetSceneViewport(scene, cam, area, viewport);
|
2008-09-14 00:32:18 +00:00
|
|
|
|
|
|
|
// store the computed viewport in the scene
|
|
|
|
scene->SetSceneViewport(viewport);
|
|
|
|
|
|
|
|
// set the viewport for this frame and scene
|
|
|
|
m_canvas->SetViewPort(viewport.GetLeft(), viewport.GetBottom(),
|
|
|
|
viewport.GetRight(), viewport.GetTop());
|
2006-01-06 03:46:54 +00:00
|
|
|
|
|
|
|
// see KX_BlenderMaterial::Activate
|
|
|
|
//m_rasterizer->SetAmbient();
|
2002-10-12 11:37:38 +00:00
|
|
|
m_rasterizer->DisplayFog();
|
|
|
|
|
2008-09-15 00:11:30 +00:00
|
|
|
override_camera = m_overrideCam && (scene->GetName() == m_overrideSceneName);
|
|
|
|
override_camera = override_camera && (cam->GetName() == "__default__cam__");
|
|
|
|
|
|
|
|
if (override_camera && m_overrideCamUseOrtho) {
|
2002-10-12 11:37:38 +00:00
|
|
|
MT_CmMatrix4x4 projmat = m_overrideCamProjMat;
|
|
|
|
m_rasterizer->SetProjectionMatrix(projmat);
|
2006-01-06 03:46:54 +00:00
|
|
|
} else if (cam->hasValidProjectionMatrix() && !cam->GetViewport() )
|
2004-05-16 12:53:39 +00:00
|
|
|
{
|
|
|
|
m_rasterizer->SetProjectionMatrix(cam->GetProjectionMatrix());
|
|
|
|
} else
|
|
|
|
{
|
2002-10-12 11:37:38 +00:00
|
|
|
RAS_FrameFrustum frustum;
|
2004-07-20 12:07:06 +00:00
|
|
|
float lens = cam->GetLens();
|
2008-09-15 00:11:30 +00:00
|
|
|
bool orthographic = !cam->GetCameraData()->m_perspective;
|
2004-07-20 12:07:06 +00:00
|
|
|
nearfrust = cam->GetCameraNear();
|
|
|
|
farfrust = cam->GetCameraFar();
|
2008-05-24 08:34:04 +00:00
|
|
|
focallength = cam->GetFocalLength();
|
2002-10-12 11:37:38 +00:00
|
|
|
|
2008-09-15 00:11:30 +00:00
|
|
|
if(override_camera) {
|
|
|
|
nearfrust = m_overrideCamNear;
|
|
|
|
farfrust = m_overrideCamFar;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (orthographic) {
|
2004-07-20 12:07:06 +00:00
|
|
|
lens *= ortho;
|
|
|
|
nearfrust = (nearfrust + 1.0)*ortho;
|
|
|
|
farfrust *= ortho;
|
|
|
|
}
|
|
|
|
|
2002-10-12 11:37:38 +00:00
|
|
|
RAS_FramingManager::ComputeFrustum(
|
|
|
|
scene->GetFramingType(),
|
2008-09-14 00:32:18 +00:00
|
|
|
area,
|
|
|
|
viewport,
|
2004-07-20 12:07:06 +00:00
|
|
|
lens,
|
|
|
|
nearfrust,
|
|
|
|
farfrust,
|
2002-10-12 11:37:38 +00:00
|
|
|
frustum
|
|
|
|
);
|
|
|
|
|
|
|
|
left = frustum.x1 * m_cameraZoom;
|
|
|
|
right = frustum.x2 * m_cameraZoom;
|
|
|
|
bottom = frustum.y1 * m_cameraZoom;
|
|
|
|
top = frustum.y2 * m_cameraZoom;
|
|
|
|
nearfrust = frustum.camnear;
|
|
|
|
farfrust = frustum.camfar;
|
|
|
|
|
|
|
|
MT_Matrix4x4 projmat = m_rasterizer->GetFrustumMatrix(
|
2008-05-24 08:34:04 +00:00
|
|
|
left, right, bottom, top, nearfrust, farfrust, focallength);
|
2008-09-14 00:32:18 +00:00
|
|
|
|
2004-08-10 11:35:38 +00:00
|
|
|
cam->SetProjectionMatrix(projmat);
|
2004-12-01 08:43:58 +00:00
|
|
|
|
|
|
|
// Otherwise the projection matrix for each eye will be the same...
|
2004-08-10 11:35:38 +00:00
|
|
|
if (m_rasterizer->Stereo())
|
|
|
|
cam->InvalidateProjectionMatrix();
|
2002-10-12 11:37:38 +00:00
|
|
|
}
|
|
|
|
|
2004-07-20 12:07:06 +00:00
|
|
|
MT_Transform camtrans(cam->GetWorldToCamera());
|
|
|
|
if (!cam->GetCameraData()->m_perspective)
|
|
|
|
camtrans.getOrigin()[2] *= ortho;
|
|
|
|
MT_Matrix4x4 viewmat(camtrans);
|
|
|
|
|
2002-10-12 11:37:38 +00:00
|
|
|
m_rasterizer->SetViewMatrix(viewmat, cam->NodeGetWorldPosition(),
|
|
|
|
cam->GetCameraLocation(), cam->GetCameraOrientation());
|
|
|
|
cam->SetModelviewMatrix(viewmat);
|
|
|
|
|
|
|
|
scene->UpdateMeshTransformations();
|
|
|
|
|
|
|
|
// The following actually reschedules all vertices to be
|
|
|
|
// redrawn. There is a cache between the actual rescheduling
|
|
|
|
// and this call though. Visibility is imparted when this call
|
|
|
|
// runs through the individual objects.
|
2006-01-06 03:46:54 +00:00
|
|
|
scene->CalculateVisibleMeshes(m_rasterizer,cam);
|
2002-10-12 11:37:38 +00:00
|
|
|
|
2004-07-20 12:07:06 +00:00
|
|
|
scene->RenderBuckets(camtrans, m_rasterizer, m_rendertools);
|
2007-10-22 20:24:26 +00:00
|
|
|
|
|
|
|
PostRenderFrame();
|
|
|
|
}
|
2007-09-29 18:51:01 +00:00
|
|
|
|
2007-10-22 20:24:26 +00:00
|
|
|
void KX_KetsjiEngine::PostRenderFrame()
|
|
|
|
{
|
|
|
|
m_rendertools->PushMatrix();
|
|
|
|
m_rendertools->Render2DFilters(m_canvas);
|
2007-09-29 18:51:01 +00:00
|
|
|
m_rendertools->MotionBlur(m_rasterizer);
|
2007-10-22 20:24:26 +00:00
|
|
|
m_rendertools->PopMatrix();
|
2002-10-12 11:37:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void KX_KetsjiEngine::StopEngine()
|
|
|
|
{
|
|
|
|
if (m_bInitialized)
|
|
|
|
{
|
2005-11-06 16:50:22 +00:00
|
|
|
|
|
|
|
if (m_game2ipo)
|
|
|
|
{
|
|
|
|
// printf("TestHandlesPhysicsObjectToAnimationIpo\n");
|
|
|
|
m_sceneconverter->TestHandlesPhysicsObjectToAnimationIpo();
|
|
|
|
}
|
|
|
|
|
2002-10-12 11:37:38 +00:00
|
|
|
KX_SceneList::iterator sceneit;
|
|
|
|
for (sceneit = m_scenes.begin();sceneit != m_scenes.end() ; sceneit++)
|
|
|
|
{
|
|
|
|
KX_Scene* scene = *sceneit;
|
2008-03-09 21:42:03 +00:00
|
|
|
m_sceneconverter->RemoveScene(scene);
|
2002-10-12 11:37:38 +00:00
|
|
|
}
|
|
|
|
m_scenes.clear();
|
|
|
|
|
|
|
|
// cleanup all the stuff
|
|
|
|
m_rasterizer->Exit();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Scene Management is able to switch between scenes
|
|
|
|
// and have several scene's running in parallel
|
|
|
|
void KX_KetsjiEngine::AddScene(KX_Scene* scene)
|
|
|
|
{
|
|
|
|
m_scenes.push_back(scene);
|
|
|
|
PostProcessScene(scene);
|
|
|
|
SceneListsChanged();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void KX_KetsjiEngine::PostProcessScene(KX_Scene* scene)
|
|
|
|
{
|
|
|
|
bool override_camera = (m_overrideCam && (scene->GetName() == m_overrideSceneName));
|
|
|
|
|
|
|
|
// if there is no activecamera, or the camera is being
|
|
|
|
// overridden we need to construct a temporarily camera
|
|
|
|
if (!scene->GetActiveCamera() || override_camera)
|
|
|
|
{
|
|
|
|
KX_Camera* activecam = NULL;
|
|
|
|
|
2004-04-08 12:01:48 +00:00
|
|
|
RAS_CameraData camdata = RAS_CameraData();
|
2004-05-16 12:53:39 +00:00
|
|
|
activecam = new KX_Camera(scene,KX_Scene::m_callbacks,camdata, false);
|
2002-10-12 11:37:38 +00:00
|
|
|
activecam->SetName("__default__cam__");
|
|
|
|
|
|
|
|
// set transformation
|
|
|
|
if (override_camera) {
|
|
|
|
const MT_CmMatrix4x4& cammatdata = m_overrideCamViewMat;
|
|
|
|
MT_Transform trans = MT_Transform(cammatdata.getPointer());
|
|
|
|
MT_Transform camtrans;
|
|
|
|
camtrans.invert(trans);
|
|
|
|
|
|
|
|
activecam->NodeSetLocalPosition(camtrans.getOrigin());
|
|
|
|
activecam->NodeSetLocalOrientation(camtrans.getBasis());
|
|
|
|
activecam->NodeUpdateGS(0,true);
|
|
|
|
} else {
|
|
|
|
activecam->NodeSetLocalPosition(MT_Point3(0.0, 0.0, 0.0));
|
|
|
|
activecam->NodeSetLocalOrientation(MT_Vector3(0.0, 0.0, 0.0));
|
|
|
|
activecam->NodeUpdateGS(0,true);
|
|
|
|
}
|
|
|
|
|
|
|
|
scene->AddCamera(activecam);
|
|
|
|
scene->SetActiveCamera(activecam);
|
|
|
|
scene->GetObjectList()->Add(activecam->AddRef());
|
|
|
|
scene->GetRootParentList()->Add(activecam->AddRef());
|
2008-03-01 19:46:50 +00:00
|
|
|
//done with activecam
|
|
|
|
activecam->Release();
|
2002-10-12 11:37:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
scene->UpdateParents(0.0);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void KX_KetsjiEngine::RenderDebugProperties()
|
|
|
|
{
|
|
|
|
STR_String debugtxt;
|
|
|
|
int xcoord = 10; // mmmm, these constants were taken from blender source
|
|
|
|
int ycoord = 14; // to 'mimic' behaviour
|
|
|
|
|
|
|
|
float tottime = m_logger->GetAverage();
|
|
|
|
if (tottime < 1e-6f) {
|
|
|
|
tottime = 1e-6f;
|
|
|
|
}
|
2006-01-06 03:46:54 +00:00
|
|
|
|
|
|
|
// Set viewport to entire canvas
|
|
|
|
RAS_Rect viewport;
|
|
|
|
m_canvas->SetViewPort(0, 0, int(m_canvas->GetWidth()), int(m_canvas->GetHeight()));
|
2002-10-12 11:37:38 +00:00
|
|
|
|
|
|
|
/* Framerate display */
|
|
|
|
if (m_show_framerate) {
|
|
|
|
debugtxt.Format("swap : %.3f (%.3f frames per second)", tottime, 1.0/tottime);
|
|
|
|
m_rendertools->RenderText2D(RAS_IRenderTools::RAS_TEXT_PADDED,
|
|
|
|
debugtxt.Ptr(),
|
|
|
|
xcoord,
|
|
|
|
ycoord,
|
|
|
|
m_canvas->GetWidth() /* RdV, TODO ?? */,
|
|
|
|
m_canvas->GetHeight() /* RdV, TODO ?? */);
|
|
|
|
ycoord += 14;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Profile and framerate display */
|
|
|
|
if (m_show_profile)
|
|
|
|
{
|
|
|
|
for (int j = tc_first; j < tc_numCategories; j++)
|
|
|
|
{
|
|
|
|
debugtxt.Format(m_profileLabels[j]);
|
|
|
|
m_rendertools->RenderText2D(RAS_IRenderTools::RAS_TEXT_PADDED,
|
|
|
|
debugtxt.Ptr(),
|
|
|
|
xcoord,ycoord,
|
|
|
|
m_canvas->GetWidth(),
|
|
|
|
m_canvas->GetHeight());
|
|
|
|
double time = m_logger->GetAverage((KX_TimeCategory)j);
|
|
|
|
debugtxt.Format("%2.2f %%", time/tottime * 100.f);
|
|
|
|
m_rendertools->RenderText2D(RAS_IRenderTools::RAS_TEXT_PADDED,
|
|
|
|
debugtxt.Ptr(),
|
|
|
|
xcoord + 60 ,ycoord,
|
|
|
|
m_canvas->GetWidth(),
|
|
|
|
m_canvas->GetHeight());
|
|
|
|
ycoord += 14;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Property display*/
|
|
|
|
if (m_show_debug_properties && m_propertiesPresent)
|
|
|
|
{
|
|
|
|
KX_SceneList::iterator sceneit;
|
|
|
|
for (sceneit = m_scenes.begin();sceneit != m_scenes.end() ; sceneit++)
|
|
|
|
{
|
|
|
|
KX_Scene* scene = *sceneit;
|
|
|
|
/* the 'normal' debug props */
|
|
|
|
vector<SCA_DebugProp*>& debugproplist = scene->GetDebugProperties();
|
|
|
|
|
|
|
|
for (vector<SCA_DebugProp*>::iterator it = debugproplist.begin();
|
|
|
|
!(it==debugproplist.end());it++)
|
|
|
|
{
|
|
|
|
CValue* propobj = (*it)->m_obj;
|
|
|
|
STR_String objname = propobj->GetName();
|
|
|
|
STR_String propname = (*it)->m_name;
|
2008-09-25 16:19:07 +00:00
|
|
|
if (propname == "__state__")
|
2002-10-12 11:37:38 +00:00
|
|
|
{
|
2008-09-25 16:19:07 +00:00
|
|
|
// reserve name for object state
|
|
|
|
KX_GameObject* gameobj = static_cast<KX_GameObject*>(propobj);
|
|
|
|
unsigned int state = gameobj->GetState();
|
|
|
|
debugtxt = objname + "." + propname + " = ";
|
|
|
|
bool first = true;
|
|
|
|
for (int statenum=1;state;state >>= 1, statenum++)
|
|
|
|
{
|
|
|
|
if (state & 1)
|
|
|
|
{
|
|
|
|
if (!first)
|
|
|
|
{
|
|
|
|
debugtxt += ",";
|
|
|
|
}
|
|
|
|
debugtxt += STR_String(statenum);
|
|
|
|
first = false;
|
|
|
|
}
|
|
|
|
}
|
2002-10-12 11:37:38 +00:00
|
|
|
m_rendertools->RenderText2D(RAS_IRenderTools::RAS_TEXT_PADDED,
|
2008-09-25 16:19:07 +00:00
|
|
|
debugtxt.Ptr(),
|
|
|
|
xcoord,
|
|
|
|
ycoord,
|
|
|
|
m_canvas->GetWidth(),
|
|
|
|
m_canvas->GetHeight());
|
2002-10-12 11:37:38 +00:00
|
|
|
ycoord += 14;
|
|
|
|
}
|
2008-09-25 16:19:07 +00:00
|
|
|
else
|
|
|
|
{
|
|
|
|
CValue* propval = propobj->GetProperty(propname);
|
|
|
|
if (propval)
|
|
|
|
{
|
|
|
|
STR_String text = propval->GetText();
|
|
|
|
debugtxt = objname + "." + propname + " = " + text;
|
|
|
|
m_rendertools->RenderText2D(RAS_IRenderTools::RAS_TEXT_PADDED,
|
|
|
|
debugtxt.Ptr(),
|
|
|
|
xcoord,
|
|
|
|
ycoord,
|
|
|
|
m_canvas->GetWidth(),
|
|
|
|
m_canvas->GetHeight());
|
|
|
|
ycoord += 14;
|
|
|
|
}
|
|
|
|
}
|
2002-10-12 11:37:38 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
KX_SceneList* KX_KetsjiEngine::CurrentScenes()
|
|
|
|
{
|
|
|
|
return &m_scenes;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
KX_Scene* KX_KetsjiEngine::FindScene(const STR_String& scenename)
|
|
|
|
{
|
|
|
|
KX_SceneList::iterator sceneit = m_scenes.begin();
|
|
|
|
|
|
|
|
// bit risky :) better to split the second clause
|
|
|
|
while ( (sceneit != m_scenes.end())
|
|
|
|
&& ((*sceneit)->GetName() != scenename))
|
|
|
|
{
|
|
|
|
sceneit++;
|
|
|
|
}
|
|
|
|
|
|
|
|
return ((sceneit == m_scenes.end()) ? NULL : *sceneit);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void KX_KetsjiEngine::ConvertAndAddScene(const STR_String& scenename,bool overlay)
|
|
|
|
{
|
|
|
|
// only add scene when it doesn't exist!
|
|
|
|
if (FindScene(scenename))
|
|
|
|
{
|
|
|
|
STR_String tmpname = scenename;
|
|
|
|
printf("warning: scene %s already exists, not added!\n",tmpname.Ptr());
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (overlay)
|
|
|
|
{
|
|
|
|
m_addingOverlayScenes.insert(scenename);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
m_addingBackgroundScenes.insert(scenename);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void KX_KetsjiEngine::RemoveScene(const STR_String& scenename)
|
|
|
|
{
|
|
|
|
if (FindScene(scenename))
|
|
|
|
{
|
|
|
|
m_removingScenes.insert(scenename);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2004-03-22 22:02:18 +00:00
|
|
|
// STR_String tmpname = scenename;
|
|
|
|
std::cout << "warning: scene " << scenename << " does not exist, not removed!" << std::endl;
|
2002-10-12 11:37:38 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void KX_KetsjiEngine::RemoveScheduledScenes()
|
|
|
|
{
|
|
|
|
if (m_removingScenes.size())
|
|
|
|
{
|
|
|
|
set<STR_String>::iterator scenenameit;
|
|
|
|
for (scenenameit=m_removingScenes.begin();scenenameit != m_removingScenes.end();scenenameit++)
|
|
|
|
{
|
|
|
|
STR_String scenename = *scenenameit;
|
|
|
|
|
|
|
|
KX_SceneList::iterator sceneit;
|
|
|
|
for (sceneit = m_scenes.begin();sceneit != m_scenes.end() ; sceneit++)
|
|
|
|
{
|
|
|
|
KX_Scene* scene = *sceneit;
|
|
|
|
if (scene->GetName()==scenename)
|
|
|
|
{
|
2008-03-09 21:42:03 +00:00
|
|
|
m_sceneconverter->RemoveScene(scene);
|
2002-10-12 11:37:38 +00:00
|
|
|
m_scenes.erase(sceneit);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
m_removingScenes.clear();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
KX_Scene* KX_KetsjiEngine::CreateScene(const STR_String& scenename)
|
|
|
|
{
|
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
|
|
|
Scene *scene = m_sceneconverter->GetBlenderSceneForName(scenename);
|
2002-10-12 11:37:38 +00:00
|
|
|
KX_Scene* tmpscene = new KX_Scene(m_keyboarddevice,
|
|
|
|
m_mousedevice,
|
|
|
|
m_networkdevice,
|
|
|
|
m_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
|
|
|
scenename,
|
|
|
|
scene);
|
2002-10-12 11:37:38 +00:00
|
|
|
|
|
|
|
m_sceneconverter->ConvertScene(scenename,
|
|
|
|
tmpscene,
|
|
|
|
m_pythondictionary,
|
|
|
|
m_keyboarddevice,
|
|
|
|
m_rendertools,
|
|
|
|
m_canvas);
|
|
|
|
|
|
|
|
return tmpscene;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void KX_KetsjiEngine::AddScheduledScenes()
|
|
|
|
{
|
|
|
|
set<STR_String>::iterator scenenameit;
|
|
|
|
|
|
|
|
if (m_addingOverlayScenes.size())
|
|
|
|
{
|
|
|
|
for (scenenameit = m_addingOverlayScenes.begin();
|
|
|
|
scenenameit != m_addingOverlayScenes.end();
|
|
|
|
scenenameit++)
|
|
|
|
{
|
|
|
|
STR_String scenename = *scenenameit;
|
|
|
|
KX_Scene* tmpscene = CreateScene(scenename);
|
|
|
|
m_scenes.push_back(tmpscene);
|
|
|
|
PostProcessScene(tmpscene);
|
|
|
|
}
|
|
|
|
m_addingOverlayScenes.clear();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (m_addingBackgroundScenes.size())
|
|
|
|
{
|
|
|
|
for (scenenameit = m_addingBackgroundScenes.begin();
|
|
|
|
scenenameit != m_addingBackgroundScenes.end();
|
|
|
|
scenenameit++)
|
|
|
|
{
|
|
|
|
STR_String scenename = *scenenameit;
|
|
|
|
KX_Scene* tmpscene = CreateScene(scenename);
|
|
|
|
m_scenes.insert(m_scenes.begin(),tmpscene);
|
|
|
|
PostProcessScene(tmpscene);
|
|
|
|
|
|
|
|
}
|
|
|
|
m_addingBackgroundScenes.clear();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void KX_KetsjiEngine::ReplaceScene(const STR_String& oldscene,const STR_String& newscene)
|
|
|
|
{
|
|
|
|
m_replace_scenes.insert(std::make_pair(oldscene,newscene));
|
|
|
|
}
|
|
|
|
|
|
|
|
// replace scene is not the same as removing and adding because the
|
|
|
|
// scene must be in exact the same place (to maintain drawingorder)
|
|
|
|
// (nzc) - should that not be done with a scene-display list? It seems
|
|
|
|
// stupid to rely on the mem allocation order...
|
|
|
|
void KX_KetsjiEngine::ReplaceScheduledScenes()
|
|
|
|
{
|
|
|
|
if (m_replace_scenes.size())
|
|
|
|
{
|
|
|
|
set<pair<STR_String,STR_String> >::iterator scenenameit;
|
|
|
|
|
|
|
|
for (scenenameit = m_replace_scenes.begin();
|
|
|
|
scenenameit != m_replace_scenes.end();
|
|
|
|
scenenameit++)
|
|
|
|
{
|
|
|
|
STR_String oldscenename = (*scenenameit).first;
|
|
|
|
STR_String newscenename = (*scenenameit).second;
|
|
|
|
int i=0;
|
|
|
|
/* Scenes are not supposed to be included twice... I think */
|
|
|
|
KX_SceneList::iterator sceneit;
|
|
|
|
for (sceneit = m_scenes.begin();sceneit != m_scenes.end() ; sceneit++)
|
|
|
|
{
|
|
|
|
KX_Scene* scene = *sceneit;
|
|
|
|
if (scene->GetName() == oldscenename)
|
|
|
|
{
|
2008-03-09 21:42:03 +00:00
|
|
|
m_sceneconverter->RemoveScene(scene);
|
2002-10-12 11:37:38 +00:00
|
|
|
KX_Scene* tmpscene = CreateScene(newscenename);
|
|
|
|
m_scenes[i]=tmpscene;
|
|
|
|
PostProcessScene(tmpscene);
|
|
|
|
}
|
|
|
|
i++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
m_replace_scenes.clear();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void KX_KetsjiEngine::SuspendScene(const STR_String& scenename)
|
|
|
|
{
|
|
|
|
KX_Scene* scene = FindScene(scenename);
|
|
|
|
if (scene) scene->Suspend();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void KX_KetsjiEngine::ResumeScene(const STR_String& scenename)
|
|
|
|
{
|
|
|
|
KX_Scene* scene = FindScene(scenename);
|
|
|
|
if (scene) scene->Resume();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void KX_KetsjiEngine::SetUseFixedTime(bool bUseFixedTime)
|
|
|
|
{
|
|
|
|
m_bFixedTime = bUseFixedTime;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2005-08-23 13:16:02 +00:00
|
|
|
void KX_KetsjiEngine::SetGame2IpoMode(bool game2ipo,int startFrame)
|
|
|
|
{
|
|
|
|
m_game2ipo = game2ipo;
|
2005-10-30 07:25:36 +00:00
|
|
|
if (game2ipo)
|
|
|
|
{
|
|
|
|
//when recording physics keyframes, always run at a fixed framerate
|
|
|
|
m_bFixedTime = true;
|
|
|
|
}
|
2005-08-23 13:16:02 +00:00
|
|
|
m_currentFrame = startFrame;
|
|
|
|
}
|
2002-10-12 11:37:38 +00:00
|
|
|
|
|
|
|
bool KX_KetsjiEngine::GetUseFixedTime(void) const
|
|
|
|
{
|
|
|
|
return m_bFixedTime;
|
|
|
|
}
|
|
|
|
|
2005-12-18 19:10:26 +00:00
|
|
|
double KX_KetsjiEngine::GetSuspendedDelta()
|
|
|
|
{
|
|
|
|
return m_suspendeddelta;
|
|
|
|
}
|
|
|
|
|
2004-10-16 11:41:50 +00:00
|
|
|
double KX_KetsjiEngine::GetTicRate()
|
|
|
|
{
|
|
|
|
return m_ticrate;
|
|
|
|
}
|
2002-10-12 11:37:38 +00:00
|
|
|
|
2004-10-16 11:41:50 +00:00
|
|
|
void KX_KetsjiEngine::SetTicRate(double ticrate)
|
|
|
|
{
|
|
|
|
m_ticrate = ticrate;
|
|
|
|
}
|
2002-10-12 11:37:38 +00:00
|
|
|
|
2008-06-17 10:06:38 +00:00
|
|
|
double KX_KetsjiEngine::GetAnimFrameRate()
|
|
|
|
{
|
|
|
|
return m_anim_framerate;
|
|
|
|
}
|
|
|
|
|
|
|
|
void KX_KetsjiEngine::SetAnimFrameRate(double framerate)
|
|
|
|
{
|
|
|
|
m_anim_framerate = framerate;
|
|
|
|
}
|
|
|
|
|
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
|
|
|
double KX_KetsjiEngine::GetAverageFrameRate()
|
|
|
|
{
|
|
|
|
return m_average_framerate;
|
|
|
|
}
|
|
|
|
|
2002-10-12 11:37:38 +00:00
|
|
|
void KX_KetsjiEngine::SetTimingDisplay(bool frameRate, bool profile, bool properties)
|
|
|
|
{
|
|
|
|
m_show_framerate = frameRate;
|
|
|
|
m_show_profile = profile;
|
|
|
|
m_show_debug_properties = properties;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void KX_KetsjiEngine::GetTimingDisplay(bool& frameRate, bool& profile, bool& properties) const
|
|
|
|
{
|
|
|
|
frameRate = m_show_framerate;
|
|
|
|
profile = m_show_profile;
|
|
|
|
properties = m_show_debug_properties;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void KX_KetsjiEngine::ProcessScheduledScenes(void)
|
|
|
|
{
|
|
|
|
// Check whether there will be changes to the list of scenes
|
|
|
|
if (m_addingOverlayScenes.size() ||
|
|
|
|
m_addingBackgroundScenes.size() ||
|
|
|
|
m_replace_scenes.size() ||
|
|
|
|
m_removingScenes.size()) {
|
|
|
|
|
|
|
|
// Change the scene list
|
|
|
|
ReplaceScheduledScenes();
|
|
|
|
RemoveScheduledScenes();
|
|
|
|
AddScheduledScenes();
|
|
|
|
|
|
|
|
// Notify
|
|
|
|
SceneListsChanged();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void KX_KetsjiEngine::SceneListsChanged(void)
|
|
|
|
{
|
|
|
|
m_propertiesPresent = false;
|
|
|
|
KX_SceneList::iterator sceneit = m_scenes.begin();
|
|
|
|
while ((sceneit != m_scenes.end()) && (!m_propertiesPresent))
|
|
|
|
{
|
|
|
|
KX_Scene* scene = *sceneit;
|
|
|
|
vector<SCA_DebugProp*>& debugproplist = scene->GetDebugProperties();
|
|
|
|
m_propertiesPresent = !debugproplist.empty();
|
|
|
|
sceneit++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void KX_KetsjiEngine::SetHideCursor(bool hideCursor)
|
|
|
|
{
|
|
|
|
m_hideCursor = hideCursor;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool KX_KetsjiEngine::GetHideCursor(void) const
|
|
|
|
{
|
|
|
|
return m_hideCursor;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void KX_KetsjiEngine::SetUseOverrideFrameColor(bool overrideFrameColor)
|
|
|
|
{
|
|
|
|
m_overrideFrameColor = overrideFrameColor;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool KX_KetsjiEngine::GetUseOverrideFrameColor(void) const
|
|
|
|
{
|
|
|
|
return m_overrideFrameColor;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void KX_KetsjiEngine::SetOverrideFrameColor(float r, float g, float b)
|
|
|
|
{
|
|
|
|
m_overrideFrameColorR = r;
|
|
|
|
m_overrideFrameColorG = g;
|
|
|
|
m_overrideFrameColorB = b;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void KX_KetsjiEngine::GetOverrideFrameColor(float& r, float& g, float& b) const
|
|
|
|
{
|
|
|
|
r = m_overrideFrameColorR;
|
|
|
|
g = m_overrideFrameColorG;
|
|
|
|
b = m_overrideFrameColorB;
|
|
|
|
}
|
|
|
|
|
2007-09-29 18:51:01 +00:00
|
|
|
|
2007-10-22 20:24:26 +00:00
|
|
|
|