Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[1] mmCullCity::Init() #140

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 2 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
2 changes: 1 addition & 1 deletion code/midtown/agiworld/texsheet.h
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ class agiTexSheet
return prop_count_;
}

private:
public:
agiTexProp* props_ {};
i32 prop_count_ {};
b32 allow_remapping_ {}; // UseAlternate
Expand Down
2 changes: 1 addition & 1 deletion code/midtown/localize/lang_english.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ X(MM_IDS_8, "Creating ambients...")
X(MM_IDS_9, "Creating pedestrians...")
X(MM_IDS_10, "Initializing AI collidables...")
X(MM_IDS_11, "Resetting all AI...")
X(MM_IDS_12, "Loading city layout...")
X(MM_IDS_LOADING_CITY_LAYOUT, "Loading city layout...")
X(MM_IDS_13, "Loading bangers...")
X(MM_IDS_14, "Loading facades...")
X(MM_IDS_15, "Gill Sans MT, 12, 24, 0, 400")
Expand Down
2 changes: 1 addition & 1 deletion code/midtown/localize/lang_german.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ X(MM_IDS_8, "Umgebungen werden erstellt...")
X(MM_IDS_9, "Fußgänger werden erstellt...")
X(MM_IDS_10, "Kollisions-KI wird initialisiert...")
X(MM_IDS_11, "KI wird zurückgesetzt...")
X(MM_IDS_12, "Stadtlayout wird geladen...")
X(MM_IDS_LOADING_CITY_LAYOUT, "Stadtlayout wird geladen...")
X(MM_IDS_13, "Klapperkisten werden geladen...")
X(MM_IDS_14, "Fassaden werden geladen...")
X(MM_IDS_15, "Gill Sans MT, 12, 24, 0, 400")
Expand Down
2 changes: 1 addition & 1 deletion code/midtown/localize/lang_japan.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ X(MM_IDS_8, "背景データを作成中")
X(MM_IDS_9, "歩行者データを作成中")
X(MM_IDS_10, "障害物データを初期化中")
X(MM_IDS_11, "AI をリセット中")
X(MM_IDS_12, "シティー レイアウトをロード中")
X(MM_IDS_LOADING_CITY_LAYOUT, "シティー レイアウトをロード中")
X(MM_IDS_13, "車データをロード中")
X(MM_IDS_14, "建物データをロード中")
X(MM_IDS_15, "MS Pゴシック, 10,14, 128, 400")
Expand Down
2 changes: 1 addition & 1 deletion code/midtown/localize/lang_russian.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ X(MM_IDS_8, "Создаю окружение...")
X(MM_IDS_9, "Создаю пешеходов...")
X(MM_IDS_10, "Считываю данные о просшествиях...")
X(MM_IDS_11, "Сброс ИИ...")
X(MM_IDS_12, "Загружаю карту города...")
X(MM_IDS_LOADING_CITY_LAYOUT, "Загружаю карту города...")
X(MM_IDS_13, "Загружаю баннеры...")
X(MM_IDS_14, "Загружаю фасады...")
X(MM_IDS_15, "System, 11, 22, 0, 400")
Expand Down
2 changes: 1 addition & 1 deletion code/midtown/localize/string_ids.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
#define MM_IDS_9 9
#define MM_IDS_10 10
#define MM_IDS_11 11
#define MM_IDS_12 12
#define MM_IDS_LOADING_CITY_LAYOUT 12
#define MM_IDS_13 13
#define MM_IDS_14 14
#define MM_IDS_15 15
Expand Down
172 changes: 172 additions & 0 deletions code/midtown/mmcity/cullcity.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,23 @@ define_dummy_symbol(mmcity_cullcity);

#include "cullcity.h"

