diff --git a/engine/includes/adapters/desktopadaptor.h b/engine/includes/adapters/desktopadaptor.h index f1c9916a8..a955243c8 100644 --- a/engine/includes/adapters/desktopadaptor.h +++ b/engine/includes/adapters/desktopadaptor.h @@ -22,6 +22,8 @@ class DesktopAdaptor : public PlatformAdaptor { void destroy() override; + bool isActive() const override; + bool key(Input::KeyCode code) const override; bool keyPressed(Input::KeyCode code) const override; bool keyReleased(Input::KeyCode code) const override; @@ -45,17 +47,13 @@ class DesktopAdaptor : public PlatformAdaptor { Vector4 joystickThumbs(int index) const override; Vector2 joystickTriggers(int index) const override; - void *pluginLoad(const char *name) override; - - bool pluginUnload(void *plugin) override; - - void *pluginAddress(void *plugin, const TString &name) override; TString locationLocalDir() const override; - void syncConfiguration(VariantMap &map) const override; protected: + static void windowFocusCallback(GLFWwindow *, int focused); + static void toggleFullscreen(GLFWwindow *window); static void keyCallback(GLFWwindow *, int, int, int, int); @@ -71,11 +69,17 @@ class DesktopAdaptor : public PlatformAdaptor { static void errorCallback(int error, const char *description); protected: - GLFWwindow *m_pWindow; - GLFWmonitor *m_pMonitor; + GLFWwindow *m_window; + GLFWmonitor *m_monitor; bool m_noOpenGL; + static TString s_appConfig; + static TString s_inputString; + + static std::unordered_map s_keys; + static std::unordered_map s_mouseButtons; + static Vector4 s_mousePosition; static Vector4 s_oldMousePosition; @@ -83,8 +87,10 @@ class DesktopAdaptor : public PlatformAdaptor { static int32_t s_width; static int32_t s_height; + static bool s_windowed; static bool s_vSync; + static bool s_appActive; }; #endif // DESKTOPADAPTOR_H diff --git a/engine/includes/adapters/mobileadaptor.h b/engine/includes/adapters/mobileadaptor.h index 729f078fa..11d79762f 100644 --- a/engine/includes/adapters/mobileadaptor.h +++ b/engine/includes/adapters/mobileadaptor.h @@ -19,6 +19,8 @@ class MobileAdaptor : public PlatformAdaptor { void destroy() override; + bool isActive() const override; + TString locationLocalDir() const override; uint32_t screenWidth() const override; @@ -58,6 +60,8 @@ class MobileAdaptor : public PlatformAdaptor { static float s_mouseScrollDelta; static bool s_mouseLocked; + + static bool s_appActive; }; #endif // MOBILEADAPTOR_H diff --git a/engine/includes/adapters/platformadaptor.h b/engine/includes/adapters/platformadaptor.h index fb2f8a2b5..5671f41db 100644 --- a/engine/includes/adapters/platformadaptor.h +++ b/engine/includes/adapters/platformadaptor.h @@ -23,8 +23,9 @@ class ENGINE_EXPORT PlatformAdaptor { virtual void destroy() = 0; - virtual uint32_t screenWidth() const = 0; + virtual bool isActive() const = 0; + virtual uint32_t screenWidth() const = 0; virtual uint32_t screenHeight() const = 0; virtual bool key(Input::KeyCode code) const; @@ -53,12 +54,6 @@ class ENGINE_EXPORT PlatformAdaptor { virtual uint32_t touchState(int index) const; virtual Vector4 touchPosition(int index) const; - virtual void *pluginLoad(const char *name); - - virtual bool pluginUnload(void *plugin); - - virtual void *pluginAddress(void *plugin, const TString &name); - virtual TString locationLocalDir() const; virtual void syncConfiguration(VariantMap &map) const; diff --git a/engine/includes/components/nativebehaviour.h b/engine/includes/components/nativebehaviour.h index 3a80b8ff4..656e858fd 100644 --- a/engine/includes/components/nativebehaviour.h +++ b/engine/includes/components/nativebehaviour.h @@ -18,9 +18,6 @@ class ENGINE_EXPORT NativeBehaviour : public Component { virtual void update(); -protected: - void setSystem(ObjectSystem *system) override; - }; #endif // NATIVEBEHAVIOUR_H diff --git a/engine/includes/components/world.h b/engine/includes/components/world.h index e30111073..e2718020b 100644 --- a/engine/includes/components/world.h +++ b/engine/includes/components/world.h @@ -5,6 +5,8 @@ #include "system.h" #include "scene.h" +class Camera; + typedef bool (*RayCastCallback)(System *system, World *graph, const Ray &ray, float maxDistance, Ray::Hit *hit); class ENGINE_EXPORT World : public Object { diff --git a/engine/includes/editor/editorplatform.h b/engine/includes/editor/editorplatform.h index e325f1947..37fddb027 100644 --- a/engine/includes/editor/editorplatform.h +++ b/engine/includes/editor/editorplatform.h @@ -44,6 +44,8 @@ class ENGINE_EXPORT EditorPlatform : public PlatformAdaptor { void destroy() override {} + bool isActive() const override; + bool key(Input::KeyCode) const override; bool keyPressed(Input::KeyCode) const override; bool keyReleased(Input::KeyCode) const override; @@ -83,6 +85,8 @@ class ENGINE_EXPORT EditorPlatform : public PlatformAdaptor { bool m_mouseLock; + static bool s_appActive; + }; #endif // EDITORPLATFORM_H diff --git a/engine/includes/editor/viewport/viewport.h b/engine/includes/editor/viewport/viewport.h index c12750d60..68a89801b 100644 --- a/engine/includes/editor/viewport/viewport.h +++ b/engine/includes/editor/viewport/viewport.h @@ -42,7 +42,6 @@ class ENGINE_EXPORT Viewport : public QWidget { int gridCell(); - bool isGamePaused() const; void setGamePaused(bool pause); bool isLiveUpdate() const; diff --git a/engine/includes/engine.h b/engine/includes/engine.h index 626a4c577..4c8e2130b 100644 --- a/engine/includes/engine.h +++ b/engine/includes/engine.h @@ -98,8 +98,6 @@ class ENGINE_EXPORT Engine : public ObjectSystem { static void setGameMode(bool flag); - static TString locationAppDir(); - static TString locationAppConfig(); static bool loadTranslator(const TString &table); @@ -108,10 +106,6 @@ class ENGINE_EXPORT Engine : public ObjectSystem { static void addModule(Module *module); - static TString applicationName(); - - static TString organizationName(); - static bool setPlatformAdaptor(PlatformAdaptor *platform); static Actor *composeActor(const TString &component, const TString &name, Object *parent = nullptr); @@ -123,16 +117,17 @@ class ENGINE_EXPORT Engine : public ObjectSystem { Object::ObjectList getAllObjectsByType(const TString &type) const override; - void addNativeBehaviour(NativeBehaviour *native); - void removeNativeBehaviour(NativeBehaviour *native); - private: friend class System; + friend class NativeBehaviour; bool event(Event *event) override; static void addSystem(System *system); static void removeSystem(System *system); + + static void addNativeBehaviour(NativeBehaviour *native); + static void removeNativeBehaviour(NativeBehaviour *native); }; #endif // ENGINE_H diff --git a/engine/src/adapters/desktopadaptor.cpp b/engine/src/adapters/desktopadaptor.cpp index dfe5f53d2..3647e692a 100644 --- a/engine/src/adapters/desktopadaptor.cpp +++ b/engine/src/adapters/desktopadaptor.cpp @@ -4,7 +4,6 @@ #include #include #elif __GNUC__ - #include #include #endif #include @@ -14,7 +13,6 @@ #include #include -#include #include #include "handlers/physfsfilehandler.h" @@ -34,6 +32,8 @@ namespace { const char *gScreenVsync("screen.vsync"); const char *gRhi(".rhi"); + const char *gCompany(".company"); + const char *gProject(".project"); }; Vector4 DesktopAdaptor::s_mousePosition = Vector4(); @@ -45,17 +45,17 @@ int32_t DesktopAdaptor::s_width = 0; int32_t DesktopAdaptor::s_height = 0; bool DesktopAdaptor::s_windowed = false; bool DesktopAdaptor::s_vSync = false; +bool DesktopAdaptor::s_appActive = true; -static TString gAppConfig; +TString DesktopAdaptor::s_appConfig; +TString DesktopAdaptor::s_inputString; -static std::unordered_map s_Keys; -static std::unordered_map s_MouseButtons; - -static TString s_inputString; +std::unordered_map DesktopAdaptor::s_keys; +std::unordered_map DesktopAdaptor::s_mouseButtons; DesktopAdaptor::DesktopAdaptor() : - m_pWindow(nullptr), - m_pMonitor(nullptr), + m_window(nullptr), + m_monitor(nullptr), m_noOpenGL(false) { Log::setHandler(new DesktopLogHandler()); @@ -73,12 +73,12 @@ bool DesktopAdaptor::init() { void DesktopAdaptor::update() { if(!m_noOpenGL) { - glfwSwapBuffers(m_pWindow); + glfwSwapBuffers(m_window); } s_inputString.clear(); - for(auto &it : s_Keys) { + for(auto &it : s_keys) { switch(it.second) { case RELEASE: it.second = NONE; break; case PRESS: it.second = REPEAT; break; @@ -86,7 +86,7 @@ void DesktopAdaptor::update() { } } - for(auto &it : s_MouseButtons) { + for(auto &it : s_mouseButtons) { switch(it.second) { case RELEASE: it.second = NONE; break; case PRESS: it.second = REPEAT; break; @@ -102,8 +102,7 @@ void DesktopAdaptor::update() { } void DesktopAdaptor::loop() { - while(!glfwWindowShouldClose(m_pWindow)) { - Timer::update(); + while(!glfwWindowShouldClose(m_window)) { Engine::update(); glfwPollEvents(); @@ -121,15 +120,15 @@ bool DesktopAdaptor::start() { return false; } - gAppConfig = Engine::locationAppConfig(); - static_cast(Log::handler())->setPath(gAppConfig); + s_appConfig = Engine::locationAppConfig(); + static_cast(Log::handler())->setPath(s_appConfig); #if _WIN32 - int32_t size = MultiByteToWideChar(CP_UTF8, 0, gAppConfig.data(), gAppConfig.size(), nullptr, 0); + int32_t size = MultiByteToWideChar(CP_UTF8, 0, s_appConfig.data(), s_appConfig.size(), nullptr, 0); if(size) { std::wstring path; path.resize(size); - MultiByteToWideChar(CP_UTF8, 0, gAppConfig.data(), gAppConfig.size(), &path[0], size); + MultiByteToWideChar(CP_UTF8, 0, s_appConfig.data(), s_appConfig.size(), path.data(), size); uint32_t start = 0; for(int32_t slash = 0; slash != -1; start = slash) { @@ -145,23 +144,23 @@ bool DesktopAdaptor::start() { } } #else - for(size_t i = 1; i < gAppConfig.size(); i++) { - if(gAppConfig[i] == '/' || i == gAppConfig.size()) { - int result = ::mkdir(gAppConfig.mid(0, i).data(), 0777); + for(size_t i = 1; i < s_appConfig.size(); i++) { + if(s_appConfig[i] == '/' || i == s_appConfig.size()) { + int result = ::mkdir(s_appConfig.mid(0, i).data(), 0777); if(result != 0 && (errno == EEXIST || errno == EACCES)) { continue; } } } #endif - fileHandler->searchPathAdd(gAppConfig.data(), true); + fileHandler->searchPathAdd(s_appConfig.data(), true); s_width = Engine::value(gScreenWidth, s_width).toInt(); s_height = Engine::value(gScreenHeight, s_height).toInt(); - m_pMonitor = glfwGetPrimaryMonitor(); - if(m_pMonitor) { - const GLFWvidmode *mode = glfwGetVideoMode(m_pMonitor); + m_monitor = glfwGetPrimaryMonitor(); + if(m_monitor) { + const GLFWvidmode *mode = glfwGetVideoMode(m_monitor); if(s_width <= 0) { s_width = mode->width; } @@ -178,7 +177,7 @@ bool DesktopAdaptor::start() { if(fp.open(File::ReadOnly)) { ByteArray data(fp.readAll()); - Variant var = Json::load(std::string(data.begin(), data.end())); + Variant var = Json::load(TString(data)); if(var.isValid()) { for(auto &it : var.toMap()) { Engine::setValue(it.first, it.second); @@ -203,21 +202,22 @@ bool DesktopAdaptor::start() { s_windowed = true;Engine::value(gScreenWindowed, s_windowed).toBool(); s_vSync = Engine::value(gScreenVsync, s_vSync).toBool(); - m_pWindow = glfwCreateWindow(s_width, s_height, Engine::applicationName().data(), (s_windowed) ? nullptr : m_pMonitor, nullptr); - if(!m_pWindow) { + m_window = glfwCreateWindow(s_width, s_height, Engine::value(gProject).toString().data(), (s_windowed) ? nullptr : m_monitor, nullptr); + if(!m_window) { glfwTerminate(); return false; } - glfwSetCharCallback(m_pWindow, charCallback); - glfwSetKeyCallback(m_pWindow, keyCallback); - glfwSetMouseButtonCallback(m_pWindow, buttonCallback); - glfwSetScrollCallback(m_pWindow, scrollCallback); - glfwSetCursorPosCallback(m_pWindow, cursorPositionCallback); + glfwSetWindowFocusCallback(m_window, windowFocusCallback); + glfwSetCharCallback(m_window, charCallback); + glfwSetKeyCallback(m_window, keyCallback); + glfwSetMouseButtonCallback(m_window, buttonCallback); + glfwSetScrollCallback(m_window, scrollCallback); + glfwSetCursorPosCallback(m_window, cursorPositionCallback); if(!m_noOpenGL) { glfwSwapInterval(s_vSync); - glfwMakeContextCurrent(m_pWindow); + glfwMakeContextCurrent(m_window); } return true; @@ -227,16 +227,20 @@ void DesktopAdaptor::destroy() { glfwTerminate(); } +bool DesktopAdaptor::isActive() const { + return s_appActive; +} + bool DesktopAdaptor::key(Input::KeyCode code) const { - return (m_pWindow && glfwGetKey(m_pWindow, code) == GLFW_PRESS); + return (m_window && glfwGetKey(m_window, code) == GLFW_PRESS); } bool DesktopAdaptor::keyPressed(Input::KeyCode code) const { - return (s_Keys[code] == PRESS); + return (s_keys[code] == PRESS); } bool DesktopAdaptor::keyReleased(Input::KeyCode code) const { - return (s_Keys[code] == RELEASE); + return (s_keys[code] == RELEASE); } TString DesktopAdaptor::inputString() const { @@ -256,19 +260,19 @@ float DesktopAdaptor::mouseScrollDelta() const { } bool DesktopAdaptor::mouseButton(int button) const { - return (m_pWindow && glfwGetMouseButton(m_pWindow, button | 0x10000000) == GLFW_PRESS); + return (m_window && glfwGetMouseButton(m_window, button | 0x10000000) == GLFW_PRESS); } bool DesktopAdaptor::mousePressed(int button) const { - return (s_MouseButtons[button | 0x10000000] == PRESS); + return (s_mouseButtons[button | 0x10000000] == PRESS); } bool DesktopAdaptor::mouseReleased(int button) const { - return (s_MouseButtons[button | 0x10000000] == RELEASE); + return (s_mouseButtons[button | 0x10000000] == RELEASE); } void DesktopAdaptor::mouseLockCursor(bool lock) { - glfwSetInputMode(m_pWindow, GLFW_CURSOR, lock ? GLFW_CURSOR_DISABLED : GLFW_CURSOR_NORMAL); + glfwSetInputMode(m_window, GLFW_CURSOR, lock ? GLFW_CURSOR_DISABLED : GLFW_CURSOR_NORMAL); } uint32_t DesktopAdaptor::screenWidth() const { @@ -319,28 +323,8 @@ Vector2 DesktopAdaptor::joystickTriggers(int index) const { return Vector2(); } -void *DesktopAdaptor::pluginLoad(const char *name) { -#ifdef WIN32 - return static_cast(LoadLibraryW(reinterpret_cast(name))); -#elif(__GNUC__) - return dlopen(name, RTLD_NOW); -#endif -} - -bool DesktopAdaptor::pluginUnload(void *plugin) { -#ifdef WIN32 - return FreeLibrary(reinterpret_cast(plugin)); -#elif(__GNUC__) - return dlclose(plugin); -#endif -} - -void *DesktopAdaptor::pluginAddress(void *plugin, const TString &name) { -#ifdef WIN32 - return (void*)GetProcAddress(reinterpret_cast(plugin), name.data()); -#elif(__GNUC__) - return dlsym(plugin, name.data()); -#endif +void DesktopAdaptor::windowFocusCallback(GLFWwindow *, int focused) { + s_appActive = focused; } void DesktopAdaptor::toggleFullscreen(GLFWwindow *window) { @@ -357,7 +341,7 @@ void DesktopAdaptor::toggleFullscreen(GLFWwindow *window) { } void DesktopAdaptor::keyCallback(GLFWwindow *widnow, int code, int, int action, int mods) { - s_Keys[static_cast(code)] = action; + s_keys[static_cast(code)] = action; if(code == GLFW_KEY_ENTER && action == GLFW_PRESS && (mods & GLFW_MOD_ALT)) { toggleFullscreen(widnow); @@ -369,7 +353,7 @@ void DesktopAdaptor::charCallback(GLFWwindow *, unsigned int codepoint) { } void DesktopAdaptor::buttonCallback(GLFWwindow *, int button, int action, int) { - s_MouseButtons[button | 0x10000000] = action; + s_mouseButtons[button | 0x10000000] = action; } void DesktopAdaptor::scrollCallback(GLFWwindow *, double, double yoffset) { @@ -404,6 +388,17 @@ TString DesktopAdaptor::locationLocalDir() const { result += ::getenv("HOME"); result += "/.config"; #endif + + TString organization(Engine::value(gCompany).toString()); + if(!organization.isEmpty()) { + result += TString("/") + organization; + } + + TString project(Engine::value(gProject).toString()); + if(!project.isEmpty()) { + result += TString("/") + project; + } + return result; } @@ -413,10 +408,10 @@ void DesktopAdaptor::syncConfiguration(VariantMap &map) const { s_windowed = Engine::value(gScreenWindowed, s_windowed).toBool(); s_vSync = Engine::value(gScreenVsync, s_vSync).toBool(); - if(m_pWindow) { + if(m_window) { int32_t x, y; - glfwGetWindowPos(m_pWindow, &x, &y); - glfwSetWindowMonitor(m_pWindow, (s_windowed) ? nullptr : m_pMonitor, x, y, s_width, s_height, GLFW_DONT_CARE); + glfwGetWindowPos(m_window, &x, &y); + glfwSetWindowMonitor(m_window, (s_windowed) ? nullptr : m_monitor, x, y, s_width, s_height, GLFW_DONT_CARE); //glfwSwapInterval(s_vSync); } diff --git a/engine/src/adapters/mobileadaptor.cpp b/engine/src/adapters/mobileadaptor.cpp index e514a293d..0a1dc8d49 100644 --- a/engine/src/adapters/mobileadaptor.cpp +++ b/engine/src/adapters/mobileadaptor.cpp @@ -75,6 +75,7 @@ int32_t MobileAdaptor::s_width = 0; int32_t MobileAdaptor::s_height = 0; float MobileAdaptor::s_mouseScrollDelta = 0.0f; bool MobileAdaptor::s_mouseLocked = false; +bool MobileAdaptor::s_appActive = true; int keyToInput(int key) { int result = key; @@ -168,12 +169,15 @@ int keyToInput(int key) { } void onFrame(GLFMDisplay *display) { - Timer::update(); Engine::update(); glfmSwapBuffers(display); } +void onFocus(GLFMDisplay *display, bool focused) { + MobileAdaptor::s_appActive = focused; +} + void onCreate(GLFMDisplay *display, int width, int height) { MobileAdaptor::s_width = width; MobileAdaptor::s_height = height; @@ -295,6 +299,7 @@ void glfmMain(GLFMDisplay *display) { GLFMStencilFormatNone, GLFMMultisampleNone); + glfmSetAppFocusFunc(display, onFocus); glfmSetRenderFunc(s_display, onFrame); glfmSetSurfaceCreatedFunc(s_display, onCreate); glfmSetSurfaceResizedFunc(s_display, onResize); @@ -355,6 +360,10 @@ void MobileAdaptor::destroy() { } +bool MobileAdaptor::isActive() const { + return s_appActive; +} + TString MobileAdaptor::locationLocalDir() const { #ifdef __ANDROID__ return reinterpret_cast(glfmGetAndroidActivity(s_display))->internalDataPath; diff --git a/engine/src/adapters/platformadaptor.cpp b/engine/src/adapters/platformadaptor.cpp index a6fa8fa13..1855c4afa 100644 --- a/engine/src/adapters/platformadaptor.cpp +++ b/engine/src/adapters/platformadaptor.cpp @@ -91,22 +91,6 @@ Vector4 PlatformAdaptor::touchPosition(int index) const { return 0; } -void *PlatformAdaptor::pluginLoad(const char *name) { - A_UNUSED(name); - return nullptr; -} - -bool PlatformAdaptor::pluginUnload(void *plugin) { - A_UNUSED(plugin); - return false; -} - -void *PlatformAdaptor::pluginAddress(void *plugin, const TString &name) { - A_UNUSED(plugin); - A_UNUSED(name); - return nullptr; -} - TString PlatformAdaptor::locationLocalDir() const { return TString(); } diff --git a/engine/src/components/actor.cpp b/engine/src/components/actor.cpp index eb743abca..de451766f 100644 --- a/engine/src/components/actor.cpp +++ b/engine/src/components/actor.cpp @@ -5,15 +5,12 @@ #include "resources/prefab.h" -#include - namespace { const char *gFlags("Flags"); const char *gPrefab("Prefab"); const char *gData("PrefabData"); const char *gStatic("Static"); const char *gDeleted("Deleted"); - const char *gTransform("Transform"); } static void enumConstObjects(const Object *object, Prefab::ConstObjectList &list) { diff --git a/engine/src/components/animator.cpp b/engine/src/components/animator.cpp index ab2bc3560..aa2ae1523 100644 --- a/engine/src/components/animator.cpp +++ b/engine/src/components/animator.cpp @@ -8,8 +8,7 @@ #include "resources/animationstatemachine.h" #include "timer.h" - -#include "log.h" +#include /*! \class Animator diff --git a/engine/src/components/armature.cpp b/engine/src/components/armature.cpp index d6729ce8a..0561266dc 100644 --- a/engine/src/components/armature.cpp +++ b/engine/src/components/armature.cpp @@ -5,15 +5,11 @@ #include "resources/mesh.h" #include "resources/pose.h" -#include "resources/texture.h" - -#include "systems/resourcesystem.h" #include "commandbuffer.h" #include "gizmos.h" #include -#include #define M4X3_SIZE 48 #define HEADER_SIZE 16 diff --git a/engine/src/components/baselight.cpp b/engine/src/components/baselight.cpp index cdcc165f1..b8d106ea3 100644 --- a/engine/src/components/baselight.cpp +++ b/engine/src/components/baselight.cpp @@ -1,12 +1,8 @@ #include "baselight.h" -#include "components/actor.h" -#include "components/transform.h" - #include "systems/rendersystem.h" #include "material.h" -#include "mesh.h" namespace { const char *uniParams = "params"; diff --git a/engine/src/components/camera.cpp b/engine/src/components/camera.cpp index f63580a88..b6973c392 100644 --- a/engine/src/components/camera.cpp +++ b/engine/src/components/camera.cpp @@ -2,6 +2,7 @@ #include "components/actor.h" #include "components/transform.h" +#include "components/world.h" #include "pipelinecontext.h" #include "gizmos.h" @@ -257,6 +258,27 @@ void Camera::setScreenSpace(bool mode) { Returns current active camera. */ Camera *Camera::current() { + if(s_currentCamera == nullptr || !s_currentCamera->isEnabled() || !s_currentCamera->actor()->isEnabled()) { + s_currentCamera = nullptr; + for(auto it : Engine::world()->findChildren()) { + if(it->isEnabled() && it->actor()->isEnabled()) { // Get first active Camera + s_currentCamera = it; + break; + } + } + + if(s_currentCamera == nullptr) { + static Camera *reserveCamera = nullptr; + if(reserveCamera == nullptr) { + Actor *cameraActor = Engine::composeActor("ReserveCamera", Engine::world()); + reserveCamera = cameraActor->getComponent(); + } + s_currentCamera = reserveCamera; + s_currentCamera->actor()->setEnabled(true); + s_currentCamera->setEnabled(true); + } + } + return s_currentCamera; } /*! diff --git a/engine/src/components/directlight.cpp b/engine/src/components/directlight.cpp index 7f1cb9f03..9083653b6 100644 --- a/engine/src/components/directlight.cpp +++ b/engine/src/components/directlight.cpp @@ -2,14 +2,11 @@ #include "components/actor.h" #include "components/transform.h" -#include "components/camera.h" #include "resources/material.h" #include "resources/mesh.h" -#include "resources/rendertarget.h" #include "pipelinecontext.h" -#include "commandbuffer.h" #include "gizmos.h" /*! diff --git a/engine/src/components/effectrender.cpp b/engine/src/components/effectrender.cpp index d7b329290..77273de07 100644 --- a/engine/src/components/effectrender.cpp +++ b/engine/src/components/effectrender.cpp @@ -1,12 +1,9 @@ #include "effectrender.h" -#include #include -#include #include "actor.h" #include "transform.h" -#include "camera.h" #include "visualeffect.h" #include "material.h" diff --git a/engine/src/components/nativebehaviour.cpp b/engine/src/components/nativebehaviour.cpp index bd86cd657..1530e2492 100644 --- a/engine/src/components/nativebehaviour.cpp +++ b/engine/src/components/nativebehaviour.cpp @@ -28,11 +28,11 @@ */ NativeBehaviour::NativeBehaviour() { - + Engine::addNativeBehaviour(this); } NativeBehaviour::~NativeBehaviour() { - static_cast(system())->removeNativeBehaviour(this); + Engine::removeNativeBehaviour(this); } /*! @@ -47,12 +47,3 @@ void NativeBehaviour::start() { void NativeBehaviour::update() { } -/*! - \internal -*/ -void NativeBehaviour::setSystem(ObjectSystem *system) { - Object::setSystem(system); - - Engine *engine = static_cast(system); - engine->addNativeBehaviour(this); -} diff --git a/engine/src/components/postprocessvolume.cpp b/engine/src/components/postprocessvolume.cpp index cfd31e16e..f1a496b49 100644 --- a/engine/src/components/postprocessvolume.cpp +++ b/engine/src/components/postprocessvolume.cpp @@ -2,13 +2,9 @@ #include "components/private/postprocessorsettings.h" -#include "components/world.h" - #include "components/actor.h" #include "components/transform.h" -#include "resources/texture.h" - #include "systems/rendersystem.h" #include "gizmos.h" @@ -27,7 +23,7 @@ PostProcessVolume::PostProcessVolume() : m_blendWeight(1.0f), m_unbound(false) { - for(auto it : m_settings->settings()) { + for(auto &it : m_settings->settings()) { Object::setProperty(it.first.c_str(), it.second); } } @@ -101,8 +97,7 @@ void PostProcessVolume::setProperty(const char *name, const Variant &value) { void PostProcessVolume::setSystem(ObjectSystem *system) { Component::setSystem(system); - RenderSystem *render = static_cast(system); - render->addPostProcessVolume(this); + static_cast(system)->addPostProcessVolume(this); } /*! \internal diff --git a/engine/src/components/scene.cpp b/engine/src/components/scene.cpp index c3bf4fca7..a2decfbf6 100644 --- a/engine/src/components/scene.cpp +++ b/engine/src/components/scene.cpp @@ -2,8 +2,6 @@ #include "components/world.h" -#include "resources/resource.h" - /*! \class Scene \brief The internal methods are marked as internal and are intended for use within the framework rather than by external code. diff --git a/engine/src/components/spline.cpp b/engine/src/components/spline.cpp index c48c2adb5..ef67d92d4 100644 --- a/engine/src/components/spline.cpp +++ b/engine/src/components/spline.cpp @@ -1,9 +1,9 @@ #include "components/spline.h" -#include "gizmos.h" - #include "components/transform.h" +#include "gizmos.h" + namespace { const char *gPoints("points"); } diff --git a/engine/src/components/spotlight.cpp b/engine/src/components/spotlight.cpp index 4cdc48a89..61f4947ae 100644 --- a/engine/src/components/spotlight.cpp +++ b/engine/src/components/spotlight.cpp @@ -7,11 +7,6 @@ #include "gizmos.h" -namespace { - const char *uni_position = "position"; - const char *uni_direction = "direction"; -}; - /*! \class SpotLight \brief A Spot Light emits light from a single point in a cone shape. diff --git a/engine/src/components/tilemaprender.cpp b/engine/src/components/tilemaprender.cpp index 1e13c44d4..d9e8dd351 100644 --- a/engine/src/components/tilemaprender.cpp +++ b/engine/src/components/tilemaprender.cpp @@ -1,8 +1,5 @@ #include "components/tilemaprender.h" -#include "components/actor.h" -#include "components/transform.h" - #include "resources/tilemap.h" #include "resources/tileset.h" #include "resources/sprite.h" diff --git a/engine/src/components/world.cpp b/engine/src/components/world.cpp index 0a22ba464..9048cbbb2 100644 --- a/engine/src/components/world.cpp +++ b/engine/src/components/world.cpp @@ -4,8 +4,6 @@ #include "components/scene.h" #include "resources/map.h" -#include "components/private/postprocessorsettings.h" - /*! \class World \brief A root object in the scene graph hierarchy. diff --git a/engine/src/editor/editorplatform.cpp b/engine/src/editor/editorplatform.cpp index ec9c3864f..1157606c4 100644 --- a/engine/src/editor/editorplatform.cpp +++ b/engine/src/editor/editorplatform.cpp @@ -2,6 +2,7 @@ #include #include +#include #include #include @@ -9,6 +10,8 @@ #include #include +bool EditorPlatform::s_appActive = true; + Input::KeyCode mapToInput(int32_t key) { static const QMap map = { { Qt::Key_Space, Input::KEY_SPACE }, @@ -141,6 +144,10 @@ EditorPlatform::EditorPlatform() : m_mouseLock(false) { File::setHandler(new DefaultFileHandler); + + QObject::connect(qApp, &QGuiApplication::applicationStateChanged, [](Qt::ApplicationState state) { + s_appActive = (state == Qt::ApplicationActive); + }); } EditorPlatform &EditorPlatform::instance() { @@ -213,6 +220,10 @@ void EditorPlatform::reset() { } } +bool EditorPlatform::isActive() const { + return s_appActive; +} + bool EditorPlatform::key(Input::KeyCode code) const { return (m_keys.value(code) > RELEASE); } diff --git a/engine/src/editor/viewport/viewport.cpp b/engine/src/editor/viewport/viewport.cpp index 973f8079d..b9e7e579b 100644 --- a/engine/src/editor/viewport/viewport.cpp +++ b/engine/src/editor/viewport/viewport.cpp @@ -258,10 +258,6 @@ int Viewport::gridCell() { return m_gridRender->scale(); } -bool Viewport::isGamePaused() const { - return m_gamePaused; -} - void Viewport::setGamePaused(bool pause) { m_gamePaused = pause; if(m_gamePaused) { diff --git a/engine/src/engine.cpp b/engine/src/engine.cpp index 9c5755a94..0f5d0f115 100644 --- a/engine/src/engine.cpp +++ b/engine/src/engine.cpp @@ -53,8 +53,6 @@ namespace { static const char *gObjects("objects"); static const char *gEntry(".entry"); - static const char *gCompany(".company"); - static const char *gProject(".project"); static const char *gTransform("Transform"); } @@ -84,11 +82,6 @@ static std::list m_serial; static std::list m_behaviours; -static TString m_applicationPath; -static TString m_applicationDir; -static TString m_organization; -static TString m_application; - static ThreadPool *m_threadPool = nullptr; static PlatformAdaptor *m_platform = nullptr; static Translator *m_translator = nullptr; @@ -133,7 +126,7 @@ static Engine *m_instance = nullptr; Constructs Engine. Using application \a path parameters creates necessary platform adapters, register basic component types and resource types. */ -Engine::Engine(const char *path) { +Engine::Engine(const char *) { PROFILE_FUNCTION(); std::locale::global(std::locale("C")); @@ -141,10 +134,6 @@ Engine::Engine(const char *path) { m_instance = this; addSystem(new ResourceSystem); - m_applicationPath = path; - Url url(m_applicationPath); - m_applicationDir = url.absoluteDir(); - m_application = url.baseName(); Url::declareMetaType(); @@ -255,36 +244,6 @@ bool Engine::start() { void Engine::update() { PROFILE_FUNCTION(); - // Active camera check - Camera *camera = Camera::current(); - if(camera == nullptr || !camera->isEnabled() || !camera->actor()->isEnabled()) { - camera = nullptr; - for(auto it : m_world->findChildren()) { - if(it->isEnabled() && it->actor()->isEnabled()) { // Get first active Camera - camera = it; - break; - } - } - - if(camera == nullptr) { - static Camera *reserveCamera = nullptr; - if(reserveCamera == nullptr) { - Actor *cameraActor = Engine::composeActor("ReserveCamera", m_world); - reserveCamera = cameraActor->getComponent(); - } - camera = reserveCamera; - camera->actor()->setEnabled(true); - camera->setEnabled(true); - } - - Camera::setCurrent(camera); - } - - // Update screen size - if(camera) { - camera->setRatio(float(m_platform->screenWidth()) / float(m_platform->screenHeight())); - } - if(m_renderSystem) { PipelineContext *pipeline = m_renderSystem->pipelineContext(); if(pipeline) { @@ -296,39 +255,43 @@ void Engine::update() { try { m_instance->processEvents(); - if(isGameMode()) { - for(auto it : m_behaviours) { - if(it->isEnabled()) { - World *world = it->world(); + if(m_platform->isActive()) { + Timer::update(); + + if(isGameMode()) { + for(auto it : m_behaviours) { + if(it->isEnabled()) { + World *world = it->world(); - if(world == m_world) { - if(!it->isStarted()) { - it->start(); - it->setStarted(true); + if(world == m_world) { + if(!it->isStarted()) { + it->start(); + it->setStarted(true); + } + it->update(); } - it->update(); } } } - } - m_world->setToBeUpdated(true); + m_world->setToBeUpdated(true); - for(auto it : m_pool) { - it->m_system->setActiveWorld(m_world); - if(m_threadPool) { - m_threadPool->start(it); - } else { - it->m_system->processEvents(); + for(auto it : m_pool) { + it->m_system->setActiveWorld(m_world); + if(m_threadPool) { + m_threadPool->start(it); + } else { + it->m_system->processEvents(); + } } - } - for(auto it : m_serial) { - it->setActiveWorld(m_world); - it->processEvents(); - } - m_threadPool->waitForDone(); + for(auto it : m_serial) { + it->setActiveWorld(m_world); + it->processEvents(); + } + m_threadPool->waitForDone(); - m_world->setToBeUpdated(false); + m_world->setToBeUpdated(false); + } m_platform->update(); @@ -528,9 +491,6 @@ bool Engine::reloadBundle() { setValue(it.first, it.second); } - m_application = value(gProject, "").toString(); - m_organization = value(gCompany, "").toString(); - return true; } } @@ -661,30 +621,13 @@ void Engine::unloadAllScenes() { m_world->unloadAll(); } -/*! - Returns path to application binary directory. -*/ -TString Engine::locationAppDir() { - PROFILE_FUNCTION(); - - return m_applicationDir; -} /*! Returns path to application config directory. */ TString Engine::locationAppConfig() { PROFILE_FUNCTION(); - TString result = m_platform->locationLocalDir(); -#ifndef THUNDER_MOBILE - if(!m_organization.isEmpty()) { - result += TString("/") + m_organization; - } - if(!m_application.isEmpty()) { - result += TString("/") + m_application; - } -#endif - return result; + return m_platform->locationLocalDir(); } /*! Loads translation table with provided file \a name. @@ -717,22 +660,6 @@ TString Engine::translate(const TString &source) { } return source; } -/*! - Returns application name. -*/ -TString Engine::applicationName() { - PROFILE_FUNCTION(); - - return m_application; -} -/*! - Returns organization name. -*/ -TString Engine::organizationName() { - PROFILE_FUNCTION(); - - return m_organization; -} /*! Creates an Actor with \a name and attached \a component. Created Actor will be added to the hierarchy of \a parent. diff --git a/engine/src/pipelinecontext.cpp b/engine/src/pipelinecontext.cpp index 8af76bda3..3c6efd3e3 100644 --- a/engine/src/pipelinecontext.cpp +++ b/engine/src/pipelinecontext.cpp @@ -132,6 +132,11 @@ void PipelineContext::resize(int32_t width, int32_t height) { it->resize(m_width, m_height); } + Camera *camera = Camera::current(); + if(camera) { + camera->setRatio(float(m_width) / float(m_height)); + } + m_buffer->setViewport(0, 0, m_width, m_height); } } diff --git a/modules/renders/rendervk/src/wrappervk.cpp b/modules/renders/rendervk/src/wrappervk.cpp index 978000c7b..9ff03a7d7 100644 --- a/modules/renders/rendervk/src/wrappervk.cpp +++ b/modules/renders/rendervk/src/wrappervk.cpp @@ -276,7 +276,7 @@ void WrapperVk::destroyContext() { void WrapperVk::createInstance() { VkApplicationInfo appInfo = {}; appInfo.sType = VK_STRUCTURE_TYPE_APPLICATION_INFO; - appInfo.pApplicationName = Engine::applicationName().data(); + appInfo.pApplicationName = Engine::value(".project").toString().data(); appInfo.applicationVersion = VK_MAKE_VERSION(1, 0, 0); appInfo.pEngineName = "Thunder Engine"; appInfo.engineVersion = VK_MAKE_VERSION(1, 0, 0); diff --git a/worldeditor/src/main/mainwindow.cpp b/worldeditor/src/main/mainwindow.cpp index 1fafa124d..7bb6dfc76 100644 --- a/worldeditor/src/main/mainwindow.cpp +++ b/worldeditor/src/main/mainwindow.cpp @@ -65,7 +65,8 @@ MainWindow::MainWindow(Engine *engine, QWidget *parent) : m_preview(nullptr), m_mainEditor(nullptr), m_currentEditor(nullptr), - m_builder(new QProcess(this)) { + m_builder(new QProcess(this)), + m_pauseSimulation(false) { qRegisterMetaType ("Vector2"); qRegisterMetaType ("Vector3"); @@ -257,8 +258,8 @@ void MainWindow::on_actionPlay_triggered() { void MainWindow::on_actionPause_triggered() { if(m_preview) { - m_preview->setGamePause(!m_preview->isGamePause()); - ui->pauseButton->setChecked(m_preview->isGamePause()); + m_pauseSimulation = !m_pauseSimulation; + ui->pauseButton->setChecked(m_pauseSimulation); } } @@ -275,7 +276,7 @@ void MainWindow::setGameMode(bool mode) { ui->toolWidget->activateToolWindow(m_mainEditor); static_cast(m_mainEditor)->restoreBackupScenes(); - m_preview->setGamePause(false); + m_pauseSimulation = false; ui->pauseButton->setChecked(false); ui->actionPause->setChecked(false); } @@ -671,5 +672,9 @@ void MainWindow::readError() { } void MainWindow::timerEvent(QTimerEvent *) { - Timer::update(); + if(!Engine::isGameMode() || m_pauseSimulation) { + Timer::update(); + } else { + Engine::update(); + } } diff --git a/worldeditor/src/main/mainwindow.h b/worldeditor/src/main/mainwindow.h index 85c492073..dd0a9087d 100644 --- a/worldeditor/src/main/mainwindow.h +++ b/worldeditor/src/main/mainwindow.h @@ -74,7 +74,7 @@ public slots: QString m_currentWorkspace; - QList m_gadgets; + std::list m_gadgets; Engine *m_engine; @@ -97,6 +97,8 @@ public slots: QProcess *m_builder; + bool m_pauseSimulation; + private slots: void onBuildProject(); diff --git a/worldeditor/src/screens/preview/preview.cpp b/worldeditor/src/screens/preview/preview.cpp index 9d29ede4d..14072b6e0 100644 --- a/worldeditor/src/screens/preview/preview.cpp +++ b/worldeditor/src/screens/preview/preview.cpp @@ -34,11 +34,3 @@ void Preview::onActivate() { } } } - -bool Preview::isGamePause() const { - return ui->viewport->isGamePaused(); -} - -void Preview::setGamePause(bool pause) { - ui->viewport->setGamePaused(pause); -} diff --git a/worldeditor/src/screens/preview/preview.h b/worldeditor/src/screens/preview/preview.h index 4d29dd187..f68f76dde 100644 --- a/worldeditor/src/screens/preview/preview.h +++ b/worldeditor/src/screens/preview/preview.h @@ -16,9 +16,6 @@ class Preview : public QWidget { void onActivate(); - bool isGamePause() const; - void setGamePause(bool pause); - protected: Ui::Preview *ui;