// File: halsafar[P]libtmx-parser/main.cpp
// Function: main
int main()
{
	printf("tmxparser::main()\n");

	tmxparser::TmxReturn error;
	tmxparser::TmxMap map;

	// test from file
	error = tmxparser::parseFromFile("./test_files/test_xml_level.tmx", &map, "test/textures/");

	// test from memory
	/*FILE* fp;
	fp = fopen("example.tmx", "rb");
	fseek( fp, 0, SEEK_SET );
	fgetc( fp );
	fseek( fp, 0, SEEK_END );
	size_t size = ftell( fp );
	fseek( fp, 0, SEEK_SET );

	char* charBuffer = new char[size+1];
	size_t read = fread( charBuffer, 1, size, fp );

	t = tmxparser::parseFromMemory(charBuffer, size, &map);*/

	if (!error)
	{
		printTmxMapData(&map);

		tmxparser::TmxRect rect;
		rect.u = 0; rect.v = 0; rect.u2 = 0; rect.v2 = 0;
		for (auto it : map.layerCollection[0].tiles)
		{
			tmxparser::calculateTileCoordinatesUV(map.tilesetCollection[it.tilesetIndex], it.tileFlatIndex, 0.5f, true, rect);
			printf("Tileset[%u]@Tile[%u]=Rect( (%f, %f)->(%f, %f) )\n", it.tilesetIndex, it.tileFlatIndex, rect.u, rect.v, rect.u2, rect.v2);
		}
	}
	else
	{
		printf("error parsing file");
	}

	return error;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x1d0, %rsp            # imm = 0x1D0
movl $0x0, -0x4(%rbp)
leaq 0xa1a6(%rip), %rdi      # 0x228bf
xorl %eax, %eax
callq 0x4060
leaq -0x118(%rbp), %rdi
callq 0x18e90
leaq -0x139(%rbp), %rdi
movq %rdi, -0x1b8(%rbp)
callq 0x4480
movq -0x1b8(%rbp), %rdx
leaq 0xa185(%rip), %rsi      # 0x228d2
leaq -0x138(%rbp), %rdi
callq 0x4370
jmp 0x1875b
leaq -0x171(%rbp), %rdi
movq %rdi, -0x1c0(%rbp)
callq 0x4480
movq -0x1c0(%rbp), %rdx
leaq 0xa176(%rip), %rsi      # 0x228f2
leaq -0x170(%rbp), %rdi
callq 0x4370
jmp 0x1878a
leaq -0x138(%rbp), %rdi
leaq -0x118(%rbp), %rsi
leaq -0x170(%rbp), %rdx
callq 0x4700
movl %eax, -0x1c4(%rbp)
jmp 0x187ac
movl -0x1c4(%rbp), %eax
movl %eax, -0x8(%rbp)
leaq -0x170(%rbp), %rdi
callq 0x4508
leaq -0x171(%rbp), %rdi
callq 0x42a0
leaq -0x138(%rbp), %rdi
callq 0x4508
leaq -0x139(%rbp), %rdi
callq 0x42a0
cmpl $0x0, -0x8(%rbp)
jne 0x189b9
leaq -0x118(%rbp), %rdi
callq 0x18570
jmp 0x187fd
xorps %xmm0, %xmm0
movss %xmm0, -0x184(%rbp)
xorps %xmm0, %xmm0
movss %xmm0, -0x180(%rbp)
xorps %xmm0, %xmm0
movss %xmm0, -0x17c(%rbp)
xorps %xmm0, %xmm0
movss %xmm0, -0x178(%rbp)
leaq -0x118(%rbp), %rdi
addq $0xc8, %rdi
xorl %eax, %eax
movl %eax, %esi
callq 0x18f20
addq $0x68, %rax
movq %rax, -0x190(%rbp)
movq -0x190(%rbp), %rdi
callq 0x16280
movq %rax, -0x198(%rbp)
movq -0x190(%rbp), %rdi
callq 0x16100
movq %rax, -0x1a0(%rbp)
leaq -0x198(%rbp), %rdi
leaq -0x1a0(%rbp), %rsi
callq 0x18f40
testb $0x1, %al
jne 0x1888d
jmp 0x189b7
leaq -0x198(%rbp), %rdi
callq 0x18f80
movups (%rax), %xmm0
movaps %xmm0, -0x1b0(%rbp)
leaq -0x68(%rbp), %rdi
movl -0x1ac(%rbp), %eax
movl %eax, %esi
callq 0x18fa0
movq %rax, %rdi
movl -0x1a8(%rbp), %esi
movss 0x9d23(%rip), %xmm0     # 0x225e8
movl $0x1, %edx
leaq -0x184(%rbp), %rcx
callq 0x7980
jmp 0x188d8
movl -0x1ac(%rbp), %esi
movl -0x1a8(%rbp), %edx
movss -0x184(%rbp), %xmm0
movss -0x180(%rbp), %xmm1
cvtss2sd %xmm0, %xmm0
cvtss2sd %xmm1, %xmm1
movss -0x17c(%rbp), %xmm2
cvtss2sd %xmm2, %xmm2
movss -0x178(%rbp), %xmm3
cvtss2sd %xmm3, %xmm3
leaq 0x9fe6(%rip), %rdi      # 0x22901
movb $0x4, %al
callq 0x4060
jmp 0x18924
jmp 0x18926
leaq -0x198(%rbp), %rdi
callq 0x18fc0
jmp 0x18871
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x148(%rbp)
movl %eax, -0x14c(%rbp)
jmp 0x18995
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x148(%rbp)
movl %eax, -0x14c(%rbp)
jmp 0x1897d
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x148(%rbp)
movl %eax, -0x14c(%rbp)
leaq -0x170(%rbp), %rdi
callq 0x4508
leaq -0x171(%rbp), %rdi
callq 0x42a0
leaq -0x138(%rbp), %rdi
callq 0x4508
leaq -0x139(%rbp), %rdi
callq 0x42a0
jmp 0x189e9
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x148(%rbp)
movl %eax, -0x14c(%rbp)
jmp 0x189e9
jmp 0x189cb
leaq 0x9f72(%rip), %rdi      # 0x22932
xorl %eax, %eax
callq 0x4060
jmp 0x189c9
jmp 0x189cb
movl -0x8(%rbp), %eax
movl %eax, -0x4(%rbp)
leaq -0x118(%rbp), %rdi
callq 0x18fe0
movl -0x4(%rbp), %eax
addq $0x1d0, %rsp            # imm = 0x1D0
popq %rbp
retq
leaq -0x118(%rbp), %rdi
callq 0x18fe0
movq -0x148(%rbp), %rdi
callq 0x4470
nopw %cs:(%rax,%rax)
nopl (%rax,%rax)