Commits

Alex Szpakowski committed 1ded49f

Reorganized the nogame screen’s drawing code to marginally reduce CPU usage. Woo!

Comments (0)

Files changed (2)

 	local text = {}
 	local rain = {}
 	local g_time = 0
+	
+	local create_rain
 
 	function love.load()
 		-- Subtractive blending isn't supported on some ancient systems, so
 		rain.ox = -rain.img_w / 2
 		rain.oy = -rain.img_h / 2
 		rain.batch = love.graphics.newSpriteBatch(rain.image, 512)
+		rain.t = 0
+
+		create_rain()
 	end
+	
+	function create_rain()
+		local batch = rain.batch
 
-	local function update_rain(t)
-
-		local batch = rain.batch
-		local ix = 0
-		local iy = 0
 		local sx = rain.spacing_x
 		local sy = rain.spacing_y
 		local ox = rain.ox
 		local oy = rain.oy
-		local img_w = rain.img_w
-		local img_h = rain.img_h
 
 		local batch_w = 2 * math.ceil(love.graphics.getWidth() / sx) + 2
 		local batch_h = 2 * math.ceil(love.graphics.getHeight() / sy) + 2
 		for i = 0, batch_h - 1 do
 			for j = 0, batch_w - 1 do
 				local is_even = (j % 2) == 0
-				local offset_y = is_even and sy * t or sy / 2 + sy * t
-				local x = ix + ox + j * sx
-				local y = iy + oy + i * sy + offset_y
+				local offset_y = is_even and 0 or sy / 2
+				local x = ox + j * sx
+				local y = oy + i * sy + offset_y
 				batch:add(x, y)
 			end
 		end
 		batch:unbind()
 	end
 
+	local function update_rain(t)		
+		rain.t = t
+	end
+
+	function love.resize(w, h)
+		create_rain()
+	end
+
 	function love.update(dt)
 		g_time = g_time + dt / 2
 		local int, frac = math.modf(g_time)
 			blendmode = "additive"
 		end
 
+		local y = rain.spacing_y * rain.t
+
+		local small_y = -rain.spacing_y + y / 2
+		local big_y = -rain.spacing_y + y
+
 		love.graphics.setBlendMode(blendmode)
 		love.graphics.setColor(255, 255, 255, 128)
-		love.graphics.draw(rain.batch, -rain.spacing_x, -rain.spacing_y, 0, 0.5, 0.5)
+		love.graphics.draw(rain.batch, -rain.spacing_x, small_y, 0, 0.5, 0.5)
 
 		love.graphics.setBlendMode("alpha")
 		love.graphics.setColor(255, 255, 255, 255)
-		love.graphics.draw(rain.batch, -rain.spacing_x, -rain.spacing_y)
+		love.graphics.draw(rain.batch, -rain.spacing_x, big_y)
 	end
 
 	local function draw_text(x, y)

src/scripts/boot.lua.h

 	0x09, 0x6c, 0x6f, 0x63, 0x61, 0x6c, 0x20, 0x74, 0x65, 0x78, 0x74, 0x20, 0x3d, 0x20, 0x7b, 0x7d, 0x0a,
 	0x09, 0x6c, 0x6f, 0x63, 0x61, 0x6c, 0x20, 0x72, 0x61, 0x69, 0x6e, 0x20, 0x3d, 0x20, 0x7b, 0x7d, 0x0a,
 	0x09, 0x6c, 0x6f, 0x63, 0x61, 0x6c, 0x20, 0x67, 0x5f, 0x74, 0x69, 0x6d, 0x65, 0x20, 0x3d, 0x20, 0x30, 0x0a,
+	0x09, 0x0a,
+	0x09, 0x6c, 0x6f, 0x63, 0x61, 0x6c, 0x20, 0x63, 0x72, 0x65, 0x61, 0x74, 0x65, 0x5f, 0x72, 0x61, 0x69, 0x6e, 0x0a,
 	0x09, 0x66, 0x75, 0x6e, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x20, 0x6c, 0x6f, 0x76, 0x65, 0x2e, 0x6c, 0x6f, 0x61, 
 	0x64, 0x28, 0x29, 0x0a,
 	0x09, 0x09, 0x2d, 0x2d, 0x20, 0x53, 0x75, 0x62, 0x74, 0x72, 0x61, 0x63, 0x74, 0x69, 0x76, 0x65, 0x20, 0x62, 
 	0x65, 0x2e, 0x67, 0x72, 0x61, 0x70, 0x68, 0x69, 0x63, 0x73, 0x2e, 0x6e, 0x65, 0x77, 0x53, 0x70, 0x72, 0x69, 
 	0x74, 0x65, 0x42, 0x61, 0x74, 0x63, 0x68, 0x28, 0x72, 0x61, 0x69, 0x6e, 0x2e, 0x69, 0x6d, 0x61, 0x67, 0x65, 
 	0x2c, 0x20, 0x35, 0x31, 0x32, 0x29, 0x0a,
