mirror of https://github.com/axmolengine/axmol.git
fix conflict
This commit is contained in:
commit
103bdb3d37
312
CMakeLists.txt
312
CMakeLists.txt
|
@ -41,60 +41,19 @@ project (Cocos2d-X)
|
|||
# The version number
|
||||
set(COCOS2D_X_VERSION 3.11)
|
||||
|
||||
# define some variables
|
||||
|
||||
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${PROJECT_SOURCE_DIR}/cmake/Modules/")
|
||||
include(CocosBuildHelpers)
|
||||
|
||||
message(${BUILDING_STRING})
|
||||
|
||||
set(USE_WEBP_DEFAULT ON)
|
||||
if(WINRT OR WP8)
|
||||
set(USE_WEBP_DEFAULT OFF)
|
||||
set(COCOS_EXTERNAL_DIR ${CMAKE_CURRENT_SOURCE_DIR}/external)
|
||||
# architecture
|
||||
if (CMAKE_SIZEOF_VOID_P EQUAL 8)
|
||||
set(ARCH_DIR "64-bit")
|
||||
elseif (CMAKE_SIZEOF_VOID_P EQUAL 4)
|
||||
set(ARCH_DIR "32-bit")
|
||||
else()
|
||||
message(FATAL_ERROR "Unsupported architecture, CMake will exit")
|
||||
return()
|
||||
endif()
|
||||
|
||||
set(USE_PREBUILT_LIBS_DEFAULT ON)
|
||||
if(MINGW)
|
||||
set(USE_PREBUILT_LIBS_DEFAULT OFF)
|
||||
endif()
|
||||
|
||||
set(BUILD_CPP_EMPTY_TEST_DEFAULT ON)
|
||||
set(BUILD_CPP_TESTS_DEFAULT ON)
|
||||
set(BUILD_LUA_LIBS_DEFAULT ON)
|
||||
set(BUILD_LUA_TESTS_DEFAULT ON)
|
||||
set(BUILD_JS_LIBS_DEFAULT ON)
|
||||
set(BUILD_JS_TESTS_DEFAULT ON)
|
||||
# TODO: fix test samples for MSVC
|
||||
if(MSVC)
|
||||
set(BUILD_CPP_EMPTY_TEST_DEFAULT OFF)
|
||||
set(BUILD_CPP_TESTS_DEFAULT OFF)
|
||||
set(BUILD_LUA_LIBS_DEFAULT OFF)
|
||||
set(BUILD_LUA_TESTS_DEFAULT OFF)
|
||||
set(BUILD_JS_LIBS_DEFAULT OFF)
|
||||
set(BUILD_JS_TESTS_DEFAULT OFF)
|
||||
endif()
|
||||
|
||||
option(USE_CHIPMUNK "Use chipmunk for physics library" ON)
|
||||
option(USE_BOX2D "Use box2d for physics library" OFF)
|
||||
option(USE_BULLET "Use bullet for physics3d library" ON)
|
||||
option(USE_RECAST "Use Recast for navigation mesh" ON)
|
||||
option(USE_WEBP "Use WebP codec" ${USE_WEBP_DEFAULT})
|
||||
option(BUILD_SHARED_LIBS "Build shared libraries" OFF)
|
||||
option(DEBUG_MODE "Debug or release?" ON)
|
||||
option(BUILD_EXTENSIONS "Build extension library" ON)
|
||||
option(BUILD_EDITOR_SPINE "Build editor support for spine" ON)
|
||||
option(BUILD_EDITOR_COCOSTUDIO "Build editor support for cocostudio" ON)
|
||||
option(BUILD_EDITOR_COCOSBUILDER "Build editor support for cocosbuilder" ON)
|
||||
option(BUILD_CPP_TESTS "Build TestCpp samples" ${BUILD_CPP_TESTS_DEFAULT})
|
||||
option(BUILD_CPP_EMPTY_TEST "Build TestCpp samples" ${BUILD_CPP_EMPTY_TEST_DEFAULT})
|
||||
option(BUILD_LUA_LIBS "Build lua libraries" ${BUILD_LUA_LIBS_DEFAULT})
|
||||
option(BUILD_LUA_TESTS "Build TestLua samples" ${BUILD_LUA_TESTS_DEFAULT})
|
||||
option(BUILD_JS_LIBS "Build js libraries" ${BUILD_JS_LIBS_DEFAULT})
|
||||
option(BUILD_JS_TESTS "Build TestJS samples" ${BUILD_JS_TESTS_DEFAULT})
|
||||
option(USE_PREBUILT_LIBS "Use prebuilt libraries in external directory" ${USE_PREBUILT_LIBS_DEFAULT})
|
||||
|
||||
if(USE_PREBUILT_LIBS AND MINGW)
|
||||
message(FATAL_ERROR "Prebuilt windows libs can't be used with mingw, please use packages.")
|
||||
endif()
|
||||
|
||||
# CMAKE_BUILD_TYPE has precedence over DEBUG_MODE
|
||||
# Still supporting DEBUG_MODE for backwards compatibility
|
||||
if (NOT CMAKE_BUILD_TYPE)
|
||||
|
@ -105,259 +64,32 @@ if (NOT CMAKE_BUILD_TYPE)
|
|||
endif(DEBUG_MODE)
|
||||
endif(NOT CMAKE_BUILD_TYPE)
|
||||
|
||||
set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} -DCOCOS2D_DEBUG=1")
|
||||
set(CMAKE_CXX_FLAGS_DEBUG ${CMAKE_C_FLAGS_DEBUG})
|
||||
include(CocosBuildHelpers)
|
||||
|
||||
# Compiler options
|
||||
if(MSVC)
|
||||
ADD_DEFINITIONS(-D_CRT_SECURE_NO_WARNINGS -D_SCL_SECURE_NO_WARNINGS
|
||||
-wd4251 -wd4244 -wd4334 -wd4005 -wd4820 -wd4710
|
||||
-wd4514 -wd4056 -wd4996 -wd4099)
|
||||
message(${BUILDING_STRING})
|
||||
|
||||
# Use inline debug info (/Z7) format. Or internal error may occur.
|
||||
# Errors looks like: "xmemory0(592): error C3130: Internal Compiler Error: failed to write injected code block to PDB"
|
||||
foreach(lang C CXX)
|
||||
string(REGEX REPLACE "/Z[iI7]" "" CMAKE_${lang}_FLAGS_DEBUG "${CMAKE_${lang}_FLAGS_DEBUG}")
|
||||
set(CMAKE_${lang}_FLAGS_DEBUG "${CMAKE_${lang}_FLAGS_DEBUG} /Z7")
|
||||
endforeach()
|
||||
# SelectModule() is a macro to select building modules
|
||||
include(SelectModule)
|
||||
SelectModule()
|
||||
|
||||
else()
|
||||
set(CMAKE_C_FLAGS_DEBUG "-g -Wall -Wextra -DCOCOS2D_DEBUG=1")
|
||||
set(CMAKE_CXX_FLAGS_DEBUG ${CMAKE_C_FLAGS_DEBUG})
|
||||
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -std=gnu99")
|
||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -Wno-deprecated-declarations -Wno-reorder")
|
||||
if(CLANG)
|
||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -stdlib=libc++")
|
||||
endif()
|
||||
endif(MSVC)
|
||||
|
||||
set(COCOS_EXTERNAL_DIR ${CMAKE_CURRENT_SOURCE_DIR}/external)
|
||||
|
||||
# Some macro definitions
|
||||
if(WINDOWS)
|
||||
|
||||
if(BUILD_SHARED_LIBS)
|
||||
ADD_DEFINITIONS (-D_USRDLL -D_EXPORT_DLL_ -D_USEGUIDLL -D_USREXDLL -D_USRSTUDIODLL)
|
||||
else()
|
||||
ADD_DEFINITIONS (-DCC_STATIC)
|
||||
endif()
|
||||
|
||||
ADD_DEFINITIONS (-DCOCOS2DXWIN32_EXPORTS -D_WINDOWS -DWIN32 -D_WIN32)
|
||||
set(PLATFORM_FOLDER win32)
|
||||
elseif(MACOSX OR APPLE)
|
||||
ADD_DEFINITIONS (-DCC_TARGET_OS_MAC)
|
||||
ADD_DEFINITIONS (-DUSE_FILE32API)
|
||||
set(PLATFORM_FOLDER mac)
|
||||
elseif(LINUX)
|
||||
ADD_DEFINITIONS(-DLINUX)
|
||||
set(PLATFORM_FOLDER linux)
|
||||
elseif(ANDROID)
|
||||
ADD_DEFINITIONS (-DUSE_FILE32API)
|
||||
set(PLATFORM_FOLDER android)
|
||||
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fexceptions")
|
||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fsigned-char -latomic")
|
||||
else()
|
||||
message( FATAL_ERROR "Unsupported platform, CMake will exit" )
|
||||
endif()
|
||||
|
||||
if(MINGW)
|
||||
#add_definitions(-DGLEW_STATIC)
|
||||
add_definitions(-D__SSIZE_T)
|
||||
|
||||
if(CLANG)
|
||||
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ")
|
||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ")
|
||||
endif()
|
||||
endif()
|
||||
|
||||
# architecture
|
||||
if ( CMAKE_SIZEOF_VOID_P EQUAL 8 )
|
||||
set(ARCH_DIR "64-bit")
|
||||
elseif ( CMAKE_SIZEOF_VOID_P EQUAL 4 )
|
||||
set(ARCH_DIR "32-bit")
|
||||
else()
|
||||
message( FATAL_ERROR "Unsupported architecture, CMake will exit" )
|
||||
endif()
|
||||
# set compiler options
|
||||
include(SetCompilerOptions)
|
||||
SetCompilerOptions()
|
||||
|
||||
include_directories(
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/cocos
|
||||
${CMAKE_CURRENT_SOURCE_DIR}
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/cocos
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/deprecated
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/cocos/platform
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/extensions
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/external
|
||||
)
|
||||
|
||||
if(USE_PREBUILT_LIBS)
|
||||
include(CocosUsePrebuiltLibs)
|
||||
endif()
|
||||
|
||||
# desktop platforms
|
||||
if(LINUX OR MACOSX OR WINDOWS)
|
||||
cocos_find_package(OpenGL OPENGL REQUIRED)
|
||||
|
||||
if(LINUX OR WINDOWS)
|
||||
cocos_find_package(GLEW GLEW REQUIRED)
|
||||
#TODO: implement correct schema for pass cocos2d specific requirements to projects
|
||||
include_directories(${GLEW_INCLUDE_DIRS})
|
||||
endif()
|
||||
|
||||
cocos_find_package(GLFW3 GLFW3 REQUIRED)
|
||||
include_directories(${GLFW3_INCLUDE_DIRS})
|
||||
|
||||
if(LINUX)
|
||||
set(CMAKE_THREAD_PREFER_PTHREAD TRUE)
|
||||
find_package(Threads REQUIRED)
|
||||
set(THREADS_LIBRARIES ${CMAKE_THREAD_LIBS_INIT})
|
||||
|
||||
cocos_find_package(FMOD FMOD REQUIRED)
|
||||
cocos_find_package(Fontconfig FONTCONFIG REQUIRED)
|
||||
cocos_find_package(GTK3 GTK3 REQUIRED)
|
||||
endif()
|
||||
|
||||
if(WINDOWS)
|
||||
cocos_find_package(Vorbis VORBIS REQUIRED)
|
||||
cocos_find_package(MPG123 MPG123 REQUIRED)
|
||||
cocos_find_package(OpenAL OPENAL REQUIRED)
|
||||
# because FindOpenAL.cmake set include dir for '#include <al.h>' for portability (not for '#include <AL/al.h>'
|
||||
set(OPENAL_DEFINITIONS "-DOPENAL_PLAIN_INCLUDES")
|
||||
endif()
|
||||
endif(LINUX OR MACOSX OR WINDOWS)
|
||||
|
||||
# Freetype required on all platforms
|
||||
cocos_find_package(Freetype FREETYPE REQUIRED)
|
||||
|
||||
# WebP required if used
|
||||
if(USE_WEBP)
|
||||
cocos_find_package(WebP WEBP REQUIRED)
|
||||
endif(USE_WEBP)
|
||||
|
||||
# Chipmunk
|
||||
if(USE_CHIPMUNK)
|
||||
if(USE_PREBUILT_LIBS)
|
||||
cocos_find_package(Chipmunk CHIPMUNK REQUIRED)
|
||||
endif()
|
||||
add_definitions(-DCC_ENABLE_CHIPMUNK_INTEGRATION=1)
|
||||
if(IOS OR MACOSX)
|
||||
# without this chipmunk will try to use apple defined geometry types, that conflicts with cocos
|
||||
add_definitions(-DCP_USE_CGPOINTS=0)
|
||||
endif()
|
||||
else(USE_CHIPMUNK)
|
||||
add_definitions(-DCC_USE_PHYSICS=0)
|
||||
endif(USE_CHIPMUNK)
|
||||
|
||||
# Box2d (not prebuilded, exists as source)
|
||||
if(USE_BOX2D)
|
||||
if(USE_PREBUILT_LIBS)
|
||||
add_subdirectory(external/Box2D)
|
||||
set(Box2D_INCLUDE_DIRS ${CMAKE_CURRENT_SOURCE_DIR}/external/box2d/include)
|
||||
set(Box2D_LIBRARIES box2d)
|
||||
else()
|
||||
find_package(Box2D REQUIRED CONFIG)
|
||||
# actually Box2D in next line is not a library, it is target exported from Box2DConfig.cmake
|
||||
set(Box2D_LIBRARIES Box2D)
|
||||
endif()
|
||||
message(STATUS "Box2D include dirs: ${Box2D_INCLUDE_DIRS}")
|
||||
add_definitions(-DCC_ENABLE_BOX2D_INTEGRATION=1)
|
||||
else()
|
||||
add_definitions(-DCC_ENABLE_BOX2D_INTEGRATION=0)
|
||||
endif(USE_BOX2D)
|
||||
|
||||
# Bullet (not prebuilded, exists as source)
|
||||
if(USE_BULLET)
|
||||
if(USE_PREBUILT_LIBS)
|
||||
add_subdirectory(external/bullet)
|
||||
set(BULLET_INCLUDE_DIRS ${CMAKE_CURRENT_SOURCE_DIR}/external/bullet)
|
||||
set(BULLET_LIBRARIES bullet)
|
||||
else()
|
||||
cocos_find_package(bullet BULLET REQUIRED)
|
||||
set(BULLET_LIBRARIES bullet)
|
||||
endif()
|
||||
message(STATUS "Bullet include dirs: ${BULLET_INCLUDE_DIRS}")
|
||||
add_definitions(-DCC_ENABLE_BULLET_INTEGRATION=1)
|
||||
add_definitions(-DCC_USE_PHYSICS=1)
|
||||
else()
|
||||
add_definitions(-DCC_ENABLE_BULLET_INTEGRATION=0)
|
||||
add_definitions(-DCC_USE_3D_PHYSICS=0)
|
||||
endif(USE_BULLET)
|
||||
|
||||
# Recast (not prebuilded, exists as source)
|
||||
if(USE_RECAST)
|
||||
if(USE_PREBUILT_LIBS)
|
||||
add_subdirectory(external/recast)
|
||||
set(RECAST_INCLUDE_DIRS ${CMAKE_CURRENT_SOURCE_DIR}/external/recast)
|
||||
set(RECAST_LIBRARIES recast)
|
||||
else()
|
||||
cocos_find_package(recast RECAST REQUIRED)
|
||||
set(RECAST_LIBRARIES recast)
|
||||
endif()
|
||||
message(STATUS "Recast include dirs: ${RECAST_INCLUDE_DIRS}")
|
||||
add_definitions(-DCC_USE_NAVMESH=1)
|
||||
else()
|
||||
add_definitions(-DCC_USE_NAVMESH=0)
|
||||
endif(USE_RECAST)
|
||||
|
||||
# Tinyxml2 (not prebuilded, exists as source)
|
||||
if(USE_PREBUILT_LIBS)
|
||||
add_subdirectory(external/tinyxml2)
|
||||
set(TinyXML2_INCLUDE_DIRS ${CMAKE_CURRENT_SOURCE_DIR}/external/tinyxml2)
|
||||
set(TinyXML2_LIBRARIES tinyxml2)
|
||||
else()
|
||||
cocos_find_package(TinyXML2 TinyXML2 REQUIRED)
|
||||
endif()
|
||||
message(STATUS "TinyXML2 include dirs: ${TinyXML2_INCLUDE_DIRS}")
|
||||
|
||||
# libjpeg
|
||||
cocos_find_package(JPEG JPEG REQUIRED)
|
||||
cocos_find_package(ZLIB ZLIB REQUIRED)
|
||||
|
||||
# minizip (we try to migrate to minizip from https://github.com/nmoinvaz/minizip)
|
||||
# only msys2 currently provides package for this variant, all other
|
||||
# dists have packages from zlib, thats very old for us.
|
||||
# moreover our embedded version modified to quick provide
|
||||
# functionality needed by cocos.
|
||||
if(USE_PREBUILT_LIBS OR NOT MINGW)
|
||||
#TODO: hack! should be in external/unzip/CMakeLists.txt
|
||||
include_directories(${ZLIB_INCLUDE_DIRS})
|
||||
add_subdirectory(external/unzip)
|
||||
set(MINIZIP_INCLUDE_DIRS ${CMAKE_CURRENT_SOURCE_DIR}/external/unzip ${ZLIB_INCLUDE_DIRS})
|
||||
set(MINIZIP_LIBRARIES unzip ${ZLIB_LIBRARIES})
|
||||
message(STATUS "MINIZIP include dirs: ${MINIZIP_INCLUDE_DIRS}")
|
||||
else()
|
||||
cocos_find_package(MINIZIP MINIZIP REQUIRED)
|
||||
# double check that we have needed functions
|
||||
include(CheckLibraryExists)
|
||||
check_library_exists(${MINIZIP_LIBRARIES} "unzGoToFirstFile2" "" MINIZIP_HAS_GOTOFIRSTFILE2)
|
||||
if(NOT MINIZIP_HAS_GOTOFIRSTFILE2)
|
||||
message(FATAL_ERROR "Minizip library on you system very old. Please use recent version from https://github.com/nmoinvaz/minizip or enable USE_PREBUILT_LIBS")
|
||||
endif()
|
||||
add_definitions(-DMINIZIP_FROM_SYSTEM)
|
||||
endif()
|
||||
|
||||
cocos_find_package(PNG PNG REQUIRED)
|
||||
cocos_find_package(TIFF TIFF REQUIRED)
|
||||
cocos_find_package(WEBSOCKETS WEBSOCKETS REQUIRED)
|
||||
cocos_find_package(CURL CURL REQUIRED)
|
||||
|
||||
# flatbuffers
|
||||
if(USE_PREBUILT_LIBS)
|
||||
add_subdirectory(external/flatbuffers)
|
||||
set(FLATBUFFERS_INCLUDE_DIRS ${CMAKE_CURRENT_SOURCE_DIR}/external)
|
||||
message(STATUS "Flatbuffers include dirs: ${FLATBUFFERS_INCLUDE_DIRS}")
|
||||
else()
|
||||
cocos_find_package(flatbuffers flatbuffers REQUIRED)
|
||||
endif()
|
||||
|
||||
# xxhash
|
||||
if(USE_PREBUILT_LIBS)
|
||||
add_subdirectory(external/xxhash)
|
||||
set(XXHASH_INCLUDE_DIRS ${CMAKE_CURRENT_SOURCE_DIR}/external/xxhash)
|
||||
set(XXHASH_LIBRARIES xxhash)
|
||||
else()
|
||||
cocos_find_package(xxhash xxhash REQUIRED)
|
||||
endif()
|
||||
# libcocos2d.a
|
||||
add_subdirectory(cocos)
|
||||
include(BuildModules)
|
||||
BuildModules()
|
||||
|
||||
# build cpp-empty-test
|
||||
if(BUILD_CPP_EMPTY_TEST)
|
||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -0,0 +1,151 @@
|
|||
macro (BuildModules)
|
||||
# desktop platforms
|
||||
if(LINUX OR MACOSX OR WINDOWS)
|
||||
cocos_find_package(OpenGL OPENGL REQUIRED)
|
||||
|
||||
if(LINUX OR WINDOWS)
|
||||
cocos_find_package(GLEW GLEW REQUIRED)
|
||||
#TODO: implement correct schema for pass cocos2d specific requirements to projects
|
||||
include_directories(${GLEW_INCLUDE_DIRS})
|
||||
endif()
|
||||
|
||||
cocos_find_package(GLFW3 GLFW3 REQUIRED)
|
||||
include_directories(${GLFW3_INCLUDE_DIRS})
|
||||
|
||||
if(LINUX)
|
||||
set(CMAKE_THREAD_PREFER_PTHREAD TRUE)
|
||||
find_package(Threads REQUIRED)
|
||||
set(THREADS_LIBRARIES ${CMAKE_THREAD_LIBS_INIT})
|
||||
|
||||
cocos_find_package(FMOD FMOD REQUIRED)
|
||||
cocos_find_package(Fontconfig FONTCONFIG REQUIRED)
|
||||
cocos_find_package(GTK3 GTK3 REQUIRED)
|
||||
endif()
|
||||
|
||||
if(WINDOWS)
|
||||
cocos_find_package(Vorbis VORBIS REQUIRED)
|
||||
cocos_find_package(MPG123 MPG123 REQUIRED)
|
||||
cocos_find_package(OpenAL OPENAL REQUIRED)
|
||||
# because FindOpenAL.cmake set include dir for '#include <al.h>' for portability (not for '#include <AL/al.h>'
|
||||
set(OPENAL_DEFINITIONS "-DOPENAL_PLAIN_INCLUDES")
|
||||
endif()
|
||||
endif(LINUX OR MACOSX OR WINDOWS)
|
||||
|
||||
# Freetype required on all platforms
|
||||
cocos_find_package(Freetype FREETYPE REQUIRED)
|
||||
|
||||
# WebP required if used
|
||||
if(USE_WEBP)
|
||||
cocos_find_package(WebP WEBP REQUIRED)
|
||||
endif(USE_WEBP)
|
||||
|
||||
# Chipmunk
|
||||
if(USE_CHIPMUNK)
|
||||
if(USE_PREBUILT_LIBS)
|
||||
cocos_find_package(Chipmunk CHIPMUNK REQUIRED)
|
||||
endif()
|
||||
endif(USE_CHIPMUNK)
|
||||
|
||||
# Box2d (not prebuilded, exists as source)
|
||||
if(USE_BOX2D)
|
||||
if(USE_PREBUILT_LIBS)
|
||||
add_subdirectory(external/Box2D)
|
||||
set(Box2D_INCLUDE_DIRS ${CMAKE_CURRENT_SOURCE_DIR}/external/box2d/include)
|
||||
set(Box2D_LIBRARIES box2d)
|
||||
else()
|
||||
find_package(Box2D REQUIRED CONFIG)
|
||||
# actually Box2D in next line is not a library, it is target exported from Box2DConfig.cmake
|
||||
set(Box2D_LIBRARIES Box2D)
|
||||
endif()
|
||||
message(STATUS "Box2D include dirs: ${Box2D_INCLUDE_DIRS}")
|
||||
endif(USE_BOX2D)
|
||||
|
||||
# Bullet (not prebuilded, exists as source)
|
||||
if(USE_BULLET)
|
||||
if(USE_PREBUILT_LIBS)
|
||||
add_subdirectory(external/bullet)
|
||||
set(BULLET_INCLUDE_DIRS ${CMAKE_CURRENT_SOURCE_DIR}/external/bullet)
|
||||
set(BULLET_LIBRARIES bullet)
|
||||
else()
|
||||
cocos_find_package(bullet BULLET REQUIRED)
|
||||
set(BULLET_LIBRARIES bullet)
|
||||
endif()
|
||||
message(STATUS "Bullet include dirs: ${BULLET_INCLUDE_DIRS}")
|
||||
endif(USE_BULLET)
|
||||
|
||||
# Recast (not prebuilded, exists as source)
|
||||
if(USE_RECAST)
|
||||
if(USE_PREBUILT_LIBS)
|
||||
add_subdirectory(external/recast)
|
||||
set(RECAST_INCLUDE_DIRS ${CMAKE_CURRENT_SOURCE_DIR}/external/recast)
|
||||
set(RECAST_LIBRARIES recast)
|
||||
else()
|
||||
cocos_find_package(recast RECAST REQUIRED)
|
||||
set(RECAST_LIBRARIES recast)
|
||||
endif()
|
||||
message(STATUS "Recast include dirs: ${RECAST_INCLUDE_DIRS}")
|
||||
endif(USE_RECAST)
|
||||
|
||||
# Tinyxml2 (not prebuilded, exists as source)
|
||||
if(USE_PREBUILT_LIBS)
|
||||
add_subdirectory(external/tinyxml2)
|
||||
set(TinyXML2_INCLUDE_DIRS ${CMAKE_CURRENT_SOURCE_DIR}/external/tinyxml2)
|
||||
set(TinyXML2_LIBRARIES tinyxml2)
|
||||
else()
|
||||
cocos_find_package(TinyXML2 TinyXML2 REQUIRED)
|
||||
endif()
|
||||
message(STATUS "TinyXML2 include dirs: ${TinyXML2_INCLUDE_DIRS}")
|
||||
|
||||
# libjpeg
|
||||
cocos_find_package(JPEG JPEG REQUIRED)
|
||||
cocos_find_package(ZLIB ZLIB REQUIRED)
|
||||
|
||||
# minizip (we try to migrate to minizip from https://github.com/nmoinvaz/minizip)
|
||||
# only msys2 currently provides package for this variant, all other
|
||||
# dists have packages from zlib, thats very old for us.
|
||||
# moreover our embedded version modified to quick provide
|
||||
# functionality needed by cocos.
|
||||
if(USE_PREBUILT_LIBS OR NOT MINGW)
|
||||
#TODO: hack! should be in external/unzip/CMakeLists.txt
|
||||
include_directories(${ZLIB_INCLUDE_DIRS})
|
||||
add_subdirectory(external/unzip)
|
||||
set(MINIZIP_INCLUDE_DIRS ${CMAKE_CURRENT_SOURCE_DIR}/external/unzip ${ZLIB_INCLUDE_DIRS})
|
||||
set(MINIZIP_LIBRARIES unzip ${ZLIB_LIBRARIES})
|
||||
message(STATUS "MINIZIP include dirs: ${MINIZIP_INCLUDE_DIRS}")
|
||||
else()
|
||||
cocos_find_package(MINIZIP MINIZIP REQUIRED)
|
||||
# double check that we have needed functions
|
||||
include(CheckLibraryExists)
|
||||
check_library_exists(${MINIZIP_LIBRARIES} "unzGoToFirstFile2" "" MINIZIP_HAS_GOTOFIRSTFILE2)
|
||||
if(NOT MINIZIP_HAS_GOTOFIRSTFILE2)
|
||||
message(FATAL_ERROR "Minizip library on you system very old. Please use recent version from https://github.com/nmoinvaz/minizip or enable USE_PREBUILT_LIBS")
|
||||
return()
|
||||
endif()
|
||||
endif()
|
||||
|
||||
cocos_find_package(PNG PNG REQUIRED)
|
||||
cocos_find_package(TIFF TIFF REQUIRED)
|
||||
cocos_find_package(WEBSOCKETS WEBSOCKETS REQUIRED)
|
||||
cocos_find_package(CURL CURL REQUIRED)
|
||||
|
||||
# flatbuffers
|
||||
if(USE_PREBUILT_LIBS)
|
||||
add_subdirectory(external/flatbuffers)
|
||||
set(FLATBUFFERS_INCLUDE_DIRS ${CMAKE_CURRENT_SOURCE_DIR}/external)
|
||||
message(STATUS "Flatbuffers include dirs: ${FLATBUFFERS_INCLUDE_DIRS}")
|
||||
else()
|
||||
cocos_find_package(flatbuffers flatbuffers REQUIRED)
|
||||
endif()
|
||||
|
||||
# xxhash
|
||||
if(USE_PREBUILT_LIBS)
|
||||
add_subdirectory(external/xxhash)
|
||||
set(XXHASH_INCLUDE_DIRS ${CMAKE_CURRENT_SOURCE_DIR}/external/xxhash)
|
||||
set(XXHASH_LIBRARIES xxhash)
|
||||
else()
|
||||
cocos_find_package(xxhash xxhash REQUIRED)
|
||||
endif()
|
||||
|
||||
# libcocos2d.a
|
||||
add_subdirectory(cocos)
|
||||
endmacro(BuildModules)
|
|
@ -0,0 +1,52 @@
|
|||
macro (SelectModule)
|
||||
set(USE_WEBP_DEFAULT ON)
|
||||
if(WINRT OR WP8)
|
||||
set(USE_WEBP_DEFAULT OFF)
|
||||
endif()
|
||||
|
||||
set(USE_PREBUILT_LIBS_DEFAULT ON)
|
||||
if(MINGW)
|
||||
set(USE_PREBUILT_LIBS_DEFAULT OFF)
|
||||
endif()
|
||||
|
||||
set(BUILD_CPP_EMPTY_TEST_DEFAULT ON)
|
||||
set(BUILD_CPP_TESTS_DEFAULT ON)
|
||||
set(BUILD_LUA_LIBS_DEFAULT ON)
|
||||
set(BUILD_LUA_TESTS_DEFAULT ON)
|
||||
set(BUILD_JS_LIBS_DEFAULT ON)
|
||||
set(BUILD_JS_TESTS_DEFAULT ON)
|
||||
# TODO: fix test samples for MSVC
|
||||
if(MSVC)
|
||||
set(BUILD_CPP_EMPTY_TEST_DEFAULT OFF)
|
||||
set(BUILD_CPP_TESTS_DEFAULT OFF)
|
||||
set(BUILD_LUA_LIBS_DEFAULT OFF)
|
||||
set(BUILD_LUA_TESTS_DEFAULT OFF)
|
||||
set(BUILD_JS_LIBS_DEFAULT OFF)
|
||||
set(BUILD_JS_TESTS_DEFAULT OFF)
|
||||
endif()
|
||||
|
||||
option(USE_CHIPMUNK "Use chipmunk for physics library" ON)
|
||||
option(USE_BOX2D "Use box2d for physics library" OFF)
|
||||
option(USE_BULLET "Use bullet for physics3d library" ON)
|
||||
option(USE_RECAST "Use Recast for navigation mesh" ON)
|
||||
option(USE_WEBP "Use WebP codec" ${USE_WEBP_DEFAULT})
|
||||
option(BUILD_SHARED_LIBS "Build shared libraries" OFF)
|
||||
option(DEBUG_MODE "Debug or release?" ON)
|
||||
option(BUILD_EXTENSIONS "Build extension library" ON)
|
||||
option(BUILD_EDITOR_SPINE "Build editor support for spine" ON)
|
||||
option(BUILD_EDITOR_COCOSTUDIO "Build editor support for cocostudio" ON)
|
||||
option(BUILD_EDITOR_COCOSBUILDER "Build editor support for cocosbuilder" ON)
|
||||
option(BUILD_CPP_TESTS "Build TestCpp samples" ${BUILD_CPP_TESTS_DEFAULT})
|
||||
option(BUILD_CPP_EMPTY_TEST "Build TestCpp samples" ${BUILD_CPP_EMPTY_TEST_DEFAULT})
|
||||
option(BUILD_LUA_LIBS "Build lua libraries" ${BUILD_LUA_LIBS_DEFAULT})
|
||||
option(BUILD_LUA_TESTS "Build TestLua samples" ${BUILD_LUA_TESTS_DEFAULT})
|
||||
option(BUILD_JS_LIBS "Build js libraries" ${BUILD_JS_LIBS_DEFAULT})
|
||||
option(BUILD_JS_TESTS "Build TestJS samples" ${BUILD_JS_TESTS_DEFAULT})
|
||||
option(USE_PREBUILT_LIBS "Use prebuilt libraries in external directory" ${USE_PREBUILT_LIBS_DEFAULT})
|
||||
|
||||
if(USE_PREBUILT_LIBS AND MINGW)
|
||||
message(FATAL_ERROR "Prebuilt windows libs can't be used with mingw, please use packages.")
|
||||
return()
|
||||
endif()
|
||||
|
||||
endmacro(SelectModule)
|
|
@ -0,0 +1,104 @@
|
|||
macro (SetCompilerOptions)
|
||||
set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} -DCOCOS2D_DEBUG=1")
|
||||
set(CMAKE_CXX_FLAGS_DEBUG ${CMAKE_C_FLAGS_DEBUG})
|
||||
|
||||
# definitions for chipmunk
|
||||
if (USE_CHIPMUNK)
|
||||
add_definitions(-DCC_ENABLE_CHIPMUNK_INTEGRATION=1)
|
||||
if (IOS OR MACOSX)
|
||||
# without this chipmunk will try to use apple defined geometry types, that conflicts with cocos
|
||||
add_definitions(-DCP_USE_CGPOINTS=0)
|
||||
endif()
|
||||
else()
|
||||
add_definitions(-DCC_USE_PHYSICS=0)
|
||||
endif()
|
||||
|
||||
# definitions for box2d
|
||||
if (USE_BOX2D)
|
||||
add_definitions(-DCC_ENABLE_BOX2D_INTEGRATION=1)
|
||||
else()
|
||||
add_definitions(-DCC_ENABLE_BOX2D_INTEGRATION=0)
|
||||
endif()
|
||||
|
||||
# definitions for bullet
|
||||
if (USE_BULLET)
|
||||
add_definitions(-DCC_ENABLE_BULLET_INTEGRATION=1)
|
||||
add_definitions(-DCC_USE_PHYSICS=1)
|
||||
else()
|
||||
add_definitions(-DCC_ENABLE_BULLET_INTEGRATION=0)
|
||||
add_definitions(-DCC_USE_3D_PHYSICS=0)
|
||||
endif()
|
||||
|
||||
# definitions for recast
|
||||
if (USE_RECAST)
|
||||
add_definitions(-DCC_USE_NAVMESH=1)
|
||||
else()
|
||||
add_definitions(-DCC_USE_NAVMESH=0)
|
||||
endif()
|
||||
|
||||
# Compiler options
|
||||
if(MSVC)
|
||||
add_definitions(-D_CRT_SECURE_NO_WARNINGS -D_SCL_SECURE_NO_WARNINGS
|
||||
-wd4251 -wd4244 -wd4334 -wd4005 -wd4820 -wd4710
|
||||
-wd4514 -wd4056 -wd4996 -wd4099)
|
||||
|
||||
# Use inline debug info (/Z7) format. Or internal error may occur.
|
||||
# Errors looks like: "xmemory0(592): error C3130: Internal Compiler Error: failed to write injected code block to PDB"
|
||||
foreach(lang C CXX)
|
||||
string(REGEX REPLACE "/Z[iI7]" "" CMAKE_${lang}_FLAGS_DEBUG "${CMAKE_${lang}_FLAGS_DEBUG}")
|
||||
set(CMAKE_${lang}_FLAGS_DEBUG "${CMAKE_${lang}_FLAGS_DEBUG} /Z7")
|
||||
endforeach()
|
||||
|
||||
else()
|
||||
set(CMAKE_C_FLAGS_DEBUG "-g -Wall -Wextra")
|
||||
set(CMAKE_CXX_FLAGS_DEBUG ${CMAKE_C_FLAGS_DEBUG})
|
||||
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -std=gnu99")
|
||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -Wno-deprecated-declarations -Wno-reorder")
|
||||
if(CLANG)
|
||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -stdlib=libc++")
|
||||
endif()
|
||||
endif(MSVC)
|
||||
|
||||
# Some macro definitions
|
||||
if(WINDOWS)
|
||||
|
||||
if(BUILD_SHARED_LIBS)
|
||||
add_definitions(-D_USRDLL -D_EXPORT_DLL_ -D_USEGUIDLL -D_USREXDLL -D_USRSTUDIODLL)
|
||||
else()
|
||||
add_definitions(-DCC_STATIC)
|
||||
endif()
|
||||
|
||||
add_definitions(-DCOCOS2DXWIN32_EXPORTS -D_WINDOWS -DWIN32 -D_WIN32)
|
||||
set(PLATFORM_FOLDER win32)
|
||||
elseif(MACOSX OR APPLE)
|
||||
add_definitions(-DCC_TARGET_OS_MAC)
|
||||
add_definitions(-DUSE_FILE32API)
|
||||
set(PLATFORM_FOLDER mac)
|
||||
elseif(LINUX)
|
||||
add_definitions(-DLINUX)
|
||||
set(PLATFORM_FOLDER linux)
|
||||
elseif(ANDROID)
|
||||
add_definitions(-DUSE_FILE32API)
|
||||
set(PLATFORM_FOLDER android)
|
||||
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fexceptions")
|
||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fsigned-char -latomic")
|
||||
else()
|
||||
message( FATAL_ERROR "Unsupported platform, CMake will exit" )
|
||||
return()
|
||||
endif()
|
||||
|
||||
if(MINGW)
|
||||
#add_definitions(-DGLEW_STATIC)
|
||||
add_definitions(-D__SSIZE_T)
|
||||
|
||||
if(CLANG)
|
||||
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ")
|
||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ")
|
||||
endif()
|
||||
endif()
|
||||
|
||||
if (MINGW OR NOT USE_PREBUILT_LIBS)
|
||||
add_definitions(-DMINIZIP_FROM_SYSTEM)
|
||||
endif()
|
||||
|
||||
endmacro (SetCompilerOptions)
|
|
@ -2,7 +2,7 @@
|
|||
Copyright (c) 2008-2010 Ricardo Quesada
|
||||
Copyright (c) 2010-2012 cocos2d-x.org
|
||||
Copyright (c) 2011 Zynga Inc.
|
||||
Copyright (c) 2013-2014 Chukong Technologies Inc.
|
||||
Copyright (c) 2013-2016 Chukong Technologies Inc.
|
||||
|
||||
http://www.cocos2d-x.org
|
||||
|
||||
|
@ -114,6 +114,12 @@ Speed* Speed::create(ActionInterval* action, float speed)
|
|||
bool Speed::initWithAction(ActionInterval *action, float speed)
|
||||
{
|
||||
CCASSERT(action != nullptr, "action must not be NULL");
|
||||
if (action == nullptr)
|
||||
{
|
||||
log("Speed::initWithAction error: action is nullptr!");
|
||||
return false;
|
||||
}
|
||||
|
||||
action->retain();
|
||||
_innerAction = action;
|
||||
_speed = speed;
|
||||
|
@ -123,21 +129,28 @@ bool Speed::initWithAction(ActionInterval *action, float speed)
|
|||
Speed *Speed::clone() const
|
||||
{
|
||||
// no copy constructor
|
||||
auto a = new (std::nothrow) Speed();
|
||||
a->initWithAction(_innerAction->clone(), _speed);
|
||||
a->autorelease();
|
||||
return a;
|
||||
if (_innerAction)
|
||||
return Speed::create(_innerAction->clone(), _speed);
|
||||
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
void Speed::startWithTarget(Node* target)
|
||||
{
|
||||
Action::startWithTarget(target);
|
||||
_innerAction->startWithTarget(target);
|
||||
if (target && _innerAction)
|
||||
{
|
||||
Action::startWithTarget(target);
|
||||
_innerAction->startWithTarget(target);
|
||||
}
|
||||
else
|
||||
log("Speed::startWithTarget error: target(%p) or _innerAction(%p) is nullptr!", target, _innerAction);
|
||||
}
|
||||
|
||||
void Speed::stop()
|
||||
{
|
||||
_innerAction->stop();
|
||||
if (_innerAction)
|
||||
_innerAction->stop();
|
||||
|
||||
Action::stop();
|
||||
}
|
||||
|
||||
|
@ -153,7 +166,10 @@ bool Speed::isDone() const
|
|||
|
||||
Speed *Speed::reverse() const
|
||||
{
|
||||
return Speed::create(_innerAction->reverse(), _speed);
|
||||
if (_innerAction)
|
||||
return Speed::create(_innerAction->reverse(), _speed);
|
||||
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
void Speed::setInnerAction(ActionInterval *action)
|
||||
|
@ -176,23 +192,33 @@ Follow::~Follow()
|
|||
|
||||
Follow* Follow::create(Node *followedNode, const Rect& rect/* = Rect::ZERO*/)
|
||||
{
|
||||
return createWithOffset(followedNode, 0.0, 0.0,rect);
|
||||
}
|
||||
|
||||
Follow* Follow::createWithOffset(Node* followedNode,float xOffset,float yOffset,const Rect& rect/*= Rect::ZERO*/){
|
||||
|
||||
|
||||
Follow *follow = new (std::nothrow) Follow();
|
||||
if (follow && follow->initWithTarget(followedNode, rect))
|
||||
|
||||
bool valid;
|
||||
|
||||
valid = follow->initWithTargetAndOffset(followedNode, xOffset, yOffset,rect);
|
||||
|
||||
if (follow && valid)
|
||||
{
|
||||
follow->autorelease();
|
||||
return follow;
|
||||
}
|
||||
CC_SAFE_DELETE(follow);
|
||||
|
||||
delete follow;
|
||||
return nullptr;
|
||||
|
||||
}
|
||||
|
||||
Follow* Follow::clone() const
|
||||
{
|
||||
// no copy constructor
|
||||
auto a = new (std::nothrow) Follow();
|
||||
a->initWithTarget(_followedNode, _worldRect);
|
||||
a->autorelease();
|
||||
return a;
|
||||
return Follow::createWithOffset(_followedNode, _offsetX,_offsetY,_worldRect);
|
||||
|
||||
}
|
||||
|
||||
Follow* Follow::reverse() const
|
||||
|
@ -200,9 +226,14 @@ Follow* Follow::reverse() const
|
|||
return clone();
|
||||
}
|
||||
|
||||
bool Follow::initWithTarget(Node *followedNode, const Rect& rect/* = Rect::ZERO*/)
|
||||
bool Follow::initWithTargetAndOffset(Node *followedNode, float xOffset,float yOffset,const Rect& rect)
|
||||
{
|
||||
CCASSERT(followedNode != nullptr, "FollowedNode can't be NULL");
|
||||
if(followedNode == nullptr)
|
||||
{
|
||||
log("Follow::initWithTarget error: followedNode is nullptr!");
|
||||
return false;
|
||||
}
|
||||
|
||||
followedNode->retain();
|
||||
_followedNode = followedNode;
|
||||
|
@ -213,7 +244,11 @@ bool Follow::initWithTarget(Node *followedNode, const Rect& rect/* = Rect::ZERO*
|
|||
Size winSize = Director::getInstance()->getWinSize();
|
||||
_fullScreenSize.set(winSize.width, winSize.height);
|
||||
_halfScreenSize = _fullScreenSize * 0.5f;
|
||||
|
||||
_offsetX=xOffset;
|
||||
_offsetY=yOffset;
|
||||
_halfScreenSize.x += _offsetX;
|
||||
_halfScreenSize.y += _offsetY;
|
||||
|
||||
if (_boundarySet)
|
||||
{
|
||||
_leftBoundary = -((rect.origin.x+rect.size.width) - _fullScreenSize.x);
|
||||
|
@ -243,6 +278,11 @@ bool Follow::initWithTarget(Node *followedNode, const Rect& rect/* = Rect::ZERO*
|
|||
return true;
|
||||
}
|
||||
|
||||
bool Follow::initWithTarget(Node *followedNode, const Rect& rect /*= Rect::ZERO*/){
|
||||
|
||||
return initWithTargetAndOffset(followedNode, 0.0, 0.0,rect);
|
||||
|
||||
}
|
||||
void Follow::step(float dt)
|
||||
{
|
||||
CC_UNUSED_PARAM(dt);
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
Copyright (c) 2008-2010 Ricardo Quesada
|
||||
Copyright (c) 2010-2012 cocos2d-x.org
|
||||
Copyright (c) 2011 Zynga Inc.
|
||||
Copyright (c) 2013-2014 Chukong Technologies Inc.
|
||||
Copyright (c) 2013-2016 Chukong Technologies Inc.
|
||||
|
||||
http://www.cocos2d-x.org
|
||||
|
||||
|
@ -323,8 +323,27 @@ public:
|
|||
* @param followedNode The node to be followed.
|
||||
* @param rect The boundary. If \p rect is equal to Rect::ZERO, it'll work
|
||||
* with no boundary.
|
||||
*/
|
||||
*/
|
||||
|
||||
static Follow* create(Node *followedNode, const Rect& rect = Rect::ZERO);
|
||||
|
||||
/**
|
||||
* Creates the action with a set boundary or with no boundary with offsets.
|
||||
*
|
||||
* @param followedNode The node to be followed.
|
||||
* @param rect The boundary. If \p rect is equal to Rect::ZERO, it'll work
|
||||
* with no boundary.
|
||||
* @param xOffset The horizontal offset from the center of the screen from which the
|
||||
* node is to be followed.It can be positive,negative or zero.If
|
||||
* set to zero the node will be horizontally centered followed.
|
||||
* @param yOffset The vertical offset from the center of the screen from which the
|
||||
* node is to be followed.It can be positive,negative or zero.
|
||||
* If set to zero the node will be vertically centered followed.
|
||||
* If both xOffset and yOffset are set to zero,then the node will be horizontally and vertically centered followed.
|
||||
*/
|
||||
|
||||
static Follow* createWithOffset(Node* followedNode,float xOffset,float yOffset,const Rect& rect = Rect::ZERO);
|
||||
|
||||
/** Return boundarySet.
|
||||
*
|
||||
* @return Return boundarySet.
|
||||
|
@ -367,6 +386,8 @@ CC_CONSTRUCTOR_ACCESS:
|
|||
, _rightBoundary(0.0)
|
||||
, _topBoundary(0.0)
|
||||
, _bottomBoundary(0.0)
|
||||
, _offsetX(0.0)
|
||||
, _offsetY(0.0)
|
||||
, _worldRect(Rect::ZERO)
|
||||
{}
|
||||
/**
|
||||
|
@ -381,8 +402,26 @@ CC_CONSTRUCTOR_ACCESS:
|
|||
* @param followedNode The node to be followed.
|
||||
* @param rect The boundary. If \p rect is equal to Rect::ZERO, it'll work
|
||||
* with no boundary.
|
||||
*/
|
||||
*/
|
||||
bool initWithTarget(Node *followedNode, const Rect& rect = Rect::ZERO);
|
||||
|
||||
|
||||
/**
|
||||
* Initializes the action with a set boundary or with no boundary with offsets.
|
||||
*
|
||||
* @param followedNode The node to be followed.
|
||||
* @param rect The boundary. If \p rect is equal to Rect::ZERO, it'll work
|
||||
* with no boundary.
|
||||
* @param xOffset The horizontal offset from the center of the screen from which the
|
||||
* node is to be followed.It can be positive,negative or zero.If
|
||||
* set to zero the node will be horizontally centered followed.
|
||||
* @param yOffset The vertical offset from the center of the screen from which the
|
||||
* node is to be followed.It can be positive,negative or zero.
|
||||
* If set to zero the node will be vertically centered followed.
|
||||
* If both xOffset and yOffset are set to zero,then the node will be horizontally and vertically centered followed.
|
||||
|
||||
*/
|
||||
bool initWithTargetAndOffset(Node *followedNode,float xOffset,float yOffset,const Rect& rect = Rect::ZERO);
|
||||
|
||||
protected:
|
||||
/** Node to follow. */
|
||||
|
@ -403,6 +442,11 @@ protected:
|
|||
float _rightBoundary;
|
||||
float _topBoundary;
|
||||
float _bottomBoundary;
|
||||
|
||||
/** Horizontal (x) and vertical (y) offset values. */
|
||||
float _offsetX;
|
||||
float _offsetY;
|
||||
|
||||
Rect _worldRect;
|
||||
|
||||
private:
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
Copyright (c) 2008-2010 Ricardo Quesada
|
||||
Copyright (c) 2010-2012 cocos2d-x.org
|
||||
Copyright (c) 2011 Zynga Inc.
|
||||
Copyright (c) 2013-2014 Chukong Technologies Inc.
|
||||
Copyright (c) 2013-2016 Chukong Technologies Inc.
|
||||
|
||||
http://www.cocos2d-x.org
|
||||
|
||||
|
@ -46,10 +46,15 @@ void ActionCamera::startWithTarget(Node *target)
|
|||
|
||||
ActionCamera* ActionCamera::clone() const
|
||||
{
|
||||
// no copy constructor
|
||||
auto a = new (std::nothrow) ActionCamera();
|
||||
a->autorelease();
|
||||
return a;
|
||||
auto action = new (std::nothrow) ActionCamera();
|
||||
if (action)
|
||||
{
|
||||
action->autorelease();
|
||||
return action;
|
||||
}
|
||||
|
||||
delete action;
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
ActionCamera * ActionCamera::reverse() const
|
||||
|
@ -100,7 +105,8 @@ void ActionCamera::updateTransform()
|
|||
|
||||
Mat4 mv = Mat4::IDENTITY;
|
||||
|
||||
if(needsTranslation) {
|
||||
if(needsTranslation)
|
||||
{
|
||||
Mat4 t;
|
||||
Mat4::createTranslation(anchorPoint.x, anchorPoint.y, 0, &t);
|
||||
mv = mv * t;
|
||||
|
@ -108,8 +114,8 @@ void ActionCamera::updateTransform()
|
|||
|
||||
mv = mv * lookupMatrix;
|
||||
|
||||
if(needsTranslation) {
|
||||
|
||||
if(needsTranslation)
|
||||
{
|
||||
Mat4 t;
|
||||
Mat4::createTranslation(-anchorPoint.x, -anchorPoint.y, 0, &t);
|
||||
mv = mv * t;
|
||||
|
@ -148,22 +154,20 @@ OrbitCamera::~OrbitCamera()
|
|||
OrbitCamera * OrbitCamera::create(float t, float radius, float deltaRadius, float angleZ, float deltaAngleZ, float angleX, float deltaAngleX)
|
||||
{
|
||||
OrbitCamera * obitCamera = new (std::nothrow) OrbitCamera();
|
||||
if(obitCamera->initWithDuration(t, radius, deltaRadius, angleZ, deltaAngleZ, angleX, deltaAngleX))
|
||||
if(obitCamera && obitCamera->initWithDuration(t, radius, deltaRadius, angleZ, deltaAngleZ, angleX, deltaAngleX))
|
||||
{
|
||||
obitCamera->autorelease();
|
||||
return obitCamera;
|
||||
}
|
||||
CC_SAFE_DELETE(obitCamera);
|
||||
|
||||
delete obitCamera;
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
OrbitCamera* OrbitCamera::clone() const
|
||||
{
|
||||
// no copy constructor
|
||||
auto a = new (std::nothrow) OrbitCamera();
|
||||
a->initWithDuration(_duration, _radius, _deltaRadius, _angleZ, _deltaAngleZ, _angleX, _deltaAngleX);
|
||||
a->autorelease();
|
||||
return a;
|
||||
// no copy constructor
|
||||
return OrbitCamera::create(_duration, _radius, _deltaRadius, _angleZ, _deltaAngleZ, _angleX, _deltaAngleX);
|
||||
}
|
||||
|
||||
bool OrbitCamera::initWithDuration(float t, float radius, float deltaRadius, float angleZ, float deltaAngleZ, float angleX, float deltaAngleX)
|
||||
|
@ -190,11 +194,11 @@ void OrbitCamera::startWithTarget(Node *target)
|
|||
|
||||
float r, zenith, azimuth;
|
||||
this->sphericalRadius(&r, &zenith, &azimuth);
|
||||
if( isnan(_radius) )
|
||||
if( std::isnan(_radius) )
|
||||
_radius = r;
|
||||
if( isnan(_angleZ) )
|
||||
if( std::isnan(_angleZ) )
|
||||
_angleZ = (float)CC_RADIANS_TO_DEGREES(zenith);
|
||||
if( isnan(_angleX) )
|
||||
if( std::isnan(_angleX) )
|
||||
_angleX = (float)CC_RADIANS_TO_DEGREES(azimuth);
|
||||
|
||||
_radZ = (float)CC_DEGREES_TO_RADIANS(_angleZ);
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
Copyright (c) 2008-2010 Ricardo Quesada
|
||||
Copyright (c) 2010-2012 cocos2d-x.org
|
||||
Copyright (c) 2011 Zynga Inc.
|
||||
Copyright (c) 2013-2014 Chukong Technologies Inc.
|
||||
Copyright (c) 2013-2016 Chukong Technologies Inc.
|
||||
|
||||
http://www.cocos2d-x.org
|
||||
|
||||
|
@ -61,7 +61,7 @@ public:
|
|||
// Overrides
|
||||
virtual void startWithTarget(Node *target) override;
|
||||
virtual ActionCamera * reverse() const override;
|
||||
virtual ActionCamera *clone() const override;
|
||||
virtual ActionCamera *clone() const override;
|
||||
|
||||
/* Sets the Eye value of the Camera.
|
||||
*
|
||||
|
@ -142,7 +142,7 @@ public:
|
|||
void sphericalRadius(float *r, float *zenith, float *azimuth);
|
||||
|
||||
// Overrides
|
||||
OrbitCamera *clone() const override;
|
||||
OrbitCamera *clone() const override;
|
||||
virtual void startWithTarget(Node *target) override;
|
||||
virtual void update(float time) override;
|
||||
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
* Copyright (c) 2008 Radu Gruian
|
||||
* Copyright (c) 2011 Vit Valentin
|
||||
* Copyright (c) 2012 cocos2d-x.org
|
||||
* Copyright (c) 2013-2014 Chukong Technologies Inc.
|
||||
* Copyright (c) 2013-2016 Chukong Technologies Inc.
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
|
@ -44,23 +44,16 @@ NS_CC_BEGIN;
|
|||
PointArray* PointArray::create(ssize_t capacity)
|
||||
{
|
||||
PointArray* pointArray = new (std::nothrow) PointArray();
|
||||
if (pointArray)
|
||||
if (pointArray && pointArray->initWithCapacity(capacity))
|
||||
{
|
||||
if (pointArray->initWithCapacity(capacity))
|
||||
{
|
||||
pointArray->autorelease();
|
||||
}
|
||||
else
|
||||
{
|
||||
delete pointArray;
|
||||
pointArray = nullptr;
|
||||
}
|
||||
pointArray->autorelease();
|
||||
return pointArray;
|
||||
}
|
||||
|
||||
return pointArray;
|
||||
delete pointArray;
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
|
||||
bool PointArray::initWithCapacity(ssize_t capacity)
|
||||
{
|
||||
_controlPoints = new (std::nothrow) vector<Vec2*>();
|
||||
|
@ -70,7 +63,7 @@ bool PointArray::initWithCapacity(ssize_t capacity)
|
|||
|
||||
PointArray* PointArray::clone() const
|
||||
{
|
||||
vector<Vec2*> *newArray = new vector<Vec2*>();
|
||||
vector<Vec2*> *newArray = new (std::nothrow) vector<Vec2*>();
|
||||
vector<Vec2*>::iterator iter;
|
||||
for (iter = _controlPoints->begin(); iter != _controlPoints->end(); ++iter)
|
||||
{
|
||||
|
@ -119,7 +112,7 @@ void PointArray::setControlPoints(vector<Vec2*> *controlPoints)
|
|||
_controlPoints = controlPoints;
|
||||
}
|
||||
|
||||
void PointArray::addControlPoint(Vec2 controlPoint)
|
||||
void PointArray::addControlPoint(const Vec2& controlPoint)
|
||||
{
|
||||
_controlPoints->push_back(new Vec2(controlPoint.x, controlPoint.y));
|
||||
}
|
||||
|
@ -204,7 +197,7 @@ Vec2 ccCardinalSplineAt(Vec2 &p0, Vec2 &p1, Vec2 &p2, Vec2 &p3, float tension, f
|
|||
* Formula: s(-ttt + 2tt - t)P1 + s(-ttt + tt)P2 + (2ttt - 3tt + 1)P2 + s(ttt - 2tt + t)P3 + (-2ttt + 3tt)P3 + s(ttt - tt)P4
|
||||
*/
|
||||
float s = (1 - tension) / 2;
|
||||
|
||||
|
||||
float b1 = s * ((-t3 + (2 * t2)) - t); // s(-t3 + 2 t2 - t)P1
|
||||
float b2 = s * (-t3 + t2) + (2 * t3 - 3 * t2 + 1); // s(-t3 + t2)P2 + (2 t3 - 3 t2 + 1)P2
|
||||
float b3 = s * (t3 - 2 * t2 + t) + (-2 * t3 + 3 * t2); // s(t3 - 2 t2 + t)P3 + (-2 t3 + 3 t2)P3
|
||||
|
@ -212,8 +205,8 @@ Vec2 ccCardinalSplineAt(Vec2 &p0, Vec2 &p1, Vec2 &p2, Vec2 &p3, float tension, f
|
|||
|
||||
float x = (p0.x*b1 + p1.x*b2 + p2.x*b3 + p3.x*b4);
|
||||
float y = (p0.y*b1 + p1.y*b2 + p2.y*b3 + p3.y*b4);
|
||||
|
||||
return Vec2(x,y);
|
||||
|
||||
return Vec2(x,y);
|
||||
}
|
||||
|
||||
/* Implementation of CardinalSplineTo
|
||||
|
@ -267,7 +260,7 @@ CardinalSplineTo::CardinalSplineTo()
|
|||
void CardinalSplineTo::startWithTarget(cocos2d::Node *target)
|
||||
{
|
||||
ActionInterval::startWithTarget(target);
|
||||
|
||||
|
||||
// _deltaT = (float) 1 / _points->count();
|
||||
|
||||
// Issue #1441
|
||||
|
@ -290,7 +283,7 @@ void CardinalSplineTo::update(float time)
|
|||
{
|
||||
ssize_t p;
|
||||
float lt;
|
||||
|
||||
|
||||
// eg.
|
||||
// p..p..p..p..p..p..p
|
||||
// 1..2..3..4..5..6..7
|
||||
|
@ -311,14 +304,15 @@ void CardinalSplineTo::update(float time)
|
|||
Vec2 pp1 = _points->getControlPointAtIndex(p+0);
|
||||
Vec2 pp2 = _points->getControlPointAtIndex(p+1);
|
||||
Vec2 pp3 = _points->getControlPointAtIndex(p+2);
|
||||
|
||||
|
||||
Vec2 newPos = ccCardinalSplineAt(pp0, pp1, pp2, pp3, _tension, lt);
|
||||
|
||||
|
||||
#if CC_ENABLE_STACKABLE_ACTIONS
|
||||
// Support for stacked actions
|
||||
Node *node = _target;
|
||||
Vec2 diff = node->getPosition() - _previousPosition;
|
||||
if( diff.x !=0 || diff.y != 0 ) {
|
||||
if( diff.x !=0 || diff.y != 0 )
|
||||
{
|
||||
_accumulatedDiff = _accumulatedDiff + diff;
|
||||
newPos = newPos + _accumulatedDiff;
|
||||
}
|
||||
|
@ -375,7 +369,7 @@ void CardinalSplineBy::updatePosition(cocos2d::Vec2 &newPos)
|
|||
CardinalSplineBy* CardinalSplineBy::reverse() const
|
||||
{
|
||||
PointArray *copyConfig = _points->clone();
|
||||
|
||||
|
||||
//
|
||||
// convert "absolutes" to "diffs"
|
||||
//
|
||||
|
@ -388,11 +382,11 @@ CardinalSplineBy* CardinalSplineBy::reverse() const
|
|||
|
||||
p = current;
|
||||
}
|
||||
|
||||
|
||||
// convert to "diffs" to "reverse absolute"
|
||||
|
||||
|
||||
PointArray *pReverse = copyConfig->reverse();
|
||||
|
||||
|
||||
// 1st element (which should be 0,0) should be here too
|
||||
|
||||
p = pReverse->getControlPointAtIndex(pReverse->count()-1);
|
||||
|
@ -410,7 +404,7 @@ CardinalSplineBy* CardinalSplineBy::reverse() const
|
|||
|
||||
p = abs;
|
||||
}
|
||||
|
||||
|
||||
return CardinalSplineBy::create(_duration, pReverse, _tension);
|
||||
}
|
||||
|
||||
|
@ -509,7 +503,7 @@ bool CatmullRomBy::initWithDuration(float dt, cocos2d::PointArray *points)
|
|||
|
||||
CatmullRomBy* CatmullRomBy::clone() const
|
||||
{
|
||||
// no copy constructor
|
||||
// no copy constructor
|
||||
auto a = new (std::nothrow) CatmullRomBy();
|
||||
a->initWithDuration(this->_duration, this->_points->clone());
|
||||
a->autorelease();
|
||||
|
@ -533,11 +527,11 @@ CatmullRomBy* CatmullRomBy::reverse() const
|
|||
p = current;
|
||||
}
|
||||
|
||||
// convert to "diffs" to "reverse absolute"
|
||||
// convert to "diffs" to "reverse absolute"
|
||||
|
||||
PointArray *reverse = copyConfig->reverse();
|
||||
|
||||
// 1st element (which should be 0,0) should be here too
|
||||
// 1st element (which should be 0,0) should be here too
|
||||
|
||||
p = reverse->getControlPointAtIndex(reverse->count()-1);
|
||||
reverse->removeControlPointAtIndex(reverse->count()-1);
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
* Copyright (c) 2008 Radu Gruian
|
||||
* Copyright (c) 2011 Vit Valentin
|
||||
* Copyright (c) 2012 cocos2d-x.org
|
||||
* Copyright (c) 2013-2014 Chukong Technologies Inc.
|
||||
* Copyright (c) 2013-2016 Chukong Technologies Inc.
|
||||
*
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
|
@ -88,7 +88,7 @@ public:
|
|||
* @js NA
|
||||
* @param controlPoint A control point.
|
||||
*/
|
||||
void addControlPoint(Vec2 controlPoint);
|
||||
void addControlPoint(const Vec2& controlPoint);
|
||||
|
||||
/** Inserts a controlPoint at index.
|
||||
*
|
||||
|
@ -232,8 +232,8 @@ protected:
|
|||
PointArray *_points;
|
||||
float _deltaT;
|
||||
float _tension;
|
||||
Vec2 _previousPosition;
|
||||
Vec2 _accumulatedDiff;
|
||||
Vec2 _previousPosition;
|
||||
Vec2 _accumulatedDiff;
|
||||
};
|
||||
|
||||
/** @class CardinalSplineBy
|
||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -1,7 +1,7 @@
|
|||
/****************************************************************************
|
||||
Copyright (c) 2008-2009 Jason Booth
|
||||
Copyright (c) 2010-2012 cocos2d-x.org
|
||||
Copyright (c) 2013-2014 Chukong Technologies Inc.
|
||||
Copyright (c) 2013-2016 Chukong Technologies Inc.
|
||||
|
||||
http://www.cocos2d-x.org
|
||||
|
||||
|
@ -73,7 +73,10 @@ public:
|
|||
virtual void update(float time) override;
|
||||
|
||||
CC_CONSTRUCTOR_ACCESS:
|
||||
ActionEase() {}
|
||||
ActionEase()
|
||||
: _inner(nullptr)
|
||||
{}
|
||||
|
||||
virtual ~ActionEase();
|
||||
/**
|
||||
@brief Initializes the action.
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
/****************************************************************************
|
||||
Copyright (c) 2009 On-Core
|
||||
Copyright (c) 2010-2012 cocos2d-x.org
|
||||
Copyright (c) 2013-2014 Chukong Technologies Inc.
|
||||
Copyright (c) 2013-2016 Chukong Technologies Inc.
|
||||
|
||||
http://www.cocos2d-x.org
|
||||
|
||||
|
@ -159,19 +159,14 @@ void TiledGrid3DAction::setTile(const Vec2& pos, const Quad3& coords)
|
|||
AccelDeccelAmplitude* AccelDeccelAmplitude::create(Action *action, float duration)
|
||||
{
|
||||
AccelDeccelAmplitude *ret = new (std::nothrow) AccelDeccelAmplitude();
|
||||
if (ret)
|
||||
if (ret && ret->initWithAction(action, duration))
|
||||
{
|
||||
if (ret->initWithAction(action, duration))
|
||||
{
|
||||
ret->autorelease();
|
||||
}
|
||||
else
|
||||
{
|
||||
CC_SAFE_DELETE(ret);
|
||||
}
|
||||
ret->autorelease();
|
||||
return ret;
|
||||
}
|
||||
|
||||
return ret;
|
||||
delete ret;
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
bool AccelDeccelAmplitude::initWithAction(Action *action, float duration)
|
||||
|
@ -191,10 +186,10 @@ bool AccelDeccelAmplitude::initWithAction(Action *action, float duration)
|
|||
AccelDeccelAmplitude* AccelDeccelAmplitude::clone() const
|
||||
{
|
||||
// no copy constructor
|
||||
auto a = new (std::nothrow) AccelDeccelAmplitude();
|
||||
a->initWithAction(_other->clone(), _rate);
|
||||
a->autorelease();
|
||||
return a;
|
||||
if (_other)
|
||||
return AccelDeccelAmplitude::create(_other->clone(), _rate);
|
||||
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
AccelDeccelAmplitude::~AccelDeccelAmplitude()
|
||||
|
@ -223,7 +218,10 @@ void AccelDeccelAmplitude::update(float time)
|
|||
|
||||
AccelDeccelAmplitude* AccelDeccelAmplitude::reverse() const
|
||||
{
|
||||
return AccelDeccelAmplitude::create(_other->reverse(), _duration);
|
||||
if (_other)
|
||||
return AccelDeccelAmplitude::create(_other->reverse(), _duration);
|
||||
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
// implementation of AccelAmplitude
|
||||
|
@ -231,19 +229,14 @@ AccelDeccelAmplitude* AccelDeccelAmplitude::reverse() const
|
|||
AccelAmplitude* AccelAmplitude::create(Action *action, float duration)
|
||||
{
|
||||
AccelAmplitude *ret = new (std::nothrow) AccelAmplitude();
|
||||
if (ret)
|
||||
if (ret && ret->initWithAction(action, duration))
|
||||
{
|
||||
if (ret->initWithAction(action, duration))
|
||||
{
|
||||
ret->autorelease();
|
||||
}
|
||||
else
|
||||
{
|
||||
CC_SAFE_DELETE(ret);
|
||||
}
|
||||
ret->autorelease();
|
||||
return ret;
|
||||
}
|
||||
|
||||
return ret;
|
||||
delete ret;
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
bool AccelAmplitude::initWithAction(Action *action, float duration)
|
||||
|
@ -263,10 +256,10 @@ bool AccelAmplitude::initWithAction(Action *action, float duration)
|
|||
AccelAmplitude* AccelAmplitude::clone() const
|
||||
{
|
||||
// no copy constructor
|
||||
auto a = new (std::nothrow) AccelAmplitude();
|
||||
a->initWithAction(_other->clone(), _duration);
|
||||
a->autorelease();
|
||||
return a;
|
||||
if (_other)
|
||||
return AccelAmplitude::create(_other->clone(), _duration);
|
||||
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
AccelAmplitude::~AccelAmplitude()
|
||||
|
@ -288,7 +281,10 @@ void AccelAmplitude::update(float time)
|
|||
|
||||
AccelAmplitude* AccelAmplitude::reverse() const
|
||||
{
|
||||
return AccelAmplitude::create(_other->reverse(), _duration);
|
||||
if (_other)
|
||||
return AccelAmplitude::create(_other->reverse(), _duration);
|
||||
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
// DeccelAmplitude
|
||||
|
@ -296,19 +292,14 @@ AccelAmplitude* AccelAmplitude::reverse() const
|
|||
DeccelAmplitude* DeccelAmplitude::create(Action *action, float duration)
|
||||
{
|
||||
DeccelAmplitude *ret = new (std::nothrow) DeccelAmplitude();
|
||||
if (ret)
|
||||
if (ret && ret->initWithAction(action, duration))
|
||||
{
|
||||
if (ret->initWithAction(action, duration))
|
||||
{
|
||||
ret->autorelease();
|
||||
}
|
||||
else
|
||||
{
|
||||
CC_SAFE_DELETE(ret);
|
||||
}
|
||||
ret->autorelease();
|
||||
return ret;
|
||||
}
|
||||
|
||||
return ret;
|
||||
delete ret;
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
bool DeccelAmplitude::initWithAction(Action *action, float duration)
|
||||
|
@ -344,11 +335,11 @@ void DeccelAmplitude::update(float time)
|
|||
|
||||
DeccelAmplitude* DeccelAmplitude::clone() const
|
||||
{
|
||||
// no copy constructor
|
||||
auto a = new (std::nothrow) DeccelAmplitude();
|
||||
a->initWithAction(_other->clone(), _duration);
|
||||
a->autorelease();
|
||||
return a;
|
||||
// no copy constructor
|
||||
if (_other)
|
||||
return DeccelAmplitude::create(_other->clone(), _duration);
|
||||
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
DeccelAmplitude* DeccelAmplitude::reverse() const
|
||||
|
@ -377,10 +368,15 @@ void StopGrid::cacheTargetAsGridNode()
|
|||
|
||||
StopGrid* StopGrid::create()
|
||||
{
|
||||
StopGrid* pAction = new (std::nothrow) StopGrid();
|
||||
pAction->autorelease();
|
||||
StopGrid* action = new (std::nothrow) StopGrid();
|
||||
if (action)
|
||||
{
|
||||
action->autorelease();
|
||||
return action;
|
||||
}
|
||||
|
||||
return pAction;
|
||||
delete action;
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
StopGrid* StopGrid::clone() const
|
||||
|
@ -399,19 +395,14 @@ StopGrid* StopGrid::reverse() const
|
|||
ReuseGrid* ReuseGrid::create(int times)
|
||||
{
|
||||
ReuseGrid *action = new (std::nothrow) ReuseGrid();
|
||||
if (action)
|
||||
if (action && action->initWithTimes(times))
|
||||
{
|
||||
if (action->initWithTimes(times))
|
||||
{
|
||||
action->autorelease();
|
||||
}
|
||||
else
|
||||
{
|
||||
CC_SAFE_DELETE(action);
|
||||
}
|
||||
action->autorelease();
|
||||
return action;
|
||||
}
|
||||
|
||||
return action;
|
||||
delete action;
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
bool ReuseGrid::initWithTimes(int times)
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
/****************************************************************************
|
||||
Copyright (c) 2009 On-Core
|
||||
Copyright (c) 2010-2012 cocos2d-x.org
|
||||
Copyright (c) 2013-2014 Chukong Technologies Inc.
|
||||
Copyright (c) 2013-2016 Chukong Technologies Inc.
|
||||
|
||||
http://www.cocos2d-x.org
|
||||
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
/****************************************************************************
|
||||
Copyright (c) 2009 On-Core
|
||||
Copyright (c) 2010-2012 cocos2d-x.org
|
||||
Copyright (c) 2013-2014 Chukong Technologies Inc.
|
||||
Copyright (c) 2013-2016 Chukong Technologies Inc.
|
||||
|
||||
http://www.cocos2d-x.org
|
||||
|
||||
|
@ -31,21 +31,16 @@ NS_CC_BEGIN
|
|||
|
||||
Waves3D* Waves3D::create(float duration, const Size& gridSize, unsigned int waves, float amplitude)
|
||||
{
|
||||
Waves3D *pAction = new (std::nothrow) Waves3D();
|
||||
Waves3D *action = new (std::nothrow) Waves3D();
|
||||
|
||||
if (pAction)
|
||||
if (action && action->initWithDuration(duration, gridSize, waves, amplitude))
|
||||
{
|
||||
if (pAction->initWithDuration(duration, gridSize, waves, amplitude))
|
||||
{
|
||||
pAction->autorelease();
|
||||
}
|
||||
else
|
||||
{
|
||||
CC_SAFE_RELEASE_NULL(pAction);
|
||||
}
|
||||
action->autorelease();
|
||||
return action;
|
||||
}
|
||||
|
||||
return pAction;
|
||||
delete action;
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
bool Waves3D::initWithDuration(float duration, const Size& gridSize, unsigned int waves, float amplitude)
|
||||
|
@ -65,10 +60,7 @@ bool Waves3D::initWithDuration(float duration, const Size& gridSize, unsigned in
|
|||
Waves3D* Waves3D::clone() const
|
||||
{
|
||||
// no copy constructor
|
||||
auto a = new (std::nothrow) Waves3D();
|
||||
a->initWithDuration(_duration, _gridSize, _waves, _amplitude);
|
||||
a->autorelease();
|
||||
return a;
|
||||
return Waves3D::create(_duration, _gridSize, _waves, _amplitude);
|
||||
}
|
||||
|
||||
void Waves3D::update(float time)
|
||||
|
@ -92,19 +84,14 @@ FlipX3D* FlipX3D::create(float duration)
|
|||
{
|
||||
FlipX3D *action = new (std::nothrow) FlipX3D();
|
||||
|
||||
if (action)
|
||||
if (action && action->initWithDuration(duration))
|
||||
{
|
||||
if (action->initWithDuration(duration))
|
||||
{
|
||||
action->autorelease();
|
||||
}
|
||||
else
|
||||
{
|
||||
CC_SAFE_RELEASE_NULL(action);
|
||||
}
|
||||
action->autorelease();
|
||||
return action;
|
||||
}
|
||||
|
||||
return action;
|
||||
delete action;
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
bool FlipX3D::initWithDuration(float duration)
|
||||
|
@ -666,7 +653,7 @@ void Waves::update(float time)
|
|||
|
||||
// implementation of Twirl
|
||||
|
||||
Twirl* Twirl::create(float duration, const Size& gridSize, Vec2 position, unsigned int twirls, float amplitude)
|
||||
Twirl* Twirl::create(float duration, const Size& gridSize, const Vec2& position, unsigned int twirls, float amplitude)
|
||||
{
|
||||
Twirl *action = new (std::nothrow) Twirl();
|
||||
|
||||
|
@ -685,7 +672,7 @@ Twirl* Twirl::create(float duration, const Size& gridSize, Vec2 position, unsign
|
|||
return action;
|
||||
}
|
||||
|
||||
bool Twirl::initWithDuration(float duration, const Size& gridSize, Vec2 position, unsigned int twirls, float amplitude)
|
||||
bool Twirl::initWithDuration(float duration, const Size& gridSize, const Vec2& position, unsigned int twirls, float amplitude)
|
||||
{
|
||||
if (Grid3DAction::initWithDuration(duration, gridSize))
|
||||
{
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
/****************************************************************************
|
||||
Copyright (c) 2009 On-Core
|
||||
Copyright (c) 2010-2012 cocos2d-x.org
|
||||
Copyright (c) 2013-2014 Chukong Technologies Inc.
|
||||
Copyright (c) 2013-2016 Chukong Technologies Inc.
|
||||
|
||||
http://www.cocos2d-x.org
|
||||
|
||||
|
@ -76,8 +76,8 @@ public:
|
|||
*/
|
||||
inline void setAmplitudeRate(float amplitudeRate) { _amplitudeRate = amplitudeRate; }
|
||||
|
||||
// Overrides
|
||||
virtual Waves3D* clone() const override;
|
||||
// Overrides
|
||||
virtual Waves3D* clone() const override;
|
||||
virtual void update(float time) override;
|
||||
|
||||
CC_CONSTRUCTOR_ACCESS:
|
||||
|
@ -118,7 +118,7 @@ public:
|
|||
static FlipX3D* create(float duration);
|
||||
|
||||
// Override
|
||||
virtual FlipX3D* clone() const override;
|
||||
virtual FlipX3D* clone() const override;
|
||||
virtual void update(float time) override;
|
||||
|
||||
CC_CONSTRUCTOR_ACCESS:
|
||||
|
@ -160,7 +160,7 @@ public:
|
|||
|
||||
// Overrides
|
||||
virtual void update(float time) override;
|
||||
virtual FlipY3D* clone() const override;
|
||||
virtual FlipY3D* clone() const override;
|
||||
|
||||
CC_CONSTRUCTOR_ACCESS:
|
||||
FlipY3D() {}
|
||||
|
@ -220,7 +220,7 @@ public:
|
|||
void setPosition(const Vec2& position);
|
||||
|
||||
// Overrides
|
||||
virtual Lens3D* clone() const override;
|
||||
virtual Lens3D* clone() const override;
|
||||
virtual void update(float time) override;
|
||||
|
||||
CC_CONSTRUCTOR_ACCESS:
|
||||
|
@ -308,7 +308,7 @@ public:
|
|||
inline void setAmplitudeRate(float fAmplitudeRate) { _amplitudeRate = fAmplitudeRate; }
|
||||
|
||||
// Override
|
||||
virtual Ripple3D* clone() const override;
|
||||
virtual Ripple3D* clone() const override;
|
||||
virtual void update(float time) override;
|
||||
|
||||
CC_CONSTRUCTOR_ACCESS:
|
||||
|
@ -359,7 +359,7 @@ public:
|
|||
static Shaky3D* create(float initWithDuration, const Size& gridSize, int range, bool shakeZ);
|
||||
|
||||
// Overrides
|
||||
virtual Shaky3D* clone() const override;
|
||||
virtual Shaky3D* clone() const override;
|
||||
virtual void update(float time) override;
|
||||
|
||||
CC_CONSTRUCTOR_ACCESS:
|
||||
|
@ -426,7 +426,7 @@ public:
|
|||
inline void setAmplitudeRate(float amplitudeRate) { _amplitudeRate = amplitudeRate; }
|
||||
|
||||
// Overrides
|
||||
virtual Liquid* clone() const override;
|
||||
virtual Liquid* clone() const override;
|
||||
virtual void update(float time) override;
|
||||
|
||||
CC_CONSTRUCTOR_ACCESS:
|
||||
|
@ -497,7 +497,7 @@ public:
|
|||
inline void setAmplitudeRate(float amplitudeRate) { _amplitudeRate = amplitudeRate; }
|
||||
|
||||
// Overrides
|
||||
virtual Waves* clone() const override;
|
||||
virtual Waves* clone() const override;
|
||||
virtual void update(float time) override;
|
||||
|
||||
CC_CONSTRUCTOR_ACCESS:
|
||||
|
@ -545,7 +545,7 @@ public:
|
|||
@param amplitude Specify the amplitude of the Twirl action.
|
||||
@return If the creation success, return a pointer of Twirl action; otherwise, return nil.
|
||||
*/
|
||||
static Twirl* create(float duration, const Size& gridSize, Vec2 position, unsigned int twirls, float amplitude);
|
||||
static Twirl* create(float duration, const Size& gridSize, const Vec2& position, unsigned int twirls, float amplitude);
|
||||
|
||||
/**
|
||||
@brief Get the center position of twirl action.
|
||||
|
@ -582,7 +582,7 @@ public:
|
|||
|
||||
|
||||
// Overrides
|
||||
virtual Twirl* clone() const override;
|
||||
virtual Twirl* clone() const override;
|
||||
virtual void update(float time) override;
|
||||
|
||||
CC_CONSTRUCTOR_ACCESS:
|
||||
|
@ -598,7 +598,7 @@ CC_CONSTRUCTOR_ACCESS:
|
|||
@param amplitude Specify the amplitude of the Twirl action.
|
||||
@return If the initialization success, return true; otherwise, return false.
|
||||
*/
|
||||
bool initWithDuration(float duration, const Size& gridSize, Vec2 position, unsigned int twirls, float amplitude);
|
||||
bool initWithDuration(float duration, const Size& gridSize, const Vec2& position, unsigned int twirls, float amplitude);
|
||||
|
||||
protected:
|
||||
/* twirl center */
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
Copyright (c) 2008-2010 Ricardo Quesada
|
||||
Copyright (c) 2010-2012 cocos2d-x.org
|
||||
Copyright (c) 2011 Zynga Inc.
|
||||
Copyright (c) 2013-2014 Chukong Technologies Inc.
|
||||
Copyright (c) 2013-2016 Chukong Technologies Inc.
|
||||
|
||||
http://www.cocos2d-x.org
|
||||
|
||||
|
@ -45,7 +45,8 @@ bool ActionInstant::isDone() const
|
|||
return true;
|
||||
}
|
||||
|
||||
void ActionInstant::step(float dt) {
|
||||
void ActionInstant::step(float dt)
|
||||
{
|
||||
CC_UNUSED_PARAM(dt);
|
||||
float updateDt = 1;
|
||||
#if CC_ENABLE_SCRIPT_BINDING
|
||||
|
@ -58,7 +59,8 @@ void ActionInstant::step(float dt) {
|
|||
update(updateDt);
|
||||
}
|
||||
|
||||
void ActionInstant::update(float time) {
|
||||
void ActionInstant::update(float time)
|
||||
{
|
||||
CC_UNUSED_PARAM(time);
|
||||
// nothing
|
||||
}
|
||||
|
@ -71,14 +73,16 @@ Show* Show::create()
|
|||
{
|
||||
Show* ret = new (std::nothrow) Show();
|
||||
|
||||
if (ret) {
|
||||
if (ret)
|
||||
{
|
||||
ret->autorelease();
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
void Show::update(float time) {
|
||||
void Show::update(float time)
|
||||
{
|
||||
CC_UNUSED_PARAM(time);
|
||||
_target->setVisible(true);
|
||||
}
|
||||
|
@ -88,12 +92,10 @@ ActionInstant* Show::reverse() const
|
|||
return Hide::create();
|
||||
}
|
||||
|
||||
Show * Show::clone() const
|
||||
Show* Show::clone() const
|
||||
{
|
||||
// no copy constructor
|
||||
auto a = new (std::nothrow) Show();
|
||||
a->autorelease();
|
||||
return a;
|
||||
return Show::create();
|
||||
}
|
||||
|
||||
//
|
||||
|
@ -103,14 +105,16 @@ Hide * Hide::create()
|
|||
{
|
||||
Hide *ret = new (std::nothrow) Hide();
|
||||
|
||||
if (ret) {
|
||||
if (ret)
|
||||
{
|
||||
ret->autorelease();
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
void Hide::update(float time) {
|
||||
void Hide::update(float time)
|
||||
{
|
||||
CC_UNUSED_PARAM(time);
|
||||
_target->setVisible(false);
|
||||
}
|
||||
|
@ -120,12 +124,10 @@ ActionInstant *Hide::reverse() const
|
|||
return Show::create();
|
||||
}
|
||||
|
||||
Hide * Hide::clone() const
|
||||
Hide* Hide::clone() const
|
||||
{
|
||||
// no copy constructor
|
||||
auto a = new (std::nothrow) Hide();
|
||||
a->autorelease();
|
||||
return a;
|
||||
return Hide::create();
|
||||
}
|
||||
|
||||
//
|
||||
|
@ -157,9 +159,7 @@ ToggleVisibility * ToggleVisibility::reverse() const
|
|||
ToggleVisibility * ToggleVisibility::clone() const
|
||||
{
|
||||
// no copy constructor
|
||||
auto a = new (std::nothrow) ToggleVisibility();
|
||||
a->autorelease();
|
||||
return a;
|
||||
return ToggleVisibility::create();
|
||||
}
|
||||
|
||||
//
|
||||
|
@ -169,19 +169,22 @@ RemoveSelf * RemoveSelf::create(bool isNeedCleanUp /*= true*/)
|
|||
{
|
||||
RemoveSelf *ret = new (std::nothrow) RemoveSelf();
|
||||
|
||||
if (ret && ret->init(isNeedCleanUp)) {
|
||||
if (ret && ret->init(isNeedCleanUp))
|
||||
{
|
||||
ret->autorelease();
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
bool RemoveSelf::init(bool isNeedCleanUp) {
|
||||
bool RemoveSelf::init(bool isNeedCleanUp)
|
||||
{
|
||||
_isNeedCleanUp = isNeedCleanUp;
|
||||
return true;
|
||||
}
|
||||
|
||||
void RemoveSelf::update(float time) {
|
||||
void RemoveSelf::update(float time)
|
||||
{
|
||||
CC_UNUSED_PARAM(time);
|
||||
_target->removeFromParentAndCleanup(_isNeedCleanUp);
|
||||
}
|
||||
|
@ -194,10 +197,7 @@ RemoveSelf *RemoveSelf::reverse() const
|
|||
RemoveSelf * RemoveSelf::clone() const
|
||||
{
|
||||
// no copy constructor
|
||||
auto a = new (std::nothrow) RemoveSelf();
|
||||
a->init(_isNeedCleanUp);
|
||||
a->autorelease();
|
||||
return a;
|
||||
return RemoveSelf::create(_isNeedCleanUp);
|
||||
}
|
||||
|
||||
//
|
||||
|
@ -208,7 +208,8 @@ FlipX *FlipX::create(bool x)
|
|||
{
|
||||
FlipX *ret = new (std::nothrow) FlipX();
|
||||
|
||||
if (ret && ret->initWithFlipX(x)) {
|
||||
if (ret && ret->initWithFlipX(x))
|
||||
{
|
||||
ret->autorelease();
|
||||
return ret;
|
||||
}
|
||||
|
@ -217,12 +218,14 @@ FlipX *FlipX::create(bool x)
|
|||
return nullptr;
|
||||
}
|
||||
|
||||
bool FlipX::initWithFlipX(bool x) {
|
||||
bool FlipX::initWithFlipX(bool x)
|
||||
{
|
||||
_flipX = x;
|
||||
return true;
|
||||
}
|
||||
|
||||
void FlipX::update(float time) {
|
||||
void FlipX::update(float time)
|
||||
{
|
||||
CC_UNUSED_PARAM(time);
|
||||
static_cast<Sprite*>(_target)->setFlippedX(_flipX);
|
||||
}
|
||||
|
@ -235,10 +238,7 @@ FlipX* FlipX::reverse() const
|
|||
FlipX * FlipX::clone() const
|
||||
{
|
||||
// no copy constructor
|
||||
auto a = new (std::nothrow) FlipX();
|
||||
a->initWithFlipX(_flipX);
|
||||
a->autorelease();
|
||||
return a;
|
||||
return FlipX::create(_flipX);
|
||||
}
|
||||
//
|
||||
// FlipY
|
||||
|
@ -248,7 +248,8 @@ FlipY * FlipY::create(bool y)
|
|||
{
|
||||
FlipY *ret = new (std::nothrow) FlipY();
|
||||
|
||||
if (ret && ret->initWithFlipY(y)) {
|
||||
if (ret && ret->initWithFlipY(y))
|
||||
{
|
||||
ret->autorelease();
|
||||
return ret;
|
||||
}
|
||||
|
@ -257,12 +258,14 @@ FlipY * FlipY::create(bool y)
|
|||
return nullptr;
|
||||
}
|
||||
|
||||
bool FlipY::initWithFlipY(bool y) {
|
||||
bool FlipY::initWithFlipY(bool y)
|
||||
{
|
||||
_flipY = y;
|
||||
return true;
|
||||
}
|
||||
|
||||
void FlipY::update(float time) {
|
||||
void FlipY::update(float time)
|
||||
{
|
||||
CC_UNUSED_PARAM(time);
|
||||
static_cast<Sprite*>(_target)->setFlippedY(_flipY);
|
||||
}
|
||||
|
@ -275,10 +278,7 @@ FlipY* FlipY::reverse() const
|
|||
FlipY * FlipY::clone() const
|
||||
{
|
||||
// no copy constructor
|
||||
auto a = new (std::nothrow) FlipY();
|
||||
a->initWithFlipY(_flipY);
|
||||
a->autorelease();
|
||||
return a;
|
||||
return FlipY::create(_flipY);
|
||||
}
|
||||
|
||||
//
|
||||
|
@ -289,16 +289,18 @@ Place* Place::create(const Vec2& pos)
|
|||
{
|
||||
Place *ret = new (std::nothrow) Place();
|
||||
|
||||
if (ret && ret->initWithPosition(pos)) {
|
||||
if (ret && ret->initWithPosition(pos))
|
||||
{
|
||||
ret->autorelease();
|
||||
return ret;
|
||||
}
|
||||
|
||||
CC_SAFE_DELETE(ret);
|
||||
delete ret;
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
bool Place::initWithPosition(const Vec2& pos) {
|
||||
bool Place::initWithPosition(const Vec2& pos)
|
||||
{
|
||||
_position = pos;
|
||||
return true;
|
||||
}
|
||||
|
@ -306,10 +308,7 @@ bool Place::initWithPosition(const Vec2& pos) {
|
|||
Place * Place::clone() const
|
||||
{
|
||||
// no copy constructor
|
||||
auto a = new (std::nothrow) Place();
|
||||
a->initWithPosition(_position);
|
||||
a->autorelease();
|
||||
return a;
|
||||
return Place::create(_position);
|
||||
}
|
||||
|
||||
Place * Place::reverse() const
|
||||
|
@ -318,7 +317,8 @@ Place * Place::reverse() const
|
|||
return this->clone();
|
||||
}
|
||||
|
||||
void Place::update(float time) {
|
||||
void Place::update(float time)
|
||||
{
|
||||
CC_UNUSED_PARAM(time);
|
||||
_target->setPosition(_position);
|
||||
}
|
||||
|
@ -331,7 +331,8 @@ CallFunc * CallFunc::create(const std::function<void()> &func)
|
|||
{
|
||||
CallFunc *ret = new (std::nothrow) CallFunc();
|
||||
|
||||
if (ret && ret->initWithFunction(func) ) {
|
||||
if (ret && ret->initWithFunction(func) )
|
||||
{
|
||||
ret->autorelease();
|
||||
return ret;
|
||||
}
|
||||
|
@ -344,7 +345,8 @@ CallFunc * CallFunc::create(Ref* selectorTarget, SEL_CallFunc selector)
|
|||
{
|
||||
CallFunc *ret = new (std::nothrow) CallFunc();
|
||||
|
||||
if (ret && ret->initWithTarget(selectorTarget)) {
|
||||
if (ret && ret->initWithTarget(selectorTarget))
|
||||
{
|
||||
ret->_callFunc = selector;
|
||||
ret->autorelease();
|
||||
return ret;
|
||||
|
@ -360,7 +362,8 @@ bool CallFunc::initWithFunction(const std::function<void()> &func)
|
|||
return true;
|
||||
}
|
||||
|
||||
bool CallFunc::initWithTarget(Ref* target) {
|
||||
bool CallFunc::initWithTarget(Ref* target)
|
||||
{
|
||||
if (target)
|
||||
{
|
||||
target->retain();
|
||||
|
@ -384,11 +387,13 @@ CallFunc * CallFunc::clone() const
|
|||
{
|
||||
// no copy constructor
|
||||
auto a = new (std::nothrow) CallFunc();
|
||||
if( _selectorTarget) {
|
||||
if( _selectorTarget)
|
||||
{
|
||||
a->initWithTarget(_selectorTarget);
|
||||
a->_callFunc = _callFunc;
|
||||
}
|
||||
else if( _function ){
|
||||
else if( _function )
|
||||
{
|
||||
a->initWithFunction(_function);
|
||||
}
|
||||
|
||||
|
@ -402,15 +407,20 @@ CallFunc * CallFunc::reverse() const
|
|||
return this->clone();
|
||||
}
|
||||
|
||||
void CallFunc::update(float time) {
|
||||
void CallFunc::update(float time)
|
||||
{
|
||||
CC_UNUSED_PARAM(time);
|
||||
this->execute();
|
||||
}
|
||||
|
||||
void CallFunc::execute() {
|
||||
if (_callFunc) {
|
||||
void CallFunc::execute()
|
||||
{
|
||||
if (_callFunc)
|
||||
{
|
||||
(_selectorTarget->*_callFunc)();
|
||||
} else if( _function ){
|
||||
}
|
||||
else if( _function )
|
||||
{
|
||||
_function();
|
||||
}
|
||||
}
|
||||
|
@ -423,7 +433,8 @@ CallFuncN * CallFuncN::create(const std::function<void(Node*)> &func)
|
|||
{
|
||||
auto ret = new (std::nothrow) CallFuncN();
|
||||
|
||||
if (ret && ret->initWithFunction(func) ) {
|
||||
if (ret && ret->initWithFunction(func) )
|
||||
{
|
||||
ret->autorelease();
|
||||
return ret;
|
||||
}
|
||||
|
@ -447,11 +458,14 @@ CallFuncN * CallFuncN::create(Ref* selectorTarget, SEL_CallFuncN selector)
|
|||
return nullptr;
|
||||
}
|
||||
|
||||
void CallFuncN::execute() {
|
||||
if (_callFuncN) {
|
||||
void CallFuncN::execute()
|
||||
{
|
||||
if (_callFuncN)
|
||||
{
|
||||
(_selectorTarget->*_callFuncN)(_target);
|
||||
}
|
||||
else if (_functionN) {
|
||||
else if (_functionN)
|
||||
{
|
||||
_functionN(_target);
|
||||
}
|
||||
}
|
||||
|
@ -464,7 +478,8 @@ bool CallFuncN::initWithFunction(const std::function<void (Node *)> &func)
|
|||
|
||||
bool CallFuncN::initWithTarget(Ref* selectorTarget, SEL_CallFuncN selector)
|
||||
{
|
||||
if (CallFunc::initWithTarget(selectorTarget)) {
|
||||
if (CallFunc::initWithTarget(selectorTarget))
|
||||
{
|
||||
_callFuncN = selector;
|
||||
return true;
|
||||
}
|
||||
|
@ -477,7 +492,8 @@ CallFuncN * CallFuncN::clone() const
|
|||
// no copy constructor
|
||||
auto a = new (std::nothrow) CallFuncN();
|
||||
|
||||
if( _selectorTarget) {
|
||||
if( _selectorTarget)
|
||||
{
|
||||
a->initWithTarget(_selectorTarget, _callFuncN);
|
||||
}
|
||||
else if( _functionN ){
|
||||
|
@ -496,7 +512,8 @@ __CCCallFuncND * __CCCallFuncND::create(Ref* selectorTarget, SEL_CallFuncND sele
|
|||
{
|
||||
__CCCallFuncND* ret = new (std::nothrow) __CCCallFuncND();
|
||||
|
||||
if (ret && ret->initWithTarget(selectorTarget, selector, d)) {
|
||||
if (ret && ret->initWithTarget(selectorTarget, selector, d))
|
||||
{
|
||||
ret->autorelease();
|
||||
return ret;
|
||||
}
|
||||
|
@ -554,7 +571,8 @@ __CCCallFuncO::~__CCCallFuncO()
|
|||
|
||||
void __CCCallFuncO::execute()
|
||||
{
|
||||
if (_callFuncO) {
|
||||
if (_callFuncO)
|
||||
{
|
||||
(_selectorTarget->*_callFuncO)(_object);
|
||||
}
|
||||
}
|
||||
|
@ -563,7 +581,8 @@ __CCCallFuncO * __CCCallFuncO::create(Ref* selectorTarget, SEL_CallFuncO selecto
|
|||
{
|
||||
__CCCallFuncO *ret = new (std::nothrow) __CCCallFuncO();
|
||||
|
||||
if (ret && ret->initWithTarget(selectorTarget, selector, object)) {
|
||||
if (ret && ret->initWithTarget(selectorTarget, selector, object))
|
||||
{
|
||||
ret->autorelease();
|
||||
return ret;
|
||||
}
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
Copyright (c) 2008-2010 Ricardo Quesada
|
||||
Copyright (c) 2010-2012 cocos2d-x.org
|
||||
Copyright (c) 2011 Zynga Inc.
|
||||
Copyright (c) 2013-2014 Chukong Technologies Inc.
|
||||
Copyright (c) 2013-2016 Chukong Technologies Inc.
|
||||
|
||||
http://www.cocos2d-x.org
|
||||
|
||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -2,7 +2,7 @@
|
|||
Copyright (c) 2008-2010 Ricardo Quesada
|
||||
Copyright (c) 2011 Zynga Inc.
|
||||
Copyright (c) 2010-2012 cocos2d-x.org
|
||||
Copyright (c) 2013-2014 Chukong Technologies Inc.
|
||||
Copyright (c) 2013-2016 Chukong Technologies Inc.
|
||||
|
||||
http://www.cocos2d-x.org
|
||||
|
||||
|
@ -190,8 +190,8 @@ public:
|
|||
virtual void update(float t) override;
|
||||
|
||||
CC_CONSTRUCTOR_ACCESS:
|
||||
Sequence() {}
|
||||
virtual ~Sequence(void);
|
||||
Sequence();
|
||||
virtual ~Sequence();
|
||||
|
||||
/** initializes the action */
|
||||
bool initWithTwoActions(FiniteTimeAction *pActionOne, FiniteTimeAction *pActionTwo);
|
||||
|
@ -416,7 +416,7 @@ public:
|
|||
virtual void update(float time) override;
|
||||
|
||||
CC_CONSTRUCTOR_ACCESS:
|
||||
Spawn() {}
|
||||
Spawn();
|
||||
virtual ~Spawn();
|
||||
|
||||
/** initializes the Spawn action with the 2 actions to spawn */
|
||||
|
|
|
@ -3,7 +3,7 @@ Copyright (c) 2008-2010 Ricardo Quesada
|
|||
Copyright (c) 2009 Valentin Milea
|
||||
Copyright (c) 2010-2012 cocos2d-x.org
|
||||
Copyright (c) 2011 Zynga Inc.
|
||||
CopyRight (c) 2013-2014 Chukong Technologies Inc.
|
||||
CopyRight (c) 2013-2016 Chukong Technologies Inc.
|
||||
|
||||
http://www.cocos2d-x.org
|
||||
|
||||
|
@ -159,7 +159,8 @@ Vector<Node*> ActionManager::pauseAllRunningActions()
|
|||
|
||||
void ActionManager::resumeTargets(const Vector<Node*>& targetsToResume)
|
||||
{
|
||||
for(const auto &node : targetsToResume) {
|
||||
for(const auto &node : targetsToResume)
|
||||
{
|
||||
this->resumeTarget(node);
|
||||
}
|
||||
}
|
||||
|
@ -170,6 +171,8 @@ void ActionManager::addAction(Action *action, Node *target, bool paused)
|
|||
{
|
||||
CCASSERT(action != nullptr, "action can't be nullptr!");
|
||||
CCASSERT(target != nullptr, "target can't be nullptr!");
|
||||
if(action == nullptr || target == nullptr)
|
||||
return;
|
||||
|
||||
tHashElement *element = nullptr;
|
||||
// we should convert it to Ref*, because we save it as Ref*
|
||||
|
@ -232,10 +235,6 @@ void ActionManager::removeAllActionsFromTarget(Node *target)
|
|||
deleteHashElement(element);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// CCLOG("cocos2d: removeAllActionsFromTarget: Target not found");
|
||||
}
|
||||
}
|
||||
|
||||
void ActionManager::removeAction(Action *action)
|
||||
|
@ -257,16 +256,16 @@ void ActionManager::removeAction(Action *action)
|
|||
removeActionAtIndex(i, element);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
CCLOG("cocos2d: removeAction: Target not found");
|
||||
}
|
||||
}
|
||||
|
||||
void ActionManager::removeActionByTag(int tag, Node *target)
|
||||
{
|
||||
CCASSERT(tag != Action::INVALID_TAG, "Invalid tag value!");
|
||||
CCASSERT(target != nullptr, "target can't be nullptr!");
|
||||
if (target == nullptr)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
tHashElement *element = nullptr;
|
||||
HASH_FIND_PTR(_targets, &target, element);
|
||||
|
@ -291,6 +290,10 @@ void ActionManager::removeAllActionsByTag(int tag, Node *target)
|
|||
{
|
||||
CCASSERT(tag != Action::INVALID_TAG, "Invalid tag value!");
|
||||
CCASSERT(target != nullptr, "target can't be nullptr!");
|
||||
if (target == nullptr)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
tHashElement *element = nullptr;
|
||||
HASH_FIND_PTR(_targets, &target, element);
|
||||
|
@ -322,6 +325,10 @@ void ActionManager::removeActionsByFlags(unsigned int flags, Node *target)
|
|||
return;
|
||||
}
|
||||
CCASSERT(target != nullptr, "target can't be nullptr!");
|
||||
if (target == nullptr)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
tHashElement *element = nullptr;
|
||||
HASH_FIND_PTR(_targets, &target, element);
|
||||
|
@ -372,11 +379,6 @@ Action* ActionManager::getActionByTag(int tag, const Node *target) const
|
|||
}
|
||||
}
|
||||
}
|
||||
//CCLOG("cocos2d : getActionByTag(tag = %d): Action not found", tag);
|
||||
}
|
||||
else
|
||||
{
|
||||
// CCLOG("cocos2d : getActionByTag: Target not found");
|
||||
}
|
||||
|
||||
return nullptr;
|
||||
|
@ -450,6 +452,11 @@ void ActionManager::update(float dt)
|
|||
{
|
||||
deleteHashElement(_currentTarget);
|
||||
}
|
||||
//if some node reference 'target', it's reference count >= 2 (issues #14050)
|
||||
else if (_currentTarget->target->getReferenceCount() == 1)
|
||||
{
|
||||
deleteHashElement(_currentTarget);
|
||||
}
|
||||
}
|
||||
|
||||
// issue #635
|
||||
|
|
|
@ -3,7 +3,7 @@ Copyright (c) 2008-2010 Ricardo Quesada
|
|||
Copyright (c) 2009 Valentin Milea
|
||||
Copyright (c) 2010-2012 cocos2d-x.org
|
||||
Copyright (c) 2011 Zynga Inc.
|
||||
CopyRight (c) 2013-2014 Chukong Technologies Inc.
|
||||
CopyRight (c) 2013-2016 Chukong Technologies Inc.
|
||||
|
||||
http://www.cocos2d-x.org
|
||||
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
/****************************************************************************
|
||||
Copyright (c) 2009 Sindesso Pty Ltd http://www.sindesso.com/
|
||||
Copyright (c) 2010-2012 cocos2d-x.org
|
||||
CopyRight (c) 2013-2014 Chukong Technologies Inc.
|
||||
CopyRight (c) 2013-2016 Chukong Technologies Inc.
|
||||
|
||||
http://www.cocos2d-x.org
|
||||
|
||||
|
@ -33,34 +33,30 @@ PageTurn3D* PageTurn3D::create(float duration, const Size& gridSize)
|
|||
{
|
||||
PageTurn3D *action = new (std::nothrow) PageTurn3D();
|
||||
|
||||
if (action)
|
||||
if (action && action->initWithDuration(duration, gridSize))
|
||||
{
|
||||
if (action->initWithDuration(duration, gridSize))
|
||||
{
|
||||
action->autorelease();
|
||||
}
|
||||
else
|
||||
{
|
||||
CC_SAFE_RELEASE_NULL(action);
|
||||
}
|
||||
action->autorelease();
|
||||
return action;
|
||||
}
|
||||
|
||||
return action;
|
||||
delete action;
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
PageTurn3D *PageTurn3D::clone() const
|
||||
{
|
||||
// no copy constructor
|
||||
auto a = new (std::nothrow) PageTurn3D();
|
||||
a->initWithDuration(_duration, _gridSize);
|
||||
a->autorelease();
|
||||
return a;
|
||||
// no copy constructor
|
||||
return PageTurn3D::create(_duration, _gridSize);
|
||||
}
|
||||
|
||||
GridBase* PageTurn3D::getGrid()
|
||||
{
|
||||
auto result = Grid3D::create(_gridSize, _gridNodeTarget->getGridRect());
|
||||
result->setNeedDepthTestForBlit(true);
|
||||
if (result)
|
||||
{
|
||||
result->setNeedDepthTestForBlit(true);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
/****************************************************************************
|
||||
Copyright (c) 2009 Sindesso Pty Ltd http://www.sindesso.com/
|
||||
Copyright (c) 2010-2012 cocos2d-x.org
|
||||
CopyRight (c) 2013-2014 Chukong Technologies Inc.
|
||||
CopyRight (c) 2013-2016 Chukong Technologies Inc.
|
||||
|
||||
http://www.cocos2d-x.org
|
||||
|
||||
|
@ -61,7 +61,7 @@ public:
|
|||
static PageTurn3D* create(float duration, const Size& gridSize);
|
||||
|
||||
// Overrides
|
||||
virtual PageTurn3D* clone() const override;
|
||||
virtual PageTurn3D* clone() const override;
|
||||
virtual void update(float time) override;
|
||||
};
|
||||
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
/****************************************************************************
|
||||
Copyright (C) 2010 Lam Pham
|
||||
Copyright (c) 2010-2012 cocos2d-x.org
|
||||
CopyRight (c) 2013-2014 Chukong Technologies Inc.
|
||||
CopyRight (c) 2013-2016 Chukong Technologies Inc.
|
||||
|
||||
http://www.cocos2d-x.org
|
||||
|
||||
|
@ -35,10 +35,14 @@ NS_CC_BEGIN
|
|||
ProgressTo* ProgressTo::create(float duration, float percent)
|
||||
{
|
||||
ProgressTo *progressTo = new (std::nothrow) ProgressTo();
|
||||
progressTo->initWithDuration(duration, percent);
|
||||
progressTo->autorelease();
|
||||
|
||||
return progressTo;
|
||||
if (progressTo && progressTo->initWithDuration(duration, percent))
|
||||
{
|
||||
progressTo->autorelease();
|
||||
return progressTo;
|
||||
}
|
||||
|
||||
delete progressTo;
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
bool ProgressTo::initWithDuration(float duration, float percent)
|
||||
|
@ -55,11 +59,8 @@ bool ProgressTo::initWithDuration(float duration, float percent)
|
|||
|
||||
ProgressTo* ProgressTo::clone() const
|
||||
{
|
||||
// no copy constructor
|
||||
auto a = new (std::nothrow) ProgressTo();
|
||||
a->initWithDuration(_duration, _to);
|
||||
a->autorelease();
|
||||
return a;
|
||||
// no copy constructor
|
||||
return ProgressTo::create(_duration, _to);
|
||||
}
|
||||
|
||||
ProgressTo* ProgressTo::reverse() const
|
||||
|
@ -84,10 +85,13 @@ void ProgressTo::update(float time)
|
|||
ProgressFromTo* ProgressFromTo::create(float duration, float fromPercentage, float toPercentage)
|
||||
{
|
||||
ProgressFromTo *progressFromTo = new (std::nothrow) ProgressFromTo();
|
||||
progressFromTo->initWithDuration(duration, fromPercentage, toPercentage);
|
||||
progressFromTo->autorelease();
|
||||
|
||||
return progressFromTo;
|
||||
if (progressFromTo && progressFromTo->initWithDuration(duration, fromPercentage, toPercentage)) {
|
||||
progressFromTo->autorelease();
|
||||
return progressFromTo;
|
||||
}
|
||||
|
||||
delete progressFromTo;
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
bool ProgressFromTo::initWithDuration(float duration, float fromPercentage, float toPercentage)
|
||||
|
@ -105,11 +109,8 @@ bool ProgressFromTo::initWithDuration(float duration, float fromPercentage, floa
|
|||
|
||||
ProgressFromTo* ProgressFromTo::clone() const
|
||||
{
|
||||
// no copy constructor
|
||||
auto a = new (std::nothrow) ProgressFromTo();
|
||||
a->initWithDuration(_duration, _from, _to);
|
||||
a->autorelease();
|
||||
return a;
|
||||
// no copy constructor
|
||||
return ProgressFromTo::create(_duration, _from, _to);
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
/****************************************************************************
|
||||
Copyright (C) 2010 Lam Pham
|
||||
Copyright (c) 2010-2012 cocos2d-x.org
|
||||
CopyRight (c) 2013-2014 Chukong Technologies Inc.
|
||||
CopyRight (c) 2013-2016 Chukong Technologies Inc.
|
||||
|
||||
http://www.cocos2d-x.org
|
||||
|
||||
|
@ -55,8 +55,8 @@ public:
|
|||
//
|
||||
// Overrides
|
||||
//
|
||||
virtual ProgressTo* clone() const override;
|
||||
virtual ProgressTo* reverse() const override;
|
||||
virtual ProgressTo* clone() const override;
|
||||
virtual ProgressTo* reverse() const override;
|
||||
virtual void startWithTarget(Node *target) override;
|
||||
virtual void update(float time) override;
|
||||
|
||||
|
@ -99,8 +99,8 @@ public:
|
|||
//
|
||||
// Overrides
|
||||
//
|
||||
virtual ProgressFromTo* clone() const override;
|
||||
virtual ProgressFromTo* reverse() const override;
|
||||
virtual ProgressFromTo* clone() const override;
|
||||
virtual ProgressFromTo* reverse() const override;
|
||||
virtual void startWithTarget(Node *target) override;
|
||||
virtual void update(float time) override;
|
||||
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
/****************************************************************************
|
||||
Copyright (c) 2009 On-Core
|
||||
Copyright (c) 2010-2012 cocos2d-x.org
|
||||
CopyRight (c) 2013-2014 Chukong Technologies Inc.
|
||||
CopyRight (c) 2013-2016 Chukong Technologies Inc.
|
||||
|
||||
http://www.cocos2d-x.org
|
||||
|
||||
|
@ -44,19 +44,14 @@ ShakyTiles3D* ShakyTiles3D::create(float duration, const Size& gridSize, int ran
|
|||
{
|
||||
ShakyTiles3D *action = new (std::nothrow) ShakyTiles3D();
|
||||
|
||||
if (action)
|
||||
if (action && action->initWithDuration(duration, gridSize, range, shakeZ))
|
||||
{
|
||||
if (action->initWithDuration(duration, gridSize, range, shakeZ))
|
||||
{
|
||||
action->autorelease();
|
||||
}
|
||||
else
|
||||
{
|
||||
CC_SAFE_RELEASE_NULL(action);
|
||||
}
|
||||
action->autorelease();
|
||||
return action;
|
||||
}
|
||||
|
||||
return action;
|
||||
delete action;
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
bool ShakyTiles3D::initWithDuration(float duration, const Size& gridSize, int range, bool shakeZ)
|
||||
|
@ -74,11 +69,8 @@ bool ShakyTiles3D::initWithDuration(float duration, const Size& gridSize, int ra
|
|||
|
||||
ShakyTiles3D* ShakyTiles3D::clone() const
|
||||
{
|
||||
// no copy constructor
|
||||
auto a = new (std::nothrow) ShakyTiles3D();
|
||||
a->initWithDuration(_duration, _gridSize, _randrange, _shakeZ);
|
||||
a->autorelease();
|
||||
return a;
|
||||
// no copy constructor
|
||||
return ShakyTiles3D::create(_duration, _gridSize, _randrange, _shakeZ);
|
||||
}
|
||||
|
||||
void ShakyTiles3D::update(float time)
|
||||
|
@ -123,19 +115,14 @@ ShatteredTiles3D* ShatteredTiles3D::create(float duration, const Size& gridSize,
|
|||
{
|
||||
ShatteredTiles3D *action = new (std::nothrow) ShatteredTiles3D();
|
||||
|
||||
if (action)
|
||||
if (action && action->initWithDuration(duration, gridSize, range, shatterZ))
|
||||
{
|
||||
if (action->initWithDuration(duration, gridSize, range, shatterZ))
|
||||
{
|
||||
action->autorelease();
|
||||
}
|
||||
else
|
||||
{
|
||||
CC_SAFE_RELEASE_NULL(action);
|
||||
}
|
||||
action->autorelease();
|
||||
return action;
|
||||
}
|
||||
|
||||
return action;
|
||||
delete action;
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
bool ShatteredTiles3D::initWithDuration(float duration, const Size& gridSize, int range, bool shatterZ)
|
||||
|
@ -154,11 +141,8 @@ bool ShatteredTiles3D::initWithDuration(float duration, const Size& gridSize, in
|
|||
|
||||
ShatteredTiles3D* ShatteredTiles3D::clone() const
|
||||
{
|
||||
// no copy constructor
|
||||
auto a = new (std::nothrow) ShatteredTiles3D();
|
||||
a->initWithDuration(_duration, _gridSize, _randrange, _shatterZ);
|
||||
a->autorelease();
|
||||
return a;
|
||||
// no copy constructor
|
||||
return ShatteredTiles3D::create(_duration, _gridSize, _randrange, _shatterZ);
|
||||
}
|
||||
|
||||
void ShatteredTiles3D::update(float time)
|
||||
|
@ -208,19 +192,14 @@ ShuffleTiles* ShuffleTiles::create(float duration, const Size& gridSize, unsigne
|
|||
{
|
||||
ShuffleTiles *action = new (std::nothrow) ShuffleTiles();
|
||||
|
||||
if (action)
|
||||
if (action && action->initWithDuration(duration, gridSize, seed))
|
||||
{
|
||||
if (action->initWithDuration(duration, gridSize, seed))
|
||||
{
|
||||
action->autorelease();
|
||||
}
|
||||
else
|
||||
{
|
||||
CC_SAFE_RELEASE_NULL(action);
|
||||
}
|
||||
action->autorelease();
|
||||
return action;
|
||||
}
|
||||
|
||||
return action;
|
||||
delete action;
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
bool ShuffleTiles::initWithDuration(float duration, const Size& gridSize, unsigned int seed)
|
||||
|
@ -240,10 +219,7 @@ bool ShuffleTiles::initWithDuration(float duration, const Size& gridSize, unsign
|
|||
ShuffleTiles* ShuffleTiles::clone() const
|
||||
{
|
||||
// no copy constructor
|
||||
auto a = new (std::nothrow) ShuffleTiles();
|
||||
a->initWithDuration(_duration, _gridSize, _seed);
|
||||
a->autorelease();
|
||||
return a;
|
||||
return ShuffleTiles::create(_duration, _gridSize, _seed);
|
||||
}
|
||||
|
||||
ShuffleTiles::~ShuffleTiles()
|
||||
|
@ -354,28 +330,20 @@ FadeOutTRTiles* FadeOutTRTiles::create(float duration, const Size& gridSize)
|
|||
{
|
||||
FadeOutTRTiles *action = new (std::nothrow) FadeOutTRTiles();
|
||||
|
||||
if (action)
|
||||
if (action && action->initWithDuration(duration, gridSize))
|
||||
{
|
||||
if (action->initWithDuration(duration, gridSize))
|
||||
{
|
||||
action->autorelease();
|
||||
}
|
||||
else
|
||||
{
|
||||
CC_SAFE_RELEASE_NULL(action);
|
||||
}
|
||||
action->autorelease();
|
||||
return action;
|
||||
}
|
||||
|
||||
return action;
|
||||
delete action;
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
FadeOutTRTiles* FadeOutTRTiles::clone() const
|
||||
{
|
||||
// no copy constructor
|
||||
auto a = new (std::nothrow) FadeOutTRTiles();
|
||||
a->initWithDuration(_duration, _gridSize);
|
||||
a->autorelease();
|
||||
return a;
|
||||
return FadeOutTRTiles::create(_duration, _gridSize);
|
||||
}
|
||||
|
||||
float FadeOutTRTiles::testFunc(const Size& pos, float time)
|
||||
|
@ -450,28 +418,20 @@ FadeOutBLTiles* FadeOutBLTiles::create(float duration, const Size& gridSize)
|
|||
{
|
||||
FadeOutBLTiles *action = new (std::nothrow) FadeOutBLTiles();
|
||||
|
||||
if (action)
|
||||
if (action && action->initWithDuration(duration, gridSize))
|
||||
{
|
||||
if (action->initWithDuration(duration, gridSize))
|
||||
{
|
||||
action->autorelease();
|
||||
}
|
||||
else
|
||||
{
|
||||
CC_SAFE_RELEASE_NULL(action);
|
||||
}
|
||||
action->autorelease();
|
||||
return action;
|
||||
}
|
||||
|
||||
return action;
|
||||
delete action;
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
FadeOutBLTiles* FadeOutBLTiles::clone() const
|
||||
{
|
||||
// no copy constructor
|
||||
auto a = new (std::nothrow) FadeOutBLTiles();
|
||||
a->initWithDuration(_duration, _gridSize);
|
||||
a->autorelease();
|
||||
return a;
|
||||
return FadeOutBLTiles::create(_duration, _gridSize);
|
||||
}
|
||||
|
||||
float FadeOutBLTiles::testFunc(const Size& pos, float time)
|
||||
|
@ -491,28 +451,20 @@ FadeOutUpTiles* FadeOutUpTiles::create(float duration, const Size& gridSize)
|
|||
{
|
||||
FadeOutUpTiles *action = new (std::nothrow) FadeOutUpTiles();
|
||||
|
||||
if (action)
|
||||
if (action && action->initWithDuration(duration, gridSize))
|
||||
{
|
||||
if (action->initWithDuration(duration, gridSize))
|
||||
{
|
||||
action->autorelease();
|
||||
}
|
||||
else
|
||||
{
|
||||
CC_SAFE_RELEASE_NULL(action);
|
||||
}
|
||||
action->autorelease();
|
||||
return action;
|
||||
}
|
||||
|
||||
return action;
|
||||
delete action;
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
FadeOutUpTiles* FadeOutUpTiles::clone() const
|
||||
{
|
||||
// no copy constructor
|
||||
auto a = new (std::nothrow) FadeOutUpTiles();
|
||||
a->initWithDuration(_duration, _gridSize);
|
||||
a->autorelease();
|
||||
return a;
|
||||
return FadeOutUpTiles::create(_duration, _gridSize);
|
||||
}
|
||||
|
||||
float FadeOutUpTiles::testFunc(const Size& pos, float time)
|
||||
|
@ -545,28 +497,20 @@ FadeOutDownTiles* FadeOutDownTiles::create(float duration, const Size& gridSize)
|
|||
{
|
||||
FadeOutDownTiles *action = new (std::nothrow) FadeOutDownTiles();
|
||||
|
||||
if (action)
|
||||
if (action && action->initWithDuration(duration, gridSize))
|
||||
{
|
||||
if (action->initWithDuration(duration, gridSize))
|
||||
{
|
||||
action->autorelease();
|
||||
}
|
||||
else
|
||||
{
|
||||
CC_SAFE_RELEASE_NULL(action);
|
||||
}
|
||||
action->autorelease();
|
||||
return action;
|
||||
}
|
||||
|
||||
return action;
|
||||
delete action;
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
FadeOutDownTiles* FadeOutDownTiles::clone() const
|
||||
{
|
||||
// no copy constructor
|
||||
auto a = new (std::nothrow) FadeOutDownTiles();
|
||||
a->initWithDuration(_duration, _gridSize);
|
||||
a->autorelease();
|
||||
return a;
|
||||
return FadeOutDownTiles::create(_duration, _gridSize);
|
||||
}
|
||||
|
||||
float FadeOutDownTiles::testFunc(const Size& pos, float time)
|
||||
|
@ -579,35 +523,29 @@ float FadeOutDownTiles::testFunc(const Size& pos, float time)
|
|||
|
||||
TurnOffTiles* TurnOffTiles::create(float duration, const Size& gridSize)
|
||||
{
|
||||
TurnOffTiles* pAction = new (std::nothrow) TurnOffTiles();
|
||||
if (pAction->initWithDuration(duration, gridSize, 0))
|
||||
TurnOffTiles* action = new (std::nothrow) TurnOffTiles();
|
||||
if (action && action->initWithDuration(duration, gridSize, 0))
|
||||
{
|
||||
pAction->autorelease();
|
||||
action->autorelease();
|
||||
return action;
|
||||
}
|
||||
else
|
||||
{
|
||||
CC_SAFE_RELEASE_NULL(pAction);
|
||||
}
|
||||
return pAction;
|
||||
|
||||
delete action;
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
TurnOffTiles* TurnOffTiles::create(float duration, const Size& gridSize, unsigned int seed)
|
||||
{
|
||||
TurnOffTiles *action = new (std::nothrow) TurnOffTiles();
|
||||
|
||||
if (action)
|
||||
if (action && action->initWithDuration(duration, gridSize, seed))
|
||||
{
|
||||
if (action->initWithDuration(duration, gridSize, seed))
|
||||
{
|
||||
action->autorelease();
|
||||
}
|
||||
else
|
||||
{
|
||||
CC_SAFE_RELEASE_NULL(action);
|
||||
}
|
||||
action->autorelease();
|
||||
return action;
|
||||
}
|
||||
|
||||
return action;
|
||||
delete action;
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
bool TurnOffTiles::initWithDuration(float duration, const Size& gridSize, unsigned int seed)
|
||||
|
@ -626,10 +564,7 @@ bool TurnOffTiles::initWithDuration(float duration, const Size& gridSize, unsign
|
|||
TurnOffTiles* TurnOffTiles::clone() const
|
||||
{
|
||||
// no copy constructor
|
||||
auto a = new (std::nothrow) TurnOffTiles();
|
||||
a->initWithDuration(_duration, _gridSize, _seed );
|
||||
a->autorelease();
|
||||
return a;
|
||||
return TurnOffTiles::create(_duration, _gridSize, _seed);
|
||||
}
|
||||
|
||||
TurnOffTiles::~TurnOffTiles(void)
|
||||
|
@ -708,19 +643,14 @@ WavesTiles3D* WavesTiles3D::create(float duration, const Size& gridSize, unsigne
|
|||
{
|
||||
WavesTiles3D *action = new (std::nothrow) WavesTiles3D();
|
||||
|
||||
if (action)
|
||||
if (action && action->initWithDuration(duration, gridSize, waves, amplitude))
|
||||
{
|
||||
if (action->initWithDuration(duration, gridSize, waves, amplitude))
|
||||
{
|
||||
action->autorelease();
|
||||
}
|
||||
else
|
||||
{
|
||||
CC_SAFE_RELEASE_NULL(action);
|
||||
}
|
||||
action->autorelease();
|
||||
return action;
|
||||
}
|
||||
|
||||
return action;
|
||||
delete action;
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
bool WavesTiles3D::initWithDuration(float duration, const Size& gridSize, unsigned int waves, float amplitude)
|
||||
|
@ -740,10 +670,7 @@ bool WavesTiles3D::initWithDuration(float duration, const Size& gridSize, unsign
|
|||
WavesTiles3D* WavesTiles3D::clone() const
|
||||
{
|
||||
// no copy constructor
|
||||
auto a = new (std::nothrow) WavesTiles3D();
|
||||
a->initWithDuration(_duration, _gridSize, _waves, _amplitude);
|
||||
a->autorelease();
|
||||
return a;
|
||||
return WavesTiles3D::create(_duration, _gridSize, _waves, _amplitude);
|
||||
}
|
||||
|
||||
void WavesTiles3D::update(float time)
|
||||
|
@ -771,19 +698,14 @@ JumpTiles3D* JumpTiles3D::create(float duration, const Size& gridSize, unsigned
|
|||
{
|
||||
JumpTiles3D *action = new (std::nothrow) JumpTiles3D();
|
||||
|
||||
if (action)
|
||||
if (action && action->initWithDuration(duration, gridSize, numberOfJumps, amplitude))
|
||||
{
|
||||
if (action->initWithDuration(duration, gridSize, numberOfJumps, amplitude))
|
||||
{
|
||||
action->autorelease();
|
||||
}
|
||||
else
|
||||
{
|
||||
CC_SAFE_RELEASE_NULL(action);
|
||||
}
|
||||
action->autorelease();
|
||||
return action;
|
||||
}
|
||||
|
||||
return action;
|
||||
delete action;
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
bool JumpTiles3D::initWithDuration(float duration, const Size& gridSize, unsigned int numberOfJumps, float amplitude)
|
||||
|
@ -803,10 +725,7 @@ bool JumpTiles3D::initWithDuration(float duration, const Size& gridSize, unsigne
|
|||
JumpTiles3D* JumpTiles3D::clone() const
|
||||
{
|
||||
// no copy constructor
|
||||
auto a = new (std::nothrow) JumpTiles3D();
|
||||
a->initWithDuration(_duration, _gridSize, _jumps, _amplitude);
|
||||
a->autorelease();
|
||||
return a;
|
||||
return JumpTiles3D::create(_duration, _gridSize, _jumps, _amplitude);
|
||||
}
|
||||
|
||||
void JumpTiles3D::update(float time)
|
||||
|
@ -846,19 +765,14 @@ SplitRows* SplitRows::create(float duration, unsigned int nRows)
|
|||
{
|
||||
SplitRows *action = new (std::nothrow) SplitRows();
|
||||
|
||||
if (action)
|
||||
if (action && action->initWithDuration(duration, nRows))
|
||||
{
|
||||
if (action->initWithDuration(duration, nRows))
|
||||
{
|
||||
action->autorelease();
|
||||
}
|
||||
else
|
||||
{
|
||||
CC_SAFE_RELEASE_NULL(action);
|
||||
}
|
||||
action->autorelease();
|
||||
return action;
|
||||
}
|
||||
|
||||
return action;
|
||||
delete action;
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
bool SplitRows::initWithDuration(float duration, unsigned int rows)
|
||||
|
@ -871,10 +785,7 @@ bool SplitRows::initWithDuration(float duration, unsigned int rows)
|
|||
SplitRows* SplitRows::clone() const
|
||||
{
|
||||
// no copy constructor
|
||||
auto a = new (std::nothrow) SplitRows();
|
||||
a->initWithDuration(_duration, _rows);
|
||||
a->autorelease();
|
||||
return a;
|
||||
return SplitRows::create(_duration, _rows);
|
||||
}
|
||||
|
||||
void SplitRows::startWithTarget(Node *target)
|
||||
|
@ -910,19 +821,14 @@ SplitCols* SplitCols::create(float duration, unsigned int cols)
|
|||
{
|
||||
SplitCols *action = new (std::nothrow) SplitCols();
|
||||
|
||||
if (action)
|
||||
if (action && action->initWithDuration(duration, cols))
|
||||
{
|
||||
if (action->initWithDuration(duration, cols))
|
||||
{
|
||||
action->autorelease();
|
||||
}
|
||||
else
|
||||
{
|
||||
CC_SAFE_RELEASE_NULL(action);
|
||||
}
|
||||
action->autorelease();
|
||||
return action;
|
||||
}
|
||||
|
||||
return action;
|
||||
delete action;
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
bool SplitCols::initWithDuration(float duration, unsigned int cols)
|
||||
|
@ -933,11 +839,8 @@ bool SplitCols::initWithDuration(float duration, unsigned int cols)
|
|||
|
||||
SplitCols* SplitCols::clone() const
|
||||
{
|
||||
// no copy constructor
|
||||
auto a = new (std::nothrow) SplitCols();
|
||||
a->initWithDuration(_duration, _cols);
|
||||
a->autorelease();
|
||||
return a;
|
||||
// no copy constructor
|
||||
return SplitCols::create(_duration, _cols);
|
||||
}
|
||||
|
||||
void SplitCols::startWithTarget(Node *target)
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
/****************************************************************************
|
||||
Copyright (c) 2009 On-Core
|
||||
Copyright (c) 2010-2012 cocos2d-x.org
|
||||
CopyRight (c) 2013-2014 Chukong Technologies Inc.
|
||||
CopyRight (c) 2013-2016 Chukong Technologies Inc.
|
||||
|
||||
http://www.cocos2d-x.org
|
||||
|
||||
|
@ -55,7 +55,7 @@ public:
|
|||
static ShakyTiles3D* create(float duration, const Size& gridSize, int range, bool shakeZ);
|
||||
|
||||
// Override
|
||||
virtual ShakyTiles3D* clone() const override;
|
||||
virtual ShakyTiles3D* clone() const override;
|
||||
virtual void update(float time) override;
|
||||
|
||||
CC_CONSTRUCTOR_ACCESS:
|
||||
|
@ -100,7 +100,7 @@ public:
|
|||
static ShatteredTiles3D* create(float duration, const Size& gridSize, int range, bool shatterZ);
|
||||
|
||||
// Override
|
||||
virtual ShatteredTiles3D* clone() const override;
|
||||
virtual ShatteredTiles3D* clone() const override;
|
||||
virtual void update(float time) override;
|
||||
|
||||
CC_CONSTRUCTOR_ACCESS:
|
||||
|
@ -152,7 +152,7 @@ public:
|
|||
// Overrides
|
||||
virtual void startWithTarget(Node *target) override;
|
||||
virtual void update(float time) override;
|
||||
virtual ShuffleTiles* clone() const override;
|
||||
virtual ShuffleTiles* clone() const override;
|
||||
|
||||
CC_CONSTRUCTOR_ACCESS:
|
||||
ShuffleTiles() {}
|
||||
|
@ -221,7 +221,7 @@ public:
|
|||
|
||||
// Overrides
|
||||
virtual void update(float time) override;
|
||||
virtual FadeOutTRTiles* clone() const override;
|
||||
virtual FadeOutTRTiles* clone() const override;
|
||||
|
||||
CC_CONSTRUCTOR_ACCESS:
|
||||
FadeOutTRTiles() {}
|
||||
|
@ -248,7 +248,7 @@ public:
|
|||
|
||||
// Overrides
|
||||
virtual float testFunc(const Size& pos, float time) override;
|
||||
virtual FadeOutBLTiles* clone() const override;
|
||||
virtual FadeOutBLTiles* clone() const override;
|
||||
|
||||
CC_CONSTRUCTOR_ACCESS:
|
||||
FadeOutBLTiles() {}
|
||||
|
@ -276,7 +276,7 @@ public:
|
|||
virtual void transformTile(const Vec2& pos, float distance) override;
|
||||
|
||||
// Overrides
|
||||
virtual FadeOutUpTiles* clone() const override;
|
||||
virtual FadeOutUpTiles* clone() const override;
|
||||
virtual float testFunc(const Size& pos, float time) override;
|
||||
|
||||
CC_CONSTRUCTOR_ACCESS:
|
||||
|
@ -303,7 +303,7 @@ public:
|
|||
static FadeOutDownTiles* create(float duration, const Size& gridSize);
|
||||
|
||||
// Overrides
|
||||
virtual FadeOutDownTiles* clone() const override;
|
||||
virtual FadeOutDownTiles* clone() const override;
|
||||
virtual float testFunc(const Size& pos, float time) override;
|
||||
|
||||
CC_CONSTRUCTOR_ACCESS:
|
||||
|
@ -423,7 +423,7 @@ public:
|
|||
inline void setAmplitudeRate(float amplitudeRate) { _amplitudeRate = amplitudeRate; }
|
||||
|
||||
// Override
|
||||
virtual WavesTiles3D* clone() const override;
|
||||
virtual WavesTiles3D* clone() const override;
|
||||
virtual void update(float time) override;
|
||||
|
||||
CC_CONSTRUCTOR_ACCESS:
|
||||
|
@ -489,7 +489,7 @@ public:
|
|||
inline void setAmplitudeRate(float amplitudeRate) { _amplitudeRate = amplitudeRate; }
|
||||
|
||||
// Override
|
||||
virtual JumpTiles3D* clone() const override;
|
||||
virtual JumpTiles3D* clone() const override;
|
||||
virtual void update(float time) override;
|
||||
|
||||
CC_CONSTRUCTOR_ACCESS:
|
||||
|
@ -532,7 +532,7 @@ public :
|
|||
static SplitRows* create(float duration, unsigned int rows);
|
||||
|
||||
// Overrides
|
||||
virtual SplitRows* clone() const override;
|
||||
virtual SplitRows* clone() const override;
|
||||
virtual void update(float time) override;
|
||||
virtual void startWithTarget(Node *target) override;
|
||||
|
||||
|
@ -574,7 +574,7 @@ public:
|
|||
static SplitCols* create(float duration, unsigned int cols);
|
||||
|
||||
// Overrides
|
||||
virtual SplitCols* clone() const override;
|
||||
virtual SplitCols* clone() const override;
|
||||
/**
|
||||
* @param time in seconds
|
||||
*/
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
/****************************************************************************
|
||||
Copyright (c) 2009 lhunath (Maarten Billemont)
|
||||
Copyright (c) 2010-2012 cocos2d-x.org
|
||||
CopyRight (c) 2013-2014 Chukong Technologies Inc.
|
||||
CopyRight (c) 2013-2016 Chukong Technologies Inc.
|
||||
|
||||
http://www.cocos2d-x.org
|
||||
|
||||
|
@ -34,12 +34,11 @@ ActionTween* ActionTween::create(float duration, const std::string& key, float f
|
|||
if (ret && ret->initWithDuration(duration, key, from, to))
|
||||
{
|
||||
ret->autorelease();
|
||||
return ret;
|
||||
}
|
||||
else
|
||||
{
|
||||
CC_SAFE_DELETE(ret);
|
||||
}
|
||||
return ret;
|
||||
|
||||
delete ret;
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
bool ActionTween::initWithDuration(float duration, const std::string& key, float from, float to)
|
||||
|
@ -57,11 +56,7 @@ bool ActionTween::initWithDuration(float duration, const std::string& key, float
|
|||
|
||||
ActionTween *ActionTween::clone() const
|
||||
{
|
||||
// no copy constructor
|
||||
auto a = new (std::nothrow) ActionTween();
|
||||
a->initWithDuration(_duration, _key, _from, _to);
|
||||
a->autorelease();
|
||||
return a;
|
||||
return ActionTween::create(_duration, _key, _from, _to);
|
||||
}
|
||||
|
||||
void ActionTween::startWithTarget(Node *target)
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
/****************************************************************************
|
||||
Copyright (c) 2009 lhunath (Maarten Billemont)
|
||||
Copyright (c) 2010-2012 cocos2d-x.org
|
||||
CopyRight (c) 2013-2014 Chukong Technologies Inc.
|
||||
CopyRight (c) 2013-2016 Chukong Technologies Inc.
|
||||
|
||||
http://www.cocos2d-x.org
|
||||
|
||||
|
@ -98,7 +98,7 @@ public:
|
|||
void startWithTarget(Node *target) override;
|
||||
void update(float dt) override;
|
||||
ActionTween* reverse() const override;
|
||||
ActionTween *clone() const override;
|
||||
ActionTween *clone() const override;
|
||||
|
||||
CC_CONSTRUCTOR_ACCESS:
|
||||
/**
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
Copyright (c) 2008-2010 Ricardo Quesada
|
||||
Copyright (c) 2010-2012 cocos2d-x.org
|
||||
Copyright (c) 2011 Zynga Inc.
|
||||
CopyRight (c) 2013-2014 Chukong Technologies Inc.
|
||||
CopyRight (c) 2013-2016 Chukong Technologies Inc.
|
||||
|
||||
http://www.cocos2d-x.org
|
||||
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
Copyright (c) 2008-2010 Ricardo Quesada
|
||||
Copyright (c) 2010-2012 cocos2d-x.org
|
||||
Copyright (c) 2011 Zynga Inc.
|
||||
CopyRight (c) 2013-2014 Chukong Technologies Inc.
|
||||
CopyRight (c) 2013-2016 Chukong Technologies Inc.
|
||||
|
||||
http://www.cocos2d-x.org
|
||||
|
||||
|
@ -121,7 +121,7 @@ public:
|
|||
}
|
||||
|
||||
// Overrides
|
||||
virtual AnimationFrame *clone() const override;
|
||||
virtual AnimationFrame *clone() const override;
|
||||
|
||||
CC_CONSTRUCTOR_ACCESS:
|
||||
/**
|
||||
|
@ -202,7 +202,7 @@ public:
|
|||
void addSpriteFrameWithFile(const std::string& filename);
|
||||
/**
|
||||
* @deprecated. Use addSpriteFrameWithFile() instead.
|
||||
@js NA
|
||||
@js NA
|
||||
*/
|
||||
CC_DEPRECATED_ATTRIBUTE void addSpriteFrameWithFileName(const std::string& filename){ addSpriteFrameWithFile(filename);}
|
||||
|
||||
|
@ -279,7 +279,7 @@ public:
|
|||
void setLoops(unsigned int loops) { _loops = loops; };
|
||||
|
||||
// overrides
|
||||
virtual Animation *clone() const override;
|
||||
virtual Animation *clone() const override;
|
||||
|
||||
CC_CONSTRUCTOR_ACCESS:
|
||||
Animation();
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
Copyright (c) 2008-2010 Ricardo Quesada
|
||||
Copyright (c) 2010-2012 cocos2d-x.org
|
||||
Copyright (c) 2011 Zynga Inc.
|
||||
CopyRight (c) 2013-2014 Chukong Technologies Inc.
|
||||
CopyRight (c) 2013-2016 Chukong Technologies Inc.
|
||||
|
||||
http://www.cocos2d-x.org
|
||||
|
||||
|
@ -71,7 +71,7 @@ void AnimationCache::addAnimation(Animation *animation, const std::string& name)
|
|||
|
||||
void AnimationCache::removeAnimation(const std::string& name)
|
||||
{
|
||||
if (name.size()==0)
|
||||
if (name.empty())
|
||||
return;
|
||||
|
||||
_animations.erase(name);
|
||||
|
@ -222,12 +222,18 @@ void AnimationCache::addAnimationsWithDictionary(const ValueMap& dictionary,cons
|
|||
/** Read an NSDictionary from a plist file and parse it automatically for animations */
|
||||
void AnimationCache::addAnimationsWithFile(const std::string& plist)
|
||||
{
|
||||
CCASSERT( plist.size()>0, "Invalid texture file name");
|
||||
|
||||
std::string path = FileUtils::getInstance()->fullPathForFilename(plist);
|
||||
ValueMap dict = FileUtils::getInstance()->getValueMapFromFile(path);
|
||||
CCASSERT(!plist.empty(), "Invalid texture file name");
|
||||
if (plist.empty()) {
|
||||
log("%s error:file name is empty!", __FUNCTION__);
|
||||
return;
|
||||
}
|
||||
|
||||
ValueMap dict = FileUtils::getInstance()->getValueMapFromFile(plist);
|
||||
|
||||
CCASSERT( !dict.empty(), "CCAnimationCache: File could not be found");
|
||||
if (dict.empty()) {
|
||||
log("AnimationCache::addAnimationsWithFile error:%s not exist!", plist.c_str());
|
||||
}
|
||||
|
||||
addAnimationsWithDictionary(dict,plist);
|
||||
}
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
Copyright (c) 2008-2010 Ricardo Quesada
|
||||
Copyright (c) 2010-2012 cocos2d-x.org
|
||||
Copyright (c) 2011 Zynga Inc.
|
||||
CopyRight (c) 2013-2014 Chukong Technologies Inc.
|
||||
CopyRight (c) 2013-2016 Chukong Technologies Inc.
|
||||
|
||||
http://www.cocos2d-x.org
|
||||
|
||||
|
|
|
@ -38,20 +38,32 @@ USING_NS_CC;
|
|||
static unsigned short quadIndices[]={0,1,2, 3,2,1};
|
||||
const static float PRECISION = 10.0f;
|
||||
|
||||
PolygonInfo::PolygonInfo(const PolygonInfo& other):
|
||||
triangles(),
|
||||
rect(),
|
||||
isVertsOwner(true)
|
||||
PolygonInfo::PolygonInfo()
|
||||
: rect(cocos2d::Rect::ZERO)
|
||||
, filename("")
|
||||
, isVertsOwner(true)
|
||||
{
|
||||
triangles.verts = nullptr;
|
||||
triangles.indices = nullptr;
|
||||
triangles.vertCount = 0;
|
||||
triangles.indexCount = 0;
|
||||
};
|
||||
|
||||
PolygonInfo::PolygonInfo(const PolygonInfo& other)
|
||||
: triangles()
|
||||
, rect()
|
||||
, isVertsOwner(true)
|
||||
{
|
||||
filename = other.filename;
|
||||
isVertsOwner = true;
|
||||
rect = other.rect;
|
||||
triangles.verts = new (std::nothrow) V3F_C4B_T2F[other.triangles.vertCount];
|
||||
triangles.indices = new (std::nothrow) unsigned short[other.triangles.indexCount];
|
||||
CCASSERT(triangles.verts && triangles.indices, "not enough memory");
|
||||
triangles.vertCount = other.triangles.vertCount;
|
||||
triangles.indexCount = other.triangles.indexCount;
|
||||
memcpy(triangles.verts, other.triangles.verts, other.triangles.vertCount*sizeof(V3F_C4B_T2F));
|
||||
memcpy(triangles.indices, other.triangles.indices, other.triangles.indexCount*sizeof(unsigned short));
|
||||
memcpy(triangles.verts, other.triangles.verts, other.triangles.vertCount * sizeof(other.triangles.verts[0]));
|
||||
memcpy(triangles.indices, other.triangles.indices, other.triangles.indexCount * sizeof(other.triangles.indices[0]));
|
||||
};
|
||||
|
||||
PolygonInfo& PolygonInfo::operator= (const PolygonInfo& other)
|
||||
|
@ -64,10 +76,11 @@ PolygonInfo& PolygonInfo::operator= (const PolygonInfo& other)
|
|||
rect = other.rect;
|
||||
triangles.verts = new (std::nothrow) V3F_C4B_T2F[other.triangles.vertCount];
|
||||
triangles.indices = new (std::nothrow) unsigned short[other.triangles.indexCount];
|
||||
CCASSERT(triangles.verts && triangles.indices, "not enough memory");
|
||||
triangles.vertCount = other.triangles.vertCount;
|
||||
triangles.indexCount = other.triangles.indexCount;
|
||||
memcpy(triangles.verts, other.triangles.verts, other.triangles.vertCount*sizeof(V3F_C4B_T2F));
|
||||
memcpy(triangles.indices, other.triangles.indices, other.triangles.indexCount*sizeof(unsigned short));
|
||||
memcpy(triangles.verts, other.triangles.verts, other.triangles.vertCount * sizeof(other.triangles.verts[0]));
|
||||
memcpy(triangles.indices, other.triangles.indices, other.triangles.indexCount * sizeof(other.triangles.indices[0]));
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
|
@ -87,7 +100,7 @@ void PolygonInfo::setQuad(V3F_C4B_T2F_Quad *quad)
|
|||
triangles.verts = (V3F_C4B_T2F*)quad;
|
||||
}
|
||||
|
||||
void PolygonInfo::setTriangles(TrianglesCommand::Triangles other)
|
||||
void PolygonInfo::setTriangles(const TrianglesCommand::Triangles& other)
|
||||
{
|
||||
this->releaseVertsAndIndices();
|
||||
isVertsOwner = false;
|
||||
|
@ -421,7 +434,7 @@ float AutoPolygon::perpendicularDistance(const cocos2d::Vec2& i, const cocos2d::
|
|||
}
|
||||
return res;
|
||||
}
|
||||
std::vector<cocos2d::Vec2> AutoPolygon::rdp(std::vector<cocos2d::Vec2> v, const float& optimization)
|
||||
std::vector<cocos2d::Vec2> AutoPolygon::rdp(const std::vector<cocos2d::Vec2>& v, float optimization)
|
||||
{
|
||||
if(v.size() < 3)
|
||||
return v;
|
||||
|
@ -435,7 +448,7 @@ std::vector<cocos2d::Vec2> AutoPolygon::rdp(std::vector<cocos2d::Vec2> v, const
|
|||
if(cdist > dist)
|
||||
{
|
||||
dist = cdist;
|
||||
index = i;
|
||||
index = static_cast<int>(i);
|
||||
}
|
||||
}
|
||||
if (dist>optimization)
|
||||
|
@ -562,12 +575,14 @@ TrianglesCommand::Triangles AutoPolygon::triangulate(const std::vector<Vec2>& po
|
|||
cdt.Triangulate();
|
||||
std::vector<p2t::Triangle*> tris = cdt.GetTriangles();
|
||||
|
||||
V3F_C4B_T2F* verts= new (std::nothrow) V3F_C4B_T2F[points.size()];
|
||||
unsigned short* indices = new (std::nothrow) unsigned short[tris.size()*3];
|
||||
// we won't know the size of verts and indices until we process all of the triangles!
|
||||
std::vector<V3F_C4B_T2F> verts;
|
||||
std::vector<unsigned short> indices;
|
||||
|
||||
unsigned short idx = 0;
|
||||
unsigned short vdx = 0;
|
||||
|
||||
for(std::vector<p2t::Triangle*>::const_iterator ite = tris.begin(); ite < tris.end(); ite++)
|
||||
for(std::vector<p2t::Triangle*>::const_iterator ite = tris.begin(); ite != tris.end(); ite++)
|
||||
{
|
||||
for(int i = 0; i < 3; i++)
|
||||
{
|
||||
|
@ -587,7 +602,7 @@ TrianglesCommand::Triangles AutoPolygon::triangulate(const std::vector<Vec2>& po
|
|||
if(found)
|
||||
{
|
||||
//if we found the same vertex, don't add to verts, but use the same vertex with indices
|
||||
indices[idx] = j;
|
||||
indices.push_back(j);
|
||||
idx++;
|
||||
}
|
||||
else
|
||||
|
@ -596,8 +611,8 @@ TrianglesCommand::Triangles AutoPolygon::triangulate(const std::vector<Vec2>& po
|
|||
auto c4b = Color4B::WHITE;
|
||||
auto t2f = Tex2F(0,0); // don't worry about tex coords now, we calculate that later
|
||||
V3F_C4B_T2F vert = {v3,c4b,t2f};
|
||||
verts[vdx] = vert;
|
||||
indices[idx] = vdx;
|
||||
verts.push_back(vert);
|
||||
indices.push_back(vdx);
|
||||
idx++;
|
||||
vdx++;
|
||||
}
|
||||
|
@ -607,7 +622,17 @@ TrianglesCommand::Triangles AutoPolygon::triangulate(const std::vector<Vec2>& po
|
|||
{
|
||||
delete j;
|
||||
};
|
||||
TrianglesCommand::Triangles triangles = {verts, indices, vdx, idx};
|
||||
|
||||
// now that we know the size of verts and indices we can create the buffers
|
||||
V3F_C4B_T2F* vertsBuf = new (std::nothrow) V3F_C4B_T2F[verts.size()];
|
||||
memcpy(vertsBuf, verts.data(), verts.size() * sizeof(V3F_C4B_T2F));
|
||||
|
||||
unsigned short* indicesBuf = new (std::nothrow) unsigned short[indices.size()];
|
||||
memcpy(indicesBuf, indices.data(), indices.size() * sizeof(short));
|
||||
|
||||
// Triangles should really use std::vector and not arrays for verts and indices.
|
||||
// Then the above memcpy would not be necessary
|
||||
TrianglesCommand::Triangles triangles = { vertsBuf, indicesBuf, static_cast<int>(verts.size()), static_cast<int>(indices.size()) };
|
||||
return triangles;
|
||||
}
|
||||
|
||||
|
@ -679,6 +704,5 @@ PolygonInfo AutoPolygon::generateTriangles(const Rect& rect, const float& epsilo
|
|||
PolygonInfo AutoPolygon::generatePolygon(const std::string& filename, const Rect& rect, const float epsilon, const float threshold)
|
||||
{
|
||||
AutoPolygon ap(filename);
|
||||
auto ret = ap.generateTriangles(rect, epsilon, threshold);
|
||||
return ret;
|
||||
return ap.generateTriangles(rect, epsilon, threshold);
|
||||
}
|
||||
|
|
|
@ -54,17 +54,8 @@ public:
|
|||
* @memberof PolygonInfo
|
||||
* @return PolygonInfo object
|
||||
*/
|
||||
PolygonInfo():
|
||||
rect(cocos2d::Rect::ZERO),
|
||||
filename(""),
|
||||
isVertsOwner(true)
|
||||
{
|
||||
triangles.verts = nullptr;
|
||||
triangles.indices = nullptr;
|
||||
triangles.vertCount = 0;
|
||||
triangles.indexCount = 0;
|
||||
};
|
||||
|
||||
PolygonInfo();
|
||||
|
||||
/**
|
||||
* Create an polygoninfo from the data of another Polygoninfo
|
||||
* @param other another PolygonInfo to be copied
|
||||
|
@ -95,7 +86,7 @@ public:
|
|||
* as the verts memory are managed by other objects
|
||||
* @param triangles a pointer to the TrianglesCommand::Triangles object
|
||||
*/
|
||||
void setTriangles(TrianglesCommand::Triangles triangles);
|
||||
void setTriangles(const TrianglesCommand::Triangles& triangles);
|
||||
|
||||
/**
|
||||
* get vertex count
|
||||
|
@ -260,7 +251,7 @@ protected:
|
|||
int getIndexFromPos(const unsigned int& x, const unsigned int& y){return y*_width+x;};
|
||||
cocos2d::Vec2 getPosFromIndex(const unsigned int& i){return cocos2d::Vec2(i%_width, i/_width);};
|
||||
|
||||
std::vector<cocos2d::Vec2> rdp(std::vector<cocos2d::Vec2> v, const float& optimization);
|
||||
std::vector<cocos2d::Vec2> rdp(const std::vector<cocos2d::Vec2>& v, float optimization);
|
||||
float perpendicularDistance(const cocos2d::Vec2& i, const cocos2d::Vec2& start, const cocos2d::Vec2& end);
|
||||
|
||||
//real rect is the size that is in scale with the texture file
|
||||
|
|
|
@ -326,9 +326,7 @@ void DrawNode::draw(Renderer *renderer, const Mat4 &transform, uint32_t flags)
|
|||
|
||||
void DrawNode::onDraw(const Mat4 &transform, uint32_t flags)
|
||||
{
|
||||
auto glProgram = getGLProgram();
|
||||
glProgram->use();
|
||||
glProgram->setUniformsForBuiltins(transform);
|
||||
getGLProgramState()->apply(transform);
|
||||
|
||||
GL::blendFunc(_blendFunc.src, _blendFunc.dst);
|
||||
|
||||
|
|
|
@ -196,7 +196,7 @@ namespace DrawPrimitives
|
|||
* @param origin The origin of the bezier path.
|
||||
* @param control The control of the bezier path.
|
||||
* @param destination The destination of the bezier path.
|
||||
* @param segments The The number of segments.
|
||||
* @param segments The number of segments.
|
||||
* @warning This function could be pretty slow. Use it only for debugging purposes.
|
||||
* @since v0.8
|
||||
*/
|
||||
|
@ -208,7 +208,7 @@ namespace DrawPrimitives
|
|||
* @param control1 The first control of the bezier path.
|
||||
* @param control2 The second control of the bezier path.
|
||||
* @param destination The destination of the bezier path.
|
||||
* @param segments The The number of segments.
|
||||
* @param segments The number of segments.
|
||||
* @warning This function could be pretty slow. Use it only for debugging purposes.
|
||||
* @since v0.8
|
||||
*/
|
||||
|
@ -217,7 +217,7 @@ namespace DrawPrimitives
|
|||
/** Draws a Catmull Rom path.
|
||||
*
|
||||
* @param arrayOfControlPoints A point array of control point.
|
||||
* @param segments The The number of segments.
|
||||
* @param segments The number of segments.
|
||||
* @warning This function could be pretty slow. Use it only for debugging purposes.
|
||||
* @since v2.0
|
||||
*/
|
||||
|
@ -227,7 +227,7 @@ namespace DrawPrimitives
|
|||
*
|
||||
* @param config A array point.
|
||||
* @param tension The tension of the spline.
|
||||
* @param segments The The number of segments.
|
||||
* @param segments The number of segments.
|
||||
* @warning This function could be pretty slow. Use it only for debugging purposes.
|
||||
* @since v2.0
|
||||
*/
|
||||
|
|
|
@ -828,7 +828,7 @@ void TMXLayer::setTileGID(int gid, const Vec2& tileCoordinate, TMXTileFlags flag
|
|||
}
|
||||
}
|
||||
|
||||
void TMXLayer::setupTileSprite(Sprite* sprite, Vec2 pos, int gid)
|
||||
void TMXLayer::setupTileSprite(Sprite* sprite, const Vec2& pos, int gid)
|
||||
{
|
||||
sprite->setPosition(getPositionAt(pos));
|
||||
sprite->setPositionZ((float)getVertexZForPos(pos));
|
||||
|
|
|
@ -261,7 +261,7 @@ public:
|
|||
* @param pos The tile coordinate.
|
||||
* @param gid The tile gid.
|
||||
*/
|
||||
void setupTileSprite(Sprite* sprite, Vec2 pos, int gid);
|
||||
void setupTileSprite(Sprite* sprite, const Vec2& pos, int gid);
|
||||
|
||||
//
|
||||
// Override
|
||||
|
|
|
@ -316,8 +316,8 @@ std::set<unsigned int>* BMFontConfiguration::parseConfigFile(const std::string&
|
|||
|
||||
auto next = strchr(contents, '\n');
|
||||
auto base = contents;
|
||||
int lineLength = 0;
|
||||
int parseCount = 0;
|
||||
size_t lineLength = 0;
|
||||
size_t parseCount = 0;
|
||||
while (next)
|
||||
{
|
||||
lineLength = ((int)(next - base));
|
||||
|
@ -809,7 +809,11 @@ FontAtlas * FontFNT::createFontAtlas()
|
|||
tempDefinition.validDefinition = true;
|
||||
tempDefinition.xAdvance = fontDef.xAdvance;
|
||||
// add the new definition
|
||||
tempAtlas->addLetterDefinition(fontDef.charID,tempDefinition);
|
||||
if (65535 < fontDef.charID) {
|
||||
CCLOGWARN("Warning: 65535 < fontDef.charID (%u), ignored", fontDef.charID);
|
||||
} else {
|
||||
tempAtlas->addLetterDefinition(fontDef.charID,tempDefinition);
|
||||
}
|
||||
}
|
||||
|
||||
// add the texture (only one texture for now)
|
||||
|
|
|
@ -46,7 +46,6 @@
|
|||
|
||||
NS_CC_BEGIN
|
||||
|
||||
static const int UNDERLINE_NODE_TAG = 0xaabbccdd;
|
||||
/**
|
||||
* LabelLetter used to update the quad in texture atlas without SpriteBatchNode.
|
||||
*/
|
||||
|
@ -780,9 +779,9 @@ bool Label::alignText()
|
|||
do {
|
||||
_fontAtlas->prepareLetterDefinitions(_utf16Text);
|
||||
auto& textures = _fontAtlas->getTextures();
|
||||
if (textures.size() > _batchNodes.size())
|
||||
if (textures.size() > static_cast<size_t>(_batchNodes.size()))
|
||||
{
|
||||
for (auto index = _batchNodes.size(); index < textures.size(); ++index)
|
||||
for (auto index = static_cast<size_t>(_batchNodes.size()); index < textures.size(); ++index)
|
||||
{
|
||||
auto batchNode = SpriteBatchNode::createWithTexture(textures.at(index));
|
||||
if (batchNode)
|
||||
|
@ -1129,7 +1128,7 @@ void Label::enableBold()
|
|||
if (!_boldEnabled)
|
||||
{
|
||||
// bold is implemented with outline
|
||||
enableShadow(Color4B::WHITE, Size(0.9,0), 0);
|
||||
enableShadow(Color4B::WHITE, Size(0.9f, 0), 0);
|
||||
// add one to kerning
|
||||
setAdditionalKerning(_additionalKerning+1);
|
||||
_boldEnabled = true;
|
||||
|
|
|
@ -137,7 +137,7 @@ bool Menu::initWithArray(const Vector<MenuItem*>& arrayOfItems)
|
|||
// menu in the center of the screen
|
||||
Size s = Director::getInstance()->getWinSize();
|
||||
|
||||
this->ignoreAnchorPointForPosition(true);
|
||||
this->setIgnoreAnchorPointForPosition(true);
|
||||
setAnchorPoint(Vec2(0.5f, 0.5f));
|
||||
this->setContentSize(s);
|
||||
|
||||
|
|
|
@ -102,7 +102,7 @@ bool MotionStreak::initWithFade(float fade, float minSeg, float stroke, const Co
|
|||
{
|
||||
Node::setPosition(Vec2::ZERO);
|
||||
setAnchorPoint(Vec2::ZERO);
|
||||
ignoreAnchorPointForPosition(true);
|
||||
setIgnoreAnchorPointForPosition(true);
|
||||
_startingPositionInitialized = false;
|
||||
|
||||
_positionR.setZero();
|
||||
|
|
|
@ -1,5 +1,3 @@
|
|||
|
||||
|
||||
/****************************************************************************
|
||||
Copyright (c) 2008-2010 Ricardo Quesada
|
||||
Copyright (c) 2009 Valentin Milea
|
||||
|
@ -653,8 +651,9 @@ bool Node::isIgnoreAnchorPointForPosition() const
|
|||
{
|
||||
return _ignoreAnchorPointForPosition;
|
||||
}
|
||||
|
||||
/// isRelativeAnchorPoint setter
|
||||
void Node::ignoreAnchorPointForPosition(bool newValue)
|
||||
void Node::setIgnoreAnchorPointForPosition(bool newValue)
|
||||
{
|
||||
if (newValue != _ignoreAnchorPointForPosition)
|
||||
{
|
||||
|
|
|
@ -705,13 +705,14 @@ public:
|
|||
* The default value is false, while in Layer and Scene are true.
|
||||
*
|
||||
* @param ignore true if anchor point will be (0,0) when you position this node.
|
||||
* @todo This method should be renamed as setIgnoreAnchorPointForPosition(bool) or something with "set".
|
||||
*/
|
||||
virtual void ignoreAnchorPointForPosition(bool ignore);
|
||||
virtual void setIgnoreAnchorPointForPosition(bool ignore);
|
||||
CC_DEPRECATED_ATTRIBUTE virtual void ignoreAnchorPointForPosition(bool ignore) { setIgnoreAnchorPointForPosition(ignore); }
|
||||
|
||||
/**
|
||||
* Gets whether the anchor point will be (0,0) when you position this node.
|
||||
*
|
||||
* @see `ignoreAnchorPointForPosition(bool)`
|
||||
* @see `setIgnoreAnchorPointForPosition(bool)`
|
||||
*
|
||||
* @return true if the anchor point will be (0,0) when you position this node.
|
||||
*/
|
||||
|
@ -1264,7 +1265,6 @@ public:
|
|||
* Composable actions are counted as 1 action. Example:
|
||||
* If you are running 1 Sequence of 7 actions, it will return 1.
|
||||
* If you are running 7 Sequences of 2 actions, it will return 7.
|
||||
* @todo Rename to getNumberOfRunningActions()
|
||||
*
|
||||
* @return The number of actions that are running plus the ones that are schedule to run.
|
||||
*/
|
||||
|
|
|
@ -932,6 +932,12 @@ void ParticleSystem::update(float dt)
|
|||
}
|
||||
else
|
||||
{
|
||||
//Why use so many for-loop separately instead of putting them together?
|
||||
//When the processor needs to read from or write to a location in memory,
|
||||
//it first checks whether a copy of that data is in the cache.
|
||||
//And every property's memory of the particle system is continuous,
|
||||
//for the purpose of improving cache hit rate, we should process only one property in one for-loop AFAP.
|
||||
//It was proved to be effective especially for low-end machine.
|
||||
for (int i = 0; i < _particleCount; ++i)
|
||||
{
|
||||
_particleData.modeB.angle[i] += _particleData.modeB.degreesPerSecond[i] * dt;
|
||||
|
|
|
@ -924,10 +924,10 @@ void Sprite::setAnchorPoint(const Vec2& anchor)
|
|||
SET_DIRTY_RECURSIVELY();
|
||||
}
|
||||
|
||||
void Sprite::ignoreAnchorPointForPosition(bool value)
|
||||
void Sprite::setIgnoreAnchorPointForPosition(bool value)
|
||||
{
|
||||
CCASSERT(! _batchNode, "ignoreAnchorPointForPosition is invalid in Sprite");
|
||||
Node::ignoreAnchorPointForPosition(value);
|
||||
CCASSERT(! _batchNode, "setIgnoreAnchorPointForPosition is invalid in Sprite");
|
||||
Node::setIgnoreAnchorPointForPosition(value);
|
||||
}
|
||||
|
||||
void Sprite::setVisible(bool bVisible)
|
||||
|
@ -1183,7 +1183,7 @@ std::string Sprite::getDescription() const
|
|||
return StringUtils::format("<Sprite | Tag = %d, TextureID = %d>", _tag, texture_id );
|
||||
}
|
||||
|
||||
PolygonInfo& Sprite::getPolygonInfo()
|
||||
const PolygonInfo& Sprite::getPolygonInfo() const
|
||||
{
|
||||
return _polyInfo;
|
||||
}
|
||||
|
|
|
@ -406,9 +406,9 @@ public:
|
|||
/**
|
||||
* returns a reference of the polygon information associated with this sprite
|
||||
*
|
||||
* @return a copy of PolygonInfo
|
||||
* @return a reference of PolygonInfo
|
||||
*/
|
||||
PolygonInfo& getPolygonInfo();
|
||||
const PolygonInfo& getPolygonInfo() const;
|
||||
|
||||
/**
|
||||
* set the sprite to use this new PolygonInfo
|
||||
|
@ -467,7 +467,9 @@ public:
|
|||
virtual void setScale(float scale) override;
|
||||
virtual void setPositionZ(float positionZ) override;
|
||||
virtual void setAnchorPoint(const Vec2& anchor) override;
|
||||
virtual void ignoreAnchorPointForPosition(bool value) override;
|
||||
|
||||
virtual void setIgnoreAnchorPointForPosition(bool value) override;
|
||||
|
||||
virtual void setVisible(bool bVisible) override;
|
||||
virtual void draw(Renderer *renderer, const Mat4 &transform, uint32_t flags) override;
|
||||
virtual void setOpacityModifyRGB(bool modify) override;
|
||||
|
|
|
@ -252,7 +252,7 @@ void SpriteBatchNode::removeAllChildrenWithCleanup(bool doCleanup)
|
|||
Node::removeAllChildrenWithCleanup(doCleanup);
|
||||
|
||||
_descendants.clear();
|
||||
_textureAtlas->removeAllQuads();
|
||||
if (_textureAtlas) {_textureAtlas->removeAllQuads();}
|
||||
}
|
||||
|
||||
//override sortAllChildren
|
||||
|
|
|
@ -137,6 +137,7 @@ SpriteFrame* SpriteFrame::clone() const
|
|||
SpriteFrame *copy = new (std::nothrow) SpriteFrame();
|
||||
copy->initWithTextureFilename(_textureFilename, _rectInPixels, _rotated, _offsetInPixels, _originalSizeInPixels);
|
||||
copy->setTexture(_texture);
|
||||
copy->setPolygonInfo(_polygonInfo);
|
||||
copy->autorelease();
|
||||
return copy;
|
||||
}
|
||||
|
@ -187,7 +188,7 @@ void SpriteFrame::setAnchorPoint(const Vec2& anchorPoint)
|
|||
|
||||
bool SpriteFrame::hasAnchorPoint() const
|
||||
{
|
||||
return !isnan(_anchorPoint.x);
|
||||
return !std::isnan(_anchorPoint.x);
|
||||
}
|
||||
|
||||
void SpriteFrame::setTexture(Texture2D * texture)
|
||||
|
@ -217,7 +218,7 @@ void SpriteFrame::setPolygonInfo(const PolygonInfo &polygonInfo)
|
|||
_polygonInfo = polygonInfo;
|
||||
}
|
||||
|
||||
const PolygonInfo &SpriteFrame::getPolygonInfo() const
|
||||
const PolygonInfo& SpriteFrame::getPolygonInfo() const
|
||||
{
|
||||
return _polygonInfo;
|
||||
}
|
||||
|
|
|
@ -215,9 +215,9 @@ public:
|
|||
|
||||
/** Get the polygonInfo for this sprite
|
||||
*
|
||||
* @return polygonInfo structure
|
||||
* @return a reference to the polygonInfo structure
|
||||
*/
|
||||
const PolygonInfo &getPolygonInfo() const;
|
||||
const PolygonInfo& getPolygonInfo() const;
|
||||
|
||||
/** Check if sprite frame is a polygon sprite
|
||||
*
|
||||
|
|
|
@ -130,9 +130,9 @@ void SpriteFrameCache::initializePolygonInfo(const Size &textureSize,
|
|||
indexData[i] = static_cast<unsigned short>(triangleIndices[i]);
|
||||
}
|
||||
|
||||
info.triangles.vertCount = vertexCount;
|
||||
info.triangles.vertCount = static_cast<int>(vertexCount);
|
||||
info.triangles.verts = vertexData;
|
||||
info.triangles.indexCount = indexCount;
|
||||
info.triangles.indexCount = static_cast<int>(indexCount);
|
||||
info.triangles.indices = indexData;
|
||||
info.rect = Rect(0, 0, spriteSize.width, spriteSize.height);
|
||||
}
|
||||
|
@ -322,7 +322,7 @@ void SpriteFrameCache::addSpriteFramesWithDictionary(ValueMap& dict, const std::
|
|||
{"I8", Texture2D::PixelFormat::I8},
|
||||
{"AI88", Texture2D::PixelFormat::AI88},
|
||||
{"ALPHA_INTENSITY", Texture2D::PixelFormat::AI88},
|
||||
//{"BGRA8888", Texture2D::PixelFormat::BGRA8888}, no Image convertion RGBA -> BGRA
|
||||
//{"BGRA8888", Texture2D::PixelFormat::BGRA8888}, no Image conversion RGBA -> BGRA
|
||||
{"RGB888", Texture2D::PixelFormat::RGB888}
|
||||
};
|
||||
|
||||
|
|
|
@ -224,7 +224,7 @@ void TMXLayer::parseInternalProperties()
|
|||
}
|
||||
}
|
||||
|
||||
void TMXLayer::setupTileSprite(Sprite* sprite, Vec2 pos, int gid)
|
||||
void TMXLayer::setupTileSprite(Sprite* sprite, const Vec2& pos, int gid)
|
||||
{
|
||||
sprite->setPosition(getPositionAt(pos));
|
||||
sprite->setPositionZ((float)getVertexZForPos(pos));
|
||||
|
@ -281,7 +281,7 @@ void TMXLayer::setupTileSprite(Sprite* sprite, Vec2 pos, int gid)
|
|||
}
|
||||
}
|
||||
|
||||
Sprite* TMXLayer::reusedTileWithRect(Rect rect)
|
||||
Sprite* TMXLayer::reusedTileWithRect(const Rect& rect)
|
||||
{
|
||||
if (! _reusedTile)
|
||||
{
|
||||
|
|
|
@ -307,8 +307,8 @@ protected:
|
|||
|
||||
/* The layer recognizes some special properties, like cc_vertexz */
|
||||
void parseInternalProperties();
|
||||
void setupTileSprite(Sprite* sprite, Vec2 pos, int gid);
|
||||
Sprite* reusedTileWithRect(Rect rect);
|
||||
void setupTileSprite(Sprite* sprite, const Vec2& pos, int gid);
|
||||
Sprite* reusedTileWithRect(const Rect& rect);
|
||||
int getVertexZForPos(const Vec2& pos);
|
||||
|
||||
// index
|
||||
|
|
|
@ -439,7 +439,13 @@ void TMXMapInfo::startElement(void *ctx, const char *name, const char **atts)
|
|||
}
|
||||
CCASSERT( compression == "" || compression == "gzip" || compression == "zlib", "TMX: unsupported compression method" );
|
||||
}
|
||||
}
|
||||
else if (encoding == "csv")
|
||||
{
|
||||
int layerAttribs = tmxMapInfo->getLayerAttribs();
|
||||
tmxMapInfo->setLayerAttribs(layerAttribs | TMXLayerAttribCSV);
|
||||
tmxMapInfo->setStoringCharacters(true);
|
||||
}
|
||||
}
|
||||
else if (elementName == "object")
|
||||
{
|
||||
TMXObjectGroup* objectGroup = tmxMapInfo->getObjectGroups().back();
|
||||
|
@ -448,7 +454,7 @@ void TMXMapInfo::startElement(void *ctx, const char *name, const char **atts)
|
|||
// Create an instance of TMXObjectInfo to store the object and its properties
|
||||
ValueMap dict;
|
||||
// Parse everything automatically
|
||||
const char* keys[] = {"name", "type", "width", "height", "gid"};
|
||||
const char* keys[] = {"name", "type", "width", "height", "gid", "id"};
|
||||
|
||||
for (const auto& key : keys)
|
||||
{
|
||||
|
@ -671,6 +677,45 @@ void TMXMapInfo::endElement(void *ctx, const char *name)
|
|||
|
||||
tmxMapInfo->setCurrentString("");
|
||||
}
|
||||
else if (tmxMapInfo->getLayerAttribs() & TMXLayerAttribCSV)
|
||||
{
|
||||
unsigned char *buffer;
|
||||
|
||||
TMXLayerInfo* layer = tmxMapInfo->getLayers().back();
|
||||
|
||||
tmxMapInfo->setStoringCharacters(false);
|
||||
std::string currentString = tmxMapInfo->getCurrentString();
|
||||
|
||||
vector<string> gidTokens;
|
||||
istringstream filestr(currentString);
|
||||
string sRow;
|
||||
while(getline(filestr, sRow, '\n')) {
|
||||
string sGID;
|
||||
istringstream rowstr(sRow);
|
||||
while (getline(rowstr, sGID, ',')) {
|
||||
gidTokens.push_back(sGID);
|
||||
}
|
||||
}
|
||||
|
||||
// 32-bits per gid
|
||||
buffer = (unsigned char*)malloc(gidTokens.size() * 4);
|
||||
if (!buffer)
|
||||
{
|
||||
CCLOG("cocos2d: TiledMap: CSV buffer not allocated.");
|
||||
return;
|
||||
}
|
||||
|
||||
uint32_t* bufferPtr = reinterpret_cast<uint32_t*>(buffer);
|
||||
for(auto gidToken : gidTokens) {
|
||||
auto tileGid = (uint32_t)strtol(gidToken.c_str(), nullptr, 10);
|
||||
*bufferPtr = tileGid;
|
||||
bufferPtr++;
|
||||
}
|
||||
|
||||
layer->_tiles = reinterpret_cast<uint32_t*>(buffer);
|
||||
|
||||
tmxMapInfo->setCurrentString("");
|
||||
}
|
||||
else if (tmxMapInfo->getLayerAttribs() & TMXLayerAttribNone)
|
||||
{
|
||||
_xmlTileIndex = 0;
|
||||
|
|
|
@ -62,6 +62,7 @@ enum {
|
|||
TMXLayerAttribBase64 = 1 << 1,
|
||||
TMXLayerAttribGzip = 1 << 2,
|
||||
TMXLayerAttribZlib = 1 << 3,
|
||||
TMXLayerAttribCSV = 1 << 4,
|
||||
};
|
||||
|
||||
enum {
|
||||
|
|
|
@ -34,7 +34,7 @@ NS_CC_BEGIN
|
|||
|
||||
#define CURSOR_TIME_SHOW_HIDE 0.5f
|
||||
#define CURSOR_DEFAULT_CHAR '|'
|
||||
|
||||
#define PASSWORD_STYLE_TEXT_DEFAULT "\xe2\x80\xa2"
|
||||
static int _calcCharCount(const char * text)
|
||||
{
|
||||
int n = 0;
|
||||
|
@ -63,7 +63,7 @@ TextFieldTTF::TextFieldTTF()
|
|||
, _placeHolder("") // prevent Label initWithString assertion
|
||||
, _colorText(Color4B::WHITE)
|
||||
, _secureTextEntry(false)
|
||||
,_passwordStyleText("\u25CF")
|
||||
, _passwordStyleText(PASSWORD_STYLE_TEXT_DEFAULT)
|
||||
, _cursorEnabled(false)
|
||||
, _cursorPosition(0)
|
||||
, _cursorChar(CURSOR_DEFAULT_CHAR)
|
||||
|
@ -134,7 +134,7 @@ bool TextFieldTTF::initWithPlaceHolder(const std::string& placeholder, const std
|
|||
// If fontName is ttf file and it corrected, use TTFConfig
|
||||
if (FileUtils::getInstance()->isFileExist(fontName))
|
||||
{
|
||||
TTFConfig ttfConfig(fontName.c_str(), fontSize, GlyphCollection::DYNAMIC);
|
||||
TTFConfig ttfConfig(fontName, fontSize, GlyphCollection::DYNAMIC);
|
||||
if (setTTFConfig(ttfConfig))
|
||||
{
|
||||
break;
|
||||
|
|
|
@ -1147,6 +1147,7 @@
|
|||
<ClCompile Include="$(MSBuildThisFileDirectory)..\..\..\..\ui\UIButton.cpp" />
|
||||
<ClCompile Include="$(MSBuildThisFileDirectory)..\..\..\..\ui\UIAbstractCheckButton.cpp" />
|
||||
<ClCompile Include="$(MSBuildThisFileDirectory)..\..\..\..\ui\UICheckBox.cpp" />
|
||||
<ClCompile Include="$(MSBuildThisFileDirectory)..\..\..\..\ui\UIEditBox\UIEditBoxImpl-common.cpp" />
|
||||
<ClCompile Include="$(MSBuildThisFileDirectory)..\..\..\..\ui\UIRadioButton.cpp" />
|
||||
<ClCompile Include="$(MSBuildThisFileDirectory)..\..\..\..\ui\UIDeprecated.cpp" />
|
||||
<ClCompile Include="$(MSBuildThisFileDirectory)..\..\..\..\ui\UIEditBox\UIEditBox.cpp" />
|
||||
|
|
|
@ -3610,6 +3610,7 @@
|
|||
<ClCompile Include="$(MSBuildThisFileDirectory)..\..\..\..\editor-support\cocostudio\LocalizationManager.cpp">
|
||||
<Filter>cocostudio\components</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="$(MSBuildThisFileDirectory)..\..\..\..\ui\UIEditBox\UIEditBoxImpl-common.cpp" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Filter Include="2d">
|
||||
|
|
|
@ -642,6 +642,7 @@
|
|||
<ClCompile Include="..\..\ui\UIButton.cpp" />
|
||||
<ClCompile Include="..\..\ui\UIAbstractCheckButton.cpp" />
|
||||
<ClCompile Include="..\..\ui\UICheckBox.cpp" />
|
||||
<ClCompile Include="..\..\ui\UIEditBox\UIEditBoxImpl-common.cpp" />
|
||||
<ClCompile Include="..\..\ui\UIRadioButton.cpp" />
|
||||
<ClCompile Include="..\..\ui\UIDeprecated.cpp" />
|
||||
<ClCompile Include="..\..\ui\UIEditBox\UIEditBox.cpp" />
|
||||
|
@ -1248,6 +1249,7 @@
|
|||
<ClInclude Include="..\..\renderer\CCBatchCommand.h" />
|
||||
<ClInclude Include="..\..\renderer\CCCustomCommand.h" />
|
||||
<ClInclude Include="..\..\renderer\CCTextureCube.h" />
|
||||
<ClInclude Include="..\..\ui\UIEditBox\UIEditBoxImpl-common.h" />
|
||||
<ClInclude Include="..\..\ui\UITabControl.h" />
|
||||
<ClInclude Include="..\CCAutoPolygon.h" />
|
||||
<ClInclude Include="..\CCCameraBackgroundBrush.h" />
|
||||
|
@ -1682,4 +1684,4 @@
|
|||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
|
||||
<ImportGroup Label="ExtensionTargets">
|
||||
</ImportGroup>
|
||||
</Project>
|
||||
</Project>
|
|
@ -1990,6 +1990,9 @@
|
|||
<ClCompile Include="..\..\ui\UITabControl.cpp">
|
||||
<Filter>ui\UIWidgets</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\..\ui\UIEditBox\UIEditBoxImpl-common.cpp">
|
||||
<Filter>ui\UIWidgets\EditBox</Filter>
|
||||
</ClCompile>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClInclude Include="..\..\cocos2d.h" />
|
||||
|
@ -3887,6 +3890,9 @@
|
|||
<ClInclude Include="..\..\ui\UITabControl.h">
|
||||
<Filter>ui\UIWidgets</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\..\ui\UIEditBox\UIEditBoxImpl-common.h">
|
||||
<Filter>ui\UIWidgets\EditBox</Filter>
|
||||
</ClInclude>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<None Include="..\..\base\CCController-iOS.mm">
|
||||
|
|
|
@ -248,7 +248,7 @@ void Animate3D::startWithTarget(Node *target)
|
|||
action->_accTransTime = 0.0f;
|
||||
action->_weight = 1.0f;
|
||||
action->_lastTime = 0.f;
|
||||
|
||||
s_runningAnimates.erase(target);
|
||||
s_fadeInAnimates[target] = this;
|
||||
_accTransTime = 0.0f;
|
||||
_state = Animate3D::Animate3DState::FadeIn;
|
||||
|
|
|
@ -232,7 +232,7 @@ void Animation3DCache::removeUnusedAnimation()
|
|||
if (itor->second->getReferenceCount() == 1)
|
||||
{
|
||||
itor->second->release();
|
||||
_animations.erase(itor++);
|
||||
itor = _animations.erase(itor);
|
||||
}
|
||||
else
|
||||
++itor;
|
||||
|
|
|
@ -104,7 +104,7 @@ bool MotionStreak3D::initWithFade(float fade, float minSeg, float stroke, const
|
|||
{
|
||||
Node::setPosition(Vec2::ZERO);
|
||||
setAnchorPoint(Vec2::ZERO);
|
||||
ignoreAnchorPointForPosition(true);
|
||||
setIgnoreAnchorPointForPosition(true);
|
||||
_startingPositionInitialized = false;
|
||||
|
||||
_positionR.setZero();
|
||||
|
|
|
@ -464,7 +464,7 @@ void Sprite3D::setMaterial(Material *material, int meshIndex)
|
|||
|
||||
if (meshIndex == -1)
|
||||
{
|
||||
for (size_t i = 0; i < _meshes.size(); i++)
|
||||
for (ssize_t i = 0; i < _meshes.size(); i++)
|
||||
{
|
||||
_meshes.at(i)->setMaterial(i == 0 ? material : material->clone());
|
||||
}
|
||||
|
@ -589,6 +589,7 @@ void Sprite3D::createNode(NodeData* nodedata, Node* root, const MaterialDatas& m
|
|||
setScaleY(scale.y);
|
||||
setScaleZ(scale.z);
|
||||
|
||||
node = this;
|
||||
}
|
||||
}
|
||||
else
|
||||
|
@ -774,7 +775,7 @@ void Sprite3D::draw(Renderer *renderer, const Mat4 &transform, uint32_t flags)
|
|||
const auto lights = scene->getLights();
|
||||
bool usingLight = false;
|
||||
for (const auto light : lights) {
|
||||
usingLight = (light->isEnabled() && (unsigned int)light->getLightFlag() & _lightMask) > 0;
|
||||
usingLight = light->isEnabled() && ((static_cast<unsigned int>(light->getLightFlag()) & _lightMask) > 0);
|
||||
if (usingLight)
|
||||
break;
|
||||
}
|
||||
|
@ -974,8 +975,8 @@ void Sprite3DCache::removeSprite3DData(const std::string& key)
|
|||
if (it != _spriteDatas.end())
|
||||
{
|
||||
delete it->second;
|
||||
_spriteDatas.erase(it);
|
||||
}
|
||||
_spriteDatas.erase(it);
|
||||
}
|
||||
|
||||
void Sprite3DCache::removeAllSprite3DData()
|
||||
|
|
|
@ -323,7 +323,7 @@ void Sprite3DMaterialCache::removeUnusedSprite3DMaterial()
|
|||
CCLOG("cocos2d: GLProgramStateCache: removing unused GLProgramState");
|
||||
|
||||
value->release();
|
||||
_materials.erase(it++);
|
||||
it = _materials.erase(it);
|
||||
} else {
|
||||
++it;
|
||||
}
|
||||
|
|
|
@ -294,7 +294,7 @@ Terrain::Terrain()
|
|||
#endif
|
||||
}
|
||||
|
||||
void Terrain::setChunksLOD(Vec3 cameraPos)
|
||||
void Terrain::setChunksLOD(const Vec3& cameraPos)
|
||||
{
|
||||
int chunk_amount_y = _imageHeight/_chunkSize.height;
|
||||
int chunk_amount_x = _imageWidth/_chunkSize.width;
|
||||
|
@ -369,9 +369,9 @@ float Terrain::getHeight(float x, float z, Vec3 * normal) const
|
|||
}
|
||||
}
|
||||
|
||||
float Terrain::getHeight(Vec2 pos, Vec3*Normal) const
|
||||
float Terrain::getHeight(const Vec2& pos, Vec3* normal) const
|
||||
{
|
||||
return getHeight(pos.x,pos.y,Normal);
|
||||
return getHeight(pos.x, pos.y, normal);
|
||||
}
|
||||
|
||||
float Terrain::getImageHeight(int pixel_x,int pixel_y) const
|
||||
|
@ -606,7 +606,7 @@ void Terrain::setMaxDetailMapAmount(int max_value)
|
|||
_maxDetailMapValue = max_value;
|
||||
}
|
||||
|
||||
cocos2d::Vec2 Terrain::convertToTerrainSpace(Vec2 worldSpaceXZ) const
|
||||
cocos2d::Vec2 Terrain::convertToTerrainSpace(const Vec2& worldSpaceXZ) const
|
||||
{
|
||||
Vec2 pos(worldSpaceXZ.x,worldSpaceXZ.y);
|
||||
|
||||
|
@ -1638,14 +1638,14 @@ Terrain::DetailMap::DetailMap()
|
|||
_detailMapSize = 35;
|
||||
}
|
||||
|
||||
Terrain::Triangle::Triangle(Vec3 p1, Vec3 p2, Vec3 p3)
|
||||
Terrain::Triangle::Triangle(const Vec3& p1, const Vec3& p2, const Vec3& p3)
|
||||
{
|
||||
_p1 = p1;
|
||||
_p2 = p2;
|
||||
_p3 = p3;
|
||||
}
|
||||
|
||||
void Terrain::Triangle::transform(cocos2d::Mat4 matrix)
|
||||
void Terrain::Triangle::transform(const cocos2d::Mat4& matrix)
|
||||
{
|
||||
matrix.transformPoint(&_p1);
|
||||
matrix.transformPoint(&_p2);
|
||||
|
|
|
@ -114,9 +114,9 @@ public:
|
|||
*/
|
||||
struct Triangle
|
||||
{
|
||||
Triangle(Vec3 p1, Vec3 p2, Vec3 p3);
|
||||
Triangle(const Vec3& p1, const Vec3& p2, const Vec3& p3);
|
||||
bool getInsterctPoint(const Ray &ray, Vec3& interScetPoint) const;
|
||||
void transform(Mat4 matrix);
|
||||
void transform(const Mat4& matrix);
|
||||
Vec3 _p1, _p2, _p3;
|
||||
};
|
||||
|
||||
|
@ -181,7 +181,7 @@ private:
|
|||
{
|
||||
/*constructor*/
|
||||
TerrainVertexData(){};
|
||||
TerrainVertexData(Vec3 v1, Tex2F v2)
|
||||
TerrainVertexData(const Vec3& v1, const Tex2F& v2)
|
||||
{
|
||||
_position = v1;
|
||||
_texcoord = v2;
|
||||
|
@ -334,7 +334,7 @@ public:
|
|||
* @param normal the specified position's normal vector in terrain . if this argument is NULL or nullptr,Normal calculation shall be skip.
|
||||
* @return the height value of the specified position of the terrain, if the (X,Z) position is out of the terrain bounds,it shall return 0;
|
||||
**/
|
||||
float getHeight(Vec2 pos, Vec3*Normal = nullptr) const;
|
||||
float getHeight(const Vec2& pos, Vec3* normal = nullptr) const;
|
||||
|
||||
/**get the normal of the specified position in terrain
|
||||
* @return the normal vector of the specified position of the terrain.
|
||||
|
@ -387,7 +387,7 @@ public:
|
|||
/**
|
||||
* Convert a world Space position (X,Z) to terrain space position (X,Z)
|
||||
*/
|
||||
Vec2 convertToTerrainSpace(Vec2 worldSpace) const;
|
||||
Vec2 convertToTerrainSpace(const Vec2& worldSpace) const;
|
||||
|
||||
/**
|
||||
* reset the heightmap data.
|
||||
|
@ -442,7 +442,7 @@ protected:
|
|||
* recursively set each chunk's LOD
|
||||
* @param cameraPos the camera position in world space
|
||||
**/
|
||||
void setChunksLOD(Vec3 cameraPos);
|
||||
void setChunksLOD(const Vec3& cameraPos);
|
||||
|
||||
/**
|
||||
* load Vertices from height filed for the whole terrain.
|
||||
|
|
|
@ -277,9 +277,9 @@ LOCAL_WHOLE_STATIC_LIBRARIES := cocos2dxandroid_static
|
|||
# define the macro to compile through support/zip_support/ioapi.c
|
||||
LOCAL_CFLAGS := -DUSE_FILE32API
|
||||
LOCAL_CFLAGS += -fexceptions
|
||||
LOCAL_CPPFLAGS := -Wno-deprecated-declarations -Wno-extern-c-compat
|
||||
LOCAL_CPPFLAGS := -Wno-deprecated-declarations
|
||||
LOCAL_EXPORT_CFLAGS := -DUSE_FILE32API
|
||||
LOCAL_EXPORT_CPPFLAGS := -Wno-deprecated-declarations -Wno-extern-c-compat
|
||||
LOCAL_EXPORT_CPPFLAGS := -Wno-deprecated-declarations
|
||||
|
||||
include $(BUILD_STATIC_LIBRARY)
|
||||
|
||||
|
|
|
@ -38,6 +38,7 @@
|
|||
#include "base/CCDirector.h"
|
||||
#include "base/CCScheduler.h"
|
||||
#include "platform/android/CCFileUtils-android.h"
|
||||
#include "platform/android/jni/Java_org_cocos2dx_lib_Cocos2dxHelper.h"
|
||||
|
||||
using namespace cocos2d;
|
||||
using namespace cocos2d::experimental;
|
||||
|
@ -104,27 +105,31 @@ bool AudioPlayer::init(SLEngineItf engineEngine, SLObjectItf outputMixObject,con
|
|||
SLDataFormat_MIME format_mime = {SL_DATAFORMAT_MIME, NULL, SL_CONTAINERTYPE_UNSPECIFIED};
|
||||
audioSrc.pFormat = &format_mime;
|
||||
|
||||
if (fileFullPath[0] != '/'){
|
||||
std::string relativePath = "";
|
||||
|
||||
if (fileFullPath[0] != '/') {
|
||||
off_t start, length;
|
||||
std::string relativePath;
|
||||
size_t position = fileFullPath.find("assets/");
|
||||
|
||||
if (0 == position) {
|
||||
// "assets/" is at the beginning of the path and we don't want it
|
||||
relativePath += fileFullPath.substr(strlen("assets/"));
|
||||
relativePath = fileFullPath.substr(strlen("assets/"));
|
||||
} else {
|
||||
relativePath += fileFullPath;
|
||||
relativePath = fileFullPath;
|
||||
}
|
||||
|
||||
auto asset = AAssetManager_open(cocos2d::FileUtilsAndroid::getAssetManager(), relativePath.c_str(), AASSET_MODE_UNKNOWN);
|
||||
|
||||
// open asset as file descriptor
|
||||
off_t start, length;
|
||||
_assetFd = AAsset_openFileDescriptor(asset, &start, &length);
|
||||
if (_assetFd <= 0){
|
||||
if (cocos2d::FileUtilsAndroid::getObbFile() != nullptr) {
|
||||
_assetFd = getObbAssetFileDescriptorJNI(relativePath.c_str(), &start, &length);
|
||||
} else {
|
||||
auto asset = AAssetManager_open(cocos2d::FileUtilsAndroid::getAssetManager(), relativePath.c_str(), AASSET_MODE_UNKNOWN);
|
||||
// open asset as file descriptor
|
||||
_assetFd = AAsset_openFileDescriptor(asset, &start, &length);
|
||||
AAsset_close(asset);
|
||||
}
|
||||
|
||||
if (_assetFd <= 0) {
|
||||
CCLOGERROR("Failed to open file descriptor for '%s'", fileFullPath.c_str());
|
||||
break;
|
||||
}
|
||||
AAsset_close(asset);
|
||||
|
||||
// configure audio source
|
||||
loc_fd = {SL_DATALOCATOR_ANDROIDFD, _assetFd, start, length};
|
||||
|
|
|
@ -75,12 +75,12 @@ AndroidJavaEngine::~AndroidJavaEngine()
|
|||
|
||||
void AndroidJavaEngine::preloadBackgroundMusic(const char* filePath) {
|
||||
std::string fullPath = CocosDenshion::android::getFullPathWithoutAssetsPrefix(filePath);
|
||||
JniHelper::callStaticVoidMethod(helperClassName, "preloadBackgroundMusic", filePath);
|
||||
JniHelper::callStaticVoidMethod(helperClassName, "preloadBackgroundMusic", fullPath);
|
||||
}
|
||||
|
||||
void AndroidJavaEngine::playBackgroundMusic(const char* filePath, bool loop) {
|
||||
std::string fullPath = CocosDenshion::android::getFullPathWithoutAssetsPrefix(filePath);
|
||||
JniHelper::callStaticVoidMethod(helperClassName, "playBackgroundMusic", filePath, loop);
|
||||
JniHelper::callStaticVoidMethod(helperClassName, "playBackgroundMusic", fullPath, loop);
|
||||
}
|
||||
|
||||
void AndroidJavaEngine::stopBackgroundMusic(bool releaseData) {
|
||||
|
|
|
@ -24,7 +24,8 @@ THE SOFTWARE.
|
|||
|
||||
#include "audio/include/SimpleAudioEngine.h"
|
||||
#include "audio/ios/SimpleAudioEngine_objc.h"
|
||||
#include "cocos2d.h"
|
||||
#include "platform/CCFileUtils.h"
|
||||
|
||||
USING_NS_CC;
|
||||
|
||||
static void static_end()
|
||||
|
|
|
@ -1,21 +1,28 @@
|
|||
/**
|
||||
* @author cesarpachon
|
||||
*/
|
||||
*/
|
||||
#include <cstring>
|
||||
#include <cstdint>
|
||||
#include "audio/linux/AudioEngine-linux.h"
|
||||
#include "cocos2d.h"
|
||||
|
||||
#include "base/CCDirector.h"
|
||||
#include "base/CCScheduler.h"
|
||||
#include "platform/CCFileUtils.h"
|
||||
|
||||
using namespace cocos2d;
|
||||
using namespace cocos2d::experimental;
|
||||
|
||||
AudioEngineImpl * g_AudioEngineImpl = nullptr;
|
||||
|
||||
void ERRCHECKWITHEXIT(FMOD_RESULT result) {
|
||||
void ERRCHECKWITHEXIT(FMOD_RESULT result)
|
||||
{
|
||||
if (result != FMOD_OK) {
|
||||
printf("FMOD error! (%d) %s\n", result, FMOD_ErrorString(result));
|
||||
}
|
||||
}
|
||||
|
||||
bool ERRCHECK(FMOD_RESULT result) {
|
||||
bool ERRCHECK(FMOD_RESULT result)
|
||||
{
|
||||
if (result != FMOD_OK) {
|
||||
printf("FMOD error! (%d) %s\n", result, FMOD_ErrorString(result));
|
||||
return true;
|
||||
|
@ -23,280 +30,298 @@ bool ERRCHECK(FMOD_RESULT result) {
|
|||
return false;
|
||||
}
|
||||
|
||||
FMOD_RESULT F_CALLBACK channelCallback(FMOD_CHANNELCONTROL *channelcontrol,
|
||||
FMOD_CHANNELCONTROL_TYPE controltype,
|
||||
FMOD_CHANNELCONTROL_CALLBACK_TYPE callbacktype,
|
||||
FMOD_RESULT F_CALLBACK channelCallback(FMOD_CHANNELCONTROL *channelcontrol,
|
||||
FMOD_CHANNELCONTROL_TYPE controltype,
|
||||
FMOD_CHANNELCONTROL_CALLBACK_TYPE callbacktype,
|
||||
void *commandData1, void *commandData2)
|
||||
{
|
||||
|
||||
if(controltype == FMOD_CHANNELCONTROL_CHANNEL && callbacktype == FMOD_CHANNELCONTROL_CALLBACK_END){
|
||||
if (controltype == FMOD_CHANNELCONTROL_CHANNEL && callbacktype == FMOD_CHANNELCONTROL_CALLBACK_END) {
|
||||
g_AudioEngineImpl->onSoundFinished((FMOD::Channel *)channelcontrol);
|
||||
}else{
|
||||
}
|
||||
return FMOD_OK;
|
||||
}
|
||||
|
||||
|
||||
AudioEngineImpl::AudioEngineImpl(){
|
||||
};
|
||||
|
||||
AudioEngineImpl::~AudioEngineImpl(){
|
||||
FMOD_RESULT result;
|
||||
result = pSystem->close();
|
||||
ERRCHECKWITHEXIT(result);
|
||||
result = pSystem->release();
|
||||
ERRCHECKWITHEXIT(result);
|
||||
};
|
||||
|
||||
|
||||
bool AudioEngineImpl::init(){
|
||||
FMOD_RESULT result;
|
||||
/*
|
||||
Create a System object and initialize.
|
||||
*/
|
||||
result = FMOD::System_Create(&pSystem);
|
||||
ERRCHECKWITHEXIT(result);
|
||||
|
||||
result = pSystem->setOutput(FMOD_OUTPUTTYPE_PULSEAUDIO);
|
||||
ERRCHECKWITHEXIT(result);
|
||||
|
||||
result = pSystem->init(32, FMOD_INIT_NORMAL, 0);
|
||||
ERRCHECKWITHEXIT(result);
|
||||
|
||||
mapChannelInfo.clear();
|
||||
mapSound.clear();
|
||||
|
||||
auto scheduler = cocos2d::Director::getInstance()->getScheduler();
|
||||
scheduler->schedule(schedule_selector(AudioEngineImpl::update), this, 0.05f, false);
|
||||
|
||||
g_AudioEngineImpl = this;
|
||||
|
||||
return true;
|
||||
};
|
||||
|
||||
int AudioEngineImpl::play2d(const std::string &fileFullPath ,bool loop ,float volume){
|
||||
int id = preload(fileFullPath, nullptr);
|
||||
if(id >= 0){
|
||||
mapChannelInfo[id].loop=loop;
|
||||
mapChannelInfo[id].channel->setPaused(true);
|
||||
mapChannelInfo[id].volume = volume;
|
||||
AudioEngine::_audioIDInfoMap[id].state = AudioEngine::AudioState::PAUSED;
|
||||
resume(id);
|
||||
}
|
||||
return id;
|
||||
};
|
||||
|
||||
void AudioEngineImpl::setVolume(int audioID,float volume){
|
||||
try{
|
||||
mapChannelInfo[audioID].channel->setVolume(volume);
|
||||
}catch(const std::out_of_range& oor){
|
||||
printf("AudioEngineImpl::setVolume: invalid audioID: %d\n", audioID);
|
||||
}
|
||||
};
|
||||
|
||||
void AudioEngineImpl::setLoop(int audioID, bool loop){
|
||||
try{
|
||||
mapChannelInfo[audioID].channel->setLoopCount(loop?-1:0);
|
||||
}catch(const std::out_of_range& oor){
|
||||
printf("AudioEngineImpl::setLoop: invalid audioID: %d\n", audioID);
|
||||
}
|
||||
};
|
||||
|
||||
bool AudioEngineImpl::pause(int audioID){
|
||||
try{
|
||||
mapChannelInfo[audioID].channel->setPaused(true);
|
||||
AudioEngine::_audioIDInfoMap[audioID].state = AudioEngine::AudioState::PAUSED;
|
||||
return true;
|
||||
}catch(const std::out_of_range& oor){
|
||||
printf("AudioEngineImpl::pause: invalid audioID: %d\n", audioID);
|
||||
return false;
|
||||
}
|
||||
};
|
||||
|
||||
bool AudioEngineImpl::resume(int audioID){
|
||||
try{
|
||||
|
||||
if(!mapChannelInfo[audioID].channel){
|
||||
FMOD::Channel *channel = nullptr;
|
||||
FMOD::ChannelGroup *channelgroup = nullptr;
|
||||
//starts the sound in pause mode, use the channel to unpause
|
||||
FMOD_RESULT result = pSystem->playSound(mapChannelInfo[audioID].sound, channelgroup, true, &channel);
|
||||
if(ERRCHECK(result)){
|
||||
return false;
|
||||
}
|
||||
channel->setMode(mapChannelInfo[audioID].loop?FMOD_LOOP_NORMAL:FMOD_LOOP_OFF);
|
||||
channel->setLoopCount(mapChannelInfo[audioID].loop?-1:0);
|
||||
channel->setVolume(mapChannelInfo[audioID].volume);
|
||||
channel->setUserData((void *)mapChannelInfo[audioID].id);
|
||||
mapChannelInfo[audioID].channel = channel;
|
||||
}
|
||||
|
||||
mapChannelInfo[audioID].channel->setPaused(false);
|
||||
AudioEngine::_audioIDInfoMap[audioID].state = AudioEngine::AudioState::PLAYING;
|
||||
|
||||
return true;
|
||||
}catch(const std::out_of_range& oor){
|
||||
printf("AudioEngineImpl::resume: invalid audioID: %d\n", audioID);
|
||||
return false;
|
||||
}
|
||||
};
|
||||
|
||||
bool AudioEngineImpl::stop(int audioID){
|
||||
try{
|
||||
mapChannelInfo[audioID].channel->stop();
|
||||
mapChannelInfo[audioID].channel = nullptr;
|
||||
return true;
|
||||
}catch(const std::out_of_range& oor){
|
||||
printf("AudioEngineImpl::stop: invalid audioID: %d\n", audioID);
|
||||
return false;
|
||||
}
|
||||
};
|
||||
|
||||
void AudioEngineImpl::stopAll(){
|
||||
for (auto it = mapChannelInfo.begin(); it != mapChannelInfo.end(); ++it) {
|
||||
ChannelInfo & audioRef = it->second;
|
||||
audioRef.channel->stop();
|
||||
audioRef.channel = nullptr;
|
||||
}
|
||||
};
|
||||
|
||||
float AudioEngineImpl::getDuration(int audioID){
|
||||
try{
|
||||
FMOD::Sound * sound = mapChannelInfo[audioID].sound;
|
||||
unsigned int length;
|
||||
FMOD_RESULT result = sound->getLength(&length, FMOD_TIMEUNIT_MS);
|
||||
ERRCHECK(result);
|
||||
float duration = (float)length / 1000.0f;
|
||||
return duration;
|
||||
}catch(const std::out_of_range& oor){
|
||||
printf("AudioEngineImpl::getDuration: invalid audioID: %d\n", audioID);
|
||||
return AudioEngine::TIME_UNKNOWN;
|
||||
}
|
||||
};
|
||||
|
||||
float AudioEngineImpl::getCurrentTime(int audioID){
|
||||
try{
|
||||
unsigned int position;
|
||||
FMOD_RESULT result = mapChannelInfo[audioID].channel->getPosition(&position, FMOD_TIMEUNIT_MS);
|
||||
ERRCHECK(result);
|
||||
float currenttime = position /1000.0f;
|
||||
return currenttime;
|
||||
}catch(const std::out_of_range& oor){
|
||||
printf("AudioEngineImpl::getCurrentTime: invalid audioID: %d\n", audioID);
|
||||
return AudioEngine::TIME_UNKNOWN;
|
||||
}
|
||||
};
|
||||
|
||||
bool AudioEngineImpl::setCurrentTime(int audioID, float time){
|
||||
try{
|
||||
unsigned int position = (unsigned int)(time * 1000.0f);
|
||||
FMOD_RESULT result = mapChannelInfo[audioID].channel->setPosition(position, FMOD_TIMEUNIT_MS);
|
||||
ERRCHECK(result);
|
||||
}catch(const std::out_of_range& oor){
|
||||
printf("AudioEngineImpl::setCurrentTime: invalid audioID: %d\n", audioID);
|
||||
}
|
||||
};
|
||||
|
||||
void AudioEngineImpl::setFinishCallback(int audioID, const std::function<void (int, const std::string &)> &callback){
|
||||
try{
|
||||
FMOD::Channel * channel = mapChannelInfo[audioID].channel;
|
||||
mapChannelInfo[audioID].callback = callback;
|
||||
FMOD_RESULT result = channel->setCallback(channelCallback);
|
||||
ERRCHECK(result);
|
||||
}catch(const std::out_of_range& oor){
|
||||
printf("AudioEngineImpl::setFinishCallback: invalid audioID: %d\n", audioID);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
void AudioEngineImpl::onSoundFinished(FMOD::Channel * channel){
|
||||
size_t id;
|
||||
try{
|
||||
void * data;
|
||||
channel->getUserData(&data);
|
||||
id = (size_t) data;
|
||||
if(mapChannelInfo[id].callback){
|
||||
mapChannelInfo[id].callback(id, mapChannelInfo[id].path);
|
||||
}
|
||||
mapChannelInfo[id].channel = nullptr;
|
||||
}catch(const std::out_of_range& oor){
|
||||
printf("AudioEngineImpl::onSoundFinished: invalid audioID: %d\n", id);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
void AudioEngineImpl::uncache(const std::string& path){
|
||||
std::string fullPath = FileUtils::getInstance()->fullPathForFilename(path);
|
||||
std::map<std::string, FMOD::Sound *>::const_iterator it = mapSound.find(fullPath);
|
||||
if(it!=mapSound.end()){
|
||||
FMOD::Sound * sound = it->second;
|
||||
if(sound){
|
||||
sound->release();
|
||||
}
|
||||
mapSound.erase(it);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
void AudioEngineImpl::uncacheAll(){
|
||||
for (auto it = mapSound.cbegin(); it != mapSound.cend(); ++it) {
|
||||
auto sound = it->second;
|
||||
if(sound){
|
||||
sound->release();
|
||||
}
|
||||
}
|
||||
mapSound.clear();
|
||||
};
|
||||
|
||||
|
||||
int AudioEngineImpl::preload(const std::string& filePath, std::function<void(bool isSuccess)> callback){
|
||||
FMOD::Sound * sound = findSound(filePath);
|
||||
if(!sound){
|
||||
std::string fullPath = FileUtils::getInstance()->fullPathForFilename(filePath);
|
||||
FMOD_RESULT result = pSystem->createSound(fullPath.c_str(), FMOD_LOOP_OFF, 0, &sound);
|
||||
if (ERRCHECK(result)){
|
||||
printf("sound effect in %s could not be preload\n", filePath.c_str());
|
||||
if(callback){
|
||||
callback(false);
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
mapSound[fullPath] = sound;
|
||||
}
|
||||
|
||||
int id = mapChannelInfo.size() + 1;
|
||||
auto& chanelInfo = mapChannelInfo[id];
|
||||
chanelInfo.sound = sound;
|
||||
chanelInfo.id = (size_t) id;
|
||||
chanelInfo.channel = nullptr;
|
||||
chanelInfo.callback = nullptr;
|
||||
chanelInfo.path = filePath;
|
||||
//we are going to use UserData to store pointer to Channel when playing
|
||||
chanelInfo.sound->setUserData((void *)id);
|
||||
|
||||
if(callback){
|
||||
callback(true);
|
||||
}
|
||||
return id;
|
||||
};
|
||||
|
||||
|
||||
void AudioEngineImpl::update(float dt){
|
||||
pSystem->update();
|
||||
};
|
||||
|
||||
|
||||
FMOD::Sound * AudioEngineImpl::findSound(const std::string &path){
|
||||
std::string fullPath = FileUtils::getInstance()->fullPathForFilename(path);
|
||||
std::map<std::string, FMOD::Sound *>::const_iterator it = mapSound.find(fullPath);
|
||||
return (it!=mapSound.end())?(it->second):nullptr;
|
||||
AudioEngineImpl::AudioEngineImpl()
|
||||
{
|
||||
}
|
||||
|
||||
AudioEngineImpl::~AudioEngineImpl()
|
||||
{
|
||||
FMOD_RESULT result;
|
||||
result = pSystem->close();
|
||||
ERRCHECKWITHEXIT(result);
|
||||
result = pSystem->release();
|
||||
ERRCHECKWITHEXIT(result);
|
||||
}
|
||||
|
||||
FMOD::Channel * AudioEngineImpl::getChannel(FMOD::Sound *sound){
|
||||
size_t id;
|
||||
void * data;
|
||||
sound->getUserData(&data);
|
||||
id = (size_t) data;
|
||||
return mapChannelInfo[id].channel;
|
||||
};
|
||||
bool AudioEngineImpl::init()
|
||||
{
|
||||
FMOD_RESULT result;
|
||||
/*
|
||||
Create a System object and initialize.
|
||||
*/
|
||||
result = FMOD::System_Create(&pSystem);
|
||||
ERRCHECKWITHEXIT(result);
|
||||
|
||||
result = pSystem->setOutput(FMOD_OUTPUTTYPE_PULSEAUDIO);
|
||||
ERRCHECKWITHEXIT(result);
|
||||
|
||||
result = pSystem->init(32, FMOD_INIT_NORMAL, 0);
|
||||
ERRCHECKWITHEXIT(result);
|
||||
|
||||
mapChannelInfo.clear();
|
||||
mapSound.clear();
|
||||
|
||||
auto scheduler = cocos2d::Director::getInstance()->getScheduler();
|
||||
scheduler->schedule(schedule_selector(AudioEngineImpl::update), this, 0.05f, false);
|
||||
|
||||
g_AudioEngineImpl = this;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
int AudioEngineImpl::play2d(const std::string &fileFullPath, bool loop, float volume)
|
||||
{
|
||||
int id = preload(fileFullPath, nullptr);
|
||||
if (id >= 0) {
|
||||
mapChannelInfo[id].loop=loop;
|
||||
mapChannelInfo[id].channel->setPaused(true);
|
||||
mapChannelInfo[id].volume = volume;
|
||||
AudioEngine::_audioIDInfoMap[id].state = AudioEngine::AudioState::PAUSED;
|
||||
resume(id);
|
||||
}
|
||||
return id;
|
||||
}
|
||||
|
||||
void AudioEngineImpl::setVolume(int audioID, float volume)
|
||||
{
|
||||
try {
|
||||
mapChannelInfo[audioID].channel->setVolume(volume);
|
||||
}
|
||||
catch (const std::out_of_range& oor) {
|
||||
printf("AudioEngineImpl::setVolume: invalid audioID: %d\n", audioID);
|
||||
}
|
||||
}
|
||||
|
||||
void AudioEngineImpl::setLoop(int audioID, bool loop)
|
||||
{
|
||||
try {
|
||||
mapChannelInfo[audioID].channel->setLoopCount(loop ? -1 : 0);
|
||||
}
|
||||
catch (const std::out_of_range& oor) {
|
||||
printf("AudioEngineImpl::setLoop: invalid audioID: %d\n", audioID);
|
||||
}
|
||||
}
|
||||
|
||||
bool AudioEngineImpl::pause(int audioID)
|
||||
{
|
||||
try {
|
||||
mapChannelInfo[audioID].channel->setPaused(true);
|
||||
AudioEngine::_audioIDInfoMap[audioID].state = AudioEngine::AudioState::PAUSED;
|
||||
return true;
|
||||
}
|
||||
catch (const std::out_of_range& oor) {
|
||||
printf("AudioEngineImpl::pause: invalid audioID: %d\n", audioID);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
bool AudioEngineImpl::resume(int audioID)
|
||||
{
|
||||
try {
|
||||
if (!mapChannelInfo[audioID].channel) {
|
||||
FMOD::Channel *channel = nullptr;
|
||||
FMOD::ChannelGroup *channelgroup = nullptr;
|
||||
//starts the sound in pause mode, use the channel to unpause
|
||||
FMOD_RESULT result = pSystem->playSound(mapChannelInfo[audioID].sound, channelgroup, true, &channel);
|
||||
if (ERRCHECK(result)) {
|
||||
return false;
|
||||
}
|
||||
channel->setMode(mapChannelInfo[audioID].loop ? FMOD_LOOP_NORMAL : FMOD_LOOP_OFF);
|
||||
channel->setLoopCount(mapChannelInfo[audioID].loop ? -1 : 0);
|
||||
channel->setVolume(mapChannelInfo[audioID].volume);
|
||||
channel->setUserData(reinterpret_cast<void *>(static_cast<std::intptr_t>(mapChannelInfo[audioID].id)));
|
||||
mapChannelInfo[audioID].channel = channel;
|
||||
}
|
||||
|
||||
mapChannelInfo[audioID].channel->setPaused(false);
|
||||
AudioEngine::_audioIDInfoMap[audioID].state = AudioEngine::AudioState::PLAYING;
|
||||
|
||||
return true;
|
||||
}
|
||||
catch (const std::out_of_range& oor) {
|
||||
printf("AudioEngineImpl::resume: invalid audioID: %d\n", audioID);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
bool AudioEngineImpl::stop(int audioID)
|
||||
{
|
||||
try {
|
||||
mapChannelInfo[audioID].channel->stop();
|
||||
mapChannelInfo[audioID].channel = nullptr;
|
||||
return true;
|
||||
}
|
||||
catch (const std::out_of_range& oor) {
|
||||
printf("AudioEngineImpl::stop: invalid audioID: %d\n", audioID);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
void AudioEngineImpl::stopAll()
|
||||
{
|
||||
for (auto it = mapChannelInfo.begin(); it != mapChannelInfo.end(); ++it) {
|
||||
ChannelInfo & audioRef = it->second;
|
||||
audioRef.channel->stop();
|
||||
audioRef.channel = nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
float AudioEngineImpl::getDuration(int audioID)
|
||||
{
|
||||
try {
|
||||
FMOD::Sound * sound = mapChannelInfo[audioID].sound;
|
||||
unsigned int length;
|
||||
FMOD_RESULT result = sound->getLength(&length, FMOD_TIMEUNIT_MS);
|
||||
ERRCHECK(result);
|
||||
float duration = (float)length / 1000.0f;
|
||||
return duration;
|
||||
}
|
||||
catch (const std::out_of_range& oor) {
|
||||
printf("AudioEngineImpl::getDuration: invalid audioID: %d\n", audioID);
|
||||
return AudioEngine::TIME_UNKNOWN;
|
||||
}
|
||||
}
|
||||
|
||||
float AudioEngineImpl::getCurrentTime(int audioID)
|
||||
{
|
||||
try {
|
||||
unsigned int position;
|
||||
FMOD_RESULT result = mapChannelInfo[audioID].channel->getPosition(&position, FMOD_TIMEUNIT_MS);
|
||||
ERRCHECK(result);
|
||||
float currenttime = position /1000.0f;
|
||||
return currenttime;
|
||||
}
|
||||
catch (const std::out_of_range& oor) {
|
||||
printf("AudioEngineImpl::getCurrentTime: invalid audioID: %d\n", audioID);
|
||||
return AudioEngine::TIME_UNKNOWN;
|
||||
}
|
||||
}
|
||||
|
||||
bool AudioEngineImpl::setCurrentTime(int audioID, float time)
|
||||
{
|
||||
try {
|
||||
unsigned int position = (unsigned int)(time * 1000.0f);
|
||||
FMOD_RESULT result = mapChannelInfo[audioID].channel->setPosition(position, FMOD_TIMEUNIT_MS);
|
||||
ERRCHECK(result);
|
||||
}
|
||||
catch (const std::out_of_range& oor) {
|
||||
printf("AudioEngineImpl::setCurrentTime: invalid audioID: %d\n", audioID);
|
||||
}
|
||||
}
|
||||
|
||||
void AudioEngineImpl::setFinishCallback(int audioID, const std::function<void (int, const std::string &)> &callback)
|
||||
{
|
||||
try {
|
||||
FMOD::Channel * channel = mapChannelInfo[audioID].channel;
|
||||
mapChannelInfo[audioID].callback = callback;
|
||||
FMOD_RESULT result = channel->setCallback(channelCallback);
|
||||
ERRCHECK(result);
|
||||
}
|
||||
catch (const std::out_of_range& oor) {
|
||||
printf("AudioEngineImpl::setFinishCallback: invalid audioID: %d\n", audioID);
|
||||
}
|
||||
}
|
||||
|
||||
void AudioEngineImpl::onSoundFinished(FMOD::Channel * channel)
|
||||
{
|
||||
int id = 0;
|
||||
try {
|
||||
void * data;
|
||||
channel->getUserData(&data);
|
||||
id = static_cast<int>(reinterpret_cast<std::intptr_t>(data));
|
||||
if (mapChannelInfo[id].callback) {
|
||||
mapChannelInfo[id].callback(id, mapChannelInfo[id].path);
|
||||
}
|
||||
mapChannelInfo[id].channel = nullptr;
|
||||
}
|
||||
catch (const std::out_of_range& oor) {
|
||||
printf("AudioEngineImpl::onSoundFinished: invalid audioID: %d\n", id);
|
||||
}
|
||||
}
|
||||
|
||||
void AudioEngineImpl::uncache(const std::string& path)
|
||||
{
|
||||
std::string fullPath = FileUtils::getInstance()->fullPathForFilename(path);
|
||||
std::map<std::string, FMOD::Sound *>::const_iterator it = mapSound.find(fullPath);
|
||||
if (it!=mapSound.end()) {
|
||||
FMOD::Sound * sound = it->second;
|
||||
if (sound) {
|
||||
sound->release();
|
||||
}
|
||||
mapSound.erase(it);
|
||||
}
|
||||
}
|
||||
|
||||
void AudioEngineImpl::uncacheAll()
|
||||
{
|
||||
for (auto it = mapSound.cbegin(); it != mapSound.cend(); ++it) {
|
||||
auto sound = it->second;
|
||||
if (sound) {
|
||||
sound->release();
|
||||
}
|
||||
}
|
||||
mapSound.clear();
|
||||
}
|
||||
|
||||
int AudioEngineImpl::preload(const std::string& filePath, std::function<void(bool isSuccess)> callback)
|
||||
{
|
||||
FMOD::Sound * sound = findSound(filePath);
|
||||
if (!sound) {
|
||||
std::string fullPath = FileUtils::getInstance()->fullPathForFilename(filePath);
|
||||
FMOD_RESULT result = pSystem->createSound(fullPath.c_str(), FMOD_LOOP_OFF, 0, &sound);
|
||||
if (ERRCHECK(result)) {
|
||||
printf("sound effect in %s could not be preload\n", filePath.c_str());
|
||||
if (callback) {
|
||||
callback(false);
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
mapSound[fullPath] = sound;
|
||||
}
|
||||
|
||||
int id = static_cast<int>(mapChannelInfo.size()) + 1;
|
||||
auto& chanelInfo = mapChannelInfo[id];
|
||||
chanelInfo.sound = sound;
|
||||
chanelInfo.id = id;
|
||||
chanelInfo.channel = nullptr;
|
||||
chanelInfo.callback = nullptr;
|
||||
chanelInfo.path = filePath;
|
||||
//we are going to use UserData to store pointer to Channel when playing
|
||||
chanelInfo.sound->setUserData(reinterpret_cast<void *>(static_cast<std::intptr_t>(id)));
|
||||
|
||||
if (callback) {
|
||||
callback(true);
|
||||
}
|
||||
return id;
|
||||
}
|
||||
|
||||
void AudioEngineImpl::update(float dt)
|
||||
{
|
||||
pSystem->update();
|
||||
}
|
||||
|
||||
FMOD::Sound * AudioEngineImpl::findSound(const std::string &path)
|
||||
{
|
||||
std::string fullPath = FileUtils::getInstance()->fullPathForFilename(path);
|
||||
std::map<std::string, FMOD::Sound *>::const_iterator it = mapSound.find(fullPath);
|
||||
return (it != mapSound.end()) ? (it->second) : nullptr;
|
||||
}
|
||||
|
||||
FMOD::Channel * AudioEngineImpl::getChannel(FMOD::Sound *sound)
|
||||
{
|
||||
void * data;
|
||||
sound->getUserData(&data);
|
||||
int id = static_cast<int>(reinterpret_cast<std::intptr_t>(data));
|
||||
return mapChannelInfo[id].channel;
|
||||
}
|
||||
|
|
|
@ -83,7 +83,7 @@ private:
|
|||
FMOD::Channel * getChannel(FMOD::Sound *);
|
||||
|
||||
struct ChannelInfo{
|
||||
size_t id;
|
||||
int id;
|
||||
std::string path;
|
||||
FMOD::Sound * sound;
|
||||
FMOD::Channel * channel;
|
||||
|
|
|
@ -7,205 +7,224 @@ using namespace CocosDenshion;
|
|||
using namespace cocos2d;
|
||||
using namespace cocos2d::experimental;
|
||||
|
||||
|
||||
struct SimpleAudioEngineLinux{
|
||||
SimpleAudioEngine * engine = nullptr;
|
||||
int musicid;
|
||||
float effectsvolume;
|
||||
std::string musicpath;
|
||||
struct SimpleAudioEngineLinux {
|
||||
SimpleAudioEngine * engine = nullptr;
|
||||
int musicid;
|
||||
float effectsvolume;
|
||||
std::string musicpath;
|
||||
};
|
||||
|
||||
SimpleAudioEngineLinux * g_SimpleAudioEngineLinux = nullptr;
|
||||
SimpleAudioEngineLinux * g_SimpleAudioEngineLinux = nullptr;
|
||||
|
||||
|
||||
SimpleAudioEngine* SimpleAudioEngine::getInstance(){
|
||||
if(!g_SimpleAudioEngineLinux){
|
||||
g_SimpleAudioEngineLinux = new SimpleAudioEngineLinux();
|
||||
g_SimpleAudioEngineLinux->engine = new SimpleAudioEngine();
|
||||
}
|
||||
return g_SimpleAudioEngineLinux->engine;
|
||||
};
|
||||
|
||||
void SimpleAudioEngine::end(){
|
||||
if(g_SimpleAudioEngineLinux){
|
||||
delete g_SimpleAudioEngineLinux->engine;
|
||||
delete g_SimpleAudioEngineLinux;
|
||||
SimpleAudioEngine* SimpleAudioEngine::getInstance()
|
||||
{
|
||||
if (!g_SimpleAudioEngineLinux) {
|
||||
g_SimpleAudioEngineLinux = new SimpleAudioEngineLinux();
|
||||
g_SimpleAudioEngineLinux->engine = new SimpleAudioEngine();
|
||||
}
|
||||
g_SimpleAudioEngineLinux = nullptr;
|
||||
};
|
||||
|
||||
|
||||
SimpleAudioEngine::SimpleAudioEngine(){
|
||||
g_SimpleAudioEngineLinux->musicid = -1;
|
||||
g_SimpleAudioEngineLinux->effectsvolume = 1.0f;
|
||||
};
|
||||
return g_SimpleAudioEngineLinux->engine;
|
||||
}
|
||||
|
||||
SimpleAudioEngine::~SimpleAudioEngine(){
|
||||
|
||||
};
|
||||
void SimpleAudioEngine::end()
|
||||
{
|
||||
if (g_SimpleAudioEngineLinux) {
|
||||
delete g_SimpleAudioEngineLinux->engine;
|
||||
delete g_SimpleAudioEngineLinux;
|
||||
}
|
||||
g_SimpleAudioEngineLinux = nullptr;
|
||||
}
|
||||
|
||||
void SimpleAudioEngine::preloadBackgroundMusic(const char* filePath){
|
||||
g_SimpleAudioEngineLinux->musicpath = filePath;
|
||||
AudioEngine::preload(filePath);
|
||||
};
|
||||
|
||||
void SimpleAudioEngine::playBackgroundMusic(const char* filePath, bool loop){
|
||||
g_SimpleAudioEngineLinux->musicpath = filePath;
|
||||
g_SimpleAudioEngineLinux->musicid = AudioEngine::play2d(filePath, loop);
|
||||
};
|
||||
SimpleAudioEngine::SimpleAudioEngine()
|
||||
{
|
||||
g_SimpleAudioEngineLinux->musicid = -1;
|
||||
g_SimpleAudioEngineLinux->effectsvolume = 1.0f;
|
||||
}
|
||||
|
||||
void SimpleAudioEngine::stopBackgroundMusic(bool releaseData){
|
||||
AudioEngine::stop(g_SimpleAudioEngineLinux->musicid);
|
||||
if(releaseData){
|
||||
AudioEngine::uncache(g_SimpleAudioEngineLinux->musicpath.c_str());
|
||||
}
|
||||
};
|
||||
SimpleAudioEngine::~SimpleAudioEngine()
|
||||
{
|
||||
}
|
||||
|
||||
void SimpleAudioEngine::pauseBackgroundMusic(){
|
||||
AudioEngine::pause(g_SimpleAudioEngineLinux->musicid);
|
||||
};
|
||||
void SimpleAudioEngine::preloadBackgroundMusic(const char* filePath)
|
||||
{
|
||||
g_SimpleAudioEngineLinux->musicpath = filePath;
|
||||
AudioEngine::preload(filePath);
|
||||
}
|
||||
|
||||
void SimpleAudioEngine::resumeBackgroundMusic(){
|
||||
AudioEngine::resume(g_SimpleAudioEngineLinux->musicid);
|
||||
};
|
||||
void SimpleAudioEngine::playBackgroundMusic(const char* filePath, bool loop)
|
||||
{
|
||||
g_SimpleAudioEngineLinux->musicpath = filePath;
|
||||
g_SimpleAudioEngineLinux->musicid = AudioEngine::play2d(filePath, loop);
|
||||
}
|
||||
|
||||
void SimpleAudioEngine::rewindBackgroundMusic(){
|
||||
AudioEngine::setCurrentTime(g_SimpleAudioEngineLinux->musicid, 0);
|
||||
};
|
||||
void SimpleAudioEngine::stopBackgroundMusic(bool releaseData)
|
||||
{
|
||||
AudioEngine::stop(g_SimpleAudioEngineLinux->musicid);
|
||||
if (releaseData) {
|
||||
AudioEngine::uncache(g_SimpleAudioEngineLinux->musicpath.c_str());
|
||||
}
|
||||
}
|
||||
|
||||
bool SimpleAudioEngine::willPlayBackgroundMusic(){
|
||||
return g_SimpleAudioEngineLinux->musicid != -1;
|
||||
};
|
||||
void SimpleAudioEngine::pauseBackgroundMusic()
|
||||
{
|
||||
AudioEngine::pause(g_SimpleAudioEngineLinux->musicid);
|
||||
}
|
||||
|
||||
bool SimpleAudioEngine::isBackgroundMusicPlaying(){
|
||||
return AudioEngine::getState(g_SimpleAudioEngineLinux->musicid) == AudioEngine::AudioState::PLAYING;
|
||||
};
|
||||
void SimpleAudioEngine::resumeBackgroundMusic()
|
||||
{
|
||||
AudioEngine::resume(g_SimpleAudioEngineLinux->musicid);
|
||||
}
|
||||
|
||||
//
|
||||
// properties
|
||||
//
|
||||
void SimpleAudioEngine::rewindBackgroundMusic()
|
||||
{
|
||||
AudioEngine::setCurrentTime(g_SimpleAudioEngineLinux->musicid, 0);
|
||||
}
|
||||
|
||||
/**
|
||||
* The volume of the background music within the range of 0.0 as the minimum and 1.0 as the maximum.
|
||||
* @js getMusicVolume
|
||||
* @lua getMusicVolume
|
||||
*/
|
||||
float SimpleAudioEngine::getBackgroundMusicVolume(){
|
||||
return AudioEngine::getVolume(g_SimpleAudioEngineLinux->musicid);
|
||||
};
|
||||
bool SimpleAudioEngine::willPlayBackgroundMusic()
|
||||
{
|
||||
return g_SimpleAudioEngineLinux->musicid != -1;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the volume of background music.
|
||||
*
|
||||
* @param volume must be within the range of 0.0 as the minimum and 1.0 as the maximum.
|
||||
* @js setMusicVolume
|
||||
* @lua setMusicVolume
|
||||
*/
|
||||
void SimpleAudioEngine::setBackgroundMusicVolume(float volume){
|
||||
AudioEngine::setVolume(g_SimpleAudioEngineLinux->musicid, volume);
|
||||
};
|
||||
bool SimpleAudioEngine::isBackgroundMusicPlaying()
|
||||
{
|
||||
return AudioEngine::getState(g_SimpleAudioEngineLinux->musicid) == AudioEngine::AudioState::PLAYING;
|
||||
}
|
||||
|
||||
/**
|
||||
* The volume of the effects within the range of 0.0 as the minimum and 1.0 as the maximum.
|
||||
*/
|
||||
float SimpleAudioEngine::getEffectsVolume(){
|
||||
return g_SimpleAudioEngineLinux->effectsvolume;
|
||||
};
|
||||
//
|
||||
// properties
|
||||
//
|
||||
|
||||
/**
|
||||
* Set the volume of sound effects.
|
||||
*
|
||||
* @param volume must be within the range of 0.0 as the minimum and 1.0 as the maximum.
|
||||
*/
|
||||
void SimpleAudioEngine::setEffectsVolume(float volume){
|
||||
g_SimpleAudioEngineLinux->effectsvolume = volume;
|
||||
};
|
||||
/**
|
||||
* The volume of the background music within the range of 0.0 as the minimum and 1.0 as the maximum.
|
||||
* @js getMusicVolume
|
||||
* @lua getMusicVolume
|
||||
*/
|
||||
float SimpleAudioEngine::getBackgroundMusicVolume()
|
||||
{
|
||||
return AudioEngine::getVolume(g_SimpleAudioEngineLinux->musicid);
|
||||
}
|
||||
|
||||
/**
|
||||
* Play sound effect with a file path, pitch, pan and gain.
|
||||
*
|
||||
* @param filePath The path of the effect file.
|
||||
* @param loop Determines whether to loop the effect playing or not. The default value is false.
|
||||
* @param pitch Frequency, normal value is 1.0. Will also change effect play time.
|
||||
* @param pan Stereo effect, in the range of [-1..1] where -1 enables only left channel.
|
||||
* @param gain Volume, in the range of [0..1]. The normal value is 1.
|
||||
* @return The sound id.
|
||||
*
|
||||
* @note Full support is under development, now there are limitations:
|
||||
* - no pitch effect on Samsung Galaxy S2 with OpenSL backend enabled;
|
||||
* - no pitch/pan/gain on win32.
|
||||
*/
|
||||
unsigned int SimpleAudioEngine::playEffect(const char* filePath, bool loop, float pitch, float pan, float gain){
|
||||
return AudioEngine::play2d(filePath, loop, gain);
|
||||
};
|
||||
/**
|
||||
* Set the volume of background music.
|
||||
*
|
||||
* @param volume must be within the range of 0.0 as the minimum and 1.0 as the maximum.
|
||||
* @js setMusicVolume
|
||||
* @lua setMusicVolume
|
||||
*/
|
||||
void SimpleAudioEngine::setBackgroundMusicVolume(float volume)
|
||||
{
|
||||
AudioEngine::setVolume(g_SimpleAudioEngineLinux->musicid, volume);
|
||||
}
|
||||
|
||||
/**
|
||||
* Pause playing sound effect.
|
||||
*
|
||||
* @param soundId The return value of function playEffect.
|
||||
*/
|
||||
void SimpleAudioEngine::pauseEffect(unsigned int soundId){
|
||||
AudioEngine::pause(soundId);
|
||||
};
|
||||
/**
|
||||
* The volume of the effects within the range of 0.0 as the minimum and 1.0 as the maximum.
|
||||
*/
|
||||
float SimpleAudioEngine::getEffectsVolume()
|
||||
{
|
||||
return g_SimpleAudioEngineLinux->effectsvolume;
|
||||
}
|
||||
|
||||
/**
|
||||
* Pause all playing sound effect.
|
||||
*/
|
||||
void SimpleAudioEngine::pauseAllEffects(){
|
||||
AudioEngine::pauseAll();
|
||||
};
|
||||
/**
|
||||
* Set the volume of sound effects.
|
||||
*
|
||||
* @param volume must be within the range of 0.0 as the minimum and 1.0 as the maximum.
|
||||
*/
|
||||
void SimpleAudioEngine::setEffectsVolume(float volume)
|
||||
{
|
||||
g_SimpleAudioEngineLinux->effectsvolume = volume;
|
||||
}
|
||||
|
||||
/**
|
||||
* Resume playing sound effect.
|
||||
*
|
||||
* @param soundId The return value of function playEffect.
|
||||
*/
|
||||
void SimpleAudioEngine::resumeEffect(unsigned int soundId){
|
||||
AudioEngine::resume(soundId);
|
||||
};
|
||||
/**
|
||||
* Play sound effect with a file path, pitch, pan and gain.
|
||||
*
|
||||
* @param filePath The path of the effect file.
|
||||
* @param loop Determines whether to loop the effect playing or not. The default value is false.
|
||||
* @param pitch Frequency, normal value is 1.0. Will also change effect play time.
|
||||
* @param pan Stereo effect, in the range of [-1..1] where -1 enables only left channel.
|
||||
* @param gain Volume, in the range of [0..1]. The normal value is 1.
|
||||
* @return The sound id.
|
||||
*
|
||||
* @note Full support is under development, now there are limitations:
|
||||
* - no pitch effect on Samsung Galaxy S2 with OpenSL backend enabled;
|
||||
* - no pitch/pan/gain on win32.
|
||||
*/
|
||||
unsigned int SimpleAudioEngine::playEffect(const char* filePath, bool loop, float pitch, float pan, float gain)
|
||||
{
|
||||
return AudioEngine::play2d(filePath, loop, gain);
|
||||
}
|
||||
|
||||
/**
|
||||
* Resume all playing sound effect.
|
||||
*/
|
||||
void SimpleAudioEngine::resumeAllEffects(){
|
||||
AudioEngine::resumeAll();
|
||||
};
|
||||
/**
|
||||
* Pause playing sound effect.
|
||||
*
|
||||
* @param soundId The return value of function playEffect.
|
||||
*/
|
||||
void SimpleAudioEngine::pauseEffect(unsigned int soundId)
|
||||
{
|
||||
AudioEngine::pause(soundId);
|
||||
}
|
||||
|
||||
/**
|
||||
* Stop playing sound effect.
|
||||
*
|
||||
* @param soundId The return value of function playEffect.
|
||||
*/
|
||||
void SimpleAudioEngine::stopEffect(unsigned int soundId){
|
||||
AudioEngine::stop(soundId);
|
||||
};
|
||||
/**
|
||||
* Pause all playing sound effect.
|
||||
*/
|
||||
void SimpleAudioEngine::pauseAllEffects()
|
||||
{
|
||||
AudioEngine::pauseAll();
|
||||
}
|
||||
|
||||
/**
|
||||
* Stop all playing sound effects.
|
||||
*/
|
||||
void SimpleAudioEngine::stopAllEffects(){
|
||||
AudioEngine::stopAll();
|
||||
};
|
||||
/**
|
||||
* Resume playing sound effect.
|
||||
*
|
||||
* @param soundId The return value of function playEffect.
|
||||
*/
|
||||
void SimpleAudioEngine::resumeEffect(unsigned int soundId)
|
||||
{
|
||||
AudioEngine::resume(soundId);
|
||||
}
|
||||
|
||||
/**
|
||||
* Preload a compressed audio file.
|
||||
*
|
||||
* The compressed audio will be decoded to wave, then written into an internal buffer in SimpleAudioEngine.
|
||||
*
|
||||
* @param filePath The path of the effect file.
|
||||
* @js NA
|
||||
*/
|
||||
void SimpleAudioEngine::preloadEffect(const char* filePath){
|
||||
AudioEngine::preload(filePath);
|
||||
};
|
||||
/**
|
||||
* Resume all playing sound effect.
|
||||
*/
|
||||
void SimpleAudioEngine::resumeAllEffects()
|
||||
{
|
||||
AudioEngine::resumeAll();
|
||||
}
|
||||
|
||||
/**
|
||||
* Unload the preloaded effect from internal buffer.
|
||||
*
|
||||
* @param filePath The path of the effect file.
|
||||
*/
|
||||
void SimpleAudioEngine::unloadEffect(const char* filePath){
|
||||
AudioEngine::uncache(filePath);
|
||||
};
|
||||
/**
|
||||
* Stop playing sound effect.
|
||||
*
|
||||
* @param soundId The return value of function playEffect.
|
||||
*/
|
||||
void SimpleAudioEngine::stopEffect(unsigned int soundId)
|
||||
{
|
||||
AudioEngine::stop(soundId);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Stop all playing sound effects.
|
||||
*/
|
||||
void SimpleAudioEngine::stopAllEffects()
|
||||
{
|
||||
AudioEngine::stopAll();
|
||||
}
|
||||
|
||||
/**
|
||||
* Preload a compressed audio file.
|
||||
*
|
||||
* The compressed audio will be decoded to wave, then written into an internal buffer in SimpleAudioEngine.
|
||||
*
|
||||
* @param filePath The path of the effect file.
|
||||
* @js NA
|
||||
*/
|
||||
void SimpleAudioEngine::preloadEffect(const char* filePath)
|
||||
{
|
||||
AudioEngine::preload(filePath);
|
||||
}
|
||||
|
||||
/**
|
||||
* Unload the preloaded effect from internal buffer.
|
||||
*
|
||||
* @param filePath The path of the effect file.
|
||||
*/
|
||||
void SimpleAudioEngine::unloadEffect(const char* filePath)
|
||||
{
|
||||
AudioEngine::uncache(filePath);
|
||||
}
|
||||
|
|
|
@ -9,7 +9,7 @@
|
|||
#else
|
||||
#include <AL/al.h>
|
||||
#endif
|
||||
#include "cocos2d.h"
|
||||
|
||||
|
||||
#if CC_TARGET_PLATFORM == CC_PLATFORM_TIZEN
|
||||
#define DISABLE_VORBIS
|
||||
|
|
|
@ -28,7 +28,8 @@ THE SOFTWARE.
|
|||
#include <cstdlib>
|
||||
|
||||
#include "audio/win32/MciPlayer.h"
|
||||
#include "cocos2d.h"
|
||||
#include "platform/CCFileUtils.h"
|
||||
|
||||
USING_NS_CC;
|
||||
|
||||
using namespace std;
|
||||
|
|
|
@ -18,10 +18,11 @@
|
|||
|
||||
#include "audio/include/SimpleAudioEngine.h"
|
||||
#include "audio/winrt/Audio.h"
|
||||
#include "cocos2d.h"
|
||||
|
||||
#include <map>
|
||||
//#include "platform/CCCommon.h"
|
||||
#include "platform/CCPlatformMacros.h"
|
||||
#include "platform/CCFileUtils.h"
|
||||
|
||||
using namespace std;
|
||||
USING_NS_CC;
|
||||
|
||||
|
@ -83,7 +84,7 @@ void SimpleAudioEngine::playBackgroundMusic(const char* pszFilePath, bool bLoop)
|
|||
return;
|
||||
}
|
||||
|
||||
string fullPath = CCFileUtils::getInstance()->fullPathForFilename(pszFilePath);
|
||||
string fullPath = FileUtils::getInstance()->fullPathForFilename(pszFilePath);
|
||||
sharedAudioController()->PlayBackgroundMusic(fullPath.c_str(), bLoop);
|
||||
}
|
||||
|
||||
|
@ -124,7 +125,7 @@ bool SimpleAudioEngine::isBackgroundMusicPlaying()
|
|||
unsigned int SimpleAudioEngine::playEffect(const char* pszFilePath, bool bLoop,float pitch, float pan, float gain)
|
||||
{
|
||||
unsigned int sound;
|
||||
string fullPath = CCFileUtils::getInstance()->fullPathForFilename(pszFilePath);
|
||||
string fullPath = FileUtils::getInstance()->fullPathForFilename(pszFilePath);
|
||||
sharedAudioController()->PlaySoundEffect(fullPath.c_str(), bLoop, sound); // TODO: need to support playEffect parameters
|
||||
return sound;
|
||||
}
|
||||
|
@ -136,7 +137,7 @@ void SimpleAudioEngine::stopEffect(unsigned int nSoundId)
|
|||
|
||||
void SimpleAudioEngine::preloadEffect(const char* pszFilePath)
|
||||
{
|
||||
string fullPath = CCFileUtils::getInstance()->fullPathForFilename(pszFilePath);
|
||||
string fullPath = FileUtils::getInstance()->fullPathForFilename(pszFilePath);
|
||||
sharedAudioController()->PreloadSoundEffect(fullPath.c_str());
|
||||
}
|
||||
|
||||
|
@ -172,7 +173,7 @@ void SimpleAudioEngine::preloadBackgroundMusic(const char* pszFilePath)
|
|||
|
||||
void SimpleAudioEngine::unloadEffect(const char* pszFilePath)
|
||||
{
|
||||
string fullPath = CCFileUtils::getInstance()->fullPathForFilename(pszFilePath);
|
||||
string fullPath = FileUtils::getInstance()->fullPathForFilename(pszFilePath);
|
||||
sharedAudioController()->UnloadSoundEffect(fullPath.c_str());
|
||||
}
|
||||
|
||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -75,10 +75,70 @@ class CC_DLL Console
|
|||
: public Ref
|
||||
{
|
||||
public:
|
||||
/** Console Utils */
|
||||
class Utility {
|
||||
public:
|
||||
// Trimming functions
|
||||
static std::string& ltrim(std::string& s);
|
||||
static std::string& rtrim(std::string& s);
|
||||
static std::string& trim(std::string& s);
|
||||
|
||||
// split
|
||||
static std::vector<std::string>& split(const std::string& s, char delim, std::vector<std::string>& elems);
|
||||
static std::vector<std::string> split(const std::string& s, char delim);
|
||||
|
||||
/** Checks myString is a floating-point type. */
|
||||
static bool isFloat(const std::string& myString);
|
||||
|
||||
/** send a message to console */
|
||||
static ssize_t sendToConsole(int fd, const void* buffer, size_t length, int flags = 0);
|
||||
|
||||
/** my dprintf() */
|
||||
static ssize_t mydprintf(int sock, const char *format, ...);
|
||||
|
||||
/** send prompt string to console */
|
||||
static void sendPrompt(int fd);
|
||||
|
||||
/** set a new string for the prompt. */
|
||||
static void setPrompt(const std::string &prompt);
|
||||
|
||||
/** get the prompt string. */
|
||||
static const std::string& getPrompt();
|
||||
|
||||
private:
|
||||
static std::string _prompt; /*!< prompt */
|
||||
};
|
||||
|
||||
/** Command Struct */
|
||||
struct Command {
|
||||
using Callback = std::function<void(int fd, const std::string& args)>;
|
||||
std::string name;
|
||||
std::string help;
|
||||
std::function<void(int, const std::string&)> callback;
|
||||
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_) {};
|
||||
|
||||
/** add callback */
|
||||
void addCallback(const Callback& callback);
|
||||
|
||||
/** add sub command */
|
||||
void addSubCommand(const Command& subCmd);
|
||||
|
||||
/** get sub command */
|
||||
const Command* getSubCommand(const std::string& subCmdName) const;
|
||||
|
||||
/** delete sub command */
|
||||
void delSubCommand(const std::string& subCmdName);
|
||||
|
||||
/** help command handler */
|
||||
void commandHelp(int fd, const std::string& args);
|
||||
|
||||
/** generic command handler */
|
||||
void commandGeneric(int fd, const std::string& args);
|
||||
};
|
||||
|
||||
/** Constructor */
|
||||
|
@ -98,6 +158,19 @@ public:
|
|||
|
||||
/** add custom command */
|
||||
void addCommand(const Command& cmd);
|
||||
void addSubCommand(const std::string& cmdName, const Command& subCmd);
|
||||
void addSubCommand(Command& cmd, const Command& subCmd);
|
||||
|
||||
/** get custom command */
|
||||
const Command* getCommand(const std::string& cmdName);
|
||||
const Command* getSubCommand(const std::string& cmdName, const std::string& subCmdName);
|
||||
const Command* getSubCommand(const Command& cmd, const std::string& subCmdName);
|
||||
|
||||
/** delete custom command */
|
||||
void delCommand(const std::string& cmdName);
|
||||
void delSubCommand(const std::string& cmdName, const std::string& subCmdName);
|
||||
void delSubCommand(Command& cmd, const std::string& subCmdName);
|
||||
|
||||
/** log something in the console */
|
||||
void log(const char *buf);
|
||||
|
||||
|
@ -107,28 +180,63 @@ public:
|
|||
* @address : 127.0.0.1
|
||||
*/
|
||||
void setBindAddress(const std::string &address);
|
||||
|
||||
|
||||
protected:
|
||||
// Main Loop
|
||||
void loop();
|
||||
|
||||
// Helpers
|
||||
ssize_t readline(int fd, char *buf, size_t maxlen);
|
||||
ssize_t readBytes(int fd, char* buffer, size_t maxlen, bool* more);
|
||||
bool parseCommand(int fd);
|
||||
|
||||
void addClient();
|
||||
|
||||
// create a map of command.
|
||||
void createCommandAllocator();
|
||||
void createCommandConfig();
|
||||
void createCommandDebugMsg();
|
||||
void createCommandDirector();
|
||||
void createCommandExit();
|
||||
void createCommandFileUtils();
|
||||
void createCommandFps();
|
||||
void createCommandHelp();
|
||||
void createCommandProjection();
|
||||
void createCommandResolution();
|
||||
void createCommandSceneGraph();
|
||||
void createCommandTexture();
|
||||
void createCommandTouch();
|
||||
void createCommandUpload();
|
||||
void createCommandVersion();
|
||||
|
||||
// Add commands here
|
||||
void commandHelp(int fd, const std::string &args);
|
||||
void commandExit(int fd, const std::string &args);
|
||||
void commandSceneGraph(int fd, const std::string &args);
|
||||
void commandFileUtils(int fd, const std::string &args);
|
||||
void commandConfig(int fd, const std::string &args);
|
||||
void commandTextures(int fd, const std::string &args);
|
||||
void commandResolution(int fd, const std::string &args);
|
||||
void commandProjection(int fd, const std::string &args);
|
||||
void commandDirector(int fd, const std::string &args);
|
||||
void commandTouch(int fd, const std::string &args);
|
||||
void commandAllocator(int fd, const std::string& args);
|
||||
void commandConfig(int fd, const std::string& args);
|
||||
void commandDebugMsg(int fd, const std::string& args);
|
||||
void commandDebugMsgSubCommandOnOff(int fd, const std::string& args);
|
||||
void commandDirectorSubCommandPause(int fd, const std::string& args);
|
||||
void commandDirectorSubCommandResume(int fd, const std::string& args);
|
||||
void commandDirectorSubCommandStop(int fd, const std::string& args);
|
||||
void commandDirectorSubCommandStart(int fd, const std::string& args);
|
||||
void commandDirectorSubCommandEnd(int fd, const std::string& args);
|
||||
void commandExit(int fd, const std::string& args);
|
||||
void commandFileUtils(int fd, const std::string& args);
|
||||
void commandFileUtilsSubCommandFlush(int fd, const std::string& args);
|
||||
void commandFps(int fd, const std::string& args);
|
||||
void commandFpsSubCommandOnOff(int fd, const std::string& args);
|
||||
void commandHelp(int fd, const std::string& args);
|
||||
void commandProjection(int fd, const std::string& args);
|
||||
void commandProjectionSubCommand2d(int fd, const std::string& args);
|
||||
void commandProjectionSubCommand3d(int fd, const std::string& args);
|
||||
void commandResolution(int fd, const std::string& args);
|
||||
void commandResolutionSubCommandEmpty(int fd, const std::string& args);
|
||||
void commandSceneGraph(int fd, const std::string& args);
|
||||
void commandTextures(int fd, const std::string& args);
|
||||
void commandTexturesSubCommandFlush(int fd, const std::string& args);
|
||||
void commandTouchSubCommandTap(int fd, const std::string& args);
|
||||
void commandTouchSubCommandSwipe(int fd, const std::string& args);
|
||||
void commandUpload(int fd);
|
||||
void commandAllocator(int fd, const std::string &args);
|
||||
void commandVersion(int fd, const std::string& args);
|
||||
// file descriptor: socket, console, etc.
|
||||
int _listenfd;
|
||||
int _maxfd;
|
||||
|
@ -152,6 +260,14 @@ protected:
|
|||
std::string _bindAddress;
|
||||
private:
|
||||
CC_DISALLOW_COPY_AND_ASSIGN(Console);
|
||||
|
||||
// helper functions
|
||||
int printSceneGraph(int fd, Node* node, int level);
|
||||
void printSceneGraphBoot(int fd);
|
||||
void printFileUtils(int fd);
|
||||
|
||||
/** send help message to console */
|
||||
static void sendHelp(int fd, const std::map<std::string, Command>& commands, const char* msg);
|
||||
};
|
||||
|
||||
NS_CC_END
|
||||
|
|
|
@ -81,7 +81,7 @@ static GCControllerConnectionEventHandler* __instance = nil;
|
|||
|
||||
-(void)dealloc {
|
||||
[[NSNotificationCenter defaultCenter] removeObserver:self];
|
||||
[super dealloc];
|
||||
[super dealloc];
|
||||
}
|
||||
|
||||
-(void) onControllerConnected :(NSNotification *)connectedNotification {
|
||||
|
@ -116,6 +116,9 @@ public:
|
|||
|
||||
void Controller::startDiscoveryController()
|
||||
{
|
||||
if (NSClassFromString(@"GCController") == nil) {
|
||||
return;
|
||||
}
|
||||
[GCController startWirelessControllerDiscoveryWithCompletionHandler: nil];
|
||||
|
||||
[[GCControllerConnectionEventHandler getInstance] observerConnection: ^(GCController* gcController) {
|
||||
|
@ -148,6 +151,9 @@ void Controller::startDiscoveryController()
|
|||
|
||||
void Controller::stopDiscoveryController()
|
||||
{
|
||||
if (NSClassFromString(@"GCController") == nil) {
|
||||
return;
|
||||
}
|
||||
[GCController stopWirelessControllerDiscovery];
|
||||
}
|
||||
|
||||
|
|
|
@ -56,6 +56,8 @@ public:
|
|||
*/
|
||||
enum Key
|
||||
{
|
||||
KEY_NONE = 0,
|
||||
|
||||
JOYSTICK_LEFT_X = 1000,
|
||||
JOYSTICK_LEFT_Y,
|
||||
JOYSTICK_RIGHT_X,
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
/****************************************************************************
|
||||
Copyright (c) 2010-2012 cocos2d-x.org
|
||||
Copyright (c) 2013-2014 Chukong Technologies Inc.
|
||||
|
||||
|
||||
http://www.cocos2d-x.org
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
|
@ -77,7 +77,7 @@ void Data::move(Data& other)
|
|||
{
|
||||
_bytes = other._bytes;
|
||||
_size = other._size;
|
||||
|
||||
|
||||
other._bytes = nullptr;
|
||||
other._size = 0;
|
||||
}
|
||||
|
@ -100,7 +100,7 @@ ssize_t Data::getSize() const
|
|||
void Data::copy(const unsigned char* bytes, const ssize_t size)
|
||||
{
|
||||
clear();
|
||||
|
||||
|
||||
if (size > 0)
|
||||
{
|
||||
_size = size;
|
||||
|
@ -122,4 +122,13 @@ void Data::clear()
|
|||
_size = 0;
|
||||
}
|
||||
|
||||
unsigned char* Data::takeBuffer(ssize_t* size)
|
||||
{
|
||||
auto buffer = getBytes();
|
||||
if (size)
|
||||
*size = getSize();
|
||||
fastSet(nullptr, 0);
|
||||
return buffer;
|
||||
}
|
||||
|
||||
NS_CC_END
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
/****************************************************************************
|
||||
Copyright (c) 2010-2012 cocos2d-x.org
|
||||
Copyright (c) 2013-2014 Chukong Technologies Inc.
|
||||
|
||||
|
||||
http://www.cocos2d-x.org
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
|
@ -41,64 +41,64 @@ NS_CC_BEGIN
|
|||
class CC_DLL Data
|
||||
{
|
||||
friend class Properties;
|
||||
|
||||
|
||||
public:
|
||||
/**
|
||||
* This parameter is defined for convenient reference if a null Data object is needed.
|
||||
*/
|
||||
static const Data Null;
|
||||
|
||||
|
||||
/**
|
||||
* Constructor of Data.
|
||||
*/
|
||||
Data();
|
||||
|
||||
|
||||
/**
|
||||
* Copy constructor of Data.
|
||||
*/
|
||||
Data(const Data& other);
|
||||
|
||||
|
||||
/**
|
||||
* Copy constructor of Data.
|
||||
*/
|
||||
Data(Data&& other);
|
||||
|
||||
|
||||
/**
|
||||
* Destructor of Data.
|
||||
*/
|
||||
~Data();
|
||||
|
||||
|
||||
/**
|
||||
* Overloads of operator=.
|
||||
*/
|
||||
Data& operator= (const Data& other);
|
||||
|
||||
|
||||
/**
|
||||
* Overloads of operator=.
|
||||
*/
|
||||
Data& operator= (Data&& other);
|
||||
|
||||
|
||||
/**
|
||||
* Gets internal bytes of Data. It will return the pointer directly used in Data, so don't delete it.
|
||||
*
|
||||
* @return Pointer of bytes used internal in Data.
|
||||
*/
|
||||
unsigned char* getBytes() const;
|
||||
|
||||
|
||||
/**
|
||||
* Gets the size of the bytes.
|
||||
*
|
||||
* @return The size of bytes of Data.
|
||||
*/
|
||||
ssize_t getSize() const;
|
||||
|
||||
|
||||
/** Copies the buffer pointer and its size.
|
||||
* @note This method will copy the whole buffer.
|
||||
* Developer should free the pointer after invoking this method.
|
||||
* @see Data::fastSet
|
||||
*/
|
||||
void copy(const unsigned char* bytes, const ssize_t size);
|
||||
|
||||
|
||||
/** Fast set the buffer pointer and its size. Please use it carefully.
|
||||
* @param bytes The buffer pointer, note that it have to be allocated by 'malloc' or 'calloc',
|
||||
* since in the destructor of Data, the buffer will be deleted by 'free'.
|
||||
|
@ -107,22 +107,45 @@ public:
|
|||
* @see Data::copy
|
||||
*/
|
||||
void fastSet(unsigned char* bytes, const ssize_t size);
|
||||
|
||||
/**
|
||||
|
||||
/**
|
||||
* Clears data, free buffer and reset data size.
|
||||
*/
|
||||
void clear();
|
||||
|
||||
/**
|
||||
|
||||
/**
|
||||
* Check whether the data is null.
|
||||
*
|
||||
* @return True if the Data is null, false if not.
|
||||
*/
|
||||
bool isNull() const;
|
||||
|
||||
|
||||
/**
|
||||
* Get the internal buffer of data and set data to empty state.
|
||||
*
|
||||
* The ownership of the buffer removed from the data object.
|
||||
* That is the user have to free the returned buffer.
|
||||
* The data object is set to empty state, that is internal buffer is set to nullptr
|
||||
* and size is set to zero.
|
||||
* Usage:
|
||||
* <pre>
|
||||
* {@code
|
||||
* Data d;
|
||||
* // ...
|
||||
* ssize_t size;
|
||||
* unsigned char* buffer = d.takeBuffer(&size);
|
||||
* // use buffer and size
|
||||
* free(buffer);
|
||||
* }
|
||||
* </pre
|
||||
*
|
||||
* @param size Will fill with the data buffer size in bytes, if you do not care buffer size, pass nullptr.
|
||||
* @return the internal data buffer, free it after use.
|
||||
*/
|
||||
unsigned char* takeBuffer(ssize_t* size);
|
||||
private:
|
||||
void move(Data& other);
|
||||
|
||||
|
||||
private:
|
||||
unsigned char* _bytes;
|
||||
ssize_t _size;
|
||||
|
|
|
@ -1088,7 +1088,7 @@ void Director::restartDirector()
|
|||
|
||||
// Real restart in script level
|
||||
#if CC_ENABLE_SCRIPT_BINDING
|
||||
ScriptEvent scriptEvent(kRestartGame, NULL);
|
||||
ScriptEvent scriptEvent(kRestartGame, nullptr);
|
||||
ScriptEngineManager::getInstance()->getScriptEngine()->sendEvent(&scriptEvent);
|
||||
#endif
|
||||
}
|
||||
|
|
|
@ -604,6 +604,10 @@ void EventDispatcher::removeEventListener(EventListener* listener)
|
|||
{
|
||||
if (listener == nullptr)
|
||||
return;
|
||||
|
||||
// just return if listener is in _toRemovedListeners to avoid remove listeners more than once
|
||||
if (std::find(_toRemovedListeners.begin(), _toRemovedListeners.end(), listener) != _toRemovedListeners.end())
|
||||
return;
|
||||
|
||||
bool isFound = false;
|
||||
|
||||
|
|
|
@ -273,7 +273,7 @@ void IMEDispatcher::dispatchKeyboardWillShow(IMEKeyboardNotificationInfo& info)
|
|||
{
|
||||
if (_impl)
|
||||
{
|
||||
IMEDelegate * delegate = 0;
|
||||
IMEDelegate * delegate = nullptr;
|
||||
DelegateIter last = _impl->_delegateList.end();
|
||||
for (DelegateIter first = _impl->_delegateList.begin(); first != last; ++first)
|
||||
{
|
||||
|
@ -290,7 +290,7 @@ void IMEDispatcher::dispatchKeyboardDidShow(IMEKeyboardNotificationInfo& info)
|
|||
{
|
||||
if (_impl)
|
||||
{
|
||||
IMEDelegate * delegate = 0;
|
||||
IMEDelegate * delegate = nullptr;
|
||||
DelegateIter last = _impl->_delegateList.end();
|
||||
for (DelegateIter first = _impl->_delegateList.begin(); first != last; ++first)
|
||||
{
|
||||
|
@ -307,7 +307,7 @@ void IMEDispatcher::dispatchKeyboardWillHide(IMEKeyboardNotificationInfo& info)
|
|||
{
|
||||
if (_impl)
|
||||
{
|
||||
IMEDelegate * delegate = 0;
|
||||
IMEDelegate * delegate = nullptr;
|
||||
DelegateIter last = _impl->_delegateList.end();
|
||||
for (DelegateIter first = _impl->_delegateList.begin(); first != last; ++first)
|
||||
{
|
||||
|
@ -324,7 +324,7 @@ void IMEDispatcher::dispatchKeyboardDidHide(IMEKeyboardNotificationInfo& info)
|
|||
{
|
||||
if (_impl)
|
||||
{
|
||||
IMEDelegate * delegate = 0;
|
||||
IMEDelegate * delegate = nullptr;
|
||||
DelegateIter last = _impl->_delegateList.end();
|
||||
for (DelegateIter first = _impl->_delegateList.begin(); first != last; ++first)
|
||||
{
|
||||
|
|
|
@ -346,7 +346,7 @@ public:
|
|||
{
|
||||
if (!_data.empty())
|
||||
{
|
||||
ssize_t randIdx = rand() % _data.size();
|
||||
ssize_t randIdx = RandomHelper::random_int<int>(0, static_cast<int>(_data.size()) - 1);
|
||||
const_iterator randIter = _data.begin();
|
||||
std::advance(randIter , randIdx);
|
||||
return randIter->second;
|
||||
|
|
|
@ -159,8 +159,6 @@ class Data;
|
|||
*/
|
||||
class CC_DLL Properties
|
||||
{
|
||||
friend class Game;
|
||||
|
||||
public:
|
||||
|
||||
/**
|
||||
|
|
|
@ -38,7 +38,6 @@
|
|||
NS_CC_BEGIN
|
||||
|
||||
GLint StencilStateManager::s_layer = -1;
|
||||
static GLint g_sStencilBits = -1;
|
||||
|
||||
StencilStateManager::StencilStateManager()
|
||||
: _alphaThreshold(1.0f)
|
||||
|
@ -57,17 +56,6 @@ StencilStateManager::StencilStateManager()
|
|||
, _currentAlphaTestRef(1)
|
||||
|
||||
{
|
||||
// get (only once) the number of bits of the stencil buffer
|
||||
static bool once = true;
|
||||
if (once)
|
||||
{
|
||||
glGetIntegerv(GL_STENCIL_BITS, &g_sStencilBits);
|
||||
if (g_sStencilBits <= 0)
|
||||
{
|
||||
CCLOG("Stencil buffer is not enabled.");
|
||||
}
|
||||
once = false;
|
||||
}
|
||||
}
|
||||
|
||||
void StencilStateManager::drawFullScreenQuadClearStencil()
|
||||
|
|
|
@ -394,7 +394,7 @@ void UserDefault::setDataForKey(const char* pKey, const Data& value) {
|
|||
return;
|
||||
}
|
||||
|
||||
char *encodedData = 0;
|
||||
char *encodedData = nullptr;
|
||||
|
||||
base64Encode(value.getBytes(), static_cast<unsigned int>(value.getSize()), &encodedData);
|
||||
|
||||
|
|
|
@ -53,6 +53,12 @@ Value::Value(int v)
|
|||
_field.intVal = v;
|
||||
}
|
||||
|
||||
Value::Value(unsigned int v)
|
||||
: _type(Type::UNSIGNED)
|
||||
{
|
||||
_field.unsignedVal = v;
|
||||
}
|
||||
|
||||
Value::Value(float v)
|
||||
: _type(Type::FLOAT)
|
||||
{
|
||||
|
@ -159,6 +165,9 @@ Value& Value::operator= (const Value& other)
|
|||
case Type::INTEGER:
|
||||
_field.intVal = other._field.intVal;
|
||||
break;
|
||||
case Type::UNSIGNED:
|
||||
_field.unsignedVal = other._field.unsignedVal;
|
||||
break;
|
||||
case Type::FLOAT:
|
||||
_field.floatVal = other._field.floatVal;
|
||||
break;
|
||||
|
@ -216,6 +225,9 @@ Value& Value::operator= (Value&& other)
|
|||
case Type::INTEGER:
|
||||
_field.intVal = other._field.intVal;
|
||||
break;
|
||||
case Type::UNSIGNED:
|
||||
_field.unsignedVal = other._field.unsignedVal;
|
||||
break;
|
||||
case Type::FLOAT:
|
||||
_field.floatVal = other._field.floatVal;
|
||||
break;
|
||||
|
@ -263,6 +275,13 @@ Value& Value::operator= (int v)
|
|||
return *this;
|
||||
}
|
||||
|
||||
Value& Value::operator= (unsigned int v)
|
||||
{
|
||||
reset(Type::UNSIGNED);
|
||||
_field.unsignedVal = v;
|
||||
return *this;
|
||||
}
|
||||
|
||||
Value& Value::operator= (float v)
|
||||
{
|
||||
reset(Type::FLOAT);
|
||||
|
@ -361,56 +380,58 @@ bool Value::operator== (const Value& v) const
|
|||
if (this->isNull()) return true;
|
||||
switch (_type)
|
||||
{
|
||||
case Type::BYTE: return v._field.byteVal == this->_field.byteVal;
|
||||
case Type::INTEGER: return v._field.intVal == this->_field.intVal;
|
||||
case Type::BOOLEAN: return v._field.boolVal == this->_field.boolVal;
|
||||
case Type::STRING: return *v._field.strVal == *this->_field.strVal;
|
||||
case Type::FLOAT: return fabs(v._field.floatVal - this->_field.floatVal) <= FLT_EPSILON;
|
||||
case Type::DOUBLE: return fabs(v._field.doubleVal - this->_field.doubleVal) <= FLT_EPSILON;
|
||||
case Type::VECTOR:
|
||||
{
|
||||
const auto &v1 = *(this->_field.vectorVal);
|
||||
const auto &v2 = *(v._field.vectorVal);
|
||||
const auto size = v1.size();
|
||||
if (size == v2.size())
|
||||
case Type::BYTE: return v._field.byteVal == this->_field.byteVal;
|
||||
case Type::INTEGER: return v._field.intVal == this->_field.intVal;
|
||||
case Type::UNSIGNED:return v._field.unsignedVal == this->_field.unsignedVal;
|
||||
case Type::BOOLEAN: return v._field.boolVal == this->_field.boolVal;
|
||||
case Type::STRING: return *v._field.strVal == *this->_field.strVal;
|
||||
case Type::FLOAT: return fabs(v._field.floatVal - this->_field.floatVal) <= FLT_EPSILON;
|
||||
case Type::DOUBLE: return fabs(v._field.doubleVal - this->_field.doubleVal) <= FLT_EPSILON;
|
||||
case Type::VECTOR:
|
||||
{
|
||||
for (size_t i = 0; i < size; i++)
|
||||
const auto &v1 = *(this->_field.vectorVal);
|
||||
const auto &v2 = *(v._field.vectorVal);
|
||||
const auto size = v1.size();
|
||||
if (size == v2.size())
|
||||
{
|
||||
if (v1[i] != v2[i]) return false;
|
||||
for (size_t i = 0; i < size; i++)
|
||||
{
|
||||
if (v1[i] != v2[i]) return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
case Type::MAP:
|
||||
{
|
||||
const auto &map1 = *(this->_field.mapVal);
|
||||
const auto &map2 = *(v._field.mapVal);
|
||||
for (const auto &kvp : map1)
|
||||
case Type::MAP:
|
||||
{
|
||||
auto it = map2.find(kvp.first);
|
||||
if (it == map2.end() || it->second != kvp.second)
|
||||
const auto &map1 = *(this->_field.mapVal);
|
||||
const auto &map2 = *(v._field.mapVal);
|
||||
for (const auto &kvp : map1)
|
||||
{
|
||||
return false;
|
||||
auto it = map2.find(kvp.first);
|
||||
if (it == map2.end() || it->second != kvp.second)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
case Type::INT_KEY_MAP:
|
||||
{
|
||||
const auto &map1 = *(this->_field.intKeyMapVal);
|
||||
const auto &map2 = *(v._field.intKeyMapVal);
|
||||
for (const auto &kvp : map1)
|
||||
case Type::INT_KEY_MAP:
|
||||
{
|
||||
auto it = map2.find(kvp.first);
|
||||
if (it == map2.end() || it->second != kvp.second)
|
||||
const auto &map1 = *(this->_field.intKeyMapVal);
|
||||
const auto &map2 = *(v._field.intKeyMapVal);
|
||||
for (const auto &kvp : map1)
|
||||
{
|
||||
return false;
|
||||
auto it = map2.find(kvp.first);
|
||||
if (it == map2.end() || it->second != kvp.second)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
default:
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
};
|
||||
|
||||
return false;
|
||||
|
@ -431,6 +452,11 @@ unsigned char Value::asByte() const
|
|||
return static_cast<unsigned char>(_field.intVal);
|
||||
}
|
||||
|
||||
if (_type == Type::UNSIGNED)
|
||||
{
|
||||
return static_cast<unsigned char>(_field.unsignedVal);
|
||||
}
|
||||
|
||||
if (_type == Type::STRING)
|
||||
{
|
||||
return static_cast<unsigned char>(atoi(_field.strVal->c_str()));
|
||||
|
@ -462,6 +488,12 @@ int Value::asInt() const
|
|||
return _field.intVal;
|
||||
}
|
||||
|
||||
if (_type == Type::UNSIGNED)
|
||||
{
|
||||
CCASSERT(_field.unsignedVal < INT_MAX, "Can only convert values < INT_MAX");
|
||||
return (int)_field.unsignedVal;
|
||||
}
|
||||
|
||||
if (_type == Type::BYTE)
|
||||
{
|
||||
return _field.byteVal;
|
||||
|
@ -490,6 +522,50 @@ int Value::asInt() const
|
|||
return 0;
|
||||
}
|
||||
|
||||
|
||||
unsigned int Value::asUnsignedInt() const
|
||||
{
|
||||
CCASSERT(_type != Type::VECTOR && _type != Type::MAP && _type != Type::INT_KEY_MAP, "Only base type (bool, string, float, double, int) could be converted");
|
||||
if (_type == Type::UNSIGNED)
|
||||
{
|
||||
return _field.unsignedVal;
|
||||
}
|
||||
|
||||
if (_type == Type::INTEGER)
|
||||
{
|
||||
CCASSERT(_field.intVal >= 0, "Only values >= 0 can be converted to unsigned");
|
||||
return static_cast<unsigned int>(_field.intVal);
|
||||
}
|
||||
|
||||
if (_type == Type::BYTE)
|
||||
{
|
||||
return static_cast<unsigned int>(_field.byteVal);
|
||||
}
|
||||
|
||||
if (_type == Type::STRING)
|
||||
{
|
||||
// NOTE: strtoul is required (need to augment on unsupported platforms)
|
||||
return static_cast<unsigned int>(strtoul(_field.strVal->c_str(), nullptr, 10));
|
||||
}
|
||||
|
||||
if (_type == Type::FLOAT)
|
||||
{
|
||||
return static_cast<unsigned int>(_field.floatVal);
|
||||
}
|
||||
|
||||
if (_type == Type::DOUBLE)
|
||||
{
|
||||
return static_cast<unsigned int>(_field.doubleVal);
|
||||
}
|
||||
|
||||
if (_type == Type::BOOLEAN)
|
||||
{
|
||||
return _field.boolVal ? 1u : 0u;
|
||||
}
|
||||
|
||||
return 0u;
|
||||
}
|
||||
|
||||
float Value::asFloat() const
|
||||
{
|
||||
CCASSERT(_type != Type::VECTOR && _type != Type::MAP && _type != Type::INT_KEY_MAP, "Only base type (bool, string, float, double, int) could be converted");
|
||||
|
@ -513,6 +589,11 @@ float Value::asFloat() const
|
|||
return static_cast<float>(_field.intVal);
|
||||
}
|
||||
|
||||
if (_type == Type::UNSIGNED)
|
||||
{
|
||||
return static_cast<float>(_field.unsignedVal);
|
||||
}
|
||||
|
||||
if (_type == Type::DOUBLE)
|
||||
{
|
||||
return static_cast<float>(_field.doubleVal);
|
||||
|
@ -549,6 +630,11 @@ double Value::asDouble() const
|
|||
return static_cast<double>(_field.intVal);
|
||||
}
|
||||
|
||||
if (_type == Type::UNSIGNED)
|
||||
{
|
||||
return static_cast<double>(_field.unsignedVal);
|
||||
}
|
||||
|
||||
if (_type == Type::FLOAT)
|
||||
{
|
||||
return static_cast<double>(_field.floatVal);
|
||||
|
@ -585,6 +671,11 @@ bool Value::asBool() const
|
|||
return _field.intVal == 0 ? false : true;
|
||||
}
|
||||
|
||||
if (_type == Type::UNSIGNED)
|
||||
{
|
||||
return _field.unsignedVal == 0 ? false : true;
|
||||
}
|
||||
|
||||
if (_type == Type::FLOAT)
|
||||
{
|
||||
return _field.floatVal == 0.0f ? false : true;
|
||||
|
@ -617,6 +708,9 @@ std::string Value::asString() const
|
|||
case Type::INTEGER:
|
||||
ret << _field.intVal;
|
||||
break;
|
||||
case Type::UNSIGNED:
|
||||
ret << _field.unsignedVal;
|
||||
break;
|
||||
case Type::FLOAT:
|
||||
ret << std::fixed << std::setprecision( 7 )<< _field.floatVal;
|
||||
break;
|
||||
|
@ -733,6 +827,7 @@ static std::string visit(const Value& v, int depth)
|
|||
case Value::Type::NONE:
|
||||
case Value::Type::BYTE:
|
||||
case Value::Type::INTEGER:
|
||||
case Value::Type::UNSIGNED:
|
||||
case Value::Type::FLOAT:
|
||||
case Value::Type::DOUBLE:
|
||||
case Value::Type::BOOLEAN:
|
||||
|
@ -774,6 +869,9 @@ void Value::clear()
|
|||
case Type::INTEGER:
|
||||
_field.intVal = 0;
|
||||
break;
|
||||
case Type::UNSIGNED:
|
||||
_field.unsignedVal = 0u;
|
||||
break;
|
||||
case Type::FLOAT:
|
||||
_field.floatVal = 0.0f;
|
||||
break;
|
||||
|
@ -798,7 +896,7 @@ void Value::clear()
|
|||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
_type = Type::NONE;
|
||||
}
|
||||
|
||||
|
|
|
@ -65,7 +65,10 @@ public:
|
|||
|
||||
/** Create a Value by an integer value. */
|
||||
explicit Value(int v);
|
||||
|
||||
|
||||
/** Create a Value by an unsigned value. */
|
||||
explicit Value(unsigned int v);
|
||||
|
||||
/** Create a Value by a float value. */
|
||||
explicit Value(float v);
|
||||
|
||||
|
@ -113,6 +116,8 @@ public:
|
|||
Value& operator= (unsigned char v);
|
||||
/** Assignment operator, assign from integer to Value. */
|
||||
Value& operator= (int v);
|
||||
/** Assignment operator, assign from integer to Value. */
|
||||
Value& operator= (unsigned int v);
|
||||
/** Assignment operator, assign from float to Value. */
|
||||
Value& operator= (float v);
|
||||
/** Assignment operator, assign from double to Value. */
|
||||
|
@ -152,6 +157,8 @@ public:
|
|||
unsigned char asByte() const;
|
||||
/** Gets as an integer value. Will convert to integer if possible, or will trigger assert error. */
|
||||
int asInt() const;
|
||||
/** Gets as an unsigned value. Will convert to unsigned if possible, or will trigger assert error. */
|
||||
unsigned int asUnsignedInt() const;
|
||||
/** Gets as a float value. Will convert to float if possible, or will trigger assert error. */
|
||||
float asFloat() const;
|
||||
/** Gets as a double value. Will convert to double if possible, or will trigger assert error. */
|
||||
|
@ -191,6 +198,8 @@ public:
|
|||
BYTE,
|
||||
/// wrap integer
|
||||
INTEGER,
|
||||
/// wrap unsigned
|
||||
UNSIGNED,
|
||||
/// wrap float
|
||||
FLOAT,
|
||||
/// wrap double
|
||||
|
@ -221,6 +230,7 @@ private:
|
|||
{
|
||||
unsigned char byteVal;
|
||||
int intVal;
|
||||
unsigned int unsignedVal;
|
||||
float floatVal;
|
||||
double doubleVal;
|
||||
bool boolVal;
|
||||
|
|
|
@ -53,14 +53,14 @@ public:
|
|||
// ------------------------------------------
|
||||
|
||||
/** Iterator, can be used to loop the Vector. */
|
||||
typedef typename std::vector<T>::iterator iterator;
|
||||
using iterator = typename std::vector<T>::iterator;
|
||||
/** Const iterator, can be used to loop the Vector. */
|
||||
typedef typename std::vector<T>::const_iterator const_iterator;
|
||||
|
||||
using const_iterator = typename std::vector<T>::const_iterator;
|
||||
|
||||
/** Reversed iterator, can be used to loop the Vector in reverse sequence. */
|
||||
typedef typename std::vector<T>::reverse_iterator reverse_iterator;
|
||||
/** Reversed iterator, can be used to loop the Vector in reverse sequence. */
|
||||
typedef typename std::vector<T>::const_reverse_iterator const_reverse_iterator;
|
||||
using reverse_iterator = typename std::vector<T>::reverse_iterator;
|
||||
/** Reversed iterator, can be used to loop the Vector in reverse sequence. */
|
||||
using const_reverse_iterator = typename std::vector<T>::const_reverse_iterator;
|
||||
|
||||
/** Returns an iterator pointing the first element of the Vector. */
|
||||
iterator begin() { return _data.begin(); }
|
||||
|
@ -125,6 +125,15 @@ public:
|
|||
reserve(capacity);
|
||||
}
|
||||
|
||||
/** Constructor with initializer list. */
|
||||
Vector<T>(std::initializer_list<T> list)
|
||||
{
|
||||
for (auto& element : list)
|
||||
{
|
||||
pushBack(element);
|
||||
}
|
||||
}
|
||||
|
||||
/** Destructor. */
|
||||
~Vector<T>()
|
||||
{
|
||||
|
@ -279,7 +288,7 @@ public:
|
|||
{
|
||||
if (!_data.empty())
|
||||
{
|
||||
ssize_t randIdx = rand() % _data.size();
|
||||
ssize_t randIdx = RandomHelper::random_int<int>(0, static_cast<int>(_data.size()) - 1);
|
||||
return *(_data.begin() + randIdx);
|
||||
}
|
||||
return nullptr;
|
||||
|
|
|
@ -645,6 +645,35 @@ unsigned char *ZipFile::getFileData(const std::string &fileName, ssize_t *size)
|
|||
return buffer;
|
||||
}
|
||||
|
||||
bool ZipFile::getFileData(const std::string &fileName, ResizableBuffer* buffer)
|
||||
{
|
||||
bool res = false;
|
||||
do
|
||||
{
|
||||
CC_BREAK_IF(!_data->zipFile);
|
||||
CC_BREAK_IF(fileName.empty());
|
||||
|
||||
ZipFilePrivate::FileListContainer::const_iterator it = _data->fileList.find(fileName);
|
||||
CC_BREAK_IF(it == _data->fileList.end());
|
||||
|
||||
ZipEntryInfo fileInfo = it->second;
|
||||
|
||||
int nRet = unzGoToFilePos(_data->zipFile, &fileInfo.pos);
|
||||
CC_BREAK_IF(UNZ_OK != nRet);
|
||||
|
||||
nRet = unzOpenCurrentFile(_data->zipFile);
|
||||
CC_BREAK_IF(UNZ_OK != nRet);
|
||||
|
||||
buffer->resize(fileInfo.uncompressed_size);
|
||||
int CC_UNUSED nSize = unzReadCurrentFile(_data->zipFile, buffer->buffer(), static_cast<unsigned int>(fileInfo.uncompressed_size));
|
||||
CCASSERT(nSize == 0 || nSize == (int)fileInfo.uncompressed_size, "the file size is wrong");
|
||||
unzCloseCurrentFile(_data->zipFile);
|
||||
res = true;
|
||||
} while (0);
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
std::string ZipFile::getFirstFilename()
|
||||
{
|
||||
if (unzGoToFirstFile(_data->zipFile) != UNZ_OK) return emptyFilename;
|
||||
|
|
|
@ -31,6 +31,7 @@ THE SOFTWARE.
|
|||
#include "platform/CCPlatformConfig.h"
|
||||
#include "platform/CCPlatformMacros.h"
|
||||
#include "platform/CCPlatformDefine.h"
|
||||
#include "platform/CCFileUtils.h"
|
||||
|
||||
#if (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID)
|
||||
#include "platform/android/CCFileUtils-android.h"
|
||||
|
@ -275,6 +276,14 @@ typedef struct unz_file_info_s unz_file_info;
|
|||
* @since v2.0.5
|
||||
*/
|
||||
unsigned char *getFileData(const std::string &fileName, ssize_t *size);
|
||||
|
||||
/**
|
||||
* Get resource file data from a zip file.
|
||||
* @param fileName File name
|
||||
* @param[out] buffer If the file read operation succeeds, if will contain the file data.
|
||||
* @return True if successful.
|
||||
*/
|
||||
bool getFileData(const std::string &fileName, ResizableBuffer* buffer);
|
||||
|
||||
std::string getFirstFilename();
|
||||
std::string getNextFilename();
|
||||
|
|
|
@ -27,6 +27,7 @@
|
|||
#define CC_ALLOCATOR_STRATEGY_DEFAULT_H
|
||||
/// @cond DO_NOT_SHOW
|
||||
|
||||
#include <stdlib.h>
|
||||
#include "base/allocator/CCAllocatorMacros.h"
|
||||
#include "base/allocator/CCAllocatorBase.h"
|
||||
|
||||
|
|
|
@ -142,7 +142,7 @@ int base64Decode(const unsigned char *in, unsigned int inLength, unsigned char *
|
|||
unsigned int outLength = 0;
|
||||
|
||||
//should be enough to store 6-bit buffers in 8-bit buffers
|
||||
*out = (unsigned char*)malloc(inLength * 3.0f / 4.0f + 1);
|
||||
*out = (unsigned char*)malloc(inLength / 4 * 3 + 1);
|
||||
if( *out ) {
|
||||
int ret = _base64Decode(in, inLength, *out, &outLength);
|
||||
|
||||
|
@ -160,7 +160,7 @@ int base64Decode(const unsigned char *in, unsigned int inLength, unsigned char *
|
|||
}
|
||||
|
||||
int base64Encode(const unsigned char *in, unsigned int inLength, char **out) {
|
||||
unsigned int outLength = inLength * 4 / 3 + (inLength % 3 > 0 ? 4 : 0);
|
||||
unsigned int outLength = (inLength + 2) / 3 * 4;
|
||||
|
||||
//should be enough to store 8-bit buffers in 6-bit buffers
|
||||
*out = (char*)malloc(outLength+1);
|
||||
|
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue