diff --git a/source/graphics/Model.cpp b/source/graphics/Model.cpp index 246c2b2674..68385b2368 100755 --- a/source/graphics/Model.cpp +++ b/source/graphics/Model.cpp @@ -416,7 +416,7 @@ void CModel::SetTransform(const CMatrix3D& transform) InvalidateBounds(); // now set transforms on props - const CMatrix3D* bonematrices=GetBoneMatrices();// TODO2: this or m_BoneMatrices? + const CMatrix3D* bonematrices=GetBoneMatrices();// TODO2: this or m_BoneMatrices? // (GetBoneMatrices updates m_BoneMatrices (when necessary) and returns it) for (size_t i=0;i attempt to load properties if (vfs_exists(xmlname.c_str())) myprops=GetPropertiesFromFile(props, xmlname); - + + CTerrainProperties *usedProps = NULL; if (myprops) + { LOG(NORMAL, LOG_CATEGORY, "CTextureManager: Successfully loaded override xml %s for texture %s\n", xmlname.c_str(), dent.name); + usedProps = myprops; + } + else + { + // Error or non-existant xml file -> use parent props + usedProps = props; + } - // Error or non-existant xml file -> use parent props - if (!myprops) - myprops = props; - - AddTexture(myprops, path+dent.name); + AddTexture(usedProps, path+dent.name); + + delete myprops; } vfs_dir_close(dir); @@ -126,14 +133,17 @@ void CTextureManager::RecurseDirectory(CTerrainProperties *parentProps, CStr pat LOG(NORMAL, LOG_CATEGORY, "CTextureManager::RecurseDirectory(%s)", path.c_str()); // Load terrains.xml first, if it exists - CTerrainProperties *props=NULL; + CTerrainProperties *loadedProps=NULL; CStr xmlpath=path+"terrains.xml"; if (vfs_exists(xmlpath.c_str())) - props=GetPropertiesFromFile(parentProps, xmlpath); + loadedProps=GetPropertiesFromFile(parentProps, xmlpath); - // No terrains.xml, or read failures -> use parent props (i.e. - if (!props) + CTerrainProperties *props=NULL; + if (loadedProps) + props = loadedProps; + else { + // No terrains.xml, or read failures -> use parent props LOG(NORMAL, LOG_CATEGORY, "CTextureManager::RecurseDirectory(%s): no terrains.xml (or errors while loading) - using parent properties", path.c_str()); props = parentProps; @@ -158,6 +168,8 @@ void CTextureManager::RecurseDirectory(CTerrainProperties *parentProps, CStr pat { LoadTextures(props, path, SupportedTextureFormats[i]); } + + delete loadedProps; } diff --git a/source/i18n/ScriptInterface.cpp b/source/i18n/ScriptInterface.cpp index 2dc317a9c0..b41ddaa1a5 100755 --- a/source/i18n/ScriptInterface.cpp +++ b/source/i18n/ScriptInterface.cpp @@ -164,8 +164,6 @@ static JSBool JSFunc_Translate(JSContext *cx, JSObject *obj, uintN argc, jsval * jsval locale_objval; JS_ASSERT(JS_GetProperty(cx, obj, "i18n", &locale_objval), "translate() failed to find i18n object in current scope"); - JSObject* locale_obj = JSVAL_TO_OBJECT(locale_objval); - UNUSED2(locale_obj); CLocale* locale = (CLocale*)JS_GetPrivate(cx, JSVAL_TO_OBJECT(locale_objval)); StringBuffer sb = locale->Translate(phrase.c_str()); diff --git a/source/i18n/tests/precompiled.h b/source/i18n/tests/precompiled.h index 834d8c5e6f..16bd2dddab 100755 --- a/source/i18n/tests/precompiled.h +++ b/source/i18n/tests/precompiled.h @@ -30,6 +30,8 @@ #define debug_assert assert #define XP_WIN +#define MSC_VERSION _MSC_VER +#define UNUSED(x) #include "ps/Errors.h" diff --git a/source/lib/mmgr.h b/source/lib/mmgr.h index c6be833ddc..8392195cd5 100644 --- a/source/lib/mmgr.h +++ b/source/lib/mmgr.h @@ -247,4 +247,3 @@ extern void operator delete[](void* p, const char* file, int line, const char* f #define new new(_NORMAL_BLOCK, __FILE__, __LINE__) #endif // #if CONFIG_USE_MMGR - diff --git a/source/lib/res/tex.cpp b/source/lib/res/tex.cpp index c837a71ede..44ba3cab9b 100755 --- a/source/lib/res/tex.cpp +++ b/source/lib/res/tex.cpp @@ -958,7 +958,7 @@ static void png_read(png_struct* png_ptr, u8* data, png_size_t length) // split out of png_decode to simplify resource cleanup and avoid // "dtor / setjmp interaction" warning. -static png_decode_impl(TexInfo* t, u8* file, size_t file_size, +static int png_decode_impl(TexInfo* t, u8* file, size_t file_size, png_structp png_ptr, png_infop info_ptr, u8*& img, RowArray& rows, const char*& msg) { diff --git a/source/lib/sysdep/win/wdbg_sym.cpp b/source/lib/sysdep/win/wdbg_sym.cpp index 54fb4533ed..c3c9060452 100755 --- a/source/lib/sysdep/win/wdbg_sym.cpp +++ b/source/lib/sysdep/win/wdbg_sym.cpp @@ -279,7 +279,7 @@ int debug_resolve_symbol(void* ptr_of_interest, char* sym_name, char* file, int* // on us returning their correct values. static __declspec(naked) void get_current_context(void* pcontext) { - // squelch W4 unused paramter warning (it's accessed from asm) + // squelch W4 unused parameter warning (it's accessed from asm) UNUSED2(pcontext); __asm { diff --git a/source/lib/sysdep/win/wsdl.cpp b/source/lib/sysdep/win/wsdl.cpp index 5bf9c90b11..0b502be16c 100755 --- a/source/lib/sysdep/win/wsdl.cpp +++ b/source/lib/sysdep/win/wsdl.cpp @@ -418,6 +418,7 @@ return_char: // sensitivity settings. Windows messages are laggy, so poll instead. POINT p; GetCursorPos(&p); + ScreenToClient(hWnd, &p); if(mouse_x != p.x || mouse_y != p.y) { ev->type = SDL_MOUSEMOTION; @@ -663,6 +664,17 @@ keep: DWORD windowStyle = fullscreen ? (WS_POPUP|WS_VISIBLE) : (WS_CAPTION | WS_POPUPWINDOW | WS_VISIBLE); + // Calculate the size of the outer window, so that the client area has + // the desired dimensions. + RECT r; + r.left = r.top = 0; + r.right = w; r.bottom = h; + if (AdjustWindowRectEx(&r, windowStyle, false, 0)) + { + w = r.right - r.left; + h = r.bottom - r.top; + } + hWnd = CreateWindowEx(0, (LPCSTR)class_atom, APP_NAME, windowStyle, 0, 0, w, h, 0, 0, hInst, 0); if(!hWnd) return 0; diff --git a/source/ps/CStr.cpp b/source/ps/CStr.cpp index 343356fc70..fb308777aa 100755 --- a/source/ps/CStr.cpp +++ b/source/ps/CStr.cpp @@ -38,7 +38,6 @@ CStr8 CStrW::ToUTF8() const { CStr8 result; - //const wchar_t* source = &*begin(); // UNUSED for (size_t i = 0; i < Length(); ++i) { unsigned short bytesToWrite; diff --git a/source/ps/CStr.h b/source/ps/CStr.h index cae981da2d..1c97dfc864 100755 --- a/source/ps/CStr.h +++ b/source/ps/CStr.h @@ -70,7 +70,7 @@ class CStr8; class CStrW; // CStr class, the mother of all strings -class CStr: public std::tstring, public ISerializable +class CStr: public std::tstring { // The two variations must be friends with each other #ifdef _UNICODE @@ -223,9 +223,11 @@ public: size_t GetHashCode() const; // Serialization functions - virtual uint GetSerializedLength() const; - virtual u8 *Serialize(u8 *buffer) const; - virtual const u8 *Deserialize(const u8 *buffer, const u8 *bufferend); + // (These are not virtual or inherited from ISerializable, to avoid + // adding a vtable and making the strings larger than std::string) + uint GetSerializedLength() const; + u8 *Serialize(u8 *buffer) const; + const u8 *Deserialize(const u8 *buffer, const u8 *bufferend); }; // Hash function (for STL_HASH_MAP, etc) diff --git a/source/ps/Game.cpp b/source/ps/Game.cpp index 92d616e4db..621f85062b 100755 --- a/source/ps/Game.cpp +++ b/source/ps/Game.cpp @@ -137,15 +137,11 @@ CPlayer *CGame::GetPlayer(uint idx) debug_warn("Invalid player ID"); LOG(ERROR, "", "Invalid player ID %d (not <=%d - internal error?)", idx, m_Players.size()); - if (m_Players.size() == 0) - { - // Hmm. This is a bit of a problem. - debug_warn("### ### ### ### ERROR: Tried to access the players list when there aren't any players. That really isn't going to work, so I'll give up. ### ###"); - abort(); - return NULL; // else VC2005 warns about not returning a value - } - else + if (m_Players.size() != 0) return m_Players[0]; + else + return NULL; // the caller will probably crash because of this, + // but at least we've reported the error } else return m_Players[idx]; diff --git a/source/scripting/ScriptingHost.cpp b/source/scripting/ScriptingHost.cpp index a4a7da75ee..bede7442ba 100755 --- a/source/scripting/ScriptingHost.cpp +++ b/source/scripting/ScriptingHost.cpp @@ -96,6 +96,8 @@ void ScriptingHost::RunMemScript(const char* script, size_t size, const char* fi if(!globalObject) globalObject = m_GlobalObject; + // Maybe TODO: support Unicode input formats? + jsval rval; JSBool ok = JS_EvaluateScript(m_Context, globalObject, script, (uint)size, filename, line, &rval); @@ -303,6 +305,8 @@ jsval ScriptingHost::GetGlobal(const std::string &globalName) // conversions //---------------------------------------------------------------------------- /* +// These have been removed in favour of ToPrimitive(value) + int ScriptingHost::ValueToInt(const jsval value) { int32 i = 0; @@ -330,14 +334,14 @@ bool ScriptingHost::ValueToBool(const jsval value) double ScriptingHost::ValueToDouble(const jsval value) { -jsdouble d; + jsdouble d; -JSBool ok = JS_ValueToNumber(m_Context, value, &d); + JSBool ok = JS_ValueToNumber(m_Context, value, &d); -if (ok == JS_FALSE || !finite( d ) ) -throw PSERROR_Scripting_ConversionFailed(); + if (ok == JS_FALSE || !finite(d)) + throw PSERROR_Scripting_ConversionFailed(); -return d; + return d; } diff --git a/source/simulation/Entity.cpp b/source/simulation/Entity.cpp index 46a23740a3..3be0dd2d67 100755 --- a/source/simulation/Entity.cpp +++ b/source/simulation/Entity.cpp @@ -783,8 +783,11 @@ JSBool CEntity::Construct( JSContext* cx, JSObject* UNUSED(obj), uint argc, jsva JSObject* jsBaseEntity = JSVAL_TO_OBJECT( argv[0] ); CStrW templateName; - CBaseEntity* baseEntity = ToNative( cx, jsBaseEntity ); - if( !JSVAL_IS_OBJECT( argv[0] ) || !baseEntity ) + CBaseEntity* baseEntity = NULL; + if( JSVAL_IS_OBJECT( argv[0] ) ) // only set baseEntity if jsBaseEntity is a valid object + baseEntity = ToNative( cx, jsBaseEntity ); + + if( !baseEntity ) { try { @@ -806,8 +809,11 @@ JSBool CEntity::Construct( JSContext* cx, JSObject* UNUSED(obj), uint argc, jsva return( JS_TRUE ); } - JSI_Vector3D::Vector3D_Info* jsVector3D = (JSI_Vector3D::Vector3D_Info*)JS_GetInstancePrivate( cx, JSVAL_TO_OBJECT( argv[1] ), &JSI_Vector3D::JSI_class, NULL ); - if( JSVAL_IS_OBJECT( argv[1] ) && jsVector3D ) + JSI_Vector3D::Vector3D_Info* jsVector3D = NULL; + if( JSVAL_IS_OBJECT( argv[1] ) ) + jsVector3D = (JSI_Vector3D::Vector3D_Info*)JS_GetInstancePrivate( cx, JSVAL_TO_OBJECT( argv[1] ), &JSI_Vector3D::JSI_class, NULL ); + + if( jsVector3D ) { position = *( jsVector3D->vector ); } diff --git a/source/simulation/EntityStateProcessing.cpp b/source/simulation/EntityStateProcessing.cpp index 82bad792bd..4e37ec4792 100755 --- a/source/simulation/EntityStateProcessing.cpp +++ b/source/simulation/EntityStateProcessing.cpp @@ -523,7 +523,8 @@ bool CEntity::processGoto( CEntityOrder* current, size_t UNUSED(timestep_millis) { CSkeletonAnim* walk = m_actor->GetRandomAnimation( "walk" ); - m_actor->GetModel()->SetAnimation( walk, false, m_speed * walk->m_AnimDef->GetDuration() ); + if( walk ) + m_actor->GetModel()->SetAnimation( walk, false, m_speed * walk->m_AnimDef->GetDuration() ); // Animation desync m_actor->GetModel()->Update( ( rand() * 1000.0f ) / 1000.0f ); }