Skip to content

Commit

Permalink
Merge pull request #232 from kimkulling/kimkulling/fix_editor_loading
Browse files Browse the repository at this point in the history
Fix crashes
  • Loading branch information
kimkulling authored Sep 13, 2024
2 parents 5b83340 + e4c3a76 commit d539d80
Show file tree
Hide file tree
Showing 8 changed files with 39 additions and 33 deletions.
4 changes: 3 additions & 1 deletion samples/00_HelloWorld/HelloWorld.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,9 @@ class HelloWorldApp : public App::AppBase {

void onUpdate() override {
Platform::Key key = AppBase::getKeyboardEventListener()->getLastKey();
mKeyboardTransCtrl->update(mKeyboardTransCtrl->getKeyBinding(key));
if (key != Platform::KEY_UNKNOWN) {
mKeyboardTransCtrl->update(mKeyboardTransCtrl->getKeyBinding(key));
}

RenderBackendService *rbSrv = ServiceProvider::getService<RenderBackendService>(ServiceType::RenderService);

Expand Down
2 changes: 1 addition & 1 deletion samples/01_ModelLoading/ModelLoading.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ class ModelLoadingApp : public App::AppBase {

int main(int argc, char *argv[]) {
ModelLoadingApp myApp(argc, argv);
if (!myApp.initWindow(10, 10, 1024, 768, "ModelLoader sample! Press o to import an Asset", false, false, App::RenderBackendType::OpenGLRenderBackend)) {
if (!myApp.initWindow(10, 10, 1024, 768, "ModelLoader sample! Press o to import an Asset", WindowMode::Windowed, WindowType::Root, App::RenderBackendType::OpenGLRenderBackend)) {
return 1;
}

Expand Down
2 changes: 1 addition & 1 deletion samples/03_Instancing/Instancing.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ class InstancingApp : public App::AppBase {

int main(int argc, char *argv[]) {
InstancingApp myApp(argc, argv);
if (!myApp.initWindow(10, 10, 1024, 768, "Instancing-Sample", false, false, RenderBackendType::OpenGLRenderBackend)) {
if (!myApp.initWindow(10, 10, 1024, 768, "Instancing-Sample", WindowMode::Windowed, WindowType::Root, RenderBackendType::OpenGLRenderBackend)) {
return 1;
}

Expand Down
3 changes: 1 addition & 2 deletions samples/04_terrain/TerrainRendering.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ class TerrainRenderingApp : public App::AppBase {

int main(int argc, char *argv[]) {
TerrainRenderingApp myApp(argc, argv);
if (!myApp.initWindow(10, 10, 1024, 768, "Instancing-Sample", false, false, RenderBackendType::OpenGLRenderBackend)) {
if (!myApp.initWindow(10, 10, 1024, 768, "Instancing-Sample", WindowMode::Windowed, WindowType::Root, RenderBackendType::OpenGLRenderBackend)) {
return 1;
}

Expand All @@ -218,4 +218,3 @@ int main(int argc, char *argv[]) {

return 0;
}

12 changes: 10 additions & 2 deletions src/Editor/src/OsreEdApp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
#include "OSREEdApp.h"
#include "ProgressReporter.h"
#include "Actions/ImportAction.h"

#include "Platform/PlatformOperations.h"
#include "RenderBackend/MeshBuilder.h"
#include "App/Stage.h"
#include "App/TransformController.h"
Expand Down Expand Up @@ -154,8 +154,16 @@ bool OsreEdApp::onCreate() {
}

void OsreEdApp::onUpdate() {
if (AppBase::isKeyPressed(Platform::KEY_O) || AppBase::isKeyPressed(Platform::KEY_o)) {
IO::Uri modelLoc;
Platform::PlatformOperations::getFileOpenDialog("Choose asset for import", "*", modelLoc);
if (modelLoc.isValid()) {
loadAsset(modelLoc);
}
}

Platform::Key key = AppBase::getKeyboardEventListener()->getLastKey();
if (mKeyboardTransCtrl != nullptr) {
if (key != Platform::KEY_UNKNOWN && mKeyboardTransCtrl != nullptr) {
mKeyboardTransCtrl->update(mKeyboardTransCtrl->getKeyBinding(key));
}

Expand Down
27 changes: 5 additions & 22 deletions src/Editor/src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
#include "App/Entity.h"
#include "Platform/AbstractWindow.h"
#include "Common/glm_common.h"
#include "Platform/PlatformOperations.h"
//#include "Platform/PlatformOperations.h"
#include "Platform/PlatformInterface.h"
#include "Platform/win32/Win32Window.h"

Expand All @@ -48,39 +48,22 @@ using namespace OSRE::Editor;

static constexpr c8 Tag[] = "HelloWorldApp";


int main(int argc, char *argv[]) {
std::cout << "Editor version 0.1\n";

OsreEdApp osreApp(argc, argv);
if (!osreApp.initWindow(100, 100, 1024, 768, "test", false, true, App::RenderBackendType::OpenGLRenderBackend)) {
if (!osreApp.initWindow(100, 100, 1024, 768, "test", WindowMode::Windowed, WindowType::Root, App::RenderBackendType::OpenGLRenderBackend)) {
return -1;
}

IO::Uri modelLoc;
PlatformOperations::getFileOpenDialog("Select asset for import", "*", modelLoc);
if (modelLoc.isValid()) {
osreApp.loadAsset(modelLoc);
}

// Main loop
bool done = false;
while (!done) {

// 2. Show a simple window that we create ourselves. We use a Begin/End pair to create a named window.
{
static int counter = 0;

App::Stage *stage = osreApp.getStage();
if (stage != nullptr) {
World *world = stage->getActiveWorld(0);
}

}
done = !osreApp.handleEvents();
osreApp.update();
osreApp.requestNextFrame();
}

osreApp.handleEvents();
osreApp.update();
osreApp.requestNextFrame();
return 0;
}
6 changes: 3 additions & 3 deletions src/Engine/App/AppBase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -82,16 +82,16 @@ AppBase::~AppBase() {
delete mSettings;
}

bool AppBase::initWindow(ui32 x, ui32 y, ui32 width, ui32 height, const String &title, bool fullscreen, bool childWindow,
bool AppBase::initWindow(ui32 x, ui32 y, ui32 width, ui32 height, const String &title, WindowMode mode, WindowType type,
RenderBackendType renderer) {
osre_assert(nullptr != mSettings);

mSettings->setInt(Settings::WinX, x);
mSettings->setInt(Settings::WinY, y);
mSettings->setInt(Settings::WinWidth, width);
mSettings->setInt(Settings::WinHeight, height);
mSettings->setBool(Settings::FullScreen, fullscreen);
mSettings->setBool(Settings::ChildWindow, childWindow);
mSettings->setBool(Settings::FullScreen, mode == WindowMode::Fullscreen);
mSettings->setBool(Settings::ChildWindow, type == WindowType::Child);
mSettings->setString(Settings::WindowsTitle, title);
if (renderer == RenderBackendType::OpenGLRenderBackend) {
mSettings->setString(Settings::RenderAPI, "opengl");
Expand Down
16 changes: 15 additions & 1 deletion src/Engine/App/AppBase.h
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,20 @@ class OSRE_EXPORT KeyboardEventListener : public Platform::OSEventListener {
char mKeymap[Platform::KEY_LAST];
};

enum class WindowMode {
Invalid,
Windowed,
Fullscreen,
Count
};

enum class WindowType {
Invalid,
Root,
Child,
Count
};

//-------------------------------------------------------------------------------------------------
/// @ingroup Engine
///
Expand Down Expand Up @@ -143,7 +157,7 @@ class OSRE_EXPORT AppBase {
/// @param[in] renderer The requested render mode.
/// @return true, if the window was generated.
virtual bool initWindow( ui32 x, ui32 y, ui32 width, ui32 height, const String &title,
bool fullscreen, bool childWindow, RenderBackendType renderer);
WindowMode mode, WindowType type, RenderBackendType renderer);

/// @brief Creates the application.
/// @param settings [in] The user-defined settings.
Expand Down

0 comments on commit d539d80

Please sign in to comment.