Making a wrapper dll to let gamemaker handle the C++ standard libraries
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 bett开发者_StackOverflower methods?
P.s. why isn't the gamemaker tag there yet?
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.
精彩评论