Subversion Repository Public Repository

Divide-Framework

This repository has no backups
This repository's network speed is throttled to 100KB/sec

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
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
#include "Headers/SceneGraph.h"
#include "Headers/SceneGraphNode.h"

#include "Scenes/Headers/SceneState.h"
#include "Core/Math/Headers/Transform.h"
#include "Geometry/Shapes/Headers/Object3D.h"
#include "Geometry/Material/Headers/Material.h"
#include "Environment/Water/Headers/Water.h"
#include "Environment/Terrain/Headers/Terrain.h"
#include "Hardware/Video/Shaders/Headers/ShaderProgram.h"

SceneGraphNode::SceneGraphNode(SceneNode* const node) : _node(node),
												  _parent(NULL),
												  _grandParent(NULL),
												  _transform(NULL),
												  _currentSceneState(NULL),
												  _wasActive(true),
											      _active(true),
												  _selected(false),
												  _noDefaultTransform(false),
												  _inView(true),
												  _sorted(false),
												  _silentDispose(false),
												  _updateBB(true),
												  _shouldDelete(false),
                                                  _isReady(false),
												  _updateTimer(GETMSTIME()),
												  _childQueue(0),
                                                  _bbAddExclusionList(0),
                                                  _usageContext(NODE_DYNAMIC),
                                                  _navigationContext(NODE_IGNORE),
												  _overrideNavMeshDetail(false)
{
	_animationTransforms.clear();
}

///If we are destroyng the current graph node
SceneGraphNode::~SceneGraphNode(){
	//delete children nodes recursively
	for_each(NodeChildren::value_type it, _children){
		SAFE_DELETE(it.second);
	}

	//and delete the transform bound to this node
	SAFE_DELETE(_transform);
	_children.clear();
}

void SceneGraphNode::addBoundingBox(const BoundingBox& bb, const SceneNodeType& type) {
    if(!bitCompare(_bbAddExclusionList, type))
        _boundingBox.Add(bb);
}

SceneGraphNode* SceneGraphNode::getRoot() const {
    return _sceneGraph->getRoot();
}

vectorImpl<BoundingBox >&  SceneGraphNode::getBBoxes(vectorImpl<BoundingBox >& boxes ){
	for_each(NodeChildren::value_type& it, _children){
		it.second->getBBoxes(boxes);
	}

    ReadLock r_lock(_queryLock);
	boxes.push_back(_boundingBox);
	return boxes;
}

const BoundingBox& SceneGraphNode::getBoundingBoxTransformed() {
	if(_transform)
		updateBoundingBoxTransform(_transform->getGlobalMatrix());
	return _boundingBox;
}
///When unloading the current graph node
bool SceneGraphNode::unload(){
	//Unload every sub node recursively
	for_each(NodeChildren::value_type& it, _children){
		it.second->unload();
	}
	//Some debug output ...
	if(!_silentDispose && getParent() && _node){
		PRINT_FN(Locale::get("REMOVE_SCENEGRAPH_NODE"),_node->getName().c_str(), getName().c_str());
	}
	//if not root
	if(getParent()){
		//Remove the SceneNode that we own
		RemoveResource(_node);
	}
	return true;
}

///Prints out the SceneGraph structure to the Console
void SceneGraphNode::print(){
	//Starting from the current node
	SceneGraphNode* parent = this;
	U8 i = 0;
	//Count how deep in the graph we are
	//by counting how many ancestors we have before the "root" node
	while(parent != NULL){
		parent = parent->getParent();
		i++;
	}
	//get out material's name
	Material* mat = _node->getMaterial();

	//Some strings to hold the names of our material and shader
	std::string material("none"),shader("none"),depthShader("none");
	//If we have a material
	if(mat){
		//Get the material's name
		material = mat->getName();
		//If we have a shader
		if(mat->getShaderProgram()){
			//Get the shader's name
			shader = mat->getShaderProgram()->getName();
		}
		if(mat->getShaderProgram(DEPTH_STAGE)){
			//Get the depth shader's name
			depthShader = mat->getShaderProgram(DEPTH_STAGE)->getName();
		}
	}
	//Print our current node's information
		PRINT_FN(Locale::get("PRINT_SCENEGRAPH_NODE"), getName().c_str(),
										               _node->getName().c_str(),
													   material.c_str(),
													   shader.c_str(),
													   depthShader.c_str());
	//Repeat for each child, but prefix it with the appropriate number of dashes
	//Based on our ancestor counting earlier
	for_each(NodeChildren::value_type& it, _children){
		for(U8 j = 0; j < i; j++){
			PRINT_F("-");
		}
		it.second->print();
	}
}

