1 #pragma once
2 #include "joepack.h"
3 #include "model_joe03.h"
4 #include "track_object.h"
5 #include "tracksurface.h"
6 
7 class TRACK;
8 
9 class OBJECTLOADER
10 {
11 public:
12 	OBJECTLOADER(
13 		const std::string & ntrackpath,
14 		int nanisotropy,
15 		bool newdynamicshadowsenabled,
16 		bool newcull,
17 		bool doagressivecombining);
18 
GetError()19 	bool GetError() const
20 	{
21 		return error;
22 	}
23 
GetNumObjects()24 	int GetNumObjects() const
25 	{
26 		return numobjects;
27 	}
28 
29 	///returns false on error
30 	bool BeginObjectLoad();
31 
32 	///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
33 	std::pair <bool,bool> ContinueObjectLoad( TRACK* track,
34 		std::map <std::string, MODEL_JOE03> & model_library,
35 		std::map <std::string, TEXTURE_GL> & texture_library,
36 		std::list <TRACK_OBJECT> & objects,
37 		const std::string & texture_size);
38 
39 	bool GetSurfacesBool();
40 
41 private:
42 	const std::string & trackpath;
43 	std::string objectpath;
44 
45 	JOEPACK pack;
46 	std::ifstream objectfile;
47 
48 	bool error;
49 	int numobjects;
50 	bool packload;
51 	int anisotropy;
52 	bool cull;
53 
54 	int params_per_object;
55 	const int expected_params;
56 	const int min_params;
57 
58 	bool dynamicshadowsenabled;
59 	bool agressivecombine;
60 
61 	void CalculateNumObjects();
62 
63 	///read from the file stream and put it in "output".
64 	/// return true if the get was successful, else false
65 	template <typename T>
GetParam(std::ifstream & f,T & output)66 	bool GetParam(std::ifstream & f, T & output)
67 	{
68 		if (!f.good())
69 			return false;
70 
71 		std::string instr;
72 		f >> instr;
73 		if (instr.empty())
74 			return false;
75 
76 		while (!instr.empty() && instr[0] == '#' && f.good())
77 		{
78 			f.ignore(1024, '\n');
79 			f >> instr;
80 		}
81 
82 		if (!f.good() && !instr.empty() && instr[0] == '#')
83 			return false;
84 
85 		std::stringstream sstr(instr);
86 		sstr >> output;
87 		return true;
88 	}
89 };
90