制作一个包装 dll 让游戏制作者处理 C++标准库

发布于 2024-10-20 22:07:14 字数 669 浏览 3 评论 0原文

Gamemaker 是一个简洁的工具,可以实现一些良好的 RAD。然而它有不少缺点。其中之一是缺乏良好的标准库。
确实,您有“ds_*”类型成员,但这些成员非常缺乏。例如,优先级队列只是只读一次类型(它在过程中被销毁)。列表的排序函数使用了一种非常慢的方法。 (虽然从未正式声明,但我怀疑它使用了冒泡排序)。并且根本没有链接列表的内置方法。最重要的是,简单的成员访问速度比应有的速度要慢。

现在人们实际上可以用母语创建这些东西。然而它变得相当慢(因为解释器很慢)。即,编写快速排序/堆排序在许多情况下比内置排序慢。编写我自己的“链表”(为每个节点使用特殊对象)的开销太大。 (gamemaker 中的每个对象每一步都会做很多事情)。

所以现在我正在考虑为标准库编写一个 C++ 层。我希望添加一些额外的功能(哈希表和链表是主要目标)并允许更好的算法。对于大多数问题,我已经知道如何解决它,除了 1 个大问题:

所有 C++ 库都使用“迭代器”来识别项目。 Gamemaker 只允许将双精度数(或 C 风格字符数组)传入和传出 dll。
我该如何规避这个问题?不返回项目的索引是非常愚蠢的,所以我必须找到一种方法将这些迭代器映射到双精度数。

这有什么好主意吗?我是否最好简单地重写所有数据结构,以便保证迭代器具有到双精度(或实际上双精度+数据结构索引)的一对一映射?或者有更好的方法吗?

PS 为什么游戏制作者标签还没有出现?

Gamemaker is a neat tool which allows for some good RAD. However it has quite a few shortcomings. One of those is the lack of a good standard library.
True you have the "ds_*" type members, but those are quite lacking. The priority queue for example is only a read-once type (it's destroyed in the process). The sort function for lists uses a terrible slow method. (While never officially stated, I suspect it uses bubble sort). And there simply is no build in method for linked lists. On top of that simple member access is slower than it should be.

Now one could actually create those things in the native language. However it becomes quite slow (as the interpreter is slow). I.e. writing a quicksort/heapsort was in many cases slower than the built in sort. Writing my own "linked lists" -using special objects for each node- had too much overhead. (each object in gamemaker does lots of things each step).

So now I'm looking at writing a C++ layer for the standard library. I hope to add some extra functionality (hash tables & linked lists are the prime target) as well as allow for better algorithms. For most of the problems I already have an idea how to tackle it, except for 1 big problem:

All C++ libraries use "iterators" to identify an item. Gamemaker only allows for doubles (or c-style character arrays) to be passed to and from dlls.
How would I circumvent this? Not returning the index of an item is quite silly, so I have to find a way to map those iterators into doubles.

What is a good idea for this? Am I best off simply rewriting all datastructures so the iterators are guaranteed to have a 1 on 1 map to double (or actually double + datastructure index)? Or are there better methods?

P.s. why isn't the gamemaker tag there yet?

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

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

发布评论

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

评论(1

夏花。依旧 2024-10-27 22:07:14

在 Game Maker 的变量中“存储”数据结构的唯一方法是使用句柄或 ID。您会注意到,使用内置数据结构可以做同样的事情,即使用整数。

我尝试的方法是将所有指向数据结构的指针及其 ID 存储在哈希表中。然后,您在 GM 和 DLL 之间传递 ID,因为除非您要求,否则 Game Maker 不需要知道数据结构的状态。

The only way to "store" a data structure in a variable in Game Maker is with a handle or ID. You'll notice that using the built-in data structures does the same thing, using integers.

The method I would try would be to store all the pointers to your data structures along with their IDs in a hashtable. Then, you pass the ID between GM and the DLL, since Game Maker doesn't need to know the state of the data structure unless you ask for it.

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