Rebound (another pong)

Show off your games, demos and other (playable) creations.
User avatar
TechnoCat
Inner party member
Posts: 1611
Joined: Thu Jul 30, 2009 12:31 am
Location: Denver, CO
Contact:

Re: Rebound (another pong)

Post by TechnoCat » Tue Jan 18, 2011 9:39 pm

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

User avatar
Robin
The Omniscient
Posts: 6506
Joined: Fri Feb 20, 2009 4:29 pm
Location: The Netherlands
Contact:

Re: Rebound (another pong)

Post by Robin » Tue Jan 18, 2011 9:48 pm

You mean CC-BY. Just saying "a Creative Commons license" isn't really clear. Luckily the URL was pretty explicit. ;)
Help us help you: attach a .love.

User avatar
TechnoCat
Inner party member
Posts: 1611
Joined: Thu Jul 30, 2009 12:31 am
Location: Denver, CO
Contact:

Re: Rebound (another pong)

Post by TechnoCat » Tue Jan 18, 2011 9:52 pm

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.

Rad3k
Citizen
Posts: 69
Joined: Mon Aug 08, 2011 12:28 pm

Re: Rebound (another pong)

Post by Rad3k » Wed Aug 10, 2011 2:00 am

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.

User avatar
TechnoCat
Inner party member
Posts: 1611
Joined: Thu Jul 30, 2009 12:31 am
Location: Denver, CO
Contact:

Re: Rebound (another pong)

Post by TechnoCat » Wed Aug 10, 2011 2:20 am

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.

User avatar
Ghuntar
Prole
Posts: 29
Joined: Wed Nov 25, 2009 8:56 am

Re: Rebound (another pong)

Post by Ghuntar » Wed Aug 10, 2011 11:56 am

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.
Crazy Little Thing Called LÖVE.

User avatar
Robin
The Omniscient
Posts: 6506
Joined: Fri Feb 20, 2009 4:29 pm
Location: The Netherlands
Contact:

Re: Rebound (another pong)

Post by Robin » Wed Aug 10, 2011 8:55 pm

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.
Help us help you: attach a .love.

User avatar
Ghuntar
Prole
Posts: 29
Joined: Wed Nov 25, 2009 8:56 am

Re: Rebound (another pong)

Post by Ghuntar » Wed Aug 10, 2011 9:38 pm

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.
Crazy Little Thing Called LÖVE.

Rad3k
Citizen
Posts: 69
Joined: Mon Aug 08, 2011 12:28 pm

Re: Rebound (another pong)

Post by Rad3k » Wed Aug 10, 2011 11:51 pm

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.
;)

User avatar
Robin
The Omniscient
Posts: 6506
Joined: Fri Feb 20, 2009 4:29 pm
Location: The Netherlands
Contact:

Re: Rebound (another pong)

Post by Robin » Thu Aug 11, 2011 5:48 am

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.
Help us help you: attach a .love.

Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest