Skip to content
Snippets Groups Projects
Commit 7fa13370 authored by dg's avatar dg
Browse files

switch to openAL, WIP

git-svn-id: http://svn.net-core.org/repos/t-engine4@3668 51575b47-30f0-44d4-a5cc-537603b46e54
parent 74b999c8
No related branches found
No related tags found
No related merge requests found
Showing
with 65 additions and 64 deletions
...@@ -44,7 +44,7 @@ project "TEngine" ...@@ -44,7 +44,7 @@ project "TEngine"
links { "IOKit" } links { "IOKit" }
configuration "windows" configuration "windows"
links { "mingw32", "SDLmain", "SDL", "SDL_ttf", "SDL_image", "SDL_mixer", "OPENGL32", "GLU32", "wsock32" } links { "mingw32", "SDLmain", "SDL", "SDL_ttf", "SDL_image", "openal", "OPENGL32", "GLU32", "wsock32" }
defines { [[TENGINE_HOME_PATH='"T-Engine"']], 'SELFEXE_WINDOWS' } defines { [[TENGINE_HOME_PATH='"T-Engine"']], 'SELFEXE_WINDOWS' }
prebuildcommands { "windres ../src/windows/icon.rc -O coff -o ../src/windows/icon.res" } prebuildcommands { "windres ../src/windows/icon.rc -O coff -o ../src/windows/icon.res" }
linkoptions { "../src/windows/icon.res" } linkoptions { "../src/windows/icon.res" }
...@@ -53,7 +53,7 @@ project "TEngine" ...@@ -53,7 +53,7 @@ project "TEngine"
configuration "linux" configuration "linux"
links { "dl", "SDL", "SDL_ttf", "SDL_image", "SDL_mixer", "GL", "GLU", "m", "pthread" } links { "dl", "SDL", "SDL_ttf", "SDL_image", "openal", "vorbisfile", "GL", "GLU", "m", "pthread" }
defines { [[TENGINE_HOME_PATH='".t-engine"']], 'SELFEXE_LINUX' } defines { [[TENGINE_HOME_PATH='".t-engine"']], 'SELFEXE_LINUX' }
configuration {"Debug"} configuration {"Debug"}
......
...@@ -92,7 +92,7 @@ function _M:defaultSavedFields(t) ...@@ -92,7 +92,7 @@ function _M:defaultSavedFields(t)
w=true, h=true, zone=true, player=true, level=true, entities=true, w=true, h=true, zone=true, player=true, level=true, entities=true,
energy_to_act=true, energy_per_tick=true, turn=true, paused=true, save_name=true, energy_to_act=true, energy_per_tick=true, turn=true, paused=true, save_name=true,
always_target=true, gfxmode=true, uniques=true, object_known_types=true, always_target=true, gfxmode=true, uniques=true, object_known_types=true,
current_music=true, memory_levels=true, achievement_data=true, factions=true, memory_levels=true, achievement_data=true, factions=true, playing_musics=true,
state=true, state=true,
__savefile_version_tokens = true, __savefile_version_tokens = true,
} }
......
...@@ -99,10 +99,6 @@ core.display.setGamma(config.settings.gamma_correction / 100) ...@@ -99,10 +99,6 @@ core.display.setGamma(config.settings.gamma_correction / 100)
if not config.settings.fbo_active then core.display.disableFBO() print("Disabling FBO") end if not config.settings.fbo_active then core.display.disableFBO() print("Disabling FBO") end
if not config.settings.shaders_active then core.shader.disable() print("Disabling Shaders") end if not config.settings.shaders_active then core.shader.disable() print("Disabling Shaders") end
-- Setup musics
engine.interface.GameMusic:soundSystemStatus(config.settings.sound.enabled, true)
core.sound.activateMusicCallback()
-- Load profile configs -- Load profile configs
core.profile.createThread() core.profile.createThread()
profile = engine.PlayerProfile.new() profile = engine.PlayerProfile.new()
......
...@@ -27,39 +27,51 @@ function _M:init() ...@@ -27,39 +27,51 @@ function _M:init()
self.current_music = nil self.current_music = nil
self.next_music = nil self.next_music = nil
self.loaded_musics = {} self.loaded_musics = {}
self.playing_musics = {}
end end
function _M:loaded() function _M:loaded()
self.playing_musics = self.playing_musics or {}
self.loaded_musics = self.loaded_musics or {} self.loaded_musics = self.loaded_musics or {}
end end
function _M:playMusic(name, loop) function _M:playMusic(name)
name = name or self.current_music if not name then
if not name then return end for name, data in pairs(self.playing_musics) do self:playMusic(name, data.loop) end
local m = self.loaded_musics[name] return
if not m then
self.loaded_musics[name] = core.sound.newMusic("/data/music/"..name)
m = self.loaded_musics[name]
end end
if self.loaded_musics[name] then return end
self.loaded_musics[name] = core.sound.load("/data/music/"..name)
local m = self.loaded_musics[name]
if not m then return end if not m then return end
print("[MUSIC] playing", name, m, " :: current ? ", self.playing_music) print("[MUSIC] playing", name, m, " :: current ? ", self.playing_music)
if self.current_music == name and self.playing_music then return end m:loop(true)
if self.current_music then m:play()
core.sound.musicStop() self.playing_musics[name] = {loop=true}
end
function _M:stopMusic(name)
if not name then
for name, _ in pairs(self.loaded_musics) do self:stopMusic(name) end
return
end end
m:play(loop or -1)
self.current_music = name if not self.loaded_musics[name] then return end
self.playing_music = true self.loaded_musics[name]:stop()
self.loaded_musics[name] = nil
self.playing_musics[name] = nil
print("[MUSIC] stoping", name)
end end
function _M:stopMusic(fadeout) function _M:playAndStopMusic(...)
if not self.loaded_musics[self.current_music] then return end local keep = table.reverse{...}
core.sound.musicStop(fadeout) for name, _ in pairs(self.loaded_musics) do if not keep[name] then self:stopMusic(name) end end
self.current_music = nil for name, _ in pairs(keep) do if not self.loaded_musics[name] then self:playMusic(name) end end
self.playing_music = false
end end
function _M:volumeMusic(vol) function _M:volumeMusic(vol)
do return end
if vol then if vol then
self:saveSettings("music", ("music.volume = %q\n"):format(vol)) self:saveSettings("music", ("music.volume = %q\n"):format(vol))
end end
...@@ -69,21 +81,3 @@ end ...@@ -69,21 +81,3 @@ end
--- Called by the C core when the current music stops --- Called by the C core when the current music stops
function _M:onMusicStop() function _M:onMusicStop()
end end
function _M:soundSystemStatus(act, init_setup)
if type(act) == "boolean" then
core.sound.soundSystemStatus(act)
if not init_setup then
self:saveSettings("sound", ("sound.enabled = %s\n"):format(act and "true" or "false"))
if act then
self:playMusic()
else
local o = self.current_music
self:stopMusic()
self.current_music = o
end
end
else
return core.sound.soundSystemStatus()
end
end
...@@ -25,27 +25,32 @@ module(..., package.seeall, class.make) ...@@ -25,27 +25,32 @@ module(..., package.seeall, class.make)
--- Initializes --- Initializes
function _M:init() function _M:init()
self.loaded_sounds = {} self.loaded_sounds = {}
-- setmetatable(self.loaded_sounds, {__mode="v"})
end end
function _M:loaded() function _M:loaded()
self.loaded_sounds = self.loaded_sounds or {} self.loaded_sounds = self.loaded_sounds or {}
-- setmetatable(self.loaded_sounds, {__mode="v"})
end end
function _M:playSound(name) function _M:playSound(name)
local s = self.loaded_sounds[name] local s = self.loaded_sounds[name]
if not s then if not s then
local def local def, ok
if fs.exists("/data/sound/"..name..".lua") then if fs.exists("/data/sound/"..name..".lua") then
local f = loadfile("/data/sound/"..name..".lua") local f = loadfile("/data/sound/"..name..".lua")
setfenv(f, setmetatable({}, {__index=_G})) setfenv(f, setmetatable({}, {__index=_G}))
def = f() def = f()
print("[SOUND] loading from", "/data/sound/"..name..".lua", ":=:", "/data/sound/"..def.file, ":>") print("[SOUND] loading from", "/data/sound/"..name..".lua", ":=:", "/data/sound/"..def.file, ":>")
def.file = core.sound.newSound("/data/sound/"..def.file) ok, def.sample = pcall(core.sound.load, "/data/sound/"..def.file)
print("[SOUND] :=>", def.file) if not ok then return end
if def.volume and def.file then def.file:setVolume(def.volume) end print("[SOUND] :=>", def.sample)
elseif fs.exists("/data/sound/"..name..".wav") then if def.volume and def.sample then def.sample:volume(def.volume / 100) end
def = {file = core.sound.newSound("/data/sound/"..name..".wav")} elseif fs.exists("/data/sound/"..name..".ogg") then
print("[SOUND] loading from", "/data/sound/"..name..".wav", ":=:", def.file) def = {}
ok, def.sample = pcall(core.sound.load, "/data/sound/"..name..".ogg")
if not ok then return end
print("[SOUND] loading from", "/data/sound/"..name..".ogg", ":=:", def.sample)
else else
def = {} def = {}
end end
...@@ -53,7 +58,7 @@ function _M:playSound(name) ...@@ -53,7 +58,7 @@ function _M:playSound(name)
self.loaded_sounds[name] = def self.loaded_sounds[name] = def
s = self.loaded_sounds[name] s = self.loaded_sounds[name]
end end
if not s or not s.file then return end if not s or not s.sample then return end
local chan = s.file:play(s.loop, s.timed) s.sample:play(s.loop)
if chan and s.fadeout then core.sound.channelFadeOut(chan, s.fadeout) end return s
end end
...@@ -148,9 +148,6 @@ function _M:run() ...@@ -148,9 +148,6 @@ function _M:run()
-- Ok everything is good to go, activate the game in the engine! -- Ok everything is good to go, activate the game in the engine!
self:setCurrent() self:setCurrent()
-- Run the current music if any
self:playMusic()
-- Start time -- Start time
self.real_starttime = os.time() self.real_starttime = os.time()
...@@ -169,6 +166,9 @@ function _M:run() ...@@ -169,6 +166,9 @@ function _M:run()
self.hotkeys_display.actor = self.player self.hotkeys_display.actor = self.player
self.npcs_display.actor = self.player self.npcs_display.actor = self.player
-- Run the current music if any
self:onTickEnd(function() self:playMusic() end)
end end
--- Checks if the current character is "tainted" by cheating --- Checks if the current character is "tainted" by cheating
...@@ -609,13 +609,19 @@ function _M:changeLevel(lev, zone, keep_old_lev, force_down) ...@@ -609,13 +609,19 @@ function _M:changeLevel(lev, zone, keep_old_lev, force_down)
act.last_act_turn = math.floor(self.turn / (self.zone.wilderness and 1000 or 10)) act.last_act_turn = math.floor(self.turn / (self.zone.wilderness and 1000 or 10))
end end
local musics = {}
local keep_musics = false
if self.level.data.ambient_music then if self.level.data.ambient_music then
if self.level.data.ambient_music ~= "last" then if self.level.data.ambient_music ~= "last" then
self:playMusic(self.level.data.ambient_music) if type(self.level.data.ambient_music) == "string" then musics[#musics+1] = self.level.data.ambient_music
elseif type(self.level.data.ambient_music) == "table" then for i, name in ipairs(self.level.data.ambient_music) do musics[#musics+1] = name end
elseif type(self.level.data.ambient_music) == "function" then for i, name in ipairs{self.level.data.ambient_music()} do musics[#musics+1] = name end
end
elseif self.level.data.ambient_music == "last" then
keep_musics = true
end end
else
self:stopMusic()
end end
if not keep_musics then self:playAndStopMusic(unpack(musics)) end
-- Update the minimap -- Update the minimap
self:setupMiniMap() self:setupMiniMap()
......
...@@ -26,7 +26,7 @@ desc = function(self, who) ...@@ -26,7 +26,7 @@ desc = function(self, who)
end end
function win(self) function win(self)
game:playMusic("Lords of the Sky.ogg") game:playAndStopMusic("Lords of the Sky.ogg")
game.player.winner = "arena" game.player.winner = "arena"
game:registerDialog(require("engine.dialogs.ShowText").new("Winner", "win", {playername=game.player.name, how="arena"}, game.w * 0.6)) game:registerDialog(require("engine.dialogs.ShowText").new("Winner", "win", {playername=game.player.name, how="arena"}, game.w * 0.6))
......
...@@ -109,7 +109,7 @@ function failed_charred_scar(self, level) ...@@ -109,7 +109,7 @@ function failed_charred_scar(self, level)
end end
function win(self, how) function win(self, how)
game:playMusic("Lords of the Sky.ogg") game:playAndStopMusic("Lords of the Sky.ogg")
if how == "full" then world:gainAchievement("WIN_FULL", game.player) if how == "full" then world:gainAchievement("WIN_FULL", game.player)
elseif how == "aeryn-sacrifice" then world:gainAchievement("WIN_AERYN", game.player) elseif how == "aeryn-sacrifice" then world:gainAchievement("WIN_AERYN", game.player)
......
return { return {
file = "actions/arrow.wav", file = "actions/arrow.ogg",
volume = 30, volume = 30,
} }
File added
File deleted
File added
File deleted
return { return {
file = "actions/melee.wav", file = "actions/melee.ogg",
volume = 30, volume = 30,
} }
File added
File deleted
return { return {
file = "actions/melee_miss.wav", file = "actions/melee_miss.ogg",
volume = 30, volume = 30,
} }
File added
File deleted
File added
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment