ACSUtils Wiki

An ACS library for ZDoom-based ports

User Tools

Site Tools


functions:newtid

This is an old revision of the document!


NewTid

int NewTid()

Description

The problem

UniqueTid is error-prone when mixed with statically allocated tid ranges. You always need to pass the correct boundaries to UniqueTid, like UniqueTid(2000, INT_MAX), making sure that no actors with tid over 2000 are spawned manually after a call to UniqueTid. Otherwise the newly spawned actor may conflict with the randomly allocated tid.

For example, if you have decided that player tids will range from 1000 to 1063, an incorrect call to UniqueTid like UniqueTid(500, 15000) may return tid 1008, which does not yet conflict with any of the player tids, but will do so when player 9 joins the game.

To correctly use UniqueTid, you need to use the same start value in the whole project.

Zandronum

There is also a Zandronum bug: tids over 32767 are not transmitted to clients. This means that you generally shouldn't use them.

The solution

NewTid is a function designed to solve both these problems. To use NewTid, you first specify the first tid it may allocate using a global #define in your project:

#define TIDALLOCSTART 15000
#include "acsutils.acs"

And NewTid() will return safe tids without any parameters required. NewTid() will prefer Zandronum-safe tids (below 32767) and only switch to Zandronum-unsafe tids if all safe tids are occupied, which can only happen if you have spawned an insane amount of actors with different tids.

Examples

Just use NewTid like UniqueTid without specifying any error-prone boundaries:

<code> int tid = NewTid(); Spawn(“SomeActor”, x, y, z, tid, angle); <code>

functions/newtid.1489940454.txt.gz · Last modified: 2017/03/19 18:20 by korshun