Page 1 of 1

Is custom RAM assignment possible?

Posted: Tue Dec 08, 2015 6:24 pm
by Telecorpse
I've been recently making a program that creates pretty complicated visuals. Unfortunately the application runs at about 1 FPS and my processor is barely used. I found out that the program's RAM consumption caps at 38MB. Is there a way to assign more RAM to the game?

Re: Is custom RAM assignment possible?

Posted: Tue Dec 08, 2015 6:47 pm
by Nixola
How did you measure RAM usage?

Re: Is custom RAM assignment possible?

Posted: Tue Dec 08, 2015 7:29 pm
by Telecorpse
Nixola wrote:How did you measure RAM usage?
I used Windows task manager. I hope I did things correctly :)

Re: Is custom RAM assignment possible?

Posted: Tue Dec 08, 2015 7:54 pm
by slime
It sounds like the low framerate is probably due to unoptimized usage of love.graphics functions rather than a RAM-related thing. If you post a .love or further describe what you're doing (graphics-wise) and what you want it to look like, we can hopefully provide some good performance-improving advice.

Re: Is custom RAM assignment possible?

Posted: Tue Dec 08, 2015 8:49 pm
by Telecorpse
slime wrote:It sounds like the low framerate is probably due to unoptimized usage of love.graphics functions rather than a RAM-related thing. If you post a .love or further describe what you're doing (graphics-wise) and what you want it to look like, we can hopefully provide some good performance-improving advice.
Well the algorithm is pretty simple. The issue might be that it's repeated 10000 times for each frame.
Anyway I ran the program on two different machines and the framerate was pretty much the same

Here's the code

Code: Select all

function love.load()
	line = 10000 -- number of lines
	rd = math.pi / (line / 2)
	n = 1
	speed = 0.5
	alpha = 5
	dir = 0
end
function love.update(dt)
	if love.keyboard.isDown("up") then
		dir = 1
	elseif love.keyboard.isDown("down") then
		dir = -1
	elseif love.keyboard.isDown(" ") then
		dir = 0
	end
	if speed >= 0 then
		if love.keyboard.isDown("w") then
			speed = speed + dt
		elseif love.keyboard.isDown("s") then
			speed = speed - dt
		end
	else
		speed = 0
	end
	n = n + speed * dir * dt
end
function love.draw()
	love.graphics.setColor(255, 255, 255, 255)
	love.graphics.print(n)
	love.graphics.print(speed, 0, 15)
	for k = 1, line do
		if k % 3 == 1 then
			love.graphics.setColor(255, 0, 0, alpha)
		elseif k % 3 == 2 then 
			love.graphics.setColor(0, 255, 0, alpha)
		elseif k % 3 == 0 then
			love.graphics.setColor(0, 0, 255, alpha)
		end
		love.graphics.line(400 + 300 * math.sin(k * rd), 300 + 300 * math.cos(k * rd), 400 + 300 * math.sin(k * n * rd), 300 + 300 * math.cos(k * n * rd))
	end
end

Re: Is custom RAM assignment possible?

Posted: Wed Dec 09, 2015 12:48 am
by kikito
Yes, those 10k draw calls certainly will slow things down.

It seems that you are changing the lines only when a key is pressed (the code handling this is a bit messy and I might be mistaken). If that's the case, I'd suggest drawing into a canvas - only updating it when a key is pressed (when speed is > 0). That way you would "pay the price" of drawing all those lines only when the speed is changed, not on every frame.

Re: Is custom RAM assignment possible?

Posted: Wed Dec 09, 2015 12:38 pm
by Telecorpse
kikito wrote:Yes, those 10k draw calls certainly will slow things down.

It seems that you are changing the lines only when a key is pressed (the code handling this is a bit messy and I might be mistaken). If that's the case, I'd suggest drawing into a canvas - only updating it when a key is pressed (when speed is > 0). That way you would "pay the price" of drawing all those lines only when the speed is changed, not on every frame.
Nah, the "up" and "down" keys control whether n is increased or decreased by the speed. I should really move that to love.keypressed function.
The value of n when dir != 0 is changing every frame, so the lines should also be updated at every frame.
Anyway the visuals look awesome even at 500 lines. I just tried to smooth the patterns out.