Skip to content

Commit

Permalink
refactor observables. (#928)
Browse files Browse the repository at this point in the history
* refactor observables: use systems & components instead of sendBatch events

* add realminfo & playerclicked component

* add missing observables

* add fallback to sdk6 obserables pollEvents

* add missing comms

* replace player clicked with ponterevents

* fix build

* add tests

* remove non used code

* update protocol version

* add fallback support because renderer release
  • Loading branch information
gonpombo8 authored Apr 24, 2024
1 parent 3236fa6 commit 6d2ec97
Show file tree
Hide file tree
Showing 10 changed files with 235 additions and 578 deletions.
14 changes: 7 additions & 7 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"bugs": "https://github.com/decentraland/js-sdk-toolchain/issues",
"dependencies": {
"@actions/core": "^1.10.0",
"@dcl/protocol": "^1.0.0-8691799990.commit-4ba546c",
"@dcl/protocol": "1.0.0-8758013256.commit-44aab53",
"@dcl/quickjs-emscripten": "^0.21.0-3680274614.commit-1808aa1",
"@dcl/ts-proto": "1.153.0",
"@types/fs-extra": "^9.0.12",
Expand Down
171 changes: 28 additions & 143 deletions packages/@dcl/playground-assets/etc/playground-assets.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -564,6 +564,7 @@ export const componentDefinitionByName: {
"core::PointerLock": LwwComponentGetter<LastWriteWinElementSetComponentDefinition<PBPointerLock>>;
"core::Raycast": LwwComponentGetter<LastWriteWinElementSetComponentDefinition<PBRaycast>>;
"core::RaycastResult": LwwComponentGetter<LastWriteWinElementSetComponentDefinition<PBRaycastResult>>;
"core::RealmInfo": LwwComponentGetter<LastWriteWinElementSetComponentDefinition<PBRealmInfo>>;
"core::TextShape": LwwComponentGetter<LastWriteWinElementSetComponentDefinition<PBTextShape>>;
"core::Tween": LwwComponentGetter<LastWriteWinElementSetComponentDefinition<PBTween>>;
"core::TweenSequence": LwwComponentGetter<LastWriteWinElementSetComponentDefinition<PBTweenSequence>>;
Expand Down Expand Up @@ -982,12 +983,6 @@ export function Engine(options?: IEngineOptions): IEngine;
// @public
export const engine: IEngine;

// @public (undocumented)
export type EngineEvent<T extends IEventNames = IEventNames, V = IEvents[T]> = {
type: T;
data: Readonly<V>;
};

// @public (undocumented)
export const EngineInfo: LastWriteWinElementSetComponentDefinition<PBEngineInfo>;

Expand Down Expand Up @@ -1097,24 +1092,6 @@ export function getComponentEntityTree<T>(engine: Pick<IEngine, 'getEntitiesWith
// @public @deprecated (undocumented)
export function getCompositeRootComponent(engine: IEngine): LastWriteWinElementSetComponentDefinition<CompositeRootType>;

// @public (undocumented)
export type GizmoDragEndEvent = {
type: 'gizmoDragEnded';
transforms: Array<{
position: Vector3Type;
rotation: QuaternionType;
scale: Vector3Type;
entityId: unknown;
}>;
};

// @public (undocumented)
export type GizmoSelectedEvent = {
type: 'gizmoSelected';
gizmoType: 'MOVE' | 'ROTATE' | 'SCALE' | 'NONE';
entities: string[];
};

// Warning: (ae-missing-release-tag) "GlobalDirectionRaycastOptions" is part of the package's API, but it is missing a release tag (@alpha, @beta, @public, or @internal)
//
// @public (undocumented)
Expand All @@ -1127,11 +1104,6 @@ export type GlobalDirectionRaycastSystemOptions = {
direction?: PBVector3;
};

// @public (undocumented)
export type GlobalInputEventResult = InputEventResult & {
type: 0 | 1;
};

// Warning: (ae-missing-release-tag) "GlobalTargetRaycastOptions" is part of the package's API, but it is missing a release tag (@alpha, @beta, @public, or @internal)
//
// @public (undocumented)
Expand Down Expand Up @@ -1219,88 +1191,22 @@ export type IEventNames = keyof IEvents;

// @public
export interface IEvents {
actionButtonEvent: GlobalInputEventResult;
builderSceneStart: unknown;
builderSceneUnloaded: unknown;
cameraModeChanged: {
cameraMode: 0 | 1 | 2;
};
chatMessage: {
id: string;
sender: string;
message: string;
isCommand: boolean;
};
comms: {
sender: string;
message: string;
};
entitiesOutOfBoundaries: {
entities: string[];
};
entityBackInScene: {
entityId: unknown;
};
entityOutOfScene: {
entityId: unknown;
};
// (undocumented)
externalAction: {
type: string;
[key: string]: any;
};
gizmoEvent: GizmoDragEndEvent | GizmoSelectedEvent;
idleStateChanged: {
isIdle: boolean;
};
// (undocumented)
limitsExceeded: {
given: Record<string, number>;
limit: Record<string, number>;
};
// (undocumented)
metricsUpdate: {
given: Record<string, number>;
limit: Record<string, number>;
};
onAnimationEnd: {
clipName: string;
};
onBlur: {
entityId: unknown;
pointerId: number;
};
onChange: {
value?: any;
pointerId?: number;
};
onClick: {
entityId: unknown;
};
onEnter: unknown;
onEnterScene: {
userId: string;
};
onFocus: {
entityId: unknown;
pointerId: number;
};
onLeaveScene: {
userId: string;
};
onPointerLock: {
locked?: boolean;
};
onRealmChanged: {
domain: string;
room: string;
serverName: string;
displayName: string;
};
// (undocumented)
onTextSubmit: {
text: string;
};
playerClicked: {
userId: string;
ray: {
Expand All @@ -1319,37 +1225,11 @@ export interface IEvents {
playerExpression: {
expressionId: string;
};
pointerDown: InputEventResult;
// @deprecated
pointerEvent: GlobalInputEventResult;
pointerHoverEnter: unknown;
pointerHoverExit: unknown;
pointerUp: InputEventResult;
positionChanged: {
position: Vector3Type;
cameraPosition: Vector3Type;
playerHeight: number;
};
profileChanged: {
ethAddress: string;
version: number;
};
raycastResponse: RaycastResponsePayload<any>;
rotationChanged: {
rotation: Vector3Type;
quaternion: QuaternionType;
};
sceneStart: unknown;
// (undocumented)
stateEvent: {
type: string;
payload: any;
};
// (undocumented)
uuidEvent: {
uuid: string;
payload: any;
};
videoEvent: {
componentId: string;
videoClipId: string;
Expand Down Expand Up @@ -1460,21 +1340,6 @@ export const enum InputAction {
IA_WALK = 9
}

// @public (undocumented)
export type InputEventResult = {
origin: Vector3Type;
direction: Vector3Type;
buttonId: number;
hit?: {
length: number;
hitPoint: Vector3Type;
meshName: string;
normal: Vector3Type;
worldNormal: Vector3Type;
entityId: unknown;
};
};

// @public
export const inputSystem: IInputSystem;

Expand Down Expand Up @@ -2800,6 +2665,30 @@ export namespace PBRaycastResult {
export function encode(message: PBRaycastResult, writer?: _m0.Writer): _m0.Writer;
}

// @public (undocumented)
export interface PBRealmInfo {
// (undocumented)
baseUrl: string;
// (undocumented)
commsAdapter: string;
// (undocumented)
isPreview: boolean;
// (undocumented)
networkId: number;
// (undocumented)
realmName: string;
// (undocumented)
room?: string | undefined;
}

// @public (undocumented)
export namespace PBRealmInfo {
// (undocumented)
export function decode(input: _m0.Reader | Uint8Array, length?: number): PBRealmInfo;
// (undocumented)
export function encode(message: PBRealmInfo, writer?: _m0.Writer): _m0.Writer;
}

// @public (undocumented)
export interface PBTextShape {
font?: Font | undefined;
Expand Down Expand Up @@ -3464,13 +3353,6 @@ export const enum RaycastQueryType {
RQT_QUERY_ALL = 1
}

// @public (undocumented)
export type RaycastResponsePayload<T> = {
queryId: string;
queryType: string;
payload: T;
};

// @public (undocumented)
export const RaycastResult: LastWriteWinElementSetComponentDefinition<PBRaycastResult>;

Expand Down Expand Up @@ -3566,6 +3448,9 @@ export type ReadOnlyLastWriteWinElementSetComponentDefinition<T> = Omit<LastWrit
// @public (undocumented)
export type ReadonlyPrimitive = number | string | number[] | string[] | boolean | boolean[];

// @public (undocumented)
export const RealmInfo: LastWriteWinElementSetComponentDefinition<PBRealmInfo>;

// @public (undocumented)
export type ReceiveMessage = CrdtMessageBody & {
transportId?: number;
Expand Down
14 changes: 7 additions & 7 deletions packages/@dcl/sdk-commands/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion packages/@dcl/sdk-commands/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
"@dcl/inspector": "file:../inspector",
"@dcl/linker-dapp": "^0.12.0",
"@dcl/mini-comms": "1.0.1-20230216163137.commit-a4c75be",
"@dcl/protocol": "^1.0.0-8691799990.commit-4ba546c",
"@dcl/protocol": "1.0.0-8758013256.commit-44aab53",
"@dcl/quests-client": "^1.0.3",
"@dcl/quests-manager": "^0.1.4",
"@dcl/rpc": "^1.1.1",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ export function createRendererTransport(engineApi: EngineApiForTransport): Trans
const response = await engineApi.crdtSendToRenderer({
data: new Uint8Array(message)
})

if (response && response.data && response.data.length) {
if (rendererTransport.onmessage) {
for (const byteArray of response.data) {
Expand Down
Loading

0 comments on commit 6d2ec97

Please sign in to comment.