Merge pull request #10 from cocos2d/v4

V4
This commit is contained in:
HALX99 2019-11-19 09:45:15 -06:00 committed by GitHub
commit c0332b7a7f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
19 changed files with 394 additions and 138 deletions

View File

@ -1,38 +1,81 @@
include(CMakeParseArguments)
# copy resource `FILES` and `FOLDERS` to TARGET_FILE_DIR/Resources
function(cocos_copy_target_res cocos_target)
set(oneValueArgs COPY_TO)
set(multiValueArgs FILES FOLDERS)
function(cocos_link_target_res cocos_target)
set(oneValueArgs LINK_TO)
set(multiValueArgs FOLDERS)
cmake_parse_arguments(opt "" "${oneValueArgs}" "${multiValueArgs}" ${ARGN})
# copy files
foreach(cc_file ${opt_FILES})
get_filename_component(file_name ${cc_file} NAME)
add_custom_command(TARGET ${cocos_target} POST_BUILD
#COMMAND ${CMAKE_COMMAND} -E echo "copy-file into Resources: ${file_name} ..."
COMMAND ${CMAKE_COMMAND} -E copy_if_different ${cc_file} "${opt_COPY_TO}/${file_name}"
if(NOT TARGET SYNC_RESOURCE-${cocos_target})
message(WARNING "SyncResource targe for ${cocos_target} is not defined")
return()
endif()
# linking folders
foreach(cc_folder ${opt_FOLDERS})
get_filename_component(link_folder ${opt_LINK_TO} DIRECTORY)
get_filename_component(link_folder_abs ${link_folder} ABSOLUTE)
add_custom_command(TARGET SYNC_RESOURCE-${cocos_target} POST_BUILD
COMMAND ${CMAKE_COMMAND} -E make_directory ${link_folder_abs}
COMMAND ${CMAKE_COMMAND} -E create_symlink ${cc_folder} ${opt_LINK_TO}
)
endforeach()
# copy folders files
foreach(cc_folder ${opt_FOLDERS})
# file(GLOB_RECURSE folder_files "${cc_folder}/*")
# get_filename_component(folder_abs_path ${cc_folder} ABSOLUTE)
# foreach(res_file ${folder_files})
# get_filename_component(res_file_abs_path ${res_file} ABSOLUTE)
# file(RELATIVE_PATH res_file_relat_path ${folder_abs_path} ${res_file_abs_path})
# 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()
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
# save all marked files in `res_out`
function(cocos_mark_multi_resources res_out)
@ -206,6 +249,11 @@ function(setup_cocos_app_config app_name)
if (XCODE)
cocos_config_app_xcode_property(${app_name})
endif()
if(LINUX OR WINDOWS)
cocos_def_copy_resource_target(${app_name})
endif()
endfunction()
# 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})
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_SOURCE_DIR:" ${PROJECT_SOURCE_DIR})
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
message(STATUS "PROJECT_BINARY_DIR:" ${PROJECT_BINARY_DIR})
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)
# include helper functions
@ -35,3 +41,22 @@ include(CocosConfigDefine)
# config libraries dependence
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

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

View File

