-
Notifications
You must be signed in to change notification settings - Fork 29
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
9cbba00
commit 0f7da56
Showing
2 changed files
with
116 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
|
||
// Import any other script files here, e.g.: | ||
// import * as myModule from "./mymodule.js"; | ||
|
||
runOnStartup(async runtime => | ||
{ | ||
runtime.addEventListener("beforeprojectstart", () => OnBeforeProjectStart(runtime)); | ||
}); | ||
|
||
async function OnBeforeProjectStart(runtime) | ||
{ | ||
// Code to run just before 'On start of layout' on | ||
// the first layout. Loading has finished and initial | ||
// instances are created and available to use here. | ||
|
||
var timestep = 1 / 60; // 60 Hz time step | ||
var accumulator = 0; | ||
|
||
requestAnimationFrame(function gameLoop(timestamp) { | ||
accumulator += (timestamp - lastFrameTimeMs) / 1000; | ||
while (accumulator > timestep) { | ||
accumulator -= timestep; | ||
} | ||
|
||
lastFrameTimeMs = timestamp; | ||
requestAnimationFrame(gameLoop); | ||
}); | ||
|
||
runtime.addEventListener("tick", () => Tick(runtime)); | ||
} | ||
|
||
var lastFrameTimeMs = 0; | ||
|
||
function Tick(runtime) | ||
{ | ||
// Code to run every tick | ||
getScreenRefreshRate(function(FPS){ | ||
//console.log(`${FPS} FPS`); | ||
runtime.globalVars.ScnRefreshRate = FPS; | ||
//console.log("FPS = "+runtime.globalVars.ScnRefreshRate); | ||
|
||
}); | ||
} | ||
|
||
/** | ||
* Allows to obtain the estimated Hz of the primary monitor in the system. | ||
* | ||
* @param {Function} callback The function triggered after obtaining the estimated Hz of the monitor. | ||
* @param {Boolean} runIndefinitely If set to true, the callback will be triggered indefinitely (for live counter). | ||
*/ | ||
function getScreenRefreshRate(callback, runIndefinitely){ | ||
let requestId = null; | ||
let callbackTriggered = false; | ||
runIndefinitely = runIndefinitely || false; | ||
|
||
if (!window.requestAnimationFrame) { | ||
window.requestAnimationFrame = window.mozRequestAnimationFrame || window.webkitRequestAnimationFrame; | ||
} | ||
|
||
let DOMHighResTimeStampCollection = []; | ||
|
||
let triggerAnimation = function(DOMHighResTimeStamp){ | ||
DOMHighResTimeStampCollection.unshift(DOMHighResTimeStamp); | ||
|
||
if (DOMHighResTimeStampCollection.length > 10) { | ||
let t0 = DOMHighResTimeStampCollection.pop(); | ||
let fps = Math.floor(1000 * 10 / (DOMHighResTimeStamp - t0)); | ||
|
||
if(!callbackTriggered){ | ||
callback.call(undefined, fps, DOMHighResTimeStampCollection); | ||
} | ||
|
||
if(runIndefinitely){ | ||
callbackTriggered = false; | ||
}else{ | ||
callbackTriggered = true; | ||
} | ||
} | ||
|
||
requestId = window.requestAnimationFrame(triggerAnimation); | ||
}; | ||
|
||
window.requestAnimationFrame(triggerAnimation); | ||
|
||
// Stop after half second if it shouldn't run indefinitely | ||
if(!runIndefinitely){ | ||
window.setTimeout(function(){ | ||
window.cancelAnimationFrame(requestId); | ||
requestId = null; | ||
}, 500); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
|
||
|
||
|
||
const scriptsInEvents = { | ||
|
||
async Introevent_Event2_Act1(runtime, localVars) | ||
{ | ||
initSDK(); | ||
}, | ||
|
||
async Rhm_ads_Event1_Act1(runtime, localVars) | ||
{ | ||
CallInterstitialAds(); | ||
}, | ||
|
||
async Rhm_ads_Event2_Act1(runtime, localVars) | ||
{ | ||
CallRewardedAds(); | ||
} | ||
|
||
}; | ||
|
||
self.C3.ScriptsInEvents = scriptsInEvents; | ||
|