From 934ce5e84e5f8385c46289438aa1877b94fb6e7e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Janiszewski?= Date: Fri, 3 Jun 2016 00:18:20 +0200 Subject: [PATCH] Fix 64 bit by skipping static_asserts for structs with pointers --- src/audio/audio.h | 9 ++++----- src/common.h | 6 ++++++ src/drawing/drawing.h | 6 ++++++ src/object.h | 2 ++ src/paint/paint.h | 6 ++++++ src/ride/ride.h | 4 ++++ src/ride/track_design.h | 2 ++ src/ride/vehicle.h | 2 ++ src/scenario.h | 2 ++ src/world/map.h | 4 ++++ src/world/scenery.h | 5 ++++- src/world/sprite.h | 4 ++++ 12 files changed, 46 insertions(+), 6 deletions(-) diff --git a/src/audio/audio.h b/src/audio/audio.h index ed4015d38b..463f1520b4 100644 --- a/src/audio/audio.h +++ b/src/audio/audio.h @@ -41,8 +41,9 @@ typedef struct rct_ride_music { uint16 frequency; void* sound_channel; } rct_ride_music; - +#ifdef PLATFORM_32BIT STATIC_ASSERT (sizeof(rct_ride_music) == 12, "Improper struct size"); +#endif typedef struct rct_ride_music_info { uint32 length; @@ -50,7 +51,6 @@ typedef struct rct_ride_music_info { uint8 path_id; uint8 var_9; } rct_ride_music_info; - STATIC_ASSERT (sizeof(rct_ride_music_info) == 10, "Improper struct size"); typedef struct rct_ride_music_params { @@ -61,7 +61,6 @@ typedef struct rct_ride_music_params { sint16 pan; uint16 frequency; } rct_ride_music_params; - STATIC_ASSERT (sizeof(rct_ride_music_params) == 12, "Improper struct size"); typedef struct rct_vehicle_sound { @@ -78,8 +77,9 @@ typedef struct rct_vehicle_sound { void* sound1_channel; void* sound2_channel; } rct_vehicle_sound; - +#ifdef PLATFORM_32BIT STATIC_ASSERT (sizeof(rct_vehicle_sound) == 28, "Improper struct size"); +#endif typedef struct rct_vehicle_sound_params { uint16 id; @@ -89,7 +89,6 @@ typedef struct rct_vehicle_sound_params { sint16 volume; uint16 var_A; } rct_vehicle_sound_params; - STATIC_ASSERT (sizeof(rct_vehicle_sound_params) == 12, "Improper struct size"); #pragma pack(pop) diff --git a/src/common.h b/src/common.h index c9dfd4998d..9d68f41744 100644 --- a/src/common.h +++ b/src/common.h @@ -34,6 +34,12 @@ #define PLATFORM_X86 #endif +#if defined(__LP64__) || defined(_WIN64) + #define PLATFORM_64BIT +#else + #define PLATFORM_32BIT +#endif + // C99's restrict keywords guarantees the pointer in question, for the whole of its lifetime, // will be the only way to access a given memory region. In other words: there is no other pointer // aliasing the same memory area. Using it lets compiler generate better code. If your compiler diff --git a/src/drawing/drawing.h b/src/drawing/drawing.h index cc9a70274f..828b944ce6 100644 --- a/src/drawing/drawing.h +++ b/src/drawing/drawing.h @@ -31,7 +31,9 @@ typedef struct rct_drawpixelinfo { short pitch; // 0x0C note: this is actually (pitch - width) uint16 zoom_level; // 0x0E } rct_drawpixelinfo; +#ifdef PLATFORM_32BIT STATIC_ASSERT (sizeof(rct_drawpixelinfo) == 0x10, "Improper struct size"); +#endif // Size: 0x10 typedef struct rct_g1_element { @@ -43,7 +45,9 @@ typedef struct rct_g1_element { uint16 flags; // 0x0C uint16 zoomed_offset; // 0x0E } rct_g1_element; +#ifdef PLATFORM_32BIT STATIC_ASSERT (sizeof(rct_g1_element) == 0x10, "Improper struct size"); +#endif enum { G1_FLAG_BMP = (1 << 0), //No invisible sections @@ -68,7 +72,9 @@ typedef struct rct_gx { rct_g1_element *elements; void *data; } rct_gx; +#ifdef PLATFORM_32BIT STATIC_ASSERT (sizeof(rct_gx) == 16, "Improper struct size"); +#endif typedef struct rct_palette_entry { uint8 blue; diff --git a/src/object.h b/src/object.h index c4f72389db..29693cf16a 100644 --- a/src/object.h +++ b/src/object.h @@ -81,7 +81,9 @@ typedef struct rct_object_entry_group { uint8 **chunks; rct_object_entry_extended *entries; } rct_object_entry_group; +#ifdef PLATFORM_32BIT STATIC_ASSERT (sizeof(rct_object_entry_group) == 8, "Improper struct size"); +#endif typedef struct rct_ride_filters { uint8 category[2]; diff --git a/src/paint/paint.h b/src/paint/paint.h index a027dfde42..491bec2006 100644 --- a/src/paint/paint.h +++ b/src/paint/paint.h @@ -39,8 +39,10 @@ struct attached_paint_struct { uint8 pad_0D; attached_paint_struct* next; //0x0E }; +#ifdef PLATFORM_32BIT // TODO: drop packing from this when all rendering is done. STATIC_ASSERT (sizeof(attached_paint_struct) == 0x12, "Improper struct size"); +#endif typedef struct paint_struct paint_struct; @@ -73,8 +75,10 @@ struct paint_struct { uint16 map_y; // 0x2E rct_map_element *mapElement; // 0x30 (or sprite pointer) }; +#ifdef PLATFORM_32BIT // TODO: drop packing from this when all rendering is done. STATIC_ASSERT (sizeof(paint_struct) == 0x34, "Improper struct size"); +#endif typedef struct paint_string_struct paint_string_struct; @@ -87,7 +91,9 @@ struct paint_string_struct { uint32 args[4]; // 0x0A uint8 *y_offsets; // 0x1A }; +#ifdef PLATFORM_32BIT STATIC_ASSERT (sizeof(paint_string_struct) == 0x1e, "Improper struct size"); +#endif #pragma pack(pop) typedef struct sprite_bb { diff --git a/src/ride/ride.h b/src/ride/ride.h index 2c247a5f7e..4a53d80b1a 100644 --- a/src/ride/ride.h +++ b/src/ride/ride.h @@ -122,7 +122,9 @@ typedef struct rct_ride_entry { uint8 shop_item; // 0x1C0 uint8 shop_item_secondary; // 0x1C1 } rct_ride_entry; +#ifdef PLATFORM_32BIT STATIC_ASSERT (sizeof(rct_ride_entry) == 0x1c2, "Improper struct size"); +#endif /** * Ride structure. @@ -363,7 +365,9 @@ typedef struct track_begin_end { int end_direction; rct_map_element *end_element; } track_begin_end; +#ifdef PLATFORM_32BIT STATIC_ASSERT (sizeof(track_begin_end) == 36, "Improper struct size"); +#endif #pragma pack(pop) diff --git a/src/ride/track_design.h b/src/ride/track_design.h index da433d57da..e23db102fa 100644 --- a/src/ride/track_design.h +++ b/src/ride/track_design.h @@ -147,7 +147,9 @@ typedef struct rct_track_td6 { utf8 *name; } rct_track_td6; //Warning: improper struct size in comment +#ifdef PLATFORM_32BIT STATIC_ASSERT (sizeof(rct_track_td6) == 0xbf, "Improper struct size"); +#endif #pragma pack(pop) typedef struct track_design_file_ref { diff --git a/src/ride/vehicle.h b/src/ride/vehicle.h index a9b94b425e..b72205d96a 100644 --- a/src/ride/vehicle.h +++ b/src/ride/vehicle.h @@ -77,7 +77,9 @@ typedef struct rct_ride_entry_vehicle { uint8 special_frames; // 0x60 , 0x7A sint8* peep_loading_positions; // 0x61 , 0x7B } rct_ride_entry_vehicle; +#ifdef PLATFORM_32BIT STATIC_ASSERT (sizeof(rct_ride_entry_vehicle) == 0x65, "Improper struct size"); +#endif typedef struct rct_vehicle { uint8 sprite_identifier; // 0x00 diff --git a/src/scenario.h b/src/scenario.h index caeb4656e0..b3f4cac62f 100644 --- a/src/scenario.h +++ b/src/scenario.h @@ -398,7 +398,9 @@ typedef struct scenario_highscore_entry { datetime64 timestamp; } scenario_highscore_entry; // NOTE: Check if needed +#ifdef PLATFORM_32BIT STATIC_ASSERT (sizeof(scenario_highscore_entry) == 20, "Improper struct size"); +#endif typedef struct scenario_index_entry { utf8 path[MAX_PATH]; diff --git a/src/world/map.h b/src/world/map.h index f4230726c1..7acaf3aac2 100644 --- a/src/world/map.h +++ b/src/world/map.h @@ -276,7 +276,9 @@ typedef struct rct_xy_element { int x, y; rct_map_element *element; } rct_xy_element; +#ifdef PLATFORM_32BIT STATIC_ASSERT (sizeof(rct_xy_element) == 12, "Improper struct size"); +#endif typedef struct rct2_peep_spawn { uint16 x; @@ -442,7 +444,9 @@ typedef struct map_element_iterator { int y; rct_map_element *element; } map_element_iterator; +#ifdef PLATFORM_32BIT STATIC_ASSERT (sizeof(map_element_iterator) == 12, "Improper struct size"); +#endif void map_element_iterator_begin(map_element_iterator *it); int map_element_iterator_next(map_element_iterator *it); diff --git a/src/world/scenery.h b/src/world/scenery.h index 2ca3ae033c..bc0fa7132b 100644 --- a/src/world/scenery.h +++ b/src/world/scenery.h @@ -104,8 +104,9 @@ typedef struct rct_large_scenery_entry { rct_large_scenery_text* text; // 0x12 uint32 text_image; // 0x16 } rct_large_scenery_entry; +#ifdef PLATFORM_32BIT STATIC_ASSERT (sizeof(rct_large_scenery_entry) == 20, "Improper struct size"); - +#endif typedef struct rct_wall_scenery_entry { uint8 tool_id; // 0x06 @@ -161,7 +162,9 @@ typedef struct rct_scenery_entry { rct_banner_scenery_entry banner; }; } rct_scenery_entry; +#ifdef PLATFORM_32BIT STATIC_ASSERT (sizeof(rct_scenery_entry) == 6 + 21, "Improper struct size"); +#endif typedef struct rct_scenery_set_entry { rct_string_id name; // 0x00 diff --git a/src/world/sprite.h b/src/world/sprite.h index 04e1156039..a086c20ac5 100644 --- a/src/world/sprite.h +++ b/src/world/sprite.h @@ -352,13 +352,17 @@ typedef struct rct_sprite_image { uint32 base_image; // 0x00 uint8* unkn_04; // 0x04 } rct_sprite_image; +#ifdef PLATFORM_32BIT STATIC_ASSERT (sizeof(rct_sprite_image) == 8, "Improper struct size"); +#endif typedef struct rct_sprite_entry { rct_sprite_image *sprite_image; // 0x00 rct_sprite_bounds *sprite_bounds; // 0x04 } rct_sprite_entry; +#ifdef PLATFORM_32BIT STATIC_ASSERT (sizeof(rct_sprite_entry) == 8, "Improper struct size"); +#endif #pragma pack(pop) enum {