Toggle between fast mode vs. visualisation mode in Love.

General discussion about LÖVE, Lua, game development, puns, and unicorns.
Post Reply
ctf20
Prole
Posts: 1
Joined: Thu Aug 28, 2014 9:48 pm

Toggle between fast mode vs. visualisation mode in Love.

Post by ctf20 »

Dear All,

I am using Lua Love to visualise a game. I am evolving agents to play the game, and since this is a long process where speed of simulation is essential for most of the time I want love.update to run without the overhead of visualisation. I want this to run very fast for 1000s of games but only when I press a button do I want the visualisation to start so I can check how well evolution is progressing.

How can I toggle between 'fast mode' and slow visualisation mode using a key press in Love? How can visualisation be switched off for 'fast mode'?

Thanks in Advance,
Chrisantha
User avatar
DaedalusYoung
Party member
Posts: 407
Joined: Sun Jul 14, 2013 8:04 pm

Re: Toggle between fast mode vs. visualisation mode in Love.

Post by DaedalusYoung »

Turn off vsync using love.window.setMode and then set the value of dt back to something like 0.016 or even 1. And disable the love.draw function while in fast-forward mode.

So for example, something like this:

Code: Select all

local fastforward = false

function love.update(dt)
    if fastforward then
        dt = 1
    end
    -- do calculations here * dt
end

function love.draw()
    if not fastforward then
        -- draw your stuff  here
    end
end

function love.keypressed(key, repeat)
    if key == "f" then
        local w, h, flag = love.window.getMode()
        flag.vsync = not flag.vsync
        fastforward = not fastforward
        love.window.setMode(w, h, flag)
    end
end
Which is completely untested.
User avatar
Robin
The Omniscient
Posts: 6506
Joined: Fri Feb 20, 2009 4:29 pm
Location: The Netherlands
Contact:

Re: Toggle between fast mode vs. visualisation mode in Love.

Post by Robin »

DaedalusYoung wrote:set the value of dt back to something like 0.016 or even 1.
That may or may not be a good idea, depending on what you want to do in love.update: some simulations lose accuracy when given too large a time-step.

Also, watch out with the vsync thing: if it is initially disabled, it will be activated at the wrong time.
Help us help you: attach a .love.
User avatar
lorinc
Prole
Posts: 1
Joined: Wed Jun 27, 2018 11:05 am

Re: Toggle between fast mode vs. visualisation mode in Love.

Post by lorinc »

Hello,

I'm having a related question.

I write a game where you build entities whose behavior is based on simple neural networks. Think of a handful of neurons per bot, not much more. The neurons behave like agents, and the controlled bots as well.

I'd like to show the player the living network, that is, the charge of each neurons at any moment, and also the firings.

My question is - what love2d mechanics do I use to draw the neurons?

- ParticleSystem: Is it even possible to do it with this?
- newArrayImage: Create sprites and display the state with those?
- Shaders: is it efficient to pass the unique parameters of each neuron to a shader?
- other idea?

Thanks,
Lorinc
Post Reply

Who is online

Users browsing this forum: Google [Bot] and 41 guests