aboutsummaryrefslogtreecommitdiff
path: root/engines/sci
diff options
context:
space:
mode:
authorFilippos Karapetis2009-03-23 08:43:53 +0000
committerFilippos Karapetis2009-03-23 08:43:53 +0000
commita6f49a636bf0e8cef76bc416d80ed10020a1924a (patch)
treeccdc650a66009b93eb5f51b84ba531fbfc44313e /engines/sci
parent93ff05cb6de0ed8b199eab31812421e03a94809c (diff)
downloadscummvm-rg350-a6f49a636bf0e8cef76bc416d80ed10020a1924a.tar.gz
scummvm-rg350-a6f49a636bf0e8cef76bc416d80ed10020a1924a.tar.bz2
scummvm-rg350-a6f49a636bf0e8cef76bc416d80ed10020a1924a.zip
- Moved palette initialization inside the graphics resource manager
- The static palette is no longer needlessly referenced directly outside the graphics resource manager - Moved the SCI interpreter version inside the graphics resource manager, instead of gfx_state_t svn-id: r39626
Diffstat (limited to 'engines/sci')
-rw-r--r--engines/sci/engine/kgraphics.cpp14
-rw-r--r--engines/sci/gfx/gfx_resmgr.cpp21
-rw-r--r--engines/sci/gfx/gfx_resmgr.h19
-rw-r--r--engines/sci/gfx/operations.cpp17
-rw-r--r--engines/sci/gfx/operations.h8
-rw-r--r--engines/sci/sci.cpp9
6 files changed, 44 insertions, 44 deletions
diff --git a/engines/sci/engine/kgraphics.cpp b/engines/sci/engine/kgraphics.cpp
index b4f00c77e6..e0e4e80e5a 100644
--- a/engines/sci/engine/kgraphics.cpp
+++ b/engines/sci/engine/kgraphics.cpp
@@ -266,10 +266,10 @@ PaletteEntry get_pic_color(EngineState *s, int color) {
if (color == 255)
return PaletteEntry(255,255,255);
- else if (color < s->gfx_state->gfxResMan->getNumberOfColors())
- return s->gfx_state->gfxResMan->getStaticPalette()->getColor(color);
+ else if (color < s->gfx_state->gfxResMan->getColorCount())
+ return s->gfx_state->gfxResMan->getColor(color);
else {
- SCIkwarn(SCIkERROR, "Color index %d out of bounds for pic %d (%d max)", color, s->gfx_state->pic_nr, s->gfx_state->gfxResMan->getNumberOfColors());
+ SCIkwarn(SCIkERROR, "Color index %d out of bounds for pic %d (%d max)", color, s->gfx_state->pic_nr, s->gfx_state->gfxResMan->getColorCount());
BREAKPOINT();
return PaletteEntry(0,0,0);
}
@@ -1262,10 +1262,10 @@ reg_t kPalette(EngineState *s, int funct_nr, int argc, reg_t *argv) {
int i, delta, bestindex = -1, bestdelta = 200000;
- for (i = 0; i < s->gfx_state->gfxResMan->getNumberOfColors(); i++) {
- int dr = abs(s->gfx_state->gfxResMan->getStaticPalette()->getColor(i).r - r);
- int dg = abs(s->gfx_state->gfxResMan->getStaticPalette()->getColor(i).g - g);
- int db = abs(s->gfx_state->gfxResMan->getStaticPalette()->getColor(i).b - b);
+ for (i = 0; i < s->gfx_state->gfxResMan->getColorCount(); i++) {
+ int dr = abs(s->gfx_state->gfxResMan->getColor(i).r - r);
+ int dg = abs(s->gfx_state->gfxResMan->getColor(i).g - g);
+ int db = abs(s->gfx_state->gfxResMan->getColor(i).b - b);
delta = dr * dr + dg * dg + db * db;
diff --git a/engines/sci/gfx/gfx_resmgr.cpp b/engines/sci/gfx/gfx_resmgr.cpp
index 6ab69e6ecf..b474a1e36c 100644
--- a/engines/sci/gfx/gfx_resmgr.cpp
+++ b/engines/sci/gfx/gfx_resmgr.cpp
@@ -48,6 +48,27 @@ struct param_struct {
gfx_driver_t *driver;
};
+GfxResManager::GfxResManager(int version, gfx_options_t *options, gfx_driver_t *driver, ResourceManager *resManager) :
+ _version(version), _options(options), _driver(driver), _resManager(resManager),
+ _lockCounter(0), _tagLockCounter(0) {
+ gfxr_init_static_palette();
+
+ if (_version < SCI_VERSION_01_VGA) {
+ _staticPalette = gfx_sci0_pic_colors->getref();
+ } else if (_version == SCI_VERSION_1_1 || _version == SCI_VERSION_32) {
+ GFXDEBUG("Palettes are not yet supported in this SCI version\n");
+ } else {
+ Resource *res = resManager->findResource(kResourceTypePalette, 999, 0);
+ if (res && res->data)
+ _staticPalette = gfxr_read_pal1(res->id, res->data, res->size);
+ }
+}
+
+GfxResManager::~GfxResManager() {
+ _staticPalette->free();
+ delete _staticPalette;
+}
+
#define DRAW_PIC01(pic, picStyle, isSci1) \
gfxr_draw_pic01((pic), flags, default_palette, res->size, res->data, (picStyle), res->id, (isSci1), _staticPalette);
diff --git a/engines/sci/gfx/gfx_resmgr.h b/engines/sci/gfx/gfx_resmgr.h
index 6d303dfaf4..cb18ca5ae7 100644
--- a/engines/sci/gfx/gfx_resmgr.h
+++ b/engines/sci/gfx/gfx_resmgr.h
@@ -102,11 +102,9 @@ struct gfx_resstate_t {
class GfxResManager {
public:
- GfxResManager(int version, gfx_options_t *options, gfx_driver_t *driver, Palette *staticPalette, ResourceManager *resManager) :
- _version(version), _options(options), _driver(driver), _resManager(resManager),
- _staticPalette(staticPalette), _lockCounter(0), _tagLockCounter(0) {}
- ~GfxResManager() {}
+ GfxResManager(int version, gfx_options_t *options, gfx_driver_t *driver, ResourceManager *resManager);
+ ~GfxResManager();
/* Calculates a unique hash value for the specified options/type setup
** Parameters: (gfx_resource_type_t) type: The type the hash is to be generated for
@@ -240,20 +238,17 @@ public:
*/
void freeResManager();
- Palette *getStaticPalette() { return _staticPalette; }
+ const PaletteEntry &getColor(int color) { return _staticPalette->getColor(color); }
void setStaticPalette(Palette *newPalette) {
- freeStaticPalette();
- _staticPalette = newPalette;
- _staticPalette->name = "static palette";
- }
-
- void freeStaticPalette() {
if (_staticPalette)
_staticPalette->free();
+
+ _staticPalette = newPalette;
+ _staticPalette->name = "static palette";
}
- int getNumberOfColors() { return _staticPalette ? _staticPalette->size() : 0; }
+ int getColorCount() { return _staticPalette ? _staticPalette->size() : 0; }
private:
int _version;
diff --git a/engines/sci/gfx/operations.cpp b/engines/sci/gfx/operations.cpp
index 75b57dc4df..8932365dc5 100644
--- a/engines/sci/gfx/operations.cpp
+++ b/engines/sci/gfx/operations.cpp
@@ -414,11 +414,10 @@ static void init_aux_pixmap(gfx_pixmap_t **pixmap) {
(*pixmap)->palette = new Palette(default_colors, DEFAULT_COLORS_NR);
}
-int gfxop_init(gfx_state_t *state, gfx_options_t *options, ResourceManager *resManager,
+int gfxop_init(int version, gfx_state_t *state, gfx_options_t *options, ResourceManager *resManager,
int xfact, int yfact, gfx_color_mode_t bpp) {
int color_depth = bpp ? bpp : 1;
int initialized = 0;
- Palette *staticPalette = NULL; /* Null for dynamic palettes */
BASIC_CHECKS(GFX_FATAL);
@@ -443,19 +442,7 @@ int gfxop_init(gfx_state_t *state, gfx_options_t *options, ResourceManager *resM
if (!initialized)
return GFX_FATAL;
- gfxr_init_static_palette();
-
- if (state->version < SCI_VERSION_01_VGA) {
- staticPalette = gfx_sci0_pic_colors->getref();
- } else if (state->version == SCI_VERSION_1_1 || state->version == SCI_VERSION_32) {
- GFXDEBUG("Palettes are not yet supported in this SCI version\n");
- } else {
- Resource *res = resManager->findResource(kResourceTypePalette, 999, 0);
- if (res && res->data)
- staticPalette = gfxr_read_pal1(res->id, res->data, res->size);
- }
-
- state->gfxResMan = new GfxResManager(state->version, state->options, state->driver, staticPalette, resManager);
+ state->gfxResMan = new GfxResManager(version, state->options, state->driver, resManager);
gfxop_set_clip_zone(state, gfx_rect(0, 0, 320, 200));
diff --git a/engines/sci/gfx/operations.h b/engines/sci/gfx/operations.h
index 30dce1afa0..d88f70724d 100644
--- a/engines/sci/gfx/operations.h
+++ b/engines/sci/gfx/operations.h
@@ -92,8 +92,6 @@ struct gfx_dirty_rect_t {
struct gfx_state_t {
- int version; /* Interpreter version */
-
gfx_options_t *options;
Common::Point pointer_pos; /* Mouse pointer coordinates */
@@ -105,7 +103,6 @@ struct gfx_state_t {
int visible_map;
- //gfx_resstate_t *resstate; /* Resource state */
GfxResManager *gfxResMan;
gfx_pixmap_t *priority_map; /* back buffer priority map (unscaled) */
@@ -139,10 +136,11 @@ struct gfx_state_t {
/* Fundamental operations */
/**************************/
-int gfxop_init(gfx_state_t *state, gfx_options_t *options, ResourceManager *resManager,
+int gfxop_init(int version, gfx_state_t *state, gfx_options_t *options, ResourceManager *resManager,
int xfact = 1, int yfact = 1, gfx_color_mode_t bpp = GFX_COLOR_MODE_INDEX);
/* Initializes a graphics mode
-** Parameters: (gfx_state_t *) state: The state to initialize
+** Parameters: (int) version: The interpreter version
+** (gfx_state_t *) state: The state to initialize
** (int x int) xfact, yfact: Horizontal and vertical scale factors
** (gfx_color_mode_t) bpp: Bytes per pixel to initialize with, or
** 0 (GFX_COLOR_MODE_AUTO) to auto-detect
diff --git a/engines/sci/sci.cpp b/engines/sci/sci.cpp
index cd065d1701..c86d2bfbfb 100644
--- a/engines/sci/sci.cpp
+++ b/engines/sci/sci.cpp
@@ -239,7 +239,6 @@ Common::Error SciEngine::run() {
gfx_crossblit_alpha_threshold = 0x90;
gfx_state_t gfx_state;
gfx_state.driver = &gfx_driver_scummvm;
- gfx_state.version = _resmgr->_sciVersion;
gamestate->port_serial = 0;
gamestate->have_mouse_flag = 1;
@@ -268,7 +267,7 @@ Common::Error SciEngine::run() {
}
// Default config ends
- if (gfxop_init(&gfx_state, &gfx_options, _resmgr)) {
+ if (gfxop_init(_resmgr->_sciVersion, &gfx_state, &gfx_options, _resmgr)) {
fprintf(stderr, "Graphics initialization failed. Aborting...\n");
return Common::kUnknownError;
}
@@ -284,9 +283,9 @@ Common::Error SciEngine::run() {
}
printf("Emulating SCI version %d.%03d.%03d\n",
- SCI_VERSION_MAJOR(gamestate->version),
- SCI_VERSION_MINOR(gamestate->version),
- SCI_VERSION_PATCHLEVEL(gamestate->version));
+ SCI_VERSION_MAJOR(_resmgr->_sciVersion),
+ SCI_VERSION_MINOR(_resmgr->_sciVersion),
+ SCI_VERSION_PATCHLEVEL(_resmgr->_sciVersion));
game_run(&gamestate); // Run the game