added AV::Sound::pause(), added Lua interface for sounds (play/pause/stop/loop/loopForever)
git-svn-id: svn://anubis/anaglym/trunk@290 99a6e188-d820-4881-8870-2d33a10e2619
This commit is contained in:
parent
ed1f9c8f7f
commit
d4d44dea86
12
AV.cc
12
AV.cc
@ -4,7 +4,7 @@
|
|||||||
#include <SDL.h>
|
#include <SDL.h>
|
||||||
#include <SDL_sound.h>
|
#include <SDL_sound.h>
|
||||||
#include <math.h>
|
#include <math.h>
|
||||||
#include <limits.h>
|
#include <limits.h> /* INT_MAX */
|
||||||
|
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
|
||||||
@ -224,10 +224,19 @@ void AV::Sound::play()
|
|||||||
loop(1);
|
loop(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void AV::Sound::pause()
|
||||||
|
{
|
||||||
|
if (m_ss != NULL)
|
||||||
|
{
|
||||||
|
m_av.stopSound(this);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void AV::Sound::stop()
|
void AV::Sound::stop()
|
||||||
{
|
{
|
||||||
if (m_ss != NULL)
|
if (m_ss != NULL)
|
||||||
{
|
{
|
||||||
|
rewind();
|
||||||
m_av.stopSound(this);
|
m_av.stopSound(this);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -236,7 +245,6 @@ void AV::Sound::loop(int times)
|
|||||||
{
|
{
|
||||||
if (m_ss != NULL)
|
if (m_ss != NULL)
|
||||||
{
|
{
|
||||||
rewind();
|
|
||||||
m_loop_count = times;
|
m_loop_count = times;
|
||||||
m_av.playSound(this);
|
m_av.playSound(this);
|
||||||
}
|
}
|
||||||
|
1
AV.h
1
AV.h
@ -21,6 +21,7 @@ class AV
|
|||||||
bool load(FileLoader & fileLoader,
|
bool load(FileLoader & fileLoader,
|
||||||
const FileLoader::Path & path);
|
const FileLoader::Path & path);
|
||||||
void play();
|
void play();
|
||||||
|
void pause();
|
||||||
void stop();
|
void stop();
|
||||||
void loop(int times);
|
void loop(int times);
|
||||||
void rewind();
|
void rewind();
|
||||||
|
@ -414,6 +414,11 @@ Engine::Object * Engine::getObject(int id)
|
|||||||
return m_objects.contains(id) ? m_objects[id] : NULL;
|
return m_objects.contains(id) ? m_objects[id] : NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
refptr<AV::Sound> Engine::getSound(int id)
|
||||||
|
{
|
||||||
|
return m_sounds.contains(id) ? m_sounds[id] : NULL;
|
||||||
|
}
|
||||||
|
|
||||||
void Engine::startFrame()
|
void Engine::startFrame()
|
||||||
{
|
{
|
||||||
checkGLError();
|
checkGLError();
|
||||||
@ -570,9 +575,7 @@ int Engine::loadSound(const string & name)
|
|||||||
|
|
||||||
if (avs->load(*m_fileLoader, path))
|
if (avs->load(*m_fileLoader, path))
|
||||||
{
|
{
|
||||||
int id = addSound(avs);
|
return addSound(avs);
|
||||||
avs->play();
|
|
||||||
return id;
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
1
Engine.h
1
Engine.h
@ -166,6 +166,7 @@ class Engine
|
|||||||
void removeObject(int id);
|
void removeObject(int id);
|
||||||
int cloneObject(const Object * obj);
|
int cloneObject(const Object * obj);
|
||||||
Object * getObject(int id);
|
Object * getObject(int id);
|
||||||
|
refptr<AV::Sound> getSound(int id);
|
||||||
void doPhysics();
|
void doPhysics();
|
||||||
void drawObjects();
|
void drawObjects();
|
||||||
void setAutoPhysics(bool val) { m_autoPhysics = val; }
|
void setAutoPhysics(bool val) { m_autoPhysics = val; }
|
||||||
|
120
ag.cc
120
ag.cc
@ -1,19 +1,24 @@
|
|||||||
|
|
||||||
#include "ag.h"
|
|
||||||
#include "ag_lua.h"
|
|
||||||
#include "anaglym.h"
|
|
||||||
#include "Engine.h"
|
|
||||||
#include <SDL.h>
|
#include <SDL.h>
|
||||||
#include "wfobj/WFObj.h"
|
|
||||||
#include <unistd.h> /* usleep() */
|
#include <unistd.h> /* usleep() */
|
||||||
#include <lua.hpp>
|
|
||||||
#include <iostream>
|
|
||||||
#include <string>
|
|
||||||
#include <GL/gl.h>
|
#include <GL/gl.h>
|
||||||
#include <GL/glu.h>
|
#include <GL/glu.h>
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
#include <windows.h> /* Sleep() */
|
#include <windows.h> /* Sleep() */
|
||||||
#endif
|
#endif
|
||||||
|
#include <limits.h> /* INT_MAX */
|
||||||
|
|
||||||
|
#include <lua.hpp>
|
||||||
|
#include <iostream>
|
||||||
|
#include <string>
|
||||||
|
|
||||||
|
#include "ag.h"
|
||||||
|
#include "ag_lua.h"
|
||||||
|
#include "anaglym.h"
|
||||||
|
#include "Engine.h"
|
||||||
|
#include "wfobj/WFObj.h"
|
||||||
|
#include "AV.h"
|
||||||
|
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
|
||||||
namespace ag
|
namespace ag
|
||||||
@ -312,10 +317,16 @@ namespace ag
|
|||||||
lua_newtable(L);
|
lua_newtable(L);
|
||||||
lua_pushinteger(L, id);
|
lua_pushinteger(L, id);
|
||||||
lua_setfield(L, -2, "id");
|
lua_setfield(L, -2, "id");
|
||||||
#if 0
|
|
||||||
lua_pushcfunction(L, sound::play);
|
lua_pushcfunction(L, sound::play);
|
||||||
lua_setfield(L, -2, "play");
|
lua_setfield(L, -2, "play");
|
||||||
#endif
|
lua_pushcfunction(L, sound::pause);
|
||||||
|
lua_setfield(L, -2, "pause");
|
||||||
|
lua_pushcfunction(L, sound::stop);
|
||||||
|
lua_setfield(L, -2, "stop");
|
||||||
|
lua_pushcfunction(L, sound::loop);
|
||||||
|
lua_setfield(L, -2, "loop");
|
||||||
|
lua_pushcfunction(L, sound::loopForever);
|
||||||
|
lua_setfield(L, -2, "loopForever");
|
||||||
}
|
}
|
||||||
|
|
||||||
static void createLuaAMotor(lua_State * L, int id)
|
static void createLuaAMotor(lua_State * L, int id)
|
||||||
@ -1602,4 +1613,93 @@ namespace ag
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
namespace sound
|
||||||
|
{
|
||||||
|
refptr<AV::Sound> getSound(lua_State * L, int index)
|
||||||
|
{
|
||||||
|
refptr<AV::Sound> ret;
|
||||||
|
|
||||||
|
lua_getfield(L, index, "id");
|
||||||
|
if (lua_isnumber(L, -1))
|
||||||
|
{
|
||||||
|
int id = lua_tointeger(L, -1);
|
||||||
|
ret = g_engine->getSound(id);
|
||||||
|
}
|
||||||
|
lua_pop(L, 1);
|
||||||
|
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
int play(lua_State * L)
|
||||||
|
{
|
||||||
|
int argc = lua_gettop(L);
|
||||||
|
if (argc == 1 && lua_istable(L, 1))
|
||||||
|
{
|
||||||
|
refptr<AV::Sound> snd = getSound(L, 1);
|
||||||
|
if (!snd.isNull())
|
||||||
|
{
|
||||||
|
snd->play();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int pause(lua_State * L)
|
||||||
|
{
|
||||||
|
int argc = lua_gettop(L);
|
||||||
|
if (argc == 1 && lua_istable(L, 1))
|
||||||
|
{
|
||||||
|
refptr<AV::Sound> snd = getSound(L, 1);
|
||||||
|
if (!snd.isNull())
|
||||||
|
{
|
||||||
|
snd->pause();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int stop(lua_State * L)
|
||||||
|
{
|
||||||
|
int argc = lua_gettop(L);
|
||||||
|
if (argc == 1 && lua_istable(L, 1))
|
||||||
|
{
|
||||||
|
refptr<AV::Sound> snd = getSound(L, 1);
|
||||||
|
if (!snd.isNull())
|
||||||
|
{
|
||||||
|
snd->stop();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int loop(lua_State * L)
|
||||||
|
{
|
||||||
|
int argc = lua_gettop(L);
|
||||||
|
if (argc == 2 && lua_istable(L, 1) && lua_isnumber(L, 2))
|
||||||
|
{
|
||||||
|
refptr<AV::Sound> snd = getSound(L, 1);
|
||||||
|
if (!snd.isNull())
|
||||||
|
{
|
||||||
|
int count = lua_tointeger(L, 2);
|
||||||
|
snd->loop(count);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int loopForever(lua_State * L)
|
||||||
|
{
|
||||||
|
int argc = lua_gettop(L);
|
||||||
|
if (argc == 1 && lua_istable(L, 1))
|
||||||
|
{
|
||||||
|
refptr<AV::Sound> snd = getSound(L, 1);
|
||||||
|
if (!snd.isNull())
|
||||||
|
{
|
||||||
|
snd->loop(INT_MAX);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
12
ag.h
12
ag.h
@ -3,7 +3,9 @@
|
|||||||
#define AG_H
|
#define AG_H
|
||||||
|
|
||||||
#include <lua.hpp>
|
#include <lua.hpp>
|
||||||
|
|
||||||
#include "Engine.h"
|
#include "Engine.h"
|
||||||
|
#include "AV.h"
|
||||||
|
|
||||||
namespace ag
|
namespace ag
|
||||||
{
|
{
|
||||||
@ -103,6 +105,16 @@ namespace ag
|
|||||||
int setAMotorFMax(lua_State * L);
|
int setAMotorFMax(lua_State * L);
|
||||||
int setAMotorBounce(lua_State * L);
|
int setAMotorBounce(lua_State * L);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
namespace sound
|
||||||
|
{
|
||||||
|
refptr<AV::Sound> getSound(lua_State * L, int index);
|
||||||
|
int play(lua_State * L);
|
||||||
|
int pause(lua_State * L);
|
||||||
|
int stop(lua_State * L);
|
||||||
|
int loop(lua_State * L);
|
||||||
|
int loopForever(lua_State * L);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -21,6 +21,8 @@ function init_event()
|
|||||||
ground = ag.loadModel("crate", {static = true, scale = 10})
|
ground = ag.loadModel("crate", {static = true, scale = 10})
|
||||||
ground:setPosition(0, 0, -10)
|
ground:setPosition(0, 0, -10)
|
||||||
ag.setCamera(2, -12, 8, 0, 0, 2, 0, 0, 1)
|
ag.setCamera(2, -12, 8, 0, 0, 2, 0, 0, 1)
|
||||||
|
|
||||||
|
iris = ag.loadSound("iris.mp3")
|
||||||
end
|
end
|
||||||
|
|
||||||
function key_down_event(key)
|
function key_down_event(key)
|
||||||
@ -38,8 +40,14 @@ function key_down_event(key)
|
|||||||
ag.registerEventHandler(mouse_moves, "mouse_motion")
|
ag.registerEventHandler(mouse_moves, "mouse_motion")
|
||||||
elseif (key == "n") then
|
elseif (key == "n") then
|
||||||
ag.clearEventHandler("mouse_motion")
|
ag.clearEventHandler("mouse_motion")
|
||||||
elseif (key == "s") then
|
elseif (key == "p") then
|
||||||
ag.loadSound("iris.mp3")
|
if (playing) then
|
||||||
|
iris:pause()
|
||||||
|
playing = false
|
||||||
|
else
|
||||||
|
iris:play()
|
||||||
|
playing = true
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user