axmol/cocos/base/CCConsole.cpp

1619 lines
46 KiB
C++
Raw Normal View History

2013-12-05 08:26:21 +08:00
/****************************************************************************
Copyright (c) 2013-2016 Chukong Technologies Inc.
Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd.
2013-12-05 08:26:21 +08:00
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.
****************************************************************************/
2014-04-27 01:35:57 +08:00
#include "base/CCConsole.h"
2013-12-04 10:46:54 +08:00
#include <thread>
2013-12-05 10:28:09 +08:00
#include <algorithm>
#include <functional>
#include <cctype>
#include <locale>
#include <sstream>
#include <stdio.h>
2014-02-13 10:40:57 +08:00
#include <stdlib.h>
#include <time.h>
#include <fcntl.h>
2013-12-05 16:09:38 +08:00
2014-01-04 14:40:22 +08:00
#if defined(_MSC_VER) || defined(__MINGW32__)
2013-12-05 16:09:38 +08:00
#include <io.h>
#include <WS2tcpip.h>
#include <Winsock2.h>
2015-02-07 04:39:50 +08:00
#if defined(__MINGW32__)
#include "platform/win32/inet_pton_mingw.h"
#endif
2013-12-05 16:09:38 +08:00
#define bzero(a, b) memset(a, 0, b);
#else
#include <netdb.h>
#include <unistd.h>
#include <arpa/inet.h>
2013-12-04 10:46:54 +08:00
#include <netinet/in.h>
#include <sys/socket.h>
#include <sys/un.h>
2014-04-10 18:31:28 +08:00
#include <sys/ioctl.h>
2013-12-05 16:09:38 +08:00
#endif
2014-04-30 08:37:36 +08:00
#include "base/CCDirector.h"
#include "base/CCScheduler.h"
#include "platform/CCPlatformConfig.h"
Squashed commit of the following: commit c16dcfaaea0922039aad05bce1f4efed18e04871 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Wed Apr 30 19:05:18 2014 -0700 more linux fixes commit 1553795976c9090a1b46deb53d12910fe0676008 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Wed Apr 30 19:04:04 2014 -0700 more linux fixes commit 1e43a8cabff33cbf25aa5eb5412f53a878222d83 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Wed Apr 30 19:02:07 2014 -0700 fixes linux isuses commit 723a445dd6411f91846da2b801248ad8298174f1 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Wed Apr 30 18:58:50 2014 -0700 more linux fixes commit 533c8025e794fc76cef02f396b3a93b3d7f4cfc8 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Wed Apr 30 18:57:33 2014 -0700 more linux fixes commit 4ba1e84959670bcbf044f18d1c0d4b3cb3be4090 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Wed Apr 30 18:53:43 2014 -0700 more linux fixes commit 1f8e011f306a47ed4134224e5e349929201f0539 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Wed Apr 30 18:49:28 2014 -0700 more linux fixes commit 3e2033100822ff6d532a1b4f012337491dc11920 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Wed Apr 30 18:47:43 2014 -0700 more linux fixes commit 2e708863c75fd032f1b2396dfdf1d31f7a62b713 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Wed Apr 30 18:46:00 2014 -0700 more linux fixes commit 861b5b92a6efd4de7b926c20d636ce9d749b293f Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Wed Apr 30 18:43:15 2014 -0700 more linux fixes commit 2a43365a0c1755e9b9cada53301be1a20adb31cf Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Wed Apr 30 18:36:06 2014 -0700 more fixes for linux commit 7d332bf911892f87c7824d2a5da7bf73ce7ec411 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Wed Apr 30 18:35:29 2014 -0700 more fixes for linux commit f1becc17d3316dfe3678c23c9dcedb7a447d9235 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Wed Apr 30 18:34:44 2014 -0700 more fixes for linux commit d2e5959bb0dde921dd5e73be1d8acc3b3f50e51d Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Wed Apr 30 18:33:45 2014 -0700 fixes for linux commit ad9b633c352107cf0e8b060a0e23d6e6a3f5e80f Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Wed Apr 30 18:16:48 2014 -0700 compiles on Windows commit 4425ee8e5de8f42a2d6050e4470109600dce8b5d Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Wed Apr 30 18:07:20 2014 -0700 fix builder
2014-05-01 10:09:13 +08:00
#include "base/CCConfiguration.h"
#include "2d/CCScene.h"
Squashed commit of the following: commit a794d107ad85667e3d754f0b6251fc864dfbf288 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Fri May 16 14:33:49 2014 -0700 Yeah... everything compiles on win32 and wp8 commit 4740be6e4a0d16f742c27996e7ab2c100adc76af Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Fri May 16 13:58:38 2014 -0700 CCIME moved to base and compiles on Android commit ff3e1bf1eb27a01019f4e1b56d1aebbe2d385f72 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Fri May 16 13:02:57 2014 -0700 compiles Ok for Windows Phone 8 commit 8160a4eb2ecdc61b5bd1cf56b90d2da6f11e3ebd Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Fri May 16 12:25:31 2014 -0700 fixes for Windows Phone 8 commit 418197649efc93032aee0adc205e502101cdb53d Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Fri May 16 11:15:13 2014 -0700 Compiles on Win32 commit 08813ed7cf8ac1079ffadeb1ce78ea9e833e1a33 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Fri May 16 10:08:31 2014 -0700 Compiles on linux! commit 118896521e5b335a5257090b6863f1fb2a2002fe Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Fri May 16 09:30:42 2014 -0700 moves cocos/2d/platform -> cocos/platform commit 4fe9319d7717b0c1bccb2db0156eeb86255a89e0 Merge: bd68ec2 511295e Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Fri May 16 08:24:41 2014 -0700 Merge remote-tracking branch 'cocos2d/v3' into files commit bd68ec2f0e3a826d8b2f4b60564ba65ce766bc56 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Thu May 15 19:36:23 2014 -0700 files in the correct directory
2014-05-17 05:36:00 +08:00
#include "platform/CCFileUtils.h"
#include "renderer/CCTextureCache.h"
2014-04-30 08:37:36 +08:00
#include "base/base64.h"
2014-07-14 20:45:24 +08:00
#include "base/ccUtils.h"
2013-12-05 16:09:38 +08:00
NS_CC_BEGIN
2014-06-10 16:29:06 +08:00
extern const char* cocos2dVersion(void);
2016-04-21 11:31:20 +08:00
#define PROMPT "> "
#define DEFAULT_COMMAND_SEPARATOR '|'
2016-04-21 11:31:20 +08:00
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();
// use non-block version of SendMessage
PostMessage(hwnd,
WM_COPYDATA,
(WPARAM)(HWND)hwnd,
(LPARAM)(LPVOID)&myCDS);
2016-04-21 11:31:20 +08:00
}
}
#endif
}
void log(const char * format, ...)
{
int bufferSize = MAX_LOG_LENGTH;
char* buf = nullptr;
int nret = 0;
va_list args;
do
2016-04-21 11:31:20 +08:00
{
buf = new (std::nothrow) char[bufferSize];
if (buf == nullptr)
return;
/*
pitfall: The behavior of vsnprintf between VS2013 and VS2015/2017 is different
VS2013 or Unix-Like System will return -1 when buffer not enough, but VS2015/2017 will return the actural needed length for buffer at this station
The _vsnprintf behavior is compatible API which always return -1 when buffer isn't enough at VS2013/2015/2017
Yes, The vsnprintf is more efficient implemented by MSVC 19.0 or later, AND it's also standard-compliant, see reference: http://www.cplusplus.com/reference/cstdio/vsnprintf/
*/
va_start(args, format);
nret = vsnprintf(buf, bufferSize - 3, format, args);
va_end(args);
if (nret >= 0)
{ // VS2015/2017
if (nret <= bufferSize - 3)
{// success, so don't need to realloc
break;
}
else
{
bufferSize = nret + 3;
delete[] buf;
2016-04-21 11:31:20 +08:00
}
}
else // < 0
{ // VS2013 or Unix-like System(GCC)
bufferSize *= 2;
delete[] buf;
}
} while (true);
buf[nret] = '\n';
buf[++nret] = '\0';
2016-04-21 11:31:20 +08:00
#if CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID
__android_log_print(ANDROID_LOG_DEBUG, "cocos2d-x debug info", "%s", buf);
metal support for cocos2d-x (#19305) * remove deprecated files * remove some deprecated codes * remove more deprecated codes * remove ui deprecated codes * remove more deprecated codes * remove deprecated codes in ccmenuitem * remove more deprecated codes in ui * remove more deprecated codes in ui * remove more deprecated codes in ui * remove more deprecated codes * remove more deprecated codes * remove more deprecated codes * remove vr related codes and ignore some modules * remove allocator * remove some config * 【Feature】add back-end project file * [Feature] add back-end file * add pipeline descriptor and shader cache * [Feature] support sprite for backend * [Feature] remove unneeded code * [Feature] according to es2.0 spec, you must use clamp-to-edge as texture wrap mode, and no mipmapping for non-power-of-two texture * [Feature] set texture wrap mode to clamp-to-edge, and no mipmapping for non-power-of-two texture * [Feature] remove macro define to .cpp file * [Feature] add log info * [Feature] add PipelineDescriptor for TriangleCommand * [Feature] add PipelineDescriptor object as member of TriangleCommand * [Feature] add getPipelineDescriptor method * add renderbackend * complete pipeline descriptor * [Feature] add viewport in RenderCommand * set viewport when rendrering * [Feature] occur error when using RendererBackend, to be fixed. * a workaround to fix black screen on macOS 10.14 (#19090) * add rendererbackend init function * fix typo * [Feature] modify testFile * [BugFix] modify shader path * [Feature] set default viewport * fix projection * [Feature] modify log info * [BugFix] change viewport data type to int * [BugFix] add BindGroup to PipelienDescriptor * [BugFix] change a_position to vec3 in sprite.vert * [BugFix] set vertexLayout according to V3F_C4B_T2F structure * [Feature] revert a_position to vec4 * [Feature] renderer should not use gl codes directly * [Feature] it's better not use default value parameter * fix depth test setting * rendererbackend -> renderer * clear color and depth at begin * add metal backend * metal support normalized attribute * simplify codes * update external * add render pass desctriptor in pipeline descriptor * fix warnings * fix crash and memeory leak * refactor Texture2D * put pipeline descriptor into render command * simplify codes * [Feature] update Sprite * fix crash when closing app * [Feature] update SpriteBatchNode and TextureAtlas * support render texture(not finish) * [Feature] remove unused code * make tests work on mac * fix download-deps path error * make tests work on iOS * [Feature] support ttf under normal label effect * refactor triangle command processing * let renderer handle more common commands * refactor backend * make render texture work * [Feature] refactor backend for GL * [Feature]Renaming to make it easy to understand * [Feature] change warp mode to CLAMP_TO_EDGE * fix ghost * simplify visit render queue logic * support progress timer without rial mode * support partcile system * Feature/update label (#149) * [BugFix] fix compile error * [Feature] support outline effect in ios * [Feature] add shader file * [BugFix] fix begin and end RenderPass * [Feature] update CustomCommand * [Feature] revert project.pbxproj * [Feature] simplify codes * [BugFix] pack AI88 to RGBA8888 only when outline enable * [Feature] support shadow effect in Label * [Feature] support BMFont * [Feature] support glow effect * [Feature] simplify shader files * LabelAtlas work * handle blend function correctly * support tile map * don't share buffer in metal * alloc buffer size as needed * support more tilemap * Merge branch 'minggo/metal-support' into feature/updateLabel * minggo/metal-support: support tile map handle blend function correctly LabelAtlas work Feature/update label (#149) support partcile system # Conflicts: # cocos/2d/CCLabel.cpp # cocos/2d/CCSprite.cpp # cocos/2d/CCSpriteBatchNode.cpp # cocos/renderer/CCQuadCommand.cpp # cocos/renderer/CCQuadCommand.h * render texture work without saving file * use global viewport * grid3d works * remove grabber * tiled3d works * [BugFix] fix label bug * [Feature] add updateSubData for buffer * [Feature] remove setVertexCount * support depth test * add callback command * [Feature] add UITest * [Feature] update UITest * [Feature] remove unneeded codes * fix custom command issue * fix layer color blend issue * [BugFix] fix iOS compile error * [Feature] remove unneeded codes * [Feature] fix updateVertexBuffer * layerradial works * add draw test back * fix batch issue * fix compiling error * [BugFix] support ETC1 * [BugFix] get the correct pipelineDescriptor * [BugFix] skip draw when backendTexture nullptr * clipping node support * [Feature] add shader files * fix stencil issue in metal * [Feature] update UILayoutTest * [BugFix] skip drawing when vertexCount is zero * refactor renderer * add set global z order for stencil manager commands * fix warnings caused by type * remove viewport in render command * [Feature] fix warnings caused by type * [BugFix] clear vertexCount and indexCount for CustomComand when needed * [Feature] update clear for CustomCommand * ios use metal * fix viewport issue * fix LayerColorGradient crash * [cmake] transport to android and windows (#160) * save point 1 * compile on windows * run on android * revert useless change * android set CC_ENABLE_CACHE_TEXTURE_DATA to 1 * add initGlew * fix android crash * add TODO new-renderer * review update * revert onGLFWWindowPosCallback * fix android compiling error * Impl progress radial (#162) * progresstimer add radial impl * default drawType to element * dec invoke times of createVertexBuffer (#163) * support depth/stencil format for gl backend * simplify progress timer codes * support motionstreak, effect is wrong * fix motionstreak issue * [Feature] update Scissor Test (#161) * [Feature] update Scissor Test * [Feature] update ScissorTest * [Feature] rename function * [Feature] get constant reference if needed * [Feature] show render status (#164) * improve performance * fix depth state * fill error that triangle vertex/index number bigger than buffer * fix compiline error in release mode * fix buffer conflict between CPU and GPU on iOS/macOS * Renderer refactor (#165) * use one vertes/index buffer with opengl * fix error on windows * custom command support index format config * CCLayer: compact vertex data structure * update comment * fix doc * support fast tilemap * pass index format instead * fix some wrong effect * fix render texture error * fix texture per-element size * fix texture format error * BlendFunc type refactor, GLenum -> backend::BlendFactor (#167) * BlendFunc use backend::BlendFactor as inner field * update comments * use int to replace GLenum * update xcode project fiel * rename to GLBlendConst * add ccConstants.h * update xcode project file * update copyright * remove primitive command * remove CCPrimitive.cpp/.h * remove deprecated files * remove unneeded files * remove multiple view support * remove multiple view support * remove the usage of frame buffer in camera * director don't use frame buffer * remove FrameBuffer * remove BatchCommand * add some api reference * add physics2d back * fix crash when close app on mac * improve render texture * fix rendertexture issue * fix rendertexture issue * simplify codes * CMake support for mac & ios (#169) * update cmake * fix compile error * update 3rd libs version * remove CCThread.h/.cpp * remove ccthread * use audio engine to implement simple audio engine * remove unneeded codes * remove deprecated codes * remove winrt macro * remove CC_USE_WIC * set partcile blend function in more elegant way * remove unneeded codes * remove unneeded codes * cmake works on windows * update project setting * improve performance * GLFloat -> float * sync v3 cmake improvements into metal-support (#172) * pick: modern cmake, compile definitions improvement (#19139) * modern cmake, use target_compile_definitions partly * simplify macro define, remove USE_* * modern cmake, macro define * add physics 2d macro define into ccConfig.h * remove USE_CHIPMUNK macro in build.gradle * remove CocosSelectModule.cmake * shrink useless define * simplify compile options config, re-add if necessary * update external for tmp CI test * un-quote target_compile_options value * add "-g" parameter only when debug mode * keep single build type when generator Xcode & VS projecy * update external for tmp CI tes * add static_cast<char>(-1), fix -Wc++11-narrowing * simplify win32 compile define * not modify code, only improve compile options # Conflicts: # .gitignore # cmake/Modules/CocosConfigDepend.cmake # cocos/CMakeLists.txt # external/config.json # tests/cpp-tests/CMakeLists.txt * modern cmake, improve cmake_compiler_flags (#19145) * cmake_compiler_flags * Fix typo * Fix typo2 * Remove chanages from Android.mk * correct lua template cmake build (#19149) * don't add -Wno-deprecated into jsb target * correct lua template cmake build * fix win32 lua template compile error * prevent cmake in-source-build friendly (#19151) * pick: Copy resources to "Resources/" on win32 like in linux configuration * add "/Z7" for cpp-tests on windows * [cmake] fix iOS xcode property setting failed (#19208) * fix iOS xcode property setting failed * use search_depend_libs_recursive at dlls collect * fix typo * [cmake] add find_host_library into iOS toolchain file (#19230) * pick: [lua android] use luajit & template cmake update (#19239) * increase cmake stability , remove tests/CMakeLists.txt (#19261) * cmake win32 Precompiled header (#19273) * Precompiled header * Fix * Precompiled header for cocos * Precompiled header jscocos2d * Fix for COCOS2D_DEBUG is always 1 on Android (#19291) Related #19289 * little build fix, tests cpp-tests works on mac * sync v3 build related codes into metal-support (#173) * strict initialization for std::array * remove proj.win32 project configs * modern cmake, cmake_cleanup_remove_unused_variables (#19146) * Switch travis CI to xenial (#19207) * Switch travis CI to xenial * Remove language: android * Set language: cpp * Fix java problem * Update sdkmanager * Fix sdkmanger * next sdkmanager fix * Remove xenial from android * revert to sdk-tools-{system}-3859397 * Remove linux cmake install * Update before-install.sh * Update .travis.yml * Simplify install-deps-linux.sh, tested on Ubuntu 16.04 (#19212) * Simplify install-deps-linux.sh * Cleanup * pick: install ninja * update cocos2d-console submodule * for metal-support alpha release, we only test cpp * add HelloCpp into project(Cocos2d-x) for tmp test * update extenal metal-support-4 * update uniform setting * [Feature] update BindGroup * [Feature] empty-test * [Feature] cpp-test * [Feature] fix GL compiler error * [Feature] fix GL crash * [Feature] empty-test * [Feature] cpp-tests * [feature] improve frameRate * [feature] fix opengl compile error * [feature] fix opengl compile error * [BugFix] fix compute maxLocation error * [Feature] update setting unifrom * [Feature] fix namespace * [Feature] remove unneeded code * [Bugfix] fix project file * [Feature] update review * [texture2d] impl texture format support (#175) * texture update * update * update texture * commit * compile on windows * ddd * rename * rename methods * no crash * save gl * save * save * rename * move out pixel format convert functions * metal crash * update * update android * support gles compressed texture format * support more compress format * add more conversion methods * ss * save * update conversion methods * add PVRTC format support * reformat * add marco linux * fix GL marcro * pvrtc supported only by ios 8.0+ * remove unused cmake * revert change * refactor Texture2D::initWithData * fix conversion log * refactor Texture2D::initWithData * remove some OpenGL constants for PVRTC * add todo * fix typo * AutoTest works on mac/iOS by disable part cases, sync v3 bug fix (#174) * review cpp-tests, and fix part issues on start auto test * sync png format fix: Node:Particle3D abnormal texture effects #19204 * fix cpp-tests SpritePolygon crash, wrong png format (#19170) * fix wrong png convert format from sRGB to Gray * erase plist index if all frames was erased * test_A8.png have I8 format, fix it * [CCSpriteCache] allow re-add plist & add testcase (#19175) * allow re-add plist & add testcase * remove comments/rename method/update testcase * fix isSpriteFramesWithFileLoaded & add testcase * remove used variable * remove unused variable * fix double free issues when js/lua-tests exit on iOS (#19236) * disable part cases, AutoTest works without crash on mac * update cocos2dx files json, to test cocos new next * fix spritecache plist parsing issue (#19269) * [linux] Fix FileUtils::getContents with folder (#19157) * fix FileUtils::getContents on linux/mac * use stat.st_mode * simplify * [CCFileUtils] win32 getFileSize (#19176) * win32 getFileSize * fix stat * [cpp test-Android]20:FileUtils/2 change title (#19197) * sync #19200 * sync #19231 * [android lua] improve performance of lua loader (#19234) * [lua] improve performance of lua loader * remove cache fix * Revert "fix spritecache plist parsing issue (#19269)" This reverts commit f3a85ece4307a7b90816c34489d1ed2c8fd11baf. * remove win32 project files ref in template.json * add metal framework lnk ref into cpp template * test on iOS, and disable part cases * alBufferData instead of alBufferDataStatic for small audio file on Apple (#19227) * changes AudioCache to use alBufferData instead of alBufferDataStatic (also makes test 19 faster to trigger openal bugs faster) The original problem: CrashIfClientProvidedBogusAudioBufferList https://github.com/cocos2d/cocos2d-x/issues/18948 is not happening anymore, but there's still a not very frequent issue that makes OpenAL crash with a call stack like this. AudioCache::readDataTask > alBufferData > CleanUpDeadBufferList It happes more frequently when the device is "cold", which means after half an hour of not using the device (locked). I could not find the actual source code for iOS OpenAL, so I used the macOS versions: https://opensource.apple.com/source/OpenAL/OpenAL-48.7/Source/OpenAL/oalImp.cpp.auto.html They seem to use CAGuard.h to make sure the dead buffer list has no threading issues. I'm worried because the CAGuard code I found has macos and win32 define but no iOS, so I'm not sure. I guess the iOS version is different and has the guard. I could not find a place in the code that's unprotected by the locks except the InitializeBufferMap() which should not be called more than once from cocos, and there's a workaround in AudioEngine-impl for it. I reduced the occurence of the CleanUpDeadBufferList crash by moving the guard in ~AudioCache to cover the alDeleteBuffers call. * remove hack method "setTimeout" on audio * AutoTest works on iOS * support set ios deployment target for root project * enable all texture2d cases, since Jiang have fixed * add CCTextureUtils to xcode project file (#176) * add leak cases for SpriteFrameCache (#177) * re-add SpriteFrameCache cases * update template file json * Update SpriteFrameCacheTest.cpp * fix compiling error
2019-01-18 15:08:25 +08:00
#elif CC_TARGET_PLATFORM == CC_PLATFORM_WIN32
int pos = 0;
int len = nret;
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);
2016-04-21 11:31:20 +08:00
#else
// Linux, Mac, iOS, etc
fprintf(stdout, "%s", buf);
fflush(stdout);
2016-04-21 11:31:20 +08:00
#endif
Director::getInstance()->getConsole()->log(buf);
delete[] buf;
2016-04-21 11:31:20 +08:00
}
// FIXME: Deprecated
// void CCLog(const char * format, ...);
2016-04-21 11:31:20 +08:00
//
// Utility code
//
std::string Console::Utility::_prompt(PROMPT);
2015-04-25 05:02:39 +08:00
//TODO: these general utils should be in a separate class
//
// Trimming functions were taken from: http://stackoverflow.com/a/217605
// Since c++17, some parts of the standard library were removed, include "ptr_fun".
// trim from start
2016-04-21 11:31:20 +08:00
std::string& Console::Utility::ltrim(std::string& s) {
s.erase(s.begin(), std::find_if(s.begin(), s.end(), [](int ch) {
return !std::isspace(ch);
}));
return s;
}
// trim from end
2016-04-21 11:31:20 +08:00
std::string& Console::Utility::rtrim(std::string& s) {
s.erase(std::find_if(s.rbegin(), s.rend(), [](int ch) {
return !std::isspace(ch);
}).base(), s.end());
return s;
}
// trim from both ends
2016-04-21 11:31:20 +08:00
std::string& Console::Utility::trim(std::string& s) {
return Console::Utility::ltrim(Console::Utility::rtrim(s));
}
2016-04-21 11:31:20 +08:00
std::vector<std::string>& Console::Utility::split(const std::string& s, char delim, std::vector<std::string>& elems) {
2014-02-14 14:54:26 +08:00
std::stringstream ss(s);
std::string item;
while (std::getline(ss, item, delim)) {
elems.push_back(item);
}
return elems;
}
2016-04-21 11:31:20 +08:00
std::vector<std::string> Console::Utility::split(const std::string& s, char delim) {
2014-02-14 14:54:26 +08:00
std::vector<std::string> elems;
2016-04-21 11:31:20 +08:00
Console::Utility::split(s, delim, elems);
2014-02-14 14:54:26 +08:00
return elems;
}
2016-04-21 11:31:20 +08:00
2014-02-25 11:04:59 +08:00
//isFloat taken from http://stackoverflow.com/questions/447206/c-isfloat-function
2016-05-17 12:17:56 +08:00
bool Console::Utility::isFloat(const std::string& myString) {
2014-02-25 11:04:59 +08:00
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
2016-04-21 11:31:20 +08:00
return iss.eof() && !iss.fail();
2014-02-25 11:04:59 +08:00
}
2016-04-21 11:31:20 +08:00
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<const char*>(buffer), length) == 0) {
fprintf(stderr,"bad parameter error: a buffer is the prompt string.\n");
return 0;
}
}
const char* buf = static_cast<const char*>(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'
2016-04-21 11:31:20 +08:00
ssize_t Console::Utility::mydprintf(int sock, const char *format, ...)
{
va_list args;
char buf[16386];
2016-04-21 11:31:20 +08:00
va_start(args, format);
vsnprintf(buf, sizeof(buf), format, args);
va_end(args);
2016-04-21 11:31:20 +08:00
return sendToConsole(sock, buf, strlen(buf));
}
2016-04-21 11:31:20 +08:00
void Console::Utility::sendPrompt(int fd)
2014-02-11 16:57:30 +08:00
{
2016-04-21 11:31:20 +08:00
const char* prompt = _prompt.c_str();
send(fd, prompt, strlen(prompt), 0);
2014-02-11 16:57:30 +08:00
}
2016-04-21 11:31:20 +08:00
void Console::Utility::setPrompt(const std::string &prompt)
{
2016-04-21 11:31:20 +08:00
_prompt = prompt;
}
2016-04-21 11:31:20 +08:00
const std::string& Console::Utility::getPrompt()
{
2016-04-21 11:31:20 +08:00
return _prompt;
}
2016-04-21 11:31:20 +08:00
//
// Command code
//
Console::Command::Command()
: _callback(nullptr)
2016-04-21 11:31:20 +08:00
{
}
Console::Command::Command(const std::string& name, const std::string& help)
: _name(name)
, _help(help)
, _callback(nullptr)
{
}
Console::Command::Command(const std::string& name, const std::string& help, const Callback& callback)
: _name(name)
, _help(help)
, _callback(callback)
{
}
Console::Command::Command(const Command& o)
{
*this = o;
}
Console::Command::Command(Command&& o)
{
*this = std::move(o);
}
Console::Command::~Command()
{
for (const auto& e : _subCommands)
{
delete e.second;
}
}
Console::Command& Console::Command::operator=(const Command& o)
{
if (this != &o)
{
_name = o._name;
_help = o._help;
_callback = o._callback;
for (const auto& e : _subCommands)
delete e.second;
_subCommands.clear();
for (const auto& e : o._subCommands)
{
Command* subCommand = e.second;
auto newCommand = new (std::nothrow) Command(*subCommand);
_subCommands[e.first] = newCommand;
}
}
return *this;
}
Console::Command& Console::Command::operator=(Command&& o)
{
if (this != &o)
{
_name = std::move(o._name);
_help = std::move(o._help);
_callback = std::move(o._callback);
o._callback = nullptr;
for (const auto& e : _subCommands)
delete e.second;
_subCommands.clear();
_subCommands = std::move(o._subCommands);
}
return *this;
}
void Console::Command::addCallback(const Callback& callback)
{
_callback = callback;
}
2016-04-21 11:31:20 +08:00
void Console::Command::addSubCommand(const Command& subCmd)
2014-01-04 14:40:22 +08:00
{
auto iter = _subCommands.find(subCmd._name);
if (iter != _subCommands.end())
{
delete iter->second;
_subCommands.erase(iter);
}
Command* cmd = new (std::nothrow) Command();
*cmd = subCmd;
_subCommands[subCmd._name] = cmd;
2014-01-04 14:40:22 +08:00
}
2016-04-21 11:31:20 +08:00
const Console::Command* Console::Command::getSubCommand(const std::string& subCmdName) const
{
auto it = _subCommands.find(subCmdName);
if(it != _subCommands.end()) {
2016-04-21 11:31:20 +08:00
auto& subCmd = it->second;
return subCmd;
2016-04-21 11:31:20 +08:00
}
return nullptr;
}
2016-04-21 11:31:20 +08:00
void Console::Command::delSubCommand(const std::string& subCmdName)
{
auto iter = _subCommands.find(subCmdName);
if (iter != _subCommands.end()) {
delete iter->second;
_subCommands.erase(iter);
2016-04-21 11:31:20 +08:00
}
}
void Console::Command::commandHelp(int fd, const std::string& /*args*/)
{
if (! _help.empty()) {
Console::Utility::mydprintf(fd, "%s\n", _help.c_str());
2016-04-21 11:31:20 +08:00
}
if (! _subCommands.empty()) {
sendHelp(fd, _subCommands, "");
2016-04-21 11:31:20 +08:00
}
}
2016-04-21 11:31:20 +08:00
void Console::Command::commandGeneric(int fd, const std::string& args)
{
2016-04-21 11:31:20 +08:00
// The first argument (including the empty)
std::string key(args);
auto pos = args.find(' ');
2016-04-21 11:31:20 +08:00
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()) {
2016-04-21 11:31:20 +08:00
auto subCmd = it->second;
if (subCmd->_callback) {
subCmd->_callback(fd, args);
2016-04-21 11:31:20 +08:00
}
return;
}
// can not find
if (_callback) {
_callback(fd, args);
2016-04-21 11:31:20 +08:00
}
}
//
// Console code
//
Console::Console()
2018-05-14 10:34:56 +08:00
: _commandSeparator(DEFAULT_COMMAND_SEPARATOR)
, _listenfd(-1)
, _running(false)
, _endThread(false)
, _isIpv6Server(false)
, _sendDebugStrings(false)
2014-12-24 02:04:42 +08:00
, _bindAddress("")
2013-12-05 16:09:38 +08:00
{
2016-04-21 11:31:20 +08:00
createCommandAllocator();
createCommandConfig();
createCommandDebugMsg();
createCommandDirector();
createCommandExit();
createCommandFileUtils();
createCommandFps();
createCommandHelp();
createCommandProjection();
createCommandResolution();
createCommandSceneGraph();
createCommandTexture();
createCommandTouch();
createCommandUpload();
createCommandVersion();
2013-12-05 09:38:11 +08:00
}
Console::~Console()
{
stop();
for (auto& e : _commands)
delete e.second;
}
2013-12-04 10:46:54 +08:00
bool Console::listenOnTCP(int port)
{
int listenfd = -1, n;
2013-12-04 10:46:54 +08:00
const int on = 1;
struct addrinfo hints, *res, *ressave;
2013-12-04 10:46:54 +08:00
char serv[30];
snprintf(serv, sizeof(serv)-1, "%d", port );
2013-12-04 10:46:54 +08:00
bzero(&hints, sizeof(struct addrinfo));
hints.ai_flags = AI_PASSIVE;
2016-05-16 14:45:09 +08:00
hints.ai_family = AF_UNSPEC;
2013-12-04 10:46:54 +08:00
hints.ai_socktype = SOCK_STREAM;
metal support for cocos2d-x (#19305) * remove deprecated files * remove some deprecated codes * remove more deprecated codes * remove ui deprecated codes * remove more deprecated codes * remove deprecated codes in ccmenuitem * remove more deprecated codes in ui * remove more deprecated codes in ui * remove more deprecated codes in ui * remove more deprecated codes * remove more deprecated codes * remove more deprecated codes * remove vr related codes and ignore some modules * remove allocator * remove some config * 【Feature】add back-end project file * [Feature] add back-end file * add pipeline descriptor and shader cache * [Feature] support sprite for backend * [Feature] remove unneeded code * [Feature] according to es2.0 spec, you must use clamp-to-edge as texture wrap mode, and no mipmapping for non-power-of-two texture * [Feature] set texture wrap mode to clamp-to-edge, and no mipmapping for non-power-of-two texture * [Feature] remove macro define to .cpp file * [Feature] add log info * [Feature] add PipelineDescriptor for TriangleCommand * [Feature] add PipelineDescriptor object as member of TriangleCommand * [Feature] add getPipelineDescriptor method * add renderbackend * complete pipeline descriptor * [Feature] add viewport in RenderCommand * set viewport when rendrering * [Feature] occur error when using RendererBackend, to be fixed. * a workaround to fix black screen on macOS 10.14 (#19090) * add rendererbackend init function * fix typo * [Feature] modify testFile * [BugFix] modify shader path * [Feature] set default viewport * fix projection * [Feature] modify log info * [BugFix] change viewport data type to int * [BugFix] add BindGroup to PipelienDescriptor * [BugFix] change a_position to vec3 in sprite.vert * [BugFix] set vertexLayout according to V3F_C4B_T2F structure * [Feature] revert a_position to vec4 * [Feature] renderer should not use gl codes directly * [Feature] it's better not use default value parameter * fix depth test setting * rendererbackend -> renderer * clear color and depth at begin * add metal backend * metal support normalized attribute * simplify codes * update external * add render pass desctriptor in pipeline descriptor * fix warnings * fix crash and memeory leak * refactor Texture2D * put pipeline descriptor into render command * simplify codes * [Feature] update Sprite * fix crash when closing app * [Feature] update SpriteBatchNode and TextureAtlas * support render texture(not finish) * [Feature] remove unused code * make tests work on mac * fix download-deps path error * make tests work on iOS * [Feature] support ttf under normal label effect * refactor triangle command processing * let renderer handle more common commands * refactor backend * make render texture work * [Feature] refactor backend for GL * [Feature]Renaming to make it easy to understand * [Feature] change warp mode to CLAMP_TO_EDGE * fix ghost * simplify visit render queue logic * support progress timer without rial mode * support partcile system * Feature/update label (#149) * [BugFix] fix compile error * [Feature] support outline effect in ios * [Feature] add shader file * [BugFix] fix begin and end RenderPass * [Feature] update CustomCommand * [Feature] revert project.pbxproj * [Feature] simplify codes * [BugFix] pack AI88 to RGBA8888 only when outline enable * [Feature] support shadow effect in Label * [Feature] support BMFont * [Feature] support glow effect * [Feature] simplify shader files * LabelAtlas work * handle blend function correctly * support tile map * don't share buffer in metal * alloc buffer size as needed * support more tilemap * Merge branch 'minggo/metal-support' into feature/updateLabel * minggo/metal-support: support tile map handle blend function correctly LabelAtlas work Feature/update label (#149) support partcile system # Conflicts: # cocos/2d/CCLabel.cpp # cocos/2d/CCSprite.cpp # cocos/2d/CCSpriteBatchNode.cpp # cocos/renderer/CCQuadCommand.cpp # cocos/renderer/CCQuadCommand.h * render texture work without saving file * use global viewport * grid3d works * remove grabber * tiled3d works * [BugFix] fix label bug * [Feature] add updateSubData for buffer * [Feature] remove setVertexCount * support depth test * add callback command * [Feature] add UITest * [Feature] update UITest * [Feature] remove unneeded codes * fix custom command issue * fix layer color blend issue * [BugFix] fix iOS compile error * [Feature] remove unneeded codes * [Feature] fix updateVertexBuffer * layerradial works * add draw test back * fix batch issue * fix compiling error * [BugFix] support ETC1 * [BugFix] get the correct pipelineDescriptor * [BugFix] skip draw when backendTexture nullptr * clipping node support * [Feature] add shader files * fix stencil issue in metal * [Feature] update UILayoutTest * [BugFix] skip drawing when vertexCount is zero * refactor renderer * add set global z order for stencil manager commands * fix warnings caused by type * remove viewport in render command * [Feature] fix warnings caused by type * [BugFix] clear vertexCount and indexCount for CustomComand when needed * [Feature] update clear for CustomCommand * ios use metal * fix viewport issue * fix LayerColorGradient crash * [cmake] transport to android and windows (#160) * save point 1 * compile on windows * run on android * revert useless change * android set CC_ENABLE_CACHE_TEXTURE_DATA to 1 * add initGlew * fix android crash * add TODO new-renderer * review update * revert onGLFWWindowPosCallback * fix android compiling error * Impl progress radial (#162) * progresstimer add radial impl * default drawType to element * dec invoke times of createVertexBuffer (#163) * support depth/stencil format for gl backend * simplify progress timer codes * support motionstreak, effect is wrong * fix motionstreak issue * [Feature] update Scissor Test (#161) * [Feature] update Scissor Test * [Feature] update ScissorTest * [Feature] rename function * [Feature] get constant reference if needed * [Feature] show render status (#164) * improve performance * fix depth state * fill error that triangle vertex/index number bigger than buffer * fix compiline error in release mode * fix buffer conflict between CPU and GPU on iOS/macOS * Renderer refactor (#165) * use one vertes/index buffer with opengl * fix error on windows * custom command support index format config * CCLayer: compact vertex data structure * update comment * fix doc * support fast tilemap * pass index format instead * fix some wrong effect * fix render texture error * fix texture per-element size * fix texture format error * BlendFunc type refactor, GLenum -> backend::BlendFactor (#167) * BlendFunc use backend::BlendFactor as inner field * update comments * use int to replace GLenum * update xcode project fiel * rename to GLBlendConst * add ccConstants.h * update xcode project file * update copyright * remove primitive command * remove CCPrimitive.cpp/.h * remove deprecated files * remove unneeded files * remove multiple view support * remove multiple view support * remove the usage of frame buffer in camera * director don't use frame buffer * remove FrameBuffer * remove BatchCommand * add some api reference * add physics2d back * fix crash when close app on mac * improve render texture * fix rendertexture issue * fix rendertexture issue * simplify codes * CMake support for mac & ios (#169) * update cmake * fix compile error * update 3rd libs version * remove CCThread.h/.cpp * remove ccthread * use audio engine to implement simple audio engine * remove unneeded codes * remove deprecated codes * remove winrt macro * remove CC_USE_WIC * set partcile blend function in more elegant way * remove unneeded codes * remove unneeded codes * cmake works on windows * update project setting * improve performance * GLFloat -> float * sync v3 cmake improvements into metal-support (#172) * pick: modern cmake, compile definitions improvement (#19139) * modern cmake, use target_compile_definitions partly * simplify macro define, remove USE_* * modern cmake, macro define * add physics 2d macro define into ccConfig.h * remove USE_CHIPMUNK macro in build.gradle * remove CocosSelectModule.cmake * shrink useless define * simplify compile options config, re-add if necessary * update external for tmp CI test * un-quote target_compile_options value * add "-g" parameter only when debug mode * keep single build type when generator Xcode & VS projecy * update external for tmp CI tes * add static_cast<char>(-1), fix -Wc++11-narrowing * simplify win32 compile define * not modify code, only improve compile options # Conflicts: # .gitignore # cmake/Modules/CocosConfigDepend.cmake # cocos/CMakeLists.txt # external/config.json # tests/cpp-tests/CMakeLists.txt * modern cmake, improve cmake_compiler_flags (#19145) * cmake_compiler_flags * Fix typo * Fix typo2 * Remove chanages from Android.mk * correct lua template cmake build (#19149) * don't add -Wno-deprecated into jsb target * correct lua template cmake build * fix win32 lua template compile error * prevent cmake in-source-build friendly (#19151) * pick: Copy resources to "Resources/" on win32 like in linux configuration * add "/Z7" for cpp-tests on windows * [cmake] fix iOS xcode property setting failed (#19208) * fix iOS xcode property setting failed * use search_depend_libs_recursive at dlls collect * fix typo * [cmake] add find_host_library into iOS toolchain file (#19230) * pick: [lua android] use luajit & template cmake update (#19239) * increase cmake stability , remove tests/CMakeLists.txt (#19261) * cmake win32 Precompiled header (#19273) * Precompiled header * Fix * Precompiled header for cocos * Precompiled header jscocos2d * Fix for COCOS2D_DEBUG is always 1 on Android (#19291) Related #19289 * little build fix, tests cpp-tests works on mac * sync v3 build related codes into metal-support (#173) * strict initialization for std::array * remove proj.win32 project configs * modern cmake, cmake_cleanup_remove_unused_variables (#19146) * Switch travis CI to xenial (#19207) * Switch travis CI to xenial * Remove language: android * Set language: cpp * Fix java problem * Update sdkmanager * Fix sdkmanger * next sdkmanager fix * Remove xenial from android * revert to sdk-tools-{system}-3859397 * Remove linux cmake install * Update before-install.sh * Update .travis.yml * Simplify install-deps-linux.sh, tested on Ubuntu 16.04 (#19212) * Simplify install-deps-linux.sh * Cleanup * pick: install ninja * update cocos2d-console submodule * for metal-support alpha release, we only test cpp * add HelloCpp into project(Cocos2d-x) for tmp test * update extenal metal-support-4 * update uniform setting * [Feature] update BindGroup * [Feature] empty-test * [Feature] cpp-test * [Feature] fix GL compiler error * [Feature] fix GL crash * [Feature] empty-test * [Feature] cpp-tests * [feature] improve frameRate * [feature] fix opengl compile error * [feature] fix opengl compile error * [BugFix] fix compute maxLocation error * [Feature] update setting unifrom * [Feature] fix namespace * [Feature] remove unneeded code * [Bugfix] fix project file * [Feature] update review * [texture2d] impl texture format support (#175) * texture update * update * update texture * commit * compile on windows * ddd * rename * rename methods * no crash * save gl * save * save * rename * move out pixel format convert functions * metal crash * update * update android * support gles compressed texture format * support more compress format * add more conversion methods * ss * save * update conversion methods * add PVRTC format support * reformat * add marco linux * fix GL marcro * pvrtc supported only by ios 8.0+ * remove unused cmake * revert change * refactor Texture2D::initWithData * fix conversion log * refactor Texture2D::initWithData * remove some OpenGL constants for PVRTC * add todo * fix typo * AutoTest works on mac/iOS by disable part cases, sync v3 bug fix (#174) * review cpp-tests, and fix part issues on start auto test * sync png format fix: Node:Particle3D abnormal texture effects #19204 * fix cpp-tests SpritePolygon crash, wrong png format (#19170) * fix wrong png convert format from sRGB to Gray * erase plist index if all frames was erased * test_A8.png have I8 format, fix it * [CCSpriteCache] allow re-add plist & add testcase (#19175) * allow re-add plist & add testcase * remove comments/rename method/update testcase * fix isSpriteFramesWithFileLoaded & add testcase * remove used variable * remove unused variable * fix double free issues when js/lua-tests exit on iOS (#19236) * disable part cases, AutoTest works without crash on mac * update cocos2dx files json, to test cocos new next * fix spritecache plist parsing issue (#19269) * [linux] Fix FileUtils::getContents with folder (#19157) * fix FileUtils::getContents on linux/mac * use stat.st_mode * simplify * [CCFileUtils] win32 getFileSize (#19176) * win32 getFileSize * fix stat * [cpp test-Android]20:FileUtils/2 change title (#19197) * sync #19200 * sync #19231 * [android lua] improve performance of lua loader (#19234) * [lua] improve performance of lua loader * remove cache fix * Revert "fix spritecache plist parsing issue (#19269)" This reverts commit f3a85ece4307a7b90816c34489d1ed2c8fd11baf. * remove win32 project files ref in template.json * add metal framework lnk ref into cpp template * test on iOS, and disable part cases * alBufferData instead of alBufferDataStatic for small audio file on Apple (#19227) * changes AudioCache to use alBufferData instead of alBufferDataStatic (also makes test 19 faster to trigger openal bugs faster) The original problem: CrashIfClientProvidedBogusAudioBufferList https://github.com/cocos2d/cocos2d-x/issues/18948 is not happening anymore, but there's still a not very frequent issue that makes OpenAL crash with a call stack like this. AudioCache::readDataTask > alBufferData > CleanUpDeadBufferList It happes more frequently when the device is "cold", which means after half an hour of not using the device (locked). I could not find the actual source code for iOS OpenAL, so I used the macOS versions: https://opensource.apple.com/source/OpenAL/OpenAL-48.7/Source/OpenAL/oalImp.cpp.auto.html They seem to use CAGuard.h to make sure the dead buffer list has no threading issues. I'm worried because the CAGuard code I found has macos and win32 define but no iOS, so I'm not sure. I guess the iOS version is different and has the guard. I could not find a place in the code that's unprotected by the locks except the InitializeBufferMap() which should not be called more than once from cocos, and there's a workaround in AudioEngine-impl for it. I reduced the occurence of the CleanUpDeadBufferList crash by moving the guard in ~AudioCache to cover the alDeleteBuffers call. * remove hack method "setTimeout" on audio * AutoTest works on iOS * support set ios deployment target for root project * enable all texture2d cases, since Jiang have fixed * add CCTextureUtils to xcode project file (#176) * add leak cases for SpriteFrameCache (#177) * re-add SpriteFrameCache cases * update template file json * Update SpriteFrameCacheTest.cpp * fix compiling error
2019-01-18 15:08:25 +08:00
#if (CC_TARGET_PLATFORM == CC_PLATFORM_WIN32)
2013-12-05 16:09:38 +08:00
WSADATA wsaData;
n = WSAStartup(MAKEWORD(2, 2),&wsaData);
#endif
if ( (n = getaddrinfo(nullptr, serv, &hints, &res)) != 0) {
2018-01-22 09:23:45 +08:00
#if (CC_TARGET_PLATFORM == CC_PLATFORM_WIN32)
fprintf(stderr, "net_listen error for %s: %s", serv, gai_strerrorA(n));
#else
fprintf(stderr,"net_listen error for %s: %s", serv, gai_strerror(n));
2018-01-22 09:23:45 +08:00
#endif
2013-12-04 10:46:54 +08:00
return false;
}
ressave = res;
do {
listenfd = socket(res->ai_family, res->ai_socktype, res->ai_protocol);
if (listenfd < 0)
continue; /* error, try next one */
2013-12-04 10:46:54 +08:00
2013-12-05 16:09:38 +08:00
setsockopt(listenfd, SOL_SOCKET, SO_REUSEADDR, (const char*)&on, sizeof(on));
2014-12-24 02:04:42 +08:00
// bind address
if (!_bindAddress.empty())
2014-12-24 02:04:42 +08:00
{
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);
}
2014-12-24 02:04:42 +08:00
}
2013-12-04 10:46:54 +08:00
if (bind(listenfd, res->ai_addr, res->ai_addrlen) == 0)
break; /* success */
2013-12-04 10:46:54 +08:00
/* bind error, close and try next one */
metal support for cocos2d-x (#19305) * remove deprecated files * remove some deprecated codes * remove more deprecated codes * remove ui deprecated codes * remove more deprecated codes * remove deprecated codes in ccmenuitem * remove more deprecated codes in ui * remove more deprecated codes in ui * remove more deprecated codes in ui * remove more deprecated codes * remove more deprecated codes * remove more deprecated codes * remove vr related codes and ignore some modules * remove allocator * remove some config * 【Feature】add back-end project file * [Feature] add back-end file * add pipeline descriptor and shader cache * [Feature] support sprite for backend * [Feature] remove unneeded code * [Feature] according to es2.0 spec, you must use clamp-to-edge as texture wrap mode, and no mipmapping for non-power-of-two texture * [Feature] set texture wrap mode to clamp-to-edge, and no mipmapping for non-power-of-two texture * [Feature] remove macro define to .cpp file * [Feature] add log info * [Feature] add PipelineDescriptor for TriangleCommand * [Feature] add PipelineDescriptor object as member of TriangleCommand * [Feature] add getPipelineDescriptor method * add renderbackend * complete pipeline descriptor * [Feature] add viewport in RenderCommand * set viewport when rendrering * [Feature] occur error when using RendererBackend, to be fixed. * a workaround to fix black screen on macOS 10.14 (#19090) * add rendererbackend init function * fix typo * [Feature] modify testFile * [BugFix] modify shader path * [Feature] set default viewport * fix projection * [Feature] modify log info * [BugFix] change viewport data type to int * [BugFix] add BindGroup to PipelienDescriptor * [BugFix] change a_position to vec3 in sprite.vert * [BugFix] set vertexLayout according to V3F_C4B_T2F structure * [Feature] revert a_position to vec4 * [Feature] renderer should not use gl codes directly * [Feature] it's better not use default value parameter * fix depth test setting * rendererbackend -> renderer * clear color and depth at begin * add metal backend * metal support normalized attribute * simplify codes * update external * add render pass desctriptor in pipeline descriptor * fix warnings * fix crash and memeory leak * refactor Texture2D * put pipeline descriptor into render command * simplify codes * [Feature] update Sprite * fix crash when closing app * [Feature] update SpriteBatchNode and TextureAtlas * support render texture(not finish) * [Feature] remove unused code * make tests work on mac * fix download-deps path error * make tests work on iOS * [Feature] support ttf under normal label effect * refactor triangle command processing * let renderer handle more common commands * refactor backend * make render texture work * [Feature] refactor backend for GL * [Feature]Renaming to make it easy to understand * [Feature] change warp mode to CLAMP_TO_EDGE * fix ghost * simplify visit render queue logic * support progress timer without rial mode * support partcile system * Feature/update label (#149) * [BugFix] fix compile error * [Feature] support outline effect in ios * [Feature] add shader file * [BugFix] fix begin and end RenderPass * [Feature] update CustomCommand * [Feature] revert project.pbxproj * [Feature] simplify codes * [BugFix] pack AI88 to RGBA8888 only when outline enable * [Feature] support shadow effect in Label * [Feature] support BMFont * [Feature] support glow effect * [Feature] simplify shader files * LabelAtlas work * handle blend function correctly * support tile map * don't share buffer in metal * alloc buffer size as needed * support more tilemap * Merge branch 'minggo/metal-support' into feature/updateLabel * minggo/metal-support: support tile map handle blend function correctly LabelAtlas work Feature/update label (#149) support partcile system # Conflicts: # cocos/2d/CCLabel.cpp # cocos/2d/CCSprite.cpp # cocos/2d/CCSpriteBatchNode.cpp # cocos/renderer/CCQuadCommand.cpp # cocos/renderer/CCQuadCommand.h * render texture work without saving file * use global viewport * grid3d works * remove grabber * tiled3d works * [BugFix] fix label bug * [Feature] add updateSubData for buffer * [Feature] remove setVertexCount * support depth test * add callback command * [Feature] add UITest * [Feature] update UITest * [Feature] remove unneeded codes * fix custom command issue * fix layer color blend issue * [BugFix] fix iOS compile error * [Feature] remove unneeded codes * [Feature] fix updateVertexBuffer * layerradial works * add draw test back * fix batch issue * fix compiling error * [BugFix] support ETC1 * [BugFix] get the correct pipelineDescriptor * [BugFix] skip draw when backendTexture nullptr * clipping node support * [Feature] add shader files * fix stencil issue in metal * [Feature] update UILayoutTest * [BugFix] skip drawing when vertexCount is zero * refactor renderer * add set global z order for stencil manager commands * fix warnings caused by type * remove viewport in render command * [Feature] fix warnings caused by type * [BugFix] clear vertexCount and indexCount for CustomComand when needed * [Feature] update clear for CustomCommand * ios use metal * fix viewport issue * fix LayerColorGradient crash * [cmake] transport to android and windows (#160) * save point 1 * compile on windows * run on android * revert useless change * android set CC_ENABLE_CACHE_TEXTURE_DATA to 1 * add initGlew * fix android crash * add TODO new-renderer * review update * revert onGLFWWindowPosCallback * fix android compiling error * Impl progress radial (#162) * progresstimer add radial impl * default drawType to element * dec invoke times of createVertexBuffer (#163) * support depth/stencil format for gl backend * simplify progress timer codes * support motionstreak, effect is wrong * fix motionstreak issue * [Feature] update Scissor Test (#161) * [Feature] update Scissor Test * [Feature] update ScissorTest * [Feature] rename function * [Feature] get constant reference if needed * [Feature] show render status (#164) * improve performance * fix depth state * fill error that triangle vertex/index number bigger than buffer * fix compiline error in release mode * fix buffer conflict between CPU and GPU on iOS/macOS * Renderer refactor (#165) * use one vertes/index buffer with opengl * fix error on windows * custom command support index format config * CCLayer: compact vertex data structure * update comment * fix doc * support fast tilemap * pass index format instead * fix some wrong effect * fix render texture error * fix texture per-element size * fix texture format error * BlendFunc type refactor, GLenum -> backend::BlendFactor (#167) * BlendFunc use backend::BlendFactor as inner field * update comments * use int to replace GLenum * update xcode project fiel * rename to GLBlendConst * add ccConstants.h * update xcode project file * update copyright * remove primitive command * remove CCPrimitive.cpp/.h * remove deprecated files * remove unneeded files * remove multiple view support * remove multiple view support * remove the usage of frame buffer in camera * director don't use frame buffer * remove FrameBuffer * remove BatchCommand * add some api reference * add physics2d back * fix crash when close app on mac * improve render texture * fix rendertexture issue * fix rendertexture issue * simplify codes * CMake support for mac & ios (#169) * update cmake * fix compile error * update 3rd libs version * remove CCThread.h/.cpp * remove ccthread * use audio engine to implement simple audio engine * remove unneeded codes * remove deprecated codes * remove winrt macro * remove CC_USE_WIC * set partcile blend function in more elegant way * remove unneeded codes * remove unneeded codes * cmake works on windows * update project setting * improve performance * GLFloat -> float * sync v3 cmake improvements into metal-support (#172) * pick: modern cmake, compile definitions improvement (#19139) * modern cmake, use target_compile_definitions partly * simplify macro define, remove USE_* * modern cmake, macro define * add physics 2d macro define into ccConfig.h * remove USE_CHIPMUNK macro in build.gradle * remove CocosSelectModule.cmake * shrink useless define * simplify compile options config, re-add if necessary * update external for tmp CI test * un-quote target_compile_options value * add "-g" parameter only when debug mode * keep single build type when generator Xcode & VS projecy * update external for tmp CI tes * add static_cast<char>(-1), fix -Wc++11-narrowing * simplify win32 compile define * not modify code, only improve compile options # Conflicts: # .gitignore # cmake/Modules/CocosConfigDepend.cmake # cocos/CMakeLists.txt # external/config.json # tests/cpp-tests/CMakeLists.txt * modern cmake, improve cmake_compiler_flags (#19145) * cmake_compiler_flags * Fix typo * Fix typo2 * Remove chanages from Android.mk * correct lua template cmake build (#19149) * don't add -Wno-deprecated into jsb target * correct lua template cmake build * fix win32 lua template compile error * prevent cmake in-source-build friendly (#19151) * pick: Copy resources to "Resources/" on win32 like in linux configuration * add "/Z7" for cpp-tests on windows * [cmake] fix iOS xcode property setting failed (#19208) * fix iOS xcode property setting failed * use search_depend_libs_recursive at dlls collect * fix typo * [cmake] add find_host_library into iOS toolchain file (#19230) * pick: [lua android] use luajit & template cmake update (#19239) * increase cmake stability , remove tests/CMakeLists.txt (#19261) * cmake win32 Precompiled header (#19273) * Precompiled header * Fix * Precompiled header for cocos * Precompiled header jscocos2d * Fix for COCOS2D_DEBUG is always 1 on Android (#19291) Related #19289 * little build fix, tests cpp-tests works on mac * sync v3 build related codes into metal-support (#173) * strict initialization for std::array * remove proj.win32 project configs * modern cmake, cmake_cleanup_remove_unused_variables (#19146) * Switch travis CI to xenial (#19207) * Switch travis CI to xenial * Remove language: android * Set language: cpp * Fix java problem * Update sdkmanager * Fix sdkmanger * next sdkmanager fix * Remove xenial from android * revert to sdk-tools-{system}-3859397 * Remove linux cmake install * Update before-install.sh * Update .travis.yml * Simplify install-deps-linux.sh, tested on Ubuntu 16.04 (#19212) * Simplify install-deps-linux.sh * Cleanup * pick: install ninja * update cocos2d-console submodule * for metal-support alpha release, we only test cpp * add HelloCpp into project(Cocos2d-x) for tmp test * update extenal metal-support-4 * update uniform setting * [Feature] update BindGroup * [Feature] empty-test * [Feature] cpp-test * [Feature] fix GL compiler error * [Feature] fix GL crash * [Feature] empty-test * [Feature] cpp-tests * [feature] improve frameRate * [feature] fix opengl compile error * [feature] fix opengl compile error * [BugFix] fix compute maxLocation error * [Feature] update setting unifrom * [Feature] fix namespace * [Feature] remove unneeded code * [Bugfix] fix project file * [Feature] update review * [texture2d] impl texture format support (#175) * texture update * update * update texture * commit * compile on windows * ddd * rename * rename methods * no crash * save gl * save * save * rename * move out pixel format convert functions * metal crash * update * update android * support gles compressed texture format * support more compress format * add more conversion methods * ss * save * update conversion methods * add PVRTC format support * reformat * add marco linux * fix GL marcro * pvrtc supported only by ios 8.0+ * remove unused cmake * revert change * refactor Texture2D::initWithData * fix conversion log * refactor Texture2D::initWithData * remove some OpenGL constants for PVRTC * add todo * fix typo * AutoTest works on mac/iOS by disable part cases, sync v3 bug fix (#174) * review cpp-tests, and fix part issues on start auto test * sync png format fix: Node:Particle3D abnormal texture effects #19204 * fix cpp-tests SpritePolygon crash, wrong png format (#19170) * fix wrong png convert format from sRGB to Gray * erase plist index if all frames was erased * test_A8.png have I8 format, fix it * [CCSpriteCache] allow re-add plist & add testcase (#19175) * allow re-add plist & add testcase * remove comments/rename method/update testcase * fix isSpriteFramesWithFileLoaded & add testcase * remove used variable * remove unused variable * fix double free issues when js/lua-tests exit on iOS (#19236) * disable part cases, AutoTest works without crash on mac * update cocos2dx files json, to test cocos new next * fix spritecache plist parsing issue (#19269) * [linux] Fix FileUtils::getContents with folder (#19157) * fix FileUtils::getContents on linux/mac * use stat.st_mode * simplify * [CCFileUtils] win32 getFileSize (#19176) * win32 getFileSize * fix stat * [cpp test-Android]20:FileUtils/2 change title (#19197) * sync #19200 * sync #19231 * [android lua] improve performance of lua loader (#19234) * [lua] improve performance of lua loader * remove cache fix * Revert "fix spritecache plist parsing issue (#19269)" This reverts commit f3a85ece4307a7b90816c34489d1ed2c8fd11baf. * remove win32 project files ref in template.json * add metal framework lnk ref into cpp template * test on iOS, and disable part cases * alBufferData instead of alBufferDataStatic for small audio file on Apple (#19227) * changes AudioCache to use alBufferData instead of alBufferDataStatic (also makes test 19 faster to trigger openal bugs faster) The original problem: CrashIfClientProvidedBogusAudioBufferList https://github.com/cocos2d/cocos2d-x/issues/18948 is not happening anymore, but there's still a not very frequent issue that makes OpenAL crash with a call stack like this. AudioCache::readDataTask > alBufferData > CleanUpDeadBufferList It happes more frequently when the device is "cold", which means after half an hour of not using the device (locked). I could not find the actual source code for iOS OpenAL, so I used the macOS versions: https://opensource.apple.com/source/OpenAL/OpenAL-48.7/Source/OpenAL/oalImp.cpp.auto.html They seem to use CAGuard.h to make sure the dead buffer list has no threading issues. I'm worried because the CAGuard code I found has macos and win32 define but no iOS, so I'm not sure. I guess the iOS version is different and has the guard. I could not find a place in the code that's unprotected by the locks except the InitializeBufferMap() which should not be called more than once from cocos, and there's a workaround in AudioEngine-impl for it. I reduced the occurence of the CleanUpDeadBufferList crash by moving the guard in ~AudioCache to cover the alDeleteBuffers call. * remove hack method "setTimeout" on audio * AutoTest works on iOS * support set ios deployment target for root project * enable all texture2d cases, since Jiang have fixed * add CCTextureUtils to xcode project file (#176) * add leak cases for SpriteFrameCache (#177) * re-add SpriteFrameCache cases * update template file json * Update SpriteFrameCacheTest.cpp * fix compiling error
2019-01-18 15:08:25 +08:00
#if (CC_TARGET_PLATFORM == CC_PLATFORM_WIN32)
closesocket(listenfd);
#else
close(listenfd);
#endif
} while ( (res = res->ai_next) != nullptr);
2013-12-04 10:46:54 +08:00
if (res == nullptr) {
2013-12-04 10:46:54 +08:00
perror("net_listen:");
freeaddrinfo(ressave);
return false;
}
2013-12-05 08:26:21 +08:00
2013-12-04 10:46:54 +08:00
listen(listenfd, 50);
2013-12-05 08:26:21 +08:00
if (res->ai_family == AF_INET) {
_isIpv6Server = false;
char buf[INET_ADDRSTRLEN] = {0};
2013-12-05 08:26:21 +08:00
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: IPV4 server is listening on %s:%d", buf, ntohs(sin->sin_port));
else
perror("inet_ntop");
} else if (res->ai_family == AF_INET6) {
_isIpv6Server = true;
char buf[INET6_ADDRSTRLEN] = {0};
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: IPV6 server is listening on [%s]:%d", buf, ntohs(sin->sin6_port));
2013-12-05 08:26:21 +08:00
else
perror("inet_ntop");
}
2013-12-04 10:46:54 +08:00
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;
}
2013-12-04 10:46:54 +08:00
_listenfd = fd;
_thread = std::thread( std::bind( &Console::loop, this) );
2013-12-04 10:46:54 +08:00
return true;
}
void Console::stop()
{
2013-12-04 10:46:54 +08:00
if( _running ) {
_endThread = true;
2015-05-19 18:33:06 +08:00
if (_thread.joinable())
{
_thread.join();
}
2013-12-04 10:46:54 +08:00
}
}
2014-02-14 14:54:26 +08:00
void Console::addCommand(const Command& cmd)
2013-12-05 09:38:11 +08:00
{
Command* newCommand = new (std::nothrow) Command(cmd);
auto iter = _commands.find(cmd.getName());
if (iter != _commands.end())
{
delete iter->second;
_commands.erase(iter);
}
_commands[cmd.getName()] = newCommand;
2014-02-13 10:40:57 +08:00
}
2013-12-05 08:26:21 +08:00
2016-04-21 11:31:20 +08:00
void Console::addSubCommand(const std::string& cmdName, const Command& subCmd)
2013-12-04 10:46:54 +08:00
{
2016-04-21 11:31:20 +08:00
auto it = _commands.find(cmdName);
if (it != _commands.end())
{
2016-04-21 11:31:20 +08:00
auto& cmd = it->second;
addSubCommand(*cmd, subCmd);
2016-04-21 11:31:20 +08:00
}
2013-12-05 08:26:21 +08:00
}
2013-12-04 10:46:54 +08:00
2016-04-21 11:31:20 +08:00
void Console::addSubCommand(Command& cmd, const Command& subCmd)
2013-12-05 08:26:21 +08:00
{
cmd.addSubCommand(subCmd);
2013-12-05 08:26:21 +08:00
}
2016-04-21 11:31:20 +08:00
const Console::Command* Console::getCommand(const std::string& cmdName)
2013-12-05 08:57:44 +08:00
{
2016-04-21 11:31:20 +08:00
auto it = _commands.find(cmdName);
if(it != _commands.end()) {
auto& cmd = it->second;
return cmd;
2016-04-21 11:31:20 +08:00
}
return nullptr;
2013-12-05 08:57:44 +08:00
}
2016-04-21 11:31:20 +08:00
const Console::Command* Console::getSubCommand(const std::string& cmdName, const std::string& subCmdName)
{
2016-04-21 11:31:20 +08:00
auto it = _commands.find(cmdName);
if(it != _commands.end()) {
auto& cmd = it->second;
return getSubCommand(*cmd, subCmdName);
}
2016-04-21 11:31:20 +08:00
return nullptr;
}
2016-04-21 11:31:20 +08:00
const Console::Command* Console::getSubCommand(const Command& cmd, const std::string& subCmdName)
{
2016-04-21 11:31:20 +08:00
return cmd.getSubCommand(subCmdName);
}
2016-04-21 11:31:20 +08:00
void Console::delCommand(const std::string& cmdName)
{
2016-04-21 11:31:20 +08:00
auto it = _commands.find(cmdName);
if(it != _commands.end()) {
delete it->second;
2016-04-21 11:31:20 +08:00
_commands.erase(it);
}
}
2016-04-21 11:31:20 +08:00
void Console::delSubCommand(const std::string& cmdName, const std::string& subCmdName)
{
2016-04-21 11:31:20 +08:00
auto it = _commands.find(cmdName);
if(it != _commands.end()) {
auto& cmd = it->second;
delSubCommand(*cmd, subCmdName);
}
}
2016-04-21 11:31:20 +08:00
void Console::delSubCommand(Command& cmd, const std::string& subCmdName)
{
2016-04-21 11:31:20 +08:00
cmd.delSubCommand(subCmdName);
}
2016-04-21 11:31:20 +08:00
void Console::log(const char* buf)
{
if( _sendDebugStrings ) {
_DebugStringsMutex.lock();
_DebugStrings.push_back(buf);
_DebugStringsMutex.unlock();
}
}
2016-04-21 11:31:20 +08:00
void Console::setBindAddress(const std::string &address)
{
2016-04-21 11:31:20 +08:00
_bindAddress = address;
}
bool Console::isIpv6Server() const
{
return _isIpv6Server;
}
2016-04-21 11:31:20 +08:00
//
// Main Loop
//
void Console::loop()
2014-02-25 11:04:59 +08:00
{
2016-04-21 11:31:20 +08:00
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 = 1;
timeout.tv_usec = 0;
2016-04-21 11:31:20 +08:00
while(!_endThread) {
2014-02-25 11:04:59 +08:00
2016-04-21 11:31:20 +08:00
copy_set = _read_set;
timeout_copy = timeout;
int nready = select(_maxfd+1, &copy_set, nullptr, nullptr, &timeout_copy);
if( nready == -1 )
2014-02-25 11:04:59 +08:00
{
2016-04-21 11:31:20 +08:00
/* error */
if(errno != EINTR)
cocos2d::log("Abnormal error in select()\n");
2016-04-21 11:31:20 +08:00
continue;
2014-02-25 11:04:59 +08:00
}
2016-04-21 11:31:20 +08:00
else if( nready == 0 )
2014-02-25 11:04:59 +08:00
{
2016-04-21 11:31:20 +08:00
/* timeout. do something ? */
2014-02-25 11:47:53 +08:00
}
2016-04-21 11:31:20 +08:00
else
2014-02-25 11:47:53 +08:00
{
2016-04-21 11:31:20 +08:00
/* new client */
if(FD_ISSET(_listenfd, &copy_set)) {
addClient();
if(--nready <= 0)
continue;
}
/* data from client */
std::vector<int> to_remove;
for(const auto &fd: _fds) {
if(FD_ISSET(fd,&copy_set))
2014-02-25 15:52:37 +08:00
{
2016-04-21 11:31:20 +08:00
//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.
metal support for cocos2d-x (#19305) * remove deprecated files * remove some deprecated codes * remove more deprecated codes * remove ui deprecated codes * remove more deprecated codes * remove deprecated codes in ccmenuitem * remove more deprecated codes in ui * remove more deprecated codes in ui * remove more deprecated codes in ui * remove more deprecated codes * remove more deprecated codes * remove more deprecated codes * remove vr related codes and ignore some modules * remove allocator * remove some config * 【Feature】add back-end project file * [Feature] add back-end file * add pipeline descriptor and shader cache * [Feature] support sprite for backend * [Feature] remove unneeded code * [Feature] according to es2.0 spec, you must use clamp-to-edge as texture wrap mode, and no mipmapping for non-power-of-two texture * [Feature] set texture wrap mode to clamp-to-edge, and no mipmapping for non-power-of-two texture * [Feature] remove macro define to .cpp file * [Feature] add log info * [Feature] add PipelineDescriptor for TriangleCommand * [Feature] add PipelineDescriptor object as member of TriangleCommand * [Feature] add getPipelineDescriptor method * add renderbackend * complete pipeline descriptor * [Feature] add viewport in RenderCommand * set viewport when rendrering * [Feature] occur error when using RendererBackend, to be fixed. * a workaround to fix black screen on macOS 10.14 (#19090) * add rendererbackend init function * fix typo * [Feature] modify testFile * [BugFix] modify shader path * [Feature] set default viewport * fix projection * [Feature] modify log info * [BugFix] change viewport data type to int * [BugFix] add BindGroup to PipelienDescriptor * [BugFix] change a_position to vec3 in sprite.vert * [BugFix] set vertexLayout according to V3F_C4B_T2F structure * [Feature] revert a_position to vec4 * [Feature] renderer should not use gl codes directly * [Feature] it's better not use default value parameter * fix depth test setting * rendererbackend -> renderer * clear color and depth at begin * add metal backend * metal support normalized attribute * simplify codes * update external * add render pass desctriptor in pipeline descriptor * fix warnings * fix crash and memeory leak * refactor Texture2D * put pipeline descriptor into render command * simplify codes * [Feature] update Sprite * fix crash when closing app * [Feature] update SpriteBatchNode and TextureAtlas * support render texture(not finish) * [Feature] remove unused code * make tests work on mac * fix download-deps path error * make tests work on iOS * [Feature] support ttf under normal label effect * refactor triangle command processing * let renderer handle more common commands * refactor backend * make render texture work * [Feature] refactor backend for GL * [Feature]Renaming to make it easy to understand * [Feature] change warp mode to CLAMP_TO_EDGE * fix ghost * simplify visit render queue logic * support progress timer without rial mode * support partcile system * Feature/update label (#149) * [BugFix] fix compile error * [Feature] support outline effect in ios * [Feature] add shader file * [BugFix] fix begin and end RenderPass * [Feature] update CustomCommand * [Feature] revert project.pbxproj * [Feature] simplify codes * [BugFix] pack AI88 to RGBA8888 only when outline enable * [Feature] support shadow effect in Label * [Feature] support BMFont * [Feature] support glow effect * [Feature] simplify shader files * LabelAtlas work * handle blend function correctly * support tile map * don't share buffer in metal * alloc buffer size as needed * support more tilemap * Merge branch 'minggo/metal-support' into feature/updateLabel * minggo/metal-support: support tile map handle blend function correctly LabelAtlas work Feature/update label (#149) support partcile system # Conflicts: # cocos/2d/CCLabel.cpp # cocos/2d/CCSprite.cpp # cocos/2d/CCSpriteBatchNode.cpp # cocos/renderer/CCQuadCommand.cpp # cocos/renderer/CCQuadCommand.h * render texture work without saving file * use global viewport * grid3d works * remove grabber * tiled3d works * [BugFix] fix label bug * [Feature] add updateSubData for buffer * [Feature] remove setVertexCount * support depth test * add callback command * [Feature] add UITest * [Feature] update UITest * [Feature] remove unneeded codes * fix custom command issue * fix layer color blend issue * [BugFix] fix iOS compile error * [Feature] remove unneeded codes * [Feature] fix updateVertexBuffer * layerradial works * add draw test back * fix batch issue * fix compiling error * [BugFix] support ETC1 * [BugFix] get the correct pipelineDescriptor * [BugFix] skip draw when backendTexture nullptr * clipping node support * [Feature] add shader files * fix stencil issue in metal * [Feature] update UILayoutTest * [BugFix] skip drawing when vertexCount is zero * refactor renderer * add set global z order for stencil manager commands * fix warnings caused by type * remove viewport in render command * [Feature] fix warnings caused by type * [BugFix] clear vertexCount and indexCount for CustomComand when needed * [Feature] update clear for CustomCommand * ios use metal * fix viewport issue * fix LayerColorGradient crash * [cmake] transport to android and windows (#160) * save point 1 * compile on windows * run on android * revert useless change * android set CC_ENABLE_CACHE_TEXTURE_DATA to 1 * add initGlew * fix android crash * add TODO new-renderer * review update * revert onGLFWWindowPosCallback * fix android compiling error * Impl progress radial (#162) * progresstimer add radial impl * default drawType to element * dec invoke times of createVertexBuffer (#163) * support depth/stencil format for gl backend * simplify progress timer codes * support motionstreak, effect is wrong * fix motionstreak issue * [Feature] update Scissor Test (#161) * [Feature] update Scissor Test * [Feature] update ScissorTest * [Feature] rename function * [Feature] get constant reference if needed * [Feature] show render status (#164) * improve performance * fix depth state * fill error that triangle vertex/index number bigger than buffer * fix compiline error in release mode * fix buffer conflict between CPU and GPU on iOS/macOS * Renderer refactor (#165) * use one vertes/index buffer with opengl * fix error on windows * custom command support index format config * CCLayer: compact vertex data structure * update comment * fix doc * support fast tilemap * pass index format instead * fix some wrong effect * fix render texture error * fix texture per-element size * fix texture format error * BlendFunc type refactor, GLenum -> backend::BlendFactor (#167) * BlendFunc use backend::BlendFactor as inner field * update comments * use int to replace GLenum * update xcode project fiel * rename to GLBlendConst * add ccConstants.h * update xcode project file * update copyright * remove primitive command * remove CCPrimitive.cpp/.h * remove deprecated files * remove unneeded files * remove multiple view support * remove multiple view support * remove the usage of frame buffer in camera * director don't use frame buffer * remove FrameBuffer * remove BatchCommand * add some api reference * add physics2d back * fix crash when close app on mac * improve render texture * fix rendertexture issue * fix rendertexture issue * simplify codes * CMake support for mac & ios (#169) * update cmake * fix compile error * update 3rd libs version * remove CCThread.h/.cpp * remove ccthread * use audio engine to implement simple audio engine * remove unneeded codes * remove deprecated codes * remove winrt macro * remove CC_USE_WIC * set partcile blend function in more elegant way * remove unneeded codes * remove unneeded codes * cmake works on windows * update project setting * improve performance * GLFloat -> float * sync v3 cmake improvements into metal-support (#172) * pick: modern cmake, compile definitions improvement (#19139) * modern cmake, use target_compile_definitions partly * simplify macro define, remove USE_* * modern cmake, macro define * add physics 2d macro define into ccConfig.h * remove USE_CHIPMUNK macro in build.gradle * remove CocosSelectModule.cmake * shrink useless define * simplify compile options config, re-add if necessary * update external for tmp CI test * un-quote target_compile_options value * add "-g" parameter only when debug mode * keep single build type when generator Xcode & VS projecy * update external for tmp CI tes * add static_cast<char>(-1), fix -Wc++11-narrowing * simplify win32 compile define * not modify code, only improve compile options # Conflicts: # .gitignore # cmake/Modules/CocosConfigDepend.cmake # cocos/CMakeLists.txt # external/config.json # tests/cpp-tests/CMakeLists.txt * modern cmake, improve cmake_compiler_flags (#19145) * cmake_compiler_flags * Fix typo * Fix typo2 * Remove chanages from Android.mk * correct lua template cmake build (#19149) * don't add -Wno-deprecated into jsb target * correct lua template cmake build * fix win32 lua template compile error * prevent cmake in-source-build friendly (#19151) * pick: Copy resources to "Resources/" on win32 like in linux configuration * add "/Z7" for cpp-tests on windows * [cmake] fix iOS xcode property setting failed (#19208) * fix iOS xcode property setting failed * use search_depend_libs_recursive at dlls collect * fix typo * [cmake] add find_host_library into iOS toolchain file (#19230) * pick: [lua android] use luajit & template cmake update (#19239) * increase cmake stability , remove tests/CMakeLists.txt (#19261) * cmake win32 Precompiled header (#19273) * Precompiled header * Fix * Precompiled header for cocos * Precompiled header jscocos2d * Fix for COCOS2D_DEBUG is always 1 on Android (#19291) Related #19289 * little build fix, tests cpp-tests works on mac * sync v3 build related codes into metal-support (#173) * strict initialization for std::array * remove proj.win32 project configs * modern cmake, cmake_cleanup_remove_unused_variables (#19146) * Switch travis CI to xenial (#19207) * Switch travis CI to xenial * Remove language: android * Set language: cpp * Fix java problem * Update sdkmanager * Fix sdkmanger * next sdkmanager fix * Remove xenial from android * revert to sdk-tools-{system}-3859397 * Remove linux cmake install * Update before-install.sh * Update .travis.yml * Simplify install-deps-linux.sh, tested on Ubuntu 16.04 (#19212) * Simplify install-deps-linux.sh * Cleanup * pick: install ninja * update cocos2d-console submodule * for metal-support alpha release, we only test cpp * add HelloCpp into project(Cocos2d-x) for tmp test * update extenal metal-support-4 * update uniform setting * [Feature] update BindGroup * [Feature] empty-test * [Feature] cpp-test * [Feature] fix GL compiler error * [Feature] fix GL crash * [Feature] empty-test * [Feature] cpp-tests * [feature] improve frameRate * [feature] fix opengl compile error * [feature] fix opengl compile error * [BugFix] fix compute maxLocation error * [Feature] update setting unifrom * [Feature] fix namespace * [Feature] remove unneeded code * [Bugfix] fix project file * [Feature] update review * [texture2d] impl texture format support (#175) * texture update * update * update texture * commit * compile on windows * ddd * rename * rename methods * no crash * save gl * save * save * rename * move out pixel format convert functions * metal crash * update * update android * support gles compressed texture format * support more compress format * add more conversion methods * ss * save * update conversion methods * add PVRTC format support * reformat * add marco linux * fix GL marcro * pvrtc supported only by ios 8.0+ * remove unused cmake * revert change * refactor Texture2D::initWithData * fix conversion log * refactor Texture2D::initWithData * remove some OpenGL constants for PVRTC * add todo * fix typo * AutoTest works on mac/iOS by disable part cases, sync v3 bug fix (#174) * review cpp-tests, and fix part issues on start auto test * sync png format fix: Node:Particle3D abnormal texture effects #19204 * fix cpp-tests SpritePolygon crash, wrong png format (#19170) * fix wrong png convert format from sRGB to Gray * erase plist index if all frames was erased * test_A8.png have I8 format, fix it * [CCSpriteCache] allow re-add plist & add testcase (#19175) * allow re-add plist & add testcase * remove comments/rename method/update testcase * fix isSpriteFramesWithFileLoaded & add testcase * remove used variable * remove unused variable * fix double free issues when js/lua-tests exit on iOS (#19236) * disable part cases, AutoTest works without crash on mac * update cocos2dx files json, to test cocos new next * fix spritecache plist parsing issue (#19269) * [linux] Fix FileUtils::getContents with folder (#19157) * fix FileUtils::getContents on linux/mac * use stat.st_mode * simplify * [CCFileUtils] win32 getFileSize (#19176) * win32 getFileSize * fix stat * [cpp test-Android]20:FileUtils/2 change title (#19197) * sync #19200 * sync #19231 * [android lua] improve performance of lua loader (#19234) * [lua] improve performance of lua loader * remove cache fix * Revert "fix spritecache plist parsing issue (#19269)" This reverts commit f3a85ece4307a7b90816c34489d1ed2c8fd11baf. * remove win32 project files ref in template.json * add metal framework lnk ref into cpp template * test on iOS, and disable part cases * alBufferData instead of alBufferDataStatic for small audio file on Apple (#19227) * changes AudioCache to use alBufferData instead of alBufferDataStatic (also makes test 19 faster to trigger openal bugs faster) The original problem: CrashIfClientProvidedBogusAudioBufferList https://github.com/cocos2d/cocos2d-x/issues/18948 is not happening anymore, but there's still a not very frequent issue that makes OpenAL crash with a call stack like this. AudioCache::readDataTask > alBufferData > CleanUpDeadBufferList It happes more frequently when the device is "cold", which means after half an hour of not using the device (locked). I could not find the actual source code for iOS OpenAL, so I used the macOS versions: https://opensource.apple.com/source/OpenAL/OpenAL-48.7/Source/OpenAL/oalImp.cpp.auto.html They seem to use CAGuard.h to make sure the dead buffer list has no threading issues. I'm worried because the CAGuard code I found has macos and win32 define but no iOS, so I'm not sure. I guess the iOS version is different and has the guard. I could not find a place in the code that's unprotected by the locks except the InitializeBufferMap() which should not be called more than once from cocos, and there's a workaround in AudioEngine-impl for it. I reduced the occurence of the CleanUpDeadBufferList crash by moving the guard in ~AudioCache to cover the alDeleteBuffers call. * remove hack method "setTimeout" on audio * AutoTest works on iOS * support set ios deployment target for root project * enable all texture2d cases, since Jiang have fixed * add CCTextureUtils to xcode project file (#176) * add leak cases for SpriteFrameCache (#177) * re-add SpriteFrameCache cases * update template file json * Update SpriteFrameCacheTest.cpp * fix compiling error
2019-01-18 15:08:25 +08:00
#if (CC_TARGET_PLATFORM == CC_PLATFORM_WIN32)
2016-04-21 11:31:20 +08:00
u_long n = 0;
ioctlsocket(fd, FIONREAD, &n);
#else
int n = 0;
if(ioctl(fd, FIONREAD, &n) < 0)
{
cocos2d::log("Abnormal error in ioctl()\n");
break;
}
2016-04-21 11:31:20 +08:00
#endif
if(n == 0)
2014-02-25 15:52:37 +08:00
{
2016-04-21 11:31:20 +08:00
//no data received, or fd is closed
//fix #18620. readable and no pending data means that the fd is closed.
to_remove.push_back(fd);
2016-04-21 11:31:20 +08:00
continue;
2014-02-25 15:52:37 +08:00
}
2016-04-21 11:31:20 +08:00
if( ! parseCommand(fd) )
2014-02-25 15:52:37 +08:00
{
2016-04-21 11:31:20 +08:00
to_remove.push_back(fd);
2014-02-25 15:52:37 +08:00
}
2016-04-21 11:31:20 +08:00
if(--nready <= 0)
break;
2014-02-25 15:52:37 +08:00
}
2014-02-25 11:47:53 +08:00
}
2016-04-21 11:31:20 +08:00
/* 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())
2014-02-25 11:47:53 +08:00
{
2016-04-21 11:31:20 +08:00
for (const auto &str : _DebugStrings) {
for (auto fd : _fds) {
Console::Utility::sendToConsole(fd, str.c_str(), str.length());
}
}
_DebugStrings.clear();
_DebugStringsMutex.unlock();
2014-02-25 11:47:53 +08:00
}
2014-02-25 11:04:59 +08:00
}
}
2016-04-21 11:31:20 +08:00
// clean up: ignore stdin, stdout and stderr
for(const auto &fd: _fds )
{
metal support for cocos2d-x (#19305) * remove deprecated files * remove some deprecated codes * remove more deprecated codes * remove ui deprecated codes * remove more deprecated codes * remove deprecated codes in ccmenuitem * remove more deprecated codes in ui * remove more deprecated codes in ui * remove more deprecated codes in ui * remove more deprecated codes * remove more deprecated codes * remove more deprecated codes * remove vr related codes and ignore some modules * remove allocator * remove some config * 【Feature】add back-end project file * [Feature] add back-end file * add pipeline descriptor and shader cache * [Feature] support sprite for backend * [Feature] remove unneeded code * [Feature] according to es2.0 spec, you must use clamp-to-edge as texture wrap mode, and no mipmapping for non-power-of-two texture * [Feature] set texture wrap mode to clamp-to-edge, and no mipmapping for non-power-of-two texture * [Feature] remove macro define to .cpp file * [Feature] add log info * [Feature] add PipelineDescriptor for TriangleCommand * [Feature] add PipelineDescriptor object as member of TriangleCommand * [Feature] add getPipelineDescriptor method * add renderbackend * complete pipeline descriptor * [Feature] add viewport in RenderCommand * set viewport when rendrering * [Feature] occur error when using RendererBackend, to be fixed. * a workaround to fix black screen on macOS 10.14 (#19090) * add rendererbackend init function * fix typo * [Feature] modify testFile * [BugFix] modify shader path * [Feature] set default viewport * fix projection * [Feature] modify log info * [BugFix] change viewport data type to int * [BugFix] add BindGroup to PipelienDescriptor * [BugFix] change a_position to vec3 in sprite.vert * [BugFix] set vertexLayout according to V3F_C4B_T2F structure * [Feature] revert a_position to vec4 * [Feature] renderer should not use gl codes directly * [Feature] it's better not use default value parameter * fix depth test setting * rendererbackend -> renderer * clear color and depth at begin * add metal backend * metal support normalized attribute * simplify codes * update external * add render pass desctriptor in pipeline descriptor * fix warnings * fix crash and memeory leak * refactor Texture2D * put pipeline descriptor into render command * simplify codes * [Feature] update Sprite * fix crash when closing app * [Feature] update SpriteBatchNode and TextureAtlas * support render texture(not finish) * [Feature] remove unused code * make tests work on mac * fix download-deps path error * make tests work on iOS * [Feature] support ttf under normal label effect * refactor triangle command processing * let renderer handle more common commands * refactor backend * make render texture work * [Feature] refactor backend for GL * [Feature]Renaming to make it easy to understand * [Feature] change warp mode to CLAMP_TO_EDGE * fix ghost * simplify visit render queue logic * support progress timer without rial mode * support partcile system * Feature/update label (#149) * [BugFix] fix compile error * [Feature] support outline effect in ios * [Feature] add shader file * [BugFix] fix begin and end RenderPass * [Feature] update CustomCommand * [Feature] revert project.pbxproj * [Feature] simplify codes * [BugFix] pack AI88 to RGBA8888 only when outline enable * [Feature] support shadow effect in Label * [Feature] support BMFont * [Feature] support glow effect * [Feature] simplify shader files * LabelAtlas work * handle blend function correctly * support tile map * don't share buffer in metal * alloc buffer size as needed * support more tilemap * Merge branch 'minggo/metal-support' into feature/updateLabel * minggo/metal-support: support tile map handle blend function correctly LabelAtlas work Feature/update label (#149) support partcile system # Conflicts: # cocos/2d/CCLabel.cpp # cocos/2d/CCSprite.cpp # cocos/2d/CCSpriteBatchNode.cpp # cocos/renderer/CCQuadCommand.cpp # cocos/renderer/CCQuadCommand.h * render texture work without saving file * use global viewport * grid3d works * remove grabber * tiled3d works * [BugFix] fix label bug * [Feature] add updateSubData for buffer * [Feature] remove setVertexCount * support depth test * add callback command * [Feature] add UITest * [Feature] update UITest * [Feature] remove unneeded codes * fix custom command issue * fix layer color blend issue * [BugFix] fix iOS compile error * [Feature] remove unneeded codes * [Feature] fix updateVertexBuffer * layerradial works * add draw test back * fix batch issue * fix compiling error * [BugFix] support ETC1 * [BugFix] get the correct pipelineDescriptor * [BugFix] skip draw when backendTexture nullptr * clipping node support * [Feature] add shader files * fix stencil issue in metal * [Feature] update UILayoutTest * [BugFix] skip drawing when vertexCount is zero * refactor renderer * add set global z order for stencil manager commands * fix warnings caused by type * remove viewport in render command * [Feature] fix warnings caused by type * [BugFix] clear vertexCount and indexCount for CustomComand when needed * [Feature] update clear for CustomCommand * ios use metal * fix viewport issue * fix LayerColorGradient crash * [cmake] transport to android and windows (#160) * save point 1 * compile on windows * run on android * revert useless change * android set CC_ENABLE_CACHE_TEXTURE_DATA to 1 * add initGlew * fix android crash * add TODO new-renderer * review update * revert onGLFWWindowPosCallback * fix android compiling error * Impl progress radial (#162) * progresstimer add radial impl * default drawType to element * dec invoke times of createVertexBuffer (#163) * support depth/stencil format for gl backend * simplify progress timer codes * support motionstreak, effect is wrong * fix motionstreak issue * [Feature] update Scissor Test (#161) * [Feature] update Scissor Test * [Feature] update ScissorTest * [Feature] rename function * [Feature] get constant reference if needed * [Feature] show render status (#164) * improve performance * fix depth state * fill error that triangle vertex/index number bigger than buffer * fix compiline error in release mode * fix buffer conflict between CPU and GPU on iOS/macOS * Renderer refactor (#165) * use one vertes/index buffer with opengl * fix error on windows * custom command support index format config * CCLayer: compact vertex data structure * update comment * fix doc * support fast tilemap * pass index format instead * fix some wrong effect * fix render texture error * fix texture per-element size * fix texture format error * BlendFunc type refactor, GLenum -> backend::BlendFactor (#167) * BlendFunc use backend::BlendFactor as inner field * update comments * use int to replace GLenum * update xcode project fiel * rename to GLBlendConst * add ccConstants.h * update xcode project file * update copyright * remove primitive command * remove CCPrimitive.cpp/.h * remove deprecated files * remove unneeded files * remove multiple view support * remove multiple view support * remove the usage of frame buffer in camera * director don't use frame buffer * remove FrameBuffer * remove BatchCommand * add some api reference * add physics2d back * fix crash when close app on mac * improve render texture * fix rendertexture issue * fix rendertexture issue * simplify codes * CMake support for mac & ios (#169) * update cmake * fix compile error * update 3rd libs version * remove CCThread.h/.cpp * remove ccthread * use audio engine to implement simple audio engine * remove unneeded codes * remove deprecated codes * remove winrt macro * remove CC_USE_WIC * set partcile blend function in more elegant way * remove unneeded codes * remove unneeded codes * cmake works on windows * update project setting * improve performance * GLFloat -> float * sync v3 cmake improvements into metal-support (#172) * pick: modern cmake, compile definitions improvement (#19139) * modern cmake, use target_compile_definitions partly * simplify macro define, remove USE_* * modern cmake, macro define * add physics 2d macro define into ccConfig.h * remove USE_CHIPMUNK macro in build.gradle * remove CocosSelectModule.cmake * shrink useless define * simplify compile options config, re-add if necessary * update external for tmp CI test * un-quote target_compile_options value * add "-g" parameter only when debug mode * keep single build type when generator Xcode & VS projecy * update external for tmp CI tes * add static_cast<char>(-1), fix -Wc++11-narrowing * simplify win32 compile define * not modify code, only improve compile options # Conflicts: # .gitignore # cmake/Modules/CocosConfigDepend.cmake # cocos/CMakeLists.txt # external/config.json # tests/cpp-tests/CMakeLists.txt * modern cmake, improve cmake_compiler_flags (#19145) * cmake_compiler_flags * Fix typo * Fix typo2 * Remove chanages from Android.mk * correct lua template cmake build (#19149) * don't add -Wno-deprecated into jsb target * correct lua template cmake build * fix win32 lua template compile error * prevent cmake in-source-build friendly (#19151) * pick: Copy resources to "Resources/" on win32 like in linux configuration * add "/Z7" for cpp-tests on windows * [cmake] fix iOS xcode property setting failed (#19208) * fix iOS xcode property setting failed * use search_depend_libs_recursive at dlls collect * fix typo * [cmake] add find_host_library into iOS toolchain file (#19230) * pick: [lua android] use luajit & template cmake update (#19239) * increase cmake stability , remove tests/CMakeLists.txt (#19261) * cmake win32 Precompiled header (#19273) * Precompiled header * Fix * Precompiled header for cocos * Precompiled header jscocos2d * Fix for COCOS2D_DEBUG is always 1 on Android (#19291) Related #19289 * little build fix, tests cpp-tests works on mac * sync v3 build related codes into metal-support (#173) * strict initialization for std::array * remove proj.win32 project configs * modern cmake, cmake_cleanup_remove_unused_variables (#19146) * Switch travis CI to xenial (#19207) * Switch travis CI to xenial * Remove language: android * Set language: cpp * Fix java problem * Update sdkmanager * Fix sdkmanger * next sdkmanager fix * Remove xenial from android * revert to sdk-tools-{system}-3859397 * Remove linux cmake install * Update before-install.sh * Update .travis.yml * Simplify install-deps-linux.sh, tested on Ubuntu 16.04 (#19212) * Simplify install-deps-linux.sh * Cleanup * pick: install ninja * update cocos2d-console submodule * for metal-support alpha release, we only test cpp * add HelloCpp into project(Cocos2d-x) for tmp test * update extenal metal-support-4 * update uniform setting * [Feature] update BindGroup * [Feature] empty-test * [Feature] cpp-test * [Feature] fix GL compiler error * [Feature] fix GL crash * [Feature] empty-test * [Feature] cpp-tests * [feature] improve frameRate * [feature] fix opengl compile error * [feature] fix opengl compile error * [BugFix] fix compute maxLocation error * [Feature] update setting unifrom * [Feature] fix namespace * [Feature] remove unneeded code * [Bugfix] fix project file * [Feature] update review * [texture2d] impl texture format support (#175) * texture update * update * update texture * commit * compile on windows * ddd * rename * rename methods * no crash * save gl * save * save * rename * move out pixel format convert functions * metal crash * update * update android * support gles compressed texture format * support more compress format * add more conversion methods * ss * save * update conversion methods * add PVRTC format support * reformat * add marco linux * fix GL marcro * pvrtc supported only by ios 8.0+ * remove unused cmake * revert change * refactor Texture2D::initWithData * fix conversion log * refactor Texture2D::initWithData * remove some OpenGL constants for PVRTC * add todo * fix typo * AutoTest works on mac/iOS by disable part cases, sync v3 bug fix (#174) * review cpp-tests, and fix part issues on start auto test * sync png format fix: Node:Particle3D abnormal texture effects #19204 * fix cpp-tests SpritePolygon crash, wrong png format (#19170) * fix wrong png convert format from sRGB to Gray * erase plist index if all frames was erased * test_A8.png have I8 format, fix it * [CCSpriteCache] allow re-add plist & add testcase (#19175) * allow re-add plist & add testcase * remove comments/rename method/update testcase * fix isSpriteFramesWithFileLoaded & add testcase * remove used variable * remove unused variable * fix double free issues when js/lua-tests exit on iOS (#19236) * disable part cases, AutoTest works without crash on mac * update cocos2dx files json, to test cocos new next * fix spritecache plist parsing issue (#19269) * [linux] Fix FileUtils::getContents with folder (#19157) * fix FileUtils::getContents on linux/mac * use stat.st_mode * simplify * [CCFileUtils] win32 getFileSize (#19176) * win32 getFileSize * fix stat * [cpp test-Android]20:FileUtils/2 change title (#19197) * sync #19200 * sync #19231 * [android lua] improve performance of lua loader (#19234) * [lua] improve performance of lua loader * remove cache fix * Revert "fix spritecache plist parsing issue (#19269)" This reverts commit f3a85ece4307a7b90816c34489d1ed2c8fd11baf. * remove win32 project files ref in template.json * add metal framework lnk ref into cpp template * test on iOS, and disable part cases * alBufferData instead of alBufferDataStatic for small audio file on Apple (#19227) * changes AudioCache to use alBufferData instead of alBufferDataStatic (also makes test 19 faster to trigger openal bugs faster) The original problem: CrashIfClientProvidedBogusAudioBufferList https://github.com/cocos2d/cocos2d-x/issues/18948 is not happening anymore, but there's still a not very frequent issue that makes OpenAL crash with a call stack like this. AudioCache::readDataTask > alBufferData > CleanUpDeadBufferList It happes more frequently when the device is "cold", which means after half an hour of not using the device (locked). I could not find the actual source code for iOS OpenAL, so I used the macOS versions: https://opensource.apple.com/source/OpenAL/OpenAL-48.7/Source/OpenAL/oalImp.cpp.auto.html They seem to use CAGuard.h to make sure the dead buffer list has no threading issues. I'm worried because the CAGuard code I found has macos and win32 define but no iOS, so I'm not sure. I guess the iOS version is different and has the guard. I could not find a place in the code that's unprotected by the locks except the InitializeBufferMap() which should not be called more than once from cocos, and there's a workaround in AudioEngine-impl for it. I reduced the occurence of the CleanUpDeadBufferList crash by moving the guard in ~AudioCache to cover the alDeleteBuffers call. * remove hack method "setTimeout" on audio * AutoTest works on iOS * support set ios deployment target for root project * enable all texture2d cases, since Jiang have fixed * add CCTextureUtils to xcode project file (#176) * add leak cases for SpriteFrameCache (#177) * re-add SpriteFrameCache cases * update template file json * Update SpriteFrameCacheTest.cpp * fix compiling error
2019-01-18 15:08:25 +08:00
#if (CC_TARGET_PLATFORM == CC_PLATFORM_WIN32)
2016-04-21 11:31:20 +08:00
closesocket(fd);
#else
close(fd);
#endif
}
metal support for cocos2d-x (#19305) * remove deprecated files * remove some deprecated codes * remove more deprecated codes * remove ui deprecated codes * remove more deprecated codes * remove deprecated codes in ccmenuitem * remove more deprecated codes in ui * remove more deprecated codes in ui * remove more deprecated codes in ui * remove more deprecated codes * remove more deprecated codes * remove more deprecated codes * remove vr related codes and ignore some modules * remove allocator * remove some config * 【Feature】add back-end project file * [Feature] add back-end file * add pipeline descriptor and shader cache * [Feature] support sprite for backend * [Feature] remove unneeded code * [Feature] according to es2.0 spec, you must use clamp-to-edge as texture wrap mode, and no mipmapping for non-power-of-two texture * [Feature] set texture wrap mode to clamp-to-edge, and no mipmapping for non-power-of-two texture * [Feature] remove macro define to .cpp file * [Feature] add log info * [Feature] add PipelineDescriptor for TriangleCommand * [Feature] add PipelineDescriptor object as member of TriangleCommand * [Feature] add getPipelineDescriptor method * add renderbackend * complete pipeline descriptor * [Feature] add viewport in RenderCommand * set viewport when rendrering * [Feature] occur error when using RendererBackend, to be fixed. * a workaround to fix black screen on macOS 10.14 (#19090) * add rendererbackend init function * fix typo * [Feature] modify testFile * [BugFix] modify shader path * [Feature] set default viewport * fix projection * [Feature] modify log info * [BugFix] change viewport data type to int * [BugFix] add BindGroup to PipelienDescriptor * [BugFix] change a_position to vec3 in sprite.vert * [BugFix] set vertexLayout according to V3F_C4B_T2F structure * [Feature] revert a_position to vec4 * [Feature] renderer should not use gl codes directly * [Feature] it's better not use default value parameter * fix depth test setting * rendererbackend -> renderer * clear color and depth at begin * add metal backend * metal support normalized attribute * simplify codes * update external * add render pass desctriptor in pipeline descriptor * fix warnings * fix crash and memeory leak * refactor Texture2D * put pipeline descriptor into render command * simplify codes * [Feature] update Sprite * fix crash when closing app * [Feature] update SpriteBatchNode and TextureAtlas * support render texture(not finish) * [Feature] remove unused code * make tests work on mac * fix download-deps path error * make tests work on iOS * [Feature] support ttf under normal label effect * refactor triangle command processing * let renderer handle more common commands * refactor backend * make render texture work * [Feature] refactor backend for GL * [Feature]Renaming to make it easy to understand * [Feature] change warp mode to CLAMP_TO_EDGE * fix ghost * simplify visit render queue logic * support progress timer without rial mode * support partcile system * Feature/update label (#149) * [BugFix] fix compile error * [Feature] support outline effect in ios * [Feature] add shader file * [BugFix] fix begin and end RenderPass * [Feature] update CustomCommand * [Feature] revert project.pbxproj * [Feature] simplify codes * [BugFix] pack AI88 to RGBA8888 only when outline enable * [Feature] support shadow effect in Label * [Feature] support BMFont * [Feature] support glow effect * [Feature] simplify shader files * LabelAtlas work * handle blend function correctly * support tile map * don't share buffer in metal * alloc buffer size as needed * support more tilemap * Merge branch 'minggo/metal-support' into feature/updateLabel * minggo/metal-support: support tile map handle blend function correctly LabelAtlas work Feature/update label (#149) support partcile system # Conflicts: # cocos/2d/CCLabel.cpp # cocos/2d/CCSprite.cpp # cocos/2d/CCSpriteBatchNode.cpp # cocos/renderer/CCQuadCommand.cpp # cocos/renderer/CCQuadCommand.h * render texture work without saving file * use global viewport * grid3d works * remove grabber * tiled3d works * [BugFix] fix label bug * [Feature] add updateSubData for buffer * [Feature] remove setVertexCount * support depth test * add callback command * [Feature] add UITest * [Feature] update UITest * [Feature] remove unneeded codes * fix custom command issue * fix layer color blend issue * [BugFix] fix iOS compile error * [Feature] remove unneeded codes * [Feature] fix updateVertexBuffer * layerradial works * add draw test back * fix batch issue * fix compiling error * [BugFix] support ETC1 * [BugFix] get the correct pipelineDescriptor * [BugFix] skip draw when backendTexture nullptr * clipping node support * [Feature] add shader files * fix stencil issue in metal * [Feature] update UILayoutTest * [BugFix] skip drawing when vertexCount is zero * refactor renderer * add set global z order for stencil manager commands * fix warnings caused by type * remove viewport in render command * [Feature] fix warnings caused by type * [BugFix] clear vertexCount and indexCount for CustomComand when needed * [Feature] update clear for CustomCommand * ios use metal * fix viewport issue * fix LayerColorGradient crash * [cmake] transport to android and windows (#160) * save point 1 * compile on windows * run on android * revert useless change * android set CC_ENABLE_CACHE_TEXTURE_DATA to 1 * add initGlew * fix android crash * add TODO new-renderer * review update * revert onGLFWWindowPosCallback * fix android compiling error * Impl progress radial (#162) * progresstimer add radial impl * default drawType to element * dec invoke times of createVertexBuffer (#163) * support depth/stencil format for gl backend * simplify progress timer codes * support motionstreak, effect is wrong * fix motionstreak issue * [Feature] update Scissor Test (#161) * [Feature] update Scissor Test * [Feature] update ScissorTest * [Feature] rename function * [Feature] get constant reference if needed * [Feature] show render status (#164) * improve performance * fix depth state * fill error that triangle vertex/index number bigger than buffer * fix compiline error in release mode * fix buffer conflict between CPU and GPU on iOS/macOS * Renderer refactor (#165) * use one vertes/index buffer with opengl * fix error on windows * custom command support index format config * CCLayer: compact vertex data structure * update comment * fix doc * support fast tilemap * pass index format instead * fix some wrong effect * fix render texture error * fix texture per-element size * fix texture format error * BlendFunc type refactor, GLenum -> backend::BlendFactor (#167) * BlendFunc use backend::BlendFactor as inner field * update comments * use int to replace GLenum * update xcode project fiel * rename to GLBlendConst * add ccConstants.h * update xcode project file * update copyright * remove primitive command * remove CCPrimitive.cpp/.h * remove deprecated files * remove unneeded files * remove multiple view support * remove multiple view support * remove the usage of frame buffer in camera * director don't use frame buffer * remove FrameBuffer * remove BatchCommand * add some api reference * add physics2d back * fix crash when close app on mac * improve render texture * fix rendertexture issue * fix rendertexture issue * simplify codes * CMake support for mac & ios (#169) * update cmake * fix compile error * update 3rd libs version * remove CCThread.h/.cpp * remove ccthread * use audio engine to implement simple audio engine * remove unneeded codes * remove deprecated codes * remove winrt macro * remove CC_USE_WIC * set partcile blend function in more elegant way * remove unneeded codes * remove unneeded codes * cmake works on windows * update project setting * improve performance * GLFloat -> float * sync v3 cmake improvements into metal-support (#172) * pick: modern cmake, compile definitions improvement (#19139) * modern cmake, use target_compile_definitions partly * simplify macro define, remove USE_* * modern cmake, macro define * add physics 2d macro define into ccConfig.h * remove USE_CHIPMUNK macro in build.gradle * remove CocosSelectModule.cmake * shrink useless define * simplify compile options config, re-add if necessary * update external for tmp CI test * un-quote target_compile_options value * add "-g" parameter only when debug mode * keep single build type when generator Xcode & VS projecy * update external for tmp CI tes * add static_cast<char>(-1), fix -Wc++11-narrowing * simplify win32 compile define * not modify code, only improve compile options # Conflicts: # .gitignore # cmake/Modules/CocosConfigDepend.cmake # cocos/CMakeLists.txt # external/config.json # tests/cpp-tests/CMakeLists.txt * modern cmake, improve cmake_compiler_flags (#19145) * cmake_compiler_flags * Fix typo * Fix typo2 * Remove chanages from Android.mk * correct lua template cmake build (#19149) * don't add -Wno-deprecated into jsb target * correct lua template cmake build * fix win32 lua template compile error * prevent cmake in-source-build friendly (#19151) * pick: Copy resources to "Resources/" on win32 like in linux configuration * add "/Z7" for cpp-tests on windows * [cmake] fix iOS xcode property setting failed (#19208) * fix iOS xcode property setting failed * use search_depend_libs_recursive at dlls collect * fix typo * [cmake] add find_host_library into iOS toolchain file (#19230) * pick: [lua android] use luajit & template cmake update (#19239) * increase cmake stability , remove tests/CMakeLists.txt (#19261) * cmake win32 Precompiled header (#19273) * Precompiled header * Fix * Precompiled header for cocos * Precompiled header jscocos2d * Fix for COCOS2D_DEBUG is always 1 on Android (#19291) Related #19289 * little build fix, tests cpp-tests works on mac * sync v3 build related codes into metal-support (#173) * strict initialization for std::array * remove proj.win32 project configs * modern cmake, cmake_cleanup_remove_unused_variables (#19146) * Switch travis CI to xenial (#19207) * Switch travis CI to xenial * Remove language: android * Set language: cpp * Fix java problem * Update sdkmanager * Fix sdkmanger * next sdkmanager fix * Remove xenial from android * revert to sdk-tools-{system}-3859397 * Remove linux cmake install * Update before-install.sh * Update .travis.yml * Simplify install-deps-linux.sh, tested on Ubuntu 16.04 (#19212) * Simplify install-deps-linux.sh * Cleanup * pick: install ninja * update cocos2d-console submodule * for metal-support alpha release, we only test cpp * add HelloCpp into project(Cocos2d-x) for tmp test * update extenal metal-support-4 * update uniform setting * [Feature] update BindGroup * [Feature] empty-test * [Feature] cpp-test * [Feature] fix GL compiler error * [Feature] fix GL crash * [Feature] empty-test * [Feature] cpp-tests * [feature] improve frameRate * [feature] fix opengl compile error * [feature] fix opengl compile error * [BugFix] fix compute maxLocation error * [Feature] update setting unifrom * [Feature] fix namespace * [Feature] remove unneeded code * [Bugfix] fix project file * [Feature] update review * [texture2d] impl texture format support (#175) * texture update * update * update texture * commit * compile on windows * ddd * rename * rename methods * no crash * save gl * save * save * rename * move out pixel format convert functions * metal crash * update * update android * support gles compressed texture format * support more compress format * add more conversion methods * ss * save * update conversion methods * add PVRTC format support * reformat * add marco linux * fix GL marcro * pvrtc supported only by ios 8.0+ * remove unused cmake * revert change * refactor Texture2D::initWithData * fix conversion log * refactor Texture2D::initWithData * remove some OpenGL constants for PVRTC * add todo * fix typo * AutoTest works on mac/iOS by disable part cases, sync v3 bug fix (#174) * review cpp-tests, and fix part issues on start auto test * sync png format fix: Node:Particle3D abnormal texture effects #19204 * fix cpp-tests SpritePolygon crash, wrong png format (#19170) * fix wrong png convert format from sRGB to Gray * erase plist index if all frames was erased * test_A8.png have I8 format, fix it * [CCSpriteCache] allow re-add plist & add testcase (#19175) * allow re-add plist & add testcase * remove comments/rename method/update testcase * fix isSpriteFramesWithFileLoaded & add testcase * remove used variable * remove unused variable * fix double free issues when js/lua-tests exit on iOS (#19236) * disable part cases, AutoTest works without crash on mac * update cocos2dx files json, to test cocos new next * fix spritecache plist parsing issue (#19269) * [linux] Fix FileUtils::getContents with folder (#19157) * fix FileUtils::getContents on linux/mac * use stat.st_mode * simplify * [CCFileUtils] win32 getFileSize (#19176) * win32 getFileSize * fix stat * [cpp test-Android]20:FileUtils/2 change title (#19197) * sync #19200 * sync #19231 * [android lua] improve performance of lua loader (#19234) * [lua] improve performance of lua loader * remove cache fix * Revert "fix spritecache plist parsing issue (#19269)" This reverts commit f3a85ece4307a7b90816c34489d1ed2c8fd11baf. * remove win32 project files ref in template.json * add metal framework lnk ref into cpp template * test on iOS, and disable part cases * alBufferData instead of alBufferDataStatic for small audio file on Apple (#19227) * changes AudioCache to use alBufferData instead of alBufferDataStatic (also makes test 19 faster to trigger openal bugs faster) The original problem: CrashIfClientProvidedBogusAudioBufferList https://github.com/cocos2d/cocos2d-x/issues/18948 is not happening anymore, but there's still a not very frequent issue that makes OpenAL crash with a call stack like this. AudioCache::readDataTask > alBufferData > CleanUpDeadBufferList It happes more frequently when the device is "cold", which means after half an hour of not using the device (locked). I could not find the actual source code for iOS OpenAL, so I used the macOS versions: https://opensource.apple.com/source/OpenAL/OpenAL-48.7/Source/OpenAL/oalImp.cpp.auto.html They seem to use CAGuard.h to make sure the dead buffer list has no threading issues. I'm worried because the CAGuard code I found has macos and win32 define but no iOS, so I'm not sure. I guess the iOS version is different and has the guard. I could not find a place in the code that's unprotected by the locks except the InitializeBufferMap() which should not be called more than once from cocos, and there's a workaround in AudioEngine-impl for it. I reduced the occurence of the CleanUpDeadBufferList crash by moving the guard in ~AudioCache to cover the alDeleteBuffers call. * remove hack method "setTimeout" on audio * AutoTest works on iOS * support set ios deployment target for root project * enable all texture2d cases, since Jiang have fixed * add CCTextureUtils to xcode project file (#176) * add leak cases for SpriteFrameCache (#177) * re-add SpriteFrameCache cases * update template file json * Update SpriteFrameCacheTest.cpp * fix compiling error
2019-01-18 15:08:25 +08:00
#if (CC_TARGET_PLATFORM == CC_PLATFORM_WIN32)
2016-04-21 11:31:20 +08:00
closesocket(_listenfd);
WSACleanup();
2014-12-13 00:57:06 +08:00
#else
2016-04-21 11:31:20 +08:00
close(_listenfd);
2014-12-13 00:57:06 +08:00
#endif
2016-04-21 11:31:20 +08:00
_running = false;
2014-12-13 00:57:06 +08:00
}
2016-04-21 11:31:20 +08:00
//
// Helpers
//
2016-04-21 11:31:20 +08:00
ssize_t Console::readline(int fd, char* ptr, size_t maxlen)
{
2016-04-21 11:31:20 +08:00
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;
}
2016-04-21 11:31:20 +08:00
} else if( rc == 0 ) {
return 0;
} else if( errno == EINTR ) {
continue;
2016-04-21 11:31:20 +08:00
} else {
return -1;
}
}
2016-04-21 11:31:20 +08:00
*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;
}
2013-12-05 09:38:11 +08:00
bool Console::parseCommand(int fd)
2013-12-05 08:26:21 +08:00
{
2014-02-18 10:32:32 +08:00
char buf[512];
bool more_data;
auto h = readBytes(fd, buf, 6, &more_data);
if( h < 0)
2014-02-14 14:54:26 +08:00
{
2013-12-05 08:26:21 +08:00
return false;
2014-02-14 14:54:26 +08:00
}
if(strncmp(buf, "upload", 6) == 0)
{
char c = '\0';
recv(fd, &c, 1, 0);
if(c == ' ')
{
commandUpload(fd);
2016-04-21 11:31:20 +08:00
Console::Utility::sendPrompt(fd);
return true;
}
else
{
const char err[] = "upload: invalid args! Type 'help' for options\n";
2016-04-21 11:31:20 +08:00
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";
2016-04-21 11:31:20 +08:00
Console::Utility::sendPrompt(fd);
Console::Utility::sendToConsole(fd, err, strlen(err));
return false;
}
}
2014-02-14 14:54:26 +08:00
std::string cmdLine;
2014-02-18 10:32:32 +08:00
cmdLine = std::string(buf);
auto commands = Console::Utility::split(cmdLine, _commandSeparator);
try {
for(auto command : commands) {
performCommand(fd, Console::Utility::trim(command));
}
} catch (const std::runtime_error& e) {
Console::Utility::sendToConsole(fd, e.what(), strlen(e.what()));
}
2016-04-21 11:31:20 +08:00
Console::Utility::sendPrompt(fd);
return true;
}
void Console::performCommand(int fd, const std::string& command) {
std::vector<std::string> args = Console::Utility::split(command, ' ');
if(args.empty()) {
throw std::runtime_error("Unknown command. Type 'help' for options\n");
2013-12-05 08:26:21 +08:00
}
2016-04-21 11:31:20 +08:00
auto it = _commands.find(Console::Utility::trim(args[0]));
2014-02-14 14:54:26 +08:00
if(it != _commands.end())
{
std::string args2;
for(size_t i = 1; i < args.size(); ++i)
2016-04-21 11:31:20 +08:00
{
2014-02-14 14:54:26 +08:00
if(i > 1)
{
args2 += ' ';
}
2016-04-21 11:31:20 +08:00
args2 += Console::Utility::trim(args[i]);
2014-02-14 14:54:26 +08:00
2013-12-05 09:38:11 +08:00
}
2014-02-14 14:54:26 +08:00
auto cmd = it->second;
cmd->commandGeneric(fd, args2);
} else {
throw std::runtime_error("Unknown command " + command + ". Type 'help' for options\n");
2014-03-05 00:07:30 +08:00
}
2013-12-05 08:26:21 +08:00
}
2016-04-21 11:31:20 +08:00
void Console::addClient()
{
struct sockaddr_in6 ipv6Addr;
struct sockaddr_in ipv4Addr;
struct sockaddr* addr = _isIpv6Server ? (struct sockaddr*)&ipv6Addr : (struct sockaddr*)&ipv4Addr;
socklen_t addrLen = _isIpv6Server ? sizeof(ipv6Addr) : sizeof(ipv4Addr);
2016-04-21 11:31:20 +08:00
2013-12-05 08:26:21 +08:00
/* new client */
int fd = accept(_listenfd, addr, &addrLen);
2016-04-21 11:31:20 +08:00
2013-12-05 08:26:21 +08:00
// add fd to list of FD
if( fd != -1 ) {
FD_SET(fd, &_read_set);
_fds.push_back(fd);
_maxfd = std::max(_maxfd,fd);
2016-04-21 11:31:20 +08:00
Console::Utility::sendPrompt(fd);
2015-05-22 10:35:34 +08:00
/**
2016-04-21 11:31:20 +08:00
* A SIGPIPE is sent to a process if it tried to write to socket that had been shutdown for
2015-05-22 10:35:34 +08:00
* 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.
*/
2015-05-21 18:14:21 +08:00
#if CC_TARGET_PLATFORM == CC_PLATFORM_IOS
int set = 1;
setsockopt(fd, SOL_SOCKET, SO_NOSIGPIPE, (void*)&set, sizeof(int));
#endif
2013-12-05 08:26:21 +08:00
}
}
2016-04-21 11:31:20 +08:00
//
// create commands
//
void Console::createCommandAllocator()
{
2016-04-21 11:31:20 +08:00
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)});
}
2013-12-05 08:26:21 +08:00
//
2016-04-21 11:31:20 +08:00
// commands
2013-12-05 08:26:21 +08:00
//
2016-04-21 11:31:20 +08:00
void Console::commandAllocator(int fd, const std::string& /*args*/)
2013-12-05 08:26:21 +08:00
{
2016-04-21 11:31:20 +08:00
#if CC_ENABLE_ALLOCATOR_DIAGNOSTICS
auto info = allocator::AllocatorDiagnostics::instance()->diagnostics();
Console::Utility::mydprintf(fd, info.c_str());
#else
Console::Utility::mydprintf(fd, "allocator diagnostics not available. CC_ENABLE_ALLOCATOR_DIAGNOSTICS must be set to 1 in ccConfig.h\n");
#endif
}
void Console::commandConfig(int fd, const std::string& /*args*/)
2016-04-21 11:31:20 +08:00
{
Scheduler *sched = Director::getInstance()->getScheduler();
sched->performFunctionInCocosThread( [=](){
Console::Utility::mydprintf(fd, "%s", Configuration::getInstance()->getInfo().c_str());
Console::Utility::sendPrompt(fd);
});
}
2013-12-05 08:26:21 +08:00
void Console::commandDebugMsg(int fd, const std::string& /*args*/)
2016-04-21 11:31:20 +08:00
{
Console::Utility::mydprintf(fd, "Debug message is: %s\n", _sendDebugStrings ? "on" : "off");
}
2013-12-04 10:46:54 +08:00
void Console::commandDebugMsgSubCommandOnOff(int /*fd*/, const std::string& args)
2016-04-21 11:31:20 +08:00
{
_sendDebugStrings = (args.compare("on") == 0);
}
void Console::commandDirectorSubCommandPause(int /*fd*/, const std::string& /*args*/)
2016-04-21 11:31:20 +08:00
{
auto director = Director::getInstance();
Scheduler *sched = director->getScheduler();
sched->performFunctionInCocosThread( [](){
Director::getInstance()->pause();
});
}
void Console::commandDirectorSubCommandResume(int /*fd*/, const std::string& /*args*/)
2016-04-21 11:31:20 +08:00
{
auto director = Director::getInstance();
director->resume();
}
void Console::commandDirectorSubCommandStop(int /*fd*/, const std::string& /*args*/)
2016-04-21 11:31:20 +08:00
{
auto director = Director::getInstance();
Scheduler *sched = director->getScheduler();
sched->performFunctionInCocosThread( [](){
Director::getInstance()->stopAnimation();
});
}
void Console::commandDirectorSubCommandStart(int /*fd*/, const std::string& /*args*/)
2016-04-21 11:31:20 +08:00
{
auto director = Director::getInstance();
director->startAnimation();
}
2013-12-04 10:46:54 +08:00
void Console::commandDirectorSubCommandEnd(int /*fd*/, const std::string& /*args*/)
2016-04-21 11:31:20 +08:00
{
auto director = Director::getInstance();
director->end();
}
void Console::commandExit(int fd, const std::string& /*args*/)
2016-04-21 11:31:20 +08:00
{
FD_CLR(fd, &_read_set);
_fds.erase(std::remove(_fds.begin(), _fds.end(), fd), _fds.end());
metal support for cocos2d-x (#19305) * remove deprecated files * remove some deprecated codes * remove more deprecated codes * remove ui deprecated codes * remove more deprecated codes * remove deprecated codes in ccmenuitem * remove more deprecated codes in ui * remove more deprecated codes in ui * remove more deprecated codes in ui * remove more deprecated codes * remove more deprecated codes * remove more deprecated codes * remove vr related codes and ignore some modules * remove allocator * remove some config * 【Feature】add back-end project file * [Feature] add back-end file * add pipeline descriptor and shader cache * [Feature] support sprite for backend * [Feature] remove unneeded code * [Feature] according to es2.0 spec, you must use clamp-to-edge as texture wrap mode, and no mipmapping for non-power-of-two texture * [Feature] set texture wrap mode to clamp-to-edge, and no mipmapping for non-power-of-two texture * [Feature] remove macro define to .cpp file * [Feature] add log info * [Feature] add PipelineDescriptor for TriangleCommand * [Feature] add PipelineDescriptor object as member of TriangleCommand * [Feature] add getPipelineDescriptor method * add renderbackend * complete pipeline descriptor * [Feature] add viewport in RenderCommand * set viewport when rendrering * [Feature] occur error when using RendererBackend, to be fixed. * a workaround to fix black screen on macOS 10.14 (#19090) * add rendererbackend init function * fix typo * [Feature] modify testFile * [BugFix] modify shader path * [Feature] set default viewport * fix projection * [Feature] modify log info * [BugFix] change viewport data type to int * [BugFix] add BindGroup to PipelienDescriptor * [BugFix] change a_position to vec3 in sprite.vert * [BugFix] set vertexLayout according to V3F_C4B_T2F structure * [Feature] revert a_position to vec4 * [Feature] renderer should not use gl codes directly * [Feature] it's better not use default value parameter * fix depth test setting * rendererbackend -> renderer * clear color and depth at begin * add metal backend * metal support normalized attribute * simplify codes * update external * add render pass desctriptor in pipeline descriptor * fix warnings * fix crash and memeory leak * refactor Texture2D * put pipeline descriptor into render command * simplify codes * [Feature] update Sprite * fix crash when closing app * [Feature] update SpriteBatchNode and TextureAtlas * support render texture(not finish) * [Feature] remove unused code * make tests work on mac * fix download-deps path error * make tests work on iOS * [Feature] support ttf under normal label effect * refactor triangle command processing * let renderer handle more common commands * refactor backend * make render texture work * [Feature] refactor backend for GL * [Feature]Renaming to make it easy to understand * [Feature] change warp mode to CLAMP_TO_EDGE * fix ghost * simplify visit render queue logic * support progress timer without rial mode * support partcile system * Feature/update label (#149) * [BugFix] fix compile error * [Feature] support outline effect in ios * [Feature] add shader file * [BugFix] fix begin and end RenderPass * [Feature] update CustomCommand * [Feature] revert project.pbxproj * [Feature] simplify codes * [BugFix] pack AI88 to RGBA8888 only when outline enable * [Feature] support shadow effect in Label * [Feature] support BMFont * [Feature] support glow effect * [Feature] simplify shader files * LabelAtlas work * handle blend function correctly * support tile map * don't share buffer in metal * alloc buffer size as needed * support more tilemap * Merge branch 'minggo/metal-support' into feature/updateLabel * minggo/metal-support: support tile map handle blend function correctly LabelAtlas work Feature/update label (#149) support partcile system # Conflicts: # cocos/2d/CCLabel.cpp # cocos/2d/CCSprite.cpp # cocos/2d/CCSpriteBatchNode.cpp # cocos/renderer/CCQuadCommand.cpp # cocos/renderer/CCQuadCommand.h * render texture work without saving file * use global viewport * grid3d works * remove grabber * tiled3d works * [BugFix] fix label bug * [Feature] add updateSubData for buffer * [Feature] remove setVertexCount * support depth test * add callback command * [Feature] add UITest * [Feature] update UITest * [Feature] remove unneeded codes * fix custom command issue * fix layer color blend issue * [BugFix] fix iOS compile error * [Feature] remove unneeded codes * [Feature] fix updateVertexBuffer * layerradial works * add draw test back * fix batch issue * fix compiling error * [BugFix] support ETC1 * [BugFix] get the correct pipelineDescriptor * [BugFix] skip draw when backendTexture nullptr * clipping node support * [Feature] add shader files * fix stencil issue in metal * [Feature] update UILayoutTest * [BugFix] skip drawing when vertexCount is zero * refactor renderer * add set global z order for stencil manager commands * fix warnings caused by type * remove viewport in render command * [Feature] fix warnings caused by type * [BugFix] clear vertexCount and indexCount for CustomComand when needed * [Feature] update clear for CustomCommand * ios use metal * fix viewport issue * fix LayerColorGradient crash * [cmake] transport to android and windows (#160) * save point 1 * compile on windows * run on android * revert useless change * android set CC_ENABLE_CACHE_TEXTURE_DATA to 1 * add initGlew * fix android crash * add TODO new-renderer * review update * revert onGLFWWindowPosCallback * fix android compiling error * Impl progress radial (#162) * progresstimer add radial impl * default drawType to element * dec invoke times of createVertexBuffer (#163) * support depth/stencil format for gl backend * simplify progress timer codes * support motionstreak, effect is wrong * fix motionstreak issue * [Feature] update Scissor Test (#161) * [Feature] update Scissor Test * [Feature] update ScissorTest * [Feature] rename function * [Feature] get constant reference if needed * [Feature] show render status (#164) * improve performance * fix depth state * fill error that triangle vertex/index number bigger than buffer * fix compiline error in release mode * fix buffer conflict between CPU and GPU on iOS/macOS * Renderer refactor (#165) * use one vertes/index buffer with opengl * fix error on windows * custom command support index format config * CCLayer: compact vertex data structure * update comment * fix doc * support fast tilemap * pass index format instead * fix some wrong effect * fix render texture error * fix texture per-element size * fix texture format error * BlendFunc type refactor, GLenum -> backend::BlendFactor (#167) * BlendFunc use backend::BlendFactor as inner field * update comments * use int to replace GLenum * update xcode project fiel * rename to GLBlendConst * add ccConstants.h * update xcode project file * update copyright * remove primitive command * remove CCPrimitive.cpp/.h * remove deprecated files * remove unneeded files * remove multiple view support * remove multiple view support * remove the usage of frame buffer in camera * director don't use frame buffer * remove FrameBuffer * remove BatchCommand * add some api reference * add physics2d back * fix crash when close app on mac * improve render texture * fix rendertexture issue * fix rendertexture issue * simplify codes * CMake support for mac & ios (#169) * update cmake * fix compile error * update 3rd libs version * remove CCThread.h/.cpp * remove ccthread * use audio engine to implement simple audio engine * remove unneeded codes * remove deprecated codes * remove winrt macro * remove CC_USE_WIC * set partcile blend function in more elegant way * remove unneeded codes * remove unneeded codes * cmake works on windows * update project setting * improve performance * GLFloat -> float * sync v3 cmake improvements into metal-support (#172) * pick: modern cmake, compile definitions improvement (#19139) * modern cmake, use target_compile_definitions partly * simplify macro define, remove USE_* * modern cmake, macro define * add physics 2d macro define into ccConfig.h * remove USE_CHIPMUNK macro in build.gradle * remove CocosSelectModule.cmake * shrink useless define * simplify compile options config, re-add if necessary * update external for tmp CI test * un-quote target_compile_options value * add "-g" parameter only when debug mode * keep single build type when generator Xcode & VS projecy * update external for tmp CI tes * add static_cast<char>(-1), fix -Wc++11-narrowing * simplify win32 compile define * not modify code, only improve compile options # Conflicts: # .gitignore # cmake/Modules/CocosConfigDepend.cmake # cocos/CMakeLists.txt # external/config.json # tests/cpp-tests/CMakeLists.txt * modern cmake, improve cmake_compiler_flags (#19145) * cmake_compiler_flags * Fix typo * Fix typo2 * Remove chanages from Android.mk * correct lua template cmake build (#19149) * don't add -Wno-deprecated into jsb target * correct lua template cmake build * fix win32 lua template compile error * prevent cmake in-source-build friendly (#19151) * pick: Copy resources to "Resources/" on win32 like in linux configuration * add "/Z7" for cpp-tests on windows * [cmake] fix iOS xcode property setting failed (#19208) * fix iOS xcode property setting failed * use search_depend_libs_recursive at dlls collect * fix typo * [cmake] add find_host_library into iOS toolchain file (#19230) * pick: [lua android] use luajit & template cmake update (#19239) * increase cmake stability , remove tests/CMakeLists.txt (#19261) * cmake win32 Precompiled header (#19273) * Precompiled header * Fix * Precompiled header for cocos * Precompiled header jscocos2d * Fix for COCOS2D_DEBUG is always 1 on Android (#19291) Related #19289 * little build fix, tests cpp-tests works on mac * sync v3 build related codes into metal-support (#173) * strict initialization for std::array * remove proj.win32 project configs * modern cmake, cmake_cleanup_remove_unused_variables (#19146) * Switch travis CI to xenial (#19207) * Switch travis CI to xenial * Remove language: android * Set language: cpp * Fix java problem * Update sdkmanager * Fix sdkmanger * next sdkmanager fix * Remove xenial from android * revert to sdk-tools-{system}-3859397 * Remove linux cmake install * Update before-install.sh * Update .travis.yml * Simplify install-deps-linux.sh, tested on Ubuntu 16.04 (#19212) * Simplify install-deps-linux.sh * Cleanup * pick: install ninja * update cocos2d-console submodule * for metal-support alpha release, we only test cpp * add HelloCpp into project(Cocos2d-x) for tmp test * update extenal metal-support-4 * update uniform setting * [Feature] update BindGroup * [Feature] empty-test * [Feature] cpp-test * [Feature] fix GL compiler error * [Feature] fix GL crash * [Feature] empty-test * [Feature] cpp-tests * [feature] improve frameRate * [feature] fix opengl compile error * [feature] fix opengl compile error * [BugFix] fix compute maxLocation error * [Feature] update setting unifrom * [Feature] fix namespace * [Feature] remove unneeded code * [Bugfix] fix project file * [Feature] update review * [texture2d] impl texture format support (#175) * texture update * update * update texture * commit * compile on windows * ddd * rename * rename methods * no crash * save gl * save * save * rename * move out pixel format convert functions * metal crash * update * update android * support gles compressed texture format * support more compress format * add more conversion methods * ss * save * update conversion methods * add PVRTC format support * reformat * add marco linux * fix GL marcro * pvrtc supported only by ios 8.0+ * remove unused cmake * revert change * refactor Texture2D::initWithData * fix conversion log * refactor Texture2D::initWithData * remove some OpenGL constants for PVRTC * add todo * fix typo * AutoTest works on mac/iOS by disable part cases, sync v3 bug fix (#174) * review cpp-tests, and fix part issues on start auto test * sync png format fix: Node:Particle3D abnormal texture effects #19204 * fix cpp-tests SpritePolygon crash, wrong png format (#19170) * fix wrong png convert format from sRGB to Gray * erase plist index if all frames was erased * test_A8.png have I8 format, fix it * [CCSpriteCache] allow re-add plist & add testcase (#19175) * allow re-add plist & add testcase * remove comments/rename method/update testcase * fix isSpriteFramesWithFileLoaded & add testcase * remove used variable * remove unused variable * fix double free issues when js/lua-tests exit on iOS (#19236) * disable part cases, AutoTest works without crash on mac * update cocos2dx files json, to test cocos new next * fix spritecache plist parsing issue (#19269) * [linux] Fix FileUtils::getContents with folder (#19157) * fix FileUtils::getContents on linux/mac * use stat.st_mode * simplify * [CCFileUtils] win32 getFileSize (#19176) * win32 getFileSize * fix stat * [cpp test-Android]20:FileUtils/2 change title (#19197) * sync #19200 * sync #19231 * [android lua] improve performance of lua loader (#19234) * [lua] improve performance of lua loader * remove cache fix * Revert "fix spritecache plist parsing issue (#19269)" This reverts commit f3a85ece4307a7b90816c34489d1ed2c8fd11baf. * remove win32 project files ref in template.json * add metal framework lnk ref into cpp template * test on iOS, and disable part cases * alBufferData instead of alBufferDataStatic for small audio file on Apple (#19227) * changes AudioCache to use alBufferData instead of alBufferDataStatic (also makes test 19 faster to trigger openal bugs faster) The original problem: CrashIfClientProvidedBogusAudioBufferList https://github.com/cocos2d/cocos2d-x/issues/18948 is not happening anymore, but there's still a not very frequent issue that makes OpenAL crash with a call stack like this. AudioCache::readDataTask > alBufferData > CleanUpDeadBufferList It happes more frequently when the device is "cold", which means after half an hour of not using the device (locked). I could not find the actual source code for iOS OpenAL, so I used the macOS versions: https://opensource.apple.com/source/OpenAL/OpenAL-48.7/Source/OpenAL/oalImp.cpp.auto.html They seem to use CAGuard.h to make sure the dead buffer list has no threading issues. I'm worried because the CAGuard code I found has macos and win32 define but no iOS, so I'm not sure. I guess the iOS version is different and has the guard. I could not find a place in the code that's unprotected by the locks except the InitializeBufferMap() which should not be called more than once from cocos, and there's a workaround in AudioEngine-impl for it. I reduced the occurence of the CleanUpDeadBufferList crash by moving the guard in ~AudioCache to cover the alDeleteBuffers call. * remove hack method "setTimeout" on audio * AutoTest works on iOS * support set ios deployment target for root project * enable all texture2d cases, since Jiang have fixed * add CCTextureUtils to xcode project file (#176) * add leak cases for SpriteFrameCache (#177) * re-add SpriteFrameCache cases * update template file json * Update SpriteFrameCacheTest.cpp * fix compiling error
2019-01-18 15:08:25 +08:00
#if (CC_TARGET_PLATFORM == CC_PLATFORM_WIN32)
2016-04-21 11:31:20 +08:00
closesocket(fd);
#else
2016-04-21 11:31:20 +08:00
close(fd);
#endif
2016-04-21 11:31:20 +08:00
}
void Console::commandFileUtils(int fd, const std::string& /*args*/)
2016-04-21 11:31:20 +08:00
{
Scheduler *sched = Director::getInstance()->getScheduler();
sched->performFunctionInCocosThread( std::bind(&Console::printFileUtils, this, fd) );
}
void Console::commandFileUtilsSubCommandFlush(int /*fd*/, const std::string& /*args*/)
2016-04-21 11:31:20 +08:00
{
FileUtils::getInstance()->purgeCachedEntries();
}
void Console::commandFps(int fd, const std::string& /*args*/)
2016-04-21 11:31:20 +08:00
{
Console::Utility::mydprintf(fd, "FPS is: %s\n", Director::getInstance()->isDisplayStats() ? "on" : "off");
}
void Console::commandFpsSubCommandOnOff(int /*fd*/, const std::string& args)
2016-04-21 11:31:20 +08:00
{
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*/)
2016-04-21 11:31:20 +08:00
{
sendHelp(fd, _commands, "\nAvailable commands:\n");
}
void Console::commandProjection(int fd, const std::string& /*args*/)
2016-04-21 11:31:20 +08:00
{
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*/)
2016-04-21 11:31:20 +08:00
{
auto director = Director::getInstance();
Scheduler *sched = director->getScheduler();
sched->performFunctionInCocosThread( [=](){
director->setProjection(Director::Projection::_2D);
} );
}
void Console::commandProjectionSubCommand3d(int /*fd*/, const std::string& /*args*/)
2016-04-21 11:31:20 +08:00
{
auto director = Director::getInstance();
Scheduler *sched = director->getScheduler();
sched->performFunctionInCocosThread( [=](){
director->setProjection(Director::Projection::_3D);
} );
}
void Console::commandResolution(int /*fd*/, const std::string& args)
2016-04-21 11:31:20 +08:00
{
2019-10-09 17:50:32 +08:00
int policy;
float width, height;
2016-04-21 11:31:20 +08:00
std::istringstream stream( args );
stream >> width >> height>> policy;
Scheduler *sched = Director::getInstance()->getScheduler();
sched->performFunctionInCocosThread( [=](){
Director::getInstance()->getOpenGLView()->setDesignResolutionSize(width, height, static_cast<ResolutionPolicy>(policy));
} );
}
void Console::commandResolutionSubCommandEmpty(int fd, const std::string& /*args*/)
2016-04-21 11:31:20 +08:00
{
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*/)
2016-04-21 11:31:20 +08:00
{
Scheduler *sched = Director::getInstance()->getScheduler();
sched->performFunctionInCocosThread( std::bind(&Console::printSceneGraphBoot, this, fd) );
}
void Console::commandTextures(int fd, const std::string& /*args*/)
2016-04-21 11:31:20 +08:00
{
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*/)
2016-04-21 11:31:20 +08:00
{
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])))
{
2019-10-09 17:50:32 +08:00
float x = (float)utils::atof(argv[1].c_str());
float y = (float)utils::atof(argv[2].c_str());
2016-04-21 11:31:20 +08:00
2016-07-11 11:17:28 +08:00
std::srand ((unsigned)time(nullptr));
2016-04-21 11:31:20 +08:00
_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])))
{
2019-10-09 17:50:32 +08:00
float x1 = (float)utils::atof(argv[1].c_str());
float y1 = (float)utils::atof(argv[2].c_str());
float x2 = (float)utils::atof(argv[3].c_str());
float y2 = (float)utils::atof(argv[4].c_str());
2016-04-21 11:31:20 +08:00
2016-07-11 11:17:28 +08:00
std::srand ((unsigned)time(nullptr));
2016-04-21 11:31:20 +08:00
_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;
2013-12-05 08:26:21 +08:00
}
2016-04-21 11:31:20 +08:00
if(y1 > y2)
{
_y_ -= dy/dx;
}
sched->performFunctionInCocosThread( [=](){
float tempx = _x_, tempy = _y_;
Director::getInstance()->getOpenGLView()->handleTouchesMove(1, &_touchId, &tempx, &tempy);
});
dx -= 1;
}
2016-04-21 11:31:20 +08:00
}
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;
2013-12-04 10:46:54 +08:00
}
2016-04-21 11:31:20 +08:00
2013-12-04 10:46:54 +08:00
}
2016-04-21 11:31:20 +08:00
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));
}
}
2013-12-05 08:26:21 +08:00
2016-04-21 11:31:20 +08:00
static char invalid_filename_char[] = {':', '/', '\\', '?', '%', '*', '<', '>', '"', '|', '\r', '\n', '\t'};
void Console::commandUpload(int fd)
{
ssize_t n, rc;
char buf[512] = {0};
char c = 0;
2016-04-21 11:31:20 +08:00
char *ptr = buf;
//read file name
for( n = 0; n < sizeof(buf) - 1; n++ )
{
if( (rc = recv(fd, &c, 1, 0)) == 1 )
2016-04-21 11:31:20 +08:00
{
for(char x : invalid_filename_char)
2015-05-19 18:33:06 +08:00
{
if (c == x)
2016-04-21 11:31:20 +08:00
{
const char err[] = "upload: invalid file name!\n";
Console::Utility::sendToConsole(fd, err, strlen(err));
return;
}
}
if (c == ' ')
2016-04-21 11:31:20 +08:00
{
break;
}
*ptr++ = c;
}
else if( rc == 0 )
{
break;
}
else if( errno == EINTR )
{
continue;
}
else
{
break;
2013-12-05 08:26:21 +08:00
}
}
2016-04-21 11:31:20 +08:00
*ptr = 0;
2016-04-21 11:31:20 +08:00
static std::string writablePath = FileUtils::getInstance()->getWritablePath();
std::string filepath = writablePath + std::string(buf);
FILE* fp = fopen(filepath.c_str(), "wb");
2016-04-21 11:31:20 +08:00
if(!fp)
2014-02-24 14:24:14 +08:00
{
2016-04-21 11:31:20 +08:00
const char err[] = "can't create file!\n";
Console::Utility::sendToConsole(fd, err, strlen(err));
return;
2014-02-24 14:24:14 +08:00
}
while (true)
2016-04-21 11:31:20 +08:00
{
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);
if (dt > 0)
2016-04-21 11:31:20 +08:00
{
fwrite(decode, dt, 1, fp);
2016-04-21 11:31:20 +08:00
}
free(decode);
}
fclose(fp);
}
2013-12-05 16:09:38 +08:00
void Console::commandVersion(int fd, const std::string& /*args*/)
2014-12-24 02:04:42 +08:00
{
2016-04-21 11:31:20 +08:00
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; i<level; ++i)
Console::Utility::sendToConsole(fd, "-", 1);
Console::Utility::mydprintf(fd, " %s\n", node->getDescription().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::unordered_map<std::string, Command*>& commands, const char* msg)
2016-04-21 11:31:20 +08:00
{
Console::Utility::sendToConsole(fd, msg, strlen(msg));
for(auto& it : commands)
2016-04-21 11:31:20 +08:00
{
auto command = it.second;
if (command->getHelp().empty()) continue;
2016-04-21 11:31:20 +08:00
Console::Utility::mydprintf(fd, "\t%s", command->getName().c_str());
ssize_t tabs = strlen(command->getName().c_str()) / 8;
2016-04-21 11:31:20 +08:00
tabs = 3 - tabs;
for(int j=0;j<tabs;j++){
Console::Utility::mydprintf(fd, "\t");
}
Console::Utility::mydprintf(fd,"%s\n", command->getHelp().c_str());
2016-04-21 11:31:20 +08:00
}
2014-12-24 02:04:42 +08:00
}
2013-12-05 16:09:38 +08:00
NS_CC_END