we got pixels

This commit is contained in:
bgkillas 2025-06-29 13:56:42 -04:00
parent 4f958371fc
commit 1fd4e775ed
5 changed files with 4 additions and 96 deletions

View file

@ -25,37 +25,3 @@ function OnWorldInitialized()
local remove_cell = tonumber(ffi.cast("intptr_t", world_info.remove_cell))
blob_guy.init_particle_world_state(grid_world, chunk_map, material_list, construct_cell, remove_cell)
end
function construct_cell(grid_world, x, y, mat, blob)
local gw = world_ffi.get_grid_world()
local chunk_map = gw.vtable.get_chunk_map(grid_world)
GamePrint("c")
local m = world_ffi.get_material_ptr(blob)
GamePrint(blob)
GamePrint(grid_world)
GamePrint(tonumber(ffi.cast("intptr_t", gw)))
GamePrint(x)
GamePrint(y)
GamePrint(mat)
GamePrint(tonumber(ffi.cast("intptr_t", m)))
GamePrint(tonumber(ffi.cast("intptr_t", chunk_map)))
GamePrint(tostring(world_ffi.chunk_loaded(chunk_map, x, y)))
local cell = world_ffi.construct_cell(gw, x, y, m, nil)
GamePrint("ce")
GamePrint(tonumber(ffi.cast("intptr_t", cell)))
return tonumber(ffi.cast("intptr_t", cell))
end
function remove_cell(grid_world, cell, x, y)
local gw = world_ffi.get_grid_world()
local chunk_map = gw.vtable.get_chunk_map(grid_world)
GamePrint("r")
GamePrint(grid_world)
GamePrint(tonumber(ffi.cast("intptr_t", gw)))
GamePrint(cell)
local c = world_ffi.get_cell(chunk_map, x, y)
GamePrint(tonumber(ffi.cast("intptr_t", c)))
GamePrint(tonumber(ffi.cast("intptr_t", c[0])))
GamePrint(tostring(world_ffi.chunk_loaded(chunk_map, x, y)))
GamePrint(x)
GamePrint(y)
world_ffi.remove_cell(gw, c[0], x, y, nil)
end

View file

@ -1,6 +1,5 @@
use crate::chunk::{CellType, Chunk, ChunkPos};
use crate::{CHUNK_SIZE, State};
use noita_api::game_print;
#[derive(Default, Debug)]
pub struct Pos {
x: f64,
@ -29,14 +28,12 @@ impl State {
let mut k = 0;
for x in -1..=1 {
for y in -1..=1 {
game_print(format!("{} {}", c.x + x, c.y + y));
if unsafe { !pws.encode_area(c.x + x, c.y + y, &mut self.world[k]) } {
continue 'upper;
}
k += 1;
}
}
game_print(blob.pixels[0].x.to_string());
blob.update(&mut self.world);
let mut k = 0;
for x in -1..=1 {
@ -73,7 +70,6 @@ impl Blob {
map[k][n] = if matches!(map[k][n], CellType::Remove) {
CellType::Ignore
} else {
game_print(format!("{} {}", k, n));
CellType::Blob
}
}

View file

@ -1,7 +1,7 @@
use crate::CHUNK_SIZE;
use std::ops::{Index, IndexMut};
pub struct Chunk(pub [CellType; CHUNK_SIZE * CHUNK_SIZE]);
#[derive(Default, Copy, Clone)]
#[derive(Default, Copy, Clone, Debug)]
pub enum CellType {
#[default]
Unknown,
@ -27,7 +27,7 @@ impl IndexMut<usize> for Chunk {
&mut self.0[index]
}
}
#[derive(Eq, Hash, PartialEq)]
#[derive(Eq, Hash, PartialEq, Debug)]
pub struct ChunkPos {
pub x: i32,
pub y: i32,

View file

@ -4,7 +4,6 @@ mod noita;
use crate::blob_guy::Blob;
use crate::chunk::Chunk;
use crate::noita::ParticleWorldState;
use eyre::WrapErr;
use noita_api::add_lua_fn;
use noita_api::lua::LUA;
use noita_api::lua::LuaState;
@ -71,40 +70,6 @@ fn init_particle_world_state(lua: LuaState) -> eyre::Result<()> {
Ok(())
})
}
fn construct_cell(
grid_world: *mut c_void,
x: i32,
y: i32,
mat: *const c_void,
b: u16,
) -> eyre::Result<*mut noita::ntypes::Cell> {
let lua = LuaState::current()?;
lua.get_global(c"construct_cell");
lua.push_integer(grid_world as isize);
lua.push_integer(x as isize);
lua.push_integer(y as isize);
lua.push_integer(mat as isize);
lua.push_integer(b as isize);
lua.call(5, 1i32).wrap_err("Failed to call construct")?;
let c = lua.to_integer(-1);
lua.pop_last_n(1);
Ok(c as *mut noita::ntypes::Cell)
}
fn remove_cell(
grid_world: *mut c_void,
cell: *mut noita::ntypes::Cell,
x: i32,
y: i32,
) -> eyre::Result<()> {
let lua = LuaState::current()?;
lua.get_global(c"remove_cell");
lua.push_integer(grid_world as isize);
lua.push_integer(cell as isize);
lua.push_integer(x as isize);
lua.push_integer(y as isize);
lua.call(4, 0i32).wrap_err("Failed to call construct")?;
Ok(())
}
fn update(_: LuaState) -> eyre::Result<()> {
STATE.with(|state| {
let mut state = state.try_borrow_mut()?;

View file

@ -1,6 +1,5 @@
use crate::CHUNK_SIZE;
use crate::chunk::{CellType, Chunk};
use crate::{CHUNK_SIZE, construct_cell, remove_cell};
use noita_api::{game_print, print};
use std::arch::asm;
use std::{ffi::c_void, mem};
pub(crate) mod ntypes;
@ -72,7 +71,6 @@ impl ParticleWorldState {
// Deref 2/3
let chunk = unsafe { chunk_arr.offset(chunk_index).cast::<*const c_void>().read() };
if chunk.is_null() {
game_print(":(");
return true;
}
// Deref 3/3
@ -90,19 +88,6 @@ impl ParticleWorldState {
unsafe { pixel.cast::<*const ntypes::Cell>().read().as_ref() }
}
fn get_cell_raw_mut(&mut self, x: i32, y: i32) -> Option<*mut ntypes::Cell> {
let x = x as isize;
let y = y as isize;
let pixel = unsafe { self.pixel_array.offset(((y << 9) | x) * 4) as *const ntypes::Cell };
if pixel.is_null() {
return None;
}
let cell = pixel as *mut ntypes::Cell;
if cell.is_null() {
return None;
}
Some(cell)
}
fn get_cell_raw_mut_nil(&mut self, x: i32, y: i32) -> *mut *mut ntypes::Cell {
let x = x as isize;
let y = y as isize;
@ -159,15 +144,12 @@ impl ParticleWorldState {
unsafe {
let cell = self.get_cell_raw_mut_nil(i, j);
if !(*cell).is_null() {
print(format!("{:?} {} {}", *cell, x, y));
self.remove_cell(*cell, x, y);
}
let blob_ptr = self
.material_list_ptr
.offset(ntypes::CELLDATA_SIZE * self.blob_guy as isize);
print(format!("{} {} {:?}", x, y, blob_ptr));
let src = self.create_cell(x, y, blob_ptr, std::ptr::null::<c_void>());
game_print(format!("{src:?} {cell:?} {:?}", *cell));
if !src.is_null() {
let liquid: &mut ntypes::LiquidCell =
&mut *(src as *mut ntypes::LiquidCell);
@ -182,8 +164,7 @@ impl ParticleWorldState {
unsafe {
let cell = self.get_cell_raw_mut_nil(i, j);
if !(*cell).is_null() {
//print(format!("2 {:?} {} {}", *cell, x, y));
//self.remove_cell(*cell, x, y);
self.remove_cell(*cell, x, y);
}
}
}