Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 23 additions & 8 deletions StructFields.pm
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,18 @@ sub get_container_item_type($;%) {
}
}

sub get_internal_item_type($;$;%) {
my ($tag, $type, %flags) = @_;
my @items = $tag->findnodes($type);
if (@items) {
return get_struct_field_type($items[0], -local => $in_struct_body, %container_flags, %flags);
} elsif ($flags{-void}) {
return $flags{-void};
} else {
die "Container without $type: $tag\n";
}
}

sub get_variant_item_type($;%) {
my ($tag, %flags) = @_;
my ($rawtype) = $tag->getAttribute('raw-type');
Expand Down Expand Up @@ -152,6 +164,11 @@ my %custom_container_handlers = (
header_ref("set");
return "std::set<$item >";
},
'stl-unordered-set' => sub {
my $item = get_container_item_type($_, -void => 'void*');
header_ref("unordered_set");
return "std::unordered_set<$item >";
},
'stl-bit-vector' => sub {
header_ref("vector");
return "std::vector<bool>";
Expand All @@ -163,18 +180,16 @@ my %custom_container_handlers = (
return "std::array<$item, $count>";
},
'stl-map' => sub {
# TODO: implement get_container_key_type?
my $key = 'void*';
my $item = get_container_item_type($_, -void => 'void*');
my $key = get_internal_item_type($_, "key-type", -void => 'void*');
my $value = get_internal_item_type($_, "value-type", -void => 'void*');
header_ref("map");
return "std::map<$key, $item>";
return "std::map<$key, $value>";
},
'stl-unordered-map' => sub {
# TODO: implement get_container_key_type?
my $key = 'void*';
my $item = get_container_item_type($_, -void => 'void*');
my $key = get_internal_item_type($_, "key-type", -void => 'void*');
my $value = get_internal_item_type($_, "value-type", -void => 'void*');
header_ref("unordered_map");
return "std::unordered_map<$key, $item>";
return "std::unordered_map<$key, $value>";
},
'stl-function' => sub {
my $item = get_container_item_type($_, -void => 'void');
Expand Down
2 changes: 2 additions & 0 deletions StructType.pm
Original file line number Diff line number Diff line change
Expand Up @@ -316,7 +316,9 @@ sub render_struct_type {
emit 'friend struct ' . fully_qualified_name($types{$backref}, $backref) . ';';
}
}

} $tag, "$typename$ispec", -export => 1;

}

1;
7 changes: 5 additions & 2 deletions codegen.pl
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,17 @@ BEGIN
my $parser = XML::LibXML->new();
my $xslt = XML::LibXSLT->new();
my @transforms =
map { $xslt->parse_stylesheet_file("$script_root/$_"); }
map { [ $_, $xslt->parse_stylesheet_file("$script_root/$_") ]; }
('lower-1.xslt', 'lower-2.xslt');
my @documents;

