diff --git a/afx-cefhud-interop/assets/examples/default/drawing.html b/afx-cefhud-interop/assets/examples/default/drawing.html index b6674d6..41fee35 100644 --- a/afx-cefhud-interop/assets/examples/default/drawing.html +++ b/afx-cefhud-interop/assets/examples/default/drawing.html @@ -73,6 +73,8 @@

Last game events:

this.connected = false; this.messages = {}; + this.indexSettings = {}; + this.shaderData = { "afx_drawtexture_vs20": this.compileShader(this.stringToAfxData(` matrix World; @@ -135,8 +137,10 @@

Last game events:

"disconnect": async function(senderId) { await Utils.toPromise(this, "disconnect"); }, - "onRenderViewBegin": async function(renderInfo){ - + "onRenderViewBegin": async function(renderInfo,settings){ + + this.indexSettings = Object.assign({}, this.indexSettings, settings); + this.elIndicator2.classList.toggle("white"); this.renderInfo = renderInfo; @@ -752,8 +756,8 @@

Last game events:

try { // Ensure resources: - await this.render({ - "sync": true, // change this according to if you need perfect sync (performance boost if false) + let renderSettings = { + "sync": this.indexSettings.sync, "x": x, "y": y, "width": width, @@ -761,6 +765,7 @@

Last game events:

"frameCount": frameCount, "pass": pass, "retry": false, + // optional: // "onAnimationFrame": async function(timestamp) {} "onBegin": async function() { let queued = false; @@ -812,8 +817,54 @@

Last game events:

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) { + "onPaint": async function(cefTextureHandle) { + + if(this.retry) return; + + //console.log("doPaintCefToGame BEGIN"); + + if(cefTextureHandle.invalid) throw Utils.toSoftError(new Error("cefTextureHandle.invalid")); + + var cefTexture = self.getCefTexture(cefTextureHandle); + + if(!cefTexture) { + console.log("Creating new texture for cefTextureHandle: ("+cefTextureHandle.hi+", "+cefTextureHandle.lo+")"); + + var refTexture = [undefined]; + const D3DFMT_A8R8G8B8 = 21; + var hr = await Utils.toPromise(self.interop, "d3d9CreateTexture", this.width, this.height, 1, D3d9.D3DUSAGE.D3DUSAGE_RENDERTARGET, D3DFMT_A8R8G8B8, D3d9.D3DPOOL.D3DPOOL_DEFAULT, refTexture, [cefTextureHandle]); + if(Utils.FAILED(hr)) throw Utils.toSoftError(Utils.failedHResultToError(hr, "CreateTexture failed for cefTextureHandle: ("+cefTextureHandle.hi+", "+cefTextureHandle.lo+")")); + + cefTexture = refTexture[0]; + + self.setCefTexture(cefTextureHandle, cefTexture); + } + + if(!cefTexture) throw Utils.toSoftError(new Error("!cefTexture")); + + //console.log("doPaintCefToGame BEGIN B"); + + await self.drawRect2d(cefTexture, this.x, this.y, this.width, this.height, 0, 0, 1, 1); + + //console.log("doPaintCefToGame BEGIN D"); + + await Utils.toPromise(self.interop, "waitForClientGpu"); + + //console.log("doPaintCefToGame END"); + + // + + return true; + }, + "onEnd": async function() { + if(this.retry) + await Utils.toPromise(self.interop, "pumpRetry"); + else + await Utils.toPromise(self.interop, "pumpFinish"); + } + }; + + if(this.indexSettings.bg) renderSettings["onClear"] = async function(rootTextureHandle) { if(this.retry) return; @@ -886,53 +937,9 @@

Last game events:

//console.log("doPaintGameToCef END"); return true; - }, - "onPaint": async function(cefTextureHandle) { - - if(this.retry) return; - - //console.log("doPaintCefToGame BEGIN"); - - if(cefTextureHandle.invalid) throw Utils.toSoftError(new Error("cefTextureHandle.invalid")); - - var cefTexture = self.getCefTexture(cefTextureHandle); - - if(!cefTexture) { - console.log("Creating new texture for cefTextureHandle: ("+cefTextureHandle.hi+", "+cefTextureHandle.lo+")"); - - var refTexture = [undefined]; - const D3DFMT_A8R8G8B8 = 21; - var hr = await Utils.toPromise(self.interop, "d3d9CreateTexture", this.width, this.height, 1, D3d9.D3DUSAGE.D3DUSAGE_RENDERTARGET, D3DFMT_A8R8G8B8, D3d9.D3DPOOL.D3DPOOL_DEFAULT, refTexture, [cefTextureHandle]); - if(Utils.FAILED(hr)) throw Utils.toSoftError(Utils.failedHResultToError(hr, "CreateTexture failed for cefTextureHandle: ("+cefTextureHandle.hi+", "+cefTextureHandle.lo+")")); - - cefTexture = refTexture[0]; - - self.setCefTexture(cefTextureHandle, cefTexture); - } - - if(!cefTexture) throw Utils.toSoftError(new Error("!cefTexture")); - - //console.log("doPaintCefToGame BEGIN B"); - - await self.drawRect2d(cefTexture, this.x, this.y, this.width, this.height, 0, 0, 1, 1); - - //console.log("doPaintCefToGame BEGIN D"); - - await Utils.toPromise(self.interop, "waitForClientGpu"); - - //console.log("doPaintCefToGame END"); - - // - - return true; - }, - "onEnd": async function() { - if(this.retry) - await Utils.toPromise(self.interop, "pumpRetry"); - else - await Utils.toPromise(self.interop, "pumpFinish"); - } - }); + }; + + await this.render(renderSettings); } catch(e) { console.log(e); if(e && e.soft) { diff --git a/afx-cefhud-interop/assets/examples/default/engine.html b/afx-cefhud-interop/assets/examples/default/engine.html index 6d23f46..b834768 100644 --- a/afx-cefhud-interop/assets/examples/default/engine.html +++ b/afx-cefhud-interop/assets/examples/default/engine.html @@ -50,7 +50,12 @@ this.drawingConnectRequested = false; + this.indexSettings = {}; + this.messageHandlers = { + "settings": async function (settings) { + this.indexSettings = Object.assign({}, this.indexSettings, settings); + }, "connect": async function(senderId) { await this.connect(); }, @@ -72,6 +77,25 @@ console.log("drawingDisconnected: "+senderId); this.drawingConnectRequested = false; await Utils.toPromise(this, "disconnect"); + }, + "pump": async function() { + + try { + await Utils.toPromise(this.interop, "pump", this.pumpEvents); + } + catch(e) { + Utils.logError(e); + + if(!(e && e.soft)) { + await Utils.toPromise(this, "disconnect"); + return; + } + } + + if(this.connected) this.interop.onMessage(this.interop.id, JSON.stringify({ + "id": "pump", + "args": [] + })); } }; @@ -290,7 +314,7 @@ await Utils.toPromise(this.interop, "sendMessage", this.args.drawingInteropId, JSON.stringify({ "id": "onRenderViewBegin", - "args": [renderInfo] + "args": [renderInfo,this.indexSettings] })); }, /* @@ -320,7 +344,7 @@ },*/ // optional. "onRenderViewHudEnd": async function(){ - console.log("onRenderViewHudEnd"); + //console.log("onRenderViewHudEnd"); await Utils.toPromise(this.interop, "sendMessage", this.args.drawingInteropId, JSON.stringify({ "id": "onHudEnd", "args": [this.renderInfo.frameCount, this.pass] @@ -350,7 +374,7 @@ // required if you want to do queued rendering optimizations, // ohterwise optional. "onForceEndQueue": async function() { - console.log("SEND onForceEndQueue"); + //console.log("SEND onForceEndQueue"); await Utils.toPromise(this.interop, "sendMessage", this.args.drawingInteropId, JSON.stringify({ "id": "onForceEndQueue", "args": [] @@ -370,45 +394,26 @@ var self = this; - await new Promise(function(resolve,reject){ - self.connected = true; - self.newConnection = true; - self.drawingConnectedEvent = [resolve,reject]; - - async function doConnect() { - self.drawingConnectRequested = true; - - await Utils.toPromise(self.interop, "sendMessage", self.args.drawingInteropId, JSON.stringify({ - "id": "connect", - "args": [self.interop.id] - })); - - await Utils.toPromise(self.interop, "connect"); - - await Utils.toPromise(self.interop, "sendMessage", self.args.indexInteropId, JSON.stringify({ - "id": "engineConnected", - "args": [self.interop.id] - })); - } - - doConnect() - .then(()=>{ - function pumper() { - Utils.toPromise(self.interop, "pump", self.pumpEvents).then(()=>{ - queueMicrotask(pumper); - }).catch((e) => { - Utils.logError(e); - - if(!(e && e.soft)) - return Utils.toPromise(self, "disconnect"); - - queueMicrotask(pumper); - }); - } + self.connected = true; + self.newConnection = true; + self.drawingConnectRequested = true; + + await Utils.toPromise(self.interop, "sendMessage", self.args.drawingInteropId, JSON.stringify({ + "id": "connect", + "args": [self.interop.id] + })); + + await Utils.toPromise(self.interop, "connect"); + + await Utils.toPromise(self.interop, "sendMessage", self.args.indexInteropId, JSON.stringify({ + "id": "engineConnected", + "args": [self.interop.id] + })); - pumper(); - }); - }); + await self.interop.onMessage(self.interop.id, JSON.stringify({ + "id": "pump", + "args": [] + })); } AfxEngineInterop.prototype.disconnect = async function() { @@ -417,14 +422,6 @@ this.messages = {}; this.pumpPromise = Promise.resolve(); - if(this.drawingConnectedEvent) - { - var e = this.drawingConnectedEvent; - this.drawingConnectedEvent = null; - e[1](); - return; - } - if(this.drawingConnectRequested) { await Utils.toPromise(this.interop, "sendMessage", this.args.drawingInteropId, JSON.stringify({ diff --git a/afx-cefhud-interop/assets/examples/default/index.html b/afx-cefhud-interop/assets/examples/default/index.html index 50799e6..c72957e 100644 --- a/afx-cefhud-interop/assets/examples/default/index.html +++ b/afx-cefhud-interop/assets/examples/default/index.html @@ -30,6 +30,17 @@

Default example

Number of reconnects: 0

Engine connected: n/a

Drawing connected: n/a

+

Settings

+
+
+ + +
+
+ + +
+