Skip to content

Lua polyobjects

Monster Iestyn requested to merge lua-polyobjects into next

Lua now has access to polyobj_t in this branch:

polyobj_t struct:

  • .valid (boolean): checks validity
  • .id (int32): the ID used to reference the PolyObject in the map
  • .parent (int32): the ID of the parent PolyObject, or -1 if it doesn't have one
  • .vertices (vertex_t array): an array containing all the PolyObject's vertices. Use #polyobj.vertices to get the number of vertices it has.
  • .lines (line_t array): an array containing all the PolyObject's linedefs. Use #polyobj.lines to get the number of lines it has.
  • .sector (sector_t): the PolyObject's control sector. (The game uses polyobj.lines[0].backsector internally, but I figured it'd be much more convenient to have a variable to grab it directly for Lua at least)
  • .angle (angle_t): the PolyObject's angle
  • .damage (int32): not entirely sure how this works exactly, but if it's non-zero then the PolyObject can crush players
  • .thrust (fixed_t): amount of thrust applied to objects that block the PolyObject's movement. By default this is set to FRACUNIT, but it may be modified by some of the linedef executor actions for PolyObjects
  • .flags (int32): the PolyObject's flags (see POF_ list below)
  • .translucency (int32): the PolyObject's translucency level, as a number from 0-9
  • .triggertag (int32): Tag of linedef executor to trigger on touch
  • :pointInside(x, y): special function to check if a XY position is inside the bounds of the PolyObject
  • :mobjTouching(mobj): special function to check if a mobj's XY position intersects with the lines of the PolyObject
  • :mobjInside(mobj): special function to check if a mobj's XY position is inside the bounds of the PolyObject
  • :moveXY(x, y [, checkmobjs]): special function that moves a PolyObject horizontally. x is the X distance to move, y is the Y distance to move, checkmobjs is a boolean to enable/disable physics with mobjs (enabled by default)
  • :rotate(delta [, turnthings [, checkmobjs]]): special function that rotates a PolyObject. delta is the angle to rotate, turnthings is an int32 to determine if and which mobjs should be rotated with it (0 = nothing, 1 = turn only non-players, 2 = turn everything), checkmobjs is a boolean to enable/disable physics with mobjs (enabled by default)

The last five can also be written longhand, e.g. polyobj.pointInside(polyobj, x, y), but obviously it's much simpler to omit the first arg, hence why I've given them with : as in polyobj.pointInside(x, y).

Of the others, only .parent, .flags, .translucency can be modified currently.

POF_ flags descriptions (from source code):

	POF_CLIPLINES         = 0x1,       ///< Test against lines for collision
	POF_CLIPPLANES        = 0x2,       ///< Test against tops and bottoms for collision
	POF_SOLID             = 0x3,       ///< Clips things.
	POF_TESTHEIGHT        = 0x4,       ///< Test line collision with heights
	POF_RENDERSIDES       = 0x8,       ///< Renders the sides.
	POF_RENDERTOP         = 0x10,      ///< Renders the top.
	POF_RENDERBOTTOM      = 0x20,      ///< Renders the bottom.
	POF_RENDERPLANES      = 0x30,      ///< Renders top and bottom.
	POF_RENDERALL         = 0x38,      ///< Renders everything.
	POF_INVERT            = 0x40,      ///< Inverts collision (like a cage).
	POF_INVERTPLANES      = 0x80,      ///< Render inside planes.
	POF_INVERTPLANESONLY  = 0x100,     ///< Only render inside planes.
	POF_PUSHABLESTOP      = 0x200,     ///< Pushables will stop movement.
	POF_LDEXEC            = 0x400,     ///< This PO triggers a linedef executor.
	POF_ONESIDE           = 0x800,     ///< Only use the first side of the linedef.
	POF_NOSPECIALS        = 0x1000,    ///< Don't apply sector specials.
	POF_SPLAT             = 0x2000,    ///< Use splat flat renderer (treat cyan pixels as invisible).

Other features:

  • PolyObjects[] is now accessible to Lua. This is an array storing all the PolyObjects in the map. #PolyObjects gives the total number of them.
  • PolyObjects.iterate iterates through all PolyObjects in the map. This functions like most of our other .iterate functions already in SRB2.
  • PolyObjects.GetForNum(id) converts a PolyObject ID (the one used in the map) to the actual polyobj_t it is associated with
  • line.polyobj if a line_t belongs to a PolyObject, this will give the polyobj_t of it
  • searchBlockmap has a new "polyobjs" search option! This functions like the "objects" and "lines" options, except this deals with polyobj_t instead obviously.
  • subsector.polyList() is a special function for iterating through all PolyObjects in the subsector. This functions much like sector.thinglist or sector.ffloors which already exist

(did I forget anything above? literally have to be off now as I'm writing this)

(sphere edit: closes #19 (closed))

Edited by sphere

Merge request reports