diff --git a/native/.travis.yml b/native/.travis.yml index 67f9d588e0..432b72c718 100644 --- a/native/.travis.yml +++ b/native/.travis.yml @@ -1,11 +1,38 @@ language: cpp -os: -- linux + +matrix: + include: + - os: windows + env: + - BUILD_TARGET=windows_cmake + language: cpp + - os: osx + env: + - BUILD_TARGET=macosx_cmake + language: cpp + osx_image: xcode10.3 + sudo: required + - os: osx + env: + - BUILD_TARGET=ios_cmake + language: cpp + osx_image: xcode10.3 + sudo: required + - os: linux + dist: xenial + sudo: required + env: + - BUILD_TARGET=android_cmake + language: cpp + +node_js: + - "7" +jdk: + - oraclejdk8 script: -- tools/travis-scripts/run-script.sh -sudo: required + - tools/travis-scripts/run-script.sh before_install: -- tools/travis-scripts/before-install.sh + - tools/travis-scripts/before-install.sh # blocklist # branches: diff --git a/native/CMakeLists.txt b/native/CMakeLists.txt new file mode 100644 index 0000000000..f0bf6b16dc --- /dev/null +++ b/native/CMakeLists.txt @@ -0,0 +1,1006 @@ + + + +if(${CMAKE_SYSTEM_NAME} MATCHES "Windows") + set(WINDOWS TRUE) + set(PLATFORM_FOLDER win32) +elseif(${CMAKE_SYSTEM_NAME} MATCHES "Android") + set(PLATFORM_FOLDER android) + set(ANDROID TRUE) +elseif(${CMAKE_SYSTEM_NAME} MATCHES "Darwin") + set(APPLE TRUE) + set(MACOSX TRUE) + set(PLATFORM_FOLDER mac) +elseif(${CMAKE_SYSTEM_NAME} MATCHES "iOS") + set(APPLE TRUE) + set(IOS TRUE) + set(PLATFORM_FOLDER ios) +else() + message(FATAL_ERROR "Unsupported platform, CMake will exit") + return() +endif() + +# generators that are capable of organizing into a hierarchy of folders +set_property(GLOBAL PROPERTY USE_FOLDERS ON) +# simplify generator condition, please use them everywhere +if(CMAKE_GENERATOR STREQUAL Xcode) + set(XCODE TRUE) +elseif(CMAKE_GENERATOR MATCHES Visual) + set(VS TRUE) +endif() + + +# set c++ standard +set(CMAKE_C_STANDARD 99) +set(CMAKE_C_STANDARD_REQUIRED ON) +set(CMAKE_CXX_STANDARD 14) +set(CMAKE_CXX_STANDARD_REQUIRED ON) +set(CMAKE_CXX_EXTENSIONS OFF) + +################################# options ############################################ + +if(ANDROID) + set(CC_USE_GLES3 ON) + set(CC_USE_GLES2 ON) +else() + set(CC_USE_GLES2 OFF) + set(CC_USE_GLES3 ON) +endif() + + +################################# external source code ################################ + + +include(${CMAKE_CURRENT_LIST_DIR}/external/CMakeLists.txt) + +################################# engine source code ################################## + +set(CWD ${CMAKE_CURRENT_LIST_DIR}) +set(COCOS2D_SOURCE_LIST) + +macro(cocos_source_files) + set(list_var "${ARGN}") + foreach(src IN LISTS list_var) + set(fp "${CWD}/${src}") + if(EXISTS ${fp}) + list(APPEND COCOS2D_SOURCE_LIST "${CWD}/${src}") + else() + message(FATAL_ERROR "Cocos souce file not exists: ${src} in ${CWD}") + endif() + endforeach() +endmacro() + + +cocos_source_files( + cocos/cocos2d.h + cocos/cocos2d.cpp +) + +##### audio +cocos_source_files( + cocos/audio/AudioEngine.cpp + cocos/audio/include/AudioEngine.h + cocos/audio/include/Export.h +) +if(WINDOWS) + cocos_source_files( + cocos/audio/win32/AudioCache.cpp + cocos/audio/win32/AudioCache.h + cocos/audio/win32/AudioDecoder.cpp + cocos/audio/win32/AudioDecoder.h + cocos/audio/win32/AudioDecoderManager.cpp + cocos/audio/win32/AudioDecoderManager.h + cocos/audio/win32/AudioDecoderMp3.cpp + cocos/audio/win32/AudioDecoderMp3.h + cocos/audio/win32/AudioDecoderOgg.cpp + cocos/audio/win32/AudioDecoderOgg.h + cocos/audio/win32/AudioEngine-win32.cpp + cocos/audio/win32/AudioEngine-win32.h + cocos/audio/win32/AudioMacros.h + cocos/audio/win32/AudioPlayer.cpp + cocos/audio/win32/AudioPlayer.h + ) +elseif(ANDROID) + cocos_source_files( + cocos/audio/android/AssetFd.cpp + cocos/audio/android/AssetFd.h + cocos/audio/android/audio.h + cocos/audio/android/AudioBufferProvider.h + cocos/audio/android/AudioDecoder.cpp + cocos/audio/android/AudioDecoder.h + cocos/audio/android/AudioDecoderMp3.cpp + cocos/audio/android/AudioDecoderMp3.h + cocos/audio/android/AudioDecoderOgg.cpp + cocos/audio/android/AudioDecoderOgg.h + cocos/audio/android/AudioDecoderProvider.cpp + cocos/audio/android/AudioDecoderProvider.h + cocos/audio/android/AudioDecoderSLES.cpp + cocos/audio/android/AudioDecoderSLES.h + cocos/audio/android/AudioDecoderWav.cpp + cocos/audio/android/AudioDecoderWav.h + cocos/audio/android/AudioEngine-inl.cpp + cocos/audio/android/AudioEngine-inl.h + cocos/audio/android/AudioMixer.cpp + cocos/audio/android/AudioMixer.h + cocos/audio/android/AudioMixerController.cpp + cocos/audio/android/AudioMixerController.h + cocos/audio/android/AudioMixerOps.h + cocos/audio/android/AudioPlayerProvider.cpp + cocos/audio/android/AudioPlayerProvider.h + cocos/audio/android/AudioResampler.cpp + cocos/audio/android/AudioResampler.h + cocos/audio/android/AudioResamplerCubic.cpp + cocos/audio/android/AudioResamplerCubic.h + cocos/audio/android/AudioResamplerPublic.h + cocos/audio/android/audio_utils/format.c + cocos/audio/android/audio_utils/include/audio_utils/format.h + cocos/audio/android/audio_utils/include/audio_utils/minifloat.h + cocos/audio/android/audio_utils/include/audio_utils/primitives.h + cocos/audio/android/audio_utils/minifloat.cpp + cocos/audio/android/audio_utils/primitives.c + cocos/audio/android/audio_utils/private/private.h + cocos/audio/android/cutils/bitops.h + cocos/audio/android/cutils/log.h + cocos/audio/android/IAudioPlayer.h + cocos/audio/android/ICallerThreadUtils.h + cocos/audio/android/IVolumeProvider.h + cocos/audio/android/mp3reader.cpp + cocos/audio/android/mp3reader.h + cocos/audio/android/OpenSLHelper.h + cocos/audio/android/PcmAudioPlayer.cpp + cocos/audio/android/PcmAudioPlayer.h + cocos/audio/android/PcmAudioService.cpp + cocos/audio/android/PcmAudioService.h + cocos/audio/android/PcmBufferProvider.cpp + cocos/audio/android/PcmBufferProvider.h + cocos/audio/android/PcmData.cpp + cocos/audio/android/PcmData.h + cocos/audio/android/tinysndfile.cpp + cocos/audio/android/tinysndfile.h + cocos/audio/android/Track.cpp + cocos/audio/android/Track.h + cocos/audio/android/UrlAudioPlayer.cpp + cocos/audio/android/UrlAudioPlayer.h + cocos/audio/android/utils/Compat.h + cocos/audio/android/utils/Errors.h + cocos/audio/android/utils/Utils.cpp + cocos/audio/android/utils/Utils.h + ) +elseif(APPLE) + cocos_source_files( + cocos/audio/apple/AudioDecoder.h + cocos/audio/apple/AudioPlayer.mm + cocos/audio/apple/AudioDecoder.mm + cocos/audio/apple/AudioPlayer.h + cocos/audio/apple/AudioEngine-inl.mm + cocos/audio/apple/AudioMacros.h + cocos/audio/apple/AudioCache.mm + cocos/audio/apple/AudioCache.h + cocos/audio/apple/AudioEngine-inl.h + ) +endif() + + +##### base +cocos_source_files( + cocos/base/base64.cpp + cocos/base/base64.h + cocos/base/CCAutoreleasePool.cpp + cocos/base/CCAutoreleasePool.h + cocos/base/ccCArray.cpp + cocos/base/ccCArray.h + cocos/base/ccConfig.h + cocos/base/CCData.cpp + cocos/base/CCData.h + cocos/base/CCLog.cpp + cocos/base/CCLog.h + cocos/base/ccMacros.h + cocos/base/CCMap.h + cocos/base/ccRandom.cpp + cocos/base/ccRandom.h + cocos/base/CCRef.cpp + cocos/base/CCRef.h + cocos/base/CCRefPtr.h + #cocos/base/CCRenderTexture.cpp + #cocos/base/CCRenderTexture.h + cocos/base/CCScheduler.cpp + cocos/base/CCScheduler.h + cocos/base/CCThreadPool.cpp + cocos/base/CCThreadPool.h + cocos/base/ccUTF8.cpp + cocos/base/ccUTF8.h + cocos/base/ccUtils.cpp + cocos/base/ccUtils.h + cocos/base/CCValue.cpp + cocos/base/CCValue.h + cocos/base/CCVector.h + cocos/base/csscolorparser.cpp + cocos/base/csscolorparser.hpp + cocos/base/etc1.cpp + cocos/base/etc1.h + cocos/base/etc2.cpp + cocos/base/etc2.h + cocos/base/pvr.cpp + cocos/base/pvr.h + cocos/base/uthash.h + cocos/base/utlist.h + cocos/base/ZipUtils.cpp + cocos/base/ZipUtils.h +) + +##### math +cocos_source_files( + cocos/math/CCGeometry.cpp + cocos/math/CCGeometry.h + cocos/math/CCMath.h + cocos/math/CCMathBase.h + cocos/math/CCVertex.cpp + cocos/math/CCVertex.h + cocos/math/Mat3.cpp + cocos/math/Mat3.hpp + cocos/math/Mat4.cpp + cocos/math/Mat4.h + cocos/math/Mat4.inl + cocos/math/MathUtil.cpp + cocos/math/MathUtil.h + cocos/math/MathUtil.inl + cocos/math/MathUtilNeon.inl + cocos/math/MathUtilNeon64.inl + cocos/math/MathUtilSSE.inl + cocos/math/Quaternion.cpp + cocos/math/Quaternion.h + cocos/math/Quaternion.inl + cocos/math/Vec2.cpp + cocos/math/Vec2.h + cocos/math/Vec2.inl + cocos/math/Vec3.cpp + cocos/math/Vec3.h + cocos/math/Vec3.inl + cocos/math/Vec4.cpp + cocos/math/Vec4.h + cocos/math/Vec4.inl +) + +##### network +cocos_source_files( + cocos/network/CCDownloader.cpp + cocos/network/CCDownloader.h + cocos/network/CCIDownloaderImpl.h + cocos/network/HttpClient.h + cocos/network/HttpCookie.cpp + cocos/network/HttpCookie.h + cocos/network/HttpRequest.h + cocos/network/HttpResponse.h + cocos/network/SocketIO.cpp + cocos/network/SocketIO.h + cocos/network/Uri.cpp + cocos/network/Uri.h + cocos/network/WebSocket.h + ) + +if(APPLE) + cocos_source_files( + cocos/network/CCDownloaderImpl-apple.h + cocos/network/CCDownloaderImpl-apple.mm + cocos/network/HttpAsynConnection-apple.h + cocos/network/HttpAsynConnection-apple.m + cocos/network/HttpClient-apple.mm + cocos/network/WebSocket-apple.mm + cocos/network/WebSocket-apple.mm + ) + set_source_files_properties(${CWD}/cocos/network/WebSocket-apple.mm PROPERTIES + COMPILE_FLAGS -fobjc-arc + ) +endif() + +if(ANDROID) + cocos_source_files( + cocos/network/CCDownloader-android.cpp + cocos/network/CCDownloader-android.h + cocos/network/HttpClient-android.cpp + ) +endif() + +if(NOT APPLE) + cocos_source_files( + cocos/network/WebSocket-libwebsockets.cpp + ) +endif() + +if(WINDOWS) + cocos_source_files( + cocos/network/CCDownloader-curl.cpp + cocos/network/CCDownloader-curl.h + ) +endif() + +if(WINDOWS OR MACOSX) + cocos_source_files( + cocos/network/HttpClient.cpp + ) +endif() + + +##### platform +cocos_source_files( + cocos/platform/CCApplication.h + cocos/platform/CCCanvasRenderingContext2D.h + cocos/platform/CCDevice.h + cocos/platform/CCFileUtils.cpp + cocos/platform/CCFileUtils.h + cocos/platform/CCImage.cpp + cocos/platform/CCImage.h + cocos/platform/CCPlatformConfig.h + cocos/platform/CCPlatformDefine.h + cocos/platform/CCSAXParser.cpp + cocos/platform/CCSAXParser.h + cocos/platform/CCStdC.h +) +if(WINDOWS) + cocos_source_files( + cocos/platform/win32/CCApplication-win32.cpp + cocos/platform/win32/CCCanvasRenderingContext2D-win32.cpp + cocos/platform/win32/CCDevice-win32.cpp + cocos/platform/win32/CCFileUtils-win32.cpp + cocos/platform/win32/CCFileUtils-win32.h + cocos/platform/win32/CCPlatformDefine-win32.h + cocos/platform/win32/CCUtils-win32.cpp + cocos/platform/win32/CCUtils-win32.h + cocos/platform/win32/View-win32.cpp + cocos/platform/win32/View-win32.h + cocos/platform/win32/compat + cocos/platform/win32/compat/stdint.h + cocos/platform/win32/inet_pton_mingw.cpp + cocos/platform/win32/inet_pton_mingw.h + ) +elseif(ANDROID) + cocos_source_files( + cocos/platform/android/CCApplication-android.cpp + cocos/platform/android/CCCanvasRenderingContext2D-android.cpp + cocos/platform/android/CCDevice-android.cpp + cocos/platform/android/CCFileUtils-android.cpp + cocos/platform/android/CCFileUtils-android.h + cocos/platform/android/CCPlatformDefine-android.h + cocos/platform/android/CCView.cpp + cocos/platform/android/CCView.h + cocos/platform/android/jni/JniHelper.cpp + cocos/platform/android/jni/JniHelper.h + cocos/platform/android/jni/JniImp.cpp + cocos/platform/android/jni/JniImp.h + ) +elseif(APPLE) + cocos_source_files( + cocos/platform/apple/CCFileUtils-apple.h + cocos/platform/apple/CCDevice-apple.mm + cocos/platform/apple/CCFileUtils-apple.mm + cocos/platform/apple/CCCanvasRenderingContext2D-apple.mm + cocos/platform/apple/CCDevice-apple.h + ) + #bad struct + cocos_source_files( + cocos/platform/ios/CCReachability.h + cocos/platform/ios/CCReachability.cpp + ) + if(MACOSX) + cocos_source_files( + cocos/platform/mac/CCView.h + cocos/platform/mac/CCKeyCodeHelper.h + cocos/platform/mac/CCView.mm + cocos/platform/mac/CCModuleConfigMac.debug.xcconfig + cocos/platform/mac/cocos2d-prefix.pch + cocos/platform/mac/CCPlatformDefine-mac.h + cocos/platform/mac/CCDevice-mac.mm + cocos/platform/mac/CCApplication-mac.mm + cocos/platform/mac/CCModuleConfigMac.release.xcconfig + cocos/platform/mac/CCKeyCodeHelper.cpp + ) + elseif(IOS) + cocos_source_files( + cocos/platform/ios/CCView.h + cocos/platform/ios/CCView.mm + cocos/platform/ios/CCApplication-ios.mm + cocos/platform/ios/cocos2d-prefix.pch + cocos/platform/ios/CCDevice-ios.mm + cocos/platform/ios/CCPlatformDefine-ios.h + cocos/platform/ios/CCImage-ios.mm + ) + endif() +endif() + +##### renderer +cocos_source_files( + cocos/renderer/core/Core.h + cocos/renderer/core/CoreDef.h + cocos/renderer/core/CoreStd.cc + cocos/renderer/core/CoreStd.h + cocos/renderer/core/gfx/GFXObject.h + cocos/renderer/core/gfx/GFXObject.cc + cocos/renderer/core/gfx/GFXBindingLayout.cc + cocos/renderer/core/gfx/GFXBindingLayout.h + cocos/renderer/core/gfx/GFXBuffer.cc + cocos/renderer/core/gfx/GFXBuffer.h + cocos/renderer/core/gfx/GFXCommand.h + cocos/renderer/core/gfx/GFXCommandAllocator.cc + cocos/renderer/core/gfx/GFXCommandAllocator.h + cocos/renderer/core/gfx/GFXCommandBuffer.cc + cocos/renderer/core/gfx/GFXCommandBuffer.h + cocos/renderer/core/gfx/GFXCommandPool.h + cocos/renderer/core/gfx/GFXContext.cc + cocos/renderer/core/gfx/GFXContext.h + cocos/renderer/core/gfx/GFXDef.cc + cocos/renderer/core/gfx/GFXDef.h + cocos/renderer/core/gfx/GFXDevice.cc + cocos/renderer/core/gfx/GFXDevice.h + cocos/renderer/core/gfx/GFXFramebuffer.cc + cocos/renderer/core/gfx/GFXFramebuffer.h + cocos/renderer/core/gfx/GFXInputAssembler.cc + cocos/renderer/core/gfx/GFXInputAssembler.h + cocos/renderer/core/gfx/GFXPipelineLayout.cc + cocos/renderer/core/gfx/GFXPipelineLayout.h + cocos/renderer/core/gfx/GFXPipelineState.cc + cocos/renderer/core/gfx/GFXPipelineState.h + cocos/renderer/core/gfx/GFXQueue.cc + cocos/renderer/core/gfx/GFXQueue.h + cocos/renderer/core/gfx/GFXRenderPass.cc + cocos/renderer/core/gfx/GFXRenderPass.h + cocos/renderer/core/gfx/GFXSampler.cc + cocos/renderer/core/gfx/GFXSampler.h + cocos/renderer/core/gfx/GFXShader.cc + cocos/renderer/core/gfx/GFXShader.h + cocos/renderer/core/gfx/GFXTexture.cc + cocos/renderer/core/gfx/GFXTexture.h + cocos/renderer/core/gfx/GFXTextureView.cc + cocos/renderer/core/gfx/GFXTextureView.h + cocos/renderer/core/gfx/GFXWindow.cc + cocos/renderer/core/gfx/GFXWindow.h + cocos/renderer/core/kernel/Assertion.cc + cocos/renderer/core/kernel/Assertion.h + cocos/renderer/core/kernel/CachedArray.h + cocos/renderer/core/kernel/Log.cc + cocos/renderer/core/kernel/Log.h + cocos/renderer/core/kernel/Object.h + cocos/renderer/core/kernel/UTFString.cc + cocos/renderer/core/kernel/UTFString.h + cocos/renderer/core/math/CCCoreMath.cc + cocos/renderer/core/math/CCCoreMath.h + cocos/renderer/core/memory/AllocatedObj.cc + cocos/renderer/core/memory/AllocatedObj.h + cocos/renderer/core/memory/JeAlloc.cc + cocos/renderer/core/memory/JeAlloc.h + cocos/renderer/core/memory/MemDef.h + cocos/renderer/core/memory/Memory.cc + cocos/renderer/core/memory/Memory.h + cocos/renderer/core/memory/MemTracker.cc + cocos/renderer/core/memory/MemTracker.h + cocos/renderer/core/memory/NedPooling.cc + cocos/renderer/core/memory/NedPooling.h + cocos/renderer/core/memory/StdAlloc.h + cocos/renderer/core/memory/StlAlloc.h + cocos/renderer/core/TypeDef.h + cocos/renderer/core/util/StringUtil.cc + cocos/renderer/core/util/StringUtil.h +) + +if(CC_USE_GLES2) + cocos_source_files( + cocos/renderer/gfx-gles2/GFXGLES2.h + cocos/renderer/gfx-gles2/GLES2BindingLayout.cc + cocos/renderer/gfx-gles2/GLES2BindingLayout.h + cocos/renderer/gfx-gles2/GLES2Buffer.cc + cocos/renderer/gfx-gles2/GLES2Buffer.h + cocos/renderer/gfx-gles2/GLES2CommandAllocator.cc + cocos/renderer/gfx-gles2/GLES2CommandAllocator.h + cocos/renderer/gfx-gles2/GLES2CommandBuffer.cc + cocos/renderer/gfx-gles2/GLES2CommandBuffer.h + cocos/renderer/gfx-gles2/GLES2Commands.cc + cocos/renderer/gfx-gles2/GLES2Commands.h + cocos/renderer/gfx-gles2/GLES2Context.h + cocos/renderer/gfx-gles2/GLES2Device.cc + cocos/renderer/gfx-gles2/GLES2Device.h + cocos/renderer/gfx-gles2/GLES2Framebuffer.cc + cocos/renderer/gfx-gles2/GLES2Framebuffer.h + cocos/renderer/gfx-gles2/GLES2GPUObjects.h + cocos/renderer/gfx-gles2/GLES2InputAssembler.cc + cocos/renderer/gfx-gles2/GLES2InputAssembler.h + cocos/renderer/gfx-gles2/GLES2PipelineLayout.cc + cocos/renderer/gfx-gles2/GLES2PipelineLayout.h + cocos/renderer/gfx-gles2/GLES2PipelineState.cc + cocos/renderer/gfx-gles2/GLES2PipelineState.h + cocos/renderer/gfx-gles2/GLES2Queue.cc + cocos/renderer/gfx-gles2/GLES2Queue.h + cocos/renderer/gfx-gles2/GLES2RenderPass.cc + cocos/renderer/gfx-gles2/GLES2RenderPass.h + cocos/renderer/gfx-gles2/GLES2Sampler.cc + cocos/renderer/gfx-gles2/GLES2Sampler.h + cocos/renderer/gfx-gles2/GLES2Shader.cc + cocos/renderer/gfx-gles2/GLES2Shader.h + cocos/renderer/gfx-gles2/GLES2StateCache.h + cocos/renderer/gfx-gles2/GLES2Std.cc + cocos/renderer/gfx-gles2/GLES2Std.h + cocos/renderer/gfx-gles2/GLES2Texture.cc + cocos/renderer/gfx-gles2/GLES2Texture.h + cocos/renderer/gfx-gles2/GLES2TextureView.cc + cocos/renderer/gfx-gles2/GLES2TextureView.h + cocos/renderer/gfx-gles2/gles2w.h + cocos/renderer/gfx-gles2/GLES2Window.cc + cocos/renderer/gfx-gles2/GLES2Window.h + ) + + if(APPLE) + cocos_source_files( + cocos/renderer/gfx-gles2/GLES2Context.mm + cocos/renderer/gfx-gles2/gles2w.mm + ) + else() + cocos_source_files( + cocos/renderer/gfx-gles2/GLES2Context.cc + cocos/renderer/gfx-gles2/gles2w.c + ) + endif() + +endif() + +if(CC_USE_GLES3) + cocos_source_files( + cocos/renderer/gfx-gles3/GFXGLES3.h + cocos/renderer/gfx-gles3/GLES3BindingLayout.cc + cocos/renderer/gfx-gles3/GLES3BindingLayout.h + cocos/renderer/gfx-gles3/GLES3Buffer.cc + cocos/renderer/gfx-gles3/GLES3Buffer.h + cocos/renderer/gfx-gles3/GLES3CommandAllocator.cc + cocos/renderer/gfx-gles3/GLES3CommandAllocator.h + cocos/renderer/gfx-gles3/GLES3CommandBuffer.cc + cocos/renderer/gfx-gles3/GLES3CommandBuffer.h + cocos/renderer/gfx-gles3/GLES3Commands.cc + cocos/renderer/gfx-gles3/GLES3Commands.h + cocos/renderer/gfx-gles3/GLES3Context.cc + cocos/renderer/gfx-gles3/GLES3Context.h + cocos/renderer/gfx-gles3/GLES3Device.cc + cocos/renderer/gfx-gles3/GLES3Device.h + cocos/renderer/gfx-gles3/GLES3Framebuffer.cc + cocos/renderer/gfx-gles3/GLES3Framebuffer.h + cocos/renderer/gfx-gles3/GLES3GPUObjects.h + cocos/renderer/gfx-gles3/GLES3InputAssembler.cc + cocos/renderer/gfx-gles3/GLES3InputAssembler.h + cocos/renderer/gfx-gles3/GLES3PipelineLayout.cc + cocos/renderer/gfx-gles3/GLES3PipelineLayout.h + cocos/renderer/gfx-gles3/GLES3PipelineState.cc + cocos/renderer/gfx-gles3/GLES3PipelineState.h + cocos/renderer/gfx-gles3/GLES3Queue.cc + cocos/renderer/gfx-gles3/GLES3Queue.h + cocos/renderer/gfx-gles3/GLES3RenderPass.cc + cocos/renderer/gfx-gles3/GLES3RenderPass.h + cocos/renderer/gfx-gles3/GLES3Sampler.cc + cocos/renderer/gfx-gles3/GLES3Sampler.h + cocos/renderer/gfx-gles3/GLES3Shader.cc + cocos/renderer/gfx-gles3/GLES3Shader.h + cocos/renderer/gfx-gles3/GLES3StateCache.h + cocos/renderer/gfx-gles3/GLES3Std.cc + cocos/renderer/gfx-gles3/GLES3Std.h + cocos/renderer/gfx-gles3/GLES3Texture.cc + cocos/renderer/gfx-gles3/GLES3Texture.h + cocos/renderer/gfx-gles3/GLES3TextureView.cc + cocos/renderer/gfx-gles3/GLES3TextureView.h + cocos/renderer/gfx-gles3/gles3w.h + cocos/renderer/gfx-gles3/GLES3Window.cc + cocos/renderer/gfx-gles3/GLES3Window.h + ) + if(APPLE) + cocos_source_files( + cocos/renderer/gfx-gles3/gles3w.mm + ) + else() + cocos_source_files( + cocos/renderer/gfx-gles3/gles3w.c + ) + endif() + if(IOS) + cocos_source_files( + cocos/renderer/gfx-gles3/GLES3Context.mm + ) + endif() +endif() + +##### script bindings +######## auto +cocos_source_files( + cocos/scripting/js-bindings/auto/jsb_cocos2dx_audioengine_auto.cpp + cocos/scripting/js-bindings/auto/jsb_cocos2dx_audioengine_auto.hpp + cocos/scripting/js-bindings/auto/jsb_cocos2dx_auto.cpp + cocos/scripting/js-bindings/auto/jsb_cocos2dx_auto.hpp + cocos/scripting/js-bindings/auto/jsb_cocos2dx_extension_auto.cpp + cocos/scripting/js-bindings/auto/jsb_cocos2dx_extension_auto.hpp + cocos/scripting/js-bindings/auto/jsb_cocos2dx_network_auto.cpp + cocos/scripting/js-bindings/auto/jsb_cocos2dx_network_auto.hpp + cocos/scripting/js-bindings/auto/jsb_gfx_auto.cpp + cocos/scripting/js-bindings/auto/jsb_gfx_auto.hpp + cocos/scripting/js-bindings/auto/jsb_video_auto.cpp + cocos/scripting/js-bindings/auto/jsb_video_auto.hpp + cocos/scripting/js-bindings/auto/jsb_webview_auto.cpp + cocos/scripting/js-bindings/auto/jsb_webview_auto.hpp +) +######## manual +cocos_source_files( + cocos/scripting/js-bindings/manual/jsb_classtype.cpp + cocos/scripting/js-bindings/manual/jsb_classtype.hpp + #cocos/scripting/js-bindings/manual/jsb_cocos2dx_extension_manual.cpp + #cocos/scripting/js-bindings/manual/jsb_cocos2dx_extension_manual.hpp + cocos/scripting/js-bindings/manual/jsb_cocos2dx_manual.cpp + cocos/scripting/js-bindings/manual/jsb_cocos2dx_manual.hpp + cocos/scripting/js-bindings/manual/jsb_cocos2dx_network_manual.cpp + cocos/scripting/js-bindings/manual/jsb_cocos2dx_network_manual.h + cocos/scripting/js-bindings/manual/jsb_conversions.cpp + cocos/scripting/js-bindings/manual/jsb_conversions.hpp + cocos/scripting/js-bindings/manual/jsb_gfx_manual.cpp + cocos/scripting/js-bindings/manual/jsb_gfx_manual.hpp + cocos/scripting/js-bindings/manual/jsb_global.cpp + cocos/scripting/js-bindings/manual/jsb_global.h + cocos/scripting/js-bindings/manual/jsb_helper.cpp + cocos/scripting/js-bindings/manual/jsb_helper.hpp + # cocos/scripting/js-bindings/manual/jsb_module_register.cpp + cocos/scripting/js-bindings/manual/jsb_module_register.hpp + cocos/scripting/js-bindings/manual/jsb_platform.h + cocos/scripting/js-bindings/manual/jsb_socketio.cpp + cocos/scripting/js-bindings/manual/jsb_socketio.hpp + cocos/scripting/js-bindings/manual/jsb_websocket.cpp + cocos/scripting/js-bindings/manual/jsb_websocket.hpp + cocos/scripting/js-bindings/manual/jsb_xmlhttprequest.cpp + cocos/scripting/js-bindings/manual/jsb_xmlhttprequest.hpp +) + +if(ANDROID) + cocos_source_files( + cocos/scripting/js-bindings/manual/jsb_platform_android.cpp + cocos/scripting/js-bindings/manual/JavaScriptJavaBridge.cpp + cocos/scripting/js-bindings/manual/JavaScriptJavaBridge.h + ) +elseif(APPLE) + cocos_source_files( + cocos/scripting/js-bindings/manual/jsb_platfrom_apple.mm + cocos/scripting/js-bindings/manual/JavaScriptObjCBridge.h + cocos/scripting/js-bindings/manual/JavaScriptObjCBridge.mm + ) +elseif(WIN32) + cocos_source_files( + cocos/scripting/js-bindings/manual/jsb_platfrom_win32.cpp + ) +endif() + +if(CC_USE_GLES2) + cocos_source_files( + cocos/scripting/js-bindings/auto/jsb_gles2_auto.hpp + cocos/scripting/js-bindings/auto/jsb_gles2_auto.cpp + ) +endif() +if(CC_USE_GLES3) + cocos_source_files( + cocos/scripting/js-bindings/auto/jsb_gles3_auto.hpp + cocos/scripting/js-bindings/auto/jsb_gles3_auto.cpp + ) +endif() + +if(USE_SE_V8) + cocos_source_files( + cocos/scripting/js-bindings/jswrapper/v8/Base.h + cocos/scripting/js-bindings/jswrapper/v8/Class.cpp + cocos/scripting/js-bindings/jswrapper/v8/Class.hpp + cocos/scripting/js-bindings/jswrapper/v8/HelperMacros.h + cocos/scripting/js-bindings/jswrapper/v8/Object.cpp + cocos/scripting/js-bindings/jswrapper/v8/Object.hpp + cocos/scripting/js-bindings/jswrapper/v8/ObjectWrap.cpp + cocos/scripting/js-bindings/jswrapper/v8/ObjectWrap.h + cocos/scripting/js-bindings/jswrapper/v8/ScriptEngine.cpp + cocos/scripting/js-bindings/jswrapper/v8/ScriptEngine.hpp + cocos/scripting/js-bindings/jswrapper/v8/SeApi.h + cocos/scripting/js-bindings/jswrapper/v8/Utils.cpp + cocos/scripting/js-bindings/jswrapper/v8/Utils.hpp + ) + if(USE_V8_DEBUGGER) + cocos_source_files( + cocos/scripting/js-bindings/jswrapper/v8/debugger/base64.h + cocos/scripting/js-bindings/jswrapper/v8/debugger/env.cc + cocos/scripting/js-bindings/jswrapper/v8/debugger/env.h + cocos/scripting/js-bindings/jswrapper/v8/debugger/http_parser.c + cocos/scripting/js-bindings/jswrapper/v8/debugger/http_parser.h + cocos/scripting/js-bindings/jswrapper/v8/debugger/inspector_agent.cc + cocos/scripting/js-bindings/jswrapper/v8/debugger/inspector_agent.h + cocos/scripting/js-bindings/jswrapper/v8/debugger/inspector_io.cc + cocos/scripting/js-bindings/jswrapper/v8/debugger/inspector_io.h + cocos/scripting/js-bindings/jswrapper/v8/debugger/inspector_socket.cc + cocos/scripting/js-bindings/jswrapper/v8/debugger/inspector_socket.h + cocos/scripting/js-bindings/jswrapper/v8/debugger/inspector_socket_server.cc + cocos/scripting/js-bindings/jswrapper/v8/debugger/inspector_socket_server.h + cocos/scripting/js-bindings/jswrapper/v8/debugger/node.cc + cocos/scripting/js-bindings/jswrapper/v8/debugger/node.h + cocos/scripting/js-bindings/jswrapper/v8/debugger/node_debug_options.cc + cocos/scripting/js-bindings/jswrapper/v8/debugger/node_debug_options.h + cocos/scripting/js-bindings/jswrapper/v8/debugger/node_mutex.h + cocos/scripting/js-bindings/jswrapper/v8/debugger/SHA1.cpp + cocos/scripting/js-bindings/jswrapper/v8/debugger/SHA1.h + cocos/scripting/js-bindings/jswrapper/v8/debugger/util-inl.h + cocos/scripting/js-bindings/jswrapper/v8/debugger/util.cc + cocos/scripting/js-bindings/jswrapper/v8/debugger/util.h + cocos/scripting/js-bindings/jswrapper/v8/debugger/v8_inspector_protocol_json.h + ) + endif() +endif() + +if(USE_SE_JSC) + cocos_source_files( + cocos/scripting/js-bindings/jswrapper/jsc/Class.hpp + cocos/scripting/js-bindings/jswrapper/jsc/EJConvert.h + cocos/scripting/js-bindings/jswrapper/jsc/HelperMacros.h + cocos/scripting/js-bindings/jswrapper/jsc/Utils.cpp + cocos/scripting/js-bindings/jswrapper/jsc/EJConvertTypedArray.h + cocos/scripting/js-bindings/jswrapper/jsc/PlatformUtils.h + cocos/scripting/js-bindings/jswrapper/jsc/EJConvertTypedArray.m + cocos/scripting/js-bindings/jswrapper/jsc/EJConvert.m + cocos/scripting/js-bindings/jswrapper/jsc/Object.hpp + cocos/scripting/js-bindings/jswrapper/jsc/Object.mm + cocos/scripting/js-bindings/jswrapper/jsc/ScriptEngine.hpp + cocos/scripting/js-bindings/jswrapper/jsc/ScriptEngine.mm + cocos/scripting/js-bindings/jswrapper/jsc/PlatformUtils.mm + cocos/scripting/js-bindings/jswrapper/jsc/SeApi.h + cocos/scripting/js-bindings/jswrapper/jsc/Class.cpp + cocos/scripting/js-bindings/jswrapper/jsc/Utils.hpp + cocos/scripting/js-bindings/jswrapper/jsc/Base.h + ) +endif() + +cocos_source_files( + cocos/scripting/js-bindings/jswrapper/config.cpp + cocos/scripting/js-bindings/jswrapper/config.hpp + cocos/scripting/js-bindings/jswrapper/HandleObject.cpp + cocos/scripting/js-bindings/jswrapper/HandleObject.hpp + cocos/scripting/js-bindings/jswrapper/MappingUtils.cpp + cocos/scripting/js-bindings/jswrapper/MappingUtils.hpp + cocos/scripting/js-bindings/jswrapper/Object.hpp + cocos/scripting/js-bindings/jswrapper/RefCounter.cpp + cocos/scripting/js-bindings/jswrapper/RefCounter.hpp + cocos/scripting/js-bindings/jswrapper/SeApi.h + cocos/scripting/js-bindings/jswrapper/State.cpp + cocos/scripting/js-bindings/jswrapper/State.hpp + cocos/scripting/js-bindings/jswrapper/Value.cpp + cocos/scripting/js-bindings/jswrapper/Value.hpp +) + +cocos_source_files( + cocos/scripting/js-bindings/event/CustomEventTypes.h + cocos/scripting/js-bindings/event/EventDispatcher.cpp + cocos/scripting/js-bindings/event/EventDispatcher.h +) + +#### storage +cocos_source_files( + cocos/storage/local-storage/LocalStorage.cpp + cocos/storage/local-storage/LocalStorage.h +) + +if(ANDROID) + cocos_source_files( + cocos/storage/local-storage/LocalStorage-android.cpp + ) +endif() + +#### ui +cocos_source_files( + cocos/ui/edit-box/EditBox.h +) + +if(ANDROID OR IOS) + if(USE_WEBVIEW) + cocos_source_files( + cocos/ui/videoplayer/VideoPlayer.h + ) + endif() + if(USE_VIDEOPLAYER) + cocos_source_files( + cocos/ui/webview/WebView-inl.h + cocos/ui/webview/WebView.h + ) + endif() +endif() + +if(ANDROID) + cocos_source_files( + cocos/ui/edit-box/EditBox-android.cpp + ) + if(USE_VIDEOPLAYER) + cocos_source_files( + cocos/ui/videoplayer/VideoPlayer-android.cpp + ) + endif() + if(USE_WEBVIEW) + cocos_source_files( + cocos/ui/webview/WebViewImpl-android.cpp + cocos/ui/webview/WebViewImpl-android.h + ) + endif() +elseif(MACOSX) + cocos_source_files( + cocos/ui/edit-box/EditBox-mac.mm + ) +elseif(IOS) + cocos_source_files( + cocos/ui/edit-box/EditBox-ios.mm + ) + if(USE_VIDEOPLAYER) + cocos_source_files( + cocos/ui/videoplayer/VideoPlayer-ios.mm + ) + endif() + if(USE_WEBVIEW) + cocos_source_files( + cocos/ui/webview/WebViewImpl-ios.h + cocos/ui/webview/WebViewImpl-ios.mm + ) + endif() +elseif(WIN32) + cocos_source_files( + cocos/ui/edit-box/EditBox-win32.cpp + ) +endif() + +##### extensions + +cocos_source_files( + extensions/assets-manager/AssetsManagerEx.cpp + extensions/assets-manager/AssetsManagerEx.h + extensions/assets-manager/CCAsyncTaskPool.cpp + extensions/assets-manager/CCAsyncTaskPool.h + extensions/assets-manager/CCEventAssetsManagerEx.cpp + extensions/assets-manager/CCEventAssetsManagerEx.h + extensions/assets-manager/Manifest.cpp + extensions/assets-manager/Manifest.h + extensions/cocos-ext.h + extensions/ExtensionExport.h + extensions/ExtensionMacros.h +) + +list(APPEND COCOS2D_SOURCE_LIST ${CC_EXTERNAL_SROUCES}) + +add_library(cocos2d ${COCOS2D_SOURCE_LIST}) + +# setup default flags +target_compile_definitions(cocos2d PUBLIC + $<$>:USE_VIDEO=0> + $<$>:USE_WEB_VIEW=0> + $<$>:USE_AUDIO=0> + $<$>:USE_SOCKET=0> + $<$>:CC_USE_TIFF=0> + $<$>:USE_V8_DEBUGGER=0> + $<$:SCRIPT_ENGINE_TYPE=3> + $<$:COCOS2D_DEBUG=1> +) + + + +target_include_directories(cocos2d PUBLIC + ${CC_EXTERNAL_INCLUDES} + ${CWD} + ${CWD}/cocos + ${CWD}/cocos/renderer + ${CWD}/cocos/platform + ${CWD}/cocos/renderer/core + ${CWD}/external/sources/khronos + $<$:${CWD}/cocos/scripting/js-bindings/jswrapper> +) + +if(WIN32) + target_link_libraries(cocos2d PUBLIC + ws2_32 userenv psapi winmm Version Iphlpapi opengl32 + ${CC_EXTERNAL_LIBS} + ) + + target_compile_definitions(cocos2d PUBLIC + CC_STATIC + WIN32 + _WIN32 + _WINDOWS + UNICODE + _UNICODE + _CRT_SECURE_NO_WARNINGS + _SCL_SECURE_NO_WARNINGS + _USRLIBSIMSTATIC + SE_ENABLE_INSPECTOR + ) + +endif() + +if(ANDROID) + find_library(LIB_EGL NAMES EGL) + find_library(LIB_GLESv2 NAMES GLESv2) + target_link_libraries(cocos2d PUBLIC + android + log + OpenSLES + ${LIB_EGL} + ${LIB_GLESv2} + GLESv2 + ${CC_EXTERNAL_LIBS} + ) +endif() + +if(APPLE) + + target_compile_options(cocos2d PRIVATE + -Wno-objc-method-access + ) + + target_include_directories(cocos2d PUBLIC + ${CWD}/cocos/platform/ios + ) + find_library(ICONV_LIBRARY iconv) + find_library(AUDIOTOOLBOX_LIBRARY AudioToolBox) + find_library(FOUNDATION_LIBRARY Foundation) + find_library(OPENAL_LIBRARY OpenAL) + find_library(GAMECONTROLLER_LIBRARY GameController) + find_library(METAL_LIBRARY Metal) + find_library(METALLIT_LIBRARY MetalKit) + find_library(SQLITE3_LIBRARY SQLite3) + find_library(SECURITY_LIBRARY Security) + find_library(SystemConfiguration_LIBRARY SystemConfiguration) + target_link_libraries(cocos2d PUBLIC + ${ICONV_LIBRARY} + ${AUDIOTOOLBOX_LIBRARY} + ${FOUNDATION_LIBRARY} + ${OPENAL_LIBRARY} + ${GAMECONTROLLER_LIBRARY} + ${METAL_LIBRARY} + ${METALLIT_LIBRARY} + ${SQLITE3_LIBRARY} + ${SECURITY_LIBRARY} + ${SystemConfiguration_LIBRARY} + ${CC_EXTERNAL_LIBS} + ) + if(MACOSX) + find_library(OPENGL_LIBRARY OpenGL) + find_library(APPKIT_LIBRARY AppKit) + target_link_libraries(cocos2d PUBLIC + ${OPENGL_LIBRARY} + ${APPKIT_LIBRARY} + ) + target_compile_definitions(cocos2d PUBLIC + CC_KEYBOARD_SUPPORT + ) + elseif(IOS) + find_library(QUARTZCORE_LIBRARY QuartzCore) + find_library(UIKIT_LIBRARY UIKit) + find_library(CORE_MOTION_LIBRARY CoreMotion) + find_library(CFNETWORK_LIBRARY CFNetwork) + find_library(CORE_MEDIA_LIBRARY CoreMedia) + find_library(CORE_TEXT_LIBRARY CoreText) + find_library(CORE_GRAPHICS_LIBRARY CoreGraphics) + find_library(AV_FOUNDATION_LIBRARY AVFoundation) + find_library(ZLIB_LIBRARY z) + find_library(OPENGLES_LIBRARY OpenGLES) + find_library(JAVASCRIPTCORE_LIBRARY JavaScriptCore) + target_link_libraries(cocos2d PUBLIC + ${QUARTZCORE_LIBRARY} + ${UIKIT_LIBRARY} + ${CFNETWORK_LIBRARY} + ${ZLIB_LIBRARY} + ${CORE_GRAPHICS_LIBRARY} + ${AV_FOUNDATION_LIBRARY} + ${CORE_TEXT_LIBRARY} + ${CORE_MOTION_LIBRARY} + ${OPENGLES_LIBRARY} + ${JAVASCRIPTCORE_LIBRARY} + ) + set_property(TARGET cocos2d PROPERTY XCODE_ATTRIBUTE_IPHONEOS_DEPLOYMENT_TARGET ${TARGET_IOS_VERSION}) + set_property(TARGET cocos2d PROPERTY XCODE_ATTRIBUTE_ENABLE_BITCODE "NO") + set_property(TARGET cocos2d PROPERTY XCODE_ATTRIBUTE_ONLY_ACTIVE_ARCH "YES") + endif() + +endif() + +source_group(TREE ${CWD} PREFIX "Source Files" FILES ${COCOS2D_SOURCE_LIST}) + + +if(MSVC) + file(GLOB_RECURSE WIN32_DLLS + ${CWD}/external/win32/libs/*.dll + ${CWD}/external/win32/libs/Debug/*.dll + ) + target_compile_options(cocos2d PUBLIC /MP) +endif() \ No newline at end of file diff --git a/native/cocos/audio/AudioEngine.cpp b/native/cocos/audio/AudioEngine.cpp index b677a666ce..3a3c46cfeb 100644 --- a/native/cocos/audio/AudioEngine.cpp +++ b/native/cocos/audio/AudioEngine.cpp @@ -244,8 +244,9 @@ int AudioEngine::play2d(const std::string& filePath, bool loop, float volume, co break; } if (profileHelper->profile.minDelay > TIME_DELAY_PRECISION) { - auto currTime = utils::gettime(); - if (profileHelper->lastPlayTime > TIME_DELAY_PRECISION && currTime - profileHelper->lastPlayTime <= profileHelper->profile.minDelay) { + auto currTime = std::chrono::high_resolution_clock::now(); + auto delay =(float)std::chrono::duration_cast(currTime - profileHelper->lastPlayTime).count() / 1000000.0; + if (profileHelper->lastPlayTime.time_since_epoch().count() != 0 && delay <= profileHelper->profile.minDelay) { log("Fail to play %s cause by limited minimum delay",filePath.c_str()); break; } @@ -271,7 +272,7 @@ int AudioEngine::play2d(const std::string& filePath, bool loop, float volume, co audioRef.filePath = &it->first; if (profileHelper) { - profileHelper->lastPlayTime = utils::gettime(); + profileHelper->lastPlayTime = std::chrono::high_resolution_clock::now(); profileHelper->audioIDs.push_back(ret); } audioRef.profileHelper = profileHelper; diff --git a/native/cocos/audio/apple/AudioEngine-inl.h b/native/cocos/audio/apple/AudioEngine-inl.h index 935e07e1be..ca1efe3023 100644 --- a/native/cocos/audio/apple/AudioEngine-inl.h +++ b/native/cocos/audio/apple/AudioEngine-inl.h @@ -30,6 +30,7 @@ #define __AUDIO_ENGINE_INL_H_ #include +#include #include "base/CCRef.h" #include "audio/apple/AudioCache.h" diff --git a/native/cocos/audio/apple/AudioEngine-inl.mm b/native/cocos/audio/apple/AudioEngine-inl.mm index 247f7cdc50..73396dcea3 100644 --- a/native/cocos/audio/apple/AudioEngine-inl.mm +++ b/native/cocos/audio/apple/AudioEngine-inl.mm @@ -32,6 +32,9 @@ #import #import +#if CC_PLATFORM == CC_PLATFORM_MAC_IOS +#import +#endif #include "audio/include/AudioEngine.h" #include "platform/CCFileUtils.h" diff --git a/native/cocos/audio/apple/AudioMacros.h b/native/cocos/audio/apple/AudioMacros.h index e96a0ee1c0..429c4ac294 100644 --- a/native/cocos/audio/apple/AudioMacros.h +++ b/native/cocos/audio/apple/AudioMacros.h @@ -44,7 +44,7 @@ #if defined(COCOS2D_DEBUG) && COCOS2D_DEBUG > 0 #define CHECK_AL_ERROR_DEBUG() \ do { \ - GLenum __error = alGetError(); \ + ALenum __error = alGetError(); \ if (__error) { \ ALOGE("OpenAL error 0x%04X in %s %s %d\n", __error, __FILE__, __FUNCTION__, __LINE__); \ } \ diff --git a/native/cocos/audio/include/AudioEngine.h b/native/cocos/audio/include/AudioEngine.h index f16aac37ad..7cd75259ea 100644 --- a/native/cocos/audio/include/AudioEngine.h +++ b/native/cocos/audio/include/AudioEngine.h @@ -36,6 +36,7 @@ #include #include #include +#include #ifdef ERROR #undef ERROR @@ -327,10 +328,9 @@ protected: std::list audioIDs; - double lastPlayTime; + std::chrono::steady_clock::time_point lastPlayTime; ProfileHelper() - : lastPlayTime(0.0) { } diff --git a/native/cocos/audio/win32/AudioCache.h b/native/cocos/audio/win32/AudioCache.h index a576ba18b2..b884b6cb2d 100644 --- a/native/cocos/audio/win32/AudioCache.h +++ b/native/cocos/audio/win32/AudioCache.h @@ -33,6 +33,7 @@ #include #include #include +#include #ifdef OPENAL_PLAIN_INCLUDES #include #else diff --git a/native/cocos/audio/win32/AudioPlayer.h b/native/cocos/audio/win32/AudioPlayer.h index 7ded81c2b0..32c4a91748 100644 --- a/native/cocos/audio/win32/AudioPlayer.h +++ b/native/cocos/audio/win32/AudioPlayer.h @@ -33,6 +33,7 @@ #include #include #include +#include #ifdef OPENAL_PLAIN_INCLUDES #include #else diff --git a/native/cocos/base/CCLog.h b/native/cocos/base/CCLog.h index 9b2ec72eed..3257a30090 100644 --- a/native/cocos/base/CCLog.h +++ b/native/cocos/base/CCLog.h @@ -43,6 +43,8 @@ #elif defined(__has_attribute) #if __has_attribute(format) #define CC_FORMAT_PRINTF(formatPos, argPos) __attribute__((__format__(printf, formatPos, argPos))) +#else +#define CC_FORMAT_PRINTF(formatPos, argPos) #endif // __has_attribute(format) #else #define CC_FORMAT_PRINTF(formatPos, argPos) diff --git a/native/cocos/base/CCThreadPool.cpp b/native/cocos/base/CCThreadPool.cpp index b7282a2e9a..7dd4ee0c50 100644 --- a/native/cocos/base/CCThreadPool.cpp +++ b/native/cocos/base/CCThreadPool.cpp @@ -27,6 +27,8 @@ #include "base/CCThreadPool.h" #include "platform/CCStdC.h" +#include +#include #ifdef __ANDROID__ #include @@ -36,6 +38,8 @@ #define LOGD(...) printf(__VA_ARGS__) #endif +#define TIME_MINUS(now, prev) (std::chrono::duration_cast((now) - (prev)).count() / 1000.0f) + namespace cocos2d { #define DEFAULT_THREAD_POOL_MIN_NUM (4) @@ -125,7 +129,7 @@ int ThreadPool::getIdleThreadNum() const void ThreadPool::init() { - gettimeofday(&_lastShrinkTime, nullptr); + _lastShrinkTime = std::chrono::high_resolution_clock::now(); _maxThreadNum = std::max(_minThreadNum, _maxThreadNum); @@ -156,8 +160,7 @@ bool ThreadPool::tryShrinkPool() { LOGD("shrink pool, _idleThreadNum = %d \n", getIdleThreadNum()); - struct timeval before; - gettimeofday(&before, nullptr); + auto before = std::chrono::high_resolution_clock::now(); std::vector threadIDsToJoin; int maxThreadNumToJoin = std::min(_initedThreadNum - _minThreadNum, _shrinkStep); @@ -194,10 +197,9 @@ bool ThreadPool::tryShrinkPool() --_initedThreadNum; } - struct timeval after; - gettimeofday(&after, nullptr); + auto after = std::chrono::high_resolution_clock::now(); - float seconds = (after.tv_sec - before.tv_sec) + (after.tv_usec - before.tv_usec) / 1000000.0f; + float seconds = TIME_MINUS(after, before); LOGD("shrink %d threads, waste: %f seconds\n", (int) threadIDsToJoin.size(), seconds); @@ -209,8 +211,7 @@ bool ThreadPool::tryShrinkPool() void ThreadPool::stretchPool(int count) { - struct timeval before; - gettimeofday(&before, nullptr); + auto before = std::chrono::high_resolution_clock::now(); int oldThreadCount = _initedThreadNum; int newThreadCount = 0; @@ -233,11 +234,8 @@ void ThreadPool::stretchPool(int count) if (newThreadCount > 0) { - struct timeval after; - gettimeofday(&after, nullptr); - - float seconds = - (after.tv_sec - before.tv_sec) + (after.tv_usec - before.tv_usec) / 1000000.0f; + auto after = std::chrono::high_resolution_clock::now(); + float seconds = TIME_MINUS(after, before); LOGD("stretch pool from %d to %d, waste %f seconds\n", oldThreadCount, _initedThreadNum, seconds); @@ -257,11 +255,8 @@ void ThreadPool::pushTask(const std::function& runnable, { if (_taskQueue.empty()) { - struct timeval now; - gettimeofday(&now, nullptr); - - float seconds = (now.tv_sec - _lastShrinkTime.tv_sec) + - (now.tv_usec - _lastShrinkTime.tv_usec) / 1000000.0f; + auto now = std::chrono::high_resolution_clock::now(); + float seconds = TIME_MINUS(now, _lastShrinkTime); if (seconds > _shrinkInterval) { tryShrinkPool(); @@ -357,7 +352,7 @@ void ThreadPool::setFixedSize(bool isFixedSize) void ThreadPool::setShrinkInterval(int seconds) { if (seconds >= 0) - _shrinkInterval = seconds; + _shrinkInterval = (float)seconds; } void ThreadPool::setShrinkStep(int step) diff --git a/native/cocos/base/CCThreadPool.h b/native/cocos/base/CCThreadPool.h index 14f7521391..7fcfeed50d 100644 --- a/native/cocos/base/CCThreadPool.h +++ b/native/cocos/base/CCThreadPool.h @@ -37,6 +37,7 @@ #include #include #include +#include namespace cocos2d { @@ -224,7 +225,7 @@ private: int _maxThreadNum; int _initedThreadNum; - struct timeval _lastShrinkTime; + std::chrono::time_point _lastShrinkTime; float _shrinkInterval; int _shrinkStep; int _stretchStep; diff --git a/native/cocos/base/ccUtils.cpp b/native/cocos/base/ccUtils.cpp index 2d3a9f2bbb..62e64a0d24 100644 --- a/native/cocos/base/ccUtils.cpp +++ b/native/cocos/base/ccUtils.cpp @@ -37,24 +37,6 @@ THE SOFTWARE. NS_CC_BEGIN -namespace -{ -#if (CC_PLATFORM == CC_PLATFORM_WINDOWS) -#include "platform/CCStdC.h" - int gettimeofday(struct timeval * val, void *) - { - if (val) - { - LARGE_INTEGER liTime, liFreq; - QueryPerformanceFrequency(&liFreq); - QueryPerformanceCounter(&liTime); - val->tv_sec = (long)(liTime.QuadPart / liFreq.QuadPart); - val->tv_usec = (long)(liTime.QuadPart * 1000000.0 / liFreq.QuadPart - val->tv_sec * 1000000.0); - } - return 0; - } -#endif -} namespace utils { @@ -80,20 +62,6 @@ double atof(const char* str) return ::atof(buf); } -double gettime() -{ - struct timeval tv; - gettimeofday(&tv, nullptr); - - return (double)tv.tv_sec + (double)tv.tv_usec/1000000; -} - -long long getTimeInMilliseconds() -{ - struct timeval tv; - gettimeofday (&tv, nullptr); - return (long long)tv.tv_sec * 1000 + tv.tv_usec / 1000; -} int nextPOT(int x) { diff --git a/native/cocos/base/ccUtils.h b/native/cocos/base/ccUtils.h index f83442ec28..0b96f59612 100644 --- a/native/cocos/base/ccUtils.h +++ b/native/cocos/base/ccUtils.h @@ -35,13 +35,7 @@ Misc free functions NS_CC_BEGIN -namespace -{ -#if (CC_PLATFORM == CC_PLATFORM_WINDOWS) -#include - extern "C" int gettimeofday(struct timeval * val, void *); -#endif -} + /* utils::nextPOT function is licensed under the same license that is used in Texture2D.m. */ @@ -68,17 +62,6 @@ namespace utils */ CC_DLL double atof(const char* str); - /** Get current exact time, accurate to nanoseconds. - * @return Returns the time in seconds since the Epoch. - */ - CC_DLL double gettime(); - - /** - * Get current time in milliseconds, accurate to nanoseconds - * - * @return Returns the time in milliseconds since the Epoch. - */ - CC_DLL long long getTimeInMilliseconds(); } NS_CC_END diff --git a/native/cocos/platform/CCImage.cpp b/native/cocos/platform/CCImage.cpp index 745f2db80d..0bb13d6afe 100644 --- a/native/cocos/platform/CCImage.cpp +++ b/native/cocos/platform/CCImage.cpp @@ -22,16 +22,18 @@ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. ****************************************************************************/ + + #include "CCImage.h" #include #include #include -#include "base/CCData.h" #include "base/ccConfig.h" // CC_USE_JPEG, CC_USE_WEBP #if CC_USE_JPEG #include "jpeg/jpeglib.h" #endif // CC_USE_JPEG +#include "base/CCData.h" #include "base/ccUtils.h" #include "renderer/core/Core.h" @@ -63,6 +65,7 @@ extern "C" #endif //CC_USE_PNG + #include "base/etc1.h" #include "base/etc2.h" } diff --git a/native/cocos/platform/android/CCDevice-android.cpp b/native/cocos/platform/android/CCDevice-android.cpp index b7794be84c..f963e64302 100644 --- a/native/cocos/platform/android/CCDevice-android.cpp +++ b/native/cocos/platform/android/CCDevice-android.cpp @@ -137,6 +137,9 @@ namespace { g_sensor->motionValue.accelerationZ = event.acceleration.z; } } + // return 1 to continue receiving callbacks + // or 0 to have this file descriptor and callback unregistered from the looper + return 1; } } diff --git a/native/cocos/platform/apple/CCCanvasRenderingContext2D-apple.mm b/native/cocos/platform/apple/CCCanvasRenderingContext2D-apple.mm index a9a66e82de..b06c9b1c9a 100644 --- a/native/cocos/platform/apple/CCCanvasRenderingContext2D-apple.mm +++ b/native/cocos/platform/apple/CCCanvasRenderingContext2D-apple.mm @@ -10,6 +10,7 @@ #import #else #import +#import #define NSBezierPath UIBezierPath #define NSFont UIFont diff --git a/native/cocos/platform/apple/CCDevice-apple.mm b/native/cocos/platform/apple/CCDevice-apple.mm index 75c900c08f..17a16c3632 100644 --- a/native/cocos/platform/apple/CCDevice-apple.mm +++ b/native/cocos/platform/apple/CCDevice-apple.mm @@ -26,21 +26,29 @@ #include "platform/apple/CCDevice-apple.h" #include "platform/CCApplication.h" + +#if CC_PLATFORM == CC_PLATFORM_MAC_OSX +#import +#endif +#if CC_PLATFORM == CC_PLATFORM_MAC_IOS +#import +#endif + + NS_CC_BEGIN int Device::getDevicePixelRatio() { -#if(CC_PLATFORM == CC_PLATFORM_MAC_IOS) - return [[UIScreen mainScreen] scale]; -#else - #if USE_METAL return 1; #else - return [[[[NSApplication sharedApplication] delegate] getWindow] backingScaleFactor]; +# if(CC_PLATFORM == CC_PLATFORM_MAC_IOS) + return [[UIScreen mainScreen] scale]; +# else + return [[[[NSApplication sharedApplication] delegate] getWindow] backingScaleFactor]; +# endif #endif //USE_METAL - -#endif } + NS_CC_END diff --git a/native/cocos/platform/mac/CCApplication-mac.mm b/native/cocos/platform/mac/CCApplication-mac.mm index bdd136b387..11aa0c2db9 100644 --- a/native/cocos/platform/mac/CCApplication-mac.mm +++ b/native/cocos/platform/mac/CCApplication-mac.mm @@ -30,6 +30,8 @@ THE SOFTWARE. #include "scripting/js-bindings/jswrapper/SeApi.h" #include "audio/include/AudioEngine.h" +#import + @interface MyTimer : NSObject { cocos2d::Application* _app; diff --git a/native/cocos/renderer/core/CoreDef.h b/native/cocos/renderer/core/CoreDef.h index f985bc4c4a..352838040b 100755 --- a/native/cocos/renderer/core/CoreDef.h +++ b/native/cocos/renderer/core/CoreDef.h @@ -306,10 +306,14 @@ Note: #define CC_TOSTR(s) #s #if (CC_PLATFORM == CC_PLATFORM_WINDOWS) -# ifdef CC_CORE_EXPORTS -# define CC_CORE_API __declspec(dllexport) -# else -# define CC_CORE_API __declspec(dllimport) +# ifdef CC_STATIC +# define CC_CORE_API +# else +# ifdef CC_CORE_EXPORTS +# define CC_CORE_API __declspec(dllexport) +# else +# define CC_CORE_API __declspec(dllimport) +# endif # endif #else # define CC_CORE_API diff --git a/native/cocos/renderer/core/kernel/Log.h b/native/cocos/renderer/core/kernel/Log.h index 85612b4e48..6805b60e00 100755 --- a/native/cocos/renderer/core/kernel/Log.h +++ b/native/cocos/renderer/core/kernel/Log.h @@ -1,6 +1,8 @@ #ifndef CC_CORE_KERNEL_LOG_H_ #define CC_CORE_KERNEL_LOG_H_ +#include + NS_CC_BEGIN enum class LogType: uint8_t { diff --git a/native/cocos/scripting/js-bindings/jswrapper/config.hpp b/native/cocos/scripting/js-bindings/jswrapper/config.hpp index b102743d72..fd16bf2f14 100644 --- a/native/cocos/scripting/js-bindings/jswrapper/config.hpp +++ b/native/cocos/scripting/js-bindings/jswrapper/config.hpp @@ -30,7 +30,9 @@ #define SCRIPT_ENGINE_JSC 3 //#define SCRIPT_ENGINE_CHAKRACORE 4 +#ifndef SCRIPT_ENGINE_TYPE #define SCRIPT_ENGINE_TYPE SCRIPT_ENGINE_V8 +#endif #ifndef USE_V8_DEBUGGER diff --git a/native/cocos/ui/edit-box/EditBox-ios.mm b/native/cocos/ui/edit-box/EditBox-ios.mm index 4a30e01a52..e79f5f17d8 100644 --- a/native/cocos/ui/edit-box/EditBox-ios.mm +++ b/native/cocos/ui/edit-box/EditBox-ios.mm @@ -26,8 +26,7 @@ #include "cocos/scripting/js-bindings/jswrapper/SeApi.h" #include "cocos/scripting/js-bindings/manual/jsb_global.h" -#import -#import +#import #define TEXT_LINE_HEIGHT 40 #define TEXT_VIEW_MAX_LINE_SHOWN 3 diff --git a/native/cocos/ui/edit-box/EditBox-mac.mm b/native/cocos/ui/edit-box/EditBox-mac.mm index d47659be9e..03e910bbb2 100644 --- a/native/cocos/ui/edit-box/EditBox-mac.mm +++ b/native/cocos/ui/edit-box/EditBox-mac.mm @@ -26,6 +26,8 @@ #include "cocos/scripting/js-bindings/jswrapper/SeApi.h" #include "cocos/scripting/js-bindings/manual/jsb_global.h" +#import + /************************************************************************* Forward declaration of global functions. ************************************************************************/ diff --git a/native/external/config.json b/native/external/config.json index 4797adde66..decda7b700 100644 --- a/native/external/config.json +++ b/native/external/config.json @@ -1,5 +1,5 @@ { - "version": "v3d-3", + "version": "v3d-4", "zip_file_size": "115677698", "repo_name": "cocos2d-x-lite-external", "repo_parent": "https://github.com/cocos-creator/" diff --git a/native/templates/js-template-link/frameworks/runtime-src/CMakeLists.txt b/native/templates/js-template-link/frameworks/runtime-src/CMakeLists.txt new file mode 100644 index 0000000000..5484018924 --- /dev/null +++ b/native/templates/js-template-link/frameworks/runtime-src/CMakeLists.txt @@ -0,0 +1,226 @@ +cmake_minimum_required(VERSION 3.8) + +set(APP_NAME MyGame) +project(${APP_NAME} CXX) + +enable_language(C ASM) + +set(CMAKE_CXX_STANDARD 14) +option(USE_SE_V8 "USE V8 JavaScript Engine" ON) +option(USE_V8_DEBUGGER "Enable Chrome Remote inspector" ON) +option(USE_SE_JSC "USE JavaScriptCore on MacOSX/iOS" OFF) +option(USE_VIDEOPLAYER "Enable VideoPlayer Component" OFF) +option(USE_WEBVIEW "Enable WebView Component" OFF) +option(USE_SOCKET "Enable WebSocket & SocketIO" ON) +option(USE_TIFF "Support TIFF image format" ON) +option(USE_AUDIO "Enable Audio" ON) #Enable AudioEngine + +if(USE_SE_JSC AND APPLE) + set(USE_SE_V8 OFF) + set(USE_V8_DEBUGGER OFF) +endif() + +set(TARGET_IOS_VERSION "8.0") + +set(cocosdir "${COCOS_X_ROOT}") +if(NOT cocosdir) + message(FATAL_ERROR "COCOS_X_ROOT is not set!") +endif() +include(${cocosdir}/CMakeLists.txt) + +if(ANDROID) + set(LIB_NAME cocos2djs) +elseif(MACOSX) + set(LIB_NAME ${APP_NAME}-desktop) +elseif(IOS) + set(LIB_NAME ${APP_NAME}-mobile) +else() + set(LIB_NAME ${APP_NAME}) +endif() + + + +set(GAME_RES_ROOT ${CMAKE_CURRENT_LIST_DIR}/../../) +set(GAME_RES_FILES + ${GAME_RES_ROOT}/main.js + ${GAME_RES_ROOT}/project.json +) +set(GAME_RES_FOLDERS + ${GAME_RES_ROOT}/jsb-adapter + ${GAME_RES_ROOT}/subpackages + ${GAME_RES_ROOT}/res + ${GAME_RES_ROOT}/src +) +set(GAME_RES_ALL + ${GAME_RES_FILES} + ${GAME_RES_FOLDERS} +) + +set(UI_RESOURCES) +set(PROJ_EXTRA_SOURCE) +set(PROJ_SOURCES + Classes/Game.h + Classes/Game.cpp +) + +if(EXISTS Classes/jsb_module_register.cpp) + list(APPEND PROJ_SOURCES + Classes/jsb_module_register.cpp + ) +else() + list(APPEND PROJ_EXTRA_SOURCE + "${cocosdir}/cocos/scripting/js-bindings/manual/jsb_module_register.cpp" + ) + source_group("Source Files\\Classes" FILES ${PROJ_EXTRA_SOURCE}) +endif() + +if(WINDOWS) + list(APPEND PROJ_SOURCES + proj.win32/AppDelegate.h + proj.win32/AppDelegate.cpp + proj.win32/main.h + proj.win32/main.cpp + proj.win32/resource.h + ) +elseif(MACOSX) + set(UI_RESOURCES + proj.ios_mac/mac/Assets.xcassets + # proj.ios_mac/mac/UserConfigMac.release.xcconfig + # proj.ios_mac/mac/UserConfigMac.debug.xcconfig + proj.ios_mac/mac/Icon.icns + ) + list(APPEND PROJ_SOURCES + proj.ios_mac/mac/main.m + proj.ios_mac/mac/ViewController.mm + proj.ios_mac/mac/ViewController.h + proj.ios_mac/mac/Prefix.pch + proj.ios_mac/mac/AppDelegate.mm + proj.ios_mac/mac/AppDelegate.h + ${UI_RESOURCES} + ) +elseif(IOS) + + set(UI_RESOURCES + #proj.ios_mac/ios/zh-Hans.lproj/Localizable.strings + #proj.ios_mac/ios/UserConfigIOS.release.xcconfig + #proj.ios_mac/ios/UserConfigIOS.debug.xcconfig + #proj.ios_mac/ios/Prefix.pch + proj.ios_mac/ios/LaunchScreenBackground.png + #proj.ios_mac/ios/Info.plist + proj.ios_mac/ios/Images.xcassets + proj.ios_mac/ios/Base.lproj/Localizable.strings + proj.ios_mac/ios/Base.lproj/LaunchScreen.storyboard + ) + + list(APPEND PROJ_SOURCES + proj.ios_mac/ios/AppDelegate.mm + proj.ios_mac/ios/AppDelegate.h + proj.ios_mac/ios/SDKWrapper.m + proj.ios_mac/ios/SDKWrapper.h + proj.ios_mac/ios/service/SDKDelegate.h + proj.ios_mac/ios/main.m + proj.ios_mac/ios/ViewController.mm + proj.ios_mac/ios/ViewController.h + ${UI_RESOURCES} + ) + +endif() + +set(asset_files) +foreach(res ${GAME_RES_ALL}) + set(res_list) + if(NOT EXISTS ${res}) + continue() + endif() + + if(IS_DIRECTORY ${res}) + file(GLOB_RECURSE res_list "${res}/*") + else() + set(res_list ${res}) + endif() + foreach(res ${res_list}) + get_filename_component(res_abs ${res} ABSOLUTE) + file(RELATIVE_PATH res_rel ${GAME_RES_ROOT} ${res_abs}) + get_filename_component(res_dir ${res_rel} PATH) + set_source_files_properties(${res_abs} PROPERTIES + MACOSX_PACKAGE_LOCATION "Resources/${res_dir}/" + HEADER_FILE_ONLY 1 + ) + list(APPEND asset_files ${res_abs}) + endforeach() +endforeach() + +if(ANDROID) + add_library(${LIB_NAME} SHARED ${PROJ_SOURCES} ${PROJ_EXTRA_SOURCE}) +elseif(APPLE OR MSVC) + add_executable(${LIB_NAME} ${PROJ_SOURCES} ${asset_files} ${PROJ_EXTRA_SOURCE}) + source_group(TREE ${GAME_RES_ROOT} PREFIX "Resources" FILES ${asset_files}) +else() + add_executable(${LIB_NAME} ${PROJ_SOURCES} ${PROJ_EXTRA_SOURCE}) +endif() + +target_link_libraries(${LIB_NAME} cocos2d) +target_include_directories(${LIB_NAME} PRIVATE + Classes +) + +source_group(TREE ${CMAKE_CURRENT_LIST_DIR} PREFIX "Source Files" FILES ${PROJ_SOURCES}) + +if(APPLE) + set_target_properties(${LIB_NAME} PROPERTIES MACOSX_BUNDLE 1) + set_target_properties(${LIB_NAME} PROPERTIES RESOURCE "${UI_RESOURCES}") + if(MACOSX) + set_target_properties(${LIB_NAME} PROPERTIES MACOSX_BUNDLE_INFO_PLIST "${CMAKE_CURRENT_LIST_DIR}/proj.ios_mac/mac/Info.plist") + set_target_properties(${LIB_NAME} PROPERTIES + MACOSX_DEPLOYMENT_TARGET 10.10 + ) + get_property(gles2_loc TARGET GLESv2 PROPERTY IMPORTED_LOCATION) + get_property(egl_loc TARGET EGL PROPERTY IMPORTED_LOCATION) + add_custom_command(TARGET ${LIB_NAME} POST_BUILD + COMMAND ${CMAKE_COMMAND} -E make_directory $/../Frameworks + COMMAND ${CMAKE_COMMAND} -E copy ${gles2_loc} $/../Frameworks + COMMAND ${CMAKE_COMMAND} -E copy ${egl_loc} $/../Frameworks + ) + elseif(IOS) + set(EXECUTABLE_NAME ${LIB_NAME}) # referenced in Info.plist + set(PRODUCT_NAME ${APP_NAME}) + target_include_directories(${LIB_NAME} PRIVATE proj.ios_mac/ios/service ) + set_target_properties(${LIB_NAME} PROPERTIES MACOSX_BUNDLE_INFO_PLIST "${CMAKE_CURRENT_LIST_DIR}/proj.ios_mac/ios/Info.plist") + set_property(TARGET ${LIB_NAME} PROPERTY XCODE_ATTRIBUTE_DEVELOPMENT_TEAM "") + set_property(TARGET ${LIB_NAME} PROPERTY XCODE_ATTRIBUTE_CODE_SIGN_IDENTITY "iPhone Developer") + set_property(TARGET ${LIB_NAME} PROPERTY XCODE_ATTRIBUTE_ASSETCATALOG_COMPILER_APPICON_NAME "AppIcon") + set_property(TARGET ${LIB_NAME} PROPERTY XCODE_ATTRIBUTE_ASSETCATALOG_COMPILER_LAUNCHSTORYBOARD_NAME "LaunchScreen") + set_property(TARGET ${LIB_NAME} PROPERTY XCODE_ATTRIBUTE_IPHONEOS_DEPLOYMENT_TARGET ${TARGET_IOS_VERSION}) + set_property(TARGET ${LIB_NAME} PROPERTY XCODE_ATTRIBUTE_ENABLE_BITCODE "NO") + set_property(TARGET ${LIB_NAME} PROPERTY XCODE_ATTRIBUTE_ONLY_ACTIVE_ARCH "YES") + endif() + +elseif(WINDOWS) + + if(EXISTS ../../../jsb-adapter) + add_custom_command(TARGET ${LIB_NAME} POST_BUILD + COMMAND ${CMAKE_COMMAND} -E copy_directory ../../../jsb-adapter $/jsb-adapter + COMMAND ${CMAKE_COMMAND} -E copy_directory ../../../res $/res + COMMAND ${CMAKE_COMMAND} -E copy_directory ../../../src $/src + COMMAND ${CMAKE_COMMAND} -E copy_if_different ../../../main.js $/main.js + COMMAND ${CMAKE_COMMAND} -E copy_if_different ../../../project.json $/project.json + ) + endif() + + target_include_directories(${LIB_NAME} PRIVATE + proj.win32 + ) + + if(MSVC) + foreach(item ${WIN32_DLLS}) + get_filename_component(filename ${item} NAME) + get_filename_component(abs ${item} ABSOLUTE) + add_custom_command(TARGET ${LIB_NAME} POST_BUILD + COMMAND ${CMAKE_COMMAND} -E copy_if_different ${abs} $/${filename} + ) + endforeach() + target_compile_options(${LIB_NAME} PUBLIC /MP) + target_link_options(${LIB_NAME} PRIVATE /SUBSYSTEM:WINDOWS) + endif() +endif() + diff --git a/native/templates/js-template-link/frameworks/runtime-src/proj.android-studio/app/build.gradle b/native/templates/js-template-link/frameworks/runtime-src/proj.android-studio/app/build.gradle index 73801544ba..4cce932b66 100755 --- a/native/templates/js-template-link/frameworks/runtime-src/proj.android-studio/app/build.gradle +++ b/native/templates/js-template-link/frameworks/runtime-src/proj.android-studio/app/build.gradle @@ -14,25 +14,34 @@ android { versionName "1.0" externalNativeBuild { - ndkBuild { - if (!project.hasProperty("PROP_NDK_MODE") || PROP_NDK_MODE.compareTo('none') != 0) { - // skip the NDK Build step if PROP_NDK_MODE is none - targets 'cocos2djs' - arguments 'NDK_TOOLCHAIN_VERSION=clang' - - def module_paths = [project.file("${COCOS_X_ROOT}"), - project.file("${COCOS_X_ROOT}/cocos"), - project.file("${COCOS_X_ROOT}/external")] - if (Os.isFamily(Os.FAMILY_WINDOWS)) { - arguments 'NDK_MODULE_PATH=' + module_paths.join(";") - } - else { - arguments 'NDK_MODULE_PATH=' + module_paths.join(':') - } - - arguments '-j' + Runtime.runtime.availableProcessors() + if (project.hasProperty("PROP_USE_CMAKE")) { + cmake { + targets "cocos2djs" + arguments "-DANDROID_STL=c++_static", "-DANDROID_TOOLCHAIN=clang", "-DANDROID_ARM_NEON=TRUE", "-DCOCOS_X_ROOT=${COCOS_X_ROOT}" + cppFlags "-frtti -fexceptions -fsigned-char" abiFilters.addAll(PROP_APP_ABI.split(':').collect{it as String}) } + } else { + ndkBuild { + if (!project.hasProperty("PROP_NDK_MODE") || PROP_NDK_MODE.compareTo('none') != 0) { + // skip the NDK Build step if PROP_NDK_MODE is none + targets 'cocos2djs' + arguments 'NDK_TOOLCHAIN_VERSION=clang' + + def module_paths = [project.file("${COCOS_X_ROOT}"), + project.file("${COCOS_X_ROOT}/cocos"), + project.file("${COCOS_X_ROOT}/external")] + if (Os.isFamily(Os.FAMILY_WINDOWS)) { + arguments 'NDK_MODULE_PATH=' + module_paths.join(";") + } + else { + arguments 'NDK_MODULE_PATH=' + module_paths.join(':') + } + + arguments '-j' + Runtime.runtime.availableProcessors() + abiFilters.addAll(PROP_APP_ABI.split(':').collect{it as String}) + } + } } } } @@ -45,10 +54,16 @@ android { } externalNativeBuild { - ndkBuild { - if (!project.hasProperty("PROP_NDK_MODE") || PROP_NDK_MODE.compareTo('none') != 0) { - // skip the NDK Build step if PROP_NDK_MODE is none - path "jni/Android.mk" + if (project.hasProperty("PROP_USE_CMAKE")) { + cmake { + path "../../CMakeLists.txt" + } + } else { + ndkBuild { + if (!project.hasProperty("PROP_NDK_MODE") || PROP_NDK_MODE.compareTo('none') != 0) { + // skip the NDK Build step if PROP_NDK_MODE is none + path "jni/Android.mk" + } } } } diff --git a/native/templates/js-template-link/frameworks/runtime-src/proj.ios_mac/ios/SDKWrapper.h b/native/templates/js-template-link/frameworks/runtime-src/proj.ios_mac/ios/SDKWrapper.h index 03b0401c14..9a64aa2efd 100644 --- a/native/templates/js-template-link/frameworks/runtime-src/proj.ios_mac/ios/SDKWrapper.h +++ b/native/templates/js-template-link/frameworks/runtime-src/proj.ios_mac/ios/SDKWrapper.h @@ -6,7 +6,7 @@ // #import - +#import NS_ASSUME_NONNULL_BEGIN @interface SDKWrapper : NSObject diff --git a/native/templates/js-template-link/frameworks/runtime-src/proj.ios_mac/ios/service/SDKDelegate.h b/native/templates/js-template-link/frameworks/runtime-src/proj.ios_mac/ios/service/SDKDelegate.h index 7d88d153c3..772d9b79e9 100644 --- a/native/templates/js-template-link/frameworks/runtime-src/proj.ios_mac/ios/service/SDKDelegate.h +++ b/native/templates/js-template-link/frameworks/runtime-src/proj.ios_mac/ios/service/SDKDelegate.h @@ -6,7 +6,7 @@ // #import - +#import NS_ASSUME_NONNULL_BEGIN @protocol SDKDelegate diff --git a/native/tools/travis-scripts/before-install.sh b/native/tools/travis-scripts/before-install.sh index 82a0fa3921..d162fb020c 100755 --- a/native/tools/travis-scripts/before-install.sh +++ b/native/tools/travis-scripts/before-install.sh @@ -5,10 +5,26 @@ set -e DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" COCOS2DX_ROOT="$DIR"/../.. HOST_NAME="" +set -x + + +function download_external() +{ + pushd $COCOS2DX_ROOT + #python download-deps.py -r=yes + cd $COCOS2DX_ROOT/external + external_version=`grep version config.json |awk -F'"' '{print $4}'` + external_repo_name=`grep repo_name config.json |awk -F'"' '{print $4}'` + external_repo_parent=`grep repo_parent config.json |awk -F'"' '{print $4}'` + rm * + git clone --branch $external_version --depth 1 $external_repo_parent$external_repo_name . + #git checkout $external_version + git log --oneline -1 + popd +} + +download_external -pushd $COCOS2DX_ROOT -python download-deps.py -r=yes -popd mkdir -p $HOME/bin cd $HOME/bin @@ -18,8 +34,10 @@ function install_android_ndk() # Download android ndk if [ $TRAVIS_OS_NAME = 'osx' ]; then HOST_NAME="darwin" - else + elif [ $TRAVIS_OS_NAME = 'linux' ]; then HOST_NAME="linux" + else + HOST_NAME="windows" fi echo "Download android-ndk-r16b-${HOST_NAME}-x86_64.zip ..." curl -O http://dl.google.com/android/repository/android-ndk-r16b-${HOST_NAME}-x86_64.zip @@ -29,28 +47,32 @@ function install_android_ndk() mv android-ndk-r16b android-ndk } -function install_clang() +function install_python_win32() { - if [ ! -f $COCOS2DX_ROOT/tools/bindings-generator/libclang/libclang.so ]; then - echo "Download clang" - curl -O http://releases.llvm.org/5.0.0/clang+llvm-5.0.0-linux-x86_64-ubuntu14.04.tar.xz - echo "Decompress clang" - tar xpf ./clang+llvm-5.0.0-linux-x86_64-ubuntu14.04.tar.xz - cp ./clang+llvm-5.0.0-linux-x86_64-ubuntu14.04/lib/libclang.so.5.0 $COCOS2DX_ROOT/tools/bindings-generator/libclang/libclang.so - else - echo "Skip downloading clang" - echo " file $COCOS2DX_ROOT/tools/bindings-generator/libclang/libclang.so exists!" - fi + choco install --forcex86 -y python2 + export PATH="/c/Python27":$PATH } -function install_python_module_for_osx() +function install_python_module() { - sudo easy_install pip - sudo -H pip install pyyaml - sudo -H pip install Cheetah + if [ "$TRAVIS_OS_NAME" == "osx" ]; then + sudo easy_install pip + pip install PyYAML + pip install Cheetah + elif [ "$TRAVIS_OS_NAME" == "windows" ]; then + install_python_win32 + python -m easy_install pip + python -m pip install PyYAML + python -m pip install Cheetah + else + sudo easy_install pip + sudo -H pip install pyyaml + sudo -H pip install Cheetah + fi } #we only use osx for generate bindings +install_python_module install_android_ndk -install_python_module_for_osx -install_clang + +set +x \ No newline at end of file diff --git a/native/tools/travis-scripts/generate-bindings.sh b/native/tools/travis-scripts/generate-bindings.sh index 9e82fa5890..1aec9ed6e8 100755 --- a/native/tools/travis-scripts/generate-bindings.sh +++ b/native/tools/travis-scripts/generate-bindings.sh @@ -29,28 +29,33 @@ JS_COMMIT_PATH="cocos/scripting/js-bindings/auto" # Exit on error set -e +if [ "$TRAVIS_OS_NAME" == "windows" ]; then + export PATH="/c/Python27":$PATH +fi + generate_bindings_glue_codes() { echo "Create auto-generated jsbinding glue codes." pushd "$TOJS_ROOT" - ./genbindings.py + python -V + python ./genbindings.py rm userconf.ini popd } -pushd "$PROJECT_ROOT" -#Set git user for cocos2d-js repo -git config user.email ${GH_EMAIL} -git config user.name ${GH_USER} -popd - # 1. Generate js bindings generate_bindings_glue_codes +if [ "$TRAVIS_OS_NAME" != "linux" ]; then + exit 0 +fi + if [ "$TRAVIS_PULL_REQUEST" != "false" ]; then exit 0 fi + + if [ -z "${GH_EMAIL}" ]; then echo "GH_EMAIL not set" exit 1 @@ -64,6 +69,13 @@ if [ -z "${GH_PASSWORD}" ]; then exit 1 fi +pushd "$PROJECT_ROOT" +#Set git user for cocos2d-js repo +git config user.email ${GH_EMAIL} +git config user.name ${GH_USER} +popd + + echo echo Bindings generated successfully echo diff --git a/native/tools/travis-scripts/generate-cocosfiles.sh b/native/tools/travis-scripts/generate-cocosfiles.sh index dd09206491..cc2f13d05e 100755 --- a/native/tools/travis-scripts/generate-cocosfiles.sh +++ b/native/tools/travis-scripts/generate-cocosfiles.sh @@ -1,5 +1,9 @@ #!/bin/bash +if [ "$TRAVIS_OS_NAME" != "linux" ]; then + exit 0 +fi + if [ "$TRAVIS_PULL_REQUEST" != "false" ]; then exit 0 fi diff --git a/native/tools/travis-scripts/run-script.sh b/native/tools/travis-scripts/run-script.sh index 7a207e231c..590987022a 100755 --- a/native/tools/travis-scripts/run-script.sh +++ b/native/tools/travis-scripts/run-script.sh @@ -13,9 +13,145 @@ fi #git remote add old https://github.com/cocos-creator/cocos2d-x-lite #git fetch --unshallow old +set -x + cd $COCOS2DX_ROOT/tools/travis-scripts ./generate-bindings.sh $TRAVIS_BRANCH + +ANDROID_SDK=$COCOS2DX_ROOT/../android/android_sdk +export ANDROID_HOME=$ANDROID_SDK +export ANDROID_NDK=$NDK_ROOT #installed in generate-bindings.sh +export ANDROID_NDK_HOME=$NDK_ROOT + + +function setup_linux_andorid_sdk() +{ + echo "Download Android SDK... " + cd $COCOS2DX_ROOT/.. + mkdir android + cd android + wget -t 5 -q https://dl.google.com/android/repository/commandlinetools-linux-6200805_latest.zip + unzip *.zip + yes | ./tools/bin/sdkmanager --sdk_root="$ANDROID_SDK" \ + "platforms;android-27" \ + "build-tools;28.0.3" \ + "platform-tools" \ + "tools" \ + "cmake;3.10.2.4988404" + cmake_dir=$ANDROID_SDK/cmake/3.10.2.4988404/bin + export PATH=$cmake_dir:$PATH +} + +function build_android() +{ + echo "Compiling Android ... " + cd $COCOS2DX_ROOT/templates/js-template-link/frameworks/runtime-src/proj.android-studio + sed -i "s@\${COCOS_X_ROOT}@$COCOS2DX_ROOT@g" app/build.gradle + sed -i "s@\${COCOS_X_ROOT}@$COCOS2DX_ROOT@g" settings.gradle + sed -i "s/^RELEASE_/#RELEASE_/g" gradle.properties + echo "PROP_USE_CMAKE = true" >> gradle.properties + echo "ANDORID_NDK ${ANDROID_NDK} or ${ANDROID_NDK_HOME}" + ./gradlew assembleDebug --quiet + echo "Compile Android Done!" +} + +function mac_install_cmake() +{ + echo "Compiling CMake ... " + NUM_OF_CORES=`getconf _NPROCESSORS_ONLN` + cd $HOME/bin + cmake_source=https://github.com/Kitware/CMake/releases/download/v3.17.0/cmake-3.17.0.tar.gz + wget -t 5 --no-check-certificate $cmake_source -O cmake-mac.tar.gz -q + tar xf cmake-mac.tar.gz 2>/dev/null + cd cmake-3.17.0 + ./configure --prefix=$HOME/bin/cmake > /dev/null + make -j $NUM_OF_CORES >/dev/null + make install >/dev/null + ls $HOME/bin/cmake + export PATH=$HOME/bin/cmake/bin:$PATH +} + +function mac_download_cmake() +{ + echo "Download CMake ..." + cmake_binary=https://github.com/Kitware/CMake/releases/download/v3.17.0/cmake-3.17.0-Darwin-x86_64.tar.gz + wget -t 3 --no-check-certificate $cmake_binary -O cmake_bin.tar.gz -q + tar xf cmake_bin.tar.gz 2>/dev/null + cmake_bin_dir=`dirname $(find . -name cmake-gui)` + cmake_bin_dir="$PWD/$cmake_bin_dir" + export PATH=$cmake_bin_dir:$PATH +} + +function build_macosx() +{ + + echo "Compiling MacOSX ... " + cd $COCOS2DX_ROOT/templates/js-template-link/frameworks/runtime-src + mkdir build-mac + cd build-mac + cmake .. -GXcode -DCOCOS_X_ROOT=$COCOS2DX_ROOT + cmake --build . --config Release -- -quiet + echo "Compile MacOSX Done!" +} + +function build_ios() +{ + + echo "Compiling iOS ... " + cd $COCOS2DX_ROOT/templates/js-template-link/frameworks/runtime-src + mkdir build-ios + cd build-ios + cmake .. -GXcode -DCOCOS_X_ROOT=$COCOS2DX_ROOT -DCMAKE_SYSTEM_NAME=iOS \ + -DCMAKE_OSX_SYSROOT=iphonesimulator \ + -DCMAKE_CXX_FLAGS="-DSCRIPT_ENGINE_TYPE=3" + cmake --build . --config Debug -- -quiet + echo "Compile iOS Done!" +} + +function build_windows() +{ + echo "Compiling Win32 ... " + cd $COCOS2DX_ROOT/templates/js-template-link/frameworks/runtime-src + mkdir build-win32 + cd build-win32 + cmake .. -G"Visual Studio 15 2017" -DCOCOS_X_ROOT=$COCOS2DX_ROOT + cmake --build . --config Debug + echo "Compile Win32 Done!" +} + + +function run_compile() +{ + if [ "$BUILD_TARGET" == "android_cmake" ]; then + setup_linux_andorid_sdk + build_android + fi + + if [ "$BUILD_TARGET" == "macosx_cmake" ]; then + mac_download_cmake + build_macosx + fi + + if [ "$BUILD_TARGET" == "ios_cmake" ]; then + mac_download_cmake + build_macosx + fi + + if [ "$BUILD_TARGET" == "windows_cmake" ]; then + cmake --version + build_windows + fi +} + +run_compile + +cd $COCOS2DX_ROOT +## revert change +git clean -fdx templates +git checkout HEAD templates +set +x + cd $COCOS2DX_ROOT/tools/travis-scripts ./generate-cocosfiles.sh $TRAVIS_BRANCH exit 0