Page 8 of 91

Re: "Questions that don't deserve their own thread" thread

Posted: Thu Aug 14, 2014 9:16 pm
by Murii
Hello folks,I`m using middleclass for OOP but i`m wondering if all the self.variable are affecting the performance.I mean they are global vars right?

Re: "Questions that don't deserve their own thread" thread

Posted: Fri Aug 15, 2014 5:16 pm
by Wojak
Ranguna259 wrote: Are you saying that drawing a pixel and scalling it to look like a line would be faster then using the actual love.graphics.line() function ?
Yes, i discovered this by accident while experimenting with raycasting - the textured raycaser was faster then untextured (I used love.graphic.line for untextured and quads for textured)
And since this removes the scalling compatibility then it would be no longer an optimization but rather a downgrade :P
Regarding the color fancy stuff, I just used colors to make the tutorial a little easier to understand.
This code doesn't remove the scaling capability... All the functionality of your code is preserved, the only difference is that the performance is better when you zoom out to maximum (I tested this and it is about 100 FPS more from ~200 to ~300)

All you need to do is add this code to love.load ;)

Re: "Questions that don't deserve their own thread" thread

Posted: Sat Aug 16, 2014 1:17 am
by Ranguna259
Wojak wrote:
Ranguna259 wrote: Are you saying that drawing a pixel and scalling it to look like a line would be faster then using the actual love.graphics.line() function ?
Yes (...) I tested this and it is about 100 FPS more from ~200 to ~300
Oh my gowds !!! I haven't tested but according to what you said then why doesn't love use this by default ? Devs ?
Murii wrote:Hello folks,I`m using middleclass for OOP but i`m wondering if all the self.variable are affecting the performance.I mean they are global vars right?
I don't think that globals impacts performance

Re: "Questions that don't deserve their own thread" thread

Posted: Sat Aug 16, 2014 2:01 am
by slime
Ranguna259 wrote:Oh my gowds !!! I haven't tested but according to what you said then why doesn't love use this by default ? Devs ?
That is what LÖVE does - at least for lines which use the 'rough' line style (and the 'none' line join mode for multi-segment lines.)

The 'smooth' line style is the default and requires more work done by the CPU and GPU compared to rough lines. Same deal for line join modes other than 'none' when line segments need to be joined ('miter' is the default.)

Re: "Questions that don't deserve their own thread" thread

Posted: Sat Aug 16, 2014 7:31 am
by Plu
I don't think that globals impacts performance
They do impact the performance somewhat, as Lua first needs to check whether a local variable by the given name exists, and then has to look again in the global table after it finds it does not. However:
Hello folks,I`m using middleclass for OOP but i`m wondering if all the self.variable are affecting the performance.I mean they are global vars right?
The self.variable aren't global vars, the self is passed as a function argument. Lua allows you to say this:

Code: Select all

obj:func( arg )
but what really happens is this:

Code: Select all

obj.func( obj, arg )
As you can see, the Lua interpreter changes your code with the : syntax to the below syntax where the object you call the function on is passed to the function as the first argument, and it's argument name automatically becomes "self".

Re: "Questions that don't deserve their own thread" thread

Posted: Mon Aug 18, 2014 2:41 pm
by IceQB
Hi

I making simple "shadow".

Code: Select all

local light = {}
table.insert(light, {200, 200})
table.insert(light, {400,400})

local function myStencil()
   local circleradius = 100
   love.graphics.setColor(255, 255, 255, 235)
   for i, xy in pairs(light) do
      love.graphics.circle("fill", xy[1], xy[2], circleradius, 32)
	  love.graphics.circle("fill", player.x+10, player.y, circleradius, 32)
   end
end

function shadow_draw()
gfx.setColor( 255, 255, 255, 255 )
		gfx.setInvertedStencil( myStencil ) 
			gfx.setColor( 0, 0, 0, 200 ) 
	gfx.rectangle( 'fill', 0, 0, 720, 480 ) 
	gfx.setInvertedStencil() 
		gfx.setColor( 255, 255, 255, 235 )

end
Its look good but how can i add "light texture" from image if love2d dont support alpha color?
And what if 2 (or more) light texture be on each other?

I would rather do this without shader but its probably impossible.

Re: "Questions that don't deserve their own thread" thread