#include "agi/dlptmpl.h"
#include "agi/getdlp.h"
#include "agi/rsys.h"
#include "agisw/swrend.h"
#include "agiworld/getmesh.h"
#include "agiworld/meshset.h"
#include "agiworld/quality.h"
#include "agiworld/texsheet.h"
#include "data7/memstat.h"
#include "localize/localize.h"
#include "mmcityinfo/state.h"
#include "mmdyna/bndtmpl.h"
#include "mmphysics/phys.h"
#include "stream/problems.h"
#include "stream/stream.h"

#include "loader.h"

#ifdef ARTS_DEV_BUILD
void mmRunwayLight::AddWidgets(Bank* /*arg1*/)
Expand Down Expand Up @@ -85,3 +98,162 @@ void mmCullCity::Cull()
}
}
}

static agiMeshCardVertex RainMeshCard[4] {
{-0.1f, 2.0f, 0.4f, 1.0f},
{-0.1f, -2.0f, 0.4f, 0.0f},
{0.1f, -2.0f, 0.6f, 0.0f},
{0.1f, 2.0f, 0.6f, 1.0f},
};

void mmCullCity::Init(char* name, asCamera* camera)
{
char city_path[64];
char lm_path[64];

IsSnowing = (MMSTATE.Weather == mmWeather::Snow);
CityName = arts_strdup(name);

arts_strcpy(city_path, name);
arts_strcat(city_path, "city");

arts_strcpy(lm_path, name);
arts_strcat(lm_path, "lm");

TEXSHEET.allow_remapping_ = (MMSTATE.TimeOfDay == mmTimeOfDay::Sunset or MMSTATE.TimeOfDay == mmTimeOfDay::Night);
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use ||, not or


switch (MMSTATE.Weather)
{
case mmWeather::Rain: TextureSuffix = "_fall"_xconst; break;
case mmWeather::Snow: TextureSuffix = "_win"_xconst; break;
default: TextureSuffix = nullptr; break;
}

StaticLog = arts_fopen(arts_formatf<64>("%s_static.csv", name), "w");

Loader()->BeginTask(LOC_STRING(MM_IDS_LOADING_CITY_LAYOUT), 0.0f);

DLPTemplate* city_dlp = nullptr;
DLPTemplate* lm_dlp = nullptr;

if (DevelopmentMode)
{
city_dlp = GetDLPTemplate(city_path);
if (!city_dlp)
Quitf("Unable to load city '%s'", name);
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you comment out these two lines? There's a patch in patches.cpp which removes this Quitf


lm_dlp = GetDLPTemplate(lm_path);
}

BeginMemStat("mmCullCity::Init");
InitProblems();

Camera = camera;
asNode::AddChild(&BangerDataManager);
asNode::AddChild(&BangerActiveManager);
asNode::AddChild(&BangerManager);
asNode::AddChild(&asnode34AF0);
asNode::AddChild(&PHYS);
asNode::AddChild(&RenderWeb);
asNode::AddChild(&Particles);
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think you need the asNode:: prefix for these


agiMeshCardVertex* vertex = NULL;

if (MMSTATE.Weather == mmWeather::Rain)
vertex = RainMeshCard;
else
vertex = agiMeshSet::DefaultQuad;

Particles.Init(100, 4, 4, 4, vertex);

SnowBirthRule.SetName("SnowRule");
AddChild(&SnowBirthRule);
SnowBirthRule.Load();

RainBirthRule.SetName("RainRule");
AddChild(&RainBirthRule);
RainBirthRule.Load();

BirthRule = 0;

Sky.Init("mmsky"_xconst);
Loader()->EndTask(0.0f);

BeginMemStat("mmCullCity.WEB");
RenderWeb.Load(name, 1);
EndMemStat();

HitIdBound = RenderWeb.HitIdBound;
HitIdBound->AddRef();

BuildingChain.Init(RenderWeb.MaxCells);
ObjectsChain.Init(RenderWeb.MaxCells);
ShadowChain.Init(RenderWeb.MaxCells);

InitObjectDetail();

LastInstance = (mmInstance*) mmInstanceHeap.HeapHead;
ResetInst = new mmYInstance();

LoadBangers(name);

if (MMSTATE.GameMode == mmGameMode::Blitz)
{
LoadBangers(arts_formatf<64>("%s_b%d", name, MMSTATE.EventId));
}
else if (MMSTATE.GameMode == mmGameMode::Checkpoint)
{
LoadBangers(arts_formatf<64>("%s_r%d", name, MMSTATE.EventId));
}
else if (MMSTATE.GameMode == mmGameMode::Circuit)
{
LoadBangers(arts_formatf<64>("%s_c%d", name, MMSTATE.EventId));
}
else if (MMSTATE.GameMode == mmGameMode::Cruise)
{
LoadBangers(arts_formatf<64>("%s_roam", name));
}
else if (MMSTATE.GameMode == mmGameMode::CnR)
{
LoadBangers(arts_formatf<64>("%s_cops", name));
}
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Make this a switch instead of lots of if-elses

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I changed them to a switch, and also reordered them so they're consistent with the codebase.


ResetInst = new mmYInstance();

LoadFacades(name);

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is missing the EnableSphereCull = CHICAGO; line

if (CHICAGO)
{
Vector3 pos_1 = {995.782, 0.173, 1188.804};
Vector3 pos_2 = {995.782, 0.173, 742.411};
Vector3 pos_3 = {1015.383, 0.173, 1188.805};
Vector3 pos_4 = {1015.383, 0.173, 742.411};

mmRunwayLight* light_1 = new mmRunwayLight("fxltglow"_xconst, pos_1, pos_2);
mmRunwayLight* light_2 = new mmRunwayLight("fxltglow"_xconst, pos_3, pos_4);
BuildingChain.Parent(light_1, 35);
BuildingChain.Parent(light_2, 35);

InitTimeOfDayAndWeather();
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This code and onwards shouldn't be inside if (CHICAGO)

Copy link
Collaborator Author

@KcRobin9 KcRobin9 Dec 29, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hopefully the new code matches what you intended.

In the future it would be nice to have something like this (next to the Chicago case)

if (CityName = "custom_city")
      ... custom Runway lights ...
      ... custom Runway lights ...


if (IsSnowing)
InitSnowTextures();

BangerMgr()->Init(40);

if (city_dlp && city_dlp->Release())
Errorf("Someone is still holding a ref on the city's template");

if (lm_dlp)
lm_dlp->Release();

EndMemStat();

void ShowRenderStats();
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is missing the CULLMGR->AddPage call.

Since ShowRenderStats is a static function, it wasn't automatically imported. You need to do ARTS_IMPORT void ShowRenderStats(); outside the function, and add import_symbol(0x48CC30, "?ShowRenderStats@@YAXXZ"); to symbols.cpp

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added the function and the import.
CULLMGR->AddPage(ShowRenderStats); correctly adds the page in the game


if (StaticLog)
{
delete StaticLog;
}
}
}
81 changes: 56 additions & 25 deletions code/midtown/mmcity/cullcity.h
Original file line number Diff line number Diff line change
Expand Up @@ -106,12 +106,17 @@
0x6A8E7C | int DisableUpper | ?DisableUpper@@3HA
*/

