summaryrefslogtreecommitdiff
path: root/src/common/bsp.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/common/bsp.c')
-rw-r--r--src/common/bsp.c215
1 files changed, 105 insertions, 110 deletions
diff --git a/src/common/bsp.c b/src/common/bsp.c
index 804b98a..16987e3 100644
--- a/src/common/bsp.c
+++ b/src/common/bsp.c
@@ -70,7 +70,7 @@ LOAD(Visibility)
bsp->vis = ALLOC(count);
memcpy(bsp->vis, base, count);
- numclusters = LittleLong(bsp->vis->numclusters);
+ numclusters = le32_to_cpu(bsp->vis->numclusters);
if (numclusters > MAX_MAP_LEAFS) {
DEBUG("bad numclusters");
return Q_ERR_TOO_MANY;
@@ -86,7 +86,7 @@ LOAD(Visibility)
for (i = 0; i < numclusters; i++) {
for (j = 0; j < 2; j++) {
- bitofs = LittleLong(bsp->vis->bitofs[i][j]);
+ bitofs = le32_to_cpu(bsp->vis->bitofs[i][j]);
if (bitofs >= count) {
DEBUG("bad bitofs");
return Q_ERR_BAD_INDEX;
@@ -119,8 +119,8 @@ LOAD(Texinfo)
out->c.name[sizeof(out->c.name) - 1] = 0;
memcpy(out->name, in->texture, sizeof(out->name));
out->name[sizeof(out->name) - 1] = 0;
- out->c.flags = LittleLong(in->flags);
- out->c.value = LittleLong(in->value);
+ out->c.flags = le32_to_cpu(in->flags);
+ out->c.value = le32_to_cpu(in->value);
#if USE_REF
for (j = 0; j < 2; j++) {
@@ -130,7 +130,7 @@ LOAD(Texinfo)
out->offset[j] = LittleFloat(in->vecs[j][k]);
}
- next = (int32_t)LittleLong(in->nexttexinfo);
+ next = (int32_t)le32_to_cpu(in->nexttexinfo);
if (next > 0) {
if (next >= count) {
DEBUG("bad anim chain");
@@ -197,13 +197,13 @@ LOAD(BrushSides)
in = base;
out = bsp->brushsides;
for (i = 0; i < count; i++, in++, out++) {
- planenum = LittleShort(in->planenum);
+ planenum = le16_to_cpu(in->planenum);
if (planenum >= bsp->numplanes) {
DEBUG("bad planenum");
return Q_ERR_BAD_INDEX;
}
out->plane = bsp->planes + planenum;
- texinfo = LittleShort(in->texinfo);
+ texinfo = le16_to_cpu(in->texinfo);
if (texinfo == (uint16_t)-1) {
out->texinfo = &nulltexinfo;
} else {
@@ -231,8 +231,8 @@ LOAD(Brushes)
in = base;
out = bsp->brushes;
for (i = 0; i < count; i++, out++, in++) {
- firstside = LittleLong(in->firstside);
- numsides = LittleLong(in->numsides);
+ firstside = le32_to_cpu(in->firstside);
+ numsides = le32_to_cpu(in->numsides);
lastside = firstside + numsides;
if (lastside < firstside || lastside > bsp->numbrushsides) {
DEBUG("bad brushsides");
@@ -240,7 +240,7 @@ LOAD(Brushes)
}
out->firstbrushside = bsp->brushsides + firstside;
out->numsides = numsides;
- out->contents = LittleLong(in->contents);
+ out->contents = le32_to_cpu(in->contents);
out->checkcount = 0;
}
@@ -260,7 +260,7 @@ LOAD(LeafBrushes)
in = base;
out = bsp->leafbrushes;
for (i = 0; i < count; i++, in++, out++) {
- brushnum = LittleShort(*in);
+ brushnum = le16_to_cpu(*in);
if (brushnum >= bsp->numbrushes) {
DEBUG("bad brushnum");
return Q_ERR_BAD_INDEX;
@@ -321,7 +321,7 @@ LOAD(Edges)
out = bsp->edges;
for (i = 0; i < count; i++, out++, in++) {
for (j = 0; j < 2; j++) {
- vertnum = LittleShort(in->v[j]);
+ vertnum = le16_to_cpu(in->v[j]);
if (vertnum >= bsp->numvertices) {
DEBUG("bad vertnum");
return Q_ERR_BAD_INDEX;
@@ -346,7 +346,7 @@ LOAD(SurfEdges)
in = base;
out = bsp->surfedges;
for (i = 0; i < count; i++, out++, in++) {
- index = (int32_t)LittleLong(*in);
+ index = (int32_t)le32_to_cpu(*in);
vert = 0;
if (index < 0) {
@@ -381,8 +381,8 @@ LOAD(Faces)
in = base;
out = bsp->faces;
for (i = 0; i < count; i++, in++, out++) {
- firstedge = LittleLong(in->firstedge);
- numedges = LittleShort(in->numedges);
+ firstedge = le32_to_cpu(in->firstedge);
+ numedges = le16_to_cpu(in->numedges);
lastedge = firstedge + numedges;
if (numedges < 3) {
DEBUG("bad surfedges");
@@ -399,14 +399,14 @@ LOAD(Faces)
out->firstsurfedge = bsp->surfedges + firstedge;
out->numsurfedges = numedges;
- planenum = LittleShort(in->planenum);
+ planenum = le16_to_cpu(in->planenum);
if (planenum >= bsp->numplanes) {
DEBUG("bad planenum");
return Q_ERR_BAD_INDEX;
}
out->plane = bsp->planes + planenum;
- texinfo = LittleShort(in->texinfo);
+ texinfo = le16_to_cpu(in->texinfo);
if (texinfo >= bsp->numtexinfo) {
DEBUG("bad texinfo");
return Q_ERR_BAD_INDEX;
@@ -421,7 +421,7 @@ LOAD(Faces)
out->styles[j] = 255;
}
- lightofs = LittleLong(in->lightofs);
+ lightofs = le32_to_cpu(in->lightofs);
if (lightofs == (uint32_t)-1 || bsp->numlightmapbytes == 0) {
out->lightmap = NULL;
} else {
@@ -432,7 +432,7 @@ LOAD(Faces)
out->lightmap = bsp->lightmap + lightofs;
}
- side = LittleShort(in->side);
+ side = le16_to_cpu(in->side);
out->drawflags = side & DSURF_PLANEBACK;
}
@@ -452,7 +452,7 @@ LOAD(LeafFaces)
in = base;
out = bsp->leaffaces;
for (i = 0; i < count; i++, in++, out++) {
- facenum = LittleShort(*in);
+ facenum = le16_to_cpu(*in);
if (facenum >= bsp->numfaces) {
DEBUG("bad facenum");
return Q_ERR_BAD_INDEX;
@@ -488,8 +488,8 @@ LOAD(Leafs)
out = bsp->leafs;
for (i = 0; i < count; i++, in++, out++) {
out->plane = NULL;
- out->contents = LittleLong(in->contents);
- cluster = LittleShort(in->cluster);
+ out->contents = le32_to_cpu(in->contents);
+ cluster = le16_to_cpu(in->cluster);
if (cluster == (uint16_t)-1) {
// solid leafs use special -1 cluster
out->cluster = -1;
@@ -505,15 +505,15 @@ LOAD(Leafs)
out->cluster = cluster;
}
- area = LittleShort(in->area);
+ area = le16_to_cpu(in->area);
if (area >= bsp->numareas) {
DEBUG("bad area");
return Q_ERR_BAD_INDEX;
}
out->area = area;
- firstleafbrush = LittleShort(in->firstleafbrush);
- numleafbrushes = LittleShort(in->numleafbrushes);
+ firstleafbrush = le16_to_cpu(in->firstleafbrush);
+ numleafbrushes = le16_to_cpu(in->numleafbrushes);
lastleafbrush = firstleafbrush + numleafbrushes;
if (lastleafbrush < firstleafbrush || lastleafbrush > bsp->numleafbrushes) {
DEBUG("bad leafbrushes");
@@ -523,8 +523,8 @@ LOAD(Leafs)
out->numleafbrushes = numleafbrushes;
#if USE_REF
- firstleafface = LittleShort(in->firstleafface);
- numleaffaces = LittleShort(in->numleaffaces);
+ firstleafface = le16_to_cpu(in->firstleafface);
+ numleaffaces = le16_to_cpu(in->numleaffaces);
lastleafface = firstleafface + numleaffaces;
if (lastleafface < firstleafface || lastleafface > bsp->numleaffaces) {
DEBUG("bad leaffaces");
@@ -534,8 +534,8 @@ LOAD(Leafs)
out->numleaffaces = numleaffaces;
for (j = 0; j < 3; j++) {
- out->mins[j] = (int16_t)LittleShort(in->mins[j]);
- out->maxs[j] = (int16_t)LittleShort(in->maxs[j]);
+ out->mins[j] = (int16_t)le16_to_cpu(in->mins[j]);
+ out->maxs[j] = (int16_t)le16_to_cpu(in->maxs[j]);
}
out->parent = NULL;
@@ -572,7 +572,7 @@ LOAD(Nodes)
in = base;
out = bsp->nodes;
for (i = 0; i < count; i++, out++, in++) {
- planenum = LittleLong(in->planenum);
+ planenum = le32_to_cpu(in->planenum);
if (planenum >= bsp->numplanes) {
DEBUG("bad planenum");
return Q_ERR_BAD_INDEX;
@@ -580,7 +580,7 @@ LOAD(Nodes)
out->plane = bsp->planes + planenum;
for (j = 0; j < 2; j++) {
- child = LittleLong(in->children[j]);
+ child = le32_to_cpu(in->children[j]);
if (child & 0x80000000) {
child = ~child;
if (child >= bsp->numleafs) {
@@ -598,8 +598,8 @@ LOAD(Nodes)
}
#if USE_REF
- firstface = LittleShort(in->firstface);
- numfaces = LittleShort(in->numfaces);
+ firstface = le16_to_cpu(in->firstface);
+ numfaces = le16_to_cpu(in->numfaces);
lastface = firstface + numfaces;
if (lastface < firstface || lastface > bsp->numfaces) {
DEBUG("bad faces");
@@ -609,8 +609,8 @@ LOAD(Nodes)
out->numfaces = numfaces;
for (j = 0; j < 3; j++) {
- out->mins[j] = (int16_t)LittleShort(in->mins[j]);
- out->maxs[j] = (int16_t)LittleShort(in->maxs[j]);
+ out->mins[j] = (int16_t)le16_to_cpu(in->mins[j]);
+ out->maxs[j] = (int16_t)le16_to_cpu(in->maxs[j]);
}
out->parent = NULL;
@@ -648,7 +648,7 @@ LOAD(Submodels)
out->maxs[j] = LittleFloat(in->maxs[j]) + 1;
out->origin[j] = LittleFloat(in->origin[j]);
}
- headnode = LittleLong(in->headnode);
+ headnode = le32_to_cpu(in->headnode);
if (headnode & 0x80000000) {
// be careful, some models have no nodes, just a leaf
headnode = ~headnode;
@@ -668,8 +668,8 @@ LOAD(Submodels)
if (i == 0) {
continue;
}
- firstface = LittleLong(in->firstface);
- numfaces = LittleLong(in->numfaces);
+ firstface = le32_to_cpu(in->firstface);
+ numfaces = le32_to_cpu(in->numfaces);
lastface = firstface + numfaces;
if (lastface < firstface || lastface > bsp->numfaces) {
DEBUG("bad faces");
@@ -698,8 +698,8 @@ LOAD(AreaPortals)
in = base;
out = bsp->areaportals;
for (i = 0; i < count; i++, in++, out++) {
- out->portalnum = LittleLong(in->portalnum);
- out->otherarea = LittleLong(in->otherarea);
+ out->portalnum = le32_to_cpu(in->portalnum);
+ out->otherarea = le32_to_cpu(in->otherarea);
}
return Q_ERR_SUCCESS;
@@ -718,8 +718,8 @@ LOAD(Areas)
in = base;
out = bsp->areas;
for (i = 0; i < count; i++, in++, out++) {
- numareaportals = LittleLong(in->numareaportals);
- firstareaportal = LittleLong(in->firstareaportal);
+ numareaportals = le32_to_cpu(in->numareaportals);
+ firstareaportal = le32_to_cpu(in->firstareaportal);
lastareaportal = firstareaportal + numareaportals;
if (lastareaportal < firstareaportal || lastareaportal > bsp->numareaportals) {
DEBUG("bad areaportals");
@@ -987,11 +987,11 @@ qerror_t BSP_Load(const char *name, bsp_t **bsp_p)
// byte swap and validate the header
header = (dheader_t *)buf;
- if (LittleLong(header->ident) != IDBSPHEADER) {
+ if (le32_to_cpu(header->ident) != IDBSPHEADER) {
ret = Q_ERR_UNKNOWN_FORMAT;
goto fail2;
}
- if (LittleLong(header->version) != BSPVERSION) {
+ if (le32_to_cpu(header->version) != BSPVERSION) {
ret = Q_ERR_UNKNOWN_FORMAT;
goto fail2;
}
@@ -999,8 +999,8 @@ qerror_t BSP_Load(const char *name, bsp_t **bsp_p)
// byte swap and validate all lumps
memsize = 0;
for (info = bsp_lumps; info->load; info++) {
- ofs = LittleLong(header->lumps[info->lump].fileofs);
- len = LittleLong(header->lumps[info->lump].filelen);
+ ofs = le32_to_cpu(header->lumps[info->lump].fileofs);
+ len = le32_to_cpu(header->lumps[info->lump].filelen);
end = ofs + len;
if (end < ofs || end > filelen) {
ret = Q_ERR_BAD_EXTENT;
@@ -1032,7 +1032,7 @@ qerror_t BSP_Load(const char *name, bsp_t **bsp_p)
Hunk_Begin(&bsp->hunk, memsize + 4096);
// calculate the checksum
- bsp->checksum = LittleLong(Com_BlockChecksum(buf, filelen));
+ bsp->checksum = le32_to_cpu(Com_BlockChecksum(buf, filelen));
// load all lumps
for (info = bsp_lumps; info->load; info++) {
@@ -1079,77 +1079,76 @@ HELPER FUNCTIONS
#if USE_REF
-static lightpoint_t *light_point;
-
-static qboolean BSP_RecursiveLightPoint(mnode_t *node, float p1f, float p2f, vec3_t p1, vec3_t p2)
+static qboolean BSP_RecursiveLightPoint(lightpoint_t *point,
+ mnode_t *node,
+ float p1f, float p2f,
+ vec3_t p1, vec3_t p2)
{
vec_t d1, d2, frac, midf;
vec3_t mid;
- int i, side, s, t;
+ int side, s, t;
mface_t *surf;
- mtexinfo_t *texinfo;
- while (node->plane) {
- // calculate distancies
- d1 = PlaneDiffFast(p1, node->plane);
- d2 = PlaneDiffFast(p2, node->plane);
- side = (d1 < 0);
-
- if ((d2 < 0) == side) {
- // both points are one the same side
- node = node->children[side];
- continue;
- }
+ if (!node->plane)
+ return qfalse;
- // find crossing point
- frac = d1 / (d1 - d2);
- midf = p1f + (p2f - p1f) * frac;
- LerpVector(p1, p2, frac, mid);
-
- // check near side
- if (BSP_RecursiveLightPoint(node->children[side], p1f, midf, p1, mid))
- return qtrue;
-
- for (i = 0, surf = node->firstface; i < node->numfaces; i++, surf++) {
- if (!surf->lightmap)
- continue;
-
- texinfo = surf->texinfo;
- if (texinfo->c.flags & SURF_NOLM_MASK)
- continue;
-
- s = DotProduct(texinfo->axis[0], mid) + texinfo->offset[0];
- t = DotProduct(texinfo->axis[1], mid) + texinfo->offset[1];
-
- s -= surf->texturemins[0];
- t -= surf->texturemins[1];
- if (s < 0 || s > surf->extents[0])
- continue;
- if (t < 0 || t > surf->extents[1])
- continue;
-
- light_point->surf = surf;
- light_point->plane = *surf->plane;
- light_point->s = s;
- light_point->t = t;
- light_point->fraction = midf;
- return qtrue;
- }
+ // calculate distancies
+ d1 = PlaneDiffFast(p1, node->plane);
+ d2 = PlaneDiffFast(p2, node->plane);
+ side = d1 < 0;
+
+ if ((d2 < 0) == side) {
+ // both points are on the same side
+ return BSP_RecursiveLightPoint(point, node->children[side], p1f, p2f, p1, p2);
+ }
- // check far side
- return BSP_RecursiveLightPoint(node->children[side ^ 1], midf, p2f, mid, p2);
+ // find crossing point
+ frac = d1 / (d1 - d2);
+ midf = p1f + (p2f - p1f) * frac;
+ LerpVector(p1, p2, frac, mid);
+
+ // check near side
+ if (BSP_RecursiveLightPoint(point, node->children[side], p1f, midf, p1, mid))
+ return qtrue;
+
+ for (surf = node->firstface;
+ surf != node->firstface + node->numfaces;
+ surf++) {
+ if (!surf->lightmap)
+ continue;
+
+ if (surf->texinfo->c.flags & SURF_NOLM_MASK)
+ continue;
+
+ s = DotProduct(surf->texinfo->axis[0], mid) +
+ surf->texinfo->offset[0] -
+ surf->texturemins[0];
+
+ t = DotProduct(surf->texinfo->axis[1], mid) +
+ surf->texinfo->offset[1] -
+ surf->texturemins[1];
+
+ if (s >= 0 && s <= surf->extents[0] &&
+ t >= 0 && t <= surf->extents[1]) {
+ point->surf = surf;
+ point->plane = *surf->plane;
+ point->s = s;
+ point->t = t;
+ point->fraction = midf;
+ return qtrue;
+ }
}
- return qfalse;
+ // check far side
+ return BSP_RecursiveLightPoint(point, node->children[side ^ 1], midf, p2f, mid, p2);
}
-void BSP_LightPoint(lightpoint_t *point, vec3_t start, vec3_t end, mnode_t *headnode)
+qboolean BSP_LightPoint(lightpoint_t *point, vec3_t start, vec3_t end, mnode_t *headnode)
{
- light_point = point;
- light_point->surf = NULL;
- light_point->fraction = 1;
+ point->surf = NULL;
+ point->fraction = 1;
- BSP_RecursiveLightPoint(headnode, 0, 1, start, end);
+ return BSP_RecursiveLightPoint(point, headnode, 0, 1, start, end);
}
void BSP_TransformedLightPoint(lightpoint_t *point, vec3_t start, vec3_t end,
@@ -1158,10 +1157,6 @@ void BSP_TransformedLightPoint(lightpoint_t *point, vec3_t start, vec3_t end,
vec3_t start_l, end_l;
vec3_t axis[3];
- light_point = point;
- light_point->surf = NULL;
- light_point->fraction = 1;
-
// subtract origin offset
VectorSubtract(start, origin, start_l);
VectorSubtract(end, origin, end_l);
@@ -1174,7 +1169,7 @@ void BSP_TransformedLightPoint(lightpoint_t *point, vec3_t start, vec3_t end,
}
// sweep the line through the model
- if (!BSP_RecursiveLightPoint(headnode, 0, 1, start_l, end_l))
+ if (!BSP_LightPoint(point, start_l, end_l, headnode))
return;
// rotate plane normal into the worlds frame of reference