From e27eb7a7e517284fe8d1fad633163b873264b278 Mon Sep 17 00:00:00 2001 From: terminx Date: Mon, 11 Jan 2016 05:06:02 +0000 Subject: [PATCH] Use XXH64 functions for editor undo/redo when building for 64-bit. git-svn-id: https://svn.eduke32.com/eduke32@5546 1a8010ca-5511-0410-912e-c29ae57300e0 --- polymer/eduke32/build/include/editor.h | 2 +- polymer/eduke32/source/m32common.c | 24 +++++++++++++++++------- 2 files changed, 18 insertions(+), 8 deletions(-) diff --git a/polymer/eduke32/build/include/editor.h b/polymer/eduke32/build/include/editor.h index bd8a9e0af..fe7fd9ab2 100644 --- a/polymer/eduke32/build/include/editor.h +++ b/polymer/eduke32/build/include/editor.h @@ -147,7 +147,7 @@ typedef struct mapundo_ // most of the time. +4 bytes refcount at the beginning. char *sws[3]; // sector, wall, sprite - uint32_t crc[3]; + uintptr_t crc[3]; struct mapundo_ *next; // 'redo' loads this struct mapundo_ *prev; // 'undo' loads this diff --git a/polymer/eduke32/source/m32common.c b/polymer/eduke32/source/m32common.c index 0dd9291ff..f348b28f2 100644 --- a/polymer/eduke32/source/m32common.c +++ b/polymer/eduke32/source/m32common.c @@ -337,7 +337,7 @@ mapundo_t *mapstate = NULL; int32_t map_revision = 1; -static int32_t try_match_with_prev(int32_t idx, int32_t numsthgs, uint32_t crc) +static int32_t try_match_with_prev(int32_t idx, int32_t numsthgs, uintptr_t crc) { if (mapstate->prev && mapstate->prev->num[idx]==numsthgs && mapstate->prev->crc[idx]==crc) { @@ -351,7 +351,7 @@ static int32_t try_match_with_prev(int32_t idx, int32_t numsthgs, uint32_t crc) return 0; } -static void create_compressed_block(int32_t idx, const void *srcdata, uint32_t size, uint32_t crc) +static void create_compressed_block(int32_t idx, const void *srcdata, uint32_t size, uintptr_t crc) { uint32_t j; @@ -442,15 +442,24 @@ void create_map_snapshot(void) if (numsectors) { - int32_t j; - uint32_t temphash = XXH32((uint8_t *)sector, numsectors*sizeof(sectortype), numsectors*sizeof(sectortype)); +#if !defined UINTPTR_MAX +# error Need UINTPTR_MAX define to select between 32- and 64-bit functions +#endif +#if UINTPTR_MAX == 0xffffffff + /* 32-bit */ +#define XXH__ XXH32 +#else + /* 64-bit */ +#define XXH__ XXH64 +#endif + uintptr_t temphash = XXH__((uint8_t *)sector, numsectors*sizeof(sectortype), numsectors*sizeof(sectortype)); if (!try_match_with_prev(0, numsectors, temphash)) create_compressed_block(0, sector, numsectors*sizeof(sectortype), temphash); if (numwalls) { - temphash = XXH32((uint8_t *)wall, numwalls*sizeof(walltype), numwalls*sizeof(walltype)); + temphash = XXH__((uint8_t *)wall, numwalls*sizeof(walltype), numwalls*sizeof(walltype)); if (!try_match_with_prev(1, numwalls, temphash)) create_compressed_block(1, wall, numwalls*sizeof(walltype), temphash); @@ -458,7 +467,7 @@ void create_map_snapshot(void) if (Numsprites) { - temphash = XXH32((uint8_t *)sprite, MAXSPRITES*sizeof(spritetype), MAXSPRITES*sizeof(spritetype)); + temphash = XXH__((uint8_t *)sprite, MAXSPRITES*sizeof(spritetype), MAXSPRITES*sizeof(spritetype)); if (!try_match_with_prev(2, Numsprites, temphash)) { @@ -466,7 +475,7 @@ void create_map_snapshot(void) spritetype *const tspri = (spritetype *)Xmalloc(Numsprites*sizeof(spritetype) + 4); spritetype *spri = tspri; - for (j=0; j