[nostalgia/core] Rename customData functions in Context and move them out of Context

This commit is contained in:
2022-02-03 21:06:44 -06:00
parent c7cd54ae52
commit 7459d687b0
5 changed files with 24 additions and 19 deletions
+17 -11
View File
@@ -25,6 +25,10 @@ class Drawer {
// User Input Output
class Context {
friend constexpr void setApplicationData(Context *ctx, void *applicationData) noexcept;
template<typename T>
[[nodiscard]]
friend constexpr T *applicationData(Context *ctx) noexcept;
friend bool bgStatus(Context *ctx, unsigned bg) noexcept;
friend common::Size getScreenSize(Context *ctx) noexcept;
friend int getScreenHeight(Context *ctx) noexcept;
@@ -60,10 +64,12 @@ class Context {
AssetManager assetManager;
#endif
private:
void *m_customData = nullptr;
void *m_windowerData = nullptr;
void *m_rendererData = nullptr;
protected:
void *m_customData = nullptr;
public:
Context() noexcept = default;
@@ -71,16 +77,6 @@ class Context {
Context(const Context &other) noexcept = delete;
Context(const Context &&other) noexcept = delete;
constexpr void setCustomData(void *customData) noexcept {
m_customData = customData;
}
template<typename T>
[[nodiscard]]
constexpr T *customData() noexcept {
return static_cast<T*>(m_customData);
}
protected:
template<typename T>
[[nodiscard]]
@@ -104,5 +100,15 @@ class Context {
};
constexpr void setApplicationData(Context *ctx, void *applicationData) noexcept {
ctx->m_customData = applicationData;
}
template<typename T>
[[nodiscard]]
constexpr T *applicationData(Context *ctx) noexcept {
return static_cast<T*>(ctx->m_customData);
}
}
+1 -1
View File
@@ -45,7 +45,7 @@ ox::Error run(Context *ctx) noexcept {
glfwSwapBuffers(id->window);
}
// destroy GLFW window
oxReturnError(renderer::shutdown(ctx, ctx->rendererData<void>()));
renderer::shutdown(ctx, ctx->rendererData<void>());
glfwDestroyWindow(id->window);
ctx->setWindowerData(nullptr);
delete id;
+1 -1
View File
@@ -12,7 +12,7 @@ namespace nostalgia::core::renderer {
ox::Error init(Context *ctx, void **rendererData) noexcept;
ox::Error shutdown(Context *ctx, void *rendererData) noexcept;
void shutdown(Context *ctx, void *rendererData) noexcept;
ox::Error loadBgTexture(void *rendererData, int section, void *pixels, int w, int h) noexcept;
+1 -2
View File
@@ -195,10 +195,9 @@ ox::Error init(Context *ctx, void **rendererData) noexcept {
return OxError(0);
}
ox::Error shutdown(Context*, void *rendererData) noexcept {
void shutdown(Context*, void *rendererData) noexcept {
const auto id = reinterpret_cast<GlImplData*>(rendererData);
delete id;
return OxError(0);
}
ox::Error loadBgTexture(void *rendererData, int section, void *pixels, int w, int h) noexcept {