From d8be908233fd7b85492d7a9e87f07bb207173990 Mon Sep 17 00:00:00 2001
From: Stijn Buys <ingar@osirion.org>
Date: Sun, 25 Nov 2012 12:06:13 +0000
Subject: Moved core::EntityGlobe into a separate file, added various methods
 to core::Item and core::Slot, added r_slots cvar to draw entity slots and
 docks, added game methods for mounting and umounting of weapons, added
 playerlist to chat window.

---
 src/render/draw.cc      | 135 +++++++++++++++++++++++++++++++++---------------
 src/render/draw.h       |   6 +--
 src/render/render.cc    |   6 +++
 src/render/render.h     |   2 +
 src/render/renderext.cc |   2 +
 src/render/state.cc     |  32 ++++++------
 6 files changed, 122 insertions(+), 61 deletions(-)

(limited to 'src/render')

diff --git a/src/render/draw.cc b/src/render/draw.cc
index 12a64ad..dea0c6b 100644
--- a/src/render/draw.cc
+++ b/src/render/draw.cc
@@ -8,6 +8,8 @@
 #include <iomanip>
 
 #include "core/application.h"
+#include "core/entity.h"
+#include "core/entityglobe.h"
 #include "core/gameinterface.h"
 #include "core/range.h"
 
