16
0
mirror of https://github.com/MaSzyna-EU07/maszyna.git synced 2026-07-17 23:39:18 +02:00

cross switch detection for map manual control

This commit is contained in:
milek7
2020-10-20 02:17:21 +02:00
parent f96575ac79
commit 78305e3b28
10 changed files with 185 additions and 11 deletions

View File

@@ -89,6 +89,7 @@ void ui::map_panel::render_map_texture(glm::mat4 transform, glm::vec2 surface_si
m_colored_paths.switches.clear();
m_colored_paths.occupied.clear();
m_colored_paths.future.clear();
m_colored_paths.highlighted.clear();
m_section_handles.clear();
for (int row = 0; row < scene::EU07_REGIONSIDESECTIONCOUNT; row++)
@@ -112,6 +113,11 @@ void ui::map_panel::render_map_texture(glm::mat4 transform, glm::vec2 surface_si
track->get_map_future_paths(m_colored_paths);
}
for (std::pair<TTrack*, int> &entry : highlighted_switches) {
if (entry.first)
entry.first->get_map_paths_for_state(m_colored_paths, entry.second);
}
glDisable(GL_DEPTH_TEST);
if (Global.iMultisampling)
{
@@ -138,6 +144,12 @@ void ui::map_panel::render_map_texture(glm::mat4 transform, glm::vec2 surface_si
gl33->Draw_Geometry(m_section_handles.begin(), m_section_handles.end());
glLineWidth(4.0f);
scene_ubs.cascade_end = glm::vec4(0.3f, 0.3f, 1.0f, 0.0f);
scene_ubo->update(scene_ubs);
gl33->Draw_Geometry(m_colored_paths.highlighted.begin(), m_colored_paths.highlighted.end());
glLineWidth(1.5f);
scene_ubs.cascade_end = glm::vec4(0.7f, 0.7f, 0.0f, 0.0f);
scene_ubo->update(scene_ubs);
gl33->Draw_Geometry(m_colored_paths.future.begin(), m_colored_paths.future.end());
@@ -349,6 +361,10 @@ void ui::handle_map_object_click(ui_panel &parent, std::shared_ptr<map::map_obje
{
parent.register_popup(std::make_unique<launcher_window>(parent, std::move(track)));
}
else if (auto track_switch = std::dynamic_pointer_cast<map::track_switch>(obj))
{
parent.register_popup(std::make_unique<track_switch_window>(parent, std::move(track_switch)));
}
else if (auto obstacle = std::dynamic_pointer_cast<map::obstacle>(obj))
{
parent.register_popup(std::make_unique<obstacle_remove_window>(parent, std::move(obstacle)));
@@ -506,6 +522,34 @@ void ui::launcher_window::render_content()
}
}
ui::track_switch_window::track_switch_window(ui_panel &panel, std::shared_ptr<map::track_switch> &&sw) : popup(panel), m_switch(sw) {}
void ui::track_switch_window::render_content()
{
auto &highlight = dynamic_cast<map_panel&>(m_parent).highlighted_switches;
ImGui::TextUnformatted(m_switch->name.c_str());
highlight.clear();
std::array<std::string, 4> names = { "ac", "ad", "bc", "bd" };
for (size_t i = 0; i < 4; i++) {
if (m_switch->action[i]) {
if (ImGui::Button(names[i].c_str()))
m_relay.post(user_command::queueevent, 0.0, 0.0, GLFW_PRESS, 0, glm::vec3(0.0f), &m_switch->action[i]->name());
if (ImGui::IsItemHovered()) {
for (size_t j = 0; j < 4; j++) {
if ((names[i][0] - 'a') != j && (names[i][1] - 'a') != j)
continue;
highlight.push_back(std::make_pair(m_switch->track[j], m_switch->preview[i][j] == '1' ? 1 : 0));
}
}
ImGui::SameLine();
}
}
}
ui::obstacle_insert_window::obstacle_insert_window(ui_panel &panel, glm::dvec3 const &pos) : popup(panel), m_position(pos)
{
std::ifstream file;

View File

@@ -46,6 +46,17 @@ class launcher_window : public popup
virtual void render_content() override;
};
class track_switch_window : public popup
{
std::shared_ptr<map::track_switch> m_switch;
command_relay m_relay;
public:
track_switch_window(ui_panel &panel, std::shared_ptr<map::track_switch> &&sw);
virtual void render_content() override;
};
class obstacle_insert_window : public popup
{
glm::dvec3 m_position;
@@ -86,6 +97,8 @@ class vehicle_click_window : public popup
class map_panel : public ui_panel
{
friend class track_switch_window;
std::unique_ptr<gl::program> m_track_shader;
std::unique_ptr<gl::program> m_poi_shader;
std::unique_ptr<gl::framebuffer> m_msaa_fb;
@@ -101,7 +114,7 @@ class map_panel : public ui_panel
std::vector<gfx::geometrybank_handle> m_section_handles;
map_colored_paths m_colored_paths;
const int fb_size = 1024;
const int fb_size = 1024;
glm::vec2 translate;
float zoom = 1.0f / 1000.0f;
@@ -113,7 +126,7 @@ class map_panel : public ui_panel
bool init_done = false;
std::optional<map::semaphore> active;
std::vector<std::pair<TTrack*, int>> highlighted_switches;
public:
map_panel();

View File

@@ -53,6 +53,18 @@ struct launcher : public map_object
}
};
// switch description (only for minimap purposes)
struct track_switch : public map_object
{
std::array<basic_event*, 4> action = { nullptr };
std::array<char[4], 4> preview;
std::array<TTrack*, 4> track = { nullptr };
virtual gfx::basic_vertex vertex() {
return gfx::basic_vertex(location, glm::vec3(), glm::vec2(0.4f, 0.6f));
}
};
// training obstacle description
struct obstacle : public map_object
{