From 574af38ed616d1adfa5e6ce35f67cda1f707f89d Mon Sep 17 00:00:00 2001 From: Charles McGarvey Date: Fri, 1 Jul 2011 02:01:10 -0600 Subject: [PATCH] remove some unused stlplus modules also updated copyright timespan and formatted files for tabstops of 8 characters --- Makefile | 77 +- README | 2 +- TODO | 4 +- build/arch/win32/makedeps.mk | 35 +- build/arch/win32/rules.mk | 12 +- build/config.lua | 66 +- build/dialog.c | 104 +- configure | 4 +- data/rules.mk | 8 +- data/scenes/Classic.lua | 7 +- doc/yoink_readme.7 | 2 +- options.lua | 27 +- scripts/man2html.lua | 14 +- {build/arch/win32 => scripts}/unix2dos.sh | 6 +- src/Animation.cc | 131 +-- src/Animation.hh | 9 +- src/Character.cc | 11 +- src/Character.hh | 10 +- src/GameState.hh | 16 +- src/Heroine.cc | 101 +- src/Heroine.hh | 8 +- src/Hud.cc | 49 +- src/Hud.hh | 7 +- src/Main.cc | 126 +-- src/Main.hh | 10 +- src/Scene.cc | 37 +- src/Scene.hh | 11 +- src/TilemapFont.cc | 6 +- src/TilemapFont.hh | 6 +- src/Typesetter.cc | 6 +- src/Typesetter.hh | 6 +- src/moof/aabb.cc | 8 +- src/moof/aabb.hh | 54 +- src/moof/application.cc | 62 +- src/moof/application.hh | 23 +- src/moof/backend.cc | 43 +- src/moof/backend.hh | 22 +- src/moof/camera.cc | 103 +- src/moof/camera.hh | 13 +- src/moof/contact.hh | 12 +- src/moof/cullable.hh | 9 +- src/moof/debug.hh | 6 +- src/moof/dispatcher.cc | 51 +- src/moof/dispatcher.hh | 13 +- src/moof/drawable.hh | 8 +- src/moof/entity.hh | 25 +- src/moof/event.hh | 6 +- src/moof/frustum.cc | 61 +- src/moof/frustum.hh | 21 +- src/moof/hash.cc | 10 +- src/moof/hash.hh | 10 +- src/moof/image.cc | 71 +- src/moof/image.hh | 40 +- src/moof/interpolator.hh | 61 +- src/moof/line.hh | 49 +- src/moof/log.cc | 57 +- src/moof/log.hh | 50 +- src/moof/manager.hh | 14 +- src/moof/math.hh | 25 +- src/moof/mesh.cc | 74 +- src/moof/mesh.hh | 46 +- src/moof/mesh_bindings.cc | 43 +- src/moof/modal_dialog.hh | 120 +-- src/moof/network.hh | 6 +- src/moof/opengl.hh | 77 +- src/moof/plane.cc | 26 +- src/moof/plane.hh | 25 +- src/moof/ray.hh | 11 +- src/moof/resource.cc | 63 +- src/moof/resource.hh | 50 +- src/moof/rigid_body.hh | 44 +- src/moof/runloop.cc | 42 +- src/moof/runloop.hh | 18 +- src/moof/script.hh | 260 +++-- src/moof/service.cc | 25 +- src/moof/service.hh | 28 +- src/moof/settings.cc | 16 +- src/moof/settings.hh | 14 +- src/moof/shape.hh | 26 +- src/moof/sound.cc | 226 ++--- src/moof/sound.hh | 14 +- src/moof/sound_bindings.cc | 15 +- src/moof/sphere.hh | 26 +- src/moof/sprite.cc | 11 +- src/moof/sprite.hh | 9 +- src/moof/string.cc | 146 ++- src/moof/string.hh | 82 +- src/moof/thread.cc | 10 +- src/moof/thread.hh | 159 ++- src/moof/timer.cc | 56 +- src/moof/timer.hh | 67 +- src/moof/video.cc | 70 +- src/moof/video.hh | 64 +- src/rules.mk | 21 +- src/stlplus/rules.mk | 2 +- src/stlplus/strings/format_types.hpp | 60 -- src/stlplus/strings/print_address.cpp | 28 - src/stlplus/strings/print_address.hpp | 33 - src/stlplus/strings/print_basic.hpp | 21 - src/stlplus/strings/print_bitset.hpp | 27 - src/stlplus/strings/print_bitset.tpp | 20 - src/stlplus/strings/print_bool.cpp | 27 - src/stlplus/strings/print_bool.hpp | 34 - src/stlplus/strings/print_cstring.cpp | 19 - src/stlplus/strings/print_cstring.hpp | 27 - src/stlplus/strings/print_digraph.hpp | 33 - src/stlplus/strings/print_digraph.tpp | 31 - src/stlplus/strings/print_float.cpp | 32 - src/stlplus/strings/print_float.hpp | 47 - src/stlplus/strings/print_foursome.hpp | 35 - src/stlplus/strings/print_foursome.tpp | 33 - src/stlplus/strings/print_hash.hpp | 34 - src/stlplus/strings/print_hash.tpp | 29 - src/stlplus/strings/print_inf.cpp | 38 - src/stlplus/strings/print_inf.hpp | 40 - src/stlplus/strings/print_int.cpp | 55 - src/stlplus/strings/print_int.hpp | 81 -- src/stlplus/strings/print_list.hpp | 30 - src/stlplus/strings/print_list.tpp | 25 - src/stlplus/strings/print_map.hpp | 38 - src/stlplus/strings/print_map.tpp | 46 - src/stlplus/strings/print_matrix.hpp | 33 - src/stlplus/strings/print_matrix.tpp | 33 - src/stlplus/strings/print_ntree.hpp | 33 - src/stlplus/strings/print_ntree.tpp | 30 - src/stlplus/strings/print_pair.hpp | 31 - src/stlplus/strings/print_pair.tpp | 25 - src/stlplus/strings/print_pointer.hpp | 32 - src/stlplus/strings/print_pointer.tpp | 34 - src/stlplus/strings/print_sequence.hpp | 46 - src/stlplus/strings/print_sequence.tpp | 50 - src/stlplus/strings/print_set.hpp | 36 - src/stlplus/strings/print_set.tpp | 41 - src/stlplus/strings/print_simple_ptr.hpp | 51 - src/stlplus/strings/print_simple_ptr.tpp | 74 -- src/stlplus/strings/print_smart_ptr.hpp | 51 - src/stlplus/strings/print_smart_ptr.tpp | 74 -- src/stlplus/strings/print_stl.hpp | 23 - src/stlplus/strings/print_stlplus.hpp | 26 - src/stlplus/strings/print_string.cpp | 22 - src/stlplus/strings/print_string.hpp | 26 - src/stlplus/strings/print_triple.hpp | 34 - src/stlplus/strings/print_triple.tpp | 30 - src/stlplus/strings/print_vector.cpp | 25 - src/stlplus/strings/print_vector.hpp | 38 - src/stlplus/strings/print_vector.tpp | 22 - src/stlplus/strings/string_address.cpp | 36 - src/stlplus/strings/string_address.hpp | 39 - src/stlplus/strings/string_basic.hpp | 21 - src/stlplus/strings/string_bitset.hpp | 26 - src/stlplus/strings/string_bitset.tpp | 22 - src/stlplus/strings/string_bool.cpp | 35 - src/stlplus/strings/string_bool.hpp | 39 - src/stlplus/strings/string_cstring.cpp | 19 - src/stlplus/strings/string_cstring.hpp | 26 - src/stlplus/strings/string_digraph.hpp | 31 - src/stlplus/strings/string_digraph.tpp | 33 - src/stlplus/strings/string_float.cpp | 96 -- src/stlplus/strings/string_float.hpp | 55 - src/stlplus/strings/string_foursome.hpp | 33 - src/stlplus/strings/string_foursome.tpp | 33 - src/stlplus/strings/string_hash.hpp | 32 - src/stlplus/strings/string_hash.tpp | 27 - src/stlplus/strings/string_inf.cpp | 536 ---------- src/stlplus/strings/string_inf.hpp | 40 - src/stlplus/strings/string_int.cpp | 1111 --------------------- src/stlplus/strings/string_int.hpp | 118 --- src/stlplus/strings/string_list.hpp | 28 - src/stlplus/strings/string_list.tpp | 24 - src/stlplus/strings/string_map.hpp | 37 - src/stlplus/strings/string_map.tpp | 45 - src/stlplus/strings/string_matrix.hpp | 31 - src/stlplus/strings/string_matrix.tpp | 35 - src/stlplus/strings/string_ntree.hpp | 31 - src/stlplus/strings/string_ntree.tpp | 31 - src/stlplus/strings/string_pair.hpp | 29 - src/stlplus/strings/string_pair.tpp | 22 - src/stlplus/strings/string_pointer.hpp | 30 - src/stlplus/strings/string_pointer.tpp | 24 - src/stlplus/strings/string_sequence.hpp | 45 - src/stlplus/strings/string_sequence.tpp | 54 - src/stlplus/strings/string_set.hpp | 33 - src/stlplus/strings/string_set.tpp | 39 - src/stlplus/strings/string_simple_ptr.hpp | 47 - src/stlplus/strings/string_simple_ptr.tpp | 44 - src/stlplus/strings/string_smart_ptr.hpp | 47 - src/stlplus/strings/string_smart_ptr.tpp | 44 - src/stlplus/strings/string_stl.hpp | 23 - src/stlplus/strings/string_stlplus.hpp | 30 - src/stlplus/strings/string_string.cpp | 22 - src/stlplus/strings/string_string.hpp | 26 - src/stlplus/strings/string_triple.hpp | 32 - src/stlplus/strings/string_triple.tpp | 29 - src/stlplus/strings/string_utilities.cpp | 442 -------- src/stlplus/strings/string_utilities.hpp | 120 --- src/stlplus/strings/string_vector.cpp | 27 - src/stlplus/strings/string_vector.hpp | 36 - src/stlplus/strings/string_vector.tpp | 22 - src/stlplus/strings/strings.hpp | 30 - src/stlplus/strings/strings_fixes.hpp | 56 -- src/win32.rc | 24 +- src/yoink.cc | 10 +- src/yoink.hh | 12 +- 203 files changed, 1618 insertions(+), 8131 deletions(-) rename {build/arch/win32 => scripts}/unix2dos.sh (74%) delete mode 100644 src/stlplus/strings/format_types.hpp delete mode 100644 src/stlplus/strings/print_address.cpp delete mode 100644 src/stlplus/strings/print_address.hpp delete mode 100644 src/stlplus/strings/print_basic.hpp delete mode 100644 src/stlplus/strings/print_bitset.hpp delete mode 100644 src/stlplus/strings/print_bitset.tpp delete mode 100644 src/stlplus/strings/print_bool.cpp delete mode 100644 src/stlplus/strings/print_bool.hpp delete mode 100644 src/stlplus/strings/print_cstring.cpp delete mode 100644 src/stlplus/strings/print_cstring.hpp delete mode 100644 src/stlplus/strings/print_digraph.hpp delete mode 100644 src/stlplus/strings/print_digraph.tpp delete mode 100644 src/stlplus/strings/print_float.cpp delete mode 100644 src/stlplus/strings/print_float.hpp delete mode 100644 src/stlplus/strings/print_foursome.hpp delete mode 100644 src/stlplus/strings/print_foursome.tpp delete mode 100644 src/stlplus/strings/print_hash.hpp delete mode 100644 src/stlplus/strings/print_hash.tpp delete mode 100644 src/stlplus/strings/print_inf.cpp delete mode 100644 src/stlplus/strings/print_inf.hpp delete mode 100644 src/stlplus/strings/print_int.cpp delete mode 100644 src/stlplus/strings/print_int.hpp delete mode 100644 src/stlplus/strings/print_list.hpp delete mode 100644 src/stlplus/strings/print_list.tpp delete mode 100644 src/stlplus/strings/print_map.hpp delete mode 100644 src/stlplus/strings/print_map.tpp delete mode 100644 src/stlplus/strings/print_matrix.hpp delete mode 100644 src/stlplus/strings/print_matrix.tpp delete mode 100644 src/stlplus/strings/print_ntree.hpp delete mode 100644 src/stlplus/strings/print_ntree.tpp delete mode 100644 src/stlplus/strings/print_pair.hpp delete mode 100644 src/stlplus/strings/print_pair.tpp delete mode 100644 src/stlplus/strings/print_pointer.hpp delete mode 100644 src/stlplus/strings/print_pointer.tpp delete mode 100644 src/stlplus/strings/print_sequence.hpp delete mode 100644 src/stlplus/strings/print_sequence.tpp delete mode 100644 src/stlplus/strings/print_set.hpp delete mode 100644 src/stlplus/strings/print_set.tpp delete mode 100644 src/stlplus/strings/print_simple_ptr.hpp delete mode 100644 src/stlplus/strings/print_simple_ptr.tpp delete mode 100644 src/stlplus/strings/print_smart_ptr.hpp delete mode 100644 src/stlplus/strings/print_smart_ptr.tpp delete mode 100644 src/stlplus/strings/print_stl.hpp delete mode 100644 src/stlplus/strings/print_stlplus.hpp delete mode 100644 src/stlplus/strings/print_string.cpp delete mode 100644 src/stlplus/strings/print_string.hpp delete mode 100644 src/stlplus/strings/print_triple.hpp delete mode 100644 src/stlplus/strings/print_triple.tpp delete mode 100644 src/stlplus/strings/print_vector.cpp delete mode 100644 src/stlplus/strings/print_vector.hpp delete mode 100644 src/stlplus/strings/print_vector.tpp delete mode 100644 src/stlplus/strings/string_address.cpp delete mode 100644 src/stlplus/strings/string_address.hpp delete mode 100644 src/stlplus/strings/string_basic.hpp delete mode 100644 src/stlplus/strings/string_bitset.hpp delete mode 100644 src/stlplus/strings/string_bitset.tpp delete mode 100644 src/stlplus/strings/string_bool.cpp delete mode 100644 src/stlplus/strings/string_bool.hpp delete mode 100644 src/stlplus/strings/string_cstring.cpp delete mode 100644 src/stlplus/strings/string_cstring.hpp delete mode 100644 src/stlplus/strings/string_digraph.hpp delete mode 100644 src/stlplus/strings/string_digraph.tpp delete mode 100644 src/stlplus/strings/string_float.cpp delete mode 100644 src/stlplus/strings/string_float.hpp delete mode 100644 src/stlplus/strings/string_foursome.hpp delete mode 100644 src/stlplus/strings/string_foursome.tpp delete mode 100644 src/stlplus/strings/string_hash.hpp delete mode 100644 src/stlplus/strings/string_hash.tpp delete mode 100644 src/stlplus/strings/string_inf.cpp delete mode 100644 src/stlplus/strings/string_inf.hpp delete mode 100644 src/stlplus/strings/string_int.cpp delete mode 100644 src/stlplus/strings/string_int.hpp delete mode 100644 src/stlplus/strings/string_list.hpp delete mode 100644 src/stlplus/strings/string_list.tpp delete mode 100644 src/stlplus/strings/string_map.hpp delete mode 100644 src/stlplus/strings/string_map.tpp delete mode 100644 src/stlplus/strings/string_matrix.hpp delete mode 100644 src/stlplus/strings/string_matrix.tpp delete mode 100644 src/stlplus/strings/string_ntree.hpp delete mode 100644 src/stlplus/strings/string_ntree.tpp delete mode 100644 src/stlplus/strings/string_pair.hpp delete mode 100644 src/stlplus/strings/string_pair.tpp delete mode 100644 src/stlplus/strings/string_pointer.hpp delete mode 100644 src/stlplus/strings/string_pointer.tpp delete mode 100644 src/stlplus/strings/string_sequence.hpp delete mode 100644 src/stlplus/strings/string_sequence.tpp delete mode 100644 src/stlplus/strings/string_set.hpp delete mode 100644 src/stlplus/strings/string_set.tpp delete mode 100644 src/stlplus/strings/string_simple_ptr.hpp delete mode 100644 src/stlplus/strings/string_simple_ptr.tpp delete mode 100644 src/stlplus/strings/string_smart_ptr.hpp delete mode 100644 src/stlplus/strings/string_smart_ptr.tpp delete mode 100644 src/stlplus/strings/string_stl.hpp delete mode 100644 src/stlplus/strings/string_stlplus.hpp delete mode 100644 src/stlplus/strings/string_string.cpp delete mode 100644 src/stlplus/strings/string_string.hpp delete mode 100644 src/stlplus/strings/string_triple.hpp delete mode 100644 src/stlplus/strings/string_triple.tpp delete mode 100644 src/stlplus/strings/string_utilities.cpp delete mode 100644 src/stlplus/strings/string_utilities.hpp delete mode 100644 src/stlplus/strings/string_vector.cpp delete mode 100644 src/stlplus/strings/string_vector.hpp delete mode 100644 src/stlplus/strings/string_vector.tpp delete mode 100644 src/stlplus/strings/strings.hpp delete mode 100644 src/stlplus/strings/strings_fixes.hpp diff --git a/Makefile b/Makefile index e104a4e..a0c754b 100644 --- a/Makefile +++ b/Makefile @@ -6,7 +6,7 @@ # Set V to `1' to echo each build command in full. The default behavior # will keep output minimal. -V = 0 +V = 0 SHELL = /bin/sh @@ -35,7 +35,7 @@ include config.mk DATA_TARGETS := EXEC_TARGETS := -SUBDIRS := +SUBDIRS := define include_func = ifeq (,$$d) @@ -43,13 +43,13 @@ dir := $1 else dir := $$d/$1 endif -sp := $$(sp).x +sp := $$(sp).x dirstack_$$(sp) := $$d datstack_$$(sp) := $$(data) exestack_$$(sp) := $$(exec) -d := $$(dir) -data := -exec := +d := $$(dir) +data := +exec := include $$(dir)/rules.mk SUBDIRS += $$d $$b data := $$(sort $$(data) $$(appdir_$$b) $$(mandir_$$b) $$(pkgdatadir_$$b) $$(desktop_$$b)) @@ -59,7 +59,7 @@ clean := $$(clean) $$(deps) $$(exec) $$(data) DEPFILE := $$(DEPFILE) $$(deps) DATA_TARGETS += $$(data) EXEC_TARGETS += $$(exec) -d := $$(dirstack_$$(sp)) +d := $$(dirstack_$$(sp)) data := $$(datstack_$$(sp)) exec := $$(exestack_$$(sp)) sp := $$(basename $$(sp)) @@ -68,7 +68,7 @@ include = $(foreach i,$1,$(eval $(call include_func,$i))) targets = $(EXEC_TARGETS) $(DATA_TARGETS) builddir = build/obj -b = $(builddir)/$(d) +b = $(builddir)/$(d) this = $(d)/rules.mk ifeq (gzip,$(manCompression)) @@ -85,7 +85,7 @@ endif # $(call include,src data doc) --include build/$(platform)/rules.mk +-include build/arch/$(platform)/rules.mk # @@ -98,7 +98,7 @@ PKG_CFLAGS += -MD -MP -MF $(@:%.o=%.d) -MT $@ endif # Include current directory to allow sources to include config.h. -override CPPFLAGS += -I. +override CPPFLAGS += -I. -DHAVE_CONFIG_H=1 TGT_CXXFLAGS = $(TGT_CFLAGS) ARFLAGS = rc INSTALL = install @@ -106,51 +106,51 @@ INSTALL = install tarname = $(TARNAME)-$(VERSION) cmd_compile_c = $(CC) $(PKG_CFLAGS) $(TGT_CFLAGS) $(CFLAGS) $(CPPFLAGS) \ - $(TARGET_ARCH) -c $(OUTPUT_OPTION) $< + $(TARGET_ARCH) -c $(OUTPUT_OPTION) $< cmd_compile_cc = $(CXX) $(PKG_CXXFLAGS) $(TGT_CXXFLAGS) $(CXXFLAGS) $(CPPFLAGS) \ - $(TARGET_ARCH) -c $(OUTPUT_OPTION) $< -cmd_link_c = $(CC) $(PKG_CFLAGS) $(TGT_CFLAGS) $(CFLAGS) $(CPPFLAGS) \ - $(PKG_LDFLAGS) $(TGT_LDFLAGS) $(LDFLAGS) \ - $(TARGET_ARCH) $^ $(LOADLIBES) $(PKG_LDLIBS) $(TGT_LDLIBS) $(LDLIBS) -o $@ -cmd_link_cc = $(CXX) $(PKG_CXXFLAGS) $(TGT_CXXFLAGS) $(CXXFLAGS) $(CPPFLAGS) \ - $(PKG_LDFLAGS) $(TGT_LDFLAGS) $(LDFLAGS) \ - $(TARGET_ARCH) $^ $(LOADLIBES) $(PKG_LDLIBS) $(TGT_LDLIBS) $(LDLIBS) -o $@ -cmd_ar = $(AR) $(ARFLAGS) $@ $^; $(RANLIB) $@ + $(TARGET_ARCH) -c $(OUTPUT_OPTION) $< +cmd_link_c = $(CC) $(PKG_CFLAGS) $(TGT_CFLAGS) $(CFLAGS) $(CPPFLAGS) \ + $(PKG_LDFLAGS) $(TGT_LDFLAGS) $(LDFLAGS) \ + $(TARGET_ARCH) $^ $(LOADLIBES) $(PKG_LDLIBS) $(TGT_LDLIBS) $(LDLIBS) -o $@ +cmd_link_cc = $(CXX) $(PKG_CXXFLAGS) $(TGT_CXXFLAGS) $(CXXFLAGS) $(CPPFLAGS) \ + $(PKG_LDFLAGS) $(TGT_LDFLAGS) $(LDFLAGS) \ + $(TARGET_ARCH) $^ $(LOADLIBES) $(PKG_LDLIBS) $(TGT_LDLIBS) $(LDLIBS) -o $@ +cmd_ar = $(AR) $(ARFLAGS) $@ $^; $(RANLIB) $@ cmd_compile_rc = $(WINDRES) $(CPPFLAGS) $(TARGET_ARCH) $(OUTPUT_OPTION) -i $< -cmd_sed = sed -f config.sed <$< >$@ -cmd_gzip = gzip -c $< >$@ -cmd_bzip2 = bzip2 -c $< >$@ -cmd_xxd = id=$(subst .,_,$(notdir $<)); \ - printf "\#include \nsize_t\tdata_%s_size = %d;\nchar\tdata_%s[] = {\n" \ - $$id $$(wc -c <$<) $$id >$@; \ - xxd -i <$< >>$@; \ - printf ", 0x00\n};\n" >>$@ +cmd_sed = sed -f config.sed <$< >$@ +cmd_gzip = gzip -c $< >$@ +cmd_bzip2 = bzip2 -c $< >$@ +cmd_xxd = id=$(subst .,_,$(notdir $<)); \ + printf "\#include \nsize_t\tdata_%s_size = %d;\nchar\tdata_%s[] = {\n" \ + $$id $$(wc -c <$<) $$id >$@; \ + xxd -i <$< >>$@; \ + printf ", 0x00\n};\n" >>$@ cmd_configure = ./configure func_install = mkdir -p $(DESTDIR)$3 && $(INSTALL) -m $1 $2 $(DESTDIR)$3 -func_remove = rm -f $1 -func_dist = git archive HEAD --prefix='$(tarname)/' | $1 >"$(tarname).tar.$2" && \ - (md5 "$(tarname).tar.$2" 2>/dev/null || md5sum "$(tarname).tar.$2") +func_remove = rm -f $1 +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) +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) +xxd = $(call func_print,XXD,$@) $(cmd_xxd) configure = $(call func_print,MAKE,$@) $(cmd_configure) dist = $(call func_print,DIST,$1) $(func_dist) -install = $(call func_print,CP,$(DESTDIR)$(3:%/=%)/$(notdir $2)) $(func_install) +install = $(call func_print,CP,$(DESTDIR:%/=%)$(3:%/=%)/$(notdir $2)) $(func_install) remove = $(call func_print,RM,$1) $(func_remove) ifeq (1,$V) -Q = +Q = func_print = else -Q = @ +Q = @ func_print = printf "\x20\x20$1\t%s\n" $2; endif @@ -214,7 +214,8 @@ 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),\ - $(call install,644,$f,$(dir $(f:$d%=$(mandir)/man$(shell echo "$f" | sed 's/[^.]*\.\([^.]*\).*/\1/')%)));)) + $(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),\ @@ -246,7 +247,7 @@ dist: dist-$(archiveFormat) # Prevent make from removing any build targets. # -.SECONDARY: $(clean) +.SECONDARY: $(clean) .PHONY: all clean distclean install install-data install-exec .PHONY: install-desktop-entry diff --git a/README b/README index 0cab8cc..b993ffd 100644 --- a/README +++ b/README @@ -80,7 +80,7 @@ DESCRIPTION o Stick to the coding style of the source code files you edit. Follow the general style of method and variable naming, as well as white space formatting. In particular, use literal tabs with an assumed - tabstop of 4 characters. Also, try to limit line lengths to 75 + tabstop of 8 characters. Also, try to limit line lengths to 78 characters. o For legal reasons, don't include other peoples' code with your patch. diff --git a/TODO b/TODO index dc4b356..4ecad27 100644 --- a/TODO +++ b/TODO @@ -2,8 +2,8 @@ The roadmap and ticket tracker are available on the website: There are lists of goals and tasks on the website: -Roadmap: http://www.dogcows.com/yoink/roadmap -Ticket Tracker: http://www.dogcows.com/yoink/report/1 +Roadmap: http://www.dogcows.com/yoink/roadmap +Ticket Tracker: http://www.dogcows.com/yoink/report/1 Other than that, the itself code is documented with stuff that needs doing: diff --git a/build/arch/win32/makedeps.mk b/build/arch/win32/makedeps.mk index fbdbecd..0376615 100644 --- a/build/arch/win32/makedeps.mk +++ b/build/arch/win32/makedeps.mk @@ -18,11 +18,10 @@ # make -f deps.mk -j2 host=i486-mingw32 prefix=/usr/i486-mingw32 # sudo make install # -# A lot of temporary files and directories are downloaded or extracted to -# the current directory, so you may want to make from a clean directory. +# A lot of temporary files and directories are downloaded or extracted to the +# current directory, so you may want to make from a clean directory. # - host = i686-mingw32 prefix = /usr/i686-mingw32/usr @@ -50,9 +49,9 @@ endif ########################################################################### -BOOST = boost_1_46_1 -BOOST_CKSUM = 7375679575f4c8db605d426fc721d506 -BOOST_EXT = .tar.bz2 +BOOST = boost_1_46_1 +BOOST_CKSUM = 7375679575f4c8db605d426fc721d506 +BOOST_EXT = .tar.bz2 BOOST_VERSION = 1.46.1 $(BOOST)$(BOOST_EXT): @@ -69,7 +68,7 @@ install-$(BOOST): $(BOOST)$(BOOST_EXT) ########################################################################### -SDL = SDL-1.2.14 +SDL = SDL-1.2.14 SDL_CKSUM = e52086d1b508fa0b76c52ee30b55bec4 SDL_EXT = .tar.gz @@ -89,9 +88,9 @@ install-$(SDL): $(SDL) ########################################################################### -LIBOGG = libogg-1.2.2 +LIBOGG = libogg-1.2.2 LIBOGG_CKSUM = 5a9fcabc9a1b7c6f1cd75ddc78f36c56 -LIBOGG_EXT = .tar.gz +LIBOGG_EXT = .tar.gz $(LIBOGG)$(LIBOGG_EXT): $(call getdist,$@,http://downloads.xiph.org/releases/ogg/$@) @@ -109,7 +108,7 @@ install-$(LIBOGG): $(LIBOGG) ########################################################################### -LIBVORBIS = libvorbis-1.3.2 +LIBVORBIS = libvorbis-1.3.2 LIBVORBIS_CKSUM = c870b9bd5858a0ecb5275c14486d9554 LIBVORBIS_EXT = .tar.gz @@ -129,9 +128,9 @@ install-$(LIBVORBIS): $(LIBVORBIS) install-$(LIBOGG) ########################################################################### -OPENAL = openal-soft-1.13-bin +OPENAL = openal-soft-1.13-bin OPENAL_CKSUM = b545d3ebb8138cc581cd67f988638f43 -OPENAL_EXT = .zip +OPENAL_EXT = .zip OPENAL_VERSION = 1.13 define OPENAL_PCFILE @@ -167,9 +166,9 @@ install-$(OPENAL): $(OPENAL)$(OPENAL_EXT) ########################################################################### -ZLIB = zlib-1.2.5 -ZLIB_CKSUM = c735eab2d659a96e5a594c9e8541ad63 -ZLIB_EXT = .tar.gz +ZLIB = zlib-1.2.5 +ZLIB_CKSUM = c735eab2d659a96e5a594c9e8541ad63 +ZLIB_EXT = .tar.gz ZLIB_VERSION = 1.2.5 define ZLIB_PCFILE @@ -208,9 +207,9 @@ install-$(ZLIB): $(ZLIB) ########################################################################### -LIBPNG = libpng-1.5.2 +LIBPNG = libpng-1.5.2 LIBPNG_CKSUM = 31d448eb93a1646359a23f1b23434ab3 -LIBPNG_EXT = .tar.gz +LIBPNG_EXT = .tar.gz define LIBPNG_PATCH diff -ur libpng-1.5.2.orig/configure.pc libpng-1.5.2/configure.pc @@ -248,7 +247,7 @@ install-$(LIBPNG): $(LIBPNG) install-$(ZLIB) ########################################################################### -LUA = lua-5.1.4 +LUA = lua-5.1.4 LUA_CKSUM = d0870f2de55d59c1c8419f36e8fac150 LUA_EXT = .tar.gz diff --git a/build/arch/win32/rules.mk b/build/arch/win32/rules.mk index 0f5eae5..3e3c49d 100644 --- a/build/arch/win32/rules.mk +++ b/build/arch/win32/rules.mk @@ -1,17 +1,13 @@ + # -# Yoink -# Run this script to create a win32 package. -# -# You should typically only run this through the "portable" and "installer" -# makes targets in the package root directory. The build system will take -# care to pass the correct arguments. +# Rules to create win32 packages. # docs = AUTHORS COPYING README TODO libraries = libogg-0 libpng15 libvorbis-0 libvorbisfile-3 lua51 OpenAL32 SDL zlib1 -MAN2HTML = lua doc/man2html.lua -UNIX2DOS = arch/win32/unix2dos.sh +MAN2HTML = $${LUA:-lua} scripts/man2html.lua +UNIX2DOS = scripts/unix2dos.sh MAKENSIS = makensis stagedir = $(builddir)/$(tarname) diff --git a/build/config.lua b/build/config.lua index fa522cf..6a72455 100644 --- a/build/config.lua +++ b/build/config.lua @@ -71,8 +71,8 @@ end local arguments = parseArguments(unpack(arg)) local interactive = arguments["--interactive"] -local rules = arguments["--rules"] or "options.lua" -local configfile = arguments["--configfile"] or "config.mk" +local rules = arguments["--rules"] or "options.lua" +local configfile = arguments["--configfile"] or "config.mk" local printendmsg = arguments["--print-instructions"] local exportHeader = arguments["--export-header"] local exportTerms = arguments["--export-terms"] @@ -92,7 +92,9 @@ local function beginProcess(title, caption) return function(progress, caption) if progress ~= nil then - if 0.0 <= progress and progress <= 1.0 then progress = progress * 100 end + if 0.0 <= progress and progress <= 1.0 then + progress = progress * 100 + end return updater(progress, caption) end print() @@ -103,16 +105,12 @@ end local function loadDialog(name, configfile) local dialog local result, err = pcall(function() dialog = require "dialog" end) - if not result - then - printWarning(err) - return nil - end + if not result then printWarning(err) return nil end dialog.title = string.format("%s - %s Configuration", configfile, name) - printInfo = dialog.msgbox - printWarning = dialog.msgbox - printError = dialog.msgbox - beginProcess = dialog.gauge + printInfo = dialog.msgbox + printWarning = dialog.msgbox + printError = dialog.msgbox + beginProcess = dialog.gauge return dialog end @@ -185,20 +183,20 @@ local Option = util.class() --------------------------------------------------------------------------- function Option:__init(rule, lookup, objects) - self.name = rule.name + self.name = rule.name self.caption = rule.caption - self.help = rule.help - self.value = rule.value - self.symbol = rule.symbol + self.help = rule.help + self.value = rule.value + self.symbol = rule.symbol self.cmdline = rule.cmdline - self.config = rule.config - self.export = rule.export + self.config = rule.config + self.export = rule.export self.visible = rule.visible - self.check = rule.check - self.temp = rule.temp - self.before = rule.before - self.after = rule.after - self.lookup = lookup or {} + self.check = rule.check + self.temp = rule.temp + self.before = rule.before + self.after = rule.after + self.lookup = lookup or {} self.objects = objects or {} if type(self.check) == "function" then setfenv(self.check, self.lookup) end @@ -327,7 +325,6 @@ function Option:writeSymbol(fd) if self.symbol ~= nil and not self.temp then fd:write(util.align(self.symbol, "= " .. tostring(self.lookup[self.symbol]), 16) .. "\n") - --fd:write(string.format("%s\t= %s\n", self.symbol, tostring(self.lookup[self.symbol]))) end end @@ -339,7 +336,7 @@ end function Option:writeSedLine(fd) if self.export then - local value = self:toExpandedString():gsub("/", "\\/") + local value = self:toExpandedString():gsub("/", "\\/") local function writeLine(key) key = tostring(key):gsub("/", "\\/") fd:write(string.format("s/@%s@/%s/g\n", key, value)) @@ -398,11 +395,11 @@ function Option:printHelpLine() end function Option:getHelpText() - local value = self:toString() - local help = self.help or "No help available.\n" - local name = self.name or "Unnamed" + local value = self:toString() + local help = self.help or "No help available.\n" + local name = self.name or "Unnamed" local symbol = self:getSymbol() or "None" - local arg = self:getArg() or "None" + local arg = self:getArg() or "None" local problem = self:getProblem() if problem then problem = "\nProblem(s):\n" .. problem @@ -591,7 +588,7 @@ end function BooleanOption:writeCppLine(fd) if self.config then - local value = self.lookup[self.symbol] + local value = self.lookup[self.symbol] local function writeLine(key) -- Reverse the value if key starts with a bang. local value = value @@ -813,8 +810,7 @@ function GroupOption:showMenu(dialog) dialog.msgbox(value.name, value:getHelpText(), {["--no-collapse"] = true}) selected = value:getMenuItem() else - dialog.msgbox("No Help", - "Sorry, no help is available for this option.") + dialog.msgbox("No Help", "Sorry, no help is available for this option.") end else running = false @@ -964,8 +960,7 @@ if interactive then loadDialog(name, configfile) end options:convertDependenciesToDependants() checkSymbols(options:getObjects()) -if dialog -then +if dialog then local action = options:runMenu() if action == "exit" or action == "error" then @@ -975,8 +970,7 @@ then options:saveToFile(configfile) print("configuration saved to " .. configfile) end -elseif options:isValid() -then +elseif options:isValid() then options:saveToFile(configfile) else printError("Uh oh!", [[ diff --git a/build/dialog.c b/build/dialog.c index ee8a2a8..e4c76d7 100644 --- a/build/dialog.c +++ b/build/dialog.c @@ -1,13 +1,11 @@ -/*] Copyright (c) 2011, Charles McGarvey [******************************* +/*] Copyright (c) 2011, Charles McGarvey [********************************** **] All rights reserved. * -* vi:ts=4 sw=4 tw=75 -* * Distributable under the terms and conditions of the 2-clause BSD license; * see the file COPYING for a complete text of the license. * -**************************************************************************/ +*****************************************************************************/ #define LUA_DIALOG_NAME "dialog" #define LUA_DIALOG_VERSION "1.0" @@ -41,13 +39,12 @@ static void printarray(const char* argv[]) /** * Fork and execute a command with arguments and optionally get a file * descriptor connected to one of the child's own file descriptors. The - * process id of the child is returned, or -1 on error. If fd is not NULL, - * a pipe will be created and connected to *fd. If *fd is 0, then *fd will - * be set to a write file descriptor connected to the child's standard - * input. If *fd is not 0, then *fd will be set to a read file descriptor - * set connected to the specified file descriptor of the child. In either - * case, the caller has the responsibility to close fd when it is no longer - * needed. + * process id of the child is returned, or -1 on error. If fd is not NULL, a + * pipe will be created and connected to *fd. If *fd is 0, then *fd will be + * set to a write file descriptor connected to the child's standard input. If + * *fd is not 0, then *fd will be set to a read file descriptor set connected + * to the specified file descriptor of the child. In either case, the caller + * has the responsibility to close fd when it is no longer needed. */ static pid_t myexec(const char* command, char* const argv[], int* fd) { @@ -55,31 +52,24 @@ static pid_t myexec(const char* command, char* const argv[], int* fd) int p[2]; pid_t child; - if (fd) - { + if (fd) { if (pipe(p) != 0) return -1; parentFd = (*fd == 0); } - if (!(child = fork())) - { - if (fd) - { + if (!(child = fork())) { + if (fd) { close(p[parentFd]); if (dup2(p[!parentFd], *fd) == -1) _exit(127); } execv(command, argv); _exit(127); } - if (child == -1) - { + if (child == -1) { if (parentFd != -1) - { close(p[0]); close(p[1]); - } return -1; } - if (parentFd != -1) - { + if (parentFd != -1) { close(p[!parentFd]); *fd = p[parentFd]; } @@ -99,8 +89,8 @@ static int mywait(pid_t pid) /** - * Read from a file descriptor until EOF and push contents to the top of - * the Lua stack. Closes the file descriptor afterward. + * Read from a file descriptor until EOF and push contents to the top of the + * Lua stack. Closes the file descriptor afterward. */ static void pushstream(lua_State* L, int fd) { @@ -109,8 +99,7 @@ static void pushstream(lua_State* L, int fd) char buffer[BUFSIZ]; ssize_t bytes; - while ((bytes = read(fd, buffer, sizeof(buffer)))) - { + while ((bytes = read(fd, buffer, sizeof(buffer)))) { if (bytes == -1) break; luaL_addlstring(&B, buffer, bytes); } @@ -125,8 +114,7 @@ static void pushstream(lua_State* L, int fd) static void writelstring(int fd, const char* str, size_t len) { ssize_t bytes; - while ((bytes = write(fd, str, len))) - { + while ((bytes = write(fd, str, len))) { if (bytes == -1) break; str += bytes; len -= bytes; @@ -168,8 +156,7 @@ static void addstrings(const char* argv[], ...) int i; for (i = 0; argv[i]; ++i); va_start(ap, argv); const char* arg = va_arg(ap, const char*); - while (arg) - { + while (arg) { argv[i++] = arg; arg = va_arg(ap, const char*); } @@ -197,8 +184,7 @@ static void addcommand(lua_State* L, const char* argv[]) lua_getfield(L, -1, "command"); lua_getfield(L, -2, "title"); addstrings(argv, lua_tostring(L, -2), NULL); - if (lua_isstring(L, -1)) - { + if (lua_isstring(L, -1)) { addstrings(argv, "--backtitle", lua_tostring(L, -1), NULL); } lua_pop(L, 3); @@ -261,8 +247,7 @@ static int addextra(lua_State* L, const char* argv[], int n) { if (!lua_istable(L, n)) return 0; lua_pushnil(L); - while (lua_next(L, n)) - { + while (lua_next(L, n)) { addstrings(argv, lua_tostring(L, -2), NULL); if (lua_isstring(L, -1)) addstrings(argv, lua_tostring(L, -1), NULL); lua_pop(L, 1); @@ -296,29 +281,24 @@ static void addmenuitems(lua_State* L, const char* argv[]) if (searchstrings(argv, "--item-help") != -1) fields = 3; if (!lua_istable(L, 3)) luaL_argerror(L, 3, "menu items"); - int i; for (i = 1;; ++i) - { + int i; for (i = 1;; ++i) { lua_pushinteger(L, i); lua_gettable(L, 3); - if (lua_isnil(L, -1)) - { + if (lua_isnil(L, -1)) { lua_pop(L, 1); break; } - else if (lua_istable(L, -1)) - { + else if (lua_istable(L, -1)) { int subtable = lua_gettop(L); lua_pushnil(L); - int j; for (j = 0; j < fields; ++j) - { + int j; for (j = 0; j < fields; ++j) { if (!lua_next(L, subtable)) luaL_argerror(L, 3, "not enough fields"); addstrings(argv, lua_tostring(L, -1), NULL); lua_pop(L, 1); } lua_pop(L, 1); } - else - { + else { if (fields == 2) addstrings(argv, "", "", NULL); else addstrings(argv, "", "", "", NULL); } @@ -356,8 +336,7 @@ static void closegauge(lua_State* L) { lua_getfield(L, LUA_REGISTRYINDEX, "dialog_gauge_pid"); lua_getfield(L, LUA_REGISTRYINDEX, "dialog_gauge_fd"); - if (!lua_isnumber(L, -2) || !lua_isnumber(L, -1)) - { + if (!lua_isnumber(L, -2) || !lua_isnumber(L, -1)) { lua_pop(L, 2); return; } @@ -385,8 +364,7 @@ static void closegauge(lua_State* L) */ static int updategauge(lua_State* L) { - if (!lua_isnumber(L, 1)) - { + if (!lua_isnumber(L, 1)) { closegauge(L); return 0; } @@ -399,15 +377,13 @@ static int updategauge(lua_State* L) if (0.0 <= percent && percent <= 1.0) percent *= 100.0; lua_pushinteger(L, (lua_Integer)percent); lua_replace(L, 1); - if (lua_isstring(L, 2)) - { + if (lua_isstring(L, 2)) { writestring(fd, "XXX"); tostream(L, 1, fd); tostream(L, 2, fd); writestring(fd, "XXX"); } - else - { + else { tostream(L, 1, fd); } return 0; @@ -530,32 +506,28 @@ static int dialog_yesno(lua_State* L) LUALIB_API int luaopen_dialog(lua_State* L) { const struct luaL_Reg dialog_funcs[] = { - {"gauge", dialog_gauge}, + {"gauge", dialog_gauge}, {"inputbox", dialog_inputbox}, - {"menu", dialog_menu}, - {"msgbox", dialog_msgbox}, - {"yesno", dialog_yesno}, + {"menu", dialog_menu}, + {"msgbox", dialog_msgbox}, + {"yesno", dialog_yesno}, {NULL, NULL} }; luaL_register(L, LUA_DIALOG_NAME, dialog_funcs); const char* names[] = {getenv("DIALOG"), "dialog", "cdialog"}; - int i; for (i = 0; i < 3; ++i) - { - if (names[i]) - { + int i; for (i = 0; i < 3; ++i) { + if (names[i]) { char* path = strdup(getenv("PATH")); char* token; char** paths = &path; - while ((token = strsep(paths, ":"))) - { + while ((token = strsep(paths, ":"))) { luaL_Buffer B; luaL_buffinit(L, &B); luaL_addstring(&B, token); luaL_addstring(&B, "/"); luaL_addstring(&B, names[i]); luaL_pushresult(&B); - if (access(lua_tostring(L, -1), X_OK) == 0) - { + if (access(lua_tostring(L, -1), X_OK) == 0) { lua_setfield(L, -2, "command"); goto break2; } @@ -564,7 +536,7 @@ LUALIB_API int luaopen_dialog(lua_State* L) free(path); } } - luaL_error(L, "cannot find dialog executable in the path; set DIALOG"); + luaL_error(L, "cannot find dialog executable in the path; set DIALOG"); break2: diff --git a/configure b/configure index 09df45f..27d2124 100755 --- a/configure +++ b/configure @@ -11,7 +11,7 @@ die () { [ -f build/config.lua ] || die 1 <<"END" You must first `cd' to the project directory root where the Makefile is. -There is no support for out-of-tree builds. +There is no support for out-of-source-tree builds. END LUA=${LUA:-lua} @@ -30,5 +30,3 @@ END export PATH="./build:$PATH" exec "$LUA" build/config.lua "$@" -L./build -# vi:ts=4 - diff --git a/data/rules.mk b/data/rules.mk index 1968532..64f7659 100644 --- a/data/rules.mk +++ b/data/rules.mk @@ -4,10 +4,10 @@ # pkgdatadir_$d := $(shell find $d -name "*.ac" \ - -o -name "*.lua" \ - -o -name "*.gz" \ - -o -name "*.ogg" \ - -o -name "*.png") $d/yoinkrc + -o -name "*.lua" \ + -o -name "*.gz" \ + -o -name "*.ogg" \ + -o -name "*.png") $d/yoinkrc # Install resource files to pkgdatadir. desktop_$b := $b/yoink.desktop # Install desktop entry file. diff --git a/data/scenes/Classic.lua b/data/scenes/Classic.lua index b1364b0..c60f68b 100644 --- a/data/scenes/Classic.lua +++ b/data/scenes/Classic.lua @@ -68,12 +68,13 @@ Event = {} do local mysound = yoink.sound("Explosion") - --local mysound = yoink.sound() - --mysound:sample("Explosion") + mysound = yoink.sound() + mysound:sample("Pop") local count = 0 function Event.Think() if count % 300 == 0 then - --mysound:play() + mysound:play() + LogDebug("Hello world!") end count = count + 1 end diff --git a/doc/yoink_readme.7 b/doc/yoink_readme.7 index e61ddf6..c35ae2d 100644 --- a/doc/yoink_readme.7 +++ b/doc/yoink_readme.7 @@ -108,7 +108,7 @@ that, please observe the following: .It Stick to the coding style of the source code files you edit. Follow the general style of method and variable naming, as well as white space -formatting. In particular, use literal tabs with an assumed tabstop of 4 +formatting. In particular, use literal tabs with an assumed tabstop of 8 characters. Also, try to limit line lengths to 75 characters. .It For legal reasons, don't include other peoples' code with your patch. You diff --git a/options.lua b/options.lua index 30d1c75..4839144 100644 --- a/options.lua +++ b/options.lua @@ -102,15 +102,15 @@ return string.format("%s %s", project, version), check = function(value) if value == "" then - CC = "gcc" - CXX = "g++" - AR = "ar" + CC = "gcc" + CXX = "g++" + AR = "ar" RANLIB = "ranlib" WINDRES = "windres" else - CC = value .. "-gcc" - CXX = value .. "-g++" - AR = value .. "-ar" + CC = value .. "-gcc" + CXX = value .. "-g++" + AR = value .. "-ar" RANLIB = value .. "-ranlib" WINDRES = value .. "-windres" end @@ -314,11 +314,11 @@ If in doubt, say No. check = function(value) if value then - PKG_CFLAGS = PKG_CFLAGS:setFlag("-pg") - PKG_LDFLAGS = PKG_LDFLAGS:setFlag("-pg") + PKG_CFLAGS = PKG_CFLAGS:setFlag("-pg") + PKG_LDFLAGS = PKG_LDFLAGS:setFlag("-pg") else - PKG_CFLAGS = PKG_CFLAGS:unsetFlag("-pg") - PKG_LDFLAGS = PKG_LDFLAGS:unsetFlag("-pg") + PKG_CFLAGS = PKG_CFLAGS:unsetFlag("-pg") + PKG_LDFLAGS = PKG_LDFLAGS:unsetFlag("-pg") end return value end @@ -351,10 +351,8 @@ without these extra codepaths. If in doubt, say No. ]], check = function(value) - if value - then + if value then CFLAGS = CFLAGS:setFlag("-Wall", "-g") - CFLAGS = CFLAGS:replaceFlag("%-O%d?", "-O0") end return value end @@ -592,6 +590,3 @@ If in doubt, say None. } } - --- vi:ft=lua - diff --git a/scripts/man2html.lua b/scripts/man2html.lua index e33a126..c7663c5 100755 --- a/scripts/man2html.lua +++ b/scripts/man2html.lua @@ -18,13 +18,13 @@ end ----- function die(...) print("die:", ...); os.exit(1) end -function isReadable(file) return os.execute("test -r "..file) == 0 end +function readable(file) return os.execute("test -r "..file) == 0 end arg.hideEmail = false arg.output = "yoink.html" arg.input = "yoink.6" -if not isReadable(arg.input) then arg.input = "build/doc/yoink.6" end +if not readable(arg.input) then arg.input = "build/doc/yoink.6" end do local t = { @@ -42,7 +42,11 @@ do showhelp(); os.exit(1) end skip = t[v](args, i) - if tonumber(skip) then skip = skip + 1 else skip = 1 end + if tonumber(skip) then + skip = skip + 1 + else + skip = 1 + end end skip = skip - 1 end @@ -51,10 +55,10 @@ end parseArgs(arg) filters = { - function(t) -- 1. Edit page title + function(t) -- 1. Edit page title return t:gsub("().*()", "%1Yoink Manual%2") end, - function(t) -- 2. Insert footer before + function(t) -- 2. Insert footer before return t:gsub("", [[

