Christian Ohm schreef: > On Wednesday, 23 May 2007 at 22:46, Giel van Schijndel wrote: > >> Christian Ohm schreef: >> >>> Some g++ fixes again. "new" is a reserved keyword, a few casts, and I've >>> moved OggVorbisDecoderState into oggvorbis.h, there was a linker error >>> when it was typedeffed to void in some cases. Don't know why it was done >>> that way, still works for me now. I've removed an #ifdef WZ_NOOGG, but >>> ./configure --disable-ogg was broken before anyway. >>> >> That double typedef was done to encapsulate the OggVorbis decoding code, >> compare it to a C++ pimpl if you wish. The linker error is caused by >> C++'s function overloading, so the correct fix is not to expose details, >> but disabling function overloading for that function: extern "C". >> > Hm, in C this looks quite inelegant to me; just because the struct is > exposed to the outside doesn't mean you have to access it directly. In > C++ the whole class is exposed as well, you just have the access control > via private (unless you just use pointers to the class; I've thought > about that as well but was too lazy to try to rewrite the code that > way). > I have to agree that it is quite inelegant. Although my approach isn't similar to C++'s private keyword, it's more equal to the Pimpl idiom. ( http://www.gamedev.net/reference/articles/article1794.asp )
However the void* pointer indeed isn't nice. Therefore I've now taken a new approach to this: forward declaration of the struct (which is enough to create a pointer to it). It does, however, require the addition of the keyword 'struct' in front of every declaration of OggVorbisDecoderState or pointers to it. Patch is attached for review. I haven't looked into a typedef solution to eliminate the struct keyword yet, so if you happen to know one right away, please tell me. -- Giel
Index: lib/sound/cdaudio.c =================================================================== --- lib/sound/cdaudio.c (revision 1337) +++ lib/sound/cdaudio.c (working copy) @@ -52,7 +52,7 @@ static ALuint music_buffers[NB_BUFFERS]; static ALuint music_source; -OggVorbisDecoderState* decoder = NULL; +struct OggVorbisDecoderState* decoder = NULL; static inline unsigned int numProcessedBuffers(void) { Index: lib/sound/oggvorbis.c =================================================================== --- lib/sound/oggvorbis.c (revision 1337) +++ lib/sound/oggvorbis.c (working copy) @@ -30,7 +30,9 @@ #define OGG_ENDIAN 0 #endif -typedef struct +#include "oggvorbis.h" + +struct OggVorbisDecoderState { // Internal identifier towards PhysicsFS PHYSFS_file* fileHandle; @@ -43,20 +45,17 @@ // Internal meta data vorbis_info* VorbisInfo; -} OggVorbisDecoderState; +}; -#define _LIBSOUND_OGGVORBIS_C_ -#include "oggvorbis.h" - static size_t wz_oggVorbis_read(void *ptr, size_t size, size_t nmemb, void *datasource) { - PHYSFS_file* fileHandle = ((OggVorbisDecoderState*)datasource)->fileHandle; + PHYSFS_file* fileHandle = ((struct OggVorbisDecoderState*)datasource)->fileHandle; return PHYSFS_read(fileHandle, ptr, 1, size*nmemb); } static int wz_oggVorbis_seek(void *datasource, ogg_int64_t offset, int whence) { - PHYSFS_file* fileHandle = ((OggVorbisDecoderState*)datasource)->fileHandle; - BOOL allowSeeking = ((OggVorbisDecoderState*)datasource)->allowSeeking; + PHYSFS_file* fileHandle = ((struct OggVorbisDecoderState*)datasource)->fileHandle; + BOOL allowSeeking = ((struct OggVorbisDecoderState*)datasource)->allowSeeking; int curPos, fileSize, newPos; @@ -101,7 +100,7 @@ } static long wz_oggVorbis_tell(void *datasource) { - PHYSFS_file* fileHandle = ((OggVorbisDecoderState*)datasource)->fileHandle; + PHYSFS_file* fileHandle = ((struct OggVorbisDecoderState*)datasource)->fileHandle; return PHYSFS_tell(fileHandle); } @@ -112,11 +111,11 @@ wz_oggVorbis_tell }; -OggVorbisDecoderState* sound_CreateOggVorbisDecoder(PHYSFS_file* PHYSFS_fileHandle, BOOL allowSeeking) +struct OggVorbisDecoderState* sound_CreateOggVorbisDecoder(PHYSFS_file* PHYSFS_fileHandle, BOOL allowSeeking) { int error; - OggVorbisDecoderState* decoder = malloc(sizeof(OggVorbisDecoderState)); + struct OggVorbisDecoderState* decoder = malloc(sizeof(struct OggVorbisDecoderState)); if (decoder == NULL) { debug(LOG_ERROR, "sound_CreateOggVorbisDecoder: couldn't allocate memory\n"); @@ -140,7 +139,7 @@ return decoder; } -void sound_DestroyOggVorbisDecoder(OggVorbisDecoderState* decoder) +void sound_DestroyOggVorbisDecoder(struct OggVorbisDecoderState* decoder) { // Close the OggVorbis decoding stream ov_clear(&decoder->oggVorbis_stream); @@ -148,27 +147,27 @@ free(decoder); } -static inline unsigned int getSampleCount(OggVorbisDecoderState* decoder) +static inline unsigned int getSampleCount(struct OggVorbisDecoderState* decoder) { int numSamples = ov_pcm_total(&decoder->oggVorbis_stream, -1); if (numSamples == OV_EINVAL) return 0; - + return numSamples; } -static inline unsigned int getCurrentSample(OggVorbisDecoderState* decoder) +static inline unsigned int getCurrentSample(struct OggVorbisDecoderState* decoder) { int samplePos = ov_pcm_tell(&decoder->oggVorbis_stream); if (samplePos == OV_EINVAL) return 0; - + return samplePos; } -soundDataBuffer* sound_DecodeOggVorbis(OggVorbisDecoderState* decoder, size_t bufferSize) +soundDataBuffer* sound_DecodeOggVorbis(struct OggVorbisDecoderState* decoder, size_t bufferSize) { size_t size = 0; int result; Index: lib/sound/oggvorbis.h =================================================================== --- lib/sound/oggvorbis.h (revision 1337) +++ lib/sound/oggvorbis.h (working copy) @@ -40,20 +40,12 @@ unsigned int frequency; } soundDataBuffer; -#ifndef _LIBSOUND_OGGVORBIS_C_ -typedef void OggVorbisDecoderState; -#endif +// Forward declaration so we can take pointers to this type +struct OggVorbisDecoderState; -#ifdef __cplusplus -extern "C" -{ -#endif -OggVorbisDecoderState* sound_CreateOggVorbisDecoder(PHYSFS_file* PHYSFS_fileHandle, BOOL allowSeeking); -void sound_DestroyOggVorbisDecoder(OggVorbisDecoderState* decoder); +struct OggVorbisDecoderState* sound_CreateOggVorbisDecoder(PHYSFS_file* PHYSFS_fileHandle, BOOL allowSeeking); +void sound_DestroyOggVorbisDecoder(struct OggVorbisDecoderState* decoder); -soundDataBuffer* sound_DecodeOggVorbis(OggVorbisDecoderState* decoder, size_t bufferSize); -#ifdef __cplusplus -} -#endif +soundDataBuffer* sound_DecodeOggVorbis(struct OggVorbisDecoderState* decoder, size_t bufferSize); #endif // _LIBSOUND_OGGVORBIS_H_ Index: lib/sound/openal_track.c =================================================================== --- lib/sound/openal_track.c (revision 1337) +++ lib/sound/openal_track.c (working copy) @@ -253,7 +253,7 @@ ALenum format; ALuint buffer; - OggVorbisDecoderState* decoder = sound_CreateOggVorbisDecoder(PHYSFS_fileHandle, TRUE); + struct OggVorbisDecoderState* decoder = sound_CreateOggVorbisDecoder(PHYSFS_fileHandle, TRUE); soundDataBuffer* soundBuffer; soundBuffer = sound_DecodeOggVorbis(decoder, 0);
signature.asc
Description: OpenPGP digital signature
_______________________________________________ Warzone-dev mailing list Warzone-dev@gna.org https://mail.gna.org/listinfo/warzone-dev