Merge from official-v4.

This commit is contained in:
halx99 2019-11-20 18:27:56 +08:00
commit e647820c9c
19 changed files with 396 additions and 138 deletions

View File

@ -1,38 +1,81 @@
include(CMakeParseArguments) include(CMakeParseArguments)
# copy resource `FILES` and `FOLDERS` to TARGET_FILE_DIR/Resources # copy resource `FILES` and `FOLDERS` to TARGET_FILE_DIR/Resources
function(cocos_copy_target_res cocos_target) function(cocos_link_target_res cocos_target)
set(oneValueArgs COPY_TO) set(oneValueArgs LINK_TO)
set(multiValueArgs FILES FOLDERS) set(multiValueArgs FOLDERS)
cmake_parse_arguments(opt "" "${oneValueArgs}" "${multiValueArgs}" ${ARGN}) cmake_parse_arguments(opt "" "${oneValueArgs}" "${multiValueArgs}" ${ARGN})
# copy files
foreach(cc_file ${opt_FILES}) if(NOT TARGET SYNC_RESOURCE-${cocos_target})
get_filename_component(file_name ${cc_file} NAME) message(WARNING "SyncResource targe for ${cocos_target} is not defined")
add_custom_command(TARGET ${cocos_target} POST_BUILD return()
#COMMAND ${CMAKE_COMMAND} -E echo "copy-file into Resources: ${file_name} ..." endif()
COMMAND ${CMAKE_COMMAND} -E copy_if_different ${cc_file} "${opt_COPY_TO}/${file_name}"
) # linking folders
endforeach()
# copy folders files
foreach(cc_folder ${opt_FOLDERS}) foreach(cc_folder ${opt_FOLDERS})
# file(GLOB_RECURSE folder_files "${cc_folder}/*") get_filename_component(link_folder ${opt_LINK_TO} DIRECTORY)
# get_filename_component(folder_abs_path ${cc_folder} ABSOLUTE) get_filename_component(link_folder_abs ${link_folder} ABSOLUTE)
# foreach(res_file ${folder_files}) add_custom_command(TARGET SYNC_RESOURCE-${cocos_target} POST_BUILD
# get_filename_component(res_file_abs_path ${res_file} ABSOLUTE) COMMAND ${CMAKE_COMMAND} -E make_directory ${link_folder_abs}
# file(RELATIVE_PATH res_file_relat_path ${folder_abs_path} ${res_file_abs_path}) COMMAND ${CMAKE_COMMAND} -E create_symlink ${cc_folder} ${opt_LINK_TO}
# add_custom_command(TARGET ${cocos_target} POST_BUILD
# COMMAND ${CMAKE_COMMAND} -E echo "copy file into Resources: ${res_file_relat_path} ..."
# COMMAND ${CMAKE_COMMAND} -E copy_if_different ${res_file} "${opt_COPY_TO}/${res_file_relat_path}"
# )
# endforeach()
### copy file by file is too slow on windows, the copy_directory improves a lot.
add_custom_command(TARGET ${cocos_target} POST_BUILD
#COMMAND ${CMAKE_COMMAND} -E echo "copy-dir into Resources: ${opt_COPY_TO} ..."
COMMAND ${CMAKE_COMMAND} -E copy_directory ${cc_folder} "${opt_COPY_TO}"
) )
endforeach() endforeach()
endfunction() endfunction()
## create a virtual target SYNC_RESOURCE-${cocos_target}
## Update resource files in Resources/ folder everytime when `Run/Debug` target.
function(cocos_def_copy_resource_target cocos_target)
add_custom_target(SYNC_RESOURCE-${cocos_target} ALL
COMMAND ${CMAKE_COMMAND} -E echo "Linking resources for ${cocos_target} ..."
)
add_dependencies(${cocos_target} SYNC_RESOURCE-${cocos_target})
set_target_properties(SYNC_RESOURCE-${cocos_target} PROPERTIES
FOLDER Utils
)
endfunction()
function(cocos_copy_lua_scripts cocos_target src_dir dst_dir)
set(luacompile_target COPY_LUA-${cocos_target})
if(NOT TARGET ${luacompile_target})
add_custom_target(${luacompile_target} ALL
COMMAND ${CMAKE_COMMAND} -E echo "Copying lua scripts ..."
)
add_dependencies(${cocos_target} ${luacompile_target})
set_target_properties(${luacompile_target} PROPERTIES
FOLDER Utils
)
endif()
if(MSVC)
add_custom_command(TARGET ${luacompile_target} POST_BUILD
COMMAND ${PYTHON_COMMAND} ARGS ${COCOS2DX_ROOT_PATH}/cmake/scripts/sync_folder.py
-s ${src_dir} -d ${dst_dir} -l ${LUAJIT32_COMMAND} -m $<CONFIG>
)
else()
if("${CMAKE_BUILD_TYPE}" STREQUAL "")
add_custom_command(TARGET ${luacompile_target} POST_BUILD
COMMAND ${PYTHON_COMMAND} ARGS ${COCOS2DX_ROOT_PATH}/cmake/scripts/sync_folder.py
-s ${src_dir} -d ${dst_dir}
)
else()
add_custom_command(TARGET ${luacompile_target} POST_BUILD
COMMAND ${PYTHON_COMMAND} ARGS ${COCOS2DX_ROOT_PATH}/cmake/scripts/sync_folder.py
-s ${src_dir} -d ${dst_dir} -l ${LUAJIT32_COMMAND} -m ${CMAKE_BUILD_TYPE}
COMMAND ${PYTHON_COMMAND} ARGS ${COCOS2DX_ROOT_PATH}/cmake/scripts/sync_folder.py
-s ${src_dir} -d ${dst_dir}/64bit -l ${LUAJIT64_COMMAND} -m ${CMAKE_BUILD_TYPE}
)
endif()
endif()
endfunction()
function(cocos_get_resource_path output cocos_target)
get_target_property(rt_output ${cocos_target} RUNTIME_OUTPUT_DIRECTORY)
set(${output} ${rt_output}/${CMAKE_CFG_INTDIR}/Resources PARENT_SCOPE)
endfunction()
# mark `FILES` and files in `FOLDERS` as resource files, the destination is `RES_TO` folder # mark `FILES` and files in `FOLDERS` as resource files, the destination is `RES_TO` folder
# save all marked files in `res_out` # save all marked files in `res_out`
function(cocos_mark_multi_resources res_out) function(cocos_mark_multi_resources res_out)
@ -206,6 +249,11 @@ function(setup_cocos_app_config app_name)
if (XCODE) if (XCODE)
cocos_config_app_xcode_property(${app_name}) cocos_config_app_xcode_property(${app_name})
endif() endif()
if(LINUX OR WINDOWS)
cocos_def_copy_resource_target(${app_name})
endif()
endfunction() endfunction()
# if cc_variable not set, then set it cc_value # if cc_variable not set, then set it cc_value

View File

@ -14,6 +14,10 @@ if(CMAKE_TOOLCHAIN_FILE)
message(STATUS "using toolchain file:" ${CMAKE_TOOLCHAIN_FILE}) message(STATUS "using toolchain file:" ${CMAKE_TOOLCHAIN_FILE})
endif() endif()
find_program(PYTHON_COMMAND NAMES python2 python)
find_program(COCOS_COMMAND NAME cocos
PATHS ${COCOS2DX_ROOT_PATH}/tools/cocos2d-console/bin $ENV{COCOS_CONSOLE_ROOT})
message(STATUS "PROJECT_NAME:" ${PROJECT_NAME}) message(STATUS "PROJECT_NAME:" ${PROJECT_NAME})
message(STATUS "PROJECT_SOURCE_DIR:" ${PROJECT_SOURCE_DIR}) message(STATUS "PROJECT_SOURCE_DIR:" ${PROJECT_SOURCE_DIR})
message(STATUS "COCOS2DX_ROOT_PATH:" ${COCOS2DX_ROOT_PATH}) message(STATUS "COCOS2DX_ROOT_PATH:" ${COCOS2DX_ROOT_PATH})
@ -21,8 +25,10 @@ message(STATUS "CMAKE_MODULE_PATH:" ${CMAKE_MODULE_PATH})
# delete binary dir if you hope a full clean re-build # delete binary dir if you hope a full clean re-build
message(STATUS "PROJECT_BINARY_DIR:" ${PROJECT_BINARY_DIR}) message(STATUS "PROJECT_BINARY_DIR:" ${PROJECT_BINARY_DIR})
message(STATUS "ENGINE_BINARY_PATH:" ${ENGINE_BINARY_PATH}) message(STATUS "ENGINE_BINARY_PATH:" ${ENGINE_BINARY_PATH})
message(STATUS "PYTHON_PATH:" ${PYTHON_COMMAND})
message(STATUS "COCOS_COMMAND_PATH:" ${COCOS_COMMAND})
message(STATUS "HOST_SYSTEM:" ${CMAKE_HOST_SYSTEM_NAME})
# the default behavior of build module
option(BUILD_LUA_LIBS "Build lua libraries" OFF) option(BUILD_LUA_LIBS "Build lua libraries" OFF)
# include helper functions # include helper functions
@ -35,3 +41,22 @@ include(CocosConfigDefine)
# config libraries dependence # config libraries dependence
include(CocosConfigDepend) include(CocosConfigDepend)
if(COCOS_COMMAND)
get_filename_component(cocos2dx_console_dir ${COCOS_COMMAND} DIRECTORY)
set(COCOS2DX_LUAJIT_ROOT ${cocos2dx_console_dir}/../plugins/plugin_luacompile/bin)
message(STATUS "COCOS2DX_LUAJIT_ROOT:" ${COCOS2DX_LUAJIT_ROOT})
if("${CMAKE_HOST_SYSTEM_NAME}" STREQUAL "Windows")
find_program(LUAJIT32_COMMAND NAMES luajit-win PATHS ${COCOS2DX_LUAJIT_ROOT}/32bit NO_SYSTEM_ENVIRONMENT_PATH)
find_program(LUAJIT64_COMMAND NAMES luajit-win PATHS ${COCOS2DX_LUAJIT_ROOT}/64bit NO_SYSTEM_ENVIRONMENT_PATH)
elseif("${CMAKE_HOST_SYSTEM_NAME}" STREQUAL "Linux")
find_program(LUAJIT32_COMMAND NAMES luajit-linux PATHS ${COCOS2DX_LUAJIT_ROOT}/32bit NO_SYSTEM_ENVIRONMENT_PATH)
find_program(LUAJIT64_COMMAND NAMES luajit-linux PATHS ${COCOS2DX_LUAJIT_ROOT}/64bit NO_SYSTEM_ENVIRONMENT_PATH)
endif()
endif()
if(WINDOWS OR LINUX)
message(STATUS "LUAJIT32_COMMAND:" ${LUAJIT32_COMMAND})
message(STATUS "LUAJIT64_COMMAND:" ${LUAJIT64_COMMAND})
endif()

View File

