From acf03ea0c7470249c0f6543b09a320394befeb30 Mon Sep 17 00:00:00 2001 From: Nick Fisher Date: Thu, 5 Jun 2025 16:40:53 +0800 Subject: [PATCH] pass TFogOptions by value, not pointer, and rearrange struct fields to minimize alignment issues --- thermion_dart/native/include/c_api/TView.h | 10 ++++--- thermion_dart/native/src/c_api/TView.cpp | 33 +++++++++++----------- 2 files changed, 22 insertions(+), 21 deletions(-) diff --git a/thermion_dart/native/include/c_api/TView.h b/thermion_dart/native/include/c_api/TView.h index 0913b716..5eb10091 100644 --- a/thermion_dart/native/include/c_api/TView.h +++ b/thermion_dart/native/include/c_api/TView.h @@ -26,13 +26,15 @@ struct TFogOptions { float maximumOpacity = 1.0f; float height = 0.0f; float heightFalloff = 1.0f; - double3 linearColor = { 1.0f, 1.0f, 1.0f }; float density = 0.1f; float inScatteringStart = 0.0f; float inScatteringSize = -1.0f; - bool fogColorFromIbl = false; TTexture* skyColor = nullptr; - bool enabled = false; + float linearColorR = 1.0; + float linearColorG = 1.0; + float linearColorB = 1.0; + bool fogColorFromIbl = 0; + bool enabled = 0; }; enum TToneMapping @@ -86,7 +88,7 @@ EMSCRIPTEN_KEEPALIVE void View_setDitheringEnabled(TView *tView, bool enabled); EMSCRIPTEN_KEEPALIVE bool View_isDitheringEnabled(TView *tView); EMSCRIPTEN_KEEPALIVE void View_setScene(TView *tView, TScene *tScene); EMSCRIPTEN_KEEPALIVE void View_setFrontFaceWindingInverted(TView *tView, bool inverted); -EMSCRIPTEN_KEEPALIVE void View_setFogOptions(TView *tView, TFogOptions *tFogOptions); +EMSCRIPTEN_KEEPALIVE void View_setFogOptions(TView *tView, TFogOptions tFogOptions); typedef void (*PickCallback)(uint32_t requestId, EntityId entityId, float depth, float fragX, float fragY, float fragZ); EMSCRIPTEN_KEEPALIVE void View_pick(TView* tView, uint32_t requestId, uint32_t x, uint32_t y, PickCallback callback); diff --git a/thermion_dart/native/src/c_api/TView.cpp b/thermion_dart/native/src/c_api/TView.cpp index a884601d..13021f83 100644 --- a/thermion_dart/native/src/c_api/TView.cpp +++ b/thermion_dart/native/src/c_api/TView.cpp @@ -256,27 +256,26 @@ namespace thermion auto *view = reinterpret_cast(tView); view->setFrontFaceWindingInverted(inverted); } - - EMSCRIPTEN_KEEPALIVE void View_setFogOptions(TView *tView, TFogOptions *tFogOptions) + EMSCRIPTEN_KEEPALIVE void View_setFogOptions(TView *tView, TFogOptions tFogOptions) { auto view = reinterpret_cast(tView); + FogOptions fogOptions { - .distance = tFogOptions->distance, - .cutOffDistance = tFogOptions->cutOffDistance, - .maximumOpacity = tFogOptions->maximumOpacity, - .height = tFogOptions->height, - .heightFalloff = tFogOptions->heightFalloff, - .color = LinearColor(tFogOptions->linearColor.x, tFogOptions->linearColor.y, tFogOptions->linearColor.z), - .density = tFogOptions->density, - .inScatteringStart = tFogOptions->inScatteringStart, - .inScatteringSize = tFogOptions->inScatteringSize, - .fogColorFromIbl = tFogOptions->fogColorFromIbl, - .skyColor = reinterpret_cast(tFogOptions->skyColor), - .enabled = tFogOptions->enabled + .distance = tFogOptions.distance, + .cutOffDistance = tFogOptions.cutOffDistance, + .maximumOpacity = tFogOptions.maximumOpacity, + .height = tFogOptions.height, + .heightFalloff = tFogOptions.heightFalloff, + .color = LinearColor(tFogOptions.linearColorR, tFogOptions.linearColorG, tFogOptions.linearColorB), + .density = tFogOptions.density, + .inScatteringStart = tFogOptions.inScatteringStart, + .inScatteringSize = tFogOptions.inScatteringSize, + .fogColorFromIbl = tFogOptions.fogColorFromIbl == 1, + .skyColor = reinterpret_cast(tFogOptions.skyColor), + .enabled = tFogOptions.enabled == 1 }; - - - TRACE("Setting fog enabled to %d (tFogOptions->cutOffDistance %f)", fogOptions.enabled, tFogOptions->cutOffDistance); + + TRACE("Setting fog enabled to %d (tFogOptions.cutOffDistance %f)", fogOptions.enabled, tFogOptions.cutOffDistance); view->setFogOptions(fogOptions); }