Skip to content

Commit

Permalink
libdoomsday|Map Data: Added “double” property value type
Browse files Browse the repository at this point in the history
  • Loading branch information
skyjake committed Nov 17, 2016
1 parent 02511bc commit 3bcfa42
Show file tree
Hide file tree
Showing 5 changed files with 122 additions and 154 deletions.
Expand Up @@ -46,13 +46,13 @@ class LIBDOOMSDAY_PUBLIC EntityDatabase
EntityDatabase();

/// @return Total number of entities by definition @a entityDef.
uint entityCount(MapEntityDef const *entityDef);
uint entityCount(MapEntityDef const *entityDef) const;

/**
* Returns @c true iff an entity with definition @a entityDef and
* @a elementIndex is known/present.
*/
bool hasEntity(MapEntityDef const *entityDef, int elementIndex);
bool hasEntity(MapEntityDef const *entityDef, int elementIndex) const;

/**
* Lookup a known entity element property value in the database.
Expand All @@ -62,7 +62,7 @@ class LIBDOOMSDAY_PUBLIC EntityDatabase
*
* @return The found PropertyValue.
*/
PropertyValue const &property(MapEntityPropertyDef const *def, int elementIndex);
PropertyValue const &property(MapEntityPropertyDef const *def, int elementIndex) const;