@@ -727,7 +729,9 @@ void draw_model_axis(const core::Entity *entity)
 void draw_pass_model_fragments()
 {
 	/*
-	 * 	FIXME 
+	 * 	FIXME
+	 * 	fragmentgroups with movement tied to engine activity can not be synchronized with server-side collision
+	 * 
 	 * 	For moving and rotating fragmentgroups, the enginetime must match
 	 * 	the time used by core:: to calculate the rotation or movement 
 	 * 	of the asssociated collision models.
@@ -756,8 +760,9 @@ void draw_pass_model_fragments()
 				ext_render(entity)->thrust()
 			);
 
-			if (entity->slots())
+			if (r_slots && r_slots->value()) {
 				draw_slots(entity);
+			}
 			
 			if (r_bbox->value()) {
 				gl::color(entity->color());
@@ -979,7 +984,6 @@ void draw_pass_model_fx(float elapsed)
 				);
 			}
 		
-		
 			// draw particle systems
 			if (draw_particles && ext_render(entity)->particles().size()) {
 				gl::disable(GL_CULL_FACE);
@@ -1227,60 +1231,106 @@ void draw(float seconds)
 	globes_list.clear();
 }
 
-// draw weapon slots
-// weapons are drawn in model space coordinate, model transformations 
+// draw model slots: weapon slots and docking ports
 void draw_slots(const core::Entity *entity)
 {
-	assert(entity->slots() && entity->model());
-	
-	gl::disable(GL_DEPTH_TEST);
+	if (!entity->model()) {
+		return;
+	}
+	 gl::disable(GL_DEPTH_TEST);
 	
 	//const float modelscale = entity->radius() / entity->model()->radius();
+	
+	// draw docks
+	if (entity->model()->docks().size()) {
+		gl::color(0, 1.0f, 1.0f, 1.0f);
+		
+		for (model::Model::Docks::iterator dit = entity->model()->docks().begin(); dit != entity->model()->docks().end(); dit++) {
+			model::Dock *dock = (*dit);
+			math::Vector3f maxbox(dock->location());
+			math::Vector3f minbox(dock->location());
+
+			for (size_t i = 0; i < 3; i++) {
+				maxbox[i] += 0.025;
+				minbox[i] -= 0.025;
+			}
 
-	gl::color(1.0f, 0.0f, 0.0f, 1.0f);
+			// top
+			gl::begin(gl::LineLoop);
+			gl::vertex(maxbox.x(), maxbox.y(), maxbox.z());
+			gl::vertex(minbox.x(), maxbox.y(), maxbox.z());
+			gl::vertex(minbox.x(), minbox.y(), maxbox.z());
+			gl::vertex(maxbox.x(), minbox.y(), maxbox.z());
+			gl::end();
 
-	for(core::Slots::iterator it = entity->slots()->begin(); it != entity->slots()->end(); ++it) {
-		core::Slot *slot = (*it);
-		
-		math::Vector3f maxbox(slot->location());
-		math::Vector3f minbox(slot->location());
+			// bottom
+			gl::begin(gl::LineLoop);
+			gl::vertex(maxbox.x(), maxbox.y(), minbox.z());
+			gl::vertex(minbox.x(), maxbox.y(), minbox.z());
+			gl::vertex(minbox.x(), minbox.y(), minbox.z());
+			gl::vertex(maxbox.x(), minbox.y(), minbox.z());
+			gl::end();
 
-		for (size_t i = 0; i < 3; i++) {
-			maxbox[i] += 0.025;
-			minbox[i] -= 0.025;
+			gl::begin(gl::Lines);
+			gl::vertex(maxbox.x(), maxbox.y(), maxbox.z());
+			gl::vertex(maxbox.x(), maxbox.y(), minbox.z());
+			gl::vertex(minbox.x(), maxbox.y(), maxbox.z());
+			gl::vertex(minbox.x(), maxbox.y(), minbox.z());
+			gl::vertex(minbox.x(), minbox.y(), maxbox.z());
+			gl::vertex(minbox.x(), minbox.y(), minbox.z());
+			gl::vertex(maxbox.x(), minbox.y(), maxbox.z());
+			gl::vertex(maxbox.x(), minbox.y(), minbox.z());
+			gl::end();
 		}
+	}
+	
+	// draw weapon slots
+	if (entity->slots()) {
+		gl::color(1.0f, 0.0f, 0.0f);
+		
+		for(core::Slots::iterator it = entity->slots()->begin(); it != entity->slots()->end(); ++it) {
+			core::Slot *slot = (*it);
+			
+			math::Vector3f maxbox(slot->location());
+			math::Vector3f minbox(slot->location());
 
-		// top
-		gl::begin(gl::LineLoop);
-		gl::vertex(maxbox.x(), maxbox.y(), maxbox.z());
-		gl::vertex(minbox.x(), maxbox.y(), maxbox.z());
-		gl::vertex(minbox.x(), minbox.y(), maxbox.z());
-		gl::vertex(maxbox.x(), minbox.y(), maxbox.z());
-		gl::end();
+			for (size_t i = 0; i < 3; i++) {
+				maxbox[i] += 0.025;
+				minbox[i] -= 0.025;
+			}
 
-		// bottom
-		gl::begin(gl::LineLoop);
-		gl::vertex(maxbox.x(), maxbox.y(), minbox.z());
-		gl::vertex(minbox.x(), maxbox.y(), minbox.z());
-		gl::vertex(minbox.x(), minbox.y(), minbox.z());
-		gl::vertex(maxbox.x(), minbox.y(), minbox.z());
-		gl::end();
+			// top
+			gl::begin(gl::LineLoop);
+			gl::vertex(maxbox.x(), maxbox.y(), maxbox.z());
+			gl::vertex(minbox.x(), maxbox.y(), maxbox.z());
+			gl::vertex(minbox.x(), minbox.y(), maxbox.z());
+			gl::vertex(maxbox.x(), minbox.y(), maxbox.z());
+			gl::end();
 
-		gl::begin(gl::Lines);
-		gl::vertex(maxbox.x(), maxbox.y(), maxbox.z());
-		gl::vertex(maxbox.x(), maxbox.y(), minbox.z());
-		gl::vertex(minbox.x(), maxbox.y(), maxbox.z());
-		gl::vertex(minbox.x(), maxbox.y(), minbox.z());
-		gl::vertex(minbox.x(), minbox.y(), maxbox.z());
-		gl::vertex(minbox.x(), minbox.y(), minbox.z());
-		gl::vertex(maxbox.x(), minbox.y(), maxbox.z());
-		gl::vertex(maxbox.x(), minbox.y(), minbox.z());
-		gl::end();
+			// bottom
+			gl::begin(gl::LineLoop);
+			gl::vertex(maxbox.x(), maxbox.y(), minbox.z());
+			gl::vertex(minbox.x(), maxbox.y(), minbox.z());
+			gl::vertex(minbox.x(), minbox.y(), minbox.z());
+			gl::vertex(maxbox.x(), minbox.y(), minbox.z());
+			gl::end();
+
+			gl::begin(gl::Lines);
+			gl::vertex(maxbox.x(), maxbox.y(), maxbox.z());
+			gl::vertex(maxbox.x(), maxbox.y(), minbox.z());
+			gl::vertex(minbox.x(), maxbox.y(), maxbox.z());
+			gl::vertex(minbox.x(), maxbox.y(), minbox.z());
+			gl::vertex(minbox.x(), minbox.y(), maxbox.z());
+			gl::vertex(minbox.x(), minbox.y(), minbox.z());
+			gl::vertex(maxbox.x(), minbox.y(), maxbox.z());
+			gl::vertex(maxbox.x(), minbox.y(), minbox.z());
+			gl::end();
+		}
 	}
 
 	gl::enable(GL_DEPTH_TEST);
 }
-
+/*
 // draw HUD target world space geometry, like dock indicators
 void draw_target(const core::Entity *entity)
 {
@@ -1344,5 +1394,6 @@ void draw_target(const core::Entity *entity)
 	gl::pop();
 	gl::disable(GL_DEPTH_TEST);
 }
+*/
 
 }
diff --git a/src/render/draw.h b/src/render/draw.h
index 71321c5..21145c2 100644
--- a/src/render/draw.h
+++ b/src/render/draw.h
@@ -17,11 +17,11 @@ namespace render
 
 /// draw the world
 void draw(float seconds);
