- 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
This commit is contained in:
Filippos Karapetis 2009-03-23 08:43:53 +00:00
parent 93ff05cb6d
commit a6f49a636b
6 changed files with 44 additions and 44 deletions

View file

@ -266,10 +266,10 @@ PaletteEntry get_pic_color(EngineState *s, int color) {
if (color == 255) if (color == 255)
return PaletteEntry(255,255,255); return PaletteEntry(255,255,255);
else if (color < s->gfx_state->gfxResMan->getNumberOfColors()) else if (color < s->gfx_state->gfxResMan->getColorCount())
return s->gfx_state->gfxResMan->getStaticPalette()->getColor(color); return s->gfx_state->gfxResMan->getColor(color);
else { 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(); BREAKPOINT();
return PaletteEntry(0,0,0); 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; int i, delta, bestindex = -1, bestdelta = 200000;
for (i = 0; i < s->gfx_state->gfxResMan->getNumberOfColors(); i++) { for (i = 0; i < s->gfx_state->gfxResMan->getColorCount(); i++) {
int dr = abs(s->gfx_state->gfxResMan->getStaticPalette()->getColor(i).r - r); int dr = abs(s->gfx_state->gfxResMan->getColor(i).r - r);
int dg = abs(s->gfx_state->gfxResMan->getStaticPalette()->getColor(i).g - g); int dg = abs(s->gfx_state->gfxResMan->getColor(i).g - g);
int db = abs(s->gfx_state->gfxResMan->getStaticPalette()->getColor(i).b - b); int db = abs(s->gfx_state->gfxResMan->getColor(i).b - b);
delta = dr * dr + dg * dg + db * db; delta = dr * dr + dg * dg + db * db;

View file

@ -48,6 +48,27 @@ struct param_struct {
gfx_driver_t *driver; 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) \ #define DRAW_PIC01(pic, picStyle, isSci1) \
gfxr_draw_pic01((pic), flags, default_palette, res->size, res->data, (picStyle), res->id, (isSci1), _staticPalette); gfxr_draw_pic01((pic), flags, default_palette, res->size, res->data, (picStyle), res->id, (isSci1), _staticPalette);

View file

@ -102,11 +102,9 @@ struct gfx_resstate_t {
class GfxResManager { class GfxResManager {
public: public:
GfxResManager(int version, gfx_options_t *options, gfx_driver_t *driver, Palette *staticPalette, ResourceManager *resManager) : GfxResManager(int version, gfx_options_t *options, gfx_driver_t *driver, ResourceManager *resManager);
_version(version), _options(options), _driver(driver), _resManager(resManager),
_staticPalette(staticPalette), _lockCounter(0), _tagLockCounter(0) {}
~GfxResManager() {}
~GfxResManager();
/* Calculates a unique hash value for the specified options/type setup /* 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 ** Parameters: (gfx_resource_type_t) type: The type the hash is to be generated for
@ -240,20 +238,17 @@ public:
*/ */
void freeResManager(); void freeResManager();
Palette *getStaticPalette() { return _staticPalette; } const PaletteEntry &getColor(int color) { return _staticPalette->getColor(color); }
void setStaticPalette(Palette *newPalette) { void setStaticPalette(Palette *newPalette) {
freeStaticPalette(); if (_staticPalette)
_staticPalette->free();
_staticPalette = newPalette; _staticPalette = newPalette;
_staticPalette->name = "static palette"; _staticPalette->name = "static palette";
} }
void freeStaticPalette() { int getColorCount() { return _staticPalette ? _staticPalette->size() : 0; }
if (_staticPalette)
_staticPalette->free();
}
int getNumberOfColors() { return _staticPalette ? _staticPalette->size() : 0; }
private: private:
int _version; int _version;

View file

@ -414,11 +414,10 @@ static void init_aux_pixmap(gfx_pixmap_t **pixmap) {
(*pixmap)->palette = new Palette(default_colors, DEFAULT_COLORS_NR); (*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 xfact, int yfact, gfx_color_mode_t bpp) {
int color_depth = bpp ? bpp : 1; int color_depth = bpp ? bpp : 1;
int initialized = 0; int initialized = 0;
Palette *staticPalette = NULL; /* Null for dynamic palettes */
BASIC_CHECKS(GFX_FATAL); BASIC_CHECKS(GFX_FATAL);
@ -443,19 +442,7 @@ int gfxop_init(gfx_state_t *state, gfx_options_t *options, ResourceManager *resM
if (!initialized) if (!initialized)
return GFX_FATAL; return GFX_FATAL;
gfxr_init_static_palette(); state->gfxResMan = new GfxResManager(version, state->options, state->driver, resManager);
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);
gfxop_set_clip_zone(state, gfx_rect(0, 0, 320, 200)); gfxop_set_clip_zone(state, gfx_rect(0, 0, 320, 200));

View file

@ -92,8 +92,6 @@ struct gfx_dirty_rect_t {
struct gfx_state_t { struct gfx_state_t {
int version; /* Interpreter version */
gfx_options_t *options; gfx_options_t *options;
Common::Point pointer_pos; /* Mouse pointer coordinates */ Common::Point pointer_pos; /* Mouse pointer coordinates */
@ -105,7 +103,6 @@ struct gfx_state_t {
int visible_map; int visible_map;
//gfx_resstate_t *resstate; /* Resource state */
GfxResManager *gfxResMan; GfxResManager *gfxResMan;
gfx_pixmap_t *priority_map; /* back buffer priority map (unscaled) */ gfx_pixmap_t *priority_map; /* back buffer priority map (unscaled) */
@ -139,10 +136,11 @@ struct gfx_state_t {
/* Fundamental operations */ /* 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); int xfact = 1, int yfact = 1, gfx_color_mode_t bpp = GFX_COLOR_MODE_INDEX);
/* Initializes a graphics mode /* 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 ** (int x int) xfact, yfact: Horizontal and vertical scale factors
** (gfx_color_mode_t) bpp: Bytes per pixel to initialize with, or ** (gfx_color_mode_t) bpp: Bytes per pixel to initialize with, or
** 0 (GFX_COLOR_MODE_AUTO) to auto-detect ** 0 (GFX_COLOR_MODE_AUTO) to auto-detect

View file

@ -239,7 +239,6 @@ Common::Error SciEngine::run() {
gfx_crossblit_alpha_threshold = 0x90; gfx_crossblit_alpha_threshold = 0x90;
gfx_state_t gfx_state; gfx_state_t gfx_state;
gfx_state.driver = &gfx_driver_scummvm; gfx_state.driver = &gfx_driver_scummvm;
gfx_state.version = _resmgr->_sciVersion;
gamestate->port_serial = 0; gamestate->port_serial = 0;
gamestate->have_mouse_flag = 1; gamestate->have_mouse_flag = 1;
@ -268,7 +267,7 @@ Common::Error SciEngine::run() {
} }
// Default config ends // 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"); fprintf(stderr, "Graphics initialization failed. Aborting...\n");
return Common::kUnknownError; return Common::kUnknownError;
} }
@ -284,9 +283,9 @@ Common::Error SciEngine::run() {
} }
printf("Emulating SCI version %d.%03d.%03d\n", printf("Emulating SCI version %d.%03d.%03d\n",
SCI_VERSION_MAJOR(gamestate->version), SCI_VERSION_MAJOR(_resmgr->_sciVersion),
SCI_VERSION_MINOR(gamestate->version), SCI_VERSION_MINOR(_resmgr->_sciVersion),
SCI_VERSION_PATCHLEVEL(gamestate->version)); SCI_VERSION_PATCHLEVEL(_resmgr->_sciVersion));
game_run(&gamestate); // Run the game game_run(&gamestate); // Run the game