From 001939ca8e2c582650d3cd77d0cd0eabffc50ed2 Mon Sep 17 00:00:00 2001 From: skal Date: Tue, 17 Feb 2026 08:57:55 +0100 Subject: style: replace C++ casts with C-style casts Converts all static_cast<>, reinterpret_cast<> to C-style casts per CODING_STYLE.md guidelines. - Modified 12 files across gpu, 3d, util, tests, and tools - All builds passing, 34/34 tests passing - No functional changes, pure style cleanup Co-Authored-By: Claude Sonnet 4.5 --- src/3d/renderer_draw.cc | 2 +- src/3d/renderer_pipelines.cc | 6 +++--- src/3d/scene_loader.cc | 50 ++++++++++++++++++++++---------------------- 3 files changed, 29 insertions(+), 29 deletions(-) (limited to 'src/3d') diff --git a/src/3d/renderer_draw.cc b/src/3d/renderer_draw.cc index 2b19787..f2d1323 100644 --- a/src/3d/renderer_draw.cc +++ b/src/3d/renderer_draw.cc @@ -61,7 +61,7 @@ void Renderer3D::update_uniforms(const Scene& scene, const Camera& camera, if (obj.type == ObjectType::PLANE && obj.shared_user_data) { // Safely cast shared_user_data to PlaneData* and get distance plane_distance = - static_cast(obj.shared_user_data.get())->distance; + ((PlaneData*)(obj.shared_user_data.get()))->distance; } data.params = diff --git a/src/3d/renderer_pipelines.cc b/src/3d/renderer_pipelines.cc index fed3983..57e71ae 100644 --- a/src/3d/renderer_pipelines.cc +++ b/src/3d/renderer_pipelines.cc @@ -17,7 +17,7 @@ void Renderer3D::create_pipeline() { WGPURenderPipeline Renderer3D::create_pipeline_impl(bool use_bvh) { // Main SDF shader size_t size; - const char* shader_code = reinterpret_cast( + const char* shader_code = (const char*)( GetAsset(AssetId::ASSET_SHADER_RENDERER_3D, &size)); // Compose the final shader by substituting the scene query implementation @@ -134,7 +134,7 @@ WGPURenderPipeline Renderer3D::create_pipeline_impl(bool use_bvh) { void Renderer3D::create_mesh_pipeline() { size_t size; - const char* shader_code = reinterpret_cast( + const char* shader_code = (const char*)( GetAsset(AssetId::ASSET_SHADER_MESH, &size)); ShaderComposer::CompositionMap composition_map; @@ -261,7 +261,7 @@ void Renderer3D::create_mesh_pipeline() { void Renderer3D::create_skybox_pipeline() { size_t size; - const char* shader_code = reinterpret_cast( + const char* shader_code = (const char*)( GetAsset(AssetId::ASSET_SHADER_SKYBOX, &size)); std::string composed_shader = diff --git a/src/3d/scene_loader.cc b/src/3d/scene_loader.cc index 286edca..2c29bc3 100644 --- a/src/3d/scene_loader.cc +++ b/src/3d/scene_loader.cc @@ -23,11 +23,11 @@ bool SceneLoader::LoadScene(Scene& scene, const uint8_t* data, size_t size) { size_t offset = 4; - uint32_t num_objects = *reinterpret_cast(data + offset); + uint32_t num_objects = *(const uint32_t*)(data + offset); offset += 4; - uint32_t num_cameras = *reinterpret_cast(data + offset); + uint32_t num_cameras = *(const uint32_t*)(data + offset); offset += 4; - uint32_t num_lights = *reinterpret_cast(data + offset); + uint32_t num_lights = *(const uint32_t*)(data + offset); offset += 4; // printf("SceneLoader: Loading %d objects, %d cameras, %d lights\n", @@ -43,48 +43,48 @@ bool SceneLoader::LoadScene(Scene& scene, const uint8_t* data, size_t size) { if (offset + 4 > size) return false; - uint32_t type_val = *reinterpret_cast(data + offset); + uint32_t type_val = *(const uint32_t*)(data + offset); offset += 4; ObjectType type = (ObjectType)type_val; if (offset + 12 + 16 + 12 + 16 > size) return false; // Transforms + Color - float px = *reinterpret_cast(data + offset); + float px = *(const float*)(data + offset); offset += 4; - float py = *reinterpret_cast(data + offset); + float py = *(const float*)(data + offset); offset += 4; - float pz = *reinterpret_cast(data + offset); + float pz = *(const float*)(data + offset); offset += 4; vec3 pos(px, py, pz); - float rx = *reinterpret_cast(data + offset); + float rx = *(const float*)(data + offset); offset += 4; - float ry = *reinterpret_cast(data + offset); + float ry = *(const float*)(data + offset); offset += 4; - float rz = *reinterpret_cast(data + offset); + float rz = *(const float*)(data + offset); offset += 4; - float rw = *reinterpret_cast(data + offset); + float rw = *(const float*)(data + offset); offset += 4; quat rot(rx, ry, rz, rw); - float sx = *reinterpret_cast(data + offset); + float sx = *(const float*)(data + offset); offset += 4; - float sy = *reinterpret_cast(data + offset); + float sy = *(const float*)(data + offset); offset += 4; - float sz = *reinterpret_cast(data + offset); + float sz = *(const float*)(data + offset); offset += 4; vec3 scale(sx, sy, sz); // Color components (cr, cg, cb, ca) - float cr = *reinterpret_cast(data + offset); + float cr = *(const float*)(data + offset); offset += 4; - float cg = *reinterpret_cast(data + offset); + float cg = *(const float*)(data + offset); offset += 4; - float cb = *reinterpret_cast(data + offset); + float cb = *(const float*)(data + offset); offset += 4; // Read ca, advance offset AFTER reading ca, then construct color - float ca = *reinterpret_cast(data + offset); + float ca = *(const float*)(data + offset); offset += 4; // Offset is now after ca vec4 color(cr, cg, cb, ca); @@ -94,7 +94,7 @@ bool SceneLoader::LoadScene(Scene& scene, const uint8_t* data, size_t size) { // Check bounds before reading plane_distance if (offset + 4 > size) return false; - plane_distance = *reinterpret_cast(data + offset); + plane_distance = *(const float*)(data + offset); offset += 4; // Advance offset after reading plane_distance } @@ -103,7 +103,7 @@ bool SceneLoader::LoadScene(Scene& scene, const uint8_t* data, size_t size) { // either after ca (if not PLANE) or after plane_distance (if PLANE). if (offset + 4 > size) return false; - uint32_t name_len = *reinterpret_cast(data + offset); + uint32_t name_len = *(const uint32_t*)(data + offset); offset += 4; AssetId mesh_id = (AssetId)0; // Default or INVALID (if 0 is invalid) @@ -129,11 +129,11 @@ bool SceneLoader::LoadScene(Scene& scene, const uint8_t* data, size_t size) { // Physics properties if (offset + 4 + 4 + 4 > size) return false; - float mass = *reinterpret_cast(data + offset); + float mass = *(const float*)(data + offset); offset += 4; - float restitution = *reinterpret_cast(data + offset); + float restitution = *(const float*)(data + offset); offset += 4; - uint32_t is_static_u32 = *reinterpret_cast(data + offset); + uint32_t is_static_u32 = *(const uint32_t*)(data + offset); offset += 4; bool is_static = (is_static_u32 != 0); @@ -155,9 +155,9 @@ bool SceneLoader::LoadScene(Scene& scene, const uint8_t* data, size_t size) { // Use std::make_shared for exception safety and efficiency obj.shared_user_data = std::make_shared(); // Assign the plane distance - // Safely cast void* to PlaneData* using static_cast on the shared_ptr's + // Safely cast void* to PlaneData* using C-style cast on the shared_ptr's // get() - static_cast(obj.shared_user_data.get())->distance = + ((PlaneData*)(obj.shared_user_data.get()))->distance = plane_distance; } -- cgit v1.2.3