Skip to content
This repository was archived by the owner on May 2, 2024. It is now read-only.

Commit c2f6f18

Browse files
committed
Merged latests changes from develop branch
2 parents a9a6f89 + e90f301 commit c2f6f18

File tree

8 files changed

+75
-70
lines changed

8 files changed

+75
-70
lines changed

CMakeLists.txt

+4-1
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ ELSEIF ("${CMAKE_CXX_COMPILER_ID}" MATCHES "Clang")
8888
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -stdlib=libc++")
8989
ENDIF (XCODE_VERSION)
9090
ENDIF (NOT (CLANG_VERSION VERSION_GREATER 3.3 OR CLANG_VERSION VERSION_EQUAL 3.3))
91-
ELSEIF (MSVC AND (MSVC10 OR MSVC11))
91+
ELSEIF (MSVC AND (MSVC_VERSION GREATER 1599))
9292
MESSAGE("Supported Visual Studio!")
9393
ELSE ("${CMAKE_CXX_COMPILER_ID}" MATCHES "GNU")
9494
MESSAGE(FATAL_ERROR "Your C++ compiler does not support C++11.")
@@ -250,6 +250,9 @@ if(BUILD_SHARED_Sigma)
250250
set_target_properties(libSigma PROPERTIES
251251
OUTPUT_NAME Sigma
252252
)
253+
set_target_properties(libSigma PROPERTIES
254+
PDB_NAME libSigma
255+
)
253256
endif(BUILD_SHARED_Sigma)
254257

255258
if(BUILD_EXE_Sigma)

include/Log.h

+36-43
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
#define snprintf _snprintf
2424

