ID:156736
Aug 4 2010, 10:30 am
|
|
i've seen in the discussions and whatnot where people say they can use a Dll with byond. Now i know what Dll files and and how they're used in c++, but i have no idea how to call a certain function from the Dll using byond. So can someone help me with this?
|
In response to UmbrousSoul
|
|
thanks :D
|
mmm, well having this compiles fine and all in Dev c++, and anyway i literally JUST started learning about DLLs yesterday and im having trouble with using a test dll in byond D:. Looks like this
yea ima use <dm></dm> tags dllmain.cpp #include "dll.h" dll.h #ifndef _DLL_H_ and this is the byond code ime using DllTest.dm mob and apparently it cant find the function :P |
In response to Masschaos100
|
|
DLLs BYOND uses requires a very specific format for functions:
extern "C" __declspec(dllexport) char * my_function(int argc, char ** argv); BYOND will pass all arguments to you functions as C strings. argc will tell you how many were passed, and argv is an array of C strings which is the arguments passed. You must also return a C string. For your example, you will need to scan the strings in argv into your int argument, do that math calculation you want to do, then print the resulting float into a string, to return to BYOND. Also be aware, you will need to convert to and from text on BYOND's side as well. |
In response to Stephen001
|
|
Out of curiosity as i dont know much about dll's
What kind of game related things could you use dll's for? and what is the benefits of using a dll for those kind of functions? can you achieve things not possible through byond programming through a dll? |
In response to Tonyth
|
|
well as i've heard(and its true) c++ is hundreds of times faster than byond, so you can use it to do things faster than you normally would using straight DM
|
In response to Masschaos100
|
|
You mistyped thousands.
Edit: DM Code: mob This took 8 seconds to complete. C++ code: void P(){ It wasn't able to measure time (says 0). So I increased loop 100 times: for(_int64 i = 0; i<1000; i++){ Now whole operation takes 1.91998e-006 seconds, that's 0.0000019 seconds if I'm right. 8 / 0.0000019 = 4,210,526 times faster. But it also had 100 times bigger loop, so we multiply that too: 4,210,526 * 100 = 421,052,600 Guess I mistyped 100s millions too. |
In response to Ripiz
|
|
Ripiz wrote:
8 / 0.0000019 = 4,210,526 times faster. But it also had 100 times bigger loop, so we multiply that too: 4,210,526 * 100 = 421,052,600 wow that fast.. I can see how that could help. So is it possible to call on a dll within a proc? example i have a battle system with a more complex of a formula. Im pretty sure with the byond language this could cause lag issues. If a lot of people are using the fight proc throughout the world. If i was able to call this forumla from a dll, could it help the problem? |
In response to Ripiz
|
|
Just to get this right, you're telling me that your computer tackles on 1,000,000,000 additions, 2,000,000,000 multiplications and 1,000,000,000 square root function calls in 1.9 microseconds.
That is leaving everything else on the program aside. Are you sure that your C++ compiler didn't optimise a LOT in this case and thus leaving the comparison horribly unfair? Edit: Sorry, mixed up the prefix, thanks for correcting me there Stephen. |
In response to Schnitzelnagler
|
|
1.9 micro-seconds, not nano-seconds, and 10,000,000 20,000,000 and 10,000,000 respectively, not including incrementers.
|
In response to Stephen001
|
|
Thanks for correcting me on the prefix, got that screwed up.
Though, I do not see how 1,000 * 1,000,000 is 10,000,000 (as you can see he edited the program to run the outer loop 1000 times, instead of 10 and profiled that to 1.9*106 seconds, according to his post). |
In response to Tonyth
|
|
It wouldn't. I doubt your formula complex enough to be worth to send it to .dll
|
In response to Ripiz
|
|
Those numbers would put you approximately on par with an IBM Blue Gene supercomputer, if you counted the sqrt() function as a single floating-point operation (which it isn't). The compiler likely optimized away the entire loop, as it wasn't actually doing anything.
|
In response to Ripiz
|
|
mmmm, im still having problems with the dlls cause i dont get what stephen meant xD. Damn.
|
In response to Masschaos100
|
|
BYOND can call only C functions, not C++, C#, VB or etc. If you want other language you have to specify it's C either call it differently from DM, so you have to use this format:
extern "C" __declspec(dllexport) char * my_function(int argc, char ** argv); extern "C" tells it's C code, not C++ __declspec(dllexport) tells it's accessible from outside char* function will return char array my_function is name of function (int argc, char ** argv) function arguments (argc argument count, argv 2 dimensional array of data) |
http://www.byond.com/members/ DreamMakers?command=top_search&text=DLL&type=resources