mirror of
https://github.com/MaSzyna-EU07/maszyna.git
synced 2026-07-22 22:09:19 +02:00
map visualization features
This commit is contained in:
@@ -14,6 +14,12 @@ http://mozilla.org/MPL/2.0/.
|
|||||||
#include "openglgeometrybank.h"
|
#include "openglgeometrybank.h"
|
||||||
#include "utilities.h"
|
#include "utilities.h"
|
||||||
|
|
||||||
|
struct map_colored_paths {
|
||||||
|
std::vector<gfx::geometrybank_handle> switches;
|
||||||
|
std::vector<gfx::geometrybank_handle> occupied;
|
||||||
|
std::vector<gfx::geometrybank_handle> future;
|
||||||
|
};
|
||||||
|
|
||||||
struct segment_data {
|
struct segment_data {
|
||||||
// types
|
// types
|
||||||
enum point {
|
enum point {
|
||||||
|
|||||||
80
Track.cpp
80
Track.cpp
@@ -1135,9 +1135,15 @@ void TTrack::create_map_geometry(std::vector<gfx::basic_vertex> &Bank, const gfx
|
|||||||
|
|
||||||
switch (eType)
|
switch (eType)
|
||||||
{
|
{
|
||||||
case tt_Normal:
|
case tt_Normal: {
|
||||||
Segment->render_lines(Bank, 0.5f);
|
std::vector<gfx::basic_vertex> 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;
|
break;
|
||||||
|
}
|
||||||
case tt_Switch: {
|
case tt_Switch: {
|
||||||
std::vector<gfx::basic_vertex> vertices;
|
std::vector<gfx::basic_vertex> vertices;
|
||||||
|
|
||||||
@@ -1156,15 +1162,77 @@ void TTrack::create_map_geometry(std::vector<gfx::basic_vertex> &Bank, const gfx
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void TTrack::get_map_active_switches(std::vector<gfx::geometrybank_handle> &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;
|
return;
|
||||||
|
|
||||||
|
if (eType == tt_Switch) {
|
||||||
if (GetSwitchState() == 0)
|
if (GetSwitchState() == 0)
|
||||||
handles.push_back(SwitchExtension->map_geometry[0]);
|
handles.switches.push_back(SwitchExtension->map_geometry[0]);
|
||||||
else
|
else
|
||||||
handles.push_back(SwitchExtension->map_geometry[1]);
|
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
|
glm::vec3 TTrack::get_nearest_point(const glm::dvec3 &point) const
|
||||||
|
|||||||
7
Track.h
7
Track.h
@@ -180,6 +180,7 @@ private:
|
|||||||
geometryhandle_sequence Geometry2; // geometry chunks textured with texture 2
|
geometryhandle_sequence Geometry2; // geometry chunks textured with texture 2
|
||||||
|
|
||||||
std::vector<segment_data> m_paths; // source data for owned paths
|
std::vector<segment_data> m_paths; // source data for owned paths
|
||||||
|
int iterate_stamp = 0;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
using dynamics_sequence = std::deque<TDynamicObject *>;
|
using dynamics_sequence = std::deque<TDynamicObject *>;
|
||||||
@@ -275,9 +276,13 @@ public:
|
|||||||
std::vector<glm::dvec3>
|
std::vector<glm::dvec3>
|
||||||
endpoints() const;
|
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_geometry( gfx::geometrybank_handle const &Bank ); // wypełnianie VBO
|
||||||
void create_map_geometry(std::vector<gfx::basic_vertex> &Bank, const gfx::geometrybank_handle Extra);
|
void create_map_geometry(std::vector<gfx::basic_vertex> &Bank, const gfx::geometrybank_handle Extra);
|
||||||
void get_map_active_switches(std::vector<gfx::geometrybank_handle> &handles);
|
void get_map_active_paths(map_colored_paths &handles);
|
||||||
glm::vec3 get_nearest_point(const glm::dvec3 &point) const;
|
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
|
void RenderDynSounds(); // odtwarzanie dźwięków pojazdów jest niezależne od ich wyświetlania
|
||||||
|
|
||||||
|
|||||||
@@ -618,10 +618,10 @@ void basic_cell::create_map_geometry(std::vector<gfx::basic_vertex> &Bank, const
|
|||||||
path->create_map_geometry(Bank, Extra);
|
path->create_map_geometry(Bank, Extra);
|
||||||
}
|
}
|
||||||
|
|
||||||
void basic_cell::get_map_active_switches(std::vector<gfx::geometrybank_handle> &handles)
|
void basic_cell::get_map_active_paths(map_colored_paths &handles)
|
||||||
{
|
{
|
||||||
for (auto *path : m_paths)
|
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)
|
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);
|
m_map_geometryhandle = GfxRenderer.Insert(lines, handle, GL_LINES);
|
||||||
}
|
}
|
||||||
|
|
||||||
void basic_section::get_map_active_switches(std::vector<gfx::geometrybank_handle> &handles)
|
void basic_section::get_map_active_paths(map_colored_paths &handles)
|
||||||
{
|
{
|
||||||
for (auto &cell : m_cells)
|
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)
|
glm::vec3 basic_section::find_nearest_track_point(const glm::dvec3 &point)
|
||||||
|
|||||||
5
scene.h
5
scene.h
@@ -157,7 +157,7 @@ public:
|
|||||||
void
|
void
|
||||||
create_map_geometry(std::vector<gfx::basic_vertex> &Bank, const gfx::geometrybank_handle Extra);
|
create_map_geometry(std::vector<gfx::basic_vertex> &Bank, const gfx::geometrybank_handle Extra);
|
||||||
void
|
void
|
||||||
get_map_active_switches(std::vector<gfx::geometrybank_handle> &handles);
|
get_map_active_paths(map_colored_paths &handles);
|
||||||
glm::vec3 find_nearest_track_point(const glm::dvec3 &pos);
|
glm::vec3 find_nearest_track_point(const glm::dvec3 &pos);
|
||||||
// provides access to bounding area data
|
// provides access to bounding area data
|
||||||
bounding_area const &
|
bounding_area const &
|
||||||
@@ -285,11 +285,12 @@ public:
|
|||||||
void
|
void
|
||||||
create_map_geometry(const gfx::geometrybank_handle handle);
|
create_map_geometry(const gfx::geometrybank_handle handle);
|
||||||
void
|
void
|
||||||
get_map_active_switches(std::vector<gfx::geometrybank_handle> &handles);
|
get_map_active_paths(map_colored_paths &handles);
|
||||||
// provides access to bounding area data
|
// provides access to bounding area data
|
||||||
bounding_area const &
|
bounding_area const &
|
||||||
area() const {
|
area() const {
|
||||||
return m_area; }
|
return m_area; }
|
||||||
|
|
||||||
const gfx::geometrybank_handle get_map_geometry()
|
const gfx::geometrybank_handle get_map_geometry()
|
||||||
{ return m_map_geometryhandle;}
|
{ return m_map_geometryhandle;}
|
||||||
glm::vec3 find_nearest_track_point(const glm::dvec3 &point);
|
glm::vec3 find_nearest_track_point(const glm::dvec3 &point);
|
||||||
|
|||||||
@@ -2,7 +2,14 @@
|
|||||||
|
|
||||||
layout(location = 0) out vec4 out_color;
|
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()
|
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);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -74,8 +74,10 @@ void ui::map_panel::render_map_texture(glm::mat4 transform, glm::vec2 surface_si
|
|||||||
cFrustum frustum;
|
cFrustum frustum;
|
||||||
frustum.calculate(transform, glm::mat4());
|
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_section_handles.clear();
|
||||||
m_switch_handles.clear();
|
|
||||||
|
|
||||||
for (int row = 0; row < scene::EU07_REGIONSIDESECTIONCOUNT; row++)
|
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)
|
if (handle != null_handle)
|
||||||
{
|
{
|
||||||
m_section_handles.push_back(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);
|
glViewport(0, 0, surface_size.x, surface_size.y);
|
||||||
|
|
||||||
scene_ubs.projection = transform;
|
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->update(scene_ubs);
|
||||||
scene_ubo->bind_uniform();
|
scene_ubo->bind_uniform();
|
||||||
|
|
||||||
GfxRenderer.Draw_Geometry(m_section_handles.begin(), m_section_handles.end());
|
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);
|
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) {
|
if (!Global.gfx_usegles || GLAD_GL_EXT_geometry_shader) {
|
||||||
GfxRenderer.Bind_Texture(0, m_icon_atlas);
|
GfxRenderer.Bind_Texture(0, m_icon_atlas);
|
||||||
|
|||||||
@@ -80,7 +80,7 @@ class map_panel : public ui_panel
|
|||||||
gl::scene_ubs scene_ubs;
|
gl::scene_ubs scene_ubs;
|
||||||
|
|
||||||
std::vector<gfx::geometrybank_handle> m_section_handles;
|
std::vector<gfx::geometrybank_handle> m_section_handles;
|
||||||
std::vector<gfx::geometrybank_handle> m_switch_handles;
|
map_colored_paths m_colored_paths;
|
||||||
|
|
||||||
const int fb_size = 1024;
|
const int fb_size = 1024;
|
||||||
|
|
||||||
|
|||||||
@@ -25,7 +25,6 @@ class trainingcard_panel : public ui_panel
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
virtual int EndRecording( std::string training_identifier ) {
|
virtual int EndRecording( std::string training_identifier ) {
|
||||||
std::this_thread::sleep_for(std::chrono::duration<float>(1.0f));
|
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user