Forums » StepMania Development » Theme-defined Actor classes

1

It'd be nice to be able to register your own derived actor classes through lua. I've been using tables with metatables to define pseudo actor classes, but there is no way to apply the "derived class's" methods to the actor, they have to be applied to the table. A quick and dirty way would be to allow actor/userdata metatables to be set/changed, but a rigorous implementation would be more convenient and far less dangerous.

Is this worth attempting for SM5 or should it wait?
Reply
I don't think explicit engine-side support for theme-defined actor classes is really necessary. Someone advanced enough to need them and make good ones can already do it with only minor trouble.

In my theme, I have a bunch of what I guess you could call theme defined actor classes.
In general, a wrapper is a table of functions which is used as the metatable for an object. create_actors is a function that returns all the actors the wrapper will control. find_actors is a function the wrapper needs to get references to the actors after the screen has finished loading. I call the create_actors function when adding stuff to the screen's main ActorFrame, and the find_actors function during the screen's InitCommand. Everywhere that would normally access the actor and set something on it instead calls a function on the correct instance of the wrapper, and the wrapper takes care of setting the actor's stuff.

If you don't like that solution, you could try something like this:
local function make_actor_of_new_class(name, x, y, class_params)

local actor_vars= {}
return Def.ActorFrame{
InitCommand= cmd(xy, x, y),
FancyCommand=
function(self, params)
actor_vars.foo= params.foo
end
}
end
-- somewhere else on screen
fancy_actor:playcommand("Fancy", {foo= 5})

Unless I've made some dumb logic error in this untested code, each actor returned by make_actor_of_new_class will have its own actor_vars for FancyCommand to change. As long as your actor class "functions" don't need to return any values, this should work fine for anything you need to do.

So that's two ways that it's currently possible to make theme defined actor classes without changing the engine. The second one is only half functional, but probably usable.

I'm interested to know what other themers think though. Currently, I think you and me are the only ones to try to make theme defined actor classes.
< cybik> til Kyzentun fixes bugs for breakfast
--
< maxvg1> shakesoda: then why do i still play lol
<@shakesoda> because you're an ITG player. And thus, a masochist
--
<@shakesoda> Kyzentun: I think you might need to put down the meshes for a bit
Reply
I think Def.LogDisplay is an interesting example of a theme defined actor class.
It's all one-way communication, telling it to do stuff without a way to fetch information from it.
< cybik> til Kyzentun fixes bugs for breakfast
--
< maxvg1> shakesoda: then why do i still play lol
<@shakesoda> because you're an ITG player. And thus, a masochist
--
<@shakesoda> Kyzentun: I think you might need to put down the meshes for a bit
Reply