diff --git a/Sources/libetk/etk/VectorType.h b/Sources/libetk/etk/VectorType.h index f12eb486..fabc355e 100644 --- a/Sources/libetk/etk/VectorType.h +++ b/Sources/libetk/etk/VectorType.h @@ -424,7 +424,10 @@ template 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 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 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 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 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); } diff --git a/Sources/libewol/ewol/Game/GameElement.h b/Sources/libewol/ewol/Game/GameElement.h index 4dd4c10a..2bc53362 100644 --- a/Sources/libewol/ewol/Game/GameElement.h +++ b/Sources/libewol/ewol/Game/GameElement.h @@ -25,9 +25,6 @@ #ifndef __EWOL_GAME_ELEMENT_H__ #define __EWOL_GAME_ELEMENT_H__ -namespace ewol { - class GameElement; -}; #include #include #include @@ -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) diff --git a/Sources/libewol/ewol/Game/SceneElement.cpp b/Sources/libewol/ewol/Game/SceneElement.cpp new file mode 100644 index 00000000..db731250 --- /dev/null +++ b/Sources/libewol/ewol/Game/SceneElement.cpp @@ -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 +#include +#include + + +int32_t ewol::SceneElement::AddElement(ewol::GameElement* newElement) +{ + if (NULL == newElement) { + return -1; + } + for (int32_t iii=0; iiiGetElementProperty(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; iiiGetNearestEnemy(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; iiiHaveImpact(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; iiiExplosion(group, type, position, pxAtenuation, power); + } + } +} \ No newline at end of file diff --git a/Sources/libewol/ewol/Game/SceneElement.h b/Sources/libewol/ewol/Game/SceneElement.h index 48ffcd10..5c6508e4 100644 --- a/Sources/libewol/ewol/Game/SceneElement.h +++ b/Sources/libewol/ewol/Game/SceneElement.h @@ -25,16 +25,23 @@ #ifndef __EWOL_SCENE_ELEMENT_H__ #define __EWOL_SCENE_ELEMENT_H__ -namespace ewol { - class SceneElement; -}; #include #include #include -#include - 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 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); }; }; diff --git a/Sources/libewol/ewol/widget/Scene.cpp b/Sources/libewol/ewol/widget/Scene.cpp index 349e853f..14eb464a 100644 --- a/Sources/libewol/ewol/widget/Scene.cpp +++ b/Sources/libewol/ewol/widget/Scene.cpp @@ -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