Turns out I missed a deref. get_cell should work now.

This commit is contained in:
IQuant 2024-09-23 23:40:48 +03:00
parent 6b9b5254f3
commit 985bb6dbe2

View file

@ -7,17 +7,20 @@ pub(crate) struct ParticleWorldState {
impl ParticleWorldState {
pub(crate) unsafe fn get_cell(&self, x: i32, y: i32) -> *const c_void {
let x = dbg!(x as isize);
let y = dbg!(y as isize);
let x = x as isize;
let y = y as isize;
let chunk_index = (((((y) >> 9) - 256) & 511) * 512 + ((((x) >> 9) - 256) & 511)) * 4;
// Deref 1/3
let chunk_arr = self.chunk_map_this.offset(8).cast::<*const c_void>().read();
// dbg!(chunk_arr);
// Deref 2/3
let chunk = chunk_arr.offset(chunk_index).cast::<*const c_void>().read();
dbg!(chunk);
if chunk.is_null() {
// TODO this normally returns air material
return null();
}
let pixel = chunk.offset(((y & 511) << 9 | x & 511) * 4);
// Deref 3/3
let pixel_array = chunk.cast::<*const c_void>().read();
let pixel = pixel_array.offset(((y & 511) << 9 | x & 511) * 4);
pixel
}