// File: tomfunkhouser[P]gaps/pkgs/GSV/GSVScene.cpp
// Function: gaps::GSVScene::ReadASCIIFile(char const*, int)
int GSVScene::
ReadASCIIFile(const char *filename, RNBoolean read_points)
{
  // Open file
  FILE *fp = fopen(filename, "r");
  if (!fp) {
    RNFail("Unable to open GSV scene file: %s\n", filename);
    return 0;
  }

  // Read run names from file
  int line_count = 0;
  const int buffer_size = 16*1024;
  char buffer[buffer_size];
  while (fgets(buffer, buffer_size, fp)) {
    line_count++;
    if (buffer[0] == '\0') continue;
    if (buffer[0] == '#') continue;
    char run_name[4096];
    if (sscanf(buffer, "%s", run_name) != (unsigned int) 1) {
      RNFail("Unable to read run name from line %d of %s\n", line_count, filename);
      return 0;
    }

    // Create run
    GSVRun *run = new GSVRun(run_name);
    InsertRun(run);

    // Read camera info
    if (!run->ReadCameraInfoFile()) return 0;

    // Read image info
    RNArray<GSVPanorama *> panoramas;
    if (!run->ReadImageSegmentFile(panoramas)) return 0;
    if (!run->ReadImagePoseFile(panoramas)) return 0;

    // Read laser stuff
    const int max_laser_index = 2;
    for (int laser_index = 0; laser_index <= max_laser_index; laser_index++) {
      if (laser_index == 1) continue;
      RNArray<GSVScanline *> scanlines;
      RNArray<GSVScan *> scanline_scans;
      if (!run->ReadLaserObjFile(laser_index, scanlines, scanline_scans, read_points)) return 0;
      if (!run->ReadLaserPoseFile(laser_index, scanlines, scanline_scans)) return 0;
    }
  }

  // Close file
  fclose(fp);

  // Return success
  return 1;
}

