From e12d25dc9508ce99a49777786969e303bc44f974 Mon Sep 17 00:00:00 2001 From: ac-stef Date: Sat, 5 Nov 2016 17:42:30 +0100 Subject: [PATCH] add todo list for entities Add some commands to support an entity TODO list. Entity errors during map load are automatically added to the list. The list is saved and restored with xmaps. A keybind (no default key assigned) to scroll through TODO entities was added. The list is indented as a means for automated map check scripts to return a list of entities to fix. cleartodoentities [index] Clear list of TODO entities. The list is also deleted, when a new map is loaded. If an entity number is given as an argument, only entries for this entity are cleared. addtodoentity index comment Add the entity #index to the TODO list. Add optional comment. enumtodoentities Returns a list of TODO entities. Returns entity index number and comment for every entry. DOCREF enumtodoentities addtodoentity cleartodoentities --- config/menus_edit.cfg | 39 ++++++++++++++++++++++++++++++++------- config/resetbinds.cfg | 1 + config/scripts.cfg | 19 +++++++++++++++++++ source/src/protos.h | 4 ++++ source/src/world.cpp | 36 ++++++++++++++++++++++++++++++++++++ source/src/worldio.cpp | 22 ++++++++++++++++++---- 6 files changed, 110 insertions(+), 11 deletions(-) diff --git a/config/menus_edit.cfg b/config/menus_edit.cfg index e6514d39..68686dd2 100644 --- a/config/menus_edit.cfg +++ b/config/menus_edit.cfg @@ -60,16 +60,19 @@ menuitem "\f2\t\t [ OK ]" [ newent light $clight $clight1 $clight2 $clight3 ] //Entities menu newmenu Entities -menuitem "RVSF Spawn point" [ newent playerstart 1 ] -menuitem "CLA Spawn point" [ newent playerstart 0 ] -menuitem "FFA Spawn point" [ newent playerstart 100 ] +menuitem "Place RVSF spawn point" [ newent playerstart 1 ] +menuitem "Place CLA spawn point" [ newent playerstart 0 ] +menuitem "Place FFA spawn point" [ newent playerstart 100 ] menuitemcheckbox "Show all spawn points: " "$showplayerstarts" [ showplayerstarts $arg1 ] menuitem "" -1 -menuitem "RVSF CTF Flag" [ newent ctf-flag 1 ] -menuitem "CLA CTF Flag" [ newent ctf-flag 0 ] +menuitem "Place RVSF CTF Flag" [ newent ctf-flag 1 ] +menuitem "Place CLA CTF Flag" [ newent ctf-flag 0 ] menuitem "" -1 -menuitem "Ladder entity" "saycommand /newent ladder " [ echo "Ensure that you have placed the ladder mapmodel first (found in the mapmodels menu)..." ] -menuitem "Clip entity" [ showmenu Clips ] [ echo Clips can be used to block off areas that players shouldn't be able to access... ] +menuitem "Place ladder entity" "saycommand /newent ladder " [ echo "Ensure that you have placed the ladder mapmodel first (found in the mapmodels menu)..." ] +menuitem "Place clip entity..." [ showmenu Clips ] [ echo Clips can be used to block off areas that players shouldn't be able to access... ] +menuitem "" -1 +menuitem "Show list of TODO entities" [ showmenu "TODO entities" ] +menuitem "Show list of deleted entities" [ showmenu "deleted entities" ] tempalias _clip00 clip; tempalias _clip00status 0; tempalias _clip01 0; tempalias _clip02 1; tempalias _clip03 1; tempalias _clip04 1 // Give aliases an initial value. @@ -759,6 +762,7 @@ menuitemeditkeyinput [Delete entity: ] editkey_delete_entity menuitemeditkeyinput [Copy entity: ] copyent menuitemeditkeyinput [Paste entity: ] pasteent menuitemeditkeyinput [Edit entity: ] editent +menuitemeditkeyinput [Cycle through TODO entities: ] editkey_scroll_todoents menuitemeditkeyinput [Cycle through spawns: ] editkey_scroll_spawns menuitem "" -1 menuitem "\f2Tag clips:" -1 @@ -788,6 +792,27 @@ menuinit [ ] ] +// todo entities +newmenu "TODO entities" +menuinit [ + resetcurmenu + push h 1 + looplisti (enumtodoentities) [n desc] [ + if $editing [ + menuitem (concatword "Entity #" $n ": \fs\f4" (editentity $n) "\fr " $desc) (concat gotoentity $n "; echo" (escape $desc)) + ][ + menuitem (concatword "Entity #" $n ": " $desc) -1 + ] + h = 0 + ] + if (pop h) [ + menuitem "no TODO entities" -1 + ][ + menuitem "" -1 + menuitem "\f3Clear list of TODO entities" cleartodoentities + ] +] + // sort config slots looplist [__mmsort __mmmerge __texsort __texmerge __sndsort __sndmerge] i [tempalias $i 1] diff --git a/config/resetbinds.cfg b/config/resetbinds.cfg index a1cd47fc..4e9b43b0 100644 --- a/config/resetbinds.cfg +++ b/config/resetbinds.cfg @@ -65,6 +65,7 @@ alias editkey_tagclip_none [ edittagclip none ] alias editkey_tagclip_plclip [ edittagclip plclip ] alias editkey_tagclip_clip [ edittagclip clip ] alias editkey_scroll_spawns [ domodifier spawns ] +alias editkey_scroll_todoents [ domodifier todoents ] _defaultbinds 1 // do not save the following binds to saved.cfg _resetallbinds diff --git a/config/scripts.cfg b/config/scripts.cfg index de53b903..a9356ed6 100644 --- a/config/scripts.cfg +++ b/config/scripts.cfg @@ -242,6 +242,7 @@ delta_edit_attr5 = [ entproperty 4 $arg2 $editmeta2down ] // Changes the fifth delta_edit_attr6 = [ entproperty 5 $arg2 $editmeta2down ] // Changes the sixth value on entities... delta_edit_attr7 = [ entproperty 6 $arg2 $editmeta2down ] // Changes the seventh value on entities... delta_edit_spawns = [ gotonextplayerstart $arg1 ] +delta_edit_todoents = [ gotonexttodoentity $arg1 ] delta_game_spawns = [] // Scroll console (in all modes) @@ -367,6 +368,24 @@ const gotonextplayerstart [ pop n sl ] +// cycle through todo entities +const gotonexttodoentity [ + if (&& (!= $arg1 1) (!= $arg1 -1)) [ arg1 = 1 ] + if (! (checkalias __gotonexttodoentity)) [ tempalias __gotonexttodoentity -1 ] + push l (enumtodoentities) + push n (div (listlen $l) 2) + if (&& $n $editing) [ + __gotonexttodoentity = (mod (+ $n $n $arg1 $__gotonexttodoentity) $n) + looplisti $l [e desc] [ + if (= $i $__gotonexttodoentity) [ + gotoentity $e + echo (concatword "TODO entity #" $e ": \fs\f4" (editentity $e) "\fr ") $desc + ] + ] + ] + pop n l +] + // select whole map const selectall [ select 2 2 (- (powf 2 (mapsize)) 4) (- (powf 2 (mapsize)) 4) diff --git a/source/src/protos.h b/source/src/protos.h index e9537b6d..32623044 100644 --- a/source/src/protos.h +++ b/source/src/protos.h @@ -617,6 +617,10 @@ extern void remipmore(const block &b, int level = 0); extern bool pinnedclosestent; extern int closestent(); extern void deletesoundentity(entity &e); +extern vector todoents; +extern vector todoentdescs; +extern void cleartodoentities(const char *n = NULL); +extern void addtodoentity(int n, const char *desc); extern int findtype(const char *what); extern int findentity(int type, int index = 0); extern int findentity(int type, int index, uchar attr2); diff --git a/source/src/world.cpp b/source/src/world.cpp index 278fea91..f6c94907 100644 --- a/source/src/world.cpp +++ b/source/src/world.cpp @@ -524,6 +524,42 @@ void enumentities(char *type) } COMMAND(enumentities, "s"); +vector todoents; +vector todoentdescs; + +void cleartodoentities(const char *n) +{ + int ni = n ? ATOI(n) : -1; + if(!n || !*n || ni < 0) + { + todoents.setsize(0); + todoentdescs.deletearrays(); + } + else loopvrev(todoents) if(todoents[i] == ni) + { + todoents.remove(i); + delstring(todoentdescs.remove(i)); + } +} +COMMAND(cleartodoentities, "s"); + +void addtodoentity(int n, const char *desc) +{ + todoents.add(n); + todoentdescs.add(newstring(desc)); +} +COMMANDF(addtodoentity, "is", (int *n, const char *desc) { if(ents.inrange(*n)) addtodoentity(*n, desc); }); + +void enumtodoentities() +{ + vector res; + loopv(todoents) cvecprintf(res, "%d %s\n", todoents[i], escapestring(todoentdescs[i], true)); + if(!res.length()) res.add('\0'); + else res.last() = '\0'; + result(res.getbuf()); +} +COMMAND(enumtodoentities, ""); + void scalecomp(uchar &c, int intens) { int n = c*intens/100; diff --git a/source/src/worldio.cpp b/source/src/worldio.cpp index f0de5d50..919696a0 100644 --- a/source/src/worldio.cpp +++ b/source/src/worldio.cpp @@ -874,6 +874,7 @@ int load_world(char *mname) // still supports all map formats that have e mapoverride_nostencilshadows = (hdr.flags & MHF_DISABLESTENCILSHADOWS) ? 1 : 0; // read and convert all entities + cleartodoentities(); persistent_entity *tempents = new persistent_entity[hdr.numents]; bool oldentityformat = hdr.version < 10; // version < 10 have only 4 attributes and no scaling loopi(hdr.numents) @@ -899,7 +900,8 @@ int load_world(char *mname) // still supports all map formats that have e if((ss = abs(entwraparound[e.type][x - 1] / entscale[e.type][x - 1]))) e.attr##x = (int(e.attr##x) % ss + ss) % ss; \ e.attr##x = ov = e.attr##x * entscale[e.type][x - 1]; \ if(ov != e.attr##x) { conoutf("overflow during conversion of attr%d of entity #%d (%s): value %d can no longer be represented - pls fix manually before saving the map",\ - x, i, entnames[e.type], oe.attr##x); e.attr##x = oe.attr##x; res |= LWW_ENTATTROVERFLOW; } + x, i, entnames[e.type], oe.attr##x); e.attr##x = oe.attr##x; res |= LWW_ENTATTROVERFLOW; \ + defformatstring(desc)("%s: attr%d was %d, value can no longer be represented", entnames[e.type], x, oe.attr##x); addtodoentity(i, desc); } SCALEATTR(1); SCALEATTR(2); SCALEATTR(3); @@ -1115,6 +1117,8 @@ struct xmap vector headerextras; vector ents, delents; vector mapconfig; + vector todoents; + vector todoentdescs; sqr *world; header hdr; int ssize, cubicsize, numundo; @@ -1139,6 +1143,7 @@ struct xmap vector tmp; // add undo/redo data in compressed form as temporary headerextra numundo = backupeditundo(tmp, MAXHEADEREXTRA, MAXHEADEREXTRA); headerextras.add(new headerextra(tmp.length(), HX_EDITUNDO, tmp.getbuf())); + loopv(::todoents) { todoents.add(::todoents[i]); todoentdescs.add(newstring(::todoentdescs[i])); } } ~xmap() @@ -1148,6 +1153,8 @@ struct xmap ents.setsize(0); delents.setsize(0); mapconfig.setsize(0); + todoents.setsize(0); + todoentdescs.deletearrays(); } void restoreent(int i) @@ -1191,6 +1198,8 @@ struct xmap loadskymap(true); startmap(name, false, true); // "start" but don't respawn: basically just set clientmap restoreposition(position); + cleartodoentities(); + loopv(todoents) addtodoentity(todoents[i], todoentdescs[i]); } void write(stream *f) // write xmap as cubescript to a file @@ -1228,6 +1237,7 @@ struct xmap } delstring(t); } + loopv(todoents) f->printf("restorexmap todoent %d %s\n", todoents[i], escapestring(todoentdescs[i])); f->printf("restorexmap position %d %d %d %d %d // EOF, don't touch this\n\n", int(position[0]), int(position[1]), int(position[2]), int(position[3]), int(position[4])); } }; @@ -1351,8 +1361,8 @@ COMMANDF(xmap_restore, "s", (const char *nick) // use xmap as current map void restorexmap(char **args, int numargs) // read an xmap from a cubescript file { - const char *cmdnames[] = { "version", "names", "sizes", "header", "world", "headerextra", "ent", "delent", "config", "position", "" }; - const char cmdnumarg[] = { 3, 2, 3, 0, 0, 1, 11, 11, 1, 5 }; + const char *cmdnames[] = { "version", "names", "sizes", "header", "world", "headerextra", "ent", "delent", "config", "todoent", "position", "" }; + const char cmdnumarg[] = { 3, 2, 3, 0, 0, 1, 11, 11, 1, 2, 5 }; if(!xmjigsaw || numargs < 1) return; // { conoutf("restorexmap out of context"); return; } bool abort = false; @@ -1403,7 +1413,11 @@ void restorexmap(char **args, int numargs) // read an xmap from a cubescript f case 8: // config cvecprintf(xmjigsaw->mapconfig, "%s\n", args[1]); break; - case 9: // position - this is also the last command and will finish the xmap + case 9: // todoent + xmjigsaw->todoents.add(ATOI(args[1])); + xmjigsaw->todoentdescs.add(args[2]); + break; + case 10: // position - this is also the last command and will finish the xmap { loopi(5) xmjigsaw->position[i] = ATOI(args[i + 1]); int i;