diff --git a/ModuleApiGameLibFrameCycle.md b/ModuleApiGameLibFrameCycle.md new file mode 100644 index 0000000..7cfed93 --- /dev/null +++ b/ModuleApiGameLibFrameCycle.md @@ -0,0 +1,21 @@ +# ModuleApi - GameLib FrameCycle + +Simple object used to perform time calculations for sychronized rendering across clients. + +## Structure + +```JSON +{ + "startTimestamp": 1754754260809, + "frameInterval": 1000 / 60, + "totalFrames": 10 +} + +``` + +| Attribute | Type | Description | +| --------------------- | ------ | ------------------------------------------------------- | +| startTimestamp | number | The start timestamp of the frame cycle in milliseconds. | +| frameInterval | number | The interval between frames in milliseconds. | +| totalFrames | number | The total number of frames in the cycle. | +| (Optional) startFrame | number | The start frame of the cycle. | diff --git a/ModuleApiGameLibTimeSpan.md b/ModuleApiGameLibTimeSpan.md new file mode 100644 index 0000000..1a631fd --- /dev/null +++ b/ModuleApiGameLibTimeSpan.md @@ -0,0 +1,18 @@ +# ModuleApi - GameLib TimeSpan + +Simple object used to perform time calculations for sychronized rendering across clients. + +## Structure + +```JSON +{ + "startTimestamp": 1754754260809, + "endTimestamp": 1754754270809 +} + +``` + +| Attribute | Type | Description | +| -------------- | ------ | ------------------------------------ | +| startTimestamp | number | The start timestamp of the TimeSpan. | +| endTimestamp | number | The end timestamp of the TimeSpan. | diff --git a/ModuleClientAPIGameLib.md b/ModuleClientAPIGameLib.md index d68f4f2..ba90fd0 100644 --- a/ModuleClientAPIGameLib.md +++ b/ModuleClientAPIGameLib.md @@ -17,20 +17,112 @@ api.GameLib.newController(roomId, controllerId); | roomId | string | The ID of the game room. | | controllerId | string | The ID of the controller. | -**Return** [Controller](./ModuleClientAPIGameLibController) _The GameLib Controller_ +**Return** [Controller](./ModuleClientAPIGameLibController) _Controller instance._ ## Timing +Several functions to synchronize clients using the synced time you can retrieve using `api.getTime()`. + ### toTimeSpan +Creates a timespan object. + +```javascript +api.GameLib.Timing.toTimeSpan(duration, startTimestamp?); +``` + +| Argument | Type | Description | +| ------------------------- | ------ | ---------------------------------------------------- | +| duration | number | The duration of the timespan in milliseconds. | +| (Optional) startTimestamp | number | The start timestamp of the timespan in milliseconds. | + +**Return** [TimeSpan](./ModuleApiGameLibTimeSpan) _TimeSpan instance._ + ### toFrameCycle +Creates a frame cycle object. + +```javascript +api.GameLib.Timing.toFrameCycle(startTimestamp, frameInterval, totalFrames, startFrame?); +``` + +| Argument | Type | Description | +| -------------- | ------ | ------------------------------------------------------- | +| startTimestamp | number | The start timestamp of the frame cycle in milliseconds. | +| frameInterval | number | The interval between frames in milliseconds. | +| totalFrames | number | The total number of frames in the cycle. | +| startFrame | number | The start frame of the cycle. | + +**Return** [FrameCycle](./ModuleApiGameLibFrameCycle) _FrameCycle instance._ + ### getCurrentFrameIndex +Gets the current frame index of the frame cycle. + +```javascript +api.GameLib.Timing.getCurrentFrameIndex(cycle); +``` + +| Argument | Type | Description | +| -------- | ------------------------------------------ | ------------------- | +| cycle | [FrameCycle](./ModuleApiGameLibFrameCycle) | FrameCycle instance | + +**Return** number _The current frame index._ + ### getFrameIndexAtTimestamp +Gets the current frame index of the frame cycle. + +```javascript +api.GameLib.Timing.getFrameIndexAtTimestamp(cycle, timestamp); +``` + +| Argument | Type | Description | +| --------- | ------------------------------------------ | ---------------------------------------- | +| cycle | [FrameCycle](./ModuleApiGameLibFrameCycle) | FrameCycle instance | +| timestamp | number | The timestamp to get the frame index at. | + +**Return** number _The frame index at the given timestamp._ + ### getCurrentTimeSpanRatio +Gets the ratio of the current time span. + +```javascript +api.GameLib.Timing.getCurrentTimeSpanRatio(span); +``` + +| Argument | Type | Description | +| -------- | -------------------------------------- | ----------------- | +| span | [TimeSpan](./ModuleApiGameLibTimeSpan) | TimeSpan instance | + +**Return** [Ratio](./ModuleApiGameLibRatio) _The ratio of the current time span._ + ### getTimeSpanRatioAtTimestamp +Gets the ratio of the time span at the given timestamp. + +```javascript +api.GameLib.Timing.getTimeSpanRatioAtTimestamp(span, timestamp); +``` + +| Argument | Type | Description | +| --------- | -------------------------------------- | ---------------------------------- | +| span | [TimeSpan](./ModuleApiGameLibTimeSpan) | TimeSpan instance | +| timestamp | number | The timestamp to get the ratio at. | + +**Return** [Ratio](./ModuleApiGameLibRatio) _The ratio of the time span at the given timestamp._ + ### toRatio + +Creates a ratio object. + +```javascript +api.GameLib.Timing.toRatio(value); +``` + +| Argument | Type | Description | +| -------- | ------ | ----------------------- | +| value | number | The value of the ratio. | + +**Return** [Ratio](./ModuleApiGameLibRatio) _Ratio instance._ diff --git a/_Sidebar.md b/_Sidebar.md index 9c5477c..1ea04e3 100644 --- a/_Sidebar.md +++ b/_Sidebar.md @@ -26,6 +26,8 @@ - ModuleApi Shared - [GameLib GameDetails](./ModuleApiGameLibGameDetails) - [GameLib EndScreen](./ModuleAPIGameLibEndScreen) + - [GameLib TimeSpan](./ModuleApiGameLibTimeSpan) + - [GameLib FrameCycle](./ModuleApiGameLibFrameCycle) - [Module Debugging](./ModuleDebugging) - [ModuleStore](./ModuleStore) - [Bug/Feature Reporting](./Reporting)