summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPiotr Dziwinski <piotrdz@gmail.com>2012-09-20 20:38:14 +0200
committerPiotr Dziwinski <piotrdz@gmail.com>2012-09-20 20:38:14 +0200
commite896b83bcf2ce803ba9823a530282bcf9c850d2f (patch)
tree950422aa48ef2bffcc743ef9d63c78703bbc80ca
parentbd36d76b31b27255c73376cda7f844e2eba7af82 (diff)
downloadcolobot-e896b83bcf2ce803ba9823a530282bcf9c850d2f.tar.gz
colobot-e896b83bcf2ce803ba9823a530282bcf9c850d2f.tar.bz2
colobot-e896b83bcf2ce803ba9823a530282bcf9c850d2f.zip
Whitespace fix
-rw-r--r--src/sound/plugins/oalsound/alsound.cpp1106
-rw-r--r--src/sound/plugins/oalsound/alsound.h190
-rw-r--r--src/tools/convert_model.cpp572
-rw-r--r--src/ui/color.cpp2
-rw-r--r--src/ui/color.h2
-rw-r--r--src/ui/control.cpp4
6 files changed, 938 insertions, 938 deletions
diff --git a/src/sound/plugins/oalsound/alsound.cpp b/src/sound/plugins/oalsound/alsound.cpp
index 8cd8221..571eacc 100644
--- a/src/sound/plugins/oalsound/alsound.cpp
+++ b/src/sound/plugins/oalsound/alsound.cpp
@@ -1,553 +1,553 @@
-// * This file is part of the COLOBOT source code
-// * Copyright (C) 2001-2008, Daniel ROUX & EPSITEC SA, www.epsitec.ch
-// * Copyright (C) 2012 Polish Portal of Colobot (PPC)
-// *
-// * This program is free software: you can redistribute it and/or modify
-// * it under the terms of the GNU General Public License as published by
-// * the Free Software Foundation, either version 3 of the License, or
-// * (at your option) any later version.
-// *
-// * 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. See the
-// * GNU General Public License for more details.
-// *
-// * You should have received a copy of the GNU General Public License
-// * along with this program. If not, see http://www.gnu.org/licenses/.
-
-// alsound.cpp
-
-
-#include "alsound.h"
-
-
-#define MIN(a, b) (a > b ? b : a)
-
-
-PLUGIN_INTERFACE(ALSound)
-
-
-std::string ALSound::PluginName()
-{
- return "Sound plugin using OpenAL library to play sounds.";
-}
-
-
-int ALSound::PluginVersion()
-{
- return 2;
-}
-
-
-void ALSound::InstallPlugin()
-{
- auto pointer = CInstanceManager::GetInstancePointer();
- if (pointer != nullptr)
- CInstanceManager::GetInstancePointer()->AddInstance(CLASS_SOUND, this);
-}
-
-
-bool ALSound::UninstallPlugin(std::string &reason)
-{
- auto pointer = CInstanceManager::GetInstancePointer();
- if (pointer != nullptr)
- CInstanceManager::GetInstancePointer()->DeleteInstance(CLASS_SOUND, this);
- CleanUp();
- return true;
-}
-
-
-ALSound::ALSound()
-{
- mEnabled = false;
- m3D = false;
- mAudioVolume = MAXVOLUME;
- mMute = false;
-}
-
-
-ALSound::~ALSound()
-{
- CleanUp();
-}
-
-
-void ALSound::CleanUp()
-{
- if (mEnabled) {
- GetLogger()->Info("Unloading files and closing device...\n");
- StopAll();
-
- for (auto item : mSounds)
- delete item.second;
-
- mEnabled = false;
- alutExit();
- }
-}
-
-
-bool ALSound::Create(bool b3D)
-{
- CleanUp();
-
- if (mEnabled)
- return true;
-
- GetLogger()->Info("Opening audio device...\n");
- if (!alutInit(NULL, NULL)) {
- ALenum error = alutGetError();
- GetLogger()->Error("Could not open audio device! Reason: %s\n", alutGetErrorString(error));
- return false;
- }
- GetLogger()->Info("Done.\n");
-
- mEnabled = true;
- return true;
-}
-
-
-void ALSound::SetSound3D(bool bMode)
-{
- // TODO stub! need to be implemented
- m3D = bMode;
-}
-
-
-bool ALSound::RetSound3D()
-{
- // TODO stub! need to be implemented
- return true;
-}
-
-
-bool ALSound::RetSound3DCap()
-{
- // TODO stub! need to be implemented
- return true;
-}
-
-
-bool ALSound::RetEnable()
-{
- return mEnabled;
-}
-
-
-void ALSound::SetAudioVolume(int volume)
-{
- alListenerf(AL_GAIN, MIN(volume, MAXVOLUME) * 0.01f);
- mAudioVolume = MIN(volume, MAXVOLUME);
-}
-
-
-int ALSound::RetAudioVolume()
-{
- float volume;
- if ( !mEnabled )
- return 0;
-
- alGetListenerf(AL_GAIN, &volume);
- return volume * MAXVOLUME;
-}
-
-
-void ALSound::SetMusicVolume(int volume)
-{
- // TODO stub! Add music support
-}
-
-
-int ALSound::RetMusicVolume()
-{
- // TODO stub! Add music support
- if ( !mEnabled )
- return 0;
-
- return 0;
-}
-
-
-bool ALSound::Cache(Sound sound, std::string filename)
-{
- Buffer *buffer = new Buffer();
- if (buffer->LoadFromFile(filename, sound)) {
- mSounds[sound] = buffer;
- return true;
- }
- return false;
-}
-
-
-void ALSound::CacheAll()
-{
- char filename[100];
- for ( int i = 1; i < 69; i++ )
- {
- sprintf(filename, "high/sound%.3d.wav", i);
- if ( !Cache((Sound) i, std::string(filename)) )
- {
- fprintf(stderr, "Unable to load audio: %s\n", filename);
- }
- }
-}
-
-
-int ALSound::RetPriority(Sound sound)
-{
- if ( sound == SOUND_FLYh ||
- sound == SOUND_FLY ||
- sound == SOUND_MOTORw ||
- sound == SOUND_MOTORt ||
- sound == SOUND_MOTORr ||
- sound == SOUND_MOTORs ||
- sound == SOUND_SLIDE ||
- sound == SOUND_ERROR )
- {
- return 30;
- }
-
- if ( sound == SOUND_CONVERT ||
- sound == SOUND_ENERGY ||
- sound == SOUND_DERRICK ||
- sound == SOUND_STATION ||
- sound == SOUND_REPAIR ||
- sound == SOUND_RESEARCH ||
- sound == SOUND_BURN ||
- sound == SOUND_BUILD ||
- sound == SOUND_TREMBLE ||
- sound == SOUND_NUCLEAR ||
- sound == SOUND_EXPLO ||
- sound == SOUND_EXPLOl ||
- sound == SOUND_EXPLOlp ||
- sound == SOUND_EXPLOp ||
- sound == SOUND_EXPLOi )
- {
- return 20;
- }
-
- if ( sound == SOUND_BLUP ||
- sound == SOUND_INSECTs ||
- sound == SOUND_INSECTa ||
- sound == SOUND_INSECTb ||
- sound == SOUND_INSECTw ||
- sound == SOUND_INSECTm ||
- sound == SOUND_PSHHH ||
- sound == SOUND_EGG )
- {
- return 0;
- }
-
- return 10;
-}
-
-
-bool ALSound::SearchFreeBuffer(Sound sound, int &channel, bool &bAlreadyLoaded)
-{
- int priority = RetPriority(sound);
-
- // Seeks a channel used which sound is stopped.
- for (auto it : mChannels) {
- if (it.second->IsPlaying())
- continue;
- if (it.second->GetSoundType() != sound)
- continue;
-
- it.second->SetPriority(priority);
- channel = it.first;
- bAlreadyLoaded = true;
- return true;
- }
-
- // just add a new channel if we dont have any
- if (mChannels.size() == 0) {
- Channel *chn = new Channel();
- // check if we channel ready to play music, if not report error
- if (chn->IsReady()) {
- chn->SetPriority(priority);
- mChannels[1] = chn;
- channel = 1;
- bAlreadyLoaded = false;
- return true;
- }
- delete chn;
- GetLogger()->Error("Could not open channel to play sound!");
- return false;
- }
-
- // Seeks a channel completely free.
- auto it = mChannels.end();
- it--;
- int i = (*it).first;
- while (++i)
- {
- if (mChannels.find(i) == mChannels.end()) {
- Channel *chn = new Channel();
- // check if we channel ready to play music, if not destroy it and seek free one
- if (chn->IsReady()) {
- chn->SetPriority(priority);
- mChannels[1] = chn;
- channel = 1;
- bAlreadyLoaded = false;
- return true;
- }
- delete chn;
- GetLogger()->Warn("Could not open additional channel to play sound!");
- }
- }
-
- int lowerOrEqual = -1;
- for (auto it : mChannels) {
- if (it.second->GetPriority() < priority) {
- GetLogger()->Info("Sound channel with lower priority will be reused.");
- channel = it.first;
- return true;
- }
- if (it.second->GetPriority() <= priority)
- lowerOrEqual = it.first;
- }
-
- if (lowerOrEqual != -1) {
- channel = lowerOrEqual;
- GetLogger()->Info("Sound channel with lower or equal priority will be reused.");
- return true;
- }
-
- GetLogger()->Warn("Could not find free buffer to use.\n");
- return false;
-}
-
-
-int ALSound::Play(Sound sound, float amplitude, float frequency, bool bLoop)
-{
- return Play(sound, Math::Vector(), amplitude, frequency, bLoop);
-}
-
-
-int ALSound::Play(Sound sound, Math::Vector pos, float amplitude, float frequency, bool bLoop)
-{
- if (!mEnabled)
- return -1;
-
- if (mAudioVolume <= 0.0f)
- return -1;
-
- if (mSounds.find(sound) == mSounds.end()) {
- GetLogger()->Warn("Sound %d was not loaded!\n", sound);
- return -1;
- }
-
- int channel;
- bool bAlreadyLoaded;
- if (!SearchFreeBuffer(sound, channel, bAlreadyLoaded))
- return -1;
- if ( !bAlreadyLoaded ) {
- mChannels[channel]->SetBuffer(mSounds[sound]);
- }
-
- Position(channel, pos);
-
- // setting initial values
- mChannels[channel]->SetStartAmplitude(amplitude);
- mChannels[channel]->SetStartFrequency(frequency);
- mChannels[channel]->SetChangeFrequency(1.0f);
- mChannels[channel]->ResetOper();
- mChannels[channel]->AdjustFrequency(frequency);
- mChannels[channel]->AdjustVolume(mAudioVolume);
- mChannels[channel]->Play();
- return channel;
-}
-
-
-bool ALSound::FlushEnvelope(int channel)
-{
- if (mChannels.find(channel) == mChannels.end()) {
- return false;
- }
-
- mChannels[channel]->ResetOper();
- return true;
-}
-
-
-bool ALSound::AddEnvelope(int channel, float amplitude, float frequency, float time, SoundNext oper)
-{
- if (!mEnabled)
- return false;
-
- if (mChannels.find(channel) == mChannels.end()) {
- return false;
- }
-
- SoundOper op;
- op.finalAmplitude = amplitude;
- op.finalFrequency = frequency;
- op.totalTime = time;
- op.nextOper = oper;
- mChannels[channel]->AddOper(op);
-
- return false;
-}
-
-
-bool ALSound::Position(int channel, Math::Vector pos)
-{
- if (!mEnabled)
- return false;
-
- if (mChannels.find(channel) == mChannels.end()) {
- return false;
- }
-
- mChannels[channel]->SetPosition(pos);
- return true;
-}
-
-
-bool ALSound::Frequency(int channel, float frequency)
-{
- if (!mEnabled)
- return false;
-
- if (mChannels.find(channel) == mChannels.end()) {
- return false;
- }
-
- mChannels[channel]->SetFrequency(frequency);
- return true;
-}
-
-bool ALSound::Stop(int channel)
-{
- if (!mEnabled)
- return false;
-
- if (mChannels.find(channel) == mChannels.end()) {
- return false;
- }
-
- mChannels[channel]->Stop();
- mChannels[channel]->ResetOper();
-
- return true;
-}
-
-
-bool ALSound::StopAll()
-{
- if (!mEnabled)
- return false;
-
- for (auto channel : mChannels) {
- channel.second->Stop();
- channel.second->ResetOper();
- }
-
- return true;
-}
-
-
-bool ALSound::MuteAll(bool bMute)
-{
- if (!mEnabled)
- return false;
-
- float volume;
- mMute = bMute;
- if (mMute)
- volume = 0;
- else
- volume = mAudioVolume;
-
- for (auto channel : mChannels) {
- channel.second->SetVolume(volume);
- }
-
- return true;
-}
-
-
-void ALSound::FrameMove(float delta)
-{
- if (!mEnabled)
- return;
-
- float progress;
- float volume, frequency;
- for (auto it : mChannels) {
- if (!it.second->IsPlaying())
- continue;
-
- if (!it.second->HasEnvelope())
- continue;
-
- //it.second->GetEnvelope().currentTime += delta;
- SoundOper oper = it.second->GetEnvelope();
- progress = it.second->GetCurrentTime() / oper.totalTime;
- progress = MIN(progress, 1.0f);
-
- // setting volume
- volume = progress * abs(oper.finalAmplitude - it.second->GetStartAmplitude());
- it.second->AdjustVolume(volume * mAudioVolume);
-
- // setting frequency
- frequency = progress * (oper.finalFrequency - it.second->GetStartFrequency()) * it.second->GetStartFrequency() * it.second->GetChangeFrequency();
- it.second->AdjustFrequency(frequency);
-
- if (it.second->GetEnvelope().totalTime <= it.second->GetCurrentTime()) {
-
- if (oper.nextOper == SOPER_LOOP) {
- GetLogger()->Info("Replay.\n");
- it.second->SetCurrentTime(0.0f);
- it.second->Play();
- } else {
- GetLogger()->Info("Next.\n");
- it.second->SetStartAmplitude(oper.finalAmplitude);
- it.second->SetStartFrequency(oper.finalFrequency);
- it.second->PopEnvelope();
- }
- }
- }
-}
-
-
-void ALSound::SetListener(Math::Vector eye, Math::Vector lookat)
-{
- GetLogger()->Info("Setting listener position.\n");
- float orientation[] = {lookat.x, lookat.y, lookat.z, 0.f, 1.f, 0.f};
- alListener3f(AL_POSITION, eye.x, eye.y, eye.z);
- alListenerfv(AL_ORIENTATION, orientation);
-}
-
-
-bool ALSound::PlayMusic(int rank, bool bRepeat)
-{
- // TODO stub! Add music support
- return true;
-}
-
-
-bool ALSound::RestartMusic()
-{
- // TODO stub! Add music support
- return true;
-}
-
-void ALSound::StopMusic()
-{
- // TODO stub! Add music support
- SuspendMusic();
-}
-
-
-bool ALSound::IsPlayingMusic()
-{
- // TODO stub! Add music support
- return true;
-}
-
-
-void ALSound::SuspendMusic()
-{
- // TODO stub! Add music support
-}
+// * This file is part of the COLOBOT source code
+// * Copyright (C) 2001-2008, Daniel ROUX & EPSITEC SA, www.epsitec.ch
+// * Copyright (C) 2012 Polish Portal of Colobot (PPC)
+// *
+// * This program is free software: you can redistribute it and/or modify
+// * it under the terms of the GNU General Public License as published by
+// * the Free Software Foundation, either version 3 of the License, or
+// * (at your option) any later version.
+// *
+// * 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. See the
+// * GNU General Public License for more details.
+// *
+// * You should have received a copy of the GNU General Public License
+// * along with this program. If not, see http://www.gnu.org/licenses/.
+
+// alsound.cpp
+
+
+#include "alsound.h"
+
+
+#define MIN(a, b) (a > b ? b : a)
+
+
+PLUGIN_INTERFACE(ALSound)
+
+
+std::string ALSound::PluginName()
+{
+ return "Sound plugin using OpenAL library to play sounds.";
+}
+
+
+int ALSound::PluginVersion()
+{
+ return 2;
+}
+
+
+void ALSound::InstallPlugin()
+{
+ auto pointer = CInstanceManager::GetInstancePointer();
+ if (pointer != nullptr)
+ CInstanceManager::GetInstancePointer()->AddInstance(CLASS_SOUND, this);
+}
+
+
+bool ALSound::UninstallPlugin(std::string &reason)
+{
+ auto pointer = CInstanceManager::GetInstancePointer();
+ if (pointer != nullptr)
+ CInstanceManager::GetInstancePointer()->DeleteInstance(CLASS_SOUND, this);
+ CleanUp();
+ return true;
+}
+
+
+ALSound::ALSound()
+{
+ mEnabled = false;
+ m3D = false;
+ mAudioVolume = MAXVOLUME;
+ mMute = false;
+}
+
+
+ALSound::~ALSound()
+{
+ CleanUp();
+}
+
+
+void ALSound::CleanUp()
+{
+ if (mEnabled) {
+ GetLogger()->Info("Unloading files and closing device...\n");
+ StopAll();
+
+ for (auto item : mSounds)
+ delete item.second;
+
+ mEnabled = false;
+ alutExit();
+ }
+}
+
+
+bool ALSound::Create(bool b3D)
+{
+ CleanUp();
+
+ if (mEnabled)
+ return true;
+
+ GetLogger()->Info("Opening audio device...\n");
+ if (!alutInit(NULL, NULL)) {
+ ALenum error = alutGetError();
+ GetLogger()->Error("Could not open audio device! Reason: %s\n", alutGetErrorString(error));
+ return false;
+ }
+ GetLogger()->Info("Done.\n");
+
+ mEnabled = true;
+ return true;
+}
+
+
+void ALSound::SetSound3D(bool bMode)
+{
+ // TODO stub! need to be implemented
+ m3D = bMode;
+}
+
+
+bool ALSound::RetSound3D()
+{
+ // TODO stub! need to be implemented
+ return true;
+}
+
+
+bool ALSound::RetSound3DCap()
+{
+ // TODO stub! need to be implemented
+ return true;
+}
+
+
+bool ALSound::RetEnable()
+{
+ return mEnabled;
+}
+
+
+void ALSound::SetAudioVolume(int volume)
+{
+ alListenerf(AL_GAIN, MIN(volume, MAXVOLUME) * 0.01f);
+ mAudioVolume = MIN(volume, MAXVOLUME);
+}
+
+
+int ALSound::RetAudioVolume()
+{
+ float volume;
+ if ( !mEnabled )
+ return 0;
+
+ alGetListenerf(AL_GAIN, &volume);
+ return volume * MAXVOLUME;
+}
+
+
+void ALSound::SetMusicVolume(int volume)
+{
+ // TODO stub! Add music support
+}
+
+
+int ALSound::RetMusicVolume()
+{
+ // TODO stub! Add music support
+ if ( !mEnabled )
+ return 0;
+
+ return 0;
+}
+
+
+bool ALSound::Cache(Sound sound, std::string filename)
+{
+ Buffer *buffer = new Buffer();
+ if (buffer->LoadFromFile(filename, sound)) {
+ mSounds[sound] = buffer;
+ return true;
+ }
+ return false;
+}
+
+
+void ALSound::CacheAll()
+{
+ char filename[100];
+ for ( int i = 1; i < 69; i++ )
+ {
+ sprintf(filename, "high/sound%.3d.wav", i);
+ if ( !Cache((Sound) i, std::string(filename)) )
+ {
+ fprintf(stderr, "Unable to load audio: %s\n", filename);
+ }
+ }
+}
+
+
+int ALSound::RetPriority(Sound sound)
+{
+ if ( sound == SOUND_FLYh ||
+ sound == SOUND_FLY ||
+ sound == SOUND_MOTORw ||
+ sound == SOUND_MOTORt ||
+ sound == SOUND_MOTORr ||
+ sound == SOUND_MOTORs ||
+ sound == SOUND_SLIDE ||
+ sound == SOUND_ERROR )
+ {
+ return 30;
+ }
+
+ if ( sound == SOUND_CONVERT ||
+ sound == SOUND_ENERGY ||
+ sound == SOUND_DERRICK ||
+ sound == SOUND_STATION ||
+ sound == SOUND_REPAIR ||
+ sound == SOUND_RESEARCH ||
+ sound == SOUND_BURN ||
+ sound == SOUND_BUILD ||
+ sound == SOUND_TREMBLE ||
+ sound == SOUND_NUCLEAR ||
+ sound == SOUND_EXPLO ||
+ sound == SOUND_EXPLOl ||
+ sound == SOUND_EXPLOlp ||
+ sound == SOUND_EXPLOp ||
+ sound == SOUND_EXPLOi )
+ {
+ return 20;
+ }
+
+ if ( sound == SOUND_BLUP ||
+ sound == SOUND_INSECTs ||
+ sound == SOUND_INSECTa ||
+ sound == SOUND_INSECTb ||
+ sound == SOUND_INSECTw ||
+ sound == SOUND_INSECTm ||
+ sound == SOUND_PSHHH ||
+ sound == SOUND_EGG )
+ {
+ return 0;
+ }
+
+ return 10;
+}
+
+
+bool ALSound::SearchFreeBuffer(Sound sound, int &channel, bool &bAlreadyLoaded)
+{
+ int priority = RetPriority(sound);
+
+ // Seeks a channel used which sound is stopped.
+ for (auto it : mChannels) {
+ if (it.second->IsPlaying())
+ continue;
+ if (it.second->GetSoundType() != sound)
+ continue;
+
+ it.second->SetPriority(priority);
+ channel = it.first;
+ bAlreadyLoaded = true;
+ return true;
+ }
+
+ // just add a new channel if we dont have any
+ if (mChannels.size() == 0) {
+ Channel *chn = new Channel();
+ // check if we channel ready to play music, if not report error
+ if (chn->IsReady()) {
+ chn->SetPriority(priority);
+ mChannels[1] = chn;
+ channel = 1;
+ bAlreadyLoaded = false;
+ return true;
+ }
+ delete chn;
+ GetLogger()->Error("Could not open channel to play sound!");
+ return false;
+ }
+
+ // Seeks a channel completely free.
+ auto it = mChannels.end();
+ it--;
+ int i = (*it).first;
+ while (++i)
+ {
+ if (mChannels.find(i) == mChannels.end()) {
+ Channel *chn = new Channel();
+ // check if we channel ready to play music, if not destroy it and seek free one
+ if (chn->IsReady()) {
+ chn->SetPriority(priority);
+ mChannels[1] = chn;
+ channel = 1;
+ bAlreadyLoaded = false;
+ return true;
+ }
+ delete chn;
+ GetLogger()->Warn("Could not open additional channel to play sound!");
+ }
+ }
+
+ int lowerOrEqual = -1;
+ for (auto it : mChannels) {
+ if (it.second->GetPriority() < priority) {
+ GetLogger()->Info("Sound channel with lower priority will be reused.");
+ channel = it.first;
+ return true;
+ }
+ if (it.second->GetPriority() <= priority)
+ lowerOrEqual = it.first;
+ }
+
+ if (lowerOrEqual != -1) {
+ channel = lowerOrEqual;
+ GetLogger()->Info("Sound channel with lower or equal priority will be reused.");
+ return true;
+ }
+
+ GetLogger()->Warn("Could not find free buffer to use.\n");
+ return false;
+}
+
+
+int ALSound::Play(Sound sound, float amplitude, float frequency, bool bLoop)
+{
+ return Play(sound, Math::Vector(), amplitude, frequency, bLoop);
+}
+
+
+int ALSound::Play(Sound sound, Math::Vector pos, float amplitude, float frequency, bool bLoop)
+{
+ if (!mEnabled)
+ return -1;
+
+ if (mAudioVolume <= 0.0f)
+ return -1;
+
+ if (mSounds.find(sound) == mSounds.end()) {
+ GetLogger()->Warn("Sound %d was not loaded!\n", sound);
+ return -1;
+ }
+
+ int channel;
+ bool bAlreadyLoaded;
+ if (!SearchFreeBuffer(sound, channel, bAlreadyLoaded))
+ return -1;
+ if ( !bAlreadyLoaded ) {
+ mChannels[channel]->SetBuffer(mSounds[sound]);
+ }
+
+ Position(channel, pos);
+
+ // setting initial values
+ mChannels[channel]->SetStartAmplitude(amplitude);
+ mChannels[channel]->SetStartFrequency(frequency);
+ mChannels[channel]->SetChangeFrequency(1.0f);
+ mChannels[channel]->ResetOper();
+ mChannels[channel]->AdjustFrequency(frequency);
+ mChannels[channel]->AdjustVolume(mAudioVolume);
+ mChannels[channel]->Play();
+ return channel;
+}
+
+
+bool ALSound::FlushEnvelope(int channel)
+{
+ if (mChannels.find(channel) == mChannels.end()) {
+ return false;
+ }
+
+ mChannels[channel]->ResetOper();
+ return true;
+}
+
+
+bool ALSound::AddEnvelope(int channel, float amplitude, float frequency, float time, SoundNext oper)
+{
+ if (!mEnabled)
+ return false;
+
+ if (mChannels.find(channel) == mChannels.end()) {
+ return false;
+ }
+
+ SoundOper op;
+ op.finalAmplitude = amplitude;
+ op.finalFrequency = frequency;
+ op.totalTime = time;
+ op.nextOper = oper;
+ mChannels[channel]->AddOper(op);
+
+ return false;
+}
+
+
+bool ALSound::Position(int channel, Math::Vector pos)
+{
+ if (!mEnabled)
+ return false;
+
+ if (mChannels.find(channel) == mChannels.end()) {
+ return false;
+ }
+
+ mChannels[channel]->SetPosition(pos);
+ return true;
+}
+
+
+bool ALSound::Frequency(int channel, float frequency)
+{
+ if (!mEnabled)
+ return false;
+
+ if (mChannels.find(channel) == mChannels.end()) {
+ return false;
+ }
+
+ mChannels[channel]->SetFrequency(frequency);
+ return true;
+}
+
+bool ALSound::Stop(int channel)
+{
+ if (!mEnabled)
+ return false;
+
+ if (mChannels.find(channel) == mChannels.end()) {
+ return false;
+ }
+
+ mChannels[channel]->Stop();
+ mChannels[channel]->ResetOper();
+
+ return true;
+}
+
+
+bool ALSound::StopAll()
+{
+ if (!mEnabled)
+ return false;
+
+ for (auto channel : mChannels) {
+ channel.second->Stop();
+ channel.second->ResetOper();
+ }
+
+ return true;
+}
+
+
+bool ALSound::MuteAll(bool bMute)
+{
+ if (!mEnabled)
+ return false;
+
+ float volume;
+ mMute = bMute;
+ if (mMute)
+ volume = 0;
+ else
+ volume = mAudioVolume;
+
+ for (auto channel : mChannels) {
+ channel.second->SetVolume(volume);
+ }
+
+ return true;
+}
+
+
+void ALSound::FrameMove(float delta)
+{
+ if (!mEnabled)
+ return;
+
+ float progress;
+ float volume, frequency;
+ for (auto it : mChannels) {
+ if (!it.second->IsPlaying())
+ continue;
+
+ if (!it.second->HasEnvelope())
+ continue;
+
+ //it.second->GetEnvelope().currentTime += delta;
+ SoundOper oper = it.second->GetEnvelope();
+ progress = it.second->GetCurrentTime() / oper.totalTime;
+ progress = MIN(progress, 1.0f);
+
+ // setting volume
+ volume = progress * abs(oper.finalAmplitude - it.second->GetStartAmplitude());
+ it.second->AdjustVolume(volume * mAudioVolume);
+
+ // setting frequency
+ frequency = progress * (oper.finalFrequency - it.second->GetStartFrequency()) * it.second->GetStartFrequency() * it.second->GetChangeFrequency();
+ it.second->AdjustFrequency(frequency);
+
+ if (it.second->GetEnvelope().totalTime <= it.second->GetCurrentTime()) {
+
+ if (oper.nextOper == SOPER_LOOP) {
+ GetLogger()->Info("Replay.\n");
+ it.second->SetCurrentTime(0.0f);
+ it.second->Play();
+ } else {
+ GetLogger()->Info("Next.\n");
+ it.second->SetStartAmplitude(oper.finalAmplitude);
+ it.second->SetStartFrequency(oper.finalFrequency);
+ it.second->PopEnvelope();
+ }
+ }
+ }
+}
+
+
+void ALSound::SetListener(Math::Vector eye, Math::Vector lookat)
+{
+ GetLogger()->Info("Setting listener position.\n");
+ float orientation[] = {lookat.x, lookat.y, lookat.z, 0.f, 1.f, 0.f};
+ alListener3f(AL_POSITION, eye.x, eye.y, eye.z);
+ alListenerfv(AL_ORIENTATION, orientation);
+}
+
+
+bool ALSound::PlayMusic(int rank, bool bRepeat)
+{
+ // TODO stub! Add music support
+ return true;
+}
+
+
+bool ALSound::RestartMusic()
+{
+ // TODO stub! Add music support
+ return true;
+}
+
+void ALSound::StopMusic()
+{
+ // TODO stub! Add music support
+ SuspendMusic();
+}
+
+
+bool ALSound::IsPlayingMusic()
+{
+ // TODO stub! Add music support
+ return true;
+}
+
+
+void ALSound::SuspendMusic()
+{
+ // TODO stub! Add music support
+}
diff --git a/src/sound/plugins/oalsound/alsound.h b/src/sound/plugins/oalsound/alsound.h
index c1cdb81..d13f95b 100644
--- a/src/sound/plugins/oalsound/alsound.h
+++ b/src/sound/plugins/oalsound/alsound.h
@@ -1,95 +1,95 @@
-// * This file is part of the COLOBOT source code
-// * Copyright (C) 2001-2008, Daniel ROUX & EPSITEC SA, www.epsitec.ch
-// * Copyright (C) 2012, Polish Portal of Colobot (PPC)
-// *
-// * This program is free software: you can redistribute it and/or modify
-// * it under the terms of the GNU General Public License as published by
-// * the Free Software Foundation, either version 3 of the License, or
-// * (at your option) any later version.
-// *
-// * 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. See the
-// * GNU General Public License for more details.
-// *
-// * You should have received a copy of the GNU General Public License
-// * along with this program. If not, see http://www.gnu.org/licenses/.
-
-// alsound.h
-
-#pragma once
-
-#include <map>
-#include <string>
-
-#include <AL/alut.h>
-
-#include <common/iman.h>
-#include <common/logger.h>
-#include <sound/sound.h>
-
-#include "buffer.h"
-#include "channel.h"
-#include "check.h"
-
-
-class ALSound : public CSoundInterface
-{
- public:
- ALSound();
- ~ALSound();
-
- bool Create(bool b3D);
- void CacheAll();
- bool Cache(Sound, std::string);
-
- bool RetEnable();
-
- void SetSound3D(bool bMode);
- bool RetSound3D();
- bool RetSound3DCap();
-
- void SetAudioVolume(int volume);
- int RetAudioVolume();
- void SetMusicVolume(int volume);
- int RetMusicVolume();
-
- void SetListener(Math::Vector eye, Math::Vector lookat);
- void FrameMove(float rTime);
-
- int Play(Sound sound, float amplitude=1.0f, float frequency=1.0f, bool bLoop = false);
- int Play(Sound sound, Math::Vector pos, float amplitude=1.0f, float frequency=1.0f, bool bLoop = false);
- bool FlushEnvelope(int channel);
- bool AddEnvelope(int channel, float amplitude, float frequency, float time, SoundNext oper);
- bool Position(int channel, Math::Vector pos);
- bool Frequency(int channel, float frequency);
- bool Stop(int channel);
- bool StopAll();
- bool MuteAll(bool bMute);
-
- bool PlayMusic(int rank, bool bRepeat);
- bool RestartMusic();
- void SuspendMusic();
- void StopMusic();
- bool IsPlayingMusic();
-
- // plugin interface
- std::string PluginName();
- int PluginVersion();
- void InstallPlugin();
- bool UninstallPlugin(std::string &);
-
- private:
- void CleanUp();
- int RetPriority(Sound);
- bool SearchFreeBuffer(Sound sound, int &channel, bool &bAlreadyLoaded);
-
- bool mEnabled;
- bool m3D;
- bool mMute;
- int mAudioVolume;
- ALCdevice* audioDevice;
- ALCcontext* audioContext;
- std::map<Sound, Buffer*> mSounds;
- std::map<int, Channel*> mChannels;
-};
+// * This file is part of the COLOBOT source code
+// * Copyright (C) 2001-2008, Daniel ROUX & EPSITEC SA, www.epsitec.ch
+// * Copyright (C) 2012, Polish Portal of Colobot (PPC)
+// *
+// * This program is free software: you can redistribute it and/or modify
+// * it under the terms of the GNU General Public License as published by
+// * the Free Software Foundation, either version 3 of the License, or
+// * (at your option) any later version.
+// *
+// * 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. See the
+// * GNU General Public License for more details.
+// *
+// * You should have received a copy of the GNU General Public License
+// * along with this program. If not, see http://www.gnu.org/licenses/.
+
+// alsound.h
+
+#pragma once
+
+#include <map>
+#include <string>
+
+#include <AL/alut.h>
+
+#include <common/iman.h>
+#include <common/logger.h>
+#include <sound/sound.h>
+
+#include "buffer.h"
+#include "channel.h"
+#include "check.h"
+
+
+class ALSound : public CSoundInterface
+{
+ public:
+ ALSound();
+ ~ALSound();
+
+ bool Create(bool b3D);
+ void CacheAll();
+ bool Cache(Sound, std::string);
+
+ bool RetEnable();
+
+ void SetSound3D(bool bMode);
+ bool RetSound3D();
+ bool RetSound3DCap();
+
+ void SetAudioVolume(int volume);
+ int RetAudioVolume();
+ void SetMusicVolume(int volume);
+ int RetMusicVolume();
+
+ void SetListener(Math::Vector eye, Math::Vector lookat);
+ void FrameMove(float rTime);
+
+ int Play(Sound sound, float amplitude=1.0f, float frequency=1.0f, bool bLoop = false);
+ int Play(Sound sound, Math::Vector pos, float amplitude=1.0f, float frequency=1.0f, bool bLoop = false);
+ bool FlushEnvelope(int channel);
+ bool AddEnvelope(int channel, float amplitude, float frequency, float time, SoundNext oper);
+ bool Position(int channel, Math::Vector pos);
+ bool Frequency(int channel, float frequency);
+ bool Stop(int channel);
+ bool StopAll();
+ bool MuteAll(bool bMute);
+
+ bool PlayMusic(int rank, bool bRepeat);
+ bool RestartMusic();
+ void SuspendMusic();
+ void StopMusic();
+ bool IsPlayingMusic();
+
+ // plugin interface
+ std::string PluginName();
+ int PluginVersion();
+ void InstallPlugin();
+ bool UninstallPlugin(std::string &);
+
+ private:
+ void CleanUp();
+ int RetPriority(Sound);
+ bool SearchFreeBuffer(Sound sound, int &channel, bool &bAlreadyLoaded);
+
+ bool mEnabled;
+ bool m3D;
+ bool mMute;
+ int mAudioVolume;
+ ALCdevice* audioDevice;
+ ALCcontext* audioContext;
+ std::map<Sound, Buffer*> mSounds;
+ std::map<int, Channel*> mChannels;
+};
diff --git a/src/tools/convert_model.cpp b/src/tools/convert_model.cpp
index a2f2b7a..a33d7d0 100644
--- a/src/tools/convert_model.cpp
+++ b/src/tools/convert_model.cpp
@@ -1,286 +1,286 @@
-#include "common/iman.h"
-#include "common/logger.h"
-#include "graphics/engine/modelfile.h"
-
-#include <iostream>
-#include <map>
-
-
-bool EndsWith(std::string const &fullString, std::string const &ending)
-{
- if (fullString.length() >= ending.length()) {
- return (0 == fullString.compare (fullString.length() - ending.length(), ending.length(), ending));
- } else {
- return false;
- }
-}
-
-
-struct Args
-{
- bool usage;
- bool dumpInfo;
- bool mirror;
- std::string inputFile;
- std::string outputFile;
- std::string inputFormat;
- std::string outputFormat;
-
- Args()
- {
- usage = false;
- dumpInfo = false;
- mirror = false;
- }
-};
-
-Args ARGS;
-
-void PrintUsage(const std::string& program)
-{
- std::cerr << "Colobot model converter" << std::endl;
- std::cerr << std::endl;
- std::cerr << "Usage:" << std::endl;
- std::cerr << std::endl;
- std::cerr << " Convert files:" << std::endl;
- std::cerr << " " << program << " -i input_file -if input_format -o output_file -of output_format [-m]" << std::endl;
- std::cerr << " -m => mirror" << std::endl;
- std::cerr << std::endl;
- std::cerr << " Dump info:" << std::endl;
- std::cerr << " " << program << " -d -i input_file -if input_format" << std::endl;
- std::cerr << std::endl;
- std::cerr << " Help:" << std::endl;
- std::cerr << " " << program << " -h" << std::endl;
- std::cerr << std::endl;
-
- std::cerr << "Model formats:" << std::endl;
- std::cerr << " old => old binary format" << std::endl;
- std::cerr << " new_bin => new binary format" << std::endl;
- std::cerr << " new_txt => new text format" << std::endl;
-}
-
-bool ParseArgs(int argc, char *argv[])
-{
- bool waitI = false, waitO = false;
- bool waitIf = false, waitOf = false;
- for (int i = 1; i < argc; ++i)
- {
- std::string arg = std::string(argv[i]);
-
- if (arg == "-i")
- {
- waitI = true;
- continue;
- }
- if (arg == "-o")
- {
- waitO = true;
- continue;
- }
- if (arg == "-if")
- {
- waitIf = true;
- continue;
- }
- if (arg == "-of")
- {
- waitOf = true;
- continue;
- }
-
- if (waitI)
- {
- waitI = false;
- ARGS.inputFile = arg;
- }
- else if (waitO)
- {
- waitO = false;
- ARGS.outputFile = arg;
- }
- else if (waitIf)
- {
- waitIf = false;
- ARGS.inputFormat = arg;
- }
- else if (waitOf)
- {
- waitOf = false;
- ARGS.outputFormat = arg;
- }
- else if (arg == "-h")
- {
- PrintUsage(argv[0]);
- ARGS.usage = true;
- }
- else if (arg == "-d")
- {
- ARGS.dumpInfo = true;
- }
- else if (arg == "-m")
- {
- ARGS.mirror = true;
- }
- else
- {
- return false;
- }
- }
-
- if (waitI || waitO || waitIf || waitOf)
- return false;
-
- if (ARGS.usage)
- return true;
-
- if (ARGS.inputFile.empty() || (!ARGS.dumpInfo && ARGS.outputFile.empty() ))
- return false;
-
- if (ARGS.inputFormat.empty() || (!ARGS.dumpInfo && ARGS.outputFormat.empty() ))
- return false;
-
- return true;
-}
-
-template<typename T>
-void PrintStats(const std::map<T, int>& stats, int total)
-{
- for (auto it = stats.begin(); it != stats.end(); ++it)
- {
- std::cerr << " " << (*it).first << " : " << (*it).second << " / " << total << std::endl;
- }
-}
-
-int main(int argc, char *argv[])
-{
- CLogger logger;
- logger.SetLogLevel(LOG_ERROR);
-
- if (!ParseArgs(argc, argv))
- {
- std::cerr << "Invalid arguments! Run with -h for usage info." << std::endl;
- return 1;
- }
-
- if (ARGS.usage)
- return 0;
-
- CInstanceManager iMan;
- Gfx::CModelFile model(&iMan);
-
- bool ok = true;
-
- if (ARGS.inputFormat == "old")
- {
- ok = model.ReadModel(ARGS.inputFile);
- }
- else if (ARGS.inputFormat == "new_bin")
- {
- ok = model.ReadBinaryModel(ARGS.inputFile);
- }
- else if (ARGS.inputFormat == "new_txt")
- {
- ok = model.ReadTextModel(ARGS.inputFile);
- }
- else
- {
- std::cerr << "Invalid input format" << std::endl;
- return 1;
- }
-
- if (!ok)
- {
- std::cerr << "Reading input model failed" << std::endl;
- return 1;
- }
-
- if (ARGS.dumpInfo)
- {
- const std::vector<Gfx::ModelTriangle>& triangles = model.GetTriangles();
-
- Math::Vector min( Math::HUGE_NUM, Math::HUGE_NUM, Math::HUGE_NUM);
- Math::Vector max(-Math::HUGE_NUM, -Math::HUGE_NUM, -Math::HUGE_NUM);
-
- std::map<std::string, int> texs1, texs2;
- std::map<int, int> states;
- std::map<float, int> mins, maxs;
- int variableTexs2 = 0;
-
- for (int i = 0; i < static_cast<int>( triangles.size() ); ++i)
- {
- const Gfx::ModelTriangle& t = triangles[i];
-
- min.x = Math::Min(t.p1.coord.x, t.p2.coord.x, t.p3.coord.x, min.x);
- min.y = Math::Min(t.p1.coord.y, t.p2.coord.y, t.p3.coord.y, min.y);
- min.z = Math::Min(t.p1.coord.z, t.p2.coord.z, t.p3.coord.z, min.z);
-
- max.x = Math::Max(t.p1.coord.x, t.p2.coord.x, t.p3.coord.x, max.x);
- max.y = Math::Max(t.p1.coord.y, t.p2.coord.y, t.p3.coord.y, max.y);
- max.z = Math::Max(t.p1.coord.z, t.p2.coord.z, t.p3.coord.z, max.z);
-
- texs1[t.tex1Name] += 1;
- if (! t.tex2Name.empty())
- texs2[t.tex2Name] += 1;
- if (t.variableTex2)
- variableTexs2 += 1;
- states[t.state] += 1;
-
- mins[t.min] += 1;
- maxs[t.max] += 1;
- }
-
- std::cerr << "---- Info ----" << std::endl;
- std::cerr << "Total triangles: " << triangles.size();
- std::cerr << std::endl;
- std::cerr << "Bounding box:" << std::endl;
- std::cerr << " min: [" << min.x << ", " << min.y << ", " << min.z << "]" << std::endl;
- std::cerr << " max: [" << max.x << ", " << max.y << ", " << max.z << "]" << std::endl;
- std::cerr << std::endl;
- std::cerr << "Textures:" << std::endl;
- std::cerr << " tex1:" << std::endl;
- PrintStats(texs1, triangles.size());
- std::cerr << " tex2:" << std::endl;
- PrintStats(texs2, triangles.size());
- std::cerr << " variable tex2: " << variableTexs2 << " / " << triangles.size() << std::endl;
- std::cerr << std::endl;
- std::cerr << "States:" << std::endl;
- PrintStats(states, triangles.size());
- std::cerr << std::endl;
- std::cerr << "LOD:" << std::endl;
- std::cerr << " min:" << std::endl;
- PrintStats(mins, triangles.size());
- std::cerr << " max:" << std::endl;
- PrintStats(maxs, triangles.size());
-
- return 0;
- }
-
- if (ARGS.mirror)
- model.Mirror();
-
- if (ARGS.outputFormat == "old")
- {
- ok = model.WriteModel(ARGS.outputFile);
- }
- else if (ARGS.outputFormat == "new_bin")
- {
- ok = model.WriteBinaryModel(ARGS.outputFile);
- }
- else if (ARGS.outputFormat == "new_txt")
- {
- ok = model.WriteTextModel(ARGS.outputFile);
- }
- else
- {
- std::cerr << "Invalid output format" << std::endl;
- return 1;
- }
-
- if (!ok)
- {
- std::cerr << "Writing output model failed" << std::endl;
- return 1;
- }
-
- return 0;
-}
+#include "common/iman.h"
+#include "common/logger.h"
+#include "graphics/engine/modelfile.h"
+
+#include <iostream>
+#include <map>
+
+
+bool EndsWith(std::string const &fullString, std::string const &ending)
+{
+ if (fullString.length() >= ending.length()) {
+ return (0 == fullString.compare (fullString.length() - ending.length(), ending.length(), ending));
+ } else {
+ return false;
+ }
+}
+
+
+struct Args
+{
+ bool usage;
+ bool dumpInfo;
+ bool mirror;
+ std::string inputFile;
+ std::string outputFile;
+ std::string inputFormat;
+ std::string outputFormat;
+
+ Args()
+ {
+ usage = false;
+ dumpInfo = false;
+ mirror = false;
+ }
+};
+
+Args ARGS;
+
+void PrintUsage(const std::string& program)
+{
+ std::cerr << "Colobot model converter" << std::endl;
+ std::cerr << std::endl;
+ std::cerr << "Usage:" << std::endl;
+ std::cerr << std::endl;
+ std::cerr << " Convert files:" << std::endl;
+ std::cerr << " " << program << " -i input_file -if input_format -o output_file -of output_format [-m]" << std::endl;
+ std::cerr << " -m => mirror" << std::endl;
+ std::cerr << std::endl;
+ std::cerr << " Dump info:" << std::endl;
+ std::cerr << " " << program << " -d -i input_file -if input_format" << std::endl;
+ std::cerr << std::endl;
+ std::cerr << " Help:" << std::endl;
+ std::cerr << " " << program << " -h" << std::endl;
+ std::cerr << std::endl;
+
+ std::cerr << "Model formats:" << std::endl;
+ std::cerr << " old => old binary format" << std::endl;
+ std::cerr << " new_bin => new binary format" << std::endl;
+ std::cerr << " new_txt => new text format" << std::endl;
+}
+
+bool ParseArgs(int argc, char *argv[])
+{
+ bool waitI = false, waitO = false;
+ bool waitIf = false, waitOf = false;
+ for (int i = 1; i < argc; ++i)
+ {
+ std::string arg = std::string(argv[i]);
+
+ if (arg == "-i")
+ {
+ waitI = true;
+ continue;
+ }
+ if (arg == "-o")
+ {
+ waitO = true;
+ continue;
+ }
+ if (arg == "-if")
+ {
+ waitIf = true;
+ continue;
+ }
+ if (arg == "-of")
+ {
+ waitOf = true;
+ continue;
+ }
+
+ if (waitI)
+ {
+ waitI = false;
+ ARGS.inputFile = arg;
+ }
+ else if (waitO)
+ {
+ waitO = false;
+ ARGS.outputFile = arg;
+ }
+ else if (waitIf)
+ {
+ waitIf = false;
+ ARGS.inputFormat = arg;
+ }
+ else if (waitOf)
+ {
+ waitOf = false;
+ ARGS.outputFormat = arg;
+ }
+ else if (arg == "-h")
+ {
+ PrintUsage(argv[0]);
+ ARGS.usage = true;
+ }
+ else if (arg == "-d")
+ {
+ ARGS.dumpInfo = true;
+ }
+ else if (arg == "-m")
+ {
+ ARGS.mirror = true;
+ }
+ else
+ {
+ return false;
+ }
+ }
+
+ if (waitI || waitO || waitIf || waitOf)
+ return false;
+
+ if (ARGS.usage)
+ return true;
+
+ if (ARGS.inputFile.empty() || (!ARGS.dumpInfo && ARGS.outputFile.empty() ))
+ return false;
+
+ if (ARGS.inputFormat.empty() || (!ARGS.dumpInfo && ARGS.outputFormat.empty() ))
+ return false;
+
+ return true;
+}
+
+template<typename T>
+void PrintStats(const std::map<T, int>& stats, int total)
+{
+ for (auto it = stats.begin(); it != stats.end(); ++it)
+ {
+ std::cerr << " " << (*it).first << " : " << (*it).second << " / " << total << std::endl;
+ }
+}
+
+int main(int argc, char *argv[])
+{
+ CLogger logger;
+ logger.SetLogLevel(LOG_ERROR);
+
+ if (!ParseArgs(argc, argv))
+ {
+ std::cerr << "Invalid arguments! Run with -h for usage info." << std::endl;
+ return 1;
+ }
+
+ if (ARGS.usage)
+ return 0;
+
+ CInstanceManager iMan;
+ Gfx::CModelFile model(&iMan);
+
+ bool ok = true;
+
+ if (ARGS.inputFormat == "old")
+ {
+ ok = model.ReadModel(ARGS.inputFile);
+ }
+ else if (ARGS.inputFormat == "new_bin")
+ {
+ ok = model.ReadBinaryModel(ARGS.inputFile);
+ }
+ else if (ARGS.inputFormat == "new_txt")
+ {
+ ok = model.ReadTextModel(ARGS.inputFile);
+ }
+ else
+ {
+ std::cerr << "Invalid input format" << std::endl;
+ return 1;
+ }
+
+ if (!ok)
+ {
+ std::cerr << "Reading input model failed" << std::endl;
+ return 1;
+ }
+
+ if (ARGS.dumpInfo)
+ {
+ const std::vector<Gfx::ModelTriangle>& triangles = model.GetTriangles();
+
+ Math::Vector min( Math::HUGE_NUM, Math::HUGE_NUM, Math::HUGE_NUM);
+ Math::Vector max(-Math::HUGE_NUM, -Math::HUGE_NUM, -Math::HUGE_NUM);
+
+ std::map<std::string, int> texs1, texs2;
+ std::map<int, int> states;
+ std::map<float, int> mins, maxs;
+ int variableTexs2 = 0;
+
+ for (int i = 0; i < static_cast<int>( triangles.size() ); ++i)
+ {
+ const Gfx::ModelTriangle& t = triangles[i];
+
+ min.x = Math::Min(t.p1.coord.x, t.p2.coord.x, t.p3.coord.x, min.x);
+ min.y = Math::Min(t.p1.coord.y, t.p2.coord.y, t.p3.coord.y, min.y);
+ min.z = Math::Min(t.p1.coord.z, t.p2.coord.z, t.p3.coord.z, min.z);
+
+ max.x = Math::Max(t.p1.coord.x, t.p2.coord.x, t.p3.coord.x, max.x);
+ max.y = Math::Max(t.p1.coord.y, t.p2.coord.y, t.p3.coord.y, max.y);
+ max.z = Math::Max(t.p1.coord.z, t.p2.coord.z, t.p3.coord.z, max.z);
+
+ texs1[t.tex1Name] += 1;
+ if (! t.tex2Name.empty())
+ texs2[t.tex2Name] += 1;
+ if (t.variableTex2)
+ variableTexs2 += 1;
+ states[t.state] += 1;
+
+ mins[t.min] += 1;
+ maxs[t.max] += 1;
+ }
+
+ std::cerr << "---- Info ----" << std::endl;
+ std::cerr << "Total triangles: " << triangles.size();
+ std::cerr << std::endl;
+ std::cerr << "Bounding box:" << std::endl;
+ std::cerr << " min: [" << min.x << ", " << min.y << ", " << min.z << "]" << std::endl;
+ std::cerr << " max: [" << max.x << ", " << max.y << ", " << max.z << "]" << std::endl;
+ std::cerr << std::endl;
+ std::cerr << "Textures:" << std::endl;
+ std::cerr << " tex1:" << std::endl;
+ PrintStats(texs1, triangles.size());
+ std::cerr << " tex2:" << std::endl;
+ PrintStats(texs2, triangles.size());
+ std::cerr << " variable tex2: " << variableTexs2 << " / " << triangles.size() << std::endl;
+ std::cerr << std::endl;
+ std::cerr << "States:" << std::endl;
+ PrintStats(states, triangles.size());
+ std::cerr << std::endl;
+ std::cerr << "LOD:" << std::endl;
+ std::cerr << " min:" << std::endl;
+ PrintStats(mins, triangles.size());
+ std::cerr << " max:" << std::endl;
+ PrintStats(maxs, triangles.size());
+
+ return 0;
+ }
+
+ if (ARGS.mirror)
+ model.Mirror();
+
+ if (ARGS.outputFormat == "old")
+ {
+ ok = model.WriteModel(ARGS.outputFile);
+ }
+ else if (ARGS.outputFormat == "new_bin")
+ {
+ ok = model.WriteBinaryModel(ARGS.outputFile);
+ }
+ else if (ARGS.outputFormat == "new_txt")
+ {
+ ok = model.WriteTextModel(ARGS.outputFile);
+ }
+ else
+ {
+ std::cerr << "Invalid output format" << std::endl;
+ return 1;
+ }
+
+ if (!ok)
+ {
+ std::cerr << "Writing output model failed" << std::endl;
+ return 1;
+ }
+
+ return 0;
+}
diff --git a/src/ui/color.cpp b/src/ui/color.cpp
index 200ed0c..5668519 100644
--- a/src/ui/color.cpp
+++ b/src/ui/color.cpp
@@ -105,7 +105,7 @@ bool CColor::EventProcess(const Event &event)
}
if ( event.type == EVENT_MOUSE_BUTTON_DOWN &&
- event.mouseButton.button == 1 &&
+ event.mouseButton.button == 1 &&
(m_state & STATE_VISIBLE) &&
(m_state & STATE_ENABLE) )
{
diff --git a/src/ui/color.h b/src/ui/color.h
index ad99ddd..311a532 100644
--- a/src/ui/color.h
+++ b/src/ui/color.h
@@ -52,7 +52,7 @@ namespace Ui {
protected:
bool m_bRepeat;
float m_repeat;
- Gfx::Color m_color;
+ Gfx::Color m_color;
};
diff --git a/src/ui/control.cpp b/src/ui/control.cpp
index 6ac82bc..fbf7575 100644
--- a/src/ui/control.cpp
+++ b/src/ui/control.cpp
@@ -199,13 +199,13 @@ std::string CControl::GetName()
void CControl::SetTextAlign(Gfx::TextAlign mode)
{
- m_textAlign = mode;
+ m_textAlign = mode;
// m_justif = mode;
}
int CControl::GetTextAlign()
{
- return m_textAlign;
+ return m_textAlign;
// return m_justif;
}