162 lines
5.6 KiB
C++
162 lines
5.6 KiB
C++
|
|
#ifndef ENGINE_H
|
|
#define ENGINE_H
|
|
|
|
#include <string>
|
|
#include <lua.hpp>
|
|
#include <map>
|
|
#include <SDL.h>
|
|
#include "OdeWorld/OdeWorld.h"
|
|
#include "TextureCache/TextureCache.h"
|
|
#include "wfobj/WFObj.h"
|
|
|
|
class Engine
|
|
{
|
|
public:
|
|
class Object
|
|
{
|
|
public:
|
|
Object(bool is_static, OdeWorld & world, GLuint dl,
|
|
float scale = 1.0f);
|
|
Object(const Object & orig);
|
|
~Object();
|
|
|
|
void setPosition(double x, double y, double z)
|
|
{
|
|
m_ode_object->setPosition(x, y, z);
|
|
}
|
|
void getPosition(double * x, double * y, double * z)
|
|
{
|
|
m_ode_object->getPosition(x, y, z);
|
|
}
|
|
void loadPhy(const std::string & path)
|
|
{
|
|
m_ode_object->loadPhy(path);
|
|
}
|
|
void setVisible(bool visible) { m_is_visible = visible; }
|
|
bool getVisible() { return m_is_visible; }
|
|
void addForce(dReal fx, dReal fy, dReal fz)
|
|
{
|
|
m_ode_object->addForce(fx, fy, fz);
|
|
}
|
|
void addRelForce(dReal fx, dReal fy, dReal fz)
|
|
{
|
|
m_ode_object->addRelForce(fx, fy, fz);
|
|
}
|
|
void addTorque(dReal fx, dReal fy, dReal fz)
|
|
{
|
|
m_ode_object->addTorque(fx, fy, fz);
|
|
}
|
|
void addRelTorque(dReal fx, dReal fy, dReal fz)
|
|
{
|
|
m_ode_object->addRelTorque(fx, fy, fz);
|
|
}
|
|
void setRotation(dReal x, dReal y, dReal z)
|
|
{
|
|
m_ode_object->setRotation(x, y, z);
|
|
}
|
|
|
|
void draw();
|
|
|
|
protected:
|
|
OdeWorld::Object * m_ode_object;
|
|
GLuint m_display_list;
|
|
int * m_display_list_refcnt;
|
|
bool m_is_visible;
|
|
float m_scale;
|
|
bool m_is_scaled;
|
|
};
|
|
|
|
class EngineFileLoader : public FileLoader
|
|
{
|
|
public:
|
|
EngineFileLoader(Engine * engine);
|
|
virtual int getSize(const Path & path);
|
|
virtual Buffer load(const Path & path);
|
|
protected:
|
|
std::string resolvePath(const Path & path);
|
|
Engine * m_engine;
|
|
};
|
|
|
|
Engine(const std::string & path);
|
|
~Engine();
|
|
|
|
std::string locateResource(const std::string & shortname);
|
|
bool load(const char * program);
|
|
void run();
|
|
void reportErrors(int status);
|
|
OdeWorld & getWorld() { return m_world; }
|
|
int addObject(WFObj * obj, bool is_static, float scale = 1.0f);
|
|
void removeObject(int id);
|
|
int cloneObject(const Object * obj);
|
|
Object * getObject(int id);
|
|
void doPhysics();
|
|
void drawObjects();
|
|
void setAutoPhysics(bool val) { m_autoPhysics = val; }
|
|
bool getAutoPhysics() { return m_autoPhysics; }
|
|
void setAutoStartFrame(bool val) { m_autoStartFrame = val; }
|
|
bool getAutoStartFrame() { return m_autoStartFrame; }
|
|
void setAutoEndFrame(bool val) { m_autoEndFrame = val; }
|
|
bool getAutoEndFrame() { return m_autoEndFrame; }
|
|
void setAutoDrawObjects(bool val) { m_autoDrawObjects = val; }
|
|
bool getAutoDrawObjects() { return m_autoDrawObjects; }
|
|
void startFrame();
|
|
void endFrame();
|
|
int loadModel(const std::string & name, bool static_data,
|
|
float scale = 1.0f);
|
|
bool isKeyDown(const std::string & key);
|
|
|
|
/* lua services */
|
|
int setCamera(lua_State * L);
|
|
|
|
protected:
|
|
static Uint32 updateCallback(Uint32 interval, void * param);
|
|
static SDL_Event userEvent;
|
|
|
|
Uint32 updateCallback(Uint32 interval);
|
|
void registerLibraries();
|
|
bool fileExists(const std::string & path);
|
|
void update_event();
|
|
void key_pressed_event(int keysym);
|
|
void key_released_event(int keysym);
|
|
void mousebutton_pressed_event(int button, int x, int y);
|
|
void mousebutton_released_event(int button, int x, int y);
|
|
void mouse_motion_event(int x, int y, int xrel, int yrel);
|
|
Object * createObject(bool is_static, GLuint display_list,
|
|
float scale = 1.0f)
|
|
{
|
|
return new Object(is_static, m_world, display_list, scale);
|
|
}
|
|
void checkForFunctionFull(const std::string & lua_fn_name,
|
|
const std::string & event_name, bool & presentFlag);
|
|
|
|
TextureCache m_textureCache;
|
|
EngineFileLoader * m_fileLoader;
|
|
lua_State * m_luaState;
|
|
std::string m_program_path;
|
|
std::string m_engine_path;
|
|
OdeWorld m_world;
|
|
std::map<int, Object *> m_objects;
|
|
int m_next_object_index;
|
|
GLdouble m_eye[3];
|
|
GLdouble m_center[3];
|
|
GLdouble m_up[3];
|
|
bool m_drawing;
|
|
bool m_autoPhysics;
|
|
bool m_autoStartFrame;
|
|
bool m_autoEndFrame;
|
|
bool m_autoDrawObjects;
|
|
std::map<std::string, bool> m_keysDown;
|
|
|
|
bool m_event_update_present;
|
|
bool m_event_key_pressed_present;
|
|
bool m_event_key_released_present;
|
|
bool m_event_mousebutton_pressed_present;
|
|
bool m_event_mousebutton_released_present;
|
|
bool m_event_mouse_motion_present;
|
|
};
|
|
|
|
extern Engine * g_engine;
|
|
|
|
#endif
|