repo_name string | dataset string | owner string | lang string | func_name string | code string | docstring string | url string | sha string |
|---|---|---|---|---|---|---|---|---|
biomes-game | github_2023 | ill-inc | typescript | UserRobot.pullCharge | pullCharge(power: number) {
for (const { ref, battery } of this.batteries()) {
power = battery.pullCharge(power);
this.inventory.set(ref, battery.build());
}
const baseChargeDecrease = Math.min(this.baseCharge(), power);
this.setBaseCharge(this.baseCharge() - baseChargeDecrease);
this.up... | /**
* Take charge from batteries stored in the robot's inventory. Once depleted,
* charge is taken from the robot's internal capacity.
*/ | https://github.com/ill-inc/biomes-game/blob/14252b95bf9e68495655af40c72750e8e3c44a42/src/server/logic/utils/robot.ts#L301-L309 | 14252b95bf9e68495655af40c72750e8e3c44a42 |
biomes-game | github_2023 | ill-inc | typescript | SubscriberTable.createAsync | createAsync(id: string, fn: SubscriberFn<Args>): Subscription {
return this.create(id, makeDefer(fn));
} | // block notify. | https://github.com/ill-inc/biomes-game/blob/14252b95bf9e68495655af40c72750e8e3c44a42/src/server/shared/subscribers.ts#L34-L36 | 14252b95bf9e68495655af40c72750e8e3c44a42 |
biomes-game | github_2023 | ill-inc | typescript | SubscriberTable.subscribeAsync | subscribeAsync(prefix: string, fn: SubscriberFn<Args>): Subscription {
return this.subscribe(prefix, makeDefer(fn));
} | // block notify. | https://github.com/ill-inc/biomes-game/blob/14252b95bf9e68495655af40c72750e8e3c44a42/src/server/shared/subscribers.ts#L44-L46 | 14252b95bf9e68495655af40c72750e8e3c44a42 |
biomes-game | github_2023 | ill-inc | typescript | Bakery.deleteBiscuits | async deleteBiscuits(meta: TrayMetadata, ...ids: BiomesId[]) {
if (!ids.length) {
return;
}
ok(
this.idGenerator !== undefined,
"No idGenerator configured: Bakery in readonly mode"
);
await this.db.runTransaction(async (tx) => {
const namesDocPromise = tx.get(this.namesDocRef... | // references but rather simply delete these definitions | https://github.com/ill-inc/biomes-game/blob/14252b95bf9e68495655af40c72750e8e3c44a42/src/server/shared/bikkie/bakery.ts#L280-L311 | 14252b95bf9e68495655af40c72750e8e3c44a42 |
biomes-game | github_2023 | ill-inc | typescript | Bakery.saveAsActive | async saveAsActive(
{
meta,
forceCompaction,
}: { meta: TrayMetadata; forceCompaction?: boolean },
...definitions: BiscuitDefinition[]
) {
ok(
this.idGenerator !== undefined,
"No idGenerator configured: Bakery in readonly mode"
);
// Before doing any real work, check th... | // active tray and immediately be visible. | https://github.com/ill-inc/biomes-game/blob/14252b95bf9e68495655af40c72750e8e3c44a42/src/server/shared/bikkie/bakery.ts#L315-L366 | 14252b95bf9e68495655af40c72750e8e3c44a42 |
biomes-game | github_2023 | ill-inc | typescript | InMemoryChatApi.sendMessage | async sendMessage(request: SendMessageRequest): Promise<SendMessageResponse> {
const envelope = await wrapInEnvelope(request, this.players);
const channelName = determineChannel(request);
const delivery: Delivery = { channelName, mail: [envelope] };
const recipients = determineTargets(this.players, cha... | // Send a message to the chat system. | https://github.com/ill-inc/biomes-game/blob/14252b95bf9e68495655af40c72750e8e3c44a42/src/server/shared/chat/memory.ts#L71-L87 | 14252b95bf9e68495655af40c72750e8e3c44a42 |
biomes-game | github_2023 | ill-inc | typescript | InMemoryChatApi.unsendMessage | async unsendMessage(request: UnsendMessageRequest): Promise<void> {
const envelope = await wrapInEnvelope(request, this.players);
const channelName = determineChannel(request);
const delivery: Delivery = { channelName, unsend: [envelope] };
const recipients = determineTargets(this.players, channelName,... | // Unsend a message from the chat system. | https://github.com/ill-inc/biomes-game/blob/14252b95bf9e68495655af40c72750e8e3c44a42/src/server/shared/chat/memory.ts#L90-L99 | 14252b95bf9e68495655af40c72750e8e3c44a42 |
biomes-game | github_2023 | ill-inc | typescript | InMemoryChatApi.deleteEntity | deleteEntity(_id: BiomesId): void {
// TODO: Implement.
} | // Will be performed in the background, you cannot wait for it. | https://github.com/ill-inc/biomes-game/blob/14252b95bf9e68495655af40c72750e8e3c44a42/src/server/shared/chat/memory.ts#L103-L105 | 14252b95bf9e68495655af40c72750e8e3c44a42 |
biomes-game | github_2023 | ill-inc | typescript | InMemoryChatApi.export | async export(id: BiomesId): Promise<Delivery[]> {
return this.storage.get(id).asDeliveries();
} | // Export all chat messages relevant for a user. | https://github.com/ill-inc/biomes-game/blob/14252b95bf9e68495655af40c72750e8e3c44a42/src/server/shared/chat/memory.ts#L108-L110 | 14252b95bf9e68495655af40c72750e8e3c44a42 |
biomes-game | github_2023 | ill-inc | typescript | InMemoryChatApi.subscribe | async *subscribe(
id: BiomesId,
signal?: AbortSignal
): AsyncIterable<Delivery> {
const [cb, stream] = callbackToStream<Delivery>(signal);
this.subscriptions.add(id, cb);
try {
yield* await this.export(id);
yield* stream;
} finally {
this.subscriptions.delete(id, cb);
}
... | // Subscribe to all chat messages relevant for a user. | https://github.com/ill-inc/biomes-game/blob/14252b95bf9e68495655af40c72750e8e3c44a42/src/server/shared/chat/memory.ts#L113-L125 | 14252b95bf9e68495655af40c72750e8e3c44a42 |
biomes-game | github_2023 | ill-inc | typescript | PlayerSpatialObserver.copyPosition | async copyPosition(id: BiomesId): Promise<Vec3 | undefined> {
const domain = this.spatial.get(id);
if (!domain) {
return undefined;
}
return isEntryDomainAabb(domain) ? centerAABB(domain) : [...domain];
} | // Not actually async, just to conform to PositionProvider. | https://github.com/ill-inc/biomes-game/blob/14252b95bf9e68495655af40c72750e8e3c44a42/src/server/shared/chat/player_observer.ts#L95-L101 | 14252b95bf9e68495655af40c72750e8e3c44a42 |
biomes-game | github_2023 | ill-inc | typescript | RemoteChatApi.sendMessage | sendMessage(request: SendMessageRequest): Promise<SendMessageResponse> {
return this.client.sendMessage(request);
} | // Send a message to the chat system. | https://github.com/ill-inc/biomes-game/blob/14252b95bf9e68495655af40c72750e8e3c44a42/src/server/shared/chat/remote.ts#L59-L61 | 14252b95bf9e68495655af40c72750e8e3c44a42 |
biomes-game | github_2023 | ill-inc | typescript | RemoteChatApi.unsendMessage | unsendMessage(request: UnsendMessageRequest): Promise<void> {
return this.client.unsendMessage(request);
} | // Unsend a message from the chat system. | https://github.com/ill-inc/biomes-game/blob/14252b95bf9e68495655af40c72750e8e3c44a42/src/server/shared/chat/remote.ts#L64-L66 | 14252b95bf9e68495655af40c72750e8e3c44a42 |
biomes-game | github_2023 | ill-inc | typescript | RemoteChatApi.deleteEntity | deleteEntity(id: BiomesId): void {
// TODO: Maybe make reliable?
fireAndForget(this.client.deleteEntity({ id }));
} | // Will be performed in the background, you cannot wait for it. | https://github.com/ill-inc/biomes-game/blob/14252b95bf9e68495655af40c72750e8e3c44a42/src/server/shared/chat/remote.ts#L70-L73 | 14252b95bf9e68495655af40c72750e8e3c44a42 |
biomes-game | github_2023 | ill-inc | typescript | RemoteChatApi.export | export(id: BiomesId): Promise<Delivery[]> {
return this.client.export(id);
} | // Export all chat messages relevant for a user. | https://github.com/ill-inc/biomes-game/blob/14252b95bf9e68495655af40c72750e8e3c44a42/src/server/shared/chat/remote.ts#L76-L78 | 14252b95bf9e68495655af40c72750e8e3c44a42 |
biomes-game | github_2023 | ill-inc | typescript | RemoteChatApi.subscribe | async *subscribe(
id: BiomesId,
signal?: AbortSignal
): AsyncIterable<Delivery> {
while (!signal?.aborted) {
yield* this.client.subscribe(id, signal);
}
} | // Subscribe to all chat messages relevant for a user. | https://github.com/ill-inc/biomes-game/blob/14252b95bf9e68495655af40c72750e8e3c44a42/src/server/shared/chat/remote.ts#L81-L88 | 14252b95bf9e68495655af40c72750e8e3c44a42 |
biomes-game | github_2023 | ill-inc | typescript | RedisChatDistributor.getPendingMessagesCount | async getPendingMessagesCount(): Promise<number | undefined> {
try {
const pending = await pendingGroupMessages(
this.redis,
EXTENDED_DELIVERY_STREAM_KEY,
this.group
);
chatPendingMessages.set(pending);
return pending;
} catch (error) {
log.warn("Could not u... | // Get the pending messages count, will also update the gauge. | https://github.com/ill-inc/biomes-game/blob/14252b95bf9e68495655af40c72750e8e3c44a42/src/server/shared/chat/redis/distribution.ts#L175-L187 | 14252b95bf9e68495655af40c72750e8e3c44a42 |
biomes-game | github_2023 | ill-inc | typescript | RedisChatDistributor.aggregateDeliveries | private aggregateDeliveries(
deliveries: Delivery[]
): [
inMessages: number,
outMessages: number,
workByTarget: DefaultMap<BiomesId, AnyPreparedDelivery[]>
] {
let inMessages = 0;
let outMessages = 0;
const workByTarget = new DefaultMap<BiomesId, AnyPreparedDelivery[]>(
() => []
... | // Aggregate work by user. | https://github.com/ill-inc/biomes-game/blob/14252b95bf9e68495655af40c72750e8e3c44a42/src/server/shared/chat/redis/distribution.ts#L267-L306 | 14252b95bf9e68495655af40c72750e8e3c44a42 |
biomes-game | github_2023 | ill-inc | typescript | RedisChatApi.unsendMessage | async unsendMessage(request: UnsendMessageRequest): Promise<void> {
const recorder = new ClientRequestStatRecorder("/chat/unsendMessage");
try {
const channelName = determineChannel(request);
const targets = determineTargets(channelName, request);
if (targets === "none") {
return;
... | // Unsend a message from the chat system. | https://github.com/ill-inc/biomes-game/blob/14252b95bf9e68495655af40c72750e8e3c44a42/src/server/shared/chat/redis/redis.ts#L135-L151 | 14252b95bf9e68495655af40c72750e8e3c44a42 |
biomes-game | github_2023 | ill-inc | typescript | RedisChatApi.deleteEntity | deleteEntity(_id: BiomesId): void {
// TODO.
} | // Will be performed in the background, you cannot wait for it. | https://github.com/ill-inc/biomes-game/blob/14252b95bf9e68495655af40c72750e8e3c44a42/src/server/shared/chat/redis/redis.ts#L155-L157 | 14252b95bf9e68495655af40c72750e8e3c44a42 |
biomes-game | github_2023 | ill-inc | typescript | RedisChatApi.export | async export(id: BiomesId): Promise<Delivery[]> {
const recorder = new ClientRequestStatRecorder("/chat/export");
try {
const key = chatsKey(id);
const raw = await this.redis.replica.hgetallBuffer(key);
const deliveries = compactMap(values(raw), (packed) =>
deserializeSingleDelivery(pa... | // Export all chat messages relevant for a user. | https://github.com/ill-inc/biomes-game/blob/14252b95bf9e68495655af40c72750e8e3c44a42/src/server/shared/chat/redis/redis.ts#L160-L176 | 14252b95bf9e68495655af40c72750e8e3c44a42 |
biomes-game | github_2023 | ill-inc | typescript | RedisChatApi.subscribe | async *subscribe(
id: BiomesId,
inputSignal?: AbortSignal
): AsyncIterable<Delivery> {
const signal = this.controller.chain(inputSignal).signal;
// The Redis client once subscribed is in 'subscribe' mode and cannot be used for
// other purposes.
const sub = this.redis.createSubscriptionConnect... | // Subscribe to all chat messages relevant for a user. | https://github.com/ill-inc/biomes-game/blob/14252b95bf9e68495655af40c72750e8e3c44a42/src/server/shared/chat/redis/redis.ts#L179-L212 | 14252b95bf9e68495655af40c72750e8e3c44a42 |
biomes-game | github_2023 | ill-inc | typescript | AdvertisedValue.keepalive | private async keepalive(ttl: number) {
try {
await asyncBackoffOnAllErrors(
async () => {
const tx = this.redis.primary.multi();
tx.publish(this.redisKey, "change");
if (ttl > 0) {
tx.hset(this.redisKey, {
[this.nonce]: zrpcWebSerialize({
... | // Indicate our presence | https://github.com/ill-inc/biomes-game/blob/14252b95bf9e68495655af40c72750e8e3c44a42/src/server/shared/discovery/redis.ts#L38-L73 | 14252b95bf9e68495655af40c72750e8e3c44a42 |
biomes-game | github_2023 | ill-inc | typescript | RedisServiceDiscovery.constructor | constructor(
private readonly redis: BiomesRedis,
public readonly service: string
) {
this.batcher = new PipelineBatcher(
() => this.refreshKnownValues(),
1_000,
this.controller.signal
);
} | // Public for tests. | https://github.com/ill-inc/biomes-game/blob/14252b95bf9e68495655af40c72750e8e3c44a42/src/server/shared/discovery/redis.ts#L108-L117 | 14252b95bf9e68495655af40c72750e8e3c44a42 |
biomes-game | github_2023 | ill-inc | typescript | RedisElection.constructor | constructor(
private readonly redis: BiomesRedis,
public readonly campaign: ElectionCampaign
) {} | // Public for tests. | https://github.com/ill-inc/biomes-game/blob/14252b95bf9e68495655af40c72750e8e3c44a42/src/server/shared/election/redis.ts#L21-L24 | 14252b95bf9e68495655af40c72750e8e3c44a42 |
biomes-game | github_2023 | ill-inc | typescript | RedisElection.keepalive | private async keepalive(value: string, ttl: number): Promise<boolean> {
if (!this.loadedLua) {
await loadLuaScript(
this.redis.primary,
"election.keepalive",
"election.keepalive.lua"
);
this.loadedLua = true;
}
const result = await (this.redis.primary as any)["elec... | // Passing a TTL of zero will remove the leadership. | https://github.com/ill-inc/biomes-game/blob/14252b95bf9e68495655af40c72750e8e3c44a42/src/server/shared/election/redis.ts#L36-L60 | 14252b95bf9e68495655af40c72750e8e3c44a42 |
biomes-game | github_2023 | ill-inc | typescript | RedisElection.getElectedValue | async getElectedValue(): Promise<string> {
const result = await this.redis.primary.hgetall(this.redisKey);
const keys = Object.keys(result);
if (keys.length === 0) {
return "";
}
return result[keys[0]];
} | // empty if no one is currently elected. | https://github.com/ill-inc/biomes-game/blob/14252b95bf9e68495655af40c72750e8e3c44a42/src/server/shared/election/redis.ts#L68-L75 | 14252b95bf9e68495655af40c72750e8e3c44a42 |
biomes-game | github_2023 | ill-inc | typescript | typeCheck | function typeCheck() {
AssertJSONable(defaultTweakableConfigValues);
} | // eslint-disable-next-line @typescript-eslint/no-unused-vars | https://github.com/ill-inc/biomes-game/blob/14252b95bf9e68495655af40c72750e8e3c44a42/src/server/shared/minigames/ruleset/tweaks.ts#L530-L532 | 14252b95bf9e68495655af40c72750e8e3c44a42 |
biomes-game | github_2023 | ill-inc | typescript | BiomesRedis.createSubscriptionConnection | createSubscriptionConnection() {
return duplicateRedis(this.replica);
} | // cannot be used for other purposes. | https://github.com/ill-inc/biomes-game/blob/14252b95bf9e68495655af40c72750e8e3c44a42/src/server/shared/redis/connection.ts#L367-L369 | 14252b95bf9e68495655af40c72750e8e3c44a42 |
biomes-game | github_2023 | ill-inc | typescript | Replica.localOnlyUpdate | localOnlyUpdate(changes: Change[]) {
if (this.table.apply(changes)) {
this.emit("tick", changes);
}
} | // Use with caution! Permits the local replica to get out of sync. | https://github.com/ill-inc/biomes-game/blob/14252b95bf9e68495655af40c72750e8e3c44a42/src/server/shared/replica/table.ts#L115-L119 | 14252b95bf9e68495655af40c72750e8e3c44a42 |
biomes-game | github_2023 | ill-inc | typescript | expandWeights | function expandWeights(
lastKnownMapping: ShardMapping,
weights: Map<number, number>,
totalShards: number
) {
const expandedWeights = new Map<number, number>();
let totalWeight = 0;
for (let shard = 0; shard < totalShards; ++shard) {
const weight = weights.get(shard) ?? lastKnownMapping.weights?.get(sha... | // Determine the active set of weights by considering the current known, | https://github.com/ill-inc/biomes-game/blob/14252b95bf9e68495655af40c72750e8e3c44a42/src/server/shared/shard_manager/balance.ts#L10-L36 | 14252b95bf9e68495655af40c72750e8e3c44a42 |
biomes-game | github_2023 | ill-inc | typescript | ShardAllocationBuilder.totalWeight | get totalWeight() {
return [...this.weights.values()].reduce((a, b) => a + b, 0);
} | // Total weight of all shards. | https://github.com/ill-inc/biomes-game/blob/14252b95bf9e68495655af40c72750e8e3c44a42/src/server/shared/shard_manager/balance.ts#L62-L64 | 14252b95bf9e68495655af40c72750e8e3c44a42 |
biomes-game | github_2023 | ill-inc | typescript | ShardAllocationBuilder.maybeAllocate | maybeAllocate(nonce: string, shard: number) {
if (this.#shards.delete(shard)) {
this.#allocation.get(nonce).add(shard);
this.#weightByServer.set(
nonce,
this.#weightByServer.get(nonce)! + this.weights.get(shard)!
);
}
} | // Attempt to allocate a shard if free to a given server by nonce. | https://github.com/ill-inc/biomes-game/blob/14252b95bf9e68495655af40c72750e8e3c44a42/src/server/shared/shard_manager/balance.ts#L67-L75 | 14252b95bf9e68495655af40c72750e8e3c44a42 |
biomes-game | github_2023 | ill-inc | typescript | ShardAllocationBuilder.allocate | allocate(nonce: string, shard: number) {
ok(this.#shards.has(shard), "Shard was already allocated");
this.maybeAllocate(nonce, shard);
} | // Allocate a shard to a given server by nonce, fail if not possible. | https://github.com/ill-inc/biomes-game/blob/14252b95bf9e68495655af40c72750e8e3c44a42/src/server/shared/shard_manager/balance.ts#L78-L81 | 14252b95bf9e68495655af40c72750e8e3c44a42 |
biomes-game | github_2023 | ill-inc | typescript | ShardAllocationBuilder.move | move(source: string, target: string, shard: number) {
ok(this.#allocation.get(source).delete(shard), "Shard was not allocated");
this.#weightByServer.set(
source,
this.#weightByServer.get(source)! - this.weights.get(shard)!
);
this.#shards.add(shard);
this.allocate(target, shard);
} | // Move a shard from one server to the other. | https://github.com/ill-inc/biomes-game/blob/14252b95bf9e68495655af40c72750e8e3c44a42/src/server/shared/shard_manager/balance.ts#L84-L92 | 14252b95bf9e68495655af40c72750e8e3c44a42 |
biomes-game | github_2023 | ill-inc | typescript | ShardAllocationBuilder.allocatedShardsFor | allocatedShardsFor(nonce: string): ReadonlySet<number> {
return this.#allocation.get(nonce);
} | // a reference to this it will be updated. | https://github.com/ill-inc/biomes-game/blob/14252b95bf9e68495655af40c72750e8e3c44a42/src/server/shared/shard_manager/balance.ts#L96-L98 | 14252b95bf9e68495655af40c72750e8e3c44a42 |
biomes-game | github_2023 | ill-inc | typescript | ShardAllocationBuilder.allocatedWeightFor | allocatedWeightFor(nonce: string) {
return this.#weightByServer.get(nonce);
} | // Get the allocated weight to a given server. | https://github.com/ill-inc/biomes-game/blob/14252b95bf9e68495655af40c72750e8e3c44a42/src/server/shared/shard_manager/balance.ts#L101-L103 | 14252b95bf9e68495655af40c72750e8e3c44a42 |
biomes-game | github_2023 | ill-inc | typescript | DistributedShardManager.balance | private async balance() {
if (this.config.strategy !== "balanced") {
this.warnNoWeightSupport();
}
const hasLoggedShard = this.held.has(LOGGED_SM_SHARD);
if (hasLoggedShard) {
log.info("ShardId(0,0,0) holder rebalancing", { gaiaGap: true });
} else {
log.info("Distributed rebalanci... | // a server disappears (as only its shards would be reallocated). | https://github.com/ill-inc/biomes-game/blob/14252b95bf9e68495655af40c72750e8e3c44a42/src/server/shared/shard_manager/distributed.ts#L75-L107 | 14252b95bf9e68495655af40c72750e8e3c44a42 |
biomes-game | github_2023 | ill-inc | typescript | BalancerDomain.keepalive | async keepalive(request: KeepaliveRequest) {
let client = this.clients.get(request.nonce);
if (!client) {
if (request.ttlMs <= 0) {
// It was shutdown of a client we didn't know about, ignore.
return;
}
client = new BalancerClientState();
this.clients.set(request.nonce, c... | // Mark a given client as still alive. | https://github.com/ill-inc/biomes-game/blob/14252b95bf9e68495655af40c72750e8e3c44a42/src/server/shared/shard_manager/service.ts#L123-L148 | 14252b95bf9e68495655af40c72750e8e3c44a42 |
biomes-game | github_2023 | ill-inc | typescript | BalancerDomain.gc | private gc() {
for (const [nonce, client] of this.clients) {
if (client.expired) {
this.clients.delete(nonce);
}
}
} | // Remove any expired clients. | https://github.com/ill-inc/biomes-game/blob/14252b95bf9e68495655af40c72750e8e3c44a42/src/server/shared/shard_manager/service.ts#L151-L157 | 14252b95bf9e68495655af40c72750e8e3c44a42 |
biomes-game | github_2023 | ill-inc | typescript | BalancerDomain.balance | private async balance() {
if (!this.mapping) {
// Attempt to fetch an existing mapping.
try {
const encoded = await this.notifier.fetch();
this.mapping = deserializeShardMapping(encoded) ?? emptyMapping();
} catch (error) {
log.warn("Failed to fetch shard mapping, starting ... | // Produce and maybe broadcast a new mapping. | https://github.com/ill-inc/biomes-game/blob/14252b95bf9e68495655af40c72750e8e3c44a42/src/server/shared/shard_manager/service.ts#L160-L190 | 14252b95bf9e68495655af40c72750e8e3c44a42 |
biomes-game | github_2023 | ill-inc | typescript | Document.maybePopulate | maybePopulate(data: T) {
if (this.fetched) {
return;
}
this.data = data;
this.fetched = true;
} | // We gained the data from the backing store, so populate if we didn't have it. | https://github.com/ill-inc/biomes-game/blob/14252b95bf9e68495655af40c72750e8e3c44a42/src/server/shared/storage/copy_on_write.ts#L52-L58 | 14252b95bf9e68495655af40c72750e8e3c44a42 |
biomes-game | github_2023 | ill-inc | typescript | Document.prepare | async prepare(): Promise<void> {
if (this.fetched) {
return;
}
this.data = (await this.backing!.get()).data();
this.fetched = true;
} | // Fetch the document from the backing store if we haven't already. | https://github.com/ill-inc/biomes-game/blob/14252b95bf9e68495655af40c72750e8e3c44a42/src/server/shared/storage/copy_on_write.ts#L83-L89 | 14252b95bf9e68495655af40c72750e8e3c44a42 |
biomes-game | github_2023 | ill-inc | typescript | createUnsafeCopyOnWriteStorage | function createUnsafeCopyOnWriteStorage(
backing: BackingStore
): BiomesStorage.Store {
return new Storage(backing);
} | // Creates a copy on write wrapper over an existing store. Any reads are satisfied from the existing store, | https://github.com/ill-inc/biomes-game/blob/14252b95bf9e68495655af40c72750e8e3c44a42/src/server/shared/storage/copy_on_write.ts#L538-L542 | 14252b95bf9e68495655af40c72750e8e3c44a42 |
biomes-game | github_2023 | ill-inc | typescript | createFilterIndexKey | function createFilterIndexKey(
field: string,
opStr: BiomesStorage.WhereFilterOp
): string {
switch (opStr) {
case "<":
return `${field}<`;
case "<=":
return `${field}<`;
case "==":
return `${field}=`;
case "!=":
return `${field}=`;
case ">=":
return `${field}>`;
... | // Create a filter function for a given document. | https://github.com/ill-inc/biomes-game/blob/14252b95bf9e68495655af40c72750e8e3c44a42/src/server/shared/storage/util.ts#L21-L43 | 14252b95bf9e68495655af40c72750e8e3c44a42 |
biomes-game | github_2023 | ill-inc | typescript | filterMap | const filterMap = (
map: ReadonlyMap<BiomesId, unknown>,
mutable: () => Map<BiomesId, unknown>
) => {
for (const id of map.keys()) {
if (!allIds.has(id)) {
mutable().delete(id);
}
}
}; | // Remove unknown IDs from a given Map or set. | https://github.com/ill-inc/biomes-game/blob/14252b95bf9e68495655af40c72750e8e3c44a42/src/server/shared/triggers/engine.ts#L234-L243 | 14252b95bf9e68495655af40c72750e8e3c44a42 |
biomes-game | github_2023 | ill-inc | typescript | TriggerEngine.process | async process(
id: BiomesId,
executors: RootExecutor[],
events: ReadonlyArray<IdempotentFirehoseEvent>
) {
let result: "success" | unknown;
for (let i = 0; i < CONFIG.triggerTransactionMaxAttempts; ++i) {
result = await this.attempt(id, executors, events);
if (result === "success") {
... | // Tick all triggers for this entity. | https://github.com/ill-inc/biomes-game/blob/14252b95bf9e68495655af40c72750e8e3c44a42/src/server/shared/triggers/engine.ts#L343-L365 | 14252b95bf9e68495655af40c72750e8e3c44a42 |
biomes-game | github_2023 | ill-inc | typescript | FilterContext.filter | filter(changes: LazyChange[]): LazyChange[] {
return compactMap(changes, (change) =>
this.included.has(changedBiomesId(change)) ? change : undefined
);
} | // Like process, but doesn't change inclusion of the current set. | https://github.com/ill-inc/biomes-game/blob/14252b95bf9e68495655af40c72750e8e3c44a42/src/server/shared/world/filter_context.ts#L118-L122 | 14252b95bf9e68495655af40c72750e8e3c44a42 |
biomes-game | github_2023 | ill-inc | typescript | RedisWorldSubscription.mark | private async mark(signal: AbortSignal): Promise<RedisStreamId | undefined> {
while (!signal.aborted) {
try {
const result = await this.redis.primary.xrevrangeBuffer(
ECS_STREAM,
"+",
"-",
"COUNT",
1
);
if (result.length > 0) {
... | // delays. | https://github.com/ill-inc/biomes-game/blob/14252b95bf9e68495655af40c72750e8e3c44a42/src/server/shared/world/redis_subscription.ts#L104-L125 | 14252b95bf9e68495655af40c72750e8e3c44a42 |
biomes-game | github_2023 | ill-inc | typescript | flush | const flush = async () => {
let update: WorldUpdate | undefined;
let batch = buffer.pop();
if (batch.length) {
if (config?.externalFilterContext) {
batch = config.externalFilterContext.filter(batch);
}
if (!update) {
update = { changes: batch };
} el... | // Flush takes the pending changes and processes them through the filter | https://github.com/ill-inc/biomes-game/blob/14252b95bf9e68495655af40c72750e8e3c44a42/src/server/shared/world/hfc/hfc.ts#L183-L201 | 14252b95bf9e68495655af40c72750e8e3c44a42 |
biomes-game | github_2023 | ill-inc | typescript | HybridWorldApi.subscribe | async *subscribe(
config?: SubscriptionConfig | undefined,
inputSignal?: AbortSignal | undefined
): AsyncIterable<WorldUpdate> {
const buffer = new LazyChangeBuffer();
const bufferChanged = new ConditionVariable();
const controller = new BackgroundTaskController().chain(inputSignal);
// Record... | // Merged subscription from both. | https://github.com/ill-inc/biomes-game/blob/14252b95bf9e68495655af40c72750e8e3c44a42/src/server/shared/world/hfc/hybrid.ts#L39-L162 | 14252b95bf9e68495655af40c72750e8e3c44a42 |
biomes-game | github_2023 | ill-inc | typescript | HybridWorldApi._apply | protected async _apply(
changesToApply: ChangeToApply[]
): Promise<{ outcomes: ApplyStatus[]; changes: LazyChange[] }> {
const result = await this.rc.apply(changesToApply);
// After the main apply is done, make a best effort attempt to propagate any
// deletes here to the HFC instance. This is not bl... | // This will be removed to be a boolean in https://github.com/ill-inc/biomes/pull/12063 | https://github.com/ill-inc/biomes-game/blob/14252b95bf9e68495655af40c72750e8e3c44a42/src/server/shared/world/hfc/hybrid.ts#L188-L222 | 14252b95bf9e68495655af40c72750e8e3c44a42 |
biomes-game | github_2023 | ill-inc | typescript | FilterContext.processChange | private processChange(
change: Readonly<Change>
): Readonly<Change> | undefined {
if (change.kind === "delete") {
this.filtered.delete(change.id);
return change;
}
const [version, entity] = this.world.getWithVersion(change.entity.id)!;
if (!entity) {
return change;
}
if... | // Returns undefined if the change is to be filtered. | https://github.com/ill-inc/biomes-game/blob/14252b95bf9e68495655af40c72750e8e3c44a42/src/server/shared/world/shim/subscription.ts#L49-L77 | 14252b95bf9e68495655af40c72750e8e3c44a42 |
biomes-game | github_2023 | ill-inc | typescript | defaultZrpcBackoffConfig | function defaultZrpcBackoffConfig(): BackoffConfig {
return {
baseMs: 25,
maxMs: 500,
timeoutMs: 10000,
};
} | // More aggressive than the usual stuff as we're talking about inter-server. | https://github.com/ill-inc/biomes-game/blob/14252b95bf9e68495655af40c72750e8e3c44a42/src/server/shared/zrpc/retries.ts#L15-L21 | 14252b95bf9e68495655af40c72750e8e3c44a42 |
biomes-game | github_2023 | ill-inc | typescript | ActiveWebSocketClient.onOpen | onOpen() {} | // to close, no errors. | https://github.com/ill-inc/biomes-game/blob/14252b95bf9e68495655af40c72750e8e3c44a42/src/server/shared/zrpc/websocket/active_client.ts#L274-L274 | 14252b95bf9e68495655af40c72750e8e3c44a42 |
biomes-game | github_2023 | ill-inc | typescript | ActiveWebSocketClient.onMessage | onMessage(message: ArrayBuffer, _isBinary: boolean) {
const onError = (error: unknown) => {
log.error(`${this.id} unexpected error, terminating`, { error });
this.close(grpc.status.INTERNAL, "Internal error.");
};
try {
const validated = validateClientMessage(
Buffer.from(message)... | // and will be neutered. | https://github.com/ill-inc/biomes-game/blob/14252b95bf9e68495655af40c72750e8e3c44a42/src/server/shared/zrpc/websocket/active_client.ts#L369-L392 | 14252b95bf9e68495655af40c72750e8e3c44a42 |
biomes-game | github_2023 | ill-inc | typescript | ActiveWebSocketClient.onDrain | onDrain() {
this.spaceAvailable.signal();
} | // backpressure throttling. | https://github.com/ill-inc/biomes-game/blob/14252b95bf9e68495655af40c72750e8e3c44a42/src/server/shared/zrpc/websocket/active_client.ts#L397-L399 | 14252b95bf9e68495655af40c72750e8e3c44a42 |
biomes-game | github_2023 | ill-inc | typescript | ActiveWebSocketClient.onClose | onClose(code: number, message: string) {
this.ws = undefined;
this.close(code, message);
} | // this WebSocket from within here, it is closed. | https://github.com/ill-inc/biomes-game/blob/14252b95bf9e68495655af40c72750e8e3c44a42/src/server/shared/zrpc/websocket/active_client.ts#L404-L407 | 14252b95bf9e68495655af40c72750e8e3c44a42 |
biomes-game | github_2023 | ill-inc | typescript | WebSocketCall.write | async write(response: any) {
if (!this.controller.aborted) {
return this.conn.sendData([this.reqId, prepare(response)]);
}
} | // Write a response, can be called many times for streaming responses. | https://github.com/ill-inc/biomes-game/blob/14252b95bf9e68495655af40c72750e8e3c44a42/src/server/shared/zrpc/websocket/call.ts#L56-L60 | 14252b95bf9e68495655af40c72750e8e3c44a42 |
biomes-game | github_2023 | ill-inc | typescript | WebSocketCall.status | async status(status: grpc.status, details?: string) {
if (this.controller.aborted) {
return;
}
this.controller.abort();
try {
await this.conn.sendData([this.reqId, status, details ?? ""]);
} catch (error) {
if (grpc.isStatusObject(error) && error.code === grpc.status.CANCELLED) {
... | // Send a status code, this terminates the call. | https://github.com/ill-inc/biomes-game/blob/14252b95bf9e68495655af40c72750e8e3c44a42/src/server/shared/zrpc/websocket/call.ts#L63-L82 | 14252b95bf9e68495655af40c72750e8e3c44a42 |
biomes-game | github_2023 | ill-inc | typescript | WebSocketCall.run | async run(path: string, handler?: WebSocketCallHandler) {
try {
if (handler === undefined || !isFunction(handler)) {
throw new RpcError(grpc.status.UNIMPLEMENTED);
}
if (this.controller.aborted) {
return;
}
this.inflight = handler(this);
await this.inflight;
... | // appropriate counters. | https://github.com/ill-inc/biomes-game/blob/14252b95bf9e68495655af40c72750e8e3c44a42/src/server/shared/zrpc/websocket/call.ts#L100-L119 | 14252b95bf9e68495655af40c72750e8e3c44a42 |
biomes-game | github_2023 | ill-inc | typescript | ComponentImpliesEntityCreationSideEffect.preApply | preApply(changes: Change[]) {
for (const change of changes) {
if (change.kind === "delete" || change.entity.iced) {
// Handled by the `deletes_with` side effect added to the implied
// entity.
continue;
}
// Check if required component are being removed or updated.
f... | // access the full entity before it's deleted. | https://github.com/ill-inc/biomes-game/blob/14252b95bf9e68495655af40c72750e8e3c44a42/src/server/sidefx/effects/component_implies_entity_creation.ts#L62-L106 | 14252b95bf9e68495655af40c72750e8e3c44a42 |
biomes-game | github_2023 | ill-inc | typescript | diffEntity | function diffEntity(
a: ReadonlyEntity,
b: Omit<ReadonlyEntity, "id">
): AsDelta<ReadonlyEntity> | undefined {
let delta: AsDelta<ReadonlyEntity> | undefined;
for (const [componentNameStr, componentValue] of Object.entries(b)) {
const componentName = componentNameStr as ComponentName;
if (!isEqual(comp... | // Returns an entity delta where if any value of b differs from any value of a, | https://github.com/ill-inc/biomes-game/blob/14252b95bf9e68495655af40c72750e8e3c44a42/src/server/sidefx/effects/component_implies_entity_creation.ts#L244-L260 | 14252b95bf9e68495655af40c72750e8e3c44a42 |
biomes-game | github_2023 | ill-inc | typescript | denormalizeAcl | function denormalizeAcl(
table: SideFxTable,
entity: EntityWithOnly<never, "created_by">,
acl: ReadonlyAcl
) {
const player = findPlayerCreatorParent(table, entity.id);
const aclComponent = AclComponent.clone({ acl });
// Owner unconditionally has full access.
// TODO: Use side-effect server to update de... | // Todo: remove this once it's automatic. | https://github.com/ill-inc/biomes-game/blob/14252b95bf9e68495655af40c72750e8e3c44a42/src/server/sidefx/effects/project_protection.ts#L77-L95 | 14252b95bf9e68495655af40c72750e8e3c44a42 |
biomes-game | github_2023 | ill-inc | typescript | createProjectedProtectionEntity | function createProjectedProtectionEntity(
table: SideFxTable,
projector: Projector
): Omit<ReadonlyEntity, "id"> | undefined {
if (!projector.projects_protection.protection) {
return;
}
const acl = projector.projects_protection.protection.acl;
return {
protection: Protection.create({
timestamp... | // Make it so protection projecting entities always have an associated child | https://github.com/ill-inc/biomes-game/blob/14252b95bf9e68495655af40c72750e8e3c44a42/src/server/sidefx/effects/project_protection.ts#L99-L114 | 14252b95bf9e68495655af40c72750e8e3c44a42 |
biomes-game | github_2023 | ill-inc | typescript | shuffle | function shuffle<T>(array: T[]) {
for (let i = array.length - 1; i >= 0; --i) {
const randomIndex = Math.floor(Math.random() * (i + 1));
[array[i], array[randomIndex]] = [array[randomIndex], array[i]];
}
} | // Shuffle an array into a random order in place. | https://github.com/ill-inc/biomes-game/blob/14252b95bf9e68495655af40c72750e8e3c44a42/src/server/spawn/npc_spawn_context_builder.ts#L21-L26 | 14252b95bf9e68495655af40c72750e8e3c44a42 |
biomes-game | github_2023 | ill-inc | typescript | shuffled | function shuffled<T>(array: T[]) {
const copy = [...array];
shuffle(copy);
return copy;
} | // Returns a shuffled version of the input array. | https://github.com/ill-inc/biomes-game/blob/14252b95bf9e68495655af40c72750e8e3c44a42/src/server/spawn/npc_spawn_context_builder.ts#L29-L33 | 14252b95bf9e68495655af40c72750e8e3c44a42 |
biomes-game | github_2023 | ill-inc | typescript | TerrainUpdateQueue.next | next(): TerrainColumn | undefined {
// Return newly added terrain first.
if (this.newTerrainQueue.size > 0) {
const next = this.newTerrainQueue.keys().next().value;
this.newTerrainQueue.delete(next);
return next;
}
if (this.terrain.size == 0) {
return;
}
// Now return e... | // referenced first. | https://github.com/ill-inc/biomes-game/blob/14252b95bf9e68495655af40c72750e8e3c44a42/src/server/spawn/npc_spawn_context_builder.ts#L62-L81 | 14252b95bf9e68495655af40c72750e8e3c44a42 |
biomes-game | github_2023 | ill-inc | typescript | CandidateSpawnPointSampler.setCount | setCount(shardId: ShardId, count: number) {
this._total += count - (this.countByShard.get(shardId) ?? 0);
if (count === 0) {
this.countByShard.delete(shardId);
} else {
this.countByShard.set(shardId, count);
}
} | // Adjusts the number of candidate spawn points in a particular shard. | https://github.com/ill-inc/biomes-game/blob/14252b95bf9e68495655af40c72750e8e3c44a42/src/server/spawn/npc_spawn_context_builder.ts#L89-L96 | 14252b95bf9e68495655af40c72750e8e3c44a42 |
biomes-game | github_2023 | ill-inc | typescript | Observer.maybePurgeVersionMap | private maybePurgeVersionMap() {
if (this.versionMap.size <= CONFIG.syncVersionMapMaxSize) {
return;
}
// Purge the version map down to half its size.
// But ensure it can fit the current resident set.
const targetPurgedSize = Math.max(
CONFIG.syncVersionMapMaxSize / 2,
this.resid... | // in place and also pushing the delete changes to this.TickChangeBuffer. | https://github.com/ill-inc/biomes-game/blob/14252b95bf9e68495655af40c72750e8e3c44a42/src/server/sync/subscription/game_observer.ts#L573-L601 | 14252b95bf9e68495655af40c72750e8e3c44a42 |
biomes-game | github_2023 | ill-inc | typescript | Observer.purgeUnknownEntities | private purgeUnknownEntities() {
const purgeChanges: Delete[] = [];
for (const [id, clientVersion] of this.versionMap) {
if (id === this.requiredId) {
continue;
}
if (!this.context.syncIndex.has(id)) {
this.versionMap.delete(id);
purgeChanges.push({ kind: "delete", tick... | // Remove anything that we don't know about. | https://github.com/ill-inc/biomes-game/blob/14252b95bf9e68495655af40c72750e8e3c44a42/src/server/sync/subscription/game_observer.ts#L604-L617 | 14252b95bf9e68495655af40c72750e8e3c44a42 |
biomes-game | github_2023 | ill-inc | typescript | ExpirySet.peek | peek(): Expiry | undefined {
this.cleanIfNeeded();
return this.triggers[0];
} | // Get the earliest trigger, or undefined if empty. | https://github.com/ill-inc/biomes-game/blob/14252b95bf9e68495655af40c72750e8e3c44a42/src/server/trigger/expiry.ts#L85-L88 | 14252b95bf9e68495655af40c72750e8e3c44a42 |
biomes-game | github_2023 | ill-inc | typescript | ExpirySet.pop | pop(): Expiry {
ok(this.triggers.length > 0);
this.cleanIfNeeded();
return this.triggers.shift()!;
} | // Pop and return the earliest trigger. | https://github.com/ill-inc/biomes-game/blob/14252b95bf9e68495655af40c72750e8e3c44a42/src/server/trigger/expiry.ts#L91-L95 | 14252b95bf9e68495655af40c72750e8e3c44a42 |
biomes-game | github_2023 | ill-inc | typescript | ExpirySet.clear | clear() {
this.triggers.length = 0;
this.dirty = false;
} | // Clear the set. | https://github.com/ill-inc/biomes-game/blob/14252b95bf9e68495655af40c72750e8e3c44a42/src/server/trigger/expiry.ts#L98-L101 | 14252b95bf9e68495655af40c72750e8e3c44a42 |
biomes-game | github_2023 | ill-inc | typescript | ExpirySet.push | push(...expiries: Expiry[]) {
this.triggers.push(...expiries);
this.dirty = this.triggers.length > 1;
} | // Push new items into the set. | https://github.com/ill-inc/biomes-game/blob/14252b95bf9e68495655af40c72750e8e3c44a42/src/server/trigger/expiry.ts#L104-L107 | 14252b95bf9e68495655af40c72750e8e3c44a42 |
biomes-game | github_2023 | ill-inc | typescript | ExpirySet.remove | remove(triggers: Expiry[]) {
if (triggers.length === 0) {
return;
}
const asSet = new Set(triggers);
remove(this.triggers, (trigger) => asSet.has(trigger));
} | // Remove a given array of triggers. | https://github.com/ill-inc/biomes-game/blob/14252b95bf9e68495655af40c72750e8e3c44a42/src/server/trigger/expiry.ts#L110-L116 | 14252b95bf9e68495655af40c72750e8e3c44a42 |
biomes-game | github_2023 | ill-inc | typescript | ExpirySet.removeById | removeById(id: BiomesId) {
remove(this.triggers, (trigger) => trigger.id === id);
} | // Remove triggers with a given entity ID. | https://github.com/ill-inc/biomes-game/blob/14252b95bf9e68495655af40c72750e8e3c44a42/src/server/trigger/expiry.ts#L119-L121 | 14252b95bf9e68495655af40c72750e8e3c44a42 |
biomes-game | github_2023 | ill-inc | typescript | ExpirySet.removeByType | removeByType(type: Expiry["type"]): Expiry[] {
return remove(this.triggers, (trigger) => trigger.type === type);
} | // Remove triggers with a type, return those removed. | https://github.com/ill-inc/biomes-game/blob/14252b95bf9e68495655af40c72750e8e3c44a42/src/server/trigger/expiry.ts#L124-L126 | 14252b95bf9e68495655af40c72750e8e3c44a42 |
biomes-game | github_2023 | ill-inc | typescript | ExpirySet.updateWhen | updateWhen(type: Expiry["type"], when: number): boolean {
const trigger = this.triggers.find((trigger) => trigger.type === type);
if (trigger) {
trigger.when = when;
this.dirty = true;
return true;
}
return false;
} | // Update the timestamp of an existing trigger, returning true if successful. | https://github.com/ill-inc/biomes-game/blob/14252b95bf9e68495655af40c72750e8e3c44a42/src/server/trigger/expiry.ts#L129-L137 | 14252b95bf9e68495655af40c72750e8e3c44a42 |
biomes-game | github_2023 | ill-inc | typescript | BigQueryConnection.getTable | getTable(config: TableConfig): TableConnection {
if (!this.bigQuery) {
throw Error("There was an error initializing the BigTable connection.");
}
const { datasetName, tableName } = config;
const tableKey = `${datasetName}.${tableName}`;
const existingTable = this.tables.get(tableKey);
if... | // can re-request the same table each time without re-initializing it. | https://github.com/ill-inc/biomes-game/blob/14252b95bf9e68495655af40c72750e8e3c44a42/src/server/web/bigquery.ts#L125-L142 | 14252b95bf9e68495655af40c72750e8e3c44a42 |
biomes-game | github_2023 | ill-inc | typescript | BigQueryConnection.stop | async stop() {
this.bigQuery = undefined;
const tablePromises = [...this.tables.values()].map((table) =>
table.stop()
);
this.tables.clear();
await Promise.all(tablePromises);
} | // flushed. | https://github.com/ill-inc/biomes-game/blob/14252b95bf9e68495655af40c72750e8e3c44a42/src/server/web/bigquery.ts#L146-L153 | 14252b95bf9e68495655af40c72750e8e3c44a42 |
biomes-game | github_2023 | ill-inc | typescript | SourceMapCache.stop | stop() {
this.lru.clear();
} | // Cleans up the cached SourceMapConsumer objects. | https://github.com/ill-inc/biomes-game/blob/14252b95bf9e68495655af40c72750e8e3c44a42/src/server/web/source_maps.ts#L51-L53 | 14252b95bf9e68495655af40c72750e8e3c44a42 |
biomes-game | github_2023 | ill-inc | typescript | fetchSourceMapForSourceUrl | async function fetchSourceMapForSourceUrl(sourceUrl: string): Promise<string> {
const bucket = cloud_storage.getStorageBucketInstance("biomes-source-maps");
if (!bucket) {
return "";
}
const pathStart = sourceUrl.indexOf("_next/");
const sourcePath =
pathStart == -1
? `_next/static/chunks/${so... | // Based on the URL of the original source file, find a GCS bucket path for | https://github.com/ill-inc/biomes-game/blob/14252b95bf9e68495655af40c72750e8e3c44a42/src/server/web/source_maps.ts#L58-L72 | 14252b95bf9e68495655af40c72750e8e3c44a42 |
biomes-game | github_2023 | ill-inc | typescript | logContextMiddleware | function logContextMiddleware<
RT extends WebServerApiRequest = WebServerApiRequest,
RS extends NextApiResponse = NextApiResponse
>(handler: (req: RT, res: RS) => Promise<void>) {
return async (req: RT, res: RS) => {
let path = "[unknown]";
if (req.url) {
const baseURL = "http://" + (req.headers.hos... | // Do not use, use biomesAPIHandler | https://github.com/ill-inc/biomes-game/blob/14252b95bf9e68495655af40c72750e8e3c44a42/src/server/web/util/api_middleware.ts#L24-L39 | 14252b95bf9e68495655af40c72750e8e3c44a42 |
biomes-game | github_2023 | ill-inc | typescript | authOptionalAPIMiddleware | function authOptionalAPIMiddleware<
RT extends WebServerApiRequest = WebServerApiRequest,
RS extends NextApiResponse = NextApiResponse
>(
handler: (req: MaybeAuthedAPIRequest<RT>, res: RS) => Promise<void>
): (req: RT, res: RS) => Promise<void> {
return async (req: RT, res: RS) => {
const token = await veri... | // Do not use, use biomesAPIHandler | https://github.com/ill-inc/biomes-game/blob/14252b95bf9e68495655af40c72750e8e3c44a42/src/server/web/util/api_middleware.ts#L51-L73 | 14252b95bf9e68495655af40c72750e8e3c44a42 |
biomes-game | github_2023 | ill-inc | typescript | RegistryBuilder.loadEarly | loadEarly<Key extends keyof Context>(key: Key): RegistryBuilder<Context> {
this.keysToLoadFirst.push(key);
return this;
} | // dependencies as it will also pull them earlier. | https://github.com/ill-inc/biomes-game/blob/14252b95bf9e68495655af40c72750e8e3c44a42/src/shared/registry.ts#L176-L179 | 14252b95bf9e68495655af40c72750e8e3c44a42 |
biomes-game | github_2023 | ill-inc | typescript | LazyBiscuit.getUnpreparedBiscuit | getUnpreparedBiscuit() {
if (!this.deserialized) {
this.deserialized = zrpcWebDeserialize(this.serialized, zBiscuit);
}
return this.deserialized;
} | // the fallback for correct behaviour. | https://github.com/ill-inc/biomes-game/blob/14252b95bf9e68495655af40c72750e8e3c44a42/src/shared/bikkie/active.ts#L47-L52 | 14252b95bf9e68495655af40c72750e8e3c44a42 |
biomes-game | github_2023 | ill-inc | typescript | BikkieRuntime.derived | derived<T>(purpose: string, fn: (runtime: BikkieRuntime) => T): () => T {
let current: T | undefined;
let currentEpoch = this.#epoch;
return () => {
if (current === undefined || currentEpoch !== this.#epoch) {
const timer = new Timer();
current = fn(this);
derivedComputeMs.inc(... | // Create a value computed only when the biscuits change. | https://github.com/ill-inc/biomes-game/blob/14252b95bf9e68495655af40c72750e8e3c44a42/src/shared/bikkie/active.ts#L89-L101 | 14252b95bf9e68495655af40c72750e8e3c44a42 |
biomes-game | github_2023 | ill-inc | typescript | BiscuitTray.set | private set(...definitions: BiscuitDefinition[]) {
definitions = definitions.map((d) => this.validateDefinition(d));
// Topologically sort the definitions for addition to ensure any parent
// dependencies are added before their children.
while (definitions.length > 0) {
const startLength = definit... | // Set a given definition, only intended to be used in construction. | https://github.com/ill-inc/biomes-game/blob/14252b95bf9e68495655af40c72750e8e3c44a42/src/shared/bikkie/tray.ts#L263-L287 | 14252b95bf9e68495655af40c72750e8e3c44a42 |
biomes-game | github_2023 | ill-inc | typescript | BiscuitTray.get | get(id: BiomesId): BiscuitDefinition | undefined {
const parent = this.parent?.get(id);
const local = this.definitions.get(id);
if (!local && !parent) {
return;
}
const output = <BiscuitDefinition>{
...parent,
...local,
attributes: {},
};
if (output.extendedFrom) {
... | // Optionally resolve parent definitions. | https://github.com/ill-inc/biomes-game/blob/14252b95bf9e68495655af40c72750e8e3c44a42/src/shared/bikkie/tray.ts#L439-L482 | 14252b95bf9e68495655af40c72750e8e3c44a42 |
biomes-game | github_2023 | ill-inc | typescript | BiscuitTray.definitionExtendedFromOk | private definitionExtendedFromOk(definition: BiscuitDefinition): boolean {
const visited = new Set<BiomesId>();
while (true) {
if (visited.has(definition.id)) {
return false;
}
visited.add(definition.id);
if (definition.extendedFrom) {
const parent = this.get(definition.e... | // Check the extendedFrom field doesn't form a chain. | https://github.com/ill-inc/biomes-game/blob/14252b95bf9e68495655af40c72750e8e3c44a42/src/shared/bikkie/tray.ts#L485-L502 | 14252b95bf9e68495655af40c72750e8e3c44a42 |
biomes-game | github_2023 | ill-inc | typescript | BiscuitTray.prepare | prepare(): Map<BiomesId, PreparedBiscuitDefinition> {
if (this.prepared !== undefined) {
return this.prepared;
}
this.prepared = new Map<BiomesId, PreparedBiscuitDefinition>(
this.parent?.prepare() ?? []
);
for (const id of this.definitions.keys()) {
const definition = this.get(id)... | // biscuit. | https://github.com/ill-inc/biomes-game/blob/14252b95bf9e68495655af40c72750e8e3c44a42/src/shared/bikkie/tray.ts#L558-L584 | 14252b95bf9e68495655af40c72750e8e3c44a42 |
biomes-game | github_2023 | ill-inc | typescript | conformsWith | function conformsWith(
tray: BiscuitTray,
id: BiomesId,
schema: SchemaPathsOf<typeof bikkie>
): boolean {
const definition = tray.get(id);
if (!definition) {
return false;
}
for (const attributeName of definedOrThrow(normalizeToSchema(bikkie, schema))
.attributes) {
const attribute = attribs.b... | // Check if a definition within this tray conforms to the given schema. | https://github.com/ill-inc/biomes-game/blob/14252b95bf9e68495655af40c72750e8e3c44a42/src/shared/bikkie/test/tray.test.ts#L62-L88 | 14252b95bf9e68495655af40c72750e8e3c44a42 |
biomes-game | github_2023 | ill-inc | typescript | LayeredTable.tick | get tick(): number {
return this.delegate.tick;
} | // and delegate tick. | https://github.com/ill-inc/biomes-game/blob/14252b95bf9e68495655af40c72750e8e3c44a42/src/shared/ecs/layered_table.ts#L189-L191 | 14252b95bf9e68495655af40c72750e8e3c44a42 |
biomes-game | github_2023 | ill-inc | typescript | LayeredTable.eagerApplyOnLayer | eagerApplyOnLayer(
layer: Layer | undefined,
change: EagerProposedChange,
options?: Partial<EagerApplyOptions>
): Layer {
if (layer) {
layer.update(change, options);
return layer;
} else {
return this.eagerApply(change, options);
}
} | // a new one. | https://github.com/ill-inc/biomes-game/blob/14252b95bf9e68495655af40c72750e8e3c44a42/src/shared/ecs/layered_table.ts#L432-L443 | 14252b95bf9e68495655af40c72750e8e3c44a42 |
biomes-game | github_2023 | ill-inc | typescript | computeLayerStackChange | function computeLayerStackChange(
baseEntity: ReadonlyEntity | undefined,
entityId: BiomesId,
layers: LayerInternal[],
incomingChange: Readonly<Change> | undefined,
tick: number,
replacements: { src: LayerInternal; dst: LayerInternal | undefined }[],
additions: LayerInternal[]
): LayerStackChange {
let ... | // This function handles all the logic for modifying a set of layers affecting | https://github.com/ill-inc/biomes-game/blob/14252b95bf9e68495655af40c72750e8e3c44a42/src/shared/ecs/layered_table.ts#L544-L639 | 14252b95bf9e68495655af40c72750e8e3c44a42 |
biomes-game | github_2023 | ill-inc | typescript | writeableMetaIndexTable | function writeableMetaIndexTable<T extends {}>(
writeableTable: WriteableTable,
metaIndexTable: T
): WriteableTable & T {
Object.assign(metaIndexTable, {
clear: () => writeableTable.clear(),
load: (id: BiomesId, state: Readonly<EntityState<number>>) =>
writeableTable.load(id, state),
apply: (cha... | // Convenience function to add WriteableTable methods to an object, e.g. to | https://github.com/ill-inc/biomes-game/blob/14252b95bf9e68495655af40c72750e8e3c44a42/src/shared/ecs/table.ts#L520-L531 | 14252b95bf9e68495655af40c72750e8e3c44a42 |
biomes-game | github_2023 | ill-inc | typescript | serializeBigInt | const serializeBigInt = (value: number | bigint): string => {
return String(value);
}; | // ================== | https://github.com/ill-inc/biomes-game/blob/14252b95bf9e68495655af40c72750e8e3c44a42/src/shared/ecs/gen/types.ts#L5276-L5278 | 14252b95bf9e68495655af40c72750e8e3c44a42 |
biomes-game | github_2023 | ill-inc | typescript | BaseSpatialIndex.scanSphere | *scanSphere(
{ center, radius }: ReadonlySphere,
options?: SpatialQueryOptions
) {
if (!isFinite(radius)) {
yield* this.scanAll();
} else if (this.inverse.size < this.totalScanThreshold(radius)) {
const sphereSq = { center, radius: radius ** 2 };
for (const [id, [domain]] of this.inv... | // entities lie in the specified radius. | https://github.com/ill-inc/biomes-game/blob/14252b95bf9e68495655af40c72750e8e3c44a42/src/shared/ecs/spatial/base_spatial_index.ts#L72-L120 | 14252b95bf9e68495655af40c72750e8e3c44a42 |
biomes-game | github_2023 | ill-inc | typescript | SpatialIndex.delete | delete(id: BiomesId) {
super.delete(id);
} | // Make it public for the index API. | https://github.com/ill-inc/biomes-game/blob/14252b95bf9e68495655af40c72750e8e3c44a42/src/shared/ecs/spatial/spatial_index.ts#L25-L27 | 14252b95bf9e68495655af40c72750e8e3c44a42 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.