2020-01-03 20:05:16 +01:00
|
|
|
// Copyright (C) 2002-2012 Nikolaus Gebhardt
|
|
|
|
// This file is part of the "Irrlicht Engine".
|
|
|
|
// For conditions of distribution and use, see copyright notice in irrlicht.h
|
|
|
|
|
|
|
|
#include "CAttributes.h"
|
|
|
|
#include "CAttributeImpl.h"
|
|
|
|
#include "ITexture.h"
|
|
|
|
#include "IVideoDriver.h"
|
|
|
|
|
|
|
|
namespace irr
|
|
|
|
{
|
|
|
|
namespace io
|
|
|
|
{
|
|
|
|
|
|
|
|
CAttributes::CAttributes(video::IVideoDriver* driver)
|
|
|
|
: Driver(driver)
|
|
|
|
{
|
|
|
|
#ifdef _DEBUG
|
|
|
|
setDebugName("CAttributes");
|
|
|
|
#endif
|
|
|
|
|
|
|
|
if (Driver)
|
|
|
|
Driver->grab();
|
|
|
|
}
|
|
|
|
|
|
|
|
CAttributes::~CAttributes()
|
|
|
|
{
|
|
|
|
clear();
|
|
|
|
|
|
|
|
if (Driver)
|
|
|
|
Driver->drop();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//! Removes all attributes
|
|
|
|
void CAttributes::clear()
|
|
|
|
{
|
|
|
|
for (u32 i=0; i<Attributes.size(); ++i)
|
|
|
|
Attributes[i]->drop();
|
|
|
|
|
|
|
|
Attributes.clear();
|
|
|
|
}
|
|
|
|
|
|
|
|
//! Returns attribute index from name, -1 if not found
|
|
|
|
s32 CAttributes::findAttribute(const c8* attributeName) const
|
|
|
|
{
|
|
|
|
for (u32 i=0; i<Attributes.size(); ++i)
|
|
|
|
if (Attributes[i]->Name == attributeName)
|
|
|
|
return i;
|
|
|
|
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
IAttribute* CAttributes::getAttributeP(const c8* attributeName) const
|
|
|
|
{
|
|
|
|
for (u32 i=0; i<Attributes.size(); ++i)
|
|
|
|
if (Attributes[i]->Name == attributeName)
|
|
|
|
return Attributes[i];
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
//! Sets a attribute as boolean value
|
|
|
|
void CAttributes::setAttribute(const c8* attributeName, bool value)
|
|
|
|
{
|
|
|
|
IAttribute* att = getAttributeP(attributeName);
|
|
|
|
if (att)
|
|
|
|
att->setBool(value);
|
|
|
|
else
|
|
|
|
{
|
|
|
|
Attributes.push_back(new CBoolAttribute(attributeName, value));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//! Gets a attribute as boolean value
|
|
|
|
//! \param attributeName: Name of the attribute to get.
|
|
|
|
//! \return Returns value of the attribute previously set by setAttribute() as bool
|
|
|
|
//! or 0 if attribute is not set.
|
|
|
|
bool CAttributes::getAttributeAsBool(const c8* attributeName, bool defaultNotFound) const
|
|
|
|
{
|
|
|
|
const IAttribute* att = getAttributeP(attributeName);
|
|
|
|
if (att)
|
|
|
|
return att->getBool();
|
|
|
|
else
|
|
|
|
return defaultNotFound;
|
|
|
|
}
|
|
|
|
|
|
|
|
//! Sets a attribute as integer value
|
|
|
|
void CAttributes::setAttribute(const c8* attributeName, s32 value)
|
|
|
|
{
|
|
|
|
IAttribute* att = getAttributeP(attributeName);
|
|
|
|
if (att)
|
|
|
|
att->setInt(value);
|
|
|
|
else
|
|
|
|
{
|
|
|
|
Attributes.push_back(new CIntAttribute(attributeName, value));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//! Gets a attribute as integer value
|
|
|
|
//! \param attributeName: Name of the attribute to get.
|
|
|
|
//! \return Returns value of the attribute previously set by setAttribute() as integer
|
|
|
|
//! or 0 if attribute is not set.
|
|
|
|
s32 CAttributes::getAttributeAsInt(const c8* attributeName, irr::s32 defaultNotFound) const
|
|
|
|
{
|
|
|
|
const IAttribute* att = getAttributeP(attributeName);
|
|
|
|
if (att)
|
|
|
|
return att->getInt();
|
|
|
|
else
|
|
|
|
return defaultNotFound;
|
|
|
|
}
|
|
|
|
|
|
|
|
//! Sets a attribute as float value
|
|
|
|
void CAttributes::setAttribute(const c8* attributeName, f32 value)
|
|
|
|
{
|
|
|
|
IAttribute* att = getAttributeP(attributeName);
|
|
|
|
if (att)
|
|
|
|
att->setFloat(value);
|
|
|
|
else
|
|
|
|
Attributes.push_back(new CFloatAttribute(attributeName, value));
|
|
|
|
}
|
|
|
|
|
|
|
|
//! Gets a attribute as integer value
|
|
|
|
//! \param attributeName: Name of the attribute to get.
|
|
|
|
//! \return Returns value of the attribute previously set by setAttribute() as float value
|
|
|
|
//! or 0 if attribute is not set.
|
|
|
|
f32 CAttributes::getAttributeAsFloat(const c8* attributeName, irr::f32 defaultNotFound) const
|
|
|
|
{
|
|
|
|
const IAttribute* att = getAttributeP(attributeName);
|
|
|
|
if (att)
|
|
|
|
return att->getFloat();
|
|
|
|
|
|
|
|
return defaultNotFound;
|
|
|
|
}
|
|
|
|
|
2021-12-29 23:00:56 +01:00
|
|
|
//! Returns amount of string attributes set in this scene manager.
|
|
|
|
u32 CAttributes::getAttributeCount() const
|
2020-01-03 20:05:16 +01:00
|
|
|
{
|
2021-12-29 23:00:56 +01:00
|
|
|
return Attributes.size();
|
2020-01-03 20:05:16 +01:00
|
|
|
}
|
|
|
|
|
2021-12-29 23:00:56 +01:00
|
|
|
//! Returns string attribute name by index.
|
|
|
|
//! \param index: Index value, must be between 0 and getStringAttributeCount()-1.
|
|
|
|
const c8* CAttributes::getAttributeName(s32 index) const
|
2020-01-03 20:05:16 +01:00
|
|
|
{
|
2021-12-29 23:00:56 +01:00
|
|
|
if ((u32)index >= Attributes.size())
|
|
|
|
return 0;
|
2020-01-03 20:05:16 +01:00
|
|
|
|
2021-12-29 23:00:56 +01:00
|
|
|
return Attributes[index]->Name.c_str();
|
2020-01-03 20:05:16 +01:00
|
|
|
}
|
|
|
|
|
2021-12-29 23:00:56 +01:00
|
|
|
//! Returns the type of an attribute
|
|
|
|
E_ATTRIBUTE_TYPE CAttributes::getAttributeType(const c8* attributeName) const
|
2020-01-03 20:05:16 +01:00
|
|
|
{
|
2021-12-29 23:00:56 +01:00
|
|
|
E_ATTRIBUTE_TYPE ret = EAT_UNKNOWN;
|
|
|
|
|
2020-01-03 20:05:16 +01:00
|
|
|
const IAttribute* att = getAttributeP(attributeName);
|
|
|
|
if (att)
|
2021-12-29 23:00:56 +01:00
|
|
|
ret = att->getType();
|
2020-01-03 20:05:16 +01:00
|
|
|
|
2021-12-29 23:00:56 +01:00
|
|
|
return ret;
|
2020-01-03 20:05:16 +01:00
|
|
|
}
|
|
|
|
|
2021-12-29 23:00:56 +01:00
|
|
|
//! Returns attribute type by index.
|
|
|
|
//! \param index: Index value, must be between 0 and getAttributeCount()-1.
|
|
|
|
E_ATTRIBUTE_TYPE CAttributes::getAttributeType(s32 index) const
|
2020-01-03 20:05:16 +01:00
|
|
|
{
|
2021-12-29 23:00:56 +01:00
|
|
|
if ((u32)index >= Attributes.size())
|
|
|
|
return EAT_UNKNOWN;
|
2020-01-03 20:05:16 +01:00
|
|
|
|
2021-12-29 23:00:56 +01:00
|
|
|
return Attributes[index]->getType();
|
2020-01-03 20:05:16 +01:00
|
|
|
}
|
|
|
|
|
2021-12-29 23:00:56 +01:00
|
|
|
//! Returns the type of an attribute
|
|
|
|
const wchar_t* CAttributes::getAttributeTypeString(const c8* attributeName, const wchar_t* defaultNotFound) const
|
2020-01-03 20:05:16 +01:00
|
|
|
{
|
|
|
|
const IAttribute* att = getAttributeP(attributeName);
|
|
|
|
if (att)
|
2021-12-29 23:00:56 +01:00
|
|
|
return att->getTypeString();
|
2020-01-03 20:05:16 +01:00
|
|
|
else
|
|
|
|
return defaultNotFound;
|
|
|
|
}
|
|
|
|
|
2021-12-29 23:00:56 +01:00
|
|
|
//! Returns attribute type string by index.
|
|
|
|
//! \param index: Index value, must be between 0 and getAttributeCount()-1.
|
|
|
|
const wchar_t* CAttributes::getAttributeTypeString(s32 index, const wchar_t* defaultNotFound) const
|
2020-01-03 20:05:16 +01:00
|
|
|
{
|
2021-12-29 23:00:56 +01:00
|
|
|
if ((u32)index >= Attributes.size())
|
2020-01-03 20:05:16 +01:00
|
|
|
return defaultNotFound;
|
|
|
|
|
2021-12-29 23:00:56 +01:00
|
|
|
return Attributes[index]->getTypeString();
|
2020-01-03 20:05:16 +01:00
|
|
|
}
|
|
|
|
|
2021-12-29 23:00:56 +01:00
|
|
|
//! Gets an attribute as integer value
|
|
|
|
//! \param index: Index value, must be between 0 and getAttributeCount()-1.
|
|
|
|
s32 CAttributes::getAttributeAsInt(s32 index) const
|
2020-01-03 20:05:16 +01:00
|
|
|
{
|
2021-12-29 23:00:56 +01:00
|
|
|
if ((u32)index < Attributes.size())
|
|
|
|
return Attributes[index]->getInt();
|
2020-01-03 20:05:16 +01:00
|
|
|
else
|
2021-12-29 23:00:56 +01:00
|
|
|
return 0;
|
2020-01-03 20:05:16 +01:00
|
|
|
}
|
|
|
|
|
2021-12-29 23:00:56 +01:00
|
|
|
//! Gets an attribute as float value
|
|
|
|
//! \param index: Index value, must be between 0 and getAttributeCount()-1.
|
|
|
|
f32 CAttributes::getAttributeAsFloat(s32 index) const
|
2020-01-03 20:05:16 +01:00
|
|
|
{
|
2021-12-29 23:00:56 +01:00
|
|
|
if ((u32)index < Attributes.size())
|
|
|
|
return Attributes[index]->getFloat();
|
2020-01-03 20:05:16 +01:00
|
|
|
else
|
2021-12-29 23:00:56 +01:00
|
|
|
return 0.f;
|
2020-01-03 20:05:16 +01:00
|
|
|
}
|
|
|
|
|
2021-12-29 23:00:56 +01:00
|
|
|
//! Gets an attribute as boolean value
|
|
|
|
//! \param index: Index value, must be between 0 and getAttributeCount()-1.
|
|
|
|
bool CAttributes::getAttributeAsBool(s32 index) const
|
2020-01-03 20:05:16 +01:00
|
|
|
{
|
2021-12-29 23:00:56 +01:00
|
|
|
bool ret = false;
|
|
|
|
|
|
|
|
if ((u32)index < Attributes.size())
|
|
|
|
ret = Attributes[index]->getBool();
|
|
|
|
|
|
|
|
return ret;
|
2020-01-03 20:05:16 +01:00
|
|
|
}
|
|
|
|
|
2021-12-29 23:00:56 +01:00
|
|
|
//! Adds an attribute as integer
|
|
|
|
void CAttributes::addInt(const c8* attributeName, s32 value)
|
2020-01-03 20:05:16 +01:00
|
|
|
{
|
2021-12-29 23:00:56 +01:00
|
|
|
Attributes.push_back(new CIntAttribute(attributeName, value));
|
2020-01-03 20:05:16 +01:00
|
|
|
}
|
|
|
|
|
2021-12-29 23:00:56 +01:00
|
|
|
//! Adds an attribute as float
|
|
|
|
void CAttributes::addFloat(const c8* attributeName, f32 value)
|
2020-01-03 20:05:16 +01:00
|
|
|
{
|
2021-12-29 23:00:56 +01:00
|
|
|
Attributes.push_back(new CFloatAttribute(attributeName, value));
|
2020-01-03 20:05:16 +01:00
|
|
|
}
|
|
|
|
|
2021-12-29 23:00:56 +01:00
|
|
|
//! Adds an attribute as bool
|
|
|
|
void CAttributes::addBool(const c8* attributeName, bool value)
|
2020-01-03 20:05:16 +01:00
|
|
|
{
|
2021-12-29 23:00:56 +01:00
|
|
|
Attributes.push_back(new CBoolAttribute(attributeName, value));
|
2020-01-03 20:05:16 +01:00
|
|
|
}
|
|
|
|
|
2021-12-29 23:00:56 +01:00
|
|
|
//! Returns if an attribute with a name exists
|
|
|
|
bool CAttributes::existsAttribute(const c8* attributeName) const
|
2020-01-03 20:05:16 +01:00
|
|
|
{
|
2021-12-29 23:00:56 +01:00
|
|
|
return getAttributeP(attributeName) != 0;
|
2020-01-03 20:05:16 +01:00
|
|
|
}
|
|
|
|
|
2021-12-29 23:00:56 +01:00
|
|
|
//! Sets an attribute as boolean value
|
|
|
|
void CAttributes::setAttribute(s32 index, bool value)
|
2020-01-03 20:05:16 +01:00
|
|
|
{
|
2021-12-29 23:00:56 +01:00
|
|
|
if ((u32)index < Attributes.size())
|
|
|
|
Attributes[index]->setBool(value);
|
2020-01-03 20:05:16 +01:00
|
|
|
}
|
|
|
|
|
2021-12-29 23:00:56 +01:00
|
|
|
//! Sets an attribute as integer value
|
|
|
|
void CAttributes::setAttribute(s32 index, s32 value)
|
2020-01-03 20:05:16 +01:00
|
|
|
{
|
2021-12-29 23:00:56 +01:00
|
|
|
if ((u32)index < Attributes.size())
|
|
|
|
Attributes[index]->setInt(value);
|
2020-01-03 20:05:16 +01:00
|
|
|
}
|
|
|
|
|
2021-12-29 23:00:56 +01:00
|
|
|
//! Sets a attribute as float value
|
|
|
|
void CAttributes::setAttribute(s32 index, f32 value)
|
2020-01-03 20:05:16 +01:00
|
|
|
{
|
|
|
|
if ((u32)index < Attributes.size())
|
2021-12-29 23:00:56 +01:00
|
|
|
Attributes[index]->setFloat(value);
|
2020-01-03 20:05:16 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
} // end namespace io
|
|
|
|
} // end namespace irr
|
|
|
|
|