// File: /workspace/github_cpp_makefile_star2_O1/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
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x158, %rsp            # imm = 0x158
leaq 0x6818(%rip), %rdi      # 0x1294a
callq 0x4320
leaq -0x170(%rbp), %rbx
movq %rbx, -0x10(%rbx)
xorl %eax, %eax
movq %rax, -0x8(%rbx)
movb %al, (%rbx)
leaq -0x138(%rbp), %r12
movq %r12, -0x10(%r12)
movq %rax, -0x8(%r12)
movb %al, (%r12)
leaq -0x118(%rbp), %r13
movq %r13, -0x10(%r13)
movq %rax, -0x8(%r13)
movb %al, (%r13)
leaq -0xd8(%rbp), %rax
movq %rax, -0x30(%rax)
movq $0x1, -0x28(%rax)
xorps %xmm0, %xmm0
movups %xmm0, -0x20(%rax)
movl $0x3f800000, -0x10(%rax) # imm = 0x3F800000
movups %xmm0, -0x8(%rax)
movups %xmm0, 0x8(%rax)
movups %xmm0, 0x18(%rax)
movups %xmm0, 0x28(%rax)
movups %xmm0, 0x38(%rax)
movups %xmm0, 0x48(%rax)
movups %xmm0, 0x58(%rax)
leaq -0x40(%rbp), %r14
movq %r14, -0x10(%r14)
leaq 0x6719(%rip), %rsi      # 0x128d7
leaq 0x6731(%rip), %rdx      # 0x128f6
leaq -0x50(%rbp), %rdi
callq 0x9152
leaq -0x60(%rbp), %r15
movq %r15, -0x10(%r15)
leaq 0x671a(%rip), %rsi      # 0x128f7
leaq 0x6721(%rip), %rdx      # 0x12905
leaq -0x70(%rbp), %rdi
callq 0x9152
leaq -0x50(%rbp), %rdi
leaq -0x180(%rbp), %rsi
leaq -0x70(%rbp), %rdx
callq 0x4cdc
movl %eax, -0x2c(%rbp)
movq -0x70(%rbp), %rdi
cmpq %r15, %rdi
je 0xc212
callq 0x41c0
movq -0x50(%rbp), %rdi
cmpq %r14, %rdi
je 0xc220
callq 0x41c0
cmpl $0x0, -0x2c(%rbp)
je 0xc239
leaq 0x670a(%rip), %rdi      # 0x12937
xorl %eax, %eax
callq 0x4050
jmp 0xc2eb
leaq -0x180(%rbp), %r14
movq %r14, %rdi
callq 0xbff4
xorps %xmm0, %xmm0
movaps %xmm0, -0x50(%rbp)
movq 0xc8(%r14), %rax
movq 0x68(%rax), %rbx
movq 0x70(%rax), %r14
cmpq %r14, %rbx
je 0xc2d6
leaq 0x669c(%rip), %r15      # 0x12906
movl 0x4(%rbx), %r13d
movl 0x8(%rbx), %r12d
movq %r13, %rax
shlq $0x8, %rax
leaq (%rax,%r13,8), %rdi
addq -0xd0(%rbp), %rdi
movl %r12d, %esi
movss 0x6371(%rip), %xmm0     # 0x12600
movl $0x1, %edx
leaq -0x50(%rbp), %rcx
callq 0x752e
xorps %xmm0, %xmm0
cvtss2sd -0x50(%rbp), %xmm0
xorps %xmm1, %xmm1
cvtss2sd -0x4c(%rbp), %xmm1
xorps %xmm2, %xmm2
cvtss2sd -0x48(%rbp), %xmm2
xorps %xmm3, %xmm3
cvtss2sd -0x44(%rbp), %xmm3
movq %r15, %rdi
movl %r13d, %esi
movl %r12d, %edx
movb $0x4, %al
callq 0x4050
addq $0x10, %rbx
cmpq %r14, %rbx
jne 0xc26a
leaq -0x170(%rbp), %rbx
leaq -0x138(%rbp), %r12
leaq -0x118(%rbp), %r13
leaq -0x108(%rbp), %r14
leaq -0x88(%rbp), %rdi
callq 0xc432
leaq -0xa0(%rbp), %rdi
callq 0x9084
leaq -0xb8(%rbp), %rdi
callq 0xc466
leaq -0xd0(%rbp), %r15
movq %r15, %rdi
callq 0xc49a
movq %r14, %rdi
callq 0x7b34
movq -0x58(%r15), %rdi
cmpq %r13, %rdi
je 0xc33b
callq 0x41c0
movq -0x148(%rbp), %rdi
cmpq %r12, %rdi
je 0xc34c
callq 0x41c0
movq -0x180(%rbp), %rdi
cmpq %rbx, %rdi
je 0xc35d
callq 0x41c0
movl -0x2c(%rbp), %eax
addq $0x158, %rsp            # imm = 0x158
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %rbx
movq -0x70(%rbp), %rdi
cmpq %r15, %rdi
je 0xc388
callq 0x41c0
jmp 0xc388
movq %rax, %rbx
movq -0x50(%rbp), %rdi
cmpq %r14, %rdi
je 0xc39d
callq 0x41c0
jmp 0xc39d
jmp 0xc39a
movq %rax, %rbx
leaq -0x180(%rbp), %rdi
callq 0xc3b2
movq %rbx, %rdi
callq 0x43d0
nop