starlit  Diff

Differences From Artifact [df4ee2ddd8]:

To Artifact [44e70e86d4]:


    61     61   
    62     62   	-- complex algorithms that cut across namespaces or don't belong anywhere else
    63     63   	alg = {};
    64     64   
    65     65   	region = {
    66     66   		radiator = {
    67     67   			store = AreaStore();
    68         -			emitters = {};
           68  +			sources = {};
    69     69   		};
    70     70   	};
    71     71   
    72     72   	-- standardized effects
    73     73   	fx = {};
    74     74   
    75     75   	type = {};
................................................................................
   218    218   	if not chunk then error(err) end
   219    219   	return chunk(...)
   220    220   end
   221    221   
   222    222   function starlit.include(name, ...) -- semantic variant used for loading modules
   223    223   	return starlit.evaluate(name..'.lua', ...)
   224    224   end
          225  +
          226  +function starlit.region.radiator.scan(pos,node)
          227  +	local R = starlit.region
          228  +	local phash = minetest.hash_node_position(pos)
          229  +	if R.radiator.sources[phash] then return end -- already loaded
          230  +	node = node or minetest.get_node(pos)
          231  +
          232  +	local def = minetest.registered_nodes[node.name]
          233  +	local cl = def._starlit and def._starlit.radiator
          234  +	if not cl then return nil end
          235  +	local min,max = cl.maxEffectArea and cl.maxEffectArea(pos) or nil
          236  +	if not min then
          237  +		assert(cl.radius, 'no radius callback for radiator')
          238  +		local r = cl.radius(pos)
          239  +		local vr = vector.new(r,r,r)
          240  +		min,max = pos-vr, pos+vr
          241  +	end
          242  +	local id = R.radiator.store:insert_area(min,max, minetest.pos_to_string(pos))
          243  +	R.radiator.sources[phash] = id
          244  +end
          245  +
          246  +function starlit.region.radiator.unload(pos)
          247  +	local R = starlit.region
          248  +	local phash = minetest.hash_node_position(pos)
          249  +	local id = R.radiator.sources[phash]
          250  +	R.radiator.store:remove_area(id)
          251  +	R.radiator.sources[phash] = nil
          252  +end
   225    253   
   226    254   minetest.register_lbm {
   227    255   	label = 'build radiator index';
   228    256   	name = 'starlit:loadradiatorboxes';
   229    257   	nodenames = {'group:radiator'};
   230    258   	run_at_every_load = true;
   231    259   	action = function(pos, node, dt)
   232         -		local R = starlit.region
   233         -		local phash = minetest.hash_node_position(pos)
   234         -		if R.radiator.sources[phash] then return end -- already loaded
   235         -
   236         -		local def = minetest.registered_nodes[node.name]
   237         -		local cl = def._starlit.radiator
   238         -		local min,max = cl.maxEffectArea(pos)
   239         -		local id = R.radiator.store:insert_area(min,max, minetest.pos_to_string(pos))
   240         -		R.radiator.sources[phash] = id
          260  +		starlit.region.radiator.scan(pos, node)
   241    261   	end;
   242    262   	-- NOTE: temp emitter nodes are responsible for decaching themselves in their on_destruct cb
   243    263   }
          264  +
   244    265   
   245    266   function starlit.startJob(id, interval, job)
   246    267   	local lastRun
   247    268   	local function start()
   248    269   		starlit.jobs[id] = minetest.after(interval, function()
   249    270   			local t = minetest.get_gametime()
   250    271   			local d = lastRun and t - lastRun or nil