Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Map|Client: Continued cleaning up particle generator management
  • Loading branch information
danij-deng committed Jan 13, 2014
1 parent 16a8bfd commit d5184f2
Show file tree
Hide file tree
Showing 9 changed files with 228 additions and 169 deletions.
20 changes: 19 additions & 1 deletion doomsday/client/include/render/rend_particle.h
Expand Up @@ -25,7 +25,25 @@

#include "world/map.h"

class Sector;
// Maximum number of particle textures (not instances).
#define MAX_PTC_TEXTURES 300

// Maximum number of particle models (not instances).
#define MAX_PTC_MODELS 100

enum ParticleType
{
PTC_NONE,
PTC_POINT,
PTC_LINE,
// New types can be added here.
PTC_TEXTURE = 100,
// ...followed by MAX_PTC_TEXTURES types.
PTC_MODEL = 1000
};

DENG_EXTERN_C byte useParticles;
DENG_EXTERN_C int maxParticles;

void Rend_ParticleRegister();

Expand Down
6 changes: 6 additions & 0 deletions doomsday/client/include/world/map.h
Expand Up @@ -787,6 +787,12 @@ class Map
*/
void initContactBlockmaps();

/**
* Spawn all generators for the map which should be initialized automatically
* during map setup.
*/
void initGenerators();

/**
* Destroys all clientside clmobjs in the map. To be called when a network
* game ends.
Expand Down
43 changes: 17 additions & 26 deletions doomsday/client/include/world/p_particle.h
Expand Up @@ -32,22 +32,6 @@ class Line;
class Plane;
struct mobj_s;

// Maximum number of particle textures (not instances).
#define MAX_PTC_TEXTURES 300

// Maximum number of particle models (not instances).
#define MAX_PTC_MODELS 100

enum ParticleType {
PTC_NONE,
PTC_POINT,
PTC_LINE,
// New types can be added here.
PTC_TEXTURE = 100,
// ...followed by MAX_PTC_TEXTURES types.
PTC_MODEL = 1000
};

/**
* POD structure used when querying the current state of a particle.
*/
Expand Down Expand Up @@ -196,6 +180,11 @@ struct Generator
*/
blendmode_t blendmode() const;

/**
* Returns the total number of active particles for the generator.
*/
int activeParticleCount() const;

/**
* Provides readonly access to the generator particle info data.
*/
Expand All @@ -209,23 +198,31 @@ struct Generator

/**
* Attempt to spawn a new particle.
*
* @return Index of the newly spawned particle; otherwise @c -1.
*/
ParticleInfo *newParticle();
int newParticle();

/**
* The movement is done in two steps:
* Z movement is done first. Skyflat kills the particle.
* XY movement checks for hits with solid walls (no backsector).
* This is supposed to be fast and simple (but not too simple).
*/
void moveParticle(ParticleInfo *pt);
void moveParticle(int index);

void spinParticle(ParticleInfo *pt);
void spinParticle(ParticleInfo &pt);

/**
* A particle may be "projected" onto the floor or ceiling of a sector.
*/
float particleZ(ParticleInfo const *pt) const;
float particleZ(ParticleInfo const &pt) const;

public:
/**
* Register the console commands, variables, etc..., of this module.
*/
static void consoleRegister();

private:
Id _id; ///< Unique in the map.
Expand All @@ -240,12 +237,6 @@ typedef Generator::ParticleStage GeneratorParticleStage;
void Generator_Delete(Generator *gen);
void Generator_Thinker(Generator *gen);

DENG_EXTERN_C byte useParticles;
DENG_EXTERN_C int maxParticles;
DENG_EXTERN_C float particleSpawnRate;

void P_PtcInitForMap(de::Map &map);

/**
* Attempt to spawn all flat-triggered particle generators for the @a map.
* To be called after map setup is completed.
Expand Down
27 changes: 15 additions & 12 deletions doomsday/client/src/def_main.cpp
@@ -1,10 +1,8 @@
/** @file def_main.cpp
/** @file def_main.cpp Definitions Subsystem.
*
* Definitions Subsystem.
*
* @authors Copyright &copy; 2003-2013 Jaakko Keränen <jaakko.keranen@iki.fi>
* @authors Copyright &copy; 2005-2013 Daniel Swanson <danij@dengine.net>
* @authors Copyright &copy; 2006 Jamie Jones <jamie_jones_au@yahoo.com.au>
* @authors Copyright © 2003-2013 Jaakko Keränen <jaakko.keranen@iki.fi>
* @authors Copyright © 2005-2013 Daniel Swanson <danij@dengine.net>
* @authors Copyright © 2006 Jamie Jones <jamie_jones_au@yahoo.com.au>
*
* @par License
* GPL: http://www.gnu.org/licenses/gpl.html
Expand All @@ -21,13 +19,11 @@
* 02110-1301 USA</small>
*/

#include <string.h>
#include <ctype.h>

#include <de/NativePath>
#include <QTextStream>
#define DENG_NO_API_MACROS_DEFINITIONS

#include "de_base.h"
#include "def_main.h"

#include "de_system.h"
#include "de_platform.h"
#include "de_console.h"
Expand All @@ -39,13 +35,20 @@
#include "de_resource.h"

#include "world/p_particle.h"
#ifdef __CLIENT__
# include "render/rend_particle.h"
#endif

#define DENG_NO_API_MACROS_DEFINITIONS
#include "api_def.h"

// XGClass.h is actually a part of the engine.
#include "../../../plugins/common/include/xgclass.h"

#include <de/NativePath>
#include <QTextStream>
#include <cctype>
#include <cstring>

using namespace de;

#define LOOPi(n) for(i = 0; i < (n); ++i)
Expand Down
8 changes: 4 additions & 4 deletions doomsday/client/src/render/rend_main.cpp
Expand Up @@ -421,6 +421,7 @@ void Rend_Register()
Sky::consoleRegister();
Rend_ModelRegister();
Rend_ParticleRegister();
Generator::consoleRegister();
Rend_RadioRegister();
Rend_SpriteRegister();
LensFx_Register();
Expand Down Expand Up @@ -3658,7 +3659,7 @@ static void drawMasked()
* dynamic lights. Details take precedence (they always cover entire primitives
* and usually *all* of the surfaces in a scene).
*/
static void drawAllLists()
static void drawAllLists(Map &map)
{
DENG_ASSERT(!Sys_GLCheckError());
DENG_ASSERT_IN_MAIN_THREAD();
Expand Down Expand Up @@ -3859,8 +3860,7 @@ static void drawAllLists()
drawMasked();

// Draw particles.
/// @todo Do not assume the CURRENT map.
Rend_RenderParticles(App_WorldSystem().map());
Rend_RenderParticles(map);

if(usingFog)
{
Expand Down Expand Up @@ -3920,7 +3920,7 @@ void Rend_RenderMap(Map &map)
// Draw the world!
traverseBspAndDrawLeafs(&map.bspRoot());
}
drawAllLists();
drawAllLists(map);

// Draw various debugging displays:
drawAllSurfaceTangentVectors(map);
Expand Down
37 changes: 18 additions & 19 deletions doomsday/client/src/render/rend_particle.cpp
Expand Up @@ -45,12 +45,8 @@ using namespace de;
// Point + custom textures.
#define NUM_TEX_NAMES (MAX_PTC_TEXTURES)

struct porder_t
{
Generator *generator;
int ptID; // Particle id.
float distance;
};
byte useParticles = true;
int maxParticles = 0; // Unlimited.

DGLuint pointTex, ptctexname[MAX_PTC_TEXTURES];
int particleNearLimit;
Expand All @@ -60,15 +56,20 @@ static size_t numParts;
static dd_bool hasPoints, hasLines, hasModels, hasNoBlend, hasBlend;
static dd_bool hasPointTexs[NUM_TEX_NAMES];

static size_t orderSize;
struct porder_t
{
Generator *generator;
int ptID; // Particle id.
float distance;
};
static porder_t *order;
static size_t orderSize;

void Rend_ParticleRegister()
{
// Cvars
C_VAR_BYTE ("rend-particle", &useParticles, 0, 0, 1);
C_VAR_INT ("rend-particle-max", &maxParticles, CVF_NO_MAX, 0, 0);
C_VAR_FLOAT("rend-particle-rate", &particleSpawnRate, 0, 0, 5);
C_VAR_FLOAT("rend-particle-diffuse", &particleDiffuse, CVF_NO_MAX, 0, 0);
C_VAR_INT ("rend-particle-visible-near", &particleNearLimit, CVF_NO_MAX, 0, 0);
}
Expand Down Expand Up @@ -251,15 +252,7 @@ static int countActiveGeneratorParticlesWorker(Generator *gen, void *context)
{
if(R_ViewerGeneratorIsVisible(*gen))
{
size_t &count = *(size_t *) context;
ParticleInfo const *pinfo = gen->particleInfo();
for(int p = 0; p < gen->count; ++p, pinfo++)
{
if(pinfo->stage >= 0)
{
count += 1;
}
}
*static_cast<size_t *>(context) += gen->activeParticleCount();
}
return false; // Continue iteration.
}
Expand All @@ -278,7 +271,7 @@ static int populateSortBuffer(Generator *gen, void *context)
if(pinfo->stage < 0 || !pinfo->bspLeaf)
continue;

// Is the particle's sector visible?
// Is the BSP leaf at the particle's origin visible?
if(!R_ViewerBspLeafIsVisible(*pinfo->bspLeaf))
continue; // No; this particle can't be seen.

Expand Down Expand Up @@ -320,9 +313,13 @@ static int populateSortBuffer(Generator *gen, void *context)
}

