Skip to content

Commit

Permalink
Refactor|DEH Reader: Use de::Uri's C++ API
Browse files Browse the repository at this point in the history
  • Loading branch information
danij-deng committed Jun 24, 2014
1 parent 43dbdaa commit 5a6aeb1
Show file tree
Hide file tree
Showing 6 changed files with 45 additions and 61 deletions.
24 changes: 9 additions & 15 deletions doomsday/plugins/dehread/include/dehread.h
@@ -1,9 +1,9 @@
/**
* @file dehread.h
* DeHackEd patch reader plugin for Doomsday Engine. @ingroup dehread
/** @file dehread.h DeHackEd patch reader plugin for Doomsday Engine.
*
* @ingroup dehread
*
* @author Copyright &copy; 2003-2013 Jaakko Keränen <jaakko.keranen@iki.fi>
* @author Copyright &copy; 2006-2013 Daniel Swanson <danij@dengine.net>
* @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
Expand All @@ -20,11 +20,6 @@
* 02110-1301 USA</small>
*/

/**
* @defgroup dehread
* DeHackEd patch reader plugin.
*/

#ifndef LIBDEHREAD_DEHREAD_H
#define LIBDEHREAD_DEHREAD_H

Expand All @@ -42,13 +37,13 @@ struct font_s;
#include <de/libcore.h>
#include <de/types.h>

DENG_EXTERN_C void DP_Initialize(void);
DENG_EXTERN_C void DP_Initialize();

// Internal:
extern ded_t* ded; // @todo Remove me.
extern ded_t *ded; // @todo Remove me.

const int NUMSPRITES = 138;
const int NUMSTATES = 968;
int const NUMSPRITES = 138;
int const NUMSTATES = 968;
extern ded_sprid_t origSpriteNames[NUMSPRITES];
extern ded_funcid_t origActionNames[NUMSTATES];

Expand All @@ -57,7 +52,6 @@ DENG_USING_API(Con);
DENG_USING_API(Def);
DENG_USING_API(F);
DENG_USING_API(Plug);
DENG_USING_API(Uri);
DENG_USING_API(W);

#endif // LIBDEHREAD_DEHREAD_H
11 changes: 5 additions & 6 deletions doomsday/plugins/dehread/include/dehreader.h
@@ -1,11 +1,10 @@
/**
* @file dehreader.h
* DeHackEd patch parser. @ingroup dehreader
/** @file dehreader.h DeHackEd patch parser.
* @ingroup dehreader
*
* Parses DeHackEd patches and updates the engine's definition databases.
*
* @author Copyright &copy; 2013 Daniel Swanson <danij@dengine.net>
* @author Copyright &copy; 2012-2013 Jaakko Keränen <jaakko.keranen@iki.fi>
* @authors Copyright © 2013-2014 Daniel Swanson <danij@dengine.net>
* @authors Copyright © 2012-2014 Jaakko Keränen <jaakko.keranen@iki.fi>
*
* @par License
* GPL: http://www.gnu.org/licenses/gpl.html
Expand Down Expand Up @@ -50,6 +49,6 @@ Q_DECLARE_OPERATORS_FOR_FLAGS(DehReaderFlags)
* @param patch DeHackEd patch to parse.
* @param flags @ref DehReaderFlags
*/
void readDehPatch(const de::Block& patch, DehReaderFlags flags = 0);
void readDehPatch(de::Block const &patch, DehReaderFlags flags = 0);

#endif // LIBDEHREAD_DEHREADER_H
18 changes: 9 additions & 9 deletions doomsday/plugins/dehread/include/dehreader_util.h
@@ -1,11 +1,11 @@
/**
* @file dehreader_util.h
* DeHackEd patch parser. @ingroup dehread
/** @file dehreader_util.h DeHackEd patch parser.
*
* @ingroup dehread
*
* Miscellaneous utility routines.
*
* @author Copyright &copy; 2003-2013 Jaakko Keränen <jaakko.keranen@iki.fi>
* @author Copyright &copy; 2006-2013 Daniel Swanson <danij@dengine.net>
* @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
Expand All @@ -30,11 +30,11 @@
#include "dehreader.h"

/// @return Newly composed map URI, must be free'd with Uri_Delete().
Uri* composeMapUri(int episode, int map);
de::Uri composeMapUri(int episode, int map);

int mapInfoDefForUri(const Uri& uri, ded_mapinfo_t** def = NULL);
int mapInfoDefForUri(de::Uri const &uri, ded_mapinfo_t **def = 0);

int valueDefForPath(const QString& id, ded_value_t** def = NULL);
int valueDefForPath(de::String const &id, ded_value_t **def = 0);

/**
* Tokenize a @a string, splitting it into at most @a max tokens.
Expand All @@ -54,6 +54,6 @@ int valueDefForPath(const QString& id, ded_value_t** def = NULL);
*
* @todo Should this be incorporated into de::String ?
*/
QStringList splitMax(const QString& string, QChar sep, int max = -1);
QStringList splitMax(QString const &string, QChar sep, int max = -1);