-
+/*
 /// draws model docks, used when targetting an entity
 void draw_target(const core::Entity *entity);
-
-/// draws entity weapon slots
+*/
+/// draws entity slots
 void draw_slots(const core::Entity *entity);
 
 /// reset
diff --git a/src/render/render.cc b/src/render/render.cc
index 45d3fda..794d777 100644
--- a/src/render/render.cc
+++ b/src/render/render.cc
@@ -11,6 +11,8 @@
 
 #include "auxiliary/functions.h"
 #include "core/application.h"
+#include "core/entity.h"
+#include "core/entityglobe.h"
 #include "core/gameinterface.h"
 #include "filesystem/filesystem.h"
 #include "model/model.h"
@@ -40,6 +42,7 @@ core::Cvar *r_mipmap = 0;
 core::Cvar *r_physics = 0;
 core::Cvar *r_normals = 0;
 core::Cvar *r_normalize = 0;
+core::Cvar *r_slots = 0;
 
 void func_list_textures(std::string const &args)
 {
@@ -100,6 +103,9 @@ void init(int width, int height)
 
 	r_physics = core::Cvar::get("r_physics", "0", core::Cvar::Archive);
 	r_physics->set_info("[bool] render physics (local game only)");
+	
+	r_slots = core::Cvar::get("r_slots", "0", core::Cvar::Archive);
+	r_slots->set_info("[bool] render model slots");
 
 	Screenshot::screenshotformat = core::Cvar::get("screenshot_format", "jpg", core::Cvar::Archive);
 	Screenshot::screenshotformat->set_info("[string] screenshot format: jpg png tga");
diff --git a/src/render/render.h b/src/render/render.h
index 2162457..71d05df 100644
--- a/src/render/render.h
+++ b/src/render/render.h
@@ -67,6 +67,8 @@ extern core::Cvar *r_physics;
 extern core::Cvar *r_mipmap;
 /// use GL_NORMALIZE instead of GL_RESCALE_NORMAL
 extern core::Cvar *r_normalize;
+/// render model slots (debug)
+extern core::Cvar *r_slots;
 
 inline RenderExt *ext_render(const core::Entity *entity)
 {
diff --git a/src/render/renderext.cc b/src/render/renderext.cc
index b96bdfe..f8fd453 100644
--- a/src/render/renderext.cc
+++ b/src/render/renderext.cc
@@ -9,6 +9,8 @@
 
 #include "math/functions.h"
 #include "core/application.h"
+#include "core/entity.h"
+#include "core/entityglobe.h"
 #include "core/range.h"
 #include "model/model.h"
 #include "render/camera.h"
diff --git a/src/render/state.cc b/src/render/state.cc
index 5f026f0..ce3a0ab 100644
--- a/src/render/state.cc
+++ b/src/render/state.cc
@@ -299,23 +299,23 @@ void State::use_material(const model::Material * material) {
 		}
 
 	} else {	
-			// envmapped without texture: use the skybox as envmap
-			if (material->flags() & model::Material::Environment) {
-				if (core::localplayer()->zone()->sky().size()) {
-					gl::enable(GL_TEXTURE_CUBE_MAP);
-					
-					glTexGeni(GL_S, GL_TEXTURE_GEN_MODE, GL_REFLECTION_MAP);
-					glTexGeni(GL_T, GL_TEXTURE_GEN_MODE, GL_REFLECTION_MAP);
-					glTexGeni(GL_R, GL_TEXTURE_GEN_MODE, GL_REFLECTION_MAP);
-					
-					gl::enable(GL_TEXTURE_GEN_S);
-					gl::enable(GL_TEXTURE_GEN_T);
-					gl::enable(GL_TEXTURE_GEN_R);
-				} else {
-					color.assign(0.0f, 0.0f, 0.0f);
-				}
-				glMateriali(GL_FRONT, GL_SHININESS, 4);
+		// envmapped without texture: use the skybox as envmap
+		if (material->flags() & model::Material::Environment) {
+			if (core::localplayer()->zone()->sky().size()) {
+				gl::enable(GL_TEXTURE_CUBE_MAP);
+				
+				glTexGeni(GL_S, GL_TEXTURE_GEN_MODE, GL_REFLECTION_MAP);
+				glTexGeni(GL_T, GL_TEXTURE_GEN_MODE, GL_REFLECTION_MAP);
+				glTexGeni(GL_R, GL_TEXTURE_GEN_MODE, GL_REFLECTION_MAP);
+				
+				gl::enable(GL_TEXTURE_GEN_S);
+				gl::enable(GL_TEXTURE_GEN_T);
+				gl::enable(GL_TEXTURE_GEN_R);
+			} else {
+				color.assign(0.0f, 0.0f, 0.0f);
 			}
+			glMateriali(GL_FRONT, GL_SHININESS, 4);
+		}
 	}
 
 	gl::color(color);
-- 
cgit v1.2.3