hank wrote:The idea is that you would define a Lua function which computes the position of the object, given a specified time. Celestia would call this function when needed to determine the position of the object.
AHA! so it's embedded in Celestia's "event-loop". So the only code-change you'd make in Celestia core code is to add a hook within the event-loop to a function called something like "position_objects()". The question is: what is meant by "when needed". Would this be arbitrarily set to "every frame/cycle", or would you allow the LUA writer discetion to specify the required "granularity" in some way. eg. User may specify "re-calc positions every 1/25th of a second".
Secondly, if this option was allowed, would it be "for all objects" or able to be specified on an "object by object" basis. eg. Object 1 re-calculated very 1/10th sec, Object 2, every 1/25th second.
hank wrote:In principle, the Lua function could calculate the position of the object by any method that can be programmed in Lua. Of course, it needs to be fast in order to maintain Celestia's frame rate. But note that Lua can call C functions, so C code could be used for time critical parts of the position calculation.
I think the fly-in-the-ointment is implied in my comments above. As the number of "periodic objects" is increased by the user, the frame-rate's going to take a hammering due to the overhead of "position_objects()" calls. (it's not as though Celestia's not got enough to do in each cycle already).
I for example, would pretty soon have plenty of these periodic objects, not just one!
hank wrote:The .ssc file for an object with a "ScriptedOrbit" could specify a chunk of Lua code that would return a Lua object with a method for calculating the position of the object. The chunk of Lua code specified in the .ssc file could be a call to a library function that returns a particular kind of orbit based on its input parameters. The user could define various orbit library functions for this purpose, or install such functions (created by others) as add-ons.
I'm not sure if an SSC file is the right place for LUA code.
I think I would prefer not to see a departure from the declarative style of the SSC files, but I think this also implies a generalised and parameter driven "movement" function (perhaps written by an expert like yourself) which would be designed to be efficient, and to interpret the SSC declarations... eg:
Code: Select all
PeriodicMotion
{
... some attributes carefully thought out to allow generalised motion
... (optionally repeating after a pause period)
}
Tthis would almost certainly have less flexibilty than what you're suggesting, but would arguably be less open to "abuse".
hank wrote:This would be a very flexible means of creating customized orbits. Any kind of motion that can be programmed efficiently in Lua/C could be implemented. The only real limitation is the requirement that the position can be calculated quickly for any specified time.
The downside of providing so much flexibility is that invariably it will not always be programmed efficiently (the aforementioned "abuse".
)
Caveat Emptor, I guess.