Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 Turing's Built in Procedures?
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
Windsurfer




PostPosted: Fri Jul 07, 2006 9:09 pm   Post subject: Turing's Built in Procedures?

How could i access the code that runs Turing's built in stuff, specifically Draw.ThickLine?

Also, while I'm asking a question, what is the fastest sorting procedure for a large series (500 +) of random real numbers?
Sponsor
Sponsor
Sponsor
sponsor
[Gandalf]




PostPosted: Fri Jul 07, 2006 9:22 pm   Post subject: (No subject)

1. You mean what's build into Turing? You can't, unless you want to do a whole lot of reverse engineering. The rest can be found in the predefs folder.

2. 500? Any sort would do that no problem. QuickSort would work best, maybe, but unless you're using the Stupid Sort you can't go wrong.
Windsurfer




PostPosted: Fri Jul 07, 2006 9:36 pm   Post subject: Okay

Well, I was thinking of sorting the 500 every frame of a game, so it would need to be fast enough to do the sort at least 100 times a second. Bubble sort simply does not cut it. Is Quick sort really the fastest?
Clayton




PostPosted: Fri Jul 07, 2006 10:33 pm   Post subject: (No subject)

what game are you making that would require you to sort 500 items every frame of a game? wholy crap! why not set a predefined time in the game to sort (every 2 seconds, instead of every 10 milliseconds) using a fps limiter? also, on you sort method question, you should search for sorting algorithms in the Turing forums, I'm sure you will come up with something Very Happy
Delos




PostPosted: Fri Jul 07, 2006 10:54 pm   Post subject: (No subject)

Look for zylum's sorting routines in [Turing Source]. He has a bunch there, any QSort is definitely the way to go with something like that. For now, stick with whatever you're planning on doing. Once you're done, optimize.
wtd wrote:

Premature optimization is the (all_evil)^1/2.

Ok, so he didn't quite phrase it that way, but I'm feeling a tad whimsical (and sleep-deprived) right now Very Happy.
[Gandalf]




PostPosted: Fri Jul 07, 2006 11:19 pm   Post subject: (No subject)

Yeah, I highly doubt that you need to sort 500 items each frame at a rate of 100 frames per second. Even if you're doing 3D stuff where you have to sort each side you wouldn't need such... results. Instead of optimizing the various sorting routines which will never be amazingly fast in Turing, why don't you optimize your actual program and how it uses that sort in the first place.
Windsurfer




PostPosted: Sat Jul 08, 2006 10:36 pm   Post subject: **Sigh**

Well, i was thinking of taking a particle system and figuring out the layering of said particles or blocks so that it doesn't look stupid. That's why i would like it. However, i think, since no one really game me a straight response, that i'm going to need to look elsewhere. Ah well. Thanks for the reference to zylum's sorting routines, at least.
Delos




PostPosted: Sun Jul 09, 2006 12:10 am   Post subject: (No subject)

Direct response eh. Ok, for something like Draw.ThickLine() you're not going to be able to access Turing's built-in protocols. You can, however, create your own analagous procs and work from there. You can also add them to said modules - check out the tuts section, Tony wrote one explaining how to do so.
Sponsor
Sponsor
Sponsor
sponsor
Mazer




PostPosted: Sun Jul 09, 2006 8:21 am   Post subject: (No subject)

But also, making your own Draw.ThickLine() probably won't give you results as good as the one Turing already has, speed-wise.
Windsurfer




PostPosted: Mon Jul 10, 2006 9:48 pm   Post subject: (No subject)

Mazer wrote:
But also, making your own Draw.ThickLine() probably won't give you results as good as the one Turing already has, speed-wise.


Why not? I read somewhere that a lot of turing is made using turing code, so why can't i just tweak it a bit and have it just as fast? Like, sure, maaaybe they coded Draw.ThickLine() in assembly or C, but I ighly doubt it, especially considering how it's a fairly new addition.
Tony




PostPosted: Mon Jul 10, 2006 11:54 pm   Post subject: (No subject)

to answer the Draw.ThickLine question - BenchMarking!

as for sorting - I would imagine that you don't need to sort, just keep z-index of objects relative to each other. Perhaps updates on creation/destruction of objects, but even then it could be a partial sort (sort just a sub-set). There should be no need to sort during every frame.
Latest from compsci.ca/blog: Tony's programming blog. DWITE - a programming contest.
zylum




PostPosted: Tue Jul 11, 2006 1:11 am   Post subject: (No subject)

here's a drawline function that works slightly faster than Tony's but is still about twice as slow as the native one:

code:
proc DrawThickLine (x1, y1, x2, y2, w, c : int)

    var x : array 1 .. 4 of int
    var y : array 1 .. 4 of int

    var m := sqrt ((x2 - x1) ** 2 + (y2 - y1) ** 2)

    var i := (y2 - y1) / m
    var j := (x2 - x1) / m

    var width := w / 2

    x (1) := round (x1 + i * width)
    x (2) := round (x1 - i * width)
    x (3) := round (x2 - i * width)
    x (4) := round (x2 + i * width)

    y (1) := round (y1 - j * width)
    y (2) := round (y1 + j * width)
    y (3) := round (y2 + j * width)
    y (4) := round (y2 - j * width)

    Draw.FillPolygon (x, y, 4, c)
    Draw.FillOval (x1, y1, round (width - 1), round (width - 1), c)
    Draw.FillOval (x2, y2, round (width - 1), round (width - 1), c)

end DrawThickLine


as for the sorting, sorting ~500 particles every frame may slow down your program. the thing is, you only need to sort overlapping particles. in a particle engine, this doesnt happen very often, especially with such few particles (unless they are big).
McKenzie




PostPosted: Tue Jul 11, 2006 11:46 am   Post subject: (No subject)

There is a Windows API call to draw a thick line. You can bet Holt is just using that one.
[Gandalf]




PostPosted: Tue Jul 11, 2006 10:23 pm   Post subject: (No subject)

To find out if a function used in Turing is coded in Turing or in another language (ie. C) just look in the predefs folder. If the function contains the keyword extern, it was coded outside of Turing. If not, then you will see the Turing code right there in the module.
Display posts from previous:   
   Index -> Programming, Turing -> Turing Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 14 Posts ]
Jump to:   


Style:  
Search: