LUADOC - Farming Simulator 19

I3DManager

Description
This class provides tools for loading shared i3d files. Access using g_i3DManager
Parent
AbstractManager
Functions

deleteSharedI3DFiles

Description
Clears i3d cache
Definition
deleteSharedI3DFiles()
Code
158function I3DManager:deleteSharedI3DFiles()
159 for _, sharedI3D in pairs(self.sharedI3DFiles) do
160 if sharedI3D.nodeId ~= 0 then
161 delete(sharedI3D.nodeId)
162 end
163 end
164 self.sharedI3DFiles = {}
165end

fillSharedI3DFileCache

Description
Adds an i3d file to cache
Definition
fillSharedI3DFileCache(string filename, string baseDir)
Arguments
stringfilenamefilename
stringbaseDirbaseDir
Code
125function I3DManager:fillSharedI3DFileCache(filename, baseDir)
126 local filename = Utils.getFilename(filename, baseDir)
127 local sharedI3D = self.sharedI3DFiles[filename]
128
129 if sharedI3D == nil then
130 local nodeId = loadI3DFile(filename, false, false)
131 local sharedI3D = {nodeId=nodeId, refCount=0}
132 self.sharedI3DFiles[filename] = sharedI3D
133 end
134end

initDataStructures

Description
Initialize data structures
Definition
initDataStructures()
Code
24function I3DManager:initDataStructures()
25 self.sharedI3DFiles = {}
26 self.sharedI3DFilesPendingCallbacks = {}
27end

loadSharedI3DFile

Description
Loads an i3D file. A cache system is used for faster loading
Definition
loadSharedI3DFile(string filename, string baseDir, boolean callOnCreate, boolean addToPhysics, boolean verbose, function asyncCallbackFunction, table asyncCallbackObject, table asyncCallbackArguments)
Arguments
stringfilenamefilename
stringbaseDirbaseDir
booleancallOnCreatetrue if onCreate i3d callbacks should be called
booleanaddToPhysicstrue if collisions should be added to physics
booleanverboseverbose
functionasyncCallbackFunctiona callback function
tableasyncCallbackObjectcallback function target object
tableasyncCallbackArgumentsa list of arguments
Return Values
integeridi3d rootnode
Code
40function I3DManager:loadSharedI3DFile(filename, baseDir, callOnCreate, addToPhysics, verbose, asyncCallbackFunction, asyncCallbackObject, asyncCallbackArguments)
41 callOnCreate = Utils.getNoNil(callOnCreate, false)
42 addToPhysics = Utils.getNoNil(addToPhysics, false)
43 local filename = Utils.getFilename(filename, baseDir)
44 local sharedI3D = self.sharedI3DFiles[filename]
45
46 -- always print all loading texts
47 verbose = true
48
49 if asyncCallbackFunction ~= nil then
50 if sharedI3D == nil then
51
52 local callbacks = self.sharedI3DFilesPendingCallbacks[filename]
53 if callbacks == nil then
54 self.sharedI3DFilesPendingCallbacks[filename] = {}
55 table.insert(self.sharedI3DFilesPendingCallbacks[filename], {callOnCreate, addToPhysics, asyncCallbackFunction, asyncCallbackObject, asyncCallbackArguments})
56 streamI3DFile(filename, "loadSharedI3DFileFinished", self, {filename}, false, false, verbose)
57 else
58 table.insert(callbacks, {callOnCreate, addToPhysics, asyncCallbackFunction, asyncCallbackObject, asyncCallbackArguments})
59 end
60 else
61 local id = 0
62
63 if sharedI3D.nodeId == 0 then
64 print("Error: failed to load i3d file '"..filename.."'")
65 else
66 id = clone(sharedI3D.nodeId, false, callOnCreate, addToPhysics)
67 end
68
69 sharedI3D.refCount = sharedI3D.refCount+1
70 asyncCallbackFunction(asyncCallbackObject, id, asyncCallbackArguments)
71 end
72 else
73 if sharedI3D == nil then
74 local nodeId = loadI3DFile(filename, false, false, verbose)
75 sharedI3D = {nodeId=nodeId, refCount=0}
76 self.sharedI3DFiles[filename] = sharedI3D
77 end
78
79 local id = 0
80 if sharedI3D.nodeId == 0 then
81 print("Error: failed to load i3d file '"..filename.."'")
82 else
83 id = clone(sharedI3D.nodeId, false, callOnCreate, addToPhysics)
84 end
85
86 sharedI3D.refCount = sharedI3D.refCount + 1
87
88 return id
89 end
90end

loadSharedI3DFileFinished

Description
Called once i3d loading is finished
Definition
loadSharedI3DFileFinished(integer nodeId, table arguments)
Arguments
integernodeIdi3d node id
tableargumentsa list of arguments
Code
96function I3DManager:loadSharedI3DFileFinished(nodeId, arguments)
97 local filename = arguments[1]
98 local callbacks = self.sharedI3DFilesPendingCallbacks[filename]
99 local sharedI3D = {nodeId=nodeId, refCount=0}
100
101 self.sharedI3DFilesPendingCallbacks[filename] = nil
102 self.sharedI3DFiles[filename] = sharedI3D
103
104 if nodeId == 0 then
105 print("Error: failed to load i3d file '"..filename.."'")
106 end
107
108 for _,callback in pairs(callbacks) do
109 local callOnCreate, addToPhysics, asyncCallbackFunction, asyncCallbackObject, asyncCallbackArguments = unpack(callback)
110 local id = 0
111
112 if sharedI3D.nodeId ~= 0 then
113 id = clone(sharedI3D.nodeId, false, callOnCreate, addToPhysics)
114 end
115
116 sharedI3D.refCount = sharedI3D.refCount+1
117 asyncCallbackFunction(asyncCallbackObject, id, asyncCallbackArguments)
118 end
119end

new

Description
Creating manager
Definition
new()
Return Values
tableinstanceinstance of object
Code
16function I3DManager:new(customMt)
17 local self = AbstractManager:new(customMt or I3DManager_mt)
18
19 return self
20end

releaseSharedI3DFile

Description
Releases one instance. If autoDelete is true and instance count <= 0. I3d will be removed from cache
Definition
releaseSharedI3DFile(string filename, string baseDir, boolean autoDelete)
Arguments
stringfilenamefilename
stringbaseDirbaseDir
booleanautoDeletetrue if file should be removed from cache if instance count is <= 0
Code
141function I3DManager:releaseSharedI3DFile(filename, baseDir, autoDelete)
142 local filename = Utils.getFilename(filename, baseDir)
143 local sharedI3D = self.sharedI3DFiles[filename]
144
145 if sharedI3D ~= nil then
146 sharedI3D.refCount = sharedI3D.refCount-1
147 if autoDelete and sharedI3D.refCount <= 0 then
148 if sharedI3D.nodeId ~= 0 then
149 delete(sharedI3D.nodeId)
150 end
151 self.sharedI3DFiles[filename] = nil
152 end
153 end
154end