/* 3ds.c generated by valac 0.15.1, the Vala compiler
 * generated from 3ds.vala, do not modify */


#include <glib.h>
#include <glib-object.h>
#include "GL/gl.h"
#include <float.h>
#include <math.h>
#include <gio/gio.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <gobject/gvaluecollector.h>


#define TYPE_TDS_MODEL (tds_model_get_type ())
#define TDS_MODEL(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), TYPE_TDS_MODEL, TDSModel))
#define TDS_MODEL_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), TYPE_TDS_MODEL, TDSModelClass))
#define IS_TDS_MODEL(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), TYPE_TDS_MODEL))
#define IS_TDS_MODEL_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), TYPE_TDS_MODEL))
#define TDS_MODEL_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), TYPE_TDS_MODEL, TDSModelClass))

typedef struct _TDSModel TDSModel;
typedef struct _TDSModelClass TDSModelClass;
typedef struct _TDSModelPrivate TDSModelPrivate;
#define _tds_model_unref0(var) ((var == NULL) ? NULL : (var = (tds_model_unref (var), NULL)))
#define _g_object_unref0(var) ((var == NULL) ? NULL : (var = (g_object_unref (var), NULL)))
#define _g_free0(var) (var = (g_free (var), NULL))
#define _g_string_free0(var) ((var == NULL) ? NULL : (var = (g_string_free (var, TRUE), NULL)))
typedef struct _ParamSpecTDSModel ParamSpecTDSModel;

struct _TDSModel {
	GTypeInstance parent_instance;
	volatile int ref_count;
	TDSModelPrivate * priv;
};

struct _TDSModelClass {
	GTypeClass parent_class;
	void (*finalize) (TDSModel *self);
};

struct _TDSModelPrivate {
	GLfloat min_height;
	GLfloat max_height;
	GLfloat* vertices;
	gint vertices_length1;
	gint _vertices_size_;
	GLushort* triangles;
	gint triangles_length1;
	gint _triangles_size_;
	GLfloat* normals;
	gint normals_length1;
	gint _normals_size_;
	GLfloat* texture_coords;
	gint texture_coords_length1;
	gint _texture_coords_size_;
};

struct _ParamSpecTDSModel {
	GParamSpec parent_instance;
};


static gpointer tds_model_parent_class = NULL;

gpointer tds_model_ref (gpointer instance);
void tds_model_unref (gpointer instance);
GParamSpec* param_spec_tds_model (const gchar* name, const gchar* nick, const gchar* blurb, GType object_type, GParamFlags flags);
void value_set_tds_model (GValue* value, gpointer v_object);
void value_take_tds_model (GValue* value, gpointer v_object);
gpointer value_get_tds_model (const GValue* value);
GType tds_model_get_type (void) G_GNUC_CONST;
#define TDS_MODEL_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), TYPE_TDS_MODEL, TDSModelPrivate))
enum  {
	TDS_MODEL_DUMMY_PROPERTY
};
TDSModel* tds_model_new (GFile* file, GError** error);
TDSModel* tds_model_construct (GType object_type, GFile* file, GError** error);
static void tds_model_parse_block (TDSModel* self, GFileInputStream* stream, gint64 length, GError** error);
static guint16 tds_model_read_uint16 (TDSModel* self, GInputStream* stream, GError** error);
static guint32 tds_model_read_uint32 (TDSModel* self, GInputStream* stream, GError** error);
static gchar* tds_model_read_string (TDSModel* self, GInputStream* stream, GError** error);
static gfloat tds_model_read_float (TDSModel* self, GInputStream* stream, GError** error);
static guint8 tds_model_read_uint8 (TDSModel* self, GInputStream* stream, GError** error);
void tds_model_render (TDSModel* self);
static gfloat* _vala_array_dup1 (gfloat* self, int length);
static void tds_model_finalize (TDSModel* obj);


