4ed_generate_keycodes.cpp adds a comment at the top of the file it generate to specify which file generated it. Added proper indentation in the generated file. Note that this executable needs to be manually ran. The build system doesn't run it.

win32_keycode_init only initialize 30 KeyCode_Ex values (0 to 29) as the code generating the enum only generates that amount (explicitly loops from 0 to < 30).
This commit is contained in:
Simon Anciaux 2024-09-26 15:56:35 +02:00 committed by Peter Slattery
parent e4a4910e6b
commit c194053b83
3 changed files with 10 additions and 6 deletions

View File

@ -45,20 +45,20 @@ generate_codes(Arena *scratch, Event_Code_List *list, FILE *out){
for (Event_Code *code = list->first;
code != 0;
code = code->next){
fprintf(out, "%.*s_%.*s = %d,\n",
fprintf(out, " %.*s_%.*s = %d,\n",
string_expand(code_prefix), string_expand(code->name), counter);
counter += 1;
}
fprintf(out, "%.*s_COUNT = %d,\n", string_expand(code_prefix), counter);
fprintf(out, " %.*s_COUNT = %d,\n", string_expand(code_prefix), counter);
fprintf(out, "};\n");
fprintf(out, "global char* %.*s[%.*s_COUNT] = {\n",
string_expand(name_table), string_expand(code_prefix));
fprintf(out, "\"None\",\n");
fprintf(out, " \"None\",\n");
for (Event_Code *code = list->first;
code != 0;
code = code->next){
fprintf(out, "\"%.*s\",\n", string_expand(code->name));
fprintf(out, " \"%.*s\",\n", string_expand(code->name));
counter += 1;
}
fprintf(out, "};\n");
@ -188,6 +188,9 @@ main(void){
exit(1);
}
fprintf(out, "/* Generated by: " __FILE__ );
fprintf(out, " */\n" );
generate_codes(&arena, &key_list, out);
generate_codes(&arena, &mouse_list, out);
generate_codes(&arena, &core_list, out);

View File

@ -1,3 +1,4 @@
/* Generated by: 4ed_generate_keycodes.cpp */
enum{
KeyCode_A = 1,
KeyCode_B = 2,

View File

@ -777,8 +777,8 @@ win32_keycode_init(void){
keycode_lookup_table[VK_NUMPAD8] = KeyCode_NumPad8;
keycode_lookup_table[VK_NUMPAD9] = KeyCode_NumPad9;
for (i32 i = 0xDF; i < 0xFF; i += 1){
keycode_lookup_table[i] = KeyCode_Ex0 + i - 0xDF;
for (i32 i = 0; i < 30; i += 1){
keycode_lookup_table[0xDF + i] = KeyCode_Ex0 + i;
}
}