Posted: Mon Aug 18, 2014 4:43 pm
by Plu
Love2d supports setting a color's alpha through the 4th argument to setColor:

Code: Select all

love.graphics.setColor( red, green, blue, alpha )
Unless you mean something else I'm not sure what the problem is?

Re: "Questions that don't deserve their own thread" thread

Posted: Mon Aug 18, 2014 10:17 pm
by IceQB
Problem is this:

Image

Code with images:

Code: Select all

local light = {}
table.insert(light, {200, 200})
table.insert(light, {400,400})

local function myStencil()
   local circleradius = 100
   love.graphics.setColor(255, 255, 255, 235)
   for i, xy in pairs(light) do
     -- love.graphics.circle("fill", xy[1], xy[2], circleradius, 32)
	 gfx.draw(plight, xy[1], xy[2], 0, 1, 1,plight:getWidth()/2, plight:getHeight()/2)
gfx.draw(plight, player.x, player.y, 0, 1, 1,plight:getWidth()/2, plight:getHeight()/2)
	 --gfx.draw(plight, player.x+8, player.y, 0, 1, 1,plight:getWidth()/2, plight:getHeight()/2)

	 -- love.graphics.circle("fill", player.x+10, player.y, circleradius, 32)
   end
end

function shadow_draw()
gfx.setColor( 255, 255, 255, 255 )  
		gfx.setInvertedStencil( myStencil ) 
			gfx.setColor( 0, 0, 0, 235 ) 
	gfx.rectangle( 'fill', 0, 0, 720, 480 ) 
	gfx.setInvertedStencil() 
		gfx.setColor( 255, 255, 255, 235 )
	
				gfx.setColor( 255, 255, 255, 235 )
gfx.draw(plight, player.x, player.y, 0, 1, 1,plight:getWidth()/2, plight:getHeight()/2)

		 
	for i, xy in pairs(light) do
			gfx.setColor( 255, 255, 255, 235 )
gfx.draw(plight, xy[1], xy[2], 0, 1, 1,plight:getWidth()/2, plight:getHeight()/2)
	love.graphics.setColor(255, 0, 0, 255) 
	       love.graphics.circle("fill", xy[1], xy[2], 5, 32)
	love.graphics.circle("fill", player.x+10, player.y, 5, 32)
	love.graphics.setColor(255, 255, 255, 235) 
   end
end
plight is image with alpha.

Re: "Questions that don't deserve their own thread" thread

Posted: Mon Aug 18, 2014 10:24 pm
by slime
The stencil buffer only cares about the geometry of what you draw, normally (drawing an image will draw a rectangle with the image's texture on it) - and the stencil test is binary: things will either pass or fail the test.

Re: "Questions that don't deserve their own thread" thread

Posted: Tue Aug 19, 2014 1:25 pm
by IceQB
I have othert question, why do all tiles change color at the same time(not only this in radius and point)?

Code: Select all



l = {}
l.vis = 255
l.radius = 5
l.point = l.point


function getDistance(x1,y1, x2,y2)
	local distx = x1 - x2
	local disty = y1 - y2
	local squared = (distx * distx) + (disty * disty)
	return math.sqrt(squared)
end

function shadow_update(dt)

	local mouse = love.mouse
	local mx,my = mouse.getPosition()

for y = 1, #map do
		local xy = map[y]
	for x = 1, #xy do
	local number = xy[x]

			 l.point = getDistance((x-1)*tileW, (y-1)*tileH, mx, my)
if l.point > l.radius then
l.vis = 255 - l.point
end
					if l.vis > 255 then l.vis = 255 elseif l.vis < 0 then l.vis = 0 end

	end
	end
	end

function map_draw()

for y = 1, #map do
		local xy = map[y]
	for x = 1, #xy do
	local number = xy[x]
		if number ~= 1  then
		gfx.setColor( l.vis, l.vis, l.vis, 255 )
	  love.graphics.draw(tileset, Quads[number], (x-1)*tileW, (y-1)*tileH)

		end
	end
end
end
Where did i do mistake?

I dont know how must look loop for this. I found codes like this:

Code: Select all

for i,v in ipairs( map ) do
	end
--or--
for i,v in ipairs(self.objects) do
end
But i cant transform this for my code.