Advertisement

Dynamic function creation???

Started by August 12, 2000 01:47 PM
2 comments, last by Enix 24 years, 4 months ago
I was wondering whether or not it is possible to dynamically create a function based on a simple little game script. Is is possible for a game to read in a simplistic script, allocate some memory, and then make that memory into a function that would do what the script wanted, and then call this dynamic function? To me, this sounds possible, but then I ask myself, if this was possible, why did quake3 scripts run slower than .DLLs? If functions could be dynamically created, the quake3 scripts should not have be that much slower becase it would be possible to convert them to native code. So, basically im asking, is this possible, if so, how could this be accomplished and is there any web-site that could give me some information on how this could be done? Edited by - Enix on 8/12/00 1:51:56 PM
Well, maybe, but your game engine would have to include a compiler.
Advertisement
It's simple if you dynamically interpret it yes, it's just a switch statement. Like this:
        int interpret(char *instructions, int length){    int index;    for(index = 0; index < length; index++)    {        switch(instructions[index])        {        case INSTRUCTION_1:            {                // do the stuff            }break;        // check for other instructions    }    return(0);}        

Or you could compile the instructions into code and then write the address of the start of the instructions to the processor's input pipe. This is more difficult, I reccomend the interpreting option. You can also make one that runs in paralell with the event loop.

------------------------------
#pragma twice

Edited by - furby100 on August 12, 2000 3:32:22 PM
I just wanted to add that there could be some "subcases".
did i say could? there will be subcases!

cya,
Phil



Visit Rarebyte!
and no!, there are NO kangaroos in Austria (I got this questions a few times over in the states ;)
Visit Rarebyte! and no!, there are NO kangaroos in Austria (I got this question a few times over in the states ;) )

This topic is closed to new replies.

Advertisement