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
#include "Headers/WarScene.h"
#include "Headers/WarSceneAIActionList.h"

#include "Geometry/Shapes/Headers/Predefined/Sphere3D.h"
#include "Geometry/Shapes/Headers/Predefined/Quad3D.h"
#include "Rendering/RenderPass/Headers/RenderQueue.h"
#include "Dynamics/Entities/Units/Headers/NPC.h"
#include "Rendering/Camera/Headers/Camera.h"
#include "Managers/Headers/SceneManager.h"
#include "Environment/Sky/Headers/Sky.h"
#include "Managers/Headers/AIManager.h"
#include "Rendering/Headers/Frustum.h"
#include "GUI/Headers/GUI.h"

//begin copy-paste: randarea scenei
void WarScene::render(){
	Sky& sky = Sky::getInstance();

	sky.setParams(_camera->getEye(),_sunVector,false,true,true);
	sky.draw();

	_sceneGraph->render();
}
//end copy-paste

void WarScene::preRender(){
	vec2<F32> _sunAngle = vec2<F32>(0.0f, RADIANS(45.0f));
	_sunVector = vec4<F32>(	-cosf(_sunAngle.x) * sinf(_sunAngle.y),
							-cosf(_sunAngle.y),
							-sinf(_sunAngle.x) * sinf(_sunAngle.y),
							0.0f );

	LightManager::getInstance().getLight(0)->setLightProperties(LIGHT_POSITION,_sunVector);

}

void WarScene::processEvents(F32 time){
	F32 FpsDisplay = 0.3f;
	if (time - _eventTimers[0] >= FpsDisplay){
		GUI::getInstance().modifyText("fpsDisplay", "FPS: %5.2f", Framerate::getInstance().getFps());
		GUI::getInstance().modifyText("RenderBinCount", "Number of items in Render Bin: %d", GFX_RENDER_BIN_SIZE);
		_eventTimers[0] += FpsDisplay;
	}
}

void WarScene::resetSimulation(){
	getEvents().clear();
}

void WarScene::startSimulation(){

	resetSimulation();

	if(getEvents().empty()){//Maxim un singur eveniment
		Event_ptr newSim(New Event(12,true,false,boost::bind(&WarScene::processSimulation,this,rand() % 5,TYPE_INTEGER)));
		addEvent(newSim);
	}
}

void WarScene::processSimulation(boost::any a, CallbackParam b){

	if(getEvents().empty()) return;
	bool updated = false;
	std::string mesaj;
	SceneGraphNode* Soldier1 = _sceneGraph->findNode("Soldier1");

	assert(Soldier1);assert(_groundPlaceholder);
}

void WarScene::processInput(){
	Scene::processInput();

	if(_angleLR) _camera->RotateX(_angleLR * Framerate::getInstance().getSpeedfactor());
	if(_angleUD) _camera->RotateY(_angleUD * Framerate::getInstance().getSpeedfactor());
	if(_moveFB)  _camera->MoveForward(_moveFB * (Framerate::getInstance().getSpeedfactor()/5));
	if(_moveLR)	 _camera->MoveStrafe(_moveLR * (Framerate::getInstance().getSpeedfactor()/5));
}

bool WarScene::load(const std::string& name){

	setInitialData();

	bool state = false;
	//Add a light
	Light* light = addDefaultLight();
	light->setLightProperties(LIGHT_AMBIENT,_white);
	light->setLightProperties(LIGHT_DIFFUSE,_white);
	light->setLightProperties(LIGHT_SPECULAR,_white);
												
	//Load scene resources
	state = loadResources(true);	
	
	//Position camera
	_camera->RotateX(RADIANS(45));
	_camera->RotateY(RADIANS(25));
	_camera->setEye(vec3<F32>(14,5.5f,11.5f));
	_faction1 = New AICoordination(1);
	_faction2 = New AICoordination(2);


	//------------------------ Restul elementelor jocului -----------------------------///
	_groundPlaceholder = _sceneGraph->findNode("Ground_placeholder");
	_groundPlaceholder->getNode<SceneNode>()->getMaterial()->setCastsShadows(false);

	state = loadEvents(true);
	return state;
}

