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

Add GLASS and HEADLIGHT_SHADOW objects support #122

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
67 changes: 55 additions & 12 deletions src/handlers/feature_handlers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5581,7 +5581,27 @@ void vehCarModelFeatureHandler::DrawShadow() {
}
}

if (MMSTATE->TimeOfDay == 3 || MMSTATE->WeatherType != 0 ||
modStatic* headlightshadow = lvlInstance::GetGeomTableEntry(geomSetIdOffset + 112)->GetHighLOD();

if (headlightshadow != nullptr)
{
if (model->getHeadlightsState())
{
Matrix34 shadowMatrix;

if (lvlInstance::ComputeShadowMatrix(&shadowMatrix, roomId, carMatrix))
{
RSTATE->SetBlendSet(0, 0x80);

Matrix44::Convert(gfxRenderState::sm_World, shadowMatrix);
gfxRenderState::m_Touched = gfxRenderState::m_Touched | 0x88;

headlightshadow->Draw(shaders);
}
}
}

if (MMSTATE->TimeOfDay == 3 || MMSTATE->WeatherType != 0 || cfgMM1StyleShadows.Get() < 3 ||
lvlLevel::Singleton->GetRoomInfo(model->GetRoomId())->Flags & static_cast<int>(RoomFlags::Subterranean))
return;

Expand Down Expand Up @@ -6298,13 +6318,11 @@ void vehCarModelFeatureHandler::Install() {
}
);

if (cfgMM1StyleShadows.Get() >= 3) {
InstallVTableHook("vehCarModel::DrawShadow",
&DrawShadow, {
0x5B2CE0,
}
);
}
InstallVTableHook("vehCarModel::DrawShadow",
&DrawShadow, {
0x5B2CE0,
}
);

InstallVTableHook("vehCarModel::DrawGlow",
&DrawGlow, {
Expand Down Expand Up @@ -6786,6 +6804,8 @@ bool aiVehicleInstanceFeatureHandler::InitVehicleGeom(const char* basename, cons
inst->AddGeom(basename, "breaklt2", 0);
inst->AddGeom(basename, "breaklt3", 0);

inst->AddGeom(basename, "glass", 0);

inst->EndGeom();
}

Expand Down Expand Up @@ -6999,18 +7019,41 @@ void aiVehicleInstanceFeatureHandler::Draw(int lod)
//draw pop-up headlights
if (lod >= 2)
{
modStatic* plighton = lvlInstance::GetGeomTableEntry(geomSetIdOffset + 23)->GetHighLOD();
modStatic* plighton = lvlInstance::GetGeomTableEntry(geomSetIdOffset + 23)->GetLOD(lod);
if (plighton != nullptr)
{
if (aiMap::Instance->drawHeadlights)
DrawPart(plighton, carMatrix, shaders, vehCarModel::PartReflections);
DrawPart(plighton, carMatrix, shaders, lod == 3);
}

modStatic* plightoff = lvlInstance::GetGeomTableEntry(geomSetIdOffset + 24)->GetHighLOD();
modStatic* plightoff = lvlInstance::GetGeomTableEntry(geomSetIdOffset + 24)->GetLOD(lod);
if (plightoff != nullptr)
{
if (!aiMap::Instance->drawHeadlights)
DrawPart(plightoff, carMatrix, shaders, vehCarModel::PartReflections);
DrawPart(plightoff, carMatrix, shaders, lod == 3);
}
}

//draw glass
if (lod >= 1)
{
modStatic* glass = lvlInstance::GetGeomTableEntry(geomSetIdOffset + 41)->GetLOD(lod);
if (glass != nullptr)
{
bool zWriteEnable = RSTATE->Data.ZWriteEnable;
if (RSTATE->Data.ZWriteEnable != false)
{
RSTATE->Data.ZWriteEnable = false;
gfxRenderState::m_Touched = gfxRenderState::m_Touched | 1;
}

DrawPart(glass, carMatrix, shaders, lod == 3);

if (RSTATE->Data.ZWriteEnable != zWriteEnable)
{
RSTATE->Data.ZWriteEnable = zWriteEnable;
gfxRenderState::m_Touched = gfxRenderState::m_Touched | 1;
}
}
}

Expand Down
35 changes: 32 additions & 3 deletions src/modules/vehicle/carmodel.h
Original file line number Diff line number Diff line change
Expand Up @@ -561,6 +561,12 @@ namespace MM2
lvlInstance::AddGeom(basename, "breaklt2", 0);
lvlInstance::AddGeom(basename, "breaklt3", 0);

lvlInstance::AddGeom(basename, "glass", 0);

gfxForceLVERTEX = true;
lvlInstance::AddGeom(basename, "headlight_shadow", 0);
gfxForceLVERTEX = false;

//add variants
//supports up to 32 paintjobs
for (int i = 0; i < 32; i++)
Expand Down Expand Up @@ -797,7 +803,7 @@ namespace MM2
InitBreakable(this->genBreakableMgr, basename, "breaklt2", 109, 5);
InitBreakable(this->genBreakableMgr, basename, "breaklt3", 110, 6);

int variantGeomId = this->variant + 111;
int variantGeomId = this->variant + 113;
string_buf<16> buffer("variant%d", this->variant);
InitBreakable(this->genBreakableMgr, basename, buffer, variantGeomId, 0);

Expand Down Expand Up @@ -1120,10 +1126,10 @@ namespace MM2
{
if (this->HeadlightsState)
//plighton
DrawPart(lod, 53, this->getCarMatrix(), shaders, vehCarModel::PartReflections);
DrawPart(lod, 53, this->getCarMatrix(), shaders, lod == 3);
else
//plightoff
DrawPart(lod, 54, this->getCarMatrix(), shaders, vehCarModel::PartReflections);
DrawPart(lod, 54, this->getCarMatrix(), shaders, lod == 3);
}

Matrix34 dummyWhl4Matrix = Matrix34();
Expand Down Expand Up @@ -1512,6 +1518,29 @@ namespace MM2
}
}

//draw glass
if (lod >= 1)
{
auto glassModel = lvlInstance::GetGeomTableEntry(geomSetIdOffset + 111)->GetLOD(lod);
if (glassModel != nullptr)
{
bool zWriteEnable = RSTATE->Data.ZWriteEnable;
if (RSTATE->Data.ZWriteEnable != false)
{
RSTATE->Data.ZWriteEnable = false;
gfxRenderState::m_Touched = gfxRenderState::m_Touched | 1;
}

DrawPart(lod, 111, this->getCarMatrix(), shaders, lod == 3);

if (RSTATE->Data.ZWriteEnable != zWriteEnable)
{
RSTATE->Data.ZWriteEnable = zWriteEnable;
gfxRenderState::m_Touched = gfxRenderState::m_Touched | 1;
}
}
}

//set alpha back if requireed
if (oldAlphaRef != (&RSTATE->Data)->AlphaRef)
{
Expand Down