Hi,
I'm working on my own engine at the moment that has a pretty similar structure to GCC and am currently fleshing out my scripting interface. My original design was (as mentioned in GCC3/4) to only use events to transfer information from my scripting languages to C++ and back.
One of the things I've implemented for my engine is a remote scripting/logging terminal. The engine listens to a socket and executes any incomming script commands that are sent from an external program (which can be on the same machine or over a network). This is incredidbly useful for inspecting the current state of the game and making modifications on the fly (it's also hooked up to my editor).
However, I frequently find that I want to query the underlying C++ code for information (eg. a list of all entities in the scene, or getting the entityId for an entity with the given name). Doing this the "correct" way would involve and writing a script -> C++ event to send the request for information, the C++ event handler to recieve the request and form a reply, then a C++ to Script event to respond with my information and an event hander in script code to recieve that event and then continue with whatever it was I was doing. Creating new custom events isn't too bad, because I've got some useful factories to generate generic events without having to write the whole class each time. My main frustration is having to break my program flow.
If I break the rules and directly exposed my C++ EntityManager functions to script I could do this:
Yes, I know it's python, but my engine has a modular scripting system, so I can switch out scripting languages with relative ease. Learning lua is one of my goals for this project.
However if I went along the events approach it would end up being something more like this:
Display All
Obviously I could optimize this by adding a "getEntityComponentsFromEntityName" event, but it still requires me to wait for a response event before processing the result. It also doesn't make querying the scene for information via the interactive terminal very easy.
For the moment I have a few exposed functions in a few modules to allow direct calls which return data immediately. My plan is for them to just be for debugging and disable them at a later date, but I'm afraid they're going to prove too tempting to ignore in production code. So I'm just wondering what other people prefer to use to query the C++ layer for information from script?
I'm working on my own engine at the moment that has a pretty similar structure to GCC and am currently fleshing out my scripting interface. My original design was (as mentioned in GCC3/4) to only use events to transfer information from my scripting languages to C++ and back.
One of the things I've implemented for my engine is a remote scripting/logging terminal. The engine listens to a socket and executes any incomming script commands that are sent from an external program (which can be on the same machine or over a network). This is incredidbly useful for inspecting the current state of the game and making modifications on the fly (it's also hooked up to my editor).
However, I frequently find that I want to query the underlying C++ code for information (eg. a list of all entities in the scene, or getting the entityId for an entity with the given name). Doing this the "correct" way would involve and writing a script -> C++ event to send the request for information, the C++ event handler to recieve the request and form a reply, then a C++ to Script event to respond with my information and an event hander in script code to recieve that event and then continue with whatever it was I was doing. Creating new custom events isn't too bad, because I've got some useful factories to generate generic events without having to write the whole class each time. My main frustration is having to break my program flow.
If I break the rules and directly exposed my C++ EntityManager functions to script I could do this:
Yes, I know it's python, but my engine has a modular scripting system, so I can switch out scripting languages with relative ease. Learning lua is one of my goals for this project.
Python Source Code
- def getEntityComponents(entityName):
- # Get the entity ID from C++ EntityManager class
- entityId = EntityManager.getEntityIdFromName(entityName)
- if entityId is None:
- return
- # Print the names of the components attached to this entity
- componentNames = EntityManager.getEntityComponents(entityId)
- for componentName in componentNames:
- print componentName
However if I went along the events approach it would end up being something more like this:
Python Source Code
- def init():
- EventManager.setupEventListener('response_getEntityId', onGetEntityId)
- EventManager.setupEventListener('response_getEntityComponents', onGetEntityComponents)
- def getEntityComponents(entityName):
- # Queue a request for the entity ID from the name
- EventManager.QueueEvent('getEntityId', entityName)
- def onGetEntityId(entityId=None):
- if entityId is None:
- return
- # Print the names of the components attached to this entity
- EventManager.QueueEvent('getEntityComponents', entityId)
- def onGetEntityComponents(componentNames=[]):
- for componentName in componentNames:
- print componentName
Obviously I could optimize this by adding a "getEntityComponentsFromEntityName" event, but it still requires me to wait for a response event before processing the result. It also doesn't make querying the scene for information via the interactive terminal very easy.
For the moment I have a few exposed functions in a few modules to allow direct calls which return data immediately. My plan is for them to just be for debugging and disable them at a later date, but I'm afraid they're going to prove too tempting to ignore in production code. So I'm just wondering what other people prefer to use to query the C++ layer for information from script?