Jump to content

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


Cyber14

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?

Link to comment
  • Scripting Moderators
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.

Link to comment
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.

Link to comment
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
Link to comment
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?

Link to comment
  • Moderators
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
Link to comment

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.
×
×
  • Create New...