Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 10 additions & 6 deletions Core/GameEngine/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ set(GAMEENGINE_SRC
Include/Common/GameDefines.h
# Include/Common/GameEngine.h
# Include/Common/GameLOD.h
# Include/Common/GameMemory.h
Include/Common/GameMemory.h
Include/Common/GameMusic.h
Include/Common/GameSounds.h
# Include/Common/GameSpyMiscPreferences.h
Expand Down Expand Up @@ -646,13 +646,13 @@ set(GAMEENGINE_SRC
# Source/Common/System/FunctionLexicon.cpp
# Source/Common/System/GameCommon.cpp
#Source/Common/System/GameMemory.cpp # is conditionally appended
#Source/Common/System/GameMemoryInit.cpp # is conditionally appended
# Source/Common/System/GameType.cpp
# Source/Common/System/Geometry.cpp
# Source/Common/System/KindOf.cpp
# Source/Common/System/List.cpp
Source/Common/System/LocalFile.cpp
Source/Common/System/LocalFileSystem.cpp
#Source/Common/System/MemoryInit.cpp # is conditionally appended
# Source/Common/System/ObjectStatusTypes.cpp
# Source/Common/System/QuotedPrintable.cpp
# Source/Common/System/Radar.cpp
Expand Down Expand Up @@ -1139,14 +1139,18 @@ set(GAMEENGINE_SRC
if(RTS_GAMEMEMORY_ENABLE)
# Uses the original Game Memory implementation.
list(APPEND GAMEENGINE_SRC
# Source/Common/System/GameMemory.cpp
# Source/Common/System/MemoryInit.cpp
Source/Common/System/GameMemory.cpp
Source/Common/System/GameMemoryInit.cpp
Source/Common/System/GameMemoryInitDMA_Generals.inl
Source/Common/System/GameMemoryInitDMA_GeneralsMD.inl
Source/Common/System/GameMemoryInitPools_Generals.inl
Source/Common/System/GameMemoryInitPools_GeneralsMD.inl
)
else()
# Uses the null implementation when disabled.
list(APPEND GAMEENGINE_SRC
# Source/Common/System/GameMemoryNull.cpp
# Include/Common/GameMemoryNull.h
Source/Common/System/GameMemoryNull.cpp
Include/Common/GameMemoryNull.h
)
endif()

Expand Down
8 changes: 8 additions & 0 deletions Core/GameEngine/Include/Common/GameDefines.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,3 +59,11 @@
#ifndef ENABLE_FILESYSTEM_EXISTENCE_CACHE
#define ENABLE_FILESYSTEM_EXISTENCE_CACHE (1)
#endif

// Enable obsolete code. This mainly refers to code that existed in Generals but was removed in GeneralsMD.
// Disable and remove this when Generals and GeneralsMD are merged.
#if RTS_GENERALS
#ifndef USE_OBSOLETE_GENERALS_CODE
#define USE_OBSOLETE_GENERALS_CODE (1)
#endif
#endif
154 changes: 154 additions & 0 deletions Core/GameEngine/Source/Common/System/GameMemoryInit.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,154 @@
/*
** Command & Conquer Generals Zero Hour(tm)
** Copyright 2025 Electronic Arts Inc.
**
** 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 3 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, see <http://www.gnu.org/licenses/>.
*/

////////////////////////////////////////////////////////////////////////////////
// //
// (c) 2001-2003 Electronic Arts Inc. //
// //
////////////////////////////////////////////////////////////////////////////////

// FILE: MemoryInit.cpp
//-----------------------------------------------------------------------------
//
// Westwood Studios Pacific.
//
// Confidential Information
// Copyright (C) 2001 - All Rights Reserved
//
//-----------------------------------------------------------------------------
//
// Project: RTS3
//
// File name: MemoryInit.cpp
//
// Created: Steven Johnson, August 2001
//
// Desc: Memory manager
//
// ----------------------------------------------------------------------------
#include "PreRTS.h" // This must go first in EVERY cpp file int the GameEngine

// SYSTEM INCLUDES

// USER INCLUDES
#include "Lib/BaseType.h"
#include "Common/GameMemory.h"

struct PoolSizeRec
{
const char* name;
Int initial;
Int overflow;
};

#if RTS_GENERALS
#include "GameMemoryInitDMA_Generals.inl"
#include "GameMemoryInitPools_Generals.inl"
#elif RTS_ZEROHOUR
#include "GameMemoryInitDMA_GeneralsMD.inl"
#include "GameMemoryInitPools_GeneralsMD.inl"
#endif

//-----------------------------------------------------------------------------
void userMemoryManagerGetDmaParms(Int *numSubPools, const PoolInitRec **pParms)
{
*numSubPools = ARRAY_SIZE(DefaultDMA);
*pParms = DefaultDMA;
}

//-----------------------------------------------------------------------------
void userMemoryAdjustPoolSize(const char *poolName, Int& initialAllocationCount, Int& overflowAllocationCount)
{
if (initialAllocationCount > 0)
return;

for (const PoolSizeRec* p = PoolSizes; p->name != NULL; ++p)
{
if (strcmp(p->name, poolName) == 0)
{
initialAllocationCount = p->initial;
overflowAllocationCount = p->overflow;
return;
}
}

DEBUG_CRASH(("Initial size for pool %s not found -- you should add it to MemoryInit.cpp",poolName));
}

//-----------------------------------------------------------------------------
static Int roundUpMemBound(Int i)
{
const int MEM_BOUND_ALIGNMENT = 4;

if (i < MEM_BOUND_ALIGNMENT)
return MEM_BOUND_ALIGNMENT;
else
return (i + (MEM_BOUND_ALIGNMENT-1)) & ~(MEM_BOUND_ALIGNMENT-1);
}

//-----------------------------------------------------------------------------
void userMemoryManagerInitPools()
{
// note that we MUST use stdio stuff here, and not the normal game file system
// (with bigfile support, etc), because that relies on memory pools, which
// aren't yet initialized properly! so rely ONLY on straight stdio stuff here.
// (not even AsciiString. thanks.)

// since we're called prior to main, the cur dir might not be what
// we expect. so do it the hard way.
char buf[_MAX_PATH];
::GetModuleFileName(NULL, buf, sizeof(buf));
char* pEnd = buf + strlen(buf);
while (pEnd != buf)
{
if (*pEnd == '\\')
{
*pEnd = 0;
break;
}
--pEnd;
}
strcat(buf, "\\Data\\INI\\MemoryPools.ini");

FILE* fp = fopen(buf, "r");
if (fp)
{
char poolName[256];
int initial, overflow;
while (fgets(buf, _MAX_PATH, fp))
{
if (buf[0] == ';')
continue;
if (sscanf(buf, "%s %d %d", poolName, &initial, &overflow ) == 3)
{
for (PoolSizeRec* p = PoolSizes; p->name != NULL; ++p)
{
if (stricmp(p->name, poolName) == 0)
{
// currently, these must be multiples of 4. so round up.
p->initial = roundUpMemBound(initial);
p->overflow = roundUpMemBound(overflow);
break; // from for-p
}
}
}
}
fclose(fp);
}
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/*
** Command & Conquer Generals(tm)
** Copyright 2025 TheSuperHackers
**
** 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 3 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, see <http://www.gnu.org/licenses/>.
*/

static const PoolInitRec DefaultDMA[] =
{
// name, allocSize, initialCount, overflowCount
{ "dmaPool_16", 16, 65536, 1024 },
{ "dmaPool_32", 32, 150000, 1024 },
{ "dmaPool_64", 64, 60000, 1024 },
{ "dmaPool_128", 128, 32768, 1024 },
{ "dmaPool_256", 256, 8192, 1024 },
{ "dmaPool_512", 512, 8192, 1024 },
{ "dmaPool_1024", 1024, 24000, 1024 }
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/*
** Command & Conquer Generals Zero Hour(tm)
** Copyright 2025 TheSuperHackers
**
** 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 3 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, see <http://www.gnu.org/licenses/>.
*/

static const PoolInitRec DefaultDMA[] =
{
// name, allocSize, initialCount, overflowCount
{ "dmaPool_16", 16, 130000, 10000 },
{ "dmaPool_32", 32, 250000, 10000 },
{ "dmaPool_64", 64, 100000, 10000 },
{ "dmaPool_128", 128, 80000, 10000 },
{ "dmaPool_256", 256, 20000, 5000 },
{ "dmaPool_512", 512, 16000, 5000 },
{ "dmaPool_1024", 1024, 6000, 1024 }
};
Loading
Loading