Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Stage: Introduce 2D and 3D for stages. #241

Merged
merged 2 commits into from
Sep 20, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion contrib/assimp
Submodule assimp updated 213 files
4 changes: 2 additions & 2 deletions src/Engine/Animation/AnimatorComponent.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,12 +49,12 @@ struct AnimationTrack {
//-------------------------------------------------------------------------------------------------
/// @ingroup Engine
///
/// @brief Describes the base class for all components.
/// @brief
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add a brief description for the class.

The brief comment for the class AnimatorComponent has been left empty. It's important to provide a concise description of the class to help readers understand its purpose and functionality.

Consider adding a brief description, such as:

/// @brief Represents a component that manages animation tracks and updates the owner entity's animation state.

//-------------------------------------------------------------------------------------------------
class AnimatorComponent : public App::Component {
public:
AnimatorComponent(App::Entity *owner, App::ComponentType type);
~AnimatorComponent();
~AnimatorComponent() override;
void addTrack(AnimationTrack *track);
AnimationTrack *getTrackAt(size_t index) const;
bool selectTrack(size_t index);
Expand Down
26 changes: 13 additions & 13 deletions src/Engine/App/AppBase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
#include "App/ResourceCacheService.h"
#include "App/ServiceProvider.h"
#include "App/World.h"
#include "App/Stage.h"
#include "App/TransformController.h"
#include "Common/Environment.h"
#include "Common/TObjPtr.h"
Expand Down Expand Up @@ -59,6 +58,17 @@

static constexpr c8 Tag[] = "AppBase";

static void attachMouseEventPtrs(EventPtrArray &eventArray) {
eventArray.add(&MouseButtonDownEvent);
eventArray.add(&MouseButtonUpEvent);
eventArray.add(&MouseMoveEvent);
}

static void attachKeyboardEventPtrs(EventPtrArray &eventArray) {
eventArray.add(&KeyboardButtonDownEvent);
eventArray.add(&KeyboardButtonUpEvent);
}

AppBase::AppBase(i32 argc, const c8 *argv[], const String &supportedArgs, const String &desc) :
mAppState(State::Uninited),
mLastTime(0l),
Expand All @@ -73,6 +83,7 @@
mMouseEvListener(nullptr),
mKeyboardEvListener(nullptr),
mIds(nullptr),
mStageMode(StageMode::Stage3D),
mShutdownRequested(false) {
mSettings->setString(Properties::Settings::RenderAPI, "opengl");
mSettings->setBool(Properties::Settings::PollingMode, true);
Expand Down Expand Up @@ -224,17 +235,6 @@
}
}

static void attachMouseEventPtrs(EventPtrArray &eventArray) {
eventArray.add(&MouseButtonDownEvent);
eventArray.add(&MouseButtonUpEvent);
eventArray.add(&MouseMoveEvent);
}

static void attachKeyboardEventPtrs(EventPtrArray &eventArray) {
eventArray.add(&KeyboardButtonDownEvent);
eventArray.add(&KeyboardButtonUpEvent);
}

bool AppBase::onCreate() {
if (mAppState != State::Uninited) {
osre_debug(Tag, "AppBase::State not in expected state: Uninited.");
Expand Down Expand Up @@ -280,7 +280,7 @@
}

// Create our world
mStage = new Stage("stage");
mStage = new Stage("stage", mStageMode);
Dismissed Show dismissed Hide dismissed
mStage->createWorld("world");

const String &api = mRbService->getSettings()->getString(Properties::Settings::RenderAPI);
Expand Down
2 changes: 2 additions & 0 deletions src/Engine/App/AppBase.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

#include "App/AppCommon.h"
#include "App/TAbstractCtrlBase.h"
#include "App/Stage.h"
#include "Platform/AbstractWindow.h"
#include "Platform/PlatformCommon.h"
#include "Platform/PlatformInterface.h"
Expand Down Expand Up @@ -289,6 +290,7 @@ class OSRE_EXPORT AppBase {
MouseEventListener *mMouseEvListener;
KeyboardEventListener *mKeyboardEvListener;
Common::Ids *mIds;
StageMode mStageMode;
bool mShutdownRequested;
};

Expand Down
13 changes: 11 additions & 2 deletions src/Engine/App/Stage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,19 +29,28 @@ namespace App {

static constexpr c8 Tag[] = "Stage";

Stage::Stage(const String &stageName) :
Stage::Stage(const String &stageName, StageMode mode) :
Object(stageName),
mStageMode(mode),
mWorlds(),
mRenderWorlds() {
// empty
}

Stage::~Stage() {
clear();
}

void Stage::clear() {
for (ui32 i = 0; i < mWorlds.size(); ++i) {
mWorlds[i]->release();
}
mWorlds.clear();
mRenderWorlds.clear();
mRenderWorlds.clear();
}

StageMode Stage::getStageMode() const {
return mStageMode;
}

World *Stage::createWorld(const String &name) {
Expand Down
30 changes: 25 additions & 5 deletions src/Engine/App/Stage.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,13 @@ namespace App {

class World;

enum class StageMode {
Invalid = -1,
Stage2D,
Stage3D,
Count
};

//-------------------------------------------------------------------------------------------------
/// @ingroup Engine
///
Expand All @@ -49,12 +56,19 @@ class OSRE_EXPORT Stage : public Common::Object {
using WorldArray = cppcore::TArray<World*>;

/// @brief The class constructor.
/// @param stageName The stage name.
Stage(const String &stageName);
/// @param[in] stageName The stage name.
Stage(const String &stageName, StageMode mode);

/// @brief The class destructor.
~Stage() override;

/// @brief Will clear the stage.
void clear();

/// @brief Will return the stage mode.
/// @return The stage mode.
StageMode getStageMode() const;

/// @brief Will create a new world instance within the stage.
/// @param[in] name The name of the stage.
/// @return The new created stage.
Expand Down Expand Up @@ -82,6 +96,9 @@ class OSRE_EXPORT Stage : public Common::Object {
/// @return The active worlds.
const WorldArray &getActiveWorlds() const;

/// @brief Will return the active world of the stage.
/// @param[in] index The world index.
/// @return The active world or nullptr, if no world is active.
World *getActiveWorld(size_t index) const;

/// @brief Will add a new created world.
Expand All @@ -91,9 +108,7 @@ class OSRE_EXPORT Stage : public Common::Object {

/// @brief Returns true if the stage is empty.
/// @return true, if the stage is empty, false if not.
bool isEmpty() const {
return mRenderWorlds.isEmpty();
}
bool isEmpty() const;

/// @brief Will update the world.
/// @param[in] dt The current delta time-tick.
Expand All @@ -104,9 +119,14 @@ class OSRE_EXPORT Stage : public Common::Object {
void render(RenderBackend::RenderBackendService *rbService);

private:
StageMode mStageMode;
WorldArray mWorlds;
WorldArray mRenderWorlds;
};

inline bool Stage::isEmpty() const {
return mRenderWorlds.isEmpty();
}

} // namespace App
} // namespace OSRE
1 change: 1 addition & 0 deletions test/UnitTests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ SET ( unittest_app_src
src/App/AssetBundleTest.cpp
src/App/AssetRegistryTest.cpp
src/App/AssetWrapperTest.cpp
src/App/StageTest.cpp
)

SET ( unittest_common_src
Expand Down
2 changes: 1 addition & 1 deletion test/UnitTests/src/App/ProjectTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ TEST_F( ProjectTest, accessAssetTests ) {
}

TEST_F( ProjectTest, accessStageTest ) {
Stage stage("test");
Stage stage("test", StageMode::Stage3D);
Project myProject;
EXPECT_EQ(nullptr, myProject.getStage());

Expand Down
64 changes: 64 additions & 0 deletions test/UnitTests/src/App/StageTest.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
/*-----------------------------------------------------------------------------------------------
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 <gtest/gtest.h>
#include "App/Stage.h"

namespace OSRE {
namespace UnitTest {

using namespace OSRE::App;

class StageTest : public ::testing::Test {
// empty
};

TEST_F(StageTest, createTest) {
bool ok = true;
try {
Stage theStage("test", StageMode::Stage2D);
} catch(...) {
ok = false;
}
EXPECT_TRUE(ok);
}

TEST_F(StageTest, clearTest) {
Stage theStage("test", StageMode::Stage2D);
static_cast<void>(theStage.createWorld("stageTest"));
EXPECT_EQ(1u, theStage.getNumberOfWorlds());

theStage.clear();
EXPECT_EQ(0u, theStage.getNumberOfWorlds());
EXPECT_TRUE(theStage.isEmpty());
}

TEST_F(StageTest, accessStageModeTest) {
Stage theStage1("test", StageMode::Stage2D);
EXPECT_EQ(StageMode::Stage2D, theStage1.getStageMode());

Stage theStage2("test", StageMode::Stage3D);
EXPECT_EQ(StageMode::Stage3D, theStage2.getStageMode());
}

} // namespace UnitTest
} // namespace OSRE
Loading