Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

Code Snippets / The DarkSDK Collection

Author
Message
Sephnroth
22
Years of Service
User Offline
Joined: 10th Oct 2002
Location: United Kingdom
Posted: 12th Apr 2005 22:00 Edited at: 28th May 2005 09:01
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.


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:


DiffF:


DRand:


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:



Use it to get distance like this:



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:


Returns the angle between two points.

Second, a scancode listing to put in your own header file:


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
Sephnroth
22
Years of Service
User Offline
Joined: 10th Oct 2002
Location: United Kingdom
Posted: 18th Apr 2005 21:18
Update, fast 3d distance.

[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
Mr Snuggles
20
Years of Service
User Offline
Joined: 7th Dec 2004
Location:
Posted: 19th Apr 2005 05:07
The console key is called the "tilde" key.

ooo isn't that precious
Smithy
20
Years of Service
User Offline
Joined: 8th Dec 2004
Location: Switzerland
Posted: 23rd Apr 2005 02:32
@MOD(s)
Can you sticky this thread please?
(Or is there an dgSDK forum for code snippets coming up?)

//Pentium IV 3200E/Prescott; 800Mhz FSB; Hyperthreading; WinXP Pro (!XP2); ATI R9700PRO; 1024MB RAM (2x 512MB "DualChanneled"; VC++ 6.0; Delphi; ADSL;
Sephnroth
22
Years of Service
User Offline
Joined: 10th Oct 2002
Location: United Kingdom
Posted: 23rd Apr 2005 09:45
Wow, a sticky request X_X Thanks smithy, im glad you are finding it usful

Updated.

Added Diff, DiffF and DRand(). Also updated the key definitions replacing KEY_CON with KEY_TILDE - thanks snuggles

[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
Smithy
20
Years of Service
User Offline
Joined: 8th Dec 2004
Location: Switzerland
Posted: 8th May 2005 22:28
Yeah, sticky, I mean... almost all of the other code-snippets-threads are code written in DBC/DBPro,...

//Pentium IV 3200E/Prescott; 800Mhz FSB; Hyperthreading; WinXP Pro (!XP2); ATI R9700PRO; 1024MB RAM (2x 512MB "DualChanneled"; VC++ 6.0; Delphi; ADSL;
Smithy
20
Years of Service
User Offline
Joined: 8th Dec 2004
Location: Switzerland
Posted: 8th May 2005 22:36 Edited at: 10th May 2005 03:36
How to use C++ strings and dbPrint (or dbText etc)



//Pentium IV 3200E/Prescott; 800Mhz FSB; Hyperthreading; WinXP Pro (!XP2); ATI R9700PRO; 1024MB RAM (2x 512MB "DualChanneled"; VC++ 6.0; Delphi; ADSL;
Sephnroth
22
Years of Service
User Offline
Joined: 10th Oct 2002
Location: United Kingdom
Posted: 28th May 2005 09:02
UPDATED.
See the latest edit of the first post for a file from path function.

[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

Login to post a reply

Server time is: 2025-05-16 23:29:43
Your offset time is: 2025-05-16 23:29:43