diff --git a/.gitmodules b/.gitmodules index 2cf9ee1a..da07503f 100644 --- a/.gitmodules +++ b/.gitmodules @@ -38,3 +38,6 @@ [submodule "external/z/zlib"] path = external/z/zlib url = https://github.com/madler/zlib.git +[submodule "external/ode"] + path = external/ode + url = https://github.com/HeeroYui/ode.git diff --git a/Makefile.mk b/Makefile.mk index f481f8ce..9721f8fc 100644 --- a/Makefile.mk +++ b/Makefile.mk @@ -19,6 +19,7 @@ USER_PACKAGES+= $(TMP_DIR)/external/portaudio USER_PACKAGES+= $(TMP_DIR)/external/tinyxml USER_PACKAGES+= $(TMP_DIR)/external/z USER_PACKAGES+= $(TMP_DIR)/external/zip +USER_PACKAGES+= $(TMP_DIR)/external/ode #include te generic toolchain : include $(TMP_DIR)/build/Makefile.mk diff --git a/external/etk b/external/etk index 1d4c27e7..033c9dd6 160000 --- a/external/etk +++ b/external/etk @@ -1 +1 @@ -Subproject commit 1d4c27e7fd68cb9cbf11a89068c4b1d10744555c +Subproject commit 033c9dd63a75db8afb448760cdb59bc8f89d5e7a diff --git a/external/ode b/external/ode new file mode 160000 index 00000000..7e4c9495 --- /dev/null +++ b/external/ode @@ -0,0 +1 @@ +Subproject commit 7e4c9495b4688c4387402897922f0e258338a9ec diff --git a/sources/Linux.mk b/sources/Linux.mk index 6f6b1932..1574fb60 100644 --- a/sources/Linux.mk +++ b/sources/Linux.mk @@ -12,7 +12,7 @@ LOCAL_VERSION=$(shell cat $(LOCAL_PATH)/tag) $(info [TAG:$(LOCAL_MODULE)] $(LOCAL_VERSION)) # name of the dependency -LOCAL_LIBRARIES := etk freetype tinyxml libzip libpng parsersvg lua portaudio +LOCAL_LIBRARIES := etk freetype tinyxml libzip libpng parsersvg lua portaudio ode LOCAL_C_INCLUDES := diff --git a/sources/ewol/game/Element.cpp b/sources/ewol/game/Element.cpp new file mode 100644 index 00000000..91769003 --- /dev/null +++ b/sources/ewol/game/Element.cpp @@ -0,0 +1,33 @@ +/** + * @author Edouard DUPIN + * + * @copyright 2011, Edouard DUPIN, all right reserved + * + * @license BSD v3 (see license file) + */ + + + +#include + +static int32_t uniqueId = 0; + + +game::Element::Element(void) : + m_position(0,0,0), + m_speed(0,0,0), + m_orientation(0,0,0), + m_uniqueId(uniqueId), + m_groupId(0), + m_type(0), + m_visible(true), + m_mass(0) +{ + uniqueId++; +} + +game::Element::~Element(void) +{ + +} + diff --git a/sources/ewol/game/Element.h b/sources/ewol/game/Element.h new file mode 100644 index 00000000..63760ce3 --- /dev/null +++ b/sources/ewol/game/Element.h @@ -0,0 +1,45 @@ +/** + * @author Edouard DUPIN + * + * @copyright 2011, Edouard DUPIN, all right reserved + * + * @license BSD v3 (see license file) + */ + +#ifndef __GAME_ELEMENT_H__ +#define __GAME_ELEMENT_H__ + + +#include +#include + +namespace game +{ + class Element + { + private: + //ewol::??? m_resource; //!< Resource to display the element. + protected: + vec3 m_position; //!< Current position of the element. + vec3 m_speed; //!< Speed of the element. + vec3 m_orientation; //!< Display orientation ==> speed does not generate the orientation. + uint32_t m_uniqueId; //!< General element ID (uint16_t, because all is reference with the groupId like this only a uint32_t reference an element) + uint32_t m_groupId; //!< General group Id More than 65000 group can be really interesting to create supid game ... + int32_t m_type; //!< type of this element + bool m_visible; //!< This is to know if the element is displayed or not ==> TODO : check if usefull ... + float m_mass; //!< Current element Mass ==> for the physical calculation + public: + /** + * @brief Basic constructor. + */ + Element(void); + /** + * @brief Basic destructor. + */ + ~Element(void); + + }; +}; + + +#endif diff --git a/sources/ewol/game/Engine.cpp b/sources/ewol/game/Engine.cpp new file mode 100644 index 00000000..1e94d10f --- /dev/null +++ b/sources/ewol/game/Engine.cpp @@ -0,0 +1,34 @@ +/** + * @author Edouard DUPIN + * + * @copyright 2011, Edouard DUPIN, all right reserved + * + * @license BSD v3 (see license file) + */ + + + +#include + + + + +game::Engine::Engine(void) +{ + +} + +game::Engine::~Engine(void) +{ + +} + +void game::Engine::Process(int64_t lastTime, int32_t deltaTime) +{ + +} + +void game::Engine::Draw(void) +{ + +} diff --git a/sources/ewol/game/Engine.h b/sources/ewol/game/Engine.h new file mode 100644 index 00000000..9759397d --- /dev/null +++ b/sources/ewol/game/Engine.h @@ -0,0 +1,49 @@ +/** + * @author Edouard DUPIN + * + * @copyright 2011, Edouard DUPIN, all right reserved + * + * @license BSD v3 (see license file) + */ + +#ifndef __GAME_ENGINE_H__ +#define __GAME_ENGINE_H__ + + +#include +#include + +namespace game +{ + class Engine + { + private: + //game::Map* m_map; //!< basic system map (BSD or other ...) + etk::Vector m_elementsStatic; + etk::Vector m_elementsDynamic; + public: + /** + * @brief Basic constructor. + */ + Engine(void); + /** + * @brief Basic destructor. + */ + ~Engine(void); + + /** + * @brief periodic call for processing. + * @param[in] lastTime Previous call time (if the system is in pause this time does restart at the same time the next time. + * @param[in] deltaTime delta time in µs from the previous call. + */ + void Process(int64_t lastTime, int32_t deltaTime); + /** + * @brief Display the environement. + */ + void Draw(void); + }; +}; + + +#endif + diff --git a/sources/ewol/game/GameElement.h b/sources/ewol/game/GameElement.h index b681a766..3fa8c9d4 100644 --- a/sources/ewol/game/GameElement.h +++ b/sources/ewol/game/GameElement.h @@ -33,7 +33,7 @@ namespace ewol { int32_t m_type; //!< float m_power; //!< Current power of the element bool m_visible; //!< This is to know if the element is displayed or not ==> TODO : check if usefull ... - vec2 m_position; //!< Current position of the element + vec2 m_position; //!< Current position of the element float m_speed; //!< Speed of the element (only one value, the angle is generated by the m_angle float m_angle; //!< Angle of the speed float m_mass; //!< Current element Mass ==> for the physical calculation diff --git a/sources/ewol/renderer/openGL.h b/sources/ewol/renderer/openGL.h index 960da845..6268cb33 100644 --- a/sources/ewol/renderer/openGL.h +++ b/sources/ewol/renderer/openGL.h @@ -40,7 +40,8 @@ extern "C" { #define GLEW_STATIC #include #elif defined(__TARGET_OS__MacOs) - + #include + #include #elif defined(__TARGET_OS__IOs) #else diff --git a/sources/ewol/renderer/os/eSystem.cpp b/sources/ewol/renderer/os/eSystem.cpp index 8a611c5b..b02efba7 100644 --- a/sources/ewol/renderer/os/eSystem.cpp +++ b/sources/ewol/renderer/os/eSystem.cpp @@ -444,9 +444,21 @@ static ewol::Fps l_FpsSystemEvent( "Event ", false); static ewol::Fps l_FpsSystemContext( "Context ", false); static ewol::Fps l_FpsSystem( "Draw ", true); +// this is to limit framerate ... in case... +static int64_t previousDisplayTime = 0; + + + bool eSystem::Draw(bool displayEveryTime) { int64_t currentTime = ewol::GetTime(); + // this is to prevent the multiple display at the a high frequency ... + if(currentTime - previousDisplayTime < 1000000/120) { + usleep(1000); + return false; + } + previousDisplayTime = currentTime; + if (true == isGlobalSystemInit) { // process the events l_FpsSystemEvent.Tic(); @@ -474,19 +486,21 @@ bool eSystem::Draw(bool displayEveryTime) } } l_FpsSystemContext.Toc(); - + bool hasDisplayDone = false; l_FpsSystem.Tic(); if (NULL != tmpWindows) { if( true == needRedraw || true == displayEveryTime) { l_FpsSystem.IncrementCounter(); tmpWindows->SysDraw(); + hasDisplayDone = true; } } l_FpsSystem.Toc(); glFlush(); + return hasDisplayDone; } - return true; + return false; } diff --git a/sources/ewol/renderer/os/gui.X11.cpp b/sources/ewol/renderer/os/gui.X11.cpp index 6e376b51..6d738450 100644 --- a/sources/ewol/renderer/os/gui.X11.cpp +++ b/sources/ewol/renderer/os/gui.X11.cpp @@ -419,6 +419,7 @@ void X11_Init(void) #endif if (m_doubleBuffered) { glXSwapBuffers(m_display, WindowHandle); + XSync (m_display,0); } m_visual = NULL; m_previousBouttonId = 0; @@ -938,9 +939,10 @@ void X11_Run(void) } } if(true == m_run) { - (void)eSystem::Draw(false); - if (m_doubleBuffered) { + bool hasDisplay = eSystem::Draw(false); + if (m_doubleBuffered && hasDisplay) { glXSwapBuffers(m_display, WindowHandle); + XSync(m_display,0); } } #ifdef DEBUG_X11_EVENT diff --git a/sources/ewol/widget/Scene.cpp b/sources/ewol/widget/Scene.cpp index aeebbb5d..e3d31db0 100644 --- a/sources/ewol/widget/Scene.cpp +++ b/sources/ewol/widget/Scene.cpp @@ -8,20 +8,19 @@ #include #include - -#include -#include -#include +#include +#include #undef __class__ #define __class__ "Scene" -widget::Scene::Scene(void) +widget::Scene::Scene(ewol::GameEngine* gameEngine) : + m_gameEngine(gameEngine), + m_isRunning(true), + m_lastCallTime(-1) { - m_isRunning = true; SetCanHaveFocus(true); PeriodicCallSet(true); - m_lastCallTime = -1; m_zoom = 1.0; } @@ -35,6 +34,7 @@ widget::Scene::~Scene(void) void widget::Scene::OnRegenerateDisplay(void) { if (true == NeedRedraw()) { + /* // clean elements for (int32_t iii=0; iiiDraw(); } } + */ } @@ -90,6 +110,10 @@ void widget::Scene::PeriodicCall(int64_t localTime) } // cut the processing in small slot of time to prevent error in the real-time Display (Android call us between 30 to 60 fps) int32_t deltaTime = (int32_t) (localTime - m_lastCallTime); + if (NULL != m_gameEngine) { + m_gameEngine->Process(m_lastCallTime, deltaTime); + } + /* //EWOL_DEBUG(" currentTime = " << localTime << " last=" << m_lastCallTime << " delta=" << deltaTime); while (deltaTime >= CYCLIC_CALL_PERIODE_US) { //EWOL_DEBUG(" process = " << CYCLIC_CALL_PERIODE_US); @@ -110,13 +134,13 @@ void widget::Scene::PeriodicCall(int64_t localTime) } } } + */ MarkToRedraw(); } -void widget::Scene::GenDraw(DrawProperty displayProp) +void widget::Scene::GenDraw(ewol::DrawProperty displayProp) { - ewol::openGL::Push(); // here we invert the reference of the standard OpenGl view because the reference in the common display is Top left and not buttom left glViewport( m_origin.x, @@ -129,12 +153,12 @@ void widget::Scene::GenDraw(DrawProperty displayProp) mat4 tmpProjection; if (ratio >= 1.0) { - tmpProjection = etk::matrix::Perspective(-ratio, ratio, -1, 1, -1, 1); + tmpProjection = etk::Matrix4::Perspective(-ratio, ratio, -1, 1, -1, 1); } else { ratio = 1.0/ratio; - tmpProjection = etk::matrix::Perspective(-1, 1, -ratio, ratio, -1, 1); + tmpProjection = etk::Matrix4::Perspective(-1, 1, -ratio, ratio, -1, 1); } - mat4 tmpScale = etk::matrix::Scale(m_zoom, m_zoom, m_zoom); + mat4 tmpScale = etk::Matrix4::Scale(vec3(m_zoom, m_zoom, m_zoom) ); mat4 tmpMat = tmpProjection * tmpScale; // set internal matrix system : ewol::openGL::SetMatrix(tmpMat); diff --git a/sources/ewol/widget/Scene.h b/sources/ewol/widget/Scene.h index 46780463..dc92ccdc 100644 --- a/sources/ewol/widget/Scene.h +++ b/sources/ewol/widget/Scene.h @@ -10,73 +10,63 @@ #define __EWOL_SCENE_H__ #include +#include #include -#include -#include -#include +#include +#include namespace widget { class Scene :public ewol::Widget { - // TODO : Set it in private ... protected: - SceneElement m_sceneElement; //!< all element neede in the scene - bool m_isRunning; - int64_t m_lastCallTime; + game::Engine* m_gameEngine; //!< display engine system + bool m_isRunning; //!< the display is running (not in pause) + int64_t m_lastCallTime; //!< previous call Time public: - Scene(void); + /** + * @brief Main scene constructor + * @param[in] gameEngine Used game engine for the display (can be NULL). + */ + Scene(ewol::GameEngine* gameEngine=NULL); + /** + * @brief Destructor + * @note The engine is not destroy, it is the reponsability of the user + */ virtual ~Scene(void); - // Derived function - virtual const char * const GetObjectType(void) { return "EwolScene"; }; - // Derived function - virtual void OnRegenerateDisplay(void); - // Derived function - virtual void PeriodicCall(int64_t localTime); - // Derived function - virtual void OnDraw(ewol::DrawProperty& displayProp); /** * @brief Set the scene in pause for a while - * @param --- - * @return --- */ - void Pause(void) { m_isRunning = false; }; + void Pause(void); /** * @brief Resume the scene activity - * @param --- - * @return --- */ - void Resume(void) { m_isRunning = true; }; + void Resume(void); /** * @brief Toggle between pause and running - * @param --- - * @return --- */ - void PauseToggle(void) { if(true==m_isRunning){ m_isRunning=false;}else{m_isRunning=true;} }; + void PauseToggle(void); /** * @brief extern interface to request a draw ... (called by the drawing thread [Android, X11, ...]) * This function generate a clipping with the viewport openGL system. Like this a widget draw can not draw over an other widget * @note This function is virtual for the scrolled widget, and the more complicated OpenGl widget - * @param --- - * @return --- */ - virtual void GenDraw(DrawProperty displayProp); + virtual void GenDraw(ewol::DrawProperty displayProp); protected: /** * @brief Periodic call in the sub element timed * @param localTime curent system time * @param deltaTime delta time while the previous call - * @return --- */ virtual void ScenePeriodicCall(int64_t localTime, int32_t deltaTime) { }; // camera properties : private: - vec3 m_camRotation; - vec3 m_camTranslation; - float m_camAngleView; - float m_camdistanceViewStart; - float m_camdistanceViewStop; - float m_zoom; + vec3 m_camRotation; + vec3 m_camTranslation; + float m_camAngleView; + float m_camdistanceViewStart; + float m_camdistanceViewStop; + float m_zoom; public: void SetCamaraTranslation(); void SetCamaraRotation(); @@ -88,7 +78,16 @@ namespace widget { * @param[in] pos Absolute position that you request convertion * @return the relative position */ - virtual vec2 RelativePosition(vec2 pos); + virtual vec2 RelativePosition(vec2 pos); + + // Derived function + virtual const char * const GetObjectType(void) { return "Ewol::Scene"; }; + // Derived function + virtual void OnRegenerateDisplay(void); + // Derived function + virtual void PeriodicCall(int64_t localTime); + // Derived function + virtual void OnDraw(ewol::DrawProperty& displayProp); }; }; diff --git a/sources/file.mk b/sources/file.mk index aae0ac0d..3b6c2118 100644 --- a/sources/file.mk +++ b/sources/file.mk @@ -78,9 +78,10 @@ FILE_LIST+= ewol/widget/Widget.cpp \ ewol/widget/meta/Parameter.cpp \ ewol/widget/meta/ParameterList.cpp +# game mode area : +FILE_LIST+= ewol/widget/Scene.cpp \ + ewol/game/GameEngine.cpp -OLD_WIDGET = \ - ewol/widget/Scene.cpp \ LOCAL_COPY_FILES := ../data/textured3D.prog:textured3D.prog \ ../data/textured3D.frag:textured3D.frag \