From bbde6be3f547e713bad4f8ee361b461576b2f745 Mon Sep 17 00:00:00 2001 From: Matthew Fioravante Date: Sat, 1 Dec 2018 22:59:47 -0500 Subject: [PATCH 1/2] Add support for constants in rpg_ headers * Adds State::kDeath * Adds pan constants so that they don't need to be duplicated in Player --- generator/csv/constants.csv | 4 ++++ generator/csv/fields.csv | 8 ++++---- generator/generate.py | 7 ++++++- generator/templates/rpg_header.tmpl | 6 ++++++ src/generated/rpg_savepartylocation.h | 13 +++++++++---- src/generated/rpg_state.h | 3 +++ 6 files changed, 32 insertions(+), 9 deletions(-) create mode 100644 generator/csv/constants.csv diff --git a/generator/csv/constants.csv b/generator/csv/constants.csv new file mode 100644 index 000000000..edd89a175 --- /dev/null +++ b/generator/csv/constants.csv @@ -0,0 +1,4 @@ +#Structure,name,type,value,comment +State,kDeathID,int,1,The ID of the special death state +SavePartyLocation,kPanXDefault,int,9 * 256,Equal to 9 tiles in 1/16th pixels +SavePartyLocation,kPanYDefault,int,7 * 256,Equal to 7 tiles in 1/16th pixels diff --git a/generator/csv/fields.csv b/generator/csv/fields.csv index 7f89be61e..7d040bd0d 100644 --- a/generator/csv/fields.csv +++ b/generator/csv/fields.csv @@ -837,10 +837,10 @@ SavePartyLocation,unboarding,f,Boolean,0x68,False,0,0, SavePartyLocation,preboard_move_speed,f,Int32,0x69,4,0,0,Move speed before the party boarded the vehicle SavePartyLocation,menu_calling,f,Boolean,0x6C,False,0,0,Flag which briefly is true if the player presses ESC. At the right place in handling each frame's activities for the player; the code checks whether this flag is set and calls the menu; however there are several conditions which would cancel this flag and instead process another higher-priority action; such as when an encounter takes place during the same frame. SavePartyLocation,pan_state,f,Enum,0x6f,1,0,0,0: screen is fixed; 1: screen moves with player. -SavePartyLocation,pan_current_x,f,Int32,0x70,2304,0,0,Number of 1/16 pixels to the left of player -SavePartyLocation,pan_current_y,f,Int32,0x71,1792,0,0,Number of 1/16 pixels above the player -SavePartyLocation,pan_finish_x,f,Int32,0x72,2304,0,0,Number of 1/16 pixels to the left of player when current scroll finishes -SavePartyLocation,pan_finish_y,f,Int32,0x73,1792,0,0,Number of 1/16 pixels above the player when current scroll finishes. +SavePartyLocation,pan_current_x,f,Int32,0x70,kPanXDefault,0,0,Number of 1/16 pixels to the left of player +SavePartyLocation,pan_current_y,f,Int32,0x71,kPanYDefault,0,0,Number of 1/16 pixels above the player +SavePartyLocation,pan_finish_x,f,Int32,0x72,kPanXDefault,0,0,Number of 1/16 pixels to the left of player when current scroll finishes +SavePartyLocation,pan_finish_y,f,Int32,0x73,kPanYDefault,0,0,Number of 1/16 pixels above the player when current scroll finishes. SavePartyLocation,pan_speed,f,Int32,0x79,16,0,0,speed in the scrolls of the screen - shown in sixteenth pixels. SavePartyLocation,encounter_steps,f,Int32,0x7C,0,0,0,int: sum of terrain.encounter_rate for each step SavePartyLocation,encounter_calling,f,Boolean,0x7D,False,0,0,Similar to 0x6C - is used to signal a different piece of code that an encounter is to be triggered; which may be cancelled by other conditions such as the player starting to interact with an event during the same frame. diff --git a/generator/generate.py b/generator/generate.py index 5924313fb..c86976d25 100755 --- a/generator/generate.py +++ b/generator/generate.py @@ -273,6 +273,9 @@ def get_flags(filename='flags.csv'): def get_setup(filename='setup.csv'): return process_file(filename, namedtuple("Setup", "method headers")) +def get_constants(filename='constants.csv'): + return process_file(filename, namedtuple("Constant", "name type value comment")) + def get_headers(): header_map = dict() @@ -379,7 +382,7 @@ def main(argv): if not os.path.exists(dest_dir): os.mkdir(dest_dir) - global structs, sfields, enums, flags, setup, headers + global structs, sfields, enums, flags, setup, constants, headers global chunk_tmpl, lcf_struct_tmpl, rpg_header_tmpl, rpg_source_tmpl, flags_tmpl, enums_tmpl structs = get_structs() @@ -387,6 +390,7 @@ def main(argv): enums = get_enums() flags = get_flags() setup = get_setup() + constants = get_constants() headers = get_headers() # Setup Jinja @@ -407,6 +411,7 @@ def main(argv): flags=flags, enums=enums, setup=setup, + constants=constants, headers=headers ) diff --git a/generator/templates/rpg_header.tmpl b/generator/templates/rpg_header.tmpl index debeb8d96..0850bcae1 100644 --- a/generator/templates/rpg_header.tmpl +++ b/generator/templates/rpg_header.tmpl @@ -25,6 +25,12 @@ namespace RPG { {%- if struct_name == "Map" %} std::string lmu_header; {%- endif %} + {%- if struct_name in constants %} + {%- for name, type, value, comment in constants[struct_name] %} + // {{ comment }} + static constexpr {{ type }} {{ name }} = {{ value }}; + {%- endfor %} + {% endif %} {%- if struct_name in enums %} {%- for name, enum in enums[struct_name].items() %} {%- if name == "Code" %} diff --git a/src/generated/rpg_savepartylocation.h b/src/generated/rpg_savepartylocation.h index 0cc79c307..961a2765a 100644 --- a/src/generated/rpg_savepartylocation.h +++ b/src/generated/rpg_savepartylocation.h @@ -23,6 +23,11 @@ namespace RPG { class SavePartyLocation : public SaveMapEventBase { public: + // Equal to 9 tiles in 1/16th pixels + static constexpr int kPanXDefault = 9 * 256; + // Equal to 7 tiles in 1/16th pixels + static constexpr int kPanYDefault = 7 * 256; + enum VehicleType { VehicleType_none = 0, VehicleType_skiff = 1, @@ -51,10 +56,10 @@ namespace RPG { int32_t preboard_move_speed = 4; bool menu_calling = false; int32_t pan_state = 1; - int32_t pan_current_x = 2304; - int32_t pan_current_y = 1792; - int32_t pan_finish_x = 2304; - int32_t pan_finish_y = 1792; + int32_t pan_current_x = kPanXDefault; + int32_t pan_current_y = kPanYDefault; + int32_t pan_finish_x = kPanXDefault; + int32_t pan_finish_y = kPanYDefault; int32_t pan_speed = 16; int32_t encounter_steps = 0; bool encounter_calling = false; diff --git a/src/generated/rpg_state.h b/src/generated/rpg_state.h index d7b52330e..a72ab00fe 100644 --- a/src/generated/rpg_state.h +++ b/src/generated/rpg_state.h @@ -23,6 +23,9 @@ namespace RPG { class State { public: + // The ID of the special death state + static constexpr int kDeathID = 1; + enum Persistence { Persistence_ends = 0, Persistence_persists = 1 From 6cd8e2d7737339a883e7f750d4f549aa4a96287b Mon Sep 17 00:00:00 2001 From: Matthew Fioravante Date: Sat, 1 Dec 2018 23:25:30 -0500 Subject: [PATCH 2/2] Add definitions of constants --- CMakeLists.txt | 2 ++ Makefile.am | 2 ++ builds/vs2015/liblcf.vcxproj | 2 ++ generator/generate.py | 2 +- generator/templates/rpg_source.tmpl | 8 +++++++- src/generated/rpg_savepartylocation.cpp | 17 +++++++++++++++++ src/generated/rpg_state.cpp | 16 ++++++++++++++++ 7 files changed, 47 insertions(+), 2 deletions(-) create mode 100644 src/generated/rpg_savepartylocation.cpp create mode 100644 src/generated/rpg_state.cpp diff --git a/CMakeLists.txt b/CMakeLists.txt index e66cb373e..00e880381 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -112,6 +112,8 @@ add_library(lcf src/generated/lsd_savevehiclelocation.cpp src/generated/rpg_chipset.cpp src/generated/rpg_enums.cpp + src/generated/rpg_savepartylocation.cpp + src/generated/rpg_state.cpp src/generated/rpg_system.cpp ) diff --git a/Makefile.am b/Makefile.am index b3f170ee8..fee13ba16 100644 --- a/Makefile.am +++ b/Makefile.am @@ -111,6 +111,8 @@ liblcf_la_SOURCES = \ src/generated/lsd_savevehiclelocation.cpp \ src/generated/rpg_chipset.cpp \ src/generated/rpg_enums.cpp \ + src/generated/rpg_savepartylocation.cpp \ + src/generated/rpg_state.cpp \ src/generated/rpg_system.cpp pkginclude_HEADERS = \ src/command_codes.h \ diff --git a/builds/vs2015/liblcf.vcxproj b/builds/vs2015/liblcf.vcxproj index 2c4437d52..f1459f3b6 100644 --- a/builds/vs2015/liblcf.vcxproj +++ b/builds/vs2015/liblcf.vcxproj @@ -264,6 +264,8 @@ + + diff --git a/generator/generate.py b/generator/generate.py index c86976d25..076b3f1f1 100755 --- a/generator/generate.py +++ b/generator/generate.py @@ -339,7 +339,7 @@ def generate(): type=filetype )) - if needs_ctor(struct.name): + if needs_ctor(struct.name) or struct.name in constants: filepath = os.path.join(tmp_dir, 'rpg_%s.cpp' % filename) with open(filepath, 'w') as f: f.write(rpg_source_tmpl.render( diff --git a/generator/templates/rpg_source.tmpl b/generator/templates/rpg_source.tmpl index e6299ec39..4d9e6b269 100644 --- a/generator/templates/rpg_source.tmpl +++ b/generator/templates/rpg_source.tmpl @@ -1,10 +1,16 @@ {% include "copyright.tmpl" %} // Headers #include "rpg_{{ filename }}.h" - +{% if struct_name in constants -%} +{%- for name, type, value, comment in constants[struct_name] %} +constexpr {{ type }} RPG::{{ struct_name }}::{{ name }}; +{%- endfor %} +{%- endif %} +{% if struct_name is needs_ctor -%} /** * Constructor. */ RPG::{{ struct_name }}::{{ struct_name }}() { Init(); } +{%- endif %} diff --git a/src/generated/rpg_savepartylocation.cpp b/src/generated/rpg_savepartylocation.cpp new file mode 100644 index 000000000..4455e329e --- /dev/null +++ b/src/generated/rpg_savepartylocation.cpp @@ -0,0 +1,17 @@ +/* !!!! GENERATED FILE - DO NOT EDIT !!!! + * -------------------------------------- + * + * This file is part of liblcf. Copyright (c) 2018 liblcf authors. + * https://github.com/EasyRPG/liblcf - https://easyrpg.org + * + * liblcf is Free/Libre Open Source Software, released under the MIT License. + * For the full copyright and license information, please view the COPYING + * file that was distributed with this source code. + */ + +// Headers +#include "rpg_savepartylocation.h" + +constexpr int RPG::SavePartyLocation::kPanXDefault; +constexpr int RPG::SavePartyLocation::kPanYDefault; + diff --git a/src/generated/rpg_state.cpp b/src/generated/rpg_state.cpp new file mode 100644 index 000000000..c3d53a807 --- /dev/null +++ b/src/generated/rpg_state.cpp @@ -0,0 +1,16 @@ +/* !!!! GENERATED FILE - DO NOT EDIT !!!! + * -------------------------------------- + * + * This file is part of liblcf. Copyright (c) 2018 liblcf authors. + * https://github.com/EasyRPG/liblcf - https://easyrpg.org + * + * liblcf is Free/Libre Open Source Software, released under the MIT License. + * For the full copyright and license information, please view the COPYING + * file that was distributed with this source code. + */ + +// Headers +#include "rpg_state.h" + +constexpr int RPG::State::kDeathID; +