#endif // LIBDEHREAD_DEHREADER_UTIL_H
4 changes: 1 addition & 3 deletions doomsday/plugins/dehread/src/dehread.cpp
Expand Up @@ -2,7 +2,7 @@
* @ingroup dehread
*
* @authors Copyright © 2013-2014 Daniel Swanson <danij@dengine.net>
* @authors Copyright © 2012-2013 Jaakko Keränen <jaakko.keranen@iki.fi>
* @authors Copyright © 2012-2014 Jaakko Keränen <jaakko.keranen@iki.fi>
*
* @par License
* GPL: http://www.gnu.org/licenses/gpl.html
Expand Down Expand Up @@ -174,14 +174,12 @@ DENG_DECLARE_API(Def);
DENG_DECLARE_API(F);
DENG_DECLARE_API(Plug);
DENG_DECLARE_API(W);
DENG_DECLARE_API(Uri);

DENG_API_EXCHANGE(
DENG_GET_API(DE_API_BASE, Base);
DENG_GET_API(DE_API_CONSOLE, Con);
DENG_GET_API(DE_API_DEFINITIONS, Def);
DENG_GET_API(DE_API_FILE_SYSTEM, F);
DENG_GET_API(DE_API_PLUGIN, Plug);
DENG_GET_API(DE_API_URI, Uri);
DENG_GET_API(DE_API_WAD, W);
)
11 changes: 4 additions & 7 deletions doomsday/plugins/dehread/src/dehreader.cpp
Expand Up @@ -1446,23 +1446,20 @@ class DehReader
float parTime = float(String(args.at(arg++)).toInt(0, 10, String::AllowSuffix));

// Apply.
uri_s *uri = composeMapUri(episode, map);
AutoStr *path = Uri_ToString(uri);

de::Uri const uri = composeMapUri(episode, map);
ded_mapinfo_t *def;
int idx = mapInfoDefForUri(*uri, &def);
int idx = mapInfoDefForUri(uri, &def);
if(idx >= 0)
{
def->parTime = parTime;
LOG_DEBUG("MapInfo #%i \"%s\" parTime => %d")
<< idx << Str_Text(path) << def->parTime;
<< idx << uri << def->parTime;
}
else
{
LOG_WARNING("Failed locating MapInfo for \"%s\" (episode:%i, map:%i), ignoring.")
<< Str_Text(path) << episode << map;
<< uri << episode << map;
}
Uri_Delete(uri);
}
}
catch(SyntaxError const &er)
Expand Down
38 changes: 17 additions & 21 deletions doomsday/plugins/dehread/src/dehreader_util.cpp
@@ -1,9 +1,7 @@
/**
* @file dehreader_util.cpp
* Miscellaneous utility routines. @ingroup dehread
/** @file dehreader_util.cpp Miscellaneous utility routines.
*
* @author Copyright &copy; 2003-2013 Jaakko Keränen <jaakko.keranen@iki.fi>
* @author Copyright &copy; 2006-2013 Daniel Swanson <danij@dengine.net>
* @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
Expand All @@ -20,32 +18,30 @@
* 02110-1301 USA</small>
*/

#include "dehreader.h"
#include <QString>
#include <QStringList>
#include "dehreader_util.h"
#include <de/Block>

Uri* composeMapUri(int episode, int map)
using namespace de;

de::Uri composeMapUri(int episode, int map)
{
if(episode > 0) // ExMy format.
{
de::Block pathUtf8 = QString("E%1M%2").arg(episode).arg(map).toUtf8();
return Uri_NewWithPath2(pathUtf8.constData(), RC_NULL);
return de::Uri(String("E%1M%2").arg(episode).arg(map), RC_NULL);
}
else // MAPxx format.
{
de::Block pathUtf8 = QString("MAP%1").arg(map % 100, 2, 10, QChar('0')).toUtf8();
return Uri_NewWithPath2(pathUtf8.constData(), RC_NULL);
return de::Uri(String("MAP%1").arg(map % 100, 2, 10, QChar('0')), RC_NULL);
}
}

int mapInfoDefForUri(const Uri& uri, ded_mapinfo_t** def)
int mapInfoDefForUri(de::Uri const &uri, ded_mapinfo_t **def)
{
if(!Str_IsEmpty(Uri_Path(&uri)))
if(!uri.path().isEmpty())
for(int i = ded->mapInfo.size() - 1; i >= 0; i--)
{
ded_mapinfo_t& info = ded->mapInfo[i];
if(info.uri && Uri_Equality((uri_s *)info.uri, &uri))
ded_mapinfo_t &info = ded->mapInfo[i];
if(info.uri && *info.uri == uri)
{
if(def) *def = &info;
return i;
Expand All @@ -54,14 +50,14 @@ int mapInfoDefForUri(const Uri& uri, ded_mapinfo_t** def)
return -1; // Not found.
}

int valueDefForPath(const QString& id, ded_value_t** def)
int valueDefForPath(String const &id, ded_value_t **def)
{
if(!id.isEmpty())
{
de::Block idUtf8 = id.toUtf8();
Block idUtf8 = id.toUtf8();
for(int i = ded->values.size() - 1; i >= 0; i--)
{
ded_value_t& value = ded->values[i];
ded_value_t &value = ded->values[i];
if(!qstricmp(value.id, idUtf8.constData()))
{
if(def) *def = &value;
Expand All @@ -73,7 +69,7 @@ int valueDefForPath(const QString& id, ded_value_t** def)
}

/// @todo Reimplement with a regex?
QStringList splitMax(const QString& str, QChar sep, int max)
QStringList splitMax(QString const &str, QChar sep, int max)
{
if(max < 0)
{
Expand Down

0 comments on commit 5a6aeb1

Please sign in to comment.