From: John Tsiombikas Date: Mon, 2 Sep 2024 18:25:31 +0000 (+0300) Subject: foobar X-Git-Url: http://git.mutantstargoat.com/user/nuclear/?a=commitdiff_plain;h=HEAD;p=comjam24 foobar --- diff --git a/Makefile b/Makefile index 584997a..4a07dd8 100644 --- a/Makefile +++ b/Makefile @@ -1,9 +1,9 @@ !ifdef __UNIX__ -obj = src/dos/main.obj src/dos/video.obj src/gamescr.obj src/menuscr.obj & - src/voxscape.obj src/lut.obj +obj = src/dos/main.obj src/dos/video.obj src/game.obj src/gamescr.obj & + src/menuscr.obj src/voxscape.obj src/lut.obj !else -obj = src\dos\main.obj src\dos\video.obj src\gamescr.obj src\menuscr.obj & - src\voxscape.obj src\lut.obj +obj = src\dos\main.obj src\dos\video.obj src\game.obj src\gamescr.obj & + src\menuscr.obj src\voxscape.obj src\lut.obj !endif bin = game.com diff --git a/src/dos/main.c b/src/dos/main.c index bc8d89d..46971ca 100644 --- a/src/dos/main.c +++ b/src/dos/main.c @@ -10,7 +10,7 @@ static int quit; int main(void) { - if(init_screens() == -1) { + if(init_game() == -1) { return 1; } diff --git a/src/game.c b/src/game.c index d543b61..ce59c4f 100644 --- a/src/game.c +++ b/src/game.c @@ -1,13 +1,24 @@ +#include +#include +#include +#include "video.h" #include "game.h" int gamescr_init(void); int menuscr_init(void); +float fov; +int znear, zfar; + struct screen *scrlist[NUM_SCREENS]; struct screen *curscr; -int init_screens(void) +int init_game(void) { + fov = 30.0f; + znear = 2; + zfar = 85; + if(menuscr_init() == -1) { return -1; } @@ -28,3 +39,16 @@ int change_screen(struct screen *scr) curscr = scr; return 0; } + +void panic(const char *fmt, ...) +{ + va_list ap; + + close_video(); + + va_start(ap, fmt); + vfprintf(stderr, fmt, ap); + va_end(ap); + + exit(1); +} diff --git a/src/game.h b/src/game.h index e4cbf98..c224c8e 100644 --- a/src/game.h +++ b/src/game.h @@ -15,13 +15,16 @@ struct screen { void (*keypress)(int key); }; +extern float fov; +extern int znear, zfar; + extern struct screen *scrlist[NUM_SCREENS]; extern struct screen *curscr; #define FBWIDTH 320 #define FBHEIGHT 200 -int init_screens(void); +int init_game(void); int change_screen(struct screen *scr); void panic(const char *fmt, ...); diff --git a/src/gamescr.c b/src/gamescr.c index cd4b4b8..6cdc36d 100644 --- a/src/gamescr.c +++ b/src/gamescr.c @@ -1,4 +1,8 @@ +#include #include "game.h" +#include "voxscape.h" + +#define VOXSZ 256 static int gamescr_start(void); static void gamescr_stop(void); @@ -11,18 +15,31 @@ static struct screen gamescr = { gamescr_keypress }; +static unsigned char far *hmap; +static unsigned char far *colmap; + int gamescr_init(void) { + scrlist[SCR_GAME] = &gamescr; return 0; } static int gamescr_start(void) { + if(!(hmap = _fmalloc(VOXSZ * VOXSZ))) { + panic("failed to allocate %dx%d heightmap", VOXSZ, VOXSZ); + } + if(!(colmap = _fmalloc(VOXSZ * VOXSZ))) { + panic("failed to allocate %dx%d texture", VOXSZ, VOXSZ); + } + vox_init(VOXSZ, VOXSZ, hmap, colmap); + vox_proj(fov, znear, zfar); return 0; } static void gamescr_stop(void) { + _ffree(hmap); } static void gamescr_draw(void) diff --git a/src/voxscape.c b/src/voxscape.c index 51ef3af..0fbec4e 100644 --- a/src/voxscape.c +++ b/src/voxscape.c @@ -17,7 +17,7 @@ #define NO_LERP #define XLERP(a, b, t, fp) \ - ((((a) << (fp)) + ((b) - (a)) * (t)) >> fp) + ((((int32_t)(a) << (fp)) + (int32_t)((b) - (a)) * (t)) >> (fp)) enum { SLICELEN = 1 @@ -34,7 +34,8 @@ static int vox_horizon; static int32_t vox_x, vox_y, vox_angle; static int vox_vheight; /* projection */ -static int vox_fov, vox_znear, vox_zfar; +static float vox_fov; +static int vox_znear, vox_zfar; static int vox_nslices; static int32_t far *vox_slicelen; @@ -45,11 +46,22 @@ static int vox_num_obj, vox_obj_stride; int far *projlut; -int vox_init(int xsz, int ysz, uint8_t far *himg, uint8_t far *cimg) +void vox_init(int x, int y, uint8_t far *himg, uint8_t far *cimg) { vox_hmap = himg; vox_color = cimg; + xsz = x; + ysz = y; + xmask = x - 1; + ymask = y - 1; + + xshift = 0; + while(x > 1) { + xshift++; + x >>= 1; + } + vox_fb = 0; vox_coltop = 0; vox_horizon = 0; @@ -62,8 +74,6 @@ int vox_init(int xsz, int ysz, uint8_t far *himg, uint8_t far *cimg) projlut = 0; vox_vheight = 80; - - return 0; } void vox_destroy(void) @@ -107,7 +117,7 @@ int vox_view(int32_t x, int32_t y, int h, int32_t angle) return h; } -void vox_proj(int fov, int znear, int zfar) +void vox_proj(float fov, int znear, int zfar) { vox_fov = fov; vox_znear = znear; @@ -149,7 +159,7 @@ void vox_begin(void) _fmemset(vox_coltop, 0, FBWIDTH * sizeof *vox_coltop); if(!(vox_valid & SLICELEN)) { - float theta = (float)vox_fov * M_PI / 360.0f; /* half angle */ + float theta = vox_fov * M_PI / 360.0f; /* half angle */ for(i=0; i> 16) & ymask) << xshift) + ((x >> 16) & xmask); if(offs == last_offs) { @@ -227,13 +237,13 @@ void vox_sky_solid(uint8_t color) void vox_sky_grad(uint8_t chor, uint8_t ctop) { - int i, j, colheight, t; - int d = FBHEIGHT - vox_horizon; + int i, j, colheight; + int32_t t, d = FBHEIGHT - vox_horizon; uint8_t grad[FBHEIGHT]; uint16_t *fbptr; for(i=0; i