Some fixes after using ndk r16 clang to build android projects (#18531)

* [android] Fixes warning in UrlAudioPlayer.cpp and CCUserDefault-android.cpp

* Don't write 'using namespace std;' in header files.

* Uses std::unordered_map instead of std::map for Particle3D module.

* Updates external/config.json to v3-deps-141

* Continue to replace `gnustl_static` to `c++_static` for templates and test projects.

* Updates CCConsole.h/.cpp to resolve the following issue on Android:

jni/../../../../../cocos/base/CCConsole.cpp:321:28:   required from here
/Users/james/Software/android/android-sdk/ndk-bundle/sources/cxx-stl/llvm-libc++/include/utility:506:63: error: incomplete type 'std::__ndk1::is_move_assignable<cocos2d::Console::Command>' used in nested name specifier
                         is_move_assignable<first_type>::value &&
                                                               ^
make: *** [obj/local/arm64-v8a/objs-debug/cocos2dx_internal_static/base/CCConsole.o] Error 1

* Fixes a memory leak while addCommand and other minor changes.

* Updates tolua/cocos2dx.ini, don't bind Console::Command

* Adds CC_DLL for Console::Command

* Reverts tolua/cocos2dx.ini and ignore Console::[add Command addSubCommand getSubCommand delSubCommand].

* Ignores Console::getCommand.
This commit is contained in:
James Chen 2017-12-05 13:35:16 +08:00 committed by minggo
parent 5151dfd6f9
commit d21af3b981
20 changed files with 197 additions and 67 deletions

View File

@ -69,7 +69,7 @@ UrlAudioPlayer::UrlAudioPlayer(SLEngineItf engineItf, SLObjectItf outputMixObjec
__playerContainerMutex.lock();
__playerContainer.push_back(this);
ALOGV("Current UrlAudioPlayer instance count: %d", __playerContainer.size());
ALOGV("Current UrlAudioPlayer instance count: %d", (int)__playerContainer.size());
__playerContainerMutex.unlock();
_callerThreadId = callerThreadUtils->getCallerThreadId();

View File

@ -311,42 +311,134 @@ const std::string& Console::Utility::getPrompt()
// Command code
//
void Console::Command::addCallback(const Callback& callback_)
Console::Command::Command()
: _callback(nullptr)
{
callback = callback_;
}
Console::Command::Command(const std::string& name, const std::string& help)
: _name(name)
, _help(help)
, _callback(nullptr)
{
}
Console::Command::Command(const std::string& name, const std::string& help, const Callback& callback)
: _name(name)
, _help(help)
, _callback(callback)
{
}
Console::Command::Command(const Command& o)
{
*this = o;
}
Console::Command::Command(Command&& o)
{
*this = std::move(o);
}
Console::Command::~Command()
{
for (const auto& e : _subCommands)
{
delete e.second;
}
}
Console::Command& Console::Command::operator=(const Command& o)
{
if (this != &o)
{
_name = o._name;
_help = o._help;
_callback = o._callback;
for (const auto& e : _subCommands)
delete e.second;
_subCommands.clear();
for (const auto& e : o._subCommands)
{
Command* subCommand = e.second;
auto newCommand = new (std::nothrow) Command(*subCommand);
_subCommands[e.first] = newCommand;
}
}
return *this;
}
Console::Command& Console::Command::operator=(Command&& o)
{
if (this != &o)
{
_name = std::move(o._name);
_help = std::move(o._help);
_callback = std::move(o._callback);
o._callback = nullptr;
for (const auto& e : _subCommands)
delete e.second;
_subCommands.clear();
_subCommands = std::move(o._subCommands);
}
return *this;
}
void Console::Command::addCallback(const Callback& callback)
{
_callback = callback;
}
void Console::Command::addSubCommand(const Command& subCmd)
{
subCommands[subCmd.name] = subCmd;
auto iter = _subCommands.find(subCmd._name);
if (iter != _subCommands.end())
{
delete iter->second;
_subCommands.erase(iter);
}
Command* cmd = new (std::nothrow) Command();
*cmd = subCmd;
_subCommands[subCmd._name] = cmd;
}
const Console::Command* Console::Command::getSubCommand(const std::string& subCmdName) const
{
auto it = subCommands.find(subCmdName);
if(it != subCommands.end()) {
auto it = _subCommands.find(subCmdName);
if(it != _subCommands.end()) {
auto& subCmd = it->second;
return &subCmd;
return subCmd;
}
return nullptr;
}
void Console::Command::delSubCommand(const std::string& subCmdName)
{
auto it = subCommands.find(subCmdName);
if(it != subCommands.end()) {
subCommands.erase(it);
auto iter = _subCommands.find(subCmdName);
if (iter != _subCommands.end()) {
delete iter->second;
_subCommands.erase(iter);
}
}
void Console::Command::commandHelp(int fd, const std::string& /*args*/)
{
if (! help.empty()) {
Console::Utility::mydprintf(fd, "%s\n", help.c_str());
if (! _help.empty()) {
Console::Utility::mydprintf(fd, "%s\n", _help.c_str());
}
if (! subCommands.empty()) {
sendHelp(fd, subCommands, "");
if (! _subCommands.empty()) {
sendHelp(fd, _subCommands, "");
}
}
@ -366,18 +458,18 @@ void Console::Command::commandGeneric(int fd, const std::string& args)
}
// find sub command
auto it = subCommands.find(key);
if (it != subCommands.end()) {
auto it = _subCommands.find(key);
if (it != _subCommands.end()) {
auto subCmd = it->second;
if (subCmd.callback) {
subCmd.callback(fd, args);
if (subCmd->_callback) {
subCmd->_callback(fd, args);
}
return;
}
// can not find
if (callback) {
callback(fd, args);
if (_callback) {
_callback(fd, args);
}
}
@ -413,6 +505,9 @@ Console::Console()
Console::~Console()
{
stop();
for (auto& e : _commands)
delete e.second;
}
bool Console::listenOnTCP(int port)
@ -530,21 +625,29 @@ void Console::stop()
void Console::addCommand(const Command& cmd)
{
_commands[cmd.name] = cmd;
Command* newCommand = new (std::nothrow) Command(cmd);
auto iter = _commands.find(cmd.getName());
if (iter != _commands.end())
{
delete iter->second;
_commands.erase(iter);
}
_commands[cmd.getName()] = newCommand;
}
void Console::addSubCommand(const std::string& cmdName, const Command& subCmd)
{
auto it = _commands.find(cmdName);
if(it != _commands.end()) {
if (it != _commands.end())
{
auto& cmd = it->second;
addSubCommand(cmd, subCmd);
addSubCommand(*cmd, subCmd);
}
}
void Console::addSubCommand(Command& cmd, const Command& subCmd)
{
cmd.subCommands[subCmd.name] = subCmd;
cmd.addSubCommand(subCmd);
}
const Console::Command* Console::getCommand(const std::string& cmdName)
@ -552,7 +655,7 @@ const Console::Command* Console::getCommand(const std::string& cmdName)
auto it = _commands.find(cmdName);
if(it != _commands.end()) {
auto& cmd = it->second;
return &cmd;
return cmd;
}
return nullptr;
}
@ -562,7 +665,7 @@ const Console::Command* Console::getSubCommand(const std::string& cmdName, const
auto it = _commands.find(cmdName);
if(it != _commands.end()) {
auto& cmd = it->second;
return getSubCommand(cmd, subCmdName);
return getSubCommand(*cmd, subCmdName);
}
return nullptr;
}
@ -576,6 +679,7 @@ void Console::delCommand(const std::string& cmdName)
{
auto it = _commands.find(cmdName);
if(it != _commands.end()) {
delete it->second;
_commands.erase(it);
}
}
@ -585,7 +689,7 @@ void Console::delSubCommand(const std::string& cmdName, const std::string& subCm
auto it = _commands.find(cmdName);
if(it != _commands.end()) {
auto& cmd = it->second;
delSubCommand(cmd, subCmdName);
delSubCommand(*cmd, subCmdName);
}
}
@ -855,7 +959,7 @@ bool Console::parseCommand(int fd)
}
auto cmd = it->second;
cmd.commandGeneric(fd, args2);
cmd->commandGeneric(fd, args2);
}else if(strcmp(buf, "\r\n") != 0) {
const char err[] = "Unknown command. Type 'help' for options\n";
Console::Utility::sendToConsole(fd, err, strlen(err));
@ -1480,21 +1584,21 @@ void Console::printFileUtils(int fd)
Console::Utility::sendPrompt(fd);
}
void Console::sendHelp(int fd, const std::map<std::string, Command>& commands, const char* msg)
void Console::sendHelp(int fd, const std::unordered_map<std::string, Command*>& commands, const char* msg)
{
Console::Utility::sendToConsole(fd, msg, strlen(msg));
for(auto& it : commands)
{
auto command = it.second;
if (command.help.empty()) continue;
if (command->getHelp().empty()) continue;
Console::Utility::mydprintf(fd, "\t%s", command.name.c_str());
ssize_t tabs = strlen(command.name.c_str()) / 8;
Console::Utility::mydprintf(fd, "\t%s", command->getName().c_str());
ssize_t tabs = strlen(command->getName().c_str()) / 8;
tabs = 3 - tabs;
for(int j=0;j<tabs;j++){
Console::Utility::mydprintf(fd, "\t");
}
Console::Utility::mydprintf(fd,"%s\n", command.help.c_str());
Console::Utility::mydprintf(fd,"%s\n", command->getHelp().c_str());
}
}

View File

@ -41,7 +41,7 @@ typedef SSIZE_T ssize_t;
#include <thread>
#include <vector>
#include <map>
#include <unordered_map>
#include <functional>
#include <string>
#include <mutex>
@ -110,17 +110,29 @@ public:
};
/** Command Struct */
struct Command {
class CC_DLL Command
{
public:
using Callback = std::function<void(int fd, const std::string& args)>;
std::string name;
std::string help;
Callback callback{nullptr};
std::map<std::string, Command> subCommands;
/** Constructor */
Command() {}
Command(std::string name_, std::string help_) : name(name_), help(help_) {};
Command(std::string name_, std::string help_, Callback callback_) : name(name_), help(help_), callback(callback_) {};
Command();
Command(const std::string& name, const std::string& help);
Command(const std::string& name, const std::string& help, const Callback& callback);
/** Copy constructor */
Command(const Command& o);
/** Move constructor */
Command(Command&& o);
/** Destructor */
~Command();
/** Copy operator */
Command& operator=(const Command& o);
/** Move operator */
Command& operator=(Command&& o);
/** add callback */
void addCallback(const Callback& callback);
@ -139,6 +151,19 @@ public:
/** generic command handler */
void commandGeneric(int fd, const std::string& args);
/** Gets the name of the current command */
const std::string& getName() const { return _name; }
/** Gets the help information of the current command */
const std::string& getHelp() const { return _help; }
private:
std::string _name;
std::string _help;
Callback _callback;
std::unordered_map<std::string, Command*> _subCommands;
};
/** Constructor */
@ -252,7 +277,7 @@ protected:
bool _endThread;
bool _isIpv6Server;
std::map<std::string, Command> _commands;
std::unordered_map<std::string, Command*> _commands;
// strings generated by cocos2d sent to the remote console
bool _sendDebugStrings;
@ -271,7 +296,7 @@ private:
void printFileUtils(int fd);
/** send help message to console */
static void sendHelp(int fd, const std::map<std::string, Command>& commands, const char* msg);
static void sendHelp(int fd, const std::unordered_map<std::string, Command*>& commands, const char* msg);
};
NS_CC_END

View File

@ -389,7 +389,7 @@ Data UserDefault::getDataForKey(const char* pKey, const Data& defaultValue)
if (encodedDefaultData)
free(encodedDefaultData);
CCLOG("ENCODED STRING: --%s--%d", encodedStr.c_str(), encodedStr.length());
CCLOG("ENCODED STRING: --%s--%d", encodedStr.c_str(), (int)encodedStr.length());
unsigned char * decodedData = NULL;
int decodedDataLen = base64Decode((unsigned char*)encodedStr.c_str(), (unsigned int)encodedStr.length(), &decodedData);

View File

@ -55,7 +55,7 @@ struct CC_DLL Particle3D
float depth;//Own depth
//user defined property
std::map<std::string, void*> userDefs;
std::unordered_map<std::string, void*> userDefs;
};
template<typename T>

View File

@ -56,7 +56,6 @@
#include "extensions/Particle3D/PU/CCPUVelocityMatchingAffectorTranslator.h"
#include "extensions/Particle3D/PU/CCPUVortexAffectorTranslator.h"
using namespace std;
NS_CC_BEGIN
class PUAffectorManager

View File

@ -31,7 +31,6 @@
#include "extensions/Particle3D/PU/CCPUBehaviour.h"
#include "extensions/Particle3D/PU/CCPUSlaveBehaviourTranslator.h"
using namespace std;
NS_CC_BEGIN
class PUBehaviourManager

View File

@ -29,6 +29,7 @@
#include "extensions/Particle3D/PU/CCPUAffector.h"
#include "base/ccTypes.h"
#include <map>
NS_CC_BEGIN

View File

@ -38,7 +38,6 @@
#include "extensions/Particle3D/PU/CCPUSlaveEmitterTranslator.h"
#include "extensions/Particle3D/PU/CCPUSphereSurfaceEmitterTranslator.h"
using namespace std;
NS_CC_BEGIN
class PUEmitterManager

View File

@ -215,7 +215,7 @@ class CC_DLL PUParticleSystem3D : public ParticleSystem3D
{
public:
typedef std::map<std::string, ParticlePool> ParticlePoolMap;
typedef std::unordered_map<std::string, ParticlePool> ParticlePoolMap;
static const float DEFAULT_WIDTH;
static const float DEFAULT_HEIGHT;

View File

@ -30,6 +30,7 @@
#include "math/CCMath.h"
#include "extensions/Particle3D/PU/CCPUBillboardChain.h"
#include <vector>
#include <unordered_map>
NS_CC_BEGIN
@ -163,7 +164,7 @@ protected:
// fast lookup node->chain index
// we use positional map too because that can be useful
typedef std::map<const Node*, size_t> NodeToChainSegmentMap;
typedef std::unordered_map<const Node*, size_t> NodeToChainSegmentMap;
NodeToChainSegmentMap _nodeToSegMap;
/// Total length of trail in world units

View File

@ -80,7 +80,7 @@ void PUObjectAbstractNode::setVariable(const std::string &inName, const std::str
std::pair<bool,std::string> PUObjectAbstractNode::getVariable(const std::string &inName) const
{
std::map<std::string,std::string>::const_iterator i = _env.find(inName);
std::unordered_map<std::string,std::string>::const_iterator i = _env.find(inName);
if(i != _env.end())
return std::make_pair(true, i->second);
@ -95,7 +95,7 @@ std::pair<bool,std::string> PUObjectAbstractNode::getVariable(const std::string
return std::make_pair(false, "");
}
const map<std::string,std::string> &PUObjectAbstractNode::getVariables() const
const std::unordered_map<std::string,std::string> &PUObjectAbstractNode::getVariables() const
{
return _env;
}
@ -313,7 +313,7 @@ void PUScriptCompiler::visit(PUConcreteNode *node)
impl->file = node->file;
impl->abstract = false;
list<PUConcreteNode*> temp;
std::list<PUConcreteNode*> temp;
temp.push_back(node);
for(const auto& child : node->children)
{

View File

@ -28,6 +28,9 @@
#include "base/CCRef.h"
#include "extensions/Particle3D/PU/CCPUScriptParser.h"
#include <list>
#include <unordered_map>
NS_CC_BEGIN
/** This enum holds the types of the possible abstract nodes */
@ -74,7 +77,7 @@ public:
class CC_DLL PUObjectAbstractNode : public PUAbstractNode
{
private:
std::map<std::string,std::string> _env;
std::unordered_map<std::string,std::string> _env;
public:
std::string name, cls;
std::vector<std::string> bases;
@ -93,7 +96,7 @@ public:
void addVariable(const std::string &name);
void setVariable(const std::string &name, const std::string &value);
std::pair<bool,std::string> getVariable(const std::string &name) const;
const std::map<std::string,std::string> &getVariables() const;
const std::unordered_map<std::string,std::string> &getVariables() const;
};
/** This abstract node represents a script property */
@ -134,7 +137,7 @@ private:
bool isNameExcluded(const std::string &cls, PUAbstractNode *parent);
public:
typedef std::map<std::string,unsigned int> IdMap;
typedef std::unordered_map<std::string,unsigned int> IdMap;
static PUScriptCompiler* Instance();
@ -144,7 +147,7 @@ public:
void convertToAST(const PUConcreteNodeList &nodes,PUAbstractNodeList &aNodes);
std::map<std::string,std::string> env;
std::unordered_map<std::string,std::string> env;
private:
PUScriptCompiler();
@ -154,7 +157,7 @@ private:
void visit(PUConcreteNode *node);
private:
std::map<std::string, PUAbstractNodeList> _compiledScripts;
std::unordered_map<std::string, PUAbstractNodeList> _compiledScripts;
PUAbstractNode *_current;
PUAbstractNodeList *_nodes;
PUParticleSystem3D *_PUParticleSystem3D;

View File

@ -37,7 +37,6 @@
#include "extensions/Particle3D/PU/CCPUObserverTranslator.h"
#include "extensions/Particle3D/PU/CCPUBehaviourTranslator.h"
using namespace std;
NS_CC_BEGIN
class PUMaterialCache;
class PUTranslateManager

View File

@ -322,7 +322,7 @@ NS_CC_BEGIN
// @remarks
// Use objectspace for the vectors and only transform as soon as a particle is emitted.
// */
// list<Vec3>::iterator iterator = mSpawnPositionList.end();
// std::list<Vec3>::iterator iterator = mSpawnPositionList.end();
// Vec3 start = startVector;
// if (lengthIncrement > 0.0f)
// {

View File

@ -1,5 +1,5 @@
{
"version": "v3-deps-139",
"version": "v3-deps-141",
"zip_file_size": "136974507",
"repo_name": "cocos2d-x-3rd-party-libs-bin",
"repo_parent": "https://github.com/cocos2d/",

View File

@ -1,4 +1,4 @@
APP_STL := gnustl_static
APP_STL := c++_static
# Uncomment this line to compile to armeabi-v7a, your application will run faster but support less devices
#APP_ABI := armeabi-v7a

View File

@ -1,4 +1,4 @@
APP_STL := gnustl_static
APP_STL := c++_static
APP_CPPFLAGS := -frtti -DCC_ENABLE_CHIPMUNK_INTEGRATION=1 -std=c++11 -fsigned-char -Wno-extern-c-compat
APP_LDFLAGS := -latomic

View File

@ -1,4 +1,4 @@
APP_STL := gnustl_static
APP_STL := c++_static
APP_CPPFLAGS := -frtti -DCC_ENABLE_CHIPMUNK_INTEGRATION=1 -std=c++11 -fsigned-char
APP_LDFLAGS := -latomic

View File

@ -114,7 +114,7 @@ skip = Node::[setGLServerState description getUserObject .*UserData getGLServerS
TMXTiledMap::[getPropertiesForGID],
EventCustom::[getUserData setUserData],
Component::[serialize],
Console::[addCommand],
Console::[addCommand addSubCommand getSubCommand delSubCommand getCommand],
ParallaxNode::[(s|g)etParallaxArray],
TileMapAtlas::[(s|g)etTGAInfo],
GLProgramState::[setVertexAttribCallback setUniformCallback setVertexAttribPointer],