diff options
-rw-r--r-- | .gitignore | 1 | ||||
-rw-r--r-- | CHANGELOG.txt | 8 | ||||
-rw-r--r-- | bowshock/GNUmakefile | 6 | ||||
-rw-r--r-- | bowshock/include/bow/bs.h | 19 | ||||
-rw-r--r-- | bowshock/include/bow/info.h | 2 | ||||
-rw-r--r-- | bowshock/include/bow/lgc.h | 4 | ||||
-rw-r--r-- | bowshock/include/bow/sav.h | 17 | ||||
-rw-r--r-- | bowshock/source/bs/init.c | 217 | ||||
-rw-r--r-- | bowshock/source/bs/loop.c | 103 | ||||
-rw-r--r-- | bowshock/source/info/shipmass.c | 4 | ||||
-rw-r--r-- | bowshock/source/sav/cont.c | 23 | ||||
-rw-r--r-- | bowshock/source/sav/sav.c | 1 |
12 files changed, 251 insertions, 154 deletions
@@ -2,5 +2,6 @@ *.elf *.exe *.o +*.webp log.* vgcore.* diff --git a/CHANGELOG.txt b/CHANGELOG.txt index 6f920f2..a637ae1 100644 --- a/CHANGELOG.txt +++ b/CHANGELOG.txt @@ -1,3 +1,11 @@ +# 0.6 + +* Update versioning: Use major.minor; +* Update save format; +* Fix invalid symbol; +* Add quotes; +* Save simulation result to image; + # 5 * Update save data format; diff --git a/bowshock/GNUmakefile b/bowshock/GNUmakefile index e6b4a9e..f68db40 100644 --- a/bowshock/GNUmakefile +++ b/bowshock/GNUmakefile @@ -27,8 +27,9 @@ endif ifeq "$(debug)" "true" CFLAGS := \ - $(CFLAGS) \ - -Dbow_dbg=true + $(CFLAGS) \ + -Dbow_dbg=true \ + -Og endif LDLIBS := \ @@ -36,6 +37,7 @@ LDLIBS := \ -lflux \ -lglfw \ -lm \ + -lwebp \ -lzap OBJS := \ diff --git a/bowshock/include/bow/bs.h b/bowshock/include/bow/bs.h index 4836713..8af25b9 100644 --- a/bowshock/include/bow/bs.h +++ b/bowshock/include/bow/bs.h @@ -27,7 +27,8 @@ #define bow_logxyz(xyz) ((void)0x0u) #endif -constexpr zap_i04 bow_ver = 0x5u; +constexpr zap_i04 bow_vermaj = 0x0u; +constexpr zap_i04 bow_vermin = 0x6u; constexpr zap_sz bow_cmdrnmlen = 0xEu; @@ -37,13 +38,13 @@ typedef enum { } 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_can, // canister + bow_objtyp_play, // player + bow_objtyp_sat, // satellite (moon) + bow_objtyp_ship, // ship + bow_objtyp_star, // star + bow_objtyp_station, // station + bow_objtyp_wrld, // world (planet) } bow_objtyp; typedef enum { @@ -110,8 +111,8 @@ typedef struct { typedef struct { char nm[bow_cmdrnmlen + 0x1u]; + zap_i04 tm; zap_i04 sysid; - zap_i04 tm; // 1728th of a second bow_obj ship; } bow_playdat; diff --git a/bowshock/include/bow/info.h b/bowshock/include/bow/info.h index e64b46b..db7e152 100644 --- a/bowshock/include/bow/info.h +++ b/bowshock/include/bow/info.h @@ -3,6 +3,6 @@ #include <bow/bs.h> -double bow_shipmass(bow_ship id); +[[unsequenced]] double bow_shipmass(bow_ship id); #endif diff --git a/bowshock/include/bow/lgc.h b/bowshock/include/bow/lgc.h index 10a139d..b2f23eb 100644 --- a/bowshock/include/bow/lgc.h +++ b/bowshock/include/bow/lgc.h @@ -3,7 +3,9 @@ #include <bow/bs.h> -constexpr double bow_gravconst = 0x1.0p-2; // gravitational constant +constexpr double bow_timemod = 0x1p-10; // time modifier + +constexpr double bow_gravconst = 0x1p0 * bow_timemod; // gravitational constant void bow_grav(bow_obj * obj,bow_obj const * par); void bow_mv( bow_obj * obj); diff --git a/bowshock/include/bow/sav.h b/bowshock/include/bow/sav.h index 23df6f0..e548a8e 100644 --- a/bowshock/include/bow/sav.h +++ b/bowshock/include/bow/sav.h @@ -5,16 +5,17 @@ #include <zap/bs.h> -constexpr zap_i04 bow_savfmtver = 0x4u; +constexpr zap_i04 bow_savfmtver = 0x5u; typedef struct { - zap_i04 fmtver; - char cmdrnm[bow_cmdrnmlen]; - zap_i04 sysid; - zap_i04 tm; - bow_xyz shippos; - bow_xyz shiprot; - bow_xyz shipvel; + zap_i04 fmtver; + char cmdrnm[bow_cmdrnmlen]; + zap_i04 tm; + zap_i04 sysid; + bow_ship shiptyp; + bow_xyz shippos; + bow_xyz shiprot; + bow_xyz shipvel; } bow_savdat; void bow_cont(char const * fil,bow_playdat * dat); diff --git a/bowshock/source/bs/init.c b/bowshock/source/bs/init.c index 6ccf132..6280f10 100644 --- a/bowshock/source/bs/init.c +++ b/bowshock/source/bs/init.c @@ -13,6 +13,8 @@ bow_stat bow_loop(bow_playdat * playdat); sig_atomic_t volatile bow_gotintr; +static bool bow_getquot(char const * * quot,char const * * src,zap_i8 id); + static void bow_intrhandl(int const sig) { signal(sig,bow_intrhandl); // Ignore the return value. bow_gotintr = 0x1; @@ -27,12 +29,12 @@ int main(int const argc,char const * const * argv) { if (zap_streq(arg,"--help")) { bow_rawlog( "\n" - "bowshock %" PRIXLEAST64 "\n" + "bowshock %" PRIXLEAST64 ".%" PRIXLEAST64 "\n" "Copyright 2022-2023 Gabriel Jensen\n" "\n" "Usage: %s [savefile]\n" "\n", - bow_ver,prognm); + bow_vermaj,bow_vermin,prognm); return EXIT_SUCCESS; } bow_logerr("invalid parameter \"%s\"",arg); @@ -40,96 +42,16 @@ int main(int const argc,char const * const * argv) { } srand((unsigned int)time(nullptr)); { - zap_i8 const quotid = (unsigned int)rand() % 0x14u; + zap_i8 const quotid = (unsigned int)rand() % 0x1Du; char const * quot; char const * src; - switch (quotid) { - default: + if (bow_getquot(",&src,quotid)) { bow_logerr("invalid quote identifier (%" PRIXLEAST8 ")",quotid); - [[fallthrough]]; - case 0x0u: - quot = "You gotta be heaven to see heaven."; - src = "Jim Carrey"; - break; - case 0x1u: - quot = "Though it's the end of the world, don't blame yourself, now."; - src = "Porter Robinson"; - break; - case 0x2u: - quot = "The future will be better tomorrow."; - src = "Dan Quayle"; - break; - case 0x3u: - quot = "Sir, an equation has no meaning for me unless it expresses a thought of god."; - src = "Srinivasa Ramanujan Aiyangar"; - break; - case 0x4u: - quot = "Amīcus Platō amīcus Aristotelēs magis amīca vēritās."; - src = "Isaac Newton"; - break; - case 0x5u: - quot = "I have studied these things \u2013 you have not."; - src = "Isaac Newton"; - break; - case 0x6u: - quot = "La construction d'une machine propre à exprimer tous les sons de nos paroles, avec toutes les articulations, serait sans doute une décourverte bien importante.\n... La chose ne me paraît pas impossible."; - src = "Leonhard Euler"; - break; - case 0x7u: - quot = "In mathematics, you don't understand things, you just get used to them."; - src = "John von Neumann"; - break; - case 0x8u: - quot = "Being a language, mathematics may be used not only to inform, but also \u2013 among other things \u2013 to seduce."; - src = "Benoît B. Mandelbrot"; - break; - case 0x9u: - quot = "The real question is not whether machines think, but whether men do."; - src = "Burrhus Frederic Skinner"; - break; - case 0xAu: - quot = "Those who are not shocked when they first come across quantum theory cannot possibly have understood it."; - src = "Niels Henrik David Bohr"; - case 0xBu: - quot = "Every sentence I utter must be understood not as an affirmation, but as a question."; - src = "Niels Henrik David Bohr"; - break; - case 0xCu: - quot = "We will now discuss in a little more detail the struggle for existence."; - src = "Charles Robert Darwin"; - break; - case 0xDu: - quot = "不患人之不己知,患不知人也。"; - src = "孔丘"; - break; - case 0xEu: - quot = "We don't know a millionth of one percent about anything."; - src = "Thomas Alva Edison"; - break; - case 0xFu: - quot = "My goal is simple. It is a complete understanding of the universe, why it is as it is, and why it exists at all."; - src = "Stephen William Hawking"; - break; - case 0x10u: - quot = "Equipped with his five senses, man explores the universe around him and calls the adventure Science."; - src = "Edwin Powell Hubble"; - break; - case 0x11u: - quot = "I can say this. I believe that the human mind, or even the mind of a cat, is more interesting in its complexity than an entire galaxy if it is devoid of life."; - src = "Martin Gardner"; - break; - case 0x12u: - quot = "I'm always right. This time I'm just more right than usual."; - src = "Linus Benedict Torvalds"; - break; - case 0x13u: - quot = "I'm an instant star. Just add water and stir."; - src = "David Robert Jones"; - break; + bow_getquot(",&src,0x0u); } bow_rawlog("\n%s\n\u2014 %s\n\n",quot,src); } - bow_rawlog("\x1B[0m\x1B[1mBowshock\x1B[0m %" PRIXLEAST64 " \u2013 Copyright 2022\u20102023, \x1B[1mGabriel Jensen\x1B[0m.\n\n",bow_ver); + bow_rawlog("\x1B[0m\x1B[1mBowshock\x1B[0m %" PRIXLEAST64 ".%" PRIXLEAST64 " \u2013 Copyright 2022\u20102023, \x1B[1mGabriel Jensen\x1B[0m.\n\n",bow_vermaj,bow_vermin); bow_log("initialising"); bow_gotintr = 0x0; if (signal(SIGINT,bow_intrhandl) == SIG_ERR) { @@ -144,3 +66,126 @@ int main(int const argc,char const * const * argv) { bow_sav(savpth,&playdat); bow_quit(bow_stat_ok); } + +static bool bow_getquot(char const * * const quot,char const * * src,zap_i8 const id) { + switch (id) { + default: + return true; + case 0x0u: + *quot = "You gotta be heaven to see heaven."; + *src = "Jim Carrey"; + break; + case 0x1u: + *quot = "Though it's the end of the world, don't blame yourself, now."; + *src = "Porter Robinson"; + break; + case 0x2u: + *quot = "The future will be better tomorrow."; + *src = "Dan Quayle"; + break; + case 0x3u: + *quot = "Sir, an equation has no meaning for me unless it expresses a thought of god."; + *src = "Srinivasa Ramanujan Aiyangar"; + break; + case 0x4u: + *quot = "Amīcus Platō amīcus Aristotelēs magis amīca vēritās."; + *src = "Isaac Newton"; + break; + case 0x5u: + *quot = "I have studied these things \u2013 you have not."; + *src = "Isaac Newton"; + break; + case 0x6u: + *quot = "La construction d'une machine propre à exprimer tous les sons de nos paroles, avec toutes les articulations, serait sans doute une décourverte bien importante.\n... La chose ne me paraît pas impossible."; + *src = "Leonhard Euler"; + break; + case 0x7u: + *quot = "In mathematics, you don't understand things, you just get used to them."; + *src = "John von Neumann"; + break; + case 0x8u: + *quot = "Being a language, mathematics may be used not only to inform, but also \u2013 among other things \u2013 to seduce."; + *src = "Benoît B. Mandelbrot"; + break; + case 0x9u: + *quot = "The real question is not whether machines think, but whether men do."; + *src = "Burrhus Frederic Skinner"; + break; + case 0xAu: + *quot = "Those who are not shocked when they first come across quantum theory cannot possibly have understood it."; + *src = "Niels Henrik David Bohr"; + case 0xBu: + *quot = "Every sentence I utter must be understood not as an affirmation, but as a question."; + *src = "Niels Henrik David Bohr"; + break; + case 0xCu: + *quot = "We will now discuss in a little more detail the struggle for existence."; + *src = "Charles Robert Darwin"; + break; + case 0xDu: + *quot = "Nam et ipsa scientia potestas est."; + *src = "Francis Bacon"; + break; + case 0xEu: + *quot = "We don't know a millionth of one percent about anything."; + *src = "Thomas Alva Edison"; + break; + case 0xFu: + *quot = "My goal is simple. It is a complete understanding of the universe, why it is as it is, and why it exists at all."; + *src = "Stephen William Hawking"; + break; + case 0x10u: + *quot = "Equipped with his five senses, man explores the universe around him and calls the adventure Science."; + *src = "Edwin Powell Hubble"; + break; + case 0x11u: + *quot = "I can say this: I believe that the human mind, or even the mind of a cat, is more interesting in its complexity than an entire galaxy if it is devoid of life."; + *src = "Martin Gardner"; + break; + case 0x12u: + *quot = "I'm always right. This time I'm just more right than usual."; + *src = "Linus Benedict Torvalds"; + break; + case 0x13u: + *quot = "I'm an instant star. Just add water and stir."; + *src = "David Robert Jones"; + break; + case 0x14u: + *quot = "Don't waste the Earth \u2013 it is our jewel!"; + *src = "Buzz Eugene Aldrin"; + break; + case 0x15u: + *quot = "I think we're going to the moon because it's in the nature of the human being to face challenges."; + *src = "Neil Alden Armstrong"; + break; + case 0x16u: + *quot = "A hacker is someone who enjoys playful cleverness \u2013 not necessarily with computers."; + *src = "Richard Matthew Stallman"; + break; + case 0x17u: + *quot = "So Einstein was wrong when he said \"God noes not play dice.\". Consideration of black holes suggests, not only that God does play dice, but that he sometimes confuses us by throwing them where they can't be seen."; + *src = "Stephen William Hawking"; + break; + case 0x18u: + *quot = "I'm a blackstar."; + *src = "David Robert Jones"; + break; + case 0x19u: + *quot = "Sooner or later, we must expand life beyond our little blue mud ball \u2013 or go extinct."; + *src = "Elon Reeve Musk"; + break; + case 0x1Au: + *quot = "I would like to die on Mars \u2013 just not on impact."; + *src = "Elon Reeve Musk"; + break; + case 0x1Bu: + *quot = "The web does not just connect computers; it connects people."; + *src = "Timothy John Berners-Lee"; + break; + case 0x1Cu: + *quot = "Can digital computers think?"; + *src = "Alan Mathison Turing"; + break; + } + return false; +} diff --git a/bowshock/source/bs/loop.c b/bowshock/source/bs/loop.c index b9506a1..acdf81a 100644 --- a/bowshock/source/bs/loop.c +++ b/bowshock/source/bs/loop.c @@ -5,63 +5,100 @@ #include <bow/sav.h> #include <GLFW/glfw3.h> +#include <flux/io.h> #include <inttypes.h> #include <math.h> +#include <stdlib.h> +#include <webp/encode.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 = { + zap_sz const imgsz = 0xFFFu * 0xFFFu * 0x3u; + zap_i8 * img = malloc(imgsz); + zap_fill(img,0x0u,imgsz); + bow_obj star = { .pos = { - .x = 0x0.0p0, - .y = 0x80.0p0, - .z = 0x0.0p0, + .x = 0x0p0, + .y = 0x0p0, + .z = 0x0p0, }, .typ = bow_objtyp_star, - .mass = 0x10000.0p0, + .mass = 0x1'0000'0000p0, }; - bow_obj star1 = { + bow_obj wrld = { .pos = { - .x = 0x0.0p0, - .y = -0x80.0p0, - .z = 0x0.0p0, + .x = 0x0p0, + .y = star.pos.y + 0x1'0000p0, + .z = 0x0p0, }, - .typ = bow_objtyp_star, - .mass = 0x1000.0p0, + .typ = bow_objtyp_wrld, + .mass = 0x1'0000p0, + }; + bow_obj sat = { + .pos = { + .x = 0x0p0, + .y = wrld.pos.y + 0x100u, + .z = 0x0p0, + }, + .typ = bow_objtyp_sat, + .mass = 0x1p0, }; - 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 - bool stop = false; - for (zap_i04 i = 0x0u;!stop;) { + wrld.vel.x = sqrt(bow_gravconst*star.mass/(wrld.pos.y - star.pos.y)); // orbital speed + sat.vel.x = wrld.vel.x + sqrt(bow_gravconst*wrld.mass/(sat.pos.y - wrld.pos.y)); // orbital speed + for (zap_i04 i = 0x0u;;) { if (bow_gotintr) { bow_log("got interrupt"); glfwSetWindowShouldClose(bow_gfxdat.win,GLFW_TRUE); } if (glfwWindowShouldClose(bow_gfxdat.win)) break; // Calculate gravitations: - bow_grav(&star0,&star1); - bow_grav(&star1,&star0); - bow_grav(&playdat.ship,&star0); - bow_grav(&playdat.ship,&star1); + bow_grav(&star,&wrld); + bow_grav(&star,&sat); + bow_grav(&wrld,&star); + bow_grav(&wrld,&sat); + bow_grav(&sat, &star); + bow_grav(&sat, &wrld); // 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); + bow_mv(&star); + bow_mv(&wrld); + bow_mv(&sat); + // Plot objects: + { + constexpr double frm = 0x4'0000p0; + zap_i04 const starposx = (zap_i04)((star.pos.x + frm / 0x2p0) / frm * 0xFFFp0); + zap_i04 const starposy = (zap_i04)((-star.pos.y + frm / 0x2p0) / frm * 0xFFFp0); + zap_i04 const wrldposx = (zap_i04)((wrld.pos.x + frm / 0x2p0) / frm * 0xFFFp0); + zap_i04 const wrldposy = (zap_i04)((-wrld.pos.y + frm / 0x2p0) / frm * 0xFFFp0); + zap_i04 const satposx = (zap_i04)((sat.pos.x + frm / 0x2p0) / frm * 0xFFFp0); + zap_i04 const satposy = (zap_i04)((-sat.pos.y + frm / 0x2p0) / frm * 0xFFFp0); + if ((starposx <= 0xFFFu) && (starposy <= 0xFFFu) && (wrldposx <= 0xFFFu) && (wrldposy <= 0xFFFu) && (satposx <= 0xFFFu) && (satposy <= 0xFFFu)) { + zap_sz const starpos = (starposy * 0xFFFu + starposx) * 0x3u; + zap_sz const wrldpos = (wrldposy * 0xFFFu + wrldposx) * 0x3u; + zap_sz const satpos = (satposy * 0xFFFu + satposx) * 0x3u; + if (img[starpos + 0x0u] <= 0xFEu) img[starpos + 0x0u] += 0x1u; + if (img[wrldpos + 0x1u] <= 0xFEu) img[wrldpos + 0x1u] += 0x1u; + if (img[satpos + 0x2u] <= 0xFEu) img[satpos + 0x2u] += 0x1u; + } + } // Check tick number: - if (i++ == 0x7Fu) break; + if (i++ == 0xFFFFFu) break; + } + { + zap_i8 * enc; + zap_sz const enclen = WebPEncodeLosslessRGB((void *)img,0xFFFu,0xFFFu,0xFFFu * 0x3u,&enc); + flux_fil * imgfil; + flux_err err = flux_mkfil(&imgfil,"img.webp",0644u); + if (err == flux_err_exist) { + flux_op(&imgfil,"img.webp",flux_md_wr,flux_disc); + } + flux_wr(imgfil,enc,enclen); + flux_cl(imgfil); + WebPFree(enc); } - fclose(log); + free(img); zap_cp(playdatptr,&playdat,sizeof (playdat)); return bow_stat_ok; } diff --git a/bowshock/source/info/shipmass.c b/bowshock/source/info/shipmass.c index b460556..d7c03f4 100644 --- a/bowshock/source/info/shipmass.c +++ b/bowshock/source/info/shipmass.c @@ -2,8 +2,6 @@ #include <bow/info.h> -#include <zap/bs.h> - double bow_shipmass([[maybe_unused]] bow_ship const id) { - return 0x100.0p0; + return 0x100p0; } diff --git a/bowshock/source/sav/cont.c b/bowshock/source/sav/cont.c index 3d201d9..93e475c 100644 --- a/bowshock/source/sav/cont.c +++ b/bowshock/source/sav/cont.c @@ -29,11 +29,12 @@ void bow_cont(char const * const pth,bow_playdat * const playdatptr) { goto new; } bow_playdat playdat = { - .sysid = dat.sysid, - .tm = dat.tm, - .ship.pos = dat.shippos, - .ship.rot = dat.shiprot, - .ship.vel = dat.shipvel, + .sysid = dat.sysid, + .tm = dat.tm, + .ship.shiptyp = dat.shiptyp, + .ship.pos = dat.shippos, + .ship.rot = dat.shiprot, + .ship.vel = dat.shipvel, }; zap_cp(playdat.nm,dat.cmdrnm,bow_cmdrnmlen); playdat.nm[bow_cmdrnmlen] = '\x0'; @@ -46,14 +47,14 @@ new: .tm = 0x1E187E00000u, // 256 julian years after the Unix Epoch. .ship = { .pos = { - .x = 0x0.0p0, - .y = 0x0.0p0, - .z = 0x0.0p0, + .x = 0x0p0, + .y = 0x0p0, + .z = 0x0p0, }, .vel = { - .x = 0x0.0p0, - .y = 0x0.0p0, - .z = 0x0.0p0, + .x = 0x0p0, + .y = 0x0p0, + .z = 0x0p0, }, .shiptyp = bow_ship_aq, }, diff --git a/bowshock/source/sav/sav.c b/bowshock/source/sav/sav.c index a59621d..53eec68 100644 --- a/bowshock/source/sav/sav.c +++ b/bowshock/source/sav/sav.c @@ -26,6 +26,7 @@ void bow_sav(char const * const pth,bow_playdat const * const playdatptr) { .fmtver = bow_savfmtver, .sysid = playdat.sysid, .tm = playdat.tm, + .shiptyp = playdat.ship.shiptyp, .shippos = playdat.ship.pos, .shiprot = playdat.ship.rot, .shipvel = playdat.ship.vel, |