summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--CHANGELOG.md5
-rw-r--r--README.md4
-rw-r--r--bowshock/source/client/ShaderProgram/compile_shader.cxx4
-rw-r--r--bowshock/source/client/ShaderProgram/constructor.cxx5
-rw-r--r--bowshock/source/logic/hull_mass.cxx4
-rw-r--r--bowshock/source/server/Server/destructor.cxx2
-rw-r--r--bowshock/source/server/ServerInstance/generate_system.cxx4
-rw-r--r--bowshock/source/server/ServerInstance/gravitate.cxx55
-rw-r--r--bowshock/source/server/ServerInstance/move.cxx5
-rw-r--r--bowshock/source/server/ServerInstance/simulate.cxx3
10 files changed, 69 insertions, 22 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 30a2f51..078fa6c 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -1,5 +1,10 @@
# 0.C.0
+*0.C.0-12*
+
+* Update readme
+* Improve commenting
+
*0.C.0-11*
* Fix readme
diff --git a/README.md b/README.md
index acd115f..b295824 100644
--- a/README.md
+++ b/README.md
@@ -1,4 +1,4 @@
-**BOWSHOCK 0.C.0-11**
+*BOWSHOCK 0.C.0-11*
![](https://mandelbrot.dk/logo/bowshock.svg)
@@ -36,7 +36,7 @@ Bowshock makes use of the following libraries:
* GLAD (see below)
* GLFW3
-For {fmt}, the appropriate package is `fmt` (Arch). For GLFW, it's either `glfw-wayland` (Arch) or `glfw-x11` (Arch).
+For {fmt}, the appropriate package is `fmt` (Arch). For GLFW, both `glfw-wayland` and `glfw-x11` (both Arch) may be used.
### GLAD
diff --git a/bowshock/source/client/ShaderProgram/compile_shader.cxx b/bowshock/source/client/ShaderProgram/compile_shader.cxx
index 40515e7..5f78e9f 100644
--- a/bowshock/source/client/ShaderProgram/compile_shader.cxx
+++ b/bowshock/source/client/ShaderProgram/compile_shader.cxx
@@ -12,6 +12,10 @@
using namespace ::std::literals::string_literals;
auto bow::ShaderProgram::compile_shader(::std::string const& name, ::bow::ShaderType const pretty_type) -> ::GLuint {
+ // Compile a shader according to the provided
+ // shader type. The path of the shader is
+ // calculated from the data directory path.
+
auto const type = [pretty_type]() -> ::GLuint {
using ::bow::ShaderType;
diff --git a/bowshock/source/client/ShaderProgram/constructor.cxx b/bowshock/source/client/ShaderProgram/constructor.cxx
index 95ad0af..4292ef1 100644
--- a/bowshock/source/client/ShaderProgram/constructor.cxx
+++ b/bowshock/source/client/ShaderProgram/constructor.cxx
@@ -9,6 +9,11 @@
using namespace ::std::literals::string_literals;
bow::ShaderProgram::ShaderProgram(::std::string const& name) {
+ // Compile a shader program. Currently, this means
+ // compiling a vertex shader and an equivalent
+ // fragment shader, both with the name "name". Cf.
+ // compile_shader for more information.
+
::bow::log("client"s, ::std::format("compiling shader program \"{}\"", name));
// Ignore exceptions:
diff --git a/bowshock/source/logic/hull_mass.cxx b/bowshock/source/logic/hull_mass.cxx
index 11479a5..00b7c54 100644
--- a/bowshock/source/logic/hull_mass.cxx
+++ b/bowshock/source/logic/hull_mass.cxx
@@ -3,6 +3,10 @@
#include <bow/logic.hxx>
auto bow::hull_mass(::bow::ShipType const ship) noexcept -> double {
+ // Calculate the default hull mass of a ship type.
+ // This is negated by the ammount of damages hull,
+ // whose mass is ignored.
+
using ::bow::ShipType;
double mass = 0x0p0;
diff --git a/bowshock/source/server/Server/destructor.cxx b/bowshock/source/server/Server/destructor.cxx
index 21c753e..ebf3e03 100644
--- a/bowshock/source/server/Server/destructor.cxx
+++ b/bowshock/source/server/Server/destructor.cxx
@@ -13,8 +13,6 @@ using namespace ::std::literals::string_literals;
this->thread->join();
delete this->stop_flag;
-
delete this->instance;
-
delete this->thread;
}
diff --git a/bowshock/source/server/ServerInstance/generate_system.cxx b/bowshock/source/server/ServerInstance/generate_system.cxx
index 8372161..4b60867 100644
--- a/bowshock/source/server/ServerInstance/generate_system.cxx
+++ b/bowshock/source/server/ServerInstance/generate_system.cxx
@@ -16,7 +16,9 @@ auto bow::ServerInstance::generate_system(::bow::ObjectRoot& system, ::std::uint
system.~ObjectRoot();
}
- // Note: The following code is only temporary;
+ // Nb.: The following code is only temporary.
+ // Currently, every system has only an Earth-Sol
+ // orbit.
system.add([]() -> ::bow::Star {
auto star = ::bow::Star();
diff --git a/bowshock/source/server/ServerInstance/gravitate.cxx b/bowshock/source/server/ServerInstance/gravitate.cxx
index 6dbad5d..b3cdd0a 100644
--- a/bowshock/source/server/ServerInstance/gravitate.cxx
+++ b/bowshock/source/server/ServerInstance/gravitate.cxx
@@ -6,12 +6,20 @@
#include <cmath>
namespace bow {
- static auto gravitate_single(::bow::Object& object, ::bow::Object const& par) noexcept -> void {
- auto const distance_x = par.position.x - object.position.x;
- auto const distance_y = par.position.y - object.position.y;
- auto const distance_z = par.position.z - object.position.z;
+ static auto gravitate_single(::bow::Object& object, ::bow::Object const& parent) noexcept -> void {
+ // Gravitate a single object to its parent (the
+ // force is unilateral).
+
+ // Calculate the distance between the two objects
+ // using the Pythagorean theorem:
+ // d = sqrt(a^2+b^2+c^2)
+ auto const distance_x = parent.position.x - object.position.x;
+ auto const distance_y = parent.position.y - object.position.y;
+ auto const distance_z = parent.position.z - object.position.z;
auto const distance = ::std::sqrt(distance_x * distance_x + distance_y * distance_y + distance_z * distance_z);
+ // Calculate the angle between the X and Y
+ // dimensions and the X and Z dimensions.
auto const angle_y = ::std::atan2(distance_y, distance_x);
auto const angle_z = ::std::atan2(distance_z, distance_x);
@@ -21,21 +29,34 @@ namespace bow {
// function branchless.
auto const no_overlap = ::std::abs(distance) != 0x0p0;
- auto const acceleration = par.mass/(distance * distance) * ::bow::GRAVITY_VALUE * static_cast<double>(no_overlap);
+ // Calculate the acceleration towards the parent
+ // object using Newtonian physics:
+ // a = (m/(s^2))G
+ auto const acceleration = parent.mass / (distance * distance) * ::bow::GRAVITY_VALUE * static_cast<double>(no_overlap);
+ // Calculate the gained velocity on the three
+ // dimensions using trigonometry:
+ // x = cos(theta_y)*a
+ // y = sin(theta_y)*a
+ // z = sin(theta_z)*a
auto const velocity_x = ::std::cos(angle_y) * acceleration;
auto const velocity_y = ::std::sin(angle_y) * acceleration;
auto const velocity_z = ::std::sin(angle_z) * acceleration;
+ // Append the gained velocities to the existing
+ // velocities.
object.positional_velocity.x += velocity_x;
object.positional_velocity.y += velocity_y;
object.positional_velocity.z += velocity_z;
}
- static void gravitate_pair(::bow::Object& obj0, ::bow::Object& obj1) noexcept {
- auto const distance_x = obj1.position.x - obj0.position.x;
- auto const distance_y = obj1.position.y - obj0.position.y;
- auto const distance_z = obj1.position.z - obj0.position.z;
+ static void gravitate_pair(::bow::Object& object0, ::bow::Object& object1) noexcept {
+ // Gravitate a pair of objects to each other (the
+ // force is mutual). Cf. gravitate_single.
+
+ auto const distance_x = object1.position.x - object0.position.x;
+ auto const distance_y = object1.position.y - object0.position.y;
+ auto const distance_z = object1.position.z - object0.position.z;
auto const distance = ::std::sqrt(distance_x * distance_x + distance_y * distance_y + distance_z * distance_z);
auto const angle_y = ::std::atan2(distance_y, distance_x);
@@ -44,8 +65,8 @@ namespace bow {
auto const no_overlap = ::std::abs(distance) != 0x0p0;
auto acceleration0 = ::bow::GRAVITY_VALUE / (distance * distance);
- auto const acceleration1 = acceleration0 * obj0.mass * static_cast<double>(no_overlap); // This is negative.
- acceleration0 *= obj1.mass * static_cast<double>(no_overlap);
+ auto const acceleration1 = acceleration0 * object0.mass * static_cast<double>(no_overlap); // This is negative.
+ acceleration0 *= object1.mass * static_cast<double>(no_overlap);
auto velocity_x0 = ::std::cos(angle_y);
auto velocity_y0 = ::std::sin(angle_y);
@@ -57,13 +78,13 @@ namespace bow {
velocity_y0 *= acceleration0;
velocity_z0 *= acceleration0;
- obj0.positional_velocity.x += velocity_x0;
- obj0.positional_velocity.y += velocity_y0;
- obj0.positional_velocity.z += velocity_z0;
+ object0.positional_velocity.x += velocity_x0;
+ object0.positional_velocity.y += velocity_y0;
+ object0.positional_velocity.z += velocity_z0;
- obj1.positional_velocity.x -= velocity_x1;
- obj1.positional_velocity.y -= velocity_y1;
- obj1.positional_velocity.z -= velocity_z1;
+ object1.positional_velocity.x -= velocity_x1;
+ object1.positional_velocity.y -= velocity_y1;
+ object1.positional_velocity.z -= velocity_z1;
}
}
diff --git a/bowshock/source/server/ServerInstance/move.cxx b/bowshock/source/server/ServerInstance/move.cxx
index ee16b0e..232523e 100644
--- a/bowshock/source/server/ServerInstance/move.cxx
+++ b/bowshock/source/server/ServerInstance/move.cxx
@@ -5,6 +5,11 @@
auto bow::ServerInstance::move(::bow::ObjectRoot& root) noexcept -> void {
for (auto& object: root) {
+ // Apply the velocities of each object to their
+ // position:
+ // x = x+v_x
+ // y = y+v_x
+ // z = z+v_x
object.position.x += object.positional_velocity.x;
object.position.y += object.positional_velocity.y;
object.position.z += object.positional_velocity.z;
diff --git a/bowshock/source/server/ServerInstance/simulate.cxx b/bowshock/source/server/ServerInstance/simulate.cxx
index 176aeb2..9e2f44f 100644
--- a/bowshock/source/server/ServerInstance/simulate.cxx
+++ b/bowshock/source/server/ServerInstance/simulate.cxx
@@ -13,6 +13,9 @@ auto bow::ServerInstance::simulate(::bow::ObjectRoot& system, ::std::uint64_t co
::bow::log("server"s, ::std::format("simulating for ({}) time units", duration));
for (auto i = UINT64_C(0x0); i <= duration; ++i) {
+ // Do a minimal simulation of the target system for
+ // n-units of time. This is for consistency when
+ // loading a system at the same in-game time.
this->gravitate(system);
this->move(system);
}