| 1 | cycrow | 1 | /*
 | 
        
           |  |  | 2 |   defines the bod_bob_parser - class that can parse bod format and create 
 | 
        
           |  |  | 3 |   bob_dom_bob object
 | 
        
           |  |  | 4 | */
 | 
        
           |  |  | 5 |   | 
        
           |  |  | 6 | #ifndef BOD_BOB_PARSER_INCLUDED
 | 
        
           |  |  | 7 | #define BOD_BOB_PARSER_INCLUDED
 | 
        
           |  |  | 8 |   | 
        
           |  |  | 9 | #include "bob_dom_bob.h"
 | 
        
           |  |  | 10 | #include "bod_text_parser.h"
 | 
        
           |  |  | 11 | #include "token_stream.h"
 | 
        
           |  |  | 12 | #include "settings.h"
 | 
        
           |  |  | 13 | #include "bod_parser_base.h"
 | 
        
           |  |  | 14 |   | 
        
           |  |  | 15 | class bod_bob_parser : public bod_parser_base
 | 
        
           |  |  | 16 | {
 | 
        
           |  |  | 17 | 	private:
 | 
        
           |  |  | 18 | 		struct texture_coord_t
 | 
        
           |  |  | 19 | 		{
 | 
        
           |  |  | 20 | 			int x;
 | 
        
           |  |  | 21 | 			int y;
 | 
        
           |  |  | 22 | 			int index;
 | 
        
           |  |  | 23 | 		};
 | 
        
           |  |  | 24 |   | 
        
           |  |  | 25 | 		struct texture_coords_t : public ext::simple_list<texture_coord_t*>
 | 
        
           |  |  | 26 | 		{
 | 
        
           |  |  | 27 | 			int flag;
 | 
        
           |  |  | 28 | 			texture_coord_t * findCoords(int x, int y)
 | 
        
           |  |  | 29 | 			{
 | 
        
           |  |  | 30 | 				for(iterator &it=begin(); it!=end(); ++it){
 | 
        
           |  |  | 31 | 					if(it->x==x && it->y==y)
 | 
        
           |  |  | 32 | 						return *it;
 | 
        
           |  |  | 33 | 				}
 | 
        
           |  |  | 34 | 				return 0;
 | 
        
           |  |  | 35 | 			}
 | 
        
           |  |  | 36 |   | 
        
           |  |  | 37 | 			~texture_coords_t()
 | 
        
           |  |  | 38 | 			{
 | 
        
           |  |  | 39 | 				for(iterator &it=begin(); it!=end(); ++it){
 | 
        
           |  |  | 40 | 					delete *it;
 | 
        
           |  |  | 41 | 				}
 | 
        
           |  |  | 42 | 			}
 | 
        
           |  |  | 43 | 		};
 | 
        
           |  |  | 44 |   | 
        
           |  |  | 45 | 		struct point_t : public ext::simple_list<texture_coords_t*>
 | 
        
           |  |  | 46 | 		{
 | 
        
           |  |  | 47 | 			int x, y, z;
 | 
        
           |  |  | 48 |   | 
        
           |  |  | 49 | 			point_t() {}
 | 
        
           |  |  | 50 | 			point_t(int x, int y, int z) { this->x=x; this->y=y; this->z=z; }
 | 
        
           |  |  | 51 |   | 
        
           |  |  | 52 | 			~point_t()
 | 
        
           |  |  | 53 | 			{
 | 
        
           |  |  | 54 | 				for(iterator &it=begin(); it!=end(); ++it){
 | 
        
           |  |  | 55 | 					delete *it;
 | 
        
           |  |  | 56 | 				}
 | 
        
           |  |  | 57 | 			}
 | 
        
           |  |  | 58 |   | 
        
           |  |  | 59 | 			texture_coords_t * findTextureCoords(int flag)
 | 
        
           |  |  | 60 | 			{
 | 
        
           |  |  | 61 | 				for(iterator &it=begin(); it!=end(); ++it){
 | 
        
           |  |  | 62 | 					if(it->flag==flag) return *it;
 | 
        
           |  |  | 63 | 				}
 | 
        
           |  |  | 64 | 				texture_coords_t *coords=new texture_coords_t();
 | 
        
           |  |  | 65 | 				coords->flag=flag;
 | 
        
           |  |  | 66 | 				push_back(coords);
 | 
        
           |  |  | 67 | 				return coords;
 | 
        
           |  |  | 68 | 			}
 | 
        
           |  |  | 69 |   | 
        
           |  |  | 70 | 			size_t pointCount() const
 | 
        
           |  |  | 71 | 			{
 | 
        
           |  |  | 72 | 				size_t c=0;
 | 
        
           |  |  | 73 | 				for(const_iterator &it=begin(); it!=end(); ++it){
 | 
        
           |  |  | 74 | 					c+=it->size();
 | 
        
           |  |  | 75 | 				}
 | 
        
           |  |  | 76 | 				return c;
 | 
        
           |  |  | 77 | 			}
 | 
        
           |  |  | 78 | 		};
 | 
        
           |  |  | 79 |   | 
        
           |  |  | 80 | 	protected:
 | 
        
           |  |  | 81 | 		const Settings *m_settings;
 | 
        
           |  |  | 82 |   | 
        
           |  |  | 83 | 		bool checkImmediatePlacement(const bod_bob_parser::token *token1, const bod_bob_parser::token *token2);
 | 
        
           |  |  | 84 |   | 
        
           |  |  | 85 | 	private:
 | 
        
           |  |  | 86 | 		typedef ext::simple_list<point_t*> PointList;
 | 
        
           |  |  | 87 | 		typedef ext::array<point_t*> PointArray;
 | 
        
           |  |  | 88 | 		typedef ext::array<bob_dom_weight*> WeightArray;
 | 
        
           |  |  | 89 |   | 
        
           |  |  | 90 | 		const bob_dom_materials *m_materials;
 | 
        
           |  |  | 91 | 		PointArray m_points;
 | 
        
           |  |  | 92 | 		WeightArray m_weights;
 | 
        
           |  |  | 93 |   | 
        
           |  |  | 94 | 	private:
 | 
        
           |  |  | 95 | 		bool loadMatRGB(token_stream& is, bob_dom_material5::rgb& rgb);
 | 
        
           |  |  | 96 | 		bool loadMatPair(token_stream& is, bob_dom_material5::pair& pair);
 | 
        
           |  |  | 97 | 		bool loadMatPair(token_stream& is, bob_dom_material6::Small::pair& pair);
 | 
        
           |  |  | 98 | 		bool loadMat(bob_dom_material5 *mat, token_stream &is);
 | 
        
           |  |  | 99 | 		bool loadMat(bob_dom_material6 *mat, token_stream &is);
 | 
        
           |  |  | 100 | 		bool loadMaterial(bob_dom_bob *bob, token_stream& is);
 | 
        
           |  |  | 101 | 		bool loadBody(bob_dom_bob *bob, token_stream& is);
 | 
        
           |  |  | 102 | 		bool loadPoints(bob_dom_body *body, token_stream& is, PointList& points);
 | 
        
           |  |  | 103 | 		bool loadPart(bob_dom_body *body, token_stream& is);
 | 
        
           |  |  | 104 | 		bool loadFace(int matIdx, bob_dom_body& body, bob_dom_part& part, token_stream& is);
 | 
        
           |  |  | 105 | 		bool flagsFromString(token_stream& is, int& flags);
 | 
        
           |  |  | 106 |   | 
        
           |  |  | 107 | 		material6_value * loadMat6Value(token_stream& is);
 | 
        
           |  |  | 108 |   | 
        
           |  |  | 109 | 		bool loadMaterial6Small(bob_dom_material6 *mat, token_stream &is);
 | 
        
           |  |  | 110 | 		bool loadMaterial6Big(bob_dom_material6 *mat, token_stream &is);
 | 
        
           |  |  | 111 |   | 
        
           |  |  | 112 | 		bool loadSpecialValues(bob_dom_point *points[3], int magic[3], token_stream& is);
 | 
        
           |  |  | 113 | 		bool loadSpecialPointValues(token_stream& is, bob_dom_point *point);
 | 
        
           |  |  | 114 |   | 
        
           |  |  | 115 | 		bool loadBones(bob_dom_body *body, token_stream& is);
 | 
        
           |  |  | 116 | 		bool loadWeights(bob_dom_body *body, token_stream& is);
 | 
        
           |  |  | 117 |   | 
        
           |  |  | 118 | 		bool loadSecondaryUVRecord(token_stream& is, bob_dom_part& part);
 | 
        
           |  |  | 119 | 		bool loadSecondaryUVs(token_stream& is, bob_dom_part& part);
 | 
        
           |  |  | 120 |   | 
        
           |  |  | 121 | 		bool loadX3PartValues(token_stream& is, bob_dom_part& part);
 | 
        
           |  |  | 122 |   | 
        
           |  |  | 123 | 		void deleteTempData()
 | 
        
           |  |  | 124 | 		{
 | 
        
           |  |  | 125 | 			for(PointArray::iterator &it=m_points.begin(); it!=m_points.end(); ++it){
 | 
        
           |  |  | 126 | 				delete *it;
 | 
        
           |  |  | 127 | 			}
 | 
        
           |  |  | 128 | 			m_points.clear();
 | 
        
           |  |  | 129 |   | 
        
           |  |  | 130 | 			for(WeightArray::iterator &it=m_weights.begin(); it!=m_weights.end(); ++it){
 | 
        
           |  |  | 131 | 				delete *it;
 | 
        
           |  |  | 132 | 			}
 | 
        
           |  |  | 133 | 			m_weights.clear();
 | 
        
           |  |  | 134 | 		}
 | 
        
           |  |  | 135 |   | 
        
           |  |  | 136 | 	public:
 | 
        
           |  |  | 137 |   | 
        
           |  |  | 138 | 		bod_bob_parser(const Settings *settings) { m_settings=settings; }
 | 
        
           |  |  | 139 | 		~bod_bob_parser() { deleteTempData(); }
 | 
        
           |  |  | 140 |   | 
        
           |  |  | 141 | 		bob_dom_bob * loadBOB(token_stream& is, bool bEmbedded);
 | 
        
           |  |  | 142 |   | 
        
           |  |  | 143 | 		bool compile(token_stream& is, bob_dom_obinaryfilestream& os, bool bEmbedded);
 | 
        
           |  |  | 144 | };
 | 
        
           |  |  | 145 |   | 
        
           |  |  | 146 | #endif //!defined(BOD_BOB_PARSER_INCLUDED)
 |