paavohtl Claude Opus 4.6 (1M context) commited on
Commit
92780f9
·
1 Parent(s): 2716775

refactor: call_gfx_find_and_load takes &CStr instead of *const u8

Browse files

The high-level sprite lookup helper now accepts &CStr directly,
moving the pointer cast inside the function. Callers pass c"name"
without .as_ptr().cast().

Lower-level functions (gfx_dir_find_entry, gfx_resource_create,
DDDisplay vtable methods) keep *const u8 since they're called from
FFI hooks or thin vtable wrappers.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>

crates/openwa-core/src/display/gradient.rs CHANGED
@@ -113,8 +113,7 @@ pub(crate) unsafe fn compute_complex_gradient(
113
  let mut palette = PaletteContext::new();
114
 
115
  // Step 1: Load gradient.img
116
- let gradient_sprite =
117
- call_gfx_find_and_load(land_layer, c"gradient.img".as_ptr().cast(), layer3_ctx);
118
  if gradient_sprite.is_null() {
119
  return;
120
  }
@@ -143,8 +142,7 @@ pub(crate) unsafe fn compute_complex_gradient(
143
 
144
  // Step 3: If heights match, also set gradient_image_2
145
  if target_rows == gradient_height {
146
- let gradient2 =
147
- call_gfx_find_and_load(land_layer, c"gradient.img".as_ptr().cast(), layer3_ctx);
148
  (*ddgame).gradient_image_2 = gradient2;
149
  }
150
 
 
113
  let mut palette = PaletteContext::new();
114
 
115
  // Step 1: Load gradient.img
116
+ let gradient_sprite = call_gfx_find_and_load(land_layer, c"gradient.img", layer3_ctx);
 
117
  if gradient_sprite.is_null() {
118
  return;
119
  }
 
142
 
143
  // Step 3: If heights match, also set gradient_image_2
144
  if target_rows == gradient_height {
145
+ let gradient2 = call_gfx_find_and_load(land_layer, c"gradient.img", layer3_ctx);
 
146
  (*ddgame).gradient_image_2 = gradient2;
147
  }
148
 
crates/openwa-core/src/engine/ddgame.rs CHANGED
@@ -1264,8 +1264,7 @@ unsafe fn init_graphics_and_resources(
1264
 
1265
  if s_var1 < 0x61 && level_height == 0x2B8 {
1266
  // Simple gradient: load gradient.img directly
1267
- let gradient =
1268
- call_gfx_find_and_load(land_layer, c"gradient.img".as_ptr().cast(), layer3_ctx);
1269
  (*ddgame).gradient_image = gradient;
1270
  } else {
1271
  compute_complex_gradient(ddgame, land_layer, layer3_ctx, s_var1);
@@ -1276,8 +1275,7 @@ unsafe fn init_graphics_and_resources(
1276
  let layer2_ctx = DDDisplay::set_active_layer((*ddgame).display, 2);
1277
  // In the original, fill.img uses piStack_126c which the decompiler
1278
  // shows was set from piVar3 (water_layer from landscape+0xB38).
1279
- let fill_sprite =
1280
- call_gfx_find_and_load(water_layer, c"fill.img".as_ptr().cast(), layer2_ctx);
1281
  if !fill_sprite.is_null() {
1282
  // Get pixel value: fill_sprite->vtable[4](0, 0)
1283
  let fill_vt = *(fill_sprite as *const *const u32);
 
1264
 
1265
  if s_var1 < 0x61 && level_height == 0x2B8 {
1266
  // Simple gradient: load gradient.img directly
1267
+ let gradient = call_gfx_find_and_load(land_layer, c"gradient.img", layer3_ctx);
 
1268
  (*ddgame).gradient_image = gradient;
1269
  } else {
1270
  compute_complex_gradient(ddgame, land_layer, layer3_ctx, s_var1);
 
1275
  let layer2_ctx = DDDisplay::set_active_layer((*ddgame).display, 2);
1276
  // In the original, fill.img uses piStack_126c which the decompiler
1277
  // shows was set from piVar3 (water_layer from landscape+0xB38).
1278
+ let fill_sprite = call_gfx_find_and_load(water_layer, c"fill.img", layer2_ctx);
 
1279
  if !fill_sprite.is_null() {
1280
  // Get pixel value: fill_sprite->vtable[4](0, 0)
1281
  let fill_vt = *(fill_sprite as *const *const u32);
crates/openwa-core/src/render/gfx_dir.rs CHANGED
@@ -378,10 +378,11 @@ pub unsafe fn gfx_resource_create(gfx_dir: *mut u8, name: *const u8, output: *mu
378
  #[cfg(target_arch = "x86")]
379
  pub(crate) unsafe fn call_gfx_find_and_load(
380
  gfx_dir: *mut u8,
381
- name: *const u8,
382
  display_ctx: *mut u8,
383
  ) -> *mut u8 {
384
- let entry = gfx_dir_find_entry(name, gfx_dir);
 
385
 
386
  if !entry.is_null() {
387
  // Try cached load: gfx_dir->vtable[2](entry->field_4)
@@ -399,7 +400,7 @@ pub(crate) unsafe fn call_gfx_find_and_load(
399
  }
400
 
401
  // Fallback: load image directly
402
- call_gfx_load_and_wrap(gfx_dir, name, display_ctx)
403
  }
404
 
405
  /// Helper: load image via GfxDir__LoadImage + wrap as DisplayGfx.
 
378
  #[cfg(target_arch = "x86")]
379
  pub(crate) unsafe fn call_gfx_find_and_load(
380
  gfx_dir: *mut u8,
381
+ name: &core::ffi::CStr,
382
  display_ctx: *mut u8,
383
  ) -> *mut u8 {
384
+ let name_ptr = name.as_ptr() as *const u8;
385
+ let entry = gfx_dir_find_entry(name_ptr, gfx_dir);
386
 
387
  if !entry.is_null() {
388
  // Try cached load: gfx_dir->vtable[2](entry->field_4)
 
400
  }
401
 
402
  // Fallback: load image directly
403
+ call_gfx_load_and_wrap(gfx_dir, name_ptr, display_ctx)
404
  }
405
 
406
  /// Helper: load image via GfxDir__LoadImage + wrap as DisplayGfx.