attach imuse to lua commands scripts

This commit is contained in:
Pawel Kolodziejski 2004-12-30 22:38:53 +00:00
parent 697527f5ac
commit dbe4a2e98f
4 changed files with 159 additions and 102 deletions

View file

@ -27,11 +27,14 @@
#include <assert.h> #include <assert.h>
#include "screen.h" #include "screen.h"
#include "smush.h" #include "smush.h"
#include "imuse/imuse.h"
#include "driver_gl.h" #include "driver_gl.h"
Engine *Engine::_instance = NULL; Engine *Engine::_instance = NULL;
extern Imuse *g_imuse;
Engine::Engine() : Engine::Engine() :
_currScene(NULL), _selectedActor(NULL) { _currScene(NULL), _selectedActor(NULL) {
for (int i = 0; i < SDLK_EXTRA_LAST; i++) for (int i = 0; i < SDLK_EXTRA_LAST; i++)
@ -242,7 +245,7 @@ void Engine::savegameRestore() {
return; return;
} }
//imuseStopAllSounds(); g_imuse->stopAllSounds();
g_smush->stop(); g_smush->stop();
// free all resource // free all resource
// lock resources // lock resources

View file

@ -102,7 +102,6 @@ private:
void callback(); void callback();
void switchToNextRegion(Track *track); void switchToNextRegion(Track *track);
int allocSlot(int priority); int allocSlot(int priority);
void startSound(const char *soundName, int volGroupId, int hookId, int volume, int pan, int priority);
void selectVolumeGroup(const char *soundName, int volGroupId); void selectVolumeGroup(const char *soundName, int volGroupId);
int32 getPosInMs(const char *soundName); int32 getPosInMs(const char *soundName);
@ -110,14 +109,13 @@ private:
void fadeOutMusic(int fadeDelay); void fadeOutMusic(int fadeDelay);
Track *cloneToFadeOutTrack(Track *track, int fadeDelay); Track *cloneToFadeOutTrack(Track *track, int fadeDelay);
void setMusicState(int stateId);
void setMusicSequence(int seqId);
void playMusic(const ImuseTable *table, int atribPos, bool sequence); void playMusic(const ImuseTable *table, int atribPos, bool sequence);
public: public:
Imuse(int fps); Imuse(int fps);
~Imuse(); ~Imuse();
bool startSound(const char *soundName, int volGroupId, int hookId, int volume, int pan, int priority);
void startVoice(const char *soundName); void startVoice(const char *soundName);
void startMusic(const char *soundName, int hookId, int volume, int pan); void startMusic(const char *soundName, int hookId, int volume, int pan);
void startSfx(const char *soundName, int priority); void startSfx(const char *soundName, int priority);
@ -134,12 +132,15 @@ public:
void setPriority(const char *soundName, int priority); void setPriority(const char *soundName, int priority);
void setVolume(const char *soundName, int volume); void setVolume(const char *soundName, int volume);
int getVolume(const char *soundName);
void setPan(const char *soundName, int pan); void setPan(const char *soundName, int pan);
void setFade(const char *soundName, int destVolume, int delay60HzTicks); void setFade(const char *soundName, int destVolume, int delay60HzTicks);
int getCountPlayedTracks();
void stopSound(const char *soundName); void stopSound(const char *soundName);
void stopAllSounds(); void stopAllSounds();
void pause(bool pause); void pause(bool pause);
// void parseScriptCmds(int cmd, int soundId, int sub_cmd, int d, int e, int f, int g, int h); void setMusicState(int stateId);
void setMusicSequence(int seqId);
void refreshScripts(); void refreshScripts();
void flushTracks(); void flushTracks();
bool getSoundStatus(const char *soundName) const; bool getSoundStatus(const char *soundName) const;

View file

@ -61,11 +61,11 @@ int Imuse::allocSlot(int priority) {
return trackId; return trackId;
} }
void Imuse::startSound(const char *soundName, int volGroupId, int hookId, int volume, int pan, int priority) { bool Imuse::startSound(const char *soundName, int volGroupId, int hookId, int volume, int pan, int priority) {
int l = allocSlot(priority); int l = allocSlot(priority);
if (l == -1) { if (l == -1) {
warning("Imuse::startSound() Can't start sound - no free slots"); warning("Imuse::startSound() Can't start sound - no free slots");
return; return false;
} }
Track *track = _track[l]; Track *track = _track[l];
@ -102,7 +102,7 @@ void Imuse::startSound(const char *soundName, int volGroupId, int hookId, int vo
track->soundHandle = _sound->openSound(soundName, volGroupId); track->soundHandle = _sound->openSound(soundName, volGroupId);
if (track->soundHandle == NULL) if (track->soundHandle == NULL)
return; return false;
bits = _sound->getBits(track->soundHandle); bits = _sound->getBits(track->soundHandle);
channels = _sound->getChannels(track->soundHandle); channels = _sound->getChannels(track->soundHandle);
@ -145,6 +145,8 @@ void Imuse::startSound(const char *soundName, int volGroupId, int hookId, int vo
g_mixer->playInputStream(&track->handle, track->stream, false, -1, track->mixerVol, track->mixerPan, false); g_mixer->playInputStream(&track->handle, track->stream, false, -1, track->mixerVol, track->mixerPan, false);
track->started = true; track->started = true;
track->used = true; track->used = true;
return true;
} }
void Imuse::setPriority(const char *soundName, int priority) { void Imuse::setPriority(const char *soundName, int priority) {
@ -176,6 +178,27 @@ void Imuse::setPan(const char *soundName, int pan) {
} }
} }
int Imuse::getVolume(const char *soundName) {
for (int l = 0; l < MAX_IMUSE_TRACKS; l++) {
Track *track = _track[l];
if (track->used && !track->toBeRemoved && (strcmp(track->soundName, soundName) == 0)) {
return track->vol / 1000;
}
}
}
int Imuse::getCountPlayedTracks() {
int count = 0;
for (int l = 0; l < MAX_IMUSE_TRACKS; l++) {
Track *track = _track[l];
if (track->used && !track->toBeRemoved) {
count++;
}
}
return count;
}
void Imuse::selectVolumeGroup(const char *soundName, int volGroupId) { void Imuse::selectVolumeGroup(const char *soundName, int volGroupId) {
assert((volGroupId >= 1) && (volGroupId <= 4)); assert((volGroupId >= 1) && (volGroupId <= 4));

218
lua.cpp
View file

@ -28,6 +28,7 @@
#include "smush.h" #include "smush.h"
#include "textobject.h" #include "textobject.h"
#include "objectstate.h" #include "objectstate.h"
#include "imuse/imuse.h"
#include <SDL_keysym.h> #include <SDL_keysym.h>
#include <SDL_keyboard.h> #include <SDL_keyboard.h>
#include <cstdio> #include <cstdio>
@ -35,6 +36,8 @@
static int actor_tag, color_tag, sound_tag, text_tag, vbuffer_tag, object_tag; static int actor_tag, color_tag, sound_tag, text_tag, vbuffer_tag, object_tag;
extern Imuse *g_imuse;
static inline bool isObject(int num) { static inline bool isObject(int num) {
if (lua_tag(lua_getparam(num)) != object_tag) if (lua_tag(lua_getparam(num)) != object_tag)
return false; return false;
@ -847,68 +850,144 @@ enum ImuseParam {
IM_SOUND_PAN = 0x700 IM_SOUND_PAN = 0x700
}; };
void ImStartSound() { static void ImStartSound() {
/* const char *name = luaL_check_string(1); char *soundName = luaL_check_string(1);
Sound *s = ResourceLoader::instance()->loadSound(name); int priority = check_int(2);
if (s != NULL) { int group = check_int(3);
Mixer::instance()->playSfx(s);
s->luaRef(); if (g_imuse->startSound(soundName, group, 0, 127, 0, priority)) {
lua_pushusertag(s, sound_tag); lua_pushstring(soundName);
} else } else {
*/ lua_pushnil(); lua_pushnil();
}
} }
void gc_Sound() { static void ImStopSound() {
// Sound *s = check_sound(1); char *soundName = luaL_check_string(1);
// s->luaGc(); g_imuse->stopSound(soundName);
} }
void ImStopSound() { static void ImStopAllSounds() {
/* Sound *s; g_imuse->stopAllSounds();
if (lua_isstring(lua_getparam(1))) { }
s = Mixer::instance()->findSfx(lua_getstring(lua_getparam(1)));
if (s == NULL) static void ImPause() {
return; g_imuse->pause(true);
} else }
s = check_sound(1);
Mixer::instance()->stopSfx(s);*/ static void ImResume() {
g_imuse->pause(false);
}
static void ImSetVoiceEffect() {
char *effectName = luaL_check_string(1);
warning("ImSetVoiceEffect(%s) Voice effects are not yet supported", effectName);
}
static void ImSetMusicVol() {
g_imuse->setGroupMusicVolume(check_int(1));
}
static void ImGetMusicVol() {
lua_pushnumber(g_imuse->getGroupMusicVolume());
}
static void ImSetVoiceVol() {
g_imuse->setGroupVoiceVolume(check_int(1));
}
static void ImGetVoiceVol() {
lua_pushnumber(g_imuse->getGroupVoiceVolume());
}
static void ImSetSfxVol() {
g_imuse->setGroupSfxVolume(check_int(1));
}
static void ImGetSfxVol() {
lua_pushnumber(g_imuse->getGroupSfxVolume());
}
static void ImSetParam() {
char *soundName = luaL_check_string(1);
int param = check_int(2);
int value = check_int(3);
switch (param) {
case IM_SOUND_VOL:
g_imuse->setVolume(soundName, value);
break;
case IM_SOUND_PAN:
g_imuse->setPan(soundName, value);
break;
default:
lua_pushnil();
warning("ImSetParam() Unimplemented %d, %d\n", param, value);
}
} }
void ImGetParam() { void ImGetParam() {
/* int param = check_int(2); char *soundName = luaL_check_string(1);
int param = check_int(2);
switch (param) { switch (param) {
case IM_SOUND_PLAY_COUNT: case IM_SOUND_PLAY_COUNT:
if (lua_isstring(lua_getparam(1))) { lua_pushnumber(g_imuse->getCountPlayedTracks());
Sound *s = Mixer::instance()->findSfx(lua_getstring(lua_getparam(1)));
if (s != NULL)
lua_pushnumber(1);
else
lua_pushnumber(0);
} else {
Sound *s = check_sound(1);
if (s->done())
lua_pushnumber(0);
else
lua_pushnumber(1);
}
break; break;
case IM_SOUND_VOL: case IM_SOUND_VOL:
lua_pushnumber(127); lua_pushnumber(g_imuse->getVolume(soundName));
break; break;
default: default:
warning("Unimplemented ImGetParam with %d\n", param);*/
lua_pushnil(); lua_pushnil();
// } warning("ImGetParam() Unimplemented %d\n", param);
}
} }
void ImSetState() { static void ImFadeParam() {
// int state = check_int(1); char *soundName = luaL_check_string(1);
// Mixer::instance()->setImuseState(state); int opcode = check_int(2);
int value = check_int(3);
int fadeDelay = check_int(4);
switch (opcode) {
case IM_SOUND_PAN:
// it should be fade panning really
g_imuse->setPan(soundName, value);
break;
default:
error("ImFadeParam(%s, %h, %d, %d)", soundName, opcode, value, fadeDelay);
break;
}
} }
void ImSetSequence() { static void ImSetState() {
// int seq = check_int(1); int state = check_int(1);
// Mixer::instance()->setImuseSeq(seq); g_imuse->setMusicState(state);
}
static void ImSetSequence() {
int state = check_int(1);
g_imuse->setMusicSequence(state);
}
static void SaveIMuse() {
warning("SaveIMuse() is not yet supported");
}
static void RestoreIMuse() {
warning("RestoreIMuse() is not yet supported");
}
static void SetSoundPosition() {
warning("SetSoundPosition() is not yet supported");
}
static void IsSoundPlaying() {
error("IsSoundPlaying() is not supported");
}
static void PlaySoundAt() {
error("PlaySoundAt() is not supported");
} }
void setFrameTime(float frameTime) { void setFrameTime(float frameTime) {
@ -1310,8 +1389,6 @@ STUB_FUNC(GetActorTurnRate)
STUB_FUNC(SetActorOffsetYaw) STUB_FUNC(SetActorOffsetYaw)
STUB_FUNC(PutActorAtOrigin) STUB_FUNC(PutActorAtOrigin)
STUB_FUNC(GetClippedPos) STUB_FUNC(GetClippedPos)
STUB_FUNC(RestoreIMuse)
STUB_FUNC(SaveIMuse)
STUB_FUNC(SetActorInvClipNode) STUB_FUNC(SetActorInvClipNode)
STUB_FUNC(NukeResources) STUB_FUNC(NukeResources)
STUB_FUNC(UnShrinkBoxes) STUB_FUNC(UnShrinkBoxes)
@ -1334,6 +1411,7 @@ STUB_FUNC(TextFileGetLine)
STUB_FUNC(TextFileGetLineCount) STUB_FUNC(TextFileGetLineCount)
STUB_FUNC(IrisUp) STUB_FUNC(IrisUp)
STUB_FUNC(IrisDown) STUB_FUNC(IrisDown)
STUB_FUNC(PlaySound)
STUB_FUNC(FadeInChore) STUB_FUNC(FadeInChore)
STUB_FUNC(FadeOutChore) STUB_FUNC(FadeOutChore)
STUB_FUNC(SetActorClipPlane) STUB_FUNC(SetActorClipPlane)
@ -1360,18 +1438,6 @@ STUB_FUNC(DimScreen)
STUB_FUNC(ForceRefresh) STUB_FUNC(ForceRefresh)
STUB_FUNC(RenderModeUser) STUB_FUNC(RenderModeUser)
STUB_FUNC(SetGamma) STUB_FUNC(SetGamma)
STUB_FUNC(ImSetVoiceEffect)
STUB_FUNC(ImResume)
STUB_FUNC(ImPause)
STUB_FUNC(ImSetMusicVol)
STUB_FUNC(ImGetMusicVol)
STUB_FUNC(ImSetVoiceVol)
STUB_FUNC(ImGetVoiceVol)
STUB_FUNC(ImSetSfxVol)
STUB_FUNC(ImGetSfxVol)
STUB_FUNC(ImFadeParam)
STUB_FUNC(ImSetParam)
STUB_FUNC(ImStopAllSounds)
STUB_FUNC(LightMgrSetChange) STUB_FUNC(LightMgrSetChange)
STUB_FUNC(LightMgrStartup) STUB_FUNC(LightMgrStartup)
STUB_FUNC(SetLightIntensity) STUB_FUNC(SetLightIntensity)
@ -1394,9 +1460,6 @@ STUB_FUNC(GetSectorOppositeEdge)
STUB_FUNC(FileFindDispose) STUB_FUNC(FileFindDispose)
STUB_FUNC(FileFindNext) STUB_FUNC(FileFindNext)
STUB_FUNC(FileFindFirst) STUB_FUNC(FileFindFirst)
STUB_FUNC(SetSoundPosition)
STUB_FUNC(IsSoundPlaying)
STUB_FUNC(PlaySoundAt)
STUB_FUNC(PreviousSetup) STUB_FUNC(PreviousSetup)
STUB_FUNC(NextSetup) STUB_FUNC(NextSetup)
STUB_FUNC(UnLockSet) STUB_FUNC(UnLockSet)
@ -1453,7 +1516,6 @@ STUB_FUNC(LockCostume)
STUB_FUNC(UnlockCostume) STUB_FUNC(UnlockCostume)
STUB_FUNC(PrintMessage) STUB_FUNC(PrintMessage)
STUB_FUNC(PrintError) STUB_FUNC(PrintError)
STUB_FUNC(PlaySoundAttached)
STUB_FUNC(QueryDialog) STUB_FUNC(QueryDialog)
STUB_FUNC(GetSectorVertices) STUB_FUNC(GetSectorVertices)
STUB_FUNC(IsSectorActive) STUB_FUNC(IsSectorActive)
@ -1477,19 +1539,6 @@ STUB_FUNC(SetLightAngles)
STUB_FUNC(GetLightAngles) STUB_FUNC(GetLightAngles)
STUB_FUNC(GetLightIntensity) STUB_FUNC(GetLightIntensity)
STUB_FUNC(PointLightAt) STUB_FUNC(PointLightAt)
STUB_FUNC(ImStartRecording)
STUB_FUNC(ImStopRecording)
STUB_FUNC(Play)
STUB_FUNC(Quiet)
STUB_FUNC(ImGetMasterVol)
STUB_FUNC(ImSetMasterVol)
STUB_FUNC(ImStartVoice)
STUB_FUNC(ImStopVoice)
STUB_FUNC(ImSetAttribute)
STUB_FUNC(ImSetCuePoint)
STUB_FUNC(Vfx)
STUB_FUNC(ImGetMemoryFootprint)
STUB_FUNC(ImGetSoundCacheSize)
STUB_FUNC(LoadBundle) STUB_FUNC(LoadBundle)
STUB_FUNC(UnloadBundle) STUB_FUNC(UnloadBundle)
STUB_FUNC(ActorShadow) STUB_FUNC(ActorShadow)
@ -1502,8 +1551,6 @@ STUB_FUNC(IrisComplete)
STUB_FUNC(IrisClear) STUB_FUNC(IrisClear)
STUB_FUNC(SaveScreen) STUB_FUNC(SaveScreen)
STUB_FUNC(FindFileOnAnyCD) STUB_FUNC(FindFileOnAnyCD)
STUB_FUNC(SetSoundParameters)
STUB_FUNC(GetSoundParameters)
STUB_FUNC(Test) STUB_FUNC(Test)
STUB_FUNC(ActorPuckOrient) STUB_FUNC(ActorPuckOrient)
STUB_FUNC(ActorVoiceIs3D) STUB_FUNC(ActorVoiceIs3D)
@ -1523,7 +1570,6 @@ STUB_FUNC(SetVideoDevices)
STUB_FUNC(SetHardwareState) STUB_FUNC(SetHardwareState)
STUB_FUNC(Enumerate3DDevices) STUB_FUNC(Enumerate3DDevices)
STUB_FUNC(EnumerateVideoDevices) STUB_FUNC(EnumerateVideoDevices)
STUB_FUNC(PlaySound)
static void LuaGetTickCount() { static void LuaGetTickCount() {
stubWarning("GetTickCount"); stubWarning("GetTickCount");
@ -1814,7 +1860,6 @@ struct luaL_reg mainOpcodes[] = {
{ "IsMoviePlaying", IsMoviePlaying }, { "IsMoviePlaying", IsMoviePlaying },
{ "PlaySound", PlaySound }, { "PlaySound", PlaySound },
{ "PlaySoundAt", PlaySoundAt }, { "PlaySoundAt", PlaySoundAt },
{ "PlaySoundAttached", PlaySoundAttached },
{ "IsSoundPlaying", IsSoundPlaying }, { "IsSoundPlaying", IsSoundPlaying },
{ "SetSoundPosition", SetSoundPosition }, { "SetSoundPosition", SetSoundPosition },
{ "FileFindFirst", FileFindFirst }, { "FileFindFirst", FileFindFirst },
@ -1871,36 +1916,23 @@ struct luaL_reg mainOpcodes[] = {
{ "PointLightAt", PointLightAt }, { "PointLightAt", PointLightAt },
{ "LightMgrSetChange", LightMgrSetChange }, { "LightMgrSetChange", LightMgrSetChange },
{ "LightMgrStartup", LightMgrStartup }, { "LightMgrStartup", LightMgrStartup },
{ "ImStartRecording", ImStartRecording },
{ "ImStopRecording", ImStopRecording },
{ "ImStartSound", ImStartSound }, { "ImStartSound", ImStartSound },
{ "Play", Play },
{ "ImStopSound", ImStopSound }, { "ImStopSound", ImStopSound },
{ "ImStopAllSounds", ImStopAllSounds }, { "ImStopAllSounds", ImStopAllSounds },
{ "Quiet", Quiet },
{ "ImGetParam", ImGetParam }, { "ImGetParam", ImGetParam },
{ "ImSetParam", ImSetParam }, { "ImSetParam", ImSetParam },
{ "ImFadeParam", ImFadeParam }, { "ImFadeParam", ImFadeParam },
{ "ImGetMasterVol", ImGetMasterVol },
{ "ImSetMasterVol", ImSetMasterVol },
{ "ImGetSfxVol", ImGetSfxVol }, { "ImGetSfxVol", ImGetSfxVol },
{ "ImSetSfxVol", ImSetSfxVol }, { "ImSetSfxVol", ImSetSfxVol },
{ "ImGetVoiceVol", ImGetVoiceVol }, { "ImGetVoiceVol", ImGetVoiceVol },
{ "ImSetVoiceVol", ImSetVoiceVol }, { "ImSetVoiceVol", ImSetVoiceVol },
{ "ImGetMusicVol", ImGetMusicVol }, { "ImGetMusicVol", ImGetMusicVol },
{ "ImSetMusicVol", ImSetMusicVol }, { "ImSetMusicVol", ImSetMusicVol },
{ "ImStartVoice", ImStartVoice },
{ "ImStopVoice", ImStopVoice },
{ "ImSetState", ImSetState }, { "ImSetState", ImSetState },
{ "ImSetSequence", ImSetSequence }, { "ImSetSequence", ImSetSequence },
{ "ImSetAttribute", ImSetAttribute },
{ "ImSetCuePoint", ImSetCuePoint },
{ "ImPause", ImPause }, { "ImPause", ImPause },
{ "ImResume", ImResume }, { "ImResume", ImResume },
{ "Vfx", Vfx },
{ "ImSetVoiceEffect", ImSetVoiceEffect }, { "ImSetVoiceEffect", ImSetVoiceEffect },
{ "ImGetMemoryFootprint", ImGetMemoryFootprint },
{ "ImGetSoundCacheSize", ImGetSoundCacheSize },
{ "LoadBundle", LoadBundle }, { "LoadBundle", LoadBundle },
{ "UnloadBundle", UnloadBundle }, { "UnloadBundle", UnloadBundle },
{ "SetGamma", SetGamma }, { "SetGamma", SetGamma },
@ -1962,8 +1994,6 @@ struct luaL_reg mainOpcodes[] = {
{ "FindFileOnAnyCD", FindFileOnAnyCD }, { "FindFileOnAnyCD", FindFileOnAnyCD },
{ "DetachFromResources", DetachFromResources }, { "DetachFromResources", DetachFromResources },
{ "AttachToResources", AttachToResources }, { "AttachToResources", AttachToResources },
{ "SetSoundParameters", SetSoundParameters },
{ "GetSoundParameters", GetSoundParameters },
{ "Test", Test }, { "Test", Test },
{ "ActorPuckOrient", ActorPuckOrient }, { "ActorPuckOrient", ActorPuckOrient },
{ "GetTickCount", LuaGetTickCount }, { "GetTickCount", LuaGetTickCount },