summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRobert Vollmert <rvollmert@gmx.net>2009-10-11 18:31:07 +0200
committerRobert Vollmert <rvollmert@gmx.net>2009-10-11 21:30:30 +0200
commit4783b4ed0e228b3de642d71c6554ffcf60ab7858 (patch)
tree65d566003743095bd5ac2549b089f95df8326c27
parentbc91b96ff7b72ed86e02274adf9404b54ae2922c (diff)
downloadcrawl-ref-4783b4ed0e228b3de642d71c6554ffcf60ab7858.tar.gz
crawl-ref-4783b4ed0e228b3de642d71c6554ffcf60ab7858.zip
More ray_def simplification.
-rw-r--r--crawl-ref/source/makefile.unix325
-rw-r--r--crawl-ref/source/ray.cc50
-rw-r--r--crawl-ref/source/ray.h3
3 files changed, 345 insertions, 33 deletions
diff --git a/crawl-ref/source/makefile.unix b/crawl-ref/source/makefile.unix
new file mode 100644
index 0000000000..19b20ad7da
--- /dev/null
+++ b/crawl-ref/source/makefile.unix
@@ -0,0 +1,325 @@
+# -*- Makefile -*- for Dungeon Crawl (unix)
+
+GAME = crawl
+
+# this file contains a list of the libraries.
+# it will make a variable called OBJECTS that contains all the libraries
+include makefile.obj
+
+OBJECTS += libunix.o crash-u.o
+
+CXX = g++
+DELETE = rm -f
+COPY = cp
+OS_TYPE = UNIX
+# To get stack trace symbols.
+LDFLAGS = -rdynamic
+
+# Change this to y (case-sensitive!) if you want to use Unicode glyphs
+# in the map, and you have libncursesw available.
+UNICODE_GLYPHS = n
+
+# If you're using UNICODE_GLYPHS=y, and have a preferred Unicode
+# (UTF-8) locale you want Crawl to use, you can set it here. The
+# default is en_US.UTF-8. If you'd prefer that Crawl use the locale
+# as set in your environment LC_* variables, use UNICODE_LOCALE = .
+UNICODE_LOCALE =
+
+# If you have lex and yacc, set DOYACC to y (lowercase y).
+DOYACC := y
+
+# Permissions to set on the game executable.
+MCHMOD := 2755
+
+# Permissions to set on the save directory.
+MCHMOD_SAVEDIR := 775
+
+# The user:group to install the game as.
+INSTALL_UGRP := games:games
+
+INSTALLDIR := /usr/games/crawl
+
+# If you're installing Crawl for multiple users, you *must* set this to a
+# valid path before building Crawl. This is not necessary if you are building
+# Crawl for a single user.
+
+# SAVEDIR := /usr/games/crawl/saves/
+# DATADIR := /usr/games/crawl/data/
+
+LEX := flex
+YACC := bison -y
+
+LUASRC := util/lua/src
+LUALIB = lua
+LUALIBA = l$(LUALIB).a
+
+SQLSRC := util/sqlite
+SQLLIB := sqlite3
+SQLLIBA := lib$(SQLLIB).a
+FSQLLIBA := $(SQLSRC)/$(SQLLIBA)
+
+LIBDBM := $(FSQLLIBA)
+EXTRA_INCLUDES += -I$(SQLSRC)
+EXTRA_DEPENDS += $(FSQLLIBA)
+
+LIB = -l$(LIBCURS) -L$(LUASRC) -l$(LUALIB) $(LIBDBM)
+
+INCLUDES := $(INCLUDES) -Iutil -I. -I$(LUASRC) $(EXTRA_INCLUDES)
+
+CFWARN := -Wall -Wno-parentheses -Wwrite-strings -Wshadow -pedantic
+
+CFOTHERS := -fsigned-char -D$(OS_TYPE) $(EXTRA_FLAGS) -DCLUA_BINDINGS
+
+ifneq ($(HURRY),y)
+ifneq ($(DEBUG_CRAWL),y)
+CFWARN += -Wuninitialized
+CFOTHERS += -O2
+endif
+endif
+
+ifneq ($(strip $(SAVEDIR)),)
+CFOTHERS += '-DSAVE_DIR_PATH="$(strip $(SAVEDIR))"'
+endif
+
+ifneq ($(strip $(DATADIR)),)
+CFOTHERS += '-DDATA_DIR_PATH="$(strip $(DATADIR))"'
+endif
+
+ifeq ($(strip $(UNICODE_GLYPHS)),y)
+# Include path for (n)curses with Unicode support.
+INCLUDES += -I/usr/include/ncursesw
+
+# Your ncurses library may include Unicode support, and you may not have a
+# separate libncursesw; in that case, change this line accordingly.
+LIBCURS = ncursesw
+CFOTHERS += -DUNICODE_GLYPHS
+
+ifneq ($(strip $(UNICODE_LOCALE)),)
+ifneq ($(strip $(UNICODE_LOCALE)),.)
+CFOTHERS += -DUNICODE_LOCALE=\"$(strip $(UNICODE_LOCALE))\"
+else
+CFOTHERS += -DUNICODE_LOCALE=\"\"
+endif
+endif
+
+# The standard ncurses library also supports Unicode on Mac OS/Darwin.
+ifeq ($(shell uname),Darwin)
+LIBCURS = ncurses
+endif
+
+else
+# Include path for curses or ncurses (non-Unicode).
+INCLUDES += -I/usr/include/ncurses
+LIBCURS = ncurses
+endif
+
+CFLAGS := $(INCLUDES) $(CFWARN) $(CFOTHERS)
+YCFLAGS := $(INCLUDES) $(CFOTHERS)
+
+UTIL = util/
+
+YTABC := levcomp.tab.c
+YTABH := levcomp.tab.h
+
+OBJECTS := $(UTIL)levcomp.tab.o $(UTIL)levcomp.lex.o $(OBJECTS)
+
+ifeq ($(strip $(LEX)),)
+DOYACC :=
+endif
+
+ifeq ($(strip $(YACC)),)
+DOYACC :=
+endif
+
+GAME_DEPENDS := $(LUASRC)$(LUALIBA) $(EXTRA_DEPENDS) $(OBJECTS)
+SRC_PKG_BASE := stone_soup
+SRC_VERSION := $(shell egrep 'VER_NUM *".*"' version.h | \
+ egrep -o '[0-9]\.[0-9](\.[0-9])?')
+PKG_SRC_DIR := $(SRC_PKG_BASE)-$(SRC_VERSION)-src
+SRC_PKG_TAR := $(PKG_SRC_DIR).tbz2
+SRC_PKG_ZIP := $(PKG_SRC_DIR).zip
+
+PKG_TIDY_LIST := $(UTIL)*.o $(LEVCOMP) *.o \
+ $(UTIL)*.tab.cc $(UTIL)*.tab.h $(UTIL)*.lex.cc *.ixx
+PKG_EXCLUDES := $(PWD)/misc/src-pkg-excludes.lst
+
+##########################################################################
+
+all: $(GAME)
+
+test: $(GAME)
+ $(PWD)/$(GAME) -test
+
+##########################################################################
+# Dependencies
+
+DEPENDENCY_MKF := makefile.dep
+
+depend: $(OBJECTS:.o=.cc)
+ rm -f $(DEPENDENCY_MKF).tmp
+ @for i in $^; do \
+ echo "Updating dependencies for $$i"; \
+ $(CXX) -MM $(CFLAGS) $$i >>$(DEPENDENCY_MKF).tmp 2>/dev/null; \
+ done
+ mv -f $(DEPENDENCY_MKF).tmp $(DEPENDENCY_MKF)
+
+-include $(DEPENDENCY_MKF)
+
+##########################################################################
+# The level compiler
+#
+
+ifeq ($(DOYACC),y)
+
+prebuildyacc: $(UTIL)levcomp.tab.cc $(UTIL)levcomp.tab.h $(UTIL)levcomp.lex.cc
+ $(COPY) $^ prebuilt/
+
+$(UTIL)levcomp.tab.cc: $(UTIL)levcomp.ypp
+ cd $(UTIL) && $(YACC) -d -b levcomp levcomp.ypp \
+ && mv $(YTABC) levcomp.tab.cc || false
+
+$(UTIL)levcomp.lex.cc: $(UTIL)levcomp.lpp
+ cd $(UTIL) && $(LEX) -olevcomp.lex.cc levcomp.lpp
+
+else
+
+# Pull the level-compiler stuff up from prebuilt/
+
+$(UTIL)levcomp.tab.cc: prebuilt/levcomp.tab.cc
+ $(COPY) prebuilt/*.h $(UTIL)
+ $(COPY) $< $@
+
+
+$(UTIL)levcomp.lex.cc: prebuilt/levcomp.lex.cc
+ $(COPY) $< $@
+
+endif
+
+##########################################################################
+
+
+##########################################################################
+# The actual build targets
+#
+
+install: $(GAME)
+ifeq ($(DATADIR),)
+ $(error DATADIR not set! Set DATADIR and run make clean install again)
+endif
+ [ -d $(INSTALLDIR) ] || mkdir -p $(INSTALLDIR)
+ $(COPY) $(GAME) $(INSTALLDIR)
+ chown $(INSTALL_UGRP) $(INSTALLDIR)/$(GAME)
+ chmod ${MCHMOD} ${INSTALLDIR}/$(GAME)
+ mkdir -p $(DATADIR)/dat
+ mkdir -p $(DATADIR)/dat/lua
+ mkdir -p $(DATADIR)/dat/clua
+ mkdir -p $(DATADIR)/dat/descript
+ mkdir -p $(DATADIR)/dat/database
+ $(COPY) dat/*.des $(DATADIR)/dat
+ $(COPY) dat/lua/*.lua $(DATADIR)/dat/lua
+ $(COPY) dat/clua/*.lua $(DATADIR)/dat/clua
+ $(COPY) dat/descript/*.txt $(DATADIR)/dat/descript
+ $(COPY) dat/database/*.txt $(DATADIR)/dat/database
+ mkdir -p $(DATADIR)/settings
+ $(COPY) ../settings/* $(DATADIR)/settings/
+ mkdir -p $(DATADIR)/docs
+ $(COPY) ../docs/*.txt $(DATADIR)/docs
+ chown -R $(INSTALL_UGRP) $(DATADIR)
+ifneq ($(SAVEDIR),)
+ mkdir -p $(SAVEDIR)
+ chown $(INSTALL_UGRP) $(SAVEDIR)
+ chmod $(MCHMOD_SAVEDIR) $(SAVEDIR)
+endif
+
+clean:
+ $(DELETE) *.o
+ $(DELETE) $(UTIL)*.o
+ $(DELETE) $(LEVCOMP)
+ $(DELETE) $(UTIL)*.tab.cc $(UTIL)*.tab.c $(UTIL)*.tab.h $(UTIL)*.lex.cc
+ $(DELETE) *.ixx
+
+clean-lua:
+ +$(MAKE) -C $(LUASRC) clean
+
+clean-sql:
+ +$(MAKE) -C $(SQLSRC) clean
+
+distclean: clean clean-lua clean-sql
+ $(DELETE) bones.*
+ $(DELETE) morgue.txt
+ $(DELETE) scores
+ $(DELETE) $(GAME)
+ $(DELETE) *.sav
+ $(DELETE) core
+ $(DELETE) *.0*
+ $(DELETE) *.lab
+ $(DELETE) $(DEPENDENCY_MKF)
+
+$(GAME): $(GAME_DEPENDS)
+ ${CXX} ${LDFLAGS} $(CFLAGS) $(OBJECTS) -o $(GAME) $(LIB)
+
+.PHONY : debug
+
+debug: $(GAME)
+
+profile: $(GAME_DEPENDS)
+ ${CXX} -g -p ${LDFLAGS} $(CFLAGS) $(OBJECTS) -o $(GAME) $(LIB)
+
+.cc.o:
+ ${CXX} ${CFLAGS} -c $<
+
+# [ds] Note we don't use the standard CFLAGS here; that's intentional, most
+# flex/bison combos I've tried don't produce code that passes the warnings
+# test.
+$(UTIL)%.o: $(UTIL)%.cc
+ $(CXX) $(YCFLAGS) -o $@ -c $<
+
+#############################################################################
+# Build Lua
+
+$(LUASRC)$(LUALIBA):
+ echo Building Lua...
+ +$(MAKE) -C $(LUASRC) crawl_unix
+
+#############################################################################
+# Build SQLite
+
+$(FSQLLIBA):
+ echo Building SQLite
+ +$(MAKE) -C $(SQLSRC)
+
+#############################################################################
+# Build unrandart data
+art-data.h: art-data.txt util/art-data.pl art-func.h
+ util/art-data.pl
+
+#############################################################################
+# Packaging a source tarball for release
+#
+
+# To package, you *must* have lex and yacc to generate the intermediates.
+ifeq ($(DOYACC),y)
+package-source: distclean prebuildyacc pkgtidy depend removeold vlink \
+ pkgtarbz2 pkgzip
+
+pkgtidy:
+ $(DELETE) $(PKG_TIDY_LIST)
+
+removeold:
+ if [ -f ../../$(SRC_PKG_TAR) ]; then $(DELETE) ../../$(SRC_PKG_TAR); fi
+ if [ -f ../../$(SRC_PKG_ZIP) ]; then $(DELETE) ../../$(SRC_PKG_ZIP); fi
+
+# [ds] Existing directory names could produce a bad package!
+vlink:
+ cd .. && WHERE=$$PWD && cd .. && \
+ ( [ -e $(PKG_SRC_DIR) ] || ln -sf $$WHERE $(PKG_SRC_DIR) )
+
+pkgtarbz2:
+ cd ../.. && tar -ch --bzip2 -f $(SRC_PKG_TAR) \
+ -X $(PKG_EXCLUDES) $(PKG_SRC_DIR)
+
+pkgzip:
+ cd ../.. && zip -rq $(SRC_PKG_ZIP) $(PKG_SRC_DIR) \
+ -x@$(PKG_EXCLUDES)
+
+endif
diff --git a/crawl-ref/source/ray.cc b/crawl-ref/source/ray.cc
index 0ce4daa57e..804090b4dc 100644
--- a/crawl-ref/source/ray.cc
+++ b/crawl-ref/source/ray.cc
@@ -240,7 +240,7 @@ int ray_def::advance(bool shortest_possible, const coord_def *target)
// note that slope must be nonnegative!
// returns 0 if the advance was in x, 1 if it was in y, 2 if it was
// the diagonal
-int ray_def::_find_next_intercept()
+int ray_def::raw_advance_0()
{
// handle perpendiculars
if (double_is_zero(slope))
@@ -302,44 +302,30 @@ int ray_def::_find_next_intercept()
return rc;
}
+/*
+ * Mirror ray into quadrant 0 or back.
+ * this.quadrant itself is not touched (used for the flip back).
+ */
+void ray_def::flip()
+{
+ int signx[] = {1, -1, -1, 1};
+ int signy[] = {1, 1, -1, -1};
+ accx *= signx[quadrant];
+ accy *= signy[quadrant];
+}
+
int ray_def::raw_advance()
{
int rc;
- switch (quadrant)
- {
- case 0:
- // going down-right
- rc = _find_next_intercept();
- break;
- case 1:
- // going down-left
- accx *= -1;
- rc = _find_next_intercept();
- accx *= -1;
- break;
- case 2:
- // going up-left
- accx *= -1;
- accy *= -1;
- rc = _find_next_intercept();
- accx *= -1;
- accy *= -1;
- break;
- case 3:
- // going up-right
- accy *= -1;
- rc = _find_next_intercept();
- accy *= -1;
- break;
- default:
- rc = -1;
- }
+ flip();
+ rc = raw_advance_0();
+ flip();
return rc;
}
// Shoot a ray from the given start point (accx, accy) with the given
// slope, bounded by the given pre-squared LOS radius.
-// Store the visited cells in xpos[] and ypos[], and
+// Store the visited cells in pos[], and
// return the number of cells visited.
int ray_def::footprint(int radius2, coord_def cpos[]) const
{
@@ -348,7 +334,7 @@ int ray_def::footprint(int radius2, coord_def cpos[]) const
int cellnum;
for (cellnum = 0; true; ++cellnum)
{
- copy._find_next_intercept();
+ copy.raw_advance();
c = copy.pos();
if (c.abs() > radius2)
break;
diff --git a/crawl-ref/source/ray.h b/crawl-ref/source/ray.h
index dca0d00e4f..201a92edf1 100644
--- a/crawl-ref/source/ray.h
+++ b/crawl-ref/source/ray.h
@@ -40,7 +40,8 @@ public:
void set_degrees(double deg);
private:
- int _find_next_intercept();
+ int raw_advance_0();
+ void flip();
int raw_advance();
double reflect(bool x, double oldc, double newc) const;
void set_reflect_point(const double oldx, const double oldy,