Author Topic: A little performance boost for those using video snaps  (Read 853 times)

popoklo

  • Full Member
  • ***
  • Posts: 44
    • View Profile
A little performance boost for those using video snaps
« on: November 06, 2017, 09:01:06 AM »
OIOIOI!

i like to share a Workaround how to Change the Video snap to normal snap.
my Problem was:
Scrolling through games causes heavy loading of Video snaps one after another, on my Retro machine Computer this was unacceptable.
So i tried to delay Video artwork. the Problem seems to be that the videoartwork property

video.video_flags = 0;
video.video_flags = Vid.ImagesOnly | Vid.NoAudio;

will only update and Show effect after transitions. i couldnt make a timer in an on_tick callback and set the new Videoflags. the effect was random.

i didnt know how to force a Transition without doing a Signal, does anybody know?.

so i made a timer in on_tick callback, waiting (800ms) to the Point the Video should load.
when the timer Ends i set a boolian and give two sgnals:

fe.signal("up"); fe.signal("down");

this fires the Transition calllback. The Transition callback then checks the boolian und sets
video.video_flags = 0;
so the Video starts loading and playing.
the up and down Thing is to stay at the current game.

the nice Thing now is: no Video will load immediatly after a new game is selected. it waits 800 MS and then loads the Video.
much better Performance when Holding a key or pushing a key fast to go through games.

this is not needed if someone can tell me how to trigger a transition without navigating signals...


Code: [Select]

local TIMEIDLE = 0;
local IDLE = 0;
local TIME = 0;

local video = gamegrid_surface.add_artwork("snap", 0, 0, 240, 220);

video.video_flags = Vid.ImagesOnly | Vid.NoAudio;


fe.add_signal_handler( "on_signal" );
function on_signal( sig )
{

if ( fe.get_input_state("down") || fe.get_input_state("up") )   //if a key is pressed (navigating to another game) reset timer
{
TIMEIDLE = TIME; IDLE = 0;
        }

switch ( sig )
{
case "up":
{
                                .... here is the code i switch my frame to another game......

return true;
}
case "down":
{
                                .... here is the code i switch my frame to another game......
return true;
}
                }
   return false;
}


fe.add_ticks_callback( this, "on_tick" );

function on_tick( ttime )
{
       TIME = ttime;        //keep track of the global time since AM runs, is used in on_signal callback
if (!IDLE && (ttime - TIMEIDLE > 800))               //check if 800ms since any key was not pressed passed, then activate via fe.signal the transitioncallback, so the video will update its state after the 800ms
{
IDLE = 1;
fe.signal( "down" );fe.signal( "up" );
        }
}


fe.add_transition_callback("artwork_transition");

function artwork_transition( ttype, var, ttime )
{
if (IDLE)  video.video_flags = 0;
        else
if (!IDLE) video.video_flags = Vid.ImagesOnly | Vid.NoAudio;


  return false;
}

« Last Edit: November 10, 2017, 05:06:05 AM by popoklo »

8bitsdeep

  • Full Member
  • ***
  • Posts: 34
    • View Profile
Re: A little performance boost for those using video snaps
« Reply #1 on: November 06, 2017, 02:16:25 PM »
Nice work!  :)  But there's a simpler way to do this built into AM.

Just do this:
my_snap.trigger = Transition.EndNavigation;

This works well on large images too. Highly recommended to anyone making a layout with large assets.

popoklo

  • Full Member
  • ***
  • Posts: 44
    • View Profile
Re: A little performance boost for those using video snaps
« Reply #2 on: November 07, 2017, 05:54:26 AM »
ou nice one! dont know when Navigation activates. is there an example how to use it? when does it trigger? thanks!

calle81

  • Sr. Member
  • ****
  • Posts: 116
    • View Profile
Re: A little performance boost for those using video snaps
« Reply #3 on: November 07, 2017, 02:58:36 PM »
This could be really awesome. Especially on the raspberry pi even when using Transition.EndNavigation;. Would be great to get a custom snap delay. I tried to use your code snippet but failed. Can you explain what should be in ".... your normal up dowbn handling"

popoklo

  • Full Member
  • ***
  • Posts: 44
    • View Profile
Re: A little performance boost for those using video snaps
« Reply #4 on: November 10, 2017, 04:37:57 AM »
i updated the code. hope its more complete for u to read. see 1st post.
but its only used with my own Gridlayout. if ur using any other gridlayout it must be changed a bit i think.
i also try to use the standard Gridlayout from AM in the future. but i dont like the normal Grid handling.

8bitsdeep

  • Full Member
  • ***
  • Posts: 34
    • View Profile
Re: A little performance boost for those using video snaps
« Reply #5 on: November 11, 2017, 09:12:50 AM »
I just realized an easier way to do this with the delayed loading.

Code: [Select]
local last_nav = 0;
local gtime = 0;
local art_flag = false;

local video = fe.add_image( fe.get_art("snap"), 0, 0, 240, 220);  //Use add_image so the snap doesn't auto-update while navigating

fe.add_transition_callback( "my_transition" );
function my_transition( ttype, var, ttime )
{
if ( ttype == Transition.ToNewSelection )
{
last_nav = gtime;
art_flag = true;
}
}

fe.add_ticks_callback( this, "on_tick" );
function on_tick( ttime )
{
    gtime = ttime;
if (art_flag && (ttime - last_nav > 800))  //800ms delay
{
video.file_name = fe.get_art("snap");
art_flag = false;
}
}

Haven't tested this exact code but the same method worked great in my current layout.  :D

popoklo

  • Full Member
  • ***
  • Posts: 44
    • View Profile
Re: A little performance boost for those using video snaps
« Reply #6 on: November 11, 2017, 11:28:10 AM »

popoklo

  • Full Member
  • ***
  • Posts: 44
    • View Profile
Re: A little performance boost for those using video snaps
« Reply #7 on: November 12, 2017, 03:31:36 AM »
i had no luck with this method :(

BadFurDay

  • Full Member
  • ***
  • Posts: 69
    • View Profile
Re: A little performance boost for those using video snaps
« Reply #8 on: November 13, 2017, 02:14:41 PM »
i had no luck with this method :(

I'm trying to add this to Cosmo's Main Menu theme to try help with performance but it doesn't want to work for me either.

calle81

  • Sr. Member
  • ****
  • Posts: 116
    • View Profile
Re: A little performance boost for those using video snaps
« Reply #9 on: November 14, 2017, 09:26:53 AM »
This works great 8bit! I have one issue though. When adding preserve_aspect_ratio = true like below it only applies after i have jumped one item in the wheel, never on the initial video. Any ideas?

if ( my_config["videomode"] == "Center") {
local last_nav = 0;
local gtime = 0;
local art_flag = false;

local video = fe.add_image( fe.get_art("snap"),flx*0.035, fly*0.155, flw*0.65, flh*0.7 );  //Use add_image so the snap doesn't auto-update while navigating
video.preserve_aspect_ratio = true;
fe.add_transition_callback( "my_transition" );
function my_transition( ttype, var, ttime )
{
   if ( ttype == Transition.ToNewSelection )
   {
      last_nav = gtime;
      art_flag = true;
   }
}

fe.add_ticks_callback( this, "on_tick" );
function on_tick( ttime )
{
    gtime = ttime;
   if (art_flag && (ttime - last_nav > 800))  //800ms delay
   {
      video.file_name = fe.get_art("snap");
      art_flag = false;
      
   }
}

}
« Last Edit: November 14, 2017, 09:29:23 AM by calle81 »