[DEV] start to have a generic game engine
This commit is contained in:
parent
926bbe6b3d
commit
eefbe48546
@ -43,7 +43,8 @@ ege::ElementGame::ElementGame(ege::Environement& _env) :
|
|||||||
m_group(0),
|
m_group(0),
|
||||||
m_fixe(true),
|
m_fixe(true),
|
||||||
m_radius(0),
|
m_radius(0),
|
||||||
m_elementInPhysicsSystem(false)
|
m_elementInPhysicsSystem(false),
|
||||||
|
m_IA(NULL)
|
||||||
{
|
{
|
||||||
static uint32_t unique=0;
|
static uint32_t unique=0;
|
||||||
m_uID = unique;
|
m_uID = unique;
|
||||||
@ -53,6 +54,10 @@ ege::ElementGame::ElementGame(ege::Environement& _env) :
|
|||||||
|
|
||||||
ege::ElementGame::~ElementGame(void)
|
ege::ElementGame::~ElementGame(void)
|
||||||
{
|
{
|
||||||
|
// in every case remove IA
|
||||||
|
IADisable();
|
||||||
|
// same ...
|
||||||
|
DynamicDisable();
|
||||||
EGE_DEBUG("Destroy element : uId=" << m_uID);
|
EGE_DEBUG("Destroy element : uId=" << m_uID);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -71,6 +76,9 @@ void ege::ElementGame::SetFireOn(int32_t groupIdSource, int32_t type, float powe
|
|||||||
float previousLife = m_life;
|
float previousLife = m_life;
|
||||||
m_life += power;
|
m_life += power;
|
||||||
m_life = etk_avg(0, m_life, m_lifeMax);
|
m_life = etk_avg(0, m_life, m_lifeMax);
|
||||||
|
if (m_life<=0) {
|
||||||
|
EGE_DEBUG("[" << GetUID() << "] element is killed ..." << GetType());
|
||||||
|
}
|
||||||
if (m_life!=previousLife) {
|
if (m_life!=previousLife) {
|
||||||
OnLifeChange();
|
OnLifeChange();
|
||||||
}
|
}
|
||||||
@ -351,4 +359,33 @@ void ege::ElementGame::DynamicDisable(void)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void ege::ElementGame::IAEnable(void)
|
||||||
|
{
|
||||||
|
if (NULL != m_IA) {
|
||||||
|
// IA already started ...
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
DynamicEnable();
|
||||||
|
m_IA = new localIA(*this);
|
||||||
|
if (NULL == m_IA) {
|
||||||
|
EGE_ERROR("Can not start the IA ==> allocation error");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
m_env.GetDynamicWorld()->addAction(m_IA);
|
||||||
|
}
|
||||||
|
|
||||||
|
void ege::ElementGame::IADisable(void)
|
||||||
|
{
|
||||||
|
if (NULL == m_IA) {
|
||||||
|
// IA already stopped ...
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
m_env.GetDynamicWorld()->removeAction(m_IA);
|
||||||
|
// Remove IA :
|
||||||
|
delete(m_IA);
|
||||||
|
m_IA = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -45,6 +45,19 @@ namespace ege
|
|||||||
* @brief Destructor
|
* @brief Destructor
|
||||||
*/
|
*/
|
||||||
virtual ~ElementGame(void);
|
virtual ~ElementGame(void);
|
||||||
|
/**
|
||||||
|
* @brief Get the element Type description string
|
||||||
|
* @return A pointer on the descriptive string (Do not free it ==> it might be a const)
|
||||||
|
*/
|
||||||
|
virtual const etk::UString& GetType(void) const;
|
||||||
|
private:
|
||||||
|
uint32_t m_uID; //!< This is a reference on a basic element ID
|
||||||
|
public:
|
||||||
|
/**
|
||||||
|
* @brief Get the curent Element Unique ID in the all Game.
|
||||||
|
* @return The requested Unique ID.
|
||||||
|
*/
|
||||||
|
inline uint32_t GetUID(void) const { return m_uID; };
|
||||||
protected:
|
protected:
|
||||||
ewol::Mesh* m_mesh; //!< Mesh of the Element (can be NULL)
|
ewol::Mesh* m_mesh; //!< Mesh of the Element (can be NULL)
|
||||||
btCollisionShape* m_shape; //!< shape of the element (set a copy here to have the debug display of it)
|
btCollisionShape* m_shape; //!< shape of the element (set a copy here to have the debug display of it)
|
||||||
@ -88,22 +101,6 @@ namespace ege
|
|||||||
* @brief Call chan the element life change
|
* @brief Call chan the element life change
|
||||||
*/
|
*/
|
||||||
virtual void OnLifeChange(void) {}
|
virtual void OnLifeChange(void) {}
|
||||||
private:
|
|
||||||
uint32_t m_uID; //!< This is a reference on a basic element ID
|
|
||||||
public:
|
|
||||||
/**
|
|
||||||
* @brief Get the curent Element Unique ID in the all Game.
|
|
||||||
* @return The requested Unique ID.
|
|
||||||
*/
|
|
||||||
inline uint32_t GetUID(void) const
|
|
||||||
{
|
|
||||||
return m_uID;
|
|
||||||
}
|
|
||||||
/**
|
|
||||||
* @brief Get the element Type description string
|
|
||||||
* @return A pointer on the descriptive string (Do not free it ==> it might be a const)
|
|
||||||
*/
|
|
||||||
virtual const etk::UString& GetType(void) const;
|
|
||||||
protected:
|
protected:
|
||||||
int32_t m_group; //!< Every element has a generic group
|
int32_t m_group; //!< Every element has a generic group
|
||||||
public:
|
public:
|
||||||
@ -203,10 +200,51 @@ namespace ege
|
|||||||
bool m_elementInPhysicsSystem;
|
bool m_elementInPhysicsSystem;
|
||||||
public:
|
public:
|
||||||
/**
|
/**
|
||||||
* @brief For intelligent system : this activate the Dynamic object
|
* @brief Set the elment in the physique engine
|
||||||
*/
|
*/
|
||||||
virtual void DynamicEnable(void);
|
void DynamicEnable(void);
|
||||||
virtual void DynamicDisable(void);
|
/**
|
||||||
|
* @brief Remove this element from the physique engine
|
||||||
|
*/
|
||||||
|
void DynamicDisable(void);
|
||||||
|
private:
|
||||||
|
class localIA : public btActionInterface
|
||||||
|
{
|
||||||
|
private:
|
||||||
|
ege::ElementGame& m_element;
|
||||||
|
public:
|
||||||
|
/**
|
||||||
|
* @brief Constructor
|
||||||
|
*/
|
||||||
|
localIA(ElementGame& element) : m_element(element) { };
|
||||||
|
/**
|
||||||
|
* @brief Destructor
|
||||||
|
*/
|
||||||
|
virtual ~localIA(void) { };
|
||||||
|
|
||||||
|
// herited function
|
||||||
|
void debugDraw(btIDebugDraw* debugDrawer) { };
|
||||||
|
// herited function
|
||||||
|
void updateAction(btCollisionWorld* collisionWorld, btScalar step)
|
||||||
|
{
|
||||||
|
m_element.IAAction(step);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
localIA* m_IA;
|
||||||
|
public:
|
||||||
|
/**
|
||||||
|
* @brief Enable periodic call Of this object for processing Artificial Intelligence
|
||||||
|
*/
|
||||||
|
void IAEnable(void);
|
||||||
|
/**
|
||||||
|
* @brief Disable periodic call Of this object for processing Artificial Intelligence
|
||||||
|
*/
|
||||||
|
void IADisable(void);
|
||||||
|
/**
|
||||||
|
* @brief Periodic call for intelligence artificial.
|
||||||
|
* @param[in] step : step of time in s
|
||||||
|
*/
|
||||||
|
virtual void IAAction(float _step) { };
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -1,63 +0,0 @@
|
|||||||
/**
|
|
||||||
* @author Edouard DUPIN
|
|
||||||
*
|
|
||||||
* @copyright 2011, Edouard DUPIN, all right reserved
|
|
||||||
*
|
|
||||||
* @license BSD v3 (see license file)
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include <ege/debug.h>
|
|
||||||
#include <ege/ElementGameIA.h>
|
|
||||||
|
|
||||||
#include <ewol/renderer/ResourceManager.h>
|
|
||||||
#include <BulletDynamics/Dynamics/btRigidBody.h>
|
|
||||||
#include <LinearMath/btDefaultMotionState.h>
|
|
||||||
#include <BulletDynamics/Dynamics/btDynamicsWorld.h>
|
|
||||||
#include <BulletCollision/CollisionShapes/btCollisionShape.h>
|
|
||||||
#include <LinearMath/btIDebugDraw.h>
|
|
||||||
#include <btBulletCollisionCommon.h>
|
|
||||||
#include <BulletCollision/CollisionShapes/btConvexPolyhedron.h>
|
|
||||||
#include <BulletCollision/CollisionShapes/btShapeHull.h>
|
|
||||||
#include <LinearMath/btTransformUtil.h>
|
|
||||||
#include <LinearMath/btIDebugDraw.h>
|
|
||||||
#include <btBulletDynamicsCommon.h>
|
|
||||||
#include <BulletCollision/CollisionDispatch/btCollisionObject.h>
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
ege::ElementGameIA::ElementGameIA(ege::Environement& _env) :
|
|
||||||
ElementGame(_env),
|
|
||||||
m_IA(*this),
|
|
||||||
m_isDynamicStarted(false)
|
|
||||||
{
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
ege::ElementGameIA::~ElementGameIA(void)
|
|
||||||
{
|
|
||||||
DynamicDisable();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void ege::ElementGameIA::DynamicEnable(void)
|
|
||||||
{
|
|
||||||
ege::ElementGame::DynamicEnable();
|
|
||||||
if (false == m_isDynamicStarted) {
|
|
||||||
m_env.GetDynamicWorld()->addAction(&m_IA);
|
|
||||||
m_isDynamicStarted = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void ege::ElementGameIA::DynamicDisable(void)
|
|
||||||
{
|
|
||||||
ege::ElementGame::DynamicDisable();
|
|
||||||
if (true == m_isDynamicStarted) {
|
|
||||||
m_env.GetDynamicWorld()->removeAction(&m_IA);
|
|
||||||
m_isDynamicStarted = false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -1,67 +0,0 @@
|
|||||||
/**
|
|
||||||
* @author Edouard DUPIN
|
|
||||||
*
|
|
||||||
* @copyright 2011, Edouard DUPIN, all right reserved
|
|
||||||
*
|
|
||||||
* @license BSD v3 (see license file)
|
|
||||||
*/
|
|
||||||
|
|
||||||
#ifndef __EGE_ELEMENT_GAME_IA_H__
|
|
||||||
#define __EGE_ELEMENT_GAME_IA_H__
|
|
||||||
|
|
||||||
#include <ege/ElementGame.h>
|
|
||||||
|
|
||||||
namespace ege
|
|
||||||
{
|
|
||||||
class ElementGameIA : public ege::ElementGame
|
|
||||||
{
|
|
||||||
private:
|
|
||||||
class localIA : public btActionInterface
|
|
||||||
{
|
|
||||||
private:
|
|
||||||
ElementGameIA& m_element;
|
|
||||||
public:
|
|
||||||
/**
|
|
||||||
* @brief Constructor
|
|
||||||
*/
|
|
||||||
localIA(ElementGameIA& element) : m_element(element) { };
|
|
||||||
/**
|
|
||||||
* @brief Destructor
|
|
||||||
*/
|
|
||||||
virtual ~localIA(void) { };
|
|
||||||
|
|
||||||
// herited function
|
|
||||||
void debugDraw(btIDebugDraw* debugDrawer) { };
|
|
||||||
// herited function
|
|
||||||
void updateAction(btCollisionWorld* collisionWorld, btScalar step)
|
|
||||||
{
|
|
||||||
m_element.IAAction(step);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
localIA m_IA;
|
|
||||||
public:
|
|
||||||
/**
|
|
||||||
* @brief Constructor
|
|
||||||
*/
|
|
||||||
ElementGameIA(ege::Environement& _env);
|
|
||||||
/**
|
|
||||||
* @brief Destructor
|
|
||||||
*/
|
|
||||||
virtual ~ElementGameIA(void);
|
|
||||||
/**
|
|
||||||
* @brief Periodic call for intelligence artificial.
|
|
||||||
* @param[in] step : step of time in s
|
|
||||||
*/
|
|
||||||
virtual void IAAction(float _step)=0;
|
|
||||||
|
|
||||||
private:
|
|
||||||
bool m_isDynamicStarted;
|
|
||||||
public:
|
|
||||||
virtual void DynamicEnable(void);
|
|
||||||
virtual void DynamicDisable(void);
|
|
||||||
};
|
|
||||||
};
|
|
||||||
|
|
||||||
#endif
|
|
||||||
|
|
||||||
|
|
@ -111,6 +111,46 @@ void ege::Environement::GetElementNearestFixed(const vec3& _sourcePosition,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static etk::Hash<ege::createElement_tf>& GetHachTableCreating(void)
|
||||||
|
{
|
||||||
|
static etk::Hash<ege::createElement_tf> s_table;
|
||||||
|
return s_table;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void ege::Environement::AddCreator(const etk::UString& _type, ege::createElement_tf _creator)
|
||||||
|
{
|
||||||
|
if (NULL == _creator) {
|
||||||
|
EGE_ERROR("Try to add an empty CREATOR ...");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
GetHachTableCreating().Add(_type, _creator);
|
||||||
|
}
|
||||||
|
|
||||||
|
ege::ElementGame* ege::Environement::CreateElement(const etk::UString& _type, const etk::UString& _description, bool _autoAddElement)
|
||||||
|
{
|
||||||
|
if (false==GetHachTableCreating().Exist(_type)) {
|
||||||
|
EGE_ERROR("Request creating of an type that is not known '" << _type << "'");
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
ege::createElement_tf pointerFunction = GetHachTableCreating()[_type];
|
||||||
|
if (NULL == pointerFunction) {
|
||||||
|
EGE_ERROR("NULL pointer ==> internal error... '" << _type << "'");
|
||||||
|
// internal error
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
ege::ElementGame* tmpElement = pointerFunction(*this, _description);
|
||||||
|
if (NULL == tmpElement) {
|
||||||
|
EGE_ERROR("Sub creator han an error when creating element : '" << _type << "'");
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
if (_autoAddElement==true) {
|
||||||
|
AddElementGame(tmpElement);
|
||||||
|
}
|
||||||
|
return tmpElement;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void ege::Environement::AddElementGame(ege::ElementGame* _newElement)
|
void ege::Environement::AddElementGame(ege::ElementGame* _newElement)
|
||||||
{
|
{
|
||||||
// prevent memory allocation and un allocation ...
|
// prevent memory allocation and un allocation ...
|
||||||
|
@ -9,6 +9,7 @@
|
|||||||
#ifndef __EGE_ENVIRONEMENT_H__
|
#ifndef __EGE_ENVIRONEMENT_H__
|
||||||
#define __EGE_ENVIRONEMENT_H__
|
#define __EGE_ENVIRONEMENT_H__
|
||||||
|
|
||||||
|
#include <etk/UString.h>
|
||||||
#include <BulletDynamics/Dynamics/btActionInterface.h>
|
#include <BulletDynamics/Dynamics/btActionInterface.h>
|
||||||
class btDynamicsWorld;
|
class btDynamicsWorld;
|
||||||
|
|
||||||
@ -17,6 +18,9 @@ class btDynamicsWorld;
|
|||||||
|
|
||||||
namespace ege {
|
namespace ege {
|
||||||
class ElementGame;
|
class ElementGame;
|
||||||
|
class Environement;
|
||||||
|
typedef ege::ElementGame* (*createElement_tf)(ege::Environement& _env, const etk::UString& _description);
|
||||||
|
|
||||||
class Environement
|
class Environement
|
||||||
{
|
{
|
||||||
private:
|
private:
|
||||||
@ -25,7 +29,22 @@ namespace ege {
|
|||||||
public:
|
public:
|
||||||
Environement(void) : m_dynamicsWorld(NULL) { };
|
Environement(void) : m_dynamicsWorld(NULL) { };
|
||||||
virtual ~Environement(void) { };
|
virtual ~Environement(void) { };
|
||||||
|
public:
|
||||||
|
/**
|
||||||
|
* @brief Add a creator element system
|
||||||
|
* @param[in] _type Type of the element.
|
||||||
|
* @param[in] _creator Function pointer that reference the element creating.
|
||||||
|
*/
|
||||||
|
static void AddCreator(const etk::UString& _type, ege::createElement_tf _creator);
|
||||||
|
/**
|
||||||
|
* @brief Create an element on the curent scene.
|
||||||
|
* @param[in] _type Type of the element that might be created.
|
||||||
|
* @param[in] _description String that describe the content of the element properties.
|
||||||
|
* @param[in] _autoAddElement this permit to add the element if it is created ==> no more action ...
|
||||||
|
* @return NULL if an error occured OR the pointer on the element and it is already added on the system.
|
||||||
|
* @note Pointer is return in case of setting properties on it...
|
||||||
|
*/
|
||||||
|
ege::ElementGame* CreateElement(const etk::UString& _type, const etk::UString& _description, bool _autoAddElement=true);
|
||||||
public:
|
public:
|
||||||
class ResultNearestElement
|
class ResultNearestElement
|
||||||
{
|
{
|
||||||
|
112
ege/Scene.cpp
112
ege/Scene.cpp
@ -41,12 +41,17 @@ const char * const ege::Scene::eventKillEnemy = "event-scene-kill-ennemy";
|
|||||||
#define WALK_FLAG_RIGHT (1<<3)
|
#define WALK_FLAG_RIGHT (1<<3)
|
||||||
#define WALK_FLAG_CAUTION (1<<4)
|
#define WALK_FLAG_CAUTION (1<<4)
|
||||||
|
|
||||||
ege::Scene::Scene(void) :
|
ege::Scene::Scene(btDefaultCollisionConfiguration* _collisionConfiguration,
|
||||||
|
btCollisionDispatcher* _dispatcher,
|
||||||
|
btBroadphaseInterface* _broadphase,
|
||||||
|
btConstraintSolver* _solver,
|
||||||
|
btDynamicsWorld* _dynamicsWorld,
|
||||||
|
ege::Camera* _camera) :
|
||||||
m_gameTime(0),
|
m_gameTime(0),
|
||||||
m_angleView(M_PI/3.0),
|
m_angleView(M_PI/3.0),
|
||||||
m_finger_DoubleTouch(false),
|
m_finger_DoubleTouch(false),
|
||||||
m_dynamicsWorld(NULL),
|
m_dynamicsWorld(NULL),
|
||||||
m_camera(vec3(0,0,0), 0, DEG_TO_RAD(45) ,50),
|
m_camera(NULL),
|
||||||
m_isRunning(true),
|
m_isRunning(true),
|
||||||
m_walk(0),
|
m_walk(0),
|
||||||
m_debugMode(false),
|
m_debugMode(false),
|
||||||
@ -60,26 +65,48 @@ ege::Scene::Scene(void) :
|
|||||||
|
|
||||||
ewol::resource::Keep(m_debugDrawing);
|
ewol::resource::Keep(m_debugDrawing);
|
||||||
|
|
||||||
m_zoom = 1.0/1000.0;
|
|
||||||
m_ratioTime = 1.0f;
|
m_ratioTime = 1.0f;
|
||||||
|
if (NULL != _collisionConfiguration) {
|
||||||
m_collisionConfiguration = new btDefaultCollisionConfiguration();
|
m_collisionConfiguration = _collisionConfiguration;
|
||||||
|
} else {
|
||||||
|
m_collisionConfiguration = new btDefaultCollisionConfiguration();
|
||||||
|
}
|
||||||
///use the default collision dispatcher.
|
///use the default collision dispatcher.
|
||||||
m_dispatcher = new btCollisionDispatcher(m_collisionConfiguration);
|
if (NULL != _dispatcher) {
|
||||||
|
m_dispatcher = _dispatcher;
|
||||||
m_broadphase = new btDbvtBroadphase();
|
} else {
|
||||||
|
m_dispatcher = new btCollisionDispatcher(m_collisionConfiguration);
|
||||||
|
}
|
||||||
|
if (NULL != _broadphase) {
|
||||||
|
m_broadphase = _broadphase;
|
||||||
|
} else {
|
||||||
|
m_broadphase = new btDbvtBroadphase();
|
||||||
|
}
|
||||||
|
|
||||||
///the default constraint solver.
|
///the default constraint solver.
|
||||||
btSequentialImpulseConstraintSolver* sol = new btSequentialImpulseConstraintSolver;
|
if (NULL != _solver) {
|
||||||
m_solver = sol;
|
m_solver = _solver;
|
||||||
|
} else {
|
||||||
|
m_solver = new btSequentialImpulseConstraintSolver();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (NULL != _dynamicsWorld) {
|
||||||
|
m_dynamicsWorld = _dynamicsWorld;
|
||||||
|
} else {
|
||||||
|
m_dynamicsWorld = new btDiscreteDynamicsWorld(m_dispatcher,m_broadphase,m_solver,m_collisionConfiguration);
|
||||||
|
// By default we set no gravity
|
||||||
|
m_dynamicsWorld->setGravity(btVector3(0,0,0));
|
||||||
|
}
|
||||||
|
|
||||||
m_dynamicsWorld = new btDiscreteDynamicsWorld(m_dispatcher,m_broadphase,m_solver,m_collisionConfiguration);
|
|
||||||
// in space, we set no gravity ...
|
|
||||||
m_dynamicsWorld->setGravity(btVector3(0,0,0));
|
|
||||||
m_env.SetDynamicWorld(m_dynamicsWorld);
|
m_env.SetDynamicWorld(m_dynamicsWorld);
|
||||||
|
|
||||||
// SET THE STATION ..
|
if (NULL != _camera) {
|
||||||
m_camera.SetEye(vec3(0,0,0));
|
m_camera = _camera;
|
||||||
|
} else {
|
||||||
|
m_camera = new ege::Camera(vec3(0,0,0), 0, DEG_TO_RAD(45) ,50);
|
||||||
|
// SET THE STATION ..
|
||||||
|
m_camera->SetEye(vec3(0,0,0));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -162,12 +189,12 @@ void ege::Scene::OnDraw(void)
|
|||||||
//EGE_DEBUG("Draw (start)");
|
//EGE_DEBUG("Draw (start)");
|
||||||
mat4 tmpMatrix;
|
mat4 tmpMatrix;
|
||||||
if (m_dynamicsWorld) {
|
if (m_dynamicsWorld) {
|
||||||
m_env.GetOrderedElementForDisplay(m_displayElementOrdered, m_camera.GetOrigin(), m_camera.GetViewVector());
|
m_env.GetOrderedElementForDisplay(m_displayElementOrdered, m_camera->GetOrigin(), m_camera->GetViewVector());
|
||||||
//EGE_DEBUG("DRAW : " << m_displayElementOrdered.Size() << " elements");
|
//EGE_DEBUG("DRAW : " << m_displayElementOrdered.Size() << " elements");
|
||||||
|
|
||||||
// TODO : Remove this ==> no more needed ==> checked in the Generate the list of the element ordered
|
// TODO : Remove this ==> no more needed ==> checked in the Generate the list of the element ordered
|
||||||
for (int32_t iii=0; iii<m_displayElementOrdered.Size(); iii++) {
|
for (int32_t iii=0; iii<m_displayElementOrdered.Size(); iii++) {
|
||||||
m_displayElementOrdered[iii].element->PreCalculationDraw(m_camera);
|
m_displayElementOrdered[iii].element->PreCalculationDraw(*m_camera);
|
||||||
}
|
}
|
||||||
// note : the first pass is done at the reverse way to prevent multiple display od the same point in the screen
|
// note : the first pass is done at the reverse way to prevent multiple display od the same point in the screen
|
||||||
// (and we remember that the first pass is to display all the non transparent elements)
|
// (and we remember that the first pass is to display all the non transparent elements)
|
||||||
@ -186,12 +213,12 @@ void ege::Scene::OnDraw(void)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
for (int32_t iii=0; iii<m_displayElementOrdered.Size(); iii++) {
|
for (int32_t iii=0; iii<m_displayElementOrdered.Size(); iii++) {
|
||||||
m_displayElementOrdered[iii].element->DrawLife(m_debugDrawing, m_camera);
|
m_displayElementOrdered[iii].element->DrawLife(m_debugDrawing, *m_camera);
|
||||||
}
|
}
|
||||||
#ifdef DEBUG
|
#ifdef DEBUG
|
||||||
if (true == m_debugMode) {
|
if (true == m_debugMode) {
|
||||||
for (int32_t iii=0; iii<m_displayElementOrdered.Size(); iii++) {
|
for (int32_t iii=0; iii<m_displayElementOrdered.Size(); iii++) {
|
||||||
m_displayElementOrdered[iii].element->DrawDebug(m_debugDrawing, m_camera);
|
m_displayElementOrdered[iii].element->DrawDebug(m_debugDrawing, *m_camera);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
@ -247,7 +274,7 @@ void ege::Scene::PeriodicCall(const ewol::EventTime& _event)
|
|||||||
//EWOL_DEBUG("Time: m_lastCallTime=" << m_lastCallTime << " deltaTime=" << deltaTime);
|
//EWOL_DEBUG("Time: m_lastCallTime=" << m_lastCallTime << " deltaTime=" << deltaTime);
|
||||||
|
|
||||||
// update camera positions:
|
// update camera positions:
|
||||||
m_camera.PeriodicCall(curentDelta);
|
m_camera->PeriodicCall(curentDelta);
|
||||||
|
|
||||||
//EGE_DEBUG("stepSimulation (start)");
|
//EGE_DEBUG("stepSimulation (start)");
|
||||||
///step the simulation
|
///step the simulation
|
||||||
@ -261,13 +288,14 @@ void ege::Scene::PeriodicCall(const ewol::EventTime& _event)
|
|||||||
int32_t numberEnnemyKilled=0;
|
int32_t numberEnnemyKilled=0;
|
||||||
int32_t victoryPoint=0;
|
int32_t victoryPoint=0;
|
||||||
etk::Vector<ege::ElementGame*>& elementList = m_env.GetElementGame();
|
etk::Vector<ege::ElementGame*>& elementList = m_env.GetElementGame();
|
||||||
for (int32_t iii=0; iii<elementList.Size(); iii++) {
|
for (int32_t iii=elementList.Size()-1; iii>=0; --iii) {
|
||||||
if(NULL != elementList[iii]) {
|
if(NULL != elementList[iii]) {
|
||||||
if (true == elementList[iii]->NeedToRemove()) {
|
if (true == elementList[iii]->NeedToRemove()) {
|
||||||
if (elementList[iii]->GetGroup() > 1) {
|
if (elementList[iii]->GetGroup() > 1) {
|
||||||
numberEnnemyKilled++;
|
numberEnnemyKilled++;
|
||||||
victoryPoint++;
|
victoryPoint++;
|
||||||
}
|
}
|
||||||
|
EGE_DEBUG("[" << elementList[iii]->GetUID() << "] element Removing ... " << elementList[iii]->GetType());
|
||||||
m_env.RmElementGame(elementList[iii]);
|
m_env.RmElementGame(elementList[iii]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -290,14 +318,14 @@ void ege::Scene::PeriodicCall(const ewol::EventTime& _event)
|
|||||||
walkValue = -1;
|
walkValue = -1;
|
||||||
}
|
}
|
||||||
if (walkValue!=0) {
|
if (walkValue!=0) {
|
||||||
float angleZ = m_camera.GetAngleZ();
|
float angleZ = m_camera->GetAngleZ();
|
||||||
vec3 offsetPosition( cosf(angleZ-M_PI/2.0)*walkValue,
|
vec3 offsetPosition( cosf(angleZ-M_PI/2.0)*walkValue,
|
||||||
-sinf(angleZ-M_PI/2.0)*walkValue,
|
-sinf(angleZ-M_PI/2.0)*walkValue,
|
||||||
0);
|
0);
|
||||||
//EWOL_DEBUG("Walk : " << ((int32_t)(angles.z/M_PI*180+180)%360-180) << " ==> " << angles);
|
//EWOL_DEBUG("Walk : " << ((int32_t)(angles.z/M_PI*180+180)%360-180) << " ==> " << angles);
|
||||||
// walk is 6 km/h
|
// walk is 6 km/h
|
||||||
vec3 pos = m_camera.GetEye() + offsetPosition*l_walkRatio*curentDelta;
|
vec3 pos = m_camera->GetEye() + offsetPosition*l_walkRatio*curentDelta;
|
||||||
m_camera.SetEye(pos);
|
m_camera->SetEye(pos);
|
||||||
}
|
}
|
||||||
walkValue=0;
|
walkValue=0;
|
||||||
if( (m_walk&WALK_FLAG_LEFT)!=0
|
if( (m_walk&WALK_FLAG_LEFT)!=0
|
||||||
@ -310,14 +338,14 @@ void ege::Scene::PeriodicCall(const ewol::EventTime& _event)
|
|||||||
walkValue = -1;
|
walkValue = -1;
|
||||||
}
|
}
|
||||||
if (walkValue != 0) {
|
if (walkValue != 0) {
|
||||||
float angleZ = m_camera.GetAngleZ();
|
float angleZ = m_camera->GetAngleZ();
|
||||||
vec3 offsetPosition( cosf(angleZ)*walkValue,
|
vec3 offsetPosition( cosf(angleZ)*walkValue,
|
||||||
-sinf(angleZ)*walkValue,
|
-sinf(angleZ)*walkValue,
|
||||||
0);
|
0);
|
||||||
//EWOL_DEBUG("Walk : " << ((int32_t)(angles.z/M_PI*180+180)%360-180) << " ==> " << angles);
|
//EWOL_DEBUG("Walk : " << ((int32_t)(angles.z/M_PI*180+180)%360-180) << " ==> " << angles);
|
||||||
// lateral walk is 4 km/h
|
// lateral walk is 4 km/h
|
||||||
vec3 pos = m_camera.GetEye() + offsetPosition*l_walkLateralRatio*curentDelta;
|
vec3 pos = m_camera->GetEye() + offsetPosition*l_walkLateralRatio*curentDelta;
|
||||||
m_camera.SetEye(pos);
|
m_camera->SetEye(pos);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -351,8 +379,8 @@ float tmp___localTime1 = (float)(ewol::GetTime() - tmp___startTime1) / 1000.0f;
|
|||||||
EWOL_DEBUG(" SCENE111 : " << tmp___localTime1 << "ms ");
|
EWOL_DEBUG(" SCENE111 : " << tmp___localTime1 << "ms ");
|
||||||
int64_t tmp___startTime2 = ewol::GetTime();
|
int64_t tmp___startTime2 = ewol::GetTime();
|
||||||
#endif
|
#endif
|
||||||
ewol::openGL::SetCameraMatrix(m_camera.GetMatrix());
|
ewol::openGL::SetCameraMatrix(m_camera->GetMatrix());
|
||||||
//mat4 tmpMat = tmpProjection * m_camera.GetMatrix();
|
//mat4 tmpMat = tmpProjection * m_camera->GetMatrix();
|
||||||
// set internal matrix system :
|
// set internal matrix system :
|
||||||
//ewol::openGL::SetMatrix(tmpMat);
|
//ewol::openGL::SetMatrix(tmpMat);
|
||||||
ewol::openGL::SetMatrix(tmpProjection);
|
ewol::openGL::SetMatrix(tmpProjection);
|
||||||
@ -397,7 +425,7 @@ vec2 ege::Scene::CalculateDeltaAngle(const vec2& posScreen)
|
|||||||
|
|
||||||
vec3 ege::Scene::ConvertScreenPositionInMapPosition(const vec2& posScreen)
|
vec3 ege::Scene::ConvertScreenPositionInMapPosition(const vec2& posScreen)
|
||||||
{
|
{
|
||||||
return m_camera.projectOnZGround(CalculateDeltaAngle(posScreen));
|
return m_camera->projectOnZGround(CalculateDeltaAngle(posScreen));
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ege::Scene::OnEventInput(const ewol::EventInput& _event)
|
bool ege::Scene::OnEventInput(const ewol::EventInput& _event)
|
||||||
@ -430,8 +458,8 @@ bool ege::Scene::OnEventInput(const ewol::EventInput& _event)
|
|||||||
if (ewol::keyEvent::statusMove == _event.GetStatus()) {
|
if (ewol::keyEvent::statusMove == _event.GetStatus()) {
|
||||||
vec2 tmppPos = relPos-m_centerButtonStartPos;
|
vec2 tmppPos = relPos-m_centerButtonStartPos;
|
||||||
tmppPos *= M_PI/(360.0f*6);
|
tmppPos *= M_PI/(360.0f*6);
|
||||||
m_camera.SetAngleZ(m_camera.GetAngleZ()- tmppPos.x());
|
m_camera->SetAngleZ(m_camera->GetAngleZ()- tmppPos.x());
|
||||||
m_camera.SetAngleTeta(m_camera.GetAngleTeta()-tmppPos.y());
|
m_camera->SetAngleTeta(m_camera->GetAngleTeta()-tmppPos.y());
|
||||||
}
|
}
|
||||||
// update register position ...
|
// update register position ...
|
||||||
m_centerButtonStartPos = relPos;
|
m_centerButtonStartPos = relPos;
|
||||||
@ -440,12 +468,12 @@ bool ege::Scene::OnEventInput(const ewol::EventInput& _event)
|
|||||||
if (ewol::keyEvent::statusMove == _event.GetStatus()) {
|
if (ewol::keyEvent::statusMove == _event.GetStatus()) {
|
||||||
vec3 nextPosition = ConvertScreenPositionInMapPosition(relPos);
|
vec3 nextPosition = ConvertScreenPositionInMapPosition(relPos);
|
||||||
vec3 tmppPos = nextPosition-m_finger_StartPosMoving;
|
vec3 tmppPos = nextPosition-m_finger_StartPosMoving;
|
||||||
vec3 oldposition = m_camera.GetEye();
|
vec3 oldposition = m_camera->GetEye();
|
||||||
// update the camera positions:
|
// update the camera positions:
|
||||||
oldposition.setX(oldposition.x() - tmppPos.x());
|
oldposition.setX(oldposition.x() - tmppPos.x());
|
||||||
oldposition.setY(oldposition.y() - tmppPos.y());
|
oldposition.setY(oldposition.y() - tmppPos.y());
|
||||||
// set the new position
|
// set the new position
|
||||||
m_camera.SetEye(oldposition);
|
m_camera->SetEye(oldposition);
|
||||||
}
|
}
|
||||||
// update register position ...
|
// update register position ...
|
||||||
m_leftButtonStartPos = relPos;
|
m_leftButtonStartPos = relPos;
|
||||||
@ -453,16 +481,16 @@ bool ege::Scene::OnEventInput(const ewol::EventInput& _event)
|
|||||||
} else if (4 == _event.GetId()) {
|
} else if (4 == _event.GetId()) {
|
||||||
if (ewol::keyEvent::statusSingle == _event.GetStatus()) {
|
if (ewol::keyEvent::statusSingle == _event.GetStatus()) {
|
||||||
// scrool input
|
// scrool input
|
||||||
float cameraDistance = m_camera.GetDistance()-3;
|
float cameraDistance = m_camera->GetDistance()-3;
|
||||||
EGE_DEBUG("New camera distance : " << etk_avg(10, cameraDistance, 100));
|
EGE_DEBUG("New camera distance : " << etk_avg(10, cameraDistance, 100));
|
||||||
m_camera.SetDistance(etk_avg(10, cameraDistance, 100));
|
m_camera->SetDistance(etk_avg(10, cameraDistance, 100));
|
||||||
}
|
}
|
||||||
} else if (5 == _event.GetId()) {
|
} else if (5 == _event.GetId()) {
|
||||||
if (ewol::keyEvent::statusSingle == _event.GetStatus()) {
|
if (ewol::keyEvent::statusSingle == _event.GetStatus()) {
|
||||||
// scrool output
|
// scrool output
|
||||||
float cameraDistance = m_camera.GetDistance()+3;
|
float cameraDistance = m_camera->GetDistance()+3;
|
||||||
EGE_DEBUG("New camera distance : " << etk_avg(10, cameraDistance, 100));
|
EGE_DEBUG("New camera distance : " << etk_avg(10, cameraDistance, 100));
|
||||||
m_camera.SetDistance(etk_avg(10, cameraDistance, 100));
|
m_camera->SetDistance(etk_avg(10, cameraDistance, 100));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
/*
|
/*
|
||||||
@ -504,9 +532,9 @@ bool ege::Scene::OnEventInput(const ewol::EventInput& _event)
|
|||||||
realDistance /= 2.0f;
|
realDistance /= 2.0f;
|
||||||
if (m_finger_oldDistance>=0) {
|
if (m_finger_oldDistance>=0) {
|
||||||
float distanceDelta = m_finger_oldDistance-realDistance;
|
float distanceDelta = m_finger_oldDistance-realDistance;
|
||||||
m_camera.SetDistance(etk_avg(10,m_camera.GetDistance()+distanceDelta/3.0f,100));
|
m_camera->SetDistance(etk_avg(10,m_camera->GetDistance()+distanceDelta/3.0f,100));
|
||||||
float angleDelta = m_finger_oldAngle - fingerAngle;
|
float angleDelta = m_finger_oldAngle - fingerAngle;
|
||||||
m_camera.SetAngleZ(m_camera.GetAngleZ()+angleDelta);
|
m_camera->SetAngleZ(m_camera->GetAngleZ()+angleDelta);
|
||||||
}
|
}
|
||||||
m_finger_oldDistance = realDistance;
|
m_finger_oldDistance = realDistance;
|
||||||
m_finger_oldAngle = fingerAngle;
|
m_finger_oldAngle = fingerAngle;
|
||||||
@ -536,9 +564,9 @@ bool ege::Scene::OnEventInput(const ewol::EventInput& _event)
|
|||||||
realDistance /= 2.0f;
|
realDistance /= 2.0f;
|
||||||
if (m_finger_oldDistance>=0) {
|
if (m_finger_oldDistance>=0) {
|
||||||
float distanceDelta = m_finger_oldDistance-realDistance;
|
float distanceDelta = m_finger_oldDistance-realDistance;
|
||||||
m_camera.SetDistance(etk_avg(10,m_camera.GetDistance()+distanceDelta/3.0f,100));
|
m_camera->SetDistance(etk_avg(10,m_camera->GetDistance()+distanceDelta/3.0f,100));
|
||||||
float angleDelta = m_finger_oldAngle - fingerAngle;
|
float angleDelta = m_finger_oldAngle - fingerAngle;
|
||||||
m_camera.SetAngleZ(m_camera.GetAngleZ()+angleDelta);
|
m_camera->SetAngleZ(m_camera->GetAngleZ()+angleDelta);
|
||||||
}
|
}
|
||||||
m_finger_oldDistance = realDistance;
|
m_finger_oldDistance = realDistance;
|
||||||
m_finger_oldAngle = fingerAngle;
|
m_finger_oldAngle = fingerAngle;
|
||||||
|
23
ege/Scene.h
23
ege/Scene.h
@ -46,7 +46,12 @@ namespace ege {
|
|||||||
* @brief Constructor of the widget classes
|
* @brief Constructor of the widget classes
|
||||||
* @return (no execption generated (not managed in embended platform))
|
* @return (no execption generated (not managed in embended platform))
|
||||||
*/
|
*/
|
||||||
Scene(void);
|
Scene(btDefaultCollisionConfiguration* _collisionConfiguration=NULL,
|
||||||
|
btCollisionDispatcher* _dispatcher=NULL,
|
||||||
|
btBroadphaseInterface* _broadphase=NULL,
|
||||||
|
btConstraintSolver* _solver=NULL,
|
||||||
|
btDynamicsWorld* _dynamicsWorld=NULL,
|
||||||
|
ege::Camera* _camera=NULL);
|
||||||
/**
|
/**
|
||||||
* @brief Destructor of the widget classes
|
* @brief Destructor of the widget classes
|
||||||
*/
|
*/
|
||||||
@ -70,14 +75,12 @@ namespace ege {
|
|||||||
btConstraintSolver* m_solver;
|
btConstraintSolver* m_solver;
|
||||||
btDynamicsWorld* m_dynamicsWorld;
|
btDynamicsWorld* m_dynamicsWorld;
|
||||||
// camera section
|
// camera section
|
||||||
ege::Camera m_camera; //!< Display point of view.
|
ege::Camera* m_camera; //!< Display point of view.
|
||||||
vec3 m_cameraMovePointStart; //!< Position where the mouse start to move
|
vec3 m_cameraMovePointStart; //!< Position where the mouse start to move
|
||||||
// Other elements
|
// Other elements
|
||||||
bool m_isRunning; //!< the display is running (not in pause)
|
bool m_isRunning; //!< the display is running (not in pause)
|
||||||
float m_ratioTime; //!< Ratio time for the speed of the game ...
|
float m_ratioTime; //!< Ratio time for the speed of the game ...
|
||||||
uint32_t m_walk; //!< Wolk properties
|
uint32_t m_walk; //!< Wolk properties
|
||||||
bool m_debugMode;
|
|
||||||
ewol::Colored3DObject* m_debugDrawing; //!< for the debug draw elements
|
|
||||||
// Note : This is only for temporary elements : on the display
|
// Note : This is only for temporary elements : on the display
|
||||||
etk::Vector<ege::Environement::ResultNearestElement> m_displayElementOrdered;
|
etk::Vector<ege::Environement::ResultNearestElement> m_displayElementOrdered;
|
||||||
public:
|
public:
|
||||||
@ -93,20 +96,24 @@ namespace ege {
|
|||||||
* @brief Toggle between pause and running
|
* @brief Toggle between pause and running
|
||||||
*/
|
*/
|
||||||
void PauseToggle(void);
|
void PauseToggle(void);
|
||||||
|
protected:
|
||||||
|
bool m_debugMode;
|
||||||
|
ewol::Colored3DObject* m_debugDrawing; //!< for the debug draw elements
|
||||||
|
public:
|
||||||
|
/**
|
||||||
|
* @brief Toggle the debug mode ==> usefull for DEBUG only ...
|
||||||
|
*/
|
||||||
void DebugToggle(void) { m_debugMode = m_debugMode?false:true; };
|
void DebugToggle(void) { m_debugMode = m_debugMode?false:true; };
|
||||||
protected:
|
protected:
|
||||||
// Derived function
|
// Derived function
|
||||||
virtual void ScenePeriodicCall(int64_t localTime, int32_t deltaTime) { };
|
virtual void ScenePeriodicCall(int64_t localTime, int32_t deltaTime) { };
|
||||||
// camera properties :
|
|
||||||
private:
|
|
||||||
float m_zoom;
|
|
||||||
public:
|
public:
|
||||||
vec2 CalculateDeltaAngle(const vec2& posScreen);
|
vec2 CalculateDeltaAngle(const vec2& posScreen);
|
||||||
vec3 ConvertScreenPositionInMapPosition(const vec2& posScreen);
|
vec3 ConvertScreenPositionInMapPosition(const vec2& posScreen);
|
||||||
/**
|
/**
|
||||||
* @brief Get the current camera reference for the scene rendering
|
* @brief Get the current camera reference for the scene rendering
|
||||||
*/
|
*/
|
||||||
ege::Camera& GetCamera(void) { return m_camera; };
|
ege::Camera& GetCamera(void) { return *m_camera; };
|
||||||
/**
|
/**
|
||||||
* @brief Set the curent Time Ratio (default 1)
|
* @brief Set the curent Time Ratio (default 1)
|
||||||
*/
|
*/
|
||||||
|
@ -13,7 +13,6 @@ def Create(target):
|
|||||||
'ege/AudioEngine.cpp',
|
'ege/AudioEngine.cpp',
|
||||||
'ege/Camera.cpp',
|
'ege/Camera.cpp',
|
||||||
'ege/ElementGame.cpp',
|
'ege/ElementGame.cpp',
|
||||||
'ege/ElementGameIA.cpp',
|
|
||||||
'ege/Particule.cpp',
|
'ege/Particule.cpp',
|
||||||
'ege/ParticuleEngine.cpp',
|
'ege/ParticuleEngine.cpp',
|
||||||
'ege/Scene.cpp',
|
'ege/Scene.cpp',
|
||||||
|
Loading…
x
Reference in New Issue
Block a user