diff --git a/native/cocos/storage/local-storage/LocalStorage-android.cpp b/native/cocos/storage/local-storage/LocalStorage-android.cpp index 46d75c8b01..ee8dd14cec 100644 --- a/native/cocos/storage/local-storage/LocalStorage-android.cpp +++ b/native/cocos/storage/local-storage/LocalStorage-android.cpp @@ -28,7 +28,7 @@ Works on cocos2d-iphone and cocos2d-x. */ -#include "LocalStorage.h" +#include "storage/local-storage/LocalStorage.h" #include "platform/CCPlatformMacros.h" #if (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID) @@ -37,13 +37,12 @@ #include #include #include "jni.h" -#include "jni/JniHelper.h" -#include "base/ccUTF8.h" +#include "platform/android/jni/JniHelper.h" USING_NS_CC; static int _initialized = 0; -#define STORAGE_JAVA_CLASS "org/cocos2dx/lib/Cocos2dxLocalStorage" +static std::string className = "org/cocos2dx/lib/Cocos2dxLocalStorage"; static void splitFilename (std::string& str) { @@ -64,7 +63,7 @@ void localStorageInit( const std::string& fullpath) { std::string strDBFilename = fullpath; splitFilename(strDBFilename); - if (JniHelper::callStaticBooleanMethod(STORAGE_JAVA_CLASS, "init", strDBFilename, "data")) { + if (JniHelper::callStaticBooleanMethod(className, "init", strDBFilename, "data")) { _initialized = 1; } } @@ -72,8 +71,8 @@ void localStorageInit( const std::string& fullpath) void localStorageFree() { - if( _initialized ) { - JniHelper::callStaticVoidMethod(STORAGE_JAVA_CLASS, "destory"); + if (_initialized) { + JniHelper::callStaticVoidMethod(className, "destroy"); _initialized = 0; } } @@ -82,7 +81,7 @@ void localStorageFree() void localStorageSetItem( const std::string& key, const std::string& value) { assert( _initialized ); - JniHelper::callStaticVoidMethod(STORAGE_JAVA_CLASS, "setItem", key, value); + JniHelper::callStaticVoidMethod(className, "setItem", key, value); } /** gets an item from the LS */ @@ -93,7 +92,7 @@ bool localStorageGetItem( const std::string& key, std::string *outItem ) if (JniHelper::getStaticMethodInfo(t, "org/cocos2dx/lib/Cocos2dxLocalStorage", "getItem", "(Ljava/lang/String;)Ljava/lang/String;")) { - jstring jkey = JniHelper::newStringUTFJNI(t.env, key); + jstring jkey = t.env->NewStringUTF(key.c_str()); jstring jret = (jstring)t.env->CallStaticObjectMethod(t.classID, t.methodID, jkey); if (jret == nullptr) { @@ -104,8 +103,7 @@ bool localStorageGetItem( const std::string& key, std::string *outItem ) } else { - auto value = JniHelper::jstring2string(jret); - outItem->assign(value); + outItem->assign(JniHelper::jstring2string(jret)); t.env->DeleteLocalRef(jret); t.env->DeleteLocalRef(jkey); t.env->DeleteLocalRef(t.classID); @@ -122,16 +120,14 @@ bool localStorageGetItem( const std::string& key, std::string *outItem ) void localStorageRemoveItem( const std::string& key ) { assert( _initialized ); - JniHelper::callStaticVoidMethod(STORAGE_JAVA_CLASS, "removeItem", key); - + JniHelper::callStaticVoidMethod(className, "removeItem", key); } /** removes all items from the LS */ void localStorageClear() { assert( _initialized ); - JniHelper::callStaticVoidMethod(STORAGE_JAVA_CLASS, "clear"); + JniHelper::callStaticVoidMethod(className, "clear"); } #endif // #if (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID) - diff --git a/native/cocos/storage/local-storage/LocalStorage.cpp b/native/cocos/storage/local-storage/LocalStorage.cpp index c4228d56f2..5ca507e09b 100644 --- a/native/cocos/storage/local-storage/LocalStorage.cpp +++ b/native/cocos/storage/local-storage/LocalStorage.cpp @@ -27,7 +27,7 @@ Works on cocos2d-iphone and cocos2d-x. */ -#include "LocalStorage.h" +#include "storage/local-storage/LocalStorage.h" #include "platform/CCPlatformMacros.h" #if (CC_TARGET_PLATFORM != CC_PLATFORM_ANDROID) @@ -35,14 +35,10 @@ #include #include #include -#if (CC_TARGET_PLATFORM != CC_PLATFORM_WIN32) #include -#else -#include "sqlite3/sqlite3.h" -#endif -static bool s_sqlite3Initialized = false; -static sqlite3 *s_sqlite3DB; +static int _initialized = 0; +static sqlite3 *_db; static sqlite3_stmt *_stmt_select; static sqlite3_stmt *_stmt_remove; static sqlite3_stmt *_stmt_update; @@ -53,7 +49,7 @@ static void localStorageCreateTable() { const char *sql_createtable = "CREATE TABLE IF NOT EXISTS data(key TEXT PRIMARY KEY,value TEXT);"; sqlite3_stmt *stmt; - int ok = sqlite3_prepare_v2(s_sqlite3DB, sql_createtable, -1, &stmt, nullptr); + int ok = sqlite3_prepare_v2(_db, sql_createtable, -1, &stmt, nullptr); ok |= sqlite3_step(stmt); ok |= sqlite3_finalize(stmt); @@ -63,61 +59,60 @@ static void localStorageCreateTable() void localStorageInit( const std::string& fullpath/* = "" */) { - if( ! s_sqlite3Initialized ) { + if (!_initialized) { int ret = 0; if (fullpath.empty()) - ret = sqlite3_open(":memory:",&s_sqlite3DB); + ret = sqlite3_open(":memory:", &_db); else - ret = sqlite3_open(fullpath.c_str(), &s_sqlite3DB); + ret = sqlite3_open(fullpath.c_str(), &_db); localStorageCreateTable(); // SELECT const char *sql_select = "SELECT value FROM data WHERE key=?;"; - ret |= sqlite3_prepare_v2(s_sqlite3DB, sql_select, -1, &_stmt_select, nullptr); + ret |= sqlite3_prepare_v2(_db, sql_select, -1, &_stmt_select, nullptr); // REPLACE const char *sql_update = "REPLACE INTO data (key, value) VALUES (?,?);"; - ret |= sqlite3_prepare_v2(s_sqlite3DB, sql_update, -1, &_stmt_update, nullptr); + ret |= sqlite3_prepare_v2(_db, sql_update, -1, &_stmt_update, nullptr); // DELETE const char *sql_remove = "DELETE FROM data WHERE key=?;"; - ret |= sqlite3_prepare_v2(s_sqlite3DB, sql_remove, -1, &_stmt_remove, nullptr); - + ret |= sqlite3_prepare_v2(_db, sql_remove, -1, &_stmt_remove, nullptr); + // Clear const char *sql_clear = "DELETE FROM data;"; - ret |= sqlite3_prepare_v2(s_sqlite3DB, sql_clear, -1, &_stmt_clear, nullptr); + ret |= sqlite3_prepare_v2(_db, sql_clear, -1, &_stmt_clear, nullptr); if( ret != SQLITE_OK ) { printf("Error initializing DB\n"); // report error } - - s_sqlite3Initialized = true; + + _initialized = 1; } } void localStorageFree() { - if( s_sqlite3Initialized ) { + if (_initialized) { sqlite3_finalize(_stmt_select); sqlite3_finalize(_stmt_remove); sqlite3_finalize(_stmt_update); - sqlite3_close(s_sqlite3DB); - s_sqlite3DB = nullptr; - - s_sqlite3Initialized = false; + sqlite3_close(_db); + + _initialized = 0; } } /** sets an item in the LS */ void localStorageSetItem( const std::string& key, const std::string& value) { - assert( s_sqlite3Initialized ); - + assert( _initialized ); + int ok = sqlite3_bind_text(_stmt_update, 1, key.c_str(), -1, SQLITE_TRANSIENT); ok |= sqlite3_bind_text(_stmt_update, 2, value.c_str(), -1, SQLITE_TRANSIENT); @@ -132,7 +127,7 @@ void localStorageSetItem( const std::string& key, const std::string& value) /** gets an item from the LS */ bool localStorageGetItem( const std::string& key, std::string *outItem ) { - assert( s_sqlite3Initialized ); + assert( _initialized ); int ok = sqlite3_reset(_stmt_select); @@ -159,7 +154,7 @@ bool localStorageGetItem( const std::string& key, std::string *outItem ) /** removes an item from the LS */ void localStorageRemoveItem( const std::string& key ) { - assert( s_sqlite3Initialized ); + assert( _initialized ); int ok = sqlite3_bind_text(_stmt_remove, 1, key.c_str(), -1, SQLITE_TRANSIENT); @@ -174,8 +169,8 @@ void localStorageRemoveItem( const std::string& key ) /** removes all items from the LS */ void localStorageClear() { - assert( s_sqlite3Initialized ); - + assert( _initialized ); + int ok = sqlite3_step(_stmt_clear); ok |= sqlite3_reset(_stmt_clear); @@ -185,4 +180,3 @@ void localStorageClear() } #endif // #if (CC_TARGET_PLATFORM != CC_PLATFORM_ANDROID) - diff --git a/native/cocos/storage/local-storage/LocalStorage.h b/native/cocos/storage/local-storage/LocalStorage.h index f89cd7c47c..2bb0f766e8 100644 --- a/native/cocos/storage/local-storage/LocalStorage.h +++ b/native/cocos/storage/local-storage/LocalStorage.h @@ -58,4 +58,3 @@ void CC_DLL localStorageClear(); /// @} #endif // __JSB_LOCALSTORAGE_H - diff --git a/native/extensions/ExtensionExport.h b/native/extensions/ExtensionExport.h index 6138c0a9c7..56d5c152d7 100644 --- a/native/extensions/ExtensionExport.h +++ b/native/extensions/ExtensionExport.h @@ -24,6 +24,8 @@ #define NULL ((void *)0) #endif #endif +#elif defined(_SHARED_) + #define CC_EX_DLL __attribute__((visibility("default"))) #else #define CC_EX_DLL #endif diff --git a/native/extensions/GUI/CCControlExtension/CCControl.cpp b/native/extensions/GUI/CCControlExtension/CCControl.cpp index ba0a198e10..d31775617c 100644 --- a/native/extensions/GUI/CCControlExtension/CCControl.cpp +++ b/native/extensions/GUI/CCControlExtension/CCControl.cpp @@ -73,7 +73,7 @@ bool Control::init() setSelected(false); setHighlighted(false); - auto dispatcher = _director->getEventDispatcher(); + auto dispatcher = Director::getInstance()->getEventDispatcher(); auto touchListener = EventListenerTouchOneByOne::create(); touchListener->setSwallowTouches(true); touchListener->onTouchBegan = CC_CALLBACK_2(Control::onTouchBegan, this); @@ -119,11 +119,11 @@ void Control::sendActionsForControlEvents(EventType controlEvents) #if CC_ENABLE_SCRIPT_BINDING //Call ScriptFunc - if (kScriptTypeLua == _scriptType && cocos2d::ScriptEngineManager::ShareInstance) + if (kScriptTypeLua == _scriptType) { cocos2d::BasicScriptData data(this,(void*)&controlEvents); cocos2d::ScriptEvent event(cocos2d::kControlEvent,(void*)&data); - cocos2d::ScriptEngineManager::ShareInstance->getScriptEngine()->sendEvent(&event); + cocos2d::ScriptEngineManager::getInstance()->getScriptEngine()->sendEvent(&event); } #endif } diff --git a/native/extensions/GUI/CCControlExtension/CCControl.h b/native/extensions/GUI/CCControlExtension/CCControl.h index 046b642c6b..3861c9b4d8 100644 --- a/native/extensions/GUI/CCControlExtension/CCControl.h +++ b/native/extensions/GUI/CCControlExtension/CCControl.h @@ -84,7 +84,7 @@ public: /** The possible state for a control. */ enum class State { - NORMAL = 1 << 0, // The normal, or default state of a control¡ªthat is, enabled but neither selected nor highlighted. + NORMAL = 1 << 0, // The normal, or default state of a control。ェthat is, enabled but neither selected nor highlighted. HIGH_LIGHTED = 1 << 1, // Highlighted state of a control. A control enters this state when a touch down, drag inside or drag enter is performed. You can retrieve and set this value through the highlighted property. DISABLED = 1 << 2, // Disabled state of a control. This state indicates that the control is currently disabled. You can retrieve and set this value through the enabled property. SELECTED = 1 << 3 // Selected state of a control. This state indicates that the control is currently selected. You can retrieve and set this value through the selected property. @@ -138,7 +138,7 @@ public: * Removes a target and action for a particular event (or events) from an * internal dispatch table. * - * @param target The target object—that is, the object to which the action + * @param target The target object葉hat is, the object to which the action * message is sent. Pass nil to remove all targets paired with action and the * specified control events. * @param action A selector identifying an action message. Pass NULL to remove @@ -155,11 +155,11 @@ public: */ virtual Vec2 getTouchLocation(Touch* touch); - virtual bool onTouchBegan(Touch *touch, Event *event) { return false; }; - virtual void onTouchMoved(Touch *touch, Event *event) {}; - virtual void onTouchEnded(Touch *touch, Event *event) {}; - virtual void onTouchCancelled(Touch *touch, Event *event) {}; - + virtual bool onTouchBegan(Touch *touch, Event *event) override { return false; }; + virtual void onTouchMoved(Touch *touch, Event *event) override {}; + virtual void onTouchEnded(Touch *touch, Event *event) override {}; + virtual void onTouchCancelled(Touch *touch, Event *event) override {}; + /** * Returns a boolean value that indicates whether a touch is inside the bounds * of the receiver. The given touch must be relative to the world. @@ -185,7 +185,7 @@ CC_CONSTRUCTOR_ACCESS: */ virtual ~Control(); - virtual bool init() override; + virtual bool init(void) override; protected: /** @@ -221,7 +221,7 @@ protected: * parameters, in that order. * When you call this method, target is not retained. * - * @param target The target object¡ªthat is, the object to which the action + * @param target The target object。ェthat is, the object to which the action * message is sent. It cannot be nil. The target is not retained. * @param action A selector identifying an action message. It cannot be NULL. * @param controlEvent A control event for which the action message is sent. @@ -233,7 +233,7 @@ protected: * Removes a target and action for a particular event from an internal dispatch * table. * - * @param target The target object¡ªthat is, the object to which the action + * @param target The target object。ェthat is, the object to which the action * message is sent. Pass nil to remove all targets paired with action and the * specified control events. * @param action A selector identifying an action message. Pass NULL to remove @@ -276,4 +276,3 @@ CC_EX_DLL Control::EventType operator|(Control::EventType a, Control::EventType NS_CC_EXT_END #endif - diff --git a/native/extensions/GUI/CCControlExtension/CCControlButton.cpp b/native/extensions/GUI/CCControlExtension/CCControlButton.cpp index e9ebe9b27e..3684f5b34e 100644 --- a/native/extensions/GUI/CCControlExtension/CCControlButton.cpp +++ b/native/extensions/GUI/CCControlExtension/CCControlButton.cpp @@ -94,7 +94,7 @@ bool ControlButton::initWithLabelAndBackgroundSprite(Node* node, ui::Scale9Sprit _scaleRatio = 1.1f; // Set the default anchor point - ignoreAnchorPointForPosition(false); + setIgnoreAnchorPointForPosition(false); setAnchorPoint(Vec2::ANCHOR_MIDDLE); // Set the nodes @@ -228,7 +228,7 @@ void ControlButton::setZoomOnTouchDown(bool zoomOnTouchDown) _zoomOnTouchDown = zoomOnTouchDown; } -bool ControlButton::getZoomOnTouchDown() +bool ControlButton::getZoomOnTouchDown() const { return _zoomOnTouchDown; } @@ -753,4 +753,3 @@ ControlButton* ControlButton::create() } NS_CC_EXT_END - diff --git a/native/extensions/GUI/CCControlExtension/CCControlButton.h b/native/extensions/GUI/CCControlExtension/CCControlButton.h index 97bfaff628..924ff6c5bf 100644 --- a/native/extensions/GUI/CCControlExtension/CCControlButton.h +++ b/native/extensions/GUI/CCControlExtension/CCControlButton.h @@ -60,7 +60,7 @@ public: static ControlButton* create(const std::string& title, const std::string& fontName, float fontSize); static ControlButton* create(Node* label, cocos2d::ui::Scale9Sprite* backgroundSprite, bool adjustBackGroundSize); - virtual void needsLayout() override; + virtual void needsLayout(void) override; virtual void setEnabled(bool enabled) override; virtual void setSelected(bool enabled) override; diff --git a/native/extensions/GUI/CCControlExtension/CCControlColourPicker.cpp b/native/extensions/GUI/CCControlExtension/CCControlColourPicker.cpp index 2eb53f5a6c..577b5a4156 100644 --- a/native/extensions/GUI/CCControlExtension/CCControlColourPicker.cpp +++ b/native/extensions/GUI/CCControlExtension/CCControlColourPicker.cpp @@ -76,7 +76,7 @@ bool ControlColourPicker::init() _hsv.v = 0; // Add image - _background=ControlUtils::addSpriteToTargetWithPosAndAnchor("menuColourPanelBackground.png", spriteSheet, Vec2::ZERO, Vec2::ANCHOR_MIDDLE); + _background=ControlUtils::addSpriteToTargetWithPosAndAnchor("menuColourPanelBackground.png", spriteSheet, Vec2::ZERO, Vec2(0.5f, 0.5f)); if(!_background) return false; CC_SAFE_RETAIN(_background); diff --git a/native/extensions/GUI/CCControlExtension/CCControlSlider.cpp b/native/extensions/GUI/CCControlExtension/CCControlSlider.cpp index ee25fdd3c3..f7b6455e15 100644 --- a/native/extensions/GUI/CCControlExtension/CCControlSlider.cpp +++ b/native/extensions/GUI/CCControlExtension/CCControlSlider.cpp @@ -126,7 +126,7 @@ bool ControlSlider::initWithSprites(Sprite * backgroundSprite, Sprite* progressS return false; } - ignoreAnchorPointForPosition(false); + setIgnoreAnchorPointForPosition(false); this->setBackgroundSprite(backgroundSprite); this->setProgressSprite(progressSprite); diff --git a/native/extensions/GUI/CCControlExtension/CCControlStepper.cpp b/native/extensions/GUI/CCControlExtension/CCControlStepper.cpp index 78e303639c..41f0979143 100644 --- a/native/extensions/GUI/CCControlExtension/CCControlStepper.cpp +++ b/native/extensions/GUI/CCControlExtension/CCControlStepper.cpp @@ -85,8 +85,8 @@ bool ControlStepper::initWithMinusSpriteAndPlusSprite(Sprite *minusSprite, Sprit _value = 0; _stepValue = 1; _wraps = false; - this->ignoreAnchorPointForPosition( false ); - + this->setIgnoreAnchorPointForPosition( false ); + // Add the minus components this->setMinusSprite(minusSprite); _minusSprite->setPosition(minusSprite->getContentSize().width / 2, minusSprite->getContentSize().height / 2); @@ -152,7 +152,6 @@ void ControlStepper::setMinimumValue(double minimumValue) if (minimumValue >= _maximumValue) { CCASSERT(0, "Must be numerically less than maximumValue."); - minimumValue = _maximumValue; } _minimumValue = minimumValue; @@ -164,7 +163,6 @@ void ControlStepper::setMaximumValue(double maximumValue) if (maximumValue <= _minimumValue) { CCASSERT(0, "Must be numerically greater than minimumValue."); - maximumValue = _minimumValue; } _maximumValue = maximumValue; diff --git a/native/extensions/GUI/CCControlExtension/CCControlSwitch.h b/native/extensions/GUI/CCControlExtension/CCControlSwitch.h index 07bb936653..29f9ee8573 100644 --- a/native/extensions/GUI/CCControlExtension/CCControlSwitch.h +++ b/native/extensions/GUI/CCControlExtension/CCControlSwitch.h @@ -79,7 +79,7 @@ public: */ void setOn(bool isOn, bool animated); void setOn(bool isOn); - bool isOn() const { return _on; } + bool isOn(void) const { return _on; } bool hasMoved() const { return _moved; } virtual void setEnabled(bool enabled) override; diff --git a/native/extensions/GUI/CCControlExtension/CCControlUtils.cpp b/native/extensions/GUI/CCControlExtension/CCControlUtils.cpp index 60c6f4a67f..4fc297d9cd 100644 --- a/native/extensions/GUI/CCControlExtension/CCControlUtils.cpp +++ b/native/extensions/GUI/CCControlExtension/CCControlUtils.cpp @@ -91,9 +91,9 @@ RGBA ControlUtils::RGBfromHSV(HSV value) out.a = 1; if (value.s <= 0.0) // < is bogus, just shuts up warnings - { - if (isnan(value.h)) // value.h == NAN - { + { + if (std::isnan(value.h)) // value.h == NAN + { out.r = value.v; out.g = value.v; out.b = value.v; diff --git a/native/extensions/GUI/CCScrollView/CCScrollView.cpp b/native/extensions/GUI/CCScrollView/CCScrollView.cpp index 385b62ddc9..cb4378d5ff 100644 --- a/native/extensions/GUI/CCScrollView/CCScrollView.cpp +++ b/native/extensions/GUI/CCScrollView/CCScrollView.cpp @@ -45,7 +45,7 @@ NS_CC_EXT_BEGIN static float convertDistanceFromPointToInch(float pointDis) { - auto glview = Director::DirectorInstance->getOpenGLView(); + auto glview = Director::getInstance()->getOpenGLView(); float factor = ( glview->getScaleX() + glview->getScaleY() ) / 2; return pointDis * factor / Device::getDPI(); } @@ -112,7 +112,7 @@ bool ScrollView::initWithViewSize(const Size& size, Node *container/* = nullptr* if (!this->_container) { _container = Layer::create(); - _container->ignoreAnchorPointForPosition(false); + _container->setIgnoreAnchorPointForPosition(false); _container->setAnchorPoint(Vec2::ANCHOR_BOTTOM_LEFT); } @@ -347,7 +347,7 @@ void ScrollView::setContainer(Node * pContainer) this->removeAllChildrenWithCleanup(true); this->_container = pContainer; - this->_container->ignoreAnchorPointForPosition(false); + this->_container->setIgnoreAnchorPointForPosition(false); this->_container->setAnchorPoint(Vec2::ANCHOR_BOTTOM_LEFT); this->addChild(this->_container); @@ -560,7 +560,7 @@ void ScrollView::beforeDraw() //ScrollView don't support drawing in 3D space _beforeDrawCommand.init(_globalZOrder); _beforeDrawCommand.func = CC_CALLBACK_0(ScrollView::onBeforeDraw, this); - _director->getRenderer()->addCommand(&_beforeDrawCommand); + Director::getInstance()->getRenderer()->addCommand(&_beforeDrawCommand); } /** @@ -572,7 +572,7 @@ void ScrollView::onBeforeDraw() { _scissorRestored = false; Rect frame = getViewRect(); - auto glview = _director->getOpenGLView(); + auto glview = Director::getInstance()->getOpenGLView(); if (glview->isScissorEnabled()) { _scissorRestored = true; @@ -597,7 +597,7 @@ void ScrollView::afterDraw() { _afterDrawCommand.init(_globalZOrder); _afterDrawCommand.func = CC_CALLBACK_0(ScrollView::onAfterDraw, this); - _director->getRenderer()->addCommand(&_afterDrawCommand); + Director::getInstance()->getRenderer()->addCommand(&_afterDrawCommand); } /** @@ -609,7 +609,7 @@ void ScrollView::onAfterDraw() if (_clippingToBounds) { if (_scissorRestored) {//restore the parent's scissor rect - auto glview = _director->getOpenGLView(); + auto glview = Director::getInstance()->getOpenGLView(); glview->setScissorInPoints(_parentScissorRect.origin.x, _parentScissorRect.origin.y, _parentScissorRect.size.width, _parentScissorRect.size.height); } @@ -632,9 +632,10 @@ void ScrollView::visit(Renderer *renderer, const Mat4 &parentTransform, uint32_t // IMPORTANT: // To ease the migration to v3.0, we still support the Mat4 stack, // but it is deprecated and your code should not rely on it - CCASSERT(nullptr != _director, "Director is null when seting matrix stack"); - _director->pushMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW); - _director->loadMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW, _modelViewTransform); + Director* director = Director::getInstance(); + CCASSERT(nullptr != director, "Director is null when setting matrix stack"); + director->pushMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW); + director->loadMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW, _modelViewTransform); this->beforeDraw(); @@ -673,7 +674,7 @@ void ScrollView::visit(Renderer *renderer, const Mat4 &parentTransform, uint32_t this->afterDraw(); - _director->popMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW); + director->popMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW); } bool ScrollView::onTouchBegan(Touch* touch, Event* event) diff --git a/native/extensions/GUI/CCScrollView/CCScrollView.h b/native/extensions/GUI/CCScrollView/CCScrollView.h index 7fc8ce7748..a49e1fd540 100644 --- a/native/extensions/GUI/CCScrollView/CCScrollView.h +++ b/native/extensions/GUI/CCScrollView/CCScrollView.h @@ -240,11 +240,11 @@ public: bool isClippingToBounds() { return _clippingToBounds; } void setClippingToBounds(bool bClippingToBounds) { _clippingToBounds = bClippingToBounds; } - virtual bool onTouchBegan(Touch *touch, Event *event); - virtual void onTouchMoved(Touch *touch, Event *event); - virtual void onTouchEnded(Touch *touch, Event *event); - virtual void onTouchCancelled(Touch *touch, Event *event); - + virtual bool onTouchBegan(Touch *touch, Event *event) override; + virtual void onTouchMoved(Touch *touch, Event *event) override; + virtual void onTouchEnded(Touch *touch, Event *event) override; + virtual void onTouchCancelled(Touch *touch, Event *event) override; + // Overrides virtual void setContentSize(const Size & size) override; virtual const Size& getContentSize() const override; @@ -260,7 +260,7 @@ public: virtual void removeAllChildren() override; virtual void removeAllChildrenWithCleanup(bool cleanup) override; - virtual void removeChild(Node* child, bool cleaup = true) override; + virtual void removeChild(Node* child, bool cleanup = true) override; /** * CCActionTweenDelegate */ @@ -328,7 +328,7 @@ protected: */ Node* _container; /** - * Determiens whether user touch is moved after begin phase. + * Determines whether user touch is moved after begin phase. */ bool _touchMoved; /** @@ -384,6 +384,9 @@ protected: CustomCommand _beforeDrawCommand; CustomCommand _afterDrawCommand; + /** + * Action created with setContentOffsetInDuration(), saved so it can be halted + */ Action* _animatedScrollAction; }; diff --git a/native/extensions/GUI/CCScrollView/CCTableView.cpp b/native/extensions/GUI/CCScrollView/CCTableView.cpp index 5cb8c3a900..a6efe0e494 100644 --- a/native/extensions/GUI/CCScrollView/CCTableView.cpp +++ b/native/extensions/GUI/CCScrollView/CCTableView.cpp @@ -55,7 +55,7 @@ bool TableView::initWithViewSize(const Size& size, Node* container/* = nullptr*/ if (ScrollView::initWithViewSize(size,container)) { CC_SAFE_DELETE(_indices); - _indices = new std::set(); + _indices = new (std::nothrow) std::set(); _vordering = VerticalFillOrder::BOTTOM_UP; this->setDirection(Direction::VERTICAL); diff --git a/native/extensions/assets-manager/AssetsManagerEx.cpp b/native/extensions/assets-manager/AssetsManagerEx.cpp index 5917e395c8..e7d0fee7c0 100644 --- a/native/extensions/assets-manager/AssetsManagerEx.cpp +++ b/native/extensions/assets-manager/AssetsManagerEx.cpp @@ -23,7 +23,7 @@ ****************************************************************************/ #include "AssetsManagerEx.h" #include "CCEventListenerAssetsManagerEx.h" -#include "base/CCString.h" +#include "base/ccUTF8.h" #include "base/CCDirector.h" #include @@ -494,7 +494,13 @@ void AssetsManagerEx::downloadManifest() if (_updateState != State::PREDOWNLOAD_MANIFEST) return; - std::string manifestUrl = _localManifest->getManifestFileUrl(); + std::string manifestUrl; + if (_remoteManifest->isVersionLoaded()) { + manifestUrl = _remoteManifest->getManifestFileUrl(); + } else { + manifestUrl = _localManifest->getManifestFileUrl(); + } + if (manifestUrl.size() > 0) { _updateState = State::DOWNLOADING_MANIFEST; @@ -658,8 +664,8 @@ void AssetsManagerEx::updateSucceed() _compressedFiles.clear(); std::function mainThread = [this](void* param) { - AsyncData* asyncData = (AsyncData*)param; - if (asyncData->errorCompressedFile.empty()) + auto asyncDataInner = reinterpret_cast(param); + if (asyncDataInner->errorCompressedFile.empty()) { // 5. Set update state _updateState = State::UP_TO_DATE; @@ -669,10 +675,10 @@ void AssetsManagerEx::updateSucceed() else { _updateState = State::FAIL_TO_UPDATE; - dispatchUpdateEvent(EventAssetsManagerEx::EventCode::ERROR_DECOMPRESS, "", "Unable to decompress file " + asyncData->errorCompressedFile); + dispatchUpdateEvent(EventAssetsManagerEx::EventCode::ERROR_DECOMPRESS, "", "Unable to decompress file " + asyncDataInner->errorCompressedFile); } - delete asyncData; + delete asyncDataInner; }; AsyncTaskPool::getInstance()->enqueue(AsyncTaskPool::TaskType::TASK_OTHER, mainThread, (void*)asyncData, [this, asyncData]() { // Decompress all compressed files @@ -807,6 +813,7 @@ void AssetsManagerEx::updateAssets(const DownloadUnits& assets) _updateState = State::UPDATING; _downloadUnits.clear(); _downloadUnits = assets; + _totalWaitToDownload = _totalToDownload = (int)_downloadUnits.size(); this->batchDownload(); } else if (size == 0 && _totalWaitToDownload == 0) @@ -823,7 +830,7 @@ const DownloadUnits& AssetsManagerEx::getFailedAssets() const void AssetsManagerEx::downloadFailedAssets() { - CCLOG("AssetsManagerEx : Start update %lu failed assets.\n", _failedUnits.size()); + CCLOG("AssetsManagerEx : Start update %lu failed assets.\n", static_cast(_failedUnits.size())); updateAssets(_failedUnits); } @@ -856,6 +863,11 @@ void AssetsManagerEx::onError(const network::DownloadTask& task, _failedUnits.emplace(unit.customId, unit); } dispatchUpdateEvent(EventAssetsManagerEx::EventCode::ERROR_UPDATING, task.identifier, errorStr, errorCode, errorCodeInternal); + + if (_totalWaitToDownload <= 0) + { + this->onDownloadUnitsFinished(); + } } } @@ -961,21 +973,7 @@ void AssetsManagerEx::onSuccess(const std::string &srcUrl, const std::string &st if (_totalWaitToDownload <= 0) { - // Finished with error check - if (_failedUnits.size() > 0) - { - // Save current download manifest information for resuming - _tempManifest->saveToFile(_tempManifestPath); - - decompressDownloadedZip(); - - _updateState = State::FAIL_TO_UPDATE; - dispatchUpdateEvent(EventAssetsManagerEx::EventCode::UPDATE_FAILED); - } - else - { - updateSucceed(); - } + this->onDownloadUnitsFinished(); } } } @@ -995,4 +993,23 @@ void AssetsManagerEx::batchDownload() } } +void AssetsManagerEx::onDownloadUnitsFinished() +{ + // Finished with error check + if (_failedUnits.size() > 0) + { + // Save current download manifest information for resuming + _tempManifest->saveToFile(_tempManifestPath); + + decompressDownloadedZip(); + + _updateState = State::FAIL_TO_UPDATE; + dispatchUpdateEvent(EventAssetsManagerEx::EventCode::UPDATE_FAILED); + } + else + { + updateSucceed(); + } +} + NS_CC_EXT_END diff --git a/native/extensions/assets-manager/AssetsManagerEx.h b/native/extensions/assets-manager/AssetsManagerEx.h index e7fa32291f..ec8b17e80d 100644 --- a/native/extensions/assets-manager/AssetsManagerEx.h +++ b/native/extensions/assets-manager/AssetsManagerEx.h @@ -189,6 +189,9 @@ protected: private: void batchDownload(); + + // Called when one DownloadUnits finished + void onDownloadUnitsFinished(); //! The event of the current AssetsManagerEx in event dispatcher std::string _eventName; diff --git a/native/extensions/assets-manager/CCEventListenerAssetsManagerEx.cpp b/native/extensions/assets-manager/CCEventListenerAssetsManagerEx.cpp index 20c034876c..5886184f27 100644 --- a/native/extensions/assets-manager/CCEventListenerAssetsManagerEx.cpp +++ b/native/extensions/assets-manager/CCEventListenerAssetsManagerEx.cpp @@ -25,7 +25,7 @@ #include "CCEventListenerAssetsManagerEx.h" #include "CCEventAssetsManagerEx.h" #include "AssetsManagerEx.h" -#include "cocos2d.h" +#include "base/ccUTF8.h" NS_CC_EXT_BEGIN diff --git a/native/extensions/assets-manager/Manifest.cpp b/native/extensions/assets-manager/Manifest.cpp index 492720c000..95f070689b 100644 --- a/native/extensions/assets-manager/Manifest.cpp +++ b/native/extensions/assets-manager/Manifest.cpp @@ -160,16 +160,13 @@ bool Manifest::versionEquals(const Manifest *b) const std::unordered_map Manifest::genDiff(const Manifest *b) const { std::unordered_map diff_map; - std::unordered_map bAssets = b->getAssets(); + const std::unordered_map &bAssets = b->getAssets(); - std::string key; - Asset valueA; - Asset valueB; std::unordered_map::const_iterator valueIt, it; for (it = _assets.begin(); it != _assets.end(); ++it) { - key = it->first; - valueA = it->second; + const auto &key = it->first; + const auto &valueA = it->second; // Deleted valueIt = bAssets.find(key); @@ -182,7 +179,7 @@ std::unordered_map Manifest::genDiff(const Man } // Modified - valueB = valueIt->second; + auto &valueB = valueIt->second; if (valueA.md5 != valueB.md5) { AssetDiff diff; diff.asset = valueB; @@ -193,8 +190,8 @@ std::unordered_map Manifest::genDiff(const Man for (it = bAssets.begin(); it != bAssets.end(); ++it) { - key = it->first; - valueB = it->second; + const auto &key = it->first; + const auto &valueB = it->second; // Added valueIt = _assets.find(key); @@ -327,8 +324,7 @@ void Manifest::setAssetDownloadState(const std::string &key, const Manifest::Dow { for (rapidjson::Value::MemberIterator itr = assets.MemberBegin(); itr != assets.MemberEnd(); ++itr) { - std::string jkey = itr->name.GetString(); - if (jkey == key) { + if (key.compare(itr->name.GetString()) == 0) { rapidjson::Value &entry = itr->value; if (entry.HasMember(KEY_DOWNLOAD_STATE) && entry[KEY_DOWNLOAD_STATE].IsInt()) { diff --git a/native/extensions/physics-nodes/CCPhysicsSprite.cpp b/native/extensions/physics-nodes/CCPhysicsSprite.cpp index 0e3d97be3c..354e2e43b2 100644 --- a/native/extensions/physics-nodes/CCPhysicsSprite.cpp +++ b/native/extensions/physics-nodes/CCPhysicsSprite.cpp @@ -413,7 +413,7 @@ void PhysicsSprite::syncPhysicsTransform() const void PhysicsSprite::onEnter() { Node::onEnter(); - _syncTransform = _director->getEventDispatcher()->addCustomEventListener(Director::EVENT_AFTER_UPDATE, std::bind(&PhysicsSprite::afterUpdate, this, std::placeholders::_1)); + _syncTransform = Director::getInstance()->getEventDispatcher()->addCustomEventListener(Director::EVENT_AFTER_UPDATE, std::bind(&PhysicsSprite::afterUpdate, this, std::placeholders::_1)); _syncTransform->retain(); } @@ -421,7 +421,7 @@ void PhysicsSprite::onExit() { if (_syncTransform != nullptr) { - _director->getEventDispatcher()->removeEventListener(_syncTransform); + Director::getInstance()->getEventDispatcher()->removeEventListener(_syncTransform); _syncTransform->release(); } Node::onExit();