Removed the gfxw_new_visual and gfxw_new_port wrappers, moved _kfuncTable inside the Kernel class and moved gfxw_find_port inside the GfxVisual struct

svn-id: r41125
This commit is contained in:
Filippos Karapetis 2009-06-02 14:16:59 +00:00
parent c1d01223aa
commit 98f64cfa2f
15 changed files with 73 additions and 111 deletions

View file

@ -34,7 +34,7 @@
#include "sci/engine/gc.h"
#include "sci/gfx/gfx_gui.h" // for sciw_set_status_bar
#include "sci/gfx/gfx_state_internal.h"
#include "sci/gfx/gfx_widgets.h" // for gfxw_find_port
#include "sci/gfx/gfx_widgets.h" // for getPort
#include "sci/sfx/songlib.h" // for songlib_t
#include "sci/vocabulary.h"
@ -647,7 +647,7 @@ bool Console::cmdPrintPort(int argc, const char **argv) {
if (!g_EngineState->visual) {
DebugPrintf("Visual is uninitialized\n");
} else {
port = gfxw_find_port(g_EngineState->visual, atoi(argv[1]));
port = g_EngineState->visual->getPort(atoi(argv[1]));
if (!port)
DebugPrintf("No such port\n");
else

View file

@ -104,11 +104,11 @@ int _reset_graphics_input(EngineState *s) {
return 1;
}
s->visual = gfxw_new_visual(s->gfx_state, font_nr);
s->visual = new GfxVisual(s->gfx_state, font_nr);
s->wm_port = gfxw_new_port(s->visual, NULL, s->gfx_state->pic_port_bounds, s->ega_colors[0], transparent);
s->wm_port = new GfxPort(s->visual, s->gfx_state->pic_port_bounds, s->ega_colors[0], transparent);
s->iconbar_port = gfxw_new_port(s->visual, NULL, gfx_rect(0, 0, 320, 200), s->ega_colors[0], transparent);
s->iconbar_port = new GfxPort(s->visual, gfx_rect(0, 0, 320, 200), s->ega_colors[0], transparent);
s->iconbar_port->_flags |= GFXW_FLAG_NO_IMPLICIT_SWITCH;
if (s->resmgr->_sciVersion >= SCI_VERSION_01_VGA) {
@ -124,9 +124,9 @@ int _reset_graphics_input(EngineState *s) {
bgcolor.visual = s->gfx_state->resstate->static_palette[255];
bgcolor.mask = GFX_MASK_VISUAL;
#endif
s->titlebar_port = gfxw_new_port(s->visual, NULL, gfx_rect(0, 0, 320, 10), fgcolor, bgcolor);
s->titlebar_port = new GfxPort(s->visual, gfx_rect(0, 0, 320, 10), fgcolor, bgcolor);
} else {
s->titlebar_port = gfxw_new_port(s->visual, NULL, gfx_rect(0, 0, 320, 10), s->ega_colors[0], s->ega_colors[15]);
s->titlebar_port = new GfxPort(s->visual, gfx_rect(0, 0, 320, 10), s->ega_colors[0], s->ega_colors[15]);
}
s->titlebar_port->_color.mask |= GFX_MASK_PRIORITY;
s->titlebar_port->_color.priority = 11;
@ -135,7 +135,7 @@ int _reset_graphics_input(EngineState *s) {
s->titlebar_port->_flags |= GFXW_FLAG_NO_IMPLICIT_SWITCH;
// but this is correct
s->picture_port = gfxw_new_port(s->visual, NULL, s->gfx_state->pic_port_bounds, s->ega_colors[0], transparent);
s->picture_port = new GfxPort(s->visual, s->gfx_state->pic_port_bounds, s->ega_colors[0], transparent);
s->_pics.clear();
@ -373,9 +373,6 @@ int script_init_engine(EngineState *s, sci_version_t version) {
s->_kernel = new Kernel(s->resmgr, (s->flags & GF_SCI0_OLD));
s->_vocabulary = new Vocabulary(s->resmgr);
script_map_kernel(s);
// Maps the kernel functions
s->restarting_flags = SCI_GAME_IS_NOT_RESTARTING;
s->bp_list = NULL; // No breakpoints defined
@ -419,8 +416,6 @@ void script_free_engine(EngineState *s) {
debug(2, "Freeing state-dependant data");
s->_kfuncTable.clear();
delete s->_vocabulary;
s->_vocabulary = 0;
delete s->_kernel;

View file

@ -482,6 +482,9 @@ Kernel::Kernel(ResourceManager *resmgr, bool isOldSci0) : _resmgr(resmgr) {
error("Kernel: Could not retrieve selector names");
}
// Map the kernel functions
mapFunctions();
// Map a few special selectors for later use
mapSelectors();
}
@ -490,6 +493,7 @@ Kernel::~Kernel() {
_selectorNames.clear();
_opcodes.clear();
_kernelNames.clear();
_kfuncTable.clear();
}
bool Kernel::loadSelectorNames(bool isOldSci0) {
@ -652,11 +656,11 @@ void kernel_compile_signature(const char **s) {
*s = result; // Write back
}
int script_map_kernel(EngineState *s) {
void Kernel::mapFunctions() {
int mapped = 0;
int ignored = 0;
uint functions_nr = s->_kernel->getKernelNamesSize();
uint max_functions_nr = (s->resmgr->_sciVersion == SCI_VERSION_0) ? 0x72 : 0x7b;
uint functions_nr = getKernelNamesSize();
uint max_functions_nr = (_resmgr->_sciVersion == SCI_VERSION_0) ? 0x72 : 0x7b;
if (functions_nr < max_functions_nr) {
warning("SCI version believed to have %d kernel"
@ -666,14 +670,14 @@ int script_map_kernel(EngineState *s) {
functions_nr = max_functions_nr;
}
s->_kfuncTable.resize(functions_nr);
_kfuncTable.resize(functions_nr);
for (uint functnr = 0; functnr < functions_nr; functnr++) {
int seeker, found = -1;
Common::String sought_name;
if (functnr < s->_kernel->getKernelNamesSize())
sought_name = s->_kernel->getKernelName(functnr);
if (functnr < getKernelNamesSize())
sought_name = getKernelName(functnr);
if (!sought_name.empty())
for (seeker = 0; (found == -1) && kfunct_mappers[seeker].type != KF_TERMINATOR; seeker++)
@ -682,27 +686,27 @@ int script_map_kernel(EngineState *s) {
if (found == -1) {
if (!sought_name.empty()) {
warning("Kernel function %s[%x] unmapped", s->_kernel->getKernelName(functnr).c_str(), functnr);
s->_kfuncTable[functnr].fun = kNOP;
warning("Kernel function %s[%x] unmapped", getKernelName(functnr).c_str(), functnr);
_kfuncTable[functnr].fun = kNOP;
} else {
warning("Flagging kernel function %x as unknown", functnr);
s->_kfuncTable[functnr].fun = k_Unknown;
_kfuncTable[functnr].fun = k_Unknown;
}
s->_kfuncTable[functnr].signature = NULL;
s->_kfuncTable[functnr].orig_name = sought_name;
_kfuncTable[functnr].signature = NULL;
_kfuncTable[functnr].orig_name = sought_name;
} else
switch (kfunct_mappers[found].type) {
case KF_NONE:
s->_kfuncTable[functnr].signature = NULL;
_kfuncTable[functnr].signature = NULL;
++ignored;
break;
case KF_NEW:
s->_kfuncTable[functnr].fun = kfunct_mappers[found].fun;
s->_kfuncTable[functnr].signature = kfunct_mappers[found].signature;
s->_kfuncTable[functnr].orig_name.clear();
kernel_compile_signature(&(s->_kfuncTable[functnr].signature));
_kfuncTable[functnr].fun = kfunct_mappers[found].fun;
_kfuncTable[functnr].signature = kfunct_mappers[found].signature;
_kfuncTable[functnr].orig_name.clear();
kernel_compile_signature(&(_kfuncTable[functnr].signature));
++mapped;
break;
case KF_TERMINATOR:
@ -712,12 +716,12 @@ int script_map_kernel(EngineState *s) {
} // for all functions requesting to be mapped
sciprintf("Handled %d/%d kernel functions, mapping %d", mapped + ignored, s->_kernel->getKernelNamesSize(), mapped);
sciprintf("Handled %d/%d kernel functions, mapping %d", mapped + ignored, getKernelNamesSize(), mapped);
if (ignored)
sciprintf(" and ignoring %d", ignored);
sciprintf(".\n");
return 0;
return;
}
int determine_reg_type(EngineState *s, reg_t reg, int allow_invalid) {

View file

@ -51,6 +51,15 @@ struct opcode {
Common::String name;
};
/* Generic description: */
typedef reg_t kfunct(EngineState *s, int funct_nr, int argc, reg_t *argv);
struct kfunct_sig_pair_t {
kfunct *fun; /* The actual function */
const char *signature; /* kfunct signature */
Common::String orig_name; /* Original name, in case we couldn't map it */
};
class Kernel {
public:
Kernel(ResourceManager *resmgr, bool isOldSci0);
@ -84,6 +93,8 @@ public:
void dumpScriptClass(char *data, int seeker, int objsize);
selector_map_t _selectorMap; /**< Shortcut list for important selectors */
Common::Array<kfunct_sig_pair_t> _kfuncTable; /**< Table of kernel functions */
private:
/**
* Loads the kernel function names.
@ -107,6 +118,11 @@ private:
*/
void mapSelectors();
/* Maps kernel functions
** Returns : (void)
*/
void mapFunctions();
/**
* Loads the opcode names (only used for debugging).
* @return true on success, false on failure
@ -341,18 +357,6 @@ List *lookup_list(EngineState *s, reg_t addr);
/******************** Kernel functions ********************/
/* Generic description: */
typedef reg_t kfunct(EngineState *s, int funct_nr, int argc, reg_t *argv);
struct kfunct_sig_pair_t {
kfunct *fun; /* The actual function */
const char *signature; /* kfunct signature */
Common::String orig_name; /* Original name, in case we couldn't map it */
};
// New kernel functions
reg_t kStrLen(EngineState *s, int funct_nr, int argc, reg_t *argv);
reg_t kGetFarText(EngineState *s, int funct_nr, int argc, reg_t *argv);

View file

@ -232,7 +232,7 @@ void graph_restore_box(EngineState *s, reg_t handle) {
while (port_nr > 2 && !(s->port->_flags & GFXW_FLAG_IMMUNE_TO_SNAPSHOTS) && (gfxw_widget_matches_snapshot(*ptr, s->port))) {
// This shouldn't ever happen, actually, since windows (ports w/ ID > 2) should all be immune
GfxPort *newport = gfxw_find_port(s->visual, port_nr);
GfxPort *newport = s->visual->getPort(port_nr);
error("Port %d is not immune against snapshots", s->port->_ID);
port_nr--;
if (newport)
@ -1031,10 +1031,10 @@ reg_t kDrawPic(EngineState *s, int funct_nr, int argc, reg_t *argv) {
delete s->picture_port;
delete s->iconbar_port;
s->wm_port = gfxw_new_port(s->visual, NULL, s->gfx_state->pic_port_bounds, s->ega_colors[0], transparent);
s->picture_port = gfxw_new_port(s->visual, NULL, s->gfx_state->pic_port_bounds, s->ega_colors[0], transparent);
s->wm_port = new GfxPort(s->visual, s->gfx_state->pic_port_bounds, s->ega_colors[0], transparent);
s->picture_port = new GfxPort(s->visual, s->gfx_state->pic_port_bounds, s->ega_colors[0], transparent);
s->iconbar_port = gfxw_new_port(s->visual, NULL, gfx_rect(0, 0, 320, 200), s->ega_colors[0], transparent);
s->iconbar_port = new GfxPort(s->visual, gfx_rect(0, 0, 320, 200), s->ega_colors[0], transparent);
s->iconbar_port->_flags |= GFXW_FLAG_NO_IMPLICIT_SWITCH;
s->visual->add((GfxContainer *)s->visual, s->picture_port);
@ -2345,7 +2345,7 @@ reg_t kSetPort(EngineState *s, int funct_nr, int argc, reg_t *argv) {
iconbar_port that does not exist in SSCI. */
if (port_nr == (unsigned int) - 1) port_nr = s->iconbar_port->_ID;
new_port = gfxw_find_port(s->visual, port_nr);
new_port = s->visual->getPort(port_nr);
if (!new_port) {
error("Invalid port %04x requested", port_nr);
@ -2431,7 +2431,7 @@ reg_t kDisposeWindow(EngineState *s, int funct_nr, int argc, reg_t *argv) {
GfxPort *goner;
GfxPort *pred;
goner = gfxw_find_port(s->visual, goner_nr);
goner = s->visual->getPort(goner_nr);
if ((goner_nr < 3) || (goner == NULL)) {
error("Removal of invalid window %04x requested", goner_nr);
return s->r_acc;

View file

@ -248,7 +248,7 @@ reg_t kstub(EngineState *s, int funct_nr, int argc, reg_t *argv) {
}
reg_t kNOP(EngineState *s, int funct_nr, int argc, reg_t *argv) {
warning("Kernel function 0x%02x (%s) invoked: unmapped", funct_nr, s->_kfuncTable[funct_nr].orig_name.c_str());
warning("Kernel function 0x%02x (%s) invoked: unmapped", funct_nr, s->_kernel->_kfuncTable[funct_nr].orig_name.c_str());
return NULL_REG;
}

View file

@ -837,7 +837,6 @@ EngineState *gamestate_restore(EngineState *s, Common::SeekableReadStream *fh) {
// s->_kernel = 0; // FIXME: We should set s->_kernel to 0 here,
// else it could be freed when the old EngineState is freed. Luckily, this freeing currently
// never happens, so we don't need to.
retval->_kfuncTable = s->_kfuncTable;
// Copy breakpoint information from current game instance
retval->have_bp = s->have_bp;

View file

@ -857,7 +857,7 @@ reg_t disassemble(EngineState *s, reg_t pos, int print_bw_tag, int print_bytecod
}
if (opcode == op_callk)
sciprintf(" %s[%x]", (param_value < s->_kfuncTable.size()) ?
sciprintf(" %s[%x]", (param_value < s->_kernel->_kfuncTable.size()) ?
((param_value < s->_kernel->getKernelNamesSize()) ? s->_kernel->getKernelName(param_value).c_str() : "[Unknown(postulated)]")
: "<invalid>", param_value);
else

View file

@ -234,8 +234,6 @@ public:
SegManager *seg_manager;
int gc_countdown; /**< Number of kernel calls until next gc */
Common::Array<kfunct_sig_pair_t> _kfuncTable; /**< Table of kernel functions */
MessageState _msgState;
Vocabulary *_vocabulary;

View file

@ -972,7 +972,7 @@ void run_vm(EngineState *s, int restoring) {
s->r_amp_rest = 0; // We just used up the restadjust, remember?
}
if (opparams[0] >= (int)s->_kfuncTable.size()) {
if (opparams[0] >= (int)s->_kernel->_kfuncTable.size()) {
error("Invalid kernel function 0x%x requested\n", opparams[0]);
} else {
int argc = ASSERT_ARITHMETIC(xs->sp[0]);
@ -980,11 +980,11 @@ void run_vm(EngineState *s, int restoring) {
if (!(s->flags & GF_SCI0_OLD))
argc += restadjust;
if (s->_kfuncTable[opparams[0]].signature
&& !kernel_matches_signature(s, s->_kfuncTable[opparams[0]].signature, argc, xs->sp + 1)) {
if (s->_kernel->_kfuncTable[opparams[0]].signature
&& !kernel_matches_signature(s, s->_kernel->_kfuncTable[opparams[0]].signature, argc, xs->sp + 1)) {
error("[VM] Invalid arguments to kernel call %x\n", opparams[0]);
} else {
s->r_acc = s->_kfuncTable[opparams[0]].fun(s, opparams[0], argc, xs->sp + 1);
s->r_acc = s->_kernel->_kfuncTable[opparams[0]].fun(s, opparams[0], argc, xs->sp + 1);
}
// Call kernel function

View file

@ -1069,13 +1069,6 @@ void quit_vm();
** Returns : (void)
*/
int script_map_kernel(EngineState *s);
/* Maps kernel functions
** Parameters: (EngineState *) s: The state which the _kernelNames are retrieved from
** Returns : (void)
** This function reads from and writes to s. It is called by script_run().
*/
reg_t kalloc(EngineState *s, const char *type, int space);
/* Allocates "kernel" memory and returns a handle suitable to be passed on to SCI scripts
** Parameters: (EngineState *) s: Pointer to the EngineState to operate on

View file

@ -171,7 +171,7 @@ GfxPort *sciw_new_window(EngineState *s,
area.height -= 1; // Normal windows are drawn one pixel too small.
sciw_make_window_fit(&area, s->wm_port);
win = gfxw_new_port(visual, s->wm_port, area, color, bgcolor);
win = new GfxPort(visual, area, color, bgcolor);
win->_font = font;
win->title_text = title;

View file

@ -345,6 +345,10 @@ public:
virtual int draw(const Common::Point &pos);
virtual void print(int indentation) const;
virtual int setVisual(GfxVisual *);
GfxPort *getPort(int portId) {
return (portId < 0 || portId >= (int)_portRefs.size()) ? NULL : _portRefs[portId];
}
};
#define GFXW_IS_PORT(widget) ((widget)->_type == GFXW_PORT)
@ -361,6 +365,16 @@ struct GfxPort : public GfxContainer {
byte gray_text; /**< Whether text is 'grayed out' (dithered) */
public:
/* Creates a new port widget with the default settings
** Paramaters: (GfxVisual *) visual: The visual the port is added to
** (GfxPort *) predecessor: The port's predecessor
** (rect_t) area: The screen area covered by the port (absolute position)
** (gfx_color_t) fgcolor: Foreground drawing color
** (gfx_color_t) bgcolor: Background color
** A port differentiates itself from a list in that it contains additional information,
** and an optional title (stored in a display list).
** Ports are assigned implicit IDs identifying their position within the port stack.
*/
GfxPort(GfxVisual *visual, rect_t area, gfx_color_t fgcolor, gfx_color_t bgcolor);
~GfxPort();

View file

@ -1440,10 +1440,6 @@ void _gfxw_set_ops_VISUAL(GfxContainer *visual) {
_gfxwop_container_add_dirty, _gfxwop_container_add);
}
GfxVisual *gfxw_new_visual(GfxState *state, int font) {
return new GfxVisual(state, font);
}
GfxVisual::GfxVisual(GfxState *state, int font)
: GfxContainer(gfx_rect(0, 0, 320, 200), GFXW_VISUAL) {
@ -1609,10 +1605,6 @@ void _gfxw_set_ops_PORT(GfxContainer *widget) {
_gfxwop_port_add_dirty, _gfxwop_port_add);
}
GfxPort *gfxw_new_port(GfxVisual *visual, GfxPort *predecessor, rect_t area, gfx_color_t fgcolor, gfx_color_t bgcolor) {
return new GfxPort(visual, area, fgcolor, bgcolor);
}
GfxPort::GfxPort(GfxVisual *visual_, rect_t area, gfx_color_t fgcolor, gfx_color_t bgcolor_)
: GfxContainer(area, GFXW_PORT) {
VERIFY_WIDGET(visual_);
@ -1659,13 +1651,6 @@ GfxPort *gfxw_remove_port(GfxVisual *visual, GfxPort *port) {
return parent;
}
GfxPort *gfxw_find_port(GfxVisual *visual, int ID) {
if (ID < 0 || ID >= (int)visual->_portRefs.size())
return NULL;
return visual->_portRefs[ID];
}
GfxPort *gfxw_find_default_port(GfxVisual *visual) {
int id = visual->_portRefs.size();

View file

@ -311,36 +311,6 @@ GfxList *gfxw_new_list(rect_t area, int sorted);
** List widgets are also referred to as Display Lists.
*/
GfxVisual *gfxw_new_visual(GfxState *state, int font);
/* Creates a new visual widget
** Parameters: (GfxState *) state: The graphics state
** (int) font: The default font number for contained ports
** Returns : (GfxList *) A newly allocated visual widget
** Visual widgets are containers for port widgets.
*/
GfxPort *gfxw_new_port(GfxVisual *visual, GfxPort *predecessor, rect_t area, gfx_color_t fgcolor, gfx_color_t bgcolor);
/* Creates a new port widget with the default settings
** Paramaters: (GfxVisual *) visual: The visual the port is added to
** (GfxPort *) predecessor: The port's predecessor
** (rect_t) area: The screen area covered by the port (absolute position)
** (gfx_color_t) fgcolor: Foreground drawing color
** (gfx_color_t) bgcolor: Background color
** Returns : (GfxPort *) A newly allocated port widget
** A port differentiates itself from a list in that it contains additional information,
** and an optional title (stored in a display list).
** Ports are assigned implicit IDs identifying their position within the port stack.
*/
GfxPort *gfxw_find_port(GfxVisual *visual, int ID);
/* Retrieves a port with the specified ID
** Parameters: (GfxVisual *) visual: The visual the port is to be retrieved from
** (int) ID: The port's ID
** Returns : (GfxPort *) The requested port, or NULL if it didn't exist
** This function is O(1).
*/
GfxPort *gfxw_find_default_port(GfxVisual *visual);
/* Retrieves the default port from a visual
** Parameters: (GfxVisual *) visual: The visual the port should be retrieved from