Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
Controllers for the behaviour of game objects are reusable across sev…
…eral projects. They are also used for [[https://sylvainhb.blogspot.com/search/label/runme|the standalone "runME" tool]] so let's have them in their own directory.
- Loading branch information
Showing
3 changed files
with
130 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
#--------------------------------------------------------------------------------- | ||
.SUFFIXES: | ||
|
||
ROOT ?= $(abspath $(CURDIR)/..) | ||
M := libplugins | ||
CPU := arm9 | ||
TARGET := $M | ||
DATA := data | ||
INCLUDES= include | ||
LIBS = -lfat -lnds9 -ldswifi9 | ||
LIBDIRS = $(LIBNDS) $(LIBPPP9) $(LIBGEDS) $(LIBNTXM) | ||
|
||
include $(ROOT)/common.mk | ||
|
||
#--------------------------------------------------------------------------------- | ||
# 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 | ||
#--------------------------------------------------------------------------------- | ||
|
||
LIBRARY := $(OUTPUT)/lib/$M.a | ||
$M_LIBRARY := $(LIBRARY) | ||
|
||
.PHONY: $(BUILD) clean install | ||
all: $M-all | ||
$M-all: $(BUILD) | ||
#--------------------------------------------------------------------------------- | ||
$(BUILD): | ||
mkdir -p $@ | ||
|
||
#--------------------------------------------------------------------------------- | ||
clean: $M-clean | ||
$M-clean: | ||
@echo $@ ... | ||
rm -fr $(libplugins_BUILD) $(libplugins_LIBRARY) | ||
|
||
$M-dox: | ||
-rm dox/html/*.html | ||
doxygen | ||
|
||
$M-postdox: dox | ||
cp dox/html/doxygen.css.org dox/html/doxygen.css | ||
cp dox/html/tabs.css.org dox/html/tabs.css | ||
cd dox/html ; fe class*.html "mv % /tmp/% ; sed /tmp/% -e 's:/a>0[0-9]*:/a>:g;' > % ; echo % stripped" ; cd - | ||
cd dox/html ; mv classes.html /tmp/ ; sed /tmp/classes.html -e "s/>[A-Z][a-zA-Z]*::/>/g;" > classes.html ; cd - | ||
echo all done. | ||
|
||
|
||
#--------------------------------------------------------------------------------- | ||
# main targets | ||
#--------------------------------------------------------------------------------- | ||
$M-all: $(LIBRARY) #checklib.elf | ||
|
||
$(LIBRARY): $(OFILES) | ||
|
||
checklib.elf: $(OFILES) ../main.o | ||
|
||
../main.o: ../main.c | ||
|
||
-include $(DEPENDS) | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
#include "nds.h" | ||
#include "interfaces.h" | ||
|
||
/** reads the buttons & dpad state and make them available in one of the target gob variables | ||
*/ | ||
class DpadController : public iGobController { | ||
NOCOPY(DpadController); | ||
/** some keys are only mentioned "pressed" for a few frames after they are actually changed | ||
* from 'released' to 'pressed' state, to allow e.g. that your character doesn't keep | ||
* jumping. timeout indicates how many frames before the button is considered pressed | ||
* for too long. | ||
*/ | ||
static int timeout[32]; | ||
|
||
/** each state can define which buttons/direction must use timeout array */ | ||
unsigned timemask; | ||
static int delay; | ||
/** knowing which button/direction were pressed at the previous frame is critical to | ||
* know which be considered a 'new' keypress. | ||
* WARNING: this code assumes only one GameObject uses a DpadController | ||
*/ | ||
static int prevkeys; | ||
public: | ||
DpadController(const iControllerFactory *icf, unsigned m) : iGobController(icf), timemask(m) {} | ||
virtual ~DpadController() {} | ||
virtual iThought think(s16 gob[8], GameObject *g) { | ||
iThought me = NONE; | ||
int prevdirs = gob[GOB_DIRS]; | ||
int newkeys = 0; | ||
int kh = (keysHeld()|keysDown()) & ~(KEY_START|KEY_SELECT); | ||
|
||
for (unsigned i=0,j=1 ; i<31 ; i++, j=j<<1) { | ||
if ((kh&j)) { | ||
if (!(prevkeys & j)) timeout[i]=delay; | ||
else if ((timemask & j) && timeout[i]>0) timeout[i]--; | ||
} else timeout[i]=0; | ||
if (timeout[i]) newkeys|=j; | ||
} | ||
gob[GOB_DIRS]=newkeys; | ||
prevkeys=kh; | ||
return combine(me, gob, g); | ||
} | ||
}; | ||
|
||
int DpadController::delay=6; | ||
int DpadController::prevkeys=0; | ||
int DpadController::timeout[32]; | ||
|
||
class GobDpadFactory : public iControllerFactory { | ||
NOCOPY(GobDpadFactory); | ||
public: | ||
GobDpadFactory(const std::string str) { | ||
name=str; | ||
} | ||
virtual iGobController* create(char* args) { | ||
unsigned mask=KEY_DPAD|KEY_R; | ||
siscanf(args,"%x",&mask); | ||
return new DpadController(this, ~mask); | ||
} | ||
virtual ~GobDpadFactory() {} | ||
}; | ||
|
||
namespace { | ||
GobDpadFactory dpad("dpad"); | ||
}; | ||
|