Jump to content

  • Log In with Google      Sign In   
  • Create Account


implementing scripting


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
17 replies to this topic

#1 Yours3!f   Members   -  Reputation: 1299

Like
0Likes
Like

Posted 13 September 2013 - 02:50 PM

Hi,

 

so I'm trying to implement scripting using runtime-compiled c++ code. Now my problem is that when I load the DLL, it's functions see different memory than the exe's code (so getting a singleton results in a new singleton, rather than getting the exe's singleton).

So I suppose I should implement some sort of interface, so that I can call the exe's functions, and the exe's code is hidden from the gameplay code. This would enable anyone to create a gameplay c++ code or DLL and load it in the exe. I suppose this interface is needed with different script languages like lua too, so there should be a 'usual' way to handle this.
How is this usually handled?



Sponsor:

#2 L. Spiro   Crossbones+   -  Reputation: 13201

Like
2Likes
Like

Posted 13 September 2013 - 06:02 PM

Your .EXE is capable of exporting symbols just as your .DLL is.  Just as your (and almost every other) .DLL relies on external symbols from other .DLL files, they may also rely on external symbols from your .EXE.

 

So make your .EXE export whatever symbols you need the .DLL to access the same way you would export symbols from any .DLL, and make the .DLL import those symbols from the .EXE the same way it would import from any .DLL.

 

 

L. Spiro


It is amazing how often people try to be unique, and yet they are always trying to make others be like them. - L. Spiro 2011
I spent most of my life learning the courage it takes to go out and get what I want. Now that I have it, I am not sure exactly what it is that I want. - L. Spiro 2013
I went to my local Subway once to find some guy yelling at the staff. When someone finally came to take my order and asked, “May I help you?”, I replied, “Yeah, I’ll have one asshole to go.”
L. Spiro Engine: http://lspiroengine.com
L. Spiro Engine Forums: http://lspiroengine.com/forums

#3 Yours3!f   Members   -  Reputation: 1299

Like
0Likes
Like

Posted 14 September 2013 - 01:52 AM

Your .EXE is capable of exporting symbols just as your .DLL is.  Just as your (and almost every other) .DLL relies on external symbols from other .DLL files, they may also rely on external symbols from your .EXE.

 

So make your .EXE export whatever symbols you need the .DLL to access the same way you would export symbols from any .DLL, and make the .DLL import those symbols from the .EXE the same way it would import from any .DLL.

 

 

L. Spiro

 

 

thank you for the reply!

well, I thought it would work the other way around too, but I would be interested in the actual howto on the interface design and such. Or there isn't much magic there, just export some functions and that's it?



#4 L. Spiro   Crossbones+   -  Reputation: 13201

Like
2Likes
Like

Posted 14 September 2013 - 01:58 AM

There is no magic.  It works the same way as any DLL linking to any function in any other DLL.  EXE’s and DLL’s are almost the same thing.

 

 

L. Spiro


It is amazing how often people try to be unique, and yet they are always trying to make others be like them. - L. Spiro 2011
I spent most of my life learning the courage it takes to go out and get what I want. Now that I have it, I am not sure exactly what it is that I want. - L. Spiro 2013
I went to my local Subway once to find some guy yelling at the staff. When someone finally came to take my order and asked, “May I help you?”, I replied, “Yeah, I’ll have one asshole to go.”
L. Spiro Engine: http://lspiroengine.com
L. Spiro Engine Forums: http://lspiroengine.com/forums

#5 Yours3!f   Members   -  Reputation: 1299

Like
0Likes
Like

Posted 14 September 2013 - 03:40 AM

There is no magic.  It works the same way as any DLL linking to any function in any other DLL.  EXE’s and DLL’s are almost the same thing.

 

 

L. Spiro

 

well, okay thank you :)



#6 dougbinks   Members   -  Reputation: 484

Like
3Likes
Like

Posted 14 September 2013 - 06:56 AM

For communication between DLL's and EXE's using C++ a commonly used technique is to have virtual interfaces to systems, as this way you can pass around a pointer to a structure which holds the pointers to the interface of each sub system. This is the technique we used in Runtime Compiled C++ and it's also how the CryENGINE passes around interfaces using gEnv.

 

For a look at what a system table looks like see this file.

 

Exporting classes without using virtual interfaces is not simple in general, for an overview have a look at this post on codeproject. Using a virtual interface makes things alot easier - they don't have to be pure virtual but this does help to eliminate mistakes. Make sure to define a virtual destructor to prevent the memory created in one module being freed in another.

 

Feel free to use any of the code in RCC++, we use a liberal Zlib license and you can just use which-ever parts you need.



