Skip to content

Commit 02c6403

Browse files
authored
Merge pull request #287 from fmatthew5876/constant
Add support for generated constants in RPG:: classes
2 parents 5b01c50 + 6cd8e2d commit 02c6403

12 files changed

+79
-11
lines changed

CMakeLists.txt

+2
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,8 @@ add_library(lcf
111111
src/generated/lsd_savevehiclelocation.cpp
112112
src/generated/rpg_chipset.cpp
113113
src/generated/rpg_enums.cpp
114+
src/generated/rpg_savepartylocation.cpp
115+
src/generated/rpg_state.cpp
114116
src/generated/rpg_system.cpp
115117
)
116118

Makefile.am

+2
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,8 @@ liblcf_la_SOURCES = \
110110
src/generated/lsd_savevehiclelocation.cpp \
111111
src/generated/rpg_chipset.cpp \
112112
src/generated/rpg_enums.cpp \
113+
src/generated/rpg_savepartylocation.cpp \
114+
src/generated/rpg_state.cpp \
113115
src/generated/rpg_system.cpp
114116
pkginclude_HEADERS = \
115117
src/command_codes.h \

builds/vs2015/liblcf.vcxproj

+2
Original file line numberDiff line numberDiff line change
@@ -263,6 +263,8 @@
263263
<ClCompile Include="..\..\src\generated\lsd_savetitle.cpp" />
264264
<ClCompile Include="..\..\src\generated\lsd_savevehiclelocation.cpp" />
265265
<ClCompile Include="..\..\src\generated\rpg_chipset.cpp" />
266+
<ClCompile Include="..\..\src\generated\rpg_savepartylocation.cpp" />
267+
<ClCompile Include="..\..\src\generated\rpg_state.cpp" />
266268
<ClCompile Include="..\..\src\generated\rpg_system.cpp" />
267269
</ItemGroup>
268270
<ItemGroup>

generator/csv/constants.csv

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
#Structure,name,type,value,comment
2+
State,kDeathID,int,1,The ID of the special death state
3+
SavePartyLocation,kPanXDefault,int,9 * 256,Equal to 9 tiles in 1/16th pixels
4+
SavePartyLocation,kPanYDefault,int,7 * 256,Equal to 7 tiles in 1/16th pixels

generator/csv/fields.csv

+4-4
Original file line numberDiff line numberDiff line change
@@ -837,10 +837,10 @@ SavePartyLocation,unboarding,f,Boolean,0x68,False,0,0,
837837
SavePartyLocation,preboard_move_speed,f,Int32,0x69,4,0,0,Move speed before the party boarded the vehicle
838838
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.
839839
SavePartyLocation,pan_state,f,Enum<SavePartyLoction_PanState>,0x6f,1,0,0,0: screen is fixed; 1: screen moves with player.
840-
SavePartyLocation,pan_current_x,f,Int32,0x70,2304,0,0,Number of 1/16 pixels to the left of player
841-
SavePartyLocation,pan_current_y,f,Int32,0x71,1792,0,0,Number of 1/16 pixels above the player
842-
SavePartyLocation,pan_finish_x,f,Int32,0x72,2304,0,0,Number of 1/16 pixels to the left of player when current scroll finishes
843-
SavePartyLocation,pan_finish_y,f,Int32,0x73,1792,0,0,Number of 1/16 pixels above the player when current scroll finishes.
840+
SavePartyLocation,pan_current_x,f,Int32,0x70,kPanXDefault,0,0,Number of 1/16 pixels to the left of player
841+
SavePartyLocation,pan_current_y,f,Int32,0x71,kPanYDefault,0,0,Number of 1/16 pixels above the player
842+
SavePartyLocation,pan_finish_x,f,Int32,0x72,kPanXDefault,0,0,Number of 1/16 pixels to the left of player when current scroll finishes
843+
SavePartyLocation,pan_finish_y,f,Int32,0x73,kPanYDefault,0,0,Number of 1/16 pixels above the player when current scroll finishes.
844844
SavePartyLocation,pan_speed,f,Int32,0x79,16,0,0,speed in the scrolls of the screen - shown in sixteenth pixels.
845845
SavePartyLocation,encounter_steps,f,Int32,0x7C,0,0,0,int: sum of terrain.encounter_rate for each step
846846
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.

generator/generate.py

+7-2
Original file line numberDiff line numberDiff line change
@@ -273,6 +273,9 @@ def get_flags(filename='flags.csv'):
273273
def get_setup(filename='setup.csv'):
274274
return process_file(filename, namedtuple("Setup", "method headers"))
275275

276+
def get_constants(filename='constants.csv'):
277+
return process_file(filename, namedtuple("Constant", "name type value comment"))
278+
276279
def get_headers():
277280
header_map = dict()
278281

@@ -344,7 +347,7 @@ def generate():
344347
type=filetype
345348
))
346349

347-
if needs_ctor(struct.name):
350+
if needs_ctor(struct.name) or struct.name in constants:
348351
filepath = os.path.join(tmp_dir, 'rpg_%s.cpp' % filename)
349352
with open(filepath, 'w') as f:
350353
f.write(rpg_source_tmpl.render(
@@ -387,14 +390,15 @@ def main(argv):
387390
if not os.path.exists(dest_dir):
388391
os.mkdir(dest_dir)
389392

390-
global structs, sfields, enums, flags, setup, headers
393+
global structs, sfields, enums, flags, setup, constants, headers
391394
global chunk_tmpl, lcf_struct_tmpl, rpg_header_tmpl, rpg_source_tmpl, flags_tmpl, enums_tmpl
392395

393396
structs = get_structs()
394397
sfields = get_fields()
395398
enums = get_enums()
396399
flags = get_flags()
397400
setup = get_setup()
401+
constants = get_constants()
398402
headers = get_headers()
399403

400404
# Setup Jinja
@@ -416,6 +420,7 @@ def main(argv):
416420
flags=flags,
417421
enums=enums,
418422
setup=setup,
423+
constants=constants,
419424
headers=headers
420425
)
421426

generator/templates/rpg_header.tmpl

+6
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,12 @@ namespace RPG {
2525
{%- if struct_name == "Map" %}
2626
std::string lmu_header;
2727
{%- endif %}
28+
{%- if struct_name in constants %}
29+
{%- for name, type, value, comment in constants[struct_name] %}
30+
// {{ comment }}
31+
static constexpr {{ type }} {{ name }} = {{ value }};
32+
{%- endfor %}
33+
{% endif %}
2834
{%- if struct_name in enums %}
2935
{%- for name, enum in enums[struct_name].items() %}
3036
{%- if name == "Code" %}

generator/templates/rpg_source.tmpl

+7-1
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,16 @@
11
{% include "copyright.tmpl" %}
22
// Headers
33
#include "rpg_{{ filename }}.h"
4-
4+
{% if struct_name in constants -%}
5+
{%- for name, type, value, comment in constants[struct_name] %}
6+
constexpr {{ type }} RPG::{{ struct_name }}::{{ name }};
7+
{%- endfor %}
8+
{%- endif %}
9+
{% if struct_name is needs_ctor -%}
510
/**
611
* Constructor.
712
*/
813
RPG::{{ struct_name }}::{{ struct_name }}() {
914
Init();
1015
}
16+
{%- endif %}
+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
/* !!!! GENERATED FILE - DO NOT EDIT !!!!
2+
* --------------------------------------
3+
*
4+
* This file is part of liblcf. Copyright (c) 2018 liblcf authors.
5+
* https://github.com/EasyRPG/liblcf - https://easyrpg.org
6+
*
7+
* liblcf is Free/Libre Open Source Software, released under the MIT License.
8+
* For the full copyright and license information, please view the COPYING
9+
* file that was distributed with this source code.
10+
*/
11+
12+
// Headers
13+
#include "rpg_savepartylocation.h"
14+
15+
constexpr int RPG::SavePartyLocation::kPanXDefault;
16+
constexpr int RPG::SavePartyLocation::kPanYDefault;
17+

src/generated/rpg_savepartylocation.h

+9-4
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,11 @@
2323
namespace RPG {
2424
class SavePartyLocation : public SaveMapEventBase {
2525
public:
26+
// Equal to 9 tiles in 1/16th pixels
27+
static constexpr int kPanXDefault = 9 * 256;
28+
// Equal to 7 tiles in 1/16th pixels
29+
static constexpr int kPanYDefault = 7 * 256;
30+
2631
enum VehicleType {
2732
VehicleType_none = 0,
2833
VehicleType_skiff = 1,
@@ -51,10 +56,10 @@ namespace RPG {
5156
int32_t preboard_move_speed = 4;
5257
bool menu_calling = false;
5358
int32_t pan_state = 1;
54-
int32_t pan_current_x = 2304;
55-
int32_t pan_current_y = 1792;
56-
int32_t pan_finish_x = 2304;
57-
int32_t pan_finish_y = 1792;
59+
int32_t pan_current_x = kPanXDefault;
60+
int32_t pan_current_y = kPanYDefault;
61+
int32_t pan_finish_x = kPanXDefault;
62+
int32_t pan_finish_y = kPanYDefault;
5863
int32_t pan_speed = 16;
5964
int32_t encounter_steps = 0;
6065
bool encounter_calling = false;

src/generated/rpg_state.cpp

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
/* !!!! GENERATED FILE - DO NOT EDIT !!!!
2+
* --------------------------------------
3+
*
4+
* This file is part of liblcf. Copyright (c) 2018 liblcf authors.
5+
* https://github.com/EasyRPG/liblcf - https://easyrpg.org
6+
*
7+
* liblcf is Free/Libre Open Source Software, released under the MIT License.
8+
* For the full copyright and license information, please view the COPYING
9+
* file that was distributed with this source code.
10+
*/
11+
12+
// Headers
13+
#include "rpg_state.h"
14+
15+
constexpr int RPG::State::kDeathID;
16+

src/generated/rpg_state.h

+3
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,9 @@
2323
namespace RPG {
2424
class State {
2525
public:
26+
// The ID of the special death state
27+
static constexpr int kDeathID = 1;
28+
2629
enum Persistence {
2730
Persistence_ends = 0,
2831
Persistence_persists = 1

0 commit comments

Comments
 (0)