Pulpscript optimisation question

Hi all. For a Pulp project I want to have floor tiles look different depending on the distance from the player. Currently, all floor tiles do this on an emit:

	tilePlayerDistX = event.x
	tilePlayerDistX -= event.px
	tilePlayerDistX *= tilePlayerDistX
	tilePlayerDistY = event.y
	tilePlayerDistY -= event.py
	tilePlayerDistY *= tilePlayerDistY
	tilePlayerDist = tilePlayerDistX
	tilePlayerDist += tilePlayerDistY
	if tilePlayerDist>20 then
		frame 1
	else
		frame 0
	end

On the actual hardware, this takes a bit of time to run. I've hidden this delay on a point in the animation where it won't be too noticable, but I'd still like to optimise it a bit. I'm mostly a self-thought coder, so there's probably a lot of obvious stuff I'm missing. Can you help me out and/or point me in the right direction? Thanks!

1 Like

emit is going to be heavy on performance for this as it is going to run the code on every tile in the room.

Consider though which tiles actually need the frame changing when the player moves - it's only those at the specific radius from the player. Rather than using emit to target every tile, you only need to target the tiles that actually need updating.

That's the route I'd go down for trying to improve the performance!

I agree, and I was actually trying to come up with something that would work for this last night to help out. I came up with something to flip the tiles to frame 1 but how would you go about flipping them back once you move out of range? I couldn't come up with anything for that. It was kind of an issue I have with my game as well, resetting tiles after events change them.

	on update do
	left = event.px
	left--
	right = event.px
	right++
	up = event.py
	up++
	down = event.py
	down--
	tell left,up to
		frame 1
	end
	tell event.px,up to
		frame 1
	end
	tell right,up to
		frame 1
	end
	tell right,event.py to
		frame 1
	end
	tell right,down to
		frame 1
	end
	tell event.px,down to
		frame 1
	end
	tell left,down to
		frame 1
	end
	tell left,event.py to
		frame 1
	end
end

Thanks for the replies!

I switched to an implementation where an emit flips all the tiles to frame 0, and then a nested set of loops (one for the x and one for the y) tells the specific tiles to go to frame 1. Still not perfect, but a bit better.

1 Like