summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--CHANGELOG.txt5
-rw-r--r--bowshock/GNUmakefile5
-rw-r--r--bowshock/include/bow/bs.h8
-rw-r--r--bowshock/include/bow/gfx.h16
-rw-r--r--bowshock/include/bow/lgc.h4
-rw-r--r--bowshock/source/bs/init.c2
-rw-r--r--bowshock/source/bs/loop.c10
-rw-r--r--bowshock/source/bs/quit.c7
-rw-r--r--bowshock/source/gfx/initgfx.c28
-rw-r--r--bowshock/source/lgc/grav.c2
-rw-r--r--bowshock/source/lgc/mv.c2
11 files changed, 77 insertions, 12 deletions
diff --git a/CHANGELOG.txt b/CHANGELOG.txt
index a9a7163..50b21f7 100644
--- a/CHANGELOG.txt
+++ b/CHANGELOG.txt
@@ -1,3 +1,8 @@
+# 3
+
+* Fix incorrect symbol names;
+* Add basic graphics instancing;
+
# 2
* Rename project to Bowshock (from Procyon);
diff --git a/bowshock/GNUmakefile b/bowshock/GNUmakefile
index 9fe2af3..c9ed20d 100644
--- a/bowshock/GNUmakefile
+++ b/bowshock/GNUmakefile
@@ -18,8 +18,10 @@ CFLAGS := \
endif
LDLIBS := \
+ -lGL \
-lflux \
- -lm \
+ -lglfw \
+ -lm \
-lzap
OBJS := \
@@ -28,6 +30,7 @@ OBJS := \
source/bs/initdat.o \
source/bs/loop.o \
source/bs/quit.o \
+ source/gfx/initgfx.o \
source/info/shipmass.o \
source/lgc/grav.o \
source/lgc/mv.o
diff --git a/bowshock/include/bow/bs.h b/bowshock/include/bow/bs.h
index fe5ecaa..c0a82fa 100644
--- a/bowshock/include/bow/bs.h
+++ b/bowshock/include/bow/bs.h
@@ -70,6 +70,10 @@ typedef enum {
bow_star_z, // white hole
} bow_star;
+typedef enum {
+ bow_star_cor, // coriolis
+} bow_stat;
+
typedef struct {
double x;
double y;
@@ -79,11 +83,13 @@ typedef struct {
typedef struct {
bow_objtyp typ;
bow_xyz pos;
- bow_xyz rot; // rad
+ bow_xyz rot; // radians
bow_xyz vel;
double mass;
union {
bow_ship shiptyp;
+ bow_star startyp;
+ bow_stat stattyp;
};
} bow_obj;
diff --git a/bowshock/include/bow/gfx.h b/bowshock/include/bow/gfx.h
new file mode 100644
index 0000000..5aa8298
--- /dev/null
+++ b/bowshock/include/bow/gfx.h
@@ -0,0 +1,16 @@
+#if !defined(bow_hdr_gfx)
+#define bow_hdr_gfx
+
+#include <bow/bs.h>
+
+#include <GLFW/glfw3.h>
+
+extern struct {
+ GLFWwindow * win;
+ int frmbufw;
+ int frmbufh;
+} bow_gfxdat;
+
+void bow_initgfx(void);
+
+#endif
diff --git a/bowshock/include/bow/lgc.h b/bowshock/include/bow/lgc.h
index 416dcf3..10a139d 100644
--- a/bowshock/include/bow/lgc.h
+++ b/bowshock/include/bow/lgc.h
@@ -3,9 +3,7 @@
#include <bow/bs.h>
-#define bow_dist(x,y,z) sqrt(pow(x,0x2.0p0)+pow(y,0x2.0p0)+pow(z,0x2.0p0))
-
-constexpr double bow_gravconst = 0x1.0p0; // gravitational constant
+constexpr double bow_gravconst = 0x1.0p-2; // gravitational constant
void bow_grav(bow_obj * obj,bow_obj const * par);
void bow_mv( bow_obj * obj);
diff --git a/bowshock/source/bs/init.c b/bowshock/source/bs/init.c
index 22d16e6..8fabb90 100644
--- a/bowshock/source/bs/init.c
+++ b/bowshock/source/bs/init.c
@@ -1,5 +1,6 @@
#define bow_sym "init"
+#include <bow/gfx.h>
#include <bow/sav.h>
#include <flux.h>
@@ -11,6 +12,7 @@ bow_stat bow_loop(bow_playdat * playdat);
flux_wrstr(flux_deflog,"\x1B[0m\x1B[1mBowshock\x1B[0m \u2013 Copyright 2022\u20102023, \x1B[1mGabriel Jensen\x1B[0m.\n\n");
bow_log("initialising");
bow_initdat(&playdat);
+ bow_initgfx();
bow_loop(&playdat);
bow_quit(bow_stat_ok);
}
diff --git a/bowshock/source/bs/loop.c b/bowshock/source/bs/loop.c
index f139fcd..1ca5238 100644
--- a/bowshock/source/bs/loop.c
+++ b/bowshock/source/bs/loop.c
@@ -1,8 +1,10 @@
#define bow_sym "loop"
+#include <bow/gfx.h>
#include <bow/lgc.h>
#include <bow/sav.h>
+#include <GLFW/glfw3.h>
#include <inttypes.h>
#include <math.h>
#include <zap/mem.h>
@@ -35,7 +37,9 @@ bow_stat bow_loop(bow_playdat * playdatptr) {
playdat.ship.pos.z = 0x100.0p0;
star0.vel.x = sqrt(bow_gravconst*star1.mass/0x100.0p0)/0x2.0p0; // orbital speed
star1.vel.x = -sqrt(bow_gravconst*star0.mass/0x100.0p0)/0x2.0p0; // orbital speed
- for (zap_i04 i = 0x0u;;) {
+ bool stop = false;
+ for (zap_i04 i = 0x0u;!stop;) {
+ if (glfwWindowShouldClose(bow_gfxdat.win)) break;
// Calculate gravitations:
bow_grav(&star0,&star1);
bow_grav(&star1,&star0);
@@ -51,9 +55,7 @@ bow_stat bow_loop(bow_playdat * playdatptr) {
fprintf(log,"%f\t%f\t%f\n",star1.pos.x,star1.pos.y,star1.pos.z);
fprintf(log,"%f\t%f\t%f\n",playdat.ship.pos.x,playdat.ship.pos.y,playdat.ship.pos.z);
// Check tick number:
- if (i++ == 0x7Fu) {
- break;
- }
+ if (i++ == 0x7Fu) break;
}
fclose(log);
zap_cp(playdatptr,&playdat,sizeof (playdat));
diff --git a/bowshock/source/bs/quit.c b/bowshock/source/bs/quit.c
index 65b4a44..9443ac3 100644
--- a/bowshock/source/bs/quit.c
+++ b/bowshock/source/bs/quit.c
@@ -1,13 +1,17 @@
#define bow_sym "quit"
+#include <bow/gfx.h>
#include <bow/info.h>
+#include <GLFW/glfw3.h>
#include <flux.h>
#include <stdio.h>
#include <stdlib.h>
void bow_quit(bow_stat const stat) {
- bow_log("goodbye");
+ bow_log("quitting");
+ glfwDestroyWindow(bow_gfxdat.win);
+ glfwTerminate();
int sysstat;
switch (stat) {
case bow_stat_err:
@@ -17,6 +21,7 @@ void bow_quit(bow_stat const stat) {
sysstat = EXIT_SUCCESS;
break;
}
+ bow_log("goodbye");
bow_log("exiting with code %i",sysstat);
exit(sysstat);
}
diff --git a/bowshock/source/gfx/initgfx.c b/bowshock/source/gfx/initgfx.c
new file mode 100644
index 0000000..a2bcfb0
--- /dev/null
+++ b/bowshock/source/gfx/initgfx.c
@@ -0,0 +1,28 @@
+#define bow_sym "initgfx"
+
+#include <bow/gfx.h>
+
+#include <GLFW/glfw3.h>
+
+typeof (bow_gfxdat) bow_gfxdat;
+
+void bow_initgfx(void) {
+ bow_log("initialising graphics");
+ if (!glfwInit()) {
+ bow_log("unable to initialise glfw");
+ bow_quit(bow_stat_err);
+ }
+ glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR,0x3);
+ glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR,0x0);
+ GLFWwindow * win = glfwCreateWindow(0x300,0x200,"Bowshock",nullptr,nullptr);
+ if (win == nullptr) {
+ bow_log("unable to open window");
+ bow_quit(bow_stat_err);
+ }
+ glfwMakeContextCurrent(win);
+ int frmbufw;
+ int frmbufh;
+ glfwGetFramebufferSize(win,&frmbufw,&frmbufh);
+ glViewport(0x0,0x0,frmbufw,frmbufh);
+ bow_gfxdat.win = win;
+}
diff --git a/bowshock/source/lgc/grav.c b/bowshock/source/lgc/grav.c
index f0ea290..0542b7e 100644
--- a/bowshock/source/lgc/grav.c
+++ b/bowshock/source/lgc/grav.c
@@ -13,7 +13,7 @@ void bow_grav(bow_obj * objptr,bow_obj const * parptr) {
double const distx = par.pos.x-obj.pos.x;
double const disty = par.pos.y-obj.pos.y;
double const distz = par.pos.z-obj.pos.z;
- double const dist = bow_dist(distx,disty,distz);
+ double const dist = sqrt(pow(distx,0x2.0p0)+pow(disty,0x2.0p0)+pow(distz,0x2.0p0));
double const acc = bow_gravconst*par.mass/pow(dist,2.0);
double const angy = atan2(disty,distx);
double const angz = atan2(distz,distx);
diff --git a/bowshock/source/lgc/mv.c b/bowshock/source/lgc/mv.c
index 046d7bd..5c8fcc0 100644
--- a/bowshock/source/lgc/mv.c
+++ b/bowshock/source/lgc/mv.c
@@ -1,4 +1,4 @@
-#define bow_sym "grav"
+#define bow_sym "mv"
#include <bow/lgc.h>