1
0
Fork 0
mirror of https://git.rip/DMCA_FUCKER/re3.git synced 2024-11-18 09:37:46 +00:00
re3/src/render/Renderer.cpp

1908 lines
53 KiB
C++
Raw Normal View History

2020-11-03 19:33:07 +00:00
#define WITH_D3D
2019-05-15 14:52:37 +00:00
#include "common.h"
2020-04-17 13:31:11 +00:00
2019-06-17 08:30:02 +00:00
#include "main.h"
2019-05-15 14:52:37 +00:00
#include "Lights.h"
#include "ModelInfo.h"
#include "Treadable.h"
#include "Ped.h"
#include "Vehicle.h"
2020-11-04 15:22:15 +00:00
#include "Boat.h"
2019-05-31 09:44:43 +00:00
#include "Heli.h"
2020-06-02 13:26:11 +00:00
#include "Bike.h"
2019-05-15 14:52:37 +00:00
#include "Object.h"
#include "PathFind.h"
#include "Collision.h"
#include "VisibilityPlugins.h"
#include "Clock.h"
#include "World.h"
#include "Camera.h"
#include "ModelIndices.h"
#include "Streaming.h"
2019-05-31 09:44:43 +00:00
#include "Shadows.h"
#include "PointLights.h"
2020-05-11 15:03:32 +00:00
#include "Occlusion.h"
2019-05-15 14:52:37 +00:00
#include "Renderer.h"
2020-08-19 14:10:22 +00:00
#include "custompipes.h"
2019-05-15 14:52:37 +00:00
2020-06-02 13:26:11 +00:00
//--MIAMI: file done
2020-05-11 15:03:32 +00:00
2019-05-15 14:52:37 +00:00
bool gbShowCollisionPolys;
2019-07-19 11:58:19 +00:00
bool gbShowCollisionLines;
bool gbBigWhiteDebugLightSwitchedOn;
2019-05-15 14:52:37 +00:00
bool gbDontRenderBuildings;
bool gbDontRenderBigBuildings;
bool gbDontRenderPeds;
bool gbDontRenderObjects;
2019-07-19 11:58:19 +00:00
bool gbDontRenderVehicles;
2019-05-15 14:52:37 +00:00
struct EntityInfo
{
CEntity *ent;
float sort;
};
2020-04-15 16:19:45 +00:00
CLinkList<EntityInfo> gSortedVehiclesAndPeds;
2019-05-15 14:52:37 +00:00
2020-04-15 16:19:45 +00:00
int32 CRenderer::ms_nNoOfVisibleEntities;
CEntity *CRenderer::ms_aVisibleEntityPtrs[NUMVISIBLEENTITIES];
CEntity *CRenderer::ms_aInVisibleEntityPtrs[NUMINVISIBLEENTITIES];
int32 CRenderer::ms_nNoOfInVisibleEntities;
2020-11-03 19:33:07 +00:00
#ifdef NEW_RENDERER
int32 CRenderer::ms_nNoOfVisibleVehicles;
CEntity *CRenderer::ms_aVisibleVehiclePtrs[NUMVISIBLEENTITIES];
int32 CRenderer::ms_nNoOfVisibleBuildings;
CEntity *CRenderer::ms_aVisibleBuildingPtrs[NUMVISIBLEENTITIES];
#endif
2019-05-15 14:52:37 +00:00
2020-04-15 16:19:45 +00:00
CVector CRenderer::ms_vecCameraPosition;
CVehicle *CRenderer::m_pFirstPersonVehicle;
bool CRenderer::m_loadingPriority;
float CRenderer::ms_lodDistScale = 1.2f;
2019-05-15 14:52:37 +00:00
2020-11-03 19:33:07 +00:00
2019-05-15 14:52:37 +00:00
void
CRenderer::Init(void)
{
gSortedVehiclesAndPeds.Init(40);
SortBIGBuildings();
}
2019-05-31 09:44:43 +00:00
2019-07-06 10:27:21 +00:00
void
CRenderer::Shutdown(void)
{
gSortedVehiclesAndPeds.Shutdown();
}
2019-05-31 09:44:43 +00:00
void
CRenderer::PreRender(void)
{
int i;
CLink<CVisibilityPlugins::AlphaObjectInfo> *node;
for(i = 0; i < ms_nNoOfVisibleEntities; i++)
ms_aVisibleEntityPtrs[i]->PreRender();
2020-11-03 19:33:07 +00:00
#ifdef NEW_RENDERER
if(gbNewRenderer){
for(i = 0; i < ms_nNoOfVisibleVehicles; i++)
ms_aVisibleVehiclePtrs[i]->PreRender();
// How is this done with cWorldStream?
for(i = 0; i < ms_nNoOfVisibleBuildings; i++)
ms_aVisibleBuildingPtrs[i]->PreRender();
for(node = CVisibilityPlugins::m_alphaBuildingList.head.next;
node != &CVisibilityPlugins::m_alphaBuildingList.tail;
node = node->next)
((CEntity*)node->item.entity)->PreRender();
}
#endif
for (i = 0; i < ms_nNoOfInVisibleEntities; i++) {
#ifdef SQUEEZE_PERFORMANCE
if (ms_aInVisibleEntityPtrs[i]->IsVehicle() && ((CVehicle*)ms_aInVisibleEntityPtrs[i])->IsHeli())
#endif
2019-05-31 09:44:43 +00:00
ms_aInVisibleEntityPtrs[i]->PreRender();
}
2019-05-31 09:44:43 +00:00
2019-11-02 23:13:29 +00:00
for(node = CVisibilityPlugins::m_alphaEntityList.head.next;
node != &CVisibilityPlugins::m_alphaEntityList.tail;
node = node->next)
2019-05-31 09:44:43 +00:00
((CEntity*)node->item.entity)->PreRender();
CHeli::SpecialHeliPreRender();
CShadows::RenderExtraPlayerShadows();
}
2019-05-15 14:52:37 +00:00
void
CRenderer::RenderOneRoad(CEntity *e)
{
if(gbDontRenderBuildings)
return;
if(gbShowCollisionPolys)
2020-05-05 11:48:35 +00:00
CCollision::DrawColModel_Coloured(e->GetMatrix(), *CModelInfo::GetModelInfo(e->GetModelIndex())->GetColModel(), e->GetModelIndex());
2019-05-15 14:52:37 +00:00
else
e->Render();
}
void
CRenderer::RenderOneNonRoad(CEntity *e)
{
CPed *ped;
CVehicle *veh;
int i;
bool resetLights;
#ifndef MASTER
if(gbShowCollisionPolys){
if(!e->IsVehicle()){
2020-05-05 11:48:35 +00:00
CCollision::DrawColModel_Coloured(e->GetMatrix(), *CModelInfo::GetModelInfo(e->GetModelIndex())->GetColModel(), e->GetModelIndex());
2019-05-15 14:52:37 +00:00
return;
}
}else if(e->IsBuilding()){
if(e->bIsBIGBuilding){
if(gbDontRenderBigBuildings)
return;
}else{
if(gbDontRenderBuildings)
return;
}
}else
#endif
if(e->IsPed()){
#ifndef MASTER
if(gbDontRenderPeds)
return;
#endif
ped = (CPed*)e;
2019-05-28 06:39:36 +00:00
if(ped->m_nPedState == PED_DRIVING)
2019-05-15 14:52:37 +00:00
return;
}
#ifndef MASTER
else if(e->IsObject() || e->IsDummy()){
if(gbDontRenderObjects)
return;
2019-07-19 11:58:19 +00:00
}else if(e->IsVehicle()){
// re3 addition
if(gbDontRenderVehicles)
return;
2019-05-15 14:52:37 +00:00
}
#endif
resetLights = e->SetupLighting();
2020-05-11 15:03:32 +00:00
if(e->IsVehicle()){
// unfortunately can't use GetClump here
CVisibilityPlugins::SetupVehicleVariables((RpClump*)e->m_rwObject);
2019-05-15 14:52:37 +00:00
CVisibilityPlugins::InitAlphaAtomicList();
2020-05-11 15:03:32 +00:00
}
2019-05-15 14:52:37 +00:00
// Render Peds in vehicle before vehicle itself
if(e->IsVehicle()){
veh = (CVehicle*)e;
2019-05-28 06:39:36 +00:00
if(veh->pDriver && veh->pDriver->m_nPedState == PED_DRIVING)
2019-05-15 14:52:37 +00:00
veh->pDriver->Render();
for(i = 0; i < 8; i++)
2019-05-28 06:39:36 +00:00
if(veh->pPassengers[i] && veh->pPassengers[i]->m_nPedState == PED_DRIVING)
2019-05-15 14:52:37 +00:00
veh->pPassengers[i]->Render();
2020-05-11 15:03:32 +00:00
SetCullMode(rwCULLMODECULLNONE);
2019-05-15 14:52:37 +00:00
}
e->Render();
if(e->IsVehicle()){
e->bImBeingRendered = true;
CVisibilityPlugins::RenderAlphaAtomics();
e->bImBeingRendered = false;
2020-05-11 15:03:32 +00:00
SetCullMode(rwCULLMODECULLBACK);
2019-05-15 14:52:37 +00:00
}
e->RemoveLighting(resetLights);
}
void
CRenderer::RenderFirstPersonVehicle(void)
{
if(m_pFirstPersonVehicle == nil)
return;
RwRenderStateSet(rwRENDERSTATEFOGENABLE, (void*)TRUE);
RwRenderStateSet(rwRENDERSTATEZWRITEENABLE, (void*)TRUE);
RwRenderStateSet(rwRENDERSTATEZTESTENABLE, (void*)TRUE);
RwRenderStateSet(rwRENDERSTATEVERTEXALPHAENABLE, (void*)TRUE);
RwRenderStateSet(rwRENDERSTATESRCBLEND, (void*)rwBLENDSRCALPHA);
RwRenderStateSet(rwRENDERSTATEDESTBLEND, (void*)rwBLENDINVSRCALPHA);
RenderOneNonRoad(m_pFirstPersonVehicle);
RwRenderStateSet(rwRENDERSTATEFOGENABLE, (void*)FALSE);
}
2020-05-11 15:03:32 +00:00
inline bool IsRoad(CEntity *e) { return e->IsBuilding() && ((CSimpleModelInfo*)CModelInfo::GetModelInfo(e->GetModelIndex()))->m_wetRoadReflection; }
2019-05-15 14:52:37 +00:00
void
CRenderer::RenderRoads(void)
{
int i;
2020-05-11 15:03:32 +00:00
CEntity *e;
2019-05-15 14:52:37 +00:00
RwRenderStateSet(rwRENDERSTATEFOGENABLE, (void*)TRUE);
2020-05-11 15:03:32 +00:00
RwRenderStateSet(rwRENDERSTATEVERTEXALPHAENABLE, (void*)TRUE);
SetCullMode(rwCULLMODECULLBACK);
2019-05-15 14:52:37 +00:00
DeActivateDirectional();
SetAmbientColours();
for(i = 0; i < ms_nNoOfVisibleEntities; i++){
2020-05-11 15:03:32 +00:00
e = ms_aVisibleEntityPtrs[i];
if(IsRoad(e))
RenderOneRoad(e);
2019-05-15 14:52:37 +00:00
}
}
2020-05-11 15:03:32 +00:00
inline bool PutIntoSortedVehicleList(CVehicle *veh)
{
if(veh->IsBoat()){
int mode = TheCamera.Cams[TheCamera.ActiveCam].Mode;
if(mode == CCam::MODE_WHEELCAM ||
mode == CCam::MODE_1STPERSON && TheCamera.GetLookDirection() != LOOKING_FORWARD && TheCamera.GetLookDirection() != LOOKING_BEHIND ||
CVisibilityPlugins::GetClumpAlpha(veh->GetClump()) != 255)
return false;
return true;
}else
return veh->bTouchingWater;
}
2019-05-15 14:52:37 +00:00
void
CRenderer::RenderEverythingBarRoads(void)
{
int i;
CEntity *e;
EntityInfo ei;
2020-05-11 15:03:32 +00:00
RwRenderStateSet(rwRENDERSTATEFOGENABLE, (void*)TRUE);
RwRenderStateSet(rwRENDERSTATEVERTEXALPHAENABLE, (void*)TRUE);
SetCullMode(rwCULLMODECULLBACK);
2019-05-15 14:52:37 +00:00
gSortedVehiclesAndPeds.Clear();
for(i = 0; i < ms_nNoOfVisibleEntities; i++){
e = ms_aVisibleEntityPtrs[i];
2020-05-11 15:03:32 +00:00
if(IsRoad(e))
2019-05-15 14:52:37 +00:00
continue;
2020-08-19 14:10:22 +00:00
#ifdef EXTENDED_PIPELINES
if(CustomPipes::bRenderingEnvMap && (e->IsPed() || e->IsVehicle()))
continue;
#endif
2019-05-15 14:52:37 +00:00
if(e->IsVehicle() ||
e->IsPed() && CVisibilityPlugins::GetClumpAlpha((RpClump*)e->m_rwObject) != 255){
2020-05-11 15:03:32 +00:00
if(e->IsVehicle() && PutIntoSortedVehicleList((CVehicle*)e)){
2019-07-03 12:06:26 +00:00
ei.ent = e;
2020-11-03 19:33:07 +00:00
ei.sort = (ms_vecCameraPosition - e->GetPosition()).MagnitudeSqr();
2019-07-03 12:06:26 +00:00
gSortedVehiclesAndPeds.InsertSorted(ei);
}else{
2020-11-03 19:33:07 +00:00
if(!CVisibilityPlugins::InsertEntityIntoSortedList(e, (ms_vecCameraPosition - e->GetPosition()).Magnitude())){
2019-05-15 14:52:37 +00:00
printf("Ran out of space in alpha entity list");
RenderOneNonRoad(e);
}
}
}else
RenderOneNonRoad(e);
}
}
void
CRenderer::RenderBoats(void)
{
CLink<EntityInfo> *node;
2020-05-11 15:03:32 +00:00
RwRenderStateSet(rwRENDERSTATEFOGENABLE, (void*)TRUE);
RwRenderStateSet(rwRENDERSTATEVERTEXALPHAENABLE, (void*)TRUE);
SetCullMode(rwCULLMODECULLBACK);
2020-11-03 19:33:07 +00:00
#ifdef NEW_RENDERER
int i;
CEntity *e;
EntityInfo ei;
if(gbNewRenderer){
gSortedVehiclesAndPeds.Clear();
// not the real thing
for(i = 0; i < ms_nNoOfVisibleVehicles; i++){
e = ms_aVisibleVehiclePtrs[i];
if(e->IsVehicle() && PutIntoSortedVehicleList((CVehicle*)e)){
ei.ent = e;
ei.sort = (ms_vecCameraPosition - e->GetPosition()).MagnitudeSqr();
gSortedVehiclesAndPeds.InsertSorted(ei);
}
}
}
#endif
2019-05-15 14:52:37 +00:00
for(node = gSortedVehiclesAndPeds.tail.prev;
node != &gSortedVehiclesAndPeds.head;
node = node->prev){
CVehicle *v = (CVehicle*)node->item.ent;
2020-05-28 16:53:54 +00:00
RenderOneNonRoad(v);
2019-05-15 14:52:37 +00:00
}
}
2020-11-03 19:33:07 +00:00
#ifdef NEW_RENDERER
#ifndef LIBRW
#error "Need librw for EXTENDED_PIPELINES"
#endif
2020-11-04 15:22:15 +00:00
#include "WaterLevel.h"
2020-11-03 19:33:07 +00:00
enum {
// blend passes
PASS_NOZ, // no z-write
PASS_ADD, // additive
PASS_BLEND // normal blend
};
static RwRGBAReal black;
2020-11-04 15:22:15 +00:00
static void
SetStencilState(int state)
{
switch(state){
// disable stencil
case 0:
2020-12-16 14:49:22 +00:00
rw::SetRenderState(rw::STENCILENABLE, FALSE);
2020-11-04 15:22:15 +00:00
break;
// test against stencil
case 1:
2020-12-16 14:49:22 +00:00
rw::SetRenderState(rw::STENCILENABLE, TRUE);
rw::SetRenderState(rw::STENCILFUNCTION, rw::STENCILNOTEQUAL);
rw::SetRenderState(rw::STENCILPASS, rw::STENCILKEEP);
rw::SetRenderState(rw::STENCILFAIL, rw::STENCILKEEP);
rw::SetRenderState(rw::STENCILZFAIL, rw::STENCILKEEP);
rw::SetRenderState(rw::STENCILFUNCTIONMASK, 0xFF);
rw::SetRenderState(rw::STENCILFUNCTIONREF, 0xFF);
2020-11-04 15:22:15 +00:00
break;
// write to stencil
case 2:
2020-12-16 14:49:22 +00:00
rw::SetRenderState(rw::STENCILENABLE, TRUE);
rw::SetRenderState(rw::STENCILFUNCTION, rw::STENCILALWAYS);
rw::SetRenderState(rw::STENCILPASS, rw::STENCILREPLACE);
rw::SetRenderState(rw::STENCILFUNCTIONREF, 0xFF);
2020-11-04 15:22:15 +00:00
break;
}
}
2020-12-16 14:49:22 +00:00
#ifdef RW_D3D9
struct BuildingInst
{
rw::RawMatrix combinedMat;
rw::d3d9::InstanceDataHeader *instHeader;
uint8 fadeAlpha;
bool lighting;
};
static BuildingInst blendInsts[3][2000];
static int numBlendInsts[3];
2020-11-03 19:33:07 +00:00
static void
SetMatrix(BuildingInst *building, rw::Matrix *worldMat)
{
using namespace rw;
RawMatrix world, worldview;
Camera *cam = engine->currentCamera;
convMatrix(&world, worldMat);
RawMatrix::mult(&worldview, &world, &cam->devView);
RawMatrix::mult(&building->combinedMat, &worldview, &cam->devProj);
}
static bool
IsTextureTransparent(RwTexture *tex)
{
if(tex == nil || tex->raster == nil)
return false;
return PLUGINOFFSET(rw::d3d::D3dRaster, tex->raster, rw::d3d::nativeRasterOffset)->hasAlpha;
}
// Render all opaque meshes and put atomics that needs blending
// into the deferred list.
static void
AtomicFirstPass(RpAtomic *atomic, int pass)
{
using namespace rw;
using namespace rw::d3d;
using namespace rw::d3d9;
BuildingInst *building = &blendInsts[pass][numBlendInsts[pass]];
atomic->getPipeline()->instance(atomic);
building->instHeader = (d3d9::InstanceDataHeader*)atomic->geometry->instData;
assert(building->instHeader != nil);
assert(building->instHeader->platform == PLATFORM_D3D9);
building->fadeAlpha = 255;
building->lighting = !!(atomic->geometry->flags & rw::Geometry::LIGHT);
bool setupDone = false;
bool defer = false;
SetMatrix(building, atomic->getFrame()->getLTM());
InstanceData *inst = building->instHeader->inst;
for(rw::uint32 i = 0; i < building->instHeader->numMeshes; i++, inst++){
Material *m = inst->material;
if(inst->vertexAlpha || m->color.alpha != 255 ||
IsTextureTransparent(m->texture)){
defer = true;
continue;
}
// alright we're rendering this atomic
if(!setupDone){
setStreamSource(0, building->instHeader->vertexStream[0].vertexBuffer, 0, building->instHeader->vertexStream[0].stride);
setIndices(building->instHeader->indexBuffer);
setVertexDeclaration(building->instHeader->vertexDeclaration);
setVertexShader(default_amb_VS);
d3ddevice->SetVertexShaderConstantF(VSLOC_combined, (float*)&building->combinedMat, 4);
if(building->lighting)
setAmbient(pAmbient->color);
else
setAmbient(black);
setupDone = true;
}
setMaterial(m->color, m->surfaceProps);
if(m->texture){
d3d::setTexture(0, m->texture);
setPixelShader(default_tex_PS);
}else
setPixelShader(default_PS);
drawInst(building->instHeader, inst);
}
if(defer)
numBlendInsts[pass]++;
}
static void
AtomicFullyTransparent(RpAtomic *atomic, int pass, int fadeAlpha)
{
using namespace rw;
using namespace rw::d3d;
using namespace rw::d3d9;
BuildingInst *building = &blendInsts[pass][numBlendInsts[pass]];
atomic->getPipeline()->instance(atomic);
building->instHeader = (d3d9::InstanceDataHeader*)atomic->geometry->instData;
assert(building->instHeader != nil);
assert(building->instHeader->platform == PLATFORM_D3D9);
building->fadeAlpha = fadeAlpha;
2020-11-04 15:22:15 +00:00
building->lighting = !!(atomic->geometry->flags & rw::Geometry::LIGHT);
2020-11-03 19:33:07 +00:00
SetMatrix(building, atomic->getFrame()->getLTM());
numBlendInsts[pass]++;
}
static void
RenderBlendPass(int pass)
{
using namespace rw;
using namespace rw::d3d;
using namespace rw::d3d9;
setVertexShader(default_amb_VS);
int i;
for(i = 0; i < numBlendInsts[pass]; i++){
BuildingInst *building = &blendInsts[pass][i];
setStreamSource(0, building->instHeader->vertexStream[0].vertexBuffer, 0, building->instHeader->vertexStream[0].stride);
setIndices(building->instHeader->indexBuffer);
setVertexDeclaration(building->instHeader->vertexDeclaration);
d3ddevice->SetVertexShaderConstantF(VSLOC_combined, (float*)&building->combinedMat, 4);
if(building->lighting)
setAmbient(pAmbient->color);
else
setAmbient(black);
InstanceData *inst = building->instHeader->inst;
for(rw::uint32 j = 0; j < building->instHeader->numMeshes; j++, inst++){
Material *m = inst->material;
if(!inst->vertexAlpha && m->color.alpha == 255 && !IsTextureTransparent(m->texture) && building->fadeAlpha == 255)
continue; // already done this one
rw::RGBA color = m->color;
color.alpha = (color.alpha * building->fadeAlpha)/255;
setMaterial(color, m->surfaceProps);
if(m->texture){
d3d::setTexture(0, m->texture);
setPixelShader(default_tex_PS);
}else
setPixelShader(default_PS);
drawInst(building->instHeader, inst);
}
}
}
#endif
#ifdef RW_GL3
struct BuildingInst
{
rw::Matrix matrix;
rw::gl3::InstanceDataHeader *instHeader;
uint8 fadeAlpha;
bool lighting;
};
static BuildingInst blendInsts[3][2000];
static int numBlendInsts[3];
static bool
IsTextureTransparent(RwTexture *tex)
{
if(tex == nil || tex->raster == nil)
return false;
return PLUGINOFFSET(rw::gl3::Gl3Raster, tex->raster, rw::gl3::nativeRasterOffset)->hasAlpha;
}
// Render all opaque meshes and put atomics that needs blending
// into the deferred list.
static void
AtomicFirstPass(RpAtomic *atomic, int pass)
{
using namespace rw;
using namespace rw::gl3;
BuildingInst *building = &blendInsts[pass][numBlendInsts[pass]];
atomic->getPipeline()->instance(atomic);
building->instHeader = (gl3::InstanceDataHeader*)atomic->geometry->instData;
assert(building->instHeader != nil);
assert(building->instHeader->platform == PLATFORM_GL3);
building->fadeAlpha = 255;
building->lighting = !!(atomic->geometry->flags & rw::Geometry::LIGHT);
WorldLights lights;
lights.numAmbients = 1;
lights.numDirectionals = 0;
lights.numLocals = 0;
if(building->lighting)
lights.ambient = pAmbient->color;
else
lights.ambient = black;
bool setupDone = false;
bool defer = false;
building->matrix = *atomic->getFrame()->getLTM();
InstanceData *inst = building->instHeader->inst;
for(rw::uint32 i = 0; i < building->instHeader->numMeshes; i++, inst++){
Material *m = inst->material;
if(inst->vertexAlpha || m->color.alpha != 255 ||
IsTextureTransparent(m->texture)){
defer = true;
continue;
}
// alright we're rendering this atomic
if(!setupDone){
defaultShader->use();
setWorldMatrix(&building->matrix);
#ifdef RW_GL_USE_VAOS
glBindVertexArray(building->instHeader->vao);
#else
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, building->instHeader->ibo);
glBindBuffer(GL_ARRAY_BUFFER, building->instHeader->vbo);
setAttribPointers(building->instHeader->attribDesc, building->instHeader->numAttribs);
#endif
setLights(&lights);
setupDone = true;
}
setMaterial(m->color, m->surfaceProps);
setTexture(0, m->texture);
drawInst(building->instHeader, inst);
}
#ifndef RW_GL_USE_VAOS
disableAttribPointers(building->instHeader->attribDesc, building->instHeader->numAttribs);
#endif
if(defer)
numBlendInsts[pass]++;
}
static void
AtomicFullyTransparent(RpAtomic *atomic, int pass, int fadeAlpha)
{
using namespace rw;
using namespace rw::gl3;
BuildingInst *building = &blendInsts[pass][numBlendInsts[pass]];
atomic->getPipeline()->instance(atomic);
building->instHeader = (gl3::InstanceDataHeader*)atomic->geometry->instData;
assert(building->instHeader != nil);
assert(building->instHeader->platform == PLATFORM_GL3);
building->fadeAlpha = fadeAlpha;
2020-11-04 15:22:15 +00:00
building->lighting = !!(atomic->geometry->flags & rw::Geometry::LIGHT);
2020-11-03 19:33:07 +00:00
building->matrix = *atomic->getFrame()->getLTM();
numBlendInsts[pass]++;
}
static void
RenderBlendPass(int pass)
{
using namespace rw;
using namespace rw::gl3;
defaultShader->use();
WorldLights lights;
lights.numAmbients = 1;
lights.numDirectionals = 0;
lights.numLocals = 0;
int i;
for(i = 0; i < numBlendInsts[pass]; i++){
BuildingInst *building = &blendInsts[pass][i];
#ifdef RW_GL_USE_VAOS
glBindVertexArray(building->instHeader->vao);
#else
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, building->instHeader->ibo);
glBindBuffer(GL_ARRAY_BUFFER, building->instHeader->vbo);
setAttribPointers(building->instHeader->attribDesc, building->instHeader->numAttribs);
#endif
setWorldMatrix(&building->matrix);
if(building->lighting)
lights.ambient = pAmbient->color;
else
lights.ambient = black;
setLights(&lights);
InstanceData *inst = building->instHeader->inst;
for(rw::uint32 j = 0; j < building->instHeader->numMeshes; j++, inst++){
Material *m = inst->material;
if(!inst->vertexAlpha && m->color.alpha == 255 && !IsTextureTransparent(m->texture) && building->fadeAlpha == 255)
continue; // already done this one
rw::RGBA color = m->color;
color.alpha = (color.alpha * building->fadeAlpha)/255;
setMaterial(color, m->surfaceProps);
setTexture(0, m->texture);
drawInst(building->instHeader, inst);
}
2020-11-04 15:22:15 +00:00
#ifndef RW_GL_USE_VAOS
disableAttribPointers(building->instHeader->attribDesc, building->instHeader->numAttribs);
#endif
2020-11-03 19:33:07 +00:00
}
}
#endif
void
CRenderer::RenderOneBuilding(CEntity *ent, float camdist)
{
if(ent->m_rwObject == nil)
return;
2020-12-13 11:53:19 +00:00
ent->bImBeingRendered = true; // TODO: this seems wrong, but do we even need it?
2020-11-03 19:33:07 +00:00
assert(RwObjectGetType(ent->m_rwObject) == rpATOMIC);
RpAtomic *atomic = (RpAtomic*)ent->m_rwObject;
CSimpleModelInfo *mi = (CSimpleModelInfo*)CModelInfo::GetModelInfo(ent->GetModelIndex());
int pass = PASS_BLEND;
if(mi->m_additive) // very questionable
pass = PASS_ADD;
if(mi->m_noZwrite)
pass = PASS_NOZ;
if(ent->bDistanceFade){
RpAtomic *lodatm;
float fadefactor;
uint32 alpha;
lodatm = mi->GetAtomicFromDistance(camdist - FADE_DISTANCE);
fadefactor = (mi->GetLargestLodDistance() - (camdist - FADE_DISTANCE))/FADE_DISTANCE;
if(fadefactor > 1.0f)
fadefactor = 1.0f;
alpha = mi->m_alpha * fadefactor;
if(alpha == 255)
AtomicFirstPass(atomic, pass);
else{
// not quite sure what this is about, do we have to do that?
RpGeometry *geo = RpAtomicGetGeometry(lodatm);
if(geo != RpAtomicGetGeometry(atomic))
RpAtomicSetGeometry(atomic, geo, rpATOMICSAMEBOUNDINGSPHERE);
AtomicFullyTransparent(atomic, pass, alpha);
}
}else
AtomicFirstPass(atomic, pass);
ent->bImBeingRendered = false; // TODO: this seems wrong, but do we even need it?
}
void
CRenderer::RenderWorld(int pass)
{
int i;
CEntity *e;
CLink<CVisibilityPlugins::AlphaObjectInfo> *node;
RwRenderStateSet(rwRENDERSTATEFOGENABLE, (void*)TRUE);
SetCullMode(rwCULLMODECULLBACK);
DeActivateDirectional();
SetAmbientColours();
// Temporary...have to figure out sorting better
switch(pass){
case 0:
// Roads
RwRenderStateSet(rwRENDERSTATEVERTEXALPHAENABLE, (void*)FALSE);
for(i = 0; i < ms_nNoOfVisibleBuildings; i++){
e = ms_aVisibleBuildingPtrs[i];
if(e->bIsBIGBuilding || IsRoad(e))
RenderOneBuilding(e);
}
for(node = CVisibilityPlugins::m_alphaBuildingList.tail.prev;
node != &CVisibilityPlugins::m_alphaBuildingList.head;
node = node->prev){
e = node->item.entity;
if(e->bIsBIGBuilding || IsRoad(e))
RenderOneBuilding(e, node->item.sort);
}
break;
case 1:
// Opaque
RwRenderStateSet(rwRENDERSTATEVERTEXALPHAENABLE, (void*)FALSE);
for(i = 0; i < ms_nNoOfVisibleBuildings; i++){
e = ms_aVisibleBuildingPtrs[i];
if(!(e->bIsBIGBuilding || IsRoad(e)))
RenderOneBuilding(e);
}
for(node = CVisibilityPlugins::m_alphaBuildingList.tail.prev;
node != &CVisibilityPlugins::m_alphaBuildingList.head;
node = node->prev){
e = node->item.entity;
if(!(e->bIsBIGBuilding || IsRoad(e)))
RenderOneBuilding(e, node->item.sort);
}
// Now we have iterated through all visible buildings (unsorted and sorted)
// and the transparency list is done.
RwRenderStateSet(rwRENDERSTATEVERTEXALPHAENABLE, (void*)TRUE);
RwRenderStateSet(rwRENDERSTATEZWRITEENABLE, FALSE);
RenderBlendPass(PASS_NOZ);
RwRenderStateSet(rwRENDERSTATEZWRITEENABLE, (void*)TRUE);
break;
case 2:
// Transparent
RwRenderStateSet(rwRENDERSTATEVERTEXALPHAENABLE, (void*)TRUE);
RwRenderStateSet(rwRENDERSTATEDESTBLEND, (void*)rwBLENDONE);
RenderBlendPass(PASS_ADD);
RwRenderStateSet(rwRENDERSTATEDESTBLEND, (void*)rwBLENDINVSRCALPHA);
RenderBlendPass(PASS_BLEND);
break;
}
}
void
2020-11-04 22:11:27 +00:00
CRenderer::RenderPeds(void)
{
int i;
CEntity *e;
for(i = 0; i < ms_nNoOfVisibleVehicles; i++){
e = ms_aVisibleVehiclePtrs[i];
if(e->IsPed())
RenderOneNonRoad(e);
}
}
void
CRenderer::RenderVehicles(void)
2020-11-03 19:33:07 +00:00
{
int i;
CEntity *e;
EntityInfo ei;
CLink<EntityInfo> *node;
2020-11-03 19:33:07 +00:00
// not the real thing
for(i = 0; i < ms_nNoOfVisibleVehicles; i++){
e = ms_aVisibleVehiclePtrs[i];
2020-11-04 22:11:27 +00:00
if(!e->IsVehicle())
continue;
if(PutIntoSortedVehicleList((CVehicle*)e))
continue; // boats handled elsewhere
2020-11-04 22:11:27 +00:00
ei.ent = e;
ei.sort = (ms_vecCameraPosition - e->GetPosition()).MagnitudeSqr();
gSortedVehiclesAndPeds.InsertSorted(ei);
2020-11-03 19:33:07 +00:00
}
for(node = gSortedVehiclesAndPeds.tail.prev;
node != &gSortedVehiclesAndPeds.head;
node = node->prev)
RenderOneNonRoad(node->item.ent);
2020-11-03 19:33:07 +00:00
}
2020-11-04 15:22:15 +00:00
void
CRenderer::RenderTransparentWater(void)
{
int i;
CEntity *e;
RwRenderStateSet(rwRENDERSTATETEXTURERASTER, nil);
RwRenderStateSet(rwRENDERSTATEVERTEXALPHAENABLE, (void*)TRUE);
RwRenderStateSet(rwRENDERSTATEFOGENABLE, (void*)FALSE);
RwRenderStateSet(rwRENDERSTATESRCBLEND, (void*)rwBLENDZERO);
RwRenderStateSet(rwRENDERSTATEDESTBLEND, (void*)rwBLENDONE);
RwRenderStateSet(rwRENDERSTATEZWRITEENABLE, (void*)FALSE);
SetStencilState(2);
for(i = 0; i < ms_nNoOfVisibleVehicles; i++){
e = ms_aVisibleVehiclePtrs[i];
if(e->IsVehicle() && ((CVehicle*)e)->IsBoat())
((CBoat*)e)->RenderWaterOutPolys();
}
RwRenderStateSet(rwRENDERSTATEFOGENABLE, (void*)TRUE);
RwRenderStateSet(rwRENDERSTATESRCBLEND, (void*)rwBLENDSRCALPHA);
RwRenderStateSet(rwRENDERSTATEDESTBLEND, (void*)rwBLENDINVSRCALPHA);
RwRenderStateSet(rwRENDERSTATEZWRITEENABLE, (void*)TRUE);
SetStencilState(1);
CWaterLevel::RenderTransparentWater();
SetStencilState(0);
}
2020-11-03 19:33:07 +00:00
void
CRenderer::ClearForFrame(void)
{
ms_nNoOfVisibleEntities = 0;
ms_nNoOfVisibleVehicles = 0;
ms_nNoOfVisibleBuildings = 0;
ms_nNoOfInVisibleEntities = 0;
gSortedVehiclesAndPeds.Clear();
numBlendInsts[PASS_NOZ] = 0;
numBlendInsts[PASS_ADD] = 0;
numBlendInsts[PASS_BLEND] = 0;
}
#endif
2019-05-15 14:52:37 +00:00
void
CRenderer::RenderFadingInEntities(void)
{
RwRenderStateSet(rwRENDERSTATEFOGENABLE, (void*)TRUE);
2020-05-11 15:03:32 +00:00
RwRenderStateSet(rwRENDERSTATEVERTEXALPHAENABLE, (void*)TRUE);
SetCullMode(rwCULLMODECULLBACK);
2019-05-15 14:52:37 +00:00
DeActivateDirectional();
SetAmbientColours();
CVisibilityPlugins::RenderFadingEntities();
}
2020-05-11 15:03:32 +00:00
void
CRenderer::RenderFadingInUnderwaterEntities(void)
{
DeActivateDirectional();
SetAmbientColours();
CVisibilityPlugins::RenderFadingUnderwaterEntities();
}
2019-07-19 11:58:19 +00:00
void
CRenderer::RenderCollisionLines(void)
{
int i;
// game doesn't draw fading in entities
// this should probably be fixed
for(i = 0; i < ms_nNoOfVisibleEntities; i++){
CEntity *e = ms_aVisibleEntityPtrs[i];
if(Abs(e->GetPosition().x - ms_vecCameraPosition.x) < 100.0f &&
Abs(e->GetPosition().y - ms_vecCameraPosition.y) < 100.0f)
CCollision::DrawColModel(e->GetMatrix(), *e->GetColModel());
}
}
2019-05-15 14:52:37 +00:00
enum Visbility
{
VIS_INVISIBLE,
VIS_VISIBLE,
VIS_OFFSCREEN,
VIS_STREAMME
};
// Time Objects can be time culled if
// other == -1 || CModelInfo::GetModelInfo(other)->GetRwObject()
// i.e. we have to draw even at the wrong time if
// other != -1 && CModelInfo::GetModelInfo(other)->GetRwObject() == nil
#define OTHERUNAVAILABLE (other != -1 && CModelInfo::GetModelInfo(other)->GetRwObject() == nil)
#define CANTIMECULL (!OTHERUNAVAILABLE)
int32
CRenderer::SetupEntityVisibility(CEntity *ent)
{
CSimpleModelInfo *mi = (CSimpleModelInfo*)CModelInfo::GetModelInfo(ent->m_modelIndex);
CTimeModelInfo *ti;
int32 other;
float dist;
bool request = true;
if(mi->GetModelType() == MITYPE_TIME){
ti = (CTimeModelInfo*)mi;
other = ti->GetOtherTimeModel();
if(CClock::GetIsTimeInRange(ti->GetTimeOn(), ti->GetTimeOff())){
// don't fade in, or between time objects
if(CANTIMECULL)
ti->m_alpha = 255;
}else{
// Hide if possible
if(CANTIMECULL)
return VIS_INVISIBLE;
// can't cull, so we'll try to draw this one, but don't request
// it since what we really want is the other one.
request = false;
}
}else{
2020-05-11 15:03:32 +00:00
if(mi->GetModelType() != MITYPE_SIMPLE && mi->GetModelType() != MITYPE_WEAPON){
if(FindPlayerVehicle() == ent &&
2020-05-11 15:03:32 +00:00
TheCamera.Cams[TheCamera.ActiveCam].Mode == CCam::MODE_1STPERSON &&
2020-06-09 13:50:00 +00:00
!(FindPlayerVehicle()->IsBike() && ((CBike*)FindPlayerVehicle())->bWheelieCam)){
// Player's vehicle in first person mode
2020-05-11 15:03:32 +00:00
CVehicle *veh = (CVehicle*)ent;
int model = veh->GetModelIndex();
int direction = TheCamera.Cams[TheCamera.ActiveCam].DirectionWasLooking;
if(direction == LOOKING_FORWARD ||
ent->GetModelIndex() == MI_RHINO ||
ent->GetModelIndex() == MI_COACH ||
2020-05-11 15:03:32 +00:00
TheCamera.m_bInATunnelAndABigVehicle ||
direction == LOOKING_BEHIND && veh->pHandling->Flags & HANDLING_UNKNOWN){
ent->bNoBrightHeadLights = true;
2020-05-11 15:03:32 +00:00
return VIS_OFFSCREEN;
}
if(direction != LOOKING_BEHIND ||
!veh->IsBoat() || model == MI_REEFER || model == MI_TROPIC || model == MI_PREDATOR || model == MI_SKIMMER){
m_pFirstPersonVehicle = (CVehicle*)ent;
ent->bNoBrightHeadLights = false;
2020-05-11 15:03:32 +00:00
return VIS_OFFSCREEN;
}
2020-05-11 15:03:32 +00:00
}
// All sorts of Clumps
if(ent->m_rwObject == nil || !ent->bIsVisible)
return VIS_INVISIBLE;
if(!ent->GetIsOnScreen() || ent->IsEntityOccluded())
return VIS_OFFSCREEN;
2020-05-11 15:03:32 +00:00
if(ent->bDrawLast){
dist = (ent->GetPosition() - ms_vecCameraPosition).Magnitude();
CVisibilityPlugins::InsertEntityIntoSortedList(ent, dist);
ent->bDistanceFade = false;
return VIS_INVISIBLE;
}
2020-05-11 15:03:32 +00:00
return VIS_VISIBLE;
}
2020-05-27 20:32:33 +00:00
if(ent->bDontStream){
if(ent->m_rwObject == nil || !ent->bIsVisible)
return VIS_INVISIBLE;
2020-05-11 15:03:32 +00:00
if(!ent->GetIsOnScreen() || ent->IsEntityOccluded())
return VIS_OFFSCREEN;
if(ent->bDrawLast){
dist = (ent->GetPosition() - ms_vecCameraPosition).Magnitude();
CVisibilityPlugins::InsertEntityIntoSortedList(ent, dist);
ent->bDistanceFade = false;
return VIS_INVISIBLE;
}
return VIS_VISIBLE;
}
}
// Simple ModelInfo
2020-05-05 21:27:43 +00:00
if(!IsAreaVisible(ent->m_area))
return VIS_INVISIBLE;
dist = (ent->GetPosition() - ms_vecCameraPosition).Magnitude();
2020-05-11 15:03:32 +00:00
#ifndef FIX_BUGS
// Whatever this is supposed to do, it breaks fading for objects
// whose draw dist is > LOD_DISTANCE-FADE_DISTANCE, i.e. 280
// because decreasing dist here makes the object visible above LOD_DISTANCE
// before fading normally once below LOD_DISTANCE.
2020-07-21 09:12:15 +00:00
// aha! this must be a workaround for the fact that we're not taking
// the LOD multiplier into account here anywhere
if(LOD_DISTANCE < dist && dist < mi->GetLargestLodDistance() + FADE_DISTANCE)
2020-05-11 15:03:32 +00:00
dist += mi->GetLargestLodDistance() - LOD_DISTANCE;
#endif
if(ent->IsObject() && ent->bRenderDamaged)
mi->m_isDamaged = true;
RpAtomic *a = mi->GetAtomicFromDistance(dist);
if(a){
mi->m_isDamaged = false;
if(ent->m_rwObject == nil)
ent->CreateRwObject();
assert(ent->m_rwObject);
RpAtomic *rwobj = (RpAtomic*)ent->m_rwObject;
// Make sure our atomic uses the right geometry and not
// that of an atomic for another draw distance.
if(RpAtomicGetGeometry(a) != RpAtomicGetGeometry(rwobj))
RpAtomicSetGeometry(rwobj, RpAtomicGetGeometry(a), rpATOMICSAMEBOUNDINGSPHERE); // originally 5 (mistake?)
mi->IncreaseAlpha();
if(ent->m_rwObject == nil || !ent->bIsVisible)
return VIS_INVISIBLE;
2020-05-11 15:03:32 +00:00
if(!ent->GetIsOnScreen() || ent->IsEntityOccluded()){
mi->m_alpha = 255;
return VIS_OFFSCREEN;
}
if(mi->m_alpha != 255){
CVisibilityPlugins::InsertEntityIntoSortedList(ent, dist);
ent->bDistanceFade = true;
return VIS_INVISIBLE;
}
if(mi->m_drawLast || ent->bDrawLast){
if(CVisibilityPlugins::InsertEntityIntoSortedList(ent, dist)){
ent->bDistanceFade = false;
return VIS_INVISIBLE;
}
}
return VIS_VISIBLE;
}
// Object is not loaded, figure out what to do
if(mi->m_noFade){
mi->m_isDamaged = false;
// request model
if(dist - STREAM_DISTANCE < mi->GetLargestLodDistance() && request)
return VIS_STREAMME;
return VIS_INVISIBLE;
}
// We might be fading
a = mi->GetAtomicFromDistance(dist - FADE_DISTANCE);
mi->m_isDamaged = false;
if(a == nil){
// request model
if(dist - FADE_DISTANCE - STREAM_DISTANCE < mi->GetLargestLodDistance() && request)
return VIS_STREAMME;
return VIS_INVISIBLE;
}
if(ent->m_rwObject == nil)
ent->CreateRwObject();
assert(ent->m_rwObject);
RpAtomic *rwobj = (RpAtomic*)ent->m_rwObject;
if(RpAtomicGetGeometry(a) != RpAtomicGetGeometry(rwobj))
RpAtomicSetGeometry(rwobj, RpAtomicGetGeometry(a), rpATOMICSAMEBOUNDINGSPHERE); // originally 5 (mistake?)
mi->IncreaseAlpha();
if(ent->m_rwObject == nil || !ent->bIsVisible)
return VIS_INVISIBLE;
2020-05-11 15:03:32 +00:00
if(!ent->GetIsOnScreen() || ent->IsEntityOccluded()){
mi->m_alpha = 255;
return VIS_OFFSCREEN;
}else{
CVisibilityPlugins::InsertEntityIntoSortedList(ent, dist);
ent->bDistanceFade = true;
return VIS_OFFSCREEN; // Why this?
}
2019-05-15 14:52:37 +00:00
}
int32
CRenderer::SetupBigBuildingVisibility(CEntity *ent)
{
CSimpleModelInfo *mi = (CSimpleModelInfo*)CModelInfo::GetModelInfo(ent->m_modelIndex);
CTimeModelInfo *ti;
int32 other;
2020-05-05 21:27:43 +00:00
if(!IsAreaVisible(ent->m_area))
return VIS_INVISIBLE;
bool request = true;
if(mi->GetModelType() == MITYPE_TIME){
ti = (CTimeModelInfo*)mi;
other = ti->GetOtherTimeModel();
if(CClock::GetIsTimeInRange(ti->GetTimeOn(), ti->GetTimeOff())){
// don't fade in, or between time objects
if(CANTIMECULL)
ti->m_alpha = 255;
}else{
// Hide if possible
if(CANTIMECULL){
ent->DeleteRwObject();
return VIS_INVISIBLE;
}
// can't cull, so we'll try to draw this one, but don't request
// it since what we really want is the other one.
request = false;
}
}else if(mi->GetModelType() == MITYPE_VEHICLE)
return ent->IsVisible() ? VIS_VISIBLE : VIS_INVISIBLE;
float dist = (ms_vecCameraPosition-ent->GetPosition()).Magnitude();
CSimpleModelInfo *nonLOD = mi->GetRelatedModel();
// Find out whether to draw below near distance.
// This is only the case if there is a non-LOD which is either not
// loaded or not completely faded in yet.
if(dist < mi->GetNearDistance() && dist < LOD_DISTANCE){
// No non-LOD or non-LOD is completely visible.
if(nonLOD == nil ||
nonLOD->GetRwObject() && nonLOD->m_alpha == 255)
return VIS_INVISIBLE;
// But if it is a time object, we'd rather draw the wrong
// non-LOD than the right LOD.
if(nonLOD->GetModelType() == MITYPE_TIME){
ti = (CTimeModelInfo*)nonLOD;
other = ti->GetOtherTimeModel();
if(other != -1 && CModelInfo::GetModelInfo(other)->GetRwObject())
return VIS_INVISIBLE;
}
}
RpAtomic *a = mi->GetFirstAtomicFromDistance(dist);
if(a){
if(ent->m_rwObject == nil)
ent->CreateRwObject();
assert(ent->m_rwObject);
RpAtomic *rwobj = (RpAtomic*)ent->m_rwObject;
// Make sure our atomic uses the right geometry and not
// that of an atomic for another draw distance.
if(RpAtomicGetGeometry(a) != RpAtomicGetGeometry(rwobj))
RpAtomicSetGeometry(rwobj, RpAtomicGetGeometry(a), rpATOMICSAMEBOUNDINGSPHERE); // originally 5 (mistake?)
mi->IncreaseAlpha();
2020-11-22 21:11:55 +00:00
if(!ent->IsVisible() || !ent->GetIsOnScreenComplex() || ent->IsEntityOccluded()){
mi->m_alpha = 255;
return VIS_INVISIBLE;
}
if(mi->m_alpha != 255){
CVisibilityPlugins::InsertEntityIntoSortedList(ent, dist);
ent->bDistanceFade = true;
return VIS_INVISIBLE;
}
if(mi->m_drawLast){
CVisibilityPlugins::InsertEntityIntoSortedList(ent, dist);
ent->bDistanceFade = false;
return VIS_INVISIBLE;
}
return VIS_VISIBLE;
}
if(mi->m_noFade){
ent->DeleteRwObject();
return VIS_INVISIBLE;
}
// get faded atomic
a = mi->GetFirstAtomicFromDistance(dist - FADE_DISTANCE);
if(a == nil){
if(ent->bStreamBIGBuilding && dist-STREAM_DISTANCE < mi->GetLodDistance(0) && request){
return ent->GetIsOnScreen() ? VIS_STREAMME : VIS_INVISIBLE;
}else{
ent->DeleteRwObject();
return VIS_INVISIBLE;
}
}
// Fade...
if(ent->m_rwObject == nil)
ent->CreateRwObject();
assert(ent->m_rwObject);
RpAtomic *rwobj = (RpAtomic*)ent->m_rwObject;
if(RpAtomicGetGeometry(a) != RpAtomicGetGeometry(rwobj))
RpAtomicSetGeometry(rwobj, RpAtomicGetGeometry(a), rpATOMICSAMEBOUNDINGSPHERE); // originally 5 (mistake?)
mi->IncreaseAlpha();
2020-11-22 21:11:55 +00:00
if(!ent->IsVisible() || !ent->GetIsOnScreenComplex() || ent->IsEntityOccluded()){
mi->m_alpha = 255;
2020-05-11 15:03:32 +00:00
return VIS_INVISIBLE;
}
CVisibilityPlugins::InsertEntityIntoSortedList(ent, dist);
ent->bDistanceFade = true;
return VIS_INVISIBLE;
2019-05-15 14:52:37 +00:00
}
void
CRenderer::ConstructRenderList(void)
{
2020-05-11 15:03:32 +00:00
COcclusion::ProcessBeforeRendering();
2020-11-03 19:33:07 +00:00
#ifdef NEW_RENDERER
if(!gbNewRenderer)
#endif
{
2019-05-15 14:52:37 +00:00
ms_nNoOfVisibleEntities = 0;
ms_nNoOfInVisibleEntities = 0;
2020-11-03 19:33:07 +00:00
}
2019-05-15 14:52:37 +00:00
ms_vecCameraPosition = TheCamera.GetPosition();
// TODO: blocked ranges, but unused
ScanWorld();
}
void
LimitFrustumVector(CVector &vec1, const CVector &vec2, float l)
{
float f;
f = (l - vec2.z) / (vec1.z - vec2.z);
vec1.x = f*(vec1.x - vec2.x) + vec2.x;
vec1.y = f*(vec1.y - vec2.y) + vec2.y;
vec1.z = f*(vec1.z - vec2.z) + vec2.z;
}
enum Corners
{
CORNER_CAM = 0,
CORNER_FAR_TOPLEFT,
CORNER_FAR_TOPRIGHT,
CORNER_FAR_BOTRIGHT,
CORNER_FAR_BOTLEFT,
CORNER_LOD_LEFT,
CORNER_LOD_RIGHT,
CORNER_PRIO_LEFT,
CORNER_PRIO_RIGHT,
};
void
CRenderer::ScanWorld(void)
{
float f = RwCameraGetFarClipPlane(TheCamera.m_pRwCamera);
RwV2d vw = *RwCameraGetViewWindow(TheCamera.m_pRwCamera);
CVector vectors[9];
RwMatrix *cammatrix;
RwV2d poly[3];
memset(vectors, 0, sizeof(vectors));
vectors[CORNER_FAR_TOPLEFT].x = -vw.x * f;
vectors[CORNER_FAR_TOPLEFT].y = vw.y * f;
vectors[CORNER_FAR_TOPLEFT].z = f;
vectors[CORNER_FAR_TOPRIGHT].x = vw.x * f;
vectors[CORNER_FAR_TOPRIGHT].y = vw.y * f;
vectors[CORNER_FAR_TOPRIGHT].z = f;
vectors[CORNER_FAR_BOTRIGHT].x = vw.x * f;
vectors[CORNER_FAR_BOTRIGHT].y = -vw.y * f;
vectors[CORNER_FAR_BOTRIGHT].z = f;
vectors[CORNER_FAR_BOTLEFT].x = -vw.x * f;
vectors[CORNER_FAR_BOTLEFT].y = -vw.y * f;
vectors[CORNER_FAR_BOTLEFT].z = f;
cammatrix = RwFrameGetMatrix(RwCameraGetFrame(TheCamera.m_pRwCamera));
m_pFirstPersonVehicle = nil;
CVisibilityPlugins::InitAlphaEntityList();
CWorld::AdvanceCurrentScanCode();
2020-05-11 15:03:32 +00:00
// unused
static CVector prevPos;
static CVector prevFwd;
static bool smallMovement;
smallMovement = (TheCamera.GetPosition() - prevPos).MagnitudeSqr() < SQR(4.0f) &&
DotProduct(TheCamera.GetForward(), prevFwd) > 0.98f;
prevPos = TheCamera.GetPosition();
prevFwd = TheCamera.GetForward();
2019-05-15 14:52:37 +00:00
if(cammatrix->at.z > 0.0f){
// looking up, bottom corners are further away
vectors[CORNER_LOD_LEFT] = vectors[CORNER_FAR_BOTLEFT] * LOD_DISTANCE/f;
vectors[CORNER_LOD_RIGHT] = vectors[CORNER_FAR_BOTRIGHT] * LOD_DISTANCE/f;
}else{
// looking down, top corners are further away
vectors[CORNER_LOD_LEFT] = vectors[CORNER_FAR_TOPLEFT] * LOD_DISTANCE/f;
vectors[CORNER_LOD_RIGHT] = vectors[CORNER_FAR_TOPRIGHT] * LOD_DISTANCE/f;
}
vectors[CORNER_PRIO_LEFT].x = vectors[CORNER_LOD_LEFT].x * 0.2f;
vectors[CORNER_PRIO_LEFT].y = vectors[CORNER_LOD_LEFT].y * 0.2f;
vectors[CORNER_PRIO_LEFT].z = vectors[CORNER_LOD_LEFT].z;
vectors[CORNER_PRIO_RIGHT].x = vectors[CORNER_LOD_RIGHT].x * 0.2f;
vectors[CORNER_PRIO_RIGHT].y = vectors[CORNER_LOD_RIGHT].y * 0.2f;
vectors[CORNER_PRIO_RIGHT].z = vectors[CORNER_LOD_RIGHT].z;
RwV3dTransformPoints((RwV3d*)vectors, (RwV3d*)vectors, 9, cammatrix);
m_loadingPriority = false;
2019-10-27 03:17:30 +00:00
if(TheCamera.Cams[TheCamera.ActiveCam].Mode == CCam::MODE_TOPDOWN ||
2020-03-26 13:16:06 +00:00
#ifdef FIX_BUGS
TheCamera.Cams[TheCamera.ActiveCam].Mode == CCam::MODE_GTACLASSIC ||
#endif
2019-10-27 03:17:30 +00:00
TheCamera.Cams[TheCamera.ActiveCam].Mode == CCam::MODE_TOP_DOWN_PED){
2019-05-15 14:52:37 +00:00
CRect rect;
int x1, x2, y1, y2;
LimitFrustumVector(vectors[CORNER_FAR_TOPLEFT], vectors[CORNER_CAM], -100.0f);
rect.ContainPoint(vectors[CORNER_FAR_TOPLEFT]);
LimitFrustumVector(vectors[CORNER_FAR_TOPRIGHT], vectors[CORNER_CAM], -100.0f);
rect.ContainPoint(vectors[CORNER_FAR_TOPRIGHT]);
LimitFrustumVector(vectors[CORNER_FAR_BOTRIGHT], vectors[CORNER_CAM], -100.0f);
rect.ContainPoint(vectors[CORNER_FAR_BOTRIGHT]);
LimitFrustumVector(vectors[CORNER_FAR_BOTLEFT], vectors[CORNER_CAM], -100.0f);
rect.ContainPoint(vectors[CORNER_FAR_BOTLEFT]);
x1 = CWorld::GetSectorIndexX(rect.left);
if(x1 < 0) x1 = 0;
x2 = CWorld::GetSectorIndexX(rect.right);
if(x2 >= NUMSECTORS_X-1) x2 = NUMSECTORS_X-1;
y1 = CWorld::GetSectorIndexY(rect.top);
2019-05-15 14:52:37 +00:00
if(y1 < 0) y1 = 0;
y2 = CWorld::GetSectorIndexY(rect.bottom);
2019-05-15 14:52:37 +00:00
if(y2 >= NUMSECTORS_Y-1) y2 = NUMSECTORS_Y-1;
for(; x1 <= x2; x1++)
for(int y = y1; y <= y2; y++)
ScanSectorList(CWorld::GetSector(x1, y)->m_lists);
}else{
2020-05-11 15:03:32 +00:00
#ifdef GTA_TRAIN
2019-05-15 14:52:37 +00:00
CVehicle *train = FindPlayerTrain();
if(train && train->GetPosition().z < 0.0f){
poly[0].x = CWorld::GetSectorX(vectors[CORNER_CAM].x);
poly[0].y = CWorld::GetSectorY(vectors[CORNER_CAM].y);
poly[1].x = CWorld::GetSectorX(vectors[CORNER_LOD_LEFT].x);
poly[1].y = CWorld::GetSectorY(vectors[CORNER_LOD_LEFT].y);
poly[2].x = CWorld::GetSectorX(vectors[CORNER_LOD_RIGHT].x);
poly[2].y = CWorld::GetSectorY(vectors[CORNER_LOD_RIGHT].y);
ScanSectorPoly(poly, 3, ScanSectorList_Subway);
2020-05-11 15:03:32 +00:00
}else
#endif
{
2020-07-21 09:12:15 +00:00
if(f > LOD_DISTANCE){
2019-05-15 14:52:37 +00:00
// priority
poly[0].x = CWorld::GetSectorX(vectors[CORNER_CAM].x);
poly[0].y = CWorld::GetSectorY(vectors[CORNER_CAM].y);
poly[1].x = CWorld::GetSectorX(vectors[CORNER_PRIO_LEFT].x);
poly[1].y = CWorld::GetSectorY(vectors[CORNER_PRIO_LEFT].y);
poly[2].x = CWorld::GetSectorX(vectors[CORNER_PRIO_RIGHT].x);
poly[2].y = CWorld::GetSectorY(vectors[CORNER_PRIO_RIGHT].y);
ScanSectorPoly(poly, 3, ScanSectorList_Priority);
// below LOD
poly[0].x = CWorld::GetSectorX(vectors[CORNER_CAM].x);
poly[0].y = CWorld::GetSectorY(vectors[CORNER_CAM].y);
poly[1].x = CWorld::GetSectorX(vectors[CORNER_LOD_LEFT].x);
poly[1].y = CWorld::GetSectorY(vectors[CORNER_LOD_LEFT].y);
poly[2].x = CWorld::GetSectorX(vectors[CORNER_LOD_RIGHT].x);
poly[2].y = CWorld::GetSectorY(vectors[CORNER_LOD_RIGHT].y);
2020-07-21 09:12:15 +00:00
ScanSectorPoly(poly, 3, ScanSectorList);
}else{
poly[0].x = CWorld::GetSectorX(vectors[CORNER_CAM].x);
poly[0].y = CWorld::GetSectorY(vectors[CORNER_CAM].y);
poly[1].x = CWorld::GetSectorX(vectors[CORNER_FAR_TOPLEFT].x);
poly[1].y = CWorld::GetSectorY(vectors[CORNER_FAR_TOPLEFT].y);
poly[2].x = CWorld::GetSectorX(vectors[CORNER_FAR_TOPRIGHT].x);
poly[2].y = CWorld::GetSectorY(vectors[CORNER_FAR_TOPRIGHT].y);
ScanSectorPoly(poly, 3, ScanSectorList);
2019-05-15 14:52:37 +00:00
}
ScanBigBuildingList(CWorld::GetBigBuildingList(CGame::currLevel));
2020-07-13 14:43:09 +00:00
ScanBigBuildingList(CWorld::GetBigBuildingList(LEVEL_GENERIC));
2019-05-15 14:52:37 +00:00
}
}
}
void
CRenderer::RequestObjectsInFrustum(void)
{
float f = RwCameraGetFarClipPlane(TheCamera.m_pRwCamera);
RwV2d vw = *RwCameraGetViewWindow(TheCamera.m_pRwCamera);
CVector vectors[9];
RwMatrix *cammatrix;
RwV2d poly[3];
memset(vectors, 0, sizeof(vectors));
vectors[CORNER_FAR_TOPLEFT].x = -vw.x * f;
vectors[CORNER_FAR_TOPLEFT].y = vw.y * f;
vectors[CORNER_FAR_TOPLEFT].z = f;
vectors[CORNER_FAR_TOPRIGHT].x = vw.x * f;
vectors[CORNER_FAR_TOPRIGHT].y = vw.y * f;
vectors[CORNER_FAR_TOPRIGHT].z = f;
vectors[CORNER_FAR_BOTRIGHT].x = vw.x * f;
vectors[CORNER_FAR_BOTRIGHT].y = -vw.y * f;
vectors[CORNER_FAR_BOTRIGHT].z = f;
vectors[CORNER_FAR_BOTLEFT].x = -vw.x * f;
vectors[CORNER_FAR_BOTLEFT].y = -vw.y * f;
vectors[CORNER_FAR_BOTLEFT].z = f;
cammatrix = RwFrameGetMatrix(RwCameraGetFrame(TheCamera.m_pRwCamera));
CWorld::AdvanceCurrentScanCode();
2020-05-11 15:03:32 +00:00
ms_vecCameraPosition = TheCamera.GetPosition();
2019-05-15 14:52:37 +00:00
if(cammatrix->at.z > 0.0f){
// looking up, bottom corners are further away
vectors[CORNER_LOD_LEFT] = vectors[CORNER_FAR_BOTLEFT] * LOD_DISTANCE/f;
vectors[CORNER_LOD_RIGHT] = vectors[CORNER_FAR_BOTRIGHT] * LOD_DISTANCE/f;
}else{
// looking down, top corners are further away
vectors[CORNER_LOD_LEFT] = vectors[CORNER_FAR_TOPLEFT] * LOD_DISTANCE/f;
vectors[CORNER_LOD_RIGHT] = vectors[CORNER_FAR_TOPRIGHT] * LOD_DISTANCE/f;
}
vectors[CORNER_PRIO_LEFT].x = vectors[CORNER_LOD_LEFT].x * 0.2f;
vectors[CORNER_PRIO_LEFT].y = vectors[CORNER_LOD_LEFT].y * 0.2f;
vectors[CORNER_PRIO_LEFT].z = vectors[CORNER_LOD_LEFT].z;
vectors[CORNER_PRIO_RIGHT].x = vectors[CORNER_LOD_RIGHT].x * 0.2f;
vectors[CORNER_PRIO_RIGHT].y = vectors[CORNER_LOD_RIGHT].y * 0.2f;
vectors[CORNER_PRIO_RIGHT].z = vectors[CORNER_LOD_RIGHT].z;
RwV3dTransformPoints((RwV3d*)vectors, (RwV3d*)vectors, 9, cammatrix);
2019-10-27 03:17:30 +00:00
if(TheCamera.Cams[TheCamera.ActiveCam].Mode == CCam::MODE_TOPDOWN ||
2020-03-26 13:16:06 +00:00
#ifdef FIX_BUGS
TheCamera.Cams[TheCamera.ActiveCam].Mode == CCam::MODE_GTACLASSIC ||
#endif
2019-10-27 03:17:30 +00:00
TheCamera.Cams[TheCamera.ActiveCam].Mode == CCam::MODE_TOP_DOWN_PED){
2019-05-15 14:52:37 +00:00
CRect rect;
int x1, x2, y1, y2;
LimitFrustumVector(vectors[CORNER_FAR_TOPLEFT], vectors[CORNER_CAM], -100.0f);
rect.ContainPoint(vectors[CORNER_FAR_TOPLEFT]);
LimitFrustumVector(vectors[CORNER_FAR_TOPRIGHT], vectors[CORNER_CAM], -100.0f);
rect.ContainPoint(vectors[CORNER_FAR_TOPRIGHT]);
LimitFrustumVector(vectors[CORNER_FAR_BOTRIGHT], vectors[CORNER_CAM], -100.0f);
rect.ContainPoint(vectors[CORNER_FAR_BOTRIGHT]);
LimitFrustumVector(vectors[CORNER_FAR_BOTLEFT], vectors[CORNER_CAM], -100.0f);
rect.ContainPoint(vectors[CORNER_FAR_BOTLEFT]);
x1 = CWorld::GetSectorIndexX(rect.left);
if(x1 < 0) x1 = 0;
x2 = CWorld::GetSectorIndexX(rect.right);
if(x2 >= NUMSECTORS_X-1) x2 = NUMSECTORS_X-1;
y1 = CWorld::GetSectorIndexY(rect.top);
2019-05-15 14:52:37 +00:00
if(y1 < 0) y1 = 0;
y2 = CWorld::GetSectorIndexY(rect.bottom);
2019-05-15 14:52:37 +00:00
if(y2 >= NUMSECTORS_Y-1) y2 = NUMSECTORS_Y-1;
for(; x1 <= x2; x1++)
for(int y = y1; y <= y2; y++)
ScanSectorList_RequestModels(CWorld::GetSector(x1, y)->m_lists);
}else{
poly[0].x = CWorld::GetSectorX(vectors[CORNER_CAM].x);
poly[0].y = CWorld::GetSectorY(vectors[CORNER_CAM].y);
poly[1].x = CWorld::GetSectorX(vectors[CORNER_LOD_LEFT].x);
poly[1].y = CWorld::GetSectorY(vectors[CORNER_LOD_LEFT].y);
poly[2].x = CWorld::GetSectorX(vectors[CORNER_LOD_RIGHT].x);
poly[2].y = CWorld::GetSectorY(vectors[CORNER_LOD_RIGHT].y);
ScanSectorPoly(poly, 3, ScanSectorList_RequestModels);
}
}
// --MIAMI: Done
bool
CPed::SetupLighting(void)
{
ActivateDirectional();
SetAmbientColoursForPedsCarsAndObjects();
#ifndef MASTER
// Originally this was being called through iteration of Sectors, but putting it here is better.
if (GetDebugDisplay() != 0 && !IsPlayer())
DebugRenderOnePedText();
#endif
if (bRenderScorched) {
WorldReplaceNormalLightsWithScorched(Scene.world, 0.1f);
} else {
// Note that this lightMult is only affected by LIGHT_DARKEN. If there's no LIGHT_DARKEN, it will be 1.0.
float lightMult = CPointLights::GenerateLightsAffectingObject(&GetPosition());
if (lightMult != 1.0f) {
SetAmbientAndDirectionalColours(lightMult);
return true;
}
}
return false;
}
// --MIAMI: Done
void
CPed::RemoveLighting(bool reset)
{
if (!bRenderScorched) {
CRenderer::RemoveVehiclePedLights(this, reset);
if (reset)
ReSetAmbientAndDirectionalColours();
}
SetAmbientColours();
DeActivateDirectional();
}
2019-05-15 14:52:37 +00:00
float
CalcNewDelta(RwV2d *a, RwV2d *b)
{
return (b->x - a->x) / (b->y - a->y);
}
2020-08-21 07:40:31 +00:00
#ifdef FIX_BUGS
#define TOINT(x) ((int)Floor(x))
#else
#define TOINT(x) ((int)(x))
#endif
2019-05-15 14:52:37 +00:00
void
CRenderer::ScanSectorPoly(RwV2d *poly, int32 numVertices, void (*scanfunc)(CPtrList *))
{
float miny, maxy;
int y, yend;
int x, xstart, xend;
int i;
int a1, a2, b1, b2;
float deltaA, deltaB;
float xA, xB;
miny = poly[0].y;
maxy = poly[0].y;
a2 = 0;
xstart = 9999;
xend = -9999;
for(i = 1; i < numVertices; i++){
if(poly[i].y > maxy)
maxy = poly[i].y;
if(poly[i].y < miny){
miny = poly[i].y;
a2 = i;
}
}
2020-08-21 07:40:31 +00:00
y = TOINT(miny);
yend = TOINT(maxy);
2019-05-15 14:52:37 +00:00
// Go left in poly to find first edge b
b2 = a2;
for(i = 0; i < numVertices; i++){
b1 = b2--;
if(b2 < 0) b2 = numVertices-1;
if(poly[b1].x < xstart)
2020-08-21 07:40:31 +00:00
xstart = TOINT(poly[b1].x);
if(TOINT(poly[b1].y) != TOINT(poly[b2].y))
2019-05-15 14:52:37 +00:00
break;
}
// Go right to find first edge a
for(i = 0; i < numVertices; i++){
a1 = a2++;
if(a2 == numVertices) a2 = 0;
if(poly[a1].x > xend)
2020-08-21 07:40:31 +00:00
xend = TOINT(poly[a1].x);
if(TOINT(poly[a1].y) != TOINT(poly[a2].y))
2019-05-15 14:52:37 +00:00
break;
}
// prestep x1 and x2 to next integer y
deltaA = CalcNewDelta(&poly[a1], &poly[a2]);
xA = deltaA * (Ceil(poly[a1].y) - poly[a1].y) + poly[a1].x;
2019-05-15 14:52:37 +00:00
deltaB = CalcNewDelta(&poly[b1], &poly[b2]);
xB = deltaB * (Ceil(poly[b1].y) - poly[b1].y) + poly[b1].x;
2019-05-15 14:52:37 +00:00
if(y != yend){
2020-08-21 07:40:31 +00:00
if(deltaB < 0.0f && TOINT(xB) < xstart)
xstart = TOINT(xB);
if(deltaA >= 0.0f && TOINT(xA) > xend)
xend = TOINT(xA);
2019-05-15 14:52:37 +00:00
}
while(y <= yend && y < NUMSECTORS_Y){
// scan one x-line
if(y >= 0 && xstart < NUMSECTORS_X)
2020-08-13 14:29:42 +00:00
for(x = xstart; x <= xend && x != NUMSECTORS_X; x++)
if(x >= 0)
2019-05-15 14:52:37 +00:00
scanfunc(CWorld::GetSector(x, y)->m_lists);
// advance one scan line
y++;
xA += deltaA;
xB += deltaB;
// update left side
2020-08-21 07:40:31 +00:00
if(y == TOINT(poly[b2].y)){
2019-05-15 14:52:37 +00:00
// reached end of edge
if(y == yend){
if(deltaB < 0.0f){
do{
2020-08-21 07:40:31 +00:00
xstart = TOINT(poly[b2--].x);
2019-05-15 14:52:37 +00:00
if(b2 < 0) b2 = numVertices-1;
2020-08-21 07:40:31 +00:00
}while(xstart > TOINT(poly[b2].x));
2019-05-15 14:52:37 +00:00
}else
2020-08-21 07:40:31 +00:00
xstart = TOINT(xB - deltaB);
2019-05-15 14:52:37 +00:00
}else{
// switch edges
if(deltaB < 0.0f)
2020-08-21 07:40:31 +00:00
xstart = TOINT(poly[b2].x);
2019-05-15 14:52:37 +00:00
else
2020-08-21 07:40:31 +00:00
xstart = TOINT(xB - deltaB);
2019-05-15 14:52:37 +00:00
do{
b1 = b2--;
if(b2 < 0) b2 = numVertices-1;
2020-08-21 07:40:31 +00:00
if(TOINT(poly[b1].x) < xstart)
xstart = TOINT(poly[b1].x);
}while(y == TOINT(poly[b2].y));
2019-05-15 14:52:37 +00:00
deltaB = CalcNewDelta(&poly[b1], &poly[b2]);
xB = deltaB * (Ceil(poly[b1].y) - poly[b1].y) + poly[b1].x;
2020-08-21 07:40:31 +00:00
if(deltaB < 0.0f && TOINT(xB) < xstart)
xstart = TOINT(xB);
2019-05-15 14:52:37 +00:00
}
}else{
if(deltaB < 0.0f)
2020-08-21 07:40:31 +00:00
xstart = TOINT(xB);
2019-05-15 14:52:37 +00:00
else
2020-08-21 07:40:31 +00:00
xstart = TOINT(xB - deltaB);
2019-05-15 14:52:37 +00:00
}
// update right side
2020-08-21 07:40:31 +00:00
if(y == TOINT(poly[a2].y)){
2019-05-15 14:52:37 +00:00
// reached end of edge
if(y == yend){
if(deltaA < 0.0f)
2020-08-21 07:40:31 +00:00
xend = TOINT(xA - deltaA);
2019-05-15 14:52:37 +00:00
else{
do{
2020-08-21 07:40:31 +00:00
xend = TOINT(poly[a2++].x);
2019-05-15 14:52:37 +00:00
if(a2 == numVertices) a2 = 0;
2020-08-21 07:40:31 +00:00
}while(xend < TOINT(poly[a2].x));
2019-05-15 14:52:37 +00:00
}
}else{
// switch edges
if(deltaA < 0.0f)
2020-08-21 07:40:31 +00:00
xend = TOINT(xA - deltaA);
2019-05-15 14:52:37 +00:00
else
2020-08-21 07:40:31 +00:00
xend = TOINT(poly[a2].x);
2019-05-15 14:52:37 +00:00
do{
a1 = a2++;
if(a2 == numVertices) a2 = 0;
2020-08-21 07:40:31 +00:00
if(TOINT(poly[a1].x) > xend)
xend = TOINT(poly[a1].x);
}while(y == TOINT(poly[a2].y));
2019-05-15 14:52:37 +00:00
deltaA = CalcNewDelta(&poly[a1], &poly[a2]);
xA = deltaA * (Ceil(poly[a1].y) - poly[a1].y) + poly[a1].x;
2020-08-21 07:40:31 +00:00
if(deltaA >= 0.0f && TOINT(xA) > xend)
xend = TOINT(xA);
2019-05-15 14:52:37 +00:00
}
}else{
if(deltaA < 0.0f)
2020-08-21 07:40:31 +00:00
xend = TOINT(xA - deltaA);
2019-05-15 14:52:37 +00:00
else
2020-08-21 07:40:31 +00:00
xend = TOINT(xA);
2019-05-15 14:52:37 +00:00
}
}
}
2020-11-04 15:22:15 +00:00
void
CRenderer::InsertEntityIntoList(CEntity *ent)
{
#ifdef NEW_RENDERER
// TODO: there are more flags being checked here
if(gbNewRenderer && (ent->IsVehicle() || ent->IsPed()))
ms_aVisibleVehiclePtrs[ms_nNoOfVisibleVehicles++] = ent;
else if(gbNewRenderer && ent->IsBuilding())
ms_aVisibleBuildingPtrs[ms_nNoOfVisibleBuildings++] = ent;
else
#endif
ms_aVisibleEntityPtrs[ms_nNoOfVisibleEntities++] = ent;
}
2019-05-15 14:52:37 +00:00
void
CRenderer::ScanBigBuildingList(CPtrList &list)
{
CPtrNode *node;
CEntity *ent;
2020-05-11 15:03:32 +00:00
int vis;
2019-05-15 14:52:37 +00:00
2020-05-11 15:03:32 +00:00
int f = CTimer::GetFrameCounter() & 3;
for(node = list.first; node; node = node->next){
ent = (CEntity*)node->item;
2020-05-11 15:03:32 +00:00
if(ent->bOffscreen || (ent->m_randomSeed&3) != f){
ent->bOffscreen = true;
vis = SetupBigBuildingVisibility(ent);
}else
vis = VIS_VISIBLE;
switch(vis){
case VIS_VISIBLE:
2020-11-04 15:22:15 +00:00
InsertEntityIntoList(ent);
2020-05-11 15:03:32 +00:00
ent->bOffscreen = false;
break;
case VIS_STREAMME:
if(!CStreaming::ms_disableStreaming)
CStreaming::RequestModel(ent->GetModelIndex(), 0);
break;
}
}
2019-05-15 14:52:37 +00:00
}
void
CRenderer::ScanSectorList(CPtrList *lists)
{
CPtrNode *node;
CPtrList *list;
CEntity *ent;
int i;
float dx, dy;
for(i = 0; i < NUMSECTORENTITYLISTS; i++){
list = &lists[i];
for(node = list->first; node; node = node->next){
ent = (CEntity*)node->item;
if(ent->m_scanCode == CWorld::GetCurrentScanCode())
continue; // already seen
ent->m_scanCode = CWorld::GetCurrentScanCode();
2020-05-11 15:03:32 +00:00
ent->bOffscreen = false;
2019-05-15 14:52:37 +00:00
2020-05-06 10:23:57 +00:00
switch(SetupEntityVisibility(ent)){
case VIS_VISIBLE:
2020-11-04 15:22:15 +00:00
InsertEntityIntoList(ent);
2020-05-06 10:23:57 +00:00
break;
case VIS_INVISIBLE:
if(!IsGlass(ent->GetModelIndex()))
2019-05-15 14:52:37 +00:00
break;
2020-05-06 10:23:57 +00:00
// fall through
case VIS_OFFSCREEN:
2020-05-11 15:03:32 +00:00
ent->bOffscreen = true;
2020-05-06 10:23:57 +00:00
dx = ms_vecCameraPosition.x - ent->GetPosition().x;
dy = ms_vecCameraPosition.y - ent->GetPosition().y;
2020-05-11 15:03:32 +00:00
if(dx > -30.0f && dx < 30.0f &&
dy > -30.0f && dy < 30.0f &&
2020-05-06 10:23:57 +00:00
ms_nNoOfInVisibleEntities < NUMINVISIBLEENTITIES - 1)
ms_aInVisibleEntityPtrs[ms_nNoOfInVisibleEntities++] = ent;
break;
case VIS_STREAMME:
2019-05-15 14:52:37 +00:00
if(!CStreaming::ms_disableStreaming)
2020-05-06 10:23:57 +00:00
if(!m_loadingPriority || CStreaming::ms_numModelsRequested < 10)
CStreaming::RequestModel(ent->GetModelIndex(), 0);
break;
2019-05-15 14:52:37 +00:00
}
}
}
}
void
CRenderer::ScanSectorList_Priority(CPtrList *lists)
{
CPtrNode *node;
CPtrList *list;
CEntity *ent;
int i;
float dx, dy;
for(i = 0; i < NUMSECTORENTITYLISTS; i++){
list = &lists[i];
for(node = list->first; node; node = node->next){
ent = (CEntity*)node->item;
if(ent->m_scanCode == CWorld::GetCurrentScanCode())
continue; // already seen
ent->m_scanCode = CWorld::GetCurrentScanCode();
2020-05-11 15:03:32 +00:00
ent->bOffscreen = false;
2019-05-15 14:52:37 +00:00
2020-05-06 10:23:57 +00:00
switch(SetupEntityVisibility(ent)){
case VIS_VISIBLE:
2020-11-04 15:22:15 +00:00
InsertEntityIntoList(ent);
2020-05-06 10:23:57 +00:00
break;
case VIS_INVISIBLE:
if(!IsGlass(ent->GetModelIndex()))
2019-05-15 14:52:37 +00:00
break;
2020-05-06 10:23:57 +00:00
// fall through
case VIS_OFFSCREEN:
2020-05-11 15:03:32 +00:00
ent->bOffscreen = true;
2020-05-06 10:23:57 +00:00
dx = ms_vecCameraPosition.x - ent->GetPosition().x;
dy = ms_vecCameraPosition.y - ent->GetPosition().y;
2020-05-11 15:03:32 +00:00
if(dx > -30.0f && dx < 30.0f &&
dy > -30.0f && dy < 30.0f &&
2020-05-06 10:23:57 +00:00
ms_nNoOfInVisibleEntities < NUMINVISIBLEENTITIES - 1)
ms_aInVisibleEntityPtrs[ms_nNoOfInVisibleEntities++] = ent;
break;
case VIS_STREAMME:
if(!CStreaming::ms_disableStreaming){
CStreaming::RequestModel(ent->GetModelIndex(), 0);
if(CStreaming::ms_aInfoForModel[ent->GetModelIndex()].m_loadState != STREAMSTATE_LOADED)
m_loadingPriority = true;
2019-05-15 14:52:37 +00:00
}
2020-05-06 10:23:57 +00:00
break;
2019-05-15 14:52:37 +00:00
}
}
}
}
2020-05-11 15:03:32 +00:00
#ifdef GTA_TRAIN
2019-05-15 14:52:37 +00:00
void
CRenderer::ScanSectorList_Subway(CPtrList *lists)
{
CPtrNode *node;
CPtrList *list;
CEntity *ent;
int i;
float dx, dy;
for(i = 0; i < NUMSECTORENTITYLISTS; i++){
list = &lists[i];
for(node = list->first; node; node = node->next){
ent = (CEntity*)node->item;
if(ent->m_scanCode == CWorld::GetCurrentScanCode())
continue; // already seen
ent->m_scanCode = CWorld::GetCurrentScanCode();
2020-05-11 15:03:32 +00:00
ent->bOffscreen = false;
2019-05-15 14:52:37 +00:00
switch(SetupEntityVisibility(ent)){
case VIS_VISIBLE:
2020-11-04 15:22:15 +00:00
InsertEntityIntoList(ent);
2019-05-15 14:52:37 +00:00
break;
case VIS_OFFSCREEN:
2020-05-11 15:03:32 +00:00
ent->bOffscreen = true;
2019-05-15 14:52:37 +00:00
dx = ms_vecCameraPosition.x - ent->GetPosition().x;
dy = ms_vecCameraPosition.y - ent->GetPosition().y;
2020-05-11 15:03:32 +00:00
if(dx > -30.0f && dx < 30.0f &&
dy > -30.0f && dy < 30.0f &&
2019-11-02 23:13:29 +00:00
ms_nNoOfInVisibleEntities < NUMINVISIBLEENTITIES - 1)
2019-05-15 14:52:37 +00:00
ms_aInVisibleEntityPtrs[ms_nNoOfInVisibleEntities++] = ent;
break;
}
}
}
}
2020-05-11 15:03:32 +00:00
#endif
2019-05-15 14:52:37 +00:00
void
CRenderer::ScanSectorList_RequestModels(CPtrList *lists)
{
CPtrNode *node;
CPtrList *list;
CEntity *ent;
int i;
for(i = 0; i < NUMSECTORENTITYLISTS; i++){
list = &lists[i];
for(node = list->first; node; node = node->next){
ent = (CEntity*)node->item;
if(ent->m_scanCode == CWorld::GetCurrentScanCode())
continue; // already seen
ent->m_scanCode = CWorld::GetCurrentScanCode();
2020-05-11 15:03:32 +00:00
if(ShouldModelBeStreamed(ent, ms_vecCameraPosition))
2019-05-15 14:52:37 +00:00
CStreaming::RequestModel(ent->GetModelIndex(), 0);
}
}
}
// Put big buildings in front
// This seems pointless because the sector lists shouldn't have big buildings in the first place
void
CRenderer::SortBIGBuildings(void)
{
int x, y;
for(y = 0; y < NUMSECTORS_Y; y++)
for(x = 0; x < NUMSECTORS_X; x++){
SortBIGBuildingsForSectorList(&CWorld::GetSector(x, y)->m_lists[ENTITYLIST_BUILDINGS]);
SortBIGBuildingsForSectorList(&CWorld::GetSector(x, y)->m_lists[ENTITYLIST_BUILDINGS_OVERLAP]);
}
}
void
CRenderer::SortBIGBuildingsForSectorList(CPtrList *list)
{
CPtrNode *node;
CEntity *ent;
for(node = list->first; node; node = node->next){
ent = (CEntity*)node->item;
if(ent->bIsBIGBuilding){
list->RemoveNode(node);
list->InsertNode(node);
}
}
}
bool
2020-05-11 15:03:32 +00:00
CRenderer::ShouldModelBeStreamed(CEntity *ent, const CVector &campos)
2019-05-15 14:52:37 +00:00
{
2020-05-11 15:03:32 +00:00
if(!IsAreaVisible(ent->m_area))
return false;
CTimeModelInfo *mi = (CTimeModelInfo *)CModelInfo::GetModelInfo(ent->GetModelIndex());
if(mi->GetModelType() == MITYPE_TIME)
if(!CClock::GetIsTimeInRange(mi->GetTimeOn(), mi->GetTimeOff()))
return false;
float dist = (ent->GetPosition() - campos).Magnitude();
2019-05-15 14:52:37 +00:00
if(mi->m_noFade)
return dist - STREAM_DISTANCE < mi->GetLargestLodDistance();
else
return dist - FADE_DISTANCE - STREAM_DISTANCE < mi->GetLargestLodDistance();
}
void
CRenderer::RemoveVehiclePedLights(CEntity *ent, bool reset)
{
2020-05-19 18:56:42 +00:00
if(!ent->bRenderScorched){
CPointLights::RemoveLightsAffectingObject();
if(reset)
ReSetAmbientAndDirectionalColours();
}
SetAmbientColours();
DeActivateDirectional();
}