TDSModel* tds_model_construct (GType object_type, GFile* file, GError** error) {
	TDSModel* self = NULL;
	GFile* _tmp0_;
	GFileInputStream* _tmp1_ = NULL;
	GFileInputStream* stream;
	GFileInputStream* _tmp2_;
	GFileInfo* _tmp3_ = NULL;
	GFileInfo* _tmp4_;
	GFileInputStream* _tmp5_;
	GFileInfo* _tmp6_;
	gint64 _tmp7_ = 0LL;
	GLfloat* _tmp8_;
	gint _tmp8__length1;
	GLfloat* _tmp9_ = NULL;
	GLfloat* _tmp161_;
	gint _tmp161__length1;
	GLfloat* _tmp162_ = NULL;
	GError * _inner_error_ = NULL;
	g_return_val_if_fail (file != NULL, NULL);
	self = (TDSModel*) g_type_create_instance (object_type);
	_tmp0_ = file;
	_tmp1_ = g_file_read (_tmp0_, NULL, &_inner_error_);
	stream = _tmp1_;
	if (_inner_error_ != NULL) {
		g_propagate_error (error, _inner_error_);
		_tds_model_unref0 (self);
		return NULL;
	}
	_tmp2_ = stream;
	_tmp3_ = g_file_input_stream_query_info (_tmp2_, G_FILE_ATTRIBUTE_STANDARD_SIZE, NULL, &_inner_error_);
	_tmp4_ = _tmp3_;
	if (_inner_error_ != NULL) {
		g_propagate_error (error, _inner_error_);
		_g_object_unref0 (stream);
		_tds_model_unref0 (self);
		return NULL;
	}
	_tmp5_ = stream;
	_tmp6_ = _tmp4_;
	_tmp7_ = g_file_info_get_size (_tmp6_);
	tds_model_parse_block (self, _tmp5_, _tmp7_, &_inner_error_);
	_g_object_unref0 (_tmp6_);
	if (_inner_error_ != NULL) {
		g_propagate_error (error, _inner_error_);
		_g_object_unref0 (stream);
		_tds_model_unref0 (self);
		return NULL;
	}
	_tmp8_ = self->priv->vertices;
	_tmp8__length1 = self->priv->vertices_length1;
	_tmp9_ = g_new0 (GLfloat, _tmp8__length1);
	self->priv->normals = (g_free (self->priv->normals), NULL);
	self->priv->normals = _tmp9_;
	self->priv->normals_length1 = _tmp8__length1;
	self->priv->_normals_size_ = self->priv->normals_length1;
	{
		gint i;
		i = 0;
		{
			gboolean _tmp10_;
			_tmp10_ = TRUE;
			while (TRUE) {
				gboolean _tmp11_;
				gint _tmp13_;
				GLfloat* _tmp14_;
				gint _tmp14__length1;
				GLfloat* _tmp15_;
				gint _tmp15__length1;
				gint _tmp16_;
				GLfloat _tmp17_;
				_tmp11_ = _tmp10_;
				if (!_tmp11_) {
					gint _tmp12_;
					_tmp12_ = i;
					i = _tmp12_ + 1;
				}
				_tmp10_ = FALSE;
				_tmp13_ = i;
				_tmp14_ = self->priv->normals;
				_tmp14__length1 = self->priv->normals_length1;
				if (!(_tmp13_ < _tmp14__length1)) {
					break;
				}
				_tmp15_ = self->priv->normals;
				_tmp15__length1 = self->priv->normals_length1;
				_tmp16_ = i;
				_tmp15_[_tmp16_] = (GLfloat) 0.f;
				_tmp17_ = _tmp15_[_tmp16_];
			}
		}
	}
	{
		gint i;
		i = 0;
		{
			gboolean _tmp18_;
			_tmp18_ = TRUE;
			while (TRUE) {
				gboolean _tmp19_;
				gint _tmp21_;
				GLushort* _tmp22_;
				gint _tmp22__length1;
				GLushort* _tmp23_;
				gint _tmp23__length1;
				gint _tmp24_;
				GLushort _tmp25_;
				gint v0;
				GLushort* _tmp26_;
				gint _tmp26__length1;
				gint _tmp27_;
				GLushort _tmp28_;
				gint v1;
				GLushort* _tmp29_;
				gint _tmp29__length1;
				gint _tmp30_;
				GLushort _tmp31_;
				gint v2;
				GLfloat a[3] = {0};
				GLfloat b[3] = {0};
				GLfloat normal[3] = {0};
				GLfloat* _tmp32_;
				gint _tmp32__length1;
				gint _tmp33_;
				GLfloat _tmp34_;
				GLfloat* _tmp35_;
				gint _tmp35__length1;
				gint _tmp36_;
				GLfloat _tmp37_;
				GLfloat _tmp38_;
				GLfloat* _tmp39_;
				gint _tmp39__length1;
				gint _tmp40_;
				GLfloat _tmp41_;
				GLfloat* _tmp42_;
				gint _tmp42__length1;
				gint _tmp43_;
				GLfloat _tmp44_;
				GLfloat _tmp45_;
				GLfloat* _tmp46_;
				gint _tmp46__length1;
				gint _tmp47_;
				GLfloat _tmp48_;
				GLfloat* _tmp49_;
				gint _tmp49__length1;
				gint _tmp50_;
				GLfloat _tmp51_;
				GLfloat _tmp52_;
				GLfloat* _tmp53_;
				gint _tmp53__length1;
				gint _tmp54_;
				GLfloat _tmp55_;
				GLfloat* _tmp56_;
				gint _tmp56__length1;
				gint _tmp57_;
				GLfloat _tmp58_;
				GLfloat _tmp59_;
				GLfloat* _tmp60_;
				gint _tmp60__length1;
				gint _tmp61_;
				GLfloat _tmp62_;
				GLfloat* _tmp63_;
				gint _tmp63__length1;
				gint _tmp64_;
				GLfloat _tmp65_;
				GLfloat _tmp66_;
				GLfloat* _tmp67_;
				gint _tmp67__length1;
				gint _tmp68_;
				GLfloat _tmp69_;
				GLfloat* _tmp70_;
				gint _tmp70__length1;
				gint _tmp71_;
				GLfloat _tmp72_;
				GLfloat _tmp73_;
				GLfloat _tmp74_;
				GLfloat _tmp75_;
				GLfloat _tmp76_;
				GLfloat _tmp77_;
				GLfloat _tmp78_;
				GLfloat _tmp79_;
				GLfloat _tmp80_;
				GLfloat _tmp81_;
				GLfloat _tmp82_;
				GLfloat _tmp83_;
				GLfloat _tmp84_;
				GLfloat _tmp85_;
				GLfloat _tmp86_;
				GLfloat _tmp87_;
				GLfloat _tmp88_;
				GLfloat* _tmp89_;
				gint _tmp89__length1;
				gint _tmp90_;
				GLfloat _tmp91_;
				GLfloat _tmp92_;
				GLfloat* _tmp93_;
				gint _tmp93__length1;
				gint _tmp94_;
				GLfloat _tmp95_;
				GLfloat _tmp96_;
				GLfloat* _tmp97_;
				gint _tmp97__length1;
				gint _tmp98_;
				GLfloat _tmp99_;
				GLfloat _tmp100_;
				GLfloat* _tmp101_;
				gint _tmp101__length1;
				gint _tmp102_;
				GLfloat _tmp103_;
				GLfloat _tmp104_;
				GLfloat* _tmp105_;
				gint _tmp105__length1;
				gint _tmp106_;
				GLfloat _tmp107_;
				GLfloat _tmp108_;
				GLfloat* _tmp109_;
				gint _tmp109__length1;
				gint _tmp110_;
				GLfloat _tmp111_;
				GLfloat _tmp112_;
				GLfloat* _tmp113_;
				gint _tmp113__length1;
				gint _tmp114_;
				GLfloat _tmp115_;
				GLfloat _tmp116_;
				GLfloat* _tmp117_;
				gint _tmp117__length1;
				gint _tmp118_;
				GLfloat _tmp119_;
				GLfloat _tmp120_;
				GLfloat* _tmp121_;
				gint _tmp121__length1;
				gint _tmp122_;
				GLfloat _tmp123_;
				GLfloat _tmp124_;
				_tmp19_ = _tmp18_;
				if (!_tmp19_) {
					gint _tmp20_;
					_tmp20_ = i;
					i = _tmp20_ + 3;
				}
				_tmp18_ = FALSE;
				_tmp21_ = i;
				_tmp22_ = self->priv->triangles;
				_tmp22__length1 = self->priv->triangles_length1;
				if (!(_tmp21_ < _tmp22__length1)) {
					break;
				}
				_tmp23_ = self->priv->triangles;
				_tmp23__length1 = self->priv->triangles_length1;
				_tmp24_ = i;
				_tmp25_ = _tmp23_[_tmp24_];
				v0 = _tmp25_ * 3;
				_tmp26_ = self->priv->triangles;
				_tmp26__length1 = self->priv->triangles_length1;
				_tmp27_ = i;
				_tmp28_ = _tmp26_[_tmp27_ + 1];
				v1 = _tmp28_ * 3;
				_tmp29_ = self->priv->triangles;
				_tmp29__length1 = self->priv->triangles_length1;
				_tmp30_ = i;
				_tmp31_ = _tmp29_[_tmp30_ + 2];
				v2 = _tmp31_ * 3;
				_tmp32_ = self->priv->vertices;
				_tmp32__length1 = self->priv->vertices_length1;
				_tmp33_ = v1;
				_tmp34_ = _tmp32_[_tmp33_];
				_tmp35_ = self->priv->vertices;
				_tmp35__length1 = self->priv->vertices_length1;
				_tmp36_ = v0;
				_tmp37_ = _tmp35_[_tmp36_];
				a[0] = _tmp34_ - _tmp37_;
				_tmp38_ = a[0];
				_tmp39_ = self->priv->vertices;
				_tmp39__length1 = self->priv->vertices_length1;
				_tmp40_ = v1;
				_tmp41_ = _tmp39_[_tmp40_ + 1];
				_tmp42_ = self->priv->vertices;
				_tmp42__length1 = self->priv->vertices_length1;
				_tmp43_ = v0;
				_tmp44_ = _tmp42_[_tmp43_ + 1];
				a[1] = _tmp41_ - _tmp44_;
				_tmp45_ = a[1];
				_tmp46_ = self->priv->vertices;
				_tmp46__length1 = self->priv->vertices_length1;
				_tmp47_ = v1;
				_tmp48_ = _tmp46_[_tmp47_ + 2];
				_tmp49_ = self->priv->vertices;
				_tmp49__length1 = self->priv->vertices_length1;
				_tmp50_ = v0;
				_tmp51_ = _tmp49_[_tmp50_ + 2];
				a[2] = _tmp48_ - _tmp51_;
				_tmp52_ = a[2];
				_tmp53_ = self->priv->vertices;
				_tmp53__length1 = self->priv->vertices_length1;
				_tmp54_ = v2;
				_tmp55_ = _tmp53_[_tmp54_];
				_tmp56_ = self->priv->vertices;
				_tmp56__length1 = self->priv->vertices_length1;
				_tmp57_ = v0;
				_tmp58_ = _tmp56_[_tmp57_];
				b[0] = _tmp55_ - _tmp58_;
				_tmp59_ = b[0];
				_tmp60_ = self->priv->vertices;
				_tmp60__length1 = self->priv->vertices_length1;
				_tmp61_ = v2;
				_tmp62_ = _tmp60_[_tmp61_ + 1];
				_tmp63_ = self->priv->vertices;
				_tmp63__length1 = self->priv->vertices_length1;
				_tmp64_ = v0;
				_tmp65_ = _tmp63_[_tmp64_ + 1];
				b[1] = _tmp62_ - _tmp65_;
				_tmp66_ = b[1];
				_tmp67_ = self->priv->vertices;
				_tmp67__length1 = self->priv->vertices_length1;
				_tmp68_ = v2;
				_tmp69_ = _tmp67_[_tmp68_ + 2];
				_tmp70_ = self->priv->vertices;
				_tmp70__length1 = self->priv->vertices_length1;
				_tmp71_ = v0;
				_tmp72_ = _tmp70_[_tmp71_ + 2];
				b[2] = _tmp69_ - _tmp72_;
				_tmp73_ = b[2];
				_tmp74_ = a[1];
				_tmp75_ = b[2];
				_tmp76_ = a[2];
				_tmp77_ = b[1];
				normal[0] = (_tmp74_ * _tmp75_) - (_tmp76_ * _tmp77_);
				_tmp78_ = normal[0];
				_tmp79_ = a[2];
				_tmp80_ = b[0];
				_tmp81_ = a[0];
				_tmp82_ = b[2];
				normal[1] = (_tmp79_ * _tmp80_) - (_tmp81_ * _tmp82_);
				_tmp83_ = normal[1];
				_tmp84_ = a[0];
				_tmp85_ = b[1];
				_tmp86_ = a[1];
				_tmp87_ = b[0];
				normal[2] = (_tmp84_ * _tmp85_) - (_tmp86_ * _tmp87_);
				_tmp88_ = normal[2];
				_tmp89_ = self->priv->normals;
				_tmp89__length1 = self->priv->normals_length1;
				_tmp90_ = v0;
				_tmp91_ = normal[0];
				_tmp89_[_tmp90_] += _tmp91_;
				_tmp92_ = _tmp89_[_tmp90_];
				_tmp93_ = self->priv->normals;
				_tmp93__length1 = self->priv->normals_length1;
				_tmp94_ = v0;
				_tmp95_ = normal[1];
				_tmp93_[_tmp94_ + 1] += _tmp95_;
				_tmp96_ = _tmp93_[_tmp94_ + 1];
				_tmp97_ = self->priv->normals;
				_tmp97__length1 = self->priv->normals_length1;
				_tmp98_ = v0;
				_tmp99_ = normal[2];
				_tmp97_[_tmp98_ + 2] += _tmp99_;
				_tmp100_ = _tmp97_[_tmp98_ + 2];
				_tmp101_ = self->priv->normals;
				_tmp101__length1 = self->priv->normals_length1;
				_tmp102_ = v1;
				_tmp103_ = normal[0];
				_tmp101_[_tmp102_] += _tmp103_;
				_tmp104_ = _tmp101_[_tmp102_];
				_tmp105_ = self->priv->normals;
				_tmp105__length1 = self->priv->normals_length1;
				_tmp106_ = v1;
				_tmp107_ = normal[1];
				_tmp105_[_tmp106_ + 1] += _tmp107_;
				_tmp108_ = _tmp105_[_tmp106_ + 1];
				_tmp109_ = self->priv->normals;
				_tmp109__length1 = self->priv->normals_length1;
				_tmp110_ = v1;
				_tmp111_ = normal[2];
				_tmp109_[_tmp110_ + 2] += _tmp111_;
				_tmp112_ = _tmp109_[_tmp110_ + 2];
				_tmp113_ = self->priv->normals;
				_tmp113__length1 = self->priv->normals_length1;
				_tmp114_ = v2;
				_tmp115_ = normal[0];
				_tmp113_[_tmp114_] += _tmp115_;
				_tmp116_ = _tmp113_[_tmp114_];
				_tmp117_ = self->priv->normals;
				_tmp117__length1 = self->priv->normals_length1;
				_tmp118_ = v2;
				_tmp119_ = normal[1];
				_tmp117_[_tmp118_ + 1] += _tmp119_;
				_tmp120_ = _tmp117_[_tmp118_ + 1];
				_tmp121_ = self->priv->normals;
				_tmp121__length1 = self->priv->normals_length1;
				_tmp122_ = v2;
				_tmp123_ = normal[2];
				_tmp121_[_tmp122_ + 2] += _tmp123_;
				_tmp124_ = _tmp121_[_tmp122_ + 2];
			}
		}
	}
	{
		gint i;
		i = 0;
		{
			gboolean _tmp125_;
			_tmp125_ = TRUE;
			while (TRUE) {
				gboolean _tmp126_;
				gint _tmp128_;
				GLfloat* _tmp129_;
				gint _tmp129__length1;
				GLfloat* _tmp130_;
				gint _tmp130__length1;
				gint _tmp131_;
				GLfloat _tmp132_;
				GLfloat* _tmp133_;
				gint _tmp133__length1;
				gint _tmp134_;
				GLfloat _tmp135_;
				GLfloat* _tmp136_;
				gint _tmp136__length1;
				gint _tmp137_;
				GLfloat _tmp138_;
				GLfloat* _tmp139_;
				gint _tmp139__length1;
				gint _tmp140_;
				GLfloat _tmp141_;
				GLfloat* _tmp142_;
				gint _tmp142__length1;
				gint _tmp143_;
				GLfloat _tmp144_;
				GLfloat* _tmp145_;
				gint _tmp145__length1;
				gint _tmp146_;
				GLfloat _tmp147_;
				gdouble _tmp148_ = 0.0;
				GLfloat length;
				GLfloat* _tmp149_;
				gint _tmp149__length1;
				gint _tmp150_;
				GLfloat _tmp151_;
				GLfloat _tmp152_;
				GLfloat* _tmp153_;
				gint _tmp153__length1;
				gint _tmp154_;
				GLfloat _tmp155_;
				GLfloat _tmp156_;
				GLfloat* _tmp157_;
				gint _tmp157__length1;
				gint _tmp158_;
				GLfloat _tmp159_;
				GLfloat _tmp160_;
				_tmp126_ = _tmp125_;
				if (!_tmp126_) {
					gint _tmp127_;
					_tmp127_ = i;
					i = _tmp127_ + 3;
				}
				_tmp125_ = FALSE;
				_tmp128_ = i;
				_tmp129_ = self->priv->normals;
				_tmp129__length1 = self->priv->normals_length1;
				if (!(_tmp128_ < _tmp129__length1)) {
					break;
				}
				_tmp130_ = self->priv->normals;
				_tmp130__length1 = self->priv->normals_length1;
				_tmp131_ = i;
				_tmp132_ = _tmp130_[_tmp131_];
				_tmp133_ = self->priv->normals;
				_tmp133__length1 = self->priv->normals_length1;
				_tmp134_ = i;
				_tmp135_ = _tmp133_[_tmp134_];
				_tmp136_ = self->priv->normals;
				_tmp136__length1 = self->priv->normals_length1;
				_tmp137_ = i;
				_tmp138_ = _tmp136_[_tmp137_ + 1];
				_tmp139_ = self->priv->normals;
				_tmp139__length1 = self->priv->normals_length1;
				_tmp140_ = i;
				_tmp141_ = _tmp139_[_tmp140_ + 1];
				_tmp142_ = self->priv->normals;
				_tmp142__length1 = self->priv->normals_length1;
				_tmp143_ = i;
				_tmp144_ = _tmp142_[_tmp143_ + 2];
				_tmp145_ = self->priv->normals;
				_tmp145__length1 = self->priv->normals_length1;
				_tmp146_ = i;
				_tmp147_ = _tmp145_[_tmp146_ + 2];
				_tmp148_ = sqrt ((gdouble) (((_tmp132_ * _tmp135_) + (_tmp138_ * _tmp141_)) + (_tmp144_ * _tmp147_)));
				length = (GLfloat) _tmp148_;
				_tmp149_ = self->priv->normals;
				_tmp149__length1 = self->priv->normals_length1;
				_tmp150_ = i;
				_tmp151_ = length;
				_tmp149_[_tmp150_] /= _tmp151_;
				_tmp152_ = _tmp149_[_tmp150_];
				_tmp153_ = self->priv->normals;
				_tmp153__length1 = self->priv->normals_length1;
				_tmp154_ = i;
				_tmp155_ = length;
				_tmp153_[_tmp154_ + 1] /= _tmp155_;
				_tmp156_ = _tmp153_[_tmp154_ + 1];
				_tmp157_ = self->priv->normals;
				_tmp157__length1 = self->priv->normals_length1;
				_tmp158_ = i;
				_tmp159_ = length;
				_tmp157_[_tmp158_ + 2] /= _tmp159_;
				_tmp160_ = _tmp157_[_tmp158_ + 2];
			}
		}
	}
	_tmp161_ = self->priv->vertices;
	_tmp161__length1 = self->priv->vertices_length1;
	_tmp162_ = g_new0 (GLfloat, (_tmp161__length1 / 3) * 2);
	self->priv->texture_coords = (g_free (self->priv->texture_coords), NULL);
	self->priv->texture_coords = _tmp162_;
	self->priv->texture_coords_length1 = (_tmp161__length1 / 3) * 2;
	self->priv->_texture_coords_size_ = self->priv->texture_coords_length1;
	{
		gint i;
		gint j;
		i = 0;
		j = 0;
		{
			gboolean _tmp163_;
			_tmp163_ = TRUE;
			while (TRUE) {
				gboolean _tmp164_;
				gint _tmp167_;
				GLfloat* _tmp168_;
				gint _tmp168__length1;
				GLfloat* _tmp169_;
				gint _tmp169__length1;
				gint _tmp170_;
				GLfloat _tmp171_;
				GLfloat u;
				GLfloat* _tmp172_;
				gint _tmp172__length1;
				gint _tmp173_;
				GLfloat _tmp174_;
				GLfloat v;
				GLfloat _tmp175_;
				GLfloat _tmp176_;
				GLfloat _tmp177_;
				GLfloat _tmp178_;
				gdouble _tmp179_ = 0.0;
				GLfloat r;
				GLfloat _tmp180_;
				GLfloat* _tmp185_;
				gint _tmp185__length1;
				gint _tmp186_;
				GLfloat _tmp187_;
				GLfloat _tmp188_;
				gfloat h;
				GLfloat* _tmp189_;
				gint _tmp189__length1;
				gint _tmp190_;
				gfloat _tmp191_;
				GLfloat _tmp192_;
				GLfloat _tmp193_;
				GLfloat* _tmp194_;
				gint _tmp194__length1;
				gint _tmp195_;
				gfloat _tmp196_;
				GLfloat _tmp197_;
				GLfloat _tmp198_;
				_tmp164_ = _tmp163_;
				if (!_tmp164_) {
					gint _tmp165_;
					gint _tmp166_;
					_tmp165_ = i;
					i = _tmp165_ + 3;
					_tmp166_ = j;
					j = _tmp166_ + 2;
				}
				_tmp163_ = FALSE;
				_tmp167_ = i;
				_tmp168_ = self->priv->vertices;
				_tmp168__length1 = self->priv->vertices_length1;
				if (!(_tmp167_ < _tmp168__length1)) {
					break;
				}
				_tmp169_ = self->priv->vertices;
				_tmp169__length1 = self->priv->vertices_length1;
				_tmp170_ = i;
				_tmp171_ = _tmp169_[_tmp170_];
				u = _tmp171_;
				_tmp172_ = self->priv->vertices;
				_tmp172__length1 = self->priv->vertices_length1;
				_tmp173_ = i;
				_tmp174_ = _tmp172_[_tmp173_ + 2];
				v = _tmp174_;
				_tmp175_ = u;
				_tmp176_ = u;
				_tmp177_ = v;
				_tmp178_ = v;
				_tmp179_ = sqrt ((gdouble) ((_tmp175_ * _tmp176_) + (_tmp177_ * _tmp178_)));
				r = (GLfloat) _tmp179_;
				_tmp180_ = r;
				if (_tmp180_ != ((GLfloat) 0)) {
					GLfloat _tmp181_;
					GLfloat _tmp182_;
					GLfloat _tmp183_;
					GLfloat _tmp184_;
					_tmp181_ = u;
					_tmp182_ = r;
					u = _tmp181_ / _tmp182_;
					_tmp183_ = v;
					_tmp184_ = r;
					v = _tmp183_ / _tmp184_;
				}
				_tmp185_ = self->priv->vertices;
				_tmp185__length1 = self->priv->vertices_length1;
				_tmp186_ = i;
				_tmp187_ = _tmp185_[_tmp186_ + 1];
				_tmp188_ = self->priv->max_height;
				h = 1.0f - (_tmp187_ / _tmp188_);
				_tmp189_ = self->priv->texture_coords;
				_tmp189__length1 = self->priv->texture_coords_length1;
				_tmp190_ = j;
				_tmp191_ = h;
				_tmp192_ = u;
				_tmp189_[_tmp190_] = (GLfloat) (0.5f + ((0.5f * _tmp191_) * _tmp192_));
				_tmp193_ = _tmp189_[_tmp190_];
				_tmp194_ = self->priv->texture_coords;
				_tmp194__length1 = self->priv->texture_coords_length1;
				_tmp195_ = j;
				_tmp196_ = h;
				_tmp197_ = v;
				_tmp194_[_tmp195_ + 1] = (GLfloat) (0.5f + ((0.5f * _tmp196_) * _tmp197_));
				_tmp198_ = _tmp194_[_tmp195_ + 1];
			}
		}
	}
	_g_object_unref0 (stream);
	return self;
}


