aboutsummaryrefslogtreecommitdiff
path: root/tool_src/BspLib/BspObjectList.h
blob: e4f8c17d9917142cbca59cb007a38a9b82e0e235 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
//-----------------------------------------------------------------------------
//	BSPLIB HEADER: BspObjectList.h
//
//  Copyright (c) 1997-1998 by Markus Hadwiger
//  All Rights Reserved.
//-----------------------------------------------------------------------------

#ifndef _BSPOBJECTLIST_H_
#define _BSPOBJECTLIST_H_

// bsplib header files
#include "BspLibDefs.h"
#include "BspObject.h"
#include "ObjectBSPTree.h"


BSPLIB_NAMESPACE_BEGIN


// class for list of BspObject items (representation class) -------------------
//
class BspObjectListRep {

	friend class BspObjectList;

public:
	BspObjectListRep() : ref_count( 0 ) { list = NULL; }
	~BspObjectListRep() { delete list; }

	BspObject*		CreateNewObject();				// prepend empty object to list
	BspObject*		InsertObject( BspObject *obj );	// insert existing object at head

	BoundingBox*	BuildBoundingBoxList();			// build a list of bounding boxes

	int				CountListObjects();				// count list objects

	int				PrepareObjectBSPTree( ObjectBSPTree& objbsptree );
	int				MergeObjectBSPTree( ObjectBSPTree& objbsptree );

	int				CollapseObjectList();			// collapse list into its head object

	int				ProcessObjects( int flags );	// various processing functions

	int				BspTreeAvailable() { return list ? list->BspTreeAvailable() : FALSE; }
	int				BSPTreeAvailable() { return list ? list->BSPTreeAvailable() : FALSE; }
	int				BSPTreeFlatAvailable() { return list ? list->BSPTreeFlatAvailable() : FALSE; }

	BspObject*		getListHead() const { return list; }

private:
	int				ref_count;	// number of references to this list
	BspObject*		list;		// first element in list
};


// class for list of BspObject items (handle class) ---------------------------
//
class BspObjectList {

public:

	// object processing flags
	enum {
		CHECK_PLANES			= 0x0001,
		BUILD_BSP				= 0x0002,
		CHECK_VERTICES			= 0x0004,
		CHECK_EDGES				= 0x0008,
		BUILD_BSP_WITH_CHECKS	= 0x000F,
		DISPLAY_STATS			= 0x0010,
		BUILD_FROM_FLAT			= 0x0020,
		MERGE_VERTICES			= 0x0040,
		CULL_NULL_EDGES			= 0x0080,
		ELIMINATE_T_VERTICES	= 0x0100,
		MERGE_FACES				= 0x0200,
		CALC_PLANE_NORMALS		= 0x0400,
		CALC_BOUNDING_BOXES		= 0x0800,
		CALC_SEPARATOR_PLANES	= 0x1000,
		APPLY_TRANSFORMATIONS	= 0x2000,
	};

public:
	BspObjectList() { rep = new BspObjectListRep(); rep->ref_count = 1; }
	~BspObjectList() { if ( --rep->ref_count == 0 ) delete rep; }

	BspObjectList( const BspObjectList& copyobj );
	BspObjectList& operator =( const BspObjectList& copyobj );

	BspObject*		CreateNewObject() { return rep->CreateNewObject(); }
	BspObject*		InsertObject( BspObject *obj ) { return rep->InsertObject( obj ); }

	// create a list of bounding boxes containing a bounding box for each
	// node in the list. user has to keep track of the list's head!
	BoundingBox*	BuildBoundingBoxList() { return rep->BuildBoundingBoxList(); }

	int				CountListObjects() { return rep->CountListObjects(); }

	int				PrepareObjectBSPTree( ObjectBSPTree& objbsptree ) { return rep->PrepareObjectBSPTree( objbsptree ); }
	int				MergeObjectBSPTree( ObjectBSPTree& objbsptree ) { return rep->MergeObjectBSPTree( objbsptree ); }

	int				CollapseObjectList() { return rep->CollapseObjectList(); }

	// process entire list according to bitfield specifying desired processing
	int				ProcessObjects( int flags ) { return rep->ProcessObjects( flags ); }

	// BSP tree of any representation available (linked or flat)?
	int				BspTreeAvailable() { return rep->BspTreeAvailable(); }
	// linked BSP tree available?
	int				BSPTreeAvailable() { return rep->BSPTreeAvailable(); }
	// flat BSP tree available?
	int				BSPTreeFlatAvailable() { return rep->BSPTreeFlatAvailable(); }

	//NOTE:
	// the previous functions actually return the state of the first BspObject
	// in the list. if bsp trees have not been built through ProcessObjects()
	// it is not guaranteed that the returned state holds for every object in
	// the list! normally, list nodes should not be accessed separately, though.

	// return pointer to first BspObject in list
	BspObject*		getListHead() { return rep->getListHead(); }

private:
	BspObjectListRep *rep;
};

// copy constructor for BspObjectList -----------------------------------------
inline BspObjectList::BspObjectList( const BspObjectList& copyobj )
{
	rep = copyobj.rep;	// shallow copy
	rep->ref_count++;	// with reference counting
}

// assignment operator for BspObjectList --------------------------------------
inline BspObjectList& BspObjectList::operator =( const BspObjectList& copyobj )
{
	if ( &copyobj != this ) {
		// old reference is overwritten
		if ( --rep->ref_count == 0 ) {
			delete rep;
		}
		rep = copyobj.rep;	// shallow copy
		rep->ref_count++;	// with reference counting
	}
	return *this;
}


BSPLIB_NAMESPACE_END


#endif // _BSPOBJECTLIST_H_