Engine calling update_event, key_pressed_event, and key_released_event
git-svn-id: svn://anubis/anaglym/trunk@98 99a6e188-d820-4881-8870-2d33a10e2619
This commit is contained in:
parent
624f8a8dcc
commit
c63a4bb808
25
Engine.cc
25
Engine.cc
@ -2,6 +2,7 @@
|
|||||||
#include "ag.h"
|
#include "ag.h"
|
||||||
#include "anaglym.h"
|
#include "anaglym.h"
|
||||||
#include "Engine.h"
|
#include "Engine.h"
|
||||||
|
#include "sdl_keymap.h"
|
||||||
#include <lua.hpp>
|
#include <lua.hpp>
|
||||||
#include <stdlib.h> /* exit() */
|
#include <stdlib.h> /* exit() */
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
@ -288,6 +289,10 @@ void Engine::run()
|
|||||||
{
|
{
|
||||||
goto RET;
|
goto RET;
|
||||||
}
|
}
|
||||||
|
key_event(event.key.keysym.sym, true);
|
||||||
|
break;
|
||||||
|
case SDL_KEYUP:
|
||||||
|
key_event(event.key.keysym.sym, false);
|
||||||
break;
|
break;
|
||||||
case SDL_QUIT:
|
case SDL_QUIT:
|
||||||
goto RET;
|
goto RET;
|
||||||
@ -311,7 +316,7 @@ void Engine::update()
|
|||||||
doPhysics();
|
doPhysics();
|
||||||
if (m_autoStartFrame)
|
if (m_autoStartFrame)
|
||||||
startFrame();
|
startFrame();
|
||||||
lua_getfield(m_luaState, LUA_GLOBALSINDEX, "update");
|
lua_getfield(m_luaState, LUA_GLOBALSINDEX, "update_event");
|
||||||
if (lua_type(m_luaState, -1) == LUA_TFUNCTION)
|
if (lua_type(m_luaState, -1) == LUA_TFUNCTION)
|
||||||
{
|
{
|
||||||
/* call the update function - pops the function ref from the stack */
|
/* call the update function - pops the function ref from the stack */
|
||||||
@ -329,6 +334,24 @@ void Engine::update()
|
|||||||
m_drawing = false;
|
m_drawing = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Engine::key_event(int keysym, bool pressed)
|
||||||
|
{
|
||||||
|
lua_getfield(m_luaState, LUA_GLOBALSINDEX,
|
||||||
|
pressed ? "key_pressed_event" : "key_released_event");
|
||||||
|
if (lua_type(m_luaState, -1) == LUA_TFUNCTION)
|
||||||
|
{
|
||||||
|
lua_pushstring(m_luaState, sdl_keymap[keysym]);
|
||||||
|
/* call the key_event function
|
||||||
|
* This pops the function ref and arguments from the stack */
|
||||||
|
int s = lua_pcall(m_luaState, 1, LUA_MULTRET, 0);
|
||||||
|
reportErrors(s);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
lua_pop(m_luaState, 1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void Engine::doPhysics()
|
void Engine::doPhysics()
|
||||||
{
|
{
|
||||||
static Uint32 last_updated = 0;
|
static Uint32 last_updated = 0;
|
||||||
|
1
Engine.h
1
Engine.h
@ -96,6 +96,7 @@ class Engine
|
|||||||
void registerLibraries();
|
void registerLibraries();
|
||||||
bool fileExists(const std::string & path);
|
bool fileExists(const std::string & path);
|
||||||
void update();
|
void update();
|
||||||
|
void key_event(int keysym, bool pressed);
|
||||||
Object * createObject(bool is_static, GLuint display_list,
|
Object * createObject(bool is_static, GLuint display_list,
|
||||||
float scale = 1.0f)
|
float scale = 1.0f)
|
||||||
{
|
{
|
||||||
|
@ -47,7 +47,7 @@ int main(int argc, char * argv[])
|
|||||||
}
|
}
|
||||||
|
|
||||||
Video video;
|
Video video;
|
||||||
#if 1
|
#if 0
|
||||||
/* start in windowed mode for debugging */
|
/* start in windowed mode for debugging */
|
||||||
video.start(0, 0, false, false);
|
video.start(0, 0, false, false);
|
||||||
#else
|
#else
|
||||||
|
@ -1,9 +1,15 @@
|
|||||||
|
|
||||||
function update()
|
function update_event()
|
||||||
ballx, bally, ballz = ball:getPosition()
|
ballx, bally, ballz = ball:getPosition()
|
||||||
ag.setCamera(7, -6, 15, ballx, bally, ballz, 0, 0, 1)
|
ag.setCamera(7, -6, 15, ballx, bally, ballz, 0, 0, 1)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
function key_pressed_event(key)
|
||||||
|
if (key == "d") then
|
||||||
|
ball2:destroy()
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
arena = ag.loadStaticModel("boxarena")
|
arena = ag.loadStaticModel("boxarena")
|
||||||
ball = ag.loadModel("checkerball")
|
ball = ag.loadModel("checkerball")
|
||||||
ball:setPosition(-7, 7.4, 12)
|
ball:setPosition(-7, 7.4, 12)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user