[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"
[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.])
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,
Moof/Mippleton.hh \
Moof/Octree.cc \
Moof/Octree.hh \
- Moof/OpenGL.cc \
Moof/OpenGL.hh \
Moof/Physics.hh \
Moof/Plane.cc \
*******************************************************************************/
-#include <iostream>
-#include <Moof/Camera.hh>
-#include <Moof/OpenGL.hh>
+#include "Camera.hh"
+#include "OpenGL.hh"
namespace Mf {
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();
}
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();
}
Camera() :
position_(0.0, 0.0, 0.0)
{
- quaternion_rotation_world_y(rotation_, 0.0);
+ cml::quaternion_rotation_world_y(rotation_, 0.0);
calculateSecondary();
}
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);
}
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);
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;
namespace Mf {
-static LogLevel logLevel_ = WARNING;
+static LogLevel logLevel_ = LOG_WARNING;
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;
}
va_list args;
va_start(args, fmt);
- printLog_(ERROR, fmt, args);
+ printLog_(LOG_ERROR, fmt, args);
va_end(args);
}
va_list args;
va_start(args, fmt);
- printLog_(WARNING, fmt, args);
+ printLog_(LOG_WARNING, fmt, args);
va_end(args);
}
va_list args;
va_start(args, fmt);
- printLog_(INFO, fmt, args);
+ printLog_(LOG_INFO, fmt, args);
va_end(args);
}
va_list args;
va_start(args, fmt);
- printLog_(DEBUGGING, fmt, args);
+ printLog_(LOG_DEBUG, fmt, args);
va_end(args);
}
* @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.
+};
/**
+++ /dev/null
-
-/*******************************************************************************
-
- 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: *************************************************/
-
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_
#include <unistd.h>
+#include <boost/algorithm/string.hpp>
+
+#include "Log.hh"
#include "Resource.hh"
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<std::string>::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;
}
}
#include <boost/algorithm/string.hpp>
+#include "Log.hh"
#include "Settings.hh"
if (home)
{
- boost::replace_first(path, "$HOME", home);
+ boost::replace_all(path, "$HOME", home);
}
try
}
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());
}
}
}
Buffer(const std::string& name) :
Mippleton<Buffer>(name)
{
+ sound = 0;
objects[0] = 0;
objects[1] = 0;
}
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);
}
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);
void Sound::play()
{
+ if (!impl_->buffer_->sound) return;
+
//alSourceRewind(impl_->source_);
alSourcePlay(impl_->source_);
impl_->playing = true;
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
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
PACKAGE_BUGREPORT << ">." << std::endl << std::endl;
#if ! NDEBUG
- Mf::setLogLevel(Mf::DEBUGGING);
+ Mf::setLogLevel(Mf::LOG_DEBUG);
#endif
int status = 0;