Skip to content

Commit

Permalink
Backup
Browse files Browse the repository at this point in the history
  • Loading branch information
dtugend committed Sep 11, 2021
1 parent 2789b13 commit 8ef3714
Show file tree
Hide file tree
Showing 7 changed files with 116 additions and 189 deletions.
40 changes: 5 additions & 35 deletions afx-cefhud-interop/AfxInterop.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2438,30 +2438,6 @@ CAfxObject::AddFunction(
});


CAfxObject::AddFunction(
obj, "lockCefTexture",
[](const CefString& name, CefRefPtr<CefV8Value> object,
const CefV8ValueList& arguments, CefRefPtr<CefV8Value>& retval,
CefString& exceptionoverride) {
auto self = CAfxObject::As<AfxObjectType::DrawingInteropImpl,
CDrawingInteropImpl>(object);
if (self == nullptr) {
exceptionoverride = g_szInvalidThis;
return true;
}

if (2 <= arguments.size() && arguments[0]->IsFunction() &&
arguments[1]->IsFunction()) {
self->m_OnAck = arguments[0];
auto message = CefProcessMessage::Create("afx-lock");
self->m_Frame->SendProcessMessage(PID_BROWSER, message);
return true;
}

exceptionoverride = g_szInvalidArguments;
return true;
});

