change the scene mmechanism and corection of a bug in the VectorType template

This commit is contained in:
Edouard Dupin 2012-04-18 00:34:02 +02:00
parent 02c92b3e2e
commit 7ad9bce29c
6 changed files with 137 additions and 31 deletions

View File

@ -424,7 +424,10 @@ template<typename MY_TYPE=int32_t> class VectorType
// Request resize of the current buffer
Resize(m_size+1);
// move curent data
memmove((m_data + pos + 1), (m_data + pos), (tmpSize - pos)*sizeof(MY_TYPE) );
int32_t sizeToMove = (tmpSize - pos)*sizeof(MY_TYPE);
if ( 0 < sizeToMove) {
memmove((m_data + pos + 1), (m_data + pos), sizeToMove );
}
// affectation of the current element
m_data[pos] = item;
}
@ -448,7 +451,10 @@ template<typename MY_TYPE=int32_t> class VectorType
// Request resize of the current buffer
Resize(m_size+nbElement);
// move curent data (after the position)
memmove((m_data + pos + nbElement), (m_data + pos), (tmpSize - pos)*sizeof(MY_TYPE) );
int32_t sizeToMove = (tmpSize - pos)*sizeof(MY_TYPE);
if ( 0 < sizeToMove) {
memmove((m_data + pos + nbElement), (m_data + pos), sizeToMove );
}
// affectation of all input element
memcpy(&m_data[pos], item, nbElement*sizeof(MY_TYPE) );
}
@ -468,8 +474,11 @@ template<typename MY_TYPE=int32_t> class VectorType
return;
}
int32_t tmpSize = m_size;
// move curent data
memmove((m_data + pos), (m_data + pos + 1), (tmpSize - (pos+1))*sizeof(MY_TYPE) );
int32_t sizeToMove = (tmpSize - (pos+1))*sizeof(MY_TYPE);
if ( 0 < sizeToMove) {
// move curent data
memmove((m_data + pos), (m_data + pos + 1), sizeToMove );
}
// Request resize of the current buffer
Resize(m_size-1);
}
@ -495,7 +504,10 @@ template<typename MY_TYPE=int32_t> class VectorType
int32_t nbElement = m_size - pos;
int32_t tmpSize = m_size;
// move curent data
memmove((m_data + pos), (m_data + pos + nbElement), (tmpSize - (pos+nbElement))*sizeof(MY_TYPE) );
int32_t sizeToMove = (tmpSize - (pos+nbElement))*sizeof(MY_TYPE);
if ( 0 < sizeToMove) {
memmove((m_data + pos), (m_data + pos + nbElement), sizeToMove );
}
// Request resize of the current buffer
Resize(m_size-nbElement);
}
@ -520,7 +532,10 @@ template<typename MY_TYPE=int32_t> class VectorType
}
int32_t tmpSize = m_size;
// move curent data
memmove((m_data + pos), (m_data + pos + nbElement), (tmpSize - (pos+nbElement))*sizeof(MY_TYPE) );
int32_t sizeToMove = (tmpSize - (pos+nbElement))*sizeof(MY_TYPE);
if ( 0 < sizeToMove) {
memmove((m_data + pos), (m_data + pos + nbElement), sizeToMove );
}
// Request resize of the current buffer
Resize(m_size-nbElement);
}

View File

