How to do a lot simpler version of UT kismet (C++ and Lua)
I know this is a non trivial question, but I have spent last week thinking about how to do this, and I can't fidn a good way.
Mainly I have a 2D level editor. I can put entities in the world, add tiles, collisions, etc... What I want is to be able to script 开发者_开发问答easy things visually. For example if I have a lever and a door, I want to select the level select its "onactivate" event and link it to the "close" action of the door.
The editor loads a xml with the possible entities, and what actions each publishes, in the case of the lever (activate/deactivate) and the door (open/close).
Now the difficult part. I need to translate this into running code. I have thought about some solutions but all seems awkard to me. For eample, for the lever/door event I could autogenerate code in a lua function with name Lever1_onactivate_Door1_open() that will register a LuaListener in the Lever1 instance listener cue foro the onactivate event (in C++), and let it be called later, when the onEnter for the trigger is triggered.
Could anyone explain how ussually this kind of things are done? One of my probs is that I want to integrate this into my event system as I exposed, to have an orthogonal arquitecture.
Thanks in advance, Maleira.
In games like Doom, this is approximately done as follows: when pressing the Use key [func: P_UseLines], the nearest wall that it would apply to is searched for [func: P_UseTraverse] and, provided you are in range and have the right angle of turn, calls an action (called "special") associated with the line in [func: P_ActivateLine], which essentially maps it to a preexisting function in the end.
In other words, a simple lookup in a function pointer array:
/* Premise */
struct line_t {
...
int special;
...
};
struct line_t *line = activation_line;
/* Function call from p_spec.cpp */
LineSpecials[line->special](line, ...);
LineSpecials
would be an array of function pointers:
int LS_Door_Open(struct line_t *, ...)
{
...
}
typedef int (*lnSpecFunc)(struct line_t *, ...);
lnSpecFunc LineSpecials[256] = {
...
/* 13 */ LS_Door_Open,
...
};
精彩评论