added ag.loadSound(), Engine::loadSound(), Engine::addSound(), and Engine::m_sounds
git-svn-id: svn://anubis/anaglym/trunk@261 99a6e188-d820-4881-8870-2d33a10e2619
This commit is contained in:
parent
0cf1ea45a2
commit
11680bf3d7
16
AV.cc
16
AV.cc
@ -119,3 +119,19 @@ void AV::stop()
|
|||||||
m_surface = NULL;
|
m_surface = NULL;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
AV::Sound::Sound()
|
||||||
|
{
|
||||||
|
m_rwops = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool AV::Sound::load(FileLoader & fileLoader, const FileLoader::Path & path)
|
||||||
|
{
|
||||||
|
FileLoader::Buffer buff = fileLoader.load(path);
|
||||||
|
if (buff.size > 0)
|
||||||
|
{
|
||||||
|
m_rwops = SDL_RWFromMem(buff.data, buff.size);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
11
AV.h
11
AV.h
@ -2,11 +2,22 @@
|
|||||||
#ifndef VIDEO_H
|
#ifndef VIDEO_H
|
||||||
#define VIDEO_H
|
#define VIDEO_H
|
||||||
|
|
||||||
|
#include "FileLoader/FileLoader.h"
|
||||||
#include <SDL.h>
|
#include <SDL.h>
|
||||||
|
|
||||||
class AV
|
class AV
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
class Sound
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
Sound();
|
||||||
|
bool load(FileLoader & fileLoader,
|
||||||
|
const FileLoader::Path & path);
|
||||||
|
protected:
|
||||||
|
SDL_RWops * m_rwops;
|
||||||
|
};
|
||||||
|
|
||||||
AV();
|
AV();
|
||||||
~AV();
|
~AV();
|
||||||
void start(int width = 0, int height = 0,
|
void start(int width = 0, int height = 0,
|
||||||
|
31
Engine.cc
31
Engine.cc
@ -89,8 +89,8 @@ Engine::Engine(const string & path, AV & av)
|
|||||||
: m_av(av)
|
: m_av(av)
|
||||||
{
|
{
|
||||||
m_next_object_index = 1;
|
m_next_object_index = 1;
|
||||||
|
m_next_sound_index = 1;
|
||||||
m_next_joint_index = 1;
|
m_next_joint_index = 1;
|
||||||
m_next_text_index = 1;
|
|
||||||
m_eye[0] = 0;
|
m_eye[0] = 0;
|
||||||
m_eye[1] = -1;
|
m_eye[1] = -1;
|
||||||
m_eye[2] = 0;
|
m_eye[2] = 0;
|
||||||
@ -298,6 +298,13 @@ int Engine::addObject(bool is_static, bool is_reference,
|
|||||||
return id;
|
return id;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int Engine::addSound(AV::Sound * avs)
|
||||||
|
{
|
||||||
|
int id = m_next_sound_index++;
|
||||||
|
m_sounds[id] = avs;
|
||||||
|
return id;
|
||||||
|
}
|
||||||
|
|
||||||
int Engine::addAMotor(Object * o1, Object * o2)
|
int Engine::addAMotor(Object * o1, Object * o2)
|
||||||
{
|
{
|
||||||
dBodyID b1 = 0;
|
dBodyID b1 = 0;
|
||||||
@ -564,6 +571,28 @@ int Engine::loadModel(const string & name, bool is_static, bool is_reference,
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int Engine::loadSound(const string & name)
|
||||||
|
{
|
||||||
|
size_t pos = name.find_first_not_of(FILENAME_SAFE_CHARS);
|
||||||
|
if (pos == string::npos)
|
||||||
|
{
|
||||||
|
FileLoader::Path path("", name);
|
||||||
|
|
||||||
|
AV::Sound * avs = new AV::Sound();
|
||||||
|
|
||||||
|
if (avs->load(*m_fileLoader, path))
|
||||||
|
{
|
||||||
|
int id = addSound(avs);
|
||||||
|
return id;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
cerr << "error loading sound '" << name << "'" << endl;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
bool Engine::isKeyDown(const std::string & key)
|
bool Engine::isKeyDown(const std::string & key)
|
||||||
{
|
{
|
||||||
return m_keysDown.find(key) != m_keysDown.end();
|
return m_keysDown.find(key) != m_keysDown.end();
|
||||||
|
6
Engine.h
6
Engine.h
@ -9,6 +9,7 @@
|
|||||||
#include <SDL.h>
|
#include <SDL.h>
|
||||||
#include "OdeWorld/OdeWorld.h"
|
#include "OdeWorld/OdeWorld.h"
|
||||||
#include "TextureCache/TextureCache.h"
|
#include "TextureCache/TextureCache.h"
|
||||||
|
#include "FileLoader/FileLoader.h"
|
||||||
#include "wfobj/WFObj.h"
|
#include "wfobj/WFObj.h"
|
||||||
#include "AV.h"
|
#include "AV.h"
|
||||||
#include "refptr/refptr.h"
|
#include "refptr/refptr.h"
|
||||||
@ -147,6 +148,7 @@ class Engine
|
|||||||
int addObject(bool is_static, bool is_reference,
|
int addObject(bool is_static, bool is_reference,
|
||||||
OdeWorld::GeomType geom_type,
|
OdeWorld::GeomType geom_type,
|
||||||
refptr< std::vector<float> > args);
|
refptr< std::vector<float> > args);
|
||||||
|
int addSound(AV::Sound * avs);
|
||||||
int addAMotor(Object * o1, Object * o2);
|
int addAMotor(Object * o1, Object * o2);
|
||||||
int addHinge(Object * o1, Object * o2,
|
int addHinge(Object * o1, Object * o2,
|
||||||
dReal anchor_x, dReal anchor_y, dReal anchor_z,
|
dReal anchor_x, dReal anchor_y, dReal anchor_z,
|
||||||
@ -177,6 +179,7 @@ class Engine
|
|||||||
void endFrame();
|
void endFrame();
|
||||||
int loadModel(const std::string & name, bool is_static,
|
int loadModel(const std::string & name, bool is_static,
|
||||||
bool is_reference, float scale = 1.0f);
|
bool is_reference, float scale = 1.0f);
|
||||||
|
int loadSound(const std::string & name);
|
||||||
bool isKeyDown(const std::string & key);
|
bool isKeyDown(const std::string & key);
|
||||||
void exit();
|
void exit();
|
||||||
bool import(const char * name);
|
bool import(const char * name);
|
||||||
@ -261,10 +264,11 @@ class Engine
|
|||||||
std::string m_engine_path;
|
std::string m_engine_path;
|
||||||
OdeWorld m_world;
|
OdeWorld m_world;
|
||||||
std::map<int, Object *> m_objects;
|
std::map<int, Object *> m_objects;
|
||||||
|
std::map<int, AV::Sound *> m_sounds;
|
||||||
std::map<int, dJointID> m_joints;
|
std::map<int, dJointID> m_joints;
|
||||||
int m_next_object_index;
|
int m_next_object_index;
|
||||||
|
int m_next_sound_index;
|
||||||
int m_next_joint_index;
|
int m_next_joint_index;
|
||||||
int m_next_text_index;
|
|
||||||
GLdouble m_eye[3];
|
GLdouble m_eye[3];
|
||||||
GLdouble m_center[3];
|
GLdouble m_center[3];
|
||||||
GLdouble m_up[3];
|
GLdouble m_up[3];
|
||||||
|
32
ag.cc
32
ag.cc
@ -44,6 +44,7 @@ namespace ag
|
|||||||
{ "import", import },
|
{ "import", import },
|
||||||
{ "isKeyDown", isKeyDown },
|
{ "isKeyDown", isKeyDown },
|
||||||
{ "loadModelSpecify", loadModelSpecify },
|
{ "loadModelSpecify", loadModelSpecify },
|
||||||
|
{ "loadSound", loadSound },
|
||||||
{ "loadTexture", loadTexture },
|
{ "loadTexture", loadTexture },
|
||||||
{ "next", next },
|
{ "next", next },
|
||||||
{ "pickObjects", pickObjects },
|
{ "pickObjects", pickObjects },
|
||||||
@ -304,6 +305,17 @@ namespace ag
|
|||||||
lua_pop(L, 2); /* pops 2 */
|
lua_pop(L, 2); /* pops 2 */
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void createLuaSound(lua_State * L, int id)
|
||||||
|
{
|
||||||
|
lua_newtable(L);
|
||||||
|
lua_pushinteger(L, id);
|
||||||
|
lua_setfield(L, -2, "id");
|
||||||
|
#if 0
|
||||||
|
lua_pushcfunction(L, sound::play);
|
||||||
|
lua_setfield(L, -2, "play");
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
static void createLuaAMotor(lua_State * L, int id)
|
static void createLuaAMotor(lua_State * L, int id)
|
||||||
{
|
{
|
||||||
lua_newtable(L);
|
lua_newtable(L);
|
||||||
@ -419,6 +431,26 @@ namespace ag
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int loadSound(lua_State * L)
|
||||||
|
{
|
||||||
|
bool created = false;
|
||||||
|
int argc = lua_gettop(L);
|
||||||
|
if (argc == 1 && lua_isstring(L, 1))
|
||||||
|
{
|
||||||
|
int id = g_engine->loadSound(lua_tostring(L, 1));
|
||||||
|
if (id > 0)
|
||||||
|
{
|
||||||
|
created = true;
|
||||||
|
createLuaSound(L, id);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (!created)
|
||||||
|
{
|
||||||
|
lua_pushnil(L);
|
||||||
|
}
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
int sleep(lua_State * L)
|
int sleep(lua_State * L)
|
||||||
{
|
{
|
||||||
int argc = lua_gettop(L);
|
int argc = lua_gettop(L);
|
||||||
|
1
ag.h
1
ag.h
@ -24,6 +24,7 @@ namespace ag
|
|||||||
int import(lua_State * L);
|
int import(lua_State * L);
|
||||||
int isKeyDown(lua_State * L);
|
int isKeyDown(lua_State * L);
|
||||||
int loadModelSpecify(lua_State * L);
|
int loadModelSpecify(lua_State * L);
|
||||||
|
int loadSound(lua_State * L);
|
||||||
int loadTexture(lua_State * L);
|
int loadTexture(lua_State * L);
|
||||||
int next(lua_State * L);
|
int next(lua_State * L);
|
||||||
int pickObjects(lua_State * L);
|
int pickObjects(lua_State * L);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user