Skip to content

Commit

Permalink
Add files via upload
Browse files Browse the repository at this point in the history
  • Loading branch information
MyBooty165 authored Oct 15, 2024
1 parent 9cbba00 commit 0f7da56
Show file tree
Hide file tree
Showing 2 changed files with 116 additions and 0 deletions.
92 changes: 92 additions & 0 deletions games/basket-random/scripts/project/FrameRateLimit.js
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);
}
}
24 changes: 24 additions & 0 deletions games/basket-random/scripts/project/scriptsInEvents.js
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;

0 comments on commit 0f7da56

Please sign in to comment.