Thank you :). Yes something is definatelly not right in the browser version I think and its somehow tied to the fps. I will have to debug that, sorry about that.
Viewing post in Soot 'em up jam comments
It’s a bit special because most of the pixel manipulations, like the smoke, are done in shaders on the GPU so it computes very quickly, and then applied to a TextureRect inside a SubViewport. Sadly, I can’t apply Areas or any collision detection nodes because it’s just a TextureRect.
I can use texturerect like a mask. every colored pixel is a smoke pixel.
I wrote my own collision detection and didnt put enough thought into it ^^
If you’re curious, that’s my solution.
func consume_smoke(image: Image) -> void:
var roomba_pos: Vector2 = roomba.global_position
var viewport_pos: Vector2 = $SubViewportContainer3.global_position
var viewport_size: Vector2 = $SubViewportContainer3.size
var local_pos: Vector2 = roomba_pos - viewport_pos
var px: int = int(local_pos.x * sim_size.x / viewport_size.x)
var py: int = int(local_pos.y * sim_size.y / viewport_size.y)
var range: int = 35
var collected: float = 0.0
for y: int in range(py - range, py + 10):
for x: int in range(px - range, px + range):
if x >= 0 and y >= 0 and x < int(sim_size.x) and y < int(sim_size.y):
var v: float = image.get_pixel(x, y).r
if v > 0.01:
collected += v
image.set_pixel(x, y, Color(0.0, 0.0, 0.0, 0.0))
if collected > 0.0:
change_satisfaction(collected * SMOKE_GAIN)
I go through every pixel occupied by the roomba and check against the TextureRect (2 for loops) to see if it has some color. This happens entirely on the CPU, which makes it super laggy because the function is called every frame. The shader that provides the image runs asynchronously, so sometimes the full image isn’t even written yet, leading to all kinds of race conditions.
In process i do
smoke_viewport.render_target_update_mode = SubViewport.UPDATE_ONCE await RenderingServer.frame_post_draw
but it doesnt seem to be helping
In hindsight, it’s a very bad implementation, and now I know I shouldn’t do something like this again :D