ref: d472babe18c4d6f7bd9f04cff0ba93f0d0c078d5
parent: 861520c581d13762bcd2f9d9a08e8b69a0af30a9
author: qwx <qwx@sciops.net>
date: Sat Mar 15 21:41:04 EDT 2025
fix next piece queue
--- a/dat.h
+++ b/dat.h
@@ -59,7 +59,7 @@
#define T0 (double)BILLION / Tspeed0
extern char playfield[Ncol * Nrow];
extern int held;
-extern int hist[4];
+extern int next[4];
extern double T;
enum{
--- a/fns.h
+++ b/fns.h
@@ -4,6 +4,7 @@
void drop(void);
void gameover(void);
void step(void);
+void initgame(void);
void redraw(void);
void initimg(void);
void quit(void);
--- a/game.c
+++ b/game.c
@@ -8,8 +8,8 @@
char playfield[Ncol * Nrow];
Current *cur;
+int next[4];
int held = -1;
-int hist[4] = {FZ, FZ, FS, FS};
enum{
Nlineperlvl = 10,
@@ -16,7 +16,6 @@
Timeinc = BILLION / 10.0,
};
static vlong ncleared;
-
static int bfield[Nrow];
static u32int
@@ -34,6 +33,7 @@
getpiece(void)
{
int i, *h, r;
+ static int hist[4] = {FZ, FZ, FS, FS};
for(r=i=0; i<5; i++){
r = trand() % 7;
@@ -51,6 +51,18 @@
return r;
}
+static int
+nextpiece(void)
+{
+ int r, *p;
+
+ r = next[0];
+ for(p=next; p<next+nelem(next)-1; p++)
+ p[0] = p[1];
+ *p = getpiece();
+ return r;
+}
+
static void
spawn(void)
{
@@ -57,7 +69,7 @@
static Current cur0;
memset(&cur0, 0, sizeof cur0);
- cur0.type = getpiece();
+ cur0.type = nextpiece();
cur0.rot = Up;
cur0.x = Ncol / 2 - 2;
cur0.y = Nstartrow - Nextrarows - 1;
@@ -202,4 +214,13 @@
return;
}
cur->y++;
+}
+
+void
+initgame(void)
+{
+ int *p;
+
+ for(p=next; p<next+nelem(next); p++)
+ *p = getpiece();
}
--- a/gm4s.c
+++ b/gm4s.c
@@ -142,6 +142,7 @@
if(proccreate(ticproc, nil, 4096) < 0)
sysfatal("proccreate: %r");
srand(time(nil));
+ initgame();
enum{
Astep,
Akey,
--- a/piece.c
+++ b/piece.c
@@ -118,12 +118,12 @@
static void
drawui(void)
{
- int y, *h;
+ int y, *p;
if(held != -1)
drawfour(-1, Nrow / 2, 1, held);
- for(y=1, h=hist+1; h<hist+nelem(hist); h++, y+=5)
- drawfour(Wside + Wwidth, Nstartrow - Nextrarows + y, 1, *h);
+ for(y=1, p=next; p<next+nelem(next); p++, y+=5)
+ drawfour(Wside + Wwidth, Nstartrow - Nextrarows + y, 1, *p);
}
static void
--
⑨