Skip to content
This repository was archived by the owner on Jan 5, 2024. It is now read-only.

Commit 4dc0765

Browse files
committed
Made ConsoleMan not use forward slash as one of its trigger keys
Cleaned up comments in PresetMan::LoadAllDataModules Cleaned up commented assert in DataModule and added issue link to a todo Cleaned up comments and commented code in Entity.cpp, used Limit when setting RandomWeight, changed tabbing in init list, fixed newline in for loop, fixed returning false instead of int Changed spacing for defines in Entity.h, reorganized ClassInfo members so they match the init list organization, fixed some method comments, added TODO Removed unused Writer(string, bool) constructor
1 parent 55249d0 commit 4dc0765

File tree

6 files changed

+49
-64
lines changed

6 files changed

+49
-64
lines changed

Managers/ConsoleMan.cpp

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -319,7 +319,7 @@ void ConsoleMan::Update()
319319
{
320320
bool inputConsumed = false;
321321

322-
if ((g_UInputMan.FlagCtrlState() && g_UInputMan.KeyPressed(KEY_TILDE)) || (g_UInputMan.FlagCtrlState() && g_UInputMan.KeyPressed(KEY_SLASH)))
322+
if (g_UInputMan.FlagCtrlState() && g_UInputMan.KeyPressed(KEY_TILDE))
323323
{
324324
inputConsumed = true;
325325
if (IsForceVisible())
@@ -388,7 +388,7 @@ void ConsoleMan::Update()
388388
}
389389

390390
// Toggle enabling with traditional tilde key
391-
if (!inputConsumed && (g_UInputMan.KeyPressed(KEY_TILDE) || g_UInputMan.KeyPressed(KEY_SLASH)))
391+
if (!inputConsumed && g_UInputMan.KeyPressed(KEY_TILDE))
392392
{
393393
if (IsEnabled())
394394
{
@@ -422,8 +422,7 @@ void ConsoleMan::Update()
422422
m_pGUIController->Update();
423423

424424
// Remove any junk input that will have been entered by the opening/closing of the console
425-
if (g_UInputMan.KeyPressed(KEY_TILDE) || g_UInputMan.KeyPressed(KEY_SLASH) ||
426-
g_UInputMan.KeyHeld(KEY_TILDE) || g_UInputMan.KeyHeld(KEY_SLASH))
425+
if (g_UInputMan.KeyPressed(KEY_TILDE) ||g_UInputMan.KeyHeld(KEY_TILDE))
427426
{
428427
// Restore any text being worked on in the input, as the box keeps getting junk added to it
429428
m_pInputTextBox->SetText(m_LastInputString);

Managers/PresetMan.cpp

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -206,11 +206,8 @@ bool PresetMan::LoadAllDataModules() {
206206
moduleID = GetModuleID(moduleInfo.name);
207207
// Make sure we don't load properties of already loaded official modules
208208
if (strlen(moduleInfo.name) > 0 && (moduleID < 0 || moduleID >= GetOfficialModuleCount()) && string(moduleInfo.name) != "Metagames.rte" && string(moduleInfo.name) != "Scenes.rte") {
209-
// Actually load the unofficial data module
210-
if (!LoadDataModule(string(moduleInfo.name), false, &LoadingGUI::LoadingSplashProgressReport)) {
211-
// LoadDataModule can return false (esp since it may try to load already loaded modules, and that's ok) and shouldn't cause stop
212-
// TODO: Report error and skip loading module.
213-
}
209+
// NOTE: LoadDataModule can return false (especially since it may try to load already loaded modules, which is okay) and shouldn't cause stop, so we can ignore its return value here.
210+
LoadDataModule(string(moduleInfo.name), false, &LoadingGUI::LoadingSplashProgressReport);
214211
}
215212
}
216213
}

System/DataModule.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -321,7 +321,6 @@ namespace RTE {
321321
std::map<std::string, std::list<std::pair<std::string, Entity *>>>::iterator classItr = m_TypeMap.find((type.empty() || type == "All") ? "Entity" : type);
322322

323323
if (classItr != m_TypeMap.end()) {
324-
//RTEAssert(!(type.empty() || type == "All") && !classItr->second.empty(), "DataModule has class entry without instances in its map!?");
325324
RTEAssert(!classItr->second.empty(), "DataModule has class entry without instances in its map!?");
326325
for (std::list<std::pair<std::string, Entity *>>::iterator instItr = classItr->second.begin(); instItr != classItr->second.end(); ++instItr) {
327326
if (instItr->second->IsInGroup(group)) {
@@ -382,6 +381,7 @@ namespace RTE {
382381

383382
// TODO: This method is almost identical to GetEntityPreset, except it doesn't return a const Entity *.
384383
// Investigate if the latter needs to return const (based on what's using it) and if not, get rid of this and replace its uses. At the very least, consider renaming this
384+
// See https://github.com/cortex-command-community/Cortex-Command-Community-Project-Source/issues/87
385385
Entity * DataModule::GetEntityIfExactType(const std::string &exactType, const std::string &instanceName) {
386386
if (exactType.empty() || instanceName == "None" || instanceName.empty()) {
387387
return 0;

System/Entity.cpp

Lines changed: 14 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,7 @@ namespace RTE {
2424
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
2525

2626
int Entity::Create() {
27-
// Special "All" group that includes.. all
28-
m_Groups.push_back("All");
27+
m_Groups.push_back("All"); // Special "All" group that includes.. all
2928
return 0;
3029
}
3130

@@ -53,15 +52,8 @@ namespace RTE {
5352

5453
if (pPreset) {
5554
pPreset->Clone(this);
56-
// Couldn't find the preset to copy from? Then just read it in as an original
5755
} else {
58-
/* Just read as an original preset instead of failing
59-
char error[256];
60-
sprintf_s(error, sizeof(error), "Referring to an instance ('%s') to copy from that hasn't been defined!", refName.c_str());
61-
reader.ReportError(error);
62-
return -1;
63-
*/
64-
// Do report this error to the console though!
56+
// If we couldn't find the preset to copy from, read it as an original but report the problem in the console
6557
g_ConsoleMan.PrintString("ERROR: Couldn't find the preset '" + refName + "' accessed in " + reader.GetCurrentFilePath() + " at line " + reader.GetCurrentFileLineString());
6658

6759
// Preset name might have "[ModuleName]/" preceding it, detect it here and select proper module!
@@ -86,8 +78,7 @@ namespace RTE {
8678
reader >> m_PresetDescription;
8779
} else if (propName == "RandomWeight") {
8880
reader >> m_RandomWeight;
89-
if (m_RandomWeight < 0) { m_RandomWeight = 0; }
90-
if (m_RandomWeight > 100) { m_RandomWeight = 100; }
81+
m_RandomWeight = Limit(m_RandomWeight, 100, 0);
9182
} else if (propName == "AddToGroup") {
9283
std::string newGroup;
9384
reader >> newGroup;
@@ -167,8 +158,7 @@ namespace RTE {
167158
if (m_DefinedInModule == whichModule) {
168159
return false;
169160
}
170-
// This now a unique snowflake
171-
m_IsOriginalPreset = true;
161+
m_IsOriginalPreset = true; // This now a unique snowflake
172162
m_DefinedInModule = whichModule;
173163
return true;
174164
}
@@ -205,9 +195,8 @@ namespace RTE {
205195
Reader & operator>>(Reader &reader, Entity &operand) {
206196
// Get this before reading Entity, since if it's the last one in its datafile, the stream will show the parent file instead
207197
std::string objectFilePath = reader.GetCurrentFilePath();
208-
// Read the Entity from the file
198+
// Read the Entity from the file and try to add it to PresetMan
209199
operand.Create(reader);
210-
// Try to add it to the PresetMan
211200
g_PresetMan.AddEntityPreset(&operand, reader.GetReadModuleID(), reader.GetPresetOverwriting(), objectFilePath);
212201

213202
return reader;
@@ -219,9 +208,8 @@ namespace RTE {
219208
if (operand) {
220209
// Get this before reading Entity, since if it's the last one in its datafile, the stream will show the parent file instead
221210
std::string objectFilePath = reader.GetCurrentFilePath();
222-
// Read the Entity from the file
211+
// Read the Entity from the file and try to add it to PresetMan
223212
operand->Create(reader);
224-
// Try to add it to the PresetMan
225213
g_PresetMan.AddEntityPreset(operand, reader.GetReadModuleID(), reader.GetPresetOverwriting(), objectFilePath);
226214
} else {
227215
reader.ReportError("Tried to read an .ini file into a null Entity pointer!");
@@ -238,11 +226,11 @@ namespace RTE {
238226
m_fpDeallocate(fpDeallocFunc),
239227
m_fpNewInstance(fpNewFunc),
240228
m_NextClass(m_sClassHead) {
241-
m_sClassHead = this;
229+
m_sClassHead = this;
242230

243-
m_AllocatedPool.clear();
244-
m_PoolAllocBlockCount = allocBlockCount > 0 ? allocBlockCount : 10;
245-
}
231+
m_AllocatedPool.clear();
232+
m_PoolAllocBlockCount = allocBlockCount > 0 ? allocBlockCount : 10;
233+
}
246234

247235
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
248236

@@ -284,8 +272,9 @@ namespace RTE {
284272

285273
// If concrete class, fill up the pool with pre-allocated memory blocks the size of the type
286274
if (m_fpAllocate && fillAmount > 0) {
287-
// As many as we're asked to make
288-
for (int i = 0; i < fillAmount; ++i) { m_AllocatedPool.push_back(m_fpAllocate()); }
275+
for (int i = 0; i < fillAmount; ++i) {
276+
m_AllocatedPool.push_back(m_fpAllocate());
277+
}
289278
}
290279
}
291280

@@ -313,7 +302,7 @@ namespace RTE {
313302

314303
int Entity::ClassInfo::ReturnPoolMemory(void *pReturnedMemory) {
315304
if (!pReturnedMemory) {
316-
return false;
305+
return 0;
317306
}
318307
m_AllocatedPool.push_back(pReturnedMemory);
319308

System/Entity.h

Lines changed: 29 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -11,41 +11,41 @@ namespace RTE {
1111

1212
#pragma region Global Macro Definitions
1313
#define ABSTRACTCLASSINFO(TYPE, PARENT) \
14-
Entity::ClassInfo TYPE::m_sClass(#TYPE, &PARENT::m_sClass);
14+
Entity::ClassInfo TYPE::m_sClass(#TYPE, &PARENT::m_sClass);
1515

1616
#define CONCRETECLASSINFO(TYPE, PARENT, BLOCKCOUNT) \
17-
Entity::ClassInfo TYPE::m_sClass(#TYPE, &PARENT::m_sClass, TYPE::Allocate, TYPE::Deallocate, TYPE::NewInstance, BLOCKCOUNT);
17+
Entity::ClassInfo TYPE::m_sClass(#TYPE, &PARENT::m_sClass, TYPE::Allocate, TYPE::Deallocate, TYPE::NewInstance, BLOCKCOUNT);
1818

1919
#define CONCRETESUBCLASSINFO(TYPE, SUPER, PARENT, BLOCKCOUNT) \
20-
Entity::ClassInfo SUPER::TYPE::m_sClass(#TYPE, &PARENT::m_sClass, SUPER::TYPE::Allocate, SUPER::TYPE::Deallocate, SUPER::TYPE::NewInstance, BLOCKCOUNT);
20+
Entity::ClassInfo SUPER::TYPE::m_sClass(#TYPE, &PARENT::m_sClass, SUPER::TYPE::Allocate, SUPER::TYPE::Deallocate, SUPER::TYPE::NewInstance, BLOCKCOUNT);
2121

2222
/// <summary>
2323
/// Convenience macro to cut down on duplicate ClassInfo methods in classes that extend Entity.
2424
/// </summary>
2525
#define CLASSINFOGETTERS \
26-
const Entity::ClassInfo & GetClass() const { return m_sClass; } \
27-
const std::string & GetClassName() const { return m_sClass.GetName(); }
26+
const Entity::ClassInfo & GetClass() const { return m_sClass; } \
27+
const std::string & GetClassName() const { return m_sClass.GetName(); }
2828

2929
/// <summary>
3030
/// Static method used in conjunction with ClassInfo to allocate an Entity.
3131
/// This function is passed into the constructor of this Entity's static ClassInfo's constructor, so that it can instantiate MovableObjects.
3232
/// </summary>
3333
/// <returns>A pointer to the newly dynamically allocated Entity. Ownership is transferred as well.</returns>
34-
#define ENTITYALLOCATION(TYPE) \
35-
static void * operator new (size_t size) { return TYPE::m_sClass.GetPoolMemory(); } \
36-
static void operator delete (void *pInstance) { TYPE::m_sClass.ReturnPoolMemory(pInstance); } \
37-
static void * operator new (size_t size, void *p) throw() { return p; } \
38-
static void operator delete (void *, void *) throw() { } \
39-
static void * Allocate() { return malloc(sizeof(TYPE)); } \
40-
static void Deallocate(void *pInstance) { free(pInstance); } \
41-
static Entity * NewInstance() { return new TYPE; } \
42-
virtual Entity * Clone(Entity *pCloneTo = 0) const { \
43-
TYPE *pEnt = pCloneTo ? dynamic_cast<TYPE *>(pCloneTo) : new TYPE(); \
44-
RTEAssert(pEnt, "Tried to clone to an incompatible instance!"); \
45-
if (pCloneTo) { pEnt->Destroy(); } \
46-
pEnt->Create(*this); \
47-
return pEnt; \
48-
}
34+
#define ENTITYALLOCATION(TYPE) \
35+
static void * operator new (size_t size) { return TYPE::m_sClass.GetPoolMemory(); } \
36+
static void operator delete (void *pInstance) { TYPE::m_sClass.ReturnPoolMemory(pInstance); } \
37+
static void * operator new (size_t size, void *p) throw() { return p; } \
38+
static void operator delete (void *, void *) throw() { } \
39+
static void * Allocate() { return malloc(sizeof(TYPE)); } \
40+
static void Deallocate(void *pInstance) { free(pInstance); } \
41+
static Entity * NewInstance() { return new TYPE; } \
42+
virtual Entity * Clone(Entity *pCloneTo = 0) const { \
43+
TYPE *pEnt = pCloneTo ? dynamic_cast<TYPE *>(pCloneTo) : new TYPE(); \
44+
RTEAssert(pEnt, "Tried to clone to an incompatible instance!"); \
45+
if (pCloneTo) { pEnt->Destroy(); } \
46+
pEnt->Create(*this); \
47+
return pEnt; \
48+
}
4949
#pragma endregion
5050

5151
/// <summary>
@@ -178,17 +178,17 @@ namespace RTE {
178178
const std::string m_Name; //!< A string with the friendly - formatted name of this ClassInfo.
179179
const ClassInfo *m_pParentInfo; //!< A pointer to the parent ClassInfo.
180180

181+
MemoryAllocate m_fpAllocate; //!< Raw memory allocation for the size of the type this ClassInfo describes.
182+
MemoryDeallocate m_fpDeallocate; //!< Raw memory deallocation for the size of the type this ClassInfo describes.
183+
// TODO: figure out why this doesn't want to work when defined as std::function.
184+
Entity *(*m_fpNewInstance)(); //!< Returns an actual new instance of the type that this describes.
185+
181186
ClassInfo *m_NextClass; //!< Next ClassInfo after this one on aforementioned unordered linked list.
182187

183188
std::vector<void *> m_AllocatedPool; //!< Pool of pre-allocated objects of the type described by this ClassInfo.
184189
int m_PoolAllocBlockCount; //!< The number of instances to fill up the pool of this type with each time it runs dry.
185190
int m_InstancesInUse; //!< The number of allocated instances passed out from the pool.
186191

187-
MemoryAllocate m_fpAllocate; //!< Raw memory allocation for the size of the type this ClassInfo describes.
188-
MemoryDeallocate m_fpDeallocate; //!< Raw memory deallocation for the size of the type this ClassInfo describes.
189-
190-
// TODO: figure out why this doesn't want to work when defined as std::function.
191-
Entity *(*m_fpNewInstance)(); //!< Returns an actual new instance of the type that this describes.
192192

193193
// Forbidding copying
194194
ClassInfo(const ClassInfo &reference) {}
@@ -220,7 +220,7 @@ namespace RTE {
220220
/// </summary>
221221
/// <param name="reader">A Reader that the Serializable will create itself from.</param>
222222
/// <param name="checkType">Whether there is a class name in the stream to check against to make sure the correct type is being read from the stream.</param>
223-
/// <param name="doCreate"></param>
223+
/// <param name="doCreate">Whether to do any additional initialization of the object after reading in all the properties from the Reader. This is done by calling Create().</param>
224224
/// <returns>An error return value signaling success or any particular failure. Anything below 0 is an error signal.</returns>
225225
virtual int Create(Reader &reader, bool checkType = true, bool doCreate = true) { return Serializable::Create(reader, checkType, doCreate); }
226226

@@ -312,7 +312,7 @@ namespace RTE {
312312
const std::string & GetDescription() const { return m_PresetDescription; }
313313

314314
/// <summary>
315-
/// Sets the plain text description of this Entity's data Preset. Should only be a couple of sentences.
315+
/// Sets the plain text description of this Entity's data Preset. Shouldn't be more than a couple of sentences.
316316
/// </summary>
317317
/// <param name="newDesc">A string reference with the preset description.</param>
318318
void SetDescription(const std::string &newDesc) { m_PresetDescription = newDesc; }
@@ -324,7 +324,7 @@ namespace RTE {
324324
std::string GetModuleAndPresetName() const;
325325

326326
/// <summary>
327-
/// Indicated whether this Entity was explicitly given a new instance name upon creation, or if it was just copied/inherited implicitly.
327+
/// Indicates whether this Entity was explicitly given a new instance name upon creation, or if it was just copied/inherited implicitly.
328328
/// </summary>
329329
/// <returns>Whether this Entity was given a new Preset Name upon creation.</returns>
330330
bool IsOriginalPreset() const { return m_IsOriginalPreset; }
@@ -430,6 +430,7 @@ namespace RTE {
430430
bool m_IsOriginalPreset; //!< Whether this is to be added to the PresetMan as an original preset instance.
431431
int m_DefinedInModule; //!< The DataModule ID that this was successfully added to at some point. -1 if not added to anything yet.
432432

433+
//TODO Consider replacing this with an unordered_set. See https://github.com/cortex-command-community/Cortex-Command-Community-Project-Source/issues/88
433434
std::list<std::string> m_Groups; //!< List of all tags associated with this. The groups are used to categorize and organize Entities.
434435
std::string m_LastGroupSearch; //!< Last group search string, for more efficient response on multiple tries for the same group name.
435436
bool m_LastGroupResult; //!< Last group search result, for more efficient response on multiple tries for the same group name.

System/Writer.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ namespace RTE {
2424
/// <param name="filename">Path to the file to open for writing.</param>
2525
/// <param name="append">Whether to append to the file if it exists, or to overwrite it.</param>
2626
Writer(const char *filename, bool append = false) { Clear(); Create(filename, append); }
27-
Writer(std::string filename, bool append = false) { Clear(); Create(filename.c_str(), append); }
2827

2928
/// <summary>
3029
/// Makes the Writer object ready for use.

0 commit comments

Comments
 (0)