From e1f06f4667a3eb961c70b6f682b4939dc93a1697 Mon Sep 17 00:00:00 2001 From: Matei Date: Mon, 17 Jul 2006 22:18:37 +0000 Subject: [PATCH] # 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. --- source/scripting/ScriptableObject.h | 24 +++++++++---------- source/scripting/SynchedJSObject.h | 2 +- source/simulation/Entity.cpp | 18 +++++++++----- .../simulation/EntityTemplateCollection.cpp | 4 ++-- source/simulation/EntityTemplateCollection.h | 18 +++++++------- 5 files changed, 35 insertions(+), 31 deletions(-) diff --git a/source/scripting/ScriptableObject.h b/source/scripting/ScriptableObject.h index 06d2dfcfb0..981981ce37 100644 --- a/source/scripting/ScriptableObject.h +++ b/source/scripting/ScriptableObject.h @@ -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::JSFunction, (uint8)MinArgs, 0, 0 }; m_Methods.push_back( FnInfo ); } - template static void AddProperty( CStrW PropertyName, PropType T::*Native, bool PropReadOnly = ReadOnly ) + template 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 void AddLocalProperty( CStrW PropertyName, PropType* Native, bool PropReadOnly = ReadOnly ) + template void AddLocalProperty( const CStrW& PropertyName, PropType* Native, bool PropReadOnly = ReadOnly ) { IJSProperty* prop; if( PropReadOnly ) diff --git a/source/scripting/SynchedJSObject.h b/source/scripting/SynchedJSObject.h index 8f7b69a9de..c02305122c 100644 --- a/source/scripting/SynchedJSObject.h +++ b/source/scripting/SynchedJSObject.h @@ -141,7 +141,7 @@ class CSynchedJSObject: public CJSObject, public CSynchedJSObjectBase protected: // Add a property to the object; if desired, a callback is called every time it changes. // Replaces CJSObject's AddProperty. - template void AddSynchedProperty(CStrW name, T *native, UpdateFn update=NULL) + template void AddSynchedProperty(const CStrW& name, T *native, UpdateFn update=NULL) { ISynchedJSProperty *prop=new CSynchedJSProperty(name, native, this, update); this->m_NonsharedProperties[name]=prop; diff --git a/source/simulation/Entity.cpp b/source/simulation/Entity.cpp index 348d1689ff..e0be201937 100644 --- a/source/simulation/Entity.cpp +++ b/source/simulation/Entity.cpp @@ -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::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 ); } } diff --git a/source/simulation/EntityTemplateCollection.cpp b/source/simulation/EntityTemplateCollection.cpp index c42ff5b60a..20df488a8f 100644 --- a/source/simulation/EntityTemplateCollection.cpp +++ b/source/simulation/EntityTemplateCollection.cpp @@ -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; diff --git a/source/simulation/EntityTemplateCollection.h b/source/simulation/EntityTemplateCollection.h index 86f60d6875..f20bfbc02e 100644 --- a/source/simulation/EntityTemplateCollection.h +++ b/source/simulation/EntityTemplateCollection.h @@ -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 #include