/* 3ds.c generated by valac 0.14.0, 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_;
	gint64 _tmp6_ = 0LL;
	GLfloat* _tmp7_;
	gint _tmp7__length1;
	GLfloat* _tmp8_ = NULL;
	GLfloat* _tmp160_;
	gint _tmp160__length1;
	GLfloat* _tmp161_ = 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_ = g_file_info_get_size (_tmp4_);
	tds_model_parse_block (self, _tmp5_, _tmp6_, &_inner_error_);
	if (_inner_error_ != NULL) {
		g_propagate_error (error, _inner_error_);
		_g_object_unref0 (stream);
		_tds_model_unref0 (self);
		return NULL;
	}
	_tmp7_ = self->priv->vertices;
	_tmp7__length1 = self->priv->vertices_length1;
	_tmp8_ = g_new0 (GLfloat, _tmp7__length1);
	self->priv->normals = (g_free (self->priv->normals), NULL);
	self->priv->normals = _tmp8_;
	self->priv->normals_length1 = _tmp7__length1;
	self->priv->_normals_size_ = self->priv->normals_length1;
	{
		gint i;
		i = 0;
		{
			gboolean _tmp9_;
			_tmp9_ = TRUE;
			while (TRUE) {
				gboolean _tmp10_;
				gint _tmp12_;
				GLfloat* _tmp13_;
				gint _tmp13__length1;
				GLfloat* _tmp14_;
				gint _tmp14__length1;
				gint _tmp15_;
				GLfloat _tmp16_;
				_tmp10_ = _tmp9_;
				if (!_tmp10_) {
					gint _tmp11_;
					_tmp11_ = i;
					i = _tmp11_ + 1;
				}
				_tmp9_ = FALSE;
				_tmp12_ = i;
				_tmp13_ = self->priv->normals;
				_tmp13__length1 = self->priv->normals_length1;
				if (!(_tmp12_ < _tmp13__length1)) {
					break;
				}
				_tmp14_ = self->priv->normals;
				_tmp14__length1 = self->priv->normals_length1;
				_tmp15_ = i;
				_tmp14_[_tmp15_] = (GLfloat) 0.f;
				_tmp16_ = _tmp14_[_tmp15_];
			}
		}
	}
	{
		gint i;
		i = 0;
		{
			gboolean _tmp17_;
			_tmp17_ = TRUE;
			while (TRUE) {
				gboolean _tmp18_;
				gint _tmp20_;
				GLushort* _tmp21_;
				gint _tmp21__length1;
				GLushort* _tmp22_;
				gint _tmp22__length1;
				gint _tmp23_;
				GLushort _tmp24_;
				gint v0;
				GLushort* _tmp25_;
				gint _tmp25__length1;
				gint _tmp26_;
				GLushort _tmp27_;
				gint v1;
				GLushort* _tmp28_;
				gint _tmp28__length1;
				gint _tmp29_;
				GLushort _tmp30_;
				gint v2;
				GLfloat a[3] = {0};
				GLfloat b[3] = {0};
				GLfloat normal[3] = {0};
				GLfloat* _tmp31_;
				gint _tmp31__length1;
				gint _tmp32_;
				GLfloat _tmp33_;
				GLfloat* _tmp34_;
				gint _tmp34__length1;
				gint _tmp35_;
				GLfloat _tmp36_;
				GLfloat _tmp37_;
				GLfloat* _tmp38_;
				gint _tmp38__length1;
				gint _tmp39_;
				GLfloat _tmp40_;
				GLfloat* _tmp41_;
				gint _tmp41__length1;
				gint _tmp42_;
				GLfloat _tmp43_;
				GLfloat _tmp44_;
				GLfloat* _tmp45_;
				gint _tmp45__length1;
				gint _tmp46_;
				GLfloat _tmp47_;
				GLfloat* _tmp48_;
				gint _tmp48__length1;
				gint _tmp49_;
				GLfloat _tmp50_;
				GLfloat _tmp51_;
				GLfloat* _tmp52_;
				gint _tmp52__length1;
				gint _tmp53_;
				GLfloat _tmp54_;
				GLfloat* _tmp55_;
				gint _tmp55__length1;
				gint _tmp56_;
				GLfloat _tmp57_;
				GLfloat _tmp58_;
				GLfloat* _tmp59_;
				gint _tmp59__length1;
				gint _tmp60_;
				GLfloat _tmp61_;
				GLfloat* _tmp62_;
				gint _tmp62__length1;
				gint _tmp63_;
				GLfloat _tmp64_;
				GLfloat _tmp65_;
				GLfloat* _tmp66_;
				gint _tmp66__length1;
				gint _tmp67_;
				GLfloat _tmp68_;
				GLfloat* _tmp69_;
				gint _tmp69__length1;
				gint _tmp70_;
				GLfloat _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_;
				gint _tmp88__length1;
				gint _tmp89_;
				GLfloat _tmp90_;
				GLfloat _tmp91_;
				GLfloat* _tmp92_;
				gint _tmp92__length1;
				gint _tmp93_;
				GLfloat _tmp94_;
				GLfloat _tmp95_;
				GLfloat* _tmp96_;
				gint _tmp96__length1;
				gint _tmp97_;
				GLfloat _tmp98_;
				GLfloat _tmp99_;
				GLfloat* _tmp100_;
				gint _tmp100__length1;
				gint _tmp101_;
				GLfloat _tmp102_;
				GLfloat _tmp103_;
				GLfloat* _tmp104_;
				gint _tmp104__length1;
				gint _tmp105_;
				GLfloat _tmp106_;
				GLfloat _tmp107_;
				GLfloat* _tmp108_;
				gint _tmp108__length1;
				gint _tmp109_;
				GLfloat _tmp110_;
				GLfloat _tmp111_;
				GLfloat* _tmp112_;
				gint _tmp112__length1;
				gint _tmp113_;
				GLfloat _tmp114_;
				GLfloat _tmp115_;
				GLfloat* _tmp116_;
				gint _tmp116__length1;
				gint _tmp117_;
				GLfloat _tmp118_;
				GLfloat _tmp119_;
				GLfloat* _tmp120_;
				gint _tmp120__length1;
				gint _tmp121_;
				GLfloat _tmp122_;
				GLfloat _tmp123_;
				_tmp18_ = _tmp17_;
				if (!_tmp18_) {
					gint _tmp19_;
					_tmp19_ = i;
					i = _tmp19_ + 3;
				}
				_tmp17_ = FALSE;
				_tmp20_ = i;
				_tmp21_ = self->priv->triangles;
				_tmp21__length1 = self->priv->triangles_length1;
				if (!(_tmp20_ < _tmp21__length1)) {
					break;
				}
				_tmp22_ = self->priv->triangles;
				_tmp22__length1 = self->priv->triangles_length1;
				_tmp23_ = i;
				_tmp24_ = _tmp22_[_tmp23_];
				v0 = _tmp24_ * 3;
				_tmp25_ = self->priv->triangles;
				_tmp25__length1 = self->priv->triangles_length1;
				_tmp26_ = i;
				_tmp27_ = _tmp25_[_tmp26_ + 1];
				v1 = _tmp27_ * 3;
				_tmp28_ = self->priv->triangles;
				_tmp28__length1 = self->priv->triangles_length1;
				_tmp29_ = i;
				_tmp30_ = _tmp28_[_tmp29_ + 2];
				v2 = _tmp30_ * 3;
				_tmp31_ = self->priv->vertices;
				_tmp31__length1 = self->priv->vertices_length1;
				_tmp32_ = v1;
				_tmp33_ = _tmp31_[_tmp32_];
				_tmp34_ = self->priv->vertices;
				_tmp34__length1 = self->priv->vertices_length1;
				_tmp35_ = v0;
				_tmp36_ = _tmp34_[_tmp35_];
				a[0] = _tmp33_ - _tmp36_;
				_tmp37_ = a[0];
				_tmp38_ = self->priv->vertices;
				_tmp38__length1 = self->priv->vertices_length1;
				_tmp39_ = v1;
				_tmp40_ = _tmp38_[_tmp39_ + 1];
				_tmp41_ = self->priv->vertices;
				_tmp41__length1 = self->priv->vertices_length1;
				_tmp42_ = v0;
				_tmp43_ = _tmp41_[_tmp42_ + 1];
				a[1] = _tmp40_ - _tmp43_;
				_tmp44_ = a[1];
				_tmp45_ = self->priv->vertices;
				_tmp45__length1 = self->priv->vertices_length1;
				_tmp46_ = v1;
				_tmp47_ = _tmp45_[_tmp46_ + 2];
				_tmp48_ = self->priv->vertices;
				_tmp48__length1 = self->priv->vertices_length1;
				_tmp49_ = v0;
				_tmp50_ = _tmp48_[_tmp49_ + 2];
				a[2] = _tmp47_ - _tmp50_;
				_tmp51_ = a[2];
				_tmp52_ = self->priv->vertices;
				_tmp52__length1 = self->priv->vertices_length1;
				_tmp53_ = v2;
				_tmp54_ = _tmp52_[_tmp53_];
				_tmp55_ = self->priv->vertices;
				_tmp55__length1 = self->priv->vertices_length1;
				_tmp56_ = v0;
				_tmp57_ = _tmp55_[_tmp56_];
				b[0] = _tmp54_ - _tmp57_;
				_tmp58_ = b[0];
				_tmp59_ = self->priv->vertices;
				_tmp59__length1 = self->priv->vertices_length1;
				_tmp60_ = v2;
				_tmp61_ = _tmp59_[_tmp60_ + 1];
				_tmp62_ = self->priv->vertices;
				_tmp62__length1 = self->priv->vertices_length1;
				_tmp63_ = v0;
				_tmp64_ = _tmp62_[_tmp63_ + 1];
				b[1] = _tmp61_ - _tmp64_;
				_tmp65_ = b[1];
				_tmp66_ = self->priv->vertices;
				_tmp66__length1 = self->priv->vertices_length1;
				_tmp67_ = v2;
				_tmp68_ = _tmp66_[_tmp67_ + 2];
				_tmp69_ = self->priv->vertices;
				_tmp69__length1 = self->priv->vertices_length1;
				_tmp70_ = v0;
				_tmp71_ = _tmp69_[_tmp70_ + 2];
				b[2] = _tmp68_ - _tmp71_;
				_tmp72_ = b[2];
				_tmp73_ = a[1];
				_tmp74_ = b[2];
				_tmp75_ = a[2];
				_tmp76_ = b[1];
				normal[0] = (_tmp73_ * _tmp74_) - (_tmp75_ * _tmp76_);
				_tmp77_ = normal[0];
				_tmp78_ = a[2];
				_tmp79_ = b[0];
				_tmp80_ = a[0];
				_tmp81_ = b[2];
				normal[1] = (_tmp78_ * _tmp79_) - (_tmp80_ * _tmp81_);
				_tmp82_ = normal[1];
				_tmp83_ = a[0];
				_tmp84_ = b[1];
				_tmp85_ = a[1];
				_tmp86_ = b[0];
				normal[2] = (_tmp83_ * _tmp84_) - (_tmp85_ * _tmp86_);
				_tmp87_ = normal[2];
				_tmp88_ = self->priv->normals;
				_tmp88__length1 = self->priv->normals_length1;
				_tmp89_ = v0;
				_tmp90_ = normal[0];
				_tmp88_[_tmp89_] += _tmp90_;
				_tmp91_ = _tmp88_[_tmp89_];
				_tmp92_ = self->priv->normals;
				_tmp92__length1 = self->priv->normals_length1;
				_tmp93_ = v0;
				_tmp94_ = normal[1];
				_tmp92_[_tmp93_ + 1] += _tmp94_;
				_tmp95_ = _tmp92_[_tmp93_ + 1];
				_tmp96_ = self->priv->normals;
				_tmp96__length1 = self->priv->normals_length1;
				_tmp97_ = v0;
				_tmp98_ = normal[2];
				_tmp96_[_tmp97_ + 2] += _tmp98_;
				_tmp99_ = _tmp96_[_tmp97_ + 2];
				_tmp100_ = self->priv->normals;
				_tmp100__length1 = self->priv->normals_length1;
				_tmp101_ = v1;
				_tmp102_ = normal[0];
				_tmp100_[_tmp101_] += _tmp102_;
				_tmp103_ = _tmp100_[_tmp101_];
				_tmp104_ = self->priv->normals;
				_tmp104__length1 = self->priv->normals_length1;
				_tmp105_ = v1;
				_tmp106_ = normal[1];
				_tmp104_[_tmp105_ + 1] += _tmp106_;
				_tmp107_ = _tmp104_[_tmp105_ + 1];
				_tmp108_ = self->priv->normals;
				_tmp108__length1 = self->priv->normals_length1;
				_tmp109_ = v1;
				_tmp110_ = normal[2];
				_tmp108_[_tmp109_ + 2] += _tmp110_;
				_tmp111_ = _tmp108_[_tmp109_ + 2];
				_tmp112_ = self->priv->normals;
				_tmp112__length1 = self->priv->normals_length1;
				_tmp113_ = v2;
				_tmp114_ = normal[0];
				_tmp112_[_tmp113_] += _tmp114_;
				_tmp115_ = _tmp112_[_tmp113_];
				_tmp116_ = self->priv->normals;
				_tmp116__length1 = self->priv->normals_length1;
				_tmp117_ = v2;
				_tmp118_ = normal[1];
				_tmp116_[_tmp117_ + 1] += _tmp118_;
				_tmp119_ = _tmp116_[_tmp117_ + 1];
				_tmp120_ = self->priv->normals;
				_tmp120__length1 = self->priv->normals_length1;
				_tmp121_ = v2;
				_tmp122_ = normal[2];
				_tmp120_[_tmp121_ + 2] += _tmp122_;
				_tmp123_ = _tmp120_[_tmp121_ + 2];
			}
		}
	}
	{
		gint i;
		i = 0;
		{
			gboolean _tmp124_;
			_tmp124_ = TRUE;
			while (TRUE) {
				gboolean _tmp125_;
				gint _tmp127_;
				GLfloat* _tmp128_;
				gint _tmp128__length1;
				GLfloat* _tmp129_;
				gint _tmp129__length1;
				gint _tmp130_;
				GLfloat _tmp131_;
				GLfloat* _tmp132_;
				gint _tmp132__length1;
				gint _tmp133_;
				GLfloat _tmp134_;
				GLfloat* _tmp135_;
				gint _tmp135__length1;
				gint _tmp136_;
				GLfloat _tmp137_;
				GLfloat* _tmp138_;
				gint _tmp138__length1;
				gint _tmp139_;
				GLfloat _tmp140_;
				GLfloat* _tmp141_;
				gint _tmp141__length1;
				gint _tmp142_;
				GLfloat _tmp143_;
				GLfloat* _tmp144_;
				gint _tmp144__length1;
				gint _tmp145_;
				GLfloat _tmp146_;
				gdouble _tmp147_ = 0.0;
				GLfloat length;
				GLfloat* _tmp148_;
				gint _tmp148__length1;
				gint _tmp149_;
				GLfloat _tmp150_;
				GLfloat _tmp151_;
				GLfloat* _tmp152_;
				gint _tmp152__length1;
				gint _tmp153_;
				GLfloat _tmp154_;
				GLfloat _tmp155_;
				GLfloat* _tmp156_;
				gint _tmp156__length1;
				gint _tmp157_;
				GLfloat _tmp158_;
				GLfloat _tmp159_;
				_tmp125_ = _tmp124_;
				if (!_tmp125_) {
					gint _tmp126_;
					_tmp126_ = i;
					i = _tmp126_ + 3;
				}
				_tmp124_ = FALSE;
				_tmp127_ = i;
				_tmp128_ = self->priv->normals;
				_tmp128__length1 = self->priv->normals_length1;
				if (!(_tmp127_ < _tmp128__length1)) {
					break;
				}
				_tmp129_ = self->priv->normals;
				_tmp129__length1 = self->priv->normals_length1;
				_tmp130_ = i;
				_tmp131_ = _tmp129_[_tmp130_];
				_tmp132_ = self->priv->normals;
				_tmp132__length1 = self->priv->normals_length1;
				_tmp133_ = i;
				_tmp134_ = _tmp132_[_tmp133_];
				_tmp135_ = self->priv->normals;
				_tmp135__length1 = self->priv->normals_length1;
				_tmp136_ = i;
				_tmp137_ = _tmp135_[_tmp136_ + 1];
				_tmp138_ = self->priv->normals;
				_tmp138__length1 = self->priv->normals_length1;
				_tmp139_ = i;
				_tmp140_ = _tmp138_[_tmp139_ + 1];
				_tmp141_ = self->priv->normals;
				_tmp141__length1 = self->priv->normals_length1;
				_tmp142_ = i;
				_tmp143_ = _tmp141_[_tmp142_ + 2];
				_tmp144_ = self->priv->normals;
				_tmp144__length1 = self->priv->normals_length1;
				_tmp145_ = i;
				_tmp146_ = _tmp144_[_tmp145_ + 2];
				_tmp147_ = sqrt ((gdouble) (((_tmp131_ * _tmp134_) + (_tmp137_ * _tmp140_)) + (_tmp143_ * _tmp146_)));
				length = (GLfloat) _tmp147_;
				_tmp148_ = self->priv->normals;
				_tmp148__length1 = self->priv->normals_length1;
				_tmp149_ = i;
				_tmp150_ = length;
				_tmp148_[_tmp149_] /= _tmp150_;
				_tmp151_ = _tmp148_[_tmp149_];
				_tmp152_ = self->priv->normals;
				_tmp152__length1 = self->priv->normals_length1;
				_tmp153_ = i;
				_tmp154_ = length;
				_tmp152_[_tmp153_ + 1] /= _tmp154_;
				_tmp155_ = _tmp152_[_tmp153_ + 1];
				_tmp156_ = self->priv->normals;
				_tmp156__length1 = self->priv->normals_length1;
				_tmp157_ = i;
				_tmp158_ = length;
				_tmp156_[_tmp157_ + 2] /= _tmp158_;
				_tmp159_ = _tmp156_[_tmp157_ + 2];
			}
		}
	}
	_tmp160_ = self->priv->vertices;
	_tmp160__length1 = self->priv->vertices_length1;
	_tmp161_ = g_new0 (GLfloat, (_tmp160__length1 / 3) * 2);
	self->priv->texture_coords = (g_free (self->priv->texture_coords), NULL);
	self->priv->texture_coords = _tmp161_;
	self->priv->texture_coords_length1 = (_tmp160__length1 / 3) * 2;
	self->priv->_texture_coords_size_ = self->priv->texture_coords_length1;
	{
		gint i;
		gint j;
		i = 0;
		j = 0;
		{
			gboolean _tmp162_;
			_tmp162_ = TRUE;
			while (TRUE) {
				gboolean _tmp163_;
				gint _tmp166_;
				GLfloat* _tmp167_;
				gint _tmp167__length1;
				GLfloat* _tmp168_;
				gint _tmp168__length1;
				gint _tmp169_;
				GLfloat _tmp170_;
				GLfloat u;
				GLfloat* _tmp171_;
				gint _tmp171__length1;
				gint _tmp172_;
				GLfloat _tmp173_;
				GLfloat v;
				GLfloat _tmp174_;
				GLfloat _tmp175_;
				GLfloat _tmp176_;
				GLfloat _tmp177_;
				gdouble _tmp178_ = 0.0;
				GLfloat r;
				GLfloat _tmp179_;
				GLfloat* _tmp184_;
				gint _tmp184__length1;
				gint _tmp185_;
				GLfloat _tmp186_;
				GLfloat _tmp187_;
				gfloat h;
				GLfloat* _tmp188_;
				gint _tmp188__length1;
				gint _tmp189_;
				gfloat _tmp190_;
				GLfloat _tmp191_;
				GLfloat _tmp192_;
				GLfloat* _tmp193_;
				gint _tmp193__length1;
				gint _tmp194_;
				gfloat _tmp195_;
				GLfloat _tmp196_;
				GLfloat _tmp197_;
				_tmp163_ = _tmp162_;
				if (!_tmp163_) {
					gint _tmp164_;
					gint _tmp165_;
					_tmp164_ = i;
					i = _tmp164_ + 3;
					_tmp165_ = j;
					j = _tmp165_ + 2;
				}
				_tmp162_ = FALSE;
				_tmp166_ = i;
				_tmp167_ = self->priv->vertices;
				_tmp167__length1 = self->priv->vertices_length1;
				if (!(_tmp166_ < _tmp167__length1)) {
					break;
				}
				_tmp168_ = self->priv->vertices;
				_tmp168__length1 = self->priv->vertices_length1;
				_tmp169_ = i;
				_tmp170_ = _tmp168_[_tmp169_];
				u = _tmp170_;
				_tmp171_ = self->priv->vertices;
				_tmp171__length1 = self->priv->vertices_length1;
				_tmp172_ = i;
				_tmp173_ = _tmp171_[_tmp172_ + 2];
				v = _tmp173_;
				_tmp174_ = u;
				_tmp175_ = u;
				_tmp176_ = v;
				_tmp177_ = v;
				_tmp178_ = sqrt ((gdouble) ((_tmp174_ * _tmp175_) + (_tmp176_ * _tmp177_)));
				r = (GLfloat) _tmp178_;
				_tmp179_ = r;
				if (_tmp179_ != ((GLfloat) 0)) {
					GLfloat _tmp180_;
					GLfloat _tmp181_;
					GLfloat _tmp182_;
					GLfloat _tmp183_;
					_tmp180_ = u;
					_tmp181_ = r;
					u = _tmp180_ / _tmp181_;
					_tmp182_ = v;
					_tmp183_ = r;
					v = _tmp182_ / _tmp183_;
				}
				_tmp184_ = self->priv->vertices;
				_tmp184__length1 = self->priv->vertices_length1;
				_tmp185_ = i;
				_tmp186_ = _tmp184_[_tmp185_ + 1];
				_tmp187_ = self->priv->max_height;
				h = 1.0f - (_tmp186_ / _tmp187_);
				_tmp188_ = self->priv->texture_coords;
				_tmp188__length1 = self->priv->texture_coords_length1;
				_tmp189_ = j;
				_tmp190_ = h;
				_tmp191_ = u;
				_tmp188_[_tmp189_] = (GLfloat) (0.5f + ((0.5f * _tmp190_) * _tmp191_));
				_tmp192_ = _tmp188_[_tmp189_];
				_tmp193_ = self->priv->texture_coords;
				_tmp193__length1 = self->priv->texture_coords_length1;
				_tmp194_ = j;
				_tmp195_ = h;
				_tmp196_ = v;
				_tmp193_[_tmp194_ + 1] = (GLfloat) (0.5f + ((0.5f * _tmp195_) * _tmp196_));
				_tmp197_ = _tmp193_[_tmp194_ + 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);
	}
}



