Skip to content

Commit

Permalink
Refactored the edgetip management in order to remove the need for a g…
Browse files Browse the repository at this point in the history
…lobal index, which has now been removed.

Finished the editable map destructor. With luck, there are no remaining leaks.
  • Loading branch information
danij committed Feb 1, 2008
1 parent 31c57a1 commit c5ab474
Show file tree
Hide file tree
Showing 6 changed files with 75 additions and 62 deletions.
17 changes: 16 additions & 1 deletion doomsday/engine/portable/include/bsp_edge.h
Expand Up @@ -42,6 +42,21 @@
// Smallest degrees between two angles before being considered equal.
#define ANG_EPSILON (1.0 / 1024.0)

// An edge tip is where an edge meets a vertex.
typedef struct edgetip_s {
// Link in list. List is kept in ANTI-clockwise order.
struct edgetip_s *next;
struct edgetip_s *prev;

// Angle that line makes at vertex (degrees).
angle_g angle;

// Segs on each side of the edge. Left is the side of increasing
// angles, right is the side of decreasing angles. Either can be
// NULL for one sided edges.
struct hedge_s *hEdges[2];
} edgetip_t;

typedef struct hedge_s {
vertex_t *v[2]; // [Start, End] of the half-edge..

Expand Down Expand Up @@ -95,7 +110,7 @@ hedge_t *HEdge_Split(hedge_t *oldHEdge, double x, double y);
// Edge tip functions:
void BSP_CreateVertexEdgeTip(vertex_t *vert, double dx, double dy,
hedge_t *back, hedge_t *front);
void BSP_DestroyVertexEdgeTip(struct edgetip_s *tip);
void BSP_CountEdgeTips(vertex_t *vert, uint *oneSided, uint *twoSided);
sector_t *BSP_VertexCheckOpen(vertex_t *vert, double dx, double dy);
void BSP_FreeEdgeTips(void);
#endif
4 changes: 1 addition & 3 deletions doomsday/engine/portable/include/bsp_level.h
Expand Up @@ -3,7 +3,7 @@
* License: GPL
* Online License Link: http://www.gnu.org/licenses/gpl.html
*
*\author Copyright © 2007 Daniel Swanson <danij@dengine.net>
*\author Copyright © 2007-2008 Daniel Swanson <danij@dengine.net>
*\author Copyright © 2000-2007 Andrew Apted <ajapted@gmail.com>
*\author Copyright © 1998-2000 Colin Reed <cph@moria.org.uk>
*\author Copyright © 1998-2000 Lee Killough <killough@rsn.hp.com>
Expand Down Expand Up @@ -42,6 +42,4 @@ struct superblock_s;
// Load all level data for the current level.
void BSP_InitForNodeBuild(editmap_t *map);

// Free all level data.
void FreeMap(void);
#endif
66 changes: 16 additions & 50 deletions doomsday/engine/portable/src/bsp_edge.c
Expand Up @@ -49,21 +49,6 @@

// TYPES -------------------------------------------------------------------

// An edge tip is where an edge meets a vertex.
typedef struct edgetip_s {
// Link in list. List is kept in ANTI-clockwise order.
struct edgetip_s *next;
struct edgetip_s *prev;

// Angle that line makes at vertex (degrees).
angle_g angle;

// Segs on each side of the edge. Left is the side of increasing
// angles, right is the side of decreasing angles. Either can be
// NULL for one sided edges.
struct hedge_s *hEdges[2];
} edgetip_t;

// EXTERNAL FUNCTION PROTOTYPES --------------------------------------------

// PUBLIC FUNCTION PROTOTYPES ----------------------------------------------
Expand All @@ -76,9 +61,6 @@ typedef struct edgetip_s {

// PRIVATE DATA DEFINITIONS ------------------------------------------------

static edgetip_t **hEdgeTips = NULL;
static int numHEdgeTips = 0;

// CODE --------------------------------------------------------------------

static __inline hedge_t *allocHEdge(void)
Expand All @@ -91,24 +73,14 @@ static __inline void freeHEdge(hedge_t *hEdge)
M_Free(hEdge);
}

static edgetip_t *allocEdgeTip(void)
static __inline edgetip_t *allocEdgeTip(void)
{
#define BLKNUM 1024

edgetip_t *edgeTip;

if((numHEdgeTips % BLKNUM) == 0)
{
hEdgeTips = M_Realloc(hEdgeTips, (numHEdgeTips + BLKNUM) *
sizeof(edgetip_t *));
}

hEdgeTips[numHEdgeTips] = edgeTip = M_Calloc(sizeof(edgetip_t));
numHEdgeTips += 1;

return edgeTip;
return M_Calloc(sizeof(edgetip_t));
}

#undef BLKNUM
static __inline void freeEdgeTip(edgetip_t *tip)
{
M_Free(tip);
}

/**
Expand Down Expand Up @@ -177,9 +149,9 @@ hedge_t *HEdge_Create(line_t *line, line_t *sourceLine,
}

/**
* Destroys the given hedge.
* Destroys the given half-edge.
*
* @param hEdge Ptr to the hedge to be destroyed.
* @param hEdge Ptr to the half-edge to be destroyed.
*/
void HEdge_Destroy(hedge_t *hEdge)
{
Expand Down Expand Up @@ -320,6 +292,14 @@ void BSP_CreateVertexEdgeTip(vertex_t *vert, double dx, double dy,
}
}

void BSP_DestroyVertexEdgeTip(edgetip_t *tip)
{
if(tip)
{
freeEdgeTip(tip);
}
}

void BSP_CountEdgeTips(vertex_t *vert, uint *oneSided, uint *twoSided)
{
edgetip_t *tip;
Expand Down Expand Up @@ -380,17 +360,3 @@ sector_t *BSP_VertexCheckOpen(vertex_t *vert, double dX, double dY)
Con_Error("Vertex %d has no tips !", vert->buildData.index);
return NULL;
}

void BSP_FreeEdgeTips(void)
{
int i;

for(i = 0; i < numHEdgeTips; ++i)
M_Free(hEdgeTips[i]);

if(hEdgeTips)
M_Free(hEdgeTips);

hEdgeTips = NULL;
numHEdgeTips = 0;
}
5 changes: 0 additions & 5 deletions doomsday/engine/portable/src/bsp_level.c
Expand Up @@ -432,11 +432,6 @@ void BSP_InitForNodeBuild(editmap_t *map)
}
}

