Ticket #8987: sci.patch
File sci.patch, 78.8 KB (added by , 16 years ago) |
---|
-
engine/kgraphics.cpp
2350 2350 UKPV(3), UKPV(2)); 2351 2351 // FIXME: Should really only invalidate all loaded pic resources here; 2352 2352 // this is overkill 2353 gfxr_free_all_resources(s->gfx_state-> driver, s->gfx_state->resstate);2353 gfxr_free_all_resources(s->gfx_state->resstate); 2354 2354 2355 2355 break; 2356 2356 } -
engine/scriptdebug.cpp
2011 2011 gfxop_set_pointer_cursor(s->gfx_state, GFXOP_NO_POINTER); 2012 2012 sciprintf("Flushing resources...\n"); 2013 2013 s->visual->widfree(GFXW(s->visual)); 2014 gfxr_free_all_resources(s->gfx_state-> driver, s->gfx_state->resstate);2014 gfxr_free_all_resources(s->gfx_state->resstate); 2015 2015 s->visual = NULL; 2016 2016 2017 2017 return 0; -
gfx/gfx_driver.cpp
94 94 int i; 95 95 if (S) { 96 96 for (i = 0; i < 2; i++) { 97 gfx_free_pixmap( drv,S->priority[i]);97 gfx_free_pixmap(S->priority[i]); 98 98 S->priority[i] = NULL; 99 99 } 100 100 -
gfx/gfx_resmgr.h
114 114 ** The options are considered to be read-only, as they belong to the overlying state object. 115 115 */ 116 116 117 void gfxr_free_resource_manager(gfx_ driver_t *driver, gfx_resstate_t *state);117 void gfxr_free_resource_manager(gfx_resstate_t *state); 118 118 /* Frees a previously allocated resource manager, and all allocated resources. 119 ** Parameters: (gfx_driver_t *) driver: The graphics driver; used to free pixmaps that 120 ** are installed in a driver-specific registry 121 ** (gfx_resstate_t *) state: The state manager to free 119 ** Parameters: (gfx_resstate_t *) state: The state manager to free 122 120 ** Return : (void) 123 121 */ 124 122 125 void gfxr_free_all_resources(gfx_ driver_t *driver, gfx_resstate_t *state);123 void gfxr_free_all_resources(gfx_resstate_t *state); 126 124 /* Frees all resources currently allocated 127 ** Parameter: (gfx_driver_t *) driver: The driver to free with 128 ** (gfx_resstate_t *) state: The state to do this on 125 ** Parameter: (gfx_resstate_t *) state: The state to do this on 129 126 ** Returns : (void) 130 127 ** This function is intended to be used primarily for debugging. 131 128 */ 132 129 133 void gfxr_tag_resources(gfx_resstate_t *state); 134 /* 'Tags' all resources for deletion 135 ** Paramters: (gfx_resstate_t *) state: The resource state to modify 136 ** Returns : (void) 137 ** Tagged resources are untagged if they are referenced. 138 */ 139 140 void gfxr_free_tagged_resources(gfx_driver_t *driver, gfx_resstate_t *state); 130 void gfxr_free_tagged_resources(gfx_resstate_t *state); 141 131 /* Frees all tagged resources. 142 ** Parameters: (gfx_driver_t *) driver: The graphics driver the pixmaps are potentially 143 ** registered in 144 ** (gfx_resstate_t *) state: The state to alter 132 ** Parameters: (gfx_resstate_t *) state: The state to alter 145 133 ** Returns : (void) 146 134 ** Resources are tagged by calling gfx_tag_resources(), and untagged by calling the 147 135 ** approprate dereferenciation function. … … 150 138 */ 151 139 152 140 153 gfxr_pic_t *gfxr_get_pic(gfx_resstate_t *state, int nr, int maps, int flags, 154 int default_palette, int scaled); 155 /* Retreives a displayable (translated) pic resource 156 ** Parameters: (gfx_resstate_t *) state: The resource state 157 ** (int) nr: Number of the pic resource 158 ** (int) maps: The maps to translate (ORred GFX_MASK_*) 159 ** (int) flags: Interpreter-dependant pic flags 160 ** (int) default_palette: The default palette to use for drawing (if applicable) 161 ** (int) scaled: Whether to return the scaled maps, or the unscaled 162 ** ones (which may be identical) for some special operations. 163 ** Returns : (gfx_pic_t *) The appropriate pic resource with all maps as index (but not 164 ** neccessarily translated) data. 165 */ 141 class GfxResManager { 142 public: 143 GfxResManager(gfx_resstate_t *state) : _state(state) {} 144 ~GfxResManager() {} 166 145 146 /* 'Tags' all resources for deletion 147 ** Paramters: (void) 148 ** Returns : (void) 149 ** Tagged resources are untagged if they are referenced. 150 */ 151 void tagResources() { (_state->tag_lock_counter)++; } 152 153 /* Retreives an SCI0/SCI01 mouse cursor 154 ** Parameters: (int) num: The cursor number 155 ** Returns : (gfx_font_t *) The approprate cursor as a pixmap, or NULL on error 156 */ 157 gfx_pixmap_t *getCursor(int num); 158 159 160 /* Retreives the static palette from the interpreter-specific code 161 ** Parameters: (int *) colors_nr: Number of colors to use 162 ** (int) nr: The palette to read 163 ** Returns : (gfx_pixmap_color_t *) *colors_nr static color entries 164 ** if a static palette must be used, NULL otherwise 165 */ 166 Palette *getPalette(int *colors_nr, int num = 999); 167 168 169 /* Retreives a font 170 ** Parameters: (int) nr: The font number 171 ** (int) scaled: Whether the font should be font-scaled 172 ** Returns : (gfx_font_t *) The appropriate font, or NULL on error 173 */ 174 gfx_bitmap_font_t *getFont(int num, bool scaled = false); 175 176 177 /* Retreives a displayable (translated) pic resource 178 ** Parameters: (int) nr: Number of the pic resource 179 ** (int) maps: The maps to translate (ORred GFX_MASK_*) 180 ** (int) flags: Interpreter-dependant pic flags 181 ** (int) default_palette: The default palette to use for drawing (if applicable) 182 ** (bool) scaled: Whether to return the scaled maps, or the unscaled 183 ** ones (which may be identical) for some special operations. 184 ** Returns : (gfx_pic_t *) The appropriate pic resource with all maps as index (but not 185 ** neccessarily translated) data. 186 */ 187 gfxr_pic_t *getPic(int num, int maps, int flags, int default_palette, bool scaled = false); 188 189 190 /* Determines whether support for pointers with more than two colors is required 191 ** Returns : (bool) false if no support for multi-colored pointers is required, true 192 ** otherwise 193 */ 194 bool multicoloredPointers() { return _state->version > SCI_VERSION_1; } 195 196 private: 197 gfx_resstate_t *_state; 198 }; 199 167 200 gfxr_pic_t *gfxr_add_to_pic(gfx_resstate_t *state, int old_nr, int new_nr, int maps, int flags, 168 201 int old_default_palette, int default_palette, int scaled); 169 202 /* Retreives a displayable (translated) pic resource written ontop of an existing pic … … 195 228 ** loop and cel numbers have to be interpreted as 'maximum' or 'minimum' by the interpreter) 196 229 */ 197 230 198 gfx_bitmap_font_t *gfxr_get_font(ResourceManager& resourceManager, gfx_resstate_t *state, int nr, int scaled);199 /* Retreives a font200 ** Parameters: (ResourceManager&) resourceManager: supplies the resource repository capability201 ** (gfx_resstate_t *) state: The relevant resource state202 ** (int) nr: The font number203 ** (int) scaled: Whether the font should be font-scaled204 ** Returns : (gfx_font_t *) The appropriate font, or NULL on error205 */206 207 gfx_pixmap_t *gfxr_get_cursor(gfx_resstate_t *state, int nr);208 /* Retreives an SCI0/SCI01 mouse cursor209 ** Parameters: (gfx_resstate_t *) state: The resource state210 ** (int) nr: The cursour number211 ** Returns : (gfx_font_t *) The approprate cursor as a pixmap, or NULL on error212 */213 214 gfx_pixmap_color_t *gfxr_get_palette(gfx_resstate_t *state, int nr);215 /* Retreives a palette216 ** Parameters: (gfx_resstate_t *) state: The resource state217 ** (int) nr: The cursour number218 ** Returns : (gfx_font_t *) The approprate cursor as a pixmap, or NULL on error219 */220 221 222 231 /* =========================== */ 223 232 /* Interpreter-dependant stuff */ 224 233 /* =========================== */ … … 241 250 ** (Yes, this isn't really a "hash" in the traditional sense...) 242 251 */ 243 252 244 gfxr_pic_t *gfxr_interpreter_init_pic(int version, gfx_mode_t *mode, int ID);245 /* Initializes a pic246 ** Parameters: (int) version: Interpreter version to use247 ** (gfx_mode_t *) mode: The graphics mode the pic will be using248 ** (int) ID: The ID to assign to the gfxr_pic_t structure249 ** Returns : (gfxr_pic_t *) A newly allocated pic250 ** This function is typically called befode gfxr_interpreter_clear_pic().251 */252 253 void gfxr_interpreter_clear_pic(int version, gfxr_pic_t *pic);254 /* Clears a previously allocated pic255 ** Parameters: (int) version: Interpreter version256 ** (gfxr_pic_t *) pic: The pic to clear257 ** Returns : (void)258 ** This function is called in preparation for the pic to be drawn with gfxr_interpreter_calculate_pic.259 */260 261 253 int gfxr_interpreter_calculate_pic(gfx_resstate_t *state, gfxr_pic_t *scaled_pic, gfxr_pic_t *unscaled_pic, 262 254 int flags, int default_palette, int nr); 263 255 /* Instructs the interpreter-specific code to calculate a picture … … 281 273 ** Returns : (gfx_view_t *) The appropriate view, or NULL on error 282 274 */ 283 275 284 gfx_bitmap_font_t *gfxr_interpreter_get_font(ResourceManager& resourceManager, int nr);285 /* Instructs the interpreter-specific code to calculate a font286 ** Parameters: (ResourceManager& ) resourceManager: The resource manager287 ** (int) nr: The font resource number288 ** Returns : (gfx_font_t *) The newly calculated font, or NULL on error289 */290 291 gfx_pixmap_t *gfxr_interpreter_get_cursor(ResourceManager& resourceManager, int nr, int version);292 /* Instructs the interpreter-specific code to calculate a cursor293 ** Parameters: (ResourceManager& ) state: The resource manager294 ** (int nr): The cursor resource number295 ** (int version): The SCI version used296 ** Returns : (gfx_pixmap_t *) The cursor pixmap, or NULL on error297 */298 299 Palette *gfxr_interpreter_get_static_palette(ResourceManager& resourceManager, int version, int *colors_nr);300 /* Retreives the static palette (palette 999) from the interpreter-specific code301 ** Parameters: (ResourceManager& ) state: The resource manager302 ** (int) version: Interpreter version to use303 ** (int *) colors_nr: Number of colors to use304 ** Returns : (gfx_pixmap_color_t *) *colors_nr static color entries305 ** if a static palette must be used, NULL otherwise306 */307 308 Palette *gfxr_interpreter_get_palette(ResourceManager& resourceManager, int version, int *colors_nr, int nr);309 /* Retreives the static palette from the interpreter-specific code310 ** Parameters: (ResourceManager& ) state: The resource manager311 ** (int) version: Interpreter version to use312 ** (int *) colors_nr: Number of colors to use313 ** (int) nr: The palette to read314 ** Returns : (gfx_pixmap_color_t *) *colors_nr static color entries315 ** if a static palette must be used, NULL otherwise316 */317 318 int gfxr_interpreter_needs_multicolored_pointers(int version);319 /* Determines whether support for pointers with more than two colors is required320 ** Parameters: (int) version: Interpreter version to test for321 ** Returns : (int) 0 if no support for multi-colored pointers is required, non-0322 ** otherwise323 */324 325 276 } // End of namespace Sci 326 277 327 278 #endif // SCI_GFX_GFX_RSMGR_H -
gfx/gfx_resource.cpp
40 40 }; 41 41 42 42 43 static void gfxr_free_loop(gfx _driver_t *driver, gfxr_loop_t *loop) {43 static void gfxr_free_loop(gfxr_loop_t *loop) { 44 44 int i; 45 45 46 46 if (loop->cels) { 47 47 for (i = 0; i < loop->cels_nr; i++) 48 48 if (loop->cels[i]) 49 gfx_free_pixmap( driver,loop->cels[i]);49 gfx_free_pixmap(loop->cels[i]); 50 50 51 51 free(loop->cels); 52 52 } 53 53 } 54 54 55 void gfxr_free_view(gfx _driver_t *driver, gfxr_view_t *view) {55 void gfxr_free_view(gfxr_view_t *view) { 56 56 int i; 57 57 58 58 if (view->palette) … … 60 60 61 61 if (view->loops) { 62 62 for (i = 0; i < view->loops_nr; i++) 63 gfxr_free_loop( driver,view->loops + i);63 gfxr_free_loop(view->loops + i); 64 64 65 65 free(view->loops); 66 66 } … … 393 393 } 394 394 } 395 395 396 void gfxr_free_pic(gfx _driver_t *driver, gfxr_pic_t *pic) {397 gfx_free_pixmap( driver,pic->visual_map);398 gfx_free_pixmap( driver,pic->priority_map);399 gfx_free_pixmap( driver,pic->control_map);396 void gfxr_free_pic(gfxr_pic_t *pic) { 397 gfx_free_pixmap(pic->visual_map); 398 gfx_free_pixmap(pic->priority_map); 399 gfx_free_pixmap(pic->control_map); 400 400 pic->visual_map = NULL; 401 401 pic->priority_map = NULL; 402 402 pic->control_map = NULL; -
gfx/gfx_resource.h
140 140 ** This function allocates memory for use by resource drawer functions. 141 141 */ 142 142 143 void gfxr_free_pic(gfx _driver_t *driver, gfxr_pic_t *pic);143 void gfxr_free_pic(gfxr_pic_t *pic); 144 144 /* Uninitializes a pic resource 145 ** Parameters: (gfx_driver_t *) driver: The driver the pic should be removed from 146 ** (gfxr_pic_t *) pic: The pic to free 145 ** Parameters: (gfxr_pic_t *) pic: The pic to free 147 146 ** Returns : (void) 148 147 */ 149 148 150 void gfxr_free_view(gfx _driver_t *driver, gfxr_view_t *view);149 void gfxr_free_view(gfxr_view_t *view); 151 150 /* Frees all memory associated with a view 152 ** Paremeters: (gfx_driver_t *) driver: The driver the view should be removed from 153 ** (gfxr_view_t *) view: The view to free 151 ** Paremeters: (gfxr_view_t *) view: The view to free 154 152 ** Returns : (void) 155 153 */ 156 154 -
gfx/gfx_tools.cpp
81 81 if (mode->palette) 82 82 mode->palette->free(); 83 83 free(mode); 84 mode = NULL; 84 85 } 85 86 86 87 void gfx_copy_pixmap_box_i(gfx_pixmap_t *dest, gfx_pixmap_t *src, rect_t box) { … … 146 147 return pxm; 147 148 } 148 149 149 void gfx_free_pixmap(gfx_driver_t *driver, gfx_pixmap_t *pxm) { 150 if (driver) { 151 if (driver->mode->palette) { 152 if (pxm->palette) 153 pxm->palette->free(); 154 } 155 } 150 void gfx_free_pixmap(gfx_pixmap_t *pxm) { 151 if (pxm->palette) 152 pxm->palette->free(); 156 153 157 154 free(pxm->index_data); 158 155 free(pxm->alpha_map); -
gfx/gfx_tools.h
118 118 ** Returns : (gfx_pixmap_t *) pixmap 119 119 */ 120 120 121 void gfx_free_pixmap(gfx_ driver_t *driver, gfx_pixmap_t *pxm);121 void gfx_free_pixmap(gfx_pixmap_t *pxm); 122 122 /* Frees all memory associated with a pixmap 123 ** Parameters: (gfx_driver_t *) driver: The driver the pixmap is to be removed from 124 ** (gfx_pixmap_t *) pxm: The pixmap to free 123 ** Parameters: (gfx_pixmap_t *) pxm: The pixmap to free 125 124 ** Returns : (void) 126 125 */ 127 126 -
gfx/operations.cpp
433 433 return GFX_FATAL; 434 434 } 435 435 436 int size; 437 state->static_palette = gfxr_interpreter_get_static_palette(*(state->resstate->resManager), state->version, &size); 436 state->static_palette = NULL; 438 437 438 if (state->version < SCI_VERSION_01_VGA) { 439 state->static_palette = gfx_sci0_pic_colors->getref(); 440 } else if (state->version == SCI_VERSION_1_1 || state->version == SCI_VERSION_32) { 441 GFXDEBUG("Palettes are not yet supported in this SCI version\n"); 442 } else { 443 Resource *res = state->resstate->resManager->findResource(kResourceTypePalette, 999, 0); 444 if (res && res->data) 445 state->static_palette = gfxr_read_pal1(res->id, res->data, res->size); 446 } 447 439 448 state->visible_map = GFX_MASK_VISUAL; 440 449 state->fullscreen_override = NULL; // No magical override 441 450 gfxop_set_clip_zone(state, gfx_rect(0, 0, 320, 200)); … … 495 504 496 505 int gfxop_exit(gfx_state_t *state) { 497 506 BASIC_CHECKS(GFX_ERROR); 498 gfxr_free_resource_manager(state-> driver, state->resstate);507 gfxr_free_resource_manager(state->resstate); 499 508 500 509 if (state->control_map) { 501 gfx_free_pixmap(state-> driver, state->control_map);510 gfx_free_pixmap(state->control_map); 502 511 state->control_map = NULL; 503 512 } 504 513 505 514 if (state->priority_map) { 506 gfx_free_pixmap(state-> driver, state->priority_map);515 gfx_free_pixmap(state->priority_map); 507 516 state->priority_map = NULL; 508 517 } 509 518 510 519 if (state->static_priority_map) { 511 gfx_free_pixmap(state-> driver, state->static_priority_map);520 gfx_free_pixmap(state->static_priority_map); 512 521 state->static_priority_map = NULL; 513 522 } 514 523 … … 1162 1171 1163 1172 if (state->tag_mode) { 1164 1173 // This usually happens after a pic and all resources have been drawn 1165 gfxr_free_tagged_resources(state-> driver, state->resstate);1174 gfxr_free_tagged_resources(state->resstate); 1166 1175 state->tag_mode = 0; 1167 1176 } 1168 1177 … … 1237 1246 if (nr == GFXOP_NO_POINTER) 1238 1247 new_pointer = NULL; 1239 1248 else { 1240 new_pointer = gfxr_get_cursor(state->resstate, nr); 1249 // FIXME: the initialization of the GFX resource manager should 1250 // be pushed up, and it shouldn't occur here 1251 GfxResManager *_gfx = new GfxResManager(state->resstate); 1252 new_pointer = _gfx->getCursor(nr); 1253 delete _gfx; 1241 1254 1242 1255 if (!new_pointer) { 1243 1256 GFXWARN("Attempt to set invalid pointer #%d\n", nr); … … 1848 1861 int gfxop_new_pic(gfx_state_t *state, int nr, int flags, int default_palette) { 1849 1862 BASIC_CHECKS(GFX_FATAL); 1850 1863 1851 gfxr_tag_resources(state->resstate); 1864 // FIXME: the initialization of the GFX resource manager should 1865 // be pushed up, and it shouldn't occur here 1866 GfxResManager *_gfx = new GfxResManager(state->resstate); 1867 _gfx->tagResources(); 1852 1868 state->tag_mode = 1; 1853 1869 state->palette_nr = default_palette; 1870 state->pic = _gfx->getPic(nr, GFX_MASK_VISUAL, flags, default_palette, true); 1871 delete _gfx; 1854 1872 1855 state->pic = gfxr_get_pic(state->resstate, nr, GFX_MASK_VISUAL, flags, default_palette, 1); 1856 1857 if (state->driver->mode->xfact == 1 && state->driver->mode->yfact == 1) 1873 if (state->driver->mode->xfact == 1 && state->driver->mode->yfact == 1) { 1858 1874 state->pic_unscaled = state->pic; 1859 else 1860 state->pic_unscaled = gfxr_get_pic(state->resstate, nr, GFX_MASK_VISUAL, flags, default_palette, 0); 1875 } else { 1876 // FIXME: the initialization of the GFX resource manager should 1877 // be pushed up, and it shouldn't occur here 1878 GfxResManager *_gfx = new GfxResManager(state->resstate); 1879 state->pic = _gfx->getPic(nr, GFX_MASK_VISUAL, flags, default_palette, false); 1880 delete _gfx; 1881 } 1861 1882 1862 1883 if (!state->pic || !state->pic_unscaled) { 1863 1884 GFXERROR("Could not retrieve background pic %d!\n", nr); … … 1904 1925 gfx_bitmap_font_t *font; 1905 1926 BASIC_CHECKS(GFX_FATAL); 1906 1927 1907 font = gfxr_get_font(*(state->resstate->resManager), state->resstate, font_nr, 0); 1928 // FIXME: the initialization of the GFX resource manager should 1929 // be pushed up, and it shouldn't occur here 1930 GfxResManager *_gfx = new GfxResManager(state->resstate); 1931 font = _gfx->getFont(font_nr); 1932 delete _gfx; 1933 1908 1934 if (!font) 1909 1935 return GFX_ERROR; 1910 1936 … … 1918 1944 1919 1945 BASIC_CHECKS(GFX_FATAL); 1920 1946 1921 font = gfxr_get_font(*(state->resstate->resManager), state->resstate, font_nr, 0); 1947 // FIXME: the initialization of the GFX resource manager should 1948 // be pushed up, and it shouldn't occur here 1949 GfxResManager *_gfx = new GfxResManager(state->resstate); 1950 font = _gfx->getFont(font_nr); 1951 delete _gfx; 1922 1952 1923 1953 if (!font) { 1924 1954 GFXERROR("Attempt to calculate text size with invalid font #%d\n", font_nr); … … 1956 1986 return NULL; 1957 1987 } 1958 1988 1959 font = gfxr_get_font(*(state->resstate->resManager), state->resstate, font_nr, 0); 1989 // FIXME: the initialization of the GFX resource manager should 1990 // be pushed up, and it shouldn't occur here 1991 GfxResManager *_gfx = new GfxResManager(state->resstate); 1992 font = _gfx->getFont(font_nr); 1993 delete _gfx; 1960 1994 1961 1995 if (!font) { 1962 1996 GFXERROR("Attempt to draw text with invalid font #%d\n", font_nr); … … 2001 2035 int j; 2002 2036 2003 2037 for (j = 0; j < i; j++) 2004 gfx_free_pixmap( state->driver,handle->text_pixmaps[j]);2038 gfx_free_pixmap(handle->text_pixmaps[j]); 2005 2039 2006 2040 free(handle->text_pixmaps); 2007 2041 free(handle->text); … … 2027 2061 2028 2062 if (handle->text_pixmaps) { 2029 2063 for (j = 0; j < handle->lines_nr; j++) 2030 gfx_free_pixmap( state->driver,handle->text_pixmaps[j]);2064 gfx_free_pixmap(handle->text_pixmaps[j]); 2031 2065 free(handle->text_pixmaps); 2032 2066 } 2033 2067 … … 2167 2201 2168 2202 int gfxop_free_pixmap(gfx_state_t *state, gfx_pixmap_t *pxm) { 2169 2203 BASIC_CHECKS(GFX_ERROR); 2170 gfx_free_pixmap( state->driver,pxm);2204 gfx_free_pixmap(pxm); 2171 2205 return GFX_OK; 2172 2206 } 2173 2207 -
gfx/resmgr.cpp
40 40 41 41 namespace Sci { 42 42 43 #undef TIME_PICDRAWING44 45 43 // Invalid hash mode: Used to invalidate modified pics 46 44 #define MODE_INVALID -1 47 45 … … 66 64 67 65 #define FREEALL(freecmd, type) \ 68 66 if (resource->scaled_data.type) \ 69 freecmd(driver, resource->scaled_data.type); \70 resource->scaled_data.type = NULL; \71 if (resource->unscaled_data.type) \72 freecmd(driver, resource->unscaled_data.type); \73 resource->unscaled_data.type = NULL;74 75 #define FREEALL_SIMPLE(freecmd, type) \76 if (resource->scaled_data.type) \77 67 freecmd(resource->scaled_data.type); \ 78 68 resource->scaled_data.type = NULL; \ 79 69 if (resource->unscaled_data.type) \ 80 70 freecmd(resource->unscaled_data.type); \ 81 71 resource->unscaled_data.type = NULL; 82 72 83 void gfxr_free_resource(gfx_ driver_t *driver, gfx_resource_t *resource, int type) {73 void gfxr_free_resource(gfx_resource_t *resource, int type) { 84 74 if (!resource) 85 75 return; 86 76 … … 95 85 break; 96 86 97 87 case GFX_RESOURCE_TYPE_FONT: 98 FREEALL _SIMPLE(gfxr_free_font, font);88 FREEALL(gfxr_free_font, font); 99 89 break; 100 90 101 91 case GFX_RESOURCE_TYPE_CURSOR: … … 109 99 free(resource); 110 100 } 111 101 112 void gfxr_free_all_resources(gfx_ driver_t *driver, gfx_resstate_t *state) {102 void gfxr_free_all_resources(gfx_resstate_t *state) { 113 103 for (int type = 0; type < GFX_RESOURCE_TYPES_NR; ++type) { 114 104 for (IntResMap::iterator iter = state->_resourceMaps[type].begin(); iter != state->_resourceMaps[type].end(); ++iter) { 115 gfxr_free_resource( driver,iter->_value, type);105 gfxr_free_resource(iter->_value, type); 116 106 iter->_value = 0; 117 107 } 118 108 } 119 109 } 120 110 121 void gfxr_free_resource_manager(gfx_ driver_t *driver, gfx_resstate_t *state) {122 gfxr_free_all_resources( driver,state);111 void gfxr_free_resource_manager(gfx_resstate_t *state) { 112 gfxr_free_all_resources(state); 123 113 delete state; 124 114 } 125 115 126 void gfxr_tag_resources(gfx_resstate_t *state) { 127 (state->tag_lock_counter)++; 128 } 129 130 void gfxr_free_tagged_resources(gfx_driver_t *driver, gfx_resstate_t *state) { 116 void gfxr_free_tagged_resources(gfx_resstate_t *state) { 131 117 // Current heuristics: free tagged views and old pics 132 118 133 119 IntResMap::iterator iter; … … 140 126 141 127 if (resource) { 142 128 if (resource->lock_sequence_nr < tmp) { 143 gfxr_free_resource( driver,resource, type);129 gfxr_free_resource(resource, type); 144 130 iter->_value = 0; 145 131 } else { 146 132 resource->lock_sequence_nr = 0; … … 154 140 155 141 if (resource) { 156 142 if (resource->lock_sequence_nr < 0) { 157 gfxr_free_resource( driver,resource, type);143 gfxr_free_resource(resource, type); 158 144 iter->_value = 0; 159 145 } else { 160 146 resource->lock_sequence_nr--; … … 191 177 } 192 178 #undef XLATE_AS_APPROPRIATE 193 179 194 gfxr_pic_t * gfxr_get_pic(gfx_resstate_t *state, int nr, int maps, int flags, int default_palette, intscaled) {180 gfxr_pic_t *GfxResManager::getPic(int num, int maps, int flags, int default_palette, bool scaled) { 195 181 gfxr_pic_t *npic = NULL; 196 182 gfx_resource_type_t restype = GFX_RESOURCE_TYPE_PIC; 197 IntResMap &resMap = state->_resourceMaps[restype];183 IntResMap &resMap = _state->_resourceMaps[restype]; 198 184 gfx_resource_t *res = NULL; 199 int hash = gfxr_interpreter_options_hash(restype, state->version,state->options, 0);185 int hash = gfxr_interpreter_options_hash(restype, _state->version, _state->options, 0); 200 186 int must_post_process_pic = 0; 201 int need_unscaled = ( state->driver->mode->xfact != 1 ||state->driver->mode->yfact != 1);187 int need_unscaled = (_state->driver->mode->xfact != 1 || _state->driver->mode->yfact != 1); 202 188 203 189 hash |= (flags << 20) | ((default_palette & 0x7) << 28); 204 190 205 res = resMap.contains(n r) ? resMap[nr] : NULL;191 res = resMap.contains(num) ? resMap[num] : NULL; 206 192 207 193 if (!res || res->mode != hash) { 208 194 gfxr_pic_t *pic; 209 195 gfxr_pic_t *unscaled_pic = NULL; 210 196 211 if ( state->options->pic0_unscaled) {197 if (_state->options->pic0_unscaled) { 212 198 need_unscaled = 0; 213 pic = gfxr_in terpreter_init_pic(state->version, &mode_1x1_color_index, GFXR_RES_ID(restype, nr));199 pic = gfxr_init_pic(&mode_1x1_color_index, GFXR_RES_ID(restype, num), _state->version >= SCI_VERSION_01_VGA); 214 200 } else 215 pic = gfxr_interpreter_init_pic(state->version, state->driver->mode, GFXR_RES_ID(restype, nr)); 216 201 pic = gfxr_init_pic(_state->driver->mode, GFXR_RES_ID(restype, num), _state->version >= SCI_VERSION_01_VGA); 217 202 if (!pic) { 218 203 GFXERROR("Failed to allocate scaled pic!\n"); 219 204 return NULL; 220 205 } 221 206 222 gfxr_ interpreter_clear_pic(state->version, pic);207 gfxr_clear_pic0(pic, SCI_TITLEBAR_SIZE); 223 208 224 209 if (need_unscaled) { 225 unscaled_pic = gfxr_in terpreter_init_pic(state->version, &mode_1x1_color_index, GFXR_RES_ID(restype, nr));210 unscaled_pic = gfxr_init_pic(&mode_1x1_color_index, GFXR_RES_ID(restype, num), _state->version >= SCI_VERSION_01_VGA); 226 211 if (!unscaled_pic) { 227 212 GFXERROR("Failed to allocate unscaled pic!\n"); 228 213 return NULL; 229 214 } 230 gfxr_ interpreter_clear_pic(state->version, unscaled_pic);215 gfxr_clear_pic0(pic, SCI_TITLEBAR_SIZE); 231 216 } 232 #ifdef TIME_PICDRAWING 233 { 234 uint32 start_msec, end_msec; 235 start_msec = g_system->getMillis(); 236 #endif 237 if (gfxr_interpreter_calculate_pic(state, pic, unscaled_pic, flags, default_palette, nr)) { 238 gfxr_free_pic(state->driver, pic); 239 if (unscaled_pic) 240 gfxr_free_pic(state->driver, unscaled_pic); 241 242 return NULL; 243 } 244 #ifdef TIME_PICDRAWING 245 end_msec = g_system->getMillis(); 246 printf("\nTIME: %d ms for drawing pic.%03d\n", end_msec - start_msec, nr); 217 if (gfxr_interpreter_calculate_pic(_state, pic, unscaled_pic, flags, default_palette, num)) { 218 gfxr_free_pic(pic); 219 if (unscaled_pic) 220 gfxr_free_pic(unscaled_pic); 221 return NULL; 247 222 } 248 #endif249 250 223 if (!res) { 251 224 res = (gfx_resource_t *)sci_malloc(sizeof(gfx_resource_t)); 252 res->ID = GFXR_RES_ID(restype, n r);253 res->lock_sequence_nr = state->options->buffer_pics_nr;254 resMap[n r] = res;225 res->ID = GFXR_RES_ID(restype, num); 226 res->lock_sequence_nr = _state->options->buffer_pics_nr; 227 resMap[num] = res; 255 228 } else { 256 gfxr_free_pic( state->driver,res->scaled_data.pic);229 gfxr_free_pic(res->scaled_data.pic); 257 230 if (res->unscaled_data.pic) 258 gfxr_free_pic( state->driver,res->unscaled_data.pic);231 gfxr_free_pic(res->unscaled_data.pic); 259 232 } 260 233 261 234 res->mode = hash; 262 235 res->scaled_data.pic = pic; 263 236 res->unscaled_data.pic = unscaled_pic; 264 237 } else { 265 res->lock_sequence_nr = state->options->buffer_pics_nr; // Update lock counter238 res->lock_sequence_nr = _state->options->buffer_pics_nr; // Update lock counter 266 239 } 267 240 268 241 must_post_process_pic = res->scaled_data.pic->visual_map->data == NULL; 269 242 // If the pic was only just drawn, we'll have to endianness-adjust it now 270 243 271 npic = gfxr_pic_xlate_common(res, maps, scaled || state->options->pic0_unscaled, 0,state->driver->mode,272 state->options->pic_xlate_filter, 0,state->options);244 npic = gfxr_pic_xlate_common(res, maps, scaled || _state->options->pic0_unscaled, 0, _state->driver->mode, 245 _state->options->pic_xlate_filter, 0, _state->options); 273 246 274 247 275 248 if (must_post_process_pic) { 276 gfxr_endianness_adjust(npic->visual_map, state->driver->mode);249 gfxr_endianness_adjust(npic->visual_map, _state->driver->mode); 277 250 } 278 251 279 252 return npic; … … 338 311 res = resMap.contains(old_nr) ? resMap[old_nr] : NULL; 339 312 340 313 if (!res || (res->mode != MODE_INVALID && res->mode != hash)) { 341 gfxr_get_pic(state, old_nr, 0, flags, old_default_palette, scaled); 314 // FIXME: the initialization of the GFX resource manager should 315 // be pushed up, and it shouldn't occur here 316 GfxResManager *_gfx = new GfxResManager(state); 317 _gfx->getPic(old_nr, 0, flags, old_default_palette, scaled); 318 delete _gfx; 342 319 343 320 res = resMap.contains(old_nr) ? resMap[old_nr] : NULL; 344 321 … … 398 375 res->mode = hash; 399 376 resMap[nr] = res; 400 377 } else { 401 gfxr_free_view( state->driver,res->unscaled_data.view);378 gfxr_free_view(res->unscaled_data.view); 402 379 } 403 380 404 381 res->mode = hash; … … 453 430 return view; 454 431 } 455 432 456 gfx_bitmap_font_t * gfxr_get_font(ResourceManager& resourceManager, gfx_resstate_t *state, int nr, intscaled) {433 gfx_bitmap_font_t *GfxResManager::getFont(int num, bool scaled) { 457 434 gfx_resource_type_t restype = GFX_RESOURCE_TYPE_FONT; 458 IntResMap &resMap = state->_resourceMaps[restype];435 IntResMap &resMap = _state->_resourceMaps[restype]; 459 436 gfx_resource_t *res = NULL; 460 437 int hash; 461 438 462 hash = gfxr_interpreter_options_hash(restype, state->version,state->options, 0);439 hash = gfxr_interpreter_options_hash(restype, _state->version, _state->options, 0); 463 440 464 res = resMap.contains(n r) ? resMap[nr] : NULL;441 res = resMap.contains(num) ? resMap[num] : NULL; 465 442 466 443 if (!res || res->mode != hash) { 467 gfx_bitmap_font_t *font = gfxr_interpreter_get_font(resourceManager, nr); 468 469 if (!font) 444 Resource *fontRes = _state->resManager->findResource(kResourceTypeFont, num, 0); 445 if (!fontRes || !fontRes->data) 470 446 return NULL; 471 447 448 gfx_bitmap_font_t *font = gfxr_read_font(fontRes->id, fontRes->data, fontRes->size); 449 472 450 if (!res) { 473 451 res = (gfx_resource_t *)sci_malloc(sizeof(gfx_resource_t)); 474 452 res->scaled_data.font = NULL; 475 res->ID = GFXR_RES_ID(restype, n r);476 res->lock_sequence_nr = state->tag_lock_counter;453 res->ID = GFXR_RES_ID(restype, num); 454 res->lock_sequence_nr = _state->tag_lock_counter; 477 455 res->mode = hash; 478 resMap[n r] = res;456 resMap[num] = res; 479 457 } else { 480 458 gfxr_free_font(res->unscaled_data.font); 481 459 } … … 484 462 485 463 return font; 486 464 } else { 487 res->lock_sequence_nr = state->tag_lock_counter; // Update lock counter465 res->lock_sequence_nr = _state->tag_lock_counter; // Update lock counter 488 466 if (res->unscaled_data.pointer) 489 467 return res->unscaled_data.font; 490 468 else … … 492 470 } 493 471 } 494 472 495 gfx_pixmap_t * gfxr_get_cursor(gfx_resstate_t *state, int nr) {473 gfx_pixmap_t *GfxResManager::getCursor(int num) { 496 474 gfx_resource_type_t restype = GFX_RESOURCE_TYPE_CURSOR; 497 IntResMap &resMap = state->_resourceMaps[restype];475 IntResMap &resMap = _state->_resourceMaps[restype]; 498 476 gfx_resource_t *res = NULL; 499 int hash = gfxr_interpreter_options_hash(restype, state->version,state->options, 0);477 int hash = gfxr_interpreter_options_hash(restype, _state->version, _state->options, 0); 500 478 501 res = resMap.contains(n r) ? resMap[nr] : NULL;479 res = resMap.contains(num) ? resMap[num] : NULL; 502 480 503 481 if (!res || res->mode != hash) { 504 gfx_pixmap_t *cursor = gfxr_interpreter_get_cursor(*(state->resManager), nr, state->version); 482 Resource *cursorRes = _state->resManager->findResource(kResourceTypeCursor, num, 0); 483 if (!cursorRes || !cursorRes->data) 484 return NULL; 505 485 486 if (_state->version >= SCI_VERSION_1_1) { 487 GFXWARN("Attempt to retrieve cursor in SCI1.1 or later\n"); 488 return NULL; 489 } 490 491 gfx_pixmap_t *cursor = gfxr_draw_cursor(GFXR_RES_ID(GFX_RESOURCE_TYPE_CURSOR, num), 492 cursorRes->data, cursorRes->size, _state->version != SCI_VERSION_0); 493 506 494 if (!cursor) 507 495 return NULL; 508 496 509 497 if (!res) { 510 498 res = (gfx_resource_t *)sci_malloc(sizeof(gfx_resource_t)); 511 499 res->scaled_data.pointer = NULL; 512 res->ID = GFXR_RES_ID(restype, n r);513 res->lock_sequence_nr = state->tag_lock_counter;500 res->ID = GFXR_RES_ID(restype, num); 501 res->lock_sequence_nr = _state->tag_lock_counter; 514 502 res->mode = hash; 515 resMap[n r] = res;503 resMap[num] = res; 516 504 } else { 517 gfx_free_pixmap( state->driver,res->unscaled_data.pointer);505 gfx_free_pixmap(res->unscaled_data.pointer); 518 506 } 519 gfx_get_res_config( state->options, cursor);520 gfx_xlate_pixmap(cursor, state->driver->mode,state->options->cursor_xlate_filter);521 gfxr_endianness_adjust(cursor, state->driver->mode);507 gfx_get_res_config(_state->options, cursor); 508 gfx_xlate_pixmap(cursor, _state->driver->mode, _state->options->cursor_xlate_filter); 509 gfxr_endianness_adjust(cursor, _state->driver->mode); 522 510 523 511 res->unscaled_data.pointer = cursor; 524 512 525 513 return cursor; 526 514 } else { 527 res->lock_sequence_nr = state->tag_lock_counter; // Update lock counter515 res->lock_sequence_nr = _state->tag_lock_counter; // Update lock counter 528 516 return res->unscaled_data.pointer; 529 517 } 530 518 } -
gfx/resource/res_manager.cpp
49 49 | (options->pic0_dither_pattern << 8) | (options->pic0_brush_mode << 4) | (options->pic0_line_mode); 50 50 51 51 case GFX_RESOURCE_TYPE_FONT: 52 return 0;53 54 52 case GFX_RESOURCE_TYPE_CURSOR: 55 53 return 0; 56 54 … … 61 59 } 62 60 } 63 61 64 gfxr_pic_t *gfxr_interpreter_init_pic(int version, gfx_mode_t *mode, int ID) {65 return gfxr_init_pic(mode, ID, version >= SCI_VERSION_01_VGA);66 }67 68 void gfxr_interpreter_clear_pic(int version, gfxr_pic_t *pic) {69 gfxr_clear_pic0(pic, SCI_TITLEBAR_SIZE);70 }71 72 62 int gfxr_interpreter_calculate_pic(gfx_resstate_t *state, gfxr_pic_t *scaled_pic, gfxr_pic_t *unscaled_pic, 73 63 int flags, int default_palette, int nr) { 74 64 ResourceManager& resourceManager = *(state->resManager); … … 152 142 153 143 if (version < SCI_VERSION_01) palette = -1; 154 144 155 switch (version) { 156 case SCI_VERSION_0: 157 case SCI_VERSION_01: 145 if (version <= SCI_VERSION_01) 158 146 result = gfxr_draw_view0(resid, res->data, res->size, palette); 159 break; 160 case SCI_VERSION_01_VGA: 161 case SCI_VERSION_01_VGA_ODD: 162 case SCI_VERSION_1_EARLY: 163 case SCI_VERSION_1_LATE: 147 else if (version >= SCI_VERSION_01_VGA && version <= SCI_VERSION_1_LATE) 164 148 result = gfxr_draw_view1(resid, res->data, res->size, staticPalette); 165 break; 166 case SCI_VERSION_1_1: 167 case SCI_VERSION_32: 149 else if (version >= SCI_VERSION_1_1) 168 150 result = gfxr_draw_view11(resid, res->data, res->size); 169 break;170 }171 151 172 152 if (version >= SCI_VERSION_01_VGA) { 173 153 if (!result->palette) { … … 179 159 return result; 180 160 } 181 161 182 gfx_bitmap_font_t *gfxr_interpreter_get_font(ResourceManager& resourceManager, int nr) {183 Resource *res = resourceManager.findResource(kResourceTypeFont, nr, 0);184 if (!res || !res->data)185 return NULL;186 187 return gfxr_read_font(res->id, res->data, res->size);188 }189 190 gfx_pixmap_t *gfxr_interpreter_get_cursor(ResourceManager& resourceManager, int nr, int version) {191 Resource *res = resourceManager.findResource(kResourceTypeCursor, nr, 0);192 int resid = GFXR_RES_ID(GFX_RESOURCE_TYPE_CURSOR, nr);193 194 if (!res || !res->data)195 return NULL;196 197 if (version >= SCI_VERSION_1_1) {198 GFXWARN("Attempt to retrieve cursor in SCI1.1 or later\n");199 return NULL;200 }201 202 return gfxr_draw_cursor(resid, res->data, res->size, version != SCI_VERSION_0);203 }204 205 Palette *gfxr_interpreter_get_static_palette(ResourceManager& resourceManager, int version, int *colors_nr) {206 if (version >= SCI_VERSION_01_VGA)207 return gfxr_interpreter_get_palette(resourceManager, version, colors_nr, 999);208 209 *colors_nr = GFX_SCI0_PIC_COLORS_NR;210 return gfx_sci0_pic_colors->getref();211 }212 213 Palette *gfxr_interpreter_get_palette(ResourceManager& resourceManager, int version, int *colors_nr, int nr) {214 Resource *res;215 216 if (version < SCI_VERSION_01_VGA)217 return NULL;218 219 res = resourceManager.findResource(kResourceTypePalette, nr, 0);220 if (!res || !res->data)221 return NULL;222 223 switch (version) {224 case SCI_VERSION_01_VGA :225 case SCI_VERSION_01_VGA_ODD :226 case SCI_VERSION_1_EARLY :227 case SCI_VERSION_1_LATE :228 return gfxr_read_pal1(res->id, res->data, res->size);229 case SCI_VERSION_1_1 :230 case SCI_VERSION_32 :231 GFXDEBUG("Palettes are not yet supported in this SCI version\n");232 return NULL;233 234 default:235 BREAKPOINT();236 return NULL;237 }238 }239 240 int gfxr_interpreter_needs_multicolored_pointers(int version) {241 return (version > SCI_VERSION_1);242 }243 244 162 } // End of namespace Sci -
gfx/resource/res_pic.cpp
1699 1699 1700 1700 gfx_xlate_pixmap(view, mode, GFX_XLATE_FILTER_NONE); 1701 1701 gfx_free_mode(mode); 1702 // When the mode is freed, the associated view 1703 // palette is freed too, so set it to NULL 1704 view->palette = NULL; 1702 1705 1703 1706 if (flags & DRAWPIC01_FLAG_OVERLAID_PIC) 1704 1707 view_transparentize(view, pic->visual_map, posx, sci_titlebar_size + posy, … … 1708 1711 view->index_data, pic->visual_map->index_width, view->index_width, 1709 1712 view->index_width, view->index_height, 1); 1710 1713 1711 gfx_free_pixmap(NULL, view); 1714 gfx_free_pixmap(view); 1715 view = NULL; 1712 1716 } 1713 1717 goto end_op_loop; 1714 1718 -
gfx/resource/res_view0.cpp
57 57 } 58 58 59 59 if (xl <= 0 || yl <= 0) { 60 gfx_free_pixmap( NULL,retval);60 gfx_free_pixmap(retval); 61 61 GFXERROR("View %02x:(%d/%d) has invalid xl=%d or yl=%d\n", id, loop, cel, xl, yl); 62 62 return NULL; 63 63 } … … 218 218 if (error_token || gfxr_draw_loop0(view->loops + i, id, i, resource, loop_offset, size, view, mirrored)) { 219 219 // An error occured 220 220 view->loops_nr = i; 221 gfxr_free_view( NULL,view);221 gfxr_free_view(view); 222 222 return NULL; 223 223 } 224 224 } -
gfx/resource/res_view1.cpp
246 246 247 247 if (view) 248 248 retval->palette = view->palette->getref(); 249 else 250 retval->palette = NULL; 249 251 250 252 if (xl <= 0 || yl <= 0) { 251 gfx_free_pixmap( NULL,retval);253 gfx_free_pixmap(retval); 252 254 GFXERROR("View %02x:(%d/%d) has invalid xl=%d or yl=%d\n", id, loop, cel, xl, yl); 253 255 return NULL; 254 256 } … … 261 263 pos, xl, yl, retval->color_key); 262 264 263 265 if (decompress_failed) { 264 gfx_free_pixmap( NULL,retval);266 gfx_free_pixmap(retval); 265 267 return NULL; 266 268 } 267 269 … … 381 383 if (error_token || gfxr_draw_loop1(view->loops + i, id, i, mirror_mask & (1 << i), resource, loop_offset, size, view, amiga_game)) { 382 384 // An error occured 383 385 view->loops_nr = i; 384 gfxr_free_view( NULL,view);386 gfxr_free_view(view); 385 387 return NULL; 386 388 } 387 389 } … … 429 431 retval->palette = view->palette->getref(); 430 432 431 433 if (xl <= 0 || yl <= 0) { 432 gfx_free_pixmap( NULL,retval);434 gfx_free_pixmap(retval); 433 435 GFXERROR("View %02x:(%d/%d) has invalid xl=%d or yl=%d\n", id, loop, cel, xl, yl); 434 436 return NULL; 435 437 } … … 438 440 runlength_offset, literal_offset, xl, yl, retval->color_key); 439 441 440 442 if (decompress_failed) { 441 gfx_free_pixmap( NULL,retval);443 gfx_free_pixmap(retval); 442 444 return NULL; 443 445 } 444 446 -
engine/kgraphics.cpp
2350 2350 UKPV(3), UKPV(2)); 2351 2351 // FIXME: Should really only invalidate all loaded pic resources here; 2352 2352 // this is overkill 2353 gfxr_free_all_resources(s->gfx_state-> driver, s->gfx_state->resstate);2353 gfxr_free_all_resources(s->gfx_state->resstate); 2354 2354 2355 2355 break; 2356 2356 } -
engine/scriptdebug.cpp
2011 2011 gfxop_set_pointer_cursor(s->gfx_state, GFXOP_NO_POINTER); 2012 2012 sciprintf("Flushing resources...\n"); 2013 2013 s->visual->widfree(GFXW(s->visual)); 2014 gfxr_free_all_resources(s->gfx_state-> driver, s->gfx_state->resstate);2014 gfxr_free_all_resources(s->gfx_state->resstate); 2015 2015 s->visual = NULL; 2016 2016 2017 2017 return 0; -
gfx/gfx_driver.cpp
94 94 int i; 95 95 if (S) { 96 96 for (i = 0; i < 2; i++) { 97 gfx_free_pixmap( drv,S->priority[i]);97 gfx_free_pixmap(S->priority[i]); 98 98 S->priority[i] = NULL; 99 99 } 100 100 -
gfx/gfx_resmgr.h
114 114 ** The options are considered to be read-only, as they belong to the overlying state object. 115 115 */ 116 116 117 void gfxr_free_resource_manager(gfx_ driver_t *driver, gfx_resstate_t *state);117 void gfxr_free_resource_manager(gfx_resstate_t *state); 118 118 /* Frees a previously allocated resource manager, and all allocated resources. 119 ** Parameters: (gfx_driver_t *) driver: The graphics driver; used to free pixmaps that 120 ** are installed in a driver-specific registry 121 ** (gfx_resstate_t *) state: The state manager to free 119 ** Parameters: (gfx_resstate_t *) state: The state manager to free 122 120 ** Return : (void) 123 121 */ 124 122 125 void gfxr_free_all_resources(gfx_ driver_t *driver, gfx_resstate_t *state);123 void gfxr_free_all_resources(gfx_resstate_t *state); 126 124 /* Frees all resources currently allocated 127 ** Parameter: (gfx_driver_t *) driver: The driver to free with 128 ** (gfx_resstate_t *) state: The state to do this on 125 ** Parameter: (gfx_resstate_t *) state: The state to do this on 129 126 ** Returns : (void) 130 127 ** This function is intended to be used primarily for debugging. 131 128 */ 132 129 133 void gfxr_tag_resources(gfx_resstate_t *state); 134 /* 'Tags' all resources for deletion 135 ** Paramters: (gfx_resstate_t *) state: The resource state to modify 136 ** Returns : (void) 137 ** Tagged resources are untagged if they are referenced. 138 */ 139 140 void gfxr_free_tagged_resources(gfx_driver_t *driver, gfx_resstate_t *state); 130 void gfxr_free_tagged_resources(gfx_resstate_t *state); 141 131 /* Frees all tagged resources. 142 ** Parameters: (gfx_driver_t *) driver: The graphics driver the pixmaps are potentially 143 ** registered in 144 ** (gfx_resstate_t *) state: The state to alter 132 ** Parameters: (gfx_resstate_t *) state: The state to alter 145 133 ** Returns : (void) 146 134 ** Resources are tagged by calling gfx_tag_resources(), and untagged by calling the 147 135 ** approprate dereferenciation function. … … 150 138 */ 151 139 152 140 153 gfxr_pic_t *gfxr_get_pic(gfx_resstate_t *state, int nr, int maps, int flags, 154 int default_palette, int scaled); 155 /* Retreives a displayable (translated) pic resource 156 ** Parameters: (gfx_resstate_t *) state: The resource state 157 ** (int) nr: Number of the pic resource 158 ** (int) maps: The maps to translate (ORred GFX_MASK_*) 159 ** (int) flags: Interpreter-dependant pic flags 160 ** (int) default_palette: The default palette to use for drawing (if applicable) 161 ** (int) scaled: Whether to return the scaled maps, or the unscaled 162 ** ones (which may be identical) for some special operations. 163 ** Returns : (gfx_pic_t *) The appropriate pic resource with all maps as index (but not 164 ** neccessarily translated) data. 165 */ 141 class GfxResManager { 142 public: 143 GfxResManager(gfx_resstate_t *state) : _state(state) {} 144 ~GfxResManager() {} 166 145 146 /* 'Tags' all resources for deletion 147 ** Paramters: (void) 148 ** Returns : (void) 149 ** Tagged resources are untagged if they are referenced. 150 */ 151 void tagResources() { (_state->tag_lock_counter)++; } 152 153 /* Retreives an SCI0/SCI01 mouse cursor 154 ** Parameters: (int) num: The cursor number 155 ** Returns : (gfx_font_t *) The approprate cursor as a pixmap, or NULL on error 156 */ 157 gfx_pixmap_t *getCursor(int num); 158 159 160 /* Retreives the static palette from the interpreter-specific code 161 ** Parameters: (int *) colors_nr: Number of colors to use 162 ** (int) nr: The palette to read 163 ** Returns : (gfx_pixmap_color_t *) *colors_nr static color entries 164 ** if a static palette must be used, NULL otherwise 165 */ 166 Palette *getPalette(int *colors_nr, int num = 999); 167 168 169 /* Retreives a font 170 ** Parameters: (int) nr: The font number 171 ** (int) scaled: Whether the font should be font-scaled 172 ** Returns : (gfx_font_t *) The appropriate font, or NULL on error 173 */ 174 gfx_bitmap_font_t *getFont(int num, bool scaled = false); 175 176 177 /* Retreives a displayable (translated) pic resource 178 ** Parameters: (int) nr: Number of the pic resource 179 ** (int) maps: The maps to translate (ORred GFX_MASK_*) 180 ** (int) flags: Interpreter-dependant pic flags 181 ** (int) default_palette: The default palette to use for drawing (if applicable) 182 ** (bool) scaled: Whether to return the scaled maps, or the unscaled 183 ** ones (which may be identical) for some special operations. 184 ** Returns : (gfx_pic_t *) The appropriate pic resource with all maps as index (but not 185 ** neccessarily translated) data. 186 */ 187 gfxr_pic_t *getPic(int num, int maps, int flags, int default_palette, bool scaled = false); 188 189 190 /* Determines whether support for pointers with more than two colors is required 191 ** Returns : (bool) false if no support for multi-colored pointers is required, true 192 ** otherwise 193 */ 194 bool multicoloredPointers() { return _state->version > SCI_VERSION_1; } 195 196 private: 197 gfx_resstate_t *_state; 198 }; 199 167 200 gfxr_pic_t *gfxr_add_to_pic(gfx_resstate_t *state, int old_nr, int new_nr, int maps, int flags, 168 201 int old_default_palette, int default_palette, int scaled); 169 202 /* Retreives a displayable (translated) pic resource written ontop of an existing pic … … 195 228 ** loop and cel numbers have to be interpreted as 'maximum' or 'minimum' by the interpreter) 196 229 */ 197 230 198 gfx_bitmap_font_t *gfxr_get_font(ResourceManager& resourceManager, gfx_resstate_t *state, int nr, int scaled);199 /* Retreives a font200 ** Parameters: (ResourceManager&) resourceManager: supplies the resource repository capability201 ** (gfx_resstate_t *) state: The relevant resource state202 ** (int) nr: The font number203 ** (int) scaled: Whether the font should be font-scaled204 ** Returns : (gfx_font_t *) The appropriate font, or NULL on error205 */206 207 gfx_pixmap_t *gfxr_get_cursor(gfx_resstate_t *state, int nr);208 /* Retreives an SCI0/SCI01 mouse cursor209 ** Parameters: (gfx_resstate_t *) state: The resource state210 ** (int) nr: The cursour number211 ** Returns : (gfx_font_t *) The approprate cursor as a pixmap, or NULL on error212 */213 214 gfx_pixmap_color_t *gfxr_get_palette(gfx_resstate_t *state, int nr);215 /* Retreives a palette216 ** Parameters: (gfx_resstate_t *) state: The resource state217 ** (int) nr: The cursour number218 ** Returns : (gfx_font_t *) The approprate cursor as a pixmap, or NULL on error219 */220 221 222 231 /* =========================== */ 223 232 /* Interpreter-dependant stuff */ 224 233 /* =========================== */ … … 241 250 ** (Yes, this isn't really a "hash" in the traditional sense...) 242 251 */ 243 252 244 gfxr_pic_t *gfxr_interpreter_init_pic(int version, gfx_mode_t *mode, int ID);245 /* Initializes a pic246 ** Parameters: (int) version: Interpreter version to use247 ** (gfx_mode_t *) mode: The graphics mode the pic will be using248 ** (int) ID: The ID to assign to the gfxr_pic_t structure249 ** Returns : (gfxr_pic_t *) A newly allocated pic250 ** This function is typically called befode gfxr_interpreter_clear_pic().251 */252 253 void gfxr_interpreter_clear_pic(int version, gfxr_pic_t *pic);254 /* Clears a previously allocated pic255 ** Parameters: (int) version: Interpreter version256 ** (gfxr_pic_t *) pic: The pic to clear257 ** Returns : (void)258 ** This function is called in preparation for the pic to be drawn with gfxr_interpreter_calculate_pic.259 */260 261 253 int gfxr_interpreter_calculate_pic(gfx_resstate_t *state, gfxr_pic_t *scaled_pic, gfxr_pic_t *unscaled_pic, 262 254 int flags, int default_palette, int nr); 263 255 /* Instructs the interpreter-specific code to calculate a picture … … 281 273 ** Returns : (gfx_view_t *) The appropriate view, or NULL on error 282 274 */ 283 275 284 gfx_bitmap_font_t *gfxr_interpreter_get_font(ResourceManager& resourceManager, int nr);285 /* Instructs the interpreter-specific code to calculate a font286 ** Parameters: (ResourceManager& ) resourceManager: The resource manager287 ** (int) nr: The font resource number288 ** Returns : (gfx_font_t *) The newly calculated font, or NULL on error289 */290 291 gfx_pixmap_t *gfxr_interpreter_get_cursor(ResourceManager& resourceManager, int nr, int version);292 /* Instructs the interpreter-specific code to calculate a cursor293 ** Parameters: (ResourceManager& ) state: The resource manager294 ** (int nr): The cursor resource number295 ** (int version): The SCI version used296 ** Returns : (gfx_pixmap_t *) The cursor pixmap, or NULL on error297 */298 299 Palette *gfxr_interpreter_get_static_palette(ResourceManager& resourceManager, int version, int *colors_nr);300 /* Retreives the static palette (palette 999) from the interpreter-specific code301 ** Parameters: (ResourceManager& ) state: The resource manager302 ** (int) version: Interpreter version to use303 ** (int *) colors_nr: Number of colors to use304 ** Returns : (gfx_pixmap_color_t *) *colors_nr static color entries305 ** if a static palette must be used, NULL otherwise306 */307 308 Palette *gfxr_interpreter_get_palette(ResourceManager& resourceManager, int version, int *colors_nr, int nr);309 /* Retreives the static palette from the interpreter-specific code310 ** Parameters: (ResourceManager& ) state: The resource manager311 ** (int) version: Interpreter version to use312 ** (int *) colors_nr: Number of colors to use313 ** (int) nr: The palette to read314 ** Returns : (gfx_pixmap_color_t *) *colors_nr static color entries315 ** if a static palette must be used, NULL otherwise316 */317 318 int gfxr_interpreter_needs_multicolored_pointers(int version);319 /* Determines whether support for pointers with more than two colors is required320 ** Parameters: (int) version: Interpreter version to test for321 ** Returns : (int) 0 if no support for multi-colored pointers is required, non-0322 ** otherwise323 */324 325 276 } // End of namespace Sci 326 277 327 278 #endif // SCI_GFX_GFX_RSMGR_H -
gfx/gfx_resource.cpp
40 40 }; 41 41 42 42 43 static void gfxr_free_loop(gfx _driver_t *driver, gfxr_loop_t *loop) {43 static void gfxr_free_loop(gfxr_loop_t *loop) { 44 44 int i; 45 45 46 46 if (loop->cels) { 47 47 for (i = 0; i < loop->cels_nr; i++) 48 48 if (loop->cels[i]) 49 gfx_free_pixmap( driver,loop->cels[i]);49 gfx_free_pixmap(loop->cels[i]); 50 50 51 51 free(loop->cels); 52 52 } 53 53 } 54 54 55 void gfxr_free_view(gfx _driver_t *driver, gfxr_view_t *view) {55 void gfxr_free_view(gfxr_view_t *view) { 56 56 int i; 57 57 58 58 if (view->palette) … … 60 60 61 61 if (view->loops) { 62 62 for (i = 0; i < view->loops_nr; i++) 63 gfxr_free_loop( driver,view->loops + i);63 gfxr_free_loop(view->loops + i); 64 64 65 65 free(view->loops); 66 66 } … … 393 393 } 394 394 } 395 395 396 void gfxr_free_pic(gfx _driver_t *driver, gfxr_pic_t *pic) {397 gfx_free_pixmap( driver,pic->visual_map);398 gfx_free_pixmap( driver,pic->priority_map);399 gfx_free_pixmap( driver,pic->control_map);396 void gfxr_free_pic(gfxr_pic_t *pic) { 397 gfx_free_pixmap(pic->visual_map); 398 gfx_free_pixmap(pic->priority_map); 399 gfx_free_pixmap(pic->control_map); 400 400 pic->visual_map = NULL; 401 401 pic->priority_map = NULL; 402 402 pic->control_map = NULL; -
gfx/gfx_resource.h
140 140 ** This function allocates memory for use by resource drawer functions. 141 141 */ 142 142 143 void gfxr_free_pic(gfx _driver_t *driver, gfxr_pic_t *pic);143 void gfxr_free_pic(gfxr_pic_t *pic); 144 144 /* Uninitializes a pic resource 145 ** Parameters: (gfx_driver_t *) driver: The driver the pic should be removed from 146 ** (gfxr_pic_t *) pic: The pic to free 145 ** Parameters: (gfxr_pic_t *) pic: The pic to free 147 146 ** Returns : (void) 148 147 */ 149 148 150 void gfxr_free_view(gfx _driver_t *driver, gfxr_view_t *view);149 void gfxr_free_view(gfxr_view_t *view); 151 150 /* Frees all memory associated with a view 152 ** Paremeters: (gfx_driver_t *) driver: The driver the view should be removed from 153 ** (gfxr_view_t *) view: The view to free 151 ** Paremeters: (gfxr_view_t *) view: The view to free 154 152 ** Returns : (void) 155 153 */ 156 154 -
gfx/gfx_tools.cpp
81 81 if (mode->palette) 82 82 mode->palette->free(); 83 83 free(mode); 84 mode = NULL; 84 85 } 85 86 86 87 void gfx_copy_pixmap_box_i(gfx_pixmap_t *dest, gfx_pixmap_t *src, rect_t box) { … … 146 147 return pxm; 147 148 } 148 149 149 void gfx_free_pixmap(gfx_driver_t *driver, gfx_pixmap_t *pxm) { 150 if (driver) { 151 if (driver->mode->palette) { 152 if (pxm->palette) 153 pxm->palette->free(); 154 } 155 } 150 void gfx_free_pixmap(gfx_pixmap_t *pxm) { 151 if (pxm->palette) 152 pxm->palette->free(); 156 153 157 154 free(pxm->index_data); 158 155 free(pxm->alpha_map); -
gfx/gfx_tools.h
118 118 ** Returns : (gfx_pixmap_t *) pixmap 119 119 */ 120 120 121 void gfx_free_pixmap(gfx_ driver_t *driver, gfx_pixmap_t *pxm);121 void gfx_free_pixmap(gfx_pixmap_t *pxm); 122 122 /* Frees all memory associated with a pixmap 123 ** Parameters: (gfx_driver_t *) driver: The driver the pixmap is to be removed from 124 ** (gfx_pixmap_t *) pxm: The pixmap to free 123 ** Parameters: (gfx_pixmap_t *) pxm: The pixmap to free 125 124 ** Returns : (void) 126 125 */ 127 126 -
gfx/operations.cpp
433 433 return GFX_FATAL; 434 434 } 435 435 436 int size; 437 state->static_palette = gfxr_interpreter_get_static_palette(*(state->resstate->resManager), state->version, &size); 436 state->static_palette = NULL; 438 437 438 if (state->version < SCI_VERSION_01_VGA) { 439 state->static_palette = gfx_sci0_pic_colors->getref(); 440 } else if (state->version == SCI_VERSION_1_1 || state->version == SCI_VERSION_32) { 441 GFXDEBUG("Palettes are not yet supported in this SCI version\n"); 442 } else { 443 Resource *res = state->resstate->resManager->findResource(kResourceTypePalette, 999, 0); 444 if (res && res->data) 445 state->static_palette = gfxr_read_pal1(res->id, res->data, res->size); 446 } 447 439 448 state->visible_map = GFX_MASK_VISUAL; 440 449 state->fullscreen_override = NULL; // No magical override 441 450 gfxop_set_clip_zone(state, gfx_rect(0, 0, 320, 200)); … … 495 504 496 505 int gfxop_exit(gfx_state_t *state) { 497 506 BASIC_CHECKS(GFX_ERROR); 498 gfxr_free_resource_manager(state-> driver, state->resstate);507 gfxr_free_resource_manager(state->resstate); 499 508 500 509 if (state->control_map) { 501 gfx_free_pixmap(state-> driver, state->control_map);510 gfx_free_pixmap(state->control_map); 502 511 state->control_map = NULL; 503 512 } 504 513 505 514 if (state->priority_map) { 506 gfx_free_pixmap(state-> driver, state->priority_map);515 gfx_free_pixmap(state->priority_map); 507 516 state->priority_map = NULL; 508 517 } 509 518 510 519 if (state->static_priority_map) { 511 gfx_free_pixmap(state-> driver, state->static_priority_map);520 gfx_free_pixmap(state->static_priority_map); 512 521 state->static_priority_map = NULL; 513 522 } 514 523 … … 1162 1171 1163 1172 if (state->tag_mode) { 1164 1173 // This usually happens after a pic and all resources have been drawn 1165 gfxr_free_tagged_resources(state-> driver, state->resstate);1174 gfxr_free_tagged_resources(state->resstate); 1166 1175 state->tag_mode = 0; 1167 1176 } 1168 1177 … … 1237 1246 if (nr == GFXOP_NO_POINTER) 1238 1247 new_pointer = NULL; 1239 1248 else { 1240 new_pointer = gfxr_get_cursor(state->resstate, nr); 1249 // FIXME: the initialization of the GFX resource manager should 1250 // be pushed up, and it shouldn't occur here 1251 GfxResManager *_gfx = new GfxResManager(state->resstate); 1252 new_pointer = _gfx->getCursor(nr); 1253 delete _gfx; 1241 1254 1242 1255 if (!new_pointer) { 1243 1256 GFXWARN("Attempt to set invalid pointer #%d\n", nr); … … 1848 1861 int gfxop_new_pic(gfx_state_t *state, int nr, int flags, int default_palette) { 1849 1862 BASIC_CHECKS(GFX_FATAL); 1850 1863 1851 gfxr_tag_resources(state->resstate); 1864 // FIXME: the initialization of the GFX resource manager should 1865 // be pushed up, and it shouldn't occur here 1866 GfxResManager *_gfx = new GfxResManager(state->resstate); 1867 _gfx->tagResources(); 1852 1868 state->tag_mode = 1; 1853 1869 state->palette_nr = default_palette; 1870 state->pic = _gfx->getPic(nr, GFX_MASK_VISUAL, flags, default_palette, true); 1871 delete _gfx; 1854 1872 1855 state->pic = gfxr_get_pic(state->resstate, nr, GFX_MASK_VISUAL, flags, default_palette, 1); 1856 1857 if (state->driver->mode->xfact == 1 && state->driver->mode->yfact == 1) 1873 if (state->driver->mode->xfact == 1 && state->driver->mode->yfact == 1) { 1858 1874 state->pic_unscaled = state->pic; 1859 else 1860 state->pic_unscaled = gfxr_get_pic(state->resstate, nr, GFX_MASK_VISUAL, flags, default_palette, 0); 1875 } else { 1876 // FIXME: the initialization of the GFX resource manager should 1877 // be pushed up, and it shouldn't occur here 1878 GfxResManager *_gfx = new GfxResManager(state->resstate); 1879 state->pic = _gfx->getPic(nr, GFX_MASK_VISUAL, flags, default_palette, false); 1880 delete _gfx; 1881 } 1861 1882 1862 1883 if (!state->pic || !state->pic_unscaled) { 1863 1884 GFXERROR("Could not retrieve background pic %d!\n", nr); … … 1904 1925 gfx_bitmap_font_t *font; 1905 1926 BASIC_CHECKS(GFX_FATAL); 1906 1927 1907 font = gfxr_get_font(*(state->resstate->resManager), state->resstate, font_nr, 0); 1928 // FIXME: the initialization of the GFX resource manager should 1929 // be pushed up, and it shouldn't occur here 1930 GfxResManager *_gfx = new GfxResManager(state->resstate); 1931 font = _gfx->getFont(font_nr); 1932 delete _gfx; 1933 1908 1934 if (!font) 1909 1935 return GFX_ERROR; 1910 1936 … … 1918 1944 1919 1945 BASIC_CHECKS(GFX_FATAL); 1920 1946 1921 font = gfxr_get_font(*(state->resstate->resManager), state->resstate, font_nr, 0); 1947 // FIXME: the initialization of the GFX resource manager should 1948 // be pushed up, and it shouldn't occur here 1949 GfxResManager *_gfx = new GfxResManager(state->resstate); 1950 font = _gfx->getFont(font_nr); 1951 delete _gfx; 1922 1952 1923 1953 if (!font) { 1924 1954 GFXERROR("Attempt to calculate text size with invalid font #%d\n", font_nr); … … 1956 1986 return NULL; 1957 1987 } 1958 1988 1959 font = gfxr_get_font(*(state->resstate->resManager), state->resstate, font_nr, 0); 1989 // FIXME: the initialization of the GFX resource manager should 1990 // be pushed up, and it shouldn't occur here 1991 GfxResManager *_gfx = new GfxResManager(state->resstate); 1992 font = _gfx->getFont(font_nr); 1993 delete _gfx; 1960 1994 1961 1995 if (!font) { 1962 1996 GFXERROR("Attempt to draw text with invalid font #%d\n", font_nr); … … 2001 2035 int j; 2002 2036 2003 2037 for (j = 0; j < i; j++) 2004 gfx_free_pixmap( state->driver,handle->text_pixmaps[j]);2038 gfx_free_pixmap(handle->text_pixmaps[j]); 2005 2039 2006 2040 free(handle->text_pixmaps); 2007 2041 free(handle->text); … … 2027 2061 2028 2062 if (handle->text_pixmaps) { 2029 2063 for (j = 0; j < handle->lines_nr; j++) 2030 gfx_free_pixmap( state->driver,handle->text_pixmaps[j]);2064 gfx_free_pixmap(handle->text_pixmaps[j]); 2031 2065 free(handle->text_pixmaps); 2032 2066 } 2033 2067 … … 2167 2201 2168 2202 int gfxop_free_pixmap(gfx_state_t *state, gfx_pixmap_t *pxm) { 2169 2203 BASIC_CHECKS(GFX_ERROR); 2170 gfx_free_pixmap( state->driver,pxm);2204 gfx_free_pixmap(pxm); 2171 2205 return GFX_OK; 2172 2206 } 2173 2207 -
gfx/resmgr.cpp
40 40 41 41 namespace Sci { 42 42 43 #undef TIME_PICDRAWING44 45 43 // Invalid hash mode: Used to invalidate modified pics 46 44 #define MODE_INVALID -1 47 45 … … 66 64 67 65 #define FREEALL(freecmd, type) \ 68 66 if (resource->scaled_data.type) \ 69 freecmd(driver, resource->scaled_data.type); \70 resource->scaled_data.type = NULL; \71 if (resource->unscaled_data.type) \72 freecmd(driver, resource->unscaled_data.type); \73 resource->unscaled_data.type = NULL;74 75 #define FREEALL_SIMPLE(freecmd, type) \76 if (resource->scaled_data.type) \77 67 freecmd(resource->scaled_data.type); \ 78 68 resource->scaled_data.type = NULL; \ 79 69 if (resource->unscaled_data.type) \ 80 70 freecmd(resource->unscaled_data.type); \ 81 71 resource->unscaled_data.type = NULL; 82 72 83 void gfxr_free_resource(gfx_ driver_t *driver, gfx_resource_t *resource, int type) {73 void gfxr_free_resource(gfx_resource_t *resource, int type) { 84 74 if (!resource) 85 75 return; 86 76 … … 95 85 break; 96 86 97 87 case GFX_RESOURCE_TYPE_FONT: 98 FREEALL _SIMPLE(gfxr_free_font, font);88 FREEALL(gfxr_free_font, font); 99 89 break; 100 90 101 91 case GFX_RESOURCE_TYPE_CURSOR: … … 109 99 free(resource); 110 100 } 111 101 112 void gfxr_free_all_resources(gfx_ driver_t *driver, gfx_resstate_t *state) {102 void gfxr_free_all_resources(gfx_resstate_t *state) { 113 103 for (int type = 0; type < GFX_RESOURCE_TYPES_NR; ++type) { 114 104 for (IntResMap::iterator iter = state->_resourceMaps[type].begin(); iter != state->_resourceMaps[type].end(); ++iter) { 115 gfxr_free_resource( driver,iter->_value, type);105 gfxr_free_resource(iter->_value, type); 116 106 iter->_value = 0; 117 107 } 118 108 } 119 109 } 120 110 121 void gfxr_free_resource_manager(gfx_ driver_t *driver, gfx_resstate_t *state) {122 gfxr_free_all_resources( driver,state);111 void gfxr_free_resource_manager(gfx_resstate_t *state) { 112 gfxr_free_all_resources(state); 123 113 delete state; 124 114 } 125 115 126 void gfxr_tag_resources(gfx_resstate_t *state) { 127 (state->tag_lock_counter)++; 128 } 129 130 void gfxr_free_tagged_resources(gfx_driver_t *driver, gfx_resstate_t *state) { 116 void gfxr_free_tagged_resources(gfx_resstate_t *state) { 131 117 // Current heuristics: free tagged views and old pics 132 118 133 119 IntResMap::iterator iter; … … 140 126 141 127 if (resource) { 142 128 if (resource->lock_sequence_nr < tmp) { 143 gfxr_free_resource( driver,resource, type);129 gfxr_free_resource(resource, type); 144 130 iter->_value = 0; 145 131 } else { 146 132 resource->lock_sequence_nr = 0; … … 154 140 155 141 if (resource) { 156 142 if (resource->lock_sequence_nr < 0) { 157 gfxr_free_resource( driver,resource, type);143 gfxr_free_resource(resource, type); 158 144 iter->_value = 0; 159 145 } else { 160 146 resource->lock_sequence_nr--; … … 191 177 } 192 178 #undef XLATE_AS_APPROPRIATE 193 179 194 gfxr_pic_t * gfxr_get_pic(gfx_resstate_t *state, int nr, int maps, int flags, int default_palette, intscaled) {180 gfxr_pic_t *GfxResManager::getPic(int num, int maps, int flags, int default_palette, bool scaled) { 195 181 gfxr_pic_t *npic = NULL; 196 182 gfx_resource_type_t restype = GFX_RESOURCE_TYPE_PIC; 197 IntResMap &resMap = state->_resourceMaps[restype];183 IntResMap &resMap = _state->_resourceMaps[restype]; 198 184 gfx_resource_t *res = NULL; 199 int hash = gfxr_interpreter_options_hash(restype, state->version,state->options, 0);185 int hash = gfxr_interpreter_options_hash(restype, _state->version, _state->options, 0); 200 186 int must_post_process_pic = 0; 201 int need_unscaled = ( state->driver->mode->xfact != 1 ||state->driver->mode->yfact != 1);187 int need_unscaled = (_state->driver->mode->xfact != 1 || _state->driver->mode->yfact != 1); 202 188 203 189 hash |= (flags << 20) | ((default_palette & 0x7) << 28); 204 190 205 res = resMap.contains(n r) ? resMap[nr] : NULL;191 res = resMap.contains(num) ? resMap[num] : NULL; 206 192 207 193 if (!res || res->mode != hash) { 208 194 gfxr_pic_t *pic; 209 195 gfxr_pic_t *unscaled_pic = NULL; 210 196 211 if ( state->options->pic0_unscaled) {197 if (_state->options->pic0_unscaled) { 212 198 need_unscaled = 0; 213 pic = gfxr_in terpreter_init_pic(state->version, &mode_1x1_color_index, GFXR_RES_ID(restype, nr));199 pic = gfxr_init_pic(&mode_1x1_color_index, GFXR_RES_ID(restype, num), _state->version >= SCI_VERSION_01_VGA); 214 200 } else 215 pic = gfxr_interpreter_init_pic(state->version, state->driver->mode, GFXR_RES_ID(restype, nr)); 216 201 pic = gfxr_init_pic(_state->driver->mode, GFXR_RES_ID(restype, num), _state->version >= SCI_VERSION_01_VGA); 217 202 if (!pic) { 218 203 GFXERROR("Failed to allocate scaled pic!\n"); 219 204 return NULL; 220 205 } 221 206 222 gfxr_ interpreter_clear_pic(state->version, pic);207 gfxr_clear_pic0(pic, SCI_TITLEBAR_SIZE); 223 208 224 209 if (need_unscaled) { 225 unscaled_pic = gfxr_in terpreter_init_pic(state->version, &mode_1x1_color_index, GFXR_RES_ID(restype, nr));210 unscaled_pic = gfxr_init_pic(&mode_1x1_color_index, GFXR_RES_ID(restype, num), _state->version >= SCI_VERSION_01_VGA); 226 211 if (!unscaled_pic) { 227 212 GFXERROR("Failed to allocate unscaled pic!\n"); 228 213 return NULL; 229 214 } 230 gfxr_ interpreter_clear_pic(state->version, unscaled_pic);215 gfxr_clear_pic0(pic, SCI_TITLEBAR_SIZE); 231 216 } 232 #ifdef TIME_PICDRAWING 233 { 234 uint32 start_msec, end_msec; 235 start_msec = g_system->getMillis(); 236 #endif 237 if (gfxr_interpreter_calculate_pic(state, pic, unscaled_pic, flags, default_palette, nr)) { 238 gfxr_free_pic(state->driver, pic); 239 if (unscaled_pic) 240 gfxr_free_pic(state->driver, unscaled_pic); 241 242 return NULL; 243 } 244 #ifdef TIME_PICDRAWING 245 end_msec = g_system->getMillis(); 246 printf("\nTIME: %d ms for drawing pic.%03d\n", end_msec - start_msec, nr); 217 if (gfxr_interpreter_calculate_pic(_state, pic, unscaled_pic, flags, default_palette, num)) { 218 gfxr_free_pic(pic); 219 if (unscaled_pic) 220 gfxr_free_pic(unscaled_pic); 221 return NULL; 247 222 } 248 #endif249 250 223 if (!res) { 251 224 res = (gfx_resource_t *)sci_malloc(sizeof(gfx_resource_t)); 252 res->ID = GFXR_RES_ID(restype, n r);253 res->lock_sequence_nr = state->options->buffer_pics_nr;254 resMap[n r] = res;225 res->ID = GFXR_RES_ID(restype, num); 226 res->lock_sequence_nr = _state->options->buffer_pics_nr; 227 resMap[num] = res; 255 228 } else { 256 gfxr_free_pic( state->driver,res->scaled_data.pic);229 gfxr_free_pic(res->scaled_data.pic); 257 230 if (res->unscaled_data.pic) 258 gfxr_free_pic( state->driver,res->unscaled_data.pic);231 gfxr_free_pic(res->unscaled_data.pic); 259 232 } 260 233 261 234 res->mode = hash; 262 235 res->scaled_data.pic = pic; 263 236 res->unscaled_data.pic = unscaled_pic; 264 237 } else { 265 res->lock_sequence_nr = state->options->buffer_pics_nr; // Update lock counter238 res->lock_sequence_nr = _state->options->buffer_pics_nr; // Update lock counter 266 239 } 267 240 268 241 must_post_process_pic = res->scaled_data.pic->visual_map->data == NULL; 269 242 // If the pic was only just drawn, we'll have to endianness-adjust it now 270 243 271 npic = gfxr_pic_xlate_common(res, maps, scaled || state->options->pic0_unscaled, 0,state->driver->mode,272 state->options->pic_xlate_filter, 0,state->options);244 npic = gfxr_pic_xlate_common(res, maps, scaled || _state->options->pic0_unscaled, 0, _state->driver->mode, 245 _state->options->pic_xlate_filter, 0, _state->options); 273 246 274 247 275 248 if (must_post_process_pic) { 276 gfxr_endianness_adjust(npic->visual_map, state->driver->mode);249 gfxr_endianness_adjust(npic->visual_map, _state->driver->mode); 277 250 } 278 251 279 252 return npic; … … 338 311 res = resMap.contains(old_nr) ? resMap[old_nr] : NULL; 339 312 340 313 if (!res || (res->mode != MODE_INVALID && res->mode != hash)) { 341 gfxr_get_pic(state, old_nr, 0, flags, old_default_palette, scaled); 314 // FIXME: the initialization of the GFX resource manager should 315 // be pushed up, and it shouldn't occur here 316 GfxResManager *_gfx = new GfxResManager(state); 317 _gfx->getPic(old_nr, 0, flags, old_default_palette, scaled); 318 delete _gfx; 342 319 343 320 res = resMap.contains(old_nr) ? resMap[old_nr] : NULL; 344 321 … … 398 375 res->mode = hash; 399 376 resMap[nr] = res; 400 377 } else { 401 gfxr_free_view( state->driver,res->unscaled_data.view);378 gfxr_free_view(res->unscaled_data.view); 402 379 } 403 380 404 381 res->mode = hash; … … 453 430 return view; 454 431 } 455 432 456 gfx_bitmap_font_t * gfxr_get_font(ResourceManager& resourceManager, gfx_resstate_t *state, int nr, intscaled) {433 gfx_bitmap_font_t *GfxResManager::getFont(int num, bool scaled) { 457 434 gfx_resource_type_t restype = GFX_RESOURCE_TYPE_FONT; 458 IntResMap &resMap = state->_resourceMaps[restype];435 IntResMap &resMap = _state->_resourceMaps[restype]; 459 436 gfx_resource_t *res = NULL; 460 437 int hash; 461 438 462 hash = gfxr_interpreter_options_hash(restype, state->version,state->options, 0);439 hash = gfxr_interpreter_options_hash(restype, _state->version, _state->options, 0); 463 440 464 res = resMap.contains(n r) ? resMap[nr] : NULL;441 res = resMap.contains(num) ? resMap[num] : NULL; 465 442 466 443 if (!res || res->mode != hash) { 467 gfx_bitmap_font_t *font = gfxr_interpreter_get_font(resourceManager, nr); 468 469 if (!font) 444 Resource *fontRes = _state->resManager->findResource(kResourceTypeFont, num, 0); 445 if (!fontRes || !fontRes->data) 470 446 return NULL; 471 447 448 gfx_bitmap_font_t *font = gfxr_read_font(fontRes->id, fontRes->data, fontRes->size); 449 472 450 if (!res) { 473 451 res = (gfx_resource_t *)sci_malloc(sizeof(gfx_resource_t)); 474 452 res->scaled_data.font = NULL; 475 res->ID = GFXR_RES_ID(restype, n r);476 res->lock_sequence_nr = state->tag_lock_counter;453 res->ID = GFXR_RES_ID(restype, num); 454 res->lock_sequence_nr = _state->tag_lock_counter; 477 455 res->mode = hash; 478 resMap[n r] = res;456 resMap[num] = res; 479 457 } else { 480 458 gfxr_free_font(res->unscaled_data.font); 481 459 } … … 484 462 485 463 return font; 486 464 } else { 487 res->lock_sequence_nr = state->tag_lock_counter; // Update lock counter465 res->lock_sequence_nr = _state->tag_lock_counter; // Update lock counter 488 466 if (res->unscaled_data.pointer) 489 467 return res->unscaled_data.font; 490 468 else … … 492 470 } 493 471 } 494 472 495 gfx_pixmap_t * gfxr_get_cursor(gfx_resstate_t *state, int nr) {473 gfx_pixmap_t *GfxResManager::getCursor(int num) { 496 474 gfx_resource_type_t restype = GFX_RESOURCE_TYPE_CURSOR; 497 IntResMap &resMap = state->_resourceMaps[restype];475 IntResMap &resMap = _state->_resourceMaps[restype]; 498 476 gfx_resource_t *res = NULL; 499 int hash = gfxr_interpreter_options_hash(restype, state->version,state->options, 0);477 int hash = gfxr_interpreter_options_hash(restype, _state->version, _state->options, 0); 500 478 501 res = resMap.contains(n r) ? resMap[nr] : NULL;479 res = resMap.contains(num) ? resMap[num] : NULL; 502 480 503 481 if (!res || res->mode != hash) { 504 gfx_pixmap_t *cursor = gfxr_interpreter_get_cursor(*(state->resManager), nr, state->version); 482 Resource *cursorRes = _state->resManager->findResource(kResourceTypeCursor, num, 0); 483 if (!cursorRes || !cursorRes->data) 484 return NULL; 505 485 486 if (_state->version >= SCI_VERSION_1_1) { 487 GFXWARN("Attempt to retrieve cursor in SCI1.1 or later\n"); 488 return NULL; 489 } 490 491 gfx_pixmap_t *cursor = gfxr_draw_cursor(GFXR_RES_ID(GFX_RESOURCE_TYPE_CURSOR, num), 492 cursorRes->data, cursorRes->size, _state->version != SCI_VERSION_0); 493 506 494 if (!cursor) 507 495 return NULL; 508 496 509 497 if (!res) { 510 498 res = (gfx_resource_t *)sci_malloc(sizeof(gfx_resource_t)); 511 499 res->scaled_data.pointer = NULL; 512 res->ID = GFXR_RES_ID(restype, n r);513 res->lock_sequence_nr = state->tag_lock_counter;500 res->ID = GFXR_RES_ID(restype, num); 501 res->lock_sequence_nr = _state->tag_lock_counter; 514 502 res->mode = hash; 515 resMap[n r] = res;503 resMap[num] = res; 516 504 } else { 517 gfx_free_pixmap( state->driver,res->unscaled_data.pointer);505 gfx_free_pixmap(res->unscaled_data.pointer); 518 506 } 519 gfx_get_res_config( state->options, cursor);520 gfx_xlate_pixmap(cursor, state->driver->mode,state->options->cursor_xlate_filter);521 gfxr_endianness_adjust(cursor, state->driver->mode);507 gfx_get_res_config(_state->options, cursor); 508 gfx_xlate_pixmap(cursor, _state->driver->mode, _state->options->cursor_xlate_filter); 509 gfxr_endianness_adjust(cursor, _state->driver->mode); 522 510 523 511 res->unscaled_data.pointer = cursor; 524 512 525 513 return cursor; 526 514 } else { 527 res->lock_sequence_nr = state->tag_lock_counter; // Update lock counter515 res->lock_sequence_nr = _state->tag_lock_counter; // Update lock counter 528 516 return res->unscaled_data.pointer; 529 517 } 530 518 } -
gfx/resource/res_manager.cpp
49 49 | (options->pic0_dither_pattern << 8) | (options->pic0_brush_mode << 4) | (options->pic0_line_mode); 50 50 51 51 case GFX_RESOURCE_TYPE_FONT: 52 return 0;53 54 52 case GFX_RESOURCE_TYPE_CURSOR: 55 53 return 0; 56 54 … … 61 59 } 62 60 } 63 61 64 gfxr_pic_t *gfxr_interpreter_init_pic(int version, gfx_mode_t *mode, int ID) {65 return gfxr_init_pic(mode, ID, version >= SCI_VERSION_01_VGA);66 }67 68 void gfxr_interpreter_clear_pic(int version, gfxr_pic_t *pic) {69 gfxr_clear_pic0(pic, SCI_TITLEBAR_SIZE);70 }71 72 62 int gfxr_interpreter_calculate_pic(gfx_resstate_t *state, gfxr_pic_t *scaled_pic, gfxr_pic_t *unscaled_pic, 73 63 int flags, int default_palette, int nr) { 74 64 ResourceManager& resourceManager = *(state->resManager); … … 152 142 153 143 if (version < SCI_VERSION_01) palette = -1; 154 144 155 switch (version) { 156 case SCI_VERSION_0: 157 case SCI_VERSION_01: 145 if (version <= SCI_VERSION_01) 158 146 result = gfxr_draw_view0(resid, res->data, res->size, palette); 159 break; 160 case SCI_VERSION_01_VGA: 161 case SCI_VERSION_01_VGA_ODD: 162 case SCI_VERSION_1_EARLY: 163 case SCI_VERSION_1_LATE: 147 else if (version >= SCI_VERSION_01_VGA && version <= SCI_VERSION_1_LATE) 164 148 result = gfxr_draw_view1(resid, res->data, res->size, staticPalette); 165 break; 166 case SCI_VERSION_1_1: 167 case SCI_VERSION_32: 149 else if (version >= SCI_VERSION_1_1) 168 150 result = gfxr_draw_view11(resid, res->data, res->size); 169 break;170 }171 151 172 152 if (version >= SCI_VERSION_01_VGA) { 173 153 if (!result->palette) { … … 179 159 return result; 180 160 } 181 161 182 gfx_bitmap_font_t *gfxr_interpreter_get_font(ResourceManager& resourceManager, int nr) {183 Resource *res = resourceManager.findResource(kResourceTypeFont, nr, 0);184 if (!res || !res->data)185 return NULL;186 187 return gfxr_read_font(res->id, res->data, res->size);188 }189 190 gfx_pixmap_t *gfxr_interpreter_get_cursor(ResourceManager& resourceManager, int nr, int version) {191 Resource *res = resourceManager.findResource(kResourceTypeCursor, nr, 0);192 int resid = GFXR_RES_ID(GFX_RESOURCE_TYPE_CURSOR, nr);193 194 if (!res || !res->data)195 return NULL;196 197 if (version >= SCI_VERSION_1_1) {198 GFXWARN("Attempt to retrieve cursor in SCI1.1 or later\n");199 return NULL;200 }201 202 return gfxr_draw_cursor(resid, res->data, res->size, version != SCI_VERSION_0);203 }204 205 Palette *gfxr_interpreter_get_static_palette(ResourceManager& resourceManager, int version, int *colors_nr) {206 if (version >= SCI_VERSION_01_VGA)207 return gfxr_interpreter_get_palette(resourceManager, version, colors_nr, 999);208 209 *colors_nr = GFX_SCI0_PIC_COLORS_NR;210 return gfx_sci0_pic_colors->getref();211 }212 213 Palette *gfxr_interpreter_get_palette(ResourceManager& resourceManager, int version, int *colors_nr, int nr) {214 Resource *res;215 216 if (version < SCI_VERSION_01_VGA)217 return NULL;218 219 res = resourceManager.findResource(kResourceTypePalette, nr, 0);220 if (!res || !res->data)221 return NULL;222 223 switch (version) {224 case SCI_VERSION_01_VGA :225 case SCI_VERSION_01_VGA_ODD :226 case SCI_VERSION_1_EARLY :227 case SCI_VERSION_1_LATE :228 return gfxr_read_pal1(res->id, res->data, res->size);229 case SCI_VERSION_1_1 :230 case SCI_VERSION_32 :231 GFXDEBUG("Palettes are not yet supported in this SCI version\n");232 return NULL;233 234 default:235 BREAKPOINT();236 return NULL;237 }238 }239 240 int gfxr_interpreter_needs_multicolored_pointers(int version) {241 return (version > SCI_VERSION_1);242 }243 244 162 } // End of namespace Sci -
gfx/resource/res_pic.cpp
1695 1695 // Set up mode structure for resizing the view 1696 1696 Graphics::PixelFormat format = { 1, 0, 0, 0, 0, 0, 0, 0, 0 }; // 1byte/p, which handles masks and the rest for us 1697 1697 gfx_mode_t *mode = gfx_new_mode(pic->visual_map->index_width / 320, 1698 pic->visual_map->index_height / 200, format, view->palette , 0);1698 pic->visual_map->index_height / 200, format, view->palette->getref(), 0); 1699 1699 1700 1700 gfx_xlate_pixmap(view, mode, GFX_XLATE_FILTER_NONE); 1701 1701 gfx_free_mode(mode); … … 1708 1708 view->index_data, pic->visual_map->index_width, view->index_width, 1709 1709 view->index_width, view->index_height, 1); 1710 1710 1711 gfx_free_pixmap(NULL, view); 1711 gfx_free_pixmap(view); 1712 view = NULL; 1712 1713 } 1713 1714 goto end_op_loop; 1714 1715 … … 1795 1796 1796 1797 // Set up mode structure for resizing the view 1797 1798 Graphics::PixelFormat format = { 1, 0, 0, 0, 0, 0, 0, 0, 0 }; // 1 byte/p, which handles masks and the rest for us 1798 gfx_mode_t *mode = gfx_new_mode(pic->visual_map->index_width / 320, pic->visual_map->index_height / 200, format, view->palette , 0);1799 gfx_mode_t *mode = gfx_new_mode(pic->visual_map->index_width / 320, pic->visual_map->index_height / 200, format, view->palette->getref(), 0); 1799 1800 1800 1801 gfx_xlate_pixmap(view, mode, GFX_XLATE_FILTER_NONE); 1801 1802 gfx_free_mode(mode); -
gfx/resource/res_view0.cpp
57 57 } 58 58 59 59 if (xl <= 0 || yl <= 0) { 60 gfx_free_pixmap( NULL,retval);60 gfx_free_pixmap(retval); 61 61 GFXERROR("View %02x:(%d/%d) has invalid xl=%d or yl=%d\n", id, loop, cel, xl, yl); 62 62 return NULL; 63 63 } … … 218 218 if (error_token || gfxr_draw_loop0(view->loops + i, id, i, resource, loop_offset, size, view, mirrored)) { 219 219 // An error occured 220 220 view->loops_nr = i; 221 gfxr_free_view( NULL,view);221 gfxr_free_view(view); 222 222 return NULL; 223 223 } 224 224 } -
gfx/resource/res_view1.cpp
246 246 247 247 if (view) 248 248 retval->palette = view->palette->getref(); 249 else 250 retval->palette = NULL; 249 251 250 252 if (xl <= 0 || yl <= 0) { 251 gfx_free_pixmap( NULL,retval);253 gfx_free_pixmap(retval); 252 254 GFXERROR("View %02x:(%d/%d) has invalid xl=%d or yl=%d\n", id, loop, cel, xl, yl); 253 255 return NULL; 254 256 } … … 261 263 pos, xl, yl, retval->color_key); 262 264 263 265 if (decompress_failed) { 264 gfx_free_pixmap( NULL,retval);266 gfx_free_pixmap(retval); 265 267 return NULL; 266 268 } 267 269 … … 381 383 if (error_token || gfxr_draw_loop1(view->loops + i, id, i, mirror_mask & (1 << i), resource, loop_offset, size, view, amiga_game)) { 382 384 // An error occured 383 385 view->loops_nr = i; 384 gfxr_free_view( NULL,view);386 gfxr_free_view(view); 385 387 return NULL; 386 388 } 387 389 } … … 429 431 retval->palette = view->palette->getref(); 430 432 431 433 if (xl <= 0 || yl <= 0) { 432 gfx_free_pixmap( NULL,retval);434 gfx_free_pixmap(retval); 433 435 GFXERROR("View %02x:(%d/%d) has invalid xl=%d or yl=%d\n", id, loop, cel, xl, yl); 434 436 return NULL; 435 437 } … … 438 440 runlength_offset, literal_offset, xl, yl, retval->color_key); 439 441 440 442 if (decompress_failed) { 441 gfx_free_pixmap( NULL,retval);443 gfx_free_pixmap(retval); 442 444 return NULL; 443 445 } 444 446