diff options
Diffstat (limited to 'src/jake2/server/SV_WORLD.java')
-rw-r--r-- | src/jake2/server/SV_WORLD.java | 273 |
1 files changed, 135 insertions, 138 deletions
diff --git a/src/jake2/server/SV_WORLD.java b/src/jake2/server/SV_WORLD.java index 4e78084..2eb2ca6 100644 --- a/src/jake2/server/SV_WORLD.java +++ b/src/jake2/server/SV_WORLD.java @@ -19,7 +19,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ // Created on 07.01.2000 by RST. -// $Id: SV_WORLD.java,v 1.3 2004-07-08 20:24:30 hzi Exp $ +// $Id: SV_WORLD.java,v 1.4 2004-07-09 06:50:49 hzi Exp $ package jake2.server; @@ -48,14 +48,13 @@ public class SV_WORLD extends SV_CCMDS //=============================================================================== // - public static void initNodes() { - for (int n = 0; n < AREA_NODES; n++) - sv_areanodes[n] = new areanode_t(); + for (int n= 0; n < AREA_NODES; n++) + sv_areanodes[n]= new areanode_t(); } - public static areanode_t sv_areanodes[] = new areanode_t[AREA_NODES]; + public static areanode_t sv_areanodes[]= new areanode_t[AREA_NODES]; static { initNodes(); @@ -70,21 +69,21 @@ public class SV_WORLD extends SV_CCMDS // ClearLink is used for new headnodes public static void ClearLink(link_t l) { - l.prev = l.next = l; + l.prev= l.next= l; } public static void RemoveLink(link_t l) { - l.next.prev = l.prev; - l.prev.next = l.next; + l.next.prev= l.prev; + l.prev.next= l.next; } public static void InsertLinkBefore(link_t l, link_t before) { - l.next = before; - l.prev = before.prev; - l.prev.next = l; - l.next.prev = l; + l.next= before; + l.prev= before.prev; + l.prev.next= l; + l.next.prev= l; } /* @@ -97,10 +96,10 @@ public class SV_WORLD extends SV_CCMDS public static areanode_t SV_CreateAreaNode(int depth, float[] mins, float[] maxs) { areanode_t anode; - float[] size = { 0, 0, 0 }; - float[] mins1 = { 0, 0, 0 }, maxs1 = { 0, 0, 0 }, mins2 = { 0, 0, 0 }, maxs2 = { 0, 0, 0 }; + float[] size= { 0, 0, 0 }; + float[] mins1= { 0, 0, 0 }, maxs1= { 0, 0, 0 }, mins2= { 0, 0, 0 }, maxs2= { 0, 0, 0 }; - anode = sv_areanodes[sv_numareanodes]; + anode= sv_areanodes[sv_numareanodes]; // just for debugging (rst) VectorCopy(mins, anode.mins_rst); @@ -113,27 +112,27 @@ public class SV_WORLD extends SV_CCMDS if (depth == AREA_DEPTH) { - anode.axis = -1; - anode.children[0] = anode.children[1] = null; + anode.axis= -1; + anode.children[0]= anode.children[1]= null; return anode; } VectorSubtract(maxs, mins, size); if (size[0] > size[1]) - anode.axis = 0; + anode.axis= 0; else - anode.axis = 1; + anode.axis= 1; - anode.dist = 0.5f * (maxs[anode.axis] + mins[anode.axis]); + anode.dist= 0.5f * (maxs[anode.axis] + mins[anode.axis]); VectorCopy(mins, mins1); VectorCopy(mins, mins2); VectorCopy(maxs, maxs1); VectorCopy(maxs, maxs2); - maxs1[anode.axis] = mins2[anode.axis] = anode.dist; + maxs1[anode.axis]= mins2[anode.axis]= anode.dist; - anode.children[0] = SV_CreateAreaNode(depth + 1, mins2, maxs2); - anode.children[1] = SV_CreateAreaNode(depth + 1, mins1, maxs1); + anode.children[0]= SV_CreateAreaNode(depth + 1, mins2, maxs2); + anode.children[1]= SV_CreateAreaNode(depth + 1, mins1, maxs1); return anode; } @@ -147,7 +146,7 @@ public class SV_WORLD extends SV_CCMDS public static void SV_ClearWorld() { initNodes(); - sv_numareanodes = 0; + sv_numareanodes= 0; SV_CreateAreaNode(0, sv.models[1].mins, sv.models[1].maxs); /* @@ -178,7 +177,7 @@ public class SV_WORLD extends SV_CCMDS if (null == ent.area.prev) return; // not linked in anywhere RemoveLink(ent.area); - ent.area.prev = ent.area.next = null; + ent.area.prev= ent.area.next= null; } /* @@ -186,18 +185,18 @@ public class SV_WORLD extends SV_CCMDS SV_LinkEdict =============== */ - public static final int MAX_TOTAL_ENT_LEAFS = 128; - + public static final int MAX_TOTAL_ENT_LEAFS= 128; + private static int leafs[]= new int[MAX_TOTAL_ENT_LEAFS]; + private static int clusters[]= new int[MAX_TOTAL_ENT_LEAFS]; + public static void SV_LinkEdict(edict_t ent) { areanode_t node; - // TODO: make static instead of new - int leafs[] = new int[MAX_TOTAL_ENT_LEAFS]; - int clusters[] = new int[MAX_TOTAL_ENT_LEAFS]; + int num_leafs; int j, k; int area; - int topnode = 0; + int topnode= 0; if (ent.area.prev != null) SV_UnlinkEdict(ent); // unlink from old position @@ -214,54 +213,54 @@ public class SV_WORLD extends SV_CCMDS // encode the size into the entity_state for client prediction if (ent.solid == SOLID_BBOX && 0 == (ent.svflags & SVF_DEADMONSTER)) { // assume that x/y are equal and symetric - int i = (int) (ent.maxs[0] / 8); + int i= (int) (ent.maxs[0] / 8); if (i < 1) - i = 1; + i= 1; if (i > 31) - i = 31; + i= 31; // z is not symetric - j = (int) ((-ent.mins[2]) / 8); + j= (int) ((-ent.mins[2]) / 8); if (j < 1) - j = 1; + j= 1; if (j > 31) - j = 31; + j= 31; // and z maxs can be negative... - k = (int) ((ent.maxs[2] + 32) / 8); + k= (int) ((ent.maxs[2] + 32) / 8); if (k < 1) - k = 1; + k= 1; if (k > 63) - k = 63; + k= 63; - ent.s.solid = (k << 10) | (j << 5) | i; + ent.s.solid= (k << 10) | (j << 5) | i; } else if (ent.solid == SOLID_BSP) { - ent.s.solid = 31; // a solid_bbox will never create this value + ent.s.solid= 31; // a solid_bbox will never create this value } else - ent.s.solid = 0; + ent.s.solid= 0; // set the abs box if (ent.solid == SOLID_BSP && (ent.s.angles[0] != 0 || ent.s.angles[1] != 0 || ent.s.angles[2] != 0)) { // expand for rotation float max, v; - max = 0; - for (int i = 0; i < 3; i++) + max= 0; + for (int i= 0; i < 3; i++) { - v = Math.abs(ent.mins[i]); + v= Math.abs(ent.mins[i]); if (v > max) - max = v; - v = Math.abs(ent.maxs[i]); + max= v; + v= Math.abs(ent.maxs[i]); if (v > max) - max = v; + max= v; } - for (int i = 0; i < 3; i++) + for (int i= 0; i < 3; i++) { - ent.absmin[i] = ent.s.origin[i] - max; - ent.absmax[i] = ent.s.origin[i] + max; + ent.absmin[i]= ent.s.origin[i] - max; + ent.absmax[i]= ent.s.origin[i] + max; } } else @@ -281,62 +280,65 @@ public class SV_WORLD extends SV_CCMDS ent.absmax[2]++; // link to PVS leafs - ent.num_clusters = 0; - ent.areanum = 0; - ent.areanum2 = 0; + ent.num_clusters= 0; + ent.areanum= 0; + ent.areanum2= 0; //get all leafs, including solids - CM.intwrap iw = new CM.intwrap(topnode); + int iw[] = {topnode}; - num_leafs = CM.CM_BoxLeafnums(ent.absmin, ent.absmax, leafs, MAX_TOTAL_ENT_LEAFS, iw); + num_leafs= CM.CM_BoxLeafnums(ent.absmin, ent.absmax, leafs, MAX_TOTAL_ENT_LEAFS, iw); - topnode = iw.i; + topnode= iw[0]; // set areas - for (int i = 0; i < num_leafs; i++) + for (int i= 0; i < num_leafs; i++) { - clusters[i] = CM.CM_LeafCluster(leafs[i]); - area = CM.CM_LeafArea(leafs[i]); + clusters[i]= CM.CM_LeafCluster(leafs[i]); + area= CM.CM_LeafArea(leafs[i]); if (area != 0) - { // doors may legally straggle two areas, + { + // doors may legally straggle two areas, // but nothing should evern need more than that if (ent.areanum != 0 && ent.areanum != area) { if (ent.areanum2 != 0 && ent.areanum2 != area && sv.state == ss_loading) Com.DPrintf("Object touching 3 areas at " + ent.absmin[0] + " " + ent.absmin[1] + " " + ent.absmin[2] + "\n"); - ent.areanum2 = area; + ent.areanum2= area; } else - ent.areanum = area; + ent.areanum= area; } } if (num_leafs >= MAX_TOTAL_ENT_LEAFS) - { // assume we missed some leafs, and mark by headnode - ent.num_clusters = -1; - ent.headnode = topnode; + { + // assume we missed some leafs, and mark by headnode + ent.num_clusters= -1; + ent.headnode= topnode; } else { - ent.num_clusters = 0; - for (int i = 0; i < num_leafs; i++) + ent.num_clusters= 0; + for (int i= 0; i < num_leafs; i++) { if (clusters[i] == -1) continue; // not a visible leaf - for (j = 0; j < i; j++) + for (j= 0; j < i; j++) if (clusters[j] == clusters[i]) break; if (j == i) { if (ent.num_clusters == MAX_ENT_CLUSTERS) - { // assume we missed some leafs, and mark by headnode - ent.num_clusters = -1; - ent.headnode = topnode; + { + // assume we missed some leafs, and mark by headnode + ent.num_clusters= -1; + ent.headnode= topnode; break; } - ent.clusternums[ent.num_clusters++] = clusters[i]; + ent.clusternums[ent.num_clusters++]= clusters[i]; } } } @@ -352,16 +354,16 @@ public class SV_WORLD extends SV_CCMDS return; // find the first node that the ent's box crosses - node = sv_areanodes[0]; + node= sv_areanodes[0]; while (true) { if (node.axis == -1) break; if (ent.absmin[node.axis] > node.dist) - node = node.children[0]; + node= node.children[0]; else if (ent.absmax[node.axis] < node.dist) - node = node.children[1]; + node= node.children[1]; else break; // crosses the node } @@ -386,19 +388,18 @@ public class SV_WORLD extends SV_CCMDS edict_t check; int count; - count = 0; + count= 0; // touch linked edicts if (area_type == AREA_SOLID) - start = node.solid_edicts; + start= node.solid_edicts; else - start = node.trigger_edicts; + start= node.trigger_edicts; - for (l = start.next; l != start; l = next) + for (l= start.next; l != start; l= next) { - next = l.next; - check = //EDICT_FROM_AREA(l); - (edict_t) l.o; + next= l.next; + check= (edict_t) l.o; if (check.solid == SOLID_NOT) continue; // deactivated @@ -416,7 +417,7 @@ public class SV_WORLD extends SV_CCMDS return; } - area_list[area_count] = check; + area_list[area_count]= check; area_count++; } @@ -438,57 +439,53 @@ public class SV_WORLD extends SV_CCMDS */ public static int SV_AreaEdicts(float[] mins, float[] maxs, edict_t list[], int maxcount, int areatype) { - area_mins = mins; - area_maxs = maxs; - area_list = list; - area_count = 0; - area_maxcount = maxcount; - area_type = areatype; + area_mins= mins; + area_maxs= maxs; + area_list= list; + area_count= 0; + area_maxcount= maxcount; + area_type= areatype; SV_AreaEdicts_r(sv_areanodes[0]); - /* - Com.Printf("found edicts in area:" + area_count + "\n"); - for (int n = 0; n < area_count; n++) { - Com.Printf("%4i : %25s", new Vargs().add(n).add(list[n].classname)); - } - */ return area_count; } //=========================================================================== + private static edict_t touch[]= new edict_t[MAX_EDICTS]; /* ============= SV_PointContents ============= */ + public static int SV_PointContents(float[] p) { - // TODO: make static instead new - edict_t touch[] = new edict_t[MAX_EDICTS], hit; + edict_t hit; + int i, num; int contents, c2; int headnode; float angles[]; // get base contents from world - contents = CM.PointContents(p, sv.models[1].headnode); + contents= CM.PointContents(p, sv.models[1].headnode); // or in contents from all the other entities - num = SV_AreaEdicts(p, p, touch, MAX_EDICTS, AREA_SOLID); + num= SV_AreaEdicts(p, p, touch, MAX_EDICTS, AREA_SOLID); - for (i = 0; i < num; i++) + for (i= 0; i < num; i++) { - hit = touch[i]; + hit= touch[i]; // might intersect, so do an exact clip - headnode = SV_HullForEntity(hit); - angles = hit.s.angles; + headnode= SV_HullForEntity(hit); + angles= hit.s.angles; if (hit.solid != SOLID_BSP) - angles = vec3_origin; // boxes don't rotate + angles= vec3_origin; // boxes don't rotate - c2 = CM.TransformedPointContents(p, headnode, hit.s.origin, hit.s.angles); + c2= CM.TransformedPointContents(p, headnode, hit.s.origin, hit.s.angles); contents |= c2; } @@ -514,7 +511,7 @@ public class SV_WORLD extends SV_CCMDS // decide which clipping hull to use, based on the size if (ent.solid == SOLID_BSP) { // explicit hulls in the BSP model - model = sv.models[ent.s.modelindex]; + model= sv.models[ent.s.modelindex]; if (null == model) Com.Error(ERR_FATAL, "MOVETYPE_PUSH with a non bsp model"); @@ -535,23 +532,23 @@ public class SV_WORLD extends SV_CCMDS ==================== */ + private static edict_t touchlist[]= new edict_t[MAX_EDICTS]; public static void SV_ClipMoveToEntities(moveclip_t clip) { int i, num; - // TODO: make static instead of new - edict_t touchlist[] = new edict_t[MAX_EDICTS]; + edict_t touch; trace_t trace; int headnode; float angles[]; - num = SV_AreaEdicts(clip.boxmins, clip.boxmaxs, touchlist, MAX_EDICTS, AREA_SOLID); + num= SV_AreaEdicts(clip.boxmins, clip.boxmaxs, touchlist, MAX_EDICTS, AREA_SOLID); // be careful, it is possible to have an entity in this // list removed before we get to it (killtriggered) - for (i = 0; i < num; i++) + for (i= 0; i < num; i++) { - touch = touchlist[i]; + touch= touchlist[i]; if (touch.solid == SOLID_NOT) continue; if (touch == clip.passedict) @@ -570,13 +567,13 @@ public class SV_WORLD extends SV_CCMDS continue; // might intersect, so do an exact clip - headnode = SV_HullForEntity(touch); - angles = touch.s.angles; + headnode= SV_HullForEntity(touch); + angles= touch.s.angles; if (touch.solid != SOLID_BSP) - angles = vec3_origin; // boxes don't rotate + angles= vec3_origin; // boxes don't rotate if ((touch.svflags & SVF_MONSTER) != 0) - trace = + trace= CM.TransformedBoxTrace( clip.start, clip.end, @@ -587,7 +584,7 @@ public class SV_WORLD extends SV_CCMDS touch.s.origin, angles); else - trace = + trace= CM.TransformedBoxTrace( clip.start, clip.end, @@ -600,17 +597,17 @@ public class SV_WORLD extends SV_CCMDS if (trace.allsolid || trace.startsolid || trace.fraction < clip.trace.fraction) { - trace.ent = touch; + trace.ent= touch; if (clip.trace.startsolid) { - clip.trace = trace; - clip.trace.startsolid = true; + clip.trace= trace; + clip.trace.startsolid= true; } else clip.trace.set(trace); } else if (trace.startsolid) - clip.trace.startsolid = true; + clip.trace.startsolid= true; } } @@ -623,17 +620,17 @@ public class SV_WORLD extends SV_CCMDS { int i; - for (i = 0; i < 3; i++) + for (i= 0; i < 3; i++) { if (end[i] > start[i]) { - boxmins[i] = start[i] + mins[i] - 1; - boxmaxs[i] = end[i] + maxs[i] + 1; + boxmins[i]= start[i] + mins[i] - 1; + boxmaxs[i]= end[i] + maxs[i] + 1; } else { - boxmins[i] = end[i] + mins[i] - 1; - boxmaxs[i] = start[i] + maxs[i] + 1; + boxmins[i]= end[i] + mins[i] - 1; + boxmaxs[i]= start[i] + maxs[i] + 1; } } @@ -651,27 +648,27 @@ public class SV_WORLD extends SV_CCMDS */ public static trace_t SV_Trace(float[] start, float[] mins, float[] maxs, float[] end, edict_t passedict, int contentmask) { - moveclip_t clip = new moveclip_t(); + moveclip_t clip= new moveclip_t(); if (mins == null) - mins = vec3_origin; + mins= vec3_origin; if (maxs == null) - maxs = vec3_origin; + maxs= vec3_origin; //memset ( clip, 0, sizeof ( moveclip_t ) ); // clip to world - clip.trace = CM.BoxTrace(start, end, mins, maxs, 0, contentmask); - clip.trace.ent = ge.edicts[0]; + clip.trace= CM.BoxTrace(start, end, mins, maxs, 0, contentmask); + clip.trace.ent= ge.edicts[0]; if (clip.trace.fraction == 0) return clip.trace; // blocked by the world - clip.contentmask = contentmask; - clip.start = start; - clip.end = end; - clip.mins = mins; - clip.maxs = maxs; - clip.passedict = passedict; + clip.contentmask= contentmask; + clip.start= start; + clip.end= end; + clip.mins= mins; + clip.maxs= maxs; + clip.passedict= passedict; VectorCopy(mins, clip.mins2); VectorCopy(maxs, clip.maxs2); |