forked from mirror/openmw-tes3mp
Merge remote branch 'upstream/master'
commit
6a936100a7
@ -1,71 +1,238 @@
|
||||
|
||||
#include "soundmanager.hpp"
|
||||
|
||||
#include <iostream> // TODO remove this line, once the real code is in place.
|
||||
#include <iostream>
|
||||
using namespace std;
|
||||
|
||||
#include <openengine/sound/sndmanager.hpp>
|
||||
#include <mangle/sound/clients/ogre_listener_mover.hpp>
|
||||
#include <mangle/sound/clients/ogre_output_updater.hpp>
|
||||
|
||||
#include <components/esm_store/store.hpp>
|
||||
#include <algorithm>
|
||||
|
||||
#include <OgreRoot.h>
|
||||
|
||||
/* Set up the sound manager to use Audiere, FFMPEG or
|
||||
MPG123/libsndfile for input. The OPENMW_USE_x macros are set in
|
||||
CMakeLists.txt.
|
||||
*/
|
||||
#ifdef OPENMW_USE_AUDIERE
|
||||
#include <mangle/sound/filters/openal_audiere.hpp>
|
||||
#define SOUND_FACTORY OpenAL_Audiere_Factory
|
||||
#endif
|
||||
|
||||
#ifdef OPENMW_USE_FFMPEG
|
||||
#include <mangle/sound/filters/openal_ffmpeg.hpp>
|
||||
#define SOUND_FACTORY OpenAL_FFMpeg_Factory
|
||||
#endif
|
||||
|
||||
#ifdef OPENMW_USE_MPG123
|
||||
#include <mangle/sound/filters/openal_sndfile_mpg123.hpp>
|
||||
#define SOUND_FACTORY OpenAL_SndFile_Mpg123_Factory
|
||||
#endif
|
||||
|
||||
using namespace Mangle::Sound;
|
||||
typedef OEngine::Sound::SoundManager OEManager;
|
||||
typedef OEngine::Sound::SoundManagerPtr OEManagerPtr;
|
||||
|
||||
/* Set the position on a sound based on a Ptr. TODO: We do not support
|
||||
tracking moving objects yet, once a sound is started it stays in
|
||||
the same place until it finishes.
|
||||
|
||||
This obviously has to be fixed at some point for player/npc
|
||||
footstep sounds and the like. However, updating all sounds each
|
||||
frame is expensive, so there should be a special flag for sounds
|
||||
that need to track their attached object.
|
||||
*/
|
||||
static void setPos(SoundPtr &snd, const MWWorld::Ptr ref)
|
||||
{
|
||||
// Get sound position from the reference
|
||||
const float *pos = ref.getCellRef().pos.pos;
|
||||
|
||||
#include <components/interpreter/context.hpp>
|
||||
// Move the sound, converting from MW coordinates to Ogre
|
||||
// coordinates.
|
||||
snd->setPos(pos[0], pos[2], -pos[1]);
|
||||
}
|
||||
|
||||
namespace MWSound
|
||||
{
|
||||
void SoundManager::say (MWWorld::Ptr reference, const std::string& filename,
|
||||
const std::string& text, Interpreter::Context& context)
|
||||
struct SoundManager::SoundImpl
|
||||
{
|
||||
/* This is the sound manager. It loades, stores and deletes
|
||||
sounds based on the sound factory it is given.
|
||||
*/
|
||||
OEManagerPtr mgr;
|
||||
|
||||
/* This class calls update() on the sound manager each frame
|
||||
using and Ogre::FrameListener
|
||||
*/
|
||||
Mangle::Sound::OgreOutputUpdater updater;
|
||||
|
||||
/* This class tracks the movement of an Ogre::Camera and moves
|
||||
a sound listener automatically to follow it.
|
||||
*/
|
||||
Mangle::Sound::OgreListenerMover cameraTracker;
|
||||
|
||||
const ESMS::ESMStore &store;
|
||||
std::string dir;
|
||||
|
||||
SoundImpl(Ogre::Root *root, Ogre::Camera *camera,
|
||||
const ESMS::ESMStore &str,
|
||||
const std::string &soundDir)
|
||||
: mgr(new OEManager(SoundFactoryPtr(new SOUND_FACTORY)))
|
||||
, updater(mgr)
|
||||
, cameraTracker(mgr)
|
||||
, store(str)
|
||||
{
|
||||
std::cout << "sound effect: " << reference.getRefData().getHandle() << " is speaking" << std::endl;
|
||||
// Attach the camera to the camera tracker
|
||||
cameraTracker.followCamera(camera);
|
||||
|
||||
context.messageBox (text);
|
||||
// Tell Ogre to update the sound system each frame
|
||||
root->addFrameListener(&updater);
|
||||
|
||||
dir = soundDir + "/";
|
||||
}
|
||||
|
||||
bool SoundManager::sayDone (MWWorld::Ptr reference, Interpreter::Context& context) const
|
||||
// Convert a soundId to file name, and modify the volume
|
||||
// according to the sounds local volume setting, minRange and
|
||||
// maxRange.
|
||||
std::string lookup(const std::string &soundId,
|
||||
float &volume, float &min, float &max)
|
||||
{
|
||||
return false;
|
||||
const ESM::Sound *snd = store.sounds.search(soundId);
|
||||
if(snd == NULL) return "";
|
||||
|
||||
volume *= snd->data.volume / 255.0;
|
||||
// These factors are not very fine tuned.
|
||||
min = snd->data.minRange * 7;
|
||||
max = snd->data.maxRange * 2000;
|
||||
std::string file = dir + snd->sound;
|
||||
std::replace(file.begin(), file.end(), '\\', '/');
|
||||
return file;
|
||||
}
|
||||
|
||||
void SoundManager::streamMusic (const std::string& filename, Interpreter::Context& context)
|
||||
// Add a sound to the list and play it
|
||||
void add(const std::string &file,
|
||||
MWWorld::Ptr reference,
|
||||
const std::string &id,
|
||||
float volume, float pitch,
|
||||
float min, float max,
|
||||
bool loop)
|
||||
{
|
||||
try
|
||||
{
|
||||
std::cout << "sound effect: playing music" << filename << std::endl;
|
||||
SoundPtr snd = mgr->load(file);
|
||||
snd->setRepeat(loop);
|
||||
snd->setVolume(volume);
|
||||
snd->setPitch(pitch);
|
||||
snd->setRange(min,max);
|
||||
setPos(snd, reference);
|
||||
snd->play();
|
||||
}
|
||||
catch(...)
|
||||
{
|
||||
cout << "Error loading " << file << ", skipping.\n";
|
||||
}
|
||||
}
|
||||
|
||||
void SoundManager::playSound (const std::string& soundId, float volume, float pitch,
|
||||
Interpreter::Context& context)
|
||||
// Stop a sound and remove it from the list. If id="" then
|
||||
// remove the entire object and stop all its sounds.
|
||||
void remove(MWWorld::Ptr reference, const std::string &id = "")
|
||||
{
|
||||
std::cout
|
||||
<< "sound effect: playing sound " << soundId
|
||||
<< " at volume " << volume << ", at pitch " << pitch
|
||||
<< std::endl;
|
||||
}
|
||||
|
||||
void SoundManager::playSound3D (MWWorld::Ptr reference, const std::string& soundId,
|
||||
float volume, float pitch, bool loop, Interpreter::Context& context)
|
||||
bool isPlaying(MWWorld::Ptr reference, const std::string &id) const
|
||||
{
|
||||
std::cout
|
||||
<< "sound effect: playing sound " << soundId
|
||||
<< " from " << reference.getRefData().getHandle()
|
||||
<< " at volume " << volume << ", at pitch " << pitch
|
||||
<< std::endl;
|
||||
return true;
|
||||
}
|
||||
|
||||
mSounds[reference.getRefData().getHandle()] = soundId;
|
||||
void removeCell(const MWWorld::Ptr::CellStore *cell)
|
||||
{
|
||||
// Note to Nico: You can get the cell of a Ptr via the getCell
|
||||
// function. Just iterate over all sounds and remove those
|
||||
// with matching cell.
|
||||
}
|
||||
|
||||
void SoundManager::stopSound3D (MWWorld::Ptr reference, const std::string& soundId,
|
||||
Interpreter::Context& context)
|
||||
void updatePositions(MWWorld::Ptr reference)
|
||||
{
|
||||
std::cout
|
||||
<< "sound effect : stop playing sound " << soundId
|
||||
<< " from " << reference.getRefData().getHandle() << std::endl;
|
||||
}
|
||||
};
|
||||
|
||||
mSounds[reference.getRefData().getHandle()] = "";
|
||||
SoundManager::SoundManager(Ogre::Root *root, Ogre::Camera *camera,
|
||||
const ESMS::ESMStore &store,
|
||||
const std::string &soundDir)
|
||||
{
|
||||
mData = new SoundImpl(root, camera, store, soundDir);
|
||||
}
|
||||
|
||||
SoundManager::~SoundManager()
|
||||
{
|
||||
delete mData;
|
||||
}
|
||||
|
||||
bool SoundManager::getSoundPlaying (MWWorld::Ptr reference, const std::string& soundId,
|
||||
Interpreter::Context& context) const
|
||||
void SoundManager::say (MWWorld::Ptr reference, const std::string& filename)
|
||||
{
|
||||
std::map<std::string, std::string>::const_iterator iter =
|
||||
mSounds.find (reference.getRefData().getHandle());
|
||||
// The range values are not tested
|
||||
mData->add(filename, reference, "_say_sound", 1, 1, 100, 10000, false);
|
||||
}
|
||||
|
||||
if (iter==mSounds.end())
|
||||
return false;
|
||||
bool SoundManager::sayDone (MWWorld::Ptr reference) const
|
||||
{
|
||||
return !mData->isPlaying(reference, "_say_sound");
|
||||
}
|
||||
|
||||
return iter->second==soundId;
|
||||
void SoundManager::streamMusic (const std::string& filename)
|
||||
{
|
||||
// Play the sound and tell it to stream, if possible. TODO:
|
||||
// Store the reference, the jukebox will need to check status,
|
||||
// control volume etc.
|
||||
SoundPtr music = mData->mgr->play(filename);
|
||||
music->setStreaming(true);
|
||||
music->setVolume(0.4);
|
||||
}
|
||||
}
|
||||
|
||||
void SoundManager::playSound (const std::string& soundId, float volume, float pitch)
|
||||
{
|
||||
// Play and forget
|
||||
float min, max;
|
||||
const std::string &file = mData->lookup(soundId, volume, min, max);
|
||||
if(file != "")
|
||||
{
|
||||
SoundPtr snd = mData->mgr->play(file);
|
||||
snd->setVolume(volume);
|
||||
snd->setRange(min,max);
|
||||
snd->setPitch(pitch);
|
||||
}
|
||||
}
|
||||
|
||||
void SoundManager::playSound3D (MWWorld::Ptr reference, const std::string& soundId,
|
||||
float volume, float pitch, bool loop)
|
||||
{
|
||||
// Look up the sound in the ESM data
|
||||
float min, max;
|
||||
const std::string &file = mData->lookup(soundId, volume, min, max);
|
||||
if(file != "")
|
||||
mData->add(file, reference, soundId, volume, pitch, min, max, loop);
|
||||
}
|
||||
|
||||
void SoundManager::stopSound3D (MWWorld::Ptr reference, const std::string& soundId)
|
||||
{
|
||||
mData->remove(reference, soundId);
|
||||
}
|
||||
|
||||
void SoundManager::stopSound (MWWorld::Ptr::CellStore *cell)
|
||||
{
|
||||
mData->removeCell(cell);
|
||||
}
|
||||
|
||||
bool SoundManager::getSoundPlaying (MWWorld::Ptr reference, const std::string& soundId) const
|
||||
{
|
||||
return mData->isPlaying(reference, soundId);
|
||||
}
|
||||
|
||||
void SoundManager::updateObject(MWWorld::Ptr reference)
|
||||
{
|
||||
mData->updatePositions(reference);
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,57 @@
|
||||
# Locate Audiere
|
||||
# This module defines
|
||||
# AUDIERE_LIBRARY
|
||||
# AUDIERE_FOUND, if false, do not try to link to Audiere
|
||||
# AUDIERE_INCLUDE_DIR, where to find the headers
|
||||
#
|
||||
# Created by Nicolay Korslund for OpenMW (http://openmw.com)
|
||||
#
|
||||
# More or less a direct ripoff of FindOpenAL.cmake by Eric Wing.
|
||||
|
||||
#=============================================================================
|
||||
# Copyright 2005-2009 Kitware, Inc.
|
||||
#
|
||||
# Distributed under the OSI-approved BSD License (the "License");
|
||||
# see accompanying file Copyright.txt for details.
|
||||
#
|
||||
# This software is distributed WITHOUT ANY WARRANTY; without even the
|
||||
# implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
||||
# See the License for more information.
|
||||
#=============================================================================
|
||||
# (To distributed this file outside of CMake, substitute the full
|
||||
# License text for the above reference.)
|
||||
|
||||
|
||||
FIND_PATH(AUDIERE_INCLUDE_DIR audiere.h
|
||||
HINTS
|
||||
PATHS
|
||||
~/Library/Frameworks
|
||||
/Library/Frameworks
|
||||
/usr/local
|
||||
/usr
|
||||
/sw # Fink
|
||||
/opt/local # DarwinPorts
|
||||
/opt/csw # Blastwave
|
||||
/opt
|
||||
)
|
||||
|
||||
FIND_LIBRARY(AUDIERE_LIBRARY
|
||||
NAMES audiere
|
||||
HINTS
|
||||
PATH_SUFFIXES lib64 lib libs64 libs libs/Win32 libs/Win64
|
||||
PATHS
|
||||
~/Library/Frameworks
|
||||
/Library/Frameworks
|
||||
/usr/local
|
||||
/usr
|
||||
/sw
|
||||
/opt/local
|
||||
/opt/csw
|
||||
/opt
|
||||
)
|
||||
|
||||
SET(AUDIERE_FOUND "NO")
|
||||
IF(AUDIERE_LIBRARY AND AUDIERE_INCLUDE_DIR)
|
||||
SET(AUDIERE_FOUND "YES")
|
||||
ENDIF(AUDIERE_LIBRARY AND AUDIERE_INCLUDE_DIR)
|
||||
|
@ -0,0 +1,90 @@
|
||||
# Find the FFmpeg library
|
||||
#
|
||||
# Sets
|
||||
# FFMPEG_FOUND. If false, don't try to use ffmpeg
|
||||
# FFMPEG_INCLUDE_DIR
|
||||
# FFMPEG_LIBRARIES
|
||||
#
|
||||
# Modified by Nicolay Korslund for OpenMW
|
||||
|
||||
SET( FFMPEG_FOUND "NO" )
|
||||
|
||||
FIND_PATH( FFMPEG_avcodec_INCLUDE_DIR avcodec.h
|
||||
HINTS
|
||||
PATHS
|
||||
/usr/include
|
||||
/usr/local/include
|
||||
/usr/include/ffmpeg
|
||||
/usr/local/include/ffmpeg
|
||||
/usr/include/ffmpeg/libavcodec
|
||||
/usr/local/include/ffmpeg/libavcodec
|
||||
/usr/include/libavcodec
|
||||
/usr/local/include/libavcodec
|
||||
)
|
||||
|
||||
FIND_PATH( FFMPEG_avformat_INCLUDE_DIR avformat.h
|
||||
HINTS
|
||||
PATHS
|
||||
/usr/include
|
||||
/usr/local/include
|
||||
/usr/include/ffmpeg
|
||||
/usr/local/include/ffmpeg
|
||||
/usr/include/ffmpeg/libavformat
|
||||
/usr/local/include/ffmpeg/libavformat
|
||||
/usr/include/libavformat
|
||||
/usr/local/include/libavformat
|
||||
)
|
||||
|
||||
set(FFMPEG_INCLUDE_DIR ${FFMPEG_avcodec_INCLUDE_DIR} ${FFMPEG_avformat_INCLUDE_DIR})
|
||||
|
||||
IF( FFMPEG_INCLUDE_DIR )
|
||||
|
||||
FIND_PROGRAM( FFMPEG_CONFIG ffmpeg-config
|
||||
/usr/bin
|
||||
/usr/local/bin
|
||||
${HOME}/bin
|
||||
)
|
||||
|
||||
IF( FFMPEG_CONFIG )
|
||||
EXEC_PROGRAM( ${FFMPEG_CONFIG} ARGS "--libs avformat" OUTPUT_VARIABLE FFMPEG_LIBS )
|
||||
SET( FFMPEG_FOUND "YES" )
|
||||
SET( FFMPEG_LIBRARIES "${FFMPEG_LIBS}" )
|
||||
|
||||
ELSE( FFMPEG_CONFIG )
|
||||
|
||||
FIND_LIBRARY( FFMPEG_avcodec_LIBRARY avcodec
|
||||
/usr/lib
|
||||
/usr/local/lib
|
||||
/usr/lib64
|
||||
/usr/local/lib64
|
||||
)
|
||||
|
||||
FIND_LIBRARY( FFMPEG_avformat_LIBRARY avformat
|
||||
/usr/lib
|
||||
/usr/local/lib
|
||||
/usr/lib64
|
||||
/usr/local/lib64
|
||||
)
|
||||
|
||||
FIND_LIBRARY( FFMPEG_avutil_LIBRARY avutil
|
||||
/usr/lib
|
||||
/usr/local/lib
|
||||
/usr/lib64
|
||||
/usr/local/lib64
|
||||
)
|
||||
|
||||
IF( FFMPEG_avcodec_LIBRARY )
|
||||
IF( FFMPEG_avformat_LIBRARY )
|
||||
|
||||
SET( FFMPEG_FOUND "YES" )
|
||||
SET( FFMPEG_LIBRARIES ${FFMPEG_avformat_LIBRARY} ${FFMPEG_avcodec_LIBRARY} )
|
||||
IF( FFMPEG_avutil_LIBRARY )
|
||||
SET( FFMPEG_LIBRARIES ${FFMPEG_LIBRARIES} ${FFMPEG_avutil_LIBRARY} )
|
||||
ENDIF( FFMPEG_avutil_LIBRARY )
|
||||
|
||||
ENDIF( FFMPEG_avformat_LIBRARY )
|
||||
ENDIF( FFMPEG_avcodec_LIBRARY )
|
||||
|
||||
ENDIF( FFMPEG_CONFIG )
|
||||
|
||||
ENDIF( FFMPEG_INCLUDE_DIR )
|
@ -0,0 +1,47 @@
|
||||
# Locate MPG123
|
||||
# This module defines
|
||||
# MPG123_LIBRARY
|
||||
# MPG123_FOUND, if false, do not try to link to Mpg123
|
||||
# MPG123_INCLUDE_DIR, where to find the headers
|
||||
#
|
||||
# Created by Nicolay Korslund for OpenMW (http://openmw.com)
|
||||
#
|
||||
# Ripped off from other sources. In fact, this file is so generic (I
|
||||
# just did a search and replace on another file) that I wonder why the
|
||||
# CMake guys haven't wrapped this entire thing in a single
|
||||
# function. Do we really need to repeat this stuff for every single
|
||||
# library when they all work the same? </today's rant>
|
||||
|
||||
FIND_PATH(MPG123_INCLUDE_DIR mpg123.h
|
||||
HINTS
|
||||
PATHS
|
||||
~/Library/Frameworks
|
||||
/Library/Frameworks
|
||||
/usr/local
|
||||
/usr
|
||||
/sw # Fink
|
||||
/opt/local # DarwinPorts
|
||||
/opt/csw # Blastwave
|
||||
/opt
|
||||
)
|
||||
|
||||
FIND_LIBRARY(MPG123_LIBRARY
|
||||
NAMES mpg123
|
||||
HINTS
|
||||
PATH_SUFFIXES lib64 lib libs64 libs libs/Win32 libs/Win64
|
||||
PATHS
|
||||
~/Library/Frameworks
|
||||
/Library/Frameworks
|
||||
/usr/local
|
||||
/usr
|
||||
/sw
|
||||
/opt/local
|
||||
/opt/csw
|
||||
/opt
|
||||
)
|
||||
|
||||
SET(MPG123_FOUND "NO")
|
||||
IF(MPG123_LIBRARY AND MPG123_INCLUDE_DIR)
|
||||
SET(MPG123_FOUND "YES")
|
||||
ENDIF(MPG123_LIBRARY AND MPG123_INCLUDE_DIR)
|
||||
|
@ -0,0 +1,41 @@
|
||||
# Locate SNDFILE
|
||||
# This module defines
|
||||
# SNDFILE_LIBRARY
|
||||
# SNDFILE_FOUND, if false, do not try to link to Sndfile
|
||||
# SNDFILE_INCLUDE_DIR, where to find the headers
|
||||
#
|
||||
# Created by Nicolay Korslund for OpenMW (http://openmw.com)
|
||||
|
||||
FIND_PATH(SNDFILE_INCLUDE_DIR sndfile.h
|
||||
HINTS
|
||||
PATHS
|
||||
~/Library/Frameworks
|
||||
/Library/Frameworks
|
||||
/usr/local
|
||||
/usr
|
||||
/sw # Fink
|
||||
/opt/local # DarwinPorts
|
||||
/opt/csw # Blastwave
|
||||
/opt
|
||||
)
|
||||
|
||||
FIND_LIBRARY(SNDFILE_LIBRARY
|
||||
NAMES sndfile
|
||||
HINTS
|
||||
PATH_SUFFIXES lib64 lib libs64 libs libs/Win32 libs/Win64
|
||||
PATHS
|
||||
~/Library/Frameworks
|
||||
/Library/Frameworks
|
||||
/usr/local
|
||||
/usr
|
||||
/sw
|
||||
/opt/local
|
||||
/opt/csw
|
||||
/opt
|
||||
)
|
||||
|
||||
SET(SNDFILE_FOUND "NO")
|
||||
IF(SNDFILE_LIBRARY AND SNDFILE_INCLUDE_DIR)
|
||||
SET(SNDFILE_FOUND "YES")
|
||||
ENDIF(SNDFILE_LIBRARY AND SNDFILE_INCLUDE_DIR)
|
||||
|
@ -0,0 +1,48 @@
|
||||
#include "records.hpp"
|
||||
|
||||
/** Implementation for some of the load() functions. Most are found in
|
||||
the header files themselves, but this is a bit irritating to
|
||||
compile if you're changing the functions often, as virtually the
|
||||
entire engine depends on these headers.
|
||||
*/
|
||||
|
||||
namespace ESM
|
||||
{
|
||||
void NPC::load(ESMReader &esm, const std::string& id)
|
||||
{
|
||||
mId = id;
|
||||
|
||||
npdt52.gold = -10;
|
||||
|
||||
model = esm.getHNOString("MODL");
|
||||
name = esm.getHNOString("FNAM");
|
||||
|
||||
race = esm.getHNString("RNAM");
|
||||
cls = esm.getHNString("CNAM");
|
||||
faction = esm.getHNString("ANAM");
|
||||
head = esm.getHNString("BNAM");
|
||||
hair = esm.getHNString("KNAM");
|
||||
|
||||
script = esm.getHNOString("SCRI");
|
||||
|
||||
esm.getSubNameIs("NPDT");
|
||||
esm.getSubHeader();
|
||||
if(esm.getSubSize() == 52) esm.getExact(&npdt52, 52);
|
||||
else if(esm.getSubSize() == 12) esm.getExact(&npdt12, 12);
|
||||
else esm.fail("NPC_NPDT must be 12 or 52 bytes long");
|
||||
|
||||
esm.getHNT(flags, "FLAG");
|
||||
|
||||
inventory.load(esm);
|
||||
spells.load(esm);
|
||||
|
||||
if(esm.isNextSub("AIDT"))
|
||||
{
|
||||
esm.getHExact(&AI, sizeof(AI));
|
||||
hasAI = true;
|
||||
}
|
||||
else hasAI = false;
|
||||
|
||||
esm.skipRecord();
|
||||
}
|
||||
}
|
@ -1 +1 @@
|
||||
Subproject commit c7b179d6546688208528c8eef681d42b7c1ec7be
|
||||
Subproject commit c982f701cacdd2932bfdc22b168f54221a549b62
|
@ -1 +1 @@
|
||||
Subproject commit c04d72cbe380217c2d1d60f8a2c6e4810fe4c050
|
||||
Subproject commit b9d4dc448bc3be908653f9dea3c3450fb85ed107
|
@ -1,47 +0,0 @@
|
||||
module scene.gamesettings;
|
||||
|
||||
import monster.monster;
|
||||
import esm.records : gameSettings;
|
||||
import esm.defs : VarType;
|
||||
import std.stdio;
|
||||
import std.string;
|
||||
|
||||
MonsterObject *gmstObj;
|
||||
|
||||
void loadGameSettings()
|
||||
{
|
||||
// Load the GameSettings Monster class, and get the singleton
|
||||
// instance
|
||||
MonsterClass mc = vm.load("GMST");
|
||||
gmstObj = mc.getSing();
|
||||
|
||||
foreach(a, b; gameSettings.names)
|
||||
{
|
||||
assert(a == b.id);
|
||||
assert(a[0] == 'i' || a[0] == 'f' || a[0] == 's');
|
||||
|
||||
// There's three cases of variable names containing
|
||||
// spaces. Since these are so seldom, it makes more sense to
|
||||
// make special workarounds for them instead of searching every
|
||||
// string.
|
||||
char[] name = a;
|
||||
if(name.length > 13 && (name[6] == ' ' || name[5] == ' '))
|
||||
{
|
||||
name = name.replace(" ", "_");
|
||||
// Make sure we don't change the original string!
|
||||
assert(name != a);
|
||||
}
|
||||
|
||||
if(!mc.sc.lookupName(name).isVar)
|
||||
{
|
||||
writefln("WARNING: GMST %s not supported!", name);
|
||||
continue;
|
||||
}
|
||||
|
||||
if(b.type == VarType.Int) gmstObj.setInt(name, b.i);
|
||||
else if(b.type == VarType.Float) gmstObj.setFloat(name, b.f);
|
||||
// TODO: At some point we will probably translate strings into
|
||||
// UTF32 at load time, so string8 will not be needed here.
|
||||
else if(b.type == VarType.String) gmstObj.setString8(name, b.str);
|
||||
}
|
||||
}
|
@ -1,96 +0,0 @@
|
||||
/*
|
||||
OpenMW - The completely unofficial reimplementation of Morrowind
|
||||
Copyright (C) 2008 Nicolay Korslund
|
||||
Email: < korslund@gmail.com >
|
||||
WWW: http://openmw.snaptoad.com/
|
||||
|
||||
This file (soundlist.d) is part of the OpenMW package.
|
||||
|
||||
OpenMW is distributed as free software: you can redistribute it
|
||||
and/or modify it under the terms of the GNU General Public License
|
||||
version 3, as published by the Free Software Foundation.
|
||||
|
||||
This program is distributed in the hope that it will be useful, but
|
||||
WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
version 3 along with this program. If not, see
|
||||
http://www.gnu.org/licenses/ .
|
||||
|
||||
*/
|
||||
|
||||
module scene.soundlist;
|
||||
|
||||
import esm.loadsoun;
|
||||
import sound.audio;
|
||||
import sound.sfx;
|
||||
|
||||
SoundList soundScene;
|
||||
|
||||
// Has a list over all sounds currently playing in the
|
||||
// scene. Currently only holds static, looping sounds, mainly
|
||||
// torches. Later I will have to decide what to do with play-once
|
||||
// sounds. Do I bother to update their position, or do I assume that
|
||||
// once it starts playing, it is short enough that it doesn't matter?
|
||||
// The last option is probably not viable, since some sounds can be
|
||||
// very long.
|
||||
struct SoundList
|
||||
{
|
||||
SoundInstance[] list;
|
||||
|
||||
// Get a sound instance from a Sound struct
|
||||
static SoundInstance getInstance(Sound *s, bool loop=false)
|
||||
{
|
||||
const distFactor = 40.0; // Just guessing, really.
|
||||
|
||||
assert(!s.sound.isEmpty());
|
||||
|
||||
SoundInstance inst = s.sound.getInstance();
|
||||
inst.setParams(s.data.volume/255.0,
|
||||
s.data.minRange*distFactor,
|
||||
s.data.maxRange*distFactor,
|
||||
loop);
|
||||
return inst;
|
||||
}
|
||||
|
||||
SoundInstance *insert(Sound *snd, bool loop=false)
|
||||
{
|
||||
// For some reason, we get called with empty sound instances here
|
||||
// if some files are missing, but not for others. Check into it
|
||||
// later.
|
||||
if(snd.sound.isEmpty) return null;
|
||||
|
||||
// Reuse a dead instance if one exists
|
||||
foreach(ref s; list)
|
||||
{
|
||||
if(s.owner == null)
|
||||
{
|
||||
s = getInstance(snd, loop);
|
||||
return &s;
|
||||
}
|
||||
}
|
||||
// Otherwise append a new one
|
||||
list ~= getInstance(snd, loop);
|
||||
return &list[$-1];
|
||||
}
|
||||
|
||||
void update(float x, float y, float z,
|
||||
float frontx, float fronty, float frontz,
|
||||
float upx, float upy, float upz)
|
||||
{
|
||||
SoundInstance.setPlayerPos(x,y,z,frontx,fronty,frontz,upx,upy,upz);
|
||||
foreach(ref s; list)
|
||||
if(s.owner) s.updateSound();
|
||||
}
|
||||
|
||||
void kill()
|
||||
{
|
||||
foreach(ref s; list)
|
||||
{
|
||||
if(s.owner) s.kill();
|
||||
}
|
||||
list = null;
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue