file: for unicode Open function, convert input to UTF8 and delegate to char* version (avoids hacky assignment to m_pathname, and also necessary because _wfopen isn't portable)

secure_crt.cpp: provide implementation of _wfopen_s

SoundGroup: fix: all attributes now have default values in case the XML
file leaves out some fields

This was SVN commit r6405.
This commit is contained in:
janwas 2008-09-20 17:42:43 +00:00
parent 90bf3bbd5d
commit 0f559024db
4 changed files with 81 additions and 60 deletions

View File

@ -46,21 +46,11 @@ public:
virtual LibError Open(const fs::wpath& pathname, char mode)
{
debug_assert(mode == 'w' || mode == 'r');
m_pathname = "(unicode)";
m_mode = mode;
int oflag = (mode == 'r')? O_RDONLY : O_WRONLY|O_CREAT|O_TRUNC;
#if OS_WIN
oflag |= O_BINARY_NP;
#endif
m_fd = wopen(pathname.external_file_string().c_str(), oflag, S_IRWXO|S_IRWXU|S_IRWXG);
if(m_fd < 0)
WARN_RETURN(ERR::FILE_ACCESS);
stats_open();
return INFO::OK;
size_t numConverted;
char pathname_c[PATH_MAX];
const errno_t ret = wcstombs_s(&numConverted, pathname_c, pathname.external_file_string().c_str(), PATH_MAX);
debug_assert(ret == 0);
return Open(pathname_c, mode);
}
virtual void Close()

View File

@ -43,8 +43,6 @@ ERROR_ASSOCIATE(ERR::STRING_NOT_TERMINATED, "Invalid string (no 0 terminator fou
# define tcpy wcscpy
# define tprintf_s swprintf_s
# define vtnprintf vswprintf // private
# define tfopen_s _wfopen_s
# define tfopen _wfopen // private
#else
# define tchar char
# define T(string_literal) string_literal
@ -57,8 +55,6 @@ ERROR_ASSOCIATE(ERR::STRING_NOT_TERMINATED, "Invalid string (no 0 terminator fou
# define tcpy strcpy
# define tprintf_s sprintf_s
# define vtnprintf vsnprintf // private
# define tfopen_s fopen_s
# define tfopen fopen // private
#endif // #ifdef WSECURE_CRT
@ -209,8 +205,6 @@ int tcat_s(tchar* dst, size_t max_dst_chars, const tchar* src)
}
int tprintf_s(tchar* buf, size_t max_chars, const tchar* fmt, ...)
{
va_list args;
@ -220,18 +214,37 @@ int tprintf_s(tchar* buf, size_t max_chars, const tchar* fmt, ...)
return len;
}
#if OS_WIN || !defined(WSECURE_CRT)
// FIXME this doesn't work in the wchar_t version, for the platforms where it's
// supposed to do good, since wfopen is microsoft-specific.
errno_t tfopen_s(FILE** pfile, const tchar* filename, const tchar* mode)
// note: there is no portable wfopen, so we need separate implementations
// of tfopen_s. (the Unicode version just converts to UTF8)
#if defined(WSECURE_CRT)
errno_t _wfopen_s(FILE** pfile, const wchar_t* filename, const wchar_t* mode)
{
*pfile = NULL;
FILE* file = tfopen(filename, mode);
size_t numConverted; errno_t ret;
char filename_c[PATH_MAX];
ret = wcstombs_s(&numConverted, filename_c, filename, PATH_MAX);
debug_assert(ret == 0);
char mode_c[PATH_MAX];
ret = wcstombs_s(&numConverted, mode_c, mode, PATH_MAX);
debug_assert(ret == 0);
return fopen_s(pfile, filename_c, mode_c);
}
#else
errno_t fopen_s(FILE** pfile, const char* filename, const char* mode)
{
*pfile = NULL;
FILE* file = fopen(filename, mode);
if(!file)
return ENOENT;
*pfile = file;
return 0;
}
#endif
#endif // #if EMULATE_SECURE_CRT

View File

@ -20,21 +20,37 @@
#define LOG_CATEGORY "audio"
CSoundGroup::CSoundGroup()
void CSoundGroup::SetDefaultValues()
{
m_index = 0;
m_Flags = 0;
m_Intensity = 0;
m_CurTime = 0.0f;
// sane defaults; will probably be replaced by the values read during LoadSoundGroup.
m_Gain = 0.5f;
m_Pitch = 1.0f;
m_Priority = 60;
m_PitchUpper = 1.1f;
m_PitchLower = 0.9f;
m_GainUpper = 1.0f;
m_GainLower = 0.8f;
m_ConeOuterGain = 0.0f;
m_ConeInnerAngle = 360.0f;
m_ConeOuterAngle = 360.0f;
m_Decay = 3.0f;
m_IntensityThreshold = 3;
// WARNING: m_TimeWindow is currently unused and uninitialized
}
CSoundGroup::CSoundGroup()
{
SetDefaultValues();
}
CSoundGroup::CSoundGroup(const char *XMLfile)
{
m_index = 0;
m_Flags = 0;
m_Intensity = 0;
m_CurTime = 0.0f;
SetDefaultValues();
LoadSoundGroup(XMLfile);
}

View File

@ -56,6 +56,36 @@ enum eSndGrpFlags
class CSoundGroup
{
public:
CSoundGroup(const char *XMLfile);
CSoundGroup(void);
~CSoundGroup(void);
// Play next sound in group
// @param position world position of the entity generating the sound
// (ignored if the eOmnipresent flag is set)
void PlayNext(const CVector3D& position);
// Load a group
bool LoadSoundGroup(const char *XMLfile);
void Reload();
// Release all remaining loaded handles
void ReleaseGroup();
// Update SoundGroup, remove dead sounds from intensity count
void Update(float TimeSinceLastFrame);
// Set a flag using a value from eSndGrpFlags
inline void SetFlag(int flag){ m_Flags |= flag; }
// Test flag, returns true if flag is set.
inline bool TestFlag(int flag) { return (m_Flags & flag) != 0;}
private:
void SetDefaultValues();
size_t m_index; // index of the next sound to play
Handle m_hReplacement;
@ -83,34 +113,6 @@ class CSoundGroup
float m_GainLower;
float m_ConeInnerAngle;
float m_ConeOuterAngle;
public:
CSoundGroup(const char *XMLfile);
CSoundGroup(void);
~CSoundGroup(void);
// Play next sound in group
// @param position world position of the entity generating the sound
// (ignored if the eOmnipresent flag is set)
void PlayNext(const CVector3D& position);
// Load a group
bool LoadSoundGroup(const char *XMLfile);
void Reload();
// Release all remaining loaded handles
void ReleaseGroup();
// Update SoundGroup, remove dead sounds from intensity count
void Update(float TimeSinceLastFrame);
// Set a flag using a value from eSndGrpFlags
inline void SetFlag(int flag){ m_Flags |= flag; }
// Test flag, returns true if flag is set.
inline bool TestFlag(int flag) { return (m_Flags & flag) != 0;}
};
#endif //#ifndef INCLUDED_SOUNDGROUP