Skip to content

Commit

Permalink
Refactor|Map|World: Implement important map element/object iterations…
Browse files Browse the repository at this point in the history
… with C++11 lambdas

Things are now looking significantly cleaner, and should also perform
a little better in an optimized Release build.

There are further iteration mechanisms which would benefit from using
a lambda based approach. However, we've now reached the end of the
"unstable" development phase for 1.15, so these will have to wait.
  • Loading branch information
danij-deng committed Nov 22, 2014
1 parent a7d4169 commit cd70c77
Show file tree
Hide file tree
Showing 41 changed files with 2,143 additions and 2,074 deletions.
19 changes: 19 additions & 0 deletions doomsday/api/api_map.h
Expand Up @@ -315,6 +315,13 @@ DENG_API_TYPEDEF(Map)
struct mobj_s *(*MO_CreateXYZ)(thinkfunc_t function, coord_t x, coord_t y, coord_t z, angle_t angle, coord_t radius, coord_t height, int ddflags);
void (*MO_Destroy)(struct mobj_s *mobj);
struct mobj_s *(*MO_ById)(int id);

/**
* @note validCount should be incremented before calling this to begin a
* new logical traversal. Otherwise Mobjs marked with a validCount equal
* to this will be skipped over (can be used to avoid processing a mobj
* multiple times during a complex and/or non-linear traversal.
*/
int (*MO_BoxIterator)(AABoxd const *box, int (*callback) (struct mobj_s *, void *), void *context);

/**
Expand Down Expand Up @@ -412,13 +419,25 @@ DENG_API_TYPEDEF(Map)
*/
struct polyobj_s *(*PO_ByTag)(int tag);

/**
* @note validCount should be incremented before calling this to begin a
* new logical traversal. Otherwise Polyobjs marked with a validCount equal
* to this will be skipped over (can be used to avoid processing a polyobj
* multiple times during a complex and/or non-linear traversal.
*/
int (*PO_BoxIterator)(AABoxd const *box, int (*callback) (struct polyobj_s *, void *), void *context);

/**
* The po_callback is called when a (any) polyobj hits a mobj.
*/
void (*PO_SetCallback)(void (*func)(struct mobj_s *, void *, void *));

/**
* @note validCount should be incremented before calling this to begin a
* new logical traversal. Otherwise Polyobjs marked with a validCount equal
* to this will be skipped over (can be used to avoid processing a polyobj
* multiple times during a complex and/or non-linear traversal.
*/
int (*SS_BoxIterator)(AABoxd const *box, int (*callback) (ConvexSubspace *, void *), void *context);

// Traversers
Expand Down
13 changes: 7 additions & 6 deletions doomsday/client/include/mesh.h
@@ -1,6 +1,6 @@
/** @file mesh.h Mesh Geometry Data Structure.
/** @file mesh.h Mesh Geometry Data Structure.
*
* @authors Copyright © 2008-2013 Daniel Swanson <danij@dengine.net>
* @authors Copyright © 2008-2014 Daniel Swanson <danij@dengine.net>
*
* @par License
* GPL: http://www.gnu.org/licenses/gpl.html
Expand Down Expand Up @@ -45,7 +45,7 @@ class HEdge;
class Mesh
{
public:
typedef QList<Vertex *> Vertexes;
typedef QList<Vertex *> Vertexs;
typedef QList<Face *> Faces;
typedef QList<HEdge *> HEdges;

Expand Down Expand Up @@ -113,6 +113,7 @@ class Mesh

public:
Mesh();
~Mesh();

/**
* Clear the mesh destroying all geometry elements.
Expand Down Expand Up @@ -155,7 +156,7 @@ class Mesh
/**
* Returns the total number of vertexes in the mesh.
*/
inline int vertexCount() const { return vertexes().count(); }
inline int vertexCount() const { return vertexs().count(); }

/**
* Returns the total number of faces in the mesh.
Expand All @@ -170,7 +171,7 @@ class Mesh
/**
* Returns @c true iff there are no vertexes in the mesh.
*/
inline bool vertexesIsEmpty() const { return vertexes().isEmpty(); }
inline bool vertexsIsEmpty() const { return vertexs().isEmpty(); }

/**
* Returns @c true iff there are no faces in the mesh.
Expand All @@ -185,7 +186,7 @@ class Mesh
/**
* Provides access to the set of all vertexes in the mesh.
*/
Vertexes const &vertexes() const;
Vertexs const &vertexs() const;

/**
* Provides access to the set of all faces in the mesh.
Expand Down
4 changes: 2 additions & 2 deletions doomsday/client/include/render/surfacedecorator.h
@@ -1,7 +1,7 @@
/** @file surfacedecorator.h World surface decorator.
/** @file surfacedecorator.h World surface decorator.
*
* @authors Copyright © 2003-2013 Jaakko Keränen <jaakko.keranen@iki.fi>
* @authors Copyright © 2006-2013 Daniel Swanson <danij@dengine.net>
* @authors Copyright © 2006-2014 Daniel Swanson <danij@dengine.net>
*
* @par License
* GPL: http://www.gnu.org/licenses/gpl.html
Expand Down
36 changes: 17 additions & 19 deletions doomsday/client/include/world/blockmap.h
@@ -1,7 +1,7 @@
/** @file blockmap.h World map element blockmap.
/** @file blockmap.h World map element blockmap.
*
* @authors Copyright © 2003-2013 Jaakko Keränen <jaakko.keranen@iki.fi>
* @authors Copyright © 2006-2013 Daniel Swanson <danij@dengine.net>
* @authors Copyright © 2006-2014 Daniel Swanson <danij@dengine.net>
*
* @par License
* GPL: http://www.gnu.org/licenses/gpl.html
Expand All @@ -21,16 +21,13 @@
#ifndef DENG_WORLD_BLOCKMAP_H
#define DENG_WORLD_BLOCKMAP_H

#include <functional>
#include <de/aabox.h>

#include <de/Vector>

#ifdef min
# undef min
#endif

#ifdef max
# undef max
#ifdef WIN32
# undef max
# undef min
#endif

namespace de {
Expand Down Expand Up @@ -152,27 +149,28 @@ class Blockmap
void unlinkAll();

/**
* Iterate over all elements in the specified @a cell.
* Iterate through all objects in the given @a cell.
*/
int iterate(Cell const &cell, int (*callback) (void *elem, void *context), void *context = 0) const;
LoopResult forAllInCell(Cell const &cell, std::function<LoopResult (void *object)> func) const;

/**
* Iterate over all elements in cells which intercept the specified map space
* @a region.
* Iterate through all objects in all cells which intercept the given map
* space, axis-aligned bounding @a box.
*/
int iterate(AABoxd const &region, int (*callback) (void *elem, void *context), void *context = 0) const;
LoopResult forAllInBox(AABoxd const &box, std::function<LoopResult (void *object)> func) const;

/**
* Iterate over all elements in cells which intercept the line specified by
* the two map space points @a from and @a to. Note that if an element is
* Iterate over all objects in cells which intercept the line specified by
* the two map space points @a from and @a to. Note that if an object is
* processed/visited it does @em not mean that the line actually intercepts
* the element. Further testing between the line and the geometry of the map
* element is necessary if this is a requirement.
* the objects. Further testing between the line and the geometry of the map
* object is necessary if this is a requirement.
*
* @param from Map space point defining the origin of the line.
* @param to Map space point defining the destination of the line.
*/
int iterate(Vector2d const &from, Vector2d const &to, int (*callback) (void *elem, void *context), void *context = 0) const;
LoopResult forAllInPath(Vector2d const &from, Vector2d const &to,
std::function<LoopResult (void *object)> func) const;

/**
* Render a visual for this gridmap to assist in debugging (etc...).
Expand Down

0 comments on commit cd70c77

Please sign in to comment.