change philosiphy of the scene manager
This commit is contained in:
parent
d489e1df83
commit
9f258dcf7e
@ -26,61 +26,90 @@
|
|||||||
#include <ewol/Game/GameElement.h>
|
#include <ewol/Game/GameElement.h>
|
||||||
#include <ewol/Game/SceneElement.h>
|
#include <ewol/Game/SceneElement.h>
|
||||||
|
|
||||||
|
ewol::SceneElement::SceneElement(void)
|
||||||
int32_t ewol::SceneElement::AddElement(ewol::GameElement* newElement)
|
|
||||||
{
|
{
|
||||||
if (NULL == newElement) {
|
m_id = 1;
|
||||||
return -1;
|
numberOfGroup = 0;
|
||||||
|
for (int32_t iii=0; iii<MAX_GROUP_NUMBER; iii++) {
|
||||||
|
for (int32_t jjj=0; jjj<MAX_GROUP_NUMBER; jjj++) {
|
||||||
|
groupEnemy[iii][jjj] = -1;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
for (int32_t iii=0; iii<listAnimatedElements.Size(); iii++) {
|
};
|
||||||
if (NULL == listAnimatedElements[iii]) {
|
|
||||||
|
void ewol::SceneElement::AddElement(int32_t group, ewol::GameElement* newElement)
|
||||||
|
{
|
||||||
|
elementIdentifier_ts tmpElement;
|
||||||
|
if (NULL == newElement) {
|
||||||
|
EWOL_ERROR("newElement is empty ==> not added at the system ...");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (group < 0 || group >= MAX_GROUP_NUMBER) {
|
||||||
|
EWOL_ERROR("group is wrong " << group << "!=[0," << MAX_GROUP_NUMBER << "]==> not added at the system ...");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
for (int32_t iii=0; iii<listAnimatedElements[group].Size(); iii++) {
|
||||||
|
if (NULL == listAnimatedElements[group][iii]) {
|
||||||
// find an empty slot ...
|
// find an empty slot ...
|
||||||
listAnimatedElements[iii] = newElement;
|
listAnimatedElements[group][iii] = newElement;
|
||||||
return iii;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
//did not find empty slot :
|
//did not find empty slot :
|
||||||
listAnimatedElements.PushBack(newElement);
|
listAnimatedElements.PushBack(newElement);
|
||||||
return listAnimatedElements.Size()-1;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
bool ewol::SceneElement::GetElementProperty(gameElementGenericProperty_ts &element, int32_t id)
|
bool ewol::SceneElement::GetElementProperty(gameElementGenericProperty_ts &element, elementIdentifier_ts& id)
|
||||||
{
|
{
|
||||||
for (int32_t iii=0; iii<listAnimatedElements.Size(); iii++) {
|
if (id.group > numberOfGroup || id.group > MAX_GROUP_NUMBER) {
|
||||||
if (NULL != listAnimatedElements[iii]) {
|
return false;
|
||||||
if (true == listAnimatedElements[iii]->GetElementProperty(element, id) ) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return false;
|
if (id.listId >= listAnimatedElements[id.group].Size()) {
|
||||||
|
return false;
|
||||||
|
if (NULL == listAnimatedElements[id.group][id.listId]) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
// copy the properties
|
||||||
|
element.id = id;
|
||||||
|
// get the sub properties ...
|
||||||
|
return listAnimatedElements[id.group][id.listId]->GetElementProperty(element, id.id);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
int32_t ewol::SceneElement::GetNearestEnemy(coord2D_ts position, int32_t groupId)
|
elementIdentifier_ts ewol::SceneElement::GetNearestEnemy(coord2D_ts position, int32_t groupId)
|
||||||
{
|
{
|
||||||
int32_t findId = -1;
|
elementIdentifier_ts findId;
|
||||||
|
findId.id = -1;
|
||||||
|
findId.group = -1;
|
||||||
|
findId.listId = -1;
|
||||||
etkFloat_t lastQuadDistance = 9999999999999999.0;
|
etkFloat_t lastQuadDistance = 9999999999999999.0;
|
||||||
for (int32_t iii=0; iii<listAnimatedElements.Size(); iii++) {
|
int32_t jjj=0;
|
||||||
if (NULL != listAnimatedElements[iii]) {
|
while (groupEnemy[jjj] != -1) {
|
||||||
int32_t newID = listAnimatedElements[iii]->GetNearestEnemy(position, groupId, lastQuadDistance);
|
for (int32_t iii=0; iii<listAnimatedElements[groupEnemy[jjj]].Size(); iii++) {
|
||||||
if (-1 != newID) {
|
if (NULL != listAnimatedElements[groupEnemy[jjj]][iii]) {
|
||||||
findId = newID;
|
int32_t newID = listAnimatedElements[groupEnemy[jjj]][iii]->GetNearestEnemy(position, lastQuadDistance);
|
||||||
|
if (-1 != newID) {
|
||||||
|
findId.id = newID;
|
||||||
|
findId.group = groupEnemy[jjj];
|
||||||
|
findId.listId = iii;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
jjj++;
|
||||||
}
|
}
|
||||||
return findId;
|
return findId;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
bool ewol::SceneElement::HaveImpact(int32_t group, int32_t type, coord2D_ts position, etkFloat_t size)
|
bool ewol::SceneElement::HaveImpact(int32_t group, int32_t type, coord2D_ts position, etkFloat_t size)
|
||||||
{
|
{
|
||||||
for (int32_t iii=0; iii<listAnimatedElements.Size(); iii++) {
|
for (int32_t jjj=0; jjj<MAX_GROUP_NUMBER; jjj++) {
|
||||||
if (NULL != listAnimatedElements[iii]) {
|
for (int32_t iii=0; iii<listAnimatedElements[jjj].Size(); iii++) {
|
||||||
if (true == listAnimatedElements[iii]->HaveImpact(group, type, position, size )) {
|
if (NULL != listAnimatedElements[jjj][iii]) {
|
||||||
return true;
|
if (true == listAnimatedElements[jjj][iii]->HaveImpact(group, type, position, size )) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -89,9 +118,55 @@ bool ewol::SceneElement::HaveImpact(int32_t group, int32_t type, coord2D_ts posi
|
|||||||
|
|
||||||
void ewol::SceneElement::Explosion(int32_t group, int32_t type, coord2D_ts position, etkFloat_t pxAtenuation, etkFloat_t power)
|
void ewol::SceneElement::Explosion(int32_t group, int32_t type, coord2D_ts position, etkFloat_t pxAtenuation, etkFloat_t power)
|
||||||
{
|
{
|
||||||
for (int32_t iii=0; iii<listAnimatedElements.Size(); iii++) {
|
for (int32_t jjj=0; jjj<MAX_GROUP_NUMBER; jjj++) {
|
||||||
if (NULL != listAnimatedElements[iii]) {
|
for (int32_t iii=0; iii<listAnimatedElements[jjj].Size(); iii++) {
|
||||||
listAnimatedElements[iii]->Explosion(group, type, position, pxAtenuation, power);
|
if (NULL != listAnimatedElements[jjj][iii]) {
|
||||||
|
listAnimatedElements[jjj][iii]->Explosion(group, type, position, pxAtenuation, power);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
elementIdentifier_ts ewol::SceneElement::GetElementAtPos(coord2D_ts position, int32_t maxDistanceDetection)
|
||||||
|
{
|
||||||
|
elementIdentifier_ts findId;
|
||||||
|
findId.id = -1;
|
||||||
|
findId.group = -1;
|
||||||
|
findId.listId = -1;
|
||||||
|
etkFloat_t lastQuadDistance = 9999999999999999.0;
|
||||||
|
int32_t jjj=0;
|
||||||
|
for (int32_t jjj=0; jjj<MAX_GROUP_NUMBER; jjj++) {
|
||||||
|
for (int32_t iii=0; iii<listAnimatedElements[jjj].Size(); iii++) {
|
||||||
|
if (NULL != listAnimatedElements[jjj][iii]) {
|
||||||
|
int32_t newID = listAnimatedElements[jjj][iii]->GetNearestEnemy(position, lastQuadDistance);
|
||||||
|
if (-1 != newID) {
|
||||||
|
findId.id = newID;
|
||||||
|
findId.group = groupEnemy[jjj];
|
||||||
|
findId.listId = iii;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (lastQuadDistance > maxDistanceDetection*maxDistanceDetection) {
|
||||||
|
findId.id = -1;
|
||||||
|
findId.group = -1;
|
||||||
|
findId.listId = -1;
|
||||||
|
}
|
||||||
|
return findId;
|
||||||
|
}
|
||||||
|
|
||||||
|
void ewol::SceneElement::SetEventInput(elementIdentifier_ts& id, coord2D_ts position)
|
||||||
|
{
|
||||||
|
EWOL_TODO("but when ...");
|
||||||
|
}
|
||||||
|
|
||||||
|
void ewol::SceneElement::SetEventExternButton(elementIdentifier_ts& id, int32_t btId, int32_t state)
|
||||||
|
{
|
||||||
|
EWOL_TODO("but when ...");
|
||||||
|
}
|
||||||
|
|
||||||
|
void ewol::SceneElement::SetEventExternJoystick(elementIdentifier_ts& id, int32_t joyId, etkFloat_t angle, etkFloat_t distance, int32_t state)
|
||||||
|
{
|
||||||
|
EWOL_TODO("but when ...");
|
||||||
|
}
|
||||||
|
|
||||||
|
@ -32,32 +32,47 @@
|
|||||||
namespace ewol {
|
namespace ewol {
|
||||||
class GameElement;
|
class GameElement;
|
||||||
|
|
||||||
|
// this is to simplify the time to acces at a specific element
|
||||||
typedef struct {
|
typedef struct {
|
||||||
int32_t id; //!< Unique ID
|
|
||||||
int32_t group; //!< the element group
|
int32_t group; //!< the element group
|
||||||
int32_t type; //!< element type
|
int32_t listId; //!< the id in the list of element
|
||||||
coord2D_ts position; //!< current position
|
int32_t id; //!< Unique ID
|
||||||
coord2D_ts speed; //!< current speed
|
} elementIdentifier_ts;
|
||||||
coord2D_ts size; //!< curent size of the element
|
|
||||||
etkFloat_t angle; //!< element angle
|
typedef struct {
|
||||||
|
elementIdentifier_ts id; //!< the element definition
|
||||||
|
int32_t type; //!< element type
|
||||||
|
coord2D_ts position; //!< current position
|
||||||
|
coord2D_ts speed; //!< current speed
|
||||||
|
coord2D_ts size; //!< curent size of the element
|
||||||
|
etkFloat_t angle; //!< element angle
|
||||||
} gameElementGenericProperty_ts;
|
} gameElementGenericProperty_ts;
|
||||||
|
|
||||||
|
#define MAX_GROUP_NUMBER (32)
|
||||||
|
|
||||||
class SceneElement {
|
class SceneElement {
|
||||||
private:
|
private:
|
||||||
int32_t m_id; //!< Unique element ID
|
int32_t m_id; //!< Unique element ID ==> to reference the element unicly
|
||||||
public:
|
public:
|
||||||
SceneElement(void) { m_id = 1; };
|
SceneElement(void);
|
||||||
~SceneElement(void) { };
|
~SceneElement(void) { };
|
||||||
etk::VectorType<ewol::OObject*> backgroundElements[NB_BOUBLE_BUFFER]; //!< element that must be display the first
|
int32_t numberOfGroup; //!< curent scene number of group
|
||||||
etk::VectorType<ewol::Sprite*> animated[NB_BOUBLE_BUFFER]; //!< element that must be display the first
|
etk::UString groupDescription[MAX_GROUP_NUMBER]; //!< name of all the groups
|
||||||
etk::VectorType<ewol::Sprite*> effects[NB_BOUBLE_BUFFER]; //!< element that must be display the first
|
int32_t groupEnemy[MAX_GROUP_NUMBER][MAX_GROUP_NUMBER]; //!< list of the ennemy
|
||||||
etk::VectorType<ewol::GameElement*> listAnimatedElements; //!< generic element to display...
|
etk::VectorType<ewol::OObject*> backgroundElements[NB_BOUBLE_BUFFER]; //!< element that must be display the first
|
||||||
int32_t GetUniqueId(void) { int32_t iddd = m_id; m_id++; return iddd; };
|
etk::VectorType<ewol::Sprite*> animated[NB_BOUBLE_BUFFER]; //!< element that must be display the second
|
||||||
int32_t AddElement(ewol::GameElement* newElement);
|
etk::VectorType<ewol::Sprite*> effects[NB_BOUBLE_BUFFER]; //!< element that must be display the third
|
||||||
bool GetElementProperty(gameElementGenericProperty_ts& element, int32_t id);
|
etk::VectorType<ewol::GameElement*> listAnimatedElements[MAX_GROUP_NUMBER]; //!< generic element to display order in the diffferent group
|
||||||
int32_t GetNearestEnemy(coord2D_ts position, int32_t groupId);
|
int32_t GetUniqueId(void) { int32_t iddd = m_id; m_id++; return iddd; };
|
||||||
bool HaveImpact(int32_t group, int32_t type, coord2D_ts position, etkFloat_t size);
|
void AddElement(int32_t group, ewol::GameElement* newElement);
|
||||||
void Explosion(int32_t group, int32_t type, coord2D_ts position, etkFloat_t pxAtenuation, etkFloat_t power);
|
bool GetElementProperty(gameElementGenericProperty_ts& element, elementIdentifier_ts& id);
|
||||||
|
elementIdentifier_ts GetNearestEnemy(coord2D_ts position, int32_t groupId);
|
||||||
|
bool HaveImpact(int32_t group, int32_t type, coord2D_ts position, etkFloat_t size);
|
||||||
|
void Explosion(int32_t group, int32_t type, coord2D_ts position, etkFloat_t pxAtenuation, etkFloat_t power);
|
||||||
|
elementIdentifier_ts GetElementAtPos(coord2D_ts position, int32_t maxDistanceDetection);
|
||||||
|
void SetEventInput(elementIdentifier_ts& id, coord2D_ts position);
|
||||||
|
void SetEventExternButton(elementIdentifier_ts& id, int32_t btId, int32_t state);
|
||||||
|
void SetEventExternJoystick(elementIdentifier_ts& id, int32_t joyId, etkFloat_t angle, etkFloat_t distance, int32_t state);
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user