compiling again after refactoring SDL calls out of Engine into anaglym.cc!
git-svn-id: svn://anubis/anaglym/trunk@78 99a6e188-d820-4881-8870-2d33a10e2619
This commit is contained in:
parent
38a517174b
commit
a630609767
70
Engine.cc
70
Engine.cc
@ -1,7 +1,7 @@
|
||||
|
||||
#include "ag.h"
|
||||
#include "Video.h"
|
||||
#include "Engine.h"
|
||||
#include "anaglym.h"
|
||||
#include <lua.hpp>
|
||||
#include <stdlib.h> /* exit() */
|
||||
#include <sys/types.h>
|
||||
@ -16,11 +16,8 @@ using namespace std;
|
||||
|
||||
Engine * g_engine;
|
||||
|
||||
SDL_Event Engine::userEvent;
|
||||
|
||||
Engine::Engine(const string & path)
|
||||
{
|
||||
m_video = new Video();
|
||||
m_next_object_index = 1;
|
||||
m_eye[0] = 0;
|
||||
m_eye[1] = -1;
|
||||
@ -36,21 +33,10 @@ Engine::Engine(const string & path)
|
||||
|
||||
size_t pos = path.find_last_of("\\/");
|
||||
m_engine_path = (pos != string::npos) ? string(path, 0, pos) : ".";
|
||||
|
||||
/* setup redraw SDL event structure */
|
||||
userEvent.type = SDL_USEREVENT;
|
||||
userEvent.user.code = 0;
|
||||
#if 0
|
||||
/* start in windowed mode for debugging */
|
||||
m_video->start(0, 0, false, false);
|
||||
#else
|
||||
m_video->start();
|
||||
#endif
|
||||
}
|
||||
|
||||
Engine::~Engine()
|
||||
{
|
||||
m_video->stop();
|
||||
lua_close(m_luaState);
|
||||
for (std::map<int, Object *>::iterator it = m_objects.begin();
|
||||
it != m_objects.end();
|
||||
@ -58,7 +44,6 @@ Engine::~Engine()
|
||||
{
|
||||
delete it->second;
|
||||
}
|
||||
delete m_video;
|
||||
}
|
||||
|
||||
bool Engine::load(const char * program)
|
||||
@ -188,7 +173,7 @@ int Engine::startFrame(lua_State * L)
|
||||
|
||||
int Engine::endFrame(lua_State * L)
|
||||
{
|
||||
SDL_GL_SwapBuffers();
|
||||
/* TODO: figure out how to SDL_GL_SwapBuffers(); */
|
||||
return 0;
|
||||
}
|
||||
|
||||
@ -228,55 +213,6 @@ int Engine::setCamera(lua_State * L)
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* called by SDL when the update timer expires */
|
||||
Uint32 Engine::updateCallback(Uint32 interval, void * param)
|
||||
{
|
||||
Engine * engine = (Engine *) param;
|
||||
return engine->updateCallback(interval);
|
||||
}
|
||||
|
||||
/* member update function to be called by our registered
|
||||
* SDL callback non-member function */
|
||||
Uint32 Engine::updateCallback(Uint32 interval)
|
||||
{
|
||||
if (!m_drawing)
|
||||
{
|
||||
SDL_PushEvent(&userEvent);
|
||||
}
|
||||
return interval;
|
||||
}
|
||||
|
||||
void Engine::run()
|
||||
{
|
||||
/* register a screen redrawing SDL event */
|
||||
SDL_AddTimer(25, &updateCallback, this);
|
||||
|
||||
SDL_Event event;
|
||||
while (SDL_WaitEvent(&event))
|
||||
{
|
||||
switch (event.type)
|
||||
{
|
||||
case SDL_KEYDOWN:
|
||||
if (event.key.keysym.sym == SDLK_ESCAPE)
|
||||
{
|
||||
goto RET;
|
||||
}
|
||||
break;
|
||||
case SDL_QUIT:
|
||||
goto RET;
|
||||
break;
|
||||
case SDL_USEREVENT:
|
||||
if (event.user.code == 0)
|
||||
{
|
||||
update();
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
RET:
|
||||
;
|
||||
}
|
||||
|
||||
void Engine::update()
|
||||
{
|
||||
m_drawing = true;
|
||||
@ -299,7 +235,7 @@ void Engine::update()
|
||||
void Engine::doPhysics()
|
||||
{
|
||||
static Uint32 last_updated = 0;
|
||||
Uint32 current_ticks = SDL_GetTicks();
|
||||
Uint32 current_ticks = GetTicks();
|
||||
if (last_updated > 0)
|
||||
{
|
||||
Uint32 msec_steps = current_ticks - last_updated;
|
||||
|
8
Engine.h
8
Engine.h
@ -5,7 +5,6 @@
|
||||
#include <string>
|
||||
#include <lua.hpp>
|
||||
#include <map>
|
||||
#include "Video.h"
|
||||
#include "OdeWorld/OdeWorld.h"
|
||||
#include "wfobj/WFObj.hh"
|
||||
|
||||
@ -50,9 +49,7 @@ class Engine
|
||||
~Engine();
|
||||
|
||||
std::string locateResource(const std::string & shortname);
|
||||
Video * getVideo() { return m_video; }
|
||||
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);
|
||||
@ -70,10 +67,6 @@ class Engine
|
||||
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();
|
||||
@ -84,7 +77,6 @@ class Engine
|
||||
}
|
||||
|
||||
lua_State * m_luaState;
|
||||
Video * m_video;
|
||||
std::string m_program_path;
|
||||
std::string m_engine_path;
|
||||
OdeWorld m_world;
|
||||
|
66
anaglym.cc
66
anaglym.cc
@ -9,6 +9,12 @@
|
||||
using namespace std;
|
||||
|
||||
static void usage();
|
||||
static void mainloop();
|
||||
static Uint32 updateCallback(Uint32 interval, void * param);
|
||||
|
||||
static bool lastDrawCompleted;
|
||||
static SDL_Event userEvent;
|
||||
Uint32 g_ticks;
|
||||
|
||||
static void usage()
|
||||
{
|
||||
@ -46,10 +52,68 @@ int main(int argc, char * argv[])
|
||||
usage();
|
||||
}
|
||||
|
||||
lastDrawCompleted = true;
|
||||
/* setup SDL update event */
|
||||
userEvent.type = SDL_USEREVENT;
|
||||
userEvent.user.code = 0;
|
||||
|
||||
Video video;
|
||||
#if 0
|
||||
/* start in windowed mode for debugging */
|
||||
video.start(0, 0, false, false);
|
||||
#else
|
||||
video.start();
|
||||
#endif
|
||||
|
||||
g_engine = new Engine(argv[0]);
|
||||
if (g_engine->load(program))
|
||||
g_engine->run();
|
||||
{
|
||||
mainloop();
|
||||
}
|
||||
delete g_engine;
|
||||
|
||||
video.stop();
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* called by SDL when the update timer expires */
|
||||
static Uint32 updateCallback(Uint32 interval, void * param)
|
||||
{
|
||||
if (lastDrawCompleted)
|
||||
SDL_PushEvent(&userEvent);
|
||||
return interval;
|
||||
}
|
||||
|
||||
static void mainloop()
|
||||
{
|
||||
SDL_Event event;
|
||||
|
||||
/* register a screen redrawing SDL event */
|
||||
SDL_AddTimer(25, &updateCallback, NULL);
|
||||
|
||||
while (SDL_WaitEvent(&event))
|
||||
{
|
||||
switch (event.type)
|
||||
{
|
||||
case SDL_KEYDOWN:
|
||||
if (event.key.keysym.sym == SDLK_ESCAPE)
|
||||
{
|
||||
goto RET;
|
||||
}
|
||||
break;
|
||||
case SDL_QUIT:
|
||||
goto RET;
|
||||
break;
|
||||
case SDL_USEREVENT:
|
||||
if (event.user.code == 0)
|
||||
{
|
||||
/* TODO: update */
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
RET:
|
||||
;
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user