From 695ebeb0efd40663e7588358d5d6cf5cccb1c374 Mon Sep 17 00:00:00 2001 From: kaetemi Date: Sun, 15 Dec 2019 17:11:05 +0800 Subject: [PATCH 1/6] Fix incorrect mutex usage --- code/ryzom/client/src/session_browser.cpp | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/code/ryzom/client/src/session_browser.cpp b/code/ryzom/client/src/session_browser.cpp index e2fa97c6d..6d80c55cb 100644 --- a/code/ryzom/client/src/session_browser.cpp +++ b/code/ryzom/client/src/session_browser.cpp @@ -66,19 +66,17 @@ class CCallbackClientAdaptor : public CNelCallbackClientAdaptor virtual void send(const NLNET::CMessage &buffer, NLNET::TSockId hostid = NLNET::InvalidSockId, bool log = true) { - CAutoMutex mutex1(_Mutex); + CAutoMutex mutex(_Mutex); if (!_PassThrue) { // queue the message for later sending. nldebug("SB: Pushing a buffer into SendQueue (from %u elts)", _SendQueue.size()); - CAutoMutex mutex(_Mutex); _SendQueue.push(buffer); } else { // protect socket because update() can be called in the main thread while send() can be called with passthru=true in the session browser thread (by authenticate() for example) - CAutoMutex mutex(_Mutex); _CallbackClient.send(buffer, hostid, log); } } From 02270e7113ddbe2d1f3306dbc83ec12334f11206 Mon Sep 17 00:00:00 2001 From: kaetemi Date: Mon, 16 Dec 2019 08:47:27 +0800 Subject: [PATCH 2/6] Functions returning a string reference must not be cast to functions returning a string object --- code/nel/include/nel/gui/group_html.h | 2 +- code/nel/include/nel/gui/group_tree.h | 2 +- code/nel/include/nel/gui/interface_element.h | 9 +-- code/nel/include/nel/gui/interface_group.h | 24 +++---- code/nel/include/nel/gui/reflect.h | 66 ++++++++++++++----- code/nel/include/nel/misc/debug.h | 2 +- code/nel/src/gui/group_html.cpp | 2 +- code/nel/src/gui/interface_expr_user_fct.cpp | 6 ++ code/nel/src/gui/interface_link.cpp | 2 + code/nel/src/gui/lua_ihm.cpp | 16 +++++ .../client/src/interface_v3/dbctrl_sheet.h | 16 ++--- .../client/src/interface_v3/group_html_cs.cpp | 2 +- .../client/src/interface_v3/group_html_cs.h | 2 +- .../src/interface_v3/group_html_forum.cpp | 4 +- .../src/interface_v3/group_html_forum.h | 2 +- .../src/interface_v3/group_html_mail.cpp | 4 +- .../client/src/interface_v3/group_html_mail.h | 2 +- .../src/interface_v3/group_html_webig.cpp | 4 +- .../src/interface_v3/group_html_webig.h | 4 +- .../src/interface_v3/group_quick_help.cpp | 2 +- .../src/interface_v3/group_quick_help.h | 2 +- 21 files changed, 115 insertions(+), 60 deletions(-) diff --git a/code/nel/include/nel/gui/group_html.h b/code/nel/include/nel/gui/group_html.h index 392644abb..74c5a0145 100644 --- a/code/nel/include/nel/gui/group_html.h +++ b/code/nel/include/nel/gui/group_html.h @@ -215,7 +215,7 @@ namespace NLGUI // Browser home std::string Home; // Get Home URL - virtual std::string home(); + virtual std::string home() const; // Undo browse: Browse the precedent url browsed. no op if none void browseUndo (); diff --git a/code/nel/include/nel/gui/group_tree.h b/code/nel/include/nel/gui/group_tree.h index 3d3a2d6fd..266e7e23f 100644 --- a/code/nel/include/nel/gui/group_tree.h +++ b/code/nel/include/nel/gui/group_tree.h @@ -181,7 +181,7 @@ namespace NLGUI REFLECT_STRING("AHParamsClose", getAHParamsClose, setAHParamsClose); REFLECT_BOOL("Opened", getOpened, setOpened); REFLECT_BOOL("Show", getShow, setShow); - REFLECT_UCSTRING("Text", getText, setText); + REFLECT_UCSTRING_REF("Text", getText, setText); // lua REFLECT_LUA_METHOD("getNumChildren", luaGetNumChildren); REFLECT_LUA_METHOD("getChild", luaGetChild); diff --git a/code/nel/include/nel/gui/interface_element.h b/code/nel/include/nel/gui/interface_element.h index dbe1ba37e..47025f155 100644 --- a/code/nel/include/nel/gui/interface_element.h +++ b/code/nel/include/nel/gui/interface_element.h @@ -365,10 +365,6 @@ namespace NLGUI void setModulateGlobalColor(bool state) {_ModulateGlobalColor= state;} bool getModulateGlobalColor() const {return _ModulateGlobalColor;} - - void dummySet(sint32 value); - void dummySet(const std::string &value); - // lua methods int luaUpdateCoords(CLuaState &ls); int luaInvalidateCoords(CLuaState &ls); @@ -382,6 +378,11 @@ namespace NLGUI std::string getSizeRefAsString() const; std::string getSizeRefAsString( const sint32 &sizeRef, const sint32 &sizeDivW, const sint32 &sizeDivH ) const; + void dummySet(sint32 value); + void dummySet(const std::string &value); + + public: + // export some properties REFLECT_EXPORT_START(CInterfaceElement, CReflectable) REFLECT_BOOL ("active", getActive, setActive); diff --git a/code/nel/include/nel/gui/interface_group.h b/code/nel/include/nel/gui/interface_group.h index 44c18414e..9f1e5562b 100644 --- a/code/nel/include/nel/gui/interface_group.h +++ b/code/nel/include/nel/gui/interface_group.h @@ -234,18 +234,18 @@ namespace NLGUI REFLECT_LUA_METHOD("dumpSize", luaDumpSize); REFLECT_LUA_METHOD("dumpEltsOrder", luaDumpEltsOrder); REFLECT_LUA_METHOD("dumpGroups", luaDumpGroups); - REFLECT_STRING ("left_click", getLeftClickHandler, setLeftClickHandler); - REFLECT_STRING ("right_click", getRightClickHandler, setRightClickHandler); - REFLECT_STRING ("left_click_params", getLeftClickHandlerParams, setLeftClickHandlerParams); - REFLECT_STRING ("right_click_params", getRightClickHandlerParams, setRightClickHandlerParams); - REFLECT_STRING ("on_active", getOnActiveHandler, setOnActiveHandler); - REFLECT_STRING ("on_active_params", getOnActiveParams, setOnActiveParams); - REFLECT_STRING ("on_deactive", getOnDeactiveHandler, setOnDeactiveHandler); - REFLECT_STRING ("on_deactive_params", getOnDeactiveParams, setOnDeactiveParams); - REFLECT_STRING ("on_enter", getAHOnEnter, setAHOnEnter); - REFLECT_STRING ("on_enter_params", getAHOnEnterParams, setAHOnEnterParams); - REFLECT_STRING ("on_escape", getAHOnEscape, setAHOnEscape); - REFLECT_STRING ("on_escape_params", getAHOnEscapeParams, setAHOnEscapeParams); + REFLECT_STRING_REF ("left_click", getLeftClickHandler, setLeftClickHandler); + REFLECT_STRING_REF ("right_click", getRightClickHandler, setRightClickHandler); + REFLECT_STRING_REF ("left_click_params", getLeftClickHandlerParams, setLeftClickHandlerParams); + REFLECT_STRING_REF ("right_click_params", getRightClickHandlerParams, setRightClickHandlerParams); + REFLECT_STRING_REF ("on_active", getOnActiveHandler, setOnActiveHandler); + REFLECT_STRING_REF ("on_active_params", getOnActiveParams, setOnActiveParams); + REFLECT_STRING_REF ("on_deactive", getOnDeactiveHandler, setOnDeactiveHandler); + REFLECT_STRING_REF ("on_deactive_params", getOnDeactiveParams, setOnDeactiveParams); + REFLECT_STRING_REF ("on_enter", getAHOnEnter, setAHOnEnter); + REFLECT_STRING_REF ("on_enter_params", getAHOnEnterParams, setAHOnEnterParams); + REFLECT_STRING_REF ("on_escape", getAHOnEscape, setAHOnEscape); + REFLECT_STRING_REF ("on_escape_params", getAHOnEscapeParams, setAHOnEscapeParams); REFLECT_SINT32 ("ofsx", getOfsX, setOfsX); REFLECT_SINT32 ("ofsy", getOfsY, setOfsY); REFLECT_BOOL("child_resize_w", getResizeFromChildW, setResizeFromChildW); diff --git a/code/nel/include/nel/gui/reflect.h b/code/nel/include/nel/gui/reflect.h index 9b594a0a5..8bd3b4781 100644 --- a/code/nel/include/nel/gui/reflect.h +++ b/code/nel/include/nel/gui/reflect.h @@ -42,6 +42,8 @@ namespace NLGUI Float, String, UCString, + StringRef, + UCStringRef, RGBA, LuaMethod }; // other types will be added when needed @@ -52,6 +54,8 @@ namespace NLGUI typedef float (CReflectable::* TGetFloat) () const; typedef std::string (CReflectable::* TGetString) () const; typedef ucstring (CReflectable::* TGetUCString) () const; + typedef const std::string & (CReflectable::* TGetStringRef) () const; + typedef const ucstring & (CReflectable::* TGetUCStringRef) () const; typedef NLMISC::CRGBA (CReflectable::* TGetRGBA) () const; // typedef void (CReflectable::* TSetBool) (bool); @@ -75,6 +79,8 @@ namespace NLGUI TGetFloat GetFloat; TGetString GetString; TGetUCString GetUCString; + TGetStringRef GetStringRef; + TGetUCStringRef GetUCStringRef; TGetRGBA GetRGBA; TLuaMethod GetLuaMethod; // lua method can only be obtained, not written ... } GetMethod; @@ -108,7 +114,7 @@ namespace NLGUI public: virtual ~CReflectable() {} virtual const char *getReflectedClassName() const { return "CReflectable"; } - virtual const char *getRflectedParentClassName() const { return ""; } + virtual const char *getReflectedParentClassName() const { return ""; } /** When registering classes, the reflect system will call this function on each class * to know which properties they exports. @@ -211,8 +217,8 @@ namespace NLGUI * Should be placed inside the class */ #define REFLECT_EXPORT_START(className, parentName) \ - virtual const char *getReflectedClassName() const { return #className; } \ - virtual const char *getReflectedParentClassName() const { return #parentName; } \ + virtual const char *getReflectedClassName() const NL_OVERRIDE { return #className; } \ + virtual const char *getReflectedParentClassName() const NL_OVERRIDE { return #parentName; } \ static void getReflectedProperties(TReflectedProperties &props) \ { \ typedef className A; \ @@ -222,6 +228,8 @@ namespace NLGUI typedef float (className::* TGetFloata) () const; \ typedef std::string (className::* TGetStringa) () const; \ typedef ucstring (className::* TGetUCStringa) () const; \ + typedef const std::string & (className::* TGetStringRefa) () const; \ + typedef const ucstring & (className::* TGetUCStringRefa) () const; \ typedef NLMISC::CRGBA (className::* TGetRGBAa) () const; \ typedef void (className::* TSetBoola) (bool); \ typedef void (className::* TSetSInt32a) (sint32); \ @@ -240,8 +248,8 @@ namespace NLGUI CReflectedProperty prop; \ prop.Name = exportName; \ prop.Type = CReflectedProperty::Boolean; \ - prop.GetMethod.GetBool = (CReflectedProperty::TGetBool) (TGetBoola) &A::getMethod; \ - prop.SetMethod.SetBool = (CReflectedProperty::TSetBool) (TSetBoola) &A::setMethod; \ + prop.GetMethod.GetBool = (CReflectedProperty::TGetBool) static_cast(&A::getMethod); \ + prop.SetMethod.SetBool = (CReflectedProperty::TSetBool) static_cast(&A::setMethod); \ props.push_back(prop); \ } @@ -251,8 +259,8 @@ namespace NLGUI CReflectedProperty prop; \ prop.Name = exportName; \ prop.Type = CReflectedProperty::SInt32; \ - prop.GetMethod.GetSInt32 = (CReflectedProperty::TGetSInt32) (TGetSInt32a) &A::getMethod; \ - prop.SetMethod.SetSInt32 = (CReflectedProperty::TSetSInt32) (TSetSInt32a) &A::setMethod; \ + prop.GetMethod.GetSInt32 = (CReflectedProperty::TGetSInt32) static_cast(&A::getMethod); \ + prop.SetMethod.SetSInt32 = (CReflectedProperty::TSetSInt32) static_cast(&A::setMethod); \ props.push_back(prop); \ } @@ -262,8 +270,8 @@ namespace NLGUI CReflectedProperty prop; \ prop.Name = exportName; \ prop.Type = CReflectedProperty::UInt32; \ - prop.GetMethod.GetUInt32 = (CReflectedProperty::TGetUInt32) (TGetUInt32a) &A::getMethod; \ - prop.SetMethod.SetUInt32 = (CReflectedProperty::TSetUInt32) (TSetUInt32a) &A::setMethod; \ + prop.GetMethod.GetUInt32 = (CReflectedProperty::TGetUInt32) static_cast(&A::getMethod); \ + prop.SetMethod.SetUInt32 = (CReflectedProperty::TSetUInt32) static_cast(&A::setMethod); \ props.push_back(prop); \ } @@ -273,8 +281,8 @@ namespace NLGUI CReflectedProperty prop; \ prop.Name = exportName; \ prop.Type = CReflectedProperty::Float; \ - prop.GetMethod.GetFloat = (CReflectedProperty::TGetFloat) (TGetFloata) &A::getMethod; \ - prop.SetMethod.SetFloat = (CReflectedProperty::TSetFloat) (TSetFloata) &A::setMethod; \ + prop.GetMethod.GetFloat = (CReflectedProperty::TGetFloat) static_cast(&A::getMethod); \ + prop.SetMethod.SetFloat = (CReflectedProperty::TSetFloat) static_cast(&A::setMethod); \ props.push_back(prop); \ } @@ -284,8 +292,8 @@ namespace NLGUI CReflectedProperty prop; \ prop.Name = exportName; \ prop.Type = CReflectedProperty::String; \ - prop.GetMethod.GetString = (CReflectedProperty::TGetString) (TGetStringa) &A::getMethod; \ - prop.SetMethod.SetString = (CReflectedProperty::TSetString) (TSetStringa) &A::setMethod; \ + prop.GetMethod.GetString = (CReflectedProperty::TGetString) static_cast(&A::getMethod); \ + prop.SetMethod.SetString = (CReflectedProperty::TSetString) static_cast(&A::setMethod); \ props.push_back(prop); \ } @@ -295,8 +303,30 @@ namespace NLGUI CReflectedProperty prop; \ prop.Name = exportName; \ prop.Type = CReflectedProperty::UCString; \ - prop.GetMethod.GetUCString = (CReflectedProperty::TGetUCString) (TGetUCStringa) &A::getMethod; \ - prop.SetMethod.SetUCString = (CReflectedProperty::TSetUCString) (TSetUCStringa) &A::setMethod; \ + prop.GetMethod.GetUCString = (CReflectedProperty::TGetUCString) static_cast(&A::getMethod); \ + prop.SetMethod.SetUCString = (CReflectedProperty::TSetUCString) static_cast(&A::setMethod); \ + props.push_back(prop); \ + } + + // export a string value, by giving the name of the get and the set method + #define REFLECT_STRING_REF(exportName, getMethod, setMethod) \ + { \ + CReflectedProperty prop; \ + prop.Name = exportName; \ + prop.Type = CReflectedProperty::StringRef; \ + prop.GetMethod.GetStringRef = (CReflectedProperty::TGetStringRef) static_cast(&A::getMethod); \ + prop.SetMethod.SetString = (CReflectedProperty::TSetString) static_cast(&A::setMethod); \ + props.push_back(prop); \ + } + + // export a unicode string value, by giving the name of the get and the set method + #define REFLECT_UCSTRING_REF(exportName, getMethod, setMethod) \ + { \ + CReflectedProperty prop; \ + prop.Name = exportName; \ + prop.Type = CReflectedProperty::UCStringRef; \ + prop.GetMethod.GetUCStringRef = (CReflectedProperty::TGetUCStringRef) static_cast(&A::getMethod); \ + prop.SetMethod.SetUCString = (CReflectedProperty::TSetUCString) static_cast(&A::setMethod); \ props.push_back(prop); \ } @@ -307,8 +337,8 @@ namespace NLGUI CReflectedProperty prop; \ prop.Name = exportName; \ prop.Type = CReflectedProperty::RGBA; \ - prop.GetMethod.GetRGBA = (CReflectedProperty::TGetRGBA) (TGetRGBAa) &A::getMethod; \ - prop.SetMethod.SetRGBA = (CReflectedProperty::TSetRGBA) (TSetRGBAa) &A::setMethod; \ + prop.GetMethod.GetRGBA = (CReflectedProperty::TGetRGBA) static_cast(&A::getMethod); \ + prop.SetMethod.SetRGBA = (CReflectedProperty::TSetRGBA) static_cast(&A::setMethod); \ props.push_back(prop); \ } @@ -318,7 +348,7 @@ namespace NLGUI CReflectedProperty prop; \ prop.Name = exportName; \ prop.Type = CReflectedProperty::LuaMethod; \ - prop.GetMethod.GetLuaMethod = (CReflectedProperty::TLuaMethod) (TLuaMethoda) &A::method; \ + prop.GetMethod.GetLuaMethod = (CReflectedProperty::TLuaMethod) static_cast(&A::method); \ props.push_back(prop); \ } diff --git a/code/nel/include/nel/misc/debug.h b/code/nel/include/nel/misc/debug.h index 68f47af8a..668c2e5a3 100644 --- a/code/nel/include/nel/misc/debug.h +++ b/code/nel/include/nel/misc/debug.h @@ -589,7 +589,7 @@ template inline T type_cast(U o) /** Compile time assertion */ #ifdef NL_ISO_CPP0X_AVAILABLE -# define nlctassert(cond) static_assert(cond, "Compile time assert in "#cond) +# define nlctassert(cond) static_assert((cond), "Compile time assert in "#cond) #else # define nlctassert(cond) (void)sizeof(uint[(cond) ? 1 : 0]) #endif diff --git a/code/nel/src/gui/group_html.cpp b/code/nel/src/gui/group_html.cpp index 2500af967..2e74182c3 100644 --- a/code/nel/src/gui/group_html.cpp +++ b/code/nel/src/gui/group_html.cpp @@ -4318,7 +4318,7 @@ namespace NLGUI // *************************************************************************** - string CGroupHTML::home () + string CGroupHTML::home () const { return Home; } diff --git a/code/nel/src/gui/interface_expr_user_fct.cpp b/code/nel/src/gui/interface_expr_user_fct.cpp index 2b77b143e..d0c687d26 100644 --- a/code/nel/src/gui/interface_expr_user_fct.cpp +++ b/code/nel/src/gui/interface_expr_user_fct.cpp @@ -555,6 +555,12 @@ namespace NLGUI case CReflectedProperty::UCString: result.setUCString ((elem->*(pRP->GetMethod.GetUCString))()); break; + case CReflectedProperty::StringRef: + result.setString ((elem->*(pRP->GetMethod.GetStringRef))()); + break; + case CReflectedProperty::UCStringRef: + result.setUCString ((elem->*(pRP->GetMethod.GetUCStringRef))()); + break; case CReflectedProperty::RGBA: result.setRGBA ((elem->*(pRP->GetMethod.GetRGBA))()); break; diff --git a/code/nel/src/gui/interface_link.cpp b/code/nel/src/gui/interface_link.cpp index 7ae26be5b..966354e10 100644 --- a/code/nel/src/gui/interface_link.cpp +++ b/code/nel/src/gui/interface_link.cpp @@ -106,6 +106,7 @@ namespace NLGUI } break; case CReflectedProperty::String: + case CReflectedProperty::StringRef: if (valueToAffect.toString()) { (destElem.*(property.SetMethod.SetString))(valueToAffect.getString()); @@ -117,6 +118,7 @@ namespace NLGUI } break; case CReflectedProperty::UCString: + case CReflectedProperty::UCStringRef: if (valueToAffect.toString()) { (destElem.*(property.SetMethod.SetUCString))(valueToAffect.getUCString()); diff --git a/code/nel/src/gui/lua_ihm.cpp b/code/nel/src/gui/lua_ihm.cpp index 1438150cf..132f1e4b9 100644 --- a/code/nel/src/gui/lua_ihm.cpp +++ b/code/nel/src/gui/lua_ihm.cpp @@ -1435,6 +1435,20 @@ namespace NLGUI #endif } break; + case CReflectedProperty::UCStringRef: + { + ucstring str = (reflectedObject.*(property.GetMethod.GetUCStringRef))(); + #if LUABIND_VERSION > 600 + luabind::detail::push(ls.getStatePointer(), str); + #else + luabind::object obj(ls.getStatePointer(), str); + obj.pushvalue(); + #endif + } + break; + case CReflectedProperty::StringRef: + ls.push( (reflectedObject.*(property.GetMethod.GetStringRef))() ); + break; case CReflectedProperty::RGBA: { CRGBA color = (reflectedObject.*(property.GetMethod.GetRGBA))(); @@ -1499,6 +1513,7 @@ namespace NLGUI return; } case CReflectedProperty::String: + case CReflectedProperty::StringRef: { std::string val; ls.toString(stackIndex, val); @@ -1506,6 +1521,7 @@ namespace NLGUI return; } case CReflectedProperty::UCString: + case CReflectedProperty::UCStringRef: { ucstring val; // Additionaly return of CInterfaceExpr may be std::string... test std string too diff --git a/code/ryzom/client/src/interface_v3/dbctrl_sheet.h b/code/ryzom/client/src/interface_v3/dbctrl_sheet.h index 1281b1ae8..8b89a91ed 100644 --- a/code/ryzom/client/src/interface_v3/dbctrl_sheet.h +++ b/code/ryzom/client/src/interface_v3/dbctrl_sheet.h @@ -296,14 +296,14 @@ public: REFLECT_SINT32("symbol", getGuildSymbol, setGuildSymbol); REFLECT_BOOL("invert_symbol", getInvertGuildSymbol, setInvertGuildSymbol); REFLECT_BOOL("can_drop", getCanDrop, setCanDrop); - REFLECT_STRING ("left_click", getActionOnLeftClick, setActionOnLeftClick); - REFLECT_STRING ("right_click", getActionOnRightClick, setActionOnRightClick); - REFLECT_STRING ("left_click_params", getParamsOnLeftClick, setParamsOnLeftClick); - REFLECT_STRING ("right_click_params", getParamsOnRightClick, setParamsOnRightClick); - REFLECT_STRING ("on_drop", getActionOnDrop, setActionOnDrop); - REFLECT_STRING ("on_drop_params", getParamsOnDrop, setParamsOnDrop); - REFLECT_STRING ("on_can_drop", getActionOnCanDrop, setActionOnCanDrop); - REFLECT_STRING ("on_can_drop_params", getParamsOnCanDrop, setParamsOnCanDrop); + REFLECT_STRING_REF ("left_click", getActionOnLeftClick, setActionOnLeftClick); + REFLECT_STRING_REF ("right_click", getActionOnRightClick, setActionOnRightClick); + REFLECT_STRING_REF ("left_click_params", getParamsOnLeftClick, setParamsOnLeftClick); + REFLECT_STRING_REF ("right_click_params", getParamsOnRightClick, setParamsOnRightClick); + REFLECT_STRING_REF ("on_drop", getActionOnDrop, setActionOnDrop); + REFLECT_STRING_REF ("on_drop_params", getParamsOnDrop, setParamsOnDrop); + REFLECT_STRING_REF ("on_can_drop", getActionOnCanDrop, setActionOnCanDrop); + REFLECT_STRING_REF ("on_can_drop_params", getParamsOnCanDrop, setParamsOnCanDrop); REFLECT_LUA_METHOD("getDraggedSheet", luaGetDraggedSheet); REFLECT_LUA_METHOD("getItemInfo", luaGetItemInfo); REFLECT_LUA_METHOD("getName", luaGetName); diff --git a/code/ryzom/client/src/interface_v3/group_html_cs.cpp b/code/ryzom/client/src/interface_v3/group_html_cs.cpp index 353410029..ba20123e1 100644 --- a/code/ryzom/client/src/interface_v3/group_html_cs.cpp +++ b/code/ryzom/client/src/interface_v3/group_html_cs.cpp @@ -88,7 +88,7 @@ void CGroupHTMLCS::addHTTPPostParams (SFormFields &formfields, bool /*trustedDom // *************************************************************************** -string CGroupHTMLCS::home () +string CGroupHTMLCS::home () const { return Home; } diff --git a/code/ryzom/client/src/interface_v3/group_html_cs.h b/code/ryzom/client/src/interface_v3/group_html_cs.h index 463bdbc09..76a066e6d 100644 --- a/code/ryzom/client/src/interface_v3/group_html_cs.h +++ b/code/ryzom/client/src/interface_v3/group_html_cs.h @@ -45,7 +45,7 @@ public: // From CGroupHTML virtual void addHTTPGetParams (std::string &url, bool trustedDomain); virtual void addHTTPPostParams (SFormFields &formfields, bool trustedDomain); - virtual std::string home(); + virtual std::string home() const NL_OVERRIDE; private: diff --git a/code/ryzom/client/src/interface_v3/group_html_forum.cpp b/code/ryzom/client/src/interface_v3/group_html_forum.cpp index 79a4574dc..fe218c215 100644 --- a/code/ryzom/client/src/interface_v3/group_html_forum.cpp +++ b/code/ryzom/client/src/interface_v3/group_html_forum.cpp @@ -108,10 +108,10 @@ void CGroupHTMLForum::addHTTPPostParams (SFormFields &formfields, bool /*trusted // *************************************************************************** -string CGroupHTMLForum::home () +string CGroupHTMLForum::home () const { CInterfaceManager *pIM = CInterfaceManager::getInstance(); - NLGUI::CDBManager::getInstance()->getDbProp("UI:VARIABLES:FORUM_UPDATED")->setValue32(0); + NLGUI::CDBManager::getInstance()->getDbProp("UI:VARIABLES:FORUM_UPDATED")->setValue32(0); // FIXME: How is this const?! return Home; } diff --git a/code/ryzom/client/src/interface_v3/group_html_forum.h b/code/ryzom/client/src/interface_v3/group_html_forum.h index 53ab7d675..31e5308be 100644 --- a/code/ryzom/client/src/interface_v3/group_html_forum.h +++ b/code/ryzom/client/src/interface_v3/group_html_forum.h @@ -45,7 +45,7 @@ public: // From CGroupHTML virtual void addHTTPGetParams (std::string &url, bool trustedDomain); virtual void addHTTPPostParams (SFormFields &formfields, bool trustedDomain); - virtual std::string home(); + virtual std::string home() const NL_OVERRIDE; virtual void handle (); private: diff --git a/code/ryzom/client/src/interface_v3/group_html_mail.cpp b/code/ryzom/client/src/interface_v3/group_html_mail.cpp index e351b10ef..8627a8573 100644 --- a/code/ryzom/client/src/interface_v3/group_html_mail.cpp +++ b/code/ryzom/client/src/interface_v3/group_html_mail.cpp @@ -77,10 +77,10 @@ void CGroupHTMLMail::addHTTPPostParams (SFormFields &formfields, bool /*trustedD // *************************************************************************** -string CGroupHTMLMail::home () +string CGroupHTMLMail::home () const { CInterfaceManager *pIM = CInterfaceManager::getInstance(); - NLGUI::CDBManager::getInstance()->getDbProp("UI:VARIABLES:MAIL_WAITING")->setValue32(0); + NLGUI::CDBManager::getInstance()->getDbProp("UI:VARIABLES:MAIL_WAITING")->setValue32(0); // FIXME: How is this const?! return Home; } diff --git a/code/ryzom/client/src/interface_v3/group_html_mail.h b/code/ryzom/client/src/interface_v3/group_html_mail.h index e67a098a4..59cf4c852 100644 --- a/code/ryzom/client/src/interface_v3/group_html_mail.h +++ b/code/ryzom/client/src/interface_v3/group_html_mail.h @@ -45,7 +45,7 @@ public: // From CGroupHTML virtual void addHTTPGetParams (std::string &url, bool trustedDomain); virtual void addHTTPPostParams (SFormFields &formfields, bool trustedDomain); - virtual std::string home(); + virtual std::string home() const NL_OVERRIDE; virtual void handle (); private: diff --git a/code/ryzom/client/src/interface_v3/group_html_webig.cpp b/code/ryzom/client/src/interface_v3/group_html_webig.cpp index 18ab0fc75..985ae3f20 100644 --- a/code/ryzom/client/src/interface_v3/group_html_webig.cpp +++ b/code/ryzom/client/src/interface_v3/group_html_webig.cpp @@ -396,7 +396,7 @@ void CGroupHTMLAuth::addHTTPPostParams (SFormFields &formfields, bool trustedDom // *************************************************************************** -string CGroupHTMLAuth::home () +string CGroupHTMLAuth::home () const { return Home; } @@ -442,7 +442,7 @@ void CGroupHTMLWebIG::addHTTPPostParams (SFormFields &formfields, bool trustedDo // *************************************************************************** -string CGroupHTMLWebIG::home () +string CGroupHTMLWebIG::home () const { return Home; } diff --git a/code/ryzom/client/src/interface_v3/group_html_webig.h b/code/ryzom/client/src/interface_v3/group_html_webig.h index 30ccb5825..a339dd3dc 100644 --- a/code/ryzom/client/src/interface_v3/group_html_webig.h +++ b/code/ryzom/client/src/interface_v3/group_html_webig.h @@ -41,7 +41,7 @@ public: // From CGroupHTML virtual void addHTTPGetParams (std::string &url, bool trustedDomain); virtual void addHTTPPostParams (SFormFields &formfields, bool trustedDomain); - virtual std::string home(); + virtual std::string home() const NL_OVERRIDE; virtual void handle (); private: @@ -63,7 +63,7 @@ public: /// From CGroupHTMLAuth virtual void addHTTPGetParams (std::string &url, bool trustedDomain); virtual void addHTTPPostParams (SFormFields &formfields, bool trustedDomain); - virtual std::string home(); + virtual std::string home() const NL_OVERRIDE; virtual void handle (); private: diff --git a/code/ryzom/client/src/interface_v3/group_quick_help.cpp b/code/ryzom/client/src/interface_v3/group_quick_help.cpp index 48b904398..0b789fccf 100644 --- a/code/ryzom/client/src/interface_v3/group_quick_help.cpp +++ b/code/ryzom/client/src/interface_v3/group_quick_help.cpp @@ -348,7 +348,7 @@ void CGroupQuickHelp::browse (const char *url) // *************************************************************************** -std::string CGroupQuickHelp::home() +std::string CGroupQuickHelp::home() const { string completeURL = getLanguageUrl(Home, ClientCfg.getHtmlLanguageCode()); diff --git a/code/ryzom/client/src/interface_v3/group_quick_help.h b/code/ryzom/client/src/interface_v3/group_quick_help.h index 7843d5de2..0d897d014 100644 --- a/code/ryzom/client/src/interface_v3/group_quick_help.h +++ b/code/ryzom/client/src/interface_v3/group_quick_help.h @@ -53,7 +53,7 @@ private: virtual void beginElement (NLGUI::CHtmlElement &elm); virtual void endBuild (); virtual void browse (const char *url); - virtual std::string home(); + virtual std::string home() const NL_OVERRIDE; // Modify uri with '.html' or '_??.html' ending to have current user language, // If the uri is not found locally, then try "en" as fallback language From d56eab0420ac132f2ec52e101731c64ac7ed8700 Mon Sep 17 00:00:00 2001 From: kaetemi Date: Mon, 16 Dec 2019 09:59:49 +0800 Subject: [PATCH 3/6] CObjectNumber for Lua interop needs to deal with both double and sint64 types, cannot have separate CObjectInteger type --- .../client/src/r2/dmc/com_lua_module.cpp | 2 +- code/ryzom/common/src/game_share/object.cpp | 267 +++++++----------- code/ryzom/common/src/game_share/object.h | 82 ++---- 3 files changed, 136 insertions(+), 215 deletions(-) diff --git a/code/ryzom/client/src/r2/dmc/com_lua_module.cpp b/code/ryzom/client/src/r2/dmc/com_lua_module.cpp index 7a3fb94fc..18ecbe011 100644 --- a/code/ryzom/client/src/r2/dmc/com_lua_module.cpp +++ b/code/ryzom/client/src/r2/dmc/com_lua_module.cpp @@ -1245,7 +1245,7 @@ CObject* CComLuaModule::getObjectFromLua(lua_State* state, sint idx) { sint64 value = lua_tointeger(state, -1); lua_pop(state, 1); - return new CObjectInteger(value); + return new CObjectNumber(value); } else #endif diff --git a/code/ryzom/common/src/game_share/object.cpp b/code/ryzom/common/src/game_share/object.cpp index 97794b812..c8e238107 100644 --- a/code/ryzom/common/src/game_share/object.cpp +++ b/code/ryzom/common/src/game_share/object.cpp @@ -175,12 +175,6 @@ void CObject::inPlaceCopy(const CObjectNumber &src) copyMismatchMsg(src); } -void CObject::inPlaceCopy(const CObjectInteger &src) -{ - //H_AUTO(R2_CObject_inPlaceCopy) - copyMismatchMsg(src); -} - void CObject::inPlaceCopy(const CObjectTable &src) { //H_AUTO(R2_CObject_inPlaceCopy) @@ -764,7 +758,15 @@ void CObjectRefId::doSerialize(std::string& out, CSerializeContext& /* context //----------------------- CObjectNumber ---------------------------------------- -CObjectNumber::CObjectNumber(double value) : CObject(), _Value(value){} +CObjectNumber::CObjectNumber(double value) : CObject(), m_IsInteger(false) +{ + m_Value.Integer = value; +} + +CObjectNumber::CObjectNumber(sint64 value) : CObject(), m_IsInteger(true) +{ + m_Value.Integer = value; +} const char *CObjectNumber::getTypeAsString() const { @@ -787,185 +789,137 @@ void CObjectNumber::inPlaceCopyTo(CObject &dest) const void CObjectNumber::inPlaceCopy(const CObjectNumber &src) { //H_AUTO(R2_CObjectNumber_inPlaceCopy) - _Value = src._Value; + m_IsInteger = src.m_IsInteger; + m_Value.Integer = src.m_Value.Integer; setGhost(src.getGhost()); } -std::string CObjectNumber::doToString() const { return NLMISC::toString("%lf", _Value);} +std::string CObjectNumber::doToString() const { return m_IsInteger ? NLMISC::toString(m_Value.Integer) : NLMISC::toString("%lf", m_Value.Number);} void CObjectNumber::doSerialize(std::string& out, CSerializeContext& /* context */) const { //H_AUTO(R2_CObjectNumber_doSerialize) nlassert(!getGhost()); - //out.precision(15); - std::string value = NLMISC::toString(double(sint64(_Value * 1000.0 + (_Value>=0.0?0.5:-0.5)))/1000.0); - // search for first not 0 value from the end - std::string::size_type pos = value.find_last_not_of('0'); - if (pos != std::string::npos) + if (m_IsInteger) + { + out += NLMISC::toString(m_Value.Integer); + } + else { - // don't remove character at pos if it's another digit - if (value[pos] != '.') ++pos; - value.erase(pos); + //out.precision(15); + double num = getNumberValue(); + // TODO: WTF is this for?! + std::string value = NLMISC::toString(double(sint64(num * 1000.0 + (num>=0.0?0.5:-0.5)))/1000.0); + // search for first not 0 value from the end + std::string::size_type pos = value.find_last_not_of('0'); + if (pos != std::string::npos) + { + // don't remove character at pos if it's another digit + if (value[pos] != '.') ++pos; + value.erase(pos); + } + out += value; } - out += value; } -bool CObjectNumber::set(const std::string& key, double value) +bool CObjectNumber::set(const std::string& key, sint64 value) { //H_AUTO(R2_CObjectNumber_set) BOMB_IF(!key.empty(), "Try to set an element of a table on an object that is not a table", return false); - _Value = value; + m_IsInteger = true; + m_Value.Integer = value; return true; } +bool CObjectNumber::set(const std::string& key, double value) +{ + //H_AUTO(R2_CObjectNumber_set) + + BOMB_IF(!key.empty(), "Try to set an element of a table on an object that is not a table", return false); + + m_IsInteger = false; + m_Value.Number = value; + return true; +} bool CObjectNumber::set(const std::string& key, const std::string & value) { //H_AUTO(R2_CObjectNumber_set) //XXX BOMB_IF(!key.empty(), "Try to set an element of a table on an object that is not a table", return false); - NLMISC::fromString(value, _Value); - return true; + double num; + sint64 i; + if (NLMISC::fromString(value, num)) + { + m_IsInteger = false; + m_Value.Number = num; + } + if (NLMISC::fromString(value, i)) + { + m_IsInteger = true; + m_Value.Number = i; + } + return false; } - -double CObjectNumber::doToNumber() const { return _Value; } - CObject* CObjectNumber::clone() const { //H_AUTO(R2_CObjectNumber_clone) - CObjectNumber *result = new CObjectNumber(_Value); + CObjectNumber *result = m_IsInteger + ? new CObjectNumber(m_Value.Integer) + : new CObjectNumber(m_Value.Number); result->setGhost(getGhost()); return result; } -bool CObjectNumber::doIsNumber() const { return true;} +bool CObjectNumber::doIsNumber() const { return !m_IsInteger || (sint64)getNumberValue() == m_Value.Integer;} + +double CObjectNumber::doToNumber() const { return getNumberValue(); } +bool CObjectNumber::doIsInteger() const { return m_IsInteger || (double)getIntegerValue() == m_Value.Number;} +sint64 CObjectNumber::doToInteger() const { return getIntegerValue(); } bool CObjectNumber::setObject(const std::string& /* key */, CObject* value) { //H_AUTO(R2_CObjectNumber_setObject) - BOMB_IF(!value->isNumber(), NLMISC::toString("Try to set an element of a type '%s' with a value of type '%s' on an object that is not a number", this->getTypeAsString(), value->getTypeAsString()), return false); + BOMB_IF(!value->isNumber() && !value->isInteger(), NLMISC::toString("Try to set an element of a type '%s' with a value of type '%s' on an object that is not a number", this->getTypeAsString(), value->getTypeAsString()), return false); - _Value = value->toNumber(); + if (value->isInteger()) + { + m_IsInteger = true; + m_Value.Integer = value->toInteger(); + } + else + { + m_IsInteger = false; + m_Value.Number = value->toNumber(); + } setGhost(value->getGhost()); return true; } - - bool CObjectNumber::equal(const CObject* other) const { - //H_AUTO(R2_CObjectNumber_equal) - if (!other || !other->isNumber()) return false; + if (!other) return false; + if (isInteger()) + { + if (!other->isInteger()) return false; + return (getIntegerValue() == other->toInteger()); + } + + if (!other->isNumber()) return false; + double value = getNumberValue(); double otherValue = other->toNumber(); - if (_Value == otherValue) return true; + if (value == otherValue) return true; // if difference between 2 values less than epsilon, we consider they are equals - return fabs(_Value - otherValue) <= std::numeric_limits::epsilon(); + return fabs(value - otherValue) <= std::numeric_limits::epsilon(); } - -//----------------------- CObjectInteger ---------------------------------------- - - -CObjectInteger::CObjectInteger(sint64 value) : CObject(), _Value(value){} - -const char *CObjectInteger::getTypeAsString() const -{ - return "Integer"; -} - -void CObjectInteger::visitInternal(IObjectVisitor &visitor) -{ - //H_AUTO(R2_CObjectInteger_visit) - visitor.visit(*this); -} - - -void CObjectInteger::inPlaceCopyTo(CObject &dest) const -{ - //H_AUTO(R2_CObjectInteger_inPlaceCopyTo) - dest.inPlaceCopy(*this); -} - -void CObjectInteger::inPlaceCopy(const CObjectInteger &src) -{ - //H_AUTO(R2_CObjectInteger_inPlaceCopy) - _Value = src._Value; - setGhost(src.getGhost()); -} - - -std::string CObjectInteger::doToString() const { return NLMISC::toString(_Value); } - -void CObjectInteger::doSerialize(std::string& out, CSerializeContext& /* context */) const -{ - //H_AUTO(R2_CObjectInteger_doSerialize) - nlassert(!getGhost()); - out += NLMISC::toString(_Value); -} - -bool CObjectInteger::set(const std::string& key, sint64 value) -{ - //H_AUTO(R2_CObjectInteger_set) - - BOMB_IF(!key.empty(), "Try to set an element of a table on an object that is not a table", return false); - - _Value = value; - return true; -} - - -bool CObjectInteger::set(const std::string& key, const std::string & value) -{ - //H_AUTO(R2_CObjectInteger_set) - //XXX - BOMB_IF(!key.empty(), "Try to set an element of a table on an object that is not a table", return false); - NLMISC::fromString(value, _Value); - return true; -} - - -sint64 CObjectInteger::doToInteger() const { return _Value; } - -CObject* CObjectInteger::clone() const -{ - //H_AUTO(R2_CObjectInteger_clone) - CObjectInteger *result = new CObjectInteger(_Value); - result->setGhost(getGhost()); - return result; -} - -bool CObjectInteger::doIsInteger() const { return true;} - - - -bool CObjectInteger::setObject(const std::string& /* key */, CObject* value) -{ - //H_AUTO(R2_CObjectInteger_setObject) - BOMB_IF(!value->isInteger(), NLMISC::toString("Try to set an element of a type '%s' with a value of type '%s' on an object that is not an integer", this->getTypeAsString(), value->getTypeAsString()), return false); - - _Value = value->toInteger(); - setGhost(value->getGhost()); - return true; -} - - - -bool CObjectInteger::equal(const CObject* other) const -{ - //H_AUTO(R2_CObjectInteger_equal) - if (!other || !other->isInteger()) return false; - sint64 otherValue = other->toInteger(); - return _Value == otherValue; -} - - //----------------------- CObjectTable ---------------------------------------- @@ -1686,7 +1640,7 @@ CObject* CObjectFactory::newBasic(const std::string & type) } else if (type == "Number") { - return new CObjectNumber(0); + return new CObjectNumber((sint64)0); } else if (type == "Table") { @@ -1976,15 +1930,10 @@ void CObjectNumber::dump(const std::string prefix, uint depth) const { //H_AUTO(R2_CObjectNumber_dump) std::string result(depth * 4, ' '); - result += NLMISC::toString("%sNumber, ptr = 0x%p, value = %lf, ghost = %s", prefix.c_str(), this, _Value, _Ghost ? "true" : "false"); - nlwarning(result.c_str()); -} - -void CObjectInteger::dump(const std::string prefix, uint depth) const -{ - //H_AUTO(R2_CObjectInteger_dump) - std::string result(depth * 4, ' '); - result += NLMISC::toString("%sInteger, ptr = 0x%p, value = %" NL_I64 "d, ghost = %s", prefix.c_str(), this, _Value, _Ghost ? "true" : "false"); + if (m_IsInteger) + result += NLMISC::toString("%sNumber, ptr = 0x%p, isNumber, value = %lf, ghost = %s", prefix.c_str(), this, m_Value.Integer, _Ghost ? "true" : "false"); + else + result += NLMISC::toString("%sNumber, ptr = 0x%p, isInteger, value = %lf, ghost = %s", prefix.c_str(), this, m_Value.Number, _Ghost ? "true" : "false"); nlwarning(result.c_str()); } @@ -3330,13 +3279,13 @@ void CObjectSerializerImpl::serialImpl(NLMISC::IStream& stream, CObject*& data, { double value; stream.serial(value); - data = serializer->Factory ? serializer->Factory->newBasic("Number") : new CObjectNumber(0); + data = serializer->Factory ? serializer->Factory->newBasic("Number") : new CObjectNumber((sint64)0); ((CObjectNumber *) data)->set("", value); return; } case ObjectNumberZero: { - data = serializer->Factory ? serializer->Factory->newBasic("Number") : new CObjectNumber(0); + data = serializer->Factory ? serializer->Factory->newBasic("Number") : new CObjectNumber((sint64)0); ((CObjectNumber *) data)->set("", 0.0); return; } @@ -3344,8 +3293,8 @@ void CObjectSerializerImpl::serialImpl(NLMISC::IStream& stream, CObject*& data, { sint32 value; stream.serial(value); - data = serializer->Factory ? serializer->Factory->newBasic("Number") : new CObjectNumber(0); - ((CObjectNumber *) data)->set("", value); + data = serializer->Factory ? serializer->Factory->newBasic("Number") : new CObjectNumber((sint64)0); + ((CObjectNumber *) data)->set("", (sint64)value); return; } @@ -3353,8 +3302,8 @@ void CObjectSerializerImpl::serialImpl(NLMISC::IStream& stream, CObject*& data, { uint32 value; stream.serial(value); - data = serializer->Factory ? serializer->Factory->newBasic("Number") : new CObjectNumber(0); - ((CObjectNumber *) data)->set("", value); + data = serializer->Factory ? serializer->Factory->newBasic("Number") : new CObjectNumber((sint64)0); + ((CObjectNumber *) data)->set("", (sint64)value); return; } @@ -3362,8 +3311,8 @@ void CObjectSerializerImpl::serialImpl(NLMISC::IStream& stream, CObject*& data, { sint16 value; stream.serial(value); - data = serializer->Factory ? serializer->Factory->newBasic("Number") : new CObjectNumber(0); - ((CObjectNumber *) data)->set("", value); + data = serializer->Factory ? serializer->Factory->newBasic("Number") : new CObjectNumber((sint64)0); + ((CObjectNumber *) data)->set("", (sint64)value); return; } @@ -3371,8 +3320,8 @@ void CObjectSerializerImpl::serialImpl(NLMISC::IStream& stream, CObject*& data, { uint16 value; stream.serial(value); - data = serializer->Factory ? serializer->Factory->newBasic("Number") : new CObjectNumber(0); - ((CObjectNumber *) data)->set("", value); + data = serializer->Factory ? serializer->Factory->newBasic("Number") : new CObjectNumber((sint64)0); + ((CObjectNumber *) data)->set("", (sint64)value); return; } @@ -3380,8 +3329,8 @@ void CObjectSerializerImpl::serialImpl(NLMISC::IStream& stream, CObject*& data, { sint8 value; stream.serial(value); - data = serializer->Factory ? serializer->Factory->newBasic("Number") : new CObjectNumber(0); - ((CObjectNumber *) data)->set("", value); + data = serializer->Factory ? serializer->Factory->newBasic("Number") : new CObjectNumber((sint64)0); + ((CObjectNumber *) data)->set("", (sint64)value); return; } @@ -3389,8 +3338,8 @@ void CObjectSerializerImpl::serialImpl(NLMISC::IStream& stream, CObject*& data, { uint8 value; stream.serial(value); - data = serializer->Factory ? serializer->Factory->newBasic("Number") : new CObjectNumber(0); - ((CObjectNumber *) data)->set("", value); + data = serializer->Factory ? serializer->Factory->newBasic("Number") : new CObjectNumber((sint64)0); + ((CObjectNumber *) data)->set("", (sint64)value); return; } // Do not remove this or it would be impossible to load old session @@ -3398,8 +3347,8 @@ void CObjectSerializerImpl::serialImpl(NLMISC::IStream& stream, CObject*& data, { float value; stream.serial(value); - data = serializer->Factory ? serializer->Factory->newBasic("Number") : new CObjectNumber(0); - ((CObjectNumber *) data)->set("", value); + data = serializer->Factory ? serializer->Factory->newBasic("Number") : new CObjectNumber((sint64)0); + ((CObjectNumber *) data)->set("", (double)value); return; } @@ -3407,7 +3356,7 @@ void CObjectSerializerImpl::serialImpl(NLMISC::IStream& stream, CObject*& data, { double value; stream.serial(value); - data = serializer->Factory ? serializer->Factory->newBasic("Number") : new CObjectNumber(0); + data = serializer->Factory ? serializer->Factory->newBasic("Number") : new CObjectNumber((sint64)0); ((CObjectNumber *) data)->set("", value); return; } diff --git a/code/ryzom/common/src/game_share/object.h b/code/ryzom/common/src/game_share/object.h index 7d4ab1f49..806d790aa 100644 --- a/code/ryzom/common/src/game_share/object.h +++ b/code/ryzom/common/src/game_share/object.h @@ -206,7 +206,6 @@ public: virtual void inPlaceCopyTo(CObject &dest) const = 0; virtual void inPlaceCopy(const CObjectString &src); virtual void inPlaceCopy(const CObjectNumber &src); - virtual void inPlaceCopy(const CObjectInteger &src); virtual void inPlaceCopy(const CObjectTable &src); protected: void copyMismatchMsg(const CObject &src); @@ -287,78 +286,51 @@ class CObjectNumber : public CObject public: explicit CObjectNumber(double value); + explicit CObjectNumber(sint64 value); - virtual const char *getTypeAsString() const; + virtual const char *getTypeAsString() const NL_OVERRIDE; - virtual bool set(const std::string& key, double value); - virtual bool set(const std::string& key, const std::string&value); + virtual bool set(const std::string& key, sint64 value) NL_OVERRIDE; + virtual bool set(const std::string& key, double value) NL_OVERRIDE; + virtual bool set(const std::string& key, const std::string&value) NL_OVERRIDE; - virtual bool setObject(const std::string& key, CObject* value); + virtual bool setObject(const std::string& key, CObject* value) NL_OVERRIDE; - virtual CObject* clone() const; + virtual CObject* clone() const NL_OVERRIDE; - double getValue() const { return _Value; } + double getNumberValue() const { return m_IsInteger ? m_Value.Integer : m_Value.Number; } + sint64 getIntegerValue() const { return m_IsInteger ? m_Value.Integer : m_Value.Number; } - virtual void dump(const std::string prefix = "", uint depth = 0) const; + virtual void dump(const std::string prefix = "", uint depth = 0) const NL_OVERRIDE; - virtual bool equal(const CObject* other) const; + virtual bool equal(const CObject* other) const NL_OVERRIDE; protected: - virtual void doSerialize(std::string& out, CSerializeContext& context) const; - - virtual bool doIsNumber() const; - - virtual double doToNumber() const; - - virtual std::string doToString() const; - - virtual void inPlaceCopyTo(CObject &dest) const; - virtual void inPlaceCopy(const CObjectNumber &src); + virtual void doSerialize(std::string& out, CSerializeContext& context) const NL_OVERRIDE; - virtual void visitInternal(IObjectVisitor &visitor); + virtual bool doIsNumber() const NL_OVERRIDE; -private: - double _Value; + virtual double doToNumber() const NL_OVERRIDE; -}; + virtual bool doIsInteger() const NL_OVERRIDE; -class CObjectInteger : public CObject -{ + virtual sint64 doToInteger() const NL_OVERRIDE; -public: - explicit CObjectInteger(sint64 value); + virtual std::string doToString() const NL_OVERRIDE; - virtual const char *getTypeAsString() const; + virtual void inPlaceCopyTo(CObject &dest) const NL_OVERRIDE; + virtual void inPlaceCopy(const CObjectNumber &src) NL_OVERRIDE; - virtual bool set(const std::string& key, sint64 value); - virtual bool set(const std::string& key, const std::string &value); - - virtual bool setObject(const std::string& key, CObject* value); - - virtual CObject* clone() const; - - sint64 getValue() const { return _Value; } - - virtual void dump(const std::string prefix = "", uint depth = 0) const; - - virtual bool equal(const CObject* other) const; - -protected: - virtual void doSerialize(std::string& out, CSerializeContext& context) const; - - virtual bool doIsInteger() const; - - virtual sint64 doToInteger() const; - - virtual std::string doToString() const; - - virtual void inPlaceCopyTo(CObject &dest) const; - virtual void inPlaceCopy(const CObjectInteger &src); - - virtual void visitInternal(IObjectVisitor &visitor); + virtual void visitInternal(IObjectVisitor &visitor) NL_OVERRIDE; private: - sint64 _Value; + bool m_IsInteger; + union + { + double Number; + sint64 Integer; + } m_Value; + }; class CObjectTable: public CObject From bddbed9da2bd192d7e59c200e3a2af9df0d183fc Mon Sep 17 00:00:00 2001 From: kaetemi Date: Mon, 16 Dec 2019 10:14:11 +0800 Subject: [PATCH 4/6] Sanity check for Lua integer size --- code/ryzom/client/src/r2/dmc/com_lua_module.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/code/ryzom/client/src/r2/dmc/com_lua_module.cpp b/code/ryzom/client/src/r2/dmc/com_lua_module.cpp index 18ecbe011..c717b2cba 100644 --- a/code/ryzom/client/src/r2/dmc/com_lua_module.cpp +++ b/code/ryzom/client/src/r2/dmc/com_lua_module.cpp @@ -1243,6 +1243,7 @@ CObject* CComLuaModule::getObjectFromLua(lua_State* state, sint idx) #if LUA_VERSION_NUM >= 503 if (lua_isinteger(state, -1) != 0) { + nlctassert(sizeof(lua_Integer) == sizeof(sint64)); sint64 value = lua_tointeger(state, -1); lua_pop(state, 1); return new CObjectNumber(value); @@ -1250,6 +1251,7 @@ CObject* CComLuaModule::getObjectFromLua(lua_State* state, sint idx) else #endif { + nlctassert(sizeof(lua_Number) == sizeof(double)); double value = lua_tonumber(state, -1); lua_pop(state, 1); return new CObjectNumber(value); From 2cdfc0ce29a4c094f9e0cd9a8d7d1983e72aa4c5 Mon Sep 17 00:00:00 2001 From: kaetemi Date: Mon, 16 Dec 2019 10:26:22 +0800 Subject: [PATCH 5/6] CObjectNumber for Lua interop needs to deal with both double and sint64 types, cannot have separate CObjectInteger type --- code/ryzom/common/src/game_share/object.cpp | 22 ++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/code/ryzom/common/src/game_share/object.cpp b/code/ryzom/common/src/game_share/object.cpp index c8e238107..4b12cf3ea 100644 --- a/code/ryzom/common/src/game_share/object.cpp +++ b/code/ryzom/common/src/game_share/object.cpp @@ -801,9 +801,9 @@ void CObjectNumber::doSerialize(std::string& out, CSerializeContext& /* context { //H_AUTO(R2_CObjectNumber_doSerialize) nlassert(!getGhost()); - if (m_IsInteger) + if (doIsInteger()) { - out += NLMISC::toString(m_Value.Integer); + out += NLMISC::toString(getIntegerValue()); } else { @@ -852,15 +852,20 @@ bool CObjectNumber::set(const std::string& key, const std::string & value) BOMB_IF(!key.empty(), "Try to set an element of a table on an object that is not a table", return false); double num; sint64 i; + if (NLMISC::fromString(value, i)) + { + if (NLMISC::toString(i) == value) + { + m_IsInteger = true; + m_Value.Integer = i; + return true; + } + } if (NLMISC::fromString(value, num)) { m_IsInteger = false; m_Value.Number = num; - } - if (NLMISC::fromString(value, i)) - { - m_IsInteger = true; - m_Value.Number = i; + return true; } return false; } @@ -905,9 +910,8 @@ bool CObjectNumber::setObject(const std::string& /* key */, CObject* value) bool CObjectNumber::equal(const CObject* other) const { if (!other) return false; - if (isInteger()) + if (isInteger() && other->isInteger()) { - if (!other->isInteger()) return false; return (getIntegerValue() == other->toInteger()); } From ae68ce722e0cba79b709838a3ff2fa38d306c484 Mon Sep 17 00:00:00 2001 From: kaetemi Date: Mon, 16 Dec 2019 11:50:15 +0800 Subject: [PATCH 6/6] Various fixes or adjustments --- code/nel/include/nel/3d/texture.h | 3 ++- code/ryzom/client/src/r2/dmc/com_lua_module.cpp | 2 +- code/ryzom/common/src/game_share/object.cpp | 2 +- 3 files changed, 4 insertions(+), 3 deletions(-) diff --git a/code/nel/include/nel/3d/texture.h b/code/nel/include/nel/3d/texture.h index bd71a00fd..f74af29d9 100644 --- a/code/nel/include/nel/3d/texture.h +++ b/code/nel/include/nel/3d/texture.h @@ -106,7 +106,8 @@ public: class ITexture : public CBitmap, public NLMISC::CRefCount, public NLMISC::IStreamable { public: -// NL_USES_DEFAULT_ARENA_OBJECT_ALLOCATOR // for fast alloc + // TODO: FIX: NL_USES_DEFAULT_ARENA_OBJECT_ALLOCATOR // for fast alloc + // Those enums MUST be the same than in UTexture!! enum TWrapMode { diff --git a/code/ryzom/client/src/r2/dmc/com_lua_module.cpp b/code/ryzom/client/src/r2/dmc/com_lua_module.cpp index c717b2cba..2ea3d91dd 100644 --- a/code/ryzom/client/src/r2/dmc/com_lua_module.cpp +++ b/code/ryzom/client/src/r2/dmc/com_lua_module.cpp @@ -1261,7 +1261,7 @@ CObject* CComLuaModule::getObjectFromLua(lua_State* state, sint idx) case LUA_TBOOLEAN: { - double value = static_cast(lua_toboolean(state, -1)); + sint64 value = lua_toboolean(state, -1); lua_pop(state, 1); return new CObjectNumber(value); } diff --git a/code/ryzom/common/src/game_share/object.cpp b/code/ryzom/common/src/game_share/object.cpp index 4b12cf3ea..c9315997f 100644 --- a/code/ryzom/common/src/game_share/object.cpp +++ b/code/ryzom/common/src/game_share/object.cpp @@ -760,7 +760,7 @@ void CObjectRefId::doSerialize(std::string& out, CSerializeContext& /* context CObjectNumber::CObjectNumber(double value) : CObject(), m_IsInteger(false) { - m_Value.Integer = value; + m_Value.Number = value; } CObjectNumber::CObjectNumber(sint64 value) : CObject(), m_IsInteger(true)