///Change current SceneGraphNode's parent
void SceneGraphNode::setParent(SceneGraphNode* const parent) {
	if(_parent){
		//Remove us from the old parent's children map
		NodeChildren::iterator it = _parent->getChildren().find(getName());
		_parent->getChildren().erase(it);
	}
	//Set the parent pointer to the new parent
	_parent = parent;
	//Add ourselves in the new parent's children map
	//Time to add it to the children map
	std::pair<Unordered_map<std::string, SceneGraphNode*>::iterator, bool > result;
	//Try and add it to the map
	result = _parent->getChildren().insert(std::make_pair(getName(),this));
	//If we had a collision (same name?)
	if(!result.second){
		///delete the old SceneGraphNode and add this one instead
		SAFE_UPDATE((result.first)->second,this);
	}
	//That's it. Parent Transforms will be updated in the next render pass;
}

///Add a new SceneGraphNode to the current node's child list based on a SceneNode
SceneGraphNode* SceneGraphNode::addNode(SceneNode* const node,const std::string& name){
	//Create a new SceneGraphNode with the SceneNode's info
	SceneGraphNode* sceneGraphNode = New SceneGraphNode(node);
	//Validate it to be safe
	assert(sceneGraphNode);
	//We need to name the new SceneGraphNode
	//If we did not supply a custom name use the SceneNode's name
	std::string sgName(name.empty() ? node->getName() : name);
	//Name the new SceneGraphNode
	sceneGraphNode->setName(sgName);
	//Set the current node's parent as the new node's grandparent
	sceneGraphNode->setGrandParent(getParent());
	//Get the new node's transform
	Transform* nodeTransform = sceneGraphNode->getTransform();
	//If the current node and the new node have transforms,
	//Update the relationship between the 2
	if(nodeTransform && getTransform()){
		//The child node's parent transform is our current transform matrix
		nodeTransform->setParentTransform(getTransform());
	}
	//Set the current node as the new node's parrent
	sceneGraphNode->setParent(this);
    sceneGraphNode->setSceneGraph(_sceneGraph);
	//Do all the post load operations on the SceneNode
	//Pass a reference to the newly created SceneGraphNode in case we need transforms or bounding boxes
	node->postLoad(sceneGraphNode);
	//return the newly created node
	return sceneGraphNode;
}

//Remove a child node from this Node
void SceneGraphNode::removeNode(SceneGraphNode* node){
	//find the node in the children map
	NodeChildren::iterator it = _children.find(node->getName());
	//If we found the node we are looking for
	if(it != _children.end()) {
		//Remove it from the map
		_children.erase(it);
	}else{
		for(U8 i = 0; i < _children.size(); ++i)
			removeNode(node);
	}
	//Beware. Removing a node, does no unload it!
	//Call delete on the SceneGraphNode's pointer to do that
}

//Finding a node based on the name of the SceneGraphNode or the SceneNode it holds
//Switching is done by setting sceneNodeName to false if we pass a SceneGraphNode name
//or to true if we search by a SceneNode's name
SceneGraphNode* SceneGraphNode::findNode(const std::string& name, bool sceneNodeName){
	//Null return value as default
	SceneGraphNode* returnValue = NULL;
	 //Make sure a name exists
	if (!name.empty()){
		//check if it is the name we are looking for
		//If we are searching for a SceneNode ...
		if(sceneNodeName){
			if (_node->getName().compare(name) == 0){
				// We got the node!
				return this;
			}
		}else{ //If we are searching for a SceneGraphNode ...
			if (getName().compare(name) == 0){
				// We got the node!
				return this;
			}
		}

		//The current node isn't the one we wan't, so recursively check all children
		for_each(NodeChildren::value_type& it, _children){
			returnValue = it.second->findNode(name);
				if(returnValue != NULL){
					// if it is not NULL it is the node we are looking for
					// so just pass it through
					return returnValue;
			}
		}
	}

    // no children's name matches or there are no more children
    // so return NULL, indicating that the node was not found yet
    return NULL;
}

