diff --git a/source/graphics/ProgramManager.h b/source/graphics/ProgramManager.h index b4285f468c..a495e59725 100755 --- a/source/graphics/ProgramManager.h +++ b/source/graphics/ProgramManager.h @@ -37,4 +37,4 @@ private: #endif }; -#endif \ No newline at end of file +#endif diff --git a/source/gui/GUItext.cpp b/source/gui/GUItext.cpp index a332df4d34..19aab70df4 100755 --- a/source/gui/GUItext.cpp +++ b/source/gui/GUItext.cpp @@ -586,4 +586,4 @@ void CGUIString::SetValue(const CStrW& str) } } #endif -} \ No newline at end of file +} diff --git a/source/gui/IGUIObject.cpp b/source/gui/IGUIObject.cpp index 064ea83b53..224f7268f9 100755 --- a/source/gui/IGUIObject.cpp +++ b/source/gui/IGUIObject.cpp @@ -507,4 +507,4 @@ void IGUIObject::SetFocus() bool IGUIObject::IsFocused() const { return GetGUI()->m_FocusedObject == this; -} \ No newline at end of file +} diff --git a/source/gui/MiniMap.cpp b/source/gui/MiniMap.cpp index a42eec5055..197c1e9dae 100755 --- a/source/gui/MiniMap.cpp +++ b/source/gui/MiniMap.cpp @@ -1,17 +1,18 @@ #include "precompiled.h" + #include "gui/MiniMap.h" -#include "ps/game.h" +#include "ps/Game.h" #include "ogl.h" -#include "renderer/renderer.h" +#include "renderer/Renderer.h" #include "graphics/TextureEntry.h" #include "graphics/TextureManager.h" static unsigned int ScaleColor(unsigned int color,float x) { - unsigned int r=unsigned int(float(color & 0xff)*x); - unsigned int g=unsigned int(float((color>>8) & 0xff)*x); - unsigned int b=unsigned int(float((color>>16) & 0xff)*x); + unsigned int r=uint(float(color & 0xff)*x); + unsigned int g=uint(float((color>>8) & 0xff)*x); + unsigned int b=uint(float((color>>16) & 0xff)*x); return (0xff000000 | r | g<<8 | b<<16); } @@ -199,4 +200,4 @@ CVector2D CMiniMap::GetMapSpaceCoords(CVector3D worldPos) float scaleX = float(m_Width) / float(m_MapSize - 1); float scaleY = float(m_Height) / float(m_MapSize - 1); return CVector2D(float(x) * scaleX, float(y) * scaleY); -} \ No newline at end of file +} diff --git a/source/gui/MiniMap.h b/source/gui/MiniMap.h index 6aa1311f92..8c8a92fb34 100755 --- a/source/gui/MiniMap.h +++ b/source/gui/MiniMap.h @@ -56,4 +56,4 @@ protected: u32 m_TextureSize; }; -#endif \ No newline at end of file +#endif diff --git a/source/lib/res/handle.h b/source/lib/res/handle.h index 87facc6c62..8ad33dded8 100755 --- a/source/lib/res/handle.h +++ b/source/lib/res/handle.h @@ -6,4 +6,4 @@ // with 32 bits, we'd need >= 12 for the index, leaving < 512K tags - // not a lot. typedef i64 Handle; -#define HANDLE_DEFINED \ No newline at end of file +#define HANDLE_DEFINED diff --git a/source/lib/res/ogghack.cpp b/source/lib/res/ogghack.cpp index f10c668f4f..fb73b42207 100755 --- a/source/lib/res/ogghack.cpp +++ b/source/lib/res/ogghack.cpp @@ -7,7 +7,7 @@ #include #include -#include +#include #include diff --git a/source/lib/res/ogghack.h b/source/lib/res/ogghack.h index 394c20f1d2..cbf0bb8904 100755 --- a/source/lib/res/ogghack.h +++ b/source/lib/res/ogghack.h @@ -6,4 +6,4 @@ void ogg_open(void* o, ALenum& fmt, ALsizei& freq); size_t ogg_read(void* o, void* buf, size_t max_size); -void ogg_release(void* o); \ No newline at end of file +void ogg_release(void* o); diff --git a/source/lib/sysdep/sysdep.h b/source/lib/sysdep/sysdep.h index 4d39836384..da061f5a4f 100755 --- a/source/lib/sysdep/sysdep.h +++ b/source/lib/sysdep/sysdep.h @@ -63,6 +63,20 @@ extern float fmaxf(float a, float b); # include # define STL_HASH_MAP __gnu_cxx::hash_map # define STL_HASH_MULTIMAP __gnu_cxx::hash_multimap + +// Hack: GCC Doesn't have a hash instance for std::string included (and it looks +// like they won't add it - marked resolved/wontfix in the gcc bugzilla) +namespace __gnu_cxx +{ + template<> struct hash + { + size_t operator()(const std::string& __x) const + { + return __stl_hash_string(__x.c_str()); + } + }; +} + #else // !__GNUC__ # include # if defined(_MSC_VER) && (_MSC_VER >= 1300) diff --git a/source/main.cpp b/source/main.cpp index 8d2b610422..6c9c03524b 100755 --- a/source/main.cpp +++ b/source/main.cpp @@ -27,7 +27,6 @@ #include "ps/Game.h" -#include "Config.h" #include "MapReader.h" #include "Terrain.h" #include "TextureManager.h" @@ -592,7 +591,7 @@ static void LoadGlobals() val->GetBool(g_Shadows); LOG(NORMAL, LOG_CATEGORY, "g_x/yres is %dx%d", g_xres, g_yres); - LOG(NORMAL, LOG_CATEGORY, "Active profile is %s", g_ActiveProfile); + LOG(NORMAL, LOG_CATEGORY, "Active profile is %s", g_ActiveProfile.c_str()); } static void ParseArgs(int argc, char* argv[]) diff --git a/source/maths/Vector3D.h b/source/maths/Vector3D.h index 5ac681d9cd..cc77a0edc6 100755 --- a/source/maths/Vector3D.h +++ b/source/maths/Vector3D.h @@ -62,4 +62,4 @@ class CVector3D void Normalize (); }; -#endif \ No newline at end of file +#endif diff --git a/source/ps/Interact.cpp b/source/ps/Interact.cpp index a8b59fc81f..d645bba583 100755 --- a/source/ps/Interact.cpp +++ b/source/ps/Interact.cpp @@ -15,7 +15,7 @@ extern bool keys[SDLK_LAST]; extern bool g_active; static const float SELECT_DBLCLICK_RATE = 0.5f; -static const int ORDER_DELAY = 5; +const int ORDER_DELAY = 5; void CSelectedEntities::addSelection( HEntity entity ) { diff --git a/source/ps/VFSUtil.cpp b/source/ps/VFSUtil.cpp index 8e68f25f3d..b3bd6482ad 100755 --- a/source/ps/VFSUtil.cpp +++ b/source/ps/VFSUtil.cpp @@ -39,4 +39,4 @@ bool VFSUtil::FindFiles (CStr dirname, const char* filter, FileList& files) return true; -} \ No newline at end of file +} diff --git a/source/ps/VFSUtil.h b/source/ps/VFSUtil.h index 7c6f7d1922..b6ea04010d 100755 --- a/source/ps/VFSUtil.h +++ b/source/ps/VFSUtil.h @@ -15,4 +15,4 @@ namespace VFSUtil // On failure, logs an error and returns false. bool FindFiles(CStr dirname, const char* filter, FileList& files); -}; \ No newline at end of file +}; diff --git a/source/ps/scripting/JSCollection.h b/source/ps/scripting/JSCollection.h index 31f4c24e8c..079ec55962 100755 --- a/source/ps/scripting/JSCollection.h +++ b/source/ps/scripting/JSCollection.h @@ -5,6 +5,8 @@ #include "scripting/ScriptingHost.h" #include "scripting/JSInterface_Entity.h" +#include "simulation/ScriptObject.h" +#include "scripting/JSConversions.h" #ifndef JS_COLLECTION_INCLUDED #define JS_COLLECTION_INCLUDED @@ -264,7 +266,7 @@ template JSBool CJSCollection::S CJSCollectionData* CollectionData = new CJSCollectionData(); CollectionData->m_EngineOwned = false; - std::vector::iterator it; + typename std::vector::iterator it; CScriptObject Predicate( argv[0] ); diff --git a/source/renderer/VertexProgram.h b/source/renderer/VertexProgram.h index a35ff1280c..10f5f36d1d 100755 --- a/source/renderer/VertexProgram.h +++ b/source/renderer/VertexProgram.h @@ -32,4 +32,4 @@ private: #endif }; -#endif \ No newline at end of file +#endif diff --git a/source/scripting/DOMEvent.cpp b/source/scripting/DOMEvent.cpp index 538ecf9ee2..ee25d03da6 100755 --- a/source/scripting/DOMEvent.cpp +++ b/source/scripting/DOMEvent.cpp @@ -12,8 +12,8 @@ CScriptEvent::CScriptEvent( const CStrW& Type, bool Cancelable, unsigned int Typ void CScriptEvent::ScriptingInit() { - AddMethod( "toString", 0 ); - AddMethod( "preventDefault", 0 ); + AddMethod( "toString", 0 ); + AddMethod( "preventDefault", 0 ); CJSObject::ScriptingInit( "Event" ); } @@ -27,9 +27,10 @@ jsval CScriptEvent::PreventDefault( JSContext* cx, uintN argc, jsval* argv ) jsval CScriptEvent::ToString( JSContext* cx, uintN argc, jsval* argv ) { - utf16_t buffer[256]; + wchar_t buffer[256]; swprintf( buffer, 256, L"[object Event: %ls]", m_Type.c_str() ); buffer[255] = 0; - return( STRING_TO_JSVAL( JS_NewUCStringCopyZ( cx, buffer ) ) ); + utf16string str16=utf16string(buffer, buffer+wcslen(buffer)); + return( STRING_TO_JSVAL( JS_NewUCStringCopyZ( cx, str16.c_str() ) ) ); } diff --git a/source/scripting/JSConversions.cpp b/source/scripting/JSConversions.cpp index 4a68302f5a..1017da5b3e 100755 --- a/source/scripting/JSConversions.cpp +++ b/source/scripting/JSConversions.cpp @@ -197,12 +197,12 @@ template<> bool ToPrimitive( JSContext* cx, jsval v, CStrW& Storage ) template<> jsval ToJSVal( const CStrW& Native ) { - return( STRING_TO_JSVAL( JS_NewUCStringCopyZ( g_ScriptingHost.GetContext(), Native.c_str() ) ) ); + return( STRING_TO_JSVAL( JS_NewUCStringCopyZ( g_ScriptingHost.GetContext(), Native.utf16().c_str() ) ) ); } template<> jsval ToJSVal( CStrW& Native ) { - return( STRING_TO_JSVAL( JS_NewUCStringCopyZ( g_ScriptingHost.GetContext(), Native.c_str() ) ) ); + return( STRING_TO_JSVAL( JS_NewUCStringCopyZ( g_ScriptingHost.GetContext(), Native.utf16().c_str() ) ) ); } // jsval diff --git a/source/scripting/JSConversions.h b/source/scripting/JSConversions.h index ceaf7cfd61..0f22ce2594 100755 --- a/source/scripting/JSConversions.h +++ b/source/scripting/JSConversions.h @@ -115,4 +115,4 @@ template<> jsval ToJSVal( const jsval& Native ); -#endif \ No newline at end of file +#endif diff --git a/source/scripting/ScriptableObject.h b/source/scripting/ScriptableObject.h index 5c04d4bd73..50df4aa545 100755 --- a/source/scripting/ScriptableObject.h +++ b/source/scripting/ScriptableObject.h @@ -164,7 +164,7 @@ template class CJSProperty : public IJSProperty public: CJSProperty( T* Data, IJSObject* Owner = NULL, bool AllowsInheritance = false, IJSObject::NotifyFn Update = NULL, IJSObject::NotifyFn Freshen = NULL ) { - assert( !( !m_Owner && ( Freshen || Update ) ) ); // Bad programmer. + assert( !( !Owner && ( Freshen || Update ) ) ); // Bad programmer. m_Data = Data; m_Owner = Owner; m_AllowsInheritance = AllowsInheritance; @@ -336,7 +336,8 @@ public: static void ScriptingInit( const char* ClassName, JSNative Constructor = NULL, uintN ConstructorMinArgs = 0 ) { JSFunctionSpec* JSI_methods = new JSFunctionSpec[ m_Methods.size() + 1 ]; - for( unsigned int MethodID = 0; MethodID < m_Methods.size(); MethodID++ ) + unsigned int MethodID; + for( MethodID = 0; MethodID < m_Methods.size(); MethodID++ ) JSI_methods[MethodID] = m_Methods[MethodID]; JSI_methods[MethodID].name = 0; diff --git a/source/scripting/ScriptingHost.cpp b/source/scripting/ScriptingHost.cpp index c4ea3deeb7..dff23aa81f 100755 --- a/source/scripting/ScriptingHost.cpp +++ b/source/scripting/ScriptingHost.cpp @@ -327,6 +327,17 @@ CStrW ScriptingHost::ValueToUCString( const jsval value ) return CStrW(std::wstring(strptr, strptr+length)); } +utf16string ScriptingHost::ValueToUTF16( const jsval value ) +{ + JSString* string = JS_ValueToString(m_Context, value); + if (string == NULL) + throw PSERROR_Scripting_ConversionFailed(); + + jschar *strptr=JS_GetStringChars(string); + size_t length=JS_GetStringLength(string); + return utf16string(strptr, strptr+length); +} + jsval ScriptingHost::UCStringToValue(const utf16string &str) { return STRING_TO_JSVAL(JS_NewUCStringCopyZ(m_Context, str.c_str())); diff --git a/source/scripting/ScriptingHost.h b/source/scripting/ScriptingHost.h index 6fa6e0aa75..ba50eaee01 100755 --- a/source/scripting/ScriptingHost.h +++ b/source/scripting/ScriptingHost.h @@ -114,6 +114,7 @@ public: bool ValueToBool(const jsval value); std::string ValueToString(const jsval value); CStrW ValueToUCString( const jsval value ); + utf16string ValueToUTF16( const jsval value ); double ValueToDouble(const jsval value); jsval UCStringToValue(const utf16string &str); diff --git a/source/simulation/BaseEntity.cpp b/source/simulation/BaseEntity.cpp index c1be9d1492..af6395829f 100755 --- a/source/simulation/BaseEntity.cpp +++ b/source/simulation/BaseEntity.cpp @@ -244,7 +244,7 @@ void CBaseEntity::XMLLoadProperty( const CXeromyces& XeroFile, const XMBElement& void CBaseEntity::ScriptingInit() { - AddMethod( "toString", 0 ); + AddMethod( "toString", 0 ); CJSObject::ScriptingInit( "EntityTemplate" ); } @@ -252,8 +252,9 @@ void CBaseEntity::ScriptingInit() jsval CBaseEntity::ToString( JSContext* cx, uintN argc, jsval* argv ) { - utf16_t buffer[256]; + wchar_t buffer[256]; swprintf( buffer, 256, L"[object EntityTemplate: %ls]", m_Tag.c_str() ); buffer[255] = 0; - return( STRING_TO_JSVAL( JS_NewUCStringCopyZ( cx, buffer ) ) ); -} \ No newline at end of file + utf16string str16(buffer, buffer+wcslen(buffer)); + return( STRING_TO_JSVAL( JS_NewUCStringCopyZ( cx, str16.c_str() ) ) ); +} diff --git a/source/simulation/Entity.cpp b/source/simulation/Entity.cpp index 293a8f47af..e890620b4c 100755 --- a/source/simulation/Entity.cpp +++ b/source/simulation/Entity.cpp @@ -25,14 +25,14 @@ CEntity::CEntity( CBaseEntity* base, CVector3D position, float orientation ) m_ahead.x = sin( m_orientation ); m_ahead.y = cos( m_orientation ); - AddProperty( L"template", (CBaseEntity**)&m_base, false, (NotifyFn)loadBase ); + AddProperty( L"template", (CBaseEntity**)&m_base, false, (NotifyFn)&CEntity::loadBase ); AddProperty( L"actions.move.speed", &m_speed ); - AddProperty( L"selected", &m_selected, false, (NotifyFn)checkSelection ); - AddProperty( L"group", &m_grouped, false, (NotifyFn)checkGroup ); - AddProperty( L"extant", &m_extant, false, (NotifyFn)checkExtant ); + AddProperty( L"selected", &m_selected, false, (NotifyFn)&CEntity::checkSelection ); + AddProperty( L"group", &m_grouped, false, (NotifyFn)&CEntity::checkGroup ); + AddProperty( L"extant", &m_extant, false, (NotifyFn)&CEntity::checkExtant ); AddProperty( L"actions.move.turningradius", &m_turningRadius ); - AddProperty( L"position", &m_graphics_position, false, (NotifyFn)teleport ); - AddProperty( L"orientation", &m_graphics_orientation, false, (NotifyFn)reorient ); + AddProperty( L"position", &m_graphics_position, false, (NotifyFn)&CEntity::teleport ); + AddProperty( L"orientation", &m_graphics_orientation, false, (NotifyFn)&CEntity::reorient ); for( int t = 0; t < EVENT_LAST; t++ ) @@ -521,9 +521,9 @@ void CEntity::renderSelectionOutline( float alpha ) void CEntity::ScriptingInit() { - AddMethod( "toString", 0 ); - AddMethod( "order", 1 ); - AddMethod( "orderQueued", 1 ); + AddMethod( "toString", 0 ); + AddMethod( "order", 1 ); + AddMethod( "orderQueued", 1 ); CJSObject::ScriptingInit( "Entity", Construct, 2 ); } @@ -593,10 +593,11 @@ JSBool CEntity::Construct( JSContext* cx, JSObject* obj, unsigned int argc, jsva jsval CEntity::ToString( JSContext* cx, uintN argc, jsval* argv ) { - utf16_t buffer[256]; + wchar_t buffer[256]; swprintf( buffer, 256, L"[object Entity: %ls]", m_base->m_Tag.c_str() ); buffer[255] = 0; - return( STRING_TO_JSVAL( JS_NewUCStringCopyZ( cx, buffer ) ) ); + utf16string str16(buffer, buffer+wcslen(buffer)); + return( STRING_TO_JSVAL( JS_NewUCStringCopyZ( cx, str16.c_str() ) ) ); } bool CEntity::Order( JSContext* cx, uintN argc, jsval* argv, bool Queued ) diff --git a/source/simulation/EntityProperties.cpp b/source/simulation/EntityProperties.cpp index f6fbaa3fac..b603052457 100755 --- a/source/simulation/EntityProperties.cpp +++ b/source/simulation/EntityProperties.cpp @@ -201,4 +201,4 @@ jsval CBoundProperty::tojsval() -*/ \ No newline at end of file +*/ diff --git a/source/simulation/EventHandlers.h b/source/simulation/EventHandlers.h index 7f6961f9b3..9d64965a49 100755 --- a/source/simulation/EventHandlers.h +++ b/source/simulation/EventHandlers.h @@ -30,4 +30,4 @@ class CEventTick : public CScriptEvent public: CEventTick() : CScriptEvent( L"tick", false, EVENT_TICK ) {} }; -#endif \ No newline at end of file +#endif diff --git a/source/simulation/ScriptObject.cpp b/source/simulation/ScriptObject.cpp index 81de82b917..530d977207 100755 --- a/source/simulation/ScriptObject.cpp +++ b/source/simulation/ScriptObject.cpp @@ -81,5 +81,6 @@ void CScriptObject::DispatchEvent( JSObject* Context, CScriptEvent* evt ) void CScriptObject::Compile( CStrW FileNameTag, CStrW FunctionBody ) { const char* argnames[] = { "evt" }; - Function = JS_CompileUCFunction( g_ScriptingHost.GetContext(), NULL, NULL, 1, argnames, FunctionBody, FunctionBody.Length(), (CStr)FileNameTag, 0 ); + utf16string str16=FunctionBody.utf16(); + Function = JS_CompileUCFunction( g_ScriptingHost.GetContext(), NULL, NULL, 1, argnames, str16.c_str(), str16.size(), (CStr)FileNameTag, 0 ); } diff --git a/source/simulation/ScriptObject.h b/source/simulation/ScriptObject.h index 79deab0e1a..2a7388bf83 100755 --- a/source/simulation/ScriptObject.h +++ b/source/simulation/ScriptObject.h @@ -42,4 +42,4 @@ public: void DispatchEvent( JSObject* Context, CScriptEvent* evt ); }; -#endif \ No newline at end of file +#endif diff --git a/source/simulation/scripting/JSInterface_Entity.cpp b/source/simulation/scripting/JSInterface_Entity.cpp index 78012af445..7d60882a7a 100755 --- a/source/simulation/scripting/JSInterface_Entity.cpp +++ b/source/simulation/scripting/JSInterface_Entity.cpp @@ -225,4 +225,4 @@ JSBool JSI_Entity::order( JSContext* cx, JSObject* obj, uintN argc, jsval* argv, } } -*/ \ No newline at end of file +*/