bool WarScene::initializeAI(bool continueOnErrors){
		//----------------------------INTELIGENTA ARTIFICIALA------------------------------//

	AIEntity* aiSoldier = NULL;
	SceneGraphNode* soldierMesh = _sceneGraph->findNode("Soldier1");
	if(soldierMesh){
		AIEntity* aiSoldier = New AIEntity("Soldier1");
		aiSoldier->attachNode(soldierMesh);
		aiSoldier->addSensor(VISUAL_SENSOR,New VisualSensor());
		aiSoldier->addSensor(COMMUNICATION_SENSOR, New CommunicationSensor(aiSoldier));
		aiSoldier->addActionProcessor(New WarSceneAIActionList());
		aiSoldier->setTeam(_faction1);
		_army1.push_back(aiSoldier);
	}

	soldierMesh = _sceneGraph->findNode("Soldier2");
	if(soldierMesh){
		aiSoldier = New AIEntity("Soldier2");
		aiSoldier->attachNode(soldierMesh);
		aiSoldier->addSensor(VISUAL_SENSOR,New VisualSensor());
		aiSoldier->addSensor(COMMUNICATION_SENSOR, New CommunicationSensor(aiSoldier));
		aiSoldier->addActionProcessor(New WarSceneAIActionList());
		aiSoldier->setTeam(_faction2);
		_army2.push_back(aiSoldier);
	}
	//----------------------- Unitati ce vor fi controlate de AI ---------------------//
	for(U8 i = 0; i < _army1.size(); i++){
		NPC* soldier = New NPC(_army1[i]);
		soldier->setMovementSpeed(2); /// 2 m/s
		_army1NPCs.push_back(soldier);
		AIManager::getInstance().addEntity(_army1[i]);
	}

	for(U8 i = 0; i < _army2.size(); i++){
		NPC* soldier = New NPC(_army2[i]);
		soldier->setMovementSpeed(2); /// 2 m/s
		_army2NPCs.push_back(soldier);
		AIManager::getInstance().addEntity(_army2[i]);
	}
	return !(_army1.empty() || _army2.empty());
}

bool WarScene::deinitializeAI(bool continueOnErrors){
	for(U8 i = 0; i < _army1NPCs.size(); i++){
		SAFE_DELETE(_army1NPCs[i]);
	}
	_army1NPCs.clear();
	for(U8 i = 0; i < _army2NPCs.size(); i++){
		SAFE_DELETE(_army2NPCs[i]);
	}
	_army2NPCs.clear();
	SAFE_DELETE(_faction1);
	SAFE_DELETE(_faction2);
	return true;
}

bool WarScene::loadResources(bool continueOnErrors){
	
	GUI::getInstance().addButton("Simulate", "Simulate", vec2<F32>(Application::getInstance().getWindowDimensions().width-220 ,
															 Application::getInstance().getWindowDimensions().height/1.1f),
													    	 vec2<F32>(100,25),vec3<F32>(0.65f,0.65f,0.65f),
															 boost::bind(&WarScene::startSimulation,this));

	GUI::getInstance().addText("fpsDisplay",           //Unique ID
		                       vec3<F32>(60,60,0),          //Position
							   BITMAP_8_BY_13,    //Font
							   vec3<F32>(0.0f,0.2f, 1.0f),  //Color
							   "FPS: %s",0);    //Text and arguments
	GUI::getInstance().addText("RenderBinCount",
								vec3<F32>(60,70,0),
								BITMAP_8_BY_13,
								vec3<F32>(0.6f,0.2f,0.2f),
								"Number of items in Render Bin: %d",0);

	
	_eventTimers.push_back(0.0f); //Fps
	return true;
}

bool WarScene::unload(){
	Sky::getInstance().DestroyInstance();
	return Scene::unload();
}


void WarScene::onKeyDown(const OIS::KeyEvent& key){
	Scene::onKeyDown(key);
	switch(key.key)	{
		case OIS::KC_W:
			_moveFB = 0.25f;
			break;
		case OIS::KC_A:
			_moveLR = 0.25f;
			break;
		case OIS::KC_S:
			_moveFB = -0.25f;
			break;
		case OIS::KC_D:
			_moveLR = -0.25f;
			break;
		default:
			break;
	}
}

void WarScene::onKeyUp(const OIS::KeyEvent& key){
	Scene::onKeyUp(key);
	switch(key.key)	{
		case OIS::KC_W:
		case OIS::KC_S:
			_moveFB = 0;
			break;
		case OIS::KC_A:
		case OIS::KC_D:
			_moveLR = 0;
			break;
		case OIS::KC_F1:
			_sceneGraph->print();
			break;
		default:
			break;
	}

}
void WarScene::onMouseMove(const OIS::MouseEvent& key){
	Scene::onMouseMove(key);
	if(_mousePressed){
		if(_prevMouse.x - key.state.X.abs > 1 )
			_angleLR = -0.15f;
		else if(_prevMouse.x - key.state.X.abs < -1 )
			_angleLR = 0.15f;
		else
			_angleLR = 0;

		if(_prevMouse.y - key.state.Y.abs > 1 )
			_angleUD = -0.1f;
		else if(_prevMouse.y - key.state.Y.abs < -1 )
			_angleUD = 0.1f;
		else
			_angleUD = 0;
	}
	
	_prevMouse.x = key.state.X.abs;
	_prevMouse.y = key.state.Y.abs;
}

void WarScene::onMouseClickDown(const OIS::MouseEvent& key,OIS::MouseButtonID button){
	Scene::onMouseClickDown(key,button);
	if(button == 0) 
		_mousePressed = true;
}

void WarScene::onMouseClickUp(const OIS::MouseEvent& key,OIS::MouseButtonID button){
	Scene::onMouseClickUp(key,button);
	if(button == 0)	{
		_mousePressed = false;
		_angleUD = 0;
		_angleLR = 0;
	}
}

Commits for Divide-Framework/trunk/Source Code/Scenes/WarScene/WarScene.cpp

Diff revisions: vs.
Revision Author Commited Message
117 Diff Diff k1ngp1n picture k1ngp1n Tue 05 Jun, 2012 17:30:40 +0000

[Ionut] [[BR]]
-Separated responsibilities between “Application” and “Kernel” [[BR]]
--“Application” handles data such as window dimensions, logs, “ParamHandler” etc [[BR]]
--“Kernel” handles the main loop, SFX, GFX, physics, sceneManager etc updates [[BR]]
---“Kernel” is now a “Core” component [[BR]]
-Reduced coupling between some classes by passing more info via parameters rather than relying on singleton access [[BR]]
--Ex: eyePos in “Terrain”,“Water” and “Trigger” classes is now passed as a "vec3<F32>" on render call rather than querying “CameraManager” [[BR]]
-Reworked “GLWrapper” shutdown routine [[BR]]
Singleton witch hunt [[BR]]
-“Kernel” is no longer a singleton and it’s initialized on application startup in the “Application” class[[BR]]
-“CameraManager” is no longer a singleton and it’s instantiated in the kernel [[BR]]

116 Diff Diff 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]]

113 Diff Diff k1ngp1n picture k1ngp1n Fri 01 Jun, 2012 16:51:23 +0000

[Ionut] [[BR]]
-Fixed animated bounding box calculations[[BR]]
-BoundingBox recalculation per frame is now a general SceneNode property [[BR]]
--Note: Animated BB’s have problems with multi-threaded collision detection for now (see AITenisScene) [[BR]]
-Wrapped boost::mutex to separate file and moved it to shared_mutex structure as read requests are more frequent than write requests [[BR]]
-Mesh class now calls animations update on all of it’s subclasses so animations for each node in a mesh are in sync [[BR]]
-Split up GUI elements by class [[BR]]
-Added base code for a console GUI element (disabled) [[BR]]
-Animations can now be disabled in confg file [[BR]]
-Added a “texture not found” default texture [[BR]]
-Some AI rewrite in AITenisScene (translation to english in next commit) [[BR]]
-Inlines, const’s, cleanups, etc [[BR]]

111 Diff Diff k1ngp1n picture k1ngp1n Tue 08 May, 2012 21:49:31 +0000

[Ionut] [[BR]]
-Added animation support based on Scott Lee’s animation loader library added a few revision’s back [[BR]]
--Added cached skeleton rendering to the library [[BR]]
--Added cached AABB transformations based on current animation frame [[BR]]
--Scene animators are added per submesh and only processed if said submesh is visible and only in the rendering stage: FINAL_STAGE [[BR]]
[[BR]]
-Added support for shader-based VBO data upload (glVertexAttribPointer) with full backwards compatibility to old method (glTexCoordPointer)[[BR]]
-Added support for Index Buffer Object (improper name) indice upload for VBO’s with full backwards compatibility to old method [[BR]]
-Reworked coordination class to better handle AIEntity teams [[BR]]
-Added “updateSceneState(currentTime)” callback that is called once per frame (used for animation update)[[BR]]
-Added “initializeAI/deinitializeAI” scene callbacks for AI creation/destruction [[BR]]
-Templatized the Quaternion class [[BR]]
-Added a “drawLines” subroutine to the rendering api[[BR]]
-Disabled tree loading in MainScene as current ASSIMP implementation is slow. Will be restored after backing and loading models to own format is added in next revision [[BR]]
-Other various small performance tweaks [[BR]]

109 k1ngp1n picture k1ngp1n Wed 25 Apr, 2012 09:52:52 +0000

[Ionut] [[BR]]
-Added a WarScene prototype that represents the foundation for my MSc thesis [[BR]]

--Features planned for this scene (ToDo list): [[BR]]
---Advanced AI (pathfinding, decision making, team based coordination)[[BR]]
---Weapons, projectiles, particles [[BR]]
---Animations [[BR]]
---Performance increases [[BR]]