SceneGraphNode* SceneGraphNode::Intersect(const Ray& ray, F32 start, F32 end){
	//Null return value as default
	SceneGraphNode* returnValue = NULL;

	if(_node->isSelectable()){
		ReadLock r_lock(_queryLock);
		if(_boundingBox.Intersect(ray,start,end)){
			return this;
		}
		r_lock.unlock();
	}

	for_each(NodeChildren::value_type& it, _children){
		returnValue = it.second->Intersect(ray,start,end);
		if(returnValue != NULL){
			// if it is not NULL it is the node we are looking for
			// so just pass it through
			return returnValue;
		}
	}

	return returnValue;
}

//This updates the SceneGraphNode's transform by deleting the old one first
void SceneGraphNode::setTransform(Transform* const t) {
	SAFE_UPDATE(_transform,t);
}

//Get the node's transform
Transform* const SceneGraphNode::getTransform(){
	//A node does not necessarily have a transform
	//If this is the case, we can either create a default one
	//Or return NULL. When creating a node we can specify if we do not want a default transform
	if(!_noDefaultTransform && !_transform){
		_transform = New Transform();
		assert(_transform);
        _isReady = true;
	}
	return _transform;
}

void SceneGraphNode::setNavigationContext(const NavigationContext& newContext) {
	_navigationContext = newContext;
	for_each(NodeChildren::value_type& it, _children){
		it.second->setNavigationContext(_navigationContext);
	}
}

void  SceneGraphNode::setNavigationDetailOverride(const bool detailOverride){
	_overrideNavMeshDetail = detailOverride;
	for_each(NodeChildren::value_type& it, _children){
		it.second->setNavigationDetailOverride(detailOverride);
	}
}

Commits for Divide-Framework/trunk/Source Code/Graphs/SceneGraphNode.cpp

Diff revisions: vs.
Revision Author Commited Message
168 Diff Diff k1ngp1n picture k1ngp1n Sat 26 Oct, 2013 19:03:21 +0000

- Reworked the Camera class[[BR]]
— Now fully quaternion based [[BR]]
— Basic camera types added but not used yet (third person, first person, orbit) [[BR]]
- Cleaned up Material and Texture handling [[BR]]
- Added clipping plane support [[BR]]
— Similar to OpenGL fixed-function clip planes but fully shader driven [[BR]]
— Added a new class, “Plane”, that helps define clip planes [[BR]]
- Optimized the Singleton class to allow faster “getInstance” calls without performance penalties [[BR]]
-- “createInstance” must be called for each singleton class before usage. Or “gerOrCreateInstance” can be used, which is basically the former “getInstance” implementation [[BR]]
- Improved console logging by changing some heap allocations to stack and removing dependencies on the std::string class [[BR]]
- Added a lot of performance optimizations related to coding standards and redundant calculations [[BR]]
— e.g. Frustum AABB check didn’t need to recompute the AABB points as they were calculated already [[BR]]
— e.g. A vector did not need to be set to 0 on initialization as that is already it’s default state on creation [[BR]]
— e.g. Faster Framerate and Timing calculations by using less member variables that are not needed outsied of calling functions [[BR]]
- The SceneState now contains the SceneRenderState and is passed on to the SceneGraph’s update calls [[BR]]
- Better material export/import to/from XML format [[BR]]
- More bug fixes and cleanups [[BR]]

161 Diff Diff k1ngp1n picture k1ngp1n Fri 12 Jul, 2013 19:51:50 +0000

[Ionut] [[BR]]
- Solved Navigation Mesh creation from Object3D nodes [[BR]]

