svn-id: r15826
This commit is contained in:
Torbjörn Andersson 2004-11-16 09:15:25 +00:00
parent 525df7cff0
commit 7adc1f419f
7 changed files with 82 additions and 118 deletions

View file

@ -104,12 +104,14 @@ void Debugger::buildDebugText(void) {
makeDebugTextBlock(buf, 0, 105); makeDebugTextBlock(buf, 0, 105);
} }
#ifdef SWORD2_DEBUG
// speed-up indicator // speed-up indicator
if (_vm->_renderSkip) { // see sword.cpp if (_vm->_renderSkip) { // see sword2.cpp
sprintf(buf, "SKIPPING FRAMES FOR SPEED-UP!"); sprintf(buf, "SKIPPING FRAMES FOR SPEED-UP!");
makeDebugTextBlock(buf, 0, 120); makeDebugTextBlock(buf, 0, 120);
} }
#endif
// debug info at top of screen - enabled/disabled as one complete unit // debug info at top of screen - enabled/disabled as one complete unit

View file

@ -211,7 +211,7 @@ int32 Logic::fnSetValue(int32 *params) {
return IR_CONT; return IR_CONT;
} }
#ifdef _SWORD2_DEBUG #ifdef SWORD2_DEBUG
#define BLACK 0 #define BLACK 0
#define WHITE 1 #define WHITE 1
#define RED 2 #define RED 2
@ -232,7 +232,7 @@ int32 Logic::fnFlash(int32 *params) {
// params: 0 colour to flash // params: 0 colour to flash
#ifdef _SWORD2_DEBUG #ifdef SWORD2_DEBUG
// what colour? // what colour?
switch (params[0]) { switch (params[0]) {
case WHITE: case WHITE:
@ -268,7 +268,7 @@ int32 Logic::fnColour(int32 *params) {
// params 0: colour (see defines above) // params 0: colour (see defines above)
#ifdef _SWORD2_DEBUG #ifdef SWORD2_DEBUG
// what colour? // what colour?
switch (params[0]) { switch (params[0]) {
case BLACK: case BLACK:

View file

@ -335,7 +335,7 @@ int32 Logic::fnAddToKillList(int32 *params) {
// params: none // params: none
// DON'T EVER KILL GEORGE! // DON'T EVER KILL GEORGE!
if (_scriptVars[ID] == 8) if (_scriptVars[ID] == CUR_PLAYER_ID)
return IR_CONT; return IR_CONT;
// Scan the list to see if it's already included // Scan the list to see if it's already included

View file

@ -75,7 +75,7 @@ ScreenHeader *Sword2Engine::fetchScreenHeader(byte *screenFile) {
*/ */
LayerHeader *Sword2Engine::fetchLayerHeader(byte *screenFile, uint16 layerNo) { LayerHeader *Sword2Engine::fetchLayerHeader(byte *screenFile, uint16 layerNo) {
#ifdef _SWORD2_DEBUG #ifdef SWORD2_DEBUG
ScreenHeader *screenHead = fetchScreenHeader(screenFile); ScreenHeader *screenHead = fetchScreenHeader(screenFile);
if (layerNo > screenHead->noLayers - 1) if (layerNo > screenHead->noLayers - 1)
@ -118,7 +118,7 @@ AnimHeader *Sword2Engine::fetchAnimHeader(byte *animFile) {
CdtEntry *Sword2Engine::fetchCdtEntry(byte *animFile, uint16 frameNo) { CdtEntry *Sword2Engine::fetchCdtEntry(byte *animFile, uint16 frameNo) {
AnimHeader *animHead = fetchAnimHeader(animFile); AnimHeader *animHead = fetchAnimHeader(animFile);
#ifdef _SWORD2_DEBUG #ifdef SWORD2_DEBUG
if (frameNo > animHead->noAnimFrames - 1) if (frameNo > animHead->noAnimFrames - 1)
error("fetchCdtEntry(animFile,%d) - anim only %d frames", frameNo, animHead->noAnimFrames); error("fetchCdtEntry(animFile,%d) - anim only %d frames", frameNo, animHead->noAnimFrames);
#endif #endif
@ -144,7 +144,7 @@ FrameHeader *Sword2Engine::fetchFrameHeader(byte *animFile, uint16 frameNo) {
Parallax *Sword2Engine::fetchBackgroundParallaxLayer(byte *screenFile, int layer) { Parallax *Sword2Engine::fetchBackgroundParallaxLayer(byte *screenFile, int layer) {
MultiScreenHeader *mscreenHeader = (MultiScreenHeader *) (screenFile + sizeof(StandardHeader)); MultiScreenHeader *mscreenHeader = (MultiScreenHeader *) (screenFile + sizeof(StandardHeader));
#ifdef _SWORD2_DEBUG #ifdef SWORD2_DEBUG
if (mscreenHeader->bg_parallax[layer] == 0) if (mscreenHeader->bg_parallax[layer] == 0)
error("fetchBackgroundParallaxLayer(%d) - No parallax layer exists", layer); error("fetchBackgroundParallaxLayer(%d) - No parallax layer exists", layer);
#endif #endif
@ -155,7 +155,7 @@ Parallax *Sword2Engine::fetchBackgroundParallaxLayer(byte *screenFile, int layer
Parallax *Sword2Engine::fetchBackgroundLayer(byte *screenFile) { Parallax *Sword2Engine::fetchBackgroundLayer(byte *screenFile) {
MultiScreenHeader *mscreenHeader = (MultiScreenHeader *) (screenFile + sizeof(StandardHeader)); MultiScreenHeader *mscreenHeader = (MultiScreenHeader *) (screenFile + sizeof(StandardHeader));
#ifdef _SWORD2_DEBUG #ifdef SWORD2_DEBUG
if (mscreenHeader->screen == 0) if (mscreenHeader->screen == 0)
error("fetchBackgroundLayer (%d) - No background layer exists"); error("fetchBackgroundLayer (%d) - No background layer exists");
#endif #endif
@ -166,7 +166,7 @@ Parallax *Sword2Engine::fetchBackgroundLayer(byte *screenFile) {
Parallax *Sword2Engine::fetchForegroundParallaxLayer(byte *screenFile, int layer) { Parallax *Sword2Engine::fetchForegroundParallaxLayer(byte *screenFile, int layer) {
MultiScreenHeader *mscreenHeader = (MultiScreenHeader *) (screenFile + sizeof(StandardHeader)); MultiScreenHeader *mscreenHeader = (MultiScreenHeader *) (screenFile + sizeof(StandardHeader));
#ifdef _SWORD2_DEBUG #ifdef SWORD2_DEBUG
if (mscreenHeader->fg_parallax[layer] == 0) if (mscreenHeader->fg_parallax[layer] == 0)
error("fetchForegroundParallaxLayer(%d) - No parallax layer exists", layer); error("fetchForegroundParallaxLayer(%d) - No parallax layer exists", layer);
#endif #endif

View file

@ -1150,7 +1150,7 @@ void Router::slidyWalkAnimator(WalkData *walkAnim) {
} }
} while (_modularPath[p].dir < NO_DIRECTIONS); } while (_modularPath[p].dir < NO_DIRECTIONS);
#ifdef _SWORD2_DEBUG #ifdef SWORD2_DEBUG
if (lastRealDir == 99) if (lastRealDir == 99)
error("slidyWalkAnimatorlast direction error"); error("slidyWalkAnimatorlast direction error");
#endif #endif

View file

@ -100,8 +100,6 @@ REGISTER_PLUGIN("Broken Sword II", Engine_SWORD2_gameList, Engine_SWORD2_create,
namespace Sword2 { namespace Sword2 {
Sword2Engine *g_sword2 = NULL;
Sword2Engine::Sword2Engine(GameDetector *detector, OSystem *syst) : Engine(syst) { Sword2Engine::Sword2Engine(GameDetector *detector, OSystem *syst) : Engine(syst) {
// Add default file directories // Add default file directories
File::addDefaultDirectory(_gameDataPath + "CLUSTERS/"); File::addDefaultDirectory(_gameDataPath + "CLUSTERS/");
@ -111,20 +109,24 @@ Sword2Engine::Sword2Engine(GameDetector *detector, OSystem *syst) : Engine(syst)
File::addDefaultDirectory(_gameDataPath + "sword2/"); File::addDefaultDirectory(_gameDataPath + "sword2/");
File::addDefaultDirectory(_gameDataPath + "video/"); File::addDefaultDirectory(_gameDataPath + "video/");
g_sword2 = this;
_debugger = NULL;
_sound = NULL;
_graphics = NULL;
_features = detector->_game.features; _features = detector->_game.features;
_targetName = detector->_targetName; _targetName = detector->_targetName;
_bootParam = ConfMan.getInt("boot_param"); _bootParam = ConfMan.getInt("boot_param");
_saveSlot = ConfMan.getInt("save_slot"); _saveSlot = ConfMan.getInt("save_slot");
_debugger = NULL;
_graphics = NULL;
_sound = NULL;
_gui = NULL;
_fontRenderer = NULL;
_logic = NULL;
_resman = NULL;
_memory = NULL;
_keyboardEvent.pending = false; _keyboardEvent.pending = false;
_mouseEvent.pending = false; _mouseEvent.pending = false;
_mouseX = _mouseY = 0;
_lastPaletteRes = 0; _lastPaletteRes = 0;
_largestLayerArea = 0; _largestLayerArea = 0;
@ -149,6 +151,7 @@ Sword2Engine::Sword2Engine(GameDetector *detector, OSystem *syst) : Engine(syst)
memset(&_thisScreen, 0, sizeof(_thisScreen)); memset(&_thisScreen, 0, sizeof(_thisScreen));
memset(_mouseList, 0, sizeof(_mouseList)); memset(_mouseList, 0, sizeof(_mouseList));
_mouseX = _mouseY = 0;
_mouseTouching = 0; _mouseTouching = 0;
_oldMouseTouching = 0; _oldMouseTouching = 0;
_menuSelectedPos = 0; _menuSelectedPos = 0;
@ -164,26 +167,24 @@ Sword2Engine::Sword2Engine(GameDetector *detector, OSystem *syst) : Engine(syst)
_playerActivityDelay = 0; _playerActivityDelay = 0;
_realLuggageItem = 0; _realLuggageItem = 0;
// used to be a define, but now it's flexible
_scrollFraction = 16; _scrollFraction = 16;
_gamePaused = false; #ifdef SWORD2_DEBUG
_stepOneCycle = false; _stepOneCycle = false;
_renderSkip = false;
#endif
_gamePaused = false;
_graphicsLevelFudged = false; _graphicsLevelFudged = false;
_debugger = NULL; _gameCycle = 0;
_graphics = NULL;
_sound = NULL;
_gui = NULL;
_fontRenderer = NULL;
_logic = NULL;
_resman = NULL;
_memory = NULL;
_quit = false; _quit = false;
} }
Sword2Engine::~Sword2Engine() { Sword2Engine::~Sword2Engine() {
killMusic();
delete _debugger; delete _debugger;
delete _graphics; delete _graphics;
delete _sound; delete _sound;
@ -223,7 +224,7 @@ void Sword2Engine::setupPersistentResources() {
} }
void Sword2Engine::mainInit() { void Sword2Engine::mainInit() {
// get some falling RAM and put it in your pocket, never let it slip // Get some falling RAM and put it in your pocket, never let it slip
// away // away
_graphics = new Graphics(this, 640, 480); _graphics = new Graphics(this, 640, 480);
@ -255,26 +256,15 @@ void Sword2Engine::mainInit() {
// nor the scroll wheel. // nor the scroll wheel.
setEventFilter(RD_LEFTBUTTONUP | RD_RIGHTBUTTONUP | RD_WHEELUP | RD_WHEELDOWN); setEventFilter(RD_LEFTBUTTONUP | RD_RIGHTBUTTONUP | RD_WHEELUP | RD_WHEELDOWN);
// Initialise global script variables and player object
setupPersistentResources(); setupPersistentResources();
// Set up font resource variables for this language version
debug(5, "CALLING: initialiseFontResourceFlags");
initialiseFontResourceFlags(); initialiseFontResourceFlags();
// initialise the sound fx queue
debug(5, "CALLING: Init_fx_queue");
initFxQueue(); initFxQueue();
// all demos (not just web)
if (_features & GF_DEMO) if (_features & GF_DEMO)
Logic::_scriptVars[DEMO] = 1; Logic::_scriptVars[DEMO] = 1;
else else
Logic::_scriptVars[DEMO] = 0; Logic::_scriptVars[DEMO] = 0;
debug(5, "CALLING: readOptionSettings");
_gui->readOptionSettings(); _gui->readOptionSettings();
if (_saveSlot != -1) { if (_saveSlot != -1) {
@ -305,13 +295,7 @@ void Sword2Engine::mainInit() {
} else } else
startGame(); startGame();
debug(5, "CALLING: initialiseRenderCycle");
_graphics->initialiseRenderCycle(); _graphics->initialiseRenderCycle();
_renderSkip = false; // Toggled on 'S' key, to render only
// 1 in 4 frames, to speed up game
_gameCycle = 0;
} }
void Sword2Engine::mainRun() { void Sword2Engine::mainRun() {
@ -319,13 +303,7 @@ void Sword2Engine::mainRun() {
if (_debugger->isAttached()) if (_debugger->isAttached())
_debugger->onFrame(); _debugger->onFrame();
// the screen is build. Mostly because of first scroll #ifdef SWORD2_DEBUG
// cycle stuff
#ifdef _SWORD2_DEBUG
// if we've just stepped forward one cycle while the
// game was paused
if (_stepOneCycle) { if (_stepOneCycle) {
pauseGame(); pauseGame();
_stepOneCycle = false; _stepOneCycle = false;
@ -349,7 +327,7 @@ void Sword2Engine::mainRun() {
if (!Logic::_scriptVars[DEMO] && !_logic->_choosing) if (!Logic::_scriptVars[DEMO] && !_logic->_choosing)
_logic->fnPlayCredits(NULL); _logic->fnPlayCredits(NULL);
break; break;
#ifdef _SWORD2_DEBUG #ifdef SWORD2_DEBUG
case ' ': case ' ':
if (_gamePaused) { if (_gamePaused) {
_stepOneCycle = true; _stepOneCycle = true;
@ -372,7 +350,7 @@ void Sword2Engine::mainRun() {
gameCycle(); gameCycle();
} }
// We can't use this as termination condition for the looop, // We can't use this as termination condition for the loop,
// because we want the break to happen before updating the // because we want the break to happen before updating the
// screen again. // screen again.
@ -382,14 +360,13 @@ void Sword2Engine::mainRun() {
// creates the debug text blocks // creates the debug text blocks
_debugger->buildDebugText(); _debugger->buildDebugText();
#ifdef _SWORD2_DEBUG #ifdef SWORD2_DEBUG
// if not in console & '_renderSkip' is set, only render // if not in console & '_renderSkip' is set, only render
// display once every 4 game-cycles // display once every 4 game-cycles
if (console_status || !_renderSkip || (_gameCycle % 4) == 0) if (!_renderSkip || (_gameCycle % 4) == 0)
buildDisplay(); // create and flip the screen buildDisplay();
#else #else
// create and flip the screen
buildDisplay(); buildDisplay();
#endif #endif
} }
@ -398,9 +375,6 @@ void Sword2Engine::mainRun() {
void Sword2Engine::go() { void Sword2Engine::go() {
mainInit(); mainInit();
mainRun(); mainRun();
// Stop music instantly!
killMusic();
} }
void Sword2Engine::closeGame() { void Sword2Engine::closeGame() {
@ -503,29 +477,28 @@ void Sword2Engine::parseEvents() {
} }
void Sword2Engine::gameCycle() { void Sword2Engine::gameCycle() {
// do one game cycle // Do one game cycle, that is run the logic session until a full loop
// has been performed.
// got a screen to run?
if (_logic->getRunList()) { if (_logic->getRunList()) {
// run the logic session UNTIL a full loop has been performed
do { do {
// reset the graphic 'BuildUnit' list before a new // Reset the 'BuildUnit' and mouse hot-spot lists
// logic list (see fnRegisterFrame) // before each new logic list. The service scripts
resetRenderLists(); // will fill thrm through fnRegisterFrame() and
// fnRegisterMouse().
// reset the mouse hot-spot list (see fnRegisterMouse resetRenderLists();
// and fnRegisterFrame)
resetMouseList(); resetMouseList();
// keep going as long as new lists keep getting put in // Keep going as long as new lists keep getting put in
// - i.e. screen changes // - i.e. screen changes.
} while (_logic->processSession()); } while (_logic->processSession());
} else { } else {
// start the console and print the start options perhaps? // Start the console and print the start options perhaps?
_debugger->attach("AWAITING START COMMAND: (Enter 's 1' then 'q' to start from beginning)"); _debugger->attach("AWAITING START COMMAND: (Enter 's 1' then 'q' to start from beginning)");
} }
// if this screen is wide, recompute the scroll offsets every cycle // If this screen is wide, recompute the scroll offsets every cycle
if (_thisScreen.scroll_flag) if (_thisScreen.scroll_flag)
setScrolling(); setScrolling();
@ -534,48 +507,36 @@ void Sword2Engine::gameCycle() {
} }
void Sword2Engine::startGame() { void Sword2Engine::startGame() {
// boot the game straight into a start script // Boot the game straight into a start script. It's always George's
// script #1, but with different ScreenManager objects depending on
// if it's the demo or the full game, or if we're using a boot param.
int screen_manager_id; int screen_manager_id;
debug(5, "startGame() STARTING:"); debug(5, "startGame() STARTING:");
// all demos not just web if (!_bootParam) {
if (Logic::_scriptVars[DEMO]) if (Logic::_scriptVars[DEMO])
screen_manager_id = 19; // DOCKS SECTION START screen_manager_id = 19; // DOCKS SECTION START
else else
screen_manager_id = 949; // INTRO & PARIS START screen_manager_id = 949; // INTRO & PARIS START
} else {
// FIXME this could be validated against startup.inf for valid numbers // FIXME this could be validated against startup.inf for valid
// to stop people shooting themselves in the foot // numbers to stop people shooting themselves in the foot
if (_bootParam != 0) if (_bootParam != 0)
screen_manager_id = _bootParam; screen_manager_id = _bootParam;
}
char *raw_script;
char *raw_data_ad;
// the required start-scripts are both script #1 in the respective
// ScreenManager objects
uint32 null_pc = 1; uint32 null_pc = 1;
// open george object, ready for start script to reference char *raw_data_ad = (char *) _resman->openResource(CUR_PLAYER_ID);
raw_data_ad = (char *) _resman->openResource(CUR_PLAYER_ID); char *raw_script = (char *) _resman->openResource(screen_manager_id);
// open the ScreenManager object
raw_script = (char *) _resman->openResource(screen_manager_id);
// run the start script now (because no console)
_logic->runScript(raw_script, raw_data_ad, &null_pc); _logic->runScript(raw_script, raw_data_ad, &null_pc);
// close the ScreenManager object
_resman->closeResource(screen_manager_id); _resman->closeResource(screen_manager_id);
// close george
_resman->closeResource(CUR_PLAYER_ID); _resman->closeResource(CUR_PLAYER_ID);
debug(5, "startGame() DONE.");
} }
// FIXME: Move this to some better place? // FIXME: Move this to some better place?
@ -591,25 +552,21 @@ void Sword2Engine::sleepUntil(uint32 time) {
} }
void Sword2Engine::pauseGame() { void Sword2Engine::pauseGame() {
// don't allow Pause while screen fading or while black // Don't allow Pause while screen fading or while black
if (_graphics->getFadeStatus() != RDFADE_NONE) if (_graphics->getFadeStatus() != RDFADE_NONE)
return; return;
pauseAllSound(); pauseAllSound();
// make a normal mouse // Make the mouse cursor normal. This is the only place where we are
// allowed to clear the luggage this way.
clearPointerText(); clearPointerText();
// this is the only place allowed to do it this way
_graphics->setLuggageAnim(NULL, 0); _graphics->setLuggageAnim(NULL, 0);
// blank cursor
setMouse(0); setMouse(0);
// forces engine to choose a cursor
_mouseTouching = 1; _mouseTouching = 1;
// if level at max, turn down because palette-matching won't work // If level at max, turn down because palette-matching won't work
// when dimmed // when dimmed
if (_gui->_currentGraphicsLevel == 3) { if (_gui->_currentGraphicsLevel == 3) {
@ -617,11 +574,15 @@ void Sword2Engine::pauseGame() {
_graphicsLevelFudged = true; _graphicsLevelFudged = true;
} }
// don't dim it if we're single-stepping through frames #ifdef SWORD2_DEBUG
// Don't dim it if we're single-stepping through frames
// dim the palette during the pause // dim the palette during the pause
if (!_stepOneCycle) if (!_stepOneCycle)
_graphics->dimPalette(); _graphics->dimPalette();
#else
_graphics->dimPalette();
#endif
_gamePaused = true; _gamePaused = true;
} }
@ -632,7 +593,7 @@ void Sword2Engine::unpauseGame() {
unpauseAllSound(); unpauseAllSound();
// put back game screen palette; see build_display.cpp // Put back game screen palette; see build_display.cpp
setFullPalette(-1); setFullPalette(-1);
// If graphics level at max, turn up again // If graphics level at max, turn up again
@ -643,7 +604,7 @@ void Sword2Engine::unpauseGame() {
_gamePaused = false; _gamePaused = false;
// if mouse is about or we're in a chooser menu // If mouse is about or we're in a chooser menu
if (!_mouseStatus || _logic->_choosing) if (!_mouseStatus || _logic->_choosing)
setMouse(NORMAL_MOUSE_ID); setMouse(NORMAL_MOUSE_ID);
} }

View file

@ -241,7 +241,11 @@ public:
bool _wantSfxDebug; bool _wantSfxDebug;
int32 _gameCycle; int32 _gameCycle;
#ifdef SWORD2_DEBUG
bool _renderSkip; bool _renderSkip;
bool _stepOneCycle;
#endif
int32 initBackground(int32 res, int32 new_palette); int32 initBackground(int32 res, int32 new_palette);
@ -392,7 +396,6 @@ public:
bool _gamePaused; bool _gamePaused;
bool _graphicsLevelFudged; bool _graphicsLevelFudged;
bool _stepOneCycle; // for use while game paused
void startGame(); void startGame();
void gameCycle(); void gameCycle();
@ -405,8 +408,6 @@ public:
void initialiseFontResourceFlags(uint8 language); void initialiseFontResourceFlags(uint8 language);
}; };
extern Sword2Engine *g_sword2;
} // End of namespace Sword2 } // End of namespace Sword2
#endif #endif