if(gen->flags.testFlag(Generator::BlendAdditive))
{
hasBlend = true;
}
else
{
hasNoBlend = true;
}
}

return false; // Continue iteration.
Expand Down Expand Up @@ -545,7 +542,9 @@ static void renderParticles(int rtype, bool withBlend)
short stageType = st->type;
if(stageType >= PTC_TEXTURE && stageType < PTC_TEXTURE + MAX_PTC_TEXTURES &&
0 == ptctexname[stageType - PTC_TEXTURE])
{
stageType = PTC_POINT;
}

// Only render one type of particles.
if((rtype == PTC_MODEL && dst->model < 0) ||
Expand Down Expand Up @@ -661,7 +660,7 @@ static void renderParticles(int rtype, bool withBlend)
float center[3];
center[VX] = FIX2FLT(pinfo->origin[VX]);
center[VZ] = FIX2FLT(pinfo->origin[VY]);
center[VY] = gen->particleZ(pinfo);
center[VY] = gen->particleZ(*pinfo);

if(!flatOnPlane && !flatOnWall)
{
Expand Down
15 changes: 14 additions & 1 deletion doomsday/client/src/world/map.cpp
Expand Up @@ -65,6 +65,7 @@
# include "WallEdge"
# include "render/viewports.h"
# include "render/rend_main.h"
# include "render/rend_particle.h"
# include "render/sky.h"
#endif

Expand Down Expand Up @@ -1300,6 +1301,7 @@ DENG2_OBSERVES(bsp::Partitioner, UnclosedSectorFound)
DENG2_ASSERT((unsigned)listIndex < gens.listsSize);

// Must check that it isn't already there...
bool found = false;
for(Generators::ListNode *it = gens.lists[listIndex]; it; it = it->next)
{
if(it->gen == gen)
Expand All @@ -1308,10 +1310,12 @@ DENG2_OBSERVES(bsp::Partitioner, UnclosedSectorFound)
// that logging is pointless (and negatively affecting performance).
//LOG_DEBUG("Attempted repeat link of generator %p to list %u.")
// << gen << listIndex;
continue; // No, no...
found = true; // No, no...
}
}

if(found) continue;

// We need a new link.
if(Generators::ListNode *link = gens.newLink())
{
Expand Down Expand Up @@ -1486,6 +1490,15 @@ void Map::spreadAllContacts(AABoxd const &region)
region.maxX + Lumobj::radiusMax(), region.maxY + Lumobj::radiusMax()));
}

void Map::initGenerators()
{
LOG_AS("Map::initGenerators");
Time begunAt;
P_SpawnTypeParticleGens(*this);
P_SpawnMapParticleGens(*this);
LOG_MAP_VERBOSE("Completed in %.2f seconds") << begunAt.since();
}

void Map::clearClMobjs()
{
d->clMobjHash.clear();
Expand Down

0 comments on commit d5184f2

Please sign in to comment.