TDSModel* tds_model_new (GFile* file, GError** error) {
	return tds_model_construct (TYPE_TDS_MODEL, file, error);
}


static void tds_model_parse_block (TDSModel* self, GFileInputStream* stream, gint64 length, GError** error) {
	gint64 _tmp109_;
	GError * _inner_error_ = NULL;
	g_return_if_fail (self != NULL);
	g_return_if_fail (stream != NULL);
	while (TRUE) {
		gint64 _tmp0_;
		GFileInputStream* _tmp1_;
		guint16 _tmp2_ = 0U;
		guint16 id;
		GFileInputStream* _tmp3_;
		guint32 _tmp4_ = 0U;
		gint64 block_length;
		gint64 _tmp5_;
		gint64 _tmp6_;
		gint64 _tmp7_;
		guint16 _tmp12_;
		gint64 _tmp107_;
		gint64 _tmp108_;
		_tmp0_ = length;
		if (!(_tmp0_ > ((gint64) 6))) {
			break;
		}
		_tmp1_ = stream;
		_tmp2_ = tds_model_read_uint16 (self, (GInputStream*) _tmp1_, &_inner_error_);
		id = _tmp2_;
		if (_inner_error_ != NULL) {
			g_propagate_error (error, _inner_error_);
			return;
		}
		_tmp3_ = stream;
		_tmp4_ = tds_model_read_uint32 (self, (GInputStream*) _tmp3_, &_inner_error_);
		block_length = (gint64) _tmp4_;
		if (_inner_error_ != NULL) {
			g_propagate_error (error, _inner_error_);
			return;
		}
		_tmp5_ = block_length;
		if (_tmp5_ < ((gint64) 6)) {
			return;
		}
		_tmp6_ = block_length;
		_tmp7_ = length;
		if (_tmp6_ > _tmp7_) {
			FILE* _tmp8_;
			gint64 _tmp9_;
			guint16 _tmp10_;
			gint64 _tmp11_;
			_tmp8_ = stderr;
			_tmp9_ = block_length;
			_tmp10_ = id;
			_tmp11_ = length;
			fprintf (_tmp8_, "Overflow, need %lli octets for %04X, but only have %lli\n", _tmp9_, (gint) _tmp10_, _tmp11_);
			return;
		}
		_tmp12_ = id;
		switch (_tmp12_) {
			case 0x4D4D:
			{
				GFileInputStream* _tmp13_;
				gint64 _tmp14_;
				_tmp13_ = stream;
				_tmp14_ = block_length;
				tds_model_parse_block (self, _tmp13_, _tmp14_ - 6, &_inner_error_);
				if (_inner_error_ != NULL) {
					g_propagate_error (error, _inner_error_);
					return;
				}
				break;
			}
			case 0x3D3D:
			{
				GFileInputStream* _tmp15_;
				gint64 _tmp16_;
				_tmp15_ = stream;
				_tmp16_ = block_length;
				tds_model_parse_block (self, _tmp15_, _tmp16_ - 6, &_inner_error_);
				if (_inner_error_ != NULL) {
					g_propagate_error (error, _inner_error_);
					return;
				}
				break;
			}
			case 0x4000:
			{
				GFileInputStream* _tmp17_;
				gchar* _tmp18_ = NULL;
				gchar* name;
				GFileInputStream* _tmp19_;
				gint64 _tmp20_;
				const gchar* _tmp21_;
				gint _tmp22_;
				gint _tmp23_;
				_tmp17_ = stream;
				_tmp18_ = tds_model_read_string (self, (GInputStream*) _tmp17_, &_inner_error_);
				name = _tmp18_;
				if (_inner_error_ != NULL) {
					g_propagate_error (error, _inner_error_);
					return;
				}
				_tmp19_ = stream;
				_tmp20_ = block_length;
				_tmp21_ = name;
				_tmp22_ = strlen (_tmp21_);
				_tmp23_ = _tmp22_;
				tds_model_parse_block (self, _tmp19_, (_tmp20_ - 6) - (_tmp23_ + 1), &_inner_error_);
				if (_inner_error_ != NULL) {
					g_propagate_error (error, _inner_error_);
					_g_free0 (name);
					return;
				}
				_g_free0 (name);
				break;
			}
			case 0x4100:
			{
				GFileInputStream* _tmp24_;
				gint64 _tmp25_;
				_tmp24_ = stream;
				_tmp25_ = block_length;
				tds_model_parse_block (self, _tmp24_, _tmp25_ - 6, &_inner_error_);
				if (_inner_error_ != NULL) {
					g_propagate_error (error, _inner_error_);
					return;
				}
				break;
			}
			case 0x4110:
			{
				GFileInputStream* _tmp26_;
				guint16 _tmp27_ = 0U;
				guint16 n;
				guint16 _tmp28_;
				GLfloat* _tmp29_ = NULL;
				_tmp26_ = stream;
				_tmp27_ = tds_model_read_uint16 (self, (GInputStream*) _tmp26_, &_inner_error_);
				n = _tmp27_;
				if (_inner_error_ != NULL) {
					g_propagate_error (error, _inner_error_);
					return;
				}
				_tmp28_ = n;
				_tmp29_ = g_new0 (GLfloat, _tmp28_ * 3);
				self->priv->vertices = (g_free (self->priv->vertices), NULL);
				self->priv->vertices = _tmp29_;
				self->priv->vertices_length1 = _tmp28_ * 3;
				self->priv->_vertices_size_ = self->priv->vertices_length1;
				{
					gint i;
					i = 0;
					{
						gboolean _tmp30_;
						_tmp30_ = TRUE;
						while (TRUE) {
							gboolean _tmp31_;
							gint _tmp33_;
							guint16 _tmp34_;
							GFileInputStream* _tmp35_;
							gfloat _tmp36_ = 0.0F;
							gfloat x;
							GFileInputStream* _tmp37_;
							gfloat _tmp38_ = 0.0F;
							gfloat y;
							GFileInputStream* _tmp39_;
							gfloat _tmp40_ = 0.0F;
							gfloat z;
							gfloat scale;
							GLfloat* _tmp41_;
							gint _tmp41__length1;
							gint _tmp42_;
							gfloat _tmp43_;
							gfloat _tmp44_;
							GLfloat _tmp45_;
							GLfloat* _tmp46_;
							gint _tmp46__length1;
							gint _tmp47_;
							gfloat _tmp48_;
							gfloat _tmp49_;
							GLfloat _tmp50_;
							GLfloat* _tmp51_;
							gint _tmp51__length1;
							gint _tmp52_;
							gfloat _tmp53_;
							gfloat _tmp54_;
							GLfloat _tmp55_;
							gfloat _tmp56_;
							gfloat _tmp57_;
							gfloat h;
							gfloat _tmp58_;
							GLfloat _tmp59_;
							gfloat _tmp61_;
							GLfloat _tmp62_;
							_tmp31_ = _tmp30_;
							if (!_tmp31_) {
								gint _tmp32_;
								_tmp32_ = i;
								i = _tmp32_ + 1;
							}
							_tmp30_ = FALSE;
							_tmp33_ = i;
							_tmp34_ = n;
							if (!(_tmp33_ < ((gint) _tmp34_))) {
								break;
							}
							_tmp35_ = stream;
							_tmp36_ = tds_model_read_float (self, (GInputStream*) _tmp35_, &_inner_error_);
							x = _tmp36_;
							if (_inner_error_ != NULL) {
								g_propagate_error (error, _inner_error_);
								return;
							}
							_tmp37_ = stream;
							_tmp38_ = tds_model_read_float (self, (GInputStream*) _tmp37_, &_inner_error_);
							y = _tmp38_;
							if (_inner_error_ != NULL) {
								g_propagate_error (error, _inner_error_);
								return;
							}
							_tmp39_ = stream;
							_tmp40_ = tds_model_read_float (self, (GInputStream*) _tmp39_, &_inner_error_);
							z = _tmp40_;
							if (_inner_error_ != NULL) {
								g_propagate_error (error, _inner_error_);
								return;
							}
							scale = 3.5f;
							_tmp41_ = self->priv->vertices;
							_tmp41__length1 = self->priv->vertices_length1;
							_tmp42_ = i;
							_tmp43_ = scale;
							_tmp44_ = x;
							_tmp41_[_tmp42_ * 3] = (GLfloat) (_tmp43_ * _tmp44_);
							_tmp45_ = _tmp41_[_tmp42_ * 3];
							_tmp46_ = self->priv->vertices;
							_tmp46__length1 = self->priv->vertices_length1;
							_tmp47_ = i;
							_tmp48_ = scale;
							_tmp49_ = z;
							_tmp46_[(_tmp47_ * 3) + 1] = (GLfloat) (_tmp48_ * _tmp49_);
							_tmp50_ = _tmp46_[(_tmp47_ * 3) + 1];
							_tmp51_ = self->priv->vertices;
							_tmp51__length1 = self->priv->vertices_length1;
							_tmp52_ = i;
							_tmp53_ = scale;
							_tmp54_ = y;
							_tmp51_[(_tmp52_ * 3) + 2] = (GLfloat) (_tmp53_ * _tmp54_);
							_tmp55_ = _tmp51_[(_tmp52_ * 3) + 2];
							_tmp56_ = scale;
							_tmp57_ = z;
							h = _tmp56_ * _tmp57_;
							_tmp58_ = h;
							_tmp59_ = self->priv->min_height;
							if (_tmp58_ < ((gfloat) _tmp59_)) {
								gfloat _tmp60_;
								_tmp60_ = h;
								self->priv->min_height = (GLfloat) _tmp60_;
							}
							_tmp61_ = h;
							_tmp62_ = self->priv->max_height;
							if (_tmp61_ > ((gfloat) _tmp62_)) {
								gfloat _tmp63_;
								_tmp63_ = h;
								self->priv->max_height = (GLfloat) _tmp63_;
							}
						}
					}
				}
				break;
			}
			case 0x4120:
			{
				gint64 _tmp64_;
				GFileInputStream* _tmp65_;
				guint16 _tmp66_ = 0U;
				guint16 n;
				guint16 _tmp67_;
				GLushort* _tmp68_ = NULL;
				gint64 _tmp69_;
				guint16 _tmp70_;
				GFileInputStream* _tmp98_;
				gint64 _tmp99_;
				guint16 _tmp100_;
				_tmp64_ = block_length;
				if (_tmp64_ < ((gint64) 2)) {
					return;
				}
				_tmp65_ = stream;
				_tmp66_ = tds_model_read_uint16 (self, (GInputStream*) _tmp65_, &_inner_error_);
				n = _tmp66_;
				if (_inner_error_ != NULL) {
					g_propagate_error (error, _inner_error_);
					return;
				}
				_tmp67_ = n;
				_tmp68_ = g_new0 (GLushort, _tmp67_ * 3);
				self->priv->triangles = (g_free (self->priv->triangles), NULL);
				self->priv->triangles = _tmp68_;
				self->priv->triangles_length1 = _tmp67_ * 3;
				self->priv->_triangles_size_ = self->priv->triangles_length1;
				_tmp69_ = block_length;
				_tmp70_ = n;
				if (_tmp69_ < ((gint64) (2 + (_tmp70_ * 8)))) {
					FILE* _tmp71_;
					guint16 _tmp72_;
					gint64 _tmp73_;
					_tmp71_ = stderr;
					_tmp72_ = n;
					_tmp73_ = block_length;
					fprintf (_tmp71_, "Invalid face data, need %u, have %lli\n", (guint) (2 + (_tmp72_ * 8)), _tmp73_);
					return;
				}
				{
					gint i;
					i = 0;
					{
						gboolean _tmp74_;
						_tmp74_ = TRUE;
						while (TRUE) {
							gboolean _tmp75_;
							gint _tmp77_;
							guint16 _tmp78_;
							GFileInputStream* _tmp79_;
							guint16 _tmp80_ = 0U;
							guint16 a;
							GFileInputStream* _tmp81_;
							guint16 _tmp82_ = 0U;
							guint16 b;
							GFileInputStream* _tmp83_;
							guint16 _tmp84_ = 0U;
							guint16 c;
							GFileInputStream* _tmp85_;
							GLushort* _tmp86_;
							gint _tmp86__length1;
							gint _tmp87_;
							guint16 _tmp88_;
							GLushort _tmp89_;
							GLushort* _tmp90_;
							gint _tmp90__length1;
							gint _tmp91_;
							guint16 _tmp92_;
							GLushort _tmp93_;
							GLushort* _tmp94_;
							gint _tmp94__length1;
							gint _tmp95_;
							guint16 _tmp96_;
							GLushort _tmp97_;
							_tmp75_ = _tmp74_;
							if (!_tmp75_) {
								gint _tmp76_;
								_tmp76_ = i;
								i = _tmp76_ + 1;
							}
							_tmp74_ = FALSE;
							_tmp77_ = i;
							_tmp78_ = n;
							if (!(_tmp77_ < ((gint) _tmp78_))) {
								break;
							}
							_tmp79_ = stream;
							_tmp80_ = tds_model_read_uint16 (self, (GInputStream*) _tmp79_, &_inner_error_);
							a = _tmp80_;
							if (_inner_error_ != NULL) {
								g_propagate_error (error, _inner_error_);
								return;
							}
							_tmp81_ = stream;
							_tmp82_ = tds_model_read_uint16 (self, (GInputStream*) _tmp81_, &_inner_error_);
							b = _tmp82_;
							if (_inner_error_ != NULL) {
								g_propagate_error (error, _inner_error_);
								return;
							}
							_tmp83_ = stream;
							_tmp84_ = tds_model_read_uint16 (self, (GInputStream*) _tmp83_, &_inner_error_);
							c = _tmp84_;
							if (_inner_error_ != NULL) {
								g_propagate_error (error, _inner_error_);
								return;
							}
							_tmp85_ = stream;
							tds_model_read_uint16 (self, (GInputStream*) _tmp85_, &_inner_error_);
							if (_inner_error_ != NULL) {
								g_propagate_error (error, _inner_error_);
								return;
							}
							_tmp86_ = self->priv->triangles;
							_tmp86__length1 = self->priv->triangles_length1;
							_tmp87_ = i;
							_tmp88_ = a;
							_tmp86_[_tmp87_ * 3] = (GLushort) _tmp88_;
							_tmp89_ = _tmp86_[_tmp87_ * 3];
							_tmp90_ = self->priv->triangles;
							_tmp90__length1 = self->priv->triangles_length1;
							_tmp91_ = i;
							_tmp92_ = c;
							_tmp90_[(_tmp91_ * 3) + 1] = (GLushort) _tmp92_;
							_tmp93_ = _tmp90_[(_tmp91_ * 3) + 1];
							_tmp94_ = self->priv->triangles;
							_tmp94__length1 = self->priv->triangles_length1;
							_tmp95_ = i;
							_tmp96_ = b;
							_tmp94_[(_tmp95_ * 3) + 2] = (GLushort) _tmp96_;
							_tmp97_ = _tmp94_[(_tmp95_ * 3) + 2];
						}
					}
				}
				_tmp98_ = stream;
				_tmp99_ = block_length;
				_tmp100_ = n;
				tds_model_parse_block (self, _tmp98_, _tmp99_ - (2 + (_tmp100_ * 8)), &_inner_error_);
				if (_inner_error_ != NULL) {
					g_propagate_error (error, _inner_error_);
					return;
				}
				break;
			}
			default:
			{
				{
					gint i;
					i = 0;
					{
						gboolean _tmp101_;
						_tmp101_ = TRUE;
						while (TRUE) {
							gboolean _tmp102_;
							gint _tmp104_;
							gint64 _tmp105_;
							GFileInputStream* _tmp106_;
							_tmp102_ = _tmp101_;
							if (!_tmp102_) {
								gint _tmp103_;
								_tmp103_ = i;
								i = _tmp103_ + 1;
							}
							_tmp101_ = FALSE;
							_tmp104_ = i;
							_tmp105_ = block_length;
							if (!(((gint64) _tmp104_) < (_tmp105_ - 6))) {
								break;
							}
							_tmp106_ = stream;
							tds_model_read_uint8 (self, (GInputStream*) _tmp106_, &_inner_error_);
							if (_inner_error_ != NULL) {
								g_propagate_error (error, _inner_error_);
								return;
							}
						}
					}
				}
				break;
			}
		}
		_tmp107_ = length;
		_tmp108_ = block_length;
		length = _tmp107_ - _tmp108_;
	}
	_tmp109_ = length;
	if (_tmp109_ != ((gint64) 0)) {
		return;
	}
}


void tds_model_render (TDSModel* self) {
	GLfloat* _tmp0_;
	gint _tmp0__length1;
	GLfloat* _tmp1_;
	gint _tmp1__length1;
	GLfloat* _tmp2_;
	gint _tmp2__length1;
	GLushort* _tmp3_;
	gint _tmp3__length1;
	GLushort* _tmp4_;
	gint _tmp4__length1;
	g_return_if_fail (self != NULL);
	glEnable (GL_CULL_FACE);
	glEnableClientState (GL_VERTEX_ARRAY);
	glEnableClientState (GL_NORMAL_ARRAY);
	glEnableClientState (GL_TEXTURE_COORD_ARRAY);
	_tmp0_ = self->priv->vertices;
	_tmp0__length1 = self->priv->vertices_length1;
	glVertexPointer ((GLint) 3, GL_FLOAT, (GLsizei) 0, _tmp0_);
	_tmp1_ = self->priv->normals;
	_tmp1__length1 = self->priv->normals_length1;
	glNormalPointer (GL_FLOAT, (GLsizei) 0, _tmp1_);
	_tmp2_ = self->priv->texture_coords;
	_tmp2__length1 = self->priv->texture_coords_length1;
	glTexCoordPointer ((GLint) 2, GL_FLOAT, (GLsizei) 0, _tmp2_);
	_tmp3_ = self->priv->triangles;
	_tmp3__length1 = self->priv->triangles_length1;
	_tmp4_ = self->priv->triangles;
	_tmp4__length1 = self->priv->triangles_length1;
	glDrawElements (GL_TRIANGLES, (GLsizei) _tmp3__length1, GL_UNSIGNED_SHORT, _tmp4_);
	glDisableClientState (GL_VERTEX_ARRAY);
	glDisableClientState (GL_NORMAL_ARRAY);
	glDisableClientState (GL_TEXTURE_COORD_ARRAY);
}


