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 ++++++++++++++--------------- src/gpu/effect.cc | 4 +-- src/gpu/sequence.cc | 10 +++--- src/gpu/texture_readback.cc | 36 ++++++++++----------- src/tests/common/effect_test_helpers.cc | 6 ++-- src/tests/common/offscreen_render_target.cc | 4 +-- src/util/asset_manager.cc | 12 +++---- 9 files changed, 65 insertions(+), 65 deletions(-) (limited to 'src') 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; } diff --git a/src/gpu/effect.cc b/src/gpu/effect.cc index 0e53862..752dd84 100644 --- a/src/gpu/effect.cc +++ b/src/gpu/effect.cc @@ -49,8 +49,8 @@ void Effect::blit_input_to_output(WGPUCommandEncoder encoder, GpuTextureCopyInfo dst_copy = { .texture = dst, .mipLevel = 0, .origin = {0, 0, 0}}; - WGPUExtent3D extent = {static_cast(width_), - static_cast(height_), 1}; + WGPUExtent3D extent = {(unsigned int)(width_), + (unsigned int)(height_), 1}; wgpuCommandEncoderCopyTextureToTexture(encoder, &src_copy, &dst_copy, &extent); diff --git a/src/gpu/sequence.cc b/src/gpu/sequence.cc index d2f99bc..901d560 100644 --- a/src/gpu/sequence.cc +++ b/src/gpu/sequence.cc @@ -185,8 +185,8 @@ void NodeRegistry::create_texture(Node& node) { WGPUTextureDescriptor desc = {}; desc.usage = usage; desc.dimension = WGPUTextureDimension_2D; - desc.size = {static_cast(node.width), - static_cast(node.height), 1}; + desc.size = {(unsigned int)(node.width), + (unsigned int)(node.height), 1}; desc.format = format; desc.mipLevelCount = 1; desc.sampleCount = 1; @@ -219,10 +219,10 @@ Sequence::Sequence(const GpuContext& ctx, int width, int height) void Sequence::preprocess(float seq_time, float beat_time, float beat_phase, float audio_intensity) { - params_.resolution = {static_cast(width_), - static_cast(height_)}; + params_.resolution = {(float)(width_), + (float)(height_)}; params_.aspect_ratio = - static_cast(width_) / static_cast(height_); + (float)(width_) / (float)(height_); params_.time = seq_time; params_.beat_time = beat_time; params_.beat_phase = beat_phase; diff --git a/src/gpu/texture_readback.cc b/src/gpu/texture_readback.cc index bd3c79c..211beed 100644 --- a/src/gpu/texture_readback.cc +++ b/src/gpu/texture_readback.cc @@ -52,12 +52,12 @@ std::vector read_texture_pixels(WGPUInstance instance, .layout = { .bytesPerRow = aligned_bytes_per_row, - .rowsPerImage = static_cast(height), + .rowsPerImage = (uint32_t)(height), }, }; - const WGPUExtent3D copy_size = {static_cast(width), - static_cast(height), 1}; + const WGPUExtent3D copy_size = {(uint32_t)(width), + (uint32_t)(height), 1}; wgpuCommandEncoderCopyTextureToBuffer(encoder, &src, &dst, ©_size); @@ -77,7 +77,7 @@ std::vector read_texture_pixels(WGPUInstance instance, // Win32: Old callback API MapState map_state = {}; auto map_cb = [](WGPUBufferMapAsyncStatus status, void* userdata) { - MapState* state = static_cast(userdata); + MapState* state = (MapState*)(userdata); state->status = status; state->done = true; }; @@ -90,7 +90,7 @@ std::vector read_texture_pixels(WGPUInstance instance, void* userdata, void* user2) { (void)message; (void)user2; - MapState* state = static_cast(userdata); + MapState* state = (MapState*)(userdata); state->status = status; state->done = true; }; @@ -117,7 +117,7 @@ std::vector read_texture_pixels(WGPUInstance instance, } // Copy data from mapped buffer (handle row padding) - const uint8_t* mapped_data = static_cast( + const uint8_t* mapped_data = (const uint8_t*)( wgpuBufferGetConstMappedRange(staging, 0, buffer_size)); if (mapped_data) { // If rows are aligned, copy row by row to remove padding @@ -209,11 +209,11 @@ std::vector texture_readback_fp16_to_u8(WGPUDevice device, .layout = { .bytesPerRow = aligned_bytes_per_row, - .rowsPerImage = static_cast(height), + .rowsPerImage = (uint32_t)(height), }, }; - const WGPUExtent3D copy_size = {static_cast(width), - static_cast(height), 1}; + const WGPUExtent3D copy_size = {(uint32_t)(width), + (uint32_t)(height), 1}; wgpuCommandEncoderCopyTextureToBuffer(encoder, &src, &dst, ©_size); WGPUCommandBuffer commands = wgpuCommandEncoderFinish(encoder, nullptr); @@ -226,7 +226,7 @@ std::vector texture_readback_fp16_to_u8(WGPUDevice device, #if defined(DEMO_CROSS_COMPILE_WIN32) MapState map_state = {}; auto map_cb = [](WGPUBufferMapAsyncStatus status, void* userdata) { - MapState* state = static_cast(userdata); + MapState* state = (MapState*)(userdata); state->status = status; state->done = true; }; @@ -238,7 +238,7 @@ std::vector texture_readback_fp16_to_u8(WGPUDevice device, void* userdata, void* user2) { (void)message; (void)user2; - MapState* state = static_cast(userdata); + MapState* state = (MapState*)(userdata); state->status = status; state->done = true; }; @@ -259,14 +259,14 @@ std::vector texture_readback_fp16_to_u8(WGPUDevice device, } // Convert FP16 to U8 ([-1,1] → [0,255]) - const uint16_t* mapped_data = static_cast( + const uint16_t* mapped_data = (const uint16_t*)( wgpuBufferGetConstMappedRange(staging, 0, buffer_size)); std::vector pixels(width * height * 4); if (mapped_data) { for (int y = 0; y < height; ++y) { - const uint16_t* src_row = reinterpret_cast( - reinterpret_cast(mapped_data) + + const uint16_t* src_row = (const uint16_t*)( + (const uint8_t*)(mapped_data) + y * aligned_bytes_per_row); for (int x = 0; x < width; ++x) { float r = fp16_to_float(src_row[x * 4 + 0]); @@ -281,10 +281,10 @@ std::vector texture_readback_fp16_to_u8(WGPUDevice device, a = (a + 1.0f) * 0.5f; int idx = (y * width + x) * 4; - pixels[idx + 0] = static_cast(b * 255.0f); // B - pixels[idx + 1] = static_cast(g * 255.0f); // G - pixels[idx + 2] = static_cast(r * 255.0f); // R - pixels[idx + 3] = static_cast(a * 255.0f); // A + pixels[idx + 0] = (uint8_t)(b * 255.0f); // B + pixels[idx + 1] = (uint8_t)(g * 255.0f); // G + pixels[idx + 2] = (uint8_t)(r * 255.0f); // R + pixels[idx + 3] = (uint8_t)(a * 255.0f); // A } } } diff --git a/src/tests/common/effect_test_helpers.cc b/src/tests/common/effect_test_helpers.cc index 430b90f..2a40f60 100644 --- a/src/tests/common/effect_test_helpers.cc +++ b/src/tests/common/effect_test_helpers.cc @@ -45,9 +45,9 @@ bool all_pixels_match_color(const std::vector& pixels, int width, const uint8_t g = pixels[offset + 1]; const uint8_t r = pixels[offset + 2]; - const int diff_r = static_cast(r) - static_cast(target_r); - const int diff_g = static_cast(g) - static_cast(target_g); - const int diff_b = static_cast(b) - static_cast(target_b); + const int diff_r = (int)(r) - (int)(target_r); + const int diff_g = (int)(g) - (int)(target_g); + const int diff_b = (int)(b) - (int)(target_b); if (diff_r * diff_r + diff_g * diff_g + diff_b * diff_b > tolerance * tolerance) { diff --git a/src/tests/common/offscreen_render_target.cc b/src/tests/common/offscreen_render_target.cc index 33f0ae0..2b0a43b 100644 --- a/src/tests/common/offscreen_render_target.cc +++ b/src/tests/common/offscreen_render_target.cc @@ -20,7 +20,7 @@ OffscreenRenderTarget::OffscreenRenderTarget(WGPUInstance instance, .usage = WGPUTextureUsage_RenderAttachment | WGPUTextureUsage_CopySrc | WGPUTextureUsage_TextureBinding, .dimension = WGPUTextureDimension_2D, - .size = {static_cast(width), static_cast(height), 1}, + .size = {(uint32_t)(width), (uint32_t)(height), 1}, .format = format, .mipLevelCount = 1, .sampleCount = 1, @@ -44,7 +44,7 @@ OffscreenRenderTarget::~OffscreenRenderTarget() { void OffscreenRenderTarget::map_callback(WGPUMapAsyncStatus status, void* userdata) { - MapState* state = static_cast(userdata); + MapState* state = (MapState*)(userdata); state->status = status; state->done = true; } diff --git a/src/util/asset_manager.cc b/src/util/asset_manager.cc index 0baa063..a606b46 100644 --- a/src/util/asset_manager.cc +++ b/src/util/asset_manager.cc @@ -112,7 +112,7 @@ const uint8_t* GetAsset(AssetId asset_id, size_t* out_size) { CHECK_RETURN_END // Write header - uint32_t* header = reinterpret_cast(generated_data); + uint32_t* header = (uint32_t*)(generated_data); header[0] = (uint32_t)width; header[1] = (uint32_t)height; @@ -155,7 +155,7 @@ TextureAsset GetTextureAsset(AssetId asset_id) { return {0, 0, nullptr}; } - const uint32_t* header = reinterpret_cast(data); + const uint32_t* header = (const uint32_t*)(data); return {(int)header[0], (int)header[1], data + 8}; } @@ -167,13 +167,13 @@ MeshAsset GetMeshAsset(AssetId asset_id) { } const uint8_t* ptr = data; - uint32_t num_vertices = *reinterpret_cast(ptr); + uint32_t num_vertices = *(const uint32_t*)(ptr); ptr += sizeof(uint32_t); - const MeshVertex* vertices = reinterpret_cast(ptr); + const MeshVertex* vertices = (const MeshVertex*)(ptr); ptr += num_vertices * sizeof(MeshVertex); - uint32_t num_indices = *reinterpret_cast(ptr); + uint32_t num_indices = *(const uint32_t*)(ptr); ptr += sizeof(uint32_t); - const uint32_t* indices = reinterpret_cast(ptr); + const uint32_t* indices = (const uint32_t*)(ptr); return {num_vertices, vertices, num_indices, indices}; } -- cgit v1.2.3