Jump to content

Mods Loading


RekZ

Recommended Posts

 

I have been looking for ways to lower the impact that mod loading has on the client, would it be a good idea to separate the mods by tables and load the mods every 5 seconds ?

local WeaponsModels = {
	["AK"] = {
          {FILE="AK/Weapon1"			, ID=00000},
          {FILE="AK/Weapon2"			, ID=00000},
          {FILE="AK/Weapon3"			, ID=00000},
          {FILE="AK/Weapon4"			, ID=00000},
          {FILE="AK/Weapon5"			, ID=00000},
          {FILE="AK/Weapon6"			, ID=00000},
	},
	["CPL"] = {
          {FILE="CPL/Weapon1"			, ID=00000},
          {FILE="CPL/Weapon2"			, ID=00000},
          {FILE="CPL/Weapon3"			, ID=00000},
          {FILE="CPL/Weapon4"			, ID=00000},
          {FILE="CPL/Weapon5"			, ID=00000},
          {FILE="CPL/Weapon6"			, ID=00000},
	},
}

function load()

	if not getElementData(localPlayer,"login") then
		setTimer(load,10000,1)
		outputChatBox ( "Reload" )
		return
	end
	
	setTimer(function()
		for index, weapon in pairs(WeaponsModels["AK"]) do
			engineImportTXD ( engineLoadTXD ( "models/"..weapon.FILE.. ".txd", weapon.ID ), weapon.ID )
			engineReplaceModel ( engineLoadDFF ( "models/"..weapon.FILE.. ".dff", weapon.ID ), weapon.ID, true )
			engineSetModelLODDistance( weapon.ID , 100 ) 
		end
		outputChatBox ( "Mods AK" )
	end, 1000, 1 )
	
	setTimer(function()
		for index, weapon in pairs(WeaponsModels["CPL"]) do
			engineImportTXD ( engineLoadTXD ( "models/"..weapon.FILE.. ".txd", weapon.ID ), weapon.ID )
			engineReplaceModel ( engineLoadDFF ( "models/"..weapon.FILE.. ".dff", weapon.ID ), weapon.ID, true )
			engineSetModelLODDistance( weapon.ID , 100 ) 
		end
		outputChatBox ( "Mods CPL" )
	end, 5000, 1 )
 end
addEventHandler ( "onClientResourceStart", getResourceRootElement(), load ) 

 

Link to comment
  • Moderators
13 hours ago, RekZ said:

would it be a good idea to separate the mods by tables and load the mods every 5 seconds

I have no idea if engineSetAsynchronousLoading works as Addlibs replied. << I truly hope this solves your issue to be honest

But the loading process of that function probably doesn't include the reading of the mod files.

 

In case of loading things in general, I recommend to align the process operation with the user his FPS. Because when you are loading a mod, you are blocking everything, so you can't go to the next frame until it is finished.
> That is why loading 2 or more mods on a single frame can cause frame drops.
> Large mods will cause frame drops, that is inevitable.

If you load a mod every 1, 2 or 3 frames, you will balance performance with processing speed.

 

This example is for loading a mod every frame. Speedy , but with performance impact. So more frames between each execution is better for performance.

local table = {{}, {}, {}}
function test ()
	local item = table[1]
	if item then
		table.remove(table, 1)
 	else
		removeEventHandler("onClientRender", root, test)
	end
end
addEventHandler("onClientRender", root, test)

 

 

 

 

Edited by IIYAMA
  • Thanks 1
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...