static guint8 tds_model_read_uint8 (TDSModel* self, GInputStream* stream, GError** error) {
	guint8 result = 0U;
	guchar buffer[1] = {0};
	GInputStream* _tmp0_;
	guchar _tmp1_;
	GError * _inner_error_ = NULL;
	g_return_val_if_fail (self != NULL, 0U);
	g_return_val_if_fail (stream != NULL, 0U);
	_tmp0_ = stream;
	g_input_stream_read_all (_tmp0_, buffer, (gsize) 1, NULL, NULL, &_inner_error_);
	if (_inner_error_ != NULL) {
		g_propagate_error (error, _inner_error_);
		return 0U;
	}
	_tmp1_ = buffer[0];
	result = (guint8) _tmp1_;
	return result;
}


static guint16 tds_model_read_uint16 (TDSModel* self, GInputStream* stream, GError** error) {
	guint16 result = 0U;
	guchar buffer[2] = {0};
	GInputStream* _tmp0_;
	guchar _tmp1_;
	guchar _tmp2_;
	GError * _inner_error_ = NULL;
	g_return_val_if_fail (self != NULL, 0U);
	g_return_val_if_fail (stream != NULL, 0U);
	_tmp0_ = stream;
	g_input_stream_read_all (_tmp0_, buffer, (gsize) 2, NULL, NULL, &_inner_error_);
	if (_inner_error_ != NULL) {
		g_propagate_error (error, _inner_error_);
		return 0U;
	}
	_tmp1_ = buffer[1];
	_tmp2_ = buffer[0];
	result = (guint16) ((_tmp1_ << 8) | _tmp2_);
	return result;
}


