Skip to content

Commit

Permalink
game's main loop added, glut removed from vs sample project
Browse files Browse the repository at this point in the history
  • Loading branch information
soniccat committed Feb 7, 2010
1 parent d8a665c commit 49df4ca
Show file tree
Hide file tree
Showing 17 changed files with 23,106 additions and 22,143 deletions.
12 changes: 12 additions & 0 deletions src/Objects/SEPhysicObject.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,17 @@ SEPhysicObject::~SEPhysicObject(void)
//SEPhysicWorld::sharedInstance()->world()->removeRigidBody( mRigidBody.get() );
}

void SEPhysicObject::Init( btScalar mass, SEMeshPtr mesh, btMotionStatePtr motionState, btTriangleMeshPtr triangleMesh, btTriangleMeshShapePtr shape, const btVector3& localInertia )
{
mMesh = mesh;
mMotionState = motionState;
mCollisionShape = shape;
mMeshInterface = triangleMesh;

btRigidBody::btRigidBodyConstructionInfo rbInfo( mass, motionState.get(), shape.get(), localInertia );
mRigidBody = btRigidBodyPtr( SENewObject<btRigidBody>( rbInfo ) );
}

void SEPhysicObject::Init( btScalar mass, SEMeshPtr mesh, btMotionStatePtr motionState, btCollisionShapePtr shape, const btVector3& localInertia )
{
mMesh = mesh;
Expand All @@ -21,6 +32,7 @@ void SEPhysicObject::Init( btScalar mass, SEMeshPtr mesh, btMotionStatePtr motio
mRigidBody = btRigidBodyPtr( SENewObject<btRigidBody>( rbInfo ) );
}


void SEPhysicObject::Draw()
{
btTransform trans;
Expand Down
6 changes: 5 additions & 1 deletion src/Objects/SEPhysicObject.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ typedef shared_ptr<btCollisionShape> btCollisionShapePtr;
typedef shared_ptr<btBvhTriangleMeshShape> btBvhTriangleMeshShapePtr;
typedef shared_ptr<btCollisionShape> btCollisionShapePtr;

typedef shared_ptr<btStridingMeshInterface> btStridingMeshInterfacePtr;
typedef shared_ptr<btTriangleMeshShape> btTriangleMeshShapePtr;

class SEPhysicObject;
typedef shared_ptr<SEPhysicObject> SEPhysicObjectPtr;
typedef vector< SEPhysicObjectPtr > SEPhysicObjectArray;
Expand All @@ -27,7 +30,7 @@ class SEPhysicObject: public SEObjectInterface
btRigidBodyPtr mRigidBody;
btMotionStatePtr mMotionState;
btCollisionShapePtr mCollisionShape;

btStridingMeshInterfacePtr mMeshInterface;

SEMeshPtr mMesh;

Expand All @@ -36,6 +39,7 @@ class SEPhysicObject: public SEObjectInterface
virtual ~SEPhysicObject(void);

void Init( btScalar mass, SEMeshPtr mesh, btMotionStatePtr motionState, btCollisionShapePtr shape, const btVector3& localInertia );
void Init( btScalar mass, SEMeshPtr mesh, btMotionStatePtr motionState, btTriangleMeshPtr triangleMesh, btTriangleMeshShapePtr shape, const btVector3& localInertia );

virtual void Draw();
btRigidBodyPtr rigidBody();
Expand Down
12 changes: 12 additions & 0 deletions src/Objects/SEPhysicWorld.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,18 @@ btDynamicsWorldPtr SEPhysicWorld::world()
return mWorld;
}

void SEPhysicWorld::Draw()
{
SEPhysicObjectArray::iterator start = mPhysicObjectArray.begin();
SEPhysicObjectArray::iterator end = mPhysicObjectArray.end();

while(start != end)
{
(*start)->Draw();
++start;
}
}

void SEPhysicWorld::AddObject( SEPhysicObjectPtr object)
{
mPhysicObjectArray.push_back( object );
Expand Down
2 changes: 2 additions & 0 deletions src/Objects/SEPhysicWorld.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ class SEPhysicWorld

btDynamicsWorldPtr world();

void Draw();

void AddObject( SEPhysicObjectPtr object);
void RemoveObjects();
};
Expand Down
33 changes: 33 additions & 0 deletions src/Tools/SEGameLoop.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
#include "SEGameLoop.h"
#include "SEGameLoopEngineConstantGameSpeedMaximumFPS.h"


SEGameLoopPtr SEGameLoop::mInstance;

SEGameLoop::SEGameLoop(void)
{
}

SEGameLoop::~SEGameLoop(void)
{
}

SEGameLoopPtr SEGameLoop::sharedInstance()
{
if( mInstance.get() == 0 )
{
mInstance = SEGameLoopPtr( SENewObject<SEGameLoop>() );
}

return mInstance;
}

void SEGameLoop::Run()
{
if( mEngine.get() == NULL )
{
mEngine = SEGameLoopEngineInterfacePtr( SENewObject<SEGameLoopEngineConstantGameSpeedMaximumFPS>() );
}

mEngine->Run();
}
26 changes: 26 additions & 0 deletions src/Tools/SEGameLoop.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@

#ifndef SEGameLoop_H
#define SEGameLoop_H


#include "SEGameLoopEngineInterface.h"
#include "SEIncludeLibrary.h"

class SEGameLoop;

typedef shared_ptr<SEGameLoop> SEGameLoopPtr;

class SEGameLoop
{
static SEGameLoopPtr mInstance;
SEGameLoopEngineInterfacePtr mEngine;

public:
SEGameLoop(void);
~SEGameLoop(void);

static SEGameLoopPtr sharedInstance();
void Run();
};

#endif SEGameLoop_H
33 changes: 33 additions & 0 deletions src/Tools/SEGameLoopEngineConstantGameSpeedMaximumFPS.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
#include "SEGameLoopEngineConstantGameSpeedMaximumFPS.h"
#include "SEPhysicWorld.h"

SEGameLoopEngineConstantGameSpeedMaximumFPS::SEGameLoopEngineConstantGameSpeedMaximumFPS(void)
{
}

SEGameLoopEngineConstantGameSpeedMaximumFPS::~SEGameLoopEngineConstantGameSpeedMaximumFPS(void)
{
}

void SEGameLoopEngineConstantGameSpeedMaximumFPS::Run()
{
static const int TICKS_PER_SECOND = 50;
static const int SKIP_TICKS = 1000 / TICKS_PER_SECOND;
static const int MAX_FRAMESKIP = 10;

static DWORD next_game_tick = GetTickCount();
int loops;

{
loops = 0;
while( GetTickCount() > next_game_tick && loops < MAX_FRAMESKIP)
{
SEPhysicWorld::sharedInstance()->world()->stepSimulation(1.0/25.0,1);

next_game_tick += SKIP_TICKS;
loops++;
}

SEPhysicWorld::sharedInstance()->Draw();
}
}
21 changes: 21 additions & 0 deletions src/Tools/SEGameLoopEngineConstantGameSpeedMaximumFPS.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@

#ifndef SEGameLoopEngineConstantGameSpeedMaximumFPS_H
#define SEGameLoopEngineConstantGameSpeedMaximumFPS_H

#include "SEGameLoopEngineInterface.h"

//
//Realization of "Constant Game Speed with Maximum FPS"
//http://dewitters.koonsolo.com/gameloop.html
//
class SEGameLoopEngineConstantGameSpeedMaximumFPS: public SEGameLoopEngineInterface
{
public:
SEGameLoopEngineConstantGameSpeedMaximumFPS(void);
virtual ~SEGameLoopEngineConstantGameSpeedMaximumFPS(void);

virtual void Run();
};


#endif SEGameLoopEngineConstantGameSpeedMaximumFPS_H
9 changes: 9 additions & 0 deletions src/Tools/SEGameLoopEngineInterface.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#include "SEGameLoopEngineInterface.h"

SEGameLoopEngineInterface::SEGameLoopEngineInterface(void)
{
}

SEGameLoopEngineInterface::~SEGameLoopEngineInterface(void)
{
}
21 changes: 21 additions & 0 deletions src/Tools/SEGameLoopEngineInterface.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@

#ifndef SEGameLoopEngineInterface_H
#define SEGameLoopEngineInterface_H

#include "SEIncludeLibrary.h"

class SEGameLoopEngineInterface;

typedef shared_ptr<SEGameLoopEngineInterface> SEGameLoopEngineInterfacePtr;

class SEGameLoopEngineInterface
{
public:
SEGameLoopEngineInterface(void);
virtual ~SEGameLoopEngineInterface(void);

virtual void Run()=0;
};


#endif SEGameLoopEngineInterface_H
2 changes: 2 additions & 0 deletions src/Tools/SEMain.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,7 @@
#include "SEPhysicObject.h"

#include "SETouchController.h"
#include "SEGameLoop.h"
#include "SEGameLoopEngineConstantGameSpeedMaximumFPS.h"

#endif //SEMainDEF
Loading

0 comments on commit 49df4ca

Please sign in to comment.