Merge branch 'gfx-work' into nodecloner

This commit is contained in:
milek7
2019-03-01 00:10:31 +01:00
22 changed files with 234 additions and 42 deletions

View File

@@ -167,7 +167,6 @@ if (WIN32)
set(GLFW3_INCLUDE_DIR ${GLFW3_INCLUDE_DIR} "${DEPS_DIR}/glfw/include/")
set(PNG_PNG_INCLUDE_DIR ${PNG_PNG_INCLUDE_DIR} "${DEPS_DIR}/libpng/include/")
set(ZLIB_INCLUDE_DIR ${ZLIB_INCLUDE_DIR} "${DEPS_DIR}/zlib/")
set(GLM_INCLUDE_DIR ${GLM_INCLUDE_DIR} "${DEPS_DIR}/glm/")
set(OPENAL_INCLUDE_DIR ${OPENAL_INCLUDE_DIR} "${DEPS_DIR}/openal/include")
set(LIBSNDFILE_INCLUDE_DIR ${LIBSNDFILE_INCLUDE_DIR} "${DEPS_DIR}/libsndfile/include")
set(LUAJIT_INCLUDE_DIR ${LUAJIT_INCLUDE_DIR} "${DEPS_DIR}/luajit/include")
@@ -191,6 +190,8 @@ if (WIN32)
set(libserialport_LIBRARY ${LIBSERIALPORT_LIBRARY} "${DEPS_DIR}/libserialport/lib/${ARCH}/libserialport-0.lib")
endif()
set(GLM_INCLUDE_DIR ${GLM_INCLUDE_DIR} "${DEPS_DIR}/glm/")
if (${CMAKE_CXX_COMPILER_ID} STREQUAL MSVC)
set(SOURCES ${SOURCES} "eu07.rc")
set(SOURCES ${SOURCES} "eu07.ico")
@@ -199,10 +200,6 @@ endif()
add_executable(${PROJECT_NAME} ${SOURCES} ${HEADERS})
set_target_properties(${PROJECT_NAME} PROPERTIES COTIRE_CXX_PREFIX_HEADER_INIT "stdafx.h")
set_target_properties(${PROJECT_NAME} PROPERTIES COTIRE_ADD_UNITY_BUILD FALSE)
cotire(${PROJECT_NAME})
if (${CMAKE_CXX_COMPILER_ID} STREQUAL MSVC)
# /wd4996: disable "deprecation" warnings
# /wd4244: disable warnings for conversion with possible loss of data
@@ -239,7 +236,7 @@ find_package(Threads REQUIRED)
target_link_libraries(${PROJECT_NAME} Threads::Threads)
find_package(GLM REQUIRED)
include_directories(${GLM_INCLUDE_DIRS})
include_directories(${GLM_INCLUDE_DIR})
find_package(OpenAL REQUIRED)
include_directories(${OPENAL_INCLUDE_DIR})
@@ -263,3 +260,7 @@ target_link_libraries(${PROJECT_NAME} ASIO::ASIO)
if (WIN32)
target_link_libraries(${PROJECT_NAME} ws2_32)
endif()
set_target_properties(${PROJECT_NAME} PROPERTIES COTIRE_CXX_PREFIX_HEADER_INIT "stdafx.h")
set_target_properties(${PROJECT_NAME} PROPERTIES COTIRE_ADD_UNITY_BUILD FALSE)
cotire(${PROJECT_NAME})

View File

@@ -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;

View File

@@ -615,7 +615,9 @@ eu07_application::init_glfw() {
}
else
{
#ifdef GLFW_CONTEXT_CREATION_API
glfwWindowHint(GLFW_CONTEXT_CREATION_API, GLFW_EGL_CONTEXT_API);
#endif
glfwWindowHint(GLFW_CLIENT_API, GLFW_OPENGL_ES_API);
glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 0);

79
azure-pipelines.yml Normal file
View File

@@ -0,0 +1,79 @@
jobs:
- job: ubuntu1604
pool:
vmImage: 'Ubuntu-16.04'
displayName: 'Ubuntu 16.04 x86-64'
steps:
- script: |
sudo add-apt-repository ppa:ubuntu-toolchain-r/test
sudo apt-get update -y
sudo apt-get install -y libglfw3-dev python2.7-dev libpng16-dev libopenal-dev libluajit-5.1-dev libserialport-dev libsndfile1-dev
sudo apt-get install -y gcc-8 g++-8
sudo update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-8 100
sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-8 100
cd ref
git clone "https://github.com/chriskohlhoff/asio" --depth 1 --branch asio-1-12-2 -q
displayName: 'Install dependencies'
- script: |
mkdir build
cd build
cmake .. -DCMAKE_BUILD_TYPE=Release
cmake --build .
displayName: 'Build'
- task: PublishBuildArtifacts@1
inputs:
pathtoPublish: 'build/bin'
artifactName: binaries
displayName: 'Publish binaries'
- job: windows_x64
pool:
vmImage: 'vs2017-win2016'
displayName: 'Windows VS2017 x86-64'
steps:
- script: |
cd ref
git clone "https://github.com/chriskohlhoff/asio" --depth 1 --branch asio-1-12-2 -q
displayName: 'Download extra dependencies'
- script: |
mkdir build
cd build
cmake .. -A x64
cmake --build . --config RelWithDebInfo
displayName: 'Build'
- task: PublishBuildArtifacts@1
inputs:
pathtoPublish: 'build/bin'
artifactName: binaries
displayName: 'Publish binaries'
- task: PublishBuildArtifacts@1
inputs:
pathtoPublish: 'build/pdb'
artifactName: symbols
displayName: 'Publish symbols'
- job: windows_x32
pool:
vmImage: 'vs2017-win2016'
displayName: 'Windows VS2017 x86'
steps:
- script: |
cd ref
git clone "https://github.com/chriskohlhoff/asio" --depth 1 --branch asio-1-12-2 -q
displayName: 'Download extra dependencies'
- script: |
mkdir build
cd build
cmake .. -A Win32 -T v141_xp
cmake --build . --config RelWithDebInfo
displayName: 'Build'
- task: PublishBuildArtifacts@1
inputs:
pathtoPublish: 'build/bin'
artifactName: binaries
displayName: 'Publish binaries'
- task: PublishBuildArtifacts@1
inputs:
pathtoPublish: 'build/pdb'
artifactName: symbols
displayName: 'Publish symbols'

View File

@@ -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

View File

@@ -61,7 +61,7 @@ namespace gl
void set_modelview(const glm::mat4 &mv)
{
modelview = mv;
modelviewnormal = glm::mat3(glm::transpose(glm::inverse(mv)));
modelviewnormal = glm::mat3x4(glm::mat3(glm::transpose(glm::inverse(mv))));
}
};

Binary file not shown.

Binary file not shown.

View File

@@ -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();

View File

@@ -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

View File

@@ -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

View File

@@ -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

View File

@@ -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 ));
}

View File

@@ -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);
}
}
}

View File

@@ -85,6 +85,12 @@
//#define GLFW_INCLUDE_GLU
#include <GLFW/glfw3.h>
#ifndef GLFW_TRUE
#define GLFW_FALSE 0
#define GLFW_TRUE 1
#define glfwGetKeyName(a, b) ("")
#endif
#define GLM_ENABLE_EXPERIMENTAL
#define GLM_FORCE_CTOR_INIT
#include <glm/glm.hpp>

View File

@@ -51,8 +51,6 @@ texture_window::texture_window(texture_handle src, std::string surfacename)
glfwSetWindowUserPointer(m_window, this);
glfwSetFramebufferSizeCallback(m_window, texture_window_fb_resize);
glfwFocusWindow(root);
m_renderthread = std::make_unique<std::thread>(&texture_window::threadfunc, this);
}

View File

@@ -14,7 +14,7 @@ uart_input::uart_input()
if (sp_get_port_by_name(conf.port.c_str(), &port) != SP_OK)
throw std::runtime_error("uart: cannot find specified port");
if (sp_open(port, SP_MODE_READ_WRITE) != SP_OK)
if (sp_open(port, (sp_mode)(SP_MODE_READ | SP_MODE_WRITE)) != SP_OK)
throw std::runtime_error("uart: cannot open port");
sp_port_config *config;

View File

@@ -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();

View File

@@ -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());
}
}
}

View File

@@ -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;

View File

@@ -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;

View File

@@ -1,5 +1,7 @@
#pragma once
#include "simulation.h"
#include "event.h"
#include "Event.h"
#include "scene.h"
namespace map {
@@ -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;
}