+	0x09, 0x09, 0x72, 0x61, 0x69, 0x6e, 0x2e, 0x74, 0x20, 0x3d, 0x20, 0x30, 0x0a,
+	0x09, 0x09, 0x63, 0x72, 0x65, 0x61, 0x74, 0x65, 0x5f, 0x72, 0x61, 0x69, 0x6e, 0x28, 0x29, 0x0a,
 	0x09, 0x65, 0x6e, 0x64, 0x0a,
-	0x09, 0x6c, 0x6f, 0x63, 0x61, 0x6c, 0x20, 0x66, 0x75, 0x6e, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x20, 0x75, 0x70, 
-	0x64, 0x61, 0x74, 0x65, 0x5f, 0x72, 0x61, 0x69, 0x6e, 0x28, 0x74, 0x29, 0x0a,
+	0x09, 0x0a,
+	0x09, 0x66, 0x75, 0x6e, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x20, 0x63, 0x72, 0x65, 0x61, 0x74, 0x65, 0x5f, 0x72, 
+	0x61, 0x69, 0x6e, 0x28, 0x29, 0x0a,
 	0x09, 0x09, 0x6c, 0x6f, 0x63, 0x61, 0x6c, 0x20, 0x62, 0x61, 0x74, 0x63, 0x68, 0x20, 0x3d, 0x20, 0x72, 0x61, 
 	0x69, 0x6e, 0x2e, 0x62, 0x61, 0x74, 0x63, 0x68, 0x0a,
-	0x09, 0x09, 0x6c, 0x6f, 0x63, 0x61, 0x6c, 0x20, 0x69, 0x78, 0x20, 0x3d, 0x20, 0x30, 0x0a,
-	0x09, 0x09, 0x6c, 0x6f, 0x63, 0x61, 0x6c, 0x20, 0x69, 0x79, 0x20, 0x3d, 0x20, 0x30, 0x0a,
 	0x09, 0x09, 0x6c, 0x6f, 0x63, 0x61, 0x6c, 0x20, 0x73, 0x78, 0x20, 0x3d, 0x20, 0x72, 0x61, 0x69, 0x6e, 0x2e, 
 	0x73, 0x70, 0x61, 0x63, 0x69, 0x6e, 0x67, 0x5f, 0x78, 0x0a,
 	0x09, 0x09, 0x6c, 0x6f, 0x63, 0x61, 0x6c, 0x20, 0x73, 0x79, 0x20, 0x3d, 0x20, 0x72, 0x61, 0x69, 0x6e, 0x2e, 
 	0x6f, 0x78, 0x0a,
 	0x09, 0x09, 0x6c, 0x6f, 0x63, 0x61, 0x6c, 0x20, 0x6f, 0x79, 0x20, 0x3d, 0x20, 0x72, 0x61, 0x69, 0x6e, 0x2e, 
 	0x6f, 0x79, 0x0a,
