From aa817c7cb4caad98628543c60eeb34909413dee2 Mon Sep 17 00:00:00 2001 From: McCabe Maxsted Date: Mon, 13 Sep 2010 17:18:52 -0700 Subject: Updated openal device loading and added debug info for startup --- linden/indra/llaudio/llaudioengine_openal.cpp | 69 +++++++++++++++++++++------ linden/indra/llaudio/llaudioengine_openal.h | 29 ++++++----- 2 files changed, 70 insertions(+), 28 deletions(-) diff --git a/linden/indra/llaudio/llaudioengine_openal.cpp b/linden/indra/llaudio/llaudioengine_openal.cpp index 93bc42b..c33b992 100644 --- a/linden/indra/llaudio/llaudioengine_openal.cpp +++ b/linden/indra/llaudio/llaudioengine_openal.cpp @@ -48,7 +48,9 @@ LLAudioEngine_OpenAL::LLAudioEngine_OpenAL() mWindBufSamples(0), mWindBufBytes(0), mWindSource(AL_NONE), - mNumEmptyWindALBuffers(MAX_NUM_WIND_BUFFERS) + mNumEmptyWindALBuffers(MAX_NUM_WIND_BUFFERS), + mContext(NULL), + mDevice(NULL) { } @@ -69,30 +71,63 @@ bool LLAudioEngine_OpenAL::init(const S32 num_channels, void* userdata) return false; } + // check for extensions + if (alcIsExtensionPresent(NULL, "ALC_ENUMERATION_EXT")) + { + llinfos << "Results for ALC_ENUMERATION_EXT:\n" + << ll_safe_string(alcGetString(NULL, ALC_DEVICE_SPECIFIER)) + << llendl; + } + + // initialize device + ALCdevice* mDevice = alcOpenDevice(NULL); + if (!mDevice) + { + llinfos << "OpenAL could not find an installed audio device. Aborting" << llendl; + ALCenum error = alcGetError(mDevice); + if (error != ALC_NO_ERROR) + { + llinfos << "ALC error:" << ll_safe_string(alcGetString(mDevice, error)) << llendl; + } + return false; + } + + // create context + ALCcontext* mContext = alcCreateContext(mDevice, NULL); + if (mContext != NULL) + { + alcMakeContextCurrent(mContext); + if (alGetError() != AL_NO_ERROR) + { + llinfos << "ALC error:" << alGetError() << ". Could not set current context!" << llendl; + } + } + else + { + llinfos << "ALC error: could not create context from device!" << llendl; + } + llinfos << "LLAudioEngine_OpenAL::init() OpenAL successfully initialized" << llendl; + llinfos << "ALC default device: " + << ll_safe_string(alcGetString(mDevice, ALC_DEFAULT_DEVICE_SPECIFIER)) + << llendl; + llinfos << "OpenAL version: " - << ll_safe_string(alGetString(AL_VERSION)) << llendl; + << ll_safe_string(alGetString(AL_VERSION)) << llendl; llinfos << "OpenAL vendor: " - << ll_safe_string(alGetString(AL_VENDOR)) << llendl; + << ll_safe_string(alGetString(AL_VENDOR)) << llendl; llinfos << "OpenAL renderer: " - << ll_safe_string(alGetString(AL_RENDERER)) << llendl; + << ll_safe_string(alGetString(AL_RENDERER)) << llendl; - ALint major = alutGetMajorVersion (); - ALint minor = alutGetMinorVersion (); + ALint major = alutGetMajorVersion(); + ALint minor = alutGetMinorVersion(); llinfos << "ALUT version: " << major << "." << minor << llendl; - ALCdevice *device = alcGetContextsDevice(alcGetCurrentContext()); - - alcGetIntegerv(device, ALC_MAJOR_VERSION, 1, &major); - alcGetIntegerv(device, ALC_MINOR_VERSION, 1, &minor); + alcGetIntegerv(mDevice, ALC_MAJOR_VERSION, 1, &major); + alcGetIntegerv(mDevice, ALC_MINOR_VERSION, 1, &minor); llinfos << "ALC version: " << major << "." << minor << llendl; - llinfos << "ALC default device: " - << ll_safe_string(alcGetString(device, - ALC_DEFAULT_DEVICE_SPECIFIER)) - << llendl; - return true; } @@ -148,6 +183,10 @@ void LLAudioEngine_OpenAL::shutdown() llwarns << "LLAudioEngine_OpenAL::shutdown() ALUT shutdown failed: " << alutGetErrorString (alutGetError ()) << llendl; } + alcMakeContextCurrent(NULL); + alcDestroyContext(mContext); + alcCloseDevice(mDevice); + llinfos << "LLAudioEngine_OpenAL::shutdown() OpenAL successfully shut down" << llendl; delete mListenerp; diff --git a/linden/indra/llaudio/llaudioengine_openal.h b/linden/indra/llaudio/llaudioengine_openal.h index 900bcb3..9b52b88 100644 --- a/linden/indra/llaudio/llaudioengine_openal.h +++ b/linden/indra/llaudio/llaudioengine_openal.h @@ -47,7 +47,7 @@ class LLAudioEngine_OpenAL : public LLAudioEngine virtual ~LLAudioEngine_OpenAL(); virtual bool init(const S32 num_channels, void *user_data); - virtual std::string getDriverName(bool verbose); + virtual std::string getDriverName(bool verbose); virtual void allocateListener(); virtual void shutdown(); @@ -62,17 +62,20 @@ class LLAudioEngine_OpenAL : public LLAudioEngine /*virtual*/ void updateWind(LLVector3 direction, F32 camera_altitude); private: - void * windDSP(void *newbuffer, int length); - typedef S16 WIND_SAMPLE_T; - LLWindGen *mWindGen; - S16 *mWindBuf; - U32 mWindBufFreq; - U32 mWindBufSamples; - U32 mWindBufBytes; - ALuint mWindSource; - int mNumEmptyWindALBuffers; - - static const int MAX_NUM_WIND_BUFFERS = 80; + void* windDSP(void *newbuffer, int length); + typedef S16 WIND_SAMPLE_T; + LLWindGen* mWindGen; + S16 *mWindBuf; + U32 mWindBufFreq; + U32 mWindBufSamples; + U32 mWindBufBytes; + ALuint mWindSource; + int mNumEmptyWindALBuffers; + + static const int MAX_NUM_WIND_BUFFERS = 80; + + ALCcontext* mContext; + ALCdevice* mDevice; }; class LLAudioChannelOpenAL : public LLAudioChannel @@ -91,7 +94,7 @@ class LLAudioChannelOpenAL : public LLAudioChannel /*virtual*/ void updateLoop(); ALuint mALSource; - ALint mLastSamplePos; + ALint mLastSamplePos; }; class LLAudioBufferOpenAL : public LLAudioBuffer{ -- cgit v1.1 From 9d7b4020d43abf83bcd22c34d560853a7232c796 Mon Sep 17 00:00:00 2001 From: McCabe Maxsted Date: Tue, 14 Sep 2010 13:38:54 -0700 Subject: Added more debugging info and initialization help. For some reason openal32.dll crashes on quit --- linden/indra/llaudio/llaudioengine_openal.cpp | 162 ++++++++++++++++++++------ linden/indra/llaudio/llaudioengine_openal.h | 3 +- 2 files changed, 130 insertions(+), 35 deletions(-) diff --git a/linden/indra/llaudio/llaudioengine_openal.cpp b/linden/indra/llaudio/llaudioengine_openal.cpp index c33b992..08ec464 100644 --- a/linden/indra/llaudio/llaudioengine_openal.cpp +++ b/linden/indra/llaudio/llaudioengine_openal.cpp @@ -40,6 +40,35 @@ static const float WIND_BUFFER_SIZE_SEC = 0.05f; // 1/20th sec +std::string convertALErrorToString(ALenum error) +{ + switch(error) + { + case AL_NO_ERROR: + return std::string("AL_NO_ERROR"); + break; + case AL_INVALID_NAME: + return std::string("AL_INVALID_NAME"); + break; + case AL_INVALID_ENUM: + return std::string("AL_INVALID_ENUM"); + break; + case AL_INVALID_VALUE: + return std::string("AL_INVALID_VALUE"); + break; + case AL_INVALID_OPERATION: + return std::string("AL_INVALID_OPERATION"); + break; + case AL_OUT_OF_MEMORY: + return std::string("AL_OUT_OF_MEMORY"); + break; + default: + std::stringstream s; + s << error; + return s.str(); + } +} + LLAudioEngine_OpenAL::LLAudioEngine_OpenAL() : mWindGen(NULL), @@ -72,39 +101,76 @@ bool LLAudioEngine_OpenAL::init(const S32 num_channels, void* userdata) } // check for extensions - if (alcIsExtensionPresent(NULL, "ALC_ENUMERATION_EXT")) + const ALCchar* device_list(NULL); + const ALCchar* device_default(NULL); + if (alcIsExtensionPresent(NULL, "ALC_ENUMERATION_EXT") == AL_TRUE) { + device_default = alcGetString(NULL, ALC_DEFAULT_DEVICE_SPECIFIER); + device_list = alcGetString(NULL, ALC_DEVICE_SPECIFIER); llinfos << "Results for ALC_ENUMERATION_EXT:\n" - << ll_safe_string(alcGetString(NULL, ALC_DEVICE_SPECIFIER)) + << ll_safe_string(device_list) << llendl; + } // initialize device ALCdevice* mDevice = alcOpenDevice(NULL); - if (!mDevice) + if (mDevice == NULL) { - llinfos << "OpenAL could not find an installed audio device. Aborting" << llendl; - ALCenum error = alcGetError(mDevice); - if (error != ALC_NO_ERROR) + llinfos << "Could not find a default device, trying to open default manually: " + << ll_safe_string(device_default) + << llendl; + mDevice = alcOpenDevice(device_default); + if (mDevice == NULL) { - llinfos << "ALC error:" << ll_safe_string(alcGetString(mDevice, error)) << llendl; + const ALCchar* device_list_walk = device_list; + do + { + mDevice = alcOpenDevice(device_list_walk); + if (mDevice != NULL) + { + break; + } + else + { + device_list_walk += strlen(device_list_walk)+1; + } + } + while (device_list_walk[0] != '\0'); + + if (mDevice == NULL) + { + llinfos << "OpenAL could not find an installed audio device. Aborting" << llendl; + ALCenum error = alcGetError(mDevice); + if (error != ALC_NO_ERROR) + { + llinfos << "ALC error: " << ll_safe_string(alcGetString(mDevice, error)) << llendl; + } + return false; + } } - return false; } // create context ALCcontext* mContext = alcCreateContext(mDevice, NULL); if (mContext != NULL) { - alcMakeContextCurrent(mContext); - if (alGetError() != AL_NO_ERROR) + if (!alcMakeContextCurrent(mContext)) { - llinfos << "ALC error:" << alGetError() << ". Could not set current context!" << llendl; + ALenum error = alGetError(); + if (error != AL_NO_ERROR) + { + llinfos << "ALC error: " << convertALErrorToString(error) << ". Could not set current context!" << llendl; + } + alcDestroyContext(mContext); + return false; } } else { llinfos << "ALC error: could not create context from device!" << llendl; + alcCloseDevice(mDevice); + return false; } llinfos << "LLAudioEngine_OpenAL::init() OpenAL successfully initialized" << llendl; @@ -174,23 +240,43 @@ void LLAudioEngine_OpenAL::allocateListener() void LLAudioEngine_OpenAL::shutdown() { llinfos << "About to LLAudioEngine::shutdown()" << llendl; + LLAudioEngine::shutdown(); llinfos << "About to alutExit()" << llendl; if(!alutExit()) { llwarns << "Nuts." << llendl; - llwarns << "LLAudioEngine_OpenAL::shutdown() ALUT shutdown failed: " << alutGetErrorString (alutGetError ()) << llendl; + llwarns << "LLAudioEngine_OpenAL::shutdown() ALUT shutdown failed: " << alutGetErrorString(alutGetError()) << llendl; } - alcMakeContextCurrent(NULL); - alcDestroyContext(mContext); - alcCloseDevice(mDevice); - llinfos << "LLAudioEngine_OpenAL::shutdown() OpenAL successfully shut down" << llendl; delete mListenerp; mListenerp = NULL; + + ALenum error; + + alcMakeContextCurrent(NULL); + error = alGetError(); + if (error != AL_NO_ERROR) + { + llinfos << "AL error: " << convertALErrorToString(error) << ". Could not make current context NULL!" << llendl; + } + + alcDestroyContext(mContext); + error = alGetError(); + if (error != AL_NO_ERROR) + { + llinfos << "AL error: " << convertALErrorToString(error) << ". Could not destroy context!" << llendl; + } + + alcCloseDevice(mDevice); + error = alGetError(); + if (error != AL_NO_ERROR) + { + llinfos << "AL error: " << convertALErrorToString(error) << ". Could not close device!" << llendl; + } } LLAudioBuffer *LLAudioEngine_OpenAL::createBuffer() @@ -220,7 +306,11 @@ LLAudioChannelOpenAL::LLAudioChannelOpenAL() LLAudioChannelOpenAL::~LLAudioChannelOpenAL() { cleanup(); - alDeleteSources(1, &mALSource); + if (mALSource != AL_NONE) //MC + { + alDeleteSources(1, &mALSource); + mALSource = AL_NONE; + } } void LLAudioChannelOpenAL::cleanup() @@ -379,18 +469,20 @@ bool LLAudioBufferOpenAL::loadWAV(const std::string& filename) ALenum error = alutGetError(); if (gDirUtilp->fileExists(filename)) { - llwarns << - "LLAudioBufferOpenAL::loadWAV() Error loading " - << filename - << " " << alutGetErrorString(error) << llendl; + llwarns << "LLAudioBufferOpenAL::loadWAV() Error loading " + << filename << " " + << convertALErrorToString(error) << ": " + << alutGetErrorString(error) + << llendl; } else { // It's common for the file to not actually exist. - lldebugs << - "LLAudioBufferOpenAL::loadWAV() Error loading " - << filename - << " " << alutGetErrorString(error) << llendl; + lldebugs << "LLAudioBufferOpenAL::loadWAV() Error loading " + << filename << " " + << convertALErrorToString(error) << ": " + << alutGetErrorString(error) + << llendl; } return false; } @@ -424,7 +516,7 @@ void LLAudioEngine_OpenAL::initWind() if((error=alGetError()) != AL_NO_ERROR) { - llwarns << "LLAudioEngine_OpenAL::initWind() Error creating wind sources: "<; @@ -524,14 +616,14 @@ void LLAudioEngine_OpenAL::updateWind(LLVector3 wind_vec, F32 camera_altitude) //llinfos << "mNumEmptyWindALBuffers: " << mNumEmptyWindALBuffers <<" (" << unprocessed << ":" << processed << ")" << llendl; - while(processed--) // unqueue old buffers + while (processed--) // unqueue old buffers { ALuint buffer; ALenum error; alGetError(); /* clear error */ alSourceUnqueueBuffers(mWindSource, 1, &buffer); error = alGetError(); - if(error != AL_NO_ERROR) + if (error != AL_NO_ERROR) { llwarns << "LLAudioEngine_OpenAL::updateWind() error swapping (unqueuing) buffers" << llendl; } @@ -547,9 +639,9 @@ void LLAudioEngine_OpenAL::updateWind(LLVector3 wind_vec, F32 camera_altitude) ALuint buffer; alGetError(); /* clear error */ alGenBuffers(1,&buffer); - if((error=alGetError()) != AL_NO_ERROR) + if ((error=alGetError()) != AL_NO_ERROR) { - llwarns << "LLAudioEngine_OpenAL::initWind() Error creating wind buffer: " << error << llendl; + llwarns << "LLAudioEngine_OpenAL::initWind() Error creating wind buffer: " << convertALErrorToString(error) << llendl; break; } @@ -560,14 +652,14 @@ void LLAudioEngine_OpenAL::updateWind(LLVector3 wind_vec, F32 camera_altitude) mWindBufBytes, mWindBufFreq); error = alGetError(); - if(error != AL_NO_ERROR) + if (error != AL_NO_ERROR) { llwarns << "LLAudioEngine_OpenAL::updateWind() error swapping (bufferdata) buffers" << llendl; } alSourceQueueBuffers(mWindSource, 1, &buffer); error = alGetError(); - if(error != AL_NO_ERROR) + if (error != AL_NO_ERROR) { llwarns << "LLAudioEngine_OpenAL::updateWind() error swapping (queuing) buffers" << llendl; } @@ -577,11 +669,13 @@ void LLAudioEngine_OpenAL::updateWind(LLVector3 wind_vec, F32 camera_altitude) ALint playing; alGetSourcei(mWindSource, AL_SOURCE_STATE, &playing); - if(playing != AL_PLAYING) + if (playing != AL_PLAYING) { alSourcePlay(mWindSource); - lldebugs << "Wind had stopped - probably ran out of buffers - restarting: " << (unprocessed+mNumEmptyWindALBuffers) << " now queued." << llendl; + lldebugs << "Wind had stopped - probably ran out of buffers - restarting: " + << (unprocessed+mNumEmptyWindALBuffers) << " now queued." + << llendl; } } diff --git a/linden/indra/llaudio/llaudioengine_openal.h b/linden/indra/llaudio/llaudioengine_openal.h index 9b52b88..df32e13 100644 --- a/linden/indra/llaudio/llaudioengine_openal.h +++ b/linden/indra/llaudio/llaudioengine_openal.h @@ -97,7 +97,8 @@ class LLAudioChannelOpenAL : public LLAudioChannel ALint mLastSamplePos; }; -class LLAudioBufferOpenAL : public LLAudioBuffer{ +class LLAudioBufferOpenAL : public LLAudioBuffer +{ public: LLAudioBufferOpenAL(); virtual ~LLAudioBufferOpenAL(); -- cgit v1.1 From 18145841697382f7f940eb3df06d62fbc6adb436 Mon Sep 17 00:00:00 2001 From: McCabe Maxsted Date: Thu, 23 Jun 2011 20:43:03 -0700 Subject: Updated Imp's easter egg chat commands with the new website urls --- linden/indra/newview/llgesturemgr.cpp | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/linden/indra/newview/llgesturemgr.cpp b/linden/indra/newview/llgesturemgr.cpp index bb678d7..bd05cb3 100644 --- a/linden/indra/newview/llgesturemgr.cpp +++ b/linden/indra/newview/llgesturemgr.cpp @@ -627,12 +627,12 @@ BOOL LLGestureManager::triggerAndReviseString(const std::string &utf8str, std::s LLStringUtil::compareInsensitive("/icanhashelp", cur_token) == 0 || LLStringUtil::compareInsensitive("/icanhashalp", cur_token) == 0) { - LLWeb::loadURLInternal("http://support.imprudenceviewer.org/"); + LLWeb::loadURLInternal("http://support.kokuaviewer.org/"); return TRUE; } else if (LLStringUtil::compareInsensitive("/icanhasblog", cur_token) == 0) { - LLWeb::loadURLInternal("http://www.imprudenceviewer.org/"); + LLWeb::loadURLInternal("http://kokuaviewer.org/"); return TRUE; } else if (LLStringUtil::compareInsensitive("/icanhascodie", cur_token) == 0) @@ -657,23 +657,23 @@ BOOL LLGestureManager::triggerAndReviseString(const std::string &utf8str, std::s LLStringUtil::compareInsensitive("/icanhasupdate", cur_token) == 0 || LLStringUtil::compareInsensitive("/icanhasupdates", cur_token) == 0 ) { - LLWeb::loadURLInternal("http://imprudenceviewer.org/wiki/Downloads"); + LLWeb::loadURLInternal("http://wiki.kokuaviewer.org/wiki/Imprudence:Downloads"); return TRUE; } else if (LLStringUtil::compareInsensitive("/icanhasfeatures", cur_token) == 0) { - LLWeb::loadURLInternal("http://imprudenceviewer.org/wiki/Features"); + LLWeb::loadURLInternal("http://wiki.kokuaviewer.org/wiki/Imprudence:Features"); return TRUE; } else if (LLStringUtil::compareInsensitive("/icanhaswiki", cur_token) == 0) { - LLWeb::loadURLInternal("http://imprudenceviewer.org/wiki/"); + LLWeb::loadURLInternal("http://wiki.kokuaviewer.org/wiki/"); return TRUE; } else if (LLStringUtil::compareInsensitive("/icanhasbugs", cur_token) == 0 || LLStringUtil::compareInsensitive("/icanhasbug", cur_token) == 0 ) { - LLWeb::loadURLInternal("http://redmine.imprudenceviewer.org/"); + LLWeb::loadURLInternal("http://redmine.kokuaviewer.org/"); return TRUE; } else if (LLStringUtil::compareInsensitive("/icanhasgit", cur_token) == 0) @@ -691,7 +691,6 @@ BOOL LLGestureManager::triggerAndReviseString(const std::string &utf8str, std::s LLWeb::loadURLInternal("http://twitter.com/ImpViewer"); return TRUE; } - else if (LLStringUtil::compareInsensitive("/icanhasimprudence", cur_token) == 0) { -- cgit v1.1 From c96afda71bd39e69e1b26849ac5e956d0fd97072 Mon Sep 17 00:00:00 2001 From: McCabe Maxsted Date: Thu, 23 Jun 2011 20:47:21 -0700 Subject: Created new window for inworld dice rolling in advanced > UI. Todo: add button for 'rocks fall, everybody dies' --- linden/indra/newview/CMakeLists.txt | 2 + linden/indra/newview/app_settings/settings.xml | 38 ++++++++ linden/indra/newview/floaterdice.cpp | 108 +++++++++++++++++++++ linden/indra/newview/floaterdice.h | 50 ++++++++++ linden/indra/newview/llviewermenu.cpp | 29 ++++++ .../skins/default/xui/en-us/floater_dice.xml | 15 +++ .../skins/default/xui/en-us/menu_viewer.xml | 7 +- 7 files changed, 248 insertions(+), 1 deletion(-) create mode 100644 linden/indra/newview/floaterdice.cpp create mode 100644 linden/indra/newview/floaterdice.h create mode 100644 linden/indra/newview/skins/default/xui/en-us/floater_dice.xml diff --git a/linden/indra/newview/CMakeLists.txt b/linden/indra/newview/CMakeLists.txt index b0cb366..46da492 100644 --- a/linden/indra/newview/CMakeLists.txt +++ b/linden/indra/newview/CMakeLists.txt @@ -78,6 +78,7 @@ set(viewer_SOURCE_FILES floaterao.cpp floaterbusy.cpp floatercommandline.cpp + floaterdice.cpp floatergriddefault.cpp floatergridmanager.cpp floaterlocalassetbrowse.cpp @@ -535,6 +536,7 @@ set(viewer_HEADER_FILES floaterao.h floaterbusy.h floatercommandline.h + floaterdice.h floatergriddefault.h floatergridmanager.h floaterlocalassetbrowse.h diff --git a/linden/indra/newview/app_settings/settings.xml b/linden/indra/newview/app_settings/settings.xml index a6b782d..eb59254 100644 --- a/linden/indra/newview/app_settings/settings.xml +++ b/linden/indra/newview/app_settings/settings.xml @@ -399,6 +399,44 @@ Value 3 + DiceLastCount + + Comment + Last entered dice count + Persist + 1 + Type + S32 + Value + 1 + + DiceLastSides + + Comment + Last entered dice sides + Persist + 1 + Type + S32 + Value + 6 + + DiceFloaterRect + + Comment + Rectangle for dice window + Persist + 1 + Type + Rect + Value + + 0 + 100 + 100 + 100 + + DisableInternalFlyUpAnimation Comment diff --git a/linden/indra/newview/floaterdice.cpp b/linden/indra/newview/floaterdice.cpp new file mode 100644 index 0000000..f16a6ca --- /dev/null +++ b/linden/indra/newview/floaterdice.cpp @@ -0,0 +1,108 @@ +/** +* @file floaterdice.cpp +* @brief Dice window for Imprudence +* +* $LicenseInfo:firstyear=2009&license=viewergpl$ +* +* Copyright (c) 2011, McCabe Maxsted +* +* Imprudence Viewer Source Code +* The source code in this file ("Source Code") is provided to you +* under the terms of the GNU General Public License, version 2.0 +* ("GPL"). Terms of the GPL can be found in doc/GPL-license.txt in +* this distribution, or online at +* http://secondlifegrid.net/programs/open_source/licensing/gplv2 +* +* There are special exceptions to the terms and conditions of the GPL as +* it is applied to this Source Code. View the full text of the exception +* in the file doc/FLOSS-exception.txt in this software distribution, or +* online at http://secondlifegrid.net/programs/open_source/licensing/flossexception +* +* By copying, modifying or distributing this software, you acknowledge +* that you have read and understood your obligations described above, +* and agree to abide by those obligations. +* +* ALL SOURCE CODE IS PROVIDED "AS IS." THE AUTHOR MAKES NO +* WARRANTIES, EXPRESS, IMPLIED OR OTHERWISE, REGARDING ITS ACCURACY, +* COMPLETENESS OR PERFORMANCE. +* $/LicenseInfo$ +*/ + +#include "llviewerprecompiledheaders.h" + +#include "floaterdice.h" + +#include "llspinctrl.h" +#include "lluictrlfactory.h" + +#include "llchat.h" +#include "llchatbar.h" +#include "llkeyboard.h" +#include "llviewercontrol.h" + + +FloaterDice::FloaterDice(const LLSD& seed) : LLFloater("Roll Dice") +{ + LLUICtrlFactory::getInstance()->buildFloater(this, "floater_dice.xml"); +} + +FloaterDice::~FloaterDice() +{ +} + +BOOL FloaterDice::postBuild() +{ + childSetAction("btn_roll", onClickRoll, this); + + return TRUE; +} + +// static +void FloaterDice::onClickRoll(void* data) +{ + FloaterDice* self = (FloaterDice*)data; + if (self) + { + S32 dice_count = (S32)(self->getChild("spin_dice_count")->getValue()); + S32 dice_sides = (S32)(self->getChild("spin_dice_sides")->getValue()); + + if (dice_count <= 0 || dice_sides <= 3) + { + llwarns << "Invalid dice roll! Someone's trying to cheat, perhaps?" << llendl; + return; + } + else + { + S32 dice_total = 0; + std::ostringstream rolls; + for (S32 i = 0; i < dice_count; ++i) + { + S32 roll = ll_rand(dice_sides); + dice_total += roll; + rolls << roll; + if (i < dice_count - 1) rolls << ", "; + } + + std::string roll_text = llformat("/me rolled %dd%d for a total of %d", dice_count, dice_sides, dice_total); + if (dice_count > 1) + { + roll_text += " (" + rolls.str() + ")"; + } + gChatBar->sendChatFromViewer(roll_text, CHAT_TYPE_NORMAL, FALSE); + } + } +} + +// virtual +BOOL FloaterDice::handleKeyHere(KEY key, MASK mask) +{ + BOOL handled = FALSE; + + if ((KEY_RETURN == key) && (mask == MASK_NONE)) + { + onClickRoll(this); + handled = TRUE; + } + + return handled; +} diff --git a/linden/indra/newview/floaterdice.h b/linden/indra/newview/floaterdice.h new file mode 100644 index 0000000..57a664b --- /dev/null +++ b/linden/indra/newview/floaterdice.h @@ -0,0 +1,50 @@ +/** +* @file floaterdice.h +* @brief Dice window for Imprudence +* +* $LicenseInfo:firstyear=2009&license=viewergpl$ +* +* Copyright (c) 2011, McCabe Maxsted +* +* Imprudence Viewer Source Code +* The source code in this file ("Source Code") is provided to you +* under the terms of the GNU General Public License, version 2.0 +* ("GPL"). Terms of the GPL can be found in doc/GPL-license.txt in +* this distribution, or online at +* http://secondlifegrid.net/programs/open_source/licensing/gplv2 +* +* There are special exceptions to the terms and conditions of the GPL as +* it is applied to this Source Code. View the full text of the exception +* in the file doc/FLOSS-exception.txt in this software distribution, or +* online at http://secondlifegrid.net/programs/open_source/licensing/flossexception +* +* By copying, modifying or distributing this software, you acknowledge +* that you have read and understood your obligations described above, +* and agree to abide by those obligations. +* +* ALL SOURCE CODE IS PROVIDED "AS IS." THE AUTHOR MAKES NO +* WARRANTIES, EXPRESS, IMPLIED OR OTHERWISE, REGARDING ITS ACCURACY, +* COMPLETENESS OR PERFORMANCE. +* $/LicenseInfo$ +*/ + +#ifndef floaterdice_h +#define floaterdice_h + +#include "llfloater.h" + +class FloaterDice : public LLFloater, public LLFloaterSingleton +{ +public: + + FloaterDice(const LLSD& seed); + virtual ~FloaterDice(); + BOOL postBuild(); + +private: + + static void onClickRoll(void* data); + virtual BOOL handleKeyHere(KEY key, MASK mask); +}; + +#endif //floaterdice_h diff --git a/linden/indra/newview/llviewermenu.cpp b/linden/indra/newview/llviewermenu.cpp index c336c3a..a83c11b 100644 --- a/linden/indra/newview/llviewermenu.cpp +++ b/linden/indra/newview/llviewermenu.cpp @@ -84,6 +84,7 @@ #include "llfirstuse.h" #include "llfloater.h" #include "floaterao.h" +#include "floaterdice.h" #include "llfloaterabout.h" #include "llfloaterbuycurrency.h" #include "llfloateractivespeakers.h" @@ -9601,6 +9602,32 @@ class LLAdvancedReloadBalance : public view_listener_t } }; + +///////////////// +// DICE WINDOW // +///////////////// + + +class LLAdvancedToggleDice : public view_listener_t +{ + bool handleEvent(LLPointer event, const LLSD& userdata) + { + FloaterDice::toggleInstance(); + return true; + } +}; + +class LLAdvancedCheckDice : public view_listener_t +{ + bool handleEvent(LLPointer event, const LLSD& userdata) + { + bool new_value = FloaterDice::instanceVisible(); + std::string control_name = userdata["control"].asString(); + gMenuHolder->findControl(control_name)->setValue(new_value); + return true; + } +}; + ///////////////////// // DUMP SELECT MGR // ///////////////////// @@ -11421,6 +11448,8 @@ void initialize_menus() addMenu(new LLAdvancedWebBrowserTest(), "Advanced.WebBrowserTest"); addMenu(new LLAdvancedToggleEditableUI(), "Advanced.ToggleEditableUI"); addMenu(new LLAdvancedReloadBalance(), "Advanced.ReloadBalance"); + addMenu(new LLAdvancedToggleDice(), "Advanced.ToggleDice"); + addMenu(new LLAdvancedCheckDice(), "Advanced.CheckDice"); //addMenu(new LLAdvancedCheckEditableUI(), "Advanced.CheckEditableUI"); addMenu(new LLAdvancedDumpSelectMgr(), "Advanced.DumpSelectMgr"); addMenu(new LLAdvancedDumpInventory(), "Advanced.DumpInventory"); diff --git a/linden/indra/newview/skins/default/xui/en-us/floater_dice.xml b/linden/indra/newview/skins/default/xui/en-us/floater_dice.xml new file mode 100644 index 0000000..4a70c1c --- /dev/null +++ b/linden/indra/newview/skins/default/xui/en-us/floater_dice.xml @@ -0,0 +1,15 @@ + + + + +