window.refsize(window.size())
window.resizemode(2)
MouseCursor.showMouse(true)

-- http://www-e.uni-magdeburg.de/kubisch/shaderworkshop.exe

local res = reschunk.getdefault()

function Reload()
	print "RELOAD START"
	
	UtilFunctions.freelook(false)
	Timer.remove "tutorial"
	TimerTask.deleteAll()

	for i=0,l3dlist.l3dsetcount()-1 do
		l3dset.get(i):getdefaultview():rcmdempty()
		l3dset.get(i):disabled(false)
	end
	l3dset.get(0):layer(0)
	l3dcamera.default():unlink()
	l3dcamera.default():worldpos(0,0,0)
	
	env = nil
	collectgarbage "collect"
	
	
	TimerTask.new(
		function()	
			collectgarbage "collect"
			res:clearload(-1)
			local sessionfile = dofile("session_startupcfg.lua")
			local fn,err = loadfile(sessionfile)
			if not fn then
				print("error:",err)
				return
			end
	
			l3dcamera.default():linkinterface(scenenode.getroot())
			l3dcamera.default():backplane(1024)
			l3dcamera.default():frontplane(1)
			
			print "RELOAD KICK"
	
			env = {}
			setmetatable(env,{__index = _G})
			setfenv(fn,env)
	
			fn()
		end,100)
end

Keyboard.setKeyBinding("F5",Reload,500)

Reload()