-	0x09, 0x09, 0x6c, 0x6f, 0x63, 0x61, 0x6c, 0x20, 0x69, 0x6d, 0x67, 0x5f, 0x77, 0x20, 0x3d, 0x20, 0x72, 0x61, 
-	0x69, 0x6e, 0x2e, 0x69, 0x6d, 0x67, 0x5f, 0x77, 0x0a,
-	0x09, 0x09, 0x6c, 0x6f, 0x63, 0x61, 0x6c, 0x20, 0x69, 0x6d, 0x67, 0x5f, 0x68, 0x20, 0x3d, 0x20, 0x72, 0x61, 
-	0x69, 0x6e, 0x2e, 0x69, 0x6d, 0x67, 0x5f, 0x68, 0x0a,
 	0x09, 0x09, 0x6c, 0x6f, 0x63, 0x61, 0x6c, 0x20, 0x62, 0x61, 0x74, 0x63, 0x68, 0x5f, 0x77, 0x20, 0x3d, 0x20, 
 	0x32, 0x20, 0x2a, 0x20, 0x6d, 0x61, 0x74, 0x68, 0x2e, 0x63, 0x65, 0x69, 0x6c, 0x28, 0x6c, 0x6f, 0x76, 0x65, 
 	0x2e, 0x67, 0x72, 0x61, 0x70, 0x68, 0x69, 0x63, 0x73, 0x2e, 0x67, 0x65, 0x74, 0x57, 0x69, 0x64, 0x74, 0x68, 
 	0x09, 0x09, 0x09, 0x09, 0x6c, 0x6f, 0x63, 0x61, 0x6c, 0x20, 0x69, 0x73, 0x5f, 0x65, 0x76, 0x65, 0x6e, 0x20, 
 	0x3d, 0x20, 0x28, 0x6a, 0x20, 0x25, 0x20, 0x32, 0x29, 0x20, 0x3d, 0x3d, 0x20, 0x30, 0x0a,
 	0x09, 0x09, 0x09, 0x09, 0x6c, 0x6f, 0x63, 0x61, 0x6c, 0x20, 0x6f, 0x66, 0x66, 0x73, 0x65, 0x74, 0x5f, 0x79, 
-	0x20, 0x3d, 0x20, 0x69, 0x73, 0x5f, 0x65, 0x76, 0x65, 0x6e, 0x20, 0x61, 0x6e, 0x64, 0x20, 0x73, 0x79, 0x20, 
-	0x2a, 0x20, 0x74, 0x20, 0x6f, 0x72, 0x20, 0x73, 0x79, 0x20, 0x2f, 0x20, 0x32, 0x20, 0x2b, 0x20, 0x73, 0x79, 
-	0x20, 0x2a, 0x20, 0x74, 0x0a,
-	0x09, 0x09, 0x09, 0x09, 0x6c, 0x6f, 0x63, 0x61, 0x6c, 0x20, 0x78, 0x20, 0x3d, 0x20, 0x69, 0x78, 0x20, 0x2b, 
-	0x20, 0x6f, 0x78, 0x20, 0x2b, 0x20, 0x6a, 0x20, 0x2a, 0x20, 0x73, 0x78, 0x0a,
-	0x09, 0x09, 0x09, 0x09, 0x6c, 0x6f, 0x63, 0x61, 0x6c, 0x20, 0x79, 0x20, 0x3d, 0x20, 0x69, 0x79, 0x20, 0x2b, 
-	0x20, 0x6f, 0x79, 0x20, 0x2b, 0x20, 0x69, 0x20, 0x2a, 0x20, 0x73, 0x79, 0x20, 0x2b, 0x20, 0x6f, 0x66, 0x66, 
-	0x73, 0x65, 0x74, 0x5f, 0x79, 0x0a,
+	0x20, 0x3d, 0x20, 0x69, 0x73, 0x5f, 0x65, 0x76, 0x65, 0x6e, 0x20, 0x61, 0x6e, 0x64, 0x20, 0x30, 0x20, 0x6f, 
+	0x72, 0x20, 0x73, 0x79, 0x20, 0x2f, 0x20, 0x32, 0x0a,
+	0x09, 0x09, 0x09, 0x09, 0x6c, 0x6f, 0x63, 0x61, 0x6c, 0x20, 0x78, 0x20, 0x3d, 0x20, 0x6f, 0x78, 0x20, 0x2b, 
+	0x20, 0x6a, 0x20, 0x2a, 0x20, 0x73, 0x78, 0x0a,
+	0x09, 0x09, 0x09, 0x09, 0x6c, 0x6f, 0x63, 0x61, 0x6c, 0x20, 0x79, 0x20, 0x3d, 0x20, 0x6f, 0x79, 0x20, 0x2b, 
+	0x20, 0x69, 0x20, 0x2a, 0x20, 0x73, 0x79, 0x20, 0x2b, 0x20, 0x6f, 0x66, 0x66, 0x73, 0x65, 0x74, 0x5f, 0x79, 0x0a,
 	0x09, 0x09, 0x09, 0x09, 0x62, 0x61, 0x74, 0x63, 0x68, 0x3a, 0x61, 0x64, 0x64, 0x28, 0x78, 0x2c, 0x20, 0x79, 
 	0x29, 0x0a,
 	0x09, 0x09, 0x09, 0x65, 0x6e, 0x64, 0x0a,
 	0x09, 0x09, 0x65, 0x6e, 0x64, 0x0a,
 	0x09, 0x09, 0x62, 0x61, 0x74, 0x63, 0x68, 0x3a, 0x75, 0x6e, 0x62, 0x69, 0x6e, 0x64, 0x28, 0x29, 0x0a,
 	0x09, 0x65, 0x6e, 0x64, 0x0a,
+	0x09, 0x6c, 0x6f, 0x63, 0x61, 0x6c, 0x20, 0x66, 0x75, 0x6e, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x20, 0x75, 0x70, 
+	0x64, 0x61, 0x74, 0x65, 0x5f, 0x72, 0x61, 0x69, 0x6e, 0x28, 0x74, 0x29, 0x09, 0x09, 0x0a,
+	0x09, 0x09, 0x72, 0x61, 0x69, 0x6e, 0x2e, 0x74, 0x20, 0x3d, 0x20, 0x74, 0x0a,
+	0x09, 0x65, 0x6e, 0x64, 0x0a,
+	0x09, 0x66, 0x75, 0x6e, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x20, 0x6c, 0x6f, 0x76, 0x65, 0x2e, 0x72, 0x65, 0x73, 
+	0x69, 0x7a, 0x65, 0x28, 0x77, 0x2c, 0x20, 0x68, 0x29, 0x0a,
+	0x09, 0x09, 0x63, 0x72, 0x65, 0x61, 0x74, 0x65, 0x5f, 0x72, 0x61, 0x69, 0x6e, 0x28, 0x29, 0x0a,
+	0x09, 0x65, 0x6e, 0x64, 0x0a,
 	0x09, 0x66, 0x75, 0x6e, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x20, 0x6c, 0x6f, 0x76, 0x65, 0x2e, 0x75, 0x70, 0x64, 
 	0x61, 0x74, 0x65, 0x28, 0x64, 0x74, 0x29, 0x0a,
 	0x09, 0x09, 0x67, 0x5f, 0x74, 0x69, 0x6d, 0x65, 0x20, 0x3d, 0x20, 0x67, 0x5f, 0x74, 0x69, 0x6d, 0x65, 0x20, 
 	0x09, 0x09, 0x09, 0x62, 0x6c, 0x65, 0x6e, 0x64, 0x6d, 0x6f, 0x64, 0x65, 0x20, 0x3d, 0x20, 0x22, 0x61, 0x64, 
 	0x64, 0x69, 0x74, 0x69, 0x76, 0x65, 0x22, 0x0a,
 	0x09, 0x09, 0x65, 0x6e, 0x64, 0x0a,
+	0x09, 0x09, 0x6c, 0x6f, 0x63, 0x61, 0x6c, 0x20, 0x79, 0x20, 0x3d, 0x20, 0x72, 0x61, 0x69, 0x6e, 0x2e, 0x73, 
+	0x70, 0x61, 0x63, 0x69, 0x6e, 0x67, 0x5f, 0x79, 0x20, 0x2a, 0x20, 0x72, 0x61, 0x69, 0x6e, 0x2e, 0x74, 0x0a,
+	0x09, 0x09, 0x6c, 0x6f, 0x63, 0x61, 0x6c, 0x20, 0x73, 0x6d, 0x61, 0x6c, 0x6c, 0x5f, 0x79, 0x20, 0x3d, 0x20, 
+	0x2d, 0x72, 0x61, 0x69, 0x6e, 0x2e, 0x73, 0x70, 0x61, 0x63, 0x69, 0x6e, 0x67, 0x5f, 0x79, 0x20, 0x2b, 0x20, 
+	0x79, 0x20, 0x2f, 0x20, 0x32, 0x0a,
+	0x09, 0x09, 0x6c, 0x6f, 0x63, 0x61, 0x6c, 0x20, 0x62, 0x69, 0x67, 0x5f, 0x79, 0x20, 0x3d, 0x20, 0x2d, 0x72, 
+	0x61, 0x69, 0x6e, 0x2e, 0x73, 0x70, 0x61, 0x63, 0x69, 0x6e, 0x67, 0x5f, 0x79, 0x20, 0x2b, 0x20, 0x79, 0x0a,
 	0x09, 0x09, 0x6c, 0x6f, 0x76, 0x65, 0x2e, 0x67, 0x72, 0x61, 0x70, 0x68, 0x69, 0x63, 0x73, 0x2e, 0x73, 0x65, 
 	0x74, 0x42, 0x6c, 0x65, 0x6e, 0x64, 0x4d, 0x6f, 0x64, 0x65, 0x28, 0x62, 0x6c, 0x65, 0x6e, 0x64, 0x6d, 0x6f, 
 	0x64, 0x65, 0x29, 0x0a,
 	0x35, 0x35, 0x2c, 0x20, 0x31, 0x32, 0x38, 0x29, 0x0a,
 	0x09, 0x09, 0x6c, 0x6f, 0x76, 0x65, 0x2e, 0x67, 0x72, 0x61, 0x70, 0x68, 0x69, 0x63, 0x73, 0x2e, 0x64, 0x72, 
 	0x61, 0x77, 0x28, 0x72, 0x61, 0x69, 0x6e, 0x2e, 0x62, 0x61, 0x74, 0x63, 0x68, 0x2c, 0x20, 0x2d, 0x72, 0x61, 
-	0x69, 0x6e, 0x2e, 0x73, 0x70, 0x61, 0x63, 0x69, 0x6e, 0x67, 0x5f, 0x78, 0x2c, 0x20, 0x2d, 0x72, 0x61, 0x69, 
-	0x6e, 0x2e, 0x73, 0x70, 0x61, 0x63, 0x69, 0x6e, 0x67, 0x5f, 0x79, 0x2c, 0x20, 0x30, 0x2c, 0x20, 0x30, 0x2e, 
-	0x35, 0x2c, 0x20, 0x30, 0x2e, 0x35, 0x29, 0x0a,
+	0x69, 0x6e, 0x2e, 0x73, 0x70, 0x61, 0x63, 0x69, 0x6e, 0x67, 0x5f, 0x78, 0x2c, 0x20, 0x73, 0x6d, 0x61, 0x6c, 
+	0x6c, 0x5f, 0x79, 0x2c, 0x20, 0x30, 0x2c, 0x20, 0x30, 0x2e, 0x35, 0x2c, 0x20, 0x30, 0x2e, 0x35, 0x29, 0x0a,
 	0x09, 0x09, 0x6c, 0x6f, 0x76, 0x65, 0x2e, 0x67, 0x72, 0x61, 0x70, 0x68, 0x69, 0x63, 0x73, 0x2e, 0x73, 0x65, 
 	0x74, 0x42, 0x6c, 0x65, 0x6e, 0x64, 0x4d, 0x6f, 0x64, 0x65, 0x28, 0x22, 0x61, 0x6c, 0x70, 0x68, 0x61, 0x22, 
 	0x29, 0x0a,
 	0x35, 0x35, 0x2c, 0x20, 0x32, 0x35, 0x35, 0x29, 0x0a,
 	0x09, 0x09, 0x6c, 0x6f, 0x76, 0x65, 0x2e, 0x67, 0x72, 0x61, 0x70, 0x68, 0x69, 0x63, 0x73, 0x2e, 0x64, 0x72, 
 	0x61, 0x77, 0x28, 0x72, 0x61, 0x69, 0x6e, 0x2e, 0x62, 0x61, 0x74, 0x63, 0x68, 0x2c, 0x20, 0x2d, 0x72, 0x61, 
-	0x69, 0x6e, 0x2e, 0x73, 0x70, 0x61, 0x63, 0x69, 0x6e, 0x67, 0x5f, 0x78, 0x2c, 0x20, 0x2d, 0x72, 0x61, 0x69, 
-	0x6e, 0x2e, 0x73, 0x70, 0x61, 0x63, 0x69, 0x6e, 0x67, 0x5f, 0x79, 0x29, 0x0a,
+	0x69, 0x6e, 0x2e, 0x73, 0x70, 0x61, 0x63, 0x69, 0x6e, 0x67, 0x5f, 0x78, 0x2c, 0x20, 0x62, 0x69, 0x67, 0x5f, 
+	0x79, 0x29, 0x0a,
 	0x09, 0x65, 0x6e, 0x64, 0x0a,
 	0x09, 0x6c, 0x6f, 0x63, 0x61, 0x6c, 0x20, 0x66, 0x75, 0x6e, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x20, 0x64, 0x72, 
 	0x61, 0x77, 0x5f, 0x74, 0x65, 0x78, 0x74, 0x28, 0x78, 0x2c, 0x20, 0x79, 0x29, 0x0a,