summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--.gitignore5
-rw-r--r--CHANGELOG.txt14
-rw-r--r--CREDITS.txt11
-rw-r--r--bowshock/GNUmakefile48
-rw-r--r--bowshock/include/bow/bs.h24
-rw-r--r--bowshock/include/bow/gfx.h8
-rw-r--r--bowshock/include/bow/info.h9
-rw-r--r--bowshock/include/bow/lgc.h37
-rw-r--r--bowshock/include/bow/sav.h6
-rw-r--r--bowshock/source/bs/chkparams.c33
-rw-r--r--bowshock/source/bs/gendat.c17
-rw-r--r--bowshock/source/bs/help.c4
-rw-r--r--bowshock/source/bs/init.c72
-rw-r--r--bowshock/source/bs/initrnd.c11
-rw-r--r--bowshock/source/bs/initsig.c21
-rw-r--r--bowshock/source/bs/intro.c51
-rw-r--r--bowshock/source/bs/loop.c77
-rw-r--r--bowshock/source/bs/quit.c2
-rw-r--r--bowshock/source/bs/rnd.c17
-rw-r--r--bowshock/source/gfx/drw.c24
-rw-r--r--bowshock/source/gfx/initgfx.c16
-rw-r--r--bowshock/source/lgc/addobj.c3
-rw-r--r--bowshock/source/lgc/freeobjs.c3
-rw-r--r--bowshock/source/lgc/gensys.c65
-rw-r--r--bowshock/source/lgc/grav.c57
-rw-r--r--bowshock/source/lgc/mv.c19
-rw-r--r--bowshock/source/lgc/objtypstr.c (renamed from bowshock/source/info/objtypstr.c)2
-rw-r--r--bowshock/source/lgc/shipmass.c (renamed from bowshock/source/info/shipmass.c)2
-rw-r--r--bowshock/source/lgc/sim.c13
-rw-r--r--bowshock/source/sav/cont.c43
-rw-r--r--bowshock/source/sav/gendat.c17
-rw-r--r--bowshock/source/sav/rstart.c41
32 files changed, 477 insertions, 295 deletions
diff --git a/.gitignore b/.gitignore
index f80b73b..ea84b71 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,7 +1,6 @@
-/procyon
+/assets
*.elf
*.exe
*.o
-*.webp
-log.*
+*.zst
vgcore.*
diff --git a/CHANGELOG.txt b/CHANGELOG.txt
index beada9c..1cbfafd 100644
--- a/CHANGELOG.txt
+++ b/CHANGELOG.txt
@@ -1,3 +1,17 @@
+# 0.9.0
+
+* Fix compilation warning;
+* Optimise mechanical functions;
+* Add system generation routine;
+* Remove 'info' module;
+* Add intro;
+* Add terminal parameters;
+* Update units;
+* Make window fullscreen;
+* Resume time;
+* Update gitignore;
+* Make code more modular;
+
# 0.8.1
* Update renderer;
diff --git a/CREDITS.txt b/CREDITS.txt
index c5c2214..47fb90f 100644
--- a/CREDITS.txt
+++ b/CREDITS.txt
@@ -1 +1,10 @@
-Gabriel Jensen
+BOWSHOCK
+
+COPYRIGHT
+2022-2023 Gabriel Jensen
+
+LEAD DESIGN
+- Gabriel Jensen
+
+ARTWORK
+- Gabriel Jensen
diff --git a/bowshock/GNUmakefile b/bowshock/GNUmakefile
index cc6cc2c..3768123 100644
--- a/bowshock/GNUmakefile
+++ b/bowshock/GNUmakefile
@@ -48,23 +48,31 @@ CFLAGS := \
endif
OBJS := \
- source/bs/abrt.o \
- source/bs/gendat.o \
- source/bs/getquot.o \
- source/bs/getsavpth.o \
- source/bs/help.o \
- source/bs/init.o \
- source/bs/loop.o \
- source/bs/quit.o \
- source/gfx/drw.o \
- source/gfx/initgfx.o \
- source/info/objtypstr.o \
- source/info/shipmass.o \
- source/lgc/addobj.o \
- source/lgc/freeobjs.o \
- source/lgc/grav.o \
- source/lgc/mv.o \
- source/sav/cont.o \
+ source/bs/abrt.o \
+ source/bs/chkparams.o \
+ source/bs/getquot.o \
+ source/bs/getsavpth.o \
+ source/bs/help.o \
+ source/bs/init.o \
+ source/bs/initrnd.o \
+ source/bs/initsig.o \
+ source/bs/intro.o \
+ source/bs/loop.o \
+ source/bs/quit.o \
+ source/bs/rnd.o \
+ source/gfx/drw.o \
+ source/gfx/initgfx.o \
+ source/lgc/addobj.o \
+ source/lgc/freeobjs.o \
+ source/lgc/gensys.o \
+ source/lgc/grav.o \
+ source/lgc/mv.o \
+ source/lgc/objtypstr.o \
+ source/lgc/shipmass.o \
+ source/lgc/sim.o \
+ source/sav/gendat.o \
+ source/sav/cont.o \
+ source/sav/rstart.o \
source/sav/sav.o
LDLIBS := \
@@ -77,9 +85,9 @@ LDLIBS := \
BIN := bowshock.elf
HDRS := \
- include/bow/bs.h \
- include/bow/info.h \
- include/bow/lgc.h \
+ include/bow/bs.h \
+ include/bow/gfx.h \
+ include/bow/lgc.h \
include/bow/sav.h
.PHONY: clean purge
diff --git a/bowshock/include/bow/bs.h b/bowshock/include/bow/bs.h
index f03c0e4..22f3aec 100644
--- a/bowshock/include/bow/bs.h
+++ b/bowshock/include/bow/bs.h
@@ -43,8 +43,8 @@ static_assert(sizeof (double) == 0x8u);
#define bow_logxyz(xyz) bow_dbglog("%.03f %.03f %.03f",(xyz).x,(xyz).y,(xyz).z)
constexpr zap_i04 bow_vermaj = 0x0u;
-constexpr zap_i04 bow_vermin = 0x8u;
-constexpr zap_i04 bow_verpat = 0x1u;
+constexpr zap_i04 bow_vermin = 0x9u;
+constexpr zap_i04 bow_verpat = 0x0u;
#define bow_cmdrnmlen ((zap_sz)0xEu)
@@ -67,14 +67,32 @@ typedef struct bow_impl_playdat bow_playdat;
typedef struct bow_impl_gfxdat bow_gfxdat;
+typedef struct {
+ char const * savpth;
+ bool hassavpth:0x1u;
+ bool rstart:0x1u;
+ bool skip:0x1u;
+} bow_termopts;
+
extern sig_atomic_t volatile bow_gotintr;
+zap_i04 bow_rnd(void);
+
char const * bow_getsavpth(void);
bool bow_getquot( char const * * quot,char const * * src,zap_i8 id);
-bow_stat bow_loop(bow_gfxdat * gfxdat,bow_playdat * playdat);
+void bow_loop(bow_gfxdat * gfxdat,bow_playdat * playdat);
[[noreturn]] void bow_help(char const * prognm);
+void bow_chkparams(bow_termopts * opts,int argc,char const * const * argv);
+
+void bow_initrnd(void);
+void bow_initsig(void);
+
+bool bow_intro(bow_gfxdat * gfxdat);
+
+[[noreturn]] void bow_init(int argc,char const * const * argv);
+
[[noreturn]] void bow_abrt(void);
[[noreturn]] void bow_quit(bow_gfxdat * gfxdat,bow_stat stat);
diff --git a/bowshock/include/bow/gfx.h b/bowshock/include/bow/gfx.h
index 45e6761..2c19950 100644
--- a/bowshock/include/bow/gfx.h
+++ b/bowshock/include/bow/gfx.h
@@ -8,9 +8,11 @@
struct bow_impl_gfxdat {
GLFWwindow * win;
- int frmbufw;
- int frmbufh;
+ int frmw;
+ int frmh;
+ float zoom;
};
-void bow_drw( bow_gfxdat * gfxdat,bow_objroot * sys,bow_objroot * objs);
void bow_initgfx(bow_gfxdat * dat);
+
+void bow_drw(bow_gfxdat * gfxdat,bow_objroot * sys,bow_objroot * objs,float zoom);
diff --git a/bowshock/include/bow/info.h b/bowshock/include/bow/info.h
deleted file mode 100644
index d8ff852..0000000
--- a/bowshock/include/bow/info.h
+++ /dev/null
@@ -1,9 +0,0 @@
-// Copyright 2022-2023 Gabriel Jensen.
-
-#pragma once
-
-#include <bow/lgc.h>
-
-char const * bow_objtypstr(bow_objtyp typ);
-
-[[unsequenced]] double bow_shipmass(bow_ship id);
diff --git a/bowshock/include/bow/lgc.h b/bowshock/include/bow/lgc.h
index acf796b..6cbca87 100644
--- a/bowshock/include/bow/lgc.h
+++ b/bowshock/include/bow/lgc.h
@@ -60,11 +60,11 @@ typedef enum {
struct bow_impl_obj {
bow_objtyp typ;
- bow_xyz pos;
- bow_xyz rot; // radians
- bow_xyz posvel;
- bow_xyz rotvel;
- double mass;
+ bow_xyz pos; // astronomical units
+ bow_xyz rot; // radians
+ bow_xyz posvel; // astronomical units per second
+ bow_xyz rotvel; // radians per second
+ double mass; // kilograms
union {
bow_wrld wrldtyp;
bow_ship shiptyp;
@@ -85,15 +85,26 @@ struct bow_impl_playdat {
bow_obj ship;
};
-constexpr double bow_tmmod = 0x1p-14; // time modifier
+constexpr double bow_distmod = 0x1.16A5D2D3p37; // distance modifier (1 au)
+constexpr double bow_massmod = 0x1p0; // mass modifier
+constexpr double bow_tmmod = 0x1p12; // time modifier
-constexpr double bow_gravconst = 0x1.2589EFFFp-34/(bow_tmmod*bow_tmmod); // gravitational constant (s^2*m*t^2)
+constexpr double bow_gravconstfac = (bow_massmod*(bow_tmmod*bow_tmmod))/((bow_distmod*bow_distmod*bow_distmod)); // inverse
+
+constexpr double bow_gravconst = 0x1.2589EFFFp-34*bow_gravconstfac; // gravitational constant (s^2*m*t^2)
+
+char const * bow_objtypstr(bow_objtyp typ);
+
+[[unsequenced]] double bow_shipmass(bow_ship id);
+
+void bow_gravsys( bow_objroot * sys);
+void bow_gravobjs(bow_objroot * sys,bow_objroot * objs);
+void bow_mv( bow_obj * obj);
+void bow_mvobjs( bow_objroot * root);
+
+void bow_sim(bow_objroot * sys,zap_i04 dur);
bow_obj * bow_addobj( bow_objroot * root,bow_obj const * obj);
-void bow_freeobjs(bow_objroot const * root);
+void bow_freeobjs(bow_objroot * root);
-void bow_grav( bow_obj * obj, bow_obj * par);
-void bow_gravsys( bow_objroot const * sys);
-void bow_gravobjs(bow_objroot const * sys,bow_objroot const * objs);
-void bow_mv( bow_obj * obj);
-void bow_mvobjs( bow_objroot const * root);
+void bow_gensys(bow_objroot * sys,zap_i04 id,zap_i04 tm);
diff --git a/bowshock/include/bow/sav.h b/bowshock/include/bow/sav.h
index 1a0ff11..391f64f 100644
--- a/bowshock/include/bow/sav.h
+++ b/bowshock/include/bow/sav.h
@@ -53,7 +53,9 @@ typedef struct {
double shiprotvelz;
} bow_savdat;
-void bow_cont( char const * fil, bow_playdat * dat,bool skipld);
-void bow_gendat(bow_playdat * playdat);
+void bow_rstart(bow_playdat * dat);
+
+void bow_cont( bow_playdat * dat,char const * fil);
+void bow_gendat(bow_playdat * dat);
void bow_sav(char const * fil,bow_playdat const * dat);
diff --git a/bowshock/source/bs/chkparams.c b/bowshock/source/bs/chkparams.c
new file mode 100644
index 0000000..2926cae
--- /dev/null
+++ b/bowshock/source/bs/chkparams.c
@@ -0,0 +1,33 @@
+// Copyright 2022-2023 Gabriel Jensen.
+
+#include <bow/bs.h>
+
+#include <zap/mem.h>
+#include <zap/str.h>
+
+void bow_chkparams(bow_termopts * const optsptr,int const argc,char const * const * argv) {
+ char const * const prognm = *argv;
+ bow_termopts opts = {
+ .hassavpth = false,
+ .rstart = false,
+ .skip = false,
+ };
+ if (argc >= 0x2) {
+ char const * const * const stop = (argv++)+(zap_sz)argc;
+ for (;argv != stop;++argv) {
+ char const * param = *argv;
+ if (param[0x0u] == '-' && param[0x1u] == '-') {
+ param += 0x2u;
+ if (zap_streq(param,"help")) bow_help(prognm);
+ else if (zap_streq(param,"restart")) opts.rstart = true;
+ else if (zap_streq(param,"skip")) opts.skip = true;
+ else bow_logerr("invalid parameter \"%s\"",param);
+ continue;
+ }
+ // Else: Interpret it as a save path;
+ opts.savpth = param;
+ opts.hassavpth = true;
+ }
+ }
+ zap_cp(optsptr,&opts,sizeof (opts));
+}
diff --git a/bowshock/source/bs/gendat.c b/bowshock/source/bs/gendat.c
deleted file mode 100644
index 6d81876..0000000
--- a/bowshock/source/bs/gendat.c
+++ /dev/null
@@ -1,17 +0,0 @@
-// Copyright 2022-2023 Gabriel Jensen.
-
-#include <bow/info.h>
-#include <bow/sav.h>
-
-#include <zap/mem.h>
-
-#include <string.h>
-
-void bow_gendat(bow_playdat * const playdatptr) {
- bow_log("generating player data");
- bow_playdat playdat;
- zap_cp(&playdat,playdatptr,sizeof (playdat));
- playdat.ship.typ = bow_objtyp_ship;
- playdat.ship.mass = bow_shipmass(playdat.ship.shiptyp);
- zap_cp(playdatptr,&playdat,sizeof (playdat));
-}
diff --git a/bowshock/source/bs/help.c b/bowshock/source/bs/help.c
index d9dd430..c362d20 100644
--- a/bowshock/source/bs/help.c
+++ b/bowshock/source/bs/help.c
@@ -14,8 +14,8 @@ void bow_help(char const * const prognm) {
"Usage: %s <options> [savefile]\n"
"\n"
"Options:\n"
- " --help Print help screen.\n"
- " --reset Don't load save file.\n"
+ " --help Print help screen\n"
+ " --restart Generate default commander\n"
"\n",
bow_vermaj,bow_vermin,bow_verpat,prognm);
exit(EXIT_SUCCESS);
diff --git a/bowshock/source/bs/init.c b/bowshock/source/bs/init.c
index a001e6e..523eb35 100644
--- a/bowshock/source/bs/init.c
+++ b/bowshock/source/bs/init.c
@@ -5,44 +5,25 @@
#include <bow/sav.h>
#include <inttypes.h>
-#include <signal.h>
#include <stdlib.h>
-#include <time.h>
#include <zap/str.h>
-[[noreturn]] void bow_init(int argc,char const * const * argv);
-
-sig_atomic_t volatile bow_gotintr;
-
-static void bow_intrhandl(int const sig) {
- signal(sig,bow_intrhandl); // Ignore the return value.
- bow_gotintr = 0x1;
-}
-
-void bow_init(int const argc,char const * const * argv) {
- char const * const prognm = *argv;
- char const * savpth;
- bool hassavpth = false;
- bool skipsavld = false;
- if (argc >= 0x2) {
- char const * const * const stop = (argv++)+(zap_sz)argc;
- for (;argv != stop;++argv) {
- char const * param = *argv;
- if (param[0x0u] == '-' && param[0x1u] == '-') {
- param += 0x2u;
- if (zap_streq(param,"help")) bow_help(prognm);
- else if (zap_streq(param,"reset")) skipsavld = true;
- else bow_logerr("invalid parameter \"%s\"",param);
- continue;
- }
- // Else: Interpret it as a save path;
- savpth = param;
- hassavpth = true;
- }
- }
- srand((unsigned int)time(nullptr));
+void bow_init(int const argc,char const * const * const argv) {
+ bow_termopts opts;
+ bow_chkparams(&opts,argc,argv);
+ bow_rawlog("\x1B[0m\x1B[1mBowshock\x1B[0m %" PRIXLEAST64 ".%" PRIXLEAST64 ".%" PRIXLEAST64 " \u2013 Copyright 2022\u20102023 \x1B[1mGabriel Jensen\x1B[0m.\n\n",bow_vermaj,bow_vermin,bow_verpat);
+ bow_log("initialising");
+ bow_dbglog("debug mode is enabled");
+ bow_dbglog("angle unit: %f radians",0x1p0f);
+ bow_dbglog("distance unit: %f metres",bow_distmod);
+ bow_dbglog("mass unit: %f kilograms",bow_massmod);
+ bow_dbglog("time unit: %f seconds",bow_tmmod);
+ bow_gfxdat gfxdat;
+ bow_initrnd();
+ bow_initsig();
+ bow_initgfx(&gfxdat);
{
- zap_i8 const quotid = (unsigned int)rand() % 0x21u;
+ zap_i8 const quotid = (zap_i8)bow_rnd() % 0x21u;
char const * quot;
char const * src;
if (bow_getquot(&quot,&src,quotid)) {
@@ -51,22 +32,15 @@ void bow_init(int const argc,char const * const * argv) {
}
bow_rawlog("\n%s\n\u2014 %s\n\n",quot,src);
}
- bow_rawlog("\x1B[0m\x1B[1mBowshock\x1B[0m %" PRIXLEAST64 ".%" PRIXLEAST64 ".%" PRIXLEAST64 " \u2013 Copyright 2022\u20102023 \x1B[1mGabriel Jensen\x1B[0m.\n\n",bow_vermaj,bow_vermin,bow_verpat);
- bow_log("initialising");
- bow_dbglog("debug mode is enabled");
- bow_gotintr = 0x0;
- if (signal(SIGINT,bow_intrhandl) == SIG_ERR) {
- bow_log("unable to set signal handler");
- bow_abrt();
+ if (opts.skip || !bow_intro(&gfxdat)) {
+ if (!opts.hassavpth) opts.savpth = bow_getsavpth();
+ bow_playdat playdat;
+ if (opts.rstart) bow_rstart(&playdat);
+ else bow_cont(&playdat,opts.savpth);
+ bow_loop(&gfxdat,&playdat);
+ bow_sav(opts.savpth,&playdat);
+ if (!opts.hassavpth) free((char *)opts.savpth);
}
- if (!hassavpth) savpth = bow_getsavpth();
- bow_playdat playdat;
- bow_cont(savpth,&playdat,skipsavld);
- bow_gfxdat gfxdat;
- bow_initgfx(&gfxdat);
- bow_loop(&gfxdat,&playdat);
- bow_sav(savpth,&playdat);
- if (!hassavpth) free((char *)savpth);
bow_quit(&gfxdat,bow_stat_ok);
}
diff --git a/bowshock/source/bs/initrnd.c b/bowshock/source/bs/initrnd.c
new file mode 100644
index 0000000..d877f3b
--- /dev/null
+++ b/bowshock/source/bs/initrnd.c
@@ -0,0 +1,11 @@
+// Copyright 2022-2023 Gabriel Jensen.
+
+#include <bow/bs.h>
+
+#include <stdlib.h>
+#include <time.h>
+
+void bow_initrnd(void) {
+ bow_log("initialising random generator");
+ srand((unsigned int)time(nullptr));
+}
diff --git a/bowshock/source/bs/initsig.c b/bowshock/source/bs/initsig.c
new file mode 100644
index 0000000..35ceb59
--- /dev/null
+++ b/bowshock/source/bs/initsig.c
@@ -0,0 +1,21 @@
+// Copyright 2022-2023 Gabriel Jensen.
+
+#include <bow/bs.h>
+
+#include <signal.h>
+
+sig_atomic_t volatile bow_gotintr;
+
+static void bow_intrhandl(int const sig) {
+ signal(sig,bow_intrhandl); // Ignore the return value.
+ bow_gotintr = 0x1;
+}
+
+void bow_initsig(void) {
+ bow_log("initialising signal handlers");
+ bow_gotintr = 0x0;
+ if (signal(SIGINT,bow_intrhandl) == SIG_ERR) {
+ bow_log("unable to set signal handler");
+ bow_abrt();
+ }
+}
diff --git a/bowshock/source/bs/intro.c b/bowshock/source/bs/intro.c
new file mode 100644
index 0000000..8032405
--- /dev/null
+++ b/bowshock/source/bs/intro.c
@@ -0,0 +1,51 @@
+// Copyright 2022-2023 Gabriel Jensen.
+
+#include <bow/gfx.h>
+#include <bow/lgc.h>
+
+#include <GLFW/glfw3.h>
+#include <zap/mem.h>
+
+bool bow_intro(bow_gfxdat * const gfxdatptr) {
+ bow_log("starting intro");
+ bow_gfxdat gfxdat;
+ zap_cp(&gfxdat,gfxdatptr,sizeof (gfxdat));
+ bool quit = false;
+ GLfloat const bowr = 0x1.6D6D6D6Ep-1;
+ GLfloat const bowg = 0x1.81818182p-4;
+ GLfloat const bowb = 0x1.9999999Ap-3;
+ glClearColor(bowr,bowg,bowb,0x1p0);
+ glClear(GL_COLOR_BUFFER_BIT);
+ glfwSwapBuffers(gfxdat.win);
+ glfwSetTime(0x0p0);
+ for (double dur = 0x0p0;dur <= 0x3p0;dur = glfwGetTime()) {
+ glfwPollEvents();
+ if (bow_gotintr) {
+ bow_log("got interrupt");
+ glfwSetWindowShouldClose(gfxdat.win,GLFW_TRUE);
+ }
+ if (glfwWindowShouldClose(gfxdat.win)) break;
+ }
+ double const fadedur = 0x1p0;
+ glfwSetTime(0x0p0);
+ for (double fac = 0x0p0;fac <= fadedur;fac = glfwGetTime()) {
+ glfwPollEvents();
+ if (bow_gotintr) {
+ bow_log("got interrupt");
+ glfwSetWindowShouldClose(gfxdat.win,GLFW_TRUE);
+ }
+ if (glfwWindowShouldClose(gfxdat.win)) break;
+ GLfloat const r = bowr-fac/fadedur;
+ GLfloat const g = bowg-fac/fadedur;
+ GLfloat const b = bowb-fac/fadedur;
+ glClearColor(r,g,b,0x1p0);
+ glClear(GL_COLOR_BUFFER_BIT);
+ glfwSwapBuffers(gfxdat.win);
+ }
+ glClearColor(0x0p0,0x0p0,0x0p0,0x1p0);
+ glClear(GL_COLOR_BUFFER_BIT);
+ glfwSwapBuffers(gfxdat.win);
+ if (glfwWindowShouldClose(gfxdat.win)) quit = true;
+ zap_cp(gfxdatptr,&gfxdat,sizeof (gfxdat));
+ return quit;
+}
diff --git a/bowshock/source/bs/loop.c b/bowshock/source/bs/loop.c
index 7bcf07a..0dcd02a 100644
--- a/bowshock/source/bs/loop.c
+++ b/bowshock/source/bs/loop.c
@@ -11,76 +11,28 @@
#include <stdlib.h>
#include <zap/mem.h>
-bow_stat bow_loop(bow_gfxdat * gfxdatptr,bow_playdat * playdatptr) {
+static void bow_scrllhandl(GLFWwindow * win,[[maybe_unused]] double const xoff,double const yoff) {
+ bow_gfxdat * dat = glfwGetWindowUserPointer(win);
+ dat->zoom *= powf(0x1.1p0f,0x0p0f-(float)yoff);
+}
+
+void bow_loop(bow_gfxdat * gfxdatptr,bow_playdat * playdatptr) {
bow_log("entering main loop");
bow_gfxdat gfxdat;
bow_playdat playdat;
zap_cp(&gfxdat, gfxdatptr, sizeof (gfxdat));
zap_cp(&playdat,playdatptr,sizeof (playdat));
- bow_objroot sysroot = { // For stellar bodies.
- .objs = nullptr,
- };
+ glfwSetWindowUserPointer(gfxdat.win,&gfxdat);
+ bow_objroot sysroot; // For stellar bodies.
bow_objroot objroot = { // For miscellaneous objects (canisters, ships...).
.objs = nullptr,
};
+ bow_gensys(&sysroot,playdat.sysid,playdat.tm);
bow_obj objtmp = {
- .typ = bow_objtyp_star,
- .pos = {
- .x = 0x0p0,
- .y = 0x0p0,
- .z = 0x0p0,
- },
- .rot = {
- .x = 0x0p0,
- .y = 0x0p0,
- .z = 0x0p0,
- },
- .posvel = {
- .x = 0x0p0,
- .y = 0x0p0,
- .z = 0x0p0,
- },
- .rotvel = {
- .x = 0x0p0,
- .y = 0x0p0,
- .z = 0x0p0,
- },
- .mass = 0x191930A5E75F0C191814000000p0,
- .startyp = bow_star_g,
- // next will be overwritten anyways.
- };
- bow_addobj(&sysroot,&objtmp);
- objtmp = (bow_obj) {
- .typ = bow_objtyp_wrld,
- .pos = {
- .x = 0x0p0,
- .y = 0x22'3F8B'93C0p0,
- .z = 0x0p0,
- },
- .rot = {
- .x = 0x0p0,
- .y = 0x0p0,
- .z = 0x0p0,
- },
- .posvel = {
- .x = 0x7652p0/bow_tmmod,
- .y = 0x0p0,
- .z = 0x0p0,
- },
- .rotvel = {
- .x = 0x0p0,
- .y = 0x0p0,
- .z = 0x1.31DB66BBp-15,
- },
- .mass = 0x4'F0A9'9C58'8848'32A0'0000p0,
- .wrldtyp = bow_wrld_rck,
- };
- bow_addobj(&sysroot,&objtmp);
- objtmp = (bow_obj) {
.typ = bow_objtyp_can,
.pos = {
- .x = 0x20'0000'0000p0,
- .y = 0x20'0000'0000p0,
+ .x = 0x0p0,
+ .y = -0x2p0,
.z = 0x0p0,
},
.rot = {
@@ -89,7 +41,7 @@ bow_stat bow_loop(bow_gfxdat * gfxdatptr,bow_playdat * playdatptr) {
.z = 0x0p0,
},
.posvel = {
- .x = 0x16A.09E667F4p0*0x20p0/bow_tmmod,
+ .x = -0x1p-12,
.y = 0x0p0,
.z = 0x0p0,
},
@@ -101,6 +53,7 @@ bow_stat bow_loop(bow_gfxdat * gfxdatptr,bow_playdat * playdatptr) {
.mass = 0x1p0,
};
bow_addobj(&objroot,&objtmp);
+ glfwSetScrollCallback(gfxdat.win,bow_scrllhandl);
for (;;++playdat.tm) {
glfwPollEvents();
if (bow_gotintr) {
@@ -115,10 +68,10 @@ bow_stat bow_loop(bow_gfxdat * gfxdatptr,bow_playdat * playdatptr) {
bow_mvobjs(&sysroot);
bow_mvobjs(&objroot);
// Render:
- bow_drw(&gfxdat,&sysroot,&objroot);
+ bow_drw(&gfxdat,&sysroot,&objroot,gfxdat.zoom);
}
+ glfwSetScrollCallback(gfxdat.win,nullptr);
bow_freeobjs(&sysroot);
zap_cp(gfxdatptr, &gfxdat, sizeof (gfxdat));
zap_cp(playdatptr,&playdat,sizeof (playdat));
- return bow_stat_ok;
}
diff --git a/bowshock/source/bs/quit.c b/bowshock/source/bs/quit.c
index 08c19b2..925b99c 100644
--- a/bowshock/source/bs/quit.c
+++ b/bowshock/source/bs/quit.c
@@ -1,7 +1,7 @@
// Copyright 2022-2023 Gabriel Jensen.
#include <bow/gfx.h>
-#include <bow/info.h>
+#include <bow/lgc.h>
#include <GLFW/glfw3.h>
#include <stddef.h>
diff --git a/bowshock/source/bs/rnd.c b/bowshock/source/bs/rnd.c
new file mode 100644
index 0000000..25e4932
--- /dev/null
+++ b/bowshock/source/bs/rnd.c
@@ -0,0 +1,17 @@
+// Copyright 2022-2023 Gabriel Jensen.
+
+#include <bow/bs.h>
+
+#include <stdlib.h>
+#include <zap/bs.h>
+
+static_assert(sizeof (int) == sizeof (zap_i02));
+
+static_assert(RAND_MAX == zap_maxvali);
+
+zap_i04 bow_rnd(void) {
+ zap_i02 const rnd0 = (zap_i02)rand();
+ zap_i02 const rnd1 = (zap_i02)rand();
+ zap_i04 const rnd = (zap_i04)rnd0 | (zap_i04)rnd1 >> 0x4u;
+ return rnd;
+}
diff --git a/bowshock/source/gfx/drw.c b/bowshock/source/gfx/drw.c
index 570735b..2d45362 100644
--- a/bowshock/source/gfx/drw.c
+++ b/bowshock/source/gfx/drw.c
@@ -4,33 +4,23 @@
#include <bow/lgc.h>
#include <GLFW/glfw3.h>
-#include <zap/mem.h>
-static void bow_drwobjs(bow_objroot * const root) {
- double const frm = 0x22'3F8B'93C0p0*0x6p0;
+static void bow_drwobjs(bow_objroot * const root,float const zoom) {
+ float const frm = 0x1p0*zoom;
for (bow_obj * obj = root->objs;obj != nullptr;obj = obj->next) {
GLfloat const posx = (GLfloat)obj->pos.x/frm;
GLfloat const posy = (GLfloat)obj->pos.y/frm;
GLfloat const posz = (GLfloat)obj->pos.z/frm;
- glColor3f(0x1p0,0x1p0,0x1p0);
glVertex3f(posx,posy,posz);
}
}
-void bow_drw(bow_gfxdat * gfxdatptr,bow_objroot * const sys,bow_objroot * const objs) {
- bow_gfxdat gfxdat;
- zap_cp(&gfxdat,gfxdatptr,sizeof (gfxdat));
- int frmbufw;
- int frmbufh;
- glfwGetFramebufferSize(gfxdat.win,&frmbufw,&frmbufh);
- glViewport(0x0,0x0,frmbufw,frmbufh);
- glOrtho(-0x1p0,0x1p0,-0x1p0,0x1p0,0x0p0,0x0p0);
+void bow_drw(bow_gfxdat * gfxdat,bow_objroot * const sys,bow_objroot * const objs,float const zoom) {
glClear(GL_COLOR_BUFFER_BIT);
- glPointSize(0x4p0);
+ glPointSize(0x2p0);
glBegin(GL_POINTS);
- bow_drwobjs(sys);
- bow_drwobjs(objs);
+ bow_drwobjs(sys,zoom);
+ bow_drwobjs(objs,zoom);
glEnd();
- glfwSwapBuffers(gfxdat.win);
- zap_cp(gfxdatptr,&gfxdat,sizeof (gfxdat));
+ glfwSwapBuffers(gfxdat->win);
}
diff --git a/bowshock/source/gfx/initgfx.c b/bowshock/source/gfx/initgfx.c
index 95174e2..6e228eb 100644
--- a/bowshock/source/gfx/initgfx.c
+++ b/bowshock/source/gfx/initgfx.c
@@ -3,6 +3,7 @@
#include <bow/gfx.h>
#include <GLFW/glfw3.h>
+#include <math.h>
#include <zap/mem.h>
void bow_initgfx(bow_gfxdat * const datptr) {
@@ -17,16 +18,23 @@ void bow_initgfx(bow_gfxdat * const datptr) {
glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR,0x3);
glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR,0x0);
glfwWindowHint(GLFW_DECORATED, GLFW_FALSE);
- GLFWwindow * win = glfwCreateWindow(0x300,0x200,"Bowshock",nullptr,nullptr);
+ glfwWindowHint(GLFW_RESIZABLE, GLFW_FALSE);
+ GLFWwindow * win = glfwCreateWindow(0x400,0x240,"Bowshock",glfwGetPrimaryMonitor(),nullptr);
if (win == nullptr) {
bow_logerr("unable to open window");
bow_abrt();
}
glfwMakeContextCurrent(win);
- glfwSwapInterval(0x1);
- //glClearColor(0x1.6D6D6D6Ep-1,0x1.81818182p-4,0x1.9999999Ap-3,0x1p0);
+ int frmbufw;
+ int frmbufh;
+ glfwGetFramebufferSize(win,&frmbufw,&frmbufh);
+ glViewport(0x0,0x0,frmbufw,frmbufh);
+ glOrtho(-0x1p0,0x1p0,-0x1p0,0x1p0,0x0p0,0x0p0);
glClearColor(0x0p0,0x0p0,0x0p0,0x1p0);
glClear(GL_COLOR_BUFFER_BIT);
- dat.win = win;
+ glfwSwapBuffers(win);
+ glfwSwapInterval(0x1);
+ dat.win = win;
+ dat.zoom = 0x4p0f;
zap_cp(datptr,&dat,sizeof (dat));
}
diff --git a/bowshock/source/lgc/addobj.c b/bowshock/source/lgc/addobj.c
index 2a36667..11f4e60 100644
--- a/bowshock/source/lgc/addobj.c
+++ b/bowshock/source/lgc/addobj.c
@@ -1,6 +1,5 @@
// Copyright 2022-2023 Gabriel Jensen.
-#include <bow/info.h>
#include <bow/lgc.h>
#include <stdlib.h>
@@ -10,7 +9,7 @@ bow_obj * bow_addobj(bow_objroot * const root,bow_obj const * const objval) {
bow_dbglog("adding object of type %s",bow_objtypstr(objval->typ));
bow_obj * const obj = malloc(sizeof (bow_obj));
if (obj == nullptr) {
- bow_dbglog("unable to allocate memory for object");
+ bow_logerr("unable to allocate memory for object");
bow_abrt();
}
zap_cp(obj,objval,sizeof (bow_obj));
diff --git a/bowshock/source/lgc/freeobjs.c b/bowshock/source/lgc/freeobjs.c
index e410559..18fd356 100644
--- a/bowshock/source/lgc/freeobjs.c
+++ b/bowshock/source/lgc/freeobjs.c
@@ -1,12 +1,11 @@
// Copyright 2022-2023 Gabriel Jensen.
-#include <bow/info.h>
#include <bow/lgc.h>
#include <stdlib.h>
#include <zap/mem.h>
-void bow_freeobjs(bow_objroot const * const root) {
+void bow_freeobjs(bow_objroot * const root) {
bow_dbglog("freeing objects");
bow_obj * obj;
bow_obj * next;
diff --git a/bowshock/source/lgc/gensys.c b/bowshock/source/lgc/gensys.c
new file mode 100644
index 0000000..9f3f226
--- /dev/null
+++ b/bowshock/source/lgc/gensys.c
@@ -0,0 +1,65 @@
+// Copyright 2022-2023 Gabriel Jensen.
+
+#include <bow/lgc.h>
+
+#include <inttypes.h>
+
+void bow_gensys(bow_objroot * const sys,zap_i04 const id,zap_i04 const tm) {
+ bow_log("generating system (%" PRIXLEAST64 ")",id);
+ sys->objs = nullptr;
+ bow_obj objtmp;
+ objtmp = (bow_obj) {
+ .typ = bow_objtyp_star,
+ .pos = {
+ .x = 0x0p0,
+ .y = 0x0p0,
+ .z = 0x0p0,
+ },
+ .rot = {
+ .x = 0x0p0,
+ .y = 0x0p0,
+ .z = 0x0p0,
+ },
+ .posvel = {
+ .x = 0x0p0,
+ .y = 0x0p0,
+ .z = 0x0p0,
+ },
+ .rotvel = {
+ .x = 0x0p0,
+ .y = 0x0p0,
+ .z = 0x0p0,
+ },
+ .mass = 0x19'1930'A5E7'5F0C'1918'1400'0000p0,
+ .startyp = bow_star_g,
+ // next will be overwritten anyways.
+ };
+ bow_addobj(sys,&objtmp);
+ objtmp = (bow_obj) {
+ .typ = bow_objtyp_wrld,
+ .pos = {
+ .x = 0x0p0,
+ .y = 0x1.F76F144Dp-1,
+ .z = 0x0p0,
+ },
+ .rot = {
+ .x = 0x0p0,
+ .y = 0x0p0,
+ .z = 0x0p0,
+ },
+ .posvel = {
+ .x = 0x1.B2D06FF3p-23*bow_tmmod,
+ .y = 0x0p0,
+ .z = 0x0p0,
+ },
+ .rotvel = {
+ .x = 0x0p0,
+ .y = 0x0p0,
+ .z = 0x1.31DB66BBp-15,
+ },
+ .mass = 0x4'F0A9'9C58'8848'32A0'0000p0,
+ .wrldtyp = bow_wrld_rck,
+ };
+ bow_addobj(sys,&objtmp);
+ bow_sim(sys,tm);
+}
diff --git a/bowshock/source/lgc/grav.c b/bowshock/source/lgc/grav.c
index ab86289..7ef2106 100644
--- a/bowshock/source/lgc/grav.c
+++ b/bowshock/source/lgc/grav.c
@@ -5,41 +5,32 @@
#include <math.h>
#include <zap/mem.h>
-void bow_grav1(bow_obj * objptr,bow_obj * parptr) {
- bow_obj obj;
- bow_obj par;
- zap_cp(&obj,objptr,sizeof (obj));
- zap_cp(&par,parptr,sizeof (par));
- double const distx = par.pos.x-obj.pos.x;
- double const disty = par.pos.y-obj.pos.y;
- double const distz = par.pos.z-obj.pos.z;
+static void bow_grav1(bow_obj * obj,bow_obj * par) {
+ double const distx = par->pos.x-obj->pos.x;
+ double const disty = par->pos.y-obj->pos.y;
+ double const distz = par->pos.z-obj->pos.z;
double const dist = sqrt(distx*distx+disty*disty+distz*distz);
double const angy = atan2(disty,distx);
double const angz = atan2(distz,distx);
- double acc = par.mass/pow(dist,2.0)*bow_gravconst;
+ double acc = par->mass/(dist*dist)*bow_gravconst;
double const vx = cos(angy)*acc;
double const vy = sin(angy)*acc;
double const vz = sin(angz)*acc;
- obj.posvel.x += vx;
- obj.posvel.y += vy;
- obj.posvel.z += vz;
- zap_cp(objptr,&obj,sizeof (obj));
+ obj->posvel.x += vx;
+ obj->posvel.y += vy;
+ obj->posvel.z += vz;
}
-void bow_grav2(bow_obj * obj0ptr,bow_obj * obj1ptr) {
- bow_obj obj0;
- bow_obj obj1;
- zap_cp(&obj0,obj0ptr,sizeof (obj0));
- zap_cp(&obj1,obj1ptr,sizeof (obj1));
- double const distx = obj1.pos.x-obj0.pos.x;
- double const disty = obj1.pos.y-obj0.pos.y;
- double const distz = obj1.pos.z-obj0.pos.z;
+static void bow_grav2(bow_obj * obj0,bow_obj * obj1) {
+ double const distx = obj1->pos.x-obj0->pos.x;
+ double const disty = obj1->pos.y-obj0->pos.y;
+ double const distz = obj1->pos.z-obj0->pos.z;
double const dist = sqrt(distx*distx+disty*disty+distz*distz);
double const angy = atan2(disty,distx);
double const angz = atan2(distz,distx);
- double acc0 = bow_gravconst/pow(dist,2.0);
- double const acc1 = acc0*obj0.mass; // This is negative.
- acc0 *= obj1.mass;
+ double acc0 = bow_gravconst/(dist*dist);
+ double const acc1 = acc0*obj0->mass; // This is negative.
+ acc0 *= obj1->mass;
double vx0 = cos(angy);
double vy0 = sin(angy);
double vz0 = sin(angz);
@@ -49,23 +40,21 @@ void bow_grav2(bow_obj * obj0ptr,bow_obj * obj1ptr) {
vx0 *= acc0;
vy0 *= acc0;
vz0 *= acc0;
- obj0.posvel.x += vx0;
- obj0.posvel.y += vy0;
- obj0.posvel.z += vz0;
- obj1.posvel.x -= vx1;
- obj1.posvel.y -= vy1;
- obj1.posvel.z -= vz1;
- zap_cp(obj0ptr,&obj0,sizeof (obj0));
- zap_cp(obj1ptr,&obj1,sizeof (obj1));
+ obj0->posvel.x += vx0;
+ obj0->posvel.y += vy0;
+ obj0->posvel.z += vz0;
+ obj1->posvel.x -= vx1;
+ obj1->posvel.y -= vy1;
+ obj1->posvel.z -= vz1;
}
-void bow_gravsys(bow_objroot const * const sys) {
+void bow_gravsys(bow_objroot * const sys) {
for (bow_obj * obj0 = sys->objs;obj0 != nullptr;obj0 = obj0->next)
for (bow_obj * obj1 = obj0->next;obj1 != nullptr;obj1 = obj1->next)
bow_grav2(obj0,obj1);
}
-void bow_gravobjs(bow_objroot const * const sys,bow_objroot const * const objs) {
+void bow_gravobjs(bow_objroot * const sys,bow_objroot * const objs) {
for (bow_obj * obj = objs->objs;obj != nullptr;obj = obj->next)
for (bow_obj * par = sys->objs;par != nullptr;par = par->next)
bow_grav1(obj,par);
diff --git a/bowshock/source/lgc/mv.c b/bowshock/source/lgc/mv.c
index 1385123..d83bbf9 100644
--- a/bowshock/source/lgc/mv.c
+++ b/bowshock/source/lgc/mv.c
@@ -5,19 +5,16 @@
#include <math.h>
#include <zap/mem.h>
-void bow_mv(bow_obj * objptr) {
- bow_obj obj;
- zap_cp(&obj,objptr,sizeof (obj));
- obj.pos.x += obj.posvel.x;
- obj.pos.y += obj.posvel.y;
- obj.pos.z += obj.posvel.z;
- obj.rot.x += obj.rotvel.x;
- obj.rot.y += obj.rotvel.y;
- obj.rot.z += obj.rotvel.z;
- zap_cp(objptr,&obj,sizeof (obj));
+void bow_mv(bow_obj * obj) {
+ obj->pos.x += obj->posvel.x;
+ obj->pos.y += obj->posvel.y;
+ obj->pos.z += obj->posvel.z;
+ obj->rot.x += obj->rotvel.x;
+ obj->rot.y += obj->rotvel.y;
+ obj->rot.z += obj->rotvel.z;
}
-void bow_mvobjs(bow_objroot const * root) {
+void bow_mvobjs(bow_objroot * root) {
for (bow_obj * obj = root->objs;obj != nullptr;obj = obj->next)
bow_mv(obj);
}
diff --git a/bowshock/source/info/objtypstr.c b/bowshock/source/lgc/objtypstr.c
index 9a53a87..ae0a300 100644
--- a/bowshock/source/info/objtypstr.c
+++ b/bowshock/source/lgc/objtypstr.c
@@ -1,6 +1,6 @@
// Copyright 2022-2023 Gabriel Jensen.
-#include <bow/info.h>
+#include <bow/lgc.h>
#include <stddef.h>
diff --git a/bowshock/source/info/shipmass.c b/bowshock/source/lgc/shipmass.c
index 2bad462..0b5f768 100644
--- a/bowshock/source/info/shipmass.c
+++ b/bowshock/source/lgc/shipmass.c
@@ -1,6 +1,6 @@
// Copyright 2022-2023 Gabriel Jensen.
-#include <bow/info.h>
+#include <bow/lgc.h>
double bow_shipmass([[maybe_unused]] bow_ship const id) {
return 0x100p0;
diff --git a/bowshock/source/lgc/sim.c b/bowshock/source/lgc/sim.c
new file mode 100644
index 0000000..69a61e4
--- /dev/null
+++ b/bowshock/source/lgc/sim.c
@@ -0,0 +1,13 @@
+// Copyright 2022-2023 Gabriel Jensen.
+
+#include <bow/lgc.h>
+
+#include <inttypes.h>
+
+void bow_sim(bow_objroot * const sys,zap_i04 const dur) {
+ bow_log("simulating for (%" PRIXLEAST64 ") time units",dur);
+ for (zap_i04 i = 0x0u;i <= dur;++i) {
+ bow_gravsys(sys);
+ bow_mvobjs(sys);
+ }
+}
diff --git a/bowshock/source/sav/cont.c b/bowshock/source/sav/cont.c
index 4cdadc5..b12d914 100644
--- a/bowshock/source/sav/cont.c
+++ b/bowshock/source/sav/cont.c
@@ -27,11 +27,7 @@ static void bow_decsav(bow_savdat * buf,zap_i8 * dat) {
dat = zap_cp(&buf->shiprotvelz,dat,0x8u).src;
}
-void bow_cont(char const * const pth,bow_playdat * const playdatptr,bool const skipld) {
- if (skipld) {
- bow_log("skipping save load");
- goto new;
- }
+void bow_cont(bow_playdat * const playdatptr,char const * const pth) {
bow_log("loading save file at \"%s\"",pth);
flux_fil * fil;
flux_err err = flux_op(&fil,pth,flux_md_rd,flux_keep);
@@ -77,39 +73,10 @@ void bow_cont(char const * const pth,bow_playdat * const playdatptr,bool const s
};
zap_cp(playdat.nm,dat.cmdrnm,bow_cmdrnmlen);
playdat.nm[bow_cmdrnmlen] = '\x0';
- bow_log("welcome back commander %s",playdat.nm);
- goto ret;
-new:
- playdat = (bow_playdat) {
- .nm = "Caelum\x0\x0\x0\x0\x0\x0\x0\x0\x0",
- .sysid = 0x0u,
- .tm = 0x1E187E00000u, // 256 julian years after the Unix Epoch.
- .ship = {
- .pos = {
- .x = 0x0p0,
- .y = 0x0p0,
- .z = 0x0p0,
- },
- .rot = {
- .x = 0x0p0,
- .y = 0x0p0,
- .z = 0x0p0,
- },
- .posvel = {
- .x = 0x0p0,
- .y = 0x0p0,
- .z = 0x0p0,
- },
- .rotvel = {
- .x = 0x0p0,
- .y = 0x0p0,
- .z = 0x0p0,
- },
- .shiptyp = bow_ship_aq,
- },
- };
- bow_log("generated commander %s",playdat.nm);
-ret:
+ bow_log("welcome back, commander %s",playdat.nm);
bow_gendat(&playdat);
zap_cp(playdatptr,&playdat,sizeof (playdat));
+ return;
+new:
+ bow_rstart(playdatptr);
}
diff --git a/bowshock/source/sav/gendat.c b/bowshock/source/sav/gendat.c
new file mode 100644
index 0000000..6711301
--- /dev/null
+++ b/bowshock/source/sav/gendat.c
@@ -0,0 +1,17 @@
+// Copyright 2022-2023 Gabriel Jensen.
+
+#include <bow/lgc.h>
+#include <bow/sav.h>
+
+#include <zap/mem.h>
+
+#include <string.h>
+
+void bow_gendat(bow_playdat * const datptr) {
+ bow_log("generating player data");
+ bow_playdat dat;
+ zap_cp(&dat,datptr,sizeof (dat));
+ dat.ship.typ = bow_objtyp_ship;
+ dat.ship.mass = bow_shipmass(dat.ship.shiptyp);
+ zap_cp(datptr,&dat,sizeof (dat));
+}
diff --git a/bowshock/source/sav/rstart.c b/bowshock/source/sav/rstart.c
new file mode 100644
index 0000000..70b7bef
--- /dev/null
+++ b/bowshock/source/sav/rstart.c
@@ -0,0 +1,41 @@
+// Copyright 2022-2023 Gabriel Jensen.
+
+#include <bow/lgc.h>
+#include <bow/sav.h>
+
+#include <zap/mem.h>
+
+void bow_rstart(bow_playdat * const datptr) {
+ bow_log("restarting save");
+ bow_playdat dat = {
+ .nm = "Caelum\x0\x0\x0\x0\x0\x0\x0\x0\x0",
+ .sysid = 0x45u,
+ .tm = 0x0u, // 256 julian years after the Unix Epoch.
+ .ship = {
+ .pos = {
+ .x = 0x0p0,
+ .y = 0x0p0,
+ .z = 0x0p0,
+ },
+ .rot = {
+ .x = 0x0p0,
+ .y = 0x0p0,
+ .z = 0x0p0,
+ },
+ .posvel = {
+ .x = 0x0p0,
+ .y = 0x0p0,
+ .z = 0x0p0,
+ },
+ .rotvel = {
+ .x = 0x0p0,
+ .y = 0x0p0,
+ .z = 0x0p0,
+ },
+ .shiptyp = bow_ship_aq,
+ },
+ };
+ bow_log("welcome, commander %s",dat.nm);
+ bow_gendat(&dat);
+ zap_cp(datptr,&dat,sizeof (dat));
+}