A background disproportionately consumes CPU

Questions about the LÖVE API, installing LÖVE and other support related questions go here.
Forum rules
Before you make a thread asking for help, read this.
User avatar
Batrachus
Prole
Posts: 7
Joined: Sat Apr 16, 2011 8:39 am
Location: Czech Republic

A background disproportionately consumes CPU

Post by Batrachus »

In love.load I have this:

Code: Select all

love.graphics.setColorMode("replace")
nebe = love.graphics.newImage("nebe.png")
...
And in love.draw:

Code: Select all

love.graphics.setBackgroundColor(152, 68, 0)
love.graphics.draw(nebe, 0, 0, 0, 1, 1, 0, 0)
love.graphics.setColor(0, 0, 0)
...
The file nebe.png looks like this:

Image

When I have runned my game, it consumes 99% of CPU. Where is the fault? I'm sorry I'm writing here two times in one day.
My arrowfish doesn't want to be in one picture with OBEY. So I putted it into my signature.
User avatar
Lafolie
Inner party member
Posts: 809
Joined: Tue Apr 05, 2011 2:59 pm
Location: SR388
Contact:

Re: A background disproportionately consumes CPU

Post by Lafolie »

Batrachus wrote:I'm sorry I'm writing here two times in one day.
I can't answer/solve the problem, but I can say that you shouldn't worry things like that, silly. If you have a problem and you need help, there's no shame in asking for it :nyu:
Do you recognise when the world won't stop for you? Or when the days don't care what you've got to do? When the weight's too tough to lift up, what do you? Don't let them choose for you, that's on you.
User avatar
TechnoCat
Inner party member
Posts: 1611
Joined: Thu Jul 30, 2009 12:31 am
Location: Milwaukee, WI
Contact:

Re: A background disproportionately consumes CPU

Post by TechnoCat »

Batrachus wrote:When I have runned my game, it consumes 99% of CPU. Where is the fault? I'm sorry I'm writing here two times in one day.
LOVE will use as much CPU as it can get its grubby little fingers on. It doesn't mean you're low on power necessarily.

Try printing your FPS to make sure it isn't low.
User avatar
Batrachus
Prole
Posts: 7
Joined: Sat Apr 16, 2011 8:39 am
Location: Czech Republic

Re: A background disproportionately consumes CPU

Post by Batrachus »

Without background image the FPS stabilized on 61. With background image it was less than 1.
My arrowfish doesn't want to be in one picture with OBEY. So I putted it into my signature.
User avatar
TechnoCat
Inner party member
Posts: 1611
Joined: Thu Jul 30, 2009 12:31 am
Location: Milwaukee, WI
Contact:

Re: A background disproportionately consumes CPU

Post by TechnoCat »

Batrachus wrote:Without background image the FPS stabilized on 61. With background image it was less than 1.
Can we see more code then?
User avatar
Lafolie
Inner party member
Posts: 809
Joined: Tue Apr 05, 2011 2:59 pm
Location: SR388
Contact:

Re: A background disproportionately consumes CPU

Post by Lafolie »

Ooooh yeah, this is interesting. I'd like to test this out also.
Do you recognise when the world won't stop for you? Or when the days don't care what you've got to do? When the weight's too tough to lift up, what do you? Don't let them choose for you, that's on you.
User avatar
Batrachus
Prole
Posts: 7
Joined: Sat Apr 16, 2011 8:39 am
Location: Czech Republic

Re: A background disproportionately consumes CPU

Post by Batrachus »

Code: Select all

mapa = {}
dolu = 0
nahoru = 0
poloha = 50

function round(num)
	return num - (num % 1)
end

function getVyska()
	zlomek = poloha % 1
	return (mapa[poloha - (poloha % 1)] + (mapa[poloha + 1 - ((poloha + 1) % 1)] - mapa[poloha - (poloha % 1)]) * zlomek)
end

function love.load()
	love.graphics.setColorMode("replace")
	obrazek_postavy = love.graphics.newImage("postava.png")
	love.graphics.draw(nebe, 0, 0, 0, 1, 1, 0, 0)
	math.randomseed(os.time())
	nahoru = math.random(1, 2)
	dolu = math.random (-2, -1)
	mapa[0] = math.random(0, 600)
	for i = 1, 1000 do
		nahoru = nahoru + math.random(-1, 1)
		if nahoru < 1 then nahoru = 1 end
		dolu = dolu + math.random(-1, 1)
		if dolu > -1 then dolu = -1 end
		mapa[i] = mapa[i-1] + math.random(dolu, nahoru)
	end
end

function love.update(dt)
	if love.keyboard.isDown("left") and poloha > 50 then poloha = poloha - 1/math.sqrt(8 + (math.abs(mapa[round(poloha)+1] - mapa[round(poloha-1)+1]))) end
	if love.keyboard.isDown("right") and poloha < 950 then poloha = poloha + 1/math.sqrt(8 + (math.abs(mapa[round(poloha)] - mapa[round(poloha+1)]))) end
	if love.keyboard.isDown("down") then mapa[round(poloha, 0)] = mapa[round(poloha, 0)] + 1 end
	
end

function love.draw()
	love.graphics.setBackgroundColor(152, 68, 0)
	nebe = love.graphics.newImage("nebe.png")
	love.graphics.setColor(0, 0, 0)
	for i = 1, 1000 do
		love.graphics.polygon(
			"fill",
			(i-1)*8-poloha*8+400,
			mapa[i-1]-getVyska()+300,
			i*8-poloha*8+400,
			mapa[i]-getVyska()+300,
			i*8-poloha*8+400,
			100000-getVyska()+300,
			(i-1)*8-poloha*8+400,
			100000-getVyska()+300
		)
	end
	love.graphics.draw(obrazek_postavy, 384, 272, 0, 1, 1, 0, 0)
	love.graphics.print(love.timer.getFPS(), 30, 30, 0, 1, 1)
end
NOTE: postava.png is small and negligible 32×32 image
NOTE 2: variable names are in czech.
My arrowfish doesn't want to be in one picture with OBEY. So I putted it into my signature.
User avatar
TechnoCat
Inner party member
Posts: 1611
Joined: Thu Jul 30, 2009 12:31 am
Location: Milwaukee, WI
Contact:

Re: A background disproportionately consumes CPU

Post by TechnoCat »

You're calling newImage in draw. So it creates a new image every frame.
move newImage to love.load()
User avatar
Batrachus
Prole
Posts: 7
Joined: Sat Apr 16, 2011 8:39 am
Location: Czech Republic

Re: A background disproportionately consumes CPU

Post by Batrachus »

Wat? :ultrashocked: I bet when I was programming the game, it wasnt so. And altrough I fixed it, still it doesnt work.
My arrowfish doesn't want to be in one picture with OBEY. So I putted it into my signature.
User avatar
Lafolie
Inner party member
Posts: 809
Joined: Tue Apr 05, 2011 2:59 pm
Location: SR388
Contact:

Re: A background disproportionately consumes CPU

Post by Lafolie »

Love is an aggressive application, it will always be intensive to some extent.
Do you recognise when the world won't stop for you? Or when the days don't care what you've got to do? When the weight's too tough to lift up, what do you? Don't let them choose for you, that's on you.
Post Reply

Who is online

Users browsing this forum: Ahrefs [Bot], Bing [Bot], Google [Bot] and 2 guests