2009-05-26 14:13:08 +00:00
|
|
|
/* Residual - A 3D game interpreter
|
2008-06-13 14:57:47 +00:00
|
|
|
*
|
|
|
|
* Residual is the legal property of its developers, whose names
|
2011-04-16 14:12:44 +02:00
|
|
|
* are too numerous to list here. Please refer to the COPYRIGHT
|
2008-06-13 14:57:47 +00:00
|
|
|
* file distributed with this source distribution.
|
2006-04-02 14:20:45 +00:00
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
|
|
|
|
|
|
|
* This library 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
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this library; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
|
|
|
|
*
|
|
|
|
* $URL$
|
|
|
|
* $Id$
|
|
|
|
*
|
|
|
|
*/
|
2003-08-15 18:00:22 +00:00
|
|
|
|
2010-01-21 19:25:03 +00:00
|
|
|
|
|
|
|
#if defined(WIN32)
|
|
|
|
#include <windows.h>
|
|
|
|
// winnt.h defines ARRAYSIZE, but we want our own one... - this is needed before including util.h
|
|
|
|
#undef ARRAYSIZE
|
|
|
|
#endif
|
|
|
|
|
2011-03-24 02:29:29 +08:00
|
|
|
#include "common/archive.h"
|
2009-05-07 19:06:31 +00:00
|
|
|
#include "common/events.h"
|
2009-10-05 08:33:46 +00:00
|
|
|
#include "common/file.h"
|
2011-04-10 21:59:04 +02:00
|
|
|
#include "common/fs.h"
|
2009-05-25 19:21:58 +00:00
|
|
|
#include "common/config-manager.h"
|
|
|
|
|
|
|
|
#include "engines/engine.h"
|
2008-01-26 11:47:23 +00:00
|
|
|
|
2009-05-24 19:13:58 +00:00
|
|
|
#include "engines/grim/grim.h"
|
|
|
|
#include "engines/grim/lua.h"
|
|
|
|
#include "engines/grim/actor.h"
|
|
|
|
#include "engines/grim/smush/smush.h"
|
|
|
|
#include "engines/grim/savegame.h"
|
|
|
|
#include "engines/grim/registry.h"
|
2009-05-25 19:21:58 +00:00
|
|
|
#include "engines/grim/resource.h"
|
|
|
|
#include "engines/grim/localize.h"
|
|
|
|
#include "engines/grim/gfx_tinygl.h"
|
|
|
|
#include "engines/grim/gfx_opengl.h"
|
2011-03-21 05:16:27 +08:00
|
|
|
#include "engines/grim/object.h"
|
|
|
|
#include "engines/grim/costume.h"
|
|
|
|
#include "engines/grim/material.h"
|
2011-04-10 11:24:03 +02:00
|
|
|
#include "engines/grim/lipsync.h"
|
2009-05-25 19:21:58 +00:00
|
|
|
|
|
|
|
#include "engines/grim/lua/lualib.h"
|
2008-01-26 11:47:23 +00:00
|
|
|
|
2009-05-24 19:13:58 +00:00
|
|
|
#include "engines/grim/imuse/imuse.h"
|
2004-04-20 17:49:12 +00:00
|
|
|
|
2011-03-21 05:16:27 +08:00
|
|
|
#include "lua/lobject.h"
|
|
|
|
#include "lua/lstate.h"
|
|
|
|
|
2009-05-25 06:49:57 +00:00
|
|
|
namespace Grim {
|
|
|
|
|
2009-05-25 19:21:58 +00:00
|
|
|
static bool g_lua_initialized = false;
|
|
|
|
|
2008-08-17 12:01:26 +00:00
|
|
|
// Entries in the system.controls table
|
|
|
|
|
|
|
|
const ControlDescriptor controls[] = {
|
|
|
|
{ "KEY_ESCAPE", Common::KEYCODE_ESCAPE },
|
|
|
|
{ "KEY_1", Common::KEYCODE_1 },
|
|
|
|
{ "KEY_2", Common::KEYCODE_2 },
|
|
|
|
{ "KEY_3", Common::KEYCODE_3 },
|
|
|
|
{ "KEY_4", Common::KEYCODE_4 },
|
|
|
|
{ "KEY_5", Common::KEYCODE_5 },
|
|
|
|
{ "KEY_6", Common::KEYCODE_6 },
|
|
|
|
{ "KEY_7", Common::KEYCODE_7 },
|
|
|
|
{ "KEY_8", Common::KEYCODE_8 },
|
|
|
|
{ "KEY_9", Common::KEYCODE_9 },
|
|
|
|
{ "KEY_0", Common::KEYCODE_0 },
|
|
|
|
{ "KEY_MINUS", Common::KEYCODE_MINUS },
|
|
|
|
{ "KEY_EQUALS", Common::KEYCODE_EQUALS },
|
|
|
|
{ "KEY_BACK", Common::KEYCODE_BACKSPACE },
|
|
|
|
{ "KEY_TAB", Common::KEYCODE_TAB },
|
|
|
|
{ "KEY_Q", Common::KEYCODE_q },
|
|
|
|
{ "KEY_W", Common::KEYCODE_w },
|
|
|
|
{ "KEY_E", Common::KEYCODE_e },
|
|
|
|
{ "KEY_R", Common::KEYCODE_r },
|
|
|
|
{ "KEY_T", Common::KEYCODE_t },
|
|
|
|
{ "KEY_Y", Common::KEYCODE_y },
|
|
|
|
{ "KEY_U", Common::KEYCODE_u },
|
|
|
|
{ "KEY_I", Common::KEYCODE_i },
|
|
|
|
{ "KEY_O", Common::KEYCODE_o },
|
|
|
|
{ "KEY_P", Common::KEYCODE_p },
|
|
|
|
{ "KEY_LBRACKET", Common::KEYCODE_LEFTBRACKET },
|
|
|
|
{ "KEY_RBRACKET", Common::KEYCODE_RIGHTBRACKET },
|
|
|
|
{ "KEY_RETURN", Common::KEYCODE_RETURN },
|
|
|
|
{ "KEY_LCONTROL", Common::KEYCODE_LCTRL },
|
|
|
|
{ "KEY_A", Common::KEYCODE_a },
|
|
|
|
{ "KEY_S", Common::KEYCODE_s },
|
|
|
|
{ "KEY_D", Common::KEYCODE_d },
|
|
|
|
{ "KEY_F", Common::KEYCODE_f },
|
|
|
|
{ "KEY_G", Common::KEYCODE_g },
|
|
|
|
{ "KEY_H", Common::KEYCODE_h },
|
|
|
|
{ "KEY_J", Common::KEYCODE_j },
|
|
|
|
{ "KEY_K", Common::KEYCODE_k },
|
|
|
|
{ "KEY_L", Common::KEYCODE_l },
|
|
|
|
{ "KEY_SEMICOLON", Common::KEYCODE_SEMICOLON },
|
|
|
|
{ "KEY_APOSTROPHE", Common::KEYCODE_QUOTEDBL },
|
|
|
|
{ "KEY_GRAVE", Common::KEYCODE_BACKQUOTE },
|
|
|
|
{ "KEY_LSHIFT", Common::KEYCODE_LSHIFT },
|
|
|
|
{ "KEY_BACKSLASH", Common::KEYCODE_BACKSLASH },
|
|
|
|
{ "KEY_Z", Common::KEYCODE_z },
|
|
|
|
{ "KEY_X", Common::KEYCODE_x },
|
|
|
|
{ "KEY_C", Common::KEYCODE_c },
|
|
|
|
{ "KEY_V", Common::KEYCODE_v },
|
|
|
|
{ "KEY_B", Common::KEYCODE_b },
|
|
|
|
{ "KEY_N", Common::KEYCODE_n },
|
|
|
|
{ "KEY_M", Common::KEYCODE_m },
|
|
|
|
{ "KEY_COMMA", Common::KEYCODE_COMMA },
|
|
|
|
{ "KEY_PERIOD", Common::KEYCODE_PERIOD },
|
|
|
|
{ "KEY_SLASH", Common::KEYCODE_SLASH },
|
|
|
|
{ "KEY_RSHIFT", Common::KEYCODE_RSHIFT },
|
|
|
|
{ "KEY_MULTIPLY", Common::KEYCODE_ASTERISK },
|
|
|
|
{ "KEY_LMENU", Common::KEYCODE_LALT },
|
|
|
|
{ "KEY_SPACE", Common::KEYCODE_SPACE },
|
|
|
|
{ "KEY_CAPITAL", Common::KEYCODE_CAPSLOCK },
|
|
|
|
{ "KEY_F1", Common::KEYCODE_F1 },
|
|
|
|
{ "KEY_F2", Common::KEYCODE_F2 },
|
|
|
|
{ "KEY_F3", Common::KEYCODE_F3 },
|
|
|
|
{ "KEY_F4", Common::KEYCODE_F4 },
|
|
|
|
{ "KEY_F5", Common::KEYCODE_F5 },
|
|
|
|
{ "KEY_F6", Common::KEYCODE_F6 },
|
|
|
|
{ "KEY_F7", Common::KEYCODE_F7 },
|
|
|
|
{ "KEY_F8", Common::KEYCODE_F8 },
|
|
|
|
{ "KEY_F9", Common::KEYCODE_F9 },
|
|
|
|
{ "KEY_F10", Common::KEYCODE_F10 },
|
|
|
|
{ "KEY_NUMLOCK", Common::KEYCODE_NUMLOCK },
|
|
|
|
{ "KEY_SCROLL", Common::KEYCODE_SCROLLOCK },
|
|
|
|
{ "KEY_NUMPAD7", Common::KEYCODE_KP7 },
|
|
|
|
{ "KEY_NUMPAD8", Common::KEYCODE_KP8 },
|
|
|
|
{ "KEY_NUMPAD9", Common::KEYCODE_KP9 },
|
|
|
|
{ "KEY_SUBTRACT", Common::KEYCODE_KP_MINUS },
|
|
|
|
{ "KEY_NUMPAD4", Common::KEYCODE_KP4 },
|
|
|
|
{ "KEY_NUMPAD5", Common::KEYCODE_KP5 },
|
|
|
|
{ "KEY_NUMPAD6", Common::KEYCODE_KP6 },
|
|
|
|
{ "KEY_ADD", Common::KEYCODE_KP_PLUS },
|
|
|
|
{ "KEY_NUMPAD1", Common::KEYCODE_KP1 },
|
|
|
|
{ "KEY_NUMPAD2", Common::KEYCODE_KP2 },
|
|
|
|
{ "KEY_NUMPAD3", Common::KEYCODE_KP3 },
|
|
|
|
{ "KEY_NUMPAD0", Common::KEYCODE_KP0 },
|
|
|
|
{ "KEY_DECIMAL", Common::KEYCODE_KP_PERIOD },
|
|
|
|
{ "KEY_F11", Common::KEYCODE_F11 },
|
|
|
|
{ "KEY_F12", Common::KEYCODE_F12 },
|
|
|
|
{ "KEY_F13", Common::KEYCODE_F13 },
|
|
|
|
{ "KEY_F14", Common::KEYCODE_F14 },
|
|
|
|
{ "KEY_F15", Common::KEYCODE_F15 },
|
|
|
|
{ "KEY_NUMPADEQUALS", Common::KEYCODE_KP_EQUALS },
|
|
|
|
{ "KEY_AT", Common::KEYCODE_AT },
|
|
|
|
{ "KEY_COLON", Common::KEYCODE_COLON },
|
|
|
|
{ "KEY_UNDERLINE", Common::KEYCODE_UNDERSCORE },
|
|
|
|
{ "KEY_STOP", Common::KEYCODE_BREAK },
|
|
|
|
{ "KEY_NUMPADENTER", Common::KEYCODE_KP_ENTER },
|
|
|
|
{ "KEY_RCONTROL", Common::KEYCODE_RCTRL },
|
|
|
|
{ "KEY_NUMPADCOMMA", Common::KEYCODE_KP_PERIOD },
|
|
|
|
{ "KEY_DIVIDE", Common::KEYCODE_KP_DIVIDE },
|
|
|
|
{ "KEY_SYSRQ", Common::KEYCODE_SYSREQ },
|
|
|
|
{ "KEY_RMENU", Common::KEYCODE_RALT },
|
|
|
|
{ "KEY_HOME", Common::KEYCODE_HOME },
|
|
|
|
{ "KEY_UP", Common::KEYCODE_UP },
|
|
|
|
{ "KEY_PRIOR", Common::KEYCODE_PAGEUP },
|
|
|
|
{ "KEY_LEFT", Common::KEYCODE_LEFT },
|
|
|
|
{ "KEY_RIGHT", Common::KEYCODE_RIGHT },
|
|
|
|
{ "KEY_END", Common::KEYCODE_END },
|
|
|
|
{ "KEY_DOWN", Common::KEYCODE_DOWN },
|
|
|
|
{ "KEY_NEXT", Common::KEYCODE_PAGEDOWN },
|
|
|
|
{ "KEY_INSERT", Common::KEYCODE_INSERT },
|
|
|
|
{ "KEY_DELETE", Common::KEYCODE_DELETE },
|
|
|
|
{ "KEY_LWIN", Common::KEYCODE_LSUPER },
|
|
|
|
{ "KEY_RWIN", Common::KEYCODE_RSUPER },
|
|
|
|
{ "KEY_APPS", Common::KEYCODE_MENU },
|
|
|
|
|
|
|
|
{ "KEY_JOY1_B1", KEYCODE_JOY1_B1 },
|
|
|
|
{ "KEY_JOY1_B2", KEYCODE_JOY1_B2 },
|
|
|
|
{ "KEY_JOY1_B3", KEYCODE_JOY1_B3 },
|
|
|
|
{ "KEY_JOY1_B4", KEYCODE_JOY1_B4 },
|
|
|
|
{ "KEY_JOY1_B5", KEYCODE_JOY1_B5 },
|
|
|
|
{ "KEY_JOY1_B6", KEYCODE_JOY1_B6 },
|
|
|
|
{ "KEY_JOY1_B7", KEYCODE_JOY1_B7 },
|
|
|
|
{ "KEY_JOY1_B8", KEYCODE_JOY1_B8 },
|
|
|
|
{ "KEY_JOY1_B9", KEYCODE_JOY1_B9 },
|
|
|
|
{ "KEY_JOY1_B10", KEYCODE_JOY1_B10 },
|
|
|
|
{ "KEY_JOY1_HLEFT", KEYCODE_JOY1_HLEFT },
|
|
|
|
{ "KEY_JOY1_HUP", KEYCODE_JOY1_HUP },
|
|
|
|
{ "KEY_JOY1_HRIGHT", KEYCODE_JOY1_HRIGHT },
|
|
|
|
{ "KEY_JOY1_HDOWN", KEYCODE_JOY1_HDOWN },
|
|
|
|
{ "KEY_JOY2_B1", KEYCODE_JOY2_B1 },
|
|
|
|
{ "KEY_JOY2_B2", KEYCODE_JOY2_B2 },
|
|
|
|
{ "KEY_JOY2_B3", KEYCODE_JOY2_B3 },
|
|
|
|
{ "KEY_JOY2_B4", KEYCODE_JOY2_B4 },
|
|
|
|
{ "KEY_JOY2_B5", KEYCODE_JOY2_B5 },
|
|
|
|
{ "KEY_JOY2_B6", KEYCODE_JOY2_B6 },
|
|
|
|
{ "KEY_JOY2_B7", KEYCODE_JOY2_B7 },
|
|
|
|
{ "KEY_JOY2_B8", KEYCODE_JOY2_B8 },
|
|
|
|
{ "KEY_JOY2_B9", KEYCODE_JOY2_B9 },
|
|
|
|
{ "KEY_JOY2_B10", KEYCODE_JOY2_B10 },
|
|
|
|
{ "KEY_JOY2_HLEFT", KEYCODE_JOY1_HLEFT },
|
|
|
|
{ "KEY_JOY2_HUP", KEYCODE_JOY2_HUP },
|
|
|
|
{ "KEY_JOY2_HRIGHT", KEYCODE_JOY2_HRIGHT },
|
|
|
|
{ "KEY_JOY2_HDOWN", KEYCODE_JOY2_HDOWN },
|
|
|
|
{ "KEY_MOUSE_B1", KEYCODE_MOUSE_B1 },
|
|
|
|
{ "KEY_MOUSE_B2", KEYCODE_MOUSE_B2 },
|
|
|
|
{ "KEY_MOUSE_B3", KEYCODE_MOUSE_B3 },
|
|
|
|
{ "KEY_MOUSE_B4", KEYCODE_MOUSE_B4 },
|
|
|
|
{ "AXIS_JOY1_X", KEYCODE_AXIS_JOY1_X },
|
|
|
|
{ "AXIS_JOY1_Y", KEYCODE_AXIS_JOY1_Y },
|
|
|
|
{ "AXIS_JOY1_Z", KEYCODE_AXIS_JOY1_Z },
|
|
|
|
{ "AXIS_JOY1_R", KEYCODE_AXIS_JOY1_R },
|
|
|
|
{ "AXIS_JOY1_U", KEYCODE_AXIS_JOY1_U },
|
|
|
|
{ "AXIS_JOY1_V", KEYCODE_AXIS_JOY1_V },
|
|
|
|
{ "AXIS_JOY2_X", KEYCODE_AXIS_JOY2_X },
|
|
|
|
{ "AXIS_JOY2_Y", KEYCODE_AXIS_JOY2_Y },
|
|
|
|
{ "AXIS_JOY2_Z", KEYCODE_AXIS_JOY2_Z },
|
|
|
|
{ "AXIS_JOY2_R", KEYCODE_AXIS_JOY2_R },
|
|
|
|
{ "AXIS_JOY2_U", KEYCODE_AXIS_JOY2_U },
|
|
|
|
{ "AXIS_JOY2_V", KEYCODE_AXIS_JOY2_V },
|
|
|
|
{ "AXIS_MOUSE_X", KEYCODE_AXIS_MOUSE_X },
|
|
|
|
{ "AXIS_MOUSE_Y", KEYCODE_AXIS_MOUSE_Y },
|
|
|
|
{ "AXIS_MOUSE_Z", KEYCODE_AXIS_MOUSE_Z },
|
|
|
|
|
|
|
|
{ NULL, 0 }
|
|
|
|
};
|
2003-08-15 18:00:22 +00:00
|
|
|
|
2005-12-26 19:26:46 +00:00
|
|
|
// CHAR_KEY tests to see whether a keycode is for
|
|
|
|
// a "character" handler or a "button" handler
|
2007-09-23 21:58:12 +00:00
|
|
|
#define CHAR_KEY(k) ((k >= 'a' && k <= 'z') || (k >= 'A' && k <= 'Z') || (k >= '0' && k <= '9') || k == ' ')
|
2005-12-26 19:26:46 +00:00
|
|
|
|
2009-05-17 08:24:17 +00:00
|
|
|
GrimEngine *g_grim = NULL;
|
2009-05-25 19:21:58 +00:00
|
|
|
GfxBase *g_driver = NULL;
|
2005-01-03 16:27:57 +00:00
|
|
|
int g_imuseState = -1;
|
2004-12-30 22:38:53 +00:00
|
|
|
|
2005-01-10 09:53:02 +00:00
|
|
|
// hack for access current upated actor to allow access position of actor to sound costume component
|
|
|
|
Actor *g_currentUpdatedActor = NULL;
|
|
|
|
|
2011-03-24 22:04:40 +08:00
|
|
|
GrimEngine::GrimEngine(OSystem *syst, int gameFlags, GrimGameType gameType) :
|
2009-06-23 07:14:53 +00:00
|
|
|
Engine(syst), _currScene(NULL), _selectedActor(NULL) {
|
2009-05-25 19:21:58 +00:00
|
|
|
g_grim = this;
|
|
|
|
|
2011-04-12 20:41:22 +08:00
|
|
|
ObjectMan.registerType<Color>();
|
|
|
|
ObjectMan.registerType<LuaFile>();
|
|
|
|
//ObjectMan.registerType<Bitmap>();
|
|
|
|
//ObjectMan.registerType<Costume>();
|
|
|
|
ObjectMan.registerType<Font>();
|
|
|
|
//ObjectMan.registerType<Material>();
|
2011-03-21 14:06:00 +01:00
|
|
|
|
2009-06-23 07:14:53 +00:00
|
|
|
_gameFlags = gameFlags;
|
2011-03-24 22:04:40 +08:00
|
|
|
_gameType = gameType;
|
2009-06-23 07:14:53 +00:00
|
|
|
|
2009-05-25 19:21:58 +00:00
|
|
|
g_registry = new Registry();
|
2009-05-26 06:27:47 +00:00
|
|
|
g_resourceloader = NULL;
|
|
|
|
g_localizer = NULL;
|
|
|
|
g_smush = NULL;
|
|
|
|
g_imuse = NULL;
|
2006-02-05 20:40:16 +00:00
|
|
|
|
2009-10-04 10:58:28 +00:00
|
|
|
_showFps = (tolower(g_registry->get("show_fps", "false")[0]) == 't');
|
2011-04-26 03:11:27 +08:00
|
|
|
|
|
|
|
#ifdef USE_OPENGL
|
2009-10-04 10:58:28 +00:00
|
|
|
_softRenderer = (tolower(g_registry->get("soft_renderer", "false")[0]) == 't');
|
2011-04-26 03:11:27 +08:00
|
|
|
#else
|
|
|
|
_softRenderer = true;
|
|
|
|
#endif
|
2009-05-25 19:21:58 +00:00
|
|
|
|
|
|
|
_mixer->setVolumeForSoundType(Audio::Mixer::kPlainSoundType, 127);
|
|
|
|
_mixer->setVolumeForSoundType(Audio::Mixer::kSFXSoundType, ConfMan.getInt("sfx_volume"));
|
|
|
|
_mixer->setVolumeForSoundType(Audio::Mixer::kSpeechSoundType, ConfMan.getInt("speech_volume"));
|
|
|
|
_mixer->setVolumeForSoundType(Audio::Mixer::kMusicSoundType, ConfMan.getInt("music_volume"));
|
|
|
|
|
|
|
|
_currScene = NULL;
|
|
|
|
_selectedActor = NULL;
|
2008-08-17 12:01:26 +00:00
|
|
|
_controlsEnabled = new bool[KEYCODE_EXTRA_LAST];
|
|
|
|
_controlsState = new bool[KEYCODE_EXTRA_LAST];
|
|
|
|
for (int i = 0; i < KEYCODE_EXTRA_LAST; i++) {
|
2004-12-09 23:55:43 +00:00
|
|
|
_controlsEnabled[i] = false;
|
2008-08-17 12:01:26 +00:00
|
|
|
_controlsState[i] = false;
|
|
|
|
}
|
2005-03-20 16:48:26 +00:00
|
|
|
_speechMode = 3; // VOICE + TEXT
|
2008-08-01 18:27:11 +00:00
|
|
|
_textSpeed = 7;
|
2005-08-13 13:35:43 +00:00
|
|
|
_mode = _previousMode = ENGINE_MODE_IDLE;
|
2005-08-13 16:25:51 +00:00
|
|
|
_flipEnable = true;
|
2008-08-17 05:36:41 +00:00
|
|
|
int speed = atol(g_registry->get("engine_speed", "30"));
|
2009-05-27 07:48:01 +00:00
|
|
|
if (speed <= 0 || speed > 100)
|
2009-05-27 07:45:54 +00:00
|
|
|
_speedLimitMs = 30;
|
2008-08-17 05:36:41 +00:00
|
|
|
else
|
|
|
|
_speedLimitMs = 1000 / speed;
|
|
|
|
char buf[20];
|
2008-08-17 07:50:38 +00:00
|
|
|
sprintf(buf, "%d", 1000 / _speedLimitMs);
|
2008-08-17 05:36:41 +00:00
|
|
|
g_registry->set("engine_speed", buf);
|
2005-08-13 16:25:51 +00:00
|
|
|
_refreshDrawNeeded = true;
|
2011-04-12 20:41:22 +08:00
|
|
|
_listFilesIter = NULL;
|
2005-12-26 02:36:00 +00:00
|
|
|
_savedState = NULL;
|
2008-07-20 09:55:29 +00:00
|
|
|
_fps[0] = 0;
|
2005-03-20 16:48:26 +00:00
|
|
|
|
2011-04-12 20:41:22 +08:00
|
|
|
_printLineDefaults.x = 0;
|
|
|
|
_printLineDefaults.y = 100;
|
|
|
|
_printLineDefaults.width = 0;
|
|
|
|
_printLineDefaults.height = 0;
|
2011-04-14 13:15:55 +02:00
|
|
|
_printLineDefaults.fgColor._vals[0] = 0;
|
|
|
|
_printLineDefaults.fgColor._vals[1] = 0;
|
|
|
|
_printLineDefaults.fgColor._vals[2] = 0;
|
2011-04-12 20:41:22 +08:00
|
|
|
_printLineDefaults.font = NULL;
|
|
|
|
_printLineDefaults.justify = TextObject::LJUSTIFY;
|
2011-04-14 13:15:55 +02:00
|
|
|
_printLineDefaults.disabled = false;
|
2011-04-12 20:41:22 +08:00
|
|
|
|
|
|
|
_sayLineDefaults.x = 0;
|
|
|
|
_sayLineDefaults.y = 100;
|
|
|
|
_sayLineDefaults.width = 0;
|
|
|
|
_sayLineDefaults.height = 0;
|
2011-04-14 13:15:55 +02:00
|
|
|
_sayLineDefaults.fgColor._vals[0] = 0;
|
|
|
|
_sayLineDefaults.fgColor._vals[1] = 0;
|
|
|
|
_sayLineDefaults.fgColor._vals[2] = 0;
|
2011-04-12 20:41:22 +08:00
|
|
|
_sayLineDefaults.font = NULL;
|
|
|
|
_sayLineDefaults.justify = TextObject::CENTER;
|
2011-04-14 13:15:55 +02:00
|
|
|
_sayLineDefaults.disabled = false;
|
2011-04-12 20:41:22 +08:00
|
|
|
|
|
|
|
_blastTextDefaults.x = 0;
|
|
|
|
_blastTextDefaults.y = 200;
|
|
|
|
_blastTextDefaults.width = 0;
|
|
|
|
_blastTextDefaults.height = 0;
|
2011-04-14 13:15:55 +02:00
|
|
|
_blastTextDefaults.fgColor._vals[0] = 0;
|
|
|
|
_blastTextDefaults.fgColor._vals[1] = 0;
|
2011-04-12 20:41:22 +08:00
|
|
|
_blastTextDefaults.fgColor._vals[2] = 80;
|
|
|
|
_blastTextDefaults.font = NULL;
|
|
|
|
_blastTextDefaults.justify = TextObject::LJUSTIFY;
|
2011-04-14 13:15:55 +02:00
|
|
|
_blastTextDefaults.disabled = false;
|
2011-03-24 02:29:29 +08:00
|
|
|
|
|
|
|
// Add 'movies' subdirectory for the demo
|
2011-04-10 21:59:04 +02:00
|
|
|
const Common::FSNode gameDataDir(ConfMan.get("path"));
|
|
|
|
SearchMan.addSubDirectoryMatching(gameDataDir, "movies");
|
2003-08-15 18:00:22 +00:00
|
|
|
}
|
|
|
|
|
2009-05-17 08:12:05 +00:00
|
|
|
GrimEngine::~GrimEngine() {
|
2011-04-12 20:41:22 +08:00
|
|
|
ObjectMan.clearTypes();
|
2011-03-21 14:06:00 +01:00
|
|
|
|
2006-02-05 20:40:16 +00:00
|
|
|
delete[] _controlsEnabled;
|
2008-08-17 12:01:26 +00:00
|
|
|
delete[] _controlsState;
|
2006-05-13 15:34:18 +00:00
|
|
|
|
2010-02-04 19:43:50 +00:00
|
|
|
for (SceneListType::const_iterator i = _scenes.begin(); i != _scenes.end(); ++i)
|
2011-03-21 05:16:27 +08:00
|
|
|
delete i->_value;
|
2006-05-13 15:34:18 +00:00
|
|
|
|
2010-02-04 19:43:50 +00:00
|
|
|
for (ActorListType::const_iterator i = _actors.begin(); i != _actors.end(); ++i)
|
2011-03-21 05:16:27 +08:00
|
|
|
delete i->_value;
|
2008-08-12 20:12:12 +00:00
|
|
|
|
|
|
|
killPrimitiveObjects();
|
|
|
|
killTextObjects();
|
2009-05-25 19:21:58 +00:00
|
|
|
|
|
|
|
if (g_lua_initialized) {
|
|
|
|
lua_removelibslists();
|
|
|
|
lua_close();
|
|
|
|
lua_iolibclose();
|
|
|
|
g_lua_initialized = false;
|
|
|
|
}
|
|
|
|
if (g_registry) {
|
|
|
|
g_registry->save();
|
|
|
|
delete g_registry;
|
|
|
|
g_registry = NULL;
|
|
|
|
}
|
|
|
|
delete g_smush;
|
|
|
|
g_smush = NULL;
|
|
|
|
delete g_imuse;
|
|
|
|
g_imuse = NULL;
|
|
|
|
delete g_localizer;
|
|
|
|
g_localizer = NULL;
|
|
|
|
delete g_resourceloader;
|
|
|
|
g_resourceloader = NULL;
|
|
|
|
delete g_driver;
|
|
|
|
g_driver = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
Common::Error GrimEngine::run() {
|
2009-05-26 06:27:47 +00:00
|
|
|
g_resourceloader = new ResourceLoader();
|
|
|
|
g_localizer = new Localizer();
|
|
|
|
g_smush = new Smush();
|
|
|
|
g_imuse = new Imuse(20);
|
|
|
|
|
2009-10-04 10:58:28 +00:00
|
|
|
bool fullscreen = (tolower(g_registry->get("fullscreen", "false")[0]) == 't');
|
2009-05-25 19:21:58 +00:00
|
|
|
|
2011-04-26 03:11:27 +08:00
|
|
|
if (!_softRenderer && !g_system->hasFeature(OSystem::kFeatureOpenGL)){
|
|
|
|
warning("gfx backend doesn't support hardware rendering");
|
|
|
|
_softRenderer=true;
|
|
|
|
}
|
2009-05-25 19:21:58 +00:00
|
|
|
|
|
|
|
if (_softRenderer)
|
|
|
|
g_driver = new GfxTinyGL();
|
|
|
|
#ifdef USE_OPENGL
|
|
|
|
else
|
|
|
|
g_driver = new GfxOpenGL();
|
|
|
|
#endif
|
|
|
|
|
2009-05-31 08:55:57 +00:00
|
|
|
g_driver->setupScreen(640, 480, fullscreen);
|
2009-05-25 19:21:58 +00:00
|
|
|
|
2011-03-21 05:16:27 +08:00
|
|
|
BitmapPtr splash_bm;
|
2011-03-24 22:11:32 +08:00
|
|
|
if (!(_gameFlags & GF_DEMO) && getGameType() == GType_GRIM)
|
2009-05-25 19:21:58 +00:00
|
|
|
splash_bm = g_resourceloader->loadBitmap("splash.bm");
|
|
|
|
|
|
|
|
g_driver->clearScreen();
|
|
|
|
|
2011-03-24 22:11:32 +08:00
|
|
|
if (!(_gameFlags & GF_DEMO) && getGameType() == GType_GRIM)
|
2009-05-25 19:21:58 +00:00
|
|
|
splash_bm->draw();
|
|
|
|
|
|
|
|
g_driver->flipBuffer();
|
|
|
|
|
|
|
|
lua_iolibopen();
|
|
|
|
lua_strlibopen();
|
|
|
|
lua_mathlibopen();
|
|
|
|
|
|
|
|
register_lua();
|
|
|
|
g_lua_initialized = true;
|
|
|
|
|
|
|
|
bundle_dofile("_system.lua");
|
|
|
|
|
|
|
|
lua_pushnil(); // resumeSave
|
|
|
|
lua_pushnil(); // bootParam - not used in scripts
|
|
|
|
// lua_pushnumber(0); // bootParam
|
|
|
|
lua_call("BOOT");
|
|
|
|
|
|
|
|
g_grim->setMode(ENGINE_MODE_NORMAL);
|
|
|
|
g_grim->mainLoop();
|
|
|
|
|
|
|
|
return Common::kNoError;
|
2006-02-05 20:40:16 +00:00
|
|
|
}
|
|
|
|
|
2009-05-31 16:09:21 +00:00
|
|
|
extern int refSystemTable;
|
|
|
|
|
|
|
|
void GrimEngine::handlePause() {
|
|
|
|
lua_Object func;
|
|
|
|
|
|
|
|
lua_beginblock();
|
|
|
|
|
|
|
|
lua_pushobject(lua_getref(refSystemTable));
|
|
|
|
lua_pushstring("pauseHandler");
|
|
|
|
lua_Object handler = lua_gettable();
|
|
|
|
if (lua_istable(handler)) {
|
|
|
|
lua_pushobject(handler);
|
|
|
|
lua_pushstring("pauseHandler");
|
|
|
|
func = lua_gettable();
|
|
|
|
if (!lua_isfunction(func))
|
|
|
|
error("handlePause: handler not a function");
|
|
|
|
lua_pushobject(handler);
|
|
|
|
} else if (lua_isfunction(handler)) {
|
|
|
|
func = handler;
|
|
|
|
} else if (!lua_isnil(handler)) {
|
|
|
|
error("handlePause: invalid handler");
|
2009-06-18 13:57:17 +00:00
|
|
|
return;
|
2009-05-31 16:09:21 +00:00
|
|
|
} else {
|
|
|
|
lua_endblock();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
lua_callfunction(func);
|
|
|
|
|
|
|
|
lua_endblock();
|
|
|
|
}
|
|
|
|
|
|
|
|
void GrimEngine::handleExit() {
|
|
|
|
lua_Object func;
|
|
|
|
|
|
|
|
lua_beginblock();
|
|
|
|
|
|
|
|
lua_pushobject(lua_getref(refSystemTable));
|
|
|
|
lua_pushstring("exitHandler");
|
|
|
|
lua_Object handler = lua_gettable();
|
|
|
|
if (lua_istable(handler)) {
|
|
|
|
lua_pushobject(handler);
|
|
|
|
lua_pushstring("exitHandler");
|
|
|
|
func = lua_gettable();
|
|
|
|
if (!lua_isfunction(func))
|
|
|
|
error("handleExit: handler not a function");
|
|
|
|
lua_pushobject(handler);
|
|
|
|
} else if (lua_isfunction(handler)) {
|
|
|
|
func = handler;
|
|
|
|
} else if (!lua_isnil(handler)) {
|
|
|
|
error("handleExit: invalid handler");
|
2009-06-18 13:57:17 +00:00
|
|
|
return;
|
2009-05-31 16:09:21 +00:00
|
|
|
} else {
|
|
|
|
lua_endblock();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
lua_callfunction(func);
|
|
|
|
|
|
|
|
lua_endblock();
|
|
|
|
}
|
|
|
|
|
|
|
|
void GrimEngine::handleUserPaint() {
|
|
|
|
lua_Object func;
|
|
|
|
|
|
|
|
lua_beginblock();
|
|
|
|
|
|
|
|
lua_pushobject(lua_getref(refSystemTable));
|
|
|
|
lua_pushstring("userPaintHandler");
|
|
|
|
lua_Object handler = lua_gettable();
|
|
|
|
if (lua_istable(handler)) {
|
|
|
|
lua_pushobject(handler);
|
|
|
|
lua_pushstring("userPaintHandler");
|
|
|
|
func = lua_gettable();
|
|
|
|
if (!lua_isfunction(func))
|
|
|
|
error("handleUserPaint: handler not a function");
|
|
|
|
lua_pushobject(handler);
|
|
|
|
} else if (lua_isfunction(handler)) {
|
|
|
|
func = handler;
|
|
|
|
} else if (!lua_isnil(handler)) {
|
|
|
|
error("handleUserPaint: invalid handler");
|
2009-06-18 13:57:17 +00:00
|
|
|
return;
|
2009-05-31 16:09:21 +00:00
|
|
|
} else {
|
|
|
|
lua_endblock();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
lua_callfunction(func);
|
|
|
|
|
|
|
|
lua_endblock();
|
|
|
|
}
|
|
|
|
|
|
|
|
void GrimEngine::handleChars(int operation, int key, int /*keyModifier*/, uint16 ascii) {
|
|
|
|
lua_Object func;
|
|
|
|
char keychar[2];
|
|
|
|
|
|
|
|
if (!CHAR_KEY(ascii))
|
|
|
|
return;
|
|
|
|
|
|
|
|
lua_beginblock();
|
|
|
|
|
|
|
|
lua_pushobject(lua_getref(refSystemTable));
|
|
|
|
lua_pushstring("characterHandler");
|
|
|
|
lua_Object handler = lua_gettable();
|
|
|
|
if (lua_istable(handler)) {
|
|
|
|
lua_pushobject(handler);
|
|
|
|
lua_pushstring("characterHandler");
|
|
|
|
func = lua_gettable();
|
|
|
|
if (!lua_isfunction(func))
|
|
|
|
error("handleChars: handler not a function");
|
|
|
|
lua_pushobject(handler);
|
|
|
|
} else if (lua_isfunction(handler)) {
|
|
|
|
func = handler;
|
|
|
|
} else if (!lua_isnil(handler)) {
|
|
|
|
error("handleChars: invalid handler");
|
2009-06-18 13:57:17 +00:00
|
|
|
return;
|
2009-05-31 16:09:21 +00:00
|
|
|
} else {
|
|
|
|
lua_endblock();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
keychar[0] = ascii;
|
|
|
|
keychar[1] = 0;
|
|
|
|
lua_pushstring(keychar);
|
|
|
|
lua_callfunction(func);
|
|
|
|
|
|
|
|
lua_endblock();
|
|
|
|
}
|
|
|
|
|
|
|
|
void GrimEngine::handleControls(int operation, int key, int /*keyModifier*/, uint16 ascii) {
|
|
|
|
lua_Object buttonFunc, joyFunc;
|
|
|
|
bool buttonFuncIsTable, joyFuncIsTable;
|
2009-05-09 17:47:28 +00:00
|
|
|
|
2005-07-17 23:40:22 +00:00
|
|
|
// If we're not supposed to handle the key then don't
|
|
|
|
if (!_controlsEnabled[key])
|
|
|
|
return;
|
2005-04-05 13:50:54 +00:00
|
|
|
|
2009-05-31 16:09:21 +00:00
|
|
|
lua_beginblock();
|
|
|
|
|
|
|
|
lua_pushobject(lua_getref(refSystemTable));
|
|
|
|
lua_pushstring("buttonHandler");
|
|
|
|
lua_Object buttonHandler = lua_gettable();
|
|
|
|
if (lua_istable(buttonHandler)) {
|
|
|
|
lua_pushobject(buttonHandler);
|
|
|
|
lua_pushstring("buttonHandler");
|
|
|
|
buttonFunc = lua_gettable();
|
2009-06-18 13:57:17 +00:00
|
|
|
if (!lua_isfunction(buttonFunc)) {
|
2009-05-31 16:09:21 +00:00
|
|
|
error("handleControls: button handler not a function");
|
2009-06-18 13:57:17 +00:00
|
|
|
return;
|
|
|
|
}
|
2009-05-31 16:09:21 +00:00
|
|
|
buttonFuncIsTable = true;
|
|
|
|
} else if (lua_isfunction(buttonHandler)) {
|
|
|
|
buttonFunc = buttonHandler;
|
|
|
|
buttonFuncIsTable = false;
|
2009-06-18 13:57:17 +00:00
|
|
|
} else {
|
2009-05-31 16:09:21 +00:00
|
|
|
error("handleControls: invalid keys handler");
|
2009-06-18 13:57:17 +00:00
|
|
|
return;
|
|
|
|
}
|
2009-05-31 16:09:21 +00:00
|
|
|
|
|
|
|
lua_pushobject(lua_getref(refSystemTable));
|
|
|
|
lua_pushstring("axisHandler");
|
|
|
|
lua_Object joyHandler = lua_gettable();
|
|
|
|
if (lua_istable(joyHandler)) {
|
|
|
|
lua_pushobject(joyHandler);
|
|
|
|
lua_pushstring("axisHandler");
|
|
|
|
joyFunc = lua_gettable();
|
2009-06-18 13:57:17 +00:00
|
|
|
if (!lua_isfunction(joyFunc)) {
|
2009-05-31 16:09:21 +00:00
|
|
|
error("handleControls: joystick handler not a function");
|
2009-06-18 13:57:17 +00:00
|
|
|
return;
|
|
|
|
}
|
2009-05-31 16:09:21 +00:00
|
|
|
joyFuncIsTable = true;
|
|
|
|
} else if (lua_isfunction(joyHandler)) {
|
|
|
|
joyFunc = joyHandler;
|
|
|
|
joyFuncIsTable = false;
|
2009-06-18 13:57:17 +00:00
|
|
|
} else {
|
2009-05-31 16:09:21 +00:00
|
|
|
error("handleControls: invalid joystick handler");
|
2009-06-18 13:57:17 +00:00
|
|
|
return;
|
|
|
|
}
|
2009-05-31 16:09:21 +00:00
|
|
|
if (buttonFuncIsTable)
|
|
|
|
lua_pushobject(buttonHandler);
|
|
|
|
lua_pushnumber(key);
|
|
|
|
if (operation == Common::EVENT_KEYDOWN) {
|
|
|
|
lua_pushnumber(1);
|
|
|
|
lua_pushnumber(1);
|
|
|
|
} else {
|
|
|
|
lua_pushnil();
|
|
|
|
lua_pushnumber(0);
|
|
|
|
}
|
|
|
|
lua_pushnumber(0);
|
|
|
|
lua_callfunction(buttonFunc);
|
|
|
|
|
2008-08-17 12:01:26 +00:00
|
|
|
if (operation == Common::EVENT_KEYDOWN)
|
|
|
|
_controlsState[key] = true;
|
|
|
|
else if (operation == Common::EVENT_KEYUP)
|
|
|
|
_controlsState[key] = false;
|
|
|
|
|
2005-04-05 13:50:54 +00:00
|
|
|
lua_endblock();
|
|
|
|
}
|
|
|
|
|
2009-05-17 08:12:05 +00:00
|
|
|
void GrimEngine::handleDebugLoadResource() {
|
2008-07-13 10:53:39 +00:00
|
|
|
void *resource = NULL;
|
2005-08-13 13:35:43 +00:00
|
|
|
int c, i = 0;
|
|
|
|
char buf[512];
|
|
|
|
|
|
|
|
// Tool for debugging the loading of a particular resource without
|
|
|
|
// having to actually make it all the way to it in the game
|
|
|
|
fprintf(stderr, "Enter resource to load (extension specifies type): ");
|
|
|
|
while (i < 512 && (c = fgetc(stdin)) != EOF && c != '\n')
|
|
|
|
buf[i++] = c;
|
|
|
|
|
|
|
|
buf[i] = '\0';
|
2009-05-12 14:32:43 +00:00
|
|
|
if (strstr(buf, ".key"))
|
2005-08-13 13:35:43 +00:00
|
|
|
resource = (void *)g_resourceloader->loadKeyframe(buf);
|
|
|
|
else if (strstr(buf, ".zbm") || strstr(buf, ".bm"))
|
|
|
|
resource = (void *)g_resourceloader->loadBitmap(buf);
|
|
|
|
else if (strstr(buf, ".cmp"))
|
|
|
|
resource = (void *)g_resourceloader->loadColormap(buf);
|
|
|
|
else if (strstr(buf, ".cos"))
|
|
|
|
resource = (void *)g_resourceloader->loadCostume(buf, NULL);
|
|
|
|
else if (strstr(buf, ".lip"))
|
2009-04-21 18:04:24 +00:00
|
|
|
resource = (void *)g_resourceloader->loadLipSync(buf);
|
2005-08-13 13:35:43 +00:00
|
|
|
else if (strstr(buf, ".snm"))
|
2009-06-09 15:34:59 +00:00
|
|
|
resource = (void *)g_smush->play(buf, false, 0, 0);
|
2005-08-13 13:35:43 +00:00
|
|
|
else if (strstr(buf, ".wav") || strstr(buf, ".imu")) {
|
|
|
|
g_imuse->startSfx(buf);
|
|
|
|
resource = (void *)1;
|
|
|
|
} else if (strstr(buf, ".mat")) {
|
|
|
|
CMap *cmap = g_resourceloader->loadColormap("item.cmp");
|
2009-05-31 07:33:18 +00:00
|
|
|
warning("Default colormap applied to resources loaded in this fashion");
|
2009-06-26 16:13:11 +00:00
|
|
|
resource = (void *)g_resourceloader->loadMaterial(buf, cmap);
|
2005-08-13 13:35:43 +00:00
|
|
|
} else {
|
2009-05-31 07:33:18 +00:00
|
|
|
warning("Resource type not understood");
|
2005-08-13 13:35:43 +00:00
|
|
|
}
|
2008-07-30 07:04:32 +00:00
|
|
|
if (!resource)
|
2009-05-31 07:35:15 +00:00
|
|
|
warning("Requested resouce (%s) not found", buf);
|
2005-08-13 13:35:43 +00:00
|
|
|
}
|
2005-08-28 23:25:14 +00:00
|
|
|
|
2009-06-08 22:25:14 +00:00
|
|
|
static void cameraChangeHandle(int prev, int next) {
|
|
|
|
lua_beginblock();
|
|
|
|
|
|
|
|
lua_pushobject(lua_getref(refSystemTable));
|
|
|
|
lua_pushstring("camChangeHandler");
|
|
|
|
lua_Object func = lua_gettable();
|
|
|
|
|
|
|
|
if (lua_isfunction(func)) {
|
|
|
|
lua_pushnumber(prev);
|
|
|
|
lua_pushnumber(next);
|
|
|
|
lua_callfunction(func);
|
|
|
|
}
|
|
|
|
|
|
|
|
lua_endblock();
|
|
|
|
}
|
|
|
|
|
|
|
|
static void cameraPostChangeHandle(int num) {
|
|
|
|
lua_beginblock();
|
|
|
|
|
|
|
|
lua_pushobject(lua_getref(refSystemTable));
|
|
|
|
lua_pushstring("postCamChangeHandler");
|
|
|
|
lua_Object func = lua_gettable();
|
|
|
|
|
|
|
|
if (lua_isfunction(func)) {
|
|
|
|
lua_pushnumber(num);
|
|
|
|
lua_callfunction(func);
|
|
|
|
}
|
|
|
|
|
|
|
|
lua_endblock();
|
|
|
|
}
|
|
|
|
|
2009-05-17 08:12:05 +00:00
|
|
|
void GrimEngine::drawPrimitives() {
|
2005-08-14 13:26:37 +00:00
|
|
|
// Draw Primitives
|
2010-02-04 19:43:50 +00:00
|
|
|
for (PrimitiveListType::iterator i = _primitiveObjects.begin(); i != _primitiveObjects.end(); ++i) {
|
2011-03-21 05:16:27 +08:00
|
|
|
i->_value->draw();
|
2005-08-14 13:26:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Draw text
|
2010-02-04 19:43:50 +00:00
|
|
|
for (TextListType::iterator i = _textObjects.begin(); i != _textObjects.end(); ++i) {
|
2011-03-21 05:16:27 +08:00
|
|
|
i->_value->draw();
|
2005-08-14 13:26:37 +00:00
|
|
|
}
|
|
|
|
}
|
2005-08-13 13:35:43 +00:00
|
|
|
|
2009-05-17 08:12:05 +00:00
|
|
|
void GrimEngine::luaUpdate() {
|
2011-04-21 17:25:00 +02:00
|
|
|
if (_savegameLoadRequest || _savegameSaveRequest)
|
2011-04-21 11:05:28 +02:00
|
|
|
return;
|
|
|
|
|
2005-08-13 13:35:43 +00:00
|
|
|
// Update timing information
|
2009-05-07 19:06:31 +00:00
|
|
|
unsigned newStart = g_system->getMillis();
|
2006-01-21 17:22:39 +00:00
|
|
|
if (newStart < _frameStart) {
|
|
|
|
_frameStart = newStart;
|
|
|
|
return;
|
|
|
|
}
|
2005-08-13 13:35:43 +00:00
|
|
|
_frameTime = newStart - _frameStart;
|
|
|
|
_frameStart = newStart;
|
|
|
|
|
|
|
|
_frameTimeCollection += _frameTime;
|
|
|
|
if (_frameTimeCollection > 10000) {
|
|
|
|
_frameTimeCollection = 0;
|
|
|
|
lua_collectgarbage(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
lua_beginblock();
|
|
|
|
setFrameTime(_frameTime);
|
|
|
|
lua_endblock();
|
|
|
|
|
|
|
|
lua_beginblock();
|
|
|
|
setMovieTime(_movieTime);
|
|
|
|
lua_endblock();
|
|
|
|
|
|
|
|
// Run asynchronous tasks
|
|
|
|
lua_runtasks();
|
2011-04-24 16:45:10 +02:00
|
|
|
|
2011-04-24 16:55:36 +02:00
|
|
|
if (_mode != ENGINE_MODE_PAUSE) {
|
|
|
|
// Update the actors. Do it here so that we are sure to react asap to any change
|
|
|
|
// in the actors state caused by lua.
|
|
|
|
for (ActorListType::iterator i = _actors.begin(); i != _actors.end(); ++i) {
|
|
|
|
Actor *a = i->_value;
|
|
|
|
|
|
|
|
// Update the actor's costumes & chores
|
|
|
|
g_currentUpdatedActor = i->_value;
|
|
|
|
// Note that the actor need not be visible to update chores, for example:
|
|
|
|
// when Manny has just brought Meche back he is offscreen several times
|
|
|
|
// when he needs to perform certain chores
|
|
|
|
if (a->inSet(_currScene->name()))
|
|
|
|
a->update();
|
|
|
|
}
|
|
|
|
g_currentUpdatedActor = NULL;
|
2011-04-24 16:45:10 +02:00
|
|
|
}
|
2005-08-13 13:35:43 +00:00
|
|
|
}
|
|
|
|
|
2009-05-17 08:12:05 +00:00
|
|
|
void GrimEngine::updateDisplayScene() {
|
2005-08-28 23:25:14 +00:00
|
|
|
_doFlip = true;
|
2005-08-13 13:35:43 +00:00
|
|
|
|
|
|
|
if (_mode == ENGINE_MODE_SMUSH) {
|
|
|
|
if (g_smush->isPlaying()) {
|
2005-08-13 16:25:51 +00:00
|
|
|
//_mode = ENGINE_MODE_NORMAL; ???
|
2005-08-13 13:35:43 +00:00
|
|
|
_movieTime = g_smush->getMovieTime();
|
|
|
|
if (g_smush->isUpdateNeeded()) {
|
|
|
|
g_driver->prepareSmushFrame(g_smush->getWidth(), g_smush->getHeight(), g_smush->getDstPtr());
|
|
|
|
g_smush->clearUpdateNeeded();
|
|
|
|
}
|
|
|
|
int frame = g_smush->getFrame();
|
|
|
|
if (frame > 0) {
|
|
|
|
if (frame != _prevSmushFrame) {
|
|
|
|
_prevSmushFrame = g_smush->getFrame();
|
|
|
|
g_driver->drawSmushFrame(g_smush->getX(), g_smush->getY());
|
2009-05-25 19:21:58 +00:00
|
|
|
if (_showFps)
|
2005-08-28 23:25:14 +00:00
|
|
|
g_driver->drawEmergString(550, 25, _fps, Color(255, 255, 255));
|
2005-08-13 13:35:43 +00:00
|
|
|
} else
|
2005-08-28 23:25:14 +00:00
|
|
|
_doFlip = false;
|
2008-08-12 14:55:16 +00:00
|
|
|
} else
|
|
|
|
g_driver->releaseSmushFrame();
|
2005-08-13 13:35:43 +00:00
|
|
|
}
|
2005-08-28 23:25:14 +00:00
|
|
|
drawPrimitives();
|
2005-08-13 13:35:43 +00:00
|
|
|
} else if (_mode == ENGINE_MODE_NORMAL) {
|
2008-07-30 07:04:32 +00:00
|
|
|
if (!_currScene)
|
2005-08-13 16:25:51 +00:00
|
|
|
return;
|
|
|
|
|
2009-06-09 15:34:59 +00:00
|
|
|
cameraPostChangeHandle(_currScene->setup());
|
|
|
|
|
2008-09-26 11:57:56 +00:00
|
|
|
g_driver->clearScreen();
|
2005-08-13 16:25:51 +00:00
|
|
|
|
2005-08-13 13:35:43 +00:00
|
|
|
_prevSmushFrame = 0;
|
2005-08-13 16:25:51 +00:00
|
|
|
|
|
|
|
_currScene->drawBackground();
|
|
|
|
|
|
|
|
// Draw underlying scene components
|
|
|
|
// Background objects are drawn underneath everything except the background
|
|
|
|
// There are a bunch of these, especially in the tube-switcher room
|
|
|
|
_currScene->drawBitmaps(ObjectState::OBJSTATE_BACKGROUND);
|
2009-06-07 20:23:28 +00:00
|
|
|
|
|
|
|
// Underlay objects are just above the background
|
|
|
|
_currScene->drawBitmaps(ObjectState::OBJSTATE_UNDERLAY);
|
|
|
|
|
2005-08-13 16:25:51 +00:00
|
|
|
// State objects are drawn on top of other things, such as the flag
|
|
|
|
// on Manny's message tube
|
|
|
|
_currScene->drawBitmaps(ObjectState::OBJSTATE_STATE);
|
|
|
|
|
|
|
|
// Play SMUSH Animations
|
|
|
|
// This should occur on top of all underlying scene objects,
|
|
|
|
// a good example is the tube switcher room where some state objects
|
|
|
|
// need to render underneath the animation or you can't see what's going on
|
|
|
|
// This should not occur on top of everything though or Manny gets covered
|
|
|
|
// up when he's next to Glottis's service room
|
|
|
|
if (g_smush->isPlaying()) {
|
|
|
|
_movieTime = g_smush->getMovieTime();
|
|
|
|
if (g_smush->isUpdateNeeded()) {
|
|
|
|
g_driver->prepareSmushFrame(g_smush->getWidth(), g_smush->getHeight(), g_smush->getDstPtr());
|
|
|
|
g_smush->clearUpdateNeeded();
|
|
|
|
}
|
|
|
|
if (g_smush->getFrame() > 0)
|
|
|
|
g_driver->drawSmushFrame(g_smush->getX(), g_smush->getY());
|
2008-08-12 14:55:16 +00:00
|
|
|
else
|
|
|
|
g_driver->releaseSmushFrame();
|
2005-08-13 16:25:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
_currScene->setupCamera();
|
|
|
|
|
|
|
|
g_driver->set3DMode();
|
|
|
|
|
|
|
|
_currScene->setupLights();
|
|
|
|
|
|
|
|
// Draw actors
|
2010-02-04 19:43:50 +00:00
|
|
|
for (ActorListType::iterator i = _actors.begin(); i != _actors.end(); ++i) {
|
2011-03-21 05:16:27 +08:00
|
|
|
Actor *a = i->_value;
|
2005-08-13 16:25:51 +00:00
|
|
|
if (a->inSet(_currScene->name()) && a->visible())
|
|
|
|
a->draw();
|
|
|
|
a->undraw(a->inSet(_currScene->name()) && a->visible());
|
|
|
|
}
|
2008-07-05 08:48:39 +00:00
|
|
|
flagRefreshShadowMask(false);
|
2005-08-13 16:25:51 +00:00
|
|
|
|
|
|
|
// Draw overlying scene components
|
|
|
|
// The overlay objects should be drawn on top of everything else,
|
|
|
|
// including 3D objects such as Manny and the message tube
|
|
|
|
_currScene->drawBitmaps(ObjectState::OBJSTATE_OVERLAY);
|
2005-08-13 20:14:46 +00:00
|
|
|
|
|
|
|
g_driver->storeDisplay();
|
2005-08-28 23:25:14 +00:00
|
|
|
drawPrimitives();
|
2005-08-13 13:35:43 +00:00
|
|
|
} else if (_mode == ENGINE_MODE_DRAW) {
|
2011-04-28 13:12:38 +02:00
|
|
|
// Adding line below and comment out rest solve flickering, also in tripple buffering mode too
|
|
|
|
_doFlip = false;
|
|
|
|
/* if (_refreshDrawNeeded) {
|
2009-05-31 16:09:21 +00:00
|
|
|
handleUserPaint();
|
2005-08-14 13:26:37 +00:00
|
|
|
g_driver->flipBuffer();
|
2005-08-13 16:25:51 +00:00
|
|
|
}
|
|
|
|
_refreshDrawNeeded = false;
|
2011-04-28 13:12:38 +02:00
|
|
|
return;*/
|
2005-08-13 13:35:43 +00:00
|
|
|
}
|
2005-08-28 23:25:14 +00:00
|
|
|
}
|
2005-08-13 13:35:43 +00:00
|
|
|
|
2009-05-17 08:12:05 +00:00
|
|
|
void GrimEngine::doFlip() {
|
2009-05-25 19:21:58 +00:00
|
|
|
if (_showFps && _doFlip)
|
2005-08-28 23:25:14 +00:00
|
|
|
g_driver->drawEmergString(550, 25, _fps, Color(255, 255, 255));
|
2005-08-13 13:35:43 +00:00
|
|
|
|
2005-08-28 23:25:14 +00:00
|
|
|
if (_doFlip && _flipEnable)
|
2005-08-13 13:35:43 +00:00
|
|
|
g_driver->flipBuffer();
|
|
|
|
|
2009-05-25 19:21:58 +00:00
|
|
|
if (_showFps && _doFlip && _mode != ENGINE_MODE_DRAW) {
|
2005-08-13 13:35:43 +00:00
|
|
|
_frameCounter++;
|
|
|
|
_timeAccum += _frameTime;
|
2008-08-16 17:54:14 +00:00
|
|
|
if (_timeAccum > 500) {
|
2005-08-28 23:25:14 +00:00
|
|
|
sprintf(_fps, "%7.2f", (double)(_frameCounter * 1000) / (double)_timeAccum );
|
2005-08-13 13:35:43 +00:00
|
|
|
_frameCounter = 0;
|
|
|
|
_timeAccum = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-05-17 08:12:05 +00:00
|
|
|
void GrimEngine::mainLoop() {
|
2004-12-09 23:55:43 +00:00
|
|
|
_movieTime = 0;
|
|
|
|
_frameTime = 0;
|
2009-05-07 19:06:31 +00:00
|
|
|
_frameStart = g_system->getMillis();
|
2005-08-13 13:35:43 +00:00
|
|
|
_frameCounter = 0;
|
|
|
|
_timeAccum = 0;
|
|
|
|
_frameTimeCollection = 0;
|
|
|
|
_prevSmushFrame = 0;
|
2004-11-01 09:47:19 +00:00
|
|
|
_savegameLoadRequest = false;
|
|
|
|
_savegameSaveRequest = false;
|
|
|
|
_savegameFileName = NULL;
|
2008-07-05 08:48:39 +00:00
|
|
|
_refreshShadowMask = false;
|
2004-11-01 09:47:19 +00:00
|
|
|
|
2004-02-24 21:09:53 +00:00
|
|
|
for (;;) {
|
2009-05-07 19:06:31 +00:00
|
|
|
uint32 startTime = g_system->getMillis();
|
2008-08-16 17:54:14 +00:00
|
|
|
|
2005-08-13 13:35:43 +00:00
|
|
|
if (_savegameLoadRequest) {
|
|
|
|
savegameRestore();
|
|
|
|
}
|
|
|
|
if (_savegameSaveRequest) {
|
|
|
|
savegameSave();
|
|
|
|
}
|
|
|
|
|
|
|
|
g_imuse->flushTracks();
|
|
|
|
g_imuse->refreshScripts();
|
|
|
|
|
2008-08-16 17:54:14 +00:00
|
|
|
if (_mode == ENGINE_MODE_IDLE) {
|
|
|
|
// don't kill CPU
|
2009-05-07 19:06:31 +00:00
|
|
|
g_system->delayMillis(10);
|
2005-08-13 13:35:43 +00:00
|
|
|
continue;
|
2008-08-16 17:54:14 +00:00
|
|
|
}
|
2005-08-13 13:35:43 +00:00
|
|
|
|
2004-02-24 21:09:53 +00:00
|
|
|
// Process events
|
2008-08-17 12:01:26 +00:00
|
|
|
Common::Event event;
|
2009-05-07 19:06:31 +00:00
|
|
|
while (g_system->getEventManager()->pollEvent(event)) {
|
2009-05-31 16:09:21 +00:00
|
|
|
// Handle any buttons, keys and joystick operations
|
|
|
|
if (event.type == Common::EVENT_KEYDOWN) {
|
2010-01-27 19:25:22 +00:00
|
|
|
if (_mode != ENGINE_MODE_DRAW && _mode != ENGINE_MODE_SMUSH && (event.kbd.ascii == 'q')) {
|
2009-05-31 16:09:21 +00:00
|
|
|
handleExit();
|
|
|
|
break;
|
|
|
|
} else {
|
|
|
|
handleChars(event.type, event.kbd.keycode, event.kbd.flags, event.kbd.ascii);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (event.type == Common::EVENT_KEYDOWN || event.type == Common::EVENT_KEYUP) {
|
|
|
|
handleControls(event.type, event.kbd.keycode, event.kbd.flags, event.kbd.ascii);
|
|
|
|
}
|
2005-07-17 23:40:22 +00:00
|
|
|
// Check for "Hard" quit"
|
2008-08-17 12:01:26 +00:00
|
|
|
if (event.type == Common::EVENT_QUIT)
|
2005-07-17 23:40:22 +00:00
|
|
|
return;
|
2008-08-17 12:01:26 +00:00
|
|
|
if (event.type == Common::EVENT_SCREEN_CHANGED)
|
2005-08-20 18:54:17 +00:00
|
|
|
_refreshDrawNeeded = true;
|
2011-04-20 18:23:03 +02:00
|
|
|
|
|
|
|
// Allow lua to react to the event.
|
|
|
|
// Without this lua_update switching the entries in the menu is slow because
|
|
|
|
// if the button is not kept pressed the KEYUP will arrive just after the KEYDOWN
|
|
|
|
// and it will break the lua scripts that checks for the state of the button
|
|
|
|
// with GetControlState()
|
|
|
|
luaUpdate();
|
2004-02-24 21:09:53 +00:00
|
|
|
}
|
|
|
|
|
2005-08-13 13:35:43 +00:00
|
|
|
luaUpdate();
|
2004-11-01 16:36:41 +00:00
|
|
|
|
2005-08-13 13:35:43 +00:00
|
|
|
if (_mode != ENGINE_MODE_PAUSE) {
|
|
|
|
updateDisplayScene();
|
2005-08-28 23:25:14 +00:00
|
|
|
doFlip();
|
2004-04-15 20:39:09 +00:00
|
|
|
}
|
2004-10-31 09:31:34 +00:00
|
|
|
|
2005-01-03 16:27:57 +00:00
|
|
|
if (g_imuseState != -1) {
|
|
|
|
g_imuse->setMusicState(g_imuseState);
|
|
|
|
g_imuseState = -1;
|
|
|
|
}
|
2008-08-16 17:54:14 +00:00
|
|
|
|
2009-05-07 19:06:31 +00:00
|
|
|
uint32 endTime = g_system->getMillis();
|
2008-08-16 17:54:14 +00:00
|
|
|
if (startTime > endTime)
|
|
|
|
continue;
|
|
|
|
uint32 diffTime = endTime - startTime;
|
2008-08-17 05:36:41 +00:00
|
|
|
if (_speedLimitMs == 0)
|
|
|
|
continue;
|
2008-08-16 17:54:14 +00:00
|
|
|
if (diffTime < _speedLimitMs) {
|
|
|
|
uint32 delayTime = _speedLimitMs - diffTime;
|
2009-05-07 19:06:31 +00:00
|
|
|
g_system->delayMillis(delayTime);
|
2008-08-16 17:54:14 +00:00
|
|
|
}
|
2004-02-24 21:09:53 +00:00
|
|
|
}
|
2003-08-15 18:00:22 +00:00
|
|
|
}
|
|
|
|
|
2009-05-17 08:12:05 +00:00
|
|
|
void GrimEngine::savegameReadStream(void *data, int32 size) {
|
2009-05-17 08:24:17 +00:00
|
|
|
g_grim->_savedState->read(data, size);
|
2006-05-13 10:16:19 +00:00
|
|
|
}
|
|
|
|
|
2009-05-17 08:12:05 +00:00
|
|
|
void GrimEngine::savegameWriteStream(void *data, int32 size) {
|
2009-05-17 08:24:17 +00:00
|
|
|
g_grim->_savedState->write(data, size);
|
2006-05-13 10:16:19 +00:00
|
|
|
}
|
|
|
|
|
2009-05-17 08:12:05 +00:00
|
|
|
int32 GrimEngine::savegameReadSint32() {
|
2009-05-17 08:24:17 +00:00
|
|
|
return g_grim->_savedState->readLESint32();
|
2008-07-25 22:21:04 +00:00
|
|
|
}
|
|
|
|
|
2009-05-17 08:12:05 +00:00
|
|
|
void GrimEngine::savegameWriteSint32(int32 val) {
|
2009-05-17 08:24:17 +00:00
|
|
|
g_grim->_savedState->writeLESint32(val);
|
2008-07-25 22:21:04 +00:00
|
|
|
}
|
|
|
|
|
2009-05-17 08:12:05 +00:00
|
|
|
uint32 GrimEngine::savegameReadUint32() {
|
2009-05-17 08:24:17 +00:00
|
|
|
return g_grim->_savedState->readLEUint32();
|
2008-07-25 22:21:04 +00:00
|
|
|
}
|
|
|
|
|
2009-05-17 08:12:05 +00:00
|
|
|
void GrimEngine::savegameWriteUint32(uint32 val) {
|
2009-05-17 08:24:17 +00:00
|
|
|
g_grim->_savedState->writeLEUint32(val);
|
2008-07-25 22:21:04 +00:00
|
|
|
}
|
|
|
|
|
2009-05-17 08:12:05 +00:00
|
|
|
void GrimEngine::savegameRestore() {
|
|
|
|
printf("GrimEngine::savegameRestore() started.\n");
|
2004-11-01 16:36:41 +00:00
|
|
|
_savegameLoadRequest = false;
|
|
|
|
char filename[200];
|
2008-07-30 07:04:32 +00:00
|
|
|
if (!_savegameFileName) {
|
2004-11-01 16:36:41 +00:00
|
|
|
strcpy(filename, "grim.sav");
|
|
|
|
} else {
|
|
|
|
strcpy(filename, _savegameFileName);
|
|
|
|
}
|
2005-12-26 02:36:00 +00:00
|
|
|
_savedState = new SaveGame(filename, false);
|
2008-08-02 21:03:23 +00:00
|
|
|
if (!_savedState)
|
|
|
|
return;
|
2004-12-30 22:38:53 +00:00
|
|
|
g_imuse->stopAllSounds();
|
2004-12-30 23:48:04 +00:00
|
|
|
g_imuse->resetState();
|
2004-11-01 16:36:41 +00:00
|
|
|
g_smush->stop();
|
2005-01-14 10:53:29 +00:00
|
|
|
g_imuse->pause(true);
|
|
|
|
g_smush->pause(true);
|
|
|
|
|
2004-11-01 16:36:41 +00:00
|
|
|
// free all resource
|
|
|
|
// lock resources
|
2005-01-12 13:48:29 +00:00
|
|
|
|
2011-03-21 05:16:27 +08:00
|
|
|
// killActors();
|
|
|
|
// killScenes();
|
|
|
|
// killPrimitiveObjects();
|
2011-03-24 20:00:57 +01:00
|
|
|
killTextObjects();
|
2011-03-21 05:16:27 +08:00
|
|
|
// killFonts();
|
|
|
|
|
|
|
|
_selectedActor = NULL;
|
|
|
|
_currScene = NULL;
|
|
|
|
|
|
|
|
restoreObjectStates(_savedState);
|
|
|
|
restoreScenes(_savedState);
|
|
|
|
restoreTextObjects(_savedState);
|
|
|
|
restorePrimitives(_savedState);
|
|
|
|
restoreActors(_savedState);
|
|
|
|
|
2011-04-24 15:41:40 +02:00
|
|
|
g_driver->restoreState(_savedState);
|
|
|
|
|
2005-12-26 02:36:00 +00:00
|
|
|
//Chore_Restore(_savedState);
|
|
|
|
//Resource_Restore(_savedState);
|
|
|
|
//Text_Restore(_savedState);
|
|
|
|
//Room_Restore(_savedState);
|
|
|
|
//Actor_Restore(_savedState);
|
|
|
|
//Render_Restore(_savedState);
|
|
|
|
//Primitive_Restore(_savedState);
|
|
|
|
//Smush_Restore(_savedState);
|
|
|
|
g_imuse->restoreState(_savedState);
|
2011-03-27 17:37:28 +02:00
|
|
|
g_smush->restoreState(_savedState);
|
2006-05-13 15:07:35 +00:00
|
|
|
_savedState->beginSection('LUAS');
|
2008-07-25 22:21:04 +00:00
|
|
|
lua_Restore(savegameReadStream, savegameReadSint32, savegameReadUint32);
|
2006-05-13 15:07:35 +00:00
|
|
|
_savedState->endSection();
|
2004-11-01 16:36:41 +00:00
|
|
|
// unlock resources
|
2005-12-26 02:36:00 +00:00
|
|
|
delete _savedState;
|
2011-04-29 18:57:00 +02:00
|
|
|
|
2011-04-29 19:04:47 +02:00
|
|
|
if (bundle_dofile("patch05.bin") == 2)
|
2011-04-29 18:57:00 +02:00
|
|
|
single_dofile("patch05.bin");
|
2004-11-01 17:34:48 +00:00
|
|
|
|
2005-01-14 10:53:29 +00:00
|
|
|
g_imuse->pause(false);
|
|
|
|
g_smush->pause(false);
|
2009-05-17 08:12:05 +00:00
|
|
|
printf("GrimEngine::savegameRestore() finished.\n");
|
2004-11-01 16:36:41 +00:00
|
|
|
}
|
|
|
|
|
2011-03-21 05:16:27 +08:00
|
|
|
void GrimEngine::restoreActors(SaveGame *state) {
|
|
|
|
state->beginSection('ACTR');
|
|
|
|
|
|
|
|
int32 size = state->readLEUint32();
|
|
|
|
for (int32 i = 0; i < size; ++i) {
|
|
|
|
int32 id = state->readLEUint32();
|
|
|
|
Actor *a = actor(id);
|
|
|
|
if (!a) {
|
|
|
|
a = new Actor();
|
|
|
|
a->_id = id;
|
|
|
|
registerActor(a);
|
|
|
|
if (id > Actor::s_id) {
|
|
|
|
Actor::s_id = id;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
a->restoreState(state);
|
|
|
|
}
|
|
|
|
|
|
|
|
int32 id = state->readLEUint32();
|
|
|
|
if (id != 0) {
|
|
|
|
_selectedActor = _actors[id];
|
|
|
|
}
|
|
|
|
|
|
|
|
state->endSection();
|
|
|
|
}
|
|
|
|
|
|
|
|
void GrimEngine::restoreTextObjects(SaveGame *state) {
|
|
|
|
state->beginSection('TEXT');
|
|
|
|
|
2011-04-12 20:41:22 +08:00
|
|
|
_sayLineDefaults.disabled = state->readLESint32();
|
|
|
|
_sayLineDefaults.fgColor.red() = state->readByte();
|
|
|
|
_sayLineDefaults.fgColor.green() = state->readByte();
|
|
|
|
_sayLineDefaults.fgColor.blue() = state->readByte();
|
|
|
|
_sayLineDefaults.font = g_resourceloader->getFont(state->readString().c_str());
|
|
|
|
_sayLineDefaults.height = state->readLESint32();
|
|
|
|
_sayLineDefaults.justify = state->readLESint32();
|
|
|
|
_sayLineDefaults.width = state->readLESint32();
|
|
|
|
_sayLineDefaults.x = state->readLESint32();
|
|
|
|
_sayLineDefaults.y = state->readLESint32();
|
2011-03-21 05:16:27 +08:00
|
|
|
|
|
|
|
int32 size = state->readLESint32();
|
|
|
|
for (int32 i = 0; i < size; ++i) {
|
|
|
|
int32 id = state->readLEUint32();
|
|
|
|
TextObject *t = textObject(id);
|
|
|
|
if (!t) {
|
|
|
|
t = new TextObject();
|
|
|
|
t->_id = id;
|
|
|
|
registerTextObject(t);
|
|
|
|
if (id > TextObject::s_id) {
|
|
|
|
TextObject::s_id = id;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
t->restoreState(state);
|
|
|
|
}
|
|
|
|
|
|
|
|
state->endSection();
|
|
|
|
}
|
|
|
|
|
|
|
|
void GrimEngine::restoreScenes(SaveGame *state) {
|
|
|
|
state->beginSection('SET ');
|
|
|
|
|
|
|
|
int32 size = state->readLESint32();
|
|
|
|
for (int32 i = 0; i < size; ++i) {
|
|
|
|
int32 id = state->readLEUint32();
|
2011-03-25 07:29:35 +08:00
|
|
|
Scene *s = _scenes[id];
|
2011-03-21 05:16:27 +08:00
|
|
|
if (!s) {
|
|
|
|
s = new Scene();
|
|
|
|
s->_id = id;
|
|
|
|
registerScene(s);
|
|
|
|
if (id > Scene::s_id) {
|
|
|
|
Scene::s_id = id;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
s->restoreState(state);
|
|
|
|
}
|
|
|
|
|
2011-03-25 07:29:35 +08:00
|
|
|
_currScene = _scenes[state->readLEUint32()];
|
2011-03-21 05:16:27 +08:00
|
|
|
|
|
|
|
state->endSection();
|
|
|
|
}
|
|
|
|
|
|
|
|
void GrimEngine::restorePrimitives(SaveGame *state) {
|
|
|
|
state->beginSection('PRIM');
|
|
|
|
|
|
|
|
int32 size = state->readLESint32();
|
|
|
|
for (int32 i = 0; i < size; ++i) {
|
|
|
|
int32 id = state->readLEUint32();
|
|
|
|
PrimitiveObject *p = primitiveObject(id);
|
|
|
|
if (!p) {
|
|
|
|
p = new PrimitiveObject();
|
|
|
|
p->_id = id;
|
|
|
|
registerPrimitiveObject(p);
|
|
|
|
if (id > PrimitiveObject::s_id) {
|
|
|
|
PrimitiveObject::s_id = id;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
p->restoreState(state);
|
|
|
|
}
|
|
|
|
|
|
|
|
state->endSection();
|
|
|
|
}
|
|
|
|
|
|
|
|
void GrimEngine::restoreObjectStates(SaveGame *state) {
|
|
|
|
state->beginSection('STAT');
|
|
|
|
|
|
|
|
int32 size = state->readLESint32();
|
|
|
|
for (int32 i = 0; i < size; ++i) {
|
|
|
|
int32 id = state->readLEUint32();
|
|
|
|
ObjectState *o = objectState(id);
|
|
|
|
if (!o) {
|
|
|
|
o = new ObjectState();
|
|
|
|
o->_id = id;
|
|
|
|
registerObjectState(o);
|
|
|
|
if (id > ObjectState::s_id) {
|
|
|
|
ObjectState::s_id = id;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
o->restoreState(state);
|
|
|
|
}
|
|
|
|
|
|
|
|
state->endSection();
|
|
|
|
}
|
|
|
|
|
2009-10-17 12:48:23 +00:00
|
|
|
void GrimEngine::storeSaveGameImage(SaveGame *state) {
|
2006-05-14 07:51:41 +00:00
|
|
|
int width = 250, height = 188;
|
|
|
|
Bitmap *screenshot;
|
|
|
|
|
2009-05-17 08:12:05 +00:00
|
|
|
printf("GrimEngine::StoreSaveGameImage() started.\n");
|
2006-05-14 07:51:41 +00:00
|
|
|
|
2009-05-17 08:24:17 +00:00
|
|
|
int mode = g_grim->getMode();
|
|
|
|
g_grim->setMode(ENGINE_MODE_NORMAL);
|
|
|
|
g_grim->updateDisplayScene();
|
2006-05-14 07:51:41 +00:00
|
|
|
screenshot = g_driver->getScreenshot(width, height);
|
2009-05-17 08:24:17 +00:00
|
|
|
g_grim->setMode(mode);
|
2009-10-17 12:48:23 +00:00
|
|
|
state->beginSection('SIMG');
|
2006-05-14 07:51:41 +00:00
|
|
|
if (screenshot) {
|
|
|
|
int size = screenshot->width() * screenshot->height() * sizeof(uint16);
|
|
|
|
screenshot->setNumber(0);
|
|
|
|
char *data = screenshot->getData();
|
2009-10-17 12:48:23 +00:00
|
|
|
state->write(data, size);
|
2006-05-14 07:51:41 +00:00
|
|
|
} else {
|
2009-05-31 07:33:18 +00:00
|
|
|
error("Unable to store screenshot");
|
2006-05-14 07:51:41 +00:00
|
|
|
}
|
2009-10-17 12:48:23 +00:00
|
|
|
state->endSection();
|
2009-06-26 16:13:11 +00:00
|
|
|
g_grim->killBitmap(screenshot);
|
2009-05-17 08:12:05 +00:00
|
|
|
printf("GrimEngine::StoreSaveGameImage() finished.\n");
|
2006-05-14 07:51:41 +00:00
|
|
|
}
|
|
|
|
|
2009-05-17 08:12:05 +00:00
|
|
|
void GrimEngine::savegameSave() {
|
|
|
|
printf("GrimEngine::savegameSave() started.\n");
|
2004-11-01 16:36:41 +00:00
|
|
|
_savegameSaveRequest = false;
|
|
|
|
char filename[200];
|
2008-07-30 07:04:32 +00:00
|
|
|
if (!_savegameFileName) {
|
2004-11-01 16:36:41 +00:00
|
|
|
strcpy(filename, "grim.sav");
|
|
|
|
} else {
|
|
|
|
strcpy(filename, _savegameFileName);
|
|
|
|
}
|
2005-12-26 02:36:00 +00:00
|
|
|
_savedState = new SaveGame(filename, true);
|
2008-08-02 21:03:23 +00:00
|
|
|
if (!_savedState)
|
|
|
|
return;
|
2004-11-01 16:36:41 +00:00
|
|
|
|
2006-05-14 07:51:41 +00:00
|
|
|
storeSaveGameImage(_savedState);
|
|
|
|
|
2005-01-14 10:51:20 +00:00
|
|
|
g_imuse->pause(true);
|
|
|
|
g_smush->pause(true);
|
|
|
|
|
2005-01-12 23:28:47 +00:00
|
|
|
savegameCallback();
|
|
|
|
|
2011-03-21 05:16:27 +08:00
|
|
|
saveObjectStates(_savedState);
|
|
|
|
saveScenes(_savedState);
|
2009-06-23 05:18:00 +00:00
|
|
|
saveTextObjects(_savedState);
|
2009-06-23 07:14:53 +00:00
|
|
|
savePrimitives(_savedState);
|
2009-06-22 14:11:40 +00:00
|
|
|
saveActors(_savedState);
|
|
|
|
|
2011-04-24 15:41:40 +02:00
|
|
|
g_driver->saveState(_savedState);
|
|
|
|
|
2005-12-26 02:36:00 +00:00
|
|
|
//Chore_Save(_savedState);
|
|
|
|
//Resource_Save(_savedState);
|
|
|
|
//Text_Save(_savedState);
|
|
|
|
//Room_Save(_savedState);
|
|
|
|
//Actor_Save(_savedState);
|
|
|
|
//Render_Save(_savedState);
|
|
|
|
//Primitive_Save(_savedState);
|
|
|
|
//Smush_Save(_savedState);
|
|
|
|
g_imuse->saveState(_savedState);
|
2011-03-27 17:37:28 +02:00
|
|
|
g_smush->saveState(_savedState);
|
2006-05-13 15:07:35 +00:00
|
|
|
_savedState->beginSection('LUAS');
|
2008-07-25 22:21:04 +00:00
|
|
|
lua_Save(savegameWriteStream, savegameWriteSint32, savegameWriteUint32);
|
2006-05-13 15:07:35 +00:00
|
|
|
_savedState->endSection();
|
2005-12-26 02:36:00 +00:00
|
|
|
|
|
|
|
delete _savedState;
|
2005-01-14 10:51:20 +00:00
|
|
|
|
|
|
|
g_imuse->pause(false);
|
|
|
|
g_smush->pause(false);
|
2009-05-17 08:12:05 +00:00
|
|
|
printf("GrimEngine::savegameSave() finished.\n");
|
2004-11-01 16:36:41 +00:00
|
|
|
}
|
|
|
|
|
2009-10-17 12:48:23 +00:00
|
|
|
void GrimEngine::saveActors(SaveGame *state) {
|
|
|
|
state->beginSection('ACTR');
|
2009-06-22 14:11:40 +00:00
|
|
|
|
2011-03-21 05:16:27 +08:00
|
|
|
state->writeLEUint32(_actors.size());
|
2010-02-04 19:43:50 +00:00
|
|
|
for (ActorListType::iterator i = _actors.begin(); i != _actors.end(); ++i) {
|
2011-03-21 05:16:27 +08:00
|
|
|
Actor *a = i->_value;
|
|
|
|
state->writeLEUint32(actorId(a));
|
2011-03-27 22:26:14 +02:00
|
|
|
|
2009-10-17 12:48:23 +00:00
|
|
|
a->saveState(state);
|
2009-06-22 14:11:40 +00:00
|
|
|
}
|
|
|
|
|
2011-03-21 05:16:27 +08:00
|
|
|
if (_selectedActor) {
|
|
|
|
state->writeLEUint32(actorId(_selectedActor));
|
|
|
|
} else {
|
|
|
|
state->writeLEUint32(0);
|
2009-06-22 21:20:12 +00:00
|
|
|
}
|
|
|
|
|
2009-10-17 12:48:23 +00:00
|
|
|
state->endSection();
|
2009-06-22 21:20:12 +00:00
|
|
|
}
|
|
|
|
|
2009-10-17 12:48:23 +00:00
|
|
|
void GrimEngine::saveTextObjects(SaveGame *state) {
|
|
|
|
state->beginSection('TEXT');
|
2009-06-23 05:15:20 +00:00
|
|
|
|
2011-04-12 20:41:22 +08:00
|
|
|
state->writeLESint32(_sayLineDefaults.disabled);
|
|
|
|
state->writeByte(_sayLineDefaults.fgColor.red());
|
|
|
|
state->writeByte(_sayLineDefaults.fgColor.green());
|
|
|
|
state->writeByte(_sayLineDefaults.fgColor.blue());
|
|
|
|
state->writeString(_sayLineDefaults.font->getFilename());
|
|
|
|
state->writeLESint32(_sayLineDefaults.height);
|
|
|
|
state->writeLESint32(_sayLineDefaults.justify);
|
|
|
|
state->writeLESint32(_sayLineDefaults.width);
|
|
|
|
state->writeLESint32(_sayLineDefaults.x);
|
|
|
|
state->writeLESint32(_sayLineDefaults.y);
|
2009-10-17 12:48:23 +00:00
|
|
|
|
|
|
|
state->writeLESint32(_textObjects.size());
|
2010-02-04 19:43:50 +00:00
|
|
|
for (TextListType::iterator i = _textObjects.begin(); i != _textObjects.end(); ++i) {
|
2011-03-21 05:16:27 +08:00
|
|
|
TextObject *t = i->_value;
|
|
|
|
state->writeLEUint32(i->_key);
|
2009-10-17 12:48:23 +00:00
|
|
|
t->saveState(state);
|
2009-06-23 05:15:20 +00:00
|
|
|
}
|
|
|
|
|
2009-10-17 12:48:23 +00:00
|
|
|
state->endSection();
|
2009-06-23 05:15:20 +00:00
|
|
|
}
|
|
|
|
|
2009-10-17 12:48:23 +00:00
|
|
|
void GrimEngine::saveScenes(SaveGame *state) {
|
|
|
|
state->beginSection('SET ');
|
2009-06-24 17:30:34 +00:00
|
|
|
|
2009-10-17 12:48:23 +00:00
|
|
|
state->writeLESint32(_scenes.size());
|
2010-02-04 19:43:50 +00:00
|
|
|
for (SceneListType::iterator i = _scenes.begin(); i != _scenes.end(); ++i) {
|
2011-03-21 05:16:27 +08:00
|
|
|
Scene *s = i->_value;
|
|
|
|
state->writeLEUint32(s->_id);
|
2009-10-17 12:48:23 +00:00
|
|
|
s->saveState(state);
|
2009-06-24 17:30:34 +00:00
|
|
|
}
|
|
|
|
|
2011-03-21 05:16:27 +08:00
|
|
|
state->writeLEUint32(_currScene->_id);
|
|
|
|
|
2009-10-17 12:48:23 +00:00
|
|
|
state->endSection();
|
2009-06-24 17:30:34 +00:00
|
|
|
}
|
|
|
|
|
2009-10-17 12:48:23 +00:00
|
|
|
void GrimEngine::savePrimitives(SaveGame *state) {
|
|
|
|
state->beginSection('PRIM');
|
2009-06-23 07:14:53 +00:00
|
|
|
|
2009-10-17 12:48:23 +00:00
|
|
|
state->writeLESint32(_primitiveObjects.size());
|
2010-02-04 19:43:50 +00:00
|
|
|
for (PrimitiveListType::iterator i = _primitiveObjects.begin(); i != _primitiveObjects.end(); ++i) {
|
2011-03-21 05:16:27 +08:00
|
|
|
PrimitiveObject *p = i->_value;
|
|
|
|
state->writeLEUint32(p->_id);
|
2009-10-17 12:48:23 +00:00
|
|
|
p->saveState(state);
|
2009-06-23 07:14:53 +00:00
|
|
|
}
|
|
|
|
|
2009-10-17 12:48:23 +00:00
|
|
|
state->endSection();
|
2009-06-23 07:14:53 +00:00
|
|
|
}
|
|
|
|
|
2011-03-21 05:16:27 +08:00
|
|
|
void GrimEngine::saveObjectStates(SaveGame *state) {
|
|
|
|
state->beginSection('STAT');
|
|
|
|
|
|
|
|
state->writeLESint32(_objectStates.size());
|
|
|
|
for (Common::HashMap<int, ObjectState *>::iterator i = _objectStates.begin(); i != _objectStates.end(); ++i) {
|
|
|
|
ObjectState *o = i->_value;
|
|
|
|
state->writeLEUint32(o->_id);
|
|
|
|
o->saveState(state);
|
|
|
|
}
|
|
|
|
|
|
|
|
state->endSection();
|
|
|
|
}
|
|
|
|
|
2009-05-17 08:12:05 +00:00
|
|
|
void GrimEngine::savegameCallback() {
|
2005-01-14 10:53:29 +00:00
|
|
|
lua_Object funcParam1;
|
|
|
|
|
|
|
|
lua_beginblock();
|
2009-05-31 16:09:21 +00:00
|
|
|
|
|
|
|
lua_pushobject(lua_getref(refSystemTable));
|
2005-01-14 10:53:29 +00:00
|
|
|
lua_pushstring("saveGameCallback");
|
2009-05-31 16:09:21 +00:00
|
|
|
lua_Object funcParam2 = lua_gettable();
|
2005-01-14 10:53:29 +00:00
|
|
|
|
|
|
|
if (lua_istable(funcParam2)) {
|
|
|
|
lua_pushobject(funcParam2);
|
|
|
|
lua_pushstring("saveGameCallback");
|
|
|
|
funcParam1 = lua_gettable();
|
|
|
|
if (lua_isfunction(funcParam1)) {
|
2009-05-31 16:09:21 +00:00
|
|
|
lua_pushobject(funcParam2);
|
|
|
|
lua_callfunction(funcParam1);
|
2005-01-14 10:53:29 +00:00
|
|
|
} else {
|
2009-05-31 16:09:21 +00:00
|
|
|
error("GrimEngine::savegameCallback: handler is not a function");
|
2005-01-14 10:53:29 +00:00
|
|
|
}
|
|
|
|
} else if (lua_isfunction(funcParam2)) {
|
|
|
|
funcParam1 = funcParam2;
|
|
|
|
lua_callfunction(funcParam1);
|
2009-05-31 16:09:21 +00:00
|
|
|
} else if (!lua_isnil(funcParam2)) {
|
|
|
|
error("GrimEngine::savegameCallback: invalid handler");
|
2005-01-14 10:53:29 +00:00
|
|
|
}
|
|
|
|
lua_endblock();
|
|
|
|
}
|
|
|
|
|
2009-05-17 08:12:05 +00:00
|
|
|
Scene *GrimEngine::findScene(const char *name) {
|
2005-07-10 18:57:27 +00:00
|
|
|
// Find scene object
|
2010-02-04 19:43:50 +00:00
|
|
|
for (SceneListType::const_iterator i = scenesBegin(); i != scenesEnd(); ++i) {
|
2011-03-21 05:16:27 +08:00
|
|
|
if (!strcmp(i->_value->name(), name))
|
|
|
|
return i->_value;
|
2005-07-10 18:57:27 +00:00
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2009-05-17 08:12:05 +00:00
|
|
|
void GrimEngine::setSceneLock(const char *name, bool lockStatus) {
|
2005-07-10 18:57:27 +00:00
|
|
|
Scene *scene = findScene(name);
|
2009-05-09 17:47:28 +00:00
|
|
|
|
2008-07-30 07:04:32 +00:00
|
|
|
if (!scene) {
|
2009-05-25 19:21:58 +00:00
|
|
|
if (gDebugLevel == DEBUG_WARN || gDebugLevel == DEBUG_ALL)
|
2009-05-31 07:33:18 +00:00
|
|
|
warning("Scene object '%s' not found in list", name);
|
2005-07-10 18:57:27 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
// Change the locking status
|
2005-08-10 08:33:45 +00:00
|
|
|
scene->_locked = lockStatus;
|
2005-07-10 18:57:27 +00:00
|
|
|
}
|
|
|
|
|
2009-05-17 08:12:05 +00:00
|
|
|
void GrimEngine::setScene(const char *name) {
|
2005-07-10 18:57:27 +00:00
|
|
|
Scene *scene = findScene(name);
|
2005-07-17 23:40:22 +00:00
|
|
|
Scene *lastScene = _currScene;
|
2009-05-09 17:47:28 +00:00
|
|
|
|
2005-07-10 18:57:27 +00:00
|
|
|
// If the scene already exists then use the existing data
|
2008-07-30 07:04:32 +00:00
|
|
|
if (scene) {
|
2005-07-10 18:57:27 +00:00
|
|
|
setScene(scene);
|
|
|
|
return;
|
|
|
|
}
|
2004-12-31 21:35:04 +00:00
|
|
|
Block *b = g_resourceloader->getFileBlock(name);
|
2008-07-30 07:04:32 +00:00
|
|
|
if (!b)
|
2008-09-28 15:23:15 +00:00
|
|
|
warning("Could not find scene file %s", name);
|
2004-12-09 23:55:43 +00:00
|
|
|
_currScene = new Scene(name, b->data(), b->len());
|
2005-07-10 18:57:27 +00:00
|
|
|
registerScene(_currScene);
|
2005-01-05 18:28:50 +00:00
|
|
|
_currScene->setSoundParameters(20, 127);
|
2005-07-17 23:40:22 +00:00
|
|
|
// should delete the old scene after creating the new one
|
2008-07-30 07:04:32 +00:00
|
|
|
if (lastScene && !lastScene->_locked) {
|
2005-07-17 23:40:22 +00:00
|
|
|
removeScene(lastScene);
|
|
|
|
delete lastScene;
|
|
|
|
}
|
2004-02-24 21:09:53 +00:00
|
|
|
delete b;
|
2003-08-15 18:00:22 +00:00
|
|
|
}
|
2005-07-10 18:57:27 +00:00
|
|
|
|
2009-05-17 08:12:05 +00:00
|
|
|
void GrimEngine::setScene(Scene *scene) {
|
2005-07-17 23:40:22 +00:00
|
|
|
Scene *lastScene = _currScene;
|
2005-07-10 18:57:27 +00:00
|
|
|
_currScene = scene;
|
|
|
|
_currScene->setSoundParameters(20, 127);
|
2005-07-17 23:40:22 +00:00
|
|
|
// should delete the old scene after setting the new one
|
2008-07-30 07:04:32 +00:00
|
|
|
if (lastScene && !lastScene->_locked) {
|
2005-07-17 23:40:22 +00:00
|
|
|
removeScene(lastScene);
|
|
|
|
delete lastScene;
|
|
|
|
}
|
2005-07-10 18:57:27 +00:00
|
|
|
}
|
|
|
|
|
2009-06-08 22:25:14 +00:00
|
|
|
void GrimEngine::makeCurrentSetup(int num) {
|
|
|
|
int prevSetup = g_grim->currScene()->setup();
|
2009-06-09 15:34:59 +00:00
|
|
|
if (prevSetup != num) {
|
|
|
|
currScene()->setSetup(num);
|
|
|
|
currScene()->setSoundParameters(20, 127);
|
|
|
|
cameraChangeHandle(prevSetup, num);
|
|
|
|
// here should be set sound position
|
|
|
|
}
|
2009-06-08 22:25:14 +00:00
|
|
|
}
|
|
|
|
|
2009-05-17 08:12:05 +00:00
|
|
|
void GrimEngine::setTextSpeed(int speed) {
|
2005-04-08 11:47:47 +00:00
|
|
|
if (speed < 1)
|
|
|
|
_textSpeed = 1;
|
|
|
|
if (speed > 10)
|
|
|
|
_textSpeed = 10;
|
|
|
|
_textSpeed = speed;
|
|
|
|
}
|
2008-08-17 12:01:26 +00:00
|
|
|
|
2009-05-17 08:12:05 +00:00
|
|
|
float GrimEngine::getControlAxis(int num) {
|
2008-08-17 12:01:26 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2009-05-17 08:12:05 +00:00
|
|
|
bool GrimEngine::getControlState(int num) {
|
2008-08-17 12:01:26 +00:00
|
|
|
return _controlsState[num];
|
|
|
|
}
|
2009-05-25 06:49:57 +00:00
|
|
|
|
2011-04-26 21:55:55 +02:00
|
|
|
float GrimEngine::perSecond(float rate) const {
|
|
|
|
return rate * _frameTime / 1000;
|
|
|
|
}
|
|
|
|
|
2011-03-21 05:16:27 +08:00
|
|
|
void GrimEngine::registerTextObject(TextObject *t) {
|
|
|
|
_textObjects[t->_id] = t;
|
|
|
|
}
|
|
|
|
|
|
|
|
void GrimEngine::killTextObject(TextObject *t) {
|
|
|
|
_textObjects.erase(t->_id);
|
|
|
|
delete t;
|
|
|
|
}
|
|
|
|
|
|
|
|
void GrimEngine::killTextObjects() {
|
|
|
|
while (!_textObjects.empty()) {
|
|
|
|
killTextObject(_textObjects.begin()->_value);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
int GrimEngine::textObjectId(TextObject *t) const {
|
|
|
|
return t->_id;
|
|
|
|
}
|
|
|
|
|
|
|
|
TextObject *GrimEngine::textObject(int id) const {
|
|
|
|
return _textObjects[id];
|
|
|
|
}
|
|
|
|
|
|
|
|
void GrimEngine::registerActor(Actor *a) {
|
|
|
|
_actors[a->_id] = a;
|
|
|
|
}
|
|
|
|
|
|
|
|
void GrimEngine::killActor(Actor *a) {
|
|
|
|
_actors.erase(a->_id);
|
|
|
|
}
|
|
|
|
|
|
|
|
void GrimEngine::killActors() {
|
|
|
|
// _actors.clear();
|
|
|
|
// while (!_actors.empty()) {
|
|
|
|
// delete _actors.back();
|
|
|
|
// _actors.pop_back();
|
|
|
|
// }
|
|
|
|
}
|
|
|
|
|
|
|
|
int GrimEngine::actorId(Actor *a) const {
|
|
|
|
return a->_id;
|
|
|
|
}
|
|
|
|
|
|
|
|
Actor *GrimEngine::actor(int id) const {
|
|
|
|
if (_actors.contains(id)) {
|
|
|
|
return _actors[id];
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
void GrimEngine::registerObjectState(ObjectState *o) {
|
|
|
|
_objectStates[o->_id] = o;
|
|
|
|
}
|
|
|
|
|
|
|
|
void GrimEngine::killObjectState(ObjectState *o) {
|
|
|
|
_objectStates.erase(o->_id);
|
|
|
|
}
|
|
|
|
|
|
|
|
void GrimEngine::killObjectStates() {
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
int GrimEngine::objectStateId(ObjectState *o) const {
|
|
|
|
return o->_id;
|
|
|
|
}
|
|
|
|
|
|
|
|
ObjectState *GrimEngine::objectState(int id) const {
|
|
|
|
return _objectStates[id];
|
|
|
|
}
|
|
|
|
|
|
|
|
void GrimEngine::registerPrimitiveObject(PrimitiveObject *p) {
|
|
|
|
_primitiveObjects[p->_id] = p;
|
|
|
|
}
|
|
|
|
|
|
|
|
void GrimEngine::killPrimitiveObject(PrimitiveObject *p) {
|
|
|
|
_primitiveObjects.erase(p->_id);
|
|
|
|
}
|
|
|
|
|
|
|
|
void GrimEngine::killPrimitiveObjects() {
|
|
|
|
while (!_primitiveObjects.empty()) {
|
|
|
|
PrimitiveObject *p = _primitiveObjects.begin()->_value;
|
|
|
|
killPrimitiveObject(p);
|
|
|
|
delete p;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
int GrimEngine::primitiveObjectId(PrimitiveObject *p) const {
|
|
|
|
return p->_id;
|
|
|
|
}
|
|
|
|
|
|
|
|
PrimitiveObject *GrimEngine::primitiveObject(int id) const {
|
|
|
|
return _primitiveObjects[id];
|
|
|
|
}
|
|
|
|
|
|
|
|
void GrimEngine::registerScene(Scene *s) {
|
|
|
|
_scenes[s->_id] = s;
|
|
|
|
}
|
|
|
|
|
|
|
|
void GrimEngine::removeScene(Scene *s) {
|
|
|
|
_scenes.erase(s->_id);
|
|
|
|
}
|
|
|
|
|
|
|
|
void GrimEngine::killScenes() {
|
|
|
|
while (!_scenes.empty()) {
|
|
|
|
removeScene(_scenes.begin()->_value);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
int GrimEngine::sceneId(Scene *s) const {
|
|
|
|
return s->_id;
|
|
|
|
}
|
|
|
|
|
2009-05-25 06:49:57 +00:00
|
|
|
} // end of namespace Grim
|