Go Back   EQEmulator Home > EQEmulator Forums > Archives > Archive::Development > Archive::Development

Archive::Development Archive area for Development's posts that were moved here after an inactivity period of 90 days.

Reply
 
Thread Tools Display Modes
  #1  
Old 11-22-2003, 01:15 PM
Scorpious2k's Avatar
Scorpious2k
Demi-God
 
Join Date: Mar 2003
Location: USA
Posts: 1,067
Default dist calculations

Took a little time to look at the dist calcs... in Mob:ist it reads

Code:
float Mob::Dist(const Mob &other) {
    double xDiff = other.x_pos - x_pos; 	
     double yDiff = other.y_pos - y_pos; 	
     double zDiff = other.z_pos - z_pos;
     return sqrt( (xDiff * xDiff) 
 	           + (yDiff * yDiff)
                     + (zDiff * zDiff) ); 
}
Which looks about as efficient as you can get without going to assembler... but if you went to that level it might look like

Code:
float Mob::Dist(const Mob &other) 
{ 	
         double xDiff = other.x_pos - x_pos;
 	double yDiff = other.y_pos - y_pos;
 	double zDiff = other.z_pos - z_pos;
	double calctemp;
	float calcdist;

	__asm 
	{
		fld	xDiff
		fmul	xDiff
		fst	calctemp
		fld	yDiff
		fmul	yDiff
		fadd	calctemp
		fst	calctemp
		fld	zDiff
		fmul	zDiff
		fadd	calctemp
		fsqrt
		fst	calcdist
	}
	return calcdist;
}
Which might run in under 500 cycles....

Haven't tested this mind you, just a thought
__________________
Maybe I should try making one of these servers...
Reply With Quote
  #2  
Old 11-22-2003, 01:49 PM
DannMann99
Hill Giant
 
Join Date: Jun 2002
Posts: 205
Default

Not to get off topic but... i love the sig lol... kind of like the saying:
"I am a compulsive liar". Makes you wonder.

About the code, you should compile it and see what happens.
~Dan
Reply With Quote
  #3  
Old 11-22-2003, 02:05 PM
Scorpious2k's Avatar
Scorpious2k
Demi-God
 
Join Date: Mar 2003
Location: USA
Posts: 1,067
Default

Quote:
Originally Posted by DannMann99
i love the sig lol...
Thanks, it fits if you know me.

Quote:
About the code, you should compile it and see what happens.
I compiled it to check and see that it was clean, but we aren't running 5.0 at the moment so I have no way to test it. I wrote it sort of off the top of my head, so I'm not positive its exactly right.

I know that Trumpcard is looking for something like this and thought I would toss it out. If it works well enough, I'll do the rest of the dist calcs if he wants.
__________________
Maybe I should try making one of these servers...
Reply With Quote
  #4  
Old 11-23-2003, 07:56 PM
Mongrel
Hill Giant
 
Join Date: Jul 2003
Location: Germany
Posts: 232
Default

Why use doubles? I doubt we need 64 bit accuracy anyway, so unless someone is running a 64 bit server, floats are 2x faster and use half the memory space.
Reply With Quote
  #5  
Old 11-23-2003, 11:59 PM
Trumpcard
Demi-God
 
Join Date: Jan 2002
Location: Charlotte, NC
Posts: 2,614
Default

You're right, those should be floats...

The original programmer put them in as doubles, we've just never gone back around to fixing it...

Good catch on that, didnt even notice it.. I'll fix those in CVS tonight.
__________________
Quitters never win, and winners never quit, but those who never win and never quit are idiots.
Reply With Quote
  #6  
Old 11-24-2003, 01:30 PM
Scorpious2k's Avatar
Scorpious2k
Demi-God
 
Join Date: Mar 2003
Location: USA
Posts: 1,067
Default

At the assembly level, it doesn't seem to make a difference since they are all converted to 80 bit values on load. And I don't see a difference in the timing in it either.

I still agree the precision should be only what is needed because it creates overhead to convert in C++.
__________________
Maybe I should try making one of these servers...
Reply With Quote
  #7  
Old 02-06-2004, 01:42 AM
Eglin
Hill Giant
 
Join Date: Nov 2003
Posts: 168
Default Re: dist calculations

It is usually better to calculate distance squared, since you eliminate the root op.
Quote:
Originally Posted by Scorpious2k
Took a little time to look at the dist calcs... in Mob::Dist it reads
Code:
float Mob::Dist(const Mob &other) {
    double xDiff = other.x_pos - x_pos; 	
     double yDiff = other.y_pos - y_pos; 	
     double zDiff = other.z_pos - z_pos;
     return sqrt( (xDiff * xDiff) 
 	           + (yDiff * yDiff)
                     + (zDiff * zDiff) ); 
}
Which looks about as efficient as you can get without going to assembler... but if you went to that level it might look like
...<snip>...
Reply With Quote
  #8  
Old 02-06-2004, 05:07 PM
kathgar
Discordant
 
Join Date: May 2002
Posts: 434
Default

Thats what DistNoRoot and DistNoRootNoZ are for
__________________
++[>++++++<-]>[<++++++>-]<.>++++[>+++++<-]>[<
+++++>-]<+.+++++++..+++.>>+++++[<++++++>-]<+
+.<<+++++++++++++++.>.+++.------.--------.>+.
Reply With Quote
Reply


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

   

All times are GMT -4. The time now is 05:39 AM.


 

Everquest is a registered trademark of Daybreak Game Company LLC.
EQEmulator is not associated or affiliated in any way with Daybreak Game Company LLC.
Except where otherwise noted, this site is licensed under a Creative Commons License.
       
Powered by vBulletin®, Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Template by Bluepearl Design and vBulletin Templates - Ver3.3