@ -0,0 +1,104 @@
import sys
import os
import shutil
import time
import subprocess
copy_files = []
update_files = 0
create_files = 0
def copy_if_newer(src, dst):
global update_files
global create_files
if not os.path.exists(dst):
shutil.copy(src, dst)
copy_files.append("Create " + dst)
create_files = create_files + 1
else:
stat_src = os.stat(src)
stat_dst = os.stat(dst)
if stat_src.st_mtime > stat_dst.st_mtime:
shutil.copy(src, dst)
copy_files.append("Update " + dst)
update_files = update_files + 1
def compile_lua(src, dst, luajit_command):
command = "%s -b \"%s\" \"%s\"" % (luajit_command, src, dst)
print(" Compiling %s " % src)
ret = subprocess.call(command, shell=True, cwd = os.path.dirname(luajit_command))
if ret != 0 :
print("[error]: %s : failed to compile lua script %s" % (__file__, src))
def compile_if_newer(src, dst, cmd):
global update_files
global create_files
if src.split(".")[-1] != "lua" :
return
dst = dst.strip() + "c"
if not os.path.exists(dst):
compile_lua(src, dst, cmd)
copy_files.append("Create " + dst)
create_files = create_files + 1
else:
stat_src = os.stat(src)
stat_dst = os.stat(dst)
if stat_src.st_mtime > stat_dst.st_mtime:
compile_lua(src, dst, cmd)
copy_files.append("Update " + dst)
update_files = update_files + 1
## copy folder if different
def sync_folder(src_dir, dst_dir, luajit, compile):
if os.path.isfile(src_dir):
if not os.path.exists(os.path.dirname(dst_dir)):
os.makedirs(os.path.dirname(dst_dir))
if luajit and need_compile:
compile_if_newer(src_dir, dst_dir, luajit)
else:
copy_if_newer(src_dir, dst_dir)
elif os.path.isdir(src_dir):
names = os.listdir(src_dir)
for name in names:
src = os.path.join(src_dir, name)
dst = os.path.join(dst_dir, name)
sync_folder(src, dst, luajit, need_compile)
else:
print("[warning] %s: src file %s is bad" % (__file__, src_dir))
if __name__ == "__main__":
from argparse import ArgumentParser
parser = ArgumentParser()
parser.add_argument("-s", dest="src_dir")
parser.add_argument("-d", dest="dst_dir")
parser.add_argument("-l", dest="luajit", default= None)
parser.add_argument("-m", dest="mode", default=None)
(args, unkonw) = parser.parse_known_args(sys.argv)
need_compile = True
# if args.luajit:
# print(" luajit mode '%s'" % (args.mode))
if args.mode == "Debug" and args.luajit:
need_compile = False
print(" -Skip luacompile in debug mode!")
create_files = 0
update_files = 0
start_at = time.time()
sync_folder(args.src_dir, args.dst_dir, args.luajit, need_compile)
end_at = time.time()
if len(copy_files) > 0:
# reduce logs
last_files = copy_files[-3:]
for x in last_files:
print(" %s" % x)
if len(copy_files) > len(last_files) :
print(" ...")
print(" %d items updated, %d items created " % (update_files, create_files))
print(" takes %s seconds"% (end_at - start_at))

View File

@ -692,7 +692,7 @@ protected:
PolygonInfo _polyInfo; PolygonInfo _polyInfo;
// opacity and RGB protocol // opacity and RGB protocol
bool _opacityModifyRGB; bool _opacityModifyRGB = false;
// image is flipped // image is flipped
bool _flippedX = false; /// Whether the sprite is flipped horizontally or not bool _flippedX = false; /// Whether the sprite is flipped horizontally or not

View File

