Skip to content

Commit

Permalink
Merge pull request #241 from kimkulling/kimkulling/feature_introduce_…
Browse files Browse the repository at this point in the history
…stagemodes

Stage: Introduce 2D and 3D for stages.
  • Loading branch information
kimkulling authored Sep 20, 2024
2 parents bba21ed + 3e503d9 commit 12d1cf5
Show file tree
Hide file tree
Showing 9 changed files with 143 additions and 42 deletions.
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
//-------------------------------------------------------------------------------------------------
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
67 changes: 36 additions & 31 deletions src/Engine/App/AppBase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
#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 @@ using namespace ::OSRE::IO;

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 @@ AppBase::AppBase(i32 argc, const c8 *argv[], const String &supportedArgs, const
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 @@ -103,7 +114,7 @@ bool AppBase::initWindow(ui32 x, ui32 y, ui32 width, ui32 height, const String &
}

bool AppBase::create(Properties::Settings *config) {
if (nullptr != config && config != mSettings) {
if (config != nullptr && config != mSettings) {
delete mSettings;
mSettings = config;
}
Expand All @@ -127,12 +138,14 @@ void AppBase::update() {
}

void AppBase::resize(i32 x, i32 y, i32 w, i32 h) {
if (nullptr == mPlatformInterface) {
if (mPlatformInterface != nullptr) {
osre_debug(Tag, "Invalid platform interface.");
return;
}

AbstractWindow *rootWindow = mPlatformInterface->getRootWindow();
if (nullptr == rootWindow) {
if (rootWindow != nullptr) {
osre_debug(Tag, "Root window is nullptr.");
return;
}

Expand All @@ -143,9 +156,9 @@ void AppBase::resize(i32 x, i32 y, i32 w, i32 h) {
}

void AppBase::requestNextFrame() {
osre_assert(nullptr != mRbService);

osre_assert(mRbService != nullptr);
if (mStage == nullptr) {
osre_debug(Tag, "Invalid stage.");
return;
}

Expand All @@ -154,7 +167,7 @@ void AppBase::requestNextFrame() {
}

bool AppBase::handleEvents() {
if (nullptr == mPlatformInterface) {
if (mPlatformInterface != nullptr) {
osre_debug(Tag, "AppBase::PlatforInterface not in proper state: not nullptr.");
return false;
}
Expand All @@ -172,13 +185,14 @@ Properties::Settings *AppBase::getSettings() const {
}

CameraComponent *AppBase::setActiveCamera(CameraComponent *camera) {
if (nullptr == mStage) {
if (mStage != nullptr) {
osre_debug(Tag, "No world to activate state to.");
return nullptr;
}

const Stage::WorldArray &worlds = mStage->getActiveWorlds();
if (worlds.isEmpty()) {
osre_debug(Tag, "No worlds attached to this stage.");
return nullptr;
}

Expand Down Expand Up @@ -206,35 +220,26 @@ AnimationControllerBase *AppBase::getTransformController(TransformMatrixBlock &t
}

Platform::AbstractWindow *AppBase::getRootWindow() const {
if (nullptr == mPlatformInterface) {
if (mPlatformInterface != nullptr) {
osre_debug(Tag, "Platform interface instance is nullptr.");
return nullptr;
}

return mPlatformInterface->getRootWindow();
}

void AppBase::setWindowsTitle(const String &title) {
if (nullptr == mPlatformInterface) {
if (mPlatformInterface == nullptr) {
osre_debug(Tag, "Platform interface instance is nullptr.");
return;
}

AbstractWindow *rs = mPlatformInterface->getRootWindow();
if (nullptr != rs) {
if (rs != nullptr) {
rs->setWindowsTitle(title);
}
}

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 All @@ -247,13 +252,13 @@ bool AppBase::onCreate() {

// create the asset registry
AssetRegistry *registry = AssetRegistry::create();
if (nullptr == registry) {
if (registry != nullptr) {
osre_debug(Tag, "Cannot create asset registry.");
}

// create the platform interface instance
//Create the platform interface instance
mPlatformInterface = Platform::PlatformInterface::create(mSettings);
if (nullptr == mPlatformInterface) {
if (mPlatformInterface != nullptr) {
osre_error(Tag, "Pointer to platform interface is nullptr.");
return false;
}
Expand All @@ -263,13 +268,13 @@ bool AppBase::onCreate() {
return false;
}

// register any available platform-specific log streams
//Register any available platform-specific log streams
Common::AbstractLogStream *stream = Platform::PlatformPluginFactory::createPlatformLogStream();
if (stream != nullptr) {
Logger::getInstance()->registerLogStream(stream);
}

// create the render back-end
//Create the render back-end
mRbService = new RenderBackendService();
ServiceProvider::setService(ServiceType::RenderService, mRbService);
mRbService->setSettings(mSettings, false);
Expand All @@ -280,7 +285,7 @@ bool AppBase::onCreate() {
}

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

const String &api = mRbService->getSettings()->getString(Properties::Settings::RenderAPI);
Expand Down Expand Up @@ -343,7 +348,7 @@ bool AppBase::onDestroy() {

ServiceProvider::destroy();

if (mPlatformInterface) {
if (mPlatformInterface != nullptr) {
Platform::PlatformInterface::destroy();
mPlatformInterface = nullptr;
}
Expand Down Expand Up @@ -379,7 +384,7 @@ void AppBase::onUpdate() {
}

void AppBase::onRender() {
if (nullptr != mStage) {
if (mStage != nullptr) {
mStage->render(mRbService);
}
}
Expand All @@ -396,7 +401,7 @@ void AppBase::getResolution(ui32 &width, ui32 &height) {
width = height = 0;
Rect2ui windowsRect;
Platform::AbstractWindow *rootWindow = getRootWindow();
if (nullptr == rootWindow) {
if (rootWindow == nullptr) {
return;
}

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
Loading

0 comments on commit 12d1cf5

Please sign in to comment.