diff options
-rw-r--r-- | CHANGELOG.txt | 6 | ||||
-rw-r--r-- | bowshock-small.svg | 9 | ||||
-rwxr-xr-x[-rw-r--r--] | bowshock.desktop | 1 | ||||
-rw-r--r-- | bowshock.svg | 8 | ||||
-rw-r--r-- | bowshock/GNUmakefile | 25 | ||||
-rw-r--r-- | bowshock/include/bow/bs.h | 31 | ||||
-rw-r--r-- | bowshock/include/bow/sav.h | 11 | ||||
-rw-r--r-- | bowshock/source/bs/init.c | 8 | ||||
-rw-r--r-- | bowshock/source/bs/initdat.c | 37 | ||||
-rw-r--r-- | bowshock/source/sav/sav.c | 33 |
10 files changed, 155 insertions, 14 deletions
diff --git a/CHANGELOG.txt b/CHANGELOG.txt index 50b21f7..502b2ec 100644 --- a/CHANGELOG.txt +++ b/CHANGELOG.txt @@ -1,3 +1,9 @@ +# 4 + +* Add simple save routine; +* Add logo; +* Add clean and purge targets to makefile; + # 3 * Fix incorrect symbol names; diff --git a/bowshock-small.svg b/bowshock-small.svg new file mode 100644 index 0000000..bf33e9a --- /dev/null +++ b/bowshock-small.svg @@ -0,0 +1,9 @@ +<!-- Copyright 2023 Gabriel Jensen. --> +<svg height="96" width="96" xmlns="http://www.w3.org/2000/svg"> + <!-- background --> + <circle cx="48" cy="54" fill="#B61833" r="36" /> + <circle cx="48" cy="42" fill="#B61833" r="36" /> + <!-- circles --> + <circle cx="48" cy="54" fill="none" r="24" stroke="#FFEEE0" stroke-width="12" /> + <circle cx="48" cy="42" fill="none" r="24" stroke="#0F0F0F" stroke-width="12" /> +</svg> diff --git a/bowshock.desktop b/bowshock.desktop index 2e9ab6d..1d8dc3d 100644..100755 --- a/bowshock.desktop +++ b/bowshock.desktop @@ -2,3 +2,4 @@ Type=Application Name=Bowshock Exec=/usr/bin/bowshock +Icon=bowshock diff --git a/bowshock.svg b/bowshock.svg new file mode 100644 index 0000000..d0624e3 --- /dev/null +++ b/bowshock.svg @@ -0,0 +1,8 @@ +<!-- Copyright 2023 Gabriel Jensen. --> +<svg height="120" width="120" xmlns="http://www.w3.org/2000/svg"> + <!-- background --> + <circle cx="60" cy="60" fill="#B61833" r="48" /> + <!-- circles --> + <circle cx="60" cy="66" fill="none" r="24" stroke="#FFEEE0" stroke-width="12" /> + <circle cx="60" cy="54" fill="none" r="24" stroke="#0F0F0F" stroke-width="12" /> +</svg> diff --git a/bowshock/GNUmakefile b/bowshock/GNUmakefile index c9ed20d..eaf09d3 100644 --- a/bowshock/GNUmakefile +++ b/bowshock/GNUmakefile @@ -6,11 +6,25 @@ CFLAGS := \ -Wall \ -Wextra \ -Wpedantic \ + -Wno-gnu-folding-constant \ -Wno-gnu-empty-initializer \ -Wno-gnu-zero-variadic-macro-arguments \ -g \ + -pipe \ -std=c2x +ifeq "$(c2xcompat)" "true" +CFLAGS := \ + $(CFLAGS) \ + -Dbool="_Bool" \ + -Dfalse="((_Bool)0x0u)" \ + -Dnullptr="((void *)0x0u)" \ + -Dstatic_assert="_Static_assert" \ + -Dthread_safe="_Thread_safe" \ + -Dtypeof="__typeof__" \ + -Dtrue="((_Bool)0x1u)" +endif + ifeq "$(debug)" "true" CFLAGS := \ $(CFLAGS) \ @@ -33,7 +47,8 @@ OBJS := \ source/gfx/initgfx.o \ source/info/shipmass.o \ source/lgc/grav.o \ - source/lgc/mv.o + source/lgc/mv.o \ + source/sav/sav.o BIN := bowshock.elf @@ -43,7 +58,15 @@ HDRS := \ include/bow/lgc.h \ include/bow/sav.h +.PHONY: clean purge + $(BIN): $(OBJS) $(LD) -o$(@) $(^) $(LDLIBS) $(OBJS): $(HDRS) + +clean: + $(RM) $(OBJS) + +purge: clean + $(RM) $(BIN) diff --git a/bowshock/include/bow/bs.h b/bowshock/include/bow/bs.h index c0a82fa..b3514da 100644 --- a/bowshock/include/bow/bs.h +++ b/bowshock/include/bow/bs.h @@ -24,7 +24,9 @@ #define bow_logxyz(xyz) ((void)0x0u) #endif -constexpr zap_i04 bow_ver; +constexpr zap_i04 bow_ver = 0x4u; + +constexpr zap_sz bow_cmdrnmlen = 0xEu; typedef enum { bow_stat_ok = 0x0u, @@ -42,6 +44,15 @@ typedef enum { } bow_objtyp; typedef enum { + bow_world_amm, // ammonium world + bow_world_gas, // gas giant + bow_world_ice, // icy world + bow_world_rck, // rocky world + bow_world_lav, // lava world + bow_world_wat, // water world +} bow_world; + +typedef enum { bow_ship_aq, // aquila bow_ship_cas, // cassiopeia bow_ship_cent, // centaurus @@ -71,8 +82,8 @@ typedef enum { } bow_star; typedef enum { - bow_star_cor, // coriolis -} bow_stat; + bow_station_cor, // coriolis +} bow_station; typedef struct { double x; @@ -87,19 +98,21 @@ typedef struct { bow_xyz vel; double mass; union { - bow_ship shiptyp; - bow_star startyp; - bow_stat stattyp; + bow_world worldtyp; + bow_ship shiptyp; + bow_star startyp; + bow_station stationtyp; }; } bow_obj; typedef struct { - zap_i04 sysid; - bow_obj ship; + char nm[bow_cmdrnmlen + 0x1u]; + zap_i04 sysid; + bow_obj ship; } bow_playdat; void bow_gendat( bow_playdat * playdat); -void bow_initdat(bow_playdat * playdat); +void bow_initdat(bow_playdat * playdat,char const * * savpth); [[noreturn]] void bow_quit(bow_stat stat); diff --git a/bowshock/include/bow/sav.h b/bowshock/include/bow/sav.h index da2e6c8..be5978d 100644 --- a/bowshock/include/bow/sav.h +++ b/bowshock/include/bow/sav.h @@ -3,6 +3,17 @@ #include <bow/bs.h> +#include <zap/bs.h> + +constexpr zap_i04 bow_savfmtver = 0x3u; + +typedef struct { + zap_i04 fmtver; + char cmdrnm[bow_cmdrnmlen]; + zap_i04 sysid; + bow_obj ship; +} bow_savdat; + void bow_cont(char const * fil,bow_playdat * dat); void bow_sav( char const * fil,bow_playdat const * dat); diff --git a/bowshock/source/bs/init.c b/bowshock/source/bs/init.c index 8fabb90..64c7d85 100644 --- a/bowshock/source/bs/init.c +++ b/bowshock/source/bs/init.c @@ -4,16 +4,20 @@ #include <bow/sav.h> #include <flux.h> +#include <inttypes.h> +#include <stdlib.h> bow_stat bow_loop(bow_playdat * playdat); [[noreturn]] void bow_init(void) { + char const * savpth; 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_rawlog("\x1B[0m\x1B[1mBowshock\x1B[0m %" PRIX64 " \u2013 Copyright 2022\u20102023, \x1B[1mGabriel Jensen\x1B[0m.\n\n",bow_ver); bow_log("initialising"); - bow_initdat(&playdat); + bow_initdat(&playdat,&savpth); bow_initgfx(); bow_loop(&playdat); + bow_sav(savpth,&playdat); bow_quit(bow_stat_ok); } diff --git a/bowshock/source/bs/initdat.c b/bowshock/source/bs/initdat.c index ee8a190..0bba930 100644 --- a/bowshock/source/bs/initdat.c +++ b/bowshock/source/bs/initdat.c @@ -3,13 +3,45 @@ #include <bow/bs.h> #include <flux.h> +#include <stdlib.h> +#include <string.h> #include <zap/mem.h> +#include <zap/str.h> -#include <string.h> +#define bow_setstr(ptr,len,str) ((void)(ptr = str,len = sizeof (str))) + +static char * bow_getsavpth(void) { + char const * hmdir = getenv("HOME"); + zap_sz hmdirlen; + char const * filnm; + zap_sz filnmlen; + if (hmdir == nullptr) { + bow_log("unable to get home directory"); + bow_setstr(hmdir,hmdirlen,"./"); + } + else hmdirlen = zap_strlen(hmdir); + bow_setstr(filnm,filnmlen,".save.bowshock"); + zap_sz pthsz = hmdirlen + filnmlen + 0x2u; + char * pth = malloc(pthsz); + if (pth == nullptr) { + bow_log("unable to allocate memory"); + bow_quit(bow_stat_err); + } + memcpy(pth,hmdir,hmdirlen); + pth += hmdirlen; + *pth++ = '/'; + memcpy(pth,filnm,filnmlen); + pth += filnmlen; + *pth++ = '\x0'; + pth -= pthsz; + return pth; +} -void bow_initdat(bow_playdat * const playdatptr) { +void bow_initdat(bow_playdat * const playdatptr,char const * * const savpthptr) { bow_log("initialising data"); + char const * savpth = bow_getsavpth(); bow_playdat playdat = { + .nm = "Caelum\x0\x0\x0\x0\x0\x0\x0\x0\x0", .sysid = 0x0u, .ship = { .typ = bow_objtyp_ship, @@ -27,5 +59,6 @@ void bow_initdat(bow_playdat * const playdatptr) { }, }; bow_gendat(&playdat); + *savpthptr = savpth; memcpy(playdatptr,&playdat,sizeof (playdat)); } diff --git a/bowshock/source/sav/sav.c b/bowshock/source/sav/sav.c new file mode 100644 index 0000000..dc32399 --- /dev/null +++ b/bowshock/source/sav/sav.c @@ -0,0 +1,33 @@ +#define bow_sym "sav" + +#include <bow/sav.h> + +#include <flux.h> +#include <zap/mem.h> + +void bow_sav(char const * const pth,bow_playdat const * const playdatptr) { + bow_log("saving commander %s at \"%s\"",playdatptr->nm,pth); + flux_fil fil; + flux_err err = flux_mkfil(&fil,pth,0644); + if (err != flux_err_ok) { + if (err != flux_err_exist) { + bow_log("unable to open save file \"%s\"",pth); + bow_quit(bow_stat_err); + } + err = flux_op(&fil,pth,flux_md_wr,flux_disc); + if (err != flux_err_ok) { + bow_log("unable to create save file \"%s\"",pth); + bow_quit(bow_stat_err); + } + } + bow_playdat playdat; + zap_cp(&playdat,playdatptr,sizeof (playdat)); + bow_savdat dat = { + .fmtver = bow_savfmtver, + .sysid = playdat.sysid, + .ship = playdat.ship, + }; + zap_cp(dat.cmdrnm,playdat.nm,bow_cmdrnmlen); + flux_wr(fil,&dat,sizeof (dat)); + flux_cl(fil); +} |