Tokio

[HELP] How to fix the fps drop?

Recommended Posts

   if getElementData(getLocalPlayer(),"kukaseh") then
  for k, v in ipairs ( getElementsByType( 'object' )) do
  	if getElementData( v, 'munkakuka' ) then
		local bx, by, bZ = getElementPosition(v)
		local actualDist = getDistanceBetweenPoints2D(playerX, playerY, bx, by)
		local dist = actualDist/(worldMaxSize/((worldWidth+worldHeight)/2))

				local rot = findRotation(bx, by, playerX, playerY)-camZ
				
				local blipX, blipY = 
				getPointFromDistanceRotation(
					(MiniMap_x+MiniMap["width"]+MiniMap_x)/2, 
					(MiniMap_y+MiniMap_y+MiniMap["height"])/2, 
					math.min(dist, math.sqrt((MiniMap_y+MiniMap_y+MiniMap["height"])/2-MiniMap_y^2 + MiniMap_x+MiniMap["width"]-(MiniMap_x+MiniMap["width"]+MiniMap_x)/2^2)),
					rot
				)
				
				local blipX = math.max(MiniMap_x, math.min(MiniMap_x+MiniMap["width"], blipX))
				local blipY = math.max(MiniMap_y, math.min(MiniMap_y+MiniMap["height"], blipY))
												if dist <= 120 then

						dxDrawImage(blipX - blipSize/2, blipY - blipSize/2, blipSize, blipSize, "blips/1125.png",0,0,0,tocolor(255,255,255,255))

				end
		end
    end
    end	

when this true, and the dxDrawImage show, the FPS decrease from 100 to 50.. how to fix this?

Share this post


Link to post

Too many objects?

Optimizations you can do:

 

Limit the amount of objects and faster looping

for k, v in ipairs ( getElementsByType( 'object' )) do

local objects = getElementsByType( 'object', root, true ) -- only streamed in objects!

for k=1, #objects do -- A `for loop` is faster
	local v = objects[k]

https://wiki.multitheftauto.com/wiki/GetElementsByType

syntax: (client)

getElementsByType ( string theType, [ element startat=getRootElement(), bool streamedIn=false ] ) 

 

 

 

Texture ftw! (argb texture)

-- on top of your script!
local objectBlipTexture = dxCreateTexture( "blips/1125.png") 

----------------------------------------------------------------

-- now draw!
dxDrawImage(blipX - blipSize/2, blipY - blipSize/2, blipSize, blipSize, objectBlipTexture, 0, 0, 0, tocolor(255,255,255,255))

 

 

Screenshot_27.png

This is a texture speed test on wiki. You are currently rendering from a path. Which is according to this test ~6,75x slower than just a pre created texture (argb).

https://wiki.multitheftauto.com/wiki/DxCreateTexture

 

Share this post


Link to post

When you create trashcan, insert the object element to an table.

And loop that table.

local trashcans = {}

function createTashcan(x,y,z)
	local object = createObject(trashcanObjectID, x,y,z)
  	trashcans[object] = true;
end

for object in pairs(trashcans) do
	-- same code
end

 

 

Hungarian:

Ha létrehozol egy kukát, akkor add hozzá a táblához ahonnan vissza tudod kérni, mert te jelenleg minden egyes lerakott objectet felsorolsz minden másodpercben ezért laggoltat.

Viszont ha a saját tábládból sorolod csak, akkor ott nincs tele felesleges objectekkel, csak ami kell.

Share this post


Link to post
1 minute ago, Patrick2562 said:

When you create trashcan, insert the object element to an table.

And loop that table.


local trashcans = {}

function createTashcan(x,y,z)
	local object = createObject(trashcanObjectID, x,y,z)
  	trashcans[object] = true;
end

for object in pairs(trashcans) do
	-- same code
end

 

 

Hungarian:

