Skip to content

Commit

Permalink
using new reference heuristics
Browse files Browse the repository at this point in the history
  • Loading branch information
hannojg committed Feb 23, 2024
1 parent 4be6e4c commit 6e3b6eb
Show file tree
Hide file tree
Showing 9 changed files with 39 additions and 36 deletions.
5 changes: 0 additions & 5 deletions package/cpp/core/CameraWrapper.cpp
Original file line number Diff line number Diff line change
@@ -1,10 +1,5 @@
#include "CameraWrapper.h"

margelo::CameraWrapper::~CameraWrapper() {
// TODO: engine.destroyCameraComponent(myCameraEntity);
_camera = nullptr;
}

void margelo::CameraWrapper::loadHybridMethods() {
// TODO: implement
}
7 changes: 3 additions & 4 deletions package/cpp/core/CameraWrapper.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,15 @@ using namespace filament;

class CameraWrapper : public HybridObject {
public:
explicit CameraWrapper(Camera* camera) : _camera(camera) {}
~CameraWrapper();
explicit CameraWrapper(const std::shared_ptr<Camera>& camera) : _camera(std::move(camera)) {}

void loadHybridMethods() override;

Camera* getCamera() {
const std::shared_ptr<Camera>& getCamera() {
return _camera;
}

private:
Camera* _camera;
std::shared_ptr<Camera> _camera;
};
} // namespace margelo
24 changes: 17 additions & 7 deletions package/cpp/core/EngineWrapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ namespace margelo {

EngineWrapper::EngineWrapper() {
_engine = References<Engine>::adoptRef(Engine::create(), [](Engine* engine) { engine->destroy(&engine); });
_materialProvider = filament::gltfio::createUbershaderProvider(_engine, UBERARCHIVE_DEFAULT_DATA, UBERARCHIVE_DEFAULT_SIZE);
_materialProvider = filament::gltfio::createUbershaderProvider(_engine.get(), UBERARCHIVE_DEFAULT_DATA, UBERARCHIVE_DEFAULT_SIZE);
_assetLoader =
filament::gltfio::AssetLoader::create(filament::gltfio::AssetConfiguration{.engine = _engine, .materials = _materialProvider});
filament::gltfio::AssetLoader::create(filament::gltfio::AssetConfiguration{.engine = _engine.get(), .materials = _materialProvider});
}

EngineWrapper::~EngineWrapper() {
Expand Down Expand Up @@ -64,22 +64,32 @@ void EngineWrapper::destroySurface() {
}

std::shared_ptr<RendererWrapper> EngineWrapper::createRenderer() {
return std::make_shared<RendererWrapper>(_engine->createRenderer());
std::shared_ptr<Renderer> renderer = References<Renderer>::adoptEngineRef(
_engine, _engine->createRenderer(), [](const std::shared_ptr<Engine>& engine, Renderer* renderer) { engine->destroy(renderer); });
return std::make_shared<RendererWrapper>(renderer);
}

std::shared_ptr<SceneWrapper> EngineWrapper::createScene() {
return std::make_shared<SceneWrapper>(_engine->createScene());
std::shared_ptr<Scene> scene = References<Scene>::adoptEngineRef(
_engine, _engine->createScene(), [](const std::shared_ptr<Engine>& engine, Scene* scene) { engine->destroy(scene); });

return std::make_shared<SceneWrapper>(scene);
}

std::shared_ptr<CameraWrapper> EngineWrapper::createCamera() {
Camera* camera = _engine->createCamera(_engine->getEntityManager().create());
// TODO: make this configurable / expose setExposure to JS
std::shared_ptr<Camera> camera = References<Camera>::adoptEngineRef(
_engine, _engine->createCamera(_engine->getEntityManager().create()),
[](const std::shared_ptr<Engine>& engine, Camera* camera) { engine->destroyCameraComponent(camera->getEntity()); });

camera->setExposure(16.0f, 1.0f / 125.0f, 100.0f);
return std::make_shared<CameraWrapper>(camera);
}

std::shared_ptr<ViewWrapper> EngineWrapper::createView() {
return std::make_shared<ViewWrapper>(_engine->createView());
std::shared_ptr view = References<View>::adoptEngineRef(_engine, _engine->createView(),
[](const std::shared_ptr<Engine>& engine, View* view) { engine->destroy(view); });

return std::make_shared<ViewWrapper>(view);
}

std::shared_ptr<EntityWrapper> EngineWrapper::createDefaultLight() {
Expand Down
11 changes: 6 additions & 5 deletions package/cpp/core/RendererWrapper.cpp
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
#include "RendererWrapper.h"

margelo::RendererWrapper::RendererWrapper(filament::Renderer* renderer) : _renderer(renderer) {
namespace margelo {
using namespace filament;

RendererWrapper::RendererWrapper(const std::shared_ptr<Renderer>& renderer) : _renderer(renderer) {
// Support translucent views
// TODO: make this configurable in the future
_renderer->setClearOptions({.clear = true});
}
margelo::RendererWrapper::~RendererWrapper() {
_renderer = nullptr;
}

void margelo::RendererWrapper::loadHybridMethods() {}
void RendererWrapper::loadHybridMethods() {}
} // namespace margelo
5 changes: 2 additions & 3 deletions package/cpp/core/RendererWrapper.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,12 @@ using namespace filament;

class RendererWrapper : public HybridObject {
public:
explicit RendererWrapper(Renderer* renderer);
~RendererWrapper();
explicit RendererWrapper(const std::shared_ptr<Renderer>& renderer);

void loadHybridMethods() override;

private:
Renderer* _renderer;
std::shared_ptr<Renderer> _renderer;
};

} // namespace margelo
5 changes: 0 additions & 5 deletions package/cpp/core/SceneWrapper.cpp
Original file line number Diff line number Diff line change
@@ -1,10 +1,5 @@
#include "SceneWrapper.h"

margelo::SceneWrapper::~SceneWrapper() {
// TODO: Engine#destroyScene(Scene)
_scene = nullptr;
}

void margelo::SceneWrapper::loadHybridMethods() {
registerHybridMethod("addEntity", &SceneWrapper::addEntity, this);
}
Expand Down
10 changes: 7 additions & 3 deletions package/cpp/core/SceneWrapper.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,16 @@ using namespace filament;

class SceneWrapper : public HybridObject {
public:
explicit SceneWrapper(Scene* scene) : _scene(scene) {}
~SceneWrapper();
explicit SceneWrapper(const std::shared_ptr<Scene>& scene) : _scene(std::move(scene)) {}

void loadHybridMethods() override;

Scene* _scene;
std::shared_ptr<Scene> getScene() {
return _scene;
}

private:
std::shared_ptr<Scene> _scene;

private:
void addEntity(std::shared_ptr<EntityWrapper> entity);
Expand Down
4 changes: 2 additions & 2 deletions package/cpp/core/ViewWrapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ void ViewWrapper::loadHybridMethods() {

void ViewWrapper::setScene(std::shared_ptr<SceneWrapper> scene) {
_scene = scene;
_view->setScene(scene->_scene);
_view->setScene(scene->getScene().get());
}

std::shared_ptr<SceneWrapper> ViewWrapper::getScene() {
Expand All @@ -23,7 +23,7 @@ std::shared_ptr<SceneWrapper> ViewWrapper::getScene() {

void ViewWrapper::setCamera(std::shared_ptr<CameraWrapper> camera) {
_camera = camera;
_view->setCamera(camera->getCamera());
_view->setCamera(camera->getCamera().get());
}

std::shared_ptr<CameraWrapper> ViewWrapper::getCamera() {
Expand Down
4 changes: 2 additions & 2 deletions package/cpp/core/ViewWrapper.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ using namespace filament;

class ViewWrapper : public HybridObject {
public:
explicit ViewWrapper(View* view) : _view(view) {}
explicit ViewWrapper(std::shared_ptr<View> view) : _view(view) {}
~ViewWrapper();

void loadHybridMethods() override;
Expand All @@ -23,7 +23,7 @@ class ViewWrapper : public HybridObject {
std::shared_ptr<CameraWrapper> getCamera();

private:
View* _view;
std::shared_ptr<View> _view;
std::shared_ptr<SceneWrapper> _scene;
std::shared_ptr<CameraWrapper> _camera;
};
Expand Down

0 comments on commit 6e3b6eb

Please sign in to comment.