1 #include "pch.h"
2 #include "../ogre/common/Def_Str.h"
3 #include "../ogre/common/RenderConst.h"
4 #include "../ogre/common/data/CData.h"
5 #include "../vdrift/pathmanager.h"
6 #include "CApp.h"
7 #include "CGui.h"
8 #include "../ogre/common/GuiCom.h"
9 #include "../ogre/common/CScene.h"
10 #include "../ogre/common/Axes.h"
11 #include "../road/Road.h"
12 #include "../paged-geom/PagedGeometry.h"
13 #include "../ogre/common/WaterRTT.h"
14 #include "../ogre/common/RenderBoxScene.h"
15 #include "settings.h"
16 #include "../vdrift/track.h"
17 #include "../shiny/Main/Factory.hpp"
18 #include "../shiny/Platforms/Ogre/OgrePlatform.hpp"
19 #include "../shiny/Platforms/Ogre/OgreMaterial.hpp"
20 #include <OgreTerrainPaging.h>
21 #include <OgreTerrainGroup.h>
22 using namespace Ogre;
23 
24 
25 //  ctor
26 //----------------------------------------------------------------------------------------------------------------------
App(SETTINGS * pSet1)27 App::App(SETTINGS* pSet1)
28 	:mFactory(0)
29 	,bTerUpd(0), curBr(0), brLockPos(0)
30 	,vNew(0,0,0)
31 	,ndPos(0), mpos(0), asp(4.f/3.f)
32 	,ndCar(0),entCar(0), ndStBox(0),entStBox(0), ndFluidBox(0),entFluidBox(0), ndObjBox(0),entObjBox(0)
33 	,eTrkEvent(TE_None), bNewHmap(0), bTrGrUpd(0)
34 	,iFlCur(0), bRecreateFluids(0)
35 
36 	,bTerUpdBlend(0), track(0)
37 	,world(0), config(0), dispatcher(0), broadphase(0), solver(0)  //blt
38 	,trackObject(0), trackMesh(0)
39 	,mStaticGeom(0), mTimer(0.f), bUpdTerPrv(0)
40 	//  objs
41 	,iObjCur(-1), iObjTNew(0), iObjLast(0)
42 	,objSim(0), objEd(EO_Move)
43 	,inst(0)
44 {
45 	pSet = pSet1;
46 	Axes::Init();
47 
48 	mBrSize[0] = 16.f;	mBrSize[1] = 24.f;	mBrSize[2] = 16.f;	mBrSize[3] = 16.f;
49 	mBrIntens[0] = 20.f;mBrIntens[1] = 20.f;mBrIntens[2] = 20.f;mBrIntens[3] = 20.f;
50 	mBrPow[0] = 2.f;	mBrPow[1] = 2.f;	mBrPow[2] = 2.f;	mBrPow[3] = 2.f;
51 	mBrFq[0] = 1.f;		mBrFq[1] = 1.f;		mBrFq[2] = 1.f;		mBrFq[3] = 1.f;
52 	mBrNOf[0] = 0.f;	mBrNOf[1] = 0.f;	mBrNOf[2] = 0.f;	mBrNOf[3] = 0.f;
53 	mBrOct[0] = 5;		mBrOct[1] = 5;		mBrOct[2] = 5;		mBrOct[3] = 5;
54 	mBrShape[0] = BRS_Sinus;  mBrShape[1] = BRS_Sinus;
55 	mBrShape[2] = BRS_Sinus;  mBrShape[3] = BRS_Sinus;
56 	terSetH = 10.f;     mBrFilt = 2.f;  mBrFiltOld = 1.f;  pBrFmask = 0;
57 	mBrushData = new float[BrushMaxSize*BrushMaxSize];
58 	sBrushTest[0]=0;   updBrush();
59 	iSnap = 0;  angSnap = crAngSnaps[iSnap];
60 
61 	///  new
62 	scn = new CScene(this);
63 
64 	gcom = new CGuiCom(this);
65 	gcom->mGui = mGui;
66 	gcom->sc = scn->sc;
67 
68 	gui = new CGui(this);
69 	gui->viewBox = new wraps::RenderBoxScene();
70 	gui->gcom = gcom;
71 	gui->sc = scn->sc;
72 	gui->scn = scn;
73 	gui->data = scn->data;
74 
75 	track = new TRACK();  //!
76 }
77 
78 const Ogre::String App::csBrShape[BRS_ALL] = { "Triangle", "Sinus", "Noise", "Noise2", "N-gon" };  // static
79 
80 
81 ///  material factory setup
82 //---------------------------------------------------------------------------------------------------------------------------
postInit()83 void App::postInit()
84 {
85 	sh::OgrePlatform* platform = new sh::OgrePlatform("General", PATHMANAGER::Data() + "/" + "materials");
86 	platform->setCacheFolder(PATHMANAGER::ShaderDir());
87 
88 	mFactory = new sh::Factory(platform);
89 	SetFactoryDefaults();
90 
91 	mFactory->setMaterialListener(this);
92 }
93 
94 
~App()95 App::~App()
96 {
97 	DestroyObjects(false);
98 
99 	delete scn;
100 
101 	delete mFactory;  //!
102 
103 	gui->viewBox->destroy();
104 	delete gui->viewBox;
105 
106 	BltWorldDestroy();
107 
108 	delete track;  //!
109 	delete[] pBrFmask;  pBrFmask = 0;
110 
111 	delete[] mBrushData;
112 
113 	delete gcom;
114 	delete gui;
115 }
116 
117 
118 //  util
119 //---------------------------------------------------------------------------------------------------------------
Create2D(const String & mat,Real s,bool dyn)120 ManualObject* App::Create2D(const String& mat, Real s, bool dyn)
121 {
122 	ManualObject* m = mSceneMgr->createManualObject();
123 	m->setDynamic(dyn);
124 	m->setUseIdentityProjection(true);
125 	m->setUseIdentityView(true);
126 	m->setCastShadows(false);
127 	m->estimateVertexCount(4);
128 	m->begin(mat, RenderOperation::OT_TRIANGLE_STRIP);
129 	m->position(-s,-s*asp, 0);  m->textureCoord(0, 1);
130 	m->position( s,-s*asp, 0);  m->textureCoord(1, 1);
131 	m->position(-s, s*asp, 0);  m->textureCoord(0, 0);
132 	m->position( s, s*asp, 0);  m->textureCoord(1, 0);
133 	m->end();
134 
135 	AxisAlignedBox aabInf;	aabInf.setInfinite();
136 	m->setBoundingBox(aabInf);  // always visible
137 	m->setRenderQueueGroup(RQG_Hud2);
138 	return m;
139 }
140 
141 
materialCreated(sh::MaterialInstance * m,const std::string & configuration,unsigned short lodIndex)142 void App::materialCreated(sh::MaterialInstance* m, const std::string& configuration, unsigned short lodIndex)
143 {
144 	Ogre::Technique* t = static_cast<sh::OgreMaterial*>(m->getMaterial())->getOgreTechniqueForConfiguration (configuration, lodIndex);
145 
146 	if (pSet->shadow_type == Sh_None)
147 	{
148 		t->setShadowCasterMaterial("");
149 		return;
150 	}
151 
152 	/*if (m->hasProperty("transparent") && m->hasProperty("cull_hardware") &&
153 		sh::retrieveValue<sh::StringValue>(m->getProperty("cull_hardware"), 0).get() == "none")
154 	{
155 		// Crash !?
156 		assert(!MaterialManager::getSingleton().getByName("PSSM/shadow_caster_nocull").isNull ());
157 		t->setShadowCasterMaterial("shadowcaster_nocull");
158 	}*/
159 
160 	if (m->hasProperty("instancing") && sh::retrieveValue<sh::StringValue>(m->getProperty("instancing"), 0).get() == "true")
161 	{
162 		t->setShadowCasterMaterial("shadowcaster_instancing");
163 	}
164 
165 	if (!m->hasProperty("transparent") || !sh::retrieveValue<sh::BooleanValue>(m->getProperty("transparent"), 0).get())
166 	{
167 		t->setShadowCasterMaterial("shadowcaster_noalpha");
168 	}
169 }
170