added an "auto physics" mode, on by default, that will call doPhysics() before update() if on, settable via ag::setAutoPhysics()

git-svn-id: svn://anubis/anaglym/trunk@71 99a6e188-d820-4881-8870-2d33a10e2619
This commit is contained in:
Josh Holtrop 2009-10-12 19:48:58 +00:00
parent 3f407b8970
commit c4f07c6c93
5 changed files with 23 additions and 1 deletions

16
ag.cc
View File

@ -31,6 +31,7 @@ namespace ag
{ "elapsedTime", elapsedTime },
{ "doPhysics", doPhysics },
{ "drawObjects", drawObjects },
{ "setAutoPhysics", setAutoPhysics },
{ NULL, NULL }
};
luaL_register(L, "ag", functions);
@ -225,6 +226,21 @@ namespace ag
return 0;
}
int setAutoPhysics(lua_State * L)
{
int argc = lua_gettop(L);
if (argc == 1)
{
if (lua_isboolean(L, 1))
{
g_engine->setAutoPhysics(lua_toboolean(L, 1));
}
}
return 0;
}
namespace object
{
static Engine::Object * getObject(lua_State * L, int index)

1
ag.h
View File

@ -18,6 +18,7 @@ namespace ag
int elapsedTime(lua_State * L);
int doPhysics(lua_State * L);
int drawObjects(lua_State * L);
int setAutoPhysics(lua_State * L);
namespace object
{

View File

@ -90,6 +90,7 @@ Engine::Engine()
m_up[1] = 0;
m_up[2] = 1;
m_drawing = false;
m_autoPhysics = true;
/* setup redraw SDL event structure */
userEvent.type = SDL_USEREVENT;
@ -334,6 +335,8 @@ RET:
void Engine::update()
{
m_drawing = true;
if (m_autoPhysics)
doPhysics();
lua_getfield(m_luaState, LUA_GLOBALSINDEX, "update");
if (lua_type(m_luaState, -1) == LUA_TFUNCTION)
{

View File

@ -60,6 +60,8 @@ class Engine
Object * getObject(int id);
void doPhysics();
void drawObjects();
void setAutoPhysics(bool autoPhysics) { m_autoPhysics = autoPhysics; }
bool getAutoPhysics() { return m_autoPhysics; }
/* lua services */
int startFrame(lua_State * L);
@ -89,6 +91,7 @@ class Engine
GLdouble m_center[3];
GLdouble m_up[3];
bool m_drawing;
bool m_autoPhysics;
};
extern Engine * g_engine;

View File

@ -2,7 +2,6 @@
function update()
ballx, bally, ballz = ball:getPosition()
ag.setCamera(7, -6, 15, ballx, bally, ballz, 0, 0, 1)
ag.doPhysics()
ag.startFrame()
ag.drawObjects()
ag.endFrame()