From e7d5e6eed11d56e0e1e4e9ae504a26b229af8110 Mon Sep 17 00:00:00 2001 From: Josh Holtrop Date: Wed, 14 Oct 2009 02:44:45 +0000 Subject: [PATCH] supposed to be swapping buffers now but only getting a black screen... not a good sign git-svn-id: svn://anubis/anaglym/trunk@82 99a6e188-d820-4881-8870-2d33a10e2619 --- Engine.cc | 3 +-- anaglym.cc | 27 +++++++++++++++++++++------ tests/ballstairs.lua | 2 -- 3 files changed, 22 insertions(+), 10 deletions(-) diff --git a/Engine.cc b/Engine.cc index f49ab4f..4cdaaec 100644 --- a/Engine.cc +++ b/Engine.cc @@ -176,8 +176,7 @@ int Engine::setCamera(lua_State * L) vector args; for (int i = 1; i <= argc; i++) { - int type = lua_type(L, i); - if (type == LUA_TNUMBER || type == LUA_TSTRING) + if (lua_isnumber(L, i)) args.push_back(lua_tonumber(L, i)); else args.push_back(0); diff --git a/anaglym.cc b/anaglym.cc index 2cdc814..c03db9a 100644 --- a/anaglym.cc +++ b/anaglym.cc @@ -7,6 +7,8 @@ #include #include #include +#include +#include using namespace std; enum EventType { EVENT_UPDATE }; @@ -28,6 +30,7 @@ static SDL_Event userEvent; static SDL_cond * event_condition; static SDL_mutex * event_mutex; static SDL_mutex * event_queue_mutex; +static SDL_mutex * engine_thread_ready_mutex; static queue event_queue; Uint32 g_ticks; @@ -42,14 +45,24 @@ static int engine_thread(void * param) const char * program = (const char *) param; if (g_engine->load(program)) { + SDL_mutexV(engine_thread_ready_mutex); for (;;) { - SDL_mutexP(event_mutex); - SDL_CondWait(event_condition, event_mutex); - bool moreEvents = true; + Event event; + bool moreEvents = false; + SDL_mutexP(event_queue_mutex); + if (event_queue.size() > 0) + moreEvents = true; + SDL_mutexV(event_queue_mutex); + if (!moreEvents) + { + /* wait for an event to be ready */ + SDL_mutexP(event_mutex); + SDL_CondWait(event_condition, event_mutex); + } + moreEvents = true; while (moreEvents) { - Event event; SDL_mutexP(event_queue_mutex); if (event_queue.size() < 1) moreEvents = false; @@ -66,6 +79,8 @@ static int engine_thread(void * param) { case EVENT_UPDATE: g_engine->update(); + GLUquadric * quad = gluNewQuadric(); + gluSphere(quad, 4.0, 16, 8); lastUpdateCompleted = true; break; } @@ -167,10 +182,10 @@ static void mainloop() goto RET; break; case SDL_USEREVENT: - if (lastUpdateCompleted) - SDL_GL_SwapBuffers(); if (event.user.code == 0) { + if (lastUpdateCompleted) + SDL_GL_SwapBuffers(); update(); } break; diff --git a/tests/ballstairs.lua b/tests/ballstairs.lua index f7a181c..3919938 100755 --- a/tests/ballstairs.lua +++ b/tests/ballstairs.lua @@ -2,9 +2,7 @@ function update() ballx, bally, ballz = ball:getPosition() ag.setCamera(7, -6, 15, ballx, bally, ballz, 0, 0, 1) - ag.startFrame() ag.drawObjects() - ag.endFrame() end --ag.setCamera(8, -8, 15, -8, 8, 4, 0, 0, 1)