for my $fn (sort { $a cmp $b } bsd_glob "$input_dir/df.*.xml") {
local $filename = $fn;
my $doc = $parser->parse_file($filename);
$doc = $_->transform($doc) for @transforms;
for my $t (@transforms) {
# print "Applying transform ", $t->[0], " to $filename\n";
$doc = $t->[1]->transform($doc);
}

push @documents, $doc;
add_type_to_hash $_ foreach $doc->findnodes('/ld:data-definition/ld:global-type');
Expand Down
12 changes: 8 additions & 4 deletions data-definition.xsd
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,7 @@
<xs:element name="stl-deque" type="StlDequeField" />
<xs:element name="stl-array" type="StlArrayField" />
<xs:element name="stl-set" type="StlSetField" />
<xs:element name="stl-unordered-set" type="StlSetField" />
<xs:element name="stl-map" type="StlMapField" />
<xs:element name="stl-unordered-map" type="StlMapField" />
<xs:element name="stl-fstream" type="OpaqueField" />
Expand Down Expand Up @@ -417,10 +418,13 @@
</xs:complexContent>
</xs:complexType>
<xs:complexType name="StlMapField">
<xs:complexContent>
<xs:extension base="ContainerFieldType">
</xs:extension>
</xs:complexContent>
<xs:sequence>
<xs:element name="key-type" minOccurs="1" maxOccurs="1" type="CompoundFieldType"/>
<xs:element name="value-type" minOccurs="1" maxOccurs="1" type="CompoundFieldType"/>
</xs:sequence>
<xs:attributeGroup ref="SharedAttributes" />
<xs:attribute name="name">
</xs:attribute>
</xs:complexType>
<xs:complexType name="StlOptionalField">
<xs:complexContent>
Expand Down
5 changes: 4 additions & 1 deletion df.creature.xml
Original file line number Diff line number Diff line change
Expand Up @@ -1528,7 +1528,10 @@

<stl-vector name='action_strings' pointer-type='stl-string' since='v0.40.01'/>

<stl-unordered-map name='hist_fig_to_creature_map' type-name='int32_t' comment='unordered_map&lt;int32_t,int32_t&gt;'/>
<stl-unordered-map name='hist_fig_to_creature_map'>
<key-type type-name='int32_t'/>
<value-type type-name='int32_t'/>
</stl-unordered-map>

<virtual-methods>
<vmethod name='getTile' ret-type='uint8_t'>
Expand Down
32 changes: 25 additions & 7 deletions df.d_interface.xml
Original file line number Diff line number Diff line change
Expand Up @@ -1975,7 +1975,7 @@
<enum-item name='OTHER'/>
</enum-type>

<struct-type type-name='labor_kitchen_interface_food_key'>
<struct-type type-name='labor_kitchen_interface_food_key' custom-methods='true'>
<enum name='type' type-name='item_type'/>
<int16_t name='subtype'/>
<int16_t name='mat'/>
Expand All @@ -1989,11 +1989,14 @@
</struct-type>

<struct-type type-name='labor_kitchen_interface_food_entry'>
<extra-include filename="custom/hash/labor_kitchen_interface_food_key.h"/>
<compound type-name='labor_kitchen_interface_food_key' name='first'/>
<compound type-name='labor_kitchen_interface_food_value' name='second'/>
</struct-type>

<struct-type type-name='labor_kitchen_interface_food_sort_entry' inherits-from='sort_entry'/>
<struct-type type-name='labor_kitchen_interface_food_sort_entry' inherits-from='sort_entry'>
<extra-include filename="custom/hash/labor_kitchen_interface_food_key.h"/>
</struct-type>

<enum-type type-name='labor_kitchen_interface_type_filter' base-type='int8_t'> bay12: labor_kitchen_interface_type_filter
<enum-item name='ALL' value='-1'/>
Expand All @@ -2005,9 +2008,15 @@

<class-type type-name='labor_kitchen_interfacest' inherits-from='widget_container'>
<enum type-name='kitchen_pref_category_type' name='current_category'/>
<stl-unordered-map type-name='labor_kitchen_interface_food_value' name='known' comment='std::unordered_map&lt;labor_kitchen_interface_food_key,labor_kitchen_interface_food_value&gt;'/>
<stl-unordered-map name='known'>
<key-type type-name='labor_kitchen_interface_food_key'/>
<value-type type-name='labor_kitchen_interface_food_value'/>
</stl-unordered-map>
<stl-vector type-name='labor_kitchen_interface_food_sort_entry' name='sorting_by'/>
<stl-unordered-map type-name='int8_t' name='ascending_sort' comment='std::unordered_map&lt;std::string,bool&gt;'/>
<stl-unordered-map name='ascending_sort'>
<key-type type-name='stl-string'/>
<value-type type-name='int8_t'/>
</stl-unordered-map>
<stl-vector name='filter_func'>
<stl-function comment='std::function&lt;bool(labor_kitchen_interface_food_entry)&gt;'/>
</stl-vector>
Expand Down Expand Up @@ -2370,9 +2379,18 @@
<stl-vector pointer-type='organization_entryst' name='organization_entry'/>
<stl-vector pointer-type='plot_entryst' name='plot_entry'/>

<stl-unordered-map type-name='int32_t' name='crimevals' comment='std::unordered_map&lt;unitst *,int32_t&gt;'/>
<stl-unordered-map type-name='justice_screen_interrogation_list_flag' name='crimeflag' comment='std::unordered_map&lt;unitst *,int32_t&gt;'/>
<stl-unordered-map type-name='int32_t' name='guardvals' comment='std::unordered_map&lt;unitst *,int32_t&gt;'/>
<stl-unordered-map name='crimevals'>
<key-type><pointer type-name='unit'/></key-type>
<value-type type-name='int32_t'/>
</stl-unordered-map>
<stl-unordered-map name='crimeflag'>
<key-type><pointer type-name='unit'/></key-type>
<value-type type-name='justice_screen_interrogation_list_flag'/>
</stl-unordered-map>
<stl-unordered-map name='guardvals'>
<key-type><pointer type-name='unit'/></key-type>
<value-type type-name='int32_t'/>
</stl-unordered-map>

<bool name='do_init'/>
</class-type>
Expand Down
39 changes: 33 additions & 6 deletions df.g_src.ViewBase.xml
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,10 @@
</class-type>

<class-type type-name='widget_container' original-name='widgets::container' inherits-from='widget'>
<stl-map name='children_by_name' comment='std::map&lt;std::string,std::shared_ptr&lt;widget&gt;&gt;'/>
<stl-map name='children_by_name'>
<key-type type-name='stl-string'/>
<value-type><stl-shared-ptr type-name='widget'/></value-type>
</stl-map>
<stl-vector name='children'>
<stl-shared-ptr type-name='widget'/>
</stl-vector>
Expand Down Expand Up @@ -185,7 +188,11 @@
<pointer type-name='widget' name='selected'/>
<int32_t name='selected_idx' init-value='0'/>
<compound type-name='widget_scroll_rows' name='rows'/>
<stl-map name='select_callback' comment='std::map&lt;size_t, std::function&lt;void(widget *)&gt;&gt;'/>
<stl-map name='select_callback'>
<key-type type-name='size_t'/>
<value-type><stl-function comment='arguments are widget *'/></value-type>
</stl-map>

</class-type>

<class-type type-name='widget_table' original-name='widgets::table' inherits-from='widget_container'>
Expand Down Expand Up @@ -248,15 +255,19 @@
<class-type type-name='widget_folder' original-name='widgets::folder' inherits-from='widget'>
<compound type-name='widget' name='open'/>
<bool name='last_visible'/>
<stl-unordered-map name='controlled_set' comment='std::unordered_set&lt;std::shared_ptr&lt;widget&gt;&gt;'/>
<stl-unordered-set name='controlled_set'>
<stl-shared-ptr type-name='widget'/>
</stl-unordered-set>
<bool name='controlled_visible'/>
<compound type-name='widget_text' name='label'/>
<stl-weak-ptr type-name='widget_container'/>
</class-type>

<struct-type type-name='filter_entry'>
<stl-shared-ptr type-name='widget_text' name='label'/>
<stl-unordered-map name='filtered_set' comment='std::unordered_set&lt;std::shared_ptr&lt;widget&gt;&gt;'/>
<stl-unordered-set name='filtered_set'>
<stl-shared-ptr type-name='widget'/>
</stl-unordered-set>
</struct-type>

<class-type type-name='widget_filter' original-name='widgets::filter' inherits-from='widget'>
Expand All @@ -279,11 +290,27 @@
</class-type>

<struct-type type-name='widget_menu' original-name='widgets::menu'>
<stl-map name='lines'/>
<stl-map name='lines'>
<key-type type-name='int32_t'/>
<value-type>
<compound>
<stl-string/>
<int8_t comment='placeholder type'/>
</compound>
</value-type>
</stl-map>
<int32_t name='selection'/>
<int32_t name='last_displayheight'/>
<bool name='bleached'/>
<stl-map name='colors'/>
<stl-map name='colors'>
<key-type type-name='int32_t'/>
<value-type>
<compound>
<int32_t/>
<int32_t/>
</compound>
</value-type>
</stl-map>
</struct-type>

<enum-type type-name='interface_breakdown_types'> bay12: InterfaceBreakdownTypes, no base type
Expand Down
2 changes: 1 addition & 1 deletion df.g_src.enabler.xml
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
<flag-bit name='convert'/>
</bitfield-type>

<struct-type type-name='texture_fullid'>
<struct-type type-name='texture_fullid' custom-methods='true'>
<int32_t name='texpos'/>
<s-float name='r'/>
<s-float name='g'/>
Expand Down
25 changes: 20 additions & 5 deletions df.g_src.music_and_sound_g.xml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,13 @@
-- Unused: Song
-- Unused: SoundType
-- Skipped: musicsound_info - platform-dependent implementation?
-- Unused: music_datast

<struct-type type-name='music_datast'>
<int32_t name='id'/>
<stl-string name='title'/>
<stl-string name='author'/>
</struct-type>

-- Unused: loading_music_filest

<struct-type type-name='musicsoundst'>
Expand Down Expand Up @@ -82,10 +88,19 @@
<int32_t name='next_song_id'/>
<int32_t name='next_sound_id'/>

<stl-unordered-map name='loaded_music' comment='unordered_map&lt;std::string, music_datast&gt;'/>
<stl-unordered-map name='music_by_id' comment='unordered_map&lt;int, music_datast&gt;'/>
<stl-unordered-map name='loaded_sounds' comment='unordered_map&lt;std::string, int&gt;'/>
<stl-vector name='loading_files' comment='std::ffuture&lt;loading_music_filest&gt;'/>
<stl-unordered-map name='loaded_music' comment='unordered_map&lt;std::string, music_datast&gt;'>
<key-type type-name='stl-string'/>
<value-type type-name='music_datast'/>
</stl-unordered-map>
<stl-unordered-map name='music_by_id'>
<key-type type-name='int32_t'/>
<value-type type-name='music_datast'/>
</stl-unordered-map>
<stl-unordered-map name='loaded_sounds'>
<key-type type-name='stl-string'/>
<value-type type-name='int32_t'/>
</stl-unordered-map>
<stl-vector name='loading_files' comment='std::future&lt;loading_music_filest&gt;'/>

<pointer name='internal' comment='musicsound_info'/>

Expand Down
7 changes: 6 additions & 1 deletion df.g_src.renderer_2d.xml
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
<data-definition>
<struct-type type-name='tile_cachest'>
<stl-unordered-map name='tile_cache' comment='unordered_map&lt;texture_fullid, SDL_Texture*\&gt;'/>
<extra-include filename="custom/hash/texture_fullid.h"/>
<stl-unordered-map name='tile_cache'>
<key-type type-name='texture_fullid'/>
<value-type type-name='pointer' comment='SDL_Texture*'/>
</stl-unordered-map>
</struct-type>

<class-type type-name='renderer_2d_base' inherits-from='renderer'>
<extra-include filename="custom/hash/texture_fullid.h"/>
<pointer name='window' comment='SDL_Window*'/>
<pointer name='sdl_renderer' comment='SDL_Renderer*'/>
<pointer name='screen_tex' comment='SDL_Texture*'/>
Expand Down
5 changes: 4 additions & 1 deletion df.item.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2453,7 +2453,10 @@

<stl-vector name='temp_save_compat' type-name='int32_t'/>

<stl-unordered-map name='deleters' comment='std::unordered_set&lt;df::item *&gt;'/>
<stl-unordered-set name='deleters'>
<pointer type-name='item'/>
</stl-unordered-set>

</struct-type>

<enum-type type-name='artifact_flags'> bay12: ArtifactFlagType
Expand Down
7 changes: 6 additions & 1 deletion df.region_midmap.xml
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,12 @@
<int16_t name="loadarea_ex"/>
<int16_t name="loadarea_ey"/>

<stl-map name="midmap_place" comment="std::map&lt;std::pair&lt;int16_t,int16_t&gt;,VIndex&gt;; not saved"/>
<stl-map name="midmap_place" comment="not saved">
<key-type>
<static-array type-name='int16_t' count='2'/>
</key-type>
<value-type type-name='int32_t'/>
</stl-map>
</struct-type>
</data-definition>

Expand Down
14 changes: 11 additions & 3 deletions df.widgets.unit_list.xml
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,10 @@
<stl-vector type-name='sort_entry' name='sorting_by' comment='std::vector&lt;sort_entry&lt;item_or_unit&gt;&gt;'/>
<stl-vector name='always_sorting_by'> <stl-function type-name='bool'/> </stl-vector>
<stl-vector name='partitions'> <stl-function type-name='bool'/> </stl-vector>
<stl-unordered-map name='ascending_sort'/> std::unordered_map&lt;std::string,bool&gt;
<stl-unordered-map name='ascending_sort'>
<key-type type-name='stl-string'/>
<value-type type-name='bool'/>
</stl-unordered-map>
<bitfield type-name='unit_list_sort_flag' name='sort_flags' base-type='uint8_t'/>
<bitfield type-name='unit_list_flag' name='flags' base-type='uint8_t'/>
<stl-vector name='filter_func'> <stl-function type-name='bool'/> </stl-vector>
Expand All @@ -76,8 +79,13 @@
<stl-function name='close_callback'/>
<stl-vector type-name='unit_list_options' name='options'/>
<stl-vector type-name='item_or_unit' name='entry_list'/>
<stl-unordered-map name='selected' comment='std::unordered_set&lt;void *&gt;'/>
<stl-unordered-map type-name='stl-string' name='job_sort_str' comment='std::unordered_map&lt;void *,std::string&gt;'/>
<stl-unordered-set name='selected' comment='std::unordered_set&lt;void *&gt;'>
<pointer/>
</stl-unordered-set>
<stl-unordered-map name='job_sort_str'>
<key-type><pointer/></key-type>
<value-type><stl-string/></value-type>
</stl-unordered-map>
<int32_t name='cursor_idx'/>
<stl-function name='is_selected' comment='std::function&lt;bool(item_or_unit)&gt;'/>
<stl-vector name='on_select_change'>
Expand Down
9 changes: 8 additions & 1 deletion df.world.xml
Original file line number Diff line number Diff line change
Expand Up @@ -340,7 +340,14 @@
<stl-fs-path name='src_dir'/>
<stl-vector pointer-type='stl-string' name='object_load_order_name'/>
<stl-vector pointer-type='stl-string' name='object_load_order_displayed_version'/>
<static-array count='23' name='token_by_mod_id'><stl-unordered-map/></static-array>
<static-array count='23' name='token_by_mod_id'>
<stl-unordered-map>
<key-type type-name='stl-string'/>
<value-type>
<stl-vector type-name='stl-string'/>
</value-type>
</stl-unordered-map>
</static-array>
</struct-type>

<enum-type type-name='prepare_rod_stage_type' base-type='int32_t'> bay12: PrepareRodStageType
Expand Down
Loading
Loading