Author Topic: Possible to make a screensaver that cycles through games? (solved, sort of)  (Read 16654 times)

wrybread

  • Sr. Member
  • ****
  • Posts: 100
    • View Profile
I'd like to make a screensaver that cycles through games, as opposed to videos of games. And when a user presses a button, no need to exit the cycling, just stay in that game and let the user play it.

Would this be possible?

Any advice for a starting point?

Or maybe something already exists?
« Last Edit: May 01, 2018, 07:34:55 PM by wrybread »

keilmillerjr

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 1167
    • View Profile
Re: Possible to make a screensaver that cycles through games?
« Reply #1 on: April 03, 2018, 03:29:25 PM »
It’s doable with autohotkey scripting. However, it wouldn’t be an easy task. You would also have to save and load states past the boot screen of each game for it to seem presentable. A lot of work for a feature I’m not too sure would even make sense. Perhaps a time out script to return to attract, and then have attract time out and select a random game?

wrybread

  • Sr. Member
  • ****
  • Posts: 100
    • View Profile
Re: Possible to make a screensaver that cycles through games?
« Reply #2 on: April 03, 2018, 04:01:14 PM »
The feature makes lots of sense to me. My cabinet sits in my living room running mostly the same few games. Sometimes I launch a game using a random hotkey, but in general it's pretty consistent and it gets a little monotonous. Would be great to inject some automated variety. I'm thinking changing the game every 10 minutes or so, after an hour of inactivity, that kind of thing. And the reason I prefer it over videos is that if the game looks interesting to someone they can simply start playing it.

AHK isn't an option for me as I'm on Linux, but good idea.

I guess I could script something using Python, but I was hoping to use Attract Mode scripting natively for various reasons, including the ability to enable and disable it directly from AM.

> You would also have to save and load states past the boot screen of each game for it to seem presentable.

Not sure what you mean by that? But I use the -autosave MAME option anyway (aka "save state"), so I *think* things should be pretty smooth. Unless it gets caught on a MAME warning screen, which I still haven't figured out how to bypass. But I guess I could either send keystrokes just in case, or recompile MAME to skip it. But this isn't really an eye candy type screensaver, so it doesn't matter if there's a rough transition here and there.

Does anyone know if there's a way to remote control AM, short of sending keystrokes? Something like "start game", and "exit game", etc?
« Last Edit: April 04, 2018, 09:58:37 AM by wrybread »

wrybread

  • Sr. Member
  • ****
  • Posts: 100
    • View Profile
Re: Possible to make a screensaver that cycles through games?
« Reply #3 on: April 03, 2018, 06:17:37 PM »
Well shoot, it looks like the timer for screensaver.nut doesn't get reset when in a game, only when in Attract Mode. In other words it can't tell if someone is playing a game, only if there's activity in AM. Reasonable enough I guess, but it means that (I think) the screensaver I have in mind would need to be an external script.
« Last Edit: April 04, 2018, 09:57:05 AM by wrybread »

wrybread

  • Sr. Member
  • ****
  • Posts: 100
    • View Profile
Re: Possible to make a screensaver that cycles through games?
« Reply #4 on: April 04, 2018, 01:58:08 AM »
Interestingly, this exists as a program:

http://tomspeirs.com/mamescreensaver/

Won't work for me since it's Windows only, but interesting to note.

wrybread

  • Sr. Member
  • ****
  • Posts: 100
    • View Profile
Re: Possible to make a screensaver that cycles through games?
« Reply #5 on: April 04, 2018, 12:31:18 PM »
Well I made a Python script that works well and should work on every platform, but the problem is that it conflicts with Attract Mode.

My script launches ROMs directly, since I don't see a way to remote control Attract Mode. However, while playing the game Attract Mode is still listening reacting to keypresses.

The flow:

- Attract Mode is running

- timeout is reached (say, 5 minutes of no activity)

- for this example, lets say Ms. Pacman is highlighted in the Attract Mode Display

- the screensaver launches Dig Dug for example

- As I play Dig Dug, Attract Mode will still be reacting to my keystrokes.  On my system I use the same button to enter and exit a game, so when I exit out of Dig Dug in this example, Attract Mode will simultaneously launch Ms. Pacman. Not good. What *should* happen when the user presses Exit is that the user is returned to Attract Mode to select the next game manually.

It's confusing I know, so let me know if that isn't clear.

Can anyone see a way around this? A few general solutions occur to me, not that I have any idea how to achieve them:

- some way to launch the ROM through Attract Mode from an external script? I think that would be the ideal method, but I haven't figured out a way to do that. Maybe make Attract Mode listen for commands on a socket? Or make it check for the existence of a text file that it reads commands from? Maybe some clever plugin solution? Maybe via a web server?

- some way to tell Attract Mode not to listen for keypresses? (In my case joystick presses but same idea)

- maybe make Attract Mode reset it's screensaver timer even while a ROM is open? That would make it so the whole screensaver is run in Attract Mode directly.

- or?

