Skip to content

Commit

Permalink
Merge pull request #151 from caveman2cosmos/graphics-paging-v2
Browse files Browse the repository at this point in the history
Graphics Paging v2
  • Loading branch information
billw2012 committed Sep 15, 2019
2 parents 958fcad + ea3daa1 commit 8d73096
Show file tree
Hide file tree
Showing 14 changed files with 1,201 additions and 627 deletions.
51 changes: 51 additions & 0 deletions Assets/XML/GlobalDefines.xml
Expand Up @@ -22,11 +22,62 @@
<iDefineIntVal>100</iDefineIntVal>
</Define>

<!-- GRAPHICS PAGING OPTIONS -->

<!-- Start paging out if memory exceeds this amount (in KB) -->
<Define>
<DefineName>MAX_DESIRED_MEMORY_USED</DefineName>
<iDefineIntVal>1835008</iDefineIntVal>
</Define>

<!-- If specified, instead of MAX_DESIRED_MEMORY_USED, a set of test
allocations will be performed to test for low memory conditions -->
<!-- Size of each test allocation -->
<!-- <Define>
<DefineName>PAGING_TEST_ALLOC</DefineName>
<iDefineIntVal>10240</iDefineIntVal>
</Define> -->
<!-- Number of test allocations -->
<!-- <Define>
<DefineName>PAGING_TEST_ALLOC_NUM</DefineName>
<iDefineIntVal>5</iDefineIntVal>
</Define> -->

<!-- Maximum amount of time in a frame that can be spent on paging operations.
Higher values mean faster paging in at the expense of more stuttering.
-->
<Define>
<DefineName>MAX_PAGING_FRAME_TIME_MS</DefineName>
<iDefineIntVal>100</iDefineIntVal>
</Define>
<!-- Distance in tiles at which to page in different components -->
<Define>
<DefineName>PAGE_IN_DIST_SYMBOLS</DefineName>
<iDefineIntVal>100</iDefineIntVal>
</Define>
<Define>
<DefineName>PAGE_IN_DIST_FEATURES</DefineName>
<iDefineIntVal>5</iDefineIntVal>
</Define>
<Define>
<DefineName>PAGE_IN_DIST_RIVER</DefineName>
<iDefineIntVal>40</iDefineIntVal>
</Define>
<Define>
<DefineName>PAGE_IN_DIST_ROUTE</DefineName>
<iDefineIntVal>100</iDefineIntVal>
</Define>
<Define>
<DefineName>PAGE_IN_DIST_UNIT</DefineName>
<iDefineIntVal>15</iDefineIntVal>
</Define>
<Define>
<DefineName>PAGE_IN_DIST_CITY</DefineName>
<iDefineIntVal>15</iDefineIntVal>
</Define>

<!-- GRAPHICS PAGING OPTIONS END -->