159 Diff Diff k1ngp1n picture k1ngp1n Tue 09 Jul, 2013 16:47:05 +0000

[Ionut] [[BR]]
- Added NavMesh config file for AITenisScene [[BR]]
- Improved ReCast debug logging [[BR]]
- Fixed Triangle Strip to Triangle List conversion [[BR]]
- Made Quad3D double-sided

152 Diff Diff k1ngp1n picture k1ngp1n Thu 20 Jun, 2013 14:23:31 +0000

[Ionut] [[BR]]
- New rendering pipeline (experimental and unstable): [[BR]]
— OpenGL 3.x clean context (glLight commands are still used for now, but UBO support is there, but not used yet) [[BR]]
— Custom matrix stacks and UBO based shader data (UBOs cause some link errors on some nVidia cards)[[BR]]
— Multi-threaded texture loading and shader compilation (mt shader compilation disabled for now. needs more tests) [[BR]]
— VAO rendering is self contained (no more enable/disable calls before a draw request) [[BR]]
— Render instance class used for rendering information [[BR]]
[[BR]]
- New unique ID generation base class: GUIDWrapper. Each class that derives from this, gets an application wide unique id on construction [[BR]]
- Added base code for an in-game editor using CEGUI [[BR]]
- Replaced some mutex locks with lockless data structures or atomic data [[BR]]
- CEGUI 0.8.2, FTGL-GL3 and GLIM 0.4 modified to support GLEW_MX if defined [[BR]]
- Dropped VS2008 support [[BR]]
- Networking library, server framework and ReCast files are now projects inside the Divide Framework solution [[BR]]
- New console command “setFov” that modifies the horizontal FoV value in realtime [[BR]]
- New console command “recompileShader” that reparses shader files, recompiles shaders and relinks shader programs who’s names match or contain the argument string [[BR]]
- New debug utility: axis angle drawn in corner of the screen if needed [[BR]]
- More ‘const’-s pasted around the code, more loop performance tweaks (allocations before a loop, tighter loops, etc), more utility member functions added to various classes [[BR]]

151 Diff Diff k1ngp1n picture k1ngp1n Tue 07 May, 2013 00:00:52 +0000

[Ionut] [[BR]]
- Better ReCast integration [[BR]]
— Any entity can be used as an obstacle in the NavMesh if that’s specified in each scene’s assets.xml file for said entity [[BR]]
— New console command, “createNavMesh”, that passes geometry data to ReCast [[BR]]
-— NavMesh generation is not yet complete [[BR]]
- Better PhysX integration [[BR]]
— Each scene passes data to and gets data from the Physics API better and safer[[BR]]
- Multi-threaded support extended: [[BR]]
— Event class replaced with Task [[BR]]
— Kernel uses a threadpool for scene tasks [[BR]]
— Each task can be added to a different threadpool if needed [[BR]]
— Most critical sections use the new boost::atomic wrapper for thread safety [[BR]]
- Rendering system updated [[BR]]
— VBO’s keep track of the geometry type internally [[BR]]
— Rendering by specific element list is internal to the VBO [[BR]]
— VBO’s can draw a “lite” version that doesn’t send Tangent, BiTangent and TexCoord data for depth rendering (disabled) [[BR]]
- Reflectors now offer a preview of the generated reflective texture if needed [[BR]]
- Buttons are now added and rendered by CEGUI [[BR]]
[[BR]]
Deprecation: [[BR]]
- Removed fixed pipeline material system [[BR]]
- Removed BoundingBox late update system [[BR]]
- Shadow references in the material system are now depth references [[BR]]
[[BR]]
Bug fixes: [[BR]]
- Problematic FBO double bind check removed [[BR]]
- Faster terrain rendering via chunk size selection through each scene’s terrain.xml[[BR]]
- Rendering is paused when the window is minimized [[BR]]
- CEGUI and impostors now render properly in deferred rendering mode [[BR]]
- Fixed various level 4 (VS2008) warnings [[BR]]
- Better state management and cleaning [[BR]]
- Better SceneGraph node management and trasformation/AABB update calls [[BR]]
- AITenisScene has proper collisions now [[BR]]

