From 4d4221d71fa32bf54a6f6547536d65d776dcd3f5 Mon Sep 17 00:00:00 2001 From: helixhorned Date: Wed, 14 Mar 2012 22:30:24 +0000 Subject: [PATCH] Continuously keep track of the number of sprites in the world. New engine variable 'int32_t Numsprites', not yet saved into savegames or mapstates. (The capitalization is to distinguish it from the often-used 'numsprites' locals or structure member names. In the editor, get rid of updatenumsprites(). git-svn-id: https://svn.eduke32.com/eduke32@2478 1a8010ca-5511-0410-912e-c29ae57300e0 --- polymer/eduke32/build/include/build.h | 1 + polymer/eduke32/build/include/editor.h | 1 - polymer/eduke32/build/src/build.c | 35 +++++++------------------- polymer/eduke32/build/src/engine.c | 21 +++++++++------- polymer/eduke32/source/astub.c | 33 ++++++++++-------------- polymer/eduke32/source/m32exec.c | 8 ++---- polymer/eduke32/source/m32vars.c | 2 +- polymer/eduke32/source/mapster32.h | 1 - 8 files changed, 38 insertions(+), 64 deletions(-) diff --git a/polymer/eduke32/build/include/build.h b/polymer/eduke32/build/include/build.h index e5e6d294b..11d5a6847 100644 --- a/polymer/eduke32/build/include/build.h +++ b/polymer/eduke32/build/include/build.h @@ -318,6 +318,7 @@ EXTERN int32_t numyaxbunches; EXTERN int16_t headsectbunch[2][YAX_MAXBUNCHES], nextsectbunch[2][MAXSECTORS]; #endif +EXTERN int32_t Numsprites; EXTERN int16_t numsectors, numwalls; EXTERN char display_mirror; EXTERN int32_t totalclock; diff --git a/polymer/eduke32/build/include/editor.h b/polymer/eduke32/build/include/editor.h index e74ec38d2..1afb63c62 100644 --- a/polymer/eduke32/build/include/editor.h +++ b/polymer/eduke32/build/include/editor.h @@ -82,7 +82,6 @@ extern int32_t autosave; extern int32_t mlook; extern int16_t prefixtiles[10]; -extern int32_t numsprites; extern int32_t showfirstwall; extern int32_t graphicsmode; diff --git a/polymer/eduke32/build/src/build.c b/polymer/eduke32/build/src/build.c index 07785a0a7..115288906 100644 --- a/polymer/eduke32/build/src/build.c +++ b/polymer/eduke32/build/src/build.c @@ -84,7 +84,6 @@ int32_t grid = 3, autogrid = 0, gridlock = 1, showtags = 2; int32_t zoom = 768, gettilezoom = 1; int32_t lastpm16time = 0; -int32_t numsprites; extern int32_t mapversion; int16_t highlight[MAXWALLS+MAXSPRITES]; @@ -217,7 +216,6 @@ static int32_t getlinehighlight(int32_t xplc, int32_t yplc, int32_t line); int32_t fixspritesectors(void); static int32_t movewalls(int32_t start, int32_t offs); int32_t loadnames(const char *namesfile, int8_t root); -void updatenumsprites(void); static void getclosestpointonwall(int32_t x, int32_t y, int32_t dawall, int32_t *nx, int32_t *ny, int32_t maybe_screen_coord_p); static void initcrc(void); @@ -416,7 +414,6 @@ static void reset_default_mapstate(void) numsectors = 0; numwalls = 0; - numsprites = 0; editorzrange[0] = INT32_MIN; editorzrange[1] = INT32_MAX; @@ -1277,7 +1274,6 @@ void editinput(void) correct_sprite_yoffset(i); - updatenumsprites(); asksave = 1; VM_OnEvent(EVENT_INSERTSPRITE3D, i); @@ -1685,12 +1681,11 @@ static int32_t restore_highlighted_map(mapinfofull_t *mapinfo, int32_t forreal) { int32_t i, j, sect, onumsectors=numsectors, newnumsectors, newnumwalls; - updatenumsprites(); if (numsectors+mapinfo->numsectors>MAXSECTORS || numwalls+mapinfo->numwalls>MAXWALLS #ifdef YAX_ENABLE || numyaxbunches+mapinfo->numyaxbunches > YAX_MAXBUNCHES #endif - || numsprites+mapinfo->numsprites>MAXSPRITES) + || Numsprites+mapinfo->numsprites>MAXSPRITES) { mapinfofull_free(mapinfo); return -1; @@ -1762,7 +1757,6 @@ static int32_t restore_highlighted_map(mapinfofull_t *mapinfo, int32_t forreal) mapinfofull_free(mapinfo); numwalls = newnumwalls; - updatenumsprites(); update_highlightsector(); @@ -1948,7 +1942,7 @@ static void duplicate_selected_sprites(void) // sprite[j].sectnum = sprite[k].sectnum; //Don't let memcpy overwrite sector! // setsprite(j,(vec3_t *)&sprite[j]); } - updatenumsprites(); + printmessage16("Sprites duplicated and stamped."); asksave = 1; } @@ -6136,7 +6130,7 @@ end_join_sectors: correct_sprite_yoffset(i); printmessage16("Sprite inserted."); - updatenumsprites(); + asksave = 1; VM_OnEvent(EVENT_INSERTSPRITE2D, i); @@ -7036,7 +7030,7 @@ end_batch_insert_points: { deletesprite(pointhighlight&16383); printmessage16("Sprite deleted."); - updatenumsprites(); + update_highlight(); asksave = 1; } @@ -7721,7 +7715,6 @@ int32_t LoadBoard(const char *filename, uint32_t flags) i==0?"successfully": (i<4 ? "(moderate corruption)" : "(HEAVY corruption)")); } - updatenumsprites(); startposx = pos.x; //this is same startposy = pos.y; startposz = pos.z; @@ -8153,7 +8146,6 @@ static int32_t deletesector(int16_t sucksect) while (headspritesect[sucksect] >= 0) deletesprite(headspritesect[sucksect]); - updatenumsprites(); startwall = sector[sucksect].wallptr; endwall = startwall + sector[sucksect].wallnum - 1; @@ -9615,7 +9607,7 @@ void printcoords16(int32_t posxe, int32_t posye, int16_t ange) char snotbuf[80]; int32_t i, m; int32_t v8 = (numsectors > MAXSECTORSV7 || numwalls > MAXWALLSV7 || - numsprites > MAXSPRITESV7 || numyaxbunches > 0); + Numsprites > MAXSPRITESV7 || numyaxbunches > 0); #if M32_UNDO Bsprintf(snotbuf,"x:%d y:%d ang:%d r%d",posxe,posye,ange,map_revision-1); #else @@ -9644,20 +9636,20 @@ void printcoords16(int32_t posxe, int32_t posye, int16_t ange) { if (xdim >= 800) Bsprintf(&snotbuf[m], "/%d wal. %d/16k spr. %d/256 bn.", - MAXWALLSV8, numsprites, numyaxbunches); + MAXWALLSV8, Numsprites, numyaxbunches); else Bsprintf(&snotbuf[m], " wal. %d spr. %d/256 bn.", - numsprites, numyaxbunches); + Numsprites, numyaxbunches); } else { if (xdim >= 800) Bsprintf(&snotbuf[m], "/%d wal. %d/%d spr.", - v8?MAXWALLSV8:MAXWALLSV7, numsprites, + v8?MAXWALLSV8:MAXWALLSV7, Numsprites, v8?MAXSPRITESV8:MAXSPRITESV7); else Bsprintf(&snotbuf[m], "/%dk wal. %d/%dk spr.", - (v8?MAXWALLSV8:MAXWALLSV7)/1000, numsprites, + (v8?MAXWALLSV8:MAXWALLSV7)/1000, Numsprites, (v8?MAXSPRITESV8:MAXSPRITESV7)/1000); } } @@ -9694,15 +9686,6 @@ void printcoords16(int32_t posxe, int32_t posye, int16_t ange) printext16(264, ydim-STATUS2DSIZ+128, v8?editorcolors[10]:whitecol, -1, snotbuf,0); } -void updatenumsprites(void) -{ - int32_t i; - - numsprites = 0; - for (i=0; iMAXSECTORS || ournumwalls+numwalls>MAXWALLS || - ournumsprites+numsprites>MAXSPRITES) + ournumsprites+Numsprites>MAXSPRITES) { initprintf("clip map: warning: exceeded limits when loading %s, aborting.\n", fn); break; @@ -1313,7 +1310,7 @@ int32_t clipmapinfo_load(const char *filename) Bmemcpy(loadsector+ournumsectors, sector, numsectors*sizeof(sectortype)); Bmemcpy(loadwall+ournumwalls, wall, numwalls*sizeof(walltype)); - Bmemcpy(loadsprite+ournumsprites, sprite, numsprites*sizeof(spritetype)); + Bmemcpy(loadsprite+ournumsprites, sprite, Numsprites*sizeof(spritetype)); for (i=ournumsectors; i=0) loadsprite[i].sectnum += ournumsectors; ournumsectors += numsectors; ournumwalls += numwalls; - ournumsprites += numsprites; + ournumsprites += Numsprites; if (lwcp != loadedwhich) { @@ -7598,7 +7595,10 @@ int32_t insertsprite(int16_t sectnum, int16_t statnum) int32_t newspritenum = insertspritestat(statnum); if (newspritenum >= 0) + { do_insertsprite_at_headofsect(newspritenum, sectnum); + Numsprites++; + } return newspritenum; @@ -7632,6 +7632,7 @@ int32_t deletesprite(int16_t spritenum) sprite[spritenum].statnum = MAXSTATUS; tailspritefree = spritenum; + Numsprites--; return 0; } @@ -8132,6 +8133,7 @@ void initspritelists(void) nextspritestat[MAXSPRITES-1] = -1; tailspritefree = MAXSPRITES-1; + Numsprites = 0; } @@ -10016,6 +10018,7 @@ int32_t saveboard(const char *filename, int32_t *daposx, int32_t *daposy, int32_ numsprites++; } #endif + assert(numsprites == Numsprites); #ifdef YAX_ENABLE if (numyaxbunches > 0) diff --git a/polymer/eduke32/source/astub.c b/polymer/eduke32/source/astub.c index 77512e1ed..c87d7e4c9 100644 --- a/polymer/eduke32/source/astub.c +++ b/polymer/eduke32/source/astub.c @@ -457,7 +457,6 @@ void create_map_snapshot(void) } fixspritesectors(); - updatenumsprites(); mapstate->numsectors = numsectors; mapstate->numwalls = numwalls; @@ -506,7 +505,7 @@ void create_map_snapshot(void) } } - if (numsprites) + if (Numsprites) { tempcrc = crc32once((uint8_t *)&sprite[0],sizeof(spritetype) * MAXSPRITES); @@ -520,11 +519,11 @@ void create_map_snapshot(void) else { int32_t i = 0; - spritetype *tspri = (spritetype *)Bcalloc(1, sizeof(spritetype) * numsprites + 1), + spritetype *tspri = (spritetype *)Bcalloc(1, sizeof(spritetype) * Numsprites + 1), *spri = &tspri[0]; - mapstate->sprites = (spritetype *)Bcalloc(1, sizeof(spritetype) * numsprites + QADDNSZ); + mapstate->sprites = (spritetype *)Bcalloc(1, sizeof(spritetype) * Numsprites + QADDNSZ); - for (j=0; jspritesiz = j = qlz_compress(&tspri[0], (char *)&mapstate->sprites[0], - sizeof(spritetype) * numsprites, state_compress); + sizeof(spritetype) * Numsprites, state_compress); mapstate->sprites = (spritetype *)Brealloc(mapstate->sprites, j); mapstate->spritecrc = tempcrc; Bfree(tspri); @@ -596,11 +595,8 @@ int32_t map_undoredo(int32_t dir) numsectors = mapstate->numsectors; numwalls = mapstate->numwalls; - numsprites = mapstate->numsprites; map_revision = mapstate->revision; - initspritelists(); - Bmemset(show2dsector, 0, sizeof(show2dsector)); Bmemset(show2dsprite, 0, sizeof(show2dsprite)); Bmemset(show2dwall, 0, sizeof(show2dwall)); @@ -617,14 +613,16 @@ int32_t map_undoredo(int32_t dir) qlz_decompress((const char *)&mapstate->sprites[0], &sprite[0], state_decompress); } - updatenumsprites(); + initspritelists(); - for (i=0; inumsprites; i++) { if ((sprite[i].cstat & 48) == 48) sprite[i].cstat &= ~48; insertsprite(sprite[i].sectnum,sprite[i].statnum); } + assert(Numsprites == mapstate->numsprites); + #ifdef POLYMER if (qsetmode == 200 && rendmode == 4) polymer_loadboard(); @@ -4576,8 +4574,6 @@ ENDFOR1: cursor = insertsprite(sprite[startspr].sectnum,0); if (cursor < 0) goto ERROR_TOOMANYSPRITES; - updatenumsprites(); - sp = &sprite[cursor]; Bmemcpy(sp, &sprite[startspr], sizeof(spritetype)); sp->yoffset = 0; @@ -4676,7 +4672,7 @@ ENDFOR1: sect = sprite[curspr].sectnum; updatesector(dax,day,§); - if (numsprites < MAXSPRITES && sect >= 0) + if (Numsprites < MAXSPRITES && sect >= 0) { i = insertsprite(sect,0); Bmemcpy(&sprite[i], &sprite[linebegspr], sizeof(spritetype)); @@ -4702,7 +4698,6 @@ ENDFOR1: curspr = i; doingspace = 0; - updatenumsprites(); asksave = 1; if (numletters >= stackallocsize) @@ -4745,15 +4740,14 @@ ENDFOR1: numletters--; deletesprite(last); - updatenumsprites(); asksave = 1; } else { numletters--; deletesprite(last); + curspr = linebegspr; - updatenumsprites(); asksave = 1; } } @@ -4775,7 +4769,6 @@ ENDFOR1: ERROR_TOOMANYSPRITES: if (cursor < 0) message("Too many sprites in map!"); else deletesprite(cursor); - updatenumsprites(); ERROR_NOMEMORY: if (spritenums) Bfree(spritenums); @@ -5221,7 +5214,7 @@ static void Keys3d(void) if (AIMING_AT_SPRITE) { deletesprite(searchwall); - updatenumsprites(); + message("Sprite %d deleted",searchwall); if (AmbienceToggle) { @@ -10707,7 +10700,7 @@ void ExtPreCheckKeys(void) // just before drawrooms if (graphicsmode && !m32_sideview && zoom >= 256) { - for (i=ii=0; i= MAXSPRITES) + if (Numsprites >= MAXSPRITES) { M32_ERROR("Maximum number of sprites reached."); continue; @@ -1675,7 +1675,6 @@ badindex: ret = insertsprite(dasectnum, 0); vm.g_i = ret; vm.g_sp = &sprite[ret]; - numsprites++; } continue; @@ -1689,7 +1688,7 @@ badindex: { M32_ERROR("Tried to duplicate nonexistent sprite %d", ospritenum); } - if ((tw==CON_DUPSPRITE && numsprites >= MAXSPRITES) || + if ((tw==CON_DUPSPRITE && Numsprites >= MAXSPRITES) || (tw==CON_DUPSPRITE && spritesortcnt >= MAXSPRITESONSCREEN)) { M32_ERROR("Maximum number of sprites reached."); @@ -1709,7 +1708,6 @@ badindex: Bmemcpy(&sprite[nspritenum], &sprite[ospritenum], sizeof(spritetype)); vm.g_i = nspritenum; vm.g_sp = &sprite[nspritenum]; - numsprites++; } else { @@ -1730,8 +1728,6 @@ badindex: X_ERROR_INVALIDSPRI(daspritenum); ret = deletesprite(daspritenum); g_iReturnVar = ret; - if (ret==0) - numsprites--; } continue; diff --git a/polymer/eduke32/source/m32vars.c b/polymer/eduke32/source/m32vars.c index 177708411..40843e362 100644 --- a/polymer/eduke32/source/m32vars.c +++ b/polymer/eduke32/source/m32vars.c @@ -554,7 +554,7 @@ static void Gv_AddSystemVars(void) Gv_NewVar("numwalls",(intptr_t)&numwalls, GAMEVAR_SYSTEM | GAMEVAR_SHORTPTR | GAMEVAR_READONLY); Gv_NewVar("numsectors",(intptr_t)&numsectors, GAMEVAR_SYSTEM | GAMEVAR_SHORTPTR | GAMEVAR_READONLY); - Gv_NewVar("numsprites",(intptr_t)&numsprites, GAMEVAR_SYSTEM | GAMEVAR_INTPTR | GAMEVAR_READONLY); + Gv_NewVar("numsprites",(intptr_t)&Numsprites, GAMEVAR_SYSTEM | GAMEVAR_INTPTR | GAMEVAR_READONLY); { static int32_t numtiles; Gv_NewVar("numtiles",(intptr_t)&numtiles, GAMEVAR_SYSTEM | GAMEVAR_INTPTR | GAMEVAR_READONLY); diff --git a/polymer/eduke32/source/mapster32.h b/polymer/eduke32/source/mapster32.h index b4e95814e..cad7ea9f8 100644 --- a/polymer/eduke32/source/mapster32.h +++ b/polymer/eduke32/source/mapster32.h @@ -40,7 +40,6 @@ uint8_t default_buildkeys[NUMBUILDKEYS] = }; extern char changechar(char dachar, int32_t dadir, char smooshyalign, char boundcheck); -extern void updatenumsprites(void); static char autospritehelp=0, autosecthelp=0; //static int32_t lastmessagetime=-1;