<!--
Default uses the normal tag for the language set in Civ4's option dialog.
All tags used in the text files are possible with English used as fallback when the chosen language is not available for some text.
Expand Down
5 changes: 5 additions & 0 deletions Sources/C2C (VS2019).vcxproj
Expand Up @@ -120,6 +120,7 @@
<ItemGroup>
<ClCompile Include="CvAllocator.cpp" />
<ClCompile Include="CvAllocator.h" />
<ClCompile Include="CvPlotPaging.cpp" />
<ClCompile Include="CyPlayerInterface3.cpp" />
<ClCompile Include="_precompile.cpp" />
<ClCompile Include="BetterBTSAI.cpp" />
Expand Down Expand Up @@ -263,6 +264,8 @@
</ItemGroup>
<ItemGroup>
<ClInclude Include="BetterBTSAI.h" />
<ClInclude Include="CvPlotPaging.h" />
<ClInclude Include="EnumFlags.h" />
<ClInclude Include="idinfo_iterator.h" />
<ClInclude Include="CvMapExternal.h" />
<ClInclude Include="CvMapInterfaceBase.h" />
Expand Down Expand Up @@ -306,6 +309,8 @@
<ClInclude Include="CvDLLUtilityIFaceBase.h" />
<ClInclude Include="CvDLLWidgetData.h" />
<ClInclude Include="CvDLLXMLIFaceBase.h" />
<ClInclude Include="NiPoint.h" />
<ClInclude Include="Stopwatch.h" />
<ClInclude Include="wchar_utils.h" />
<ClInclude Include="CvEnums.h" />
<ClInclude Include="CvEventReporter.h" />
Expand Down
15 changes: 15 additions & 0 deletions Sources/C2C (VS2019).vcxproj.filters
Expand Up @@ -441,6 +441,9 @@
<ClCompile Include="CvAllocator.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="CvPlotPaging.cpp">
<Filter>Source Files</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="BetterBTSAI.h">
Expand Down Expand Up @@ -851,6 +854,18 @@
<ClInclude Include="idinfo_iterator.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="Stopwatch.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="EnumFlags.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="NiPoint.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="CvPlotPaging.h">
<Filter>Header Files</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<ResourceCompile Include="CvGameCoreDLL.rc">
Expand Down
2 changes: 1 addition & 1 deletion Sources/CvCity.cpp
Expand Up @@ -21793,7 +21793,7 @@ class VisibleBuildingComparator
void CvCity::getVisibleBuildings(std::list<BuildingTypes>& kChosenVisible, int& iChosenNumGenerics)
{

if ( !plot()->shouldHaveFullGraphics() )
if ( !plot()->isGraphicsRequiredVisible(ECvPlotGraphics::CITY) )
{
iChosenNumGenerics = 0;
return;
Expand Down
66 changes: 3 additions & 63 deletions Sources/CvGame.cpp
Expand Up @@ -31,9 +31,6 @@ CvGame::CvGame()
: m_GameObject()
, m_Properties(this)
, m_iChokePointCalculationVersion(0)
, m_iLastLookatX(-1)
, m_iLastLookatY(-1)
, m_bWasGraphicsPagingEnabled(false)
, m_eCurrentMap(MAP_INITIAL)

{
Expand Down Expand Up @@ -1183,9 +1180,8 @@ void CvGame::reset(HandicapTypes eHandicap, bool bConstructorCall)
m_lastGraphicUpdateRequestTickCount = -1;

m_plotGroupHashesInitialized = false;
m_bWasGraphicsPagingEnabled = false;
m_iLastLookatX = -1;
m_iLastLookatY = -1;

CvPlotPaging::ResetPaging();
}


Expand Down Expand Up @@ -2647,7 +2643,6 @@ int CvGame::getTeamClosenessScore(int** aaiDistances, int* aiStartingLocs)
return iScore;
}


void CvGame::update()
{
MEMORY_TRACE_FUNCTION();
Expand All @@ -2666,62 +2661,7 @@ void CvGame::update()

startProfilingDLL(false);

CvPlot* lookatPlot = gDLL->getInterfaceIFace()->getLookAtPlot();
if ( lookatPlot != NULL )
{
// Sample th BUG setting in the main thread on entry to game update here (it requires a Python call
// so we don't want it happening in background, or more frequently than once per turn slice)
bool bPagingEnabled = getBugOptionBOOL("MainInterface__EnableGraphicalPaging", true);
GC.setGraphicalDetailPagingEnabled(bPagingEnabled);

if ( m_bWasGraphicsPagingEnabled != bPagingEnabled)
{
for(int iI = 0; iI < GC.getMapINLINE().numPlotsINLINE(); iI++)
{
CvPlot* pPlot = GC.getMapINLINE().plotByIndexINLINE(iI);
if ( pPlot != NULL )
{
if ( m_bWasGraphicsPagingEnabled )
{
pPlot->setShouldHaveFullGraphics(true);
}
else
{
pPlot->setShouldHaveFullGraphics(false);
}
}
}
}

m_bWasGraphicsPagingEnabled = bPagingEnabled;

if ( GC.getGraphicalDetailPagingEnabled() )
{
if ( (m_iLastLookatX != lookatPlot->getX_INLINE() || m_iLastLookatY != lookatPlot->getY_INLINE()) )
{
int pageInRange = GC.getGraphicalDetailPageInRange();
CvPlot::notePageRenderStart((pageInRange*2+1)*(pageInRange*2+1));

for(int iX = -pageInRange; iX <= pageInRange; iX++)
{
for(int iY = -pageInRange; iY <= pageInRange; iY++)
{
CvPlot* pPlot = plotXY(lookatPlot->getX_INLINE(),lookatPlot->getY_INLINE(),iX,iY);

if ( pPlot != NULL )
{
pPlot->setShouldHaveFullGraphics(true);
}
}
}

m_iLastLookatX = lookatPlot->getX_INLINE();
m_iLastLookatY = lookatPlot->getY_INLINE();
}

CvPlot::EvictGraphicsIfNecessary();
}
}
CvPlotPaging::UpdatePaging();

//OutputDebugString(CvString::format("Start profiling(false) for CvGame::update()\n").c_str());
PROFILE_BEGIN("CvGame::update");
Expand Down
4 changes: 0 additions & 4 deletions Sources/CvGame.h
Expand Up @@ -1014,10 +1014,6 @@ class CvGame
// points evaluated
int m_iChokePointCalculationVersion;

int m_iLastLookatX;
int m_iLastLookatY;
bool m_bWasGraphicsPagingEnabled;

public:
// Super forts adaptation to C2C - calc choke points if not already done
void ensureChokePointsEvaluated();
Expand Down
90 changes: 4 additions & 86 deletions Sources/CvGameCoreDLL.h
Expand Up @@ -18,6 +18,7 @@
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
#include <MMSystem.h>

//#if defined _DEBUG && !defined USE_MEMMANAGER
//#define USE_MEMMANAGER
//#include <crtdbg.h>
Expand All @@ -41,92 +42,8 @@

#define DllExport __declspec( dllexport )

//
// GameBryo
//
class NiColor
{
public:
float r, g, b;
};
class NiColorA
{
public:
NiColorA(float fr, float fg, float fb, float fa) : r(fr), g(fg), b(fb), a(fa) {}
NiColorA() {}
float r, g, b, a;
};
class NiPoint2
{
public:
NiPoint2() {}
NiPoint2(float fx, float fy) : x(fx),y(fy) {}

float x, y;
};
class NiPoint3
{
public:
NiPoint3(): x(0.0f), y(0.0f), z(0.0f) {}
NiPoint3(float fx, float fy, float fz) : x(fx),y(fy),z(fz) {}

bool operator== (const NiPoint3& pt) const
{ return (x == pt.x && y == pt.y && z == pt.z); }

inline NiPoint3 operator+ (const NiPoint3& pt) const
{ return NiPoint3(x+pt.x,y+pt.y,z+pt.z); }

inline NiPoint3 operator- (const NiPoint3& pt) const
{ return NiPoint3(x-pt.x,y-pt.y,z-pt.z); }

inline float operator* (const NiPoint3& pt) const
{ return x*pt.x+y*pt.y+z*pt.z; }

inline NiPoint3 operator* (float fScalar) const
{ return NiPoint3(fScalar*x,fScalar*y,fScalar*z); }

inline NiPoint3 operator/ (float fScalar) const
{
float fInvScalar = 1.0f/fScalar;
return NiPoint3(fInvScalar*x,fInvScalar*y,fInvScalar*z);
}

inline NiPoint3 operator- () const
{ return NiPoint3(-x,-y,-z); }

inline float Length() const
{ return sqrt(x * x + y * y + z * z); }

inline float Unitize()
{
float length = Length();
if(length != 0)
{
x /= length;
y /= length;
z /= length;
}
return length;
}

// inline NiPoint3 operator* (float fScalar, const NiPoint3& pt)
// { return NiPoint3(fScalar*pt.x,fScalar*pt.y,fScalar*pt.z); }
float x, y, z;
};

namespace NiAnimationKey
{
enum KeyType
{
NOINTERP,
LINKEY,
BEZKEY,
TCBKEY,
EULERKEY,
STEPKEY,
NUMKEYTYPES
};
};
#include "EnumFlags.h"
#include "NiPoint.h"

typedef unsigned char byte;
typedef unsigned short word;
Expand Down Expand Up @@ -235,6 +152,7 @@ namespace python = boost::python;

#include "FAssert.h"
#include "CheckSum.h"
#include "Stopwatch.h"
#include "CvGameCoreDLLDefNew.h"
#include "FDataStreamBase.h"
#include "FFreeListArrayBase.h"
Expand Down

0 comments on commit 8d73096

Please sign in to comment.