External library example
Please login or register.

Login with username, password and session length
Advanced search  

News:

Latest WME version: WME 1.9.1 (January 1st, 2010) - download

Author Topic: External library example  (Read 7994 times)

0 Members and 1 Guest are viewing this topic.

Jerrot

  • Global Moderator
  • Addicted to WME forum
  • *
  • Karma: 0
  • Offline Offline
  • Gender: Male
  • Posts: 688
    • View Profile
External library example
« on: June 12, 2003, 10:54:56 PM »

2003-12-19: Since WME supports math functions now, this library became obsolete. So now this thread is only a example how to create your own libraries with C++.

Hiya,

so - you're not just a game designer, but also a genius, right ?  ;)
OK, here is your math functions dll for WME!

http://wme.jerrot.de/mathdll11.zip

Usage:

Example:

external "math.dll" cdecl double math_pow(double,double);
Game.Msg("pow(2,8) = " + math_pow(2,8));

Supported functions :

int     math_abs(int mynumber)
double  math_acos(double mynumber)
double  math_asin(double mynumber)
double  math_atan(double mynumber)
double  math_atan2(double mynumber1, double mynumber2)
double  math_cos(double mynumber)
double  math_cosh(double mynumber)
double  math_exp(double mynumber)
double  math_fabs(double mynumber)
double  math_fmod(double mynumber1, double mynumber2)
double  math_log(double mynumber)
double  math_log10(double mynumber)
double  math_pow(double mynumber1, double mynumber2)
double  math_sin(double mynumber)
double  math_sinh(double mynumber)
double  math_tan(double mynumber)
double  math_tanh(double mynumber)
double  math_sqrt(double mynumber)
double  DegToRad(double mynumber)
double  RadToDeg(double mynumber)

Version history:

2003-06-12 - [v1.0]
           - initial release
2003-06-13 - [v1.1]
           - added DegToRad() and RadToDeg()

C++ Sourcecode is included in the archive, but for the case my server burns up, here it is :

Code: [Select]
#include <math.h>
#define PI 3.1415926535f

extern "C" __declspec(dllexport) int math_abs(int mynumber)
{
  return abs(mynumber);
}
extern "C" __declspec(dllexport) double  math_acos(double mynumber)
{
  return acos(mynumber);
}
extern "C" __declspec(dllexport) double  math_asin(double mynumber)
{
  return asin(mynumber);
}
extern "C" __declspec(dllexport) double  math_atan(double mynumber)
{
  return atan(mynumber);
}
extern "C" __declspec(dllexport) double  math_atan2(double mynumber1, double mynumber2)
{
  return atan2(mynumber1,mynumber2);
}
extern "C" __declspec(dllexport) double  math_cos(double mynumber)
{
  return cos(mynumber);
}
extern "C" __declspec(dllexport) double  math_cosh(double mynumber)
{
  return cosh(mynumber);
}
extern "C" __declspec(dllexport) double  math_exp(double mynumber)
{
  return exp(mynumber);
}
extern "C" __declspec(dllexport) double  math_fabs(double mynumber)
{
  return fabs(mynumber);
}
extern "C" __declspec(dllexport) double  math_fmod(double mynumber1, double mynumber2)
{
  return fmod(mynumber1,mynumber2);
}
extern "C" __declspec(dllexport) double  math_log(double mynumber)
{
  return log(mynumber);
}
extern "C" __declspec(dllexport) double  math_log10(double mynumber)
{
  return log10(mynumber);
}
extern "C" __declspec(dllexport) double  math_pow(double mynumber1, double mynumber2)
{
  return pow(mynumber1,mynumber2);
}
extern "C" __declspec(dllexport) double  math_sin(double mynumber)
{
  return sin(mynumber);
}
extern "C" __declspec(dllexport) double  math_sinh(double mynumber)
{
  return sinh(mynumber);
}
extern "C" __declspec(dllexport) double  math_tan(double mynumber)
{
  return tan(mynumber);
}
extern "C" __declspec(dllexport) double  math_tanh(double mynumber)
{
  return tanh(mynumber);
}
extern "C" __declspec(dllexport) double  math_sqrt(double mynumber)
{
  return sqrt(mynumber);
}
extern "C" __declspec(dllexport) double  DegToRad(double mynumber)
{
  return mynumber * (PI / 180.0f);
}
extern "C" __declspec(dllexport) double  RadToDeg(double mynumber)
{
  return mynumber * (180.0f / PI);
}

