Lets make a game...

Started by
15 comments, last by HellRiZZer 21 years, 2 months ago
lol remind me to never post code here you guys are brutal
Advertisement
You should welcome constructive criticism from others, it''s a significant aid to improving code (and many other things). In fact it''s probably the most significant aid since (in my experience) many people get stuck in coding ruts and, without someone else''s help, rarely uncover their own flaws.
Further to what Dobbs posted, in general, try to avoid the ''=='' and ''!='' operators when used in conjunction with floating point values. I always use this code to demonstrate why those operators are dangerous with floating point values:


  int main (int argc, char *argv){	for (float value = 0.0f ; value < 2.0f ; value += 0.05f)	{		printf ("Does %.02f == 1? %s\n", value, value == 1.0f ? "Yes" : "No");	}	return 0;}  


Try the above and see what happens. Then work out why.

Skizz
when we are talking about square roots you could use a large lookup table to get the values you want

of course precision suffers a bit but who cares about precision

take a 2 mb chunk of your memory for the lookup table and you should be able to get squareroots from 0-2000 with a precision of 0.001
http://www.8ung.at/basiror/theironcross.html
2mb? You''d have to be nuts about your lookup table to use so much memory for it .


The way I see it

(0-2000)
100 * 2001 * 4 (float) / 1024 = ~781.25kb

Which still seems like quite a bit for a lookup table, it would probably be better to reduce precision by 10 to get it to 78.13kb

Although that is still quite a bit, there are a number of ways to optimize the memory while inflicting a smaller calculation cost. (i.e. do you really need a float to store a number thats 0-2000?)

Since we are all in a mood for constructive critism .

-------
Homepage: http://students.washington.edu/andrey
-------Homepage: http://www.pclx.com
quote:Original post by Basiror
when we are talking about square roots you could use a large lookup table to get the values you want

of course precision suffers a bit but who cares about precision

take a 2 mb chunk of your memory for the lookup table and you should be able to get squareroots from 0-2000 with a precision of 0.001


2MB lookup table? are you sane? Ever heard about caches ?
With intrinsic functions enabled sqrt() or sqrtf() will generate something like:

fld var
fsqrt
fstp var

which takes about 80 clock cycles on a Pentium 3
Thanks to everyone posting replies on this topic (and torring my code apart), I really appreciate that.
Although that code was originally been written by Bas Kuenen (with some of my updates), I will try to consider all your thoughts and ideas.
Thanks again.

" Do we need us? "


Ionware Productions - Games and Game Tools Development

This topic is closed to new replies.

Advertisement