Skip to content

Commit

Permalink
API: Def_Get() now returns the index of a found text definition
Browse files Browse the repository at this point in the history
If the type argument specified to Def_Get() is DD_DEF_TEXT and a
definition is found for the specified identifier - the index of the
definition is returned. If no definition is found then the value -1
will be returned.
  • Loading branch information
danij-deng committed Sep 4, 2012
1 parent 22033a7 commit 798a070
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 10 deletions.
18 changes: 13 additions & 5 deletions doomsday/engine/portable/src/def_main.c
Expand Up @@ -839,7 +839,7 @@ int Def_GetIntValue(char* val, int* returned_val)
char* data;

// First look for a DED Value
if(Def_Get(DD_DEF_VALUE, val, &data))
if(Def_Get(DD_DEF_VALUE, val, &data) >= 0)
{
*returned_val = strtol(data, 0, 0);
return true;
Expand Down Expand Up @@ -1819,10 +1819,18 @@ int Def_Get(int type, const char* id, void* out)
return -1;

case DD_DEF_VALUE: {
ded_value_t* value = Def_GetValueById(id);
if(!value) return false;
if(out) *(char**) out = value->text;
return true; }
int idx = -1; // Not found.
if(id && id[0])
{
// Read backwards to allow patching.
for(idx = defs.count.values.num - 1; idx >= 0; idx--)
{
if(!stricmp(defs.values[idx].id, id))
break;
}
}
if(out) *(char**) out = (idx >= 0? defs.values[idx].text : 0);
return idx; }

case DD_DEF_FINALE: { // Find InFine script by ID.
finalescript_t* fin = (finalescript_t*) out;
Expand Down
4 changes: 2 additions & 2 deletions doomsday/plugins/common/src/g_defs.c
Expand Up @@ -69,7 +69,7 @@ int GetDefInt(char* def, int* returnVal)
int val;

// Get the value.
if(!Def_Get(DD_DEF_VALUE, def, &data))
if(Def_Get(DD_DEF_VALUE, def, &data) < 0)
return 0; // No such value...

// Convert to integer.
Expand All @@ -85,7 +85,7 @@ void GetDefState(char* def, int* val)
char* data;

// Get the value.
if(!Def_Get(DD_DEF_VALUE, def, &data))
if(Def_Get(DD_DEF_VALUE, def, &data) < 0)
return;

// Get the state number.
Expand Down
2 changes: 1 addition & 1 deletion doomsday/plugins/common/src/hu_stuff.cpp
Expand Up @@ -1082,7 +1082,7 @@ const char* Hu_FindPatchReplacementString(patchid_t patchId, int flags)

valueStr = Str_Appendf(AutoStr_New(), "Patch Replacement|%s", Str_Text(patchPath));
result = Def_Get(DD_DEF_VALUE, Str_Text(valueStr), (void*)&replacement);
if(result == 0) return NULL; // Not found.
if(result < 0) return NULL; // Not found.

if(flags & (PRF_NO_IWAD|PRF_NO_PWAD))
{
Expand Down
2 changes: 1 addition & 1 deletion doomsday/plugins/jdoom/src/d_items.c
Expand Up @@ -196,7 +196,7 @@ void P_InitWeaponInfo(void)
{
//// \todo Only allows for one type of ammo per weapon.
sprintf(buf, WPINF "%i|Type", i);
if(Def_Get(DD_DEF_VALUE, buf, &data))
if(Def_Get(DD_DEF_VALUE, buf, &data) >= 0)
{
memset(weaponInfo[i][pclass].mode[0].ammoType, 0,
sizeof(int) * NUM_AMMO_TYPES);
Expand Down
2 changes: 1 addition & 1 deletion doomsday/plugins/jdoom64/src/d_items.c
Expand Up @@ -211,7 +211,7 @@ void P_InitWeaponInfo(void)
{
//// \todo Only allows for one type of ammo per weapon.
sprintf(buf, WPINF "%i|Type", i);
if(Def_Get(DD_DEF_VALUE, buf, &data))
if(Def_Get(DD_DEF_VALUE, buf, &data) >= 0)
{
memset(weaponInfo[i][pclass].mode[0].ammoType, 0,
sizeof(int) * NUM_AMMO_TYPES);
Expand Down

0 comments on commit 798a070

Please sign in to comment.