Skip to content

Commit

Permalink
Refactor: Moved particle generators to a new class named Generators
Browse files Browse the repository at this point in the history
Generators comprises the underlying ptcgen_t collection and all support
structures and logics for bookkeeping purposes.

Each GameMap instance owns a Generators collection.
  • Loading branch information
danij-deng committed Mar 9, 2012
1 parent 240e57f commit 4577ad0
Show file tree
Hide file tree
Showing 13 changed files with 832 additions and 511 deletions.
2 changes: 2 additions & 0 deletions doomsday/engine/engine.pro
Expand Up @@ -186,6 +186,7 @@ DENG_HEADERS = \
portable/include/fs_util.h \
portable/include/game.h \
portable/include/gamemap.h \
portable/include/generators.h \
portable/include/gl_defer.h \
portable/include/gl_deferredapi.h \
portable/include/gl_draw.h \
Expand Down Expand Up @@ -436,6 +437,7 @@ SOURCES += \
portable/src/fs_util.c \
portable/src/game.c \
portable/src/gamemap.c \
portable/src/generators.c \
portable/src/gl_defer.c \
portable/src/gl_deferredapi.c \
portable/src/gl_draw.c \
Expand Down
2 changes: 1 addition & 1 deletion doomsday/engine/portable/include/def_data.h
Expand Up @@ -347,7 +347,7 @@ typedef struct ded_embsound_s {
float volume;
} ded_embsound_t;

