diff --git a/src/graphics/cframebuffer.cpp b/src/graphics/cframebuffer.cpp index 629de65f8..ec4541c02 100644 --- a/src/graphics/cframebuffer.cpp +++ b/src/graphics/cframebuffer.cpp @@ -74,4 +74,16 @@ void cFrameBuffer::RecoverView() { cEngine::instance()->SetView( mPrevView ); } +const Int32& cFrameBuffer::GetWidth() const { + return mWidth; +} + +const Int32& cFrameBuffer::GetHeight() const { + return mHeight; +} + +const bool& cFrameBuffer::HasDepthBuffer() const { + return mHasDepthBuffer; +} + }} diff --git a/src/graphics/cframebuffer.hpp b/src/graphics/cframebuffer.hpp index d16d2aedc..8f8c11879 100644 --- a/src/graphics/cframebuffer.hpp +++ b/src/graphics/cframebuffer.hpp @@ -32,6 +32,12 @@ class EE_API cFrameBuffer { void ClearColor( eeColorAf Color ); eeColorAf ClearColor() const; + + const Int32& GetWidth() const; + + const Int32& GetHeight() const; + + const bool& HasDepthBuffer() const; protected: Int32 mWidth; Int32 mHeight; diff --git a/src/physics/area.hpp b/src/physics/area.hpp index 32c0f8864..0bf717323 100644 --- a/src/physics/area.hpp +++ b/src/physics/area.hpp @@ -3,9 +3,9 @@ #include "base.hpp" -namespace EE { namespace Physics { +CP_NAMESPACE_BEGIN -class Area { +class CP_API Area { public: inline static cpFloat ForCircle( cpFloat r1, cpFloat r2 ) { @@ -21,7 +21,7 @@ class Area { } }; -}} +CP_NAMESPACE_END #endif diff --git a/src/physics/base.hpp b/src/physics/base.hpp index 26f544722..55fb397ce 100644 --- a/src/physics/base.hpp +++ b/src/physics/base.hpp @@ -1,28 +1,36 @@ #ifndef EE_PHYSICS_BASE #define EE_PHYSICS_BASE +//! Chipmunk includes +#include "../helper/chipmunk/chipmunk_private.h" +#include "../helper/chipmunk/chipmunk_unsafe.h" + +//! EE includes needed for the wrapper, all templates, so it will be easy to port this. #include "../base.hpp" - -#include "../math/math.hpp" -using namespace EE::Math; - -#include "../window/cengine.hpp" -using namespace EE::Window; +#include "../utils/vector2.hpp" +#include "../utils/rect.hpp" +#include "../utils/colors.hpp" +using namespace EE::Utils; #include "../system/tsingleton.hpp" using namespace EE::System; +//! Default settings are defined here +#include "settings.hpp" + +//! Some helpers for the wrapper ( most of them can be disabled in the settings ) +#include "physicshelper.hpp" + +//! Dependencies in case that you want to use the EE renderer. +#ifdef PHYSICS_RENDERER_ENABLED + +#include "../window/cengine.hpp" +using namespace EE::Window; + #include "../graphics/cprimitives.hpp" #include "../graphics/cbatchrenderer.hpp" #include "../graphics/cglobalbatchrenderer.hpp" -#include "../helper/chipmunk/chipmunk_private.h" -#include "../helper/chipmunk/chipmunk_unsafe.h" - -#define USE_EE_VECTOR -#define USE_EE_AABB -#define BB_INVERT_Y_AXIS - -#include "physicshelper.hpp" +#endif #endif diff --git a/src/physics/carbiter.cpp b/src/physics/carbiter.cpp index a8389c6d6..ffd06c9b9 100644 --- a/src/physics/carbiter.cpp +++ b/src/physics/carbiter.cpp @@ -1,6 +1,6 @@ #include "carbiter.hpp" -namespace EE { namespace Physics { +CP_NAMESPACE_BEGIN cArbiter::cArbiter( cpArbiter * arbiter ) { mArbiter = arbiter; @@ -80,4 +80,4 @@ cpArbiter * cArbiter::Arbiter() const { return mArbiter; } -}} +CP_NAMESPACE_END diff --git a/src/physics/carbiter.hpp b/src/physics/carbiter.hpp index 56fc9b264..a836d305b 100644 --- a/src/physics/carbiter.hpp +++ b/src/physics/carbiter.hpp @@ -5,9 +5,9 @@ #include "cshape.hpp" #include "cbody.hpp" -namespace EE { namespace Physics { +CP_NAMESPACE_BEGIN -class cArbiter { +class CP_API cArbiter { public: cArbiter( cpArbiter * arbiter ); @@ -38,6 +38,6 @@ class cArbiter { cpArbiter * mArbiter; }; -}} +CP_NAMESPACE_END #endif diff --git a/src/physics/cbody.cpp b/src/physics/cbody.cpp index 69f1922cf..5121ad13a 100644 --- a/src/physics/cbody.cpp +++ b/src/physics/cbody.cpp @@ -1,44 +1,56 @@ #include "cbody.hpp" +#include "cphysicsmanager.hpp" -namespace EE { namespace Physics { +CP_NAMESPACE_BEGIN cBody * cBody::New( cpFloat m, cpFloat i ) { - return eeNew( cBody, ( m, i ) ); + return cpNew( cBody, ( m, i ) ); } cBody * cBody::New( cpBody * body ) { - return eeNew( cBody, ( body ) ); + return cpNew( cBody, ( body ) ); } cBody * cBody::New() { - return eeNew( cBody, () ); + return cpNew( cBody, () ); } void cBody::Free( cBody * body ) { - eeSAFE_DELETE( body ); + cpSAFE_DELETE( body ); } cBody::cBody( cpBody * body ) : mBody( body ), mData( NULL ) { - mBody->data = (void*)this; + SetData(); } cBody::cBody( cpFloat m, cpFloat i ) : + mBody( cpBodyNew( m, i ) ), mData( NULL ) { - mBody = cpBodyNew( m, i ); - mBody->data = (void*)this; + SetData(); } -cBody::cBody() { - mBody = cpBodyNewStatic(); +cBody::cBody() : + mBody( cpBodyNewStatic() ), + mData( NULL ) +{ + SetData(); } cBody::~cBody() { if ( NULL != mBody ) cpBodyFree( mBody ); + + cPhysicsManager::instance()->RemoveBodyFree( this ); +} + +void cBody::SetData() { + mBody->data = (void*)this; + + cPhysicsManager::instance()->AddBodyFree( this ); } void cBody::Activate() { @@ -118,11 +130,11 @@ void cBody::Angle( const cpFloat& rads ) { } cpFloat cBody::AngleDeg() { - return Degrees( mBody->a ); + return cpDegrees( mBody->a ); } void cBody::AngleDeg( const cpFloat& angle ) { - Angle( Radians( angle ) ); + Angle( cpRadians( angle ) ); } cpFloat cBody::AngVel() const { @@ -197,4 +209,4 @@ void cBody::Data( void * data ) { mData = data; } -}} +CP_NAMESPACE_END diff --git a/src/physics/cbody.hpp b/src/physics/cbody.hpp index 2013dc9e4..63256e17f 100644 --- a/src/physics/cbody.hpp +++ b/src/physics/cbody.hpp @@ -3,9 +3,9 @@ #include "base.hpp" -namespace EE { namespace Physics { +CP_NAMESPACE_BEGIN -class cBody { +class CP_API cBody { public: static cBody * New( cpFloat m, cpFloat i ); @@ -105,8 +105,10 @@ class cBody { cpBody * mBody; void * mData; + + void SetData(); }; -}} +CP_NAMESPACE_END #endif diff --git a/src/physics/constraints/cconstraint.cpp b/src/physics/constraints/cconstraint.cpp index c5de45324..cfd06dbd2 100644 --- a/src/physics/constraints/cconstraint.cpp +++ b/src/physics/constraints/cconstraint.cpp @@ -1,9 +1,10 @@ #include "cconstraint.hpp" +#include "../cphysicsmanager.hpp" -namespace EE { namespace Physics { +CP_NAMESPACE_BEGIN void cConstraint::Free( cConstraint * constraint ) { - eeSAFE_DELETE( constraint ); + cpSAFE_DELETE( constraint ); } cConstraint::cConstraint( cpConstraint * Constraint ) { @@ -16,10 +17,13 @@ cConstraint::cConstraint() { cConstraint::~cConstraint() { cpConstraintFree( mConstraint ); + + cPhysicsManager::instance()->RemoveConstraintFree( this ); } void cConstraint::SetData() { mConstraint->data = (void*)this; + cPhysicsManager::instance()->AddConstraintFree( this ); } cpConstraint * cConstraint::Constraint() const { @@ -61,4 +65,4 @@ void cConstraint::MaxBias( const cpFloat& maxbias ) { void cConstraint::Draw() { } -}} +CP_NAMESPACE_END diff --git a/src/physics/constraints/cconstraint.hpp b/src/physics/constraints/cconstraint.hpp index 560dd9533..bd916cff1 100644 --- a/src/physics/constraints/cconstraint.hpp +++ b/src/physics/constraints/cconstraint.hpp @@ -4,16 +4,14 @@ #include "../base.hpp" #include "../cbody.hpp" -namespace EE { namespace Physics { +CP_NAMESPACE_BEGIN -class cConstraint { +class CP_API cConstraint { public: static void Free( cConstraint * constraint ); cConstraint( cpConstraint * Constraint ); - cConstraint(); - ~cConstraint(); cpConstraint * Constraint() const; @@ -38,9 +36,11 @@ class cConstraint { protected: cpConstraint * mConstraint; + cConstraint(); + void SetData(); }; -}} +CP_NAMESPACE_END #endif diff --git a/src/physics/constraints/cdampedrotaryspring.cpp b/src/physics/constraints/cdampedrotaryspring.cpp index a00334ba0..e08c2b04d 100644 --- a/src/physics/constraints/cdampedrotaryspring.cpp +++ b/src/physics/constraints/cdampedrotaryspring.cpp @@ -1,6 +1,6 @@ #include "cdampedrotaryspring.hpp" -namespace EE { namespace Physics { +CP_NAMESPACE_BEGIN cDampedRotarySpring::cDampedRotarySpring( cBody * a, cBody * b, cpFloat restAngle, cpFloat stiffness, cpFloat damping ) { mConstraint = cpDampedRotarySpringNew( a->Body(), b->Body(), restAngle, stiffness, damping ); @@ -35,4 +35,4 @@ void cDampedRotarySpring::Draw() { // Not implemented } -}} +CP_NAMESPACE_END diff --git a/src/physics/constraints/cdampedrotaryspring.hpp b/src/physics/constraints/cdampedrotaryspring.hpp index cec8c3242..bcc592b77 100644 --- a/src/physics/constraints/cdampedrotaryspring.hpp +++ b/src/physics/constraints/cdampedrotaryspring.hpp @@ -3,9 +3,9 @@ #include "cconstraint.hpp" -namespace EE { namespace Physics { +CP_NAMESPACE_BEGIN -class cDampedRotarySpring : public cConstraint { +class CP_API cDampedRotarySpring : public cConstraint { public: cDampedRotarySpring( cBody * a, cBody * b, cpFloat restAngle, cpFloat stiffness, cpFloat damping ); @@ -24,6 +24,6 @@ class cDampedRotarySpring : public cConstraint { virtual void Draw(); }; -}} +CP_NAMESPACE_END #endif diff --git a/src/physics/constraints/cdampedspring.cpp b/src/physics/constraints/cdampedspring.cpp index c5b3bcc32..4fdc8a0c5 100644 --- a/src/physics/constraints/cdampedspring.cpp +++ b/src/physics/constraints/cdampedspring.cpp @@ -1,6 +1,6 @@ #include "cdampedspring.hpp" -namespace EE { namespace Physics { +CP_NAMESPACE_BEGIN cDampedSpring::cDampedSpring( cBody * a, cBody * b, cVect anchr1, cVect anchr2, cpFloat restLength, cpFloat stiffness, cpFloat damping ) { mConstraint = cpDampedSpringNew( a->Body(), b->Body(), tocpv( anchr1 ), tocpv( anchr2 ), restLength, stiffness, damping ); @@ -48,6 +48,7 @@ void cDampedSpring::Damping( const cpFloat& damping ) { } void cDampedSpring::Draw() { + #ifdef PHYSICS_RENDERER_ENABLED cpDampedSpring * spring = (cpDampedSpring*)mConstraint; cpBody * body_a = mConstraint->a; cpBody * body_b = mConstraint->b; @@ -81,6 +82,7 @@ void cDampedSpring::Draw() { glMultMatrixf(matrix); glDrawArrays(GL_LINE_STRIP, 0, springVAR_count); } glPopMatrix(); + #endif } -}} +CP_NAMESPACE_END diff --git a/src/physics/constraints/cdampedspring.hpp b/src/physics/constraints/cdampedspring.hpp index e6fdb8917..cb336c83d 100644 --- a/src/physics/constraints/cdampedspring.hpp +++ b/src/physics/constraints/cdampedspring.hpp @@ -3,9 +3,9 @@ #include "cconstraint.hpp" -namespace EE { namespace Physics { +CP_NAMESPACE_BEGIN -class cDampedSpring : public cConstraint { +class CP_API cDampedSpring : public cConstraint { public: cDampedSpring( cBody * a, cBody * b, cVect anchr1, cVect anchr2, cpFloat restLength, cpFloat stiffness, cpFloat damping ); @@ -32,6 +32,6 @@ class cDampedSpring : public cConstraint { virtual void Draw(); }; -}} +CP_NAMESPACE_END #endif diff --git a/src/physics/constraints/cgearjoint.cpp b/src/physics/constraints/cgearjoint.cpp index 72e002160..6159bccbf 100644 --- a/src/physics/constraints/cgearjoint.cpp +++ b/src/physics/constraints/cgearjoint.cpp @@ -1,6 +1,6 @@ #include "cgearjoint.hpp" -namespace EE { namespace Physics { +CP_NAMESPACE_BEGIN cGearJoint::cGearJoint( cBody * a, cBody * b, cpFloat phase, cpFloat ratio ) { mConstraint = cpGearJointNew( a->Body(), b->Body(), phase, ratio ); @@ -27,4 +27,4 @@ void cGearJoint::Draw() { // Not implemented } -}} +CP_NAMESPACE_END diff --git a/src/physics/constraints/cgearjoint.hpp b/src/physics/constraints/cgearjoint.hpp index 475d8442a..353500a42 100644 --- a/src/physics/constraints/cgearjoint.hpp +++ b/src/physics/constraints/cgearjoint.hpp @@ -3,9 +3,9 @@ #include "cconstraint.hpp" -namespace EE { namespace Physics { +CP_NAMESPACE_BEGIN -class cGearJoint : public cConstraint { +class CP_API cGearJoint : public cConstraint { public: cGearJoint( cBody * a, cBody * b, cpFloat phase, cpFloat ratio ); @@ -20,6 +20,6 @@ class cGearJoint : public cConstraint { virtual void Draw(); }; -}} +CP_NAMESPACE_END #endif diff --git a/src/physics/constraints/cgroovejoint.cpp b/src/physics/constraints/cgroovejoint.cpp index 810cda0d5..a45f6d20b 100644 --- a/src/physics/constraints/cgroovejoint.cpp +++ b/src/physics/constraints/cgroovejoint.cpp @@ -1,6 +1,6 @@ #include "cgroovejoint.hpp" -namespace EE { namespace Physics { +CP_NAMESPACE_BEGIN cGrooveJoint::cGrooveJoint( cBody * a, cBody * b, cVect groove_a, cVect groove_b, cVect anchr2 ) { mConstraint = cpGrooveJointNew( a->Body(), b->Body(), tocpv( groove_a ), tocpv( groove_b ), tocpv( anchr2 ) ); @@ -32,6 +32,7 @@ void cGrooveJoint::GrooveB( const cVect& groove_b ) { } void cGrooveJoint::Draw() { + #ifdef PHYSICS_RENDERER_ENABLED cpGrooveJoint *joint= (cpGrooveJoint *)mConstraint; cpBody * body_a = mConstraint->a; cpBody * body_b = mConstraint->b; @@ -52,6 +53,7 @@ void cGrooveJoint::Draw() { BR->Draw(); BR->SetPointSize( ps ); + #endif } -}} +CP_NAMESPACE_END diff --git a/src/physics/constraints/cgroovejoint.hpp b/src/physics/constraints/cgroovejoint.hpp index f52377b20..9b85b67b0 100644 --- a/src/physics/constraints/cgroovejoint.hpp +++ b/src/physics/constraints/cgroovejoint.hpp @@ -3,9 +3,9 @@ #include "cconstraint.hpp" -namespace EE { namespace Physics { +CP_NAMESPACE_BEGIN -class cGrooveJoint : public cConstraint { +class CP_API cGrooveJoint : public cConstraint { public: cGrooveJoint( cBody * a, cBody * b, cVect groove_a, cVect groove_b, cVect anchr2 ); @@ -24,6 +24,6 @@ class cGrooveJoint : public cConstraint { virtual void Draw(); }; -}} +CP_NAMESPACE_END #endif diff --git a/src/physics/constraints/cpinjoint.cpp b/src/physics/constraints/cpinjoint.cpp index 41b1b4cd7..7606b70ae 100644 --- a/src/physics/constraints/cpinjoint.cpp +++ b/src/physics/constraints/cpinjoint.cpp @@ -1,6 +1,6 @@ #include "cpinjoint.hpp" -namespace EE { namespace Physics { +CP_NAMESPACE_BEGIN cPinJoint::cPinJoint( cBody * a, cBody * b, cVect anchr1, cVect anchr2 ) { mConstraint = cpPinJointNew( a->Body(), b->Body(), tocpv( anchr1 ), tocpv( anchr2 ) ); @@ -32,6 +32,7 @@ void cPinJoint::Dist( const cpFloat& dist ) { } void cPinJoint::Draw() { + #ifdef PHYSICS_RENDERER_ENABLED cpPinJoint *joint = (cpPinJoint *)mConstraint; cpBody * body_a = mConstraint->a; cpBody * body_b = mConstraint->b; @@ -53,6 +54,7 @@ void cPinJoint::Draw() { BR->Draw(); BR->SetPointSize( ps ); + #endif } -}} +CP_NAMESPACE_END diff --git a/src/physics/constraints/cpinjoint.hpp b/src/physics/constraints/cpinjoint.hpp index 13c5757a8..c01bf0776 100644 --- a/src/physics/constraints/cpinjoint.hpp +++ b/src/physics/constraints/cpinjoint.hpp @@ -3,9 +3,9 @@ #include "cconstraint.hpp" -namespace EE { namespace Physics { +CP_NAMESPACE_BEGIN -class cPinJoint : public cConstraint { +class CP_API cPinJoint : public cConstraint { public: cPinJoint( cBody * a, cBody * b, cVect anchr1, cVect anchr2 ); @@ -24,6 +24,6 @@ class cPinJoint : public cConstraint { virtual void Draw(); }; -}} +CP_NAMESPACE_END #endif diff --git a/src/physics/constraints/cpivotjoint.cpp b/src/physics/constraints/cpivotjoint.cpp index 3d415d86d..339d181f6 100644 --- a/src/physics/constraints/cpivotjoint.cpp +++ b/src/physics/constraints/cpivotjoint.cpp @@ -1,6 +1,6 @@ #include "cpivotjoint.hpp" -namespace EE { namespace Physics { +CP_NAMESPACE_BEGIN cPivotJoint::cPivotJoint( cBody * a, cBody * b, cVect pivot ) { mConstraint = cpPivotJointNew( a->Body(), b->Body(), tocpv( pivot ) ); @@ -29,6 +29,7 @@ void cPivotJoint::Anchr2( const cVect& anchr2 ) { } void cPivotJoint::Draw() { + #ifdef PHYSICS_RENDERER_ENABLED cpBody * body_a = mConstraint->a; cpBody * body_b = mConstraint->b; cpPivotJoint* joint = (cpPivotJoint *)mConstraint; @@ -44,6 +45,7 @@ void cPivotJoint::Draw() { BR->BatchPoint( b.x, b.y ); BR->Draw(); BR->SetPointSize( ps ); + #endif } -}} +CP_NAMESPACE_END diff --git a/src/physics/constraints/cpivotjoint.hpp b/src/physics/constraints/cpivotjoint.hpp index 74eefb0af..ae3e23e54 100644 --- a/src/physics/constraints/cpivotjoint.hpp +++ b/src/physics/constraints/cpivotjoint.hpp @@ -3,9 +3,9 @@ #include "cconstraint.hpp" -namespace EE { namespace Physics { +CP_NAMESPACE_BEGIN -class cPivotJoint : public cConstraint { +class CP_API cPivotJoint : public cConstraint { public: cPivotJoint( cBody * a, cBody * b, cVect pivot ); @@ -22,6 +22,6 @@ class cPivotJoint : public cConstraint { virtual void Draw(); }; -}} +CP_NAMESPACE_END #endif diff --git a/src/physics/constraints/cratchetjoint.cpp b/src/physics/constraints/cratchetjoint.cpp index 1573b3b83..706df687d 100644 --- a/src/physics/constraints/cratchetjoint.cpp +++ b/src/physics/constraints/cratchetjoint.cpp @@ -1,6 +1,6 @@ #include "cratchetjoint.hpp" -namespace EE { namespace Physics { +CP_NAMESPACE_BEGIN cRatchetJoint::cRatchetJoint( cBody * a, cBody * b, cpFloat phase, cpFloat ratchet ) { mConstraint = cpRatchetJointNew( a->Body(), b->Body(), phase, ratchet ); @@ -35,4 +35,4 @@ void cRatchetJoint::Draw() { // Not implemented } -}} +CP_NAMESPACE_END diff --git a/src/physics/constraints/cratchetjoint.hpp b/src/physics/constraints/cratchetjoint.hpp index 406804ae8..79dbc9ed0 100644 --- a/src/physics/constraints/cratchetjoint.hpp +++ b/src/physics/constraints/cratchetjoint.hpp @@ -3,9 +3,9 @@ #include "cconstraint.hpp" -namespace EE { namespace Physics { +CP_NAMESPACE_BEGIN -class cRatchetJoint : public cConstraint { +class CP_API cRatchetJoint : public cConstraint { public: cRatchetJoint( cBody * a, cBody * b, cpFloat phase, cpFloat ratchet ); @@ -24,6 +24,6 @@ class cRatchetJoint : public cConstraint { virtual void Draw(); }; -}} +CP_NAMESPACE_END #endif diff --git a/src/physics/constraints/crotarylimitjoint.cpp b/src/physics/constraints/crotarylimitjoint.cpp index 918cc7158..84ccea167 100644 --- a/src/physics/constraints/crotarylimitjoint.cpp +++ b/src/physics/constraints/crotarylimitjoint.cpp @@ -1,6 +1,6 @@ #include "crotarylimitjoint.hpp" -namespace EE { namespace Physics { +CP_NAMESPACE_BEGIN cRotaryLimitJoint::cRotaryLimitJoint( cBody * a, cBody * b, cpFloat min, cpFloat max ) { mConstraint = cpRotaryLimitJointNew( a->Body(), b->Body(), min, max ); @@ -27,4 +27,4 @@ void cRotaryLimitJoint::Draw() { // Not implemented } -}} +CP_NAMESPACE_END diff --git a/src/physics/constraints/crotarylimitjoint.hpp b/src/physics/constraints/crotarylimitjoint.hpp index 42f8ef689..c704ff6b2 100644 --- a/src/physics/constraints/crotarylimitjoint.hpp +++ b/src/physics/constraints/crotarylimitjoint.hpp @@ -3,9 +3,9 @@ #include "cconstraint.hpp" -namespace EE { namespace Physics { +CP_NAMESPACE_BEGIN -class cRotaryLimitJoint : public cConstraint { +class CP_API cRotaryLimitJoint : public cConstraint { public: cRotaryLimitJoint( cBody * a, cBody * b, cpFloat min, cpFloat max ); @@ -20,6 +20,6 @@ class cRotaryLimitJoint : public cConstraint { virtual void Draw(); }; -}} +CP_NAMESPACE_END #endif diff --git a/src/physics/constraints/csimplemotor.cpp b/src/physics/constraints/csimplemotor.cpp index 707bad282..08d308351 100644 --- a/src/physics/constraints/csimplemotor.cpp +++ b/src/physics/constraints/csimplemotor.cpp @@ -1,6 +1,6 @@ #include "csimplemotor.hpp" -namespace EE { namespace Physics { +CP_NAMESPACE_BEGIN cSimpleMotor::cSimpleMotor( cBody * a, cBody * b, cpFloat rate ) { mConstraint = cpSimpleMotorNew( a->Body(), b->Body(), rate ); @@ -19,4 +19,4 @@ void cSimpleMotor::Draw() { // Not implemented } -}} +CP_NAMESPACE_END diff --git a/src/physics/constraints/csimplemotor.hpp b/src/physics/constraints/csimplemotor.hpp index e43287115..db48e8b04 100644 --- a/src/physics/constraints/csimplemotor.hpp +++ b/src/physics/constraints/csimplemotor.hpp @@ -3,9 +3,9 @@ #include "cconstraint.hpp" -namespace EE { namespace Physics { +CP_NAMESPACE_BEGIN -class cSimpleMotor : public cConstraint { +class CP_API cSimpleMotor : public cConstraint { public: cSimpleMotor( cBody * a, cBody * b, cpFloat rate ); @@ -16,6 +16,6 @@ class cSimpleMotor : public cConstraint { virtual void Draw(); }; -}} +CP_NAMESPACE_END #endif diff --git a/src/physics/constraints/cslidejoint.cpp b/src/physics/constraints/cslidejoint.cpp index 271fe9bfa..27db461dd 100644 --- a/src/physics/constraints/cslidejoint.cpp +++ b/src/physics/constraints/cslidejoint.cpp @@ -1,6 +1,6 @@ #include "cslidejoint.hpp" -namespace EE { namespace Physics { +CP_NAMESPACE_BEGIN cSlideJoint::cSlideJoint( cBody * a, cBody *b, cVect anchr1, cVect anchr2, cpFloat min, cpFloat max ) { mConstraint = cpSlideJointNew( a->Body(), b->Body(), tocpv( anchr1 ), tocpv( anchr2 ), min, max ); @@ -40,6 +40,7 @@ void cSlideJoint::Max( const cpFloat& max ) { } void cSlideJoint::Draw() { + #ifdef PHYSICS_RENDERER_ENABLED cpBody * body_a = mConstraint->a; cpBody * body_b = mConstraint->b; cpSlideJoint *joint = (cpSlideJoint *)mConstraint; @@ -59,6 +60,7 @@ void cSlideJoint::Draw() { BR->BatchLine( a.x, a.y, b.x, b.y ); BR->Draw(); BR->SetPointSize( ps ); + #endif } -}} +CP_NAMESPACE_END diff --git a/src/physics/constraints/cslidejoint.hpp b/src/physics/constraints/cslidejoint.hpp index a648bcbac..797cb38b0 100644 --- a/src/physics/constraints/cslidejoint.hpp +++ b/src/physics/constraints/cslidejoint.hpp @@ -3,9 +3,9 @@ #include "cconstraint.hpp" -namespace EE { namespace Physics { +CP_NAMESPACE_BEGIN -class cSlideJoint : public cConstraint { +class CP_API cSlideJoint : public cConstraint { public: cSlideJoint( cBody * a, cBody *b, cVect anchr1, cVect anchr2, cpFloat min, cpFloat max ); @@ -28,6 +28,6 @@ class cSlideJoint : public cConstraint { virtual void Draw(); }; -}} +CP_NAMESPACE_END #endif diff --git a/src/physics/cphysicsmanager.cpp b/src/physics/cphysicsmanager.cpp index 7a35f9009..341fc33ae 100644 --- a/src/physics/cphysicsmanager.cpp +++ b/src/physics/cphysicsmanager.cpp @@ -1,12 +1,37 @@ #include "cphysicsmanager.hpp" +#include "cbody.hpp" +#include "cshape.hpp" +#include "cspace.hpp" +#include "constraints/cconstraint.hpp" -namespace EE { namespace Physics { +CP_NAMESPACE_BEGIN -cPhysicsManager::cPhysicsManager() { +cPhysicsManager::cPhysicsManager() : + mMemoryManager( false ) +{ cpInitChipmunk(); } cPhysicsManager::~cPhysicsManager() { + if ( mMemoryManager ) { + mMemoryManager = false; + + std::list::iterator its = mSpaces.begin(); + for ( ; its != mSpaces.end(); its++ ) + cpSAFE_DELETE( *its ); + + std::list::iterator itb = mBodysFree.begin(); + for ( ; itb != mBodysFree.end(); itb++ ) + cpSAFE_DELETE( *itb ); + + std::list::iterator itp = mShapesFree.begin(); + for ( ; itp != mShapesFree.end(); itp++ ) + cpSAFE_DELETE( *itp ); + + std::list::iterator itc = mConstraintFree.begin(); + for ( ; itc != mConstraintFree.end(); itc++ ) + cpSAFE_DELETE( *itc ); + } } const cpFloat& cPhysicsManager::BiasCoef() const { @@ -45,4 +70,64 @@ cPhysicsManager::cDrawSpaceOptions * cPhysicsManager::GetDrawOptions() { return &mOptions; } -}} +void cPhysicsManager::MemoryManager( bool MemoryManager ) { + mMemoryManager = MemoryManager; +} + +const bool& cPhysicsManager::MemoryManager() const { + return mMemoryManager; +} + +void cPhysicsManager::AddBodyFree( cBody * body ) { + if ( mMemoryManager ) { + if ( std::find( mBodysFree.begin(), mBodysFree.end(), body ) == mBodysFree.end() ) + mBodysFree.push_back( body ); + } +} + +void cPhysicsManager::RemoveBodyFree( cBody * body ) { + if ( mMemoryManager ) { + mBodysFree.remove( body ); + } +} + +void cPhysicsManager::AddShapeFree( cShape * shape ) { + if ( mMemoryManager ) { + if ( std::find( mShapesFree.begin(), mShapesFree.end(), shape ) == mShapesFree.end() ) + mShapesFree.push_back( shape ); + } +} + +void cPhysicsManager::RemoveShapeFree( cShape * shape ) { + if ( mMemoryManager ) { + mShapesFree.remove( shape ); + } +} + +void cPhysicsManager::AddConstraintFree( cConstraint * constraint ) { + if ( mMemoryManager ) { + if ( std::find( mConstraintFree.begin(), mConstraintFree.end(), constraint ) == mConstraintFree.end() ) + mConstraintFree.push_back( constraint ); + } +} + +void cPhysicsManager::RemoveConstraintFree( cConstraint * constraint ) { + if ( mMemoryManager ) { + mConstraintFree.remove( constraint ); + } +} + +void cPhysicsManager::AddSpace( cSpace * space ) { + if ( mMemoryManager ) { + if ( std::find( mSpaces.begin(), mSpaces.end(), space ) == mSpaces.end() ) + mSpaces.push_back( space ); + } +} + +void cPhysicsManager::RemoveSpace( cSpace * space ) { + if ( mMemoryManager ) { + mSpaces.remove( space ); + } +} + +CP_NAMESPACE_END diff --git a/src/physics/cphysicsmanager.hpp b/src/physics/cphysicsmanager.hpp index 80f2d228a..9a0513e30 100644 --- a/src/physics/cphysicsmanager.hpp +++ b/src/physics/cphysicsmanager.hpp @@ -3,9 +3,14 @@ #include "base.hpp" -namespace EE { namespace Physics { +CP_NAMESPACE_BEGIN -class EE_API cPhysicsManager : public tSingleton { +class cBody; +class cShape; +class cConstraint; +class cSpace; + +class CP_API cPhysicsManager : public tSingleton { friend class tSingleton; public: class cDrawSpaceOptions { @@ -31,6 +36,14 @@ class EE_API cPhysicsManager : public tSingleton { ~cPhysicsManager(); + /** The Memory Manager will keep track of all the allocations from cSpace, cBody, cShape and cConstraint and will release any non-released pointer. + *** This is a lazy deallocation for the lazy programmers. It is disabled by defeault. + *** To work properly set as active before allocating anything, activate it just before the singleton creation. + */ + void MemoryManager( bool MemoryManager ); + + const bool& MemoryManager() const; + const cpFloat& BiasCoef() const; void BiasCoef( const cpFloat& biasCoef ); @@ -50,8 +63,35 @@ class EE_API cPhysicsManager : public tSingleton { cPhysicsManager::cDrawSpaceOptions * GetDrawOptions(); protected: cDrawSpaceOptions mOptions; + + friend class cBody; + friend class cShape; + friend class cConstraint; + friend class cSpace; + + bool mMemoryManager; + std::list mBodysFree; + std::list mShapesFree; + std::list mConstraintFree; + std::list mSpaces; + + void AddBodyFree( cBody * body ); + + void RemoveBodyFree( cBody * body ); + + void AddShapeFree( cShape * shape ); + + void RemoveShapeFree( cShape * shape ); + + void AddConstraintFree( cConstraint * constraint ); + + void RemoveConstraintFree( cConstraint * constraint ); + + void AddSpace( cSpace * space ); + + void RemoveSpace( cSpace * space ); }; -}} +CP_NAMESPACE_END #endif diff --git a/src/physics/cshape.cpp b/src/physics/cshape.cpp index feb7f5909..3d78adee7 100644 --- a/src/physics/cshape.cpp +++ b/src/physics/cshape.cpp @@ -2,8 +2,9 @@ #include "cshapecircle.hpp" #include "cshapesegment.hpp" #include "cshapepoly.hpp" +#include "cphysicsmanager.hpp" -namespace EE { namespace Physics { +CP_NAMESPACE_BEGIN void cShape::ResetShapeIdCounter() { cpResetShapeIdCounter(); @@ -12,10 +13,10 @@ void cShape::ResetShapeIdCounter() { void cShape::Free( cShape * shape, bool DeleteBody ) { if ( DeleteBody ) { cBody * b = shape->Body(); - eeSAFE_DELETE( b ); + cpSAFE_DELETE( b ); } - eeSAFE_DELETE( shape ); + cpSAFE_DELETE( shape ); } cShape::cShape() : @@ -25,10 +26,13 @@ cShape::cShape() : cShape::~cShape() { cpShapeFree( mShape ); + + cPhysicsManager::instance()->RemoveShapeFree( this ); } void cShape::SetData() { mShape->data = (void*)this; + cPhysicsManager::instance()->AddShapeFree( this ); } cpShape * cShape::Shape() const { @@ -158,9 +162,11 @@ cShapeSegment * cShape::GetAsSegment() { } void cShape::DrawBB() { + #ifdef PHYSICS_RENDERER_ENABLED cPrimitives P; P.SetColor( eeColorA( 76, 128, 76, 255 ) ); P.DrawRectangle( eeRectf( mShape->bb.l, mShape->bb.t, mShape->bb.r, mShape->bb.b ), 0.f, 1.f, EE_DRAW_LINE ); + #endif } void * cShape::Data() const { @@ -171,4 +177,4 @@ void cShape::Data( void * data ) { mData = data; } -}} +CP_NAMESPACE_END diff --git a/src/physics/cshape.hpp b/src/physics/cshape.hpp index 1ed2ce86b..169cbe255 100644 --- a/src/physics/cshape.hpp +++ b/src/physics/cshape.hpp @@ -4,14 +4,14 @@ #include "base.hpp" #include "cbody.hpp" -namespace EE { namespace Physics { +CP_NAMESPACE_BEGIN class cShapeCircle; class cShapeSegment; class cShapePoly; class cSpace; -class cShape { +class CP_API cShape { public: static void ResetShapeIdCounter(); @@ -95,6 +95,6 @@ class cShape { void SetData(); }; -}} +CP_NAMESPACE_END #endif diff --git a/src/physics/cshapecircle.cpp b/src/physics/cshapecircle.cpp index a9bbab06e..261d9998e 100644 --- a/src/physics/cshapecircle.cpp +++ b/src/physics/cshapecircle.cpp @@ -1,10 +1,10 @@ #include "cshapecircle.hpp" #include "cspace.hpp" -namespace EE { namespace Physics { +CP_NAMESPACE_BEGIN cShapeCircle * cShapeCircle::New( cBody * body, cpFloat radius, cVect offset ) { - return eeNew( cShapeCircle, ( body, radius, offset ) ); + return cpNew( cShapeCircle, ( body, radius, offset ) ); } cShapeCircle::cShapeCircle( cBody * body, cpFloat radius, cVect offset ) { @@ -29,12 +29,14 @@ void cShapeCircle::Radius( const cpFloat& radius ) { } void cShapeCircle::Draw( cSpace * space ) { + #ifdef PHYSICS_RENDERER_ENABLED cPrimitives p; cpCircleShape * cs = (cpCircleShape*)mShape; p.SetColor( ColorForShape( mShape, space->Space() ) ); p.DrawCircle( cs->CP_PRIVATE(tc).x, cs->CP_PRIVATE(tc).y, cs->CP_PRIVATE(r) ); + #endif } -}} +CP_NAMESPACE_END diff --git a/src/physics/cshapecircle.hpp b/src/physics/cshapecircle.hpp index 8af43a431..a7ef00bd5 100644 --- a/src/physics/cshapecircle.hpp +++ b/src/physics/cshapecircle.hpp @@ -3,9 +3,9 @@ #include "cshape.hpp" -namespace EE { namespace Physics { +CP_NAMESPACE_BEGIN -class cShapeCircle : public cShape { +class CP_API cShapeCircle : public cShape { public: static cShapeCircle * New( cBody * body, cpFloat radius, cVect offset ); @@ -22,6 +22,6 @@ class cShapeCircle : public cShape { virtual void Draw( cSpace * space ); }; -}} +CP_NAMESPACE_END #endif diff --git a/src/physics/cshapepoly.cpp b/src/physics/cshapepoly.cpp index 32cb82fde..1b0394364 100644 --- a/src/physics/cshapepoly.cpp +++ b/src/physics/cshapepoly.cpp @@ -1,14 +1,14 @@ #include "cshapepoly.hpp" #include "cspace.hpp" -namespace EE { namespace Physics { +CP_NAMESPACE_BEGIN cShapePoly * cShapePoly::New( cBody * body, int numVerts, cVect *verts, cVect offset ) { - return eeNew( cShapePoly, ( body, numVerts, verts, offset ) ); + return cpNew( cShapePoly, ( body, numVerts, verts, offset ) ); } cShapePoly * cShapePoly::New( cBody * body, cpFloat width, cpFloat height ) { - return eeNew( cShapePoly, ( body, width, height ) ); + return cpNew( cShapePoly, ( body, width, height ) ); } cShapePoly::cShapePoly( cBody * body, int numVerts, cVect *verts, cVect offset ) { @@ -48,6 +48,7 @@ cVect cShapePoly::Centroid( int numVerts, const cVect * verts ) { } void cShapePoly::Draw( cSpace * space ) { + #ifdef PHYSICS_RENDERER_ENABLED cpPolyShape * poly = (cpPolyShape*)mShape; cBatchRenderer * BR = cGlobalBatchRenderer::instance(); @@ -75,6 +76,7 @@ void cShapePoly::Draw( cSpace * space ) { } BR->Draw(); + #endif } -}} +CP_NAMESPACE_END diff --git a/src/physics/cshapepoly.hpp b/src/physics/cshapepoly.hpp index 8185706ff..f41cfed54 100644 --- a/src/physics/cshapepoly.hpp +++ b/src/physics/cshapepoly.hpp @@ -3,9 +3,9 @@ #include "cshape.hpp" -namespace EE { namespace Physics { +CP_NAMESPACE_BEGIN -class cShapePoly : public cShape { +class CP_API cShapePoly : public cShape { public: static cShapePoly * New( cBody * body, int numVerts, cVect *verts, cVect offset ); @@ -30,6 +30,6 @@ class cShapePoly : public cShape { static cVect Centroid( int numVerts, const cVect * verts ); }; -}} +CP_NAMESPACE_END #endif diff --git a/src/physics/cshapesegment.cpp b/src/physics/cshapesegment.cpp index 97eb014bf..38703d0c8 100644 --- a/src/physics/cshapesegment.cpp +++ b/src/physics/cshapesegment.cpp @@ -1,10 +1,10 @@ #include "cshapesegment.hpp" #include "cspace.hpp" -namespace EE { namespace Physics { +CP_NAMESPACE_BEGIN cShapeSegment * cShapeSegment::New( cBody * body, cVect a, cVect b, cpFloat radius ) { - return eeNew( cShapeSegment, ( body, a, b, radius ) ); + return cpNew( cShapeSegment, ( body, a, b, radius ) ); } cShapeSegment::cShapeSegment( cBody * body, cVect a, cVect b, cpFloat radius ) { @@ -49,6 +49,7 @@ cpFloat cShapeSegment::QueryHitDist( const cVect start, const cVect end, const c } void cShapeSegment::Draw( cSpace * space ) { + #ifdef PHYSICS_RENDERER_ENABLED cpSegmentShape * seg = (cpSegmentShape *)mShape; cVect a = tovect( seg->CP_PRIVATE(ta) ); cVect b = tovect( seg->CP_PRIVATE(tb) ); @@ -92,6 +93,7 @@ void cShapeSegment::Draw( cSpace * space ) { cPrimitives p; p.DrawLine( eeVector2f( a.x, a.y ), eeVector2f( b.x, b.y ) ); } + #endif } -}} +CP_NAMESPACE_END diff --git a/src/physics/cshapesegment.hpp b/src/physics/cshapesegment.hpp index e3a81894c..af38af11a 100644 --- a/src/physics/cshapesegment.hpp +++ b/src/physics/cshapesegment.hpp @@ -3,9 +3,9 @@ #include "cshape.hpp" -namespace EE { namespace Physics { +CP_NAMESPACE_BEGIN -class cShapeSegment : public cShape { +class CP_API cShapeSegment : public cShape { public: static cShapeSegment * New( cBody * body, cVect a, cVect b, cpFloat radius ); @@ -32,6 +32,6 @@ class cShapeSegment : public cShape { virtual void Draw( cSpace * space ); }; -}} +CP_NAMESPACE_END #endif diff --git a/src/physics/cspace.cpp b/src/physics/cspace.cpp index 469034986..0941b7220 100644 --- a/src/physics/cspace.cpp +++ b/src/physics/cspace.cpp @@ -1,39 +1,45 @@ #include "cspace.hpp" #include "cphysicsmanager.hpp" -namespace EE { namespace Physics { +CP_NAMESPACE_BEGIN cSpace * cSpace::New() { - return eeNew( cSpace, () ); + return cpNew( cSpace, () ); } void cSpace::Free( cSpace * space ) { - eeSAFE_DELETE( space ); + cpSAFE_DELETE( space ); } cSpace::cSpace() { mSpace = cpSpaceNew(); mSpace->data = (void*)this; - mStaticBody = eeNew( cBody, ( mSpace->staticBody ) ); + mStaticBody = cpNew( cBody, ( mSpace->staticBody ) ); + + cPhysicsManager::instance()->RemoveBodyFree( mStaticBody ); + cPhysicsManager::instance()->AddSpace( this ); } -cSpace::~cSpace() { +cSpace::~cSpace() { cpSpaceFree( mSpace ); std::list::iterator itc = mConstraints.begin(); for ( ; itc != mConstraints.end(); itc++ ) - eeSAFE_DELETE( *itc ); + cpSAFE_DELETE( *itc ); std::list::iterator its = mShapes.begin(); for ( ; its != mShapes.end(); its++ ) - eeSAFE_DELETE( *its ); + cpSAFE_DELETE( *its ); std::list::iterator itb = mBodys.begin(); for ( ; itb != mBodys.end(); itb++ ) - eeSAFE_DELETE( *itb ); + cpSAFE_DELETE( *itb ); - mStaticBody->mBody = NULL; - eeSAFE_DELETE( mStaticBody ); + mStaticBody->mBody = NULL; // The body has been released by cpSpaceFree( mSpace ) + + cpSAFE_DELETE( mStaticBody ); + + cPhysicsManager::instance()->RemoveSpace( this ); } void cSpace::Step( const cpFloat& dt ) { @@ -41,7 +47,11 @@ void cSpace::Step( const cpFloat& dt ) { } void cSpace::Update() { + #ifdef PHYSICS_RENDERER_ENABLED Step( cEngine::instance()->Elapsed() / 1000 ); + #else + Step( 1 / 60 ); + #endif } void cSpace::ResizeStaticHash( cpFloat dim, int count ) { @@ -102,53 +112,81 @@ cBody * cSpace::StaticBody() const { cShape * cSpace::AddShape( cShape * shape ) { cpSpaceAddShape( mSpace, shape->Shape() ); + mShapes.push_back( shape ); + + cPhysicsManager::instance()->RemoveShapeFree( shape ); + return shape; } cShape * cSpace::AddStaticShape( cShape * shape ) { cpSpaceAddStaticShape( mSpace, shape->Shape() ); + mShapes.push_back( shape ); + + cPhysicsManager::instance()->RemoveShapeFree( shape ); + return shape; } cBody * cSpace::AddBody( cBody * body ) { cpSpaceAddBody( mSpace, body->Body() ); + mBodys.push_back( body ); + + cPhysicsManager::instance()->RemoveBodyFree( body ); + return body; } cConstraint * cSpace::AddConstraint( cConstraint * constraint ) { cpSpaceAddConstraint( mSpace, constraint->Constraint() ); + mConstraints.push_back( constraint ); + + cPhysicsManager::instance()->RemoveConstraintFree( constraint ); + return constraint; } void cSpace::RemoveShape( cShape * shape ) { if ( NULL != shape ) { cpSpaceRemoveShape( mSpace, shape->Shape() ); + mShapes.remove( shape ); + + cPhysicsManager::instance()->AddShapeFree( shape ); } } void cSpace::RemoveStaticShape( cShape * shape ) { if ( NULL != shape ) { cpSpaceRemoveStaticShape( mSpace, shape->Shape() ); + mShapes.remove( shape ); + + cPhysicsManager::instance()->AddShapeFree( shape ); } } void cSpace::RemoveBody( cBody * body ) { if ( NULL != body ) { cpSpaceRemoveBody( mSpace, body->Body() ); + mBodys.remove( body ); + + cPhysicsManager::instance()->RemoveBodyFree( body ); } } void cSpace::RemoveConstraint( cConstraint * constraint ) { if ( NULL != constraint ) { cpSpaceRemoveConstraint( mSpace, constraint->Constraint() ); + mConstraints.remove( constraint ); + + cPhysicsManager::instance()->AddConstraintFree( constraint ); } } @@ -184,6 +222,7 @@ void cSpace::RehashShape( cShape * shape ) { cpSpaceRehashShape( mSpace, shape->Shape() ); } +#ifdef PHYSICS_RENDERER_ENABLED static void drawObject( cpShape * shape, cpSpace * space ) { reinterpret_cast ( shape->data )->Draw( reinterpret_cast( space->data ) ); } @@ -195,8 +234,11 @@ static void drawBB( cpShape *shape, void * unused ) { static void drawConstraint( cpConstraint *constraint ) { reinterpret_cast ( constraint->data )->Draw(); } +#endif void cSpace::Draw() { + #ifdef PHYSICS_RENDERER_ENABLED + cBatchRenderer * BR = cGlobalBatchRenderer::instance(); BR->SetPreBlendFunc( ALPHA_NORMAL ); @@ -206,10 +248,7 @@ void cSpace::Draw() { cpFloat ps = BR->GetPointSize(); if( options->DrawHash ) { - //glColor3f(0.5, 0.5, 0.5); //cpBBTreeRenderDebug( mSpace->staticShapes ); - - //glColor3f(0, 1, 0); //cpBBTreeRenderDebug( mSpace->activeShapes ); } @@ -270,6 +309,8 @@ void cSpace::Draw() { BR->SetLineWidth( lw ); BR->SetPointSize( ps ); + + #endif } /** Collision Handling */ @@ -408,7 +449,7 @@ void cSpace::OnPostStepCallback( void * obj, void * data ) { } mPostStepCallbacks.remove( Cb ); - eeSAFE_DELETE( Cb ); + cpSAFE_DELETE( Cb ); } void cSpace::OnBBQuery( cShape * shape, cBBQuery * query ) { @@ -461,7 +502,7 @@ void cSpace::SetDefaultCollisionHandler( const cCollisionHandler& handler ) { } void cSpace::AddPostStepCallback( PostStepCallback postStep, void * obj, void * data ) { - cPostStepCallback * PostStepCb = eeNew( cPostStepCallback, () ); + cPostStepCallback * PostStepCb = cpNew( cPostStepCallback, () ); PostStepCb->Callback = postStep, PostStepCb->Data = data; @@ -497,4 +538,4 @@ void cSpace::PointQuery( cVect point, cpLayers layers, cpGroup group, PointQuery cpSpacePointQuery( mSpace, tocpv( point ), layers, group, &RecieverPointQueryFunc, reinterpret_cast( &tPointQuery ) ); } -}} +CP_NAMESPACE_END diff --git a/src/physics/cspace.hpp b/src/physics/cspace.hpp index e79ce7176..16071d72c 100644 --- a/src/physics/cspace.hpp +++ b/src/physics/cspace.hpp @@ -7,9 +7,9 @@ #include "carbiter.hpp" #include "constraints/cconstraint.hpp" -namespace EE { namespace Physics { +CP_NAMESPACE_BEGIN -class cSpace { +class CP_API cSpace { public: typedef cb::Callback3 CollisionBeginFunc; typedef cb::Callback3 CollisionPreSolveFunc; @@ -198,6 +198,6 @@ class cSpace { std::list< cPostStepCallback* > mPostStepCallbacks; }; -}} +CP_NAMESPACE_END #endif diff --git a/src/physics/moment.hpp b/src/physics/moment.hpp index 9261128c3..a037dc754 100644 --- a/src/physics/moment.hpp +++ b/src/physics/moment.hpp @@ -3,7 +3,9 @@ #include "base.hpp" -class Moment { +CP_NAMESPACE_BEGIN + +class CP_API Moment { public: public: @@ -24,4 +26,6 @@ class Moment { } }; +CP_NAMESPACE_END + #endif diff --git a/src/physics/physicshelper.hpp b/src/physics/physicshelper.hpp index 309890b7e..832230f10 100644 --- a/src/physics/physicshelper.hpp +++ b/src/physics/physicshelper.hpp @@ -1,6 +1,20 @@ #ifndef EE_PHYSICS_HELPER #define EE_PHYSICS_HELPER +CP_NAMESPACE_BEGIN + +const cpFloat cpPI = 3.141592654; +const cpFloat cpPId180 = cpPI / 180; +const cpFloat cpd180PI = 180 / cpPI; + +inline static cpFloat cpRadians( const cpFloat& Ang ) { + return Ang * cpPId180; +} + +inline static cpFloat cpDegrees( const cpFloat& Radians ) { + return Radians * cpd180PI; +} + #ifdef USE_EE_VECTOR typedef Vector2 cVect; @@ -59,6 +73,8 @@ typedef cpBB cBB; #endif +#ifdef PHYSICS_RENDERER_ENABLED + static const GLfloat pillVAR[] = { 0.0000f, 1.0000f, 1.0f, 0.2588f, 0.9659f, 1.0f, @@ -155,3 +171,7 @@ static const GLfloat springVAR[] = { static const int springVAR_count = sizeof(springVAR)/sizeof(GLfloat)/2; #endif + +CP_NAMESPACE_END + +#endif diff --git a/src/physics/settings.hpp b/src/physics/settings.hpp new file mode 100644 index 000000000..254462e74 --- /dev/null +++ b/src/physics/settings.hpp @@ -0,0 +1,31 @@ +#ifndef EE_PHYSICS_SETTINGS_HPP +#define EE_PHYSICS_SETTINGS_HPP + +//! Comment this if you don't want to use all the rendering stuff from EE. Disabling this will disable any kind of rendering, and the only dependencies with EE will be the templates. +#define PHYSICS_RENDERER_ENABLED + +//! Safe delete a pointer, check if not null, delete it, and set the variable to NULL. ( Must be like this: cpSAFE_DELETE( ptr ) ) +#define cpSAFE_DELETE eeSAFE_DELETE + +//! new Allocator used by the wrapper, by default use the EE allocator. ( Must be like this: cpNew( classType, constructor ) ) +#define cpNew eeNew + +//! Dynamic Library Export/Import symbols +#define CP_API EE_API + +//! Define this to use the template vector from EE +#define USE_EE_VECTOR + +//! Define this to use the templace aabb from EE +#define USE_EE_AABB + +//! Define this if you want to invert the BB Y Axis ( by default BB.Top is the bigger y-axis instead of BB.Bottom ) +#define BB_INVERT_Y_AXIS + +//! Namespace name begin +#define CP_NAMESPACE_BEGIN namespace EE { namespace Physics { + +//! Namespace name end +#define CP_NAMESPACE_END }} + +#endif diff --git a/src/test/ee.cpp b/src/test/ee.cpp index edae8c11c..6fe154cd6 100644 --- a/src/test/ee.cpp +++ b/src/test/ee.cpp @@ -149,10 +149,12 @@ class cEETest : private cThread { Int32 NH; Uint8 Screen; - SceneCb Scenes[4]; + SceneCb Scenes[6]; void Screen1(); void Screen2(); void Screen3(); + void Screen4(); + void Screen5(); cZip PAK; cZip PakTest; @@ -185,7 +187,6 @@ class cEETest : private cThread { eeInt mHeight; std::wstring mBuda; - cTextCache mBudaTC; bool mTextureLoaded; cResourceLoader mResLoad; @@ -208,14 +209,16 @@ class cEETest : private cThread { cSprite mBlindy; cSprite * mBlindyPtr; - cFrameBuffer * mFB; + cFrameBuffer * mFBO; cVertexBuffer * mVBO; void ItemClick( const cUIEvent * Event ); void MainClick( const cUIEvent * Event ); void QuitClick( const cUIEvent * Event ); + void CloseClick( const cUIEvent * Event ); void ButtonClick( const cUIEvent * Event ); void OnValueChange( const cUIEvent * Event ); + void CreateDecoratedWindow(); void CreateAquaTextureAtlas(); cUIControlAnim * C; @@ -225,6 +228,7 @@ class cEETest : private cThread { cUIProgressBar * mProgressBar; cUIListBox * mListBox; cUIPopUpMenu * Menu; + cUIWindow * mWindow; cTextCache mEEText; cTextCache mFBOText; @@ -342,6 +346,8 @@ void cEETest::Init() { Scenes[1] = cb::Make0( this, &cEETest::Screen1 ); Scenes[2] = cb::Make0( this, &cEETest::Screen2 ); Scenes[3] = cb::Make0( this, &cEETest::Screen3 ); + Scenes[4] = cb::Make0( this, &cEETest::Screen4 ); + Scenes[5] = cb::Make0( this, &cEETest::Screen5 ); InBuf.Start(); InBuf.SupportNewLine( true ); @@ -376,10 +382,10 @@ void cEETest::Init() { Batch.AllocVertexs( 1024 ); Batch.SetPreBlendFunc( ALPHA_BLENDONE ); - mFB = cFrameBuffer::CreateNew( 256, 256, false ); + mFBO = cFrameBuffer::CreateNew( 256, 256, false ); - if ( NULL != mFB ) - mFB->ClearColor( eeColorAf( 0, 0, 0, 0.5f ) ); + if ( NULL != mFBO ) + mFBO->ClearColor( eeColorAf( 0, 0, 0, 0.5f ) ); eePolygon2f Poly = CreateRoundedPolygon( 0.f, 0.f, 256.f, 50.f ); @@ -434,9 +440,7 @@ void cEETest::OnFontLoaded( cResourceLoader * ObjLoaded ) { CreateUI(); cLog::instance()->Writef( "CreateUI time: %f", TE.ElapsedSinceStart() ); - TTFB->ShrinkText( mBuda, 400 ); - mBudaTC.Create( TTFB, mBuda, eeColorA(255,255,255,255) ); - mEEText.Create( TTFB, L"Entropia Engine++\nCTRL + 1 = Physics\nCTRL + 2 = Screen 2 - CTRL + 3 = Screen 3\nCTRL + 4 = Screen 4" ); + mEEText.Create( TTFB, L"Entropia Engine++\nCTRL + Number to change Demo Screen" ); mFBOText.Create( TTFB, L"This is a VBO\nInside of a FBO" ); mInfoText.Create( FF, L"", eeColorA(255,255,255,150) ); @@ -475,8 +479,6 @@ void cEETest::CreateUI() { Params.Border.Color( 0xFF979797 ); Params.Background.Colors( eeColorA( 0x66EDEDED ), eeColorA( 0xCCEDEDED ), eeColorA( 0xCCEDEDED ), eeColorA( 0x66EDEDED ) ); C = eeNew( cUITest, ( Params ) ); - C->Visible( true ); - C->Enabled( true ); C->Pos( 320, 240 ); C->DragEnable( true ); @@ -689,10 +691,12 @@ void cEETest::CreateUI() { Menu->Add( L"Show Screen 2" ); Menu->Add( L"Show Screen 3" ); Menu->Add( L"Show Screen 4" ); + Menu->Add( L"Show Screen 5" ); + Menu->Add( L"Show Screen 6" ); Menu->AddSeparator(); Menu->AddCheckBox( L"Show Window" ); + Menu->Add( L"Show Window 2" ); Menu->AddCheckBox( L"Multi Viewport" ); - reinterpret_cast ( Menu->GetItem( L"Show Window" ) )->Active( true ); cUIPopUpMenu * Menu3 = eeNew( cUIPopUpMenu, ( MenuParams ) ); Menu3->Add( L"Hello World 1" ); @@ -767,11 +771,21 @@ void cEETest::CreateUI() { mGenGrid->CollumnWidth( 0, 50 ); mGenGrid->CollumnWidth( 1, 24 ); mGenGrid->CollumnWidth( 2, 100 ); - +/* + //reinterpret_cast ( Menu->GetItem( L"Show Window" ) )->Active( true ); + C->Visible( true ); + C->Enabled( true ); C->StartScaleAnim( 0.f, 1.f, 500.f, SINEOUT ); C->StartAlphaAnim( 0.f, 255.f, 500.f ); C->StartRotation( 0, 360, 500.f, SINEOUT ); +*/ + C->Scale( 0 ); + CreateDecoratedWindow(); + //mWindow->Show(); +} + +void cEETest::CreateDecoratedWindow() { cUIWindow::CreateParams WinParams; WinParams.Flags = UI_HALIGN_CENTER; WinParams.WinFlags |= cUIWindow::UI_WIN_MAXIMIZE_BUTTON; @@ -782,10 +796,15 @@ void cEETest::CreateUI() { WinParams.BaseAlpha = 240; //WinParams.BorderAutoSize = false; //WinParams.BorderSize = eeSize( 8, 8 ); - cUIWindow * mWindow = eeNew( cUIWindow, ( WinParams ) ); + + mWindow = eeNew( cUIWindow, ( WinParams ) ); + mWindow->AddEventListener( cUIEvent::EventOnWindowCloseClick, cb::Make1( this, &cEETest::CloseClick ) ); mWindow->Title( L"Test Window" ); mWindow->ToBack(); - mWindow->Show(); +} + +void cEETest::CloseClick( const cUIEvent * Event ) { + mWindow = NULL; } void cEETest::ItemClick( const cUIEvent * Event ) { @@ -802,9 +821,16 @@ void cEETest::ItemClick( const cUIEvent * Event ) { SetScreen( 2 ); } else if ( L"Show Screen 4" == txt ) { SetScreen( 3 ); + } else if ( L"Show Screen 5" == txt ) { + SetScreen( 4 ); + } else if ( L"Show Screen 6" == txt ) { + SetScreen( 5 ); } else if ( L"Show Window" == txt ) { cUIMenuCheckBox * Chk = reinterpret_cast ( Event->Ctrl() ); + C->Visible( true ); + C->Enabled( true ); + if ( Chk->Active() ) { C->StartScaleAnim( C->Scale(), 1.f, 500.f, SINEOUT ); C->StartAlphaAnim( C->Alpha(), 255.f, 500.f ); @@ -814,6 +840,12 @@ void cEETest::ItemClick( const cUIEvent * Event ) { C->StartAlphaAnim( C->Alpha(), 0.f, 500.f ); C->StartRotation( 0, 360, 500.f, SINEIN ); } + } else if ( L"Show Window 2" == txt ) { + if ( NULL == mWindow ) { + CreateDecoratedWindow(); + } + + mWindow->Show(); } else if ( L"Multi Viewport" == txt ) { MultiViewportMode = !MultiViewportMode; } @@ -870,7 +902,7 @@ void cEETest::SetScreen( Uint32 num ) { else EE->SetBackColor( eeColor( 0, 0, 0 ) ); - if ( num < 4 ) + if ( num < 6 ) Screen = num; } @@ -1241,6 +1273,33 @@ void cEETest::Screen3() { Batch.Draw(); } +void cEETest::Screen4() { + if ( NULL != mFBO ) { + mFBO->Bind(); + mFBO->Clear(); + + mBlindy.Position( 128-16, 128-16 ); + mBlindy.Draw(); + + mVBO->Bind(); + mVBO->Draw(); + mVBO->Unbind(); + + mFBOText.Draw( 128.f - (eeFloat)(Int32)( mFBOText.GetTextWidth() * 0.5f ), 25.f - (eeFloat)(Int32)( mFBOText.GetTextHeight() * 0.5f ), FONT_DRAW_CENTER ); + + mFBO->Unbind(); + + if ( NULL != mFBO->GetTexture() ) { + mFBO->GetTexture()->Draw( (eeFloat)EE->GetWidth() * 0.5f - (eeFloat)mFBO->GetWidth() * 0.5f, (eeFloat)EE->GetHeight() * 0.5f - (eeFloat)mFBO->GetHeight() * 0.5f, Ang ); + cGlobalBatchRenderer::instance()->Draw(); + } + } +} + +void cEETest::Screen5() { + +} + void cEETest::Render() { if ( !mTextureLoaded ) mResLoad.Update(); @@ -1310,12 +1369,10 @@ void cEETest::Render() { ColRR1, ColRR2, ColRR3, ColRR4 ); - mEEText.Draw( 0.f, (eeFloat)EE->GetHeight() - mEEText.GetTextHeight(), FONT_DRAW_CENTER, 1.f, Ang ); + mEEText.Draw( 0.f, (eeFloat)EE->GetHeight() - mEEText.GetTextHeight(), FONT_DRAW_CENTER ); mInfoText.Draw( 6.f, 6.f ); - mBudaTC.Draw( 5.f, 60.f ); - Uint32 NLPos = 0; Uint32 LineNum = InBuf.GetCurPosLinePos( NLPos ); if ( InBuf.CurPos() == (eeInt)InBuf.Buffer().size() && !LineNum ) { @@ -1331,27 +1388,6 @@ void cEETest::Render() { FF2->SetText( InBuf.Buffer() ); FF2->Draw( 6, 180, FONT_DRAW_SHADOW ); - if ( NULL != mFB ) { - mFB->Bind(); - mFB->Clear(); - - mBlindy.Position( 128-16, 128-16 ); - mBlindy.Draw(); - - mVBO->Bind(); - mVBO->Draw(); - mVBO->Unbind(); - - mFBOText.Draw( 128.f - (eeFloat)(Int32)( mFBOText.GetTextWidth() * 0.5f ), 25.f - (eeFloat)(Int32)( mFBOText.GetTextHeight() * 0.5f ), FONT_DRAW_CENTER ); - - mFB->Unbind(); - - if ( NULL != mFB->GetTexture() ) { - mFB->GetTexture()->Draw( (eeFloat)EE->GetWidth() - 256.f, 240.f, Ang ); - cGlobalBatchRenderer::instance()->Draw(); - } - } - cUIManager::instance()->Update(); cUIManager::instance()->Draw(); @@ -1449,6 +1485,12 @@ void cEETest::Input() { if ( KM->IsKeyUp(KEY_4) && KM->ControlPressed() ) SetScreen( 3 ); + if ( KM->IsKeyUp(KEY_5) && KM->ControlPressed() ) + SetScreen( 4 ); + + if ( KM->IsKeyUp(KEY_6) && KM->ControlPressed() ) + SetScreen( 5 ); + cJoystick * Joy = JM->GetJoystick(0); if ( NULL != Joy ) { @@ -1616,7 +1658,7 @@ void cEETest::End() { Mus->Stop(); eeSAFE_DELETE( Mus ); eeSAFE_DELETE( mTGL ); - eeSAFE_DELETE( mFB ); + eeSAFE_DELETE( mFBO ); eeSAFE_DELETE( mVBO ); eeSAFE_DELETE( mBlindyPtr ); @@ -1713,9 +1755,8 @@ void cEETest::Demo1Update() { } void cEETest::Demo1Destroy() { - eeSAFE_DELETE( mSpace ); - eeSAFE_DELETE( mMouseJoint ); eeSAFE_DELETE( mMouseBody ); + eeSAFE_DELETE( mSpace ); } cpBool cEETest::blockerBegin( cArbiter *arb, cSpace *space, void *unused ) { @@ -1823,9 +1864,8 @@ void cEETest::Demo2Update() { } void cEETest::Demo2Destroy() { - eeSAFE_DELETE( mSpace ); - eeSAFE_DELETE( mMouseJoint ); eeSAFE_DELETE( mMouseBody ); + eeSAFE_DELETE( mSpace ); } void cEETest::ChangeDemo( Uint32 num ) { diff --git a/src/ui/cuievent.hpp b/src/ui/cuievent.hpp index 3c9524fc8..2b29476d6 100644 --- a/src/ui/cuievent.hpp +++ b/src/ui/cuievent.hpp @@ -40,6 +40,9 @@ class EE_API cUIEvent { EventOnItemKeyUp, EventOnCursorPosChange, EventOnParentSizeChange, + EventOnWindowCloseClick, + EventOnWindowMaximizeClick, + EventOnWindowMinimizeClick, EventUser, EventForceDWord = 0xFFFFFFFF }; diff --git a/src/ui/cuiwindow.cpp b/src/ui/cuiwindow.cpp index 487067def..957bf018c 100644 --- a/src/ui/cuiwindow.cpp +++ b/src/ui/cuiwindow.cpp @@ -104,7 +104,12 @@ void cUIWindow::ContainerPosChange( const cUIEvent * Event ) { } void cUIWindow::ButtonCloseClick( const cUIEvent * Event ) { - CloseFadeOut( cUIThemeManager::instance()->ControlsFadeOutTime() ); + if ( 0 != cUIThemeManager::instance()->ControlsFadeOutTime() ) + CloseFadeOut( cUIThemeManager::instance()->ControlsFadeOutTime() ); + else + Close(); + + SendCommonEvent( cUIEvent::EventOnWindowCloseClick ); } void cUIWindow::ButtonMaximizeClick( const cUIEvent * Event ) { @@ -120,10 +125,14 @@ void cUIWindow::ButtonMaximizeClick( const cUIEvent * Event ) { Pos( 0, 0 ); InternalSize( cUIManager::instance()->MainControl()->Size() ); } + + SendCommonEvent( cUIEvent::EventOnWindowMaximizeClick ); } void cUIWindow::ButtonMinimizeClick( const cUIEvent * Event ) { Hide(); + + SendCommonEvent( cUIEvent::EventOnWindowMinimizeClick ); } void cUIWindow::SetTheme( cUITheme *Theme ) {