From dd6679b0b84abd3868249ff23902a0d044e124c9 Mon Sep 17 00:00:00 2001 From: janwas Date: Thu, 6 Jul 2006 15:52:59 +0000 Subject: [PATCH] # fixes to string_s selftest snd_mgr: fix cppdoc comments (got shredded by IDE autofmt) string_s: disable WARN_IF_PTR_LEN (too many false positives) test_string_s: add missing debug_skip_next_err (fixes complaints on VC2003) refs #130 This was SVN commit r4066. --- source/lib/res/sound/snd_mgr.cpp | 1014 +++++++++++++++--------------- source/lib/string_s.cpp | 8 +- source/lib/tests/test_string_s.h | 23 +- 3 files changed, 535 insertions(+), 510 deletions(-) diff --git a/source/lib/res/sound/snd_mgr.cpp b/source/lib/res/sound/snd_mgr.cpp index 8b0ea2f635..981ba83a5b 100644 --- a/source/lib/res/sound/snd_mgr.cpp +++ b/source/lib/res/sound/snd_mgr.cpp @@ -7,7 +7,7 @@ * * @author Jan.Wassenberg@stud.uni-karlsruhe.de * ========================================================================= - */ + */ /* * Copyright (c) 2004-2005 Jan Wassenberg @@ -19,7 +19,7 @@ * 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. - */ + */ #include "precompiled.h" @@ -121,12 +121,12 @@ static void hsd_list_free_all(); /** -* check if OpenAL indicates an error has occurred. it can only report -* 1 error at a time, so this is called after every OpenAL request. -* -* @param caller Name of calling function (typically passed via __func__) -*/ -static void al_check(const char* caller = "(unknown)") + * check if OpenAL indicates an error has occurred. it can only report + * 1 error at a time, so this is called after every OpenAL request. + * + * @param caller Name of calling function (typically passed via __func__) + */ +static void al_check(const char * caller = "(unknown)") { debug_assert(al_initialized); @@ -134,7 +134,7 @@ static void al_check(const char* caller = "(unknown)") if(err == AL_NO_ERROR) return; - const char* str = (const char*)alGetString(err); + const char * str = (const char*)alGetString(err); debug_printf("OpenAL error: %s; called from %s\n", str, caller); debug_warn("OpenAL error"); } @@ -150,32 +150,32 @@ static void al_check(const char* caller = "(unknown)") // /////////////////////////////////////////////////////////////////////////////// -static const char* alc_dev_name = 0; +static const char * alc_dev_name = 0; // default (0): use OpenAL default device. // note: that's why this needs to be a pointer instead of an array. /** -* tell OpenAL to use the specified device in future. -* -* @param alc_new_dev_name Device name. -* @return LibError -* -* name = 0 reverts to OpenAL's default choice, which will also -* be used if this routine is never called. -* -* the device name is typically taken from a config file at init-time; -* the snd_dev* enumeration routines below are used to present a list -* of choices to the user in the options screen. -* -* if OpenAL hasn't yet been initialized (i.e. no sounds have been opened), -* this just stores the device name for use when init does occur. -* note: we can't check now if it's invalid (if so, init will fail). -* otherwise, we shut OpenAL down (thereby stopping all sounds) and -* re-initialize with the new device. that's fairly time-consuming, -* so preferably call this routine before sounds are loaded. -*/ -LibError snd_dev_set(const char* alc_new_dev_name) + * tell OpenAL to use the specified device in future. + * + * @param alc_new_dev_name Device name. + * @return LibError + * + * name = 0 reverts to OpenAL's default choice, which will also + * be used if this routine is never called. + * + * the device name is typically taken from a config file at init-time; + * the snd_dev * enumeration routines below are used to present a list + * of choices to the user in the options screen. + * + * if OpenAL hasn't yet been initialized (i.e. no sounds have been opened), + * this just stores the device name for use when init does occur. + * note: we can't check now if it's invalid (if so, init will fail). + * otherwise, we shut OpenAL down (thereby stopping all sounds) and + * re-initialize with the new device. that's fairly time-consuming, + * so preferably call this routine before sounds are loaded. + */ +LibError snd_dev_set(const char * alc_new_dev_name) { // requesting a specific device if(alc_new_dev_name) @@ -205,13 +205,13 @@ LibError snd_dev_set(const char* alc_new_dev_name) } -static ALCcontext* alc_ctx = 0; -static ALCdevice* alc_dev = 0; +static ALCcontext * alc_ctx = 0; +static ALCdevice * alc_dev = 0; /** -* free the OpenAL context and device. -*/ + * free the OpenAL context and device. + */ static void alc_shutdown() { if(alc_ctx) @@ -226,10 +226,10 @@ static void alc_shutdown() /** -* Ready OpenAL for use by setting up a device and context. -* -* @return LibError -*/ + * Ready OpenAL for use by setting up a device and context. + * + * @return LibError + */ static LibError alc_init() { LibError ret = INFO_OK; @@ -279,7 +279,7 @@ static LibError alc_init() // make note of which sound device is actually being used // (e.g. DS3D, native, MMSYSTEM) - needed when reporting OpenAL bugs. - const char* dev_name = (const char*)alcGetString(alc_dev, ALC_DEVICE_SPECIFIER); + const char * dev_name = (const char*)alcGetString(alc_dev, ALC_DEVICE_SPECIFIER); wchar_t buf[200]; swprintf(buf, ARRAY_SIZE(buf), L"SND| alc_init: success, using %hs\n", dev_name); ah_log(buf); @@ -311,10 +311,10 @@ static float al_listener_orientation[6] = {0, 0, -1, 0, 1, 0}; /** -* send the current listener properties to OpenAL. -* -* also called from al_init. -*/ + * send the current listener properties to OpenAL. + * + * also called from al_init. + */ static void al_listener_latch() { if(al_initialized) @@ -328,13 +328,13 @@ static void al_listener_latch() /** -* set amplitude modifier, which is effectively applied to all sounds. -* in layman's terms, this is the global "volume". -* -* @param gain Modifier: must be non-negative; -* 1 -> unattenuated, 0.5 -> -6 dB, 0 -> silence. -* @return LibError -*/ + * set amplitude modifier, which is effectively applied to all sounds. + * in layman's terms, this is the global "volume". + * + * @param gain Modifier: must be non-negative; + * 1 -> unattenuated, 0.5 -> -6 dB, 0 -> silence. + * @return LibError + */ LibError snd_set_master_gain(float gain) { if(gain < 0) @@ -351,13 +351,13 @@ LibError snd_set_master_gain(float gain) /** -* set position of the listener (corresponds to camera in graphics). -* coordinates are in world space; the system doesn't matter. -* -* @param pos position support vector -* @param dir view direction -* @param up up vector -*/ + * set position of the listener (corresponds to camera in graphics). + * coordinates are in world space; the system doesn't matter. + * + * @param pos position support vector + * @param dir view direction + * @param up up vector + */ static void al_listener_set_pos(const float pos[3], const float dir[3], const float up[3]) { int i; @@ -373,12 +373,12 @@ static void al_listener_set_pos(const float pos[3], const float dir[3], const fl /** -* get distance between listener and point. -* this is used to determine sound priority. -* -* @param point position support vector -* @return float euclidean distance squared -*/ + * get distance between listener and point. + * this is used to determine sound priority. + * + * @param point position support vector + * @return float euclidean distance squared + */ static float al_listener_dist_2(const float point[3]) { const float dx = al_listener_pos[0] - point[0]; @@ -400,15 +400,15 @@ static int al_bufs_outstanding; /** -* allocate a new buffer, and fill it with the specified data. -* -* @param data raw sound data buffer -* @param size size of buffer in bytes -* @param al_fmt AL_FORMAT_* describing the sound data -* @param al_freq sampling frequency (typically 22050 Hz) -* @return ALuint buffer name -*/ -static ALuint al_buf_alloc(ALvoid* data, ALsizei size, ALenum al_fmt, ALsizei al_freq) + * allocate a new buffer, and fill it with the specified data. + * + * @param data raw sound data buffer + * @param size size of buffer in bytes + * @param al_fmt AL_FORMAT_ * describing the sound data + * @param al_freq sampling frequency (typically 22050 Hz) + * @return ALuint buffer name + */ +static ALuint al_buf_alloc(ALvoid * data, ALsizei size, ALenum al_fmt, ALsizei al_freq) { ALuint al_buf; alGenBuffers(1, &al_buf); @@ -421,10 +421,10 @@ static ALuint al_buf_alloc(ALvoid* data, ALsizei size, ALenum al_fmt, ALsizei al /** -* free the buffer and its contained sound data. -* -* @param al_buf buffer name -*/ + * free the buffer and its contained sound data. + * + * @param al_buf buffer name + */ static void al_buf_free(ALuint al_buf) { // no-op if 0 (needed in case SndData_reload fails - @@ -441,9 +441,9 @@ static void al_buf_free(ALuint al_buf) /** -* make sure all buffers have been returned to us via al_buf_free. -* called from al_shutdown. -*/ + * make sure all buffers have been returned to us via al_buf_free. + * called from al_shutdown. + */ static void al_buf_shutdown() { if(al_bufs_outstanding != 0) @@ -474,9 +474,9 @@ static uint al_src_cap = AL_SRC_MAX; /** -* grab as many sources as possible up to the limit. -* called from al_init. -*/ + * grab as many sources as possible up to the limit. + * called from al_init. + */ static void al_src_init() { // grab as many sources as possible and count how many we get. @@ -501,10 +501,10 @@ static void al_src_init() /** -* release all sources on freelist (currently stack). -* all sources must have been returned to us via al_src_free. -* called from al_shutdown. -*/ + * release all sources on freelist (currently stack). + * all sources must have been returned to us via al_src_free. + * called from al_shutdown. + */ static void al_src_shutdown() { debug_assert(al_src_used == 0); @@ -515,10 +515,10 @@ static void al_src_shutdown() /** -* try to allocate a source. -* -* @return ALuint source name, or 0 if none available -*/ + * try to allocate a source. + * + * @return ALuint source name, or 0 if none available + */ static ALuint al_src_alloc() { // no more to give @@ -530,10 +530,10 @@ static ALuint al_src_alloc() /** -* mark a source as free and available for reuse. -* -* @param al_src source name -*/ + * mark a source as free and available for reuse. + * + * @param al_src source name + */ static void al_src_free(ALuint al_src) { debug_assert(alIsSource(al_src)); @@ -545,14 +545,14 @@ static void al_src_free(ALuint al_src) /** -* set maximum number of voices to play simultaneously, -* to reduce mixing cost on low-end systems. -* this limit may be ignored if e.g. there's a stricter -* implementation- defined ceiling anyway. -* -* @param limit max. number of sources -* @return LibError -*/ + * set maximum number of voices to play simultaneously, + * to reduce mixing cost on low-end systems. + * this limit may be ignored if e.g. there's a stricter + * implementation- defined ceiling anyway. + * + * @param limit max. number of sources + * @return LibError + */ LibError snd_set_max_voices(uint limit) { // valid if cap is legit (less than what we allocated in al_src_init), @@ -582,11 +582,11 @@ LibError snd_set_max_voices(uint limit) /////////////////////////////////////////////////////////////////////////////// /** -* master OpenAL init; makes sure all subsystems are ready for use. -* called from each snd_open; no harm if called more than once. -* -* @return LibError -*/ + * master OpenAL init; makes sure all subsystems are ready for use. + * called from each snd_open; no harm if called more than once. + * + * @return LibError + */ static LibError al_init() { // only take action on first call, OR when re-initializing. @@ -606,8 +606,8 @@ static LibError al_init() /** -* shut down all module subsystems. -*/ + * shut down all module subsystems. + */ static void al_shutdown() { // was never initialized - nothing to do. @@ -636,10 +636,10 @@ static void al_shutdown() /** -* re-initialize OpenAL. currently only required for changing devices. -* -* @return LibError -*/ + * re-initialize OpenAL. currently only required for changing devices. + * + * @return LibError + */ static LibError al_reinit() { // not yet initialized. settings have been saved, and will be @@ -663,19 +663,19 @@ static LibError al_reinit() // set by snd_dev_prepare_enum; used by snd_dev_next. // consists of back-to-back C strings, terminated by an extra '\0'. // (this is taken straight from OpenAL; dox say this format may change). -static const char* devs; +static const char * devs; /** -* Prepare to enumerate all device names (this resets the list returned by -* snd_dev_next). -* -* may be called each time the device list is needed. -* -* @return LibError; always successful unless the requisite device -* enumeration extension isn't available. in the latter case, -* a "cannot enum device" message should be presented to the user, -* and snd_dev_set need not be called; OpenAL will use its default device. -*/ + * Prepare to enumerate all device names (this resets the list returned by + * snd_dev_next). + * + * may be called each time the device list is needed. + * + * @return LibError; always successful unless the requisite device + * enumeration extension isn't available. in the latter case, + * a "cannot enum device" message should be presented to the user, + * and snd_dev_set need not be called; OpenAL will use its default device. + */ LibError snd_dev_prepare_enum() { if(alcIsExtensionPresent(0, (ALubyte*)"ALC_ENUMERATION_EXT") != AL_TRUE) @@ -687,18 +687,18 @@ LibError snd_dev_prepare_enum() /** -* Get next device name. -* -* do not call unless snd_dev_prepare_enum succeeded! -* not thread-safe! (static data from snd_dev_prepare_enum is used) -* -* @return const char* device name, or 0 if all have been returned -*/ -const char* snd_dev_next() + * Get next device name. + * + * do not call unless snd_dev_prepare_enum succeeded! + * not thread-safe! (static data from snd_dev_prepare_enum is used) + * + * @return const char * device name, or 0 if all have been returned + */ +const char * snd_dev_next() { if(!*devs) return 0; - const char* dev = devs; + const char * dev = devs; devs += strlen(dev)+1; return dev; } @@ -731,18 +731,18 @@ static const int TOTAL_IOS = MAX_STREAMS * MAX_IOS; static const size_t TOTAL_BUF_SIZE = TOTAL_IOS * STREAM_BUF_SIZE; // one large allocation for all buffers -static void* io_bufs; +static void * io_bufs; // list of free buffers. start of buffer holds pointer to next in list. -static void* io_buf_freelist; +static void * io_buf_freelist; /** -* Free an IO buffer. -* -* @param void* IO buffer -*/ -static void io_buf_free(void* p) + * Free an IO buffer. + * + * @param void * IO buffer + */ +static void io_buf_free(void * p) { debug_assert(io_bufs <= p && p <= (char*)io_bufs+TOTAL_BUF_SIZE); *(void**)p = io_buf_freelist; @@ -751,9 +751,9 @@ static void io_buf_free(void* p) /** -* Allocate a memory pool for all IO buffers. -* Called from first io_buf_alloc. -*/ + * Allocate a memory pool for all IO buffers. + * Called from first io_buf_alloc. + */ static void io_buf_init() { // allocate 1 big aligned block for all buffers. @@ -763,7 +763,7 @@ static void io_buf_init() return; // build freelist. - char* p = (char*)io_bufs; + char * p = (char*)io_bufs; for(int i = 0; i < TOTAL_IOS; i++) { io_buf_free(p); @@ -773,15 +773,15 @@ static void io_buf_init() /** -* Allocate a fixed-size IO buffer. -* -* @return void* buffer, or 0 (and warning) if not enough memory. -*/ -static void* io_buf_alloc() + * Allocate a fixed-size IO buffer. + * + * @return void * buffer, or 0 (and warning) if not enough memory. + */ +static void * io_buf_alloc() { ONCE(io_buf_init()); - void* buf = io_buf_freelist; + void * buf = io_buf_freelist; // note: we have to bail now; can't update io_buf_freelist. if(!buf) { @@ -802,10 +802,10 @@ static void* io_buf_alloc() /** -* Free memory pool holding all IO buffers. -* no-op if io_buf_alloc was never called. -* called by snd_shutdown. -*/ + * Free memory pool holding all IO buffers. + * no-op if io_buf_alloc was never called. + * called by snd_shutdown. + */ static void io_buf_shutdown() { mem_free(io_bufs); @@ -822,32 +822,32 @@ static void io_buf_shutdown() // because we'll only have <= 2 streams active at a time. /** -* Information for streaming sounds from file -* (i.e. loading pieces of it in the background) -*/ + * Information for streaming sounds from file + * (i.e. loading pieces of it in the background) + */ struct Stream { Handle hf; Handle ios[MAX_IOS]; uint active_ios; /// set by stream_buf_get, used by stream_buf_discard to free buf. - void* last_buf; + void * last_buf; }; /** -* Begin reading the next segment (asynchronously). -* Called from SndData_reload and snd_data_buf_get. -* -* @param Stream* -* @return LibError -*/ -static LibError stream_issue(Stream* s) + * Begin reading the next segment (asynchronously). + * Called from SndData_reload and snd_data_buf_get. + * + * @param Stream* + * @return LibError + */ +static LibError stream_issue(Stream * s) { if(s->active_ios >= MAX_IOS) return INFO_OK; - void* buf = io_buf_alloc(); + void * buf = io_buf_alloc(); if(!buf) WARN_RETURN(ERR_NO_MEM); @@ -859,15 +859,15 @@ static LibError stream_issue(Stream* s) /** -* Access the data most recently streamed in. -* -* @param Stream* -* @param data pointer to buffer -* @param size [bytes] -* @return LibError; if the first pending IO hasn't completed, -* ERR_AGAIN (not an error). -*/ -static LibError stream_buf_get(Stream* s, void*& data, size_t& size) + * Access the data most recently streamed in. + * + * @param Stream* + * @param data pointer to buffer + * @param size [bytes] + * @return LibError; if the first pending IO hasn't completed, + * ERR_AGAIN (not an error). + */ +static LibError stream_buf_get(Stream * s, void*& data, size_t& size) { if(s->active_ios == 0) WARN_RETURN(ERR_EOF); @@ -890,16 +890,16 @@ static LibError stream_buf_get(Stream* s, void*& data, size_t& size) /** -* Free the buffer that was last returned by stream_buf_get, -* and remove its IO slot from our queue. -* -* Must be called exactly once after every successful stream_buf_get; -* call before calling any other stream_* functions! -* -* @param Stream* -* @return LibError -*/ -static LibError stream_buf_discard(Stream* s) + * Free the buffer that was last returned by stream_buf_get, + * and remove its IO slot from our queue. + * + * Must be called exactly once after every successful stream_buf_get; + * call before calling any other stream_ * functions! + * + * @param Stream* + * @return LibError + */ +static LibError stream_buf_discard(Stream * s) { Handle hio = s->ios[0]; @@ -922,13 +922,13 @@ static uint active_streams; /** -* open a stream and begin reading from disk. -* -* @param Stream* -* @param fn VFS filename. -* @return LibError -*/ -static LibError stream_open(Stream* s, const char* fn) + * open a stream and begin reading from disk. + * + * @param Stream* + * @param fn VFS filename. + * @return LibError + */ +static LibError stream_open(Stream * s, const char * fn) { // bail because we wouldn't have enough IO buffers for all if(active_streams >= MAX_STREAMS) @@ -946,13 +946,13 @@ static LibError stream_open(Stream* s, const char* fn) /** -* close a stream, which may currently be active. -* -* @param Stream* -* @return LibError - the first error that occurred while waiting for -* IOs / closing file. -*/ -static LibError stream_close(Stream* s) + * close a stream, which may currently be active. + * + * @param Stream* + * @return LibError - the first error that occurred while waiting for + * IOs / closing file. + */ +static LibError stream_close(Stream * s) { LibError ret = INFO_OK; LibError err; @@ -961,7 +961,7 @@ static LibError stream_close(Stream* s) for(uint i = 0; i < s->active_ios; i++) { // .. wait until complete, - void* data; size_t size; // unused + void * data; size_t size; // unused do err = stream_buf_get(s, data, size); while(err == ERR_AGAIN); @@ -985,12 +985,12 @@ static LibError stream_close(Stream* s) /** -* Make sure the given Stream is valid/self-consistent. -* -* @param const Stream* -* @return LibError -*/ -static LibError stream_validate(const Stream* s) + * Make sure the given Stream is valid/self-consistent. + * + * @param const Stream* + * @return LibError + */ +static LibError stream_validate(const Stream * s) { if(s->active_ios > MAX_IOS) WARN_RETURN(ERR_1); @@ -1023,8 +1023,8 @@ static LibError stream_validate(const Stream* s) // IOs are passed to OpenAL and then discarded immediately. /** -* Holder for sound data - either a clip, or stream. -*/ + * Holder for sound data - either a clip, or stream. + */ struct SndData { // stream @@ -1040,19 +1040,19 @@ struct SndData #ifdef OGG_HACK // pointer to Ogg instance -void* o; +void * o; #endif }; H_TYPE_DEFINE(SndData); -static void SndData_init(SndData* sd, va_list args) +static void SndData_init(SndData * sd, va_list args) { // olsner: pass as int instead of bool for GCC compat. sd->is_stream = va_arg(args, int) != 0; } -static void SndData_dtor(SndData* sd) +static void SndData_dtor(SndData * sd) { // in case reload failed and the following haven't been initialized yet // (freeing them would fail in that case, so bail) @@ -1071,7 +1071,7 @@ if(sd->o) ogg_release(sd->o); static void hsd_list_add(Handle hsd); -static LibError SndData_reload(SndData* sd, const char* fn, Handle hsd) +static LibError SndData_reload(SndData * sd, const char * fn, Handle hsd) { hsd_list_add(hsd); @@ -1086,7 +1086,7 @@ static LibError SndData_reload(SndData* sd, const char* fn, Handle hsd) } file_type; - const char* ext = path_extension(fn); + const char * ext = path_extension(fn); // .. OGG (data will be passed directly to OpenAL) if(!stricmp(ext, "ogg")) { @@ -1132,12 +1132,12 @@ static LibError SndData_reload(SndData* sd, const char* fn, Handle hsd) size_t file_size; RETURN_ERR(vfs_load(fn, file, file_size)); - ALvoid* al_data = (ALvoid*)file; + ALvoid * al_data = (ALvoid*)file; ALsizei al_size = (ALsizei)file_size; if(file_type == FT_WAV) { - ALbyte* memory = (ALbyte*)file; + ALbyte * memory = (ALbyte*)file; ALboolean al_loop; // unused alutLoadWAVMemory(memory, &sd->al_fmt, &al_data, &al_size, &sd->al_freq, &al_loop); } @@ -1178,7 +1178,7 @@ else return INFO_OK; } -static LibError SndData_validate(const SndData* sd) +static LibError SndData_validate(const SndData * sd) { if(sd->al_fmt == 0) WARN_RETURN(ERR_11); @@ -1193,25 +1193,25 @@ static LibError SndData_validate(const SndData* sd) return INFO_OK; } -static LibError SndData_to_string(const SndData* sd, char* buf) +static LibError SndData_to_string(const SndData * sd, char * buf) { - const char* type = sd->is_stream? "stream" : "clip"; + const char * type = sd->is_stream? "stream" : "clip"; snprintf(buf, H_STRING_LEN, "%s; al_buf=%d", type, sd->al_buf); return INFO_OK; } /** -* open and return a handle to a sound file's data. -* -* @param fn VFS filename -* @param is_stream (default false) indicates whether this file should be -* streamed in (opening is faster, it won't be kept in memory, but -* only one instance can be open at a time; makes sense for large music files) -* or loaded immediately. -* @return Handle or LibError on failure -*/ -static Handle snd_data_load(const char* fn, bool is_stream) + * open and return a handle to a sound file's data. + * + * @param fn VFS filename + * @param is_stream (default false) indicates whether this file should be + * streamed in (opening is faster, it won't be kept in memory, but + * only one instance can be open at a time; makes sense for large music files) + * or loaded immediately. + * @return Handle or LibError on failure + */ +static Handle snd_data_load(const char * fn, bool is_stream) { // don't allow reloading stream objects // (both references would read from the same file handle). @@ -1224,11 +1224,11 @@ static Handle snd_data_load(const char* fn, bool is_stream) /** -* Free the sound. -* -* @param hsd Handle to SndData; set to 0 afterwards. -* @return LibError -*/ + * Free the sound. + * + * @param hsd Handle to SndData; set to 0 afterwards. + * @return LibError + */ static LibError snd_data_free(Handle& hsd) { return h_free(hsd, H_SndData); @@ -1260,10 +1260,10 @@ typedef std::vector Handles; static Handles hsd_list; /** -* Add hsd to the list. -* called from SndData_reload; will later be removed via hsd_list_free_all. -* @param hsd Handle to SndData -*/ + * Add hsd to the list. + * called from SndData_reload; will later be removed via hsd_list_free_all. + * @param hsd Handle to SndData + */ static void hsd_list_add(Handle hsd) { hsd_list.push_back(hsd); @@ -1271,9 +1271,9 @@ static void hsd_list_add(Handle hsd) /** -* Free all sounds on list. -* called by al_shutdown (at exit, or when reinitializing OpenAL). -*/ + * Free all sounds on list. + * called by al_shutdown (at exit, or when reinitializing OpenAL). + */ static void hsd_list_free_all() { for(Handles::iterator it = hsd_list.begin(); it != hsd_list.end(); ++it) @@ -1297,17 +1297,17 @@ static void hsd_list_free_all() /////////////////////////////////////////////////////////////////////////////// /** -* Get the sound's AL buffer (typically to play it) -* -* @param hsd Handle to SndData. -* @param al_buf buffer name. -* @return LibError, most commonly: -* INFO_OK = buffer has been returned; more are expected to be available. -* ERR_EOF = buffer has been returned but is the last one -* (end of file reached) -* ERR_AGAIN = no buffer returned yet; still streaming in ATM. -* call back later. -*/ + * Get the sound's AL buffer (typically to play it) + * + * @param hsd Handle to SndData. + * @param al_buf buffer name. + * @return LibError, most commonly: + * INFO_OK = buffer has been returned; more are expected to be available. + * ERR_EOF = buffer has been returned but is the last one + * (end of file reached) + * ERR_AGAIN = no buffer returned yet; still streaming in ATM. + * call back later. + */ static LibError snd_data_buf_get(Handle hsd, ALuint& al_buf) { LibError err = INFO_OK; @@ -1327,7 +1327,7 @@ static LibError snd_data_buf_get(Handle hsd, ALuint& al_buf) // stream: // .. check if IO finished. - void* data; + void * data; size_t size; err = stream_buf_get(&sd->s, data, size); if(err == ERR_AGAIN) @@ -1351,12 +1351,12 @@ static LibError snd_data_buf_get(Handle hsd, ALuint& al_buf) /** -* Indicate the sound's buffer is no longer needed. -* -* @param hsd Handle to SndData. -* @param al_buf buffer name -* @return LibError -*/ + * Indicate the sound's buffer is no longer needed. + * + * @param hsd Handle to SndData. + * @param al_buf buffer name + * @return LibError + */ static LibError snd_data_buf_free(Handle hsd, ALuint al_buf) { H_DEREF(hsd, SndData, sd); @@ -1377,8 +1377,8 @@ static LibError snd_data_buf_free(Handle hsd, ALuint al_buf) //----------------------------------------------------------------------------- /** -* control block for a fade operation. -*/ + * control block for a fade operation. + */ struct FadeInfo { double start_time; @@ -1409,8 +1409,8 @@ static float fade_factor_s_curve(float t) /** -* fade() return value; indicates if the fade operation is complete. -*/ + * fade() return value; indicates if the fade operation is complete. + */ enum FadeRet { FADE_NO_CHANGE, @@ -1419,18 +1419,18 @@ enum FadeRet }; /** -* Carry out the requested fade operation. -* -* This is called for each active VSrc; if they have no fade operation -* active, nothing happens. Note: as an optimization, we could make a -* list of VSrc with fade active and only call this for those; -* not yet necessary, though. -* -* @param fi Describes the fade operation -* @param cur_time typically returned via get_time() -* @param out_val Output gain value, i.e. the current result of the fade. -* @return FadeRet -*/ + * Carry out the requested fade operation. + * + * This is called for each active VSrc; if they have no fade operation + * active, nothing happens. Note: as an optimization, we could make a + * list of VSrc with fade active and only call this for those; + * not yet necessary, though. + * + * @param fi Describes the fade operation + * @param cur_time typically returned via get_time() + * @param out_val Output gain value, i.e. the current result of the fade. + * @return FadeRet + */ static FadeRet fade(FadeInfo& fi, double cur_time, float& out_val) { // no fade in progress - abort immediately. this check is necessary to @@ -1488,11 +1488,11 @@ static FadeRet fade(FadeInfo& fi, double cur_time, float& out_val) /** -* Is the fade operation currently active? -* -* @param FadeInfo -* @return bool -*/ + * Is the fade operation currently active? + * + * @param FadeInfo + * @return bool + */ static bool fade_is_active(FadeInfo& fi) { return (fi.type != FT_NONE); @@ -1528,10 +1528,10 @@ enum VSrcFlags }; /** -* control block for a virtual source, which represents a sound that the -* application wants played. it may or may not be played, depending on -* priority and whether an actual OpenAL source is available. -*/ + * control block for a virtual source, which represents a sound that the + * application wants played. it may or may not be played, depending on + * priority and whether an actual OpenAL source is available. + */ struct VSrc { /// handle to this VSrc, so that it can close itself. @@ -1561,16 +1561,16 @@ struct VSrc H_TYPE_DEFINE(VSrc); -static void VSrc_init(VSrc* vs, va_list args) +static void VSrc_init(VSrc * vs, va_list args) { vs->flags = va_arg(args, uint); vs->fade.type = FT_NONE; } -static void list_remove(VSrc* vs); -static LibError vsrc_reclaim(VSrc* vs); +static void list_remove(VSrc * vs); +static LibError vsrc_reclaim(VSrc * vs); -static void VSrc_dtor(VSrc* vs) +static void VSrc_dtor(VSrc * vs) { // only remove if added (not the case if load failed) if(vs->flags & VS_IN_LIST) @@ -1584,7 +1584,7 @@ static void VSrc_dtor(VSrc* vs) (void)snd_data_free(vs->hsd); } -static LibError VSrc_reload(VSrc* vs, const char* fn, Handle hvs) +static LibError VSrc_reload(VSrc * vs, const char * fn, Handle hvs) { // cannot wait till play(), need to init here: // must load OpenAL so that snd_data_load can check for OGG extension. @@ -1601,12 +1601,12 @@ static LibError VSrc_reload(VSrc* vs, const char* fn, Handle hvs) // and assume default gain (1.0). // - const char* snd_fn; // actual sound file name + const char * snd_fn; // actual sound file name std::string snd_fn_s; // extracted from stringstream; // declare here so that it doesn't go out of scope below. - const char* ext = path_extension(fn); + const char * ext = path_extension(fn); if(!stricmp(ext, "txt")) { FileIOBuf buf; size_t size; @@ -1641,7 +1641,7 @@ static LibError VSrc_reload(VSrc* vs, const char* fn, Handle hvs) return INFO_OK; } -static LibError VSrc_validate(const VSrc* vs) +static LibError VSrc_validate(const VSrc * vs) { // al_src can legitimately be 0 (if vs is low-pri) if(vs->flags & ~VS_ALL_FLAGS) @@ -1657,7 +1657,7 @@ static LibError VSrc_validate(const VSrc* vs) return INFO_OK; } -static LibError VSrc_to_string(const VSrc* vs, char* buf) +static LibError VSrc_to_string(const VSrc * vs, char * buf) { snprintf(buf, H_STRING_LEN, "al_src = %d", vs->al_src); return INFO_OK; @@ -1665,20 +1665,20 @@ static LibError VSrc_to_string(const VSrc* vs, char* buf) /** -* open and return a handle to a sound instance. -* -* @param snd_fn VFS filename. if a text file (extension ".txt"), -* it is assumed to be a definition file containing the -* sound file name and its gain (0.0 .. 1.0). -* otherwise, it is taken to be the sound file name and -* gain is set to the default of 1.0 (no attenuation). -* @param is_stream (default false) indicates whether this file should be -* streamed in (opening is faster, it won't be kept in memory, but -* only one instance can be open at a time; makes sense for large music files) -* or loaded immediately. -* @return Handle or LibError on failure -*/ -Handle snd_open(const char* snd_fn, bool is_stream) + * open and return a handle to a sound instance. + * + * @param snd_fn VFS filename. if a text file (extension ".txt"), + * it is assumed to be a definition file containing the + * sound file name and its gain (0.0 .. 1.0). + * otherwise, it is taken to be the sound file name and + * gain is set to the default of 1.0 (no attenuation). + * @param is_stream (default false) indicates whether this file should be + * streamed in (opening is faster, it won't be kept in memory, but + * only one instance can be open at a time; makes sense for large music files) + * or loaded immediately. + * @return Handle or LibError on failure + */ +Handle snd_open(const char * snd_fn, bool is_stream) { uint flags = 0; if(is_stream) @@ -1690,13 +1690,13 @@ Handle snd_open(const char* snd_fn, bool is_stream) /** -* Free the sound; if it was playing, it will be stopped. -* Note: sounds are closed automatically when done playing; -* this is provided for completeness only. -* -* @param hvs Handle to VSrc. will be set to 0 afterwards. -* @return LibError -*/ + * Free the sound; if it was playing, it will be stopped. + * Note: sounds are closed automatically when done playing; + * this is provided for completeness only. + * + * @param hvs Handle to VSrc. will be set to 0 afterwards. + * @return LibError + */ LibError snd_free(Handle& hvs) { return h_free(hvs, H_VSrc); @@ -1721,19 +1721,19 @@ typedef VSrcs::iterator It; static VSrcs vsrcs; // don't need to sort now - caller will list_sort() during update. -static void list_add(VSrc* vs) +static void list_add(VSrc * vs) { vsrcs.push_back(vs); } /** -* call back for each VSrc entry in the list. -* -* @param cb Callback function -* @param skip number of entries to skip (default 0) -* @param end_idx if not the default value of 0, stop before that entry. -*/ + * call back for each VSrc entry in the list. + * + * @param cb Callback function + * @param skip number of entries to skip (default 0) + * @param end_idx if not the default value of 0, stop before that entry. + */ static void list_foreach(void (*cb)(VSrc*), uint skip = 0, uint end_idx = 0) { It begin = vsrcs.begin() + skip; @@ -1745,14 +1745,14 @@ static void list_foreach(void (*cb)(VSrc*), uint skip = 0, uint end_idx = 0) // (i.e. set to 0) since last update. for(It it = begin; it != end; ++it) { - VSrc* vs = *it; + VSrc * vs = *it; if(vs) cb(vs); } } -static bool is_greater(const VSrc* vs1, const VSrc* vs2) +static bool is_greater(const VSrc * vs1, const VSrc * vs2) { return vs1->cur_pri > vs2->cur_pri; } @@ -1765,13 +1765,13 @@ static void list_sort() /** -* scan list and remove the given VSrc (by setting it to 0; list will be -* pruned later (see rationale below). -* O(N)! -* -* @param vs VSrc to remove. -*/ -static void list_remove(VSrc* vs) + * scan list and remove the given VSrc (by setting it to 0; list will be + * pruned later (see rationale below). + * O(N)! + * + * @param vs VSrc to remove. + */ +static void list_remove(VSrc * vs) { for(size_t i = 0; i < vsrcs.size(); i++) { @@ -1792,12 +1792,12 @@ static void list_remove(VSrc* vs) } -static bool is_null(VSrc* vs) { return (vs == 0); } +static bool is_null(VSrc * vs) { return (vs == 0); } /** -* remove entries that were set to 0 by list_remove, so that -* code below can grant the first al_src_cap entries a soure. -*/ + * remove entries that were set to 0 by list_remove, so that + * code below can grant the first al_src_cap entries a soure. + */ static void list_prune_removed() { It new_end = remove_if(vsrcs.begin(), vsrcs.end(), is_null); @@ -1805,7 +1805,7 @@ static void list_prune_removed() } -static void vsrc_free(VSrc* vs) { snd_free(vs->hvs); } +static void vsrc_free(VSrc * vs) { snd_free(vs->hvs); } static LibError list_free_all() { @@ -1817,12 +1817,12 @@ static LibError list_free_all() /////////////////////////////////////////////////////////////////////////////// /** -* Send the VSrc properties to OpenAL (when we actually have a source). -* called by snd_set* and vsrc_grant. -* -* @param VSrc* -*/ -static void vsrc_latch(VSrc* vs) + * Send the VSrc properties to OpenAL (when we actually have a source). + * called by snd_set * and vsrc_grant. + * + * @param VSrc* + */ +static void vsrc_latch(VSrc * vs) { if(!vs->al_src) return; @@ -1848,12 +1848,12 @@ static void vsrc_latch(VSrc* vs) /** -* Dequeue any of the VSrc's sound buffers that are finished playing. -* -* @param VSrc* -* @return int number of entries that were removed. -*/ -static int vsrc_deque_finished_bufs(VSrc* vs) + * Dequeue any of the VSrc's sound buffers that are finished playing. + * + * @param VSrc* + * @return int number of entries that were removed. + */ +static int vsrc_deque_finished_bufs(VSrc * vs) { int num_processed; alGetSourcei(vs->al_src, AL_BUFFERS_PROCESSED, &num_processed); @@ -1877,13 +1877,13 @@ static int vsrc_deque_finished_bufs(VSrc* vs) static double snd_update_time; /** -* Update the VSrc - perform fade (if active), queue/unqueue buffers. -* Called once a frame. -* -* @param VSrc* -* @return LibError -*/ -static LibError vsrc_update(VSrc* vs) + * Update the VSrc - perform fade (if active), queue/unqueue buffers. + * Called once a frame. + * + * @param VSrc* + * @return LibError + */ +static LibError vsrc_update(VSrc * vs) { if(!vs->al_src) return INFO_OK; @@ -1948,13 +1948,13 @@ static LibError vsrc_update(VSrc* vs) /** -* Try to give the VSrc an AL source so that it can (re)start playing. -* called by snd_play and voice management. -* -* @param VSrc* -* @return LibError (ERR_FAIL if no AL source is available) -*/ -static LibError vsrc_grant(VSrc* vs) + * Try to give the VSrc an AL source so that it can (re)start playing. + * called by snd_play and voice management. + * + * @param VSrc* + * @return LibError (ERR_FAIL if no AL source is available) + */ +static LibError vsrc_grant(VSrc * vs) { // already playing - bail if(vs->al_src) @@ -1988,14 +1988,14 @@ static LibError vsrc_grant(VSrc* vs) /** -* stop playback, and reclaim the OpenAL source. -* called when closing the VSrc, or when voice management decides -* this VSrc must yield to others of higher priority. -* -* @param VSrc* -* @return LibError -*/ -static LibError vsrc_reclaim(VSrc* vs) + * stop playback, and reclaim the OpenAL source. + * called when closing the VSrc, or when voice management decides + * this VSrc must yield to others of higher priority. + * + * @param VSrc* + * @return LibError + */ +static LibError vsrc_reclaim(VSrc * vs) { // don't own a source - bail. if(!vs->al_src) @@ -2016,19 +2016,19 @@ static LibError vsrc_reclaim(VSrc* vs) /////////////////////////////////////////////////////////////////////////////// /** -* Request the sound be played. -* -* Once done playing, the sound is automatically closed (allows -* fire-and-forget play code). -* if no hardware voice is available, this sound may not be played at all, -* or in the case of looped sounds, start later. -* -* @param hvs Handle to VSrc -* @param static_pri (min 0 .. max 1, default 0) indicates which sounds are -* considered more important; this is attenuated by distance to the -* listener (see snd_update). -* @return LibError -*/ + * Request the sound be played. + * + * Once done playing, the sound is automatically closed (allows + * fire-and-forget play code). + * if no hardware voice is available, this sound may not be played at all, + * or in the case of looped sounds, start later. + * + * @param hvs Handle to VSrc + * @param static_pri (min 0 .. max 1, default 0) indicates which sounds are + * considered more important; this is attenuated by distance to the + * listener (see snd_update). + * @return LibError + */ LibError snd_play(Handle hvs, float static_pri) { H_DEREF(hvs, VSrc, vs); @@ -2049,17 +2049,17 @@ LibError snd_play(Handle hvs, float static_pri) /** -* Change 3d position of the sound source. -* -* May be called at any time; fails with invalid handle return if -* the sound has already been closed (e.g. it never played). -* -* @param hvs Handle to VSrc -* @param x,y,z coordinates (interpretation: see below) -* @param relative if true, (x,y,z) is treated as relative to the listener; -* otherwise, it is the position in world coordinates (default). -* @return LibError -*/ + * Change 3d position of the sound source. + * + * May be called at any time; fails with invalid handle return if + * the sound has already been closed (e.g. it never played). + * + * @param hvs Handle to VSrc + * @param x,y,z coordinates (interpretation: see below) + * @param relative if true, (x,y,z) is treated as relative to the listener; + * otherwise, it is the position in world coordinates (default). + * @return LibError + */ LibError snd_set_pos(Handle hvs, float x, float y, float z, bool relative) { H_DEREF(hvs, VSrc, vs); @@ -2073,17 +2073,17 @@ LibError snd_set_pos(Handle hvs, float x, float y, float z, bool relative) /** -* Change gain (amplitude modifier) of the sound source. -* -* should not be called during a fade (see note in implementation); -* fails with invalid handle return if the sound has already been -* closed (e.g. it never played). -* -* @param hvs Handle to VSrc -* @param gain modifier; must be non-negative; -* 1 -> unattenuated, 0.5 -> -6 dB, 0 -> silence. -* @return LibError -*/ + * Change gain (amplitude modifier) of the sound source. + * + * should not be called during a fade (see note in implementation); + * fails with invalid handle return if the sound has already been + * closed (e.g. it never played). + * + * @param hvs Handle to VSrc + * @param gain modifier; must be non-negative; + * 1 -> unattenuated, 0.5 -> -6 dB, 0 -> silence. + * @return LibError + */ LibError snd_set_gain(Handle hvs, float gain) { H_DEREF(hvs, VSrc, vs); @@ -2105,16 +2105,16 @@ LibError snd_set_gain(Handle hvs, float gain) /** -* Change pitch shift of the sound source. -* -* may be called at any time; fails with invalid handle return if -* the sound has already been closed (e.g. it never played). -* -* @param hvs Handle to VSrc -* @param pitch shift: 1.0 means no change; each reduction by 50% equals a -* pitch shift of -12 semitones (one octave). zero is invalid. -* @return LibError -*/ + * Change pitch shift of the sound source. + * + * may be called at any time; fails with invalid handle return if + * the sound has already been closed (e.g. it never played). + * + * @param hvs Handle to VSrc + * @param pitch shift: 1.0 means no change; each reduction by 50% equals a + * pitch shift of -12 semitones (one octave). zero is invalid. + * @return LibError + */ LibError snd_set_pitch(Handle hvs, float pitch) { H_DEREF(hvs, VSrc, vs); @@ -2130,22 +2130,22 @@ LibError snd_set_pitch(Handle hvs, float pitch) /** -* Enable/disable looping on the sound source. -* used to implement variable-length sounds (e.g. while building). -* -* may be called at any time; fails with invalid handle return if -* the sound has already been closed (e.g. it never played). -* -* notes: -* - looping sounds are not discarded if they cannot be played for lack of -* a hardware voice at the moment play was requested. -* - once looping is again disabled and the sound has reached its end, -* the sound instance is freed automatically (as if never looped). -* -* @param hvs Handle to VSrc -* @param bool loop -* @return LibError -*/ + * Enable/disable looping on the sound source. + * used to implement variable-length sounds (e.g. while building). + * + * may be called at any time; fails with invalid handle return if + * the sound has already been closed (e.g. it never played). + * + * notes: + * - looping sounds are not discarded if they cannot be played for lack of + * a hardware voice at the moment play was requested. + * - once looping is again disabled and the sound has reached its end, + * the sound instance is freed automatically (as if never looped). + * + * @param hvs Handle to VSrc + * @param bool loop + * @return LibError + */ LibError snd_set_loop(Handle hvs, bool loop) { H_DEREF(hvs, VSrc, vs); @@ -2158,34 +2158,34 @@ LibError snd_set_loop(Handle hvs, bool loop) /** -* Fade the sound source in or out over time. -* Its gain starts at immediately and is moved toward -* over seconds. -* -* may be called at any time; fails with invalid handle return if -* the sound has already been closed (e.g. it never played). -* -* note that this function doesn't busy-wait until the fade is complete; -* any number of fades may be active at a time (allows cross-fading). -* each snd_update calculates a new gain value for all pending fades. -* it is safe to start another fade on the same sound source while -* one is currently in progress; the old one is dropped. -* -* @param hvs Handle to VSrc -* @param initial_gain gain. if < 0 (an otherwise illegal value), the sound's -* current gain is used as the start value (useful for fading out). -* @param final_gain gain. if 0, the sound is freed when the fade completes or -* is aborted, thus allowing fire-and-forget fadeouts. no cases are -* foreseen where this is undesirable, and it is easier to implement -* than an extra set-free-after-fade-flag function. -* @param length duration of fade [s] -* @param type determines the fade curve: linear, exponential or S-curve. -* for guidance on which to use, see -* http://www.transom.org/tools/editing_mixing/200309.stupidfadetricks.html -* you can also pass FT_ABORT to stop fading (if in progress) and -* set gain to the final_gain parameter passed here. -* @return LibError -*/ + * Fade the sound source in or out over time. + * Its gain starts at immediately and is moved toward + * over seconds. + * + * may be called at any time; fails with invalid handle return if + * the sound has already been closed (e.g. it never played). + * + * note that this function doesn't busy-wait until the fade is complete; + * any number of fades may be active at a time (allows cross-fading). + * each snd_update calculates a new gain value for all pending fades. + * it is safe to start another fade on the same sound source while + * one is currently in progress; the old one is dropped. + * + * @param hvs Handle to VSrc + * @param initial_gain gain. if < 0 (an otherwise illegal value), the sound's + * current gain is used as the start value (useful for fading out). + * @param final_gain gain. if 0, the sound is freed when the fade completes or + * is aborted, thus allowing fire-and-forget fadeouts. no cases are + * foreseen where this is undesirable, and it is easier to implement + * than an extra set-free-after-fade-flag function. + * @param length duration of fade [s] + * @param type determines the fade curve: linear, exponential or S-curve. + * for guidance on which to use, see + * http://www.transom.org/tools/editing_mixing/200309.stupidfadetricks.html + * you can also pass FT_ABORT to stop fading (if in progress) and + * set gain to the final_gain parameter passed here. + * @return LibError + */ LibError snd_fade(Handle hvs, float initial_gain, float final_gain, float length, FadeType type) { @@ -2231,13 +2231,13 @@ static float magnitude_2(const float v[3]) /** -* determine new priority of the VSrc based on distance to listener and -* static priority. -* called via list_foreach. -* -* @param VSrc* -*/ -static void calc_cur_pri(VSrc* vs) + * determine new priority of the VSrc based on distance to listener and + * static priority. + * called via list_foreach. + * + * @param VSrc* + */ +static void calc_cur_pri(VSrc * vs) { const float MAX_DIST_2 = 1000.0f; const float falloff = 10.0f; @@ -2260,10 +2260,10 @@ static void calc_cur_pri(VSrc* vs) /** -* convenience function that strips all unimportant VSrc of their AL source. -* called via list_foreach; also immediately frees discarded clips. -*/ -static void reclaim(VSrc* vs) + * convenience function that strips all unimportant VSrc of their AL source. + * called via list_foreach; also immediately frees discarded clips. + */ +static void reclaim(VSrc * vs) { vsrc_reclaim(vs); @@ -2272,18 +2272,18 @@ static void reclaim(VSrc* vs) } /// thunk that allows calling via list_foreach (return types differ) -static void grant(VSrc* vs) +static void grant(VSrc * vs) { vsrc_grant(vs); } /** -* update voice management, i.e. recalculate priority and assign AL sources. -* no-op if OpenAL not yet initialized. -* -* @return LibError -*/ + * update voice management, i.e. recalculate priority and assign AL sources. + * no-op if OpenAL not yet initialized. + * + * @return LibError + */ static LibError vm_update() { list_prune_removed(); @@ -2308,16 +2308,16 @@ static LibError vm_update() /////////////////////////////////////////////////////////////////////////////// /** -* perform housekeeping (e.g. streaming); call once a frame. -* -* @param pos position support vector. if NULL, all parameters are -* ignored and listener position unchanged; this is useful in case the -* world isn't initialized yet. -* @param dir view direction -* @param up up vector -* @return LibError -*/ -LibError snd_update(const float* pos, const float* dir, const float* up) + * perform housekeeping (e.g. streaming); call once a frame. + * + * @param pos position support vector. if NULL, all parameters are + * ignored and listener position unchanged; this is useful in case the + * world isn't initialized yet. + * @param dir view direction + * @param up up vector + * @return LibError + */ +LibError snd_update(const float * pos, const float * dir, const float * up) { // there's no sense in updating anything if we weren't initialized // yet (most notably, if sound is disabled). we check for this to @@ -2344,11 +2344,11 @@ LibError snd_update(const float* pos, const float* dir, const float* up) static bool snd_disabled = false; /** -* extra layer on top of al_init that allows 'disabling' sound. -* called from each snd_open. -* -* @return LibError from al_init, or ERR_AGAIN if sound disabled -*/ + * extra layer on top of al_init that allows 'disabling' sound. + * called from each snd_open. + * + * @return LibError from al_init, or ERR_AGAIN if sound disabled + */ static inline LibError snd_init() { // (note: each VSrc_reload and therefore snd_open will fail) @@ -2360,21 +2360,21 @@ static inline LibError snd_init() /** -* (temporarily) disable all sound output. because it causes future snd_open -* calls to immediately abort before they demand-initialize OpenAL, -* startup is sped up considerably (500..1000ms). therefore, this must be -* called before the first snd_open to have any effect; otherwise, the -* cat will already be out of the bag and we debug_warn of it. -* -* rationale: this is a quick'n dirty way of speeding up startup during -* development without having to change the game's sound code. -* -* can later be called to reactivate sound; all settings ever changed -* will be applied and subsequent sound load / play requests will work. -* -* @param bool disabled -* @return LibError -*/ + * (temporarily) disable all sound output. because it causes future snd_open + * calls to immediately abort before they demand-initialize OpenAL, + * startup is sped up considerably (500..1000ms). therefore, this must be + * called before the first snd_open to have any effect; otherwise, the + * cat will already be out of the bag and we debug_warn of it. + * + * rationale: this is a quick'n dirty way of speeding up startup during + * development without having to change the game's sound code. + * + * can later be called to reactivate sound; all settings ever changed + * will be applied and subsequent sound load / play requests will work. + * + * @param bool disabled + * @return LibError + */ LibError snd_disable(bool disabled) { snd_disabled = disabled; @@ -2392,9 +2392,9 @@ LibError snd_disable(bool disabled) /** -* free all resources and shut down the sound system. -* call before h_mgr_shutdown. -*/ + * free all resources and shut down the sound system. + * call before h_mgr_shutdown. + */ void snd_shutdown() { io_buf_shutdown(); diff --git a/source/lib/string_s.cpp b/source/lib/string_s.cpp index 662b7458d8..b72a298394 100644 --- a/source/lib/string_s.cpp +++ b/source/lib/string_s.cpp @@ -70,10 +70,14 @@ // raise a debug warning if is the size of a pointer. // catches bugs such as: tchar* s = ..; tcpy_s(s, sizeof(s), T("..")); // if warnings get annoying, replace with debug_printf. usable as a statement. -#define WARN_IF_PTR_LEN(len) STMT( \ +// +// currently disabled due to high risk of false positives. +#define WARN_IF_PTR_LEN(len)\ +/* +STMT( \ if(len == sizeof(char*)) \ debug_warn("make sure string buffer size is correct");\ -) +)*/ // skip our implementation if already available, but not the diff --git a/source/lib/tests/test_string_s.h b/source/lib/tests/test_string_s.h index b08c2501e0..162d0b8db2 100644 --- a/source/lib/tests/test_string_s.h +++ b/source/lib/tests/test_string_s.h @@ -119,31 +119,53 @@ public: debug_skip_next_err(ERR_INVALID_PARAM); TEST_CPY(d1,0,s1, ERANGE,""); // max_dst_chars = 0 + debug_skip_next_err(ERR_BUF_SIZE); TEST_CPY2(d1,1, s1, ERANGE,""); + debug_skip_next_err(ERR_BUF_SIZE); TEST_CPY2(d1,1, s5, ERANGE,""); + debug_skip_next_err(ERR_BUF_SIZE); TEST_CPY2(d5,5, s5, ERANGE,""); + debug_skip_next_err(ERR_BUF_SIZE); TEST_NCPY(d1,1 ,s1,1, ERANGE,""); + debug_skip_next_err(ERR_BUF_SIZE); TEST_NCPY(d1,1 ,s5,1, ERANGE,""); + debug_skip_next_err(ERR_BUF_SIZE); TEST_NCPY(d5,5 ,s5,5, ERANGE,""); + debug_skip_next_err(ERR_INVALID_PARAM); TEST_CAT(0 ,0,0 , EINVAL,""); // all invalid + debug_skip_next_err(ERR_INVALID_PARAM); TEST_CAT(0 ,0,s1, EINVAL,""); // dst = 0, max = 0 + debug_skip_next_err(ERR_INVALID_PARAM); TEST_CAT(0 ,1,s1, EINVAL,""); // dst = 0, max > 0 + debug_skip_next_err(ERR_INVALID_PARAM); TEST_CAT(d1,1,0 , EINVAL,""); // src = 0 + debug_skip_next_err(ERR_INVALID_PARAM); TEST_CAT(d1,0,s1, ERANGE,""); // max_dst_chars = 0 + debug_skip_next_err(ERR_STRING_NOT_TERMINATED); TEST_CAT(no_null,5,s1, ERANGE,""); // dst not terminated + debug_skip_next_err(ERR_BUF_SIZE); TEST_CAT2(d1,1, s1, "",ERANGE,""); + debug_skip_next_err(ERR_BUF_SIZE); TEST_CAT2(d1,1, s5, "",ERANGE,""); + debug_skip_next_err(ERR_BUF_SIZE); TEST_CAT2(d10,10, s10, "",ERANGE,""); // empty, total overflow + debug_skip_next_err(ERR_BUF_SIZE); TEST_CAT2(d10,10, s5, "12345",ERANGE,""); // not empty, overflow + debug_skip_next_err(ERR_BUF_SIZE); TEST_CAT2(d10,10, s10, "12345",ERANGE,""); // not empty, total overflow + debug_skip_next_err(ERR_BUF_SIZE); TEST_NCAT(d1,1, s1,1, "",ERANGE,""); + debug_skip_next_err(ERR_BUF_SIZE); TEST_NCAT(d1,1, s5,5, "",ERANGE,""); + debug_skip_next_err(ERR_BUF_SIZE); TEST_NCAT(d10,10, s10,10, "",ERANGE,""); // empty, total overflow + debug_skip_next_err(ERR_BUF_SIZE); TEST_NCAT(d10,10, s5,5, "12345",ERANGE,""); // not empty, overflow + debug_skip_next_err(ERR_BUF_SIZE); TEST_NCAT(d10,10, s10,10, "12345",ERANGE,""); // not empty, total overflow #endif } @@ -179,7 +201,6 @@ public: strcpy(d5, "----"); TEST_NCPY(d5,5, s5,0 , 0,""); // specified behavior! see 3.6.2.1.1 #4 TEST_NCPY(d5,5, s5,1 , 0,"a"); - TEST_NCPY(d5,5, s5,4 , 0,"abcd"); TEST_NCPY(d6,6, s5,5 , 0,"abcde"); TEST_NCPY(d6,6, s5,10, 0,"abcde"); }