[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: dynamically loading/unloading plugins (was: Re: Scripting)



Steve Baker wrote:

> Gregor Mueckl wrote:
> 
> 
>>>>But
>>>>with a new binary there also is the need to restart the game engine (or
>>>>engines in case you develop a networked game as I do). With a script you
>>>>might avoid this.
>>>>
>>>>
>>>OK - for the third or fourth time in this thread...
>>>
>>>
>>I've read it.
>>
> 
> So why are you still saying it's impossible?
> 


I'll come back to this further down.


> 
>>>So, you can actually edit and recompile parts of your program WHILE
>>>IT'S STILL RUNNING!!
>>>
>  
> 
>>This works only if you have C-ish interface between the module and the
>>core engine.
>>
> 
> That's not *entirely* true - but I don't think the interface between
> the core engine and a script interpreter would be likely to be any
> better.
> 


Sorry. I don't understand this sentence. Could you please paraphrase it?


> But none the less, what I said is true - you can edit and recompile
> "scripts" written in C or C++ without restarting the game - you may
> have to be kinda selective about how you call it - but that's a small
> price to pay if your only alternative is to resort to a really slow
> interpreter.
> 


Whether the price is small depends on one's point of view. My point was 
that you didn't explicitely restrict your statement in scope. You said 
"it works". I took it for "it works in all cases", which is a wrong 
thing to say. And I wanted to point that out.


> As I have already said, there are several other reasons to prefer
> an interpreted script - but hot-swappability isn't one of them.
> 
> 
>>But what if you pass on an instance of a class that's
>>implemented in the module on to the engine and loose track of it (you
>>would have to replace it, anyway)?
>>
> 
> Well, you could work around this if you wanted too.
> 


How?

I'll give you an example of a situation that (a) probably won't work and 
(b) is hard to avoid (IMHO):

The main engine defines some interface class (say, for an in-game-object):

class A {
   public:
     virtual void foo() = 0;
};

The plugin provides a derived class and a suitable create() function for 
such an object:

class B : public class A {
   public:
     virtual void foo()
     {
       // some code here
     }
}

B* create()
{
   return new B;
}

On calling create() the engine gets a poiner to this object, which it 
most likely merges somewhere into the scene graph and maybe into some 
other places as well, but by doing so it must loose the exact type 
information of this object as the exact type is only known by the 
plugin, along with the code for the function B::foo(), which is called 
by an indirect reference in the vtable of class B, that also resides 
within the plugin (and not within the object). So the situation is that 
(a) you can't reliably find the object and replace it and (b) would 
crash the engine after you reloaded the plugin while such an object is 
present because the pointer to the vtable the engine's instance of B 
carries becomes invalid and the next call to B::foo() will go into nowhere.

Even if you solve the first problem, you will still have to find all 
pointers to this object everywhere in your engine and you will have to 
replace them with pointers to an instance of the updated class, which 
preferably gets a state on its creation that is in sync with the rest of 
the game world.

I don't know how you can solve all this. If it can be done at all (which 
I doubt), it can't be done without a ton of code and performance losses 
due to management overhead (both of which hamper the game engine).

I might be missing something very important, but I don't see what it is. 

Therefore I'm pretty much convinced of my own point of view.


 >

>>Answer above question first, please.
>>
> 
> Sorry - I don't understand which question I didn't answer.
> 


My fault - sorry. I wanted to say "please think about my question above 
(in the same email) and then take a look at your answer and decide, 
whether it is still true".



-- 
*****************************************************
* Gregor Mueckl                 GregorMueckl@gmx.de *
*                                                   *
* The ChallengeOS project:                          *
* http://challengeos.sourceforge.net                *
*****************************************************
* Math problems?                                    *
* Call 1-800-[(10x)(13i)^2]-[sin(xy)/2.362x].       *
*****************************************************