Skip to content

Commit

Permalink
GitHub'd
Browse files Browse the repository at this point in the history
  • Loading branch information
bl0ckeduser committed Nov 30, 2011
0 parents commit 2a3eb7a
Show file tree
Hide file tree
Showing 46 changed files with 14,371 additions and 0 deletions.
129 changes: 129 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,129 @@
#---------------------------------------------------------------------------------
.SUFFIXES:
#---------------------------------------------------------------------------------

ifeq ($(strip $(DEVKITARM)),)
$(error "Please set DEVKITARM in your environment. export DEVKITARM=<path to>devkitARM")
endif

include $(DEVKITARM)/ds_rules

#---------------------------------------------------------------------------------
# TARGET is the name of the output
# BUILD is the directory where object files & intermediate files will be placed
# SOURCES is a list of directories containing source code
# INCLUDES is a list of directories containing extra header files
#---------------------------------------------------------------------------------
TARGET := $(shell basename $(CURDIR))
BUILD := build
SOURCES := source .
DATA := data
INCLUDES := include

#---------------------------------------------------------------------------------
# options for code generation
#---------------------------------------------------------------------------------
ARCH := -mthumb -mthumb-interwork

CFLAGS := -g -Wall -O2\
-march=armv5te -mtune=arm946e-s -fomit-frame-pointer\
-ffast-math \
$(ARCH)

CFLAGS += $(INCLUDE) -DARM9
CXXFLAGS := $(CFLAGS) -fno-rtti -fno-exceptions

ASFLAGS := -g $(ARCH)
LDFLAGS = -specs=ds_arm9.specs -g $(ARCH) -mno-fpu -Wl,-Map,$(notdir $*.map)

#---------------------------------------------------------------------------------
# any extra libraries we wish to link with the project
#---------------------------------------------------------------------------------
LIBS := -lnds9


#---------------------------------------------------------------------------------
# list of directories containing libraries, this must be the top level containing
# include and lib
#---------------------------------------------------------------------------------
LIBDIRS := $(LIBNDS)

#---------------------------------------------------------------------------------
# no real need to edit anything past this point unless you need to add additional
# rules for different file extensions
#---------------------------------------------------------------------------------
ifneq ($(BUILD),$(notdir $(CURDIR)))
#---------------------------------------------------------------------------------

export OUTPUT := $(CURDIR)/$(TARGET)

export VPATH := $(foreach dir,$(SOURCES),$(CURDIR)/$(dir)) \
$(foreach dir,$(DATA),$(CURDIR)/$(dir))

export DEPSDIR := $(CURDIR)/$(BUILD)

CFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.c)))
CPPFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.cpp)))
SFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.s)))
BINFILES := $(foreach dir,$(DATA),$(notdir $(wildcard $(dir)/*.*)))

#---------------------------------------------------------------------------------
# use CXX for linking C++ projects, CC for standard C
#---------------------------------------------------------------------------------
ifeq ($(strip $(CPPFILES)),)
#---------------------------------------------------------------------------------
export LD := $(CC)
#---------------------------------------------------------------------------------
else
#---------------------------------------------------------------------------------
export LD := $(CXX)
#---------------------------------------------------------------------------------
endif
#---------------------------------------------------------------------------------

export OFILES := $(addsuffix .o,$(BINFILES)) \
$(CPPFILES:.cpp=.o) $(CFILES:.c=.o) $(SFILES:.s=.o)

export INCLUDE := $(foreach dir,$(INCLUDES),-I$(CURDIR)/$(dir)) \
$(foreach dir,$(LIBDIRS),-I$(dir)/include) \
$(foreach dir,$(LIBDIRS),-I$(dir)/include) \
-I$(CURDIR)/$(BUILD)

export LIBPATHS := $(foreach dir,$(LIBDIRS),-L$(dir)/lib)

.PHONY: $(BUILD) clean

#---------------------------------------------------------------------------------
$(BUILD):
@[ -d $@ ] || mkdir -p $@
@make --no-print-directory -C $(BUILD) -f $(CURDIR)/Makefile

#---------------------------------------------------------------------------------
clean:
@echo clean ...
@rm -fr $(BUILD) $(TARGET).elf $(TARGET).nds $(TARGET).ds.gba


#---------------------------------------------------------------------------------
else

DEPENDS := $(OFILES:.o=.d)

#---------------------------------------------------------------------------------
# main targets
#---------------------------------------------------------------------------------
$(OUTPUT).nds : $(OUTPUT).elf
$(OUTPUT).elf : $(OFILES)

#---------------------------------------------------------------------------------
%.bin.o : %.bin
#---------------------------------------------------------------------------------
@echo $(notdir $<)
@$(bin2o)


-include $(DEPENDS)

#---------------------------------------------------------------------------------------
endif
#---------------------------------------------------------------------------------------
60 changes: 60 additions & 0 deletions Makefile.pc
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
# now works in BSD `make'

CFLAGS = -DPC_TARGET `sdl-config --libs --cflags`

CC ?= cc
objects = bullet-mdl.o bullet.o collisions.o door-mdl.o door.o framerate.o gc.o genBoxes.o key-mdl.o key.o main.o maze-mdl.o mem-check.o model-draw.o model-load.o objlist.o player.o require.o string-read.o target.o turtle-mdl.o worldfile.o

headers = headers.h

clown: $(objects)
$(CC) -o demo $(objects) $(CFLAGS)

clean:
rm -f demo $(objects)


bullet-mdl.o: bullet-mdl.c $(headers)
$(CC) -c -o bullet-mdl.o bullet-mdl.c $(CFLAGS)
bullet.o: bullet.c $(headers)
$(CC) -c -o bullet.o bullet.c $(CFLAGS)
collisions.o: collisions.c $(headers)
$(CC) -c -o collisions.o collisions.c $(CFLAGS)
door-mdl.o: door-mdl.c $(headers)
$(CC) -c -o door-mdl.o door-mdl.c $(CFLAGS)
door.o: door.c $(headers)
$(CC) -c -o door.o door.c $(CFLAGS)
framerate.o: framerate.c $(headers)
$(CC) -c -o framerate.o framerate.c $(CFLAGS)
gc.o: gc.c $(headers)
$(CC) -c -o gc.o gc.c $(CFLAGS)
genBoxes.o: genBoxes.c $(headers)
$(CC) -c -o genBoxes.o genBoxes.c $(CFLAGS)
key-mdl.o: key-mdl.c $(headers)
$(CC) -c -o key-mdl.o key-mdl.c $(CFLAGS)
key.o: key.c $(headers)
$(CC) -c -o key.o key.c $(CFLAGS)
main.o: main.c $(headers)
$(CC) -c -o main.o main.c $(CFLAGS)
maze-mdl.o: maze-mdl.c $(headers)
$(CC) -c -o maze-mdl.o maze-mdl.c $(CFLAGS)
mem-check.o: mem-check.c $(headers)
$(CC) -c -o mem-check.o mem-check.c $(CFLAGS)
model-draw.o: model-draw.c $(headers)
$(CC) -c -o model-draw.o model-draw.c $(CFLAGS)
model-load.o: model-load.c $(headers)
$(CC) -c -o model-load.o model-load.c $(CFLAGS)
objlist.o: objlist.c $(headers)
$(CC) -c -o objlist.o objlist.c $(CFLAGS)
player.o: player.c $(headers)
$(CC) -c -o player.o player.c $(CFLAGS)
require.o: require.c $(headers)
$(CC) -c -o require.o require.c $(CFLAGS)
string-read.o: string-read.c $(headers)
$(CC) -c -o string-read.o string-read.c $(CFLAGS)
target.o: target.c $(headers)
$(CC) -c -o target.o target.c $(CFLAGS)
turtle-mdl.o: turtle-mdl.c $(headers)
$(CC) -c -o turtle-mdl.o turtle-mdl.c $(CFLAGS)
worldfile.o: worldfile.c $(headers)
$(CC) -c -o worldfile.o worldfile.c $(CFLAGS)
34 changes: 34 additions & 0 deletions README
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
This is an *extremely work-in-progress*, non-finalized
port to NDS (via the libnds API) of my 3d platformer engine, "clown3d".
The source here was forked from the November 12, 2011 snapshot of
clown3d.

The first phase of porting involved decreasing the
vertex count of all the models to make them "fit" on
the DS' limited GPU; I also made sure the engine's RAM
usage didn't exceed the DS' limit (4 MB, I think).
Finally, I had to store model files as char[]'s in source
files (could have been header files, more typical) and
implement a reader (string-read.c) because
you don't usually have a filesystem available on NDS.
(the data-source directory contains the low-poly model files).

I then copy-pasted libnds 3D example code by Dovoto to
start porting to the libnds pseudo-GL API (and DS buttons,
timing, etc.)

Following that, several quirks in libnds had to be worked
around.

Right now, I'm still trying to improve the graphics and
optimize the code. I have yet to test the program on a
real console.

--------------------------------------------------------------

Note that the current clown3D-ds can still be built for the
PC using either Makefile.pc or mingw-build.bat; to build the
libnds version use Makefile. The PC build shows a vertex count
and (optionally, see main.c) a RAM usage estimation.


54 changes: 54 additions & 0 deletions README-original.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
Readme for original PC version from which this port was forked:

----------------------- about -------------------------------------

This is an extremely simple 3D platformer demo, featuring AABB
collisions (via homegrown collision code based on simplistic
vector arithmetic), bullets which disappear ("explode") when they hit
objects, and variable FPS physics (via "delta time" calculations and
constant acceleration formulas).

This is my first [ongoing] attempt at a truly 3D game. It is
written in the C programming language using the GL/glu and SDL APIs.

It is mostly written from scratch, however...

- Thanks to the many great OpenGL tutorials available on the
Web (notably NeHe's), as well as the freely available
"OpenGL Red Book", and, finally to the great OpenGL man pages.

NeHe OpenGL tutorials: http://nehe.gamedev.net/
"OpenGL Red Book": http://www.opengl.org/documentation/red_book/

- Thanks to the great OBJ file format documentation available
at [http://www.royriggs.com/obj.html]. The current program
uses a custom OBJ-like 3D model file format.

- The OOP-style object code structure was heavily influenced by
the structure of the source code for the C++ game "Grall 2"
by nikki93 (http://nikhilesh.info/grall2.html).

- Variable FPS physics formulas taken from my grade 11 physics course

----------------------- controls ----------------------------------

movement: cursor keys (aka up/down/left/right arrow keys)
(Note that the left and right keys rotate the
player, while up and down keys translate the
player)
jumping: Z key
shooting bullets: S key
resetting the game: R key

keypad 1: switch to third-person view (default)
keypad 2: switch to first-person view

----------------------- arguments --------------------------------

- using "-f" as the *last* argument runs the game full-screen
- alternate levels can be specified by typing in e.g.
./demo worlds/maze (Unix)
demo worlds/maze (Windows)



25 changes: 25 additions & 0 deletions TODO
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
+ Good low-poly map
+ Low-poly player; optimized again
+ Store datafiles in sourcefiles !
System for this set up. See data2src.sh script !
+ Why doesn't the player model ("turtle") appear ???!
Fixed. read_float returned an int o_O
+ Low-poly and map-included bullets, keys, doors
+ Uses only about 42 KB of program (i.e. not video) RAM
Also the model data only uses about 50 KB of ROM.
+ Ported to libnds (define PC_TARGET to build with SDL/GL,
don't define it to build with libnds)
+ Works at 30 FPS regardless of platform; on DS, it's
also VSync'd to this. (60 FPS is hard ! Famous programmer
John Carmack said so in some article).
+ The world map is messed up ! I have no idea why !
Bug fixed: glVertex3f only accepts coordinates in a certain
(small) range. A workaround for this quirk was added to
model-draw.c; use drawModelWithGL_big(model*) to use this
fixed version.
- Faster code / optimize
* key model seems to be the [performance] culprit
- Add lighting/shininess/antialiasing/you-name-it effects
to make things nicer


31 changes: 31 additions & 0 deletions bullet-mdl.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/*
#include <stdio.h>
int main(int argc, char** argv)
{
char c;
printf("char %s[] = \"", argv[1]);
while(!feof(stdin)){
c = getchar();
if(c=='\n') printf(" \\");
putchar(c);
}
printf("\";\n");
return 0;
}
*/
char bullet_model[] = "newgroup \
color 255 255 0 \
vertex -1 -0.5 0.5 \
vertex -1 0.5 0.5 \
vertex 1 -0.5 0.5 \
vertex 1 0.5 0.5 \
vertex 1 -0.5 -0.5 \
vertex 1 0.5 -0.5 \
vertex -1 -0.5 -0.5 \
vertex -1 0.5 -0.5 \
face 1 2 4 3 \
face 3 4 6 5 \
face 5 6 8 7 \
face 7 8 2 1 \
face 2 8 6 4 \
face 7 1 3 5";
Loading

0 comments on commit 2a3eb7a

Please sign in to comment.