// File: intheswim[P]FractalTubes/infra.cpp
// Function: rollover()
void rollover()
{
    freePoints();
    
    rotation = 10.0 * (float)rand() / RAND_MAX;
    
    if (rand() & 1)
    {
        rotationSpeed = fabs (rotationSpeed);
    }
    else
    {
        rotationSpeed = -fabs (rotationSpeed);
    }
    
    x_shift = ((float)rand() / RAND_MAX - 0.5f) * 1.6f;
    
    image_alpha = 0.0;
    
    
    float scale = detailLevel;
    
#ifdef USE_RUNTIME
    scale = 2 * scale;
#endif
    
    if (m_Preview) scale = 0.4;
    
    M3DDrawer *m3d = new M3DDrawer (300 * scale, 200 * scale);
        
    m3d->SetDefaultPrams ();
    
    bool altPalette = AppParams::isPaletteAlternative();
    
    int palIndex = 0;
    
#ifndef USE_RUNTIME
    if (altPalette)
    {
        palIndex = rand();
    }
#endif
    
    m3d->SetAltPalette (altPalette, palIndex);
    
    bool lightChanged = NO;
    
    lightOption = AppParams::getLightSource();
    
    paletteOption = AppParams::getPalette();
    
    light2Sides = AppParams::getLight2Sides() ? GL_TRUE : GL_FALSE;
    
    distance2Light = AppParams::getLightDistance();
    
    bool newUseLight = AppParams::getLightMoving();
        
    if (newUseLight != USE_LIGHT)
    {
        USE_LIGHT = newUseLight;
        lightChanged = YES;
    }
    
    if ( USE_LIGHT )
    {
        m3d->DisableBrightness();
    }
    
    double light_x = 1; 
    double light_y = 1; 
    double light_z = 1; 
    
    m3d->SetLightDirection(light_x, light_y, light_z);
    
    if (!m3d->Paint (current_set_index, true, &pointData, &corePoints ))
    {
          if ((!m_Preview) && (AppParams::getDetailLevel() > 0))
          {
            writeLog ("Out of memory. Try smaller detail level.");
          }
          else if (!m_Preview)
          {
            writeLog ("Out of Memory");
          }

          return;
    }
    
    m3d_pt_count = m3d->getPointCount(m3d_pt_cycle);
    
    m3d_y_range = m3d->getYRange();
    
    delete m3d;
    
    shineFactor = AppParams::getGlossLevel();
        
    if (AppParams::getGlossRandom())
    {
        shineFactor = 0.1f * (rand() % 101);
    }
    
    if (lightChanged)
    {
        if (USE_LIGHT)
        {
            glShadeModel( SHADE_MODE );
            
            // both needed to enable light:
            glEnable(GL_LIGHTING);
            glEnable(GL_LIGHT0);
            
            glEnable ( GL_COLOR_MATERIAL ) ;
        }
        else
        {
            glShadeModel( SHADE_MODE );
        
            // both needed to enable light:
            glDisable (GL_LIGHTING);
            glDisable (GL_LIGHT0);
        
            glDisable ( GL_COLOR_MATERIAL ) ;
        }
    }
    
    rolloverPeriod = AppParams::getIntervalInSecs();
    
    rollover_time = time (NULL);
        
    grid_step = m3d_pt_cycle;
    
    if (USE_LIGHT)
    {
        adjustNormals();
    }
    
    after_rollover = true;

}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x50, %rsp
callq 0x5ee0
callq 0x30f0
cvtsi2ss %eax, %xmm0
cvtss2sd %xmm0, %xmm1
movsd 0x87be(%rip), %xmm0     # 0xe2c0
mulsd %xmm1, %xmm0
movsd 0x87aa(%rip), %xmm1     # 0xe2b8
divsd %xmm1, %xmm0
cvtsd2ss %xmm0, %xmm0
movss %xmm0, 0xda32(%rip)     # 0x13550
callq 0x30f0
andl $0x1, %eax
cmpl $0x0, %eax
je 0x5b42
movss 0xda49(%rip), %xmm0     # 0x1357c
callq 0x6620
movss %xmm0, 0xda3c(%rip)     # 0x1357c
jmp 0x5b64
movss 0xda32(%rip), %xmm0     # 0x1357c
callq 0x6620
movd %xmm0, %eax
xorl $0x80000000, %eax       # imm = 0x80000000
movd %eax, %xmm0
movss %xmm0, 0xda18(%rip)     # 0x1357c
callq 0x30f0
cvtsi2ss %eax, %xmm0
movss 0x8783(%rip), %xmm1     # 0xe2f8
divss %xmm1, %xmm0
movss 0x875b(%rip), %xmm1     # 0xe2dc
subss %xmm1, %xmm0
movss 0x8767(%rip), %xmm1     # 0xe2f4
mulss %xmm1, %xmm0
movss %xmm0, 0xd9b3(%rip)     # 0x1354c
xorps %xmm0, %xmm0
movsd %xmm0, 0xd9bc(%rip)     # 0x13560
movss 0xd9d4(%rip), %xmm0     # 0x13580
movss %xmm0, -0x4(%rbp)
testb $0x1, 0xd988(%rip)      # 0x13540
je 0x5bc7
movss 0x873a(%rip), %xmm0     # 0xe2fc
movss %xmm0, -0x4(%rbp)
movl $0x70, %edi
callq 0x3380
movq %rax, %rdi
movq %rdi, %rax
movq %rax, -0x48(%rbp)
movss -0x4(%rbp), %xmm1
movss 0x8718(%rip), %xmm2     # 0xe300
movaps %xmm1, %xmm0
mulss %xmm2, %xmm0
movss 0x870d(%rip), %xmm2     # 0xe304
mulss %xmm2, %xmm1
callq 0x8a20
jmp 0x5c02
movq -0x48(%rbp), %rax
movq %rax, -0x10(%rbp)
movq -0x10(%rbp), %rdi
callq 0x91c0
callq 0xb7c0
andb $0x1, %al
movb %al, -0x1d(%rbp)
movl $0x0, -0x24(%rbp)
testb $0x1, -0x1d(%rbp)
je 0x5c53
callq 0x30f0
movl %eax, -0x24(%rbp)
jmp 0x5c53
movq -0x48(%rbp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x18(%rbp)
movl %eax, -0x1c(%rbp)
movl $0x70, %esi
callq 0x3390
jmp 0x5ece
movq -0x10(%rbp), %rdi
movb -0x1d(%rbp), %al
movl -0x24(%rbp), %edx
andb $0x1, %al
movzbl %al, %esi
callq 0x91f0
movb $0x0, -0x25(%rbp)
callq 0xb620
movl %eax, 0xd90e(%rip)      # 0x13584
callq 0xb7a0
movl %eax, 0xd907(%rip)      # 0x13588
callq 0xb680
movb %al, %dl
xorl %eax, %eax
movl $0x1, %ecx
testb $0x1, %dl
cmovnel %ecx, %eax
cmpl $0x0, %eax
setne %al
andb $0x1, %al
movb %al, 0xd8b6(%rip)       # 0x13559
callq 0xb6f0
movss %xmm0, 0xd8ac(%rip)     # 0x1355c
callq 0xb810
andb $0x1, %al
movb %al, -0x26(%rbp)
movb -0x26(%rbp), %al
andb $0x1, %al
movzbl %al, %eax
movb 0xd890(%rip), %cl       # 0x13558
andb $0x1, %cl
movzbl %cl, %ecx
cmpl %ecx, %eax
je 0x5ce1
movb -0x26(%rbp), %al
andb $0x1, %al
movb %al, 0xd87b(%rip)       # 0x13558
movb $0x1, -0x25(%rbp)
testb $0x1, 0xd870(%rip)      # 0x13558
je 0x5cf3
movq -0x10(%rbp), %rdi
callq 0x9230
movsd 0x8555(%rip), %xmm0     # 0xe250
movsd %xmm0, -0x30(%rbp)
movsd 0x8548(%rip), %xmm0     # 0xe250
movsd %xmm0, -0x38(%rbp)
movsd 0x853b(%rip), %xmm0     # 0xe250
movsd %xmm0, -0x40(%rbp)
movq -0x10(%rbp), %rdi
movsd -0x30(%rbp), %xmm0
movsd -0x38(%rbp), %xmm1
movsd -0x40(%rbp), %xmm2
callq 0xac60
movq -0x10(%rbp), %rdi
movl 0xd850(%rip), %esi      # 0x1358c
movl $0x1, %edx
leaq 0xd7e8(%rip), %rcx      # 0x13530
leaq 0xd7e9(%rip), %r8       # 0x13538
callq 0x9250
testb $0x1, %al
jne 0x5d95
testb $0x1, 0xd7e1(%rip)      # 0x13540
jne 0x5d79
callq 0xb550
cmpl $0x0, %eax
jle 0x5d79
leaq 0x85f7(%rip), %rdi      # 0xe369
callq 0x4590
jmp 0x5d90
testb $0x1, 0xd7c0(%rip)      # 0x13540
jne 0x5d8e
leaq 0x8609(%rip), %rdi      # 0xe392
callq 0x4590
jmp 0x5d90
jmp 0x5ec8
movq -0x10(%rbp), %rdi
leaq 0xd7d0(%rip), %rsi      # 0x13570
callq 0xa9c0
movq %rax, 0xd7bc(%rip)      # 0x13568
movq -0x10(%rbp), %rdi
callq 0x6640
cvtss2sd %xmm0, %xmm0
movsd %xmm0, 0xd7cf(%rip)     # 0x13590
movq -0x10(%rbp), %rax
movq %rax, -0x50(%rbp)
cmpq $0x0, %rax
je 0x5de6
movq -0x50(%rbp), %rdi
callq 0x90a0
movq -0x50(%rbp), %rdi
movl $0x70, %esi
callq 0x3390
callq 0xb9a0
movss %xmm0, 0xd761(%rip)     # 0x13554
callq 0xb950
testb $0x1, %al
jne 0x5dfe
jmp 0x5e23
callq 0x30f0
movl $0x65, %ecx
cltd
idivl %ecx
cvtsi2ss %edx, %xmm1
movss 0x84d5(%rip), %xmm0     # 0xe2ec
mulss %xmm1, %xmm0
movss %xmm0, 0xd731(%rip)     # 0x13554
testb $0x1, -0x25(%rbp)
je 0x5e86
testb $0x1, 0xd728(%rip)      # 0x13558
je 0x5e5c
movl $0x1d01, %edi           # imm = 0x1D01
callq 0x3670
movl $0xb50, %edi            # imm = 0xB50
callq 0x3340
movl $0x4000, %edi           # imm = 0x4000
callq 0x3340
movl $0xb57, %edi            # imm = 0xB57
callq 0x3340
jmp 0x5e84
movl $0x1d01, %edi           # imm = 0x1D01
callq 0x3670
movl $0xb50, %edi            # imm = 0xB50
callq 0x30d0
movl $0x4000, %edi           # imm = 0x4000
callq 0x30d0
movl $0xb57, %edi            # imm = 0xB57
callq 0x30d0
jmp 0x5e86
callq 0xb8b0
cvttss2si %xmm0, %rax
movq %rax, 0xd701(%rip)      # 0x13598
xorl %eax, %eax
movl %eax, %edi
callq 0x3330
movq %rax, 0xd6f9(%rip)      # 0x135a0
movl 0xd6c3(%rip), %eax      # 0x13570
movl %eax, 0xd6c1(%rip)      # 0x13574
testb $0x1, 0xd69e(%rip)      # 0x13558
je 0x5ec1
callq 0x5f50
movb $0x1, 0xd6e0(%rip)      # 0x135a8
addq $0x50, %rsp
popq %rbp
retq
movq -0x18(%rbp), %rdi
callq 0x36b0
nopw (%rax,%rax)