#7 Yours3!f   Members   -  Reputation: 1299

Like
0Likes
Like

Posted 14 September 2013 - 10:42 AM

For communication between DLL's and EXE's using C++ a commonly used technique is to have virtual interfaces to systems, as this way you can pass around a pointer to a structure which holds the pointers to the interface of each sub system. This is the technique we used in Runtime Compiled C++ and it's also how the CryENGINE passes around interfaces using gEnv.

 

For a look at what a system table looks like see this file.

 

Exporting classes without using virtual interfaces is not simple in general, for an overview have a look at this post on codeproject. Using a virtual interface makes things alot easier - they don't have to be pure virtual but this does help to eliminate mistakes. Make sure to define a virtual destructor to prevent the memory created in one module being freed in another.

 

Feel free to use any of the code in RCC++, we use a liberal Zlib license and you can just use which-ever parts you need.

Thank you,
I'm actually using the rtcc++ (win32 alternate file watcher api, remember?), and I'm now at the implementation stage. I skipped the actual example (simpleexample) code, because it was a bit huge (the consoleexample wasn't though) tongue.png

I've actually read the codeproject article while googling, and I started to do something like that, but this seems a bit more organized.
So I guess I'll look into the SimpleExample now...


Edited by Yours3!f, 14 September 2013 - 10:46 AM.


#8 dougbinks   Members   -  Reputation: 484

Like
0Likes
Like

Posted 14 September 2013 - 11:06 AM

Hi - I thought there might be a connection, but wasn't sure since you'd used different profile names! Thanks once again for the alternate file watcher ;)

 

The SimpleExample is a bit big - keep meaning to change the name to PulseDemo as that's what it morphed into. The sample does show how to pass in a pointer to an interface structure so you can interact with your game engine.

 

In my case with the game Avoyd I'm working on, I'm actually implementing most of the engine using RCC++ as a trial of how that can be made to work better. The new features described in the blog help with that, though I need to get more documentation up on the wiki to help.



#9 Yours3!f   Members   -  Reputation: 1299

Like
0Likes
Like

Posted 15 September 2013 - 11:56 AM

Hi - I thought there might be a connection, but wasn't sure since you'd used different profile names! Thanks once again for the alternate file watcher ;)

 

The SimpleExample is a bit big - keep meaning to change the name to PulseDemo as that's what it morphed into. The sample does show how to pass in a pointer to an interface structure so you can interact with your game engine.

 

In my case with the game Avoyd I'm working on, I'm actually implementing most of the engine using RCC++ as a trial of how that can be made to work better. The new features described in the blog help with that, though I need to get more documentation up on the wiki to help.

 

Yeah, I use a couple of them :)

I actually took my time today, and looked at it, and got it right. As I noticed I still need to export one function at least to set the system table, but that is fine.

 

I'm working on one too, though it doesn't have a website yet (only youtube channel), I intend to use the scripting to do gameplay, not the whole engine. More docs/wiki would be awesome!



#10 dougbinks   Members   -  Reputation: 484

Like
0Likes
Like

Posted 15 September 2013 - 01:49 PM


I'm working on one too, though it doesn't have a website yet (only youtube channel)

 

Looks great :)



#11 skarab   Members   -  Reputation: 449

Like
0Likes
Like

Posted 15 September 2013 - 02:27 PM

Interesting, wasn't aware about RCC++, just knowing internal studios roll those kind of thing in proprietary engines.

Cool idea to roll a separate framework for this.

In Coffee The Engine, I based the whole thing on component/plugin oriented design, working nice and should scale well.

Not sure how it's similar though, will take a look later on.



#12 Wolftein   Members   -  Reputation: 167

Like
0Likes
Like

Posted 17 September 2013 - 02:36 PM

For communication between DLL's and EXE's using C++ a commonly used technique is to have virtual interfaces to systems, as this way you can pass around a pointer to a structure which holds the pointers to the interface of each sub system. This is the technique we used in Runtime Compiled C++ and it's also how the CryENGINE passes around interfaces using gEnv.

 

For a look at what a system table looks like see this file.

 

Exporting classes without using virtual interfaces is not simple in general, for an overview have a look at this post on codeproject. Using a virtual interface makes things alot easier - they don't have to be pure virtual but this does help to eliminate mistakes. Make sure to define a virtual destructor to prevent the memory created in one module being freed in another.

 

Feel free to use any of the code in RCC++, we use a liberal Zlib license and you can just use which-ever parts you need.

I just knew about Runtime Compiled C++ and must say, wow, amazing idea.


Feel free to comment and star my project! <https://github.com/Ghrum/Ghrum>


#13 dougbinks   Members   -  Reputation: 484

