35 Commits
Author SHA1 Message Date
Goober5000andClaude Fable 5.1 37b0b6ea82 Standardize isValid across the Lua API by making the types auto-generate it (#7761)
* Automatically generate the isValid() Lua API function for handle types

If an ADE object's stored type has an isValid() member, ade_obj now registers an isValid function for it automatically.  An explicit ADE_FUNC(isValid, ...) declared after the ADE_OBJ replaces the generated one, so types with special semantics (e.g. sound) keep their own.  The 67 hand-written functions that merely delegated to the member are removed, and 26 types that previously exposed no isValid() gain one.

Co-Authored-By: Claude Fable 5.1 <[email protected]>

* Add ADE_OBJ_VALIDATOR for index-based Lua handles

Int-index handles (shipclass, weaponclass, team, etc.) can now declare their validity predicate with a single ADE_OBJ_VALIDATOR or ADE_OBJ_VALIDATOR_RANGE line after the ADE_OBJ.  The registered validator drives the generated isValid() function and is also honored by ade_set_args when the mod table asks for nil instead of invalid objects, which previously never applied to these handles.  The 19 hand-written range-check functions are replaced, and loadout_ship, default_primary, default_secondary, and support_rearm_pool_team gain isValid().  Add a validator to HudGauge while we're at it.

Also fully qualify the scripting namespace in LuaConvert.h so its templates can be instantiated from the unit tests.

Co-Authored-By: Claude Fable 5.1 <[email protected]>

---------

Co-authored-by: Claude Fable 5.1 <[email protected]>
2026-09-08 10:50:53 -04:00
Goober5000 8dc03b0fff additional submodel scripting enhancements
4. `__eq` functions for models and submodels
5. Store model and submodel IDs, not pointers
2025-07-05 16:05:19 -04:00
Goober5000 1b75fea06c subsystem scripting enhancements
Add several API features to improve scripting support for subsystems.

1. A `CanonicalName` virtvar to provide a clear way to get subsystem names for indexing and referencing
2. `Submodel` and `SubmodelInstance` virtvars to get the submodel information associated with the subsystem, if it exists
3. A `getSubsystemList()` function to provide a subsystem iterator
2025-07-05 16:05:19 -04:00
Mike Nelson 4d39287de1 LuaLS meta file generation (scripting.lua) (#6516) 2025-06-08 11:29:30 -04:00
Goober5000 4797ce55a2 use vm_vector_2_matrix_norm on normalized vectors
Most places in the code that use `vm_vector_2_matrix` do so on already-normalized vectors.  Changing these to `vm_vector_2_matrix_norm` avoids redundant normalization.
2025-03-02 23:07:09 -05:00
Goober5000 e90416e199 Several coverity fixes (#6232)
* coverity - using `std::move` instead of copying, and change some parameters from value to reference

* coverity - fix or mark potential copy-paste mistakes

* coverity - various checking of parameter and return values

* coverity - miscellaneous fixes, and change some 'intentional' markers to 'false positive' markers
2024-07-06 12:51:31 +02:00
Goober5000 ebeec69a6d add API for glow point banks (#6107)
* add API for glow point banks

Previously, a model API existed for glow points mounted on thrusters, but not glow points mounted on glow point banks.  This adds glow point bank support.  Also, this refactors and cleans up the implementation of the model API a bit.

* NULL -> nullptr
2024-06-17 21:28:40 +02:00
Goober5000 89f4fe54c3 convert model_h and submodel_h to use indexes
Indexes are a more robust way than pointers to manage model and submodel handles, and in the event that models are made dynamic in the future, indexes will be necessary anyway.
2024-04-11 15:15:44 -04:00
Asteroth dc4daafd61 fix for a merge mistake 2024-03-12 15:39:00 -04:00
Asteroth 4b37796628 Merge remote-tracking branch 'upstream/master' into scripted-model-arcs 2024-03-12 15:38:13 -04:00
Goober5000 671fe21a75 additional collision info
* Add the submodel that was hit to the On Ship Collision scripting hook.  (This will only be non-nil if the ship was the "heavy object".)
* Add a `getModel()` function to the scripted submodel object.
* Fix some incorrect documentation in `OnShipCollision`.
2024-03-12 13:02:58 -04:00
Goober5000 d6606ad642 enhancements for submodel collisions
* Expose NoCollide and NoCollideThisOnly as virtual variables for submodels
* Allow submodels to be optionally specified in object:checkRayCollision
* Be sure to calculate ship-to-ship hit position before the override collision hook is called, in case the hook needs this value.  (The other collision hooks already calculate the hit position before the override hook.)
2024-03-12 13:02:57 -04:00
Asteroth 27925607b8 add scripted model arcs 2024-03-09 12:46:34 -05:00
Goober5000 592eefb60f scripting refactor to compose handle types
Several handle types in the scripting API used inheritance where composition would be more appropriate.  This refactors those types, as well as removing the various handle types that were just aliases for `model_h`.  These are just the C++-side types; all the Lua types remain as-is.

This also refactors `sound_h` to move the previous `isSoundValid` to `isValid` so that `ade_set_args` will work properly for sounds with the `Lua_API_returns_nil_instead_of_invalid_object` flag.  The subclassing from `sound_entry_h` was removed and the "full validity check" was moved to `isValidWithEntry`.  The Lua side remains unaffected, but additional documentation was added to clarify the usage.

Follow-up to #6009 and prerequisite to #6006 due to the `isValid` refactor for `sound_h`.
2024-02-28 02:51:08 -05:00
Goober5000 ec241fcab3 standardize on isValid() and make validity member functions const 2024-02-26 15:56:41 -05:00
BMagnu a9cfd27455 Expose more submodel instance and submodel attributes and functions to Lua (#5766)
* Add global to local for matrices

* Add lua integration

* Get Submodel from Submodel instance

* Add submodel functions

* Add model instance from submodel instance

* Fix index

* Fix copy paste error
2023-11-11 07:23:47 +09:00
Goober5000 17d36156cb add const where appropriate to the modelrender API
See title.  There were some cascade effects, but the changes are mostly contained to the model code.  The calls to `gr_render_model` and `g3_render_primitives` use `const_cast` because constifying that API would require a whole other PR.
2023-06-18 14:05:46 -04:00
Asteroth db5a37c178 add num vertices script func 2023-02-17 23:23:24 -05:00
Asteroth b68e424213 refactor getting random vertices and script func 2023-02-17 23:03:57 -05:00
Goober5000 da7228cedb model.Submodels fix
Guard against the indexer being invalid, e.g. if the model isn't loaded yet.
2022-10-14 02:07:35 -04:00
Goober5000 c7b1092a96 a few more script enhancements
1) Add the "no-thrusters" ship flag to the list of flag that can be used by alter-ship-flag or the ship's setFlag function
2) Add a `FireRateMultiplier` virtvar to control the firing rate of turrets (fulfills #4300)
3) Add a `setGlowPointBankActive` function to do the same thing as `activate-glow-point-bank`/`deactivate-glow-point-bank`
2022-09-22 02:12:17 -04:00
Goober5000 18a8e280dc add scripting support for decals
This extends the existing decal system so that decals can be created through scripting.
2022-03-01 19:07:39 -05:00
Goober5000 54ff2f00ed more updates 2022-02-17 01:57:34 -05:00
Goober5000 dc2d3ae623 fix compilation and address feedback 2022-02-16 23:57:54 -05:00
Goober5000 57705db466 add scripting support for submodels
Allow scripts to reference submodels, submodel instances, and model instances.  Currently just a few properties (like Orientation and Radius) can be accessed, but this can be easily expanded in the future.

Also add relevant functions to calculate real-world positions and orientations of rotated submodels.
2022-02-16 21:45:23 -05:00
Goober5000 09da73eec8 fix another isValid scripting function 2022-02-15 00:02:05 -05:00
asarium 0fb712ed39 Add full type coverage for return types and variables
This introduces type parsing for all types used within the scripting
documentation. This improves the generated JSON output and also
validates new code via the unit test.
2021-02-26 22:37:37 +01:00
Goober5000 6e40248490 add vector interpolation, sexp variable name, and joystick axis inversion
add several more vecmat functions to scripting
2020-07-23 14:43:02 -04:00
Goober5000 31fa2ac444 cleanup of tech room, and scripting stuff
1) Upgrade the pilot file code to correctly save flags whether entries are added *or* removed
2) Make the tech-db/tech-db-multi ship flag handling consistent
3) Add scripting support for intel entries
4) Add scripting support for adding and removing entries from the tech room
5) Minor cleanup
2020-07-15 13:27:27 -04:00
asarium 4ca589a61c Make Lua documentation generation more generic
This adds JSON as an additional scripting documentation output format.
This can be used by external tools to examine the scripting
documentation and generate interface declarations or documentation for
any language. The existing documentation code is left largely in place.
2019-12-01 12:53:51 +01:00
asarium 4eb0e41142 Check optional scripting parameters before using them
These were all cases where the parameter was the new value when setting
a variable. The variables should always be initialized when that code is
reached but it is still better to check the pointers before using them.

These were found by @niffiwan.
2018-11-26 18:50:12 +01:00
asarium 00b0a80ad9 Call scripting handle destructor when Lua collects garbage
This will automatically call the destructor of a type of Lua calls the
garbage collector for an object of that type. This is the last step
towards fully supporting non-trivial objects in the Lua API and all
previous workarounds have been removed.
2018-11-18 12:43:39 +01:00
asarium 88115c7703 Fix clang-tidy issues 2018-09-26 19:15:42 +02:00
asarium 8f4d51b14a Convert ade_get_args to variadic template based solution
This maintains the type information which can be used for enforce
const-correctness and also for implementing more advanced ways of
handling the type information.
2018-09-26 19:15:42 +02:00
asarium c17dcb1835 Move source files into category directories 2016-12-30 19:13:39 +01:00