diff options
author | Nicholas Tay <nick@windblume.net> | 2022-05-08 01:35:55 +1000 |
---|---|---|
committer | Nicholas Tay <nick@windblume.net> | 2022-05-08 01:35:55 +1000 |
commit | 5270088f730a7e30155a642dcd5c4e9a80055d7a (patch) | |
tree | 021a97b39cfe8cb68ae6a21c353a90cb731380eb | |
parent | 047544a5af9100ec269e9222213385bc7794f619 (diff) | |
download | clak-5270088f730a7e30155a642dcd5c4e9a80055d7a.tar.gz clak-5270088f730a7e30155a642dcd5c4e9a80055d7a.tar.bz2 clak-5270088f730a7e30155a642dcd5c4e9a80055d7a.zip |
More messing around with plugin system
Just more attempts, but I think I'm gonna switch over to dynamic
.so/.dll loading. That would be pretty fun to check out.
-rw-r--r-- | .gitignore | 2 | ||||
-rw-r--r-- | Makefile | 20 | ||||
-rw-r--r-- | board/generate.sh | 8 | ||||
-rw-r--r-- | board/mxblue/board.h | 3 | ||||
-rw-r--r-- | board/quack/board.h | 3 | ||||
-rw-r--r-- | board/simple.h | 9 | ||||
-rw-r--r-- | boards.h | 6 | ||||
-rw-r--r-- | clak.c | 14 |
8 files changed, 40 insertions, 25 deletions
@@ -1,4 +1,4 @@ clak clak.exe board/boards.h -board/*/board.h
\ No newline at end of file +board/*/sound.h
\ No newline at end of file @@ -1,13 +1,9 @@ NAME = clak PREFIX = $(HOME)/.local -BOARDS = mxblue quack - CC = gcc CFLAGS += -std=c99 -Wall -Wextra -Wshadow -Werror -pedantic -BOARD_FILES = $(addsuffix /board.h,$(addprefix board/,$(BOARDS))) - ifeq ($(OS),Windows_NT) LDLIBS = -lWinmm PLATFORM = win32 @@ -20,21 +16,9 @@ endif default: $(NAME) -$(NAME): $(NAME).c platform/$(PLATFORM).c $(BOARD_FILES) board/boards.h +$(NAME): $(NAME).c platform/$(PLATFORM).c boards.h $(CC) $(CFLAGS) $(NAME).c platform/$(PLATFORM).c $(LDLIBS) -o $(NAME) -board/boards.h: - printf "#ifndef BOARD_DEFAULTS_H\n#define BOARD_DEFAULTS_H\n\n" > board/boards.h - for board in $(BOARDS); do echo "#include \"$$board/board.h\"" >> board/boards.h; done - printf "\n#define BOARDS " >> board/boards.h - for board in $(BOARDS); do printf "BOARD(\"$$board\", board_$${board}_board_down_wav) " >> board/boards.h; done - printf "\n\n#endif /* BOARD_DEFAULTS_H */" >> board/boards.h - -$(BOARD_FILES): %.h: %_down.wav - xxd -i "$<" "$@" - clean: rm -f *.o - rm -f $(NAME) - rm -f board/boards.h - rm -f $(BOARD_FILES)
\ No newline at end of file + rm -f $(NAME)
\ No newline at end of file diff --git a/board/generate.sh b/board/generate.sh new file mode 100644 index 0000000..6d8d593 --- /dev/null +++ b/board/generate.sh @@ -0,0 +1,8 @@ +#!/bin/sh + +BOARDS='mxblue quack' + +cd "$(dirname "$0")" +for board in $BOARDS; do + xxd -i $board/board_down.wav $board/sound.h +done
\ No newline at end of file diff --git a/board/mxblue/board.h b/board/mxblue/board.h new file mode 100644 index 0000000..7d17f3f --- /dev/null +++ b/board/mxblue/board.h @@ -0,0 +1,3 @@ +#include "./sound.h" +#include "../simple.h" +SIMPLE_BOARD(mxblue)
\ No newline at end of file diff --git a/board/quack/board.h b/board/quack/board.h new file mode 100644 index 0000000..64ba4cb --- /dev/null +++ b/board/quack/board.h @@ -0,0 +1,3 @@ +#include "./sound.h" +#include "../simple.h" +SIMPLE_BOARD(quack)
\ No newline at end of file diff --git a/board/simple.h b/board/simple.h new file mode 100644 index 0000000..c2b211b --- /dev/null +++ b/board/simple.h @@ -0,0 +1,9 @@ +#ifndef CLAK_SIMPLE_H_ +#define CLAK_SIMPLE_H_ + +extern void sound_play(unsigned char *buffer); +#define SIMPLE_BOARD(name) \ + void name ## _on_down(void) { sound_play( name ## _board_down_wav ); } \ + void name ## _on_up(void) { sound_play( name ## _board_down_wav ); } + +#endif /* CLAK_SIMPLE_H_ */
\ No newline at end of file diff --git a/boards.h b/boards.h new file mode 100644 index 0000000..9090570 --- /dev/null +++ b/boards.h @@ -0,0 +1,6 @@ +#include "board/mxblue/board.h" +#include "board/quack/board.h" + +#define BOARDS \ + BOARD(mxblue) \ + BOARD(quack) @@ -6,14 +6,15 @@ #define VOLUME 0.15 -#include "board/boards.h" -#define BOARD(str, buf) { .name = str, .wav = buf }, +#define BOARD(x) { .name = #x, .on_down = x ## _on_down, .on_up = x ## _on_up }, +#include "boards.h" #include "platform/platform.h" typedef struct { char *name; - unsigned char* wav; + void (*on_down)(void); + void (*on_up)(void); } Board; Board boards[] = { @@ -44,13 +45,14 @@ void keyboard_on_down(void) { if (board == NULL) return; - sound_play(board->wav); + board->on_down(); } void keyboard_on_up(void) { - // if (board == NULL) - // return; + if (board == NULL) + return; + board->on_up(); } int main(int argc, char **argv) |