From c4c24c9d54b5b26d4605986f89e3a26e8ea0a15c Mon Sep 17 00:00:00 2001 From: minggo Date: Wed, 7 Mar 2018 14:31:46 +0800 Subject: [PATCH] windows works with new renderer (#1137) --- native/build/cocos2d-win32.sln | 67 - native/build/libcocos2d.vcxproj | 437 +++++ native/build/libcocos2d.vcxproj.filters | 877 ++++++++++ native/cocos/audio/apple/AudioCache.h | 2 +- native/cocos/audio/apple/AudioPlayer.h | 2 +- native/cocos/audio/include/AudioEngine.h | 2 +- native/cocos/audio/win32/AudioCache.h | 2 +- native/cocos/audio/win32/AudioPlayer.h | 2 +- native/cocos/base/CCConfiguration.cpp | 4 +- native/cocos/base/CCConsole.cpp | 1486 ----------------- native/cocos/base/CCConsole.h | 277 --- native/cocos/base/CCData.cpp | 1 - native/cocos/base/CCData.h | 2 +- native/cocos/base/CCDataVisitor.cpp | 221 --- native/cocos/base/CCDataVisitor.h | 113 -- native/cocos/base/CCEvent.cpp | 42 - native/cocos/base/CCEvent.h | 108 -- native/cocos/base/CCEventAcceleration.cpp | 37 - native/cocos/base/CCEventCustom.cpp | 38 - native/cocos/base/CCEventCustom.h | 82 - native/cocos/base/CCEventFocus.cpp | 44 - native/cocos/base/CCEventFocus.h | 73 - native/cocos/base/CCEventKeyboard.cpp | 38 - native/cocos/base/CCEventKeyboard.h | 246 --- native/cocos/base/CCEventMouse.cpp | 85 - native/cocos/base/CCEventMouse.h | 201 --- native/cocos/base/CCEventTouch.cpp | 43 - native/cocos/base/CCEventTouch.h | 109 -- native/cocos/base/CCEventType.h | 50 - native/cocos/base/CCIMEDelegate.h | 180 -- native/cocos/base/CCIMEDispatcher.cpp | 356 ---- native/cocos/base/CCIMEDispatcher.h | 145 -- native/cocos/base/CCLog.cpp | 119 ++ .../base/{CCEventAcceleration.h => CCLog.h} | 57 +- native/cocos/base/CCProfiling.cpp | 179 -- native/cocos/base/CCProfiling.h | 162 -- native/cocos/base/CCRef.h | 2 +- native/cocos/base/CCTouch.cpp | 87 - native/cocos/base/CCTouch.h | 184 -- native/cocos/base/CCUserDefault.h | 2 +- native/cocos/base/CCValue.h | 2 +- native/cocos/base/ObjectFactory.h | 2 +- native/cocos/base/ZipUtils.h | 2 +- native/cocos/base/base64.h | 2 +- native/cocos/base/ccMacros.h | 343 ++-- native/cocos/base/ccRandom.h | 2 +- native/cocos/base/ccUTF8.cpp | 2 +- native/cocos/base/ccUTF8.h | 2 +- native/cocos/base/ccUtils.cpp | 40 +- native/cocos/base/ccUtils.h | 12 +- native/cocos/cocos2d.cpp | 2 +- native/cocos/cocos2d.h | 6 +- native/cocos/math/CCAffineTransform.h | 2 +- native/cocos/math/CCGeometry.h | 2 +- native/cocos/math/CCMathBase.h | 2 +- native/cocos/network/CCDownloader.h | 2 +- native/cocos/network/SocketIO.h | 2 +- native/cocos/network/Uri.h | 2 +- native/cocos/network/WebSocket.h | 2 +- native/cocos/platform/CCApplication.h | 7 +- native/cocos/platform/CCDevice.h | 5 +- native/cocos/platform/CCFileUtils.h | 2 +- native/cocos/platform/CCImage.cpp | 5 +- native/cocos/platform/CCImage.h | 1 + native/cocos/platform/CCPlatformMacros.h | 330 ---- native/cocos/platform/CCSAXParser.h | 2 +- native/cocos/platform/CCStdC.h | 61 +- .../platform/android/CCFileUtils-android.h | 2 +- native/cocos/platform/android/jni/JniHelper.h | 2 +- .../cocos/platform/apple/CCFileUtils-apple.h | 2 +- native/cocos/platform/apple/CCLock-apple.h | 2 +- .../platform/desktop/CCGLView-desktop.cpp | 2 +- .../cocos/platform/desktop/CCGLView-desktop.h | 11 +- .../platform/win32/CCApplication-win32.cpp | 318 ++-- .../platform/win32/CCApplication-win32.h | 111 -- .../cocos/platform/win32/CCCommon-win32.cpp | 55 - .../cocos/platform/win32/CCDevice-win32.cpp | 14 +- .../platform/win32/CCFileUtils-win32.cpp | 1 - .../cocos/platform/win32/CCFileUtils-win32.h | 2 +- native/cocos/platform/win32/CCStdC-win32.h | 76 +- native/cocos/platform/win32/CCUtils-win32.cpp | 5 +- native/cocos/platform/win32/CCUtils-win32.h | 2 +- native/cocos/renderer/gfx/State.h | 4 +- native/cocos/renderer/renderer/Camera.h | 8 + .../js-bindings/manual/jsb_conversions.hpp | 2 - .../local-storage/LocalStorage-android.cpp | 2 +- .../storage/local-storage/LocalStorage.cpp | 2 +- .../storage/local-storage/LocalStorage.h | 2 +- .../runtime-src/Classes/AppDelegate.cpp | 6 +- 89 files changed, 1933 insertions(+), 5706 deletions(-) delete mode 100644 native/build/cocos2d-win32.sln create mode 100644 native/build/libcocos2d.vcxproj create mode 100644 native/build/libcocos2d.vcxproj.filters delete mode 100644 native/cocos/base/CCConsole.cpp delete mode 100644 native/cocos/base/CCConsole.h delete mode 100644 native/cocos/base/CCDataVisitor.cpp delete mode 100644 native/cocos/base/CCDataVisitor.h delete mode 100644 native/cocos/base/CCEvent.cpp delete mode 100644 native/cocos/base/CCEvent.h delete mode 100644 native/cocos/base/CCEventAcceleration.cpp delete mode 100644 native/cocos/base/CCEventCustom.cpp delete mode 100644 native/cocos/base/CCEventCustom.h delete mode 100644 native/cocos/base/CCEventFocus.cpp delete mode 100644 native/cocos/base/CCEventFocus.h delete mode 100644 native/cocos/base/CCEventKeyboard.cpp delete mode 100644 native/cocos/base/CCEventKeyboard.h delete mode 100644 native/cocos/base/CCEventMouse.cpp delete mode 100644 native/cocos/base/CCEventMouse.h delete mode 100644 native/cocos/base/CCEventTouch.cpp delete mode 100644 native/cocos/base/CCEventTouch.h delete mode 100644 native/cocos/base/CCEventType.h delete mode 100644 native/cocos/base/CCIMEDelegate.h delete mode 100644 native/cocos/base/CCIMEDispatcher.cpp delete mode 100644 native/cocos/base/CCIMEDispatcher.h create mode 100644 native/cocos/base/CCLog.cpp rename native/cocos/base/{CCEventAcceleration.h => CCLog.h} (58%) delete mode 100644 native/cocos/base/CCProfiling.cpp delete mode 100644 native/cocos/base/CCProfiling.h delete mode 100644 native/cocos/base/CCTouch.cpp delete mode 100644 native/cocos/base/CCTouch.h delete mode 100644 native/cocos/platform/CCPlatformMacros.h delete mode 100644 native/cocos/platform/win32/CCApplication-win32.h delete mode 100644 native/cocos/platform/win32/CCCommon-win32.cpp diff --git a/native/build/cocos2d-win32.sln b/native/build/cocos2d-win32.sln deleted file mode 100644 index 825b7a042b..0000000000 --- a/native/build/cocos2d-win32.sln +++ /dev/null @@ -1,67 +0,0 @@ -Microsoft Visual Studio Solution File, Format Version 12.00 -# Visual Studio 2013 -VisualStudioVersion = 12.0.31101.0 -MinimumVisualStudioVersion = 12.0.21005.1 -Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "libcocos2d", "..\cocos\2d\libcocos2d.vcxproj", "{98A51BA8-FC3A-415B-AC8F-8C7BD464E93E}" - ProjectSection(ProjectDependencies) = postProject - {6B494955-1E66-40DA-830D-0D31B8D301EF} = {6B494955-1E66-40DA-830D-0D31B8D301EF} - EndProjectSection -EndProject -Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "External", "External", "{92D54E36-7916-48EF-A951-224DD3B25442}" -EndProject -Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "libSpine", "..\cocos\editor-support\spine\proj.win32\libSpine.vcxproj", "{B7C2A162-DEC9-4418-972E-240AB3CBFCAE}" -EndProject -Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "libjscocos2d", "..\cocos\scripting\js-bindings\proj.win32\libjscocos2d.vcxproj", "{39379840-825A-45A0-B363-C09FFEF864BD}" - ProjectSection(ProjectDependencies) = postProject - {6B494955-1E66-40DA-830D-0D31B8D301EF} = {6B494955-1E66-40DA-830D-0D31B8D301EF} - EndProjectSection -EndProject -Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "libDragonBones", "..\cocos\editor-support\dragonbones\proj.win32\libDragonBones.vcxproj", "{6B494955-1E66-40DA-830D-0D31B8D301EF}" -EndProject -Global - GlobalSection(SolutionConfigurationPlatforms) = preSolution - Debug|ARM = Debug|ARM - Debug|Win32 = Debug|Win32 - Release|ARM = Release|ARM - Release|Win32 = Release|Win32 - EndGlobalSection - GlobalSection(ProjectConfigurationPlatforms) = postSolution - {98A51BA8-FC3A-415B-AC8F-8C7BD464E93E}.Debug|ARM.ActiveCfg = Debug|Win32 - {98A51BA8-FC3A-415B-AC8F-8C7BD464E93E}.Debug|Win32.ActiveCfg = Debug|Win32 - {98A51BA8-FC3A-415B-AC8F-8C7BD464E93E}.Debug|Win32.Build.0 = Debug|Win32 - {98A51BA8-FC3A-415B-AC8F-8C7BD464E93E}.Release|ARM.ActiveCfg = Release|Win32 - {98A51BA8-FC3A-415B-AC8F-8C7BD464E93E}.Release|Win32.ActiveCfg = Release|Win32 - {98A51BA8-FC3A-415B-AC8F-8C7BD464E93E}.Release|Win32.Build.0 = Release|Win32 - {B7C2A162-DEC9-4418-972E-240AB3CBFCAE}.Debug|ARM.ActiveCfg = Debug|Win32 - {B7C2A162-DEC9-4418-972E-240AB3CBFCAE}.Debug|Win32.ActiveCfg = Debug|Win32 - {B7C2A162-DEC9-4418-972E-240AB3CBFCAE}.Debug|Win32.Build.0 = Debug|Win32 - {B7C2A162-DEC9-4418-972E-240AB3CBFCAE}.Release|ARM.ActiveCfg = Release|Win32 - {B7C2A162-DEC9-4418-972E-240AB3CBFCAE}.Release|Win32.ActiveCfg = Release|Win32 - {B7C2A162-DEC9-4418-972E-240AB3CBFCAE}.Release|Win32.Build.0 = Release|Win32 - {39379840-825A-45A0-B363-C09FFEF864BD}.Debug|ARM.ActiveCfg = Debug|Win32 - {39379840-825A-45A0-B363-C09FFEF864BD}.Debug|Win32.ActiveCfg = Debug|Win32 - {39379840-825A-45A0-B363-C09FFEF864BD}.Debug|Win32.Build.0 = Debug|Win32 - {39379840-825A-45A0-B363-C09FFEF864BD}.Release|ARM.ActiveCfg = Release|Win32 - {39379840-825A-45A0-B363-C09FFEF864BD}.Release|Win32.ActiveCfg = Release|Win32 - {39379840-825A-45A0-B363-C09FFEF864BD}.Release|Win32.Build.0 = Release|Win32 - {6B494955-1E66-40DA-830D-0D31B8D301EF}.Debug|ARM.ActiveCfg = Debug|Win32 - {6B494955-1E66-40DA-830D-0D31B8D301EF}.Debug|Win32.ActiveCfg = Debug|Win32 - {6B494955-1E66-40DA-830D-0D31B8D301EF}.Debug|Win32.Build.0 = Debug|Win32 - {6B494955-1E66-40DA-830D-0D31B8D301EF}.Release|ARM.ActiveCfg = Release|Win32 - {6B494955-1E66-40DA-830D-0D31B8D301EF}.Release|Win32.ActiveCfg = Release|Win32 - {6B494955-1E66-40DA-830D-0D31B8D301EF}.Release|Win32.Build.0 = Release|Win32 - EndGlobalSection - GlobalSection(SolutionProperties) = preSolution - HideSolutionNode = FALSE - EndGlobalSection - GlobalSection(NestedProjects) = preSolution - {B7C2A162-DEC9-4418-972E-240AB3CBFCAE} = {92D54E36-7916-48EF-A951-224DD3B25442} - {6B494955-1E66-40DA-830D-0D31B8D301EF} = {92D54E36-7916-48EF-A951-224DD3B25442} - EndGlobalSection - GlobalSection(DPCodeReviewSolutionGUID) = preSolution - DPCodeReviewSolutionGUID = {00000000-0000-0000-0000-000000000000} - EndGlobalSection - GlobalSection(DPCodeReviewSolutionGUID) = preSolution - DPCodeReviewSolutionGUID = {00000000-0000-0000-0000-000000000000} - EndGlobalSection -EndGlobal diff --git a/native/build/libcocos2d.vcxproj b/native/build/libcocos2d.vcxproj new file mode 100644 index 0000000000..fe9e984703 --- /dev/null +++ b/native/build/libcocos2d.vcxproj @@ -0,0 +1,437 @@ + + + + + Debug + Win32 + + + Release + Win32 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + libcocos2d + {98A51BA8-FC3A-415B-AC8F-8C7BD464E93E} + cocos2d-x.win32 + Win32Proj + 8.1 + + + + StaticLibrary + Unicode + v120 + v120_xp + v140 + v140_xp + v140 + v140_xp + + + StaticLibrary + Unicode + v120 + v120_xp + v140 + v140_xp + v140 + v140_xp + + + + + + + + + + + + + <_ProjectFileVersion>12.0.21005.1 + $(SolutionDir)$(Configuration).win32\ + $(Configuration).win32\ + false + $(SolutionDir)$(Configuration).win32\ + $(Configuration).win32\ + false + AllRules.ruleset + + + AllRules.ruleset + + + + + $(EngineRoot)external\win32\libs;$(MSBuildProgramFiles32)\Microsoft SDKs\Windows\v7.1A\lib;$(LibraryPath) + $(ProjectName) + + + ../../external/sqlite3/libraries/win32;$(MSBuildProgramFiles32)\Microsoft SDKs\Windows\v7.1A\lib;$(LibraryPath) + $(ProjectName) + + + + + + + + Disabled + $(ProjectDir)..\cocos;$(ProjectDir)..\external\sources;$(ProjectDir)..\cocos\renderer\gfx;$(ProjectDir)..\cocos\renderer;$(ProjectDir)..\external\win32\include\zlib;$(ProjectDir)..\external\win32\include\v8;$(ProjectDir)..\external\sources\firefox;$(projectDir)..;$(ProjectDir)..\external\win32\include;$(ProjectDir)..\external\win32\include\uv;$(ProjectDir)..\external\win32\include\uv + WIN32;_USRDLL;USING_V8_SHARED;_LIB;COCOS2D_DEBUG=1;JS_HAVE____INTN;JS_INTPTR_TYPE=int;COCOS2D_JAVASCRIPT=1;XP_WIN;_CRT_SECURE_NO_WARNINGS;_USRJSSTATIC;GLFW_EXPOSE_NATIVE_WIN32;GLFW_EXPOSE_NATIVE_WGL;HAVE_INSPECTOR;_WINDOWS;_WIN32;__MWERKS__;%(PreprocessorDefinitions) + false + EnableFastChecks + MultiThreadedDebugDLL + + + Level3 + OldStyle + 4267;4251;4244;%(DisableSpecificWarnings) + true + CompileAsCpp + $(IntDir)/%(RelativeDir) + + + if not exist "$(OutDir)" mkdir "$(OutDir)" +xcopy /Y /Q "$(ProjectDir)..\external\win32\libs\*.*" "$(OutDir)" +xcopy /Y /Q "$(ProjectDir)..\external\win32\libs\Debug\*.*" "$(OutDir)" + + + $(OutDir)$(ProjectName).dll + $(OutDir);%(AdditionalLibraryDirectories) + false + libcmtd.lib;%(IgnoreSpecificDefaultLibraries) + true + Windows + $(TargetDir)$(TargetName).lib + MachineX86 + sqlite3.lib;libcrypto.lib;libssl.lib;libcurl.lib;websockets.lib;libmpg123.lib;libogg.lib;libvorbis.lib;libvorbisfile.lib;OpenAL32.lib;version.lib;libwebp.lib;libuv.lib;v8_libplatform.dll.lib;v8_libbase.dll.lib;opengl32.lib;glew32.lib;libzlib.lib;Psapi.lib;Iphlpapi.lib;userenv.lib;ws2_32.lib;libiconv.lib;v8.dll.lib;winmm.lib;%(AdditionalDependencies) + + + + + + + + + + + + + $(ProjectDir)..\cocos;$(ProjectDir)..\external\sources;$(ProjectDir)..\cocos\renderer\gfx;$(ProjectDir)..\cocos\renderer;$(ProjectDir)..\external\win32\include\zlib;$(ProjectDir)..\external\win32\include\v8;$(ProjectDir)..\external\sources\firefox;$(projectDir)..;$(ProjectDir)..\external\win32\include;$(ProjectDir)..\external\win32\include\uv; + WIN32;_USRDLL;USING_V8_SHARED;GLFW_EXPOSE_NATIVE_WIN32;GLFW_EXPOSE_NATIVE_WGL;HAVE_INSPECTOR;_WINDOWS;_WIN32;__MWERKS__;%(PreprocessorDefinitions) + MultiThreadedDLL + + + Level3 + None + 4267;4251;4244;%(DisableSpecificWarnings) + true + CompileAsCpp + false + MinSpace + $(IntDir)/%(RelativeDir) + + + if not exist "$(OutDir)" mkdir "$(OutDir)" +xcopy /Y /Q "$(ProjectDir)..\..\external\win32\libs\*.*" "$(OutDir)" + + + + sqlite3.lib;libcrypto.lib;libssl.lib;libcurl.lib;websockets.lib;libmpg123.lib;libogg.lib;libvorbis.lib;libvorbisfile.lib;OpenAL32.lib;version.lib;libwebp.lib;libuv.lib;v8_libplatform.dll.lib;v8_libbase.dll.lib;%(AdditionalDependencies) + $(OutDir)$(ProjectName).dll + $(OutDir);%(AdditionalLibraryDirectories) + LIBCMTD.lib;%(IgnoreSpecificDefaultLibraries) + true + Windows + true + true + $(TargetDir)$(TargetName).lib + MachineX86 + + + + + + + + + + \ No newline at end of file diff --git a/native/build/libcocos2d.vcxproj.filters b/native/build/libcocos2d.vcxproj.filters new file mode 100644 index 0000000000..80ad43b448 --- /dev/null +++ b/native/build/libcocos2d.vcxproj.filters @@ -0,0 +1,877 @@ + + + + + base + + + base + + + base + + + base + + + base + + + base + + + base + + + base + + + base + + + base + + + base + + + base + + + base + + + base + + + base + + + base + + + base + + + base + + + base + + + math + + + math + + + math + + + math + + + math + + + math + + + math + + + math + + + math + + + math + + + renderer\gfx + + + renderer\gfx + + + renderer\gfx + + + renderer\gfx + + + renderer\gfx + + + renderer\gfx + + + renderer\gfx + + + renderer\gfx + + + renderer\gfx + + + renderer\gfx + + + renderer\gfx + + + renderer\gfx + + + renderer\gfx + + + renderer\gfx + + + renderer\renderer + + + renderer\renderer + + + renderer\renderer + + + renderer\renderer + + + renderer\renderer + + + renderer\renderer + + + renderer\renderer + + + renderer\renderer + + + renderer\renderer + + + renderer\renderer + + + renderer\renderer + + + renderer\renderer + + + renderer\renderer + + + renderer\renderer + + + renderer + + + js-bindings\auto + + + js-bindings\auto + + + js-bindings\manual + + + js-bindings\manual + + + js-bindings\manual + + + js-bindings\manual + + + js-bindings\manual + + + js-bindings\manual + + + js-bindings\event + + + js-bindings\jswrapper + + + js-bindings\jswrapper + + + js-bindings\jswrapper + + + js-bindings\jswrapper + + + js-bindings\jswrapper + + + js-bindings\jswrapper + + + js-bindings\jswrapper\v8 + + + js-bindings\jswrapper\v8 + + + js-bindings\jswrapper\v8 + + + js-bindings\jswrapper\v8 + + + js-bindings\jswrapper\v8 + + + js-bindings\jswrapper\v8 + + + js-bindings\jswrapper\v8 + + + js-bindings\jswrapper\v8 + + + js-bindings\jswrapper\v8 + + + js-bindings\jswrapper\v8 + + + js-bindings\jswrapper\v8 + + + js-bindings\jswrapper\v8 + + + js-bindings\jswrapper\v8 + + + js-bindings\jswrapper\v8 + + + js-bindings\jswrapper\v8 + + + + platform + + + platform + + + platform + + + platform\win32 + + + platform\win32 + + + platform\win32 + + + platform\win32 + + + external\unzip + + + external\unzip + + + external\unzip + + + external\tinyxml2 + + + external\firefox + + + external\firefox + + + external\firefox + + + external\ConvertUTF + + + external\ConvertUTF + + + base + + + platform\win32 + + + external\xxtea + + + + + base + + + base + + + base + + + base + + + base + + + base + + + base + + + base + + + base + + + base + + + base + + + base + + + base + + + base + + + base + + + base + + + base + + + base + + + base + + + base + + + base + + + base + + + base + + + base + + + base + + + base + + + base + + + math + + + math + + + math + + + math + + + math + + + math + + + math + + + math + + + math + + + math + + + math + + + math + + + renderer\gfx + + + renderer\gfx + + + renderer\gfx + + + renderer\gfx + + + renderer\gfx + + + renderer\gfx + + + renderer\gfx + + + renderer\gfx + + + renderer\gfx + + + renderer\gfx + + + renderer\gfx + + + renderer\gfx + + + renderer\gfx + + + renderer\gfx + + + renderer\renderer + + + renderer\renderer + + + renderer\renderer + + + renderer\renderer + + + renderer\renderer + + + renderer\renderer + + + renderer\renderer + + + renderer\renderer + + + renderer\renderer + + + renderer\renderer + + + renderer\renderer + + + renderer\renderer + + + renderer\renderer + + + renderer\renderer + + + renderer\renderer + + + renderer\renderer + + + renderer + + + renderer + + + js-bindings\auto + + + js-bindings\auto + + + js-bindings\manual + + + js-bindings\manual + + + js-bindings\manual + + + js-bindings\manual + + + js-bindings\manual + + + js-bindings\manual + + + js-bindings\event + + + js-bindings\jswrapper + + + js-bindings\jswrapper + + + js-bindings\jswrapper + + + js-bindings\jswrapper + + + js-bindings\jswrapper + + + js-bindings\jswrapper + + + js-bindings\jswrapper + + + js-bindings\jswrapper + + + js-bindings\jswrapper\v8 + + + js-bindings\jswrapper\v8 + + + js-bindings\jswrapper\v8 + + + js-bindings\jswrapper\v8 + + + js-bindings\jswrapper\v8 + + + js-bindings\jswrapper\v8 + + + js-bindings\jswrapper\v8 + + + js-bindings\jswrapper\v8 + + + js-bindings\jswrapper\v8 + + + js-bindings\jswrapper\v8 + + + js-bindings\jswrapper\v8 + + + js-bindings\jswrapper\v8 + + + js-bindings\jswrapper\v8 + + + js-bindings\jswrapper\v8 + + + js-bindings\jswrapper\v8 + + + js-bindings\jswrapper\v8 + + + js-bindings\jswrapper\v8 + + + js-bindings\jswrapper\v8 + + + js-bindings\jswrapper\v8 + + + js-bindings\jswrapper\v8 + + + js-bindings\jswrapper\v8 + + + js-bindings\jswrapper\v8 + + + + platform + + + platform + + + platform + + + platform + + + platform + + + platform + + + platform + + + platform + + + platform + + + platform\win32 + + + platform\win32 + + + platform\win32 + + + platform\win32 + + + platform\compat + + + external\unzip + + + external\unzip + + + external\unzip + + + external\unzip + + + external\tinyxml2 + + + external\firefox + + + external\firefox + + + external\firefox + + + external\firefox + + + external\firefox + + + external\firefox + + + external\firefox + + + external\firefox + + + external\firefox + + + external\firefox + + + external\firefox + + + external\firefox + + + external\firefox + + + external\firefox + + + external\firefox + + + external\firefox + + + external\firefox + + + external\firefox + + + external\firefox + + + external\ConvertUTF + + + base + + + platform\win32 + + + external\xxtea + + + + + {6a5f69d8-d02d-47cc-8131-8db6fe039a50} + + + {e46822d9-b9c5-478a-bc5c-58f05596ae33} + + + {f1074b9e-05d1-449e-a4fe-231be0b0f471} + + + {f777a81c-1489-45b5-b779-1863c8c1ca24} + + + {584857a2-7316-45cd-855e-c978b7ba49f5} + + + {b1ea90ed-adb4-4b5c-8909-d47a94d4cd69} + + + {c7fe8b88-0a77-47a2-a6f6-1ba6c0780e3f} + + + {766b04cb-29df-45b0-9cf6-0cf34e0a8946} + + + {2fb73413-4163-4cb7-84f9-04999528a918} + + + {99e2f021-bb2f-4066-b5d3-f325c4d58780} + + + {7979edde-e9e2-4380-9b85-1c4e179007ce} + + + {01e3df91-f31a-4667-9168-4243137023c8} + + + {72a6823d-4c79-4918-b029-f0a82c6eb46a} + + + {f88e61be-1179-4b36-955d-abf72181fa9e} + + + {aaf34557-236c-4e37-b157-1b20593e359f} + + + {a2211f5f-b9f5-4991-bae9-daa3f5473a78} + + + {bb37b797-0707-4912-8e2f-c2b090878e88} + + + {08f33107-f626-45a4-a2e6-af4a7875808d} + + + {cd4028d4-9f5d-4b3a-85f1-e2f8c3b7885d} + + + {9198c362-43e7-4445-affb-225d0257dea7} + + + + + math + + + math + + + math + + + math + + + math + + + math + + + math + + + math + + + math + + + \ No newline at end of file diff --git a/native/cocos/audio/apple/AudioCache.h b/native/cocos/audio/apple/AudioCache.h index 6174dcbdef..0a9127aa01 100644 --- a/native/cocos/audio/apple/AudioCache.h +++ b/native/cocos/audio/apple/AudioCache.h @@ -34,7 +34,7 @@ #include #include -#include "platform/CCPlatformMacros.h" +#include "base/ccMacros.h" #include "audio/apple/AudioMacros.h" NS_CC_BEGIN diff --git a/native/cocos/audio/apple/AudioPlayer.h b/native/cocos/audio/apple/AudioPlayer.h index db4c9a08aa..9c108ac7ed 100644 --- a/native/cocos/audio/apple/AudioPlayer.h +++ b/native/cocos/audio/apple/AudioPlayer.h @@ -28,7 +28,7 @@ #include "platform/CCPlatformConfig.h" #if CC_TARGET_PLATFORM == CC_PLATFORM_IOS || CC_TARGET_PLATFORM == CC_PLATFORM_MAC -#include "platform/CCPlatformMacros.h" +#include "base/ccMacros.h" #include "audio/apple/AudioMacros.h" #include diff --git a/native/cocos/audio/include/AudioEngine.h b/native/cocos/audio/include/AudioEngine.h index 81bd3668a8..3ab436cb21 100644 --- a/native/cocos/audio/include/AudioEngine.h +++ b/native/cocos/audio/include/AudioEngine.h @@ -26,7 +26,7 @@ #pragma once #include "platform/CCPlatformConfig.h" -#include "platform/CCPlatformMacros.h" +#include "base/ccMacros.h" #include "audio/include/Export.h" #include diff --git a/native/cocos/audio/win32/AudioCache.h b/native/cocos/audio/win32/AudioCache.h index 944ac73b36..2414efe4db 100644 --- a/native/cocos/audio/win32/AudioCache.h +++ b/native/cocos/audio/win32/AudioCache.h @@ -38,7 +38,7 @@ #else #include #endif -#include "platform/CCPlatformMacros.h" +#include "base/ccMacros.h" #include "audio/win32/AudioMacros.h" NS_CC_BEGIN diff --git a/native/cocos/audio/win32/AudioPlayer.h b/native/cocos/audio/win32/AudioPlayer.h index 84d2cfb940..60cfec91c0 100644 --- a/native/cocos/audio/win32/AudioPlayer.h +++ b/native/cocos/audio/win32/AudioPlayer.h @@ -38,7 +38,7 @@ #else #include #endif -#include "platform/CCPlatformMacros.h" +#include "base/ccMacros.h" NS_CC_BEGIN namespace experimental{ diff --git a/native/cocos/base/CCConfiguration.cpp b/native/cocos/base/CCConfiguration.cpp index 7d2cd93886..8b6257e53c 100644 --- a/native/cocos/base/CCConfiguration.cpp +++ b/native/cocos/base/CCConfiguration.cpp @@ -26,9 +26,7 @@ THE SOFTWARE. #include "base/CCConfiguration.h" #include "platform/CCFileUtils.h" -//cjh #include "base/CCEventCustom.h" -//cjh #include "base/CCDirector.h" -//cjh #include "base/CCEventDispatcher.h" +#include "base/CCLog.h" NS_CC_BEGIN diff --git a/native/cocos/base/CCConsole.cpp b/native/cocos/base/CCConsole.cpp deleted file mode 100644 index f905322358..0000000000 --- a/native/cocos/base/CCConsole.cpp +++ /dev/null @@ -1,1486 +0,0 @@ -/**************************************************************************** - Copyright (c) 2013-2016 Chukong Technologies Inc. - Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd. - - http://www.cocos2d-x.org - - Permission is hereby granted, free of charge, to any person obtaining a copy - of this software and associated documentation files (the "Software"), to deal - in the Software without restriction, including without limitation the rights - to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - copies of the Software, and to permit persons to whom the Software is - furnished to do so, subject to the following conditions: - - The above copyright notice and this permission notice shall be included in - all copies or substantial portions of the Software. - - THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - 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 "base/CCConsole.h" - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#if defined(_MSC_VER) || defined(__MINGW32__) -#include -#include -#include - -#if defined(__MINGW32__) -#include "platform/win32/inet_pton_mingw.h" -#endif - -#ifndef bzero -#define bzero(a, b) memset(a, 0, b); -#endif - -#else -#include -#include -#include -#include -#include -#include -#include -#endif - -#if CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID - -#ifndef bzero -#define bzero(a, b) memset(a, 0, b); -#endif - -#endif - -#include "base/CCDirector.h" -#include "base/CCScheduler.h" -#include "platform/CCPlatformConfig.h" -#include "base/CCConfiguration.h" -#include "2d/CCScene.h" -#include "platform/CCFileUtils.h" -#include "renderer/CCTextureCache.h" -#include "base/base64.h" -#include "base/ccUtils.h" -NS_CC_BEGIN - -extern const char* cocos2dVersion(void); - -#define PROMPT "> " - -static const size_t SEND_BUFSIZ = 512; - -/** private functions */ -namespace { -#if defined(__MINGW32__) - // inet - const char* inet_ntop(int af, const void* src, char* dst, int cnt) - { - struct sockaddr_in srcaddr; - - memset(&srcaddr, 0, sizeof(struct sockaddr_in)); - memcpy(&(srcaddr.sin_addr), src, sizeof(srcaddr.sin_addr)); - - srcaddr.sin_family = af; - if (WSAAddressToStringA((struct sockaddr*) &srcaddr, sizeof(struct sockaddr_in), 0, dst, (LPDWORD) &cnt) != 0) - { - return nullptr; - } - return dst; - } -#endif - - // - // Free functions to log - // - -#if (CC_TARGET_PLATFORM == CC_PLATFORM_WIN32) - void SendLogToWindow(const char *log) - { - static const int CCLOG_STRING_TAG = 1; - // Send data as a message - COPYDATASTRUCT myCDS; - myCDS.dwData = CCLOG_STRING_TAG; - myCDS.cbData = (DWORD)strlen(log) + 1; - myCDS.lpData = (PVOID)log; - if (Director::getInstance()->getOpenGLView()) - { - HWND hwnd = Director::getInstance()->getOpenGLView()->getWin32Window(); - SendMessage(hwnd, - WM_COPYDATA, - (WPARAM)(HWND)hwnd, - (LPARAM)(LPVOID)&myCDS); - } - } -#endif - - void _log(const char *format, va_list args) - { - int bufferSize = MAX_LOG_LENGTH; - char* buf = nullptr; - - do - { - buf = new (std::nothrow) char[bufferSize]; - if (buf == nullptr) - return; // not enough memory - - int ret = vsnprintf(buf, bufferSize - 3, format, args); - if (ret < 0) - { - bufferSize *= 2; - - delete [] buf; - } - else - break; - - } while (true); - - strcat(buf, "\n"); - -#if CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID - __android_log_print(ANDROID_LOG_DEBUG, "cocos2d-x debug info", "%s", buf); - -#elif CC_TARGET_PLATFORM == CC_PLATFORM_WIN32 - - int pos = 0; - int len = strlen(buf); - char tempBuf[MAX_LOG_LENGTH + 1] = { 0 }; - WCHAR wszBuf[MAX_LOG_LENGTH + 1] = { 0 }; - - do - { - std::copy(buf + pos, buf + pos + MAX_LOG_LENGTH, tempBuf); - - tempBuf[MAX_LOG_LENGTH] = 0; - - MultiByteToWideChar(CP_UTF8, 0, tempBuf, -1, wszBuf, sizeof(wszBuf)); - OutputDebugStringW(wszBuf); - WideCharToMultiByte(CP_ACP, 0, wszBuf, -1, tempBuf, sizeof(tempBuf), nullptr, FALSE); - printf("%s", tempBuf); - - pos += MAX_LOG_LENGTH; - - } while (pos < len); - SendLogToWindow(buf); - fflush(stdout); -#else - // Linux, Mac, iOS, etc - fprintf(stdout, "%s", buf); - fflush(stdout); -#endif - - Director::getInstance()->getConsole()->log(buf); - delete [] buf; - } -} - -// FIXME: Deprecated -void CCLog(const char * format, ...) -{ - va_list args; - va_start(args, format); - _log(format, args); - va_end(args); -} - -void log(const char * format, ...) -{ - va_list args; - va_start(args, format); - _log(format, args); - va_end(args); -} - -// -// Utility code -// - -std::string Console::Utility::_prompt(PROMPT); - -//TODO: these general utils should be in a separate class -// -// Trimming functions were taken from: http://stackoverflow.com/a/217605 -// -// trim from start - -std::string& Console::Utility::ltrim(std::string& s) { - s.erase(s.begin(), std::find_if(s.begin(), s.end(), std::not1(std::ptr_fun(std::isspace)))); - return s; -} - -// trim from end -std::string& Console::Utility::rtrim(std::string& s) { - s.erase(std::find_if(s.rbegin(), s.rend(), std::not1(std::ptr_fun(std::isspace))).base(), s.end()); - return s; -} - -// trim from both ends -std::string& Console::Utility::trim(std::string& s) { - return Console::Utility::ltrim(Console::Utility::rtrim(s)); -} - -std::vector& Console::Utility::split(const std::string& s, char delim, std::vector& elems) { - std::stringstream ss(s); - std::string item; - while (std::getline(ss, item, delim)) { - elems.push_back(item); - } - return elems; -} - -std::vector Console::Utility::split(const std::string& s, char delim) { - std::vector elems; - Console::Utility::split(s, delim, elems); - return elems; -} - -//isFloat taken from http://stackoverflow.com/questions/447206/c-isfloat-function -bool Console::Utility::isFloat(const std::string& myString) { - std::istringstream iss(myString); - float f; - iss >> std::noskipws >> f; // noskipws considers leading whitespace invalid - // Check the entire string was consumed and if either failbit or badbit is set - return iss.eof() && !iss.fail(); -} - -ssize_t Console::Utility::sendToConsole(int fd, const void* buffer, size_t length, int flags) -{ - if (_prompt.length() == length) { - if (strncmp(_prompt.c_str(), static_cast(buffer), length) == 0) { - fprintf(stderr,"bad parameter error: a buffer is the prompt string.\n"); - return 0; - } - } - - const char* buf = static_cast(buffer); - ssize_t retLen = 0; - for (size_t i = 0; i < length; ) { - size_t len = length - i; - if (SEND_BUFSIZ < len) len = SEND_BUFSIZ; - retLen += send(fd, buf + i, len, flags); - i += len; - } - return retLen; -} - -// dprintf() is not defined in Android -// so we add our own 'dpritnf' -ssize_t Console::Utility::mydprintf(int sock, const char *format, ...) -{ - va_list args; - char buf[16386]; - - va_start(args, format); - vsnprintf(buf, sizeof(buf), format, args); - va_end(args); - return sendToConsole(sock, buf, strlen(buf)); -} - -void Console::Utility::sendPrompt(int fd) -{ - const char* prompt = _prompt.c_str(); - send(fd, prompt, strlen(prompt), 0); -} - -void Console::Utility::setPrompt(const std::string &prompt) -{ - _prompt = prompt; -} - -const std::string& Console::Utility::getPrompt() -{ - return _prompt; -} - -// -// Command code -// - -void Console::Command::addCallback(const Callback& callback_) -{ - callback = callback_; -} - -void Console::Command::addSubCommand(const Command& subCmd) -{ - subCommands[subCmd.name] = subCmd; -} - -const Console::Command* Console::Command::getSubCommand(const std::string& subCmdName) const -{ - auto it = subCommands.find(subCmdName); - if(it != subCommands.end()) { - auto& subCmd = it->second; - return &subCmd; - } - return nullptr; -} - -void Console::Command::delSubCommand(const std::string& subCmdName) -{ - auto it = subCommands.find(subCmdName); - if(it != subCommands.end()) { - subCommands.erase(it); - } -} - -void Console::Command::commandHelp(int fd, const std::string& args) -{ - if (! help.empty()) { - Console::Utility::mydprintf(fd, "%s\n", help.c_str()); - } - - if (! subCommands.empty()) { - sendHelp(fd, subCommands, ""); - } -} - -void Console::Command::commandGeneric(int fd, const std::string& args) -{ - // The first argument (including the empty) - std::string key(args); - auto pos = args.find(" "); - if ((pos != std::string::npos) && (0 < pos)) { - key = args.substr(0, pos); - } - - // help - if (key == "help" || key == "-h") { - commandHelp(fd, args); - return; - } - - // find sub command - auto it = subCommands.find(key); - if (it != subCommands.end()) { - auto subCmd = it->second; - if (subCmd.callback) { - subCmd.callback(fd, args); - } - return; - } - - // can not find - if (callback) { - callback(fd, args); - } -} - -// -// Console code -// - -Console::Console() -: _listenfd(-1) -, _running(false) -, _endThread(false) -, _sendDebugStrings(false) -, _bindAddress("") -{ - createCommandAllocator(); - createCommandConfig(); - createCommandDebugMsg(); - createCommandDirector(); - createCommandExit(); - createCommandFileUtils(); - createCommandFps(); - createCommandHelp(); - createCommandProjection(); - createCommandResolution(); - createCommandSceneGraph(); - createCommandTexture(); - createCommandTouch(); - createCommandUpload(); - createCommandVersion(); -} - -Console::~Console() -{ - stop(); -} - -bool Console::listenOnTCP(int port) -{ - int listenfd = -1, n; - const int on = 1; - struct addrinfo hints, *res, *ressave; - char serv[30]; - - snprintf(serv, sizeof(serv)-1, "%d", port ); - - bzero(&hints, sizeof(struct addrinfo)); - hints.ai_flags = AI_PASSIVE; - hints.ai_family = AF_UNSPEC; - hints.ai_socktype = SOCK_STREAM; - -#if (CC_TARGET_PLATFORM == CC_PLATFORM_WIN32) - WSADATA wsaData; - n = WSAStartup(MAKEWORD(2, 2),&wsaData); -#endif - - if ( (n = getaddrinfo(nullptr, serv, &hints, &res)) != 0) { - fprintf(stderr,"net_listen error for %s: %s", serv, gai_strerror(n)); - return false; - } - - ressave = res; - - do { - listenfd = socket(res->ai_family, res->ai_socktype, res->ai_protocol); - if (listenfd < 0) - continue; /* error, try next one */ - - setsockopt(listenfd, SOL_SOCKET, SO_REUSEADDR, (const char*)&on, sizeof(on)); - - // bind address - if (!_bindAddress.empty()) - { - if (res->ai_family == AF_INET) - { - struct sockaddr_in *sin = (struct sockaddr_in*) res->ai_addr; - inet_pton(res->ai_family, _bindAddress.c_str(), (void*)&sin->sin_addr); - } - else if (res->ai_family == AF_INET6) - { - struct sockaddr_in6 *sin = (struct sockaddr_in6*) res->ai_addr; - inet_pton(res->ai_family, _bindAddress.c_str(), (void*)&sin->sin6_addr); - } - } - - if (bind(listenfd, res->ai_addr, res->ai_addrlen) == 0) - break; /* success */ - -/* bind error, close and try next one */ -#if (CC_TARGET_PLATFORM == CC_PLATFORM_WIN32) - closesocket(listenfd); -#else - close(listenfd); -#endif - } while ( (res = res->ai_next) != nullptr); - - if (res == nullptr) { - perror("net_listen:"); - freeaddrinfo(ressave); - return false; - } - - listen(listenfd, 50); - - if (res->ai_family == AF_INET) { - char buf[INET_ADDRSTRLEN] = ""; - struct sockaddr_in *sin = (struct sockaddr_in*) res->ai_addr; - if( inet_ntop(res->ai_family, &sin->sin_addr, buf, sizeof(buf)) != nullptr ) - cocos2d::log("Console: listening on %s : %d", buf, ntohs(sin->sin_port)); - else - perror("inet_ntop"); - } else if (res->ai_family == AF_INET6) { - char buf[INET6_ADDRSTRLEN] = ""; - struct sockaddr_in6 *sin = (struct sockaddr_in6*) res->ai_addr; - if( inet_ntop(res->ai_family, &sin->sin6_addr, buf, sizeof(buf)) != nullptr ) - cocos2d::log("Console: listening on %s : %d", buf, ntohs(sin->sin6_port)); - else - perror("inet_ntop"); - } - - - freeaddrinfo(ressave); - return listenOnFileDescriptor(listenfd); -} - -bool Console::listenOnFileDescriptor(int fd) -{ - if(_running) { - cocos2d::log("Console already started. 'stop' it before calling 'listen' again"); - return false; - } - - _listenfd = fd; - _thread = std::thread( std::bind( &Console::loop, this) ); - - return true; -} - -void Console::stop() -{ - if( _running ) { - _endThread = true; - if (_thread.joinable()) - { - _thread.join(); - } - } -} - -void Console::addCommand(const Command& cmd) -{ - _commands[cmd.name]=cmd; -} - -void Console::addSubCommand(const std::string& cmdName, const Command& subCmd) -{ - auto it = _commands.find(cmdName); - if(it != _commands.end()) { - auto& cmd = it->second; - addSubCommand(cmd, subCmd); - } -} - -void Console::addSubCommand(Command& cmd, const Command& subCmd) -{ - cmd.subCommands[subCmd.name] = subCmd; -} - -const Console::Command* Console::getCommand(const std::string& cmdName) -{ - auto it = _commands.find(cmdName); - if(it != _commands.end()) { - auto& cmd = it->second; - return &cmd; - } - return nullptr; -} - -const Console::Command* Console::getSubCommand(const std::string& cmdName, const std::string& subCmdName) -{ - auto it = _commands.find(cmdName); - if(it != _commands.end()) { - auto& cmd = it->second; - return getSubCommand(cmd, subCmdName); - } - return nullptr; -} - -const Console::Command* Console::getSubCommand(const Command& cmd, const std::string& subCmdName) -{ - return cmd.getSubCommand(subCmdName); -} - -void Console::delCommand(const std::string& cmdName) -{ - auto it = _commands.find(cmdName); - if(it != _commands.end()) { - _commands.erase(it); - } -} - -void Console::delSubCommand(const std::string& cmdName, const std::string& subCmdName) -{ - auto it = _commands.find(cmdName); - if(it != _commands.end()) { - auto& cmd = it->second; - delSubCommand(cmd, subCmdName); - } -} - -void Console::delSubCommand(Command& cmd, const std::string& subCmdName) -{ - cmd.delSubCommand(subCmdName); -} - -void Console::log(const char* buf) -{ - if( _sendDebugStrings ) { - _DebugStringsMutex.lock(); - _DebugStrings.push_back(buf); - _DebugStringsMutex.unlock(); - } -} - -void Console::setBindAddress(const std::string &address) -{ - _bindAddress = address; -} - -// -// Main Loop -// -void Console::loop() -{ - fd_set copy_set; - struct timeval timeout, timeout_copy; - - _running = true; - - FD_ZERO(&_read_set); - FD_SET(_listenfd, &_read_set); - _maxfd = _listenfd; - - timeout.tv_sec = 0; - - /* 0.016 seconds. Wake up once per frame at 60PFS */ - timeout.tv_usec = 16000; - - while(!_endThread) { - - copy_set = _read_set; - timeout_copy = timeout; - - int nready = select(_maxfd+1, ©_set, nullptr, nullptr, &timeout_copy); - - if( nready == -1 ) - { - /* error */ - if(errno != EINTR) - log("Abnormal error in select()\n"); - continue; - } - else if( nready == 0 ) - { - /* timeout. do something ? */ - } - else - { - /* new client */ - if(FD_ISSET(_listenfd, ©_set)) { - addClient(); - if(--nready <= 0) - continue; - } - - /* data from client */ - std::vector to_remove; - for(const auto &fd: _fds) { - if(FD_ISSET(fd,©_set)) - { - //fix Bug #4302 Test case ConsoleTest--ConsoleUploadFile crashed on Linux - //On linux, if you send data to a closed socket, the sending process will - //receive a SIGPIPE, which will cause linux system shutdown the sending process. - //Add this ioctl code to check if the socket has been closed by peer. - -#if (CC_TARGET_PLATFORM == CC_PLATFORM_WIN32) - u_long n = 0; - ioctlsocket(fd, FIONREAD, &n); -#else - int n = 0; - ioctl(fd, FIONREAD, &n); -#endif - if(n == 0) - { - //no data received, or fd is closed - continue; - } - - if( ! parseCommand(fd) ) - { - to_remove.push_back(fd); - } - if(--nready <= 0) - break; - } - } - - /* remove closed connections */ - for(int fd: to_remove) { - FD_CLR(fd, &_read_set); - _fds.erase(std::remove(_fds.begin(), _fds.end(), fd), _fds.end()); - } - } - - /* Any message for the remote console ? send it! */ - if( !_DebugStrings.empty() ) { - if (_DebugStringsMutex.try_lock()) - { - for (const auto &str : _DebugStrings) { - for (auto fd : _fds) { - Console::Utility::sendToConsole(fd, str.c_str(), str.length()); - } - } - _DebugStrings.clear(); - _DebugStringsMutex.unlock(); - } - } - } - - // clean up: ignore stdin, stdout and stderr - for(const auto &fd: _fds ) - { -#if (CC_TARGET_PLATFORM == CC_PLATFORM_WIN32) - closesocket(fd); -#else - close(fd); -#endif - } - -#if (CC_TARGET_PLATFORM == CC_PLATFORM_WIN32) - closesocket(_listenfd); - WSACleanup(); -#else - close(_listenfd); -#endif - _running = false; -} - -// -// Helpers -// - -ssize_t Console::readline(int fd, char* ptr, size_t maxlen) -{ - size_t n, rc; - char c; - - for( n = 0; n < maxlen - 1; n++ ) { - if( (rc = recv(fd, &c, 1, 0)) ==1 ) { - *ptr++ = c; - if(c == '\n') { - break; - } - } else if( rc == 0 ) { - return 0; - } else if( errno == EINTR ) { - continue; - } else { - return -1; - } - } - *ptr = 0; - return n; -} - -ssize_t Console::readBytes(int fd, char* buffer, size_t maxlen, bool* more) -{ - size_t n, rc; - char c, *ptr = buffer; - *more = false; - for( n = 0; n < maxlen; n++ ) { - if( (rc = recv(fd, &c, 1, 0)) ==1 ) { - *ptr++ = c; - if(c == '\n') { - return n; - } - } else if( rc == 0 ) { - return 0; - } else if( errno == EINTR ) { - continue; - } else { - return -1; - } - } - *more = true; - return n; -} - -bool Console::parseCommand(int fd) -{ - char buf[512]; - bool more_data; - auto h = readBytes(fd, buf, 6, &more_data); - if( h < 0) - { - return false; - } - if(strncmp(buf, "upload", 6) == 0) - { - char c = '\0'; - recv(fd, &c, 1, 0); - if(c == ' ') - { - commandUpload(fd); - Console::Utility::sendPrompt(fd); - return true; - } - else - { - const char err[] = "upload: invalid args! Type 'help' for options\n"; - Console::Utility::sendToConsole(fd, err, strlen(err)); - Console::Utility::sendPrompt(fd); - return true; - - } - } - if(!more_data) - { - buf[h] = 0; - } - else - { - char *pb = buf + 6; - auto r = readline(fd, pb, sizeof(buf)-6); - if(r < 0) - { - const char err[] = "Unknown error!\n"; - Console::Utility::sendPrompt(fd); - Console::Utility::sendToConsole(fd, err, strlen(err)); - return false; - } - } - std::string cmdLine; - - std::vector args; - cmdLine = std::string(buf); - - args = Console::Utility::split(cmdLine, ' '); - if(args.empty()) - { - const char err[] = "Unknown command. Type 'help' for options\n"; - Console::Utility::sendToConsole(fd, err, strlen(err)); - Console::Utility::sendPrompt(fd); - return true; - } - - auto it = _commands.find(Console::Utility::trim(args[0])); - if(it != _commands.end()) - { - std::string args2; - for(size_t i = 1; i < args.size(); ++i) - { - if(i > 1) - { - args2 += ' '; - } - args2 += Console::Utility::trim(args[i]); - - } - auto cmd = it->second; - cmd.commandGeneric(fd, args2); - }else if(strcmp(buf, "\r\n") != 0) { - const char err[] = "Unknown command. Type 'help' for options\n"; - Console::Utility::sendToConsole(fd, err, strlen(err)); - } - Console::Utility::sendPrompt(fd); - - return true; -} - -void Console::addClient() -{ - struct sockaddr client; - socklen_t client_len; - - /* new client */ - client_len = sizeof( client ); - int fd = accept(_listenfd, (struct sockaddr *)&client, &client_len ); - - // add fd to list of FD - if( fd != -1 ) { - FD_SET(fd, &_read_set); - _fds.push_back(fd); - _maxfd = std::max(_maxfd,fd); - - Console::Utility::sendPrompt(fd); - - /** - * A SIGPIPE is sent to a process if it tried to write to socket that had been shutdown for - * writing or isn't connected (anymore) on iOS. - * - * The default behaviour for this signal is to end the process.So we make the process ignore SIGPIPE. - */ -#if CC_TARGET_PLATFORM == CC_PLATFORM_IOS - int set = 1; - setsockopt(fd, SOL_SOCKET, SO_NOSIGPIPE, (void*)&set, sizeof(int)); -#endif - } -} - -// -// create commands -// - -void Console::createCommandAllocator() -{ - addCommand({"allocator", "Display allocator diagnostics for all allocators. Args: [-h | help | ]", - CC_CALLBACK_2(Console::commandAllocator, this)}); -} - -void Console::createCommandConfig() -{ - addCommand({"config", "Print the Configuration object. Args: [-h | help | ]", - CC_CALLBACK_2(Console::commandConfig, this)}); -} - -void Console::createCommandDebugMsg() -{ - addCommand({"debugmsg", "Whether or not to forward the debug messages on the console. Args: [-h | help | on | off | ]", - CC_CALLBACK_2(Console::commandDebugMsg, this)}); - addSubCommand("debugmsg", {"on", "enable debug logging", CC_CALLBACK_2(Console::commandDebugMsgSubCommandOnOff, this)}); - addSubCommand("debugmsg", {"off", "disable debug logging", CC_CALLBACK_2(Console::commandDebugMsgSubCommandOnOff, this)}); -} - -void Console::createCommandDirector() -{ - addCommand({"director", "director commands, type -h or [director help] to list supported directives"}); - addSubCommand("director", {"pause", "pause all scheduled timers, the draw rate will be 4 FPS to reduce CPU consumption", - CC_CALLBACK_2(Console::commandDirectorSubCommandPause, this)}); - addSubCommand("director", {"resume", "resume all scheduled timers", - CC_CALLBACK_2(Console::commandDirectorSubCommandResume, this)}); - addSubCommand("director", {"stop", "Stops the animation. Nothing will be drawn.", - CC_CALLBACK_2(Console::commandDirectorSubCommandStop, this)}); - addSubCommand("director", {"start", "Restart the animation again, Call this function only if [director stop] was called earlier", - CC_CALLBACK_2(Console::commandDirectorSubCommandStart, this)}); - addSubCommand("director", {"end", "exit this app.", - CC_CALLBACK_2(Console::commandDirectorSubCommandEnd, this)}); -} - -void Console::createCommandExit() -{ - addCommand({"exit", "Close connection to the console. Args: [-h | help | ]", CC_CALLBACK_2(Console::commandExit, this)}); -} - -void Console::createCommandFileUtils() -{ - addCommand({"fileutils", "Flush or print the FileUtils info. Args: [-h | help | flush | ]", - CC_CALLBACK_2(Console::commandFileUtils, this)}); - addSubCommand("fileutils", {"flush", "Purges the file searching cache.", - CC_CALLBACK_2(Console::commandFileUtilsSubCommandFlush, this)}); -} - -void Console::createCommandFps() -{ - addCommand({"fps", "Turn on / off the FPS. Args: [-h | help | on | off | ]", CC_CALLBACK_2(Console::commandFps, this)}); - addSubCommand("fps", {"on", "Display the FPS on the bottom-left corner.", CC_CALLBACK_2(Console::commandFpsSubCommandOnOff, this)}); - addSubCommand("fps", {"off", "Hide the FPS on the bottom-left corner.", CC_CALLBACK_2(Console::commandFpsSubCommandOnOff, this)}); -} - -void Console::createCommandHelp() -{ - addCommand({"help", "Print this message. Args: [ ]", CC_CALLBACK_2(Console::commandHelp, this)}); -} - -void Console::createCommandProjection() -{ - addCommand({"projection", "Change or print the current projection. Args: [-h | help | 2d | 3d | ]", - CC_CALLBACK_2(Console::commandProjection, this)}); - addSubCommand("projection", {"2d", "sets a 2D projection (orthogonal projection).", - CC_CALLBACK_2(Console::commandProjectionSubCommand2d, this)}); - addSubCommand("projection", {"3d", "sets a 3D projection with a fovy=60, znear=0.5f and zfar=1500.", - CC_CALLBACK_2(Console::commandProjectionSubCommand3d, this)}); -} - -void Console::createCommandResolution() -{ - addCommand({"resolution", "Change or print the window resolution. Args: [-h | help | width height resolution_policy | ]", - CC_CALLBACK_2(Console::commandResolution, this)}); - addSubCommand("resolution", {"", "", CC_CALLBACK_2(Console::commandResolutionSubCommandEmpty, this)}); -} - -void Console::createCommandSceneGraph() -{ - addCommand({"scenegraph", "Print the scene graph", CC_CALLBACK_2(Console::commandSceneGraph, this)}); -} - -void Console::createCommandTexture() -{ - addCommand({"texture", "Flush or print the TextureCache info. Args: [-h | help | flush | ] ", - CC_CALLBACK_2(Console::commandTextures, this)}); - addSubCommand("texture", {"flush", "Purges the dictionary of loaded textures.", - CC_CALLBACK_2(Console::commandTexturesSubCommandFlush, this)}); -} - -void Console::createCommandTouch() -{ - addCommand({"touch", "simulate touch event via console, type -h or [touch help] to list supported directives"}); - addSubCommand("touch", {"tap", "touch tap x y: simulate touch tap at (x,y).", - CC_CALLBACK_2(Console::commandTouchSubCommandTap, this)}); - addSubCommand("touch", {"swipe", "touch swipe x1 y1 x2 y2: simulate touch swipe from (x1,y1) to (x2,y2).", - CC_CALLBACK_2(Console::commandTouchSubCommandSwipe, this)}); -} - -void Console::createCommandUpload() -{ - addCommand({"upload", "upload file. Args: [filename base64_encoded_data]", CC_CALLBACK_1(Console::commandUpload, this)}); -} - -void Console::createCommandVersion() -{ - addCommand({"version", "print version string ", CC_CALLBACK_2(Console::commandVersion, this)}); -} - -// -// commands -// - -void Console::commandAllocator(int fd, const std::string& args) -{ -} - -void Console::commandConfig(int fd, const std::string& args) -{ - Scheduler *sched = Director::getInstance()->getScheduler(); - sched->performFunctionInCocosThread( [=](){ - Console::Utility::mydprintf(fd, "%s", Configuration::getInstance()->getInfo().c_str()); - Console::Utility::sendPrompt(fd); - }); -} - -void Console::commandDebugMsg(int fd, const std::string& args) -{ - Console::Utility::mydprintf(fd, "Debug message is: %s\n", _sendDebugStrings ? "on" : "off"); -} - -void Console::commandDebugMsgSubCommandOnOff(int fd, const std::string& args) -{ - _sendDebugStrings = (args.compare("on") == 0); -} - -void Console::commandDirectorSubCommandPause(int fd, const std::string& args) -{ - auto director = Director::getInstance(); - Scheduler *sched = director->getScheduler(); - sched->performFunctionInCocosThread( [](){ - Director::getInstance()->pause(); - }); -} - -void Console::commandDirectorSubCommandResume(int fd, const std::string& args) -{ - auto director = Director::getInstance(); - director->resume(); -} - -void Console::commandDirectorSubCommandStop(int fd, const std::string& args) -{ - auto director = Director::getInstance(); - Scheduler *sched = director->getScheduler(); - sched->performFunctionInCocosThread( [](){ - Director::getInstance()->stopAnimation(); - }); -} - -void Console::commandDirectorSubCommandStart(int fd, const std::string& args) -{ - auto director = Director::getInstance(); - director->startAnimation(); -} - -void Console::commandDirectorSubCommandEnd(int fd, const std::string& args) -{ - auto director = Director::getInstance(); - director->end(); -} - -void Console::commandExit(int fd, const std::string& args) -{ - FD_CLR(fd, &_read_set); - _fds.erase(std::remove(_fds.begin(), _fds.end(), fd), _fds.end()); -#if (CC_TARGET_PLATFORM == CC_PLATFORM_WIN32) - closesocket(fd); -#else - close(fd); -#endif -} - -void Console::commandFileUtils(int fd, const std::string& args) -{ - Scheduler *sched = Director::getInstance()->getScheduler(); - sched->performFunctionInCocosThread( std::bind(&Console::printFileUtils, this, fd) ); -} - -void Console::commandFileUtilsSubCommandFlush(int fd, const std::string& args) -{ - FileUtils::getInstance()->purgeCachedEntries(); -} - -void Console::commandFps(int fd, const std::string& args) -{ - Console::Utility::mydprintf(fd, "FPS is: %s\n", Director::getInstance()->isDisplayStats() ? "on" : "off"); -} - -void Console::commandFpsSubCommandOnOff(int fd, const std::string& args) -{ - bool state = (args.compare("on") == 0); - Director *dir = Director::getInstance(); - Scheduler *sched = dir->getScheduler(); - sched->performFunctionInCocosThread( std::bind(&Director::setDisplayStats, dir, state)); -} - -void Console::commandHelp(int fd, const std::string& args) -{ - sendHelp(fd, _commands, "\nAvailable commands:\n"); -} - -void Console::commandProjection(int fd, const std::string& args) -{ - auto director = Director::getInstance(); - char buf[20]; - auto proj = director->getProjection(); - switch (proj) { - case cocos2d::Director::Projection::_2D: - sprintf(buf,"2d"); - break; - case cocos2d::Director::Projection::_3D: - sprintf(buf,"3d"); - break; - case cocos2d::Director::Projection::CUSTOM: - sprintf(buf,"custom"); - break; - - default: - sprintf(buf,"unknown"); - break; - } - Console::Utility::mydprintf(fd, "Current projection: %s\n", buf); -} - -void Console::commandProjectionSubCommand2d(int fd, const std::string& args) -{ - auto director = Director::getInstance(); - Scheduler *sched = director->getScheduler(); - sched->performFunctionInCocosThread( [=](){ - director->setProjection(Director::Projection::_2D); - } ); -} - -void Console::commandProjectionSubCommand3d(int fd, const std::string& args) -{ - auto director = Director::getInstance(); - Scheduler *sched = director->getScheduler(); - sched->performFunctionInCocosThread( [=](){ - director->setProjection(Director::Projection::_3D); - } ); -} - -void Console::commandResolution(int fd, const std::string& args) -{ - int width, height, policy; - - std::istringstream stream( args ); - stream >> width >> height>> policy; - - Scheduler *sched = Director::getInstance()->getScheduler(); - sched->performFunctionInCocosThread( [=](){ - Director::getInstance()->getOpenGLView()->setDesignResolutionSize(width, height, static_cast(policy)); - } ); -} - -void Console::commandResolutionSubCommandEmpty(int fd, const std::string& args) -{ - auto director = Director::getInstance(); - Size points = director->getWinSize(); - Size pixels = director->getWinSizeInPixels(); - auto glview = director->getOpenGLView(); - Size design = glview->getDesignResolutionSize(); - ResolutionPolicy res = glview->getResolutionPolicy(); - Rect visibleRect = glview->getVisibleRect(); - - Console::Utility::mydprintf(fd, "Window Size:\n" - "\t%d x %d (points)\n" - "\t%d x %d (pixels)\n" - "\t%d x %d (design resolution)\n" - "Resolution Policy: %d\n" - "Visible Rect:\n" - "\torigin: %d x %d\n" - "\tsize: %d x %d\n", - (int)points.width, (int)points.height, - (int)pixels.width, (int)pixels.height, - (int)design.width, (int)design.height, - (int)res, - (int)visibleRect.origin.x, (int)visibleRect.origin.y, - (int)visibleRect.size.width, (int)visibleRect.size.height - ); -} - -void Console::commandSceneGraph(int fd, const std::string& args) -{ - Scheduler *sched = Director::getInstance()->getScheduler(); - sched->performFunctionInCocosThread( std::bind(&Console::printSceneGraphBoot, this, fd) ); -} - -void Console::commandTextures(int fd, const std::string& args) -{ - Scheduler *sched = Director::getInstance()->getScheduler(); - sched->performFunctionInCocosThread( [=](){ - Console::Utility::mydprintf(fd, "%s", Director::getInstance()->getTextureCache()->getCachedTextureInfo().c_str()); - Console::Utility::sendPrompt(fd); - }); -} - -void Console::commandTexturesSubCommandFlush(int fd, const std::string& args) -{ - Scheduler *sched = Director::getInstance()->getScheduler(); - sched->performFunctionInCocosThread( [](){ - Director::getInstance()->getTextureCache()->removeAllTextures(); - }); -} - -void Console::commandTouchSubCommandTap(int fd, const std::string& args) -{ - auto argv = Console::Utility::split(args,' '); - - if((argv.size() == 3 ) && (Console::Utility::isFloat(argv[1]) && Console::Utility::isFloat(argv[2]))) - { - - float x = utils::atof(argv[1].c_str()); - float y = utils::atof(argv[2].c_str()); - - std::srand ((unsigned)time(nullptr)); - _touchId = rand(); - Scheduler *sched = Director::getInstance()->getScheduler(); - sched->performFunctionInCocosThread( [&](){ - Director::getInstance()->getOpenGLView()->handleTouchesBegin(1, &_touchId, &x, &y); - Director::getInstance()->getOpenGLView()->handleTouchesEnd(1, &_touchId, &x, &y); - }); - } - else - { - const char msg[] = "touch: invalid arguments.\n"; - Console::Utility::sendToConsole(fd, msg, strlen(msg)); - } -} - -void Console::commandTouchSubCommandSwipe(int fd, const std::string& args) -{ - auto argv = Console::Utility::split(args,' '); - - if((argv.size() == 5) - && (Console::Utility::isFloat(argv[1])) && (Console::Utility::isFloat(argv[2])) - && (Console::Utility::isFloat(argv[3])) && (Console::Utility::isFloat(argv[4]))) - { - - float x1 = utils::atof(argv[1].c_str()); - float y1 = utils::atof(argv[2].c_str()); - float x2 = utils::atof(argv[3].c_str()); - float y2 = utils::atof(argv[4].c_str()); - - std::srand ((unsigned)time(nullptr)); - _touchId = rand(); - - Scheduler *sched = Director::getInstance()->getScheduler(); - sched->performFunctionInCocosThread( [=](){ - float tempx = x1, tempy = y1; - Director::getInstance()->getOpenGLView()->handleTouchesBegin(1, &_touchId, &tempx, &tempy); - }); - - float dx = std::abs(x1 - x2); - float dy = std::abs(y1 - y2); - float _x_ = x1, _y_ = y1; - if(dx > dy) - { - while(dx > 1) - { - - if(x1 < x2) - { - _x_ += 1; - } - if(x1 > x2) - { - _x_ -= 1; - } - if(y1 < y2) - { - _y_ += dy/dx; - } - if(y1 > y2) - { - _y_ -= dy/dx; - } - sched->performFunctionInCocosThread( [=](){ - float tempx = _x_, tempy = _y_; - Director::getInstance()->getOpenGLView()->handleTouchesMove(1, &_touchId, &tempx, &tempy); - }); - dx -= 1; - } - - } - else - { - while(dy > 1) - { - if(x1 < x2) - { - _x_ += dx/dy; - } - if(x1 > x2) - { - _x_ -= dx/dy; - } - if(y1 < y2) - { - _y_ += 1; - } - if(y1 > y2) - { - _y_ -= 1; - } - sched->performFunctionInCocosThread( [=](){ - float tempx = _x_, tempy = _y_; - Director::getInstance()->getOpenGLView()->handleTouchesMove(1, &_touchId, &tempx, &tempy); - }); - dy -= 1; - } - - } - - sched->performFunctionInCocosThread( [=](){ - float tempx = x2, tempy = y2; - Director::getInstance()->getOpenGLView()->handleTouchesEnd(1, &_touchId, &tempx, &tempy); - }); - - } - else - { - const char msg[] = "touch: invalid arguments.\n"; - Console::Utility::sendToConsole(fd, msg, strlen(msg)); - } -} - -static char invalid_filename_char[] = {':', '/', '\\', '?', '%', '*', '<', '>', '"', '|', '\r', '\n', '\t'}; - -void Console::commandUpload(int fd) -{ - ssize_t n, rc; - char buf[512], c; - char *ptr = buf; - //read file name - for( n = 0; n < sizeof(buf) - 1; n++ ) - { - if( (rc = recv(fd, &c, 1, 0)) ==1 ) - { - for(char x : invalid_filename_char) - { - if(c == x) - { - const char err[] = "upload: invalid file name!\n"; - Console::Utility::sendToConsole(fd, err, strlen(err)); - return; - } - } - if(c == ' ') - { - break; - } - *ptr++ = c; - } - else if( rc == 0 ) - { - break; - } - else if( errno == EINTR ) - { - continue; - } - else - { - break; - } - } - *ptr = 0; - - static std::string writablePath = FileUtils::getInstance()->getWritablePath(); - std::string filepath = writablePath + std::string(buf); - - FILE* fp = fopen(FileUtils::getInstance()->getSuitableFOpen(filepath).c_str(), "wb"); - if(!fp) - { - const char err[] = "can't create file!\n"; - Console::Utility::sendToConsole(fd, err, strlen(err)); - return; - } - - while (true) - { - char data[4]; - for(int i = 0; i < 4; i++) - { - data[i] = '='; - } - bool more_data; - readBytes(fd, data, 4, &more_data); - if(!more_data) - { - break; - } - unsigned char *decode; - unsigned char *in = (unsigned char *)data; - int dt = base64Decode(in, 4, &decode); - for(int i = 0; i < dt; i++) - { - fwrite(decode+i, 1, 1, fp); - } - free(decode); - } - fclose(fp); -} - -void Console::commandVersion(int fd, const std::string& args) -{ - Console::Utility::mydprintf(fd, "%s\n", cocos2dVersion()); -} - -// helper free functions - -int Console::printSceneGraph(int fd, Node* node, int level) -{ - int total = 1; - for(int i=0; igetDescription().c_str()); - - for(const auto& child: node->getChildren()) - total += printSceneGraph(fd, child, level+1); - - return total; -} - -void Console::printSceneGraphBoot(int fd) -{ - Console::Utility::sendToConsole(fd,"\n",1); - auto scene = Director::getInstance()->getRunningScene(); - int total = printSceneGraph(fd, scene, 0); - Console::Utility::mydprintf(fd, "Total Nodes: %d\n", total); - Console::Utility::sendPrompt(fd); -} - -void Console::printFileUtils(int fd) -{ - FileUtils* fu = FileUtils::getInstance(); - - Console::Utility::mydprintf(fd, "\nSearch Paths:\n"); - auto& list = fu->getSearchPaths(); - for( const auto &item : list) { - Console::Utility::mydprintf(fd, "%s\n", item.c_str()); - } - - Console::Utility::mydprintf(fd, "\nResolution Order:\n"); - auto& list1 = fu->getSearchResolutionsOrder(); - for( const auto &item : list1) { - Console::Utility::mydprintf(fd, "%s\n", item.c_str()); - } - - Console::Utility::mydprintf(fd, "\nWritable Path:\n"); - Console::Utility::mydprintf(fd, "%s\n", fu->getWritablePath().c_str()); - - Console::Utility::mydprintf(fd, "\nFull Path Cache:\n"); - auto& cache = fu->getFullPathCache(); - for( const auto &item : cache) { - Console::Utility::mydprintf(fd, "%s -> %s\n", item.first.c_str(), item.second.c_str()); - } - Console::Utility::sendPrompt(fd); -} - -void Console::sendHelp(int fd, const std::map& commands, const char* msg) -{ - Console::Utility::sendToConsole(fd, msg, strlen(msg)); - for(auto it=commands.begin();it!=commands.end();++it) - { - auto command = it->second; - if (command.help.empty()) continue; - - Console::Utility::mydprintf(fd, "\t%s", command.name.c_str()); - ssize_t tabs = strlen(command.name.c_str()) / 8; - tabs = 3 - tabs; - for(int j=0;j -#include - -#ifndef __SSIZE_T -#define __SSIZE_T -typedef SSIZE_T ssize_t; -#endif // __SSIZE_T - -#else -#include -#endif - -#include -#include -#include -#include -#include -#include -#include - -#include "base/CCRef.h" -#include "base/ccMacros.h" -#include "platform/CCPlatformMacros.h" - -NS_CC_BEGIN - -/// The max length of CCLog message. -static const int MAX_LOG_LENGTH = 16*1024; - -/** - @brief Output Debug message. - */ -void CC_DLL log(const char * format, ...) CC_FORMAT_PRINTF(1, 2); - -/** Console is helper class that lets the developer control the game from TCP connection. - Console will spawn a new thread that will listen to a specified TCP port. - Console has a basic token parser. Each token is associated with an std::function. - If the std::function<> needs to use the cocos2d API, it needs to call - - ``` - scheduler->performFunctionInCocosThread( ... ); - ``` - */ - -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& split(const std::string& s, char delim, std::vector& elems); - static std::vector 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; - std::string name; - std::string help; - Callback callback{nullptr}; - std::map 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 */ - Console(); - - /** Destructor */ - virtual ~Console(); - - /** starts listening to specified TCP port */ - bool listenOnTCP(int port); - - /** starts listening to specified file descriptor */ - bool listenOnFileDescriptor(int fd); - - /** stops the Console. 'stop' will be called at destruction time as well */ - void stop(); - - /** 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); - - /** - * set bind address - * - * @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 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 commandVersion(int fd, const std::string& args); - // file descriptor: socket, console, etc. - int _listenfd; - int _maxfd; - std::vector _fds; - std::thread _thread; - - fd_set _read_set; - - bool _running; - bool _endThread; - - std::map _commands; - - // strings generated by cocos2d sent to the remote console - bool _sendDebugStrings; - std::mutex _DebugStringsMutex; - std::vector _DebugStrings; - - intptr_t _touchId; - - 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& commands, const char* msg); -}; - -NS_CC_END - -/// @endcond -#endif /* defined(__CCCONSOLE_H__) */ diff --git a/native/cocos/base/CCData.cpp b/native/cocos/base/CCData.cpp index 40e10777dc..fa68fd41e9 100644 --- a/native/cocos/base/CCData.cpp +++ b/native/cocos/base/CCData.cpp @@ -25,7 +25,6 @@ ****************************************************************************/ #include "base/CCData.h" -#include "base/CCConsole.h" NS_CC_BEGIN diff --git a/native/cocos/base/CCData.h b/native/cocos/base/CCData.h index 07bc7c0ba7..0bdca9e831 100644 --- a/native/cocos/base/CCData.h +++ b/native/cocos/base/CCData.h @@ -27,7 +27,7 @@ #ifndef __CCDATA_H__ #define __CCDATA_H__ -#include "platform/CCPlatformMacros.h" +#include "base/ccMacros.h" #include // for ssize_t on android #include // for ssize_t on linux #include "platform/CCStdC.h" // for ssize_t on window diff --git a/native/cocos/base/CCDataVisitor.cpp b/native/cocos/base/CCDataVisitor.cpp deleted file mode 100644 index e06c9df977..0000000000 --- a/native/cocos/base/CCDataVisitor.cpp +++ /dev/null @@ -1,221 +0,0 @@ -/**************************************************************************** - Copyright (c) 2013-2016 Chukong Technologies Inc. - Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd. - - http://www.cocos2d-x.org - - Permission is hereby granted, free of charge, to any person obtaining a copy - of this software and associated documentation files (the "Software"), to deal - in the Software without restriction, including without limitation the rights - to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - copies of the Software, and to permit persons to whom the Software is - furnished to do so, subject to the following conditions: - - The above copyright notice and this permission notice shall be included in - all copies or substantial portions of the Software. - - THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - 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 "base/CCRef.h" - -NS_CC_BEGIN - -void DataVisitor::visit(const __Bool *value) -{ - visitObject(value); -} - -void DataVisitor::visit(const __Integer *value) -{ - visitObject(value); -} - -void DataVisitor::visit(const __Float *value) -{ - visitObject(value); -} - -void DataVisitor::visit(const __Double *value) -{ - visitObject(value); -} - -void DataVisitor::visit(const __String *value) -{ - visitObject(value); -} - -void DataVisitor::visit(const __Array *value) -{ - visitObject(value); -} - -void DataVisitor::visit(const __Dictionary *value) -{ - visitObject(value); -} - -void DataVisitor::visit(const __Set *value) -{ - visitObject(value); -} - -// PrettyPrinter -PrettyPrinter::PrettyPrinter(int indentLevel/* = 0 */) -{ - setIndentLevel(indentLevel); -} - -void PrettyPrinter::clear() -{ - _result.clear(); -} - -std::string PrettyPrinter::getResult() -{ - return _result; -} - -void PrettyPrinter::visitObject(const Ref *p) -{ - char buf[50] = {0}; - sprintf(buf, "%p", p); - _result += buf; -} - -void PrettyPrinter::visit(const __Bool * p) -{ - char buf[50] = {0}; - sprintf(buf, "%s", p->getValue() ? "true" : "false"); - _result += buf; -} - -void PrettyPrinter::visit(const __Integer *p) -{ - char buf[50] = {0}; - sprintf(buf, "%d", p->getValue()); - _result += buf; -} - -void PrettyPrinter::visit(const __Float *p) -{ - char buf[50] = {0}; - sprintf(buf, "%f", p->getValue()); - _result += buf; -} - -void PrettyPrinter::visit(const __Double *p) -{ - char buf[50] = {0}; - sprintf(buf, "%lf", p->getValue()); - _result += buf; -} - -void PrettyPrinter::visit(const __String *p) -{ - _result += p->getCString(); -} - -void PrettyPrinter::visit(const __Array *p) -{ - _result += "\n"; - _result += _indentStr; - _result += "\n"; - - setIndentLevel(_indentLevel+1); - Ref* obj; - int i = 0; - char buf[50] = {0}; - CCARRAY_FOREACH(p, obj) - { - if (i > 0) { - _result += "\n"; - } - sprintf(buf, "%s%02d: ", _indentStr.c_str(), i); - _result += buf; - PrettyPrinter v(_indentLevel); -//FIXME:james obj->acceptVisitor(v); - _result += v.getResult(); - i++; - } - setIndentLevel(_indentLevel-1); - - _result += "\n"; - _result += _indentStr; - _result += ""; -} - -void PrettyPrinter::visit(const __Dictionary *p) -{ - _result += "\n"; - _result += _indentStr; - _result += "\n"; - - setIndentLevel(_indentLevel+1); - DictElement* element; - bool bFirstElement = true; - char buf[1000] = {0}; - CCDICT_FOREACH(p, element) - { - if (!bFirstElement) { - _result += "\n"; - } - sprintf(buf, "%s%s: ", _indentStr.c_str(),element->getStrKey()); - _result += buf; - PrettyPrinter v(_indentLevel); -//FIXME:james element->getObject()->acceptVisitor(v); - _result += v.getResult(); - bFirstElement = false; - } - setIndentLevel(_indentLevel-1); - - _result += "\n"; - _result += _indentStr; - _result += ""; -} - -void PrettyPrinter::visit(const __Set *p) -{ - _result += "\n"; - _result += _indentStr; - _result += "\n"; - - setIndentLevel(_indentLevel+1); - - int i = 0; - __Set* tmp = const_cast<__Set*>(p); - __SetIterator it = tmp->begin(); - - for (; it != tmp->end(); ++it, ++i) { - if (i > 0) { - _result += "\n"; - } - _result += _indentStr.c_str(); - PrettyPrinter v(_indentLevel); -//FIXME:james (*it)->acceptVisitor(v); - _result += v.getResult(); - } - setIndentLevel(_indentLevel-1); - - _result += "\n"; - _result += _indentStr; - _result += "\n"; -} - -void PrettyPrinter::setIndentLevel(int indentLevel) -{ - _indentLevel = indentLevel; - _indentStr.clear(); - for (int i = 0; i < _indentLevel; ++i) { - _indentStr += "\t"; - } -} - -NS_CC_END diff --git a/native/cocos/base/CCDataVisitor.h b/native/cocos/base/CCDataVisitor.h deleted file mode 100644 index b6ae49a716..0000000000 --- a/native/cocos/base/CCDataVisitor.h +++ /dev/null @@ -1,113 +0,0 @@ -/**************************************************************************** - Copyright (c) 2013-2016 Chukong Technologies Inc. - Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd. - - http://www.cocos2d-x.org - - Permission is hereby granted, free of charge, to any person obtaining a copy - of this software and associated documentation files (the "Software"), to deal - in the Software without restriction, including without limitation the rights - to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - copies of the Software, and to permit persons to whom the Software is - furnished to do so, subject to the following conditions: - - The above copyright notice and this permission notice shall be included in - all copies or substantial portions of the Software. - - THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - 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. - ****************************************************************************/ - -#ifndef __CCDATAVISITOR_H__ -#define __CCDATAVISITOR_H__ -/// @cond DO_NOT_SHOW - -#include "platform/CCPlatformMacros.h" -#include - -NS_CC_BEGIN - -class Ref; -class __Bool; -class __Integer; -class __Float; -class __Double; -class __String; -class __Array; -class __Dictionary; -class __Set; - -/** - * Visitor that helps to perform action that depends on polymorphic object type - * - * Use cases: - * - data serialization, - * - pretty printing of Ref* - * - safe value reading from Array, __Dictionary, Set - * - * Usage: - * 1. subclass DataVisitor - * 2. overload visit() methods for object that you need to handle - * 3. handle other objects in visitObject() - * 4. pass your visitor to Object::acceptVisitor() - */ -class CC_DLL DataVisitor -{ -public: - /** - * @js NA - * @lua NA - */ - virtual ~DataVisitor() {} - - /** default method, called from non-overloaded methods and for unrecognized objects */ - virtual void visitObject(const Ref *p) = 0; - - virtual void visit(const __Bool *p); - virtual void visit(const __Integer *p); - virtual void visit(const __Float *p); - virtual void visit(const __Double *p); - virtual void visit(const __String *p); - virtual void visit(const __Array *p); - virtual void visit(const __Dictionary *p); - virtual void visit(const __Set *p); -}; - - -class CC_DLL PrettyPrinter : public DataVisitor -{ -public: - PrettyPrinter(int indentLevel = 0); - - virtual void clear(); - virtual std::string getResult(); - - virtual void visitObject(const Ref *p); - virtual void visit(const __Bool * p); - virtual void visit(const __Integer *p); - virtual void visit(const __Float *p); - virtual void visit(const __Double *p); - virtual void visit(const __String *p); - virtual void visit(const __Array *p); - virtual void visit(const __Dictionary *p); - virtual void visit(const __Set *p); -private: - void setIndentLevel(int indentLevel); - int _indentLevel; - std::string _indentStr; - std::string _result; -}; - -/** - * @endcond - */ - -NS_CC_END - -/// @endcond -#endif // __CCDATAVISITOR_H__ diff --git a/native/cocos/base/CCEvent.cpp b/native/cocos/base/CCEvent.cpp deleted file mode 100644 index c7928d51e0..0000000000 --- a/native/cocos/base/CCEvent.cpp +++ /dev/null @@ -1,42 +0,0 @@ -/**************************************************************************** - Copyright (c) 2013-2016 Chukong Technologies Inc. - Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd. - - http://www.cocos2d-x.org - - Permission is hereby granted, free of charge, to any person obtaining a copy - of this software and associated documentation files (the "Software"), to deal - in the Software without restriction, including without limitation the rights - to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - copies of the Software, and to permit persons to whom the Software is - furnished to do so, subject to the following conditions: - - The above copyright notice and this permission notice shall be included in - all copies or substantial portions of the Software. - - THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - 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 "base/CCEvent.h" - -NS_CC_BEGIN - -Event::Event(Type type) -: _type(type) -, _isStopped(false) -, _currentTarget(nullptr) -{ -} - -Event::~Event() -{ -} - - -NS_CC_END diff --git a/native/cocos/base/CCEvent.h b/native/cocos/base/CCEvent.h deleted file mode 100644 index acbbcaf721..0000000000 --- a/native/cocos/base/CCEvent.h +++ /dev/null @@ -1,108 +0,0 @@ -/**************************************************************************** - Copyright (c) 2013-2016 Chukong Technologies Inc. - Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd. - - http://www.cocos2d-x.org - - Permission is hereby granted, free of charge, to any person obtaining a copy - of this software and associated documentation files (the "Software"), to deal - in the Software without restriction, including without limitation the rights - to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - copies of the Software, and to permit persons to whom the Software is - furnished to do so, subject to the following conditions: - - The above copyright notice and this permission notice shall be included in - all copies or substantial portions of the Software. - - THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - 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. - ****************************************************************************/ - - -#ifndef __CCEVENT_H__ -#define __CCEVENT_H__ - -#include "base/CCRef.h" -#include "platform/CCPlatformMacros.h" - -/** - * @addtogroup base - * @{ - */ - -NS_CC_BEGIN - -class Node; - -/** @class Event - * @brief Base class of all kinds of events. - */ -class CC_DLL Event : public Ref -{ -public: - /** Type Event type.*/ - enum class Type - { - TOUCH, - KEYBOARD, - ACCELERATION, - MOUSE, - FOCUS, - GAME_CONTROLLER, - CUSTOM - }; - -CC_CONSTRUCTOR_ACCESS: - /** Constructor */ - Event(Type type); -protected: - /** Destructor. - */ - virtual ~Event(); -public: - /** Gets the event type. - * - * @return The event type. - */ - inline Type getType() const { return _type; }; - - /** Stops propagation for current event. - */ - inline void stopPropagation() { _isStopped = true; }; - - /** Checks whether the event has been stopped. - * - * @return True if the event has been stopped. - */ - inline bool isStopped() const { return _isStopped; }; - - /** Gets current target of the event. - * @return The target with which the event associates. - * @note It's only available when the event listener is associated with node. - * It returns 0 when the listener is associated with fixed priority. - */ - inline Node* getCurrentTarget() { return _currentTarget; }; - -protected: - /** Sets current target */ - inline void setCurrentTarget(Node* target) { _currentTarget = target; }; - - Type _type; ///< Event type - - bool _isStopped; ///< whether the event has been stopped. - Node* _currentTarget; ///< Current target - - friend class EventDispatcher; -}; - -NS_CC_END - -// end of base group -/// @} - -#endif // __CCEVENT_H__ diff --git a/native/cocos/base/CCEventAcceleration.cpp b/native/cocos/base/CCEventAcceleration.cpp deleted file mode 100644 index 081e213660..0000000000 --- a/native/cocos/base/CCEventAcceleration.cpp +++ /dev/null @@ -1,37 +0,0 @@ -/**************************************************************************** - Copyright (c) 2013-2016 Chukong Technologies Inc. - Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd. - - http://www.cocos2d-x.org - - Permission is hereby granted, free of charge, to any person obtaining a copy - of this software and associated documentation files (the "Software"), to deal - in the Software without restriction, including without limitation the rights - to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - copies of the Software, and to permit persons to whom the Software is - furnished to do so, subject to the following conditions: - - The above copyright notice and this permission notice shall be included in - all copies or substantial portions of the Software. - - THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - 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 "base/CCEventAcceleration.h" - -NS_CC_BEGIN - -EventAcceleration::EventAcceleration(const Acceleration& acc) -: Event(Type::ACCELERATION) -, _acc(acc) -{ -} - -NS_CC_END - diff --git a/native/cocos/base/CCEventCustom.cpp b/native/cocos/base/CCEventCustom.cpp deleted file mode 100644 index 2db37f00e6..0000000000 --- a/native/cocos/base/CCEventCustom.cpp +++ /dev/null @@ -1,38 +0,0 @@ -/**************************************************************************** - Copyright (c) 2013-2016 Chukong Technologies Inc. - Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd. - - http://www.cocos2d-x.org - - Permission is hereby granted, free of charge, to any person obtaining a copy - of this software and associated documentation files (the "Software"), to deal - in the Software without restriction, including without limitation the rights - to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - copies of the Software, and to permit persons to whom the Software is - furnished to do so, subject to the following conditions: - - The above copyright notice and this permission notice shall be included in - all copies or substantial portions of the Software. - - THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - 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 "base/CCEventCustom.h" -#include "base/CCEvent.h" - -NS_CC_BEGIN - -EventCustom::EventCustom(const std::string& eventName) -: Event(Type::CUSTOM) -, _userData(nullptr) -, _eventName(eventName) -{ -} - -NS_CC_END diff --git a/native/cocos/base/CCEventCustom.h b/native/cocos/base/CCEventCustom.h deleted file mode 100644 index 1870be80b1..0000000000 --- a/native/cocos/base/CCEventCustom.h +++ /dev/null @@ -1,82 +0,0 @@ -/**************************************************************************** - Copyright (c) 2013-2016 Chukong Technologies Inc. - Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd. - - http://www.cocos2d-x.org - - Permission is hereby granted, free of charge, to any person obtaining a copy - of this software and associated documentation files (the "Software"), to deal - in the Software without restriction, including without limitation the rights - to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - copies of the Software, and to permit persons to whom the Software is - furnished to do so, subject to the following conditions: - - The above copyright notice and this permission notice shall be included in - all copies or substantial portions of the Software. - - THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - 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. - ****************************************************************************/ - -#ifndef __cocos2d_libs__CCCustomEvent__ -#define __cocos2d_libs__CCCustomEvent__ - -#include -#include "base/CCEvent.h" - -/** - * @addtogroup base - * @{ - */ - -NS_CC_BEGIN - -/** @class EventCustom - * @brief Custom event. - */ -class CC_DLL EventCustom : public Event -{ -public: - /** Constructor. - * - * @param eventName A given name of the custom event. - * @js ctor - */ - EventCustom(const std::string& eventName); - - /** Sets user data. - * - * @param data The user data pointer, it's a void*. - */ - inline void setUserData(void* data) { _userData = data; }; - - /** Gets user data. - * - * @return The user data pointer, it's a void*. - */ - inline void* getUserData() const { return _userData; }; - - /** Gets event name. - * - * @return The name of the event. - */ - inline const std::string& getEventName() const { return _eventName; }; -protected: - virtual ~EventCustom() {} - - void* _userData; ///< User data - std::string _eventName; -}; - -NS_CC_END - -// end of base group -/// @} - -#endif /* defined(__cocos2d_libs__CCCustomEvent__) */ - diff --git a/native/cocos/base/CCEventFocus.cpp b/native/cocos/base/CCEventFocus.cpp deleted file mode 100644 index 34503dfdf3..0000000000 --- a/native/cocos/base/CCEventFocus.cpp +++ /dev/null @@ -1,44 +0,0 @@ -/**************************************************************************** - Copyright (c) 2014 cocos2d-x.org - Copyright (c) 2014-2016 Chukong Technologies Inc. - Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd. - - http://www.cocos2d-x.org - - Permission is hereby granted, free of charge, to any person obtaining a copy - of this software and associated documentation files (the "Software"), to deal - in the Software without restriction, including without limitation the rights - to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - copies of the Software, and to permit persons to whom the Software is - furnished to do so, subject to the following conditions: - - The above copyright notice and this permission notice shall be included in - all copies or substantial portions of the Software. - - THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - 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 "base/CCEventFocus.h" - -NS_CC_BEGIN - - -EventFocus::EventFocus(ui::Widget *widgetLoseFocus, ui::Widget* widgetGetFocus) -:Event(Type::FOCUS), -_widgetGetFocus(widgetGetFocus), -_widgetLoseFocus(widgetLoseFocus) -{ - -} - - - - -NS_CC_END - diff --git a/native/cocos/base/CCEventFocus.h b/native/cocos/base/CCEventFocus.h deleted file mode 100644 index fd372c3472..0000000000 --- a/native/cocos/base/CCEventFocus.h +++ /dev/null @@ -1,73 +0,0 @@ -/**************************************************************************** - Copyright (c) 2014 cocos2d-x.org - Copyright (c) 2014-2016 Chukong Technologies Inc. - Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd. - - http://www.cocos2d-x.org - - Permission is hereby granted, free of charge, to any person obtaining a copy - of this software and associated documentation files (the "Software"), to deal - in the Software without restriction, including without limitation the rights - to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - copies of the Software, and to permit persons to whom the Software is - furnished to do so, subject to the following conditions: - - The above copyright notice and this permission notice shall be included in - all copies or substantial portions of the Software. - - THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - 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. - ****************************************************************************/ - -#ifndef __cocos2d_libs__CCEventFocus__ -#define __cocos2d_libs__CCEventFocus__ - -#include "base/CCEvent.h" - -/** - * @addtogroup base - * @{ - */ - -NS_CC_BEGIN - -namespace ui { - class Widget; -} - -/** @class EventFocus - * @brief Focus event. - */ -class CC_DLL EventFocus : public Event -{ -public: - /** Constructor. - * - * @param widgetLoseFocus The widget which lose focus. - * @param widgetGetFocus The widget which get focus. - * @js ctor - */ - EventFocus(ui::Widget* widgetLoseFocus, ui::Widget* widgetGetFocus); - -private: - virtual ~EventFocus() {} - - ui::Widget *_widgetGetFocus; - ui::Widget *_widgetLoseFocus; - - friend class EventListenerFocus; -}; - - -NS_CC_END - -// end of base group -/// @} - -#endif /* defined(__cocos2d_libs__CCEventFocus__) */ - diff --git a/native/cocos/base/CCEventKeyboard.cpp b/native/cocos/base/CCEventKeyboard.cpp deleted file mode 100644 index 2c426a42ee..0000000000 --- a/native/cocos/base/CCEventKeyboard.cpp +++ /dev/null @@ -1,38 +0,0 @@ -/**************************************************************************** - Copyright (c) 2013-2016 Chukong Technologies Inc. - Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd. - - http://www.cocos2d-x.org - - Permission is hereby granted, free of charge, to any person obtaining a copy - of this software and associated documentation files (the "Software"), to deal - in the Software without restriction, including without limitation the rights - to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - copies of the Software, and to permit persons to whom the Software is - furnished to do so, subject to the following conditions: - - The above copyright notice and this permission notice shall be included in - all copies or substantial portions of the Software. - - THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - 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 "base/CCEventKeyboard.h" - -NS_CC_BEGIN - -EventKeyboard::EventKeyboard(KeyCode keyCode, bool isPressed) -: Event(Type::KEYBOARD) -, _keyCode(keyCode) -, _isPressed(isPressed) -{} - -NS_CC_END - diff --git a/native/cocos/base/CCEventKeyboard.h b/native/cocos/base/CCEventKeyboard.h deleted file mode 100644 index 9b0f8f0b21..0000000000 --- a/native/cocos/base/CCEventKeyboard.h +++ /dev/null @@ -1,246 +0,0 @@ -/**************************************************************************** - Copyright (c) 2013-2016 Chukong Technologies Inc. - Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd. - - http://www.cocos2d-x.org - - Permission is hereby granted, free of charge, to any person obtaining a copy - of this software and associated documentation files (the "Software"), to deal - in the Software without restriction, including without limitation the rights - to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - copies of the Software, and to permit persons to whom the Software is - furnished to do so, subject to the following conditions: - - The above copyright notice and this permission notice shall be included in - all copies or substantial portions of the Software. - - THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - 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. - - ****************************************************************************/ - -#ifndef __cocos2d_libs__CCKeyboardEvent__ -#define __cocos2d_libs__CCKeyboardEvent__ - -#include "base/CCEvent.h" - -/** - * @addtogroup base - * @{ - */ - -NS_CC_BEGIN - -/** @class EventKeyboard - * @brief Keyboard event. - */ -class CC_DLL EventKeyboard : public Event -{ -public: - /** - * KeyCode The key (code). - * @js NA - */ - enum class KeyCode - { - KEY_NONE, - KEY_PAUSE, - KEY_SCROLL_LOCK, - KEY_PRINT, - KEY_SYSREQ, - KEY_BREAK, - KEY_ESCAPE, - KEY_BACK = KEY_ESCAPE, - KEY_BACKSPACE, - KEY_TAB, - KEY_BACK_TAB, - KEY_RETURN, - KEY_CAPS_LOCK, - KEY_SHIFT, - KEY_LEFT_SHIFT = KEY_SHIFT, - KEY_RIGHT_SHIFT, - KEY_CTRL, - KEY_LEFT_CTRL = KEY_CTRL, - KEY_RIGHT_CTRL, - KEY_ALT, - KEY_LEFT_ALT = KEY_ALT, - KEY_RIGHT_ALT, - KEY_MENU, - KEY_HYPER, - KEY_INSERT, - KEY_HOME, - KEY_PG_UP, - KEY_DELETE, - KEY_END, - KEY_PG_DOWN, - KEY_LEFT_ARROW, - KEY_RIGHT_ARROW, - KEY_UP_ARROW, - KEY_DOWN_ARROW, - KEY_NUM_LOCK, - KEY_KP_PLUS, - KEY_KP_MINUS, - KEY_KP_MULTIPLY, - KEY_KP_DIVIDE, - KEY_KP_ENTER, - KEY_KP_HOME, - KEY_KP_UP, - KEY_KP_PG_UP, - KEY_KP_LEFT, - KEY_KP_FIVE, - KEY_KP_RIGHT, - KEY_KP_END, - KEY_KP_DOWN, - KEY_KP_PG_DOWN, - KEY_KP_INSERT, - KEY_KP_DELETE, - KEY_F1, - KEY_F2, - KEY_F3, - KEY_F4, - KEY_F5, - KEY_F6, - KEY_F7, - KEY_F8, - KEY_F9, - KEY_F10, - KEY_F11, - KEY_F12, - KEY_SPACE, - KEY_EXCLAM, - KEY_QUOTE, - KEY_NUMBER, - KEY_DOLLAR, - KEY_PERCENT, - KEY_CIRCUMFLEX, - KEY_AMPERSAND, - KEY_APOSTROPHE, - KEY_LEFT_PARENTHESIS, - KEY_RIGHT_PARENTHESIS, - KEY_ASTERISK, - KEY_PLUS, - KEY_COMMA, - KEY_MINUS, - KEY_PERIOD, - KEY_SLASH, - KEY_0, - KEY_1, - KEY_2, - KEY_3, - KEY_4, - KEY_5, - KEY_6, - KEY_7, - KEY_8, - KEY_9, - KEY_COLON, - KEY_SEMICOLON, - KEY_LESS_THAN, - KEY_EQUAL, - KEY_GREATER_THAN, - KEY_QUESTION, - KEY_AT, - KEY_CAPITAL_A, - KEY_CAPITAL_B, - KEY_CAPITAL_C, - KEY_CAPITAL_D, - KEY_CAPITAL_E, - KEY_CAPITAL_F, - KEY_CAPITAL_G, - KEY_CAPITAL_H, - KEY_CAPITAL_I, - KEY_CAPITAL_J, - KEY_CAPITAL_K, - KEY_CAPITAL_L, - KEY_CAPITAL_M, - KEY_CAPITAL_N, - KEY_CAPITAL_O, - KEY_CAPITAL_P, - KEY_CAPITAL_Q, - KEY_CAPITAL_R, - KEY_CAPITAL_S, - KEY_CAPITAL_T, - KEY_CAPITAL_U, - KEY_CAPITAL_V, - KEY_CAPITAL_W, - KEY_CAPITAL_X, - KEY_CAPITAL_Y, - KEY_CAPITAL_Z, - KEY_LEFT_BRACKET, - KEY_BACK_SLASH, - KEY_RIGHT_BRACKET, - KEY_UNDERSCORE, - KEY_GRAVE, - KEY_A, - KEY_B, - KEY_C, - KEY_D, - KEY_E, - KEY_F, - KEY_G, - KEY_H, - KEY_I, - KEY_J, - KEY_K, - KEY_L, - KEY_M, - KEY_N, - KEY_O, - KEY_P, - KEY_Q, - KEY_R, - KEY_S, - KEY_T, - KEY_U, - KEY_V, - KEY_W, - KEY_X, - KEY_Y, - KEY_Z, - KEY_LEFT_BRACE, - KEY_BAR, - KEY_RIGHT_BRACE, - KEY_TILDE, - KEY_EURO, - KEY_POUND, - KEY_YEN, - KEY_MIDDLE_DOT, - KEY_SEARCH, - KEY_DPAD_LEFT, - KEY_DPAD_RIGHT, - KEY_DPAD_UP, - KEY_DPAD_DOWN, - KEY_DPAD_CENTER, - KEY_ENTER, - KEY_PLAY - }; - - /** Constructor. - * - * @param keyCode A given keycode. - * @param isPressed True if the key is pressed. - * @js ctor - */ - EventKeyboard(KeyCode keyCode, bool isPressed); - -private: - virtual ~EventKeyboard() {} - - KeyCode _keyCode; - bool _isPressed; - - friend class EventListenerKeyboard; -}; - -NS_CC_END - -// end of base group -/// @} - -#endif /* defined(__cocos2d_libs__CCKeyboardEvent__) */ - diff --git a/native/cocos/base/CCEventMouse.cpp b/native/cocos/base/CCEventMouse.cpp deleted file mode 100644 index e0369beafd..0000000000 --- a/native/cocos/base/CCEventMouse.cpp +++ /dev/null @@ -1,85 +0,0 @@ -/**************************************************************************** - Copyright (c) 2013-2016 Chukong Technologies Inc. - Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd. - - http://www.cocos2d-x.org - - Permission is hereby granted, free of charge, to any person obtaining a copy - of this software and associated documentation files (the "Software"), to deal - in the Software without restriction, including without limitation the rights - to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - copies of the Software, and to permit persons to whom the Software is - furnished to do so, subject to the following conditions: - - The above copyright notice and this permission notice shall be included in - all copies or substantial portions of the Software. - - THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - 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 "base/CCEventMouse.h" -#include "base/CCDirector.h" - -NS_CC_BEGIN - -EventMouse::EventMouse(MouseEventType mouseEventCode) -: Event(Type::MOUSE) -, _mouseEventType(mouseEventCode) -, _mouseButton(-1) -, _x(0.0f) -, _y(0.0f) -, _scrollX(0.0f) -, _scrollY(0.0f) -, _startPointCaptured(false) -{ -}; - -// returns the current touch location in screen coordinates -Vec2 EventMouse::getLocationInView() const -{ - return _point; -} - -// returns the previous touch location in screen coordinates -Vec2 EventMouse::getPreviousLocationInView() const -{ - return _prevPoint; -} - -// returns the start touch location in screen coordinates -Vec2 EventMouse::getStartLocationInView() const -{ - return _startPoint; -} - -// returns the current touch location in OpenGL coordinates -Vec2 EventMouse::getLocation() const -{ - return Director::getInstance()->convertToGL(_point); -} - -// returns the previous touch location in OpenGL coordinates -Vec2 EventMouse::getPreviousLocation() const -{ - return Director::getInstance()->convertToGL(_prevPoint); -} - -// returns the start touch location in OpenGL coordinates -Vec2 EventMouse::getStartLocation() const -{ - return Director::getInstance()->convertToGL(_startPoint); -} - -// returns the delta position between the current location and the previous location in OpenGL coordinates -Vec2 EventMouse::getDelta() const -{ - return getLocation() - getPreviousLocation(); -} -NS_CC_END diff --git a/native/cocos/base/CCEventMouse.h b/native/cocos/base/CCEventMouse.h deleted file mode 100644 index 3ee3d12a0a..0000000000 --- a/native/cocos/base/CCEventMouse.h +++ /dev/null @@ -1,201 +0,0 @@ -/**************************************************************************** - Copyright (c) 2013-2016 Chukong Technologies Inc. - Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd. - - http://www.cocos2d-x.org - - Permission is hereby granted, free of charge, to any person obtaining a copy - of this software and associated documentation files (the "Software"), to deal - in the Software without restriction, including without limitation the rights - to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - copies of the Software, and to permit persons to whom the Software is - furnished to do so, subject to the following conditions: - - The above copyright notice and this permission notice shall be included in - all copies or substantial portions of the Software. - - THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - 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. - - ****************************************************************************/ - -#ifndef __cocos2d_libs__CCMouseEvent__ -#define __cocos2d_libs__CCMouseEvent__ - -#include "base/CCEvent.h" -#include "math/CCGeometry.h" - -#define MOUSE_BUTTON_LEFT 0 -#define MOUSE_BUTTON_RIGHT 1 -#define MOUSE_BUTTON_MIDDLE 2 -#define MOUSE_BUTTON_4 3 -#define MOUSE_BUTTON_5 4 -#define MOUSE_BUTTON_6 5 -#define MOUSE_BUTTON_7 6 -#define MOUSE_BUTTON_8 7 - -/** - * @addtogroup base - * @{ - */ - -NS_CC_BEGIN - -/** @class EventMouse - * @brief The mouse event. - */ -class CC_DLL EventMouse : public Event -{ -public: - /** - * MouseEventType Different types of MouseEvent. - * @js NA - */ - enum class MouseEventType - { - MOUSE_NONE, - MOUSE_DOWN, - MOUSE_UP, - MOUSE_MOVE, - MOUSE_SCROLL, - }; - - /** Constructor. - * - * @param mouseEventCode A given mouse event type. - * @js ctor - */ - EventMouse(MouseEventType mouseEventCode); - - /** Set mouse scroll data. - * - * @param scrollX The scroll data of x axis. - * @param scrollY The scroll data of y axis. - */ - inline void setScrollData(float scrollX, float scrollY) { _scrollX = scrollX; _scrollY = scrollY; }; - /** Get mouse scroll data of x axis. - * - * @return The scroll data of x axis. - */ - inline float getScrollX() const { return _scrollX; }; - /** Get mouse scroll data of y axis. - * - * @return The scroll data of y axis. - */ - inline float getScrollY() const { return _scrollY; }; - - /** Set the cursor position. - * - * @param x The x coordinate of cursor position. - * @param y The y coordinate of cursor position. - * @js setLocation - */ - inline void setCursorPosition(float x, float y) { - _x = x; - _y = y; - _prevPoint = _point; - _point.x = x; - _point.y = y; - if (!_startPointCaptured) - { - _startPoint = _point; - _startPointCaptured = true; - } - } - - /** Set mouse button. - * - * @param button a given mouse button. - * @js setButton - */ - inline void setMouseButton(int button) { _mouseButton = button; }; - /** Get mouse button. - * - * @return The mouse button. - * @js getButton - */ - inline int getMouseButton() const { return _mouseButton; }; - /** Get the cursor position of x axis. - * - * @return The x coordinate of cursor position. - * @js getLocationX - */ - inline float getCursorX() const { return _x; }; - /** Get the cursor position of y axis. - * - * @return The y coordinate of cursor position. - * @js getLocationY - */ - inline float getCursorY() const { return _y; }; - - /** Returns the current touch location in OpenGL coordinates. - * - * @return The current touch location in OpenGL coordinates. - */ - Vec2 getLocation() const; - /** Returns the previous touch location in OpenGL coordinates. - * - * @return The previous touch location in OpenGL coordinates. - * @js NA - */ - Vec2 getPreviousLocation() const; - /** Returns the start touch location in OpenGL coordinates. - * - * @return The start touch location in OpenGL coordinates. - * @js NA - */ - Vec2 getStartLocation() const; - /** Returns the delta of 2 current touches locations in screen coordinates. - * - * @return The delta of 2 current touches locations in screen coordinates. - */ - Vec2 getDelta() const; - /** Returns the current touch location in screen coordinates. - * - * @return The current touch location in screen coordinates. - */ - Vec2 getLocationInView() const; - /** Returns the previous touch location in screen coordinates. - * - * @return The previous touch location in screen coordinates. - * @js NA - */ - Vec2 getPreviousLocationInView() const; - /** Returns the start touch location in screen coordinates. - * - * @return The start touch location in screen coordinates. - * @js NA - */ - Vec2 getStartLocationInView() const; - - -private: - virtual ~EventMouse() {} - - MouseEventType _mouseEventType; - int _mouseButton; - float _x; - float _y; - float _scrollX; - float _scrollY; - - bool _startPointCaptured; - Vec2 _startPoint; - Vec2 _point; - Vec2 _prevPoint; - - friend class EventListenerMouse; -}; - -NS_CC_END - -// end of base group -/// @} - -#endif /* defined(__cocos2d_libs__CCMouseEvent__) */ - diff --git a/native/cocos/base/CCEventTouch.cpp b/native/cocos/base/CCEventTouch.cpp deleted file mode 100644 index 73f1b0d8c1..0000000000 --- a/native/cocos/base/CCEventTouch.cpp +++ /dev/null @@ -1,43 +0,0 @@ -/**************************************************************************** - Copyright (c) 2013-2016 Chukong Technologies Inc. - Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd. - - http://www.cocos2d-x.org - - Permission is hereby granted, free of charge, to any person obtaining a copy - of this software and associated documentation files (the "Software"), to deal - in the Software without restriction, including without limitation the rights - to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - copies of the Software, and to permit persons to whom the Software is - furnished to do so, subject to the following conditions: - - The above copyright notice and this permission notice shall be included in - all copies or substantial portions of the Software. - - THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - 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 "base/CCEventTouch.h" -#include "base/CCTouch.h" - -NS_CC_BEGIN - -EventTouch::EventTouch() -: Event(Type::TOUCH) -{ - _touches.reserve(MAX_TOUCHES); -} - -void EventTouch::reset() -{ - _touches.clear(); -} - -NS_CC_END - diff --git a/native/cocos/base/CCEventTouch.h b/native/cocos/base/CCEventTouch.h deleted file mode 100644 index 7f576d0b2a..0000000000 --- a/native/cocos/base/CCEventTouch.h +++ /dev/null @@ -1,109 +0,0 @@ -/**************************************************************************** - Copyright (c) 2013-2016 Chukong Technologies Inc. - Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd. - - http://www.cocos2d-x.org - - Permission is hereby granted, free of charge, to any person obtaining a copy - of this software and associated documentation files (the "Software"), to deal - in the Software without restriction, including without limitation the rights - to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - copies of the Software, and to permit persons to whom the Software is - furnished to do so, subject to the following conditions: - - The above copyright notice and this permission notice shall be included in - all copies or substantial portions of the Software. - - THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - 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. - ****************************************************************************/ - -#ifndef __cocos2d_libs__TouchEvent__ -#define __cocos2d_libs__TouchEvent__ - -#include "base/CCEvent.h" -#include - -/** - * @addtogroup base - * @{ - */ - -NS_CC_BEGIN - -class Touch; - -#define TOUCH_PERF_DEBUG 1 - -/** @class EventTouch - * @brief Touch event. - */ -class CC_DLL EventTouch : public Event -{ -public: - static const int MAX_TOUCHES = 15; - - /** EventCode Touch event code.*/ - enum class EventCode - { - BEGAN, - MOVED, - ENDED, - CANCELLED - }; - - /** - * Constructor. - * @js NA - */ - EventTouch(); - - /** Get event code. - * - * @return The code of the event. - */ - inline EventCode getEventCode() const { return _eventCode; }; - - /** Get the touches. - * - * @return The touches of the event. - */ - inline const std::vector& getTouches() const { return _touches; }; - -#if TOUCH_PERF_DEBUG - /** Set the event code. - * - * @param eventCode A given EventCode. - */ - void setEventCode(EventCode eventCode) { _eventCode = eventCode; }; - /** Set the touches - * - * @param touches A given touches vector. - */ - void setTouches(const std::vector& touches) { _touches = touches; }; -#endif - -private: - virtual ~EventTouch() {} - - void reset(); - - EventCode _eventCode; - std::vector _touches; - - friend class GLView; -}; - - -NS_CC_END - -// end of base group -/// @} - -#endif /* defined(__cocos2d_libs__TouchEvent__) */ - diff --git a/native/cocos/base/CCEventType.h b/native/cocos/base/CCEventType.h deleted file mode 100644 index 3b545e5233..0000000000 --- a/native/cocos/base/CCEventType.h +++ /dev/null @@ -1,50 +0,0 @@ -/**************************************************************************** - Copyright (c) 2013-2016 Chukong Technologies Inc. - Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd. - - http://www.cocos2d-x.org - - Permission is hereby granted, free of charge, to any person obtaining a copy - of this software and associated documentation files (the "Software"), to deal - in the Software without restriction, including without limitation the rights - to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - copies of the Software, and to permit persons to whom the Software is - furnished to do so, subject to the following conditions: - - The above copyright notice and this permission notice shall be included in - all copies or substantial portions of the Software. - - THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - 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. - ****************************************************************************/ - -#ifndef __CCEVENT_TYPE_H__ -#define __CCEVENT_TYPE_H__ -/// @cond DO_NOT_SHOW - -/** - * This header is used for defining event types using in NotificationCenter - */ - -// The application will come to foreground. -// This message is posted in cocos/platform/android/jni/Java_org_cocos2dx_lib_Cocos2dxRenderer.cpp. -#define EVENT_COME_TO_FOREGROUND "event_come_to_foreground" - -// The renderer[android:GLSurfaceView.Renderer WP8:Cocos2dRenderer] was recreated. -// This message is used for reloading resources before renderer is recreated on Android/WP8. -// This message is posted in cocos/platform/android/javaactivity.cpp and cocos\platform\wp8-xaml\cpp\Cocos2dRenderer.cpp. -#define EVENT_RENDERER_RECREATED "event_renderer_recreated" - -// The application will come to background. -// This message is used for doing something before coming to background, such as save RenderTexture. -// This message is posted in cocos/platform/android/jni/Java_org_cocos2dx_lib_Cocos2dxRenderer.cpp and cocos\platform\wp8-xaml\cpp\Cocos2dRenderer.cpp. -#define EVENT_COME_TO_BACKGROUND "event_come_to_background" - -/// @endcond -#endif // __CCEVENT_TYPE_H__ - diff --git a/native/cocos/base/CCIMEDelegate.h b/native/cocos/base/CCIMEDelegate.h deleted file mode 100644 index 0d961d63c8..0000000000 --- a/native/cocos/base/CCIMEDelegate.h +++ /dev/null @@ -1,180 +0,0 @@ -/**************************************************************************** -Copyright (c) 2010 cocos2d-x.org -Copyright (C) 2013-2016 Chukong Technologies Inc. -Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd. - -http://www.cocos2d-x.org - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in -all copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -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. -****************************************************************************/ - -#ifndef __CC_IME_DELEGATE_H__ -#define __CC_IME_DELEGATE_H__ - -#include -#include "math/CCGeometry.h" -#include "base/CCEventKeyboard.h" - -/** - * @addtogroup base - * @{ - */ -NS_CC_BEGIN - -/** - * A static global empty std::string install. - */ -extern const std::string CC_DLL STD_STRING_EMPTY; - - -/** - * Keyboard notification event type. - */ -typedef struct -{ - Rect begin; // the soft keyboard rectangle when animation begins - Rect end; // the soft keyboard rectangle when animation ends - float duration; // the soft keyboard animation duration -} IMEKeyboardNotificationInfo; - -/** - *@brief Input method editor delegate. - */ -class CC_DLL IMEDelegate -{ -public: - /** - * Default constructor. - * @js NA - * @lua NA - */ - virtual ~IMEDelegate(); - - /** - * Default destructor. - * @js NA - * @lua NA - */ - virtual bool attachWithIME(); - - /** - * Determine whether the IME is detached or not. - * @js NA - * @lua NA - */ - virtual bool detachWithIME(); - -protected: - friend class IMEDispatcher; - - /** - @brief Decide if the delegate instance is ready to receive an IME message. - - Called by IMEDispatcher. - * @js NA - * @lua NA - */ - virtual bool canAttachWithIME() { return false; } - /** - @brief When the delegate detaches from the IME, this method is called by IMEDispatcher. - * @js NA - * @lua NA - */ - virtual void didAttachWithIME() {} - - /** - @brief Decide if the delegate instance can stop receiving IME messages. - * @js NA - * @lua NA - */ - virtual bool canDetachWithIME() { return false; } - - /** - @brief When the delegate detaches from the IME, this method is called by IMEDispatcher. - * @js NA - * @lua NA - */ - virtual void didDetachWithIME() {} - - /** - @brief Called by IMEDispatcher when text input received from the IME. - * @js NA - * @lua NA - */ - virtual void insertText(const char * text, size_t len) {CC_UNUSED_PARAM(text);CC_UNUSED_PARAM(len);} - - /** - @brief Called by IMEDispatcher after the user clicks the backward key. - * @js NA - * @lua NA - */ - virtual void deleteBackward() {} - - /** - @brief Called by IMEDispatcher after the user press control key. - * @js NA - * @lua NA - */ - virtual void controlKey(EventKeyboard::KeyCode keyCode) {} - - /** - @brief Called by IMEDispatcher for text stored in delegate. - * @js NA - * @lua NA - */ - virtual const std::string& getContentText() { return STD_STRING_EMPTY; } - - ////////////////////////////////////////////////////////////////////////// - // keyboard show/hide notification - ////////////////////////////////////////////////////////////////////////// - /** - * @js NA - * @lua NA - */ - virtual void keyboardWillShow(IMEKeyboardNotificationInfo& info) {CC_UNUSED_PARAM(info);} - /** - * @js NA - * @lua NA - */ - virtual void keyboardDidShow(IMEKeyboardNotificationInfo& info) {CC_UNUSED_PARAM(info);} - /** - * @js NA - * @lua NA - */ - virtual void keyboardWillHide(IMEKeyboardNotificationInfo& info) {CC_UNUSED_PARAM(info);} - /** - * @js NA - * @lua NA - */ - virtual void keyboardDidHide(IMEKeyboardNotificationInfo& info) {CC_UNUSED_PARAM(info);} - -protected: - /** - * @js NA - * @lua NA - */ - IMEDelegate(); -}; - - -NS_CC_END -// end of base group -/// @} - -#endif // __CC_IME_DELEGATE_H__ diff --git a/native/cocos/base/CCIMEDispatcher.cpp b/native/cocos/base/CCIMEDispatcher.cpp deleted file mode 100644 index 5f4254ffe9..0000000000 --- a/native/cocos/base/CCIMEDispatcher.cpp +++ /dev/null @@ -1,356 +0,0 @@ -/**************************************************************************** -Copyright (c) 2010 cocos2d-x.org -Copyright (C) 2013-2016 Chukong Technologies Inc. -Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd. - -http://www.cocos2d-x.org - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in -all copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -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 "base/CCIMEDispatcher.h" - -#include - -NS_CC_BEGIN - -////////////////////////////////////////////////////////////////////////// -// add/remove delegate in IMEDelegate Cons/Destructor -////////////////////////////////////////////////////////////////////////// - -IMEDelegate::IMEDelegate() -{ - IMEDispatcher::sharedDispatcher()->addDelegate(this); -} - -IMEDelegate::~IMEDelegate() -{ - IMEDispatcher::sharedDispatcher()->removeDelegate(this); -} - -bool IMEDelegate::attachWithIME() -{ - return IMEDispatcher::sharedDispatcher()->attachDelegateWithIME(this); -} - -bool IMEDelegate::detachWithIME() -{ - return IMEDispatcher::sharedDispatcher()->detachDelegateWithIME(this); -} - -////////////////////////////////////////////////////////////////////////// - -typedef std::list< IMEDelegate * > DelegateList; -typedef std::list< IMEDelegate * >::iterator DelegateIter; - -////////////////////////////////////////////////////////////////////////// -// Delegate List manage class -////////////////////////////////////////////////////////////////////////// - -class IMEDispatcher::Impl -{ -public: - Impl() - { - } - - ~Impl() - { - - } - - void init() - { - _delegateWithIme = 0; - } - - DelegateIter findDelegate(IMEDelegate* delegate) - { - DelegateIter end = _delegateList.end(); - for (DelegateIter iter = _delegateList.begin(); iter != end; ++iter) - { - if (delegate == *iter) - { - return iter; - } - } - return end; - } - - DelegateList _delegateList; - IMEDelegate* _delegateWithIme; -}; - -////////////////////////////////////////////////////////////////////////// -// Cons/Destructor -////////////////////////////////////////////////////////////////////////// - -IMEDispatcher::IMEDispatcher() -: _impl(new IMEDispatcher::Impl) -{ - _impl->init(); -} - -IMEDispatcher::~IMEDispatcher() -{ - CC_SAFE_DELETE(_impl); -} - -////////////////////////////////////////////////////////////////////////// -// Add/Attach/Remove IMEDelegate -////////////////////////////////////////////////////////////////////////// - -void IMEDispatcher::addDelegate(IMEDelegate* delegate) -{ - if (! delegate || ! _impl) - { - return; - } - if (_impl->_delegateList.end() != _impl->findDelegate(delegate)) - { - // pDelegate already in list - return; - } - _impl->_delegateList.push_front(delegate); -} - -bool IMEDispatcher::attachDelegateWithIME(IMEDelegate * delegate) -{ - bool ret = false; - do - { - CC_BREAK_IF(! _impl || ! delegate); - - DelegateIter end = _impl->_delegateList.end(); - DelegateIter iter = _impl->findDelegate(delegate); - - // if pDelegate is not in delegate list, return - CC_BREAK_IF(end == iter); - - if (_impl->_delegateWithIme) - { - if (_impl->_delegateWithIme != delegate) - { - // if old delegate canDetachWithIME return false - // or pDelegate canAttachWithIME return false, - // do nothing. - CC_BREAK_IF(!_impl->_delegateWithIme->canDetachWithIME() - || !delegate->canAttachWithIME()); - - // detach first - IMEDelegate * oldDelegate = _impl->_delegateWithIme; - _impl->_delegateWithIme = 0; - oldDelegate->didDetachWithIME(); - - _impl->_delegateWithIme = *iter; - delegate->didAttachWithIME(); - } - ret = true; - break; - } - - // delegate hasn't attached to IME yet - CC_BREAK_IF(! delegate->canAttachWithIME()); - - _impl->_delegateWithIme = *iter; - delegate->didAttachWithIME(); - ret = true; - } while (0); - return ret; -} - -bool IMEDispatcher::detachDelegateWithIME(IMEDelegate * delegate) -{ - bool ret = false; - do - { - CC_BREAK_IF(! _impl || ! delegate); - - // if pDelegate is not the current delegate attached to IME, return - CC_BREAK_IF(_impl->_delegateWithIme != delegate); - - CC_BREAK_IF(! delegate->canDetachWithIME()); - - _impl->_delegateWithIme = 0; - delegate->didDetachWithIME(); - ret = true; - } while (0); - return ret; -} - -void IMEDispatcher::removeDelegate(IMEDelegate* delegate) -{ - do - { - CC_BREAK_IF(! delegate || ! _impl); - - DelegateIter iter = _impl->findDelegate(delegate); - DelegateIter end = _impl->_delegateList.end(); - CC_BREAK_IF(end == iter); - - if (_impl->_delegateWithIme) - - if (*iter == _impl->_delegateWithIme) - { - _impl->_delegateWithIme = 0; - } - _impl->_delegateList.erase(iter); - } while (0); -} - -////////////////////////////////////////////////////////////////////////// -// dispatch text message -////////////////////////////////////////////////////////////////////////// - -void IMEDispatcher::dispatchInsertText(const char * text, size_t len) -{ - do - { - CC_BREAK_IF(! _impl || ! text || len <= 0); - - // there is no delegate attached to IME - CC_BREAK_IF(! _impl->_delegateWithIme); - - _impl->_delegateWithIme->insertText(text, len); - } while (0); -} - -void IMEDispatcher::dispatchDeleteBackward() -{ - do - { - CC_BREAK_IF(! _impl); - - // there is no delegate attached to IME - CC_BREAK_IF(! _impl->_delegateWithIme); - - _impl->_delegateWithIme->deleteBackward(); - } while (0); -} - -void IMEDispatcher::dispatchControlKey(EventKeyboard::KeyCode keyCode) -{ - do - { - CC_BREAK_IF(!_impl); - - // there is no delegate attached to IME - CC_BREAK_IF(!_impl->_delegateWithIme); - - _impl->_delegateWithIme->controlKey(keyCode); - } while (0); -} - -const std::string& IMEDispatcher::getContentText() -{ - if (_impl && _impl->_delegateWithIme) - { - return _impl->_delegateWithIme->getContentText(); - } - return STD_STRING_EMPTY; -} - -////////////////////////////////////////////////////////////////////////// -// dispatch keyboard message -////////////////////////////////////////////////////////////////////////// - -void IMEDispatcher::dispatchKeyboardWillShow(IMEKeyboardNotificationInfo& info) -{ - if (_impl) - { - IMEDelegate * delegate = nullptr; - DelegateIter last = _impl->_delegateList.end(); - for (DelegateIter first = _impl->_delegateList.begin(); first != last; ++first) - { - delegate = *(first); - if (delegate) - { - delegate->keyboardWillShow(info); - } - } - } -} - -void IMEDispatcher::dispatchKeyboardDidShow(IMEKeyboardNotificationInfo& info) -{ - if (_impl) - { - IMEDelegate * delegate = nullptr; - DelegateIter last = _impl->_delegateList.end(); - for (DelegateIter first = _impl->_delegateList.begin(); first != last; ++first) - { - delegate = *(first); - if (delegate) - { - delegate->keyboardDidShow(info); - } - } - } -} - -void IMEDispatcher::dispatchKeyboardWillHide(IMEKeyboardNotificationInfo& info) -{ - if (_impl) - { - IMEDelegate * delegate = nullptr; - DelegateIter last = _impl->_delegateList.end(); - for (DelegateIter first = _impl->_delegateList.begin(); first != last; ++first) - { - delegate = *(first); - if (delegate) - { - delegate->keyboardWillHide(info); - } - } - } -} - -void IMEDispatcher::dispatchKeyboardDidHide(IMEKeyboardNotificationInfo& info) -{ - if (_impl) - { - IMEDelegate * delegate = nullptr; - DelegateIter last = _impl->_delegateList.end(); - for (DelegateIter first = _impl->_delegateList.begin(); first != last; ++first) - { - delegate = *(first); - if (delegate) - { - delegate->keyboardDidHide(info); - } - } - } -} - -////////////////////////////////////////////////////////////////////////// -// protected member function -////////////////////////////////////////////////////////////////////////// - - -////////////////////////////////////////////////////////////////////////// -// static member function -////////////////////////////////////////////////////////////////////////// - -IMEDispatcher* IMEDispatcher::sharedDispatcher() -{ - static IMEDispatcher s_instance; - return &s_instance; -} - -NS_CC_END diff --git a/native/cocos/base/CCIMEDispatcher.h b/native/cocos/base/CCIMEDispatcher.h deleted file mode 100644 index 188456021e..0000000000 --- a/native/cocos/base/CCIMEDispatcher.h +++ /dev/null @@ -1,145 +0,0 @@ -/**************************************************************************** -Copyright (c) 2010 cocos2d-x.org -Copyright (c) 2013-2016 Chukong Technologies Inc. -Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd. - -http://www.cocos2d-x.org - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in -all copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -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. -****************************************************************************/ - -#ifndef __CC_IME_DISPATCHER_H__ -#define __CC_IME_DISPATCHER_H__ - -#include "base/CCIMEDelegate.h" - -/** - * @addtogroup base - * @{ - */ -NS_CC_BEGIN - - -/** -@brief Input Method Edit Message Dispatcher. -*/ -class CC_DLL IMEDispatcher -{ -public: - /** - * @js NA - * @lua NA - */ - ~IMEDispatcher(); - - /** - * @brief Returns the shared IMEDispatcher object for the system. - * @js NA - * @lua NA - */ - static IMEDispatcher* sharedDispatcher(); - - /** - * @brief Dispatches the input text from IME. - * @lua NA - */ - void dispatchInsertText(const char * text, size_t len); - - /** - * @brief Dispatches the delete-backward operation. - * @lua NA - */ - void dispatchDeleteBackward(); - - /** - * @brief Dispatches the press control key operation. - * @lua NA - */ - void dispatchControlKey(EventKeyboard::KeyCode keyCode); - - /** - * @brief Get the content text from IMEDelegate, retrieved previously from IME. - * @lua NA - */ - const std::string& getContentText(); - - ////////////////////////////////////////////////////////////////////////// - // dispatch keyboard notification - ////////////////////////////////////////////////////////////////////////// - /** - * @lua NA - */ - void dispatchKeyboardWillShow(IMEKeyboardNotificationInfo& info); - /** - * @lua NA - */ - void dispatchKeyboardDidShow(IMEKeyboardNotificationInfo& info); - /** - * @lua NA - */ - void dispatchKeyboardWillHide(IMEKeyboardNotificationInfo& info); - /** - * @lua NA - */ - void dispatchKeyboardDidHide(IMEKeyboardNotificationInfo& info); - -protected: - friend class IMEDelegate; - - /** - *@brief Add delegate to receive IME messages. - *@param delegate A instance implements IMEDelegate delegate. - */ - void addDelegate(IMEDelegate * delegate); - - /** - *@brief Attach the Delegate to the IME. - *@param delegate A instance implements IMEDelegate delegate. - *@return If the old delegate can detach from the IME, and the new delegate - * can attach to the IME, return true, otherwise false. - */ - bool attachDelegateWithIME(IMEDelegate * delegate); - - /** - * Detach the delegate to the IME - *@see `attachDelegateWithIME(IMEDelegate*)` - *@param delegate A instance implements IMEDelegate delegate. - *@return Whether the IME is detached or not. - */ - bool detachDelegateWithIME(IMEDelegate * delegate); - - /** - *@brief Remove the delegate from the delegates which receive IME messages. - *@param delegate A instance implements the IMEDelegate delegate. - */ - void removeDelegate(IMEDelegate * delegate); - -private: - IMEDispatcher(); - - class Impl; - Impl * _impl; -}; - - -NS_CC_END -// end of base group -/// @} - -#endif // __CC_IME_DISPATCHER_H__ diff --git a/native/cocos/base/CCLog.cpp b/native/cocos/base/CCLog.cpp new file mode 100644 index 0000000000..db46af5b96 --- /dev/null +++ b/native/cocos/base/CCLog.cpp @@ -0,0 +1,119 @@ +/**************************************************************************** + Copyright (c) 2013-2016 Chukong Technologies Inc. + Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd. + + http://www.cocos2d-x.org + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + 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 "base/CCLog.h" +#include +#include +#include + +#if (CC_TARGET_PLATFORM == CC_PLATFORM_WIN32) +#include +#include +#include + +#endif // (CC_TARGET_PLATFORM == CC_PLATFORM_WIN32) + +/** private functions */ +namespace +{ + const size_t SEND_BUFSIZ = 512; + const int MAX_LOG_LENGTH = 16*1024; + + // + // Free functions to log + // + + void _log(const char *format, va_list args) + { + int bufferSize = MAX_LOG_LENGTH; + char* buf = nullptr; + + do + { + buf = new (std::nothrow) char[bufferSize]; + if (buf == nullptr) + return; // not enough memory + + int ret = vsnprintf(buf, bufferSize - 3, format, args); + if (ret < 0) + { + bufferSize *= 2; + + delete [] buf; + } + else + break; + + } while (true); + + strcat(buf, "\n"); + +#if CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID + #include + __android_log_print(ANDROID_LOG_DEBUG, "cocos2d-x debug info", "%s", buf); +#elif CC_TARGET_PLATFORM == CC_PLATFORM_WIN32 + int pos = 0; + int len = strlen(buf); + char tempBuf[MAX_LOG_LENGTH + 1] = { 0 }; + WCHAR wszBuf[MAX_LOG_LENGTH + 1] = { 0 }; + + do + { + std::copy(buf + pos, buf + pos + MAX_LOG_LENGTH, tempBuf); + + tempBuf[MAX_LOG_LENGTH] = 0; + + MultiByteToWideChar(CP_UTF8, 0, tempBuf, -1, wszBuf, sizeof(wszBuf)); + OutputDebugStringW(wszBuf); + WideCharToMultiByte(CP_ACP, 0, wszBuf, -1, tempBuf, sizeof(tempBuf), nullptr, FALSE); + printf("%s", tempBuf); + + pos += MAX_LOG_LENGTH; + + } while (pos < len); + fflush(stdout); +#else + // Linux, Mac, iOS, etc + fprintf(stdout, "%s", buf); + fflush(stdout); +#endif + + //cocos2d::log(buf); + delete [] buf; + } +} + +namespace cocos2d +{ + + void log(const char * format, ...) + { + va_list args; + va_start(args, format); + _log(format, args); + va_end(args); + } + +} + diff --git a/native/cocos/base/CCEventAcceleration.h b/native/cocos/base/CCLog.h similarity index 58% rename from native/cocos/base/CCEventAcceleration.h rename to native/cocos/base/CCLog.h index f3ebd09915..9b2ec72eed 100644 --- a/native/cocos/base/CCEventAcceleration.h +++ b/native/cocos/base/CCLog.h @@ -23,41 +23,40 @@ THE SOFTWARE. ****************************************************************************/ -#ifndef __cocos2d_libs__CCAccelerometerEvent__ -#define __cocos2d_libs__CCAccelerometerEvent__ +#pragma once -#include "base/CCEvent.h" -#include "base/ccTypes.h" +#include "platform/CCPlatformDefine.h" -/** - * @addtogroup base - * @{ +/// @cond DO_NOT_SHOW + +// Because ccMacros.h includes this header file, and CC_FORMAT_PRINTF is defined in ccMacros.h, so +// we define it here too. + +/** @def CC_FORMAT_PRINTF(formatPos, argPos) + * Only certain compiler support __attribute__((format)) + * + * @param formatPos 1-based position of format string argument. + * @param argPos 1-based position of first format-dependent argument. */ +#if defined(__GNUC__) && (__GNUC__ >= 4) +#define CC_FORMAT_PRINTF(formatPos, argPos) __attribute__((__format__(printf, formatPos, argPos))) +#elif defined(__has_attribute) +#if __has_attribute(format) +#define CC_FORMAT_PRINTF(formatPos, argPos) __attribute__((__format__(printf, formatPos, argPos))) +#endif // __has_attribute(format) +#else +#define CC_FORMAT_PRINTF(formatPos, argPos) +#endif -NS_CC_BEGIN - -/** @class EventAcceleration - * @brief Accelerometer event. - */ -class CC_DLL EventAcceleration : public Event +namespace cocos2d { -public: - /** Constructor. - * - * @param acc A given Acceleration. - */ - EventAcceleration(const Acceleration& acc); -private: - virtual ~EventAcceleration() {} - Acceleration _acc; - friend class EventListenerAcceleration; -}; + /** + @brief Output Debug message. + */ + void CC_DLL log(const char * format, ...) CC_FORMAT_PRINTF(1, 2); -NS_CC_END +} -// end of base group -/// @} - -#endif /* defined(__cocos2d_libs__CCAccelerometerEvent__) */ +/// @endcond diff --git a/native/cocos/base/CCProfiling.cpp b/native/cocos/base/CCProfiling.cpp deleted file mode 100644 index dea57fb153..0000000000 --- a/native/cocos/base/CCProfiling.cpp +++ /dev/null @@ -1,179 +0,0 @@ -/**************************************************************************** -Copyright (c) 2010 Stuart Carnie -Copyright (c) 2010-2012 cocos2d-x.org -Copyright (c) 2013-2016 Chukong Technologies Inc. -Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd. - -http://www.cocos2d-x.org - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in -all copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -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 "base/CCProfiling.h" - -using namespace std; - -NS_CC_BEGIN - -// Profiling Categories -/* set to false the categories that you don't want to profile */ -bool kProfilerCategorySprite = false; -bool kProfilerCategoryBatchSprite = false; -bool kProfilerCategoryParticles = false; - - -static Profiler* g_sSharedProfiler = nullptr; - -Profiler* Profiler::getInstance() -{ - if (! g_sSharedProfiler) - { - g_sSharedProfiler = new (std::nothrow) Profiler(); - g_sSharedProfiler->init(); - } - - return g_sSharedProfiler; -} - -ProfilingTimer* Profiler::createAndAddTimerWithName(const char* timerName) -{ - ProfilingTimer *t = new (std::nothrow) ProfilingTimer(); - t->initWithName(timerName); - _activeTimers.insert(timerName, t); - t->release(); - - return t; -} - -void Profiler::releaseTimer(const char* timerName) -{ - _activeTimers.erase(timerName); -} - -void Profiler::releaseAllTimers() -{ - _activeTimers.clear(); -} - -bool Profiler::init() -{ - return true; -} - -Profiler::~Profiler(void) -{ -} - -void Profiler::displayTimers() -{ - for (auto iter = _activeTimers.begin(); iter != _activeTimers.end(); ++iter) - { - ProfilingTimer* timer = iter->second; - log("%s", timer->getDescription().c_str()); - } -} - -// implementation of ProfilingTimer - -ProfilingTimer::ProfilingTimer() -: _averageTime1(0) -, _averageTime2(0) -, minTime(100000000) -, maxTime(0) -, totalTime(0) -, numberOfCalls(0) -{ -} - -bool ProfilingTimer::initWithName(const char* timerName) -{ - _nameStr = timerName; - return true; -} - -ProfilingTimer::~ProfilingTimer(void) -{ - -} - -std::string ProfilingTimer::getDescription() const -{ - static char s_description[512] = {0}; - - sprintf(s_description, "%s ::\tavg1: %ldu,\tavg2: %ldu,\tmin: %ldu,\tmax: %ldu,\ttotal: %.2fs,\tnr calls: %ld", _nameStr.c_str(), _averageTime1, _averageTime2, minTime, maxTime, totalTime/1000000., numberOfCalls); - return s_description; -} - -void ProfilingTimer::reset() -{ - numberOfCalls = 0; - _averageTime1 = 0; - _averageTime2 = 0; - totalTime = 0; - minTime = 100000000; - maxTime = 0; - _startTime = chrono::high_resolution_clock::now(); -} - -void ProfilingBeginTimingBlock(const char *timerName) -{ - Profiler* p = Profiler::getInstance(); - ProfilingTimer* timer = p->_activeTimers.at(timerName); - if( ! timer ) - { - timer = p->createAndAddTimerWithName(timerName); - } - - timer->numberOfCalls++; - - // should be the last instruction in order to be more reliable - timer->_startTime = chrono::high_resolution_clock::now(); -} - -void ProfilingEndTimingBlock(const char *timerName) -{ - // should be the 1st instruction in order to be more reliable - auto now = chrono::high_resolution_clock::now(); - - Profiler* p = Profiler::getInstance(); - ProfilingTimer* timer = p->_activeTimers.at(timerName); - - CCASSERT(timer, "CCProfilingTimer not found"); - - - long duration = static_cast(chrono::duration_cast(now - timer->_startTime).count()); - - timer->totalTime += duration; - timer->_averageTime1 = (timer->_averageTime1 + duration) / 2.0f; - timer->_averageTime2 = timer->totalTime / timer->numberOfCalls; - timer->maxTime = std::max( timer->maxTime, duration); - timer->minTime = std::min( timer->minTime, duration); -} - -void ProfilingResetTimingBlock(const char *timerName) -{ - Profiler* p = Profiler::getInstance(); - ProfilingTimer *timer = p->_activeTimers.at(timerName); - - CCASSERT(timer, "CCProfilingTimer not found"); - - timer->reset(); -} - -NS_CC_END - diff --git a/native/cocos/base/CCProfiling.h b/native/cocos/base/CCProfiling.h deleted file mode 100644 index fd53280102..0000000000 --- a/native/cocos/base/CCProfiling.h +++ /dev/null @@ -1,162 +0,0 @@ -/**************************************************************************** -Copyright (c) 2010 Stuart Carnie -Copyright (c) 2010-2012 cocos2d-x.org -Copyright (c) 2013-2016 Chukong Technologies Inc. -Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd. - -http://www.cocos2d-x.org - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in -all copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -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. -****************************************************************************/ - -#ifndef __SUPPORT_CCPROFILING_H__ -#define __SUPPORT_CCPROFILING_H__ -/// @cond DO_NOT_SHOW - -#include -#include -#include "base/ccConfig.h" -#include "base/CCRef.h" -#include "base/CCMap.h" - -NS_CC_BEGIN - -/** - * @addtogroup global - * @{ - */ - -class ProfilingTimer; - -/** Profiler - cocos2d builtin profiler. - - To use it, enable set the CC_ENABLE_PROFILERS=1 in the ccConfig.h file - */ - -class CC_DLL Profiler : public Ref -{ -public: - /** - * @js NA - * @lua NA - */ - ~Profiler(void); - /** display the timers - * @js NA - * @lua NA - */ - void displayTimers(void); - /** - * @js NA - * @lua NA - */ - bool init(void); - -public: - /** returns the singleton - * @js NA - * @lua NA - */ - static Profiler* getInstance(void); - - /** Creates and adds a new timer - * @js NA - * @lua NA - */ - ProfilingTimer* createAndAddTimerWithName(const char* timerName); - /** releases a timer - * @js NA - * @lua NA - */ - void releaseTimer(const char* timerName); - /** releases all timers - * @js NA - * @lua NA - */ - void releaseAllTimers(); - - Map _activeTimers; -}; - -class ProfilingTimer : public Ref -{ -public: - /** - * @js NA - * @lua NA - */ - ProfilingTimer(); - /** - * @js NA - * @lua NA - */ - ~ProfilingTimer(void); - /** - * @js NA - * @lua NA - */ - bool initWithName(const char* timerName); - /** - * @js NA - * @lua NA - */ - virtual std::string getDescription() const; - /** - * @js NA - * @lua NA - */ - inline const std::chrono::high_resolution_clock::time_point& getStartTime(void) { return _startTime; }; - - /** resets the timer properties - * @js NA - * @lua NA - */ - void reset(); - - std::string _nameStr; - std::chrono::high_resolution_clock::time_point _startTime; - long _averageTime1; - long _averageTime2; - long minTime; - long maxTime; - long totalTime; - long numberOfCalls; -}; - -extern void CC_DLL ProfilingBeginTimingBlock(const char *timerName); -extern void CC_DLL ProfilingEndTimingBlock(const char *timerName); -extern void CC_DLL ProfilingResetTimingBlock(const char *timerName); - -/* - * cocos2d profiling categories - * used to enable / disable profilers with granularity - */ - -extern bool kProfilerCategorySprite; -extern bool kProfilerCategoryBatchSprite; -extern bool kProfilerCategoryParticles; - -// end of global group -/// @} - -NS_CC_END - -/// @endcond -#endif // __SUPPORT_CCPROFILING_H__ diff --git a/native/cocos/base/CCRef.h b/native/cocos/base/CCRef.h index a23df0da62..af7e94e9f7 100644 --- a/native/cocos/base/CCRef.h +++ b/native/cocos/base/CCRef.h @@ -27,7 +27,7 @@ THE SOFTWARE. #ifndef __BASE_CCREF_H__ #define __BASE_CCREF_H__ -#include "platform/CCPlatformMacros.h" +#include "base/ccMacros.h" #include "base/ccConfig.h" #define CC_REF_LEAK_DETECTION 0 diff --git a/native/cocos/base/CCTouch.cpp b/native/cocos/base/CCTouch.cpp deleted file mode 100644 index 58f4b9a6fb..0000000000 --- a/native/cocos/base/CCTouch.cpp +++ /dev/null @@ -1,87 +0,0 @@ -/**************************************************************************** - Copyright (c) 2010-2012 cocos2d-x.org - Copyright (c) 2013-2016 Chukong Technologies Inc. - Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd. - - http://www.cocos2d-x.org - - Permission is hereby granted, free of charge, to any person obtaining a copy - of this software and associated documentation files (the "Software"), to deal - in the Software without restriction, including without limitation the rights - to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - copies of the Software, and to permit persons to whom the Software is - furnished to do so, subject to the following conditions: - - The above copyright notice and this permission notice shall be included in - all copies or substantial portions of the Software. - - THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - 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 "base/CCTouch.h" -#include "base/CCDirector.h" - -NS_CC_BEGIN - -// returns the current touch location in screen coordinates -Vec2 Touch::getLocationInView() const -{ - return _point; -} - -// returns the previous touch location in screen coordinates -Vec2 Touch::getPreviousLocationInView() const -{ - return _prevPoint; -} - -// returns the start touch location in screen coordinates -Vec2 Touch::getStartLocationInView() const -{ - return _startPoint; -} - -// returns the current touch location in OpenGL coordinates -Vec2 Touch::getLocation() const -{ - return Director::getInstance()->convertToGL(_point); -} - -// returns the previous touch location in OpenGL coordinates -Vec2 Touch::getPreviousLocation() const -{ - return Director::getInstance()->convertToGL(_prevPoint); -} - -// returns the start touch location in OpenGL coordinates -Vec2 Touch::getStartLocation() const -{ - return Director::getInstance()->convertToGL(_startPoint); -} - -// returns the delta position between the current location and the previous location in OpenGL coordinates -Vec2 Touch::getDelta() const -{ - return getLocation() - getPreviousLocation(); -} - -// Returns the current touch force for 3d touch. -float Touch::getCurrentForce() const -{ - return _curForce; -} - -// Returns the maximum touch force for 3d touch. -float Touch::getMaxForce() const -{ - return _maxForce; -} - -NS_CC_END - diff --git a/native/cocos/base/CCTouch.h b/native/cocos/base/CCTouch.h deleted file mode 100644 index 3d09a6b9db..0000000000 --- a/native/cocos/base/CCTouch.h +++ /dev/null @@ -1,184 +0,0 @@ -/**************************************************************************** -Copyright (c) 2010-2012 cocos2d-x.org -Copyright (c) 2013-2016 Chukong Technologies Inc. -Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd. - -http://www.cocos2d-x.org - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in -all copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -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. -****************************************************************************/ - -#ifndef __CC_TOUCH_H__ -#define __CC_TOUCH_H__ - -#include "base/CCRef.h" -#include "math/CCGeometry.h" - -NS_CC_BEGIN - -/** - * @addtogroup base - * @{ - */ - -/** @class Touch - * @brief Encapsulates the Touch information, such as touch point, id and so on, - and provides the methods that commonly used. - */ -class CC_DLL Touch : public Ref -{ -public: - /** - * Dispatch mode, how the touches are dispatched. - * @js NA - */ - enum class DispatchMode { - ALL_AT_ONCE, /** All at once. */ - ONE_BY_ONE, /** One by one. */ - }; - - /** Constructor. - * @js ctor - */ - Touch() - : _id(0), - _startPointCaptured(false), - _curForce(0.f), - _maxForce(0.f) - {} - - /** Returns the current touch location in OpenGL coordinates. - * - * @return The current touch location in OpenGL coordinates. - */ - Vec2 getLocation() const; - /** Returns the previous touch location in OpenGL coordinates. - * - * @return The previous touch location in OpenGL coordinates. - */ - Vec2 getPreviousLocation() const; - /** Returns the start touch location in OpenGL coordinates. - * - * @return The start touch location in OpenGL coordinates. - */ - Vec2 getStartLocation() const; - /** Returns the delta of 2 current touches locations in screen coordinates. - * - * @return The delta of 2 current touches locations in screen coordinates. - */ - Vec2 getDelta() const; - /** Returns the current touch location in screen coordinates. - * - * @return The current touch location in screen coordinates. - */ - Vec2 getLocationInView() const; - /** Returns the previous touch location in screen coordinates. - * - * @return The previous touch location in screen coordinates. - */ - Vec2 getPreviousLocationInView() const; - /** Returns the start touch location in screen coordinates. - * - * @return The start touch location in screen coordinates. - */ - Vec2 getStartLocationInView() const; - - /** Set the touch information. It always used to monitor touch event. - * - * @param id A given id - * @param x A given x coordinate. - * @param y A given y coordinate. - */ - void setTouchInfo(int id, float x, float y) - { - _id = id; - _prevPoint = _point; - _point.x = x; - _point.y = y; - _curForce = 0.0f; - _maxForce = 0.0f; - if (!_startPointCaptured) - { - _startPoint = _point; - _startPointCaptured = true; - _prevPoint = _point; - } - } - - /** Set the touch information. It always used to monitor touch event. - * - * @param id A given id - * @param x A given x coordinate. - * @param y A given y coordinate. - * @param force Current force for 3d touch. - * @param maxForce maximum possible force for 3d touch. - */ - void setTouchInfo(int id, float x, float y, float force, float maxForce) - { - _id = id; - _prevPoint = _point; - _point.x = x; - _point.y = y; - _curForce = force; - _maxForce = maxForce; - if (!_startPointCaptured) - { - _startPoint = _point; - _startPointCaptured = true; - _prevPoint = _point; - } - } - /** Get touch id. - * @js getId - * @lua getId - * - * @return The id of touch. - */ - int getID() const - { - return _id; - } - /** Returns the current touch force for 3d touch. - * - * @return The current touch force for 3d touch. - */ - float getCurrentForce() const; - /** Returns the maximum touch force for 3d touch. - * - * @return The maximum touch force for 3d touch. - */ - float getMaxForce() const; - -private: - int _id; - bool _startPointCaptured; - Vec2 _startPoint; - Vec2 _point; - Vec2 _prevPoint; - float _curForce; - float _maxForce; -}; - -// end of base group -/// @} - -NS_CC_END - -#endif // __PLATFORM_TOUCH_H__ - diff --git a/native/cocos/base/CCUserDefault.h b/native/cocos/base/CCUserDefault.h index 2ddcf036a3..430289d92a 100644 --- a/native/cocos/base/CCUserDefault.h +++ b/native/cocos/base/CCUserDefault.h @@ -26,7 +26,7 @@ THE SOFTWARE. #ifndef __SUPPORT_CCUSERDEFAULT_H__ #define __SUPPORT_CCUSERDEFAULT_H__ -#include "platform/CCPlatformMacros.h" +#include "base/ccMacros.h" #include #include "base/CCData.h" diff --git a/native/cocos/base/CCValue.h b/native/cocos/base/CCValue.h index c6c7c65f79..707c312504 100644 --- a/native/cocos/base/CCValue.h +++ b/native/cocos/base/CCValue.h @@ -26,7 +26,7 @@ #ifndef __cocos2d_libs__CCValue__ #define __cocos2d_libs__CCValue__ -#include "platform/CCPlatformMacros.h" +#include "base/ccMacros.h" #include "base/ccMacros.h" #include #include diff --git a/native/cocos/base/ObjectFactory.h b/native/cocos/base/ObjectFactory.h index c29cc94c16..7100c1285b 100644 --- a/native/cocos/base/ObjectFactory.h +++ b/native/cocos/base/ObjectFactory.h @@ -30,7 +30,7 @@ THE SOFTWARE. #include #include #include "base/CCRef.h" -#include "platform/CCPlatformMacros.h" +#include "base/ccMacros.h" NS_CC_BEGIN diff --git a/native/cocos/base/ZipUtils.h b/native/cocos/base/ZipUtils.h index d5d82beb94..1bce3f5bef 100644 --- a/native/cocos/base/ZipUtils.h +++ b/native/cocos/base/ZipUtils.h @@ -30,7 +30,7 @@ THE SOFTWARE. #include #include "platform/CCPlatformConfig.h" -#include "platform/CCPlatformMacros.h" +#include "base/ccMacros.h" #include "platform/CCPlatformDefine.h" #include "platform/CCFileUtils.h" diff --git a/native/cocos/base/base64.h b/native/cocos/base/base64.h index 068fea0b2f..f41939916f 100644 --- a/native/cocos/base/base64.h +++ b/native/cocos/base/base64.h @@ -28,7 +28,7 @@ THE SOFTWARE. #define __SUPPORT_BASE64_H__ /// @cond DO_NOT_SHOW -#include "platform/CCPlatformMacros.h" +#include "base/ccMacros.h" #ifdef __cplusplus extern "C" { diff --git a/native/cocos/base/ccMacros.h b/native/cocos/base/ccMacros.h index 447606b110..495ff77c08 100644 --- a/native/cocos/base/ccMacros.h +++ b/native/cocos/base/ccMacros.h @@ -25,17 +25,24 @@ 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. ****************************************************************************/ +#pragma once -#ifndef __BASE_CCMACROS_H__ -#define __BASE_CCMACROS_H__ - +/* #ifndef _USE_MATH_DEFINES #define _USE_MATH_DEFINES #endif +*/ -#include "platform/CCStdC.h" -#include "base/ccUtils.h" +#include "base/CCLog.h" +#include "base/ccConfig.h" +#if (CC_TARGET_PLATFORM == CC_PLATFORM_WIN32) +#include +#ifndef __SSIZE_T +#define __SSIZE_T +typedef SSIZE_T ssize_t; +#endif // __SSIZE_T +#endif #ifndef CCASSERT #if COCOS2D_DEBUG > 0 @@ -57,33 +64,7 @@ THE SOFTWARE. #endif #define GP_ASSERT(cond) CCASSERT(cond, "") - -// FIXME:: Backward compatible -#define CCAssert CCASSERT -#endif // CCASSERT - -#include "base/ccConfig.h" - -/** @def CC_SWAP -simple macro that swaps 2 variables - @deprecated use std::swap() instead -*/ -#define CC_SWAP(x, y, type) \ -{ type temp = (x); \ - x = y; y = temp; \ -} - -#include "base/ccRandom.h" - -/** @def CCRANDOM_MINUS1_1 - returns a random float between -1 and 1 - */ -#define CCRANDOM_MINUS1_1() cocos2d::rand_minus1_1() - -/** @def CCRANDOM_0_1 - returns a random float between 0 and 1 - */ -#define CCRANDOM_0_1() cocos2d::rand_0_1() +#endif // CCASSERT /** @def CC_DEGREES_TO_RADIANS converts degrees to radians @@ -95,91 +76,6 @@ simple macro that swaps 2 variables */ #define CC_RADIANS_TO_DEGREES(__ANGLE__) ((__ANGLE__) * 57.29577951f) // PI * 180 -#define CC_REPEAT_FOREVER (UINT_MAX -1) -#define kRepeatForever CC_REPEAT_FOREVER - -/** @def CC_BLEND_SRC -default gl blend src function. Compatible with premultiplied alpha images. -*/ -#define CC_BLEND_SRC GL_ONE -#define CC_BLEND_DST GL_ONE_MINUS_SRC_ALPHA - - -/** @def CC_NODE_DRAW_SETUP - Helpful macro that setups the GL server state, the correct GL program and sets the Model View Projection matrix - @since v2.0 - */ -#define CC_NODE_DRAW_SETUP() \ -do { \ - CCASSERT(getGLProgram(), "No shader program set for this node"); \ - { \ - getGLProgram()->use(); \ - getGLProgram()->setUniformsForBuiltins(_modelViewTransform); \ - } \ -} while(0) - - - /** @def CC_DIRECTOR_END - Stops and removes the director from memory. - Removes the GLView from its parent - - @since v0.99.4 - */ -#define CC_DIRECTOR_END() \ -do { \ - Director *__director = cocos2d::Director::getInstance(); \ - __director->end(); \ -} while(0) - -/** @def CC_CONTENT_SCALE_FACTOR -On Mac it returns 1; -On iPhone it returns 2 if RetinaDisplay is On. Otherwise it returns 1 -*/ -#define CC_CONTENT_SCALE_FACTOR() cocos2d::Director::getInstance()->getContentScaleFactor() - -/****************************/ -/** RETINA DISPLAY ENABLED **/ -/****************************/ - -/** @def CC_RECT_PIXELS_TO_POINTS - Converts a rect in pixels to points - */ -#define CC_RECT_PIXELS_TO_POINTS(__rect_in_pixels__) \ - Rect( (__rect_in_pixels__).origin.x / CC_CONTENT_SCALE_FACTOR(), (__rect_in_pixels__).origin.y / CC_CONTENT_SCALE_FACTOR(), \ - (__rect_in_pixels__).size.width / CC_CONTENT_SCALE_FACTOR(), (__rect_in_pixels__).size.height / CC_CONTENT_SCALE_FACTOR() ) - -/** @def CC_RECT_POINTS_TO_PIXELS - Converts a rect in points to pixels - */ -#define CC_RECT_POINTS_TO_PIXELS(__rect_in_points_points__) \ - Rect( (__rect_in_points_points__).origin.x * CC_CONTENT_SCALE_FACTOR(), (__rect_in_points_points__).origin.y * CC_CONTENT_SCALE_FACTOR(), \ - (__rect_in_points_points__).size.width * CC_CONTENT_SCALE_FACTOR(), (__rect_in_points_points__).size.height * CC_CONTENT_SCALE_FACTOR() ) - -/** @def CC_POINT_PIXELS_TO_POINTS - Converts a rect in pixels to points - */ -#define CC_POINT_PIXELS_TO_POINTS(__pixels__) \ -Vec2( (__pixels__).x / CC_CONTENT_SCALE_FACTOR(), (__pixels__).y / CC_CONTENT_SCALE_FACTOR()) - -/** @def CC_POINT_POINTS_TO_PIXELS - Converts a rect in points to pixels - */ -#define CC_POINT_POINTS_TO_PIXELS(__points__) \ -Vec2( (__points__).x * CC_CONTENT_SCALE_FACTOR(), (__points__).y * CC_CONTENT_SCALE_FACTOR()) - -/** @def CC_POINT_PIXELS_TO_POINTS - Converts a rect in pixels to points - */ -#define CC_SIZE_PIXELS_TO_POINTS(__size_in_pixels__) \ -Size( (__size_in_pixels__).width / CC_CONTENT_SCALE_FACTOR(), (__size_in_pixels__).height / CC_CONTENT_SCALE_FACTOR()) - -/** @def CC_POINT_POINTS_TO_PIXELS - Converts a rect in points to pixels - */ -#define CC_SIZE_POINTS_TO_PIXELS(__size_in_points__) \ -Size( (__size_in_points__).width * CC_CONTENT_SCALE_FACTOR(), (__size_in_points__).height * CC_CONTENT_SCALE_FACTOR()) - - #ifndef FLT_EPSILON #define FLT_EPSILON 1.192092896e-07F #endif // FLT_EPSILON @@ -188,6 +84,17 @@ Size( (__size_in_points__).width * CC_CONTENT_SCALE_FACTOR(), (__size_in_points_ TypeName(const TypeName&);\ void operator=(const TypeName&) + + /** @def CC_SWAP + simple macro that swaps 2 variables + @deprecated use std::swap() instead + */ +#define CC_SWAP(x, y, type) \ +{ type temp = (x); \ + x = y; y = temp; \ +} + + /** Helper macros which converts 4-byte little/big endian integral number to the machine native number representation @@ -204,46 +111,6 @@ It should work same as apples CFSwapInt32LittleToHost(..) #define CC_SWAP_INT32_BIG_TO_HOST(i) ((CC_HOST_IS_BIG_ENDIAN == true)? (i) : CC_SWAP32(i) ) #define CC_SWAP_INT16_BIG_TO_HOST(i) ((CC_HOST_IS_BIG_ENDIAN == true)? (i): CC_SWAP16(i) ) -/**********************/ -/** Profiling Macros **/ -/**********************/ -#if CC_ENABLE_PROFILERS - -#define CC_PROFILER_DISPLAY_TIMERS() NS_CC::Profiler::getInstance()->displayTimers() -#define CC_PROFILER_PURGE_ALL() NS_CC::Profiler::getInstance()->releaseAllTimers() - -#define CC_PROFILER_START(__name__) NS_CC::ProfilingBeginTimingBlock(__name__) -#define CC_PROFILER_STOP(__name__) NS_CC::ProfilingEndTimingBlock(__name__) -#define CC_PROFILER_RESET(__name__) NS_CC::ProfilingResetTimingBlock(__name__) - -#define CC_PROFILER_START_CATEGORY(__cat__, __name__) do{ if(__cat__) NS_CC::ProfilingBeginTimingBlock(__name__); } while(0) -#define CC_PROFILER_STOP_CATEGORY(__cat__, __name__) do{ if(__cat__) NS_CC::ProfilingEndTimingBlock(__name__); } while(0) -#define CC_PROFILER_RESET_CATEGORY(__cat__, __name__) do{ if(__cat__) NS_CC::ProfilingResetTimingBlock(__name__); } while(0) - -#define CC_PROFILER_START_INSTANCE(__id__, __name__) do{ NS_CC::ProfilingBeginTimingBlock( NS_CC::String::createWithFormat("%08X - %s", __id__, __name__)->getCString() ); } while(0) -#define CC_PROFILER_STOP_INSTANCE(__id__, __name__) do{ NS_CC::ProfilingEndTimingBlock( NS_CC::String::createWithFormat("%08X - %s", __id__, __name__)->getCString() ); } while(0) -#define CC_PROFILER_RESET_INSTANCE(__id__, __name__) do{ NS_CC::ProfilingResetTimingBlock( NS_CC::String::createWithFormat("%08X - %s", __id__, __name__)->getCString() ); } while(0) - - -#else - -#define CC_PROFILER_DISPLAY_TIMERS() do {} while (0) -#define CC_PROFILER_PURGE_ALL() do {} while (0) - -#define CC_PROFILER_START(__name__) do {} while (0) -#define CC_PROFILER_STOP(__name__) do {} while (0) -#define CC_PROFILER_RESET(__name__) do {} while (0) - -#define CC_PROFILER_START_CATEGORY(__cat__, __name__) do {} while(0) -#define CC_PROFILER_STOP_CATEGORY(__cat__, __name__) do {} while(0) -#define CC_PROFILER_RESET_CATEGORY(__cat__, __name__) do {} while(0) - -#define CC_PROFILER_START_INSTANCE(__id__, __name__) do {} while(0) -#define CC_PROFILER_STOP_INSTANCE(__id__, __name__) do {} while(0) -#define CC_PROFILER_RESET_INSTANCE(__id__, __name__) do {} while(0) - -#endif - #if !defined(COCOS2D_DEBUG) || COCOS2D_DEBUG == 0 #define CHECK_GL_ERROR_DEBUG() #else @@ -254,7 +121,7 @@ It should work same as apples CFSwapInt32LittleToHost(..) cocos2d::log("OpenGL error 0x%04X in %s %s %d\n", __error, __FILE__, __FUNCTION__, __LINE__); \ } \ } while (false) -#endif +#endif // !defined(COCOS2D_DEBUG) || COCOS2D_DEBUG == 0 /** * GL assertion that can be used for any OpenGL function call. @@ -273,7 +140,7 @@ gl_code; \ __gl_error_code = glGetError(); \ CC_ASSERT(__gl_error_code == GL_NO_ERROR, "Error"); \ } while(0) -#endif +#endif // defined(NDEBUG) || (defined(__APPLE__) && !defined(DEBUG)) /*********************************/ /** 64bits Program Sense Macros **/ @@ -284,31 +151,145 @@ CC_ASSERT(__gl_error_code == GL_NO_ERROR, "Error"); \ #define CC_64BITS 0 #endif - -/** @def CC_INCREMENT_GL_DRAWS_BY_ONE - Increments the GL Draws counts by one. - The number of calls per frame are displayed on the screen when the Director's stats are enabled. - */ -#define CC_INCREMENT_GL_DRAWS(__n__) cocos2d::Director::getInstance()->getRenderer()->addDrawnBatches(__n__) -#define CC_INCREMENT_GL_DRAWN_BATCHES_AND_VERTICES(__drawcalls__, __vertices__) \ - do { \ - auto __renderer__ = cocos2d::Director::getInstance()->getRenderer(); \ - __renderer__->addDrawnBatches(__drawcalls__); \ - __renderer__->addDrawnVertices(__vertices__); \ - } while(0) - -/*******************/ -/** Notifications **/ -/*******************/ -/** @def AnimationFrameDisplayedNotification - Notification name when a SpriteFrame is displayed - */ -#define AnimationFrameDisplayedNotification "CCAnimationFrameDisplayedNotification" - // new callbacks based on C++11 #define CC_CALLBACK_0(__selector__,__target__, ...) std::bind(&__selector__,__target__, ##__VA_ARGS__) #define CC_CALLBACK_1(__selector__,__target__, ...) std::bind(&__selector__,__target__, std::placeholders::_1, ##__VA_ARGS__) #define CC_CALLBACK_2(__selector__,__target__, ...) std::bind(&__selector__,__target__, std::placeholders::_1, std::placeholders::_2, ##__VA_ARGS__) #define CC_CALLBACK_3(__selector__,__target__, ...) std::bind(&__selector__,__target__, std::placeholders::_1, std::placeholders::_2, std::placeholders::_3, ##__VA_ARGS__) -#endif // __BASE_CCMACROS_H__ +// Generic macros + +/// @name namespace cocos2d +/// @{ +#ifdef __cplusplus +#define NS_CC_BEGIN namespace cocos2d { +#define NS_CC_END } +#define USING_NS_CC using namespace cocos2d +#define NS_CC ::cocos2d +#else +#define NS_CC_BEGIN +#define NS_CC_END +#define USING_NS_CC +#define NS_CC +#endif +// end of namespace group +/// @} + +#define CC_SAFE_DELETE(p) do { delete (p); (p) = nullptr; } while(0) +#define CC_SAFE_DELETE_ARRAY(p) do { if(p) { delete[] (p); (p) = nullptr; } } while(0) +#define CC_SAFE_FREE(p) do { if(p) { free(p); (p) = nullptr; } } while(0) +#define CC_SAFE_RELEASE(p) do { if(p) { (p)->release(); } } while(0) +#define CC_SAFE_RELEASE_NULL(p) do { if(p) { (p)->release(); (p) = nullptr; } } while(0) +#define CC_SAFE_RETAIN(p) do { if(p) { (p)->retain(); } } while(0) +#define CC_BREAK_IF(cond) if(cond) break + +#define __CCLOGWITHFUNCTION(s, ...) \ + cocos2d::log("%s : %s",__FUNCTION__, cocos2d::StringUtils::format(s, ##__VA_ARGS__).c_str()) + +/// @name Cocos2d debug +/// @{ +#if !defined(COCOS2D_DEBUG) || COCOS2D_DEBUG == 0 +#define CCLOG(...) do {} while (0) +#define CCLOGINFO(...) do {} while (0) +#define CCLOGERROR(...) do {} while (0) +#define CCLOGWARN(...) do {} while (0) + +#elif COCOS2D_DEBUG == 1 + +#if (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID) +#define COCOS_LOG_TAG "cocos2d-x" +#define CCLOG(...) __android_log_print(ANDROID_LOG_DEBUG, COCOS_LOG_TAG, __VA_ARGS__) +#define CCLOGINFO(format,...) do {} while (0) +#define CCLOGWARN(...) __android_log_print(ANDROID_LOG_WARN, COCOS_LOG_TAG, __VA_ARGS__) +#define CCLOGERROR(...) __android_log_print(ANDROID_LOG_ERROR, COCOS_LOG_TAG, __VA_ARGS__) +#else +#define CCLOG(format, ...) cocos2d::log(format, ##__VA_ARGS__) +#define CCLOGERROR(format,...) cocos2d::log(format, ##__VA_ARGS__) +#define CCLOGINFO(format,...) do {} while (0) +#define CCLOGWARN(...) __CCLOGWITHFUNCTION(__VA_ARGS__) +#endif + + +#elif COCOS2D_DEBUG > 1 +#define CCLOG(format, ...) cocos2d::log(format, ##__VA_ARGS__) +#define CCLOGERROR(format,...) cocos2d::log(format, ##__VA_ARGS__) +#define CCLOGINFO(format,...) cocos2d::log(format, ##__VA_ARGS__) +#define CCLOGWARN(...) __CCLOGWITHFUNCTION(__VA_ARGS__) +#endif // COCOS2D_DEBUG + +// end of debug group +/// @} + +/** @def CC_DISALLOW_COPY_AND_ASSIGN(TypeName) +* A macro to disallow the copy constructor and operator= functions. +* This should be used in the private: declarations for a class +*/ +#if defined(__GNUC__) && ((__GNUC__ >= 5) || ((__GNUG__ == 4) && (__GNUC_MINOR__ >= 4))) \ + || (defined(__clang__) && (__clang_major__ >= 3)) || (_MSC_VER >= 1800) +#define CC_DISALLOW_COPY_AND_ASSIGN(TypeName) \ + TypeName(const TypeName &) = delete; \ + TypeName &operator =(const TypeName &) = delete; +#else +#define CC_DISALLOW_COPY_AND_ASSIGN(TypeName) \ + TypeName(const TypeName &); \ + TypeName &operator =(const TypeName &); +#endif + +/** @def CC_DEPRECATED_ATTRIBUTE +* Only certain compilers support __attribute__((deprecated)). +*/ +#if defined(__GNUC__) && ((__GNUC__ >= 4) || ((__GNUC__ == 3) && (__GNUC_MINOR__ >= 1))) +#define CC_DEPRECATED_ATTRIBUTE __attribute__((deprecated)) +#elif _MSC_VER >= 1400 //vs 2005 or higher +#define CC_DEPRECATED_ATTRIBUTE __declspec(deprecated) +#else +#define CC_DEPRECATED_ATTRIBUTE +#endif + +/** @def CC_DEPRECATED(...) +* Macro to mark things deprecated as of a particular version +* can be used with arbitrary parameters which are thrown away. +* e.g. CC_DEPRECATED(4.0) or CC_DEPRECATED(4.0, "not going to need this anymore") etc. +*/ +#define CC_DEPRECATED(...) CC_DEPRECATED_ATTRIBUTE + +/** @def CC_FORMAT_PRINTF(formatPos, argPos) +* Only certain compiler support __attribute__((format)) +* +* @param formatPos 1-based position of format string argument. +* @param argPos 1-based position of first format-dependent argument. +*/ +#if defined(__GNUC__) && (__GNUC__ >= 4) +#define CC_FORMAT_PRINTF(formatPos, argPos) __attribute__((__format__(printf, formatPos, argPos))) +#elif defined(__has_attribute) +#if __has_attribute(format) +#define CC_FORMAT_PRINTF(formatPos, argPos) __attribute__((__format__(printf, formatPos, argPos))) +#endif // __has_attribute(format) +#else +#define CC_FORMAT_PRINTF(formatPos, argPos) +#endif + +#if defined(_MSC_VER) +#define CC_FORMAT_PRINTF_SIZE_T "%08lX" +#else +#define CC_FORMAT_PRINTF_SIZE_T "%08zX" +#endif + +#ifdef __GNUC__ +#define CC_UNUSED __attribute__ ((unused)) +#else +#define CC_UNUSED +#endif + +/** @def CC_REQUIRES_NULL_TERMINATION +* +*/ +#if !defined(CC_REQUIRES_NULL_TERMINATION) +#if defined(__APPLE_CC__) && (__APPLE_CC__ >= 5549) +#define CC_REQUIRES_NULL_TERMINATION __attribute__((sentinel(0,1))) +#elif defined(__GNUC__) +#define CC_REQUIRES_NULL_TERMINATION __attribute__((sentinel)) +#else +#define CC_REQUIRES_NULL_TERMINATION +#endif +#endif diff --git a/native/cocos/base/ccRandom.h b/native/cocos/base/ccRandom.h index bfb8093f38..cfdd56e64b 100644 --- a/native/cocos/base/ccRandom.h +++ b/native/cocos/base/ccRandom.h @@ -30,7 +30,7 @@ THE SOFTWARE. #include #include -#include "platform/CCPlatformMacros.h" +#include "base/ccMacros.h" /** * @addtogroup base diff --git a/native/cocos/base/ccUTF8.cpp b/native/cocos/base/ccUTF8.cpp index c754c19bf3..ce66f1e055 100644 --- a/native/cocos/base/ccUTF8.cpp +++ b/native/cocos/base/ccUTF8.cpp @@ -25,7 +25,7 @@ ****************************************************************************/ #include "base/ccUTF8.h" -#include "base/CCConsole.h" +#include #include "ConvertUTF/ConvertUTF.h" NS_CC_BEGIN diff --git a/native/cocos/base/ccUTF8.h b/native/cocos/base/ccUTF8.h index 90d8474abb..d7527855ff 100644 --- a/native/cocos/base/ccUTF8.h +++ b/native/cocos/base/ccUTF8.h @@ -27,7 +27,7 @@ #ifndef __cocos2dx__ccUTF8__ #define __cocos2dx__ccUTF8__ -#include "platform/CCPlatformMacros.h" +#include "base/ccMacros.h" #include #include #include diff --git a/native/cocos/base/ccUtils.cpp b/native/cocos/base/ccUtils.cpp index 3fbbc851d9..c478217c14 100644 --- a/native/cocos/base/ccUtils.cpp +++ b/native/cocos/base/ccUtils.cpp @@ -34,20 +34,25 @@ THE SOFTWARE. NS_CC_BEGIN -void log(const char * format, ...) +namespace { - -} +#if (CC_TARGET_PLATFORM == CC_PLATFORM_WIN32) +#include "platform/CCStdC.h" +#include -int ccNextPOT(int x) -{ - x = x - 1; - x = x | (x >> 1); - x = x | (x >> 2); - x = x | (x >> 4); - x = x | (x >> 8); - x = x | (x >>16); - return x + 1; + 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 @@ -89,6 +94,17 @@ long long getTimeInMilliseconds() return (long long)tv.tv_sec * 1000 + tv.tv_usec / 1000; } +int nextPOT(int x) +{ + x = x - 1; + x = x | (x >> 1); + x = x | (x >> 2); + x = x | (x >> 4); + x = x | (x >> 8); + x = x | (x >> 16); + return x + 1; +} + } NS_CC_END diff --git a/native/cocos/base/ccUtils.h b/native/cocos/base/ccUtils.h index a613d3179b..1f00dcf0ba 100644 --- a/native/cocos/base/ccUtils.h +++ b/native/cocos/base/ccUtils.h @@ -23,13 +23,11 @@ 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. ****************************************************************************/ -#ifndef __SUPPORT_CC_UTILS_H__ -#define __SUPPORT_CC_UTILS_H__ +#pragma once #include #include #include "base/ccMacros.h" -#include "platform/CCPlatformMacros.h" /** @file ccUtils.h Misc free functions @@ -37,7 +35,7 @@ Misc free functions NS_CC_BEGIN /* -ccNextPOT function is licensed under the same license that is used in Texture2D.m. +utils::nextPOT function is licensed under the same license that is used in Texture2D.m. */ /** Returns the Next Power of Two value. @@ -51,14 +49,11 @@ Examples: @since v0.99.5 */ -int ccNextPOT(int value); - -void log(const char * format, ...); - class Image; namespace utils { + CC_DLL int nextPOT(int x); /** Same to ::atof, but strip the string, remain 7 numbers after '.' before call atof. * Why we need this? Because in android c++_static, atof ( and std::atof ) is unsupported for numbers have long decimal part and contain * several numbers can approximate to 1 ( like 90.099998474121094 ), it will return inf. This function is used to fix this bug. @@ -82,4 +77,3 @@ namespace utils NS_CC_END -#endif // __SUPPORT_CC_UTILS_H__ diff --git a/native/cocos/cocos2d.cpp b/native/cocos/cocos2d.cpp index 3985c767a1..e05786eb52 100644 --- a/native/cocos/cocos2d.cpp +++ b/native/cocos/cocos2d.cpp @@ -26,7 +26,7 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. ****************************************************************************/ -#include "platform/CCPlatformMacros.h" +#include "base/ccMacros.h" NS_CC_BEGIN diff --git a/native/cocos/cocos2d.h b/native/cocos/cocos2d.h index 5b56db7e5a..e39eb27aae 100644 --- a/native/cocos/cocos2d.h +++ b/native/cocos/cocos2d.h @@ -40,13 +40,9 @@ THE SOFTWARE. // base #include "base/CCAutoreleasePool.h" -#include "base/CCConsole.h" #include "base/CCData.h" -#include "base/CCIMEDelegate.h" -#include "base/CCIMEDispatcher.h" #include "base/CCMap.h" #include "base/CCNS.h" -#include "base/CCProfiling.h" #include "base/CCRef.h" #include "base/CCRefPtr.h" #include "base/CCUserDefault.h" @@ -83,7 +79,7 @@ THE SOFTWARE. #include "platform/CCFileUtils.h" #include "platform/CCImage.h" #include "platform/CCPlatformConfig.h" -#include "platform/CCPlatformMacros.h" +#include "base/ccMacros.h" #include "platform/CCSAXParser.h" #if (CC_TARGET_PLATFORM == CC_PLATFORM_IOS) diff --git a/native/cocos/math/CCAffineTransform.h b/native/cocos/math/CCAffineTransform.h index 640da6d332..e57c28b57e 100644 --- a/native/cocos/math/CCAffineTransform.h +++ b/native/cocos/math/CCAffineTransform.h @@ -27,7 +27,7 @@ THE SOFTWARE. #ifndef __MATH_CCAFFINETRANSFORM_H__ #define __MATH_CCAFFINETRANSFORM_H__ -#include "platform/CCPlatformMacros.h" +#include "base/ccMacros.h" #include "math/CCGeometry.h" #include "math/CCMath.h" diff --git a/native/cocos/math/CCGeometry.h b/native/cocos/math/CCGeometry.h index 2412127011..4fc12c046f 100644 --- a/native/cocos/math/CCGeometry.h +++ b/native/cocos/math/CCGeometry.h @@ -27,7 +27,7 @@ THE SOFTWARE. #ifndef __MATH_CCGEOMETRY_H__ #define __MATH_CCGEOMETRY_H__ -#include "platform/CCPlatformMacros.h" +#include "base/ccMacros.h" #include "base/ccMacros.h" #include "math/CCMath.h" diff --git a/native/cocos/math/CCMathBase.h b/native/cocos/math/CCMathBase.h index 778246878c..5561514572 100644 --- a/native/cocos/math/CCMathBase.h +++ b/native/cocos/math/CCMathBase.h @@ -28,7 +28,7 @@ #include #include -#include "platform/CCPlatformMacros.h" +#include "base/ccMacros.h" /** * @addtogroup base * @{ diff --git a/native/cocos/network/CCDownloader.h b/native/cocos/network/CCDownloader.h index de409b0c91..89fe44ca75 100644 --- a/native/cocos/network/CCDownloader.h +++ b/native/cocos/network/CCDownloader.h @@ -31,7 +31,7 @@ #include #include -#include "platform/CCPlatformMacros.h" +#include "base/ccMacros.h" namespace cocos2d { namespace network { diff --git a/native/cocos/network/SocketIO.h b/native/cocos/network/SocketIO.h index 35e01097ab..05b8d47fdb 100644 --- a/native/cocos/network/SocketIO.h +++ b/native/cocos/network/SocketIO.h @@ -62,7 +62,7 @@ in the onClose method the pointer should be set to NULL or used to connect to a #include #include -#include "platform/CCPlatformMacros.h" +#include "base/ccMacros.h" #include "base/CCMap.h" diff --git a/native/cocos/network/Uri.h b/native/cocos/network/Uri.h index eda89f4311..74668ecd9f 100644 --- a/native/cocos/network/Uri.h +++ b/native/cocos/network/Uri.h @@ -19,7 +19,7 @@ #pragma once -#include "platform/CCPlatformMacros.h" +#include "base/ccMacros.h" #include #include diff --git a/native/cocos/network/WebSocket.h b/native/cocos/network/WebSocket.h index 9bb16b4e54..60eee3c990 100644 --- a/native/cocos/network/WebSocket.h +++ b/native/cocos/network/WebSocket.h @@ -27,7 +27,7 @@ #pragma once -#include "platform/CCPlatformMacros.h" +#include "base/ccMacros.h" #include "platform/CCStdC.h" #include "base/CCRef.h" diff --git a/native/cocos/platform/CCApplication.h b/native/cocos/platform/CCApplication.h index 18e93061ef..b38df447cf 100644 --- a/native/cocos/platform/CCApplication.h +++ b/native/cocos/platform/CCApplication.h @@ -22,11 +22,12 @@ 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. ****************************************************************************/ - #pragma once #include -#include "platform/CCPlatformMacros.h" +#include "base/ccMacros.h" +#include "platform/CCPlatformConfig.h" +#include "platform/CCPlatformDefine.h" NS_CC_BEGIN @@ -156,7 +157,7 @@ private: void* _view = nullptr; bool _multiTouch = false; void* _delegate = nullptr; - float _animationInterval = 1.0 / 60; + float _animationInterval = 1.0f / 60; }; // end of platform group diff --git a/native/cocos/platform/CCDevice.h b/native/cocos/platform/CCDevice.h index b7b5fe5f85..b4f6ce6291 100644 --- a/native/cocos/platform/CCDevice.h +++ b/native/cocos/platform/CCDevice.h @@ -27,7 +27,7 @@ THE SOFTWARE. #ifndef __CCDEVICE_H__ #define __CCDEVICE_H__ -#include "platform/CCPlatformMacros.h" +#include "base/ccMacros.h" #include "base/ccMacros.h" #include "base/CCData.h" @@ -113,7 +113,8 @@ public: static NetworkType getNetworkType(); private: - CC_DISALLOW_IMPLICIT_CONSTRUCTORS(Device); + Device(); + CC_DISALLOW_COPY_AND_ASSIGN(Device); }; // end group diff --git a/native/cocos/platform/CCFileUtils.h b/native/cocos/platform/CCFileUtils.h index cfdab3f81b..8f69593e5b 100644 --- a/native/cocos/platform/CCFileUtils.h +++ b/native/cocos/platform/CCFileUtils.h @@ -31,7 +31,7 @@ THE SOFTWARE. #include #include -#include "platform/CCPlatformMacros.h" +#include "base/ccMacros.h" #include "base/ccTypes.h" #include "base/CCValue.h" #include "base/CCData.h" diff --git a/native/cocos/platform/CCImage.cpp b/native/cocos/platform/CCImage.cpp index b2e1a1184e..5724a8cd53 100644 --- a/native/cocos/platform/CCImage.cpp +++ b/native/cocos/platform/CCImage.cpp @@ -31,6 +31,7 @@ THE SOFTWARE. #include "base/CCData.h" #include "base/ccConfig.h" // CC_USE_JPEG, CC_USE_TIFF, CC_USE_WEBP +#include "base/ccUtils.h" extern "C" { @@ -1187,8 +1188,8 @@ bool Image::initWithPVRv2Data(const unsigned char * data, ssize_t dataLen) } if (! configuration->supportsNPOT() && - (static_cast(header->width) != ccNextPOT(header->width) - || static_cast(header->height) != ccNextPOT(header->height))) + (static_cast(header->width) != utils::nextPOT(header->width) + || static_cast(header->height) != utils::nextPOT(header->height))) { CCLOG("cocos2d: ERROR: Loading an NPOT texture (%dx%d) but is not supported on this device", header->width, header->height); return false; diff --git a/native/cocos/platform/CCImage.h b/native/cocos/platform/CCImage.h index 6905f112e5..f79b32b025 100644 --- a/native/cocos/platform/CCImage.h +++ b/native/cocos/platform/CCImage.h @@ -29,6 +29,7 @@ THE SOFTWARE. #include "base/CCRef.h" #include "platform/CCGL.h" +#include "platform/CCStdC.h" #include #include diff --git a/native/cocos/platform/CCPlatformMacros.h b/native/cocos/platform/CCPlatformMacros.h deleted file mode 100644 index 859d44486a..0000000000 --- a/native/cocos/platform/CCPlatformMacros.h +++ /dev/null @@ -1,330 +0,0 @@ -/**************************************************************************** -Copyright (c) 2010-2012 cocos2d-x.org -Copyright (c) 2013-2016 Chukong Technologies Inc. -Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd. - - http://www.cocos2d-x.org - - Permission is hereby granted, free of charge, to any person obtaining a copy - of this software and associated documentation files (the "Software"), to deal - in the Software without restriction, including without limitation the rights - to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - copies of the Software, and to permit persons to whom the Software is - furnished to do so, subject to the following conditions: - - The above copyright notice and this permission notice shall be included in - all copies or substantial portions of the Software. - - THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - 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. - ****************************************************************************/ - -#ifndef __CC_PLATFORM_MACROS_H__ -#define __CC_PLATFORM_MACROS_H__ - -/** - * Define some platform specific macros. - */ -#include "base/ccConfig.h" -#include "platform/CCPlatformConfig.h" -#include "platform/CCPlatformDefine.h" - -/** @def CREATE_FUNC(__TYPE__) - * Define a create function for a specific type, such as Layer. - * - * @param __TYPE__ class type to add create(), such as Layer. - */ -#define CREATE_FUNC(__TYPE__) \ -static __TYPE__* create() \ -{ \ - __TYPE__ *pRet = new(std::nothrow) __TYPE__(); \ - if (pRet && pRet->init()) \ - { \ - pRet->autorelease(); \ - return pRet; \ - } \ - else \ - { \ - delete pRet; \ - pRet = nullptr; \ - return nullptr; \ - } \ -} - -/** @def CC_ENABLE_CACHE_TEXTURE_DATA - * Enable it if you want to cache the texture data. - * Not enabling for Emscripten any more -- doesn't seem necessary and don't want - * to be different from other platforms unless there's a good reason. - * - * @since v0.99.5 - */ -#if (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID) || (CC_TARGET_PLATFORM == CC_PLATFORM_WINRT) - #define CC_ENABLE_CACHE_TEXTURE_DATA 1 -#else - #define CC_ENABLE_CACHE_TEXTURE_DATA 0 -#endif - -#if (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID) || (CC_TARGET_PLATFORM == CC_PLATFORM_WIN32) || (CC_TARGET_PLATFORM == CC_PLATFORM_EMSCRIPTEN) - /** Application will crash in glDrawElements function on some win32 computers and some android devices. - * Indices should be bound again while drawing to avoid this bug. - */ - #define CC_REBIND_INDICES_BUFFER 1 -#else - #define CC_REBIND_INDICES_BUFFER 0 -#endif - -// Generic macros - -/// @name namespace cocos2d -/// @{ -#ifdef __cplusplus - #define NS_CC_BEGIN namespace cocos2d { - #define NS_CC_END } - #define USING_NS_CC using namespace cocos2d - #define NS_CC ::cocos2d -#else - #define NS_CC_BEGIN - #define NS_CC_END - #define USING_NS_CC - #define NS_CC -#endif -// end of namespace group -/// @} - -/** @def CC_PROPERTY_READONLY - * It is used to declare a protected variable. We can use getter to read the variable. - * - * @param varType the type of variable. - * @param varName variable name. - * @param funName "get + funName" will be the name of the getter. - * @warning The getter is a public virtual function, you should rewrite it first. - * The variables and methods declared after CC_PROPERTY_READONLY are all public. - * If you need protected or private, please declare. - */ -#define CC_PROPERTY_READONLY(varType, varName, funName)\ -protected: varType varName;\ -public: virtual varType get##funName(void) const; - -#define CC_PROPERTY_READONLY_PASS_BY_REF(varType, varName, funName)\ -protected: varType varName;\ -public: virtual const varType& get##funName(void) const; - -/** @def CC_PROPERTY - * It is used to declare a protected variable. - * We can use getter to read the variable, and use the setter to change the variable. - * - * @param varType The type of variable. - * @param varName Variable name. - * @param funName "get + funName" will be the name of the getter. - * "set + funName" will be the name of the setter. - * @warning The getter and setter are public virtual functions, you should rewrite them first. - * The variables and methods declared after CC_PROPERTY are all public. - * If you need protected or private, please declare. - */ -#define CC_PROPERTY(varType, varName, funName)\ -protected: varType varName;\ -public: virtual varType get##funName(void) const;\ -public: virtual void set##funName(varType var); - -#define CC_PROPERTY_PASS_BY_REF(varType, varName, funName)\ -protected: varType varName;\ -public: virtual const varType& get##funName(void) const;\ -public: virtual void set##funName(const varType& var); - -/** @def CC_SYNTHESIZE_READONLY - * It is used to declare a protected variable. We can use getter to read the variable. - * - * @param varType The type of variable. - * @param varName Variable name. - * @param funName "get + funName" will be the name of the getter. - * @warning The getter is a public inline function. - * The variables and methods declared after CC_SYNTHESIZE_READONLY are all public. - * If you need protected or private, please declare. - */ -#define CC_SYNTHESIZE_READONLY(varType, varName, funName)\ -protected: varType varName;\ -public: virtual varType get##funName(void) const { return varName; } - -#define CC_SYNTHESIZE_READONLY_PASS_BY_REF(varType, varName, funName)\ -protected: varType varName;\ -public: virtual const varType& get##funName(void) const { return varName; } - -/** @def CC_SYNTHESIZE - * It is used to declare a protected variable. - * We can use getter to read the variable, and use the setter to change the variable. - * - * @param varType The type of variable. - * @param varName Variable name. - * @param funName "get + funName" will be the name of the getter. - * "set + funName" will be the name of the setter. - * @warning The getter and setter are public inline functions. - * The variables and methods declared after CC_SYNTHESIZE are all public. - * If you need protected or private, please declare. - */ -#define CC_SYNTHESIZE(varType, varName, funName)\ -protected: varType varName;\ -public: virtual varType get##funName(void) const { return varName; }\ -public: virtual void set##funName(varType var){ varName = var; } - -#define CC_SYNTHESIZE_PASS_BY_REF(varType, varName, funName)\ -protected: varType varName;\ -public: virtual const varType& get##funName(void) const { return varName; }\ -public: virtual void set##funName(const varType& var){ varName = var; } - -#define CC_SYNTHESIZE_RETAIN(varType, varName, funName) \ -private: varType varName; \ -public: virtual varType get##funName(void) const { return varName; } \ -public: virtual void set##funName(varType var) \ -{ \ - if (varName != var) \ - { \ - CC_SAFE_RETAIN(var); \ - CC_SAFE_RELEASE(varName); \ - varName = var; \ - } \ -} - -#define CC_SAFE_DELETE(p) do { delete (p); (p) = nullptr; } while(0) -#define CC_SAFE_DELETE_ARRAY(p) do { if(p) { delete[] (p); (p) = nullptr; } } while(0) -#define CC_SAFE_FREE(p) do { if(p) { free(p); (p) = nullptr; } } while(0) -#define CC_SAFE_RELEASE(p) do { if(p) { (p)->release(); } } while(0) -#define CC_SAFE_RELEASE_NULL(p) do { if(p) { (p)->release(); (p) = nullptr; } } while(0) -#define CC_SAFE_RETAIN(p) do { if(p) { (p)->retain(); } } while(0) -#define CC_BREAK_IF(cond) if(cond) break - -#define __CCLOGWITHFUNCTION(s, ...) \ - cocos2d::log("%s : %s",__FUNCTION__, cocos2d::StringUtils::format(s, ##__VA_ARGS__).c_str()) - -/// @name Cocos2d debug -/// @{ -#if !defined(COCOS2D_DEBUG) || COCOS2D_DEBUG == 0 -#define CCLOG(...) do {} while (0) -#define CCLOGINFO(...) do {} while (0) -#define CCLOGERROR(...) do {} while (0) -#define CCLOGWARN(...) do {} while (0) - -#elif COCOS2D_DEBUG == 1 - -#if (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID) -#define COCOS_LOG_TAG "cocos2d-x" -#define CCLOG(...) __android_log_print(ANDROID_LOG_DEBUG, COCOS_LOG_TAG, __VA_ARGS__) -#define CCLOGINFO(format,...) do {} while (0) -#define CCLOGWARN(...) __android_log_print(ANDROID_LOG_WARN, COCOS_LOG_TAG, __VA_ARGS__) -#define CCLOGERROR(...) __android_log_print(ANDROID_LOG_ERROR, COCOS_LOG_TAG, __VA_ARGS__) -#else -#define CCLOG(format, ...) cocos2d::log(format, ##__VA_ARGS__) -#define CCLOGERROR(format,...) cocos2d::log(format, ##__VA_ARGS__) -#define CCLOGINFO(format,...) do {} while (0) -#define CCLOGWARN(...) __CCLOGWITHFUNCTION(__VA_ARGS__) -#endif - - -#elif COCOS2D_DEBUG > 1 -#define CCLOG(format, ...) cocos2d::log(format, ##__VA_ARGS__) -#define CCLOGERROR(format,...) cocos2d::log(format, ##__VA_ARGS__) -#define CCLOGINFO(format,...) cocos2d::log(format, ##__VA_ARGS__) -#define CCLOGWARN(...) __CCLOGWITHFUNCTION(__VA_ARGS__) -#endif // COCOS2D_DEBUG - -/** Lua engine debug */ -#if !defined(COCOS2D_DEBUG) || COCOS2D_DEBUG == 0 || CC_LUA_ENGINE_DEBUG == 0 -#define LUALOG(...) -#else -#define LUALOG(format, ...) cocos2d::log(format, ##__VA_ARGS__) -#endif // Lua engine debug - -// end of debug group -/// @} - -/** @def CC_DISALLOW_COPY_AND_ASSIGN(TypeName) - * A macro to disallow the copy constructor and operator= functions. - * This should be used in the private: declarations for a class - */ -#if defined(__GNUC__) && ((__GNUC__ >= 5) || ((__GNUG__ == 4) && (__GNUC_MINOR__ >= 4))) \ - || (defined(__clang__) && (__clang_major__ >= 3)) || (_MSC_VER >= 1800) -#define CC_DISALLOW_COPY_AND_ASSIGN(TypeName) \ - TypeName(const TypeName &) = delete; \ - TypeName &operator =(const TypeName &) = delete; -#else -#define CC_DISALLOW_COPY_AND_ASSIGN(TypeName) \ - TypeName(const TypeName &); \ - TypeName &operator =(const TypeName &); -#endif - -/** @def CC_DISALLOW_IMPLICIT_CONSTRUCTORS(TypeName) - * A macro to disallow all the implicit constructors, namely the - * default constructor, copy constructor and operator= functions. - * - * This should be used in the private: declarations for a class - * that wants to prevent anyone from instantiating it. This is - * especially useful for classes containing only static methods. - */ -#define CC_DISALLOW_IMPLICIT_CONSTRUCTORS(TypeName) \ - TypeName(); \ - CC_DISALLOW_COPY_AND_ASSIGN(TypeName) - -/** @def CC_DEPRECATED_ATTRIBUTE - * Only certain compilers support __attribute__((deprecated)). - */ -#if defined(__GNUC__) && ((__GNUC__ >= 4) || ((__GNUC__ == 3) && (__GNUC_MINOR__ >= 1))) - #define CC_DEPRECATED_ATTRIBUTE __attribute__((deprecated)) -#elif _MSC_VER >= 1400 //vs 2005 or higher - #define CC_DEPRECATED_ATTRIBUTE __declspec(deprecated) -#else - #define CC_DEPRECATED_ATTRIBUTE -#endif - -/** @def CC_DEPRECATED(...) - * Macro to mark things deprecated as of a particular version - * can be used with arbitrary parameters which are thrown away. - * e.g. CC_DEPRECATED(4.0) or CC_DEPRECATED(4.0, "not going to need this anymore") etc. - */ -#define CC_DEPRECATED(...) CC_DEPRECATED_ATTRIBUTE - -/** @def CC_FORMAT_PRINTF(formatPos, argPos) - * Only certain compiler support __attribute__((format)) - * - * @param formatPos 1-based position of format string argument. - * @param argPos 1-based position of first format-dependent argument. - */ -#if defined(__GNUC__) && (__GNUC__ >= 4) -#define CC_FORMAT_PRINTF(formatPos, argPos) __attribute__((__format__(printf, formatPos, argPos))) -#elif defined(__has_attribute) - #if __has_attribute(format) - #define CC_FORMAT_PRINTF(formatPos, argPos) __attribute__((__format__(printf, formatPos, argPos))) - #endif // __has_attribute(format) -#else -#define CC_FORMAT_PRINTF(formatPos, argPos) -#endif - -#if defined(_MSC_VER) -#define CC_FORMAT_PRINTF_SIZE_T "%08lX" -#else -#define CC_FORMAT_PRINTF_SIZE_T "%08zX" -#endif - -#ifdef __GNUC__ -#define CC_UNUSED __attribute__ ((unused)) -#else -#define CC_UNUSED -#endif - -/** @def CC_REQUIRES_NULL_TERMINATION - * - */ -#if !defined(CC_REQUIRES_NULL_TERMINATION) - #if defined(__APPLE_CC__) && (__APPLE_CC__ >= 5549) - #define CC_REQUIRES_NULL_TERMINATION __attribute__((sentinel(0,1))) - #elif defined(__GNUC__) - #define CC_REQUIRES_NULL_TERMINATION __attribute__((sentinel)) - #else - #define CC_REQUIRES_NULL_TERMINATION - #endif -#endif - -#endif // __CC_PLATFORM_MACROS_H__ diff --git a/native/cocos/platform/CCSAXParser.h b/native/cocos/platform/CCSAXParser.h index 5f92b6e78a..8a443c1e96 100644 --- a/native/cocos/platform/CCSAXParser.h +++ b/native/cocos/platform/CCSAXParser.h @@ -28,7 +28,7 @@ /// @cond DO_NOT_SHOW #include "platform/CCPlatformConfig.h" -#include "platform/CCPlatformMacros.h" +#include "base/ccMacros.h" #include NS_CC_BEGIN diff --git a/native/cocos/platform/CCStdC.h b/native/cocos/platform/CCStdC.h index 076dd3360d..974010d814 100644 --- a/native/cocos/platform/CCStdC.h +++ b/native/cocos/platform/CCStdC.h @@ -28,15 +28,56 @@ THE SOFTWARE. #include "platform/CCPlatformConfig.h" #if CC_TARGET_PLATFORM == CC_PLATFORM_WIN32 -#include "platform/win32/CCStdC-win32.h" + + #define WIN32_LEAN_AND_MEAN + #include + + #if _MSC_VER < 1800 + #if !defined(isnan) + #define isnan _isnan + #endif + #endif + + #include + #include + #include + #include + #include + #include + + #if _MSC_VER >= 1600 + #include + #else + #include "platform/win32/compat/stdint.h" + #endif + + // Conflicted with ParticleSystem::PositionType::RELATIVE, so we need to undef it. + #ifdef RELATIVE + #undef RELATIVE + #endif + + // Conflicted with CCBReader::SizeType::RELATIVE and CCBReader::ScaleType::RELATIVE, so we need to undef it. + #ifdef ABSOLUTE + #undef ABSOLUTE + #endif + + // Conflicted with HttpRequest::Type::DELETE, so we need to undef it. + #ifdef DELETE + #undef DELETE + #endif + + #undef min + #undef max #else -#include -#include -#include -#include -#include -#include -#include -#include -#include + + #include + #include + #include + #include + #include + #include + #include + #include + #include + #endif // CC_TARGET_PLATFORM == CC_PLATFORM_WIN32 diff --git a/native/cocos/platform/android/CCFileUtils-android.h b/native/cocos/platform/android/CCFileUtils-android.h index 0d9a3c0acf..d50bb11593 100644 --- a/native/cocos/platform/android/CCFileUtils-android.h +++ b/native/cocos/platform/android/CCFileUtils-android.h @@ -30,7 +30,7 @@ Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd. #if CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID #include "platform/CCFileUtils.h" -#include "platform/CCPlatformMacros.h" +#include "base/ccMacros.h" #include "base/ccTypes.h" #include #include diff --git a/native/cocos/platform/android/jni/JniHelper.h b/native/cocos/platform/android/jni/JniHelper.h index 5460be3e41..f5bb493886 100644 --- a/native/cocos/platform/android/jni/JniHelper.h +++ b/native/cocos/platform/android/jni/JniHelper.h @@ -31,7 +31,7 @@ THE SOFTWARE. #include #include #include -#include "platform/CCPlatformMacros.h" +#include "base/ccMacros.h" #include "math/Vec3.h" NS_CC_BEGIN diff --git a/native/cocos/platform/apple/CCFileUtils-apple.h b/native/cocos/platform/apple/CCFileUtils-apple.h index 93bd28ea3c..8e9da63b4e 100644 --- a/native/cocos/platform/apple/CCFileUtils-apple.h +++ b/native/cocos/platform/apple/CCFileUtils-apple.h @@ -32,7 +32,7 @@ #include #include "platform/CCFileUtils.h" -#include "platform/CCPlatformMacros.h" +#include "base/ccMacros.h" #include "base/ccTypes.h" NS_CC_BEGIN diff --git a/native/cocos/platform/apple/CCLock-apple.h b/native/cocos/platform/apple/CCLock-apple.h index f3f07d11fd..979eadb562 100644 --- a/native/cocos/platform/apple/CCLock-apple.h +++ b/native/cocos/platform/apple/CCLock-apple.h @@ -27,7 +27,7 @@ THE SOFTWARE. #ifndef __PLATFORM_IPHONE_PLATFORM_CCLOCK_H__ #define __PLATFORM_IPHONE_PLATFORM_CCLOCK_H__ -#include "platform/CCPlatformMacros.h" +#include "base/ccMacros.h" NS_CC_BEGIN diff --git a/native/cocos/platform/desktop/CCGLView-desktop.cpp b/native/cocos/platform/desktop/CCGLView-desktop.cpp index d82293de39..cf5aa26d26 100644 --- a/native/cocos/platform/desktop/CCGLView-desktop.cpp +++ b/native/cocos/platform/desktop/CCGLView-desktop.cpp @@ -30,7 +30,7 @@ THE SOFTWARE. #include #include "scripting/js-bindings/event/EventDispatcher.h" -#include "ccMacros.h" +#include "base/ccUtils.h" NS_CC_BEGIN diff --git a/native/cocos/platform/desktop/CCGLView-desktop.h b/native/cocos/platform/desktop/CCGLView-desktop.h index 0b317f412e..ea785608fa 100644 --- a/native/cocos/platform/desktop/CCGLView-desktop.h +++ b/native/cocos/platform/desktop/CCGLView-desktop.h @@ -26,20 +26,13 @@ THE SOFTWARE. #pragma once +#include "platform/CCGL.h" #include "glfw3/glfw3.h" #include "glfw3/glfw3native.h" -#include "platform/CCPlatformMacros.h" +#include "base/ccMacros.h" #include "platform/CCApplication.h" -#ifndef GLFW_EXPOSE_NATIVE_WIN32 -#define GLFW_EXPOSE_NATIVE_WIN32 -#endif - -#ifndef GLFW_EXPOSE_NATIVE_WGL -#define GLFW_EXPOSE_NATIVE_WGL -#endif - NS_CC_BEGIN class CC_DLL GLView final diff --git a/native/cocos/platform/win32/CCApplication-win32.cpp b/native/cocos/platform/win32/CCApplication-win32.cpp index 36689d31d0..4b6ddfae1f 100644 --- a/native/cocos/platform/win32/CCApplication-win32.cpp +++ b/native/cocos/platform/win32/CCApplication-win32.cpp @@ -23,45 +23,105 @@ 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 "platform/CCPlatformConfig.h" -#if CC_TARGET_PLATFORM == CC_PLATFORM_WIN32 - #include "platform/CCApplication.h" -#include "base/CCDirector.h" +#include "platform/CCStdC.h" // need it to include Windows.h #include -#include "platform/CCFileUtils.h" #include -#include -/** -@brief This function change the PVRFrame show/hide setting in register. -@param bEnable If true show the PVRFrame window, otherwise hide. -*/ -static void PVRFrameEnableControlWindow(bool bEnable); +#include +#include "platform/CCFileUtils.h" +#include "platform/desktop/CCGLView-desktop.h" +#include "renderer/gfx/DeviceGraphics.h" +#include "scripting/js-bindings/jswrapper/v8/ScriptEngine.hpp" +#include "scripting/js-bindings/event/EventDispatcher.h" + +#define CAST_VIEW(view) ((GLView*)view) + +namespace +{ + /** + @brief This function changes the PVRFrame show/hide setting in register. + @param bEnable If true show the PVRFrame window, otherwise hide. + */ + void PVRFrameEnableControlWindow(bool bEnable) + { + HKEY hKey = 0; + + // Open PVRFrame control key, if not exist create it. + if(ERROR_SUCCESS != RegCreateKeyExW(HKEY_CURRENT_USER, + L"Software\\Imagination Technologies\\PVRVFRame\\STARTUP\\", + 0, + 0, + REG_OPTION_NON_VOLATILE, + KEY_ALL_ACCESS, + 0, + &hKey, + nullptr)) + { + return; + } + + const WCHAR* wszValue = L"hide_gui"; + const WCHAR* wszNewData = (bEnable) ? L"NO" : L"YES"; + WCHAR wszOldData[256] = {0}; + DWORD dwSize = sizeof(wszOldData); + LSTATUS status = RegQueryValueExW(hKey, wszValue, 0, nullptr, (LPBYTE)wszOldData, &dwSize); + if (ERROR_FILE_NOT_FOUND == status // the key not exist + || (ERROR_SUCCESS == status // or the hide_gui value is exist + && 0 != wcscmp(wszNewData, wszOldData))) // but new data and old data not equal + { + dwSize = sizeof(WCHAR) * (wcslen(wszNewData) + 1); + RegSetValueEx(hKey, wszValue, 0, REG_SZ, (const BYTE *)wszNewData, dwSize); + } + + RegCloseKey(hKey); + } + + int g_width = 0; + int g_height = 0; + bool setCanvasCallback(se::Object* global) + { + se::ScriptEngine* se = se::ScriptEngine::getInstance(); + char commandBuf[200] = {0}; + sprintf(commandBuf, "var window = window || this; window.canvas = { width: %d, height: %d };", + g_width, + g_height); + se->evalString(commandBuf); + + return true; + } +} NS_CC_BEGIN -// sharedApplication pointer -Application * Application::sm_pSharedApplication = nullptr; - -Application::Application() -: _instance(nullptr) -, _accelTable(nullptr) +Application::Application(const std::string& name) { - _instance = GetModuleHandle(nullptr); - _animationInterval.QuadPart = 0; - CC_ASSERT(! sm_pSharedApplication); - sm_pSharedApplication = this; + createView(name); + + renderer::DeviceGraphics::getInstance(); + se::ScriptEngine::getInstance(); } Application::~Application() { - CC_ASSERT(this == sm_pSharedApplication); - sm_pSharedApplication = nullptr; + // TODO: destroy DeviceGraphics + + se::ScriptEngine::destroyInstance(); + + delete CAST_VIEW(_view); + _view = nullptr; } -int Application::run() +void Application::start() { + se::ScriptEngine* se = se::ScriptEngine::getInstance(); + se->addRegisterCallback(setCanvasCallback); + + if(!applicationDidFinishLaunching()) + return; + + if (!_view) + return; + PVRFrameEnableControlWindow(false); /////////////////////////////////////////////////////////////////////////// @@ -82,35 +142,24 @@ int Application::run() QueryPerformanceCounter(&nLast); - initGLContextAttrs(); - - // Initialize instance and cocos2d. - if (!applicationDidFinishLaunching()) - { - return 1; - } - - auto director = Director::getInstance(); - auto glview = director->getOpenGLView(); - - // Retain glview to avoid glview being released in the while loop - glview->retain(); - LONGLONG interval = 0LL; LONG waitMS = 0L; LARGE_INTEGER freq; QueryPerformanceFrequency(&freq); + + while (!CAST_VIEW(_view)->windowShouldClose()) + { - while (!glview->windowShouldClose()) - { QueryPerformanceCounter(&nNow); interval = nNow.QuadPart - nLast.QuadPart; - if (interval >= _animationInterval.QuadPart) + if (interval >= _animationInterval) { nLast.QuadPart = nNow.QuadPart; - director->mainLoop(); - glview->pollEvents(); + + CAST_VIEW(_view)->pollEvents(); + EventDispatcher::dispatchTickEvent(); + CAST_VIEW(_view)->swapBuffers(); } else { @@ -119,57 +168,24 @@ int Application::run() // Sleep(3) may make a sleep of 2ms or 4ms. Therefore, we subtract 1ms here to make Sleep time shorter. // If 'waitMS' is equal or less than 1ms, don't sleep and run into next loop to // boost CPU to next frame accurately. - waitMS = (_animationInterval.QuadPart - interval) * 1000LL / freq.QuadPart - 1L; + waitMS = (_animationInterval - interval) * 1000LL / freq.QuadPart - 1L; if (waitMS > 1L) Sleep(waitMS); - } + } } - // Director should still do a cleanup if the window was closed manually. - if (glview->isOpenGLReady()) - { - director->end(); - director->mainLoop(); - director = nullptr; - } - glview->release(); - - /////////////////////////////////////////////////////////////////////////// - /////////////// restoring timer resolution - /////////////////////////////////////////////////////////////////////////// if (wTimerRes != 0) - { timeEndPeriod(wTimerRes); - } - return 0; } void Application::setAnimationInterval(float interval) { LARGE_INTEGER nFreq; QueryPerformanceFrequency(&nFreq); - _animationInterval.QuadPart = (LONGLONG)(interval * nFreq.QuadPart); + _animationInterval = (LONGLONG)(interval * nFreq.QuadPart); } -////////////////////////////////////////////////////////////////////////// -// static member function -////////////////////////////////////////////////////////////////////////// -Application* Application::getInstance() -{ - CC_ASSERT(sm_pSharedApplication); - return sm_pSharedApplication; -} - -void Application::destroyInstance() -{ - if (sm_pSharedApplication) { - delete sm_pSharedApplication; - } - - sm_pSharedApplication = nullptr; -} - -LanguageType Application::getCurrentLanguage() +Application::LanguageType Application::getCurrentLanguage() const { LanguageType ret = LanguageType::ENGLISH; @@ -240,7 +256,7 @@ LanguageType Application::getCurrentLanguage() return ret; } -const char * Application::getCurrentLanguageCode() +std::string Application::getCurrentLanguageCode() const { LANGID lid = GetUserDefaultUILanguage(); const LCID locale_id = MAKELCID(lid, SORT_DEFAULT); @@ -250,50 +266,9 @@ const char * Application::getCurrentLanguageCode() return code; } -Application::Platform Application::getTargetPlatform() +Application::Platform Application::getPlatform() const { - return Platform::OS_WINDOWS; -} - -std::string Application::getVersion() -{ - char verString[256] = { 0 }; - TCHAR szVersionFile[MAX_PATH]; - GetModuleFileName(NULL, szVersionFile, MAX_PATH); - DWORD verHandle = NULL; - UINT size = 0; - LPBYTE lpBuffer = NULL; - DWORD verSize = GetFileVersionInfoSize(szVersionFile, &verHandle); - - if (verSize != NULL) - { - LPSTR verData = new char[verSize]; - - if (GetFileVersionInfo(szVersionFile, verHandle, verSize, verData)) - { - if (VerQueryValue(verData, L"\\", (VOID FAR* FAR*)&lpBuffer, &size)) - { - if (size) - { - VS_FIXEDFILEINFO *verInfo = (VS_FIXEDFILEINFO *)lpBuffer; - if (verInfo->dwSignature == 0xfeef04bd) - { - - // Doesn't matter if you are on 32 bit or 64 bit, - // DWORD is always 32 bits, so first two revision numbers - // come from dwFileVersionMS, last two come from dwFileVersionLS - sprintf(verString, "%d.%d.%d.%d", (verInfo->dwFileVersionMS >> 16) & 0xffff, - (verInfo->dwFileVersionMS >> 0) & 0xffff, - (verInfo->dwFileVersionLS >> 16) & 0xffff, - (verInfo->dwFileVersionLS >> 0) & 0xffff - ); - } - } - } - } - delete[] verData; - } - return verString; + return Platform::WINDOWS; } bool Application::openURL(const std::string &url) @@ -305,49 +280,58 @@ bool Application::openURL(const std::string &url) return (size_t)r>32; } -void Application::setStartupScriptFilename(const std::string& startupScriptFile) +bool Application::applicationDidFinishLaunching() { - _startupScriptFilename = startupScriptFile; - std::replace(_startupScriptFilename.begin(), _startupScriptFilename.end(), '\\', '/'); + return true; +} + +void Application::applicationDidEnterBackground() +{ +} + +void Application::applicationWillEnterForeground() +{ +} + +void Application::setMultitouch(bool) +{ +} + +void Application::onCreateView(int&x, int& y, int& width, int& height, PixelFormat& pixelformat, DepthFormat& depthFormat, int& multisamplingCount) +{ + x = 0; + y = 0; + width = 960; + height = 640; + + pixelformat = PixelFormat::RGBA8; + depthFormat = DepthFormat::DEPTH24_STENCIL8; + + multisamplingCount = 0; +} + +void Application::createView(const std::string& name) +{ + int x = 0; + int y = 0; + int width = 0; + int height = 0; + int multisamplingCount = 0; + PixelFormat pixelformat; + DepthFormat depthFormat; + + onCreateView(x, + y, + width, + height, + pixelformat, + depthFormat, + multisamplingCount); + + _view = new GLView(this, name, x, y, width, height, pixelformat, depthFormat, multisamplingCount); + + g_width = width; + g_height = height; } NS_CC_END - -////////////////////////////////////////////////////////////////////////// -// Local function -////////////////////////////////////////////////////////////////////////// -static void PVRFrameEnableControlWindow(bool bEnable) -{ - HKEY hKey = 0; - - // Open PVRFrame control key, if not exist create it. - if(ERROR_SUCCESS != RegCreateKeyExW(HKEY_CURRENT_USER, - L"Software\\Imagination Technologies\\PVRVFRame\\STARTUP\\", - 0, - 0, - REG_OPTION_NON_VOLATILE, - KEY_ALL_ACCESS, - 0, - &hKey, - nullptr)) - { - return; - } - - const WCHAR* wszValue = L"hide_gui"; - const WCHAR* wszNewData = (bEnable) ? L"NO" : L"YES"; - WCHAR wszOldData[256] = {0}; - DWORD dwSize = sizeof(wszOldData); - LSTATUS status = RegQueryValueExW(hKey, wszValue, 0, nullptr, (LPBYTE)wszOldData, &dwSize); - if (ERROR_FILE_NOT_FOUND == status // the key not exist - || (ERROR_SUCCESS == status // or the hide_gui value is exist - && 0 != wcscmp(wszNewData, wszOldData))) // but new data and old data not equal - { - dwSize = sizeof(WCHAR) * (wcslen(wszNewData) + 1); - RegSetValueEx(hKey, wszValue, 0, REG_SZ, (const BYTE *)wszNewData, dwSize); - } - - RegCloseKey(hKey); -} - -#endif // CC_TARGET_PLATFORM == CC_PLATFORM_WIN32 diff --git a/native/cocos/platform/win32/CCApplication-win32.h b/native/cocos/platform/win32/CCApplication-win32.h deleted file mode 100644 index 9a06328dd4..0000000000 --- a/native/cocos/platform/win32/CCApplication-win32.h +++ /dev/null @@ -1,111 +0,0 @@ -/**************************************************************************** -Copyright (c) 2010-2012 cocos2d-x.org -Copyright (c) 2013-2016 Chukong Technologies Inc. -Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd. - -http://www.cocos2d-x.org - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in -all copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -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. -****************************************************************************/ -#ifndef __CC_APPLICATION_WIN32_H__ -#define __CC_APPLICATION_WIN32_H__ - -#include "platform/CCPlatformConfig.h" -#if CC_TARGET_PLATFORM == CC_PLATFORM_WIN32 - -#include "platform/CCStdC.h" -#include "platform/CCCommon.h" -#include "platform/CCApplicationProtocol.h" -#include - -NS_CC_BEGIN - -class Rect; - -class CC_DLL Application : public ApplicationProtocol -{ -public: - /** - * @js ctor - */ - Application(); - /** - * @js NA - * @lua NA - */ - virtual ~Application(); - - /** - @brief Run the message loop. - */ - int run(); - - /** - @brief Get current application instance. - @return Current application instance pointer. - */ - static Application* getInstance(); - - static void destroyInstance(); - - /* override functions */ - virtual void setAnimationInterval(float interval); - virtual LanguageType getCurrentLanguage(); - - virtual const char * getCurrentLanguageCode(); - - /** - @brief Get target platform - */ - virtual Platform getTargetPlatform(); - - /** - @brief Get application version - */ - virtual std::string getVersion() override; - - /** - @brief Open url in default browser - @param String with url to open. - @return true if the resource located by the URL was successfully opened; otherwise false. - */ - virtual bool openURL(const std::string &url); - - void setStartupScriptFilename(const std::string& startupScriptFile); - - const std::string& getStartupScriptFilename(void) - { - return _startupScriptFilename; - } - -protected: - HINSTANCE _instance; - HACCEL _accelTable; - LARGE_INTEGER _animationInterval; - std::string _resourceRootPath; - std::string _startupScriptFilename; - - static Application * sm_pSharedApplication; -}; - -NS_CC_END - -#endif // CC_TARGET_PLATFORM == CC_PLATFORM_WIN32 - -#endif // __CC_APPLICATION_WIN32_H__ diff --git a/native/cocos/platform/win32/CCCommon-win32.cpp b/native/cocos/platform/win32/CCCommon-win32.cpp deleted file mode 100644 index c3b97c1bdd..0000000000 --- a/native/cocos/platform/win32/CCCommon-win32.cpp +++ /dev/null @@ -1,55 +0,0 @@ -/**************************************************************************** -Copyright (c) 2010-2012 cocos2d-x.org -Copyright (c) 2013-2016 Chukong Technologies Inc. -Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd. - -http://www.cocos2d-x.org - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in -all copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -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 "platform/CCPlatformConfig.h" -#if CC_TARGET_PLATFORM == CC_PLATFORM_WIN32 - -#include "platform/CCCommon.h" -#include "platform/CCStdC.h" -#include "platform/win32/CCUtils-win32.h" - -NS_CC_BEGIN - -#define MAX_LEN (cocos2d::kMaxLogLen + 1) - -void MessageBox(const char * pszMsg, const char * pszTitle) -{ - std::wstring wsMsg = cocos2d::StringUtf8ToWideChar(pszMsg); - std::wstring wsTitle = cocos2d::StringUtf8ToWideChar(pszTitle); - MessageBoxW(nullptr, wsMsg.c_str(), wsTitle.c_str(), MB_OK); -} - -void LuaLog(const char *pszMsg) -{ - OutputDebugStringW(cocos2d::StringUtf8ToWideChar(pszMsg).c_str()); - OutputDebugStringA("\n"); - - puts(UTF8StringToMultiByte(pszMsg).c_str()); -} - -NS_CC_END - -#endif // CC_TARGET_PLATFORM == CC_PLATFORM_WIN32 diff --git a/native/cocos/platform/win32/CCDevice-win32.cpp b/native/cocos/platform/win32/CCDevice-win32.cpp index 6727ee8d18..a174992223 100644 --- a/native/cocos/platform/win32/CCDevice-win32.cpp +++ b/native/cocos/platform/win32/CCDevice-win32.cpp @@ -447,8 +447,18 @@ public: return nRet; } - CC_SYNTHESIZE_READONLY(HDC, _DC, DC); - CC_SYNTHESIZE_READONLY(HBITMAP, _bmp, Bitmap); + HDC getDC() const + { + return _DC; + } + + HBITMAP getBitmap() const + { + return _bmp; + } + + HDC _DC; + HBITMAP _bmp; private: friend class Image; diff --git a/native/cocos/platform/win32/CCFileUtils-win32.cpp b/native/cocos/platform/win32/CCFileUtils-win32.cpp index cf3c0134cf..bddb2de85c 100644 --- a/native/cocos/platform/win32/CCFileUtils-win32.cpp +++ b/native/cocos/platform/win32/CCFileUtils-win32.cpp @@ -29,7 +29,6 @@ THE SOFTWARE. #include "platform/win32/CCFileUtils-win32.h" #include "platform/win32/CCUtils-win32.h" -#include "platform/CCCommon.h" #include #include #include diff --git a/native/cocos/platform/win32/CCFileUtils-win32.h b/native/cocos/platform/win32/CCFileUtils-win32.h index be1edd8108..a625d4421e 100644 --- a/native/cocos/platform/win32/CCFileUtils-win32.h +++ b/native/cocos/platform/win32/CCFileUtils-win32.h @@ -30,7 +30,7 @@ THE SOFTWARE. #if CC_TARGET_PLATFORM == CC_PLATFORM_WIN32 #include "platform/CCFileUtils.h" -#include "platform/CCPlatformMacros.h" +#include "base/ccMacros.h" #include "base/ccTypes.h" #include #include diff --git a/native/cocos/platform/win32/CCStdC-win32.h b/native/cocos/platform/win32/CCStdC-win32.h index 1561edc666..96bf8e402b 100644 --- a/native/cocos/platform/win32/CCStdC-win32.h +++ b/native/cocos/platform/win32/CCStdC-win32.h @@ -23,12 +23,7 @@ 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. ****************************************************************************/ - -#ifndef __CC_STD_C_H__ -#define __CC_STD_C_H__ - -#include "platform/CCPlatformConfig.h" -#if CC_TARGET_PLATFORM == CC_PLATFORM_WIN32 +#pragma once #include #ifndef __SSIZE_T @@ -36,9 +31,10 @@ THE SOFTWARE. typedef SSIZE_T ssize_t; #endif // __SSIZE_T -#include "platform/CCPlatformMacros.h" #include + + // for math.h on win32 platform #ifndef __MINGW32__ @@ -74,17 +70,6 @@ typedef SSIZE_T ssize_t; #define M_PI_2 1.57079632679 #endif // for MIN MAX and sys/time.h on win32 platform -#ifdef __MINGW32__ -#include -#endif // __MINGW32__ - -#ifndef MIN -#define MIN(x,y) (((x) > (y)) ? (y) : (x)) -#endif // MIN - -#ifndef MAX -#define MAX(x,y) (((x) < (y)) ? (y) : (x)) -#endif // MAX #if _MSC_VER >= 1600 || defined(__MINGW32__) @@ -93,56 +78,6 @@ typedef SSIZE_T ssize_t; #include "platform/win32/compat/stdint.h" #endif -#define _WINSOCKAPI_ -#ifndef NOMINMAX - #define NOMINMAX -#endif -// Structure timeval has define in winsock.h, include windows.h for it. -#include - -#ifndef __MINGW32__ - -#include - -NS_CC_BEGIN - -struct timezone -{ - int tz_minuteswest; - int tz_dsttime; -}; - -int CC_DLL gettimeofday(struct timeval *, struct timezone *); - -NS_CC_END - -#else - -#undef _WINSOCKAPI_ -#include - -// Conflicted with math.h isnan -#include -using std::isnan; - -inline int vsnprintf_s(char *buffer, size_t sizeOfBuffer, size_t count, - const char *format, va_list argptr) { - return vsnprintf(buffer, sizeOfBuffer, format, argptr); -} - -#ifndef __clang__ -inline errno_t strcpy_s(char *strDestination, size_t numberOfElements, - const char *strSource) { - strcpy(strDestination, strSource); - return 0; -} -#endif -#endif // __MINGW32__ - -// Conflicted with cocos2d::MessageBox, so we need to undef it. -#ifdef MessageBox -#undef MessageBox -#endif // Conflicted with ParticleSystem::PositionType::RELATIVE, so we need to undef it. #ifdef RELATIVE @@ -161,8 +96,3 @@ inline errno_t strcpy_s(char *strDestination, size_t numberOfElements, #undef min #undef max - -#endif // CC_TARGET_PLATFORM == CC_PLATFORM_WIN32 - -#endif // __CC_STD_C_H__ - diff --git a/native/cocos/platform/win32/CCUtils-win32.cpp b/native/cocos/platform/win32/CCUtils-win32.cpp index 87f75ca711..b54ae592cf 100644 --- a/native/cocos/platform/win32/CCUtils-win32.cpp +++ b/native/cocos/platform/win32/CCUtils-win32.cpp @@ -23,11 +23,10 @@ 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 "base/ccMacros.h" -#include "platform/CCPlatformMacros.h" #include "platform/win32/CCUtils-win32.h" - +#include "platform/CCStdC.h" #include +#include "base/ccMacros.h" NS_CC_BEGIN diff --git a/native/cocos/platform/win32/CCUtils-win32.h b/native/cocos/platform/win32/CCUtils-win32.h index 92795a1ad1..7682d7e7b8 100644 --- a/native/cocos/platform/win32/CCUtils-win32.h +++ b/native/cocos/platform/win32/CCUtils-win32.h @@ -27,7 +27,7 @@ THE SOFTWARE. #ifndef __CC_UTILS_WIN32_H__ #define __CC_UTILS_WIN32_H__ -#include "platform/CCPlatformMacros.h" +#include "base/ccMacros.h" #include diff --git a/native/cocos/renderer/gfx/State.h b/native/cocos/renderer/gfx/State.h index d51d20a89b..f5313a59b2 100644 --- a/native/cocos/renderer/gfx/State.h +++ b/native/cocos/renderer/gfx/State.h @@ -37,9 +37,7 @@ class Program; class Texture; struct State final -{ - // TODO: adjust memeber position to reduce size?? - +{ State(); State(const State&); State(State &&); diff --git a/native/cocos/renderer/renderer/Camera.h b/native/cocos/renderer/renderer/Camera.h index 32cbdc78c0..cd10fdf4ce 100644 --- a/native/cocos/renderer/renderer/Camera.h +++ b/native/cocos/renderer/renderer/Camera.h @@ -33,6 +33,14 @@ #include "../Types.h" #include "View.h" +#ifdef near +#undef near +#endif + +#ifdef far +#undef far +#endif + RENDERER_BEGIN class FrameBuffer; diff --git a/native/cocos/scripting/js-bindings/manual/jsb_conversions.hpp b/native/cocos/scripting/js-bindings/manual/jsb_conversions.hpp index 4f71b0ac54..ca06cfe089 100644 --- a/native/cocos/scripting/js-bindings/manual/jsb_conversions.hpp +++ b/native/cocos/scripting/js-bindings/manual/jsb_conversions.hpp @@ -6,9 +6,7 @@ #include "cocos2d.h" #include "gfx/GFX.h" #include "renderer/Renderer.h" -//#include "cocos/ui/CocosGUI.h" //#include "extensions/cocos-ext.h" -//#include "cocos/editor-support/spine/spine.h" //#include "Box2D/Box2D.h" #define SE_PRECONDITION2_VOID(condition, ...) \ diff --git a/native/cocos/storage/local-storage/LocalStorage-android.cpp b/native/cocos/storage/local-storage/LocalStorage-android.cpp index 680e76a735..670761c26a 100644 --- a/native/cocos/storage/local-storage/LocalStorage-android.cpp +++ b/native/cocos/storage/local-storage/LocalStorage-android.cpp @@ -31,7 +31,7 @@ */ #include "storage/local-storage/LocalStorage.h" -#include "platform/CCPlatformMacros.h" +#include "base/ccMacros.h" #if (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID) diff --git a/native/cocos/storage/local-storage/LocalStorage.cpp b/native/cocos/storage/local-storage/LocalStorage.cpp index 8a6501cbb2..a653b23395 100644 --- a/native/cocos/storage/local-storage/LocalStorage.cpp +++ b/native/cocos/storage/local-storage/LocalStorage.cpp @@ -30,7 +30,7 @@ */ #include "storage/local-storage/LocalStorage.h" -#include "platform/CCPlatformMacros.h" +#include "base/ccMacros.h" #if (CC_TARGET_PLATFORM != CC_PLATFORM_ANDROID) diff --git a/native/cocos/storage/local-storage/LocalStorage.h b/native/cocos/storage/local-storage/LocalStorage.h index c21c38dcc7..3da4652d0a 100644 --- a/native/cocos/storage/local-storage/LocalStorage.h +++ b/native/cocos/storage/local-storage/LocalStorage.h @@ -28,7 +28,7 @@ THE SOFTWARE. #define __JSB_LOCALSTORAGE_H #include -#include "platform/CCPlatformMacros.h" +#include "base/ccMacros.h" /** * @addtogroup storage diff --git a/native/templates/js-template-link/frameworks/runtime-src/Classes/AppDelegate.cpp b/native/templates/js-template-link/frameworks/runtime-src/Classes/AppDelegate.cpp index e4ad3a4c1c..b059befce0 100755 --- a/native/templates/js-template-link/frameworks/runtime-src/Classes/AppDelegate.cpp +++ b/native/templates/js-template-link/frameworks/runtime-src/Classes/AppDelegate.cpp @@ -24,8 +24,7 @@ ****************************************************************************/ #include "AppDelegate.h" - -#include "cocos2d.h" + #include "platform/CCFileUtils.h" #include "cocos/scripting/js-bindings/jswrapper/SeApi.h" #include "cocos/scripting/js-bindings/auto/jsb_gfx_auto.hpp" @@ -107,9 +106,6 @@ bool AppDelegate::applicationDidFinishLaunching() se::AutoHandleScope hs; - char commandBuf[200] = {0}; - sprintf(commandBuf, "window.canvas = { width: %d, height: %d };", 960, 640); - se->evalString(commandBuf); se->runScript("src/renderer-test/main-jsb.js"); se->addAfterCleanupHook([](){