[Scummvm-cvs-logs] SF.net SVN: scummvm:[39626] scummvm/trunk/engines/sci

thebluegr at users.sourceforge.net thebluegr at users.sourceforge.net
Mon Mar 23 09:43:53 CET 2009


Revision: 39626
          http://scummvm.svn.sourceforge.net/scummvm/?rev=39626&view=rev
Author:   thebluegr
Date:     2009-03-23 08:43:53 +0000 (Mon, 23 Mar 2009)

Log Message:
-----------
- 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

Modified Paths:
--------------
    scummvm/trunk/engines/sci/engine/kgraphics.cpp
    scummvm/trunk/engines/sci/gfx/gfx_resmgr.cpp
    scummvm/trunk/engines/sci/gfx/gfx_resmgr.h
    scummvm/trunk/engines/sci/gfx/operations.cpp
    scummvm/trunk/engines/sci/gfx/operations.h
    scummvm/trunk/engines/sci/sci.cpp

Modified: scummvm/trunk/engines/sci/engine/kgraphics.cpp
===================================================================
--- scummvm/trunk/engines/sci/engine/kgraphics.cpp	2009-03-23 08:31:14 UTC (rev 39625)
+++ scummvm/trunk/engines/sci/engine/kgraphics.cpp	2009-03-23 08:43:53 UTC (rev 39626)
@@ -266,10 +266,10 @@
 
 	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 @@
 
 		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;
 

Modified: scummvm/trunk/engines/sci/gfx/gfx_resmgr.cpp
===================================================================
--- scummvm/trunk/engines/sci/gfx/gfx_resmgr.cpp	2009-03-23 08:31:14 UTC (rev 39625)
+++ scummvm/trunk/engines/sci/gfx/gfx_resmgr.cpp	2009-03-23 08:43:53 UTC (rev 39626)
@@ -48,6 +48,27 @@
 	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);
 

Modified: scummvm/trunk/engines/sci/gfx/gfx_resmgr.h
===================================================================
--- scummvm/trunk/engines/sci/gfx/gfx_resmgr.h	2009-03-23 08:31:14 UTC (rev 39625)
+++ scummvm/trunk/engines/sci/gfx/gfx_resmgr.h	2009-03-23 08:43:53 UTC (rev 39626)
@@ -102,11 +102,9 @@
 
 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,21 +238,18 @@
 	*/
 	void freeResManager();
 
-	Palette *getStaticPalette() { return _staticPalette; }
+	const PaletteEntry &getColor(int color) { return _staticPalette->getColor(color); }
 
 	void setStaticPalette(Palette *newPalette) {
-		freeStaticPalette();
+		if (_staticPalette)
+			_staticPalette->free();
+
 		_staticPalette = newPalette;
 		_staticPalette->name = "static palette";
 	}
 
-	void freeStaticPalette() { 
-		if (_staticPalette)
-			_staticPalette->free();
-	}
+	int getColorCount() { return _staticPalette ? _staticPalette->size() : 0; }
 
-	int getNumberOfColors() { return _staticPalette ? _staticPalette->size() : 0; }
-
 private:
 	int _version;
 	gfx_options_t *_options;

Modified: scummvm/trunk/engines/sci/gfx/operations.cpp
===================================================================
--- scummvm/trunk/engines/sci/gfx/operations.cpp	2009-03-23 08:31:14 UTC (rev 39625)
+++ scummvm/trunk/engines/sci/gfx/operations.cpp	2009-03-23 08:43:53 UTC (rev 39626)
@@ -414,11 +414,10 @@
 	(*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,20 +442,8 @@
 	if (!initialized)
 		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));
 
 	init_aux_pixmap(&(state->control_map));

Modified: scummvm/trunk/engines/sci/gfx/operations.h
===================================================================
--- scummvm/trunk/engines/sci/gfx/operations.h	2009-03-23 08:31:14 UTC (rev 39625)
+++ scummvm/trunk/engines/sci/gfx/operations.h	2009-03-23 08:43:53 UTC (rev 39626)
@@ -92,8 +92,6 @@
 
 
 struct gfx_state_t {
-	int version; /* Interpreter version */
-
 	gfx_options_t *options;
 
 	Common::Point pointer_pos; /* Mouse pointer coordinates */
@@ -105,7 +103,6 @@
 
 	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 @@
 /* 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

Modified: scummvm/trunk/engines/sci/sci.cpp
===================================================================
--- scummvm/trunk/engines/sci/sci.cpp	2009-03-23 08:31:14 UTC (rev 39625)
+++ scummvm/trunk/engines/sci/sci.cpp	2009-03-23 08:43:53 UTC (rev 39626)
@@ -239,7 +239,6 @@
 	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 @@
 	}
 	// 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 @@
 	}
 
 	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
 


This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.




More information about the Scummvm-git-logs mailing list