多个 Dll 通过“main”调用彼此的函数动态链接库

发布于 2024-10-16 03:58:38 字数 560 浏览 8 评论 0原文

我正在构建一个游戏引擎(用 C++ 编写),它分为多个项目(在 Windows 上编译为单独的 DLL 和库,在 Linux 中编译为共享对象),其结构如下:

                                    Main.exe

                                   Engine.dll

          Graphics Engine.dll Physics Engine.dll Sound Engine.dll ...dll

Main.exe 初始化一个新引擎,然后引擎创建图形、物理和声音引擎。这一切都工作正常,但我现在希望例如图形引擎运行声音引擎中存在的函数,但不是直接通过 Engine.dll 中的函数运行。

然而有一个问题。 Main包括Engine,Engine包括Graphics、Physics和Sound。如果我现在告诉图形、物理和声音包含引擎,并将引擎对象的引用传递给每个相应的“子引擎”,则存在循环依赖性问题...

我怎样才能让图形、物理和声音引擎与主引擎通信(因为目前这只是主引擎调用子引擎的所有功能的单向关系)?

I am building a game engine (in c++) which is split up into multiple projects (compiling to separate dll's and libs on windows and shared objects in linux ) the structure is as follows:

                                    Main.exe

                                   Engine.dll

          Graphics Engine.dll Physics Engine.dll Sound Engine.dll ...dll

The Main.exe initializes a new Engine then the engine creates the graphics, physics and sound engines. This all works fine however I now want for example the Graphics engine to run functions present in the sound engine but not directly instead via a function in the Engine.dll.

There is a problem however. Main includes Engine, and Engine includes Graphics, Physics and Sound. If I now tell Graphics, Physics and sound to include Engine and also pass a reference of the engine object to each respective "sub-engine" there is a problem with circular dependencies...

How could I get Graphics, Physics and Sound engine to communicate to the Main engine (as at the moment it is only the one way relationship where the Main engine calls all of the function of the sub engines)?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

孤独难免 2024-10-23 03:58:38

您可以使用 Engine.dll 中的抽象类(即带有纯虚函数)来公开接口。然后在Engine.dll中实现该接口。然后创建具体此类的实例,并将该实例的引用/指针(作为抽象类引用/指针)传递给GraphicsEngine.dll。现在,每当 GraphicsEngine 需要与 Engine 通信时,它都可以使用此实例。由于您仅使用抽象类,因此不需要将 GraphicsEngine.dll 链接到 Engine.dll。所以不会出现循环依赖。

You can expose an interface using a abstract class (i.e. with pure virtual functions) from the Engine.dll. Then implement this interface in the Engine.dll. Then create an instance of the concrete this class and pass the reference/pointer of this instance (as a abstract class reference/pointer) to the GraphicsEngine.dll. Now, whenever GraphicsEngine needs to communicate with Engine it can use this instance. Since you are using just the abstract class this doesn't require the GraphicsEngine.dll to be linked to Engine.dll. So there will be no circular dependency.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文