## Simulation language ideas?

Hi,

I am piecing together a scripting language for gaming applications(something that will help in adding details on top of a "core" existing game structure: ways to add tutorial messages, particle effects, tween HUD elements in and out...) and keep coming back to a particular model that I've seen in a few game scripting environments over the years: Bringing an explicit timeline into the language, so that lines of code represent events in a frame of simulation, rather than a computation that can happen at "any" time.

The advantages of this model are easy to see: rather than maintaining the bookkeeping of a tiresome bundle of timers and event callbacks, the language becomes a descriptive storyboard for various actions. Both one-shots and tweened parameters(fades, bounces, etc.) can be defined beautifully in this way.

What I'm struggling with - and have been struggling with for the past few days - isn't really this aspect of it, but how to implement it in a beautiful, powerful way within a game engine. Crude approaches that only let the language trigger externally coded events are limiting; I considered an approach with a set of named "channels" that could aid in grouping, starting, and stopping timeline scripts in a concurrent fashion, which added some reflective behavior, but this gradually led me towards bolting on a computational type system(including numbers, strings, lists, hashes) that could encompass the capabilities of the channel groups.

In trying to add a type system, memory management reared its head; e.g., when one timeline instance ends, how should I destroy the variables it was using - given that there could be circular references? Garbage collection then comes into play as a possibility, and by this point I was getting way too complex to feel comfortable with the implementation. Ideally it should be possible to serialize the whole game state and recall it at any time; with such a large system the task becomes dire.

The approach I'm starting on now returns to looking what the game engine is already doing for a domain model. It's an incomplete thought but I figured it might make good discussion:

The state of the art currently is to use relatively lightweight entities and hook components to them. The components can "live" primarily in their own domain and exploit custom data structures, memory coherency, etc. The entity, meanwhile, only has to know which components/component instances it has. (in my own engine, I apply an id value that lives on both the components and the entity, hence lookups can be done from anything to anything on the same entity.)

My current thought is to start building the language around access to the entity and component model, making the timeline scripts another kind of component, one where awareness of the other components is built in, and the access methods to traverse the graph of world state(looking up collision boundaries, searching indexes of actors or objects, etc.) are available, but computation in the traditional sense is limited. But I draw a blank once I start thinking of the details of how this system might work. My intuition says that computation is a secondary need since the host language can do it, but I find it really hard to break away and get new ideas.

## Comment viewing options

### Examples

Do you have any simple (toy) examples of what you are thinking of? Part of what you are describing sounds like a real-time language (ie constructs for time constraints / delays) but other parts sound more like the synchronous channels of Occam (which included a channel for time). I've seen some interesting work in the cross-over between the two but I don't think any of it has been published.

### I second this...

I like the idea too, but you really need to give examples.

### Some References

Discrete Event Calculus

Dedalus - Datalog (logic programming) with events at discrete time, space.

Physics-inspired Programming Abstractions

These might not be what you're aiming for, but they are likely to give you 'ideas', which is what you're asking for.

### Look at Impromptu

This sounds similar to what is done in Impromptu, a Scheme language environment for sound composition. From the website:

Time plays a major role in the Impromptu environment allowing accurate real-time scheduling of events and code. Impromptu is a dynamic environment designed for the creation and manipulation of running programs in live performance.

Check out the FAQ (accessible from the Resources link) as it has many examples.

When I had hacked up a mini language for testing my media server logic, I just added a "@ time command" construct, where time could be absolute (from start of the test) or relative (to the previous or parent event). Both could be used in a subroutine (or script). Using a small number of routines I could fire off hundreds of "media players" to stress the server.

Or you can abstract out timing events in some sort of time streams and just provide a triggering mechanism: "when event-occurs do-something..."