Saturday, September 27, 2008

Script Engine Component System (SECS)

What is a script engine?
Currently I see people define a script engine very simply as: The thing that runs the scripts.
This is a narrow definition that I never intended with DotNetEngine (see previous posts).

Instead I would say the script engine is the most important component of OpenSim. I am a humble person when it comes to my own doing and do not see DotNetEngine as anything more than a script executor. The greatness lies in the potential and what other people will make if we can offer them some good interfaces.

Instead of giving this complex explanation that required several of your neurons to connect I will use examples:
  • Second Life LSL2 script support. Events and commands. Execution.
  • OSSL script support. Other events and other commands. Execution.
  • Additional command modules to for example give scripts SQL-access, Webservice acces, shared memory, etc.
  • A plant module that grows grass/trees randomly around the region
  • A bombterrain module that makes holes in the ground when bombs are detonated and fill them slowly back up over time.
  • NPCs
  • Bridges: Examples: "Contact us" module that allows sending of e-mail when someone drops a message in your region, IRC chat bridge, MSN chat bridge, etc.
  • Complete game systems that allows a single system to control some or all aspect of the region/grid. Multiple modules can be loaded simultaneously to cover all aspects (one covers NPCs, others covers inventory stuff, swords, lazer guns, etc etc).

This was the original idea behind DotNetEngine, and the reason for the design of inheriting only what you need from the engine. I do not want OpenSim to be limited to in-world scripting only.

SECS
So how can we support all this?

Note! This is work in progress!

I imagine in the future we will want to download a good NPC module and install it independently of what script engine we are running. Lets face it, if each module had to be adapted to a certain script engine then it would put some heavy restrictions on us.

Instead I propose we redefine what a script engine actually is, and allow it to co-exist with other script engines. We may not want to run DotNetEngine and xengine simultaneously, but we may want to run a whole bunch of other "engines" (game control systems, AI-bots, etc) along with a script engine. And while these systems are running they should be able to benefit from the services the script engine already offers such as event hookups (into OpenSim) and the scheduler - IF they want.

To achieve this I have been looking at different models, all with their advantages and disadvantages. Though I have not landed at a perfect model yet I am closing in.

Basically it is a loader. It loads modules (.dll). The modules are registered in a central location with a name (string). Some of these modules will be of well-known base types (event hookups, schedulers, etc). Because they are well-known base types an alternate module should be able to utilize it even though it wasn't made for that distinct type.

When a script engine is loaded it will create instances of whatever it needs to do its job. This is pretty much exactly how the script engines work today. The only exception is that we (probably) need to register the instances globally.

Any other modules that are started are now free to either instanciate what modules they need. Example of what they may load: OSSL commands, SQL commands. They can also access main script engine scheduler if they want to associate a custom class with a prim for example.

Note! This is work in progress!

DotNetEngine and xengine

The realization
Before my hands went bad I started the process of introducing a new common way of implementing script engines. This came from the realization of two things. First of all that many had difficulties understanding how to implement their own engine variations based on current engine, and second that not all developers are willing to conform to one structure.

Developers are (often) skilled people and often have a clear understanding of what is right. Structure and rules on how to do things are key elements to write good code. And with the complexity of modular programming languages there is more than one way to get things done 'right'.

DotNetEngine
The idea behind DotNetEngine was simple. We implement an engine consisting of a set of modules and a couple of classes to bind it all (main ScriptEngine and in-world ScriptLoader). Any new script engine could then inherit what it liked and ignore what it didn't like.

DotNetEngine was made from the assumption that users are hostile (or stupid). They will run too many scripts, script may be harmful to system, etc. It works with a set of queues that ensures equal priority for all scripts and will drop loading/execution if system resources is exhausted (if you don't have a fast enough CPU). It allows things like regions themselves and physics to go in front of script execution.

I felt this approach was correct for a generic engine as it would guarantee a smooth region execution.

xengine
xengine is for the most part the effort of Melanie. It is targeted towards gaming in the sense that scripts essentially will have dominance over resources.

With the introduction of xengine the DotNetEngine modular inheritance model was bypassed and most of DotNetEngine simply copied into xengine and made modifications to. This means that any patch needs to be applied to two places, which of course meant double work and ended in it not being done. This was especially bad for LSL implementation where steady progress has been over a long period of time and suddenly there were demands that new functions should be implemented only in xengine.

DotNetEngine vs xengine
There has been an ongoing conflict between the developers on how to solve this problem. On one side we have the newly formed xengine mob which feels that DotNetEngine is inferior, and on the other side we have those who cheer for DotNetEngine and a revamp.

I've personally chosen not to take part in this debate as I agree with Einstein (with a modification) - Politics lasts for about a month, code lasts forever. I have however seen a lot of false assumptions been spoken both about DotNetEngine and about my self and my intentions, as well as a few true ones. But I believe this is totally irrelevant. We have the power to fix anything, and frankly most of the ones pointed out in DotNetEngine are not that big. However I feel some sides in this case may have be pushing too strongly on the political side and not doing too enough the code side to solve the problem - and that is a WOMBAT. (Waste Of Money, Brains And Time)

SECS
Now back to this common structure I mentioned at the start of this post.
--- to be continued in next post ---

Absent

Hello... Is this thing still on?


Ok, its a while between each post. The amount of time I have varies.

Lately I've been disabled by some inevitable hand-hurting as a result from effort in another project I worked on. I'm also in the startup phase with a new company, so time is still not something I have an abundance of - but who does.


After a nice scenic vacation in north of Norway my hands are 70%-80% back to normal and here I am. :)