1
0
forked from 0ad/0ad

Fix decals and LOS texture in Actor Viewer, by slightly reducing use of globals.

Fix particles in Actor Viewer.
Expand terrain in Actor Viewer.
Change background to black so it blends with the LOS texture more
nicely.

This was SVN commit r9172.
This commit is contained in:
Ykkrosh 2011-04-05 20:32:03 +00:00
parent 329d044a9e
commit 29dd635d3b
15 changed files with 136 additions and 38 deletions

View File

@ -159,6 +159,7 @@ public:
: Game(game),
ColladaManager(), MeshManager(ColladaManager), SkeletonAnimManager(ColladaManager),
ObjectManager(MeshManager, SkeletonAnimManager, *game->GetSimulation2()),
LOSTexture(*game->GetSimulation2()),
ViewCamera(),
CullCamera(),
LockCullCamera(false),
@ -467,7 +468,7 @@ void CGameView::BeginFrame()
void CGameView::Render()
{
g_Renderer.RenderScene(this);
g_Renderer.RenderScene(*this);
}
///////////////////////////////////////////////////////////

View File

@ -51,10 +51,13 @@ private:
// Check whether lighting environment has changed and update vertex data if necessary
void CheckLightEnv();
public:
//BEGIN: Implementation of Scene
void EnumerateObjects(const CFrustum& frustum, SceneCollector* c);
virtual void EnumerateObjects(const CFrustum& frustum, SceneCollector* c);
virtual CLOSTexture& GetLOSTexture();
//END: Implementation of Scene
private:
// InitResources(): Load all graphics resources (textures, actor objects and
// alpha maps) required by the game
//void InitResources();
@ -90,7 +93,6 @@ public:
CCamera *GetCamera();
CCinemaManager* GetCinema();
CLOSTexture& GetLOSTexture();
JSObject* GetScript();
static void ScriptingInit();

View File

