0

I have a game enginewhere you can write your custom scripts.I managed to make it work and load the scripts dynamicly using LoadLibrary()&GetProcAddress although it seems im stuck.

I have a .dll file an .exe,they both using same engine's library i created.The Application(.exe) inits the game engine so its must the host of the my global singleton variable.

This my script's code

#include "MyConsoleWriterComponent.h"
#include "../DarkLightEngine/DLE_Engine.h"
void MyConsoleWriterComponent::OnTick()
{

    Atom* a = Atom::CreateAtom("Heyo");
    OutputDebugString(L"Text Text!\n");
}

Atom::CreateAtom uses the singleton for registering the current game entity to a scene.However if call this method in .exe it's works as expected(atom pushed into scene everything is perfect) but when i export this class and using it from my .exe,it seems it does not register to my .exe singleton.

I have read it somewhere that you must mark the singleton as a 'volatile' variable but it seems prompts some errors,like some structres dont accept volatile variable(used on stacks,vectors),and there is a keyword called extern but eveytime i used on my singleton it propmts the error 'illegal' storage class.

It seems like im missing a critical concept here on this matter.

can you help me with me,any direction's opinions are much appreciated.

Roveldo
  • 29
  • 1
  • 4
  • 1
    Volatile has nothing to do with this. Your question is whether your dll can automatically have access to static variables in the program that loads it, the answer is it can not. Also, the fact that you are working on a game engine and are having problems spawning entities in your world is irrelevant. Try to distill your questions to the core issue - in this case, making a dll automatically have access to static variables in the program that loaded it - you will both be asking better questions and have a higher chance of figuring stuff out yourself. – DeducibleSteak Feb 17 '20 at 10:58
  • 1
    As far as how you would go about achieving an effect similar to what you want - and I haven't thought this all the way through, but it should give you a good starting point: create a dll that your global variables live in; have both your application load-time link that dll, and your game script dlls load-time link to it, and use the global variables in that dll. Some reading for you: https://stackoverflow.com/questions/19373061/what-happens-to-global-and-static-variables-in-a-shared-library-when-it-is-dynam https://stackoverflow.com/questions/12530022/load-the-same-dll-multiple-times – DeducibleSteak Feb 17 '20 at 11:07
  • Thank you for your lightning input,im sure i will put your comment#1 directives to good use and for comment#2,it seems what i what to achieve. – Roveldo Feb 17 '20 at 11:14

0 Answers0