2007-05-30 21:56:52 +00:00
|
|
|
/* ScummVM - Graphic Adventure Engine
|
|
|
|
*
|
|
|
|
* ScummVM is the legal property of its developers, whose names
|
|
|
|
* are too numerous to list here. Please refer to the COPYRIGHT
|
|
|
|
* file distributed with this source distribution.
|
2003-07-28 01:44:38 +00:00
|
|
|
*
|
2007-05-31 20:28:29 +00:00
|
|
|
* Additional copyright for this file:
|
|
|
|
* Copyright (C) 1994-1998 Revolution Software Ltd.
|
|
|
|
*
|
2003-07-28 01:44:38 +00:00
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
|
|
|
* of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* 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
|
2005-10-18 01:30:26 +00:00
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
2003-07-28 01:44:38 +00:00
|
|
|
*/
|
|
|
|
|
2007-09-19 08:40:12 +00:00
|
|
|
|
2003-11-18 08:17:36 +00:00
|
|
|
#include "common/file.h"
|
2011-04-24 08:34:27 +00:00
|
|
|
#include "common/textconsole.h"
|
2004-11-14 15:00:01 +00:00
|
|
|
|
2003-11-16 14:18:29 +00:00
|
|
|
#include "sword2/sword2.h"
|
2004-09-08 07:10:54 +00:00
|
|
|
#include "sword2/defs.h"
|
2006-02-17 15:07:36 +00:00
|
|
|
#include "sword2/header.h"
|
2004-02-05 14:19:07 +00:00
|
|
|
#include "sword2/logic.h"
|
|
|
|
#include "sword2/maketext.h"
|
2004-11-14 15:00:01 +00:00
|
|
|
#include "sword2/memory.h"
|
2004-02-05 14:19:07 +00:00
|
|
|
#include "sword2/resman.h"
|
2004-11-14 15:00:01 +00:00
|
|
|
#include "sword2/router.h"
|
Began what I hope is the final major restructuring of the BS2 engine.
In this first step, I have moved all opcode functions into functions.cpp,
instead of having them scattered all over the place.
To get things to compile again, I had to rewrite the overly complicated
sound effects handling. It's much simpler now.
The next step will be to move any non-trivial code out of the opcode
functions and into the appropriate object. This, I hope, will make it
easier to create well-separated objects, instead of the current mess.
I also want to tear down the artificial boundary between the main directory
and the "driver" directory. We already have a cross-platform layer; there's
no need to have yet another one. (Actually, the rewriting of the sound
effects code took one first step in this direction.)
At the final stage, I'd like to get rid of the "drivers" directory
completely, but I'll probably need some help with that if I want to
preserve the CVS history of the code.
Things will probably be a bit bumpy along the way, but I seem to have
reached a point of relative stability again, which is why I'm commiting
this now.
svn-id: r16668
2005-01-28 16:33:14 +00:00
|
|
|
#include "sword2/sound.h"
|
2003-07-28 01:44:38 +00:00
|
|
|
|
2003-10-04 00:52:27 +00:00
|
|
|
namespace Sword2 {
|
|
|
|
|
Began what I hope is the final major restructuring of the BS2 engine.
In this first step, I have moved all opcode functions into functions.cpp,
instead of having them scattered all over the place.
To get things to compile again, I had to rewrite the overly complicated
sound effects handling. It's much simpler now.
The next step will be to move any non-trivial code out of the opcode
functions and into the appropriate object. This, I hope, will make it
easier to create well-separated objects, instead of the current mess.
I also want to tear down the artificial boundary between the main directory
and the "driver" directory. We already have a cross-platform layer; there's
no need to have yet another one. (Actually, the rewriting of the sound
effects code took one first step in this direction.)
At the final stage, I'd like to get rid of the "drivers" directory
completely, but I'll probably need some help with that if I want to
preserve the CVS history of the code.
Things will probably be a bit bumpy along the way, but I seem to have
reached a point of relative stability again, which is why I'm commiting
this now.
svn-id: r16668
2005-01-28 16:33:14 +00:00
|
|
|
bool Sword2Engine::initStartMenu() {
|
2003-09-20 17:00:14 +00:00
|
|
|
// Print out a list of all the start points available.
|
|
|
|
// There should be a linc produced file called startup.txt.
|
|
|
|
// This file should contain ascii numbers of all the resource game
|
|
|
|
// objects that are screen managers.
|
|
|
|
// We query each in turn and setup an array of start structures.
|
|
|
|
// If the file doesn't exist then we say so and return a 0.
|
2003-07-28 01:44:38 +00:00
|
|
|
|
2005-05-10 22:56:25 +00:00
|
|
|
Common::File fp;
|
2003-11-18 08:17:36 +00:00
|
|
|
|
2003-09-20 17:00:14 +00:00
|
|
|
// ok, load in the master screen manager file
|
2003-07-28 01:44:38 +00:00
|
|
|
|
2004-04-27 08:59:58 +00:00
|
|
|
_totalStartups = 0;
|
Began what I hope is the final major restructuring of the BS2 engine.
In this first step, I have moved all opcode functions into functions.cpp,
instead of having them scattered all over the place.
To get things to compile again, I had to rewrite the overly complicated
sound effects handling. It's much simpler now.
The next step will be to move any non-trivial code out of the opcode
functions and into the appropriate object. This, I hope, will make it
easier to create well-separated objects, instead of the current mess.
I also want to tear down the artificial boundary between the main directory
and the "driver" directory. We already have a cross-platform layer; there's
no need to have yet another one. (Actually, the rewriting of the sound
effects code took one first step in this direction.)
At the final stage, I'd like to get rid of the "drivers" directory
completely, but I'll probably need some help with that if I want to
preserve the CVS history of the code.
Things will probably be a bit bumpy along the way, but I seem to have
reached a point of relative stability again, which is why I'm commiting
this now.
svn-id: r16668
2005-01-28 16:33:14 +00:00
|
|
|
_totalScreenManagers = 0;
|
2003-07-28 01:44:38 +00:00
|
|
|
|
2003-11-18 08:17:36 +00:00
|
|
|
if (!fp.open("startup.inf")) {
|
2004-04-27 08:59:58 +00:00
|
|
|
warning("Cannot open startup.inf - the debugger won't have a start menu");
|
|
|
|
return false;
|
2003-07-28 01:44:38 +00:00
|
|
|
}
|
|
|
|
|
2003-11-18 08:17:36 +00:00
|
|
|
// The startup.inf file which contains a list of all the files. Now
|
|
|
|
// extract the filenames
|
|
|
|
|
2004-04-27 08:59:58 +00:00
|
|
|
int start_ids[MAX_starts];
|
2006-07-08 20:20:55 +00:00
|
|
|
int lineno = 0;
|
|
|
|
|
2009-07-29 21:39:34 +00:00
|
|
|
while (!fp.eos() && !fp.err()) {
|
2008-09-04 21:40:32 +00:00
|
|
|
Common::String line = fp.readLine();
|
|
|
|
|
|
|
|
// Skip empty lines or, more likely, the end of the stream.
|
|
|
|
if (line.size() == 0)
|
|
|
|
continue;
|
|
|
|
|
2006-07-08 20:20:55 +00:00
|
|
|
char *errptr;
|
|
|
|
int id;
|
|
|
|
|
|
|
|
lineno++;
|
2008-09-04 21:40:32 +00:00
|
|
|
id = strtol(line.c_str(), &errptr, 10);
|
2006-07-08 20:20:55 +00:00
|
|
|
|
|
|
|
if (*errptr) {
|
2008-09-04 21:40:32 +00:00
|
|
|
warning("startup.inf:%d: Invalid string '%s'", lineno, line.c_str());
|
2006-07-08 20:20:55 +00:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!_resman->checkValid(id)) {
|
|
|
|
warning("startup.inf:%d: Invalid resource %d", lineno, id);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (_resman->fetchType(id) != SCREEN_MANAGER) {
|
2006-07-08 20:45:01 +00:00
|
|
|
warning("startup.inf:%d: '%s' (%d) is not a screen manager", lineno, _resman->fetchName(id), id);
|
2006-07-08 20:20:55 +00:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
start_ids[_totalScreenManagers] = id;
|
|
|
|
|
2006-04-01 21:56:10 +00:00
|
|
|
if (++_totalScreenManagers >= MAX_starts) {
|
|
|
|
warning("Too many entries in startup.inf");
|
2003-07-28 01:44:38 +00:00
|
|
|
break;
|
|
|
|
}
|
2003-11-18 08:17:36 +00:00
|
|
|
}
|
|
|
|
|
2008-09-04 21:40:32 +00:00
|
|
|
// An I/O error before EOS? That's bad, but this is not a vital file.
|
2009-07-29 21:39:34 +00:00
|
|
|
if (fp.err() && !fp.eos())
|
2008-09-04 21:40:32 +00:00
|
|
|
warning("I/O error while reading startup.inf");
|
|
|
|
|
2003-11-18 08:17:36 +00:00
|
|
|
fp.close();
|
2003-07-28 01:44:38 +00:00
|
|
|
|
2004-04-27 08:59:58 +00:00
|
|
|
// Using this method the Gode generated resource.inf must have #0d0a
|
2003-09-20 17:00:14 +00:00
|
|
|
// on the last entry
|
2003-07-28 01:44:38 +00:00
|
|
|
|
2004-04-27 08:59:58 +00:00
|
|
|
debug(1, "%d screen manager objects", _totalScreenManagers);
|
2003-07-28 01:44:38 +00:00
|
|
|
|
2003-09-20 17:00:14 +00:00
|
|
|
// Open each object and make a query call. The object must fill in a
|
|
|
|
// startup structure. It may fill in several if it wishes - for
|
|
|
|
// instance a startup could be set for later in the game where
|
|
|
|
// specific vars are set
|
2003-07-28 01:44:38 +00:00
|
|
|
|
2003-11-18 08:17:36 +00:00
|
|
|
for (uint i = 0; i < _totalScreenManagers; i++) {
|
2004-04-27 08:59:58 +00:00
|
|
|
_startRes = start_ids[i];
|
2003-07-28 01:44:38 +00:00
|
|
|
|
2004-04-27 08:59:58 +00:00
|
|
|
debug(2, "Querying screen manager %d", _startRes);
|
2003-07-28 01:44:38 +00:00
|
|
|
|
2004-04-27 08:59:58 +00:00
|
|
|
// Open each one and run through the interpreter. Script 0 is
|
2006-07-08 20:20:55 +00:00
|
|
|
// the query request script. We have already made reasonably
|
|
|
|
// sure the resource is ok.
|
2003-07-28 01:44:38 +00:00
|
|
|
|
2006-07-08 20:20:55 +00:00
|
|
|
_logic->runResScript(_startRes, 0);
|
2003-07-28 01:44:38 +00:00
|
|
|
}
|
|
|
|
|
2003-09-20 17:00:14 +00:00
|
|
|
return 1;
|
|
|
|
}
|
2003-07-28 01:44:38 +00:00
|
|
|
|
Began what I hope is the final major restructuring of the BS2 engine.
In this first step, I have moved all opcode functions into functions.cpp,
instead of having them scattered all over the place.
To get things to compile again, I had to rewrite the overly complicated
sound effects handling. It's much simpler now.
The next step will be to move any non-trivial code out of the opcode
functions and into the appropriate object. This, I hope, will make it
easier to create well-separated objects, instead of the current mess.
I also want to tear down the artificial boundary between the main directory
and the "driver" directory. We already have a cross-platform layer; there's
no need to have yet another one. (Actually, the rewriting of the sound
effects code took one first step in this direction.)
At the final stage, I'd like to get rid of the "drivers" directory
completely, but I'll probably need some help with that if I want to
preserve the CVS history of the code.
Things will probably be a bit bumpy along the way, but I seem to have
reached a point of relative stability again, which is why I'm commiting
this now.
svn-id: r16668
2005-01-28 16:33:14 +00:00
|
|
|
void Sword2Engine::registerStartPoint(int32 key, char *name) {
|
2004-04-27 08:59:58 +00:00
|
|
|
assert(_totalStartups < MAX_starts);
|
2003-07-28 01:44:38 +00:00
|
|
|
|
2003-11-04 18:02:49 +00:00
|
|
|
_startList[_totalStartups].start_res_id = _startRes;
|
Began what I hope is the final major restructuring of the BS2 engine.
In this first step, I have moved all opcode functions into functions.cpp,
instead of having them scattered all over the place.
To get things to compile again, I had to rewrite the overly complicated
sound effects handling. It's much simpler now.
The next step will be to move any non-trivial code out of the opcode
functions and into the appropriate object. This, I hope, will make it
easier to create well-separated objects, instead of the current mess.
I also want to tear down the artificial boundary between the main directory
and the "driver" directory. We already have a cross-platform layer; there's
no need to have yet another one. (Actually, the rewriting of the sound
effects code took one first step in this direction.)
At the final stage, I'd like to get rid of the "drivers" directory
completely, but I'll probably need some help with that if I want to
preserve the CVS history of the code.
Things will probably be a bit bumpy along the way, but I seem to have
reached a point of relative stability again, which is why I'm commiting
this now.
svn-id: r16668
2005-01-28 16:33:14 +00:00
|
|
|
_startList[_totalStartups].key = key;
|
2003-07-28 01:44:38 +00:00
|
|
|
|
2004-04-27 08:59:58 +00:00
|
|
|
strncpy(_startList[_totalStartups].description, name, MAX_description);
|
|
|
|
_startList[_totalStartups].description[MAX_description - 1] = 0;
|
2003-07-28 01:44:38 +00:00
|
|
|
|
2003-11-04 18:02:49 +00:00
|
|
|
_totalStartups++;
|
2003-07-28 01:44:38 +00:00
|
|
|
}
|
|
|
|
|
2005-02-22 07:37:50 +00:00
|
|
|
void Sword2Engine::runStart(int start) {
|
2004-04-27 08:59:58 +00:00
|
|
|
// Restarting - stop sfx, music & speech!
|
2003-09-20 17:00:14 +00:00
|
|
|
|
2007-01-26 18:21:41 +00:00
|
|
|
_sound->clearFxQueue(true);
|
Began what I hope is the final major restructuring of the BS2 engine.
In this first step, I have moved all opcode functions into functions.cpp,
instead of having them scattered all over the place.
To get things to compile again, I had to rewrite the overly complicated
sound effects handling. It's much simpler now.
The next step will be to move any non-trivial code out of the opcode
functions and into the appropriate object. This, I hope, will make it
easier to create well-separated objects, instead of the current mess.
I also want to tear down the artificial boundary between the main directory
and the "driver" directory. We already have a cross-platform layer; there's
no need to have yet another one. (Actually, the rewriting of the sound
effects code took one first step in this direction.)
At the final stage, I'd like to get rid of the "drivers" directory
completely, but I'll probably need some help with that if I want to
preserve the CVS history of the code.
Things will probably be a bit bumpy along the way, but I seem to have
reached a point of relative stability again, which is why I'm commiting
this now.
svn-id: r16668
2005-01-28 16:33:14 +00:00
|
|
|
_logic->fnStopMusic(NULL);
|
|
|
|
_sound->unpauseSpeech();
|
|
|
|
_sound->stopSpeech();
|
2003-09-20 17:00:14 +00:00
|
|
|
|
2004-04-27 08:59:58 +00:00
|
|
|
// Remove all resources from memory, including player object and global
|
|
|
|
// variables
|
2003-09-20 17:00:14 +00:00
|
|
|
|
Began what I hope is the final major restructuring of the BS2 engine.
In this first step, I have moved all opcode functions into functions.cpp,
instead of having them scattered all over the place.
To get things to compile again, I had to rewrite the overly complicated
sound effects handling. It's much simpler now.
The next step will be to move any non-trivial code out of the opcode
functions and into the appropriate object. This, I hope, will make it
easier to create well-separated objects, instead of the current mess.
I also want to tear down the artificial boundary between the main directory
and the "driver" directory. We already have a cross-platform layer; there's
no need to have yet another one. (Actually, the rewriting of the sound
effects code took one first step in this direction.)
At the final stage, I'd like to get rid of the "drivers" directory
completely, but I'll probably need some help with that if I want to
preserve the CVS history of the code.
Things will probably be a bit bumpy along the way, but I seem to have
reached a point of relative stability again, which is why I'm commiting
this now.
svn-id: r16668
2005-01-28 16:33:14 +00:00
|
|
|
_resman->removeAll();
|
2003-07-28 01:44:38 +00:00
|
|
|
|
2004-09-08 07:10:54 +00:00
|
|
|
// Reopen global variables resource and player object
|
Began what I hope is the final major restructuring of the BS2 engine.
In this first step, I have moved all opcode functions into functions.cpp,
instead of having them scattered all over the place.
To get things to compile again, I had to rewrite the overly complicated
sound effects handling. It's much simpler now.
The next step will be to move any non-trivial code out of the opcode
functions and into the appropriate object. This, I hope, will make it
easier to create well-separated objects, instead of the current mess.
I also want to tear down the artificial boundary between the main directory
and the "driver" directory. We already have a cross-platform layer; there's
no need to have yet another one. (Actually, the rewriting of the sound
effects code took one first step in this direction.)
At the final stage, I'd like to get rid of the "drivers" directory
completely, but I'll probably need some help with that if I want to
preserve the CVS history of the code.
Things will probably be a bit bumpy along the way, but I seem to have
reached a point of relative stability again, which is why I'm commiting
this now.
svn-id: r16668
2005-01-28 16:33:14 +00:00
|
|
|
setupPersistentResources();
|
2003-07-28 01:44:38 +00:00
|
|
|
|
2004-04-27 08:59:58 +00:00
|
|
|
// Free all the route memory blocks from previous game
|
Began what I hope is the final major restructuring of the BS2 engine.
In this first step, I have moved all opcode functions into functions.cpp,
instead of having them scattered all over the place.
To get things to compile again, I had to rewrite the overly complicated
sound effects handling. It's much simpler now.
The next step will be to move any non-trivial code out of the opcode
functions and into the appropriate object. This, I hope, will make it
easier to create well-separated objects, instead of the current mess.
I also want to tear down the artificial boundary between the main directory
and the "driver" directory. We already have a cross-platform layer; there's
no need to have yet another one. (Actually, the rewriting of the sound
effects code took one first step in this direction.)
At the final stage, I'd like to get rid of the "drivers" directory
completely, but I'll probably need some help with that if I want to
preserve the CVS history of the code.
Things will probably be a bit bumpy along the way, but I seem to have
reached a point of relative stability again, which is why I'm commiting
this now.
svn-id: r16668
2005-01-28 16:33:14 +00:00
|
|
|
_logic->_router->freeAllRouteMem();
|
2003-09-20 17:00:14 +00:00
|
|
|
|
2004-04-27 08:59:58 +00:00
|
|
|
// If there was speech text, kill the text block
|
Began what I hope is the final major restructuring of the BS2 engine.
In this first step, I have moved all opcode functions into functions.cpp,
instead of having them scattered all over the place.
To get things to compile again, I had to rewrite the overly complicated
sound effects handling. It's much simpler now.
The next step will be to move any non-trivial code out of the opcode
functions and into the appropriate object. This, I hope, will make it
easier to create well-separated objects, instead of the current mess.
I also want to tear down the artificial boundary between the main directory
and the "driver" directory. We already have a cross-platform layer; there's
no need to have yet another one. (Actually, the rewriting of the sound
effects code took one first step in this direction.)
At the final stage, I'd like to get rid of the "drivers" directory
completely, but I'll probably need some help with that if I want to
preserve the CVS history of the code.
Things will probably be a bit bumpy along the way, but I seem to have
reached a point of relative stability again, which is why I'm commiting
this now.
svn-id: r16668
2005-01-28 16:33:14 +00:00
|
|
|
if (_logic->_speechTextBlocNo) {
|
|
|
|
_fontRenderer->killTextBloc(_logic->_speechTextBlocNo);
|
|
|
|
_logic->_speechTextBlocNo = 0;
|
2004-04-27 08:59:58 +00:00
|
|
|
}
|
2003-09-20 17:00:14 +00:00
|
|
|
|
Applied my own patch #1341495, in an attempt to fix alignment issues
reported by Crilith.
To elaborate a bit, the engine no longer accesses resource data through
packed structs. Instead it uses memory streams and the READ/WRITE
functions.
If data is mainly read, not written, I have replaced the old struct with a
new one with a read() function to read the whole thing from memory into the
struct's variables, and a write() function to dump the struct's variables
to memory. In fact, most of these write() functions remain unused.
If data is both read and written, I have replaced the struct with a class
with individual get/set functions to replace the old variables. This
manipulates memory directly.
Since I'm fairly sure that these structs are frequently stored as local
variables for a script, all script variables (both local and global) are
stored as little-endian and accessed through the READ/WRITE functions,
rather than being treated as arrays of 32-bit integers.
On a positive note, the functions for doing endian conversion of resources
and save games have been removed, and some general cleanups have been made
to assist in the rewrite.
Initial reports indicate that this patch indeed fixes alignment issues, and
that I have not - surprisingly - broken the game on big-endian platforms.
At least not in any immediately obvious way. And there's still plenty of
time to fix regressions before 0.9.0, too.
svn-id: r19366
2005-10-29 21:24:54 +00:00
|
|
|
_logic->runResObjScript(_startList[start].start_res_id, CUR_PLAYER_ID, _startList[start].key & 0xffff);
|
2003-09-20 17:00:14 +00:00
|
|
|
|
2004-04-27 08:59:58 +00:00
|
|
|
// Make sure there's a mouse, in case restarting while mouse not
|
|
|
|
// available
|
Began what I hope is the final major restructuring of the BS2 engine.
In this first step, I have moved all opcode functions into functions.cpp,
instead of having them scattered all over the place.
To get things to compile again, I had to rewrite the overly complicated
sound effects handling. It's much simpler now.
The next step will be to move any non-trivial code out of the opcode
functions and into the appropriate object. This, I hope, will make it
easier to create well-separated objects, instead of the current mess.
I also want to tear down the artificial boundary between the main directory
and the "driver" directory. We already have a cross-platform layer; there's
no need to have yet another one. (Actually, the rewriting of the sound
effects code took one first step in this direction.)
At the final stage, I'd like to get rid of the "drivers" directory
completely, but I'll probably need some help with that if I want to
preserve the CVS history of the code.
Things will probably be a bit bumpy along the way, but I seem to have
reached a point of relative stability again, which is why I'm commiting
this now.
svn-id: r16668
2005-01-28 16:33:14 +00:00
|
|
|
_logic->fnAddHuman(NULL);
|
2003-09-20 17:00:14 +00:00
|
|
|
}
|
2003-10-04 00:52:27 +00:00
|
|
|
|
|
|
|
} // End of namespace Sword2
|