Merge branch 'develop' of https://github.com/cocos2d/cocos2d-x into develop_label_fixs

Conflicts:
	cocos/2d/CCLabel.cpp
This commit is contained in:
Dhilan007 2014-03-26 11:15:48 +08:00
commit 1247760d95
71 changed files with 1167 additions and 794 deletions

View File

@ -1 +1 @@
819b72559f8be48c41958b0afb4c6513207b453a 8141cfdd7d973fa5a4c189a72c2fd6cac8eb95ae

View File

@ -590,7 +590,7 @@ void EventDispatcher::dispatchEventToListeners(EventListenerVector* listeners, c
// priority < 0 // priority < 0
if (fixedPriorityListeners) if (fixedPriorityListeners)
{ {
CCASSERT(listeners->getGt0Index() <= fixedPriorityListeners->size(), "Out of range exception!"); CCASSERT(listeners->getGt0Index() <= static_cast<ssize_t>(fixedPriorityListeners->size()), "Out of range exception!");
if (!fixedPriorityListeners->empty()) if (!fixedPriorityListeners->empty())
{ {

View File

@ -231,6 +231,8 @@ bool FontAtlas::prepareLetterDefinitions(unsigned short *utf16String)
auto pixelFormat = fontTTf->getOutlineSize() > 0 ? Texture2D::PixelFormat::AI88 : Texture2D::PixelFormat::A8; auto pixelFormat = fontTTf->getOutlineSize() > 0 ? Texture2D::PixelFormat::AI88 : Texture2D::PixelFormat::A8;
bool existNewLetter = false; bool existNewLetter = false;
int bottomHeight = _commonLineHeight - _fontAscender;
for (int i = 0; i < length; ++i) for (int i = 0; i < length; ++i)
{ {
auto outIterator = _fontLetterDefinitions.find(utf16String[i]); auto outIterator = _fontLetterDefinitions.find(utf16String[i]);
@ -248,6 +250,7 @@ bool FontAtlas::prepareLetterDefinitions(unsigned short *utf16String)
tempDef.height = tempRect.size.height + _letterPadding; tempDef.height = tempRect.size.height + _letterPadding;
tempDef.offsetX = tempRect.origin.x + offsetAdjust; tempDef.offsetX = tempRect.origin.x + offsetAdjust;
tempDef.offsetY = _fontAscender + tempRect.origin.y - offsetAdjust; tempDef.offsetY = _fontAscender + tempRect.origin.y - offsetAdjust;
tempDef.clipBottom = bottomHeight - (tempDef.height + tempRect.origin.y + offsetAdjust);
if (_currentPageOrigX + tempDef.width > CacheTextureWidth) if (_currentPageOrigX + tempDef.width > CacheTextureWidth)
{ {
@ -290,6 +293,7 @@ bool FontAtlas::prepareLetterDefinitions(unsigned short *utf16String)
tempDef.offsetX = 0; tempDef.offsetX = 0;
tempDef.offsetY = 0; tempDef.offsetY = 0;
tempDef.textureID = 0; tempDef.textureID = 0;
tempDef.clipBottom = 0;
_currentPageOrigX += 1; _currentPageOrigX += 1;
} }

View File

@ -50,6 +50,8 @@ struct FontLetterDefinition
int textureID; int textureID;
bool validDefinition; bool validDefinition;
int xAdvance; int xAdvance;
int clipBottom;
}; };
class CC_DLL FontAtlas : public Ref class CC_DLL FontAtlas : public Ref

View File

@ -388,7 +388,7 @@ unsigned char * makeDistanceMap( unsigned char *img, long width, long height)
double * data = (double *) calloc( pixelAmount, sizeof(double) ); double * data = (double *) calloc( pixelAmount, sizeof(double) );
double * outside = (double *) calloc( pixelAmount, sizeof(double) ); double * outside = (double *) calloc( pixelAmount, sizeof(double) );
double * inside = (double *) calloc( pixelAmount, sizeof(double) ); double * inside = (double *) calloc( pixelAmount, sizeof(double) );
unsigned int i,j; long i,j;
// Convert img into double (data) rescale image levels between 0 and 1 // Convert img into double (data) rescale image levels between 0 and 1
long outWidth = width + 2 * FontFreeType::DistanceMapSpread; long outWidth = width + 2 * FontFreeType::DistanceMapSpread;

View File

@ -341,7 +341,9 @@ void Label::reset()
_textColor = Color4B::WHITE; _textColor = Color4B::WHITE;
_textColorF = Color4F::WHITE; _textColorF = Color4F::WHITE;
setColor(Color3B::WHITE); setColor(Color3B::WHITE);
_shadowEnabled = false; _shadowEnabled = false;
_clipEnabled = false;
} }
void Label::updateShaderProgram() void Label::updateShaderProgram()

View File

@ -217,6 +217,10 @@ public:
virtual Sprite * getLetter(int lettetIndex); virtual Sprite * getLetter(int lettetIndex);
/** clip upper and lower margin for reduce height of label.
*/
void setClipMarginEnabled(bool clipEnabled) { _clipEnabled = clipEnabled; }
bool isClipMarginEnabled() const { return _clipEnabled; }
// font related stuff // font related stuff
int getCommonLineHeight() const; int getCommonLineHeight() const;
@ -370,6 +374,8 @@ protected:
Color4B _textColor; Color4B _textColor;
Color4F _textColorF; Color4F _textColorF;
bool _clipEnabled;
private: private:
CC_DISALLOW_COPY_AND_ASSIGN(Label); CC_DISALLOW_COPY_AND_ASSIGN(Label);

View File

@ -322,6 +322,16 @@ bool LabelTextFormatter::createStringSprites(Label *theLabel)
Point letterPosition; Point letterPosition;
const auto& kernings = theLabel->_horizontalKernings; const auto& kernings = theLabel->_horizontalKernings;
float clipTop = 0;
float clipBottom = 0;
int lineIndex = 0;
bool lineStart = true;
bool clip = false;
if (theLabel->_currentLabelType == Label::LabelType::TTF && theLabel->_clipEnabled)
{
clip = true;
}
for (unsigned int i = 0; i < stringLen; i++) for (unsigned int i = 0; i < stringLen; i++)
{ {
unsigned short c = strWhole[i]; unsigned short c = strWhole[i];
@ -340,6 +350,7 @@ bool LabelTextFormatter::createStringSprites(Label *theLabel)
if (c == '\n') if (c == '\n')
{ {
lineIndex++;
nextFontPositionX = 0; nextFontPositionX = 0;
nextFontPositionY -= theLabel->_commonLineHeight; nextFontPositionY -= theLabel->_commonLineHeight;
@ -347,8 +358,30 @@ bool LabelTextFormatter::createStringSprites(Label *theLabel)
if(nextFontPositionY < theLabel->_commonLineHeight) if(nextFontPositionY < theLabel->_commonLineHeight)
break; break;
lineStart = true;
continue; continue;
} }
else if (clip && tempDefinition.height > 0.0f)
{
if (lineStart)
{
if (lineIndex == 0)
{
clipTop = charYOffset;
}
lineStart = false;
clipBottom = tempDefinition.clipBottom;
}
else if(tempDefinition.clipBottom < clipBottom)
{
clipBottom = tempDefinition.clipBottom;
}
if (lineIndex == 0 && charYOffset < clipTop)
{
clipTop = charYOffset;
}
}
letterPosition.x = (nextFontPositionX + charXOffset + kernings[i]) / contentScaleFactor; letterPosition.x = (nextFontPositionX + charXOffset + kernings[i]) / contentScaleFactor;
letterPosition.y = (nextFontPositionY - charYOffset) / contentScaleFactor; letterPosition.y = (nextFontPositionY - charYOffset) / contentScaleFactor;
@ -382,11 +415,26 @@ bool LabelTextFormatter::createStringSprites(Label *theLabel)
} }
tmpSize.height = totalHeight; tmpSize.height = totalHeight;
if (theLabel->_labelHeight > 0) if (theLabel->_labelHeight > 0)
{ {
tmpSize.height = theLabel->_labelHeight * contentScaleFactor; tmpSize.height = theLabel->_labelHeight * contentScaleFactor;
} }
if (clip)
{
int clipTotal = (clipTop + clipBottom) / contentScaleFactor;
tmpSize.height -= clipTotal * contentScaleFactor;
clipBottom /= contentScaleFactor;
for (int i = 0; i < theLabel->_limitShowCount; i++)
{
theLabel->_lettersInfo[i].position.y -= clipBottom;
}
}
theLabel->setContentSize(CC_SIZE_PIXELS_TO_POINTS(tmpSize)); theLabel->setContentSize(CC_SIZE_PIXELS_TO_POINTS(tmpSize));
return true; return true;
} }

View File

@ -492,7 +492,7 @@ void TMXLayer::setTileGID(uint32_t gid, const Point& pos, TMXTileFlags flags)
{ {
CCASSERT(pos.x < _layerSize.width && pos.y < _layerSize.height && pos.x >=0 && pos.y >=0, "TMXLayer: invalid position"); CCASSERT(pos.x < _layerSize.width && pos.y < _layerSize.height && pos.x >=0 && pos.y >=0, "TMXLayer: invalid position");
CCASSERT(_tiles && _atlasIndexArray, "TMXLayer: the tiles map has been released"); CCASSERT(_tiles && _atlasIndexArray, "TMXLayer: the tiles map has been released");
CCASSERT(gid == 0 || gid >= _tileSet->_firstGid, "TMXLayer: invalid gid" ); CCASSERT(gid == 0 || (int)gid >= _tileSet->_firstGid, "TMXLayer: invalid gid" );
TMXTileFlags currentFlags; TMXTileFlags currentFlags;
uint32_t currentGID = getTileGIDAt(pos, &currentFlags); uint32_t currentGID = getTileGIDAt(pos, &currentFlags);

View File

@ -1203,6 +1203,9 @@ void Texture2D::generateMipmap()
GL::bindTexture2D( _name ); GL::bindTexture2D( _name );
glGenerateMipmap(GL_TEXTURE_2D); glGenerateMipmap(GL_TEXTURE_2D);
_hasMipmaps = true; _hasMipmaps = true;
#if CC_ENABLE_CACHE_TEXTURE_DATA
VolatileTextureMgr::setHasMipmaps(this, _hasMipmaps);
#endif
} }
bool Texture2D::hasMipmaps() const bool Texture2D::hasMipmaps() const

View File

@ -635,6 +635,12 @@ void VolatileTextureMgr::addStringTexture(Texture2D *tt, const char* text, const
vt->_fontDefinition = fontDefinition; vt->_fontDefinition = fontDefinition;
} }
void VolatileTextureMgr::setHasMipmaps(Texture2D *t, bool hasMipmaps)
{
VolatileTexture *vt = findVolotileTexture(t);
vt->_hasMipmaps = hasMipmaps;
}
void VolatileTextureMgr::setTexParameters(Texture2D *t, const Texture2D::TexParams &texParams) void VolatileTextureMgr::setTexParameters(Texture2D *t, const Texture2D::TexParams &texParams)
{ {
VolatileTexture *vt = findVolotileTexture(t); VolatileTexture *vt = findVolotileTexture(t);
@ -717,6 +723,9 @@ void VolatileTextureMgr::reloadAllTextures()
default: default:
break; break;
} }
if (vt->_hasMipmaps) {
vt->_texture->generateMipmap();
}
vt->_texture->setTexParameters(vt->_texParams); vt->_texture->setTexParameters(vt->_texParams);
} }

View File

@ -251,6 +251,7 @@ protected:
std::string _fileName; std::string _fileName;
bool _hasMipmaps;
Texture2D::TexParams _texParams; Texture2D::TexParams _texParams;
std::string _text; std::string _text;
FontDefinition _fontDefinition; FontDefinition _fontDefinition;
@ -264,6 +265,7 @@ public:
static void addDataTexture(Texture2D *tt, void* data, int dataLen, Texture2D::PixelFormat pixelFormat, const Size& contentSize); static void addDataTexture(Texture2D *tt, void* data, int dataLen, Texture2D::PixelFormat pixelFormat, const Size& contentSize);
static void addImage(Texture2D *tt, Image *image); static void addImage(Texture2D *tt, Image *image);
static void setHasMipmaps(Texture2D *t, bool hasMipmaps);
static void setTexParameters(Texture2D *t, const Texture2D::TexParams &texParams); static void setTexParameters(Texture2D *t, const Texture2D::TexParams &texParams);
static void removeTexture(Texture2D *t); static void removeTexture(Texture2D *t);
static void reloadAllTextures(); static void reloadAllTextures();

View File

@ -241,7 +241,7 @@ void ActionNode::insertFrame(int index, ActionFrame* frame)
return; return;
} }
int frameType = frame->getFrameType(); int frameType = frame->getFrameType();
if(frameType < _frameArray.size()) if(frameType < (int)_frameArray.size())
{ {
auto cArray = _frameArray.at(frameType); auto cArray = _frameArray.at(frameType);
cArray->insert(index, frame); cArray->insert(index, frame);
@ -256,7 +256,7 @@ void ActionNode::addFrame(ActionFrame* frame)
} }
int frameType = frame->getFrameType(); int frameType = frame->getFrameType();
if(frameType < _frameArray.size()) if(frameType < (int)_frameArray.size())
{ {
auto cArray = _frameArray.at(frameType); auto cArray = _frameArray.at(frameType);
cArray->pushBack(frame); cArray->pushBack(frame);
@ -270,7 +270,7 @@ void ActionNode::deleteFrame(ActionFrame* frame)
return; return;
} }
int frameType = frame->getFrameType(); int frameType = frame->getFrameType();
if(frameType < _frameArray.size()) if(frameType < (int)_frameArray.size())
{ {
auto cArray = _frameArray.at(frameType); auto cArray = _frameArray.at(frameType);
cArray->eraseObject(frame); cArray->eraseObject(frame);

View File

@ -126,8 +126,8 @@ void Skin::setSkinData(const BaseData &var)
setScaleX(_skinData.scaleX); setScaleX(_skinData.scaleX);
setScaleY(_skinData.scaleY); setScaleY(_skinData.scaleY);
setRotationX(CC_RADIANS_TO_DEGREES(_skinData.skewX)); setRotationSkewX(CC_RADIANS_TO_DEGREES(_skinData.skewX));
setRotationY(CC_RADIANS_TO_DEGREES(-_skinData.skewY)); setRotationSkewY(CC_RADIANS_TO_DEGREES(-_skinData.skewY));
setPosition(Point(_skinData.x, _skinData.y)); setPosition(Point(_skinData.x, _skinData.y));
_skinTransform = getNodeToParentTransform(); _skinTransform = getNodeToParentTransform();

View File

@ -187,10 +187,11 @@ void WsThreadHelper::update(float dt)
WsMessage *msg = nullptr; WsMessage *msg = nullptr;
// Returns quickly if no message // Returns quickly if no message
std::lock_guard<std::mutex> lk(_UIWsMessageQueueMutex); _UIWsMessageQueueMutex.lock();
if (0 == _UIWsMessageQueue->size()) if (0 == _UIWsMessageQueue->size())
{ {
_UIWsMessageQueueMutex.unlock();
return; return;
} }
@ -198,6 +199,8 @@ void WsThreadHelper::update(float dt)
msg = *(_UIWsMessageQueue->begin()); msg = *(_UIWsMessageQueue->begin());
_UIWsMessageQueue->pop_front(); _UIWsMessageQueue->pop_front();
_UIWsMessageQueueMutex.unlock();
if (_ws) if (_ws)
{ {
_ws->onUIThreadReceiveMessage(msg); _ws->onUIThreadReceiveMessage(msg);

View File

@ -3,6 +3,11 @@
-- @module Label -- @module Label
-- @extend SpriteBatchNode,LabelProtocol, -- @extend SpriteBatchNode,LabelProtocol,
--------------------------------
-- @function [parent=#Label] isClipMarginEnabled
-- @param self
-- @return bool#bool ret (return value: bool)
-------------------------------- --------------------------------
-- @function [parent=#Label] enableShadow -- @function [parent=#Label] enableShadow
-- @param self -- @param self
@ -57,6 +62,11 @@
-- @param self -- @param self
-- @return TextHAlignment#TextHAlignment ret (return value: cc.TextHAlignment) -- @return TextHAlignment#TextHAlignment ret (return value: cc.TextHAlignment)
--------------------------------
-- @function [parent=#Label] setClipMarginEnabled
-- @param self
-- @param #bool bool
-------------------------------- --------------------------------
-- @function [parent=#Label] setString -- @function [parent=#Label] setString
-- @param self -- @param self

View File

@ -52,6 +52,11 @@
-- @param self -- @param self
-- @return RichText#RichText ret (return value: ccui.RichText) -- @return RichText#RichText ret (return value: ccui.RichText)
--------------------------------
-- @function [parent=#RichText] getDescription
-- @param self
-- @return string#string ret (return value: string)
-------------------------------- --------------------------------
-- @function [parent=#RichText] RichText -- @function [parent=#RichText] RichText
-- @param self -- @param self

View File

@ -187,57 +187,21 @@
-- @param #int int -- @param #int int
-- @param #int int -- @param #int int
--------------------------------
-- @function [parent=#ScrollView] getChildByName
-- @param self
-- @param #char char
-- @return Widget#Widget ret (return value: ccui.Widget)
-------------------------------- --------------------------------
-- @function [parent=#ScrollView] getDescription -- @function [parent=#ScrollView] getDescription
-- @param self -- @param self
-- @return string#string ret (return value: string) -- @return string#string ret (return value: string)
-------------------------------- --------------------------------
-- @function [parent=#ScrollView] removeAllChildren -- @function [parent=#ScrollView] update
-- @param self -- @param self
-- @param #float float
--------------------------------
-- overload function: getChildren()
--
-- overload function: getChildren()
--
-- @function [parent=#ScrollView] getChildren
-- @param self
-- @return array_table#array_table ret (retunr value: array_table)
--------------------------------
-- @function [parent=#ScrollView] getNodes
-- @param self
-- @return array_table#array_table ret (return value: array_table)
--------------------------------
-- @function [parent=#ScrollView] getChildByTag
-- @param self
-- @param #int int
-- @return Node#Node ret (return value: cc.Node)
--------------------------------
-- @function [parent=#ScrollView] removeNode
-- @param self
-- @param #cc.Node node
--------------------------------
-- @function [parent=#ScrollView] removeNodeByTag
-- @param self
-- @param #int int
--------------------------------
-- overload function: addNode(cc.Node, int)
--
-- overload function: addNode(cc.Node)
--
-- overload function: addNode(cc.Node, int, int)
--
-- @function [parent=#ScrollView] addNode
-- @param self
-- @param #cc.Node node
-- @param #int int
-- @param #int int
-------------------------------- --------------------------------
-- @function [parent=#ScrollView] getLayoutType -- @function [parent=#ScrollView] getLayoutType
@ -250,24 +214,7 @@
-- @param #bool bool -- @param #bool bool
-------------------------------- --------------------------------
-- @function [parent=#ScrollView] update -- @function [parent=#ScrollView] removeAllChildren
-- @param self
-- @param #float float
--------------------------------
-- @function [parent=#ScrollView] getNodeByTag
-- @param self
-- @param #int int
-- @return Node#Node ret (return value: cc.Node)
--------------------------------
-- @function [parent=#ScrollView] getChildByName
-- @param self
-- @param #char char
-- @return Widget#Widget ret (return value: ccui.Widget)
--------------------------------
-- @function [parent=#ScrollView] removeAllNodes
-- @param self -- @param self
-------------------------------- --------------------------------
@ -276,6 +223,21 @@
-- @param #cc.Node node -- @param #cc.Node node
-- @param #bool bool -- @param #bool bool
--------------------------------
-- overload function: getChildren()
--
-- overload function: getChildren()
--
-- @function [parent=#ScrollView] getChildren
-- @param self
-- @return array_table#array_table ret (retunr value: array_table)
--------------------------------
-- @function [parent=#ScrollView] getChildByTag
-- @param self
-- @param #int int
-- @return Node#Node ret (return value: cc.Node)
-------------------------------- --------------------------------
-- @function [parent=#ScrollView] getChildrenCount -- @function [parent=#ScrollView] getChildrenCount
-- @param self -- @param self

View File

@ -1,18 +1,13 @@
-------------------------------- --------------------------------
-- @module Widget -- @module Widget
-- @extend Node -- @extend ProtectedNode
-------------------------------- --------------------------------
-- @function [parent=#Widget] setSizePercent -- @function [parent=#Widget] setSizePercent
-- @param self -- @param self
-- @param #point_table point -- @param #point_table point
--------------------------------
-- @function [parent=#Widget] isFlippedX
-- @param self
-- @return bool#bool ret (return value: bool)
-------------------------------- --------------------------------
-- @function [parent=#Widget] getCustomSize -- @function [parent=#Widget] getCustomSize
-- @param self -- @param self
@ -29,10 +24,9 @@
-- @param #bool bool -- @param #bool bool
-------------------------------- --------------------------------
-- @function [parent=#Widget] getNodeByTag -- @function [parent=#Widget] getLeftInParent
-- @param self -- @param self
-- @param #int int -- @return float#float ret (return value: float)
-- @return Node#Node ret (return value: cc.Node)
-------------------------------- --------------------------------
-- @function [parent=#Widget] getTouchEndPos -- @function [parent=#Widget] getTouchEndPos
@ -44,11 +38,6 @@
-- @param self -- @param self
-- @param #point_table point -- @param #point_table point
--------------------------------
-- @function [parent=#Widget] getNodes
-- @param self
-- @return array_table#array_table ret (return value: array_table)
-------------------------------- --------------------------------
-- @function [parent=#Widget] getLayoutSize -- @function [parent=#Widget] getLayoutSize
-- @param self -- @param self
@ -69,15 +58,6 @@
-- @param self -- @param self
-- @return bool#bool ret (return value: bool) -- @return bool#bool ret (return value: bool)
--------------------------------
-- overload function: updateSizeAndPosition(size_table)
--
-- overload function: updateSizeAndPosition()
--
-- @function [parent=#Widget] updateSizeAndPosition
-- @param self
-- @param #size_table size
-------------------------------- --------------------------------
-- @function [parent=#Widget] getBottomInParent -- @function [parent=#Widget] getBottomInParent
-- @param self -- @param self
@ -100,9 +80,9 @@
-- @return PositionType#PositionType ret (return value: ccui.PositionType) -- @return PositionType#PositionType ret (return value: ccui.PositionType)
-------------------------------- --------------------------------
-- @function [parent=#Widget] setName -- @function [parent=#Widget] getWidgetType
-- @param self -- @param self
-- @param #char char -- @return WidgetType#WidgetType ret (return value: ccui.WidgetType)
-------------------------------- --------------------------------
-- @function [parent=#Widget] getChildByName -- @function [parent=#Widget] getChildByName
@ -116,9 +96,9 @@
-- @return bool#bool ret (return value: bool) -- @return bool#bool ret (return value: bool)
-------------------------------- --------------------------------
-- @function [parent=#Widget] removeNodeByTag -- @function [parent=#Widget] isFocused
-- @param self -- @param self
-- @param #int int -- @return bool#bool ret (return value: bool)
-------------------------------- --------------------------------
-- @function [parent=#Widget] isTouchEnabled -- @function [parent=#Widget] isTouchEnabled
@ -175,17 +155,9 @@
-- @param #ccui.BrightStyle brightstyle -- @param #ccui.BrightStyle brightstyle
-------------------------------- --------------------------------
-- overload function: addNode(cc.Node, int) -- @function [parent=#Widget] setName
--
-- overload function: addNode(cc.Node)
--
-- overload function: addNode(cc.Node, int, int)
--
-- @function [parent=#Widget] addNode
-- @param self -- @param self
-- @param #cc.Node node -- @param #char char
-- @param #int int
-- @param #int int
-------------------------------- --------------------------------
-- @function [parent=#Widget] setLayoutParameter -- @function [parent=#Widget] setLayoutParameter
@ -202,21 +174,11 @@
-- @param self -- @param self
-- @return point_table#point_table ret (return value: point_table) -- @return point_table#point_table ret (return value: point_table)
--------------------------------
-- @function [parent=#Widget] getLeftInParent
-- @param self
-- @return float#float ret (return value: float)
-------------------------------- --------------------------------
-- @function [parent=#Widget] setActionTag -- @function [parent=#Widget] setActionTag
-- @param self -- @param self
-- @param #int int -- @param #int int
--------------------------------
-- @function [parent=#Widget] ignoreContentAdaptWithSize
-- @param self
-- @param #bool bool
-------------------------------- --------------------------------
-- @function [parent=#Widget] isBright -- @function [parent=#Widget] isBright
-- @param self -- @param self
@ -234,9 +196,13 @@
-- @return float#float ret (return value: float) -- @return float#float ret (return value: float)
-------------------------------- --------------------------------
-- @function [parent=#Widget] getWidgetType -- overload function: updateSizeAndPosition(size_table)
--
-- overload function: updateSizeAndPosition()
--
-- @function [parent=#Widget] updateSizeAndPosition
-- @param self -- @param self
-- @return WidgetType#WidgetType ret (return value: ccui.WidgetType) -- @param #size_table size
-------------------------------- --------------------------------
-- @function [parent=#Widget] getSize -- @function [parent=#Widget] getSize
@ -254,13 +220,9 @@
-- @return SizeType#SizeType ret (return value: ccui.SizeType) -- @return SizeType#SizeType ret (return value: ccui.SizeType)
-------------------------------- --------------------------------
-- @function [parent=#Widget] removeNode -- @function [parent=#Widget] ignoreContentAdaptWithSize
-- @param self
-- @param #cc.Node node
--------------------------------
-- @function [parent=#Widget] removeAllNodes
-- @param self -- @param self
-- @param #bool bool
-------------------------------- --------------------------------
-- @function [parent=#Widget] getPositionPercent -- @function [parent=#Widget] getPositionPercent
@ -274,7 +236,7 @@
-- @return bool#bool ret (return value: bool) -- @return bool#bool ret (return value: bool)
-------------------------------- --------------------------------
-- @function [parent=#Widget] isFocused -- @function [parent=#Widget] isFlippedX
-- @param self -- @param self
-- @return bool#bool ret (return value: bool) -- @return bool#bool ret (return value: bool)
@ -310,72 +272,11 @@
-- @param self -- @param self
-- @return Widget#Widget ret (return value: ccui.Widget) -- @return Widget#Widget ret (return value: ccui.Widget)
--------------------------------
-- overload function: addChild(cc.Node, int)
--
-- overload function: addChild(cc.Node)
--
-- overload function: addChild(cc.Node, int, int)
--
-- @function [parent=#Widget] addChild
-- @param self
-- @param #cc.Node node
-- @param #int int
-- @param #int int
-------------------------------- --------------------------------
-- @function [parent=#Widget] setColor -- @function [parent=#Widget] setColor
-- @param self -- @param self
-- @param #color3B_table color3b -- @param #color3B_table color3b
--------------------------------
-- @function [parent=#Widget] removeFromParent
-- @param self
--------------------------------
-- @function [parent=#Widget] removeAllChildrenWithCleanup
-- @param self
-- @param #bool bool
--------------------------------
-- @function [parent=#Widget] removeAllChildren
-- @param self
--------------------------------
-- @function [parent=#Widget] sortAllChildren
-- @param self
--------------------------------
-- @function [parent=#Widget] removeChild
-- @param self
-- @param #cc.Node node
-- @param #bool bool
--------------------------------
-- overload function: getChildren()
--
-- overload function: getChildren()
--
-- @function [parent=#Widget] getChildren
-- @param self
-- @return array_table#array_table ret (retunr value: array_table)
--------------------------------
-- @function [parent=#Widget] getDescription
-- @param self
-- @return string#string ret (return value: string)
--------------------------------
-- @function [parent=#Widget] getChildByTag
-- @param self
-- @param #int int
-- @return Node#Node ret (return value: cc.Node)
--------------------------------
-- @function [parent=#Widget] removeFromParentAndCleanup
-- @param self
-- @param #bool bool
-------------------------------- --------------------------------
-- @function [parent=#Widget] getColor -- @function [parent=#Widget] getColor
-- @param self -- @param self
@ -386,26 +287,20 @@
-- @param self -- @param self
-- @param #unsigned char char -- @param #unsigned char char
--------------------------------
-- @function [parent=#Widget] setPosition
-- @param self
-- @param #point_table point
--------------------------------
-- @function [parent=#Widget] removeChildByTag
-- @param self
-- @param #int int
-- @param #bool bool
-------------------------------- --------------------------------
-- @function [parent=#Widget] getOpacity -- @function [parent=#Widget] getOpacity
-- @param self -- @param self
-- @return unsigned char#unsigned char ret (return value: unsigned char) -- @return unsigned char#unsigned char ret (return value: unsigned char)
-------------------------------- --------------------------------
-- @function [parent=#Widget] getChildrenCount -- @function [parent=#Widget] setPosition
-- @param self -- @param self
-- @return long#long ret (return value: long) -- @param #point_table point
--------------------------------
-- @function [parent=#Widget] getDescription
-- @param self
-- @return string#string ret (return value: string)
-------------------------------- --------------------------------
-- @function [parent=#Widget] Widget -- @function [parent=#Widget] Widget

View File

@ -1 +1 @@
83d9fece450a67211518c287e9ecf99ce122c142 bb331bf4e55b4ca2f5b12c75e6c3e638ae3367d0

View File

@ -1544,6 +1544,8 @@ int register_all_cocos2dx(lua_State* tolua_S);

View File

@ -1 +1 @@
11bba6be0cebc89eb4c7195a61d021e51719468f 19adb2eb5a08b20b670b77975f7e30c08bbac2d6

View File

@ -362,12 +362,6 @@ int register_all_cocos2dx_ui(lua_State* tolua_S);

View File

@ -340,7 +340,7 @@ void RichText::formarRenderers()
float newContentSizeHeight = 0.0f; float newContentSizeHeight = 0.0f;
float *maxHeights = new float[_elementRenders.size()]; float *maxHeights = new float[_elementRenders.size()];
for (ssize_t i=0; i<_elementRenders.size(); i++) for (size_t i=0; i<_elementRenders.size(); i++)
{ {
Vector<Node*>* row = (_elementRenders[i]); Vector<Node*>* row = (_elementRenders[i]);
float maxHeight = 0.0f; float maxHeight = 0.0f;
@ -355,7 +355,7 @@ void RichText::formarRenderers()
float nextPosY = _customSize.height; float nextPosY = _customSize.height;
for (ssize_t i=0; i<_elementRenders.size(); i++) for (size_t i=0; i<_elementRenders.size(); i++)
{ {
Vector<Node*>* row = (_elementRenders[i]); Vector<Node*>* row = (_elementRenders[i]);
float nextPosX = 0.0f; float nextPosX = 0.0f;
@ -375,7 +375,7 @@ void RichText::formarRenderers()
} }
size_t length = _elementRenders.size(); size_t length = _elementRenders.size();
for (ssize_t i = 0; i<length; i++) for (size_t i = 0; i<length; i++)
{ {
Vector<Node*>* l = _elementRenders[i]; Vector<Node*>* l = _elementRenders[i];
l->clear(); l->clear();

View File

@ -23,9 +23,7 @@
#define CHIPMUNK_HEADER #define CHIPMUNK_HEADER
#ifdef _MSC_VER #ifdef _MSC_VER
#ifndef _USE_MATH_DEFINES #define _USE_MATH_DEFINES
#define _USE_MATH_DEFINES
#endif
#endif #endif
#include <stdlib.h> #include <stdlib.h>
@ -112,10 +110,10 @@ typedef struct cpSpace cpSpace;
#include "cpSpace.h" #include "cpSpace.h"
// Chipmunk 6.1.5 // Chipmunk 6.2.1
#define CP_VERSION_MAJOR 6 #define CP_VERSION_MAJOR 6
#define CP_VERSION_MINOR 1 #define CP_VERSION_MINOR 2
#define CP_VERSION_RELEASE 5 #define CP_VERSION_RELEASE 1
/// Version string. /// Version string.
extern const char *cpVersionString; extern const char *cpVersionString;

View File

@ -25,6 +25,9 @@
#define CP_HASH_COEF (3344921057ul) #define CP_HASH_COEF (3344921057ul)
#define CP_HASH_PAIR(A, B) ((cpHashValue)(A)*CP_HASH_COEF ^ (cpHashValue)(B)*CP_HASH_COEF) #define CP_HASH_PAIR(A, B) ((cpHashValue)(A)*CP_HASH_COEF ^ (cpHashValue)(B)*CP_HASH_COEF)
// TODO: Eww. Magic numbers.
#define MAGIC_EPSILON 1e-5
//MARK: cpArray //MARK: cpArray
struct cpArray { struct cpArray {
@ -43,6 +46,7 @@ cpBool cpArrayContains(cpArray *arr, void *ptr);
void cpArrayFreeEach(cpArray *arr, void (freeFunc)(void*)); void cpArrayFreeEach(cpArray *arr, void (freeFunc)(void*));
//MARK: Foreach loops //MARK: Foreach loops
static inline cpConstraint * static inline cpConstraint *
@ -69,6 +73,7 @@ cpArbiterNext(cpArbiter *node, cpBody *body)
#define CP_BODY_FOREACH_COMPONENT(root, var)\ #define CP_BODY_FOREACH_COMPONENT(root, var)\
for(cpBody *var = root; var; var = var->node.next) for(cpBody *var = root; var; var = var->node.next)
//MARK: cpHashSet //MARK: cpHashSet
typedef cpBool (*cpHashSetEqlFunc)(void *ptr, void *elt); typedef cpBool (*cpHashSetEqlFunc)(void *ptr, void *elt);
@ -90,6 +95,7 @@ void cpHashSetEach(cpHashSet *set, cpHashSetIteratorFunc func, void *data);
typedef cpBool (*cpHashSetFilterFunc)(void *elt, void *data); typedef cpBool (*cpHashSetFilterFunc)(void *elt, void *data);
void cpHashSetFilter(cpHashSet *set, cpHashSetFilterFunc func, void *data); void cpHashSetFilter(cpHashSet *set, cpHashSetFilterFunc func, void *data);
//MARK: Body Functions //MARK: Body Functions
void cpBodyAddShape(cpBody *body, cpShape *shape); void cpBodyAddShape(cpBody *body, cpShape *shape);
@ -116,7 +122,29 @@ cpShapeActive(cpShape *shape)
return shape->prev || (shape->body && shape->body->shapeList == shape); return shape->prev || (shape->body && shape->body->shapeList == shape);
} }
int cpCollideShapes(const cpShape *a, const cpShape *b, cpContact *arr); int cpCollideShapes(const cpShape *a, const cpShape *b, cpCollisionID *id, cpContact *arr);
static inline void
CircleSegmentQuery(cpShape *shape, cpVect center, cpFloat r, cpVect a, cpVect b, cpSegmentQueryInfo *info)
{
cpVect da = cpvsub(a, center);
cpVect db = cpvsub(b, center);
cpFloat qa = cpvdot(da, da) - 2.0f*cpvdot(da, db) + cpvdot(db, db);
cpFloat qb = -2.0f*cpvdot(da, da) + 2.0f*cpvdot(da, db);
cpFloat qc = cpvdot(da, da) - r*r;
cpFloat det = qb*qb - 4.0f*qa*qc;
if(det >= 0.0f){
cpFloat t = (-qb - cpfsqrt(det))/(2.0f*qa);
if(0.0f<= t && t <= 1.0f){
info->shape = shape;
info->t = t;
info->n = cpvnormalize(cpvlerp(da, db, t));
}
}
}
// TODO doesn't really need to be inline, but need a better place to put this function // TODO doesn't really need to be inline, but need a better place to put this function
static inline cpSplittingPlane static inline cpSplittingPlane
@ -135,50 +163,12 @@ cpSplittingPlaneCompare(cpSplittingPlane plane, cpVect v)
void cpLoopIndexes(cpVect *verts, int count, int *start, int *end); void cpLoopIndexes(cpVect *verts, int count, int *start, int *end);
static inline cpFloat
cpPolyShapeValueOnAxis(const cpPolyShape *poly, const cpVect n, const cpFloat d)
{
cpVect *verts = poly->tVerts;
cpFloat min = cpvdot(n, verts[0]);
for(int i=1; i<poly->numVerts; i++){
min = cpfmin(min, cpvdot(n, verts[i]));
}
return min - d;
}
static inline cpBool
cpPolyShapeContainsVert(const cpPolyShape *poly, const cpVect v)
{
cpSplittingPlane *planes = poly->tPlanes;
for(int i=0; i<poly->numVerts; i++){
cpFloat dist = cpSplittingPlaneCompare(planes[i], v);
if(dist > 0.0f) return cpFalse;
}
return cpTrue;
}
static inline cpBool
cpPolyShapeContainsVertPartial(const cpPolyShape *poly, const cpVect v, const cpVect n)
{
cpSplittingPlane *planes = poly->tPlanes;
for(int i=0; i<poly->numVerts; i++){
if(cpvdot(planes[i].n, n) < 0.0f) continue;
cpFloat dist = cpSplittingPlaneCompare(planes[i], v);
if(dist > 0.0f) return cpFalse;
}
return cpTrue;
}
//MARK: Spatial Index Functions //MARK: Spatial Index Functions
cpSpatialIndex *cpSpatialIndexInit(cpSpatialIndex *index, cpSpatialIndexClass *klass, cpSpatialIndexBBFunc bbfunc, cpSpatialIndex *staticIndex); cpSpatialIndex *cpSpatialIndexInit(cpSpatialIndex *index, cpSpatialIndexClass *klass, cpSpatialIndexBBFunc bbfunc, cpSpatialIndex *staticIndex);
//MARK: Space Functions //MARK: Space Functions
extern cpCollisionHandler cpDefaultCollisionHandler; extern cpCollisionHandler cpDefaultCollisionHandler;
@ -221,8 +211,7 @@ cpSpaceUncacheArbiter(cpSpace *space, cpArbiter *arb)
} }
void cpShapeUpdateFunc(cpShape *shape, void *unused); void cpShapeUpdateFunc(cpShape *shape, void *unused);
void cpSpaceCollideShapes(cpShape *a, cpShape *b, cpSpace *space); cpCollisionID cpSpaceCollideShapes(cpShape *a, cpShape *b, cpCollisionID id, cpSpace *space);
//MARK: Arbiters //MARK: Arbiters

View File

@ -1,4 +1,5 @@
#include <stdint.h> #include <stdint.h>
#include <float.h>
#ifdef __APPLE__ #ifdef __APPLE__
#include "TargetConditionals.h" #include "TargetConditionals.h"
@ -45,6 +46,7 @@
#define cpfpow pow #define cpfpow pow
#define cpffloor floor #define cpffloor floor
#define cpfceil ceil #define cpfceil ceil
#define CPFLOAT_MIN DBL_MIN
#else #else
typedef float cpFloat; typedef float cpFloat;
#define cpfsqrt sqrtf #define cpfsqrt sqrtf
@ -57,6 +59,7 @@
#define cpfpow powf #define cpfpow powf
#define cpffloor floorf #define cpffloor floorf
#define cpfceil ceilf #define cpfceil ceilf
#define CPFLOAT_MIN FLT_MIN
#endif #endif
#ifndef INFINITY #ifndef INFINITY
@ -135,6 +138,10 @@ static inline cpFloat cpflerpconst(cpFloat f1, cpFloat f2, cpFloat d)
/// Hash value type. /// Hash value type.
typedef uintptr_t cpHashValue; typedef uintptr_t cpHashValue;
/// Type used internally to cache colliding object info for cpCollideShapes().
/// Should be at least 32 bits.
typedef uint32_t cpCollisionID;
// Oh C, how we love to define our own boolean types to get compiler compatibility // Oh C, how we love to define our own boolean types to get compiler compatibility
/// Chipmunk's boolean type. /// Chipmunk's boolean type.
#ifdef CP_BOOL_TYPE #ifdef CP_BOOL_TYPE

View File

@ -55,6 +55,8 @@ void cpSegmentShapeSetRadius(cpShape *shape, cpFloat radius);
/// Set the vertexes of a poly shape. /// Set the vertexes of a poly shape.
void cpPolyShapeSetVerts(cpShape *shape, int numVerts, cpVect *verts, cpVect offset); void cpPolyShapeSetVerts(cpShape *shape, int numVerts, cpVect *verts, cpVect offset);
/// Set the radius of a poly shape.
void cpPolyShapeSetRadius(cpShape *shape, cpFloat radius);
#ifdef __cplusplus #ifdef __cplusplus
} }

View File

@ -50,7 +50,7 @@ struct cpCollisionHandler {
typedef struct cpContact cpContact; typedef struct cpContact cpContact;
#define CP_MAX_CONTACTS_PER_ARBITER 4 #define CP_MAX_CONTACTS_PER_ARBITER 2
/// @private /// @private
typedef enum cpArbiterState { typedef enum cpArbiterState {

View File

@ -79,6 +79,13 @@ static inline cpBB cpBBExpand(const cpBB bb, const cpVect v){
); );
} }
/// Returns the center of a bounding box.
static inline cpVect
cpBBCenter(cpBB bb)
{
return cpvlerp(cpv(bb.l, bb.b), cpv(bb.r, bb.t), 0.5f);
}
/// Returns the area of the bounding box. /// Returns the area of the bounding box.
static inline cpFloat cpBBArea(cpBB bb) static inline cpFloat cpBBArea(cpBB bb)
{ {

View File

@ -35,6 +35,8 @@ typedef struct cpPolyShape {
int numVerts; int numVerts;
cpVect *verts, *tVerts; cpVect *verts, *tVerts;
cpSplittingPlane *planes, *tPlanes; cpSplittingPlane *planes, *tPlanes;
cpFloat r;
} cpPolyShape; } cpPolyShape;
/// Allocate a polygon shape. /// Allocate a polygon shape.
@ -42,26 +44,38 @@ cpPolyShape* cpPolyShapeAlloc(void);
/// Initialize a polygon shape. /// Initialize a polygon shape.
/// A convex hull will be created from the vertexes. /// A convex hull will be created from the vertexes.
cpPolyShape* cpPolyShapeInit(cpPolyShape *poly, cpBody *body, int numVerts, const cpVect *verts, cpVect offset); cpPolyShape* cpPolyShapeInit(cpPolyShape *poly, cpBody *body, int numVerts, const cpVect *verts, cpVect offset);
/// Initialize a polygon shape.
/// A convex hull will be created from the vertexes.
cpPolyShape* cpPolyShapeInit2(cpPolyShape *poly, cpBody *body, int numVerts, const cpVect *verts, cpVect offset, cpFloat radius);
/// Allocate and initialize a polygon shape. /// Allocate and initialize a polygon shape.
/// A convex hull will be created from the vertexes. /// A convex hull will be created from the vertexes.
cpShape* cpPolyShapeNew(cpBody *body, int numVerts, cpVect *verts, cpVect offset); cpShape* cpPolyShapeNew(cpBody *body, int numVerts, const cpVect *verts, cpVect offset);
/// Allocate and initialize a polygon shape.
/// A convex hull will be created from the vertexes.
cpShape* cpPolyShapeNew2(cpBody *body, int numVerts, const cpVect *verts, cpVect offset, cpFloat radius);
/// Initialize a box shaped polygon shape. /// Initialize a box shaped polygon shape.
cpPolyShape* cpBoxShapeInit(cpPolyShape *poly, cpBody *body, cpFloat width, cpFloat height); cpPolyShape* cpBoxShapeInit(cpPolyShape *poly, cpBody *body, cpFloat width, cpFloat height);
/// Initialize an offset box shaped polygon shape. /// Initialize an offset box shaped polygon shape.
cpPolyShape* cpBoxShapeInit2(cpPolyShape *poly, cpBody *body, cpBB box); cpPolyShape* cpBoxShapeInit2(cpPolyShape *poly, cpBody *body, cpBB box);
/// Initialize an offset box shaped polygon shape.
cpPolyShape* cpBoxShapeInit3(cpPolyShape *poly, cpBody *body, cpBB box, cpFloat radius);
/// Allocate and initialize a box shaped polygon shape. /// Allocate and initialize a box shaped polygon shape.
cpShape* cpBoxShapeNew(cpBody *body, cpFloat width, cpFloat height); cpShape* cpBoxShapeNew(cpBody *body, cpFloat width, cpFloat height);
/// Allocate and initialize an offset box shaped polygon shape. /// Allocate and initialize an offset box shaped polygon shape.
cpShape* cpBoxShapeNew2(cpBody *body, cpBB box); cpShape* cpBoxShapeNew2(cpBody *body, cpBB box);
/// Allocate and initialize an offset box shaped polygon shape.
cpShape* cpBoxShapeNew3(cpBody *body, cpBB box, cpFloat radius);
/// Check that a set of vertexes is convex and has a clockwise winding. /// Check that a set of vertexes is convex and has a clockwise winding.
/// NOTE: Due to floating point precision issues, hulls created with cpQuickHull() are not guaranteed to validate! /// NOTE: Due to floating point precision issues, hulls created with cpQuickHull() are not guaranteed to validate!
cpBool cpPolyValidate(const cpVect *verts, const int numVerts); cpBool cpPolyValidate(const cpVect *verts, const int numVerts);
/// Get the number of verts in a polygon shape. /// Get the number of verts in a polygon shape.
int cpPolyShapeGetNumVerts(cpShape *shape); int cpPolyShapeGetNumVerts(const cpShape *shape);
/// Get the @c ith vertex of a polygon shape. /// Get the @c ith vertex of a polygon shape.
cpVect cpPolyShapeGetVert(cpShape *shape, int idx); cpVect cpPolyShapeGetVert(const cpShape *shape, int idx);
/// Get the radius of a polygon shape.
cpFloat cpPolyShapeGetRadius(const cpShape *shape);
/// @} /// @}

View File

@ -33,6 +33,9 @@ typedef struct cpNearestPointQueryInfo {
cpVect p; cpVect p;
/// The distance to the point. The distance is negative if the point is inside the shape. /// The distance to the point. The distance is negative if the point is inside the shape.
cpFloat d; cpFloat d;
/// The gradient of the signed distance function.
/// The same as info.p/info.d, but accurate even for very small values of info.d.
cpVect g;
} cpNearestPointQueryInfo; } cpNearestPointQueryInfo;
/// Segment query info struct. /// Segment query info struct.
@ -218,6 +221,7 @@ cpSegmentShape* cpSegmentShapeInit(cpSegmentShape *seg, cpBody *body, cpVect a,
/// Allocate and initialize a segment shape. /// Allocate and initialize a segment shape.
cpShape* cpSegmentShapeNew(cpBody *body, cpVect a, cpVect b, cpFloat radius); cpShape* cpSegmentShapeNew(cpBody *body, cpVect a, cpVect b, cpFloat radius);
/// Let Chipmunk know about the geometry of adjacent segments to avoid colliding with endcaps.
void cpSegmentShapeSetNeighbors(cpShape *shape, cpVect prev, cpVect next); void cpSegmentShapeSetNeighbors(cpShape *shape, cpVect prev, cpVect next);
CP_DeclareShapeGetter(cpSegmentShape, cpVect, A); CP_DeclareShapeGetter(cpSegmentShape, cpVect, A);

View File

@ -46,7 +46,7 @@ typedef cpBB (*cpSpatialIndexBBFunc)(void *obj);
/// Spatial index/object iterator callback function type. /// Spatial index/object iterator callback function type.
typedef void (*cpSpatialIndexIteratorFunc)(void *obj, void *data); typedef void (*cpSpatialIndexIteratorFunc)(void *obj, void *data);
/// Spatial query callback function type. /// Spatial query callback function type.
typedef void (*cpSpatialIndexQueryFunc)(void *obj1, void *obj2, void *data); typedef cpCollisionID (*cpSpatialIndexQueryFunc)(void *obj1, void *obj2, cpCollisionID id, void *data);
/// Spatial segment query callback function type. /// Spatial segment query callback function type.
typedef cpFloat (*cpSpatialIndexSegmentQueryFunc)(void *obj1, void *obj2, void *data); typedef cpFloat (*cpSpatialIndexSegmentQueryFunc)(void *obj1, void *obj2, void *data);

View File

@ -151,13 +151,14 @@ static inline cpVect cpvlerp(const cpVect v1, const cpVect v2, const cpFloat t)
/// Returns a normalized copy of v. /// Returns a normalized copy of v.
static inline cpVect cpvnormalize(const cpVect v) static inline cpVect cpvnormalize(const cpVect v)
{ {
return cpvmult(v, 1.0f/cpvlength(v)); // Neat trick I saw somewhere to avoid div/0.
return cpvmult(v, 1.0f/(cpvlength(v) + CPFLOAT_MIN));
} }
/// Returns a normalized copy of v or cpvzero if v was already cpvzero. Protects against divide by zero errors. /// @deprecated Just an alias for cpvnormalize() now.
static inline cpVect cpvnormalize_safe(const cpVect v) static inline cpVect cpvnormalize_safe(const cpVect v)
{ {
return (v.x == 0.0f && v.y == 0.0f ? cpvzero : cpvnormalize(v)); return cpvnormalize(v);
} }
/// Clamp v to length len. /// Clamp v to length len.

View File

@ -16,7 +16,14 @@ if(BUILD_SHARED)
set_target_properties(chipmunk PROPERTIES LINKER_LANGUAGE CXX) set_target_properties(chipmunk PROPERTIES LINKER_LANGUAGE CXX)
endif(MSVC) endif(MSVC)
# set the lib's version number # set the lib's version number
set_target_properties(chipmunk PROPERTIES VERSION 6.1.5) # But avoid on Android because symlinks to version numbered .so's don't work with Android's Java-side loadLibrary.
if(NOT ANDROID)
set_target_properties(chipmunk PROPERTIES VERSION 6.2.1)
endif(NOT ANDROID)
if(ANDROID)
# need to explicitly link to the math library because the CMake/Android toolchains may not do it automatically
target_link_libraries(chipmunk m)
endif(ANDROID)
install(TARGETS chipmunk RUNTIME DESTINATION lib LIBRARY DESTINATION lib) install(TARGETS chipmunk RUNTIME DESTINATION lib LIBRARY DESTINATION lib)
endif(BUILD_SHARED) endif(BUILD_SHARED)

View File

@ -83,6 +83,8 @@ cpAreaForSegment(cpVect a, cpVect b, cpFloat r)
cpFloat cpFloat
cpMomentForPoly(cpFloat m, const int numVerts, const cpVect *verts, cpVect offset) cpMomentForPoly(cpFloat m, const int numVerts, const cpVect *verts, cpVect offset)
{ {
if(numVerts == 2) return cpMomentForSegment(m, verts[0], verts[1]);
cpFloat sum1 = 0.0f; cpFloat sum1 = 0.0f;
cpFloat sum2 = 0.0f; cpFloat sum2 = 0.0f;
for(int i=0; i<numVerts; i++){ for(int i=0; i<numVerts; i++){

View File

@ -37,7 +37,7 @@ preStep(cpRotaryLimitJoint *joint, cpFloat dt)
} }
// calculate moment of inertia coefficient. // calculate moment of inertia coefficient.
joint->iSum = 1.0f/(1.0f/a->i + 1.0f/b->i); joint->iSum = 1.0f/(a->i_inv + b->i_inv);
// calculate bias velocity // calculate bias velocity
cpFloat maxBias = joint->constraint.maxBias; cpFloat maxBias = joint->constraint.maxBias;

View File

@ -72,7 +72,10 @@ typedef struct Thread {
Pair *next; Pair *next;
} Thread; } Thread;
struct Pair { Thread a, b; }; struct Pair {
Thread a, b;
cpCollisionID id;
};
//MARK: Misc Functions //MARK: Misc Functions
@ -205,7 +208,7 @@ PairInsert(Node *a, Node *b, cpBBTree *tree)
{ {
Pair *nextA = a->PAIRS, *nextB = b->PAIRS; Pair *nextA = a->PAIRS, *nextB = b->PAIRS;
Pair *pair = PairFromPool(tree); Pair *pair = PairFromPool(tree);
Pair temp = {{NULL, a, nextA},{NULL, b, nextB}}; Pair temp = {{NULL, a, nextA},{NULL, b, nextB}, 0};
a->PAIRS = b->PAIRS = pair; a->PAIRS = b->PAIRS = pair;
*pair = temp; *pair = temp;
@ -351,7 +354,7 @@ SubtreeQuery(Node *subtree, void *obj, cpBB bb, cpSpatialIndexQueryFunc func, vo
{ {
if(cpBBIntersects(subtree->bb, bb)){ if(cpBBIntersects(subtree->bb, bb)){
if(NodeIsLeaf(subtree)){ if(NodeIsLeaf(subtree)){
func(obj, subtree->obj, data); func(obj, subtree->obj, 0, data);
} else { } else {
SubtreeQuery(subtree->A, obj, bb, func, data); SubtreeQuery(subtree->A, obj, bb, func, data);
SubtreeQuery(subtree->B, obj, bb, func, data); SubtreeQuery(subtree->B, obj, bb, func, data);
@ -428,7 +431,7 @@ MarkLeafQuery(Node *subtree, Node *leaf, cpBool left, MarkContext *context)
PairInsert(leaf, subtree, context->tree); PairInsert(leaf, subtree, context->tree);
} else { } else {
if(subtree->STAMP < leaf->STAMP) PairInsert(subtree, leaf, context->tree); if(subtree->STAMP < leaf->STAMP) PairInsert(subtree, leaf, context->tree);
context->func(leaf->obj, subtree->obj, context->data); context->func(leaf->obj, subtree->obj, 0, context->data);
} }
} else { } else {
MarkLeafQuery(subtree->A, leaf, left, context); MarkLeafQuery(subtree->A, leaf, left, context);
@ -456,7 +459,7 @@ MarkLeaf(Node *leaf, MarkContext *context)
Pair *pair = leaf->PAIRS; Pair *pair = leaf->PAIRS;
while(pair){ while(pair){
if(leaf == pair->b.leaf){ if(leaf == pair->b.leaf){
context->func(pair->a.leaf->obj, leaf->obj, context->data); pair->id = context->func(pair->a.leaf->obj, leaf->obj, pair->id, context->data);
pair = pair->b.next; pair = pair->b.next;
} else { } else {
pair = pair->a.next; pair = pair->a.next;
@ -472,7 +475,7 @@ MarkSubtree(Node *subtree, MarkContext *context)
MarkLeaf(subtree, context); MarkLeaf(subtree, context);
} else { } else {
MarkSubtree(subtree->A, context); MarkSubtree(subtree->A, context);
MarkSubtree(subtree->B, context); MarkSubtree(subtree->B, context); // TODO Force TCO here?
} }
} }
@ -508,12 +511,12 @@ LeafUpdate(Node *leaf, cpBBTree *tree)
leaf->STAMP = GetMasterTree(tree)->stamp; leaf->STAMP = GetMasterTree(tree)->stamp;
return cpTrue; return cpTrue;
} else {
return cpFalse;
} }
return cpFalse;
} }
static void VoidQueryFunc(void *obj1, void *obj2, void *data){} static cpCollisionID VoidQueryFunc(void *obj1, void *obj2, cpCollisionID id, void *data){return id;}
static void static void
LeafAddPairs(Node *leaf, cpBBTree *tree) LeafAddPairs(Node *leaf, cpBBTree *tree)
@ -864,17 +867,17 @@ NodeRender(Node *node, int depth)
// glColor3f(1.0f - v, v, 0.0f); // glColor3f(1.0f - v, v, 0.0f);
glLineWidth(cpfmax(5.0f - depth, 1.0f)); glLineWidth(cpfmax(5.0f - depth, 1.0f));
glBegin(GL_LINES); { glBegin(GL_LINES); {
glVertex2F(bb.l, bb.b); glVertex2f(bb.l, bb.b);
glVertex2F(bb.l, bb.t); glVertex2f(bb.l, bb.t);
glVertex2F(bb.l, bb.t); glVertex2f(bb.l, bb.t);
glVertex2F(bb.r, bb.t); glVertex2f(bb.r, bb.t);
glVertex2F(bb.r, bb.t); glVertex2f(bb.r, bb.t);
glVertex2F(bb.r, bb.b); glVertex2f(bb.r, bb.b);
glVertex2F(bb.r, bb.b); glVertex2f(bb.r, bb.b);
glVertex2F(bb.l, bb.b); glVertex2f(bb.l, bb.b);
}; glEnd(); }; glEnd();
} }

File diff suppressed because it is too large Load Diff

View File

@ -47,7 +47,8 @@ cpPolyShapeTransformVerts(cpPolyShape *poly, cpVect p, cpVect rot)
t = cpfmax(t, v.y); t = cpfmax(t, v.y);
} }
return cpBBNew(l, b, r, t); cpFloat radius = poly->r;
return cpBBNew(l - radius, b - radius, r + radius, t + radius);
} }
static void static void
@ -84,10 +85,12 @@ cpPolyShapeNearestPointQuery(cpPolyShape *poly, cpVect p, cpNearestPointQueryInf
int count = poly->numVerts; int count = poly->numVerts;
cpSplittingPlane *planes = poly->tPlanes; cpSplittingPlane *planes = poly->tPlanes;
cpVect *verts = poly->tVerts; cpVect *verts = poly->tVerts;
cpFloat r = poly->r;
cpVect v0 = verts[count - 1]; cpVect v0 = verts[count - 1];
cpFloat minDist = INFINITY; cpFloat minDist = INFINITY;
cpVect closestPoint = cpvzero; cpVect closestPoint = cpvzero;
cpVect closestNormal = cpvzero;
cpBool outside = cpFalse; cpBool outside = cpFalse;
for(int i=0; i<count; i++){ for(int i=0; i<count; i++){
@ -100,14 +103,21 @@ cpPolyShapeNearestPointQuery(cpPolyShape *poly, cpVect p, cpNearestPointQueryInf
if(dist < minDist){ if(dist < minDist){
minDist = dist; minDist = dist;
closestPoint = closest; closestPoint = closest;
closestNormal = planes[i].n;
} }
v0 = v1; v0 = v1;
} }
cpFloat dist = (outside ? minDist : -minDist);
cpVect g = cpvmult(cpvsub(p, closestPoint), 1.0f/dist);
info->shape = (cpShape *)poly; info->shape = (cpShape *)poly;
info->p = closestPoint; // TODO div/0 info->p = cpvadd(closestPoint, cpvmult(g, r));
info->d = (outside ? minDist : -minDist); info->d = dist - r;
// Use the normal of the closest segment if the distance is small.
info->g = (minDist > MAGIC_EPSILON ? g : closestNormal);
} }
static void static void
@ -116,20 +126,22 @@ cpPolyShapeSegmentQuery(cpPolyShape *poly, cpVect a, cpVect b, cpSegmentQueryInf
cpSplittingPlane *axes = poly->tPlanes; cpSplittingPlane *axes = poly->tPlanes;
cpVect *verts = poly->tVerts; cpVect *verts = poly->tVerts;
int numVerts = poly->numVerts; int numVerts = poly->numVerts;
cpFloat r = poly->r;
for(int i=0; i<numVerts; i++){ for(int i=0; i<numVerts; i++){
cpVect n = axes[i].n; cpVect n = axes[i].n;
cpFloat an = cpvdot(a, n); cpFloat an = cpvdot(a, n);
if(axes[i].d > an) continue; cpFloat d = axes[i].d + r - an;
if(d > 0.0f) continue;
cpFloat bn = cpvdot(b, n); cpFloat bn = cpvdot(b, n);
cpFloat t = (axes[i].d - an)/(bn - an); cpFloat t = d/(bn - an);
if(t < 0.0f || 1.0f < t) continue; if(t < 0.0f || 1.0f < t) continue;
cpVect point = cpvlerp(a, b, t); cpVect point = cpvlerp(a, b, t);
cpFloat dt = -cpvcross(n, point); cpFloat dt = -cpvcross(n, point);
cpFloat dtMin = -cpvcross(n, verts[i]); cpFloat dtMin = -cpvcross(n, verts[(i - 1 + numVerts)%numVerts]);
cpFloat dtMax = -cpvcross(n, verts[(i+1)%numVerts]); cpFloat dtMax = -cpvcross(n, verts[i]);
if(dtMin <= dt && dt <= dtMax){ if(dtMin <= dt && dt <= dtMax){
info->shape = (cpShape *)poly; info->shape = (cpShape *)poly;
@ -137,6 +149,15 @@ cpPolyShapeSegmentQuery(cpPolyShape *poly, cpVect a, cpVect b, cpSegmentQueryInf
info->n = n; info->n = n;
} }
} }
// Also check against the beveled vertexes.
if(r > 0.0f){
for(int i=0; i<numVerts; i++){
cpSegmentQueryInfo circle_info = {NULL, 1.0f, cpvzero};
CircleSegmentQuery(&poly->shape, verts[i], r, a, b, &circle_info);
if(circle_info.t < info->t) (*info) = circle_info;
}
}
} }
static const cpShapeClass polyClass = { static const cpShapeClass polyClass = {
@ -164,14 +185,14 @@ cpPolyValidate(const cpVect *verts, const int numVerts)
} }
int int
cpPolyShapeGetNumVerts(cpShape *shape) cpPolyShapeGetNumVerts(const cpShape *shape)
{ {
cpAssertHard(shape->klass == &polyClass, "Shape is not a poly shape."); cpAssertHard(shape->klass == &polyClass, "Shape is not a poly shape.");
return ((cpPolyShape *)shape)->numVerts; return ((cpPolyShape *)shape)->numVerts;
} }
cpVect cpVect
cpPolyShapeGetVert(cpShape *shape, int idx) cpPolyShapeGetVert(const cpShape *shape, int idx)
{ {
cpAssertHard(shape->klass == &polyClass, "Shape is not a poly shape."); cpAssertHard(shape->klass == &polyClass, "Shape is not a poly shape.");
cpAssertHard(0 <= idx && idx < cpPolyShapeGetNumVerts(shape), "Index out of range."); cpAssertHard(0 <= idx && idx < cpPolyShapeGetNumVerts(shape), "Index out of range.");
@ -179,6 +200,13 @@ cpPolyShapeGetVert(cpShape *shape, int idx)
return ((cpPolyShape *)shape)->verts[idx]; return ((cpPolyShape *)shape)->verts[idx];
} }
cpFloat
cpPolyShapeGetRadius(const cpShape *shape)
{
cpAssertHard(shape->klass == &polyClass, "Shape is not a poly shape.");
return ((cpPolyShape *)shape)->r;
}
static void static void
setUpVerts(cpPolyShape *poly, int numVerts, const cpVect *verts, cpVect offset) setUpVerts(cpPolyShape *poly, int numVerts, const cpVect *verts, cpVect offset)
@ -202,21 +230,39 @@ setUpVerts(cpPolyShape *poly, int numVerts, const cpVect *verts, cpVect offset)
poly->planes[i].d = cpvdot(n, a); poly->planes[i].d = cpvdot(n, a);
} }
// TODO: Why did I add this? It duplicates work from above.
for(int i=0; i<numVerts; i++){
poly->planes[i] = cpSplittingPlaneNew(poly->verts[(i - 1 + numVerts)%numVerts], poly->verts[i]);
}
} }
cpPolyShape * cpPolyShape *
cpPolyShapeInit(cpPolyShape *poly, cpBody *body, int numVerts, const cpVect *verts, cpVect offset) cpPolyShapeInit(cpPolyShape *poly, cpBody *body, int numVerts, const cpVect *verts, cpVect offset)
{
return cpPolyShapeInit2(poly, body, numVerts, verts, offset, 0.0f);
}
cpPolyShape *
cpPolyShapeInit2(cpPolyShape *poly, cpBody *body, int numVerts, const cpVect *verts, cpVect offset, cpFloat radius)
{ {
setUpVerts(poly, numVerts, verts, offset); setUpVerts(poly, numVerts, verts, offset);
cpShapeInit((cpShape *)poly, &polyClass, body); cpShapeInit((cpShape *)poly, &polyClass, body);
poly->r = radius;
return poly; return poly;
} }
cpShape * cpShape *
cpPolyShapeNew(cpBody *body, int numVerts, cpVect *verts, cpVect offset) cpPolyShapeNew(cpBody *body, int numVerts, const cpVect *verts, cpVect offset)
{ {
return (cpShape *)cpPolyShapeInit(cpPolyShapeAlloc(), body, numVerts, verts, offset); return cpPolyShapeNew2(body, numVerts, verts, offset, 0.0f);
}
cpShape *
cpPolyShapeNew2(cpBody *body, int numVerts, const cpVect *verts, cpVect offset, cpFloat radius)
{
return (cpShape *)cpPolyShapeInit2(cpPolyShapeAlloc(), body, numVerts, verts, offset, radius);
} }
cpPolyShape * cpPolyShape *
@ -230,6 +276,12 @@ cpBoxShapeInit(cpPolyShape *poly, cpBody *body, cpFloat width, cpFloat height)
cpPolyShape * cpPolyShape *
cpBoxShapeInit2(cpPolyShape *poly, cpBody *body, cpBB box) cpBoxShapeInit2(cpPolyShape *poly, cpBody *body, cpBB box)
{
return cpBoxShapeInit3(poly, body, box, 0.0f);
}
cpPolyShape *
cpBoxShapeInit3(cpPolyShape *poly, cpBody *body, cpBB box, cpFloat radius)
{ {
cpVect verts[] = { cpVect verts[] = {
cpv(box.l, box.b), cpv(box.l, box.b),
@ -238,7 +290,7 @@ cpBoxShapeInit2(cpPolyShape *poly, cpBody *body, cpBB box)
cpv(box.r, box.b), cpv(box.r, box.b),
}; };
return cpPolyShapeInit(poly, body, 4, verts, cpvzero); return cpPolyShapeInit2(poly, body, 4, verts, cpvzero, radius);
} }
cpShape * cpShape *
@ -253,6 +305,12 @@ cpBoxShapeNew2(cpBody *body, cpBB box)
return (cpShape *)cpBoxShapeInit2(cpPolyShapeAlloc(), body, box); return (cpShape *)cpBoxShapeInit2(cpPolyShapeAlloc(), body, box);
} }
cpShape *
cpBoxShapeNew3(cpBody *body, cpBB box, cpFloat radius)
{
return (cpShape *)cpBoxShapeInit3(cpPolyShapeAlloc(), body, box, radius);
}
// Unsafe API (chipmunk_unsafe.h) // Unsafe API (chipmunk_unsafe.h)
void void
@ -262,3 +320,10 @@ cpPolyShapeSetVerts(cpShape *shape, int numVerts, cpVect *verts, cpVect offset)
cpPolyShapeDestroy((cpPolyShape *)shape); cpPolyShapeDestroy((cpPolyShape *)shape);
setUpVerts((cpPolyShape *)shape, numVerts, verts, offset); setUpVerts((cpPolyShape *)shape, numVerts, verts, offset);
} }
void
cpPolyShapeSetRadius(cpShape *shape, cpFloat radius)
{
cpAssertHard(shape->klass == &polyClass, "Shape is not a poly shape.");
((cpPolyShape *)shape)->r = radius;
}

View File

@ -103,7 +103,7 @@ cpShapeUpdate(cpShape *shape, cpVect pos, cpVect rot)
cpBool cpBool
cpShapePointQuery(cpShape *shape, cpVect p){ cpShapePointQuery(cpShape *shape, cpVect p){
cpNearestPointQueryInfo info = {NULL, cpvzero, INFINITY}; cpNearestPointQueryInfo info = {NULL, cpvzero, INFINITY, cpvzero};
cpShapeNearestPointQuery(shape, p, &info); cpShapeNearestPointQuery(shape, p, &info);
return (info.d < 0.0f); return (info.d < 0.0f);
@ -112,7 +112,7 @@ cpShapePointQuery(cpShape *shape, cpVect p){
cpFloat cpFloat
cpShapeNearestPointQuery(cpShape *shape, cpVect p, cpNearestPointQueryInfo *info) cpShapeNearestPointQuery(cpShape *shape, cpVect p, cpNearestPointQueryInfo *info)
{ {
cpNearestPointQueryInfo blank = {NULL, cpvzero, INFINITY}; cpNearestPointQueryInfo blank = {NULL, cpvzero, INFINITY, cpvzero};
if(info){ if(info){
(*info) = blank; (*info) = blank;
} else { } else {
@ -126,7 +126,7 @@ cpShapeNearestPointQuery(cpShape *shape, cpVect p, cpNearestPointQueryInfo *info
cpBool cpBool
cpShapeSegmentQuery(cpShape *shape, cpVect a, cpVect b, cpSegmentQueryInfo *info){ cpShapeSegmentQuery(cpShape *shape, cpVect a, cpVect b, cpSegmentQueryInfo *info){
cpSegmentQueryInfo blank = {NULL, 0.0f, cpvzero}; cpSegmentQueryInfo blank = {NULL, 1.0f, cpvzero};
if(info){ if(info){
(*info) = blank; (*info) = blank;
} else { } else {
@ -169,34 +169,15 @@ cpCicleShapeNearestPointQuery(cpCircleShape *circle, cpVect p, cpNearestPointQue
info->shape = (cpShape *)circle; info->shape = (cpShape *)circle;
info->p = cpvadd(circle->tc, cpvmult(delta, r/d)); // TODO div/0 info->p = cpvadd(circle->tc, cpvmult(delta, r/d)); // TODO div/0
info->d = d - r; info->d = d - r;
}
static void // Use up for the gradient if the distance is very small.
circleSegmentQuery(cpShape *shape, cpVect center, cpFloat r, cpVect a, cpVect b, cpSegmentQueryInfo *info) info->g = (d > MAGIC_EPSILON ? cpvmult(delta, 1.0f/d) : cpv(0.0f, 1.0f));
{
cpVect da = cpvsub(a, center);
cpVect db = cpvsub(b, center);
cpFloat qa = cpvdot(da, da) - 2.0f*cpvdot(da, db) + cpvdot(db, db);
cpFloat qb = -2.0f*cpvdot(da, da) + 2.0f*cpvdot(da, db);
cpFloat qc = cpvdot(da, da) - r*r;
cpFloat det = qb*qb - 4.0f*qa*qc;
if(det >= 0.0f){
cpFloat t = (-qb - cpfsqrt(det))/(2.0f*qa);
if(0.0f<= t && t <= 1.0f){
info->shape = shape;
info->t = t;
info->n = cpvnormalize(cpvlerp(da, db, t));
}
}
} }
static void static void
cpCircleShapeSegmentQuery(cpCircleShape *circle, cpVect a, cpVect b, cpSegmentQueryInfo *info) cpCircleShapeSegmentQuery(cpCircleShape *circle, cpVect a, cpVect b, cpSegmentQueryInfo *info)
{ {
circleSegmentQuery((cpShape *)circle, circle->tc, circle->r, a, b, info); CircleSegmentQuery((cpShape *)circle, circle->tc, circle->r, a, b, info);
} }
static const cpShapeClass cpCircleShapeClass = { static const cpShapeClass cpCircleShapeClass = {
@ -270,10 +251,14 @@ cpSegmentShapeNearestPointQuery(cpSegmentShape *seg, cpVect p, cpNearestPointQue
cpVect delta = cpvsub(p, closest); cpVect delta = cpvsub(p, closest);
cpFloat d = cpvlength(delta); cpFloat d = cpvlength(delta);
cpFloat r = seg->r; cpFloat r = seg->r;
cpVect g = cpvmult(delta, 1.0f/d);
info->shape = (cpShape *)seg; info->shape = (cpShape *)seg;
info->p = (d ? cpvadd(closest, cpvmult(delta, r/d)) : closest); info->p = (d ? cpvadd(closest, cpvmult(g, r)) : closest);
info->d = d - r; info->d = d - r;
// Use the segment's normal if the distance is very small.
info->g = (d > MAGIC_EPSILON ? g : seg->n);
} }
static void static void
@ -304,8 +289,8 @@ cpSegmentShapeSegmentQuery(cpSegmentShape *seg, cpVect a, cpVect b, cpSegmentQue
} else if(r != 0.0f){ } else if(r != 0.0f){
cpSegmentQueryInfo info1 = {NULL, 1.0f, cpvzero}; cpSegmentQueryInfo info1 = {NULL, 1.0f, cpvzero};
cpSegmentQueryInfo info2 = {NULL, 1.0f, cpvzero}; cpSegmentQueryInfo info2 = {NULL, 1.0f, cpvzero};
circleSegmentQuery((cpShape *)seg, seg->ta, seg->r, a, b, &info1); CircleSegmentQuery((cpShape *)seg, seg->ta, seg->r, a, b, &info1);
circleSegmentQuery((cpShape *)seg, seg->tb, seg->r, a, b, &info2); CircleSegmentQuery((cpShape *)seg, seg->tb, seg->r, a, b, &info2);
if(info1.t < info2.t){ if(info1.t < info2.t){
(*info) = info1; (*info) = info1;

View File

@ -362,7 +362,7 @@ query_helper(cpSpaceHash *hash, cpSpaceHashBin **bin_ptr, void *obj, cpSpatialIn
if(hand->stamp == hash->stamp || obj == other){ if(hand->stamp == hash->stamp || obj == other){
continue; continue;
} else if(other){ } else if(other){
func(obj, other, data); func(obj, other, 0, data);
hand->stamp = hash->stamp; hand->stamp = hash->stamp;
} else { } else {
// The object for this handle has been removed // The object for this handle has been removed

View File

@ -31,8 +31,8 @@ struct PointQueryContext {
void *data; void *data;
}; };
static void static cpCollisionID
PointQuery(struct PointQueryContext *context, cpShape *shape, void *data) PointQuery(struct PointQueryContext *context, cpShape *shape, cpCollisionID id, void *data)
{ {
if( if(
!(shape->group && context->group == shape->group) && (context->layers&shape->layers) && !(shape->group && context->group == shape->group) && (context->layers&shape->layers) &&
@ -40,6 +40,8 @@ PointQuery(struct PointQueryContext *context, cpShape *shape, void *data)
){ ){
context->func(shape, context->data); context->func(shape, context->data);
} }
return id;
} }
void void
@ -79,8 +81,8 @@ struct NearestPointQueryContext {
cpSpaceNearestPointQueryFunc func; cpSpaceNearestPointQueryFunc func;
}; };
static void static cpCollisionID
NearestPointQuery(struct NearestPointQueryContext *context, cpShape *shape, void *data) NearestPointQuery(struct NearestPointQueryContext *context, cpShape *shape, cpCollisionID id, void *data)
{ {
if( if(
!(shape->group && context->group == shape->group) && (context->layers&shape->layers) !(shape->group && context->group == shape->group) && (context->layers&shape->layers)
@ -90,6 +92,8 @@ NearestPointQuery(struct NearestPointQueryContext *context, cpShape *shape, void
if(info.shape && info.d < context->maxDistance) context->func(shape, info.d, info.p, data); if(info.shape && info.d < context->maxDistance) context->func(shape, info.d, info.p, data);
} }
return id;
} }
void void
@ -104,8 +108,8 @@ cpSpaceNearestPointQuery(cpSpace *space, cpVect point, cpFloat maxDistance, cpLa
} cpSpaceUnlock(space, cpTrue); } cpSpaceUnlock(space, cpTrue);
} }
static void static cpCollisionID
NearestPointQueryNearest(struct NearestPointQueryContext *context, cpShape *shape, cpNearestPointQueryInfo *out) NearestPointQueryNearest(struct NearestPointQueryContext *context, cpShape *shape, cpCollisionID id, cpNearestPointQueryInfo *out)
{ {
if( if(
!(shape->group && context->group == shape->group) && (context->layers&shape->layers) && !shape->sensor !(shape->group && context->group == shape->group) && (context->layers&shape->layers) && !shape->sensor
@ -115,12 +119,14 @@ NearestPointQueryNearest(struct NearestPointQueryContext *context, cpShape *shap
if(info.d < out->d) (*out) = info; if(info.d < out->d) (*out) = info;
} }
return id;
} }
cpShape * cpShape *
cpSpaceNearestPointQueryNearest(cpSpace *space, cpVect point, cpFloat maxDistance, cpLayers layers, cpGroup group, cpNearestPointQueryInfo *out) cpSpaceNearestPointQueryNearest(cpSpace *space, cpVect point, cpFloat maxDistance, cpLayers layers, cpGroup group, cpNearestPointQueryInfo *out)
{ {
cpNearestPointQueryInfo info = {NULL, cpvzero, maxDistance}; cpNearestPointQueryInfo info = {NULL, cpvzero, maxDistance, cpvzero};
if(out){ if(out){
(*out) = info; (*out) = info;
} else { } else {
@ -228,8 +234,8 @@ struct BBQueryContext {
cpSpaceBBQueryFunc func; cpSpaceBBQueryFunc func;
}; };
static void static cpCollisionID
BBQuery(struct BBQueryContext *context, cpShape *shape, void *data) BBQuery(struct BBQueryContext *context, cpShape *shape, cpCollisionID id, void *data)
{ {
if( if(
!(shape->group && context->group == shape->group) && (context->layers&shape->layers) && !(shape->group && context->group == shape->group) && (context->layers&shape->layers) &&
@ -237,6 +243,8 @@ BBQuery(struct BBQueryContext *context, cpShape *shape, void *data)
){ ){
context->func(shape, data); context->func(shape, data);
} }
return id;
} }
void void
@ -259,24 +267,24 @@ struct ShapeQueryContext {
}; };
// Callback from the spatial hash. // Callback from the spatial hash.
static void static cpCollisionID
ShapeQuery(cpShape *a, cpShape *b, struct ShapeQueryContext *context) ShapeQuery(cpShape *a, cpShape *b, cpCollisionID id, struct ShapeQueryContext *context)
{ {
// Reject any of the simple cases // Reject any of the simple cases
if( if(
(a->group && a->group == b->group) || (a->group && a->group == b->group) ||
!(a->layers & b->layers) || !(a->layers & b->layers) ||
a == b a == b
) return; ) return id;
cpContact contacts[CP_MAX_CONTACTS_PER_ARBITER]; cpContact contacts[CP_MAX_CONTACTS_PER_ARBITER];
int numContacts = 0; int numContacts = 0;
// Shape 'a' should have the lower shape type. (required by cpCollideShapes() ) // Shape 'a' should have the lower shape type. (required by cpCollideShapes() )
if(a->klass->type <= b->klass->type){ if(a->klass->type <= b->klass->type){
numContacts = cpCollideShapes(a, b, contacts); numContacts = cpCollideShapes(a, b, &id, contacts);
} else { } else {
numContacts = cpCollideShapes(b, a, contacts); numContacts = cpCollideShapes(b, a, &id, contacts);
for(int i=0; i<numContacts; i++) contacts[i].n = cpvneg(contacts[i].n); for(int i=0; i<numContacts; i++) contacts[i].n = cpvneg(contacts[i].n);
} }
@ -296,6 +304,8 @@ ShapeQuery(cpShape *a, cpShape *b, struct ShapeQueryContext *context)
context->func(b, &set, context->data); context->func(b, &set, context->data);
} }
} }
return id;
} }
cpBool cpBool

View File

@ -219,19 +219,20 @@ queryReject(cpShape *a, cpShape *b)
} }
// Callback from the spatial hash. // Callback from the spatial hash.
void cpCollisionID
cpSpaceCollideShapes(cpShape *a, cpShape *b, cpSpace *space) cpSpaceCollideShapes(cpShape *a, cpShape *b, cpCollisionID id, cpSpace *space)
{ {
// Reject any of the simple cases // Reject any of the simple cases
if(queryReject(a,b)) return; if(queryReject(a,b)) return id;
cpCollisionHandler *handler = cpSpaceLookupHandler(space, a->collision_type, b->collision_type); cpCollisionHandler *handler = cpSpaceLookupHandler(space, a->collision_type, b->collision_type);
cpBool sensor = a->sensor || b->sensor; cpBool sensor = a->sensor || b->sensor;
if(sensor && handler == &cpDefaultCollisionHandler) return; if(sensor && handler == &cpDefaultCollisionHandler) return id;
// Shape 'a' should have the lower shape type. (required by cpCollideShapes() ) // Shape 'a' should have the lower shape type. (required by cpCollideShapes() )
if(a->klass->type > b->klass->type){ // TODO remove me: a < b comparison is for debugging collisions
if(a->klass->type > b->klass->type || (a->klass->type == b->klass->type && a < b)){
cpShape *temp = a; cpShape *temp = a;
a = b; a = b;
b = temp; b = temp;
@ -239,8 +240,8 @@ cpSpaceCollideShapes(cpShape *a, cpShape *b, cpSpace *space)
// Narrow-phase collision detection. // Narrow-phase collision detection.
cpContact *contacts = cpContactBufferGetArray(space); cpContact *contacts = cpContactBufferGetArray(space);
int numContacts = cpCollideShapes(a, b, contacts); int numContacts = cpCollideShapes(a, b, &id, contacts);
if(!numContacts) return; // Shapes are not colliding. if(!numContacts) return id; // Shapes are not colliding.
cpSpacePushContacts(space, numContacts); cpSpacePushContacts(space, numContacts);
// Get an arbiter from space->arbiterSet for the two shapes. // Get an arbiter from space->arbiterSet for the two shapes.
@ -277,6 +278,7 @@ cpSpaceCollideShapes(cpShape *a, cpShape *b, cpSpace *space)
// Time stamp the arbiter so we know it was used recently. // Time stamp the arbiter so we know it was used recently.
arb->stamp = space->stamp; arb->stamp = space->stamp;
return id;
} }
// Hashset filter func to throw away old arbiters. // Hashset filter func to throw away old arbiters.

View File

@ -183,7 +183,7 @@ cpSweep1DQuery(cpSweep1D *sweep, void *obj, cpBB bb, cpSpatialIndexQueryFunc fun
TableCell *table = sweep->table; TableCell *table = sweep->table;
for(int i=0, count=sweep->num; i<count; i++){ for(int i=0, count=sweep->num; i<count; i++){
TableCell cell = table[i]; TableCell cell = table[i];
if(BoundsOverlap(bounds, cell.bounds) && obj != cell.obj) func(obj, cell.obj, data); if(BoundsOverlap(bounds, cell.bounds) && obj != cell.obj) func(obj, cell.obj, 0, data);
} }
} }
@ -223,7 +223,7 @@ cpSweep1DReindexQuery(cpSweep1D *sweep, cpSpatialIndexQueryFunc func, void *data
cpFloat max = cell.bounds.max; cpFloat max = cell.bounds.max;
for(int j=i+1; table[j].bounds.min < max && j<count; j++){ for(int j=i+1; table[j].bounds.min < max && j<count; j++){
func(cell.obj, table[j].obj, data); func(cell.obj, table[j].obj, 0, data);
} }
} }

View File

@ -1 +1 @@
fa70974de744fb12ec4f753989e6e0a7eb9fc73a d53bc7d6e68a49984c5971344f59bba8414d142b

View File

@ -32,7 +32,7 @@ ChipmunkTestLayer::ChipmunkTestLayer()
// title // title
auto label = LabelTTF::create("Multi touch the screen", "Marker Felt", 36); auto label = LabelTTF::create("Multi touch the screen", "Marker Felt", 36);
label->setPosition(Point( VisibleRect::center().x, VisibleRect::top().y - 30)); label->setPosition(cocos2d::Point( VisibleRect::center().x, VisibleRect::top().y - 30));
this->addChild(label, -1); this->addChild(label, -1);
// reset button // reset button
@ -52,7 +52,7 @@ ChipmunkTestLayer::ChipmunkTestLayer()
#endif #endif
addChild(parent, 0, kTagParentNode); addChild(parent, 0, kTagParentNode);
addNewSpriteAtPosition(Point(200,200)); addNewSpriteAtPosition(cocos2d::Point(200,200));
// menu for debug layer // menu for debug layer
MenuItemFont::setFontSize(18); MenuItemFont::setFontSize(18);
@ -60,7 +60,7 @@ ChipmunkTestLayer::ChipmunkTestLayer()
auto menu = Menu::create(item, NULL); auto menu = Menu::create(item, NULL);
this->addChild(menu); this->addChild(menu);
menu->setPosition(Point(VisibleRect::right().x-100, VisibleRect::top().y-60)); menu->setPosition(cocos2d::Point(VisibleRect::right().x-100, VisibleRect::top().y-60));
scheduleUpdate(); scheduleUpdate();
#else #else
@ -160,7 +160,7 @@ void ChipmunkTestLayer::createResetButton()
auto menu = Menu::create(reset, NULL); auto menu = Menu::create(reset, NULL);
menu->setPosition(Point(VisibleRect::center().x, VisibleRect::bottom().y + 30)); menu->setPosition(cocos2d::Point(VisibleRect::center().x, VisibleRect::bottom().y + 30));
this->addChild(menu, -1); this->addChild(menu, -1);
} }
@ -174,7 +174,7 @@ void ChipmunkTestLayer::reset(Ref* sender)
s->release(); s->release();
} }
void ChipmunkTestLayer::addNewSpriteAtPosition(Point pos) void ChipmunkTestLayer::addNewSpriteAtPosition(cocos2d::Point pos)
{ {
#if CC_ENABLE_CHIPMUNK_INTEGRATION #if CC_ENABLE_CHIPMUNK_INTEGRATION
int posx, posy; int posx, posy;
@ -205,7 +205,7 @@ void ChipmunkTestLayer::addNewSpriteAtPosition(Point pos)
shape->e = 0.5f; shape->u = 0.5f; shape->e = 0.5f; shape->u = 0.5f;
cpSpaceAddShape(_space, shape); cpSpaceAddShape(_space, shape);
auto sprite = PhysicsSprite::createWithTexture(_spriteTexture, Rect(posx, posy, 85, 121)); auto sprite = PhysicsSprite::createWithTexture(_spriteTexture, cocos2d::Rect(posx, posy, 85, 121));
parent->addChild(sprite); parent->addChild(sprite);
sprite->setCPBody(body); sprite->setCPBody(body);
@ -242,7 +242,7 @@ void ChipmunkTestLayer::onAcceleration(Acceleration* acc, Event* event)
prevX = accelX; prevX = accelX;
prevY = accelY; prevY = accelY;
auto v = Point( accelX, accelY); auto v = cocos2d::Point( accelX, accelY);
v = v * 200; v = v * 200;
_space->gravity = cpv(v.x, v.y); _space->gravity = cpv(v.x, v.y);
} }

View File

@ -21,7 +21,7 @@ public:
void createResetButton(); void createResetButton();
void reset(Ref* sender); void reset(Ref* sender);
void addNewSpriteAtPosition(Point p); void addNewSpriteAtPosition(cocos2d::Point p);
void update(float dt); void update(float dt);
void toggleDebugCallback(Ref* sender); void toggleDebugCallback(Ref* sender);
void onTouchesEnded(const std::vector<Touch*>& touches, Event* event); void onTouchesEnded(const std::vector<Touch*>& touches, Event* event);

View File

@ -1040,7 +1040,7 @@ void TestColliderDetector::update(float delta)
float minx = 0, miny = 0, maxx = 0, maxy = 0; float minx = 0, miny = 0, maxx = 0, maxy = 0;
size_t length = vertexList.size(); size_t length = vertexList.size();
for (int i = 0; i<length; i++) for (size_t i = 0; i<length; i++)
{ {
Point vertex = vertexList.at(i); Point vertex = vertexList.at(i);
if (i == 0) if (i == 0)

View File

@ -48,7 +48,7 @@ void CustomImageView::initRenderer()
ImageView::initRenderer(); ImageView::initRenderer();
_label = LabelTTF::create(); _label = LabelTTF::create();
CCNodeRGBA::addChild(_label, getZOrder() + 1, -1); CCNodeRGBA::addChild(_label, getLocalZOrder() + 1, -1);
} }
void CustomImageView::setText(const std::string &text) void CustomImageView::setText(const std::string &text)

View File

@ -72,7 +72,7 @@ void CustomParticleWidget::setParticlePlist(const char *plist)
_emitter->removeFromParent(); _emitter->removeFromParent();
_emitter = ParticleSystemQuad::create(plist); _emitter = ParticleSystemQuad::create(plist);
} }
Node::addChild(_emitter , getZOrder() + 1, -1); Node::addChild(_emitter , getLocalZOrder() + 1, -1);
_emitterPlist = plist; _emitterPlist = plist;
} }

View File

@ -39,7 +39,7 @@ bool UILayoutTest_Editor::init()
left_button->getSize().height)); left_button->getSize().height));
left_button->setTouchEnabled(true); left_button->setTouchEnabled(true);
left_button->addTouchEventListener(this, toucheventselector(UIScene_Editor::previousCallback)); left_button->addTouchEventListener(this, toucheventselector(UIScene_Editor::previousCallback));
left_button->setZOrder(_layout->getZOrder() + 1); left_button->setLocalZOrder(_layout->getLocalZOrder() + 1);
_layout->addChild(left_button); _layout->addChild(left_button);
Button* right_button = Button::create(); Button* right_button = Button::create();
@ -47,7 +47,7 @@ bool UILayoutTest_Editor::init()
right_button->setPosition(Point(_layout->getSize().width / 2 + right_button->getSize().width, right_button->setPosition(Point(_layout->getSize().width / 2 + right_button->getSize().width,
right_button->getSize().height)); right_button->getSize().height));
right_button->setTouchEnabled(true); right_button->setTouchEnabled(true);
right_button->setZOrder(_layout->getZOrder() + 1); right_button->setLocalZOrder(_layout->getLocalZOrder() + 1);
right_button->addTouchEventListener(this, toucheventselector(UIScene_Editor::nextCallback)); right_button->addTouchEventListener(this, toucheventselector(UIScene_Editor::nextCallback));
_layout->addChild(right_button); _layout->addChild(right_button);
@ -94,7 +94,7 @@ bool UILayoutTest_Color_Editor::init()
left_button->getSize().height)); left_button->getSize().height));
left_button->setTouchEnabled(true); left_button->setTouchEnabled(true);
left_button->addTouchEventListener(this, toucheventselector(UIScene_Editor::previousCallback)); left_button->addTouchEventListener(this, toucheventselector(UIScene_Editor::previousCallback));
left_button->setZOrder(_layout->getZOrder() + 1); left_button->setLocalZOrder(_layout->getLocalZOrder() + 1);
_layout->addChild(left_button); _layout->addChild(left_button);
Button* right_button = Button::create(); Button* right_button = Button::create();
@ -102,7 +102,7 @@ bool UILayoutTest_Color_Editor::init()
right_button->setPosition(Point(_layout->getSize().width / 2 + right_button->getSize().width, right_button->setPosition(Point(_layout->getSize().width / 2 + right_button->getSize().width,
right_button->getSize().height)); right_button->getSize().height));
right_button->setTouchEnabled(true); right_button->setTouchEnabled(true);
right_button->setZOrder(_layout->getZOrder() + 1); right_button->setLocalZOrder(_layout->getLocalZOrder() + 1);
right_button->addTouchEventListener(this, toucheventselector(UIScene_Editor::nextCallback)); right_button->addTouchEventListener(this, toucheventselector(UIScene_Editor::nextCallback));
_layout->addChild(right_button); _layout->addChild(right_button);
@ -149,7 +149,7 @@ bool UILayoutTest_Gradient_Editor::init()
left_button->getSize().height)); left_button->getSize().height));
left_button->setTouchEnabled(true); left_button->setTouchEnabled(true);
left_button->addTouchEventListener(this, toucheventselector(UIScene_Editor::previousCallback)); left_button->addTouchEventListener(this, toucheventselector(UIScene_Editor::previousCallback));
left_button->setZOrder(_layout->getZOrder() + 1); left_button->setLocalZOrder(_layout->getLocalZOrder() + 1);
_layout->addChild(left_button); _layout->addChild(left_button);
Button* right_button = Button::create(); Button* right_button = Button::create();
@ -157,7 +157,7 @@ bool UILayoutTest_Gradient_Editor::init()
right_button->setPosition(Point(_layout->getSize().width / 2 + right_button->getSize().width, right_button->setPosition(Point(_layout->getSize().width / 2 + right_button->getSize().width,
right_button->getSize().height)); right_button->getSize().height));
right_button->setTouchEnabled(true); right_button->setTouchEnabled(true);
right_button->setZOrder(_layout->getZOrder() + 1); right_button->setLocalZOrder(_layout->getLocalZOrder() + 1);
right_button->addTouchEventListener(this, toucheventselector(UIScene_Editor::nextCallback)); right_button->addTouchEventListener(this, toucheventselector(UIScene_Editor::nextCallback));
_layout->addChild(right_button); _layout->addChild(right_button);
@ -204,7 +204,7 @@ bool UILayoutTest_BackGroundImage_Editor::init()
left_button->getSize().height * 0.625)); left_button->getSize().height * 0.625));
left_button->setTouchEnabled(true); left_button->setTouchEnabled(true);
left_button->addTouchEventListener(this, toucheventselector(UIScene_Editor::previousCallback)); left_button->addTouchEventListener(this, toucheventselector(UIScene_Editor::previousCallback));
left_button->setZOrder(_layout->getZOrder() + 1); left_button->setLocalZOrder(_layout->getLocalZOrder() + 1);
_layout->addChild(left_button); _layout->addChild(left_button);
Button* right_button = Button::create(); Button* right_button = Button::create();
@ -212,7 +212,7 @@ bool UILayoutTest_BackGroundImage_Editor::init()
right_button->setPosition(Point(_layout->getSize().width / 2 + right_button->getSize().width, right_button->setPosition(Point(_layout->getSize().width / 2 + right_button->getSize().width,
right_button->getSize().height * 0.625)); right_button->getSize().height * 0.625));
right_button->setTouchEnabled(true); right_button->setTouchEnabled(true);
right_button->setZOrder(_layout->getZOrder() + 1); right_button->setLocalZOrder(_layout->getLocalZOrder() + 1);
right_button->addTouchEventListener(this, toucheventselector(UIScene_Editor::nextCallback)); right_button->addTouchEventListener(this, toucheventselector(UIScene_Editor::nextCallback));
_layout->addChild(right_button); _layout->addChild(right_button);
@ -259,7 +259,7 @@ bool UILayoutTest_BackGroundImage_Scale9_Editor::init()
left_button->getSize().height)); left_button->getSize().height));
left_button->setTouchEnabled(true); left_button->setTouchEnabled(true);
left_button->addTouchEventListener(this, toucheventselector(UIScene_Editor::previousCallback)); left_button->addTouchEventListener(this, toucheventselector(UIScene_Editor::previousCallback));
left_button->setZOrder(_layout->getZOrder() + 1); left_button->setLocalZOrder(_layout->getLocalZOrder() + 1);
_layout->addChild(left_button); _layout->addChild(left_button);
Button* right_button = Button::create(); Button* right_button = Button::create();
@ -267,7 +267,7 @@ bool UILayoutTest_BackGroundImage_Scale9_Editor::init()
right_button->setPosition(Point(_layout->getSize().width / 2 + right_button->getSize().width, right_button->setPosition(Point(_layout->getSize().width / 2 + right_button->getSize().width,
right_button->getSize().height)); right_button->getSize().height));
right_button->setTouchEnabled(true); right_button->setTouchEnabled(true);
right_button->setZOrder(_layout->getZOrder() + 1); right_button->setLocalZOrder(_layout->getLocalZOrder() + 1);
right_button->addTouchEventListener(this, toucheventselector(UIScene_Editor::nextCallback)); right_button->addTouchEventListener(this, toucheventselector(UIScene_Editor::nextCallback));
_layout->addChild(right_button); _layout->addChild(right_button);
@ -314,7 +314,7 @@ bool UILayoutTest_Layout_Linear_Vertical_Editor::init()
left_button->getSize().height * 0.625)); left_button->getSize().height * 0.625));
left_button->setTouchEnabled(true); left_button->setTouchEnabled(true);
left_button->addTouchEventListener(this, toucheventselector(UIScene_Editor::previousCallback)); left_button->addTouchEventListener(this, toucheventselector(UIScene_Editor::previousCallback));
left_button->setZOrder(_layout->getZOrder() + 1); left_button->setLocalZOrder(_layout->getLocalZOrder() + 1);
_layout->addChild(left_button); _layout->addChild(left_button);
Button* right_button = Button::create(); Button* right_button = Button::create();
@ -322,7 +322,7 @@ bool UILayoutTest_Layout_Linear_Vertical_Editor::init()
right_button->setPosition(Point(_layout->getSize().width / 2 + right_button->getSize().width, right_button->setPosition(Point(_layout->getSize().width / 2 + right_button->getSize().width,
right_button->getSize().height * 0.625)); right_button->getSize().height * 0.625));
right_button->setTouchEnabled(true); right_button->setTouchEnabled(true);
right_button->setZOrder(_layout->getZOrder() + 1); right_button->setLocalZOrder(_layout->getLocalZOrder() + 1);
right_button->addTouchEventListener(this, toucheventselector(UIScene_Editor::nextCallback)); right_button->addTouchEventListener(this, toucheventselector(UIScene_Editor::nextCallback));
_layout->addChild(right_button); _layout->addChild(right_button);
@ -369,7 +369,7 @@ bool UILayoutTest_Layout_Linear_Horizontal_Editor::init()
left_button->getSize().height * 0.625)); left_button->getSize().height * 0.625));
left_button->setTouchEnabled(true); left_button->setTouchEnabled(true);
left_button->addTouchEventListener(this, toucheventselector(UIScene_Editor::previousCallback)); left_button->addTouchEventListener(this, toucheventselector(UIScene_Editor::previousCallback));
left_button->setZOrder(_layout->getZOrder() + 1); left_button->setLocalZOrder(_layout->getLocalZOrder() + 1);
_layout->addChild(left_button); _layout->addChild(left_button);
Button* right_button = Button::create(); Button* right_button = Button::create();
@ -377,7 +377,7 @@ bool UILayoutTest_Layout_Linear_Horizontal_Editor::init()
right_button->setPosition(Point(_layout->getSize().width / 2 + right_button->getSize().width, right_button->setPosition(Point(_layout->getSize().width / 2 + right_button->getSize().width,
right_button->getSize().height * 0.625)); right_button->getSize().height * 0.625));
right_button->setTouchEnabled(true); right_button->setTouchEnabled(true);
right_button->setZOrder(_layout->getZOrder() + 1); right_button->setLocalZOrder(_layout->getLocalZOrder() + 1);
right_button->addTouchEventListener(this, toucheventselector(UIScene_Editor::nextCallback)); right_button->addTouchEventListener(this, toucheventselector(UIScene_Editor::nextCallback));
_layout->addChild(right_button); _layout->addChild(right_button);
@ -425,7 +425,7 @@ bool UILayoutTest_Layout_Relative_Align_Parent_Editor::init()
left_button->getSize().height * 0.625)); left_button->getSize().height * 0.625));
left_button->setTouchEnabled(true); left_button->setTouchEnabled(true);
left_button->addTouchEventListener(this, toucheventselector(UIScene_Editor::previousCallback)); left_button->addTouchEventListener(this, toucheventselector(UIScene_Editor::previousCallback));
left_button->setZOrder(_layout->getZOrder() + 1); left_button->setLocalZOrder(_layout->getLocalZOrder() + 1);
_layout->addChild(left_button); _layout->addChild(left_button);
Button* right_button = Button::create(); Button* right_button = Button::create();
@ -433,7 +433,7 @@ bool UILayoutTest_Layout_Relative_Align_Parent_Editor::init()
right_button->setPosition(Point(_layout->getSize().width / 2 + right_button->getSize().width, right_button->setPosition(Point(_layout->getSize().width / 2 + right_button->getSize().width,
right_button->getSize().height * 0.625)); right_button->getSize().height * 0.625));
right_button->setTouchEnabled(true); right_button->setTouchEnabled(true);
right_button->setZOrder(_layout->getZOrder() + 1); right_button->setLocalZOrder(_layout->getLocalZOrder() + 1);
right_button->addTouchEventListener(this, toucheventselector(UIScene_Editor::nextCallback)); right_button->addTouchEventListener(this, toucheventselector(UIScene_Editor::nextCallback));
_layout->addChild(right_button); _layout->addChild(right_button);
@ -480,7 +480,7 @@ bool UILayoutTest_Layout_Relative_Location_Editor::init()
left_button->getSize().height * 0.625)); left_button->getSize().height * 0.625));
left_button->setTouchEnabled(true); left_button->setTouchEnabled(true);
left_button->addTouchEventListener(this, toucheventselector(UIScene_Editor::previousCallback)); left_button->addTouchEventListener(this, toucheventselector(UIScene_Editor::previousCallback));
left_button->setZOrder(_layout->getZOrder() + 1); left_button->setLocalZOrder(_layout->getLocalZOrder() + 1);
_layout->addChild(left_button); _layout->addChild(left_button);
Button* right_button = Button::create(); Button* right_button = Button::create();
@ -488,7 +488,7 @@ bool UILayoutTest_Layout_Relative_Location_Editor::init()
right_button->setPosition(Point(_layout->getSize().width / 2 + right_button->getSize().width, right_button->setPosition(Point(_layout->getSize().width / 2 + right_button->getSize().width,
right_button->getSize().height * 0.625)); right_button->getSize().height * 0.625));
right_button->setTouchEnabled(true); right_button->setTouchEnabled(true);
right_button->setZOrder(_layout->getZOrder() + 1); right_button->setLocalZOrder(_layout->getLocalZOrder() + 1);
right_button->addTouchEventListener(this, toucheventselector(UIScene_Editor::nextCallback)); right_button->addTouchEventListener(this, toucheventselector(UIScene_Editor::nextCallback));
_layout->addChild(right_button); _layout->addChild(right_button);

View File

@ -42,7 +42,7 @@ bool UIListViewTest_Vertical_Editor::init()
left_button->getSize().height * 0.625)); left_button->getSize().height * 0.625));
left_button->setTouchEnabled(true); left_button->setTouchEnabled(true);
left_button->addTouchEventListener(this, toucheventselector(UIScene_Editor::previousCallback)); left_button->addTouchEventListener(this, toucheventselector(UIScene_Editor::previousCallback));
left_button->setZOrder(_layout->getZOrder() + 1); left_button->setLocalZOrder(_layout->getLocalZOrder() + 1);
_layout->addChild(left_button); _layout->addChild(left_button);
Button* right_button = Button::create(); Button* right_button = Button::create();
@ -50,7 +50,7 @@ bool UIListViewTest_Vertical_Editor::init()
right_button->setPosition(Point(_layout->getSize().width / 2 + right_button->getSize().width, right_button->setPosition(Point(_layout->getSize().width / 2 + right_button->getSize().width,
right_button->getSize().height * 0.625)); right_button->getSize().height * 0.625));
right_button->setTouchEnabled(true); right_button->setTouchEnabled(true);
right_button->setZOrder(_layout->getZOrder() + 1); right_button->setLocalZOrder(_layout->getLocalZOrder() + 1);
right_button->addTouchEventListener(this, toucheventselector(UIScene_Editor::nextCallback)); right_button->addTouchEventListener(this, toucheventselector(UIScene_Editor::nextCallback));
_layout->addChild(right_button); _layout->addChild(right_button);
@ -98,7 +98,7 @@ bool UIListViewTest_Horizontal_Editor::init()
left_button->getSize().height * 0.625)); left_button->getSize().height * 0.625));
left_button->setTouchEnabled(true); left_button->setTouchEnabled(true);
left_button->addTouchEventListener(this, toucheventselector(UIScene_Editor::previousCallback)); left_button->addTouchEventListener(this, toucheventselector(UIScene_Editor::previousCallback));
left_button->setZOrder(_layout->getZOrder() + 1); left_button->setLocalZOrder(_layout->getLocalZOrder() + 1);
_layout->addChild(left_button); _layout->addChild(left_button);
Button* right_button = Button::create(); Button* right_button = Button::create();
@ -106,7 +106,7 @@ bool UIListViewTest_Horizontal_Editor::init()
right_button->setPosition(Point(_layout->getSize().width / 2 + right_button->getSize().width, right_button->setPosition(Point(_layout->getSize().width / 2 + right_button->getSize().width,
right_button->getSize().height * 0.625)); right_button->getSize().height * 0.625));
right_button->setTouchEnabled(true); right_button->setTouchEnabled(true);
right_button->setZOrder(_layout->getZOrder() + 1); right_button->setLocalZOrder(_layout->getLocalZOrder() + 1);
right_button->addTouchEventListener(this, toucheventselector(UIScene_Editor::nextCallback)); right_button->addTouchEventListener(this, toucheventselector(UIScene_Editor::nextCallback));
_layout->addChild(right_button); _layout->addChild(right_button);
return true; return true;

View File

@ -40,7 +40,7 @@ bool UIPageViewTest_Editor::init()
left_button->getSize().height * 0.625)); left_button->getSize().height * 0.625));
left_button->setTouchEnabled(true); left_button->setTouchEnabled(true);
left_button->addTouchEventListener(this, toucheventselector(UIScene_Editor::previousCallback)); left_button->addTouchEventListener(this, toucheventselector(UIScene_Editor::previousCallback));
left_button->setZOrder(_layout->getZOrder() + 1); left_button->setLocalZOrder(_layout->getLocalZOrder() + 1);
_layout->addChild(left_button); _layout->addChild(left_button);
Button* right_button = Button::create(); Button* right_button = Button::create();
@ -48,7 +48,7 @@ bool UIPageViewTest_Editor::init()
right_button->setPosition(Point(_layout->getSize().width / 2 + right_button->getSize().width, right_button->setPosition(Point(_layout->getSize().width / 2 + right_button->getSize().width,
right_button->getSize().height * 0.625)); right_button->getSize().height * 0.625));
right_button->setTouchEnabled(true); right_button->setTouchEnabled(true);
right_button->setZOrder(_layout->getZOrder() + 1); right_button->setLocalZOrder(_layout->getLocalZOrder() + 1);
right_button->addTouchEventListener(this, toucheventselector(UIScene_Editor::nextCallback)); right_button->addTouchEventListener(this, toucheventselector(UIScene_Editor::nextCallback));
_layout->addChild(right_button); _layout->addChild(right_button);

View File

@ -36,7 +36,7 @@ bool UIRichTextTest::init()
button->setTitleText("switch"); button->setTitleText("switch");
button->setPosition(Point(widgetSize.width / 2.0f, widgetSize.height / 2.0f + button->getSize().height * 2.5)); button->setPosition(Point(widgetSize.width / 2.0f, widgetSize.height / 2.0f + button->getSize().height * 2.5));
button->addTouchEventListener(this, toucheventselector(UIRichTextTest::touchEvent)); button->addTouchEventListener(this, toucheventselector(UIRichTextTest::touchEvent));
button->setZOrder(10); button->setLocalZOrder(10);
_widget->addChild(button); _widget->addChild(button);
@ -69,7 +69,7 @@ bool UIRichTextTest::init()
_richText->pushBackElement(re6); _richText->pushBackElement(re6);
_richText->setPosition(Point(widgetSize.width / 2, widgetSize.height / 2)); _richText->setPosition(Point(widgetSize.width / 2, widgetSize.height / 2));
_richText->setZOrder(10); _richText->setLocalZOrder(10);
_widget->addChild(_richText); _widget->addChild(_richText);

View File

@ -39,7 +39,7 @@ bool UIScrollViewTest_Vertical_Editor::init()
left_button->getSize().height * 0.625)); left_button->getSize().height * 0.625));
left_button->setTouchEnabled(true); left_button->setTouchEnabled(true);
left_button->addTouchEventListener(this, toucheventselector(UIScene_Editor::previousCallback)); left_button->addTouchEventListener(this, toucheventselector(UIScene_Editor::previousCallback));
left_button->setZOrder(_layout->getZOrder() + 1); left_button->setLocalZOrder(_layout->getLocalZOrder() + 1);
_layout->addChild(left_button); _layout->addChild(left_button);
Button* right_button = Button::create(); Button* right_button = Button::create();
@ -47,7 +47,7 @@ bool UIScrollViewTest_Vertical_Editor::init()
right_button->setPosition(Point(_layout->getSize().width / 2 + right_button->getSize().width, right_button->setPosition(Point(_layout->getSize().width / 2 + right_button->getSize().width,
right_button->getSize().height * 0.625)); right_button->getSize().height * 0.625));
right_button->setTouchEnabled(true); right_button->setTouchEnabled(true);
right_button->setZOrder(_layout->getZOrder() + 1); right_button->setLocalZOrder(_layout->getLocalZOrder() + 1);
right_button->addTouchEventListener(this, toucheventselector(UIScene_Editor::nextCallback)); right_button->addTouchEventListener(this, toucheventselector(UIScene_Editor::nextCallback));
_layout->addChild(right_button); _layout->addChild(right_button);
@ -94,7 +94,7 @@ bool UIScrollViewTest_Horizontal_Editor::init()
left_button->getSize().height * 0.625)); left_button->getSize().height * 0.625));
left_button->setTouchEnabled(true); left_button->setTouchEnabled(true);
left_button->addTouchEventListener(this, toucheventselector(UIScene_Editor::previousCallback)); left_button->addTouchEventListener(this, toucheventselector(UIScene_Editor::previousCallback));
left_button->setZOrder(_layout->getZOrder() + 1); left_button->setLocalZOrder(_layout->getLocalZOrder() + 1);
_layout->addChild(left_button); _layout->addChild(left_button);
Button* right_button = Button::create(); Button* right_button = Button::create();
@ -102,7 +102,7 @@ bool UIScrollViewTest_Horizontal_Editor::init()
right_button->setPosition(Point(_layout->getSize().width / 2 + right_button->getSize().width, right_button->setPosition(Point(_layout->getSize().width / 2 + right_button->getSize().width,
right_button->getSize().height * 0.625)); right_button->getSize().height * 0.625));
right_button->setTouchEnabled(true); right_button->setTouchEnabled(true);
right_button->setZOrder(_layout->getZOrder() + 1); right_button->setLocalZOrder(_layout->getLocalZOrder() + 1);
right_button->addTouchEventListener(this, toucheventselector(UIScene_Editor::nextCallback)); right_button->addTouchEventListener(this, toucheventselector(UIScene_Editor::nextCallback));
_layout->addChild(right_button); _layout->addChild(right_button);
@ -149,7 +149,7 @@ bool UIScrollViewTest_Both_Editor::init()
left_button->getSize().height * 0.625)); left_button->getSize().height * 0.625));
left_button->setTouchEnabled(true); left_button->setTouchEnabled(true);
left_button->addTouchEventListener(this, toucheventselector(UIScene_Editor::previousCallback)); left_button->addTouchEventListener(this, toucheventselector(UIScene_Editor::previousCallback));
left_button->setZOrder(_layout->getZOrder() + 1); left_button->setLocalZOrder(_layout->getLocalZOrder() + 1);
_layout->addChild(left_button); _layout->addChild(left_button);
Button* right_button = Button::create(); Button* right_button = Button::create();
@ -157,7 +157,7 @@ bool UIScrollViewTest_Both_Editor::init()
right_button->setPosition(Point(_layout->getSize().width / 2 + right_button->getSize().width, right_button->setPosition(Point(_layout->getSize().width / 2 + right_button->getSize().width,
right_button->getSize().height * 0.625)); right_button->getSize().height * 0.625));
right_button->setTouchEnabled(true); right_button->setTouchEnabled(true);
right_button->setZOrder(_layout->getZOrder() + 1); right_button->setLocalZOrder(_layout->getLocalZOrder() + 1);
right_button->addTouchEventListener(this, toucheventselector(UIScene_Editor::nextCallback)); right_button->addTouchEventListener(this, toucheventselector(UIScene_Editor::nextCallback));
_layout->addChild(right_button); _layout->addChild(right_button);

View File

@ -336,7 +336,7 @@ void UITextFieldTest_LineWrap::textFieldEvent(Ref *pSender, TextFiledEventType t
{ {
TextField* textField = dynamic_cast<TextField*>(pSender); TextField* textField = dynamic_cast<TextField*>(pSender);
Size widgetSize = _widget->getSize(); Size widgetSize = _widget->getSize();
textField->runAction(CCMoveTo::create(0.225, textField->runAction(CCMoveTo::create(0.225f,
Point(widgetSize.width / 2.0f, widgetSize.height / 2.0f + textField->getContentSize().height / 2))); Point(widgetSize.width / 2.0f, widgetSize.height / 2.0f + textField->getContentSize().height / 2)));
textField->setTextHorizontalAlignment(TextHAlignment::LEFT); textField->setTextHorizontalAlignment(TextHAlignment::LEFT);
textField->setTextVerticalAlignment(TextVAlignment::TOP); textField->setTextVerticalAlignment(TextVAlignment::TOP);
@ -349,7 +349,7 @@ void UITextFieldTest_LineWrap::textFieldEvent(Ref *pSender, TextFiledEventType t
{ {
TextField* textField = dynamic_cast<TextField*>(pSender); TextField* textField = dynamic_cast<TextField*>(pSender);
Size widgetSize = _widget->getSize(); Size widgetSize = _widget->getSize();
textField->runAction(CCMoveTo::create(0.175, Point(widgetSize.width / 2.0f, widgetSize.height / 2.0f))); textField->runAction(CCMoveTo::create(0.175f, Point(widgetSize.width / 2.0f, widgetSize.height / 2.0f)));
textField->setTextHorizontalAlignment(TextHAlignment::CENTER); textField->setTextHorizontalAlignment(TextHAlignment::CENTER);
textField->setTextVerticalAlignment(TextVAlignment::CENTER); textField->setTextVerticalAlignment(TextVAlignment::CENTER);

View File

@ -37,7 +37,7 @@ bool UIWidgetAddNodeTest_Editor::init()
// Create the ui widget // Create the ui widget
Widget* widget = Widget::create(); Widget* widget = Widget::create();
widget->setPosition(Point(rootSize.width / 2.0f, rootSize.height / 2.0f)); widget->setPosition(Point(rootSize.width / 2.0f, rootSize.height / 2.0f));
widget->setZOrder(_layout->getZOrder() + 1); widget->setLocalZOrder(_layout->getLocalZOrder() + 1);
_layout->addChild(widget); _layout->addChild(widget);
Sprite* sprite = Sprite::create("cocosui/ccicon.png"); Sprite* sprite = Sprite::create("cocosui/ccicon.png");

View File

@ -199,7 +199,7 @@ void TMoveBy::serialize(const rapidjson::Value &val)
} }
else if (key == "IsReverse") else if (key == "IsReverse")
{ {
_reverse = (bool)(DICTOOL->getIntValue_json(subDict, "value")); _reverse = DICTOOL->getIntValue_json(subDict, "value") ? true : false;
continue; continue;
} }
} }
@ -337,7 +337,7 @@ void TRotateBy::serialize(const rapidjson::Value &val)
} }
else if (key == "IsReverse") else if (key == "IsReverse")
{ {
_reverse = (int)(DICTOOL->getIntValue_json(subDict, "value")); _reverse = (DICTOOL->getIntValue_json(subDict, "value")) ? true : false;
continue; continue;
} }
} }
@ -483,7 +483,7 @@ void TScaleBy::serialize(const rapidjson::Value &val)
} }
else if (key == "IsReverse") else if (key == "IsReverse")
{ {
_reverse = (bool)(DICTOOL->getIntValue_json(subDict, "value")); _reverse = (DICTOOL->getIntValue_json(subDict, "value")) ? true : false;
continue; continue;
} }
} }
@ -629,7 +629,7 @@ void TSkewBy::serialize(const rapidjson::Value &val)
} }
else if (key == "IsReverse") else if (key == "IsReverse")
{ {
_reverse = (bool)(DICTOOL->getIntValue_json(subDict, "value")); _reverse = DICTOOL->getIntValue_json(subDict, "value") ? true : false;
} }
} }
} }

View File

@ -255,7 +255,7 @@ void NodeVisible::serialize(const rapidjson::Value &val)
} }
else if (key == "Visible") else if (key == "Visible")
{ {
_visible = DICTOOL->getIntValue_json(subDict, "value"); _visible = DICTOOL->getIntValue_json(subDict, "value") ? true : false;
continue; continue;
} }
} }

View File

@ -1547,7 +1547,11 @@ TTFFontShadowAndStroke::TTFFontShadowAndStroke()
strokeShaodwTextDef._fontFillColor = tintColorBlue; strokeShaodwTextDef._fontFillColor = tintColorBlue;
// shadow + stroke label // shadow + stroke label
auto fontStrokeAndShadow = LabelTTF::createWithFontDefinition("Stroke & Shadow Blue Text", strokeShaodwTextDef); #if CC_TARGET_PLATFORM == CC_PLATFORM_WIN32
auto fontStrokeAndShadow = LabelTTF::createWithFontDefinition("Stroke && Shadow Blue Text", strokeShaodwTextDef);
#else
auto fontStrokeAndShadow = LabelTTF::createWithFontDefinition("Stroke &Shadow Blue Text", strokeShaodwTextDef);
#endif
// add label to the scene // add label to the scene
this->addChild(fontStrokeAndShadow); this->addChild(fontStrokeAndShadow);

View File

@ -845,7 +845,7 @@ void PhysicsDemoJoints::onEnter()
_scene->getPhysicsWorld()->addJoint(PhysicsJointPin::construct(sp1->getPhysicsBody(), box, sp1->getPosition())); _scene->getPhysicsWorld()->addJoint(PhysicsJointPin::construct(sp1->getPhysicsBody(), box, sp1->getPosition()));
_scene->getPhysicsWorld()->addJoint(PhysicsJointPin::construct(sp2->getPhysicsBody(), box, sp2->getPosition())); _scene->getPhysicsWorld()->addJoint(PhysicsJointPin::construct(sp2->getPhysicsBody(), box, sp2->getPosition()));
PhysicsJointRotaryLimit* joint = PhysicsJointRotaryLimit::construct(sp1->getPhysicsBody(), sp2->getPhysicsBody(), 0.0f, M_PI_2); PhysicsJointRotaryLimit* joint = PhysicsJointRotaryLimit::construct(sp1->getPhysicsBody(), sp2->getPhysicsBody(), 0.0f,(float) M_PI_2);
_scene->getPhysicsWorld()->addJoint(joint); _scene->getPhysicsWorld()->addJoint(joint);
this->addChild(sp1); this->addChild(sp1);
@ -861,7 +861,7 @@ void PhysicsDemoJoints::onEnter()
_scene->getPhysicsWorld()->addJoint(PhysicsJointPin::construct(sp1->getPhysicsBody(), box, sp1->getPosition())); _scene->getPhysicsWorld()->addJoint(PhysicsJointPin::construct(sp1->getPhysicsBody(), box, sp1->getPosition()));
_scene->getPhysicsWorld()->addJoint(PhysicsJointPin::construct(sp2->getPhysicsBody(), box, sp2->getPosition())); _scene->getPhysicsWorld()->addJoint(PhysicsJointPin::construct(sp2->getPhysicsBody(), box, sp2->getPosition()));
PhysicsJointRatchet* joint = PhysicsJointRatchet::construct(sp1->getPhysicsBody(), sp2->getPhysicsBody(), 0.0f, M_PI_2); PhysicsJointRatchet* joint = PhysicsJointRatchet::construct(sp1->getPhysicsBody(), sp2->getPhysicsBody(), 0.0f, (float)M_PI_2);
_scene->getPhysicsWorld()->addJoint(joint); _scene->getPhysicsWorld()->addJoint(joint);
this->addChild(sp1); this->addChild(sp1);
@ -893,7 +893,7 @@ void PhysicsDemoJoints::onEnter()
_scene->getPhysicsWorld()->addJoint(PhysicsJointPin::construct(sp1->getPhysicsBody(), box, sp1->getPosition())); _scene->getPhysicsWorld()->addJoint(PhysicsJointPin::construct(sp1->getPhysicsBody(), box, sp1->getPosition()));
_scene->getPhysicsWorld()->addJoint(PhysicsJointPin::construct(sp2->getPhysicsBody(), box, sp2->getPosition())); _scene->getPhysicsWorld()->addJoint(PhysicsJointPin::construct(sp2->getPhysicsBody(), box, sp2->getPosition()));
PhysicsJointMotor* joint = PhysicsJointMotor::construct(sp1->getPhysicsBody(), sp2->getPhysicsBody(), M_PI_2); PhysicsJointMotor* joint = PhysicsJointMotor::construct(sp1->getPhysicsBody(), sp2->getPhysicsBody(), (float)M_PI_2);
_scene->getPhysicsWorld()->addJoint(joint); _scene->getPhysicsWorld()->addJoint(joint);
this->addChild(sp1); this->addChild(sp1);
@ -1445,7 +1445,7 @@ void PhysicsContactTest::resetTest()
label->setPosition(Point(s.width/2, s.height-170)); label->setPosition(Point(s.width/2, s.height-170));
auto wall = Node::create(); auto wall = Node::create();
wall->setPhysicsBody(PhysicsBody::createEdgeBox(VisibleRect::getVisibleRect().size, PhysicsMaterial(0.1, 1, 0.0))); wall->setPhysicsBody(PhysicsBody::createEdgeBox(VisibleRect::getVisibleRect().size, PhysicsMaterial(0.1f, 1, 0.0f)));
wall->setPosition(VisibleRect::center()); wall->setPosition(VisibleRect::center());
root->addChild(wall); root->addChild(wall);
@ -1463,7 +1463,7 @@ void PhysicsContactTest::resetTest()
position.y = position.y * CCRANDOM_0_1(); position.y = position.y * CCRANDOM_0_1();
position = VisibleRect::leftBottom() + position + Point(size.width/2, size.height/2); position = VisibleRect::leftBottom() + position + Point(size.width/2, size.height/2);
Vect velocity((CCRANDOM_0_1() - 0.5)*200, (CCRANDOM_0_1() - 0.5)*200); Vect velocity((CCRANDOM_0_1() - 0.5)*200, (CCRANDOM_0_1() - 0.5)*200);
auto box = makeBox(position, size, 1, PhysicsMaterial(0.1, 1, 0.0)); auto box = makeBox(position, size, 1, PhysicsMaterial(0.1f, 1, 0.0f));
box->getPhysicsBody()->setVelocity(velocity); box->getPhysicsBody()->setVelocity(velocity);
box->getPhysicsBody()->setCategoryBitmask(0x01); // 0001 box->getPhysicsBody()->setCategoryBitmask(0x01); // 0001
box->getPhysicsBody()->setContactTestBitmask(0x04); // 0100 box->getPhysicsBody()->setContactTestBitmask(0x04); // 0100
@ -1481,7 +1481,7 @@ void PhysicsContactTest::resetTest()
position.y = position.y * CCRANDOM_0_1(); position.y = position.y * CCRANDOM_0_1();
position = VisibleRect::leftBottom() + position + Point(size.width/2, size.height/2); position = VisibleRect::leftBottom() + position + Point(size.width/2, size.height/2);
Vect velocity((CCRANDOM_0_1() - 0.5)*200, (CCRANDOM_0_1() - 0.5)*200); Vect velocity((CCRANDOM_0_1() - 0.5)*200, (CCRANDOM_0_1() - 0.5)*200);
auto box = makeBox(position, size, 2, PhysicsMaterial(0.1, 1, 0.0)); auto box = makeBox(position, size, 2, PhysicsMaterial(0.1f, 1, 0.0f));
box->getPhysicsBody()->setVelocity(velocity); box->getPhysicsBody()->setVelocity(velocity);
box->getPhysicsBody()->setCategoryBitmask(0x02); // 0010 box->getPhysicsBody()->setCategoryBitmask(0x02); // 0010
box->getPhysicsBody()->setContactTestBitmask(0x08); // 1000 box->getPhysicsBody()->setContactTestBitmask(0x08); // 1000
@ -1499,7 +1499,7 @@ void PhysicsContactTest::resetTest()
position.y = position.y * CCRANDOM_0_1(); position.y = position.y * CCRANDOM_0_1();
position = VisibleRect::leftBottom() + position + Point(size.width/2, size.height/2); position = VisibleRect::leftBottom() + position + Point(size.width/2, size.height/2);
Vect velocity((CCRANDOM_0_1() - 0.5)*300, (CCRANDOM_0_1() - 0.5)*300); Vect velocity((CCRANDOM_0_1() - 0.5)*300, (CCRANDOM_0_1() - 0.5)*300);
auto triangle = makeTriangle(position, size, 1, PhysicsMaterial(0.1, 1, 0.0)); auto triangle = makeTriangle(position, size, 1, PhysicsMaterial(0.1f, 1, 0.0f));
triangle->getPhysicsBody()->setVelocity(velocity); triangle->getPhysicsBody()->setVelocity(velocity);
triangle->getPhysicsBody()->setCategoryBitmask(0x04); // 0100 triangle->getPhysicsBody()->setCategoryBitmask(0x04); // 0100
triangle->getPhysicsBody()->setContactTestBitmask(0x01); // 0001 triangle->getPhysicsBody()->setContactTestBitmask(0x01); // 0001
@ -1517,7 +1517,7 @@ void PhysicsContactTest::resetTest()
position.y = position.y * CCRANDOM_0_1(); position.y = position.y * CCRANDOM_0_1();
position = VisibleRect::leftBottom() + position + Point(size.width/2, size.height/2); position = VisibleRect::leftBottom() + position + Point(size.width/2, size.height/2);
Vect velocity((CCRANDOM_0_1() - 0.5)*300, (CCRANDOM_0_1() - 0.5)*300); Vect velocity((CCRANDOM_0_1() - 0.5)*300, (CCRANDOM_0_1() - 0.5)*300);
auto triangle = makeTriangle(position, size, 2, PhysicsMaterial(0.1, 1, 0.0)); auto triangle = makeTriangle(position, size, 2, PhysicsMaterial(0.1f, 1, 0.0f));
triangle->getPhysicsBody()->setVelocity(velocity); triangle->getPhysicsBody()->setVelocity(velocity);
triangle->getPhysicsBody()->setCategoryBitmask(0x08); // 1000 triangle->getPhysicsBody()->setCategoryBitmask(0x08); // 1000
triangle->getPhysicsBody()->setContactTestBitmask(0x02); // 0010 triangle->getPhysicsBody()->setContactTestBitmask(0x02); // 0010
@ -1566,7 +1566,7 @@ void PhysicsPositionRotationTest::onEnter()
// anchor test // anchor test
auto anchorNode = Sprite::create("Images/YellowSquare.png"); auto anchorNode = Sprite::create("Images/YellowSquare.png");
anchorNode->setAnchorPoint(Point(0.1, 0.9)); anchorNode->setAnchorPoint(Point(0.1f, 0.9f));
anchorNode->setPosition(100, 100); anchorNode->setPosition(100, 100);
anchorNode->setScale(0.25); anchorNode->setScale(0.25);
anchorNode->setPhysicsBody(PhysicsBody::createBox(anchorNode->getContentSize()*anchorNode->getScale())); anchorNode->setPhysicsBody(PhysicsBody::createBox(anchorNode->getContentSize()*anchorNode->getScale()));

