添加新的游戏类型而不需要重新编译程序? (C++)

发布于 2024-10-16 17:36:17 字数 367 浏览 8 评论 0原文

我有一个游戏,它有不同的游戏类型,即计时赛、无限游戏等。

每种游戏类型都有不同的计时规则和潜在的碰撞规则。 显然,在计时赛中,比赛会在时间耗尽时结束。

我目前通过将游戏类型“硬编码”到程序中来添加游戏类型,因此每次我想添加新的游戏类型时,我都必须重新编译整个程序。

基本上,为了更轻松地添加游戏类型,我不想重新编译所有内容。因此,潜在的新游戏类型可以是可下载内容,并且只需将新类型放入游戏文件夹即可运行。

人们会如何去做这件事呢?我认为这是使用 libs 或 dlls 或其他东西(我对此知之甚少,所以我可能完全错误)。

我希望一切都有意义,我希望你们能帮助我,或者至少为我指明解释这种方法的书籍或文章的方向。

提前致谢。

I have a game which has different game types, i.e Time Trial, Infinite Game etc.

Each game type has different timing rules and potentially collision rules.
Obviously in the Time Trial the game ends when the time runs out.

I am currently adding game types by 'hardcoding' them into the program, therefore each time I want to add a new game type I have to recompile the whole program.

Basically to make adding game types easier I don't want to have to recompile everything. So potentially new game types could be downloadable content and would work simply by putting the new type in the game folder.

How would one go about doing this? I assume it is with the use of libs or dlls or something (I have very little knowledge about that so I might be completely incorrect).

I hope that all makes sense and I hope you guys can help me out or atleast point me in the direction of a book or article that explains this methodology.

Thanks in advance.

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

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

发布评论

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

评论(1

聆听风音 2024-10-23 17:36:17

在我看来,使用本机 DLL 来实现游戏可扩展性并不是一个好主意,特别是如果代码不是从头开始设计的。

您最好使用一些脚本语言,例如 LUAPython,因此无需编写和编译C++代码即可添加游戏模式。这些很容易实现(特别是如果您使用一些绑定/包装库),但需要您设计一个脚本 API,这可能是一项不平凡的任务(取决于您希望游戏可修改的程度)。这现在是游戏行业相当标准的方法 - 如今大多数商业游戏都有某种脚本支持。

一般来说,趋势是将尽可能多的代码从核心(C++)转移到脚本,因为这些脚本更容易开发、维护和修改。许多现代游戏在游戏逻辑(用脚本语言编写)和游戏引擎(用 C++ 或其他编译语言编写)之间有非常清晰的区别。

Using native DLL for game extensibility is IMO not a good idea, especially if the code is not designed for this from ground up.

You would best employ some scripting language like LUA or Python, so game modes can be added without writing and compiling C++ code. These are quite easy to implement (especially with if you use some binding/wrapper library), but require you to design a scripting API which can be a nontrivial task (depending on how much you want the game to be modifiable). This is now quite standard approach in game industry - most commercial games have some sort of scripting support these days.

Generally, the trend is to move as much code from core (C++) to scripts, because these scripts are easier to develop, maintain and modify. Many modern games have quite clean distinction between gameplay logic (written in scripting language) and game engine (written in C++ or another compiled language).

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