Package: simutrans-makeobj Followup-For: Bug #493409 With the attached series of patches I get identical results on i386, amd64 and mips.
00_big_endian.patch This uses the <endian.h> header to detect big-endian systems. This replaces the hack in the Makefile (seriously, powerpc isn't the only big-endian arch...). I don't think <endian.h> is portable, so this probably isn't a suitable solution for upstream. 01_png.patch Peter Green's PNG reader fix. 02_makeobj_fixes.patch makeobj writes some data by dumping in-memory object instances to disk. This is obviously not portable, so this needed to be rewritten. It looks like Hajo fixed most of this in the past, I did the rest. 03_makeobj_cleanup.patch After the last patch the weird logic in obj_node_t isn't needed anymore, so it can be removed. (This is strictly cleanup, it isn't necessary for makeobj to run correctly.)
--- a/simtypes.h +++ b/simtypes.h @@ -8,6 +8,13 @@ #ifndef SIMTYPES_H #define SIMTYPES_H +#include <endian.h> +#undef LITTLE_ENDIAN //endian.h gives these definitions we don't want +#undef BIG_ENDIAN +#if __BYTE_ORDER == __BIG_ENDIAN + #define BIG_ENDIAN +#endif + #if defined _MSC_VER # if _MSC_VER <= 1200 # error "Simutrans cannot be compiled with Visual C++ 6.0 or earlier."
--- a/utils/dr_rdpng.c +++ b/utils/dr_rdpng.c @@ -48,11 +48,15 @@ png_read_info(png_ptr, info_ptr); + //png_uint_32 is 64 bit on some architectures! + png_uint_32 widthpu32,heightpu32; png_get_IHDR( png_ptr, info_ptr, - width, height, &bit_depth, &color_type, + &widthpu32, &heightpu32, &bit_depth, &color_type, &interlace_type, NULL, NULL ); + *width = widthpu32; + *height = heightpu32; if (*height % base_img_size != 0 || *width % base_img_size != 0) { printf("read_png: Invalid image size.\n");
--- a/besch/writer/factory_writer.cc +++ b/besch/writer/factory_writer.cc @@ -38,14 +38,19 @@ { rauch_besch_t besch; memset(&besch, 0, sizeof(besch)); - obj_node_t node(this, sizeof(besch), &parent, true); + obj_node_t node(this, 10, &parent, false); xref_writer_t::instance()->write_obj(outfp, node, obj_smoke, obj.get("smoke"), true); besch.pos_off = obj.get_koord("smoketile", koord(0, 0)); besch.xy_off = obj.get_koord("smokeoffset", koord(0, 0)); besch.zeitmaske = obj.get_int( "smokespeed", 0); - node.write_data(outfp, &besch); + node.write_sint16(outfp, besch.pos_off.x, 0); + node.write_sint16(outfp, besch.pos_off.y, 2); + node.write_sint16(outfp, besch.xy_off.x, 4); + node.write_sint16(outfp, besch.xy_off.x, 6); + node.write_sint16(outfp, besch.zeitmaske, 8); + node.write(outfp); } @@ -72,7 +77,7 @@ { fabrik_lieferant_besch_t besch; - obj_node_t node(this, sizeof(besch), &parent, true); + obj_node_t node(this, 8, &parent, false); besch.anzahl = count; besch.kapazitaet = capacity; @@ -80,7 +85,11 @@ xref_writer_t::instance()->write_obj(outfp, node, obj_good, warename, true); - node.write_data(outfp, &besch); + node.write_uint16(outfp, besch.kapazitaet, 0); + node.write_uint16(outfp, besch.anzahl, 2); + node.write_uint16(outfp, besch.verbrauch, 4); + node.write_uint16(outfp, 0, 6); //dummy, unused (and uninitialized in past versions) + node.write(outfp); } --- a/besch/writer/ground_writer.cc +++ b/besch/writer/ground_writer.cc @@ -10,7 +10,7 @@ { grund_besch_t besch; - obj_node_t node(this, sizeof(besch), &parent, true); + obj_node_t node(this, 0, &parent, false); write_head(fp, node, obj); @@ -37,6 +37,5 @@ } imagelist2d_writer_t::instance()->write_obj(fp, node, keys); - node.write_data(fp, &besch); node.write(fp); } --- a/besch/writer/pedestrian_writer.cc +++ b/besch/writer/pedestrian_writer.cc @@ -12,7 +12,7 @@ fussgaenger_besch_t besch; int i; - obj_node_t node(this, sizeof(besch), &parent, true); + obj_node_t node(this, 4, &parent, false); write_head(fp, node, obj); @@ -33,6 +33,8 @@ } imagelist_writer_t::instance()->write_obj(fp, node, keys); - node.write_data(fp, &besch); + node.write_uint16(fp, besch.gewichtung, 0); + node.write_uint16(fp, 0, 2); //dummy, unused (and uninitialized in past versions) + node.write(fp); } --- a/besch/writer/skin_writer.cc +++ b/besch/writer/skin_writer.cc @@ -31,12 +31,11 @@ skin_besch_t besch; - obj_node_t node(this, sizeof(besch), &parent, true); + obj_node_t node(this, 0, &parent, false); write_head(fp, node, obj); imagelist_writer_t::instance()->write_obj(fp, node, imagekeys); - node.write_data(fp, &besch); node.write(fp); } --- a/besch/writer/sound_writer.cc +++ b/besch/writer/sound_writer.cc @@ -7,7 +7,7 @@ void sound_writer_t::write_obj(FILE* fp, obj_node_t& parent, tabfileobj_t& obj) { - obj_node_t node(this, 4, &parent, true); + obj_node_t node(this, 4, &parent, false); write_head(fp, node, obj);
--- a/besch/writer/obj_node.cc +++ b/besch/writer/obj_node.cc @@ -8,14 +8,13 @@ uint32 obj_node_t::free_offset; // next free offset in file -obj_node_t::obj_node_t(obj_writer_t* writer, int size, obj_node_t* parent, bool adjust) +obj_node_t::obj_node_t(obj_writer_t* writer, int size, obj_node_t* parent) { this->parent = parent; - this->adjust = adjust; desc.type = writer->get_type(); desc.children = 0; - desc.size = adjust ? (size - sizeof(obj_besch_t)) : size; + desc.size = size; write_offset = free_offset + sizeof(desc); free_offset = write_offset + desc.size; } @@ -39,21 +38,12 @@ void obj_node_t::write_data(FILE* fp, const void* data) { - write_data_at(fp, data, 0, adjust ? desc.size + 4 : desc.size); + write_data_at(fp, data, 0, desc.size); } void obj_node_t::write_data_at(FILE* fp, const void* data, int offset, int size) { - if (adjust) { - if (offset < sizeof(obj_besch_t)) { - data = static_cast<const char*>(data) + sizeof(obj_besch_t) - offset; - size -= sizeof(obj_besch_t) - offset; - offset = 0; - } else { - offset -= sizeof(obj_besch_t); - } - } if (offset < 0 || size < 0 || offset + size > desc.size) { char reason[1024]; sprintf(reason, "invalid parameters (offset=%d, size=%d, obj_size=%d)", offset, size, desc.size); --- a/besch/writer/obj_node.h +++ b/besch/writer/obj_node.h @@ -16,7 +16,6 @@ uint32 write_offset; // Start of node data in file (after node.desc) obj_node_t* parent; - bool adjust; // a normal besch structure start with 4 extra bytes public: // set_start_offset() - set offset of first node in file @@ -27,7 +26,7 @@ // writer object, that writes the node to the file // size space needed for node data // parent parent node - obj_node_t(obj_writer_t* writer, int size, obj_node_t* parent, bool adjust); + obj_node_t(obj_writer_t* writer, int size, obj_node_t* parent); // Write the complete node data to the file void write_data(FILE* fp, const void* data); --- a/besch/writer/bridge_writer.cc +++ b/besch/writer/bridge_writer.cc @@ -12,7 +12,7 @@ void bridge_writer_t::write_obj(FILE* outfp, obj_node_t& parent, tabfileobj_t& obj) { - obj_node_t node(this, 22, &parent, false); + obj_node_t node(this, 22, &parent); uint8 wegtyp = get_waytype(obj.get("waytype")); uint16 topspeed = obj.get_int("topspeed", 999); --- a/besch/writer/building_writer.cc +++ b/besch/writer/building_writer.cc @@ -18,7 +18,7 @@ { haus_tile_besch_t besch; - obj_node_t node(this, 7, &parent, false); + obj_node_t node(this, 7, &parent); besch.phasen = 0; for (int i = 0; i < seasons; i++) { @@ -68,7 +68,7 @@ haus_besch_t besch; // Hajo: take care, hardocded size of node on disc here! - obj_node_t node(this, 26, &parent, false); + obj_node_t node(this, 26, &parent); write_head(fp, node, obj); --- a/besch/writer/citycar_writer.cc +++ b/besch/writer/citycar_writer.cc @@ -12,7 +12,7 @@ stadtauto_besch_t besch; int i; - obj_node_t node(this, 10, &parent, false); + obj_node_t node(this, 10, &parent); besch.gewichtung = obj.get_int("distributionweight", 1); --- a/besch/writer/crossing_writer.cc +++ b/besch/writer/crossing_writer.cc @@ -38,7 +38,7 @@ } // ok, node can be allocated now - obj_node_t node(this, total_len, &parent, false); + obj_node_t node(this, total_len, &parent); write_head(fp, node, obj); // Hajo: version number --- a/besch/writer/factory_writer.cc +++ b/besch/writer/factory_writer.cc @@ -12,7 +12,7 @@ { field_besch_t besch; memset(&besch, 0, sizeof(besch)); - obj_node_t node(this, 11, &parent, false); + obj_node_t node(this, 11, &parent); xref_writer_t::instance()->write_obj(outfp, node, obj_field, s, true); @@ -38,7 +38,7 @@ { rauch_besch_t besch; memset(&besch, 0, sizeof(besch)); - obj_node_t node(this, 10, &parent, false); + obj_node_t node(this, 10, &parent); xref_writer_t::instance()->write_obj(outfp, node, obj_smoke, obj.get("smoke"), true); besch.pos_off = obj.get_koord("smoketile", koord(0, 0)); @@ -57,7 +57,7 @@ void factory_product_writer_t::write_obj(FILE* outfp, obj_node_t& parent, int capacity, int factor, const char* warename) { - obj_node_t node(this, sizeof(uint16) * 3, &parent, false); + obj_node_t node(this, sizeof(uint16) * 3, &parent); xref_writer_t::instance()->write_obj(outfp, node, obj_good, warename, true); @@ -77,7 +77,7 @@ { fabrik_lieferant_besch_t besch; - obj_node_t node(this, 8, &parent, false); + obj_node_t node(this, 8, &parent); besch.anzahl = count; besch.kapazitaet = capacity; @@ -117,7 +117,7 @@ } besch.pax_level = obj.get_int("pax_level", 12); - obj_node_t node(this, 18, &parent, false); + obj_node_t node(this, 18, &parent); obj.put("type", "fac"); --- a/besch/writer/good_writer.cc +++ b/besch/writer/good_writer.cc @@ -9,7 +9,7 @@ void good_writer_t::write_obj(FILE* fp, obj_node_t& parent, tabfileobj_t& obj) { - obj_node_t node(this, 10, &parent, false); + obj_node_t node(this, 10, &parent); write_head(fp, node, obj); text_writer_t::instance()->write_obj(fp, node, obj.get("metric")); --- a/besch/writer/ground_writer.cc +++ b/besch/writer/ground_writer.cc @@ -10,7 +10,7 @@ { grund_besch_t besch; - obj_node_t node(this, 0, &parent, false); + obj_node_t node(this, 0, &parent); write_head(fp, node, obj); --- a/besch/writer/groundobj_writer.cc +++ b/besch/writer/groundobj_writer.cc @@ -11,7 +11,7 @@ void groundobj_writer_t::write_obj(FILE* fp, obj_node_t& parent, tabfileobj_t& obj) { - obj_node_t node(this, 16, &parent, false); /* false, because we write this ourselves */ + obj_node_t node(this, 16, &parent); write_head(fp, node, obj); // Hajodoc: Preferred height of this tree type --- a/besch/writer/image_writer.cc +++ b/besch/writer/image_writer.cc @@ -324,7 +324,7 @@ #ifdef IMG_VERSION0 // ok, need to be changed to hand mode ... - obj_node_t node(this, 12 + (bild.len * sizeof(uint16)), &parent, false); + obj_node_t node(this, 12 + (bild.len * sizeof(uint16)), &parent); // to avoid any problems due to structure changes, we write manually the data node.write_uint8 (outfp, bild.x, 0); @@ -343,7 +343,7 @@ } #else // ok, need to be changed to hand mode ... - obj_node_t node(this, 10 + (bild.len * sizeof(uint16)), &parent, false); + obj_node_t node(this, 10 + (bild.len * sizeof(uint16)), &parent); // to avoid any problems due to structure changes, we write manually the data node.write_uint16(outfp, bild.x, 0); --- a/besch/writer/imagelist2d_writer.cc +++ b/besch/writer/imagelist2d_writer.cc @@ -10,7 +10,7 @@ { bildliste2d_besch_t besch; - obj_node_t node(this, 4, &parent, false); + obj_node_t node(this, 4, &parent); slist_iterator_tpl<slist_tpl<cstring_t> > iter(keys); --- a/besch/writer/imagelist_writer.cc +++ b/besch/writer/imagelist_writer.cc @@ -11,7 +11,7 @@ { bildliste_besch_t besch; - obj_node_t node(this, 4, &parent, false); + obj_node_t node(this, 4, &parent); slist_iterator_tpl<cstring_t> iter(keys); --- a/besch/writer/pedestrian_writer.cc +++ b/besch/writer/pedestrian_writer.cc @@ -12,7 +12,7 @@ fussgaenger_besch_t besch; int i; - obj_node_t node(this, 4, &parent, false); + obj_node_t node(this, 4, &parent); write_head(fp, node, obj); --- a/besch/writer/roadsign_writer.cc +++ b/besch/writer/roadsign_writer.cc @@ -11,7 +11,7 @@ void roadsign_writer_t::write_obj(FILE* fp, obj_node_t& parent, tabfileobj_t& obj) { - obj_node_t node(this, 14, &parent, false); /* false, because we write this ourselves */ + obj_node_t node(this, 14, &parent); // Hajodoc: Preferred height of this tree type // Hajoval: int (useful range: 0-14) --- a/besch/writer/root_writer.cc +++ b/besch/writer/root_writer.cc @@ -48,7 +48,7 @@ printf("writing file %s\n", filename); write_header(outfp); - node = new obj_node_t(this, 0, NULL, false); + node = new obj_node_t(this, 0, NULL); } for( int i=0; i==0 || i<argc; i++ ) { @@ -86,7 +86,7 @@ printf(" writing file %s\n", (const char*)name); write_header(outfp); - node = new obj_node_t(this, 0, NULL, false); + node = new obj_node_t(this, 0, NULL); } obj_writer_t::write(outfp, *node, obj); --- a/besch/writer/skin_writer.cc +++ b/besch/writer/skin_writer.cc @@ -31,7 +31,7 @@ skin_besch_t besch; - obj_node_t node(this, 0, &parent, false); + obj_node_t node(this, 0, &parent); write_head(fp, node, obj); --- a/besch/writer/sound_writer.cc +++ b/besch/writer/sound_writer.cc @@ -7,7 +7,7 @@ void sound_writer_t::write_obj(FILE* fp, obj_node_t& parent, tabfileobj_t& obj) { - obj_node_t node(this, 4, &parent, false); + obj_node_t node(this, 4, &parent); write_head(fp, node, obj); --- a/besch/writer/text_writer.cc +++ b/besch/writer/text_writer.cc @@ -11,7 +11,7 @@ } int len = strlen(text); - obj_node_t node(this, len + 1, &parent, false); + obj_node_t node(this, len + 1, &parent); node.write_data(outfp, text); node.write(outfp); --- a/besch/writer/tree_writer.cc +++ b/besch/writer/tree_writer.cc @@ -11,7 +11,7 @@ void tree_writer_t::write_obj(FILE* fp, obj_node_t& parent, tabfileobj_t& obj) { - obj_node_t node(this, 6, &parent, false); /* false, because we write this ourselves */ + obj_node_t node(this, 6, &parent); write_head(fp, node, obj); // Hajodoc: Preferred height of this tree type --- a/besch/writer/tunnel_writer.cc +++ b/besch/writer/tunnel_writer.cc @@ -14,7 +14,7 @@ { int pos, i; - obj_node_t node(this, 20, &parent, false); + obj_node_t node(this, 20, &parent); uint32 topspeed = obj.get_int("topspeed", 999); uint32 preis = obj.get_int("cost", 0); --- a/besch/writer/vehicle_writer.cc +++ b/besch/writer/vehicle_writer.cc @@ -76,7 +76,7 @@ } } - obj_node_t node(this, total_len, &parent, false); + obj_node_t node(this, total_len, &parent); write_head(fp, node, obj); --- a/besch/writer/way_obj_writer.cc +++ b/besch/writer/way_obj_writer.cc @@ -21,8 +21,7 @@ }; int ribi, hang; - // Hajo: node size is 24 bytes - obj_node_t node(this, 20, &parent, false); + obj_node_t node(this, 20, &parent); // Hajo: Version needs high bit set as trigger -> this is required --- a/besch/writer/way_writer.cc +++ b/besch/writer/way_writer.cc @@ -22,7 +22,7 @@ int ribi, hang; // Hajo: node size is 25 bytes - obj_node_t node(this, 26, &parent, false); + obj_node_t node(this, 26, &parent); // Hajo: Version needs high bit set as trigger -> this is required --- a/besch/writer/xref_writer.cc +++ b/besch/writer/xref_writer.cc @@ -16,8 +16,7 @@ sizeof(char) + // Fatal-Flag sizeof(obj_type) + // type of dest node len + 1, // 0-terminated name of dest node - &parent, - false + &parent ); char c = fatal ? 1 : 0;