2009-04-18 19:00:33 +02:00
|
|
|
/* Copyright (C) 2009 Wildfire Games.
|
|
|
|
* This file is part of 0 A.D.
|
|
|
|
*
|
|
|
|
* 0 A.D. is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* 0 A.D. is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with 0 A.D. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
2009-04-18 19:51:05 +02:00
|
|
|
/*
|
|
|
|
* Implementation of CBrush, a class representing a convex object
|
2006-03-26 23:58:48 +02:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include "precompiled.h"
|
|
|
|
|
2006-06-02 04:10:27 +02:00
|
|
|
#include "lib/ogl.h"
|
2006-03-26 23:58:48 +02:00
|
|
|
|
|
|
|
#include <float.h>
|
|
|
|
|
|
|
|
#include "Brush.h"
|
2011-11-25 07:36:13 +01:00
|
|
|
#include "BoundingBoxAligned.h"
|
2006-06-02 04:10:27 +02:00
|
|
|
#include "graphics/Frustum.h"
|
2006-03-26 23:58:48 +02:00
|
|
|
|
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
// Convert the given bounds into a brush
|
2011-11-25 07:36:13 +01:00
|
|
|
CBrush::CBrush(const CBoundingBoxAligned& bounds)
|
2006-03-26 23:58:48 +02:00
|
|
|
{
|
|
|
|
m_Vertices.resize(8);
|
|
|
|
|
had to remove uint and ulong from lib/types.h due to conflict with other library.
this snowballed into a massive search+destroy of the hodgepodge of
mostly equivalent types we had in use (int, uint, unsigned, unsigned
int, i32, u32, ulong, uintN).
it is more efficient to use 64-bit types in 64-bit mode, so the
preferred default is size_t (for anything remotely resembling a size or
index). tile coordinates are ssize_t to allow more efficient conversion
to/from floating point. flags are int because we almost never need more
than 15 distinct bits, bit test/set is not slower and int is fastest to
type. finally, some data that is pretty much directly passed to OpenGL
is now typed accordingly.
after several hours, the code now requires fewer casts and less
guesswork.
other changes:
- unit and player IDs now have an "invalid id" constant in the
respective class to avoid casting and -1
- fix some endian/64-bit bugs in the map (un)packing. added a
convenience function to write/read a size_t.
- ia32: change CPUID interface to allow passing in ecx (required for
cache topology detection, which I need at work). remove some unneeded
functions from asm, replace with intrinsics where possible.
This was SVN commit r5942.
2008-05-11 20:48:32 +02:00
|
|
|
for(size_t i = 0; i < 8; ++i)
|
2006-03-26 23:58:48 +02:00
|
|
|
{
|
|
|
|
m_Vertices[i][0] = bounds[(i & 1) ? 1 : 0][0];
|
|
|
|
m_Vertices[i][1] = bounds[(i & 2) ? 1 : 0][1];
|
|
|
|
m_Vertices[i][2] = bounds[(i & 4) ? 1 : 0][2];
|
|
|
|
}
|
|
|
|
|
|
|
|
m_Faces.resize(30);
|
|
|
|
|
|
|
|
m_Faces[0] = 0; m_Faces[1] = 1; m_Faces[2] = 3; m_Faces[3] = 2; m_Faces[4] = 0; // Z = min
|
|
|
|
m_Faces[5] = 4; m_Faces[6] = 5; m_Faces[7] = 7; m_Faces[8] = 6; m_Faces[9] = 4; // Z = max
|
|
|
|
|
|
|
|
m_Faces[10] = 0; m_Faces[11] = 2; m_Faces[12] = 6; m_Faces[13] = 4; m_Faces[14] = 0; // X = min
|
|
|
|
m_Faces[15] = 1; m_Faces[16] = 3; m_Faces[17] = 7; m_Faces[18] = 5; m_Faces[19] = 1; // X = max
|
|
|
|
|
|
|
|
m_Faces[20] = 0; m_Faces[21] = 1; m_Faces[22] = 5; m_Faces[23] = 4; m_Faces[24] = 0; // Y = min
|
|
|
|
m_Faces[25] = 2; m_Faces[26] = 3; m_Faces[27] = 7; m_Faces[28] = 6; m_Faces[29] = 2; // Y = max
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
// Calculate bounds of this brush
|
2011-11-25 07:36:13 +01:00
|
|
|
void CBrush::Bounds(CBoundingBoxAligned& result) const
|
2006-03-26 23:58:48 +02:00
|
|
|
{
|
|
|
|
result.SetEmpty();
|
|
|
|
|
had to remove uint and ulong from lib/types.h due to conflict with other library.
this snowballed into a massive search+destroy of the hodgepodge of
mostly equivalent types we had in use (int, uint, unsigned, unsigned
int, i32, u32, ulong, uintN).
it is more efficient to use 64-bit types in 64-bit mode, so the
preferred default is size_t (for anything remotely resembling a size or
index). tile coordinates are ssize_t to allow more efficient conversion
to/from floating point. flags are int because we almost never need more
than 15 distinct bits, bit test/set is not slower and int is fastest to
type. finally, some data that is pretty much directly passed to OpenGL
is now typed accordingly.
after several hours, the code now requires fewer casts and less
guesswork.
other changes:
- unit and player IDs now have an "invalid id" constant in the
respective class to avoid casting and -1
- fix some endian/64-bit bugs in the map (un)packing. added a
convenience function to write/read a size_t.
- ia32: change CPUID interface to allow passing in ecx (required for
cache topology detection, which I need at work). remove some unneeded
functions from asm, replace with intrinsics where possible.
This was SVN commit r5942.
2008-05-11 20:48:32 +02:00
|
|
|
for(size_t i = 0; i < m_Vertices.size(); ++i)
|
2006-03-26 23:58:48 +02:00
|
|
|
result += m_Vertices[i];
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
// Cut the brush according to a given plane
|
|
|
|
struct SliceVertexInfo {
|
|
|
|
float d; // distance
|
had to remove uint and ulong from lib/types.h due to conflict with other library.
this snowballed into a massive search+destroy of the hodgepodge of
mostly equivalent types we had in use (int, uint, unsigned, unsigned
int, i32, u32, ulong, uintN).
it is more efficient to use 64-bit types in 64-bit mode, so the
preferred default is size_t (for anything remotely resembling a size or
index). tile coordinates are ssize_t to allow more efficient conversion
to/from floating point. flags are int because we almost never need more
than 15 distinct bits, bit test/set is not slower and int is fastest to
type. finally, some data that is pretty much directly passed to OpenGL
is now typed accordingly.
after several hours, the code now requires fewer casts and less
guesswork.
other changes:
- unit and player IDs now have an "invalid id" constant in the
respective class to avoid casting and -1
- fix some endian/64-bit bugs in the map (un)packing. added a
convenience function to write/read a size_t.
- ia32: change CPUID interface to allow passing in ecx (required for
cache topology detection, which I need at work). remove some unneeded
functions from asm, replace with intrinsics where possible.
This was SVN commit r5942.
2008-05-11 20:48:32 +02:00
|
|
|
size_t res; // index in result brush (or no_vertex if cut away)
|
2006-03-26 23:58:48 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
struct NewVertexInfo {
|
had to remove uint and ulong from lib/types.h due to conflict with other library.
this snowballed into a massive search+destroy of the hodgepodge of
mostly equivalent types we had in use (int, uint, unsigned, unsigned
int, i32, u32, ulong, uintN).
it is more efficient to use 64-bit types in 64-bit mode, so the
preferred default is size_t (for anything remotely resembling a size or
index). tile coordinates are ssize_t to allow more efficient conversion
to/from floating point. flags are int because we almost never need more
than 15 distinct bits, bit test/set is not slower and int is fastest to
type. finally, some data that is pretty much directly passed to OpenGL
is now typed accordingly.
after several hours, the code now requires fewer casts and less
guesswork.
other changes:
- unit and player IDs now have an "invalid id" constant in the
respective class to avoid casting and -1
- fix some endian/64-bit bugs in the map (un)packing. added a
convenience function to write/read a size_t.
- ia32: change CPUID interface to allow passing in ecx (required for
cache topology detection, which I need at work). remove some unneeded
functions from asm, replace with intrinsics where possible.
This was SVN commit r5942.
2008-05-11 20:48:32 +02:00
|
|
|
size_t v1, v2; // adjacent vertices in original brush
|
|
|
|
size_t res; // index in result brush
|
2006-03-26 23:58:48 +02:00
|
|
|
|
had to remove uint and ulong from lib/types.h due to conflict with other library.
this snowballed into a massive search+destroy of the hodgepodge of
mostly equivalent types we had in use (int, uint, unsigned, unsigned
int, i32, u32, ulong, uintN).
it is more efficient to use 64-bit types in 64-bit mode, so the
preferred default is size_t (for anything remotely resembling a size or
index). tile coordinates are ssize_t to allow more efficient conversion
to/from floating point. flags are int because we almost never need more
than 15 distinct bits, bit test/set is not slower and int is fastest to
type. finally, some data that is pretty much directly passed to OpenGL
is now typed accordingly.
after several hours, the code now requires fewer casts and less
guesswork.
other changes:
- unit and player IDs now have an "invalid id" constant in the
respective class to avoid casting and -1
- fix some endian/64-bit bugs in the map (un)packing. added a
convenience function to write/read a size_t.
- ia32: change CPUID interface to allow passing in ecx (required for
cache topology detection, which I need at work). remove some unneeded
functions from asm, replace with intrinsics where possible.
This was SVN commit r5942.
2008-05-11 20:48:32 +02:00
|
|
|
size_t neighb1, neighb2; // index into newv
|
2006-03-26 23:58:48 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
struct SliceInfo {
|
|
|
|
std::vector<SliceVertexInfo> v;
|
|
|
|
std::vector<NewVertexInfo> newv;
|
had to remove uint and ulong from lib/types.h due to conflict with other library.
this snowballed into a massive search+destroy of the hodgepodge of
mostly equivalent types we had in use (int, uint, unsigned, unsigned
int, i32, u32, ulong, uintN).
it is more efficient to use 64-bit types in 64-bit mode, so the
preferred default is size_t (for anything remotely resembling a size or
index). tile coordinates are ssize_t to allow more efficient conversion
to/from floating point. flags are int because we almost never need more
than 15 distinct bits, bit test/set is not slower and int is fastest to
type. finally, some data that is pretty much directly passed to OpenGL
is now typed accordingly.
after several hours, the code now requires fewer casts and less
guesswork.
other changes:
- unit and player IDs now have an "invalid id" constant in the
respective class to avoid casting and -1
- fix some endian/64-bit bugs in the map (un)packing. added a
convenience function to write/read a size_t.
- ia32: change CPUID interface to allow passing in ecx (required for
cache topology detection, which I need at work). remove some unneeded
functions from asm, replace with intrinsics where possible.
This was SVN commit r5942.
2008-05-11 20:48:32 +02:00
|
|
|
size_t thisFaceNewVertex; // index into newv
|
2006-03-26 23:58:48 +02:00
|
|
|
const CBrush* original;
|
|
|
|
CBrush* result;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct CBrush::Helper
|
|
|
|
{
|
had to remove uint and ulong from lib/types.h due to conflict with other library.
this snowballed into a massive search+destroy of the hodgepodge of
mostly equivalent types we had in use (int, uint, unsigned, unsigned
int, i32, u32, ulong, uintN).
it is more efficient to use 64-bit types in 64-bit mode, so the
preferred default is size_t (for anything remotely resembling a size or
index). tile coordinates are ssize_t to allow more efficient conversion
to/from floating point. flags are int because we almost never need more
than 15 distinct bits, bit test/set is not slower and int is fastest to
type. finally, some data that is pretty much directly passed to OpenGL
is now typed accordingly.
after several hours, the code now requires fewer casts and less
guesswork.
other changes:
- unit and player IDs now have an "invalid id" constant in the
respective class to avoid casting and -1
- fix some endian/64-bit bugs in the map (un)packing. added a
convenience function to write/read a size_t.
- ia32: change CPUID interface to allow passing in ecx (required for
cache topology detection, which I need at work). remove some unneeded
functions from asm, replace with intrinsics where possible.
This was SVN commit r5942.
2008-05-11 20:48:32 +02:00
|
|
|
static size_t SliceNewVertex(SliceInfo& si, size_t v1, size_t v2);
|
2006-03-26 23:58:48 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
// create a new vertex between the given two vertices (index into original brush)
|
|
|
|
// returns the index of the new vertex in the resulting brush
|
had to remove uint and ulong from lib/types.h due to conflict with other library.
this snowballed into a massive search+destroy of the hodgepodge of
mostly equivalent types we had in use (int, uint, unsigned, unsigned
int, i32, u32, ulong, uintN).
it is more efficient to use 64-bit types in 64-bit mode, so the
preferred default is size_t (for anything remotely resembling a size or
index). tile coordinates are ssize_t to allow more efficient conversion
to/from floating point. flags are int because we almost never need more
than 15 distinct bits, bit test/set is not slower and int is fastest to
type. finally, some data that is pretty much directly passed to OpenGL
is now typed accordingly.
after several hours, the code now requires fewer casts and less
guesswork.
other changes:
- unit and player IDs now have an "invalid id" constant in the
respective class to avoid casting and -1
- fix some endian/64-bit bugs in the map (un)packing. added a
convenience function to write/read a size_t.
- ia32: change CPUID interface to allow passing in ecx (required for
cache topology detection, which I need at work). remove some unneeded
functions from asm, replace with intrinsics where possible.
This was SVN commit r5942.
2008-05-11 20:48:32 +02:00
|
|
|
size_t CBrush::Helper::SliceNewVertex(SliceInfo& si, size_t v1, size_t v2)
|
2006-03-26 23:58:48 +02:00
|
|
|
{
|
had to remove uint and ulong from lib/types.h due to conflict with other library.
this snowballed into a massive search+destroy of the hodgepodge of
mostly equivalent types we had in use (int, uint, unsigned, unsigned
int, i32, u32, ulong, uintN).
it is more efficient to use 64-bit types in 64-bit mode, so the
preferred default is size_t (for anything remotely resembling a size or
index). tile coordinates are ssize_t to allow more efficient conversion
to/from floating point. flags are int because we almost never need more
than 15 distinct bits, bit test/set is not slower and int is fastest to
type. finally, some data that is pretty much directly passed to OpenGL
is now typed accordingly.
after several hours, the code now requires fewer casts and less
guesswork.
other changes:
- unit and player IDs now have an "invalid id" constant in the
respective class to avoid casting and -1
- fix some endian/64-bit bugs in the map (un)packing. added a
convenience function to write/read a size_t.
- ia32: change CPUID interface to allow passing in ecx (required for
cache topology detection, which I need at work). remove some unneeded
functions from asm, replace with intrinsics where possible.
This was SVN commit r5942.
2008-05-11 20:48:32 +02:00
|
|
|
size_t idx;
|
2006-03-26 23:58:48 +02:00
|
|
|
|
|
|
|
for(idx = 0; idx < si.newv.size(); ++idx)
|
|
|
|
{
|
|
|
|
if ((si.newv[idx].v1 == v1 && si.newv[idx].v2 == v2) ||
|
|
|
|
(si.newv[idx].v1 == v2 && si.newv[idx].v2 == v1))
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (idx >= si.newv.size())
|
|
|
|
{
|
|
|
|
NewVertexInfo nvi;
|
|
|
|
CVector3D newpos;
|
|
|
|
float inv = 1.0 / (si.v[v1].d - si.v[v2].d);
|
|
|
|
|
|
|
|
newpos = si.original->m_Vertices[v2]*(si.v[v1].d*inv) +
|
|
|
|
si.original->m_Vertices[v1]*(-si.v[v2].d*inv);
|
|
|
|
|
|
|
|
nvi.v1 = v1;
|
|
|
|
nvi.v2 = v2;
|
had to remove uint and ulong from lib/types.h due to conflict with other library.
this snowballed into a massive search+destroy of the hodgepodge of
mostly equivalent types we had in use (int, uint, unsigned, unsigned
int, i32, u32, ulong, uintN).
it is more efficient to use 64-bit types in 64-bit mode, so the
preferred default is size_t (for anything remotely resembling a size or
index). tile coordinates are ssize_t to allow more efficient conversion
to/from floating point. flags are int because we almost never need more
than 15 distinct bits, bit test/set is not slower and int is fastest to
type. finally, some data that is pretty much directly passed to OpenGL
is now typed accordingly.
after several hours, the code now requires fewer casts and less
guesswork.
other changes:
- unit and player IDs now have an "invalid id" constant in the
respective class to avoid casting and -1
- fix some endian/64-bit bugs in the map (un)packing. added a
convenience function to write/read a size_t.
- ia32: change CPUID interface to allow passing in ecx (required for
cache topology detection, which I need at work). remove some unneeded
functions from asm, replace with intrinsics where possible.
This was SVN commit r5942.
2008-05-11 20:48:32 +02:00
|
|
|
nvi.res = si.result->m_Vertices.size();
|
2006-03-26 23:58:48 +02:00
|
|
|
nvi.neighb1 = no_vertex;
|
|
|
|
nvi.neighb2 = no_vertex;
|
|
|
|
si.result->m_Vertices.push_back(newpos);
|
|
|
|
si.newv.push_back(nvi);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (si.thisFaceNewVertex != no_vertex)
|
|
|
|
{
|
|
|
|
if (si.newv[si.thisFaceNewVertex].neighb1 == no_vertex)
|
|
|
|
si.newv[si.thisFaceNewVertex].neighb1 = idx;
|
|
|
|
else
|
|
|
|
si.newv[si.thisFaceNewVertex].neighb2 = idx;
|
|
|
|
|
|
|
|
if (si.newv[idx].neighb1 == no_vertex)
|
|
|
|
si.newv[idx].neighb1 = si.thisFaceNewVertex;
|
|
|
|
else
|
|
|
|
si.newv[idx].neighb2 = si.thisFaceNewVertex;
|
|
|
|
|
|
|
|
si.thisFaceNewVertex = no_vertex;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
si.thisFaceNewVertex = idx;
|
|
|
|
}
|
|
|
|
|
|
|
|
return si.newv[idx].res;
|
|
|
|
}
|
|
|
|
|
|
|
|
void CBrush::Slice(const CPlane& plane, CBrush& result) const
|
|
|
|
{
|
2011-04-30 15:01:45 +02:00
|
|
|
ENSURE(&result != this);
|
2006-03-26 23:58:48 +02:00
|
|
|
|
|
|
|
SliceInfo si;
|
|
|
|
|
|
|
|
si.original = this;
|
|
|
|
si.result = &result;
|
|
|
|
si.thisFaceNewVertex = no_vertex;
|
|
|
|
si.newv.reserve(m_Vertices.size() / 2);
|
|
|
|
|
|
|
|
result.m_Vertices.resize(0); // clear any left-overs
|
|
|
|
result.m_Faces.resize(0);
|
|
|
|
result.m_Vertices.reserve(m_Vertices.size() + 2);
|
|
|
|
result.m_Faces.reserve(m_Faces.size() + 5);
|
|
|
|
|
|
|
|
// Classify and copy vertices
|
|
|
|
si.v.resize(m_Vertices.size());
|
|
|
|
|
had to remove uint and ulong from lib/types.h due to conflict with other library.
this snowballed into a massive search+destroy of the hodgepodge of
mostly equivalent types we had in use (int, uint, unsigned, unsigned
int, i32, u32, ulong, uintN).
it is more efficient to use 64-bit types in 64-bit mode, so the
preferred default is size_t (for anything remotely resembling a size or
index). tile coordinates are ssize_t to allow more efficient conversion
to/from floating point. flags are int because we almost never need more
than 15 distinct bits, bit test/set is not slower and int is fastest to
type. finally, some data that is pretty much directly passed to OpenGL
is now typed accordingly.
after several hours, the code now requires fewer casts and less
guesswork.
other changes:
- unit and player IDs now have an "invalid id" constant in the
respective class to avoid casting and -1
- fix some endian/64-bit bugs in the map (un)packing. added a
convenience function to write/read a size_t.
- ia32: change CPUID interface to allow passing in ecx (required for
cache topology detection, which I need at work). remove some unneeded
functions from asm, replace with intrinsics where possible.
This was SVN commit r5942.
2008-05-11 20:48:32 +02:00
|
|
|
for(size_t i = 0; i < m_Vertices.size(); ++i)
|
2006-03-26 23:58:48 +02:00
|
|
|
{
|
|
|
|
si.v[i].d = plane.DistanceToPlane(m_Vertices[i]);
|
|
|
|
if (si.v[i].d >= 0.0)
|
|
|
|
{
|
had to remove uint and ulong from lib/types.h due to conflict with other library.
this snowballed into a massive search+destroy of the hodgepodge of
mostly equivalent types we had in use (int, uint, unsigned, unsigned
int, i32, u32, ulong, uintN).
it is more efficient to use 64-bit types in 64-bit mode, so the
preferred default is size_t (for anything remotely resembling a size or
index). tile coordinates are ssize_t to allow more efficient conversion
to/from floating point. flags are int because we almost never need more
than 15 distinct bits, bit test/set is not slower and int is fastest to
type. finally, some data that is pretty much directly passed to OpenGL
is now typed accordingly.
after several hours, the code now requires fewer casts and less
guesswork.
other changes:
- unit and player IDs now have an "invalid id" constant in the
respective class to avoid casting and -1
- fix some endian/64-bit bugs in the map (un)packing. added a
convenience function to write/read a size_t.
- ia32: change CPUID interface to allow passing in ecx (required for
cache topology detection, which I need at work). remove some unneeded
functions from asm, replace with intrinsics where possible.
This was SVN commit r5942.
2008-05-11 20:48:32 +02:00
|
|
|
si.v[i].res = result.m_Vertices.size();
|
2006-03-26 23:58:48 +02:00
|
|
|
result.m_Vertices.push_back(m_Vertices[i]);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
si.v[i].res = no_vertex;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Transfer faces
|
had to remove uint and ulong from lib/types.h due to conflict with other library.
this snowballed into a massive search+destroy of the hodgepodge of
mostly equivalent types we had in use (int, uint, unsigned, unsigned
int, i32, u32, ulong, uintN).
it is more efficient to use 64-bit types in 64-bit mode, so the
preferred default is size_t (for anything remotely resembling a size or
index). tile coordinates are ssize_t to allow more efficient conversion
to/from floating point. flags are int because we almost never need more
than 15 distinct bits, bit test/set is not slower and int is fastest to
type. finally, some data that is pretty much directly passed to OpenGL
is now typed accordingly.
after several hours, the code now requires fewer casts and less
guesswork.
other changes:
- unit and player IDs now have an "invalid id" constant in the
respective class to avoid casting and -1
- fix some endian/64-bit bugs in the map (un)packing. added a
convenience function to write/read a size_t.
- ia32: change CPUID interface to allow passing in ecx (required for
cache topology detection, which I need at work). remove some unneeded
functions from asm, replace with intrinsics where possible.
This was SVN commit r5942.
2008-05-11 20:48:32 +02:00
|
|
|
size_t firstInFace = no_vertex; // in original brush
|
|
|
|
size_t startInResultFaceArray = ~0u;
|
2006-03-26 23:58:48 +02:00
|
|
|
|
had to remove uint and ulong from lib/types.h due to conflict with other library.
this snowballed into a massive search+destroy of the hodgepodge of
mostly equivalent types we had in use (int, uint, unsigned, unsigned
int, i32, u32, ulong, uintN).
it is more efficient to use 64-bit types in 64-bit mode, so the
preferred default is size_t (for anything remotely resembling a size or
index). tile coordinates are ssize_t to allow more efficient conversion
to/from floating point. flags are int because we almost never need more
than 15 distinct bits, bit test/set is not slower and int is fastest to
type. finally, some data that is pretty much directly passed to OpenGL
is now typed accordingly.
after several hours, the code now requires fewer casts and less
guesswork.
other changes:
- unit and player IDs now have an "invalid id" constant in the
respective class to avoid casting and -1
- fix some endian/64-bit bugs in the map (un)packing. added a
convenience function to write/read a size_t.
- ia32: change CPUID interface to allow passing in ecx (required for
cache topology detection, which I need at work). remove some unneeded
functions from asm, replace with intrinsics where possible.
This was SVN commit r5942.
2008-05-11 20:48:32 +02:00
|
|
|
for(size_t i = 0; i < m_Faces.size(); ++i)
|
2006-03-26 23:58:48 +02:00
|
|
|
{
|
|
|
|
if (firstInFace == no_vertex)
|
|
|
|
{
|
2011-04-30 15:01:45 +02:00
|
|
|
ENSURE(si.thisFaceNewVertex == no_vertex);
|
2006-03-26 23:58:48 +02:00
|
|
|
|
|
|
|
firstInFace = m_Faces[i];
|
had to remove uint and ulong from lib/types.h due to conflict with other library.
this snowballed into a massive search+destroy of the hodgepodge of
mostly equivalent types we had in use (int, uint, unsigned, unsigned
int, i32, u32, ulong, uintN).
it is more efficient to use 64-bit types in 64-bit mode, so the
preferred default is size_t (for anything remotely resembling a size or
index). tile coordinates are ssize_t to allow more efficient conversion
to/from floating point. flags are int because we almost never need more
than 15 distinct bits, bit test/set is not slower and int is fastest to
type. finally, some data that is pretty much directly passed to OpenGL
is now typed accordingly.
after several hours, the code now requires fewer casts and less
guesswork.
other changes:
- unit and player IDs now have an "invalid id" constant in the
respective class to avoid casting and -1
- fix some endian/64-bit bugs in the map (un)packing. added a
convenience function to write/read a size_t.
- ia32: change CPUID interface to allow passing in ecx (required for
cache topology detection, which I need at work). remove some unneeded
functions from asm, replace with intrinsics where possible.
This was SVN commit r5942.
2008-05-11 20:48:32 +02:00
|
|
|
startInResultFaceArray = result.m_Faces.size();
|
2006-03-26 23:58:48 +02:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
had to remove uint and ulong from lib/types.h due to conflict with other library.
this snowballed into a massive search+destroy of the hodgepodge of
mostly equivalent types we had in use (int, uint, unsigned, unsigned
int, i32, u32, ulong, uintN).
it is more efficient to use 64-bit types in 64-bit mode, so the
preferred default is size_t (for anything remotely resembling a size or
index). tile coordinates are ssize_t to allow more efficient conversion
to/from floating point. flags are int because we almost never need more
than 15 distinct bits, bit test/set is not slower and int is fastest to
type. finally, some data that is pretty much directly passed to OpenGL
is now typed accordingly.
after several hours, the code now requires fewer casts and less
guesswork.
other changes:
- unit and player IDs now have an "invalid id" constant in the
respective class to avoid casting and -1
- fix some endian/64-bit bugs in the map (un)packing. added a
convenience function to write/read a size_t.
- ia32: change CPUID interface to allow passing in ecx (required for
cache topology detection, which I need at work). remove some unneeded
functions from asm, replace with intrinsics where possible.
This was SVN commit r5942.
2008-05-11 20:48:32 +02:00
|
|
|
size_t prev = m_Faces[i-1];
|
|
|
|
size_t cur = m_Faces[i];
|
2006-03-26 23:58:48 +02:00
|
|
|
|
|
|
|
if (si.v[prev].res == no_vertex)
|
|
|
|
{
|
|
|
|
if (si.v[cur].res != no_vertex)
|
|
|
|
{
|
|
|
|
// re-entering the front side of the plane
|
|
|
|
result.m_Faces.push_back(Helper::SliceNewVertex(si, prev, cur));
|
|
|
|
result.m_Faces.push_back(si.v[cur].res);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (si.v[cur].res != no_vertex)
|
|
|
|
{
|
|
|
|
// perfectly normal edge
|
|
|
|
result.m_Faces.push_back(si.v[cur].res);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// leaving the front side of the plane
|
|
|
|
result.m_Faces.push_back(Helper::SliceNewVertex(si, prev, cur));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (cur == firstInFace)
|
|
|
|
{
|
|
|
|
if (result.m_Faces.size() > startInResultFaceArray)
|
|
|
|
result.m_Faces.push_back(result.m_Faces[startInResultFaceArray]);
|
|
|
|
firstInFace = no_vertex; // start a new face
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-04-30 15:01:45 +02:00
|
|
|
ENSURE(firstInFace == no_vertex);
|
2006-03-26 23:58:48 +02:00
|
|
|
|
|
|
|
// Create the face that lies in the slicing plane
|
|
|
|
if (si.newv.size())
|
|
|
|
{
|
had to remove uint and ulong from lib/types.h due to conflict with other library.
this snowballed into a massive search+destroy of the hodgepodge of
mostly equivalent types we had in use (int, uint, unsigned, unsigned
int, i32, u32, ulong, uintN).
it is more efficient to use 64-bit types in 64-bit mode, so the
preferred default is size_t (for anything remotely resembling a size or
index). tile coordinates are ssize_t to allow more efficient conversion
to/from floating point. flags are int because we almost never need more
than 15 distinct bits, bit test/set is not slower and int is fastest to
type. finally, some data that is pretty much directly passed to OpenGL
is now typed accordingly.
after several hours, the code now requires fewer casts and less
guesswork.
other changes:
- unit and player IDs now have an "invalid id" constant in the
respective class to avoid casting and -1
- fix some endian/64-bit bugs in the map (un)packing. added a
convenience function to write/read a size_t.
- ia32: change CPUID interface to allow passing in ecx (required for
cache topology detection, which I need at work). remove some unneeded
functions from asm, replace with intrinsics where possible.
This was SVN commit r5942.
2008-05-11 20:48:32 +02:00
|
|
|
size_t prev = 0;
|
|
|
|
size_t idx;
|
2006-03-26 23:58:48 +02:00
|
|
|
|
|
|
|
result.m_Faces.push_back(si.newv[0].res);
|
|
|
|
idx = si.newv[0].neighb2;
|
|
|
|
si.newv[0].neighb2 = no_vertex;
|
|
|
|
|
|
|
|
while(idx != 0)
|
|
|
|
{
|
2011-04-30 15:01:45 +02:00
|
|
|
ENSURE(idx < si.newv.size());
|
2006-03-26 23:58:48 +02:00
|
|
|
|
|
|
|
if (si.newv[idx].neighb1 == prev)
|
|
|
|
{
|
|
|
|
si.newv[idx].neighb1 = si.newv[idx].neighb2;
|
|
|
|
si.newv[idx].neighb2 = no_vertex;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2011-04-30 15:01:45 +02:00
|
|
|
ENSURE(si.newv[idx].neighb2 == prev);
|
2006-03-26 23:58:48 +02:00
|
|
|
|
|
|
|
si.newv[idx].neighb2 = no_vertex;
|
|
|
|
}
|
|
|
|
|
|
|
|
result.m_Faces.push_back(si.newv[idx].res);
|
|
|
|
|
|
|
|
prev = idx;
|
|
|
|
idx = si.newv[idx].neighb1;
|
|
|
|
si.newv[prev].neighb1 = no_vertex;
|
|
|
|
}
|
|
|
|
|
|
|
|
result.m_Faces.push_back(si.newv[0].res);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
// Intersect with frustum by repeated slicing
|
|
|
|
void CBrush::Intersect(const CFrustum& frustum, CBrush& result) const
|
|
|
|
{
|
2011-04-30 15:01:45 +02:00
|
|
|
ENSURE(&result != this);
|
2006-03-26 23:58:48 +02:00
|
|
|
|
|
|
|
if (!frustum.GetNumPlanes())
|
|
|
|
{
|
|
|
|
result = *this;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
CBrush buf;
|
|
|
|
const CBrush* prev = this;
|
|
|
|
CBrush* next;
|
|
|
|
|
|
|
|
if (frustum.GetNumPlanes() & 1)
|
|
|
|
next = &result;
|
|
|
|
else
|
|
|
|
next = &buf;
|
|
|
|
|
had to remove uint and ulong from lib/types.h due to conflict with other library.
this snowballed into a massive search+destroy of the hodgepodge of
mostly equivalent types we had in use (int, uint, unsigned, unsigned
int, i32, u32, ulong, uintN).
it is more efficient to use 64-bit types in 64-bit mode, so the
preferred default is size_t (for anything remotely resembling a size or
index). tile coordinates are ssize_t to allow more efficient conversion
to/from floating point. flags are int because we almost never need more
than 15 distinct bits, bit test/set is not slower and int is fastest to
type. finally, some data that is pretty much directly passed to OpenGL
is now typed accordingly.
after several hours, the code now requires fewer casts and less
guesswork.
other changes:
- unit and player IDs now have an "invalid id" constant in the
respective class to avoid casting and -1
- fix some endian/64-bit bugs in the map (un)packing. added a
convenience function to write/read a size_t.
- ia32: change CPUID interface to allow passing in ecx (required for
cache topology detection, which I need at work). remove some unneeded
functions from asm, replace with intrinsics where possible.
This was SVN commit r5942.
2008-05-11 20:48:32 +02:00
|
|
|
for(size_t i = 0; i < frustum.GetNumPlanes(); ++i)
|
2006-03-26 23:58:48 +02:00
|
|
|
{
|
|
|
|
prev->Slice(frustum[i], *next);
|
|
|
|
prev = next;
|
|
|
|
if (prev == &buf)
|
|
|
|
next = &result;
|
|
|
|
else
|
|
|
|
next = &buf;
|
|
|
|
}
|
|
|
|
|
2011-04-30 15:01:45 +02:00
|
|
|
ENSURE(prev == &result);
|
2012-02-08 21:43:38 +01:00
|
|
|
}
|