From 33adffb6142e6981102a5277c363593ff13e6124 Mon Sep 17 00:00:00 2001 From: milek7 Date: Tue, 2 Apr 2019 01:21:49 +0200 Subject: [PATCH] map visualization features --- Segment.h | 6 +++ Track.cpp | 84 ++++++++++++++++++++++++++++++++++++++---- Track.h | 7 +++- scene.cpp | 8 ++-- scene.h | 5 ++- shaders/map.frag | 9 ++++- widgets/map.cpp | 18 ++++++--- widgets/map.h | 2 +- widgets/trainingcard.h | 1 - 9 files changed, 116 insertions(+), 24 deletions(-) diff --git a/Segment.h b/Segment.h index 937b56ff..8c1b02cd 100644 --- a/Segment.h +++ b/Segment.h @@ -14,6 +14,12 @@ http://mozilla.org/MPL/2.0/. #include "openglgeometrybank.h" #include "utilities.h" +struct map_colored_paths { + std::vector switches; + std::vector occupied; + std::vector future; +}; + struct segment_data { // types enum point { diff --git a/Track.cpp b/Track.cpp index 1de11962..fdb99cf7 100644 --- a/Track.cpp +++ b/Track.cpp @@ -1135,9 +1135,15 @@ void TTrack::create_map_geometry(std::vector &Bank, const gfx switch (eType) { - case tt_Normal: - Segment->render_lines(Bank, 0.5f); + case tt_Normal: { + std::vector vertices; + Segment->render_lines(vertices, 0.5f); + + extra_map_geometry = GfxRenderer.Insert(vertices, Extra, GL_LINES); + std::copy(vertices.begin(), vertices.end(), std::back_inserter(Bank)); + break; + } case tt_Switch: { std::vector vertices; @@ -1156,15 +1162,77 @@ void TTrack::create_map_geometry(std::vector &Bank, const gfx } } -void TTrack::get_map_active_switches(std::vector &handles) +TTrack *TTrack::Next(TTrack *visitor) { + if (eType == tt_Normal) { + if (trNext != visitor) + return trNext; + else + return trPrev; + } else if (eType == tt_Switch) { + int state = GetSwitchState(); + + if (SwitchExtension->pPrevs[0] == visitor + || SwitchExtension->pPrevs[1] == visitor) + { + // we came from 'previous' side + return SwitchExtension->pNexts[state]; + } + + if (SwitchExtension->pNexts[0] == visitor + || SwitchExtension->pNexts[1] == visitor) + { + // we came from 'next' side + return SwitchExtension->pPrevs[state]; + } + } + return nullptr; +} + +void TTrack::get_map_active_paths(map_colored_paths &handles) { - if (iCategoryFlag != 1 || eType != tt_Switch) + if (iCategoryFlag != 1) return; - if (GetSwitchState() == 0) - handles.push_back(SwitchExtension->map_geometry[0]); - else - handles.push_back(SwitchExtension->map_geometry[1]); + if (eType == tt_Switch) { + if (GetSwitchState() == 0) + handles.switches.push_back(SwitchExtension->map_geometry[0]); + else + handles.switches.push_back(SwitchExtension->map_geometry[1]); + } + + if (!Dynamics.empty()) { + handles.occupied.push_back(extra_map_geometry); + + static int stamp = 0; + stamp++; + + int limit = 15; + TTrack *track = trPrev; + TTrack *visitor = this; + + while (limit-- > 0 && track && track->iterate_stamp != stamp) { + handles.future.push_back(track->extra_map_geometry); + track->iterate_stamp = stamp; + + TTrack *tmp = track; + track = track->Next(visitor); + visitor = tmp; + } + + limit = 15; + stamp++; + track = trNext; + visitor = this; + + while (limit-- > 0 && track && track->iterate_stamp != stamp) { + handles.future.push_back(track->extra_map_geometry); + track->iterate_stamp = stamp; + + TTrack *tmp = track; + track = track->Next(visitor); + visitor = tmp; + } + } } glm::vec3 TTrack::get_nearest_point(const glm::dvec3 &point) const diff --git a/Track.h b/Track.h index 5899b4ce..fa32af9f 100644 --- a/Track.h +++ b/Track.h @@ -180,6 +180,7 @@ private: geometryhandle_sequence Geometry2; // geometry chunks textured with texture 2 std::vector m_paths; // source data for owned paths + int iterate_stamp = 0; public: using dynamics_sequence = std::deque; @@ -275,9 +276,13 @@ public: std::vector endpoints() const; + gfx::geometrybank_handle extra_map_geometry; // handle for map highlighting + + TTrack *Next(TTrack *visitor); + void create_geometry( gfx::geometrybank_handle const &Bank ); // wypełnianie VBO void create_map_geometry(std::vector &Bank, const gfx::geometrybank_handle Extra); - void get_map_active_switches(std::vector &handles); + void get_map_active_paths(map_colored_paths &handles); glm::vec3 get_nearest_point(const glm::dvec3 &point) const; void RenderDynSounds(); // odtwarzanie dźwięków pojazdów jest niezależne od ich wyświetlania diff --git a/scene.cpp b/scene.cpp index 7df09c95..1bb6d05f 100644 --- a/scene.cpp +++ b/scene.cpp @@ -618,10 +618,10 @@ void basic_cell::create_map_geometry(std::vector &Bank, const path->create_map_geometry(Bank, Extra); } -void basic_cell::get_map_active_switches(std::vector &handles) +void basic_cell::get_map_active_paths(map_colored_paths &handles) { for (auto *path : m_paths) - path->get_map_active_switches(handles); + path->get_map_active_paths(handles); } glm::vec3 basic_cell::find_nearest_track_point(const glm::dvec3 &pos) @@ -960,10 +960,10 @@ void basic_section::create_map_geometry(const gfx::geometrybank_handle handle) m_map_geometryhandle = GfxRenderer.Insert(lines, handle, GL_LINES); } -void basic_section::get_map_active_switches(std::vector &handles) +void basic_section::get_map_active_paths(map_colored_paths &handles) { for (auto &cell : m_cells) - cell.get_map_active_switches(handles); + cell.get_map_active_paths(handles); } glm::vec3 basic_section::find_nearest_track_point(const glm::dvec3 &point) diff --git a/scene.h b/scene.h index 2fbb23f0..7237efcc 100644 --- a/scene.h +++ b/scene.h @@ -157,7 +157,7 @@ public: void create_map_geometry(std::vector &Bank, const gfx::geometrybank_handle Extra); void - get_map_active_switches(std::vector &handles); + get_map_active_paths(map_colored_paths &handles); glm::vec3 find_nearest_track_point(const glm::dvec3 &pos); // provides access to bounding area data bounding_area const & @@ -285,11 +285,12 @@ public: void create_map_geometry(const gfx::geometrybank_handle handle); void - get_map_active_switches(std::vector &handles); + get_map_active_paths(map_colored_paths &handles); // provides access to bounding area data bounding_area const & area() const { return m_area; } + const gfx::geometrybank_handle get_map_geometry() { return m_map_geometryhandle;} glm::vec3 find_nearest_track_point(const glm::dvec3 &point); diff --git a/shaders/map.frag b/shaders/map.frag index 18a124e2..fd981f21 100644 --- a/shaders/map.frag +++ b/shaders/map.frag @@ -2,7 +2,14 @@ layout(location = 0) out vec4 out_color; +vec3 hsv2rgb(vec3 c) +{ + vec4 K = vec4(1.0, 2.0 / 3.0, 1.0 / 3.0, 3.0); + vec3 p = abs(fract(c.xxx + K.xyz) * 6.0 - K.www); + return c.z * mix(K.xxx, clamp(p - K.xxx, 0.0, 1.0), c.y); +} + void main() { - out_color = vec4(vec3(0.3f, time, 0.3f), 1.0f); + out_color = vec4(hsv2rgb(vec3(time, 1.0, 1.0)), 1.0f); } diff --git a/widgets/map.cpp b/widgets/map.cpp index 3a0880ad..f101ba31 100644 --- a/widgets/map.cpp +++ b/widgets/map.cpp @@ -74,8 +74,10 @@ void ui::map_panel::render_map_texture(glm::mat4 transform, glm::vec2 surface_si cFrustum frustum; frustum.calculate(transform, glm::mat4()); + m_colored_paths.switches.clear(); + m_colored_paths.occupied.clear(); + m_colored_paths.future.clear(); m_section_handles.clear(); - m_switch_handles.clear(); for (int row = 0; row < scene::EU07_REGIONSIDESECTIONCOUNT; row++) { @@ -88,7 +90,7 @@ void ui::map_panel::render_map_texture(glm::mat4 transform, glm::vec2 surface_si if (handle != null_handle) { m_section_handles.push_back(handle); - section->get_map_active_switches(m_switch_handles); + section->get_map_active_paths(m_colored_paths); } } } @@ -111,17 +113,21 @@ void ui::map_panel::render_map_texture(glm::mat4 transform, glm::vec2 surface_si glViewport(0, 0, surface_size.x, surface_size.y); scene_ubs.projection = transform; - scene_ubs.time = 0.3f; // color is stuffed in time variable + scene_ubs.time = 0.5f; // color is stuffed in time variable scene_ubo->update(scene_ubs); scene_ubo->bind_uniform(); GfxRenderer.Draw_Geometry(m_section_handles.begin(), m_section_handles.end()); - glLineWidth(3.0f); + glLineWidth(2.0f); - scene_ubs.time = 0.6f; // color is stuffed in time variable + scene_ubs.time = 0.27f; // color is stuffed in time variable scene_ubo->update(scene_ubs); - GfxRenderer.Draw_Geometry(m_switch_handles.begin(), m_switch_handles.end()); + GfxRenderer.Draw_Geometry(m_colored_paths.switches.begin(), m_colored_paths.switches.end()); + GfxRenderer.Draw_Geometry(m_colored_paths.future.begin(), m_colored_paths.future.end()); + scene_ubs.time = 1.0f; // color is stuffed in time variable + scene_ubo->update(scene_ubs); + GfxRenderer.Draw_Geometry(m_colored_paths.occupied.begin(), m_colored_paths.occupied.end()); if (!Global.gfx_usegles || GLAD_GL_EXT_geometry_shader) { GfxRenderer.Bind_Texture(0, m_icon_atlas); diff --git a/widgets/map.h b/widgets/map.h index abc3708d..be3c8b20 100644 --- a/widgets/map.h +++ b/widgets/map.h @@ -80,7 +80,7 @@ class map_panel : public ui_panel gl::scene_ubs scene_ubs; std::vector m_section_handles; - std::vector m_switch_handles; + map_colored_paths m_colored_paths; const int fb_size = 1024; diff --git a/widgets/trainingcard.h b/widgets/trainingcard.h index cd7bc05c..fd0a6b63 100644 --- a/widgets/trainingcard.h +++ b/widgets/trainingcard.h @@ -25,7 +25,6 @@ class trainingcard_panel : public ui_panel return 1; } virtual int EndRecording( std::string training_identifier ) { - std::this_thread::sleep_for(std::chrono::duration(1.0f)); return 1; }