Project Alice
Loading...
Searching...
No Matches
map_state.hpp
Go to the documentation of this file.
1#pragma once
2
3#include "map_modes.hpp"
4#include <glm/vec2.hpp>
5#include <glm/mat4x4.hpp>
6#include "map.hpp"
7
8namespace sys {
9struct state;
10};
11namespace parsers {
12struct scenario_building_context;
13};
14
15namespace map {
16
18class map_state {
19public:
21
22 // Called to load the terrain and province map data
24 // Called to load the map. Will load the texture and shaders from disk
25 void load_map(sys::state& state);
26
28
29 void render(sys::state& state, uint32_t screen_x, uint32_t screen_y);
30 void set_province_color(std::vector<uint32_t> const& prov_color, map_mode::mode map_mode);
33
34 glm::vec2 normalize_map_coord(glm::vec2 pos);
35 bool map_to_screen(sys::state& state, glm::vec2 map_pos, glm::vec2 screen_size, glm::vec2& screen_pos);
36
37 // Set the position of camera. Position relative from 0-1
38 void set_pos(glm::vec2 pos);
39
40 void center_map_on_province(sys::state& state, dcon::province_id);
41
42 // Input methods
45 void on_mouse_wheel(int32_t x, int32_t y, int32_t screen_size_x, int32_t screen_size_y, sys::key_modifiers mod, float amount);
46 void on_mouse_move(int32_t x, int32_t y, int32_t screen_size_x, int32_t screen_size_y, sys::key_modifiers mod);
47 void on_mbuttom_down(int32_t x, int32_t y, int32_t screen_size_x, int32_t screen_size_y, sys::key_modifiers mod);
48 void on_mbuttom_up(int32_t x, int32_t y, sys::key_modifiers mod);
49 void on_lbutton_down(sys::state& state, int32_t x, int32_t y, int32_t screen_size_x, int32_t screen_size_y, sys::key_modifiers mod);
50 void on_lbutton_up(sys::state& state, int32_t x, int32_t y, int32_t screen_size_x, int32_t screen_size_y, sys::key_modifiers mod);
51 void on_rbutton_down(sys::state& state, int32_t x, int32_t y, int32_t screen_size_x, int32_t screen_size_y, sys::key_modifiers mod);
52 dcon::province_id get_province_under_mouse(sys::state& state, int32_t x, int32_t y, int32_t screen_size_x, int32_t screen_size_y);
53
54 dcon::province_id get_selected_province();
55 void set_selected_province(dcon::province_id prov_id);
56
58 dcon::province_id selected_province = dcon::province_id{};
59
61 bool is_dragging = false;
62
63 // Last update time, used for smooth map movement
64 std::chrono::time_point<std::chrono::steady_clock> last_update_time{};
65
66 // Time in seconds, send to the map shader for animations
67 float time_counter = 0;
68
69 // interaction
71
72 // Position and movement
73 glm::vec2 pos = glm::vec2(0.5f, 0.5f);
74 glm::vec2 pos_velocity = glm::vec2(0.f);
75 glm::vec2 last_camera_drag_pos = glm::vec2(0.5f, 0.5f);
76 glm::mat4 globe_rotation = glm::mat4(1.0f);
77 glm::vec2 last_unit_box_drag_pos = glm::vec2(0, 0);
78
79 float zoom = 1.f;
80 float zoom_change = 1.f;
81 bool has_zoom_changed = false;
82 bool pgup_key_down = false;
83 bool pgdn_key_down = false;
84 bool left_arrow_key_down = false;
86 bool up_arrow_key_down = false;
87 bool down_arrow_key_down = false;
88 bool shift_key_down = false;
89 bool left_mouse_down = false;
90 glm::vec2 scroll_pos_velocity = glm::vec2(0.f);
91 std::vector<bool> visible_provinces;
92
93 void update(sys::state& state);
94
95 bool screen_to_map(glm::vec2 screen_pos, glm::vec2 screen_size, map_view view_mode, glm::vec2& map_pos);
96
97 float get_zoom() {
98 return zoom;
99 }
100};
101
102void update_text_lines(sys::state& state, display_data& map_data);
103
104} // namespace map
float time_counter
Definition: map_state.hpp:67
bool map_to_screen(sys::state &state, glm::vec2 map_pos, glm::vec2 screen_size, glm::vec2 &screen_pos)
Definition: map_state.cpp:1406
bool up_arrow_key_down
Definition: map_state.hpp:86
glm::vec2 last_camera_drag_pos
Definition: map_state.hpp:75
void on_mouse_wheel(int32_t x, int32_t y, int32_t screen_size_x, int32_t screen_size_y, sys::key_modifiers mod, float amount)
Definition: map_state.cpp:1204
void load_map_data(parsers::scenario_building_context &context)
bool down_arrow_key_down
Definition: map_state.hpp:87
void on_lbutton_up(sys::state &state, int32_t x, int32_t y, int32_t screen_size_x, int32_t screen_size_y, sys::key_modifiers mod)
Definition: map_state.cpp:1337
void on_mbuttom_up(int32_t x, int32_t y, sys::key_modifiers mod)
Definition: map_state.cpp:1326
void on_mbuttom_down(int32_t x, int32_t y, int32_t screen_size_x, int32_t screen_size_y, sys::key_modifiers mod)
Definition: map_state.cpp:1314
bool screen_to_map(glm::vec2 screen_pos, glm::vec2 screen_size, map_view view_mode, glm::vec2 &map_pos)
Definition: map_state.cpp:1233
void update_borders(sys::state &state)
bool pgdn_key_down
Definition: map_state.hpp:83
void set_selected_province(dcon::province_id prov_id)
Definition: map_state.cpp:37
bool unhandled_province_selection
Definition: map_state.hpp:70
map_view current_view(sys::state &state)
Definition: map_state.cpp:27
bool pgup_key_down
Definition: map_state.hpp:82
bool shift_key_down
Definition: map_state.hpp:88
void update(sys::state &state)
Definition: map_state.cpp:967
glm::mat4 globe_rotation
Definition: map_state.hpp:76
std::chrono::time_point< std::chrono::steady_clock > last_update_time
Definition: map_state.hpp:64
dcon::province_id get_selected_province()
Definition: map_state.cpp:18
void on_key_up(sys::virtual_key keycode, sys::key_modifiers mod)
Definition: map_state.cpp:1160
glm::vec2 pos_velocity
Definition: map_state.hpp:74
void set_terrain_map_mode()
Definition: map_state.cpp:1128
void load_map(sys::state &state)
Definition: map_state.cpp:23
dcon::province_id selected_province
Definition: map_state.hpp:58
void on_rbutton_down(sys::state &state, int32_t x, int32_t y, int32_t screen_size_x, int32_t screen_size_y, sys::key_modifiers mod)
Definition: map_state.cpp:1368
float zoom_change
Definition: map_state.hpp:80
void on_key_down(sys::virtual_key keycode, sys::key_modifiers mod)
Definition: map_state.cpp:1132
glm::vec2 scroll_pos_velocity
Definition: map_state.hpp:90
void set_province_color(std::vector< uint32_t > const &prov_color, map_mode::mode map_mode)
Definition: map_state.cpp:1123
bool left_mouse_down
Definition: map_state.hpp:89
float get_zoom()
Definition: map_state.hpp:97
bool has_zoom_changed
Definition: map_state.hpp:81
glm::vec2 last_unit_box_drag_pos
Definition: map_state.hpp:77
std::vector< bool > visible_provinces
Definition: map_state.hpp:91
void on_lbutton_down(sys::state &state, int32_t x, int32_t y, int32_t screen_size_x, int32_t screen_size_y, sys::key_modifiers mod)
Definition: map_state.cpp:1330
glm::vec2 pos
Definition: map_state.hpp:73
glm::vec2 normalize_map_coord(glm::vec2 pos)
Definition: map_state.cpp:1565
map_mode::mode active_map_mode
Definition: map_state.hpp:57
void on_mouse_move(int32_t x, int32_t y, int32_t screen_size_x, int32_t screen_size_y, sys::key_modifiers mod)
Definition: map_state.cpp:1211
void center_map_on_province(sys::state &state, dcon::province_id)
Definition: map_state.cpp:1193
bool left_arrow_key_down
Definition: map_state.hpp:84
void render(sys::state &state, uint32_t screen_x, uint32_t screen_y)
Definition: map_state.cpp:42
dcon::province_id get_province_under_mouse(sys::state &state, int32_t x, int32_t y, int32_t screen_size_x, int32_t screen_size_y)
Definition: map_state.cpp:1385
bool right_arrow_key_down
Definition: map_state.hpp:85
display_data map_data
Definition: map_state.hpp:60
void set_pos(glm::vec2 pos)
Definition: map_state.cpp:1188
map_view
Definition: map_state.hpp:17
void update_text_lines(sys::state &state, display_data &map_data)
Definition: map_state.cpp:230
Definition: constants.hpp:4
virtual_key
Definition: constants.hpp:5
key_modifiers
Definition: constants.hpp:156
uint uint32_t