[DEV] First rework of the scene system
This commit is contained in:
parent
160fd67d03
commit
d56017aacf
3
.gitmodules
vendored
3
.gitmodules
vendored
@ -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
|
||||
|
@ -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
|
||||
|
2
external/etk
vendored
2
external/etk
vendored
@ -1 +1 @@
|
||||
Subproject commit 1d4c27e7fd68cb9cbf11a89068c4b1d10744555c
|
||||
Subproject commit 033c9dd63a75db8afb448760cdb59bc8f89d5e7a
|
1
external/ode
vendored
Submodule
1
external/ode
vendored
Submodule
@ -0,0 +1 @@
|
||||
Subproject commit 7e4c9495b4688c4387402897922f0e258338a9ec
|
@ -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 :=
|
||||
|
||||
|
33
sources/ewol/game/Element.cpp
Normal file
33
sources/ewol/game/Element.cpp
Normal file
@ -0,0 +1,33 @@
|
||||
/**
|
||||
* @author Edouard DUPIN
|
||||
*
|
||||
* @copyright 2011, Edouard DUPIN, all right reserved
|
||||
*
|
||||
* @license BSD v3 (see license file)
|
||||
*/
|
||||
|
||||
|
||||
|
||||
#include <ewol/game/Element.h>
|
||||
|
||||
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)
|
||||
{
|
||||
|
||||
}
|
||||
|
45
sources/ewol/game/Element.h
Normal file
45
sources/ewol/game/Element.h
Normal file
@ -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 <etk/types.h>
|
||||
#include <ewol/debug.h>
|
||||
|
||||
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
|
34
sources/ewol/game/Engine.cpp
Normal file
34
sources/ewol/game/Engine.cpp
Normal file
@ -0,0 +1,34 @@
|
||||
/**
|
||||
* @author Edouard DUPIN
|
||||
*
|
||||
* @copyright 2011, Edouard DUPIN, all right reserved
|
||||
*
|
||||
* @license BSD v3 (see license file)
|
||||
*/
|
||||
|
||||
|
||||
|
||||
#include <ewol/game/Engine.h>
|
||||
|
||||
|
||||
|
||||
|
||||
game::Engine::Engine(void)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
game::Engine::~Engine(void)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void game::Engine::Process(int64_t lastTime, int32_t deltaTime)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void game::Engine::Draw(void)
|
||||
{
|
||||
|
||||
}
|
49
sources/ewol/game/Engine.h
Normal file
49
sources/ewol/game/Engine.h
Normal file
@ -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 <etk/types.h>
|
||||
#include <ewol/debug.h>
|
||||
|
||||
namespace game
|
||||
{
|
||||
class Engine
|
||||
{
|
||||
private:
|
||||
//game::Map* m_map; //!< basic system map (BSD or other ...)
|
||||
etk::Vector<game::Element*> m_elementsStatic;
|
||||
etk::Vector<game::Element*> 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
|
||||
|
@ -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
|
||||
|
@ -40,7 +40,8 @@ extern "C" {
|
||||
#define GLEW_STATIC
|
||||
#include <GL/glew.h>
|
||||
#elif defined(__TARGET_OS__MacOs)
|
||||
|
||||
#include <OpenGL/gl.h>
|
||||
#include <OpenGL/glu.h>
|
||||
#elif defined(__TARGET_OS__IOs)
|
||||
|
||||
#else
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
|
||||
|
@ -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
|
||||
|
@ -8,20 +8,19 @@
|
||||
|
||||
#include <ewol/widget/Scene.h>
|
||||
#include <math.h>
|
||||
|
||||
#include <ewol/oObject/OObject.h>
|
||||
#include <ewol/widget/WidgetManager.h>
|
||||
#include <ewol/openGL/openGL.h>
|
||||
#include <ewol/renderer/openGL.h>
|
||||
#include <etk/math/Matrix4.h>
|
||||
|
||||
#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; iii<m_sceneElement.animated.Size(); iii++) {
|
||||
if (NULL != m_sceneElement.animated[iii]) {
|
||||
@ -49,17 +49,36 @@ void widget::Scene::OnRegenerateDisplay(void)
|
||||
}
|
||||
}
|
||||
}
|
||||
*/
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Common widget drawing function (called by the drawing thread [Android, X11, ...])
|
||||
* @param ---
|
||||
* @return ---
|
||||
*/
|
||||
//TODO : Il y a un bug : seg fault ... je ne sais pas trop ou ...
|
||||
|
||||
void widget::Scene::Pause(void)
|
||||
{
|
||||
m_isRunning = false;
|
||||
}
|
||||
|
||||
|
||||
void widget::Scene::Resume(void)
|
||||
{
|
||||
m_isRunning = true;
|
||||
}
|
||||
|
||||
|
||||
void widget::Scene::PauseToggle(void)
|
||||
{
|
||||
if(true==m_isRunning) {
|
||||
m_isRunning=false;
|
||||
} else {
|
||||
m_isRunning=true;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void widget::Scene::OnDraw(ewol::DrawProperty& displayProp)
|
||||
{
|
||||
/*
|
||||
//EWOL_ERROR(" On draw : " << m_currentDrawId);
|
||||
// draw background :
|
||||
// TODO : ...
|
||||
@ -73,6 +92,7 @@ void widget::Scene::OnDraw(ewol::DrawProperty& displayProp)
|
||||
m_sceneElement.animated[iii]->Draw();
|
||||
}
|
||||
}
|
||||
*/
|
||||
}
|
||||
|
||||
|
||||
@ -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);
|
||||
|
@ -10,73 +10,63 @@
|
||||
#define __EWOL_SCENE_H__
|
||||
|
||||
#include <etk/types.h>
|
||||
#include <etk/math/Vector3D.h>
|
||||
#include <ewol/debug.h>
|
||||
#include <ewol/widget/WidgetScrolled.h>
|
||||
#include <ewol/oObject/Sprite.h>
|
||||
#include <ewol/game/GameElement.h>
|
||||
#include <ewol/game/Engine.h>
|
||||
#include <ewol/widget/Widget.h>
|
||||
|
||||
|
||||
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);
|
||||
};
|
||||
};
|
||||
|
||||
|
@ -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 \
|
||||
|
Loading…
x
Reference in New Issue
Block a user