ref: 4c2c9c8892686ad0a04ec93222a1f51fdafdf4f3
parent: a4c273b2345da84aaa0409096965b4b3146f7eb6
author: qwx <[email protected]>
date: Sun Aug 15 20:09:32 EDT 2021
M ./drw.c M ./fns.h M ./path.c M ./sce.c M ./sim.c M ./sim.move.c M ./util.c util: normalize debug prints, add mobjfmt
--- a/drw.c
+++ b/drw.c
@@ -81,7 +81,7 @@
i = fbvis[vp.y * fbw + vp.x];
mo = i == -1 ? nil : visbuf[i];
if(mo == it){
- dprint("select: %#p not moving to itself\n", it);
+ dprint("select: %M not moving to itself\n", it);
return;
}
p = divpt(addpt(subpt(p, selr.min), pan), scale);
@@ -88,7 +88,7 @@
p.x /= Nodewidth;
p.y /= Nodeheight;
if(nodemapwidth - p.x < it->o->w || nodemapheight - p.y < it->o->h){
- dprint("select: %#p not moving beyond map edge\n", it);
+ dprint("select: %M not moving beyond map edge\n", it);
return;
}
if(mo != nil)
@@ -316,7 +316,7 @@
n = mo->state;
if(n < 0 || n > OSend){
- dprint("frm: %s invalid animation frame %d\n", mo->o->name, n);
+ dprint("frm: %M invalid animation frame %d\n", mo, n);
return nil;
}
pp = &mo->o->pics[n][type];
--- a/fns.h
+++ b/fns.h
@@ -59,6 +59,7 @@
u64int* bload(int, int, int, int, int, int, int, int);
void bset(int, int, int, int, int);
void initbmap(void);
+int mobjfmt(Fmt*);
void dprint(char *, ...);
int max(int, int);
int min(int, int);
@@ -68,3 +69,4 @@
vlong flen(int);
#pragma varargck argpos dprint 1
+#pragma varargck type "M" Mobj*
--- a/path.c
+++ b/path.c
@@ -492,7 +492,7 @@
return;
}
mo->goalblocked = 1;
- dprint("setgoal: moving goal %d,%d in block %#p ", p->x, p->y, block);
+ dprint("%M setgoal: moving goal %d,%d in block %#p ", mo, p->x, p->y, block);
pm = nodemap + p->y * nodemapwidth + p->x;
pm->x = p->x;
pm->y = p->y;
@@ -549,7 +549,7 @@
{
Node *a, *b, *n;
- dprint("findpath %d,%d → %d,%d\n", mo->x, mo->y, p.x, p.y);
+ dprint("%M findpath to %d,%d\n", mo, p.x, p.y);
clearpath();
a = nodemap + mo->y * nodemapwidth + mo->x;
a->x = mo->x;
@@ -564,13 +564,13 @@
markmobj(mo, 0);
n = a∗(a, b, mo);
if(n != b){
- dprint("findpath: goal unreachable\n");
+ dprint("%M findpath: goal unreachable\n", mo);
if((n = nearest) == a || n == nil || a->h < n->h){
werrstr("a∗: can't move");
markmobj(mo, 1);
return -1;
}
- dprint("nearest: %#p %d,%d dist %f\n", n, n->x, n->y, n->h);
+ dprint("%M nearest: %#p %d,%d dist %f\n", mo, n, n->x, n->y, n->h);
b = nearestnonjump(n, b, mo);
if(b == a){
werrstr("a∗: really can't move");
--- a/sce.c
+++ b/sce.c
@@ -191,6 +191,7 @@
if(prefix == nil)
prefix = smprint("/sys/games/lib/%s", progname);
srand(time(nil));
+ fmtinstall('M', mobjfmt);
initfs();
initsv(tv, *argv);
initcl();
--- a/sim.c
+++ b/sim.c
@@ -66,12 +66,12 @@
mo->actp->cleanupfn(mo);
mo->actp++;
if((mo->state = mo->actp->os) == OSskymaybe){
- dprint("A nextaction %s %#p: done\n", mo->o->name, mo);
+ dprint("%M nextaction: done\n", mo);
mo->actp = nil;
popcommand(mo);
return;
}
- dprint("A nextaction %s %#p: %s\n", mo->o->name, mo, mo->actp->name);
+ dprint("%M nextaction: %s\n", mo, mo->actp->name);
}
int
@@ -79,7 +79,7 @@
{
mo->actp = a;
mo->state = a->os;
- dprint("A pushaction %s %#p: %s\n", mo->o->name, mo, a->name);
+ dprint("%M pushaction: %s\n", mo, a->name);
return 0;
}
@@ -86,7 +86,6 @@
void
clearcommands(Mobj *mo)
{
- dprint("C clearcommand %s %#p: %s\n", mo->o->name, mo, mo->cmds[0].name);
if(mo->actp != nil && mo->actp->cleanupfn != nil)
mo->actp->cleanupfn(mo);
mo->actp = nil;
@@ -98,7 +97,7 @@
void
abortcommands(Mobj *mo)
{
- dprint("C abortcommand %s %#p: %s\n", mo->o->name, mo, mo->cmds[0].name);
+ dprint("%M abortcommand: %s\n", mo, mo->cmds[0].name);
clearcommands(mo);
}
@@ -105,7 +104,7 @@
void
popcommand(Mobj *mo)
{
- dprint("C popcommand %s %#p: %s\n", mo->o->name, mo, mo->cmds[0].name);
+ dprint("%M popcommand: %s\n", mo, mo->cmds[0].name);
if(--mo->ctail > 0){
memmove(mo->cmds, mo->cmds+1, mo->ctail * sizeof *mo->cmds);
mo->state = OSskymaybe;
@@ -118,7 +117,7 @@
{
Command *c;
- dprint("C pushcommand %s %#p\n", mo->o->name, mo);
+ dprint("%M pushcommand\n", mo);
if(mo->ctail >= nelem(mo->cmds)){
werrstr("command buffer overflow");
return nil;
--- a/sim.move.c
+++ b/sim.move.c
@@ -81,7 +81,7 @@
static void
movedone(Mobj *mo)
{
- dprint("mobj %s %#p successfully reached goal\n", mo->o->name, mo);
+ dprint("%M successfully reached goal\n", mo);
nextaction(mo);
}
@@ -167,8 +167,8 @@
/* disallow corner coasting */
if(x != mo->x && y != mo->y
&& (isblocked(x, mo->y, mo->o) || isblocked(mo->x, y, mo->o))){
- dprint("detected corner coasting %d,%d vs %d,%d\n",
- x, y, mo->x, mo->y);
+ dprint("%M detected corner coasting at %d,%d\n",
+ mo, x, y);
goto end;
}
mo->subpx = sx;
@@ -248,13 +248,13 @@
return;
if(continuemove(mo) < 0){
if(nerr > 1){
- fprint(2, "stepmove: %s %#p bug: infinite loop!\n", mo->o->name, mo);
+ fprint(2, "%M stepmove: bug: infinite loop!\n", mo);
return;
}
- dprint("stepmove: %s %#p failed moving to %d,%d from %d,%d: %r\n",
- mo->o->name, mo, mo->pathp->x, mo->pathp->y, mo->px, mo->py);
+ dprint("%M stepmove: failed moving from %d,%d to %d,%d: %r\n",
+ mo, mo->px, mo->py, mo->pathp->x, mo->pathp->y);
if(repath(mo->target, mo) < 0){
- dprint("stepmove: %s %#p moving towards target: %r\n", mo->o->name, mo);
+ dprint("%M stepmove: failed moving towards target: %r\n", mo);
abortcommands(mo);
return;
}
@@ -271,17 +271,15 @@
movedone(mo);
return;
}
- dprint("stepmove: %s %#p reached final node, but not target\n",
- mo->o->name, mo);
+ dprint("%M stepmove: reached final node, but not target\n", mo);
if(mo->goalblocked && isblocked(mo->target.x, mo->target.y, mo->o)){
- dprint("stepmove: %s %#p goal still blocked, stopping\n", mo->o->name, mo);
+ dprint("%M stepmove: goal still blocked, stopping\n", mo);
abortmove(mo);
return;
}
- dprint("stepmove: %s %#p trying again\n", mo->o->name, mo);
+ dprint("%M stepmove: trying again\n", mo);
if(mo->npatherr++ > 1 || repath(mo->target, mo) < 0){
- dprint("stepmove: %s %#p still can't reach target: %r\n",
- mo->o->name, mo);
+ dprint("%M stepmove: still can't reach target: %r\n", mo);
abortmove(mo);
return;
}
--- a/util.c
+++ b/util.c
@@ -18,6 +18,17 @@
return a < b ? a : b;
}
+int
+mobjfmt(Fmt *fmt)
+{
+ Mobj *mo;
+
+ mo = va_arg(fmt->args, Mobj*);
+ if(mo == nil)
+ return fmtstrcpy(fmt, "[]");
+ return fmtprint(fmt, "[%s:%#p:%d,%d]", mo->o->name, mo, mo->x, mo->y);
+}
+
void
dprint(char *fmt, ...)
{