Ha létrehozol egy kukát, akkor add hozzá a táblához ahonnan vissza tudod kérni, mert te jelenleg minden egyes lerakott objectet felsorolsz minden másodpercben ezért laggoltat.

Viszont ha a saját tábládból sorolod csak, akkor ott nincs tele felesleges objectekkel, csak ami kell.

Looping through an object structure instead of an array structure is slower, even though you do not have to recreate the table.

-- Object structure
{
	[value1] = true,
	[value2] = true
}


-- Array structure
{
	[1] = value1,
  	[2] = value2
}
-- Same as: {value1, value2}

 

  • Thanks 1

Share this post


Link to post
2 minutes ago, IIYAMA said:

Looping through an object structure instead of an array structure is slower, even though you do not have to recreate the table.


-- Object structure
{
	[value1] = true,
	[value2] = true
}


-- Array structure
{
	[1] = value1,
  	[2] = value2
}
-- Same as: {value1, value2}

 

I did not know that. Thanks the info.

 

So that is faster?

local trashcans = {}

function createTashcan(x,y,z)
	local object = createObject(trashcanObjectID, x,y,z)
  	table.insert(trashcans, object)
end

for _, object in ipairs(trashcans) do
	-- same code
end

 

Share this post


Link to post
9 minutes ago, IIYAMA said:

Too many objects?

Optimizations you can do:

 

Limit the amount of objects and faster looping

for k, v in ipairs ( getElementsByType( 'object' )) do


local objects = getElementsByType( 'object', root, true ) -- only streamed in objects!

for k=1, #objects do -- A `for loop` is faster
	local v = objects[k]

https://wiki.multitheftauto.com/wiki/GetElementsByType

syntax: (client)


getElementsByType ( string theType, [ element startat=getRootElement(), bool streamedIn=false ] ) 

 

 

 

Texture ftw! (argb texture)


-- on top of your script!
local objectBlipTexture = dxCreateTexture( "blips/1125.png") 

----------------------------------------------------------------

-- now draw!
dxDrawImage(blipX - blipSize/2, blipY - blipSize/2, blipSize, blipSize, objectBlipTexture, 0, 0, 0, tocolor(255,255,255,255))

 

 

Screenshot_27.png

This is a texture speed test on wiki. You are currently rendering from a path. Which is according to this test ~6,75x slower than just a pre created texture (argb).

https://wiki.multitheftauto.com/wiki/DxCreateTexture

 

i tried this, but show only 2 blip

Share this post


Link to post
1 minute ago, Nerve said:

i tried this, but show only 2 blip

Because its shows only streamed objects. What near to you.

 

Hungarian:

Azért mert csak annyit változtatott rajta, hogy a betöltött objecteket sorolja.

Szóval ahol megnyitod a térképet és ott a közeledben lévőek.

  • Thanks 1

Share this post


Link to post

If streamed in objects aren't a solution, then fixing the problem by the source might be a solution.

 

 

 

 

Preparing:

-- instead of setElementData

local munkakuka = createElement("munkakuka")
setElementParent(munkakuka, object)

https://wiki.multitheftauto.com/wiki/CreateElement

 

  1. Creates the element munkakuka
  2. Sets the munkakuka element as child of the object.

 

Using a map file instead of a script? (also possible)

Spoiler

<object model="" posX="" posY="" posZ="" rotX="" rotY="" rotZ="" interior="" dimension="" scale="" collisions="" alpha="" frozen=""> 
	<munkakuka><munkakuka/>
</object>

 

 

 

Looping:

local munkakuka = getElementsByType( 'munkakuka')

for k=1, #munkakuka do
	local v = getElementParent(munkakuka[k])

 

  1. It gets all custom elements `munkakuka`.
  2. Get the parent of it. (which is the object)

 

This should reduce the amount of loops of the code. You can also set the object as child of the munkakuka element + it can make the code faster if you limit the note scope. (requires to change the code a little bit)

 

Edited by IIYAMA

Share this post


Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Recently Browsing   0 members

    No registered users viewing this page.