@ -120,30 +120,63 @@ void SpriteBatchNode::updateShaders(const std::string &vertexShader, const std::
CC_SAFE_RELEASE(_programState);
_programState = new (std::nothrow) backend::ProgramState(program);
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();
const auto& attributeInfo = _programState->getProgram()->getActiveAttributes();
auto iter = attributeInfo.find("a_position");
if(iter != attributeInfo.end())
{
vertexLayout->setAttribute("a_position", iter->second.location, backend::VertexFormat::FLOAT3, 0, false);
}
iter = attributeInfo.find("a_texCoord");
if(iter != attributeInfo.end())
{
vertexLayout->setAttribute("a_texCoord", iter->second.location, backend::VertexFormat::FLOAT2, offsetof(V3F_C4B_T2F, texCoords), false);
}
iter = attributeInfo.find("a_color");
if(iter != attributeInfo.end())
{
vertexLayout->setAttribute("a_color", iter->second.location, backend::VertexFormat::UBYTE4, offsetof(V3F_C4B_T2F, colors), true);
}
///a_position
vertexLayout->setAttribute(backend::ATTRIBUTE_NAME_POSITION,
_programState->getAttributeLocation(backend::Attribute::POSITION),
backend::VertexFormat::FLOAT3,
0,
false);
///a_texCoord
vertexLayout->setAttribute(backend::ATTRIBUTE_NAME_TEXCOORD,
_programState->getAttributeLocation(backend::Attribute::TEXCOORD),
backend::VertexFormat::FLOAT2,
offsetof(V3F_C4B_T2F, texCoords),
false);
///a_color
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));
}
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()
{
Texture2D * texture = new (std::nothrow) Texture2D();
@ -167,7 +200,6 @@ SpriteBatchNode::SpriteBatchNode()
SpriteBatchNode::~SpriteBatchNode()
{
CC_SAFE_RELEASE(_textureAtlas);
CC_SAFE_RELEASE(_programState);
}
// override visit

View File

@ -210,6 +210,11 @@ public:
* @js NA
*/
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.
* This method should be called only when you are dealing with very big AtlasSprite and when most of the Sprite won't be updated.
@ -259,6 +264,8 @@ protected:
void updateAtlasIndex(Sprite* sprite, ssize_t* curIndex);
void swap(ssize_t oldIndex, ssize_t newIndex);
void updateBlendFunc();
void setVertexLayout();
void setUniformLocation();
virtual void updateShaders(const std::string& vertexShader, const std::string& fragmentShader);
@ -268,7 +275,6 @@ protected:
backend::UniformLocation _mvpMatrixLocaiton;
backend::UniformLocation _textureLocation;
backend::ProgramState* _programState = nullptr;
// all descendants: children, grand children, etc...
// There is not need to retain/release these objects, since they are already retained by _children

View File

@ -32,6 +32,7 @@
#include "network/Uri.h"
#include <algorithm>
#include <sstream>
#include <memory>
#include <iterator>
#include "base/ccUTF8.h"
#include "base/CCDirector.h"
@ -79,8 +80,8 @@ public:
std::vector<std::string> getData()const{ return _args; };
virtual std::string stringify()const;
static SocketIOPacket * createPacketWithType(const std::string& type, SocketIOVersion version);
static SocketIOPacket * createPacketWithTypeIndex(int type, SocketIOVersion version);
static std::shared_ptr<SocketIOPacket> createPacketWithType(const std::string& type, SocketIOVersion version);
static std::shared_ptr<SocketIOPacket> createPacketWithTypeIndex(int type, SocketIOVersion version);
protected:
std::string _pId;//id message
std::string _ack;//
@ -305,37 +306,38 @@ SocketIOPacketV10x::~SocketIOPacketV10x()
_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;
switch (version)
if(version == SocketIOPacket::SocketIOVersion::V09x)
{
case SocketIOPacket::SocketIOVersion::V09x:
ret = new (std::nothrow) SocketIOPacket;
break;
case SocketIOPacket::SocketIOVersion::V10x:
ret = new (std::nothrow) SocketIOPacketV10x;
break;
auto ret = std::make_shared<SocketIOPacket>();
ret->initWithType(type);
return ret;
}
ret->initWithType(type);
return ret;
else if(version == SocketIOPacket::SocketIOVersion::V10x)
{
auto ret = std::make_shared<SocketIOPacketV10x>();
ret->initWithType(type);
return ret;
}
return nullptr;
}
SocketIOPacket * SocketIOPacket::createPacketWithTypeIndex(int type, SocketIOPacket::SocketIOVersion version)
std::shared_ptr<SocketIOPacket> SocketIOPacket::createPacketWithTypeIndex(int type, SocketIOPacket::SocketIOVersion version)
{
SocketIOPacket *ret;
switch (version)
if(version == SocketIOPacket::SocketIOVersion::V09x)
{
case SocketIOPacket::SocketIOVersion::V09x:
ret = new (std::nothrow) SocketIOPacket;
break;
case SocketIOPacket::SocketIOVersion::V10x:
return new (std::nothrow) SocketIOPacketV10x;
break;
auto ret = std::make_shared<SocketIOPacket>();
ret->initWithTypeIndex(type);
return ret;
}
ret->initWithTypeIndex(type);
return ret;
else if(version == SocketIOPacket::SocketIOVersion::V10x)
{
auto ret = std::make_shared<SocketIOPacketV10x>();
ret->initWithTypeIndex(type);
return ret;
}
return nullptr;
}
/**
@ -343,8 +345,8 @@ SocketIOPacket * SocketIOPacket::createPacketWithTypeIndex(int type, SocketIOPac
* Clients/endpoints may share the same impl to accomplish multiplexing on the same websocket
*/
class SIOClientImpl :
public cocos2d::Ref,
public WebSocket::Delegate
public WebSocket::Delegate,
public std::enable_shared_from_this<SIOClientImpl>
{
private:
int _heartbeat, _timeout;
@ -362,7 +364,7 @@ public:
SIOClientImpl(const Uri& uri, const std::string& caFilePath);
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 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::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::vector<std::string>& args);
@ -429,7 +431,14 @@ void SIOClientImpl::handshake()
request->setUrl(pre.str());
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");
CCLOGINFO("SIOClientImpl::handshake() waiting");
@ -633,13 +642,13 @@ void SIOClientImpl::disconnect()
_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);
if (s && s->init())
{
return s;
return std::shared_ptr<SIOClientImpl>(s);
}
return nullptr;
@ -657,7 +666,7 @@ void SIOClientImpl::addClient(const std::string& endpoint, SIOClient* client)
void SIOClientImpl::connectToEndpoint(const std::string& endpoint)
{
SocketIOPacket *packet = SocketIOPacket::createPacketWithType("connect", _version);
auto packet = SocketIOPacket::createPacketWithType("connect", _version);
packet->setEndpoint(endpoint);
this->send(packet);
}
@ -685,7 +694,7 @@ void SIOClientImpl::disconnectFromEndpoint(const std::string& endpoint)
void SIOClientImpl::heartbeat(float /*dt*/)
{
SocketIOPacket *packet = SocketIOPacket::createPacketWithType("heartbeat", _version);
auto packet = SocketIOPacket::createPacketWithType("heartbeat", _version);
this->send(packet);
@ -698,7 +707,7 @@ void SIOClientImpl::send(const std::string& endpoint, const std::vector<std::str
switch (_version) {
case SocketIOPacket::SocketIOVersion::V09x:
{
SocketIOPacket *packet = SocketIOPacket::createPacketWithType("message", _version);
auto packet = SocketIOPacket::createPacketWithType("message", _version);
packet->setEndpoint(endpoint);
for(auto &i : s)
{
@ -721,7 +730,7 @@ void SIOClientImpl::send(const std::string& endpoint, const std::string& s)
send(endpoint, t);
}
void SIOClientImpl::send(SocketIOPacket *packet)
void SIOClientImpl::send(std::shared_ptr<SocketIOPacket>& packet)
{
std::string req = packet->toString();
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)
{
CCLOGINFO("Emitting event \"%s\"", eventname.c_str());
SocketIOPacket *packet = SocketIOPacket::createPacketWithType("event", _version);
auto packet = SocketIOPacket::createPacketWithType("event", _version);
packet->setEndpoint(endpoint == "/" ? "" : endpoint);
packet->setEvent(eventname);
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)
{
CCLOGINFO("Emitting event \"%s\"", eventname.c_str());
SocketIOPacket *packet = SocketIOPacket::createPacketWithType("event", _version);
auto packet = SocketIOPacket::createPacketWithType("event", _version);
packet->setEndpoint(endpoint == "/" ? "" : endpoint);
packet->setEvent(eventname);
for (auto &arg : args) {
@ -759,7 +768,9 @@ void SIOClientImpl::onOpen(WebSocket* /*ws*/)
{
_connected = true;
SocketIO::getInstance()->addSocket(_uri.getAuthority(), this);
auto self = shared_from_this();
SocketIO::getInstance()->addSocket(_uri.getAuthority(), self);
if (_version == SocketIOPacket::SocketIOVersion::V10x)
{
@ -767,14 +778,20 @@ void SIOClientImpl::onOpen(WebSocket* /*ws*/)
_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)
{
client.second->onOpen();
}
CCLOGINFO("SIOClientImpl::onOpen socket connected!");
}
void SIOClientImpl::onMessage(WebSocket* /*ws*/, const WebSocket::Data& data)
@ -1020,11 +1037,9 @@ void SIOClientImpl::onClose(WebSocket* /*ws*/)
_connected = false;
if (Director::getInstance())
Director::getInstance()->getScheduler()->unscheduleAllForTarget(this);
SocketIO::getInstance()->removeSocket(_uri.getAuthority());
}
this->release();
}
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
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)
, _connected(false)
, _socket(impl)
@ -1115,7 +1130,6 @@ void SIOClient::disconnect()
{
setConnected(false);
_socket->disconnectFromEndpoint(_path);
this->release();
}
@ -1123,7 +1137,6 @@ void SIOClient::socketClosed()
{
setConnected(false);
_delegate->onClose(this);
this->release();
}
@ -1132,7 +1145,7 @@ bool SIOClient::isConnected() const
return _socket && _socket->_connected && _connected;
}
void SIOClient::setConnected(bool connected)
void SIOClient::setConnected(bool connected)
{
_connected = connected;
}
@ -1198,8 +1211,8 @@ SIOClient* SocketIO::connect(const std::string& uri, SocketIO::SIODelegate& dele
{
Uri uriObj = Uri::parse(uri);
SIOClientImpl *socket = SocketIO::getInstance()->getSocket(uriObj.getAuthority());
SIOClient *c = nullptr;
std::shared_ptr<SIOClientImpl> socket = SocketIO::getInstance()->getSocket(uriObj.getAuthority());
SIOClient * c = nullptr;
std::string path = uriObj.getPath();
if (path == "")
@ -1235,7 +1248,7 @@ SIOClient* SocketIO::connect(const std::string& uri, SocketIO::SIODelegate& dele
c->disconnect();
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);
newSocket->addClient(path, newC);
@ -1248,14 +1261,16 @@ SIOClient* SocketIO::connect(const std::string& uri, SocketIO::SIODelegate& dele
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)

View File

@ -173,10 +173,11 @@ private:
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);
void addSocket(const std::string& uri, SIOClientImpl* socket);
std::shared_ptr<SIOClientImpl> getSocket(const std::string& uri);
void addSocket(const std::string& uri, std::shared_ptr<SIOClientImpl>& socket);
void removeSocket(const std::string& uri);
friend class SIOClientImpl;
@ -202,9 +203,9 @@ private:
std::string _path, _tag;
bool _connected;
SIOClientImpl* _socket;
SocketIO::SIODelegate* _delegate;
std::shared_ptr<SIOClientImpl> _socket;
SocketIO::SIODelegate* _delegate = nullptr;
EventRegistry _eventRegistry;
@ -228,7 +229,7 @@ private:
* @param impl the SIOClientImpl 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.
*/

View File

@ -467,11 +467,11 @@ public:
return false;
}
_data.reserve(LWS_PRE + len);
_data.resize(LWS_PRE, 0x00);
_data.resize(LWS_PRE + len);
if (len > 0)
{
_data.insert(_data.end(), buf, buf + len);
std::copy(buf, buf + len, _data.begin() + LWS_PRE);
}
_payload = _data.data() + LWS_PRE;
@ -544,7 +544,7 @@ WebSocket::WebSocket()
WebSocket::~WebSocket()
{
LOGD("In the destructor of WebSocket (%p)\n", this);
std::lock_guard<std::mutex> lk(__instanceMutex);
if (__websocketInstances != nullptr)

View File

@ -235,7 +235,10 @@ Copyright (C) 2008 Apple Inc. All Rights Reserved.
// Pass the touches to the superview
#pragma mark CCEAGLView - Touch Delegate
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
{
if (self.isKeyboardShown)
[self closeKeyboardOpenedByEditBox];
UITouch* ids[IOS_MAX_TOUCHES_COUNT] = {0};
float xs[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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -31,6 +31,7 @@ function do_retry()
function build_linux()
{
echo "Building tests ..."
source ../environment.sh
cd $COCOS2DX_ROOT
mkdir -p linux-build
cd linux-build
@ -41,7 +42,7 @@ function build_linux()
function build_mac_cmake()
{
NUM_OF_CORES=`getconf _NPROCESSORS_ONLN`
# pushd $COCOS2DX_ROOT
# python -u tools/cocos2d-console/bin/cocos.py --agreement n new -l cpp -p my.pack.qqqq cocos_new_test
# popd
@ -208,6 +209,7 @@ function run_pull_request()
fi
if [ "$BUILD_TARGET" == "linux_cocos_new_test" ]; then
export PATH=$PATH:$COCOS2DX_ROOT/tools/cocos2d-console/bin
genernate_binding_codes
pushd $COCOS2DX_ROOT
update_cocos_files