@ -27,6 +27,7 @@
#include "renderer/Renderer.h"
#include "simulation2/Simulation2.h"
#include "simulation2/components/ICmpRangeManager.h"
#include "simulation2/components/ICmpTerrain.h"
/*
@ -47,8 +48,8 @@ The blurred bitmap is then uploaded into a GL texture for use by the renderer.
// Blur with a NxN filter, where N = g_BlurSize must be an odd number.
static const size_t g_BlurSize = 7;
CLOSTexture::CLOSTexture() :
m_Dirty(true), m_Texture(0), m_MapSize(0), m_TextureSize(0)
CLOSTexture::CLOSTexture(CSimulation2& simulation) :
m_Simulation(simulation), m_Dirty(true), m_Texture(0), m_MapSize(0), m_TextureSize(0)
{
}
@ -102,8 +103,12 @@ const float* CLOSTexture::GetMinimapTextureMatrix()
void CLOSTexture::ConstructTexture(int unit)
{
CTerrain* terrain = g_Game->GetWorld()->GetTerrain();
m_MapSize = terrain->GetVerticesPerSide();
CmpPtr<ICmpTerrain> cmpTerrain(m_Simulation, SYSTEM_ENTITY);
if (cmpTerrain.null())
return;
m_MapSize = cmpTerrain->GetVerticesPerSide();
m_TextureSize = (GLsizei)round_up_to_pow2((size_t)m_MapSize + g_BlurSize - 1);
glGenTextures(1, &m_Texture);
@ -152,7 +157,7 @@ void CLOSTexture::RecomputeTexture(int unit)
std::vector<u8> losData;
losData.resize(GetBitmapSize(m_MapSize, m_MapSize));
CmpPtr<ICmpRangeManager> cmpRangeManager(*g_Game->GetSimulation2(), SYSTEM_ENTITY);
CmpPtr<ICmpRangeManager> cmpRangeManager(m_Simulation, SYSTEM_ENTITY);
if (cmpRangeManager.null())
return;

View File

@ -20,6 +20,8 @@
#include "maths/Matrix3D.h"
#include "simulation2/components/ICmpRangeManager.h"
class CSimulation2;
/**
* Maintains the LOS (fog-of-war / shroud-of-darkness) texture, used for
* rendering and for the minimap.
@ -30,7 +32,7 @@ class CLOSTexture
friend class TestLOSTexture;
public:
CLOSTexture();
CLOSTexture(CSimulation2& simulation);
~CLOSTexture();
/**
@ -75,6 +77,8 @@ private:
size_t GetBitmapSize(size_t w, size_t h);
void GenerateBitmap(ICmpRangeManager::CLosQuerier los, u8* losData, size_t w, size_t h);
CSimulation2& m_Simulation;
bool m_Dirty;
GLuint m_Texture;

View File

@ -88,7 +88,7 @@ bool CObjectEntry::BuildVariation(const std::vector<std::set<CStr> >& selections
variation.decal.m_SizeX, variation.decal.m_SizeZ,
variation.decal.m_Angle, variation.decal.m_OffsetX, variation.decal.m_OffsetZ,
m_Base->m_Properties.m_FloatOnWater);
m_Model = new CModelDecal(g_Game->GetWorld()->GetTerrain(), decal);
m_Model = new CModelDecal(objectManager.GetTerrain(), decal);
return true;
}

View File

@ -26,6 +26,7 @@
#include "ps/Profile.h"
#include "ps/Filesystem.h"
#include "simulation2/Simulation2.h"
#include "simulation2/components/ICmpTerrain.h"
#include "simulation2/components/ICmpVisual.h"
template<typename T, typename S>
@ -155,6 +156,13 @@ CObjectEntry* CObjectManager::FindObjectVariation(CObjectBase* base, const std::
return obj;
}
CTerrain* CObjectManager::GetTerrain()
{
CmpPtr<ICmpTerrain> cmpTerrain(m_Simulation, SYSTEM_ENTITY);
if (cmpTerrain.null())
return NULL;
return cmpTerrain->GetCTerrain();
}
void CObjectManager::DeleteObject(CObjectEntry* entry)
{

View File

@ -30,6 +30,7 @@ class CObjectBase;
class CObjectEntry;
class CSkeletonAnimManager;
class CSimulation2;
class CTerrain;
///////////////////////////////////////////////////////////////////////////////////////////
// CObjectManager: manager class for all possible actor types
@ -72,6 +73,12 @@ public:
CObjectEntry* FindObjectVariation(const CStrW& objname, const std::vector<std::set<CStr> >& selections);
CObjectEntry* FindObjectVariation(CObjectBase* base, const std::vector<std::set<CStr> >& selections);
/**
* Get the terrain object that actors managed by this manager should be linked
* with (primarily for the purpose of decals)
*/
CTerrain* GetTerrain();
/**
* Reload any scripts that were loaded from the given filename.
* (This is used to implement hotloading.)

View File

@ -337,7 +337,7 @@ int ShaderRenderModifier::BeginPass(int pass)
if (shader->HasTexture("losTex"))
{
CLOSTexture& los = g_Game->GetView()->GetLOSTexture();
CLOSTexture& los = g_Renderer.GetScene().GetLOSTexture();
shader->BindTexture("losTex", los.GetTexture());
// Don't bother sending the whole matrix, we just need two floats (scale and translation)
shader->Uniform("losTransform", los.GetTextureMatrix()[0], los.GetTextureMatrix()[12], 0.f, 0.f);

View File

@ -459,6 +459,8 @@ CRenderer::CRenderer()
m_LightEnv = NULL;
m_CurrentScene = NULL;
m_hCompositeAlphaMap = 0;
AddLocalProperty(L"fancyWater", &m_Options.m_FancyWater, false);
@ -1832,19 +1834,28 @@ void CRenderer::SubmitNonRecursive(CModel* model)
///////////////////////////////////////////////////////////
// Render the given scene
void CRenderer::RenderScene(Scene *scene)
void CRenderer::RenderScene(Scene& scene)
{
m_CurrentScene = &scene;
CFrustum frustum = m_CullCamera.GetFrustum();
scene->EnumerateObjects(frustum, this);
scene.EnumerateObjects(frustum, this);
m->particleManager.RenderSubmit(*this, frustum);
ogl_WarnIfError();
RenderSubmissions();
m_CurrentScene = NULL;
}
Scene& CRenderer::GetScene()
{
debug_assert(m_CurrentScene);
return *m_CurrentScene;
}
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// BindTexture: bind a GL texture object to current active unit

View File

@ -204,7 +204,13 @@ public:
* Render the given scene immediately.
* @param scene a Scene object describing what should be rendered.
*/
void RenderScene(Scene* scene);
void RenderScene(Scene& scene);
/**
* Return the scene that is currently being rendered.
* Only valid when the renderer is in a RenderScene call.
*/
Scene& GetScene();
/**
* Render text overlays on top of the scene.
@ -398,6 +404,9 @@ protected:
*/
CCamera m_CullCamera;
// only valid inside a call to RenderScene
Scene* m_CurrentScene;
// color used to clear screen in BeginFrame
float m_ClearColor[4];
// current lighting setup

View File

@ -1,4 +1,4 @@
/* Copyright (C) 2009 Wildfire Games.
/* Copyright (C) 2011 Wildfire Games.
* This file is part of 0 A.D.
*
* 0 A.D. is free software: you can redistribute it and/or modify
@ -34,6 +34,7 @@ class CModelAbstract;
class CModelDecal;
class CParticleEmitter;
class CPatch;
class CLOSTexture;
struct SOverlayLine;
struct SOverlaySprite;
@ -57,6 +58,11 @@ public:
* that are visible.
*/
virtual void EnumerateObjects(const CFrustum& frustum, SceneCollector* c) = 0;
/**
* Return the LOS texture to be used for rendering this scene.
*/
virtual CLOSTexture& GetLOSTexture() = 0;
};

View File

@ -276,7 +276,7 @@ void TerrainRenderer::RenderTerrain(ShadowMap* shadow)
1.f
};
CLOSTexture& losTexture = g_Game->GetView()->GetLOSTexture();
CLOSTexture& losTexture = g_Renderer.GetScene().GetLOSTexture();
int streamflags = STREAM_POS|STREAM_COLOR|STREAM_POSTOUV0;
@ -516,7 +516,7 @@ void TerrainRenderer::PrepareShader(const CShaderProgramPtr& shader, ShadowMap*
shader->Uniform("shadowTransform", shadow->GetTextureMatrix());
}
CLOSTexture& los = g_Game->GetView()->GetLOSTexture();
CLOSTexture& los = g_Renderer.GetScene().GetLOSTexture();
shader->BindTexture("losTex", los.GetTexture());
shader->Uniform("losTransform", los.GetTextureMatrix()[0], los.GetTextureMatrix()[12], 0.f, 0.f);
@ -679,9 +679,9 @@ void TerrainRenderer::RenderWater()
m->fancyWaterShader = h;
}
}
CTerrain* terrain = g_Game->GetWorld()->GetTerrain();
CTerrain* terrain = g_Game->GetWorld()->GetTerrain(); // TODO: stop using g_Game
CLOSTexture& losTexture = g_Game->GetView()->GetLOSTexture();
CLOSTexture& losTexture = g_Renderer.GetScene().GetLOSTexture();
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);

View File