My other problem is that if a ROM has a warning screen it will hang there, since MAME apparently ignores simulated keystrokes (so I can't just send a key after a pause to skip it if present) and there's no way to disable the warning screens (ugh). Edited: solved by recompiling with the nag screen turned off, let me know if anyone wants that build (MAME v0.175 for Ubuntu 64 bit). Could also solve that by using a list of ROMs that don't have warning screens.

And let me know if anyone would like to try my screensaver script. I'm using it on Linux but it *should* work on Windows and Mac since it just uses Python standard libraries.

« Last Edit: April 04, 2018, 03:45:12 PM by wrybread »

qqplayer

  • Sr. Member
  • ****
  • Posts: 301
    • View Profile
Re: Possible to make a screensaver that cycles through games?
« Reply #6 on: April 07, 2018, 06:46:41 AM »
Configure - Controls - Random Game   :)

If it is not what you want I was thinking on something like this:

http://forum.attractmode.org/index.php?topic=1185.msg8725#msg8725

Creating a function who press "random" buttoms like up , prev_page , next_letter....
« Last Edit: April 07, 2018, 06:55:14 AM by qqplayer »

wrybread

  • Sr. Member
  • ****
  • Posts: 100
    • View Profile
Re: Possible to make a screensaver that cycles through games?
« Reply #7 on: April 11, 2018, 07:58:50 PM »
> Configure - Controls - Random Game

I don't see how I can use that to automatically choose random games after a timeout?


qqplayer

  • Sr. Member
  • ****
  • Posts: 301
    • View Profile
Re: Possible to make a screensaver that cycles through games?
« Reply #8 on: April 12, 2018, 03:45:16 AM »
> Configure - Controls - Random Game

I don't see how I can use that to automatically choose random games after a timeout?

As simple as like I said , creating a "tick_time" function.
If you set:

> Configure - Controls - Random Game - KeyA

Then just create a function who presses "keyA" after a certain time.

Code: [Select]
random_game          A
Code: [Select]
local settings = {
   delay_timer = 0,
   play_delay = 10000
}

local random = fe.signal("random_game ");

function on_transition(ttype, var, transition_time) {
    if ( ttype == Transition.StartLayout || ttype == Transition.ToNewList || ttype == Transition.FromOldSelection ) {
        settings.delay_timer = fe.layout.time
    }
    return false
}

function on_tick(tick_time) {
   if ( tick_time - settings.delay_timer >= settings.play_delay ) random_game = true
}

fe.add_ticks_callback(this, "on_tick")
fe.add_transition_callback(this, "on_transition")

You have to create the function because my squirrel skills are "minimal" so look into those links:

http://forum.attractmode.org/index.php?topic=1185.msg8725#msg8725
http://forum.attractmode.org/index.php?topic=1826.0
http://forum.attractmode.org/index.php?topic=1236.0
https://github.com/mickelson/attract/issues/37
« Last Edit: April 12, 2018, 04:13:06 AM by qqplayer »

qqplayer

  • Sr. Member
  • ****
  • Posts: 301
    • View Profile
Re: Possible to make a screensaver that cycles through games?
« Reply #9 on: April 12, 2018, 04:11:31 AM »
So... I found a "solution" just download Kent79 AMGPS (Attract Mode Grid Pro System) v1.13

http://forum.attractmode.org/index.php?topic=1824.0

Layout.nut - line 502

Code: [Select]
            fe.signal( "random_game" );
As I said you have to create an standalone function for your purpose but I can confirm that this works , I´ve set:

Code: [Select]
param                rtime 10
An after every 10 seconds randomizes the selected game.

qqplayer

  • Sr. Member
  • ****
  • Posts: 301
    • View Profile
Re: Possible to make a screensaver that cycles through games?
« Reply #10 on: April 12, 2018, 04:41:03 AM »
Sorry for repost , but I get another option based on keilmillerjr timer.nut

http://forum.attractmode.org/index.php?topic=1826.0

Tested on Basic layout:

Edit layout.nut adding this line.

Code: [Select]
fe.do_nut("timer.nut")
Put the timer.nut file alongside the layout.nut

Code: [Select]
class UserConfig { </ label="Idle Timer ", help="The amount of time (in seconds) that if timer expired, go back to home menu", order=5 />  rtime=10;}
local my_config = fe.get_config();
local bgtime;
bgtime=abs(("0"+my_config["rtime"]).tointeger());
local  preview_counter =  fe.add_text( "", 1220 , 24 , 100, 25 );
//preview_counter.align = Align.Left;
//preview_counter.set_rgb( 255, 30, 30 );
//preview_counter.font = "archivonarrow-bolditalic";
local i=0;
local count = bgtime;
local user_interval = bgtime;
preview_counter.msg = count;
local previous_select = i;
local last_time = 0;
function saver_tick( stime )
{if ( previous_select != i) {
last_time = stime;
count = user_interval;
previous_select = i;
return;}
if ( stime - last_time > 1000) {
count--;
preview_counter.msg = count;
last_time = stime;}
if ( count <= 0 ) {
fe.signal( "random_game" );
}
}
function fade_transitions( ttype, var, ttime ) {
 switch ( ttype ) {
  case Transition.EndNavigation:
  case Transition.ToNewList:
      i++;
  break;
  }
 return false;
}
fe.add_ticks_callback( "saver_tick" );
fe.add_transition_callback( "fade_transitions" );

