Cyber14

[QUESTION] How to reduce the decrease of performence when having a lot of created objects?

Recommended Posts

Hi. I have a lot of objects on my server, all of them are created by server-side createObject() function on resource start but there is one problem with that. When someone connects to my server and the resource is started, the player have to wait a lot for objects loading. (It takes about 1 minute) So in order to reduce this time I moved some objects to other dimensions but It didnt give an effect.

Now I have a question. Im going to change the way of creating objects. Im thinking about creating objects client-side and creating only this objects which actually are in the same dimension as the player is. When the player changes dimension, objects in previous dimension will be deleted and new objects from proper dimension will be created. Is that the good idea or there is any better solution?

Share this post


Link to post
1 hour ago, Saml1er said:

Are those custom objects?

I have the same problem with custom objects too

Edited by iDannz

Share this post


Link to post
15 hours ago, iDannz said:

I have the same problem with custom objects too

createObject function executes pretty quickly. I think you're talking about engine functions, like engineLoadDFF, *TXD, and *COL.

Share this post


Link to post

Use "onClientRender" to disperse the pressure

Share this post


Link to post
17 minutes ago, thisdp said:

Use "onClientRender" to disperse the pressure

What exactly do you mean? 

Share this post


Link to post
Just now, Cyber14 said:

What exactly do you mean? 

Create a queue, and deal with it inside "onClientRender". For example, 200 objects will be created in 1 frame.

Share this post


Link to post
On 08/01/2019 at 05:50, iDannz said:

I have the same problem with custom objects too

 

20 hours ago, Saml1er said:

createObject function executes pretty quickly. I think you're talking about engine functions, like engineLoadDFF, *TXD, and *COL.

I have no any problems with custom objects. I know It can be weird but I tested how long it takes to load objects with and without replacing models and it turned out that objects without replacing loaded faster.. Even when I create objects with no custom objects and then I run resource which replaces models it doesn't take more than 1-2 seconds to replace all models. I would like to add that I have about 3.000 objects to create on my server.

In that case I will check solution with onClientRender event.

Share this post


Link to post
4 hours ago, Cyber14 said:

I have no any problems with custom objects. I know It can be weird but I tested how long it takes to load objects with and without replacing models and it turned out that objects without replacing loaded faster

Can you post the script where you create the objects? I'd like to test it.

Edited by Saml1er
  • Thanks 1

Share this post


Link to post
13 minutes ago, Saml1er said:

Can you post the script where you create the objects? I'd like to test it.

Ok you were right. I analyzed the code and createObject() function works really quickly. My problem was connected with adding textures to all of this models on client-side (im using "UV scripted" resource from this site https://wiki.multitheftauto.com/wiki/Shader_examples) Maybe now  @thisdp 's solution will have sense for loading shaders a bit slower?

Share this post


Link to post
Quote

My problem was connected with adding textures to all of this models

You can also use the onClientRender event to load the textures one by one. To keep up the frame- rate, you can use getTickCount() function to delay the process even further.

https://wiki.multitheftauto.com/wiki/OnClientRender

https://wiki.multitheftauto.com/wiki/GetTickCount

 

 

24 minutes ago, Cyber14 said:

Ok you were right. I analyzed the code and createObject() function works really quickly.

Have you ever considered using a map file? Loading map files is damn xxxxxxx fast in compare to create every single element with createObject.
Take it or leave it. (of course this means that you will lose the ability to send specific maps to each client)

 

local file = xmlCreateFile("saved.map", "map")
if file then

	local mapRoot = createElement("map")
	setElementParent(createObject([[...]]), mapRoot) -- all your objects

	saveMapData ( file, mapRoot)
	xmlSaveFile ( file )
	xmlUnloadFile ( file )
end

https://wiki.multitheftauto.com/wiki/SaveMapData

 

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.