Like
0Likes
Like

Posted 18 September 2013 - 03:55 AM

Interesting, wasn't aware about RCC++, just knowing internal studios roll those kind of thing in proprietary engines.

Cool idea to roll a separate framework for this.

In Coffee The Engine, I based the whole thing on component/plugin oriented design, working nice and should scale well.

Not sure how it's similar though, will take a look later on.

 

The approach in RCC++ is somewhat different from what I'm aware other teams have used in the past, as rather than simply allowing shared libraries (DLLs on Windows) to be reloaded dynamically RCC++ detects changes in files and compiles the minimal set of source files needed into a shared library then links this in. This gives a quicker turn around at the cost of some developer effort in code markup using macros.

 


I just knew about Runtime Compiled C++ and must say, wow, amazing idea.

 

Thanks :)



#14 skarab   Members   -  Reputation: 449

Like
0Likes
Like

Posted 18 September 2013 - 03:20 PM

The approach in RCC++ is somewhat different from what I'm aware other teams have used in the past, as rather than simply allowing shared libraries (DLLs on Windows) to be reloaded dynamically RCC++ detects changes in files and compiles the minimal set of source files needed into a shared library then links this in. This gives a quicker turn around at the cost of some developer effort in code markup using macros.

 

Having instant reload of shared libraries isn't that simple, it's already the same job of having interfaces/macros and lot of tricky stuff... Depends if this is just some plugin system with init/exit method (as standard plugin systems) or full Objects creation/refresh handling (which is what "Runtime C++" means) I guess. Thats not the same, sure you know it, but I wanted to make it clear for others.

 

. Having full source files change detection is nice, but you loose IDE ability to have output/error reporting (double click to go to the error), not sure about debugging abilities, if some part is failing, what happens?

. Automatically separate the whole project in libs: I thought about it as well, but in Coffee's component based system it makes no point, it's already clearly separated. Rebuilding a simple component takes 1s, and build system already figure out which files need to be rebuilt.

. Coffee already have assets changes detection, that's why I may have extended it to source files as well, but I choose to only take built DLLs into account for the upper reasons.

 

RCC++ is a nice idea, but it seems hard to integrate it into an existing engine (with the usual existing custom build system, reflection and so on...), but for starting a new project from scratch it seriously looks like a great idea.

But, indeed, that's the future and some nice reason to stick to only one langage for the whole thing...



#15 dougbinks   Members   -  Reputation: 484

Like
0Likes
Like

Posted 19 September 2013 - 03:37 AM


Having full source files change detection is nice, but you loose IDE ability to have output/error reporting (double click to go to the error), not sure about debugging abilities, if some part is failing, what happens?

 

All output is piped through a logging interface, and if you copy this to either stdio (on Linux/Mac OS X) or OutputDebugString (Windows) you get full double click to go to error support as well. Debugging is also handled similarly, with the added benefit of the game not stopping due to error catching (though this has issues with gdb which I need to sort out). See http://runtimecompiledcplusplus.blogspot.fr/2011/09/crash-protection.html

 


but it seems hard to integrate it into an existing engine

It's intended initial use is for scripting style additions to an engine. For this purpose it should be easier to add than adding something like lua or python. The problem at the moment is the lack of documentation, which I do hope to fix.



#16 skarab   Members   -  Reputation: 449

Like
0Likes
Like

Posted 19 September 2013 - 07:35 AM

Okay, so you attach VS to the main exe, then use usual things, great!

Tried SEH years ago but I failed to enable it on whole project (unwinding problems or don't remember).

This looks good, will definitively follow your project.



#17 dougbinks   Members   -  Reputation: 484

Like
0Likes
Like

Posted 19 September 2013 - 07:48 AM

Okay, so you attach VS to the main exe, then use usual things, great!

Tried SEH years ago but I failed to enable it on whole project (unwinding problems or don't remember).

This looks good, will definitively follow your project.

 

You can use our system outside of RCC++ with only a small amount of effort - have a look at RuntimeProtector.h and the implementation functions in RuntimeObjectSystem_Platform*.cpp

 

[Edit] Note that this will likely interfere with any crash handler like Breakpad, but since it's primarily intended for development I'd simply turn it off in shipping code if you use Breadpad in shipping code. I intend to look into a solution at some point.


Edited by dougbinks, 19 September 2013 - 07:50 AM.


#18 skarab   Members   -  Reputation: 449

Like
0Likes
Like

Posted 21 September 2013 - 09:31 AM

Looks good, will see how to integrate RCC++ later on (will start with this part) and will see if I can use more as well, since it'll save lot of headache in future platform support.

Thanks.






Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS