Restructured things a bit, got the makefiles working together more intelligently, added uninstall target, removed build-demos.sh

This commit is contained in:
2011-05-26 03:46:16 +00:00
parent ccca81e04e
commit 8652136f75
32 changed files with 1046 additions and 1054 deletions

View File

@@ -9,51 +9,62 @@ ifndef $(OS)
OS=linux OS=linux
endif endif
LIBNAME=game LIBNAME=sdlgame
PROJECTHOME=$(shell pwd) PROJECTHOME=$(shell pwd)
SDL_CFLAGS=$(shell sdl-config --cflags) SDL_CFLAGS=$(shell sdl-config --cflags)
SDL_LDFLAGS=$(shell sdl-config --static-libs) SDL_LDFLAGS=$(shell sdl-config --static-libs)
LIBDIR=/usr/lib LIBDIR=/usr/lib
HEADERDIR=/usr/include HEADERDIR=/usr/include
ADDL_CFLAGS= ADDL_CFLAGS=
OBJDIR=libsdlgame
EXESUFFIX=
LIBSUFFIX=
ifeq "$(OS)" "mingw32" ifeq "$(OS)" "mingw32"
ADDL_CFLAGS=-mwindows ADDL_CFLAGS=-mwindows
EXESUFFIX=".exe"
LIBSUFFIX=".a"
endif endif
ifeq "$(CFG)" "Debug" ifeq "$(CFG)" "Debug"
OUTDIR=Debug OUTDIR=Debug
LIBTARGET=lib$(LIBNAME)-dbg LIBTARGET=lib$(LIBNAME)-dbg$(LIBSUFFIX)
LINKLIB=game-dbg LINKLIB=game-dbg
CXXFLAGS=-pg -I./source -g -ggdb -gstabs -c $(SDL_CFLAGS) $(ADDL_CFLAGS) CXXFLAGS=-pg -I./source -g -ggdb -gstabs -c $(SDL_CFLAGS) $(ADDL_CFLAGS)
endif endif
ifeq "$(CFG)" "Release" ifeq "$(CFG)" "Release"
OUTDIR=Release OUTDIR=Release
LIBTARGET=lib$(LIBNAME) LIBTARGET=lib$(LIBNAME)$(LIBSUFFIX)
LINKLIB=game LINKLIB=game
CXXFLAGS=-I./source -c $(SDL_CFLAGS) $(ADDL_CFLAGS) CXXFLAGS=-I./source -c $(SDL_CFLAGS) $(ADDL_CFLAGS)
endif endif
LINKLIBS=-L../../$(CFG) -L$(OUTDIR) -l$(LINKLIB) $(SDL_LDFLAGS) -lSDL_image -lSDL_mixer LINKLIBS=-L../../$(CFG) -L$(OUTDIR) -l$(LINKLIB) $(SDL_LDFLAGS) -lSDL_image -lSDL_mixer
LIBOBJ=$(OUTDIR)/Common.o \ LIBOBJ=$(OBJDIR)/Common.o \
$(OUTDIR)/FontRenderer.o \ $(OBJDIR)/FontRenderer.o \
$(OUTDIR)/Renderable.o \ $(OBJDIR)/Renderable.o \
$(OUTDIR)/SpriteStrip.o \ $(OBJDIR)/SpriteStrip.o \
$(OUTDIR)/Animation.o \ $(OBJDIR)/Animation.o \
$(OUTDIR)/Actor.o \ $(OBJDIR)/Actor.o \
$(OUTDIR)/Display.o \ $(OBJDIR)/Display.o \
$(OUTDIR)/Display2D.o \ $(OBJDIR)/Display2D.o \
$(OUTDIR)/MenuDisplay.o \ $(OBJDIR)/MenuDisplay.o \
$(OUTDIR)/Game.o $(OBJDIR)/Game.o
DEMOS=bouncingball \
exploder \
explodingball \
frictionball \
gravity
CC = gcc CC = gcc
CXX = g++ CXX = g++
LD = $(CXX) LD = $(CXX)
INSTALL = $(shell which install) INSTALL = $(shell which install)
$(OUTDIR)/%.o : %.cpp $(OUTDIR)/%.o : $(OBJDIR)/%.cpp
$(CXX) $(CXXFLAGS) -o $@ $< $(CXX) $(CXXFLAGS) -o $@ $<
ifeq "$(OS)" "macosx" ifeq "$(OS)" "macosx"
all: sharedlib all: sharedlib
@@ -74,12 +85,13 @@ docs:
.PHONY: clean .PHONY: clean
clean: clean:
rm -f $(OUTDIR)/*.o rm -f $(OBJDIR)/*.o
rm -f $(OUTDIR)/$(LIBTARGET).* rm -f $(OUTDIR)/$(LIBTARGET).*
rm -rf docs/*
cd demo && for dir in $(DEMOS); do cd $$dir && make CFG=$(CFG) OS=$(OS) clean; if [ $$? -ne 0 ]; then exit 1 ; fi; cd .. ; done
.PHONY: demos .PHONY: demos
demos: demos:
cd demo && ./build-demos.sh $(CFG) cd demo && for dir in $(DEMOS); do cd $$dir && make CFG=$(CFG) OS=$(OS); if [ $$? -ne 0 ]; then exit 1 ; fi; cd .. ; done
.PHONY: rebuild .PHONY: rebuild
rebuild: rebuild:
@@ -90,8 +102,13 @@ rebuild:
.PHONY: install .PHONY: install
install: install:
$(INSTALL) $(OUTDIR)/$(LIBTARGET)* $(LIBDIR)/ $(INSTALL) $(OUTDIR)/$(LIBTARGET)* $(LIBDIR)/
mkdir -p $(HEADERDIR)/libgame mkdir -p $(HEADERDIR)/libsdlgame
$(INSTALL) *h $(HEADERDIR)/libgame/ $(INSTALL) $(OBJDIR)/*h $(HEADERDIR)/libsdlgame/
.PHONY: uninstall
uninstall:
rm $(LIBDIR)/$(LIBTARGET)*
rm -rf $(HEADERDIR)/libsdlgame
.PHONY: deps .PHONY: deps
deps: deps:

View File

@@ -1,78 +1,78 @@
# This makefile is a bit hackish. I wrote it early in the AM. # This makefile is a bit hackish. I wrote it early in the AM.
# Fohgiveuhness, please!! # Fohgiveuhness, please!!
ifndef $(CFG) ifndef $(CFG)
CFG=Debug CFG=Debug
endif endif
# you can also pass : mingw32 and macosx # you can also pass : mingw32 and macosx
ifndef $(OS) ifndef $(OS)
OS=linux OS=linux
endif endif
TARGET=demo TARGET=demo
BINTARGET=$(TARGET) BINTARGET=$(TARGET)
PROJECTHOME=$(shell pwd) PROJECTHOME=$(shell pwd)
SDL_CFLAGS=$(shell sdl-config --cflags) SDL_CFLAGS=$(shell sdl-config --cflags)
SDL_LDFLAGS=$(shell sdl-config --libs) SDL_LDFLAGS=$(shell sdl-config --libs)
LIBDIR=/usr/lib LIBDIR=/usr/lib
HEADERDIR=/usr/include HEADERDIR=/usr/include
ADDL_CFLAGS= ADDL_CFLAGS=
ifeq "$(OS)" "mingw32" ifeq "$(OS)" "mingw32"
ADDL_CFLAGS=-mwindows -DBUILD_MINGW32 ADDL_CFLAGS=-mwindows -DBUILD_MINGW32
endif endif
ifeq "$(OS)" "linux" ifeq "$(OS)" "linux"
ADDL_CFLAGS=-DBUILD_LINUX ADDL_CFLAGS=-DBUILD_LINUX
endif endif
# default for release configs # default for release configs
ifeq "$(CFG)" "Release" ifeq "$(CFG)" "Release"
OUTDIR=Release OUTDIR=Release
ifeq "$(OS)" "mingw32" ifeq "$(OS)" "mingw32"
BINTARGET=$(TARGET).exe BINTARGET=$(TARGET).exe
else else
BINTARGET=$(TARGET) BINTARGET=$(TARGET)
endif endif
LINKLIB=game LINKLIB=sdlgame
CXXFLAGS=-I../../../ -I$(HEADERDIR) -I./cpp -c $(SDL_CFLAGS) $(ADDL_CFLAGS) CXXFLAGS=-I../../ -I$(HEADERDIR) -I./cpp -c $(SDL_CFLAGS) $(ADDL_CFLAGS)
endif endif
ifeq "$(CFG)" "Debug" ifeq "$(CFG)" "Debug"
OUTDIR=Debug OUTDIR=Debug
ifeq "$(OS)" "mingw32" ifeq "$(OS)" "mingw32"
BINTARGET=$(TARGET)-dbg.exe BINTARGET=$(TARGET)-dbg.exe
else else
BINTARGET=$(TARGET)-dbg BINTARGET=$(TARGET)-dbg
endif endif
LINKLIB=game-dbg LINKLIB=sdlgame-dbg
CXXFLAGS=-I../../../ -I$(HEADERDIR) -I./cpp -pg -g -ggdb -gstabs -Wall -c $(SDL_CFLAGS) $(ADDL_CFLAGS) CXXFLAGS=-I../../ -I$(HEADERDIR) -I./cpp -pg -g -ggdb -gstabs -Wall -c $(SDL_CFLAGS) $(ADDL_CFLAGS)
endif endif
LINKLIBS=-L../../$(CFG) -L$(LIBDIR) -l$(LINKLIB) $(SDL_LDFLAGS) -lSDL_image -lSDL_mixer -lSDL_gfx -lSDL_ttf LINKLIBS=-L../../$(CFG) -L$(LIBDIR) -l$(LINKLIB) $(SDL_LDFLAGS) -lSDL_image -lSDL_mixer -lSDL_gfx -lSDL_ttf
BINOBJ=$(OUTDIR)/demo.o BINOBJ=$(OUTDIR)/demo.o
CC = gcc CC = gcc
CXX = g++ CXX = g++
LD = $(CXX) LD = $(CXX)
INSTALL = $(which install) INSTALL = $(which install)
$(OUTDIR)/%.o : cpp/%.cpp $(OUTDIR)/%.o : cpp/%.cpp
$(CXX) $(CXXFLAGS) -o $@ $< $(CXX) $(CXXFLAGS) -o $@ $<
all: bin all: bin
bin: $(BINOBJ) bin: $(BINOBJ)
$(LD) -pg -o $(OUTDIR)/$(BINTARGET) \ $(LD) -pg -o $(OUTDIR)/$(BINTARGET) \
-pg $(BINOBJ) $(LINKLIBS) -pg $(BINOBJ) $(LINKLIBS)
.PHONY: clean .PHONY: clean
clean: clean:
rm -f $(OUTDIR)/*.o rm -f $(OUTDIR)/*.o
rm -f $(OUTDIR)/$(BINTARGET) rm -f $(OUTDIR)/$(BINTARGET)
.PHONY: rebuild .PHONY: rebuild
rebuild: rebuild:
make clean make clean
make CFG=$(CFG) make CFG=$(CFG)

View File

@@ -1,25 +0,0 @@
#!/bin/bash
BUILTOK=""
BUILTFAIL=""
for dir in $(find . -maxdepth 1 -type d | grep -v "\.$" );
do
echo "Making in $dir "
cd $dir
make CFG=$1 $2
if [ $? -eq 0 ]; then
BUILTOK="$(echo $BUILTOK $dir)"
else
BUILTFAIL="$(echo $BUILTFAIL $dir)"
fi
cd ..
done
echo
echo
echo "OK : $BUILTOK"
echo
echo "FAIL : $BUILTFAIL"

View File

@@ -1,78 +1,78 @@
# This makefile is a bit hackish. I wrote it early in the AM. # This makefile is a bit hackish. I wrote it early in the AM.
# Fohgiveuhness, please!! # Fohgiveuhness, please!!
ifndef $(CFG) ifndef $(CFG)
CFG=Debug CFG=Debug
endif endif
# you can also pass : mingw32 and macosx # you can also pass : mingw32 and macosx
ifndef $(OS) ifndef $(OS)
OS=linux OS=linux
endif endif
TARGET=demo TARGET=demo
BINTARGET=$(TARGET) BINTARGET=$(TARGET)
PROJECTHOME=$(shell pwd) PROJECTHOME=$(shell pwd)
SDL_CFLAGS=$(shell sdl-config --cflags) SDL_CFLAGS=$(shell sdl-config --cflags)
SDL_LDFLAGS=$(shell sdl-config --libs) SDL_LDFLAGS=$(shell sdl-config --libs)
LIBDIR=/usr/lib LIBDIR=/usr/lib
HEADERDIR=/usr/include HEADERDIR=/usr/include
ADDL_CFLAGS= ADDL_CFLAGS=
ifeq "$(OS)" "mingw32" ifeq "$(OS)" "mingw32"
ADDL_CFLAGS=-mwindows -DBUILD_MINGW32 ADDL_CFLAGS=-mwindows -DBUILD_MINGW32
endif endif
ifeq "$(OS)" "linux" ifeq "$(OS)" "linux"
ADDL_CFLAGS=-DBUILD_LINUX ADDL_CFLAGS=-DBUILD_LINUX
endif endif
# default for release configs # default for release configs
ifeq "$(CFG)" "Release" ifeq "$(CFG)" "Release"
OUTDIR=Release OUTDIR=Release
ifeq "$(OS)" "mingw32" ifeq "$(OS)" "mingw32"
BINTARGET=$(TARGET).exe BINTARGET=$(TARGET).exe
else else
BINTARGET=$(TARGET) BINTARGET=$(TARGET)
endif endif
LINKLIB=game LINKLIB=sdlgame
CXXFLAGS=-I../../../ -I$(HEADERDIR) -I./cpp -c $(SDL_CFLAGS) $(ADDL_CFLAGS) CXXFLAGS=-I../../ -I$(HEADERDIR) -I./cpp -c $(SDL_CFLAGS) $(ADDL_CFLAGS)
endif endif
ifeq "$(CFG)" "Debug" ifeq "$(CFG)" "Debug"
OUTDIR=Debug OUTDIR=Debug
ifeq "$(OS)" "mingw32" ifeq "$(OS)" "mingw32"
BINTARGET=$(TARGET)-dbg.exe BINTARGET=$(TARGET)-dbg.exe
else else
BINTARGET=$(TARGET)-dbg BINTARGET=$(TARGET)-dbg
endif endif
LINKLIB=game-dbg LINKLIB=sdlgame-dbg
CXXFLAGS=-I../../../ -I$(HEADERDIR) -I./cpp -pg -g -ggdb -gstabs -Wall -c $(SDL_CFLAGS) $(ADDL_CFLAGS) CXXFLAGS=-I../../ -I$(HEADERDIR) -I./cpp -pg -g -ggdb -gstabs -Wall -c $(SDL_CFLAGS) $(ADDL_CFLAGS)
endif endif
LINKLIBS=-L../../$(CFG) -L$(LIBDIR) -l$(LINKLIB) $(SDL_LDFLAGS) -lSDL_image -lSDL_mixer -lSDL_gfx -lSDL_ttf LINKLIBS=-L../../$(CFG) -L$(LIBDIR) -l$(LINKLIB) $(SDL_LDFLAGS) -lSDL_image -lSDL_mixer -lSDL_gfx -lSDL_ttf
BINOBJ=$(OUTDIR)/demo.o BINOBJ=$(OUTDIR)/demo.o
CC = gcc CC = gcc
CXX = g++ CXX = g++
LD = $(CXX) LD = $(CXX)
INSTALL = $(which install) INSTALL = $(which install)
$(OUTDIR)/%.o : cpp/%.cpp $(OUTDIR)/%.o : cpp/%.cpp
$(CXX) $(CXXFLAGS) -o $@ $< $(CXX) $(CXXFLAGS) -o $@ $<
all: bin all: bin
bin: $(BINOBJ) bin: $(BINOBJ)
$(LD) -pg -o $(OUTDIR)/$(BINTARGET) \ $(LD) -pg -o $(OUTDIR)/$(BINTARGET) \
-pg $(BINOBJ) $(LINKLIBS) -pg $(BINOBJ) $(LINKLIBS)
.PHONY: clean .PHONY: clean
clean: clean:
rm -f $(OUTDIR)/*.o rm -f $(OUTDIR)/*.o
rm -f $(OUTDIR)/$(BINTARGET) rm -f $(OUTDIR)/$(BINTARGET)
.PHONY: rebuild .PHONY: rebuild
rebuild: rebuild:
make clean make clean
make CFG=$(CFG) make CFG=$(CFG)

View File

@@ -1,78 +1,78 @@
# This makefile is a bit hackish. I wrote it early in the AM. # This makefile is a bit hackish. I wrote it early in the AM.
# Fohgiveuhness, please!! # Fohgiveuhness, please!!
ifndef $(CFG) ifndef $(CFG)
CFG=Debug CFG=Debug
endif endif
# you can also pass : mingw32 and macosx # you can also pass : mingw32 and macosx
ifndef $(OS) ifndef $(OS)
OS=linux OS=linux
endif endif
TARGET=demo TARGET=demo
BINTARGET=$(TARGET) BINTARGET=$(TARGET)
PROJECTHOME=$(shell pwd) PROJECTHOME=$(shell pwd)
SDL_CFLAGS=$(shell sdl-config --cflags) SDL_CFLAGS=$(shell sdl-config --cflags)
SDL_LDFLAGS=$(shell sdl-config --libs) SDL_LDFLAGS=$(shell sdl-config --libs)
LIBDIR=/usr/lib LIBDIR=/usr/lib
HEADERDIR=/usr/include HEADERDIR=/usr/include
ADDL_CFLAGS= ADDL_CFLAGS=
ifeq "$(OS)" "mingw32" ifeq "$(OS)" "mingw32"
ADDL_CFLAGS=-mwindows -DBUILD_MINGW32 ADDL_CFLAGS=-mwindows -DBUILD_MINGW32
endif endif
ifeq "$(OS)" "linux" ifeq "$(OS)" "linux"
ADDL_CFLAGS=-DBUILD_LINUX ADDL_CFLAGS=-DBUILD_LINUX
endif endif
# default for release configs # default for release configs
ifeq "$(CFG)" "Release" ifeq "$(CFG)" "Release"
OUTDIR=Release OUTDIR=Release
ifeq "$(OS)" "mingw32" ifeq "$(OS)" "mingw32"
BINTARGET=$(TARGET).exe BINTARGET=$(TARGET).exe
else else
BINTARGET=$(TARGET) BINTARGET=$(TARGET)
endif endif
LINKLIB=game LINKLIB=sdlgame
CXXFLAGS=-I../../../ -I$(HEADERDIR) -I./cpp -c $(SDL_CFLAGS) $(ADDL_CFLAGS) CXXFLAGS=-I../../ -I$(HEADERDIR) -I./cpp -c $(SDL_CFLAGS) $(ADDL_CFLAGS)
endif endif
ifeq "$(CFG)" "Debug" ifeq "$(CFG)" "Debug"
OUTDIR=Debug OUTDIR=Debug
ifeq "$(OS)" "mingw32" ifeq "$(OS)" "mingw32"
BINTARGET=$(TARGET)-dbg.exe BINTARGET=$(TARGET)-dbg.exe
else else
BINTARGET=$(TARGET)-dbg BINTARGET=$(TARGET)-dbg
endif endif
LINKLIB=game-dbg LINKLIB=sdlgame-dbg
CXXFLAGS=-I../../../ -I$(HEADERDIR) -I./cpp -pg -g -ggdb -gstabs -Wall -c $(SDL_CFLAGS) $(ADDL_CFLAGS) CXXFLAGS=-I../../ -I$(HEADERDIR) -I./cpp -pg -g -ggdb -gstabs -Wall -c $(SDL_CFLAGS) $(ADDL_CFLAGS)
endif endif
LINKLIBS=-L../../$(CFG) -L$(LIBDIR) -l$(LINKLIB) $(SDL_LDFLAGS) -lSDL_image -lSDL_mixer -lSDL_gfx -lSDL_ttf LINKLIBS=-L../../$(CFG) -L$(LIBDIR) -l$(LINKLIB) $(SDL_LDFLAGS) -lSDL_image -lSDL_mixer -lSDL_gfx -lSDL_ttf
BINOBJ=$(OUTDIR)/demo.o BINOBJ=$(OUTDIR)/demo.o
CC = gcc CC = gcc
CXX = g++ CXX = g++
LD = $(CXX) LD = $(CXX)
INSTALL = $(which install) INSTALL = $(which install)
$(OUTDIR)/%.o : cpp/%.cpp $(OUTDIR)/%.o : cpp/%.cpp
$(CXX) $(CXXFLAGS) -o $@ $< $(CXX) $(CXXFLAGS) -o $@ $<
all: bin all: bin
bin: $(BINOBJ) bin: $(BINOBJ)
$(LD) -pg -o $(OUTDIR)/$(BINTARGET) \ $(LD) -pg -o $(OUTDIR)/$(BINTARGET) \
-pg $(BINOBJ) $(LINKLIBS) -pg $(BINOBJ) $(LINKLIBS)
.PHONY: clean .PHONY: clean
clean: clean:
rm -f $(OUTDIR)/*.o rm -f $(OUTDIR)/*.o
rm -f $(OUTDIR)/$(BINTARGET) rm -f $(OUTDIR)/$(BINTARGET)
.PHONY: rebuild .PHONY: rebuild
rebuild: rebuild:
make clean make clean
make CFG=$(CFG) make CFG=$(CFG)

View File

@@ -1,78 +1,78 @@
# This makefile is a bit hackish. I wrote it early in the AM. # This makefile is a bit hackish. I wrote it early in the AM.
# Fohgiveuhness, please!! # Fohgiveuhness, please!!
ifndef $(CFG) ifndef $(CFG)
CFG=Debug CFG=Debug
endif endif
# you can also pass : mingw32 and macosx # you can also pass : mingw32 and macosx
ifndef $(OS) ifndef $(OS)
OS=linux OS=linux
endif endif
TARGET=demo TARGET=demo
BINTARGET=$(TARGET) BINTARGET=$(TARGET)
PROJECTHOME=$(shell pwd) PROJECTHOME=$(shell pwd)
SDL_CFLAGS=$(shell sdl-config --cflags) SDL_CFLAGS=$(shell sdl-config --cflags)
SDL_LDFLAGS=$(shell sdl-config --libs) SDL_LDFLAGS=$(shell sdl-config --libs)
LIBDIR=/usr/lib LIBDIR=/usr/lib
HEADERDIR=/usr/include HEADERDIR=/usr/include
ADDL_CFLAGS= ADDL_CFLAGS=
ifeq "$(OS)" "mingw32" ifeq "$(OS)" "mingw32"
ADDL_CFLAGS=-mwindows -DBUILD_MINGW32 ADDL_CFLAGS=-mwindows -DBUILD_MINGW32
endif endif
ifeq "$(OS)" "linux" ifeq "$(OS)" "linux"
ADDL_CFLAGS=-DBUILD_LINUX ADDL_CFLAGS=-DBUILD_LINUX
endif endif
# default for release configs # default for release configs
ifeq "$(CFG)" "Release" ifeq "$(CFG)" "Release"
OUTDIR=Release OUTDIR=Release
ifeq "$(OS)" "mingw32" ifeq "$(OS)" "mingw32"
BINTARGET=$(TARGET).exe BINTARGET=$(TARGET).exe
else else
BINTARGET=$(TARGET) BINTARGET=$(TARGET)
endif endif
LINKLIB=game LINKLIB=sdlgame
CXXFLAGS=-I../../../ -I$(HEADERDIR) -I./cpp -c $(SDL_CFLAGS) $(ADDL_CFLAGS) CXXFLAGS=-I../../ -I$(HEADERDIR) -I./cpp -c $(SDL_CFLAGS) $(ADDL_CFLAGS)
endif endif
ifeq "$(CFG)" "Debug" ifeq "$(CFG)" "Debug"
OUTDIR=Debug OUTDIR=Debug
ifeq "$(OS)" "mingw32" ifeq "$(OS)" "mingw32"
BINTARGET=$(TARGET)-dbg.exe BINTARGET=$(TARGET)-dbg.exe
else else
BINTARGET=$(TARGET)-dbg BINTARGET=$(TARGET)-dbg
endif endif
LINKLIB=game-dbg LINKLIB=sdlgame-dbg
CXXFLAGS=-I../../../ -I$(HEADERDIR) -I./cpp -pg -g -ggdb -gstabs -Wall -c $(SDL_CFLAGS) $(ADDL_CFLAGS) CXXFLAGS=-I../../ -I$(HEADERDIR) -I./cpp -pg -g -ggdb -gstabs -Wall -c $(SDL_CFLAGS) $(ADDL_CFLAGS)
endif endif
LINKLIBS=-L../../$(CFG) -L$(LIBDIR) -l$(LINKLIB) $(SDL_LDFLAGS) -lSDL_image -lSDL_mixer -lSDL_gfx -lSDL_ttf LINKLIBS=-L../../$(CFG) -L$(LIBDIR) -l$(LINKLIB) $(SDL_LDFLAGS) -lSDL_image -lSDL_mixer -lSDL_gfx -lSDL_ttf
BINOBJ=$(OUTDIR)/demo.o BINOBJ=$(OUTDIR)/demo.o
CC = gcc CC = gcc
CXX = g++ CXX = g++
LD = $(CXX) LD = $(CXX)
INSTALL = $(which install) INSTALL = $(which install)
$(OUTDIR)/%.o : cpp/%.cpp $(OUTDIR)/%.o : cpp/%.cpp
$(CXX) $(CXXFLAGS) -o $@ $< $(CXX) $(CXXFLAGS) -o $@ $<
all: bin all: bin
bin: $(BINOBJ) bin: $(BINOBJ)
$(LD) -pg -o $(OUTDIR)/$(BINTARGET) \ $(LD) -pg -o $(OUTDIR)/$(BINTARGET) \
-pg $(BINOBJ) $(LINKLIBS) -pg $(BINOBJ) $(LINKLIBS)
.PHONY: clean .PHONY: clean
clean: clean:
rm -f $(OUTDIR)/*.o rm -f $(OUTDIR)/*.o
rm -f $(OUTDIR)/$(BINTARGET) rm -f $(OUTDIR)/$(BINTARGET)
.PHONY: rebuild .PHONY: rebuild
rebuild: rebuild:
make clean make clean
make CFG=$(CFG) make CFG=$(CFG)

View File

@@ -1,78 +1,78 @@
# This makefile is a bit hackish. I wrote it early in the AM. # This makefile is a bit hackish. I wrote it early in the AM.
# Fohgiveuhness, please!! # Fohgiveuhness, please!!
ifndef $(CFG) ifndef $(CFG)
CFG=Debug CFG=Debug
endif endif
# you can also pass : mingw32 and macosx # you can also pass : mingw32 and macosx
ifndef $(OS) ifndef $(OS)
OS=linux OS=linux
endif endif
TARGET=demo TARGET=demo
BINTARGET=$(TARGET) BINTARGET=$(TARGET)
PROJECTHOME=$(shell pwd) PROJECTHOME=$(shell pwd)
SDL_CFLAGS=$(shell sdl-config --cflags) SDL_CFLAGS=$(shell sdl-config --cflags)
SDL_LDFLAGS=$(shell sdl-config --libs) SDL_LDFLAGS=$(shell sdl-config --libs)
LIBDIR=/usr/lib LIBDIR=/usr/lib
HEADERDIR=/usr/include HEADERDIR=/usr/include
ADDL_CFLAGS= ADDL_CFLAGS=
ifeq "$(OS)" "mingw32" ifeq "$(OS)" "mingw32"
ADDL_CFLAGS=-mwindows -DBUILD_MINGW32 ADDL_CFLAGS=-mwindows -DBUILD_MINGW32
endif endif
ifeq "$(OS)" "linux" ifeq "$(OS)" "linux"
ADDL_CFLAGS=-DBUILD_LINUX ADDL_CFLAGS=-DBUILD_LINUX
endif endif
# default for release configs # default for release configs
ifeq "$(CFG)" "Release" ifeq "$(CFG)" "Release"
OUTDIR=Release OUTDIR=Release
ifeq "$(OS)" "mingw32" ifeq "$(OS)" "mingw32"
BINTARGET=$(TARGET).exe BINTARGET=$(TARGET).exe
else else
BINTARGET=$(TARGET) BINTARGET=$(TARGET)
endif endif
LINKLIB=game LINKLIB=sdlgame
CXXFLAGS=-I../../../ -I$(HEADERDIR) -I./cpp -c $(SDL_CFLAGS) $(ADDL_CFLAGS) CXXFLAGS=-I../../ -I$(HEADERDIR) -I./cpp -c $(SDL_CFLAGS) $(ADDL_CFLAGS)
endif endif
ifeq "$(CFG)" "Debug" ifeq "$(CFG)" "Debug"
OUTDIR=Debug OUTDIR=Debug
ifeq "$(OS)" "mingw32" ifeq "$(OS)" "mingw32"
BINTARGET=$(TARGET)-dbg.exe BINTARGET=$(TARGET)-dbg.exe
else else
BINTARGET=$(TARGET)-dbg BINTARGET=$(TARGET)-dbg
endif endif
LINKLIB=game-dbg LINKLIB=sdlgame-dbg
CXXFLAGS=-I../../../ -I$(HEADERDIR) -I./cpp -pg -g -ggdb -gstabs -Wall -c $(SDL_CFLAGS) $(ADDL_CFLAGS) CXXFLAGS=-I../../ -I$(HEADERDIR) -I./cpp -pg -g -ggdb -gstabs -Wall -c $(SDL_CFLAGS) $(ADDL_CFLAGS)
endif endif
LINKLIBS=-L../../$(CFG) -L$(LIBDIR) -l$(LINKLIB) $(SDL_LDFLAGS) -lSDL_image -lSDL_mixer -lSDL_gfx -lSDL_ttf LINKLIBS=-L../../$(CFG) -L$(LIBDIR) -l$(LINKLIB) $(SDL_LDFLAGS) -lSDL_image -lSDL_mixer -lSDL_gfx -lSDL_ttf
BINOBJ=$(OUTDIR)/demo.o BINOBJ=$(OUTDIR)/demo.o
CC = gcc CC = gcc
CXX = g++ CXX = g++
LD = $(CXX) LD = $(CXX)
INSTALL = $(which install) INSTALL = $(which install)
$(OUTDIR)/%.o : cpp/%.cpp $(OUTDIR)/%.o : cpp/%.cpp
$(CXX) $(CXXFLAGS) -o $@ $< $(CXX) $(CXXFLAGS) -o $@ $<
all: bin all: bin
bin: $(BINOBJ) bin: $(BINOBJ)
$(LD) -pg -o $(OUTDIR)/$(BINTARGET) \ $(LD) -pg -o $(OUTDIR)/$(BINTARGET) \
-pg $(BINOBJ) $(LINKLIBS) -pg $(BINOBJ) $(LINKLIBS)
.PHONY: clean .PHONY: clean
clean: clean:
rm -f $(OUTDIR)/*.o rm -f $(OUTDIR)/*.o
rm -f $(OUTDIR)/$(BINTARGET) rm -f $(OUTDIR)/$(BINTARGET)
.PHONY: rebuild .PHONY: rebuild
rebuild: rebuild:
make clean make clean
make CFG=$(CFG) make CFG=$(CFG)

View File

@@ -1,430 +1,430 @@
#include "libgame.h" #include "libsdlgame.h"
#include <iostream> #include <iostream>
#include <SDL_ttf.h> #include <SDL_ttf.h>
#include <SDL_gfxPrimitives.h> #include <SDL_gfxPrimitives.h>
#include <cstdlib> #include <cstdlib>
// TODO : Need to get the up/down left/right arrows displaying // TODO : Need to get the up/down left/right arrows displaying
// ------------------ Menu Relation -------------- // ------------------ Menu Relation --------------
MenuRelation::MenuRelation() MenuRelation::MenuRelation()
{ {
this->opt1 = 0; this->opt1 = 0;
this->opt2 = 0; this->opt2 = 0;
this->relation = 0; this->relation = 0;
} }
// ------------------ Menu Option ------------------- // ------------------ Menu Option -------------------
MenuOption::MenuOption(std::string name, int rangeLow, int rangeHigh, int rangeStart, int spinFree, SDL_Surface *img) MenuOption::MenuOption(std::string name, int rangeLow, int rangeHigh, int rangeStart, int spinFree, SDL_Surface *img)
{ {
this->name = name; this->name = name;
this->rangeLow = rangeLow; this->rangeLow = rangeLow;
this->rangeHigh = rangeHigh; this->rangeHigh = rangeHigh;
this->rangeStart = rangeStart; this->rangeStart = rangeStart;
this->optionImage = img; this->optionImage = img;
this->spinFree = spinFree; this->spinFree = spinFree;
if ( rangeHigh + rangeLow != 0 ) { if ( rangeHigh + rangeLow != 0 ) {
this->selected = rangeStart; this->selected = rangeStart;
} else } else
this->selected = -1; this->selected = -1;
} }
MenuOption::~MenuOption() MenuOption::~MenuOption()
{ {
} }
void MenuOption::clampValue(MenuRelation *relation, int defClampVal) void MenuOption::clampValue(MenuRelation *relation, int defClampVal)
{ {
// check our relation for clamping issues // check our relation for clamping issues
if ( relation != NULL && relation->opt1 != NULL && relation->opt2 != NULL && relation->opt1 == this ) { if ( relation != NULL && relation->opt1 != NULL && relation->opt2 != NULL && relation->opt1 == this ) {
std::cerr << "[" << this << "]->selected (" << this->selected << "=" << this->getStringValue() << ") = [" << relation->opt2 << "]->selected (" << relation->opt2->selected << "=" << relation->opt2->getStringValue() << ")\n"; std::cerr << "[" << this << "]->selected (" << this->selected << "=" << this->getStringValue() << ") = [" << relation->opt2 << "]->selected (" << relation->opt2->selected << "=" << relation->opt2->getStringValue() << ")\n";
if ( (relation->relation == MENURELATION_NODUPLICATE) && if ( (relation->relation == MENURELATION_NODUPLICATE) &&
(this->getStringValue() == relation->opt2->getStringValue()) ) { (this->getStringValue() == relation->opt2->getStringValue()) ) {
if ( ((this->selected+1) >= (int) this->optlist.size()) || if ( ((this->selected+1) >= (int) this->optlist.size()) ||
((this->rangeHigh != 0) && (this->selected+1 > this->rangeHigh)) ){ ((this->rangeHigh != 0) && (this->selected+1 > this->rangeHigh)) ){
//std::cerr << "Clamping DOWN\n"; //std::cerr << "Clamping DOWN\n";
this->selected -= 1; this->selected -= 1;
} else if ( ((this->selected - 1) < 0) || } else if ( ((this->selected - 1) < 0) ||
((this->rangeLow != 0) && (this->selected - 1 < this->rangeLow)) ) { ((this->rangeLow != 0) && (this->selected - 1 < this->rangeLow)) ) {
//std::cerr << "Clamping UP\n"; //std::cerr << "Clamping UP\n";
this->selected += 1; this->selected += 1;
} else { } else {
// we're safe to move either direction on the option here, so just ++ it and then clamp it // we're safe to move either direction on the option here, so just ++ it and then clamp it
this->selected += defClampVal; this->selected += defClampVal;
} }
this->clampValue(NULL); this->clampValue(NULL);
//std::cerr << "[" << this << "]->selected (" << this->selected << "=" << this->getStringValue() << ") = [" << relation->opt2 << "]->selected (" << relation->opt2->selected << "=" << relation->opt2->getStringValue() << ")\n"; //std::cerr << "[" << this << "]->selected (" << this->selected << "=" << this->getStringValue() << ") = [" << relation->opt2 << "]->selected (" << relation->opt2->selected << "=" << relation->opt2->getStringValue() << ")\n";
} }
} }
else { else {
if ( this->optlist.size() > 0 ) { if ( this->optlist.size() > 0 ) {
if ( this->selected >= (int) this->optlist.size() ) { if ( this->selected >= (int) this->optlist.size() ) {
this->selected = this->optlist.size()-1; this->selected = this->optlist.size()-1;
} else if ( this->selected < 0 ) { } else if ( this->selected < 0 ) {
this->selected = 0; this->selected = 0;
} }
} else { } else {
if ( this->selected < this->rangeLow ) { if ( this->selected < this->rangeLow ) {
this->selected = this->rangeLow; this->selected = this->rangeLow;
} else if ( this->selected > this->rangeHigh ) { } else if ( this->selected > this->rangeHigh ) {
this->selected = this->rangeHigh; this->selected = this->rangeHigh;
} else if ( this->rangeLow > this->rangeHigh || this->rangeLow + this->rangeHigh == 0 ) { } else if ( this->rangeLow > this->rangeHigh || this->rangeLow + this->rangeHigh == 0 ) {
this->selected = 0; this->selected = 0;
} }
} }
} }
//std::cerr << "MenuOption::clampValue " << this->name //std::cerr << "MenuOption::clampValue " << this->name
//<< " (" << this->optlist.size() << " sub-options ) " //<< " (" << this->optlist.size() << " sub-options ) "
//<< " range (" << this->rangeLow << " - " << this->rangeHigh << ") " //<< " range (" << this->rangeLow << " - " << this->rangeHigh << ") "
//<< " selected " << this->selected << "\n"; //<< " selected " << this->selected << "\n";
} }
std::string MenuOption::getStringValue() std::string MenuOption::getStringValue()
{ {
char intStringBuff[64]; char intStringBuff[64];
memset((char *)&intStringBuff, 0x00, 63); memset((char *)&intStringBuff, 0x00, 63);
if ( this->rangeLow + this->rangeHigh != 0 ) { if ( this->rangeLow + this->rangeHigh != 0 ) {
sprintf((char *)&intStringBuff, "%d\0", this->selected); sprintf((char *)&intStringBuff, "%d\0", this->selected);
return std::string((char *)&intStringBuff); return std::string((char *)&intStringBuff);
} }
if ( this->optlist.size() > this->selected ) if ( this->optlist.size() > this->selected )
return this->optlist.at(this->selected); return this->optlist.at(this->selected);
else else
return this->name; return this->name;
} }
int MenuOption::getIntValue() int MenuOption::getIntValue()
{ {
return this->selected; return this->selected;
} }
int MenuOption::select(int value) int MenuOption::select(int value)
{ {
if ( ( this->optlist.size() > 0 ) && ( value < this->optlist.size()) && ( value > -1 ) ) { if ( ( this->optlist.size() > 0 ) && ( value < this->optlist.size()) && ( value > -1 ) ) {
this->selected = value; this->selected = value;
return 0; return 0;
} else if ( (value >= this->rangeLow) && ( value <= this->rangeHigh ) ) { } else if ( (value >= this->rangeLow) && ( value <= this->rangeHigh ) ) {
this->selected = value; this->selected = value;
return 0; return 0;
} }
return 1; return 1;
} }
int MenuOption::whenhighlighted() int MenuOption::whenhighlighted()
{ {
return 0; return 0;
} }
int MenuOption::whenselected() int MenuOption::whenselected()
{ {
return 0; return 0;
} }
int MenuOption::valueup() int MenuOption::valueup()
{ {
this->select(this->selected + 1); this->select(this->selected + 1);
} }
int MenuOption::valuedown() int MenuOption::valuedown()
{ {
this->select(this->selected - 1); this->select(this->selected - 1);
} }
// ----------------- MenuDisplay -------------------- // ----------------- MenuDisplay --------------------
MenuDisplay::MenuDisplay() MenuDisplay::MenuDisplay()
{ {
this->pointerActor = NULL; this->pointerActor = NULL;
this->curOpt = 0; this->curOpt = 0;
this->origin.x = 0; this->origin.x = 0;
this->origin.y = 0; this->origin.y = 0;
this->origin.z = 0; this->origin.z = 0;
this->fontname = ""; this->fontname = "";
this->pointsize = 0; this->pointsize = 0;
this->spacing = 0; this->spacing = 0;
this->closeOpt = ""; this->closeOpt = "";
} }
MenuDisplay::~MenuDisplay() MenuDisplay::~MenuDisplay()
{ {
if ( this->pointerActor != NULL ) { if ( this->pointerActor != NULL ) {
delete this->pointerActor; delete this->pointerActor;
} }
} }
void MenuDisplay::setMenuImages(Animation *arrowLeft, Animation *arrowRight, Animation *arrowUp, Animation *arrowDown) void MenuDisplay::setMenuImages(Animation *arrowLeft, Animation *arrowRight, Animation *arrowUp, Animation *arrowDown)
{ {
this->arrowLeft = arrowLeft; this->arrowLeft = arrowLeft;
this->arrowRight = arrowRight; this->arrowRight = arrowRight;
this->arrowUp = arrowUp; this->arrowUp = arrowUp;
this->arrowDown = arrowDown; this->arrowDown = arrowDown;
} }
// this is just for backwards compatibility with old code. // this is just for backwards compatibility with old code.
void MenuDisplay::addOption(std::string name, int rangeLow = 0, int rangeHigh = 0, int rangeStart = 0, int spinFree = 0, SDL_Surface *img = NULL) void MenuDisplay::addOption(std::string name, int rangeLow = 0, int rangeHigh = 0, int rangeStart = 0, int spinFree = 0, SDL_Surface *img = NULL)
{ {
this->addOption(new MenuOption(name, rangeLow, rangeHigh, rangeStart, spinFree, img) ); this->addOption(new MenuOption(name, rangeLow, rangeHigh, rangeStart, spinFree, img) );
} }
void MenuDisplay::addOption(MenuOption *mopt) void MenuDisplay::addOption(MenuOption *mopt)
{ {
if ( mopt != NULL ) if ( mopt != NULL )
this->menuOptions.push_back(mopt); this->menuOptions.push_back(mopt);
} }
int MenuDisplay::addSubOption(std::string name, std::string subopt) int MenuDisplay::addSubOption(std::string name, std::string subopt)
{ {
std::vector<MenuOption *>::iterator iter; std::vector<MenuOption *>::iterator iter;
iter = this->menuOptions.begin(); iter = this->menuOptions.begin();
while ( iter != this->menuOptions.end() ) { while ( iter != this->menuOptions.end() ) {
if ( *iter != NULL && (*iter)->optionImage != NULL ) { if ( *iter != NULL && (*iter)->optionImage != NULL ) {
// there's zero point in adding a sub option string when this has an image // there's zero point in adding a sub option string when this has an image
return 1; return 1;
} }
if ( *iter != NULL && (*iter)->name == name ) { if ( *iter != NULL && (*iter)->name == name ) {
(*iter)->optlist.push_back(subopt); (*iter)->optlist.push_back(subopt);
(*iter)->select(0); (*iter)->select(0);
return 0; return 0;
} }
iter++; iter++;
} }
return 1; return 1;
} }
int MenuDisplay::setPointer(Animation *ptr) int MenuDisplay::setPointer(Animation *ptr)
{ {
if ( ptr == NULL ) { if ( ptr == NULL ) {
//std::cerr << "MenuDisplay::setPointer was passed a NULL Animation.\n"; //std::cerr << "MenuDisplay::setPointer was passed a NULL Animation.\n";
return 1; return 1;
} }
if ( this->pointerActor != NULL ) { if ( this->pointerActor != NULL ) {
delete this->pointerActor; delete this->pointerActor;
} else { } else {
this->pointerActor = new Actor(); this->pointerActor = new Actor();
if ( this->pointerActor == NULL ) { if ( this->pointerActor == NULL ) {
//std::cerr << "Couldn't allocate memory for new pointer actor\n"; //std::cerr << "Couldn't allocate memory for new pointer actor\n";
return 1; return 1;
} }
} }
//std::cerr << "Set animation " << ptr << " as animation for actor " << this->pointerActor << " for menu pointer\n"; //std::cerr << "Set animation " << ptr << " as animation for actor " << this->pointerActor << " for menu pointer\n";
this->pointerActor->addAnimation(ptr, STATE_NONE); this->pointerActor->addAnimation(ptr, STATE_NONE);
this->pointerActor->addState(STATE_NONE); this->pointerActor->addState(STATE_NONE);
return 0; return 0;
} }
MenuOption *MenuDisplay::getOption(std::string name) MenuOption *MenuDisplay::getOption(std::string name)
{ {
std::vector<MenuOption *>::iterator menuIter; std::vector<MenuOption *>::iterator menuIter;
MenuOption *opt = NULL; MenuOption *opt = NULL;
menuIter = this->menuOptions.begin(); menuIter = this->menuOptions.begin();
if ( name != "" ) { if ( name != "" ) {
while ( menuIter != this->menuOptions.end() ) { while ( menuIter != this->menuOptions.end() ) {
opt = *menuIter; opt = *menuIter;
//std::cerr << "Checking " << opt->name << " against " << name << "\n"; //std::cerr << "Checking " << opt->name << " against " << name << "\n";
if ( opt->name == name ) { if ( opt->name == name ) {
return opt; return opt;
} }
menuIter++; menuIter++;
} }
} else { } else {
//std::cerr << "Returning option at " << this->curOpt << "\n"; //std::cerr << "Returning option at " << this->curOpt << "\n";
return this->menuOptions.at(this->curOpt); return this->menuOptions.at(this->curOpt);
} }
return NULL; return NULL;
} }
void MenuDisplay::setMenuOrigin(Vector origin) void MenuDisplay::setMenuOrigin(Vector origin)
{ {
this->origin.x = origin.x; this->origin.x = origin.x;
this->origin.y = origin.y; this->origin.y = origin.y;
this->origin.z = origin.z; this->origin.z = origin.z;
//std::cerr << "MenuDisplay::setMenuOrigin x = " << this->origin.x << " y = " << this->origin.y << " z = " << this->origin.z << "\n"; //std::cerr << "MenuDisplay::setMenuOrigin x = " << this->origin.x << " y = " << this->origin.y << " z = " << this->origin.z << "\n";
} }
void MenuDisplay::update(int logicOnly) void MenuDisplay::update(int logicOnly)
{ {
SDL_Surface *frame = NULL; SDL_Surface *frame = NULL;
SDL_Rect destrect; SDL_Rect destrect;
SDL_Rect lastdirty; SDL_Rect lastdirty;
MenuOption *opt = NULL; MenuOption *opt = NULL;
FontRenderer &textEngine = FontRenderer::NewSingleton(); FontRenderer &textEngine = FontRenderer::NewSingleton();
int lastwidth = 0; int lastwidth = 0;
std::vector<int> yvalues; std::vector<int> yvalues;
if ( this->active == 0 ) { if ( this->active == 0 ) {
return; return;
} }
Display2D::update(logicOnly); Display2D::update(logicOnly);
//std::cerr << "curOpt now " << this->curOpt << "\n"; //std::cerr << "curOpt now " << this->curOpt << "\n";
if ( this->curOpt >= (int) this->menuOptions.size() ) { if ( this->curOpt >= (int) this->menuOptions.size() ) {
this->curOpt = this->menuOptions.size() - 1; this->curOpt = this->menuOptions.size() - 1;
} else if ( this->curOpt < 0 ) { } else if ( this->curOpt < 0 ) {
this->curOpt = 0; this->curOpt = 0;
} }
if ( logicOnly == 1 ) { if ( logicOnly == 1 ) {
return; return;
} }
//std::cerr << "fixed curOpt now " << this->curOpt << "\n"; //std::cerr << "fixed curOpt now " << this->curOpt << "\n";
lastdirty.x = (Sint16) this->origin.x; lastdirty.x = (Sint16) this->origin.x;
lastdirty.y = (Sint16) this->origin.y; lastdirty.y = (Sint16) this->origin.y;
lastdirty.w = 0; lastdirty.w = 0;
lastdirty.h = 0; lastdirty.h = 0;
frame = this->pointerActor->nextFrame(); frame = this->pointerActor->nextFrame();
if ( frame != NULL ) { if ( frame != NULL ) {
lastdirty.x += (frame->w + 10); lastdirty.x += (frame->w + 10);
} }
for ( unsigned int i = 0; i < this->menuOptions.size(); i++ ) { for ( unsigned int i = 0; i < this->menuOptions.size(); i++ ) {
opt = this->menuOptions.at(i); opt = this->menuOptions.at(i);
if ( opt == NULL ) { if ( opt == NULL ) {
continue; continue;
} }
//std::cerr << " in MenuDisplay::update i = " << i << " curOpt = " << curOpt << "\n"; //std::cerr << " in MenuDisplay::update i = " << i << " curOpt = " << curOpt << "\n";
//std::cerr << "String value of currently rendering option: " << opt->getStringValue() << "\n"; //std::cerr << "String value of currently rendering option: " << opt->getStringValue() << "\n";
lastdirty = textEngine.renderString(opt->name, this->canvas, this->fontname, (Vector){lastdirty.x, lastdirty.y + lastdirty.h, 0}, this->pointsize); lastdirty = textEngine.renderString(opt->name, this->canvas, this->fontname, (Vector){lastdirty.x, lastdirty.y + lastdirty.h, 0}, this->pointsize);
if ( i == (unsigned int) curOpt ) { if ( i == (unsigned int) curOpt ) {
//std::cerr << this->optHeight * this->curOpt << " = " << this->origin.y + (this->optHeight * this->curOpt) << " = " << ptrdest.y << "\n"; //std::cerr << this->optHeight * this->curOpt << " = " << this->origin.y + (this->optHeight * this->curOpt) << " = " << ptrdest.y << "\n";
//std::cerr << "MenuDisplay origin is x = " << this->origin.x << " y = " << this->origin.y << " z = " << this->origin.z << " optHeight is " << this->optHeight << " curOpt is " << this->curOpt << "\n"; //std::cerr << "MenuDisplay origin is x = " << this->origin.x << " y = " << this->origin.y << " z = " << this->origin.z << " optHeight is " << this->optHeight << " curOpt is " << this->curOpt << "\n";
if ( frame != NULL ) { if ( frame != NULL ) {
// the pointer actually appears slightly to the left of the current option // the pointer actually appears slightly to the left of the current option
destrect.x = (Sint16) this->origin.x; destrect.x = (Sint16) this->origin.x;
destrect.y = lastdirty.y + ((lastdirty.h/2) - frame->h/2); destrect.y = lastdirty.y + ((lastdirty.h/2) - frame->h/2);
destrect.w = 0; destrect.w = 0;
destrect.h = 0; destrect.h = 0;
//std::cerr << "Blitting frame " << frame << " to canvas " << this->canvas << " at (" << destrect.x << " x " << destrect.y << ") as pointer.\n"; //std::cerr << "Blitting frame " << frame << " to canvas " << this->canvas << " at (" << destrect.x << " x " << destrect.y << ") as pointer.\n";
SDL_BlitSurface(frame, NULL, this->canvas, &destrect); SDL_BlitSurface(frame, NULL, this->canvas, &destrect);
} }
} }
lastdirty.y += this->spacing; lastdirty.y += this->spacing;
if ( lastdirty.w > lastwidth ) { if ( lastdirty.w > lastwidth ) {
lastwidth = lastdirty.w; lastwidth = lastdirty.w;
} }
yvalues.push_back(lastdirty.y - this->spacing); yvalues.push_back(lastdirty.y - this->spacing);
} }
for ( unsigned int i = 0; i < this->menuOptions.size(); i++ ) { for ( unsigned int i = 0; i < this->menuOptions.size(); i++ ) {
opt = this->menuOptions.at(i); opt = this->menuOptions.at(i);
if ( opt->getStringValue() != opt->name ) { if ( opt->getStringValue() != opt->name ) {
textEngine.renderString(opt->getStringValue(), this->canvas, this->fontname, (Vector){lastdirty.x + lastwidth + 10, yvalues.at(i), 0}, this->pointsize); textEngine.renderString(opt->getStringValue(), this->canvas, this->fontname, (Vector){lastdirty.x + lastwidth + 10, yvalues.at(i), 0}, this->pointsize);
} }
} }
return; return;
} }
void MenuDisplay::setFont(std::string fontname, int pointsize, SDL_Color color, SDL_Color bgcolor) void MenuDisplay::setFont(std::string fontname, int pointsize, SDL_Color color, SDL_Color bgcolor)
{ {
FontRenderer &textEngine = FontRenderer::NewSingleton(); FontRenderer &textEngine = FontRenderer::NewSingleton();
textEngine.setColor(color, bgcolor, 1); textEngine.setColor(color, bgcolor, 1);
this->fontname = fontname; this->fontname = fontname;
this->pointsize = pointsize; this->pointsize = pointsize;
} }
int MenuDisplay::handleEvent(SDL_Event *event) int MenuDisplay::handleEvent(SDL_Event *event)
{ {
MenuOption *opt = NULL; MenuOption *opt = NULL;
opt = this->getOption(); opt = this->getOption();
int retval = 1; int retval = 1;
if ( this->active == 0 || opt == NULL ) { if ( this->active == 0 || opt == NULL ) {
return retval; return retval;
} }
//std::cerr << "MenuDisplay::handleEvent\n"; //std::cerr << "MenuDisplay::handleEvent\n";
//switch (event->type) { //switch (event->type) {
//default: //default:
if ( event->key.state == SDL_RELEASED && event->key.keysym.sym == SDLK_DOWN ) { if ( event->key.state == SDL_RELEASED && event->key.keysym.sym == SDLK_DOWN ) {
this->curOpt += 1; this->curOpt += 1;
if ( this->curOpt < 0 ) { if ( this->curOpt < 0 ) {
this->curOpt = 0; this->curOpt = 0;
} }
retval = 0; retval = 0;
} else if ( event->key.state == SDL_RELEASED && event->key.keysym.sym == SDLK_UP ) { } else if ( event->key.state == SDL_RELEASED && event->key.keysym.sym == SDLK_UP ) {
this->curOpt -= 1; this->curOpt -= 1;
if ( this->curOpt >= (int) this->menuOptions.size() ) { if ( this->curOpt >= (int) this->menuOptions.size() ) {
this->curOpt = this->menuOptions.size()-1; this->curOpt = this->menuOptions.size()-1;
} }
retval = 0; retval = 0;
} else if ( ( event->key.state == SDL_RELEASED || opt->spinFree == 1 && event->key.state == SDL_PRESSED ) } else if ( ( event->key.state == SDL_RELEASED || opt->spinFree == 1 && event->key.state == SDL_PRESSED )
&& event->key.keysym.sym == SDLK_LEFT ) { && event->key.keysym.sym == SDLK_LEFT ) {
opt->valuedown(); opt->valuedown();
this->clampValue(opt, -1); this->clampValue(opt, -1);
retval = 0; retval = 0;
} else if ( ( event->key.state == SDL_RELEASED || opt->spinFree == 1 && event->key.state == SDL_PRESSED ) } else if ( ( event->key.state == SDL_RELEASED || opt->spinFree == 1 && event->key.state == SDL_PRESSED )
&& event->key.keysym.sym == SDLK_RIGHT ) { && event->key.keysym.sym == SDLK_RIGHT ) {
opt->valueup(); opt->valueup();
this->clampValue(opt, 1); this->clampValue(opt, 1);
retval = 0; retval = 0;
} else if ( event->key.state == SDL_RELEASED && event->key.keysym.sym == SDLK_RETURN ) { } else if ( event->key.state == SDL_RELEASED && event->key.keysym.sym == SDLK_RETURN ) {
if ( (this->closeOpt != "") && (opt->name != this->closeOpt)) { if ( (this->closeOpt != "") && (opt->name != this->closeOpt)) {
retval = 0; retval = 0;
} else if ( ((this->closeOpt != "" ) && (opt->name == this->closeOpt)) || this->closeOpt == "") { } else if ( ((this->closeOpt != "" ) && (opt->name == this->closeOpt)) || this->closeOpt == "") {
this->active = 0; this->active = 0;
retval = 0; retval = 0;
} }
} }
//} //}
//opt->clampValue(); //opt->clampValue();
return retval; return retval;
} }
void MenuDisplay::setCloseOption(std::string option) void MenuDisplay::setCloseOption(std::string option)
{ {
this->closeOpt = option; this->closeOpt = option;
} }
void MenuDisplay::setSpacing(int spacing) void MenuDisplay::setSpacing(int spacing)
{ {
this->spacing = spacing; this->spacing = spacing;
} }
int MenuDisplay::setRelation(std::string opt1, std::string opt2, int relationType) int MenuDisplay::setRelation(std::string opt1, std::string opt2, int relationType)
{ {
std::vector<MenuRelation *>::iterator iter; std::vector<MenuRelation *>::iterator iter;
MenuRelation *tmp; MenuRelation *tmp;
iter = this->menuRelations.begin(); iter = this->menuRelations.begin();
while ( iter != this->menuRelations.end() ) { while ( iter != this->menuRelations.end() ) {
tmp = *iter; tmp = *iter;
if ( tmp == NULL || tmp->opt1 == NULL || tmp->opt2 == NULL ) { if ( tmp == NULL || tmp->opt1 == NULL || tmp->opt2 == NULL ) {
iter++; iter++;
continue; continue;
} }
if ( tmp->opt1->name == opt1 && tmp->opt2->name == opt2 && tmp->relation == relationType ) { if ( tmp->opt1->name == opt1 && tmp->opt2->name == opt2 && tmp->relation == relationType ) {
return 1; return 1;
} }
iter++; iter++;
} }
tmp = new MenuRelation(); tmp = new MenuRelation();
tmp->opt1 = this->getOption(opt1); tmp->opt1 = this->getOption(opt1);
tmp->opt2 = this->getOption(opt2); tmp->opt2 = this->getOption(opt2);
tmp->relation = relationType; tmp->relation = relationType;
this->menuRelations.push_back(tmp); this->menuRelations.push_back(tmp);
this->clampValue(tmp->opt1, 1); this->clampValue(tmp->opt1, 1);
return 0; return 0;
} }
void MenuDisplay::clampValue(MenuOption *opt, int defclamp) void MenuDisplay::clampValue(MenuOption *opt, int defclamp)
{ {
std::vector<MenuRelation *>::iterator iter; std::vector<MenuRelation *>::iterator iter;
MenuRelation *tmp; MenuRelation *tmp;
opt->clampValue(); opt->clampValue();
//std::cerr << "(PRE-RELATION CLAMP) Option " << opt->name << " now set to option " << opt->getIntValue() << "=" << opt->getStringValue() << "\n"; //std::cerr << "(PRE-RELATION CLAMP) Option " << opt->name << " now set to option " << opt->getIntValue() << "=" << opt->getStringValue() << "\n";
iter = this->menuRelations.begin(); iter = this->menuRelations.begin();
while ( iter != this->menuRelations.end() ) { while ( iter != this->menuRelations.end() ) {
tmp = *iter; tmp = *iter;
if ( tmp == NULL || tmp->opt1 == NULL || tmp->opt2 == NULL ) { if ( tmp == NULL || tmp->opt1 == NULL || tmp->opt2 == NULL ) {
iter++; iter++;
continue; continue;
} }
if ( tmp->opt1->name == opt->name ) { if ( tmp->opt1->name == opt->name ) {
//std::cerr << "Found relation for " << opt->name << " (" << tmp->opt1 << " = " << tmp->opt2 << ")\n"; //std::cerr << "Found relation for " << opt->name << " (" << tmp->opt1 << " = " << tmp->opt2 << ")\n";
opt->clampValue(tmp, defclamp); opt->clampValue(tmp, defclamp);
} }
iter++; iter++;
} }
//std::cerr << "(POST-RELATION CLAMP) Option " << opt->name << " now set to option " << opt->getIntValue << "=" <<opt->getStringValue() << "\n"; //std::cerr << "(POST-RELATION CLAMP) Option " << opt->name << " now set to option " << opt->getIntValue << "=" <<opt->getStringValue() << "\n";
} }

View File

@@ -1,97 +1,97 @@
#ifndef __MENUDISPLAY_H__ #ifndef __MENUDISPLAY_H__
#define __MENUDISPLAY_H__ #define __MENUDISPLAY_H__
#include "Actor.h" #include "Actor.h"
#include "Common.h" #include "Common.h"
#include "Display2D.h" #include "Display2D.h"
#include <vector> #include <vector>
// TODO: Add the ability to set a MenuOption to display as either text or as a slider for numeric values. // TODO: Add the ability to set a MenuOption to display as either text or as a slider for numeric values.
typedef struct MenuRelation; typedef struct MenuRelation;
#define MENU_OPTYPE_CHOICE 0 #define MENU_OPTYPE_CHOICE 0
#define MENU_OPTYPE_RANGE 1 #define MENU_OPTYPE_RANGE 1
#define MENU_OPTYPE_SUBMENU 2 #define MENU_OPTYPE_SUBMENU 2
class MenuOption class MenuOption
{ {
public: public:
std::string name; std::string name;
SDL_Surface *optionImage; SDL_Surface *optionImage;
std::vector<std::string> optlist; std::vector<std::string> optlist;
int rangeLow; int rangeLow;
int rangeHigh; int rangeHigh;
int rangeStart; int rangeStart;
int selected; // doesn't hold info on whether this is selected or not, holds the index of optlist or the range number that is currently selected int selected; // doesn't hold info on whether this is selected or not, holds the index of optlist or the range number that is currently selected
int spinFree; // if this is set to 1, then the value is modified on the presence of a key DOWN event, not a key RELEASE. int spinFree; // if this is set to 1, then the value is modified on the presence of a key DOWN event, not a key RELEASE.
MenuOption(std::string name, int rangeLow, int rangeHigh, int rangeStart, int spinFree, SDL_Surface *img); MenuOption(std::string name, int rangeLow, int rangeHigh, int rangeStart, int spinFree, SDL_Surface *img);
~MenuOption(); ~MenuOption();
void clampValue(MenuRelation *relation = NULL, int defClampVal = 1); void clampValue(MenuRelation *relation = NULL, int defClampVal = 1);
int getIntValue(); int getIntValue();
std::string getStringValue(); std::string getStringValue();
virtual int select(int value); // called by MenuDisplay to force selection to a given item virtual int select(int value); // called by MenuDisplay to force selection to a given item
virtual int whenhighlighted(); // called whenever the menu item is highlighted virtual int whenhighlighted(); // called whenever the menu item is highlighted
virtual int whenselected(); // called whenever the menu item is selected ("enter" is pressed on the item) virtual int whenselected(); // called whenever the menu item is selected ("enter" is pressed on the item)
virtual int valueup(); // called whenever the value of the item is increased (the range is moved up, or the next sub option is selected) virtual int valueup(); // called whenever the value of the item is increased (the range is moved up, or the next sub option is selected)
virtual int valuedown(); // as with valueup(), but works with lower values and previous items virtual int valuedown(); // as with valueup(), but works with lower values and previous items
}; };
#define MENURELATION_NODUPLICATE 0 #define MENURELATION_NODUPLICATE 0
struct MenuRelation struct MenuRelation
{ {
MenuOption *opt1; MenuOption *opt1;
MenuOption *opt2; MenuOption *opt2;
int relation; int relation;
MenuRelation(); MenuRelation();
}; };
// class for the menus in the game // class for the menus in the game
// This class dynamically creates actors for the menu options and such // This class dynamically creates actors for the menu options and such
// the only actor you have to feed it is your pointer Animation // the only actor you have to feed it is your pointer Animation
class MenuDisplay : public Display2D class MenuDisplay : public Display2D
{ {
protected: protected:
std::vector<MenuOption *> menuOptions; std::vector<MenuOption *> menuOptions;
std::vector<MenuRelation *> menuRelations; std::vector<MenuRelation *> menuRelations;
std::vector<MenuDisplay *> subMenus; std::vector<MenuDisplay *> subMenus;
Actor *pointerActor; Actor *pointerActor;
int curOpt; int curOpt;
Vector origin; Vector origin;
SDL_Color textColor; SDL_Color textColor;
SDL_Color bgColor; SDL_Color bgColor;
std::string fontname; std::string fontname;
int pointsize; int pointsize;
int spacing; int spacing;
std::string closeOpt; std::string closeOpt;
Animation *arrowUp; Animation *arrowUp;
Animation *arrowDown; Animation *arrowDown;
Animation *arrowLeft; Animation *arrowLeft;
Animation *arrowRight; Animation *arrowRight;
public: public:
MenuDisplay(); MenuDisplay();
~MenuDisplay(); ~MenuDisplay();
void setCloseOption(std::string option); void setCloseOption(std::string option);
void setSpacing(int spacing); void setSpacing(int spacing);
int setPointer(Animation *ptr); int setPointer(Animation *ptr);
void setMenuOrigin(Vector origin); void setMenuOrigin(Vector origin);
void setMenuImages(Animation *arrowLeft, Animation *arrowRight, Animation *arrowUp, Animation *arrowDown); void setMenuImages(Animation *arrowLeft, Animation *arrowRight, Animation *arrowUp, Animation *arrowDown);
void setFont(std::string fontname, int pointsize, SDL_Color color, SDL_Color bgcolor); void setFont(std::string fontname, int pointsize, SDL_Color color, SDL_Color bgcolor);
void update(int logicOnly = 0); void update(int logicOnly = 0);
int handleEvent(SDL_Event *event); int handleEvent(SDL_Event *event);
void clampValue(MenuOption *opt, int defClamp); void clampValue(MenuOption *opt, int defClamp);
int setRelation(std::string opt1, std::string opt2, int relationType = MENURELATION_NODUPLICATE); int setRelation(std::string opt1, std::string opt2, int relationType = MENURELATION_NODUPLICATE);
void setOption(std::string optName, std::string ); void setOption(std::string optName, std::string );
void setOption(std::string optName, int); void setOption(std::string optName, int);
void addOption(MenuOption *mopt); void addOption(MenuOption *mopt);
void addOption(std::string name, int rangeLow, int rangeHigh, int rangeStart, int spinFree, SDL_Surface *img); void addOption(std::string name, int rangeLow, int rangeHigh, int rangeStart, int spinFree, SDL_Surface *img);
int addSubOption(std::string name, std::string subopt); int addSubOption(std::string name, std::string subopt);
MenuOption *getOption(std::string name = ""); MenuOption *getOption(std::string name = "");
}; };
#endif // __MENUDISPLAY_H__ #endif // __MENUDISPLAY_H__

View File

@@ -29,7 +29,7 @@ protected:
* @class AnimatedRenderable * @class AnimatedRenderable
* @brief A subclass of Renderable for objects that are renderable and animated * @brief A subclass of Renderable for objects that are renderable and animated
* *
* This subclass defines the interface for libgame objects that are both * This subclass defines the interface for libsdlgame objects that are both
* Renderable, but that also perform some kind of internal logic to return * Renderable, but that also perform some kind of internal logic to return
* different surfaces each call. * different surfaces each call.
*/ */

View File

@@ -1,15 +1,15 @@
#ifndef __LIBGAME_H__ #ifndef __LIBGAME_H__
#define __LIBGAME_H__ #define __LIBGAME_H__
#include "Common.h" #include "Common.h"
#include "FontRenderer.h" #include "FontRenderer.h"
#include "Renderable.h" #include "Renderable.h"
#include "SpriteStrip.h" #include "SpriteStrip.h"
#include "Animation.h" #include "Animation.h"
#include "Actor.h" #include "Actor.h"
#include "Display.h" #include "Display.h"
#include "Display2D.h" #include "Display2D.h"
#include "MenuDisplay.h" #include "MenuDisplay.h"
#include "Game.h" #include "Game.h"
#endif // __LIBGAME_H__ #endif // __LIBGAME_H__

View File

@@ -1,77 +1,77 @@
# This makefile is a bit hackish. I wrote it early in the AM. # This makefile is a bit hackish. I wrote it early in the AM.
# Fohgiveuhness, please!! # Fohgiveuhness, please!!
ifndef $(CFG) ifndef $(CFG)
CFG=Debug CFG=Debug
endif endif
# you can also pass : mingw32 and macosx # you can also pass : mingw32 and macosx
ifndef $(OS) ifndef $(OS)
OS=linux OS=linux
endif endif
TARGET=animate TARGET=animate
BINTARGET=$(TARGET) BINTARGET=$(TARGET)
PROJECTHOME=$(shell pwd) PROJECTHOME=$(shell pwd)
SDL_CFLAGS=$(shell sdl-config --cflags) SDL_CFLAGS=$(shell sdl-config --cflags)
SDL_LDFLAGS=$(shell sdl-config --libs) SDL_LDFLAGS=$(shell sdl-config --libs)
LIBDIR=/usr/lib LIBDIR=/usr/lib
HEADERDIR=/usr/include HEADERDIR=/usr/include
ADDL_CFLAGS= ADDL_CFLAGS=
ifeq "$(OS)" "mingw32" ifeq "$(OS)" "mingw32"
ADDL_CFLAGS=-mwindows -DBUILD_MINGW32 ADDL_CFLAGS=-mwindows -DBUILD_MINGW32
endif endif
ifeq "$(OS)" "linux" ifeq "$(OS)" "linux"
ADDL_CFLAGS=-DBUILD_LINUX ADDL_CFLAGS=-DBUILD_LINUX
endif endif
# default for release configs # default for release configs
ifeq "$(CFG)" "Release" ifeq "$(CFG)" "Release"
OUTDIR=Release OUTDIR=Release
ifeq "$(OS)" "mingw32" ifeq "$(OS)" "mingw32"
BINTARGET=$(TARGET).exe BINTARGET=$(TARGET).exe
else else
BINTARGET=$(TARGET) BINTARGET=$(TARGET)
endif endif
LINKLIB=game LINKLIB=game
CXXFLAGS=-I../../../ -I$(HEADERDIR) -I./cpp -c $(SDL_CFLAGS) $(ADDL_CFLAGS) CXXFLAGS=-I../../../ -I$(HEADERDIR) -I./cpp -c $(SDL_CFLAGS) $(ADDL_CFLAGS)
endif endif
ifeq "$(CFG)" "Debug" ifeq "$(CFG)" "Debug"
OUTDIR=Debug OUTDIR=Debug
ifeq "$(OS)" "mingw32" ifeq "$(OS)" "mingw32"
BINTARGET=$(TARGET)-dbg.exe BINTARGET=$(TARGET)-dbg.exe
else else
BINTARGET=$(TARGET)-dbg BINTARGET=$(TARGET)-dbg
endif endif
LINKLIB=game-dbg LINKLIB=game-dbg
CXXFLAGS=-I../../../ -I$(HEADERDIR) -I./cpp -pg -g -ggdb -gstabs -Wall -c $(SDL_CFLAGS) $(ADDL_CFLAGS) CXXFLAGS=-I../../../ -I$(HEADERDIR) -I./cpp -pg -g -ggdb -gstabs -Wall -c $(SDL_CFLAGS) $(ADDL_CFLAGS)
endif endif
LINKLIBS=-L../../$(CFG) -L$(LIBDIR) -l$(LINKLIB) $(SDL_LDFLAGS) -lSDL_image -lSDL_mixer -lSDL_gfx -lSDL_ttf LINKLIBS=-L../../$(CFG) -L$(LIBDIR) -l$(LINKLIB) $(SDL_LDFLAGS) -lSDL_image -lSDL_mixer -lSDL_gfx -lSDL_ttf
BINOBJ=$(OUTDIR)/demo.o BINOBJ=$(OUTDIR)/demo.o
CC = gcc CC = gcc
CXX = g++ CXX = g++
LD = $(CXX) LD = $(CXX)
INSTALL = $(which install) INSTALL = $(which install)
$(OUTDIR)/%.o : cpp/%.cpp $(OUTDIR)/%.o : cpp/%.cpp
$(CXX) $(CXXFLAGS) -o $@ $< $(CXX) $(CXXFLAGS) -o $@ $<
all: bin all: bin
bin: $(BINOBJ) bin: $(BINOBJ)
$(LD) -pg -o $(OUTDIR)/$(BINTARGET) \ $(LD) -pg -o $(OUTDIR)/$(BINTARGET) \
-pg $(BINOBJ) $(LINKLIBS) -pg $(BINOBJ) $(LINKLIBS)
.PHONY: clean .PHONY: clean
clean: clean:
rm -f $(OUTDIR)/*.o rm -f $(OUTDIR)/*.o
rm -f $(OUTDIR)/$(BINTARGET) rm -f $(OUTDIR)/$(BINTARGET)
.PHONY: rebuild .PHONY: rebuild
rebuild: rebuild:
make clean make clean
make CFG=$(CFG) make CFG=$(CFG)