Removed the exportsAreWide variable from the segment manager and save games, and moved validateExportFunc() in the Script class, thus resolving a TODO
svn-id: r49093
This commit is contained in:
parent
852cb16c49
commit
174a043aa7
8 changed files with 27 additions and 50 deletions
|
@ -218,11 +218,6 @@ int script_init_engine(EngineState *s) {
|
|||
|
||||
s->restarting_flags = SCI_GAME_IS_NOT_RESTARTING;
|
||||
|
||||
if (g_sci->_features->detectLofsType() == SCI_VERSION_1_MIDDLE)
|
||||
s->_segMan->setExportAreWide(true);
|
||||
else
|
||||
s->_segMan->setExportAreWide(false);
|
||||
|
||||
debug(2, "Engine initialized");
|
||||
|
||||
return 0;
|
||||
|
|
|
@ -187,12 +187,11 @@ reg_t kScriptID(EngineState *s, int argc, reg_t *argv) {
|
|||
return argv[0];
|
||||
|
||||
SegmentId scriptSeg = s->_segMan->getScriptSegment(script, SCRIPT_GET_LOAD);
|
||||
Script *scr;
|
||||
|
||||
if (!scriptSeg)
|
||||
return NULL_REG;
|
||||
|
||||
scr = s->_segMan->getScript(scriptSeg);
|
||||
Script *scr = s->_segMan->getScript(scriptSeg);
|
||||
|
||||
if (!scr->_numExports) {
|
||||
// FIXME: Is this fatal? This occurs in SQ4CD
|
||||
|
@ -205,7 +204,7 @@ reg_t kScriptID(EngineState *s, int argc, reg_t *argv) {
|
|||
return NULL_REG;
|
||||
}
|
||||
|
||||
return make_reg(scriptSeg, s->_segMan->validateExportFunc(index, scriptSeg));
|
||||
return make_reg(scriptSeg, scr->validateExportFunc(index));
|
||||
}
|
||||
|
||||
reg_t kDisposeScript(EngineState *s, int argc, reg_t *argv) {
|
||||
|
|
|
@ -222,7 +222,7 @@ void syncWithSerializer(Common::Serializer &s, reg_t &obj) {
|
|||
|
||||
void SegManager::saveLoadWithSerializer(Common::Serializer &s) {
|
||||
s.skip(4, VER(9), VER(9)); // OBSOLETE: Used to be reserved_id
|
||||
s.syncAsSint32LE(_exportsAreWide);
|
||||
s.skip(4, VER(18), VER(18)); // OBSOLETE: Used to be _exportsAreWide
|
||||
s.skip(4, VER(9), VER(9)); // OBSOLETE: Used to be gc_mark_bits
|
||||
|
||||
if (s.isLoading()) {
|
||||
|
|
|
@ -49,7 +49,6 @@ SegManager::SegManager(ResourceManager *resMan) {
|
|||
String_seg_id = 0;
|
||||
#endif
|
||||
|
||||
_exportsAreWide = false;
|
||||
_resMan = resMan;
|
||||
|
||||
createClassTable();
|
||||
|
@ -340,10 +339,6 @@ bool SegManager::check(SegmentId seg) {
|
|||
return true;
|
||||
}
|
||||
|
||||
void SegManager::setExportAreWide(bool flag) {
|
||||
_exportsAreWide = flag;
|
||||
}
|
||||
|
||||
// return the seg if script_id is valid and in the map, else 0
|
||||
SegmentId SegManager::getScriptSegment(int script_id) const {
|
||||
return _scriptSegMap.getVal(script_id, 0);
|
||||
|
|
|
@ -95,17 +95,6 @@ public:
|
|||
*/
|
||||
void reconstructScripts(EngineState *s);
|
||||
|
||||
/**
|
||||
* Validate whether the specified public function is exported by
|
||||
* the script in the specified segment.
|
||||
* @param pubfunct Index of the function to validate
|
||||
* @param seg Segment ID of the script the check is to
|
||||
* be performed for
|
||||
* @return NULL if the public function is invalid, its
|
||||
* offset into the script's segment otherwise
|
||||
*/
|
||||
uint16 validateExportFunc(int pubfunct, SegmentId seg);
|
||||
|
||||
/**
|
||||
* Determines the segment occupied by a certain script, if any.
|
||||
* @param script_nr Number of the script to look up
|
||||
|
@ -125,7 +114,7 @@ public:
|
|||
// TODO: document this
|
||||
reg_t lookupScriptExport(int script_nr, int export_index) {
|
||||
SegmentId seg = getScriptSegment(script_nr, SCRIPT_GET_DONT_LOAD);
|
||||
return make_reg(seg, validateExportFunc(export_index, seg));
|
||||
return make_reg(seg, getScript(seg)->validateExportFunc(export_index));
|
||||
}
|
||||
|
||||
// TODO: document this
|
||||
|
@ -171,12 +160,6 @@ public:
|
|||
*/
|
||||
void scriptInitialiseLocals(reg_t location);
|
||||
|
||||
/**
|
||||
* Tells the segment manager whether exports are wide (32-bit) or not.
|
||||
* @param flag true if exports are wide, false otherwise
|
||||
*/
|
||||
void setExportAreWide(bool flag);
|
||||
|
||||
// 2. Clones
|
||||
|
||||
/**
|
||||
|
@ -472,8 +455,6 @@ private:
|
|||
|
||||
ResourceManager *_resMan;
|
||||
|
||||
bool _exportsAreWide;
|
||||
|
||||
SegmentId Clones_seg_id; ///< ID of the (a) clones segment
|
||||
SegmentId Lists_seg_id; ///< ID of the (a) list segment
|
||||
SegmentId Nodes_seg_id; ///< ID of the (a) node segment
|
||||
|
|
|
@ -26,6 +26,7 @@
|
|||
#include "common/endian.h"
|
||||
|
||||
#include "sci/sci.h"
|
||||
#include "sci/engine/features.h"
|
||||
#include "sci/engine/segment.h"
|
||||
#include "sci/engine/seg_manager.h"
|
||||
#include "sci/engine/state.h"
|
||||
|
@ -366,22 +367,18 @@ void Script::setExportTableOffset(int offset) {
|
|||
}
|
||||
}
|
||||
|
||||
// TODO: This method should be Script method. The only reason
|
||||
// that it isn't is that it uses _exportsAreWide, which is true if
|
||||
// detectLofsType() == SCI_VERSION_1_MIDDLE
|
||||
// Maybe _exportsAreWide should become a Script member var, e.g. set
|
||||
// by setExportTableOffset?
|
||||
uint16 SegManager::validateExportFunc(int pubfunct, SegmentId seg) {
|
||||
Script *scr = getScript(seg);
|
||||
if (scr->_numExports <= pubfunct) {
|
||||
uint16 Script::validateExportFunc(int pubfunct) {
|
||||
bool exportsAreWide = (g_sci->_features->detectLofsType() == SCI_VERSION_1_MIDDLE);
|
||||
|
||||
if (_numExports <= pubfunct) {
|
||||
warning("validateExportFunc(): pubfunct is invalid");
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (_exportsAreWide)
|
||||
if (exportsAreWide)
|
||||
pubfunct *= 2;
|
||||
uint16 offset = READ_SCI11ENDIAN_UINT16((byte *)(scr->_exportTable + pubfunct));
|
||||
VERIFY(offset < scr->_bufSize, "invalid export function pointer");
|
||||
uint16 offset = READ_SCI11ENDIAN_UINT16((byte *)(_exportTable + pubfunct));
|
||||
VERIFY(offset < _bufSize, "invalid export function pointer");
|
||||
|
||||
return offset;
|
||||
}
|
||||
|
|
|
@ -446,13 +446,21 @@ public:
|
|||
*/
|
||||
int getSynonymsNr() const;
|
||||
|
||||
|
||||
/**
|
||||
* Sets the script-relative offset of the exports table.
|
||||
* @param offset script-relative exports table offset
|
||||
*/
|
||||
void setExportTableOffset(int offset);
|
||||
|
||||
/**
|
||||
* Validate whether the specified public function is exported by
|
||||
* the script in the specified segment.
|
||||
* @param pubfunct Index of the function to validate
|
||||
* @return NULL if the public function is invalid, its
|
||||
* offset into the script's segment otherwise
|
||||
*/
|
||||
uint16 validateExportFunc(int pubfunct);
|
||||
|
||||
/**
|
||||
* Sets the script-relative offset of the synonyms associated with this script.
|
||||
* @param offset script-relative offset of the synonyms block
|
||||
|
|
|
@ -258,10 +258,12 @@ ExecStack *execute_method(EngineState *s, uint16 script, uint16 pubfunct, StackP
|
|||
int seg = s->_segMan->getScriptSegment(script);
|
||||
Script *scr = s->_segMan->getScriptIfLoaded(seg);
|
||||
|
||||
if (!scr || scr->isMarkedAsDeleted()) // Script not present yet?
|
||||
if (!scr || scr->isMarkedAsDeleted()) { // Script not present yet?
|
||||
seg = script_instantiate(g_sci->getResMan(), s->_segMan, script);
|
||||
scr = s->_segMan->getScript(seg);
|
||||
}
|
||||
|
||||
const int temp = s->_segMan->validateExportFunc(pubfunct, seg);
|
||||
const int temp = scr->validateExportFunc(pubfunct);
|
||||
if (!temp) {
|
||||
#ifdef ENABLE_SCI32
|
||||
// HACK: Temporarily switch to a warning in SCI32 games until we can figure out why Torin has
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue