Merge branch 'master' into reflection-mapping
This commit is contained in:
@@ -312,9 +312,9 @@ namespace Nz
|
||||
while (!remainingRects.empty())
|
||||
{
|
||||
// Stores the penalty score of the best rectangle placement - bigger=worse, smaller=better.
|
||||
bool bestFlipped;
|
||||
std::size_t bestFreeRect;
|
||||
std::size_t bestRect;
|
||||
bool bestFlipped = false;
|
||||
std::size_t bestFreeRect = m_freeRectangles.size();
|
||||
std::size_t bestRect = std::numeric_limits<int>::min();
|
||||
int bestScore = std::numeric_limits<int>::max();
|
||||
|
||||
for (std::size_t i = 0; i < m_freeRectangles.size(); ++i)
|
||||
|
||||
@@ -413,9 +413,9 @@ namespace Nz
|
||||
while (ptr != &s_list)
|
||||
{
|
||||
if (ptr->file)
|
||||
std::fprintf(log, "-0x%p -> %zu bytes allocated at %s:%u\n", reinterpret_cast<UInt8*>(ptr) + sizeof(Block), ptr->size, ptr->file, ptr->line);
|
||||
std::fprintf(log, "-0x%s -> %zu bytes allocated at %s:%u\n", reinterpret_cast<UInt8*>(ptr) + sizeof(Block), ptr->size, ptr->file, ptr->line);
|
||||
else
|
||||
std::fprintf(log, "-0x%p -> %zu bytes allocated at unknown position\n", reinterpret_cast<UInt8*>(ptr) + sizeof(Block), ptr->size);
|
||||
std::fprintf(log, "-0x%s -> %zu bytes allocated at unknown position\n", reinterpret_cast<UInt8*>(ptr) + sizeof(Block), ptr->size);
|
||||
|
||||
void* pointer = ptr;
|
||||
ptr = ptr->next;
|
||||
|
||||
@@ -39,9 +39,9 @@ namespace Nz
|
||||
*/
|
||||
|
||||
ParticleGroup::ParticleGroup(unsigned int maxParticleCount, ParticleDeclarationConstRef declaration) :
|
||||
m_declaration(std::move(declaration)),
|
||||
m_maxParticleCount(maxParticleCount),
|
||||
m_particleCount(0),
|
||||
m_declaration(std::move(declaration)),
|
||||
m_processing(false)
|
||||
{
|
||||
// In case of error, the constructor can only throw an exception
|
||||
@@ -60,13 +60,13 @@ namespace Nz
|
||||
|
||||
ParticleGroup::ParticleGroup(const ParticleGroup& system) :
|
||||
Renderable(system),
|
||||
m_maxParticleCount(system.m_maxParticleCount),
|
||||
m_particleCount(system.m_particleCount),
|
||||
m_particleSize(system.m_particleSize),
|
||||
m_controllers(system.m_controllers),
|
||||
m_generators(system.m_generators),
|
||||
m_declaration(system.m_declaration),
|
||||
m_renderer(system.m_renderer),
|
||||
m_maxParticleCount(system.m_maxParticleCount),
|
||||
m_particleCount(system.m_particleCount),
|
||||
m_particleSize(system.m_particleSize),
|
||||
m_processing(false)
|
||||
{
|
||||
ErrorFlags flags(ErrorFlag_ThrowException, true);
|
||||
|
||||
@@ -11,6 +11,18 @@ namespace Nz
|
||||
{
|
||||
Collider2D::~Collider2D() = default;
|
||||
|
||||
std::vector<cpShape*> Collider2D::GenerateShapes(RigidBody2D* body) const
|
||||
{
|
||||
std::vector<cpShape*> shapes = CreateShapes(body);
|
||||
for (cpShape* shape : shapes)
|
||||
{
|
||||
cpShapeSetCollisionType(shape, m_collisionId);
|
||||
cpShapeSetSensor(shape, (m_trigger) ? cpTrue : cpFalse);
|
||||
}
|
||||
|
||||
return shapes;
|
||||
}
|
||||
|
||||
/******************************** BoxCollider2D *********************************/
|
||||
|
||||
BoxCollider2D::BoxCollider2D(const Vector2f& size, float radius) :
|
||||
|
||||
@@ -37,6 +37,16 @@ namespace Nz
|
||||
return m_stepSize;
|
||||
}
|
||||
|
||||
void PhysWorld2D::RegisterCallbacks(unsigned int collisionId, const Callback& callbacks)
|
||||
{
|
||||
InitCallbacks(cpSpaceAddWildcardHandler(m_handle, collisionId), callbacks);
|
||||
}
|
||||
|
||||
void PhysWorld2D::RegisterCallbacks(unsigned int collisionIdA, unsigned int collisionIdB, const Callback& callbacks)
|
||||
{
|
||||
InitCallbacks(cpSpaceAddCollisionHandler(m_handle, collisionIdA, collisionIdB), callbacks);
|
||||
}
|
||||
|
||||
void PhysWorld2D::SetGravity(const Vector2f& gravity)
|
||||
{
|
||||
cpSpaceSetGravity(m_handle, cpv(gravity.x, gravity.y));
|
||||
@@ -57,4 +67,99 @@ namespace Nz
|
||||
m_timestepAccumulator -= m_stepSize;
|
||||
}
|
||||
}
|
||||
|
||||
void PhysWorld2D::InitCallbacks(cpCollisionHandler* handler, const Callback& callbacks)
|
||||
{
|
||||
auto it = m_callbacks.emplace(handler, std::make_unique<Callback>(callbacks)).first;
|
||||
|
||||
handler->userData = it->second.get();
|
||||
|
||||
if (callbacks.startCallback)
|
||||
{
|
||||
handler->beginFunc = [](cpArbiter* arb, cpSpace* space, void *data) -> cpBool
|
||||
{
|
||||
cpBody* firstBody;
|
||||
cpBody* secondBody;
|
||||
cpArbiterGetBodies(arb, &firstBody, &secondBody);
|
||||
|
||||
PhysWorld2D* world = static_cast<PhysWorld2D*>(cpSpaceGetUserData(space));
|
||||
RigidBody2D* firstRigidBody = static_cast<RigidBody2D*>(cpBodyGetUserData(firstBody));
|
||||
RigidBody2D* secondRigidBody = static_cast<RigidBody2D*>(cpBodyGetUserData(secondBody));
|
||||
|
||||
const Callback* customCallbacks = static_cast<const Callback*>(data);
|
||||
if (customCallbacks->startCallback(*world, *firstRigidBody, *secondRigidBody, customCallbacks->userdata))
|
||||
{
|
||||
cpBool retA = cpArbiterCallWildcardBeginA(arb, space);
|
||||
cpBool retB = cpArbiterCallWildcardBeginB(arb, space);
|
||||
return retA && retB;
|
||||
}
|
||||
else
|
||||
return cpFalse;
|
||||
};
|
||||
}
|
||||
|
||||
if (callbacks.endCallback)
|
||||
{
|
||||
handler->separateFunc = [](cpArbiter* arb, cpSpace* space, void *data)
|
||||
{
|
||||
cpBody* firstBody;
|
||||
cpBody* secondBody;
|
||||
cpArbiterGetBodies(arb, &firstBody, &secondBody);
|
||||
|
||||
PhysWorld2D* world = static_cast<PhysWorld2D*>(cpSpaceGetUserData(space));
|
||||
RigidBody2D* firstRigidBody = static_cast<RigidBody2D*>(cpBodyGetUserData(firstBody));
|
||||
RigidBody2D* secondRigidBody = static_cast<RigidBody2D*>(cpBodyGetUserData(secondBody));
|
||||
|
||||
const Callback* customCallbacks = static_cast<const Callback*>(data);
|
||||
customCallbacks->endCallback(*world, *firstRigidBody, *secondRigidBody, customCallbacks->userdata);
|
||||
|
||||
cpArbiterCallWildcardSeparateA(arb, space);
|
||||
cpArbiterCallWildcardSeparateB(arb, space);
|
||||
};
|
||||
}
|
||||
|
||||
if (callbacks.preSolveCallback)
|
||||
{
|
||||
handler->preSolveFunc = [](cpArbiter* arb, cpSpace* space, void *data) -> cpBool
|
||||
{
|
||||
cpBody* firstBody;
|
||||
cpBody* secondBody;
|
||||
cpArbiterGetBodies(arb, &firstBody, &secondBody);
|
||||
|
||||
PhysWorld2D* world = static_cast<PhysWorld2D*>(cpSpaceGetUserData(space));
|
||||
RigidBody2D* firstRigidBody = static_cast<RigidBody2D*>(cpBodyGetUserData(firstBody));
|
||||
RigidBody2D* secondRigidBody = static_cast<RigidBody2D*>(cpBodyGetUserData(secondBody));
|
||||
|
||||
const Callback* customCallbacks = static_cast<const Callback*>(data);
|
||||
if (customCallbacks->preSolveCallback(*world, *firstRigidBody, *secondRigidBody, customCallbacks->userdata))
|
||||
{
|
||||
cpBool retA = cpArbiterCallWildcardPreSolveA(arb, space);
|
||||
cpBool retB = cpArbiterCallWildcardPreSolveB(arb, space);
|
||||
return retA && retB;
|
||||
}
|
||||
else
|
||||
return cpFalse;
|
||||
};
|
||||
}
|
||||
|
||||
if (callbacks.postSolveCallback)
|
||||
{
|
||||
handler->postSolveFunc = [](cpArbiter* arb, cpSpace* space, void *data)
|
||||
{
|
||||
cpBody* firstBody;
|
||||
cpBody* secondBody;
|
||||
cpArbiterGetBodies(arb, &firstBody, &secondBody);
|
||||
|
||||
PhysWorld2D* world = static_cast<PhysWorld2D*>(cpSpaceGetUserData(space));
|
||||
RigidBody2D* firstRigidBody = static_cast<RigidBody2D*>(cpBodyGetUserData(firstBody));
|
||||
RigidBody2D* secondRigidBody = static_cast<RigidBody2D*>(cpBodyGetUserData(secondBody));
|
||||
|
||||
const Callback* customCallbacks = static_cast<const Callback*>(data);
|
||||
customCallbacks->postSolveCallback(*world, *firstRigidBody, *secondRigidBody, customCallbacks->userdata);
|
||||
|
||||
cpArbiterCallWildcardPostSolveA(arb, space);
|
||||
cpArbiterCallWildcardPostSolveB(arb, space);
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -20,6 +20,7 @@ namespace Nz
|
||||
|
||||
RigidBody2D::RigidBody2D(PhysWorld2D* world, float mass, Collider2DRef geom) :
|
||||
m_geom(),
|
||||
m_userData(nullptr),
|
||||
m_world(world),
|
||||
m_gravityFactor(1.f),
|
||||
m_mass(1.f)
|
||||
@@ -34,6 +35,7 @@ namespace Nz
|
||||
|
||||
RigidBody2D::RigidBody2D(const RigidBody2D& object) :
|
||||
m_geom(object.m_geom),
|
||||
m_userData(object.m_userData),
|
||||
m_world(object.m_world),
|
||||
m_gravityFactor(object.m_gravityFactor),
|
||||
m_mass(0.f)
|
||||
@@ -48,18 +50,27 @@ namespace Nz
|
||||
}
|
||||
|
||||
RigidBody2D::RigidBody2D(RigidBody2D&& object) :
|
||||
OnRigidBody2DMove(std::move(object.OnRigidBody2DMove)),
|
||||
OnRigidBody2DRelease(std::move(object.OnRigidBody2DRelease)),
|
||||
m_shapes(std::move(object.m_shapes)),
|
||||
m_geom(std::move(object.m_geom)),
|
||||
m_userData(object.m_userData),
|
||||
m_handle(object.m_handle),
|
||||
m_world(object.m_world),
|
||||
m_gravityFactor(object.m_gravityFactor),
|
||||
m_mass(object.m_mass)
|
||||
{
|
||||
cpBodySetUserData(m_handle, this);
|
||||
|
||||
object.m_handle = nullptr;
|
||||
|
||||
OnRigidBody2DMove(&object, this);
|
||||
}
|
||||
|
||||
RigidBody2D::~RigidBody2D()
|
||||
{
|
||||
OnRigidBody2DRelease(this);
|
||||
|
||||
Destroy();
|
||||
}
|
||||
|
||||
@@ -144,6 +155,11 @@ namespace Nz
|
||||
return static_cast<float>(cpBodyGetAngle(m_handle));
|
||||
}
|
||||
|
||||
void* RigidBody2D::GetUserdata() const
|
||||
{
|
||||
return m_userData;
|
||||
}
|
||||
|
||||
Vector2f RigidBody2D::GetVelocity() const
|
||||
{
|
||||
cpVect vel = cpBodyGetVelocity(m_handle);
|
||||
@@ -190,7 +206,7 @@ namespace Nz
|
||||
else
|
||||
m_geom = NullCollider2D::New();
|
||||
|
||||
m_shapes = m_geom->CreateShapes(this);
|
||||
m_shapes = m_geom->GenerateShapes(this);
|
||||
|
||||
cpSpace* space = m_world->GetHandle();
|
||||
for (cpShape* shape : m_shapes)
|
||||
@@ -242,6 +258,11 @@ namespace Nz
|
||||
cpBodySetAngle(m_handle, rotation);
|
||||
}
|
||||
|
||||
void RigidBody2D::SetUserdata(void* ud)
|
||||
{
|
||||
m_userData = ud;
|
||||
}
|
||||
|
||||
void RigidBody2D::SetVelocity(const Vector2f& velocity)
|
||||
{
|
||||
cpBodySetVelocity(m_handle, cpv(velocity.x, velocity.y));
|
||||
@@ -257,15 +278,23 @@ namespace Nz
|
||||
{
|
||||
Destroy();
|
||||
|
||||
OnRigidBody2DMove = std::move(object.OnRigidBody2DMove);
|
||||
OnRigidBody2DRelease = std::move(object.OnRigidBody2DRelease);
|
||||
|
||||
m_handle = object.m_handle;
|
||||
m_geom = std::move(object.m_geom);
|
||||
m_gravityFactor = object.m_gravityFactor;
|
||||
m_mass = object.m_mass;
|
||||
m_shapes = std::move(object.m_shapes);
|
||||
m_userData = object.m_userData;
|
||||
m_world = object.m_world;
|
||||
|
||||
cpBodySetUserData(m_handle, this);
|
||||
|
||||
object.m_handle = nullptr;
|
||||
|
||||
OnRigidBody2DMove(&object, this);
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
@@ -8,28 +8,28 @@
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
// Version majeure d'OpenGL, initialisé par OpenGL::Initialize()
|
||||
// Major version of OpenGL, initialised by OpenGL::Initialize()
|
||||
UInt8 ContextParameters::defaultMajorVersion;
|
||||
|
||||
// Version majeure d'OpenGL, initialisé par OpenGL::Initialize()
|
||||
// Minor version of OpenGL, initialised by OpenGL::Initialize()
|
||||
UInt8 ContextParameters::defaultMinorVersion;
|
||||
|
||||
// Contexte de partage par défaut, initialisé par OpenGL::Initialize()
|
||||
// Context of default sharing, initialised by OpenGL::Initialize()
|
||||
const Context* ContextParameters::defaultShareContext = nullptr;
|
||||
|
||||
// Si possible, garder la compatibilité avec les fonctionnalités dépréciées
|
||||
// If it's possible, keep the compatibility with deprecated functionalities
|
||||
bool ContextParameters::defaultCompatibilityProfile = false;
|
||||
|
||||
// Mode debug d'OpenGL par défaut
|
||||
// Default debug mode of OpenGL
|
||||
#if NAZARA_RENDERER_OPENGL_DEBUG || defined(NAZARA_DEBUG)
|
||||
bool ContextParameters::defaultDebugMode = true;
|
||||
#else
|
||||
bool ContextParameters::defaultDebugMode = false;
|
||||
#endif
|
||||
|
||||
// Active le double-buffering sur les contextes
|
||||
// Enables double-buffering on contexts Active le double-buffering sur les contextes
|
||||
bool ContextParameters::defaultDoubleBuffered = false;
|
||||
|
||||
// Active le partage des ressources entre contextes (Via le defaultShareContext)
|
||||
// Enables ressource sharing on contexts (via defaultShareContext)
|
||||
bool ContextParameters::defaultShared = true;
|
||||
}
|
||||
|
||||
@@ -129,7 +129,7 @@ namespace Nz
|
||||
|
||||
if (s_useAnisotropicFilter)
|
||||
{
|
||||
for (const std::pair<UInt32, GLuint>& pair : s_samplers)
|
||||
for (const std::pair<const UInt32, GLuint>& pair : s_samplers)
|
||||
{
|
||||
if (((pair.first >> 5) & 0xFF) == 0)
|
||||
glSamplerParameterf(pair.second, GL_TEXTURE_MAX_ANISOTROPY_EXT, static_cast<float>(anisotropyLevel));
|
||||
@@ -149,7 +149,7 @@ namespace Nz
|
||||
|
||||
s_defaultFilterMode = filterMode;
|
||||
|
||||
for (const std::pair<UInt32, GLuint>& pair : s_samplers)
|
||||
for (const std::pair<const UInt32, GLuint>& pair : s_samplers)
|
||||
{
|
||||
if (((pair.first >> 1) & 0x3) == SamplerFilter_Default)
|
||||
{
|
||||
@@ -204,7 +204,7 @@ namespace Nz
|
||||
s_defaultWrapMode = wrapMode;
|
||||
|
||||
GLenum wrapEnum = OpenGL::SamplerWrapMode[wrapMode];
|
||||
for (const std::pair<UInt32, GLuint>& pair : s_samplers)
|
||||
for (const std::pair<const UInt32, GLuint>& pair : s_samplers)
|
||||
{
|
||||
if (((pair.first >> 3) & 0x3) == SamplerWrap_Default)
|
||||
{
|
||||
@@ -380,7 +380,7 @@ namespace Nz
|
||||
if (!s_samplers.empty())
|
||||
{
|
||||
Context::EnsureContext();
|
||||
for (const std::pair<UInt32, GLuint>& pair : s_samplers)
|
||||
for (const std::pair<const UInt32, GLuint>& pair : s_samplers)
|
||||
OpenGL::DeleteSampler(pair.second);
|
||||
|
||||
s_samplers.clear();
|
||||
|
||||
@@ -369,7 +369,7 @@ namespace Nz
|
||||
if (!m_glyphs.empty())
|
||||
{
|
||||
Glyph& lastGlyph = m_glyphs.back();
|
||||
m_lines.back().bounds.ExtendTo(glyph.bounds);
|
||||
m_lines.back().bounds.ExtendTo(lastGlyph.bounds);
|
||||
}
|
||||
|
||||
// Reset cursor
|
||||
|
||||
Reference in New Issue
Block a user