CAfxObject::AddFunction(
obj, "waitForCefFrame",
[](const CefString& name, CefRefPtr<CefV8Value> object,
Expand All @@ -2485,7 +2461,7 @@ CAfxObject::AddFunction(
});

CAfxObject::AddFunction(
obj, "unlockCefTexture",
obj, "setCefUseClearTexture",
[](const CefString& name, CefRefPtr<CefV8Value> object,
const CefV8ValueList& arguments, CefRefPtr<CefV8Value>& retval,
CefString& exceptionoverride) {
Expand All @@ -2496,20 +2472,14 @@ CAfxObject::AddFunction(
return true;
}

if (2 <= arguments.size() && arguments[0]->IsFunction() &&
arguments[1]->IsFunction()) {
self->m_OnAck = arguments[0];
auto message = CefProcessMessage::Create("afx-unlock");
auto message = CefProcessMessage::Create("afx-use-clear");
auto args = message->GetArgumentList();
args->SetSize(1);
args->SetBool(0, 3 <= arguments.size() && arguments[2]->IsBool() &&
arguments[2]->GetBoolValue());
args->SetBool(0, 1 <= arguments.size() && arguments[0]->IsBool() &&
arguments[0]->GetBoolValue());
self->m_Frame->SendProcessMessage(PID_BROWSER, message);
return true;
}

exceptionoverride = g_szInvalidArguments;
return true;
return true;
});


Expand Down
221 changes: 86 additions & 135 deletions afx-cefhud-interop/assets/examples/default/drawing.html
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ <h2>Last game events:</h2>
let messages = self.messages[port]
let jMessage = messages[0];

console.log(JSON.stringify(jMessage));
//console.log(JSON.stringify(jMessage));

self.messageHandlers[jMessage.id].apply(self, jMessage.args).then(()=>{
messages.shift();
Expand Down Expand Up @@ -235,27 +235,6 @@ <h2>Last game events:</h2>
"rect": null
};

self.onAnimationFrame = [];

function onAnimationFrame(timestamp) {
console.log(timestamp);
if(0 < self.onAnimationFrame.length) {
let elFn = self.onAnimationFrame.shift();
//Utils.toPromise(self.interop, "waitForCefFrame").then(()=>{
//Utils.toPromise(self.interop, "lockCefTexture").then(()=>{
elFn(timestamp).then((updateClearTexture)=>{
//Utils.toPromise(self.interop, "unlockCefTexture", updateClearTexture).then(()=>{
window.requestAnimationFrame(onAnimationFrame);
//});
});
//});
//});
}
else
window.requestAnimationFrame(onAnimationFrame);
}
window.requestAnimationFrame(onAnimationFrame);

Utils.toPromise(self.interop, "sendMessage", self.args.indexInteropId, JSON.stringify({
"id": "drawingCreated",
"args": [interop.id]
Expand Down Expand Up @@ -642,9 +621,16 @@ <h2>Last game events:</h2>

var self = this;

await new Promise((resolvePass,rejectPass)=>{
while(true) {

async function updateShareHandle() {
let lastRender = Utils.coalesce(self.lastRender, null);

// paint last frame (if wanted):
if(lastRender && lastRender.onPaint) {

if(lastRender.sync)
await self.waitForCefFrame;

if(self.lastShareHandle)
{
if(
Expand All @@ -656,142 +642,107 @@ <h2>Last game events:</h2>
}
self.lastShareHandle = self.interop.cefTextureShareHandle;

if(self.lastClearShareHandle)
{
if(
self.interop.cefClearTextureShareHandle.lo != self.lastClearShareHandle.lo
|| self.interop.cefClearTextureShareHandle.hi != self.lastClearShareHandle.hi) {
console.log("Cleaer share handle changed, releasing old one on client ...");
await self.releaseShareHandle(self.lastClearShareHandle);
}
try {
await lastRender.onPaint(self.interop.cefTextureShareHandle);
} catch(e) {
if(!(e && e.soft)) throw e;
}
}

// finish last frame:
if(lastRender && lastRender.onEnd) {
try {
await lastRender.onEnd();
} catch(e) {
if(!(e && e.soft)) throw e;
}
self.lastClearShareHandle = self.interop.cefClearTextureShareHandle;
}

async function doNewFrame(queued) {
console.log("doNewFrame("+queued+")");

self.lastRender = newRender;
// Handle resizing:
if(newRender && (self.width !== newRender.width || self.height !== newRender.height)) {
console.log("Resizing to "+newRender.width+"x"+newRender.height+" ...");

if(newRender) {
if(queued) {
resolvePass();
return;
}
newRender = null;
}
else {
resolvePass();
return;
}
self.width = newRender.width;
self.height = newRender.height;

self.interop.setSize(newRender.width, newRender.height);

await doRender();
let timestamp = await new Promise((resolve,reject)=>{
window.requestAnimationFrame(function(timestamp){
if(newRender.sync) self.waitForCefFrame = Utils.toPromise(self.interop, "waitForCefFrame");
resolve(timestamp);
});
});
if(newRender.sync) await self.waitForCefFrame;
}

async function doRenderClear(queued, resized) {
console.log("doRenderClear("+queued+", "+resized+")");

await updateShareHandle();

let queued = false;

// begin new frame:
if(newRender && newRender.onBegin) {
try {
await newRender.onClear(self.interop.cefClearTextureShareHandle);
queued = await newRender.onBegin();
} catch(e) {
Utils.logError(e);
if(!(e && e.soft)) throw e;
queued = false;
}

if(resized) {
await doNewFrame(queued);
}

}

async function doContinueRender(lastRender) {
// finish last frame:
if(lastRender && lastRender.onEnd) {
console.log("6");
try {
await lastRender.onEnd();
} catch(e) {
if(!(e && e.soft)) throw e;

async function doClear() {
// clear new frame (if wanted):
if(newRender && newRender.onClear) {
self.interop.setCefUseClearTexture(true);

if(self.lastClearShareHandle)
{
if(
self.interop.cefClearTextureShareHandle.lo != self.lastClearShareHandle.lo
|| self.interop.cefClearTextureShareHandle.hi != self.lastClearShareHandle.hi) {
console.log("Clear share handle changed, releasing old one on client ...");
await self.releaseShareHandle(self.lastClearShareHandle);
}
}
}

let resized = false;

// Handle resizing:
if(newRender && (self.width !== newRender.width || self.height !== newRender.height)) {
console.log(newRender.width, newRender.height);
self.lastClearShareHandle = self.interop.cefClearTextureShareHandle;

self.width = newRender.width;
self.height = newRender.height;

self.interop.setSize(newRender.width, newRender.height);
resized = true;
}

let queued = false;

// begin new frame:
if(newRender && newRender.onBegin) {
try {
queued = await newRender.onBegin();
await newRender.onClear(self.interop.cefClearTextureShareHandle);
} catch(e) {
Utils.logError(e);
if(!(e && e.soft)) throw e;
queued = false;
}

}

// clear new frame (if wanted):
if(newRender && newRender.onClear) {

// If we resized we need to waste a frame, since we paint onto the old one.
if(resized) {
self.onAnimationFrame.push(function(timestamp) {
return doRenderClear(queued,true).then(()=>{ return false; }).catch((e)=>{rejectPass(e); return false; });
});
return;
}

await doRenderClear(queued,false);
else {
self.interop.setCefUseClearTexture(false);
}

await doNewFrame(queued);
}

async function doPaint(lastRender) {

await updateShareHandle();

try {
await lastRender.onPaint(self.interop.cefTextureShareHandle);
} catch(e) {
if(!(e && e.soft)) throw e;
let timestamp = await new Promise((resolve,reject)=>{
window.requestAnimationFrame(function(timestamp){
let onAnimationFrame = doClear();
if(newRender && newRender.onAnimationFrame)
onAnimationFrame = onAnimationFrame.then(()=>newRender.onAnimationFrame(timestamp));
onAnimationFrame.then(()=>{
if(newRender && newRender.sync) self.waitForCefFrame = Utils.toPromise(self.interop, "waitForCefFrame");
resolve(timestamp);
}).catch((e)=>{reject(e);});
});
});

self.lastRender = newRender;

if(newRender) {
if(queued) {
break;
}

await doContinueRender(lastRender);
newRender = null;
}

async function doRender() {
console.log("doRender()");

let lastRender = Utils.coalesce(self.lastRender, null);

// paint last frame (if wanted):
if(lastRender && lastRender.onPaint) {
self.onAnimationFrame.push(function(timestamp) {
return doPaint(lastRender).then(()=>{
return null !== lastRender;
}).catch((e)=>{rejectPass(e); return false; });
});
return;
}

await doContinueRender(lastRender);
else {
break;
}

return doRender();
});
}
}

AfxDrawingInterop.prototype.renderScreen = async function(frameCount,pass,x,y,width,height) {
Expand All @@ -802,6 +753,7 @@ <h2>Last game events:</h2>
// Ensure resources:

await this.render({
"sync": true, // change this according to if you need perfect sync (performance boost if false)
"x": x,
"y": y,
"width": width,
Expand All @@ -822,8 +774,6 @@ <h2>Last game events:</h2>
let cmp = this.frameCount - clientFrameCount;
if(0 == cmp) cmp = this.pass - clientPass;

console.log("CMP: "+cmp);

if(cmp < 0) {
// client ahead.
this.retry = true;
Expand Down Expand Up @@ -862,6 +812,7 @@ <h2>Last game events:</h2>

return queued;
},
// comment out or rename this to s.th. else if you don't need background of cs:go in cef for special background effects.
"onClear": async function(rootTextureHandle) {

if(this.retry) return;
Expand Down
1 change: 1 addition & 0 deletions afx-cefhud-interop/assets/examples/default/engine.html
Original file line number Diff line number Diff line change
Expand Up @@ -320,6 +320,7 @@
},*/
// optional.
"onRenderViewHudEnd": async function(){
console.log("onRenderViewHudEnd");
await Utils.toPromise(this.interop, "sendMessage", this.args.drawingInteropId, JSON.stringify({
"id": "onHudEnd",
"args": [this.renderInfo.frameCount, this.pass]
Expand Down
Loading

0 comments on commit 8ef3714

Please sign in to comment.