#include "agiworld/texsort.h"
#include "arts7/node.h"
#include "mmbangers/active.h"
#include "mmbangers/banger.h"
#include "mmbangers/data.h"
#include "vector7/matrix34.h"

#include "inst.h"
#include "instchn.h"
#include "renderweb.h"
#include "sky.h"

class agiTexDef;
class asCamera;
Expand Down Expand Up @@ -156,7 +161,7 @@ class mmCullCity final : public asNode
ARTS_IMPORT i16 GetRoomFlags(i16 arg1);

// ?Init@mmCullCity@@QAEXPADPAVasCamera@@@Z
ARTS_IMPORT void Init(char* arg1, asCamera* arg2);
ARTS_EXPORT void Init(char* name, asCamera* camera);

// ?InitObjectDetail@mmCullCity@@QAEXXZ
ARTS_IMPORT void InitObjectDetail();
Expand Down Expand Up @@ -191,26 +196,6 @@ class mmCullCity final : public asNode
// ?GetInstance@mmCullCity@@SAPAV1@XZ | inline
ARTS_IMPORT static mmCullCity* GetInstance();

offset_field(0x20, asCamera*, Camera);

offset_field(0x2B950, asRenderWeb, RenderWeb);

offset_field(0x34ACC, mmInstChain, BuildingChain); // StaticChain?
offset_field(0x34AD8, mmInstChain, ObjectsChain); // DynamicChain?
offset_field(0x34AE4, mmInstChain, ShadowChain);

offset_field(0x34B30, f32, WeatherFriction);

offset_field(0x34B48, agiTexDef*, ShadowMap);
offset_field(0x34B50, Matrix34, EnvMatrix);

offset_field(0x34D54, u32, SkyColor);
offset_field(0x34D58, b32, UseFogEnd2);
offset_field(0x34D5C, f32, FogEnd);
offset_field(0x34D60, f32, FogEnd2);

ARTS_ZEROED;

private:
// ?AddInstance@mmCullCity@@AAEXHPAD0HPAVVector3@@11M@Z
ARTS_IMPORT void AddInstance(
Expand All @@ -230,9 +215,49 @@ class mmCullCity final : public asNode
// ?Instance@mmCullCity@@0PAV1@A
ARTS_IMPORT static mmCullCity* Instance;

u8 gap20[0x34D4C];
public:
asCamera* Camera;
mmBoundTemplate* HitIdBound;
mmBangerDataManager BangerDataManager;
mmBangerActiveManager BangerActiveManager;
mmBangerManager BangerManager;
mmSky Sky;
asRenderWeb RenderWeb;
agiTexSorter TexSorter;
u8 gap[0x3];
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can remove this gap, since it's just from alignment padding

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thought this would mess with the check_size, but yeah it's still good now

mmInstChain BuildingChain;
mmInstChain ObjectsChain;
mmInstChain ShadowChain;
asNode asnode34AF0;
i32 field_34B10;
char* CityName;
i32 SnowTextureCount;
i32 CurrentSnowTexture;
agiTexDef** SnowTexturesDst;
agiTexDef** SnowTexturesSrc;
i8* ShowTextureWidthRatios;
i8* SnowTextureHeightRatios;
f32 WeatherFriction;
f32 RainFriction;
f32 SnowFrictionStart;
f32 SnowFrictionMin;
f32 SnowFrictionTime;
f32 SnowTotalElapsed;
agiTexDef* ShadowMap;
agiTexDef* SphereMap;
Matrix34 EnvMatrix;
asParticles Particles;
asBirthRule* BirthRule;
asBirthRule SnowBirthRule;
asBirthRule RainBirthRule;
i32 field_34D50;
u32 SkyColor;
b32 UseFogEnd2;
f32 FogEnd;
f32 FogEnd2;
mmInstance* LastInstance;
mmInstance* ResetInst;
};

check_size(mmCullCity, 0x34D6C);

inline mmCullCity* CullCity()
Expand Down Expand Up @@ -289,9 +314,15 @@ class mmRunwayLight final : public mmInstance
// ?Phase@mmRunwayLight@@2MA
ARTS_IMPORT static f32 Phase;

u8 gap14[0x4C];
Vector3 Start;
Vector3 End;
Vector3 Step;
Vector3 Center;
f32 Scale;
i32 NumLights;
i32 Texture;
agiMeshCardInfo MeshCard;
};

check_size(mmRunwayLight, 0x60);

// ?fix_clip@@YAXXZ
Expand Down
2 changes: 1 addition & 1 deletion code/midtown/mmcity/heap.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
template <typename T>
class mmHeap
{
private:
public:
u8* HeapBase {};
u8* HeapEnd {};
u8* HeapHead {};
Expand Down
Loading