ref: 5f46149bb72df55aecbe51fd6faec2dc3b36ef1a
parent: f7927e23bd580bca048fb9eba61d59959722de44
author: qwx <qwx@sciops.net>
date: Wed May 12 03:55:55 EDT 2021
drw: basic drawing functions and minor intro corrections
--- a/dat.h
+++ b/dat.h
@@ -58,11 +58,11 @@
extern Pic pics[PCend], canvas;
enum{
- DShip = 0xbb0000ff,
- DHud1 = 0x313131ff,
- DHud2 = 0x808591ff,
- DFace = 0x323232ff,
- DAmmo = 0x828282ff,
+ DShip = 0xffbb0000,
+ DHud1 = 0xff313131,
+ DHud2 = 0xff808591,
+ DFace = 0xff323232,
+ DAmmo = 0xff828282,
};
extern void (*step)(void);
--- a/drw.c
+++ b/drw.c
@@ -9,7 +9,6 @@
Pic pics[PCend], canvas;
static u32int fb[Vw * Vfullh];
-
static int scale, fbsz;
static Rectangle fbsr;
static Image *fbs;
@@ -18,17 +17,39 @@
void
scrollpic(Pic *pp, int Δx)
{
- // FIXME: scroll pic into canvas
- // scrollpic(&pics[PCspace], tc / scrollΔtc % pics[PCspace].w);
- // instead we just pass tc / scrollΔtc and do MOD here with pp->w
- USED(pp,Δx);
+ int h, w;
+ u32int *s, *d;
+
+ d = canvas.p;
+ s = pp->p + Δx % pp->w;
+ for(h=0; h<canvas.h; h++){
+ for(w=0; w<canvas.w; w++){
+ if(*s >> 24)
+ *d = *s;
+ d++, s++;
+ }
+ s += pp->w - canvas.w;
+ }
}
void
-drawstr(int x, int y, char *s)
+drawpic(int x, int y, Pic *pp)
{
- // FIXME
- USED(x,y,s);
+ int w, pw;
+ u32int *d, *s, *e;
+
+ d = fb + Vw * y + x;
+ s = pp->p;
+ pw = pp->w;
+ e = s + pw * pp->h;
+ while(s < e){
+ for(w=0; w<pw; w++){
+ if(*s >> 24)
+ *d = *s;
+ d++, s++;
+ }
+ d += Vw - pw;
+ }
}
void
@@ -36,27 +57,37 @@
{
// FIXME
USED(x,y,s,e);
+ //use a drawsubpic?
}
void
-drawline(int x, int y, int w, int h, u32int col)
+drawstr(int x, int y, char *s)
{
// FIXME
- USED(x,y,w,h,col);
+ USED(x,y,s);
}
void
-drawpic(int x, int y, Pic *pp)
+drawrect(int x, int y, int w, int h, u32int col)
{
- // FIXME: draw pp at x,y
- USED(x,y,pp);
+ int n;
+ u32int *d;
+
+ d = fb + Vw * y + x;
+ while(h-- > 0){
+ for(n=0; n<w; n++)
+ *d++ = col;
+ d += Vw - w;
+ }
}
void
drawfill(u32int col)
{
- // FIXME: fill window/vis area/rect with color
- USED(col);
+ u32int *p;
+
+ for(p=fb; p<fb+nelem(fb); p++)
+ *p = col;
}
static void
@@ -91,7 +122,7 @@
Rectangle r;
if(scale == 1){
- loadimage(fbs, fbs->r, (uchar*)fb, fbsz);
+ loadimage(fbs, fbs->r, (uchar*)fb, sizeof fb);
draw(screen, fbsr, fbs, nil, ZP);
}else{
drawscaled();
--- a/fns.h
+++ b/fns.h
@@ -1,12 +1,12 @@
void enterloadmap(void);
void enterintro(void);
int advclock(void);
-void setfsm(void (*)(void), void (*)(Rune));
+void setfsm(void (*)(void), void (*)(Rune), int);
void initfsm(void);
void scrollpic(Pic*, int);
void drawsubstr(int, int, char*, char*);
void drawstr(int, int, char*);
-void drawline(int, int, int, int, u32int);
+void drawrect(int, int, int, int, u32int);
void drawpic(int, int, Pic*);
void drawfill(u32int);
void drawfb(void);
--- a/fsm.c
+++ b/fsm.c
@@ -30,12 +30,13 @@
}
void
-setfsm(void (*stepfn)(void), void (*inputfn)(Rune))
+setfsm(void (*stepfn)(void), void (*inputfn)(Rune), int clear)
{
step = stepfn;
input = inputfn;
t0 = nsec();
- tc = 0;
+ if(clear)
+ tc = 0;
}
void
--- a/fsm.intro.c
+++ b/fsm.intro.c
@@ -44,23 +44,23 @@
{
int x, y;
- x = Vcenterx + tc / TshipΔx;
+ x = canvmidx + tc / TshipΔx;
y = Vcentery + 22 - tc / TshipΔy;
- drawline(x, y - 1, 10, 1, DShip);
- drawline(x + 4, canvmidy, 1, y - canvmidy - 1, DShip);
- drawline(x, y + 9, 10, 1, DShip);
- drawline(x + 4, y + 9, 1, canvmidy + canvas.h - y - 9, DShip);
+ drawrect(x, y - 1, 10, 1, DShip);
+ drawrect(x + 4, canvmidy, 1, y - canvmidy - 1, DShip);
+ drawrect(x, y + 9, 10, 1, DShip);
+ drawrect(x + 4, y + 9, 1, canvmidy + canvas.h - y - 9, DShip);
if(x - 1 > canvmidx)
- drawline(x - 1, y, 1, 10, DShip);
- drawline(canvmidx, y + 4, x - 1 - canvmidx + canvas.w, 1, DShip);
- drawline(x + 9, y, 1, 9, DShip);
- drawline(x + 9, y + 4, canvmidx + canvas.w - x - 9, 1, DShip);
+ drawrect(x - 1, y, 1, 10, DShip);
+ drawrect(canvmidx, y + 4, x - 1 - canvmidx, 1, DShip);
+ drawrect(x + 9, y, 1, 9, DShip);
+ drawrect(x + 9, y + 4, canvmidx + canvas.w - x - 9, 1, DShip);
}
static void
drawship(void)
{
- drawpic(Vcenterx + tc / TshipΔx, Vh / 2 + 22 - tc / TshipΔy, &pics[PCship]);
+ drawpic(canvmidx + tc / TshipΔx, Vh / 2 + 22 - tc / TshipΔy, &pics[PCship]);
}
static void
@@ -155,17 +155,17 @@
if(stri < strlen(curstr))
stri = strlen(curstr);
else if(step == intro1step){
- setfsm(intro2step, introkey);
+ setfsm(intro2step, introkey, 0);
curstr = basestr[BSintro2];
stri = 0;
steptc = 0;
}else if(step == intro2step){
- setfsm(intro3step, introkey);
+ setfsm(intro3step, introkey, 1);
scrollΔtc = Tbg2scroll;
scroll2Δtc = Tbg1scroll;
steptc = 0;
}else if(step == intro3step){
- setfsm(intro4step, introkey);
+ setfsm(intro4step, introkey, 1);
curstr = basestr[BSintro3];
prompt = basestr[BScontinue];
promptΔx = 8 - 4;
@@ -183,7 +183,7 @@
canvas.h = pics[PCplanets].h;
canvmidx = Vcenterx - canvas.w / 2;
canvmidy = Vcentery - canvas.h / 2;
- setfsm(intro1step, introkey);
+ setfsm(intro1step, introkey, 1);
curstr = basestr[BSintro1];
prompt = basestr[BSmore];
promptΔx = 36 - 30;