1. Hey! Guest! The 36th GMC Jam will take place between February 27th, 12:00 UTC - March 2nd, 12:00 UTC. Why not join in! Click here to find out more!
    Dismiss Notice
  2. NOTICE: We will be applying a Xenforo update on Tuesday 25th of February. This means that from approximately 10:00 to 14:00 BST the forums will be offline (or possibly longer). Sorry for the inconvenience! Official Announcement here.

Snapshot/Screenshot very slow

Discussion in 'Programming' started by MrOut, Feb 13, 2020.

  1. MrOut

    MrOut Member

    Joined:
    Jun 9, 2018
    Posts:
    8
    Hello,

    I try to implement a snapshot/screenshot button in my game but with the screen_save(fileName) function, this is very slow. I got a huge drop in FPS. Same with the 'Snapshot' option into an object.
    I notice also that screen_save put in the image file my Steam overlay (FPS counter and notifications for examples).
    I tried other games in my list made with Gamemaker (Hotline Miami and Gunpoint) and there is not this problem with Steam overlay, or FPS drop.

    I also try with surface_save(surfaceID, fileName) but I got the same result. This is too slow with a massive drop in FPS.

    If anyone as an idea, I'm all ears.

    Thanks in advance.
     
  2. Nocturne

    Nocturne Friendly Tyrant Forum Staff Admin

    Joined:
    Apr 13, 2016
    Posts:
    7,167
    There shouldn't be ay drop in FPS with these functions as long as it's only called once... Make sure you have it in a DOWN event and not a PRESSED event, so it's not taking screenshots every single step of the game that the key s pressed. As for the steam overlay, I haven't found this but then I haven't tested it either! Certainly it's not something I've had reports of for my own games on steam... I suspect it might depend on WHEN you call the save code so, if you could provide that information and the actual code you are using then that would be great.
     
  3. MrOut

    MrOut Member

    Joined:
    Jun 9, 2018
    Posts:
    8
    Thanks for your response.

    I call my code from a step event object dedicated to all Steam functionality (Achievements, Screenshots,etc...).

    So basicaly I have a obj_steam and in the step event i got this code:

    if (steam_is_screenshot_requested()){

    //SCREENSHOT
    screen_save("screenshot.png");

    //SEND SCREENSHOT TO STEAM
    steam_send_screenshot("screenshot.png", window_get_width(), window_get_height());
    }

    I will try with a down event ( I guess you mean released?).

    I also notice that when I use screen_save_part() and take only 500x500 pixels it's way faster.
     
  4. Nocturne

    Nocturne Friendly Tyrant Forum Staff Admin

    Joined:
    Apr 13, 2016
    Posts:
    7,167
    Okay, iirc, there is a bug with the function that means if you don't explicitly use "== true" then it runs all the time!!!! SO, make sure the code actually says:

    Code:
    if steam_is_screenshot_requested() == true
    Also, I usually call the screenshot functions in the Draw GUI End event. Here's an example of the code I use in all my Steam games if it's any help to you...:

    Code:
    var _scr = false;
    if steam_is_screenshot_requested() == true
        {
        log("Steam Screenshot Request"); // wrapper script for show_debug_message
        _scr = true;
        }
    if keyboard_check_pressed(vk_printscreen)
        {
        log("PrintScreen Screenshot Request");
        _scr = true;
        }
    if keyboard_check_direct(vk_printscreen)
        {
        log("PrintScreen Direct Screenshot Request");
        _scr = true;
        }
    if _scr
    {
    screen_save_part(file, 0, 0, window_get_width(), window_get_height());
    if steam_initialised()
            {
            steam_send_screenshot(file, window_get_width(), window_get_height());
            }
    }
    
    EDIT: Yup, there is a bug on Mantis about this: https://bugs.yoyogames.com/view.php?id=31230
     
  5. MrOut

    MrOut Member

    Joined:
    Jun 9, 2018
    Posts:
    8
    Thanks a lot.

    I put your code in a Draw GUI End event and it's way faster. But there is still some microseconds after the screenshot is taken where my game is freezing.
     
  6. Nocturne

    Nocturne Friendly Tyrant Forum Staff Admin

    Joined:
    Apr 13, 2016
    Posts:
    7,167
    I'm not sure there is much that you can do about this, tbh... GMS is not a multi-threaded app, and so saving an image file (especially if the image is fairly large) will require a tiny pause in the running of the game.
     
  7. MrOut

    MrOut Member

    Joined:
    Jun 9, 2018
    Posts:
    8
    This is probably nothing, but there is always a significent size differences between the screenshot taken by Gamemaker and the one send to the Steam folder.
     
  8. Nocturne

    Nocturne Friendly Tyrant Forum Staff Admin

    Joined:
    Apr 13, 2016
    Posts:
    7,167
    Interesting... I've never actually checked this, but I'd suspect it's something that the Steam API does to compress the image for uploading. Certainly, GMS does no such thing...
     
  9. MrOut

    MrOut Member

    Joined:
    Jun 9, 2018
    Posts:
    8
    With your code, but this was the case with mine too, if I took only a small part of the screen there is no delay.
    So this as definitely something to do with big resolution (in my case at least).

    The screenshots I took of Hotline Miami have the same size as my screen (2560*1440) so I guess they use a trick somewhere.
     
    Nocturne likes this.
  10. MrOut

    MrOut Member

    Joined:
    Jun 9, 2018
    Posts:
    8
    I made some changes to my textures pages, switching from 2048*2048 to 8192*8192. I have a massive gain of time on my screenshot delay now. This is still not perfect, but I maybe have a lead.

    I let you know if I make any progress.
     
    Nocturne likes this.

Share This Page