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

Merge remote-tracking branch 'tmj/master' into sim

This commit is contained in:
milek7
2020-10-18 23:35:14 +02:00
244 changed files with 54164 additions and 11636 deletions

View File

@@ -15,6 +15,17 @@ ui::map_panel::map_panel() : ui_panel(STR_C("Map"), false)
size_max = {fb_size, fb_size};
window_flags = ImGuiWindowFlags_NoScrollbar | ImGuiWindowFlags_NoScrollWithMouse;
#ifdef WITH_OPENGL_MODERN
opengl33_renderer *gl33 = dynamic_cast<opengl33_renderer*>(GfxRenderer.get());
if (!gl33) {
ErrorLog("map not supported on old renderer");
return;
}
#else
ErrorLog("map not supported on old renderer");
return;
#endif
gl::shader vert("map.vert");
gl::shader frag("map.frag");
@@ -23,11 +34,11 @@ ui::map_panel::map_panel() : ui_panel(STR_C("Map"), false)
gl::shader poi_frag("map_poi.frag");
gl::shader poi_geom("map_poi.geom");
m_poi_shader = std::unique_ptr<gl::program>(new gl::program({vert, poi_frag, poi_geom}));
m_icon_atlas = GfxRenderer.Fetch_Texture("map_icons");
m_icon_atlas = GfxRenderer->Fetch_Texture("map_icons");
}
m_tex = std::make_unique<opengl_texture>();
m_tex->alloc_rendertarget(GL_RGB8, GL_RGB, fb_size, fb_size);
m_tex->alloc_rendertarget(GL_RGB8, GL_RGB, fb_size, fb_size);
m_fb = std::make_unique<gl::framebuffer>();
m_fb->attach(*m_tex, GL_COLOR_ATTACHMENT0);
@@ -118,30 +129,33 @@ 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.scene_extra = glm::vec3(0.5f);
scene_ubs.cascade_end = glm::vec4(0.5f, 0.5f, 0.5f, 0.0f);
scene_ubo->update(scene_ubs);
scene_ubo->bind_uniform();
GfxRenderer.Draw_Geometry(m_section_handles.begin(), m_section_handles.end());
#ifdef WITH_OPENGL_MODERN
opengl33_renderer *gl33 = dynamic_cast<opengl33_renderer*>(GfxRenderer.get());
scene_ubs.scene_extra = glm::vec3(0.7f, 0.7f, 0.0f);
gl33->Draw_Geometry(m_section_handles.begin(), m_section_handles.end());
scene_ubs.cascade_end = glm::vec4(0.7f, 0.7f, 0.0f, 0.0f);
scene_ubo->update(scene_ubs);
GfxRenderer.Draw_Geometry(m_colored_paths.future.begin(), m_colored_paths.future.end());
gl33->Draw_Geometry(m_colored_paths.future.begin(), m_colored_paths.future.end());
glLineWidth(3.0f);
scene_ubs.scene_extra = glm::vec3(0.0f, 1.0f, 0.0f);
scene_ubs.cascade_end = glm::vec4(0.0f, 1.0f, 0.0f, 0.0f);
scene_ubo->update(scene_ubs);
GfxRenderer.Draw_Geometry(m_colored_paths.switches.begin(), m_colored_paths.switches.end());
gl33->Draw_Geometry(m_colored_paths.switches.begin(), m_colored_paths.switches.end());
glLineWidth(1.5f);
scene_ubs.scene_extra = glm::vec3(1.0f, 0.0f, 0.0f);
scene_ubs.cascade_end = glm::vec4(1.0f, 0.0f, 0.0f, 0.0f);
scene_ubo->update(scene_ubs);
GfxRenderer.Draw_Geometry(m_colored_paths.occupied.begin(), m_colored_paths.occupied.end());
gl33->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);
gl33->Bind_Texture(0, m_icon_atlas);
m_poi_shader->bind();
scene_ubs.scene_extra = glm::vec3(1.0f / (surface_size / 200.0f), 1.0f);
scene_ubs.cascade_end = glm::vec4(1.0f / (surface_size / 200.0f), 1.0f, 0.0f);
}
if (map::Objects.poi_dirty) {
@@ -150,7 +164,8 @@ void ui::map_panel::render_map_texture(glm::mat4 transform, glm::vec2 surface_si
}
scene_ubo->update(scene_ubs);
GfxRenderer.Draw_Geometry(simulation::Region->get_map_poi_geometry());
gl33->Draw_Geometry(simulation::Region->get_map_poi_geometry());
#endif
if (Global.iMultisampling)
m_fb->blit_from(m_msaa_fb.get(), surface_size.x, surface_size.y, GL_COLOR_BUFFER_BIT, GL_COLOR_ATTACHMENT0);
@@ -184,16 +199,14 @@ void ui::map_panel::render_labels(glm::mat4 transform, ImVec2 origin, glm::vec2
ImGui::TextUnformatted(label.c_str());
}
ImGui::PopStyleColor();
if (zoom > 0.005f)
{
}
}
void ui::map_panel::render_contents()
{
if (!init_done)
return;
if (!init_done) {
is_open = false;
return;
}
{
float prev_zoom = zoom;
@@ -213,11 +226,11 @@ void ui::map_panel::render_contents()
glm::mat4 transform;
transform[0][0] = -1.0f;
ImGui::RadioButton("Pan", (int *)&mode, 0);
ImGui::RadioButton(STR_C("Pan"), (int *)&mode, 0);
ImGui::SameLine();
ImGui::RadioButton("Follow camera", (int *)&mode, 1);
ImGui::RadioButton(STR_C("Follow camera"), (int *)&mode, 1);
ImGui::SameLine();
ImGui::RadioButton("Follow vehicle", (int *)&mode, 2);
ImGui::RadioButton(STR_C("Follow vehicle"), (int *)&mode, 2);
ImVec2 surface_size_im = ImGui::GetContentRegionAvail();
glm::vec2 surface_size(surface_size_im.x, surface_size_im.y);
@@ -359,7 +372,9 @@ void ui::handle_map_object_hover(std::shared_ptr<map::map_object> &obj)
for (int i = 0; i < iMaxNumLights; i++)
{
GfxRenderer.Update_AnimModel(model); // update lamp opacities
#ifdef WITH_OPENGL_MODERN
dynamic_cast<opengl33_renderer*>(GfxRenderer.get())->Update_AnimModel(model); // update lamp opacities
#endif
auto state = model->LightGet(i);
if (!state)
continue;
@@ -413,7 +428,9 @@ void ui::semaphore_window::render_content()
for (int i = 0; i < iMaxNumLights; i++)
{
GfxRenderer.Update_AnimModel(model); // update lamp opacities
#ifdef WITH_OPENGL_MODERN
dynamic_cast<opengl33_renderer*>(GfxRenderer.get())->Update_AnimModel(model); // update lamp opacities
#endif
auto state = model->LightGet(i);
if (!state)
continue;
@@ -535,7 +552,7 @@ void ui::obstacle_insert_window::render_content()
std::vector<gfx::basic_vertex> vertices;
vertices.emplace_back(std::move(obstacle->vertex()));
GfxRenderer.Append(vertices, simulation::Region->get_map_poi_geometry(), GL_POINTS);
GfxRenderer->Append(vertices, simulation::Region->get_map_poi_geometry(), GL_POINTS);
map::Objects.entries.push_back(std::move(obstacle));

View File

@@ -1,11 +1,15 @@
#pragma once
#include "gl/shader.h"
#include "opengl33renderer.h"
#include "Texture.h"
#include "uilayer.h"
#include "widgets/map_objects.h"
#include "widgets/popup.h"
#include "gl/framebuffer.h"
#include "frustum.h"
#ifdef WITH_OPENGL_MODERN
#include "opengl33renderer.h"
#endif
namespace ui
{

View File

@@ -3,6 +3,7 @@
#include "simulation.h"
#include "Event.h"
#include "scene.h"
#include "MemCell.h"
namespace map
{

View File

@@ -8,7 +8,7 @@
ui::vehicleparams_panel::vehicleparams_panel(const std::string &vehicle)
: ui_panel(std::string(STR("Vehicle parameters")) + ": " + vehicle, false), m_vehicle_name(vehicle)
{
vehicle_mini = GfxRenderer.Fetch_Texture("vehicle_mini");
vehicle_mini = GfxRenderer->Fetch_Texture("vehicle_mini");
}
void screen_window_callback(ImGuiSizeCallbackData *data) {
@@ -52,7 +52,7 @@ void ui::vehicleparams_panel::draw_mini(const TMoverParameters &mover)
if (vehicle_mini == null_handle)
return;
opengl_texture &tex = GfxRenderer.Texture(vehicle_mini);
opengl_texture &tex = GfxRenderer->Texture(vehicle_mini);
tex.create();
ImVec2 size = ImGui::GetContentRegionAvail();
@@ -63,9 +63,9 @@ void ui::vehicleparams_panel::draw_mini(const TMoverParameters &mover)
{
ImGui::Image(reinterpret_cast<void*>(tex.id), ImVec2(x, y), ImVec2(0, 1), ImVec2(1, 0));
if (mover.PantRearUp)
if (mover.Pantographs[end::rear].is_active)
draw_infobutton(u8"╨╨╨", ImVec2(126, 10));
if (mover.PantFrontUp)
if (mover.Pantographs[end::front].is_active)
draw_infobutton(u8"╨╨╨", ImVec2(290, 10));
if (mover.Battery)
@@ -149,8 +149,8 @@ void ui::vehicleparams_panel::render_contents()
( mover.Battery ? 'B' : '.' ),
( mover.Mains ? 'M' : '.' ),
( mover.FuseFlag ? '!' : '.' ),
( mover.PantRearUp ? ( mover.PantRearVolt > 0.0 ? 'O' : 'o' ) : '.' ),
( mover.PantFrontUp ? ( mover.PantFrontVolt > 0.0 ? 'P' : 'p' ) : '.' ),
( mover.Pantographs[end::rear].is_active ? ( mover.PantRearVolt > 0.0 ? 'O' : 'o' ) : '.' ),
( mover.Pantographs[end::front].is_active ? ( mover.PantFrontVolt > 0.0 ? 'P' : 'p' ) : '.' ),
( mover.PantPressLockActive ? '!' : ( mover.PantPressSwitchActive ? '*' : '.' ) ),
( mover.WaterPump.is_active ? 'W' : ( false == mover.WaterPump.breaker ? '-' : ( mover.WaterPump.is_enabled ? 'w' : '.' ) ) ),
( true == mover.WaterHeater.is_damaged ? '!' : ( mover.WaterHeater.is_active ? 'H' : ( false == mover.WaterHeater.breaker ? '-' : ( mover.WaterHeater.is_enabled ? 'h' : '.' ) ) ) ),
@@ -259,7 +259,7 @@ void ui::vehicleparams_panel::render_contents()
buffer.data(), buffer.size(),
STR_C("Forces:\n tractive: %.1f, brake: %.1f, friction: %.2f%s\nAcceleration:\n tangential: %.2f, normal: %.2f (path radius: %s)\nVelocity: %.2f, distance traveled: %.2f\nPosition: [%.2f, %.2f, %.2f]"),
// forces
mover.Ft * 0.001f * ( mover.ActiveCab ? mover.ActiveCab : vehicle.ctOwner ? vehicle.ctOwner->Controlling()->ActiveCab : 1 ) + 0.001f,
mover.Ft * 0.001f * ( mover.CabActive ? mover.CabActive : vehicle.ctOwner ? vehicle.ctOwner->Controlling()->CabActive : 1 ) + 0.001f,
mover.Fb * 0.001f,
mover.Adhesive( mover.RunningTrack.friction ),
( mover.SlippingWheels ? " (!)" : "" ),
@@ -280,7 +280,7 @@ void ui::vehicleparams_panel::render_contents()
draw_mini(mover);
if (ImGui::Button(STR_C("Radiostop")))
m_relay.post(user_command::radiostop, 0.0, 0.0, GLFW_PRESS, 0, vehicle_ptr->GetPosition());
m_relay.post(user_command::radiostopsend, 0.0, 0.0, GLFW_PRESS, 0, vehicle_ptr->GetPosition());
ImGui::SameLine();
if (ImGui::Button(STR_C("Stop and repair")))

View File

@@ -3,7 +3,7 @@
#include "uilayer.h"
#include "translation.h"
#include "command.h"
#include "opengl33renderer.h"
#include "renderer.h"
namespace ui
{