HUMP - yet another set of helpers

Showcase your libraries, tools and other projects that help your fellow love users.
Post Reply
User avatar
MarekkPie
Inner party member
Posts: 587
Joined: Wed Dec 28, 2011 4:48 pm
Contact:

Re: HUMP - yet another set of helpers

Post by MarekkPie »

Yeah, my bad.
User avatar
mofr
Prole
Posts: 8
Joined: Thu Apr 26, 2012 11:04 am
Contact:

Re: HUMP - yet another set of helpers

Post by mofr »

Very nice and compact lib, vdrl, thank you!

What do you think about multiple timer instances in one game?
For example, one timer for one game state.

Something like this:

Code: Select all

-- load library
hump_timer = require 'hump.timer'

-- create timer instance with separate update, add, addPeriodic etc functions
timer1 = hump_timer.new() 

-- another instance
timer2 = hump_timer.new()

-- timer1:add(1, function() end )
-- timer2:add(1, function() end )
-- timer1:update(dt)
-- timer2:update(dt)
-- etc
Sorry for my english and lua. Please, correct my mistakes!
User avatar
vrld
Party member
Posts: 917
Joined: Sun Apr 04, 2010 9:14 pm
Location: Germany
Contact:

Re: HUMP - yet another set of helpers

Post by vrld »

I've given that some thought but went with a single instance timer because of two reasons:
  1. It's a more compact implementation, and more importantly
  2. It's an easier, more direct interface.
I don't really see the benefit of having timer instances, but am willing to implement it if there is reason that outweighs having a simple interface.One timer per gamestate is (imo) no such reason: To avoid timers to "leak" from the previous to the current state, you tend to clear all timers (Timer.clear) anyway when switching state.
I have come here to chew bubblegum and kick ass... and I'm all out of bubblegum.

hump | HC | SUIT | moonshine
User avatar
mofr
Prole
Posts: 8
Joined: Thu Apr 26, 2012 11:04 am
Contact:

Re: HUMP - yet another set of helpers

Post by mofr »

The main reason is possibility to pause a group of timers.
Example. There are two states: game process and menu. When user enters menu I have to pause game timers (to allow user continue game and its timers) and run menu timers. When user resumes a game I have to pause menu timers and continue updating only playgame-state timers.

P.S. sorry for my english.
Sorry for my english and lua. Please, correct my mistakes!
User avatar
mofr
Prole
Posts: 8
Joined: Thu Apr 26, 2012 11:04 am
Contact:

Re: HUMP - yet another set of helpers

Post by mofr »

Example 2. Arkanoid. Level finished and I add a timer function with level changing code. Then I press escape to enter menu and pause the game, but no way to pause my timer function with level transition.

Whether correctly I use the hump timer library?
Sorry for my english and lua. Please, correct my mistakes!
User avatar
vrld
Party member
Posts: 917
Joined: Sun Apr 04, 2010 9:14 pm
Location: Germany
Contact:

Re: HUMP - yet another set of helpers

Post by vrld »

That are some compelling points. However, I am still not fully convinced to drop the simple interface (maybe we can have a hybrid approach though). Can you give an example of timers you need to run during the pause menu, but not during the game?
I have come here to chew bubblegum and kick ass... and I'm all out of bubblegum.

hump | HC | SUIT | moonshine
User avatar
mofr
Prole
Posts: 8
Joined: Thu Apr 26, 2012 11:04 am
Contact:

Re: HUMP - yet another set of helpers

Post by mofr »

vrld wrote:Can you give an example of timers you need to run during the pause menu, but not during the game?
There are various delayed and periodical animations and events, which I want to add to my menu (not only menu gamestate).
Concrete examples:
  • After "resume game" click, we run menu dissappearance animation (or another transition effect) and only then (1 sec, for example) continue the game;
  • Run some demo when user wait for long enough (remember mortal combat).
There are two little (imo) differencies between current simple interface and complicated:
1. Minimal library initialization requires two lines of code

Code: Select all

timer = require 'hump.timer'
versus complicated

Code: Select all

hump_timer = require 'hump.timer'
timer = hump_timer()
2. Methods versus library functions:

Code: Select all

timer.update(dt)
versus complicated

Code: Select all

timer:update(dt)
Sorry for my english and lua. Please, correct my mistakes!
User avatar
vrld
Party member
Posts: 917
Joined: Sun Apr 04, 2010 9:14 pm
Location: Germany
Contact:

Re: HUMP - yet another set of helpers

Post by vrld »

You convinced me. :D

You can now create individual timers:

Code: Select all

local Timer = require 'hump.timer'
function love.load()
    foo = Timer.new()
    bar = Timer()
    foo:addPeriodic(5, function()
        print('foo')
        bar:add(1, function() print('bar') end)
    end)
end
function love.update(dt)
    foo:update(dt)
    bar:update(dt/2)
end
For the sake of simplicity, there is a global/default timer, which you can access just like before, i.e.

Code: Select all

Timer.add(1, function() print('baz') end
Note that timer objects use the : syntax, while the default timer uses the . as before.
I have come here to chew bubblegum and kick ass... and I'm all out of bubblegum.

hump | HC | SUIT | moonshine
User avatar
mofr
Prole
Posts: 8
Joined: Thu Apr 26, 2012 11:04 am
Contact:

Re: HUMP - yet another set of helpers

Post by mofr »

Many thanks, vrld!
Default/global timer is very good idea. Backward compatibility and simple interface are preserved.
Sorry for my english and lua. Please, correct my mistakes!
summered
Prole
Posts: 1
Joined: Tue May 08, 2012 10:44 pm
Contact:

Re: HUMP - yet another set of helpers

Post by summered »

I'm now using the gamestate lib, and it is amazingly simple to use.

Thanks a lot for building and releasing it. :awesome:
Post Reply

Who is online

Users browsing this forum: No registered users and 193 guests