1
0
forked from 0ad/0ad

Corrected mesh manager's use of hashmap. Added CStrW support to JS/GUI interface. Added error checking to CStr::Left/Right to make bugs more obvious.

This was SVN commit r1456.
This commit is contained in:
Ykkrosh 2004-12-05 18:26:43 +00:00
parent 761261880a
commit ffb5f87857
6 changed files with 31 additions and 12 deletions

View File

@ -14,7 +14,7 @@ CModelDef *CMeshManager::GetMesh(const char *filename)
{
mesh_map::iterator iter;
CStr fn(filename);
if((iter = m_MeshMap.find(fn.GetHashCode())) == m_MeshMap.end())
if((iter = m_MeshMap.find(fn)) == m_MeshMap.end())
{
try
{
@ -23,9 +23,9 @@ CModelDef *CMeshManager::GetMesh(const char *filename)
return NULL;
LOG(MESSAGE, "mesh", "Loading mesh '%s'...\n", filename);
model->m_Hash = fn.GetHashCode();
model->m_Filename = fn;
model->m_RefCount = 1;
m_MeshMap[model->m_Hash] = model;
m_MeshMap[fn] = model;
return model;
}
catch(...)
@ -45,7 +45,7 @@ CModelDef *CMeshManager::GetMesh(const char *filename)
int CMeshManager::ReleaseMesh(CModelDef* mesh)
{
if(!mesh)
if(!mesh)
return 0;
// FIXME: Someone sort this out. I'm tired.
@ -56,7 +56,7 @@ int CMeshManager::ReleaseMesh(CModelDef* mesh)
try
{
iter = m_MeshMap.find(mesh->m_Hash);
iter = m_MeshMap.find(mesh->m_Filename);
}
catch( ... )
{

View File

@ -6,7 +6,7 @@
#define g_MeshManager CMeshManager::GetSingleton()
typedef STL_HASH_MAP<size_t, CModelDef *> mesh_map;
typedef STL_HASH_MAP<CStr, CModelDef *, CStr_hash_compare> mesh_map;
class CMeshManager : public Singleton<CMeshManager>
{

View File

@ -128,7 +128,7 @@ public:
protected:
static CModelDef* Load(const char* filename);
int m_RefCount;
size_t m_Hash;
CStr m_Filename;
};
#endif

View File

@ -1,4 +1,4 @@
// $Id: JSInterface_IGUIObject.cpp,v 1.15 2004/09/06 11:28:30 philip Exp $
// $Id$
#include "precompiled.h"
@ -173,11 +173,20 @@ JSBool JSI_IGUIObject::getProperty(JSContext* cx, JSObject* obj, jsval id, jsval
{
CStr value;
GUI<CStr>::GetSetting(e, propName, value);
// Create a garbage-collectable copy of the string
// Create a garbage-collectible copy of the string
*vp = STRING_TO_JSVAL(JS_NewStringCopyZ(cx, value.c_str() ));
break;
}
case GUIST_CStrW:
{
CStrW value;
GUI<CStrW>::GetSetting(e, propName, value);
// Create a garbage-collectible copy of the string
*vp = STRING_TO_JSVAL(JS_NewUCStringCopyZ(cx, value.utf16().c_str() ));
break;
}
// TODO Gee: (2004-09-01) EAlign and EVAlign too.
default:
@ -220,6 +229,13 @@ JSBool JSI_IGUIObject::setProperty(JSContext* cx, JSObject* obj, jsval id, jsval
break;
}
case GUIST_CStrW:
{
utf16string value (JS_GetStringChars(JS_ValueToString(cx, *vp)));
GUI<CStrW>::SetSetting(e, propName, value);
break;
}
case GUIST_CGUIString:
{
std::wstring value;

View File

@ -1,4 +1,4 @@
// $Id: JSInterface_IGUIObject.h,v 1.2 2004/07/10 21:23:06 philip Exp $
// $Id$
#include "scripting/ScriptingHost.h"
#include "gui/GUI.h"
@ -19,7 +19,6 @@ namespace JSI_IGUIObject
JSBool getByName(JSContext* cx, JSObject* obj, unsigned int argc, jsval* argv, jsval* rval);
JSBool toString(JSContext* cx, JSObject* obj, unsigned int argc, jsval* argv, jsval* rval);
void init();
void x();
}
#endif

View File

@ -11,7 +11,7 @@
// Only include these function definitions in the first instance of CStr.cpp:
CStrW::CStrW(const CStr8 &asciStr) : std::wstring(asciStr.begin(), asciStr.end()) {}
CStr8::CStr8(const CStrW &wideStr) : std::string(wideStr.begin(), wideStr.end()) {}
CStr8::CStr8(const CStrW &wideStr) : std:: string(wideStr.begin(), wideStr.end()) {}
#else
@ -172,12 +172,16 @@ CStr CStr::UCase() const
// Retrieve the substring of the first n characters
CStr CStr::Left(long len) const
{
assert(len >= 0);
assert(len <= (long)length());
return substr(0, len);
}
// Retrieve the substring of the last n characters
CStr CStr::Right(long len) const
{
assert(len >= 0);
assert(len <= (long)length());
return substr(length()-len, len);
}