ID:151473
![]() Oct 10 2010, 12:58 pm
|
|
If I can program a large portion of procedures in my game in c++, offloading them as .DLL files, would this have my game run even faster? Or would it use the same amount of memory.
|
One thing I've found worthwhile using a DLL is string management systems, since the stl library has all sorts of goodies that are easily translated into BYOND functions using a DLL.
|
Thanks for the good example; I couldn't think of any good examples of things that actually are easier in C++ and so I left that part poorly explained.
I just thought of another example too. You could access external applications, such as MySQL, easier with C++ instead of doing hacky stuff with using PHP via Byond's browser support, or however the heck people are using MySQL with Byond these days. Also, anything you use shell for could probably be done at least as easily in C, if not easier. C has very good support for that, since you could combine that with OS system calls, which are extremely easy for Windows in C just by including windows.h |
Loduwijk wrote:
I just thought of another example too. You could access external applications, such as MySQL, easier with C++ instead of doing hacky stuff with using PHP via Byond's browser support, or however the heck people are using MySQL with Byond these days. You already can access MySQL directly from DM code, you don't have to use PHP. |
Another good example would be to generate large, complex images that BYOND can't handle very well. I remember seeing someone do that a few years ago.
|
Oh, that's actually quite handy to know. Actually, I'm not even developing games on BYOND, why am I excited about this? =/
I can definently see how this could be implemented server side, maybe provide functionality to update server details on a web server. |
In the general case, no. You can't easily access the majority of the game's context (player mobs, where is this object on the map etc), needing to push that data via the DLL's interface in string form.
The main consequence of this is the need to form a string on DM's side to represent the object, make the call, deconstruct it on the DLL's side, then back again to return. This is obviously costly in time, for trivial tasks. Further to that, seen as you can't access a lot of BYOND's functionality directly, there are some tasks which are impossible for a DLL to even attempt to speed up, for example path-finding (you can't look at the current running map, how are you going to plot a route?). Fortunately you are not undone, as chances are you can do some pretty significant optimisations in DM by altering your design to better suit that the problem actually is, not what you first thought it was. As for memory, that really depends on you as a programmer. Frankly I don't consider this a worthy consideration with BYOND though, you've chosen to use a VMed language, aside from ridiculously excessive resource creation (hey everyone, have a load of runtime generated ... everything), memory isn't your big concern. If it was, you'd have picked another language. |
The current DLL setup is good for things like extensive string-handling (perhaps parsing, regex, etc.), and maybe some complex mathematics due to the restrictions in place by DM's type system. It may also be easier to implement encryption routines such as SHA-1, which often uses bit-wise mathematics on number types wider than the 16-bits guaranteed by DM's number type.
I can imagine image generation might be a feasible use; you might generate an image and return the file name to be loaded in DM. I imagine that only has limited applications. It would be nice if BYOND provided a whole API for the DLLs to call into, providing an interface similar to Python's and making the DLLs better capable of things like pathfinding and handling DM objects. However, this isn't the case and likely will never come to fruition due to the complexity of integration and the considerations that must be made. |
I just did a forum search for MySQL to see how people are doing it now. I did not see anyone discussing how they are going about it, but I found a link to a MySQL library. Searching the library section I find 2 such libraries, both of which seem to leverage Dantom.DB, but doing a search for that offers up nothing, and searching my hard drive shows that it is not built in (at least not as a separate but prepackaged library).
|
Dantom.DB is simply a wrapper to BYOND's internal libmysql hooks. There are indeed built-in functions for it, they're just not very friendly, hence the wrapper for them.
|
Loduwijk wrote:
which seem to leverage Dantom.DB, but doing a search for that offers up nothing, and searching my hard drive shows that it is not built in (at least not as a separate but prepackaged library). It's here: http://www.byond.com/hub/dantom/db IIRC, the search systems ignore terms with fewer than 3 characters. |
Nadrew wrote:
Dantom.DB is simply a wrapper to BYOND's internal libmysql hooks. Speaking of which, how does BYOND get around the fact that the MySQL client libraries are GPLv2? |
This is a concern we had at work recently. While we were not redistributing the MySQL client library ourselves, we were definitely using it, thus meaning we'd fallen into one of two choices:
1. Comply with the terms of GPLv2 or use Oracle's FOSS licencing exception. 2. Enter into a commercial licence with Oracle. We chose the latter. It was deemed that simply not providing the library didn't get around GPLv2's concept of redistribution, as we still had their linker symbols etc. |
Yeah, this came to mind recently when a friend of mine asked how he could connect to a MySQL database in a closed source proprietary program. At first I told him he'd need a commercial license, but then I thought about BYOND and was wondering if there was something I didn't know. I thought perhaps the MySQL server process itself was GPL'd but maybe the client libraries were not, but after looking it up on the MySQL website as well as asking for clarification on StackOverflow, it seems you can't even connect to MySQL without either being GPL'd as well or having a commercial license.
In the case of BYOND, I'm unsure what this means for individual games as well. Assuming BYOND has a commercial license to access MySQL, does each game need to have a license or no? Assuming BYOND went open-source to meet the requirements of the GPL or FOSS exception, would each game then need to be FOSS as well (or purchase a commercial license)? |
I don't think so, as your work isn't touching their code directly. Similarly with the FOSS route, you'd follow the decisions taken on OpenJDK or GCC, the target output (DMB in this case, which is just a complex data file for BYOND) is separate to the platform itself.
|
Airjoe wrote:
In the case of BYOND, I'm unsure what this means for individual games as well. Assuming BYOND has a commercial license to access MySQL, does each game need to have a license or no? Does every PHP script that accesses MySQL databases need to either be GPL'd or have a commercial license? No. |
No, but PHP itself did buy a license. I don't think it was an issue way back when MySQL was first hooked into. Now it's probably an issue and I honestly don't see MySQL support being important enough to spend money on it (on BYOND's end). Perhaps it is best to just leave it up to the game developers to find a way to provide their own MySQL support.
|
Nadrew wrote:
No, but PHP itself did buy a license. I won't say that PHP didn't buy a license, but they probably didn't because they fall under the FOSS exception. |
In reality, whether or not it runs faster depends on what you are doing, but whether or not it runs faster is not always important. The reason you are using Byond is because it is easy to use. The reason DLL support was added to Byond was to make it so that you can add your own functionality to Byond which is not already there (on the server side). This is what your main use of DLLs should be, and obviously using them for what they were intended makes them "worth it" since it's sometimes the only way to do what you want.
That said (especially the part about Byond's purpose for being used is that it is easy to use), if you can do some specific thing easier in C or in C++ (rarely going to happen, but it is possible), then obviously go ahead and use a DLL, or if you have a part of your project which is really being a bottleneck on your resources to the point where speed is noticeably impacted and you could easily use a DLL to find a way to make it a lot faster, then go ahead.
Converting a large portion of your procedures for DLL use would not be worth any possible speed gain, and it might not even be faster at all. So the basic answer to your question is "No, it is not worth it to convert most of your project into C or C++."
Then your question also begs a question in response: If you are considering writing most of your game in C++, why not do that, then go the extra half mile and do your own networking and graphics so you end up with your own standalone executable that doesn't need Byond? If you are already willing to put the effort into doing most of it in C++, and if you already know C++ well enough that this is a feasible option, it isn't much of a stretch to do the entire thing completely in C++, especially if you don't need any GUI widgets. This would be more satisfying than doing a bunch of it in C++ for use in Byond.