Get all stuff ready for retiring the QUEUE code.
The replacement isn't too much better... But it's a wrapper around C++ `std::list`, which means C++ code can start to peer into it without needing to make widespread changes to the C code that still works with it. Over time, I can modernize all of the C code into C++ code at whatever pace is needed.
This commit is contained in:
@@ -28,4 +28,5 @@ uqm_HFILES="battlecontrols.h battle.h build.h clock.h cnctdlg.h coderes.h
|
||||
uqm_CXXFILES="
|
||||
gamestate-modern.cpp
|
||||
load-modern.cpp
|
||||
cxxlist.cpp
|
||||
"
|
||||
|
||||
@@ -19,6 +19,7 @@
|
||||
#ifndef UQM_COMMGLUE_H_
|
||||
#define UQM_COMMGLUE_H_
|
||||
|
||||
#include "locdata.h"
|
||||
#include "globdata.h"
|
||||
#include "resinst.h"
|
||||
#include "libs/sound/trackplayer.h"
|
||||
|
||||
@@ -0,0 +1,8 @@
|
||||
#include "uqm/races.h"
|
||||
#include "uqm/grpinfo.h"
|
||||
#include "uqm/encount.h"
|
||||
|
||||
|
||||
// The inclusion causes code gen, because of the define.
|
||||
#define COMPILING_CXX_LIST
|
||||
#include "src/uqm/cxxlist.h"
|
||||
@@ -0,0 +1,241 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "locdata.h"
|
||||
#include "fleetinfo.h"
|
||||
#include "shipfragment.h"
|
||||
#include "encounter.h"
|
||||
#include "ipgroup.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
||||
#include <list>
|
||||
|
||||
extern "C"
|
||||
{
|
||||
#endif
|
||||
|
||||
typedef struct encounter ENCOUNTER;
|
||||
|
||||
#ifdef COMPILING_CXX_LIST
|
||||
#define EXPAND_TEMPLATE_LIST_DEF( type ) \
|
||||
\
|
||||
struct CXXList_##type##_t \
|
||||
{ \
|
||||
std::list< type > data;\
|
||||
std::size_t capacity; \
|
||||
}; \
|
||||
\
|
||||
struct CXXList_##type##_iterator_t \
|
||||
{ \
|
||||
std::list< type >::iterator data;\
|
||||
}; \
|
||||
\
|
||||
\
|
||||
CXXList_##type \
|
||||
newList_##type( std::size_t capacity ) \
|
||||
{ \
|
||||
return new CXXList_##type##_t{ .data{}, .capacity{ capacity } }; \
|
||||
} \
|
||||
\
|
||||
void \
|
||||
deleteList_##type( CXXList_##type l ) \
|
||||
{ \
|
||||
delete l; \
|
||||
} \
|
||||
\
|
||||
void \
|
||||
emplace_back_List_##type( CXXList_##type list ) \
|
||||
{ \
|
||||
list->data.emplace_back(); \
|
||||
} \
|
||||
\
|
||||
std::size_t \
|
||||
size_List_##type( CXXList_##type list ) \
|
||||
{ \
|
||||
return list->data.size(); \
|
||||
} \
|
||||
\
|
||||
std::size_t \
|
||||
capacity_List_##type( CXXList_##type list ) \
|
||||
{ \
|
||||
return list->capacity; \
|
||||
} \
|
||||
\
|
||||
void \
|
||||
push_back_List_##type( CXXList_##type list, type item ) \
|
||||
{ \
|
||||
list->data.push_back( item ); \
|
||||
} \
|
||||
\
|
||||
void \
|
||||
push_front_List_##type( CXXList_##type list, type item ) \
|
||||
{ \
|
||||
list->data.push_front( item ); \
|
||||
} \
|
||||
\
|
||||
void \
|
||||
pop_back_List_##type( CXXList_##type list ) \
|
||||
{ \
|
||||
list->data.pop_back(); \
|
||||
} \
|
||||
\
|
||||
void \
|
||||
pop_front_List_##type( CXXList_##type list ) \
|
||||
{ \
|
||||
list->data.pop_front(); \
|
||||
} \
|
||||
\
|
||||
type * \
|
||||
back_List_##type( CXXList_##type list ) \
|
||||
{ \
|
||||
return &list->data.back(); \
|
||||
} \
|
||||
\
|
||||
type * \
|
||||
front_List_##type( CXXList_##type list ) \
|
||||
{ \
|
||||
return &list->data.front(); \
|
||||
} \
|
||||
\
|
||||
CXXList_##type##_iterator \
|
||||
beginList_##type( CXXList_##type list ) \
|
||||
{ \
|
||||
return new CXXList_##type##_iterator_t( list->data.begin() ); \
|
||||
} \
|
||||
\
|
||||
CXXList_##type##_iterator \
|
||||
endList_##type( CXXList_##type list ) \
|
||||
{ \
|
||||
return new CXXList_##type##_iterator_t( list->data.end() ); \
|
||||
} \
|
||||
\
|
||||
type * \
|
||||
derefIterator_##type( CXXList_##type##_iterator iter ) \
|
||||
{ \
|
||||
return &*iter->data; \
|
||||
} \
|
||||
\
|
||||
void \
|
||||
nextIterator_##type( CXXList_##type##_iterator iter ) \
|
||||
{ \
|
||||
++iter->data; \
|
||||
} \
|
||||
\
|
||||
void \
|
||||
prevIterator_##type( CXXList_##type##_iterator iter ) \
|
||||
{ \
|
||||
--iter->data; \
|
||||
} \
|
||||
\
|
||||
void \
|
||||
removeIterator_##type( CXXList_##type list, CXXList_##type##_iterator iter ) \
|
||||
{ \
|
||||
list->data.erase( iter->data ); \
|
||||
} \
|
||||
\
|
||||
void \
|
||||
deleteIterator_##type( CXXList_##type##_iterator iter ) \
|
||||
{ \
|
||||
delete iter; \
|
||||
} \
|
||||
\
|
||||
bool \
|
||||
eqIterator_##type( CXXList_##type##_iterator lhs, CXXList_##type##_iterator rhs ) \
|
||||
{ \
|
||||
return lhs->data == rhs->data; \
|
||||
}
|
||||
|
||||
#else
|
||||
|
||||
#define EXPAND_TEMPLATE_LIST_DEF( type ) /* Nothing */
|
||||
|
||||
#endif
|
||||
|
||||
// The purpose of this List is to replace displist's macro-driven
|
||||
// linked-list system with C++ STL's `std::list`. `CXXList *` is
|
||||
// just a pointer to a struct with four members,
|
||||
// `std::list< std::shared_ptr< void > >`. The deleter of the
|
||||
// shared ptr is put in the second member, which is the deleter
|
||||
// passed when the list is constructed. The fourth member is
|
||||
// the capacity. The third member is the allocator function.
|
||||
//
|
||||
// Note that capacity is voluntarily enforced -- it's just
|
||||
// an integer along for the ride.
|
||||
//
|
||||
// This permits C++ code to just start working with these lists
|
||||
// right away, although it requires using some nasty casting.
|
||||
//
|
||||
// I'm doing this so that the operations on lists have a precise
|
||||
// 1:1 relationship with STL operations. This permits eventual
|
||||
// simpler translation to C++.
|
||||
|
||||
#define DEFINE_TEMPLATE_LIST_TYPE( type ) \
|
||||
struct hack__;\
|
||||
typedef struct CXXList_##type##_t *CXXList_##type; \
|
||||
\
|
||||
typedef struct CXXList_##type##_iterator_t *CXXList_##type##_iterator; \
|
||||
\
|
||||
CXXList_##type newList_##type( size_t capacity ); \
|
||||
\
|
||||
void deleteList_##type( CXXList_##type list ); \
|
||||
\
|
||||
/* `std::list::emplace_back()` (No arguments).... */ \
|
||||
void emplace_back_List_##type( CXXList_##type list ); \
|
||||
\
|
||||
size_t size_List_##type( CXXList_##type list ); \
|
||||
size_t capacity_List_##type( CXXList_##type list ); \
|
||||
\
|
||||
void push_back_List_##type( CXXList_##type list, type item ); \
|
||||
void push_front_List_##type( CXXList_##type list, type item ); \
|
||||
\
|
||||
void pop_back_List_##type( CXXList_##type list ); \
|
||||
void pop_front_List_##type( CXXList_##type list ); \
|
||||
\
|
||||
/* std::list::back */ \
|
||||
type *back_List_##type( CXXList_##type list ); \
|
||||
\
|
||||
type *front_List_##type( CXXList_##type list ); \
|
||||
\
|
||||
\
|
||||
type *derefIterator_##type( CXXList_##type##_iterator ); \
|
||||
\
|
||||
void nextIterator_##type( CXXList_##type##_iterator ); \
|
||||
void prevIterator_##type( CXXList_##type##_iterator ); \
|
||||
void removeIterator_##type( CXXList_##type, CXXList_##type##_iterator ); \
|
||||
void deleteIterator_##type( CXXList_##type##_iterator ); \
|
||||
\
|
||||
bool eqIterator_##type( CXXList_##type##_iterator, CXXList_##type##_iterator ); \
|
||||
\
|
||||
CXXList_##type##_iterator beginList_##type( CXXList_##type ); \
|
||||
CXXList_##type##_iterator endList_##type( CXXList_##type ); \
|
||||
\
|
||||
EXPAND_TEMPLATE_LIST_DEF( type ) /* Only in the def file */
|
||||
|
||||
// Define the list types here:
|
||||
|
||||
DEFINE_TEMPLATE_LIST_TYPE( FLEET_INFO );
|
||||
DEFINE_TEMPLATE_LIST_TYPE( SHIP_FRAGMENT );
|
||||
DEFINE_TEMPLATE_LIST_TYPE( IP_GROUP );
|
||||
DEFINE_TEMPLATE_LIST_TYPE( ENCOUNTER );
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
||||
|
||||
#endif
|
||||
@@ -20,7 +20,6 @@
|
||||
#define UQM_ENCOUNT_H_
|
||||
|
||||
typedef struct brief_ship_info BRIEF_SHIP_INFO;
|
||||
typedef struct encounter ENCOUNTER;
|
||||
|
||||
// XXX: temporary, for CONVERSATION
|
||||
#include "commglue.h"
|
||||
|
||||
@@ -0,0 +1,13 @@
|
||||
#pragma once
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
{
|
||||
#endif
|
||||
|
||||
typedef struct encounter ENCOUNTER;
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -0,0 +1,13 @@
|
||||
#pragma once
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
{
|
||||
#endif
|
||||
|
||||
typedef struct FLEET_INFO_t FLEET_INFO;
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -26,6 +26,8 @@
|
||||
#include "sis.h"
|
||||
#include "velocity.h"
|
||||
#include "commanim.h"
|
||||
#include "locdata.h"
|
||||
#include "cxxlist.h"
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
@@ -96,7 +98,7 @@ typedef DWORD LDAS_FLAGS;
|
||||
#define LDASF_NONE ((LDAS_FLAGS) 0 )
|
||||
#define LDASF_USE_ALTERNATE ((LDAS_FLAGS)(1 << 0))
|
||||
|
||||
typedef struct
|
||||
struct LOCDATA_t
|
||||
{
|
||||
void (*init_encounter_func) (void);
|
||||
/* Called when entering communications */
|
||||
@@ -138,7 +140,7 @@ typedef struct
|
||||
MUSIC_REF AlienSong;
|
||||
STRING ConversationPhrases;
|
||||
|
||||
} LOCDATA;
|
||||
};
|
||||
|
||||
enum
|
||||
{
|
||||
@@ -994,6 +996,7 @@ typedef struct
|
||||
VELOCITY_DESC velocity;
|
||||
|
||||
DWORD BattleGroupRef;
|
||||
//CXXList_FLEET_INFO avail_race_q;
|
||||
QUEUE avail_race_q;
|
||||
/* List of all the races in the game with information
|
||||
* about their ships, and what player knows about their
|
||||
|
||||
@@ -33,7 +33,7 @@ extern "C" {
|
||||
|
||||
typedef HLINK HIPGROUP;
|
||||
|
||||
typedef struct
|
||||
typedef struct IP_GROUP_t
|
||||
{
|
||||
// LINK elements; must be first
|
||||
HIPGROUP pred;
|
||||
|
||||
@@ -0,0 +1,12 @@
|
||||
#pragma once
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
{
|
||||
#endif
|
||||
|
||||
typedef struct IP_GROUP_t IP_GROUP;
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
@@ -0,0 +1,12 @@
|
||||
#pragma once
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
{
|
||||
#endif
|
||||
|
||||
typedef struct LOCDATA_t LOCDATA;
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
+2
-2
@@ -300,7 +300,7 @@ LockStarShip (const QUEUE *pq, HSTARSHIP h)
|
||||
|
||||
typedef HLINK HSHIPFRAG;
|
||||
|
||||
typedef struct
|
||||
typedef struct SHIP_FRAGMENT_t
|
||||
{
|
||||
SHIP_BASE_COMMON;
|
||||
|
||||
@@ -336,7 +336,7 @@ LockShipFrag (const QUEUE *pq, HSHIPFRAG h)
|
||||
|
||||
typedef HLINK HFLEETINFO;
|
||||
|
||||
typedef struct
|
||||
typedef struct FLEET_INFO_t
|
||||
{
|
||||
// LINK elements; must be first
|
||||
HFLEETINFO pred;
|
||||
|
||||
@@ -0,0 +1,12 @@
|
||||
#pragma once
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
{
|
||||
#endif
|
||||
|
||||
typedef struct SHIP_FRAGMENT_t SHIP_FRAGMENT;
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
Reference in New Issue
Block a user