Vigilante Game Framework
1.0.0.8
A 2D/3D C++ Game Framework using SFML.
|
A special VGroup that sets up a physics world and updates VPhysicsObjects. It doesn't handle rendering except for debugging, nor does it update the VObject. More...
#include <VPhysicsGroup.h>
Public Types | |
enum | VPhysicsCallbackType { BEGIN, PRESOLVE, POSTSOLVE, SEPARATE } |
The types of collision callback. More... | |
typedef VGroup | VSUPERCLASS |
Used to call parent class functions when they are overrided in class. | |
![]() | |
typedef VBase | VSUPERCLASS |
Used to call parent class functions when they are overrided in class. | |
Public Member Functions | |
VPhysicsGroup (unsigned int Amount=0) | |
VPhysicsObject * | AddObject (VObject *Object, VPhysicsObject::VObjectType BodyType, VPhysicsObject::VObjectShape Shape=VPhysicsObject::BOX, std::vector< sf::Vector2f > Verts={}) |
bool | RemoveObject (VObject *Object) |
VPhysicsJointBase * | AddJoint (VPhysicsJointBase *Joint) |
bool | RemoveJoint (VPhysicsJointBase *Joint) |
virtual void | Destroy () override |
Destroys all VPhysicsObjects, this has no effect on the VObject that's attached to them. | |
virtual void | Update (float dt) override |
int | GetIterations () |
void | SetIterations (int Iterations) |
sf::Vector2f | GetGravity () |
void | SetGravity (sf::Vector2f Gravity) |
float | GetDamping () |
void | SetDamping (float Damping) |
float | GetIdleSpeedThreshold () |
void | SetIdleSpeedThreshold (float IdleSpeedThreshold) |
float | GetSleepTimeThreshold () |
void | SetSleepTimeThreshold (float SleepTimeThreshold) |
float | GetCollisionSlop () |
void | SetCollisionSlop (float CollisionSlop) |
float | GetCollisionBias () |
void | SetCollisionBias (float CollisionBias) |
unsigned int | GetCollisionPersistence () |
void | SetCollisionPersistence (unsigned int CollisionPersistence) |
VPhysicsCPBody * | GetBody () |
void | SetCollisionCallback (VObject *a, VObject *b, const std::function< bool(VPhysicsObject *, VPhysicsObject *)> &callback, VPhysicsCallbackType type, bool persist=false) |
void | SetCollisionCallback (VPhysicsObject *a, VPhysicsObject *b, const std::function< bool(VPhysicsObject *, VPhysicsObject *)> &callback, VPhysicsCallbackType type, bool persist=false) |
void | SetConstraintCallback (VPhysicsJointBase *joint, const std::function< void(VPhysicsJointBase *, VPhysicsObject *, VPhysicsObject *)> &callback, VPhysicsCallbackType type, bool persist=false) |
virtual bool | ProcessCallback (VPhysicsCPArbiter *arb, VPhysicsCPSpace *space, VPhysicsCallbackType type) |
virtual void | ProcessCallback (VPhysicsCPConstraint *constraint, VPhysicsCPSpace *space, VPhysicsCallbackType type) |
![]() | |
VGroup (unsigned int maxSize=0) | |
int | Length () |
VBase * | Add (VBase *object) |
VBase * | Remove (VBase *object, bool splice=false) |
VBase * | FirstAvailable () |
int | FirstNULL () |
VBase * | FirstExisting () |
VBase * | FirstAlive () |
VBase * | FirstDead () |
int | CountAlive (bool Recursive=false) |
int | CountDead (bool Recursive=false) |
VBase * | GetRandom (int min=0, int max=0) |
void | ForEach (std::function< void(VBase *)> function, bool recursive=false) |
void | ForEachAlive (std::function< void(VBase *)> function, bool recursive=false) |
void | ForEachDead (std::function< void(VBase *)> function, bool recursive=false) |
void | ForEachExists (std::function< void(VBase *)> function, bool recursive=false) |
VBase * | GetGroupItem (int index) |
template<class T > | |
T * | GetGroupItemAsType (int index) |
int | GetIndexOfItem (VBase *object) |
void | OrganiseNULLS () |
Sort nullptr members to the bottom of the group. | |
void | Swap (int a, int b) |
void | Sort (std::function< bool(VBase *, VBase *)> func) |
void | Reverse () |
Reverse order of group. | |
void | Clear () |
Clears the whole group (does not destroy any of the members, that must be done using the Destroy method). | |
virtual void | Kill () override |
Kills all living objects before killing the group itself. | |
virtual void | Revive () override |
Revives all dead objects before reviving the group itself. | |
virtual void | Draw (sf::RenderTarget &RenderTarget) override |
Additional Inherited Members | |
![]() | |
static const wchar_t * | VString (const char *fmt,...) |
static void | VLog (const char *fmt,...) |
static void | VLogError (const char *fmt,...) |
static void | VClearLog () |
![]() | |
bool | active = true |
Base can be updated using Update if true. | |
bool | visible = true |
Base can be rendered using Draw if true. | |
bool | alive = true |
Helper member that is mainly used filter out behaviours to objects which aren't alive in the scene. | |
bool | exists = true |
Base can be updated and rendered if true, else it would no longer be treated as being part of the scene. | |
VType | type = NONE |
Base object type, typically set in the constructor of an inherited object to specify what type it is. | |
uint32_t | RefCount = 0 |
Counts the amount of times the object is referenced in groups, ensures an object is only destroyed when no longer part of a single group. | |
![]() | |
std::vector< VBase * > | members |
VBase List. | |
int | length = 0 |
Current amount of members in the list. | |
unsigned int | MaxSize = 0 |
Maximum Size of the list, used if VGroup is set to have a fixed size. | |
A special VGroup that sets up a physics world and updates VPhysicsObjects. It doesn't handle rendering except for debugging, nor does it update the VObject.
The types of collision callback.
VPhysicsGroup::VPhysicsGroup | ( | unsigned int | Amount = 0 | ) |
Amount | The fixed length of the group. If 0, then the VGroup has no limit in size. |
VPhysicsJointBase* VPhysicsGroup::AddJoint | ( | VPhysicsJointBase * | Joint | ) |
This functions adds a VPhysicsJointBase object to the physics world.
Joint | The Physics Joint to add into the scene, it must be already set up with both physics objects. |
VPhysicsObject* VPhysicsGroup::AddObject | ( | VObject * | Object, |
VPhysicsObject::VObjectType | BodyType, | ||
VPhysicsObject::VObjectShape | Shape = VPhysicsObject::BOX , |
||
std::vector< sf::Vector2f > | Verts = {} |
||
) |
This functions adds a VPhysicsObject to the group. This should be used instead of the Add function unless you want to set up a VPhysicsObject yourself.
Object | The game object you wish to apply physics to. |
BodyType | This sets what type of physics body the object should have, see VObjectType for which types. |
Shape | This sets what shape the collider should have. |
Verts | If Shape is set to either LINE or SHAPE, these set the points of the shape. These should be set relative to the top left of the shape. |
VPhysicsCPBody* VPhysicsGroup::GetBody | ( | ) |
float VPhysicsGroup::GetCollisionBias | ( | ) |
unsigned int VPhysicsGroup::GetCollisionPersistence | ( | ) |
float VPhysicsGroup::GetCollisionSlop | ( | ) |
float VPhysicsGroup::GetDamping | ( | ) |
sf::Vector2f VPhysicsGroup::GetGravity | ( | ) |
float VPhysicsGroup::GetIdleSpeedThreshold | ( | ) |
int VPhysicsGroup::GetIterations | ( | ) |
float VPhysicsGroup::GetSleepTimeThreshold | ( | ) |
|
virtual |
This function is called to process all the callbacks, this should only be overridden if you want to manipulate the collision response directly.
arb | The collision arbiter, which essentially holds all the collision response infomation between two shapes. |
space | The Physics world the collision took place in (always the one created in VPhysicsGroup). |
type | The type of callback to process. |
|
virtual |
This function is called to process all the callbacks, this should only be overridden if you want to manipulate the collision response directly.
constraint | The collision arbiter, which essentially holds all the collision response infomation between two shapes. |
space | The Physics world the collision took place in (always the one created in VPhysicsGroup). |
type | The type of callback to process. |
bool VPhysicsGroup::RemoveJoint | ( | VPhysicsJointBase * | Joint | ) |
Removes the VPhysicsJointBase from the group and destroys it.
Joint | The physics joint you wish to be removed. |
bool VPhysicsGroup::RemoveObject | ( | VObject * | Object | ) |
Removes the VPhysicsObject from the group based on it's attached VObject and destroys it, useful if you no longer have the VPhysicsObject at hand.
Object | The game object that you wish to remove the physics from. |
void VPhysicsGroup::SetCollisionBias | ( | float | CollisionBias | ) |
CollisionBias | The bias percentage of overlap remaining unfixed after a second. |
void VPhysicsGroup::SetCollisionCallback | ( | VObject * | a, |
VObject * | b, | ||
const std::function< bool(VPhysicsObject *, VPhysicsObject *)> & | callback, | ||
VPhysicsCallbackType | type, | ||
bool | persist = false |
||
) |
Collision callbacks act slightly differently from VCollision. Here you can set the collision between specific objects, their callback, when the callback should be applied and whether you want the collision to be active forever or deactivated after being called once.
a | The first object to test collisions with for the callback. |
b | The second object to test collisions with for the callback. Setting this to nullptr will apply the callback between object a and anything else. |
callback | The function to call if the collision takes place, the two parameters are VPhysicsObject so you can adjust the collision properties and access the VObject at the same time. |
type | The type of collision callback to set (see VPhysicsCallbackType). |
persist | If true, this callback will remain active for the duration of the space, otherwise this callback will be removed after one call. This way you aren't required to call it on each update. |
void VPhysicsGroup::SetCollisionCallback | ( | VPhysicsObject * | a, |
VPhysicsObject * | b, | ||
const std::function< bool(VPhysicsObject *, VPhysicsObject *)> & | callback, | ||
VPhysicsCallbackType | type, | ||
bool | persist = false |
||
) |
Collision callbacks act slightly differently from VCollision. Here you can set the collision between specific objects, their callback, when the callback should be applied and whether you want the collision to be active forever or deactivated after being called once.
a | The first object to test collisions with for the callback. |
b | The second object to test collisions with for the callback. Setting this to nullptr will apply the callback between object a and anything else. |
callback | The function to call if the collision takes place, the two parameters are VPhysicsObject so you can adjust the collision properties and access the VObject at the same time. |
type | The type of collision callback to set (see VPhysicsCallbackType). |
persist | If true, this callback will remain active for the duration of the space, otherwise this callback will be removed after one call. This way you aren't required to call it on each update. |
void VPhysicsGroup::SetCollisionPersistence | ( | unsigned int | CollisionPersistence | ) |
CollisionPersistence | The number of frames/steps to keep collision solutions. |
void VPhysicsGroup::SetCollisionSlop | ( | float | CollisionSlop | ) |
CollisionSlop | The amount of overlap between shapes that is allowed. |
void VPhysicsGroup::SetConstraintCallback | ( | VPhysicsJointBase * | joint, |
const std::function< void(VPhysicsJointBase *, VPhysicsObject *, VPhysicsObject *)> & | callback, | ||
VPhysicsCallbackType | type, | ||
bool | persist = false |
||
) |
Here you can set callbacks for the pre and post solve conditions of a joint.
joint | The joint to test the callback with. |
callback | The function to call if the joint is applied, the parameters are the VPhysicsJointBase and two VPhysicsObject so you can modify the joints or the objects. |
type | The type of callback to set (see VPhysicsCallbackType). BEGIN and SEPARATE are ignored. |
persist | If true, this callback will remain active for the duration of the space, otherwise this callback will be removed after one call. This way you aren't required to call it on each update. |
void VPhysicsGroup::SetDamping | ( | float | Damping | ) |
Damping | The general damping applied when objects collide |
void VPhysicsGroup::SetGravity | ( | sf::Vector2f | Gravity | ) |
Gravity | The gravity set for both axis in pixels per second (e.g. sf::Vector(0.0f, 910.0f is down). |
void VPhysicsGroup::SetIdleSpeedThreshold | ( | float | IdleSpeedThreshold | ) |
IdleSpeedThreshold | The speed threshold to determine when a physics object should be idle. |
void VPhysicsGroup::SetIterations | ( | int | Iterations | ) |
Iterations | The accuracy of the collision iterative solver in number of iterations. |
void VPhysicsGroup::SetSleepTimeThreshold | ( | float | SleepTimeThreshold | ) |
SleepTimeThreshold | The time threshold to determine when a physics object should sleep. |
|
overridevirtual |