diff --git a/sc2/src/uqm/Makeinfo b/sc2/src/uqm/Makeinfo index da2a64879..aaee0cc99 100644 --- a/sc2/src/uqm/Makeinfo +++ b/sc2/src/uqm/Makeinfo @@ -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 " diff --git a/sc2/src/uqm/commglue.h b/sc2/src/uqm/commglue.h index 5a1e440f6..bf04c1b89 100644 --- a/sc2/src/uqm/commglue.h +++ b/sc2/src/uqm/commglue.h @@ -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" diff --git a/sc2/src/uqm/cxxlist.cpp b/sc2/src/uqm/cxxlist.cpp new file mode 100644 index 000000000..253268f55 --- /dev/null +++ b/sc2/src/uqm/cxxlist.cpp @@ -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" diff --git a/sc2/src/uqm/cxxlist.h b/sc2/src/uqm/cxxlist.h new file mode 100644 index 000000000..232a4f707 --- /dev/null +++ b/sc2/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 + +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 diff --git a/sc2/src/uqm/encount.h b/sc2/src/uqm/encount.h index b623a4141..cc3cb9f93 100644 --- a/sc2/src/uqm/encount.h +++ b/sc2/src/uqm/encount.h @@ -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" diff --git a/sc2/src/uqm/encounter.h b/sc2/src/uqm/encounter.h new file mode 100644 index 000000000..877e08c78 --- /dev/null +++ b/sc2/src/uqm/encounter.h @@ -0,0 +1,13 @@ +#pragma once + +#ifdef __cplusplus +extern "C" +{ +#endif + +typedef struct encounter ENCOUNTER; + +#ifdef __cplusplus +} +#endif + diff --git a/sc2/src/uqm/fleetinfo.h b/sc2/src/uqm/fleetinfo.h new file mode 100644 index 000000000..a02a6d48d --- /dev/null +++ b/sc2/src/uqm/fleetinfo.h @@ -0,0 +1,13 @@ +#pragma once + +#ifdef __cplusplus +extern "C" +{ +#endif + +typedef struct FLEET_INFO_t FLEET_INFO; + +#ifdef __cplusplus +} +#endif + diff --git a/sc2/src/uqm/globdata.h b/sc2/src/uqm/globdata.h index 3c6df21dc..b9b183f56 100644 --- a/sc2/src/uqm/globdata.h +++ b/sc2/src/uqm/globdata.h @@ -26,6 +26,8 @@ #include "sis.h" #include "velocity.h" #include "commanim.h" +#include "locdata.h" +#include "cxxlist.h" #include @@ -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 diff --git a/sc2/src/uqm/grpinfo.h b/sc2/src/uqm/grpinfo.h index 65286aa1b..caaa15834 100644 --- a/sc2/src/uqm/grpinfo.h +++ b/sc2/src/uqm/grpinfo.h @@ -33,7 +33,7 @@ extern "C" { typedef HLINK HIPGROUP; -typedef struct +typedef struct IP_GROUP_t { // LINK elements; must be first HIPGROUP pred; diff --git a/sc2/src/uqm/ipgroup.h b/sc2/src/uqm/ipgroup.h new file mode 100644 index 000000000..01faa4d77 --- /dev/null +++ b/sc2/src/uqm/ipgroup.h @@ -0,0 +1,12 @@ +#pragma once + +#ifdef __cplusplus +extern "C" +{ +#endif + +typedef struct IP_GROUP_t IP_GROUP; + +#ifdef __cplusplus +} +#endif diff --git a/sc2/src/uqm/locdata.h b/sc2/src/uqm/locdata.h new file mode 100644 index 000000000..abd0ecf00 --- /dev/null +++ b/sc2/src/uqm/locdata.h @@ -0,0 +1,12 @@ +#pragma once + +#ifdef __cplusplus +extern "C" +{ +#endif + +typedef struct LOCDATA_t LOCDATA; + +#ifdef __cplusplus +} +#endif diff --git a/sc2/src/uqm/races.h b/sc2/src/uqm/races.h index b1a1617f1..4279d738e 100644 --- a/sc2/src/uqm/races.h +++ b/sc2/src/uqm/races.h @@ -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; diff --git a/sc2/src/uqm/shipfragment.h b/sc2/src/uqm/shipfragment.h new file mode 100644 index 000000000..9d887bece --- /dev/null +++ b/sc2/src/uqm/shipfragment.h @@ -0,0 +1,12 @@ +#pragma once + +#ifdef __cplusplus +extern "C" +{ +#endif + +typedef struct SHIP_FRAGMENT_t SHIP_FRAGMENT; + +#ifdef __cplusplus +} +#endif