Add compatibility for macOS and *NIX files TODO: inspect building of dependenciesmaster
@@ -62,3 +62,4 @@ cmake-build-debug/ | |||||
dependencies/ | dependencies/ | ||||
assets_wip/ | assets_wip/ | ||||
Backup_*.cdr | Backup_*.cdr | ||||
.DS_Store |
@@ -27,6 +27,7 @@ endif() | |||||
include_directories( | include_directories( | ||||
"${PROJECT_SOURCE_DIR}/dependencies/SDL2/include" | "${PROJECT_SOURCE_DIR}/dependencies/SDL2/include" | ||||
"${PROJECT_SOURCE_DIR}/dependencies/SDL2_image" | |||||
"${PROJECT_SOURCE_DIR}/dependencies/SDL2_image/include" | "${PROJECT_SOURCE_DIR}/dependencies/SDL2_image/include" | ||||
"${PROJECT_SOURCE_DIR}/dependencies/SDL2_ttf/include" | "${PROJECT_SOURCE_DIR}/dependencies/SDL2_ttf/include" | ||||
"${PROJECT_SOURCE_DIR}/dependencies/minIni/dev" | "${PROJECT_SOURCE_DIR}/dependencies/minIni/dev" | ||||
@@ -1,20 +1,27 @@ | |||||
# sdl2-hello-world | |||||
# izanagi | |||||
A beginner template for SDL2 powered by CMake. | |||||
A run-and-gun shooter inspired by Metal Slug. | |||||
## Setup | ## Setup | ||||
> **Note:** CMake and OpenSSL are required. | |||||
### Windows | |||||
1. Clone this repo. | 1. Clone this repo. | ||||
2. Download the **SDL2 Development Libraries** from the [official download page](https://www.libsdl.org/download-2.0.php). | |||||
- For Windows | |||||
1. Unpack the **MSVC** archive under `dependencies` folder in this project's root. | |||||
2. Rename the directory as `SDL2`. | |||||
- For macOS | |||||
`TODO` | |||||
_Alternatively, on Windows, you can link the external libraries via symlink._ | |||||
3. Build the following dependencies first: | |||||
2. Clone the repositories under `dependencies.txt` except for SDL2. | |||||
3. Unpack the **MSVC** archive under `dependencies` folder in this project's root. Rename the directory as `SDL2`. | |||||
4. Build the following dependencies first: | |||||
- `portmidi` | - `portmidi` | ||||
- `libwebsockets` (follow the [instructions on building LWS](https://libwebsockets.org/lws-api-doc-master/html/md_README_8build.html)) | - `libwebsockets` (follow the [instructions on building LWS](https://libwebsockets.org/lws-api-doc-master/html/md_README_8build.html)) | ||||
4. Build via CMake. | |||||
5. Build via CMake. | |||||
### macOS/*NIX | |||||
1. Clone this repo. | |||||
2. Clone the repositories under `dependencies.txt`, including SDL2. | |||||
3. Build the SDL2 dependency using the [build instructions for macOS](https://wiki.libsdl.org/SDL2/Installation#macos). | |||||
4. Build the following dependencies first: | |||||
- `portmidi` | |||||
- `libwebsockets` (follow the [instructions on building LWS](https://libwebsockets.org/lws-api-doc-master/html/md_README_8build.html)) | |||||
5. Build via CMake. |
@@ -1,7 +1,10 @@ | |||||
https://github.com/libsdl-org/SDL | |||||
https://github.com/libsdl-org/SDL_image | |||||
https://github.com/compuphase/minIni | https://github.com/compuphase/minIni | ||||
https://github.com/grassator/bdd-for-c | https://github.com/grassator/bdd-for-c | ||||
https://github.com/PortMidi/portmidi | https://github.com/PortMidi/portmidi | ||||
https://github.com/EsotericSoftware/spine-runtimes | https://github.com/EsotericSoftware/spine-runtimes | ||||
https://github.com/Chunde/getopt-for-windows | https://github.com/Chunde/getopt-for-windows | ||||
https://libwebsockets.org/repo/libwebsockets | https://libwebsockets.org/repo/libwebsockets | ||||
https://www.sqlite.org/download.html (use SQLite amalgamated source code) | |||||
https://github.com/openssl/openssl | |||||
https://www.sqlite.org/download.html (use SQLite amalgamated source code, unpack into `sqlite` directory) |
@@ -123,13 +123,13 @@ void IZ_ConfigEnsureValidString(IZ_ConfigItem* item, const char* buffer) { | |||||
if (item->validator) { | if (item->validator) { | ||||
IZ_ConfigLoadParamsStringValidator* validator = item->validator; | IZ_ConfigLoadParamsStringValidator* validator = item->validator; | ||||
if (validator(buffer)) { | if (validator(buffer)) { | ||||
memcpy_s(item->dest, item->dest_size, buffer, item->dest_size); | |||||
memcpy(item->dest, buffer, item->dest_size); | |||||
return; | return; | ||||
} | } | ||||
memcpy_s(item->dest, item->dest_size, item->default_value, item->dest_size); | |||||
memcpy(item->dest, item->default_value, item->dest_size); | |||||
return; | return; | ||||
} | } | ||||
memcpy_s(item->dest, item->dest_size, buffer, item->dest_size); | |||||
memcpy(item->dest, buffer, item->dest_size); | |||||
} | } | ||||
void IZ_ConfigLoadString(IZ_ConfigItem* item, const char* config_path) { | void IZ_ConfigLoadString(IZ_ConfigItem* item, const char* config_path) { | ||||
@@ -32,7 +32,7 @@ IZ_AppInitializeResult IZ_AppInitialize(struct IZ_App* app, u8 argc, const char* | |||||
char config_path[128]; | char config_path[128]; | ||||
// TODO abstract command line args parsing | // TODO abstract command line args parsing | ||||
if ((cmdline_buffer = IZ_ConfigGetCommandlineOption(argc, argv, "-c"))) { | if ((cmdline_buffer = IZ_ConfigGetCommandlineOption(argc, argv, "-c"))) { | ||||
memcpy_s(config_path, 128, cmdline_buffer, 128); | |||||
memcpy(config_path, cmdline_buffer, 128); | |||||
} else { | } else { | ||||
IZ_ConfigGetDefaultPath(config_path, 128); | IZ_ConfigGetDefaultPath(config_path, 128); | ||||
} | } | ||||
@@ -7,6 +7,6 @@ void IZ_ConfigGetDefaultPath(const char* config_path, size_t string_size) { | |||||
const char* config_path_dir = SDL_GetPrefPath("Modal Studios", IZ_APP_NAME); | const char* config_path_dir = SDL_GetPrefPath("Modal Studios", IZ_APP_NAME); | ||||
#endif | #endif | ||||
memcpy_s(config_path, string_size, config_path_dir, 128); | |||||
strcat_s(config_path, string_size, "config-game.ini"); | |||||
memcpy(config_path, config_path_dir, string_size); | |||||
strcat(config_path, "config-game.ini"); | |||||
} | } |
@@ -157,7 +157,7 @@ void IZ_JoystickInitializeConfigItems(IZ_ConfigItem config_items[]) { | |||||
char* control_mapping_section_name; | char* control_mapping_section_name; | ||||
for (player_index = 0; player_index < IZ_PLAYERS; player_index += 1) { | for (player_index = 0; player_index < IZ_PLAYERS; player_index += 1) { | ||||
main_section_name = SDL_malloc(sizeof(char) * 64); | main_section_name = SDL_malloc(sizeof(char) * 64); | ||||
sprintf_s(main_section_name, 64, "Joystick.%d", player_index); | |||||
sprintf(main_section_name, "Joystick.%d", player_index); | |||||
u8 base_index = (player_index * (IZ_CONTROLS - 4 + 2)); | u8 base_index = (player_index * (IZ_CONTROLS - 4 + 2)); | ||||
config_items[base_index] = (IZ_ConfigItem) { | config_items[base_index] = (IZ_ConfigItem) { | ||||
IZ_CONFIG_TYPE_I32, | IZ_CONFIG_TYPE_I32, | ||||
@@ -182,7 +182,7 @@ void IZ_JoystickInitializeConfigItems(IZ_ConfigItem config_items[]) { | |||||
}; | }; | ||||
control_mapping_section_name = SDL_malloc(sizeof(char) * 64); | control_mapping_section_name = SDL_malloc(sizeof(char) * 64); | ||||
sprintf_s(control_mapping_section_name, 64, "Joystick.%d.ControlMapping", player_index); | |||||
sprintf(control_mapping_section_name, "Joystick.%d.ControlMapping", player_index); | |||||
for (control_index = 4; control_index < IZ_CONTROLS; control_index += 1) { | for (control_index = 4; control_index < IZ_CONTROLS; control_index += 1) { | ||||
config_items[base_index + 2 + (control_index - 4)] = (IZ_ConfigItem) { | config_items[base_index + 2 + (control_index - 4)] = (IZ_ConfigItem) { | ||||
IZ_CONFIG_TYPE_U8, | IZ_CONFIG_TYPE_U8, | ||||
@@ -4,7 +4,7 @@ static IZ_ConfigItem keyboard_config_items[IZ_PLAYERS * IZ_CONTROLS + 1]; | |||||
void IZ_KeyboardSerializeControl(i32 value, char control[128]) { | void IZ_KeyboardSerializeControl(i32 value, char control[128]) { | ||||
const char* serialized = SDL_GetKeyName(value); | const char* serialized = SDL_GetKeyName(value); | ||||
memcpy_s(control, 128, serialized, 128); | |||||
memcpy(control, serialized, 128); | |||||
} | } | ||||
i32 IZ_KeyboardDeserializeControl(const char* control) { | i32 IZ_KeyboardDeserializeControl(const char* control) { | ||||
@@ -55,7 +55,7 @@ void IZ_KeyboardInitializeConfigItems(IZ_ConfigItem config_items[]) { | |||||
char* control_mapping_section_name; | char* control_mapping_section_name; | ||||
for (player_index = 0; player_index < IZ_PLAYERS; player_index += 1) { | for (player_index = 0; player_index < IZ_PLAYERS; player_index += 1) { | ||||
control_mapping_section_name = SDL_malloc(sizeof(char) * 64); | control_mapping_section_name = SDL_malloc(sizeof(char) * 64); | ||||
sprintf_s(control_mapping_section_name, 64, "Keyboard.%d.ControlMapping", player_index); | |||||
sprintf(control_mapping_section_name, "Keyboard.%d.ControlMapping", player_index); | |||||
for (control_index = 0; control_index < IZ_CONTROLS; control_index += 1) { | for (control_index = 0; control_index < IZ_CONTROLS; control_index += 1) { | ||||
config_items[player_index * IZ_CONTROLS + control_index] = (IZ_ConfigItem) { | config_items[player_index * IZ_CONTROLS + control_index] = (IZ_ConfigItem) { | ||||
IZ_CONFIG_TYPE_I32, | IZ_CONFIG_TYPE_I32, | ||||
@@ -8,7 +8,7 @@ bool IZ_MIDIInputIsValidChannel(u8 value) { | |||||
void IZ_MIDIInputSerializeControl(i32 value, char* control[128]) { | void IZ_MIDIInputSerializeControl(i32 value, char* control[128]) { | ||||
const char* serialized = IZ_MIDIGetNoteName(value); | const char* serialized = IZ_MIDIGetNoteName(value); | ||||
memcpy_s(control, 128, serialized, 128); | |||||
memcpy(control, serialized, 128); | |||||
} | } | ||||
i32 IZ_MIDIInputDeserializeControl(const char* control) { | i32 IZ_MIDIInputDeserializeControl(const char* control) { | ||||
@@ -77,7 +77,7 @@ void IZ_MIDIInputInitializeConfigItems(IZ_ConfigItem config_items[]) { | |||||
char* control_mapping_section_name; | char* control_mapping_section_name; | ||||
for (player_index = 0; player_index < IZ_PLAYERS; player_index += 1) { | for (player_index = 0; player_index < IZ_PLAYERS; player_index += 1) { | ||||
main_section_name = SDL_malloc(sizeof(char) * 64); | main_section_name = SDL_malloc(sizeof(char) * 64); | ||||
sprintf_s(main_section_name, 64, "MIDIInput.%d", player_index); | |||||
sprintf(main_section_name, "MIDIInput.%d", player_index); | |||||
u16 base_index = (player_index * (IZ_CONTROLS + 2)); | u16 base_index = (player_index * (IZ_CONTROLS + 2)); | ||||
config_items[base_index] = (IZ_ConfigItem) { | config_items[base_index] = (IZ_ConfigItem) { | ||||
@@ -111,7 +111,7 @@ void IZ_MIDIInputInitializeConfigItems(IZ_ConfigItem config_items[]) { | |||||
}; | }; | ||||
control_mapping_section_name = SDL_malloc(sizeof(char) * 64); | control_mapping_section_name = SDL_malloc(sizeof(char) * 64); | ||||
sprintf_s(control_mapping_section_name, 64, "MIDIInput.%d.ControlMapping", player_index); | |||||
sprintf(control_mapping_section_name, "MIDIInput.%d.ControlMapping", player_index); | |||||
for (control_index = 0; control_index < IZ_CONTROLS; control_index += 1) { | for (control_index = 0; control_index < IZ_CONTROLS; control_index += 1) { | ||||
config_items[base_index + 2 + control_index] = (IZ_ConfigItem) { | config_items[base_index + 2 + control_index] = (IZ_ConfigItem) { | ||||
IZ_CONFIG_TYPE_U8, | IZ_CONFIG_TYPE_U8, | ||||
@@ -19,14 +19,16 @@ char* IZ_MIDIGetNoteName(u8 midi_note) { | |||||
const u8 pitch_class = midi_note % 12; | const u8 pitch_class = midi_note % 12; | ||||
const u8 octave = midi_note / 12; | const u8 octave = midi_note / 12; | ||||
static char note_name[8]; | static char note_name[8]; | ||||
sprintf_s(note_name, 8, "%s%u", pitch_names[pitch_class], octave); | |||||
sprintf(note_name, "%s%u", pitch_names[pitch_class], octave); | |||||
return note_name; | return note_name; | ||||
} | } | ||||
u8 IZ_MIDIGetNoteFromName(const char* name) { | u8 IZ_MIDIGetNoteFromName(const char* name) { | ||||
char name_copy[8]; | char name_copy[8]; | ||||
memcpy_s(name_copy, 8, name, 8); | |||||
memcpy(name_copy, name, 8); | |||||
#ifdef WIN32 | |||||
_strlwr_s(name_copy, 8); | _strlwr_s(name_copy, 8); | ||||
#endif | |||||
u8 octave; | u8 octave; | ||||
const char base_pitch_name[] = "c d ef g a b"; | const char base_pitch_name[] = "c d ef g a b"; | ||||
@@ -50,7 +50,7 @@ void IZ_NetClientInitializeConfigItems(IZ_ConfigItem config_items[]) { | |||||
char* main_section_name; | char* main_section_name; | ||||
for (player_index = 0; player_index < IZ_PLAYERS; player_index += 1) { | for (player_index = 0; player_index < IZ_PLAYERS; player_index += 1) { | ||||
main_section_name = malloc(sizeof(char) * 64); | main_section_name = malloc(sizeof(char) * 64); | ||||
sprintf_s(main_section_name, 64, "Network.%d", player_index); | |||||
sprintf(main_section_name, "Network.%d", player_index); | |||||
config_items[3 + player_index] = (IZ_ConfigItem) { | config_items[3 + player_index] = (IZ_ConfigItem) { | ||||
IZ_CONFIG_TYPE_STRING, | IZ_CONFIG_TYPE_STRING, | ||||
32, | 32, | ||||
@@ -106,7 +106,7 @@ IZ_ProcedureResult IZ_NetClientInitialize( | |||||
if (!user_data) { | if (!user_data) { | ||||
return -1; | return -1; | ||||
} | } | ||||
memcpy_s(state, sizeof(IZ_NetClientState), &IZ_NET_CLIENT_DEFAULT_STATE, sizeof(IZ_NetClientState)); | |||||
memcpy(state, &IZ_NET_CLIENT_DEFAULT_STATE, sizeof(IZ_NetClientState)); | |||||
if (IZ_NetClientInitializeConfig(state, config_path, argc, argv) < 0) { | if (IZ_NetClientInitializeConfig(state, config_path, argc, argv) < 0) { | ||||
return -2; | return -2; | ||||
} | } | ||||