View File

@ -314,9 +314,9 @@ RenderTextureZbuffer::RenderTextureZbuffer()
label3->setPosition(Point(size.width / 2, size.height * 0.75f)); label3->setPosition(Point(size.width / 2, size.height * 0.75f));
this->addChild(label3); this->addChild(label3);
label->setVertexZ(50); label->setPositionZ(50);
label2->setVertexZ(0); label2->setPositionZ(0);
label3->setVertexZ(-50); label3->setPositionZ(-50);
SpriteFrameCache::getInstance()->addSpriteFramesWithFile("Images/bugs/circle.plist"); SpriteFrameCache::getInstance()->addSpriteFramesWithFile("Images/bugs/circle.plist");
mgr = SpriteBatchNode::create("Images/bugs/circle.png", 9); mgr = SpriteBatchNode::create("Images/bugs/circle.png", 9);
@ -341,15 +341,15 @@ RenderTextureZbuffer::RenderTextureZbuffer()
mgr->addChild(sp8, 2); mgr->addChild(sp8, 2);
mgr->addChild(sp9, 1); mgr->addChild(sp9, 1);
sp1->setVertexZ(400); sp1->setPositionZ(400);
sp2->setVertexZ(300); sp2->setPositionZ(300);
sp3->setVertexZ(200); sp3->setPositionZ(200);
sp4->setVertexZ(100); sp4->setPositionZ(100);
sp5->setVertexZ(0); sp5->setPositionZ(0);
sp6->setVertexZ(-100); sp6->setPositionZ(-100);
sp7->setVertexZ(-200); sp7->setPositionZ(-200);
sp8->setVertexZ(-300); sp8->setPositionZ(-300);
sp9->setVertexZ(-400); sp9->setPositionZ(-400);
sp9->setScale(2); sp9->setScale(2);
sp9->setColor(Color3B::YELLOW); sp9->setColor(Color3B::YELLOW);

View File

@ -1 +1 @@
4bb0b2a6151e4910ea662bedd91a5be655ec05d1 4d17613c96e30631ec5da21b2629fa3d0fc39f2d

View File

@ -38,6 +38,7 @@ static std::function<Layer*()> createFunctions[] =
{ {
CL(TexturePVRv3Premult), CL(TexturePVRv3Premult),
CL(TextureMipMap),
CL(TextureMemoryAlloc), CL(TextureMemoryAlloc),
CL(TextureAlias), CL(TextureAlias),
CL(TexturePVRMipMap), CL(TexturePVRMipMap),

View File

@ -285,7 +285,7 @@ TMXOrthoTest::TMXOrthoTest()
Size CC_UNUSED s = map->getContentSize(); Size CC_UNUSED s = map->getContentSize();
CCLOG("ContentSize: %f, %f", s.width,s.height); CCLOG("ContentSize: %f, %f", s.width,s.height);
auto scale = ScaleBy::create(10, 0.1); auto scale = ScaleBy::create(10, 0.1f);
auto back = scale->reverse(); auto back = scale->reverse();
auto seq = Sequence::create(scale, back, NULL); auto seq = Sequence::create(scale, back, NULL);
auto repeat = RepeatForever::create(seq); auto repeat = RepeatForever::create(seq);
@ -1086,7 +1086,7 @@ void TMXIsoVertexZ::repositionSprite(float dt)
auto p = _tamara->getPosition(); auto p = _tamara->getPosition();
p = CC_POINT_POINTS_TO_PIXELS(p); p = CC_POINT_POINTS_TO_PIXELS(p);
float newZ = -(p.y+32) /16; float newZ = -(p.y+32) /16;
_tamara->setVertexZ( newZ ); _tamara->setPositionZ( newZ );
} }
void TMXIsoVertexZ::onEnter() void TMXIsoVertexZ::onEnter()
@ -1132,7 +1132,7 @@ TMXOrthoVertexZ::TMXOrthoVertexZ()
// can use any Sprite and it will work OK. // can use any Sprite and it will work OK.
auto layer = map->getLayer("trees"); auto layer = map->getLayer("trees");
_tamara = layer->getTileAt(Point(0,11)); _tamara = layer->getTileAt(Point(0,11));
CCLOG("%p vertexZ: %f", _tamara, _tamara->getVertexZ()); CCLOG("%p vertexZ: %f", _tamara, _tamara->getPositionZ());
_tamara->retain(); _tamara->retain();
auto move = MoveBy::create(10, Point(400,450) * (1/CC_CONTENT_SCALE_FACTOR())); auto move = MoveBy::create(10, Point(400,450) * (1/CC_CONTENT_SCALE_FACTOR()));
@ -1155,7 +1155,7 @@ void TMXOrthoVertexZ::repositionSprite(float dt)
// map size: 12x12 // map size: 12x12
auto p = _tamara->getPosition(); auto p = _tamara->getPosition();
p = CC_POINT_POINTS_TO_PIXELS(p); p = CC_POINT_POINTS_TO_PIXELS(p);
_tamara->setVertexZ( -( (p.y+81) /81) ); _tamara->setPositionZ( -( (p.y+81) /81) );
} }
void TMXOrthoVertexZ::onEnter() void TMXOrthoVertexZ::onEnter()

View File

@ -24,6 +24,8 @@
#include "VisibleRect.h" #include "VisibleRect.h"
USING_NS_CC;
Rect VisibleRect::s_visibleRect; Rect VisibleRect::s_visibleRect;
void VisibleRect::lazyInit() void VisibleRect::lazyInit()

View File

@ -2,25 +2,24 @@
#define __VISIBLERECT_H__ #define __VISIBLERECT_H__
#include "cocos2d.h" #include "cocos2d.h"
USING_NS_CC;
class VisibleRect class VisibleRect
{ {
public: public:
static Rect getVisibleRect(); static cocos2d::Rect getVisibleRect();
static Point left(); static cocos2d::Point left();
static Point right(); static cocos2d::Point right();
static Point top(); static cocos2d::Point top();
static Point bottom(); static cocos2d::Point bottom();
static Point center(); static cocos2d::Point center();
static Point leftTop(); static cocos2d::Point leftTop();
static Point rightTop(); static cocos2d::Point rightTop();
static Point leftBottom(); static cocos2d::Point leftBottom();
static Point rightBottom(); static cocos2d::Point rightBottom();
private: private:
static void lazyInit(); static void lazyInit();
static Rect s_visibleRect; static cocos2d::Rect s_visibleRect;
}; };
#endif /* __VISIBLERECT_H__ */ #endif /* __VISIBLERECT_H__ */

