From 4a9df071fe97f2f6d7af4881e14b26004412fb59 Mon Sep 17 00:00:00 2001 From: Kim Kulling Date: Tue, 28 Jan 2025 15:51:35 +0100 Subject: [PATCH 1/7] Add axis --- src/Editor/CMakeLists.txt | 9 - src/Editor/src/Gui/UIElements.cpp | 168 ------------------- src/Editor/src/Gui/UIElements.h | 106 ------------ src/Editor/src/Gui/UIElementsWin32.cpp | 75 --------- src/Editor/src/Gui/UIElementsWin32.h | 40 ----- src/Editor/src/OsreEdApp.cpp | 42 +++-- src/Editor/src/ProgressReporter.cpp | 11 +- src/Editor/src/RenderView/MainRenderView.cpp | 11 +- src/Editor/src/RenderView/MainRenderView.h | 7 +- src/Editor/src/main.cpp | 10 +- src/Engine/App/AppBase.h | 8 +- src/Engine/Common/osre_common.h | 2 - 12 files changed, 45 insertions(+), 444 deletions(-) delete mode 100644 src/Editor/src/Gui/UIElements.cpp delete mode 100644 src/Editor/src/Gui/UIElements.h delete mode 100644 src/Editor/src/Gui/UIElementsWin32.cpp delete mode 100644 src/Editor/src/Gui/UIElementsWin32.h diff --git a/src/Editor/CMakeLists.txt b/src/Editor/CMakeLists.txt index 7941b9978..fe6708cf6 100644 --- a/src/Editor/CMakeLists.txt +++ b/src/Editor/CMakeLists.txt @@ -52,13 +52,6 @@ set(actions_src src/Actions/ImportAction.h ) -set( gui_src - src/Gui/UIElementsWin32.h - src/Gui/UIElementsWin32.cpp - src/Gui/UIElements.cpp - src/Gui/UIElements.h -) - set(main_src src/OsreEdApp.cpp src/OsreEdApp.h @@ -70,7 +63,6 @@ set(main_src ) SOURCE_GROUP(RenderView FILES ${renderview_src}) SOURCE_GROUP(Actions FILES ${actions_src}) -source_group(Gui FILES ${gui_src}) SOURCE_GROUP(Modules\\InspectorModule FILES ${inspector_module_src} ) SOURCE_GROUP(Modules\\LogModule FILES ${log_module_src} ) SOURCE_GROUP(Modules\\EditorModule FILES ${editor_module_src} ) @@ -80,7 +72,6 @@ SOURCE_GROUP(Main\\ FILES ${main_src}) ADD_EXECUTABLE( osre_ed ${actions_src} - ${gui_src} ${inspector_module_src} ${log_module_src} ${editor_module_src} diff --git a/src/Editor/src/Gui/UIElements.cpp b/src/Editor/src/Gui/UIElements.cpp deleted file mode 100644 index d8db10d5a..000000000 --- a/src/Editor/src/Gui/UIElements.cpp +++ /dev/null @@ -1,168 +0,0 @@ -/*----------------------------------------------------------------------------------------------- -The MIT License (MIT) - -Copyright (c) 2015-2024 OSRE ( Open Source Render Engine ) by Kim Kulling - -Permission is hereby granted, free of charge, to any person obtaining a copy of -this software and associated documentation files (the "Software"), to deal in -the Software without restriction, including without limitation the rights to -use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of -the Software, and to permit persons to whom the Software is furnished to do so, -subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS -FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR -COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER -IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN -CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. ------------------------------------------------------------------------------------------------*/ -#include "UIElements.h" -#include "RenderBackend/MeshBuilder.h" -#include "Platform/PlatformOperations.h" -#include "Platform/PlatformInterface.h" - -#ifdef OSRE_WINDOWS -# include "Platform/win32/Win32EventQueue.h" -# include "Platform/win32/Win32Window.h" -# include -# include -# include -# include -# include -# include -# include -#endif // OSRE_WINDOWS - -namespace OSRE { - -using namespace ::OSRE::RenderBackend; -using namespace ::OSRE::Platform; -using namespace ::OSRE::Editor; - -constexpr int IDM_FILE_NEW = 1; -constexpr int IDM_FILE_OPEN = 2; -constexpr int IDM_FILE_SAVE = 3; -constexpr int IDM_FILE_IMPORT = 4; -constexpr int IDM_FILE_QUIT = 5; - -constexpr int IDM_MESH_NEW = 100; - -constexpr int IDM_GETTING_HELP = 6; -constexpr int IDM_INFO_VERSION = 7; - -String TreeItem::generateName() { - return "newItem_" + std::to_string(mChildren.size()); -} - -TreeItem::TreeItem() : mName(generateName()), mParent(nullptr), mChildren() {} - -void TreeItem::addChild(TreeItem *item) { - if (item == nullptr) { - return; - } - - mChildren.add(item); -} - -size_t TreeItem::numChildren() const { - return mChildren.size(); -} - -TreeItem *TreeItem::getParent() const { - return mParent; -} - -ProgressBar *UIElements::createProgressBar(int id, HWND hWnd, const Rect2ui &rect) { - ProgressBar *pb = new ProgressBar; - pb->mPlatformData.mHWnd = CreateWindowEx( - 0, - PROGRESS_CLASS, - (LPSTR)NULL, - WS_VISIBLE | WS_CHILD, - rect.getX1(), - rect.getY1(), - rect.getWidth(), - rect.getHeight(), - hWnd, - (HMENU)id, - (HINSTANCE)GetWindowLong(hWnd, GWLP_HINSTANCE), - NULL); - - if (!pb->mPlatformData.mHWnd) { - MessageBox(NULL, "Progress Bar Failed.", "Error", MB_OK | MB_ICONERROR); - return nullptr; - } - pb->mRange=100; - pb->mCurrent = 0; - - pb->mPlatformData.mHWnd; - ::SendMessage(hWnd, PBM_SETRANGE, 0, MAKELPARAM(0, 99)); - ::SendMessage(hWnd, PBM_SETSTEP, (WPARAM)1, 0); - - pb->mParent = nullptr; - pb->mRect = rect; - - return pb; -} - -void UIElements::updateProgressBar(ProgressBar *pb, ui32 step) { - if (pb == nullptr) { - return; - } - ::SendMessage(pb->mPlatformData.mHWnd, PBM_SETPOS, (WPARAM)step, 0); -} - -void UIElements::deleteProgressBar(ProgressBar *pb) { - if (pb == nullptr) { - return; - } - ::CloseWindow(pb->mPlatformData.mHWnd); - delete pb; -} - -void UIElements::createMenues(Win32Window *w, OsreEdApp *app, Platform::AbstractPlatformEventQueue *queue) { - osre_assert(w != nullptr); - osre_assert(app != nullptr); - osre_assert(queue != nullptr); - - /* w->beginMenu(); - MenuEntry FileMenu[8] = { - { MF_STRING, IDM_FILE_NEW, L"&New", MenuFunctor::Make(app, &OsreEdApp::newProjectCmd) }, - { MF_STRING, IDM_FILE_OPEN, L"&Open Project", MenuFunctor::Make(app, &OsreEdApp::loadProjectCmd) }, - { MF_STRING, IDM_FILE_SAVE, L"&Save Project", MenuFunctor::Make(app, &OsreEdApp::saveProjectCmd) }, - { MF_SEPARATOR, 0, nullptr }, - { MF_STRING, IDM_FILE_IMPORT, L"&Import Asset", MenuFunctor::Make(app, &OsreEdApp::importAssetCmd) }, - { MF_SEPARATOR, 0, nullptr }, - { MF_STRING, IDM_FILE_QUIT, L"&Quit", MenuFunctor::Make(app, &OsreEdApp::quitEditorCmd) }, - }; - w->addSubMenues(nullptr, queue, L"File", FileMenu, 8); - - MenuEntry SceneMenu[1] = { - { MF_STRING, IDM_MESH_NEW, L"&New Mesh", MenuFunctor::Make(app, &OsreEdApp::newMeshCmd) }, - }; - w->addSubMenues(nullptr, queue, L"Scene", SceneMenu, 1); - - MenuEntry InfoMenu[2] = { - { MF_STRING, IDM_GETTING_HELP, L"&Getting Help", MenuFunctor::Make(app, &OsreEdApp::gettingHelpCmd) }, - { MF_STRING, IDM_INFO_VERSION, L"&Version", MenuFunctor::Make(app, &OsreEdApp::showVersionCmd) } - }; - w->addSubMenues(nullptr, queue, L"&Info", InfoMenu, 2); - - w->endMenu();*/ -} - -TreeView *UIElements::createTreeView(Win32Window *w) { - if (w == nullptr) { - return nullptr; - } - - auto *t = new TreeView; - - return t; -} - -} // namespace OSRE diff --git a/src/Editor/src/Gui/UIElements.h b/src/Editor/src/Gui/UIElements.h deleted file mode 100644 index fda16d607..000000000 --- a/src/Editor/src/Gui/UIElements.h +++ /dev/null @@ -1,106 +0,0 @@ -/*----------------------------------------------------------------------------------------------- -The MIT License (MIT) - -Copyright (c) 2015-2024 OSRE ( Open Source Render Engine ) by Kim Kulling - -Permission is hereby granted, free of charge, to any person obtaining a copy of -this software and associated documentation files (the "Software"), to deal in -the Software without restriction, including without limitation the rights to -use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of -the Software, and to permit persons to whom the Software is furnished to do so, -subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS -FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR -COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER -IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN -CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. ------------------------------------------------------------------------------------------------*/ -#pragma once - -#include "Common/osre_common.h" -#include "RenderBackend/RenderCommon.h" -#include "RenderBackend/RenderBackendService.h" -#include "Platform/Windows/MinWindows.h" - -#include - -namespace OSRE { - -namespace Platform { - class Win32Window; - class AbstractPlatformEventQueue; -} - -namespace Editor { - class OsreEdApp; -} - -struct ProgressBar; -struct TreeView; - -// OS-specific API -class UIElements { -public: - static ProgressBar *createProgressBar(int id, HWND hWnd, const Rect2ui &dimension); - static void updateProgressBar(ProgressBar *pb, ui32 step); - static void deleteProgressBar(ProgressBar *pb); - static void createMenues(Platform::Win32Window *w, Editor::OsreEdApp *app, Platform::AbstractPlatformEventQueue *queue); - static TreeView *createTreeView(Platform::Win32Window *w); -}; - -struct Widget { - Widget *mParent; - cppcore::TArray mChildren; - Rect2ui mRect; -}; - -struct Label : Widget { - String mText; -}; - -struct PlatformData { - HWND mHWnd; -}; - -/// @brief The progress-bar data. -struct ProgressBar : Widget { - ui32 mRange; - ui32 mCurrent; - - PlatformData mPlatformData; -}; - -struct TreeItem { - using TreeItemArray = ::cppcore::TArray; - - String mName; - TreeItem *mParent; - TreeItemArray mChildren; - - String generateName(); - TreeItem(); - void addChild(TreeItem *item); - size_t numChildren() const; - TreeItem *getParent() const; - PlatformData mPlatformData; - -}; - -struct TreeView : Widget { - TreeItem *mRoot; - - PlatformData mPlatformData; -}; - -struct Style { - Color4 FG; - Color4 BG; - ui32 DefaultFontSize; -}; - -} // namespace OSRE diff --git a/src/Editor/src/Gui/UIElementsWin32.cpp b/src/Editor/src/Gui/UIElementsWin32.cpp deleted file mode 100644 index fd22de23c..000000000 --- a/src/Editor/src/Gui/UIElementsWin32.cpp +++ /dev/null @@ -1,75 +0,0 @@ -/*----------------------------------------------------------------------------------------------- -The MIT License (MIT) - -Copyright (c) 2015-2024 OSRE ( Open Source Render Engine ) by Kim Kulling - -Permission is hereby granted, free of charge, to any person obtaining a copy of -this software and associated documentation files (the "Software"), to deal in -the Software without restriction, including without limitation the rights to -use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of -the Software, and to permit persons to whom the Software is furnished to do so, -subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS -FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR -COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER -IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN -CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. ------------------------------------------------------------------------------------------------*/ -#include "UIElementsWin32.h" - -#include "Debugging/osre_debugging.h" - -#include "windows.h" -#include -#include - -namespace OSRE { - -bool UIElementsWin32::sInited = false; -HMODULE lib = nullptr; - -bool UIElementsWin32::init() { - if (sInited) { - return false; - } - - // needed for the RichEdit control in the about/help dialog - lib = LoadLibrary("riched20.dll"); - if (lib == nullptr) { - osre_assert(lib != nullptr); - return false; - } - - // load windows common controls library to get XP style - InitCommonControls(); - - sInited = true; - - return true; -} - -bool UIElementsWin32::release() { - if (!sInited) { - return false; - } - FreeLibrary(lib); - lib = nullptr; - - return true; -} - -void UIElementsWin32::getMonitorResolution(ui32 &width, ui32 &heigt) { -#ifdef OSRE_WINDOWS - width = GetSystemMetrics(SM_CXSCREEN); - heigt = GetSystemMetrics(SM_CYSCREEN); -#else - width = heigt = 0; -#endif -} - -} // namespace OSRE diff --git a/src/Editor/src/Gui/UIElementsWin32.h b/src/Editor/src/Gui/UIElementsWin32.h deleted file mode 100644 index 9b3fcc8db..000000000 --- a/src/Editor/src/Gui/UIElementsWin32.h +++ /dev/null @@ -1,40 +0,0 @@ -/*----------------------------------------------------------------------------------------------- -The MIT License (MIT) - -Copyright (c) 2015-2024 OSRE ( Open Source Render Engine ) by Kim Kulling - -Permission is hereby granted, free of charge, to any person obtaining a copy of -this software and associated documentation files (the "Software"), to deal in -the Software without restriction, including without limitation the rights to -use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of -the Software, and to permit persons to whom the Software is furnished to do so, -subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS -FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR -COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER -IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN -CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. ------------------------------------------------------------------------------------------------*/ -#pragma once - -#include "Common/osre_common.h" -#include "Platform/Windows/MinWindows.h" - -namespace OSRE { - -class UIElementsWin32 { -public: - static bool init(); - static bool release(); - static void getMonitorResolution(ui32 &width, ui32 &heigt); - -private: - static bool sInited; -}; - -} // namespace OSRE diff --git a/src/Editor/src/OsreEdApp.cpp b/src/Editor/src/OsreEdApp.cpp index c26217362..aeaeb5add 100644 --- a/src/Editor/src/OsreEdApp.cpp +++ b/src/Editor/src/OsreEdApp.cpp @@ -1,13 +1,14 @@ #pragma once #include "OSREEdApp.h" -#include "ProgressReporter.h" #include "Actions/ImportAction.h" -#include "Platform/PlatformOperations.h" -#include "RenderBackend/MeshBuilder.h" -#include "App/TransformController.h" #include "App/ServiceProvider.h" +#include "App/TransformController.h" #include "Common/Logger.h" +#include "Platform/PlatformOperations.h" +#include "ProgressReporter.h" +#include "RenderBackend/MeshBuilder.h" +#include "RenderView/MainRenderView.h" namespace OSRE { namespace Editor { @@ -96,7 +97,7 @@ void OsreEdApp::loadAsset(const IO::Uri &modelLoc) { newProjectCmd(1, cppcore::Variant::createFromString(modelLoc.getResource())); } reporter.update(10); - RenderBackendService *rbSrv = ServiceProvider::getService(ServiceType::RenderService); + auto *rbSrv = ServiceProvider::getService(ServiceType::RenderService); if (nullptr == rbSrv) { reporter.stop(); return; @@ -109,8 +110,8 @@ void OsreEdApp::loadAsset(const IO::Uri &modelLoc) { mProject = createProject(modelLoc.getAbsPath()); } Entity *entity = action.getEntity(); - Entity *camEntity = new Entity(std::string("camera_1"), *getIdContainer(), scene); - CameraComponent *camera = (CameraComponent *)camEntity->createComponent(ComponentType::CameraComponentType); + auto *camEntity = new Entity(std::string("camera_1"), *getIdContainer(), scene); + auto *camera = (CameraComponent *)camEntity->createComponent(ComponentType::CameraComponentType); scene->setActiveCamera(camera); mSceneData.mCamera = camera; mSceneData.mCamera->setProjectionParameters(60.f, (f32)windowsRect.width, (f32)windowsRect.height, 0.01f, 1000.f); @@ -128,27 +129,24 @@ void OsreEdApp::loadAsset(const IO::Uri &modelLoc) { reporter.stop(); } +void setupTripod() { + Mesh *axis = MainRenderView::createCoordAxis(150); + RenderBackendService *rbSrv = ServiceProvider::getService(ServiceType::RenderService); + rbSrv->addMesh(axis, 0); +} + bool OsreEdApp::onCreate() { if (!AppBase::onCreate()) { return false; } AppBase::setWindowsTitle("Hello-World sample! Rotate with keyboard: w, a, s, d, scroll with q, e"); - Scene *world = new Scene("hello_world"); - addScene(world, true); - mEntity = new Entity("entity", *AppBase::getIdContainer(), world); - CameraComponent *camera = setupCamera(world); - - MeshBuilder meshBuilder; - RenderBackend::Mesh *mesh = meshBuilder.createCube(VertexType::ColorVertex, .5, .5, .5, BufferAccessType::ReadOnly).getMesh(); - if (nullptr != mesh) { - RenderComponent *rc = (RenderComponent *)mEntity->getComponent(ComponentType::RenderComponentType); - rc->addStaticMesh(mesh); - - Time dt; - world->update(dt); - camera->observeBoundingBox(mEntity->getAABB()); - } + Scene *scene = new Scene("hello_world"); + addScene(scene, true); + mEntity = new Entity("entity", *AppBase::getIdContainer(), scene); + CameraComponent *camera = setupCamera(scene); + setupTripod(); + mSceneData.mCamera->observeBoundingBox(mEntity->getAABB()); mKeyboardTransCtrl = AppBase::getTransformController(mTransformMatrix); osre_info(Tag, "Creation finished."); diff --git a/src/Editor/src/ProgressReporter.cpp b/src/Editor/src/ProgressReporter.cpp index b8ccbf494..908b8f280 100644 --- a/src/Editor/src/ProgressReporter.cpp +++ b/src/Editor/src/ProgressReporter.cpp @@ -24,8 +24,9 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. #include "Platform/AbstractWindow.h" #include "Platform/win32/Win32Window.h" -#include "Gui/UIElements.h" -#include "Platform/Windows/MinWindows.h" +#ifdef _WIN32 +# include "Platform/Windows/MinWindows.h" +#endif #include "Platform/AbstractOSService.h" #include "Platform/PlatformInterface.h" @@ -43,7 +44,7 @@ ProgressReporter::ProgressReporter(AbstractWindow *window) : ProgressReporter::~ProgressReporter() { if (nullptr != mProgressBar) { - UIElements::deleteProgressBar(mProgressBar); + } } @@ -65,21 +66,17 @@ void ProgressReporter::start() { if (nullptr == w) { return; } - - mProgressBar = UIElements::createProgressBar(1, w->getHWnd(), r); } void ProgressReporter::stop() { if (nullptr != mWindow) { mWindow->setWindowsMouseCursor(Platform::DefaultMouseCursorType::ComonCursor); - UIElements::deleteProgressBar(mProgressBar); mProgressBar = nullptr; } } void ProgressReporter::update(i32 percent) { mProgress = percent; - UIElements::updateProgressBar(mProgressBar, percent); } void ProgressReporter::reset() { diff --git a/src/Editor/src/RenderView/MainRenderView.cpp b/src/Editor/src/RenderView/MainRenderView.cpp index 1993e1430..d777cf17d 100644 --- a/src/Editor/src/RenderView/MainRenderView.cpp +++ b/src/Editor/src/RenderView/MainRenderView.cpp @@ -24,6 +24,9 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. #include "Animation/AnimatorBase.h" #include "RenderBackend/MaterialBuilder.h" #include "RenderBackend/Mesh.h" +#include "RenderBackend/RenderPass.h" +#include "RenderBackend/RenderBackendService.h" + namespace OSRE { namespace Editor { @@ -160,10 +163,10 @@ void MainRenderView::createRect2D(const Rect2ui &r, Mesh *mesh2D, Style &style) edges[1].position = p1; edges[2].position = p2; edges[3].position = p3; - edges[0].color0 = style.BG.toVec4(); - edges[1].color0 = style.BG.toVec4(); - edges[2].color0 = style.BG.toVec4(); - edges[3].color0 = style.BG.toVec4(); + edges[0].color0 = style.bg.toVec4(); + edges[1].color0 = style.bg.toVec4(); + edges[2].color0 = style.bg.toVec4(); + edges[3].color0 = style.bg.toVec4(); constexpr size_t NumIndices = 6; cppcore::TArray indices; diff --git a/src/Editor/src/RenderView/MainRenderView.h b/src/Editor/src/RenderView/MainRenderView.h index 529580c01..f71496e06 100644 --- a/src/Editor/src/RenderView/MainRenderView.h +++ b/src/Editor/src/RenderView/MainRenderView.h @@ -22,8 +22,6 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -----------------------------------------------------------------------------------------------*/ #pragma once -#include "Gui/UIElements.h" - #include "App/Entity.h" namespace OSRE { @@ -42,6 +40,11 @@ namespace Animation { namespace Editor { +struct Style { + Color4 fg; + Color4 bg; +}; + //------------------------------------------------------------------------------------------------- /// @ingroup Editor /// diff --git a/src/Editor/src/main.cpp b/src/Editor/src/main.cpp index b7f687a41..db8c7f459 100644 --- a/src/Editor/src/main.cpp +++ b/src/Editor/src/main.cpp @@ -56,7 +56,7 @@ int main(int argc, char *argv[]) { OsreEdApp osreApp(argc, argv); if (!osreApp.initWindow(100, 100, 1024, 768, "OSRE-Ed", WindowMode::Windowed, - WindowType::Child, + WindowType::Root, RenderBackendType::OpenGLRenderBackend)) { osre_error(Tag, "Cannot open the window."); return AppError; @@ -66,10 +66,10 @@ int main(int argc, char *argv[]) { bool running = true; while (running) { running = osreApp.handleEvents(); - Scene *world = osreApp.getActiveScene(); - if (world != nullptr) { - world = new Scene("world"); - osreApp.addScene(world, true); + Scene *scene = osreApp.getActiveScene(); + if (scene != nullptr) { + scene = new Scene("world"); + osreApp.addScene(scene, true); } osreApp.update(); osreApp.requestNextFrame(); diff --git a/src/Engine/App/AppBase.h b/src/Engine/App/AppBase.h index ac73f5420..c30d6fd45 100644 --- a/src/Engine/App/AppBase.h +++ b/src/Engine/App/AppBase.h @@ -326,13 +326,13 @@ inline Common::Ids *AppBase::getIdContainer() const { return mIds; } -inline void AppBase::addScene(Scene *world, bool enable) { - if (nullptr == world) { +inline void AppBase::addScene(Scene *scene, bool enable) { + if (nullptr == scene) { return; } - mScenes.add(world); + mScenes.add(scene); if (enable) { - mActiveScene = world; + mActiveScene = scene; } } diff --git a/src/Engine/Common/osre_common.h b/src/Engine/Common/osre_common.h index 4c719d522..00c0e4fc0 100644 --- a/src/Engine/Common/osre_common.h +++ b/src/Engine/Common/osre_common.h @@ -39,8 +39,6 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. #include #include "Common/glm_common.h" -#include -#include #include #include #include From e24fd01c5d37a22c0b56c37ca06c2d12b66f02e1 Mon Sep 17 00:00:00 2001 From: Kim Kulling Date: Thu, 30 Jan 2025 16:25:51 +0100 Subject: [PATCH 2/7] Setup axis --- src/Editor/src/OsreEdApp.cpp | 37 +++++++++++++++++++++++++----------- src/Editor/src/OsreEdApp.h | 1 + 2 files changed, 27 insertions(+), 11 deletions(-) diff --git a/src/Editor/src/OsreEdApp.cpp b/src/Editor/src/OsreEdApp.cpp index aeaeb5add..b5d872641 100644 --- a/src/Editor/src/OsreEdApp.cpp +++ b/src/Editor/src/OsreEdApp.cpp @@ -34,7 +34,11 @@ static Project *createProject(const String &name) { } OsreEdApp::OsreEdApp(int argc, char *argv[]) : - AppBase(argc, (const char **)argv, "api", "The render API"), mProject(nullptr) { + AppBase(argc, (const char **)argv, "api", "The render API"), + mProject(nullptr), + mEntity(nullptr), + mGuiEntity(nullptr), + mKeyboardTransCtrl(nullptr) { // empty } @@ -110,7 +114,7 @@ void OsreEdApp::loadAsset(const IO::Uri &modelLoc) { mProject = createProject(modelLoc.getAbsPath()); } Entity *entity = action.getEntity(); - auto *camEntity = new Entity(std::string("camera_1"), *getIdContainer(), scene); + auto *camEntity = new Entity(std::string("camera"), *getIdContainer(), scene); auto *camera = (CameraComponent *)camEntity->createComponent(ComponentType::CameraComponentType); scene->setActiveCamera(camera); mSceneData.mCamera = camera; @@ -129,10 +133,16 @@ void OsreEdApp::loadAsset(const IO::Uri &modelLoc) { reporter.stop(); } -void setupTripod() { +bool setupTripod(Entity *guiEntity) { + if (guiEntity == nullptr) { + return false; + } + Mesh *axis = MainRenderView::createCoordAxis(150); - RenderBackendService *rbSrv = ServiceProvider::getService(ServiceType::RenderService); - rbSrv->addMesh(axis, 0); + RenderComponent *rc = (RenderComponent*) guiEntity->getComponent(ComponentType::RenderComponentType); + rc->addStaticMesh(axis); + + return true; } bool OsreEdApp::onCreate() { @@ -141,13 +151,18 @@ bool OsreEdApp::onCreate() { } AppBase::setWindowsTitle("Hello-World sample! Rotate with keyboard: w, a, s, d, scroll with q, e"); - Scene *scene = new Scene("hello_world"); - addScene(scene, true); - mEntity = new Entity("entity", *AppBase::getIdContainer(), scene); - CameraComponent *camera = setupCamera(scene); - setupTripod(); - mSceneData.mCamera->observeBoundingBox(mEntity->getAABB()); + Scene *scene = getActiveScene(); + + mGuiEntity = new Entity("gui", *AppBase::getIdContainer(), scene); + scene->addEntity(mGuiEntity); + + setupTripod(mGuiEntity); mKeyboardTransCtrl = AppBase::getTransformController(mTransformMatrix); + auto *camEntity = new Entity(std::string("camera"), *getIdContainer(), scene); + auto *camera = (CameraComponent *)camEntity->createComponent(ComponentType::CameraComponentType); + scene->setActiveCamera(camera); + mSceneData.mCamera = camera; + //camera->observeBoundingBox(mGuiEntity->getAABB()); osre_info(Tag, "Creation finished."); diff --git a/src/Editor/src/OsreEdApp.h b/src/Editor/src/OsreEdApp.h index eadbc151f..f05319f05 100644 --- a/src/Editor/src/OsreEdApp.h +++ b/src/Editor/src/OsreEdApp.h @@ -27,6 +27,7 @@ class OsreEdApp : public App::AppBase { App::Project *mProject; RenderBackend::TransformMatrixBlock mTransformMatrix; App::Entity *mEntity; + App::Entity *mGuiEntity; Animation::AnimationControllerBase *mKeyboardTransCtrl; SceneData mSceneData; }; From 0e39ee4ca19cc6b5a7522f81e30001bf09d5a7a7 Mon Sep 17 00:00:00 2001 From: Kim Kulling Date: Fri, 31 Jan 2025 14:26:22 +0100 Subject: [PATCH 3/7] Fix the editor --- src/Editor/src/Actions/ActionBase.h | 2 +- src/Editor/src/Actions/ImportAction.cpp | 2 +- src/Editor/src/Actions/ImportAction.h | 2 +- .../src/Modules/LogModule/LogModule.cpp | 79 +--------------- src/Editor/src/OsreEdApp.cpp | 80 +++++++++++------ src/Editor/src/OsreEdApp.h | 30 ++++++- src/Editor/src/ProgressReporter.cpp | 2 +- src/Editor/src/ProgressReporter.h | 2 +- src/Editor/src/RenderView/MainRenderView.cpp | 10 +-- src/Editor/src/RenderView/MainRenderView.h | 2 +- src/Editor/src/SceneData.h | 2 +- src/Editor/src/main.cpp | 29 ++---- src/Engine/App/AbstractBehaviour.h | 90 ------------------- src/Engine/App/App.h | 1 - src/Engine/App/AssetRegistry.h | 3 +- src/Engine/App/AssimpWrapper.cpp | 5 +- src/Engine/App/AssimpWrapper.h | 2 +- src/Engine/App/Entity.cpp | 11 --- src/Engine/App/Entity.h | 3 - src/Engine/App/RenderComponent.cpp | 60 ------------- src/Engine/App/RenderComponent.h | 54 ----------- src/Engine/Common/ColorRGBA.h | 16 ++-- 22 files changed, 116 insertions(+), 371 deletions(-) delete mode 100644 src/Engine/App/AbstractBehaviour.h delete mode 100644 src/Engine/App/RenderComponent.cpp delete mode 100644 src/Engine/App/RenderComponent.h diff --git a/src/Editor/src/Actions/ActionBase.h b/src/Editor/src/Actions/ActionBase.h index 876510e50..cc39d7904 100644 --- a/src/Editor/src/Actions/ActionBase.h +++ b/src/Editor/src/Actions/ActionBase.h @@ -1,7 +1,7 @@ /*----------------------------------------------------------------------------------------------- The MIT License (MIT) -Copyright (c) 2015-2024 OSRE ( Open Source Render Engine ) by Kim Kulling +Copyright (c) 2015-2025 OSRE ( Open Source Render Engine ) by Kim Kulling Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in diff --git a/src/Editor/src/Actions/ImportAction.cpp b/src/Editor/src/Actions/ImportAction.cpp index b43841195..f35ef4b34 100644 --- a/src/Editor/src/Actions/ImportAction.cpp +++ b/src/Editor/src/Actions/ImportAction.cpp @@ -1,7 +1,7 @@ /*----------------------------------------------------------------------------------------------- The MIT License (MIT) -Copyright (c) 2015-2024 OSRE ( Open Source Render Engine ) by Kim Kulling +Copyright (c) 2015-2025 OSRE ( Open Source Render Engine ) by Kim Kulling Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in diff --git a/src/Editor/src/Actions/ImportAction.h b/src/Editor/src/Actions/ImportAction.h index e16d90cd5..0bab9b2c6 100644 --- a/src/Editor/src/Actions/ImportAction.h +++ b/src/Editor/src/Actions/ImportAction.h @@ -1,7 +1,7 @@ /*----------------------------------------------------------------------------------------------- The MIT License (MIT) -Copyright (c) 2015-2024 OSRE ( Open Source Render Engine ) by Kim Kulling +Copyright (c) 2015-2025 OSRE ( Open Source Render Engine ) by Kim Kulling Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in diff --git a/src/Editor/src/Modules/LogModule/LogModule.cpp b/src/Editor/src/Modules/LogModule/LogModule.cpp index af1c88181..2d33e344f 100644 --- a/src/Editor/src/Modules/LogModule/LogModule.cpp +++ b/src/Editor/src/Modules/LogModule/LogModule.cpp @@ -1,7 +1,7 @@ /*----------------------------------------------------------------------------------------------- The MIT License (MIT) -Copyright (c) 2015-2024 OSRE ( Open Source Render Engine ) by Kim Kulling +Copyright (c) 2015-2025 OSRE ( Open Source Render Engine ) by Kim Kulling Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in @@ -46,58 +46,16 @@ using namespace ::OSRE::App; using namespace ::OSRE::Modules; using namespace ::OSRE::Platform; -/* INT_PTR CALLBACK LogDialogProc(HWND hWnd, UINT uMsg, WPARAM, LPARAM lParam) { - (void)lParam; - switch (uMsg) { - case WM_INITDIALOG: - return TRUE; - - case WM_SIZE: { - const int x = LOWORD(lParam); - const int y = HIWORD(lParam); - - ::SetWindowPos(GetDlgItem(hWnd, IDC_EDIT1), nullptr, 10, 10, - x - 10, y - 12, SWP_NOMOVE | SWP_NOZORDER); - - return TRUE; - } - case WM_CLOSE: - ::CloseWindow(hWnd); - return TRUE; - }; - - return FALSE; -} -*/ static constexpr int MarginWidth = 20; static constexpr int MarginHeight = 300; -/* static HWND initLogWindow(HINSTANCE hInstance, HWND hParent, const Rect2ui &rect) { - HWND hwnd = ::CreateDialog(hInstance, MAKEINTRESOURCE(IDD_LOGVIEW), - hParent, &LogDialogProc); - if (hwnd == nullptr) { - osre_error(Tag, "Cannot create log window."); - return nullptr; - } - - ::MoveWindow(hwnd, rect.getX1() + MarginWidth, rect.getY2() - 300, rect.getX2() - rect.getX1() - MarginWidth, 280, TRUE); - if (hwnd == nullptr) { - auto err = Win32OSService::getLastErrorAsString(); - osre_error(Tag, "Unable to create log window. Error : " + err); - return nullptr; - } - - return hwnd; -} -*/ class LogView : public IModuleView { public: LogView(Platform::AbstractWindow *window) : IModuleView("logview" ), mText(), mRect(), - mRootWindow(window), - mLogWndHandle(nullptr) { + mRootWindow(window) { // empty } @@ -115,58 +73,29 @@ class LogView : public IModuleView { protected: void onCreate(const Rect2ui &rect) override { - Win32Window *w = (Win32Window *)mRootWindow; - if (w == nullptr) { - osre_error(Tag, "Cannot create log module view."); - return; - } - - // mLogWndHandle = initLogWindow(w->getModuleHandle(), w->getHWnd(), rect); - if (mLogWndHandle == nullptr) { - osre_error(Tag, "Cannot create log module view."); - return; - } - - ::ShowWindow(mLogWndHandle, SW_SHOW); - mRect = rect; } void onUpdate() override { - /* SETTEXTEX sInfo = {}; - sInfo.flags = ST_DEFAULT; - sInfo.codepage = CP_ACP; - ::SendDlgItemMessage(mLogWndHandle, IDC_EDIT1, EM_SETTEXTEX, (WPARAM)&sInfo, (LPARAM)mText.c_str());*/ } private: String mText; Platform::AbstractWindow *mRootWindow; Rect2ui mRect; - HWND mLogWndHandle; }; class LogStream : public AbstractLogStream { public: - LogStream(LogView *lv) : - AbstractLogStream(), mThreadId(999999), mLogView(lv) { - osre_assert(mLogView != nullptr); - - mThreadId = ::GetCurrentThreadId(); + LogStream(LogView *lv) : AbstractLogStream() { + // empty } ~LogStream() override = default; void write(const String &rMessage) override { - if (mThreadId == ::GetCurrentThreadId()) { - if (mLogView != nullptr) { - mLogView->addEntry(rMessage); - } - } } private: - DWORD mThreadId; - LogView *mLogView; }; class AssimpLogStream : public Assimp::LogStream { diff --git a/src/Editor/src/OsreEdApp.cpp b/src/Editor/src/OsreEdApp.cpp index b5d872641..ac2a51040 100644 --- a/src/Editor/src/OsreEdApp.cpp +++ b/src/Editor/src/OsreEdApp.cpp @@ -1,3 +1,25 @@ +/*----------------------------------------------------------------------------------------------- +The MIT License (MIT) + +Copyright (c) 2015-2025 OSRE ( Open Source Render Engine ) by Kim Kulling + +Permission is hereby granted, free of charge, to any person obtaining a copy of +this software and associated documentation files (the "Software"), to deal in +the Software without restriction, including without limitation the rights to +use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of +the Software, and to permit persons to whom the Software is furnished to do so, +subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS +FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR +COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER +IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN +CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +-----------------------------------------------------------------------------------------------*/ #pragma once #include "OSREEdApp.h" @@ -27,7 +49,7 @@ static void createTitleString(const String &projectName, String &titleString) { } static Project *createProject(const String &name) { - Project *project = new App::Project(); + auto *project = new App::Project(); project->setProjectName(name); return project; @@ -42,22 +64,20 @@ OsreEdApp::OsreEdApp(int argc, char *argv[]) : // empty } -constexpr float Near = 0.001f; -constexpr float Far = 1000.f; - -CameraComponent *OsreEdApp::setupCamera(Scene *world) { - Entity *camEntity = world->findEntity("camera"); - if (camEntity != nullptr) { - return (CameraComponent*) camEntity->getComponent(ComponentType::CameraComponentType); +CameraComponent *OsreEdApp::setupCamera(Scene *scene) { + Entity *camEntity = scene->findEntity("camera"); + if (camEntity == nullptr) { + camEntity = new Entity("camera", *getIdContainer(), scene); } - - camEntity = new Entity("camera", *getIdContainer(), world); - world->addEntity(camEntity); CameraComponent *camera = (CameraComponent*) camEntity->createComponent(ComponentType::CameraComponentType); - world->setActiveCamera(camera); + + + scene->addEntity(camEntity); + camera = (CameraComponent*) camEntity->createComponent(ComponentType::CameraComponentType); + scene->setActiveCamera(camera); ui32 w{0u}, h{0u}; AppBase::getResolution(w, h); - camera->setProjectionParameters(60.f, (f32)w, (f32)h, Near, Far); + camera->setProjectionParameters(mConfig.mFov, (f32)w, (f32)h, mConfig.mNear, mConfig.mFar); return camera; } @@ -65,7 +85,7 @@ CameraComponent *OsreEdApp::setupCamera(Scene *world) { void OsreEdApp::newProjectCmd(ui32, void *data) { String name = "New project"; if (data != nullptr) { - cppcore::Variant *v = (cppcore::Variant *)data; + cppcore::Variant *v = (cppcore::Variant*) data; name = v->getString(); } mProject = createProject(name); @@ -114,11 +134,7 @@ void OsreEdApp::loadAsset(const IO::Uri &modelLoc) { mProject = createProject(modelLoc.getAbsPath()); } Entity *entity = action.getEntity(); - auto *camEntity = new Entity(std::string("camera"), *getIdContainer(), scene); - auto *camera = (CameraComponent *)camEntity->createComponent(ComponentType::CameraComponentType); - scene->setActiveCamera(camera); - mSceneData.mCamera = camera; - mSceneData.mCamera->setProjectionParameters(60.f, (f32)windowsRect.width, (f32)windowsRect.height, 0.01f, 1000.f); + mSceneData.mCamera = setupCamera(scene); reporter.update(10); scene->addEntity(entity); @@ -133,15 +149,21 @@ void OsreEdApp::loadAsset(const IO::Uri &modelLoc) { reporter.stop(); } -bool setupTripod(Entity *guiEntity) { +bool setupEditorGimmics(Entity *guiEntity) { if (guiEntity == nullptr) { return false; } + RenderComponent *rc = (RenderComponent*) guiEntity->getComponent(ComponentType::RenderComponentType); + if (rc == nullptr) { + return false; + } Mesh *axis = MainRenderView::createCoordAxis(150); - RenderComponent *rc = (RenderComponent*) guiEntity->getComponent(ComponentType::RenderComponentType); rc->addStaticMesh(axis); + Mesh *grid = MainRenderView::createGrid(50); + rc->addStaticMesh(grid); + return true; } @@ -150,19 +172,21 @@ bool OsreEdApp::onCreate() { return false; } - AppBase::setWindowsTitle("Hello-World sample! Rotate with keyboard: w, a, s, d, scroll with q, e"); + AppBase::setWindowsTitle("OSRE Ed "); Scene *scene = getActiveScene(); mGuiEntity = new Entity("gui", *AppBase::getIdContainer(), scene); scene->addEntity(mGuiEntity); + setupEditorGimmics(mGuiEntity); + scene->init(); + + Platform::AbstractWindow *rootWindow = getRootWindow(); + Rect2ui windowsRect; + rootWindow->getWindowsRect(windowsRect); - setupTripod(mGuiEntity); mKeyboardTransCtrl = AppBase::getTransformController(mTransformMatrix); - auto *camEntity = new Entity(std::string("camera"), *getIdContainer(), scene); - auto *camera = (CameraComponent *)camEntity->createComponent(ComponentType::CameraComponentType); - scene->setActiveCamera(camera); - mSceneData.mCamera = camera; - //camera->observeBoundingBox(mGuiEntity->getAABB()); + mSceneData.mCamera = setupCamera(scene); + mSceneData.mCamera->observeBoundingBox(mGuiEntity->getAABB()); osre_info(Tag, "Creation finished."); diff --git a/src/Editor/src/OsreEdApp.h b/src/Editor/src/OsreEdApp.h index f05319f05..cce990955 100644 --- a/src/Editor/src/OsreEdApp.h +++ b/src/Editor/src/OsreEdApp.h @@ -1,3 +1,25 @@ +/*----------------------------------------------------------------------------------------------- +The MIT License (MIT) + +Copyright (c) 2015-2025 OSRE ( Open Source Render Engine ) by Kim Kulling + +Permission is hereby granted, free of charge, to any person obtaining a copy of +this software and associated documentation files (the "Software"), to deal in +the Software without restriction, including without limitation the rights to +use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of +the Software, and to permit persons to whom the Software is furnished to do so, +subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS +FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR +COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER +IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN +CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +-----------------------------------------------------------------------------------------------*/ #pragma once #include "SceneData.h" @@ -6,9 +28,7 @@ #include "App/CameraComponent.h" #include "App/Entity.h" #include "App/Scene.h" -#include "RenderBackend/RenderCommon.h" #include "RenderBackend/TransformMatrixBlock.h" -#include "RenderBackend/RenderBackendService.h" namespace OSRE { namespace Editor { @@ -24,6 +44,12 @@ class OsreEdApp : public App::AppBase { void loadAsset(const IO::Uri &modelLoc); private: + struct Config { + f32 mFov = 60.f; + f32 mNear = 0.01f; + f32 mFar = 10000.0f; + } mConfig; + App::Project *mProject; RenderBackend::TransformMatrixBlock mTransformMatrix; App::Entity *mEntity; diff --git a/src/Editor/src/ProgressReporter.cpp b/src/Editor/src/ProgressReporter.cpp index 908b8f280..0733104d8 100644 --- a/src/Editor/src/ProgressReporter.cpp +++ b/src/Editor/src/ProgressReporter.cpp @@ -1,7 +1,7 @@ /*----------------------------------------------------------------------------------------------- The MIT License (MIT) -Copyright (c) 2015-2024 OSRE ( Open Source Render Engine ) by Kim Kulling +Copyright (c) 2015-2025 OSRE ( Open Source Render Engine ) by Kim Kulling Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in diff --git a/src/Editor/src/ProgressReporter.h b/src/Editor/src/ProgressReporter.h index 7c2a231f5..389da0719 100644 --- a/src/Editor/src/ProgressReporter.h +++ b/src/Editor/src/ProgressReporter.h @@ -1,7 +1,7 @@ /*----------------------------------------------------------------------------------------------- The MIT License (MIT) -Copyright (c) 2015-2024 OSRE ( Open Source Render Engine ) by Kim Kulling +Copyright (c) 2015-2025 OSRE ( Open Source Render Engine ) by Kim Kulling Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in diff --git a/src/Editor/src/RenderView/MainRenderView.cpp b/src/Editor/src/RenderView/MainRenderView.cpp index d777cf17d..eac8300a2 100644 --- a/src/Editor/src/RenderView/MainRenderView.cpp +++ b/src/Editor/src/RenderView/MainRenderView.cpp @@ -1,7 +1,7 @@ /*----------------------------------------------------------------------------------------------- The MIT License (MIT) -Copyright (c) 2015-2024 OSRE ( Open Source Render Engine ) by Kim Kulling +Copyright (c) 2015-2025 OSRE ( Open Source Render Engine ) by Kim Kulling Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in @@ -77,12 +77,12 @@ Mesh *MainRenderView::createCoordAxis(ui32 size) { v[5].position.x = v[5].position.y = 0; v[5].color0 = Colors::Blue; - cppcore::TArray axisData; + TArray axisData; axisData.add(v, 6); axis->attachVertices(&axisData[0], sizeof(ColorVert) * axisData.size()); - cppcore::TArray axisIndices; + TArray axisIndices; axisIndices.add(0); axisIndices.add(1); @@ -108,8 +108,8 @@ Mesh *MainRenderView::createGrid(ui32 numLines) { f32 currentX = -300.0f, currentY = -300.0f; f32 diffX = 600.0f / numLines; f32 diffY = 600.0f / numLines; - cppcore::TArray lineData; - cppcore::TArray lineIndices; + TArray lineData; + TArray lineIndices; ui16 currentIndex = 0; for (ui32 x = 0; x < numLines + 1; ++x) { ColorVert v1, v2; diff --git a/src/Editor/src/RenderView/MainRenderView.h b/src/Editor/src/RenderView/MainRenderView.h index f71496e06..00ae639c8 100644 --- a/src/Editor/src/RenderView/MainRenderView.h +++ b/src/Editor/src/RenderView/MainRenderView.h @@ -1,7 +1,7 @@ /*----------------------------------------------------------------------------------------------- The MIT License (MIT) -Copyright (c) 2015-2024 OSRE ( Open Source Render Engine ) by Kim Kulling +Copyright (c) 2015-2025 OSRE ( Open Source Render Engine ) by Kim Kulling Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in diff --git a/src/Editor/src/SceneData.h b/src/Editor/src/SceneData.h index 6026cfcdd..15d559375 100644 --- a/src/Editor/src/SceneData.h +++ b/src/Editor/src/SceneData.h @@ -1,7 +1,7 @@ /*----------------------------------------------------------------------------------------------- The MIT License (MIT) -Copyright (c) 2015-2024 OSRE ( Open Source Render Engine ) by Kim Kulling +Copyright (c) 2015-2025 OSRE ( Open Source Render Engine ) by Kim Kulling Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in diff --git a/src/Editor/src/main.cpp b/src/Editor/src/main.cpp index db8c7f459..6e492a1dc 100644 --- a/src/Editor/src/main.cpp +++ b/src/Editor/src/main.cpp @@ -1,7 +1,7 @@ /*----------------------------------------------------------------------------------------------- The MIT License (MIT) -Copyright (c) 2015-2024 OSRE ( Open Source Render Engine ) by Kim Kulling +Copyright (c) 2015-2025 OSRE ( Open Source Render Engine ) by Kim Kulling Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in @@ -20,25 +20,16 @@ COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -----------------------------------------------------------------------------------------------*/ -#include -#include - #define main main #include "App/App.h" -#include "RenderBackend/RenderCommon.h" -#include "RenderBackend/MeshBuilder.h" #include "Common/Logger.h" -#include "RenderBackend/RenderBackendService.h" #include "RenderBackend/TransformMatrixBlock.h" -#include "App/Entity.h" -#include "Platform/AbstractWindow.h" -#include "Common/glm_common.h" -#include "Platform/PlatformInterface.h" #include "Platform/win32/Win32Window.h" - #include "OSREEdApp.h" +#include + using namespace OSRE; using namespace OSRE::RenderBackend; using namespace OSRE::App; @@ -50,11 +41,14 @@ static constexpr c8 Tag[] = "HelloWorldApp"; static constexpr i32 AppOk = 0; static constexpr i32 AppError = -1; -int main(int argc, char *argv[]) { - std::cout << "Editor version 0.1\n"; +static String getVersion() { + String v = "0.0.1"; + return v; +} +int main(int argc, char *argv[]) { OsreEdApp osreApp(argc, argv); - if (!osreApp.initWindow(100, 100, 1024, 768, "OSRE-Ed", + if (!osreApp.initWindow(100, 100, 1024, 768, "OSRE-Ed version " + getVersion(), WindowMode::Windowed, WindowType::Root, RenderBackendType::OpenGLRenderBackend)) { @@ -66,11 +60,6 @@ int main(int argc, char *argv[]) { bool running = true; while (running) { running = osreApp.handleEvents(); - Scene *scene = osreApp.getActiveScene(); - if (scene != nullptr) { - scene = new Scene("world"); - osreApp.addScene(scene, true); - } osreApp.update(); osreApp.requestNextFrame(); } diff --git a/src/Engine/App/AbstractBehaviour.h b/src/Engine/App/AbstractBehaviour.h deleted file mode 100644 index 8b152e757..000000000 --- a/src/Engine/App/AbstractBehaviour.h +++ /dev/null @@ -1,90 +0,0 @@ -/*----------------------------------------------------------------------------------------------- -The MIT License (MIT) - -Copyright (c) 2015-2024 OSRE ( Open Source Render Engine ) by Kim Kulling - -Permission is hereby granted, free of charge, to any person obtaining a copy of -this software and associated documentation files (the "Software"), to deal in -the Software without restriction, including without limitation the rights to -use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of -the Software, and to permit persons to whom the Software is furnished to do so, -subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS -FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR -COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER -IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN -CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. ------------------------------------------------------------------------------------------------*/ -#pragma once - -#include "Common/osre_common.h" - -namespace OSRE { -namespace App { - -//------------------------------------------------------------------------------------------------- -/// @ingroup Engine -/// -/// @brief This class is used to implement behavior controls. -//------------------------------------------------------------------------------------------------- -class AbstractBehaviour { -public: - /// @brief The class destructor, virtual. - virtual ~AbstractBehaviour() = default; - - /// @brief The update method. - /// @param[in] dt The time difference. - virtual bool update(Time dt ) { - return onUpdate(dt); - } - - virtual bool mouseDown() { - return onMouseDown(); - } - - virtual bool mouseUp() { - return onMouseUp(); - } - - virtual bool keyboardDown() { - return onKeyboardDown(); - } - - virtual bool keyboardUp() { - return onKeyboardUp(); - } - -protected: - AbstractBehaviour() { - // empty - } - - virtual bool onUpdate(Time ) { - return true; - } - - virtual bool onMouseDown() { - return true; - } - - virtual bool onMouseUp() { - return true; - } - - virtual bool onKeyboardDown() { - return true; - } - - virtual bool onKeyboardUp() { - return true; - } -}; - -} // Namespace App -} // Namespace OSRE - diff --git a/src/Engine/App/App.h b/src/Engine/App/App.h index 2b9542cc9..4ec3e6cbe 100644 --- a/src/Engine/App/App.h +++ b/src/Engine/App/App.h @@ -23,7 +23,6 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. #pragma once // The public API from the App-layer -#include "App/AbstractBehaviour.h" #include "App/AppBase.h" #include "App/Component.h" #include "App/CameraComponent.h" diff --git a/src/Engine/App/AssetRegistry.h b/src/Engine/App/AssetRegistry.h index fc28061e2..ee6ca2d5a 100644 --- a/src/Engine/App/AssetRegistry.h +++ b/src/Engine/App/AssetRegistry.h @@ -106,8 +106,7 @@ class OSRE_EXPORT AssetRegistry { /// @brief The class destructor. ~AssetRegistry() = default; - -private: + static AssetRegistry *sInstance; struct PathNode { String mountPoint; diff --git a/src/Engine/App/AssimpWrapper.cpp b/src/Engine/App/AssimpWrapper.cpp index 85e3ccf6b..ca8dabca1 100644 --- a/src/Engine/App/AssimpWrapper.cpp +++ b/src/Engine/App/AssimpWrapper.cpp @@ -136,11 +136,9 @@ bool AssimpWrapper::importAsset(const IO::Uri &file, ui32 flags) { flags = DefaultImportFlags; } - printf("Uri = %s\n", file.getUri().c_str()); mAssetContext.mRoot = AssetRegistry::getPath("media"); mAssetContext.mAbsPathWithFile = AssetRegistry::resolvePathFromUri(file); - printf("Path = %s\n", mAssetContext.mAbsPathWithFile.c_str()); String filename; if (!Directory::getDirectoryAndFile(mAssetContext.mAbsPathWithFile, mAssetContext.mRoot, filename)) { osre_error(Tag, "Error while separating folder and file from " + mAssetContext.mAbsPathWithFile); @@ -157,7 +155,6 @@ bool AssimpWrapper::importAsset(const IO::Uri &file, ui32 flags) { mImporter = new Importer; osre_debug(Tag, "Start importing " + filename + "."); - printf("filename = %s\n", filename.c_str()); mAssetContext.mScene = mImporter->ReadFile(filename, flags); if (nullptr == mAssetContext.mScene) { osre_error(Tag, "Cannot start importing " + filename + ", scene is nullptr."); @@ -423,7 +420,7 @@ void AssimpWrapper::importMeshes(aiMesh **meshes, ui32 numMeshes) { mat2MeshMap.clear(); } -void AssimpWrapper::importNode(aiNode *node, TransformComponent *parent) { +void AssimpWrapper::importNode(const aiNode *node, TransformComponent *parent) { if (nullptr == node) { return; } diff --git a/src/Engine/App/AssimpWrapper.h b/src/Engine/App/AssimpWrapper.h index 84b79d5b6..33091bda6 100644 --- a/src/Engine/App/AssimpWrapper.h +++ b/src/Engine/App/AssimpWrapper.h @@ -109,7 +109,7 @@ class OSRE_EXPORT AssimpWrapper { protected: Entity *convertScene(); void importMeshes( aiMesh **meshes, ui32 numMeshes ); - void importNode( aiNode *node, TransformComponent *parent ); + void importNode(const aiNode *node, TransformComponent *parent ); void importMaterial( aiMaterial *material ); void importAnimations(const aiScene *scene); void optimizeVertexBuffer(); diff --git a/src/Engine/App/Entity.cpp b/src/Engine/App/Entity.cpp index 742682171..6bca6e1ee 100644 --- a/src/Engine/App/Entity.cpp +++ b/src/Engine/App/Entity.cpp @@ -21,11 +21,9 @@ IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -----------------------------------------------------------------------------------------------*/ #include "App/Entity.h" -#include "App/AbstractBehaviour.h" #include "App/Component.h" #include "App/CameraComponent.h" #include "App/Scene.h" -#include "Animation/AnimatorBase.h" #include "Animation/AnimatorComponent.h" #include "RenderBackend/MeshProcessor.h" @@ -38,7 +36,6 @@ using namespace ::OSRE::RenderBackend; Entity::Entity(const String &name, Common::Ids &ids, Scene *world) : Object(name), - mBehavior(nullptr), mRenderComponent(nullptr), mComponentArray(), mTransformNode(nullptr), @@ -63,10 +60,6 @@ Entity::~Entity() { } } -void Entity::setBehaviourControl(AbstractBehaviour *behaviour) { - mBehavior = behaviour; -} - void Entity::setNode(TransformComponent *node) { mTransformNode = node; } @@ -76,10 +69,6 @@ TransformComponent *Entity::getNode() const { } bool Entity::update(Time dt) { - if (nullptr != mBehavior) { - mBehavior->update(dt); - } - for (auto &it : mComponentArray) { if (it != nullptr) { it->update(dt); diff --git a/src/Engine/App/Entity.h b/src/Engine/App/Entity.h index 148ab8e38..7330dbbd9 100644 --- a/src/Engine/App/Entity.h +++ b/src/Engine/App/Entity.h @@ -42,7 +42,6 @@ namespace IO { namespace App { class TransformComponent; -class AbstractBehaviour; class Component; class RenderComponent; class AppBase; @@ -59,7 +58,6 @@ class OSRE_EXPORT Entity final : public Common::Object { Entity(const String &name, Common::Ids &ids, Scene *world); ~Entity() override; - void setBehaviourControl(AbstractBehaviour *behaviour ); void setNode(TransformComponent *node); TransformComponent *getNode() const; bool update( Time dt ); @@ -70,7 +68,6 @@ class OSRE_EXPORT Entity final : public Common::Object { const Common::AABB &getAABB() const; private: - AbstractBehaviour *mBehavior; RenderComponent *mRenderComponent; ComponentArray mComponentArray; TransformComponent *mTransformNode; diff --git a/src/Engine/App/RenderComponent.cpp b/src/Engine/App/RenderComponent.cpp deleted file mode 100644 index 8f573e3e7..000000000 --- a/src/Engine/App/RenderComponent.cpp +++ /dev/null @@ -1,60 +0,0 @@ -#include "RenderComponent.h" -#include - -namespace OSRE { -namespace App { - -using namespace ::OSRE::RenderBackend; - -RenderComponent::RenderComponent(Entity *owner) : - Component(owner, ComponentType::RenderComponentType), m_newGeo() { - // empty -} - -void RenderComponent::addStaticMesh(Mesh *geo) { - if (nullptr == geo) { - return; - } - - m_newGeo.add(geo); -} - -void RenderComponent::addStaticMeshArray(const RenderBackend::MeshArray &array) { - if (array.isEmpty()) { - return; - } - - for (size_t i = 0; i < array.size(); ++i) { - m_newGeo.add(array[i]); - } -} - -size_t RenderComponent::getNumGeometry() const { - return m_newGeo.size(); -} - -Mesh *RenderComponent::getMeshAt(size_t idx) const { - return m_newGeo[idx]; -} - -void RenderComponent::getMeshArray(RenderBackend::MeshArray &meshArray) { - meshArray = m_newGeo; -} - -bool RenderComponent::onUpdate(Time) { - return true; -} - -bool RenderComponent::onRender(RenderBackendService *renderBackendSrv) { - if (!m_newGeo.isEmpty()) { - for (ui32 i = 0; i < m_newGeo.size(); i++) { - renderBackendSrv->addMesh(m_newGeo[i], 0); - } - m_newGeo.resize(0); - } - - return true; -} - -} // namespace App -} // namespace OSRE diff --git a/src/Engine/App/RenderComponent.h b/src/Engine/App/RenderComponent.h deleted file mode 100644 index 5758954a1..000000000 --- a/src/Engine/App/RenderComponent.h +++ /dev/null @@ -1,54 +0,0 @@ -#pragma once - -#include -#include -#include - -namespace OSRE { -namespace App { - -//------------------------------------------------------------------------------------------------- -/// @ingroup Engine -/// -/// @brief Describes the render component -//------------------------------------------------------------------------------------------------- -class OSRE_EXPORT RenderComponent : public Component { -public: - /// @brief - /// @param owner - RenderComponent(Entity *owner); - - /// @brief - ~RenderComponent() override = default; - - /// @brief - /// @return - size_t getNumGeometry() const; - - /// @brief - /// @param idx - /// @return - RenderBackend::Mesh *getMeshAt(size_t idx) const; - - /// @brief - /// @param array - void getMeshArray(RenderBackend::MeshArray &array); - - /// @brief - /// @param geo - void addStaticMesh(RenderBackend::Mesh *geo); - - /// @brief - /// @param array - void addStaticMeshArray(const RenderBackend::MeshArray &array); - -protected: - bool onUpdate(Time dt) override; - bool onRender(RenderBackend::RenderBackendService *rbSrv) override; - -private: - cppcore::TArray m_newGeo; -}; - -} // namespace App -} // namespace OSRE \ No newline at end of file diff --git a/src/Engine/Common/ColorRGBA.h b/src/Engine/Common/ColorRGBA.h index e9fa41580..c0b6bda87 100644 --- a/src/Engine/Common/ColorRGBA.h +++ b/src/Engine/Common/ColorRGBA.h @@ -42,11 +42,11 @@ class OSRE_EXPORT ColorRGBA { ColorRGBA(); /// @brief The class constructor with an array of the 4 float components. - /// @param pData [in] A pointer showing to the buffer. - ColorRGBA( f32 *pData ); + /// @param[in] data A pointer showing to the buffer. + ColorRGBA( f32 *data ); /// @brief The class constructor with the color components. - /// @param r, g, b, a [in] The several components. + /// @param[in] r, g, b, a The several components. ColorRGBA( f32 r, f32 g, f32 b, f32 a ); /// @brief The class copy constructor. @@ -104,11 +104,11 @@ inline ColorRGBA::ColorRGBA() { m_ColorValues[ 3 ] = 0.0f; } -inline ColorRGBA::ColorRGBA( f32 *pData ) { - m_ColorValues[ 0 ] = pData[ 0 ]; - m_ColorValues[ 1 ] = pData[ 1 ]; - m_ColorValues[ 2 ] = pData[ 2 ]; - m_ColorValues[ 3 ] = pData[ 3 ]; +inline ColorRGBA::ColorRGBA( f32 *data ) { + m_ColorValues[ 0 ] = data[ 0 ]; + m_ColorValues[ 1 ] = data[ 1 ]; + m_ColorValues[ 2 ] = data[ 2 ]; + m_ColorValues[ 3 ] = data[ 3 ]; } inline ColorRGBA::ColorRGBA( f32 r, f32 g, f32 b, f32 a ) { From 0c6ebbcd20f3655c4af4f89a70c857b08e6eff14 Mon Sep 17 00:00:00 2001 From: Kim Kulling Date: Fri, 31 Jan 2025 16:07:40 +0100 Subject: [PATCH 4/7] Fix the build --- src/Editor/src/Modules/LogModule/LogModule.cpp | 7 ++++--- src/Editor/src/OsreEdApp.cpp | 3 +++ 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/src/Editor/src/Modules/LogModule/LogModule.cpp b/src/Editor/src/Modules/LogModule/LogModule.cpp index 2d33e344f..fbe551443 100644 --- a/src/Editor/src/Modules/LogModule/LogModule.cpp +++ b/src/Editor/src/Modules/LogModule/LogModule.cpp @@ -26,15 +26,15 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. #include "Common/Logger.h" #include "Common/osre_common.h" -#include "Common/Logger.h" #include "Platform/AbstractWindow.h" #include #include #include -#include "richedit.h" #include "Platform/win32/Win32Window.h" -#include "Platform/win32/Win32OSService.h" +#include "richedit.h" + +#include namespace OSRE { namespace Editor { @@ -93,6 +93,7 @@ class LogStream : public AbstractLogStream { ~LogStream() override = default; void write(const String &rMessage) override { + std::cout << rMessage << std::endl; } private: diff --git a/src/Editor/src/OsreEdApp.cpp b/src/Editor/src/OsreEdApp.cpp index ac2a51040..a1ea3de7c 100644 --- a/src/Editor/src/OsreEdApp.cpp +++ b/src/Editor/src/OsreEdApp.cpp @@ -30,6 +30,9 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. #include "Platform/PlatformOperations.h" #include "ProgressReporter.h" #include "RenderBackend/MeshBuilder.h" +#include "RenderBackend/Material.h" +#include "RenderBackend/RenderPass.h" +#include "RenderBackend/RenderBackendService.h" #include "RenderView/MainRenderView.h" namespace OSRE { From 2a1f742f32b2afd04d2e420104673d13430f77d2 Mon Sep 17 00:00:00 2001 From: Kim Kulling Date: Fri, 31 Jan 2025 16:09:45 +0100 Subject: [PATCH 5/7] Remove stuff from cmake --- src/Engine/CMakeLists.txt | 1 - 1 file changed, 1 deletion(-) diff --git a/src/Engine/CMakeLists.txt b/src/Engine/CMakeLists.txt index 0a89b3672..f4492c51d 100644 --- a/src/Engine/CMakeLists.txt +++ b/src/Engine/CMakeLists.txt @@ -48,7 +48,6 @@ SET( app_src App/AppCommon.h App/AssetBundle.h App/AssetRegistry.h - App/AbstractBehaviour.h App/TransformComponent.h App/TransformComponent.cpp App/CameraComponent.h From 7f8240c97c05e5acb5fbd885d0cee7b3cf3e45eb Mon Sep 17 00:00:00 2001 From: Kim Kulling Date: Fri, 31 Jan 2025 20:43:35 +0100 Subject: [PATCH 6/7] Fix review findings --- .../src/Modules/LogModule/LogModule.cpp | 60 ++++++++++++++----- src/Editor/src/Modules/LogModule/LogModule.h | 2 +- src/Editor/src/OsreEdApp.cpp | 4 +- 3 files changed, 48 insertions(+), 18 deletions(-) diff --git a/src/Editor/src/Modules/LogModule/LogModule.cpp b/src/Editor/src/Modules/LogModule/LogModule.cpp index fbe551443..0236a6d7e 100644 --- a/src/Editor/src/Modules/LogModule/LogModule.cpp +++ b/src/Editor/src/Modules/LogModule/LogModule.cpp @@ -49,13 +49,30 @@ using namespace ::OSRE::Platform; static constexpr int MarginWidth = 20; static constexpr int MarginHeight = 300; -class LogView : public IModuleView { +/** + * @class LogView + * @brief Provides a module-specific implementation for managing and displaying log entries. + * + * The `LogView` class extends from `IModuleView` and serves as a mechanism to + * manage log messages within a module. It provides functionalities to add, clear, + * and display log messages. The class ensures that changes in the log data are + * updated in real-time via the `onUpdate()` method. + * + * A `LogView` requires an `AbstractWindow` instance upon construction. The + * `addEntry` method allows appending log messages, while the `clear` method + * resets the log storage. Changes to the log are visualized through the `onUpdate` + * call, which outputs the log data and resets after displaying. + * + * This class also overrides `onCreate` and `onUpdate`, ensuring integration + * with the lifecycle of the module view. + * + * @note The log data is cleared after each update in `onUpdate`. + */ +class LogView final : public IModuleView { public: - LogView(Platform::AbstractWindow *window) : + explicit LogView(AbstractWindow *window) : IModuleView("logview" ), - mText(), - mRect(), - mRootWindow(window) { + mText() { // empty } @@ -66,7 +83,7 @@ class LogView : public IModuleView { onUpdate(); } - void addEntry(String text) { + void addEntry(const String &text) { mText.append(text); onUpdate(); } @@ -76,37 +93,52 @@ class LogView : public IModuleView { } void onUpdate() override { + std::cout << mText << std::endl; + mText.clear(); } private: String mText; - Platform::AbstractWindow *mRootWindow; - Rect2ui mRect; }; class LogStream : public AbstractLogStream { public: - LogStream(LogView *lv) : AbstractLogStream() { - // empty + explicit LogStream(LogView *logView) : AbstractLogStream(), mLogView(logView) { + osre_assert(logView != nullptr); } ~LogStream() override = default; void write(const String &rMessage) override { - std::cout << rMessage << std::endl; + if (mLogView != nullptr) { + mLogView->addEntry(rMessage); + } } private: + LogView *mLogView; }; -class AssimpLogStream : public Assimp::LogStream { +/** + * @class AssimpLogStream + * @brief Implements a custom log stream for Assimp logging to interface with a given LogView. + * + * This class extends the Assimp::LogStream interface, providing a mechanism + * to redirect log messages from the Assimp library to a given `LogView` instance. + * The log message is formatted and augmented with `(Assimp)` before being passed + * to the `LogView` for visualization or storage. + * + * @note The constructor requires a valid `LogView` instance; passing a nullptr will + * trigger an assertion failure. + */ +class AssimpLogStream final : public Assimp::LogStream { public: - AssimpLogStream(LogView *logView) : + explicit AssimpLogStream(LogView *logView) : LogStream(), mLogView(logView) { osre_assert(logView != nullptr); } - ~AssimpLogStream() = default; + ~AssimpLogStream() override = default; void write(const char *message) override { String logMsg = String(message)+ " (Assimp)"; diff --git a/src/Editor/src/Modules/LogModule/LogModule.h b/src/Editor/src/Modules/LogModule/LogModule.h index c418925cc..c6e9f0a99 100644 --- a/src/Editor/src/Modules/LogModule/LogModule.h +++ b/src/Editor/src/Modules/LogModule/LogModule.h @@ -44,7 +44,7 @@ class LogModule : public Modules::ModuleBase { public: /// @brief The class constructor. /// @param[in] parentApp The parent application. - LogModule(App::AppBase *parentApp); + explicit LogModule(App::AppBase *parentApp); /// @brief The class destructor. ~LogModule() override; diff --git a/src/Editor/src/OsreEdApp.cpp b/src/Editor/src/OsreEdApp.cpp index a1ea3de7c..40e7b008f 100644 --- a/src/Editor/src/OsreEdApp.cpp +++ b/src/Editor/src/OsreEdApp.cpp @@ -72,11 +72,9 @@ CameraComponent *OsreEdApp::setupCamera(Scene *scene) { if (camEntity == nullptr) { camEntity = new Entity("camera", *getIdContainer(), scene); } - CameraComponent *camera = (CameraComponent*) camEntity->createComponent(ComponentType::CameraComponentType); - + auto *camera = (CameraComponent*) camEntity->createComponent(ComponentType::CameraComponentType); scene->addEntity(camEntity); - camera = (CameraComponent*) camEntity->createComponent(ComponentType::CameraComponentType); scene->setActiveCamera(camera); ui32 w{0u}, h{0u}; AppBase::getResolution(w, h); From e943c4032ad1303201ab77a3e587da7a0a4b95db Mon Sep 17 00:00:00 2001 From: Kim Kulling Date: Fri, 31 Jan 2025 20:54:28 +0100 Subject: [PATCH 7/7] Update LogModule.cpp --- src/Editor/src/Modules/LogModule/LogModule.cpp | 3 --- 1 file changed, 3 deletions(-) diff --git a/src/Editor/src/Modules/LogModule/LogModule.cpp b/src/Editor/src/Modules/LogModule/LogModule.cpp index 0236a6d7e..7fd23d838 100644 --- a/src/Editor/src/Modules/LogModule/LogModule.cpp +++ b/src/Editor/src/Modules/LogModule/LogModule.cpp @@ -31,9 +31,6 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. #include #include -#include "Platform/win32/Win32Window.h" -#include "richedit.h" - #include namespace OSRE {