/*
* 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;
没有合适的资源?快使用搜索试试~ 我知道了~
iOS游戏应用源代码——alect-Digital-Egg-Drop-a1b6091.zip
共473个文件
h:174个
m:97个
png:41个
1.该资源内容由用户上传,如若侵权请联系客服进行举报
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
版权申诉
0 下载量 88 浏览量
2023-07-02
15:43:42
上传
评论
收藏 9.91MB ZIP 举报
温馨提示
iOS游戏应用源代码——alect-Digital-Egg-Drop-a1b6091.zip
资源推荐
资源详情
资源评论
收起资源包目录
iOS游戏应用源代码——alect-Digital-Egg-Drop-a1b6091.zip (473个子文件)
002a7796bd73001013e5dcb9224f616b 481B
305738e7bc73001013e5dcb9224f616b 75B
402dd7eebc73001013e5dcb9224f616b 169B
407ef06fbd73001013e5dcb9224f616b 444B
60a7dfa0bd73001013e5dcb9224f616b 481B
70272382bd73001013e5dcb9224f616b 479B
703e8789bd73001013e5dcb9224f616b 481B
9099b727ba73001013e5dcb9224f616b 387B
glu.c 3KB
base64.c 2KB
ccUtils.c 364B
c075ae3abd73001013e5dcb9224f616b 171B
c0c2a77bbd73001013e5dcb9224f616b 479B
c0f0d3a9bc73001013e5dcb9224f616b 0B
wind.caf 488KB
earthquake.caf 384KB
straw_blowing_away.caf 182KB
rotting_wood.caf 146KB
wrong_placement.caf 136KB
breaking_egg_glass.caf 129KB
egg_break.caf 95KB
hinge.caf 64KB
hammer_click.caf 45KB
.classpath 295B
b2World.cpp 24KB
b2ContactSolver.cpp 18KB
b2PrismaticJoint.cpp 16KB
b2LineJoint.cpp 15KB
b2Distance.cpp 13KB
b2Island.cpp 13KB
b2RevoluteJoint.cpp 13KB
b2TimeOfImpact.cpp 12KB
b2PolygonShape.cpp 11KB
b2PulleyJoint.cpp 11KB
b2Body.cpp 10KB
b2CollidePolygon.cpp 9KB
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 5KB
b2CollideCircle.cpp 4KB
b2Fixture.cpp 4KB
b2BroadPhase.cpp 3KB
b2CircleShape.cpp 3KB
b2PolygonAndCircleContact.cpp 2KB
b2StackAllocator.cpp 2KB
b2PolygonContact.cpp 2KB
b2CircleContact.cpp 2KB
b2Math.cpp 2KB
b2WorldCallbacks.cpp 2KB
b2Settings.cpp 1KB
WindRayCastCallback.cpp 564B
usagedata.csv 25KB
d081e965bd73001013e5dcb9224f616b 444B
variablesAndContainers.dat 37KB
e03e01dbbd73001013e5dcb9224f616b 479B
externalLibsTimeStamps 2KB
f0a96d58bd73001013e5dcb9224f616b 359B
.gitignore 0B
uthash.h 63KB
utlist.h 36KB
b2Body.h 21KB
CCNode.h 17KB
b2Math.h 15KB
CocosDenshion.h 14KB
CCParticleSystem.h 14KB
CCMenuItem.h 13KB
CCActionInterval.h 13KB
CCSprite.h 12KB
ccCArray.h 12KB
CCTexture2D.h 11KB
ccConfig.h 10KB
CCDirector.h 9KB
CCLayer.h 9KB
CDAudioManager.h 9KB
b2Fixture.h 9KB
b2World.h 9KB
ccMacros.h 8KB
CCTransition.h 8KB
b2Collision.h 8KB
CCEventDispatcher.h 8KB
CCDirectorIOS.h 8KB
b2WorldCallbacks.h 8KB
CGPointExtension.h 8KB
b2DynamicTree.h 7KB
EAGLView.h 7KB
b2Contact.h 7KB
CCActionGrid3D.h 7KB
CCActionTiledGrid.h 7KB
b2BroadPhase.h 6KB
CCSpriteBatchNode.h 6KB
ccTypes.h 6KB
共 473 条
- 1
- 2
- 3
- 4
- 5
资源评论
快乐无限出发
- 粉丝: 1135
- 资源: 7277
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功