Skip to content

Commit

Permalink
Refactor|libdoomsday: Added dedarray.h for DED array management
Browse files Browse the repository at this point in the history
  • Loading branch information
skyjake committed May 11, 2014
1 parent bad00cc commit 9aea6ac
Show file tree
Hide file tree
Showing 7 changed files with 258 additions and 194 deletions.
13 changes: 4 additions & 9 deletions doomsday/client/src/def_main.cpp
Expand Up @@ -145,23 +145,19 @@ void Def_Init(void)
stateLights = 0;
DED_ZCount(&countStateLights);

DED_Init(&defs);
defs.clear();
}

void Def_Destroy(void)
{
int i;

// To make sure...
DED_Clear(&defs);
DED_Init(&defs);
defs.clear();

// Destroy the databases.
DED_DelArray((void**) &sprNames, &countSprNames);
DED_DelArray((void**) &states, &countStates);
DED_DelArray((void**) &mobjInfo, &countMobjInfo);

for(i = 0; i < countSounds.num; ++i)
for(int i = 0; i < countSounds.num; ++i)
{
Str_Free(&sounds[i].external);
}
Expand Down Expand Up @@ -1188,8 +1184,7 @@ void Def_Read()
firstDED = true;

// Now we can clear all existing definitions and re-init.
DED_Clear(&defs);
DED_Init(&defs);
defs.clear();

// Generate definitions.
generateMaterialDefs();
Expand Down
24 changes: 6 additions & 18 deletions doomsday/libdoomsday/include/doomsday/defs/ded.h
Expand Up @@ -52,7 +52,6 @@ struct LIBDOOMSDAY_PUBLIC ded_s {
ded_count_t sprites;
ded_count_t lights;
ded_count_t materials;
//ded_count_t models;
ded_count_t skies;
ded_count_t sounds;
ded_count_t music;
Expand Down Expand Up @@ -174,6 +173,8 @@ struct LIBDOOMSDAY_PUBLIC ded_s {
de::zap(count);
}

void clear();

ded_flag_t *getFlag(char const *flag) const;

int evalFlags2(char const *ptr) const;
Expand Down Expand Up @@ -218,6 +219,9 @@ struct LIBDOOMSDAY_PUBLIC ded_s {
ded_compositefont_t* findCompositeFontDef(de::Uri const& uri) const;

ded_compositefont_t* getCompositeFont(char const* uriCString) const;

protected:
void release();
};

typedef ded_s ded_t;
Expand All @@ -226,9 +230,7 @@ typedef ded_s ded_t;
extern "C" {
#endif

// Routines for managing DED files.
void DED_Init(ded_t* ded);
void DED_Clear(ded_t* ded);
// Routines for managing DED files:

int DED_AddFlag(ded_t* ded, char const* name, int value);
int DED_AddMobj(ded_t* ded, char const* idStr);
Expand Down Expand Up @@ -283,20 +285,6 @@ void DED_RemoveSectorType(ded_t* ded, int index);
void DED_RemoveLineType(ded_t* ded, int index);
void DED_RemoveCompositeFont(ded_t* ded, int index);

/**
* @return Pointer to the new block of memory.
*/
void* DED_NewEntries(void** ptr, ded_count_t* cnt, size_t elemSize, int count);

/**
* @return Pointer to the new block of memory.
*/
void* DED_NewEntry(void** ptr, ded_count_t* cnt, size_t elemSize);

void DED_DelEntry(int index, void** ptr, ded_count_t* cnt, size_t elemSize);
void DED_DelArray(void** ptr, ded_count_t* cnt);
void DED_ZCount(ded_count_t* c);

#ifdef __cplusplus
} // extern "C"
#endif
Expand Down
58 changes: 58 additions & 0 deletions doomsday/libdoomsday/include/doomsday/defs/dedarray.h
@@ -0,0 +1,58 @@
/** @file defs/dedarray.h Definition struct (POD) array.
*
* @authors Copyright © 2003-2014 Jaakko Keränen <jaakko.keranen@iki.fi>
* @authors Copyright © 2006-2014 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, see:
* http://www.gnu.org/licenses</small>
*/

#ifndef LIBDOOMSDAY_DEFINITION_ARRAY_H
#define LIBDOOMSDAY_DEFINITION_ARRAY_H

#include "../libdoomsday.h"
#include <de/Vector>

struct ded_count_s
{
int num;
int max;
};

typedef struct ded_count_s ded_count_t;

#ifdef __cplusplus
extern "C" {
#endif

/**
* @return Pointer to the new block of memory.
*/
LIBDOOMSDAY_PUBLIC void *DED_NewEntries(void** ptr, ded_count_t* cnt, size_t elemSize, int count);

/**
* @return Pointer to the new block of memory.
*/
LIBDOOMSDAY_PUBLIC void *DED_NewEntry(void** ptr, ded_count_t* cnt, size_t elemSize);

LIBDOOMSDAY_PUBLIC void DED_DelEntry(int index, void** ptr, ded_count_t* cnt, size_t elemSize);

LIBDOOMSDAY_PUBLIC void DED_DelArray(void** ptr, ded_count_t* cnt);

LIBDOOMSDAY_PUBLIC void DED_ZCount(ded_count_t* c);

#ifdef __cplusplus
} // extern "C"
#endif

#endif // LIBDOOMSDAY_DEFINITION_ARRAY_H
6 changes: 1 addition & 5 deletions doomsday/libdoomsday/include/doomsday/defs/dedtypes.h
Expand Up @@ -27,6 +27,7 @@

#include "def_share.h"
#include "api_gl.h"
#include "dedarray.h"

#define DED_SPRITEID_LEN 4
#define DED_STRINGID_LEN 31
Expand All @@ -48,11 +49,6 @@ typedef char ded_func_t[DED_FUNC_LEN + 1];
typedef int ded_flags_t;
typedef char* ded_anystring_t;

typedef struct ded_count_s {
int num;
int max;
} ded_count_t;

// Embedded sound information.
typedef struct ded_embsound_s {
ded_string_t name;
Expand Down
2 changes: 2 additions & 0 deletions doomsday/libdoomsday/libdoomsday.pro
Expand Up @@ -65,6 +65,7 @@ HEADERS += \
include/doomsday/console/knownword.h \
include/doomsday/console/var.h \
include/doomsday/defs/ded.h \
include/doomsday/defs/dedarray.h \
include/doomsday/defs/dedfile.h \
include/doomsday/defs/dedparser.h \
include/doomsday/defs/dedtypes.h \
Expand Down Expand Up @@ -99,6 +100,7 @@ SOURCES += \
src/console/knownword.cpp \
src/console/var.cpp \
src/defs/ded.cpp \
src/defs/dedarray.cpp \
src/defs/dedfile.cpp \
src/defs/dedparser.cpp \
src/dualstring.cpp \
Expand Down

0 comments on commit 9aea6ac

Please sign in to comment.