gameplay_race_segment¶
File: lua/ge/extensions/gameplay/race/segment.lua · VM: Game Engine (GE) · 250 lines · BeamNG.drive 0.40.5 (buildbot 302427 on GitLab)
Access: require("extensions/gameplay/race/segment") (file under extensions/ but not a regular extension)
Class of a race path segment: stretch between two pathnodes (from and to). Three representations are planned: "waypoint" (straight line between the two nodes), a navgraph path automatically filled with capsules, or manual capsules (points with radius). The segment tells whether a vehicle is inside it (contains) and whether it reached the end node (finished). The module returns a factory: require('/lua/ge/extensions/gameplay/race/segment')(path, name, forceId).
Notes¶
- Inconsistent mode names: the local modes list is {'waypoint', 'navgraphCapsule', 'manualCapsules'}, but the code tests 'waypoint', 'navpath' and 'capsules'. The values 'navgraphCapsule' and 'manualCapsules' are handled nowhere: contains then returns false.
- A capsule is a point {pos, radius, name}; a segment's capsules link from, the capsulePoints, then to. The radius is linearly interpolated along each stretch.
- The capsules generated by fillNavpath carry _generated = true and are recomputed on each call of fillNavpath.
- isValid reads .missing on the from and to pathnodes: Lua error if either id does not exist in path.pathnodes.objects.
- contains in waypoint mode requires state.currentSegments, state.previousCorners and state.currentCorners.
Class C¶
Race segment. Fields: path, id, name ("Segment
The module returns a constructor: local obj = require("gameplay_race_segment")(options).
| Method | Description | Line |
|---|---|---|
C:addCapsule(pos, radius, name, index) |
Inserts a capsule at the given index (at the end by default). | 78 |
C:capsuleContains(point, id) |
Indicates whether a point is inside the capsule stretch between points id and id+1 (distance to the segment less than the interpolated radius). | 96 |
C:checkMode() |
Revalidates the mode after an end change: in 'navpath' mode, recomputes the path if possible, otherwise returns to 'waypoint'. | 43 |
C:contains(point, state) |
Indicates whether the vehicle is inside the segment. In waypoint mode: true if it is already in this segment (state.currentSegments) or has just crossed the start pathnode. In 'capsules' or 'navpath' mode: true if it is inside one of the capsules. | 107 |
C:drawDebug(drawMode) |
Draws the segment (prism between the two nodes in waypoint mode, capsules and edges otherwise) and its name. Draws nothing if the segment is invalid. | 176 |
C:fillNavpath() |
Fills the capsules with the intermediate nodes of the shortest path map.getPath between the navgraph nodes from and to (ends excluded). | 67 |
C:finished(point, state) |
Indicates whether the vehicle has just crossed the end pathnode (intersectCorners). | 139 |
C:getBeNavpath() |
Indicates whether both end pathnodes are in navgraph mode (hence whether a navgraph path is possible). | 23 |
C:getCapsuleCount() |
Number of capsule points, ends included (#capsulePoints + 2). | 86 |
C:getCapsuleNode(i) |
Point i of the capsule chain: 1 = pathnode from, last = pathnode to, otherwise a capsulePoint. | 87 |
C:getFrom() |
Start pathnode. | 32 |
C:getTo() |
End pathnode. | 33 |
C:init(path, name, forceId) |
Constructor: id, name, mode 'waypoint', from/to at -1, empty capsule list. | 11 |
C:isValid() |
Indicates whether the from and to pathnodes exist, are not marked missing and are different. | 240 |
C:onDeserialized(data, oldIdMap) |
Restores the segment; converts from/to with oldIdMap, applies the mode then adds the saved capsules. | 160 |
C:onSerialize() |
Serializes the segment (name, mode, from, to, oldId, capsules). | 144 |
C:removeCapsule(index) |
Removes the capsule at the given index. | 82 |
C:setFrom(from) |
Sets the start pathnode (by id) and revalidates the mode. | 34 |
C:setMode(mode) |
Changes the mode: 'waypoint' clears the capsules; 'navpath' fills them from the navgraph. | 55 |
C:setTo(to) |
Sets the end pathnode (by id) and revalidates the mode. | 38 |
Calls into the engine (C++)¶
debugDrawer:drawSphere,drawSquarePrism,drawTextAdvanced
tim19Atlas (Tim0219800) — derived from BeamNG GmbH Lua code (bCDDL 1.1, see LICENSE). Source: lua/ge/extensions/gameplay/race/segment.lua.