"use strict";
/*---------------------------------------------------------------------------------------------
* Copyright (c) Bentley Systems, Incorporated. All rights reserved.
* See LICENSE.md in the project root for license terms and full copyright notice.
*--------------------------------------------------------------------------------------------*/
/** @packageDocumentation
 * @module Tiles
 */
Object.defineProperty(exports, "__esModule", { value: true });
exports.TileUsageMarker = void 0;
const core_bentley_1 = require("@itwin/core-bentley");
const IModelApp_1 = require("../IModelApp");
/** A marker associated with a [[Tile]] to track usage of that tile by any number of [[TileUser]]s.
 * The marker tracks:
 *  - the set of [[TileUser]]s by which the tile is in use for some purpose (displayed, preloaded, requested, selected for shadow map, etc); and
 *  - the most recent time at which any tile user declared its use of the tile.
 * The marker is used to allow tiles to be discarded after they become disused by any tile user, via [[Tile.prune]].
 * @see [[Tile.usageMarker]].
 * @public
 * @extensions
 */
class TileUsageMarker {
    _timePoint = core_bentley_1.BeTimePoint.now();
    /** Constructs a usage marker with its timepoint set to the current time and its set of [[TileUser]]s empty. */
    constructor() {
    }
    /** Returns true if this tile is currently in use by no [[TileUser]]s and its timestamp pre-dates `expirationTime`. */
    isExpired(expirationTime) {
        return this.isTimestampExpired(expirationTime) && !this.getIsTileInUse();
    }
    /** Returns true if this tile is currently in use by any [[TileUser]]. */
    getIsTileInUse() {
        return IModelApp_1.IModelApp.tileAdmin.isTileInUse(this);
    }
    /** Returns true if this tile's timestamp pre-dates `expirationTime`, without checking if it is in use. */
    isTimestampExpired(expirationTime) {
        return this._timePoint.before(expirationTime);
    }
    /** Updates the timestamp to the specified time and marks the tile as being in use by the specified [[TileUser]]. */
    mark(user, time) {
        this._timePoint = time;
        IModelApp_1.IModelApp.tileAdmin.markTileUsed(this, user);
    }
}
exports.TileUsageMarker = TileUsageMarker;
//# sourceMappingURL=TileUsageMarker.js.map