From ffb5f8785763e8d59bdda4e88b40f2148b51b5d7 Mon Sep 17 00:00:00 2001 From: Ykkrosh Date: Sun, 5 Dec 2004 18:26:43 +0000 Subject: [PATCH] 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. --- source/graphics/MeshManager.cpp | 10 +++++----- source/graphics/MeshManager.h | 2 +- source/graphics/ModelDef.h | 2 +- .../gui/scripting/JSInterface_IGUIObject.cpp | 20 +++++++++++++++++-- source/gui/scripting/JSInterface_IGUIObject.h | 3 +-- source/ps/CStr.cpp | 6 +++++- 6 files changed, 31 insertions(+), 12 deletions(-) diff --git a/source/graphics/MeshManager.cpp b/source/graphics/MeshManager.cpp index 472a07a8b1..0672f43079 100755 --- a/source/graphics/MeshManager.cpp +++ b/source/graphics/MeshManager.cpp @@ -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( ... ) { diff --git a/source/graphics/MeshManager.h b/source/graphics/MeshManager.h index 08e4400585..d80693a416 100755 --- a/source/graphics/MeshManager.h +++ b/source/graphics/MeshManager.h @@ -6,7 +6,7 @@ #define g_MeshManager CMeshManager::GetSingleton() -typedef STL_HASH_MAP mesh_map; +typedef STL_HASH_MAP mesh_map; class CMeshManager : public Singleton { diff --git a/source/graphics/ModelDef.h b/source/graphics/ModelDef.h index 2bbecb0abf..119c1d10ff 100755 --- a/source/graphics/ModelDef.h +++ b/source/graphics/ModelDef.h @@ -128,7 +128,7 @@ public: protected: static CModelDef* Load(const char* filename); int m_RefCount; - size_t m_Hash; + CStr m_Filename; }; #endif diff --git a/source/gui/scripting/JSInterface_IGUIObject.cpp b/source/gui/scripting/JSInterface_IGUIObject.cpp index 49e03eb477..fbebd30ce4 100755 --- a/source/gui/scripting/JSInterface_IGUIObject.cpp +++ b/source/gui/scripting/JSInterface_IGUIObject.cpp @@ -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::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::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::SetSetting(e, propName, value); + break; + } + case GUIST_CGUIString: { std::wstring value; diff --git a/source/gui/scripting/JSInterface_IGUIObject.h b/source/gui/scripting/JSInterface_IGUIObject.h index c9e3525f33..0a04fa1439 100755 --- a/source/gui/scripting/JSInterface_IGUIObject.h +++ b/source/gui/scripting/JSInterface_IGUIObject.h @@ -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 diff --git a/source/ps/CStr.cpp b/source/ps/CStr.cpp index 0b6b7afe17..bdcee064f6 100755 --- a/source/ps/CStr.cpp +++ b/source/ps/CStr.cpp @@ -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); }