waypoints should hopefully be a little faster :)

This commit is contained in:
Bill Currie 2003-07-24 20:23:03 +00:00
parent ae3e600a7f
commit 35be5480ca
2 changed files with 88 additions and 132 deletions

View file

@ -43,8 +43,9 @@ this notice in its entirety.
*/ */
#include "libfrikbot.h" #include "libfrikbot.h"
#include "Array.h"
Waypoint way_foot; // Ugh. Do I need a foot for this or not? @static Array waypoint_array;
@implementation Target @implementation Target
@ -76,6 +77,57 @@ Waypoint way_foot; // Ugh. Do I need a foot for this or not?
@implementation Waypoint @implementation Waypoint
-(id)init
{
if (!waypoint_array)
waypoint_array = [[Array alloc] init];
return [super init];
}
-(id)initAt:(vector)org
{
[self init];
[waypoint_array addItem: self];
return self;
}
-(id)initFromEntity:(entity)ent
{
[self initAt:ent.origin];
}
/*
entity (vector org)
make_waypoint =
{
local entity point;
point = spawn ();
point.classname = "waypoint";
point.search_time = time; // don't double back for me;
point.solid = SOLID_TRIGGER;
point.movetype = MOVETYPE_NONE;
point.items = -1;
setorigin (point, org);
setsize (point, VEC_HULL_MIN, VEC_HULL_MAX);
waypoints++;
if (!way_head) {
way_head = point;
way_foot = point;
} else {
way_foot._next = point;
point._last = way_foot;
way_foot = point;
}
point.count = waypoints;
if (waypoint_mode > WM_LOADED) // editor modes
setmodel (point, "progs/s_bubble.spr");
return point;
};
*/
-(integer)isLinkedTo:(Waypoint)way -(integer)isLinkedTo:(Waypoint)way
{ {
local integer i; local integer i;
@ -148,59 +200,6 @@ Waypoint way_foot; // Ugh. Do I need a foot for this or not?
} }
} }
// Waypoint Spawning Code =====================================================
-(id)initAt:(vector)org
{
count = ++waypoints;
if (!way_head) {
way_head = self;
way_foot = self;
} else {
way_foot.next = self;
self.prev = way_foot;
way_foot = self;
}
return self;
}
-(id)initFromEntity:(entity)ent
{
[self initAt:ent.origin];
}
/*
entity (vector org)
make_waypoint =
{
local entity point;
point = spawn ();
point.classname = "waypoint";
point.search_time = time; // don't double back for me;
point.solid = SOLID_TRIGGER;
point.movetype = MOVETYPE_NONE;
point.items = -1;
setorigin (point, org);
setsize (point, VEC_HULL_MIN, VEC_HULL_MAX);
waypoints++;
if (!way_head) {
way_head = point;
way_foot = point;
} else {
way_foot._next = point;
point._last = way_foot;
way_foot = point;
}
point.count = waypoints;
if (waypoint_mode > WM_LOADED) // editor modes
setmodel (point, "progs/s_bubble.spr");
return point;
};
*/
/* /*
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
@ -211,33 +210,13 @@ Waypoint Loading from file
+(void)clearAll +(void)clearAll
{ {
[waypoint_array free];
local Waypoint t, n; waypoint_array = [[Array alloc] init];
t = way_head;
while(t) {
n = t.next;
[t free];
t = n;
}
way_head = NIL;
way_foot = NIL;
waypoints = 0;
} }
+(Waypoint)waypointForNum:(integer)num +(Waypoint)waypointForNum:(integer)num
{ {
local Waypoint t; return [waypoint_array getItemAt:num];
if (!num)
return NIL;
t = way_head;
while (t) {
if (t.count == num)
return t;
t = t.next;
}
return NIL;
} }
-(void)fix -(void)fix
@ -250,10 +229,7 @@ Waypoint Loading from file
+(void) fixWaypoints +(void) fixWaypoints
{ {
local Waypoint way; [waypoint_array makeObjectsPerformSelector:@selector(fix)];
for (way = way_head; way; way = way.next)
[way fix];
} }
/* /*
@ -264,32 +240,30 @@ Route & path table management
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
*/ */
-(void)clearRoute
{
keys = FALSE;
enemy = NIL;
items = -1; // not in table
}
+(void)clearRouteTable +(void)clearRouteTable
{ {
// cleans up route table // cleans up route table
[waypoint_array makeObjectsPerformSelector:@selector (clearRoute)];
}
local Waypoint t; -(void)clearRouteForBot:(Bot)bot
t = way_head; {
while (t) { local integer flag;
t.keys = FALSE; flag = ClientBitFlag(bot.b_clientno);
t.enemy = NIL; b_sound &= ~flag;
t.items = -1; // not in table
t = t.next;
}
} }
+(void)clearMyRoute:(Bot) bot +(void)clearMyRoute:(Bot) bot
{ {
local integer flag; [waypoint_array makeObjectsPerformSelector:@selector (clearRoute)
local Waypoint t; withObject:bot];
flag = ClientBitFlag(bot.b_clientno);
t = way_head;
while (t) {
t.b_sound &= ~flag;
t = t.next;
}
} }
/* /*
@ -441,59 +415,41 @@ Finds the closest, fisible, waypoint to e
local Waypoint best, t; local Waypoint best, t;
local float dst, tdst; local float dst, tdst;
local vector org; local vector org;
local integer count, i;
org = realorigin (ent); org = realorigin (ent);
t = way_head; if (start) {
if (start != NIL) {
dst = vlen (start.origin - org); dst = vlen (start.origin - org);
best = start; best = start;
} else { } else {
dst = 100000; dst = 100000;
best = NIL; best = NIL;
} }
while (t) { count = [waypoint_array count];
for (i = 0; i < count; i++) {
t = [waypoint_array getItemAt:i];
// real players cut through ignore types // real players cut through ignore types
if (dst < 20) if (dst < 20)
return best; return best;
if (!(t.flags & AI_IGNORE_TYPES) || ishuman) { if (!(t.flags & AI_IGNORE_TYPES) || ishuman) {
tdst = vlen (t.origin - org); tdst = vlen (t.origin - org);
if (tdst < dst) { if (tdst < dst) {
/*XXX if (sisible (ent, t.ent)) {
if (sisible (t)) {
dst = tdst; dst = tdst;
best = t; best = t;
} }
*/
} }
} }
t = t.next;
} }
return best; return best;
} }
-(void)deleteWaypoint:(Waypoint)what -(void)deleteWaypoint:(Waypoint)what
{ {
local Waypoint t;
if (way_head == what)
way_head = what.next;
if (way_foot == what)
way_foot = what.prev;
if (what.prev)
what.prev.next = what.next;
if (what.next)
what.next.prev = what.prev;
waypoints = 0;
t = way_head;
while(t) {
t.count = waypoints = waypoints + 1;
if ([t isLinkedTo:what])
[t unlinkWay:what];
t = t.next;
}
if (self.current_way == what) if (self.current_way == what)
self.current_way = NIL; self.current_way = NIL;
[waypoint_array removeItem:what];
[what free]; [what free];
} }
@ -545,12 +501,14 @@ an object.
local Waypoint t, best; local Waypoint t, best;
local float dst, tdst; local float dst, tdst;
local integer flag; local integer flag;
local integer count, i;
flag = ClientBitFlag(b_clientno); flag = ClientBitFlag(b_clientno);
t = way_head;
dst = 100000; dst = 100000;
best = NIL; best = NIL;
while(t) { count = [waypoint_array count];
for (i = 0; i < count; i++) {
t = [waypoint_array getItemAt:i];
tdst = vlen(t.origin - ent.origin); tdst = vlen(t.origin - ent.origin);
if ((tdst < dst) && (t.b_sound & flag)) { if ((tdst < dst) && (t.b_sound & flag)) {
if ((lastone == NIL) || ([lastone isLinkedTo:t])) { if ((lastone == NIL) || ([lastone isLinkedTo:t])) {
@ -558,7 +516,6 @@ an object.
best = t; best = t;
} }
} }
t = t.next;
} }
return best; return best;
} }

