[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Stratagus-CVS] stratagus/src/sound ccl_sound.c sound_id.c
From: |
Jimmy Salmon |
Subject: |
[Stratagus-CVS] stratagus/src/sound ccl_sound.c sound_id.c |
Date: |
Tue, 02 Dec 2003 19:31:36 -0500 |
CVSROOT: /cvsroot/stratagus
Module name: stratagus
Branch:
Changes by: Jimmy Salmon <address@hidden> 03/12/02 19:31:36
Modified files:
src/sound : ccl_sound.c sound_id.c
Log message:
Added lua functions
Patches:
Index: stratagus/src/sound/ccl_sound.c
diff -u stratagus/src/sound/ccl_sound.c:1.58
stratagus/src/sound/ccl_sound.c:1.59
--- stratagus/src/sound/ccl_sound.c:1.58 Mon Dec 1 14:44:19 2003
+++ stratagus/src/sound/ccl_sound.c Tue Dec 2 19:31:36 2003
@@ -26,7 +26,7 @@
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
// 02111-1307, USA.
//
-// $Id: ccl_sound.c,v 1.58 2003/12/01 19:44:19 nehalmistry Exp $
+// $Id: ccl_sound.c,v 1.59 2003/12/03 00:31:36 jsalmon3 Exp $
//@{
@@ -84,7 +84,6 @@
sound_id = CclMakeSmobObj(SiodSoundTag, id);
return sound_id;
}
-#elif defined(USE_LUA)
#endif
/**
@@ -106,6 +105,20 @@
return sound_id_ccl(id);
}
#elif defined(USE_LUA)
+local int CclSoundForName(lua_State* l)
+{
+ SoundId id;
+ const char* sound_name;
+ LuaUserData* data;
+
+ sound_name = LuaToString(l, -1);
+ id = SoundIdForName(sound_name);
+
+ data = lua_newuserdata(l, sizeof(LuaUserData));
+ data->Type = LuaSoundType;
+ data->Data = id;
+ return 1;
+}
#endif
@@ -125,6 +138,23 @@
}
}
#elif defined(USE_LUA)
+local SoundId CclGetSoundId(lua_State* l)
+{
+ LuaUserData* data;
+
+ if (lua_isstring(l, -1)) {
+ CclSoundForName(l);
+ }
+ if (lua_isuserdata(l, -1)) {
+ data = lua_touserdata(l, -1);
+ if (data->Type == LuaSoundType) {
+ return data->Data;
+ }
+ }
+ lua_pushfstring(l, "CclGetSoundId: not a sound");
+ lua_error(l);
+ return NULL;
+}
#endif
/**
@@ -196,6 +226,55 @@
return sound_id_ccl(id);
}
#elif defined(USE_LUA)
+local int CclMakeSound(lua_State* l)
+{
+ SoundId id;
+ const char* c_name;
+ const char* c_file;
+ char** c_files;
+ int args;
+ int j;
+ LuaUserData* data;
+
+ if (lua_gettop(l) != 2) {
+ lua_pushstring(l, "incorrect argument");
+ lua_error(l);
+ }
+
+ c_name = LuaToString(l, 1);
+ if (lua_isstring(l, 2)) {
+ // only one file
+ c_file = LuaToString(l, 2);
+ id = MakeSound(c_name, &c_file, 1);
+ DebugLevel3("Making sound `%s' from `%s' with id %p\n" _C_ c_name _C_
+ c_file _C_ id);
+ } else if (lua_istable(l, 2)) {
+ // several files
+ DebugLevel3("Making sound `%s'\n" _C_ c_name);
+ args = luaL_getn(l, 2);
+ c_files = malloc(args * sizeof(char*));
+ for (j = 0; j < args; ++j) {
+ lua_rawgeti(l, 2, j + 1);
+ c_files[j] = strdup(LuaToString(l, -1));
+ lua_pop(l, 1);
+ DebugLevel3("\tComponent %d: `%s'\n" _C_ i _C_ c_files[j]);
+ }
+ // FIXME: check size before casting
+ id = MakeSound(c_name, (const char**)c_files, (unsigned char)args);
+ for (j = 0; j < args; ++j) {
+ free(c_files[j]);
+ }
+ free(c_files);
+ } else {
+ lua_pushfstring(l, "string or table expected");
+ lua_error(l);
+ return 0;
+ }
+ data = lua_newuserdata(l, sizeof(LuaUserData));
+ data->Type = LuaSoundType;
+ data->Data = id;
+ return 1;
+}
#endif
/**
@@ -226,6 +305,31 @@
return sound_id_ccl(id);
}
#elif defined(USE_LUA)
+local int CclMakeSoundGroup(lua_State* l)
+{
+ SoundId id;
+ const char* c_name;
+ SoundId first;
+ SoundId second;
+ LuaUserData* data;
+
+ if (lua_gettop(l) != 3) {
+ lua_pushstring(l, "incorrect argument");
+ lua_error(l);
+ }
+
+ c_name = LuaToString(l, 1);
+
+ lua_pushvalue(l, 2);
+ first = CclGetSoundId(l);
+ lua_pop(l, 1);
+ second = CclGetSoundId(l);
+ id = MakeSoundGroup(c_name, first, second);
+ data = lua_newuserdata(l, sizeof(LuaUserData));
+ data->Type = LuaSoundType;
+ data->Data = id;
+ return 1;
+}
#endif
/**
@@ -248,6 +352,19 @@
return sound;
}
#elif defined(USE_LUA)
+local int CclMapSound(lua_State* l)
+{
+ const char* sound_name;
+
+ if (lua_gettop(l) != 2) {
+ lua_pushstring(l, "incorrect argument");
+ lua_error(l);
+ }
+ sound_name = LuaToString(l, 1);
+ MapSound(sound_name, CclGetSoundId(l));
+ lua_pushvalue(l, 2);
+ return 1;
+}
#endif
/**
@@ -267,6 +384,19 @@
return SCM_UNSPECIFIED;
}
#elif defined(USE_LUA)
+local int CclPlaySound(lua_State* l)
+{
+ SoundId id;
+
+ if (lua_gettop(l) != 1) {
+ lua_pushstring(l, "incorrect argument");
+ lua_error(l);
+ }
+
+ id = CclGetSoundId(l);
+ PlayGameSound(id, MaxSampleVolume);
+ return 0;
+}
#endif
/**
@@ -281,7 +411,6 @@
{
return CCL_SOUNDP(sound);
}
-#elif defined(USE_LUA)
#endif
/**
@@ -296,7 +425,6 @@
{
return CCL_SOUND_ID(sound);
}
-#elif defined(USE_LUA)
#endif
/**
@@ -422,6 +550,99 @@
return SCM_UNSPECIFIED;
}
#elif defined(USE_LUA)
+local int CclDefineGameSounds(lua_State* l)
+{
+ //FIXME: should allow to define ALL the game sounds
+ const char* value;
+ int i;
+ int args;
+ int j;
+ LuaUserData* data;
+
+ args = lua_gettop(l);
+ for (j = 0; j < args; ++j) {
+ value = LuaToString(l, j + 1);
+ ++j;
+
+ // let's handle now the different cases
+ if (!strcmp(value, "click")) {
+ if (!lua_isuserdata(l, j + 1) ||
+ (data = lua_touserdata(l, j + 1))->Type != LuaSoundType) {
+ lua_pushfstring(l, "Sound id expected");
+ lua_error(l);
+ }
+ GameSounds.Click.Sound = data->Data;
+ } else if (!strcmp(value, "placement-error")) {
+ if (!lua_isuserdata(l, j + 1) ||
+ (data = lua_touserdata(l, j + 1))->Type != LuaSoundType) {
+ lua_pushfstring(l, "Sound id expected");
+ lua_error(l);
+ }
+ GameSounds.PlacementError.Sound = data->Data;
+ } else if (!strcmp(value, "placement-success")) {
+ if (!lua_isuserdata(l, j + 1) ||
+ (data = lua_touserdata(l, j + 1))->Type != LuaSoundType) {
+ lua_pushfstring(l, "Sound id expected");
+ lua_error(l);
+ }
+ GameSounds.PlacementSuccess.Sound = data->Data;
+ } else if (!strcmp(value, "work-complete")) {
+ if (!lua_istable(l, j + 1) || luaL_getn(l, j + 1) != 2) {
+ lua_pushstring(l, "incorrect argument");
+ lua_error(l);
+ }
+ lua_rawgeti(l, j + 1, 1);
+ value = LuaToString(l, -1);
+ lua_pop(l, 1);
+ for (i = 0; i < PlayerRaces.Count; ++i) {
+ if (!strcmp(PlayerRaces.Name[i], value)) {
+ break;
+ }
+ }
+ if (i == PlayerRaces.Count) {
+ lua_pushfstring(l, "Unknown race: %s", value);
+ lua_error(l);
+ }
+ lua_rawgeti(l, j + 1, 2);
+ if (!lua_isuserdata(l, -1) ||
+ (data = lua_touserdata(l, -1))->Type != LuaSoundType) {
+ lua_pushfstring(l, "Sound id expected");
+ lua_error(l);
+ }
+ lua_pop(l, 1);
+ GameSounds.WorkComplete[i].Sound = data->Data;
+ } else if (!strcmp(value, "rescue")) {
+ if (!lua_istable(l, j + 1) || luaL_getn(l, j + 1) != 2) {
+ lua_pushstring(l, "incorrect argument");
+ lua_error(l);
+ }
+ lua_rawgeti(l, j + 1, 1);
+ value = LuaToString(l, -1);
+ lua_pop(l, 1);
+ for (i = 0; i < PlayerRaces.Count; ++i) {
+ if (!strcmp(PlayerRaces.Name[i], value)) {
+ break;
+ }
+ }
+ if (i == PlayerRaces.Count) {
+ lua_pushfstring(l, "Unknown race: %s", value);
+ lua_error(l);
+ }
+ lua_rawgeti(l, j + 1, 2);
+ if (!lua_isuserdata(l, -1) ||
+ (data = lua_touserdata(l, -1))->Type != LuaSoundType) {
+ lua_pushfstring(l, "Sound id expected");
+ lua_error(l);
+ }
+ lua_pop(l, 1);
+ GameSounds.Rescue[i].Sound = data->Data;
+ } else {
+ lua_pushfstring(l, "Unsupported tag: %s", value);
+ lua_error(l);
+ }
+ }
+ return 0;
+}
#endif
/**
@@ -646,6 +867,112 @@
return SCM_UNSPECIFIED;
}
#elif defined(USE_LUA)
+local int CclDefinePlaySections(lua_State* l)
+{
+#if 0
+ SCM value;
+ SCM sublist;
+ PlaySection* p;
+ int i;
+
+ ++NumPlaySections;
+ PlaySections = realloc(PlaySections, NumPlaySections *
sizeof(PlaySection));
+ p = PlaySections + NumPlaySections - 1;
+ memset(p, 0, sizeof(PlaySection));
+
+ while (!gh_null_p(list)) {
+ value = gh_car(list);
+ list = gh_cdr(list);
+ if (gh_eq_p(value, gh_symbol2scm("race"))) {
+ value = gh_car(list);
+ list = gh_cdr(list);
+ p->Race = gh_scm2newstr(value, NULL);
+ } else if (gh_eq_p(value, gh_symbol2scm("type"))) {
+ value = gh_car(list);
+ list = gh_cdr(list);
+ if (gh_eq_p(value, gh_symbol2scm("game"))) {
+ p->Type = PlaySectionGame;
+ } else if (gh_eq_p(value, gh_symbol2scm("briefing"))) {
+ p->Type = PlaySectionBriefing;
+ } else if (gh_eq_p(value, gh_symbol2scm("stats-victory"))) {
+ p->Type = PlaySectionStatsVictory;
+ } else if (gh_eq_p(value, gh_symbol2scm("stats-defeat"))) {
+ p->Type = PlaySectionStatsDefeat;
+ } else if (gh_eq_p(value, gh_symbol2scm("main-menu"))) {
+ p->Type = PlaySectionMainMenu;
+ } else {
+ errl("Unsupported tag", value);
+ }
+ } else if (gh_eq_p(value, gh_symbol2scm("cd"))) {
+ sublist = gh_car(list);
+ list = gh_cdr(list);
+ while (!gh_null_p(sublist)) {
+ value = gh_car(sublist);
+ sublist = gh_cdr(sublist);
+ if (gh_eq_p(value, gh_symbol2scm("order"))) {
+ value = gh_car(sublist);
+ sublist = gh_cdr(sublist);
+ if (gh_eq_p(value, gh_symbol2scm("all"))) {
+ p->CDOrder = PlaySectionOrderAll;
+ } else if (gh_eq_p(value, gh_symbol2scm("random"))) {
+ p->CDOrder = PlaySectionOrderRandom;
+ } else {
+ errl("Unsupported tag", value);
+ }
+ } else if (gh_eq_p(value, gh_symbol2scm("tracks"))) {
+ SCM temp;
+
+ value = gh_car(sublist);
+ sublist = gh_cdr(sublist);
+ for (i = 0; i < (signed)gh_vector_length(value); ++i) {
+ temp=gh_vector_ref(value, gh_int2scm(i));
+ p->CDTracks |= (1 << gh_scm2int(temp));
+ }
+ } else {
+ errl("Unsupported tag", value);
+ }
+ }
+ } else if (gh_eq_p(value, gh_symbol2scm("no-cd"))) {
+ sublist = gh_car(list);
+ list = gh_cdr(list);
+ while (!gh_null_p(sublist)) {
+ value = gh_car(sublist);
+ sublist = gh_cdr(sublist);
+ if (gh_eq_p(value, gh_symbol2scm("order"))) {
+ value = gh_car(sublist);
+ sublist = gh_cdr(sublist);
+ if (gh_eq_p(value, gh_symbol2scm("all"))) {
+ p->FileOrder = PlaySectionOrderAll;
+ } else if (gh_eq_p(value, gh_symbol2scm("random"))) {
+ p->FileOrder = PlaySectionOrderRandom;
+ } else {
+ errl("Unsupported tag", value);
+ }
+ } else if (gh_eq_p(value, gh_symbol2scm("files"))) {
+ SCM sublist2;
+
+ sublist2 = gh_car(sublist);
+ sublist = gh_cdr(sublist);
+ i = 0;
+ while (!gh_null_p(sublist2)) {
+ value = gh_car(sublist2);
+ sublist2 = gh_cdr(sublist2);
+ ++i;
+ p->Files = realloc(p->Files, (i + 1) * sizeof(char*));
+ p->Files[i - 1] = gh_scm2newstr(value, NULL);
+ p->Files[i] = NULL;
+ }
+ } else {
+ errl("Unsupported tag", value);
+ }
+ }
+ } else {
+ errl("Unsupported tag", value);
+ }
+ }
+#endif
+ return 0;
+}
#endif
/**
@@ -985,13 +1312,11 @@
gh_new_procedure1_0("play-file", CclPlayFile);
gh_new_procedure0_0("stop-music", CclStopMusic);
#elif defined(USE_LUA)
-// SiodSoundTag = CclMakeSmobType("Sound");
-
lua_register(Lua, "SetSoundVolume", CclSetSoundVolume);
lua_register(Lua, "SetMusicVolume", CclSetMusicVolume);
lua_register(Lua, "SetCdMode", CclSetCdMode);
-// lua_register(Lua, "DefinePlaySections", CclDefinePlaySections);
+ lua_register(Lua, "DefinePlaySections", CclDefinePlaySections);
lua_register(Lua, "SoundOff", CclSoundOff);
lua_register(Lua, "SoundOn", CclSoundOn);
@@ -999,14 +1324,14 @@
lua_register(Lua, "MusicOn", CclMusicOn);
lua_register(Lua, "SoundThread", CclSoundThread);
lua_register(Lua, "SetGlobalSoundRange", CclSetGlobalSoundRange);
-// lua_register(Lua, "DefineGameSounds", CclDefineGameSounds);
+ lua_register(Lua, "DefineGameSounds", CclDefineGameSounds);
lua_register(Lua, "DisplaySounds", CclDisplaySounds);
-// lua_register(Lua, "MapSound", CclMapSound);
-// lua_register(Lua, "SoundForName", CclSoundForName);
+ lua_register(Lua, "MapSound", CclMapSound);
+ lua_register(Lua, "SoundForName", CclSoundForName);
lua_register(Lua, "SetSoundRange", CclSetSoundRange);
-// lua_register(Lua, "MakeSound", CclMakeSound);
-// lua_register(Lua, "MakeSoundGroup", CclMakeSoundGroup);
-// lua_register(Lua, "PlaySound", CclPlaySound);
+ lua_register(Lua, "MakeSound", CclMakeSound);
+ lua_register(Lua, "MakeSoundGroup", CclMakeSoundGroup);
+ lua_register(Lua, "PlaySound", CclPlaySound);
lua_register(Lua, "PlayMusic", CclPlayMusic);
lua_register(Lua, "PlayFile", CclPlayFile);
@@ -1029,6 +1354,15 @@
return volume;
}
#elif defined(USE_LUA)
+local int CclSetSoundVolume(lua_State* l)
+{
+ if (lua_gettop(l) != 1) {
+ lua_pushstring(l, "incorrect argument");
+ lua_error(l);
+ }
+ lua_pushvalue(l, 1);
+ return 1;
+}
#endif
/**
@@ -1042,6 +1376,15 @@
return volume;
}
#elif defined(USE_LUA)
+local int CclSetMusicVolume(lua_State* l)
+{
+ if (lua_gettop(l) != 1) {
+ lua_pushstring(l, "incorrect argument");
+ lua_error(l);
+ }
+ lua_pushvalue(l, 1);
+ return 1;
+}
#endif
/**
@@ -1055,6 +1398,15 @@
return mode;
}
#elif defined(USE_LUA)
+local int CclSetCdMode(lua_State* l)
+{
+ if (lua_gettop(l) != 1) {
+ lua_pushstring(l, "incorrect argument");
+ lua_error(l);
+ }
+ lua_pushvalue(l, 1);
+ return 1;
+}
#endif
/**
@@ -1066,6 +1418,10 @@
return SCM_UNSPECIFIED;
}
#elif defined(USE_LUA)
+local int CclSoundOff(lua_State* l)
+{
+ return 0;
+}
#endif
/**
@@ -1080,6 +1436,11 @@
return SCM_BOOL_T;
}
#elif defined(USE_LUA)
+local int CclSoundOn(lua_State* l)
+{
+ lua_pushboolean(l, 1);
+ return 1;
+}
#endif
/**
@@ -1091,6 +1452,10 @@
return SCM_UNSPECIFIED;
}
#elif defined(USE_LUA)
+local int CclMusicOff(lua_State* l)
+{
+ return 0;
+}
#endif
/**
@@ -1105,6 +1470,10 @@
return SCM_UNSPECIFIED;
}
#elif defined(USE_LUA)
+local int CclMusicOn(lua_State* l)
+{
+ return 0;
+}
#endif
/**
@@ -1118,6 +1487,15 @@
return distance;
}
#elif defined(USE_LUA)
+local int CclSetGlobalSoundRange(lua_State* l)
+{
+ if (lua_gettop(l) != 1) {
+ lua_pushstring(l, "incorrect argument");
+ lua_error(l);
+ }
+ lua_pushvalue(l, 1);
+ return 1;
+}
#endif
/**
@@ -1132,6 +1510,15 @@
return sound;
}
#elif defined(USE_LUA)
+local int CclSetSoundRange(lua_State* l)
+{
+ if (lua_gettop(l) != 2) {
+ lua_pushstring(l, "incorrect argument");
+ lua_error(l);
+ }
+ lua_pushvalue(l, 1);
+ return 1;
+}
#endif
/**
@@ -1143,6 +1530,10 @@
return SCM_UNSPECIFIED;
}
#elif defined(USE_LUA)
+local int CclSoundThread(lua_State* l)
+{
+ return 0;
+}
#endif
/**
@@ -1155,6 +1546,10 @@
return SCM_UNSPECIFIED;
}
#elif defined(USE_LUA)
+local int CclDisplaySounds(lua_State* l)
+{
+ return 0;
+}
#endif
/**
@@ -1167,6 +1562,10 @@
return NIL;
}
#elif defined(USE_LUA)
+local int CclSoundForName(lua_State* l)
+{
+ return 0;
+}
#endif
/**
@@ -1179,6 +1578,10 @@
return NIL;
}
#elif defined(USE_LUA)
+local SCM CclDefineGameSounds(lua_State* l)
+{
+ return 0;
+}
#endif
/**
@@ -1196,6 +1599,15 @@
return sound;
}
#elif defined(USE_LUA)
+local int CclMapSound(lua_State* l)
+{
+ if (lua_gettop(l) != 2) {
+ lua_pushstring(l, "incorrect argument");
+ lua_error(l);
+ }
+ lua_pushvalue(l, 2);
+ return 1;
+}
#endif
/**
@@ -1209,6 +1621,10 @@
return SCM_UNSPECIFIED;
}
#elif defined(USE_LUA)
+local int CclPlayMusic(lua_State* l)
+{
+ return 0;
+}
#endif
/**
@@ -1222,6 +1638,10 @@
return SCM_UNSPECIFIED;
}
#elif defined(USE_LUA)
+local int CclPlayFile(lua_State* l)
+{
+ return 0;
+}
#endif
/**
@@ -1247,6 +1667,24 @@
gh_new_procedure1_0("play-music", CclPlayMusic);
gh_new_procedure1_0("play-file", CclPlayFile);
+#elif defined(USE_LUA)
+ lua_register(Lua, "SetSoundVolume!", CclSetSoundVolume);
+ lua_register(Lua, "SetMusicVolume!", CclSetMusicVolume);
+ lua_register(Lua, "SetCdMode!", CclSetCdMode);
+ lua_register(Lua, "SoundOff", CclSoundOff);
+ lua_register(Lua, "SoundOn", CclSoundOn);
+ lua_register(Lua, "MusicOff", CclMusicOff);
+ lua_register(Lua, "MusicOn", CclMusicOn);
+ lua_register(Lua, "SoundThread", CclSoundThread);
+ lua_register(Lua, "SetGlobalSoundRange!", CclSetGlobalSoundRange);
+ lua_register(Lua, "DefineGameSounds", CclDefineGameSounds);
+ lua_register(Lua, "DisplaySounds", CclDisplaySounds);
+ lua_register(Lua, "MapSound", CclMapSound);
+ lua_register(Lua, "SoundForName", CclSoundForName);
+ lua_register(Lua, "SetSoundRange!", CclSetSoundRange);
+
+ lua_register(Lua, "PlayMusic", CclPlayMusic);
+ lua_register(Lua, "PlayFile", CclPlayFile);
#endif
}
Index: stratagus/src/sound/sound_id.c
diff -u stratagus/src/sound/sound_id.c:1.21 stratagus/src/sound/sound_id.c:1.22
--- stratagus/src/sound/sound_id.c:1.21 Mon Dec 1 12:22:18 2003
+++ stratagus/src/sound/sound_id.c Tue Dec 2 19:31:36 2003
@@ -10,7 +10,7 @@
//
/address@hidden sound_id.c - The sound id. */
//
-// (c) Copyright 1998-2002 by Lutz Sammer and Fabrice Rossi
+// (c) Copyright 1998-2003 by Lutz Sammer and Fabrice Rossi
//
// it under the terms of the GNU General Public License as published
// by the Free Software Foundation; only version 2 of the License.
@@ -20,7 +20,7 @@
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
-// $Id: sound_id.c,v 1.21 2003/12/01 17:22:18 jsalmon3 Exp $
+// $Id: sound_id.c,v 1.22 2003/12/03 00:31:36 jsalmon3 Exp $
//@{
@@ -82,7 +82,7 @@
fprintf(stdout,"FIXME: not written\n");
fprintf(stdout,"Sound HashTable End\n");
- hash_stat(SoundIdHash, &st);
+ hash_stat(SoundIdHash, &st);
printf("nelem : %d\n", st.nelem);
printf("hashsize: %d\n", st.hashsize);
printf("maxdepth: %d\n", st.maxdepth);
@@ -176,7 +176,7 @@
return *result;
}
- sound=RegisterTwoGroups(first, second);
+ sound = RegisterTwoGroups(first, second);
MapSound(name, sound);
return sound;
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Stratagus-CVS] stratagus/src/sound ccl_sound.c sound_id.c,
Jimmy Salmon <=