added ag::drawObjects() to draw all objects in the scene from a lua script

git-svn-id: svn://anubis/anaglym/trunk@65 99a6e188-d820-4881-8870-2d33a10e2619
This commit is contained in:
Josh Holtrop 2009-10-12 14:54:40 +00:00
parent 2107a67d08
commit bd2d3d8b25
5 changed files with 19 additions and 5 deletions

7
ag.cc
View File

@ -30,6 +30,7 @@ namespace ag
{ "setCamera", setCamera }, { "setCamera", setCamera },
{ "elapsedTime", elapsedTime }, { "elapsedTime", elapsedTime },
{ "doPhysics", doPhysics }, { "doPhysics", doPhysics },
{ "drawObjects", drawObjects },
{ NULL, NULL } { NULL, NULL }
}; };
luaL_register(L, "ag", functions); luaL_register(L, "ag", functions);
@ -214,6 +215,12 @@ namespace ag
return 0; return 0;
} }
int drawObjects(lua_State * L)
{
g_engine->drawObjects();
return 0;
}
namespace object namespace object
{ {
static Engine::Object * getObject(lua_State * L, int index) static Engine::Object * getObject(lua_State * L, int index)

1
ag.h
View File

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

View File

@ -334,6 +334,15 @@ void Engine::doPhysics()
last_updated = current_ticks; last_updated = current_ticks;
} }
void Engine::drawObjects()
{
std::map<int, Object *>::iterator it;
for (it = m_objects.begin(); it != m_objects.end(); it++)
{
it->second->draw();
}
}
Engine::Object::Object(const Engine::Object & orig) Engine::Object::Object(const Engine::Object & orig)
{ {
m_display_list = orig.m_display_list; m_display_list = orig.m_display_list;

View File

@ -61,6 +61,7 @@ class Engine
int cloneObject(const Object * obj); int cloneObject(const Object * obj);
Object * getObject(int id); Object * getObject(int id);
void doPhysics(); void doPhysics();
void drawObjects();
/* lua services */ /* lua services */
int startFrame(lua_State * L); int startFrame(lua_State * L);

View File

@ -4,11 +4,7 @@ function update()
ag.setCamera(7, -6, 15, ballx, bally, ballz, 0, 0, 1) ag.setCamera(7, -6, 15, ballx, bally, ballz, 0, 0, 1)
ag.doPhysics() ag.doPhysics()
ag.startFrame() ag.startFrame()
arena:draw() ag.drawObjects()
ball:draw()
ball2:draw()
ball3:draw()
logo:draw()
ag.endFrame() ag.endFrame()
end end