Author Topic: Possible to delay starting an emulator? SOLVED  (Read 154 times)

j.e.f.f

  • Newbie
  • *
  • Posts: 7
    • View Profile
Possible to delay starting an emulator? SOLVED
« on: May 27, 2020, 03:46:26 AM »
I've noticed with a couple of emulators I'm using (Mednafen via RetroArch, for example) sometimes it takes a considerable amount of time to start, and the Attract interface just appears locked during that time.  I'd like to be able to fade down the interface before the initiating the emulator call to provide a little bit of feedback that something is happening instead of it looking like Attract has frozen

So far I have code that looks like this:

Code: [Select]
function drawVeil() {
log("Drawing veil");
local veil = fe.add_image("veil.jpg", 0, 0, SCREEN_WIDTH, SCREEN_HEIGHT);
veil.alpha = 0;

//fade in animation
local fadeInVeil = {
when = Transition.ToGame,
property = "alpha",
start = 0,
end = 255,
time = L_CONF.TRANSITION_VEIL_FADE_ANIM_DURATION,
onStart = function(anim) {
log("fading in veil");
}
}

//fade in animation
local fadeOutVeil = {
when = Transition.FromGame,
property = "alpha",
start = 255,
end = 0,
time = L_CONF.TRANSITION_VEIL_FADE_ANIM_DURATION
}

animation.add( PropertyAnimation(veil, fadeInVeil) );
animation.add( PropertyAnimation(veil, fadeOutVeil) );

function toFromGameTransition( ttype, var, transition_time )
{
switch(ttype) {
case Transition.ToGame:
log("ttime " + transition_time);
break;
}
}
fe.add_transition_callback("toFromGameTransition");

}

The problem is that the hand off to the emulator happens immediately before the fade in can happen.  I have a Transition callback in place, and I was hoping I could add something in there to delay the hand off in order to give the UI enough time to update (i.e. complete fading in the veil).

1) I can't figure out what the function call is to create a timer in squirrel.  I'm looking for the equivalent of javascript's setTimeout function.
2) How do I first cancel the handoff, then reinitiate it after the timer fires?
3) Is there a better approach to achieve what I'm after?

All help is appreciated.

Thanks!
 - Jeff
« Last Edit: May 27, 2020, 10:44:04 AM by j.e.f.f »

sickle

  • Full Member
  • ***
  • Posts: 63
    • View Profile
Re: Possible to delay starting an emulator?
« Reply #1 on: May 27, 2020, 10:12:20 AM »
I tried doing exactly what you're doing last week, and I think the problem is that a layout can't control it, though something that works on a higher level can, such as plugins


try using keilmillerjr's fade to game plugin
https://github.com/keilmillerjr/fadetogame-plugin

it adds a fade to black every time you select a game, and a fade from black when you return from a game
« Last Edit: May 27, 2020, 10:17:56 AM by sickle »

j.e.f.f

  • Newbie
  • *
  • Posts: 7
    • View Profile
Re: Possible to delay starting an emulator?
« Reply #2 on: May 27, 2020, 10:43:34 AM »
Thanks for this plugin tip!

I managed to get it t work anyway... the trick was I couldn't get the animation to work during the  ToGame transition.  So I explicitly used the ToGame transition call back to manually set an alpha value to my veil object,  Code looks like this:

Code: [Select]
function drawVeil() {
log("Drawing veil");
local veil = fe.add_image("veil.jpg", 0, 0, SCREEN_WIDTH, SCREEN_HEIGHT);
veil.alpha = 0;

//fade in animation - not used. Explicitly set alpha during ToGame transition instead.
local fadeInVeil = {
property = "alpha",
start = 0,
end = 255,
time = L_CONF.TRANSITION_VEIL_FADE_ANIM_DURATION,
onStart = function(anim) {
log("fading in veil");
}
}

//fade in animation
local fadeOutVeil = {
when = Transition.FromGame,
property = "alpha",
start = 255,
end = 0,
delay = L_CONF.TRANSITION_RETURN_FROM_GAME_VEIL_FADE_ANIM_DELAY,
time = L_CONF.TRANSITION_VEIL_FADE_ANIM_DURATION
}
animation.add( PropertyAnimation(veil, fadeOutVeil) );

function toFromGameTransition( ttype, var, transition_time )
{
switch(ttype) {
case Transition.ToGame:
if(transition_time < L_CONF.TRANSITION_VEIL_FADE_ANIM_DURATION) {
local newAlpha = floor( ((transition_time * 1.0) / (L_CONF.TRANSITION_VEIL_FADE_ANIM_DURATION * 1.0)) * 255);
veil.alpha = newAlpha;
} else if (transition_time >= L_CONF.TRANSITION_VEIL_FADE_ANIM_DURATION) {
return false;
}
return true;
break;
}
}
fe.add_transition_callback("toFromGameTransition");

}

The callback works such that it won't do the default action if the callback returns true.  When that happens, the callback is called again, and will be repeatedly called while it returns true.  Kind of like an impromptu tick event handler.  So basically I adjust the value of the veil's opacity until the time is reached, then I return false, and the game loads.

For the return trip, the animation works just fine, as control has been passed back completely to the layout by the time I run the fade in.  I put a bit of a delay in the fade back in because the fade in actually happens a bit too quickly.

Mission accomplished, but I still haven't figured out squirrel's equivalent to JavaScript's setTimeout function  :P