oakes / play-clj

A Clojure game library
The Unlicense
939 stars 73 forks source link

timer breaks on de-/focus after more than one call to `set-screen!` #90

Open nblumoe opened 8 years ago

nblumoe commented 8 years ago

Odd behavior with a timer:

  1. starting the app normally (CIDER Repl, calling (-main))
  2. the timer starts and works flawlessly
  3. defocus game window
  4. timer events not triggered anymore
  5. focus game window
  6. timer event triggered again

So I guess the timer is on hold when the window is not focused (guess one can hook into that via on-pause and on-resume). I do not necessarily consider this an issue so far. Maybe a bit weird, that the timer stops, but on-render keeps going...

Here is the real issue, continuing after step 6. from above:

  1. run (play-clj/on-gl (play-clj/set-screen! viking-village-vandalism-game main-screen ui-screen))
  2. the game window is defocused now (as I switched to the REPL)
  3. the screens are reset and start over again, the timer working normally
  4. focusing the game window again stops the timer
  5. defocusing the game window does not change anything, most importantly does not enable the timer again (12. GOTO 7. and everything repeats from there)

So, this really seems to be broken somehow. I am running this on Fedora 23, play-clj "1.0.0".

nblumoe commented 8 years ago

Here is the project I am encountering this issue.

adding timer: https://github.com/nblumoe/viking-village-vandalism/blob/7da07fd81c3aa566a799c03b7a6812069529324b//desktop/src-common/viking_village_vandalism/core.clj#L109 (this gets trigger on-show https://github.com/nblumoe/viking-village-vandalism/blob/7da07fd81c3aa566a799c03b7a6812069529324b//desktop/src-common/viking_village_vandalism/core.clj#L83)

on-timer handler: https://github.com/nblumoe/viking-village-vandalism/blob/7da07fd81c3aa566a799c03b7a6812069529324b//desktop/src-common/viking_village_vandalism/core.clj#L163 function call to reset the screens: https://github.com/nblumoe/viking-village-vandalism/blob/7da07fd81c3aa566a799c03b7a6812069529324b//desktop/src-common/viking_village_vandalism/core.clj#L265

oakes commented 8 years ago

Yeah there's a pretty long history of timer-related issues in libGDX. The particular issue you mentioned about its behavior when calling set-screen! is new to me, though. I'll look into it and see if we can do some kind of workaround, but since libGDX is a Java framework I imagine their design doesn't account for calling methods from a REPL =)

ul commented 8 years ago

Probably you can suggest any workaround? Just hit this issue too.

newhook commented 6 years ago

I hit this problem as well... after I click on the game window the timer stops firing :( I think its probably simplest just not to use the timer and count down from delta times.