static guint32 tds_model_read_uint32 (TDSModel* self, GInputStream* stream, GError** error) {
	guint32 result = 0U;
	guchar buffer[4] = {0};
	GInputStream* _tmp0_;
	guchar _tmp1_;
	guchar _tmp2_;
	guchar _tmp3_;
	guchar _tmp4_;
	GError * _inner_error_ = NULL;
	g_return_val_if_fail (self != NULL, 0U);
	g_return_val_if_fail (stream != NULL, 0U);
	_tmp0_ = stream;
	g_input_stream_read_all (_tmp0_, buffer, (gsize) 4, NULL, NULL, &_inner_error_);
	if (_inner_error_ != NULL) {
		g_propagate_error (error, _inner_error_);
		return 0U;
	}
	_tmp1_ = buffer[3];
	_tmp2_ = buffer[2];
	_tmp3_ = buffer[1];
	_tmp4_ = buffer[0];
	result = (guint32) ((((_tmp1_ << 24) | (_tmp2_ << 16)) | (_tmp3_ << 8)) | _tmp4_);
	return result;
}


static gfloat* _vala_array_dup1 (gfloat* self, int length) {
	return g_memdup (self, length * sizeof (gfloat));
}


static gfloat tds_model_read_float (TDSModel* self, GInputStream* stream, GError** error) {
	gfloat result = 0.0F;
	guint8 buffer[4] = {0};
	GInputStream* _tmp0_;
	gfloat* _tmp1_;
	gint _tmp1__length1;
	gfloat* fbuffer;
	gint fbuffer_length1;
	gint _fbuffer_size_;
	gfloat* _tmp2_;
	gint _tmp2__length1;
	gfloat _tmp3_;
	GError * _inner_error_ = NULL;
	g_return_val_if_fail (self != NULL, 0.0F);
	g_return_val_if_fail (stream != NULL, 0.0F);
	_tmp0_ = stream;
	g_input_stream_read_all (_tmp0_, buffer, (gsize) 4, NULL, NULL, &_inner_error_);
	if (_inner_error_ != NULL) {
		g_propagate_error (error, _inner_error_);
		return 0.0F;
	}
	_tmp1_ = (((gfloat*) buffer) != NULL) ? _vala_array_dup1 ((gfloat*) buffer, 4) : ((gpointer) ((gfloat*) buffer));
	_tmp1__length1 = 4;
	fbuffer = _tmp1_;
	fbuffer_length1 = _tmp1__length1;
	_fbuffer_size_ = fbuffer_length1;
	_tmp2_ = fbuffer;
	_tmp2__length1 = fbuffer_length1;
	_tmp3_ = _tmp2_[0];
	result = _tmp3_;
	fbuffer = (g_free (fbuffer), NULL);
	return result;
}


static gchar* tds_model_read_string (TDSModel* self, GInputStream* stream, GError** error) {
	gchar* result = NULL;
	GString* _tmp0_;
	GString* value;
	GError * _inner_error_ = NULL;
	g_return_val_if_fail (self != NULL, NULL);
	g_return_val_if_fail (stream != NULL, NULL);
	_tmp0_ = g_string_new ("");
	value = _tmp0_;
	while (TRUE) {
		GInputStream* _tmp1_;
		guint8 _tmp2_ = 0U;
		guint8 c;
		guint8 _tmp3_;
		GString* _tmp7_;
		guint8 _tmp8_;
		_tmp1_ = stream;
		_tmp2_ = tds_model_read_uint8 (self, _tmp1_, &_inner_error_);
		c = _tmp2_;
		if (_inner_error_ != NULL) {
			g_propagate_error (error, _inner_error_);
			_g_string_free0 (value);
			return NULL;
		}
		_tmp3_ = c;
		if (((gint) _tmp3_) == 0) {
			GString* _tmp4_;
			const gchar* _tmp5_;
			gchar* _tmp6_;
			_tmp4_ = value;
			_tmp5_ = _tmp4_->str;
			_tmp6_ = g_strdup (_tmp5_);
			result = _tmp6_;
			_g_string_free0 (value);
			return result;
		}
		_tmp7_ = value;
		_tmp8_ = c;
		g_string_append_c (_tmp7_, (gchar) _tmp8_);
	}
	_g_string_free0 (value);
}


