From: Charles McGarvey Date: Mon, 7 Sep 2009 06:21:58 +0000 (-0600) Subject: initial port to win32 X-Git-Url: https://git.brokenzipper.com/gitweb?a=commitdiff_plain;h=8ad81a8282ce6e9e488a453e6bcd05fbc09715dc;p=chaz%2Fyoink initial port to win32 --- diff --git a/configure.ac b/configure.ac index 731e421..c510429 100644 --- a/configure.ac +++ b/configure.ac @@ -39,8 +39,8 @@ AC_ARG_ENABLE([debug], [debug=$enableval if test x$debug = xyes then - CFLAGS="-Wall -Werror -gstabs+ -O0 -DDEBUG" - CXXFLAGS="-Wall -Werror -gstabs+ -O0 -DDEBUG" + CFLAGS="-O0 -DDEBUG" + CXXFLAGS="-O0 -DDEBUG" else CFLAGS="-O2 -DNDEBUG" CXXFLAGS="-O2 -DNDEBUG" @@ -69,6 +69,11 @@ AC_ARG_WITH([assetdir], [DATADIR="$withval"], [eval DATADIR="$datarootdir/yoink"]) +case "${host}" in + *mingw32*) + DATADIR="data" +esac + AC_SUBST([DATADIR]) AC_DEFINE_UNQUOTED([YOINK_DATADIR], ["$DATADIR"], [Define to path of game asset directory.]) @@ -96,22 +101,22 @@ BOOST_BIND BOOST_FUNCTION AC_SEARCH_LIBS([IMG_Load], [SDL_image],, - [AC_MSG_ERROR([libSDL_image is required])]) + [AC_MSG_ERROR([SDL_image is required])]) AC_SEARCH_LIBS([Sound_Init], [SDL_sound],, - [AC_MSG_ERROR([libSDL_sound is required])]) + [AC_MSG_ERROR([SDL_sound is required])]) -AC_SEARCH_LIBS([glBegin], [GL],, - [AC_MSG_ERROR([libGL is required])]) +AC_SEARCH_LIBS([glBegin], [GL opengl32],, + [AC_MSG_ERROR([OpenGL is required])]) -AC_SEARCH_LIBS([gluPerspective], [GLU],, - [AC_MSG_ERROR([libGLU is required])]) +AC_SEARCH_LIBS([gluPerspective], [GLU MesaGLU glu32],, + [AC_MSG_ERROR([GLU is required])]) -AC_SEARCH_LIBS([alGenBuffers], [openal],, - [AC_MSG_ERROR([libopenal is required])]) +AC_SEARCH_LIBS([alGenBuffers], [openal openal32],, + [AC_MSG_ERROR([OpenAL is required])]) AC_SEARCH_LIBS([alutInit], [alut],, - [AC_MSG_ERROR([libalut is required])]) + [AC_MSG_ERROR([alut is required])]) AC_SEARCH_LIBS([clock_gettime], [rt], [AC_DEFINE([HAVE_CLOCK_GETTIME], 1, diff --git a/src/Makefile.am b/src/Makefile.am index 8b3900c..01c521e 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -32,7 +32,6 @@ libmoof_la_SOURCES = \ Moof/Mippleton.hh \ Moof/Octree.cc \ Moof/Octree.hh \ - Moof/OpenGL.cc \ Moof/OpenGL.hh \ Moof/Physics.hh \ Moof/Plane.cc \ diff --git a/src/Moof/Camera.cc b/src/Moof/Camera.cc index 376e2c5..06261a1 100644 --- a/src/Moof/Camera.cc +++ b/src/Moof/Camera.cc @@ -26,9 +26,8 @@ *******************************************************************************/ -#include -#include -#include +#include "Camera.hh" +#include "OpenGL.hh" namespace Mf { @@ -52,11 +51,11 @@ void Camera::setProjection(const Matrix4& projection) projection_ = projection; } -void Camera::setProjection(Scalar fovy, Scalar aspect, Scalar near, Scalar far) +void Camera::setProjection(Scalar fovy, Scalar aspect, Scalar abutting, + Scalar distant) { - cml::matrix_perspective_yfov_RH(projection_, fovy, aspect, near, far, - cml::z_clip_neg_one); - + cml::matrix_perspective_yfov_RH(projection_, fovy, aspect, abutting, + distant, cml::z_clip_neg_one); calculateSecondary(); } @@ -80,7 +79,8 @@ void Camera::update(Scalar t, Scalar dt) void Camera::lookAt(const Vector3& point) { - cml::quaternion_rotation_aim_at(rotation_, position_, point, Vector3(0.0, -1.0, 0.0)); + cml::quaternion_rotation_aim_at(rotation_, position_, point, + Vector3(0.0, -1.0, 0.0)); calculateSecondary(); } diff --git a/src/Moof/Camera.hh b/src/Moof/Camera.hh index 24632a5..72df5db 100644 --- a/src/Moof/Camera.hh +++ b/src/Moof/Camera.hh @@ -46,7 +46,7 @@ public: Camera() : position_(0.0, 0.0, 0.0) { - quaternion_rotation_world_y(rotation_, 0.0); + cml::quaternion_rotation_world_y(rotation_, 0.0); calculateSecondary(); } diff --git a/src/Moof/Engine.cc b/src/Moof/Engine.cc index df6b35a..2740652 100644 --- a/src/Moof/Engine.cc +++ b/src/Moof/Engine.cc @@ -53,7 +53,11 @@ public: Engine* outer) : interface(outer) { +#if defined(_WIN32) || defined (_WIN64) || defined(__WIN32__) + if (SDL_Init(SDL_INIT_EVERYTHING) != 0) +#else if (SDL_Init(SDL_INIT_EVERYTHING | SDL_INIT_EVENTTHREAD) != 0) +#endif { std::cerr << "sdl is complaining: " << SDL_GetError() << std::endl; throw Exception(Exception::SDL_ERROR); diff --git a/src/Moof/Frustum.cc b/src/Moof/Frustum.cc index 4dc6340..dddbde0 100644 --- a/src/Moof/Frustum.cc +++ b/src/Moof/Frustum.cc @@ -50,11 +50,11 @@ void Frustum::init(const Matrix4& modelview, const Matrix4& projection) } void Frustum::init(const Matrix4& modelview, Scalar fovy, Scalar aspect, - Scalar near, Scalar far) + Scalar abutting, Scalar distant) { Matrix4 projection; - cml::matrix_perspective_yfov_RH(projection, fovy, aspect, near, far, + cml::matrix_perspective_yfov_RH(projection, fovy, aspect, abutting, distant, cml::z_clip_neg_one); init(modelview, projection); diff --git a/src/Moof/Frustum.hh b/src/Moof/Frustum.hh index a50dc83..4154f14 100644 --- a/src/Moof/Frustum.hh +++ b/src/Moof/Frustum.hh @@ -57,14 +57,14 @@ public: init(modelview, projection); } inline Frustum(const Matrix4& modelview, Scalar fovy, Scalar aspect, - Scalar near, Scalar far) + Scalar abutting, Scalar distant) { - init(modelview, fovy, aspect, near, far); + init(modelview, fovy, aspect, abutting, distant); } void init(const Matrix4& modelview, const Matrix4& projection); - void init(const Matrix4& modelview, Scalar fovy, Scalar aspect, Scalar near, - Scalar far); + void init(const Matrix4& modelview, Scalar fovy, Scalar aspect, + Scalar abutting, Scalar distant); Collision containsAabb(const Aabb& aabb) const; Collision containsSphere(const Sphere& sphere) const; diff --git a/src/Moof/Log.cc b/src/Moof/Log.cc index ddd12bb..0639a60 100644 --- a/src/Moof/Log.cc +++ b/src/Moof/Log.cc @@ -36,7 +36,7 @@ namespace Mf { -static LogLevel logLevel_ = WARNING; +static LogLevel logLevel_ = LOG_WARNING; inline void printLog_(int logLevel, const char* fmt, va_list args) { @@ -44,16 +44,16 @@ inline void printLog_(int logLevel, const char* fmt, va_list args) switch (logLevel) { - case ERROR: + case LOG_ERROR: fprintf(stderr, " error: "); break; - case WARNING: + case LOG_WARNING: fprintf(stderr, "warning: "); break; - case INFO: + case LOG_INFO: fprintf(stderr, " info: "); break; - case DEBUGGING: + case LOG_DEBUG: fprintf(stderr, " debug: "); break; } @@ -77,7 +77,7 @@ void logError(const char* fmt, ...) va_list args; va_start(args, fmt); - printLog_(ERROR, fmt, args); + printLog_(LOG_ERROR, fmt, args); va_end(args); } @@ -87,7 +87,7 @@ void logWarning(const char* fmt, ...) va_list args; va_start(args, fmt); - printLog_(WARNING, fmt, args); + printLog_(LOG_WARNING, fmt, args); va_end(args); } @@ -97,7 +97,7 @@ void logInfo(const char* fmt, ...) va_list args; va_start(args, fmt); - printLog_(INFO, fmt, args); + printLog_(LOG_INFO, fmt, args); va_end(args); } @@ -107,7 +107,7 @@ void logDebug(const char* fmt, ...) va_list args; va_start(args, fmt); - printLog_(DEBUGGING, fmt, args); + printLog_(LOG_DEBUG, fmt, args); va_end(args); } diff --git a/src/Moof/Log.hh b/src/Moof/Log.hh index 3f6b6d7..cdd5cd4 100644 --- a/src/Moof/Log.hh +++ b/src/Moof/Log.hh @@ -62,13 +62,14 @@ namespace Mf { * @see LogLevel() */ -typedef enum { - NONE = -1, ///< Disable all logging. - ERROR = 1, ///< Log only errors. - WARNING = 2, ///< Log warnings and errors. - INFO = 3, ///< Log info, warnings, errors. - DEBUGGING = 4 ///< Log all messages. -} LogLevel; +enum LogLevel +{ + LOG_NONE = -1, ///< Disable all logging. + LOG_ERROR = 1, ///< Log only errors. + LOG_WARNING = 2, ///< Log warnings and errors. + LOG_INFO = 3, ///< Log info, warnings, errors. + LOG_DEBUG = 4 ///< Log all messages. +}; /** diff --git a/src/Moof/OpenGL.cc b/src/Moof/OpenGL.cc deleted file mode 100644 index b286b35..0000000 --- a/src/Moof/OpenGL.cc +++ /dev/null @@ -1,96 +0,0 @@ - -/******************************************************************************* - - Copyright (c) 2009, Charles McGarvey - All rights reserved. - - Redistribution and use in source and binary forms, with or without - modification, are permitted provided that the following conditions are met: - - * Redistributions of source code must retain the above copyright notice, - this list of conditions and the following disclaimer. - * Redistributions in binary form must reproduce the above copyright notice, - this list of conditions and the following disclaimer in the documentation - and/or other materials provided with the distribution. - - THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE - FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR - SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER - CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, - OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - -*******************************************************************************/ - -#include "OpenGL.hh" - - -#if USE_DOUBLE_PRECISION - -void (*glGetScalarv)(GLenum, GLscalar*)(glGetDoublev); - -void (*glLoadMatrix)(const GLscalar*)(glLoadMatrixd); -void (*glMultMatrix)(const GLscalar*)(glMultMatrixd); - -void (*glScale)(GLscalar, GLscalar, GLscalar)(glScaled); -void (*glRotate)(GLscalar, GLscalar, GLscalar, GLscalar)(glRotated); -void (*glTranslate)(GLscalar, GLscalar, GLscalar)(glTranslated); - -void (*glColor3)(GLscalar, GLscalar, GLscalar)(glColor3d); -void (*glColor4)(GLscalar, GLscalar, GLscalar, GLscalar)(glColor4d); -void (*glColor3v)(const GLscalar*)(glColor3dv); -void (*glColor4v)(const GLscalar*)(glColor4dv); - -void (*glVertex2)(GLscalar, GLscalar)(glVertex2d); -void (*glVertex3)(GLscalar, GLscalar, GLscalar)(glVertex3d); -void (*glVertex4)(GLscalar, GLscalar, GLscalar, GLscalar)(glVertex4d); -void (*glVertex2v)(const GLscalar*)(glVertex2dv); -void (*glVertex3v)(const GLscalar*)(glVertex3dv); -void (*glVertex4v)(const GLscalar*)(glVertex4dv); - -void (*glTexCoord2)(GLscalar, GLscalar)(glTexCoord2d); -void (*glTexCoord3)(GLscalar, GLscalar, GLscalar)(glTexCoord3d); -void (*glTexCoord4)(GLscalar, GLscalar, GLscalar, GLscalar)(glTexCoord4d); -void (*glTexCoord2v)(const GLscalar*)(glTexCoord2dv); -void (*glTexCoord3v)(const GLscalar*)(glTexCoord3dv); -void (*glTexCoord4v)(const GLscalar*)(glTexCoord4dv); - -#else - -void (*glGetScalarv(GLenum, GLscalar*)(glGetFloatv); - -void (*glLoadMatrix)(const GLscalar*)(glLoadMatrixf); -void (*glMultMatrix)(const GLscalar*)(glMultMatrixf); - -void (*glScale)(GLscalar, GLscalar, GLscalar)(glScalef); -void (*glRotate)(GLscalar, GLscalar, GLscalar, GLscalar)(glRotatef); -void (*glTranslate)(GLscalar, GLscalar, GLscalar)(glTranslatef); - -void (*glColor3)(GLscalar, GLscalar, GLscalar)(glColor3f); -void (*glColor4)(GLscalar, GLscalar, GLscalar, GLscalar)(glColor4f); -void (*glColor3v)(const GLscalar*)(glColor3fv); -void (*glColor4v)(const GLscalar*)(glColor4fv); - -void (*glVertex2)(GLscalar, GLscalar)(glVertex2f); -void (*glVertex3)(GLscalar, GLscalar, GLscalar)(glVertex3f); -void (*glVertex4)(GLscalar, GLscalar, GLscalar, GLscalar)(glVertex4f); -void (*glVertex2v)(const GLscalar*)(glVertex2fv); -void (*glVertex3v)(const GLscalar*)(glVertex3fv); -void (*glVertex4v)(const GLscalar*)(glVertex4fv); - -void (*glTexCoord2)(GLscalar, GLscalar)(glTexCoord2f); -void (*glTexCoord3)(GLscalar, GLscalar, GLscalar)(glTexCoord3f); -void (*glTexCoord4)(GLscalar, GLscalar, GLscalar, GLscalar)(glTexCoord4f); -void (*glTexCoord2v)(const GLscalar*)(glTexCoord2df); -void (*glTexCoord3v)(const GLscalar*)(glTexCoord3df); -void (*glTexCoord4v)(const GLscalar*)(glTexCoord4df); - -#endif - - -/** vim: set ts=4 sw=4 tw=80: *************************************************/ - diff --git a/src/Moof/OpenGL.hh b/src/Moof/OpenGL.hh index 51c3e5f..0ac6612 100644 --- a/src/Moof/OpenGL.hh +++ b/src/Moof/OpenGL.hh @@ -41,42 +41,68 @@ typedef GLdouble GLscalar; #define GL_SCALAR GL_DOUBLE +inline void glGetScalarv(GLenum a, GLscalar* b) { glGetDoublev(a, b); } + +inline void glLoadMatrix(const GLscalar* a) { glLoadMatrixd(a); } +inline void glMultMatrix(const GLscalar* a) { glMultMatrixd(a); } + +inline void glScale(GLscalar a, GLscalar b, GLscalar c) { glScaled(a, b, c); } +inline void glRotate(GLscalar a, GLscalar b, GLscalar c, GLscalar d) { glRotated(a, b, c, d); } +inline void glTranslate(GLscalar a, GLscalar b, GLscalar c) { glTranslated(a, b, c); } + +inline void glColor3(GLscalar a, GLscalar b, GLscalar c) { glColor3d(a, b, c); } +inline void glColor4(GLscalar a, GLscalar b, GLscalar c, GLscalar d) { glColor4d(a, b, c, d); } +inline void glColor3v(const GLscalar *a) { glColor3dv(a); } +inline void glColor4v(const GLscalar *a) { glColor4dv(a); } + +inline void glVertex2(GLscalar a, GLscalar b) { glVertex2d(a, b); } +inline void glVertex3(GLscalar a, GLscalar b, GLscalar c) { glVertex3d(a, b, c); } +inline void glVertex4(GLscalar a, GLscalar b, GLscalar c, GLscalar d) { glVertex4d(a, b, c, d); } +inline void glVertex2v(const GLscalar* a) { glVertex2dv(a); } +inline void glVertex3v(const GLscalar* a) { glVertex3dv(a); } +inline void glVertex4v(const GLscalar* a) { glVertex4dv(a); } + +inline void glTexCoord2(GLscalar a, GLscalar b) { glTexCoord2d(a, b); } +inline void glTexCoord3(GLscalar a, GLscalar b, GLscalar c) { glTexCoord3d(a, b, c); } +inline void glTexCoord4(GLscalar a, GLscalar b, GLscalar c, GLscalar d) { glTexCoord4d(a, b, c, d); } +inline void glTexCoord2v(const GLscalar* a) { glTexCoord2dv(a); } +inline void glTexCoord3v(const GLscalar* a) { glTexCoord3dv(a); } +inline void glTexCoord4v(const GLscalar* a) { glTexCoord4dv(a); } + #else typedef GLfloat GLscalar; #define GL_SCALAR GL_FLOAT -#endif - +inline void glGetScalarv(GLenum a, GLscalar* b) { glGetFloatv(a, b); } -extern void (*glGetScalarv)(GLenum, GLscalar*); +inline void glLoadMatrix(const GLscalar* a) { glLoadMatrixf(a); } +inline void glMultMatrix(const GLscalar* a) { glMultMatrixf(a); } -extern void (*glLoadMatrix)(const GLscalar*); -extern void (*glMultMatrix)(const GLscalar*); +inline void glScale(GLscalar a, GLscalar b, GLscalar c) { glScalef(a, b, c); } +inline void glRotate(GLscalar a, GLscalar b, GLscalar c, GLscalar d) { glRotatef(a, b, c, d); } +inline void glTranslate(GLscalar a, GLscalar b, GLscalar c) { glTranslatef(a, b, c); } -extern void (*glScale)(GLscalar, GLscalar, GLscalar); -extern void (*glRotate)(GLscalar, GLscalar, GLscalar, GLscalar); -extern void (*glTranslate)(GLscalar, GLscalar, GLscalar); +inline void glColor3(GLscalar a, GLscalar b, GLscalar c) { glColor3f(a, b, c); } +inline void glColor4(GLscalar a, GLscalar b, GLscalar c, GLscalar d) { glColor4f(a, b, c, d); } +inline void glColor3v(const GLscalar *a) { glColor3fv(a); } +inline void glColor4v(const GLscalar *a) { glColor4fv(a); } -extern void (*glColor3)(GLscalar, GLscalar, GLscalar); -extern void (*glColor4)(GLscalar, GLscalar, GLscalar, GLscalar); -extern void (*glColor3v)(const GLscalar*); -extern void (*glColor4v)(const GLscalar*); +inline void glVertex2(GLscalar a, GLscalar b) { glVertex2f(a, b); } +inline void glVertex3(GLscalar a, GLscalar b, GLscalar c) { glVertex3f(a, b, c); } +inline void glVertex4(GLscalar a, GLscalar b, GLscalar c, GLscalar d) { glVertex4f(a, b, c, d); } +inline void glVertex2v(const GLscalar* a) { glVertex2fv(a); } +inline void glVertex3v(const GLscalar* a) { glVertex3fv(a); } +inline void glVertex4v(const GLscalar* a) { glVertex4fv(a); } -extern void (*glVertex2)(GLscalar, GLscalar); -extern void (*glVertex3)(GLscalar, GLscalar, GLscalar); -extern void (*glVertex4)(GLscalar, GLscalar, GLscalar, GLscalar); -extern void (*glVertex2v)(const GLscalar*); -extern void (*glVertex3v)(const GLscalar*); -extern void (*glVertex4v)(const GLscalar*); - -extern void (*glTexCoord2)(GLscalar, GLscalar); -extern void (*glTexCoord3)(GLscalar, GLscalar, GLscalar); -extern void (*glTexCoord4)(GLscalar, GLscalar, GLscalar, GLscalar); -extern void (*glTexCoord2v)(const GLscalar*); -extern void (*glTexCoord3v)(const GLscalar*); -extern void (*glTexCoord4v)(const GLscalar*); +inline void glTexCoord2(GLscalar a, GLscalar b) { glTexCoord2f(a, b); } +inline void glTexCoord3(GLscalar a, GLscalar b, GLscalar c) { glTexCoord3f(a, b, c); } +inline void glTexCoord4(GLscalar a, GLscalar b, GLscalar c, GLscalar d) { glTexCoord4f(a, b, c, d); } +inline void glTexCoord2v(const GLscalar* a) { glTexCoord2fv(a); } +inline void glTexCoord3v(const GLscalar* a) { glTexCoord3fv(a); } +inline void glTexCoord4v(const GLscalar* a) { glTexCoord4fv(a); } +#endif #endif // _MOOF_OPENGL_HH_ diff --git a/src/Moof/Resource.cc b/src/Moof/Resource.cc index d958c3a..a9ff22d 100644 --- a/src/Moof/Resource.cc +++ b/src/Moof/Resource.cc @@ -28,6 +28,9 @@ #include +#include + +#include "Log.hh" #include "Resource.hh" @@ -43,29 +46,43 @@ Resource::~Resource() {} void Resource::addSearchPath(const std::string& directory) { + std::string path(directory); + + ASSERT(path.length() > 0 && "empty search path string"); + // add a slash if there isn't one already - if (directory[directory.length() - 1] != '/') - { - searchPaths_.push_back(directory + '/'); - } - else + if (*path.rbegin() != '/') { - searchPaths_.push_back(directory); + path += '/'; } + +#if defined(__WIN32__) || defined(_WIN32) || defined(_WIN64) + boost::replace_all(path, "/", "\\"); +#endif + + searchPaths_.push_back(path); } std::string Resource::getPath(const std::string& name) { std::vector::iterator it; + std::string path(name); + +#if defined(__WIN32__) || defined(_WIN32) || defined(_WIN64) + boost::replace_all(path, "/", "\\"); +#endif + for (it = searchPaths_.begin(); it != searchPaths_.end(); ++it) { std::string fullPath(*it); - fullPath += name; + fullPath += path; + + logDebug("looking for resource %s at %s", name.c_str(), path.c_str()); - // TODO this could be more portable if (access(fullPath.c_str(), R_OK) == 0) { + logDebug("found resource %s at %s", name.c_str(), path.c_str()); return fullPath; } } diff --git a/src/Moof/Settings.cc b/src/Moof/Settings.cc index 624179c..6883ddc 100644 --- a/src/Moof/Settings.cc +++ b/src/Moof/Settings.cc @@ -32,6 +32,7 @@ #include +#include "Log.hh" #include "Settings.hh" @@ -104,7 +105,7 @@ void Settings::loadFromFiles(const std::vector& filePaths, if (home) { - boost::replace_first(path, "$HOME", home); + boost::replace_all(path, "$HOME", home); } try @@ -129,8 +130,8 @@ void Settings::loadFromFiles(const std::vector& filePaths, } catch (Deserializer::Exception e) { - std::cerr << "Cannot load settings from " << *it << - " because an exception was thrown: " << e.what() << std::endl; + logWarning("cannot load settings from %s because an exception was" + "thrown: %s", (*it).c_str(), e.what()); } } } diff --git a/src/Moof/Sound.cc b/src/Moof/Sound.cc index 368e938..a0302fb 100644 --- a/src/Moof/Sound.cc +++ b/src/Moof/Sound.cc @@ -63,6 +63,7 @@ struct Sound::Impl Buffer(const std::string& name) : Mippleton(name) { + sound = 0; objects[0] = 0; objects[1] = 0; } @@ -84,7 +85,7 @@ struct Sound::Impl if (!sound) { - logWarning("audio not found: %s", getName().c_str()); + logWarning("error while loading sound %s: %s", getName().c_str(), Sound_GetError()); throw Exception(Exception::FILE_NOT_FOUND); } @@ -93,8 +94,9 @@ struct Sound::Impl unsigned decoded = Sound_DecodeAll(sound); if (decoded == 0) { - logWarning("decoded not bytes from %s", getName().c_str()); - throw Exception(Exception::FILE_NOT_FOUND); + logWarning("decoded no bytes from %s", getName().c_str()); + //throw Exception(Exception::FILE_NOT_FOUND); + return; } alGenBuffers(2, objects); @@ -207,6 +209,8 @@ Sound::Sound(const std::string& name) : void Sound::play() { + if (!impl_->buffer_->sound) return; + //alSourceRewind(impl_->source_); alSourcePlay(impl_->source_); impl_->playing = true; diff --git a/src/Moof/Timer.cc b/src/Moof/Timer.cc index 4eea488..fb17f1d 100644 --- a/src/Moof/Timer.cc +++ b/src/Moof/Timer.cc @@ -76,6 +76,22 @@ Scalar getTicks() return Scalar(ts.tv_sec - reference) + Scalar(ts.tv_nsec) / 1000000000.0; } +void sleep(Scalar seconds, bool absolute) +{ + struct timespec ts; + int ret; + + if (absolute) seconds -= getTicks(); + ts.tv_sec = time_t(seconds); + ts.tv_nsec = long((seconds - Scalar(ts.tv_sec)) * 1000000000.0); + + do + { + ret = nanosleep(&ts, &ts); + } + while (ret == -1 && errno == EINTR); +} + #else // ! HAVE_CLOCK_GETTIME @@ -92,26 +108,15 @@ Scalar getTicks() return Scalar(ms / 1000) + Scalar(ms % 1000) / 1000.0; } - -#endif // HAVE_CLOCK_GETTIME - - void sleep(Scalar seconds, bool absolute) { - struct timespec ts; - int ret; - if (absolute) seconds -= getTicks(); - ts.tv_sec = time_t(seconds); - ts.tv_nsec = long((seconds - Scalar(ts.tv_sec)) * 1000000000.0); - do - { - ret = nanosleep(&ts, &ts); - } - while (ret == -1 && errno == EINTR); + SDL_Delay(Uint32(seconds * 1000.0)); } +#endif // HAVE_CLOCK_GETTIME + } // namespace Mf diff --git a/src/YoinkApp.cc b/src/YoinkApp.cc index d391927..9ea4b37 100644 --- a/src/YoinkApp.cc +++ b/src/YoinkApp.cc @@ -465,7 +465,7 @@ int main(int argc, char* argv[]) PACKAGE_BUGREPORT << ">." << std::endl << std::endl; #if ! NDEBUG - Mf::setLogLevel(Mf::DEBUGGING); + Mf::setLogLevel(Mf::LOG_DEBUG); #endif int status = 0;