games/snes: do message display in screenproc
do the message drawing from the screenproc so there are no race conditions with libdraw.
This commit is contained in:
parent
dc2c8dca5b
commit
5a6131ea09
1 changed files with 16 additions and 12 deletions
|
@ -13,7 +13,7 @@ int nprg, nsram, hirom, battery;
|
||||||
|
|
||||||
int ppuclock, spcclock, dspclock, stimerclock, saveclock, msgclock, paused, perfclock, cpupause;
|
int ppuclock, spcclock, dspclock, stimerclock, saveclock, msgclock, paused, perfclock, cpupause;
|
||||||
Mousectl *mc;
|
Mousectl *mc;
|
||||||
Channel *flushc;
|
Channel *flushc, *msgc;
|
||||||
QLock pauselock;
|
QLock pauselock;
|
||||||
u32int keys;
|
u32int keys;
|
||||||
int savefd, scale, profile, mouse, loadreq, savereq;
|
int savefd, scale, profile, mouse, loadreq, savereq;
|
||||||
|
@ -191,14 +191,16 @@ void
|
||||||
screenproc(void *)
|
screenproc(void *)
|
||||||
{
|
{
|
||||||
extern uchar pic[256*239*2*3];
|
extern uchar pic[256*239*2*3];
|
||||||
|
char *s;
|
||||||
Mouse m;
|
Mouse m;
|
||||||
Point p;
|
Point p;
|
||||||
|
|
||||||
enum { AMOUSE, ARESIZE, AFLUSH, AEND };
|
enum { AMOUSE, ARESIZE, AFLUSH, AMSG, AEND };
|
||||||
Alt a[AEND+1] = {
|
Alt a[AEND+1] = {
|
||||||
{ mc->c, &m, CHANRCV },
|
{ mc->c, &m, CHANRCV },
|
||||||
{ mc->resizec, nil, CHANRCV },
|
{ mc->resizec, nil, CHANRCV },
|
||||||
{ flushc, nil, CHANRCV },
|
{ flushc, nil, CHANRCV },
|
||||||
|
{ msgc, &s, CHANRCV },
|
||||||
{ nil, nil, CHANEND }
|
{ nil, nil, CHANEND }
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -245,6 +247,14 @@ screenproc(void *)
|
||||||
}
|
}
|
||||||
flushimage(display, 1);
|
flushimage(display, 1);
|
||||||
break;
|
break;
|
||||||
|
case AMSG:
|
||||||
|
draw(screen, rectaddpt(Rect(10, 10, 200, 30), screen->r.min), bg, nil, ZP);
|
||||||
|
if(s != nil){
|
||||||
|
string(screen, addpt(screen->r.min, Pt(10, 10)), display->black, ZP,
|
||||||
|
display->defaultfont, s);
|
||||||
|
free(s);
|
||||||
|
}
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -253,16 +263,11 @@ void
|
||||||
timing(void)
|
timing(void)
|
||||||
{
|
{
|
||||||
static vlong old;
|
static vlong old;
|
||||||
static char buf[32];
|
|
||||||
vlong new;
|
vlong new;
|
||||||
|
|
||||||
new = nsec();
|
new = nsec();
|
||||||
if(new != old)
|
if(new != old)
|
||||||
sprint(buf, "%6.2f%%", 1e11 / (new - old));
|
message("%6.2f%%", 1e11 / (new - old));
|
||||||
else
|
|
||||||
buf[0] = 0;
|
|
||||||
draw(screen, rectaddpt(Rect(10, 10, 200, 30), screen->r.min), bg, nil, ZP);
|
|
||||||
string(screen, addpt(screen->r.min, Pt(10, 10)), display->black, ZP, display->defaultfont, buf);
|
|
||||||
old = nsec();
|
old = nsec();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -310,6 +315,7 @@ usage:
|
||||||
if(initdraw(nil, nil, argv0) < 0)
|
if(initdraw(nil, nil, argv0) < 0)
|
||||||
sysfatal("initdraw: %r");
|
sysfatal("initdraw: %r");
|
||||||
flushc = chancreate(sizeof(ulong), 1);
|
flushc = chancreate(sizeof(ulong), 1);
|
||||||
|
msgc = chancreate(sizeof(char*), 0);
|
||||||
mc = initmouse(nil, screen);
|
mc = initmouse(nil, screen);
|
||||||
if(mc == nil)
|
if(mc == nil)
|
||||||
sysfatal("initmouse: %r");
|
sysfatal("initmouse: %r");
|
||||||
|
@ -367,7 +373,7 @@ usage:
|
||||||
if(msgclock > 0){
|
if(msgclock > 0){
|
||||||
msgclock -= t;
|
msgclock -= t;
|
||||||
if(msgclock <= 0){
|
if(msgclock <= 0){
|
||||||
draw(screen, screen->r, bg, nil, ZP);
|
sendp(msgc, nil); /* clear message */
|
||||||
msgclock = 0;
|
msgclock = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -389,11 +395,9 @@ void
|
||||||
message(char *fmt, ...)
|
message(char *fmt, ...)
|
||||||
{
|
{
|
||||||
va_list va;
|
va_list va;
|
||||||
static char buf[512];
|
|
||||||
|
|
||||||
va_start(va, fmt);
|
va_start(va, fmt);
|
||||||
vsnprint(buf, sizeof buf, fmt, va);
|
sendp(msgc, vsmprint(fmt, va));
|
||||||
string(screen, Pt(10, 10), display->black, ZP, display->defaultfont, buf);
|
|
||||||
msgclock = FREQ;
|
msgclock = FREQ;
|
||||||
va_end(va);
|
va_end(va);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue