Browse Source

Rename ast namespace to astro, move astro namespace out of game folder, rename files in the astro namespace

master
C. J. Howard 3 years ago
parent
commit
60238e95be
19 changed files with 104 additions and 65 deletions
  1. +1
    -0
      CMakeLists.txt
  2. +2
    -2
      src/astro/apparent-size.cpp
  3. +5
    -5
      src/astro/apparent-size.hpp
  4. +34
    -0
      src/astro/astro.hpp
  5. +2
    -2
      src/astro/blackbody.cpp
  6. +5
    -5
      src/astro/blackbody.hpp
  7. +2
    -2
      src/astro/color-index.cpp
  8. +5
    -5
      src/astro/color-index.hpp
  9. +8
    -6
      src/astro/constants.hpp
  10. +3
    -3
      src/astro/coordinates.cpp
  11. +5
    -5
      src/astro/coordinates.hpp
  12. +3
    -3
      src/astro/orbit.cpp
  13. +5
    -5
      src/astro/orbit.hpp
  14. +4
    -4
      src/ecs/components/celestial-body-component.hpp
  15. +4
    -4
      src/ecs/components/orbit-component.hpp
  16. +2
    -0
      src/ecs/ecs.hpp
  17. +7
    -7
      src/ecs/systems/astronomy-system.cpp
  18. +5
    -5
      src/ecs/systems/solar-system.cpp
  19. +2
    -2
      src/ecs/systems/weather-system.cpp

+ 1
- 0
CMakeLists.txt View File

@ -14,6 +14,7 @@ find_package(SDL2 REQUIRED COMPONENTS SDL2::SDL2-static SDL2::SDL2main CONFIG)
find_package(OpenAL REQUIRED CONFIG) find_package(OpenAL REQUIRED CONFIG)
find_library(physfs REQUIRED NAMES physfs-static PATHS "${CMAKE_PREFIX_PATH}/lib") find_library(physfs REQUIRED NAMES physfs-static PATHS "${CMAKE_PREFIX_PATH}/lib")
# Determine dependencies # Determine dependencies
set(STATIC_LIBS set(STATIC_LIBS
dr_wav dr_wav

src/game/astronomy/apparent-size.cpp → src/astro/apparent-size.cpp View File

@ -20,7 +20,7 @@
#include "apparent-size.hpp" #include "apparent-size.hpp"
#include <cmath> #include <cmath>
namespace ast
namespace astro
{ {
double find_angular_radius(double radius, double distance) 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); return std::asin(radius / distance);
} }
} // namespace ast
} // namespace astro

src/game/astronomy/apparent-size.hpp → src/astro/apparent-size.hpp View File

@ -17,10 +17,10 @@
* along with Antkeeper source code. If not, see <http://www.gnu.org/licenses/>. * along with Antkeeper source code. If not, see <http://www.gnu.org/licenses/>.
*/ */
#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); double find_angular_radius(double radius, double distance);
} // namespace ast
} // namespace astro
#endif // ANTKEEPER_APPARENT_SIZE_HPP
#endif // ANTKEEPER_ASTRO_APPARENT_SIZE_HPP

+ 34
- 0
src/astro/astro.hpp View File

@ -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 <http://www.gnu.org/licenses/>.
*/
#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

src/game/astronomy/blackbody.cpp → src/astro/blackbody.cpp View File

@ -20,7 +20,7 @@
#include "blackbody.hpp" #include "blackbody.hpp"
#include <algorithm> #include <algorithm>
namespace ast
namespace astro
{ {
/// Transforms colors from CIE XYZ to linear RGB /// Transforms colors from CIE XYZ to linear RGB
@ -51,4 +51,4 @@ double3 blackbody(double t)
return rgb / std::max<double>(rgb.x, std::max<double>(rgb.y, rgb.z)); return rgb / std::max<double>(rgb.x, std::max<double>(rgb.y, rgb.z));
} }
} // namespace ast
} // namespace astro

src/game/astronomy/blackbody.hpp → src/astro/blackbody.hpp View File

@ -17,12 +17,12 @@
* along with Antkeeper source code. If not, see <http://www.gnu.org/licenses/>. * along with Antkeeper source code. If not, see <http://www.gnu.org/licenses/>.
*/ */
#ifndef ANTKEEPER_BLACKBODY_HPP
#define ANTKEEPER_BLACKBODY_HPP
#ifndef ANTKEEPER_ASTRO_BLACKBODY_HPP
#define ANTKEEPER_ASTRO_BLACKBODY_HPP
#include "utility/fundamental-types.hpp" #include "utility/fundamental-types.hpp"
namespace ast
namespace astro
{ {
/** /**
@ -37,6 +37,6 @@ namespace ast
*/ */
double3 blackbody(double t); double3 blackbody(double t);
} // namespace ast
} // namespace astro
#endif // ANTKEEPER_BLACKBODY_HPP
#endif // ANTKEEPER_ASTRO_BLACKBODY_HPP

src/game/astronomy/color-index.cpp → src/astro/color-index.cpp View File

@ -19,7 +19,7 @@
#include "color-index.hpp" #include "color-index.hpp"
namespace ast
namespace astro
{ {
double bv_to_k(double bv) 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)); return 4600.0 * (1.0 / (0.92 * bv + 1.7) + 1.0 / (0.92 * bv + 0.62));
} }
} // namespace ast
} // namespace astro

src/game/astronomy/color-index.hpp → src/astro/color-index.hpp View File

@ -17,10 +17,10 @@
* along with Antkeeper source code. If not, see <http://www.gnu.org/licenses/>. * along with Antkeeper source code. If not, see <http://www.gnu.org/licenses/>.
*/ */
#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); double bv_to_k(double bv);
} // namespace ast
} // namespace astro
#endif // ANTKEEPER_COLOR_INDEX_HPP
#endif // ANTKEEPER_ASTRO_COLOR_INDEX_HPP

src/game/astronomy/astronomical-constants.hpp → src/astro/constants.hpp View File

@ -17,14 +17,16 @@
* along with Antkeeper source code. If not, see <http://www.gnu.org/licenses/>. * along with Antkeeper source code. If not, see <http://www.gnu.org/licenses/>.
*/ */
#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 <typename T>
constexpr T km_per_au = 6.68459e-9;
} // namespace ast
} // namespace astro
#endif // ANTKEEPER_ASTRONOMICAL_CONSTANTS_HPP
#endif // ANTKEEPER_ASTRO_CONSTANTS_HPP

src/game/astronomy/celestial-coordinates.cpp → src/astro/coordinates.cpp View File

@ -17,10 +17,10 @@
* along with Antkeeper source code. If not, see <http://www.gnu.org/licenses/>. * along with Antkeeper source code. If not, see <http://www.gnu.org/licenses/>.
*/ */
#include "celestial-coordinates.hpp"
#include "coordinates.hpp"
#include <cmath> #include <cmath>
namespace ast
namespace astro
{ {
double3 rectangular_to_spherical(const double3& rectangular) 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

src/game/astronomy/celestial-coordinates.hpp → src/astro/coordinates.hpp View File

@ -17,12 +17,12 @@
* along with Antkeeper source code. If not, see <http://www.gnu.org/licenses/>. * along with Antkeeper source code. If not, see <http://www.gnu.org/licenses/>.
*/ */
#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" #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 0.0, -1.0, 0.0
}; };
} // namespace ast
} // namespace astro
#endif // ANTKEEPER_CELESTIAL_COORDINATES_HPP
#endif // ANTKEEPER_ASTRO_COORDINATES_HPP

src/game/astronomy/celestial-mechanics.cpp → src/astro/orbit.cpp View File

@ -17,11 +17,11 @@
* along with Antkeeper source code. If not, see <http://www.gnu.org/licenses/>. * along with Antkeeper source code. If not, see <http://www.gnu.org/licenses/>.
*/ */
#include "celestial-mechanics.hpp"
#include "orbit.hpp"
#include "math/angles.hpp" #include "math/angles.hpp"
#include <cmath> #include <cmath>
namespace ast
namespace astro
{ {
double solve_kepler(double ec, double ma, double tolerance, std::size_t iterations) 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

src/game/astronomy/celestial-mechanics.hpp → src/astro/orbit.hpp View File

@ -17,12 +17,12 @@
* along with Antkeeper source code. If not, see <http://www.gnu.org/licenses/>. * along with Antkeeper source code. If not, see <http://www.gnu.org/licenses/>.
*/ */
#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" #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); 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

+ 4
- 4
src/ecs/components/celestial-body-component.hpp View File

@ -20,7 +20,7 @@
#ifndef ANTKEEPER_ECS_CELESTIAL_BODY_COMPONENT_HPP #ifndef ANTKEEPER_ECS_CELESTIAL_BODY_COMPONENT_HPP
#define 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 "utility/fundamental-types.hpp"
#include "math/quaternion-type.hpp" #include "math/quaternion-type.hpp"
@ -28,9 +28,9 @@ namespace ecs {
struct celestial_body_component 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 position;
double3 velocity; double3 velocity;

+ 4
- 4
src/ecs/components/orbit-component.hpp View File

@ -20,15 +20,15 @@
#ifndef ANTKEEPER_ECS_ORBIT_COMPONENT_HPP #ifndef ANTKEEPER_ECS_ORBIT_COMPONENT_HPP
#define ANTKEEPER_ECS_ORBIT_COMPONENT_HPP #define ANTKEEPER_ECS_ORBIT_COMPONENT_HPP
#include "game/astronomy/celestial-mechanics.hpp"
#include "astro/orbit.hpp"
namespace ecs { namespace ecs {
struct orbit_component 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 } // namespace ecs

+ 2
- 0
src/ecs/ecs.hpp View File

@ -24,6 +24,8 @@
namespace ecs {} namespace ecs {}
#include "archetype.hpp" #include "archetype.hpp"
#include "commands.hpp"
#include "entity.hpp" #include "entity.hpp"
#include "registry.hpp"
#endif // ANTKEEPER_ECS_HPP #endif // ANTKEEPER_ECS_HPP

+ 7
- 7
src/ecs/systems/astronomy-system.cpp View File

@ -18,8 +18,8 @@
*/ */
#include "ecs/systems/astronomy-system.hpp" #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/celestial-body-component.hpp"
#include "ecs/components/transform-component.hpp" #include "ecs/components/transform-component.hpp"
#include "renderer/passes/sky-pass.hpp" #include "renderer/passes/sky-pass.hpp"
@ -56,15 +56,15 @@ void astronomy_system::update(double t, double dt)
horizontal.z -= observer_location[0]; horizontal.z -= observer_location[0];
// Convert rectangular horizontal coordinates to spherical // Convert rectangular horizontal coordinates to spherical
double3 spherical = ast::rectangular_to_spherical(horizontal);
double3 spherical = astro::rectangular_to_spherical(horizontal);
spherical.z -= math::pi<double>; spherical.z -= math::pi<double>;
// Find angular radius // 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 // 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 // Set local transform of transform component
transform.local.translation = math::type_cast<float>(translation); transform.local.translation = math::type_cast<float>(translation);
@ -145,7 +145,7 @@ void astronomy_system::update_sidereal_time()
void astronomy_system::update_ecliptic_to_horizontal() 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 } // namespace ecs

+ 5
- 5
src/ecs/systems/solar-system.cpp View File

@ -18,9 +18,9 @@
*/ */
#include "ecs/systems/solar-system.hpp" #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/components/celestial-body-component.hpp"
#include "ecs/entity.hpp" #include "ecs/entity.hpp"
@ -45,7 +45,7 @@ void solar_system::update(double t, double dt)
registry.view<celestial_body_component>().each( registry.view<celestial_body_component>().each(
[&](ecs::entity entity, auto& body) [&](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.a += body.orbital_rate.a * universal_time;
elements.ec += body.orbital_rate.ec * universal_time; elements.ec += body.orbital_rate.ec * universal_time;
elements.w += body.orbital_rate.w * 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; elements.om += body.orbital_rate.om * universal_time;
// Calculate ecliptic orbital position // 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);
}); });
} }

+ 2
- 2
src/ecs/systems/weather-system.cpp View File

@ -25,8 +25,8 @@
#include "renderer/passes/material-pass.hpp" #include "renderer/passes/material-pass.hpp"
#include "utility/gamma.hpp" #include "utility/gamma.hpp"
#include "resources/image.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 <cmath> #include <cmath>
namespace ecs { namespace ecs {

Loading…
Cancel
Save