To set the time just mod this line:

Code: [Select]
rtime=10

wrybread

  • Sr. Member
  • ****
  • Posts: 100
    • View Profile
Re: Possible to make a screensaver that cycles through games?
« Reply #11 on: April 15, 2018, 05:16:53 PM »
I'll try this:

> fe.signal( "random_game" );

One problem though is that with a keystroke, when I press the "random game" key, it simply chooses a random game, highlighting it, but not entering it.

Another issue is that that will, I think, at best launch a random game after X timeout from Attract Mode, but not continue to launch games after more inactivity, since Attract Mode can't (I think) detect inactivity when in a game. In other words, it's "tick" function isn't triggered by presses when you're actually in a game.

At best this random game rotation would:

1- launch a game after X minutes of inactivity

2- continue listening for inactivity even while displaying the MAME game

3- launch another game after X minutes of inactivity

I think the fe.signal( "random_game" ) will only achieve step 1.



qqplayer

  • Sr. Member
  • ****
  • Posts: 301
    • View Profile
Re: Possible to make a screensaver that cycles through games?
« Reply #12 on: April 16, 2018, 08:11:43 AM »
I´m not on my pc but you can add "more" commands:

Code: [Select]
preview_counter.msg = count;
last_time = stime;}
if ( count <= 0 ) {
fe.signal( "next_letter" );
fe.signal( "down" );
fe.signal( "random_game" );
fe.signal( "select" );
}

qqplayer

  • Sr. Member
  • ****
  • Posts: 301
    • View Profile
Re: Possible to make a screensaver that cycles through games?
« Reply #13 on: April 16, 2018, 12:44:57 PM »

2- continue listening for inactivity even while displaying the MAME game


I think this only can be done using an autothotkey script or something like that I´m not sure if the f.e. can make this  :D

wrybread

  • Sr. Member
  • ****
  • Posts: 100
    • View Profile
Well with a whole lot of duct tape I got everything working. My cabinet swaps to a random game every 5 minutes if no one is playing it, which has officially gotten us out of our rut of playing the same few games over and over. And it makes our MAME cabinet a lot more interesting in general, since every time I walk past there's some new oddball artifact of the 80s or 90s playing on it. If you don't mind a heinous pun, it's a game changer (oof, sorry about that).

It would be so nice if this was natively possible in Attract Mode! Unfortunately I don't where to start for adding the functionality there though. If any AM devs are interested, I'm glad to help however I can though.


An outline of how I got it working:

- I made an Attract Mode screensaver.nut that simply launches my Python script after X minutes of inactivity

- my Python script then launches a new game after every 5 minutes (configurable) of inactivity, and is smart enough to reset it's inactivity counter even during game play (something that Attract Mode currently can't do, as far as I can tell). So it keeps launching random games whenever no one is using the cabinet. And someone can start playing that game any time. But if someone presses the exit button, they're returned to Attract Mode so they can choose specific games manually.

- and the cycle repeats: Attract Mode will then relaunch my script after X minutes of inactivity.


A couple of nice features:

- the script starts either via a screensaver.nut after X minutes, or manually via a "Random" button on my cabinet (the Random button executes an AM plugin that launches the script)

- currently it picks a random ROM from the roms directory, but it could easily be adapted to choose a random entry from a specific Attract Mode romlist.

- it detects when a ROM doesn't launch properly and adds it to a list of bad ROMs that it won't use in the future. Also handy for finding and fixing bad ROMs.

- the script can run independently of Attract Mode, but it's nice to also give the user the ability to choose their own games manually, which Attract Mode does so beautifully. So the user is returned to Attract Mode when they press the Exit button on the cabinet.

- it works with my ServoStik to change the joystick between 4 and 8 way as needed



The duct tape part:

- when my Python script launches it has to kill Attract Mode, or AM will keep responding to keystokes in the background. That's a big issue since for example when exiting a game from my script AM will simultaneously launch a game, which is a pretty big conflict. Solved by simply killing AM.

- when my Python script exits, it then relaunches Attract Mode, so the player can manually choose games again.


I'm glad to share it if there's interest, but I made it for Linux so I'd have to make a few mods if someone wanted to use it on Windows.

And if any Attract Mode devs have interest in implementing this natively in AM, I'd be glad to help. I think this is what would be required:

- have AM listen for keystrokes and/or joystick action while a ROM is playing. Possibly solvable by a secondary script that sends an activity notice to AM whenever there's activity (maybe by sending dummy keypresses to the AM interface?).

- or if AM was remote controllable, an external script could simply tell Attract Mode to launch new games at will. For example if I could run "attract_mode_cli mame/dkong" or maybe send a command through a webserver or a network socket, then an external script could handle the screensaver part but still play nice with AM.

« Last Edit: May 01, 2018, 07:40:38 PM by wrybread »