Simulation problem [Love2D/Lua]

Questions about the LÖVE API, installing LÖVE and other support related questions go here.
Forum rules
Before you make a thread asking for help, read this.
Post Reply
User avatar
RedHot
Citizen
Posts: 87
Joined: Mon May 27, 2013 2:43 pm
Location: Poland

Simulation problem [Love2D/Lua]

Post by RedHot »

As this is my first post I'd like to say hi everyone :)

This is a "falling water" simulation based on a simple Cellular automata algorithm.
Have a look at the attachment.

The problem is I have designed the algorihm and according to my logic it's so simple it should work straight away. But some times there are groups of water that will accumulate mid air and not fall down.

There are 2 options :

1) My knowledge of LUA isn't sufficient and I am making a mistake in code
2) There is this tiny bug somewhere out there and I can't find it.

Code: Select all



(....)
	 MaxMass = 1.0; --The normal, un-pressurized mass of a full water cell
	 MaxCompress = 0.02; --//How much excess water a cell can store, compared to the cell above it
	 MinFlow = 0
	 MinMass = 0.0001;  --//Ignore cells that are dry

function simulateCompression()
local Flow = 0
for i = 1, map_y+1 do
	for j = 1, map_x+1 do
		if grid[i][j] == 1 then

			local  remaining_mass = mass[map_y+2-i][j]
			if remaining_mass > MinMass then
			
				 if (grid[map_y+2-i+1][j] == 1) and mass[map_y+2-i+1][j]<(MaxMass+MaxCompress) then

					Flow = math.min( remaining_mass, MaxMass+MaxCompress -  mass[map_y+2-i+1][j])*math.min(globdt,0.3)
					Flow = math.max(0,Flow)
					b1x = Flow
					remaining_mass = remaining_mass- Flow 
					mass[map_y+2-i][j] = remaining_mass 
					newmass[map_y+2-i][j] = mass[map_y+2-i][j]
					newmass[map_y+2-i+1][j] = mass[map_y+2-i+1][j] +Flow
		
						
				 end
				 
				 
				 
				
			end
			
		end
	end
end

for i = 1, map_y+2 do
  for j = 1, map_x+2 do
	mass[i][j] = newmass[i][j] 
  end
end

end
Attachments
main.lua
(2.96 KiB) Downloaded 52 times
User avatar
Plu
Inner party member
Posts: 722
Joined: Fri Mar 15, 2013 9:36 pm

Re: Simulation problem [Love2D/Lua]

Post by Plu »

You don't have any output in there, so I can't actually see anything happening...
User avatar
RedHot
Citizen
Posts: 87
Joined: Mon May 27, 2013 2:43 pm
Location: Poland

Re: Simulation problem [Love2D/Lua]

Post by RedHot »

You have the main.lua file in the attachment. Just run it as a Love2d code :)


Problem Solved

There was an error with. "if grid[j] == 1 then"
Post Reply

Who is online

Users browsing this forum: Bing [Bot], davidkonsumer and 21 guests