This manual page was generated on ]]..os.date("%d %b %Y")..[[. diff --git a/build/arch/win32/unix2dos.sh b/scripts/unix2dos.sh similarity index 74% rename from build/arch/win32/unix2dos.sh rename to scripts/unix2dos.sh index c3ee7a8..41e4085 100755 --- a/build/arch/win32/unix2dos.sh +++ b/scripts/unix2dos.sh @@ -5,11 +5,11 @@ # An implementation of unix2dos using sed. # -if [ -f "$1" ]; +if [ -f "$1" ] then TMPFILE="$1.$$" sed 's/\r*$/\r/' "$1" >$TMPFILE - if [ ! "$2" ]; + if [ ! "$2" ] then mv -f "$TMPFILE" "$1" else @@ -18,7 +18,7 @@ then rm -f "$TMPFILE" else echo "`basename $0` infile [outfile]" - echo " convert a file from unix to dos file format" + echo " convert a text file from unix to dos line-endings" exit 1 fi diff --git a/src/Animation.cc b/src/Animation.cc index a9710ce..5ab26d2 100644 --- a/src/Animation.cc +++ b/src/Animation.cc @@ -1,13 +1,11 @@ -/*] Copyright (c) 2009-2010, Charles McGarvey [************************** +/*] Copyright (c) 2009-2011, Charles McGarvey [***************************** **] All rights reserved. * -* vi:ts=4 sw=4 tw=75 -* * Distributable under the terms and conditions of the 2-clause BSD license; * see the file COPYING for a complete text of the license. * -**************************************************************************/ +*****************************************************************************/ #include #include @@ -22,48 +20,44 @@ /** - * The collection of nested animation classes. The animation - * implementation consists of an impl class which is allocated and - * initialized with the interface object. This class contains the specific - * fields which are required to run a single instance of an animation. The - * sequence data is loaded in a different class which can be shared amongst - * multiple animation implementation instances. + * The collection of nested animation classes. The animation implementation + * consists of an impl class which is allocated and initialized with the + * interface object. This class contains the specific fields which are + * required to run a single instance of an animation. The sequence data is + * loaded in a different class which can be shared amongst multiple animation + * implementation instances. */ - class Animation::impl { public: /** * Contains "global" animation data for the various animations which - * get loaded. This is a mippleton, so it will be shared amongst any + * get loaded. This is a manager, so it will be shared amongst any * animation which wants to use these loaded sequences. */ - class Data : public moof::manager { public: /** - * A frame of an animation sequence. A frame is merely an index - * which presumably represents a "slide" or tile which should be - * displayed, and the duration that is how long the slide will be - * shown. + * A frame of an animation sequence. A frame is merely an + * index which presumably represents a "slide" or tile which + * should be displayed, and the duration that is how long the + * slide will be shown. */ - class Frame { public: - unsigned mIndex; ///< Frame index. - moof::scalar mDuration; ///< Frame duration. + unsigned mIndex; ///< Frame index. + moof::scalar mDuration; ///< Frame duration. /** - * Construction is initialization. The frame data is loaded - * from a frame map which is probably loaded within an - * animation file. + * Construction is initialization. The frame data is + * loaded from a frame map which is probably loaded + * within an animation file. */ - Frame(const moof::script::slot& table) : mIndex(0), mDuration(1.0) @@ -73,28 +67,26 @@ public: } }; - /** - * A sequence is just a few attributes and a list of frames in the - * order that they should be played. + * A sequence is just a few attributes and a list of frames in + * the order that they should be played. */ - class Sequence { public: std::vector mFrames; ///< List of frames. - moof::scalar mDelay; ///< Scale frame durations. - bool mLoop; ///< Does the sequence repeat? - std::string mNext; ///< Next sequence name. + moof::scalar mDelay; ///< Scale frame durations. + bool mLoop; ///< Does the sequence repeat? + std::string mNext; ///< Next sequence name. /** - * Construction is initialization. The constructor loads - * sequence data from the sequence map, presumably loaded from - * an animation file. The rest of the loading takes place in - * the frame's constructor which loads each individual frame. + * Construction is initialization. The constructor + * loads sequence data from the sequence map, + * presumably loaded from an animation file. The rest + * of the loading takes place in the frame's + * constructor which loads each individual frame. */ - Sequence(const moof::script::slot& table) : mDelay(0.0), mLoop(true) @@ -106,35 +98,27 @@ public: // TODO - sequence class/type not yet implemented moof::script::slot frameTable = table.push_field("frames"); - if (frameTable.is_table()) - { + if (frameTable.is_table()) { int max = frameTable.length(); - for (int index = 1; index <= max; ++index) - { + for (int index = 1; index <= max; ++index) { moof::script::slot top = frameTable.push_field(index); if (top.is_table()) - { mFrames.push_back(Frame(top)); - } else - { moof::log_warning << "invalid frame at index " << index << std::endl; - } } } frameTable.remove(); } }; - /** * Starts loading a file with animation data. Such a file is * formatted as a map of named sequences. The sequence * constructor loads each individual sequence. */ - void init(const std::string& name) { moof::script script; @@ -144,8 +128,7 @@ public: moof::log::import(script); importAnimationBindings(script); - if (script.do_file(path) != moof::script::success) - { + if (script.do_file(path) != moof::script::success) { std::string str; script[-1].get(str); moof::log_warning(str); @@ -165,12 +148,10 @@ public: return 0; } - void importAnimationBindings(moof::script& script) { script.import_function("DefineSequence", - boost::bind(&Data::defineSequence, - this, _1)); + boost::bind(&Data::defineSequence, this, _1)); script.globals().set_field("ATTACK", 1); script.globals().set_field("CHARGE", 2); @@ -181,15 +162,12 @@ public: script.globals().set_field("STAND", 7); } - std::map mSequences; ///< List of sequences. }; - /** * Construction is intialization. */ - impl(const std::string& name) : mData(Data::instance(name)), mCurrentSequence(0), @@ -198,59 +176,50 @@ public: mTimeAccum(0), mFrameDuration(0) {} - /** * Sets up the animation classes to "play" a named sequence. If * another sequence was active, it will be replaced. Future updates * will progress the new sequence. */ - void startSequence(const std::string& name) { std::map::iterator it; it = mData->mSequences.find(name); - if (it != mData->mSequences.end()) - { + if (it != mData->mSequences.end()) { mCurrentSequence = &(*it).second; mFrameCounter = 0; mFrameIndex = mCurrentSequence->mFrames[0].mIndex; mTimeAccum = 0.0; mFrameDuration = mCurrentSequence->mDelay * - mCurrentSequence->mFrames[0].mDuration; + mCurrentSequence->mFrames[0].mDuration; } } /** * Updates or progresses the animation sequence. If the time interval - * surpasses the duration of the current frame, a new frame becomes the - * current frame. If the last frame of a sequence expires, the active - * sequence will switch automatically to the designated "next" + * surpasses the duration of the current frame, a new frame becomes + * the current frame. If the last frame of a sequence expires, the + * active sequence will switch automatically to the designated "next" * sequence, or if none is specified but the sequence is set to loop, * the first frame of the sequence will become the current frame, and * the animation essentially starts over again. */ - void update(moof::scalar t, moof::scalar dt) { if (!mCurrentSequence) return; mTimeAccum += dt; - if (mTimeAccum >= mFrameDuration) - { - if (++mFrameCounter >= mCurrentSequence->mFrames.size()) - { - if (!mCurrentSequence->mNext.empty()) - { + if (mTimeAccum >= mFrameDuration) { + if (++mFrameCounter >= mCurrentSequence->mFrames.size()) { + if (!mCurrentSequence->mNext.empty()) { startSequence(mCurrentSequence->mNext); } - else if (mCurrentSequence->mLoop) - { + else if (mCurrentSequence->mLoop) { mFrameCounter = 0; } - else - { + else { mFrameCounter--; mCurrentSequence = 0; } @@ -263,21 +232,19 @@ public: } } - boost::shared_ptr mData; ///< Internal data. + boost::shared_ptr mData; ///< Internal data. - Data::Sequence* mCurrentSequence; ///< Active sequence. - unsigned mFrameCounter; ///< Current frame. - unsigned mFrameIndex; ///< Index of current frame. - moof::scalar mTimeAccum; ///< Time accumulation. - moof::scalar mFrameDuration; ///< Scaled frame duration. + Data::Sequence* mCurrentSequence; ///< Active sequence. + unsigned mFrameCounter; ///< Current frame. + unsigned mFrameIndex; ///< Index of current frame. + moof::scalar mTimeAccum; ///< Time accumulation. + moof::scalar mFrameDuration; ///< Scaled frame duration. }; - Animation::Animation(const std::string& name) : // pass through impl_(new Animation::impl(name)) {} - void Animation::startSequence(const std::string& name) { // pass through @@ -290,12 +257,10 @@ void Animation::update(moof::scalar t, moof::scalar dt) impl_->update(t, dt); } - /** * Gets the index for the current frame. This is presumably called by some * drawing code which will draw the correct current frame. */ - unsigned Animation::getFrame() const { return impl_->mFrameIndex; diff --git a/src/Animation.hh b/src/Animation.hh index 97e916d..c8cdca8 100644 --- a/src/Animation.hh +++ b/src/Animation.hh @@ -1,13 +1,11 @@ -/*] Copyright (c) 2009-2010, Charles McGarvey [************************** +/*] Copyright (c) 2009-2011, Charles McGarvey [***************************** **] All rights reserved. * -* vi:ts=4 sw=4 tw=75 -* * Distributable under the terms and conditions of the 2-clause BSD license; * see the file COPYING for a complete text of the license. * -**************************************************************************/ +*****************************************************************************/ #ifndef _ANIMATION_HH_ #define _ANIMATION_HH_ @@ -34,7 +32,6 @@ typedef boost::shared_ptr AnimationP; * is determined. This class is generic enough that a frame can mean just * about anything to whatever drawing context is used to render the frame. */ - class Animation { public: @@ -46,13 +43,11 @@ public: return AnimationP(new Animation(name)); } - void startSequence(const std::string& name); void update(moof::scalar t, moof::scalar dt); unsigned getFrame() const; - private: class impl; diff --git a/src/Character.cc b/src/Character.cc index 3cae680..c6a47f9 100644 --- a/src/Character.cc +++ b/src/Character.cc @@ -1,13 +1,11 @@ -/*] Copyright (c) 2009-2010, Charles McGarvey [************************** +/*] Copyright (c) 2009-2011, Charles McGarvey [***************************** **] All rights reserved. * -* vi:ts=4 sw=4 tw=75 -* * Distributable under the terms and conditions of the 2-clause BSD license; * see the file COPYING for a complete text of the license. * -**************************************************************************/ +*****************************************************************************/ #include @@ -42,6 +40,7 @@ private: moof::vector2 location; }; + class ResistanceForce { public: @@ -85,7 +84,6 @@ Character::Character(const std::string& name) : prev_state_ = state_; } - void Character::update(moof::scalar t, moof::scalar dt) { moof::rigid_body2::update(t, dt); // update physics @@ -103,7 +101,6 @@ void Character::update(moof::scalar t, moof::scalar dt) tilemap.tile(frame); } - void Character::draw(moof::scalar alpha) const { moof::state2 state = moof::rigid_body2::state(alpha); @@ -121,7 +118,6 @@ void Character::draw(moof::scalar alpha) const tilemap.draw(coords); } - /*int Character::getOctant(const moof::Aabb<3>& aabb) const { int octantNum = -1; @@ -232,7 +228,6 @@ void Character::draw(moof::scalar alpha) const } */ - void Character::addImpulse(moof::vector2 impulse) { state_.momentum += impulse; diff --git a/src/Character.hh b/src/Character.hh index bdbdb29..bb2d5e6 100644 --- a/src/Character.hh +++ b/src/Character.hh @@ -1,13 +1,11 @@ -/*] Copyright (c) 2009-2010, Charles McGarvey [************************** +/*] Copyright (c) 2009-2011, Charles McGarvey [***************************** **] All rights reserved. * -* vi:ts=4 sw=4 tw=75 -* * Distributable under the terms and conditions of the 2-clause BSD license; * see the file COPYING for a complete text of the license. * -**************************************************************************/ +*****************************************************************************/ #ifndef _CHARACTER_HH_ #define _CHARACTER_HH_ @@ -29,12 +27,10 @@ class Character; typedef boost::shared_ptr CharacterP; - /** * Parent class of animate objects with "personalities." This basically * includes the heroine herself and the bad guys. */ - class Character : public moof::rigid_body2 { public: @@ -52,7 +48,7 @@ public: //virtual int getOctant(const moof::Aabb<3>& aabb) const; moof::sprite tilemap; - Animation animation; + Animation animation; }; diff --git a/src/GameState.hh b/src/GameState.hh index 66b7a7d..ecf9e05 100644 --- a/src/GameState.hh +++ b/src/GameState.hh @@ -1,13 +1,11 @@ -/*] Copyright (c) 2009-2010, Charles McGarvey [************************** +/*] Copyright (c) 2009-2011, Charles McGarvey [***************************** **] All rights reserved. * -* vi:ts=4 sw=4 tw=75 -* * Distributable under the terms and conditions of the 2-clause BSD license; * see the file COPYING for a complete text of the license. * -**************************************************************************/ +*****************************************************************************/ #ifndef _GAMESTATE_HH_ #define _GAMESTATE_HH_ @@ -33,15 +31,15 @@ struct GameState { - moof::script script; + moof::script script; std::vector sceneList; - HeroineP heroine; - SceneP scene; + HeroineP heroine; + SceneP scene; - moof::lerp_scalar interp; + moof::lerp_scalar interp; - moof::camera camera; + moof::camera camera; }; diff --git a/src/Heroine.cc b/src/Heroine.cc index a206918..4ca4ce8 100644 --- a/src/Heroine.cc +++ b/src/Heroine.cc @@ -1,88 +1,87 @@ -/*] Copyright (c) 2009-2010, Charles McGarvey [************************** +/*] Copyright (c) 2009-2011, Charles McGarvey [***************************** **] All rights reserved. * -* vi:ts=4 sw=4 tw=75 -* * Distributable under the terms and conditions of the 2-clause BSD license; * see the file COPYING for a complete text of the license. * -**************************************************************************/ +*****************************************************************************/ #include #include #include "Heroine.hh" + Heroine::Heroine() : Character("Heroine") {} - void Heroine::update(moof::scalar t, moof::scalar dt) { Character::update(t, dt); - moof::vector3 at(0.0, 0.0, 0.0); - const moof::vector3 up(0.0, 1.0, 0.0); + moof::vector3 at(0.0, 0.0, 0.0); + const moof::vector3 up(0.0, 1.0, 0.0); if (state_.velocity[0] < 0.0) at[0] = -1.0; - else at[0] = 1.0; + else at[0] = 1.0; moof::sound::listener_position(moof::promote(state_.position)); moof::sound::listener_velocity(moof::promote(state_.velocity)); moof::sound::listener_orientation(at, up); } - bool Heroine::handle_event(const moof::event& event) { moof::scalar force = 40.0; switch (event.type) { - case SDL_KEYDOWN: - if (event.key.keysym.sym == SDLK_a) - { - state_.force += moof::vector2(-force, 0.0); - return true; - } - else if (event.key.keysym.sym == SDLK_d) - { - state_.force += moof::vector2(force, 0.0); - return true; - } - else if (event.key.keysym.sym == SDLK_s) - { - state_.force += moof::vector2(0.0, -force); - return true; - } - else if (event.key.keysym.sym == SDLK_w) - { - state_.force += moof::vector2(0.0, force); - return true; - } + case SDL_KEYDOWN: + if (event.key.keysym.sym == SDLK_a) + { + state_.force += moof::vector2(-force, 0.0); + return true; + } + else if (event.key.keysym.sym == SDLK_d) + { + state_.force += moof::vector2(force, 0.0); + return true; + } + else if (event.key.keysym.sym == SDLK_s) + { + state_.force += moof::vector2(0.0, -force); + return true; + } + else if (event.key.keysym.sym == SDLK_w) + { + state_.force += moof::vector2(0.0, force); + return true; + } + break; - case SDL_KEYUP: - if (event.key.keysym.sym == SDLK_a) - { - state_.force += moof::vector2(force, 0.0); - return true; - } - else if (event.key.keysym.sym == SDLK_d) - { - state_.force += moof::vector2(-force, 0.0); - return true; - } - else if (event.key.keysym.sym == SDLK_s) - { - state_.force += moof::vector2(0.0, force); - return true; - } - else if (event.key.keysym.sym == SDLK_w) - { - state_.force += moof::vector2(0.0, -force); - return true; - } + case SDL_KEYUP: + if (event.key.keysym.sym == SDLK_a) + { + state_.force += moof::vector2(force, 0.0); + return true; + } + else if (event.key.keysym.sym == SDLK_d) + { + state_.force += moof::vector2(-force, 0.0); + return true; + } + else if (event.key.keysym.sym == SDLK_s) + { + state_.force += moof::vector2(0.0, force); + return true; + } + else if (event.key.keysym.sym == SDLK_w) + { + state_.force += moof::vector2(0.0, -force); + return true; + } + break; } return false; } diff --git a/src/Heroine.hh b/src/Heroine.hh index 6eb5a54..4cbf8b1 100644 --- a/src/Heroine.hh +++ b/src/Heroine.hh @@ -1,13 +1,11 @@ -/*] Copyright (c) 2009-2010, Charles McGarvey [************************** +/*] Copyright (c) 2009-2011, Charles McGarvey [***************************** **] All rights reserved. * -* vi:ts=4 sw=4 tw=75 -* * Distributable under the terms and conditions of the 2-clause BSD license; * see the file COPYING for a complete text of the license. * -**************************************************************************/ +*****************************************************************************/ #ifndef _HEROINE_HH_ #define _HEROINE_HH_ @@ -22,11 +20,9 @@ class Heroine; typedef boost::shared_ptr HeroineP; - /** * The protagonist. */ - class Heroine : public Character { public: diff --git a/src/Hud.cc b/src/Hud.cc index cc25dd5..dde53ee 100644 --- a/src/Hud.cc +++ b/src/Hud.cc @@ -1,13 +1,11 @@ -/*] Copyright (c) 2009-2010, Charles McGarvey [************************** +/*] Copyright (c) 2009-2011, Charles McGarvey [***************************** **] All rights reserved. * -* vi:ts=4 sw=4 tw=75 -* * Distributable under the terms and conditions of the 2-clause BSD license; * see the file COPYING for a complete text of the license. * -**************************************************************************/ +*****************************************************************************/ #include #include @@ -62,11 +60,8 @@ void ProgressBar::setProgress(moof::scalar progress) void ProgressBar::draw(moof::scalar alpha) const { - if (moof::is_equal(mProgress, 0.0)) - { - // don't draw anything if the progress is 0% - return; - } + if (moof::is_equal(mProgress, 0.0)) return; + // don't draw anything if the progress is 0% glColor4f(1.0f, 1.0f, 1.0f, 0.85f); mTilemap.bind(); @@ -113,13 +108,12 @@ Hud::Hud(GameState& state) : resize(video->width(), video->height()); } - void Hud::resize(int width, int height) { moof::matrix_orthographic_RH(mProjection, SCALAR(0.0), - moof::scalar(width), SCALAR(0.0), - moof::scalar(height), - SCALAR(1.0), SCALAR(-1.0), moof::z_clip_neg_one); + moof::scalar(width), SCALAR(0.0), + moof::scalar(height), SCALAR(1.0), + SCALAR(-1.0), moof::z_clip_neg_one); // position the two progress bars at the top-left of the screen mBar1.resize(moof::rectangle(20, height - 51, 0.7 * width, height - 3)); @@ -129,7 +123,6 @@ void Hud::resize(int width, int height) setBar2Progress(0.0); } - void Hud::update(moof::scalar t, moof::scalar dt) { state_.interp.update(t, dt); @@ -167,20 +160,20 @@ bool Hud::handle_event(const moof::event& event) { switch (event.type) { - case SDL_KEYUP: - if (event.key.keysym.sym == SDLK_h) - { - // don't want the hud anymore - //parent().remove_child(this); - - moof::log_warning("okay bye bye hud"); - return true; - } - break; - - case SDL_VIDEORESIZE: - resize(event.resize.w, event.resize.h); - break; + case SDL_KEYUP: + if (event.key.keysym.sym == SDLK_h) + { + // don't want the hud anymore + //parent().remove_child(this); + + moof::log_warning("okay bye bye hud"); + return true; + } + break; + + case SDL_VIDEORESIZE: + resize(event.resize.w, event.resize.h); + break; } return false; diff --git a/src/Hud.hh b/src/Hud.hh index 30c0136..05882ed 100644 --- a/src/Hud.hh +++ b/src/Hud.hh @@ -1,13 +1,11 @@ -/*] Copyright (c) 2009-2010, Charles McGarvey [************************** +/*] Copyright (c) 2009-2011, Charles McGarvey [***************************** **] All rights reserved. * -* vi:ts=4 sw=4 tw=75 -* * Distributable under the terms and conditions of the 2-clause BSD license; * see the file COPYING for a complete text of the license. * -**************************************************************************/ +*****************************************************************************/ #ifndef _HUD_HH_ #define _HUD_HH_ @@ -25,6 +23,7 @@ #include "GameState.hh" +// forward declarations class rectangle; // TODO this stuff is still just hacked up diff --git a/src/Main.cc b/src/Main.cc index a674bbc..8b01163 100644 --- a/src/Main.cc +++ b/src/Main.cc @@ -1,26 +1,26 @@ -/*] Copyright (c) 2009-2010, Charles McGarvey [************************** +/*] Copyright (c) 2009-2011, Charles McGarvey [***************************** **] All rights reserved. * -* vi:ts=4 sw=4 tw=75 -* * Distributable under the terms and conditions of the 2-clause BSD license; * see the file COPYING for a complete text of the license. * -**************************************************************************/ +*****************************************************************************/ +#if HAVE_CONFIG_H #include "config.h" +#endif -#include // atexit +#include // atexit #include #include #include #include -#if PLATFORM_WIN32 -inline int isatty(int dummy) { return 0; } -#else +#if PLATFORM_POSIX #include +#else +inline int isatty(int dummy) { return 0; } #endif #include @@ -53,7 +53,6 @@ Main::Main(moof::settings& settings) : #endif } - void Main::update(moof::scalar t, moof::scalar dt) { yoink.update(t, dt); @@ -78,35 +77,31 @@ void Main::handle_event(const moof::event& event) switch (event.type) { - case SDL_KEYUP: - - if (event.key.keysym.sym == SDLK_f) - { - moof::video::current()->toggle_fullscreen(); - } - else if (event.key.keysym.sym == SDLK_l) - { - moof::video::current()->toggle_cursor_captured(); - moof::video::current()->toggle_cursor_visible(); - } - else if (event.key.keysym.sym == SDLK_ESCAPE) - { - stop(); - } - break; - - case SDL_VIDEORESIZE: - - glViewport(0, 0, event.resize.w, event.resize.h); - break; - - case SDL_QUIT: - + case SDL_KEYUP: + if (event.key.keysym.sym == SDLK_f) + { + moof::video::current()->toggle_fullscreen(); + } + else if (event.key.keysym.sym == SDLK_l) + { + moof::video::current()->toggle_cursor_captured(); + moof::video::current()->toggle_cursor_visible(); + } + else if (event.key.keysym.sym == SDLK_ESCAPE) + { stop(); + } + break; + + case SDL_VIDEORESIZE: + glViewport(0, 0, event.resize.w, event.resize.h); + break; + + case SDL_QUIT: + stop(); } } - std::string Main::search_paths() { // Add search paths; they should be searched in this order: @@ -152,7 +147,6 @@ std::string Main::config_paths() return path; } - void Main::setup_opengl() { glEnable(GL_TEXTURE_2D); @@ -187,27 +181,26 @@ void Main::setup_opengl() glLightfv(GL_LIGHT0, GL_SPECULAR, spec); } - void Main::print_usage() { std::cout << "Usage: " - << PACKAGE" [-h|--help] [-i|--info] [OPTION=VALUE]..." - << std::endl - << "The alien-smashing action game." << std::endl - << std::endl - << "Options:" << std::endl - << " -h, --help" << std::endl - << " show this help and exit" << std::endl - << " -i, --info" << std::endl - << " show version and build information" << std::endl - << " detail=1|2|3" << std::endl - << " the level of detail of game scenes" << std::endl - << " fullscreen=true|false" << std::endl - << " if true, uses the entire display" << std::endl - << " framerate=num" << std::endl - << " number of frames to draw per second" << std::endl - << std::endl - << "See documentation for more options." << std::endl; + << PACKAGE" [-h|--help] [-i|--info] [OPTION=VALUE]..." + << std::endl + << "The alien-smashing action game." << std::endl + << std::endl + << "Options:" << std::endl + << " -h, --help" << std::endl + << " show this help and exit" << std::endl + << " -i, --info" << std::endl + << " show version and build information" << std::endl + << " detail=1|2|3" << std::endl + << " the level of detail of game scenes" << std::endl + << " fullscreen=true|false" << std::endl + << " if true, uses the entire display" << std::endl + << " framerate=num" << std::endl + << " number of frames to draw per second" << std::endl + << std::endl + << "See documentation for more options." << std::endl; } void Main::print_info(int argc, char* argv[]) @@ -220,27 +213,14 @@ void Main::print_info(int argc, char* argv[]) #endif } -void Main::print_option(const std::string& option, bool enabled) -{ - if (isatty(1) == 1) - { - if (enabled) std::cout << "\033[1;94m"; - else std::cout << "\033[1m"; - } - if (!enabled) std::cout << "-"; - std::cout << option; - if (isatty(1) == 1) std::cout << "\033[0m"; - std::cout << " "; -} - void hello() { if (isatty(1) == 1) std::cout << "\033[94m"; std::cout << std::endl << PACKAGE_STRING << std::endl - << "Compiled " << __TIME__ " " __DATE__ << std::endl - << "Send patches and bug reports to <" - PACKAGE_BUGREPORT << ">." << std::endl << moof::log::endl; + << "Compiled " << __TIME__" "__DATE__ << std::endl + << "Send patches and bug reports to <"PACKAGE_BUGREPORT">." + << std::endl << moof::log::endl; } void goodbye() @@ -297,18 +277,16 @@ int main(int argc, char* argv[]) catch (const std::exception& e) { moof::modal_dialog dialog(moof::modal_dialog::error, - PACKAGE_STRING, "unhandled exception", - e.what()); + PACKAGE_STRING, "unhandled exception", + e.what()); dialog.run(); } catch (const char* e) { moof::modal_dialog dialog(moof::modal_dialog::error, - PACKAGE_STRING, "unhandled exception", - e); + PACKAGE_STRING, "unhandled exception", e); dialog.run(); } - return 1; } diff --git a/src/Main.hh b/src/Main.hh index 088bd3c..65ad901 100644 --- a/src/Main.hh +++ b/src/Main.hh @@ -1,13 +1,11 @@ -/*] Copyright (c) 2009-2010, Charles McGarvey [************************** +/*] Copyright (c) 2009-2011, Charles McGarvey [***************************** **] All rights reserved. * -* vi:ts=4 sw=4 tw=75 -* * Distributable under the terms and conditions of the 2-clause BSD license; * see the file COPYING for a complete text of the license. * -**************************************************************************/ +*****************************************************************************/ #ifndef _MAIN_HH_ #define _MAIN_HH_ @@ -34,7 +32,7 @@ class Main : public moof::application { public: - Main(moof::settings& settings); + explicit Main(moof::settings& settings); void update(moof::scalar t, moof::scalar dt); void draw(moof::scalar alpha) const; @@ -53,8 +51,6 @@ private: */ static void setup_opengl(); - static void print_option(const std::string& option, bool enabled); - moof::dispatcher::handle video_reloaded_; moof::timer hotload_timer_; diff --git a/src/Scene.cc b/src/Scene.cc index af54c28..dc6ab75 100644 --- a/src/Scene.cc +++ b/src/Scene.cc @@ -1,13 +1,11 @@ -/*] Copyright (c) 2009-2010, Charles McGarvey [************************** +/*] Copyright (c) 2009-2011, Charles McGarvey [***************************** **] All rights reserved. * -* vi:ts=4 sw=4 tw=75 -* * Distributable under the terms and conditions of the 2-clause BSD license; * see the file COPYING for a complete text of the license. * -**************************************************************************/ +*****************************************************************************/ #include @@ -36,12 +34,12 @@ struct Scene::impl : public moof::manager NONE = 0, LEFT = 1, RIGHT = 2, - TOP = 3 + TOP = 3 }; Quad(const moof::vector3* vertices[4], - const moof::image_handle& texture, - int tileIndex) : + const moof::image_handle& texture, + int tileIndex) : mTilemap(texture, tileIndex), mBlending(false), mFog(false), @@ -112,9 +110,9 @@ struct Scene::impl : public moof::manager moof::sprite mTilemap; - bool mBlending; - bool mFog; - Surface mSurface; + bool mBlending; + bool mFog; + Surface mSurface; }; @@ -123,9 +121,9 @@ struct Scene::impl : public moof::manager moof::image_handle mTexture; std::list< boost::shared_ptr > mObjects; - std::list mLines; + std::list mLines; - moof::aabb<3> mBounds; + moof::aabb<3> mBounds; enum AXIS @@ -264,14 +262,13 @@ struct Scene::impl : public moof::manager int rotate(moof::script& script) { - size_t index = 0; + size_t index = 0; moof::scalar value; script[1].require_number().get(index); script[2].require_number().get(value); - moof::matrix_rotate_about_world_axis(mTransform, index, - moof::rad(value)); + moof::matrix_rotate_about_world_axis(mTransform, index, moof::rad(value)); return 0; } @@ -350,7 +347,7 @@ struct Scene::impl : public moof::manager } } - Quad::Surface surface = Quad::NONE; + Quad::Surface surface = Quad::NONE; table.get(surface, "surface"); if (surface != Quad::NONE) @@ -365,7 +362,6 @@ struct Scene::impl : public moof::manager mLines.push_back(moof::line<2>(bl, tr)); } - return 0; } @@ -374,8 +370,8 @@ struct Scene::impl : public moof::manager moof::script::slot param = script[1]; moof::script::slot top = script[-1]; - int index = 0; - int width = 1; + int index = 0; + int width = 1; bool blending = false; bool fog = false; @@ -479,7 +475,7 @@ void Scene::draw_if_visible(moof::scalar alpha, bool Scene::castRay(const moof::ray<2>& ray, - std::list::contact>& hits) const + std::list::contact>& hits) const { std::list< moof::line<2> >& lines = impl_->mLines; std::list< moof::line<2> >::const_iterator it; @@ -558,4 +554,3 @@ bool Scene::checkForCollision(Character& character) return false; } - diff --git a/src/Scene.hh b/src/Scene.hh index 8c60cc5..7f36f9b 100644 --- a/src/Scene.hh +++ b/src/Scene.hh @@ -1,13 +1,11 @@ -/*] Copyright (c) 2009-2010, Charles McGarvey [************************** +/*] Copyright (c) 2009-2011, Charles McGarvey [***************************** **] All rights reserved. * -* vi:ts=4 sw=4 tw=75 -* * Distributable under the terms and conditions of the 2-clause BSD license; * see the file COPYING for a complete text of the license. * -**************************************************************************/ +*****************************************************************************/ #ifndef _SCENE_HH_ #define _SCENE_HH_ @@ -22,12 +20,11 @@ #include -class Character; - - +// forward declarations namespace moof { class settings; } +class Character; class Scene; typedef boost::shared_ptr SceneP; diff --git a/src/TilemapFont.cc b/src/TilemapFont.cc index b060ccf..f0facbb 100644 --- a/src/TilemapFont.cc +++ b/src/TilemapFont.cc @@ -1,13 +1,11 @@ -/*] Copyright (c) 2009-2010, Charles McGarvey [************************** +/*] Copyright (c) 2009-2011, Charles McGarvey [***************************** **] All rights reserved. * -* vi:ts=4 sw=4 tw=75 -* * Distributable under the terms and conditions of the 2-clause BSD license; * see the file COPYING for a complete text of the license. * -**************************************************************************/ +*****************************************************************************/ #include diff --git a/src/TilemapFont.hh b/src/TilemapFont.hh index 3a7d378..b3759a9 100644 --- a/src/TilemapFont.hh +++ b/src/TilemapFont.hh @@ -1,13 +1,11 @@ -/*] Copyright (c) 2009-2010, Charles McGarvey [************************** +/*] Copyright (c) 2009-2011, Charles McGarvey [***************************** **] All rights reserved. * -* vi:ts=4 sw=4 tw=75 -* * Distributable under the terms and conditions of the 2-clause BSD license; * see the file COPYING for a complete text of the license. * -**************************************************************************/ +*****************************************************************************/ #ifndef _TILEMAPFONT_HH_ #define _TILEMAPFONT_HH_ diff --git a/src/Typesetter.cc b/src/Typesetter.cc index 1b21f76..e6689e5 100644 --- a/src/Typesetter.cc +++ b/src/Typesetter.cc @@ -1,13 +1,11 @@ -/*] Copyright (c) 2009-2010, Charles McGarvey [************************** +/*] Copyright (c) 2009-2011, Charles McGarvey [***************************** **] All rights reserved. * -* vi:ts=4 sw=4 tw=75 -* * Distributable under the terms and conditions of the 2-clause BSD license; * see the file COPYING for a complete text of the license. * -**************************************************************************/ +*****************************************************************************/ #include #include diff --git a/src/Typesetter.hh b/src/Typesetter.hh index 19e6dbf..ac2e3f1 100644 --- a/src/Typesetter.hh +++ b/src/Typesetter.hh @@ -1,13 +1,11 @@ -/*] Copyright (c) 2009-2010, Charles McGarvey [************************** +/*] Copyright (c) 2009-2011, Charles McGarvey [***************************** **] All rights reserved. * -* vi:ts=4 sw=4 tw=75 -* * Distributable under the terms and conditions of the 2-clause BSD license; * see the file COPYING for a complete text of the license. * -**************************************************************************/ +*****************************************************************************/ #ifndef _TYPESETTER_HH_ #define _TYPESETTER_HH_ diff --git a/src/moof/aabb.cc b/src/moof/aabb.cc index cbad71b..f403f7a 100644 --- a/src/moof/aabb.cc +++ b/src/moof/aabb.cc @@ -1,21 +1,17 @@ -/*] Copyright (c) 2009-2010, Charles McGarvey [************************** +/*] Copyright (c) 2009-2011, Charles McGarvey [***************************** **] All rights reserved. * -* vi:ts=4 sw=4 tw=75 -* * Distributable under the terms and conditions of the 2-clause BSD license; * see the file COPYING for a complete text of the license. * -**************************************************************************/ +*****************************************************************************/ #include "aabb.hh" #include "script.hh" - namespace moof { - void import_aabb_class(script& script) { } diff --git a/src/moof/aabb.hh b/src/moof/aabb.hh index b2fc4b0..3228b5a 100644 --- a/src/moof/aabb.hh +++ b/src/moof/aabb.hh @@ -1,13 +1,11 @@ -/*] Copyright (c) 2009-2010, Charles McGarvey [************************** +/*] Copyright (c) 2009-2011, Charles McGarvey [***************************** **] All rights reserved. * -* vi:ts=4 sw=4 tw=75 -* * 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_AABB_HH_ #define _MOOF_AABB_HH_ @@ -31,9 +29,9 @@ namespace moof { +// forward declarations class script; - template struct aabb : public cullable, public drawable, public shape { @@ -42,7 +40,6 @@ struct aabb : public cullable, public drawable, public shape vector min; vector max; - aabb() {} aabb(const vector& a, const vector& b) @@ -66,7 +63,6 @@ struct aabb : public cullable, public drawable, public shape init(a, b); } - void init(const vector2& a, const vector2& b) { if (a[0] < b[0]) @@ -125,13 +121,11 @@ struct aabb : public cullable, public drawable, public shape } } - vector center() const { return (min + max) / 2.0; } - plane xy_plane() const { plane plane; @@ -156,7 +150,6 @@ struct aabb : public cullable, public drawable, public shape return plane; } - void get_corners(vector2 corners[4]) const { corners[0][0] = min[0]; corners[0][1] = min[1]; @@ -193,12 +186,10 @@ struct aabb : public cullable, public drawable, public shape corners[7][2] = min[2]; } - void enclose_vertices(const vector vertices[], unsigned count) { min.zero(); max.zero(); - for (unsigned i = 1; i < count; ++i) { min.minimize(vertices[i]); @@ -206,7 +197,6 @@ struct aabb : public cullable, public drawable, public shape } } - void draw(scalar alpha = 0.0) const { glRect(min[0], min[1], max[0], max[1]); @@ -224,21 +214,25 @@ void import_aabb_class(script& script); template <> inline void aabb<3>::draw(scalar alpha) const { - scalar vertices[] = {min[0], min[1], min[2], - min[0], max[1], min[2], - max[0], max[1], min[2], - max[0], min[1], min[2], - min[0], max[1], max[2], - min[0], min[1], max[2], - max[0], min[1], max[2], - max[0], max[1], max[2]}; - - GLubyte indices[] = {0, 1, 2, 3, - 1, 2, 7, 4, - 3, 0, 5, 6, - 2, 3, 6, 7, - 5, 0, 1, 4, - 4, 5, 6, 7}; + scalar vertices[] = { + min[0], min[1], min[2], + min[0], max[1], min[2], + max[0], max[1], min[2], + max[0], min[1], min[2], + min[0], max[1], max[2], + min[0], min[1], max[2], + max[0], min[1], max[2], + max[0], max[1], max[2] + }; + + GLubyte indices[] = { + 0, 1, 2, 3, + 1, 2, 7, 4, + 3, 0, 5, 6, + 2, 3, 6, 7, + 5, 0, 1, 4, + 4, 5, 6, 7 + }; glEnableClientState(GL_VERTEX_ARRAY); glDisableClientState(GL_TEXTURE_COORD_ARRAY); @@ -247,8 +241,7 @@ inline void aabb<3>::draw(scalar alpha) const glPolygonMode(GL_FRONT_AND_BACK, GL_LINE); image::reset_binding(); - glDrawElements(GL_QUADS, sizeof(indices), GL_UNSIGNED_BYTE, - indices); + glDrawElements(GL_QUADS, sizeof(indices), GL_UNSIGNED_BYTE, indices); glEnableClientState(GL_TEXTURE_COORD_ARRAY); //glDisableClientState(GL_VERTEX_ARRAY); @@ -262,7 +255,6 @@ inline bool aabb<3>::is_visible(const frustum& frustum) const return frustum.contains(*this); } - typedef aabb<2> aabb2; typedef aabb2 rectangle; typedef aabb<3> aabb3; diff --git a/src/moof/application.cc b/src/moof/application.cc index 0da5bae..e0b73b7 100644 --- a/src/moof/application.cc +++ b/src/moof/application.cc @@ -1,15 +1,13 @@ -/*] Copyright (c) 2009-2010, Charles McGarvey [************************** +/*] Copyright (c) 2009-2011, Charles McGarvey [***************************** **] All rights reserved. * -* vi:ts=4 sw=4 tw=75 -* * Distributable under the terms and conditions of the 2-clause BSD license; * see the file COPYING for a complete text of the license. * -**************************************************************************/ +*****************************************************************************/ -#include // exit, srand +#include // exit, srand #include #include @@ -42,20 +40,19 @@ application::application(settings& settings) : settings.get("framerate", framerate); framerate = SCALAR(1.0) / framerate; - //timer::default_source().scale(SCALAR(0.76)); - //update_timer_.init(boost::bind(&application::dispatch_update, - //this, _1, _2), - //timestep_, timer::repeat); + //this, _1, _2), timestep_, timer::repeat); //add_timer(update_timer_); game_time_.reset(timestep_); + //game_time_.scale(SCALAR(0.5)); draw_timer_.init(boost::bind(&application::dispatch_draw, - this, _1, _2), framerate, timer::repeat); + this, _1, _2), framerate, timer::repeat); add_timer(draw_timer_); -} + //timer::default_source().scale(SCALAR(0.2)); +} void application::dispatch_update(timer& timer, scalar t) { @@ -65,27 +62,23 @@ void application::dispatch_update(timer& timer, scalar t) { switch (event.type) { - case SDL_KEYDOWN: - - if (event.key.keysym.sym == SDLK_ESCAPE && - (SDL_GetModState() & KMOD_CTRL) ) - { - // emergency escape - log_warning("escape forced"); - exit(1); - } - break; - - case SDL_VIDEORESIZE: - - video::current()->resize(event.resize.w, event.resize.h); - break; + case SDL_KEYDOWN: + if (event.key.keysym.sym == SDLK_ESCAPE && + (SDL_GetModState() & KMOD_CTRL)) + { + log_warning("escape forced"); + exit(1); + } + break; + + case SDL_VIDEORESIZE: + video::current()->resize(event.resize.w, + event.resize.h); + break; } - handle_event(event); } - const int MAX_CONSECUTIVE_UPDATES = 15; log_debug("updating", timer.expiration(), "/", t); @@ -96,9 +89,8 @@ void application::dispatch_update(timer& timer, scalar t) int i = 0; while (timestep_ <= accum_ && i < MAX_CONSECUTIVE_UPDATES) { - log_debug("UPDATING"); - update(game_time_.ticks(), timestep_); - game_time_.step(); + scalar dt = game_time_.step(); + update(game_time_.ticks(), dt); accum_ -= timestep_; } @@ -116,7 +108,7 @@ void application::dispatch_draw(timer& timer, scalar t) scalar alpha = accum_ * inverse_timestep_; - alpha = cml::clamp(alpha, SCALAR(-1.0), SCALAR(2.0)); + //alpha = cml::clamp(alpha, SCALAR(-1.0), SCALAR(2.0)); if (alpha < SCALAR(0.0)) log_warning("alpha:", alpha); else if (alpha > SCALAR(1.0)) log_warning("alpha:", alpha); else log_debug("alpha:", alpha); @@ -125,9 +117,11 @@ void application::dispatch_draw(timer& timer, scalar t) scalar begin = timer::ticks(); video::current()->swap(t); - scalar duration = timer::ticks() - begin; - log_debug("flip duration:", duration); + log_debug("flip duration:", duration, begin, timer::ticks()); + + log_info("draw difference:", t - last_draw_); + last_draw_ = t; } diff --git a/src/moof/application.hh b/src/moof/application.hh index 8449058..5c80867 100644 --- a/src/moof/application.hh +++ b/src/moof/application.hh @@ -1,13 +1,11 @@ -/*] Copyright (c) 2009-2010, Charles McGarvey [************************** +/*] Copyright (c) 2009-2011, Charles McGarvey [***************************** **] All rights reserved. * -* vi:ts=4 sw=4 tw=75 -* * 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_APPLICATION_HH_ #define _MOOF_APPLICATION_HH_ @@ -28,34 +26,35 @@ namespace moof { +// forward declarations class settings; class application : public runloop { public: - application(settings& settings); + explicit application(settings& settings); virtual ~application() {} virtual void update(scalar t, scalar dt) = 0; virtual void draw(scalar alpha) const = 0; virtual void handle_event(const event& event) = 0; - private: void dispatch_update(timer& timer, scalar t); void dispatch_draw(timer& timer, scalar t); - scalar last_update_; - scalar accum_; + scalar last_update_; + scalar last_draw_; + scalar accum_; game_time game_time_; - timer update_timer_; - timer draw_timer_; + timer update_timer_; + timer draw_timer_; - scalar timestep_; - scalar inverse_timestep_; + scalar timestep_; + scalar inverse_timestep_; }; diff --git a/src/moof/backend.cc b/src/moof/backend.cc index 2dd199d..fa3ad31 100644 --- a/src/moof/backend.cc +++ b/src/moof/backend.cc @@ -1,13 +1,15 @@ -/*] Copyright (c) 2009-2010, Charles McGarvey [************************** +/*] Copyright (c) 2009-2011, Charles McGarvey [***************************** **] All rights reserved. * -* vi:ts=4 sw=4 tw=75 -* * Distributable under the terms and conditions of the 2-clause BSD license; * see the file COPYING for a complete text of the license. * -**************************************************************************/ +*****************************************************************************/ + +#if HAVE_CONFIG_H +#include "config.h" +#endif #include @@ -21,21 +23,13 @@ namespace moof { -struct impl -{ - static bool is_initialized; - static int retain_count; -}; - -bool impl::is_initialized = false; -int impl::retain_count = 0; - +static int retain_count = 0; backend::backend() { - if (impl::retain_count++ == 0) + if (retain_count++ == 0) { -#if defined(_WIN32) +#if PLATFORM_WIN32 if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_TIMER) != 0) #else if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_EVENTTHREAD) != 0) @@ -47,45 +41,40 @@ backend::backend() { char name[128]; SDL_VideoDriverName(name, sizeof(name)); - log_info << "initialized SDL; using video driver `" - << name << "'" << std::endl; + log_info << "initialized SDL; using video driver `" << + name << "'" << std::endl; } - if (FE_Init() != 0) { throw std::runtime_error(FE_GetError()); } } - - impl::is_initialized = true; } backend::backend(const backend& backend) { - ++impl::retain_count; + ++retain_count; } -backend& backend::operator=(const backend& backend) +backend& backend::operator = (const backend& backend) { - ++impl::retain_count; + ++retain_count; return *this; } backend::~backend() { - if (--impl::retain_count == 0) + if (--retain_count == 0) { log_info("shutting down SDL..."); FE_Quit(); SDL_Quit(); - - impl::is_initialized = false; } } bool backend::is_initialized() { - return impl::is_initialized; + return 0 < retain_count; } diff --git a/src/moof/backend.hh b/src/moof/backend.hh index b40a72a..b25e53a 100644 --- a/src/moof/backend.hh +++ b/src/moof/backend.hh @@ -1,13 +1,11 @@ -/*] Copyright (c) 2009-2010, Charles McGarvey [************************** +/*] Copyright (c) 2009-2011, Charles McGarvey [***************************** **] All rights reserved. * -* vi:ts=4 sw=4 tw=75 -* * 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_BACKEND_HH_ #define _MOOF_BACKEND_HH_ @@ -23,18 +21,17 @@ namespace moof { /** * Some classes and subsystems require certain backend libraries to be - * initialized. This is the mechanism to accomplish that. Classes which - * rely on any backend libraries just need to instantiate this class as a - * member. Backend cleanup will occur automagically when there are no more - * instances. + * initialized. This is the mechanism to accomplish that. Classes which rely + * on any backend libraries just need to instantiate this class as a member. + * Backend cleanup will occur automagically when there are no more instances. */ class backend { public: /** - * Construct a backend reference, initializing the backend if it hasn't - * already been initialized. + * Construct a backend reference, initializing the backend if it + * hasn't already been initialized. */ backend(); @@ -44,11 +41,10 @@ public: */ static bool is_initialized(); - - // The rest of this stuff is to implement the reference counting. + /* The rest of this stuff is to implement the reference counting. */ backend(const backend& backend); - backend& operator=(const backend& backend); + backend& operator = (const backend& backend); ~backend(); }; diff --git a/src/moof/camera.cc b/src/moof/camera.cc index 093b7d1..95488db 100644 --- a/src/moof/camera.cc +++ b/src/moof/camera.cc @@ -1,13 +1,11 @@ -/*] Copyright (c) 2009-2010, Charles McGarvey [************************** +/*] Copyright (c) 2009-2011, Charles McGarvey [***************************** **] All rights reserved. * -* vi:ts=4 sw=4 tw=75 -* * Distributable under the terms and conditions of the 2-clause BSD license; * see the file COPYING for a complete text of the license. * -**************************************************************************/ +*****************************************************************************/ #include "camera.hh" #include "opengl.hh" @@ -30,23 +28,21 @@ void camera::look_at(const vector3& point) { // FIXME: this doesn't work as expected quaternion_rotation_aim_at(state_.orientation, state_.position, point, - vector3(0.0, 1.0, 0.0)); + vector3(0.0, 1.0, 0.0)); } - void camera::projection(const matrix4& projection) { projection_ = projection; } -void camera::projection(scalar fovy, scalar aspect, scalar abutting, - scalar distant) +void camera::projection(scalar fovy, + scalar aspect, scalar abutting, scalar distant) { matrix_perspective_yfov_RH(projection_, fovy, aspect, abutting, - distant, z_clip_neg_one); + distant, z_clip_neg_one); } - void camera::upload_to_gl(scalar alpha) const { calculate(alpha); @@ -72,7 +68,6 @@ void camera::calculate(scalar alpha) const frustum_.init(modelview_, projection_); } - void camera::update(scalar t, scalar dt) { rigid_body3::update(t, dt); @@ -83,66 +78,58 @@ void camera::draw(scalar alpha) const sphere_.draw(alpha); } - void camera::handle_event(const event& event) { const scalar ds = 50.0; switch (event.type) { - case SDL_KEYDOWN: - if (event.key.keysym.sym == SDLK_RIGHT) - { - state_.position[0] -= ds; - } - else if (event.key.keysym.sym == SDLK_LEFT) - { - state_.position[0] += ds; - } - else if (event.key.keysym.sym == SDLK_UP) - { - state_.position[1] -= ds; - } - else if (event.key.keysym.sym == SDLK_DOWN) - { - state_.position[1] += ds; - } - else if (event.key.keysym.sym == SDLK_PAGEUP) - { - state_.position[2] += ds; - } - else if (event.key.keysym.sym == SDLK_PAGEDOWN) - { - state_.position[2] -= ds; - } + case SDL_KEYDOWN: + switch (event.key.keysym.sym) + { + case SDLK_RIGHT: + state_.position[0] -= ds; break; + case SDLK_LEFT: + state_.position[0] += ds; break; + case SDLK_UP: + state_.position[1] -= ds; break; + case SDLK_DOWN: + state_.position[1] += ds; break; + case SDLK_PAGEUP: + state_.position[2] += ds; break; + case SDLK_PAGEDOWN: + state_.position[2] -= ds; break; + default: break; + } + break; - case SDL_MOUSEMOTION: - { - scalar xrel = rad(scalar(event.motion.xrel) / 6.0); - scalar yrel = rad(scalar(event.motion.yrel) / 6.0); + case SDL_MOUSEMOTION: + { + scalar xrel = rad(scalar(event.motion.xrel) / 6.0); + scalar yrel = rad(scalar(event.motion.yrel) / 6.0); - quaternion rotation = state_.orientation; + quaternion rotation = state_.orientation; - quaternion_rotate_about_world_x(rotation, yrel); - //mRotation.normalize(); - quaternion_rotate_about_world_y(rotation, xrel); + quaternion_rotate_about_world_x(rotation, yrel); + //mRotation.normalize(); + quaternion_rotate_about_world_y(rotation, xrel); - rotation.normalize(); - state_.orientation = rotation; - } - break; + rotation.normalize(); + state_.orientation = rotation; + break; + } - case SDL_MOUSEBUTTONDOWN: - if (event.button.button == SDL_BUTTON_WHEELUP) - { - state_.position[2] -= ds; - } - else if (event.button.button == SDL_BUTTON_WHEELDOWN) - { - state_.position[2] -= ds; - } + case SDL_MOUSEBUTTONDOWN: + switch (event.button.button) + { + case SDL_BUTTON_WHEELUP: + state_.position[2] -= ds; + break; + case SDL_BUTTON_WHEELDOWN: + state_.position[2] += ds; break; + } } } diff --git a/src/moof/camera.hh b/src/moof/camera.hh index b3aac0e..43e5471 100644 --- a/src/moof/camera.hh +++ b/src/moof/camera.hh @@ -1,13 +1,11 @@ -/*] Copyright (c) 2009-2010, Charles McGarvey [************************** +/*] Copyright (c) 2009-2011, Charles McGarvey [***************************** **] All rights reserved. * -* vi:ts=4 sw=4 tw=75 -* * 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_CAMERA_HH_ #define _MOOF_CAMERA_HH_ @@ -61,21 +59,18 @@ public: return frustum_; } - void upload_to_gl(scalar alpha = 0) const; void update(scalar t, scalar dt); void draw(scalar alpha = 0) const; void handle_event(const event& event); - private: void calculate(scalar alpha) const; - mutable matrix4 modelview_; - matrix4 projection_; - + mutable matrix4 modelview_; + matrix4 projection_; mutable class frustum frustum_; }; diff --git a/src/moof/contact.hh b/src/moof/contact.hh index a14718a..1d1998e 100644 --- a/src/moof/contact.hh +++ b/src/moof/contact.hh @@ -1,13 +1,11 @@ -/*] Copyright (c) 2009-2010, Charles McGarvey [************************** +/*] Copyright (c) 2009-2011, Charles McGarvey [***************************** **] All rights reserved. * -* vi:ts=4 sw=4 tw=75 -* * 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_CONTACT_HH_ #define _MOOF_CONTACT_HH_ @@ -28,9 +26,9 @@ struct contact { typedef moof::vector< scalar, fixed > vector; - vector point; // point of contact - scalar distance; // distance of penetration - vector normal; // normal of surface at point of contact + vector point; // point of contact + scalar distance; // distance of penetration + vector normal; // normal of surface at point of contact bool operator < (const contact& rhs) { diff --git a/src/moof/cullable.hh b/src/moof/cullable.hh index 4e4391e..3f0169a 100644 --- a/src/moof/cullable.hh +++ b/src/moof/cullable.hh @@ -1,13 +1,11 @@ -/*] Copyright (c) 2009-2010, Charles McGarvey [************************** +/*] Copyright (c) 2009-2011, Charles McGarvey [***************************** **] All rights reserved. * -* vi:ts=4 sw=4 tw=75 -* * 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_CULLABLE_HH_ #define _MOOF_CULLABLE_HH_ @@ -21,15 +19,16 @@ namespace moof { +// forward declarations class frustum; /** * Interface for anything that can be culled. */ - class cullable { public: + virtual ~cullable() {} virtual bool is_visible(const frustum& frustum) const diff --git a/src/moof/debug.hh b/src/moof/debug.hh index 837340f..baa0304 100644 --- a/src/moof/debug.hh +++ b/src/moof/debug.hh @@ -1,13 +1,11 @@ -/*] Copyright (c) 2009-2010, Charles McGarvey [************************** +/*] Copyright (c) 2009-2011, Charles McGarvey [***************************** **] All rights reserved. * -* vi:ts=4 sw=4 tw=75 -* * 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_DEBUG_HH_ #define _MOOF_DEBUG_HH_ diff --git a/src/moof/dispatcher.cc b/src/moof/dispatcher.cc index 96babe4..c0aeae5 100644 --- a/src/moof/dispatcher.cc +++ b/src/moof/dispatcher.cc @@ -1,13 +1,11 @@ -/*] Copyright (c) 2009-2010, Charles McGarvey [************************** +/*] Copyright (c) 2009-2011, Charles McGarvey [***************************** **] All rights reserved. * -* vi:ts=4 sw=4 tw=75 -* * Distributable under the terms and conditions of the 2-clause BSD license; * see the file COPYING for a complete text of the license. * -**************************************************************************/ +*****************************************************************************/ #include @@ -25,29 +23,25 @@ public: dispatcher_(dispatcher), id_(0) {} - dispatcher::handle getNewHandle() + dispatcher::handle new_handle() { - ++id_; - dispatcher::handle handle(dispatcher_->impl_, id_); + dispatcher::handle handle(dispatcher_->impl_, --id_); return handle; } typedef std::pair callback; - typedef std::multimap callback_lookup; - typedef callback_lookup::iterator callback_it; - - typedef std::multimap handle_lookup; - typedef handle_lookup::iterator handle_it; + typedef std::multimap callback_lookup; + typedef callback_lookup::iterator callback_it; + typedef std::multimap handle_lookup; + typedef handle_lookup::iterator handle_it; handle add_target(const std::string& event, - const function& callback, - handle handle) + const function& callback, handle handle) { - callbacks_.insert(std::make_pair(event, std::make_pair(handle.id(), - callback))); + callbacks_.insert(std::make_pair(event, + std::make_pair(handle.id(), callback))); handles_.insert(std::make_pair(handle.id(), event)); - return handle; } @@ -55,7 +49,8 @@ public: { std::pair matching(handles_.equal_range(id)); - for (handle_it it = matching.first; it != matching.second; ++it) + for (handle_it it = matching.first; + it != matching.second; ++it) { callback_it first = callbacks_.find((*it).second); callback_it last = callbacks_.end(); @@ -85,16 +80,13 @@ public: } } - - dispatcher* dispatcher_; - - unsigned id_; + dispatcher* dispatcher_; + unsigned id_; callback_lookup callbacks_; handle_lookup handles_; }; - void dispatcher::handle::clear() { boost::shared_ptr dispatcher; @@ -109,36 +101,31 @@ void dispatcher::handle::clear() dispatcher::dispatcher() : impl_(new dispatcher::impl(this)) {} - -dispatcher::handle dispatcher::add_target(const std::string& event, - const function& callback) +dispatcher::handle +dispatcher::add_target(const std::string& event, const function& callback) { - return add_target(event, callback, impl_->getNewHandle()); + return add_target(event, callback, impl_->new_handle()); } dispatcher::handle dispatcher::add_target(const std::string& event, - const function& callback, - handle handle) + const function& callback, handle handle) { // pass through return impl_->add_target(event, callback, handle); } - void dispatcher::remove_target(unsigned id) { // pass through return impl_->remove_target(id); } - void dispatcher::dispatch(const std::string& event) { // pass through impl_->dispatch(event); } - dispatcher& dispatcher::global() { static dispatcher dispatcher; diff --git a/src/moof/dispatcher.hh b/src/moof/dispatcher.hh index a4207c4..f2613e8 100644 --- a/src/moof/dispatcher.hh +++ b/src/moof/dispatcher.hh @@ -1,13 +1,11 @@ -/*] Copyright (c) 2009-2010, Charles McGarvey [************************** +/*] Copyright (c) 2009-2011, Charles McGarvey [***************************** **] All rights reserved. * -* vi:ts=4 sw=4 tw=75 -* * 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_DISPATCH_HH_ #define _MOOF_DISPATCH_HH_ @@ -31,7 +29,6 @@ namespace moof { /** * Dispatcher of messages to interested parties. */ - class dispatcher { class impl; @@ -39,7 +36,6 @@ class dispatcher void remove_target(unsigned id); - public: class handle @@ -84,17 +80,16 @@ public: private: boost::weak_ptr dispatcher_; - mutable unsigned id_; + mutable unsigned id_; }; typedef boost::function function; - dispatcher(); handle add_target(const std::string& event, const function& callback); handle add_target(const std::string& event, const function& callback, - handle handle); + handle handle); void dispatch(const std::string& event); diff --git a/src/moof/drawable.hh b/src/moof/drawable.hh index 3882995..2f5c6cd 100644 --- a/src/moof/drawable.hh +++ b/src/moof/drawable.hh @@ -1,13 +1,11 @@ -/*] Copyright (c) 2009-2010, Charles McGarvey [************************** +/*] Copyright (c) 2009-2011, Charles McGarvey [***************************** **] All rights reserved. * -* vi:ts=4 sw=4 tw=75 -* * 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_DRAWABLE_HH_ #define _MOOF_DRAWABLE_HH_ @@ -29,8 +27,8 @@ namespace moof { class drawable { public: - virtual ~drawable() {} + virtual ~drawable() {} virtual void draw(scalar alpha) const = 0; }; diff --git a/src/moof/entity.hh b/src/moof/entity.hh index f95a94c..92b4dc5 100644 --- a/src/moof/entity.hh +++ b/src/moof/entity.hh @@ -1,13 +1,11 @@ -/*] Copyright (c) 2009-2010, Charles McGarvey [************************** +/*] Copyright (c) 2009-2011, Charles McGarvey [***************************** **] All rights reserved. * -* vi:ts=4 sw=4 tw=75 -* * 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_ENTITY_HH_ #define _MOOF_ENTITY_HH_ @@ -28,17 +26,9 @@ namespace moof { +// forward declarations class frustum; - -class entity; - -/** - * Entity pointer. - */ -typedef boost::shared_ptr entity_ptr; - - /** * Interface for game objects that can be drawn to the screen and have a * specified volume (take up space). @@ -57,7 +47,8 @@ public: * timestep. * \param frustum The camera frustum for determining visibility. */ - virtual void draw_if_visible(scalar alpha, const frustum& frustum) const + virtual void + draw_if_visible(scalar alpha, const frustum& frustum) const { if (is_visible(frustum)) draw(alpha); } @@ -74,7 +65,6 @@ public: return sphere_.is_visible(frustum) && aabb_.is_visible(frustum); } - /** * Get the axis-aligned bounding box surrounding the entity. * \return The AABB. @@ -92,13 +82,14 @@ public: return sphere_; } - protected: - moof::aabb3 aabb_; + moof::aabb3 aabb_; moof::sphere3 sphere_; }; +typedef boost::shared_ptr entity_ptr; + } // namespace moof diff --git a/src/moof/event.hh b/src/moof/event.hh index c717db4..8635e5f 100644 --- a/src/moof/event.hh +++ b/src/moof/event.hh @@ -1,13 +1,11 @@ -/*] Copyright (c) 2009-2010, Charles McGarvey [************************** +/*] Copyright (c) 2009-2011, Charles McGarvey [***************************** **] All rights reserved. * -* vi:ts=4 sw=4 tw=75 -* * 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_EVENT_HH_ #define _MOOF_EVENT_HH_ diff --git a/src/moof/frustum.cc b/src/moof/frustum.cc index aaeceb0..c525c1a 100644 --- a/src/moof/frustum.cc +++ b/src/moof/frustum.cc @@ -1,13 +1,11 @@ -/*] Copyright (c) 2009-2010, Charles McGarvey [************************** +/*] Copyright (c) 2009-2011, Charles McGarvey [***************************** **] All rights reserved. * -* vi:ts=4 sw=4 tw=75 -* * Distributable under the terms and conditions of the 2-clause BSD license; * see the file COPYING for a complete text of the license. * -**************************************************************************/ +*****************************************************************************/ #include "aabb.hh" #include "frustum.hh" @@ -20,72 +18,55 @@ namespace moof { void frustum::init(const matrix4& modelview, const matrix4& projection) { scalar planes[6][4]; - extract_frustum_planes(modelview, projection, planes, z_clip_neg_one); - planes_[0] = plane(planes[0][0], planes[0][1], - planes[0][2], planes[0][3]); - planes_[1] = plane(planes[1][0], planes[1][1], - planes[1][2], planes[1][3]); - planes_[2] = plane(planes[2][0], planes[2][1], - planes[2][2], planes[2][3]); - planes_[3] = plane(planes[3][0], planes[3][1], - planes[3][2], planes[3][3]); - planes_[4] = plane(planes[4][0], planes[4][1], - planes[4][2], planes[4][3]); - planes_[5] = plane(planes[5][0], planes[5][1], - planes[5][2], planes[5][3]); + planes_[0] = plane(planes[0][0], planes[0][1], planes[0][2], planes[0][3]); + planes_[1] = plane(planes[1][0], planes[1][1], planes[1][2], planes[1][3]); + planes_[2] = plane(planes[2][0], planes[2][1], planes[2][2], planes[2][3]); + planes_[3] = plane(planes[3][0], planes[3][1], planes[3][2], planes[3][3]); + planes_[4] = plane(planes[4][0], planes[4][1], planes[4][2], planes[4][3]); + planes_[5] = plane(planes[5][0], planes[5][1], planes[5][2], planes[5][3]); } void frustum::init(const matrix4& modelview, scalar fovy, scalar aspect, - scalar abutting, scalar distant) + scalar abutting, scalar distant) { matrix4 projection; - - matrix_perspective_yfov_RH(projection, fovy, aspect, abutting, - distant, z_clip_neg_one); - + matrix_perspective_yfov_RH(projection, + fovy, aspect, abutting, distant, z_clip_neg_one); init(modelview, projection); } frustum::collision frustum::contains(const aabb<3>& aabb) const { - vector3 corners[8]; - int nTotalInside = 0; - + int total = 0; + vector3 corners[8]; aabb.get_corners(corners); for (int i = 0; i < 6; ++i) { - int nInside = 8; - + int num = 8; for (int j = 0; j < 8; ++j) { if (planes_[i].intersects(corners[j]) == plane::negative) - { - --nInside; - } + --num; } - - if (nInside == 0) return outside; - else if (nInside == 8) ++nTotalInside; + if (num == 0) return outside; + else if (num == 8) ++total; } - if (nTotalInside == 6) return inside; - else return intersecting; + if (total == 6) return inside; + return intersecting; } - -frustum::collision frustum::contains(const sphere<3>& sphere) const +frustum::collision frustum::contains(const sphere3& sphere) const { for (int i = 0; i < 6; ++i) { plane::halfspace halfspace = planes_[i].intersects(sphere); - - if (halfspace == plane::negative) return outside; + if (halfspace == plane::negative) return outside; else if (halfspace == plane::intersecting) return intersecting; } - return inside; } diff --git a/src/moof/frustum.hh b/src/moof/frustum.hh index 1e44701..c603a97 100644 --- a/src/moof/frustum.hh +++ b/src/moof/frustum.hh @@ -1,13 +1,11 @@ -/*] Copyright (c) 2009-2010, Charles McGarvey [************************** +/*] Copyright (c) 2009-2011, Charles McGarvey [***************************** **] All rights reserved. * -* vi:ts=4 sw=4 tw=75 -* * 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_FRUSTUM_HH_ #define _MOOF_FRUSTUM_HH_ @@ -20,17 +18,14 @@ #include #include - namespace moof { - template class aabb; template class sphere; - /** - * A six-sided volume for representing the space visible by a position - * looking outward. + * A six-sided volume for representing the space visible by a position looking + * outward. */ class frustum { @@ -38,8 +33,8 @@ public: enum collision { - outside = 0, - inside = 1, + outside = 0, + inside = 1, intersecting = 2 }; @@ -56,18 +51,16 @@ public: void init(const matrix4& modelview, const matrix4& projection); void init(const matrix4& modelview, scalar fovy, scalar aspect, - scalar abutting, scalar distant); + scalar abutting, scalar distant); collision contains(const aabb<3>& aabb) const; collision contains(const sphere<3>& sphere) const; - private: plane planes_[6]; // left, right, bottom, top, near, far }; - } // namespace moof #endif // _MOOF_FRUSTUM_HH_ diff --git a/src/moof/hash.cc b/src/moof/hash.cc index dbbc9be..ae09b1c 100644 --- a/src/moof/hash.cc +++ b/src/moof/hash.cc @@ -1,13 +1,11 @@ -/*] Copyright (c) 2009-2010, Charles McGarvey [************************** +/*] Copyright (c) 2009-2011, Charles McGarvey [***************************** **] All rights reserved. * -* vi:ts=4 sw=4 tw=75 -* * Distributable under the terms and conditions of the 2-clause BSD license; * see the file COPYING for a complete text of the license. * -**************************************************************************/ +*****************************************************************************/ #include "hash.hh" @@ -31,8 +29,8 @@ namespace moof { // 2. It will not produce the same results on little-endian and big-endian // machines. -unsigned hash_function::operator()(const void* key, int len, - unsigned int seed) const +unsigned +hash_function::operator()(const void* key, int len, unsigned int seed) const { // 'm' and 'r' are mixing constants generated offline. // They're not really 'magic', they just happen to work well. diff --git a/src/moof/hash.hh b/src/moof/hash.hh index ea63db1..8b14ac5 100644 --- a/src/moof/hash.hh +++ b/src/moof/hash.hh @@ -1,13 +1,11 @@ -/*] Copyright (c) 2009-2010, Charles McGarvey [************************** +/*] Copyright (c) 2009-2011, Charles McGarvey [***************************** **] All rights reserved. * -* vi:ts=4 sw=4 tw=75 -* * 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_HASH_HH_ #define _MOOF_HASH_HH_ @@ -27,12 +25,10 @@ namespace moof { using stlplus::hash; - struct hash_function { // generic hash function - unsigned operator () (const void* key, int len, - unsigned seed = -1) const; + unsigned operator () (const void* key, int len, unsigned seed = -1) const; unsigned operator () (const std::string& val) const { diff --git a/src/moof/image.cc b/src/moof/image.cc index b9076f0..09f797c 100644 --- a/src/moof/image.cc +++ b/src/moof/image.cc @@ -1,13 +1,11 @@ -/*] Copyright (c) 2009-2010, Charles McGarvey [************************** +/*] Copyright (c) 2009-2011, Charles McGarvey [***************************** **] All rights reserved. * -* vi:ts=4 sw=4 tw=75 -* * Distributable under the terms and conditions of the 2-clause BSD license; * see the file COPYING for a complete text of the license. * -**************************************************************************/ +*****************************************************************************/ #include // strncmp #include @@ -60,19 +58,20 @@ image::image(const std::string& path) : wrap_s_(GL_CLAMP), wrap_t_(GL_CLAMP) { - std::ifstream file(path.c_str()); - if (!file.good()) throw std::runtime_error("no valid image found at " + path); + std::ifstream file(path.c_str(), std::ifstream::binary); + if (!file.good()) + throw std::runtime_error("no valid image found at " + path); png_byte signature[8]; size_t bytesRead; - int bpp; + int bpp; png_byte colors; png_bytepp rows = 0; png_textp texts = 0; - int nutext_s; + int nutext_s; bytesRead = file.read((char*)signature, sizeof(signature)).gcount(); if (bytesRead < sizeof(signature) || @@ -80,10 +79,11 @@ image::image(const std::string& path) : struct png { - png_structp context; + png_structp context; png_infop info; png() : - context(png_create_read_struct(PNG_LIBPNG_VER_STRING, 0, 0, 0)), + context(png_create_read_struct(PNG_LIBPNG_VER_STRING, + 0, 0, 0)), info(png_create_info_struct(context)) { if (!context || !info) throw 0; @@ -91,7 +91,7 @@ image::image(const std::string& path) : ~png() { png_destroy_read_struct(context ? &context : 0, - info ? &info : 0, 0); + info ? &info : 0, 0); } } png; @@ -105,17 +105,17 @@ image::image(const std::string& path) : colors = png_get_color_type(png.context, png.info); switch (colors) { - case PNG_COLOR_TYPE_PALETTE: - png_set_palette_to_rgb(png.context); - break; + case PNG_COLOR_TYPE_PALETTE: + png_set_palette_to_rgb(png.context); + break; - case PNG_COLOR_TYPE_GRAY: - if (bpp < 8) png_set_expand(png.context); - break; + case PNG_COLOR_TYPE_GRAY: + if (bpp < 8) png_set_expand(png.context); + break; - case PNG_COLOR_TYPE_GRAY_ALPHA: - png_set_gray_to_rgb(png.context); - break; + case PNG_COLOR_TYPE_GRAY_ALPHA: + png_set_gray_to_rgb(png.context); + break; } if (bpp == 16) png_set_strip_16(png.context); @@ -127,14 +127,14 @@ image::image(const std::string& path) : depth_ = bpp * channels_; // read comments - bool isTexture = false; + bool texture = false; png_get_text(png.context, png.info, &texts, &nutext_s); for (int i = 0; i < nutext_s; ++i) { if (strncmp(texts[i].key, "X-Yoink-Texture", 11) == 0) { set_texture_info(texts[i].text); - isTexture = true; + texture = true; break; } } @@ -146,12 +146,13 @@ image::image(const std::string& path) : pixels_ = new char[width_ * pitch_]; rows = new png_bytep[height_]; - if (isTexture) + if (texture) { log_debug("texture detected; loading flipped"); for (int i = 0; i < height_; ++i) { - rows[height_-1-i] = (png_bytep)(pixels_ + i * channels_ * width_); + rows[height_-1-i] = (png_bytep)(pixels_ + + i * channels_ * width_); } } else @@ -159,7 +160,8 @@ image::image(const std::string& path) : log_debug("no texture attributes found"); for (int i = 0; i < height_; ++i) { - rows[i] = (png_bytep)(pixels_ + i * channels_ * width_); + rows[i] = (png_bytep)(pixels_ + + i * channels_ * width_); } } @@ -202,11 +204,9 @@ void image::set_as_icon() const ); SDL_WM_SetIcon(context, 0); - SDL_FreeSurface(context); } - bool image::tile_coordinates(int index, scalar coords[8]) const { // make sure the index represents a real tile @@ -227,7 +227,6 @@ bool image::tile_coordinates(int index, scalar coords[8]) const return true; } - void image::bind() const { ASSERT(video::current() && "should have a video context set"); @@ -251,25 +250,20 @@ void image::reset_binding() global_object_ = 0; } - /* * Upload the image to GL so that it will be accessible by a much more * manageable handle and hopefully reside in video memory. */ void image::upload_to_gl() const { - if (object_) - { - // already loaded - return; - } + if (object_) return; // already loaded glGenTextures(1, (GLuint*)&object_); glBindTexture(GL_TEXTURE_2D, (GLuint)object_); GLuint mode; if (channels_ == 3) mode = GL_RGB; - else mode = GL_RGBA; + else mode = GL_RGBA; glTexImage2D //gluBuild2DMipmaps @@ -299,11 +293,7 @@ void image::unload_from_gl() const { if (object_) { - if (object_ == global_object_) - { - global_object_ = 0; - } - + if (object_ == global_object_) global_object_ = 0; glDeleteTextures(1, (GLuint*)&object_); object_ = 0; } @@ -327,7 +317,6 @@ void image::set_properties() const glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, wrap_t_); } - void image::set_texture_info(const std::string& info) { script script; diff --git a/src/moof/image.hh b/src/moof/image.hh index 6aa251b..62f8699 100644 --- a/src/moof/image.hh +++ b/src/moof/image.hh @@ -1,13 +1,11 @@ -/*] Copyright (c) 2009-2010, Charles McGarvey [************************** +/*] Copyright (c) 2009-2011, Charles McGarvey [***************************** **] All rights reserved. * -* vi:ts=4 sw=4 tw=75 -* * 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_IMAGE_HH_ #define _MOOF_IMAGE_HH_ @@ -33,9 +31,7 @@ public: static const int no_tile = -1; - explicit image(const std::string& path); - ~image(); int width() const @@ -63,7 +59,6 @@ public: return channels_; } - std::string comment() const { return comment_; @@ -74,10 +69,8 @@ public: return pixels_; } - void set_as_icon() const; - /** * Calculate texture coordinates for a tile at a certain index. Tiles * are indexed start with zero as the top-left tile and moving across, @@ -93,11 +86,9 @@ public: */ bool tile_coordinates(int index, scalar coords[8]) const; - void bind() const; static void reset_binding(); - private: void upload_to_gl() const; @@ -106,26 +97,25 @@ private: void set_properties() const; void set_texture_info(const std::string& info); - - char* pixels_; + char* pixels_; mutable unsigned object_; static unsigned global_object_; - int width_; - int height_; - int depth_; - int pitch_; - int channels_; + int width_; + int height_; + int depth_; + int pitch_; + int channels_; - std::string comment_; + std::string comment_; - unsigned min_filter_; - unsigned mag_filter_; - int tile_s_; - int tile_t_; - unsigned wrap_s_; - unsigned wrap_t_; + unsigned min_filter_; + unsigned mag_filter_; + int tile_s_; + int tile_t_; + unsigned wrap_s_; + unsigned wrap_t_; //mutable dispatcher::handle new_context_; }; diff --git a/src/moof/interpolator.hh b/src/moof/interpolator.hh index 0a7aa01..83dd0c9 100644 --- a/src/moof/interpolator.hh +++ b/src/moof/interpolator.hh @@ -1,13 +1,11 @@ -/*] Copyright (c) 2009-2010, Charles McGarvey [************************** +/*] Copyright (c) 2009-2011, Charles McGarvey [***************************** **] All rights reserved. * -* vi:ts=4 sw=4 tw=75 -* * 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_INTERPOLATOR_HH_ #define _MOOF_INTERPOLATOR_HH_ @@ -40,10 +38,9 @@ public: { stop = 0, /// Interpolator will stop when done. repeat = 1, /// Interpolator will go back to the beginning. - oscillate = 2 /// Interpolator will reverse direction. + oscillate = 2 /// Interpolator will reverse direction. }; - /** * Construct an uninitialized interpolator. */ @@ -57,7 +54,8 @@ public: * \param t The duration of the interpolation. * \param mode The interpolation mode. */ - interpolator(const T& a, const T& b, scalar t = 1.0, mode mode = stop) : + interpolator(const T& a, const T& b, + scalar t = 1.0, mode mode = stop) : state_(a), prior_(a), a_(a), @@ -86,7 +84,6 @@ public: is_done_ = false; } - /** * Update the interpolation state with a timeslice. * \param t The total time in seconds. @@ -104,42 +101,40 @@ public: { switch (mode_) { - case stop: - alpha_ = SCALAR(1.0); - is_done_ = true; - break; - case repeat: - alpha_ -= SCALAR(1.0); - break; - case oscillate: - alpha_ = SCALAR(2.0) - alpha_; - scale_ = -scale_; - break; + case stop: + alpha_ = SCALAR(1.0); + is_done_ = true; + break; + case repeat: + alpha_ -= SCALAR(1.0); + break; + case oscillate: + alpha_ = SCALAR(2.0) - alpha_; + scale_ = -scale_; + break; } } else if (alpha_ < 0.0) { switch (mode_) { - case stop: - alpha_ = SCALAR(0.0); - is_done_ = true; - break; - case repeat: - alpha_ += SCALAR(1.0); - break; - case oscillate: - alpha_ = -alpha_; - scale_ = -scale_; - break; + case stop: + alpha_ = SCALAR(0.0); + is_done_ = true; + break; + case repeat: + alpha_ += SCALAR(1.0); + break; + case oscillate: + alpha_ = -alpha_; + scale_ = -scale_; + break; } } - state_ = function_(a_, b_, alpha_); } } - /** * Get the interpolated value. * \return The interpolated value. @@ -169,7 +164,6 @@ public: return is_done_; } - private: T state_; @@ -195,7 +189,6 @@ struct linear_interpolation_function } }; - typedef interpolator lerp_scalar; diff --git a/src/moof/line.hh b/src/moof/line.hh index 0ba6bb3..8f5794d 100644 --- a/src/moof/line.hh +++ b/src/moof/line.hh @@ -1,13 +1,11 @@ -/*] Copyright (c) 2009-2010, Charles McGarvey [************************** +/*] Copyright (c) 2009-2011, Charles McGarvey [***************************** **] All rights reserved. * -* vi:ts=4 sw=4 tw=75 -* * 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_LINE_HH_ #define _MOOF_LINE_HH_ @@ -36,18 +34,15 @@ struct line : public drawable, public shape { typedef moof::vector< scalar, fixed > vector; - vector a; vector b; - line() {} line(const vector& point1, const vector& point2) : a(point1), b(point2) {} - vector direction() const { return b - a; @@ -58,31 +53,31 @@ struct line : public drawable, public shape return direction().length(); } - bool intersect(const line& other, contact& hit) const { scalar d = (other.b[1] - other.a[1]) * (b[0] - a[0]) - - (other.b[0] - other.a[0]) * (b[1] - a[1]); + (other.b[0] - other.a[0]) * (b[1] - a[1]); - if (d == SCALAR(0.0)) return false; // lines are parallel + if (d == SCALAR(0.0)) return false; // lines are parallel // ignoring the (somewhat remote) possibility of coincidence - scalar m = ((other.b[0] - other.a[0]) * (a[1] - other.a[1]) - - (other.b[1] - other.a[1]) * (a[0] - other.a[0])) / d; + scalar m = ((other.b[0] - other.a[0]) * + (a[1] - other.a[1]) - + (other.b[1] - other.a[1]) * + (a[0] - other.a[0])) / d; scalar n = ((b[0] - a[0]) * (b[1] - other.a[1]) - - (b[1] - a[1]) * (b[0] - other.a[0])) / d; + (b[1] - a[1]) * (b[0] - other.a[0])) / d; if (m < SCALAR(0.0) || m > SCALAR(1.0) || // not intersecting - n < SCALAR(0.0) || n > SCALAR(1.0)) return false; + n < SCALAR(0.0) || n > SCALAR(1.0)) + return false; vector2 tangent = b - a; vector2 normal = perp(tangent).normalize(); if (dot(normal, other.a - other.b) < SCALAR(0.0)) - { normal = -normal; - } hit.point = a + m * tangent; hit.normal = normal; @@ -104,7 +99,6 @@ struct line : public drawable, public shape if (projection < SCALAR(0.0) || projection > surfaceLength) { // try endpoints - if (other.intersect(a, hit)) { hit.normal = -hit.normal; @@ -117,7 +111,6 @@ struct line : public drawable, public shape hit.point = b; return true; } - return false; } @@ -126,7 +119,7 @@ struct line : public drawable, public shape scalar distance = normal.length(); - if (distance > other.radius) false; // not intersecting + if (distance > other.radius) false; // not intersecting normal.normalize(); @@ -137,8 +130,8 @@ struct line : public drawable, public shape return true; } - - bool intersect_ray(const ray<2>& ray, moof::ray<2>::contact& hit) const + bool + intersect_ray(const ray<2>& ray, moof::ray<2>::contact& hit) const { vector2 v1 = a - ray.point; scalar a1 = signed_angle_2D(v1, b - ray.point); @@ -170,7 +163,6 @@ struct line : public drawable, public shape hit.normal = perp(a - b); return true; - /* // solve: Cx + r*Dx = Ax + s(Bx - Ax) // Cy + r*Dy = Ay + s(By - Ay) @@ -222,7 +214,6 @@ struct line : public drawable, public shape */ } - void draw(scalar alpha = 0.0) const { image::reset_binding(); @@ -233,7 +224,6 @@ struct line : public drawable, public shape } }; - typedef line<2> line2; typedef line<3> line3; @@ -248,7 +238,7 @@ struct polygon : public drawable, public shape polygon() {} bool intersect_ray(const ray& ray, - typename moof::ray::contact& hit) + typename moof::ray::contact& hit) { return false; } @@ -257,22 +247,17 @@ struct polygon : public drawable, public shape { image::reset_binding(); glBegin(GL_POLYGON); - for (int i = 0; i < D; ++i) - { - glVertex(points[0]); - } + for (int i = 0; i < D; ++i) glVertex(points[0]); glEnd(); } }; - typedef polygon<2,3> triangle2; typedef polygon<3,3> triangle3; template -bool intersect(const line& line, const sphere& sphere, - contact& hit) +bool intersect(const line& line, const sphere& sphere, contact& hit) { return false; } diff --git a/src/moof/log.cc b/src/moof/log.cc index d0acf2e..5146496 100644 --- a/src/moof/log.cc +++ b/src/moof/log.cc @@ -1,23 +1,24 @@ -/*] Copyright (c) 2009-2010, Charles McGarvey [************************** +/*] Copyright (c) 2009-2011, Charles McGarvey [***************************** **] All rights reserved. * -* vi:ts=4 sw=4 tw=75 -* * Distributable under the terms and conditions of the 2-clause BSD license; * see the file COPYING for a complete text of the license. * -**************************************************************************/ +*****************************************************************************/ + +#if HAVE_INCLUDE_H +#include "config.h" +#endif #include -#if !defined(__WIN32) +#if PLATFORM_POSIX #include #else inline int isatty(int dummy) { return 0; } #endif - #include "log.hh" #include "script.hh" @@ -38,27 +39,29 @@ enum log::level log::level() return global_level_; } - log::log(enum level level) : level_(level) { if (isatty(1) == 0) switch (level) { - case log::error: prefix_ = " error: "; break; - case log::warning: prefix_ = "warning: "; break; - case log::info: prefix_ = " info: "; break; - case log::debug: prefix_ = " debug: "; break; - case log::none: break; + case log::error: prefix_ = " error: "; break; + case log::warning: prefix_ = "warning: "; break; + case log::info: prefix_ = " info: "; break; + case log::debug: prefix_ = " debug: "; break; + case log::none: break; } else switch (level) { - case log::error: prefix_ = "\033[30;101m error: "; break; - case log::warning: prefix_ = "\033[30;103mwarning: "; break; - case log::info: prefix_ = " info: "; break; - case log::debug: prefix_ = "\033[2m debug: "; break; - case log::none: break; + case log::error: prefix_ = "\033[30;101m error: "; + break; + case log::warning: prefix_ = "\033[30;103mwarning: "; + break; + case log::info: prefix_ = " info: "; + break; + case log::debug: prefix_ = "\033[2m debug: "; + case log::none: break; } } @@ -66,22 +69,20 @@ std::ostream& operator << (class log& log, log::endl_ endl) { if (log::global_level_ < log.level_) return null_log; if (isatty(1) == 0) return moof::log << std::endl; - else return moof::log << "\033[0m" << std::endl; + return moof::log << "\033[0m" << std::endl; } std::ostream& operator << (std::ostream& stream, log::endl_ endl) { if (isatty(1) == 0) return stream << std::endl; - else return stream << "\033[0m" << std::endl; + return stream << "\033[0m" << std::endl; } - std::ostream& log(std::cout); static std::ofstream null_log_; std::ostream& null_log(null_log_); - // These objects are intentionally not deconstructed so that logging will // still be available after this module has been cleaned up. class log& log_error(*new class log(log::error)); @@ -89,7 +90,6 @@ class log& log_warning(*new class log(log::warning)); class log& log_info(*new class log(log::info)); class log& log_debug(*new class log(log::debug)); - static int log_script(script& script, enum log::level level) { static class log* logs[] = { @@ -102,8 +102,7 @@ static int log_script(script& script, enum log::level level) script::slot param = script[1]; - while (!param.is_none()) - { + while (!param.is_none()) { (*logs[level])(param); ++param.index; } @@ -114,15 +113,15 @@ static int log_script(script& script, enum log::level level) void log::import(script& script) { script.import_function("LogError", - boost::bind(log_script, _1, log::error)); + boost::bind(log_script, _1, log::error)); script.import_function("LogWarning", - boost::bind(log_script, _1, log::warning)); + boost::bind(log_script, _1, log::warning)); script.import_function("LogInfo", - boost::bind(log_script, _1, log::info)); + boost::bind(log_script, _1, log::info)); script.import_function("print", - boost::bind(log_script, _1, log::info)); + boost::bind(log_script, _1, log::info)); script.import_function("LogDebug", - boost::bind(log_script, _1, log::debug)); + boost::bind(log_script, _1, log::debug)); } diff --git a/src/moof/log.hh b/src/moof/log.hh index cad63e9..addf37c 100644 --- a/src/moof/log.hh +++ b/src/moof/log.hh @@ -1,22 +1,20 @@ -/*] Copyright (c) 2009-2010, Charles McGarvey [************************** +/*] Copyright (c) 2009-2011, Charles McGarvey [***************************** **] All rights reserved. * -* vi:ts=4 sw=4 tw=75 -* * 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_LOG_HH_ #define _MOOF_LOG_HH_ /** * \file log.hh - * Functions related to logging the process. - * The logging functions are log_error(), log_warning(), and log_info(), - * listed from most critical to least critical. + * Functions related to logging the process. The logging functions are + * log_error(), log_warning(), and log_info(), listed from most critical to + * least critical. */ #include // exit @@ -27,9 +25,9 @@ namespace moof { +// forward declarations class script; - /** * A class for handling a log priority. There are two ways to log * messages: by treating a log object as a function whose parameters are @@ -46,14 +44,13 @@ public: */ enum level { - none = 0, ///< Disable all logging. - error = 1, ///< Log only errors. - warning = 2, ///< Log warnings and errors. - info = 3, ///< Log everything. - debug = 4, ///< Log absolutely everything. + none = 0, ///< Disable all logging. + error = 1, ///< Log only errors. + warning = 2, ///< Log warnings and errors. + info = 3, ///< Log everything. + debug = 4, ///< Log absolutely everything. }; - /** * Set the lowest-priority log message that will be outputted to the * log. Any logging with a lower priority will be ignored. @@ -68,14 +65,12 @@ public: */ static enum level level(); - /** * Import log functions to a script. * \param The script. */ static void import(script& script); - /** * Construct a log with a certain priority and prefix string. * \param level The log level. @@ -83,7 +78,6 @@ public: */ log(enum level level); - /** * Output this to end a line. This is equivalent to std::endl except * this will also reset terminal format attributes. @@ -92,7 +86,6 @@ public: { } endl; - template void operator () (const A& a) { @@ -119,19 +112,15 @@ public: template void operator () (const A& a, - const B& b, - const C& c, - const D& d, - const E& e) + const B& b, + const C& c, + const D& d, + const E& e) { - *this << a << " " - << b << " " - << c << " " - << d << " " - << e << endl; + *this << a << " " << b << " " << c << " " << d << " " << e << + endl; } - private: template friend std::ostream& operator << (log&, const T&); @@ -139,11 +128,10 @@ private: static enum level global_level_; - enum level level_; - std::string prefix_; + enum level level_; + std::string prefix_; }; - extern std::ostream& log; extern std::ostream& null_log; diff --git a/src/moof/manager.hh b/src/moof/manager.hh index 98b102d..a3963e8 100644 --- a/src/moof/manager.hh +++ b/src/moof/manager.hh @@ -1,13 +1,11 @@ -/*] Copyright (c) 2009-2010, Charles McGarvey [************************** +/*] Copyright (c) 2009-2011, Charles McGarvey [***************************** **] All rights reserved. * -* vi:ts=4 sw=4 tw=75 -* * 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_MANAGER_HH_ #define _MOOF_MANAGER_HH_ @@ -47,7 +45,6 @@ public: return boost::shared_ptr(retain(name), &release); } - private: typedef stlplus::hash ptr_lookup; @@ -68,7 +65,8 @@ private: { new_object->name_ = name; new_object->init(name); - ptr_lookup_.insert(std::make_pair(name, new_object)); + ptr_lookup_.insert(std::make_pair(name, + new_object)); } return new_object; } @@ -85,8 +83,8 @@ private: static ptr_lookup ptr_lookup_; - std::string name_; - unsigned retain_count_; + std::string name_; + unsigned retain_count_; }; template diff --git a/src/moof/math.hh b/src/moof/math.hh index 14e8c78..e7cd3f0 100644 --- a/src/moof/math.hh +++ b/src/moof/math.hh @@ -1,13 +1,11 @@ -/*] Copyright (c) 2009-2010, Charles McGarvey [************************** +/*] Copyright (c) 2009-2011, Charles McGarvey [***************************** **] All rights reserved. * -* vi:ts=4 sw=4 tw=75 -* * 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_MATH_HH_ #define _MOOF_MATH_HH_ @@ -17,14 +15,15 @@ * General math-related types and functions. */ +#if HAVE_CONFIG_H #include "config.h" +#endif #include #include #include - #if ENABLE_DOUBLE_PRECISION typedef GLdouble GLscalar; #define GL_SCALAR GL_DOUBLE @@ -41,7 +40,6 @@ namespace moof { using namespace cml; - typedef GLscalar scalar; typedef vector< scalar, fixed<2> > vector2; @@ -52,11 +50,10 @@ typedef matrix< scalar, fixed<2,2>, col_basis, col_major > matrix2; typedef matrix< scalar, fixed<3,3>, col_basis, col_major > matrix3; typedef matrix< scalar, fixed<4,4>, col_basis, col_major > matrix4; -typedef quaternion< scalar, fixed<>, vector_first, positive_cross > quaternion; +typedef quaternion< scalar, fixed<>, vector_first, positive_cross > quaternion; typedef constants constants; - inline vector3 demote(const vector4& vec) { return vector3(vec[0], vec[1], vec[2]); @@ -90,10 +87,10 @@ inline bool is_equal(scalar a, scalar b, scalar epsilon = EPSILON) } -// Here are some generic implementations of a few simple integrators. To -// use, you need one type representing the state and another containing the -// derivatives of the primary state variables. The state class must -// implement these methods: +// Here are some generic implementations of a few simple integrators. To use, +// you need one type representing the state and another containing the +// derivatives of the primary state variables. The state class must implement +// these methods: // // void calculate_derivative(Derivative_Type& derivative, scalar absoluteTime); // void step(const Derivative_Type& derivative, scalar deltaTime); @@ -118,12 +115,10 @@ inline D evaluate(S state, scalar t, scalar dt, const D& derivative) return evaluate(state, t + dt); } - template inline void euler(S& state, scalar t, scalar dt) { D a = evaluate(state, t); - state.step(a, dt); } @@ -132,7 +127,6 @@ inline void rk2(S& state, scalar t, scalar dt) { D a = evaluate(state, t); D b = evaluate(state, t, dt * SCALAR(0.5), a); - state.step(b, dt); } @@ -143,7 +137,6 @@ inline void rk4(S& state, scalar t, scalar dt) D b = evaluate(state, t, dt * SCALAR(0.5), a); D c = evaluate(state, t, dt * SCALAR(0.5), b); D d = evaluate(state, t, dt, c); - state.step((a + (b + c) * SCALAR(2.0) + d) * SCALAR(1.0/6.0), dt); } diff --git a/src/moof/mesh.cc b/src/moof/mesh.cc index e380adf..32550f7 100644 --- a/src/moof/mesh.cc +++ b/src/moof/mesh.cc @@ -1,13 +1,11 @@ -/*] Copyright (c) 2009-2010, Charles McGarvey [************************** +/*] Copyright (c) 2009-2011, Charles McGarvey [***************************** **] All rights reserved. * -* vi:ts=4 sw=4 tw=75 -* * Distributable under the terms and conditions of the 2-clause BSD license; * see the file COPYING for a complete text of the license. * -**************************************************************************/ +*****************************************************************************/ #include #include @@ -18,8 +16,6 @@ #include #include -#include - #include "debug.hh" #include "log.hh" #include "mesh.hh" @@ -27,9 +23,8 @@ // TODO: this file needs to be cleaned up - -#define AC3D_FORMAT_VERSION (0x0b) -#define ZLIB_BUF_SIZE (262114) +#define AC3D_FORMAT_VERSION 0x0b +#define ZLIB_BUF_SIZE 262114 namespace moof { @@ -37,22 +32,17 @@ namespace moof { MOOF_REGISTER_RESOURCE(mesh, ac, models); - static std::string read_string(std::istream& stream) { std::string str; char atom; - do // skip to the next non-space character - { - stream.get(atom); - } + do stream.get(atom); while (stream && std::isspace(atom)); if (atom == '"') { - do - { + do { stream.get(atom); if (atom == '"') break; str += atom; @@ -61,8 +51,7 @@ static std::string read_string(std::istream& stream) } else { - do - { + do { stream.get(atom); if (std::isspace(atom)) break; str += atom; @@ -73,7 +62,7 @@ static std::string read_string(std::istream& stream) return str; } -inline int read_hex(std::istream& stream) +static int read_hex(std::istream& stream) { int hex; std::ios::fmtflags flags = stream.flags(); @@ -83,21 +72,21 @@ inline int read_hex(std::istream& stream) return hex; } -inline vector2 read_pair(std::istream& stream) +static vector2 read_pair(std::istream& stream) { vector2 triplet; stream >> triplet[0] >> triplet[1]; return triplet; } -inline vector3 read_triplet(std::istream& stream) +static vector3 read_triplet(std::istream& stream) { vector3 triplet; stream >> triplet[0] >> triplet[1] >> triplet[2]; return triplet; } -inline vector4 read_color(std::istream& stream) +static vector4 read_color(std::istream& stream) { vector4 color; stream >> color[0] >> color[1] >> color[2]; @@ -105,12 +94,10 @@ inline vector4 read_color(std::istream& stream) return color; } - void mesh::import(std::istream& stream) { - std::string atom; - - object_ptr obj; + std::string atom; + object_ptr obj; std::stack kids; // read and verify the AC3D header @@ -379,12 +366,10 @@ void mesh::import(std::istream& stream) //face.triangles.push_back(vert); //} - - mesh::mesh(const std::string& path) { std::ifstream file(path.c_str(), std::ifstream::in | - std::ifstream::binary); + std::ifstream::binary); if (!file) throw std::runtime_error("cannot find mesh file"); // if we can read the header, the file isn't compressed @@ -394,7 +379,6 @@ mesh::mesh(const std::string& path) { log_info("text mesh detected"); file.seekg(std::ios::beg); - import(file); } else @@ -415,31 +399,30 @@ mesh::mesh(const std::string& path) zstream.next_in = Z_NULL; int result = inflateInit2(&zstream, 32+MAX_WBITS); - if (result != Z_OK) throw std::runtime_error("zlib init error"); + if (result != Z_OK) + throw std::runtime_error("zlib init error"); - do - { + do { file.read(in, sizeof(in)); zstream.next_in = (Bytef*)in; zstream.avail_in = file.gcount(); if (zstream.avail_in == 0) break; - do - { + do { zstream.next_out = (Bytef*)out; zstream.avail_out = sizeof(out); result = inflate(&zstream, Z_NO_FLUSH); switch (result) { - case Z_NEED_DICT: - case Z_DATA_ERROR: - case Z_MEM_ERROR: - inflateEnd(&zstream); - throw std::runtime_error("zlib inflate error"); - case Z_STREAM_ERROR: - throw std::runtime_error("zlib stream error"); + case Z_NEED_DICT: + case Z_DATA_ERROR: + case Z_MEM_ERROR: + inflateEnd(&zstream); + throw std::runtime_error("zlib inflate error"); + case Z_STREAM_ERROR: + throw std::runtime_error("zlib stream error"); } int inflated = sizeof(out) - zstream.avail_out; @@ -450,12 +433,10 @@ mesh::mesh(const std::string& path) while(result != Z_STREAM_END); inflateEnd(&zstream); - import(stream); } } - void mesh::draw(scalar alpha) const { glEnableClientState(GL_VERTEX_ARRAY); @@ -469,7 +450,6 @@ void mesh::draw(scalar alpha) const // TODO: disable vertex array? } - void mesh::set_material(int index) const { set_material(materials_[index]); @@ -485,7 +465,6 @@ void mesh::set_material(const material& material) const glMaterial(GL_FRONT, GL_SHININESS, material.shininess); } - void mesh::object::draw(scalar alpha, bool recurse) const { glVertexPointer(verts); @@ -516,13 +495,10 @@ void mesh::object::draw(scalar alpha, bool recurse) const { std::vector::const_iterator jt; for (jt = kids.begin(); jt != kids.end(); ++jt) - { (*jt)->draw(alpha); - } } } - //class mesh_resource_loader //{ //public: diff --git a/src/moof/mesh.hh b/src/moof/mesh.hh index 0fbc3cc..26accec 100644 --- a/src/moof/mesh.hh +++ b/src/moof/mesh.hh @@ -1,13 +1,11 @@ -/*] Copyright (c) 2009-2010, Charles McGarvey [************************** +/*] Copyright (c) 2009-2011, Charles McGarvey [***************************** **] All rights reserved. * -* vi:ts=4 sw=4 tw=75 -* * 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_MESH_HH_ #define _MOOF_MESH_HH_ @@ -34,9 +32,9 @@ namespace moof { +// forward declarations class script; - class mesh : public boost::noncopyable, public entity { public: @@ -45,23 +43,19 @@ public: void draw(scalar alpha = SCALAR(0.0)) const; - struct material { material(const std::string& id) : name(id) {} - + scalar shininess; std::string name; - - vector4 diffuse; vector4 ambient; + vector4 diffuse; vector4 emissive; vector4 specular; - scalar shininess; }; - void set_material(int index) const; void set_material(const material& material) const; @@ -71,7 +65,6 @@ public: std::vector triangles_uv; }; - class object; typedef boost::shared_ptr object_ptr; typedef boost::weak_ptr object_weakptr; @@ -87,33 +80,31 @@ public: return object_ptr(new object(m)); } - void draw(scalar alpha = SCALAR(0.0), bool recurse = true) const; - + void + draw(scalar alpha = SCALAR(0.0), bool recurse = true) const; - const moof::mesh& mesh; + const moof::mesh& mesh; - std::string name; - std::string data; - std::string url; + std::string name; + std::string data; + std::string url; - image_handle texture; - vector2 texrep; + image_handle texture; + vector2 texrep; - std::vector verts; - std::vector faces; + std::vector verts; + std::vector faces; - std::vector kids; - std::map kids_byname; - object_weakptr parent; + std::vector kids; + std::map kids_byname; + object_weakptr parent; }; - object_ptr operator [] (unsigned index) const { return objects_[index]; } - /** * Import script bindings for the mesh class. * \param The script. @@ -121,7 +112,6 @@ public: */ static void import(script& script, const std::string& nspace = ""); - private: void import(std::istream& stream); diff --git a/src/moof/mesh_bindings.cc b/src/moof/mesh_bindings.cc index 02138ad..8c9f9e0 100644 --- a/src/moof/mesh_bindings.cc +++ b/src/moof/mesh_bindings.cc @@ -1,13 +1,11 @@ -/*] Copyright (c) 2009-2010, Charles McGarvey [************************** +/*] Copyright (c) 2009-2011, Charles McGarvey [***************************** **] All rights reserved. * -* vi:ts=4 sw=4 tw=75 -* * Distributable under the terms and conditions of the 2-clause BSD license; * see the file COPYING for a complete text of the license. * -**************************************************************************/ +*****************************************************************************/ #include "log.hh" #include "mesh.hh" @@ -37,8 +35,10 @@ static int mesh_draw(script& script) script[1].require_object("mesh").get(mesh); scalar alpha; - if (script[2].get(alpha)) (*mesh)->draw(alpha); - else (*mesh)->draw(); + if (script[2].get(alpha)) + (*mesh)->draw(alpha); + else + (*mesh)->draw(); return 0; } @@ -70,17 +70,19 @@ static int object_draw(script& script) mesh::object_ptr* object; script[1].require_object("mesh object").get(object); - scalar alpha; - bool recurse; - if (script[2].get(alpha)) - { - if (script[3].get(recurse)) (*object)->draw(alpha, recurse); - else (*object)->draw(alpha); + scalar alpha; + bool recurse; + if (script[2].get(alpha)) { + if (script[3].get(recurse)) + (*object)->draw(alpha, recurse); + else + (*object)->draw(alpha); } - else - { - if (script[2].get(recurse)) (*object)->draw(SCALAR(0.0), recurse); - else (*object)->draw(); + else { + if (script[2].get(recurse)) + (*object)->draw(SCALAR(0.0), recurse); + else + (*object)->draw(); } return 0; @@ -91,21 +93,18 @@ static int object_index(script& script) mesh::object_ptr* object; script[1].require_object("mesh object").get(object); - if (script[2].is_number()) - { + if (script[2].is_number()) { unsigned index; script[2].get(index); --index; script.push((*object)->kids[index]); } - else if (script[2].is_string()) - { + else if (script[2].is_string()) { std::string name; script[2].get(name); script.push((*object)->kids_byname[name]); } - else - { + else { script[2].raise_type_error("index or name"); } return 1; diff --git a/src/moof/modal_dialog.hh b/src/moof/modal_dialog.hh index 4498692..4afeb39 100644 --- a/src/moof/modal_dialog.hh +++ b/src/moof/modal_dialog.hh @@ -1,13 +1,11 @@ -/*] Copyright (c) 2009-2010, Charles McGarvey [************************** +/*] Copyright (c) 2009-2011, Charles McGarvey [***************************** **] All rights reserved. * -* vi:ts=4 sw=4 tw=75 -* * 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_MODAL_DIALOG_HH_ #define _MOOF_MODAL_DIALOG_HH_ @@ -18,7 +16,9 @@ * supported, but only one can be used as determined at build time. */ +#if HAVE_CONFIG_H #include "config.h" +#endif #include @@ -42,7 +42,6 @@ namespace moof { /** * Small wrapper over various user interface modal dialog windows. */ - struct modal_dialog { enum type @@ -52,12 +51,10 @@ struct modal_dialog error = 3 }; - - std::string title; + std::string title; type type; - std::string text1; - std::string text2; - + std::string text1; + std::string text2; /** * Construct a dialog box. @@ -67,84 +64,80 @@ struct modal_dialog * \param text2 The second line. */ modal_dialog(enum type type = information, - const std::string& title = "", - const std::string& text1 = "", - const std::string& text2 = "") : + const std::string& title = "", + const std::string& text1 = "", + const std::string& text2 = "") : title(title), type(type), text1(text1), text2(text2) {} - void run() const { switch (type) { - case warning: - log_warning(text1); - log_warning(text2); - break; - case error: - log_error(text1); - log_error(text2); - break; - default: - log_info(text1); - log_info(text2); - break; + case warning: + log_warning(text1); + log_warning(text2); + break; + case error: + log_error(text1); + log_error(text2); + break; + default: + log_info(text1); + log_info(text2); + break; } #if PLATFORM_WIN32 - int icon_type; switch (type) { - case warning: - icon_type = MB_ICONWARNING; - break; - case error: - icon_type = MB_ICONERROR; - break; - default: - icon_type = MB_ICONINFORMATION; - break; + case warning: + icon_type = MB_ICONWARNING; + break; + case error: + icon_type = MB_ICONERROR; + break; + default: + icon_type = MB_ICONINFORMATION; + break; } MessageBox(0, (text1 + "\n" + text2).c_str(), title.c_str(), MB_OK | icon_type); - #elif WITH_GUI_GTK - - int argc = 0; + int argc = 0; char** argv; gtk_init(&argc, &argv); GtkMessageType icon_type; switch (type) { - case warning: - icon_type = GTK_MESSAGE_WARNING; - break; - case error: - icon_type = GTK_MESSAGE_ERROR; - break; - default: - icon_type = GTK_MESSAGE_INFO; - break; + case warning: + icon_type = GTK_MESSAGE_WARNING; + break; + case error: + icon_type = GTK_MESSAGE_ERROR; + break; + default: + icon_type = GTK_MESSAGE_INFO; + break; } GtkWidget* dialog = gtk_message_dialog_new(NULL, GTK_DIALOG_DESTROY_WITH_PARENT, icon_type, GTK_BUTTONS_CLOSE, "%s", text1.c_str()); gtk_message_dialog_format_secondary_text(GTK_MESSAGE_DIALOG(dialog), - "%s", text2.c_str()); + "%s", text2.c_str()); gtk_window_set_title(GTK_WINDOW(dialog), title.c_str()); - std::string icon_path = resource::find_file(PACKAGE".png"); + std::string icon_path = resource::find_file(PACKAGE_TARNAME".png"); if (!icon_path.empty()) { GdkPixbuf* iconPixbuf = gdk_pixbuf_new_from_file(icon_path.c_str(), - NULL); + NULL); gtk_window_set_icon(GTK_WINDOW(dialog), iconPixbuf); } @@ -152,25 +145,23 @@ struct modal_dialog gtk_widget_destroy(dialog); // FIXME - this doesn't seem to actually remove the window from the // screen when it closes - #elif WITH_GUI_QT4 - - int argc = 0; + int argc = 0; char** argv; QApplication qt_app(argc, argv); QMessageBox::Icon icon_type; switch (type) { - case warning: - icon_type = QMessageBox::Warning; - break; - case error: - icon_type = QMessageBox::Critical; - break; - default: - icon_type = QMessageBox::Information; - break; + case warning: + icon_type = QMessageBox::Warning; + break; + case error: + icon_type = QMessageBox::Critical; + break; + default: + icon_type = QMessageBox::Information; + break; } QMessageBox dialog; @@ -180,7 +171,7 @@ struct modal_dialog dialog.setInformativeText(text2.c_str()); dialog.setStandardButtons(QMessageBox::Close); - std::string icon_path = resource::find_file(PACKAGE".png"); + std::string icon_path = resource::find_file(PACKAGE_TARNAME".png"); if (!icon_path.empty()) { QIcon icon(icon_path.c_str()); @@ -188,7 +179,6 @@ struct modal_dialog } dialog.exec(); - #endif } }; diff --git a/src/moof/network.hh b/src/moof/network.hh index 38502d3..998473b 100644 --- a/src/moof/network.hh +++ b/src/moof/network.hh @@ -1,13 +1,11 @@ -/*] Copyright (c) 2009-2010, Charles McGarvey [************************** +/*] Copyright (c) 2009-2011, Charles McGarvey [***************************** **] All rights reserved. * -* vi:ts=4 sw=4 tw=75 -* * 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_NETWORK_HH_ #define _MOOF_NETWORK_HH_ diff --git a/src/moof/opengl.hh b/src/moof/opengl.hh index 3367bc8..6eeb553 100644 --- a/src/moof/opengl.hh +++ b/src/moof/opengl.hh @@ -1,24 +1,24 @@ -/*] Copyright (c) 2009-2010, Charles McGarvey [************************** +/*] Copyright (c) 2009-2011, Charles McGarvey [***************************** **] All rights reserved. * -* vi:ts=4 sw=4 tw=75 -* * 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_OPENGL_HH_ #define _MOOF_OPENGL_HH_ /** * \file opengl.hh - * Defines macros for OpenGL functions that operate on scalars, vectors, - * and matrices. + * Defines macros for OpenGL functions that operate on scalars, vectors, and + * matrices. */ +#if HAVE_CONFIG_H #include "config.h" +#endif #include @@ -58,54 +58,51 @@ #define ARGS_V4 const moof::vector4& v #define PASS_V4 v[0], v[1], v[2], v[3] - #if ENABLE_DOUBLE_PRECISION -#define OPENGL_GENERIC_FUNC(R, N, L) \ +#define OPENGL_GENERIC_FUNC(R, N, L) \ inline R gl##N(ARGS_##L) { gl##N##d(PASS_##L); }// -#define OPENGL_ORDINAL_FUNC(R, N, K) \ - inline R gl##N(ARGS_##S##K) { gl##N##K##d(PASS_##S##K); } \ +#define OPENGL_ORDINAL_FUNC(R, N, K) \ + inline R gl##N(ARGS_##S##K) { gl##N##K##d(PASS_##S##K); } \ inline R gl##N(ARGS_##P##K) { gl##N##K##d##v(PASS_##P##K); }// #else -#define OPENGL_GENERIC_FUNC(R, N, L) \ +#define OPENGL_GENERIC_FUNC(R, N, L) \ inline R gl##N(ARGS_##L) { gl##N##f(PASS_##L); }// -#define OPENGL_ORDINAL_FUNC(R, N, K) \ - inline R gl##N(ARGS_##S##K) { gl##N##K##f(PASS_##S##K); } \ +#define OPENGL_ORDINAL_FUNC(R, N, K) \ + inline R gl##N(ARGS_##S##K) { gl##N##K##f(PASS_##S##K); } \ inline R gl##N(ARGS_##P##K) { gl##N##K##f##v(PASS_##P##K); }// #endif +OPENGL_GENERIC_FUNC(void, LoadMatrix, P); +OPENGL_GENERIC_FUNC(void, LoadMatrix, M); +OPENGL_GENERIC_FUNC(void, MultMatrix, P); +OPENGL_GENERIC_FUNC(void, MultMatrix, M); + +OPENGL_GENERIC_FUNC(void, Scale, S3); +OPENGL_GENERIC_FUNC(void, Scale, V3); +OPENGL_GENERIC_FUNC(void, Rotate, S4); +OPENGL_GENERIC_FUNC(void, Rotate, V4); +OPENGL_GENERIC_FUNC(void, Translate, S3); +OPENGL_GENERIC_FUNC(void, Translate, V3); -OPENGL_GENERIC_FUNC(void, LoadMatrix, P); -OPENGL_GENERIC_FUNC(void, LoadMatrix, M); -OPENGL_GENERIC_FUNC(void, MultMatrix, P); -OPENGL_GENERIC_FUNC(void, MultMatrix, M); - -OPENGL_GENERIC_FUNC(void, Scale, S3); -OPENGL_GENERIC_FUNC(void, Scale, V3); -OPENGL_GENERIC_FUNC(void, Rotate, S4); -OPENGL_GENERIC_FUNC(void, Rotate, V4); -OPENGL_GENERIC_FUNC(void, Translate, S3); -OPENGL_GENERIC_FUNC(void, Translate, V3); - -OPENGL_ORDINAL_FUNC(void, Color, 3); -OPENGL_ORDINAL_FUNC(void, Color, 4); +OPENGL_ORDINAL_FUNC(void, Color, 3); +OPENGL_ORDINAL_FUNC(void, Color, 4); -OPENGL_ORDINAL_FUNC(void, Vertex, 2); -OPENGL_ORDINAL_FUNC(void, Vertex, 3); -OPENGL_ORDINAL_FUNC(void, Vertex, 4); +OPENGL_ORDINAL_FUNC(void, Vertex, 2); +OPENGL_ORDINAL_FUNC(void, Vertex, 3); +OPENGL_ORDINAL_FUNC(void, Vertex, 4); -OPENGL_ORDINAL_FUNC(void, TexCoord, 2); -OPENGL_ORDINAL_FUNC(void, TexCoord, 3); -OPENGL_ORDINAL_FUNC(void, TexCoord, 4); - -OPENGL_GENERIC_FUNC(void, Rect, S4); -OPENGL_GENERIC_FUNC(void, Rect, V4); +OPENGL_ORDINAL_FUNC(void, TexCoord, 2); +OPENGL_ORDINAL_FUNC(void, TexCoord, 3); +OPENGL_ORDINAL_FUNC(void, TexCoord, 4); +OPENGL_GENERIC_FUNC(void, Rect, S4); +OPENGL_GENERIC_FUNC(void, Rect, V4); inline void glMaterial(GLenum face, GLenum pname, moof::scalar s) { @@ -136,12 +133,14 @@ inline void glDrawElements(GLenum type, const std::vector& v) glDrawElements(type, v.size(), GL_UNSIGNED_INT, &v[0]); } - +inline void glGetScalar(GLenum a, GLscalar* b) +{ #if ENABLE_DOUBLE_PRECISION -inline void glGetScalar(GLenum a, GLscalar* b) { glGetDoublev(a, b); } + glGetDoublev(a, b); #else -inline void glGetScalar(GLenum a, GLscalar* b) { glGetFloatv(a, b); } + glGetFloatv(a, b); #endif +} #endif // _MOOF_OPENGL_HH_ diff --git a/src/moof/plane.cc b/src/moof/plane.cc index 4a175b0..dc9ce2d 100644 --- a/src/moof/plane.cc +++ b/src/moof/plane.cc @@ -1,13 +1,11 @@ -/*] Copyright (c) 2009-2010, Charles McGarvey [************************** +/*] Copyright (c) 2009-2011, Charles McGarvey [***************************** **] All rights reserved. * -* vi:ts=4 sw=4 tw=75 -* * Distributable under the terms and conditions of the 2-clause BSD license; * see the file COPYING for a complete text of the license. * -**************************************************************************/ +*****************************************************************************/ #include "aabb.hh" #include "plane.hh" @@ -17,33 +15,29 @@ namespace moof { -plane::halfspace plane::intersects(const aabb<3>& aabb) const +plane::halfspace plane::intersects(const aabb3& aabb) const { - vector3 corners[8]; int nPositive = 8; - + vector3 corners[8]; aabb.get_corners(corners); for (int i = 0; i < 8; ++i) { - if (intersects(corners[i]) == negative) - { - --nPositive; - } + if (intersects(corners[i]) == negative) --nPositive; } - if (nPositive == 0) return negative; + if (nPositive == 0) return negative; else if (nPositive == 8) return positive; - else return intersecting; + return intersecting; } -plane::halfspace plane::intersects(const sphere<3>& sphere) const +plane::halfspace plane::intersects(const sphere3& sphere) const { scalar distance = distance_to_point(sphere.point); - if (distance < -sphere.radius) return negative; + if (distance < -sphere.radius) return negative; else if (distance < sphere.radius) return intersecting; - else return positive; + return positive; } diff --git a/src/moof/plane.hh b/src/moof/plane.hh index 5605831..83b5517 100644 --- a/src/moof/plane.hh +++ b/src/moof/plane.hh @@ -1,13 +1,11 @@ -/*] Copyright (c) 2009-2010, Charles McGarvey [************************** +/*] Copyright (c) 2009-2011, Charles McGarvey [***************************** **] All rights reserved. * -* vi:ts=4 sw=4 tw=75 -* * 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_PLANE_HH_ #define _MOOF_PLANE_HH_ @@ -24,13 +22,13 @@ namespace moof { +// forward declarations template class aabb; template class sphere; - /** - * A plane in 3-space defined by the equation Ax + By + Cz = D, where [A, - * B, C] is normal to the plane. + * A plane in 3-space defined by the equation Ax + By + Cz = D, where [A, B, + * C] is normal to the plane. */ struct plane : public shape<3> { @@ -39,9 +37,9 @@ struct plane : public shape<3> enum halfspace { - negative = -1, + negative = -1, intersecting = 0, - positive = 1 + positive = 1 }; plane() {} @@ -52,7 +50,6 @@ struct plane : public shape<3> normal(a, b, c), d(scalar) {} - bool intersect_ray(const ray3& ray, ray3::contact& hit) { // solve: [(ray.point + t*ray.direction) dot normal] + d = 0 @@ -79,11 +76,10 @@ struct plane : public shape<3> if (hit.distance < SCALAR(0.0)) return false; if (numer >= 0.0) hit.normal = normal; - else hit.normal = -normal; + else hit.normal = -normal; return true; } - /* Causes the normal of the plane to become normalized. The scalar may * also be changed to keep the equation true. Word to the wise: don't * normalize a plane if the normal is the zero vector. @@ -91,7 +87,6 @@ struct plane : public shape<3> void normalize() { scalar mag = normal.length(); - normal /= mag; d /= mag; } @@ -109,8 +104,8 @@ struct plane : public shape<3> scalar distance = distance_to_point(point); if (is_equal(distance, 0.0)) return intersecting; - else if (distance < 0.0) return negative; - else return positive; + else if (distance < 0.0) return negative; + return positive; } halfspace intersects(const aabb<3>& aabb) const; diff --git a/src/moof/ray.hh b/src/moof/ray.hh index b1f7bdd..b992903 100644 --- a/src/moof/ray.hh +++ b/src/moof/ray.hh @@ -1,13 +1,11 @@ -/*] Copyright (c) 2009-2010, Charles McGarvey [************************** +/*] Copyright (c) 2009-2011, Charles McGarvey [***************************** **] All rights reserved. * -* vi:ts=4 sw=4 tw=75 -* * 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_RAY_HH_ #define _MOOF_RAY_HH_ @@ -73,9 +71,8 @@ struct ray : public drawable } }; - -typedef ray<2> ray2; -typedef ray<3> ray3; +typedef ray<2> ray2; +typedef ray<3> ray3; } // namespace moof diff --git a/src/moof/resource.cc b/src/moof/resource.cc index 95b4c69..7a60d0e 100644 --- a/src/moof/resource.cc +++ b/src/moof/resource.cc @@ -1,15 +1,15 @@ -/*] Copyright (c) 2009-2010, Charles McGarvey [************************** +/*] Copyright (c) 2009-2011, Charles McGarvey [***************************** **] All rights reserved. * -* vi:ts=4 sw=4 tw=75 -* * Distributable under the terms and conditions of the 2-clause BSD license; * see the file COPYING for a complete text of the license. * -**************************************************************************/ +*****************************************************************************/ +#if HAVE_CONFIG_H #include "config.h" +#endif #include @@ -25,14 +25,13 @@ #include "hash.hh" #include "resource.hh" - #ifndef BUF_SIZE -#define BUF_SIZE 4096 +#define BUF_SIZE 8192 #endif namespace moof { - + /*] Filesystem searching *************************************************************************/ @@ -44,7 +43,6 @@ void resource::set_search_paths(const std::string& paths) boost::split(search_paths_, paths, boost::is_any_of(":")); } - std::string resource::find_file(const std::string& name) { std::string ext = stlplus::extension_part(name); @@ -76,8 +74,8 @@ std::string resource::find_file(const std::string& name) return std::string(); } -std::string resource::find_file(const std::string& name, - const std::string& ext) +std::string +resource::find_file(const std::string& name, const std::string& ext) { std::string actual_ext = stlplus::extension_part(name); if (actual_ext != ext) @@ -105,9 +103,7 @@ static struct rsrc_list { hash::iterator it; for (it = table.begin(); it != table.end(); ++it) - { log_warning("leaked resource:", (*it).first); - } } #endif } rsrc_list; @@ -131,7 +127,7 @@ static struct watch_list int add(resource_ptr rsrc) { int wd = inotify_add_watch(fd, rsrc->path().c_str(), - IN_DELETE_SELF | IN_MODIFY); + IN_DELETE_SELF | IN_MODIFY); table[wd] = rsrc; return wd; } @@ -142,22 +138,19 @@ static struct watch_list } watch_list; #endif - resource_ptr resource::load(const std::string& name) { std::string ext = stlplus::extension_part(name); return load_with_path(find_file(name, ext), ext); } -resource_ptr resource::load(const std::string& name, - const std::string& ext) +resource_ptr resource::load(const std::string& name, const std::string& ext) { return load_with_path(find_file(name, ext), ext); } - -resource_ptr resource::load_with_path(const std::string& path, - const std::string& ext) +resource_ptr +resource::load_with_path(const std::string& path, const std::string& ext) { if (path.empty()) return resource_ptr(); @@ -189,7 +182,6 @@ resource_ptr resource::load_with_path(const std::string& path, return resource_ptr(); } - /*] Hotloading *************************************************************************/ @@ -237,7 +229,6 @@ int resource::reload_as_needed() } } #endif - return count; } @@ -260,32 +251,30 @@ resource::~resource() #endif } - /*] Resource registration *************************************************************************/ bool resource::call_registry(const std::string& ext, - loader_ptr& loader, - registry_action action) + loader_ptr& loader, registry_action action) { static std::map table; switch (action) { - case set: - { - if (loader) table[ext] = loader; - else table.erase(ext); - break; - } + case lookup: + { + std::map::iterator it; + it = table.find(ext); + if (it != table.end()) loader = (*it).second; + break; + } - case lookup: - { - std::map::iterator it; - it = table.find(ext); - if (it != table.end()) loader = (*it).second; - break; - } + case set: + if (loader) + table[ext] = loader; + else + table.erase(ext); + break; } return loader; diff --git a/src/moof/resource.hh b/src/moof/resource.hh index 094791c..41dfd61 100644 --- a/src/moof/resource.hh +++ b/src/moof/resource.hh @@ -1,13 +1,11 @@ -/*] Copyright (c) 2009-2010, Charles McGarvey [************************** +/*] Copyright (c) 2009-2011, Charles McGarvey [***************************** **] All rights reserved. * -* vi:ts=4 sw=4 tw=75 -* * 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_RESOURCE_HH_ #define _MOOF_RESOURCE_HH_ @@ -34,7 +32,6 @@ namespace moof { class resource; typedef boost::shared_ptr resource_ptr; - /** * Generic resource class capable of containing any type of resource, * providing a type-safe interface. @@ -49,7 +46,6 @@ public: */ static void set_search_paths(const std::string& paths); - /** * Get the path to a resource of a given name. This uses the search * path(s) and resources prefixes to locate resource files. @@ -67,8 +63,8 @@ public: * extension is not already a part of name. * \return The full path of the resource. */ - static std::string find_file(const std::string& name, - const std::string& ext); + static std::string + find_file(const std::string& name, const std::string& ext); /** * Register a type with the extension of files which this type can @@ -78,7 +74,7 @@ public: */ template static void register_type(const std::string& extension, - const std::string& prefix = "") + const std::string& prefix = "") { loader_ptr loader(new specific_loader(prefix)); call_registry(extension, loader, set); @@ -96,7 +92,6 @@ public: call_registry(extension, loader, set); } - /** * Find and load a resource by name or path. * \param name The name or partial path of the resource. This should @@ -112,9 +107,8 @@ public: * \param * \return The resource. */ - static resource_ptr load(const std::string& name, - const std::string& ext); - + static resource_ptr + load(const std::string& name, const std::string& ext); /** * Reload the resource data. This will cause the resource file to be @@ -138,7 +132,6 @@ public: */ static int reload_as_needed(); - /** * Get whether or not the type of the underlying resource data matches * an expected type. @@ -162,13 +155,11 @@ public: return 0; } - /** * Deconstruct a resource container. */ virtual ~resource(); - private: template @@ -178,9 +169,8 @@ private: unloader_(new specific_unloader(ptr)), wd_(-1) {} - static resource_ptr load_with_path(const std::string& path, - const std::string& extension); - + static resource_ptr + load_with_path(const std::string& path, const std::string& extension); class loader { @@ -201,7 +191,6 @@ private: return prefix_; } - private: std::string prefix_; @@ -223,7 +212,6 @@ private: } }; - class unloader { public: @@ -246,13 +234,11 @@ private: delete object_; } - private: T* object_; }; - enum registry_action { lookup, @@ -260,16 +246,14 @@ private: }; static bool call_registry(const std::string& extension, - loader_ptr& loader, - registry_action action); + loader_ptr& loader, registry_action action); - - void* resource_; + void* resource_; std::type_info* typeinfo_; unloader_ptr unloader_; - int wd_; - std::string path_; - std::string type_; + int wd_; + std::string path_; + std::string type_; }; @@ -301,7 +285,6 @@ public: resource_handle(const std::string& name, const std::string& ext) : resource_(resource::load(name, ext)) {} - /** * Get whether or not the handle is dereferenceable to the type of this * handle. A resource handle is dereferenceable if it is not a null @@ -315,7 +298,6 @@ public: return resource_->check(); } - /** * Get a pointer to the underlying resource. * \return The pointer, or null if this handle is not dereferenceable. @@ -337,7 +319,6 @@ public: return *(resource_->get()); } - /** * Same as get() for getting a pointer to the underlying resources. * \return The pointer, or null if this handle is not dereferenceable. @@ -357,7 +338,6 @@ public: return get_reference(); } - /** * Unload the resource associated with this handle. */ @@ -366,13 +346,11 @@ public: resource_ = resource_ptr(); } - private: resource_ptr resource_; }; - /** * This macro easily registers types to act as resources. It should be * used in a module file in global scope. diff --git a/src/moof/rigid_body.hh b/src/moof/rigid_body.hh index 65e502c..67e12dd 100644 --- a/src/moof/rigid_body.hh +++ b/src/moof/rigid_body.hh @@ -1,13 +1,11 @@ -/*] Copyright (c) 2009-2010, Charles McGarvey [************************** +/*] Copyright (c) 2009-2011, Charles McGarvey [***************************** **] All rights reserved. * -* vi:ts=4 sw=4 tw=75 -* * 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_RIGID_BODY_HH_ #define _MOOF_RIGID_BODY_HH_ @@ -34,34 +32,28 @@ struct linear_state { typedef moof::vector< scalar, fixed > vector; typedef boost::function - force_function; + force_function; // primary - vector position; vector momentum; // secondary - vector velocity; // user - vector force; std::vector forces; // constant - scalar mass; scalar inverse_mass; - void recalculate() { velocity = momentum * inverse_mass; } - struct gravity_force { explicit gravity_force(scalar a = -9.8) @@ -76,14 +68,12 @@ struct linear_state return force; } - private: vector force; scalar acceleration; }; - void init() { position.zero(); @@ -98,7 +88,6 @@ struct linear_state inverse_mass = 1.0 / mass; } - struct derivative { vector velocity; @@ -121,7 +110,6 @@ struct linear_state } }; - vector total_force() const { vector f(force); @@ -148,30 +136,24 @@ struct linear_state } }; - struct rotational_state2 { // primary - scalar orientation; scalar angular_momentum; // secondary - scalar angularVelocity; // constant - scalar inertia; scalar inverse_inertia; - void recalculate() { angularVelocity = angular_momentum * inertia; } - struct derivative { scalar angularVelocity; @@ -189,21 +171,17 @@ struct rotational_state2 struct rotational_state3 { // primary - quaternion orientation; vector3 angular_momentum; // secondary - quaternion spin; vector3 angularVelocity; // constant - scalar inertia; scalar inverse_inertia; - void recalculate() { angularVelocity = angular_momentum * inertia; @@ -239,7 +217,6 @@ struct state3 : public linear_state<3>, public rotational_state3 } }; - template inline T interpolate(const T& a, const T& b, scalar alpha) { @@ -247,37 +224,34 @@ inline T interpolate(const T& a, const T& b, scalar alpha) } template <> -inline state2 interpolate(const state2& a, const state2& b, - scalar alpha) +inline state2 +interpolate(const state2& a, const state2& b, scalar alpha) { state2 state(b); state.position = interpolate(a.position, b.position, alpha); state.momentum = interpolate(a.momentum, b.momentum, alpha); state.orientation = interpolate(a.orientation, b.orientation, alpha); state.angular_momentum = interpolate(a.angular_momentum, - b.angular_momentum, alpha); + b.angular_momentum, alpha); return state; } template <> -inline state3 interpolate(const state3& a, const state3& b, - scalar alpha) +inline state3 +interpolate(const state3& a, const state3& b, scalar alpha) { state3 state(b); state.position = interpolate(a.position, b.position, alpha); state.momentum = interpolate(a.momentum, b.momentum, alpha); state.orientation = slerp(a.orientation, b.orientation, alpha); state.angular_momentum = interpolate(a.angular_momentum, - b.angular_momentum, alpha); + b.angular_momentum, alpha); return state; } - - /** * Interface for anything that can move. */ - template class rigid_body : public entity { diff --git a/src/moof/runloop.cc b/src/moof/runloop.cc index 98bc3a2..f8e4ccf 100644 --- a/src/moof/runloop.cc +++ b/src/moof/runloop.cc @@ -1,15 +1,15 @@ -/*] Copyright (c) 2009-2010, Charles McGarvey [************************** +/*] Copyright (c) 2009-2011, Charles McGarvey [***************************** **] All rights reserved. * -* vi:ts=4 sw=4 tw=75 -* * Distributable under the terms and conditions of the 2-clause BSD license; * see the file COPYING for a complete text of the license. * -**************************************************************************/ +*****************************************************************************/ +#if HAVE_CONFIG_H #include "config.h" +#endif #include @@ -27,27 +27,24 @@ bool comp(timer* a, timer* b) return a->expiration() < b->expiration(); } -void runloop::run_once() + +int runloop::run_once() { #if ENABLE_THREADS thread_id_ = thread::current_identifier(); #endif //log_debug("------------------------------------"); - //scalar next_event = SCALAR(0.0); - { - MOOF_MUTEX_LOCK(timers_mutex_); + int expired = 0; + MOOF_MUTEX_LOCK(timers_mutex_); - for (timers_it_ = timers_.begin(); - timers_it_ != timers_.end(); - ++timers_it_) - { - (*timers_it_)->fire_if_expired(); - } - - std::sort(timers_.begin(), timers_.end(), comp); - //next_event = timers_[0]->expiration(); + std::sort(timers_.begin(), timers_.end(), comp); + for (timers_it_ = timers_.begin(); + timers_it_ != timers_.end(); ++timers_it_) + { + if ((*timers_it_)->fire_if_expired()) ++expired; } + return expired; } int runloop::run() @@ -55,22 +52,21 @@ int runloop::run() stop_ = false; while (!stop_) { - run_once(); - //timer::sleep(next_event, timer::absolute); - timer::sleep(SCALAR(0.0)); + if (run_once() == 0);//timer::sleep(SCALAR(0.0)); + // TODO: maybe sleep(0.0001) will actually return sooner than + // sleep(0)... if the kernel interprets sleep(0) as we don't need + // to process for an arbitrarily long timespan while specifying a + // value lets the kernel know when we need control back... } - return code_; } - void runloop::stop(int code) { code_ = code; stop_ = true; } - void runloop::add_timer(timer& timer) { #if ENABLE_THREADS diff --git a/src/moof/runloop.hh b/src/moof/runloop.hh index 2952952..6d56d83 100644 --- a/src/moof/runloop.hh +++ b/src/moof/runloop.hh @@ -1,13 +1,11 @@ -/*] Copyright (c) 2009-2010, Charles McGarvey [************************** +/*] Copyright (c) 2009-2011, Charles McGarvey [***************************** **] All rights reserved. * -* vi:ts=4 sw=4 tw=75 -* * 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_RUNLOOP_HH_ #define _MOOF_RUNLOOP_HH_ @@ -29,7 +27,6 @@ namespace moof { // forward declarations class timer; - /** * A runloop is a loop with scheduled timers. @@ -51,9 +48,9 @@ public: /** * Do one iteration of the runloop. + * \return The number of tasks which were given time. */ - void run_once(); - + int run_once(); /** * Start running the runloop. @@ -67,15 +64,18 @@ public: */ void stop(int code = 0); + bool is_running() const + { + return !stop_; + } void add_timer(timer& timer); void remove_timer(timer& timer); - private: bool stop_; - int code_; + int code_; typedef std::vector timer_table; timer_table timers_; diff --git a/src/moof/script.hh b/src/moof/script.hh index 35e80d2..79412ac 100644 --- a/src/moof/script.hh +++ b/src/moof/script.hh @@ -1,13 +1,11 @@ -/*] Copyright (c) 2009-2010, Charles McGarvey [************************** +/*] Copyright (c) 2009-2011, Charles McGarvey [***************************** **] All rights reserved. * -* vi:ts=4 sw=4 tw=75 -* * 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_SCRIPT_HH_ #define _MOOF_SCRIPT_HH_ @@ -16,10 +14,10 @@ * \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. + * 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 @@ -43,7 +41,6 @@ namespace moof { class script; typedef boost::shared_ptr