Merge branch 'develop' of git://github.com/cocos2d/cocos2d-x into di2893

This commit is contained in:
Dhilan007 2013-10-24 18:16:44 +08:00
commit 08960f1510
12 changed files with 240 additions and 40 deletions

View File

@ -627,6 +627,9 @@ Developers:
Fixed a bug that CCBReader can't play sequence automatically in JSB.
Could not set next animation in CCBAnimationCompleted callback.
lite3
Fixed a bug that Node's anchor point was changed after being added to ScrollView.
Retired Core Developers:
WenSheng Yang
Author of windows port, CCTextField,

View File

@ -8,6 +8,7 @@ cocos2d-x-3.0alpha1 @??? 2013
[FIX] Avoid unnecessary object duplication for Scale9Sprite.
[FIX] create_project.py does not rename/replace template projects completely.
[FIX] Could not set next animation in CCBAnimationCompleted callback.
[FIX] The Node's anchor point was changed after being added to ScrollView.
[Android]
[FIX] Added EGL_RENDERABLE_TYPE to OpenGL attributes
[NEW] Added Cocos2dxHelper.runOnGLThread(Runnable) again

View File

@ -43,7 +43,7 @@ class PhysicsJoint;
class PhysicsBodyInfo;
const PhysicsMaterial PHYSICSBODY_MATERIAL_DEFAULT = {1.0f, 1.0f, 1.0f};
const PhysicsMaterial PHYSICSBODY_MATERIAL_DEFAULT(1.0f, 1.0f, 1.0f);
/**
* A body affect by physics.

View File

@ -70,16 +70,21 @@ bool PhysicsJoint::init(cocos2d::PhysicsBody *a, cocos2d::PhysicsBody *b)
{
do
{
CC_BREAK_IF(a == nullptr || b == nullptr);
CC_BREAK_IF(!(_info = new PhysicsJointInfo(this)));
if (a != nullptr)
{
_bodyA = a;
_bodyA->retain();
_bodyA->_joints.push_back(this);
}
if (b != nullptr)
{
_bodyB = b;
_bodyB->retain();
_bodyB->_joints.push_back(this);
}
return true;
} while (false);

View File

@ -44,14 +44,20 @@ typedef struct PhysicsMaterial
float restitution;
float friction;
static PhysicsMaterial make(float density, float restitution, float friction)
{
PhysicsMaterial var = {density, restitution, friction};
return var;
}
PhysicsMaterial()
: density(0.0f)
, restitution(0.0f)
, friction(0.0f)
{}
PhysicsMaterial(float density, float restitution, float friction)
: density(density)
, restitution(restitution)
, friction(friction)
{}
}PhysicsMaterial;
const PhysicsMaterial PHYSICSSHAPE_MATERIAL_DEFAULT = {0.0f, 1.0f, 1.0f};
const PhysicsMaterial PHYSICSSHAPE_MATERIAL_DEFAULT(0.0f, 1.0f, 1.0f);
/**
* @brief A shape for body. You do not create PhysicsWorld objects directly, instead, you can view PhysicsBody to see how to create it.

View File

@ -88,6 +88,7 @@ public:
static void collisionSeparateCallbackFunc(cpArbiter *arb, cpSpace *space, PhysicsWorld *world);
static void rayCastCallbackFunc(cpShape *shape, cpFloat t, cpVect n, RayCastCallbackInfo *info);
static void rectQueryCallbackFunc(cpShape *shape, RectQueryCallbackInfo *info);
static void nearestPointQueryFunc(cpShape *shape, cpFloat distance, cpVect point, Array *arr);
public:
static bool continues;
@ -166,6 +167,15 @@ void PhysicsWorldCallback::rectQueryCallbackFunc(cpShape *shape, RectQueryCallba
info->data);
}
void PhysicsWorldCallback::nearestPointQueryFunc(cpShape *shape, cpFloat distance, cpVect point, Array *arr)
{
auto it = PhysicsShapeInfo::map.find(shape);
CC_ASSERT(it != PhysicsShapeInfo::map.end());
arr->addObject(it->second->shape);
}
bool PhysicsWorld::init()
{
_info = new PhysicsWorldInfo();
@ -561,9 +571,30 @@ void PhysicsWorld::rectQuery(PhysicsRectQueryCallback& callback, Rect rect, void
}
}
Array* getShapesAtPoint(Point point)
Array* PhysicsWorld::getShapesAtPoint(Point point)
{
Array* arr = Array::create();
cpSpaceNearestPointQuery(this->_info->space,
PhysicsHelper::point2cpv(point),
0,
CP_ALL_LAYERS,
CP_NO_GROUP,
(cpSpaceNearestPointQueryFunc)PhysicsWorldCallback::nearestPointQueryFunc,
arr);
return arr;
}
PhysicsShape* PhysicsWorld::getShapeAtPoint(Point point)
{
cpShape* shape = cpSpaceNearestPointQueryNearest(this->_info->space,
PhysicsHelper::point2cpv(point),
0,
CP_ALL_LAYERS,
CP_NO_GROUP,
nullptr);
return shape == nullptr ? nullptr : PhysicsShapeInfo::map.find(shape)->second->shape;
}
Array* PhysicsWorld::getAllBody() const

View File

@ -98,6 +98,7 @@ public:
void rayCast(PhysicsRayCastCallback& callback, Point point1, Point point2, void* data);
void rectQuery(PhysicsRectQueryCallback& callback, Rect rect, void* data);
Array* getShapesAtPoint(Point point);
PhysicsShape* getShapeAtPoint(Point point);
Array* getAllBody() const;
/** Register a listener to receive contact callbacks*/

View File

@ -469,8 +469,6 @@ void ScrollView::updateInset()
*/
void ScrollView::addChild(Node * child, int zOrder, int tag)
{
child->ignoreAnchorPointForPosition(false);
child->setAnchorPoint(Point(0.0f, 0.0f));
if (_container != child) {
_container->addChild(child, zOrder, tag);
} else {

View File

@ -50,7 +50,7 @@ namespace
return layer;
}
static const Color4F STATIC_COLOR = {1.0f, 0.0f, 0.0f, 1.0f};
static const Color4F STATIC_COLOR(1.0f, 0.0f, 0.0f, 1.0f);
}
@ -92,6 +92,7 @@ PhysicsDemo::PhysicsDemo()
: _scene(nullptr)
, _ball(nullptr)
, _spriteTexture(nullptr)
, _mouse(nullptr)
{
}
@ -296,7 +297,8 @@ namespace
-25,-8,0,63,-57,-29,-4,-1,-1,-13,-4,127,-64,31,-2,0,15,103,-1,-1,-57,-8,127,
-97,-25,-8,0,63,-61,-61,-4,127,-1,-29,-4,127,-64,15,-8,0,0,55,-1,-1,-121,-8,
127,-97,-25,-8,0,63,-61,-61,-4,127,-1,-29,-4,63,-64,15,-32,0,0,23,-1,-2,3,-16,
63,15,-61,-16,0,31,-127,-127,-8,31,-1,-127,-8,31,-128,7,-128,0,0};
63,15,-61,-16,0,31,-127,-127,-8,31,-1,-127,-8,31,-128,7,-128,0,0
};
static inline int get_pixel(int x, int y)
{
@ -365,6 +367,31 @@ Sprite* PhysicsDemo::makeTriangle(float x, float y, Size size, PhysicsMaterial m
return triangle;
}
void PhysicsDemo::onTouchesBegan(const std::vector<Touch*>& touches, Event* event)
{
for( auto &touch: touches)
{
auto location = touch->getLocation();
Array* arr = _scene->getPhysicsWorld()->getShapesAtPoint(location);
PhysicsShape* shape = nullptr;
for (Object* obj : *arr)
{
}
}
}
void PhysicsDemo::onTouchesMoved(const std::vector<Touch*>& touches, Event* event)
{
}
void PhysicsDemo::onTouchesEnded(const std::vector<Touch*>& touches, Event* event)
{
}
void PhysicsDemoLogoSmash::onEnter()
{
PhysicsDemo::onEnter();
@ -384,7 +411,7 @@ void PhysicsDemoLogoSmash::onEnter()
Node* ball = makeBall(2*(x - logo_width/2 + x_jitter) + VisibleRect::getVisibleRect().size.width/2,
2*(logo_height-y + y_jitter) + VisibleRect::getVisibleRect().size.height/2 - logo_height/2,
0.95f, PhysicsMaterial::make(1.0f, 0.0f, 0.0f));
0.95f, PhysicsMaterial(1.0f, 0.0f, 0.0f));
ball->getPhysicsBody()->setMass(1.0);
ball->getPhysicsBody()->setMoment(PHYSICS_INFINITY);
@ -396,7 +423,7 @@ void PhysicsDemoLogoSmash::onEnter()
}
auto bullet = makeBall(400, 0, 10, PhysicsMaterial::make(PHYSICS_INFINITY, 0, 0));
auto bullet = makeBall(400, 0, 10, PhysicsMaterial(PHYSICS_INFINITY, 0, 0));
bullet->getPhysicsBody()->setVelocity(Point(400, 0));
bullet->setPosition(Point(-1000, VisibleRect::getVisibleRect().size.height/2));
@ -427,7 +454,7 @@ void PhysicsDemoPyramidStack::onEnter()
{
for(int j=0; j<=i; j++)
{
addGrossiniAtPosition(VisibleRect::bottom() + Point((i/2 - j) * 11, (14 - i) * 23 + 100), 0.2);
addGrossiniAtPosition(VisibleRect::bottom() + Point((i/2 - j) * 11, (14 - i) * 23 + 100), 0.2f);
}
}
}
@ -644,7 +671,7 @@ void PhysicsDemoRayCast::update(float delta)
break;
}
_angle += 0.25f * M_PI / 180.0f;
_angle += 0.25f * (float)M_PI / 180.0f;
}
void PhysicsDemoRayCast::onTouchesEnded(const std::vector<Touch*>& touches, Event* event)
@ -687,18 +714,6 @@ void PhysicsDemoJoints::onEnter()
}
void PhysicsDemoJoints::onTouchesEnded(const std::vector<Touch*>& touches, Event* event)
{
//Add a new body/atlas sprite at the touched location
for( auto &touch: touches)
{
auto location = touch->getLocation();
}
}
std::string PhysicsDemoJoints::title()
{
return "Joints";

View File

@ -37,13 +37,18 @@ public:
void toggleDebugCallback(Object* sender);
void addGrossiniAtPosition(Point p, float scale = 1.0);
Sprite* makeBall(float x, float y, float radius, PhysicsMaterial material = {1.0f, 1.0f, 1.0f});
Sprite* makeBox(float x, float y, Size size, PhysicsMaterial material = {1.0f, 1.0f, 1.0f});
Sprite* makeTriangle(float x, float y, Size size, PhysicsMaterial material = {1.0f, 1.0f, 1.0f});
Sprite* makeBall(float x, float y, float radius, PhysicsMaterial material = PhysicsMaterial(1.0f, 1.0f, 1.0f));
Sprite* makeBox(float x, float y, Size size, PhysicsMaterial material = PhysicsMaterial(1.0f, 1.0f, 1.0f));
Sprite* makeTriangle(float x, float y, Size size, PhysicsMaterial material = PhysicsMaterial(1.0f, 1.0f, 1.0f));
void onTouchesBegan(const std::vector<Touch*>& touches, Event* event) override;
void onTouchesMoved(const std::vector<Touch*>& touches, Event* event) override;
void onTouchesEnded(const std::vector<Touch*>& touches, Event* event) override;
protected:
Texture2D* _spriteTexture; // weak ref
SpriteBatchNode* _ball;
DrawNode* _mouse;
};
class PhysicsDemoClickAdd : public PhysicsDemo
@ -99,10 +104,15 @@ private:
class PhysicsDemoJoints : public PhysicsDemo
{
public:
PhysicsDemoJoints();
public:
void onEnter() override;
std::string title() override;
void onTouchesEnded(const std::vector<Touch*>& touches, Event* event) override;
private:
PhysicsShape* _touchesShape;
};
#endif

View File

@ -0,0 +1,65 @@
[cocos2dx_builder]
# the prefix to be added to the generated functions. You might or might not use this in your own
# templates
prefix = cocos2dx_builder
# create a target namespace (in javascript, this would create some code like the equiv. to `ns = ns || {}`)
# all classes will be embedded in that namespace
target_namespace = cc
android_headers = -I%(androidndkdir)s/platforms/android-14/arch-arm/usr/include -I%(androidndkdir)s/sources/cxx-stl/gnu-libstdc++/4.7/libs/armeabi-v7a/include -I%(androidndkdir)s/sources/cxx-stl/gnu-libstdc++/4.7/include
android_flags = -D_SIZE_T_DEFINED_
clang_headers = -I%(clangllvmdir)s/lib/clang/3.3/include
clang_flags = -nostdinc -x c++ -std=c++11
cocos_headers = -I%(cocosdir)s/cocos/2d -I%(cocosdir)s/cocos/base -I%(cocosdir)s/cocos/gui -I%(cocosdir)s/cocos/physics -I%(cocosdir)s/cocos/2d/platform -I%(cocosdir)s/cocos/2d/platform/android -I%(cocosdir)s/cocos/math/kazmath/include -I%(cocosdir)s/extensions -I%(cocosdir)s/external -I%(cocosdir)s/cocos/editor-support -I%(cocosdir)s
cocos_flags = -DANDROID -DCOCOS2D_JAVASCRIPT
cxxgenerator_headers =
# extra arguments for clang
extra_arguments = %(android_headers)s %(clang_headers)s %(cxxgenerator_headers)s %(cocos_headers)s %(android_flags)s %(clang_flags)s %(cocos_flags)s %(extra_flags)s
# what headers to parse
headers = %(cocosdir)s/cocos/editor-support/cocosbuilder/CocosBuilder.h
# what classes to produce code for. You can use regular expressions here. When testing the regular
# expression, it will be enclosed in "^$", like this: "^Menu*$".
classes = CCBReader.* CCBAnimationManager.*
# what should we skip? in the format ClassName::[function function]
# ClassName is a regular expression, but will be used like this: "^ClassName$" functions are also
# regular expressions, they will not be surrounded by "^$". If you want to skip a whole class, just
# add a single "*" as functions. See bellow for several examples. A special class name is "*", which
# will apply to all class names. This is a convenience wildcard to be able to skip similar named
# functions from all classes.
skip = CCBReader::[^CCBReader$ addOwnerCallbackName isJSControlled readByte getCCBMemberVariableAssigner readFloat getCCBSelectorResolver toLowerCase lastPathComponent deletePathExtension endsWith concat getResolutionScale getAnimatedProperties readBool readInt addOwnerCallbackNode addDocumentCallbackName readCachedString readNodeGraphFromData addDocumentCallbackNode getLoadedSpriteSheet initWithData readFileWithCleanUp getOwner$ readNodeGraphFromFile createSceneWithNodeGraphFromFile getAnimationManagers$ setAnimationManagers],
CCBAnimationManager::[setAnimationCompletedCallback],
.*Delegate::[*],
.*Loader.*::[*],
*::[^visit$ copyWith.* onEnter.* onExit.* ^description$ getObjectType .*HSV onTouch.* onAcc.* onKey.* onRegisterTouchListener]
rename_functions =
rename_classes = CCBReader::_Reader,
CCBAnimationManager::BuilderAnimationManager
# for all class names, should we remove something when registering in the target VM?
remove_prefix =
# classes for which there will be no "parent" lookup
classes_have_no_parents =
# base classes which will be skipped when their sub-classes found them.
base_classes_to_skip = Object
# classes that create no constructor
# Set is special and we will use a hand-written constructor
abstract_classes =
# Determining whether to use script object(js object) to control the lifecycle of native(cpp) object or the other way around. Supported values are 'yes' or 'no'.
script_control_cpp = no