Have fun,
Jerrot!
« Last Edit: December 19, 2003, 03:30:55 PM by Jerrot »
Logged
Mooh!

renno

  • Lurker
  • *
  • Karma: 0
  • Offline Offline
  • Posts: 6
  • I'm a llama!
    • View Profile
Re:Math functions DLL
« Reply #1 on: June 13, 2003, 12:07:46 AM »

it doesn't work for me. Wintermute gives me a compilation error (script error). I don't know how to use it.
Logged

Mnemonic

  • WME developer
  • Administrator
  • Addicted to WME forum
  • *
  • Karma: 41
  • Offline Offline
  • Gender: Male
  • Posts: 5675
    • View Profile
    • Dead:Code Site
Re:Math functions DLL
« Reply #2 on: June 13, 2003, 07:06:02 AM »

Quote
it doesn't work for me. Wintermute gives me a compilation error (script error). I don't know how to use it.

1) You need at least the 1.0.022 version of WME (if you didn't already, please download the latest build)
2) Put Jerrot's math.dll to the same folder where is the wme.exe file
3) in a script, you need to declare the function you want to use, like the example above:
 
  external "math.dll" cdecl double math_pow(double,double);

4) Now you can call the math_pow function from the script, e.g.

  Game.Msg("pow(2,8) = " + math_pow(2,8));
Logged
Yes, I do have a twitter account
Please don't send me technical questions in private messages, use the forum. ::wave

Musta Kaapu

  • Occasional poster
  • **
  • Karma: 0
  • Offline Offline
  • Gender: Male
  • Posts: 55
  • "I'm a bunny rabbit!"
    • View Profile
    • SomethingAwful
Re:Math functions DLL
« Reply #3 on: June 13, 2003, 11:42:03 AM »

Slightly offtopic again  :-[

But are you Jerrot going to release other "libraries" to WME, do you have any plans?
Logged
"Do you still wish to fight me?"

Jerrot

  • Global Moderator
  • Addicted to WME forum
  • *
  • Karma: 0
  • Offline Offline
  • Gender: Male
  • Posts: 688
    • View Profile
Re:Math functions DLL
« Reply #4 on: June 13, 2003, 12:26:21 PM »

Slightly offtopic again  :-[

Slightly ?? ;)

Quote
But are you Jerrot going to release other "libraries" to WME, do you have any plans?

[off-topic]
Ehm - I am not a "real coder" ! I just tried this one because McCoy asked for it - and it's just include, copy, paste! So there are no plans - but I start off scripting my own game soon, therefore I'm sure I will need some strange features again...  8)

If you have any ideas for future releases - just tell us your ideas in the wishlist board, I'm always looking for new ideas...  ;)
[/off-topic]
Logged
Mooh!

Jerrot

  • Global Moderator
  • Addicted to WME forum
  • *
  • Karma: 0
  • Offline Offline
  • Gender: Male
  • Posts: 688
    • View Profile
Re:Math functions DLL
« Reply #5 on: June 13, 2003, 12:36:55 PM »

v1.1 released (added DegToRad() and RadToDeg() ), see above.

Logged
Mooh!

MMR

  • Global Moderator
  • Frequent poster
  • *
  • Karma: 3
  • Offline Offline
  • Gender: Male
  • Posts: 349
  • http://mmrdeveloper.wordpress.com/
    • View Profile
    • TinyWME
Re:Math functions DLL
« Reply #6 on: June 13, 2003, 01:53:32 PM »

Nice Work.

Thank you for that GREAT Plug-in ;)

Take a look at http://adan.iefactory.com/wintermute/mates.htm
Logged

Jerrot

  • Global Moderator
  • Addicted to WME forum
  • *
  • Karma: 0
  • Offline Offline
  • Gender: Male
  • Posts: 688
    • View Profile
Re:Math functions DLL
« Reply #7 on: June 13, 2003, 02:14:07 PM »

Take a look at http://adan.iefactory.com/wintermute/mates.htm

Wow, it even seems to be better described than I did...  ;D
Logged
Mooh!

Jerrot

  • Global Moderator
  • Addicted to WME forum
  • *
  • Karma: 0
  • Offline Offline
  • Gender: Male
  • Posts: 688
    • View Profile
Re:External library example
« Reply #8 on: December 19, 2003, 03:32:18 PM »

Deleted the file from my server and updated subject and the first message in this thread (see above).
Logged
Mooh!
 

Page created in 0.27 seconds with 22 queries.