/**
* Replace/add a value for a known entity element property to the database.
Expand Down
15 changes: 8 additions & 7 deletions doomsday/apps/libdoomsday/include/doomsday/world/entitydef.h
@@ -1,6 +1,6 @@
/** @file entitydef.h World map entity definitions.
*
* @authors Copyright © 2003-2013 Jaakko Keränen <jaakko.keranen@iki.fi>
* @authors Copyright © 2003-2016 Jaakko Keränen <jaakko.keranen@iki.fi>
* @authors Copyright © 2006-2013 Daniel Swanson <danij@dengine.net>
*
* @par License
Expand Down Expand Up @@ -130,12 +130,13 @@ LIBDOOMSDAY_PUBLIC void P_ShutdownMapEntityDefs();
LIBDOOMSDAY_PUBLIC dd_bool P_RegisterMapObj(int identifier, char const *name);
LIBDOOMSDAY_PUBLIC dd_bool P_RegisterMapObjProperty(int entityId, int propertyId,
char const *propertyName, valuetype_t type);
LIBDOOMSDAY_PUBLIC byte P_GetGMOByte(int entityId, int elementIndex, int propertyId);
LIBDOOMSDAY_PUBLIC short P_GetGMOShort(int entityId, int elementIndex, int propertyId);
LIBDOOMSDAY_PUBLIC int P_GetGMOInt(int entityId, int elementIndex, int propertyId);
LIBDOOMSDAY_PUBLIC fixed_t P_GetGMOFixed(int entityId, int elementIndex, int propertyId);
LIBDOOMSDAY_PUBLIC angle_t P_GetGMOAngle(int entityId, int elementIndex, int propertyId);
LIBDOOMSDAY_PUBLIC float P_GetGMOFloat(int entityId, int elementIndex, int propertyId);
LIBDOOMSDAY_PUBLIC byte P_GetGMOByte(int entityId, int elementIndex, int propertyId);
LIBDOOMSDAY_PUBLIC short P_GetGMOShort(int entityId, int elementIndex, int propertyId);
LIBDOOMSDAY_PUBLIC int P_GetGMOInt(int entityId, int elementIndex, int propertyId);
LIBDOOMSDAY_PUBLIC fixed_t P_GetGMOFixed(int entityId, int elementIndex, int propertyId);
LIBDOOMSDAY_PUBLIC angle_t P_GetGMOAngle(int entityId, int elementIndex, int propertyId);
LIBDOOMSDAY_PUBLIC float P_GetGMOFloat(int entityId, int elementIndex, int propertyId);
LIBDOOMSDAY_PUBLIC double P_GetGMODouble(int entityId, int elementIndex, int propertyId);

#ifdef __cplusplus
} // extern "C"
Expand Down
113 changes: 71 additions & 42 deletions doomsday/apps/libdoomsday/include/doomsday/world/propertyvalue.h
Expand Up @@ -38,12 +38,13 @@ class LIBDOOMSDAY_PUBLIC PropertyValue
virtual valuetype_t type() const = 0;
virtual char const* typeName() const = 0;

virtual byte asByte() const = 0;
virtual int16_t asInt16() const = 0;
virtual int32_t asInt32() const = 0;
virtual fixed_t asFixed() const = 0;
virtual angle_t asAngle() const = 0;
virtual float asFloat() const = 0;
virtual byte asByte() const = 0;
virtual int16_t asInt16() const = 0;
virtual int32_t asInt32() const = 0;
virtual fixed_t asFixed() const = 0;
virtual angle_t asAngle() const = 0;
virtual float asFloat() const = 0;
virtual double asDouble() const = 0;
};

class LIBDOOMSDAY_PUBLIC PropertyByteValue : public PropertyValue
Expand All @@ -56,12 +57,13 @@ class LIBDOOMSDAY_PUBLIC PropertyByteValue : public PropertyValue

byte value() const { return value_; }

byte asByte() const { return value_; }
int16_t asInt16() const { return value_; }
int32_t asInt32() const { return value_; }
fixed_t asFixed() const { return value_ << FRACBITS; }
angle_t asAngle() const { return value_; }
float asFloat() const { return value_; }
byte asByte() const { return value_; }
int16_t asInt16() const { return value_; }
int32_t asInt32() const { return value_; }
fixed_t asFixed() const { return value_ << FRACBITS; }
angle_t asAngle() const { return value_; }
float asFloat() const { return value_; }
double asDouble() const { return value_; }

private:
byte value_;
Expand All @@ -77,12 +79,13 @@ class LIBDOOMSDAY_PUBLIC PropertyInt16Value : public PropertyValue

int16_t value() const { return value_; }

byte asByte() const { return byte(value_); }
int16_t asInt16() const { return value_; }
int32_t asInt32() const { return int32_t(value_); }
fixed_t asFixed() const { return fixed_t(value_ << FRACBITS); }
angle_t asAngle() const { return angle_t(value_); }
float asFloat() const { return float(value_); }
byte asByte() const { return byte(value_); }
int16_t asInt16() const { return value_; }
int32_t asInt32() const { return int32_t(value_); }
fixed_t asFixed() const { return fixed_t(value_ << FRACBITS); }
angle_t asAngle() const { return angle_t(value_); }
float asFloat() const { return float(value_); }
double asDouble() const { return double(value_); }

private:
int16_t value_;
Expand All @@ -98,12 +101,13 @@ class LIBDOOMSDAY_PUBLIC PropertyInt32Value : public PropertyValue

int32_t value() const { return value_; }

byte asByte() const { return byte(value_); }
int16_t asInt16() const { return int16_t(value_); }
int32_t asInt32() const { return value_; }
fixed_t asFixed() const { return fixed_t(value_ << FRACBITS); }
angle_t asAngle() const { return angle_t(value_); }
float asFloat() const { return float(value_); }
byte asByte() const { return byte(value_); }
int16_t asInt16() const { return int16_t(value_); }
int32_t asInt32() const { return value_; }
fixed_t asFixed() const { return fixed_t(value_ << FRACBITS); }
angle_t asAngle() const { return angle_t(value_); }
float asFloat() const { return float(value_); }
double asDouble() const { return double(value_); }

private:
int32_t value_;
Expand All @@ -119,12 +123,13 @@ class LIBDOOMSDAY_PUBLIC PropertyFixedValue : public PropertyValue

fixed_t value() const { return value_; }

byte asByte() const { return byte(value_ >> FRACBITS); }
int16_t asInt16() const { return int16_t(value_ >> FRACBITS); }
int32_t asInt32() const { return int32_t(value_ >> FRACBITS); }
fixed_t asFixed() const { return value_; }
angle_t asAngle() const { return angle_t(value_ >> FRACBITS); }
float asFloat() const { return FIX2FLT(value_); }
byte asByte() const { return byte(value_ >> FRACBITS); }
int16_t asInt16() const { return int16_t(value_ >> FRACBITS); }
int32_t asInt32() const { return int32_t(value_ >> FRACBITS); }
fixed_t asFixed() const { return value_; }
angle_t asAngle() const { return angle_t(value_ >> FRACBITS); }
float asFloat() const { return FIX2FLT(value_); }
double asDouble() const { return FIX2FLT(value_); }

private:
fixed_t value_;
Expand All @@ -140,12 +145,13 @@ class LIBDOOMSDAY_PUBLIC PropertyAngleValue : public PropertyValue

angle_t value() const { return value_; }

byte asByte() const { return byte(value_); }
int16_t asInt16() const { return int16_t(value_); }
int32_t asInt32() const { return int32_t(value_); }
fixed_t asFixed() const { return fixed_t(value_ << FRACBITS); }
angle_t asAngle() const { return value_; }
float asFloat() const { return float(value_); }
byte asByte() const { return byte(value_); }
int16_t asInt16() const { return int16_t(value_); }
int32_t asInt32() const { return int32_t(value_); }
fixed_t asFixed() const { return fixed_t(value_ << FRACBITS); }
angle_t asAngle() const { return value_; }
float asFloat() const { return float(value_); }
double asDouble() const { return double(value_); }

private:
angle_t value_;
Expand All @@ -161,17 +167,40 @@ class LIBDOOMSDAY_PUBLIC PropertyFloatValue : public PropertyValue

float value() const { return value_; }

byte asByte() const { return byte(value_); }
int16_t asInt16() const { return int16_t(value_); }
int32_t asInt32() const { return int32_t(value_); }
fixed_t asFixed() const { return FLT2FIX(value_); }
angle_t asAngle() const { return angle_t(value_); }
float asFloat() const { return value_; }
byte asByte() const { return byte(value_); }
int16_t asInt16() const { return int16_t(value_); }
int32_t asInt32() const { return int32_t(value_); }
fixed_t asFixed() const { return FLT2FIX(value_); }
angle_t asAngle() const { return angle_t(value_); }
float asFloat() const { return value_; }
double asDouble() const { return value_; }

private:
float value_;
};

class LIBDOOMSDAY_PUBLIC PropertyDoubleValue : public PropertyValue
{
public:
PropertyDoubleValue(double value) : PropertyValue(), value_(value) {}

valuetype_t type() const { return DDVT_DOUBLE; }
char const *typeName() const { return "double"; }

double value() const { return value_; }

byte asByte() const { return byte(value_); }
int16_t asInt16() const { return int16_t(value_); }
int32_t asInt32() const { return int32_t(value_); }
fixed_t asFixed() const { return FLT2FIX(value_); }
angle_t asAngle() const { return angle_t(value_); }
float asFloat() const { return float(value_); }
double asDouble() const { return value_; }

private:
double value_;
};

/**
* Factory constructor for instantiation of new PropertyValues.
*
Expand Down
6 changes: 3 additions & 3 deletions doomsday/apps/libdoomsday/src/world/entitydatabase.cpp
Expand Up @@ -85,22 +85,22 @@ DENG2_PIMPL(EntityDatabase)
EntityDatabase::EntityDatabase() : d(new Impl(this))
{}

uint EntityDatabase::entityCount(MapEntityDef const *entityDef)
uint EntityDatabase::entityCount(MapEntityDef const *entityDef) const
{
DENG2_ASSERT(entityDef);
Entities *set = d->entities(entityDef->id);
return set->size();
}

bool EntityDatabase::hasEntity(MapEntityDef const *entityDef, int elementIndex)
bool EntityDatabase::hasEntity(MapEntityDef const *entityDef, int elementIndex) const
{
DENG2_ASSERT(entityDef);
Entities *set = d->entities(entityDef->id);
return d->entityByElementIndex(*set, elementIndex, false /*do not create*/) != 0;
}

PropertyValue const &EntityDatabase::property(MapEntityPropertyDef const *def,
int elementIndex)
int elementIndex) const
{
DENG2_ASSERT(def);
Entities *set = d->entities(def->entity->id);
Expand Down

0 comments on commit 3bcfa42

Please sign in to comment.