@ -79,6 +79,16 @@ public:
return m_Terrain->GetExactGroundLevel(x, z);
}
virtual uint32_t GetVerticesPerSide()
{
return m_Terrain->GetVerticesPerSide();
}
virtual CTerrain* GetCTerrain()
{
return m_Terrain;
}
virtual void ReloadTerrain()
{
// TODO: should refactor this code to be nicer

View File

@ -24,6 +24,8 @@
#include "maths/FixedVector3D.h"
class CTerrain;
class ICmpTerrain : public IComponent
{
public:
@ -33,6 +35,10 @@ public:
virtual float GetExactGroundLevel(float x, float z) = 0;
virtual uint32_t GetVerticesPerSide() = 0;
virtual CTerrain* GetCTerrain() = 0;
/**
* Call when the underlying CTerrain has been modified behind our backs.
* (TODO: eventually we should manage the CTerrain in this class so nobody

View File

@ -1,4 +1,4 @@
/* Copyright (C) 2010 Wildfire Games.
/* Copyright (C) 2011 Wildfire Games.
* This file is part of 0 A.D.
*
* 0 A.D. is free software: you can redistribute it and/or modify
@ -22,8 +22,10 @@
#include "View.h"
#include "graphics/ColladaManager.h"
#include "graphics/LOSTexture.h"
#include "graphics/Model.h"
#include "graphics/ObjectManager.h"
#include "graphics/ParticleManager.h"
#include "graphics/Patch.h"
#include "graphics/SkeletonAnimManager.h"
#include "graphics/Terrain.h"
@ -49,9 +51,16 @@ struct ActorViewerImpl : public Scene
{
NONCOPYABLE(ActorViewerImpl);
public:
ActorViewerImpl()
: Entity(INVALID_ENTITY), Terrain(), ColladaManager(), MeshManager(ColladaManager), SkeletonAnimManager(ColladaManager),
UnitManager(), Simulation2(&UnitManager, &Terrain), ObjectManager(MeshManager, SkeletonAnimManager, Simulation2)
ActorViewerImpl() :
Entity(INVALID_ENTITY),
Terrain(),
ColladaManager(),
MeshManager(ColladaManager),
SkeletonAnimManager(ColladaManager),
UnitManager(),
Simulation2(&UnitManager, &Terrain),
ObjectManager(MeshManager, SkeletonAnimManager, Simulation2),
LOSTexture(Simulation2)
{
UnitManager.SetObjectManager(ObjectManager);
}
@ -74,15 +83,26 @@ public:
CObjectManager ObjectManager;
CUnitManager UnitManager;
CSimulation2 Simulation2;
CLOSTexture LOSTexture;
// Simplistic implementation of the Scene interface
void EnumerateObjects(const CFrustum& frustum, SceneCollector* c)
virtual void EnumerateObjects(const CFrustum& frustum, SceneCollector* c)
{
if (GroundEnabled)
c->Submit(Terrain.GetPatch(0, 0));
{
for (ssize_t pj = 0; pj < Terrain.GetPatchesPerSide(); ++pj)
for (ssize_t pi = 0; pi < Terrain.GetPatchesPerSide(); ++pi)
c->Submit(Terrain.GetPatch(pi, pj));
}
Simulation2.RenderSubmit(*c, frustum, false);
}
virtual CLOSTexture& GetLOSTexture()
{
return LOSTexture;
}
};
ActorViewer::ActorViewer()
@ -91,22 +111,28 @@ ActorViewer::ActorViewer()
m.WalkEnabled = false;
m.GroundEnabled = true;
m.ShadowsEnabled = g_Renderer.GetOptionBool(CRenderer::OPT_SHADOWS);
m.Background = SColor4ub(255, 255, 255, 255);
m.Background = SColor4ub(0, 0, 0, 255);
// Create a tiny empty piece of terrain, just so we can put shadows
// on it without having to think too hard
m.Terrain.Initialize(1, NULL);
m.Terrain.Initialize(2, NULL);
CTerrainTextureEntry* tex = g_TexMan.FindTexture("whiteness");
if (tex)
{
CPatch* patch = m.Terrain.GetPatch(0, 0);
for (ssize_t i = 0; i < PATCH_SIZE; ++i)
for (ssize_t pi = 0; pi < m.Terrain.GetPatchesPerSide(); ++pi)
{
for (ssize_t j = 0; j < PATCH_SIZE; ++j)
for (ssize_t pj = 0; pj < m.Terrain.GetPatchesPerSide(); ++pj)
{
CMiniPatch& mp = patch->m_MiniPatches[i][j];
mp.Tex = tex;
mp.Priority = 0;
CPatch* patch = m.Terrain.GetPatch(pi, pj);
for (ssize_t i = 0; i < PATCH_SIZE; ++i)
{
for (ssize_t j = 0; j < PATCH_SIZE; ++j)
{
CMiniPatch& mp = patch->m_MiniPatches[i][j];
mp.Tex = tex;
mp.Priority = 0;
}
}
}
}
}
@ -178,7 +204,8 @@ void ActorViewer::SetActor(const CStrW& name, const CStrW& animation)
CmpPtr<ICmpPosition> cmpPosition(m.Simulation2, m.Entity);
if (!cmpPosition.null())
{
cmpPosition->JumpTo(entity_pos_t::FromInt(CELL_SIZE*PATCH_SIZE/2), entity_pos_t::FromInt(CELL_SIZE*PATCH_SIZE/2));
ssize_t c = CELL_SIZE * m.Terrain.GetPatchesPerSide()*PATCH_SIZE/2;
cmpPosition->JumpTo(entity_pos_t::FromInt(c), entity_pos_t::FromInt(c));
cmpPosition->SetYRotation(entity_angle_t::FromFloat((float)M_PI));
}
needsAnimReload = true;
@ -301,7 +328,7 @@ void ActorViewer::Render()
cmpVisual->GetBounds().GetCentre(centre);
else
centre.Y = 0.f;
centre.X = centre.Z = CELL_SIZE * PATCH_SIZE/2;
centre.X = centre.Z = CELL_SIZE * m.Terrain.GetPatchesPerSide()*PATCH_SIZE/2;
CCamera camera = View::GetView_Actor()->GetCamera();
camera.m_Orientation.Translate(centre.X, centre.Y, centre.Z);
@ -309,7 +336,7 @@ void ActorViewer::Render()
g_Renderer.SetSceneCamera(camera, camera);
g_Renderer.RenderScene(&m);
g_Renderer.RenderScene(m);
// ....
@ -352,6 +379,7 @@ void ActorViewer::Update(float dt)
{
m.Simulation2.Update((int)(dt*1000));
m.Simulation2.Interpolate(dt, 0);
g_Renderer.GetParticleManager().Interpolate(dt);
if (m.WalkEnabled && m.CurrentSpeed)
{
@ -362,8 +390,9 @@ void ActorViewer::Update(float dt)
float z = cmpPosition->GetPosition().Z.ToFloat();
z -= m.CurrentSpeed*dt;
// Wrap at the edges, so it doesn't run off into the horizon
if (z < CELL_SIZE*PATCH_SIZE * 0.4f)
z = CELL_SIZE*PATCH_SIZE * 0.6f;
ssize_t c = CELL_SIZE * m.Terrain.GetPatchesPerSide()*PATCH_SIZE/2;
if (z < c - CELL_SIZE*PATCH_SIZE * 0.1f)
z = c + CELL_SIZE*PATCH_SIZE * 0.1f;
cmpPosition->JumpTo(cmpPosition->GetPosition().X, entity_pos_t::FromFloat(z));
}
}