typedef struct {
typedef struct ded_ptcstage_s {
ded_flags_t type;
int tics;
float variance; // Stage variance (time).
Expand Down
61 changes: 46 additions & 15 deletions doomsday/engine/portable/include/gamemap.h
Expand Up @@ -23,8 +23,11 @@
#ifndef LIBDENG_GAMEMAP_H
#define LIBDENG_GAMEMAP_H

#include "p_particle.h"

struct thinkerlist_s;
struct clmoinfo_s;
struct generators_s;

/// Size of Blockmap blocks in map units. Must be an integer power of two.
#define MAPBLOCKUNITS (128)
Expand Down Expand Up @@ -66,6 +69,8 @@ typedef struct gamemap_s {
boolean inited;
} thinkers;

struct generators_s* generators;

// Client only data:
cmhash_t clMobjHash[CLIENT_MOBJ_HASH_SIZE];

Expand Down Expand Up @@ -514,6 +519,16 @@ boolean GameMap_ClMobjIterator(GameMap* map, boolean (*callback) (struct mobj_s*
struct clplane_s* GameMap_NewClPlane(GameMap* map, uint sectornum, clplanetype_t type,
float dest, float speed);

/**
* Retrieve a pointer to the Generators collection for this map.
* If no collection has yet been constructed a new empty collection will be
* initialized as a result of this call.
*
* @param map GameMap instance.
* @return Generators collection for this map.
*/
struct generators_s* GameMap_Generators(GameMap* map);

/**
* Initialize all Polyobjs in the map. To be called after map load.
*
Expand All @@ -540,9 +555,9 @@ void GameMap_LinkMobjInBlockmap(GameMap* map, struct mobj_s* mo);
boolean GameMap_UnlinkMobjInBlockmap(GameMap* map, struct mobj_s* mo);

int GameMap_IterateCellMobjs(GameMap* map, const uint coords[2],
int (*callback) (struct mobj_s*, void*), void* paramaters);
int (*callback) (struct mobj_s*, void*), void* parameters);
int GameMap_IterateCellBlockMobjs(GameMap* map, const struct gridmapblock_s* blockCoords,
int (*callback) (struct mobj_s*, void*), void* paramaters);
int (*callback) (struct mobj_s*, void*), void* parameters);

int GameMap_MobjsBoxIterator(GameMap* map, const AABoxf* box,
int (*callback) (struct mobj_s*, void*), void* parameters);
Expand All @@ -558,17 +573,19 @@ void GameMap_InitLineDefBlockmap(GameMap* map, const_pvec2_t min, const_pvec2_t
void GameMap_LinkLineDefInBlockmap(GameMap* map, linedef_t* lineDef);

int GameMap_IterateCellLineDefs(GameMap* map, const uint coords[2],
int (*callback) (linedef_t*, void*), void* paramaters);
int (*callback) (linedef_t*, void*), void* parameters);
int GameMap_IterateCellBlockLineDefs(GameMap* map, const struct gridmapblock_s* blockCoords,
int (*callback) (linedef_t*, void*), void* paramaters);
int (*callback) (linedef_t*, void*), void* parameters);

int GameMap_LineDefIterator(GameMap* map, int (*callback) (linedef_t*, void*), void* parameters);

int GameMap_IterateCellPolyobjLineDefs(GameMap* map, const uint coords[2],
int (*callback) (linedef_t*, void*), void* paramaters);
int (*callback) (linedef_t*, void*), void* parameters);
int GameMap_IterateCellBlockPolyobjLineDefs(GameMap* map, const struct gridmapblock_s* blockCoords,
int (*callback) (linedef_t*, void*), void* paramaters);
int (*callback) (linedef_t*, void*), void* parameters);

int GameMap_LineDefsBoxIterator(GameMap* map, const AABoxf* box,
int (*callback) (linedef_t*, void*), void* paramaters);
int (*callback) (linedef_t*, void*), void* parameters);

int GameMap_PolyobjLinesBoxIterator(GameMap* map, const AABoxf* box,
int (*callback) (linedef_t*, void*), void* parameters);
Expand All @@ -581,7 +598,7 @@ int GameMap_PolyobjLinesBoxIterator(GameMap* map, const AABoxf* box,
* to GameMap_IterateCellLineDefs(), then make one or more calls to it.
*/
int GameMap_AllLineDefsBoxIterator(GameMap* map, const AABoxf* box,
int (*callback) (linedef_t*, void*), void* paramaters);
int (*callback) (linedef_t*, void*), void* parameters);

/**
* Construct an initial (empty) Subsector Blockmap for this map.
Expand All @@ -595,14 +612,16 @@ void GameMap_LinkSubsectorInBlockmap(GameMap* map, subsector_t* subsector);

int GameMap_IterateCellSubsectors(GameMap* map, const uint coords[2],
sector_t* sector, const AABoxf* box, int localValidCount,
int (*callback) (subsector_t*, void*), void* paramaters);
int (*callback) (subsector_t*, void*), void* parameters);
int GameMap_IterateCellBlockSubsectors(GameMap* map, const struct gridmapblock_s* blockCoords,
sector_t* sector, const AABoxf* box, int localValidCount,
int (*callback) (subsector_t*, void*), void* paramaters);
int (*callback) (subsector_t*, void*), void* parameters);

int GameMap_SubsectorsBoxIterator(GameMap* map, const AABoxf* box, sector_t* sector,
int (*callback) (subsector_t*, void*), void* parameters);

int GameMap_SubsectorIterator(GameMap* map, int (*callback) (subsector_t*, void*), void* parameters);

/**
* Construct an initial (empty) Polyobj Blockmap for this map.
*
Expand All @@ -615,9 +634,9 @@ void GameMap_LinkPolyobjInBlockmap(GameMap* map, polyobj_t* po);
void GameMap_UnlinkPolyobjInBlockmap(GameMap* map, polyobj_t* po);

int GameMap_IterateCellPolyobjs(GameMap* map, const uint coords[2],
int (*callback) (polyobj_t*, void*), void* paramaters);
int (*callback) (polyobj_t*, void*), void* parameters);
int GameMap_IterateCellBlockPolyobjs(GameMap* map, const struct gridmapblock_s* blockCoords,
int (*callback) (polyobj_t*, void*), void* paramaters);
int (*callback) (polyobj_t*, void*), void* parameters);

/**
* The validCount flags are used to avoid checking polys that are marked in
Expand All @@ -627,18 +646,30 @@ int GameMap_IterateCellBlockPolyobjs(GameMap* map, const struct gridmapblock_s*
int GameMap_PolyobjsBoxIterator(GameMap* map, const AABoxf* box,
int (*callback) (struct polyobj_s*, void*), void* parameters);

int GameMap_PolyobjIterator(GameMap* map, int (*callback) (polyobj_t*, void*), void* parameters);

int GameMap_VertexIterator(GameMap* map, int (*callback) (vertex_t*, void*), void* parameters);

int GameMap_SideDefIterator(GameMap* map, int (*callback) (sidedef_t*, void*), void* parameters);

int GameMap_SectorIterator(GameMap* map, int (*callback) (sector_t*, void*), void* parameters);

int GameMap_HEdgeIterator(GameMap* map, int (*callback) (HEdge*, void*), void* parameters);

int GameMap_NodeIterator(GameMap* map, int (*callback) (node_t*, void*), void* parameters);

/**
* Traces a line between @a from and @a to, making a callback for each
* interceptable object linked within Blockmap cells which cover the path this
* defines.
*/
int GameMap_PathTraverse2(GameMap* map, float const from[2], float const to[2],
int flags, traverser_t callback, void* paramaters);
int flags, traverser_t callback, void* parameters);
int GameMap_PathTraverse(GameMap* map, float const from[2], float const to[2],
int flags, traverser_t callback/* void* paramaters=NULL*/);
int flags, traverser_t callback/* void* parameters=NULL*/);

int GameMap_PathXYTraverse2(GameMap* map, float fromX, float fromY, float toX, float toY,
int flags, traverser_t callback, void* paramaters);
int flags, traverser_t callback, void* parameters);
int GameMap_PathXYTraverse(GameMap* map, float fromX, float fromY, float toX, float toY,
int flags, traverser_t callback);

Expand Down
142 changes: 142 additions & 0 deletions doomsday/engine/portable/include/generators.h
@@ -0,0 +1,142 @@
/**
* @file generators.h
* Generator collection. @ingroup map
*
* A collection of ptcgen_t instances and implements all bookkeeping logic
* pertinent to the management of said instances.
*
* @authors Copyright &copy; 2003-2012 Jaakko Keränen <jaakko.keranen@iki.fi>
* @authors Copyright &copy; 2006-2012 Daniel Swanson <danij@dengine.net>
*
* @par License
* GPL: http://www.gnu.org/licenses/gpl.html
*
* <small>This program is free software; you can redistribute it 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. This program is distributed in the hope that it
* will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty
* of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
* Public License for more details. You should have received a copy of the GNU
* General Public License along with this program; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA</small>
*/

#ifndef LIBDENG_MAP_GENERATORS
#define LIBDENG_MAP_GENERATORS

#include "p_particle.h"

/// Unique identifier associated with each generator in the collection.
typedef short ptcgenid_t;

/// Maximum number of ptcgen_ts supported by a Generators instance.
#define GENERATORS_MAX (256)

/**
* Generators instance. Created with Generators_New().
*/
typedef struct generators_s Generators;

/**
* Constructs a new generators collection. Must be deleted with Generators_Delete().
*
* @param sectorCount Number of sectors the collection must support.
*/
Generators* Generators_New(uint sectorCount);

/**
* Destructs the generators collection @a generators.
* @param generators Generators instance.
*/
void Generators_Delete(Generators* generators);

/**
* Clear all references to any ptcgen_t instances currently owned by this
* collection.
*
* @warning Does nothing about any memory allocated for said instances.
* It is therefore the caller's responsibilty to
*/
void Generators_Clear(Generators* generators);

/**
* Retrieve the generator associated with the unique @a generatorId
*
* @param generators Generators instance.
* @param generatorId Unique id of the generator to lookup.
* @return Pointer to ptcgen iff found, else @c NULL.
*/
ptcgen_t* Generators_Generator(Generators* generators, ptcgenid_t generatorId);

/**
* Lookup the unique id of @a generator in this collection.
*
* @param generators Generators instance.
* @param generator Generator to lookup an id for.
* @return The unique id if found else @c -1 iff if @a generator is not linked.
*/
ptcgenid_t Generators_GeneratorId(Generators* generators, const ptcgen_t* generator);

/**
* Retrieve the next available generator id.
*
* @param generators Generators instance.
* @return The next available id else @c -1 iff there are no unused ids.
*/
ptcgenid_t Generators_NextAvailableId(Generators* generators);

/**
* Unlink a generator from this collection. Ownership is unaffected.
*
* @param generators Generators instance.
* @param generator Generator to be unlinked.
* @return Same as @a generator for caller convenience.
*/
ptcgen_t* Generators_Unlink(Generators* generators, ptcgen_t* generator);

/**
* Link a generator into this collection. Ownership does NOT transfer to
* the collection.
*
* @param generators Generators instance.
* @param slot Logical slot into which the generator will be linked.
* @return Same as @a generator for caller convenience.
*/
ptcgen_t* Generators_Link(Generators* generators, ptcgenid_t slot, ptcgen_t* generator);

/**
* Clear all sector --> generator links.
*
* @param generators Generators instance.
*/
void Generators_ClearSectorLinks(Generators* generators);

/**
* Link the a sector with a generator.
*
* @param generators Generators instance.
* @param generator Generator to link with the identified sector.
* @param sectorIndex Index of the sector to link the generator with.
*
* @return Same as @a generator for caller convenience.
*/
ptcgen_t* Generators_LinkToSector(Generators* generators, ptcgen_t* generator, uint sectorIndex);

/**
* Walk the entire list of generators.
*
* @param generators Generators instance.
*/
int Generators_Iterate(Generators* generators, int (*callback) (ptcgen_t*, void*), void* parameters);

/**
* Walk the list of sector-linked generators.
*
* @param generators Generators instance.
*/
int Generators_IterateSectorLinked(Generators* generators, uint sectorIndex,
int (*callback) (ptcgen_t*, void*), void* parameters);

#endif /// LIBDENG_MAP_GENERATORS

0 comments on commit 4577ad0

Please sign in to comment.