# Updates to health/stamina bar rendering code, and optimizations in CJSObject.
(Replaced CStrW parameters with const CStrW& in CJSObject and CSynchedJSObject). This was SVN commit r4136.
This commit is contained in:
parent
624cbebeb1
commit
e1f06f4667
@ -33,14 +33,14 @@ public:
|
||||
typedef void (IJSObject::*SetFn)( JSContext* cx, jsval value );
|
||||
|
||||
// Return a pointer to a property, if it exists
|
||||
virtual IJSProperty* HasProperty( CStrW PropertyName ) = 0;
|
||||
virtual IJSProperty* HasProperty( const CStrW& PropertyName ) = 0;
|
||||
|
||||
// Retrieve the value of a property (returning false if that property is not defined)
|
||||
virtual bool GetProperty( JSContext* cx, CStrW PropertyName, jsval* vp ) = 0;
|
||||
virtual bool GetProperty( JSContext* cx, const CStrW& PropertyName, jsval* vp ) = 0;
|
||||
|
||||
// Add a property (with immediate value)
|
||||
virtual void AddProperty( CStrW PropertyName, jsval Value ) = 0;
|
||||
virtual void AddProperty( CStrW PropertyName, CStrW Value ) = 0;
|
||||
virtual void AddProperty( const CStrW& PropertyName, jsval Value ) = 0;
|
||||
virtual void AddProperty( const CStrW& PropertyName, CStrW Value ) = 0;
|
||||
|
||||
inline IJSObject() {}
|
||||
};
|
||||
@ -224,7 +224,7 @@ public:
|
||||
}
|
||||
|
||||
// JS Property access
|
||||
bool GetProperty( JSContext* cx, CStrW PropertyName, jsval* vp )
|
||||
bool GetProperty( JSContext* cx, const CStrW& PropertyName, jsval* vp )
|
||||
{
|
||||
IJSProperty* Property = HasProperty( PropertyName );
|
||||
if( Property )
|
||||
@ -232,7 +232,7 @@ public:
|
||||
|
||||
return( true );
|
||||
}
|
||||
void SetProperty( JSContext* cx, CStrW PropertyName, jsval* vp )
|
||||
void SetProperty( JSContext* cx, const CStrW& PropertyName, jsval* vp )
|
||||
{
|
||||
if( !ReadOnly )
|
||||
{
|
||||
@ -251,7 +251,7 @@ public:
|
||||
}
|
||||
}
|
||||
|
||||
IJSProperty* HasProperty( CStrW PropertyName )
|
||||
IJSProperty* HasProperty( const CStrW& PropertyName )
|
||||
{
|
||||
PropertyTable::iterator it;
|
||||
|
||||
@ -275,17 +275,17 @@ public:
|
||||
return( NULL );
|
||||
}
|
||||
|
||||
void AddProperty( CStrW PropertyName, jsval Value )
|
||||
void AddProperty( const CStrW& PropertyName, jsval Value )
|
||||
{
|
||||
debug_assert( !HasProperty( PropertyName ) );
|
||||
CJSValProperty* newProp = new CJSValProperty( Value );
|
||||
m_ScriptProperties[PropertyName] = newProp;
|
||||
}
|
||||
void AddProperty( CStrW PropertyName, CStrW Value )
|
||||
void AddProperty( const CStrW& PropertyName, CStrW Value )
|
||||
{
|
||||
AddProperty( PropertyName, JSParseString( Value ) );
|
||||
}
|
||||
static void AddProperty( CStrW PropertyName, TGetFn Getter, TSetFn Setter = NULL )
|
||||
static void AddProperty( const CStrW& PropertyName, TGetFn Getter, TSetFn Setter = NULL )
|
||||
{
|
||||
m_NativeProperties[PropertyName] = new CJSFunctionProperty( (GetFn)Getter, (SetFn)Setter );
|
||||
}
|
||||
@ -295,7 +295,7 @@ public:
|
||||
JSFunctionSpec FnInfo = { Name, CNativeFunction<T, ReadOnly, ReturnType, NativeFunction>::JSFunction, (uint8)MinArgs, 0, 0 };
|
||||
m_Methods.push_back( FnInfo );
|
||||
}
|
||||
template<typename PropType> static void AddProperty( CStrW PropertyName, PropType T::*Native, bool PropReadOnly = ReadOnly )
|
||||
template<typename PropType> static void AddProperty( const CStrW& PropertyName, PropType T::*Native, bool PropReadOnly = ReadOnly )
|
||||
{
|
||||
IJSProperty* prop;
|
||||
if( PropReadOnly )
|
||||
@ -309,7 +309,7 @@ public:
|
||||
m_NativeProperties[PropertyName] = prop;
|
||||
}
|
||||
#ifdef ALLOW_NONSHARED_NATIVES
|
||||
template<typename PropType> void AddLocalProperty( CStrW PropertyName, PropType* Native, bool PropReadOnly = ReadOnly )
|
||||
template<typename PropType> void AddLocalProperty( const CStrW& PropertyName, PropType* Native, bool PropReadOnly = ReadOnly )
|
||||
{
|
||||
IJSProperty* prop;
|
||||
if( PropReadOnly )
|
||||
|
@ -141,7 +141,7 @@ class CSynchedJSObject: public CJSObject<Class>, public CSynchedJSObjectBase
|
||||
protected:
|
||||
// Add a property to the object; if desired, a callback is called every time it changes.
|
||||
// Replaces CJSObject's AddProperty.
|
||||
template <typename T> void AddSynchedProperty(CStrW name, T *native, UpdateFn update=NULL)
|
||||
template <typename T> void AddSynchedProperty(const CStrW& name, T *native, UpdateFn update=NULL)
|
||||
{
|
||||
ISynchedJSProperty *prop=new CSynchedJSProperty<T>(name, native, this, update);
|
||||
this->m_NonsharedProperties[name]=prop;
|
||||
|
@ -1160,7 +1160,7 @@ void CEntity::drawBar( CVector3D& centre, CVector3D& up, CVector3D& right,
|
||||
if(maxVal == 0) fraction = 1.0f;
|
||||
else fraction = clamp( currVal / maxVal, 0.0f, 1.0f );
|
||||
|
||||
// Draw the border at full size
|
||||
/*// Draw the border at full size
|
||||
ogl_tex_bind( g_Selection.m_unitUITextures[m_base->m_barBorder] );
|
||||
drawRect( centre, up, right, x1, y1, x2, y2 );
|
||||
ogl_tex_bind( 0 );
|
||||
@ -1169,7 +1169,7 @@ void CEntity::drawBar( CVector3D& centre, CVector3D& up, CVector3D& right,
|
||||
x1 += m_base->m_barBorderSize;
|
||||
y1 += m_base->m_barBorderSize;
|
||||
x2 -= m_base->m_barBorderSize;
|
||||
y2 -= m_base->m_barBorderSize;
|
||||
y2 -= m_base->m_barBorderSize;*/
|
||||
|
||||
// Draw the bar contents
|
||||
float xMid = x2 * fraction + x1 * (1.0f - fraction);
|
||||
@ -1200,13 +1200,19 @@ void CEntity::renderBars()
|
||||
|
||||
bool hasStamina = (m_staminaMax > 0);
|
||||
|
||||
float off = hasStamina ? (h/2 - borderSize/2) : 0;
|
||||
float backgroundW = w+2*borderSize;
|
||||
float backgroundH = hasStamina ? 2*h+2*borderSize : h+2*borderSize;
|
||||
ogl_tex_bind( g_Selection.m_unitUITextures[m_base->m_barBorder] );
|
||||
drawRect( centre, up, right, -backgroundW/2, -backgroundH/2, backgroundW/2, backgroundH/2 );
|
||||
ogl_tex_bind( 0 );
|
||||
|
||||
float off = hasStamina ? h/2 : 0;
|
||||
drawBar( centre, up, right, -w/2, off-h/2, w/2, off+h/2,
|
||||
SColour(0,1,0), SColour(1,0,0), m_healthCurr, m_healthMax );
|
||||
|
||||
if( hasStamina )
|
||||
{
|
||||
drawBar( centre, up, right, -w/2, borderSize/2-h, w/2, borderSize/2,
|
||||
drawBar( centre, up, right, -w/2, -h, w/2, 0,
|
||||
SColour(0,0,1), SColour(0.4f,0.4f,0.1f), m_staminaCurr, m_staminaMax );
|
||||
}
|
||||
|
||||
@ -1215,9 +1221,9 @@ void CEntity::renderBars()
|
||||
std::map<CStr, Handle>::iterator it = g_Selection.m_unitUITextures.find( m_rankName );
|
||||
if( it != g_Selection.m_unitUITextures.end() )
|
||||
{
|
||||
float size = hasStamina ? (2*h - 3*borderSize) : h;
|
||||
float size = 2*h + borderSize;
|
||||
ogl_tex_bind( it->second );
|
||||
drawRect( centre, up, right, w/2, -size/2, w/2+size, size/2 );
|
||||
drawRect( centre, up, right, w/2+borderSize, -size/2, w/2+borderSize+size, size/2 );
|
||||
ogl_tex_bind( 0 );
|
||||
}
|
||||
}
|
||||
|
@ -56,12 +56,12 @@ CEntityTemplate* CEntityTemplateCollection::getTemplate( CStrW name, CPlayer* pl
|
||||
CEntityTemplate* newTemplate = new CEntityTemplate( player );
|
||||
if( !newTemplate->loadXML( path ) )
|
||||
{
|
||||
LOG(ERROR, LOG_CATEGORY, "CEntityTemplateCollection::loadTemplates(): Couldn't load template \"%s\"", path.c_str());
|
||||
LOG(ERROR, LOG_CATEGORY, "CEntityTemplateCollection::getTemplate(): Couldn't load template \"%s\"", path.c_str());
|
||||
delete newTemplate;
|
||||
return( NULL );
|
||||
}
|
||||
|
||||
LOG(NORMAL, LOG_CATEGORY, "CEntityTemplateCollection::loadTemplates(): Loaded template \"%s\"", path.c_str());
|
||||
LOG(NORMAL, LOG_CATEGORY, "CEntityTemplateCollection::getTemplate(): Loaded template \"%s\"", path.c_str());
|
||||
m_templates[id][name] = newTemplate;
|
||||
|
||||
return newTemplate;
|
||||
|
@ -6,17 +6,15 @@
|
||||
//
|
||||
// General note: Template, Base Entity, and Entity Class are used more-or-less interchangably.
|
||||
//
|
||||
// Usage: g_EntityTemplateCollection.loadTemplates(): initializes the lists from entities/templates
|
||||
// After that, you can:
|
||||
// Find an entity class by the actor it uses: g_EntityTemplateCollection.getTemplateByActor()
|
||||
// Note that this is included solely for loading ScnEd 4,5 and 6 format map files. Don't rely on this
|
||||
// working all the time.
|
||||
// Find an entity class by its name: g_EntityTemplateCollection.getTemplate()
|
||||
// g_EntityManager will also use this class to lookup entity templates when you instantiate an entity with
|
||||
// a class name string.
|
||||
// Usage: g_EntityTemplateCollection.loadTemplates(): loads all templates
|
||||
// g_EntityTemplateCollection.getTemplate(name): get a template by name
|
||||
//
|
||||
// EntityTemplateCollection will look at all subdirectiroes of entities/, but each template's
|
||||
// name will only be its filename; thus, no two templates should have the same filename,
|
||||
// but subdirectories can be created in entities/ to organize the files nicely.
|
||||
|
||||
#ifndef BASEENT_COLLECTION_INCLUDED
|
||||
#define BASEENT_COLLECTION_INCLUDED
|
||||
#ifndef ENTITY_TEMPLATE_COLLECTION_INCLUDED
|
||||
#define ENTITY_TEMPLATE_COLLECTION_INCLUDED
|
||||
|
||||
#include <vector>
|
||||
#include <map>
|
||||
|
Loading…
Reference in New Issue
Block a user