embed external c++ class

Post your questions, suggestions and experiences regarding game design, integration of external libraries here. For irrEdit, irrXML and irrKlang, see the
ambiera forums
Post Reply
DallasFromFrance
Posts: 2
Joined: Mon Jan 07, 2008 9:48 am

embed external c++ class

Post by DallasFromFrance »

do anyone know (well maybe God truly exist in that case :twisted: ) if it's possible to embed new cpp classes, compiling it and so on "on the fly" ?

I'm French so excuse my *average ? poor ? choose for yourself* english, I'll try to explain a little more.

Imagine we are using something like a class, let's call it : modelClassA, controllerClassA, graphicalClassA (... a complete MVC view, but an answer for a single graphicalClass is like the Graal actually), and we use it into our main app to be shown.

Practically, is it possible to create children of the classA (complete MVC or graphical only) externally, let's say graphicalChildAClassA.h & .cpp, and integrate it while main app is running..?

For example, main app is a "persistent *persisting ? other word ?* world" (let's say a city), and I would like to add on the fly new models of cars (new children of the Car class). I've heard it's possible in Java, but indeed that's not my language of predilection (indeed it's a kind of... hate, so slow).

Thanks in advance for any help ("it is simply impossible" is considered as useful help... personaly with compiled code I don't see how this could work, I imagined a kind of XML full description of new caracteristics, but it's dead for specific methods I guess).

Regards !

PS : I was first thinking about it about "all-in-one app", extended on the fly and keeping modifications for the next launches, but maybe it could be easier (or possible) to make it via plug-ins...
CuteAlien
Admin
Posts: 9734
Joined: Mon Mar 06, 2006 2:25 pm
Location: Tübingen, Germany
Contact:

Post by CuteAlien »

The usual ways to do such stuff is either adding a plugin architecture or adding new modules with a scriptlanguage.

Compiling on the fly is certainly hard to do as you need a compiler for that. You could probably use gcc on linux systems, but on windows most user don't have a compiler installed.

But you can expect that anyone who adds modules will have a compiler and can use it himself. So just adding modules with a plugin-architecture should be fine. I recently found an article series for that which supports adding plugins as static and dynamic libraries and even works platform independent. Check here for the "Building Your Own Plugin Framework" articles: http://www.ddj.com/cpp/archives.jhtml

Another way is adding a script-interface to your code. A good script-interface might make it even easier to add features, as c++ is not such a nice language for high-level programming. Though you can even use c++ for scripting with interpreters like cint http://root.cern.ch/twiki/bin/view/ROOT/CINT. It's not supporting every c++ feature, but it will work for most classes.

If a script-interface is overkill you might also get away with adding a parameter set. Like using xml-files.
IRC: #irrlicht on irc.libera.chat
Code snippet repository: https://github.com/mzeilfelder/irr-playground-micha
Free racer made with Irrlicht: http://www.irrgheist.com/hcraftsource.htm
Dorth
Posts: 931
Joined: Sat May 26, 2007 11:03 pm

Post by Dorth »

You can't compile on the fly, unless you dig so very deep it's not even fun. But you can use JIT languages, like C# or Java, or better yet, pre-compile your stuff in dlls then dynamically switch from one to anothe on runtime ^^
DallasFromFrance
Posts: 2
Joined: Mon Jan 07, 2008 9:48 am

Thanks a lot

Post by DallasFromFrance »

the idea of platform independent libraries/plugins sounds great, while I'm on OS X and use to care about platform independence *-dency ? maybe* ;-) Thanks for the link, I'll explore this soon.

The scripting way, I would never have thought about that :-D But clearly it's a possibility to be evaluated, even if more useful in a middle or high-scale development, since the "preparative work" seems to be more important.

XML-like interfaces, I thought about that today (well, at this hour in France, yesterday), I don't think it's a good solution : quick, but I can't see enough flexibility (for specific methods for examples, they only could be a sequencialized set of predefined methods).

Well I'm starting my researches and hope I'll find time to create a prototype of such a system, and add some proto-features in an existing project.

To Dorth : your solution is related with plug-ins, and for the langages I'll be interested in when C# would be fully portable (some "adaptations" exist, but I don't remember any anouncement concerning C# platform independence), and for Java, well, I only see the bad in everything maybe, but now I'm wary of programs requiring virtual machines to run, it's "too nice to be true", I definitely prefer compiled languages, for the less we can control what's included and what's not, added to language quickness *hope it's the good woooooord :roll: *.

Time to sleep, have nice coming days people !
Dorth
Posts: 931
Joined: Sat May 26, 2007 11:03 pm

Post by Dorth »

... I was not suggesting that you used Java or C#. But I'm saying they both are JIT, aka Just In Time compilation, exactly what you asked for... personally, I say stick with c++ and do dlls/scripts for the rest...
Post Reply