Skip to content

Commit

Permalink
Fix resize behavior and expensive calls to emscripten_get_now
Browse files Browse the repository at this point in the history
  • Loading branch information
SanderMertens committed Dec 27, 2024
1 parent d5a415a commit f97900c
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 19 deletions.
10 changes: 4 additions & 6 deletions deps/flecs.c
Original file line number Diff line number Diff line change
Expand Up @@ -21636,12 +21636,10 @@ int ecs_app_run(
{
ecs_app_desc = *desc;

#ifndef ECS_TARGET_EM
if (ECS_NEQZERO(ecs_app_desc.target_fps)) {
ecs_set_target_fps(world, ecs_app_desc.target_fps);
}

/* Don't set threads if using emscripten */
#ifndef ECS_TARGET_EM
if (ecs_app_desc.threads) {
ecs_set_threads(world, ecs_app_desc.threads);
}
Expand Down Expand Up @@ -55847,7 +55845,7 @@ typedef struct ecs_script_rng_t {
} ecs_script_rng_t;

static
ecs_script_rng_t* flecs_script_rng_new() {
ecs_script_rng_t* flecs_script_rng_new(void) {
ecs_script_rng_t *result = ecs_os_calloc_t(ecs_script_rng_t);
result->x = 0;
result->w = 0;
Expand Down Expand Up @@ -55934,7 +55932,7 @@ void flecs_script_rng_get_float(
double max = *(double*)argv[1].ptr;
double *r = result->ptr;

if (!max) {
if (ECS_EQZERO(max)) {
ecs_err("flecs.script.math.Rng.f(): invalid division by zero");
} else {
*r = (double)x / ((double)UINT64_MAX / max);
Expand Down Expand Up @@ -79858,7 +79856,7 @@ int flecs_expr_identifier_visit_type(
ecs_expr_value_node_t *result = flecs_expr_value_from(
script, (ecs_expr_node_t*)node, type);

if (type == ecs_id(ecs_entity_t)) {
if (type == ecs_id(ecs_entity_t) || type == ecs_id(ecs_id_t)) {
result->storage.entity = desc->lookup_action(
script->world, node->value, desc->lookup_ctx);
result->ptr = &result->storage.entity;
Expand Down
2 changes: 1 addition & 1 deletion etc/assets/scene.flecs
Original file line number Diff line number Diff line change
Expand Up @@ -357,7 +357,7 @@ for y in 0..$Height {

for i in 0..$Lights {
for s in 0..4 {
const h = $rng.u($i * ($Height / $Lights))
const h = $rng.u(1 + $i * ($Height / $Lights))
const w = ($h - $Height) * 0.6
const x = $rng.f($w)
const hv = $h + ($rng.f(0.5) - 0.25)
Expand Down
2 changes: 1 addition & 1 deletion etc/flecs_explorer.js

Large diffs are not rendered by default.

Binary file modified etc/flecs_explorer.wasm
Binary file not shown.
6 changes: 3 additions & 3 deletions etc/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -129,10 +129,10 @@
</div>

<!-- Vue3 -->
<script src="https://unpkg.com/vue@3/dist/vue.global.js">
<!-- <script src="https://unpkg.com/vue@3/dist/vue.global.js">
Vue.config.devtools = true;
</script>
<!-- <script src="https://unpkg.com/vue@3/dist/vue.global.prod.js"></script> -->
</script> -->
<script src="https://unpkg.com/vue@3/dist/vue.global.prod.js"></script>

<!-- Vue SFC support without webpack -->
<script src="https://cdn.jsdelivr.net/npm/vue3-sfc-loader/dist/vue3-sfc-loader.js"></script>
Expand Down
20 changes: 12 additions & 8 deletions etc/js/components/widgets/canvas-container.vue
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,21 @@ const canvasContainerStyle = ref();
onMounted(() => {
window.addEventListener('resize', handleResize);
handleResize();
setTimeout(() => {
var resizeEvent = new Event('resize');
window.dispatchEvent(resizeEvent);
}, 5);
});
watch(() => [props.app_state.has3DCanvas, props.app_params.page], () => {
watch(() => [props.app_state.has3DCanvas, props.app_params.page,
props.app_params.sidebar, props.app_params.entity.path,
props.app_params.script], () =>
{
nextTick(() => {
handleResize();
setTimeout(() => {
var resizeEvent = new Event('resize');
window.dispatchEvent(resizeEvent);
}, 5);
});
});
Expand All @@ -40,11 +49,6 @@ const handleResize = () => {
height: ${r.height}px;
top: ${r.top}px;
left: ${r.left}px;`;
setTimeout(() => {
var resizeEvent = new Event('resize');
window.dispatchEvent(resizeEvent);
}, 5);
} else {
canvasContainerStyle.value = "display: none;";
}
Expand Down

0 comments on commit f97900c

Please sign in to comment.