@ -124,29 +124,63 @@ void SpriteBatchNode::setProgramState(backend::ProgramState* programState)
CC_SAFE_RETAIN(programState); CC_SAFE_RETAIN(programState);
} }
pipelineDescriptor.programState = _programState; pipelineDescriptor.programState = _programState;
_mvpMatrixLocaiton = pipelineDescriptor.programState->getUniformLocation("u_MVPMatrix");
_textureLocation = pipelineDescriptor.programState->getUniformLocation("u_texture");
CC_SAFE_RELEASE(program);
setVertexLayout();
setUniformLocation();
}
void SpriteBatchNode::setUniformLocation()
{
CCASSERT(_programState, "programState should not be nullptr");
_mvpMatrixLocaiton = _programState->getUniformLocation("u_MVPMatrix");
_textureLocation = _programState->getUniformLocation("u_texture");
}
void SpriteBatchNode::setVertexLayout()
{
CCASSERT(_programState, "programState should not be nullptr");
//set vertexLayout according to V3F_C4B_T2F structure
auto vertexLayout = _programState->getVertexLayout(); auto vertexLayout = _programState->getVertexLayout();
const auto& attributeInfo = _programState->getProgram()->getActiveAttributes(); ///a_position
auto iter = attributeInfo.find("a_position"); vertexLayout->setAttribute(backend::ATTRIBUTE_NAME_POSITION,
if (iter != attributeInfo.end()) _programState->getAttributeLocation(backend::Attribute::POSITION),
{ backend::VertexFormat::FLOAT3,
vertexLayout->setAttribute("a_position", iter->second.location, backend::VertexFormat::FLOAT3, 0, false); 0,
} false);
iter = attributeInfo.find("a_texCoord"); ///a_texCoord
if (iter != attributeInfo.end()) vertexLayout->setAttribute(backend::ATTRIBUTE_NAME_TEXCOORD,
{ _programState->getAttributeLocation(backend::Attribute::TEXCOORD),
vertexLayout->setAttribute("a_texCoord", iter->second.location, backend::VertexFormat::FLOAT2, offsetof(V3F_C4B_T2F, texCoords), false); backend::VertexFormat::FLOAT2,
} offsetof(V3F_C4B_T2F, texCoords),
iter = attributeInfo.find("a_color"); false);
if (iter != attributeInfo.end())
{ ///a_color
vertexLayout->setAttribute("a_color", iter->second.location, backend::VertexFormat::UBYTE4, offsetof(V3F_C4B_T2F, colors), true); vertexLayout->setAttribute(backend::ATTRIBUTE_NAME_COLOR,
} _programState->getAttributeLocation(backend::Attribute::COLOR),
backend::VertexFormat::UBYTE4,
offsetof(V3F_C4B_T2F, colors),
true);
vertexLayout->setLayout(sizeof(V3F_C4B_T2F)); vertexLayout->setLayout(sizeof(V3F_C4B_T2F));
} }
void SpriteBatchNode::setProgramState(backend::ProgramState *programState)
{
CCASSERT(programState, "programState should not be nullptr");
auto& pipelineDescriptor = _quadCommand.getPipelineDescriptor();
if (_programState != programState)
{
CC_SAFE_RELEASE(_programState);
_programState = programState;
CC_SAFE_RETAIN(programState);
}
pipelineDescriptor.programState = _programState;
setVertexLayout();
setUniformLocation();
}
bool SpriteBatchNode::init() bool SpriteBatchNode::init()
{ {
Texture2D * texture = new (std::nothrow) Texture2D(); Texture2D * texture = new (std::nothrow) Texture2D();
@ -170,7 +204,6 @@ SpriteBatchNode::SpriteBatchNode()
SpriteBatchNode::~SpriteBatchNode() SpriteBatchNode::~SpriteBatchNode()
{ {
CC_SAFE_RELEASE(_textureAtlas); CC_SAFE_RELEASE(_textureAtlas);
CC_SAFE_RELEASE(_programState);
} }
// override visit // override visit

View File

@ -211,6 +211,11 @@ public:
*/ */
virtual std::string getDescription() const override; virtual std::string getDescription() const override;
/**
* Set ProgramState
*/
virtual void setProgramState(backend::ProgramState *programState) override;
/** Inserts a quad at a certain index into the texture atlas. The Sprite won't be added into the children array. /** Inserts a quad at a certain index into the texture atlas. The Sprite won't be added into the children array.
* This method should be called only when you are dealing with very big AtlasSprite and when most of the Sprite won't be updated. * This method should be called only when you are dealing with very big AtlasSprite and when most of the Sprite won't be updated.
* For example: a tile map (TMXMap) or a label with lots of characters (LabelBMFont). * For example: a tile map (TMXMap) or a label with lots of characters (LabelBMFont).
@ -259,6 +264,8 @@ protected:
void updateAtlasIndex(Sprite* sprite, ssize_t* curIndex); void updateAtlasIndex(Sprite* sprite, ssize_t* curIndex);
void swap(ssize_t oldIndex, ssize_t newIndex); void swap(ssize_t oldIndex, ssize_t newIndex);
void updateBlendFunc(); void updateBlendFunc();
void setVertexLayout();
void setUniformLocation();
void setProgramState(backend::ProgramState* programState) override; void setProgramState(backend::ProgramState* programState) override;

View File

@ -32,6 +32,7 @@
#include "network/Uri.h" #include "network/Uri.h"
#include <algorithm> #include <algorithm>
#include <sstream> #include <sstream>
#include <memory>
#include <iterator> #include <iterator>
#include "base/ccUTF8.h" #include "base/ccUTF8.h"
#include "base/CCDirector.h" #include "base/CCDirector.h"
@ -79,8 +80,8 @@ public:
std::vector<std::string> getData()const{ return _args; }; std::vector<std::string> getData()const{ return _args; };
virtual std::string stringify()const; virtual std::string stringify()const;
static SocketIOPacket * createPacketWithType(const std::string& type, SocketIOVersion version); static std::shared_ptr<SocketIOPacket> createPacketWithType(const std::string& type, SocketIOVersion version);
static SocketIOPacket * createPacketWithTypeIndex(int type, SocketIOVersion version); static std::shared_ptr<SocketIOPacket> createPacketWithTypeIndex(int type, SocketIOVersion version);
protected: protected:
std::string _pId;//id message std::string _pId;//id message
std::string _ack;// std::string _ack;//
@ -305,46 +306,47 @@ SocketIOPacketV10x::~SocketIOPacketV10x()
_endpoint = ""; _endpoint = "";
} }
SocketIOPacket * SocketIOPacket::createPacketWithType(const std::string& type, SocketIOPacket::SocketIOVersion version) std::shared_ptr<SocketIOPacket> SocketIOPacket::createPacketWithType(const std::string& type, SocketIOPacket::SocketIOVersion version)
{ {
SocketIOPacket *ret; if(version == SocketIOPacket::SocketIOVersion::V09x)
switch (version)
{ {
case SocketIOPacket::SocketIOVersion::V09x: auto ret = std::make_shared<SocketIOPacket>();
ret = new (std::nothrow) SocketIOPacket;
break;
case SocketIOPacket::SocketIOVersion::V10x:
ret = new (std::nothrow) SocketIOPacketV10x;
break;
}
ret->initWithType(type); ret->initWithType(type);
return ret; return ret;
} }
else if(version == SocketIOPacket::SocketIOVersion::V10x)
SocketIOPacket * SocketIOPacket::createPacketWithTypeIndex(int type, SocketIOPacket::SocketIOVersion version)
{ {
SocketIOPacket *ret; auto ret = std::make_shared<SocketIOPacketV10x>();
switch (version) ret->initWithType(type);
{ return ret;
case SocketIOPacket::SocketIOVersion::V09x:
ret = new (std::nothrow) SocketIOPacket;
break;
case SocketIOPacket::SocketIOVersion::V10x:
return new (std::nothrow) SocketIOPacketV10x;
break;
} }
return nullptr;
}
std::shared_ptr<SocketIOPacket> SocketIOPacket::createPacketWithTypeIndex(int type, SocketIOPacket::SocketIOVersion version)
{
if(version == SocketIOPacket::SocketIOVersion::V09x)
{
auto ret = std::make_shared<SocketIOPacket>();
ret->initWithTypeIndex(type); ret->initWithTypeIndex(type);
return ret; return ret;
} }
else if(version == SocketIOPacket::SocketIOVersion::V10x)
{
auto ret = std::make_shared<SocketIOPacketV10x>();
ret->initWithTypeIndex(type);
return ret;
}
return nullptr;
}
/** /**
* @brief The implementation of the socket.io connection * @brief The implementation of the socket.io connection
* Clients/endpoints may share the same impl to accomplish multiplexing on the same websocket * Clients/endpoints may share the same impl to accomplish multiplexing on the same websocket
*/ */
class SIOClientImpl : class SIOClientImpl :
public cocos2d::Ref, public WebSocket::Delegate,
public WebSocket::Delegate public std::enable_shared_from_this<SIOClientImpl>
{ {
private: private:
int _heartbeat, _timeout; int _heartbeat, _timeout;
@ -362,7 +364,7 @@ public:
SIOClientImpl(const Uri& uri, const std::string& caFilePath); SIOClientImpl(const Uri& uri, const std::string& caFilePath);
virtual ~SIOClientImpl(); virtual ~SIOClientImpl();
static SIOClientImpl* create(const Uri& uri, const std::string& caFilePath); static std::shared_ptr<SIOClientImpl> create(const Uri& uri, const std::string& caFilePath);
virtual void onOpen(WebSocket* ws); virtual void onOpen(WebSocket* ws);
virtual void onMessage(WebSocket* ws, const WebSocket::Data& data); virtual void onMessage(WebSocket* ws, const WebSocket::Data& data);
@ -385,7 +387,7 @@ public:
void send(const std::string& endpoint, const std::string& s); void send(const std::string& endpoint, const std::string& s);
void send(const std::string& endpoint, const std::vector<std::string>& s); void send(const std::string& endpoint, const std::vector<std::string>& s);
void send(SocketIOPacket *packet); void send(std::shared_ptr<SocketIOPacket>& packet);
void emit(const std::string& endpoint, const std::string& eventname, const std::string& args); void emit(const std::string& endpoint, const std::string& eventname, const std::string& args);
void emit(const std::string& endpoint, const std::string& eventname, const std::vector<std::string>& args); void emit(const std::string& endpoint, const std::string& eventname, const std::vector<std::string>& args);
@ -429,7 +431,14 @@ void SIOClientImpl::handshake()
request->setUrl(pre.str()); request->setUrl(pre.str());
request->setRequestType(HttpRequest::Type::GET); request->setRequestType(HttpRequest::Type::GET);
request->setResponseCallback(CC_CALLBACK_2(SIOClientImpl::handshakeResponse, this)); std::weak_ptr<SIOClientImpl> self = shared_from_this();
auto callback = [self](HttpClient* client, HttpResponse *resp) {
auto conn = self.lock();
if (conn) {
conn->handshakeResponse(client, resp);
}
};
request->setResponseCallback(callback);
request->setTag("handshake"); request->setTag("handshake");
CCLOGINFO("SIOClientImpl::handshake() waiting"); CCLOGINFO("SIOClientImpl::handshake() waiting");
@ -633,13 +642,13 @@ void SIOClientImpl::disconnect()
_ws->close(); _ws->close();
} }
SIOClientImpl* SIOClientImpl::create(const Uri& uri, const std::string& caFilePath) std::shared_ptr<SIOClientImpl> SIOClientImpl::create(const Uri& uri, const std::string& caFilePath)
{ {
SIOClientImpl *s = new (std::nothrow) SIOClientImpl(uri, caFilePath); SIOClientImpl *s = new (std::nothrow) SIOClientImpl(uri, caFilePath);
if (s && s->init()) if (s && s->init())
{ {
return s; return std::shared_ptr<SIOClientImpl>(s);
} }
return nullptr; return nullptr;
@ -657,7 +666,7 @@ void SIOClientImpl::addClient(const std::string& endpoint, SIOClient* client)
void SIOClientImpl::connectToEndpoint(const std::string& endpoint) void SIOClientImpl::connectToEndpoint(const std::string& endpoint)
{ {
SocketIOPacket *packet = SocketIOPacket::createPacketWithType("connect", _version); auto packet = SocketIOPacket::createPacketWithType("connect", _version);
packet->setEndpoint(endpoint); packet->setEndpoint(endpoint);
this->send(packet); this->send(packet);
} }
@ -685,7 +694,7 @@ void SIOClientImpl::disconnectFromEndpoint(const std::string& endpoint)
void SIOClientImpl::heartbeat(float /*dt*/) void SIOClientImpl::heartbeat(float /*dt*/)
{ {
SocketIOPacket *packet = SocketIOPacket::createPacketWithType("heartbeat", _version); auto packet = SocketIOPacket::createPacketWithType("heartbeat", _version);
this->send(packet); this->send(packet);
@ -698,7 +707,7 @@ void SIOClientImpl::send(const std::string& endpoint, const std::vector<std::str
switch (_version) { switch (_version) {
case SocketIOPacket::SocketIOVersion::V09x: case SocketIOPacket::SocketIOVersion::V09x:
{ {
SocketIOPacket *packet = SocketIOPacket::createPacketWithType("message", _version); auto packet = SocketIOPacket::createPacketWithType("message", _version);
packet->setEndpoint(endpoint); packet->setEndpoint(endpoint);
for(auto &i : s) for(auto &i : s)
{ {
@ -721,7 +730,7 @@ void SIOClientImpl::send(const std::string& endpoint, const std::string& s)
send(endpoint, t); send(endpoint, t);
} }
void SIOClientImpl::send(SocketIOPacket *packet) void SIOClientImpl::send(std::shared_ptr<SocketIOPacket>& packet)
{ {
std::string req = packet->toString(); std::string req = packet->toString();
if (_connected) if (_connected)
@ -736,7 +745,7 @@ void SIOClientImpl::send(SocketIOPacket *packet)
void SIOClientImpl::emit(const std::string& endpoint, const std::string& eventname, const std::string& args) void SIOClientImpl::emit(const std::string& endpoint, const std::string& eventname, const std::string& args)
{ {
CCLOGINFO("Emitting event \"%s\"", eventname.c_str()); CCLOGINFO("Emitting event \"%s\"", eventname.c_str());
SocketIOPacket *packet = SocketIOPacket::createPacketWithType("event", _version); auto packet = SocketIOPacket::createPacketWithType("event", _version);
packet->setEndpoint(endpoint == "/" ? "" : endpoint); packet->setEndpoint(endpoint == "/" ? "" : endpoint);
packet->setEvent(eventname); packet->setEvent(eventname);
packet->addData(args); packet->addData(args);
@ -746,7 +755,7 @@ void SIOClientImpl::emit(const std::string& endpoint, const std::string& eventna
void SIOClientImpl::emit(const std::string& endpoint, const std::string& eventname, const std::vector<std::string>& args) void SIOClientImpl::emit(const std::string& endpoint, const std::string& eventname, const std::vector<std::string>& args)
{ {
CCLOGINFO("Emitting event \"%s\"", eventname.c_str()); CCLOGINFO("Emitting event \"%s\"", eventname.c_str());
SocketIOPacket *packet = SocketIOPacket::createPacketWithType("event", _version); auto packet = SocketIOPacket::createPacketWithType("event", _version);
packet->setEndpoint(endpoint == "/" ? "" : endpoint); packet->setEndpoint(endpoint == "/" ? "" : endpoint);
packet->setEvent(eventname); packet->setEvent(eventname);
for (auto &arg : args) { for (auto &arg : args) {
@ -759,7 +768,9 @@ void SIOClientImpl::onOpen(WebSocket* /*ws*/)
{ {
_connected = true; _connected = true;
SocketIO::getInstance()->addSocket(_uri.getAuthority(), this); auto self = shared_from_this();
SocketIO::getInstance()->addSocket(_uri.getAuthority(), self);
if (_version == SocketIOPacket::SocketIOVersion::V10x) if (_version == SocketIOPacket::SocketIOVersion::V10x)
{ {
@ -767,14 +778,20 @@ void SIOClientImpl::onOpen(WebSocket* /*ws*/)
_ws->send(s.data()); _ws->send(s.data());
} }
Director::getInstance()->getScheduler()->schedule(CC_SCHEDULE_SELECTOR(SIOClientImpl::heartbeat), this, (_heartbeat * .9f), false); std::weak_ptr<SIOClientImpl> selfWeak = shared_from_this();
auto f = [selfWeak](float dt) {
auto conn = selfWeak.lock();
if(conn)
conn->heartbeat(dt);
};
Director::getInstance()->getScheduler()->schedule(f, this, (_heartbeat * .9f), false, "heart_beat");
for (auto& client : _clients) for (auto& client : _clients)
{ {
client.second->onOpen(); client.second->onOpen();
} }
CCLOGINFO("SIOClientImpl::onOpen socket connected!");
} }
void SIOClientImpl::onMessage(WebSocket* /*ws*/, const WebSocket::Data& data) void SIOClientImpl::onMessage(WebSocket* /*ws*/, const WebSocket::Data& data)
@ -1023,8 +1040,6 @@ void SIOClientImpl::onClose(WebSocket* /*ws*/)
SocketIO::getInstance()->removeSocket(_uri.getAuthority()); SocketIO::getInstance()->removeSocket(_uri.getAuthority());
} }
this->release();
} }
void SIOClientImpl::onError(WebSocket* /*ws*/, const WebSocket::ErrorCode& error) void SIOClientImpl::onError(WebSocket* /*ws*/, const WebSocket::ErrorCode& error)
@ -1033,7 +1048,7 @@ void SIOClientImpl::onError(WebSocket* /*ws*/, const WebSocket::ErrorCode& error
} }
//begin SIOClient methods //begin SIOClient methods
SIOClient::SIOClient(const std::string& path, SIOClientImpl* impl, SocketIO::SIODelegate& delegate) SIOClient::SIOClient(const std::string& path, std::shared_ptr<SIOClientImpl>& impl, SocketIO::SIODelegate& delegate)
: _path(path) : _path(path)
, _connected(false) , _connected(false)
, _socket(impl) , _socket(impl)
@ -1115,7 +1130,6 @@ void SIOClient::disconnect()
{ {
setConnected(false); setConnected(false);
_socket->disconnectFromEndpoint(_path); _socket->disconnectFromEndpoint(_path);
this->release(); this->release();
} }
@ -1123,7 +1137,6 @@ void SIOClient::socketClosed()
{ {
setConnected(false); setConnected(false);
_delegate->onClose(this); _delegate->onClose(this);
this->release(); this->release();
} }
@ -1198,7 +1211,7 @@ SIOClient* SocketIO::connect(const std::string& uri, SocketIO::SIODelegate& dele
{ {
Uri uriObj = Uri::parse(uri); Uri uriObj = Uri::parse(uri);
SIOClientImpl *socket = SocketIO::getInstance()->getSocket(uriObj.getAuthority()); std::shared_ptr<SIOClientImpl> socket = SocketIO::getInstance()->getSocket(uriObj.getAuthority());
SIOClient * c = nullptr; SIOClient * c = nullptr;
std::string path = uriObj.getPath(); std::string path = uriObj.getPath();
@ -1235,7 +1248,7 @@ SIOClient* SocketIO::connect(const std::string& uri, SocketIO::SIODelegate& dele
c->disconnect(); c->disconnect();
CCLOG("SocketIO: recreate a new socket, new client, connect"); CCLOG("SocketIO: recreate a new socket, new client, connect");
SIOClientImpl* newSocket = SIOClientImpl::create(uriObj, caFilePath); std::shared_ptr<SIOClientImpl> newSocket = SIOClientImpl::create(uriObj, caFilePath);
SIOClient *newC = new (std::nothrow) SIOClient(path, newSocket, delegate); SIOClient *newC = new (std::nothrow) SIOClient(path, newSocket, delegate);
newSocket->addClient(path, newC); newSocket->addClient(path, newC);
@ -1248,14 +1261,16 @@ SIOClient* SocketIO::connect(const std::string& uri, SocketIO::SIODelegate& dele
return c; return c;
} }
SIOClientImpl* SocketIO::getSocket(const std::string& uri) std::shared_ptr<SIOClientImpl> SocketIO::getSocket(const std::string& uri)
{ {
return _sockets.at(uri); auto p = _sockets.find(uri);
if(p == _sockets.end()) return nullptr;
return p->second.lock();
} }
void SocketIO::addSocket(const std::string& uri, SIOClientImpl* socket) void SocketIO::addSocket(const std::string& uri, std::shared_ptr<SIOClientImpl>& socket)
{ {
_sockets.insert(uri, socket); _sockets.emplace(uri, socket);
} }
void SocketIO::removeSocket(const std::string& uri) void SocketIO::removeSocket(const std::string& uri)

View File

@ -173,10 +173,11 @@ private:
static SocketIO *_inst; static SocketIO *_inst;
cocos2d::Map<std::string, SIOClientImpl*> _sockets; std::unordered_map<std::string, std::weak_ptr<SIOClientImpl
>> _sockets;
SIOClientImpl* getSocket(const std::string& uri); std::shared_ptr<SIOClientImpl> getSocket(const std::string& uri);
void addSocket(const std::string& uri, SIOClientImpl* socket); void addSocket(const std::string& uri, std::shared_ptr<SIOClientImpl>& socket);
void removeSocket(const std::string& uri); void removeSocket(const std::string& uri);
friend class SIOClientImpl; friend class SIOClientImpl;
@ -202,9 +203,9 @@ private:
std::string _path, _tag; std::string _path, _tag;
bool _connected; bool _connected;
SIOClientImpl* _socket; std::shared_ptr<SIOClientImpl> _socket;
SocketIO::SIODelegate* _delegate; SocketIO::SIODelegate* _delegate = nullptr;
EventRegistry _eventRegistry; EventRegistry _eventRegistry;
@ -228,7 +229,7 @@ private:
* @param impl the SIOClientImpl object. * @param impl the SIOClientImpl object.
* @param delegate the SIODelegate object. * @param delegate the SIODelegate object.
*/ */
SIOClient(const std::string& path, SIOClientImpl* impl, SocketIO::SIODelegate& delegate); SIOClient(const std::string& path, std::shared_ptr<SIOClientImpl>& impl, SocketIO::SIODelegate& delegate);
/** /**
* Destructor of SIOClient class. * Destructor of SIOClient class.
*/ */

View File

@ -467,11 +467,11 @@ public:
return false; return false;
} }
_data.reserve(LWS_PRE + len); _data.resize(LWS_PRE + len);
_data.resize(LWS_PRE, 0x00);
if (len > 0) if (len > 0)
{ {
_data.insert(_data.end(), buf, buf + len); std::copy(buf, buf + len, _data.begin() + LWS_PRE);
} }
_payload = _data.data() + LWS_PRE; _payload = _data.data() + LWS_PRE;

View File

@ -236,6 +236,9 @@ Copyright (C) 2008 Apple Inc. All Rights Reserved.
#pragma mark CCEAGLView - Touch Delegate #pragma mark CCEAGLView - Touch Delegate
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event - (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{ {
if (self.isKeyboardShown)
[self closeKeyboardOpenedByEditBox];
UITouch* ids[IOS_MAX_TOUCHES_COUNT] = {0}; UITouch* ids[IOS_MAX_TOUCHES_COUNT] = {0};
float xs[IOS_MAX_TOUCHES_COUNT] = {0.0f}; float xs[IOS_MAX_TOUCHES_COUNT] = {0.0f};
float ys[IOS_MAX_TOUCHES_COUNT] = {0.0f}; float ys[IOS_MAX_TOUCHES_COUNT] = {0.0f};
@ -546,4 +549,23 @@ namespace {
} }
} }
// Close the keyboard opened by EditBox
-(void) closeKeyboardOpenedByEditBox
{
NSArray *subviews = self.subviews;
for(UIView* view in subviews)
{
if([view isKindOfClass:NSClassFromString(@"UITextView")] ||
[view isKindOfClass:NSClassFromString(@"UITextField")])
{
if ([view isFirstResponder])
{
[view resignFirstResponder];
return;
}
}
}
}
@end @end

View File

@ -47,7 +47,7 @@ typedef NS_ENUM(NSInteger, PlayerbackState) {
PlayerbackStateCompleted PlayerbackStateCompleted
}; };
@property (strong, nonatomic) AVPlayerViewController * playerController; @property (assign, nonatomic) AVPlayerViewController * playerController;
- (void) setFrame:(int) left :(int) top :(int) width :(int) height; - (void) setFrame:(int) left :(int) top :(int) width :(int) height;
- (void) setURL:(int) videoSource :(std::string&) videoUrl; - (void) setURL:(int) videoSource :(std::string&) videoUrl;
@ -87,7 +87,7 @@ typedef NS_ENUM(NSInteger, PlayerbackState) {
-(id)init:(void*)videoPlayer -(id)init:(void*)videoPlayer
{ {
if (self = [super init]) { if (self = [super init]) {
self.playerController = [[AVPlayerViewController new] autorelease]; self.playerController = [AVPlayerViewController new];
[self setRepeatEnabled:FALSE]; [self setRepeatEnabled:FALSE];
[self showPlaybackControls:TRUE]; [self showPlaybackControls:TRUE];
@ -103,6 +103,7 @@ typedef NS_ENUM(NSInteger, PlayerbackState) {
-(void) dealloc -(void) dealloc
{ {
_videoPlayer = nullptr;
[self clean]; [self clean];
[self.playerController release]; [self.playerController release];
[super dealloc]; [super dealloc];
@ -110,7 +111,6 @@ typedef NS_ENUM(NSInteger, PlayerbackState) {
-(void) clean -(void) clean
{ {
_videoPlayer = nullptr;
[self stop]; [self stop];
[self removePlayerEventListener]; [self removePlayerEventListener];
[self.playerController.view removeFromSuperview]; [self.playerController.view removeFromSuperview];

View File

@ -30,6 +30,7 @@
"cmake/README.md", "cmake/README.md",
"cmake/images/Xcode_Find_Setting_Name.png", "cmake/images/Xcode_Find_Setting_Name.png",
"cmake/images/Xcode_General_Page.png", "cmake/images/Xcode_General_Page.png",
"cmake/scripts/sync_folder.py",
"cocos/2d/CCAction.cpp", "cocos/2d/CCAction.cpp",
"cocos/2d/CCAction.h", "cocos/2d/CCAction.h",
"cocos/2d/CCActionCamera.cpp", "cocos/2d/CCActionCamera.cpp",

View File

@ -154,6 +154,6 @@ elseif(WINDOWS)
endif() endif()
if(LINUX OR WINDOWS) if(LINUX OR WINDOWS)
set(APP_RES_DIR "$<TARGET_FILE_DIR:${APP_NAME}>/Resources") cocos_get_resource_path(APP_RES_DIR ${APP_NAME})
cocos_copy_target_res(${APP_NAME} COPY_TO ${APP_RES_DIR} FOLDERS ${GAME_RES_FOLDER}) cocos_link_target_res(${APP_NAME} LINK_TO ${APP_RES_DIR} FOLDERS ${GAME_RES_FOLDER})
endif() endif()

View File

@ -146,7 +146,7 @@ elseif(WINDOWS)
endif() endif()
# copy resource on linux or WINDOWS # copy resource on linux or WINDOWS
if(LINUX OR WINDOWS) if(LINUX OR WINDOWS)
set(APP_RES_DIR "$<TARGET_FILE_DIR:${APP_NAME}>/Resources") cocos_get_resource_path(APP_RES_DIR ${APP_NAME})
cocos_copy_target_res(${APP_NAME} COPY_TO ${APP_RES_DIR}/res FOLDERS ${res_res_folders}) cocos_link_target_res(${APP_NAME} LINK_TO ${APP_RES_DIR}/res FOLDERS ${res_res_folders})
cocos_copy_target_res(${APP_NAME} COPY_TO ${APP_RES_DIR}/src FOLDERS ${res_src_folders}) cocos_copy_lua_scripts(${APP_NAME} ${res_src_folders} ${APP_RES_DIR}/src )
endif() endif()

View File

@ -147,6 +147,6 @@ elseif(WINDOWS)
endif() endif()
if(LINUX OR WINDOWS) if(LINUX OR WINDOWS)
set(APP_RES_DIR "$<TARGET_FILE_DIR:${APP_NAME}>/Resources") cocos_get_resource_path(APP_RES_DIR ${APP_NAME})
cocos_copy_target_res(${APP_NAME} COPY_TO ${APP_RES_DIR} FOLDERS ${GAME_RES_FOLDER}) cocos_link_target_res(${APP_NAME} LINK_TO ${APP_RES_DIR} FOLDERS ${GAME_RES_FOLDER})
endif() endif()

View File

@ -420,8 +420,8 @@ elseif(WINDOWS)
endif() endif()
if(LINUX OR WINDOWS) if(LINUX OR WINDOWS)
set(APP_RES_DIR "$<TARGET_FILE_DIR:${APP_NAME}>/Resources") cocos_get_resource_path(APP_RES_DIR ${APP_NAME})
cocos_copy_target_res(${APP_NAME} COPY_TO ${APP_RES_DIR} FOLDERS ${GAME_RES_FOLDER}) cocos_link_target_res(${APP_NAME} LINK_TO ${APP_RES_DIR} FOLDERS ${GAME_RES_FOLDER})
endif() endif()
if(WINDOWS) if(WINDOWS)

View File

@ -123,8 +123,8 @@ elseif(WINDOWS)
endif() endif()
if(LINUX OR WINDOWS) if(LINUX OR WINDOWS)
set(APP_RES_DIR "$<TARGET_FILE_DIR:${APP_NAME}>/Resources") cocos_get_resource_path(APP_RES_DIR ${APP_NAME})
cocos_copy_target_res(${APP_NAME} COPY_TO ${APP_RES_DIR}/res FOLDERS ${res_res_folders}) cocos_link_target_res(${APP_NAME} LINK_TO ${APP_RES_DIR}/res FOLDERS ${res_res_folders})
cocos_copy_target_res(${APP_NAME} COPY_TO ${APP_RES_DIR}/src FOLDERS ${res_src_folders}) cocos_copy_lua_scripts(${APP_NAME} ${res_src_folders} ${APP_RES_DIR}/src )
cocos_copy_target_res(${APP_NAME} COPY_TO ${APP_RES_DIR}/src/cocos FOLDERS ${res_script_folders}) cocos_copy_lua_scripts(${APP_NAME} ${res_script_folders} ${APP_RES_DIR}/src/cocos)
endif() endif()

View File

@ -136,8 +136,8 @@ elseif(WINDOWS)
endif() endif()
if(LINUX OR WINDOWS) if(LINUX OR WINDOWS)
set(APP_RES_DIR "$<TARGET_FILE_DIR:${APP_NAME}>/Resources") cocos_get_resource_path(APP_RES_DIR ${APP_NAME})
cocos_copy_target_res(${APP_NAME} COPY_TO ${APP_RES_DIR}/res FOLDERS ${res_res_folders}) cocos_link_target_res(${APP_NAME} LINK_TO ${APP_RES_DIR}/res FOLDERS ${res_res_folders})
cocos_copy_target_res(${APP_NAME} COPY_TO ${APP_RES_DIR}/src FOLDERS ${res_src_folders}) cocos_copy_lua_scripts(${APP_NAME} ${res_src_folders} ${APP_RES_DIR}/src )
cocos_copy_target_res(${APP_NAME} COPY_TO ${APP_RES_DIR}/src/cocos FOLDERS ${res_script_folders}) cocos_copy_lua_scripts(${APP_NAME} ${res_script_folders} ${APP_RES_DIR}/src/cocos)
endif() endif()

View File

@ -31,6 +31,7 @@ function do_retry()
function build_linux() function build_linux()
{ {
echo "Building tests ..." echo "Building tests ..."
source ../environment.sh
cd $COCOS2DX_ROOT cd $COCOS2DX_ROOT
mkdir -p linux-build mkdir -p linux-build
cd linux-build cd linux-build
@ -208,6 +209,7 @@ function run_pull_request()
fi fi
if [ "$BUILD_TARGET" == "linux_cocos_new_test" ]; then if [ "$BUILD_TARGET" == "linux_cocos_new_test" ]; then
export PATH=$PATH:$COCOS2DX_ROOT/tools/cocos2d-console/bin
genernate_binding_codes genernate_binding_codes
pushd $COCOS2DX_ROOT pushd $COCOS2DX_ROOT
update_cocos_files update_cocos_files