void FreeMap(void)
{
BSP_FreeEdgeTips();
}

static void hardenLinedefs(gamemap_t *dest, editmap_t *src)
{
uint i;
Expand Down
1 change: 0 additions & 1 deletion doomsday/engine/portable/src/bsp_main.c
Expand Up @@ -303,7 +303,6 @@ boolean BSP_Build(gamemap_t *dest, editmap_t *src)
}

// Free temporary storage.
FreeMap();
BSP_ShutdownSuperBlockAllocator();
BSP_ShutdownIntersectionAllocator();

Expand Down
44 changes: 42 additions & 2 deletions doomsday/engine/portable/src/edit_map.c
Expand Up @@ -173,26 +173,61 @@ static boolean C_DECL freeBSPNodeData(binarytree_t *tree, void *data)

static void destroyMap(void)
{
uint i;

memset(map->name, 0, sizeof(map->name));

if(map->vertexes)
{
for(i = 0; i < map->numVertexes; ++i)
{
vertex_t *vtx = map->vertexes[i];
edgetip_t *tip, *n;

tip = vtx->buildData.tipSet;
while(tip)
{
n = tip->next;
BSP_DestroyVertexEdgeTip(tip);
tip = n;
}

M_Free(vtx);
}

M_Free(map->vertexes);
}
map->vertexes = NULL;
map->numVertexes = 0;

if(map->lines)
{
for(i = 0; i < map->numLines; ++i)
{
line_t *line = map->lines[i];
M_Free(line);
}

M_Free(map->lines);
}
map->lines = NULL;
map->numLines = 0;

if(map->sides)
{
for(i = 0; i < map->numSides; ++i)
{
side_t *side = map->sides[i];
M_Free(side);
}

M_Free(map->sides);
}
map->sides = NULL;
map->numSides = 0;

if(map->sectors)
{
uint i;
for(i = 0; i < map->numSectors; ++i)
{
uint j;
Expand All @@ -206,7 +241,10 @@ static void destroyMap(void)
}
M_Free(s->planes);
}

M_Free(s);
}

M_Free(map->sectors);
}
map->sectors = NULL;
Expand All @@ -216,8 +254,8 @@ static void destroyMap(void)
{
BinaryTree_PostOrder(map->rootNode, freeBSPNodeData, NULL);
BinaryTree_Destroy(map->rootNode);
map->rootNode = NULL;
}
map->rootNode = NULL;

if(map->polyobjs)
{
Expand All @@ -226,8 +264,10 @@ static void destroyMap(void)
{
polyobj_t *po = map->polyobjs[i];
M_Free(po->buildData.lines);

M_Free(po);
}

M_Free(map->polyobjs);
}
map->polyobjs = NULL;
Expand Down

0 comments on commit c5ab474

Please sign in to comment.