// File: /workspace/github_c_makefile_star2_O2/vlenhart[P]q3bsp/q3bsp.cpp
// Function: Quake3BSP::SaveEntity(EntityReference const&, _IO_FILE*, VFormatOptions&) const
void Quake3BSP::SaveEntity(const EntityReference &entity,
						   FILE *f
						   ,VFormatOptions &options
						   ) const
{
   
   std::string classname;
   std::string targetname;
   float angle = 0;
   vec3_t origin;
   // targetname	
   // model
   // dmg
   // spawnflags
   //_color
   //message
   //music
 
  ArgList args;
  
  args.Set( entity.mBody.c_str(),false); // crunch it into arguments.
  // now ready to process it as a series of arguments!

  int argi=0;
  while (argi < args.size()) 
  {
	String&  key = args[argi];
	
	argi++;

	if (key == "classname") {
		classname = args[argi];
		argi++;
	}
	else if (key == "targetname") {
		targetname = args[argi];
		argi++;
	}
	else if (key == "origin") {
		sscanf(args[argi].c_str(),"%f %f %f",&origin[0],&origin[1],&origin[2]);
		options.MapVertex(origin);
		argi++;
	}
	else if (key == "angle") {
		sscanf(args[argi].c_str(),"%f",&angle);
		angle -=90;
		angle *= (float)Q_PI/180.0f;

		argi++;
	}
	else {
		argi += 1;
	}

  }	

  //
  // info_player_intermission
  if (classname == "target_position") {
	  fprintf(f,"DEF %s Viewpoint { position %g %g %g fieldOfView 1.0 jump TRUE orientation 0 1 0 %g\n\tdescription %c%s%c }\n",targetname.c_str(),origin[0],origin[1],origin[2],angle,'"',targetname.c_str(),'"');
  }	
  if (classname == "info_player_deathmatch") {
	  fprintf(f,"Viewpoint { position %g %g %g fieldOfView 1.0 jump TRUE orientation 0 1 0 %g\n\tdescription %c%s%c }\n",origin[0],origin[1],origin[2],angle,'"',classname.c_str(),'"');
  }	
  // worldspawn	
  //misc_model .. model


}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x98, %rsp
movq %rdx, -0x48(%rbp)
leaq -0x58(%rbp), %rax
movq %rax, -0x10(%rax)
andq $0x0, -0x8(%rax)
movq %rsi, %rbx
xorl %ecx, %ecx
movb %cl, (%rax)
leaq -0x90(%rbp), %rax
movq %rax, -0x10(%rax)
andq $0x0, -0x8(%rax)
movb %cl, (%rax)
andl $0x0, -0x2c(%rbp)
leaq -0x80(%rbp), %rdi
callq 0x5f9a
movq (%rbx), %rsi
leaq -0xc0(%rbp), %rdi
leaq -0x39(%rbp), %rdx
callq 0x5b0c
leaq -0x80(%rbp), %rdi
leaq -0xc0(%rbp), %rsi
xorl %edx, %edx
callq 0x5fe2
leaq -0xc0(%rbp), %rdi
callq 0x2120
pushq $0x1
popq %r15
leaq -0x80(%rbp), %r13
leaq 0x8183(%rip), %rbx      # 0x110a6
leaq 0x8186(%rip), %r14      # 0x110b0
movq %r13, %rdi
callq 0x623c
leal -0x1(%r15), %esi
cmpl %eax, %esi
jge 0x9061
movq %r13, %rdi
callq 0x626e
movq %rax, %r12
movq %rax, %rdi
movq %rbx, %rsi
callq 0x99d7
testb %al, %al
je 0x8f69
movq %r13, %rdi
movl %r15d, %esi
callq 0x626e
leaq -0x68(%rbp), %rdi
jmp 0x8f8a
movq %r12, %rdi
movq %r14, %rsi
callq 0x99d7
testb %al, %al
je 0x8f98
movq %r13, %rdi
movl %r15d, %esi
callq 0x626e
leaq -0xa0(%rbp), %rdi
movq %rax, %rsi
callq 0x2140
addl $0x2, %r15d
jmp 0x8f2a
movq %r12, %rdi
leaq 0x8119(%rip), %rsi      # 0x110bb
callq 0x99d7
testb %al, %al
je 0x900b
movq %r13, %rdi
movl %r15d, %esi
callq 0x626e
movq (%rax), %rdi
leaq 0x8102(%rip), %rsi      # 0x110c2
leaq -0x38(%rbp), %rdx
leaq -0x34(%rbp), %rcx
leaq -0x30(%rbp), %r8
xorl %eax, %eax
callq 0x2200
movss -0x38(%rbp), %xmm0
movss 0x7c10(%rip), %xmm2     # 0x10bf0
mulss %xmm2, %xmm0
movss %xmm0, -0x38(%rbp)
movss -0x34(%rbp), %xmm0
movss -0x30(%rbp), %xmm1
mulss %xmm2, %xmm1
movss %xmm1, -0x34(%rbp)
mulss 0x7bf0(%rip), %xmm0     # 0x10bf4
movss %xmm0, -0x30(%rbp)
jmp 0x8f92
movq %r12, %rdi
leaq 0x80b6(%rip), %rsi      # 0x110cb
callq 0x99d7
testb %al, %al
je 0x8f92
movq %r13, %rdi
movl %r15d, %esi
callq 0x626e
movq (%rax), %rdi
leaq 0x8091(%rip), %rsi      # 0x110c8
leaq -0x2c(%rbp), %rdx
xorl %eax, %eax
callq 0x2200
movss -0x2c(%rbp), %xmm0
addss 0x7ba9(%rip), %xmm0     # 0x10bf8
mulss 0x7ba5(%rip), %xmm0     # 0x10bfc
movss %xmm0, -0x2c(%rbp)
jmp 0x8f92
leaq 0x8069(%rip), %rsi      # 0x110d1
leaq -0x68(%rbp), %rdi
callq 0x99d7
testb %al, %al
je 0x90ab
movq -0xa0(%rbp), %rdx
cvtss2sd -0x38(%rbp), %xmm0
cvtss2sd -0x34(%rbp), %xmm1
cvtss2sd -0x30(%rbp), %xmm2
cvtss2sd -0x2c(%rbp), %xmm3
leaq 0x804a(%rip), %rsi      # 0x110e1
pushq $0x22
popq %rcx
movq -0x48(%rbp), %rdi
movq %rdx, %r8
movl %ecx, %r9d
movb $0x4, %al
callq 0x2330
leaq 0x809a(%rip), %rsi      # 0x1114c
leaq -0x68(%rbp), %rdi
callq 0x99d7
testb %al, %al
je 0x90ef
cvtss2sd -0x38(%rbp), %xmm0
cvtss2sd -0x34(%rbp), %xmm1
cvtss2sd -0x30(%rbp), %xmm2
cvtss2sd -0x2c(%rbp), %xmm3
movq -0x68(%rbp), %rcx
leaq 0x800a(%rip), %rsi      # 0x110e8
pushq $0x22
popq %rdx
movq -0x48(%rbp), %rdi
movl %edx, %r8d
movb $0x4, %al
callq 0x2330
leaq -0x80(%rbp), %rdi
callq 0x61c2
leaq -0xa0(%rbp), %rdi
callq 0x2120
leaq -0x68(%rbp), %rdi
callq 0x2120
addq $0x98, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %rbx
leaq -0xc0(%rbp), %rdi
callq 0x2120
jmp 0x913c
jmp 0x9139
movq %rax, %rbx
jmp 0x9145
jmp 0x9139
movq %rax, %rbx
leaq -0x80(%rbp), %rdi
callq 0x61c2
leaq -0xa0(%rbp), %rdi
callq 0x2120
leaq -0x68(%rbp), %rdi
callq 0x2120
movq %rbx, %rdi
callq 0x23e0