Conquer Space 0.0.0
A space themed grand strategy game set in the near future, with realistic orbital mechanics, and an emphasis on economics and politics.
starsystemcontroller.h
Go to the documentation of this file.
1/* Conquer Space
2 * Copyright (C) 2021-2025 Conquer Space
3 *
4 * This program is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation, either version 3 of the License, or
7 * (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program. If not, see <https://www.gnu.org/licenses/>.
16 */
17#pragma once
18
19#include <optional>
20
21#include <glm/glm.hpp>
22
28#include "core/universe.h"
29#include "engine/application.h"
30
31namespace cqsp::client::systems {
32class StarSystemViewUI;
33class SysStarSystemRenderer;
35 public:
37 void Update(float delta_time);
38
39 // Gets the intersection in 3d point between the mouse and any planet
41
48 glm::quat GetBodyRotation(double axial, double rotation, double day_offset) const;
49 glm::quat GetBodyRotation(const core::components::bodies::Body &body) const;
50
52
53 glm::vec3 CalculateCenteredObject(const entt::entity &);
54 glm::vec3 CalculateCenteredObject(const glm::vec3 &);
55
56 glm::vec3 CalculateObjectPos(const entt::entity &ent);
57
58 void FocusOnProvince(entt::entity province);
59 void FocusOnProvinceListener(const ctx::ViewProvince &province);
60
61 void PreRender();
62
63 entt::entity m_viewing_entity = entt::null;
64
65 glm::vec3 CalculateFuturePosition(const entt::entity entity);
69 glm::vec3 CalculateFutureCenteredPosition(const entt::entity entity);
70
71 entt::entity GetSelectedCountry() { return selected_country; }
72
73 private:
74 void SeeEntity();
75 void CenterCameraOnCity();
76 void MoveCamera(double delta_time);
77
78 void FocusOnEntity(entt::entity ent);
79 void SeePlanet(entt::entity ent);
80
81 void CalculateScroll();
82 float GetScrollValue();
83
84 void FocusPlanetView();
85 void FocusCityView();
86 void HandleCameraMovement(float delta_time);
87
88 void CalculateCityPositions(entt::entity entity);
89
93 void FoundCity();
94 bool IsFoundingCity();
95
96 void UpdateMapMode();
97
98 glm::vec3 CalculateMouseRay(const glm::vec3 &ray_nds);
99 entt::entity GetMouseOnObject(int mouse_x, int mouse_y);
100 void CalculateViewChange(double deltaX, double deltaY);
101
103
104 glm::vec3 GetMouseInScreenSpace(int mouse_x, int mouse_y);
105 std::optional<glm::vec3> CheckIntersection(const glm::vec3 &object_pos, const glm::vec3 &ray_wor, float radius);
106
107 void SetCountryProvincesColor(entt::entity country);
108 void SetCountryProvincesToProvinceColor(entt::entity country);
110
111 glm::vec4 GetCountryProvinceColor(entt::entity province);
112 glm::vec4 ColonizationTargetProvinceColor(entt::entity province);
113
114 void SelectProvince();
115
116 void ResetProvinceColor(entt::entity province);
117 void SelectForeignProvince(entt::entity province);
118 void SelectDomesticProvince(entt::entity province);
119
120 void HandleHoverTooltip();
121 bool MouseOverObjectBillboard(glm::vec3 object_pos);
122 std::optional<glm::vec3> IsMouseOverEntity(entt::entity entity, glm::vec3 ray_wor, double radius);
123
124 void CheckHoveringEntity();
126 entt::entity planet);
127
128 glm::vec4 CountryColorToVec4(const glm::vec3 &color);
130 glm::vec4 CountryColorToVec4(const entt::entity province);
131 glm::vec4 GetCountrySelectionColor(const glm::vec3 &country_color);
132 glm::vec3 MixScale(float amount);
133
136
139
140 entt::entity terrain_displaying = entt::null;
141 entt::entity selected_city = entt::null;
142
143 double previous_mouseX = 0;
144 double previous_mouseY = 0;
145
149 int tex_x = 0;
150 int tex_y = 0;
151
155 int tex_r = 0;
156 int tex_g = 0;
157 int tex_b = 0;
158
159 entt::entity hovering_province;
160
164 entt::entity hovering_planet = entt::null;
165 entt::entity hovering_country = entt::null;
166 entt::entity selected_province = entt::null;
167 entt::entity selected_country = entt::null;
168
172 glm::vec3 mouse_on_object_position = glm::vec3(0);
173
175 bool is_founding_city = false;
176
177 bool focus_on_city = false;
179
180 const float CAMERA_MOVEMENT_SPEED = 30.f / 40.f;
181 const float PAN_SPEED = 2.0f;
182 const float SCROLL_SENSITIVITY = 3.f / 33.f;
183 const float DEFAULT_PROVINCE_APLHA = 0.65f;
184
187
189
191
192 const glm::vec4 selected_province_color = glm::vec4(1.f, 0.f, 0.f, 0.35f);
193
195
196 entt::entity focused_planet = entt::null;
197 entt::entity last_focused_planet = entt::null;
198 entt::entity last_hovered_province = entt::null;
199
201 // Free camera just going anywhere
203 // Fixed on the planet/body but not rotating
205 // Fixed to a spot on the planet's surface
207 };
208
209 CameraState camera_state = CameraState::FreeCamera;
210};
211} // namespace cqsp::client::systems
Definition: starsystemcontroller.h:34
void ResetProvinceColor(entt::entity province)
Definition: starsystemcontroller.cpp:787
entt::entity SurfaceCoordinateToProvince(core::components::types::SurfaceCoordinate coordinate, entt::entity planet)
Definition: starsystemcontroller.cpp:875
glm::vec4 CountryColorToVec4(const glm::vec3 &color)
Definition: starsystemcontroller.cpp:812
void SeeEntity()
Definition: starsystemcontroller.cpp:666
CameraState camera_state
Definition: starsystemcontroller.h:209
SysStarSystemRenderer & renderer
Definition: starsystemcontroller.h:138
void CheckHoveringEntity()
Definition: starsystemcontroller.cpp:849
entt::entity selected_city
Definition: starsystemcontroller.h:141
double previous_mouseX
Definition: starsystemcontroller.h:143
core::components::types::SurfaceCoordinate target_surface_coordinate
Definition: starsystemcontroller.h:185
void SetCountryProvincesColor(entt::entity country)
Definition: starsystemcontroller.cpp:501
void SetCameraToSolarSystemReferenceFrame()
Definition: starsystemcontroller.cpp:459
entt::entity focused_planet
Definition: starsystemcontroller.h:196
ctx::MapMode last_map_mode
Definition: starsystemcontroller.h:194
glm::vec3 CalculateMouseRay(const glm::vec3 &ray_nds)
Definition: starsystemcontroller.cpp:589
bool focus_on_city
Definition: starsystemcontroller.h:177
bool planet_frame_scroll
Definition: starsystemcontroller.h:178
glm::vec3 CalculateCenteredObject(const entt::entity &)
Definition: starsystemcontroller.cpp:680
entt::entity last_focused_planet
Definition: starsystemcontroller.h:197
void SelectForeignProvince(entt::entity province)
Definition: starsystemcontroller.cpp:795
const float SCROLL_SENSITIVITY
Definition: starsystemcontroller.h:182
entt::entity hovering_planet
Definition: starsystemcontroller.h:164
void SelectProvince()
Definition: starsystemcontroller.cpp:328
glm::vec4 GetCountryProvinceColor(entt::entity province)
Definition: starsystemcontroller.cpp:706
void HandleHoverTooltip()
Definition: starsystemcontroller.cpp:900
entt::entity last_hovered_province
Definition: starsystemcontroller.h:198
const float DEFAULT_PROVINCE_APLHA
Definition: starsystemcontroller.h:183
void HandleCameraMovement(float delta_time)
Definition: starsystemcontroller.cpp:92
void UpdateMapMode()
Definition: starsystemcontroller.cpp:212
entt::entity selected_country
Definition: starsystemcontroller.h:167
void FoundCity()
Definition: starsystemcontroller.cpp:398
void SetCountryProvincesToProvinceColor(entt::entity country)
Definition: starsystemcontroller.cpp:514
bool MouseOverObjectBillboard(glm::vec3 object_pos)
Definition: starsystemcontroller.cpp:939
core::components::types::SurfaceCoordinate GetCameraOverCoordinate()
Definition: starsystemcontroller.cpp:377
void PreRender()
Definition: starsystemcontroller.cpp:416
glm::vec3 GetMouseOnObjectPosition()
Definition: starsystemcontroller.h:40
void CalculateCityPositions(entt::entity entity)
Calculate offset for all cities on planet if they exist.
Definition: starsystemcontroller.cpp:600
glm::vec4 ColonizationTargetProvinceColor(entt::entity province)
Definition: starsystemcontroller.cpp:776
void Update(float delta_time)
Definition: starsystemcontroller.cpp:61
core::Universe & universe
Definition: starsystemcontroller.h:134
friend StarSystemViewUI
Definition: starsystemcontroller.h:190
void HandleProvinceHoverColor()
Definition: starsystemcontroller.cpp:552
void SetCameraToPlanetReferenceFrame()
Definition: starsystemcontroller.cpp:451
entt::entity GetMouseOnObject(int mouse_x, int mouse_y)
Definition: starsystemcontroller.cpp:637
glm::vec3 MixScale(float amount)
Definition: starsystemcontroller.cpp:989
entt::entity hovering_country
Definition: starsystemcontroller.h:165
const glm::vec4 selected_province_color
Definition: starsystemcontroller.h:192
void FocusCityView()
Definition: starsystemcontroller.cpp:467
entt::entity m_viewing_entity
Definition: starsystemcontroller.h:63
void FocusPlanetView()
Definition: starsystemcontroller.cpp:696
glm::vec3 CalculateObjectPos(const entt::entity &ent)
Definition: starsystemcontroller.cpp:686
bool is_founding_city
Definition: starsystemcontroller.h:175
entt::entity selected_province
Definition: starsystemcontroller.h:166
entt::entity hovering_province
Definition: starsystemcontroller.h:159
void CalculateViewChange(double deltaX, double deltaY)
Definition: starsystemcontroller.cpp:181
void MoveCamera(double delta_time)
Definition: starsystemcontroller.cpp:122
CameraState
Definition: starsystemcontroller.h:200
@ PlanetIntertial
Definition: starsystemcontroller.h:204
@ FreeCamera
Definition: starsystemcontroller.h:202
@ PlanetFixed
Definition: starsystemcontroller.h:206
void SeePlanet(entt::entity ent)
Definition: starsystemcontroller.cpp:390
const float PAN_SPEED
Definition: starsystemcontroller.h:181
glm::vec3 mouse_on_object_position
Definition: starsystemcontroller.h:172
void CenterCameraOnPoint()
Definition: starsystemcontroller.cpp:423
engine::Application & app
Definition: starsystemcontroller.h:135
int tex_b
Definition: starsystemcontroller.h:157
std::optional< glm::vec3 > IsMouseOverEntity(entt::entity entity, glm::vec3 ray_wor, double radius)
Definition: starsystemcontroller.cpp:947
glm::vec3 GetMouseInScreenSpace(int mouse_x, int mouse_y)
Definition: starsystemcontroller.cpp:627
int tex_r
Debugging colors
Definition: starsystemcontroller.h:155
int tex_g
Definition: starsystemcontroller.h:156
int tex_y
Definition: starsystemcontroller.h:150
void CalculateScroll()
Definition: starsystemcontroller.cpp:155
bool is_rendering_founding_city
Definition: starsystemcontroller.h:174
StarSystemController(core::Universe &, engine::Application &, StarSystemCamera &, SysStarSystemRenderer &)
Definition: starsystemcontroller.cpp:55
void FocusOnProvinceListener(const ctx::ViewProvince &province)
Definition: starsystemcontroller.cpp:118
glm::vec3 CalculateFutureCenteredPosition(const entt::entity entity)
Definition: starsystemcontroller.cpp:976
glm::vec3 CalculateFuturePosition(const entt::entity entity)
Definition: starsystemcontroller.cpp:964
void CenterCameraOnCity()
Definition: starsystemcontroller.cpp:276
bool IsFoundingCity()
Definition: starsystemcontroller.cpp:210
glm::vec4 GetCountrySelectionColor(const glm::vec3 &country_color)
Definition: starsystemcontroller.cpp:804
float GetScrollValue()
Definition: starsystemcontroller.cpp:179
entt::entity terrain_displaying
Definition: starsystemcontroller.h:140
void SelectDomesticProvince(entt::entity province)
Definition: starsystemcontroller.cpp:829
entt::entity GetSelectedCountry()
Definition: starsystemcontroller.h:71
bool ShouldDrawCityPrototype()
Definition: starsystemcontroller.cpp:664
StarSystemCamera & camera
Definition: starsystemcontroller.h:137
glm::quat GetBodyRotation(double axial, double rotation, double day_offset) const
Gets the quaternion to calculate the planet's rotation from the axial rotation and the rotation perio...
Definition: starsystemcontroller.cpp:260
double previous_mouseY
Definition: starsystemcontroller.h:144
core::components::types::SurfaceCoordinate GetMouseSurfaceIntersection()
Definition: starsystemcontroller.cpp:241
const float CAMERA_MOVEMENT_SPEED
Definition: starsystemcontroller.h:180
std::optional< glm::vec3 > CheckIntersection(const glm::vec3 &object_pos, const glm::vec3 &ray_wor, float radius)
Definition: starsystemcontroller.cpp:486
void FocusOnEntity(entt::entity ent)
Definition: starsystemcontroller.cpp:308
void FocusOnProvince(entt::entity province)
Definition: starsystemcontroller.cpp:289
int tex_x
Debugging mouse position
Definition: starsystemcontroller.h:149
Definition: starsystemrenderer.h:43
Definition: universe.h:59
Definition: application.h:61
MapMode
Definition: clientctx.h:64
Definition: editorwidgets.cpp:29
Definition: clientctx.h:99
Definition: starsystemcamera.h:28
Longitude and lattitude. Planet coordinates.
Definition: coordinates.h:75