|
3 registered members (AndrewAMD, juanex, Grant),
1,018
guests, and 8
spiders. |
|
Key:
Admin,
Global Mod,
Mod
|
|
|
ent_next problem
#389962
12/20/11 14:58
12/20/11 14:58
|
Joined: Feb 2010
Posts: 886
Random
OP
User
|
OP
User
Joined: Feb 2010
Posts: 886
|
I have another little question. I notice that "ent_next" uses all entities. Which means, that in the example below, every entity with "entity_typ = 3" becomes invisible. But I want that only the nearest entity with "entity_typ = 3" becomes invisible. Also the entity should become visible again, if it is not the nearest entity with "entity_typ = 3" anymore. example: for (you = ent_next(NULL); you != NULL; you = ent_next(you)) { if ((you != my) && (you.entity_typ == 3)) { set(you,INVISIBLE); } else { reset(my,INVISIBLE); } } Does anyone know how to do that?
|
|
|
Re: ent_next problem
[Re: Random]
#389963
12/20/11 14:58
12/20/11 14:58
|
Joined: Feb 2010
Posts: 886
Random
OP
User
|
OP
User
Joined: Feb 2010
Posts: 886
|
So this is my biggest problem, right now. Really...
|
|
|
Re: ent_next problem
[Re: krial057]
#389970
12/20/11 17:34
12/20/11 17:34
|
Joined: Feb 2008
Posts: 3,232 Australia
EvilSOB
Expert
|
Expert
Joined: Feb 2008
Posts: 3,232
Australia
|
I assume you are talking about the entity nearest to ME, so here goes.
ENTITY* nearest=NULL; //GLOBAL entity pointer, or just OUTSIDE do-while loop
...
if(nearest!=NULL) { reset(nearest, INVISIBLE); }
for(you=ent_next(NULL); you!=NULL; you=ent_next(you))
{
if ((you != my) && (you.entity_typ == 3))
{
if(nearest==NULL)
{ nearest = you; set(you,INVISIBLE); }
else
{
if(vec_dist(you.x,me.x)<vec_dist(nearest.x,me.x))
{ nearest = you; set(you,INVISIBLE); }
}
}
}
...
I think that should do the trick...
"There is no fate but what WE make." - CEO Cyberdyne Systems Corp. A8.30.5 Commercial
|
|
|
Re: ent_next problem
[Re: EvilSOB]
#390023
12/21/11 15:26
12/21/11 15:26
|
Joined: Feb 2010
Posts: 886
Random
OP
User
|
OP
User
Joined: Feb 2010
Posts: 886
|
Works perfectly! Yes, that does more then the trick ^^
|
|
|
Re: ent_next problem
[Re: Random]
#390025
12/21/11 15:43
12/21/11 15:43
|
Joined: Jul 2008
Posts: 894
TechMuc
User
|
User
Joined: Jul 2008
Posts: 894
|
please do not recalculate the distance of the nearest pointer on an on, but store the distance in a temporary variable and compare the distance of the next entity against it. e.g. if(nearest == null) { nearest = you; nearest_temp = vec_dist(you.x,me.x); } else if(vec_dist(you.x,me.x) < nearest_temp) { nearest_temp = vec_dist(you.x,me.x); //.. never forget the performance 
|
|
|
Re: ent_next problem
[Re: TechMuc]
#390075
12/22/11 08:17
12/22/11 08:17
|
Joined: Feb 2008
Posts: 3,232 Australia
EvilSOB
Expert
|
Expert
Joined: Feb 2008
Posts: 3,232
Australia
|
I do agree with TechMuc. My code is not very efficient, but it WAS only written to explain a point... A MORE efficient method, in line with TechMuc is as follows...
ENTITY* nearest=NULL; //GLOBAL entity pointer, or just OUTSIDE do-while loop
...
var nearest_dist;
if(nearest!=NULL) { reset(nearest, INVISIBLE); }
for(you=ent_next(NULL); you!=NULL; you=ent_next(you))
{
if ((you != my) && (you.entity_typ == 3))
{
if(nearest==NULL)
{ nearest = you; set(you,INVISIBLE);
nearest_dist = vec_dist(you.x, me.x); }
else
{
if(vec_dist(you.x, me.x) < nearest_dist)
{ nearest = you; set(you,INVISIBLE);
nearest_dist = vec_dist(you.x, me.x); }
}
}
}
...
By the way ... where did you get the idea for the "for(you=ent_next(NULL); you!=NULL; you=ent_next(you))" from? Excellent way of handling ??_next searching... Much more efficient than my usual way with "while(1)"'s.
"There is no fate but what WE make." - CEO Cyberdyne Systems Corp. A8.30.5 Commercial
|
|
|
|