forked from mtcontrib/weather_pack
		
	minor code cleanup
This commit is contained in:
		| @@ -31,7 +31,7 @@ end | |||||||
| rain.add_rain_particles = function(player, dtime) | rain.add_rain_particles = function(player, dtime) | ||||||
|   rain.last_rp_count = 0 |   rain.last_rp_count = 0 | ||||||
|   for i=rain.particles_count, 1,-1 do |   for i=rain.particles_count, 1,-1 do | ||||||
|     local random_pos_x, random_pos_y, random_pos_z = get_random_pos_by_player_look_dir(player) |     local random_pos_x, random_pos_y, random_pos_z = weather.get_random_pos_by_player_look_dir(player) | ||||||
|     if minetest.get_node_light({x=random_pos_x, y=random_pos_y, z=random_pos_z}, 0.5) == 15 then |     if minetest.get_node_light({x=random_pos_x, y=random_pos_y, z=random_pos_z}, 0.5) == 15 then | ||||||
|       rain.last_rp_count = rain.last_rp_count + 1 |       rain.last_rp_count = rain.last_rp_count + 1 | ||||||
|       minetest.add_particle({ |       minetest.add_particle({ | ||||||
| @@ -136,7 +136,7 @@ end) | |||||||
| rain.make_weather = function() | rain.make_weather = function() | ||||||
|   rain.raining = true |   rain.raining = true | ||||||
|   for _, player in ipairs(minetest.get_connected_players()) do |   for _, player in ipairs(minetest.get_connected_players()) do | ||||||
|     if (is_underwater(player)) then  |     if (weather.is_underwater(player)) then  | ||||||
|       return false |       return false | ||||||
|     end |     end | ||||||
|     rain.add_player(player) |     rain.add_player(player) | ||||||
|   | |||||||
| @@ -6,8 +6,8 @@ snow.particles_count = 25 | |||||||
| snow.add_rain_particles = function(player, dtime) | snow.add_rain_particles = function(player, dtime) | ||||||
|   rain.last_rp_count = 0 |   rain.last_rp_count = 0 | ||||||
|   for i=snow.particles_count, 1,-1 do |   for i=snow.particles_count, 1,-1 do | ||||||
|     local random_pos_x, random_pos_y, random_pos_z = get_random_pos_by_player_look_dir(player) |     local random_pos_x, random_pos_y, random_pos_z = weather.get_random_pos_by_player_look_dir(player) | ||||||
|     random_pos_y = math.random() + random_pos(player:getpos().y - 1, player:getpos().y + 7) |     random_pos_y = math.random() + math.random(player:getpos().y - 1, player:getpos().y + 7) | ||||||
|     if minetest.get_node_light({x=random_pos_x, y=random_pos_y, z=random_pos_z}, 0.5) == 15 then |     if minetest.get_node_light({x=random_pos_x, y=random_pos_y, z=random_pos_z}, 0.5) == 15 then | ||||||
|       rain.last_rp_count = rain.last_rp_count + 1 |       rain.last_rp_count = rain.last_rp_count + 1 | ||||||
|       minetest.add_particle({ |       minetest.add_particle({ | ||||||
| @@ -43,7 +43,7 @@ minetest.register_globalstep(function(dtime) | |||||||
|   end |   end | ||||||
|    |    | ||||||
|   for _, player in ipairs(minetest.get_connected_players()) do |   for _, player in ipairs(minetest.get_connected_players()) do | ||||||
|     if (is_underwater(player)) then  |     if (weather.is_underwater(player)) then  | ||||||
|       return false |       return false | ||||||
|     end |     end | ||||||
|     snow.add_rain_particles(player, dtime) |     snow.add_rain_particles(player, dtime) | ||||||
|   | |||||||
| @@ -47,7 +47,7 @@ end | |||||||
|  |  | ||||||
| -- checks if player is undewater. This is needed in order to | -- checks if player is undewater. This is needed in order to | ||||||
| -- turn off weather particles generation. | -- turn off weather particles generation. | ||||||
| function is_underwater(player) | weather.is_underwater = function(player) | ||||||
|     local ppos = player:getpos() |     local ppos = player:getpos() | ||||||
|     local offset = player:get_eye_offset() |     local offset = player:get_eye_offset() | ||||||
|     local player_eye_pos = {x = ppos.x + offset.x,  |     local player_eye_pos = {x = ppos.x + offset.x,  | ||||||
| @@ -60,17 +60,9 @@ function is_underwater(player) | |||||||
|     return false |     return false | ||||||
| end | end | ||||||
|  |  | ||||||
| -- returns random number between a and b. |  | ||||||
| function random_pos(a, b) |  | ||||||
|   if (a > b) then |  | ||||||
|     return math.random(b, a); |  | ||||||
|   end |  | ||||||
|   return math.random(a, b); |  | ||||||
| end |  | ||||||
|  |  | ||||||
| -- trying to locate position for particles by player look direction for performance reason. | -- trying to locate position for particles by player look direction for performance reason. | ||||||
| -- it is costly to generate many particles around player so goal is focus mainly on front view.   | -- it is costly to generate many particles around player so goal is focus mainly on front view.   | ||||||
| function get_random_pos_by_player_look_dir(player) | weather.get_random_pos_by_player_look_dir = function(player) | ||||||
|   local look_dir = player:get_look_dir() |   local look_dir = player:get_look_dir() | ||||||
|   local player_pos = player:getpos() |   local player_pos = player:getpos() | ||||||
|  |  | ||||||
| @@ -96,7 +88,7 @@ function get_random_pos_by_player_look_dir(player) | |||||||
|     end |     end | ||||||
|   end |   end | ||||||
|  |  | ||||||
|   random_pos_y = math.random() + random_pos(player_pos.y + 1, player_pos.y + 7) |   random_pos_y = math.random() + math.random(player_pos.y + 1, player_pos.y + 7) | ||||||
|   return random_pos_x, random_pos_y, random_pos_z |   return random_pos_x, random_pos_y, random_pos_z | ||||||
| end | end | ||||||
|  |  | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user