All pastes #837217 Raw Edit

Miscellany

public text v1 · immutable
#837217 ·published 2007-12-29 13:06 UTC
rendered paste body
class CTil
{
public:
	CTil():_Textures(NULL){}
	~CTil(){CleanUp();}

	bool OpenTIL(char* path){
		CleanUp();

		CFile* fh = new CFile(path, "rb");
		if(!fh->IsOpen()) return false;
		
		_Width = fh->Read<dword>();
		_Height = fh->Read<dword>();

		_Textures = new dword*[_Width];
		for(dword x = 0; x < _Width; x++)
			_Textures[x] = new dword[_Height];

		for(dword x = 0; x < _Width; x++){
			for(dword z = 0; z < _Height; z++){
				fh->Skip(3);
				_Textures[x][z] = fh->Read<dword>();
			}
		}

		fh->Close();
		delete fh;
		return true;
	}

	dword Texture(dword x, dword z){
		return _Textures[x][z];
	}
private:
	void CleanUp(){
		if(_Textures != NULL){
			for(dword x = 0; x < _Width; x++) 
				delete [] _Textures[x];

			delete [] _Textures;
			_Textures = NULL;
		}
		_Width = 0;
		_Height = 0;
	}
	dword _Width;
	dword _Height;

	dword** _Textures;
};