###############################################################
##
## Show these accelerated suckers who we are ;)
##
###############################################################

#
# Blenders
#

create FillColor32bpp whiteScreen { color = white }

create FillColor32bpp clearScreen { }
create FillColor32bpp clearBuffer { screen = buffer }
create FillColor32bpp fadeScreen { render = fadein }
create FillColor32bpp fadeBuffer { screen = buffer render = fadein }

create FillColor32bpp fadeinBuffer { screen = buffer render = fadein }
create FillColor32bpp fadeoutBuffer { screen = buffer render = fadeout }

create FillLayer32bpp blendBuffer2 { screen = buffer source = buffer2 render = fadein }
create FillLayer32bpp addBuffer { source = buffer render = add }

create FillLayer32bpp blendTitle { source = title render = fadein }
create FillLayer32bpp blendLoading  {source = loading render = fadein }

create Integer fadetoglenz25 = linear [ 0, 8, 1 ]
create FillLayer32bpp blendCouloir { source = buffer2 render = fadetoglenz25 }

#
# Distos
#

create CombineLayer32bpp lightDisto {
	lut = floor_shade
	source1 = buffer8bpp
	source2 = lightbuffer
	screen = buffer
}

create CombineLayer32bpp lightDisto2 {
	lut = floor_shade
	source1 = buffer8bpp
	source2 = lightbuffer
	screen = buffer2
}

create Disto8bpp briocheFloor {
	screen = buffer8bpp
	map = floor_map8bpp 
	light_buffer = lightbuffer
	compute_light = true
	#high_quality = true
	type = "freeWarpedFloor"
}
	
create Disto8bpp briocheWarper {
	screen = buffer8bpp
	map = floor_map8bpp 
	light_buffer = lightbuffer
	compute_light = true
	#high_quality = true
	type = "warper"
}

create Disto8bpp valdorWarper {
	screen = buffer8bpp
	map = floor_map8bpp 
	light_buffer = lightbuffer
	compute_light = true
	#high_quality = true
	type = "valdor"
}

create Disto32bpp twirlWarper {
	screen = buffer2
	map = floor_map32bpp 
	#light_buffer = lightbuffer
	#compute_light = true
	#high_quality = true
	type = "twirl"
}

#
# Tunnel during the whole demo
#

create Vector2 tunnelPosition = sinus [ (144,100), (80,0), 0.3]
create Vector2 attenuatePosition = sinus [ (-144,-100), (-80,0), 0.3]

create Vector2 tunnelDisplacement = linear [ (0,0), (64000, 0), 0.0009]

create DynamicOffsets updateCouloir {
	offsets = couloirOffsets
	source_offsets = sourceCouloirOffsets
	position = tunnelPosition
	displacement = tunnelDisplacement
}

create Tunnel32bpp drawCouloir { 
	screen = buffer2
	offsets = couloirOffsets
	map = floor_map32bpp
}

create PutSprite32bpp attenuateCouloir {
	screen = buffer2
	source = sourceTunnelLitemap
	render = sub
	position = attenuatePosition 
	pixel_position = true
}

<
create TunnelLighted32bpp drawCouloir { 
	screen = buffer2
	offsets = couloirOffsets
	map = floor2_map8bpp
	lut = floor2_shade
	lightmap = tunnel_litemap
	#displacement = tunnelDisplacement
}
>

###############################################################
##
## Demo Script
##
###############################################################

#loading
play clearScreen 0 4 0 0 1
play blendLoading 0 3 0 1 1
wait 3
modify blendLoading { render = fadeout }
play blendLoading 3 4 0 1 1

# Title
play clearScreen 4 12 0 0 1
play blendTitle 4 7 0 0.8 1
wait 7
modify blendTitle { render = fadeout }
play blendTitle 7 12 0 0.2 1

# Square Tunnel Attenuation
play updateCouloir 7 155 0 1 10
play drawCouloir 7 155 0 1 10
play attenuateCouloir 7 155 0 1 10
play blendCouloir 7 155 0 0.2 99

# mix: screen = blend(screen, tunnel) + blend(buffer, buffer2)
play addBuffer 12 157 0 0 100

# Floor
play briocheFloor 12 35 0 10 1
play lightDisto 12 35 0 0 1
play fadeoutBuffer 12 17 0 0.2 1
play fadeinBuffer 30 35 0 0.2 1

# Nothing

# Valdor
play valdorWarper 40 75 0 0.2 1
play lightDisto 40 75 0 0 2
play fadeoutBuffer 40 45 0 0.2 2

# Warper
play briocheWarper 70 105 0 1.5 2
play lightDisto2 70 75 0 0 3
play blendBuffer2 70 75 0 0.2 3
play lightDisto 75 105 0 0 3

# Re-Floor 
play briocheFloor 100 145 2545 10 4
play lightDisto2 100 105 0 0 5
play blendBuffer2 100 105 0 0.2 5
play lightDisto 105 145 0 0 5

# Twirl
play twirlWarper 140 157 0 2 8
play blendBuffer2 140 145 0 0.2 9
wait 145
modify twirlWarper { screen = buffer }

#
# Surprise (@ kick)
#

# saturation for low framerate computers
create Interpreter saturate { 
	filename = "scripts/saturate.txt" 
	framerate = const 24
}

play saturate 157 158 0 1 12

wait 158
modify blendTitle { render = sub }
modify blendCouloir { render = fadein }
play whiteScreen 158 180 0 0 12
play updateCouloir 158 180 0 1 10
play drawCouloir 158 180 0 1 10
play attenuateCouloir 158 180 0 1 10
play blendCouloir 158 180 0 0.2 99
play blendTitle 158 180 0 0.32 101

# Fade out tunnel
play fadeScreen 175 180 0 0.35 102

#
# Credits
#

create FillLayer32bpp credit { source = credits }
play credit 186.5 240 0 0 1
wait 198.2
modify credit { source = greets1 }
wait 209.5
modify credit { source = greets2 }
wait 220.8
modify credit { source = greets3 }
wait 232.1
modify credit { source = greets4 }

wait 9999