From 044e59dd66761ca40ae6ac20f27a61197561b307 Mon Sep 17 00:00:00 2001 From: avolkov Date: Sun, 20 Dec 2009 02:02:24 +0000 Subject: [PATCH] Make STRINGPTR a 'char *'; GetStringContents() removed; minor header path changes git-svn-id: svn://svn.code.sf.net/p/sc2/code/trunk@3452 8092fc87-c524-0410-9efc-e669fe64eaf9 --- sc2/src/libs/gfxlib.h | 11 +++++++---- sc2/src/libs/graphics/cmap.c | 12 +++++++++++- sc2/src/libs/reslib.h | 6 ++---- sc2/src/libs/sndlib.h | 8 +++++--- sc2/src/libs/sound/sfx.c | 13 ++++++++++++- sc2/src/libs/strings/getstr.c | 2 +- sc2/src/libs/strings/strings.c | 22 ---------------------- sc2/src/libs/strlib.h | 6 ++---- sc2/src/uqm/cyborg.c | 7 ++++--- sc2/src/uqm/encount.c | 4 ++-- sc2/src/uqm/master.c | 16 +++++++--------- sc2/src/uqm/planets/plandata.h | 3 +++ sc2/src/uqm/planets/planets.h | 2 +- 13 files changed, 57 insertions(+), 55 deletions(-) diff --git a/sc2/src/libs/gfxlib.h b/sc2/src/libs/gfxlib.h index e9cb98861..651648b4c 100644 --- a/sc2/src/libs/gfxlib.h +++ b/sc2/src/libs/gfxlib.h @@ -19,6 +19,7 @@ #ifndef _GFXLIB_H #define _GFXLIB_H +#include "port.h" #include "libs/compiler.h" typedef struct Color Color; @@ -220,11 +221,13 @@ typedef struct text COUNT CharCount; } TEXT; -#include "strlib.h" +#include "libs/strlib.h" typedef STRING_TABLE COLORMAP_REF; typedef STRING COLORMAP; -typedef STRINGPTR COLORMAPPTR; +// COLORMAPPTR is really a pointer to colortable entry structure +// which is documented in doc/devel/strtab, .ct files section +typedef void *COLORMAPPTR; #include "graphics/prim.h" @@ -374,8 +377,8 @@ extern void FlushColorXForms (void); #define SetAbsColorMapIndex SetAbsStringTableIndex #define SetRelColorMapIndex SetRelStringTableIndex #define GetColorMapLength GetStringLengthBin -#define GetColorMapAddress GetStringAddress -#define GetColorMapContents GetStringContents + +extern COLORMAPPTR GetColorMapAddress (COLORMAP); void SetSystemRect (const RECT *pRect); void ClearSystemRect (void); diff --git a/sc2/src/libs/graphics/cmap.c b/sc2/src/libs/graphics/cmap.c index 3ebfedb74..d6c0d6576 100644 --- a/sc2/src/libs/graphics/cmap.c +++ b/sc2/src/libs/graphics/cmap.c @@ -20,6 +20,8 @@ #include "libs/threadlib.h" #include "libs/timelib.h" #include "libs/inplib.h" +#include "libs/strlib.h" + // for GetStringAddress() #include "libs/log.h" #include #include @@ -543,7 +545,7 @@ XFormPLUT (COLORMAPPTR ColorMapPtr, SIZE TimeInterval) DWORD Now; Now = GetTimeCounter (); - index = *ColorMapPtr; + index = *(UBYTE*)ColorMapPtr; LockMutex (XFormControl.Lock); // Find an available slot, or reuse if required @@ -619,3 +621,11 @@ FlushColorXForms (void) FlushFadeXForms (); FlushPLUTXForms (); } + +// The type conversions are implicit and will generate errors +// or warnings if types change imcompatibly +COLORMAPPTR +GetColorMapAddress (COLORMAP colormap) +{ + return GetStringAddress (colormap); +} diff --git a/sc2/src/libs/reslib.h b/sc2/src/libs/reslib.h index ee1ff701c..4966affa1 100644 --- a/sc2/src/libs/reslib.h +++ b/sc2/src/libs/reslib.h @@ -78,13 +78,12 @@ void *GetResourceData (uio_Stream *fp, DWORD length); #define AllocResourceData HMalloc BOOLEAN FreeResourceData (void *); -#include "strlib.h" -#include "gfxlib.h" +#include "libs/strlib.h" +#include "libs/gfxlib.h" // For Color typedef STRING_TABLE DIRENTRY_REF; typedef STRING DIRENTRY; -typedef STRINGPTR DIRENTRYPTR; extern DIRENTRY_REF LoadDirEntryTable (uio_DirHandle *dirHandle, const char *path, const char *pattern, match_MatchType matchType); @@ -98,7 +97,6 @@ extern DIRENTRY_REF LoadDirEntryTable (uio_DirHandle *dirHandle, #define SetRelDirEntryTableIndex SetRelStringTableIndex #define GetDirEntryLength GetStringLengthBin #define GetDirEntryAddress GetStringAddress -#define GetDirEntryContents GetStringContents /* Key-Value resources */ diff --git a/sc2/src/libs/sndlib.h b/sc2/src/libs/sndlib.h index dca4cfaf5..cc8c38895 100644 --- a/sc2/src/libs/sndlib.h +++ b/sc2/src/libs/sndlib.h @@ -19,11 +19,13 @@ #ifndef _SNDLIB_H #define _SNDLIB_H +#include "port.h" #include "libs/strlib.h" typedef STRING_TABLE SOUND_REF; typedef STRING SOUND; -typedef STRINGPTR SOUNDPTR; +// SOUNDPTR is really a TFB_SoundSample** +typedef void *SOUNDPTR; typedef struct soundposition { @@ -39,8 +41,8 @@ typedef struct soundposition #define GetSoundIndex GetStringTableIndex #define SetAbsSoundIndex SetAbsStringTableIndex #define SetRelSoundIndex SetRelStringTableIndex -#define GetSoundAddress GetStringAddress -#define GetSoundContents GetStringContents + +extern SOUNDPTR GetSoundAddress (SOUND sound); typedef struct tfb_soundsample TFB_SoundSample; typedef TFB_SoundSample **MUSIC_REF; diff --git a/sc2/src/libs/sound/sfx.c b/sc2/src/libs/sound/sfx.c index 409874e43..e8af8b808 100644 --- a/sc2/src/libs/sound/sfx.c +++ b/sc2/src/libs/sound/sfx.c @@ -19,7 +19,10 @@ #include "sndintrn.h" #include "libs/reslib.h" #include "libs/log.h" +#include "libs/strlib.h" + // for GetStringAddress() #include "libs/strings/strintrn.h" + // for AllocStringTable(), FreeStringTable() #include "libs/memlib.h" #include @@ -31,7 +34,7 @@ void PlayChannel (COUNT channel, SOUND snd, SoundPosition pos, void *positional_object, unsigned char priority) { - void *snd_ptr = GetSoundAddress (snd); + SOUNDPTR snd_ptr = GetSoundAddress (snd); TFB_SoundSample *sample; StopSource (channel); @@ -293,3 +296,11 @@ DestroySound(SOUND_REF target) { return _ReleaseSoundBankData (target); } + +// The type conversions are implicit and will generate errors +// or warnings if types change imcompatibly +SOUNDPTR +GetSoundAddress (SOUND sound) +{ + return GetStringAddress (sound); +} diff --git a/sc2/src/libs/strings/getstr.c b/sc2/src/libs/strings/getstr.c index b055382a0..74d57a207 100644 --- a/sc2/src/libs/strings/getstr.c +++ b/sc2/src/libs/strings/getstr.c @@ -470,7 +470,7 @@ _GetBinaryTableData (uio_Stream *fp, DWORD length) stringptr = (BYTE *)(fileData + 2 + size + fileData[1]); for (i = 0; i < size; i++) { - set_strtab_entry (lpST, i, stringptr, fileData[2+i]); + set_strtab_entry (lpST, i, (char *)stringptr, fileData[2+i]); stringptr += fileData[2+i]; } } diff --git a/sc2/src/libs/strings/strings.c b/sc2/src/libs/strings/strings.c index 0bf3beae1..02e93a2a2 100644 --- a/sc2/src/libs/strings/strings.c +++ b/sc2/src/libs/strings/strings.c @@ -285,25 +285,3 @@ GetStringAddress (STRING String) } return String->data; } - -BOOLEAN -GetStringContents (STRING String, STRINGPTR StringBuf, BOOLEAN - AppendSpace) -{ - STRINGPTR StringAddr; - COUNT StringLength; - - if ((StringAddr = GetStringAddress (String)) != 0 && - (StringLength = GetStringLengthBin (String)) != 0) - { - memcpy (StringBuf, StringAddr, StringLength); - if (AppendSpace) - StringBuf[StringLength++] = ' '; - StringBuf[StringLength] = '\0'; - - return (TRUE); - } - - *StringBuf = '\0'; - return (FALSE); -} diff --git a/sc2/src/libs/strlib.h b/sc2/src/libs/strlib.h index c0e242b36..7f4ba0245 100644 --- a/sc2/src/libs/strlib.h +++ b/sc2/src/libs/strlib.h @@ -31,10 +31,10 @@ typedef struct string_table STRING_TABLE_DESC; typedef STRING_TABLE_DESC *STRING_TABLE; typedef STRING_TABLE_ENTRY_DESC *STRING; -typedef BYTE *STRINGPTR; +typedef char *STRINGPTR; /* This has to go here because reslib requires the above typedefs. */ -#include "reslib.h" +#include "libs/reslib.h" extern BOOLEAN InstallStringTableResType (void); extern STRING_TABLE LoadStringTableInstance (RESOURCE res); @@ -55,8 +55,6 @@ extern COUNT GetStringLengthBin (STRING String); extern STRINGPTR GetStringAddress (STRING String); extern STRINGPTR GetStringSoundClip (STRING String); extern STRINGPTR GetStringTimeStamp (STRING String); -extern BOOLEAN GetStringContents (STRING String, STRINGPTR StringBuf, - BOOLEAN AppendSpace); #define UNICHAR_DEGREE_SIGN 0x00b0 #define STR_DEGREE_SIGN "\xC2\xB0" diff --git a/sc2/src/uqm/cyborg.c b/sc2/src/uqm/cyborg.c index c1f91b052..056c1b4e6 100644 --- a/sc2/src/uqm/cyborg.c +++ b/sc2/src/uqm/cyborg.c @@ -299,10 +299,11 @@ InitCyborg (STARSHIP *StarShipPtr) Index >>= 1; #ifdef PRINT_MI { - char buf[40]; + char *shipName; - GetStringContents (StarShipPtr->RaceDescPtr->ship_data.race_strings, buf, FALSE); - log_add (log_Debug, "MI(%s) -- <%u:%u> = %u", buf, + shipName = GetStringAddress ( + StarShipPtr->RaceDescPtr->ship_data.race_strings); + log_add (log_Debug, "MI(%s) -- <%u:%u> = %u", shipName, StarShipPtr->RaceDescPtr->characteristics.max_thrust * StarShipPtr->RaceDescPtr->characteristics.thrust_increment, Divisor, Index); diff --git a/sc2/src/uqm/encount.c b/sc2/src/uqm/encount.c index 0d60b357a..0ae24f8a4 100644 --- a/sc2/src/uqm/encount.c +++ b/sc2/src/uqm/encount.c @@ -555,8 +555,8 @@ UninitEncounter (void) BUILD_COLOR (MAKE_RGB15 (0x08, 0x08, 0x08), 0x1F)); SetContextFont (TinyFont); - GetStringContents (FragPtr->race_strings, - (STRINGPTR)buf, FALSE); + utf8StringCopy (buf, sizeof buf, + GetStringAddress (FragPtr->race_strings)); // XXX: this will not work with UTF-8 strings strupr (buf); diff --git a/sc2/src/uqm/master.c b/sc2/src/uqm/master.c index a641a1da8..23864fe1d 100644 --- a/sc2/src/uqm/master.c +++ b/sc2/src/uqm/master.c @@ -36,7 +36,7 @@ LoadMasterShipList (void (* YieldProcessing)(void)) while (num_entries--) { HMASTERSHIP hBuiltShip; - char built_buf[30]; + char *builtName; HMASTERSHIP hStarShip, hNextShip; MASTER_SHIP_INFO *BuiltPtr; RACE_DESC *RDPtr; @@ -65,9 +65,8 @@ LoadMasterShipList (void (* YieldProcessing)(void)) BuiltPtr->Fleet = RDPtr->fleet; free_ship (RDPtr, FALSE, FALSE); - GetStringContents (SetAbsStringTableIndex ( - BuiltPtr->ShipInfo.race_strings, 2 - ), (STRINGPTR)built_buf, FALSE); + builtName = GetStringAddress (SetAbsStringTableIndex ( + BuiltPtr->ShipInfo.race_strings, 2)); UnlockMasterShip (&master_q, hBuiltShip); // Insert the ship in the master queue in the right location @@ -75,17 +74,16 @@ LoadMasterShipList (void (* YieldProcessing)(void)) for (hStarShip = GetHeadLink (&master_q); hStarShip; hStarShip = hNextShip) { - char ship_buf[30]; + char *curName; MASTER_SHIP_INFO *MasterPtr; MasterPtr = LockMasterShip (&master_q, hStarShip); hNextShip = _GetSuccLink (MasterPtr); - GetStringContents (SetAbsStringTableIndex ( - MasterPtr->ShipInfo.race_strings, 2 - ), (STRINGPTR)ship_buf, FALSE); + curName = GetStringAddress (SetAbsStringTableIndex ( + MasterPtr->ShipInfo.race_strings, 2)); UnlockMasterShip (&master_q, hStarShip); - if (strcmp (built_buf, ship_buf) < 0) + if (strcmp (builtName, curName) < 0) break; } InsertQueue (&master_q, hBuiltShip, hStarShip); diff --git a/sc2/src/uqm/planets/plandata.h b/sc2/src/uqm/planets/plandata.h index 10b8adfb3..8a7d00f82 100644 --- a/sc2/src/uqm/planets/plandata.h +++ b/sc2/src/uqm/planets/plandata.h @@ -194,6 +194,9 @@ enum #define NUMBER_OF_ROCKY_WORLDS (NUMBER_OF_SMALL_ROCKY_WORLDS + NUMBER_OF_LARGE_ROCKY_WORLDS) #define NUMBER_OF_GAS_GIANTS (LAST_GAS_GIANT - FIRST_GAS_GIANT + 1) +// TODO: This struct is highly alignment and padding dependent and +// should not be used! The data is loaded as binary from files and +// cast to this struct. typedef struct { const SIZE level_tab[3]; diff --git a/sc2/src/uqm/planets/planets.h b/sc2/src/uqm/planets/planets.h index a75932d17..94aabee9a 100644 --- a/sc2/src/uqm/planets/planets.h +++ b/sc2/src/uqm/planets/planets.h @@ -199,7 +199,7 @@ struct solarsys_state BYTE max_ship_speed; STRING XlatRef; - STRINGPTR XlatPtr; + void *XlatPtr; COLORMAP OrbitalCMap; SYSTEM_INFO SysInfo;