mirror of
https://github.com/MaSzyna-EU07/maszyna.git
synced 2026-07-22 19:49:19 +02:00
switch state visualisation, semaphore tracking for map purposes
This commit is contained in:
@@ -125,6 +125,7 @@ set(SOURCES
|
|||||||
|
|
||||||
"widgets/vehiclelist.cpp"
|
"widgets/vehiclelist.cpp"
|
||||||
"widgets/map.cpp"
|
"widgets/map.cpp"
|
||||||
|
"widgets/map_objects.cpp"
|
||||||
|
|
||||||
"ref/glad/src/glad.c"
|
"ref/glad/src/glad.c"
|
||||||
|
|
||||||
|
|||||||
1
Event.h
1
Event.h
@@ -80,6 +80,7 @@ public:
|
|||||||
virtual glm::dvec3 input_location() const;
|
virtual glm::dvec3 input_location() const;
|
||||||
void group( scene::group_handle Group );
|
void group( scene::group_handle Group );
|
||||||
scene::group_handle group() const;
|
scene::group_handle group() const;
|
||||||
|
std::string const &name() const { return m_name; }
|
||||||
// members
|
// members
|
||||||
basic_event *m_next { nullptr }; // następny w kolejce // TODO: replace with event list in the manager
|
basic_event *m_next { nullptr }; // następny w kolejce // TODO: replace with event list in the manager
|
||||||
basic_event *m_sibling { nullptr }; // kolejny event z tą samą nazwą - od wersji 378
|
basic_event *m_sibling { nullptr }; // kolejny event z tą samą nazwą - od wersji 378
|
||||||
|
|||||||
30
Track.cpp
30
Track.cpp
@@ -1128,7 +1128,7 @@ void TTrack::RaAssign( TAnimModel *am, basic_event *done, basic_event *joined )
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
void TTrack::create_map_geometry(std::vector<gfx::basic_vertex> &Bank)
|
void TTrack::create_map_geometry(std::vector<gfx::basic_vertex> &Bank, const gfx::geometrybank_handle Extra)
|
||||||
{
|
{
|
||||||
if (iCategoryFlag != 1)
|
if (iCategoryFlag != 1)
|
||||||
return; // only tracks for now
|
return; // only tracks for now
|
||||||
@@ -1136,19 +1136,37 @@ void TTrack::create_map_geometry(std::vector<gfx::basic_vertex> &Bank)
|
|||||||
switch (eType)
|
switch (eType)
|
||||||
{
|
{
|
||||||
case tt_Normal:
|
case tt_Normal:
|
||||||
case tt_Table:
|
|
||||||
Segment->render_lines(Bank, 0.5f);
|
Segment->render_lines(Bank, 0.5f);
|
||||||
break;
|
break;
|
||||||
case tt_Switch:
|
case tt_Switch: {
|
||||||
case tt_Cross:
|
std::vector<gfx::basic_vertex> vertices;
|
||||||
SwitchExtension->Segments[0]->render_lines(Bank, 0.5f);
|
|
||||||
SwitchExtension->Segments[1]->render_lines(Bank, 0.5f);
|
SwitchExtension->Segments[0]->render_lines(vertices, 0.5f);
|
||||||
|
SwitchExtension->map_geometry[0] = GfxRenderer.Insert(vertices, Extra, GL_LINES);
|
||||||
|
std::copy(vertices.begin(), vertices.end(), std::back_inserter(Bank));
|
||||||
|
|
||||||
|
vertices.clear();
|
||||||
|
SwitchExtension->Segments[1]->render_lines(vertices, 0.5f);
|
||||||
|
SwitchExtension->map_geometry[1] = GfxRenderer.Insert(vertices, Extra, GL_LINES);
|
||||||
|
std::copy(vertices.begin(), vertices.end(), std::back_inserter(Bank));
|
||||||
break;
|
break;
|
||||||
|
}
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void TTrack::get_map_active_switches(std::vector<gfx::geometrybank_handle> &handles)
|
||||||
|
{
|
||||||
|
if (iCategoryFlag != 1 || eType != tt_Switch)
|
||||||
|
return;
|
||||||
|
|
||||||
|
if (GetSwitchState() == 0)
|
||||||
|
handles.push_back(SwitchExtension->map_geometry[0]);
|
||||||
|
else
|
||||||
|
handles.push_back(SwitchExtension->map_geometry[1]);
|
||||||
|
}
|
||||||
|
|
||||||
// wypełnianie tablic VBO
|
// wypełnianie tablic VBO
|
||||||
void TTrack::create_geometry( gfx::geometrybank_handle const &Bank ) {
|
void TTrack::create_geometry( gfx::geometrybank_handle const &Bank ) {
|
||||||
|
|
||||||
|
|||||||
5
Track.h
5
Track.h
@@ -95,6 +95,8 @@ class TSwitchExtension
|
|||||||
Math3D::vector3 vTrans; // docelowa translacja przesuwnicy
|
Math3D::vector3 vTrans; // docelowa translacja przesuwnicy
|
||||||
material_handle m_material3 = 0; // texture of auto generated switch trackbed
|
material_handle m_material3 = 0; // texture of auto generated switch trackbed
|
||||||
gfx::geometry_handle Geometry3; // geometry of auto generated switch trackbed
|
gfx::geometry_handle Geometry3; // geometry of auto generated switch trackbed
|
||||||
|
|
||||||
|
gfx::geometrybank_handle map_geometry[6]; // geometry for map visualisation
|
||||||
};
|
};
|
||||||
|
|
||||||
class TIsolated
|
class TIsolated
|
||||||
@@ -274,7 +276,8 @@ public:
|
|||||||
endpoints() const;
|
endpoints() const;
|
||||||
|
|
||||||
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);
|
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 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
|
||||||
|
|
||||||
void RaOwnerSet( scene::basic_cell *o ) {
|
void RaOwnerSet( scene::basic_cell *o ) {
|
||||||
|
|||||||
18
scene.cpp
18
scene.cpp
@@ -608,13 +608,19 @@ basic_cell::create_geometry( gfx::geometrybank_handle const &Bank ) {
|
|||||||
m_geometrycreated = true; // helper for legacy animation code, get rid of it after refactoring
|
m_geometrycreated = true; // helper for legacy animation code, get rid of it after refactoring
|
||||||
}
|
}
|
||||||
|
|
||||||
void basic_cell::create_map_geometry(std::vector<gfx::basic_vertex> &Bank)
|
void basic_cell::create_map_geometry(std::vector<gfx::basic_vertex> &Bank, const gfx::geometrybank_handle Extra)
|
||||||
{
|
{
|
||||||
if (!m_active)
|
if (!m_active)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
for (auto *path : m_paths)
|
for (auto *path : m_paths)
|
||||||
path->create_map_geometry(Bank);
|
path->create_map_geometry(Bank, Extra);
|
||||||
|
}
|
||||||
|
|
||||||
|
void basic_cell::get_map_active_switches(std::vector<gfx::geometrybank_handle> &handles)
|
||||||
|
{
|
||||||
|
for (auto *path : m_paths)
|
||||||
|
path->get_map_active_switches(handles);
|
||||||
}
|
}
|
||||||
|
|
||||||
// executes event assigned to specified launcher
|
// executes event assigned to specified launcher
|
||||||
@@ -926,11 +932,17 @@ void basic_section::create_map_geometry(const gfx::geometrybank_handle handle)
|
|||||||
{
|
{
|
||||||
std::vector<gfx::basic_vertex> lines;
|
std::vector<gfx::basic_vertex> lines;
|
||||||
for (auto &cell : m_cells)
|
for (auto &cell : m_cells)
|
||||||
cell.create_map_geometry(lines);
|
cell.create_map_geometry(lines, 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)
|
||||||
|
{
|
||||||
|
for (auto &cell : m_cells)
|
||||||
|
cell.get_map_active_switches(handles);
|
||||||
|
}
|
||||||
|
|
||||||
// provides access to section enclosing specified point
|
// provides access to section enclosing specified point
|
||||||
basic_cell &
|
basic_cell &
|
||||||
basic_section::cell( glm::dvec3 const &Location ) {
|
basic_section::cell( glm::dvec3 const &Location ) {
|
||||||
|
|||||||
10
scene.h
10
scene.h
@@ -153,7 +153,10 @@ public:
|
|||||||
// generates renderable version of held non-instanced geometry in specified geometry bank
|
// generates renderable version of held non-instanced geometry in specified geometry bank
|
||||||
void
|
void
|
||||||
create_geometry( gfx::geometrybank_handle const &Bank );
|
create_geometry( gfx::geometrybank_handle const &Bank );
|
||||||
void create_map_geometry(std::vector<gfx::basic_vertex> &Bank);
|
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);
|
||||||
// provides access to bounding area data
|
// provides access to bounding area data
|
||||||
bounding_area const &
|
bounding_area const &
|
||||||
area() const {
|
area() const {
|
||||||
@@ -277,7 +280,10 @@ public:
|
|||||||
// generates renderable version of held non-instanced geometry
|
// generates renderable version of held non-instanced geometry
|
||||||
void
|
void
|
||||||
create_geometry();
|
create_geometry();
|
||||||
void create_map_geometry(const gfx::geometrybank_handle handle);
|
void
|
||||||
|
create_map_geometry(const gfx::geometrybank_handle handle);
|
||||||
|
void
|
||||||
|
get_map_active_switches(std::vector<gfx::geometrybank_handle> &handles);
|
||||||
// provides access to bounding area data
|
// provides access to bounding area data
|
||||||
bounding_area const &
|
bounding_area const &
|
||||||
area() const {
|
area() const {
|
||||||
|
|||||||
@@ -13,6 +13,8 @@ http://mozilla.org/MPL/2.0/.
|
|||||||
#include "Event.h"
|
#include "Event.h"
|
||||||
#include "MemCell.h"
|
#include "MemCell.h"
|
||||||
|
|
||||||
|
#include "widgets/map_objects.h"
|
||||||
|
|
||||||
namespace scene {
|
namespace scene {
|
||||||
|
|
||||||
node_groups Groups;
|
node_groups Groups;
|
||||||
@@ -28,7 +30,30 @@ node_groups::create() {
|
|||||||
|
|
||||||
// indicates creation of current group ended. returns: handle to the parent group or null_handle if group stack is empty
|
// indicates creation of current group ended. returns: handle to the parent group or null_handle if group stack is empty
|
||||||
scene::group_handle
|
scene::group_handle
|
||||||
node_groups::close() {
|
node_groups::close()
|
||||||
|
{
|
||||||
|
if (!m_activegroup.empty()) {
|
||||||
|
for (basic_node *node : m_groupmap[m_activegroup.top()].nodes) {
|
||||||
|
std::string postfix { "sem_mem" };
|
||||||
|
|
||||||
|
if (typeid(TMemCell) == typeid(*node) && string_ends_with(node->name(), postfix)) {
|
||||||
|
std::string sem_name = node->name().substr(0, node->name().length() - postfix.length());
|
||||||
|
|
||||||
|
map::Semaphores.emplace_back();
|
||||||
|
map::semaphore &sem_info = map::Semaphores.back();
|
||||||
|
|
||||||
|
sem_info.location = node->location();
|
||||||
|
sem_info.name = sem_name;
|
||||||
|
|
||||||
|
for (basic_event *event : m_groupmap[m_activegroup.top()].events) {
|
||||||
|
if (string_starts_with(event->name(), sem_name)
|
||||||
|
&& event->name().substr(sem_name.length()).find("sem") == std::string::npos) {
|
||||||
|
sem_info.events.push_back(event);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if( false == m_activegroup.empty() ) {
|
if( false == m_activegroup.empty() ) {
|
||||||
|
|
||||||
@@ -46,6 +71,7 @@ node_groups::close() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return handle();
|
return handle();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -4,5 +4,5 @@ layout(location = 0) out vec4 out_color;
|
|||||||
|
|
||||||
void main()
|
void main()
|
||||||
{
|
{
|
||||||
out_color = vec4(0.5f);
|
out_color = vec4(vec3(0.3f, time, 0.3f), 1.0f);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -252,6 +252,22 @@ std::string to_hex_str( int const Value, int const Width )
|
|||||||
return converter.str();
|
return converter.str();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
bool string_ends_with(const std::string &string, const std::string &ending)
|
||||||
|
{
|
||||||
|
if (string.length() < ending.length())
|
||||||
|
return false;
|
||||||
|
|
||||||
|
return string.compare(string.length() - ending.length(), ending.length(), ending) == 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool string_starts_with(const std::string &string, const std::string &begin)
|
||||||
|
{
|
||||||
|
if (string.length() < begin.length())
|
||||||
|
return false;
|
||||||
|
|
||||||
|
return string.compare(0, begin.length(), begin) == 0;
|
||||||
|
}
|
||||||
|
|
||||||
int stol_def(const std::string &str, const int &DefaultValue) {
|
int stol_def(const std::string &str, const int &DefaultValue) {
|
||||||
|
|
||||||
int result { DefaultValue };
|
int result { DefaultValue };
|
||||||
|
|||||||
@@ -135,6 +135,9 @@ std::string to_string( glm::tvec4<Type_, Precision_> const &Value, int const Wid
|
|||||||
return to_string( Value.x, Width ) + ", " + to_string( Value.y, Width ) + ", " + to_string( Value.z, Width ) + ", " + to_string( Value.w, Width );
|
return to_string( Value.x, Width ) + ", " + to_string( Value.y, Width ) + ", " + to_string( Value.z, Width ) + ", " + to_string( Value.w, Width );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool string_ends_with(std::string const &string, std::string const &ending);
|
||||||
|
bool string_starts_with(std::string const &string, std::string const &begin);
|
||||||
|
|
||||||
int stol_def(const std::string & str, const int & DefaultValue);
|
int stol_def(const std::string & str, const int & DefaultValue);
|
||||||
|
|
||||||
std::string ToLower(std::string const &text);
|
std::string ToLower(std::string const &text);
|
||||||
|
|||||||
@@ -67,6 +67,7 @@ void ui::map_panel::render_map_texture(glm::mat4 transform, glm::vec2 surface_si
|
|||||||
frustum.calculate(transform, glm::mat4());
|
frustum.calculate(transform, glm::mat4());
|
||||||
|
|
||||||
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++)
|
||||||
{
|
{
|
||||||
@@ -76,15 +77,13 @@ void ui::map_panel::render_map_texture(glm::mat4 transform, glm::vec2 surface_si
|
|||||||
if (section && frustum.sphere_inside(section->area().center, section->area().radius) > 0.f)
|
if (section && frustum.sphere_inside(section->area().center, section->area().radius) > 0.f)
|
||||||
{
|
{
|
||||||
const gfx::geometrybank_handle handle = section->get_map_geometry();
|
const gfx::geometrybank_handle handle = section->get_map_geometry();
|
||||||
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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
scene_ubs.projection = transform;
|
|
||||||
scene_ubo->update(scene_ubs);
|
|
||||||
scene_ubo->bind_uniform();
|
|
||||||
|
|
||||||
glDisable(GL_DEPTH_TEST);
|
glDisable(GL_DEPTH_TEST);
|
||||||
if (Global.iMultisampling)
|
if (Global.iMultisampling)
|
||||||
@@ -102,8 +101,17 @@ void ui::map_panel::render_map_texture(glm::mat4 transform, glm::vec2 surface_si
|
|||||||
glLineWidth(1.5f);
|
glLineWidth(1.5f);
|
||||||
glViewport(0, 0, surface_size.x, surface_size.y);
|
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_ubo->update(scene_ubs);
|
||||||
|
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());
|
||||||
|
|
||||||
|
scene_ubs.time = 0.6f; // color is stuffed in time variable
|
||||||
|
scene_ubo->update(scene_ubs);
|
||||||
|
GfxRenderer.Draw_Geometry(m_switch_handles.begin(), m_switch_handles.end());
|
||||||
|
|
||||||
if (Global.iMultisampling)
|
if (Global.iMultisampling)
|
||||||
m_fb->blit_from(m_msaa_fb.get(), surface_size.x, surface_size.y, GL_COLOR_BUFFER_BIT, GL_COLOR_ATTACHMENT0);
|
m_fb->blit_from(m_msaa_fb.get(), surface_size.x, surface_size.y, GL_COLOR_BUFFER_BIT, GL_COLOR_ATTACHMENT0);
|
||||||
|
|
||||||
@@ -215,7 +223,6 @@ void ui::map_panel::render_contents()
|
|||||||
if (ImGui::IsItemHovered())
|
if (ImGui::IsItemHovered())
|
||||||
{
|
{
|
||||||
if (mode == 0 && ImGui::IsMouseDragging(0)) {
|
if (mode == 0 && ImGui::IsMouseDragging(0)) {
|
||||||
WriteLog("drag");
|
|
||||||
ImVec2 delta_im = ImGui::GetMouseDragDelta();
|
ImVec2 delta_im = ImGui::GetMouseDragDelta();
|
||||||
ImGui::ResetMouseDragDelta();
|
ImGui::ResetMouseDragDelta();
|
||||||
|
|
||||||
@@ -226,7 +233,6 @@ void ui::map_panel::render_contents()
|
|||||||
translate -= delta * 2.0f;
|
translate -= delta * 2.0f;
|
||||||
}
|
}
|
||||||
if (ImGui::IsMouseClicked(1)) {
|
if (ImGui::IsMouseClicked(1)) {
|
||||||
WriteLog("click");
|
|
||||||
ImVec2 screen_pos = ImGui::GetMousePos();
|
ImVec2 screen_pos = ImGui::GetMousePos();
|
||||||
glm::vec2 surface_pos(screen_pos.x - screen_origin.x, screen_pos.y - screen_origin.y);
|
glm::vec2 surface_pos(screen_pos.x - screen_origin.x, screen_pos.y - screen_origin.y);
|
||||||
glm::vec2 ndc_pos = surface_pos / surface_size * 2.0f - 1.0f;
|
glm::vec2 ndc_pos = surface_pos / surface_size * 2.0f - 1.0f;
|
||||||
@@ -241,9 +247,6 @@ void ui::map_panel::render_contents()
|
|||||||
else if (launcher->Event2)
|
else if (launcher->Event2)
|
||||||
relay.post(user_command::queueevent, (double)simulation::Events.GetEventId(launcher->Event2), 0.0, GLFW_PRESS, 0);
|
relay.post(user_command::queueevent, (double)simulation::Events.GetEventId(launcher->Event2), 0.0, GLFW_PRESS, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
WriteLog(std::to_string(world_pos.x) + "," + std::to_string(world_pos.z));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -19,6 +19,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;
|
||||||
|
|
||||||
const int fb_size = 1024;
|
const int fb_size = 1024;
|
||||||
|
|
||||||
|
|||||||
4
widgets/map_objects.cpp
Normal file
4
widgets/map_objects.cpp
Normal file
@@ -0,0 +1,4 @@
|
|||||||
|
#include "widgets/map_objects.h"
|
||||||
|
|
||||||
|
std::vector<map::semaphore> map::Semaphores;
|
||||||
|
std::vector<map::track_switch> map::Switches;
|
||||||
22
widgets/map_objects.h
Normal file
22
widgets/map_objects.h
Normal file
@@ -0,0 +1,22 @@
|
|||||||
|
#include "simulation.h"
|
||||||
|
#include "event.h"
|
||||||
|
#include "scene.h"
|
||||||
|
|
||||||
|
namespace map {
|
||||||
|
|
||||||
|
// semaphore description (only for minimap purposes)
|
||||||
|
struct semaphore {
|
||||||
|
std::string name;
|
||||||
|
glm::vec3 location;
|
||||||
|
|
||||||
|
std::vector<basic_event *> events;
|
||||||
|
};
|
||||||
|
|
||||||
|
// switch description (only for minimap purposes)
|
||||||
|
struct track_switch {
|
||||||
|
glm::vec3 location;
|
||||||
|
};
|
||||||
|
|
||||||
|
extern std::vector<semaphore> Semaphores;
|
||||||
|
extern std::vector<track_switch> Switches;
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user