Cross-platform plugin system?
Hi
I want my game to have some sort of plugin system. I want my users (and myself) to be able to add custom vehicles and weapons that do strange, complicated things with a minimal amount of fuss. This would probably involve writing some code, compiling it, then the main program loading it in and executing it as a function somehow. My question is how can I execute the code once it''s loaded into memory, and how can I get it to use the funtions in the main code? The game will be cross-platform and I''d like the plugin source code to work for every platform, so that eliminates all sorts of stuff like COM.
Cheers,
=> Arfa <=
=> Arfa <=
maybe CORBA would be intresting to look at.
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~I'm looking for work
Bit weighty for what I need. Just a simple dynamically-loaded plugin system is what I need. Did it once on the M68K, but that''s a hell of a lot easier than on the PC: Malloc some memory, load the plugin into it, throw a pointer to your function reference on register A7, then jmp to it. Oh, but that required the plugin to be written in ASM, and I want my plugins to be compiled C/C++.
=> Arfa <=
=> Arfa <=
=> Arfa <=
What exactly will you be compiling this code into? It is C/C++, so I assume you are going to be compiling it into a DLL or a library (like a .so in Linux for example). It was my understanding that you could see what sorts of things were in DLLs when you load them in. Couldn''t you just make a common interface for plugins, and have them register what they have? I mean, with a vehicle plug-in (DLL), you could go like:
/* pseudocode */
InitPlugin(vehicle.dll)
now that you have an object, do stuff with it.
I don''t know if this is at all what you want, but it seems that if you had a common interface for your plugins, you could just wing it and call virtually the same function to them to get them to init, and come "online" in your program. Like initPlugin(vehicle.dll) would do stuff similar to initPlugin(weapon.dll) or even initPlugin(sound.dll). Maybe I am wrong, but I hope this helps.
/* pseudocode */
InitPlugin(vehicle.dll)
now that you have an object, do stuff with it.
I don''t know if this is at all what you want, but it seems that if you had a common interface for your plugins, you could just wing it and call virtually the same function to them to get them to init, and come "online" in your program. Like initPlugin(vehicle.dll) would do stuff similar to initPlugin(weapon.dll) or even initPlugin(sound.dll). Maybe I am wrong, but I hope this helps.
There are 2 approaches to consider:
Build the plugins as shared libraries. You''ll have to compile a library for each platform you support (since almost every platform is not binary compatible), and at runtime, you''ll load a specific function by name and execute it. This method will require you to provide callbacks from your application to the shared library, so that the plugin can actually modify the world state. The drawbacks are that (a) you will need to recompile a shared lib for *every* platform you support and (b) if you make the plugin format available to developers, it''s very easy to make a trojan horse.
Build the plugins using a scripting langauge. There are plenty of languages/interpreters out there that can be embedded into an application: java-script, Python, Lua, Dylan, etc, etc. You can also write your own scripting language and interpreter if the others don''t satify your needs, but you will need to write the parser, the interpreter, the object format, and a debugger -- and this can be very time consuming! (You can start by picking up "Compilers" by Aho (the dragon book) and the O''Reilly book on "Lex+Yacc"). With a scriptable plugin, you write it once, and it will run on any platform with no binary changes.
As for adding support "strange, complicated things" -- the users have as much control as you give them. The better your callback API, the better plugins will be possible.
Build the plugins as shared libraries. You''ll have to compile a library for each platform you support (since almost every platform is not binary compatible), and at runtime, you''ll load a specific function by name and execute it. This method will require you to provide callbacks from your application to the shared library, so that the plugin can actually modify the world state. The drawbacks are that (a) you will need to recompile a shared lib for *every* platform you support and (b) if you make the plugin format available to developers, it''s very easy to make a trojan horse.
Build the plugins using a scripting langauge. There are plenty of languages/interpreters out there that can be embedded into an application: java-script, Python, Lua, Dylan, etc, etc. You can also write your own scripting language and interpreter if the others don''t satify your needs, but you will need to write the parser, the interpreter, the object format, and a debugger -- and this can be very time consuming! (You can start by picking up "Compilers" by Aho (the dragon book) and the O''Reilly book on "Lex+Yacc"). With a scriptable plugin, you write it once, and it will run on any platform with no binary changes.
As for adding support "strange, complicated things" -- the users have as much control as you give them. The better your callback API, the better plugins will be possible.
Matt Slot / Bitwise Operator / Ambrosia Software, Inc.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement
Recommended Tutorials
Advertisement