A toe in the water for the first bits of pure (modern) C++ in the code.

I'll expand it from here.
This commit is contained in:
2024-04-24 18:45:55 -04:00
parent 67fb344596
commit d2c22dc648
6 changed files with 120 additions and 74 deletions
+1 -1
View File
@@ -172,7 +172,7 @@ struct element
static inline BOOLEAN
elementsOfSamePlayer (ELEMENT *ElementPtr0, ELEMENT *ElementPtr1)
{
return ElementPtr0->playerNr == ElementPtr1->playerNr;
return ElementPtr0->playerNr == ElementPtr1->playerNr ? TRUE : FALSE;
}
extern QUEUE disp_q;
+1
View File
@@ -5,3 +5,4 @@ uqm_CFILES="calc.c cargo.c devices.c gentopo.c lander.c orbits.c
uqm_HFILES="elemdata.h generate.h lander.h lifeform.h plandata.h planets.h
scan.h solarsys.h sundata.h"
uqm_CXXFILES="pstarmap-modern.cpp"
+10
View File
@@ -17,8 +17,18 @@
#ifndef GENERATE_H
#define GENERATE_H
#if defined(__cplusplus)
extern "C" {
#endif
struct GenerateFunctions;
typedef struct GenerateFunctions GenerateFunctions;
#if defined(__cplusplus)
}
#endif
#include "types.h"
#include "planets.h"
#include "libs/compiler.h"
+71
View File
@@ -0,0 +1,71 @@
//Copyright Paul Reiche, Fred Ford. 1992-2002
//Edited by ADAM David Alan Martin. 2024
/*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
#include "../starmap.h"
#include "../menustat.h"
#include "../controls.h"
#include "../sis.h"
#include "../sounds.h"
extern "C" bool
DoStarSearch (MENU_STATE *pMS)
{
TEXTENTRY_STATE tes;
STAR_SEARCH_STATE *pss;
bool success;
pss = (STAR_SEARCH_STATE *) HMalloc (sizeof (*pss));
if (!pss)
return FALSE;
pss->SortedStars= (int *) HMalloc( GetStarCount() * sizeof( int * ) );
if (!pss->SortedStars)
{
HFree (pss);
return FALSE;
}
DrawSISMessageEx ("", 0, 0, DSME_SETFR);
pss->pMS = pMS;
pss->LastChangeTime = 0;
pss->Text[0] = '\0';
pss->LastText[0] = '\0';
pss->FirstIndex = -1;
SortStarsOnName (pss);
// text entry setup
tes.Initialized = FALSE;
tes.BaseStr = pss->Text;
tes.MaxSize = sizeof (pss->Text);
tes.CursorPos = 0;
tes.CbParam = pss;
tes.ChangeCallback = OnStarNameChange;
tes.FrameCallback = OnStarNameFrame;
SetMenuSounds (MENU_SOUND_ARROWS, MENU_SOUND_SELECT);
SetDefaultMenuRepeatDelay ();
success = DoTextEntry (&tes);
DrawSISMessageEx (pss->Text, -1, -1, DSME_CLEARFR);
HFree (pss->SortedStars);
HFree (pss);
return success;
}
+3 -73
View File
@@ -797,29 +797,6 @@ UpdateFuelRequirement (void)
DrawStatusMessage (buf);
}
#define STAR_SEARCH_BUFSIZE 256
typedef struct starsearch_state
{
// TODO: pMS field is probably not needed anymore
MENU_STATE *pMS;
UNICODE Text[STAR_SEARCH_BUFSIZE];
UNICODE LastText[STAR_SEARCH_BUFSIZE];
DWORD LastChangeTime;
int FirstIndex;
int CurIndex;
int LastIndex;
BOOLEAN SingleClust;
BOOLEAN SingleMatch;
UNICODE Buffer[STAR_SEARCH_BUFSIZE];
const UNICODE *Prefix;
const UNICODE *Cluster;
int PrefixLen;
int ClusterLen;
int ClusterPos;
int *SortedStars;
} STAR_SEARCH_STATE;
static int
compStarName (const void *ptr1, const void *ptr2)
{
@@ -843,7 +820,7 @@ compStarName (const void *ptr1, const void *ptr2)
return 0;
}
static void
void
SortStarsOnName (STAR_SEARCH_STATE *pSS)
{
int i;
@@ -1092,7 +1069,7 @@ MatchNextStar (STAR_SEARCH_STATE *pSS, BOOLEAN Reset)
}
}
static BOOLEAN
BOOLEAN
OnStarNameChange (TEXTENTRY_STATE *pTES)
{
STAR_SEARCH_STATE *pSS = (STAR_SEARCH_STATE *) pTES->CbParam;
@@ -1134,7 +1111,7 @@ OnStarNameChange (TEXTENTRY_STATE *pTES)
return ret;
}
static BOOLEAN
BOOLEAN
OnStarNameFrame (TEXTENTRY_STATE *pTES)
{
STAR_SEARCH_STATE *pSS = (STAR_SEARCH_STATE *) pTES->CbParam;
@@ -1167,53 +1144,6 @@ OnStarNameFrame (TEXTENTRY_STATE *pTES)
return TRUE;
}
static BOOLEAN
DoStarSearch (MENU_STATE *pMS)
{
TEXTENTRY_STATE tes;
STAR_SEARCH_STATE *pss;
BOOLEAN success;
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);
pss->pMS = pMS;
pss->LastChangeTime = 0;
pss->Text[0] = '\0';
pss->LastText[0] = '\0';
pss->FirstIndex = -1;
SortStarsOnName (pss);
// text entry setup
tes.Initialized = FALSE;
tes.BaseStr = pss->Text;
tes.MaxSize = sizeof (pss->Text);
tes.CursorPos = 0;
tes.CbParam = pss;
tes.ChangeCallback = OnStarNameChange;
tes.FrameCallback = OnStarNameFrame;
SetMenuSounds (MENU_SOUND_ARROWS, MENU_SOUND_SELECT);
SetDefaultMenuRepeatDelay ();
success = DoTextEntry (&tes);
DrawSISMessageEx (pss->Text, -1, -1, DSME_CLEARFR);
HFree (pss->SortedStars);
HFree (pss);
return success;
}
static BOOLEAN
DoMoveCursor (MENU_STATE *pMS)
{
+34
View File
@@ -19,6 +19,8 @@
#include "libs/compiler.h"
#include "planets/planets.h"
#include "uqm/menustat.h"
#include "uqm/controls.h"
#if defined(__cplusplus)
extern "C" {
@@ -37,6 +39,38 @@ extern void GetClusterName (const STAR_DESC *pSD, UNICODE buf[]);
// Defined in plandata.c
extern COUNT GetStarCount (void);
// Star search functions
#define STAR_SEARCH_BUFSIZE 256
typedef struct starsearch_state
{
// TODO: pMS field is probably not needed anymore
MENU_STATE *pMS;
UNICODE Text[STAR_SEARCH_BUFSIZE];
UNICODE LastText[STAR_SEARCH_BUFSIZE];
DWORD LastChangeTime;
int FirstIndex;
int CurIndex;
int LastIndex;
BOOLEAN SingleClust;
BOOLEAN SingleMatch;
UNICODE Buffer[STAR_SEARCH_BUFSIZE];
const UNICODE *Prefix;
const UNICODE *Cluster;
int PrefixLen;
int ClusterLen;
int ClusterPos;
int *SortedStars;
} STAR_SEARCH_STATE;
bool DoStarSearch( MENU_STATE * );
void SortStarsOnName( STAR_SEARCH_STATE * );
BOOLEAN OnStarNameChange( TEXTENTRY_STATE * );
BOOLEAN OnStarNameFrame ( TEXTENTRY_STATE *pTES );
#if defined(__cplusplus)
}
#endif