1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342
|
/**
* $Id: GPC_Engine.cpp,v 1.5 2005/08/23 13:16:02 erwin Exp $
*
* ***** BEGIN GPL/BL DUAL LICENSE BLOCK *****
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version. The Blender
* Foundation also sells licenses for use in proprietary software under
* the Blender License. See http://www.blender.org/BL/ for information
* about this.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*
* The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
* All rights reserved.
*
* The Original Code is: all of this file.
*
* Contributor(s): none yet.
*
* ***** END GPL/BL DUAL LICENSE BLOCK *****
*/
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
#ifdef WIN32
#pragma warning (disable:4786) // suppress stl-MSVC debug info warning
#endif // WIN32
#include <iostream>
#include "BKE_blender.h" // initglobals()
#include "BKE_global.h" // Global G
#include "DNA_scene_types.h"
#include "DNA_camera_types.h" // Camera
#include "DNA_object_types.h" // Object
#include "BLO_readfile.h"
#include "BLI_blenlib.h"
// include files needed by "KX_BlenderSceneConverter.h"
#include "GEN_Map.h"
#include "SCA_IActuator.h"
#include "RAS_MeshObject.h"
#include "KX_BlenderSceneConverter.h"
#include "KX_KetsjiEngine.h"
#include "NG_LoopBackNetworkDeviceInterface.h"
#include "RAS_IRenderTools.h"
#include "SND_DeviceManager.h"
#include "GPC_Engine.h"
#include "GPC_KeyboardDevice.h"
#include "GPC_MouseDevice.h"
#include "GPC_RawImage.h"
#include "GPC_RawLoadDotBlendArray.h"
GPC_Engine::GPC_Engine(char *customLoadingAnimationURL,
int foregroundColor, int backgroundColor, int frameRate) :
m_initialized(false), m_running(false), m_loading(false),
m_customLoadingAnimation(false), m_previousProgress(0.0),
m_system(NULL), m_keyboarddev(NULL),
m_mousedev(NULL), m_canvas(NULL), m_rendertools(NULL),
m_portal(NULL), m_sceneconverter(NULL), m_networkdev(NULL),
m_audiodevice(NULL), m_curarea(NULL),
m_customLoadingAnimationURL(NULL),
m_foregroundColor(foregroundColor), m_backgroundColor(backgroundColor),
m_frameRate(frameRate),
m_BlenderLogo(0), m_Blender3DLogo(0)/*, m_NaNLogo(0)*/
{
if(customLoadingAnimationURL[0] != '\0')
{
m_customLoadingAnimationURL = new char[sizeof(customLoadingAnimationURL)];
// not yet, need to be implemented first... m_customLoadingAnimation = true;
}
// load the Blender logo into memory
m_BlenderLogo = new GPC_RawImage();
// blender3d size is 115 x 32 so make resulting texture 128 x 128
if(!m_BlenderLogo->Load("BlenderLogo", 128, 128, GPC_RawImage::alignTopLeft, 8, 8))
m_BlenderLogo = 0;
// load the Blender3D logo into memory
m_Blender3DLogo = new GPC_RawImage();
// blender3d size is 136 x 11 so make resulting texture 256 x 256
if(!m_Blender3DLogo->Load("Blender3DLogo", 256, 256, GPC_RawImage::alignBottomRight, 8, 8))
m_Blender3DLogo = 0;
#if 0
// obsolete logo
// load the NaN logo into memory
m_NaNLogo = new GPC_RawImage();
// blender3d size is 32 x 31 so make resulting texture 64 x 64
if(!m_NaNLogo->Load("NaNLogo", 64, 64, GPC_RawImage::alignBottomRight, 8, 8))
m_NaNLogo = 0;
#endif
}
GPC_Engine::~GPC_Engine()
{
// deleting everything in reverse order of creation
#if 0
// hmm deleted in Stop() delete m_portal;
// hmm deleted in Stop() delete m_sceneconverter;
delete m_system;
delete m_networkdev;
delete m_rendertools;
delete m_canvas;
delete m_mousedev;
delete m_keyboarddev;
// not yet used so be careful and not delete them
// delete m_WaveCache;
// delete m_curarea; // for future use, not used yet
#endif
delete m_BlenderLogo;
delete m_Blender3DLogo;
#if 0
delete m_NaNLogo;
#endif
}
bool GPC_Engine::Start(char *filename)
{
BlendReadError error;
BlendFileData *bfd= BLO_read_from_file(filename, &error);
if (!bfd) {
// XXX, deal with error here
cout << "Unable to load: " << filename << endl;
return false;
}
StartKetsji();
if(bfd->type == BLENFILETYPE_PUB)
m_canvas->SetBannerDisplayEnabled(false);
return true;
}
bool GPC_Engine::Start(unsigned char *blenderDataBuffer,
unsigned int blenderDataBufferSize)
{
BlendReadError error;
BlendFileData *bfd= BLO_read_from_memory(blenderDataBuffer, blenderDataBufferSize, &error);
if (!bfd) {
// XXX, deal with error here
cout << "Unable to load. " << endl;
return false;
}
StartKetsji();
if(bfd->type == BLENFILETYPE_PUB)
m_canvas->SetBannerDisplayEnabled(false);
return true;
}
bool GPC_Engine::StartKetsji(void)
{
STR_String startSceneName = G.scene->id.name + 2;
/*
KX_KetsjiEngine* ketsjieng = new KX_KetsjiEngine(m_system);
m_portal = new KetsjiPortal(ketsjieng);
m_portal->setSecurity(psl_Highest);
KX_ISceneConverter *sceneconverter = new KX_BlenderSceneConverter(&G, ketsjieng);
m_portal->Enter(
startSceneName,
sceneconverter,
m_canvas,
m_rendertools,
m_keyboarddev,
m_mousedev,
m_networkdev,
m_audiodevice,
m_system);
m_system->SetMainLoop(m_portal->m_ketsjieng);
m_running = true;
*/
return true;
}
void GPC_Engine::StartLoadingAnimation()
{
if(m_customLoadingAnimation)
{
}
else
{
unsigned char *blenderDataBuffer;
int blenderDataBufferSize;
GetRawLoadingAnimation(&blenderDataBuffer, &blenderDataBufferSize);
if(!Start(blenderDataBuffer, blenderDataBufferSize))
cout << "something went wrong when starting the engine" << endl;
delete blenderDataBuffer; // created with 'new' in GetRawLoadingAnimation()
}
}
// will be platform dependant
float GPC_Engine::DetermineProgress(void)
{
#if 0
float progress;
if ((m_blenderData.m_ulProgress > 0) &&
(m_blenderData.m_ulProgressMax != m_blenderData.m_ulProgress)) {
progress = (float)m_blenderData.m_ulProgress;
progress /= (float)m_blenderData.m_ulProgressMax;
}
else {
progress = 0.f;
}
progress *= 100.f;
return (unsigned int) progress ;
#endif
return m_previousProgress + 0.01; // temporary TODO
}
void GPC_Engine::UpdateLoadingAnimation(void)
{
//int delta;
float progress = DetermineProgress();
if(progress > m_previousProgress)
{
// delta = progress - m_previousProgress;
m_previousProgress = progress;
if(m_previousProgress > 1.0)
m_previousProgress = 1.0; // limit to 1.0 (has to change !)
// m_engine->m_previousProgress = 0.0;
}
STR_String to = "";
STR_String from = "";
STR_String subject = "progress";
STR_String body;
body.Format("%f", progress); // a number between 0.0 and 1.0
if(m_networkdev)
{
// Store a progress message in the network device.
NG_NetworkMessage* msg = new NG_NetworkMessage(to, from, subject, body);
m_networkdev->SendNetworkMessage(msg);
msg->Release();
}
}
void GPC_Engine::Stop()
{
// only delete things that are created in StartKetsji()
/* if(m_portal)
{
m_portal->Leave();
delete m_portal; // also gets rid of KX_KetsjiEngine (says Maarten)
m_portal = 0;
}
*/ if(m_sceneconverter)
{
delete m_sceneconverter;
m_sceneconverter = 0;
}
#if 0
if(m_frameTimerID)
{
::KillTimer(0, m_frameTimerID);
m_frameTimerID = 0;
}
m_engineRunning = false;
#endif
m_running = false;
}
void GPC_Engine::Exit()
{
if(m_running)
Stop();
if (m_system) {
delete m_system;
m_system = 0;
}
if (m_keyboarddev) {
delete m_keyboarddev;
m_keyboarddev = 0;
}
if (m_mousedev) {
delete m_mousedev;
m_mousedev = 0;
}
if (m_canvas) {
delete m_canvas;
m_canvas = 0;
}
if (m_rendertools) {
delete m_rendertools;
m_rendertools = 0;
}
if (m_networkdev) {
delete m_networkdev;
m_networkdev = 0;
}
if (m_audiodevice)
{
SND_DeviceManager::Unsubscribe();
m_audiodevice = 0;
}
m_initialized = false;
}
|