@utsp/core 0.14.0 → 0.14.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/benchmark.cjs +10 -5
- package/dist/benchmark.d.ts +157 -30
- package/dist/benchmark.mjs +10 -5
- package/dist/index.cjs +10 -5
- package/dist/index.d.ts +210 -55
- package/dist/index.mjs +10 -5
- package/package.json +2 -2
package/dist/benchmark.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import * as _utsp_types from '@utsp/types';
|
|
2
|
-
import { ScalingModeValue, Vector2, AxisSource, ButtonSource, InputBindingLoadPacket, AxisBinding, ButtonBinding, SoundInstanceId, AudioConfigCommand, PlaySoundCommand, StopSoundCommand, FadeOutSoundCommand, PauseSoundCommand, ResumeSoundCommand, SetSoundEffectsCommand, IAudioProcessor, VibrationPattern, GamepadVibrationOptions, GamepadVibrationCommand, IGamepadVibrationProcessor, MobileVibrationCommand, IMobileVibrationProcessor, AudioAck, PostProcessConfig, PostProcessCommand, ScalingMode, GridConfig, SoundFormat, SoundLoadType, SoundLoadPacket, SoundExternalLoadPacket, UserRenderState, RenderState } from '@utsp/types';
|
|
2
|
+
import { ScalingModeValue, Vector2, AxisSource, ButtonSource, InputBindingLoadPacket, AxisBinding, ButtonBinding, TouchZoneBinding, SoundInstanceId, AudioConfigCommand, PlaySoundCommand, StopSoundCommand, FadeOutSoundCommand, PauseSoundCommand, ResumeSoundCommand, SetSoundEffectsCommand, IAudioProcessor, VibrationPattern, GamepadVibrationOptions, GamepadVibrationCommand, IGamepadVibrationProcessor, MobileVibrationCommand, IMobileVibrationProcessor, AudioAck, PostProcessConfig, PostProcessCommand, ScalingMode, GridConfig, SoundFormat, SoundLoadType, SoundLoadPacket, SoundExternalLoadPacket, UserRenderState, RenderState } from '@utsp/types';
|
|
3
3
|
export { Vector2 } from '@utsp/types';
|
|
4
4
|
|
|
5
5
|
/**
|
|
@@ -3905,14 +3905,17 @@ declare class MacroRegistry {
|
|
|
3905
3905
|
*
|
|
3906
3906
|
* Allows to:
|
|
3907
3907
|
* - Define axes and buttons (bindingId → name)
|
|
3908
|
+
* - Define touch zones (virtual screen regions for mobile)
|
|
3908
3909
|
* - Generate a JSON LoadPacket to send to client
|
|
3909
3910
|
* - Decode compressed inputs received from client (future)
|
|
3910
3911
|
*/
|
|
3911
3912
|
declare class InputBindingRegistry {
|
|
3912
3913
|
private axes;
|
|
3913
3914
|
private buttons;
|
|
3915
|
+
private touchZones;
|
|
3914
3916
|
private axisNameToId;
|
|
3915
3917
|
private buttonNameToId;
|
|
3918
|
+
private touchZoneNameToId;
|
|
3916
3919
|
private version;
|
|
3917
3920
|
/**
|
|
3918
3921
|
* Defines an axis binding
|
|
@@ -3956,6 +3959,44 @@ declare class InputBindingRegistry {
|
|
|
3956
3959
|
* ```
|
|
3957
3960
|
*/
|
|
3958
3961
|
defineButton(bindingId: number, name: string, sources?: ButtonSource[], defaultValue?: boolean): void;
|
|
3962
|
+
/**
|
|
3963
|
+
* Defines a touch zone (virtual screen region for mobile touch input)
|
|
3964
|
+
*
|
|
3965
|
+
* Touch zones allow you to define regions of the screen that act as
|
|
3966
|
+
* virtual buttons or joysticks. Each zone has:
|
|
3967
|
+
* - A button state (pressed when any touch is in the zone)
|
|
3968
|
+
* - X/Y axis values (last touch position within the zone, normalized to cell coords)
|
|
3969
|
+
*
|
|
3970
|
+
* @param zoneId - Unique zone ID (0-31)
|
|
3971
|
+
* @param name - Zone name (e.g., "DPadUp", "ButtonA", "LeftJoystick")
|
|
3972
|
+
* @param x - X position in grid cells
|
|
3973
|
+
* @param y - Y position in grid cells
|
|
3974
|
+
* @param width - Width in grid cells
|
|
3975
|
+
* @param height - Height in grid cells
|
|
3976
|
+
* @throws Error if zoneId or name already exists
|
|
3977
|
+
*
|
|
3978
|
+
* @example
|
|
3979
|
+
* ```typescript
|
|
3980
|
+
* // D-pad buttons (bottom-left corner)
|
|
3981
|
+
* registry.defineTouchZone(0, "DPadUp", 2, 16, 4, 4);
|
|
3982
|
+
* registry.defineTouchZone(1, "DPadDown", 2, 24, 4, 4);
|
|
3983
|
+
* registry.defineTouchZone(2, "DPadLeft", 0, 20, 4, 4);
|
|
3984
|
+
* registry.defineTouchZone(3, "DPadRight", 6, 20, 4, 4);
|
|
3985
|
+
*
|
|
3986
|
+
* // Action button (bottom-right)
|
|
3987
|
+
* registry.defineTouchZone(4, "ButtonA", 74, 20, 6, 6);
|
|
3988
|
+
*
|
|
3989
|
+
* // Virtual joystick (large touch area)
|
|
3990
|
+
* registry.defineTouchZone(10, "LeftJoystick", 0, 12, 20, 16);
|
|
3991
|
+
*
|
|
3992
|
+
* // Then bind them in button/axis sources:
|
|
3993
|
+
* registry.defineButton(0, "Up", [
|
|
3994
|
+
* { sourceId: 0, type: InputDeviceType.Keyboard, key: KeyboardInput.ArrowUp },
|
|
3995
|
+
* { sourceId: 100, type: InputDeviceType.TouchZone, touchZoneId: 0 },
|
|
3996
|
+
* ]);
|
|
3997
|
+
* ```
|
|
3998
|
+
*/
|
|
3999
|
+
defineTouchZone(zoneId: number, name: string, x: number, y: number, width: number, height: number): void;
|
|
3959
4000
|
/**
|
|
3960
4001
|
* Evaluates an axis by summing all its sources
|
|
3961
4002
|
*
|
|
@@ -4106,6 +4147,13 @@ declare class InputBindingRegistry {
|
|
|
4106
4147
|
* @returns true if defined
|
|
4107
4148
|
*/
|
|
4108
4149
|
hasButton(bindingId: number): boolean;
|
|
4150
|
+
/**
|
|
4151
|
+
* Checks if a touch zone is defined
|
|
4152
|
+
*
|
|
4153
|
+
* @param zoneId - Zone ID
|
|
4154
|
+
* @returns true if defined
|
|
4155
|
+
*/
|
|
4156
|
+
hasTouchZone(zoneId: number): boolean;
|
|
4109
4157
|
/**
|
|
4110
4158
|
* Counts the number of defined axes
|
|
4111
4159
|
*
|
|
@@ -4118,6 +4166,12 @@ declare class InputBindingRegistry {
|
|
|
4118
4166
|
* @returns number of buttons
|
|
4119
4167
|
*/
|
|
4120
4168
|
getButtonCount(): number;
|
|
4169
|
+
/**
|
|
4170
|
+
* Counts the number of defined touch zones
|
|
4171
|
+
*
|
|
4172
|
+
* @returns number of touch zones
|
|
4173
|
+
*/
|
|
4174
|
+
getTouchZoneCount(): number;
|
|
4121
4175
|
/**
|
|
4122
4176
|
* Retrieves all axes
|
|
4123
4177
|
*
|
|
@@ -4130,6 +4184,26 @@ declare class InputBindingRegistry {
|
|
|
4130
4184
|
* @returns array of all button bindings
|
|
4131
4185
|
*/
|
|
4132
4186
|
getAllButtons(): ButtonBinding[];
|
|
4187
|
+
/**
|
|
4188
|
+
* Retrieves all touch zones
|
|
4189
|
+
*
|
|
4190
|
+
* @returns array of all touch zone bindings
|
|
4191
|
+
*/
|
|
4192
|
+
getAllTouchZones(): TouchZoneBinding[];
|
|
4193
|
+
/**
|
|
4194
|
+
* Retrieves a touch zone by ID
|
|
4195
|
+
*
|
|
4196
|
+
* @param zoneId - Zone ID
|
|
4197
|
+
* @returns zone binding or null if not found
|
|
4198
|
+
*/
|
|
4199
|
+
getTouchZone(zoneId: number): TouchZoneBinding | null;
|
|
4200
|
+
/**
|
|
4201
|
+
* Retrieves a touch zone ID from its name
|
|
4202
|
+
*
|
|
4203
|
+
* @param name - Zone name
|
|
4204
|
+
* @returns zoneId or null if not found
|
|
4205
|
+
*/
|
|
4206
|
+
getTouchZoneId(name: string): number | null;
|
|
4133
4207
|
/**
|
|
4134
4208
|
* Retrieves the current binding version
|
|
4135
4209
|
*
|
|
@@ -4150,6 +4224,13 @@ declare class InputBindingRegistry {
|
|
|
4150
4224
|
* @returns true if removed, false if not found
|
|
4151
4225
|
*/
|
|
4152
4226
|
removeButton(bindingId: number): boolean;
|
|
4227
|
+
/**
|
|
4228
|
+
* Removes a touch zone
|
|
4229
|
+
*
|
|
4230
|
+
* @param zoneId - Zone ID to remove
|
|
4231
|
+
* @returns true if removed, false if not found
|
|
4232
|
+
*/
|
|
4233
|
+
removeTouchZone(zoneId: number): boolean;
|
|
4153
4234
|
/**
|
|
4154
4235
|
* Removes all axes
|
|
4155
4236
|
*/
|
|
@@ -4158,6 +4239,10 @@ declare class InputBindingRegistry {
|
|
|
4158
4239
|
* Removes all buttons
|
|
4159
4240
|
*/
|
|
4160
4241
|
clearButtons(): void;
|
|
4242
|
+
/**
|
|
4243
|
+
* Removes all touch zones
|
|
4244
|
+
*/
|
|
4245
|
+
clearTouchZones(): void;
|
|
4161
4246
|
/**
|
|
4162
4247
|
* Completely resets the registry
|
|
4163
4248
|
*/
|
|
@@ -5726,6 +5811,40 @@ declare class User<TData = Record<string, any>> {
|
|
|
5726
5811
|
* Get the number of sounds currently playing on the client
|
|
5727
5812
|
*/
|
|
5728
5813
|
getPlayingSoundCount(): number;
|
|
5814
|
+
/**
|
|
5815
|
+
* Get audio loading state for this client
|
|
5816
|
+
*
|
|
5817
|
+
* Provides a summary of the client's audio loading progress,
|
|
5818
|
+
* useful for showing loading screens or progress bars.
|
|
5819
|
+
*
|
|
5820
|
+
* @param totalExpected - Total number of sounds expected (from SoundRegistry)
|
|
5821
|
+
* @returns Audio loading state
|
|
5822
|
+
*
|
|
5823
|
+
* @example
|
|
5824
|
+
* ```typescript
|
|
5825
|
+
* updateUser(core: Core, user: User): void {
|
|
5826
|
+
* const totalSounds = core.getSoundRegistry().getAll().length;
|
|
5827
|
+
* const audioState = user.getAudioLoadingState(totalSounds);
|
|
5828
|
+
*
|
|
5829
|
+
* if (!audioState.isComplete) {
|
|
5830
|
+
* // Client still loading sounds
|
|
5831
|
+
* console.log(`Loading: ${audioState.loadedCount}/${audioState.totalExpected}`);
|
|
5832
|
+
* }
|
|
5833
|
+
* }
|
|
5834
|
+
* ```
|
|
5835
|
+
*/
|
|
5836
|
+
getAudioLoadingState(totalExpected: number): {
|
|
5837
|
+
/** Number of sounds successfully loaded on client */
|
|
5838
|
+
loadedCount: number;
|
|
5839
|
+
/** Total number of sounds expected */
|
|
5840
|
+
totalExpected: number;
|
|
5841
|
+
/** Number of sounds that failed to load */
|
|
5842
|
+
errorCount: number;
|
|
5843
|
+
/** Whether all expected sounds are loaded */
|
|
5844
|
+
isComplete: boolean;
|
|
5845
|
+
/** Names of sounds that failed to load */
|
|
5846
|
+
errors: string[];
|
|
5847
|
+
};
|
|
5729
5848
|
/**
|
|
5730
5849
|
* Load a macro template
|
|
5731
5850
|
* The template will be sent to the client in the next config packet
|
|
@@ -7265,38 +7384,22 @@ declare class Core {
|
|
|
7265
7384
|
*
|
|
7266
7385
|
* This method:
|
|
7267
7386
|
* 1. Encodes displays and layers of each user into binary packets
|
|
7268
|
-
* 2.
|
|
7269
|
-
* 3.
|
|
7270
|
-
*
|
|
7271
|
-
*
|
|
7272
|
-
*
|
|
7273
|
-
* @returns Map<userId, packet> - Encoded packets for each user
|
|
7274
|
-
*
|
|
7275
|
-
* @example
|
|
7276
|
-
* ```typescript
|
|
7277
|
-
* const packets = engine.endTick();
|
|
7278
|
-
* packets.forEach((packet, userId) => {
|
|
7279
|
-
* networkSend(userId, packet);
|
|
7280
|
-
* });
|
|
7281
|
-
* ```
|
|
7282
|
-
*/
|
|
7283
|
-
endTick(): Map<string, Uint8Array>;
|
|
7284
|
-
/**
|
|
7285
|
-
* Ends tick and generates SEPARATE packets for static and dynamic layers
|
|
7286
|
-
*
|
|
7287
|
-
* This method allows sending:
|
|
7288
|
-
* - STATIC Layers on a reliable Socket.IO channel (guaranteed delivery)
|
|
7289
|
-
* - DYNAMIC Layers on a volatile Socket.IO channel (can drop packets)
|
|
7387
|
+
* 2. Only sends layers that have called commit() (optimization)
|
|
7388
|
+
* 3. Separates static and dynamic layers for network optimization
|
|
7389
|
+
* 4. Increments tick counter
|
|
7390
|
+
* 5. Returns a Map with split packets ready to send
|
|
7290
7391
|
*
|
|
7291
|
-
*
|
|
7292
|
-
*
|
|
7392
|
+
* Network strategy:
|
|
7393
|
+
* - STATIC Layers → Reliable channel (guaranteed delivery)
|
|
7394
|
+
* - DYNAMIC Layers → Volatile channel (can drop packets for performance)
|
|
7395
|
+
* - Audio/Vibration/Macro/PostProcess orders → Only in dynamic packet
|
|
7293
7396
|
*
|
|
7294
7397
|
* @returns Map<userId, { static: Uint8Array | null, dynamic: Uint8Array | null }>
|
|
7295
7398
|
*
|
|
7296
7399
|
* @example
|
|
7297
7400
|
* ```typescript
|
|
7298
|
-
* const
|
|
7299
|
-
*
|
|
7401
|
+
* const packets = engine.endTick();
|
|
7402
|
+
* packets.forEach(({ static: staticPacket, dynamic: dynamicPacket }, userId) => {
|
|
7300
7403
|
* if (staticPacket) {
|
|
7301
7404
|
* network.sendToClient(userId, 'update-static', staticPacket); // Reliable
|
|
7302
7405
|
* }
|
|
@@ -7306,7 +7409,7 @@ declare class Core {
|
|
|
7306
7409
|
* });
|
|
7307
7410
|
* ```
|
|
7308
7411
|
*/
|
|
7309
|
-
|
|
7412
|
+
endTick(): Map<string, {
|
|
7310
7413
|
static: Uint8Array | null;
|
|
7311
7414
|
dynamic: Uint8Array | null;
|
|
7312
7415
|
}>;
|
|
@@ -7589,6 +7692,25 @@ declare class Core {
|
|
|
7589
7692
|
* @returns Array of encoded MacroLoad packets
|
|
7590
7693
|
*/
|
|
7591
7694
|
generateMacroLoadPackets(userId: string): Uint8Array[];
|
|
7695
|
+
/**
|
|
7696
|
+
* Generates an initial update packet for a specific user (SERVER-SIDE)
|
|
7697
|
+
*
|
|
7698
|
+
* This is used to send any pending PostProcessCommands (like switchPalette)
|
|
7699
|
+
* that were created during initUser() but before the first regular tick.
|
|
7700
|
+
*
|
|
7701
|
+
* @param userId - Target user ID
|
|
7702
|
+
* @returns Encoded update packet, or null if no pending commands
|
|
7703
|
+
*
|
|
7704
|
+
* @example
|
|
7705
|
+
* ```typescript
|
|
7706
|
+
* // Server side - after initUser and load packets
|
|
7707
|
+
* const initialPacket = core.generateInitialUpdatePacket(clientId);
|
|
7708
|
+
* if (initialPacket) {
|
|
7709
|
+
* socket.emit('update', initialPacket);
|
|
7710
|
+
* }
|
|
7711
|
+
* ```
|
|
7712
|
+
*/
|
|
7713
|
+
generateInitialUpdatePacket(userId: string): Uint8Array | null;
|
|
7592
7714
|
/**
|
|
7593
7715
|
* Applies Input Bindings to a user (CLIENT-SIDE)
|
|
7594
7716
|
*
|
|
@@ -8763,14 +8885,19 @@ declare class Layer {
|
|
|
8763
8885
|
* ```
|
|
8764
8886
|
*/
|
|
8765
8887
|
commit(): void;
|
|
8888
|
+
/**
|
|
8889
|
+
* Returns a breakdown of order types for debugging
|
|
8890
|
+
* @internal
|
|
8891
|
+
*/
|
|
8892
|
+
private getOrdersBreakdown;
|
|
8766
8893
|
/**
|
|
8767
8894
|
* Checks if layer needs to be sent
|
|
8768
|
-
* @internal - Used by Core.
|
|
8895
|
+
* @internal - Used by Core.endTick()
|
|
8769
8896
|
*/
|
|
8770
8897
|
getNeedsCommit(): boolean;
|
|
8771
8898
|
/**
|
|
8772
8899
|
* Resets commit flag after sending
|
|
8773
|
-
* @internal - Used by Core.
|
|
8900
|
+
* @internal - Used by Core.endTick()
|
|
8774
8901
|
*/
|
|
8775
8902
|
resetCommit(): void;
|
|
8776
8903
|
}
|