diff options
| author | Nicholas Tay <nick@windblume.net> | 2022-05-11 19:22:08 +1000 | 
|---|---|---|
| committer | Nicholas Tay <nick@windblume.net> | 2022-05-11 19:22:08 +1000 | 
| commit | 2fee408d6fe0964e245dc0bae90027baa13b159a (patch) | |
| tree | 8ff7cd648f2e9331b6e86ac3dfeb7c4e07df8f99 /platform | |
| parent | 6a1e6a7d6b6a3d987f2fccb3c06f4f5da071f504 (diff) | |
| download | clak-2fee408d6fe0964e245dc0bae90027baa13b159a.tar.gz clak-2fee408d6fe0964e245dc0bae90027baa13b159a.tar.bz2 clak-2fee408d6fe0964e245dc0bae90027baa13b159a.zip | |
Improve plugin loading architecture
This should be better, maybe the variable names could be better though.
Init is more extensible, we take in a 'board_data' struct on the plugin
end that has everything it needs (mainly function pointers for now).
Then, a 'board' struct is given back to the main Clak runtime, with
everything it needs to know (again, mainly function pointers).
It is a bit weird that the board is not stored with Clak but as a
pointer to the dynamically loaded bit, but not sure.
Diffstat (limited to '')
| -rw-r--r-- | platform/platform.h | 5 | ||||
| -rw-r--r-- | platform/win32.c | 22 | 
2 files changed, 11 insertions, 16 deletions
| diff --git a/platform/platform.h b/platform/platform.h index fd9b9bb..a5e5db4 100644 --- a/platform/platform.h +++ b/platform/platform.h @@ -5,11 +5,14 @@  #include "../board/board.h" -bool load_board(char *board_name, fn_board_on_down *on_down, fn_board_on_down *on_up); +struct board *load_board(char *board_name); +  bool sound_init(float volume);  void sound_play(unsigned char *buffer); +  void keyboard_unhook(void);  bool keyboard_hook(void); +  void enter_idle(void);  #endif /* CLAK_PLATFORM_H_ */
\ No newline at end of file diff --git a/platform/win32.c b/platform/win32.c index cf22718..1dccc7b 100644 --- a/platform/win32.c +++ b/platform/win32.c @@ -82,7 +82,7 @@ void enter_idle(void)  	}  } -bool load_board(char *board_name, fn_board_on_down *on_down, fn_board_on_down *on_up) +struct board *load_board(char *board_name)  {  	char dll_name[100];  	int r = snprintf(dll_name, 100, "./board/%s.dll", board_name); @@ -96,23 +96,15 @@ bool load_board(char *board_name, fn_board_on_down *on_down, fn_board_on_down *o  		printf("ERROR: Could not load board module.\n");  		return false;  	} +	// HACK: Cast to void function ptr then cast back, otherwise types are incompatible to the compiler.  	fn_board_init board_init = (fn_board_init) (void (*)(void)) GetProcAddress(board_module, "board_init");  	if (board_init == NULL) { -		printf("ERROR: No board down function could be loaded.\n"); +		printf("ERROR: No board initialisation function could be loaded.\n");  		return false;  	} -	board_init(&sound_play); -	*on_down = (fn_board_on_down) GetProcAddress(board_module, "board_on_down"); -	if (on_down == NULL) { -		printf("ERROR: No board down function could be loaded.\n"); -		return false; -	} -	*on_up = (fn_board_on_up) GetProcAddress(board_module, "board_on_up"); -	if (on_up == NULL) { -		printf("ERROR: No board up function could be loaded.\n"); -		return false; -	} - -	return true; +	struct board_data data = { +		.sound_play = &sound_play +	}; +	return board_init(data);  }
\ No newline at end of file | 
