From 60238e95be9e5032ccc21f64b83f3aa771c4364a Mon Sep 17 00:00:00 2001 From: "C. J. Howard" Date: Thu, 14 Jan 2021 20:07:06 +0800 Subject: [PATCH] Rename ast namespace to astro, move astro namespace out of game folder, rename files in the astro namespace --- CMakeLists.txt | 1 + .../astronomy => astro}/apparent-size.cpp | 4 +-- .../astronomy => astro}/apparent-size.hpp | 10 +++--- src/astro/astro.hpp | 34 +++++++++++++++++++ src/{game/astronomy => astro}/blackbody.cpp | 4 +-- src/{game/astronomy => astro}/blackbody.hpp | 10 +++--- src/{game/astronomy => astro}/color-index.cpp | 4 +-- src/{game/astronomy => astro}/color-index.hpp | 10 +++--- .../constants.hpp} | 14 ++++---- .../coordinates.cpp} | 6 ++-- .../coordinates.hpp} | 10 +++--- .../orbit.cpp} | 6 ++-- .../orbit.hpp} | 10 +++--- .../components/celestial-body-component.hpp | 8 ++--- src/ecs/components/orbit-component.hpp | 8 ++--- src/ecs/ecs.hpp | 2 ++ src/ecs/systems/astronomy-system.cpp | 14 ++++---- src/ecs/systems/solar-system.cpp | 10 +++--- src/ecs/systems/weather-system.cpp | 4 +-- 19 files changed, 104 insertions(+), 65 deletions(-) rename src/{game/astronomy => astro}/apparent-size.cpp (96%) rename src/{game/astronomy => astro}/apparent-size.hpp (86%) create mode 100644 src/astro/astro.hpp rename src/{game/astronomy => astro}/blackbody.cpp (97%) rename src/{game/astronomy => astro}/blackbody.hpp (88%) rename src/{game/astronomy => astro}/color-index.cpp (96%) rename src/{game/astronomy => astro}/color-index.hpp (86%) rename src/{game/astronomy/astronomical-constants.hpp => astro/constants.hpp} (75%) rename src/{game/astronomy/celestial-coordinates.cpp => astro/coordinates.cpp} (98%) rename src/{game/astronomy/celestial-coordinates.hpp => astro/coordinates.hpp} (95%) rename src/{game/astronomy/celestial-mechanics.cpp => astro/orbit.cpp} (97%) rename src/{game/astronomy/celestial-mechanics.hpp => astro/orbit.hpp} (92%) diff --git a/CMakeLists.txt b/CMakeLists.txt index d4aa351..bc40e61 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -14,6 +14,7 @@ find_package(SDL2 REQUIRED COMPONENTS SDL2::SDL2-static SDL2::SDL2main CONFIG) find_package(OpenAL REQUIRED CONFIG) find_library(physfs REQUIRED NAMES physfs-static PATHS "${CMAKE_PREFIX_PATH}/lib") + # Determine dependencies set(STATIC_LIBS dr_wav diff --git a/src/game/astronomy/apparent-size.cpp b/src/astro/apparent-size.cpp similarity index 96% rename from src/game/astronomy/apparent-size.cpp rename to src/astro/apparent-size.cpp index e704783..159986c 100644 --- a/src/game/astronomy/apparent-size.cpp +++ b/src/astro/apparent-size.cpp @@ -20,7 +20,7 @@ #include "apparent-size.hpp" #include -namespace ast +namespace astro { double find_angular_radius(double radius, double distance) @@ -28,4 +28,4 @@ double find_angular_radius(double radius, double distance) return std::asin(radius / distance); } -} // namespace ast +} // namespace astro diff --git a/src/game/astronomy/apparent-size.hpp b/src/astro/apparent-size.hpp similarity index 86% rename from src/game/astronomy/apparent-size.hpp rename to src/astro/apparent-size.hpp index f43c615..13d1aae 100644 --- a/src/game/astronomy/apparent-size.hpp +++ b/src/astro/apparent-size.hpp @@ -17,10 +17,10 @@ * along with Antkeeper source code. If not, see . */ -#ifndef ANTKEEPER_APPARENT_SIZE_HPP -#define ANTKEEPER_APPARENT_SIZE_HPP +#ifndef ANTKEEPER_ASTRO_APPARENT_SIZE_HPP +#define ANTKEEPER_ASTRO_APPARENT_SIZE_HPP -namespace ast +namespace astro { /** @@ -32,6 +32,6 @@ namespace ast */ double find_angular_radius(double radius, double distance); -} // namespace ast +} // namespace astro -#endif // ANTKEEPER_APPARENT_SIZE_HPP +#endif // ANTKEEPER_ASTRO_APPARENT_SIZE_HPP diff --git a/src/astro/astro.hpp b/src/astro/astro.hpp new file mode 100644 index 0000000..f818809 --- /dev/null +++ b/src/astro/astro.hpp @@ -0,0 +1,34 @@ +/* + * Copyright (C) 2021 Christopher J. Howard + * + * This file is part of Antkeeper source code. + * + * Antkeeper source code is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Antkeeper source code is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Antkeeper source code. If not, see . + */ + +#ifndef ANTKEEPER_ASTRO_HPP +#define ANTKEEPER_ASTRO_HPP + +/// Astronomy/astrophysics +namespace astro {} + +#include "apparent-size.hpp" +#include "blackbody.hpp" +#include "coordinates.hpp" +#include "color-index.hpp" +#include "constants.hpp" +#include "coordinates.hpp" +#include "orbit.hpp" + +#endif // ANTKEEPER_ASTRO_HPP diff --git a/src/game/astronomy/blackbody.cpp b/src/astro/blackbody.cpp similarity index 97% rename from src/game/astronomy/blackbody.cpp rename to src/astro/blackbody.cpp index 7542fd4..fcc11bd 100644 --- a/src/game/astronomy/blackbody.cpp +++ b/src/astro/blackbody.cpp @@ -20,7 +20,7 @@ #include "blackbody.hpp" #include -namespace ast +namespace astro { /// Transforms colors from CIE XYZ to linear RGB @@ -51,4 +51,4 @@ double3 blackbody(double t) return rgb / std::max(rgb.x, std::max(rgb.y, rgb.z)); } -} // namespace ast +} // namespace astro diff --git a/src/game/astronomy/blackbody.hpp b/src/astro/blackbody.hpp similarity index 88% rename from src/game/astronomy/blackbody.hpp rename to src/astro/blackbody.hpp index bf5450e..8731bdc 100644 --- a/src/game/astronomy/blackbody.hpp +++ b/src/astro/blackbody.hpp @@ -17,12 +17,12 @@ * along with Antkeeper source code. If not, see . */ -#ifndef ANTKEEPER_BLACKBODY_HPP -#define ANTKEEPER_BLACKBODY_HPP +#ifndef ANTKEEPER_ASTRO_BLACKBODY_HPP +#define ANTKEEPER_ASTRO_BLACKBODY_HPP #include "utility/fundamental-types.hpp" -namespace ast +namespace astro { /** @@ -37,6 +37,6 @@ namespace ast */ double3 blackbody(double t); -} // namespace ast +} // namespace astro -#endif // ANTKEEPER_BLACKBODY_HPP +#endif // ANTKEEPER_ASTRO_BLACKBODY_HPP diff --git a/src/game/astronomy/color-index.cpp b/src/astro/color-index.cpp similarity index 96% rename from src/game/astronomy/color-index.cpp rename to src/astro/color-index.cpp index b76ebc2..c0e09b3 100644 --- a/src/game/astronomy/color-index.cpp +++ b/src/astro/color-index.cpp @@ -19,7 +19,7 @@ #include "color-index.hpp" -namespace ast +namespace astro { double bv_to_k(double bv) @@ -27,4 +27,4 @@ double bv_to_k(double bv) return 4600.0 * (1.0 / (0.92 * bv + 1.7) + 1.0 / (0.92 * bv + 0.62)); } -} // namespace ast +} // namespace astro diff --git a/src/game/astronomy/color-index.hpp b/src/astro/color-index.hpp similarity index 86% rename from src/game/astronomy/color-index.hpp rename to src/astro/color-index.hpp index 1a698dc..682fae7 100644 --- a/src/game/astronomy/color-index.hpp +++ b/src/astro/color-index.hpp @@ -17,10 +17,10 @@ * along with Antkeeper source code. If not, see . */ -#ifndef ANTKEEPER_COLOR_INDEX_HPP -#define ANTKEEPER_COLOR_INDEX_HPP +#ifndef ANTKEEPER_ASTRO_COLOR_INDEX_HPP +#define ANTKEEPER_ASTRO_COLOR_INDEX_HPP -namespace ast +namespace astro { /** @@ -33,6 +33,6 @@ namespace ast */ double bv_to_k(double bv); -} // namespace ast +} // namespace astro -#endif // ANTKEEPER_COLOR_INDEX_HPP +#endif // ANTKEEPER_ASTRO_COLOR_INDEX_HPP diff --git a/src/game/astronomy/astronomical-constants.hpp b/src/astro/constants.hpp similarity index 75% rename from src/game/astronomy/astronomical-constants.hpp rename to src/astro/constants.hpp index cafe491..7aceb8f 100644 --- a/src/game/astronomy/astronomical-constants.hpp +++ b/src/astro/constants.hpp @@ -17,14 +17,16 @@ * along with Antkeeper source code. If not, see . */ -#ifndef ANTKEEPER_ASTRONOMICAL_CONSTANTS_HPP -#define ANTKEEPER_ASTRONOMICAL_CONSTANTS_HPP +#ifndef ANTKEEPER_ASTRO_CONSTANTS_HPP +#define ANTKEEPER_ASTRO_CONSTANTS_HPP -namespace ast +namespace astro { -static constexpr double km_per_au = 6.68459e-9; +/// Kilometers per astronomical unit +template +constexpr T km_per_au = 6.68459e-9; -} // namespace ast +} // namespace astro -#endif // ANTKEEPER_ASTRONOMICAL_CONSTANTS_HPP +#endif // ANTKEEPER_ASTRO_CONSTANTS_HPP diff --git a/src/game/astronomy/celestial-coordinates.cpp b/src/astro/coordinates.cpp similarity index 98% rename from src/game/astronomy/celestial-coordinates.cpp rename to src/astro/coordinates.cpp index 9d17252..7bfe6e8 100644 --- a/src/game/astronomy/celestial-coordinates.cpp +++ b/src/astro/coordinates.cpp @@ -17,10 +17,10 @@ * along with Antkeeper source code. If not, see . */ -#include "celestial-coordinates.hpp" +#include "coordinates.hpp" #include -namespace ast +namespace astro { double3 rectangular_to_spherical(const double3& rectangular) @@ -135,4 +135,4 @@ double3x3 horizontal_to_ecliptic(double ecl, double lat, double lst) }; } -} // namespace ast +} // namespace astro diff --git a/src/game/astronomy/celestial-coordinates.hpp b/src/astro/coordinates.hpp similarity index 95% rename from src/game/astronomy/celestial-coordinates.hpp rename to src/astro/coordinates.hpp index 9b3c0ff..5e76468 100644 --- a/src/game/astronomy/celestial-coordinates.hpp +++ b/src/astro/coordinates.hpp @@ -17,12 +17,12 @@ * along with Antkeeper source code. If not, see . */ -#ifndef ANTKEEPER_CELESTIAL_COORDINATES_HPP -#define ANTKEEPER_CELESTIAL_COORDINATES_HPP +#ifndef ANTKEEPER_ASTRO_COORDINATES_HPP +#define ANTKEEPER_ASTRO_COORDINATES_HPP #include "utility/fundamental-types.hpp" -namespace ast +namespace astro { /** @@ -103,6 +103,6 @@ constexpr double3x3 horizontal_to_right_handed = 0.0, -1.0, 0.0 }; -} // namespace ast +} // namespace astro -#endif // ANTKEEPER_CELESTIAL_COORDINATES_HPP +#endif // ANTKEEPER_ASTRO_COORDINATES_HPP diff --git a/src/game/astronomy/celestial-mechanics.cpp b/src/astro/orbit.cpp similarity index 97% rename from src/game/astronomy/celestial-mechanics.cpp rename to src/astro/orbit.cpp index 618967d..c157384 100644 --- a/src/game/astronomy/celestial-mechanics.cpp +++ b/src/astro/orbit.cpp @@ -17,11 +17,11 @@ * along with Antkeeper source code. If not, see . */ -#include "celestial-mechanics.hpp" +#include "orbit.hpp" #include "math/angles.hpp" #include -namespace ast +namespace astro { double solve_kepler(double ec, double ma, double tolerance, std::size_t iterations) @@ -75,4 +75,4 @@ double3 orbital_elements_to_ecliptic(const orbital_elements& elements, double ke }; } -} // namespace ast +} // namespace astro diff --git a/src/game/astronomy/celestial-mechanics.hpp b/src/astro/orbit.hpp similarity index 92% rename from src/game/astronomy/celestial-mechanics.hpp rename to src/astro/orbit.hpp index 5cf181b..594a8a5 100644 --- a/src/game/astronomy/celestial-mechanics.hpp +++ b/src/astro/orbit.hpp @@ -17,12 +17,12 @@ * along with Antkeeper source code. If not, see . */ -#ifndef ANTKEEPER_CELESTIAL_MECHANICS_HPP -#define ANTKEEPER_CELESTIAL_MECHANICS_HPP +#ifndef ANTKEEPER_ASTRO_ORBIT_HPP +#define ANTKEEPER_ASTRO_ORBIT_HPP #include "utility/fundamental-types.hpp" -namespace ast +namespace astro { /** @@ -70,6 +70,6 @@ double solve_kepler(double ec, double ma, double tolerance, std::size_t iteratio */ double3 orbital_elements_to_ecliptic(const orbital_elements& elements, double ke_tolerance, std::size_t ke_iterations); -} // namespace ast +} // namespace astro -#endif // ANTKEEPER_CELESTIAL_MECHANICS_HPP +#endif // ANTKEEPER_ASTRO_ORBIT_HPP diff --git a/src/ecs/components/celestial-body-component.hpp b/src/ecs/components/celestial-body-component.hpp index 0faddce..3119ce0 100644 --- a/src/ecs/components/celestial-body-component.hpp +++ b/src/ecs/components/celestial-body-component.hpp @@ -20,7 +20,7 @@ #ifndef ANTKEEPER_ECS_CELESTIAL_BODY_COMPONENT_HPP #define ANTKEEPER_ECS_CELESTIAL_BODY_COMPONENT_HPP -#include "game/astronomy/celestial-mechanics.hpp" +#include "astro/orbit.hpp" #include "utility/fundamental-types.hpp" #include "math/quaternion-type.hpp" @@ -28,9 +28,9 @@ namespace ecs { struct celestial_body_component { - ast::orbital_elements orbital_elements; - ast::orbital_elements orbital_rate; - ast::orbital_state orbital_state; + astro::orbital_elements orbital_elements; + astro::orbital_elements orbital_rate; + astro::orbital_state orbital_state; double3 position; double3 velocity; diff --git a/src/ecs/components/orbit-component.hpp b/src/ecs/components/orbit-component.hpp index 7e6089a..5f933f6 100644 --- a/src/ecs/components/orbit-component.hpp +++ b/src/ecs/components/orbit-component.hpp @@ -20,15 +20,15 @@ #ifndef ANTKEEPER_ECS_ORBIT_COMPONENT_HPP #define ANTKEEPER_ECS_ORBIT_COMPONENT_HPP -#include "game/astronomy/celestial-mechanics.hpp" +#include "astro/orbit.hpp" namespace ecs { struct orbit_component { - ast::orbital_elements elements; - ast::orbital_elements rate; - ast::orbital_state state; + astro::orbital_elements elements; + astro::orbital_elements rate; + astro::orbital_state state; }; } // namespace ecs diff --git a/src/ecs/ecs.hpp b/src/ecs/ecs.hpp index f1d10dc..47ec38b 100644 --- a/src/ecs/ecs.hpp +++ b/src/ecs/ecs.hpp @@ -24,6 +24,8 @@ namespace ecs {} #include "archetype.hpp" +#include "commands.hpp" #include "entity.hpp" +#include "registry.hpp" #endif // ANTKEEPER_ECS_HPP diff --git a/src/ecs/systems/astronomy-system.cpp b/src/ecs/systems/astronomy-system.cpp index c2f9478..5a65e6d 100644 --- a/src/ecs/systems/astronomy-system.cpp +++ b/src/ecs/systems/astronomy-system.cpp @@ -18,8 +18,8 @@ */ #include "ecs/systems/astronomy-system.hpp" -#include "game/astronomy/celestial-coordinates.hpp" -#include "game/astronomy/apparent-size.hpp" +#include "astro/coordinates.hpp" +#include "astro/apparent-size.hpp" #include "ecs/components/celestial-body-component.hpp" #include "ecs/components/transform-component.hpp" #include "renderer/passes/sky-pass.hpp" @@ -56,15 +56,15 @@ void astronomy_system::update(double t, double dt) horizontal.z -= observer_location[0]; // Convert rectangular horizontal coordinates to spherical - double3 spherical = ast::rectangular_to_spherical(horizontal); + double3 spherical = astro::rectangular_to_spherical(horizontal); spherical.z -= math::pi; // Find angular radius - double angular_radius = ast::find_angular_radius(body.radius, spherical.x); + double angular_radius = astro::find_angular_radius(body.radius, spherical.x); // Transform into local right-handed coordinates - double3 translation = ast::horizontal_to_right_handed * horizontal; - double3x3 rotation = ast::horizontal_to_right_handed * ecliptic_to_horizontal; + double3 translation = astro::horizontal_to_right_handed * horizontal; + double3x3 rotation = astro::horizontal_to_right_handed * ecliptic_to_horizontal; // Set local transform of transform component transform.local.translation = math::type_cast(translation); @@ -145,7 +145,7 @@ void astronomy_system::update_sidereal_time() void astronomy_system::update_ecliptic_to_horizontal() { - ecliptic_to_horizontal = ast::ecliptic_to_horizontal(obliquity, observer_location[1], lst); + ecliptic_to_horizontal = astro::ecliptic_to_horizontal(obliquity, observer_location[1], lst); } } // namespace ecs diff --git a/src/ecs/systems/solar-system.cpp b/src/ecs/systems/solar-system.cpp index 4bd9596..fd4e3c4 100644 --- a/src/ecs/systems/solar-system.cpp +++ b/src/ecs/systems/solar-system.cpp @@ -18,9 +18,9 @@ */ #include "ecs/systems/solar-system.hpp" -#include "game/astronomy/celestial-coordinates.hpp" -#include "game/astronomy/celestial-mechanics.hpp" -#include "game/astronomy/astronomical-constants.hpp" +#include "astro/coordinates.hpp" +#include "astro/orbit.hpp" +#include "astro/constants.hpp" #include "ecs/components/celestial-body-component.hpp" #include "ecs/entity.hpp" @@ -45,7 +45,7 @@ void solar_system::update(double t, double dt) registry.view().each( [&](ecs::entity entity, auto& body) { - ast::orbital_elements elements = body.orbital_elements; + astro::orbital_elements elements = body.orbital_elements; elements.a += body.orbital_rate.a * universal_time; elements.ec += body.orbital_rate.ec * universal_time; elements.w += body.orbital_rate.w * universal_time; @@ -54,7 +54,7 @@ void solar_system::update(double t, double dt) elements.om += body.orbital_rate.om * universal_time; // Calculate ecliptic orbital position - body.orbital_state.r = ast::orbital_elements_to_ecliptic(elements, ke_tolerance, ke_iterations); + body.orbital_state.r = astro::orbital_elements_to_ecliptic(elements, ke_tolerance, ke_iterations); }); } diff --git a/src/ecs/systems/weather-system.cpp b/src/ecs/systems/weather-system.cpp index bf93321..cf37ae8 100644 --- a/src/ecs/systems/weather-system.cpp +++ b/src/ecs/systems/weather-system.cpp @@ -25,8 +25,8 @@ #include "renderer/passes/material-pass.hpp" #include "utility/gamma.hpp" #include "resources/image.hpp" -#include "game/astronomy/celestial-coordinates.hpp" -#include "game/astronomy/celestial-mechanics.hpp" +#include "astro/coordinates.hpp" +#include "astro/orbit.hpp" #include namespace ecs {