1
1
-- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ --
2
- -- clipDistanceControl
2
+ -- clipDistanceControl v1.1.0.0
3
3
--
4
4
-- Purpose: The purpose of this script is to control the 'clip distance' (also known as view distance)
5
- -- of an object that is inside the associated trigger. With how the GIANTS engine currently handles
6
- -- rendering objects, it also renders them if they are not visible to the player (e.g. blocked by a
7
- -- vehicle shed). Reducing the clip distance on them when they are in this shed can greatly increase
8
- -- the performance of the game.
5
+ -- of an object that is inside the associated trigger. With how the GIANTS engine currently handles
6
+ -- rendering objects, it also renders them if they are not visible to the player (e.g. blocked by a
7
+ -- vehicle shed). Reducing the clip distance on them when they are in this shed can greatly increase
8
+ -- the performance of the game.
9
9
--
10
10
-- How to use:
11
11
-- - Add the trigger shape
33
33
--
34
34
-- Authors: Timmiej93
35
35
-- Based on the FS15 script 'clipDistanceControl', of which I have been unable to find the author.
36
+ -- If you know or are the original author, please let me know, so I can properly credit them.
37
+ --
38
+ -- Changelog
39
+ -- For the changelog, please visit GitHub. This always has the most up to date and most complete
40
+ -- changelog available. GitHub information is at the bottom of this comment block.
41
+ --
36
42
--
37
43
-- Copyright (c) Timmiej93, 2018
38
44
-- This file can be used in any map without specific permission. It can however not be claimed to be
39
- -- your own work. Crediting me is not required, but it would be nice.
40
- -- For more information on copyright for this mod, please check the readme file on GitHub:
41
- -- GitHub > Timmiej93 > clipDistanceControl
42
- -- https://github.com/Timmiej93/clipDistanceControl
45
+ -- your own work. Crediting me is not required, but it would be nice. This comment block (line 1
46
+ -- through 56) can NOT be removed (there is also no reason to remove it), to ensure that anyone
47
+ -- with questions can find the original author, and can complain to me, instead of you, the map
48
+ -- maker.
49
+ -- For more information or questions on copyright for this mod, please check the readme file on
50
+ -- GitHub. GitHub information is at the bottom of this comment block.
51
+ --
52
+ -- GitHub information
53
+ -- GitHub > Timmiej93 > clipDistanceControl
54
+ -- https://github.com/Timmiej93/clipDistanceControl
43
55
--
44
56
-- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ --
45
57
@@ -52,47 +64,80 @@ function clipDistanceControl.onCreate(id)
52
64
end
53
65
54
66
function clipDistanceControl :new (id , customMt )
67
+
68
+ if (g_currentMission .CDC_savedDistances == nil ) then
69
+ g_currentMission .CDC_savedDistances = {}
70
+ end
71
+
55
72
local self = {}
56
73
if (customMt ~= nil ) then
57
74
setmetatable (self , customMt )
58
75
else
59
76
setmetatable (self , clipDistanceControl_mt )
60
77
end
61
-
78
+
62
79
self .triggerId = id
63
80
addTrigger (id , " clipDistanceControlCallback" , self )
64
81
65
- self .innerClipDistance = Utils .getNoNil (getUserAttribute (id , " innerClipDistance" ), 300 )
66
82
self .savedCD = {}
83
+ self .innerClipDistance = Utils .getNoNil (getUserAttribute (id , " innerClipDistance" ), 100 )
67
84
68
85
return self
69
86
end
70
87
71
- function clipDistanceControl :delete ()
88
+ function clipDistanceControl :deleteMap ()
72
89
removeTrigger (self .triggerId )
73
90
end
74
91
92
+ function clipDistanceControl :keyEvent (unicode , sym , modifier , isDown ) end
93
+ function clipDistanceControl :mouseEvent (posX , posY , isDown , isUp , button ) end
94
+ function clipDistanceControl :draw () end
95
+ function clipDistanceControl :update (dt ) end
96
+
75
97
function clipDistanceControl :clipDistanceControlCallback (triggerId , otherId , onEnter , onLeave , onStay , otherShapeId )
98
+
99
+ -- Use the otherId to check if it's a vehicle or an object.
76
100
local vehicle = g_currentMission .nodeToVehicle [otherId ]
77
101
local object = g_currentMission .nodeObjects [otherId ]
78
102
103
+ -- Grab a local copy of the table, to prevent humongeous lines.
104
+ local gcmData = g_currentMission .CDC_savedDistances
105
+
79
106
if (vehicle ~= nil or object ~= nil ) then
107
+ -- If the ID is indeed a vehicle or an ojbect...
80
108
81
109
if (onEnter ) then
110
+ -- Get the vehicle's clip distance.
82
111
local cd = getClipDistance (otherId )
112
+
83
113
if (cd ~= nil and self .savedCD [otherId ] == nil ) then
114
+ -- If the found clipdistance isn't nil, and this vehicle/object isn't in this trigger's database yet...
115
+ if (gcmData [otherId ] == nil ) then
116
+ -- If this vehicle/object isn't in the global database yet, store it there.
117
+ gcmData [otherId ] = cd
118
+ end
119
+ -- Store the clip distance in this trigger's database.
84
120
self .savedCD [otherId ] = cd
121
+ -- Set the vehicle's/object's clip distance to the trigger's distance.
85
122
setClipDistance (otherId , self .innerClipDistance )
123
+
86
124
end
87
125
end
126
+
88
127
if (onLeave ) then
89
- local cd = self .savedCD [otherId ]
128
+ -- Get the stored (original) clip distance from the global database
129
+ local cd = gcmData [otherId ]
130
+
90
131
if (cd ~= nil ) then
132
+ -- If the stored clip distance isn't nil, clear the stored data in this trigger's database and the global
133
+ -- database, and then set the clipdistance back to the original clip distance of the vehicle / object.
91
134
self .savedCD [otherId ] = nil
135
+ gcmData [otherId ] = nil
92
136
setClipDistance (otherId , cd )
93
137
end
94
138
end
95
139
end
96
140
end
97
141
98
- g_onCreateUtil .addOnCreateFunction (" clipDistanceControl" , clipDistanceControl .onCreate )
142
+ g_onCreateUtil .addOnCreateFunction (" clipDistanceControl" , clipDistanceControl .onCreate )
143
+ addModEventListener (clipDistanceControl )
0 commit comments