Cannot use the new setWindowSize() player command when switching from full screen to window mode

  • #1, by fulviovTuesday, 05. May 2015, 20:17 10 years ago
    I am trying to integrate the new 4.2 commands setWindowSize() and toggleWindowMode() into my game, but while they work ok individually, when I try to switch to window mode with a specified window size, the size command gets ignored.
    What I am doing is chaining the Lua calls, for example If I am fullscreen and I do:

    toggleWindowMode()
    setWindowSize({x=640,y=480})
    


    I would expect the game to go into window mode, with a 640x480 window size.
    What happens is that the player does go into widow mode, but the size command gets ignored.
    I suspect it is because the size command gets executed while the window is still resizing, but I cannot find a way to make it work with Lua "callback style".
    Any help would be really appreciated! smile

    Forum Fan

    119 Posts


  • #2, by afrlmeTuesday, 05. May 2015, 23:34 10 years ago
    Try adding a 16ms pause between the actions.

    example:

    1. create an execute a script action part containing...
    toggleWindowMode()
    

    2. create a pause action part & set to 1 or 16ms (doesn't really matter).

    3. finally create another execute a script action part containing...
    if not getWindowMode() then
     setWindowSize({ x = 800, y = 450} )
    end
    

    ... change window size, as needed.

    Imperator

    7285 Posts

  • #3, by fulviovWednesday, 06. May 2015, 01:27 10 years ago
    Thanks, but this doesn't seem to work.
    I have to use a very long pause (more than 1 second) to get the window size command to go trough.
    I think 1 second is more or less ok since you can barely notice the size change, but I am afraid this could be dependant on the speed of the computer running the application. (could still be too fast for slow computers, for example)

    Edit: Just tried a few more times and as suspected, 1 second works like 80% of the time, so it is definitely dependant on execution speed roll

    Forum Fan

    119 Posts

  • #4, by afrlmeWednesday, 06. May 2015, 02:06 10 years ago
    That's strange. Mac or Windows? I forget which OS you are running.

    On my windows machine it's almost instant. If I set a 1ms pause it's not actually 1ms, it's one system loop which is approx every 16ms, which works out at 60fps. (technically it's 16.666...ms, but pause only allows integer values).

    The most offset I get from the time taken per loop is usually only off by a few ms either way when I've tested by adding a print function containing a getTime() function inside of it to a script or an execute a script action part.

    * edit: just ran a test using the internal editor loop function using the jump to x action part & the pause action part set to 1ms along with a print() lua function. The fastest loop time was 2ms, the longest loop time was 48ms, the average loop time for most loops was 15 to 16ms. I tested 10 loops by wrapping it in a value & decrementing the value by 1 each loop until it reached 0.

    Anyway, I'm not really sure what else to say... I know on mac that it doesn't seem to store the last window mode size to memory during current game session but on windows it should remember the window size for current session - I think, but not 100% sure.

    Imperator

    7285 Posts

  • #5, by fulviovWednesday, 06. May 2015, 02:27 10 years ago
    I'm running on a Mac.
    I think ideally the toggle window command should get a parameter (like toggleWindowMode({ x = 800, y = 450}), for example) so that visionaire can set up the window with the proper size immediately :S

    Forum Fan

    119 Posts

  • #6, by afrlmeWednesday, 06. May 2015, 05:07 10 years ago
    toggleWindowMode() actually toggles between fullscreen & window mode depending on current mode. Either way it would be 2 functions even if it was rolled into one Lua function because they are separate parameters of SDL2 lib.

    The issue is most likely to do with your mac. I'll test my example on a mac the morrow & see what happens. The mac version of the engine / editor is still pretty raw, meaning it's buggy in comparison & probably not as optimized as windows version.

    Imperator

    7285 Posts

  • #7, by LebosteinWednesday, 06. May 2015, 07:57 10 years ago
    Why not setWindowMode(True/False) like the existend getWindowMode()?

    Key Killer

    621 Posts

  • #8, by afrlmeWednesday, 06. May 2015, 11:52 10 years ago
    getWindowMode() is also new. It just returns true or false depending on current window mode.

    Imperator

    7285 Posts

  • #9, by LebosteinWednesday, 06. May 2015, 16:52 10 years ago
    is it possible to activate the free resize function of the window from inside the game?

    Key Killer

    621 Posts

  • #10, by afrlmeWednesday, 06. May 2015, 17:06 10 years ago
    You mean the resizeable parameter that can be defined in the config.ini file? No that has to be set in the config.ini file.

    Also setWindowSize() will only work when windowed.

    I'm sure the window options will get better in time.

    Ok back to the other issue... I tested on mac earlier & ended up with mixed results.

    1. The first time I toggle from fullscreen to window it automatically sized the window to the available space of my screen.

    2. The second time it resized itself to the default game resolution.

    3. I tried using the same method I used for windows with the 16ms pause & it ended up resizing to default game resolution > flickering to defined window size > then back to default game resolution. If I used a pause value of about 1000ms then it seemed to update the window size to the size I specified.

    4. I ran the same system loop test as on windows to check loop times & it had an average of same as windows, between 15 & 16ms per loop with quickest time being 3ms & longest time being 16ms - however it printed into the log that it took approx 100ms+ for the toggleWindowMode() function to be executed, although I don't really think 100ms is all that bad really.

    My conclusion is that it's all probably just some osx related issue as it works perfectly fine on my windows laptop.

    Imperator

    7285 Posts

  • #11, by LebosteinWednesday, 06. May 2015, 17:57 10 years ago
    I have tested this. The problem is, the Mac needs more than one second to switch between fullscreen and windowed mode because there is a system animation (smooth zoom) for the size change of the window...

    It would useful to can set the resulting window size BEFORE switching... or this damn Apple window resize animation has to be turned off (in the player?) somehow...

    Key Killer

    621 Posts