View file

@ -14,10 +14,8 @@
{ {
@public @public
Waypoint [4] targets; Waypoint [4] targets;
Waypoint next, prev;
integer flags; integer flags;
vector origin; vector origin;
integer count;
integer b_pants, b_skill, b_shirt, b_frags, b_sound; integer b_pants, b_skill, b_shirt, b_frags, b_sound;
integer keys; integer keys;
@ -33,7 +31,7 @@
+(void)clearMyRoute:(Bot) bot; +(void)clearMyRoute:(Bot) bot;
-(void)fix; -(void)fix;
//-(id)init; -(id)init;
-(id)initAt:(vector)org; -(id)initAt:(vector)org;
-(id)initFromEntity:(entity)ent; -(id)initFromEntity:(entity)ent;
@ -44,6 +42,9 @@
-(void)followLink:(Waypoint)e2 :(integer)b_bit; -(void)followLink:(Waypoint)e2 :(integer)b_bit;
-(void)waypointThink; -(void)waypointThink;
-(void)clearRoute;
-(void)clearRouteForBot:(Bot)bot;
@end @end
@interface Bot: Target @interface Bot: Target
@ -232,14 +233,12 @@
@extern float real_frametime; @extern float real_frametime;
@extern float bot_count, b_options, lasttime; @extern float bot_count, b_options, lasttime;
@extern float waypoint_mode, dump_mode; @extern float waypoint_mode, dump_mode;
@extern integer waypoints;
@extern float direct_route, userid; @extern float direct_route, userid;
@extern float sv_friction, sv_gravity; @extern float sv_friction, sv_gravity;
@extern float sv_accelerate, sv_maxspeed, sv_stopspeed; @extern float sv_accelerate, sv_maxspeed, sv_stopspeed;
@extern entity fixer; @extern entity fixer;
@extern Bot route_table; @extern Bot route_table;
@extern entity b_temp1, b_temp2, b_temp3; @extern entity b_temp1, b_temp2, b_temp3;
@extern Waypoint way_head;
@extern float busy_waypoints; @extern float busy_waypoints;
@extern float coop; @extern float coop;