149 Diff Diff k1ngp1n picture k1ngp1n Sun 21 Apr, 2013 21:38:05 +0000

[Ionut] [[BR]]
- Major GUI revamp: [[BR]]
— Fixed CEGUI rendering (invalid state reset after VBO/VAO unbind) [[BR]]
— Added a working Console window with a basic command parser [[BR]]
— GUI inputs take priority over scene (e.g. pressing a key in the console, does not affect the scene)[[BR]]
— Added AutoKey repeat [[BR]]
— Added config options for the GUI [[BR]]
- Revamped OpenGL Vertex Array Object class [[BR]]
— VBO’s without a shader attached will not use VAO’s [[BR]]
— VAO’s and VBO’s cleanup all states after them [[BR]]
- Added multiple Joystick support [[BR]]
- FrameBufferObject take in account the combination of texture id and bind slot when checking for double binds [[BR]]
- Upgraded Framerate/timing system [[BR]]
- Fixed Deferred rendering (typo in normal buffer creation) [[BR]]
- Fixed initial camera placement via scene config (RotateX(Y) replace with setAngleX(Y)) on camera init) [[BR]]
- Added better thread deletion in Event class [[BR]]
- Major mutex/semaphore/shared_lock rework in threaded classes [[BR]]
- Better A.I. initialization/destruction [[BR]]
- Fixed a typo in window positioning [[BR]]
- Better Unit movement code [[BR]]

146 Diff Diff k1ngp1n picture k1ngp1n Wed 10 Apr, 2013 13:20:15 +0000

[Ionut] [[BR]]
*Final LightBranch updates 2/3 : Main trunk merge and build test (VC90, VC100, gDebugger) [[BR]]
-Merged light branch with trunk [[BR]]
-Deleted light branch [[BR]]

121 Diff Diff k1ngp1n picture k1ngp1n Sun 10 Jun, 2012 16:40:45 +0000

[Ionut] [[BR]]
-Added basic localization support [[BR]]
-Added cross-platform INI parsing [[BR]]
-Moved ReCast+Detour to LIBS folder [[BR]]

120 Diff Diff k1ngp1n picture k1ngp1n Sat 09 Jun, 2012 20:44:43 +0000

[Ionut] [[BR]]
-Added a new class, “SceneState” which holds information that does not affect scene logic such as wind and fog information, visibility toggles etc [[BR]]
--“Scene” is new derived from this state as well as from “Resource” [[BR]]
-Cleaned up “SceneManager” and “Scene” classes for fewer virtual call lookups and easier interfaces [[BR]]
-Each scene now loads it’s own XML files (moved from “Kernel” [[BR]]
-Scene’s are now auto-registered to the SceneManager’s scene-factory via a call to “REGISTER_SCENE” [[BR]]
-Added error codes for various initialization steps [[BR]]
-Reworked object selection and deletion (still not tested) [[BR]]
-fog can now be toggled on and off via “config.xml” [[BR]]

116 k1ngp1n picture k1ngp1n Mon 04 Jun, 2012 22:27:07 +0000

[Ionut] [[BR]]
-Removed now useless “BaseCache” class as a simple unordered_map in each manager-type class is all that’s needed [[BR]]
-Moved loading responsibility from each Resource implementation to each "ImplResourceLoader<T>" class (defaults via macro’s are available for convenience) [[BR]]
--Resources now have a “setInitialData” method for setting post-load values [[BR]]
--Also added a loader for Particle Emitters [[BR]]
-Added a new class, “HardwareResource” (for textures, shaders, etc) that needs special loading routines to facilitate future multi-threaded asset streaming [[BR]]
--HardwareResource’s have a “generateHWResource” that should be called after threaded loading routines join with main thread [[BR]]
-Renamed “Guardian” class to “Kernel” as that’s what it’s new responsibility will be in future revisions [[BR]]
-Added the “threadpool” library from here: http://threadpool.sourceforge.net/ (not used yet) [[BR]]
-Added some more macro’s and cleanups [[BR]]