View File

@ -0,0 +1,65 @@
[cocos2dx_studio]
# the prefix to be added to the generated functions. You might or might not use this in your own
# templates
prefix = cocos2dx_studio
# create a target namespace (in javascript, this would create some code like the equiv. to `ns = ns || {}`)
# all classes will be embedded in that namespace
target_namespace = cc
android_headers = -I%(androidndkdir)s/platforms/android-14/arch-arm/usr/include -I%(androidndkdir)s/sources/cxx-stl/gnu-libstdc++/4.7/libs/armeabi-v7a/include -I%(androidndkdir)s/sources/cxx-stl/gnu-libstdc++/4.7/include
android_flags = -D_SIZE_T_DEFINED_
clang_headers = -I%(clangllvmdir)s/lib/clang/3.3/include
clang_flags = -nostdinc -x c++ -std=c++11
cocos_headers = -I%(cocosdir)s/cocos -I%(cocosdir)s/cocos/2d -I%(cocosdir)s/cocos/base -I%(cocosdir)s/cocos/gui -I%(cocosdir)s/cocos/physics -I%(cocosdir)s/cocos/2d/platform -I%(cocosdir)s/cocos/2d/platform/android -I%(cocosdir)s/cocos/math/kazmath/include -I%(cocosdir)s/extensions -I%(cocosdir)s/external -I%(cocosdir)s/cocos/editor-support -I%(cocosdir)s
cocos_flags = -DANDROID -DCOCOS2D_JAVASCRIPT
cxxgenerator_headers =
# extra arguments for clang
extra_arguments = %(android_headers)s %(clang_headers)s %(cxxgenerator_headers)s %(cocos_headers)s %(android_flags)s %(clang_flags)s %(cocos_flags)s %(extra_flags)s
# what headers to parse
headers = %(cocosdir)s/cocos/editor-support/cocostudio/CocoStudio.h
# what classes to produce code for. You can use regular expressions here. When testing the regular
# expression, it will be enclosed in "^$", like this: "^Menu*$".
classes = Armature ArmatureAnimation Skin Bone ArmatureDataManager
# what should we skip? in the format ClassName::[function function]
# ClassName is a regular expression, but will be used like this: "^ClassName$" functions are also
# regular expressions, they will not be surrounded by "^$". If you want to skip a whole class, just
# add a single "*" as functions. See bellow for several examples. A special class name is "*", which
# will apply to all class names. This is a convenience wildcard to be able to skip similar named
# functions from all classes.
skip = .*Delegate::[*],
.*Loader.*::[*],
*::[^visit$ copyWith.* onEnter.* onExit.* ^description$ getObjectType .*HSV onTouch.* onAcc.* onKey.* onRegisterTouchListener],
Armature::[createBone updateBlendType getBody setBody getShapeList .*BlendFunc],
Skin::[getSkinData setSkinData],
ArmatureAnimation::[updateHandler updateFrameData frameEvent]
rename_functions =
rename_classes =
# for all class names, should we remove something when registering in the target VM?
remove_prefix =
# classes for which there will be no "parent" lookup
classes_have_no_parents =
# base classes which will be skipped when their sub-classes found them.
base_classes_to_skip = Object ProcessBase
# classes that create no constructor
# Set is special and we will use a hand-written constructor
abstract_classes = ArmatureDataManager
# Determining whether to use script object(js object) to control the lifecycle of native(cpp) object or the other way around. Supported values are 'yes' or 'no'.
script_control_cpp = no