Using and writing packages
A package is Tide code, and C, that games share: a folder of .tide files, like a game's, without a Main. A game lists the packages it uses in a file named tide.packages, next to its own files, and tide builds them with it. Packages come from git repositories, at a commit, from folders on your machine, or with tide itself.
For the list of bundled packages, their API documentation and how to find docs for other packages, start with the Packages overview.
Using one
tide add puts a package in the game in the current folder:
tide add github.com/someone/tide-physicsIt finds the newest commit of the repository's default branch, downloads it, and writes a line for it in tide.packages, starting the file if there's none:
github.com/someone/tide-physics b01aac4d779e32c9c415283b65e40c86d691e7abThe package's code is in its namespace, which is its name, so the game names what it declares with it, or imports it with using (see Namespaces and files):
using Physics;
scene Main { }
event(Spawned) Setup(with Main)
{
Spawn(Body { velocity = float3(0, 1, 0) });
}tide add takes the repository however you have it: https://github.com/someone/tide-physics.git, git@github.com:someone/tide-physics.git, or as tide.packages writes it. Packages come from GitHub, GitLab, Codeberg and Bitbucket, and need no git on your machine: tide downloads each commit as its host's archive of it.
Every build, the same code
A line always has its commit, and the game builds with that commit's code, whoever builds it and wherever: your machine, someone else's, a build server, the web build and the desktop one. They have to: a match's players simulate it together, so each of them has to run the same code. A branch or a tag can move, so a line never builds with "the newest" of anything.
tide keeps each commit it downloads, once for every game on your machine, in %LOCALAPPDATA%\Tide\packages on Windows and ~/.tide/packages elsewhere (or where the TIDE_PACKAGES environment variable says). A game whose packages aren't there yet, like one you just cloned, downloads them the first time tide run or tide build builds it. tide fetch downloads them without building, for a build that then needs no network.
Pinning Tide itself
tide pin writes the invoking Tide's exact version into the game's tide.packages.
To choose another release, use tide pin 0.5.0-nightly.12:
tide = 0.5.0-nightly.12To follow a channel automatically, use tide pin nightly or tide pin stable:
tide = nightlyEach channel has one shared installation under TIDE_VERSIONS/nightly or
TIDE_VERSIONS/stable. Project commands check for the newest release at startup
and update that installation in place while idle. Nightly follows the same
release selection as tide upgrade --nightly (including a newer stable release).
An active build or watch session keeps its current compiler; another command
can share it and defers updating until the installation is idle. Offline, or if
a download fails, a complete installed version is reused. The command reports
the exact version selected. The first installation asks for download approval;
choosing a channel authorizes its subsequent automatic updates. A channel can
resolve to different versions on different machines or days; use an exact pin
for reproducible builds.
run, build, schedule, shaders, add, update, eject, fetch and
publish use that pinned release. If it is missing, Tide asks to download it,
checks its release checksum, then continues the original command. Declining or
ending input stops the command. Scripts with no terminal report the missing
version; a caller that can forward an answer through stdin can set
TIDE_INTERACTIVE=1 to enable the prompt.
Versions stay side by side in TIDE_VERSIONS, or by default
%LOCALAPPDATA%/Tide/versions on Windows and ~/.tide/versions elsewhere.
Exact installations are removed automatically after 30 days without use, during
project commands. Active sessions are protected; existing caches get a fresh
30-day grace period when first observed. Returning to an expired pin asks to
download it again. The main installation and the two channel installations are
kept. Unity uses the same cache and protects selected compilers while its editor
is using them. Downloading
a project version leaves your main Tide installation and editor plugins as they
are. tide upgrade still updates the invoking installation; tide version and
help describe that installation. tide pin only changes the project's pin.
Unity projects keep using the toolchain selected by their Tide Unity package.
A Tide built from engine source (a version ending in -dev) keeps using that
build for engine development, even when a game pins a release.
Updating
tide update moves packages to the newest commit of what they follow, and says what changed:
tide update # every package from git
tide update physics # one, by its name, its repository's name, or its sourcetide: Physics b01aac4 -> 7d3e9f1 (main)A line follows its repository's default branch, or what comes after @ in it:
| Line | tide update moves it to |
|---|---|
github.com/someone/tide-physics b01aac4... |
The newest commit of the default branch |
github.com/someone/tide-physics@dev b01aac4... |
The newest commit of the dev branch |
github.com/someone/tide-physics@v1 b01aac4... |
The newest v1.x.y tag |
github.com/someone/tide-physics@v1.2 b01aac4... |
The newest v1.2.x tag |
A version, like v1 or 1.2, follows tags, leaving out pre-releases like v1.3.0-rc.1; anything else is a branch. tide add takes the same: tide add github.com/someone/tide-physics@v1.
A line can leave its commit out, as when you write one by hand: tide update puts the newest one in. tide update only changes the commits in tide.packages, so your comments and the order of its lines stay, and what changed shows in git like any other change.
The packages a package needs
A package can use other packages, which its own tide.packages lists. The game builds with them too, and with what they need in turn, each from the line of the package that needs it: a package from git at the commit that package names, a folder relative to that package's folder. The game's tide.packages lists only the packages it chooses.
If a package's metadata or dependencies are invalid, tide add, tide update and a build report the problem, at the line of the package that needs it, and fail.
When the game lists a package that one of its packages needs too, the game's line is the one it builds with, whatever commit each names. That's how a game chooses: when two packages need one from git at different commits and the game doesn't list it, nothing builds, and the error names both and the line that settles it:
tools/tide.packages:2: error: Tools needs github.com/someone/tide-math at 6e1f0a2, and Physics needs it at 9f2c1e0
= note: a game builds one commit of each package: list the one to build in game/tide.packages, like `github.com/someone/tide-math 9f2c1e0...`Two packages needing the same commit, or the same folder, need one package.
Packages in folders
A line can be a folder instead, relative to the game's, for a package you're writing, or one a few games of yours share:
../shared
github.com/someone/tide-physics b01aac4d779e32c9c415283b65e40c86d691e7abA folder's files build as they are, with no commit, and tide run reloads the game when they change, as it does for the game's own. tide add ../shared adds one and preserves the complete folder path in tide.packages.
Packages that come with tide
The bundled packages are render3d, cornerculling, geometry, box2d, box3d, rooms, lobby, steam and voice. Their API docs are collected in this section. Render3D supplies static/skinned mesh materials with package-owned lighting, shadows, vertex deformation, transparency and HDR effects. Use a checkout or installation containing the packages you need, and check their current scope. A line for a bundled package is its name alone:
box2d
github.com/someone/tide-physics b01aac4d779e32c9c415283b65e40c86d691e7abtide add box2d writes that line. A game that doesn't list one builds none of it: its code compiles and links only with the games that name it.
A name is lower-case letters and digits, and it's never a folder: a folder of that name beside the game is still written as a path, ./box2d. The line has no commit and follows no branch, since the package is the version your tide came with: tide upgrade updates both, and tide update leaves the line alone. So two machines build the same code of it when they have the same version of tide. A tide 0.3 line in the game's tide.packages says the oldest one the game builds with.
A game may follow tide = nightly or tide = stable, as described under
Pinning Tide itself. An exact tide = 0.5.0-nightly.12 line pins the one version the game builds with, so everyone working on it, and a build server, build the same: another version refuses to build it, and says how to install the pinned one (tide upgrade --version 0.5.0-nightly.12). tide pin writes the line for the tide you have, or tide pin <version> for another. Only a game pins: a package says the oldest version it builds with. A build of tide's own source (its version ends in -dev) builds a pinned game anyway, as someone working on tide would. In a Unity project, Tide's package builds with the version of its own commit, and a pin it doesn't match is an error.
A name no package has is an error that lists the ones there are. They're folders of the installation's src/packages folder, each named as its line is, where the editors' go to definition takes you.
Packages for some builds only
#if lines say which builds a package is in, by the build's symbols: DEBUG, which default debug builds, rather than --release or --distribution builds has, and what the command line names with --define.
rooms
#if STEAM
github.com/someone/tide-steam 9c1d7be0a4f25d6c8e3b17f04a92d5c6e8f0a1b2
#else
../our-lobby
#endif
#if DEBUG
../cheats
#endiftide build --release --define STEAM builds with rooms and the Steam package; tide run builds with rooms, the lobby in the folder and the cheats. A package a build leaves out is no part of it: none of its code, C or libraries compiles or links, and its PACKAGE_ symbol isn't defined, so the game's own code can follow with #if PACKAGE_STEAM.
Conditions are written as in code: symbols with !, &&, ||, == and !=, parentheses, true and false, and versions of tide like TIDE_0_4_OR_NEWER, with #elif and #else branches, and #ifs inside one another. Any other line that starts with # is still a comment. A package or tide line is the same in every build, so it goes outside them, and a condition can't read a PACKAGE_ symbol, as those come from this file.
tide add, tide update, tide fetch and tide eject see every line, whichever build it's for: tide update moves a package no matter which branch lists it, and tide fetch downloads them all. Editors read the file as tide run does, with DEBUG and nothing a command line would define.
Making a package your own
A package's code isn't the game's to edit: one from git is a commit, and one that comes with tide is replaced by the next upgrade. tide eject copies a package into the game and builds with the copy:
tide eject rooms./packages/roomsThe package is a folder of the game's from there, in packages/ under its own folder's name, and its line is that folder, with any comment after it kept. It's the same package still, with its namespace and what it needs, so nothing else in the game changes; tide update and tide upgrade no longer move it. Before ejecting, see whether the package marks what you want to change as virtual: an override changes that much and keeps the package's updates.
Writing a package
A package is a folder whose tide.packages starts with its name, which is its namespace:
package Physics
tide 0.3
github.com/someone/tide-math 9f2c1e07d4b8a3f6e5c2d1b0a9f8e7d6c5b4a392- Every file of the package puts what it declares in its namespace,
namespace Physics;, or in one inside it, likenamespace Physics.Joints;. - What's the game's own stays the game's: a package can't declare
Main, the input or settings. Its systems can takeDevices, which the game's input sends with its own fields. tide 0.3is the oldesttideit builds with. With an older one, a game that uses it says so, and to runtide upgrade.- Its other lines are the packages it needs, as a game lists them. One from git only needs packages from git and packages that come with
tide, since a folder on your machine isn't on anyone else's. - Its C goes in its folder, as a game's does (see Calling C), and compiles with the game.
- A package's systems run before the game's: packages' files compile first, each package after those it needs, and the game's files last (see Systems).
- A package can replace code the game marked
virtual, with anoverride, and mark its own for the game to replace (see Virtual and override).
To try a package as you write it, make a game in a folder of its own inside it, whose tide.packages lists the package's folder:
physics/
tide.packages package Physics
body.tide
example/
tide.packages ..
main.tide scene Main { } ...A folder with a tide.packages of its own is a game or a package, so example/ isn't part of the package, and the package isn't part of a game that holds it in a folder: a game uses it by listing it. Put a package's repository online, and tide add takes it. A repository can hold several packages, each in a folder of it, which a line names after //:
github.com/someone/tide-packages//physics b01aac4d779e32c9c415283b65e40c86d691e7abReplacing a game's code
A package adds to a game, and it can also change it: an expansion, a variant of the rules, a mod. The game marks what can be replaced with virtual, and the package replaces it with an override of the same name and parameters, which runs in its place:
// The game
namespace Combat;
virtual float Damage(float base, Weapon weapon)
{
return base + weapon.power;
}// The package
namespace Hardcore;
override float Combat.Damage(float base, Combat.Weapon weapon)
{
return (base + weapon.power) * 2;
}Every call of Damage in the game now calls the package's. Systems, views, handlers, methods, frags and verts are replaced the same way, and a game replaces what a package marked: see Virtual and override.
Code for other versions of tide
Tide still changes from version to version, so a package can have code for the versions it supports, which #if picks between (see Namespaces and files):
#if TIDE_0_4_OR_NEWER
// Code that uses what tide 0.4 added
#else
// The same, as tide 0.3 writes it
#endifUnity components
In a Unity project, a package's components are on GameObjects like the game's own. A unity.json in the package's folder says how they're shown and baked there, for each game that lists the package. Box3D's:
{
"components": {
"Box3D.Body": { "hidden": ["stepPosition", "stepVelocity"] },
"Box3D.Box": {
"scaled": { "size": "absScale", "offset": "scale" },
"shape": { "box": "size", "center": "offset" }
},
"Box3D.MeshCollider": {
"placed": "offset",
"mesh": { "vertices": "vertices", "indices": "indices", "scale": "scale" }
},
"Box3D.Part": { "part": { "of": "of", "body": "Box3D.Body" } },
"Box3D.Joint": {
"readBack": ["force", "torque"],
"joint": { "a": "a", "b": "b", "anchorA": "anchorA", "anchorB": "anchorB" }
}
},
"source": ["namespace Box3D", "{", " ...", "}"]
}Every component and field it names must be the package's: a rule for one the package doesn't have, such as one left from an earlier version, is an error that names it. A component's [Native] fields are the package's own without being listed: they aren't in the Inspector, baked or read.
hiddenis a list of the component's fields that aren't in the Inspector or baked from the scene, as the package sets them itself; ortruefor a component that isn't in Add Component, one the package adds itself.scaledgives fields that are by the GameObject's scale, as a collider's size is. They're authored without the scale and baked times it, and in Play the component shows the match's value divided by it. Each one's scale is one ofscaleandabsScale(each axis, with its sign or without),largestScale,largestScaleXY,largestScaleXZ(the largest axis without its sign),scaleX,scaleYorscaleZ.shapeis what the Scene view draws of the component while its GameObject or one above it is selected, as Unity draws a collider (every shape, with Always Show Tide Shapes on in Project Settings > Tide), and gives handles with Edit Shape: one ofbox,sphereorcapsule, or in the XY planerectorcircle, naming its size field (a radius for the round ones).centernames its centre's field, and a capsule'sheightits height's.placednames the field that places the component on its entity's body, such as a shape's offset. A shape'scenteris its placed field unless another is named.partsays the component makes its entity a part of another's body:ofnames its entity field for the body, andbodythe body's component. Whenofis left empty, it's the nearest GameObject above with that component, and the package'ssourceshould find the same at run time. A part's placed fields are baked where its GameObject puts them on its body, in the body's frame, and in Play they're shown from the body's GameObject again. A part turned against its body is a warning, unless its shape is round, as a shape's offset can't turn.meshnames a component's lists that Unity fills from a Mesh:vertices(a list offloat3) andindices(a list ofint, three for each triangle; left out for a hull), andscale, the field the vertices are scaled by. The component's Inspector has a Mesh field and Copy, and a component added to a GameObject with a MeshFilter starts with its mesh. Unity's triangles go in as they are: their front is the side they're clockwise from, as in Tide. A selected one's triangles are drawn in the Scene view, a hull's points.pointslists fields that are a shape's points in its GameObject's own space: afloat2orfloat3, or a list of them. They're baked times the GameObject's scale, each axis with its sign, and on a part turned and moved into its body's frame, which points can be (a flat shape's part turned other than about z is a warning). Where the scale mirrors a list, it's baked in the other order, so a chain's sides stay its sides. In Play the component shows them as authored.outlineis what the Scene view draws of a shape of points, with a handle on each point in Edit Shape:pointsnames its point fields in order,radiusthe field rounding it,closedistrueor names a bool field saying when it's closed, andhulldraws the points' convex hull, as a polygon made of them is.jointis what the Scene view draws of a joint: a line between its anchors, with handles in Edit Shape that move them and turn their frames.aandbname its entity fields,anchorAandanchorBits anchors in their bodies' frames (each body's position and turn, not its scale), androtationAandrotationB, if it has them, the frames' turns: a quaternion, or an angle about z.terrainnames the fields of a height field that Unity fills from a Terrain:heights(a list offloat,x + z * columns),holes(a list ofbyte, one for each cell, nonzero for a hole),columns,rows,scale(a cell's size in x and z, the heights' in y), and its bounds,minimumandmaximum. The Inspector has a Terrain field and Copy, and a component added to a Terrain's GameObject starts with its data. A terrain of more samples than Box3D takes (65,536, 4,096 a side) is copied every second, fourth or more sample, and a cell is a hole where every one of the terrain's in it is. The Scene view draws its grid.readBacklists fields the package writes for code to read, such as a joint's force. They're shown in Play, never authored or baked.sourceis lines of Tide that the game has in a Unity project alone, in the package's namespace. Box3D's starts a body where its entity's Transform is, has the Transform follow the body, and makes a part that names no body a part of the nearest body above it.
tide schedule Assets --assets Assets checks a Unity project's game with its packages' rules and source, without building it.
Editors
The editors' language server analyzes a game with its packages, so completion, errors and go to definition reach into them. A package's file you open is analyzed with the open game that uses it, or else on its own, with what it needs. Packages from git it doesn't have yet are left out until tide downloads them.