Dynamically compute the number of stars in the array.

This commit is contained in:
2024-04-24 10:05:20 -04:00
parent 32a1344643
commit bdbd7158b9
7 changed files with 51 additions and 14 deletions
+1 -1
View File
@@ -483,7 +483,7 @@ InterplanetaryTransition (ELEMENT *ElementPtr)
COUNT index;
const POINT portal_pt[] = QUASISPACE_PORTALS_HYPERSPACE_ENDPOINTS;
index = CurStarDescPtr - &star_array[NUM_SOLAR_SYSTEMS + 1];
index = CurStarDescPtr - &star_array[GetStarCount() + 1];
GLOBAL_SIS (log_x) = UNIVERSE_TO_LOGX (portal_pt[index].x);
GLOBAL_SIS (log_y) = UNIVERSE_TO_LOGY (portal_pt[index].y);
+21
View File
@@ -22,6 +22,9 @@
#include "planets/elemdata.h"
// This array has to be sorted in Y coordinate order then X coordinate order.
// Items out of order can cause crashes (better, actually) or "ghost"
// stars in the map that cannot be entered.
STAR_DESC starmap_array[] =
{
// postfix name index (like 'Normae')
@@ -572,6 +575,24 @@ STAR_DESC starmap_array[] =
{{MAX_X_UNIVERSE << 1, MAX_Y_UNIVERSE << 1}, 0, 0, 0, 0},
};
COUNT
GetStarCount( void )
{
static bool ready= false;
static COUNT rv= 0;
while( !ready )
{
if( starmap_array[ rv ].star_pt.x == MAX_X_UNIVERSE << 1
&& starmap_array[ rv ].star_pt.y == MAX_Y_UNIVERSE << 1 ) break;
++rv;
}
ready= true;
return rv;
}
const BYTE element_array[NUMBER_OF_ELEMENTS] =
{
COMMON, /* HYDROGEN */
+14 -7
View File
@@ -331,7 +331,7 @@ DrawStarMap (COUNT race_update, RECT *pClipRect)
}
else
{
SDPtr = &star_array[NUM_SOLAR_SYSTEMS + 1];
SDPtr = &star_array[GetStarCount() + 1];
SetContextForeGroundColor (
BUILD_COLOR (MAKE_RGB15 (0x00, 0x0B, 0x00), 0x6D));
SetContextBackGroundColor (
@@ -817,7 +817,7 @@ typedef struct starsearch_state
int PrefixLen;
int ClusterLen;
int ClusterPos;
int SortedStars[NUM_SOLAR_SYSTEMS];
int *SortedStars;
} STAR_SEARCH_STATE;
static int
@@ -849,10 +849,10 @@ SortStarsOnName (STAR_SEARCH_STATE *pSS)
int i;
int *sorted = pSS->SortedStars;
for (i = 0; i < NUM_SOLAR_SYSTEMS; i++)
for (i = 0; i < GetStarCount(); i++)
sorted[i] = i;
qsort (sorted, NUM_SOLAR_SYSTEMS, sizeof (int), compStarName);
qsort (sorted, GetStarCount(), sizeof (int), compStarName);
}
static void
@@ -917,7 +917,7 @@ SkipStarCluster (int *sortedStars, int istar)
{
int Postfix = star_array[sortedStars[istar]].Postfix;
for (++istar; istar < NUM_SOLAR_SYSTEMS &&
for (++istar; istar < GetStarCount() &&
star_array[sortedStars[istar]].Postfix == Postfix;
++istar)
;
@@ -932,7 +932,7 @@ FindNextStarIndex (STAR_SEARCH_STATE *pSS, int from, BOOLEAN WithinClust)
if (!pSS->Cluster)
return -1; // nothing to search for
for (i = from; i < NUM_SOLAR_SYSTEMS; ++i)
for (i = from; i < GetStarCount(); ++i)
{
STAR_DESC *SDPtr = &star_array[pSS->SortedStars[i]];
UNICODE FullName[STAR_SEARCH_BUFSIZE];
@@ -1009,7 +1009,7 @@ FindNextStarIndex (STAR_SEARCH_STATE *pSS, int from, BOOLEAN WithinClust)
break; // found one
}
return (i < NUM_SOLAR_SYSTEMS) ? i : -1;
return (i < GetStarCount()) ? i : -1;
}
static void
@@ -1177,6 +1177,12 @@ DoStarSearch (MENU_STATE *pMS)
pss = HMalloc (sizeof (*pss));
if (!pss)
return FALSE;
pss->SortedStars= HMalloc( GetStarCount() * sizeof( int * ) );
if (!pss->SortedStars)
{
HFree (pss);
return FALSE;
}
DrawSISMessageEx ("", 0, 0, DSME_SETFR);
@@ -1202,6 +1208,7 @@ DoStarSearch (MENU_STATE *pMS)
DrawSISMessageEx (pss->Text, -1, -1, DSME_CLEARFR);
HFree (pss->SortedStars);
HFree (pss);
return success;
+2 -2
View File
@@ -36,12 +36,12 @@ FindStar (STAR_DESC *LastSDPtr, POINT *puniverse, SIZE xbounds,
if (GET_GAME_STATE (ARILOU_SPACE_SIDE) <= 1)
{
BaseSDPtr = star_array;
hi = NUM_SOLAR_SYSTEMS - 1;
hi = GetStarCount() - 1;
}
else
{
#define NUM_HYPER_VORTICES 15
BaseSDPtr = &star_array[NUM_SOLAR_SYSTEMS + 1];
BaseSDPtr = &star_array[GetStarCount() + 1];
hi = (NUM_HYPER_VORTICES + 1) - 1;
}
+4 -1
View File
@@ -27,13 +27,16 @@ extern "C" {
extern STAR_DESC *CurStarDescPtr;
extern STAR_DESC *star_array;
#define NUM_SOLAR_SYSTEMS 502
//#define NUM_SOLAR_SYSTEMS 503
extern STAR_DESC* FindStar (STAR_DESC *pLastStar, POINT *puniverse,
SIZE xbounds, SIZE ybounds);
extern void GetClusterName (const STAR_DESC *pSD, UNICODE buf[]);
// Defined in plandata.c
extern COUNT GetStarCount (void);
#if defined(__cplusplus)
}
#endif
+8 -2
View File
@@ -54,8 +54,14 @@ typedef struct GAME_STATE_FILE GAME_STATE_FILE;
#define STARINFO_FILE 0
//"starinfo.dat"
#define STAR_BUFSIZE (NUM_SOLAR_SYSTEMS * sizeof (DWORD) \
+ 3800 * (3 * sizeof (DWORD)))
// Hack for up to 4k star systems (for now)...
// Each system having up to 15 planets with
// up to 5 moons each. This is somewhat
// overkill.... but I don't want to unspool
// all of the C arrays just yet. Memory
// is cheap, so let it get big...
#define STAR_BUFSIZE (4096 * sizeof (DWORD) \
+ 16 * 5 * 4096 * (3 * sizeof (DWORD)))
#define RANDGRPINFO_FILE 1
//"randgrp.dat"
#define RAND_BUFSIZE (4 * 1024)
+1 -1
View File
@@ -568,7 +568,7 @@ forAllStars (void (*callback) (STAR_DESC *, void *), void *arg)
int i;
extern STAR_DESC starmap_array[];
for (i = 0; i < NUM_SOLAR_SYSTEMS; i++)
for (i = 0; i < GetStarCount(); i++)
callback (&starmap_array[i], arg);
}