A game language would benefit greatly from a state based mechanic, such as delegates. Basically these are objects whose classes can be changed at runtime.
A light example:
delegate light
- void toggle()
- boolean status()
state on:light
- void toggle()
state off
- boolean status()
return true
state off:light
- void toggle()
state on
- boolean status()
return false
I’m not entirely sure about the syntax for changing states, it could either be setting a certain property, a method call or a keyword call as shown. Either way, this is quite cool.
I’m also not sure about inheritance, can a delegate ’subclass’ another delegate? What about states?
Either way, states can’t add any extra methods or properties to the class.
Oh, and they are fast because all they do is replace the class, so this is a good way to multiple functions without if statements all the time.
My virtual machine is going to use a similar ‘constant pool’ to java and this can be linked dynamically or statically on load. Also I talk in the 2nd and 3rd person a lot… sorry. So with that in mind, this is the most recent question that I’ve asked myself.
We need a way of loading and unloading scripted bits of functionality faster than the complicated re-linking (or whatever I decide on) method. It would be very nice (ie I won’t settle for less) for this to be dynamic and automatically upkept. If a series of groups are written in such a way that reversing the order and unloading won’t change the offsets for any other part of the code base, this should happen automatically.
I think a good way to do this is for each class to have a stack of groups that have modified it, if the group that we are trying to unload is at the top of every stack of every class then we can unload it automatically. Also if we are the last group in the stack we should delete the class, but we need no instances of it in existance (may be hard for classes with static instances?).
I haven’t completely worked out the specifics yet (the class hierarchy will get in the way) but I think it will work.
Can two or more virtual machines share groups?
The chances and\or reasons for having two or more virtual machines is very rare, but then if I’m building it possible do I need to support this?
Reasons for having two virtual machines:
sandboxing? … but then they can’t talk to each other
different scripting for different parts of the program
… don’t need group overlap
So… making the virtual machine instanceable for oop niceness only, two virtual machines running at the same time maybe possible but not supported.
Previously I had a ‘group’ being a special xml file ending with .vgroup that details the dependancies and files that are a part of a group. The directory that has the same name of the group is automatically searched for voodoo files and those are added to the the group as well. I was thinking, this is overly complicated - the dependancy can be worked out from the files themselves and it’s not often that you want files from a group being in two different places.
So now a group is just a folder of voodoo files found in the default base folder. They can all be loaded and unloaded at the same time. Loading a single file encapsulates it in a group within the virtual machine.