void SpriteCache::removeSprite(int index, bool freeMemory) { if ((images[index] != NULL) && (freeMemory)) wfreeblock(images[index]); images[index] = NULL; offsets[index] = 0; }
void domouse(int str) { /* TO USE THIS ROUTINE YOU MUST LOAD A MOUSE CURSOR USING mloadcursor. . . YOU MUST ALSO REMEMBER TO CALL mfreemem AT THE END OF THE PROGRAM. */ /* short *sstr=(short*)&mousecurs[currentcursor][0]; int poow=(short)sstr[0],pooh=(short)sstr[1];*/ int poow=wgetblockwidth(mousecurs[currentcursor]); int pooh=wgetblockheight(mousecurs[currentcursor]); int smx=mousex-hotxwas,smy=mousey-hotywas; // mousex-=hotx; mousey-=hoty; mgetgraphpos(); mousex-=hotx; mousey-=hoty; if (mousex+poow>=vesa_xres) poow=vesa_xres-mousex; if (mousey+pooh>=vesa_yres) pooh=vesa_yres-mousey; wclip(0,0,vesa_xres-1,vesa_yres-1); if ((str==0) & (mouseturnedon==TRUE)) { if ((mousex!=smx) | (mousey!=smy)) { // the mouse has moved wputblock(smx,smy,savebk,0); wfreeblock(savebk); savebk=wnewblock(mousex,mousey,mousex+poow,mousey+pooh); wputblock(mousex,mousey,mousecurs[currentcursor],1); } } else if ((str==1) & (mouseturnedon==FALSE)) { // the mouse is just being turned on savebk=wnewblock(mousex,mousey,mousex+poow,mousey+pooh); wputblock(mousex,mousey,mousecurs[currentcursor],1); mouseturnedon=TRUE; } else if ((str==2) & (mouseturnedon==TRUE)) { // the mouse is being turned off // if (abuf != ignore_mouseoff_bitmap) wputblock(smx,smy,savebk,0); wfreeblock(savebk); mouseturnedon=FALSE; } mousex+=hotx; mousey+=hoty; hotxwas=hotx; hotywas=hoty; }
void SpriteCache::removeAll() { int ii; liststart = -1; listend = -1; for (ii = 0; ii < elements; ii++) { if ((offsets[ii] != SPRITE_LOCKED) && (images[ii] != NULL) && ((flags[ii] & SPRCACHEFLAG_DOESNOTEXIST) == 0)) { wfreeblock(images[ii]); images[ii] = NULL; } mrulist[ii] = 0; mrubacklink[ii] = 0; } cachesize = lockedSize; }
void SpriteCache::reset() { int ii; for (ii = 0; ii < elements; ii++) { if (images[ii] != NULL) { wfreeblock(images[ii]); images[ii] = NULL; } } free(offsets); free(images); free(mrulist); free(mrubacklink); free(sizes); free(flags); offsets = NULL; init(); }
// Remove the oldest cache element void SpriteCache::removeOldest() { if (liststart < 0) return; int sprnum = liststart; if ((images[sprnum] != NULL) && (offsets[sprnum] != SPRITE_LOCKED)) { // Free the memory if (flags[sprnum] & SPRCACHEFLAG_DOESNOTEXIST) { char msgg[150]; sprintf(msgg, "SpriteCache::removeOldest: Attempted to remove sprite %d that does not exist", sprnum); quit(msgg); } cachesize -= sizes[sprnum]; wfreeblock(images[sprnum]); images[sprnum] = NULL; } if (liststart == listend) { // there was one huge sprite, removing it has now emptied the cache completely if (cachesize > 0) { char msgg[150]; sprintf(msgg, "!!!! SPRITE CACHE ERROR: Sprite cache should be empty, but still has %d bytes", cachesize); write_log(msgg); } mrulist[liststart] = 0; liststart = -1; listend = -1; } else { int oldstart = liststart; liststart = mrulist[liststart]; mrulist[oldstart] = 0; mrubacklink[liststart] = START_OF_LIST; if (oldstart == liststart) { // Somehow, we have got a recursive link to itself, so we // the game will freeze (since it is not actually freeing any // memory) // There must be a bug somewhere causing this, but for now // let's just reset the cache write_log("!!!! RUNTIME CACHE ERROR: CACHE INCONSISTENT: RESETTING"); char msgg[150]; sprintf(msgg, "!!!! At size %ld (of %ld), start %d end %d fwdlink=%d", cachesize, maxCacheSize, oldstart, listend, liststart); write_log(msgg); removeAll(); } } #ifdef DEBUG_SPRITECACHE char msgg[100]; sprintf(msgg, "Removed %d, size now %d KB", sprnum, cachesize / 1024); write_log(msgg); #endif }
int is_route_possible(int fromx, int fromy, int tox, int toy, block wss) { wallscreen = wss; suggestx = -1; // ensure it's a memory bitmap, so we can use direct access to line[] array if ((wss == NULL) || (!is_memory_bitmap(wss)) || (bitmap_color_depth(wss) != 8)) quit("is_route_possible: invalid walkable areas bitmap supplied"); if (getpixel(wallscreen, fromx, fromy) < 1) return 0; block tempw = create_bitmap_ex(8, wallscreen->w, wallscreen->h); if (tempw == NULL) quit("no memory for route calculation"); if (!is_memory_bitmap(tempw)) quit("tempw is not memory bitmap"); blit(wallscreen, tempw, 0, 0, 0, 0, tempw->w, tempw->h); int dd, ff; // initialize array for finding widths of walkable areas int thisar, inarow = 0, lastarea = 0; int walk_area_times[MAX_WALK_AREAS + 1]; for (dd = 0; dd <= MAX_WALK_AREAS; dd++) { walk_area_times[dd] = 0; walk_area_granularity[dd] = 0; } for (ff = 0; ff < tempw->h; ff++) { for (dd = 0; dd < tempw->w; dd++) { thisar = tempw->line[ff][dd]; // count how high the area is at this point if ((thisar == lastarea) && (thisar > 0)) inarow++; else if (lastarea > MAX_WALK_AREAS) quit("!Calculate_Route: invalid colours in walkable area mask"); else if (lastarea != 0) { walk_area_granularity[lastarea] += inarow; walk_area_times[lastarea]++; inarow = 0; } lastarea = thisar; } } for (dd = 0; dd < tempw->w; dd++) { for (ff = 0; ff < tempw->h; ff++) { thisar = tempw->line[ff][dd]; if (thisar > 0) putpixel(tempw, dd, ff, 1); // count how high the area is at this point if ((thisar == lastarea) && (thisar > 0)) inarow++; else if (lastarea != 0) { walk_area_granularity[lastarea] += inarow; walk_area_times[lastarea]++; inarow = 0; } lastarea = thisar; } } // find the average "width" of a path in this walkable area for (dd = 1; dd <= MAX_WALK_AREAS; dd++) { if (walk_area_times[dd] == 0) { walk_area_granularity[dd] = MAX_GRANULARITY; continue; } walk_area_granularity[dd] /= walk_area_times[dd]; if (walk_area_granularity[dd] <= 4) walk_area_granularity[dd] = 2; else if (walk_area_granularity[dd] <= 15) walk_area_granularity[dd] = 3; else walk_area_granularity[dd] = MAX_GRANULARITY; /*char toprnt[200]; sprintf(toprnt,"area %d: Gran %d", dd, walk_area_granularity[dd]); winalert(toprnt); */ } walk_area_granularity[0] = MAX_GRANULARITY; floodfill(tempw, fromx, fromy, 232); if (getpixel(tempw, tox, toy) != 232) { // Destination pixel is not walkable // Try the 100x100 square around the target first at 3-pixel granularity int tryFirstX = tox - 50, tryToX = tox + 50; int tryFirstY = toy - 50, tryToY = toy + 50; if (!find_nearest_walkable_area(tempw, tryFirstX, tryFirstY, tryToX, tryToY, tox, toy, 3)) { // Nothing found, sweep the whole room at 5 pixel granularity find_nearest_walkable_area(tempw, 0, 0, tempw->w, tempw->h, tox, toy, 5); } wfreeblock(tempw); return 0; } wfreeblock(tempw); return 1; }
void mfreemem() { for (int re=0;re<numcurso;re++) { if (mousecurs[re]!=NULL) wfreeblock(mousecurs[re]); } }
/* *** SCRIPT SYMBOL: [Multimedia] PlayFlic *** */ void play_flc_file(int numb,int playflags) { color oldpal[256]; if (play.fast_forward) return; wreadpalette(0,255,oldpal); int clearScreenAtStart = 1; canabort = playflags % 10; playflags -= canabort; if (canabort == 2) // convert to PlayVideo-compatible setting canabort = 3; if (playflags % 100 == 0) stretch_flc = 1; else stretch_flc = 0; if (playflags / 100) clearScreenAtStart = 0; char flicnam[20]; sprintf(flicnam,"flic%d.flc",numb); FILE*iii=clibfopen(flicnam,"rb"); if (iii==NULL) { sprintf(flicnam,"flic%d.fli",numb); iii=clibfopen(flicnam,"rb"); } if (iii==NULL) { debug_log("FLIC animation FLIC%d.FLC not found",numb); return; } fseek(iii,8,SEEK_CUR); fread(&fliwidth,2,1,iii); fread(&fliheight,2,1,iii); fclose(iii); if (game.color_depth > 1) { hicol_buf=create_bitmap_ex(final_col_dep,fliwidth,fliheight); clear(hicol_buf); } // override the stretch option if necessary if ((fliwidth==scrnwid) && (fliheight==scrnhit)) stretch_flc = 0; else if ((fliwidth > scrnwid) || (fliheight > scrnhit)) stretch_flc = 1; fli_buffer=create_bitmap_ex(8,fliwidth,fliheight); //640,400); //scrnwid,scrnhit); if (fli_buffer==NULL) quit("Not enough memory to play animation"); clear(fli_buffer); if (clearScreenAtStart) { clear(screen); render_to_screen(screen, 0, 0); } fli_target = create_bitmap_ex(final_col_dep, BMP_W(screen), BMP_H(screen)); fli_ddb = gfxDriver->CreateDDBFromBitmap(fli_target, false, true); if (play_fli(flicnam,fli_buffer,0,fli_callback)==FLI_ERROR) quit("FLI/FLC animation play error"); wfreeblock(fli_buffer); clear(screen); wsetpalette(0,255,oldpal); render_to_screen(screen, 0, 0); destroy_bitmap(fli_target); gfxDriver->DestroyDDB(fli_ddb); fli_ddb = NULL; if (hicol_buf!=NULL) { wfreeblock(hicol_buf); hicol_buf=NULL; } // wsetscreen(screen); wputblock(0,0,backbuffer,0); while (ac_mgetbutton()!=NONE) ; invalidate_screen(); }