rm dupavlue and freevalue

This commit is contained in:
2026-02-25 09:42:19 -06:00
parent 0b3e6e6213
commit 07032a3ea0

41
model.c
View File

@@ -295,7 +295,6 @@ JSValue js_model_mat4_from_array(JSContext *js, JSValue this_val, int argc, JSVa
JSValue v = JS_GetPropertyNumber(js, argv[0], i);
double d = 0.0;
JS_ToFloat64(js, &d, v);
JS_FreeValue(js, v);
m[i] = (float)d;
}
@@ -437,7 +436,6 @@ JSValue js_model_pack_vertices(JSContext *js, JSValue this_val, int argc, JSValu
JSValue vc_v = JS_GetPropertyStr(js, mesh, "vertex_count");
int vertex_count = 0;
JS_ToInt32(js, &vertex_count, vc_v);
JS_FreeValue(js, vc_v);
if (vertex_count <= 0) return JS_ThrowTypeError(js, "invalid vertex count");
@@ -458,12 +456,6 @@ JSValue js_model_pack_vertices(JSContext *js, JSValue this_val, int argc, JSValu
float *weights = JS_IsNull(weights_v) ? NULL : js_get_blob_data(js, &weights_size, weights_v);
if (!positions) {
JS_FreeValue(js, pos_v);
JS_FreeValue(js, norm_v);
JS_FreeValue(js, uv_v);
JS_FreeValue(js, color_v);
JS_FreeValue(js, joints_v);
JS_FreeValue(js, weights_v);
return JS_ThrowTypeError(js, "positions required");
}
@@ -543,12 +535,6 @@ JSValue js_model_pack_vertices(JSContext *js, JSValue this_val, int argc, JSValu
}
}
JS_FreeValue(js, pos_v);
JS_FreeValue(js, norm_v);
JS_FreeValue(js, uv_v);
JS_FreeValue(js, color_v);
JS_FreeValue(js, joints_v);
JS_FreeValue(js, weights_v);
JS_FRAME(js);
JS_ROOT(result, JS_NewObject(js));
@@ -610,9 +596,6 @@ JSValue js_model_build_uniforms(JSContext *js, JSValue this_val, int argc, JSVal
// Projection at offset 48-63
memcpy(&uniforms[48], proj.m, 64);
JS_FreeValue(js, model_v);
JS_FreeValue(js, view_v);
JS_FreeValue(js, proj_v);
// Ambient color at offset 64-67 (rgb, unused)
JSValue ambient_v = JS_GetPropertyStr(js, params, "ambient");
@@ -622,13 +605,11 @@ JSValue js_model_build_uniforms(JSContext *js, JSValue this_val, int argc, JSVal
double val = 0;
JS_ToFloat64(js, &val, c);
uniforms[64 + i] = val;
JS_FreeValue(js, c);
}
} else {
uniforms[64] = 0.2f; uniforms[65] = 0.2f; uniforms[66] = 0.2f;
}
uniforms[67] = 0.0f; // unused
JS_FreeValue(js, ambient_v);
// Light direction at offset 68-71 (xyz, unused)
JSValue light_dir_v = JS_GetPropertyStr(js, params, "light_dir");
@@ -638,13 +619,11 @@ JSValue js_model_build_uniforms(JSContext *js, JSValue this_val, int argc, JSVal
double val = 0;
JS_ToFloat64(js, &val, c);
uniforms[68 + i] = val;
JS_FreeValue(js, c);
}
} else {
uniforms[68] = 0.5f; uniforms[69] = 1.0f; uniforms[70] = 0.3f;
}
uniforms[71] = 0.0f; // unused
JS_FreeValue(js, light_dir_v);
// Light color at offset 72-75 (rgb, intensity)
JSValue light_color_v = JS_GetPropertyStr(js, params, "light_color");
@@ -654,19 +633,16 @@ JSValue js_model_build_uniforms(JSContext *js, JSValue this_val, int argc, JSVal
double val = 0;
JS_ToFloat64(js, &val, c);
uniforms[72 + i] = val;
JS_FreeValue(js, c);
}
} else {
uniforms[72] = 1.0f; uniforms[73] = 1.0f; uniforms[74] = 1.0f;
}
JS_FreeValue(js, light_color_v);
// Light intensity at offset 75
JSValue light_int_v = JS_GetPropertyStr(js, params, "light_intensity");
double light_int = 1.0;
JS_ToFloat64(js, &light_int, light_int_v);
uniforms[75] = light_int;
JS_FreeValue(js, light_int_v);
// Fog params at offset 76-79 (near, far, unused, enabled)
JSValue fog_near_v = JS_GetPropertyStr(js, params, "fog_near");
@@ -688,16 +664,12 @@ JSValue js_model_build_uniforms(JSContext *js, JSValue this_val, int argc, JSVal
double val = 0;
JS_ToFloat64(js, &val, c);
uniforms[80 + i] = val;
JS_FreeValue(js, c);
}
} else {
uniforms[80] = 0; uniforms[81] = 0; uniforms[82] = 0;
}
uniforms[83] = 0.0f; // unused
JS_FreeValue(js, fog_near_v);
JS_FreeValue(js, fog_far_v);
JS_FreeValue(js, fog_color_v);
// Tint color at offset 84-87 (rgba)
JSValue tint_v = JS_GetPropertyStr(js, params, "tint");
@@ -707,19 +679,16 @@ JSValue js_model_build_uniforms(JSContext *js, JSValue this_val, int argc, JSVal
double val = 1.0;
JS_ToFloat64(js, &val, c);
uniforms[84 + i] = val;
JS_FreeValue(js, c);
}
} else {
uniforms[84] = 1; uniforms[85] = 1; uniforms[86] = 1; uniforms[87] = 1;
}
JS_FreeValue(js, tint_v);
// Style params at offset 88-91 (style_id, vertex_snap, affine, dither)
JSValue style_v = JS_GetPropertyStr(js, params, "style_id");
double style_id = 0;
JS_ToFloat64(js, &style_id, style_v);
uniforms[88] = style_id;
JS_FreeValue(js, style_v);
uniforms[89] = (style_id == 0) ? 1.0f : 0.0f; // vertex_snap for PS1
uniforms[90] = (style_id == -1) ? 1.0f : 0.0f; // affine texturing for PS1
@@ -735,8 +704,6 @@ JSValue js_model_build_uniforms(JSContext *js, JSValue this_val, int argc, JSVal
uniforms[93] = res_h;
uniforms[94] = 0.0f; // unused
uniforms[95] = 0.0f; // unused
JS_FreeValue(js, res_w_v);
JS_FreeValue(js, res_h_v);
// Material params at offset 96-99 (alpha_mode, alpha_cutoff, unlit, unused)
// alpha_mode: 0=OPAQUE, 1=MASK, 2=BLEND
@@ -763,9 +730,6 @@ JSValue js_model_build_uniforms(JSContext *js, JSValue this_val, int argc, JSVal
uniforms[98] = (float)unlit_d;
uniforms[99] = 0.0f; // unused
JS_FreeValue(js, alpha_mode_v);
JS_FreeValue(js, alpha_cutoff_v);
JS_FreeValue(js, unlit_v);
return js_new_blob_stoned_copy(js, uniforms, sizeof(uniforms));
}
@@ -787,7 +751,6 @@ JSValue js_model_f32_blob(JSContext *js, JSValue this_val, int argc, JSValueCons
JSValue v = JS_GetPropertyNumber(js, arr, (uint32_t)i);
double d = 0.0;
JS_ToFloat64(js, &d, v);
JS_FreeValue(js, v);
data[i] = (float)d;
}
@@ -1012,7 +975,6 @@ JSValue js_model_build_joint_palette(JSContext *js, JSValue this_val, int argc,
JSValue world_v = JS_GetPropertyNumber(js, worlds_arr, j);
size_t world_size;
float *world_m = js_get_blob_data(js, &world_size, world_v);
JS_FreeValue(js, world_v);
mat4 world, inv;
if (world_m && world_size >= 64) {
@@ -1046,7 +1008,6 @@ JSValue js_model_get_node_world(JSContext *js, JSValue this_val, int argc, JSVal
JSValue mat_v = JS_GetPropertyNumber(js, argv[0], node_idx);
if (JS_IsNull(mat_v)) {
JS_FreeValue(js, mat_v);
mat4 id = mat4_identity();
return js_new_blob_stoned_copy(js, id.m, 64);
}
@@ -1054,7 +1015,6 @@ JSValue js_model_get_node_world(JSContext *js, JSValue this_val, int argc, JSVal
// Return a copy
size_t size;
float *data = js_get_blob_data(js, &size, mat_v);
JS_FreeValue(js, mat_v);
if (!data || size < 64) {
mat4 id = mat4_identity();
@@ -1146,7 +1106,6 @@ JSValue js_model_u16_blob(JSContext *js, JSValue this_val, int argc, JSValueCons
JSValue v = JS_GetPropertyNumber(js, arr, (uint32_t)i);
uint32_t u = 0;
JS_ToUint32(js, &u, v);
JS_FreeValue(js, v);
if (u > 0xFFFF) u = 0xFFFF;
data[i] = (uint16_t)u;
}