Update 27th May 05:
Heres a short quickie for you. The following function will (hopfully) extract a file name from a full path. Example, if you pass "e:\moo\test\blah.exe" it should return "blah.exe" - I have found a use for this here and there.
Note, it assumes the path to be split up using backslashes (\) and not forward slashes (/) as thats what most directory and file functions will return, easy to modify though.
It appears to work fine in my short tests.
char *FileFromPath(char *Str) {
char *pch;
char *pch2;
pch = strchr(Str,'\\');
while (pch != NULL) {
pch2 = pch;
pch = strchr(pch+1,'\\');
}
return pch2+1;
}
Update 23rd April 05:
EDIT:
A quick note on the get angle function posted previously - its base angle and dbp's base angle are 90 degrees apart. To get a dbp matching result from GetAngle() subtract 90 from the result - probably best to do this inside a dbWrapValue() statement. The one exception is if the angle differance is zero in whichcase both GetAngle and darksdk will agree on that and you dont need the -90.
I may update the function to make it more friendly to use with darkSDK, but i use it for more than just darkSDK which is why it hasnt been altered yet

On with this post~
3 quick small ones for you (most of the stuff I post here may not be complex, its just quick utility functions that I find usful because I use them lots in my code) - Diff(), DiffF() and DRand().
Diff returns the differance between two numbers. DiffF() is the same thing but works on floats not integers. DRand() returns a random value between a minium and a maxium range.
Diff:
int Diff(int a, int b) {
if (a > b)
return a - b;
if (b > a)
return b - a;
return 0;
}
DiffF:
float DiffF(float a, float b) {
if (a > b)
return a - b;
if (b > a)
return b - a;
return 0.0;
}
DRand:
int DRand(int low, int high) {
int r = low + rand() % (high - low + 1);
return r;
}
Update 18th April 05:
Fast get 3D distance.
Getting the distance between two points in 3d space isnt too hard and many people have provided code showing how. However, they are often quite slow. The problem lays in most using a square root calculation and these are generally -not- fast. Its okay if you are only doing a few distance checks a frame, but attempting to check the distance between my player and possiably upto 100x100 points a frame completly killed my application (less than 0 fps..). After some research I found many fast square root functions online - i can now do my checks without too much of a speed hit (its a God send for me I can tell you).
Heres the sqrt function:
double fsqrt(double r) {
double x,y;
double tempf;
unsigned long *tfptr = ((unsigned long *)&tempf)+1;
tempf = r;
*tfptr=(0xbfcd4600-*tfptr)>>1;
x=tempf;
y=r*0.5;
x*=1.5-x*x*y;
x*=1.5-x*x*y;
x*=1.5-x*x*y;
x*=1.5-x*x*y;
return x*r;
}
Use it to get distance like this:
float Get3dDistance(float x1, float y1, float z1, float x2, float y2, float z2) {
return (float) fsqrt(((x2 - x1)*(x2 - x1)) + ((y2 - y1)*(y2 - y1)) + ((z2 - z1)*(z2 - z1)));
}
Source for the fsqrt is from:
http://www.azillionmonkeys.com/qed/sqroot.html
-----------------------------------
Not sure if theres any snippets for Dark SDK actually posted before. Im just going to submit a few things I find myself using often, will edit the post with new stuff if I make more things.
Start off with just two things, first the classic GetAngle:
float GetAngle(float x0, float y0, float x1, float y1) {
x0 = x1 - x0;
y0 = y0 - y1;
if (!x0 && !y0)
return 0;
else
return dbAtanFull(y0, x0);
}
Returns the angle between two points.
Second, a scancode listing to put in your own header file:
#define KEY_Q 16
#define KEY_W 17
#define KEY_E 18
#define KEY_R 19
#define KEY_T 20
#define KEY_Y 21
#define KEY_U 22
#define KEY_I 23
#define KEY_O 24
#define KEY_P 25
#define KEY_SBO 26 //Square Bracket Open
#define KEY_SBC 27 //Square Bracket Close
#define KEY_ENTER 28
#define KEY_A 30
#define KEY_S 31
#define KEY_D 32
#define KEY_F 33
#define KEY_G 34
#define KEY_H 35
#define KEY_J 36
#define KEY_K 37
#define KEY_L 38
#define KEY_SEMI 39 //Semicolan
#define KEY_AT 40 //@
#define KEY_BSLASH 86 //Backslash
#define KEY_Z 44
#define KEY_X 45
#define KEY_C 46
#define KEY_V 47
#define KEY_B 48
#define KEY_N 49
#define KEY_M 50
#define KEY_COMMA 51
#define KEY_PERIOD 52
#define KEY_FSLASH 53 //Forward slash
#define KEY_TILDE 41 //Console key
#define KEY_1 2
#define KEY_2 3
#define KEY_3 4
#define KEY_4 5
#define KEY_5 6
#define KEY_6 7
#define KEY_7 8
#define KEY_8 9
#define KEY_9 10
#define KEY_0 11
#define KEY_MINUS 12
#define KEY_PLUS 13
#define KEY_HASH 43 //#
#define KEY_F1 59
#define KEY_F2 60
#define KEY_F3 61
#define KEY_F4 62
#define KEY_F5 63
#define KEY_F6 64
#define KEY_F7 65
#define KEY_F8 66
#define KEY_F9 67
#define KEY_F10 68
#define KEY_F11 87
#define KEY_F12 88
#define KEY_INS 210
#define KEY_HOME 199
#define KEY_PAGEUP 201
#define KEY_DEL 211
#define KEY_END 207
#define KEY_PAGEDOWN 209
#define KEY_BACKSPACE 14
#define KEY_PRINTSCR 183
#define KEY_SCROLL 70
#define KEY_PAUSE 197
#define KEY_UP 200
#define KEY_DOWN 208
#define KEY_LEFT 203
#define KEY_RIGHT 205
#define KEY_L_CTRL 29
#define KEY_ALT 56
#define KEY_L_SHIFT 42
#define KEY_R_CTRL 157
#define KEY_R_SHIFT 54
#define KEY_ALTGR 184
#define KEY_L_WIN 219
#define KEY_R_WIN 220
#define KEY_TAB 15
#define KEY_CAPS 58
Just paste it into KeyDefs.h or something and #include it in your progs. For people too lazy to make their own for use with dbScanCode()

No defines for the numpad yet because i completly forgot, easy enough to add though
More later maybe
[07:16:59-pm] « Sephnroth » you were dreaming about lee...
[07:17:13-pm] « Mouse » stfu

[07:17:22-pm] « Mouse » he was hanging himself lol