From 465a36b250e8445bf14564184e8ae3f56d36ead0 Mon Sep 17 00:00:00 2001 From: Nimetu Date: Tue, 3 Nov 2020 22:28:58 +0200 Subject: [PATCH 01/12] fix build --- ryzom/client/src/interface_v3/sphrase_manager.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ryzom/client/src/interface_v3/sphrase_manager.cpp b/ryzom/client/src/interface_v3/sphrase_manager.cpp index 94f2b3d84..d03b71411 100644 --- a/ryzom/client/src/interface_v3/sphrase_manager.cpp +++ b/ryzom/client/src/interface_v3/sphrase_manager.cpp @@ -4696,8 +4696,8 @@ int CSPhraseComAdpater::luaGetDesc(CLuaState &ls) if (*desc) { #ifdef RYZOM_LUA_UCSTRING - ucstring desc = ucstring::makeFromUtf8(desc); // Compatibility - CLuaIHM::push(ls, desc); + ucstring uc = ucstring::makeFromUtf8(desc); // Compatibility + CLuaIHM::push(ls, uc); #else ls.push(desc); #endif From b220dac7b3640566715b53a92f13809cc28bd425 Mon Sep 17 00:00:00 2001 From: kaetemi Date: Tue, 3 Nov 2020 13:55:06 +0800 Subject: [PATCH 02/12] Fix memory release --- nel/include/nel/gui/action_handler.h | 15 ++++++++++++++- nel/src/gui/action_handler.cpp | 2 ++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/nel/include/nel/gui/action_handler.h b/nel/include/nel/gui/action_handler.h index 7288c9529..5bdad89ba 100644 --- a/nel/include/nel/gui/action_handler.h +++ b/nel/include/nel/gui/action_handler.h @@ -69,7 +69,7 @@ namespace NLGUI static CAHManager* getInstance() { - if (_GlobalInstance == NULL) + if (_GlobalInstance == NULL && !s_Deleted) _GlobalInstance = new CAHManager; return _GlobalInstance; } @@ -134,6 +134,19 @@ namespace NLGUI static CAHManager *_GlobalInstance; static bool editorMode; + class CDeleter + { + public: + ~CDeleter() + { + delete _GlobalInstance; + _GlobalInstance = NULL; + s_Deleted = true; + } + }; + static CDeleter s_Deleter; + static bool s_Deleted; + }; /// Ah name must all be lower case diff --git a/nel/src/gui/action_handler.cpp b/nel/src/gui/action_handler.cpp index f7a5f2cee..601175361 100644 --- a/nel/src/gui/action_handler.cpp +++ b/nel/src/gui/action_handler.cpp @@ -42,6 +42,8 @@ namespace NLGUI // ------------------------------------------------------------------------------------------------ CAHManager *CAHManager::_GlobalInstance = NULL; bool CAHManager::editorMode = false; + CAHManager::CDeleter CAHManager::s_Deleter; + bool CAHManager::s_Deleted = false; // ------------------------------------------------------------------------------------------------ // ------------------------------------------------------------------------------------------------ From f50b59702e7698cdbf6073be2ba8fda9d1ba3bb9 Mon Sep 17 00:00:00 2001 From: kaetemi Date: Tue, 3 Nov 2020 13:55:12 +0800 Subject: [PATCH 03/12] Fix memory release --- ryzom/client/src/string_manager_client.h | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/ryzom/client/src/string_manager_client.h b/ryzom/client/src/string_manager_client.h index e3cd736fd..ef55b0367 100644 --- a/ryzom/client/src/string_manager_client.h +++ b/ryzom/client/src/string_manager_client.h @@ -46,6 +46,7 @@ class CStringManagerClient public: // Singleton pattern implementation static CStringManagerClient *instance(); + static bool hasInstance() { return _Instance; } static void release(bool mustReleaseStaticArrays); /** Prepare the string manager to use a persistent string cache. @@ -388,7 +389,8 @@ public: virtual ~IStringWaiterRemover() { // signal the string manager that this waiter is destroyed - CStringManagerClient::instance()->removeStringWaiter(this); + if (CStringManagerClient::hasInstance()) + CStringManagerClient::instance()->removeStringWaiter(this); } }; @@ -406,7 +408,8 @@ public: virtual ~IStringWaitCallback() { // signal the string manager that this waiter is destroyed - CStringManagerClient::instance()->removeStringWaiter(this); + if (CStringManagerClient::hasInstance()) + CStringManagerClient::instance()->removeStringWaiter(this); } }; From 0ba45054d0e975bd19b2bebdc810189a2302137e Mon Sep 17 00:00:00 2001 From: kaetemi Date: Tue, 3 Nov 2020 14:34:25 +0800 Subject: [PATCH 04/12] Fix memory release --- nel/include/nel/georges/form.h | 5 +++++ nel/include/nel/georges/form_elm.h | 8 ++++++++ nel/src/georges/form.cpp | 3 +++ nel/src/georges/form_elm.cpp | 10 ++++++---- nel/src/georges/form_loader.cpp | 2 +- nel/src/sound/audio_mixer_user.cpp | 1 + 6 files changed, 24 insertions(+), 5 deletions(-) diff --git a/nel/include/nel/georges/form.h b/nel/include/nel/georges/form.h index 9b21c4c49..732a45840 100644 --- a/nel/include/nel/georges/form.h +++ b/nel/include/nel/georges/form.h @@ -22,6 +22,7 @@ #include "nel/misc/types_nl.h" #include "nel/georges/u_form.h" +#include "form_dfn.h" #include "form_elm.h" #include "header.h" @@ -124,6 +125,10 @@ private: // The form filename std::string _Filename; + + // The dfn + NLMISC::CSmartPtr _Dfn; + }; } // NLGEORGES diff --git a/nel/include/nel/georges/form_elm.h b/nel/include/nel/georges/form_elm.h index 6795ad328..f94d9842c 100644 --- a/nel/include/nel/georges/form_elm.h +++ b/nel/include/nel/georges/form_elm.h @@ -282,6 +282,10 @@ public: { Element = NULL; } + ~CFormElmStructElm() + { + nlassert(!Element); + } std::string Name; CFormElm* Element; @@ -400,6 +404,10 @@ public: { Element = NULL; } + ~CElement () + { + nlassert(!Element); + } std::string Name; CFormElm* Element; diff --git a/nel/src/georges/form.cpp b/nel/src/georges/form.cpp index 2f9ecf9b1..63e4ee2ed 100644 --- a/nel/src/georges/form.cpp +++ b/nel/src/georges/form.cpp @@ -191,6 +191,9 @@ void CForm::read (xmlNodePtr node, CFormLoader &loader, CFormDfn *dfn, const std // Reset form clean (); + // Save the dfn + _Dfn = dfn; + // Check node name if ( ((const char*)node->name == NULL) || (strcmp ((const char*)node->name, "FORM") != 0) ) { diff --git a/nel/src/georges/form_elm.cpp b/nel/src/georges/form_elm.cpp index af87a2e0a..358b45f65 100644 --- a/nel/src/georges/form_elm.cpp +++ b/nel/src/georges/form_elm.cpp @@ -1707,6 +1707,7 @@ CFormElmStruct::CFormElmStruct (CForm *form, CFormElm *parentNode, const CFormDf CFormElmStruct::~CFormElmStruct () { // Job done in clean() + clean(); } // *************************************************************************** @@ -1717,10 +1718,10 @@ void CFormElmStruct::clean () uint elm; for (elm =0; elm dfn = loadFormDfn (name, false); if (dfn) { // Open the file diff --git a/nel/src/sound/audio_mixer_user.cpp b/nel/src/sound/audio_mixer_user.cpp index 5d037750b..3f6a5dcbe 100644 --- a/nel/src/sound/audio_mixer_user.cpp +++ b/nel/src/sound/audio_mixer_user.cpp @@ -695,6 +695,7 @@ void CAudioMixerUser::initDevice(const std::string &deviceName, const CInitInfo setBackgroundFlags(flags); } + form = NULL; NLGEORGES::UFormLoader::releaseLoader(formLoader); } } From 64b978b77ac4f84a6421f7c665c1dc3c20067e43 Mon Sep 17 00:00:00 2001 From: kaetemi Date: Tue, 3 Nov 2020 14:47:01 +0800 Subject: [PATCH 05/12] Fix memory release --- nel/include/nel/misc/factory.h | 16 ++++------------ 1 file changed, 4 insertions(+), 12 deletions(-) diff --git a/nel/include/nel/misc/factory.h b/nel/include/nel/misc/factory.h index b1c22a668..82da7ce7d 100644 --- a/nel/include/nel/misc/factory.h +++ b/nel/include/nel/misc/factory.h @@ -58,12 +58,8 @@ public: static CFactory &instance() { // Singleton instance pointer. - static CFactory *instance = NULL; - if (!instance) - { - instance = new CFactory(); - } - return *instance; + static CFactory instance; + return instance; } /** Register a factorable object in the factory. @@ -185,12 +181,8 @@ public: /// Get the singleton instance reference. static CFactoryIndirect &instance() { - static CFactoryIndirect *instance = NULL; - if (!instance) - { - instance = new CFactoryIndirect(); - } - return *instance; + static CFactoryIndirect instance; + return instance; } void registerClass(const KeyType &key, IFactoryIndirectRegister *factoryRegister) From e9fdac30a2928103857d3ae00862b3f2bae6940c Mon Sep 17 00:00:00 2001 From: kaetemi Date: Tue, 3 Nov 2020 14:47:59 +0800 Subject: [PATCH 06/12] Fix memory release --- ryzom/client/src/release.cpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/ryzom/client/src/release.cpp b/ryzom/client/src/release.cpp index bcbf7259f..ccf84af18 100644 --- a/ryzom/client/src/release.cpp +++ b/ryzom/client/src/release.cpp @@ -629,6 +629,9 @@ void release() delete FXAA; FXAA = NULL; CBloomEffect::releaseInstance(); + // Release texture + endLoading(); + // Release Scene, textcontexts, materials, ... Driver->release(); From c9f967b52ba2a505c11cef6ead04abc7d279d475 Mon Sep 17 00:00:00 2001 From: kaetemi Date: Tue, 3 Nov 2020 16:00:25 +0800 Subject: [PATCH 07/12] Fix memory release --- nel/src/misc/app_context.cpp | 4 ++-- ryzom/client/src/release.cpp | 1 + 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/nel/src/misc/app_context.cpp b/nel/src/misc/app_context.cpp index 34d312d98..fc8c64e5f 100644 --- a/nel/src/misc/app_context.cpp +++ b/nel/src/misc/app_context.cpp @@ -135,12 +135,12 @@ CApplicationContext::~CApplicationContext() while (it != iend) { // can't use nldebug there because it'll create new displayers - std::string message = toString("Instance '%s' still allocated at %p", it->first.c_str(), it->second); + std::string message = toString("Instance '%s' still allocated at %p\n", it->first.c_str(), it->second); #ifdef NL_OS_WINDOWS OutputDebugStringW(nlUtf8ToWide(message)); #else - printf("%s\n", message.c_str()); + printf("%s", message.c_str()); #endif ++it; diff --git a/ryzom/client/src/release.cpp b/ryzom/client/src/release.cpp index ccf84af18..24783d391 100644 --- a/ryzom/client/src/release.cpp +++ b/ryzom/client/src/release.cpp @@ -704,6 +704,7 @@ void release() CIXml::releaseLibXml(); CHttpCache::release(); CStrictTransportSecurity::release(); + CCoTask::releaseInstance(); #if FINAL_VERSION // openURL ("http://ryzom.com/exit/"); From 0d2633b6977a5d6677d50493b2fc32f71a4cf1bb Mon Sep 17 00:00:00 2001 From: kaetemi Date: Wed, 4 Nov 2020 05:39:43 +0800 Subject: [PATCH 08/12] Cleanup string --- nel/include/nel/misc/string_view.h | 131 ++++++++++++++++++ nel/include/nel/misc/utf_string_view.h | 10 +- nel/src/misc/string_view.cpp | 31 +++++ ryzom/client/src/client_chat_manager.cpp | 6 +- ryzom/client/src/commands.cpp | 68 ++++----- ryzom/client/src/connection.cpp | 2 +- ryzom/client/src/far_tp.cpp | 4 +- .../src/interface_v3/action_handler_game.cpp | 14 +- .../src/interface_v3/action_handler_help.cpp | 6 +- .../src/interface_v3/action_handler_item.cpp | 30 ++-- .../interface_v3/action_handler_outpost.cpp | 8 +- .../bot_chat_page_create_guild.cpp | 2 +- 12 files changed, 240 insertions(+), 72 deletions(-) create mode 100644 nel/include/nel/misc/string_view.h create mode 100644 nel/src/misc/string_view.cpp diff --git a/nel/include/nel/misc/string_view.h b/nel/include/nel/misc/string_view.h new file mode 100644 index 000000000..9d1a96308 --- /dev/null +++ b/nel/include/nel/misc/string_view.h @@ -0,0 +1,131 @@ +// NeL - MMORPG Framework +// Copyright (C) 2020 Jan BOON (Kaetemi) +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU Affero General Public License as +// published by the Free Software Foundation, either version 3 of the +// License, or (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Affero General Public License for more details. +// +// You should have received a copy of the GNU Affero General Public License +// along with this program. If not, see . + +#ifndef NLMISC_STRING_VIEW_H +#define NLMISC_STRING_VIEW_H + +#include +#include + +#ifdef NL_CPP14 +using namespace std::string_literals; +#ifdef NL_CPP17 +#include +using namespace std::string_view_literals; +#endif +#endif + +#ifdef NL_CPP14 +/// Obtain an std::string from a string literal. +#define nlstr(strLit) (strLit##s) +#else +/// Obtain an std::string from a string literal. +#define nlstr(strLit) (std::string(strLit)) +#endif + +#ifdef NL_CPP17 +/// Obtain a string view from a string literal. +#define nlsv(strLit) (strLit##sv) +/// Obtain an std::string from a string view. +#define nlsvs(strView) (std::string(strView)) +#else +/// Obtain a string view from a string literal. +#define nlsv(strLit) (CStringView(strLit, ::strlen(strLit))) +/// Obtain an std::string from a string view. +#define nlsvs(strView) (std::string(strView.data(), strView.size())) +#endif + +/// Obtain a temporary C-string from a string view. Use directly in argument, do not store. +#define nlsvc(strView) ((strView.data()[strView.size()]) ? nlsvs(strView).c_str() : strView.data()) + +namespace NLMISC { + +/// String view literals allow bypassing allocation and strlen calls. +/// CStringView is a 100% drop-in replacement for (const char *str, size_t len) tuples. It's a non-owning reference. +/// Always use `CStringView` where previously `const std::string &` would have been used. It avoids accidental copy. +/// Gotcha: CStringView doesn't need to end with \0, so there's no guarantee with functions that expect \0 terminated strings, +/// use the `nlsvc` macro to get a temporary C-string from a CStringView. +/// Use the `nlsv` macro to get a CStringView from a string literal. +/// Use the `nlstr` macro to get an std::string from a string literal. +/// Use the `nlsvs` macro to get an std::string from a CStringView. +#ifdef NL_CPP17 +typedef std::string_view CStringView; +#else +class CStringView +{ +public: + CStringView(const std::string &str) : m_Str(&str[0]), m_Len(str.size()) {} + CStringView(const char *const str, const size_t len) : m_Str(str), m_Len(len) {} + CStringView(const char *const str) : m_Str(str), m_Len(sizeof(str)) {} + + inline const char *data() const { return m_Str; } + inline size_t length() const { return m_Len; } + inline size_t size() const { return m_Len; } + + inline CStringView substr(const size_t offset, const size_t count = -1) { return CStringView(m_Str + offset, std::min(m_Len - offset, count)); } + + inline bool operator==(const CStringView o) { if (m_Len != o.m_Len) return false; return memcmp(m_Str, o.m_Str, m_Len) == 0; } + inline bool operator!=(const CStringView o) { if (m_Len != o.m_Len) return true; return memcmp(m_Str, o.m_Str, m_Len) != 0; } + + struct const_iterator + { + public: + const_iterator() : m_Addr(NULL) { } + + inline void operator++() + { + ++m_Addr; + } + inline void operator+=(ptrdiff_t v) + { + m_Addr += v; + } + inline void operator--() + { + --m_Addr; + } + inline void operator-=(ptrdiff_t v) + { + m_Addr -= v; + } + inline bool operator!=(const const_iterator &o) const { return m_Addr != o.m_Addr; } + inline bool operator==(const const_iterator &o) const { return m_Addr == o.m_Addr; } + inline const char &operator*() const { return *m_Addr; } + + private: + friend class CStringView; + inline const_iterator(const char *addr) : m_Addr(addr) {} + const char *m_Addr; + + }; + + typedef const_iterator iterator; + + iterator begin() const { return iterator(m_Str); } + inline iterator end() const { return iterator(m_Str + m_Len); } + +private: + const char *m_Str; + size_t m_Len; + +}; +#endif + +} + +#endif /* #ifndef NLMISC_STRING_VIEW_H */ + +/* end of file */ diff --git a/nel/include/nel/misc/utf_string_view.h b/nel/include/nel/misc/utf_string_view.h index 5b349a2d8..8a224cef5 100644 --- a/nel/include/nel/misc/utf_string_view.h +++ b/nel/include/nel/misc/utf_string_view.h @@ -18,9 +18,12 @@ #define NLMISC_UTF_STRING_VIEW_H #include -#include + #include +#include +#include + namespace NLMISC { class IStream; @@ -40,6 +43,9 @@ public: { nlassert(len <= strlen(utf8Str)); } + + inline CUtfStringView(CStringView utf8Str) : m_Str(utf8Str.data()), m_Size(utf8Str.size()), m_Iterator(utf8Iterator) {} + #if defined(NL_OS_WINDOWS) inline CUtfStringView(const wchar_t *utf16Str) : m_Str(utf16Str), m_Size(wcslen(utf16Str)), m_Iterator(utf16Iterator) {} inline CUtfStringView(const wchar_t *utf16Str, size_t len): m_Str(utf16Str), m_Size(len), m_Iterator(utf16Iterator) @@ -166,6 +172,6 @@ private: } /* namespace NLMISC */ -#endif /* #ifndef NLMISC_STREAMED_PACKAGE_PROVIDER_H */ +#endif /* #ifndef NLMISC_UTF_STRING_VIEW_H */ /* end of file */ diff --git a/nel/src/misc/string_view.cpp b/nel/src/misc/string_view.cpp new file mode 100644 index 000000000..1299d233f --- /dev/null +++ b/nel/src/misc/string_view.cpp @@ -0,0 +1,31 @@ +// NeL - MMORPG Framework +// Copyright (C) 2020 Jan BOON (Kaetemi) +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU Affero General Public License as +// published by the Free Software Foundation, either version 3 of the +// License, or (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Affero General Public License for more details. +// +// You should have received a copy of the GNU Affero General Public License +// along with this program. If not, see . + +#include "stdmisc.h" +#include "nel/misc/string_view.h" + +// STL includes + +// Project includes + +namespace NLMISC +{ + +void nothing_here_string_view_nl() { } + +} /* namespace NLMISC */ + +/* end of file */ diff --git a/ryzom/client/src/client_chat_manager.cpp b/ryzom/client/src/client_chat_manager.cpp index 5515e8580..1414c175d 100644 --- a/ryzom/client/src/client_chat_manager.cpp +++ b/ryzom/client/src/client_chat_manager.cpp @@ -329,7 +329,7 @@ void CClientChatManager::tell( const string& receiverIn, const string& strIn ) // *** send str CBitMemStream bms; - string msgType = "STRING:TELL"; + const char *msgType = "STRING:TELL"; if( GenericMsgHeaderMngr.pushNameToStream(msgType,bms) ) { bms.serial( receiver ); @@ -385,7 +385,7 @@ void CClientChatManager::tell( const string& receiverIn, const string& strIn ) void CClientChatManager::filter( uint8 filter ) { CBitMemStream bms; - string msgType = "STRING:FILTER"; + const char *msgType = "STRING:FILTER"; if( GenericMsgHeaderMngr.pushNameToStream(msgType,bms) ) { bms.serial( filter ); @@ -417,7 +417,7 @@ void CClientChatManager::setChatMode(CChatGroup::TGroupType group, TChanID dynam if (group != CChatGroup::team) { CBitMemStream bms; - string msgType = "STRING:CHAT_MODE"; + const char *msgType = "STRING:CHAT_MODE"; if( GenericMsgHeaderMngr.pushNameToStream(msgType,bms) ) { bms.serial( mode ); diff --git a/ryzom/client/src/commands.cpp b/ryzom/client/src/commands.cpp index 46f494660..00d2b9e4f 100644 --- a/ryzom/client/src/commands.cpp +++ b/ryzom/client/src/commands.cpp @@ -181,14 +181,14 @@ NLMISC_COMMAND(where, "Ask information on the position", "") // Check parameters. if(args.empty()) { // Create the message and send. - const string msgName = "COMMAND:WHERE"; + const char *msgName = "COMMAND:WHERE"; CBitMemStream out; if(GenericMsgHeaderMngr.pushNameToStream(msgName, out)) { NetMngr.push(out); } else - nlwarning("command 'where': unknown message named '%s'", msgName.c_str()); + nlwarning("command 'where': unknown message named '%s'", msgName); return true; } return false; @@ -1803,14 +1803,14 @@ NLMISC_COMMAND(usePreprogCombat, "use the specified combat preprog sentence", "< NLMISC_COMMAND(engage, "engage target in combat", "") { // Create the message for the server to execute a phrase. - const string msgName = "COMBAT:ENGAGE"; + const char *msgName = "COMBAT:ENGAGE"; CBitMemStream out; if(GenericMsgHeaderMngr.pushNameToStream(msgName, out)) { NetMngr.push(out); } else - nlwarning("mainLoop : unknown message name : '%s'", msgName.c_str()); + nlwarning("mainLoop : unknown message name : '%s'", msgName); return true; } @@ -1836,14 +1836,14 @@ NLMISC_COMMAND(disengage, "disengage from combat", "") NLMISC_COMMAND(leaveTeam, "leave team", "") { // Create the message for the server to execute a phrase. - const string msgName = "TEAM:LEAVE"; + const char *msgName = "TEAM:LEAVE"; CBitMemStream out; if(GenericMsgHeaderMngr.pushNameToStream(msgName, out)) { NetMngr.push(out); } else - nlwarning("mainLoop : unknown message name : '%s'", msgName.c_str()); + nlwarning("mainLoop : unknown message name : '%s'", msgName); return true; } @@ -1851,14 +1851,14 @@ NLMISC_COMMAND(leaveTeam, "leave team", "") NLMISC_COMMAND(joinTeam, "join the specified team", "") { // Create the message for the server to execute a phrase. - const string msgName = "TEAM:JOIN"; + const char *msgName = "TEAM:JOIN"; CBitMemStream out; if(GenericMsgHeaderMngr.pushNameToStream(msgName, out)) { NetMngr.push(out); } else - nlwarning("mainLoop : unknown message name : '%s'", msgName.c_str()); + nlwarning("mainLoop : unknown message name : '%s'", msgName); return true; } @@ -1866,14 +1866,14 @@ NLMISC_COMMAND(joinTeam, "join the specified team", "") NLMISC_COMMAND(joinTeamProposal, "propose to current target to join the team", "") { // Create the message for the server to execute a phrase. - const string msgName = "TEAM:JOIN_PROPOSAL"; + const char *msgName = "TEAM:JOIN_PROPOSAL"; CBitMemStream out; if(GenericMsgHeaderMngr.pushNameToStream(msgName, out)) { NetMngr.push(out); } else - nlwarning("mainLoop : unknown message name : '%s'", msgName.c_str()); + nlwarning("mainLoop : unknown message name : '%s'", msgName); return true; } @@ -1881,14 +1881,14 @@ NLMISC_COMMAND(joinTeamProposal, "propose to current target to join the team", " NLMISC_COMMAND(joinTeamDecline, "decline a join team proposal", "") { // Create the message for the server to execute a phrase. - const string msgName = "TEAM:JOIN_PROPOSAL_DECLINE"; + const char *msgName = "TEAM:JOIN_PROPOSAL_DECLINE"; CBitMemStream out; if(GenericMsgHeaderMngr.pushNameToStream(msgName, out)) { NetMngr.push(out); } else - nlwarning("mainLoop : unknown message name : '%s'", msgName.c_str()); + nlwarning("mainLoop : unknown message name : '%s'", msgName); return true; } @@ -1896,14 +1896,14 @@ NLMISC_COMMAND(joinTeamDecline, "decline a join team proposal", "") NLMISC_COMMAND(kickTeammate, "kick someone from your team", "") { // Create the message for the server to execute a phrase. - const string msgName = "TEAM:KICK"; + const char *msgName = "TEAM:KICK"; CBitMemStream out; if(GenericMsgHeaderMngr.pushNameToStream(msgName, out)) { NetMngr.push(out); } else - nlwarning("mainLoop : unknown message name : '%s'", msgName.c_str()); + nlwarning("mainLoop : unknown message name : '%s'", msgName); return true; } @@ -1913,14 +1913,14 @@ NLMISC_COMMAND(cancelCurrentSentence, "cancel the sentence being executed", "") // no parameter needed // Create the message for the server to cancel the phrase being executed - const string msgName = "SENTENCE:CANCEL_CURRENT"; + const char *msgName = "SENTENCE:CANCEL_CURRENT"; CBitMemStream out; if(GenericMsgHeaderMngr.pushNameToStream(msgName, out)) { NetMngr.push(out); } else - nlwarning("command : unknown message name : '%s'", msgName.c_str()); + nlwarning("command : unknown message name : '%s'", msgName); return true; } @@ -1952,7 +1952,7 @@ NLMISC_COMMAND(drop,"drop an item to the ground","") sint32 z = (sint32)UserEntity->pos().z * 1000; CBitMemStream bms; - string msgType = "ITEM:DROP"; + const char *msgType = "ITEM:DROP"; if( GenericMsgHeaderMngr.pushNameToStream(msgType,bms) ) { bms.serial( itemId ); @@ -3769,7 +3769,7 @@ NLMISC_COMMAND( createPerso, "create a new character", "Parameters:\n-Character fromString(args[4], level); CBitMemStream bms; - string msgType = "CHEAT:CREATE_CHARACTER"; + const char *msgType = "CHEAT:CREATE_CHARACTER"; if( GenericMsgHeaderMngr.pushNameToStream(msgType,bms) ) { bms.serial( characterName ); @@ -3800,7 +3800,7 @@ NLMISC_COMMAND( add_role, "add role to character", "") { if (args.size() != 1) return false; - const string msgName = "GUILD:CREATE"; + const char *msgName = "GUILD:CREATE"; CBitMemStream out; if(GenericMsgHeaderMngr.pushNameToStream(msgName, out)) { - string buf = args[0]; + ucstring buf = ucstring::makeFromUtf8(args[0]); // FIXME: UTF-8 (serial) out.serial( buf ); NetMngr.push(out); } @@ -4144,7 +4144,7 @@ NLMISC_COMMAND(GUCreate, "create a guild", "") NLMISC_COMMAND(GUQuit, "quit a guild", "") { if (args.size() != 0) return false; - const string msgName = "GUILD:QUIT"; + const char *msgName = "GUILD:QUIT"; CBitMemStream out; if(GenericMsgHeaderMngr.pushNameToStream(msgName, out)) { @@ -4156,7 +4156,7 @@ NLMISC_COMMAND(GUQuit, "quit a guild", "") NLMISC_COMMAND(GULeaveLeadership, "abandon leadership of a guild", "") { if (args.size() != 0) return false; - const string msgName = "GUILD:ABANDON_LEADERSHIP"; + const char *msgName = "GUILD:ABANDON_LEADERSHIP"; CBitMemStream out; if(GenericMsgHeaderMngr.pushNameToStream(msgName, out)) { @@ -4167,7 +4167,7 @@ NLMISC_COMMAND(GULeaveLeadership, "abandon leadership of a guild", "") NLMISC_COMMAND(GULeaveOfficerTitle, "abandon officer title", "") { if (args.size() != 0) return false; - const string msgName = "GUILD:ABANDON_OFFICER_TITLE"; + const char *msgName = "GUILD:ABANDON_OFFICER_TITLE"; CBitMemStream out; if(GenericMsgHeaderMngr.pushNameToStream(msgName, out)) { @@ -4179,7 +4179,7 @@ NLMISC_COMMAND(GULeaveOfficerTitle, "abandon officer title", "") NLMISC_COMMAND(GUNameOfficer, "name an officer", "") { if (args.size() != 1) return false; - const string msgName = "GUILD:NAME_OFFICER"; + const char *msgName = "GUILD:NAME_OFFICER"; CBitMemStream out; if(GenericMsgHeaderMngr.pushNameToStream(msgName, out)) { @@ -4193,7 +4193,7 @@ NLMISC_COMMAND(GUNameOfficer, "name an officer", "") NLMISC_COMMAND(GUDismissOfficer, "dismiss an officer", "") { if (args.size() != 1) return false; - const string msgName = "GUILD:DISMISS_OFFICER"; + const char *msgName = "GUILD:DISMISS_OFFICER"; CBitMemStream out; if(GenericMsgHeaderMngr.pushNameToStream(msgName, out)) { @@ -4207,7 +4207,7 @@ NLMISC_COMMAND(GUDismissOfficer, "dismiss an officer", "") NLMISC_COMMAND(GUKick, "kick a member", "") { if (args.size() != 1) return false; - const string msgName = "GUILD:KICK_MEMBER"; + const char *msgName = "GUILD:KICK_MEMBER"; CBitMemStream out; if(GenericMsgHeaderMngr.pushNameToStream(msgName, out)) { @@ -4234,7 +4234,7 @@ NLMISC_COMMAND(GURefuse, "refuse an invitation", "") NLMISC_COMMAND(GUFriend, "invite a player to become a friend of the guild", "") { if (args.size() != 1) return false; - const string msgName = "GUILD:FRIEND_INVITATION"; + const char *msgName = "GUILD:FRIEND_INVITATION"; CBitMemStream out; if(GenericMsgHeaderMngr.pushNameToStream(msgName, out)) { @@ -4248,7 +4248,7 @@ NLMISC_COMMAND(GUFriend, "invite a player to become a friend of the guild", "") { if (args.size() != 1) return false; - const string msgName = "GUILD:SET_SUCCESSOR"; + const char *msgName = "GUILD:SET_SUCCESSOR"; CBitMemStream out; if(GenericMsgHeaderMngr.pushNameToStream(msgName, out)) { @@ -4286,7 +4286,7 @@ NLMISC_COMMAND(GUSetSuccessor, "set the successor of the guild leader", "") { if (args.size() != 1) return false; - const string msgName = "GUILD:GET_INFOS"; + const char *msgName = "GUILD:GET_INFOS"; CBitMemStream out; if(GenericMsgHeaderMngr.pushNameToStream(msgName, out)) { @@ -4300,7 +4300,7 @@ NLMISC_COMMAND(GUInfos, "get information on a guild", "") NLMISC_COMMAND(GUJournal, "get the guild journal", "") { if (args.size() != 0) return false; - const string msgName = "GUILD:GET_LOG"; + const char *msgName = "GUILD:GET_LOG"; CBitMemStream out; if(GenericMsgHeaderMngr.pushNameToStream(msgName, out)) { @@ -4314,7 +4314,7 @@ NLMISC_COMMAND(buildingTeleport, "teleport to a building", "building index") if (args.size() != 1) return false; uint16 index; fromString(args[0], index); - const string msgName = "GUILD:TELEPORT"; + const char *msgName = "GUILD:TELEPORT"; CBitMemStream out; if(GenericMsgHeaderMngr.pushNameToStream(msgName, out)) { diff --git a/ryzom/client/src/connection.cpp b/ryzom/client/src/connection.cpp index 3cc9f97dc..1ec84433f 100644 --- a/ryzom/client/src/connection.cpp +++ b/ryzom/client/src/connection.cpp @@ -1706,7 +1706,7 @@ public: string sCharSumPath = getParam(Params, "charsum"); SCharacter3DSetup::setupCharacterSummaryFromDB(CS, sCharSumPath); CS.Mainland = MainlandSelected; - CS.Name = sFirstName; + CS.Name = ucstring::makeFromUtf8(sFirstName); // FIXME: UTF-8 (serial) //CS.Surname = sSurName; // Create the message to send to the server from the character summary diff --git a/ryzom/client/src/far_tp.cpp b/ryzom/client/src/far_tp.cpp index 7f98d8b82..6b0d18409 100644 --- a/ryzom/client/src/far_tp.cpp +++ b/ryzom/client/src/far_tp.cpp @@ -1010,13 +1010,13 @@ void CFarTP::hookNextFarTPForEditor() */ void CFarTP::requestReturnToPreviousSession(TSessionId rejectedSessionId) { - const string msgName = "CONNECTION:RET_MAINLAND"; + const char *msgName = "CONNECTION:RET_MAINLAND"; CBitMemStream out; nlverify(GenericMsgHeaderMngr.pushNameToStream(msgName, out)); out.serial(PlayerSelectedSlot); out.serial(rejectedSessionId); NetMngr.push(out); - nlinfo("%s sent", msgName.c_str()); + nlinfo("%s sent", msgName); } /* diff --git a/ryzom/client/src/interface_v3/action_handler_game.cpp b/ryzom/client/src/interface_v3/action_handler_game.cpp index 171b4bc08..2fedf8aad 100644 --- a/ryzom/client/src/interface_v3/action_handler_game.cpp +++ b/ryzom/client/src/interface_v3/action_handler_game.cpp @@ -1166,7 +1166,7 @@ public: game_exit_request = true; ryzom_exit_request = true; - const string msgName = "CONNECTION:CLIENT_QUIT_REQUEST"; + const char *msgName = "CONNECTION:CLIENT_QUIT_REQUEST"; CBitMemStream out; nlverify(GenericMsgHeaderMngr.pushNameToStream(msgName, out)); bool bypassDisconnectionTimer = FarTP.isFastDisconnectGranted() && (!IsInRingSession); // no need on a ring shard, as it's very short @@ -1489,7 +1489,7 @@ void beastOrder (const std::string &orderStr, const std::string &beastIndexStr, else { // execute the order. - const string msgName = "ANIMALS:BEAST"; + const char *msgName = "ANIMALS:BEAST"; CBitMemStream out; if(GenericMsgHeaderMngr.pushNameToStream(msgName, out)) { @@ -1500,7 +1500,7 @@ void beastOrder (const std::string &orderStr, const std::string &beastIndexStr, NetMngr.push(out); } else - nlwarning(" : unknown message name : '%s'.", msgName.c_str()); + nlwarning(" : unknown message name : '%s'.", msgName); } } @@ -4530,7 +4530,7 @@ public: if( sCustomPhrase.empty() ) { // Create the message and send. - static const string msgName = "COMMAND:EMOTE"; + static const char *msgName = "COMMAND:EMOTE"; CBitMemStream out; if(GenericMsgHeaderMngr.pushNameToStream(msgName, out)) { @@ -4540,12 +4540,12 @@ public: //nlinfo("impulseCallBack : %s %d %d sent", msgName.c_str(), (uint32)behavToSend, phraseNbToSend); } else - nlwarning("command 'emote': unknown message named '%s'.", msgName.c_str()); + nlwarning("command 'emote': unknown message named '%s'.", msgName); } else { // Create the message and send. - static const string msgName = "COMMAND:CUSTOM_EMOTE"; + static const char *msgName = "COMMAND:CUSTOM_EMOTE"; CBitMemStream out; if(GenericMsgHeaderMngr.pushNameToStream(msgName, out)) { @@ -4575,7 +4575,7 @@ public: //nlinfo("impulseCallBack : %s %d %s sent", msgName.c_str(), (uint32)behavToSend, sCustomPhrase.c_str()); } else - nlwarning("command 'emote': unknown message named '%s'.", msgName.c_str()); + nlwarning("command 'emote': unknown message named '%s'.", msgName); } } }; diff --git a/ryzom/client/src/interface_v3/action_handler_help.cpp b/ryzom/client/src/interface_v3/action_handler_help.cpp index 102307909..cd79f0192 100644 --- a/ryzom/client/src/interface_v3/action_handler_help.cpp +++ b/ryzom/client/src/interface_v3/action_handler_help.cpp @@ -3706,17 +3706,17 @@ public: sint n = PeopleInterraction.TeamList.getIndexFromName(selection->getEntityName()); if (n >= 0) { - const string msgName = "TEAM:KICK"; + const char *msgName = "TEAM:KICK"; CBitMemStream out; if(GenericMsgHeaderMngr.pushNameToStream(msgName, out)) { uint8 teamMember = (uint8)n; out.serialEnum(teamMember); NetMngr.push(out); - //nlinfo("impulseCallBack : %s %d sent", msgName.c_str(), teamMember); + //nlinfo("impulseCallBack : %s %d sent", msgName, teamMember); } else - nlwarning("unknown message named '%s'.", msgName.c_str()); + nlwarning("unknown message named '%s'.", msgName); } } } diff --git a/ryzom/client/src/interface_v3/action_handler_item.cpp b/ryzom/client/src/interface_v3/action_handler_item.cpp index a6eaca91e..9bbf9fbc8 100644 --- a/ryzom/client/src/interface_v3/action_handler_item.cpp +++ b/ryzom/client/src/interface_v3/action_handler_item.cpp @@ -417,10 +417,10 @@ void CInterfaceItemEdition::CItemEditionWindow::validate() if (textValid) { CBitMemStream out; - const string msgName = "EVENT:SET_ITEM_CUSTOM_TEXT"; + const char *msgName = "EVENT:SET_ITEM_CUSTOM_TEXT"; if (!GenericMsgHeaderMngr.pushNameToStream(msgName, out)) { - nlwarning ("don't know message name %s", msgName.c_str()); + nlwarning ("don't know message name %s", msgName); } else { @@ -456,7 +456,7 @@ static void checkItemCommand(const CItemSheet *itemSheet); static void sendSwapItemMsg(const CDBCtrlSheet *pCSSrc, const CDBCtrlSheet *pCSDst, sint32 quantitySrc) { CBitMemStream out; - const string sMsg = "ITEM:SWAP"; + const char *sMsg = "ITEM:SWAP"; if(GenericMsgHeaderMngr.pushNameToStream(sMsg, out)) { // Swap all the Src (quantity= quantitySrc) to dest @@ -489,7 +489,7 @@ static void sendSwapItemMsg(const CDBCtrlSheet *pCSSrc, const CDBCtrlSheet *pCSD //nlinfo("impulseCallBack : %s %d %d %d %d %d sent", sMsg.c_str(), srcInvId, srcSlotId, dstInvId, dstSlotId, quantity); } else - nlwarning(" unknown message name '%s'",sMsg.c_str()); + nlwarning(" unknown message name '%s'",sMsg); } /** Display the popup to ask item quantity @@ -567,7 +567,7 @@ static void openStackItem(CCtrlBase *pCaller, CDBCtrlSheet *pCSSrc, CDBCtrlSheet CInterfaceManager *pIM= CInterfaceManager::getInstance(); CBitMemStream out; - const string sMsg = "EXCHANGE:ADD"; + const char *sMsg = "EXCHANGE:ADD"; if(GenericMsgHeaderMngr.pushNameToStream(sMsg, out)) { // Swap all the Src (quantity= quantitySrc) to dest @@ -580,7 +580,7 @@ static void openStackItem(CCtrlBase *pCaller, CDBCtrlSheet *pCSSrc, CDBCtrlSheet //nlinfo("impulseCallBack : %s %d %d %d sent", sMsg.c_str(), srcSlotIndex, destSlotIndex, quantitySrc); } else - nlwarning(" unknown message name '%s'",sMsg.c_str()); + nlwarning(" unknown message name '%s'",sMsg); } //===================================================================================================================== @@ -636,8 +636,8 @@ static void openStackItem(CCtrlBase *pCaller, CDBCtrlSheet *pCSSrc, CDBCtrlSheet // send msg to server CBitMemStream out; - const string sMsg = "EXCHANGE:REMOVE"; - if(GenericMsgHeaderMngr.pushNameToStream(sMsg.c_str(), out)) + const char *sMsg = "EXCHANGE:REMOVE"; + if(GenericMsgHeaderMngr.pushNameToStream(sMsg, out)) { // Swap all the Src (quantity= quantitySrc) to dest uint16 slotIndex = (uint16) exchangeSlot->getIndexInDB(); @@ -647,7 +647,7 @@ static void openStackItem(CCtrlBase *pCaller, CDBCtrlSheet *pCSSrc, CDBCtrlSheet //nlinfo("impulseCallBack : %s %d sent", sMsg.c_str(), slotIndex); } else - nlwarning(" unknown message name '%s'",sMsg.c_str()); + nlwarning(" unknown message name '%s'",sMsg); } @@ -1658,7 +1658,7 @@ REGISTER_ACTION_HANDLER( CHandlerDragNDrop, "drag_n_drop" ); static void sendToServerEnchantMessage(uint8 invent, uint16 slot) { CBitMemStream out; - const string sMsg = "ITEM:ENCHANT"; + const char *sMsg = "ITEM:ENCHANT"; if(GenericMsgHeaderMngr.pushNameToStream(sMsg, out)) { @@ -1667,7 +1667,7 @@ static void sendToServerEnchantMessage(uint8 invent, uint16 slot) NetMngr.push(out); } else - nlinfo("unknown message %s", sMsg.c_str()); + nlinfo("unknown message %s", sMsg); } // ********************************************************************************************************** @@ -2230,7 +2230,7 @@ static void sendMsgUseItem(uint16 slot) if(!ClientCfg.Local) { CBitMemStream out; - const string sMsg = "ITEM:USE_ITEM"; + const char *sMsg = "ITEM:USE_ITEM"; if(GenericMsgHeaderMngr.pushNameToStream(sMsg, out)) { @@ -2238,7 +2238,7 @@ static void sendMsgUseItem(uint16 slot) NetMngr.push(out); } else - nlinfo("unknown message %s", sMsg.c_str()); + nlinfo("unknown message %s", sMsg); } } @@ -2248,7 +2248,7 @@ static void sendMsgStopUseXpCat( bool isRingCatalyser ) if(!ClientCfg.Local) { CBitMemStream out; - const string sMsg = "ITEM:STOP_USE_XP_CAT"; + const char *sMsg = "ITEM:STOP_USE_XP_CAT"; if(GenericMsgHeaderMngr.pushNameToStream(sMsg, out)) { @@ -2256,7 +2256,7 @@ static void sendMsgStopUseXpCat( bool isRingCatalyser ) NetMngr.push(out); } else - nlinfo("unknown message %s", sMsg.c_str()); + nlinfo("unknown message %s", sMsg); } } diff --git a/ryzom/client/src/interface_v3/action_handler_outpost.cpp b/ryzom/client/src/interface_v3/action_handler_outpost.cpp index 023030ebe..a4270e309 100644 --- a/ryzom/client/src/interface_v3/action_handler_outpost.cpp +++ b/ryzom/client/src/interface_v3/action_handler_outpost.cpp @@ -471,7 +471,7 @@ public: startAttackTime= node->getValue32(); // send a DECLARE_WAR_VALIDATE message to server - string sMsg= "OUTPOST:DECLARE_WAR_VALIDATE"; + const char *sMsg= "OUTPOST:DECLARE_WAR_VALIDATE"; CBitMemStream out; if(GenericMsgHeaderMngr.pushNameToStream(sMsg, out)) { @@ -483,7 +483,7 @@ public: } else { - nlwarning("command : unknown message name : '%s'.", sMsg.c_str()); + nlwarning("command : unknown message name : '%s'.", sMsg); } } @@ -508,7 +508,7 @@ public: // Send a msg to server if(outpostSheet) { - string sMsg= "OUTPOST:SELECT"; + const char *sMsg= "OUTPOST:SELECT"; CBitMemStream out; if(GenericMsgHeaderMngr.pushNameToStream(sMsg, out)) { @@ -518,7 +518,7 @@ public: } else { - nlwarning("command : unknown message name : '%s'.", sMsg.c_str()); + nlwarning("command : unknown message name : '%s'.", sMsg); } } } diff --git a/ryzom/client/src/interface_v3/bot_chat_page_create_guild.cpp b/ryzom/client/src/interface_v3/bot_chat_page_create_guild.cpp index 4da27749b..6bfbea0b3 100644 --- a/ryzom/client/src/interface_v3/bot_chat_page_create_guild.cpp +++ b/ryzom/client/src/interface_v3/bot_chat_page_create_guild.cpp @@ -79,7 +79,7 @@ class CHandlerGuildCreate : public IActionHandler uint64 icon = CGuildManager::iconMake((uint8)pCS->getGuildBack(), (uint8)pCS->getGuildSymbol(), pCS->getInvertGuildSymbol(), pCS->getGuildColor1(), pCS->getGuildColor2()); - const string msgName = "GUILD:CREATE"; + const char *msgName = "GUILD:CREATE"; NLMISC::CBitMemStream out; if(GenericMsgHeaderMngr.pushNameToStream(msgName, out)) { From 2444d94f4f0b0409f5216611e139c47546d20b50 Mon Sep 17 00:00:00 2001 From: kaetemi Date: Wed, 4 Nov 2020 06:16:21 +0800 Subject: [PATCH 09/12] Don't expose ucstring to Lua, unless compatibility flag is set --- nel/include/nel/gui/reflect.h | 10 ++++++++++ nel/src/gui/interface_expr_user_fct.cpp | 4 ++++ nel/src/gui/interface_link.cpp | 4 ++-- nel/src/gui/lua_ihm.cpp | 4 ++++ ryzom/client/src/connection.cpp | 8 +++++++- 5 files changed, 27 insertions(+), 3 deletions(-) diff --git a/nel/include/nel/gui/reflect.h b/nel/include/nel/gui/reflect.h index 579a9418b..3f0b936a9 100644 --- a/nel/include/nel/gui/reflect.h +++ b/nel/include/nel/gui/reflect.h @@ -42,9 +42,13 @@ namespace NLGUI UInt32, Float, String, +#ifdef RYZOM_LUA_UCSTRING UCString, +#endif StringRef, +#ifdef RYZOM_LUA_UCSTRING UCStringRef, +#endif RGBA, LuaMethod }; // other types will be added when needed @@ -79,9 +83,13 @@ namespace NLGUI TGetUInt32 GetUInt32; TGetFloat GetFloat; TGetString GetString; +#ifdef RYZOM_LUA_UCSTRING TGetUCString GetUCString; +#endif TGetStringRef GetStringRef; +#ifdef RYZOM_LUA_UCSTRING TGetUCStringRef GetUCStringRef; +#endif TGetRGBA GetRGBA; TLuaMethod GetLuaMethod; // lua method can only be obtained, not written ... } GetMethod; @@ -92,7 +100,9 @@ namespace NLGUI TSetUInt32 SetUInt32; TSetFloat SetFloat; TSetString SetString; +#ifdef RYZOM_LUA_UCSTRING TSetUCString SetUCString; +#endif TSetRGBA SetRGBA; } SetMethod; // name of the property diff --git a/nel/src/gui/interface_expr_user_fct.cpp b/nel/src/gui/interface_expr_user_fct.cpp index f5de62b6f..e2bb589e1 100644 --- a/nel/src/gui/interface_expr_user_fct.cpp +++ b/nel/src/gui/interface_expr_user_fct.cpp @@ -553,15 +553,19 @@ namespace NLGUI case CReflectedProperty::String: result.setString ((elem->*(pRP->GetMethod.GetString))()); break; +#ifdef RYZOM_LUA_UCSTRING case CReflectedProperty::UCString: result.setString ((elem->*(pRP->GetMethod.GetUCString))().toUtf8()); break; +#endif case CReflectedProperty::StringRef: result.setString ((elem->*(pRP->GetMethod.GetStringRef))()); break; +#ifdef RYZOM_LUA_UCSTRING case CReflectedProperty::UCStringRef: result.setString ((elem->*(pRP->GetMethod.GetUCStringRef))().toUtf8()); break; +#endif case CReflectedProperty::RGBA: result.setRGBA ((elem->*(pRP->GetMethod.GetRGBA))()); break; diff --git a/nel/src/gui/interface_link.cpp b/nel/src/gui/interface_link.cpp index c320f8c51..5b9bebb1f 100644 --- a/nel/src/gui/interface_link.cpp +++ b/nel/src/gui/interface_link.cpp @@ -117,18 +117,18 @@ namespace NLGUI return false; } break; +#ifdef RYZOM_LUA_UCSTRING case CReflectedProperty::UCString: case CReflectedProperty::UCStringRef: -#ifdef RYZOM_LUA_UCSTRING if (valueToAffect.toString()) { (destElem.*(property.SetMethod.SetUCString))(ucstring::makeFromUtf8(valueToAffect.getString())); } else -#endif { return false; } +#endif break; case CReflectedProperty::RGBA: if (valueToAffect.toRGBA()) diff --git a/nel/src/gui/lua_ihm.cpp b/nel/src/gui/lua_ihm.cpp index 9a6bacc3c..cdd87330c 100644 --- a/nel/src/gui/lua_ihm.cpp +++ b/nel/src/gui/lua_ihm.cpp @@ -1412,6 +1412,7 @@ namespace NLGUI case CReflectedProperty::String: ls.push( (reflectedObject.*(property.GetMethod.GetString))() ); break; +#ifdef RYZOM_LUA_UCSTRING case CReflectedProperty::UCString: { ucstring str = (reflectedObject.*(property.GetMethod.GetUCString))(); @@ -1434,6 +1435,7 @@ namespace NLGUI #endif } break; +#endif case CReflectedProperty::StringRef: ls.push( (reflectedObject.*(property.GetMethod.GetStringRef))() ); break; @@ -1508,6 +1510,7 @@ namespace NLGUI (target.*(property.SetMethod.SetString))(val); return; } +#ifdef RYZOM_LUA_UCSTRING case CReflectedProperty::UCString: case CReflectedProperty::UCStringRef: { @@ -1532,6 +1535,7 @@ namespace NLGUI (target.*(property.SetMethod.SetUCString))(val); return; } +#endif case CReflectedProperty::RGBA: { CRGBA color; diff --git a/ryzom/client/src/connection.cpp b/ryzom/client/src/connection.cpp index 1ec84433f..d7eaa2969 100644 --- a/ryzom/client/src/connection.cpp +++ b/ryzom/client/src/connection.cpp @@ -1863,8 +1863,9 @@ string getTarget(CCtrlBase * /* ctrl */, const string &targetName) return ""; } +#ifdef RYZOM_LUA_UCSTRING // ------------------------------------------------------------------------------------------------ -ucstring getUCTarget(CCtrlBase * /* ctrl */, const string &targetName) // TODO: UTF-8 Lua +ucstring getUCTarget(CCtrlBase * /* ctrl */, const string &targetName) { string sTmp = targetName; std::vector targetsVector; @@ -1884,6 +1885,7 @@ ucstring getUCTarget(CCtrlBase * /* ctrl */, const string &targetName) // TODO: return ((elem->*(pRP->GetMethod.GetUCString))()); return ucstring(""); // TODO: UTF-8 Lua } +#endif /*// Ask the server to rename a character // ------------------------------------------------------------------------------------------------ @@ -1955,7 +1957,11 @@ public: string sDBLink = getParam(Params, "dblink"); CharNameValidDBLink = sDBLink; +#ifdef RYZOM_LUA_UCSTRING string sName = getUCTarget(NULL,sTarget).toUtf8(); // TODO: UTF-8 Lua +#else + string sName = getTarget(NULL, sTarget); +#endif CInterfaceManager *pIM = CInterfaceManager::getInstance(); if (sName.empty()) From 297de1d19a825b37d8cf646b1db10f27706712cd Mon Sep 17 00:00:00 2001 From: kaetemi Date: Wed, 4 Nov 2020 07:03:09 +0800 Subject: [PATCH 10/12] Fix memory release --- nel/include/nel/3d/async_file_manager_3d.h | 2 +- ryzom/client/src/client.cpp | 1 + ryzom/client/src/release.cpp | 5 ++++- 3 files changed, 6 insertions(+), 2 deletions(-) diff --git a/nel/include/nel/3d/async_file_manager_3d.h b/nel/include/nel/3d/async_file_manager_3d.h index 4e86f10b1..3f43a01e3 100644 --- a/nel/include/nel/3d/async_file_manager_3d.h +++ b/nel/include/nel/3d/async_file_manager_3d.h @@ -40,7 +40,7 @@ class CTextureFile; class CAsyncFileManager3D { - NLMISC_SAFE_SINGLETON_DECL(CAsyncFileManager3D); + NLMISC_SAFE_RELEASABLE_SINGLETON_DECL(CAsyncFileManager3D); CAsyncFileManager3D(); public: diff --git a/ryzom/client/src/client.cpp b/ryzom/client/src/client.cpp index da9eb8a54..84abb8cd4 100644 --- a/ryzom/client/src/client.cpp +++ b/ryzom/client/src/client.cpp @@ -451,6 +451,7 @@ int main(int argc, char **argv) // delete all logs and displayers when we're not using logs macros anymore destroyDebug(); CLog::releaseProcessName(); + // CCoTask::releaseInstance(); // delete the Nel context delete appContext; diff --git a/ryzom/client/src/release.cpp b/ryzom/client/src/release.cpp index 24783d391..b29683149 100644 --- a/ryzom/client/src/release.cpp +++ b/ryzom/client/src/release.cpp @@ -43,6 +43,7 @@ #include "nel/3d/u_visual_collision_manager.h" #include "nel/3d/u_shape_bank.h" #include "nel/3d/stereo_hmd.h" +#include "nel/3d/async_file_manager_3d.h" // Client #include "global.h" #include "release.h" @@ -572,6 +573,8 @@ void release() { CLoginProgressPostThread::getInstance().step(CLoginStep(LoginStep_GameExit, "login_step_game_exit&play_time=" + toString((NLMISC::CTime::getLocalTime() - StartPlayTime) / 1000))); } + + setCrashCallback(NULL); #ifdef RYZOM_BG_DOWNLOADER CBGDownloaderAccess::getInstance().release(); @@ -704,7 +707,7 @@ void release() CIXml::releaseLibXml(); CHttpCache::release(); CStrictTransportSecurity::release(); - CCoTask::releaseInstance(); + CAsyncFileManager3D::releaseInstance(); #if FINAL_VERSION // openURL ("http://ryzom.com/exit/"); From 3b6e27e800975fd98638495608387be9c4b29d90 Mon Sep 17 00:00:00 2001 From: kaetemi Date: Wed, 4 Nov 2020 10:00:29 +0800 Subject: [PATCH 11/12] Find offset by index --- nel/include/nel/misc/utf_string_view.h | 3 ++- nel/src/misc/utf_string_view.cpp | 12 ++++++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/nel/include/nel/misc/utf_string_view.h b/nel/include/nel/misc/utf_string_view.h index 8a224cef5..6264f425e 100644 --- a/nel/include/nel/misc/utf_string_view.h +++ b/nel/include/nel/misc/utf_string_view.h @@ -131,7 +131,8 @@ public: inline bool empty() const { return !m_Size; } const void *ptr() const { return m_Str; } - size_t count() const; // Slow count of UTF-32 characters + size_t count() const; //< Slow count of UTF-32 codepoints + ptrdiff_t offset(ptrdiff_t i); const //< Get byte offset by utf-32 codepoint index inline CUtfStringView substr(const iterator &begin, const iterator &end) const { diff --git a/nel/src/misc/utf_string_view.cpp b/nel/src/misc/utf_string_view.cpp index 39bf3b92f..283ef9555 100644 --- a/nel/src/misc/utf_string_view.cpp +++ b/nel/src/misc/utf_string_view.cpp @@ -230,6 +230,18 @@ size_t CUtfStringView::count() const return res; } +ptrdiff_t CUtfStringView::offset(ptrdiff_t i) +{ + size_t res = 0; + for (iterator it(begin()), end(this->end()); it != end; ++it) + { + if (res == i) + return (ptrdiff_t)it.ptr() - (ptrdiff_t)ptr(); + ++res; + } + return res; +} + u32char CUtfStringView::utf8Iterator(const void **addr) { // Decode UTF-8 From bb564a630245503926d9701fedfc46f3764c141f Mon Sep 17 00:00:00 2001 From: kaetemi Date: Wed, 4 Nov 2020 11:07:27 +0800 Subject: [PATCH 12/12] Trim unsupported unicode for now, since they mess with input --- nel/src/3d/font_manager.cpp | 4 +++- nel/src/gui/group_editbox.cpp | 34 +++++++++++++++++++++++++++++++++- 2 files changed, 36 insertions(+), 2 deletions(-) diff --git a/nel/src/3d/font_manager.cpp b/nel/src/3d/font_manager.cpp index da8573ef7..3d468f987 100644 --- a/nel/src/3d/font_manager.cpp +++ b/nel/src/3d/font_manager.cpp @@ -146,8 +146,10 @@ void CFontManager::computeString (NLMISC::CUtfStringView sv, { // Creating font k.Char = *it; - if (k.Char < 0x20) + if (k.Char < 0x20) // Control Characters k.Char += 0x2400; + if (k.Char == 0x7F) // DEL + k.Char = 0x2421; k.FontGenerator = fontGen; k.Size = fontSize; k.Embolden = embolden; diff --git a/nel/src/gui/group_editbox.cpp b/nel/src/gui/group_editbox.cpp index 64390bf24..98782cca1 100644 --- a/nel/src/gui/group_editbox.cpp +++ b/nel/src/gui/group_editbox.cpp @@ -54,6 +54,36 @@ namespace NLGUI CGroupEditBox *CGroupEditBox::_MenuFather = NULL; CGroupEditBox::IComboKeyHandler* CGroupEditBox::comboKeyHandler = NULL; + // For now, just trim unsupported codepoints to make emoji fallback to text form + static bool supportedCodepoint(u32char c) + { + if (c >= 0xFE00 && c < 0xFE10) + return false; // Variation Selectors + else if (c >= 0xE0100 && c < 0xE01F0) + return false; // Variation Selectors Supplement + else if (c >= 0x200B && c < 0x2010) + return false; // ZERO WIDTH JOINER, etcetera + else if (c >= 0x2028 && c < 0x202F) + return false; // PARAGRAPH SEPARATOR, etcetera + else if (c >= 0x2060 && c < 0x2070) + return false; // WORD JOINER, etcetera + else if (c == 0xFEFF) + return false; // BOM + return true; + } + + // For now, just trim unsupported codepoints to make emoji fallback to text form + static ::u32string trimUnsupported(const ::u32string str) + { + ::u32string res; + res.reserve(str.size()); + for (::u32string::const_iterator it(str.begin()), end(str.end()); it != end; ++it) + { + if (supportedCodepoint(*it)) + res.push_back(*it); + } + return res; + } // ---------------------------------------------------------------------------- NLMISC_REGISTER_OBJECT(CViewBase, CGroupEditBox, std::string, "edit_box"); @@ -850,7 +880,8 @@ namespace NLGUI // ---------------------------------------------------------------------------- void CGroupEditBox::writeString(const std::string &str16, bool replace, bool atEnd) { - ::u32string str = CUtfStringView(str16).toUtf32(); + // For now, just trim unsupported codepoints to make emoji fallback to text form + ::u32string str = trimUnsupported(CUtfStringView(str16).toUtf32()); sint length = (sint)str.length(); ::u32string toAppend; @@ -1111,6 +1142,7 @@ namespace NLGUI u32char c = isKeyRETURN ? '\n' : rEDK.getChar(); if (isFiltered(c)) return; + if (!supportedCodepoint(c)) return; // For now, just trim unsupported codepoints to make emoji fallback to text form switch(_EntryType) { case Integer: