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

Merge branch 'milek-dev' into gfx-work

This commit is contained in:
milek7
2018-10-10 19:33:08 +02:00
49 changed files with 1697 additions and 1026 deletions

View File

@@ -19,7 +19,6 @@ http://mozilla.org/MPL/2.0/.
#include "gamepadinput.h"
#include "Console.h"
#include "simulation.h"
#include "PyInt.h"
#include "sceneeditor.h"
#include "renderer.h"
#include "uilayer.h"
@@ -27,6 +26,7 @@ http://mozilla.org/MPL/2.0/.
#include "screenshot.h"
#include "translation.h"
#include "Train.h"
#include "Timer.h"
#pragma comment (lib, "glu32.lib")
#pragma comment (lib, "dsound.lib")
@@ -136,6 +136,7 @@ eu07_application::init( int Argc, char *Argv[] ) {
if( ( result = init_audio() ) != 0 ) {
return result;
}
m_taskqueue.init();
if( ( result = init_modes() ) != 0 ) {
return result;
}
@@ -147,7 +148,7 @@ int
eu07_application::run() {
// main application loop
while (!glfwWindowShouldClose( m_window ) && !m_modestack.empty())
while (!glfwWindowShouldClose( m_windows.front() ) && !m_modestack.empty())
{
if (!m_modes[ m_modestack.top() ]->update())
break;
@@ -173,6 +174,12 @@ eu07_application::run() {
return 0;
}
bool
eu07_application::request( python_taskqueue::task_request const &Task ) {
return m_taskqueue.insert( Task );
}
void
eu07_application::exit() {
@@ -181,10 +188,11 @@ eu07_application::exit() {
ui_layer::shutdown();
glfwDestroyWindow( m_window );
for( auto *window : m_windows ) {
glfwDestroyWindow( window );
}
glfwTerminate();
TPythonInterpreter::killInstance();
m_taskqueue.exit();
}
void
@@ -219,7 +227,7 @@ eu07_application::push_mode( eu07_application::mode const Mode ) {
void
eu07_application::set_title( std::string const &Title ) {
glfwSetWindowTitle( m_window, Title.c_str() );
glfwSetWindowTitle( m_windows.front(), Title.c_str() );
}
void
@@ -239,15 +247,13 @@ eu07_application::set_cursor( int const Mode ) {
void
eu07_application::set_cursor_pos( double const Horizontal, double const Vertical ) {
if( m_window != nullptr ) {
glfwSetCursorPos( m_window, Horizontal, Vertical );
}
glfwSetCursorPos( m_windows.front(), Horizontal, Vertical );
}
glm::dvec2 eu07_application::get_cursor_pos() const {
glm::dvec2 pos;
if( m_window != nullptr ) {
glfwGetCursorPos( m_window, &pos.x, &pos.y );
if( !m_windows.empty() ) {
glfwGetCursorPos( m_windows.front(), &pos.x, &pos.y );
}
return pos;
}
@@ -255,9 +261,7 @@ glm::dvec2 eu07_application::get_cursor_pos() const {
void
eu07_application::get_cursor_pos( double &Horizontal, double &Vertical ) const {
if( m_window != nullptr ) {
glfwGetCursorPos( m_window, &Horizontal, &Vertical );
}
glfwGetCursorPos( m_windows.front(), &Horizontal, &Vertical );
}
void
@@ -306,6 +310,24 @@ void eu07_application::on_char(unsigned int c) {
return;
}
GLFWwindow *
eu07_application::window( int const Windowindex ) {
if( Windowindex >= 0 ) {
return (
Windowindex < m_windows.size() ?
m_windows[ Windowindex ] :
nullptr );
}
// for index -1 create a new child window
glfwWindowHint( GLFW_VISIBLE, GL_FALSE );
auto *childwindow = glfwCreateWindow( 1, 1, "eu07helper", nullptr, m_windows.front() );
if( childwindow != nullptr ) {
m_windows.emplace_back( childwindow );
}
return childwindow;
}
// private:
void
@@ -450,9 +472,7 @@ eu07_application::init_glfw() {
else
Global.ControlPicking = true;
// TBD, TODO: move the global pointer to a more appropriate place
m_window = window;
m_windows.emplace_back( window );
return 0;
}
@@ -460,17 +480,18 @@ eu07_application::init_glfw() {
void
eu07_application::init_callbacks() {
glfwSetFramebufferSizeCallback( m_window, window_resize_callback );
glfwSetCursorPosCallback( m_window, cursor_pos_callback );
glfwSetMouseButtonCallback( m_window, mouse_button_callback );
glfwSetKeyCallback( m_window, key_callback );
glfwSetScrollCallback( m_window, scroll_callback );
glfwSetCharCallback(m_window, char_callback);
glfwSetWindowFocusCallback( m_window, focus_callback );
auto *window { m_windows.front() };
glfwSetFramebufferSizeCallback( window, window_resize_callback );
glfwSetCursorPosCallback( window, cursor_pos_callback );
glfwSetMouseButtonCallback( window, mouse_button_callback );
glfwSetKeyCallback( window, key_callback );
glfwSetScrollCallback( window, scroll_callback );
glfwSetCharCallback(window, char_callback);
glfwSetWindowFocusCallback( window, focus_callback );
{
int width, height;
glfwGetFramebufferSize( m_window, &width, &height );
window_resize_callback( m_window, width, height );
glfwGetFramebufferSize( window, &width, &height );
window_resize_callback( window, width, height );
}
}
@@ -482,10 +503,10 @@ eu07_application::init_gfx() {
return -1;
}
if (!ui_layer::init(m_window))
if (!ui_layer::init(m_windows.front()))
return -1;
if (!GfxRenderer.Init(m_window))
if (!GfxRenderer.Init(m_windows.front()))
return -1;
return 0;