2525
// Get bored of theses warnings
26-
#pragma warning(disable : 4996) // Ni puñetera idea
26+
#pragma warning(disable : 4996) // Ni pu�etera idea
2727
#pragma warning(disable : 4333) // Shift warning execding output var size, data loss
2828
#pragma warning(disable : 4018) // Comparation of signed and unsigned with auto conversion
2929
#pragma warning(disable : 4244) // Conversion of variables with data loss
@@ -37,13 +37,7 @@ namespace Log {
3737
/**
3838
* Logging levels
3939
*/
40-
enum LogLevel {
41-
LOGG_OFF = -1,
42-
LOGG_ERROR = 0,
43-
LOGG_WARN = 1,
44-
LOGG_INFO = 2,
45-
LOGG_DEBUG = 3,
46-
};
40+
enum LogLevel { OFF = -1, LL_ERROR = 0, LL_WARN = 1, LL_INFO = 2, LL_DEBUG = 3, LL_DEBUG1 };
4741

4842

4943
class Print {
@@ -70,7 +64,7 @@ namespace Log {
7064
* \param level Logger level. By default it is at Debug level
7165
* \param sout Output Streambuffer where to write. By default uses std::clog
7266
*/
73-
static void Init(LogLevel level = LogLevel::LOGG_DEBUG) {
67+
static void Init(LogLevel level = LogLevel::LL_DEBUG) {
7468
log_level = level;
7569
out = &std::clog;
7670
}
@@ -80,7 +74,7 @@ namespace Log {
8074
* \param level Logger level. By default it is at Debug level
8175
* \param sout Output Streambuffer where to write. By default uses std::clog
8276
*/
83-
static void Init(std::ostream& sout, LogLevel level = LogLevel::LOGG_DEBUG) {
77+
static void Init(std::ostream& sout, LogLevel level = LogLevel::LL_DEBUG) {
8478
log_level = level;
8579
out = &sout;
8680
}
@@ -96,35 +90,34 @@ namespace Log {
9690
* /brief Builds an instance of the logger
9791
* /param level Logging level of the message
9892
*/
99-
Print( LogLevel level ) :
100-
output( level <= log_level ), level(level) {
101-
102-
if( output ) {
103-
switch (level) {
104-
case LogLevel::LOGG_ERROR:
105-
*out << "[ERROR] ";
106-
break;
107-
108-
case LogLevel::LOGG_WARN:
109-
*out << "[WARNING] ";
110-
break;
111-
112-
case LogLevel::LOGG_INFO:
113-
*out << "[INFO] ";
114-
break;
115-
116-
case LogLevel::LOGG_DEBUG:
117-
*out << "[DEBUG] ";
118-
break;
119-
120-
default:
121-
break;
122-
}
123-
// Auto ident more if is more severe
124-
//*out << std::string( static_cast<int>(logger::log_level) -
125-
// static_cast<int>(level), '\t');
93+
Print( LogLevel level ) : output( level <= log_level ), level(level) {
94+
if( output ) {
95+
// Last ditch effort to make sure out is valid and set it if it isn't.
96+
if (!out) {
97+
out = &std::clog;
98+
}
99+
switch (level) {
100+
case LogLevel::LL_ERROR:
101+
*out << "[ERROR] ";
102+
break;
103+
104+
case LogLevel::LL_WARN:
105+
*out << "[WARNING] ";
106+
break;
107+
108+
case LogLevel::LL_INFO:
109+
*out << "[INFO] ";
110+
break;
111+
112+
case LogLevel::LL_DEBUG:
113+
*out << "[DEBUG] ";
114+
break;
115+
116+
default:
117+
break;
126118
}
127119
}
120+
}
128121

129122
/**
130123
* \brief Destructor of the class. Here writes the output
@@ -147,7 +140,7 @@ namespace Log {
147140
}
148141

149142
/**
150-
* \brief Opertaor << to write anything at the C++ way. Allow to chain multiple strings or values
143+
* \brief Operator << to write anything at the C++ way. Allow to chain multiple strings or values
151144
*/
152145
template<typename T>
153146
Print& operator<<( T t) {
@@ -162,10 +155,10 @@ namespace Log {
162155
} // END OF NAMESPACE logger
163156

164157
// Macros to type less
165-
#define LOG_DEBUG Log::Print(Log::LogLevel::LOGG_DEBUG)
166-
#define LOG Log::Print(Log::LogLevel::LOGG_INFO)
167-
#define LOG_WARN Log::Print(Log::LogLevel::LOGG_WARN)
168-
#define LOG_ERROR Log::Print(Log::LogLevel::LOGG_ERROR)
169-
158+
#define LOG_DEBUG Log::Print(Log::LogLevel::LL_DEBUG)
159+
#define LOG Log::Print(Log::LogLevel::LL_INFO)
160+
#define LOG_WARN Log::Print(Log::LogLevel::LL_WARN)
161+
#define LOG_ERROR Log::Print(Log::LogLevel::LL_ERROR)
162+
#define LOG_DEBUG1 Log::Print(Log::LogLevel::LL_DEBUG1)
170163

171164
#endif // __LOGGER_H_

include/systems/OpenALSystem.h

+2-6
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,6 @@
2323
#include "components/ALSound.h"
2424
#include "Sigma.h"
2525

26-
//#define OPENAL_DEBUG
27-
#if defined(OPENAL_DEBUG)
28-
#define ALDEBUG(a) a
29-
#else
30-
#define ALDEBUG(a)
31-
#endif
3226

3327
namespace Sigma {
3428
class OpenALSystem
@@ -101,6 +95,8 @@ namespace Sigma {
10195
std::weak_ptr<resource::SoundFile> p;
10296
if (audiofiles.find(i) != audiofiles.end()) {
10397
p = audiofiles[i];
98+
} else {
99+
LOG_WARN << "Invalid Sound index: " << i;
104100
}
105101
return p;
106102
}

src/SoundFile.cpp

+13-4
Original file line numberDiff line numberDiff line change
@@ -76,13 +76,17 @@ namespace Sigma {
7676
else if(chk.id == FourCC('d','a','t','a')) {
7777
if(this->data) { free(data); }
7878
this->data = (unsigned char*)malloc(sizeof(WAVEHeader) + 4 + chk.size);
79-
if(this->data == nullptr) { return; }
79+
if(this->data == nullptr) {
80+
LOG_ERROR << errno << "] Memory can not allocate " << sizeof(WAVEHeader) + 4 + chk.size << " bytes";
81+
return;
82+
}
8083
*((unsigned long*)this->data) = chk.size / (head.align);
8184
memcpy(this->data + 4, &head, sizeof(WAVEHeader));
8285
fh.read((char*)this->data + 4 + sizeof(WAVEHeader), chk.size);
8386
readcount -= chk.size;
8487
}
8588
else {
89+
LOG_DEBUG << "[WAV] Skip chunk " << chk.id.cvalue[0] << chk.id.cvalue[1] << chk.id.cvalue[2] << chk.id.cvalue[3];
8690
fh.ignore(chk.size); // unknown chunks
8791
}
8892
}
@@ -107,7 +111,10 @@ namespace Sigma {
107111
offs = 0;
108112
if(this->data) { free(data); }
109113
this->data = (unsigned char*)malloc(allosz);
110-
if(this->data == nullptr) { return; }
114+
if(this->data == nullptr) {
115+
LOG_ERROR << errno << "] Memory can not allocate " << allosz << " bytes";
116+
return;
117+
}
111118
opdata = (OggLinkedPacket*)this->data;
112119

113120
ogg_sync_init(&sync);
@@ -132,7 +139,7 @@ namespace Sigma {
132139
bytec = opdata->pack.bytes;
133140
if(!offs) {
134141
if(vorbis_synthesis_idheader(&opdata->pack) == 1) {
135-
LOG << "\nVorbis ";
142+
LOG_DEBUG << "Vorbis";
136143
dataformat = Vorbis;
137144
}
138145
}
@@ -154,6 +161,8 @@ namespace Sigma {
154161
offs += sizeof(OggLinkedPacket) + bytec;
155162
opdata = (OggLinkedPacket*)(this->data + offs);
156163
datasz = ndatasz;
164+
} else {
165+
LOG_WARN << errno << "] Memory can not reallocate " << allosz << " bytes";
157166
}
158167
}
159168
}
@@ -490,7 +499,7 @@ namespace Sigma {
490499
fh.read(fourcc.cvalue, 4); // read the id string
491500
fh.seekg(0, std::ios::beg);
492501
if(fourcc == FourCC('R','I','F','F')) {
493-
LOG << "Loading Sound from WAV file: " << fn << '\n';
502+
LOG << "Loading Sound from WAV file: " << fn;
494503
LoadWAV(fh, sz);
495504
ProcessMeta();
496505
}

src/components/ALSound.cpp

+16-13
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,9 @@ namespace Sigma {
3434
albuf = master->buffers[this->buffers[this->bufferindex]]->GetID();
3535
if(param != 0 && playlist.size() > 0) {
3636
sfi = playlist[playindex];
37+
if(master->GetSoundFile(sfi).expired()) {
38+
return;
39+
}
3740
sfp = std::shared_ptr<resource::SoundFile>(master->GetSoundFile(sfi));
3841
if(stream) {
3942
chancount = sfp->Channels();
@@ -44,7 +47,7 @@ namespace Sigma {
4447
buf = new short[buflen];
4548
if(++this->bufferindex >= this->buffercount) {
4649
this->bufferindex = 0;
47-
ALDEBUG(std::cerr << "ALSound: Buffer-set wrap around\n";)
50+
LOG_DEBUG1 << "ALSound: Buffer-set wrap around";
4851
}
4952
i = codec.FetchBuffer(*sfp, buf, ((chancount == 1) ? resource::PCM_MONO16 : resource::PCM_STEREO16), samplecount);
5053
alSourceUnqueueBuffers(this->sourceid, 1, &albuf);
@@ -53,27 +56,27 @@ namespace Sigma {
5356
buflen = chancount * i;
5457
if(playloop == PLAYBACK_LOOP) {
5558
this->codec.Rewind(*sfp);
56-
ALDEBUG(std::cerr << "ALSound: Looping stream at sample: " << i << '\n';)
59+
LOG_DEBUG1 << "ALSound: Looping stream at sample: " << i;
5760
//bufbytes = i;
5861
//i = codec.FetchBuffer(*sfp, buf+bufbytes, ((chancount == 1) ? resource::PCM_MONO16 : resource::PCM_STEREO16), samplecount - i);
5962
//buflen = bufbytes+i;
6063
buflen = i;
6164
buflen *= chancount;
6265
} else {
63-
ALDEBUG(std::cerr << "ALSound: Playback done; at sample: " << i << '\n';)
66+
LOG_DEBUG1 << "ALSound: Playback done; at sample: " << i;
6467
playing = false;
6568
}
6669
bufbytes = buflen * sizeof(short);
67-
ALDEBUG(std::cerr << "ALSound: Buffered " << albuf << "b + " << i << '/' << samplecount << " samples\n";)
70+
LOG_DEBUG1 << "ALSound: Buffered " << albuf << "b + " << i << '/' << samplecount << " samples";
6871
alBufferData(albuf, ((chancount == 1) ? AL_FORMAT_MONO16 : AL_FORMAT_STEREO16), buf, bufbytes, samplerate);
6972
}
7073
else {
71-
ALDEBUG(std::cerr << "ALSound: Buffered " << albuf << "b + " << i << '/' << samplecount << " samples\n";)
74+
LOG_DEBUG1 << "ALSound: Buffered " << albuf << "b + " << i << '/' << samplecount << " samples";
7275
alBufferData(albuf, ((chancount == 1) ? AL_FORMAT_MONO16 : AL_FORMAT_STEREO16), buf, bufbytes, samplerate);
7376
}
7477
alSourceQueueBuffers(this->sourceid, 1, &albuf);
7578
} else {
76-
ALDEBUG(std::cerr << "ALSound: Playback end " << albuf << "b + " << i << '/' << samplecount << "samples\n";)
79+
LOG_DEBUG1 << "ALSound: Playback end " << albuf << "b + " << i << '/' << samplecount << "samples";
7780
if(playloop == PLAYBACK_LOOP) {
7881
this->codec.Rewind(*sfp);
7982
} else {
@@ -84,7 +87,7 @@ namespace Sigma {
8487
}
8588
}
8689
else if(param == this->buffercount && stream) {
87-
ALDEBUG(std::cerr << "ALSound: Playback underrun\n";)
90+
LOG_DEBUG1 << "ALSound: Playback underrun";
8891
alSourcei(this->sourceid, AL_LOOPING, AL_FALSE);
8992
}
9093
}
@@ -126,12 +129,12 @@ namespace Sigma {
126129
bufbytes = buflen * 2;
127130
this->codec.Rewind(*sfp);
128131
buf = new unsigned short[buflen];
129-
ALDEBUG(std::cerr << "ALSound: Buffering Ch:" << chancount << " R:" << samplerate << " sz:" << bufbytes << "\n";)
132+
LOG_DEBUG1 << "ALSound: Buffering Ch:" << chancount << " R:" << samplerate << " sz:" << bufbytes;
130133
x = 0;
131134
while(x < this->buffercount && 0 < (i = codec.FetchBuffer(*sfp, buf, ((chancount == 1) ? resource::PCM_MONO16 : resource::PCM_STEREO16), samplecount))) {
132135
albuf[x] = master->buffers[this->buffers[x]]->GetID();
133136
if(i < samplecount) {
134-
ALDEBUG(std::cerr << "ALSound: Buffered " << x << "b + " << i << '/' << samplecount << "samples\n";)
137+
LOG_DEBUG1 << "ALSound: Buffered " << x << "b + " << i << '/' << samplecount << "samples";
135138
buflen = chancount * i;
136139
stream = false;
137140
bufbytes = buflen * sizeof(short);
@@ -143,15 +146,15 @@ namespace Sigma {
143146
//break;
144147
}
145148
else {
146-
ALDEBUG(std::cerr << "ALSound: Buffered " << x << "b + " << i << '/' << bufbytes << "\n";)
149+
LOG_DEBUG1 << "ALSound: Buffered " << x << "b + " << i << '/' << bufbytes;
147150
alBufferData(albuf[x], ((chancount == 1) ? AL_FORMAT_MONO16 : AL_FORMAT_STEREO16), buf, bufbytes, samplerate);
148151
stream = true;
149152
}
150153
x++;
151154
}
152155
if(x < this->buffercount) {
153156
stream = false;
154-
ALDEBUG(std::cerr << "ALSound: Only " << x << '/' << this->buffercount << " buffers used, not streaming.\n";)
157+
LOG_DEBUG1 << "ALSound: Only " << x << '/' << this->buffercount << " buffers used, not streaming.";
155158
}
156159
delete buf;
157160
if(x > 0) {
@@ -161,10 +164,10 @@ namespace Sigma {
161164
alSourcePlay(this->sourceid);
162165
if(playloop == PLAYBACK_LOOP && !stream) {
163166
alSourcei(this->sourceid, AL_LOOPING, AL_TRUE);
164-
ALDEBUG(std::cerr << "ALSound: Looping playback\n";)
167+
LOG_DEBUG1 << "ALSound: Looping playback";
165168
} else {
166169
alSourcei(this->sourceid, AL_LOOPING, AL_FALSE);
167-
ALDEBUG(std::cerr << "ALSound: NOT looping playback, stream:" << stream << '\n';)
170+
LOG_DEBUG1 << "ALSound: NOT looping playback, stream:" << stream;
168171
}
169172
playing = true;
170173
paused = false;

src/systems/OpenALSystem.cpp

+1
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ namespace Sigma {
6060
this->audioindex[filename] = i;
6161
return i;
6262
} else {
63+
LOG_WARN << "Failed to load sound from " << filename;
6364
this->audiofiles.erase(i);
6465
return 0;
6566
}

src/tests/Log.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ int main () {
1717
LOG_WARN << "Hello world!";
1818
LOG_ERROR << "Hello world!";
1919

20-
Log::Print::Level(Log::LogLevel::LOGG_WARN);
20+
Log::Print::Level(Log::LogLevel::LL_WARN);
2121
LOG_DEBUG << "Hello world! 2";
2222
LOG << "Hello world! 2";
2323
LOG_WARN << "Hello world! 2";
@@ -54,7 +54,7 @@ int main () {
5454
LOG_ERROR << "String : " << str1;
5555
LOG_ERROR << "String : " << path << filename;
5656

57-
Log::Print::Level(Log::LogLevel::LOGG_WARN);
57+
Log::Print::Level(Log::LogLevel::LL_WARN);
5858
LOG_DEBUG << "You shouldn't see this";
5959
LOG << "Too verbose...";
6060
LOG_WARN << "Alarm!";

src/tests/main.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
#endif
1919

2020
int main(int argCount, char **argValues) {
21-
Log::Print::Init(); // Initiatin the Logger must the first thing
21+
Log::Print::Init(); // Initializing the Logger must be done first.
2222

2323
Sigma::WebGUISystem webguisys;
2424

0 commit comments

Comments
 (0)