View File

@ -185,8 +185,8 @@ void ZwoptexGenericTest::flipSprites(float dt)
char str2[32] = {0}; char str2[32] = {0};
sprintf(str1, "grossini_dance_%02d.png", spriteFrameIndex); sprintf(str1, "grossini_dance_%02d.png", spriteFrameIndex);
sprintf(str2, "grossini_dance_generic_%02d.png", spriteFrameIndex); sprintf(str2, "grossini_dance_generic_%02d.png", spriteFrameIndex);
sprite1->setDisplayFrame(SpriteFrameCache::getInstance()->getSpriteFrameByName(str1)); sprite1->setSpriteFrame(SpriteFrameCache::getInstance()->getSpriteFrameByName(str1));
sprite2->setDisplayFrame(SpriteFrameCache::getInstance()->getSpriteFrameByName(str2)); sprite2->setSpriteFrame(SpriteFrameCache::getInstance()->getSpriteFrameByName(str2));
} }
ZwoptexGenericTest::~ZwoptexGenericTest() ZwoptexGenericTest::~ZwoptexGenericTest()

View File

@ -23,6 +23,8 @@ ELAPSEDSECS=`date +%s`
COCOS_BRANCH="update_lua_bindings_$ELAPSEDSECS" COCOS_BRANCH="update_lua_bindings_$ELAPSEDSECS"
COCOS_ROBOT_REMOTE="https://${GH_USER}:${GH_PASSWORD}@github.com/${GH_USER}/cocos2d-x.git" COCOS_ROBOT_REMOTE="https://${GH_USER}:${GH_PASSWORD}@github.com/${GH_USER}/cocos2d-x.git"
PULL_REQUEST_REPO="https://api.github.com/repos/cocos2d/cocos2d-x/pulls" PULL_REQUEST_REPO="https://api.github.com/repos/cocos2d/cocos2d-x/pulls"
FETCH_REMOTE_BRANCH="develop"
COMMIT_PATH="cocos/scripting/lua-bindings/auto"
# Exit on error # Exit on error
set -e set -e
@ -88,12 +90,14 @@ pushd "$PROJECT_ROOT"
git status git status
echo echo
echo Comparing with HEAD ... echo Comparing with origin HEAD ...
echo echo
git fetch origin ${FETCH_REMOTE_BRANCH}
# Don't exit on non-zero return value # Don't exit on non-zero return value
set +e set +e
git diff --stat --exit-code git diff FETCH_HEAD --stat --exit-code ${COMMIT_PATH}
DIFF_RETVAL=$? DIFF_RETVAL=$?
if [ $DIFF_RETVAL -eq 0 ] if [ $DIFF_RETVAL -eq 0 ]

View File

@ -6,6 +6,8 @@ PROJECT_ROOT="$DIR"/../..
COMMITTAG="[AUTO][ci skip]: updating cocos2dx_files.json" COMMITTAG="[AUTO][ci skip]: updating cocos2dx_files.json"
PUSH_REPO="https://api.github.com/repos/cocos2d/cocos2d-x/pulls" PUSH_REPO="https://api.github.com/repos/cocos2d/cocos2d-x/pulls"
OUTPUT_FILE_PATH="${PROJECT_ROOT}/templates/cocos2dx_files.json" OUTPUT_FILE_PATH="${PROJECT_ROOT}/templates/cocos2dx_files.json"
FETCH_REMOTE_BRANCH="develop"
COMMIT_PATH="templates/cocos2dx_files.json"
# Exit on error # Exit on error
set -e set -e
@ -51,12 +53,14 @@ pushd "$PROJECT_ROOT"
git status git status
echo echo
echo Comparing with HEAD ... echo Comparing with origin HEAD ...
echo echo
git fetch origin ${FETCH_REMOTE_BRANCH}
# Don't exit on non-zero return value # Don't exit on non-zero return value
set +e set +e
git diff --stat --exit-code git diff FETCH_HEAD --stat --exit-code ${COMMIT_PATH}
DIFF_RETVAL=$? DIFF_RETVAL=$?
if [ $DIFF_RETVAL -eq 0 ] if [ $DIFF_RETVAL -eq 0 ]