@ -25,9 +25,6 @@
#ifndef __EWOL_GAME_ELEMENT_H__
#define __EWOL_GAME_ELEMENT_H__
namespace ewol {
class GameElement;
};
#include <etk/Types.h>
#include <ewol/Debug.h>
#include <ewol/OObject/Sprite.h>
@ -82,6 +79,8 @@ namespace ewol {
int32_t GroupGet(void) { return m_group; };
void GroupSet(int32_t state) { m_group = state; };
virtual bool GetElementProperty(gameElementGenericProperty_ts &element, int32_t id) {return false;};
virtual int32_t GetNearestEnemy(coord2D_ts position, int32_t groupId, etkFloat_t& lastQuadDistance) { return -1;};
/**
* @brief Periodicly this fuction will be call tu change property of all the dynamic obbjects
* @param[in] time Current game time (start at 0)

View File

@ -0,0 +1,97 @@
/**
*******************************************************************************
* @file ewol/Game/SceneElement.cpp
* @brief ewol Scene widget system (Sources)
* @author Edouard DUPIN
* @date 17/04/2012
* @par Project
* ewol
*
* @par Copyright
* Copyright 2011 Edouard DUPIN, all right reserved
*
* This software is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY.
*
* Licence summary :
* You can modify and redistribute the sources code and binaries.
* You can send me the bug-fix
*
* Term of the licence in in the file licence.txt.
*
*******************************************************************************
*/
#include <ewol/Debug.h>
#include <ewol/Game/GameElement.h>
#include <ewol/Game/SceneElement.h>
int32_t ewol::SceneElement::AddElement(ewol::GameElement* newElement)
{
if (NULL == newElement) {
return -1;
}
for (int32_t iii=0; iii<listAnimatedElements.Size(); iii++) {
if (NULL == listAnimatedElements[iii]) {
// find an empty slot ...
listAnimatedElements[iii] = newElement;
return iii;
}
}
//did not find empty slot :
listAnimatedElements.PushBack(newElement);
return listAnimatedElements.Size()-1;
}
bool ewol::SceneElement::GetElementProperty(gameElementGenericProperty_ts &element, int32_t id)
{
for (int32_t iii=0; iii<listAnimatedElements.Size(); iii++) {
if (NULL != listAnimatedElements[iii]) {
if (true == listAnimatedElements[iii]->GetElementProperty(element, id) ) {
return true;
}
}
}
return false;
}
int32_t ewol::SceneElement::GetNearestEnemy(coord2D_ts position, int32_t groupId)
{
int32_t findId = -1;
etkFloat_t lastQuadDistance = 9999999999999999.0;
for (int32_t iii=0; iii<listAnimatedElements.Size(); iii++) {
if (NULL != listAnimatedElements[iii]) {
int32_t newID = listAnimatedElements[iii]->GetNearestEnemy(position, groupId, lastQuadDistance);
if (-1 != newID) {
findId = newID;
}
}
}
return findId;
}
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++) {
if (NULL != listAnimatedElements[iii]) {
if (true == listAnimatedElements[iii]->HaveImpact(group, type, position, size )) {
return true;
}
}
}
return false;
}
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++) {
if (NULL != listAnimatedElements[iii]) {
listAnimatedElements[iii]->Explosion(group, type, position, pxAtenuation, power);
}
}
}

View File

@ -25,16 +25,23 @@
#ifndef __EWOL_SCENE_ELEMENT_H__
#define __EWOL_SCENE_ELEMENT_H__
namespace ewol {
class SceneElement;
};
#include <etk/Types.h>
#include <ewol/Debug.h>
#include <ewol/OObject/Sprite.h>
#include <ewol/Game/GameElement.h>
namespace ewol {
class GameElement;
typedef struct {
int32_t id; //!< Unique ID
int32_t group; //!< the element group
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;
class SceneElement {
private:
int32_t m_id; //!< Unique element ID
@ -47,6 +54,10 @@ namespace ewol {
etk::VectorType<ewol::GameElement*> listAnimatedElements; //!< generic element to display...
int32_t GetUniqueId(void) { int32_t iddd = m_id; m_id++; return iddd; };
int32_t AddElement(ewol::GameElement* newElement);
bool GetElementProperty(gameElementGenericProperty_ts& element, int32_t id);
int32_t 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);
};
};

View File

@ -146,23 +146,6 @@ void ewol::Scene::OnDraw(void)
}
int32_t ewol::SceneElement::AddElement(ewol::GameElement* newElement)
{
if (NULL == newElement) {
return -1;
}
for (int32_t iii=0; iii<listAnimatedElements.Size(); iii++) {
if (NULL == listAnimatedElements[iii]) {
// find an empty slot ...
listAnimatedElements[iii] = newElement;
return iii;
}
}
//did not find empty slot :
listAnimatedElements.PushBack(newElement);
return listAnimatedElements.Size()-1;
}
#define CYCLIC_CALL_PERIODE_US (10000)
/**
* @brief Periodic call of this widget

View File

@ -11,6 +11,7 @@ FILE_LIST = ewol/ewol.cpp \
ewol/EObjectManager.cpp \
ewol/OObject.cpp \
ewol/Game/GameElement.cpp \
ewol/Game/SceneElement.cpp \
ewol/OObject/2DText.cpp \
ewol/OObject/2DTextColored.cpp \
ewol/OObject/2DColored.cpp \