diff --git a/AV.cc b/AV.cc index 8c64f9f..8e4ef3b 100644 --- a/AV.cc +++ b/AV.cc @@ -17,6 +17,15 @@ using namespace std; #define CALLBACK_SAMPLES 4096 #define CHANNELS 2 #define BYTES_PER_SAMPLE 2 +#if AV_SOUND_FORMAT == AUDIO_S16SYS +# define SAMPLE_MIN SHRT_MIN +# define SAMPLE_MAX SHRT_MAX +#elif AV_SOUND_FORMAT == AUDIO_U16SYS +# define SAMPLE_MIN 0 +# define SAMPLE_MAX USHRT_MAX +#else +# error Unknown AV_SOUND_FORMAT +#endif void AV_sound_callback(void * userdata, Uint8 * stream, int len) { @@ -56,12 +65,13 @@ AV::AV() desired.samples = CALLBACK_SAMPLES; desired.callback = AV_sound_callback; desired.userdata = this; + desired.silence = 0; if (SDL_OpenAudio(&desired, NULL) < 0) { cerr << "SDL_OpenAudio() error." << endl; exit(3); } - m_sound_buffer = new int16_t[CALLBACK_SAMPLES * CHANNELS]; + m_sound_buffer = new sample_t[CALLBACK_SAMPLES * CHANNELS]; m_active_sounds_mutex = SDL_CreateMutex(); } @@ -76,7 +86,7 @@ AV::~AV() delete[] m_sound_buffer; } -void AV::start(int width, int height, bool fullscreen, bool grab_input, +bool AV::start(int width, int height, bool fullscreen, bool grab_input, int samples) { if (m_surface == NULL) @@ -96,6 +106,31 @@ void AV::start(int width, int height, bool fullscreen, bool grab_input, SDL_GL_SetAttribute(SDL_GL_MULTISAMPLESAMPLES, samples); } m_surface = SDL_SetVideoMode(width, height, 32, flags); + if (m_surface == NULL) + { + if (samples > 1) + { + cerr << "Error setting video mode, trying again without multisampling" << endl; + /* failed to set SDL video mode with multisampling, try without */ + SDL_GL_SetAttribute(SDL_GL_MULTISAMPLEBUFFERS, 0); + SDL_GL_SetAttribute(SDL_GL_MULTISAMPLESAMPLES, 0); + m_surface = SDL_SetVideoMode(width, height, 32, flags); + if (m_surface != NULL) + { + cerr << "Successfully set video mode without multisampling" << endl; + } + } + } + if (m_surface == NULL) + { + cerr << "Error setting SDL video mode." << endl; + cerr << "Parameters:" << endl; + cerr << " width = " << width << endl; + cerr << " height = " << height << endl; + cerr << " fullscreen = " << fullscreen << endl; + cerr << " input grab = " << grab_input << endl; + return false; + } if (grab_input) { SDL_ShowCursor(SDL_DISABLE); @@ -119,6 +154,7 @@ void AV::start(int width, int height, bool fullscreen, bool grab_input, glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_DECAL); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); } + return true; } void AV::stop() @@ -161,7 +197,7 @@ void AV::stopSound(AV::Sound * s) void AV::playCallback(Uint8 * stream, int len) { - uint16_t * stream16 = (uint16_t *) stream; + sample_t * stream16 = (sample_t *) stream; memset(stream, 0, len); SDL_mutexP(m_active_sounds_mutex); #ifdef DEBUG @@ -188,7 +224,7 @@ void AV::playCallback(Uint8 * stream, int len) i++) { int sample_val = stream16[i] + (int)(volume * m_sound_buffer[i]); - stream16[i] = min(SHRT_MAX, max(SHRT_MIN, sample_val)); + stream16[i] = min(SAMPLE_MAX, max(SAMPLE_MIN, sample_val)); } } int sz = m_active_sounds.size(); @@ -237,10 +273,9 @@ bool AV::Sound::load(FileLoader & fileLoader, const FileLoader::Path & path) } else { - SDL_FreeRW(m_rwops); - m_rwops = NULL; cerr << "Error loading sound " << path.toString() << ": " << Sound_GetError() << endl; + m_rwops = NULL; } } return false; diff --git a/AV.h b/AV.h index a56039e..8d2c760 100644 --- a/AV.h +++ b/AV.h @@ -11,9 +11,18 @@ #include "FileLoader/FileLoader.h" #include "refptr/refptr.h" +#define AV_SOUND_FORMAT AUDIO_S16SYS + class AV { public: +#if AV_SOUND_FORMAT == AUDIO_S16SYS + typedef int16_t sample_t; +#elif AV_SOUND_FORMAT == AUDIO_U16SYS + typedef uint16_t sample_t; +#else +# error Unknown AV_SOUND_FORMAT +#endif class Sound { public: @@ -41,7 +50,7 @@ class AV AV(); ~AV(); - void start(int width = 0, int height = 0, + bool start(int width = 0, int height = 0, bool fullscreen = true, bool grab_input = true, int samples = 4); void stop(); @@ -87,7 +96,7 @@ class AV #endif std::set< Sound * > m_active_sounds; SDL_mutex * m_active_sounds_mutex; - int16_t * m_sound_buffer; + sample_t * m_sound_buffer; }; #endif diff --git a/anaglym.cc b/anaglym.cc index febeb99..bf9ce6a 100644 --- a/anaglym.cc +++ b/anaglym.cc @@ -13,6 +13,12 @@ static void usage(); static void usage() { cerr << "Usage: anaglym [options] program.lua[c]" << endl; + cerr << "Options:" << endl; + cerr << " -w : set window width" << endl; + cerr << " -h : set window height" << endl; + cerr << " -f : do not fullscreen" << endl; + cerr << " -g : do not grab mouse input" << endl; + cerr << " -s: set multisample level (default 4)" << endl; exit(42); } @@ -22,6 +28,7 @@ int main(int argc, char * argv[]) bool grab_input = true; int width = 0; int height = 0; + int samples = 4; const char * program = NULL; for (int i = 1; i < argc; i++) { @@ -55,6 +62,10 @@ int main(int argc, char * argv[]) { height = atoi((strlen(argv[i]) == 2) ? argv[++i] : argv[i] + 2); } + else if (!strncmp(argv[i], "-s", 2)) + { + samples = atoi((strlen(argv[i]) == 2) ? argv[++i] : argv[i] + 2); + } else { cerr << "Warning: Unrecognized option '" << argv[i]+1 @@ -72,7 +83,11 @@ int main(int argc, char * argv[]) srand(time(NULL)); AV av; - av.start(width, height, fullscreen, grab_input); + if (!av.start(width, height, fullscreen, grab_input, samples)) + { + cerr << "anaglym: exiting." << endl; + return -1; + } dInitODE(); g_engine = new Engine(argv[0], av); diff --git a/doc/index.html b/doc/index.html index 612591c..a3feb52 100644 --- a/doc/index.html +++ b/doc/index.html @@ -34,6 +34,8 @@ The library functions are documented below.
  • std library
  • @@ -58,6 +60,7 @@ The library functions are documented below.
  • -h height - specify the height in pixels of the window
  • -f - do not fullscreen window
  • -g - do not grab mouse input
  • +
  • -s samples - set multisample level (default 4)
  • @@ -476,6 +479,16 @@ You can instantiate a reference object into a normal object by calling the clone() method on the object.

    + +

    loadSound

    +

    sound = ag.loadSound(sound_name)

    +

    +This routine loads a sound object from file +sound_name and returns a Lua reference to the loaded sound. +The sound_name should contain the file extension, +since multiple formats are supported (.wav, .mp3, etc...). +

    +

    loadTexture

    texture = ag.loadTexture(texture_name)

    @@ -925,6 +938,135 @@ Newly created objects are visible by default.
    +
    +

    Joint member methods

    + +
    +

    setAMotorAxis

    +

    joint:setAMotorAxis(anum, rel, x, y, z)

    +

    +Set axis parameters of the AMotor joint. +See ag.createAMotor() for more information. +

    + + +

    setAMotorNumAxes

    +

    joint:setAMotorNumAxes(num)

    +

    +Set the number of axes of the AMotor joint. +See ag.createAMotor() for more information. +

    + + +

    setAMotorAngle

    +

    joint:setAMotorAngle(anum, angle)

    +

    +Set the angle of the specified of axis of the AMotor joint. +See ag.createAMotor() for more information. +

    + + +

    setAMotorLoStop

    +

    joint:setAMotorLoStop(anum, lostop)

    +

    +Set the low stop angle of the specified axis of the AMotor joint. +See ag.createAMotor() for more information. +

    + + +

    setAMotorHiStop

    +

    joint:setAMotorHiStop(anum, histop)

    +

    +Set the high stop angle of the specified axis of the AMotor joint. +See ag.createAMotor() for more information. +

    + + +

    setAMotorVel

    +

    joint:setAMotorVel(vel)

    +

    +Set the velocity of the AMotor joint. +See ag.createAMotor() for more information. +

    + + +

    setAMotorFMax

    +

    joint:setAMotorFMax(vel)

    +

    +Set the maximum force that the AMotor joint will apply to +maintain its constraints. +See ag.createAMotor() for more information. +

    + + +

    setAMotorBounce

    +

    joint:setAMotorBounce(bounce)

    +

    +Set the bounciness of the AMotor joint. +See ag.createAMotor() for more information. +

    + +
    + + +

    Sound member methods

    + +
    +

    play

    +

    snd:play()

    +

    +Begins playing the snd sound at the beginning. +

    + +
    +

    resume

    +

    snd:resume()

    +

    +Begins playing the snd sound where it stopped after calling +stop(). +

    + + +

    stop

    +

    snd:stop()

    +

    +Stops playing the snd sound at its current position. +

    + +
    +

    loop

    +

    snd:loop(count)

    +

    +Begins playing the snd sound at the beginning and sets the loop +count to count. snd:loop(1) is equivalent to +snd:play(). +

    + +
    +

    loopForever

    +

    snd:loopForever()

    +

    +Begins playing the snd sound at the beginning and sets the loop +count to infinity. This routine is good for background music. +

    + +
    +

    getVolume

    +

    snd:getVolume()

    +

    +Get the volume for the snd sound. +

    + +
    +

    setVolume

    +

    snd:setVolume(vol)

    +

    +Set the volume for the snd sound to snd. +snd should be between 0.0 and 1.0. +

    + +
    +

    std library