16
0
mirror of https://github.com/MaSzyna-EU07/maszyna.git synced 2026-07-23 00:29:19 +02:00
This commit is contained in:
milek7
2018-10-24 12:59:34 +02:00
parent 472255931d
commit 8abe898735
8 changed files with 150 additions and 120 deletions

View File

@@ -147,6 +147,9 @@ eu07_application::run() {
// main application loop
while (!glfwWindowShouldClose( m_windows.front() ) && !m_modestack.empty())
{
Timer::subsystem.mainloop_total.start();
glfwPollEvents();
if (!m_modes[ m_modestack.top() ]->update())
break;
if (!GfxRenderer.Render())
@@ -154,9 +157,6 @@ eu07_application::run() {
GfxRenderer.SwapBuffers();
Timer::subsystem.mainloop_total.start();
glfwPollEvents();
if (m_modestack.empty())
return 0;

View File

@@ -288,12 +288,13 @@ drivermouse_input::button( int const Button, int const Action ) {
// left mouse button launches on_click event associated with to the node
if( Button == GLFW_MOUSE_BUTTON_LEFT ) {
if( Action == GLFW_PRESS ) {
auto const *node { GfxRenderer.Update_Pick_Node() };
GfxRenderer.pick_node([this](scene::basic_node *node)
{
if( ( node == nullptr )
|| ( typeid( *node ) != typeid( TAnimModel ) ) ) {
|| ( typeid( *node ) != typeid( TAnimModel ) ) )
return;
}
simulation::Region->on_click( static_cast<TAnimModel const *>( node ) );
});
}
}
// right button controls panning
@@ -333,7 +334,10 @@ drivermouse_input::button( int const Button, int const Action ) {
}
else {
// if not release then it's press
auto const lookup = m_buttonbindings.find( simulation::Train->GetLabel( GfxRenderer.Update_Pick_Control() ) );
GfxRenderer.pick_control([this, Button, Action, &mousecommand](TSubModel const *control)
{
auto const lookup = m_buttonbindings.find( simulation::Train->GetLabel( control ) );
if( lookup != m_buttonbindings.end() ) {
// if the recognized element under the cursor has a command associated with the pressed button, notify the recipient
mousecommand = (
@@ -394,6 +398,7 @@ drivermouse_input::button( int const Button, int const Action ) {
m_pickmodepanning = true;
}
}
});
}
}
}

View File

@@ -173,16 +173,16 @@ driver_ui::update() {
if( ( train != nullptr ) && ( false == FreeFlyModeFlag ) ) {
if( false == DebugModeFlag ) {
// in regular mode show control functions, for defined controls
set_tooltip( locale::label_cab_control( train->GetLabel( GfxRenderer.Pick_Control() ) ) );
set_tooltip( locale::label_cab_control( train->GetLabel( GfxRenderer.get_picked_control() ) ) );
}
else {
// in debug mode show names of submodels, to help with cab setup and/or debugging
auto const cabcontrol = GfxRenderer.Pick_Control();
auto const cabcontrol = GfxRenderer.get_picked_control();
set_tooltip( ( cabcontrol ? cabcontrol->pName : "" ) );
}
}
if( ( true == Global.ControlPicking ) && ( true == FreeFlyModeFlag ) && ( true == DebugModeFlag ) ) {
auto const scenerynode = GfxRenderer.Pick_Node();
auto const scenerynode = GfxRenderer.get_picked_node();
set_tooltip(
( scenerynode ?
scenerynode->name() :

View File

@@ -230,17 +230,24 @@ editor_mode::on_mouse_button( int const Button, int const Action, int const Mods
if( Action == GLFW_PRESS ) {
// left button press
m_node = GfxRenderer.Update_Pick_Node();
if( m_node ) {
GfxRenderer.pick_node([this](scene::basic_node *node)
{
if (!m_dragging)
return;
m_node = node;
if( m_node )
Application.set_cursor( GLFW_CURSOR_DISABLED );
}
else
m_dragging = false;
dynamic_cast<editor_ui*>( m_userinterface.get() )->set_node( m_node );
});
m_dragging = true;
}
else {
// left button release
if( m_node ) {
if( m_node )
Application.set_cursor( GLFW_CURSOR_NORMAL );
}
m_dragging = false;
// prime history stack for another snapshot
m_takesnapshot = true;
}

View File

@@ -82,5 +82,5 @@ private:
scene::basic_node *m_node; // currently selected scene node
bool m_takesnapshot { true }; // helper, hints whether snapshot of selected node(s) should be taken before modification
state_backup m_statebackup; // helper, cached variables to be restored on mode exit
bool m_dragging = false;
};

View File

@@ -38,7 +38,7 @@ editor_ui::update() {
if( ( true == Global.ControlPicking )
&& ( true == DebugModeFlag ) ) {
auto const scenerynode = GfxRenderer.Pick_Node();
auto const scenerynode = GfxRenderer.get_picked_node();
set_tooltip(
( scenerynode ?
scenerynode->name() :

View File

@@ -3351,7 +3351,7 @@ void opengl_renderer::Render_Alpha(TSubModel *Submodel)
};
// utility methods
TSubModel const *opengl_renderer::Update_Pick_Control()
void opengl_renderer::Update_Pick_Control()
{
if (!m_picking_pbo->is_busy())
{
@@ -3366,8 +3366,14 @@ TSubModel const *opengl_renderer::Update_Pick_Control()
}
m_pickcontrolitem = control;
for (auto f : m_control_pick_requests)
f(m_pickcontrolitem);
m_control_pick_requests.clear();
}
if (!m_control_pick_requests.empty())
{
// determine point to examine
glm::dvec2 mousepos = Application.get_cursor_pos();
mousepos.y = Global.iWindowHeight - mousepos.y; // cursor coordinates are flipped compared to opengl
@@ -3381,11 +3387,10 @@ TSubModel const *opengl_renderer::Update_Pick_Control()
m_picking_pbo->request_read(pickbufferpos.x, pickbufferpos.y, 1, 1);
m_pick_fb->unbind();
}
return m_pickcontrolitem;
}
}
scene::basic_node *opengl_renderer::Update_Pick_Node()
void opengl_renderer::Update_Pick_Node()
{
if (!m_picking_node_pbo->is_busy())
{
@@ -3400,8 +3405,14 @@ scene::basic_node *opengl_renderer::Update_Pick_Node()
}
m_picksceneryitem = node;
for (auto f : m_node_pick_requests)
f(m_picksceneryitem);
m_node_pick_requests.clear();
}
if (!m_picking_node_pbo->is_busy())
{
// determine point to examine
glm::dvec2 mousepos = Application.get_cursor_pos();
mousepos.y = Global.iWindowHeight - mousepos.y; // cursor coordinates are flipped compared to opengl
@@ -3415,8 +3426,17 @@ scene::basic_node *opengl_renderer::Update_Pick_Node()
m_picking_node_pbo->request_read(pickbufferpos.x, pickbufferpos.y, 1, 1);
m_pick_fb->unbind();
}
}
}
return m_picksceneryitem;
void opengl_renderer::pick_control(std::function<void(TSubModel const *)> callback)
{
m_control_pick_requests.push_back(callback);
}
void opengl_renderer::pick_node(std::function<void(scene::basic_node *)> callback)
{
m_node_pick_requests.push_back(callback);
}
glm::dvec3 opengl_renderer::Update_Mouse_Position()
@@ -3446,6 +3466,9 @@ glm::dvec3 opengl_renderer::Update_Mouse_Position()
void opengl_renderer::Update(double const Deltatime)
{
Update_Pick_Control();
Update_Pick_Node();
m_updateaccumulator += Deltatime;
if (m_updateaccumulator < 1.0)
@@ -3497,22 +3520,11 @@ void opengl_renderer::Update(double const Deltatime)
}
if ((true == Global.ControlPicking) && (false == FreeFlyModeFlag))
{
Update_Pick_Control();
}
else
{
m_pickcontrolitem = nullptr;
}
pick_control([](const TSubModel*) {});
// temporary conditions for testing. eventually will be coupled with editor mode
if ((true == Global.ControlPicking) && (true == DebugModeFlag) && (true == FreeFlyModeFlag))
{
Update_Pick_Node();
}
else
{
m_picksceneryitem = nullptr;
}
pick_node([](scene::basic_node*) {});
// dump last opengl error, if any
auto const glerror = ::glGetError();
if (glerror != GL_NO_ERROR)

View File

@@ -166,11 +166,11 @@ class opengl_renderer
void Bind_Texture(size_t Unit, texture_handle const Texture);
opengl_texture &Texture(texture_handle const Texture) const;
// utility methods
TSubModel const *Pick_Control() const
TSubModel const *get_picked_control() const
{
return m_pickcontrolitem;
}
scene::basic_node const *Pick_Node() const
scene::basic_node const *get_picked_node() const
{
return m_picksceneryitem;
}
@@ -180,13 +180,16 @@ class opengl_renderer
}
// maintenance methods
void Update(double const Deltatime);
TSubModel const *Update_Pick_Control();
scene::basic_node *Update_Pick_Node();
void Update_Pick_Control();
void Update_Pick_Node();
glm::dvec3 Update_Mouse_Position();
// debug methods
std::string const &info_times() const;
std::string const &info_stats() const;
void pick_control(std::function<void(TSubModel const *)> callback);
void pick_node(std::function<void(scene::basic_node *)> callback);
// members
GLenum static const sunlight{0};
std::size_t m_drawcount{0};
@@ -338,6 +341,9 @@ class opengl_renderer
glm::mat4 ortho_projection(float left, float right, float bottom, float top, float z_near, float z_far);
glm::mat4 ortho_frustumtest_projection(float left, float right, float bottom, float top, float z_near, float z_far);
std::vector<std::function<void(TSubModel const *)>> m_control_pick_requests;
std::vector<std::function<void(scene::basic_node *)>> m_node_pick_requests;
std::unique_ptr<gl::shader> m_vertex_shader;
std::unique_ptr<gl::ubo> scene_ubo;