/*
* Copyright (c) 2006-2009 Erin Catto http://www.gphysics.com
*
* This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages
* arising from the use of this software.
* Permission is granted to anyone to use this software for any purpose,
* including commercial applications, and to alter it and redistribute it
* freely, subject to the following restrictions:
* 1. The origin of this software must not be misrepresented; you must not
* claim that you wrote the original software. If you use this software
* in a product, an acknowledgment in the product documentation would be
* appreciated but is not required.
* 2. Altered source versions must be plainly marked as such, and must not be
* misrepresented as being the original software.
* 3. This notice may not be removed or altered from any source distribution.
*/
#include <Box2D/Dynamics/b2World.h>
#include <Box2D/Dynamics/b2Body.h>
#include <Box2D/Dynamics/b2Fixture.h>
#include <Box2D/Dynamics/b2Island.h>
#include <Box2D/Dynamics/Joints/b2PulleyJoint.h>
#include <Box2D/Dynamics/Contacts/b2Contact.h>
#include <Box2D/Dynamics/Contacts/b2ContactSolver.h>
#include <Box2D/Dynamics/Contacts/b2TOISolver.h>
#include <Box2D/Collision/b2Collision.h>
#include <Box2D/Collision/b2BroadPhase.h>
#include <Box2D/Collision/Shapes/b2CircleShape.h>
#include <Box2D/Collision/Shapes/b2PolygonShape.h>
#include <Box2D/Collision/b2TimeOfImpact.h>
#include <new>
b2World::b2World(const b2Vec2& gravity, bool doSleep)
{
m_destructionListener = NULL;
m_debugDraw = NULL;
m_bodyList = NULL;
m_jointList = NULL;
m_bodyCount = 0;
m_jointCount = 0;
m_warmStarting = true;
m_continuousPhysics = true;
m_allowSleep = doSleep;
m_gravity = gravity;
m_flags = e_clearForces;
m_inv_dt0 = 0.0f;
m_contactManager.m_allocator = &m_blockAllocator;
}
b2World::~b2World()
{
}
void b2World::SetDestructionListener(b2DestructionListener* listener)
{
m_destructionListener = listener;
}
void b2World::SetContactFilter(b2ContactFilter* filter)
{
m_contactManager.m_contactFilter = filter;
}
void b2World::SetContactListener(b2ContactListener* listener)
{
m_contactManager.m_contactListener = listener;
}
void b2World::SetDebugDraw(b2DebugDraw* debugDraw)
{
m_debugDraw = debugDraw;
}
b2Body* b2World::CreateBody(const b2BodyDef* def)
{
b2Assert(IsLocked() == false);
if (IsLocked())
{
return NULL;
}
void* mem = m_blockAllocator.Allocate(sizeof(b2Body));
b2Body* b = new (mem) b2Body(def, this);
// Add to world doubly linked list.
b->m_prev = NULL;
b->m_next = m_bodyList;
if (m_bodyList)
{
m_bodyList->m_prev = b;
}
m_bodyList = b;
++m_bodyCount;
return b;
}
void b2World::DestroyBody(b2Body* b)
{
b2Assert(m_bodyCount > 0);
b2Assert(IsLocked() == false);
if (IsLocked())
{
return;
}
// Delete the attached joints.
b2JointEdge* je = b->m_jointList;
while (je)
{
b2JointEdge* je0 = je;
je = je->next;
if (m_destructionListener)
{
m_destructionListener->SayGoodbye(je0->joint);
}
DestroyJoint(je0->joint);
}
b->m_jointList = NULL;
// Delete the attached contacts.
b2ContactEdge* ce = b->m_contactList;
while (ce)
{
b2ContactEdge* ce0 = ce;
ce = ce->next;
m_contactManager.Destroy(ce0->contact);
}
b->m_contactList = NULL;
// Delete the attached fixtures. This destroys broad-phase proxies.
b2Fixture* f = b->m_fixtureList;
while (f)
{
b2Fixture* f0 = f;
f = f->m_next;
if (m_destructionListener)
{
m_destructionListener->SayGoodbye(f0);
}
f0->DestroyProxy(&m_contactManager.m_broadPhase);
f0->Destroy(&m_blockAllocator);
f0->~b2Fixture();
m_blockAllocator.Free(f0, sizeof(b2Fixture));
}
b->m_fixtureList = NULL;
b->m_fixtureCount = 0;
// Remove world body list.
if (b->m_prev)
{
b->m_prev->m_next = b->m_next;
}
if (b->m_next)
{
b->m_next->m_prev = b->m_prev;
}
if (b == m_bodyList)
{
m_bodyList = b->m_next;
}
--m_bodyCount;
b->~b2Body();
m_blockAllocator.Free(b, sizeof(b2Body));
}
b2Joint* b2World::CreateJoint(const b2JointDef* def)
{
b2Assert(IsLocked() == false);
if (IsLocked())
{
return NULL;
}
b2Joint* j = b2Joint::Create(def, &m_blockAllocator);
// Connect to the world list.
j->m_prev = NULL;
j->m_next = m_jointList;
if (m_jointList)
{
m_jointList->m_prev = j;
}
m_jointList = j;
++m_jointCount;
// Connect to the bodies' doubly linked lists.
j->m_edgeA.joint = j;
j->m_edgeA.other = j->m_bodyB;
j->m_edgeA.prev = NULL;
j->m_edgeA.next = j->m_bodyA->m_jointList;
if (j->m_bodyA->m_jointList) j->m_bodyA->m_jointList->prev = &j->m_edgeA;
j->m_bodyA->m_jointList = &j->m_edgeA;
j->m_edgeB.joint = j;
j->m_edgeB.other = j->m_bodyA;
j->m_edgeB.prev = NULL;
j->m_edgeB.next = j->m_bodyB->m_jointList;
if (j->m_bodyB->m_jointList) j->m_bodyB->m_jointList->prev = &j->m_edgeB;
j->m_bodyB->m_jointList = &j->m_edgeB;
b2Body* bodyA = def->bodyA;
b2Body* bodyB = def->bodyB;
// If the joint prevents collisions, then flag any contacts for filtering.
if (def->collideConnected == false)
{
b2ContactEdge* edge = bodyB->GetContactList();
while (edge)
{
if (edge->other == bodyA)
{
// Flag the contact for filtering at the next time step (where either
// body is awake).
edge->contact->FlagForFiltering();
}
edge = edge->next;
}
}
// Note: creating a joint doesn't wake the bodies.
return j;
}
void b2World::DestroyJoint(b2Joint* j)
{
b2Assert(IsLocked() == false);
if (IsLocked())
{
return;
}
bool collideConnected = j->m_collideConnected;
// Remove from the doubly linked list.
if (j->m_prev)
{
j->m_prev->m_next = j->m_next;
}
if (j->m_next)
{
j->m_next->m_prev = j->m_prev;
}
if (j == m_jointList)
{
m_jointList = j->m_next;
}
// Disconnect from island graph.
b2Body* bodyA = j->m_bodyA;
b2Body* bodyB = j->m_bodyB;
// Wake up connected bodies.
bodyA->SetAwake(true);
bodyB->SetAwake(true);
// Remove from body 1.
if (j->m_edgeA.prev)
{
j->m_edgeA.prev->next = j->m_edgeA.next;
}
if (j->m_edgeA.next)
{
j->m_edgeA.next->prev = j->m_edgeA.prev;
}
if (&j->m_edgeA == bodyA->m_jointList)
{
bodyA->m_jointList = j->m_edgeA.next;
}
j->m_edgeA.prev = NULL;
j->m_edgeA.next = NULL;
// Remove from body 2
if (j->m_edgeB.prev)
{
j->m_edgeB.prev->next = j->m_edgeB.next;
}
if (j->m_edgeB.next)
{
j->m_edgeB.next->prev = j->m_edgeB.prev;
}
if (&j->m_edgeB == bodyB->m_jointList)
{
bodyB->m_jointList = j->m_edgeB.next;
}
j->m_edgeB.prev = NULL;
j->m_edgeB.next = NULL;
b2Joint::Destroy(j, &m_blockAllocator);
b2Assert(m_jointCount > 0);
--m_jointCount;
// If the joint prevents collisions, then flag any contacts for filtering.
if (collideConnected == false)
{
b2ContactEdge* edge = bodyB->GetContactList();
while (edge)
{
if (edge->other == bodyA)
{
// Flag the contact for filtering at the next time step (where either
// body is awake).
edge->contact->FlagForFiltering();
}
edge = edge->next;
}
}
}
// Find islands, integrate and solve constraints, solve position constraints
void b2World::Solve(const b2TimeStep& step)
{
// Size the island for the worst case.
b2Island island(m_bodyCount,
m_contactManager.m_contactCount,
m_jointCount,
&m_stackAllocator,
m_contactManager.m_contactListener);
// Clear all the island flags.
for (b2Body* b = m_bodyList; b; b = b->m_next)
{
b->m_flags &= ~b2Body::e_islandFlag;
}
for (b2Contact* c = m_contactManager.m_contactList; c; c = c->m_next)
{
c->m_flags &= ~b2Contact::e_islandFlag;
}
for (b2Joint* j = m_jointList; j; j = j->m_next)
{
j->m_islandFlag = false;
}
// Build and simulate all awake islands.
int32 stackSize = m_bodyCount;
b2Body** stack = (b2Body**)m_stackAllocator.Allocate(stackSize * sizeof(b2Body*));
for (b2Body* seed = m_bodyList; seed; seed = seed->m_next)
{
if (seed->m_flags & b2Body::e_islandFlag)
{
continue;
}
if (seed->IsAw
没有合适的资源?快使用搜索试试~ 我知道了~
iOS游戏应用源代码——miketucker-popclock-a19298b.zip
共308个文件
h:145个
m:91个
cpp:36个
1.该资源内容由用户上传,如若侵权请联系客服进行举报
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
版权申诉
0 下载量 89 浏览量
2023-07-05
23:21:51
上传
评论
收藏 1015KB ZIP 举报
温馨提示
iOS游戏应用源代码——miketucker-popclock-a19298b.zip
资源推荐
资源详情
资源评论
收起资源包目录
iOS游戏应用源代码——miketucker-popclock-a19298b.zip (308个子文件)
glu.c 2KB
base64.c 2KB
LICENSE.cocos2d 1KB
LICENSE.cocosdenshion 1KB
b2World.cpp 23KB
b2ContactSolver.cpp 17KB
b2PrismaticJoint.cpp 15KB
b2LineJoint.cpp 14KB
b2Island.cpp 12KB
b2Distance.cpp 12KB
b2RevoluteJoint.cpp 12KB
b2TimeOfImpact.cpp 11KB
b2PolygonShape.cpp 10KB
b2PulleyJoint.cpp 10KB
b2Body.cpp 10KB
b2CollidePolygon.cpp 8KB
b2DynamicTree.cpp 8KB
b2GearJoint.cpp 7KB
b2Contact.cpp 6KB
b2WeldJoint.cpp 6KB
b2TOISolver.cpp 6KB
b2Collision.cpp 6KB
b2ContactManager.cpp 6KB
b2FrictionJoint.cpp 6KB
b2DistanceJoint.cpp 6KB
b2MouseJoint.cpp 5KB
b2BlockAllocator.cpp 5KB
b2Joint.cpp 4KB
b2CollideCircle.cpp 4KB
b2Fixture.cpp 4KB
b2BroadPhase.cpp 3KB
b2CircleShape.cpp 3KB
b2PolygonAndCircleContact.cpp 2KB
b2PolygonContact.cpp 2KB
b2StackAllocator.cpp 2KB
b2CircleContact.cpp 2KB
b2Math.cpp 2KB
b2WorldCallbacks.cpp 2KB
b2Settings.cpp 1KB
Force.cpp 192B
uthash.h 63KB
utlist.h 36KB
b2Body.h 21KB
CCDirector.h 16KB
CCNode.h 16KB
b2Math.h 14KB
CCCompatibility.h 14KB
CCParticleSystem.h 14KB
CocosDenshion.h 13KB
CCIntervalAction.h 13KB
CCMenuItem.h 12KB
ccCArray.h 12KB
CCSprite.h 12KB
CCTexture2D.h 10KB
CDAudioManager.h 9KB
b2World.h 9KB
b2Fixture.h 8KB
CCTransition.h 8KB
b2Collision.h 8KB
CGPointExtension.h 8KB
b2WorldCallbacks.h 8KB
b2DynamicTree.h 7KB
ccConfig.h 7KB
CCTiledGridAction.h 7KB
b2Contact.h 7KB
CCScheduler.h 6KB
CCGrid3DAction.h 6KB
b2BroadPhase.h 6KB
CCTMXLayer.h 6KB
EAGLView.h 6KB
CCSpriteSheet.h 6KB
ccMacros.h 6KB
CCEaseAction.h 6KB
CCAction.h 6KB
ccTypes.h 6KB
CCTMXXMLParser.h 5KB
b2Joint.h 5KB
CCBitmapFontAtlas.h 5KB
CCTMXTiledMap.h 5KB
b2RevoluteJoint.h 5KB
CCGridAction.h 5KB
b2Settings.h 5KB
CCTextureAtlas.h 5KB
b2PrismaticJoint.h 5KB
CCSpriteFrame.h 5KB
CCLayer.h 5KB
b2LineJoint.h 5KB
CCTextureCache.h 5KB
OpenGL_Internal.h 4KB
CCInstantAction.h 4KB
CLScoreServerRequest.h 4KB
CLScoreServerPost.h 4KB
b2PulleyJoint.h 4KB
CCActionManager.h 4KB
CCSpriteFrameCache.h 4KB
CCRibbon.h 4KB
CCTouchDispatcher.h 4KB
FontLabelStringDrawing.h 4KB
b2PolygonShape.h 4KB
b2DistanceJoint.h 4KB
共 308 条
- 1
- 2
- 3
- 4
资源评论
快乐无限出发
- 粉丝: 1137
- 资源: 7276
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功