static void value_tds_model_init (GValue* value) {
	value->data[0].v_pointer = NULL;
}


static void value_tds_model_free_value (GValue* value) {
	if (value->data[0].v_pointer) {
		tds_model_unref (value->data[0].v_pointer);
	}
}


static void value_tds_model_copy_value (const GValue* src_value, GValue* dest_value) {
	if (src_value->data[0].v_pointer) {
		dest_value->data[0].v_pointer = tds_model_ref (src_value->data[0].v_pointer);
	} else {
		dest_value->data[0].v_pointer = NULL;
	}
}


static gpointer value_tds_model_peek_pointer (const GValue* value) {
	return value->data[0].v_pointer;
}


static gchar* value_tds_model_collect_value (GValue* value, guint n_collect_values, GTypeCValue* collect_values, guint collect_flags) {
	if (collect_values[0].v_pointer) {
		TDSModel* object;
		object = collect_values[0].v_pointer;
		if (object->parent_instance.g_class == NULL) {
			return g_strconcat ("invalid unclassed object pointer for value type `", G_VALUE_TYPE_NAME (value), "'", NULL);
		} else if (!g_value_type_compatible (G_TYPE_FROM_INSTANCE (object), G_VALUE_TYPE (value))) {
			return g_strconcat ("invalid object type `", g_type_name (G_TYPE_FROM_INSTANCE (object)), "' for value type `", G_VALUE_TYPE_NAME (value), "'", NULL);
		}
		value->data[0].v_pointer = tds_model_ref (object);
	} else {
		value->data[0].v_pointer = NULL;
	}
	return NULL;
}


static gchar* value_tds_model_lcopy_value (const GValue* value, guint n_collect_values, GTypeCValue* collect_values, guint collect_flags) {
	TDSModel** object_p;
	object_p = collect_values[0].v_pointer;
	if (!object_p) {
		return g_strdup_printf ("value location for `%s' passed as NULL", G_VALUE_TYPE_NAME (value));
	}
	if (!value->data[0].v_pointer) {
		*object_p = NULL;
	} else if (collect_flags & G_VALUE_NOCOPY_CONTENTS) {
		*object_p = value->data[0].v_pointer;
	} else {
		*object_p = tds_model_ref (value->data[0].v_pointer);
	}
	return NULL;
}


GParamSpec* param_spec_tds_model (const gchar* name, const gchar* nick, const gchar* blurb, GType object_type, GParamFlags flags) {
	ParamSpecTDSModel* spec;
	g_return_val_if_fail (g_type_is_a (object_type, TYPE_TDS_MODEL), NULL);
	spec = g_param_spec_internal (G_TYPE_PARAM_OBJECT, name, nick, blurb, flags);
	G_PARAM_SPEC (spec)->value_type = object_type;
	return G_PARAM_SPEC (spec);
}


gpointer value_get_tds_model (const GValue* value) {
	g_return_val_if_fail (G_TYPE_CHECK_VALUE_TYPE (value, TYPE_TDS_MODEL), NULL);
	return value->data[0].v_pointer;
}


void value_set_tds_model (GValue* value, gpointer v_object) {
	TDSModel* old;
	g_return_if_fail (G_TYPE_CHECK_VALUE_TYPE (value, TYPE_TDS_MODEL));
	old = value->data[0].v_pointer;
	if (v_object) {
		g_return_if_fail (G_TYPE_CHECK_INSTANCE_TYPE (v_object, TYPE_TDS_MODEL));
		g_return_if_fail (g_value_type_compatible (G_TYPE_FROM_INSTANCE (v_object), G_VALUE_TYPE (value)));
		value->data[0].v_pointer = v_object;
		tds_model_ref (value->data[0].v_pointer);
	} else {
		value->data[0].v_pointer = NULL;
	}
	if (old) {
		tds_model_unref (old);
	}
}


void value_take_tds_model (GValue* value, gpointer v_object) {
	TDSModel* old;
	g_return_if_fail (G_TYPE_CHECK_VALUE_TYPE (value, TYPE_TDS_MODEL));
	old = value->data[0].v_pointer;
	if (v_object) {
		g_return_if_fail (G_TYPE_CHECK_INSTANCE_TYPE (v_object, TYPE_TDS_MODEL));
		g_return_if_fail (g_value_type_compatible (G_TYPE_FROM_INSTANCE (v_object), G_VALUE_TYPE (value)));
		value->data[0].v_pointer = v_object;
	} else {
		value->data[0].v_pointer = NULL;
	}
	if (old) {
		tds_model_unref (old);
	}
}


static void tds_model_class_init (TDSModelClass * klass) {
	tds_model_parent_class = g_type_class_peek_parent (klass);
	TDS_MODEL_CLASS (klass)->finalize = tds_model_finalize;
	g_type_class_add_private (klass, sizeof (TDSModelPrivate));
}


static void tds_model_instance_init (TDSModel * self) {
	gfloat _tmp0_;
	gfloat _tmp1_;
	self->priv = TDS_MODEL_GET_PRIVATE (self);
	_tmp0_ = FLT_MAX;
	self->priv->min_height = (GLfloat) _tmp0_;
	_tmp1_ = FLT_MIN;
	self->priv->max_height = (GLfloat) _tmp1_;
	self->ref_count = 1;
}


static void tds_model_finalize (TDSModel* obj) {
	TDSModel * self;
	self = TDS_MODEL (obj);
	self->priv->vertices = (g_free (self->priv->vertices), NULL);
	self->priv->triangles = (g_free (self->priv->triangles), NULL);
	self->priv->normals = (g_free (self->priv->normals), NULL);
	self->priv->texture_coords = (g_free (self->priv->texture_coords), NULL);
}


GType tds_model_get_type (void) {
	static volatile gsize tds_model_type_id__volatile = 0;
	if (g_once_init_enter (&tds_model_type_id__volatile)) {
		static const GTypeValueTable g_define_type_value_table = { value_tds_model_init, value_tds_model_free_value, value_tds_model_copy_value, value_tds_model_peek_pointer, "p", value_tds_model_collect_value, "p", value_tds_model_lcopy_value };
		static const GTypeInfo g_define_type_info = { sizeof (TDSModelClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) tds_model_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (TDSModel), 0, (GInstanceInitFunc) tds_model_instance_init, &g_define_type_value_table };
		static const GTypeFundamentalInfo g_define_type_fundamental_info = { (G_TYPE_FLAG_CLASSED | G_TYPE_FLAG_INSTANTIATABLE | G_TYPE_FLAG_DERIVABLE | G_TYPE_FLAG_DEEP_DERIVABLE) };
		GType tds_model_type_id;
		tds_model_type_id = g_type_register_fundamental (g_type_fundamental_next (), "TDSModel", &g_define_type_info, &g_define_type_fundamental_info, 0);
		g_once_init_leave (&tds_model_type_id__volatile, tds_model_type_id);
	}
	return tds_model_type_id__volatile;
}


gpointer tds_model_ref (gpointer instance) {
	TDSModel* self;
	self = instance;
	g_atomic_int_inc (&self->ref_count);
	return instance;
}


void tds_model_unref (gpointer instance) {
	TDSModel* self;
	self = instance;
	if (g_atomic_int_dec_and_test (&self->ref_count)) {
		TDS_MODEL_GET_CLASS (self)->finalize (self);
		g_type_free_instance ((GTypeInstance *) self);
	}
}



