Separate state files

General discussion about LÖVE, Lua, game development, puns, and unicorns.
User avatar
s-ol
Party member
Posts: 1077
Joined: Mon Sep 15, 2014 7:41 pm
Location: Cologne, Germany
Contact:

Re: Separate state files

Post by s-ol »

airstruck wrote: Wed Feb 22, 2017 8:33 am
s-ol wrote:i have my own on github too but I think you really dont need it.
The thing I like about your solution is the ability to propagate some callbacks upward (drawing) and others downward (input). I'm not sure how the others handle that. If you don't have a lot of layers of stuff, though, maybe just a floating pause menu or something, you don't really even need a stack, you can just have your pause state hold a reference to the game state and have it draw your game state before it draws itself. If you don't need a stack, you probably don't really need a library either. Should be easy enough to have something like "game.activeState" and set that to whatever state instance you want.
Yeah, with a stack a library is starting to make sense. I think most libraries are not meant to handle multiple states at once, even on a stack (which is why i called st8 'double stacked'), but afaik jasocos does. His explanations of what he did sort of inspired st8.lua, and I bet he had the problem of up/down ordering too.

a different way to solve it that I somehow only just realized would be to do it with a node-style callback argument:

Code: Select all

OverlayingMenu:update(propagate, dt)
  -- update menu
   propagate(0.1 * dt) -- slow down underlying state
end

OverlayingMenu:draw(propagate)
  propagate() -- draw underlying state first
  -- draw menu
end

OverlayingMenu:keypressed(propagate, key)
  if key == "up" then
   ...
  else
    propagate(key) -- pass remaining keys on
  end
end
a benefit is that you can do things before and after, and operate on the results of the functions too:

Code: Select all

OverlayingMenu:draw(propagate)
  lg.setCanvas(canvas)
  propagate() -- lower state needs to care for the current canvas of course
  lg.setCanvas()
  lg.setColor(255, 255, 255, 100)
  lg.draw(canvas)
end

s-ol.nu /blog  -  p.s-ol.be /st8.lua  -  g.s-ol.be /gtglg /curcur

Code: Select all

print( type(love) )
if false then
  baby:hurt(me)
end
User avatar
Positive07
Party member
Posts: 1014
Joined: Sun Aug 12, 2012 4:34 pm
Location: Argentina

Re: Separate state files

Post by Positive07 »

Yeah, the propagate is a good idea and I think I'll probably implement it in ScreenManager (I hold a fork and have contributed to rm-code repository)

Currently ScreenManager goes upward for drawing, downwards for some input and only to the top of the stack on the rest, so It's really unpredictable where it will go next
for i, person in ipairs(everybody) do
[tab]if not person.obey then person:setObey(true) end
end
love.system.openURL(github.com/pablomayobre)
Post Reply

Who is online

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