mirror of
https://github.com/MaSzyna-EU07/maszyna.git
synced 2026-03-22 15:05:03 +01:00
map work
This commit is contained in:
2
Timer.h
2
Timer.h
@@ -53,7 +53,7 @@ struct subsystem_stopwatches {
|
||||
stopwatch gfx_shadows;
|
||||
stopwatch gfx_reflections;
|
||||
stopwatch gfx_swap;
|
||||
stopwatch gfx_gui;
|
||||
stopwatch gfx_gui;
|
||||
stopwatch sim_total;
|
||||
stopwatch sim_dynamics;
|
||||
stopwatch sim_events;
|
||||
|
||||
@@ -247,7 +247,7 @@ drivermouse_input::scroll( double const Xoffset, double const Yoffset ) {
|
||||
|
||||
if( Global.ctrlState ) {
|
||||
// ctrl + scroll wheel adjusts fov
|
||||
Global.FieldOfView = clamp( static_cast<float>( Global.FieldOfView - Yoffset * 20.0 / Timer::subsystem.gfx_total.average() ), 15.0f, 75.0f );
|
||||
Global.FieldOfView = clamp( static_cast<float>( Global.FieldOfView - Yoffset * 20.0 / Timer::subsystem.mainloop_total.average() ), 15.0f, 75.0f );
|
||||
}
|
||||
else {
|
||||
// scroll adjusts master controller
|
||||
|
||||
30
renderer.cpp
30
renderer.cpp
@@ -367,9 +367,7 @@ std::unique_ptr<gl::program> opengl_renderer::make_shader(std::string v, std::st
|
||||
|
||||
bool opengl_renderer::Render()
|
||||
{
|
||||
Timer::subsystem.gfx_total.stop();
|
||||
Timer::subsystem.gfx_total.start(); // note: gfx_total is actually frame total, clean this up
|
||||
Timer::subsystem.gfx_color.start();
|
||||
Timer::subsystem.gfx_total.start();
|
||||
|
||||
GLuint gl_time_ready;
|
||||
if (!Global.gfx_usegles)
|
||||
@@ -404,7 +402,6 @@ bool opengl_renderer::Render()
|
||||
m_debugstats = debug_stats();
|
||||
|
||||
Render_pass(rendermode::color);
|
||||
Timer::subsystem.gfx_color.stop();
|
||||
|
||||
m_drawcount = m_cellqueue.size();
|
||||
m_debugtimestext.clear();
|
||||
@@ -430,6 +427,8 @@ bool opengl_renderer::Render()
|
||||
|
||||
++m_framestamp;
|
||||
|
||||
Timer::subsystem.gfx_total.stop();
|
||||
|
||||
return true; // for now always succeed
|
||||
}
|
||||
|
||||
@@ -551,6 +550,7 @@ void opengl_renderer::Render_pass(rendermode const Mode)
|
||||
|
||||
glEnable(GL_DEPTH_TEST);
|
||||
|
||||
Timer::subsystem.gfx_color.start();
|
||||
setup_matrices();
|
||||
setup_drawing(true);
|
||||
|
||||
@@ -621,6 +621,8 @@ void opengl_renderer::Render_pass(rendermode const Mode)
|
||||
Render_cab(vehicle, vehicle->InteriorLightLevel, true);
|
||||
}
|
||||
|
||||
Timer::subsystem.gfx_color.stop();
|
||||
|
||||
setup_shadow_map(nullptr, m_renderpass);
|
||||
setup_env_map(nullptr);
|
||||
|
||||
@@ -656,9 +658,13 @@ void opengl_renderer::Render_pass(rendermode const Mode)
|
||||
glDisable(GL_FRAMEBUFFER_SRGB);
|
||||
|
||||
glDebug("uilayer render");
|
||||
Timer::subsystem.gfx_gui.start();
|
||||
|
||||
draw_debug_ui();
|
||||
Application.render_ui();
|
||||
|
||||
Timer::subsystem.gfx_gui.stop();
|
||||
|
||||
// restore binding
|
||||
scene_ubo->bind_uniform();
|
||||
|
||||
@@ -1943,6 +1949,11 @@ void opengl_renderer::Draw_Geometry(std::vector<gfx::geometrybank_handle>::itera
|
||||
m_geometry.draw(begin, end);
|
||||
}
|
||||
|
||||
void opengl_renderer::Draw_Geometry(const gfx::geometrybank_handle &handle)
|
||||
{
|
||||
m_geometry.draw(handle);
|
||||
}
|
||||
|
||||
void opengl_renderer::draw(const gfx::geometry_handle &handle)
|
||||
{
|
||||
model_ubs.set_modelview(OpenGLMatrices.data(GL_MODELVIEW));
|
||||
@@ -3537,10 +3548,11 @@ glm::dvec3 opengl_renderer::get_mouse_depth()
|
||||
|
||||
if (pointdepth != std::numeric_limits<float>::max())
|
||||
{
|
||||
if (GLAD_GL_ARB_clip_control || GLAD_GL_EXT_clip_control)
|
||||
m_worldmousecoordinates = glm::unProjectZO(glm::vec3(bufferpos, pointdepth), glm::mat4(glm::mat3(m_colorpass.camera.modelview())), m_colorpass.camera.projection(),
|
||||
glm::vec4(0, 0, Global.gfx_framebuffer_width, Global.gfx_framebuffer_height));
|
||||
else
|
||||
if (GLAD_GL_ARB_clip_control || GLAD_GL_EXT_clip_control) {
|
||||
if (pointdepth > 0.0f)
|
||||
m_worldmousecoordinates = glm::unProjectZO(glm::vec3(bufferpos, pointdepth), glm::mat4(glm::mat3(m_colorpass.camera.modelview())), m_colorpass.camera.projection(),
|
||||
glm::vec4(0, 0, Global.gfx_framebuffer_width, Global.gfx_framebuffer_height));
|
||||
} else if (pointdepth < 1.0f)
|
||||
m_worldmousecoordinates = glm::unProjectNO(glm::vec3(bufferpos, pointdepth), glm::mat4(glm::mat3(m_colorpass.camera.modelview())), m_colorpass.camera.projection(),
|
||||
glm::vec4(0, 0, Global.gfx_framebuffer_width, Global.gfx_framebuffer_height));
|
||||
}
|
||||
@@ -3563,7 +3575,7 @@ void opengl_renderer::Update(double const Deltatime)
|
||||
}
|
||||
|
||||
m_updateaccumulator = 0.0;
|
||||
m_framerate = 1000.f / (Timer::subsystem.gfx_total.average());
|
||||
m_framerate = 1000.f / (Timer::subsystem.mainloop_total.average());
|
||||
|
||||
// adjust draw ranges etc, based on recent performance
|
||||
auto const framerate = 1000.f / Timer::subsystem.gfx_color.average();
|
||||
|
||||
@@ -149,6 +149,7 @@ class opengl_renderer
|
||||
bool Append(gfx::vertex_array &Vertices, gfx::geometry_handle const &Geometry, int const Type);
|
||||
// draws supplied geometry handles
|
||||
void Draw_Geometry(std::vector<gfx::geometrybank_handle>::iterator begin, std::vector<gfx::geometrybank_handle>::iterator end);
|
||||
void Draw_Geometry(const gfx::geometrybank_handle &handle);
|
||||
// provides direct access to vertex data of specfied chunk
|
||||
gfx::vertex_array const &Vertices(gfx::geometry_handle const &Geometry) const;
|
||||
// material methods
|
||||
|
||||
@@ -20,6 +20,7 @@ http://mozilla.org/MPL/2.0/.
|
||||
#include "Logs.h"
|
||||
#include "sn_utils.h"
|
||||
#include "renderer.h"
|
||||
#include "widgets/map_objects.h"
|
||||
|
||||
namespace scene {
|
||||
|
||||
@@ -1669,6 +1670,13 @@ void basic_region::create_map_geometry()
|
||||
if (s)
|
||||
s->create_map_geometry(m_map_geometrybank);
|
||||
}
|
||||
|
||||
std::vector<gfx::basic_vertex> vertices;
|
||||
for (const auto sem : map::Semaphores) {
|
||||
vertices.push_back(gfx::basic_vertex(sem->location, glm::vec3(), glm::vec3()));
|
||||
}
|
||||
gfx::geometrybank_handle poibank = GfxRenderer.Create_Bank();
|
||||
m_map_poipoints = GfxRenderer.Insert(vertices, poibank, GL_POINTS);
|
||||
}
|
||||
|
||||
} // scene
|
||||
|
||||
6
scene.h
6
scene.h
@@ -403,11 +403,14 @@ public:
|
||||
// finds sections inside specified sphere. returns: list of sections
|
||||
std::vector<basic_section *> const &
|
||||
sections( glm::dvec3 const &Point, float const Radius );
|
||||
void create_map_geometry();
|
||||
void
|
||||
create_map_geometry();
|
||||
basic_section* get_section(size_t section)
|
||||
{
|
||||
return m_sections[section];
|
||||
}
|
||||
gfx::geometrybank_handle
|
||||
get_map_poi_geometry() { return m_map_poipoints; }
|
||||
|
||||
private:
|
||||
// types
|
||||
@@ -419,6 +422,7 @@ private:
|
||||
};
|
||||
|
||||
gfx::geometrybank_handle m_map_geometrybank;
|
||||
gfx::geometrybank_handle m_map_poipoints;
|
||||
|
||||
// methods
|
||||
// checks whether specified point is within boundaries of the region
|
||||
|
||||
@@ -49,7 +49,7 @@ void
|
||||
bounding_area::deserialize( std::istream &Input ) {
|
||||
|
||||
center = sn_utils::d_dvec3( Input );
|
||||
radius = sn_utils::ld_float32( Input );
|
||||
radius = std::max(radius, sn_utils::ld_float32( Input ));
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -39,16 +39,16 @@ node_groups::close()
|
||||
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();
|
||||
map::Semaphores.push_back(std::make_shared<map::semaphore>());
|
||||
auto sem_info = map::Semaphores.back();
|
||||
|
||||
sem_info.location = node->location();
|
||||
sem_info.name = sem_name;
|
||||
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);
|
||||
sem_info->events.push_back(event);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -216,8 +216,6 @@ void ui_layer::update()
|
||||
|
||||
void ui_layer::render()
|
||||
{
|
||||
Timer::subsystem.gfx_gui.start();
|
||||
|
||||
render_background();
|
||||
render_progress();
|
||||
|
||||
@@ -232,8 +230,6 @@ void ui_layer::render()
|
||||
gl::buffer::unbind(gl::buffer::ARRAY_BUFFER);
|
||||
ImGui::Render();
|
||||
|
||||
Timer::subsystem.gfx_gui.stop();
|
||||
|
||||
#ifdef EU07_USEIMGUIIMPLOPENGL2
|
||||
ImGui_ImplOpenGL2_RenderDrawData(ImGui::GetDrawData());
|
||||
ImGui_ImplOpenGL2_NewFrame();
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
#include "stdafx.h"
|
||||
#include "widgets/map.h"
|
||||
#include "widgets/map_objects.h"
|
||||
#include "imgui/imgui.h"
|
||||
#include "Logs.h"
|
||||
#include "Train.h"
|
||||
@@ -108,10 +109,17 @@ void ui::map_panel::render_map_texture(glm::mat4 transform, glm::vec2 surface_si
|
||||
|
||||
GfxRenderer.Draw_Geometry(m_section_handles.begin(), m_section_handles.end());
|
||||
|
||||
glLineWidth(3.0f);
|
||||
|
||||
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());
|
||||
|
||||
glPointSize(3.0f);
|
||||
scene_ubs.time = 0.0f;
|
||||
scene_ubo->update(scene_ubs);
|
||||
GfxRenderer.Draw_Geometry(simulation::Region->get_map_poi_geometry());
|
||||
|
||||
if (Global.iMultisampling)
|
||||
m_fb->blit_from(m_msaa_fb.get(), surface_size.x, surface_size.y, GL_COLOR_BUFFER_BIT, GL_COLOR_ATTACHMENT0);
|
||||
|
||||
@@ -143,6 +151,24 @@ void ui::map_panel::render_labels(glm::mat4 transform, ImVec2 origin, glm::vec2
|
||||
ImGui::TextUnformatted(desc);
|
||||
}
|
||||
ImGui::PopStyleColor();
|
||||
|
||||
if (zoom > 0.005f) {
|
||||
ImGui::PushStyleColor(ImGuiCol_Text, ImVec4(0.7f, 1.0f, 1.0f, 0.7f));
|
||||
for (auto sem : map::Semaphores) {
|
||||
glm::vec4 ndc_pos = transform * glm::vec4(sem->location, 1.0f);
|
||||
if (glm::abs(ndc_pos.x) > 1.0f || glm::abs(ndc_pos.z) > 1.0f)
|
||||
continue;
|
||||
|
||||
glm::vec2 gui_pos = (glm::vec2(ndc_pos.x, -ndc_pos.z) / 2.0f + 0.5f) * glm::vec2(surface_size.x, surface_size.y);
|
||||
|
||||
const char *desc = sem->name.c_str();
|
||||
ImVec2 textsize = ImGui::CalcTextSize(desc);
|
||||
ImGui::SetCursorPos(ImVec2(origin.x + gui_pos.x - textsize.x / 2.0f,
|
||||
origin.y + gui_pos.y - textsize.y / 2.0f));
|
||||
ImGui::TextUnformatted(desc);
|
||||
}
|
||||
ImGui::PopStyleColor();
|
||||
}
|
||||
}
|
||||
|
||||
void ui::map_panel::render_contents()
|
||||
@@ -150,6 +176,19 @@ void ui::map_panel::render_contents()
|
||||
if (!init_done)
|
||||
return;
|
||||
|
||||
if (active) {
|
||||
if (ImGui::BeginPopup("Sem")) {
|
||||
for (auto ev : active->events)
|
||||
if (ImGui::Button(ev->name().c_str())) {
|
||||
active.reset();
|
||||
command_relay relay;
|
||||
relay.post(user_command::queueevent, (double)simulation::Events.GetEventId(ev), 0.0, GLFW_PRESS, 0);
|
||||
break;
|
||||
}
|
||||
ImGui::EndPopup();
|
||||
}
|
||||
}
|
||||
|
||||
float prev_zoom = zoom;
|
||||
|
||||
if (ImGui::Button("-"))
|
||||
@@ -238,14 +277,44 @@ void ui::map_panel::render_contents()
|
||||
glm::vec2 ndc_pos = surface_pos / surface_size * 2.0f - 1.0f;
|
||||
glm::vec3 world_pos = glm::inverse(transform) * glm::vec4(ndc_pos.x, 0.0f, -ndc_pos.y, 1.0f);
|
||||
|
||||
std::vector<TEventLauncher *> launchers = simulation::Events.find_eventlaunchers(glm::vec2(world_pos.x, world_pos.z), 15.0f);
|
||||
std::vector<TEventLauncher *> launchers = simulation::Events.find_eventlaunchers(glm::vec2(world_pos.x, world_pos.z), 10.0f);
|
||||
|
||||
float distx = 1000000.0f;
|
||||
|
||||
TEventLauncher *lau = nullptr;
|
||||
for (auto launcher : launchers) {
|
||||
float distance = glm::distance2(glm::vec2(launcher->location().x, launcher->location().z),
|
||||
glm::vec2(world_pos.x, world_pos.z));
|
||||
if (distance < distx) {
|
||||
lau = launcher;
|
||||
distx = distance;
|
||||
}
|
||||
}
|
||||
|
||||
if (lau) {
|
||||
command_relay relay;
|
||||
if (!Global.shiftState && launcher->Event1)
|
||||
relay.post(user_command::queueevent, (double)simulation::Events.GetEventId(launcher->Event1), 0.0, GLFW_PRESS, 0);
|
||||
else if (launcher->Event2)
|
||||
relay.post(user_command::queueevent, (double)simulation::Events.GetEventId(launcher->Event2), 0.0, GLFW_PRESS, 0);
|
||||
if (!Global.shiftState && lau->Event1)
|
||||
relay.post(user_command::queueevent, (double)simulation::Events.GetEventId(lau->Event1), 0.0, GLFW_PRESS, 0);
|
||||
else if (lau->Event2)
|
||||
relay.post(user_command::queueevent, (double)simulation::Events.GetEventId(lau->Event2), 0.0, GLFW_PRESS, 0);
|
||||
}
|
||||
|
||||
std::vector<std::shared_ptr<map::semaphore>> list;
|
||||
|
||||
for (auto entry : map::Semaphores) {
|
||||
float distance = glm::distance2(glm::vec2(entry->location.x, entry->location.z),
|
||||
glm::vec2(world_pos.x, world_pos.z));
|
||||
if (distance < 100.0f) {
|
||||
if (distance < distx) {
|
||||
list.clear();
|
||||
list.push_back(entry);
|
||||
distx = distance;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!list.empty()) {
|
||||
ImGui::OpenPopup("Sem");
|
||||
active.emplace(*list[0].get());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,9 +4,21 @@
|
||||
#include "renderer.h"
|
||||
#include "Texture.h"
|
||||
#include "uilayer.h"
|
||||
#include "widgets/map_objects.h"
|
||||
|
||||
namespace ui {
|
||||
|
||||
class disambiguation_popup {
|
||||
std::string m_id;
|
||||
std::vector<map::semaphore> m_list;
|
||||
|
||||
public:
|
||||
disambiguation_popup(std::string &&id, std::vector<map::semaphore> &&list)
|
||||
: m_id(id), m_list(list) {}
|
||||
|
||||
void render();
|
||||
};
|
||||
|
||||
class map_panel : public ui_panel {
|
||||
std::unique_ptr<gl::program> m_shader;
|
||||
std::unique_ptr<gl::framebuffer> m_msaa_fb;
|
||||
@@ -31,6 +43,8 @@ class map_panel : public ui_panel {
|
||||
|
||||
bool init_done = false;
|
||||
|
||||
std::optional<map::semaphore> active;
|
||||
|
||||
public:
|
||||
map_panel();
|
||||
void render_contents() override;
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
#include "widgets/map_objects.h"
|
||||
|
||||
std::vector<map::semaphore> map::Semaphores;
|
||||
std::vector<map::track_switch> map::Switches;
|
||||
std::vector<std::shared_ptr<map::semaphore>> map::Semaphores;
|
||||
std::vector<std::shared_ptr<map::track_switch>> map::Switches;
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
#pragma once
|
||||
|
||||
#include "simulation.h"
|
||||
#include "event.h"
|
||||
#include "scene.h"
|
||||
@@ -17,6 +19,6 @@ namespace map {
|
||||
glm::vec3 location;
|
||||
};
|
||||
|
||||
extern std::vector<semaphore> Semaphores;
|
||||
extern std::vector<track_switch> Switches;
|
||||
extern std::vector<std::shared_ptr<semaphore>> Semaphores;
|
||||
extern std::vector<std::shared_ptr<track_switch>> Switches;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user