1 #pragma once
2 #include <memory>
3 
4 #include "model_joe03.h"
5 #include "texture.h"
6 #include "joepack.h"
7 #include "tracksurface.h"
8 
9 #include "mathvector.h"
10 #include "quaternion.h"
11 #include "bezier.h"
12 #include "aabb.h"
13 #include "aabb_space_partitioning.h"
14 #include "optional.h"
15 
16 #include "track_object.h"
17 #include "roadstrip.h"
18 
19 class OBJECTLOADER;
20 
21 
22 ///------- for ogre
23 class OGRE_MESH
24 {
25 public:
26 	bool newMtr, sky, alpha, newM, found;
27 	std::string name, material;
28 	class VERTEXARRAY* mesh;
29 
30 	//bool operator<(const OGRE_MESH& other)
31 	//{
32 	//	return material < other.material;
33 	//}
34 };
35 ///-------
36 
37 
38 class TRACK
39 {
40 public:
41 	TRACK();
42 	~TRACK();
43 
44 	class GAME* pGame;  // for tire map
45 	bool asphalt;  // for car config switch
46 	std::string sDefaultTire;  //
47 
48 	void Clear();
49 
50 	///---- mesh list for ogre ----
51 	std::vector<OGRE_MESH> ogre_meshes;
52 
53 
54 	///returns true if successful.  only begins loading the track; the track won't be loaded until more calls to ContinueDeferredLoad().
55 	///  use Loaded() to see if loading is complete yet.
56 	bool DeferredLoad(
57 		const std::string & trackpath,
58 		bool reverse,
59 		int anisotropy,
60 		const std::string & texsize,
61 		bool shadows,
62 		bool doagressivecombining);
63 
64 	bool ContinueDeferredLoad();
65 
66 	int DeferredLoadTotalObjects();
67 
68 
Loaded()69 	bool Loaded() const
70 	{
71 		return loaded;
72 	}
73 
74 	bool CastRay(
75 		const MATHVECTOR<float,3> & origin,
76 		const MATHVECTOR<float,3> & direction,
77 		float seglen, MATHVECTOR<float,3> & outtri,
78 		const BEZIER * & colpatch,
79 		MATHVECTOR<float,3> & normal) const;
80 
GetRoadList()81 	const std::list <ROADSTRIP> & GetRoadList() const
82 	{
83 		return roads;
84 	}
85 
Unload()86 	void Unload()
87 	{
88 		Clear();
89 	}
90 
GetTrackObjects()91 	const std::list<TRACK_OBJECT> & GetTrackObjects()
92 	{
93 		return objects;
94 	}
95 
96 private:
97 
98 	std::string texture_size;
99 public:
100 	std::map <std::string, MODEL_JOE03> model_library;
101 private:
102 	std::map <std::string, TEXTURE_GL> texture_library;
103 	std::list <TRACK_OBJECT> objects;
104 
105 private:
106 
107 	//road information
108 	std::list <ROADSTRIP> roads;
109 
110 	bool LoadObjects(
111 		const std::string & trackpath,
112 		//SCENENODE & sceneroot,
113 		int anisotropy);
114 
115 	std::auto_ptr <OBJECTLOADER> objload;
116 
117 	///returns false on error
118 	bool BeginObjectLoad(
119 		const std::string & trackpath,
120 		int anisotropy,
121 		bool dynamicshadowsenabled,
122 		bool doagressivecombining);
123 
124 	///returns a pair of bools: the first bool is true if there was an error, the second bool is true if an object was loaded
125 	std::pair <bool, bool> ContinueObjectLoad();
126 
127 	bool LoadRoads(const std::string & trackpath, bool reverse);
128 
ClearRoads()129 	void ClearRoads() {  roads.clear();  }
130 
131 	///read from the file stream and put it in "output".
132 	/// return true if the get was successful, else false
133 	template <typename T>
GetParam(std::ifstream & f,T & output)134 	bool GetParam(std::ifstream & f, T & output)
135 	{
136 		if (!f.good())
137 			return false;
138 
139 		std::string instr;
140 		f >> instr;
141 		if (instr.empty())
142 			return false;
143 
144 		while (!instr.empty() && instr[0] == '#' && f.good())
145 		{
146 			f.ignore(1024, '\n');
147 			f >> instr;
148 		}
149 
150 		if (!f.good() && !instr.empty() && instr[0] == '#')
151 			return false;
152 
153 		std::stringstream sstr(instr);
154 		sstr >> output;
155 		return true;
156 	}
157 
158 	bool loaded;
159 };
160