fixed teamcolor bug from last code checkins dealing with threaded interpolation

This commit is contained in:
Mark Vejvoda
2010-05-10 19:35:56 +00:00
parent 52270de56e
commit a68ae2fdfb
3 changed files with 92 additions and 18 deletions

View File

@@ -41,15 +41,6 @@ namespace Glest { namespace Game{
// class MeshCallbackTeamColor
// =====================================================
class MeshCallbackTeamColor: public MeshCallback{
private:
const Texture *teamTexture;
public:
void setTeamTexture(const Texture *teamTexture) {this->teamTexture= teamTexture;}
virtual void execute(const Mesh *mesh);
};
void MeshCallbackTeamColor::execute(const Mesh *mesh){
//team color
@@ -1687,7 +1678,7 @@ void Renderer::renderUnits(){
std::vector<RenderEntity> vctEntity;
for(int i=0; i<world->getFactionCount(); ++i){
meshCallbackTeamColor.setTeamTexture(world->getFaction(i)->getTexture());
// meshCallbackTeamColor.setTeamTexture(world->getFaction(i)->getTexture());
for(int j=0; j<world->getFaction(i)->getUnitCount(); ++j){
unit= world->getFaction(i)->getUnit(j);
if(world->toRenderUnit(unit, visibleQuad)) {
@@ -1728,7 +1719,7 @@ void Renderer::renderUnits(){
unit->setVisible(true);
*/
vctEntity.push_back(RenderEntity(retUnit,NULL,Vec2i(),unit));
vctEntity.push_back(RenderEntity(retUnit,NULL,Vec2i(),unit,world->getFaction(i)->getTexture()));
}
else
{
@@ -1738,7 +1729,7 @@ void Renderer::renderUnits(){
}
modelRenderer->begin(true, true, true, &meshCallbackTeamColor);
renderUnitList(vctEntity);
renderUnitList(vctEntity,&meshCallbackTeamColor);
modelRenderer->end();
//restore
@@ -1749,7 +1740,7 @@ void Renderer::renderUnits(){
assertGl();
}
void Renderer::renderUnitList(std::vector<RenderEntity> &vctEntity) {
void Renderer::renderUnitList(std::vector<RenderEntity> &vctEntity,MeshCallbackTeamColor *meshCallbackTeamColor) {
//SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] vctEntity.size() = %d\n",__FILE__,__FUNCTION__,__LINE__,vctEntity.size());
// Run interpolation threaded if the thread is created
@@ -1778,7 +1769,7 @@ void Renderer::renderUnitList(std::vector<RenderEntity> &vctEntity) {
//SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] idx = %d\n",__FILE__,__FUNCTION__,__LINE__,idx);
renderUnit(entity);
renderUnit(entity,meshCallbackTeamColor);
entityPendingLookup[idx] = true;
renderedUnitCount++;
@@ -1796,9 +1787,13 @@ void Renderer::renderUnitList(std::vector<RenderEntity> &vctEntity) {
//SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] vctEntity.size() = %d\n",__FILE__,__FUNCTION__,__LINE__,vctEntity.size());
}
void Renderer::renderUnit(RenderEntity &entity) {
void Renderer::renderUnit(RenderEntity &entity,MeshCallbackTeamColor *meshCallbackTeamColor) {
Unit *unit = entity.unit;
if(unit != NULL) {
if(meshCallbackTeamColor != NULL) {
meshCallbackTeamColor->setTeamTexture(entity.teamTexture);
}
glMatrixMode(GL_MODELVIEW);
glPushMatrix();

View File

@@ -28,6 +28,8 @@
#include "camera.h"
#include <vector>
#include "base_thread.h"
#include "model_renderer.h"
#include "model.h"
namespace Glest{ namespace Game{
@@ -50,9 +52,24 @@ using Shared::Graphics::Model;
using Shared::Graphics::ParticleSystem;
using Shared::Graphics::Pixmap2D;
using Shared::Graphics::Camera;
using Shared::Graphics::MeshCallback;
using Shared::Graphics::Mesh;
using namespace Shared::PlatformCommon;
// =====================================================
// class MeshCallbackTeamColor
// =====================================================
class MeshCallbackTeamColor: public MeshCallback{
private:
const Texture *teamTexture;
public:
void setTeamTexture(const Texture *teamTexture) {this->teamTexture= teamTexture;}
virtual void execute(const Mesh *mesh);
};
//non shared classes
class Config;
class Game;
@@ -102,6 +119,7 @@ protected:
this->o = obj.o;
this->mapPos = obj.mapPos;
this->unit = obj.unit;
this->teamTexture = obj.teamTexture;;
}
public:
@@ -110,13 +128,15 @@ public:
this->type = retObject;
this->o = NULL;
this->unit = NULL;
this->teamTexture = NULL;
setState(resNone);
}
RenderEntity(RenderEntityType type,Object *o, Vec2i mapPos, Unit *unit) {
RenderEntity(RenderEntityType type,Object *o, Vec2i mapPos, Unit *unit,const Texture2D *teamTexture=NULL) {
this->type = type;
this->o = o;
this->mapPos = mapPos;
this->unit = unit;
this->teamTexture = teamTexture;
setState(resNone);
}
RenderEntity(const RenderEntity &obj) {
@@ -131,6 +151,7 @@ public:
Object *o;
Vec2i mapPos;
Unit *unit;
const Texture2D *teamTexture;
RenderEntityState getState() {
RenderEntityState result;
@@ -359,8 +380,8 @@ public:
void renderWater();
void renderUnits();
void prepareUnitForRender(RenderEntity &entity);
void renderUnitList(std::vector<RenderEntity> &vctEntity);
void renderUnit(RenderEntity &entity);
void renderUnitList(std::vector<RenderEntity> &vctEntity,MeshCallbackTeamColor *meshCallbackTeamColor);
void renderUnit(RenderEntity &entity,MeshCallbackTeamColor *meshCallbackTeamColor);
void renderSelectionEffects();
void renderWaterEffects();

View File

@@ -0,0 +1,58 @@
// ==============================================================
// This file is part of Glest Shared Library (www.glest.org)
//
// Copyright (C) 2001-2008 Martio Figueroa
//
// You can redistribute this code 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
// ==============================================================
#ifndef _SHARED_GRAPHICS_MODELRENDERER_H_
#define _SHARED_GRAPHICS_MODELRENDERER_H_
#include "model.h"
namespace Shared{ namespace Graphics{
class Texture;
// =====================================================
// class MeshCallback
//
/// This gets called before rendering mesh
// =====================================================
class MeshCallback{
public:
virtual ~MeshCallback(){};
virtual void execute(const Mesh *mesh)= 0;
};
// =====================================================
// class ModelRenderer
// =====================================================
class ModelRenderer{
protected:
bool renderNormals;
bool renderTextures;
bool renderColors;
MeshCallback *meshCallback;
public:
ModelRenderer() {meshCallback= NULL;}
virtual ~ModelRenderer(){};
virtual void begin(bool renderNormals, bool renderTextures, bool renderColors, MeshCallback *meshCallback= NULL)=0;
virtual void end()=0;
virtual void render(const Model *model)=0;
virtual void renderNormalsOnly(const Model *model)=0;
};
}}//end namespace
#endif