Page 4 of 5

Re: Rebound (another pong)

Posted: Tue Jan 18, 2011 9:39 pm
by TechnoCat
Robin wrote:Also, it appears to lack a license. This makes böb sad: :cry:
I usually go with this CC http://creativecommons.org/licenses/by/3.0/

EDIT: Licensed with CC3.0 https://bitbucket.org/dannyfritz/reboun ... e13f970402

Re: Rebound (another pong)

Posted: Tue Jan 18, 2011 9:48 pm
by Robin
You mean CC-BY. Just saying "a Creative Commons license" isn't really clear. Luckily the URL was pretty explicit. ;)

Re: Rebound (another pong)

Posted: Tue Jan 18, 2011 9:52 pm
by TechnoCat
Robin wrote:You mean CC-BY. Just saying "a Creative Commons license" isn't really clear. Luckily the URL was pretty explicit. ;)
CC BY 3.0 actually. And my team projects are usually CC BY-NC because my teammates are usually like that.

Re: Rebound (another pong)

Posted: Wed Aug 10, 2011 2:00 am
by Rad3k
I know it's an old thread, but I've just tried this game and wanted to say a few words.

The game is really nice, although a bit slow at the beginning (the paddles could move faster too). I'll have yet to try it with a friend to see how it feels when playing against another human.

Oh, and I have a small suggestion for (technical) improvement. CPU usage - on my system it's over 60% out of 2GHz, and it's quite much for a simple game like this. For stationary PCs it may not be a big deal, but it's certainly not nice for laptop batteries. The cause of this CPU usage is that the default LÖVE game loop runs as fast as it can. And normally, there's no reason to go faster than 60fps - refresh rate of most computer displays. Add this to your main.lua and expect an order of magnitude drop in CPU usage, with no decrease in performance:

Code: Select all

function love.run ()
	-- Prepare stuff
	love.load(arg)

	-- Set a reasonable FPS limit
	local FPS = 60
	local dt = 1 / FPS

	-- Timekeeping variable
	local time

	-- Main loop
	while true do

		-- Update the time
		time = love.timer.getTime()

		-- Process events
		for e, a, b, c in love.event.poll() do
			if e == "q" then
				if love.quit then love.quit() end
				if love.audio then love.audio.stop() end
				return
			end
			love.handlers[e](a, b, c)
		end
		
		-- Do the game mechanic
		if love.update then love.update(dt) end

		-- Draw the graphics
		love.graphics.clear()
		love.draw()
		love.graphics.present()

		-- Wait for another frame
		local time_work = love.timer.getTime() - time
		if time_work < dt then
			local time_wait = dt - time_work
			love.timer.sleep(time_wait * 1000)
		end
	end
end
This is the main loop I use in my projects - it runs with a constant framerate of 60fps.

Re: Rebound (another pong)

Posted: Wed Aug 10, 2011 2:20 am
by TechnoCat
Thanks for the suggestions, although I won't be relearning my code to implement them unless I get a pull request. =P The way I code has actually changed a ton since I made this.

Re: Rebound (another pong)

Posted: Wed Aug 10, 2011 11:56 am
by Ghuntar
Rad3k wrote:I know it's an old thread, but I've just tried this game and wanted to say a few words.

The game is really nice, although a bit slow at the beginning (the paddles could move faster too). I'll have yet to try it with a friend to see how it feels when playing against another human.

Oh, and I have a small suggestion for (technical) improvement. CPU usage - on my system it's over 60% out of 2GHz, and it's quite much for a simple game like this. For stationary PCs it may not be a big deal, but it's certainly not nice for laptop batteries. The cause of this CPU usage is that the default LÖVE game loop runs as fast as it can. And normally, there's no reason to go faster than 60fps - refresh rate of most computer displays. Add this to your main.lua and expect an order of magnitude drop in CPU usage, with no decrease in performance:

Code: Select all

function love.run ()
	-- Prepare stuff
	love.load(arg)

	-- Set a reasonable FPS limit
	local FPS = 60
	local dt = 1 / FPS

	-- Timekeeping variable
	local time

	-- Main loop
	while true do

		-- Update the time
		time = love.timer.getTime()

		-- Process events
		for e, a, b, c in love.event.poll() do
			if e == "q" then
				if love.quit then love.quit() end
				if love.audio then love.audio.stop() end
				return
			end
			love.handlers[e](a, b, c)
		end
		
		-- Do the game mechanic
		if love.update then love.update(dt) end

		-- Draw the graphics
		love.graphics.clear()
		love.draw()
		love.graphics.present()

		-- Wait for another frame
		local time_work = love.timer.getTime() - time
		if time_work < dt then
			local time_wait = dt - time_work
			love.timer.sleep(time_wait * 1000)
		end
	end
end
This is the main loop I use in my projects - it runs with a constant framerate of 60fps.
Is it better than :

Code: Select all

function love.update(dt)
   if dt < (100/6) then
      love.timer.sleep((100/6) - dt)
   end
end
? (As you can find in the wiki : http://love2d.org/wiki/love.timer.sleep )

Ghuntar.

Re: Rebound (another pong)

Posted: Wed Aug 10, 2011 8:55 pm
by Robin
Ehm, don't you mean something like:

Code: Select all

function love.update(dt)
   if dt < 1/60 then
      love.timer.sleep(1000*(1/60 - dt))
   end
end
The example on the wiki is dead wrong, by the way. Fixing it right away.

Re: Rebound (another pong)

Posted: Wed Aug 10, 2011 9:38 pm
by Ghuntar
Hum... *cough*... Yes, that was what I meant... But the question stay still.
I would prefer the one that do not touch to love.run(), but am I right ?

Ghuntar.

Re: Rebound (another pong)

Posted: Wed Aug 10, 2011 11:51 pm
by Rad3k
Robin wrote:Ehm, don't you mean something like:

Code: Select all

function love.update(dt)
   if dt < 1/60 then
      love.timer.sleep(1000*(1/60 - dt))
   end
end
The example on the wiki is dead wrong, by the way. Fixing it right away.
I understand what this code is supposed to do, but it's unclear to me what it's actually doing. I assume you use the default love.run. You calculate the sleep time based on how much the previous frame took? Let's see:

1st frame: dt is 0, we sleep for 1/60 second
2nd frame: dt is 1/60 plus the processing time of 1st frame, so we don't sleep at all
3rd frame: dt is processing time of 2nd frame, so we sleep for 1/60 - processing_time
4th frame: dt is 1/60 plus the processing time of 3rd frame, so we don't sleep at all
5th frame: dt is processing time of 4th frame, so we sleep for 1/60 - processing_time
etc.

It turns out it sleeps only once every two frames. And the framerate would vary with processing times. Or did I make an error somewhere?

By the way, one of my favourite quotes about programming is
probably Edsger W. Dijkstra wrote:The computing scientist's main challenge is not to get confused by the complexities of his own making.
;)

Re: Rebound (another pong)

Posted: Thu Aug 11, 2011 5:48 am
by Robin
Rad3k wrote:I understand what this code is supposed to do, but it's unclear to me what it's actually doing.
Oh, I don't know whether it actually works either. But love.timer.sleep is in milliseconds and dt in seconds, so the example from the wiki could never work.