diff options
34 files changed, 390 insertions, 564 deletions
@@ -1,3 +1,6 @@ +/procyon *.elf *.exe *.o +log.* +vgcore.* diff --git a/CHANGELOG.txt b/CHANGELOG.txt index 2a57e29..a9a7163 100644 --- a/CHANGELOG.txt +++ b/CHANGELOG.txt @@ -1,3 +1,9 @@ +# 2 + +* Rename project to Bowshock (from Procyon); +* Rewrite project; +* Add gravity engine; + # 1 * Move save handlers into their own module 'sav'; diff --git a/bowshock.desktop b/bowshock.desktop new file mode 100644 index 0000000..2e9ab6d --- /dev/null +++ b/bowshock.desktop @@ -0,0 +1,4 @@ +[Desktop Entry] +Type=Application +Name=Bowshock +Exec=/usr/bin/bowshock diff --git a/bowshock/GNUmakefile b/bowshock/GNUmakefile new file mode 100644 index 0000000..9fe2af3 --- /dev/null +++ b/bowshock/GNUmakefile @@ -0,0 +1,46 @@ +LD := $(CC) + +CFLAGS := \ + -Iinclude \ + -Ofast \ + -Wall \ + -Wextra \ + -Wpedantic \ + -Wno-gnu-empty-initializer \ + -Wno-gnu-zero-variadic-macro-arguments \ + -g \ + -std=c2x + +ifeq "$(debug)" "true" +CFLAGS := \ + $(CFLAGS) \ + -Dbow_dbg=true +endif + +LDLIBS := \ + -lflux \ + -lm \ + -lzap + +OBJS := \ + source/bs/gendat.o \ + source/bs/init.o \ + source/bs/initdat.o \ + source/bs/loop.o \ + source/bs/quit.o \ + source/info/shipmass.o \ + source/lgc/grav.o \ + source/lgc/mv.o + +BIN := bowshock.elf + +HDRS := \ + include/bow/bs.h \ + include/bow/info.h \ + include/bow/lgc.h \ + include/bow/sav.h + +$(BIN): $(OBJS) + $(LD) -o$(@) $(^) $(LDLIBS) + +$(OBJS): $(HDRS) diff --git a/bowshock/include/bow/bs.h b/bowshock/include/bow/bs.h new file mode 100644 index 0000000..fe5ecaa --- /dev/null +++ b/bowshock/include/bow/bs.h @@ -0,0 +1,100 @@ +#if !defined(bow_hdr_bs) +#define bow_hdr_bs + +#define constexpr static const + +#include <stdio.h> +#include <zap/bs.h> + +#if !defined(bow_sym) +#error symbol not defined +#endif + +#define bow_rawlog(msg,...) fprintf(stderr,msg __VA_OPT__(,) __VA_ARGS__) + +#define bow_log(msg,...) bow_rawlog("\x1B[1m%s\x1B[0m: " msg "\n",bow_sym __VA_OPT__(,) __VA_ARGS__) + +#if bow_dbg +#define bow_dbglog(msg,...) bow_log(msg __VA_OPT__ (,) __VA_ARGS__) + +#define bow_logxyz(xyz) bow_rawlog("x: %f\ny: %f\nz: %f\n\n",xyz.x,xyz.y,xyz.z) +#else +#define bow_dbglog(msg,...) ((void)0x0u) + +#define bow_logxyz(xyz) ((void)0x0u) +#endif + +constexpr zap_i04 bow_ver; + +typedef enum { + bow_stat_ok = 0x0u, + bow_stat_err = 0x1u, +} bow_stat; + +typedef enum { + bow_objtyp_can, // canister + bow_objtyp_plan, // planet + bow_objtyp_play, // player + bow_objtyp_sat, // satellite (moon) + bow_objtyp_ship, // ship + bow_objtyp_star, // star + bow_objtyp_stat, // station +} bow_objtyp; + +typedef enum { + bow_ship_aq, // aquila + bow_ship_cas, // cassiopeia + bow_ship_cent, // centaurus + bow_ship_eri, // eridanus + bow_ship_lyra, // lyra + bow_ship_tau, // taurus + bow_ship_ursa, // ursa +} bow_ship; + +typedef enum { + bow_star_a, // main sequence + bow_star_b, // main sequence + bow_star_c, // carbon + bow_star_f, // main sequence + bow_star_g, // main sequence + bow_star_k, // main sequence + bow_star_l, // brown dwarf + bow_star_m, // main sequence + bow_star_n, // neutron star + bow_star_o, // main sequence + bow_star_s, // carbon + bow_star_t, // brown dwarf + bow_star_w, // worm hole + bow_star_x, // black hole + bow_star_y, // brown dwarf + bow_star_z, // white hole +} bow_star; + +typedef struct { + double x; + double y; + double z; +} bow_xyz; + +typedef struct { + bow_objtyp typ; + bow_xyz pos; + bow_xyz rot; // rad + bow_xyz vel; + double mass; + union { + bow_ship shiptyp; + }; +} bow_obj; + +typedef struct { + zap_i04 sysid; + bow_obj ship; +} bow_playdat; + +void bow_gendat( bow_playdat * playdat); +void bow_initdat(bow_playdat * playdat); + +[[noreturn]] void bow_quit(bow_stat stat); + +#endif diff --git a/bowshock/include/bow/info.h b/bowshock/include/bow/info.h new file mode 100644 index 0000000..e64b46b --- /dev/null +++ b/bowshock/include/bow/info.h @@ -0,0 +1,8 @@ +#if !defined(bow_hdr_info) +#define bow_hdr_info + +#include <bow/bs.h> + +double bow_shipmass(bow_ship id); + +#endif diff --git a/bowshock/include/bow/lgc.h b/bowshock/include/bow/lgc.h new file mode 100644 index 0000000..416dcf3 --- /dev/null +++ b/bowshock/include/bow/lgc.h @@ -0,0 +1,13 @@ +#if !defined(bow_hdr_lgc) +#define bow_hdr_lgc + +#include <bow/bs.h> + +#define bow_dist(x,y,z) sqrt(pow(x,0x2.0p0)+pow(y,0x2.0p0)+pow(z,0x2.0p0)) + +constexpr double bow_gravconst = 0x1.0p0; // gravitational constant + +void bow_grav(bow_obj * obj,bow_obj const * par); +void bow_mv( bow_obj * obj); + +#endif diff --git a/bowshock/include/bow/sav.h b/bowshock/include/bow/sav.h new file mode 100644 index 0000000..da2e6c8 --- /dev/null +++ b/bowshock/include/bow/sav.h @@ -0,0 +1,9 @@ +#if !defined(bow_hdr_sav) +#define bow_hdr_sav + +#include <bow/bs.h> + +void bow_cont(char const * fil,bow_playdat * dat); +void bow_sav( char const * fil,bow_playdat const * dat); + +#endif diff --git a/bowshock/source/bs/gendat.c b/bowshock/source/bs/gendat.c new file mode 100644 index 0000000..95516c6 --- /dev/null +++ b/bowshock/source/bs/gendat.c @@ -0,0 +1,16 @@ +#define bow_sym "gendat" + +#include <bow/info.h> + +#include <flux.h> +#include <zap/mem.h> + +#include <string.h> + +void bow_gendat(bow_playdat * const playdatptr) { + bow_log("generating data"); + bow_playdat playdat; + memcpy(&playdat,playdatptr,sizeof (playdat)); + playdat.ship.mass = bow_shipmass(playdat.ship.shiptyp); + memcpy(playdatptr,&playdat,sizeof (playdat)); +} diff --git a/bowshock/source/bs/init.c b/bowshock/source/bs/init.c new file mode 100644 index 0000000..22d16e6 --- /dev/null +++ b/bowshock/source/bs/init.c @@ -0,0 +1,20 @@ +#define bow_sym "init" + +#include <bow/sav.h> + +#include <flux.h> + +bow_stat bow_loop(bow_playdat * playdat); + +[[noreturn]] void bow_init(void) { + bow_playdat playdat; + flux_wrstr(flux_deflog,"\x1B[0m\x1B[1mBowshock\x1B[0m \u2013 Copyright 2022\u20102023, \x1B[1mGabriel Jensen\x1B[0m.\n\n"); + bow_log("initialising"); + bow_initdat(&playdat); + bow_loop(&playdat); + bow_quit(bow_stat_ok); +} + +int main(void) { + bow_init(); +} diff --git a/bowshock/source/bs/initdat.c b/bowshock/source/bs/initdat.c new file mode 100644 index 0000000..ee8a190 --- /dev/null +++ b/bowshock/source/bs/initdat.c @@ -0,0 +1,31 @@ +#define bow_sym "initdat" + +#include <bow/bs.h> + +#include <flux.h> +#include <zap/mem.h> + +#include <string.h> + +void bow_initdat(bow_playdat * const playdatptr) { + bow_log("initialising data"); + bow_playdat playdat = { + .sysid = 0x0u, + .ship = { + .typ = bow_objtyp_ship, + .pos = { + .x = 0x0.0p0, + .y = 0x0.0p0, + .z = 0x0.0p0, + }, + .vel = { + .x = 0x0.0p0, + .y = 0x0.0p0, + .z = 0x0.0p0, + }, + .shiptyp = bow_ship_aq, + }, + }; + bow_gendat(&playdat); + memcpy(playdatptr,&playdat,sizeof (playdat)); +} diff --git a/bowshock/source/bs/loop.c b/bowshock/source/bs/loop.c new file mode 100644 index 0000000..f139fcd --- /dev/null +++ b/bowshock/source/bs/loop.c @@ -0,0 +1,61 @@ +#define bow_sym "loop" + +#include <bow/lgc.h> +#include <bow/sav.h> + +#include <inttypes.h> +#include <math.h> +#include <zap/mem.h> + +#include <stdio.h> + +bow_stat bow_loop(bow_playdat * playdatptr) { + bow_log("entering main loop"); + FILE * log = fopen("log.xyz","w"); + bow_playdat playdat; + zap_cp(&playdat,playdatptr,sizeof (playdat)); + bow_obj star0 = { + .pos = { + .x = 0x0.0p0, + .y = 0x80.0p0, + .z = 0x0.0p0, + }, + .typ = bow_objtyp_star, + .mass = 0x10000.0p0, + }; + bow_obj star1 = { + .pos = { + .x = 0x0.0p0, + .y = -0x80.0p0, + .z = 0x0.0p0, + }, + .typ = bow_objtyp_star, + .mass = 0x1000.0p0, + }; + playdat.ship.pos.z = 0x100.0p0; + star0.vel.x = sqrt(bow_gravconst*star1.mass/0x100.0p0)/0x2.0p0; // orbital speed + star1.vel.x = -sqrt(bow_gravconst*star0.mass/0x100.0p0)/0x2.0p0; // orbital speed + for (zap_i04 i = 0x0u;;) { + // Calculate gravitations: + bow_grav(&star0,&star1); + bow_grav(&star1,&star0); + bow_grav(&playdat.ship,&star0); + bow_grav(&playdat.ship,&star1); + // Move objects: + bow_mv(&star0); + bow_mv(&star1); + bow_mv(&playdat.ship); + // Log: + //bow_logxyz(playdat.ship.vel); + fprintf(log,"%f\t%f\t%f\n",star0.pos.x,star0.pos.y,star0.pos.z); + fprintf(log,"%f\t%f\t%f\n",star1.pos.x,star1.pos.y,star1.pos.z); + fprintf(log,"%f\t%f\t%f\n",playdat.ship.pos.x,playdat.ship.pos.y,playdat.ship.pos.z); + // Check tick number: + if (i++ == 0x7Fu) { + break; + } + } + fclose(log); + zap_cp(playdatptr,&playdat,sizeof (playdat)); + return bow_stat_ok; +} diff --git a/bowshock/source/bs/quit.c b/bowshock/source/bs/quit.c new file mode 100644 index 0000000..65b4a44 --- /dev/null +++ b/bowshock/source/bs/quit.c @@ -0,0 +1,22 @@ +#define bow_sym "quit" + +#include <bow/info.h> + +#include <flux.h> +#include <stdio.h> +#include <stdlib.h> + +void bow_quit(bow_stat const stat) { + bow_log("goodbye"); + int sysstat; + switch (stat) { + case bow_stat_err: + sysstat = EXIT_FAILURE; + break; + case bow_stat_ok: + sysstat = EXIT_SUCCESS; + break; + } + bow_log("exiting with code %i",sysstat); + exit(sysstat); +} diff --git a/bowshock/source/info/shipmass.c b/bowshock/source/info/shipmass.c new file mode 100644 index 0000000..b460556 --- /dev/null +++ b/bowshock/source/info/shipmass.c @@ -0,0 +1,9 @@ +#define bow_sym "shipmass" + +#include <bow/info.h> + +#include <zap/bs.h> + +double bow_shipmass([[maybe_unused]] bow_ship const id) { + return 0x100.0p0; +} diff --git a/bowshock/source/lgc/grav.c b/bowshock/source/lgc/grav.c new file mode 100644 index 0000000..f0ea290 --- /dev/null +++ b/bowshock/source/lgc/grav.c @@ -0,0 +1,27 @@ +#define bow_sym "grav" + +#include <bow/lgc.h> + +#include <math.h> +#include <zap/mem.h> + +void bow_grav(bow_obj * objptr,bow_obj const * 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; + double const dist = bow_dist(distx,disty,distz); + double const acc = bow_gravconst*par.mass/pow(dist,2.0); + double const angy = atan2(disty,distx); + double const angz = atan2(distz,distx); + double const vx = cos(angy)*acc; + double const vy = sin(angy)*acc; + double const vz = sin(angz)*acc; + obj.vel.x += vx; + obj.vel.y += vy; + obj.vel.z += vz; + zap_cp(objptr,&obj,sizeof (obj)); +} diff --git a/bowshock/source/lgc/mv.c b/bowshock/source/lgc/mv.c new file mode 100644 index 0000000..046d7bd --- /dev/null +++ b/bowshock/source/lgc/mv.c @@ -0,0 +1,15 @@ +#define bow_sym "grav" + +#include <bow/lgc.h> + +#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.vel.x; + obj.pos.y += obj.vel.y; + obj.pos.z += obj.vel.z; + zap_cp(objptr,&obj,sizeof (obj)); +} diff --git a/procyon.desktop b/procyon.desktop deleted file mode 100644 index 21c9313..0000000 --- a/procyon.desktop +++ /dev/null @@ -1,5 +0,0 @@ -[Desktop Entry] -Type=Application -Name=Procyon -Exec=/usr/bin/procyon - diff --git a/procyon/GNUmakefile b/procyon/GNUmakefile deleted file mode 100644 index a9379b7..0000000 --- a/procyon/GNUmakefile +++ /dev/null @@ -1,63 +0,0 @@ -# TOOLS - -# TOOL FLAGS - -CFLAGS := \ - -D_POSIX_C_SOURCE=200809L \ - -Iinclude \ - -O3 \ - -Wall \ - -Wextra \ - -Wpedantic \ - -g \ - -march=native \ - -std=c2x - -ifeq "$(debug)" "true" -CFLAGS := \ - $(CFLAGS) \ - -Dacm_dbg -endif - -LDLIBS := \ - -lGL \ - -lflux \ - -lglfw \ - -lzap - -# HEADERS - -HDRS := \ - include/acm/bs.h - -# BINARIES - -OBJS := \ - source/bs/dbglog.o \ - source/bs/exit.o \ - source/bs/init.o \ - source/bs/shipnm.o \ - source/evt/jmp.o \ - source/gfx/initgfx.o \ - source/info/jmplen.o \ - source/info/sysdist.o \ - source/sav/cont.o \ - source/sav/sav.o \ - source/main.o - -BIN := procyon.elf - -# TARGETS - -.PHONY: clean purge - -$(BIN): $(OBJS) - $(CC) $(CFLAGS) $(LDFLAGS) -o$(@) $(^) $(LDLIBS) - -$(OBJS): $(HDRS) - -clean: - $(RM) $(OBJS) - -purge: clean - $(RM) $(LIB) diff --git a/procyon/include/acm/bs.h b/procyon/include/acm/bs.h deleted file mode 100644 index 497bdb0..0000000 --- a/procyon/include/acm/bs.h +++ /dev/null @@ -1,121 +0,0 @@ -#if !defined(acm_hdr_bs) -#define acm_hdr_bs - -#include <GLFW/glfw3.h> -#include <signal.h> -#include <stdint.h> -#include <stdio.h> -#include <zap/bs.h> - -#define acm_ver ((uint_least64_t)+0x1) -#define acm_savver ((uint_least64_t)+0x1) - -#define acm_plnmlen ((zap_sz)+0x10u) - -#define acm_dflplnm ("Jameson\x0\x0\x0\x0\x0\x0\x0\x0") - -#if defined(acm_dbg) -#define acm_log(...) (acm_dbglog(__VA_ARGS__)) -#else -#define acm_log(...) ((void)0x0u) -#endif - -typedef enum { - acm_drv_h1, - acm_drv_h2, - acm_drv_h3, - acm_drv_h4, - acm_drv_h5, - acm_drv_h6, - acm_drv_h7, - acm_drv_h8, - acm_drv_m1, - acm_drv_m2, - acm_drv_m3, - acm_drv_m4, -} acm_drv; - -typedef enum { - acm_shipid_add, - acm_shipid_ana, - acm_shipid_asp, - acm_shipid_boa, - acm_shipid_cob, - acm_shipid_con, - acm_shipid_cou, - acm_shipid_cyg, - acm_shipid_dov, - acm_shipid_eag, - acm_shipid_falc, - acm_shipid_fer, - acm_shipid_frei, - acm_shipid_geck, - acm_shipid_haul, - acm_shipid_hawk, - acm_shipid_keel, - acm_shipid_kes, - acm_shipid_krait, - acm_shipid_lift, - acm_shipid_lion, - acm_shipid_mamba, - acm_shipid_moray, - acm_shipid_osp, - acm_shipid_pan, - acm_shipid_puma, - acm_shipid_py, - acm_shipid_shut, - acm_shipid_side, - acm_shipid_tran, - acm_shipid_vip, - acm_shipid_vult, -} acm_shipid; - -typedef enum { - acm_stat_err, - acm_stat_ok, -} acm_stat; - -typedef struct { - uint_least64_t rx; /* Rotation data */ - uint_least64_t ry; - uint_least64_t rz; - uint_least64_t px; /* Position data */ - uint_least64_t py; - uint_least64_t pz; - uint_least64_t vx; /* Velocity data */ - uint_least64_t vy; - uint_least64_t vz; -} acm_objpos; - -typedef struct { - acm_objpos pos; -} acm_obj; - -typedef struct { - acm_drv drv; - acm_shipid id; -} acm_ship; - -typedef struct { - char nm[acm_plnmlen + 0x1u]; - uint_least16_t heat; - acm_objpos pos; - uint_least64_t selsys; - acm_ship ship; - uint_least64_t tm; -} acm_pldat; - -extern struct { - bool gfxisinit; - acm_pldat pldat; - char const * savloc; - GLFWwindow * win; -} acm_dat; - -extern sig_atomic_t volatile acm_gotintr; - - void acm_dbglog(char const * fmt,...); - void acm_init( void); -[[noreturn]] void acm_exit( acm_stat stat); - -#endif diff --git a/procyon/include/acm/evt.h b/procyon/include/acm/evt.h deleted file mode 100644 index 3a5aa2a..0000000 --- a/procyon/include/acm/evt.h +++ /dev/null @@ -1,10 +0,0 @@ -#if !defined(acm_hdr_evt) -#define acm_hdr_evt - -#include <acm/bs.h> - -#include <stdint.h> - -bool acm_jmp(uint_least64_t sys); - -#endif diff --git a/procyon/include/acm/gfx.h b/procyon/include/acm/gfx.h deleted file mode 100644 index c3fdc15..0000000 --- a/procyon/include/acm/gfx.h +++ /dev/null @@ -1,8 +0,0 @@ -#if !defined(acm_hdr_gfx) -#define acm_hdr_gfx - -#include <acm/bs.h> - -void acm_initgfx(void); - -#endif diff --git a/procyon/include/acm/info.h b/procyon/include/acm/info.h deleted file mode 100644 index d42ad0b..0000000 --- a/procyon/include/acm/info.h +++ /dev/null @@ -1,12 +0,0 @@ -#if !defined(acm_hdr_info) -#define acm_hdr_info - -#include <acm/bs.h> - -#include <stdint.h> - -char const * acm_shipnm( acm_shipid ship); -uint_least64_t acm_sysdist(uint_least64_t sys); -uint_least64_t acm_jmplen( acm_ship const * ship); - -#endif diff --git a/procyon/include/acm/sav.h b/procyon/include/acm/sav.h deleted file mode 100644 index 4caf810..0000000 --- a/procyon/include/acm/sav.h +++ /dev/null @@ -1,9 +0,0 @@ -#if !defined(acm_hdr_sav) -#define acm_hdr_sav - -#include <acm/bs.h> - -void acm_cont(acm_pldat * pldat); -void acm_sav( acm_pldat const * pldat); - -#endif diff --git a/procyon/source/bs/dbglog.c b/procyon/source/bs/dbglog.c deleted file mode 100644 index d04174f..0000000 --- a/procyon/source/bs/dbglog.c +++ /dev/null @@ -1,11 +0,0 @@ -#include <acm/bs.h> - -#include <stdarg.h> -#include <stdio.h> - -void acm_dbglog(char const * const _fmt,...) { - va_list args; - va_start(args,_fmt); - vfprintf(stderr,_fmt,args); - va_end(args); -} diff --git a/procyon/source/bs/exit.c b/procyon/source/bs/exit.c deleted file mode 100644 index e49dfc9..0000000 --- a/procyon/source/bs/exit.c +++ /dev/null @@ -1,15 +0,0 @@ -#include <acm/bs.h> - -#include <GLFW/glfw3.h> -#include <stdlib.h> - -void acm_exit(acm_stat const _stat) { - int const cstat = _stat == acm_stat_ok ? EXIT_SUCCESS : EXIT_FAILURE; - free((void *)acm_dat.savloc); - if (acm_dat.gfxisinit) { - glfwDestroyWindow(acm_dat.win); - glfwTerminate(); - } - acm_log("Done (%X)\n",cstat); - exit(cstat); -} diff --git a/procyon/source/bs/init.c b/procyon/source/bs/init.c deleted file mode 100644 index 1f4c57e..0000000 --- a/procyon/source/bs/init.c +++ /dev/null @@ -1,51 +0,0 @@ -#include <acm/gfx.h> - -#include <signal.h> -#include <stdio.h> -#include <stdlib.h> -#include <zap/mem.h> - -sig_atomic_t volatile acm_gotintr; - -typeof (acm_dat) acm_dat; - -static char * acm_getsavloc(void) { - char const * const hmdir = getenv("HOME"); - if (hmdir == nullptr) { - fprintf(stderr,"Unable to get home directory (HOME not set)\n"); - acm_exit(acm_stat_err); - } - char const * const savfilnm = ".procyon-save"; - zap_sz const hmdirlen = zap_strlen(hmdir); - zap_sz const savfilnmlen = zap_strlen(savfilnm); - zap_sz const savloclen = hmdirlen + 0x1u + savfilnmlen; - char * savloc = malloc(savloclen + 0x1u); - if (savloc == nullptr) { - fprintf(stderr,"Unable allocate memory\n"); - acm_exit(acm_stat_err); - } - zap_memcp(hmdir,hmdirlen,savloc); - savloc[hmdirlen] = '/'; - zap_memcp(savfilnm,savfilnmlen,savloc + hmdirlen + 0x1u); - savloc[savloclen] = 0x0u; - return savloc; -} - -static void acm_intrhandl(int const _sig) { - signal(_sig,acm_intrhandl); /* Ignore the return value. */ - acm_gotintr = 0x1; -} - -void acm_init(void) { - acm_gotintr = 0x0; - acm_dat.gfxisinit = false; - acm_dat.win = nullptr; - acm_log("Initialising data\n"); - acm_dat.savloc = acm_getsavloc(); - acm_log("Initialising signal handlers\n"); - if (signal(SIGINT,acm_intrhandl) == SIG_ERR) { - fprintf(stderr,"Unable to set SIGINT handler\n"); - acm_exit(acm_stat_err); - } - acm_initgfx(); -} diff --git a/procyon/source/bs/shipnm.c b/procyon/source/bs/shipnm.c deleted file mode 100644 index f1d8f4e..0000000 --- a/procyon/source/bs/shipnm.c +++ /dev/null @@ -1,70 +0,0 @@ -#include <acm/bs.h> - -char const * acm_shipnm(acm_shipid const _ship) { - switch (_ship) { - case acm_shipid_add: - return "Adder"; - case acm_shipid_ana: - return "Anaconda"; - case acm_shipid_asp: - return "Asp"; - case acm_shipid_boa: - return "Boa"; - case acm_shipid_cob: - return "Cobra"; - case acm_shipid_con: - return "Constrictor"; - case acm_shipid_cou: - return "Courier"; - case acm_shipid_cyg: - return "Cygnus"; - case acm_shipid_dov: - return "Dove"; - case acm_shipid_eag: - return "Eagle"; - case acm_shipid_falc: - return "Falcon"; - case acm_shipid_fer: - return "Fer-de-lance"; - case acm_shipid_frei: - return "Freighter"; - case acm_shipid_geck: - return "Gecko"; - case acm_shipid_haul: - return "Hauler"; - case acm_shipid_hawk: - return "Hawk"; - case acm_shipid_keel: - return "Keelback"; - case acm_shipid_kes: - return "Kestral"; - case acm_shipid_krait: - return "Krait"; - case acm_shipid_lift: - return "Lifter"; - case acm_shipid_lion: - return "Lion"; - case acm_shipid_mamba: - return "Mamba"; - case acm_shipid_moray: - return "Moray"; - case acm_shipid_osp: - return "Osprey"; - case acm_shipid_pan: - return "Panther"; - case acm_shipid_puma: - return "Puma"; - case acm_shipid_py: - return "Python"; - case acm_shipid_shut: - return "Shuttle"; - case acm_shipid_side: - return "Sidewinder"; - case acm_shipid_tran: - return "Transporter"; - case acm_shipid_vip: - return "Viper"; - case acm_shipid_vult: - return "Vulture"; - } -} diff --git a/procyon/source/evt/jmp.c b/procyon/source/evt/jmp.c deleted file mode 100644 index 5a93491..0000000 --- a/procyon/source/evt/jmp.c +++ /dev/null @@ -1,13 +0,0 @@ -#include <acm/evt.h> -#include <acm/info.h> - -#include <stdint.h> - -bool acm_jmp(uint_least64_t const _sys) { - acm_pldat pldat = acm_dat.pldat; - if (acm_sysdist(_sys) > acm_jmplen(&pldat.ship)) { - return true; - } - acm_dat.pldat = pldat; - return false; -} diff --git a/procyon/source/gfx/initgfx.c b/procyon/source/gfx/initgfx.c deleted file mode 100644 index d60e393..0000000 --- a/procyon/source/gfx/initgfx.c +++ /dev/null @@ -1,22 +0,0 @@ -#include <acm/gfx.h> - -#include <GLFW/glfw3.h> - -void acm_initgfx(void) { - acm_log("Initialising graphics\n"); - if (!glfwInit()) { - fprintf(stderr,"Unable to initialise GLFW\n"); - acm_exit(acm_stat_err); - } - GLFWwindow * win = glfwCreateWindow(0x300,0x200,"Procyon",nullptr,nullptr); - if (win == nullptr) { - fprintf(stderr,"Unable to open window\n"); - goto abrt; - } - glfwMakeContextCurrent(win); - acm_dat.win = win; - return; -abrt:; - glfwTerminate(); - acm_exit(acm_stat_err); -} diff --git a/procyon/source/info/jmplen.c b/procyon/source/info/jmplen.c deleted file mode 100644 index 7ef8995..0000000 --- a/procyon/source/info/jmplen.c +++ /dev/null @@ -1,7 +0,0 @@ -#include <acm/info.h> - -#include <stdint.h> - -uint_least64_t acm_jmplen(acm_ship const * _ship) { - return 0x0u; -} diff --git a/procyon/source/info/sysdist.c b/procyon/source/info/sysdist.c deleted file mode 100644 index 2e77220..0000000 --- a/procyon/source/info/sysdist.c +++ /dev/null @@ -1,7 +0,0 @@ -#include <acm/info.h> - -#include <stdint.h> - -uint_least64_t acm_sysdist(uint_least64_t const _sys) { - return ~(uint_least64_t)0x0u; -} diff --git a/procyon/source/main.c b/procyon/source/main.c deleted file mode 100644 index 19439a4..0000000 --- a/procyon/source/main.c +++ /dev/null @@ -1,24 +0,0 @@ -#include <acm/sav.h> - -#include <flux.h> -#include <inttypes.h> -#include <stdio.h> - -int main(int const argc,[[maybe_unused]] char const * const * const argv) { - acm_dat.gfxisinit = false; - if (argc > 0x1) { - fprintf(stderr,"Ignoring terminal options\n"); - } - printf("Procyon, %" PRIxLEAST64 " - Copyright 2022 Gabriel Jensen.\n",acm_ver); - acm_init(); - acm_cont(&acm_dat.pldat); - acm_log("Ready\n"); - while (!glfwWindowShouldClose(acm_dat.win)) { - if (acm_gotintr) { - fprintf(stderr,"Got interrupt, stopping\n"); - glfwSetWindowShouldClose(acm_dat.win,0x1); - } - } - acm_sav(&acm_dat.pldat); - acm_exit(acm_stat_ok); -} diff --git a/procyon/source/sav/cont.c b/procyon/source/sav/cont.c deleted file mode 100644 index e52fd76..0000000 --- a/procyon/source/sav/cont.c +++ /dev/null @@ -1,81 +0,0 @@ -#include <acm/info.h> -#include <acm/sav.h> - -#include <flux.h> -#include <inttypes.h> -#include <zap/mem.h> - -static_assert(sizeof (acm_dflplnm) == acm_plnmlen); - -void acm_cont(acm_pldat * const _pldat) { - acm_log("Continuing\n"); - acm_pldat pldat; - uint_least64_t savver; - flux_err fluxerr; - flux_fil savfil; - fluxerr = flux_op(&savfil,acm_dat.savloc,flux_md_rd,flux_keep); - if (fluxerr) { - acm_log("Unable to open save file, starting new game: %s\n",flux_errstr(fluxerr)); - goto new; - } - fluxerr = flux_rd(savfil,sizeof (savver),&savver,nullptr); - if (!fluxerr) { - fluxerr = flux_rd(savfil,sizeof (pldat),&pldat,nullptr); - } - flux_cl(savfil); - if (fluxerr) { - acm_log("Unable to read save file, starting new game: %s\n",flux_errstr(fluxerr)); - goto new; - } - if (savver != acm_savver) { - printf("Old save version (%" PRIXLEAST64 "), starting new game: %s\n",savver,flux_errstr(fluxerr)); - goto new; - } - acm_log("Validating commander name\n"); - bool validnm = false; - for (zap_sz n = 0x0u;n < acm_plnmlen + 0x1u;++n) { - if (pldat.nm[n] == '\x0') { - if (n == 0x0u) { - break; - } - validnm = true; - break; - } - } - if (!validnm) { - acm_log("Invalid commander name (corrupt save file), starting new game\n"); - acm_log( - "Commander name:\n" - " %hhX %hhX %hhX %hhX\n" - " %hhX %hhX %hhX %hhX\n" - " %hhX %hhX %hhX %hhX\n" - " %hhX %hhX %hhX %hhX\n" - " %hhX\n", - pldat.nm[0x0u],pldat.nm[0x1u],pldat.nm[0x2u],pldat.nm[0x3u], - pldat.nm[0x4u],pldat.nm[0x5u],pldat.nm[0x6u],pldat.nm[0x7u], - pldat.nm[0x8u],pldat.nm[0x9u],pldat.nm[0xAu],pldat.nm[0xBu], - pldat.nm[0xCu],pldat.nm[0xDu],pldat.nm[0xEu],pldat.nm[0xFu], - pldat.nm[0x10u] - ); - goto new; - } - printf("Loaded CMDR %s, %s @ %" PRIiLEAST64 "\n",pldat.nm,acm_shipnm(pldat.ship.id),pldat.tm); - *_pldat = pldat; - return; -new:; - pldat.heat = 0x120u; /* 288K */ - pldat.pos.px = 0x0u; - pldat.pos.py = 0x0u; - pldat.pos.pz = 0x0u; - pldat.pos.rx = 0x0u; - pldat.pos.ry = 0x0u; - pldat.pos.rz = 0x0u; - pldat.pos.vx = 0x0u; - pldat.pos.vy = 0x0u; - pldat.pos.vz = 0x0u; - pldat.ship.drv = acm_drv_h1; - pldat.ship.id = acm_shipid_side; - pldat.tm = 0x9679C2B40u; /* 3250-01-01T12:00:00Z */ - zap_memcp(acm_dflplnm,acm_plnmlen + 0x1u,pldat.nm); - *_pldat = pldat; -} diff --git a/procyon/source/sav/sav.c b/procyon/source/sav/sav.c deleted file mode 100644 index d7301c7..0000000 --- a/procyon/source/sav/sav.c +++ /dev/null @@ -1,35 +0,0 @@ -#include <acm/sav.h> - -#include <flux.h> -#include <stdio.h> - -void acm_sav(acm_pldat const * const _pldat) { - acm_log("Saving\n"); - flux_err fluxerr; - flux_fil savfil; - fluxerr = flux_mkfil(&savfil,acm_dat.savloc,0644u); - if (fluxerr) { - if (fluxerr != flux_err_exist) { - fprintf(stderr,"Unable to create save file (\"%s\"): %s\n",acm_dat.savloc,flux_errstr(fluxerr)); - acm_exit(acm_stat_err); - } - acm_log("Save file already exists, overwritting\n"); - fluxerr = flux_op(&savfil,acm_dat.savloc,flux_md_wr,flux_disc); - if (fluxerr) { - fprintf(stderr,"Unable to open save file: %s\n",flux_errstr(fluxerr)); - acm_exit(acm_stat_err); - } - } - { - uint_least64_t const savver = acm_savver; - fluxerr = flux_wr(savfil,&savver,sizeof (savver)); - } - if (!fluxerr) { - fluxerr = flux_wr(savfil,_pldat,sizeof (*_pldat)); - } - if (fluxerr) { - fprintf(stderr,"Unable to write to save file: %s\n",flux_errstr(fluxerr)); - acm_exit(acm_stat_err); - } - flux_cl(savfil); -} |