// Assembly:
subq $0x50c8, %rsp           # imm = 0x50C8
movq %rdi, 0x50b8(%rsp)
movq %rsi, 0x50b0(%rsp)
movl %edx, 0x50ac(%rsp)
movq 0x50b8(%rsp), %rax
movq %rax, 0x30(%rsp)
movq 0x50b0(%rsp), %rdi
leaq 0x246f19(%rip), %rsi    # 0x2833f3
callq 0x2a520
movq %rax, 0x50a0(%rsp)
cmpq $0x0, 0x50a0(%rsp)
jne 0x3c518
movq 0x50b0(%rsp), %rsi
leaq 0x22a705(%rip), %rdi    # 0x266c06
movb $0x0, %al
callq 0x1cbff0
movl $0x0, 0x50c4(%rsp)
jmp 0x3c875
movl $0x0, 0x509c(%rsp)
movl $0x4000, 0x5098(%rsp) # imm = 0x4000
leaq 0x1090(%rsp), %rdi
movq 0x50a0(%rsp), %rdx
movl $0x4000, %esi           # imm = 0x4000
callq 0x29bd0
cmpq $0x0, %rax
je 0x3c85d
movl 0x509c(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x509c(%rsp)
movsbl 0x1090(%rsp), %eax
cmpl $0x0, %eax
jne 0x3c572
jmp 0x3c52e
movsbl 0x1090(%rsp), %eax
cmpl $0x23, %eax
jne 0x3c581
jmp 0x3c52e
leaq 0x1090(%rsp), %rdi
leaq 0x90(%rsp), %rdx
leaq 0x243c8f(%rip), %rsi    # 0x280227
movb $0x0, %al
callq 0x29150
cmpl $0x1, %eax
je 0x3c5d1
movl 0x509c(%rsp), %esi
movq 0x50b0(%rsp), %rdx
leaq 0x22a66f(%rip), %rdi    # 0x266c29
movb $0x0, %al
callq 0x1cbff0
movl $0x0, 0x50c4(%rsp)
jmp 0x3c875
movl $0x90, %edi
callq 0x292e0
movq %rax, %rdi
movq %rdi, %rax
movq %rax, 0x28(%rsp)
leaq 0x90(%rsp), %rsi
callq 0x45090
jmp 0x3c5f5
movq 0x30(%rsp), %rdi
movq 0x28(%rsp), %rax
movq %rax, 0x88(%rsp)
movq 0x88(%rsp), %rsi
callq 0x3b700
movq 0x88(%rsp), %rdi
callq 0x46020
cmpl $0x0, %eax
jne 0x3c65b
movl $0x0, 0x50c4(%rsp)
jmp 0x3c875
movq 0x28(%rsp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x80(%rsp)
movl %eax, 0x7c(%rsp)
movl $0x90, %esi
callq 0x291f0
jmp 0x3c884
leaq 0x68(%rsp), %rdi
movq %rdi, 0x18(%rsp)
callq 0x44490
movq 0x18(%rsp), %rsi
movq 0x88(%rsp), %rdi
callq 0x464f0
movl %eax, 0x24(%rsp)
jmp 0x3c682
movl 0x24(%rsp), %eax
cmpl $0x0, %eax
jne 0x3c6b9
movl $0x0, 0x50c4(%rsp)
movl $0x1, 0x64(%rsp)
jmp 0x3c836
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x80(%rsp)
movl %eax, 0x7c(%rsp)
jmp 0x3c851
movq 0x88(%rsp), %rdi
leaq 0x68(%rsp), %rsi
callq 0x46850
movl %eax, 0x14(%rsp)
jmp 0x3c6d1
movl 0x14(%rsp), %eax
cmpl $0x0, %eax
jne 0x3c6f2
movl $0x0, 0x50c4(%rsp)
movl $0x1, 0x64(%rsp)
jmp 0x3c836
movl $0x2, 0x60(%rsp)
movl $0x0, 0x5c(%rsp)
cmpl $0x2, 0x5c(%rsp)
jg 0x3c82e
cmpl $0x1, 0x5c(%rsp)
jne 0x3c719
jmp 0x3c812
leaq 0x48(%rsp), %rdi
callq 0x444a0
jmp 0x3c725
leaq 0x38(%rsp), %rdi
callq 0x444b0
jmp 0x3c731
movq 0x88(%rsp), %rdi
movl 0x5c(%rsp), %esi
movl 0x50ac(%rsp), %r8d
leaq 0x48(%rsp), %rdx
leaq 0x38(%rsp), %rcx
callq 0x46e80
movl %eax, 0x10(%rsp)
jmp 0x3c75a
movl 0x10(%rsp), %eax
cmpl $0x0, %eax
jne 0x3c7ab
movl $0x0, 0x50c4(%rsp)
movl $0x1, 0x64(%rsp)
jmp 0x3c7f2
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x80(%rsp)
movl %eax, 0x7c(%rsp)
jmp 0x3c822
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x80(%rsp)
movl %eax, 0x7c(%rsp)
leaq 0x38(%rsp), %rdi
callq 0x444c0
jmp 0x3c822
movq 0x88(%rsp), %rdi
movl 0x5c(%rsp), %esi
leaq 0x48(%rsp), %rdx
leaq 0x38(%rsp), %rcx
callq 0x477e0
movl %eax, 0xc(%rsp)
jmp 0x3c7cc
movl 0xc(%rsp), %eax
cmpl $0x0, %eax
jne 0x3c7ea
movl $0x0, 0x50c4(%rsp)
movl $0x1, 0x64(%rsp)
jmp 0x3c7f2
movl $0x0, 0x64(%rsp)
leaq 0x38(%rsp), %rdi
callq 0x444c0
leaq 0x48(%rsp), %rdi
callq 0x444d0
movl 0x64(%rsp), %eax
testl %eax, %eax
jne 0x3c836
jmp 0x3c810
jmp 0x3c812
movl 0x5c(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x5c(%rsp)
jmp 0x3c702
leaq 0x48(%rsp), %rdi
callq 0x444d0
jmp 0x3c851
movl $0x0, 0x64(%rsp)
leaq 0x68(%rsp), %rdi
callq 0x444e0
movl 0x64(%rsp), %eax
testl %eax, %eax
je 0x3c84c
jmp 0x3c84a
jmp 0x3c875
jmp 0x3c52e
leaq 0x68(%rsp), %rdi
callq 0x444e0
jmp 0x3c884
movq 0x50a0(%rsp), %rdi
callq 0x297e0
movl $0x1, 0x50c4(%rsp)
movl 0x50c4(%rsp), %eax
addq $0x50c8, %rsp           # imm = 0x50C8
retq
movq 0x80(%rsp), %rdi
callq 0x29c10
nopw %cs:(%rax,%rax)