summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/core/FileLoader.cpp344
-rw-r--r--src/core/config.h3
-rw-r--r--src/extras/custompipes.cpp2
-rw-r--r--src/modelinfo/BaseModelInfo.h8
-rw-r--r--src/render/Renderer.cpp29
-rw-r--r--src/rw/RwHelper.cpp24
-rw-r--r--src/rw/RwHelper.h2
-rw-r--r--src/rw/VisibilityPlugins.cpp9
8 files changed, 418 insertions, 3 deletions
diff --git a/src/core/FileLoader.cpp b/src/core/FileLoader.cpp
index ff50575f..aadafc29 100644
--- a/src/core/FileLoader.cpp
+++ b/src/core/FileLoader.cpp
@@ -1,6 +1,7 @@
#include "common.h"
#include "main.h"
+#include "General.h"
#include "Quaternion.h"
#include "ModelInfo.h"
#include "ModelIndices.h"
@@ -449,6 +450,334 @@ CFileLoader::LoadAtomicFile(RwStream *stream, uint32 id)
return true;
}
+#ifdef HARDCODED_MODEL_FLAGS
+char *DoubleSidedNames[] = {
+ "chnabankdoor",
+ "Security_Hut",
+ "Hospital_Sub",
+ "phonebooth1",
+ "trafficlight1",
+ "sub_roadbarrier",
+ "redlightbuild09",
+ "doublestreetlght1",
+ "doc_shedbig31",
+ "com_land_128",
+ "garage7",
+ "proj_garage01",
+ "buildingground2",
+ "buildingground3",
+ "ch_roof_kb",
+ "overpassind",
+ "casino",
+ "ind_land100",
+ "fuckedup_skewlbus",
+ "Police_Station_ind",
+ "flagsitaly",
+ "sidebarrier_gaz1",
+ "bar_barrier12",
+ "bar_barrier10b",
+ "sidebarrier_gaz2",
+ "doc_shedbig3",
+ "doc_shedbig4",
+ "verticalift_bridge",
+ "verticalift_bridg2",
+ "usdcrdlrbuild01",
+ "apairporthanger",
+ "apairporthangerA",
+ "porthangerclosed",
+ "redlightbuild13",
+ "doc_rave",
+ "const_woodfence",
+ "const_woodfence2",
+ "const_woodfence3",
+ "subfraightback01",
+ "subfraightback02",
+ "subfraightback03",
+ "subfraightback04",
+ "subind_build03",
+ "chinabanner1",
+ "chinabanner2",
+ "chinabanner3",
+ "chinabanner4",
+ "Pumpfirescape",
+ "Pumphouse",
+ "amcounder",
+ "barrel1",
+ "barrel2",
+ "barrel3",
+ "barrel4",
+ "com_1way50",
+ "com_1way20",
+ "overpasscom01",
+ "overpasscom02",
+ "overpasscom03",
+ "overpasscom04",
+ "overpass_comse",
+ "newdockbuilding",
+ "newdockbuilding2",
+ "newdockbuilding",
+ "policeballhall",
+ "fuzballdoor",
+ "ind_land106",
+ "PoliceBallSigns",
+ "amcoudet",
+ "rustship_structure",
+ "impexpgrgesub",
+ "ind_land128",
+ "fshfctry_dstryd",
+ "railtrax_bentl",
+ "railtrax_lo4b",
+ "railtrax_straight",
+ "railtrax_bentrb",
+ "railtrax_skew",
+ "newtrackaaa",
+ "railtrax_skew5",
+ // these they forgot:
+ "railtrax_skewp",
+ "railtrax_ske2b",
+ "railtrax_strtshort",
+ "railtrax_2b",
+ "railtrax_straightss",
+ "railtrax_bentr",
+ ""
+};
+char *TreeNames[] = {
+ "coast_treepatch",
+ "comparknewtrees",
+ "comtreepatchprk",
+ "condotree01",
+ "condotree1",
+ "indatree03",
+ "indtreepatch5",
+ "indtreepatch06f",
+ "new_carprktrees",
+ "new_carprktrees4",
+ "newcoasttrees1",
+ "newcoasttrees2",
+ "newcoasttrees3",
+ "newtreepatch_sub",
+ "newtrees1_sub",
+ "newunitrepatch",
+ "pinetree_narrow",
+ "pinetree_wide",
+ "treencom2",
+ "treepatch",
+ "treepatch01_sub",
+ "treepatch02_sub",
+ "treepatch2",
+ "treepatch2b",
+ "treepatch03",
+ "treepatch03_sub",
+ "treepatch04_sub",
+ "treepatch05_sub",
+ "treepatch06_sub",
+ "treepatch07_sub",
+ "treepatch08_sub",
+ "treepatch09_sub",
+ "treepatch10_sub",
+ "treepatch11_sub",
+ "treepatch12_sub",
+ "treepatch13_sub",
+ "treepatch14_sub",
+ "treepatch15_sub",
+ "treepatch16_sub",
+ "treepatch17_sub",
+ "treepatch18_sub",
+ "treepatch19_sub",
+ "treepatch20_sub",
+ "treepatch21_sub",
+ "treepatch22_sub",
+ "treepatch23_sub",
+ "treepatch24_sub",
+ "treepatch25_sub",
+ "treepatch26_sub",
+ "treepatch27_sub",
+ "treepatch28_sub",
+ "treepatch29_sub",
+ "treepatch30_sub",
+ "treepatch31_sub",
+ "treepatch32_sub",
+ "treepatch33_sub",
+ "treepatch34_sub",
+ "treepatch35_sub",
+ "treepatch69",
+ "treepatch152_sub",
+ "treepatch153_sub",
+ "treepatch171_sub",
+ "treepatch172_sub",
+ "treepatch173_sub",
+ "treepatch212_sub",
+ "treepatch213_sub",
+ "treepatch214_sub",
+ "treepatcha",
+ "treepatchb",
+ "treepatchcomtop1",
+ "treepatchd",
+ "treepatche",
+ "treepatchh",
+ "treepatchindaa2",
+ "treepatchindnew",
+ "treepatchindnew2",
+ "treepatchk",
+ "treepatchkb4",
+ "treepatchkb5",
+ "treepatchkb6",
+ "treepatchkb7",
+ "treepatchkb9",
+ "treepatchl",
+ "treepatchm",
+ "treepatchnew_sub",
+ "treepatchttwrs",
+ "treesuni1",
+ "trepatchindaa1",
+ "veg_bush2",
+ "veg_bush14",
+ "veg_tree1",
+ "veg_tree3",
+ "veg_treea1",
+ "veg_treea3",
+ "veg_treeb1",
+ "veg_treenew01",
+ "veg_treenew03",
+ "veg_treenew05",
+ "veg_treenew06",
+ "veg_treenew08",
+ "veg_treenew09",
+ "veg_treenew10",
+ "veg_treenew16",
+ "veg_treenew17",
+ "vegclubtree01",
+ "vegclubtree02",
+ "vegclubtree03",
+ "vegpathtree",
+ ""
+};
+char *OptimizedNames[] = {
+ "coast_treepatch",
+ "comparknewtrees",
+ "comtreepatchprk",
+ "indtreepatch5",
+ "indtreepatch06f",
+ "new_carprktrees",
+ "new_carprktrees4",
+ "newcoasttrees1",
+ "newcoasttrees2",
+ "newcoasttrees3",
+ "newtreepatch_sub",
+ "newtrees1_sub",
+ "newunitrepatch",
+ "treepatch",
+ "treepatch01_sub",
+ "treepatch02_sub",
+ "treepatch2",
+ "treepatch2b",
+ "treepatch03",
+ "treepatch03_sub",
+ "treepatch04_sub",
+ "treepatch05_sub",
+ "treepatch06_sub",
+ "treepatch07_sub",
+ "treepatch08_sub",
+ "treepatch09_sub",
+ "treepatch10_sub",
+ "treepatch11_sub",
+ "treepatch12_sub",
+ "treepatch13_sub",
+ "treepatch14_sub",
+ "treepatch15_sub",
+ "treepatch16_sub",
+ "treepatch17_sub",
+ "treepatch18_sub",
+ "treepatch19_sub",
+ "treepatch20_sub",
+ "treepatch21_sub",
+ "treepatch22_sub",
+ "treepatch23_sub",
+ "treepatch24_sub",
+ "treepatch25_sub",
+ "treepatch26_sub",
+ "treepatch27_sub",
+ "treepatch28_sub",
+ "treepatch29_sub",
+ "treepatch30_sub",
+ "treepatch31_sub",
+ "treepatch32_sub",
+ "treepatch33_sub",
+ "treepatch34_sub",
+ "treepatch35_sub",
+ "treepatch69",
+ "treepatch152_sub",
+ "treepatch153_sub",
+ "treepatch171_sub",
+ "treepatch172_sub",
+ "treepatch173_sub",
+ "treepatch212_sub",
+ "treepatch213_sub",
+ "treepatch214_sub",
+ "treepatcha",
+ "treepatchb",
+ "treepatchcomtop1",
+ "treepatchd",
+ "treepatche",
+ "treepatchh",
+ "treepatchindaa2",
+ "treepatchindnew",
+ "treepatchindnew2",
+ "treepatchk",
+ "treepatchkb4",
+ "treepatchkb5",
+ "treepatchkb6",
+ "treepatchkb7",
+ "treepatchkb9",
+ "treepatchl",
+ "treepatchm",
+ "treepatchnew_sub",
+ "treepatchttwrs",
+ "treesuni1",
+ "trepatchindaa1",
+ "combtm_treeshad01",
+ "combtm_treeshad02",
+ "combtm_treeshad03",
+ "combtm_treeshad04",
+ "combtm_treeshad05",
+ "combtm_treeshad06",
+ "comtop_tshad",
+ "comtop_tshad2",
+ "comtop_tshad3",
+ "comtop_tshad4",
+ "comtop_tshad5",
+ "comtop_tshad6",
+ "se_treeshad01",
+ "se_treeshad02",
+ "se_treeshad03",
+ "se_treeshad04",
+ "se_treeshad05",
+ "se_treeshad06",
+ "treeshads01",
+ "treeshads02",
+ "treeshads03",
+ "treeshads04",
+ "treeshads05",
+ ""
+};
+// not from mobile
+static bool
+MatchModelName(char *name, char **list)
+{
+ int i;
+ char *s;
+ for(i = 0; *list[i] != '\0'; i++)
+ if(strncmp(name, "LOD", 3) == 0){
+ if(!CGeneral::faststricmp(name+3, list[i]+3))
+ return true;
+ }else{
+ if(!CGeneral::faststricmp(name, list[i]))
+ return true;
+ }
+ return false;
+}
+#endif
+
RpAtomic*
CFileLoader::SetRelatedModelInfoCB(RpAtomic *atomic, void *data)
{
@@ -600,6 +929,21 @@ SetModelInfoFlags(CSimpleModelInfo *mi, uint32 flags)
mi->m_isSubway = !!(flags & 0x10);
mi->m_ignoreLight = !!(flags & 0x20);
mi->m_noZwrite = !!(flags & 0x40);
+#ifdef EXTRA_MODEL_FLAGS
+ // same flag values as SA
+ mi->m_bIsTree = !!(flags & 0x2000);
+ mi->m_bIsDoubleSided = !!(flags & 0x200000);
+ // new value otherwise unused
+ mi->m_bCanBeIgnored = !!(flags & 0x10000);
+
+#ifdef HARDCODED_MODEL_FLAGS
+ // mobile sets these flags in CFileLoader::SetRelatedModelInfoCB, but that's stupid
+ if(MatchModelName(mi->GetName(), DoubleSidedNames)) mi->m_bIsDoubleSided = true;
+ if(MatchModelName(mi->GetName(), TreeNames)) mi->m_bIsTree = true;
+ if(MatchModelName(mi->GetName(), OptimizedNames)) mi->m_bCanBeIgnored = true;
+#endif
+
+#endif
}
void
diff --git a/src/core/config.h b/src/core/config.h
index 019ff659..ea4330a4 100644
--- a/src/core/config.h
+++ b/src/core/config.h
@@ -218,6 +218,9 @@ enum Config {
#define LOAD_INI_SETTINGS
// Rendering/display
+//#define EXTRA_MODEL_FLAGS // from mobile to optimize rendering
+//# define HARDCODED_MODEL_FLAGS // sets the flags enabled above from hardcoded model names.
+ // NB: keep this enabled unless your map IDEs have these flags baked in
#define ASPECT_RATIO_SCALE // Not just makes everything scale with aspect ratio, also adds support for all aspect ratios
#define DEFAULT_NATIVE_RESOLUTION // Set default video mode to your native resolution (fixes Windows 10 launch)
#define USE_TXD_CDIMAGE // generate and load textures from txd.img
diff --git a/src/extras/custompipes.cpp b/src/extras/custompipes.cpp
index b545b4d8..8c2b6916 100644
--- a/src/extras/custompipes.cpp
+++ b/src/extras/custompipes.cpp
@@ -337,7 +337,7 @@ ReadTweakValueTable(char *fp, InterpolatedValue &interp)
* Neo Vehicle pipe
*/
-int32 VehiclePipeSwitch = VEHICLEPIPE_NEO;
+int32 VehiclePipeSwitch = VEHICLEPIPE_MATFX;
float VehicleShininess = 0.7f; // the default is a bit extreme
float VehicleSpecularity = 1.0f;
InterpolatedFloat Fresnel(0.4f);
diff --git a/src/modelinfo/BaseModelInfo.h b/src/modelinfo/BaseModelInfo.h
index 783f871f..2505967b 100644
--- a/src/modelinfo/BaseModelInfo.h
+++ b/src/modelinfo/BaseModelInfo.h
@@ -31,6 +31,14 @@ protected:
ModelInfoType m_type;
uint8 m_num2dEffects;
bool m_bOwnsColModel;
+#ifdef EXTRA_MODEL_FLAGS
+public:
+ // from mobile
+ bool m_bIsDoubleSided;
+ bool m_bIsTree;
+ bool m_bCanBeIgnored; // for low-end devices
+ bool RenderDoubleSided(void) { return m_bIsDoubleSided || m_bIsTree; }
+#endif
public:
CBaseModelInfo(ModelInfoType type);
diff --git a/src/render/Renderer.cpp b/src/render/Renderer.cpp
index 8c194067..4ad1d3b9 100644
--- a/src/render/Renderer.cpp
+++ b/src/render/Renderer.cpp
@@ -53,6 +53,14 @@ CVehicle *CRenderer::m_pFirstPersonVehicle;
bool CRenderer::m_loadingPriority;
float CRenderer::ms_lodDistScale = 1.2f;
+#ifdef EXTRA_MODEL_FLAGS
+#define BACKFACE_CULLING_ON SetCullMode(rwCULLMODECULLBACK)
+#define BACKFACE_CULLING_OFF SetCullMode(rwCULLMODECULLNONE)
+#else
+#define BACKFACE_CULLING_ON
+#define BACKFACE_CULLING_OFF
+#endif
+
void
CRenderer::Init(void)
{
@@ -102,6 +110,13 @@ CRenderer::RenderOneRoad(CEntity *e)
#ifdef EXTENDED_PIPELINES
CustomPipes::AttachGlossPipe(e->GetAtomic());
#endif
+#ifdef EXTRA_MODEL_FLAGS
+ if(CModelInfo::GetModelInfo(e->GetModelIndex())->RenderDoubleSided()){
+ BACKFACE_CULLING_OFF;
+ e->Render();
+ BACKFACE_CULLING_ON;
+ }else
+#endif
e->Render();
}
}
@@ -163,13 +178,22 @@ CRenderer::RenderOneNonRoad(CEntity *e)
for(i = 0; i < 8; i++)
if(veh->pPassengers[i] && veh->pPassengers[i]->m_nPedState == PED_DRIVING)
veh->pPassengers[i]->Render();
+ BACKFACE_CULLING_OFF;
}
+#ifdef EXTRA_MODEL_FLAGS
+ if(CModelInfo::GetModelInfo(e->GetModelIndex())->RenderDoubleSided()){
+ BACKFACE_CULLING_OFF;
+ e->Render();
+ BACKFACE_CULLING_ON;
+ }else
+#endif
e->Render();
if(e->IsVehicle()){
e->bImBeingRendered = true;
CVisibilityPlugins::RenderAlphaAtomics();
e->bImBeingRendered = false;
+ BACKFACE_CULLING_ON;
}
e->RemoveLighting(resetLights);
@@ -197,6 +221,7 @@ CRenderer::RenderRoads(void)
CTreadable *t;
RwRenderStateSet(rwRENDERSTATEFOGENABLE, (void*)TRUE);
+ BACKFACE_CULLING_ON;
DeActivateDirectional();
SetAmbientColours();
@@ -230,6 +255,7 @@ CRenderer::RenderEverythingBarRoads(void)
CVector dist;
EntityInfo ei;
+ BACKFACE_CULLING_ON;
gSortedVehiclesAndPeds.Clear();
for(i = 0; i < ms_nNoOfVisibleEntities; i++){
@@ -284,6 +310,8 @@ CRenderer::RenderBoats(void)
{
CLink<EntityInfo> *node;
+ BACKFACE_CULLING_ON;
+
for(node = gSortedVehiclesAndPeds.tail.prev;
node != &gSortedVehiclesAndPeds.head;
node = node->prev){
@@ -298,6 +326,7 @@ void
CRenderer::RenderFadingInEntities(void)
{
RwRenderStateSet(rwRENDERSTATEFOGENABLE, (void*)TRUE);
+ BACKFACE_CULLING_ON;
DeActivateDirectional();
SetAmbientColours();
CVisibilityPlugins::RenderFadingEntities();
diff --git a/src/rw/RwHelper.cpp b/src/rw/RwHelper.cpp
index dbadae6a..35af1ebd 100644
--- a/src/rw/RwHelper.cpp
+++ b/src/rw/RwHelper.cpp
@@ -3,6 +3,7 @@
#endif
#include "common.h"
+#include "RwHelper.h"
#include "Timecycle.h"
#include "skeleton.h"
#include "Debug.h"
@@ -18,6 +19,7 @@ bool gPS2alphaTest = true;
#else
bool gPS2alphaTest = false;
#endif
+bool gBackfaceCulling = true;
#if !defined(FINAL) || defined(DEBUGMENU)
static bool charsetOpen;
@@ -123,14 +125,32 @@ DefinedState(void)
#ifdef LIBRW
rw::SetRenderState(rw::ALPHATESTFUNC, rw::ALPHAGREATEREQUAL);
- rw::SetRenderState(rw::ALPHATESTREF, 3);
rw::SetRenderState(rw::GSALPHATEST, gPS2alphaTest);
#else
// D3D stuff
RwD3D8SetRenderState(D3DRS_ALPHAFUNC, D3DCMP_GREATER);
- RwD3D8SetRenderState(D3DRS_ALPHAREF, 2);
#endif
+ SetAlphaRef(2);
+}
+
+void
+SetAlphaRef(int ref)
+{
+#ifdef LIBRW
+ rw::SetRenderState(rw::ALPHATESTREF, ref+1);
+#else
+ RwD3D8SetRenderState(D3DRS_ALPHAREF, ref);
+#endif
+}
+
+void
+SetCullMode(uint32 mode)
+{
+ if(gBackfaceCulling)
+ RwRenderStateSet(rwRENDERSTATECULLMODE, (void*)mode);
+ else
+ RwRenderStateSet(rwRENDERSTATECULLMODE, (void*)rwCULLMODECULLNONE);
}
RwFrame*
diff --git a/src/rw/RwHelper.h b/src/rw/RwHelper.h
index eceaee07..130eb636 100644
--- a/src/rw/RwHelper.h
+++ b/src/rw/RwHelper.h
@@ -11,6 +11,8 @@ void DestroyDebugFont();
void ObrsPrintfString(const char *str, short x, short y);
void FlushObrsPrintfs();
void DefinedState(void);
+void SetAlphaRef(int ref);
+void SetCullMode(uint32 mode);
RwFrame *GetFirstChild(RwFrame *frame);
RwObject *GetFirstObject(RwFrame *frame);
RpAtomic *GetFirstAtomic(RpClump *clump);
diff --git a/src/rw/VisibilityPlugins.cpp b/src/rw/VisibilityPlugins.cpp
index b2e252a0..8878a26a 100644
--- a/src/rw/VisibilityPlugins.cpp
+++ b/src/rw/VisibilityPlugins.cpp
@@ -1,5 +1,6 @@
#include "common.h"
+#include "RwHelper.h"
#include "templates.h"
#include "Entity.h"
#include "ModelInfo.h"
@@ -158,6 +159,10 @@ CVisibilityPlugins::RenderFadingEntities(void)
if(mi->m_noZwrite)
#endif
RwRenderStateSet(rwRENDERSTATEZWRITEENABLE, FALSE);
+#ifdef EXTRA_MODEL_FLAGS
+ else if(mi->m_bIsTree)
+ SetAlphaRef(128);
+#endif
if(e->bDistanceFade){
DeActivateDirectional();
@@ -168,6 +173,10 @@ CVisibilityPlugins::RenderFadingEntities(void)
}else
CRenderer::RenderOneNonRoad(e);
+#ifdef EXTRA_MODEL_FLAGS
+ if(mi->m_bIsTree)
+ SetAlphaRef(2);
+#endif
#ifdef FIX_BUGS
if(mi->GetModelType() == MITYPE_SIMPLE && mi->m_noZwrite)
#else