summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--.gitignore1
-rw-r--r--CHANGELOG.txt7
-rw-r--r--bowshock/CMakeLists.txt65
-rw-r--r--bowshock/include/bow/bs.hxx124
-rw-r--r--bowshock/include/bow/ini.hxx60
-rw-r--r--bowshock/include/bow/init.hxx63
-rw-r--r--bowshock/include/bow/lgc.hxx20
-rw-r--r--bowshock/include/bow/run.hxx10
-rw-r--r--bowshock/include/bow/sav.hxx86
-rw-r--r--bowshock/source/bs/objtypstr.cxx (renamed from bowshock/source/bs/objTypStr.cxx)14
-rw-r--r--bowshock/source/bs/rnd.cxx4
-rw-r--r--bowshock/source/ini/bow/chkpar.cxx40
-rw-r--r--bowshock/source/ini/bow/cmpshd.cxx (renamed from bowshock/source/init/bow/compShd.cxx)29
-rw-r--r--bowshock/source/ini/bow/cmpshdprg.cxx34
-rw-r--r--bowshock/source/ini/bow/crd.cxx (renamed from bowshock/source/init/bow/cred.cxx)34
-rw-r--r--bowshock/source/ini/bow/exi.cxx29
-rw-r--r--bowshock/source/ini/bow/getquo.cxx157
-rw-r--r--bowshock/source/ini/bow/getsavpth.cxx36
-rw-r--r--bowshock/source/ini/bow/hlp.cxx (renamed from bowshock/source/init/bow/help.cxx)10
-rw-r--r--bowshock/source/ini/bow/ini.cxx51
-rw-r--r--bowshock/source/ini/bow/inigfx.cxx (renamed from bowshock/source/init/bow/initGfx.cxx)28
-rw-r--r--bowshock/source/ini/bow/inirnd.cxx (renamed from bowshock/source/init/bow/initRnd.cxx)4
-rw-r--r--bowshock/source/ini/bow/inisig.cxx25
-rw-r--r--bowshock/source/ini/bow/lop.cxx113
-rw-r--r--bowshock/source/ini/bow/polevt.cxx18
-rw-r--r--bowshock/source/ini/bow/priquo.cxx (renamed from bowshock/source/init/bow/priQuot.cxx)12
-rw-r--r--bowshock/source/ini/bow/srtseq.cxx46
-rw-r--r--bowshock/source/init/bow/bow.cxx20
-rw-r--r--bowshock/source/init/bow/chkParams.cxx38
-rw-r--r--bowshock/source/init/bow/compShdProg.cxx34
-rw-r--r--bowshock/source/init/bow/getQuot.cxx157
-rw-r--r--bowshock/source/init/bow/getSavPth.cxx36
-rw-r--r--bowshock/source/init/bow/init.cxx44
-rw-r--r--bowshock/source/init/bow/initSig.cxx25
-rw-r--r--bowshock/source/init/bow/intro.cxx45
-rw-r--r--bowshock/source/init/bow/loop.cxx113
-rw-r--r--bowshock/source/init/bow/pollEvts.cxx18
-rw-r--r--bowshock/source/init/bow/quit.cxx29
-rw-r--r--bowshock/source/lgc/grv.cxx (renamed from bowshock/source/lgc/grav.cxx)22
-rw-r--r--bowshock/source/lgc/mov.cxx (renamed from bowshock/source/lgc/mv.cxx)8
-rw-r--r--bowshock/source/lgc/shipMass.cxx10
-rw-r--r--bowshock/source/lgc/shpmas.cxx10
-rw-r--r--bowshock/source/lgc/sim.cxx6
-rw-r--r--bowshock/source/run/abr.cxx13
-rw-r--r--bowshock/source/run/abrt.cxx11
-rw-r--r--bowshock/source/run/addobj.cxx (renamed from bowshock/source/run/addObj.cxx)6
-rw-r--r--bowshock/source/run/freeObjs.cxx16
-rw-r--r--bowshock/source/run/gensys.cxx (renamed from bowshock/source/run/genSys.cxx)27
-rw-r--r--bowshock/source/run/remobj.cxx16
-rw-r--r--bowshock/source/sav/cnt.cxx84
-rw-r--r--bowshock/source/sav/cont.cxx84
-rw-r--r--bowshock/source/sav/decSav.cxx29
-rw-r--r--bowshock/source/sav/decsav.cxx29
-rw-r--r--bowshock/source/sav/encSav.cxx29
-rw-r--r--bowshock/source/sav/encsav.cxx29
-rw-r--r--bowshock/source/sav/genDat.cxx12
-rw-r--r--bowshock/source/sav/gendat.cxx12
-rw-r--r--bowshock/source/sav/newsav.cxx (renamed from bowshock/source/sav/newSav.cxx)18
-rw-r--r--bowshock/source/sav/sav.cxx50
59 files changed, 1100 insertions, 1100 deletions
diff --git a/.gitignore b/.gitignore
index b7109f3..70ac5d9 100644
--- a/.gitignore
+++ b/.gitignore
@@ -3,6 +3,7 @@
/build
/datdir
/glad
+/rust
*.tar
*.zip
*.zst
diff --git a/CHANGELOG.txt b/CHANGELOG.txt
index e3f30ee..93f4594 100644
--- a/CHANGELOG.txt
+++ b/CHANGELOG.txt
@@ -5,6 +5,13 @@
* Tag development versions;
* Use minimum-width types;
+* Update naming convention;
+* Use trailing return types;
+* Use C++20;
+* Don't use minimum-width types;
+* Update some typings;
+* Rename intro to start sequence;
+
# 0.B.2
* Fix data directory not being set correctly by CMake;
diff --git a/bowshock/CMakeLists.txt b/bowshock/CMakeLists.txt
index 3ceca37..f5e93fb 100644
--- a/bowshock/CMakeLists.txt
+++ b/bowshock/CMakeLists.txt
@@ -6,47 +6,46 @@ if("${BOW_DATA_DIRECTORY}" STREQUAL "")
message(FATAL_ERROR "Data directory (BOW_DATA_DIRECTORY) not specified")
endif()
-set(CMAKE_CXX_STANDARD 23)
+set(CMAKE_CXX_STANDARD 20)
add_executable(
bowshock
- "source/bs/objTypStr.cxx"
+ "source/bs/objtypstr.cxx"
"source/bs/rnd.cxx"
- "source/init/bow/bow.cxx"
- "source/init/bow/chkParams.cxx"
- "source/init/bow/compShd.cxx"
- "source/init/bow/compShdProg.cxx"
- "source/init/bow/cred.cxx"
- "source/init/bow/getQuot.cxx"
- "source/init/bow/getSavPth.cxx"
- "source/init/bow/help.cxx"
- "source/init/bow/init.cxx"
- "source/init/bow/initGfx.cxx"
- "source/init/bow/initRnd.cxx"
- "source/init/bow/initSig.cxx"
- "source/init/bow/intro.cxx"
- "source/init/bow/loop.cxx"
- "source/init/bow/pollEvts.cxx"
- "source/init/bow/priQuot.cxx"
- "source/init/bow/quit.cxx"
-
- "source/lgc/grav.cxx"
- "source/lgc/mv.cxx"
- "source/lgc/shipMass.cxx"
+ "source/ini/bow/chkpar.cxx"
+ "source/ini/bow/cmpshd.cxx"
+ "source/ini/bow/cmpshdprg.cxx"
+ "source/ini/bow/crd.cxx"
+ "source/ini/bow/exi.cxx"
+ "source/ini/bow/getquo.cxx"
+ "source/ini/bow/getsavpth.cxx"
+ "source/ini/bow/hlp.cxx"
+ "source/ini/bow/ini.cxx"
+ "source/ini/bow/inigfx.cxx"
+ "source/ini/bow/inirnd.cxx"
+ "source/ini/bow/inisig.cxx"
+ "source/ini/bow/lop.cxx"
+ "source/ini/bow/polevt.cxx"
+ "source/ini/bow/priquo.cxx"
+ "source/ini/bow/srtseq.cxx"
+
+ "source/lgc/grv.cxx"
+ "source/lgc/mov.cxx"
+ "source/lgc/shpmas.cxx"
"source/lgc/sim.cxx"
- "source/run/abrt.cxx"
- "source/run/addObj.cxx"
- "source/run/freeObjs.cxx"
- "source/run/genSys.cxx"
+ "source/run/abr.cxx"
+ "source/run/addobj.cxx"
+ "source/run/remobj.cxx"
+ "source/run/gensys.cxx"
- "source/sav/genDat.cxx"
- "source/sav/cont.cxx"
- "source/sav/decSav.cxx"
- "source/sav/encSav.cxx"
- "source/sav/newSav.cxx"
+ "source/sav/gendat.cxx"
+ "source/sav/cnt.cxx"
+ "source/sav/decsav.cxx"
+ "source/sav/encsav.cxx"
+ "source/sav/newsav.cxx"
"source/sav/sav.cxx"
)
@@ -78,7 +77,7 @@ target_compile_definitions(
_FORTIFY_SOURCE=$<IF:$<STREQUAL:"${CMAKE_BUILD_TYPE}","Debug">,0x0,0x2>
_POSIX_C_SOURCE=200112l
GLFW_INCLUDE_NONE
- bow_datDir="${BOW_DATA_DIRECTORY}"
+ bow_datdir="${BOW_DATA_DIRECTORY}"
bow_dbg=$<IF:$<STREQUAL:"${CMAKE_BUILD_TYPE}","Debug">,true,false>
)
diff --git a/bowshock/include/bow/bs.hxx b/bowshock/include/bow/bs.hxx
index c9faaf4..0b3d487 100644
--- a/bowshock/include/bow/bs.hxx
+++ b/bowshock/include/bow/bs.hxx
@@ -2,7 +2,7 @@
#pragma once
-#ifndef bow_datDir
+#ifndef bow_datdir
#error Data directory not specified!
#endif
@@ -11,46 +11,46 @@
static_assert(::zp::bytelen == 0x8u,"Bytes must contain exactly eight bits.");
-#define bow_logRaw(msg,...) fprintf(stderr,msg __VA_OPT__(,) __VA_ARGS__)
+#define bow_lograw(msg,...) fprintf(stderr,msg __VA_OPT__(,) __VA_ARGS__)
-#define bow_log(msg,...) bow_logRaw("\x1B[1m%s\x1B[0m: " msg "\n",__func__ __VA_OPT__(,) __VA_ARGS__)
+#define bow_log(msg,...) bow_lograw("\x1B[1m%s\x1B[0m: " msg "\n",__func__ __VA_OPT__(,) __VA_ARGS__)
-#define bow_logErr(msg,...) bow_log("\x1B[38;5;197m[ERROR]\x1B[0m " msg __VA_OPT__(,) __VA_ARGS__)
+#define bow_logerr(msg,...) bow_log("\x1B[38;5;197m[ERROR]\x1B[0m " msg __VA_OPT__(,) __VA_ARGS__)
#if bow_dbg
-#define bow_logDbg(msg,...) bow_log(msg __VA_OPT__ (,) __VA_ARGS__)
+#define bow_logdbg(msg,...) bow_log(msg __VA_OPT__ (,) __VA_ARGS__)
#else
-#define bow_logDbg(msg,...) ((void)0x0u)
+#define bow_logdbg(msg,...) ((void)0x0u)
#endif
-#define bow_logXyz(xyz) bow_logDbg("%s: %.03f %.03f %.03f",#xyz,(xyz).x,(xyz).y,(xyz).z)
+#define bow_logxyz(xyz) bow_logdbg("%s: %.03f %.03f %.03f",#xyz,(xyz).x,(xyz).y,(xyz).z)
-#define bow_setStrLen(ptr,len,str) ((void)(ptr = str,len = sizeof (str)-0x1u))
+#define bow_setstrlen(ptr,len,str) ((void)(ptr = str,len = sizeof (str)-0x1u))
namespace bow {
- constexpr ::zp::i04m verMaj = 0x0u;
- constexpr ::zp::i04m verMin = 0xCu;
- constexpr ::zp::i04m verPat = 0x0u;
+ constexpr ::zp::i04 vermaj = 0x0u;
+ constexpr ::zp::i04 vermin = 0xCu;
+ constexpr ::zp::i04 verpat = 0x0u;
- constexpr bool dbg = bow_dbg;
+ constexpr auto dbg = bow_dbg;
- constexpr ::zp::siz cmdrNmLen = 0xEu;
-
- enum struct stat : ::zp::i8m {
- ok = 0x0u,
- err = 0x1u,
+ constexpr ::zp::siz cmdnamlen = 0xEu;
+
+ enum struct cnd : ::zp::i8 {
+ err, // error
+ oky, // okay
};
- enum struct objTyp : ::zp::i8m {
- can, // canister
- pl, // player
- ship, // ship
- star, // star
- station, // station
- wrld, // world (planet/moon)
+ enum struct objtyp : ::zp::i8 {
+ can, // canister
+ ply, // player
+ shp, // ship
+ tar, // star
+ stn, // station
+ wrl, // world (planet/moon)
};
- enum struct wrld : ::zp::i8m {
+ enum struct wrl : ::zp::i8 {
amm, // ammonium world
gas, // gas giant
ice, // icy world
@@ -59,22 +59,22 @@ namespace bow {
wat, // water world
};
- enum struct ship : ::zp::i8m {
- aq, // aquila
- cas, // cassiopeia
- cent, // centaurus
- cov, // corvus
- cur, // cursor
- eri, // eridanus
- fal, // falco
- lyra, // lyra
- tau, // taurus
- ursa, // ursa
- vip, // vipera
- // Remember maxShipId in sav
+ enum struct shp : ::zp::i8 {
+ aqu, // aquila
+ cas, // cassiopeia
+ cen, // centaurus
+ cov, // corvus
+ cur, // cursor
+ eri, // eridanus
+ fal, // falco
+ lyr, // lyra
+ tau, // taurus
+ urs, // ursa
+ vip, // vipera
+ // Remember maxshpid in sav
};
- enum struct star : ::zp::i8m {
+ enum struct tar : ::zp::i8 {
a, // main sequence
b, // main sequence
c, // carbon
@@ -93,9 +93,9 @@ namespace bow {
z, // white hole
};
- enum struct station : ::zp::i8m {
- station_glob, // globus
- station_orb, // orbis
+ enum struct stn : ::zp::i8 {
+ stn_glb, // globus
+ stn_orb, // orbis
};
struct xyz {
@@ -105,34 +105,34 @@ namespace bow {
};
struct obj {
- ::bow::objTyp typ;
+ ::bow::objtyp typ;
union {
- ::bow::wrld wrldTyp;
- ::bow::ship shipTyp;
- ::bow::star starTyp;
- ::bow::station stationTyp;
+ ::bow::wrl wrldTyp;
+ ::bow::shp shptyp;
+ ::bow::tar tartyp;
+ ::bow::stn stnTyp;
};
- ::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
- ::bow::obj * next;
+ ::bow::xyz pos; // astronomical units
+ ::bow::xyz rot; // radians
+ ::bow::xyz posVel; // astronomical units per second
+ ::bow::xyz rotVel; // radians per second
+ double mas; // kilograms
+ ::bow::obj * nxt;
};
- struct objRoot {
+ struct objroot {
::bow::obj * objs;
};
- struct plDat {
- char nm[::bow::cmdrNmLen+0x1u];
- ::zp::i04m tm;
- ::zp::i04m sysId;
- ::bow::obj ship;
- float zoom;
+ struct pldat {
+ char nam[::bow::cmdnamlen+0x1u];
+ ::zp::i04 tim;
+ ::zp::i04 sysidt;
+ ::bow::obj shp;
+ float zom;
};
- char const * objTypStr(::bow::objTyp typ) noexcept;
+ auto objtypstr(::bow::objtyp typ) noexcept -> char const *;
- ::zp::i04 rnd() noexcept;
+ auto rnd() noexcept -> ::zp::i04;
}
diff --git a/bowshock/include/bow/ini.hxx b/bowshock/include/bow/ini.hxx
new file mode 100644
index 0000000..f86eb80
--- /dev/null
+++ b/bowshock/include/bow/ini.hxx
@@ -0,0 +1,60 @@
+// Copyright 2022-2023 Gabriel Jensen.
+
+#pragma once
+
+#include <bow/run.hxx>
+
+#include <GLFW/glfw3.h>
+#include <csignal>
+#include <glad/glad.h>
+
+namespace bow {
+ constexpr char const shdfilext[] = "glsl";
+
+ struct gfxdat {
+ ::GLFWwindow * win;
+ ::GLuint shdprog;
+ };
+
+ struct trmopt {
+ char const * savPth;
+ bool hassavpth:0x1u;
+ bool newsav:0x1u;
+ bool skip:0x1u;
+ };
+
+ class bow {
+ public:
+ [[noreturn]] auto ini(int argc,char const * const * argv) noexcept -> void;
+
+ private:
+ ::bow::pldat pldat;
+ ::bow::gfxdat gfxdat;
+
+ auto getsavpth() noexcept -> char const *;
+ auto getquo( char const * * quo,char const * * src,::zp::i8 id) noexcept -> void;
+
+ auto priquo() noexcept -> void;
+
+ [[noreturn]] auto crd() noexcept -> void;
+ [[noreturn]] auto hlp(char const * progNm) noexcept -> void;
+
+ auto chkpar(trmopt & opt,int argc,char const * const * argv) noexcept -> void;
+
+ auto cmpshd( ::GLuint & shd, char const * nam,GLenum typ) -> void;
+ auto compshdprog(::GLuint & shdprog,char const * nam) noexcept -> void;
+
+ auto inigfx() noexcept -> void;
+ auto inirnd() noexcept -> void;
+ auto inisig() noexcept -> void;
+
+ auto polevt() noexcept -> bool;
+
+ auto srtseq() noexcept -> bool;
+ auto lop() noexcept -> void;
+
+ [[noreturn]] auto exi(::bow::cnd stat) noexcept -> void;
+ };
+
+ extern ::std::sig_atomic_t volatile gotint;
+}
diff --git a/bowshock/include/bow/init.hxx b/bowshock/include/bow/init.hxx
deleted file mode 100644
index 60a8d50..0000000
--- a/bowshock/include/bow/init.hxx
+++ /dev/null
@@ -1,63 +0,0 @@
-// Copyright 2022-2023 Gabriel Jensen.
-
-#pragma once
-
-#include <bow/run.hxx>
-
-#include <GLFW/glfw3.h>
-#include <csignal>
-#include <glad/glad.h>
-
-namespace bow {
- constexpr char const shdFilExt[] = "glsl";
-
- struct gfxDat {
- ::GLFWwindow * win;
- GLuint shdProg;
- };
-
- struct termOpts {
- char const * savPth;
- bool hasSavPth:0x1u;
- bool newSav:0x1u;
- bool skip:0x1u;
- };
-
- class bow {
- public:
- bow( int argc,char const * const * argv) noexcept;
- [[noreturn]] ~bow() noexcept;
-
- private:
- ::bow::plDat plDat;
- ::bow::gfxDat gfxDat;
-
- char const * getSavPth() noexcept;
- void getQuot( char const * * quot,char const * * src,::zp::i8m id) noexcept;
-
- void priQuot() noexcept;
-
- [[noreturn]] void cred() noexcept;
- [[noreturn]] void help(char const * progNm) noexcept;
-
- void chkParams(termOpts & opts,int argc,char const * const * argv) noexcept;
-
- void compShd( GLuint & shd, char const * nm,GLenum typ);
- void compShdProg(GLuint & shdProg,char const * nm) noexcept;
-
- void initGfx() noexcept;
- void initRnd() noexcept;
- void initSig() noexcept;
-
- void init(int argc,char const * const * argv) noexcept;
-
- bool pollEvts() noexcept;
-
- bool intro() noexcept;
- void loop() noexcept;
-
- [[noreturn]] void quit(::bow::stat stat) noexcept;
- };
-
- extern ::std::sig_atomic_t volatile gotIntr;
-}
diff --git a/bowshock/include/bow/lgc.hxx b/bowshock/include/bow/lgc.hxx
index 4db1a4e..b3ff4e3 100644
--- a/bowshock/include/bow/lgc.hxx
+++ b/bowshock/include/bow/lgc.hxx
@@ -5,19 +5,19 @@
#include <bow/bs.hxx>
namespace bow {
- constexpr double distMod = 0x1.16A5D2D360000000p037; // distance modifier (1 astronomical unit)
- constexpr double massMod = 0x1.91930A5E75F0C192p100; // mass modifier (1 solar mass)
- constexpr double tmMod = 0x1.0000000000000000p012; // time modifier (1 second)
+ constexpr double dstmod = 0x1.16A5D2D360000000p037; // distance modifier (1 astronomical unit)
+ constexpr double masmod = 0x1.91930A5E75F0C192p100; // mass modifier (1 solar mas)
+ constexpr double timmod = 0x1.0000000000000000p012; // time modifier (1 second)
- constexpr double gravConstFac = (::bow::massMod*(::bow::tmMod*::bow::tmMod))/((::bow::distMod*::bow::distMod*::bow::distMod)); // inverse
+ constexpr double grvfac = (::bow::masmod*(::bow::timmod*::bow::timmod))/((::bow::dstmod*::bow::dstmod*::bow::dstmod)); // inverse
- constexpr double gravConst = 0x1.258688101B4BB16Dp-34*::bow::gravConstFac; // gravitational constant (s^2*m*t^2)
+ constexpr double grvval = 0x1.258688101B4BB16Dp-34*::bow::grvfac; // gravitational constant (s^2*m*t^2)
- zp_useq double shipMass(::bow::ship id) noexcept;
+ [[nodiscard]] auto shpmas(::bow::shp id) noexcept -> double;
- void grav(::bow::objRoot & sys) noexcept;
- void grav(::bow::objRoot & objs,::bow::objRoot const & sys) noexcept;
- void mv( ::bow::objRoot & root) noexcept;
+ auto grv(::bow::objroot & sys) noexcept -> void;
+ auto grv(::bow::objroot & objs,::bow::objroot const & sys) noexcept -> void;
+ auto mov(::bow::objroot & root) noexcept -> void;
- void sim(::bow::objRoot & sys,::zp::i04 dur) noexcept;
+ auto sim(::bow::objroot & sys,::zp::i04 dur) noexcept -> void;
}
diff --git a/bowshock/include/bow/run.hxx b/bowshock/include/bow/run.hxx
index 63311cb..ecfe31d 100644
--- a/bowshock/include/bow/run.hxx
+++ b/bowshock/include/bow/run.hxx
@@ -4,11 +4,13 @@
#include <bow/bs.hxx>
+#include <source_location>
+
namespace bow {
- [[noreturn]] void abrt() noexcept;
+ [[noreturn]] auto abr(::std::source_location srcloc = ::std::source_location::current()) noexcept -> void;
- void addObj( ::bow::objRoot & root,::bow::obj const & obj);
- void freeObjs(::bow::objRoot const & root) noexcept;
+ auto addobj(::bow::objroot & root,::bow::obj const & obj) -> void;
+ auto remobj(::bow::objroot const & root) noexcept -> void;
- void genSys(::bow::objRoot & sys,::zp::i04 id,::zp::i04 tm);
+ auto gensys(::bow::objroot & sys,::zp::i04 id,::zp::i04 tim) -> void;
}
diff --git a/bowshock/include/bow/sav.hxx b/bowshock/include/bow/sav.hxx
index 6a3d130..c2d8912 100644
--- a/bowshock/include/bow/sav.hxx
+++ b/bowshock/include/bow/sav.hxx
@@ -5,63 +5,63 @@
#include <bow/bs.hxx>
namespace bow {
- constexpr ::zp::i04 savVer = 0x6u;
+ constexpr ::zp::i04 savver = 0x6u;
- constexpr ::zp::siz savLen = 0x79u+::bow::cmdrNmLen;
+ constexpr ::zp::siz savlen = 0x79u+::bow::cmdnamlen;
- constexpr ::zp::i8 maxShipId = static_cast<::zp::i8>(::bow::ship::vip);
+ constexpr ::zp::i8 maxshpid = static_cast<::zp::i8>(::bow::shp::vip);
/*
Save format:
offset: id: size [bytes]: format:
- 0x00 fmtver 8 unsigned
- 0x08 cmdrnm E UTF-8
- 0x16 tm 8 unsigned
- 0x1E sysid 8 unsigned
- 0x1F shiptyp 1 unsigned
- 0x27 shipposx 8 binary64
- 0x2F shipposy 8 binary64
- 0x37 shipposz 8 binary64
- 0x3F shiprotx 8 binary64
- 0x47 shiproty 8 binary64
- 0x4F shiprotz 8 binary64
- 0x57 shipposvelx 8 binary64
- 0x5F shipposvely 8 binary64
- 0x67 shipposvelz 8 binary64
- 0x6F shiprotvelx 8 binary64
- 0x77 shiprotvely 8 binary64
- 0x7F shiprotvelz 8 binary64
+ 0x00 fmtver 8 unsigned
+ 0x08 cmdnam E UTF-8
+ 0x16 tim 8 unsigned
+ 0x1E sysidt 8 unsigned
+ 0x1F shptyp 1 unsigned
+ 0x27 shpposx 8 binary64
+ 0x2F shpposy 8 binary64
+ 0x37 shpposz 8 binary64
+ 0x3F shprotx 8 binary64
+ 0x47 shproty 8 binary64
+ 0x4F shprotz 8 binary64
+ 0x57 shpposvelx 8 binary64
+ 0x5F shpposvely 8 binary64
+ 0x67 shpposvelz 8 binary64
+ 0x6F shprotvelx 8 binary64
+ 0x77 shprotvely 8 binary64
+ 0x7F shprotvelz 8 binary64
*/
- struct savDat {
+ struct savdat {
::zp::i04 fmtVer;
- char cmdrNm[::bow::cmdrNmLen];
- ::zp::i04 tm;
- ::zp::i04 sysId;
- ::zp::i8 shipTyp;
- double shipPosX;
- double shipPosY;
- double shipPosZ;
- double shipRotX;
- double shipRotY;
- double shipRotZ;
- double shipPosVelX;
- double shipPosVelY;
- double shipPosVelZ;
- double shipRotVelX;
- double shipRotVelY;
- double shipRotVelZ;
+ char8_t cmdnam[::bow::cmdnamlen];
+ ::zp::i04 tim;
+ ::zp::i04 sysidt;
+ ::zp::i8 shptyp;
+ ::zp::f04 shpposx;
+ ::zp::f04 shpposy;
+ ::zp::f04 shpposz;
+ ::zp::f04 shprotx;
+ ::zp::f04 shproty;
+ ::zp::f04 shprotz;
+ ::zp::f04 shpposvelx;
+ ::zp::f04 shpposvely;
+ ::zp::f04 shpposvelz;
+ ::zp::f04 shprotvelx;
+ ::zp::f04 shprotvely;
+ ::zp::f04 shprotvelz;
};
- void decSav(::bow::savDat & buf,::zp::i8 const * dat) noexcept;
- void encSav(::zp::i8 * buf,::bow::savDat const & dat) noexcept;
+ auto decsav(::bow::savdat & buf,::zp::i8 const * dat) noexcept -> void;
+ auto encsav(::zp::i8 * buf,::bow::savdat const & dat) noexcept -> void;
- void newSav(::bow::plDat & dat) noexcept;
+ auto newsav(::bow::pldat & dat) noexcept -> void;
- void cont( ::bow::plDat & dat,char const * fil) noexcept;
- void genDat(::bow::plDat & dat) noexcept;
+ auto cnt( ::bow::pldat & dat,char const * fil) noexcept -> void;
+ auto gendat(::bow::pldat & dat) noexcept -> void;
- void sav(char const * fil,::bow::plDat const & dat) noexcept;
+ auto sav(char const * fil,::bow::pldat const & dat) noexcept -> void;
}
diff --git a/bowshock/source/bs/objTypStr.cxx b/bowshock/source/bs/objtypstr.cxx
index d70c9f5..db4ccf0 100644
--- a/bowshock/source/bs/objTypStr.cxx
+++ b/bowshock/source/bs/objtypstr.cxx
@@ -2,26 +2,26 @@
#include <bow/lgc.hxx>
-char const * ::bow::objTypStr(::bow::objTyp const typ) noexcept {
+auto ::bow::objtypstr(::bow::objtyp const typ) noexcept -> char const * {
char const * str;
switch (typ) {
- case ::bow::objTyp::can:
+ case ::bow::objtyp::can:
str = "canister";
break;
- case ::bow::objTyp::pl:
+ case ::bow::objtyp::ply:
str = "player";
break;
- case ::bow::objTyp::ship:
+ case ::bow::objtyp::shp:
str = "ship";
break;
- case ::bow::objTyp::star:
+ case ::bow::objtyp::tar:
str = "star";
break;
- case ::bow::objTyp::station:
+ case ::bow::objtyp::stn:
str = "station";
break;
- case ::bow::objTyp::wrld:
+ case ::bow::objtyp::wrl:
str = "world";
break;
}
diff --git a/bowshock/source/bs/rnd.cxx b/bowshock/source/bs/rnd.cxx
index 4ee7e4b..c345037 100644
--- a/bowshock/source/bs/rnd.cxx
+++ b/bowshock/source/bs/rnd.cxx
@@ -8,10 +8,10 @@ static_assert(sizeof (int) == sizeof (::zp::i02));
static_assert(RAND_MAX == ::zp::maxval<int>::val);
-unsigned long ::bow::rnd() noexcept {
+auto ::bow::rnd() noexcept -> ::zp::i04 {
::zp::i02 const rnd0 = (::zp::i02)::std::rand();
::zp::i02 const rnd1 = (::zp::i02)::std::rand();
- ::zp::i04 const rnd = (::zp::i04)rnd0 | (::zp::i04)rnd1 >> 0x4u;
+ ::zp::i04 const rnd = static_cast<::zp::i04>(rnd0) | static_cast<::zp::i04>(rnd1) >> 0x4u;
return rnd;
}
diff --git a/bowshock/source/ini/bow/chkpar.cxx b/bowshock/source/ini/bow/chkpar.cxx
new file mode 100644
index 0000000..6d50e81
--- /dev/null
+++ b/bowshock/source/ini/bow/chkpar.cxx
@@ -0,0 +1,40 @@
+// Copyright 2022-2023 Gabriel Jensen.
+
+#include <bow/ini.hxx>
+
+#include <zp/mem>
+#include <zp/str>
+
+auto ::bow::bow::chkpar(::bow::trmopt & opt,int const argc,char const * const * argv) noexcept -> void {
+ char const * const progNm = *argv;
+
+ opt = ::bow::trmopt {
+ .hassavpth = false,
+ .newsav = false,
+ .skip = false,
+ };
+
+ if (argc >= 0x2) [[unlikely]] {
+ char const * const * const stop = (argv++)+(::zp::siz)argc;
+
+ for (;argv != stop;++argv) {
+ char const * par = *argv;
+
+ if (par[0x0u] == '-' && par[0x1u] == '-') {
+ par += 0x2u;
+
+ if (::zp::strequ(par,"credits")) crd();
+ else if (::zp::strequ(par,"help")) hlp(progNm);
+ else if (::zp::strequ(par,"new")) opt.newsav = true;
+ else if (::zp::strequ(par,"skip")) opt.skip = true;
+ else bow_logerr("invalid pareter \"%s\"",par);
+
+ continue;
+ }
+
+ // Else: Interpret it as a save path.
+ opt.savPth = par;
+ opt.hassavpth = true;
+ }
+ }
+}
diff --git a/bowshock/source/init/bow/compShd.cxx b/bowshock/source/ini/bow/cmpshd.cxx
index e1d418c..572ae4c 100644
--- a/bowshock/source/init/bow/compShd.cxx
+++ b/bowshock/source/ini/bow/cmpshd.cxx
@@ -1,6 +1,6 @@
// Copyright 2022-2023 Gabriel Jensen.
-#include <bow/init.hxx>
+#include <bow/ini.hxx>
#include <cstdlib>
#include <ly/io>
@@ -10,45 +10,46 @@
#include <zp/mem>
#include <zp/str>
-void ::bow::bow::compShd(GLuint & shd,char const * const nm,GLenum const typ) {
+auto ::bow::bow::cmpshd(::GLuint & shd,char const * const nam,GLenum const typ) -> void {
char const * typStr;
char const * typExt;
::zp::siz typExtLen;
+
switch (typ) {
default:
- bow_logErr("bad shader type %lX",static_cast<unsigned long>(typ));
- ::bow::abrt();
+ bow_logerr("bad shader type %lX",static_cast<unsigned long>(typ));
+ ::bow::abr();
case GL_FRAGMENT_SHADER:
- bow_setStrLen(typExt,typExtLen,"frag");
+ bow_setstrlen(typExt,typExtLen,"frag");
typStr = "fragment";
break;
case GL_VERTEX_SHADER:
- bow_setStrLen(typExt,typExtLen,"vert");
+ bow_setstrlen(typExt,typExtLen,"vert");
typStr = "vertex";
break;
}
char const * dir;
::zp::siz dirLen;
- bow_setStrLen(dir,dirLen,bow_datDir "/shaders");
+ bow_setstrlen(dir,dirLen,bow_datdir "/shaders");
- ::zp::siz const nmLen = ::zp::strlen(nm);
- ::zp::siz const pthLen = dirLen + 0x1u + nmLen + 0x1u + typExtLen + 0x1u + sizeof (::bow::shdFilExt);
+ ::zp::siz const nmLen = ::zp::strlen(nam);
+ ::zp::siz const pthlen = dirLen + 0x1u + nmLen + 0x1u + typExtLen + 0x1u + sizeof (::bow::shdfilext);
- char * pth = new char[pthLen + 0x1u];
+ char * pth = new char[pthlen + 0x1u];
pth = ::zp::cpy(pth,dir,dirLen).dst;
*pth++ = '/';
- pth = ::zp::cpy(pth,nm,nmLen).dst;
+ pth = ::zp::cpy(pth,nam,nmLen).dst;
*pth++ = '.';
pth = ::zp::cpy(pth,typExt,typExtLen).dst;
*pth++ = '.';
- pth = ::zp::cpy(pth,::bow::shdFilExt,sizeof (::bow::shdFilExt)).dst;
+ pth = ::zp::cpy(pth,::bow::shdfilext,sizeof (::bow::shdfilext)).dst;
*pth = '\x00';
- pth -= pthLen;
+ pth -= pthlen;
- bow_logDbg("compiling %s shader at \"%s\"",typStr,pth);
+ bow_logdbg("compiling %s shader at \"%s\"",typStr,pth);
::ly::fil fil;
::ly::err err = fil.opn(pth,::ly::mod::red,::ly::kep);
diff --git a/bowshock/source/ini/bow/cmpshdprg.cxx b/bowshock/source/ini/bow/cmpshdprg.cxx
new file mode 100644
index 0000000..9869c35
--- /dev/null
+++ b/bowshock/source/ini/bow/cmpshdprg.cxx
@@ -0,0 +1,34 @@
+// Copyright 2022-2023 Gabriel Jensen.
+
+#include <bow/ini.hxx>
+
+#include <glad/glad.h>
+#include <stdexcept>
+
+auto ::bow::bow::compshdprog(::GLuint & shdprog,char const * const nam) noexcept -> void {
+ bow_log("compiling shader program \"%s\"",nam);
+
+ ::GLuint vtxshd;
+ ::GLuint frgshd;
+
+ try {
+ cmpshd(vtxshd,nam,GL_VERTEX_SHADER);
+ cmpshd(frgshd,nam,GL_FRAGMENT_SHADER);
+ }
+ catch (::std::runtime_error const & e) {
+ bow_logerr("%s",e.what());
+ ::bow::abr();
+ }
+ catch (::std::bad_alloc const & e) {
+ bow_logerr("unable to allocate memory for shader data");
+ ::bow::abr();
+ }
+
+ shdprog = glCreateProgram();
+ glAttachShader(shdprog,vtxshd);
+ glAttachShader(shdprog,frgshd);
+ glLinkProgram(shdprog);
+
+ glDeleteShader(vtxshd);
+ glDeleteShader(frgshd);
+}
diff --git a/bowshock/source/init/bow/cred.cxx b/bowshock/source/ini/bow/crd.cxx
index fe69aae..f76b4e7 100644
--- a/bowshock/source/init/bow/cred.cxx
+++ b/bowshock/source/ini/bow/crd.cxx
@@ -1,14 +1,14 @@
// Copyright 2022-2023 Gabriel Jensen.
-#include <bow/init.hxx>
+#include <bow/ini.hxx>
#include <ly/io>
#include <ly/fs>
#include <cstdlib>
#include <stdexcept>
-void ::bow::bow::cred() noexcept {
- char const * const pth = bow_datDir "/CREDITS.txt";
+auto ::bow::bow::crd() noexcept -> void {
+ char const * const pth = bow_datdir "/CREDITS.txt";
::zp::siz const filsiz = [&pth]() {
::ly::pthinf pthinf;
@@ -21,42 +21,42 @@ void ::bow::bow::cred() noexcept {
::ly::err err = fil.opn(pth,::ly::mod::red,::ly::kep);
if (err != ::ly::err::ok) [[unlikely]] {
- bow_logErr("unable to open credits file");
+ bow_logerr("unable to open credits file");
::std::exit(EXIT_FAILURE);
}
- char * cred;
+ char * crd;
- try {cred = new char[filsiz + 0x3u];}
+ try {crd = new char[filsiz + 0x3u];}
catch (::std::bad_alloc const & e) {
- bow_logErr("unable to allocate memory");
+ bow_logerr("unable to allocate memory");
::std::exit(EXIT_FAILURE);
}
- char * const credstart = cred;
+ char * const credsrt = crd;
- *cred++ = '\n';
+ *crd++ = '\n';
- fil.red(cred,filsiz);
+ fil.red(crd,filsiz);
fil.cls();
- cred += filsiz;
+ crd += filsiz;
- *cred++ = '\n';
- *cred++ = '\x00';
+ *crd++ = '\n';
+ *crd++ = '\x00';
- cred = credstart;
+ crd = credsrt;
- ::ly::dflout.wrt(cred,filsiz + 0x3u);
+ ::ly::dflout.wrt(crd,filsiz + 0x3u);
if (err != ::ly::err::ok) {
- bow_logErr("unable to write to defout");
+ bow_logerr("unable to write to defout");
::std::exit(EXIT_FAILURE);
}
- delete[] cred;
+ delete[] crd;
::std::exit(EXIT_SUCCESS);
}
diff --git a/bowshock/source/ini/bow/exi.cxx b/bowshock/source/ini/bow/exi.cxx
new file mode 100644
index 0000000..76477b0
--- /dev/null
+++ b/bowshock/source/ini/bow/exi.cxx
@@ -0,0 +1,29 @@
+// Copyright 2022-2023 Gabriel Jensen.
+
+#include <bow/ini.hxx>
+
+#include <cstdlib>
+#include <GLFW/glfw3.h>
+
+auto ::bow::bow::exi(::bow::cnd const cnd) noexcept -> void {
+ bow_log("quitting");
+
+ glDeleteProgram(gfxdat.shdprog);
+
+ ::glfwDestroyWindow(gfxdat.win);
+ ::glfwTerminate();
+
+ int cod;
+ switch (cnd) {
+ case ::bow::cnd::err:
+ cod = EXIT_FAILURE;
+ break;
+ case ::bow::cnd::oky:
+ cod = EXIT_SUCCESS;
+ break;
+ }
+
+ bow_log("goodbye");
+ bow_log("exiting with code %i",cod);
+ ::std::exit(cod);
+}
diff --git a/bowshock/source/ini/bow/getquo.cxx b/bowshock/source/ini/bow/getquo.cxx
new file mode 100644
index 0000000..f1f80cb
--- /dev/null
+++ b/bowshock/source/ini/bow/getquo.cxx
@@ -0,0 +1,157 @@
+// Copyright 2022-2023 Gabriel Jensen.
+
+#include <bow/ini.hxx>
+
+#include <cinttypes>
+
+auto ::bow::bow::getquo(char const * * const quo,char const * * src,::zp::i8 const id) noexcept -> void {
+ switch (id) {
+ default:
+ bow_logerr("invalid quote identifier (%" PRIX8 ")",id);
+ [[fallthrough]];
+ case 0x0u:
+ *quo = "You gotta be heaven to see heaven.";
+ *src = "Jim Carrey";
+ break;
+ case 0x1u:
+ *quo = "Though it's the end of the world, don't blame yourself, now.";
+ *src = "Porter Robinson";
+ break;
+ case 0x2u:
+ *quo = "The future will be better tomorrow.";
+ *src = "Dan Quayle";
+ break;
+ case 0x3u:
+ *quo = "Sir, an equation has no meaning for me unless it expresses a thought of god.";
+ *src = "Srinivasa Ramanujan Aiyangar";
+ break;
+ case 0x4u:
+ *quo = "Amīcus Platō amīcus Aristotelēs magis amīca vēritās.";
+ *src = "Isaac Newton";
+ break;
+ case 0x5u:
+ *quo = "I have studied these things \u2013 you have not.";
+ *src = "Isaac Newton";
+ break;
+ case 0x6u:
+ *quo = "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:
+ *quo = "In mathematics, you don't understand things, you just get used to them.";
+ *src = "John von Neumann";
+ break;
+ case 0x8u:
+ *quo = "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:
+ *quo = "The real question is not whether machines think, but whether men do.";
+ *src = "Burrhus Frederic Skinner";
+ break;
+ case 0xAu:
+ *quo = "Those who are not shocked when they first come across quantum theory cannot possibly have understood it.";
+ *src = "Niels Henrik David Bohr";
+ break;
+ case 0xBu:
+ *quo = "Every sentence I utter must be understood not as an affirmation, but as a question.";
+ *src = "Niels Henrik David Bohr";
+ break;
+ case 0xCu:
+ *quo = "We will now discuss in a little more detail the struggle for existence.";
+ *src = "Charles Robert Darwin";
+ break;
+ case 0xDu:
+ *quo = "Nam et ipsa scientia potestas est.";
+ *src = "Francis Bacon";
+ break;
+ case 0xEu:
+ *quo = "We don't know a millionth of one percent about anything.";
+ *src = "Thomas Alva Edison";
+ break;
+ case 0xFu:
+ *quo = "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:
+ *quo = "Equipped with his five senses, man explores the universe around him and calls the adventure Science.";
+ *src = "Edwin Powell Hubble";
+ break;
+ case 0x11u:
+ *quo = "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:
+ *quo = "I'm always right. This time I'm just more right than usual.";
+ *src = "Linus Benedict Torvalds";
+ break;
+ case 0x13u:
+ *quo = "I'm an instant tar. Just add water and stir.";
+ *src = "David Robert Jones";
+ break;
+ case 0x14u:
+ *quo = "Don't waste the Earth \u2013 it is our jewel!";
+ *src = "Buzz Eugene Aldrin";
+ break;
+ case 0x15u:
+ *quo = "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:
+ *quo = "A hacker is someone who enjoys playful cleverness \u2013 not necessarily with computers.";
+ *src = "Richard Matthew Stallman";
+ break;
+ case 0x17u:
+ *quo = "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:
+ *quo = "I'm a blacktar.";
+ *src = "David Robert Jones";
+ break;
+ case 0x19u:
+ *quo = "Sooner or later, we must expand life beyond our little blue mud ball \u2013 or go extinct.";
+ *src = "Elon Reeve Musk";
+ break;
+ case 0x1Au:
+ *quo = "I would like to die on Mars \u2013 just not on impact.";
+ *src = "Elon Reeve Musk";
+ break;
+ case 0x1Bu:
+ *quo = "The web does not just connect computers; it connects people.";
+ *src = "Timothy John Berners-Lee";
+ break;
+ case 0x1Cu:
+ *quo = "Can digital computers think?";
+ *src = "Alan Mathison Turing";
+ break;
+ case 0x1Du:
+ *quo = "That's one small step for a man, one giant leap for mankind.";
+ *src = "Neil Alden Armstrong";
+ break;
+ case 0x1Eu:
+ *quo = "If you think it's simple, then you have misunderstood the problem.";
+ *src = "Bjarne Stroustrup";
+ break;
+ case 0x1Fu:
+ *quo = "Controlling complexity is the essence of computer programming.";
+ *src = "Brian Wilson Kerningham";
+ break;
+ case 0x20u:
+ *quo = "I have always wished for my computer to be as easy to use as my telephone.\nMy wish has come true because I can no longer figure out how to use my telephone.";
+ *src = "Bjarne Stroustrup";
+ break;
+ case 0x21u:
+ *quo = "There is no mathematical sibstitute for philosophy.";
+ *src = "Saul Aaron Kripke";
+ break;
+ case 0x22u:
+ *quo = "Biology is engineering.";
+ *src = "Daniel Clement Dennett III";
+ break;
+ case 0x23u:
+ *quo = "The universe is under no obligation to make sense to you.";
+ *src = "Neil deGrasse Tyson";
+ break;
+ }
+}
diff --git a/bowshock/source/ini/bow/getsavpth.cxx b/bowshock/source/ini/bow/getsavpth.cxx
new file mode 100644
index 0000000..a3c0c22
--- /dev/null
+++ b/bowshock/source/ini/bow/getsavpth.cxx
@@ -0,0 +1,36 @@
+// Copyright 2022-2023 Gabriel Jensen.
+
+#include <bow/ini.hxx>
+
+#include <cstdlib>
+#include <ly/fs>
+#include <zp/mem>
+#include <zp/str>
+
+auto ::bow::bow::getsavpth() noexcept -> char const * {
+ char const * homdir = ::ly::homdir();
+ char const * filnam;
+ ::zp::siz homdirlen;
+ ::zp::siz filnamlen;
+
+ if (homdir == nullptr) [[unlikely]] {
+ bow_log("unable to get home directory, using current directory");
+ bow_setstrlen(homdir,homdirlen,"./");
+ }
+ else homdirlen = ::zp::strlen(homdir);
+
+ bow_setstrlen(filnam,filnamlen,".save.bowshock");
+
+ ::zp::siz pthlen = homdirlen+filnamlen+0x1u;
+
+ char * pth = new char[pthlen + 0x1u];
+
+ pth = ::zp::memcpy(pth,homdir,homdirlen).dst;
+ *pth++ = '/';
+ pth = ::zp::memcpy(pth,filnam,filnamlen).dst;
+ *pth = '\x00';
+
+ pth -= pthlen;
+
+ return pth;
+}
diff --git a/bowshock/source/init/bow/help.cxx b/bowshock/source/ini/bow/hlp.cxx
index f216ed3..ec75280 100644
--- a/bowshock/source/init/bow/help.cxx
+++ b/bowshock/source/ini/bow/hlp.cxx
@@ -1,12 +1,12 @@
// Copyright 2022-2023 Gabriel Jensen.
-#include <bow/init.hxx>
+#include <bow/ini.hxx>
#include <cinttypes>
#include <cstdlib>
-void ::bow::bow::help(char const * const progNm) noexcept {
- bow_logRaw(
+auto ::bow::bow::hlp(char const * const progNm) noexcept -> void {
+ bow_lograw(
"\n"
"\x1B[1mBowshock\x1B[0m %" PRIX64 ".%" PRIX64 ".%" PRIX64 "\n"
"Copyright 2022-2023 Gabriel Jensen.\n"
@@ -16,10 +16,10 @@ void ::bow::bow::help(char const * const progNm) noexcept {
"Options:\n"
" --credits Print the game \x1B[1mcredits\x1B[0m\n"
" --help Print \x1B[1mhelp\x1B[0m screen\n"
- " --new Start a \x1B[1mnew\x1B[0m save file\n"
+ " --new srt a \x1B[1mnew\x1B[0m save file\n"
" --skip \x1B[1mSkip\x1B[0m the intro\n"
"\n",
- ::bow::verMaj,::bow::verMin,::bow::verPat,progNm);
+ ::bow::vermaj,::bow::vermin,::bow::verpat,progNm);
::std::exit(EXIT_SUCCESS);
}
diff --git a/bowshock/source/ini/bow/ini.cxx b/bowshock/source/ini/bow/ini.cxx
new file mode 100644
index 0000000..a13fd1f
--- /dev/null
+++ b/bowshock/source/ini/bow/ini.cxx
@@ -0,0 +1,51 @@
+// Copyright 2022-2023 Gabriel Jensen.
+
+#include <bow/ini.hxx>
+#include <bow/lgc.hxx>
+#include <bow/run.hxx>
+#include <bow/sav.hxx>
+
+#include <cinttypes>
+
+auto ::bow::bow::ini(int const argc,char const * const * const argv) noexcept -> void {
+ ::bow::trmopt opt;
+ chkpar(opt,argc,argv);
+
+ priquo();
+
+ bow_lograw("\x1B[0m\x1B[1mBowshock\x1B[0m %" PRIX64 ".%" PRIX64 ".%" PRIX64 " \u2013 Copyright 2022\u20102023 \x1B[1mGabriel Jensen\x1B[0m.\n\n",::bow::vermaj,::bow::vermin,::bow::verpat);
+
+ bow_log("initialising");
+
+ bow_logdbg("debug mode is enabled");
+ bow_logdbg("data directory at \"" bow_datdir "\"");
+ bow_logdbg("angle unit: %.3f radians",0x1p0f);
+ bow_logdbg("distance unit: %.3f metres",::bow::dstmod);
+ bow_logdbg("mass unit: %.3f kilograms",::bow::masmod);
+ bow_logdbg("time unit: %.3f seconds",::bow::timmod);
+ bow_logdbg("gravitational constant: %f (factor: %f))",::bow::grvval,::bow::grvfac);
+
+ inirnd();
+ inisig();
+ inigfx();
+
+ if (opt.skip || !srtseq()) [[likely]] {
+ if (!opt.hassavpth) {opt.savPth = getsavpth();}
+
+ if (opt.newsav) ::bow::newsav(pldat);
+ else ::bow::cnt(pldat,opt.savPth);
+
+ lop();
+
+ ::bow::sav(opt.savPth,pldat);
+
+ if (!opt.hassavpth) delete[] const_cast<char *>(opt.savPth);
+ }
+
+ exi(::bow::cnd::oky);
+}
+
+int main(int const argc,char const * const * argv) {
+ ::bow::bow bow;
+ bow.ini(argc,argv);
+}
diff --git a/bowshock/source/init/bow/initGfx.cxx b/bowshock/source/ini/bow/inigfx.cxx
index 11efdeb..ba33ce5 100644
--- a/bowshock/source/init/bow/initGfx.cxx
+++ b/bowshock/source/ini/bow/inigfx.cxx
@@ -1,42 +1,42 @@
// Copyright 2022-2023 Gabriel Jensen.
-#include <bow/init.hxx>
+#include <bow/ini.hxx>
#include <GLFW/glfw3.h>
#include <glad/glad.h>
-void ::bow::bow::initGfx() noexcept {
+auto ::bow::bow::inigfx() noexcept -> void {
bow_log("initialising graphics");
- bow_logDbg("initialising glfw");
+ bow_logdbg("initialising glfw");
if (!::glfwInit()) [[unlikely]] {
- bow_logErr("unable to initialise glfw");
- ::bow::abrt();
+ bow_logerr("unable to initialise glfw");
+ ::bow::abr();
}
- bow_logDbg("initialising window");
+ bow_logdbg("initialising window");
::glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR,0x4);
::glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR,0x1);
::glfwWindowHint(GLFW_DECORATED, GLFW_FALSE);
::glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
::glfwWindowHint(GLFW_RESIZABLE, GLFW_FALSE);
::glfwWindowHint(GLFW_SAMPLES, 0x8);
- gfxDat.win = ::glfwCreateWindow(0x400,0x240,"Bowshock",::glfwGetPrimaryMonitor(),nullptr);
- if (gfxDat.win == nullptr) [[unlikely]] {
- bow_logErr("unable to open window");
- ::bow::abrt();
+ gfxdat.win = ::glfwCreateWindow(0x400,0x240,"Bowshock",::glfwGetPrimaryMonitor(),nullptr);
+ if (gfxdat.win == nullptr) [[unlikely]] {
+ bow_logerr("unable to open window");
+ ::bow::abr();
}
- bow_logDbg("initialising context");
- ::glfwMakeContextCurrent(gfxDat.win);
+ bow_logdbg("initialising context");
+ ::glfwMakeContextCurrent(gfxdat.win);
::gladLoadGL();
glEnable(GL_MULTISAMPLE);
::GLFWvidmode const * vidmd = ::glfwGetVideoMode(::glfwGetPrimaryMonitor());
glViewport(0x0,0x0,vidmd->width,vidmd->height);
glClearColor(0x0p0,0x0p0,0x0p0,0x1p0);
glClear(GL_COLOR_BUFFER_BIT);
- ::glfwSwapBuffers(gfxDat.win);
+ ::glfwSwapBuffers(gfxdat.win);
::glfwSwapInterval(0x1);
- compShdProg(gfxDat.shdProg,"main");
+ compshdprog(gfxdat.shdprog,"main");
}
diff --git a/bowshock/source/init/bow/initRnd.cxx b/bowshock/source/ini/bow/inirnd.cxx
index 369a68a..1e073a8 100644
--- a/bowshock/source/init/bow/initRnd.cxx
+++ b/bowshock/source/ini/bow/inirnd.cxx
@@ -1,11 +1,11 @@
// Copyright 2022-2023 Gabriel Jensen.
-#include <bow/init.hxx>
+#include <bow/ini.hxx>
#include <cstdlib>
#include <ctime>
-void ::bow::bow::initRnd() noexcept {
+auto ::bow::bow::inirnd() noexcept -> void {
bow_log("initialising random number generator");
::std::srand(static_cast<unsigned int>(::std::time(nullptr)));
diff --git a/bowshock/source/ini/bow/inisig.cxx b/bowshock/source/ini/bow/inisig.cxx
new file mode 100644
index 0000000..dec7fb2
--- /dev/null
+++ b/bowshock/source/ini/bow/inisig.cxx
@@ -0,0 +1,25 @@
+// Copyright 2022-2023 Gabriel Jensen.
+
+#include <bow/ini.hxx>
+
+#include <csignal>
+
+::std::sig_atomic_t volatile ::bow::gotint;
+
+namespace bow {
+ static auto intHnd(int const sig) -> void {
+ ::std::signal(sig,::bow::intHnd); // Ignore the return value: We can't do anything (meaningful) about it anyways.
+ ::bow::gotint = 0x1;
+ }
+}
+
+auto ::bow::bow::inisig() noexcept -> void {
+ bow_log("initialising signal handlers");
+
+ ::bow::gotint = 0x0;
+
+ if (::std::signal(SIGINT,::bow::intHnd) == SIG_ERR) [[unlikely]] {
+ bow_log("unable to set signal handler");
+ ::bow::abr();
+ }
+}
diff --git a/bowshock/source/ini/bow/lop.cxx b/bowshock/source/ini/bow/lop.cxx
new file mode 100644
index 0000000..3e607f2
--- /dev/null
+++ b/bowshock/source/ini/bow/lop.cxx
@@ -0,0 +1,113 @@
+// Copyright 2022-2023 Gabriel Jensen.
+
+#include <bow/ini.hxx>
+#include <bow/lgc.hxx>
+
+#include <GLFW/glfw3.h>
+#include <cmath>
+#include <glad/glad.h>
+#include <stdexcept>
+
+auto ::bow::bow::lop() noexcept -> void {
+ bow_log("entering main loop");
+
+ ::GLfloat vtx[] = {
+ -0x1.0000p0f,+0x1.0000p0f,0x0p0f,
+ +0x1.0000p0f,+0x1.0000p0f,0x0p0f,
+ +0x0.0000p0f,+0x0.0000p0f,0x0p0f,
+ };
+
+ ::GLuint vao;
+ ::GLuint vbo;
+ glGenVertexArrays(0x1,&vao);
+ glGenBuffers(0x1,&vbo);
+
+ glBindVertexArray(vao);
+
+ glBindBuffer(GL_ARRAY_BUFFER,vbo);
+ glBufferData(GL_ARRAY_BUFFER,sizeof (vtx),vtx,GL_STREAM_DRAW);
+
+ glVertexAttribPointer(0x0,0x3,GL_FLOAT,GL_FALSE,0x3 * sizeof (::GLfloat),nullptr);
+ glEnableVertexAttribArray(0x0);
+
+ ::bow::objroot sysRoot; // For stellar bodies.
+ ::bow::objroot objroot = { // For miscellaneous objects (canisters, shps...).
+ .objs = nullptr,
+ };
+
+ try {::bow::gensys(sysRoot,pldat.sysidt,pldat.tim);}
+ catch (::std::bad_alloc const & e) {
+ bow_logerr("unable to allocate memory for object");
+ ::bow::abr();
+ }
+
+ ::bow::obj objTmp = {
+ .typ = ::bow::objtyp::can,
+ .pos = {
+ .x = 0x0p0,
+ .y = -0x2p0,
+ .z = 0x0p0,
+ },
+ .rot = {
+ .x = 0x0p0,
+ .y = 0x0p0,
+ .z = 0x0p0,
+ },
+ .posVel = {
+ .x = -0x1p-12,
+ .y = 0x0p0,
+ .z = 0x0p0,
+ },
+ .rotVel = {
+ .x = 0x0p0,
+ .y = 0x0p0,
+ .z = 0x0p0,
+ },
+ .mas = 0x1p0,
+ };
+ ::bow::addobj(objroot,objTmp);
+
+ auto const scrlHand = [](::GLFWwindow * const win,[[maybe_unused]] double const xoff,double const yoff) -> void {
+ ::bow::pldat * dat = static_cast<::bow::pldat *>(::glfwGetWindowUserPointer(win));
+ dat->zom *= ::std::pow(0x1.04p0f,0x0p0f-static_cast<float>(yoff));
+ };
+
+ ::glfwSetWindowUserPointer(gfxdat.win,&pldat);
+ ::glfwSetScrollCallback(gfxdat.win,scrlHand);
+
+ for (;;++pldat.tim) {
+ if (polevt()) [[unlikely]] break;
+
+ ::bow::grv(sysRoot);
+ ::bow::grv(objroot,sysRoot);
+
+ ::bow::mov(sysRoot);
+ ::bow::mov(objroot);
+
+ ::GLfloat const frm = 0x1p0*pldat.zom;
+
+ vtx[0x0u] = (::GLfloat)sysRoot.objs->nxt->pos.x/frm;
+ vtx[0x1u] = (::GLfloat)sysRoot.objs->nxt->pos.y/frm;
+ vtx[0x3u] = (::GLfloat)sysRoot.objs->pos.x/frm;
+ vtx[0x4u] = (::GLfloat)sysRoot.objs->pos.y/frm;
+ vtx[0x6u] = (::GLfloat)objroot.objs->pos.x/frm;
+ vtx[0x7u] = (::GLfloat)objroot.objs->pos.y/frm;
+
+ glClearColor(0x0p0f,0x0p0f,0x0p0f,1.0f);
+ glClear(GL_COLOR_BUFFER_BIT);
+
+ glBindBuffer(GL_ARRAY_BUFFER,vbo);
+ glBufferSubData(GL_ARRAY_BUFFER,0x0,sizeof (vtx),vtx);
+
+ glUseProgram(gfxdat.shdprog);
+ glBindVertexArray(vao);
+ glDrawArrays(GL_TRIANGLES,0x0,0x3 * 0x1);
+
+ ::glfwSwapBuffers(gfxdat.win);
+ }
+
+ ::glfwSetScrollCallback(gfxdat.win,nullptr);
+
+ glDeleteVertexArrays(0x1,&vao);
+ glDeleteBuffers(0x1,&vbo);
+}
diff --git a/bowshock/source/ini/bow/polevt.cxx b/bowshock/source/ini/bow/polevt.cxx
new file mode 100644
index 0000000..7b0d093
--- /dev/null
+++ b/bowshock/source/ini/bow/polevt.cxx
@@ -0,0 +1,18 @@
+// Copyright 2022-2023 Gabriel Jensen.
+
+#include <bow/ini.hxx>
+
+#include <GLFW/glfw3.h>
+
+auto ::bow::bow::polevt() noexcept -> bool {
+ ::glfwPollEvents();
+
+ if (::bow::gotint) [[unlikely]] {
+ bow_log("got interrupt");
+ ::glfwSetWindowShouldClose(gfxdat.win,GLFW_TRUE);
+
+ }
+ if (::glfwWindowShouldClose(gfxdat.win)) [[unlikely]] return true;
+
+ return false;
+}
diff --git a/bowshock/source/init/bow/priQuot.cxx b/bowshock/source/ini/bow/priquo.cxx
index 6882c15..de964af 100644
--- a/bowshock/source/init/bow/priQuot.cxx
+++ b/bowshock/source/ini/bow/priquo.cxx
@@ -1,19 +1,19 @@
// Copyright 2022-2023 Gabriel Jensen.
-#include <bow/init.hxx>
+#include <bow/ini.hxx>
#include <cinttypes>
#include <ctime>
#include <cstdlib>
-void ::bow::bow::priQuot() noexcept {
+auto ::bow::bow::priquo() noexcept -> void {
::std::srand(static_cast<unsigned int>(::std::time(nullptr)));
::zp::i8 const quotId = (::zp::i8)rand() % 0x24u;
- char const * quot;
+ char const * quo;
char const * src;
- getQuot(&quot,&src,quotId);
+ getquo(&quo,&src,quotId);
- if (src == nullptr) {bow_logRaw("%s\n",quot);}
- else {bow_logRaw("\n%s\n\u2014 %s\n\n",quot,src);}
+ if (src == nullptr) {bow_lograw("%s\n",quo);}
+ else {bow_lograw("\n%s\n\u2014 %s\n\n",quo,src);}
}
diff --git a/bowshock/source/ini/bow/srtseq.cxx b/bowshock/source/ini/bow/srtseq.cxx
new file mode 100644
index 0000000..6377fb2
--- /dev/null
+++ b/bowshock/source/ini/bow/srtseq.cxx
@@ -0,0 +1,46 @@
+// Copyright 2022-2023 Gabriel Jensen.
+
+#include <bow/ini.hxx>
+
+#include <GLFW/glfw3.h>
+
+auto ::bow::bow::srtseq() noexcept -> bool {
+ bow_log("starting start sequence");
+
+ bool exi = false;
+
+ constexpr ::GLfloat bowr = 0x1.6D6D6D6Ep-1;
+ constexpr ::GLfloat bowg = 0x1.81818182p-4;
+ constexpr ::GLfloat bowb = 0x1.9999999Ap-3;
+
+ ::glfwSetTime(0x0p0);
+ for (double dur = 0x0p0;dur <= 0x3p0;dur = ::glfwGetTime()) {
+ if (polevt()) [[unlikely]] break;
+
+ glClearColor(bowr,bowg,bowb,0x1p0);
+ glClear(GL_COLOR_BUFFER_BIT);
+ ::glfwSwapBuffers(gfxdat.win);
+ }
+
+ double const fadedur = 0x1p0;
+ ::glfwSetTime(0x0p0);
+ for (double fac = 0x0p0;fac <= fadedur;fac = ::glfwGetTime()) {
+ if (polevt()) [[unlikely]] {break;}
+
+ ::GLfloat const r = bowr*(0x1p0f-fac/fadedur);
+ ::GLfloat const g = bowg*(0x1p0f-fac/fadedur);
+ ::GLfloat const b = bowb*(0x1p0f-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)) [[unlikely]] {exi = true;}
+
+ return exi;
+}
diff --git a/bowshock/source/init/bow/bow.cxx b/bowshock/source/init/bow/bow.cxx
deleted file mode 100644
index 61d2820..0000000
--- a/bowshock/source/init/bow/bow.cxx
+++ /dev/null
@@ -1,20 +0,0 @@
-// Copyright 2022-2023 Gabriel Jensen.
-
-#include <bow/init.hxx>
-#include <bow/lgc.hxx>
-#include <bow/run.hxx>
-#include <bow/sav.hxx>
-
-#include <cinttypes>
-
-::bow::bow::bow(int const argc,char const * const * const argv) noexcept {
- init(argc,argv);
-}
-
-::bow::bow::~bow() noexcept {
- quit(::bow::stat::ok);
-}
-
-int main(int const argc,char const * const * argv) {
- ::bow::bow bow = {argc,argv};
-}
diff --git a/bowshock/source/init/bow/chkParams.cxx b/bowshock/source/init/bow/chkParams.cxx
deleted file mode 100644
index 153838e..0000000
--- a/bowshock/source/init/bow/chkParams.cxx
+++ /dev/null
@@ -1,38 +0,0 @@
-// Copyright 2022-2023 Gabriel Jensen.
-
-#include <bow/init.hxx>
-
-#include <zp/mem>
-#include <zp/str>
-
-void ::bow::bow::chkParams(::bow::termOpts & opts,int const argc,char const * const * argv) noexcept {
- char const * const progNm = *argv;
-
- opts = ::bow::termOpts {
- .hasSavPth = false,
- .newSav = false,
- .skip = false,
- };
-
- if (argc >= 0x2) [[unlikely]] {
- char const * const * const stop = (argv++)+(::zp::siz)argc;
-
- for (;argv != stop;++argv) {
- char const * param = *argv;
-
- if (param[0x0u] == '-' && param[0x1u] == '-') {
- param += 0x2u;
- if (::zp::strequ(param,"credits")) cred();
- else if (::zp::strequ(param,"help")) help(progNm);
- else if (::zp::strequ(param,"new")) opts.newSav = true;
- else if (::zp::strequ(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;
- }
- }
-}
diff --git a/bowshock/source/init/bow/compShdProg.cxx b/bowshock/source/init/bow/compShdProg.cxx
deleted file mode 100644
index 43bd7e5..0000000
--- a/bowshock/source/init/bow/compShdProg.cxx
+++ /dev/null
@@ -1,34 +0,0 @@
-// Copyright 2022-2023 Gabriel Jensen.
-
-#include <bow/init.hxx>
-
-#include <glad/glad.h>
-#include <stdexcept>
-
-void ::bow::bow::compShdProg(GLuint & shdProg,char const * const nm) noexcept {
- bow_log("compiling shader program \"%s\"",nm);
-
- GLuint vtxShd;
- GLuint fragShd;
-
- try {
- compShd(vtxShd, nm, GL_VERTEX_SHADER);
- compShd(fragShd,nm,GL_FRAGMENT_SHADER);
- }
- catch (::std::runtime_error const & e) {
- bow_logErr("%s",e.what());
- ::bow::abrt();
- }
- catch (::std::bad_alloc const & e) {
- bow_logErr("unable to allocate memory for shader data");
- ::bow::abrt();
- }
-
- shdProg = glCreateProgram();
- glAttachShader(shdProg,vtxShd);
- glAttachShader(shdProg,fragShd);
- glLinkProgram(shdProg);
-
- glDeleteShader(vtxShd);
- glDeleteShader(fragShd);
-}
diff --git a/bowshock/source/init/bow/getQuot.cxx b/bowshock/source/init/bow/getQuot.cxx
deleted file mode 100644
index 8d41eea..0000000
--- a/bowshock/source/init/bow/getQuot.cxx
+++ /dev/null
@@ -1,157 +0,0 @@
-// Copyright 2022-2023 Gabriel Jensen.
-
-#include <bow/init.hxx>
-
-#include <cinttypes>
-
-void ::bow::bow::getQuot(char const * * const quot,char const * * src,::zp::i8m const id) noexcept {
- switch (id) {
- default:
- bow_logErr("invalid quote identifier (%" PRIX8 ")",id);
- [[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";
- break;
- 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;
- case 0x1Du:
- *quot = "That's one small step for a man, one giant leap for mankind.";
- *src = "Neil Alden Armstrong";
- break;
- case 0x1Eu:
- *quot = "If you think it's simple, then you have misunderstood the problem.";
- *src = "Bjarne Stroustrup";
- break;
- case 0x1Fu:
- *quot = "Controlling complexity is the essence of computer programming.";
- *src = "Brian Wilson Kerningham";
- break;
- case 0x20u:
- *quot = "I have always wished for my computer to be as easy to use as my telephone.\nMy wish has come true because I can no longer figure out how to use my telephone.";
- *src = "Bjarne Stroustrup";
- break;
- case 0x21u:
- *quot = "There is no mathematical sibstitute for philosophy.";
- *src = "Saul Aaron Kripke";
- break;
- case 0x22u:
- *quot = "Biology is engineering.";
- *src = "Daniel Clement Dennett III";
- break;
- case 0x23u:
- *quot = "The universe is under no obligation to make sense to you.";
- *src = "Neil deGrasse Tyson";
- break;
- }
-}
diff --git a/bowshock/source/init/bow/getSavPth.cxx b/bowshock/source/init/bow/getSavPth.cxx
deleted file mode 100644
index e3068dc..0000000
--- a/bowshock/source/init/bow/getSavPth.cxx
+++ /dev/null
@@ -1,36 +0,0 @@
-// Copyright 2022-2023 Gabriel Jensen.
-
-#include <bow/init.hxx>
-
-#include <cstdlib>
-#include <ly/fs>
-#include <zp/mem>
-#include <zp/str>
-
-char const * ::bow::bow::getSavPth() noexcept {
- char const * homdir = ::ly::homdir();
- char const * filNm;
- ::zp::siz hmDirLen;
- ::zp::siz filNmLen;
-
- if (homdir == nullptr) [[unlikely]] {
- bow_log("unable to get home directory, using current directory");
- bow_setStrLen(homdir,hmDirLen,"./");
- }
- else hmDirLen = ::zp::strlen(homdir);
-
- bow_setStrLen(filNm,filNmLen,".save.bowshock");
-
- ::zp::siz pthLen = hmDirLen+filNmLen+0x1u;
-
- char * pth = new char[pthLen + 0x1u];
-
- pth = ::zp::memcpy(pth,homdir,hmDirLen).dst;
- *pth++ = '/';
- pth = ::zp::memcpy(pth,filNm,filNmLen).dst;
- *pth = '\x00';
-
- pth -= pthLen;
-
- return pth;
-}
diff --git a/bowshock/source/init/bow/init.cxx b/bowshock/source/init/bow/init.cxx
deleted file mode 100644
index ffb1083..0000000
--- a/bowshock/source/init/bow/init.cxx
+++ /dev/null
@@ -1,44 +0,0 @@
-// Copyright 2022-2023 Gabriel Jensen.
-
-#include <bow/init.hxx>
-#include <bow/lgc.hxx>
-#include <bow/run.hxx>
-#include <bow/sav.hxx>
-
-#include <cinttypes>
-
-void ::bow::bow::init(int const argc,char const * const * const argv) noexcept {
- ::bow::termOpts opts;
- chkParams(opts,argc,argv);
-
- priQuot();
-
- bow_logRaw("\x1B[0m\x1B[1mBowshock\x1B[0m %" PRIX64 ".%" PRIX64 ".%" PRIX64 " \u2013 Copyright 2022\u20102023 \x1B[1mGabriel Jensen\x1B[0m.\n\n",::bow::verMaj,::bow::verMin,::bow::verPat);
-
- bow_log("initialising");
-
- bow_logDbg("debug mode is enabled");
- bow_logDbg("data directory at \"" bow_datDir "\"");
- bow_logDbg("angle unit: %.3f radians",0x1p0f);
- bow_logDbg("distance unit: %.3f metres",::bow::distMod);
- bow_logDbg("mass unit: %.3f kilograms",::bow::massMod);
- bow_logDbg("time unit: %.3f seconds",::bow::tmMod);
- bow_logDbg("gravitational constant: %f (factor: %f))",::bow::gravConst,::bow::gravConstFac);
-
- initRnd();
- initSig();
- initGfx();
-
- if (opts.skip || !intro()) [[likely]] {
- if (!opts.hasSavPth) {opts.savPth = getSavPth();}
-
- if (opts.newSav) ::bow::newSav(plDat);
- else ::bow::cont(plDat,opts.savPth);
-
- loop();
-
- ::bow::sav(opts.savPth,plDat);
-
- if (!opts.hasSavPth) delete[] const_cast<char *>(opts.savPth);
- }
-}
diff --git a/bowshock/source/init/bow/initSig.cxx b/bowshock/source/init/bow/initSig.cxx
deleted file mode 100644
index aef0424..0000000
--- a/bowshock/source/init/bow/initSig.cxx
+++ /dev/null
@@ -1,25 +0,0 @@
-// Copyright 2022-2023 Gabriel Jensen.
-
-#include <bow/init.hxx>
-
-#include <csignal>
-
-::std::sig_atomic_t volatile ::bow::gotIntr;
-
-namespace bow {
- static void intrHand(int const sig) {
- ::std::signal(sig,::bow::intrHand); // Ignore the return value: We can't do anything (meaningful) about it anyways.
- ::bow::gotIntr = 0x1;
- }
-}
-
-void ::bow::bow::initSig() noexcept {
- bow_log("initialising signal handlers");
-
- ::bow::gotIntr = 0x0;
-
- if (::std::signal(SIGINT,::bow::intrHand) == SIG_ERR) [[unlikely]] {
- bow_log("unable to set signal handler");
- ::bow::abrt();
- }
-}
diff --git a/bowshock/source/init/bow/intro.cxx b/bowshock/source/init/bow/intro.cxx
deleted file mode 100644
index 9d2d8c3..0000000
--- a/bowshock/source/init/bow/intro.cxx
+++ /dev/null
@@ -1,45 +0,0 @@
-// Copyright 2022-2023 Gabriel Jensen.
-
-#include <bow/init.hxx>
-
-#include <GLFW/glfw3.h>
-
-bool ::bow::bow::intro() noexcept {
- bow_log("starting intro");
-
- bool quit = false;
- GLfloat const bowr = 0x1.6D6D6D6Ep-1;
- GLfloat const bowg = 0x1.81818182p-4;
- GLfloat const bowb = 0x1.9999999Ap-3;
-
- ::glfwSetTime(0x0p0);
- for (double dur = 0x0p0;dur <= 0x3p0;dur = ::glfwGetTime()) {
- if (pollEvts()) [[unlikely]] break;
-
- glClearColor(bowr,bowg,bowb,0x1p0);
- glClear(GL_COLOR_BUFFER_BIT);
- ::glfwSwapBuffers(gfxDat.win);
- }
-
- double const fadedur = 0x1p0;
- ::glfwSetTime(0x0p0);
- for (double fac = 0x0p0;fac <= fadedur;fac = ::glfwGetTime()) {
- if (pollEvts()) [[unlikely]] break;
-
- GLfloat const r = bowr*(0x1p0f-fac/fadedur);
- GLfloat const g = bowg*(0x1p0f-fac/fadedur);
- GLfloat const b = bowb*(0x1p0f-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)) [[unlikely]] quit = true;
-
- return quit;
-}
diff --git a/bowshock/source/init/bow/loop.cxx b/bowshock/source/init/bow/loop.cxx
deleted file mode 100644
index 8a963e4..0000000
--- a/bowshock/source/init/bow/loop.cxx
+++ /dev/null
@@ -1,113 +0,0 @@
-// Copyright 2022-2023 Gabriel Jensen.
-
-#include <bow/init.hxx>
-#include <bow/lgc.hxx>
-
-#include <GLFW/glfw3.h>
-#include <cmath>
-#include <glad/glad.h>
-#include <stdexcept>
-
-void ::bow::bow::loop() noexcept {
- bow_log("entering main loop");
-
- GLfloat vtx[] = {
- -0x1.0000p0f,+0x1.0000p0f,0x0p0f,
- +0x1.0000p0f,+0x1.0000p0f,0x0p0f,
- +0x0.0000p0f,+0x0.0000p0f,0x0p0f,
- };
-
- GLuint vao;
- GLuint vbo;
- glGenVertexArrays(0x1,&vao);
- glGenBuffers(0x1,&vbo);
-
- glBindVertexArray(vao);
-
- glBindBuffer(GL_ARRAY_BUFFER,vbo);
- glBufferData(GL_ARRAY_BUFFER,sizeof (vtx),vtx,GL_STREAM_DRAW);
-
- glVertexAttribPointer(0x0,0x3,GL_FLOAT,GL_FALSE,0x3 * sizeof (GLfloat),nullptr);
- glEnableVertexAttribArray(0x0);
-
- ::bow::objRoot sysRoot; // For stellar bodies.
- ::bow::objRoot objRoot = { // For miscellaneous objects (canisters, ships...).
- .objs = nullptr,
- };
-
- try {::bow::genSys(sysRoot,plDat.sysId,plDat.tm);}
- catch (::std::bad_alloc const & e) {
- bow_logErr("unable to allocate memory for object");
- ::bow::abrt();
- }
-
- ::bow::obj objTmp = {
- .typ = ::bow::objTyp::can,
- .pos = {
- .x = 0x0p0,
- .y = -0x2p0,
- .z = 0x0p0,
- },
- .rot = {
- .x = 0x0p0,
- .y = 0x0p0,
- .z = 0x0p0,
- },
- .posVel = {
- .x = -0x1p-12,
- .y = 0x0p0,
- .z = 0x0p0,
- },
- .rotVel = {
- .x = 0x0p0,
- .y = 0x0p0,
- .z = 0x0p0,
- },
- .mass = 0x1p0,
- };
- ::bow::addObj(objRoot,objTmp);
-
- auto const scrlHand = [](::GLFWwindow * const win,[[maybe_unused]] double const xoff,double const yoff) -> void {
- ::bow::plDat * dat = static_cast<::bow::plDat *>(::glfwGetWindowUserPointer(win));
- dat->zoom *= ::std::pow(0x1.04p0f,0x0p0f-static_cast<float>(yoff));
- };
-
- ::glfwSetWindowUserPointer(gfxDat.win,&plDat);
- ::glfwSetScrollCallback(gfxDat.win,scrlHand);
-
- for (;;++plDat.tm) {
- if (pollEvts()) [[unlikely]] break;
-
- ::bow::grav(sysRoot);
- ::bow::grav(objRoot,sysRoot);
-
- ::bow::mv(sysRoot);
- ::bow::mv(objRoot);
-
- GLfloat const frm = 0x1p0*plDat.zoom;
-
- vtx[0x0u] = (GLfloat)sysRoot.objs->next->pos.x/frm;
- vtx[0x1u] = (GLfloat)sysRoot.objs->next->pos.y/frm;
- vtx[0x3u] = (GLfloat)sysRoot.objs->pos.x/frm;
- vtx[0x4u] = (GLfloat)sysRoot.objs->pos.y/frm;
- vtx[0x6u] = (GLfloat)objRoot.objs->pos.x/frm;
- vtx[0x7u] = (GLfloat)objRoot.objs->pos.y/frm;
-
- glClearColor(0x0p0f,0x0p0f,0x0p0f,1.0f);
- glClear(GL_COLOR_BUFFER_BIT);
-
- glBindBuffer(GL_ARRAY_BUFFER,vbo);
- glBufferSubData(GL_ARRAY_BUFFER,0x0,sizeof (vtx),vtx);
-
- glUseProgram(gfxDat.shdProg);
- glBindVertexArray(vao);
- glDrawArrays(GL_TRIANGLES,0x0,0x3 * 0x1);
-
- ::glfwSwapBuffers(gfxDat.win);
- }
-
- ::glfwSetScrollCallback(gfxDat.win,nullptr);
-
- glDeleteVertexArrays(0x1,&vao);
- glDeleteBuffers(0x1,&vbo);
-}
diff --git a/bowshock/source/init/bow/pollEvts.cxx b/bowshock/source/init/bow/pollEvts.cxx
deleted file mode 100644
index 063a68e..0000000
--- a/bowshock/source/init/bow/pollEvts.cxx
+++ /dev/null
@@ -1,18 +0,0 @@
-// Copyright 2022-2023 Gabriel Jensen.
-
-#include <bow/init.hxx>
-
-#include <GLFW/glfw3.h>
-
-bool ::bow::bow::pollEvts() noexcept {
- ::glfwPollEvents();
-
- if (::bow::gotIntr) [[unlikely]] {
- bow_log("got interrupt");
- ::glfwSetWindowShouldClose(gfxDat.win,GLFW_TRUE);
-
- }
- if (::glfwWindowShouldClose(gfxDat.win)) [[unlikely]] return true;
-
- return false;
-}
diff --git a/bowshock/source/init/bow/quit.cxx b/bowshock/source/init/bow/quit.cxx
deleted file mode 100644
index 50c71ea..0000000
--- a/bowshock/source/init/bow/quit.cxx
+++ /dev/null
@@ -1,29 +0,0 @@
-// Copyright 2022-2023 Gabriel Jensen.
-
-#include <bow/init.hxx>
-
-#include <cstdlib>
-#include <GLFW/glfw3.h>
-
-void ::bow::bow::quit(::bow::stat const stat) noexcept {
- bow_log("quitting");
-
- glDeleteProgram(gfxDat.shdProg);
-
- ::glfwDestroyWindow(gfxDat.win);
- ::glfwTerminate();
-
- int sysstat;
- switch (stat) {
- case ::bow::stat::err:
- sysstat = EXIT_FAILURE;
- break;
- case ::bow::stat::ok:
- sysstat = EXIT_SUCCESS;
- break;
- }
-
- bow_log("goodbye");
- bow_log("exiting with code %i",sysstat);
- ::std::exit(sysstat);
-}
diff --git a/bowshock/source/lgc/grav.cxx b/bowshock/source/lgc/grv.cxx
index 3896756..1eceae5 100644
--- a/bowshock/source/lgc/grav.cxx
+++ b/bowshock/source/lgc/grv.cxx
@@ -5,7 +5,7 @@
#include <cmath>
namespace bow {
- static void grav1(::bow::obj & obj,::bow::obj const & par) noexcept {
+ static auto grav1(::bow::obj & obj,::bow::obj const & par) noexcept -> void {
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;
@@ -14,7 +14,7 @@ namespace bow {
double const angy = ::std::atan2(disty,distx);
double const angz = ::std::atan2(distz,distx);
- double acc = par.mass/(dist*dist)*::bow::gravConst;
+ double acc = par.mas/(dist*dist)*::bow::grvval;
double const vx = ::std::cos(angy)*acc;
double const vy = ::std::sin(angy)*acc;
@@ -34,9 +34,9 @@ namespace bow {
double const angy = ::std::atan2(disty,distx);
double const angz = ::std::atan2(distz,distx);
- double acc0 = ::bow::gravConst/(dist*dist);
- double const acc1 = acc0*obj0.mass; // This is negative.
- acc0 *= obj1.mass;
+ double acc0 = ::bow::grvval/(dist*dist);
+ double const acc1 = acc0*obj0.mas; // This is negative.
+ acc0 *= obj1.mas;
double vx0 = ::std::cos(angy);
double vy0 = ::std::sin(angy);
@@ -58,17 +58,17 @@ namespace bow {
}
}
-void ::bow::grav(::bow::objRoot & sys) noexcept {
- for (::bow::obj * obj0 = sys.objs;obj0 != nullptr;obj0 = obj0->next) {
- for (::bow::obj * obj1 = obj0->next;obj1 != nullptr;obj1 = obj1->next) {
+auto ::bow::grv(::bow::objroot & sys) noexcept -> void {
+ for (::bow::obj * obj0 = sys.objs;obj0 != nullptr;obj0 = obj0->nxt) {
+ for (::bow::obj * obj1 = obj0->nxt;obj1 != nullptr;obj1 = obj1->nxt) {
::bow::grav2(*obj0,*obj1);
}
}
}
-void ::bow::grav(::bow::objRoot & objs,::bow::objRoot const & sys) noexcept {
- for (::bow::obj * obj = objs.objs;obj != nullptr;obj = obj->next) {
- for (::bow::obj * par = sys.objs;par != nullptr;par = par->next) {
+auto ::bow::grv(::bow::objroot & objs,::bow::objroot const & sys) noexcept -> void {
+ for (::bow::obj * obj = objs.objs;obj != nullptr;obj = obj->nxt) {
+ for (::bow::obj * par = sys.objs;par != nullptr;par = par->nxt) {
::bow::grav1(*obj,*par);
}
}
diff --git a/bowshock/source/lgc/mv.cxx b/bowshock/source/lgc/mov.cxx
index b54a0af..eee6759 100644
--- a/bowshock/source/lgc/mv.cxx
+++ b/bowshock/source/lgc/mov.cxx
@@ -2,8 +2,8 @@
#include <bow/lgc.hxx>
-void ::bow::mv(::bow::objRoot & root) noexcept {
- auto const mv = [](::bow::obj & obj) {
+auto ::bow::mov(::bow::objroot & root) noexcept -> void {
+ auto const mov = [](::bow::obj & obj) {
obj.pos.x += obj.posVel.x;
obj.pos.y += obj.posVel.y;
obj.pos.z += obj.posVel.z;
@@ -12,7 +12,7 @@ void ::bow::mv(::bow::objRoot & root) noexcept {
obj.rot.z += obj.rotVel.z;
};
- for (::bow::obj * obj = root.objs;obj != nullptr;obj = obj->next) {
- mv(*obj);
+ for (::bow::obj * obj = root.objs;obj != nullptr;obj = obj->nxt) {
+ mov(*obj);
}
}
diff --git a/bowshock/source/lgc/shipMass.cxx b/bowshock/source/lgc/shipMass.cxx
deleted file mode 100644
index e95140b..0000000
--- a/bowshock/source/lgc/shipMass.cxx
+++ /dev/null
@@ -1,10 +0,0 @@
-// Copyright 2022-2023 Gabriel Jensen.
-
-#include <bow/lgc.hxx>
-
-double ::bow::shipMass([[maybe_unused]] ::bow::ship const id) noexcept {
- double mass = 0x100p0;
- mass /= ::bow::massMod;
-
- return mass;
-}
diff --git a/bowshock/source/lgc/shpmas.cxx b/bowshock/source/lgc/shpmas.cxx
new file mode 100644
index 0000000..675a1b0
--- /dev/null
+++ b/bowshock/source/lgc/shpmas.cxx
@@ -0,0 +1,10 @@
+// Copyright 2022-2023 Gabriel Jensen.
+
+#include <bow/lgc.hxx>
+
+auto ::bow::shpmas([[maybe_unused]] ::bow::shp const id) noexcept -> double {
+ double mas = 0x100p0;
+ mas /= ::bow::masmod;
+
+ return mas;
+}
diff --git a/bowshock/source/lgc/sim.cxx b/bowshock/source/lgc/sim.cxx
index 7832c64..ea1ffd3 100644
--- a/bowshock/source/lgc/sim.cxx
+++ b/bowshock/source/lgc/sim.cxx
@@ -6,11 +6,11 @@
#include <cinttypes>
-void ::bow::sim(::bow::objRoot & sys,::zp::i04 const dur) noexcept {
+auto ::bow::sim(::bow::objroot & sys,::zp::i04 const dur) noexcept -> void {
bow_log("simulating for (%" PRIX64 ") time units",dur);
for (::zp::i04 i = 0x0u;i <= dur;++i) {
- ::bow::grav(sys);
- ::bow::mv(sys);
+ ::bow::grv(sys);
+ ::bow::mov(sys);
}
}
diff --git a/bowshock/source/run/abr.cxx b/bowshock/source/run/abr.cxx
new file mode 100644
index 0000000..76225be
--- /dev/null
+++ b/bowshock/source/run/abr.cxx
@@ -0,0 +1,13 @@
+// Copyright 2022-2023 Gabriel Jensen.
+
+#include <bow/run.hxx>
+
+#include <cinttypes>
+#include <cstdlib>
+#include <source_location>
+
+auto ::bow::abr(::std::source_location const srcloc) noexcept -> void {
+ bow_log("\x1B[38;5;197maborting\x1B[0m from \"%s\":%" PRIXLEAST32 " @ %s\n",srcloc.file_name(),srcloc.line(),srcloc.function_name());
+
+ ::std::abort();
+}
diff --git a/bowshock/source/run/abrt.cxx b/bowshock/source/run/abrt.cxx
deleted file mode 100644
index 80ceb4b..0000000
--- a/bowshock/source/run/abrt.cxx
+++ /dev/null
@@ -1,11 +0,0 @@
-// Copyright 2022-2023 Gabriel Jensen.
-
-#include <bow/run.hxx>
-
-#include <cstdlib>
-
-void ::bow::abrt() noexcept {
- bow_log("\x1B[38;5;197maborting\x1B[0m");
-
- ::std::abort();
-}
diff --git a/bowshock/source/run/addObj.cxx b/bowshock/source/run/addobj.cxx
index 06ad41a..27459c9 100644
--- a/bowshock/source/run/addObj.cxx
+++ b/bowshock/source/run/addobj.cxx
@@ -5,12 +5,12 @@
#include <cstdlib>
#include <zp/mem>
-void ::bow::addObj(::bow::objRoot & root,::bow::obj const & objVal) {
- bow_logDbg("adding object of type %s",::bow::objTypStr(objVal.typ));
+auto ::bow::addobj(::bow::objroot & root,::bow::obj const & objVal) -> void {
+ bow_logdbg("adding object of type %s",::bow::objtypstr(objVal.typ));
::bow::obj * const obj = new ::bow::obj;
::zp::memcpy(obj,&objVal,sizeof (objVal));
- obj->next = root.objs;
+ obj->nxt = root.objs;
root.objs = obj;
}
diff --git a/bowshock/source/run/freeObjs.cxx b/bowshock/source/run/freeObjs.cxx
deleted file mode 100644
index 7843aca..0000000
--- a/bowshock/source/run/freeObjs.cxx
+++ /dev/null
@@ -1,16 +0,0 @@
-// Copyright 2022-2023 Gabriel Jensen.
-
-#include <bow/run.hxx>
-
-void ::bow::freeObjs(::bow::objRoot const & root) noexcept {
- bow_logDbg("freeing objects");
-
- ::bow::obj * obj;
- ::bow::obj * next;
- for (obj = root.objs;obj != nullptr;obj = next) {
- bow_logDbg("freeing object of type %s",::bow::objTypStr(obj->typ));
-
- next = obj->next;
- delete obj;
- }
-}
diff --git a/bowshock/source/run/genSys.cxx b/bowshock/source/run/gensys.cxx
index d8d199c..4b0d17c 100644
--- a/bowshock/source/run/genSys.cxx
+++ b/bowshock/source/run/gensys.cxx
@@ -5,14 +5,15 @@
#include <cinttypes>
-void ::bow::genSys(::bow::objRoot & sys,::zp::i04 const id,::zp::i04 const tm) {
- bow_log("generating system (%" PRIXLEAST64 ")",id);
+auto ::bow::gensys(::bow::objroot & sys,::zp::i04 const id,::zp::i04 const tim) -> void {
+ bow_log("generating system (%" PRIX64 ")",id);
+ // Note: The following code is only temporary;
sys.objs = nullptr;
::bow::obj objTmp;
objTmp = ::bow::obj {
- .typ = ::bow::objTyp::star,
- .starTyp = ::bow::star::g,
+ .typ = ::bow::objtyp::tar,
+ .tartyp = ::bow::tar::g,
.pos = {
.x = 0x0p0,
.y = 0x0p0,
@@ -33,13 +34,13 @@ void ::bow::genSys(::bow::objRoot & sys,::zp::i04 const id,::zp::i04 const tm) {
.y = 0x0p0,
.z = 0x0p0,
},
- .mass = 0x1p0,
- // next will be overwritten anyways.
+ .mas = 0x1p0,
+ // nxt will be overwritten anyways.
};
- ::bow::addObj(sys,objTmp);
+ ::bow::addobj(sys,objTmp);
objTmp = ::bow::obj {
- .typ = ::bow::objTyp::wrld,
- .wrldTyp = ::bow::wrld::rck,
+ .typ = ::bow::objtyp::wrl,
+ .wrldTyp = ::bow::wrl::rck,
.pos = {
.x = 0x0p0,
.y = 0x1.F76F144Dp-1,
@@ -51,7 +52,7 @@ void ::bow::genSys(::bow::objRoot & sys,::zp::i04 const id,::zp::i04 const tm) {
.z = 0x0p0,
},
.posVel = {
- .x = 0x1.B2D06FF3p-23*::bow::tmMod,
+ .x = 0x1.B2D06FF3p-23*::bow::timmod,
.y = 0x0p0,
.z = 0x0p0,
},
@@ -60,9 +61,9 @@ void ::bow::genSys(::bow::objRoot & sys,::zp::i04 const id,::zp::i04 const tm) {
.y = 0x0p0,
.z = 0x1.31DB66BBp-15,
},
- .mass = 0x1.931AFC649369998Fp-19,
+ .mas = 0x1.931AFC649369998Fp-19,
};
- ::bow::addObj(sys,objTmp);
+ ::bow::addobj(sys,objTmp);
- ::bow::sim(sys,tm);
+ ::bow::sim(sys,tim);
}
diff --git a/bowshock/source/run/remobj.cxx b/bowshock/source/run/remobj.cxx
new file mode 100644
index 0000000..a6b689d
--- /dev/null
+++ b/bowshock/source/run/remobj.cxx
@@ -0,0 +1,16 @@
+// Copyright 2022-2023 Gabriel Jensen.
+
+#include <bow/run.hxx>
+
+auto ::bow::remobj(::bow::objroot const & root) noexcept -> void {
+ bow_logdbg("freeing objects");
+
+ ::bow::obj * obj;
+ ::bow::obj * nxt;
+ for (obj = root.objs;obj != nullptr;obj = nxt) {
+ bow_logdbg("freeing object of type %s",::bow::objtypstr(obj->typ));
+
+ nxt = obj->nxt;
+ delete obj;
+ }
+}
diff --git a/bowshock/source/sav/cnt.cxx b/bowshock/source/sav/cnt.cxx
new file mode 100644
index 0000000..d6effdb
--- /dev/null
+++ b/bowshock/source/sav/cnt.cxx
@@ -0,0 +1,84 @@
+// Copyright 2022-2023 Gabriel Jensen.
+
+#include <bow/sav.hxx>
+
+#include <cinttypes>
+#include <ly/io>
+#include <zp/mem>
+
+auto ::bow::cnt(::bow::pldat & pldat,char const * const pth) noexcept -> void {
+ bow_log("loading save file at \"%s\"",pth);
+
+ ::ly::fil fil;
+
+ ::ly::err err = fil.opn(pth,::ly::mod::red,::ly::kep);
+
+ if (err != ::ly::err::ok) [[unlikely]] {
+ bow_logerr("unable to open save file \"%s\"",pth);
+
+ return ::bow::newsav(pldat);
+ }
+
+ ::zp::i8 rawDat[::bow::savlen];
+ err = fil.red(rawDat,::bow::savlen);
+
+ if (err != ::ly::err::ok) [[unlikely]] {
+ fil.cls();
+
+ if (err == ::ly::err::eof) bow_logerr("corrupt save file at \"%s\"",pth);
+ else bow_logerr("unable to read file at \"%s\"",pth);
+
+ return ::bow::newsav(pldat);
+ }
+
+ fil.cls();
+
+ ::bow::savdat dat;
+
+ ::bow::decsav(dat,rawDat);
+
+ if (dat.fmtVer != ::bow::savver) [[unlikely]] {
+ bow_logerr("invalid format (%" PRIX64 ") of save file at \"%s\"",dat.fmtVer,pth);
+
+ return ::bow::newsav(pldat);
+ }
+ if (dat.shptyp > ::bow::maxshpid) [[unlikely]] {
+ bow_logerr("invalid shp type (%" PRIX8 ")",dat.shptyp);
+
+ return ::bow::newsav(pldat);
+ }
+
+ pldat = ::bow::pldat {
+ .tim = dat.tim,
+ .sysidt = dat.sysidt,
+ .shp = {
+ .shptyp = (::bow::shp)dat.shptyp,
+ .pos = {
+ .x = dat.shpposx,
+ .y = dat.shpposy,
+ .z = dat.shpposz,
+ },
+ .rot = {
+ .x = dat.shprotx,
+ .y = dat.shproty,
+ .z = dat.shprotz,
+ },
+ .posVel = {
+ .x = dat.shpposvelx,
+ .y = dat.shpposvely,
+ .z = dat.shpposvelz,
+ },
+ .rotVel = {
+ .x = dat.shprotvelx,
+ .y = dat.shprotvely,
+ .z = dat.shprotvelz,
+ },
+ },
+ };
+ ::zp::cpy(pldat.nam,dat.cmdnam,::bow::cmdnamlen);
+ pldat.nam[::bow::cmdnamlen] = '\x00';
+
+ ::bow::gendat(pldat);
+
+ bow_log("welcome back, commander %s",pldat.nam);
+}
diff --git a/bowshock/source/sav/cont.cxx b/bowshock/source/sav/cont.cxx
deleted file mode 100644
index 6d81798..0000000
--- a/bowshock/source/sav/cont.cxx
+++ /dev/null
@@ -1,84 +0,0 @@
-// Copyright 2022-2023 Gabriel Jensen.
-
-#include <bow/sav.hxx>
-
-#include <cinttypes>
-#include <ly/io>
-#include <zp/mem>
-
-void ::bow::cont(::bow::plDat & plDat,char const * const pth) noexcept {
- bow_log("loading save file at \"%s\"",pth);
-
- ::ly::fil fil;
-
- ::ly::err err = fil.opn(pth,::ly::mod::red,::ly::kep);
-
- if (err != ::ly::err::ok) [[unlikely]] {
- bow_logErr("unable to open save file \"%s\"",pth);
-
- return ::bow::newSav(plDat);
- }
-
- ::zp::i8 rawDat[::bow::savLen];
- err = fil.red(rawDat,::bow::savLen);
-
- if (err != ::ly::err::ok) [[unlikely]] {
- fil.cls();
-
- if (err == ::ly::err::eof) bow_logErr("corrupt save file at \"%s\"",pth);
- else bow_logErr("unable to read file at \"%s\"",pth);
-
- return ::bow::newSav(plDat);
- }
-
- fil.cls();
-
- ::bow::savDat dat;
-
- ::bow::decSav(dat,rawDat);
-
- if (dat.fmtVer != ::bow::savVer) [[unlikely]] {
- bow_logErr("invalid format (%" PRIX64 ") of save file at \"%s\"",dat.fmtVer,pth);
-
- return ::bow::newSav(plDat);
- }
- if (dat.shipTyp > ::bow::maxShipId) [[unlikely]] {
- bow_logErr("invalid ship type (%" PRIX8 ")",dat.shipTyp);
-
- return ::bow::newSav(plDat);
- }
-
- plDat = ::bow::plDat {
- .tm = dat.tm,
- .sysId = dat.sysId,
- .ship = {
- .shipTyp = (::bow::ship)dat.shipTyp,
- .pos = {
- .x = dat.shipPosX,
- .y = dat.shipPosY,
- .z = dat.shipPosZ,
- },
- .rot = {
- .x = dat.shipRotX,
- .y = dat.shipRotY,
- .z = dat.shipRotZ,
- },
- .posVel = {
- .x = dat.shipPosVelX,
- .y = dat.shipPosVelY,
- .z = dat.shipPosVelZ,
- },
- .rotVel = {
- .x = dat.shipRotVelX,
- .y = dat.shipRotVelY,
- .z = dat.shipRotVelZ,
- },
- },
- };
- ::zp::cpy(plDat.nm,dat.cmdrNm,::bow::cmdrNmLen);
- plDat.nm[::bow::cmdrNmLen] = '\x00';
-
- ::bow::genDat(plDat);
-
- bow_log("welcome back, commander %s",plDat.nm);
-}
diff --git a/bowshock/source/sav/decSav.cxx b/bowshock/source/sav/decSav.cxx
deleted file mode 100644
index 2141c48..0000000
--- a/bowshock/source/sav/decSav.cxx
+++ /dev/null
@@ -1,29 +0,0 @@
-// Copyright 2022-2023 Gabriel Jensen.
-
-#include <bow/sav.hxx>
-
-#include <zp/mem>
-
-void ::bow::decSav(::bow::savDat & buf,::zp::i8 const * dat) noexcept {
- auto const decVal = [&dat]<typename typ>(typ & buf) {
- dat = ::zp::memcpy(&buf,dat,sizeof (buf)).src;
- };
-
- decVal(buf.fmtVer); // fmtver
- decVal(buf.cmdrNm); // cmdrnm
- decVal(buf.tm); // tm
- decVal(buf.sysId); // sysId
- decVal(buf.shipTyp); // shipTyp
- decVal(buf.shipPosX); // shipposx
- decVal(buf.shipPosY); // shipposy
- decVal(buf.shipPosZ); // shipposz
- decVal(buf.shipRotX); // shiprotx
- decVal(buf.shipRotY); // shiproty
- decVal(buf.shipRotZ); // shiprotz
- decVal(buf.shipPosVelX); // shipposVelx
- decVal(buf.shipPosVelY); // shipposVely
- decVal(buf.shipPosVelZ); // shipposVelz
- decVal(buf.shipRotVelX); // shiprotVelx
- decVal(buf.shipRotVelY); // shiprotVely
- decVal(buf.shipRotVelZ); // shiprotVelz
-}
diff --git a/bowshock/source/sav/decsav.cxx b/bowshock/source/sav/decsav.cxx
new file mode 100644
index 0000000..61d0f16
--- /dev/null
+++ b/bowshock/source/sav/decsav.cxx
@@ -0,0 +1,29 @@
+// Copyright 2022-2023 Gabriel Jensen.
+
+#include <bow/sav.hxx>
+
+#include <zp/mem>
+
+auto ::bow::decsav(::bow::savdat & buf,::zp::i8 const * dat) noexcept -> void {
+ auto const decVal = [&dat]<typename typ>(typ & buf) {
+ dat = ::zp::memcpy(&buf,dat,sizeof (buf)).src;
+ };
+
+ decVal(buf.fmtVer); // fmtver
+ decVal(buf.cmdnam); // cmdnam
+ decVal(buf.tim); // tim
+ decVal(buf.sysidt); // sysidt
+ decVal(buf.shptyp); // shptyp
+ decVal(buf.shpposx); // shpposx
+ decVal(buf.shpposy); // shpposy
+ decVal(buf.shpposz); // shpposz
+ decVal(buf.shprotx); // shprotx
+ decVal(buf.shproty); // shproty
+ decVal(buf.shprotz); // shprotz
+ decVal(buf.shpposvelx); // shpposvelx
+ decVal(buf.shpposvely); // shpposvely
+ decVal(buf.shpposvelz); // shpposvelz
+ decVal(buf.shprotvelx); // shprotvelx
+ decVal(buf.shprotvely); // shprotvely
+ decVal(buf.shprotvelz); // shprotvelz
+}
diff --git a/bowshock/source/sav/encSav.cxx b/bowshock/source/sav/encSav.cxx
deleted file mode 100644
index cefd92f..0000000
--- a/bowshock/source/sav/encSav.cxx
+++ /dev/null
@@ -1,29 +0,0 @@
-// Copyright 2022-2023 Gabriel Jensen.
-
-#include <bow/sav.hxx>
-
-#include <zp/mem>
-
-void ::bow::encSav(::zp::i8 * buf,::bow::savDat const & dat) noexcept {
- auto const encVal = [&buf]<typename typ>(typ const & val) {
- buf = ::zp::memcpy(buf,&val,sizeof (val)).dst;
- };
-
- encVal(dat.fmtVer); // fmtver
- encVal(dat.cmdrNm); // cmdrnm
- encVal(dat.tm); // tm
- encVal(dat.sysId); // sysid
- encVal(dat.shipTyp); // shiptyp
- encVal(dat.shipPosX); // shipposx
- encVal(dat.shipPosY); // shipposy
- encVal(dat.shipPosZ); // shipposz
- encVal(dat.shipRotX); // shiprotx
- encVal(dat.shipRotY); // shiproty
- encVal(dat.shipRotZ); // shiprotz
- encVal(dat.shipPosVelX); // shipposelx
- encVal(dat.shipPosVelY); // shipposely
- encVal(dat.shipPosVelZ); // shipposelz
- encVal(dat.shipRotVelX); // shiprotelx
- encVal(dat.shipRotVelY); // shiprotely
- encVal(dat.shipRotVelZ); // shiprotelz
-}
diff --git a/bowshock/source/sav/encsav.cxx b/bowshock/source/sav/encsav.cxx
new file mode 100644
index 0000000..aa66fde
--- /dev/null
+++ b/bowshock/source/sav/encsav.cxx
@@ -0,0 +1,29 @@
+// Copyright 2022-2023 Gabriel Jensen.
+
+#include <bow/sav.hxx>
+
+#include <zp/mem>
+
+auto ::bow::encsav(::zp::i8 * buf,::bow::savdat const & dat) noexcept -> void {
+ auto const encVal = [&buf]<typename typ>(typ const & val) {
+ buf = ::zp::memcpy(buf,&val,sizeof (val)).dst;
+ };
+
+ encVal(dat.fmtVer); // fmtver
+ encVal(dat.cmdnam); // cmdnam
+ encVal(dat.tim); // tim
+ encVal(dat.sysidt); // sysidt
+ encVal(dat.shptyp); // shptyp
+ encVal(dat.shpposx); // shpposx
+ encVal(dat.shpposy); // shpposy
+ encVal(dat.shpposz); // shpposz
+ encVal(dat.shprotx); // shprotx
+ encVal(dat.shproty); // shproty
+ encVal(dat.shprotz); // shprotz
+ encVal(dat.shpposvelx); // shpposelx
+ encVal(dat.shpposvely); // shpposely
+ encVal(dat.shpposvelz); // shpposelz
+ encVal(dat.shprotvelx); // shprotelx
+ encVal(dat.shprotvely); // shprotely
+ encVal(dat.shprotvelz); // shprotelz
+}
diff --git a/bowshock/source/sav/genDat.cxx b/bowshock/source/sav/genDat.cxx
deleted file mode 100644
index 341d062..0000000
--- a/bowshock/source/sav/genDat.cxx
+++ /dev/null
@@ -1,12 +0,0 @@
-// Copyright 2022-2023 Gabriel Jensen.
-
-#include <bow/lgc.hxx>
-#include <bow/sav.hxx>
-
-void ::bow::genDat(::bow::plDat & dat) noexcept {
- bow_log("generating player data");
-
- dat.ship.typ = ::bow::objTyp::ship;
- dat.ship.mass = ::bow::shipMass(dat.ship.shipTyp);
- dat.zoom = 0x4p0;
-}
diff --git a/bowshock/source/sav/gendat.cxx b/bowshock/source/sav/gendat.cxx
new file mode 100644
index 0000000..f362b27
--- /dev/null
+++ b/bowshock/source/sav/gendat.cxx
@@ -0,0 +1,12 @@
+// Copyright 2022-2023 Gabriel Jensen.
+
+#include <bow/lgc.hxx>
+#include <bow/sav.hxx>
+
+auto ::bow::gendat(::bow::pldat & dat) noexcept -> void {
+ bow_log("generating player data");
+
+ dat.shp.typ = ::bow::objtyp::shp;
+ dat.shp.mas = ::bow::shpmas(dat.shp.shptyp);
+ dat.zom = 0x4p0;
+}
diff --git a/bowshock/source/sav/newSav.cxx b/bowshock/source/sav/newsav.cxx
index 62482b0..d00bf61 100644
--- a/bowshock/source/sav/newSav.cxx
+++ b/bowshock/source/sav/newsav.cxx
@@ -2,15 +2,15 @@
#include <bow/sav.hxx>
-void ::bow::newSav(::bow::plDat & dat) noexcept {
+auto ::bow::newsav(::bow::pldat & dat) noexcept -> void {
bow_log("generating new save file");
- dat = ::bow::plDat {
- .nm = "Caelum\x00\x00\x00\x00\x00\x00\x00\x00",
- .tm = 0x0u, // 256 julian years after the Unix Epoch.
- .sysId = 0x45u,
- .ship = {
- .shipTyp = ::bow::ship::aq,
+ dat = ::bow::pldat {
+ .nam = "Caelum\x00\x00\x00\x00\x00\x00\x00\x00",
+ .tim = 0x0u, // 256 julian years after the Unix Epoch.
+ .sysidt = 0x45u,
+ .shp = {
+ .shptyp = ::bow::shp::aqu,
.pos = {
.x = 0x0p0,
.y = 0x0p0,
@@ -33,7 +33,7 @@ void ::bow::newSav(::bow::plDat & dat) noexcept {
},
},
};
- ::bow::genDat(dat);
+ ::bow::gendat(dat);
- bow_log("welcome, commander %s",dat.nm);
+ bow_log("welcome, commander %s",dat.nam);
}
diff --git a/bowshock/source/sav/sav.cxx b/bowshock/source/sav/sav.cxx
index 3974ced..f221292 100644
--- a/bowshock/source/sav/sav.cxx
+++ b/bowshock/source/sav/sav.cxx
@@ -6,41 +6,41 @@
#include <ly/io>
#include <zp/mem>
-void ::bow::sav(char const * const pth,::bow::plDat const & plDat) noexcept {
- bow_log("saving commander %s at \"%s\"",plDat.nm,pth);
+auto ::bow::sav(char const * const pth,::bow::pldat const & pldat) noexcept -> void {
+ bow_log("saving commander %s at \"%s\"",pldat.nam,pth);
::ly::fil fil;
::ly::err err = fil.crt(pth,0644u);
if (err != ::ly::err::ok) [[unlikely]] {
- bow_logErr("unable to open save file \"%s\"",pth);
- ::bow::abrt();
+ bow_logerr("unable to open save file \"%s\"",pth);
+ ::bow::abr();
}
- ::zp::i8 dat[::bow::savLen];
+ ::zp::i8 dat[::bow::savlen];
- ::bow::savDat savDat = {
- .fmtVer = ::bow::savVer,
- .tm = plDat.tm,
- .sysId = plDat.sysId,
- .shipTyp = static_cast<::zp::i8>(plDat.ship.shipTyp),
- .shipPosX = plDat.ship.pos.x,
- .shipPosY = plDat.ship.pos.y,
- .shipPosZ = plDat.ship.pos.z,
- .shipRotX = plDat.ship.rot.x,
- .shipRotY = plDat.ship.rot.y,
- .shipRotZ = plDat.ship.rot.z,
- .shipPosVelX = plDat.ship.posVel.x,
- .shipPosVelY = plDat.ship.posVel.y,
- .shipPosVelZ = plDat.ship.posVel.z,
- .shipRotVelX = plDat.ship.rotVel.x,
- .shipRotVelY = plDat.ship.rotVel.y,
- .shipRotVelZ = plDat.ship.rotVel.z,
+ ::bow::savdat savdat = {
+ .fmtVer = ::bow::savver,
+ .tim = pldat.tim,
+ .sysidt = pldat.sysidt,
+ .shptyp = static_cast<::zp::i8>(pldat.shp.shptyp),
+ .shpposx = pldat.shp.pos.x,
+ .shpposy = pldat.shp.pos.y,
+ .shpposz = pldat.shp.pos.z,
+ .shprotx = pldat.shp.rot.x,
+ .shproty = pldat.shp.rot.y,
+ .shprotz = pldat.shp.rot.z,
+ .shpposvelx = pldat.shp.posVel.x,
+ .shpposvely = pldat.shp.posVel.y,
+ .shpposvelz = pldat.shp.posVel.z,
+ .shprotvelx = pldat.shp.rotVel.x,
+ .shprotvely = pldat.shp.rotVel.y,
+ .shprotvelz = pldat.shp.rotVel.z,
};
- ::zp::cpy(savDat.cmdrNm,plDat.nm,sizeof (savDat.cmdrNm));
+ ::zp::cpy(savdat.cmdnam,pldat.nam,sizeof (savdat.cmdnam));
- ::bow::encSav(dat,savDat);
+ ::bow::encsav(dat,savdat);
- fil.wrt(dat,::bow::savLen);
+ fil.wrt(dat,::bow::savlen);
fil.cls();
}