# Use this file with GNU make to compile and install Yoink.
#
-# Set V to `1' to echo each build command in full. The default behavior
-# will keep output minimal.
+# Set V to `1' to echo each build command in full. The default behavior will
+# keep output minimal so that warnings are clearly visible.
V = 0
SHELL = /bin/sh
ifeq (menuconfig,$(MAKECMDGOALS))
+# If all we want is to bring up the configure script, then we really don't
+# need to define any other functions or recipes process anything else.
menuconfig:
./configure --interactive
.PHONY: menuconfig
else
+# Recipe to create `config.h' which is included by some source files.
config.h: config.mk
$(Q)$(configure) --export-header=$@
+# Recipe to create `config.sed' which is used by some recipes to search and
+# replace certain terms in some files, usually with a `.in' suffix.
config.sed: config.mk
$(Q)$(configure) --export-terms=$@
+# Recipe to create `config.mk' which is the makefile with important configure
+# options set.
config.mk:
$(Q)$(configure) --interactive --print-instructions=no
+
+# Include the configure makefile; fail if it doesn't exist.
include config.mk
-#
-# Define some useful functions.
-#
+# This simple variable will be appended with targets which must be built
+# before the `install-data' target.
+data_targets :=
-DATA_TARGETS :=
-EXEC_TARGETS :=
-SUBDIRS :=
+# This simple variable will be appended with targets which must be built
+# before the `install-exec' target.
+exec_targets :=
+# This simple variable will be appended with subdirectories which contain
+# rules as well as their corresponding subdirectories under the build
+# directory, any directory which might have files to be installed.
+subdirs :=
+
+# Function to include rules from subdirectories. This is the core of the
+# non-recursive make method this build system uses. It works by managing
+# several stacks and helping to append the appropriate values to the simple
+# variables defined above.
define include_func =
ifeq (,$$d)
dir := $1
data :=
exec :=
include $$(dir)/rules.mk
-SUBDIRS += $$d $$b
-data := $$(sort $$(data) $$(appdir_$$b) $$(mandir_$$b) $$(pkgdatadir_$$b) $$(desktop_$$b))
+subdirs += $$d $$b
+data := $$(sort $$(data) $$(mandir_$$b) $$(datadir_$$b) $$(pkgdatadir_$$b) $$(desktop_$$b))
exec := $$(sort $$(exec) $$(bindir_$$b) $$(libdir_$$b))
-deps := $$(filter %.d,$$(exec:%.o=%.d))
+deps := $$(filter %.d,$$(call depfile,$$(exec)))
clean := $$(clean) $$(deps) $$(exec) $$(data)
DEPFILE := $$(DEPFILE) $$(deps)
-DATA_TARGETS += $$(data)
-EXEC_TARGETS += $$(exec)
+data_targets += $$(data)
+exec_targets += $$(exec)
d := $$(dirstack_$$(sp))
data := $$(datstack_$$(sp))
exec := $$(exestack_$$(sp))
endef
include = $(foreach i,$1,$(eval $(call include_func,$i)))
-targets = $(EXEC_TARGETS) $(DATA_TARGETS)
+# These shortcut variables are meant to be used to simplify included rules.
builddir = build/obj
b = $(builddir)/$(d)
this = $(d)/rules.mk
+# Function to convert object file paths to dependency file paths. This also
+# supports pre-compiled header files.
+depfile = $(patsubst %.h.gch,%.d,$(patsubst %.hh.gch,%.d,$(1:%.o=%.d)))
+
+# Determine the suffix that installed manual pages should have.
ifeq (gzip,$(manCompression))
MANEXT=.gz
else
endif
endif
-
-#
-# Include the subdirectories--order is not important.
-#
-
+# Now do the actual inclusion of the rules from these subdirectories.
$(call include,src data doc)
--include build/arch/$(platform)/rules.mk
-
-#
-# Define some common rules.
-#
+# Also include platform-specific rules, if they exist.
+-include build/arch/$(platform)/rules.mk
+# Handle automatic tracking of dependencies, if enabled. This adds overhead
+# and should be disabled if not needed.
ifeq (true,$(tracking))
-PKG_CFLAGS += -MD -MP -MF $(@:%.o=%.d) -MT $@
+PKG_CFLAGS += -MT $@ -MMD -MP -MF $(call depfile,$@)
-include $(DEPFILE)
endif
+# Handle the inclusion of a PCH file, if enabled. Using a PCH file can
+# improve build times in some (but not all) cases. The rules should also
+# define the `pchfile' variable to the path of the PCH file. Only one PCH
+# file can be used. If the PCH file has a `.h' suffix, it is included only
+# when compiling C sources, otherwise it will be included only when compiling
+# C++ sources.
+ifeq (true,$(pch))
+ifneq (,$(pchfile))
+PCH_FLAGS = -Winvalid-pch -include $(pchfile)
+endif
+endif
+
# Include current directory to allow sources to include config.h.
override CPPFLAGS += -I. -DHAVE_CONFIG_H=1
+
+# The target C++ flags should mirror the target C flags by default.
TGT_CXXFLAGS = $(TGT_CFLAGS)
+
+# Define the default flags passed to the library archiver.
ARFLAGS = rc
+
+# Define the default install program.
INSTALL = install
+# Define the `tarname' to be used as a base filename for distributable
+# archives.
tarname = $(TARNAME)-$(VERSION)
-cmd_compile_c = $(CC) $(PKG_CFLAGS) $(TGT_CFLAGS) $(CFLAGS) $(CPPFLAGS) \
+# Define the commands needed to make several different types of files. Don't
+# used these commands directly because they don't account for verbosity;
+# instead use the commands without the `cmd_' prefix (defined below).
+cmd_compile_c = $(CC) $(PKG_CFLAGS) $(TGT_CFLAGS) $(PCH_CFLAGS) $(CFLAGS) $(MYCFLAGS) $(CPPFLAGS) \
$(TARGET_ARCH) -c $(OUTPUT_OPTION) $<
-cmd_compile_cc = $(CXX) $(PKG_CXXFLAGS) $(TGT_CXXFLAGS) $(CXXFLAGS) $(CPPFLAGS) \
+cmd_compile_cc = $(CXX) $(PKG_CXXFLAGS) $(TGT_CXXFLAGS) $(PCH_CXXFLAGS) $(CXXFLAGS) $(MYCXXFLAGS) $(CPPFLAGS) \
$(TARGET_ARCH) -c $(OUTPUT_OPTION) $<
-cmd_link_c = $(CC) $(PKG_CFLAGS) $(TGT_CFLAGS) $(CFLAGS) $(CPPFLAGS) \
- $(PKG_LDFLAGS) $(TGT_LDFLAGS) $(LDFLAGS) \
+cmd_link_c = $(CC) $(PKG_CFLAGS) $(TGT_CFLAGS) $(PCH_CFLAGS) $(CFLAGS) $(MYCFLAGS) $(CPPFLAGS) \
+ $(PKG_LDFLAGS) $(TGT_LDFLAGS) $(LDFLAGS) $(MYLDFLAGS) \
$(TARGET_ARCH) $^ $(LOADLIBES) $(PKG_LDLIBS) $(TGT_LDLIBS) $(LDLIBS) -o $@
-cmd_link_cc = $(CXX) $(PKG_CXXFLAGS) $(TGT_CXXFLAGS) $(CXXFLAGS) $(CPPFLAGS) \
- $(PKG_LDFLAGS) $(TGT_LDFLAGS) $(LDFLAGS) \
+cmd_link_cc = $(CXX) $(PKG_CXXFLAGS) $(TGT_CXXFLAGS) $(PCH_CXXFLAGS) $(CXXFLAGS) $(MYCXXFLAGS) $(CPPFLAGS) \
+ $(PKG_LDFLAGS) $(TGT_LDFLAGS) $(LDFLAGS) $(MYLDFLAGS) \
$(TARGET_ARCH) $^ $(LOADLIBES) $(PKG_LDLIBS) $(TGT_LDLIBS) $(LDLIBS) -o $@
+cmd_compile_pch = $(CC) $(PKG_CFLAGS) $(TGT_CFLAGS) $(CFLAGS) $(MYCFLAGS) $(CPPFLAGS) \
+ $(TARGET_ARCH) -c $(OUTPUT_OPTION) $<
+cmd_compile_pchh = $(CXX) $(PKG_CXXFLAGS) $(TGT_CXXFLAGS) $(CXXFLAGS) $(MYCXXFLAGS) $(CPPFLAGS) \
+ $(TARGET_ARCH) -c $(OUTPUT_OPTION) $<
cmd_ar = $(AR) $(ARFLAGS) $@ $^; $(RANLIB) $@
cmd_compile_rc = $(WINDRES) $(CPPFLAGS) $(TARGET_ARCH) $(OUTPUT_OPTION) -i $<
cmd_sed = sed -f config.sed <$< >$@
xxd -i <$< >>$@; \
printf ", 0x00\n};\n" >>$@
cmd_configure = ./configure
-func_install = mkdir -p $(DESTDIR)$3 && $(INSTALL) -m $1 $2 $(DESTDIR)$3
+
+# Define some useful functions. Don't use these functions directly because
+# they don't account for verbosity; instead use the functions without the
+# `func_' prefix (defined below).
func_remove = rm -f $1
+func_install = mkdir -p $(DESTDIR)$3 && $(INSTALL) -m $1 $2 $(DESTDIR)$3
func_dist = git archive HEAD --prefix='$(tarname)/' | $1 >"$(tarname).tar.$2" && \
- (md5 "$(tarname).tar.$2" 2>/dev/null || md5sum "$(tarname).tar.$2")
-
-compile_c = $(call func_print,CC,$@) $(cmd_compile_c)
-compile_cc = $(call func_print,CXX,$@) $(cmd_compile_cc)
-compile_rc = $(call func_print,RC,$@) $(cmd_compile_rc)
-link_c = $(call func_print,LINK,$@) $(cmd_link_c)
-link_cc = $(call func_print,LINK,$@) $(cmd_link_cc)
-ar = $(call func_print,AR,$@) $(cmd_ar)
-sed = $(call func_print,SED,$@) $(cmd_sed)
-gzip = $(call func_print,GZIP,$@) $(cmd_gzip)
-bzip2 = $(call func_print,BZIP2,$@) $(cmd_bzip2)
-xxd = $(call func_print,XXD,$@) $(cmd_xxd)
-configure = $(call func_print,MAKE,$@) $(cmd_configure)
-dist = $(call func_print,DIST,$1) $(func_dist)
+ (openssl md5 "$(tarname).tar.$2" 2>/dev/null || \
+ md5 "$(tarname).tar.$2" 2>/dev/null || \
+ md5sum "$(tarname).tar.$2" 2>/dev/null)
+
+# These commands and functions should be used in most recipes to compile
+# sources, link objects, compress files, create distfiles, install files, etc.
+compile_c = $(call func_print,CC,$@) $(cmd_compile_c)
+compile_cc = $(call func_print,CXX,$@) $(cmd_compile_cc)
+compile_rc = $(call func_print,RC,$@) $(cmd_compile_rc)
+link_c = $(call func_print,LINK,$@) $(cmd_link_c)
+link_cc = $(call func_print,LINK,$@) $(cmd_link_cc)
+compile_pch = $(call func_print,CC,$@) $(cmd_compile_pch)
+compile_pchh = $(call func_print,CXX,$@) $(cmd_compile_pchh)
+ar = $(call func_print,AR,$@) $(cmd_ar)
+sed = $(call func_print,SED,$@) $(cmd_sed)
+gzip = $(call func_print,GZIP,$@) $(cmd_gzip)
+bzip2 = $(call func_print,BZIP2,$@) $(cmd_bzip2)
+xxd = $(call func_print,XXD,$@) $(cmd_xxd)
+configure = $(call func_print,MAKE,$@) $(cmd_configure)
+dist = $(call func_print,DIST,$1) $(func_dist)
+remove = $(call func_print,RM,$1) $(func_remove)
install = $(call func_print,CP,$(DESTDIR:%/=%)$(3:%/=%)/$(notdir $2)) $(func_install)
-remove = $(call func_print,RM,$1) $(func_remove)
+# The mechanism used by this makefile to handle verbosity simply requires (by
+# convention) commands in rules to be prefixed with `$Q' and the commands and
+# functions defined above will then print a single line describing the command
+# instead of the entire command.
ifeq (1,$V)
Q =
func_print =
endif
-#
-# Define the implicit rules.
-#
-
+# Define the implicit rules. Targets and sources which match do not need to
+# be explicitly stated in the rule definitions.
+%.o: %.c
+ $(Q)$(compile_c)
+%.h.gch: %.h
+ $(Q)$(compile_pch)
%.o: %.cc
$(Q)$(compile_cc)
%.o: %.cpp
$(Q)$(compile_cc)
-%.o: %.c
- $(Q)$(compile_c)
+%.hh.gch: %.hh
+ $(Q)$(compile_pchh)
%.o: %.rc
$(Q)$(compile_rc)
%: %.in
%.bz2: %
$(Q)$(bzip2)
+# More explicit rules which allow targets in the build directory to be made
+# directly. A special rules is also defined to create directories or copy
+# files under the build directory to match the structure of the source
+# directory.
$(builddir)/%.o: %.cc
$(Q)$(compile_cc)
$(builddir)/%.o: %.cpp
$(Q)if [ -d $< ]; then mkdir -p $@; elif [ -f $< ]; then cp -f $< $@; fi
-#
-# Define the phony targets.
-#
-
+# Define the default target(s). This should `make' just about everything.
.DEFAULT_GOAL :=
-all: $(targets)
+all: $(exec_targets) $(data_targets)
+# Define the recipe to clean the targets. This will remove the target files
+# and the empty directories of the build hierarchy.
clean:
$(Q)$(foreach f,$(clean),$(call remove,$f);)
$(Q)if [ -d $(builddir) ]; then find $(builddir) -type d -empty -delete; fi
+# Make the project even cleaner by removing files created by configuration.
distclean: clean
$(Q)cd build && $(MAKE) clean
$(Q)$(call remove,config.h);$(call remove,config.mk);$(call remove,config.sed)
-
+# Installation happens in two separated phases, installing the executable
+# (i.e. platform-specific) files and installing the data files.
install: install-data install-exec
-install-data: $(DATA_TARGETS)
- $(Q)$(foreach d,$(SUBDIRS),$(foreach f,$(pkgdatadir_$d),\
+# Recipe to install the data files. Right now, that includes files destined
+# for `pkgdatadir' and `mandir'.
+install-data: $(data_targets)
+ $(Q)$(foreach d,$(subdirs),$(foreach f,$(pkgdatadir_$d),\
$(call install,644,$f,$(dir $(f:$d%=$(pkgdatadir)%)));))
- $(Q)$(foreach d,$(SUBDIRS),$(foreach f,$(mandir_$d),\
+ $(Q)$(foreach d,$(subdirs),$(foreach f,$(mandir_$d),\
$(call install,644,$f,\
$(dir $(f:$d%=$(mandir)/man$(shell echo "$f" | sed 's/[^.]*\.\([^.]*\).*/\1/')%)));))
-install-exec: $(EXEC_TARGETS)
- $(Q)$(foreach d,$(SUBDIRS),$(foreach f,$(bindir_$d),\
+# Recipe to install executable files. Right now, that includes files destined
+# for `bindir'.
+install-exec: $(exec_targets)
+ $(Q)$(foreach d,$(subdirs),$(foreach f,$(bindir_$d),\
$(call install,755,$f,$(dir $(f:$d%=$(bindir)%)));))
-install-desktop-entry: $(DATA_TARGETS)
- $(Q)$(foreach d,$(SUBDIRS),$(foreach f,$(desktop_$d),\
+# Recipe to install desktop entry file(s) to /usr/share/applications.
+install-desktop-entry: $(data_targets)
+ $(Q)$(foreach d,$(subdirs),$(foreach f,$(desktop_$d),\
$(call install,644,$f,/usr/share/applications);))
-
+# Target used to create distfiles in all the supported compression formats.
dist-all: dist-bzip2 dist-gzip dist-lzma dist-xz
+# Separate targets to create distfiles in the corresponding formats.
dist-bzip2:
$(Q)$(call dist,bzip2,bz2)
-
dist-gzip:
$(Q)$(call dist,gzip,gz)
-
dist-lzma:
$(Q)$(call dist,lzma,lzma)
-
dist-xz:
$(Q)$(call dist,xz,xz)
+# The `dist' target will create the distfile in whatever format was set in the
+# configuration.
dist: dist-$(archiveFormat)
-#
-# Prevent make from removing any build targets.
-#
-
-.SECONDARY: $(clean)
-
-.PHONY: all clean distclean install install-data install-exec
-.PHONY: install-desktop-entry
+# Define which targets do not actually correspond to real files.
+.PHONY: all clean distclean
+.PHONY: install install-data install-exec install-desktop-entry
.PHONY: dist dist-all dist-gzip dist-bzip2 dist-xz dist-lzma
endif # menuconfig
src_configure() {
egamesconf --disable-dependency-tracking \
- --install-icon=no \
- --print-instructions=no \
+ --install-icon=no --print-instructions=no \
$(use_enable debug) \
$(use_enable double-precision) \
$(use_enable hotload) \
+ $(use_enable pch) \
$(use_enable threads) \
$(use_with gtk) \
$(use_with qt4)
to the build process.
If in doubt, say Yes.
+]]
+ },
+ {
+ symbol = "pch",
+ value = false,
+ cmdline = "--enable-pch",
+ name = "Use Precompiled Header",
+ caption = "Enable building and using a precompiled header.",
+ help = [[
+Recent versions of GCC can use precompiled headers
+which may improve compile times.
+
+If in doubt, say No.
]]
},
{
#ifndef _ANIMATION_HH_
#define _ANIMATION_HH_
-/**
- * @file Animation.hh
- * Motion picture!!
- */
-
#include <string>
#include <boost/shared_ptr.hpp>
#include <moof/math.hh>
+/**
+ * \file Animation.hh
+ * Motion picture!!
+ */
+
class Animation;
typedef boost::shared_ptr<Animation> AnimationP;
#ifndef _GAMESTATE_HH_
#define _GAMESTATE_HH_
-/**
- * \file GameState.hh
- * The data.
- */
-
#include <string>
#include <vector>
#include "Scene.hh"
+/**
+ * \file GameState.hh
+ * The data.
+ */
+
struct GameState
{
moof::script script;
*****************************************************************************/
#include <moof/aabb.hh>
-#include <moof/log.hh>
+#include <moof/debug.hh>
#include <moof/opengl.hh>
#include <moof/video.hh>
#ifndef _HUD_HH_
#define _HUD_HH_
-/**
- * @file Hud.hh
- * Heads-up Display
- */
-
#include <moof/drawable.hh>
#include <moof/math.hh>
//#include <moof/rectangle.hh>
#include "GameState.hh"
+/**
+ * \file Hud.hh
+ * Heads-up Display
+ */
+
+
// forward declarations
class rectangle;
#ifndef _TILEMAPFONT_HH_
#define _TILEMAPFONT_HH_
+#include <moof/sprite.hh>
+
+
/**
- * @file TilemapFont.hh
+ * \file TilemapFont.hh
* Text on the screen.
*/
-#include <moof/sprite.hh>
-
/*
class TilemapFont : public moof::texture
#include "aabb.hh"
#include "script.hh"
+
namespace moof {
+
void import_aabb_class(script& script)
{
}
+
} // namepsace moof
#ifndef _MOOF_AABB_HH_
#define _MOOF_AABB_HH_
-/**
- * \file aabb.hh
- * Axis-aligned Bounding Box
- */
-
#include <moof/cullable.hh>
#include <moof/drawable.hh>
#include <moof/math.hh>
#include <moof/opengl.hh>
+/**
+ * \file aabb.hh
+ * Axis-aligned Bounding Box
+ */
+
namespace moof {
}
typedef aabb<2> aabb2;
-typedef aabb2 rectangle;
+typedef aabb<2> rectangle;
typedef aabb<3> aabb3;
*
*****************************************************************************/
-#include <cstdlib> // exit, srand
-#include <boost/noncopyable.hpp>
+#include <cstdlib> // exit, srand
#include <SDL/SDL.h>
-#include "fastevents.h"
#include "application.hh"
+#include "fastevents.h"
#include "log.hh"
#include "settings.hh"
-#include "timer.hh"
#include "video.hh"
#ifndef _MOOF_APPLICATION_HH_
#define _MOOF_APPLICATION_HH_
-/**
- * \file application.hh
- * The main loop.
- */
-
-#include <boost/noncopyable.hpp>
-
#include <moof/event.hh>
#include <moof/math.hh>
#include <moof/runloop.hh>
+#include <moof/thread.hh>
#include <moof/timer.hh>
+/**
+ * \file application.hh
+ * The main loop.
+ */
+
namespace moof {
#include <stdexcept>
#include <SDL/SDL.h>
-#include "fastevents.h"
#include "backend.hh"
+#include "fastevents.h"
#include "log.hh"
* Initialize the backend libraries and subsystems.
*/
-
namespace moof {
#ifndef _MOOF_CAMERA_HH_
#define _MOOF_CAMERA_HH_
-/**
- * \file camera.hh
- * Classes related to managing the modelview and perspective matrices.
- */
-
#include <moof/event.hh>
#include <moof/frustum.hh>
#include <moof/math.hh>
#include <moof/rigid_body.hh>
+/**
+ * \file camera.hh
+ * Classes related to managing the modelview and perspective matrices.
+ */
+
namespace moof {
#ifndef _MOOF_CONTACT_HH_
#define _MOOF_CONTACT_HH_
+#include <moof/math.hh>
+
+
/**
* \file contact.hh
* Represents a collision between entities.
*/
-#include <moof/math.hh>
-
-
namespace moof {
* Representation for an object that may or may not be visible.
*/
-
namespace moof {
#ifndef _MOOF_DEBUG_HH_
#define _MOOF_DEBUG_HH_
+#include <exception>
+
+#include <moof/log.hh>
+
+
/**
* \file debug.hh
* Debugging facilities.
*/
-#include <cstdlib> // exit
-
-#include <stlplus/portability/debug.hpp>
-
-#include <moof/log.hh>
#undef ASSERT
#ifndef _MOOF_DISPATCH_HH_
#define _MOOF_DISPATCH_HH_
-/**
- * \file dispatcher.hh
- * Classes that deal with message dispatching.
- */
-
#include <string>
#include <boost/bind.hpp>
#include <boost/weak_ptr.hpp>
+/**
+ * \file dispatcher.hh
+ * Classes that deal with message dispatching.
+ */
+
namespace moof {
#ifndef _MOOF_DRAWABLE_HH_
#define _MOOF_DRAWABLE_HH_
+#include <moof/math.hh>
+
+
/**
* \file drawable.hh
* Representation for an object that can be drawn to the screen.
*/
-#include <moof/math.hh>
-
-
namespace moof {
#ifndef _MOOF_ENTITY_HH_
#define _MOOF_ENTITY_HH_
-/**
- * \file entity.hh
- * Interface class for cullable and drawable objects.
- */
-
#include <boost/shared_ptr.hpp>
#include <moof/aabb.hh>
#include <moof/sphere.hh>
+/**
+ * \file entity.hh
+ * Interface class for cullable and drawable objects.
+ */
+
namespace moof {
#ifndef _MOOF_EVENT_HH_
#define _MOOF_EVENT_HH_
+#include <SDL/SDL.h>
+
+
/**
* \file event.hh
* Defines an event object.
*/
-#include <SDL/SDL.h>
-
-
namespace moof {
#ifndef _MOOF_FRUSTUM_HH_
#define _MOOF_FRUSTUM_HH_
+#include <moof/math.hh>
+#include <moof/plane.hh>
+
+
/**
* \file frustum.hh
* All things related to frustums!
*/
-#include <moof/math.hh>
-#include <moof/plane.hh>
-
namespace moof {
+
template <int D> class aabb;
template <int D> class sphere;
plane planes_[6]; // left, right, bottom, top, near, far
};
+
} // namespace moof
#endif // _MOOF_FRUSTUM_HH_
#ifndef _MOOF_HASH_HH_
#define _MOOF_HASH_HH_
-/**
- * \file hash.hh
- * Hash tables and functions.
- */
-
#include <string>
#include <stlplus/containers/hash.hpp>
+/**
+ * \file hash.hh
+ * Hash tables and functions.
+ */
+
namespace moof {
*
*****************************************************************************/
-#include <cstring> // strncmp
#include <fstream>
#include <stdexcept>
-
#include <png.h>
+
#include <SDL/SDL.h>
+#include <stlplus/portability/file_system.hpp>
+
#include "backend.hh"
+#include "debug.hh"
#include "image.hh"
#include "log.hh"
#include "opengl.hh"
namespace moof {
+MOOF_REGISTER_RESOURCE(image, bmp, textures);
MOOF_REGISTER_RESOURCE(image, png, textures);
-//static int power_of_two(int input)
-//{
- //int value = 1;
-
- //while (value < input)
- //{
- //value <<= 1;
- //}
- //return value;
-//}
-
-unsigned image::global_object_ = 0;
+static int higher_power_of_two(int input)
+{
+ int value = 2;
+ while (value <= input) value <<= 1;
+ return value;
+}
-static void read_from_stream(png_structp context, png_bytep data, png_size_t length)
+static void read_from_stream(png_structp context,
+ png_bytep data, png_size_t length)
{
std::istream& stream(*(std::istream*)png_get_io_ptr(context));
stream.read((char*)data, length);
}
-image::image(const std::string& path) :
- pixels_(0),
- object_(0),
- min_filter_(GL_NEAREST),
- mag_filter_(GL_NEAREST),
- tile_s_(1),
- tile_t_(1),
- wrap_s_(GL_CLAMP),
- wrap_t_(GL_CLAMP)
+struct texture_attributes
+{
+ texture_attributes() :
+ min_filter(GL_NEAREST),
+ mag_filter(GL_NEAREST),
+ tile_s(1),
+ tile_t(1),
+ wrap_s(GL_CLAMP_TO_EDGE),
+ wrap_t(GL_CLAMP_TO_EDGE) {}
+
+ void init(const std::string& info)
+ {
+ script script;
+ log::import(script);
+
+ script::slot g = script.globals();
+#define EXPORT_CONSTANT(K) g.set_field(#K, GL_##K)
+ EXPORT_CONSTANT(CLAMP);
+ EXPORT_CONSTANT(CLAMP_TO_EDGE);
+ EXPORT_CONSTANT(REPEAT);
+ EXPORT_CONSTANT(LINEAR);
+ EXPORT_CONSTANT(NEAREST);
+ EXPORT_CONSTANT(LINEAR_MIPMAP_LINEAR);
+ EXPORT_CONSTANT(LINEAR_MIPMAP_NEAREST);
+ EXPORT_CONSTANT(NEAREST_MIPMAP_LINEAR);
+ EXPORT_CONSTANT(NEAREST_MIPMAP_NEAREST);
+#undef export_constant
+
+ if (script.do_string(info) != script::success)
+ {
+ std::string str;
+ script[-1].get(str);
+ log_warning(str);
+ }
+ else
+ {
+ log_info("loading texture information...");
+
+ script::slot globals = script.globals();
+ globals.get(min_filter, "min_filter");
+ globals.get(mag_filter, "mag_filter");
+ globals.get(tile_s, "tile_s");
+ globals.get(tile_t, "tile_t");
+ globals.get(wrap_s, "wrap_s");
+ globals.get(wrap_t, "wrap_t");
+ }
+ }
+
+ GLuint min_filter;
+ GLuint mag_filter;
+ int tile_s;
+ int tile_t;
+ GLuint wrap_s;
+ GLuint wrap_t;
+};
+
+
+static SDL_Surface* load_png(const std::string& path, texture_attributes& attribs)
{
std::ifstream file(path.c_str(), std::ifstream::binary);
if (!file.good())
#ifndef _MOOF_IMAGE_HH_
#define _MOOF_IMAGE_HH_
-/**
- * \file image.hh
- * Defines classes for loading and manipulating images.
- */
-
#include <boost/noncopyable.hpp>
#include <moof/dispatcher.hh>
#include <moof/resource.hh>
+/**
+ * \file image.hh
+ * Defines classes for loading and manipulating images.
+ */
+
namespace moof {
#ifndef _MOOF_INTERPOLATOR_HH_
#define _MOOF_INTERPOLATOR_HH_
+#include <moof/math.hh>
+
+
/**
* \file interpolator.hh
* Functions and classes concerning interpolations between values.
*/
-#include <moof/math.hh>
-
-
namespace moof {
#ifndef _MOOF_LINE_HH_
#define _MOOF_LINE_HH_
-/**
- * \file line.hh
- * Classes related to line segments.
- */
-
#include <moof/contact.hh>
#include <moof/drawable.hh>
#include <moof/image.hh>
#include <moof/sphere.hh>
+/**
+ * \file line.hh
+ * Classes related to line segments.
+ */
+
namespace moof {
#ifndef _MOOF_LOG_HH_
#define _MOOF_LOG_HH_
+#include <cstdlib> // exit
+#include <iostream>
+#include <string>
+
+
/**
* \file log.hh
* Functions related to logging the process. The logging functions are
* least critical.
*/
-#include <cstdlib> // exit
-#include <iostream>
-#include <string>
-
-
namespace moof {
#ifndef _MOOF_MANAGER_HH_
#define _MOOF_MANAGER_HH_
+#include <string>
+#include <boost/shared_ptr.hpp>
+
+#include <moof/hash.hh>
+
+
/**
* \file manager.hh
* A manager is a collection of named objects of the same type. Libraries
* have any interested code.
*/
-#include <string>
-
-#include <boost/shared_ptr.hpp>
-
-#include <moof/hash.hh>
-
-
namespace moof {
#ifndef _MOOF_MATH_HH_
#define _MOOF_MATH_HH_
-/**
- * \file math.hh
- * General math-related types and functions.
- */
+#include <cmath>
+
+#include <boost/shared_ptr.hpp>
+#include <SDL/SDL_opengl.h>
+
+#include <cml/cml.h>
#if HAVE_CONFIG_H
#include "config.h"
#endif
-#include <cmath>
-
-#include <cml/cml.h>
-#include <SDL/SDL_opengl.h>
#if ENABLE_DOUBLE_PRECISION
typedef GLdouble GLscalar;
#endif
+/**
+ * \file math.hh
+ * General math-related types and functions.
+ */
+
namespace moof {
D b = evaluate<S,D>(state, t, dt * SCALAR(0.5), a);
D c = evaluate<S,D>(state, t, dt * SCALAR(0.5), b);
D d = evaluate<S,D>(state, t, dt, c);
- state.step((a + (b + c) * SCALAR(2.0) + d) * SCALAR(1.0/6.0), dt);
+ state.step((a + (b + c) * SCALAR(2.0) + d) * (SCALAR(1.0)/SCALAR(6.0)), dt);
}
#ifndef _MOOF_MESH_HH_
#define _MOOF_MESH_HH_
-/**
- * \file mesh.hh
- * Defines classes for loading and manipulating meshes.
- */
-
#include <iostream>
#include <map>
#include <vector>
#include <moof/resource.hh>
+/**
+ * \file mesh.hh
+ * Defines classes for loading and manipulating meshes.
+ */
+
namespace moof {
#ifndef _MOOF_MODAL_DIALOG_HH_
#define _MOOF_MODAL_DIALOG_HH_
-/**
- * \file modal_dialog.hh
- * A class for creating and running modal dialogs. Several toolkits are
- * supported, but only one can be used as determined at build time.
- */
-
#if HAVE_CONFIG_H
#include "config.h"
#endif
#include <moof/resource.hh>
+/**
+ * \file modal_dialog.hh
+ * A class for creating and running modal dialogs. Several toolkits are
+ * supported, but only one can be used as determined at build time.
+ */
+
namespace moof {
#ifndef _MOOF_NETWORK_HH_
#define _MOOF_NETWORK_HH_
+#include <string>
+#include <vector>
+
+
/**
* \file network.hh
* Builds a high-level protocol and match-making system on top of network
* sockets for multiplayer support.
*/
-#include <string>
-#include <vector>
-
-
namespace moof {
#ifndef _MOOF_OPENGL_HH_
#define _MOOF_OPENGL_HH_
-/**
- * \file opengl.hh
- * Defines macros for OpenGL functions that operate on scalars, vectors, and
- * matrices.
- */
-
#if HAVE_CONFIG_H
#include "config.h"
#endif
#include <moof/math.hh>
+/**
+ * \file opengl.hh
+ * Defines macros for OpenGL functions that operate on scalars, vectors, and
+ * matrices.
+ */
+
// generic function arguments
#define ARGS_P const GLscalar* p
*
**************************************************************************/
+#if HAVE_CONFIG_H
#include "config.h"
+#endif
#include <algorithm>
+#include <cstdlib>
+
+#include <SDL/SDL.h>
+
#if HAVE_BYTESWAP_H
#include <byteswap.h>
#endif
-#include <cstdlib>
#if HAVE_ARPA_INET_H
#include <arpa/inet.h>
#endif
-#include <SDL/SDL.h>
-
#include "packet.hh"
#ifndef _MOOF_PACKET_HH_
#define _MOOF_PACKET_HH_
-/**
- * \file packet.hh
- * Classes for building and interpreting datagram packets.
- */
-
#include <cstring>
#include <stdexcept>
+#include <stdint.h>
#include <string>
#include <vector>
-
#ifndef PAGE_SIZE
#define PAGE_SIZE 4096
#endif
+/**
+ * \file packet.hh
+ * Classes for building and interpreting datagram packets.
+ */
+
namespace moof {
#ifndef _MOOF_PLANE_HH_
#define _MOOF_PLANE_HH_
+#include <moof/math.hh>
+#include <moof/shape.hh>
+
+
/**
* \file plane.hh
* Classes and functions related to planes.
*/
-#include <moof/math.hh>
-#include <moof/shape.hh>
-
-
namespace moof {
--- /dev/null
+
+/*] Copyright (c) 2009-2011, Charles McGarvey [*****************************
+**] All rights reserved.
+*
+* Distributable under the terms and conditions of the 2-clause BSD license;
+* see the file COPYING for a complete text of the license.
+*
+*****************************************************************************/
+
+#ifndef _MOOF_PRECOMPILE_HH_
+#define _MOOF_PRECOMPILE_HH_
+
+/**
+ * \file precompile.hh
+ * PCH includes for quicker compiles.
+ */
+
+#include <algorithm>
+#include <bitset>
+#include <cerrno>
+#include <cmath>
+#include <cstdio>
+#include <cstdlib>
+#include <cstring>
+#include <ctime>
+#include <deque>
+#include <exception>
+#include <fstream>
+#include <functional>
+#include <iomanip>
+#include <iostream>
+#include <limits>
+#include <list>
+#include <map>
+#include <set>
+#include <sstream>
+#include <stack>
+#include <stdexcept>
+#include <stdint.h>
+#include <stddef.h>
+#include <string>
+#include <utility>
+#include <vector>
+
+#include <boost/algorithm/string.hpp>
+#include <boost/bind.hpp>
+#include <boost/function.hpp>
+#include <boost/noncopyable.hpp>
+#include <boost/shared_ptr.hpp>
+#include <boost/shared_array.hpp>
+#include <boost/weak_ptr.hpp>
+#include <lua.hpp>
+#include <png.h>
+#include <SDL/SDL.h>
+#include <SDL/SDL_opengl.h>
+#include <zlib.h>
+
+#endif // _MOOF_PRECOMPILE_HH_
+
#ifndef _MOOF_RAY_HH_
#define _MOOF_RAY_HH_
-/**
- * \file ray.hh
- * A class for lines that start at one point and go to infinity in some
- * direction.
- */
-
#include <moof/drawable.hh>
#include <moof/image.hh>
#include <moof/math.hh>
#include <moof/opengl.hh>
+/**
+ * \file ray.hh
+ * A class for lines that start at one point and go to infinity in some
+ * direction.
+ */
+
namespace moof {
#include <queue>
+#include <boost/algorithm/string.hpp>
+#include <boost/weak_ptr.hpp>
+
+#include <stlplus/portability/file_system.hpp>
+
#if ENABLE_HOTLOADING
#include <sys/inotify.h>
#include <sys/ioctl.h>
#endif
-#include <boost/algorithm/string.hpp>
-#include <boost/weak_ptr.hpp>
-#include <stlplus/portability/file_system.hpp>
-
#include "hash.hh"
+#include "log.hh"
#include "resource.hh"
#ifndef BUF_SIZE
#ifndef _MOOF_RESOURCE_HH_
#define _MOOF_RESOURCE_HH_
-/**
- * \file resource.hh
- * Interface for textures, sounds, and other types of resources.
- */
-
#include <map>
#include <stdexcept>
#include <string>
#include <boost/shared_ptr.hpp>
#include <boost/function.hpp>
-#include <moof/debug.hh>
+/**
+ * \file resource.hh
+ * Interface for textures, sounds, and other types of resources.
+ */
namespace moof {
#ifndef _MOOF_RIGID_BODY_HH_
#define _MOOF_RIGID_BODY_HH_
-/**
- * \file rigid_body.hh
- * Classes and functions for simulating rigid body physics.
- */
-
#include <vector>
#include <boost/bind.hpp>
#include <moof/math.hh>
+/**
+ * \file rigid_body.hh
+ * Classes and functions for simulating rigid body physics.
+ */
+
namespace moof {
#
objects = $(patsubst %.c,$(builddir)/%.o,$(patsubst %.cc,$(builddir)/%.o,$(wildcard $d/*.c $d/*.cc)))
-$(objects): TGT_CFLAGS := -I$d -I$d/..
-$(objects): config.h $(this) | $b
+$(objects): TGT_CFLAGS := -I$b -I$b/.. -I$d -I$d/..
+$(objects): config.h | $b
library = $b/libmoof.a
$(library): $(objects)
$(Q)$(ar)
+ifeq (true,$(pch))
+pchfile := $b/precompile.hh
+exec += $(pchfile) $(pchfile).gch
+$(pchfile).gch: TGT_CFLAGS := -I$b -I$b/.. -I$d -I$d/..
+$(pchfile).gch: $(pchfile)
+$(pchfile): config.mk | $b
+$(objects): $(pchfile).gch
+endif
+
exec += $(objects) $(library)
#ifndef _MOOF_RUNLOOP_HH_
#define _MOOF_RUNLOOP_HH_
-/**
- * \file runloop.hh
- * Thread timer management class.
- */
-
#include <vector>
#include <boost/noncopyable.hpp>
#include <moof/thread.hh>
+/**
+ * \file runloop.hh
+ * Thread timer management class.
+ */
+
namespace moof {
#ifndef _MOOF_SCRIPT_HH_
#define _MOOF_SCRIPT_HH_
-/**
- * \file script.hh
- * A thin wrapper over Lua 5.1. This is not meant as a complicated binding
- * package between C++ and Lua. It is not meant to obscure the division
- * between C++ and Lua but rather to clarify it and make it more manageable.
- * It does not hide the concept of the Lua stack, but rather provides that
- * mechanism with a certain level of abstraction while also providing a
- * cleaner, more consistent API.
- */
-
#include <cstring>
#include <iostream>
#include <map>
#include <lua.hpp>
+/**
+ * \file script.hh
+ * A thin wrapper over Lua 5.1. This is not meant as a complicated binding
+ * package between C++ and Lua. It is not meant to obscure the division
+ * between C++ and Lua but rather to clarify it and make it more manageable.
+ * It does not hide the concept of the Lua stack, but rather provides that
+ * mechanism with a certain level of abstraction while also providing a
+ * cleaner, more consistent API.
+ */
+
namespace moof {
#ifndef _MOOF_SERVICE_HH_
#define _MOOF_SERVICE_HH_
-/**
- * \file service.hh
- * Classes for publishing and finding network services.
- */
-
#include <map>
#include <moof/math.hh>
#include <moof/socket.hh>
+/**
+ * \file service.hh
+ * Classes for publishing and finding network services.
+ */
+
namespace moof {
#ifndef _MOOF_SETTINGS_HH_
#define _MOOF_SETTINGS_HH_
-/**
- * \file settings.hh
- * Load, store, save program settings.
- */
-
#include <string>
#include <vector>
#include <moof/script.hh>
+/**
+ * \file settings.hh
+ * Load, store, save program settings.
+ */
+
namespace moof {
#ifndef _MOOF_SHAPE_HH_
#define _MOOF_SHAPE_HH_
-/**
- * \file shape.hh
- * Declares an interface for shapes.
- */
-
#include <moof/drawable.hh>
#include <moof/math.hh>
#include <moof/opengl.hh>
#include <moof/ray.hh>
+
+/**
+ * \file shape.hh
+ * Declares an interface for shapes.
+ */
+
// frustum
// plane (can construct from triangle2)
// ray
#ifndef _MOOF_SOCKET_HH_
#define _MOOF_SOCKET_HH_
-/**
- * \file socket.hh
- * Network-related classes, including a reinterpreted sockets API.
- */
-
#include <algorithm>
#include <cstring>
#include <iostream>
#include <moof/packet.hh>
#include <moof/thread.hh>
-
#ifndef AI_ADDRCONFIG
#define AI_ADDRCONFIG 0
#endif
#endif
+/**
+ * \file socket.hh
+ * Network-related classes, including a reinterpreted sockets API.
+ */
+
namespace moof {
#include <vorbis/codec.h>
#include <vorbis/vorbisfile.h>
-#include "log.hh"
+#include "debug.hh"
#include "sound.hh"
#include "resource.hh"
#include "runloop.hh"
#include "thread.hh"
#include "timer.hh"
+
#ifndef BUF_SIZE
#define BUF_SIZE 8192
#endif
ALCdevice* sound_backend::al_device;
ALCcontext* sound_backend::al_context;
+
class sound_resource;
typedef resource_handle<sound_resource> sound_handle;
MOOF_REGISTER_RESOURCE(sound_resource, ogg, sounds);
-
class sound_resource : public boost::noncopyable
{
public:
#ifndef _MOOF_SOUND_HH_
#define _MOOF_SOUND_HH_
-/**
- * \file sound.hh
- * Load and play sounds, currently supports ogg vorbis.
- */
-
#include <string>
#include <boost/shared_ptr.hpp>
#include <moof/math.hh>
+/**
+ * \file sound.hh
+ * Load and play sounds, currently supports ogg vorbis.
+ */
+
namespace moof {
#ifndef _MOOF_SPHERE_HH_
#define _MOOF_SPHERE_HH_
-/**
- * \file sphere.hh
- * A round shape like a circle or sphere.
- * TODO: This class needs some work.
- */
-
#include <moof/contact.hh>
#include <moof/cullable.hh>
#include <moof/drawable.hh>
#include <moof/shape.hh>
+/**
+ * \file sphere.hh
+ * A round shape like a circle or sphere.
+ * TODO: This class needs some work.
+ */
+
namespace moof {
#include <boost/algorithm/string.hpp>
#include <boost/bind.hpp>
+
#include <stlplus/portability/file_system.hpp>
#include "dispatcher.hh"
#ifndef _MOOF_SPRITE_HH_
#define _MOOF_SPRITE_HH_
-/**
- * \file sprite.hh
- * Image-loading and OpenGL texture loading.
- */
-
#include <string>
#include <moof/image.hh>
#include <moof/math.hh>
+/**
+ * \file sprite.hh
+ * Image-loading and OpenGL texture loading.
+ */
+
namespace moof {
#include <boost/shared_array.hpp>
-#include "ConvertUTF.h"
#include "script.hh"
#include "string.hh"
+#include "ConvertUTF.h"
namespace moof {
#ifndef _MOOF_STRING_HH_
#define _MOOF_STRING_HH_
-/**
- * \file string.hh
- * Functions and classes related to string manipulation.
- */
-
#include <string>
#include <boost/noncopyable.hpp>
+/**
+ * \file string.hh
+ * Functions and classes related to string manipulation.
+ */
+
namespace moof {
#ifndef _MOOF_THREAD_HH_
#define _MOOF_THREAD_HH_
-/**
- * \file thread.hh
- * Light C++ wrapper around the SDL threads API.
- */
-
#include <boost/bind.hpp>
#include <boost/function.hpp>
#include <boost/shared_ptr.hpp>
#include <moof/timer.hh>
+/**
+ * \file thread.hh
+ * Light C++ wrapper around the SDL threads API.
+ */
+
namespace moof {
#ifndef _MOOF_TIMER_HH_
#define _MOOF_TIMER_HH_
-/**
- * \file timer.hh
- * Functions for measuring time in a friendly unit.
- */
-
#include <boost/bind.hpp>
#include <boost/function.hpp>
#include <boost/noncopyable.hpp>
#include <moof/math.hh>
+/**
+ * \file timer.hh
+ * Functions for measuring time in a friendly unit.
+ */
+
namespace moof {
#ifndef _MOOF_VIDEO_HH_
#define _MOOF_VIDEO_HH_
-/**
- * \file video.hh
- * Classes for managing a video context.
- */
-
#include <string>
#include <boost/shared_ptr.hpp>
#include <moof/timer.hh>
+/**
+ * \file video.hh
+ * Classes for managing a video context.
+ */
+
namespace moof {
ifeq (true,$(includeConfig))
objects += $b/config.o # Also compile in the configuration.
+exec += $b/config.gz
exec += $b/config.c # Make config.c a build target.
-$b/config.c: config.mk
+$b/config.gz: config.mk
+ $(Q)$(gzip)
+$b/config.c: $b/config.gz
$(Q)$(xxd)
endif
-$(objects): TGT_CFLAGS := -I$d
-$(objects): config.h $(this) | $b
+$(objects): TGT_CFLAGS := -I$b -I$d
+$(objects): config.h | $b
# Make all objects depend on config.h; it's excessive, but config.h won't be
# remade otherwise if dependencies are not being generated. The alternative
# is to maintain an accurate list of objects with a dependency on config.h.
+ifeq (true,$(pch))
+$(objects): $b/moof/precompile.hh.gch
+endif
+
exec += $(objects) # Make the objects build targets.
bindir_$b := $b/$(projectName)$(EXEEXT) # Install executable to bindir.
objects = $(patsubst %.cpp,$(builddir)/%.o,$(shell find $d -name "*.cpp"))
$(objects): TGT_CFLAGS := -I$d -I$d/containers -I$d/portability
-$(objects): config.mk $(this) | $b/containers $b/portability
+$(objects): config.mk | $b/containers $b/portability
library = $b/libstlplus.a
$(library): $(objects)
#ifndef _YOINK_HH_
#define _YOINK_HH_
-/**
- * \file yoink.hh
- * This is the big enchilada.
- */
-
#include <iostream>
#include <string>
#include <vector>
#include <boost/shared_ptr.hpp>
-#include <moof/math.hh>
-#include <moof/sound.hh>
-
#include <moof/line.hh> // TODO
+#include <moof/math.hh>
#include <moof/plane.hh>
#include <moof/ray.hh>
+#include <moof/sound.hh>
#include <moof/sphere.hh>
#include <moof/timer.hh>
#include "Hud.hh"
+/**
+ * \file yoink.hh
+ * This is the big enchilada.
+ */
+
class yoink
{
public: