Skip to content

Commit

Permalink
Backup
Browse files Browse the repository at this point in the history
  • Loading branch information
dtugend committed Aug 6, 2021
1 parent a9d35d0 commit 3b638d6
Show file tree
Hide file tree
Showing 9 changed files with 721 additions and 581 deletions.
1,105 changes: 616 additions & 489 deletions afx-cefhud-interop/AfxInterop.cpp

Large diffs are not rendered by default.

38 changes: 11 additions & 27 deletions afx-cefhud-interop/assets/examples/default/drawing.html
Original file line number Diff line number Diff line change
Expand Up @@ -632,12 +632,7 @@ <h2>Last game events:</h2>
await Utils.toPromise(self.interop, "pumpSkip");
}

let hasLastRender = Utils.coalesce(self.lastRender, false);
self.lastRender = false;

let cmp = frameCount - clientFrameCount;
//console.log(cmp+" "+hasLastRender);
if(hasLastRender) cmp -= 1;
if(0 == cmp) cmp = pass - clientPass;

if(cmp < 0) {
Expand Down Expand Up @@ -797,26 +792,20 @@ <h2>Last game events:</h2>
try {
await Utils.toPromise(self.interop, "cefBeginFrame", width, height, {
"onAfterClear": function(resolve,reject,shareHandle) {
if(hasLastRender)
onAfterClear(shareHandle,width,height).then(()=>{
resolve(true);
}).catch((e)=>{
reject(e);
});
else
resolve(false);
onAfterClear(shareHandle,width,height).then(()=>{
resolve(true);
}).catch((e)=>{
reject(e);
});
}
, "onAfterRender": function(resolve,reject,shareHandle) {
if(animationFrame) {
rendered = true;
if(hasLastRender)
onAfterRender(shareHandle,x,y,width,height).then(()=>{
resolve(true);
}).catch((e)=>{
reject(e);
});
else
resolve(false);
onAfterRender(shareHandle,x,y,width,height).then(()=>{
resolve(true);
}).catch((e)=>{
reject(e);
});
} else
resolve(false);
}
Expand All @@ -832,12 +821,7 @@ <h2>Last game events:</h2>
}
}

self.lastRender = true;

if(hasLastRender)
await Utils.toPromise(self.interop, "pumpFinish");
else
await Utils.toPromise(self.interop, "pumpRetry");
await Utils.toPromise(self.interop, "pumpFinish");
}

////////////////////////////////////////////////////////////////////////////////
Expand Down
68 changes: 36 additions & 32 deletions afx-cefhud-interop/assets/examples/default/engine.html
Original file line number Diff line number Diff line change
Expand Up @@ -220,11 +220,9 @@
// optional.
"onNewConnection": async function(){
console.log("New connection");
await Utils.toPromise(this.interop, "pump", this.pumpEvents);
},
// recommended.
// optional.
"onDone": async function(){
await Utils.toPromise(this.interop, "pump", this.pumpEvents);
},
// optional.
"onCommands": async function(commands) {
Expand Down Expand Up @@ -266,15 +264,15 @@
}
}
}
await Utils.toPromise(this.interop, "pump", this.pumpEvents, doCommands);

return doCommands;
},
// optional.
"onGameEvent": async function(e){
await Utils.toPromise(this.interop, "sendMessage", this.args.drawingInteropId, JSON.stringify({
"id": "onGameEvent",
"args": [e]
}));
await Utils.toPromise(this.interop, "pump", this.pumpEvents);
},
// optional.
"onRenderViewBegin": async function(renderInfo) {
Expand All @@ -286,37 +284,31 @@
"id": "onRenderViewBegin",
"args": [renderInfo]
}));
await Utils.toPromise(this.interop, "pump", this.pumpEvents);
},
/*
// optional.
"onRenderViewBeforeTranslucent" : async function(view) {
//TODO: schedule for drawing.
await Utils.toPromise(this.interop, "pump", this.pumpEvents);
},*/
/*
// optional.
"onRenderViewAfterTranslucent" : async function(view) {
//TODO: schedule for drawing.
await Utils.toPromise(this.interop, "pump", this.pumpEvents);
},*/
/*
// optional.
"onRenderViewBeforeTranslucentShadow" : async function(view) {
//TODO: schedule for drawing.
await Utils.toPromise(this.interop, "pump", this.pumpEvents);
},*/
/*
// optional.
"onRenderViewAfterTranslucentShadow" : async function(view) {
//TODO: schedule for drawing.
await Utils.toPromise(this.interop, "pump", this.pumpEvents);
},*/
/*
// optional.
"onRenderViewHudBegin" : async function() {
//TODO: schedule for drawing.
await Utils.toPromise(this.interop, "pump", this.pumpEvents);
},*/
// optional.
"onRenderViewHudEnd": async function(){
Expand All @@ -327,25 +319,24 @@

this.pass++;

await Utils.toPromise(this.interop, "pump", this.pumpEvents);
},
// optional.
/*"onRenderViewEnd": aync function() {
//TODO: schedule for drawing.
await Utils.toPromise(this.interop, "pump", this.pumpEvents);
},*/
/*
// optional.
"onViewOverride": async function(view) {
await Utils.toPromise(this.interop, "pump", this.pumpEvents, {
//tX: 0,
//tY: 0,
//tZ: 0,
//rX: 0,
//rY: 0,
//rZ: 0,
//fov: 90,
});
// optional:
//return {
// tX: 0, // optional
// tY: 0, // optional
// tZ: 0, // optional
// rX: 0, // optional
// rY: 0, // optional
// rZ: 0, // optional
// fov: 90, // optional
//};
},*/
};

Expand Down Expand Up @@ -383,7 +374,24 @@
}

doConnect()
.then(()=>Utils.toPromise(self.interop, "pump", self.pumpEvents));
.then(()=>{
function pumper() {
if(self.connected) {
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);
});
}
}

pumper();
});
});
}

Expand Down Expand Up @@ -439,15 +447,11 @@

Object.keys(self.pumpEventsAsync).forEach((key) => {

pumpEvents[key] = function(...args){

self.pumpPromise = self.pumpPromise
.finally(()=>self.pumpEventsAsync[key].apply(self, args))
.catch((e) => {
Utils.logError(e);

if(!(e && e.soft))
return Utils.toPromise(self, "disconnect");
pumpEvents[key] = function(resolve,reject,...args){
self.pumpEventsAsync[key].apply(self, args).then((...args)=>{
resolve(...args);
}).catch((...args) => {
reject(...args);
});
}
});
Expand Down
2 changes: 1 addition & 1 deletion afx-cefhud-interop/assets/examples/default/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
The game must run with at least 2 queues (which is the case for mat_queueu_mode 2, and on almost all CPUs also for mat_queue_mode -1 (recommended))!
Execute (will log warings / errors to debug.log in current directoy):
afx-cefhud-interop.exe "--url=afx://file/C:/source/afx-cefhud-interop/afx-cefhud-interop/assets/examples/default/index.html" "--enable-experimental-web-platform-features" "--enable-logging" "--log-severity=error"
afx-cefhud-interop.exe "--url=afx://file/C:/source/afx-cefhud-interop/afx-cefhud-interop/assets/examples/default/index.html" "--enable-experimental-web-platform-features" "--enable-logging" "--log-severity=info"
For live execute:
afx-cefhud-interop.exe "--url=afx://file/C:/source/afx-cefhud-interop/afx-cefhud-interop/assets/examples/default/index.html" "--enable-experimental-web-platform-features" "--disable-logging" "--log-severity=error"
Expand Down
2 changes: 1 addition & 1 deletion afx-cefhud-interop/assets/js/modules/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,6 @@ export function transposeMatrix(matrix) {

export function coalesce(lhs,rhs) {
let lhsType = typeof lhs;
if(lhsType == "undefined" || lhsType == "null") return rhs;
if(lhsType === "undefined" || lhsType === "null") return rhs;
return lhs;
}
66 changes: 46 additions & 20 deletions afx-cefhud-interop/cefsimple_win.cc
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,48 @@ void STDMETHODCALLTYPE My_OMSetRenderTargets(
pDepthStencilView);
}


typedef void(STDMETHODCALLTYPE* CopyResource_t)(
ID3D11DeviceContext* This,
/* [annotation] */
_In_ ID3D11Resource* pDstResource,
/* [annotation] */
_In_ ID3D11Resource* pSrcResource);

CopyResource_t g_Org_CopyResource;

void STDMETHODCALLTYPE My_CopyResource(ID3D11DeviceContext* This,
/* [annotation] */
_In_ ID3D11Resource* pDstResource,
/* [annotation] */
_In_ ID3D11Resource* pSrcResource) {

g_Org_CopyResource(This, pDstResource, pSrcResource);

if (pSrcResource) {
auto it = g_Textures.find((ID3D11Texture2D*)pSrcResource);
if (it != g_Textures.end()) {
it->second.FirstClear = true;
++it->second.FlushCount;

// AfxWaitForGPU(This);

try {
g_GpuPipeClient.WriteInt32(
(INT32)advancedfx::interop::HostGpuMessage::OnAfterRender);
g_GpuPipeClient.WriteHandle(it->second.ShareHandle);
g_GpuPipeClient.WriteInt32(it->second.ActiveBrowser);
g_GpuPipeClient.Flush();

g_GpuPipeClient.ReadBoolean();
} catch (const std::exception& e) {
DLOG(ERROR) << "Error in " << __FILE__ << ":" << __LINE__ << ": "
<< e.what();
}
}
}
}

void STDMETHODCALLTYPE My_Flush(ID3D11DeviceContext* This) {
g_Org_Flush(This);

Expand All @@ -242,26 +284,6 @@ void STDMETHODCALLTYPE My_Flush(ID3D11DeviceContext* This) {
oldRenderTarget[0]->GetResource(&resource);

if (resource) {
auto it = g_Textures.find((ID3D11Texture2D*)resource);
if (it != g_Textures.end()) {
it->second.FirstClear = true;
++it->second.FlushCount;

// AfxWaitForGPU(This);

try {
g_GpuPipeClient.WriteInt32(
(INT32)advancedfx::interop::HostGpuMessage::OnAfterRender);
g_GpuPipeClient.WriteHandle(it->second.ShareHandle);
g_GpuPipeClient.WriteInt32(it->second.ActiveBrowser);
g_GpuPipeClient.Flush();

g_GpuPipeClient.ReadBoolean();
} catch (const std::exception& e) {
DLOG(ERROR) << "Error in " << __FILE__ << ":" << __LINE__ << ": "
<< e.what();
}
}

resource->Release();
}
Expand Down Expand Up @@ -896,6 +918,9 @@ MyD3D11CreateDevice(_In_opt_ IDXGIAdapter* pAdapter,
(OMSetRenderTargets_t) *
(void**)((*(char**)(pContext)) + sizeof(void*) * 33);

g_Org_CopyResource =
(CopyResource_t) *
(void**)((*(char**)(pContext)) + sizeof(void*) * 47);

g_Org_ClearRenderTargetView =
(ClearRenderTargetView_t) *
Expand All @@ -910,6 +935,7 @@ MyD3D11CreateDevice(_In_opt_ IDXGIAdapter* pAdapter,
DetourTransactionBegin();
DetourUpdateThread(GetCurrentThread());
DetourAttach(&(PVOID&)g_Org_OMSetRenderTargets, My_OMSetRenderTargets);
DetourAttach(&(PVOID&)g_Org_CopyResource, My_CopyResource);
DetourAttach(&(PVOID&)g_Org_ClearRenderTargetView,
My_ClearRenderTargetView);
DetourAttach(&(PVOID&)g_Org_Flush,
Expand Down
15 changes: 8 additions & 7 deletions afx-cefhud-interop/simple_app.cc
Original file line number Diff line number Diff line change
Expand Up @@ -265,18 +265,19 @@ void SimpleApp::OnBeforeCommandLineProcessing(
command_line->AppendSwitch("disable-hang-monitor");

command_line->AppendSwitch("disable-frame-rate-limit");
command_line->AppendSwitchWithValue("deadline-to-synchronize-surfaces",
"0");
command_line->AppendSwitchWithValue("deadline-to-synchronize-surfaces", "0");

command_line->AppendSwitch("disable-threaded-animation");
command_line->AppendSwitch("disable-threaded-scrolling");
command_line->AppendSwitch("disable-checker-imaging");
//command_line->AppendSwitch("disable-threaded-animation");
//command_line->AppendSwitch("disable-threaded-scrolling");
//command_line->AppendSwitch("disable-checker-imaging");
//command_line->AppendSwitch("run-all-compositor-stages-before-draw");

//command_line->AppendSwitch("disable-image-animation-resync");
//command_line->AppendSwitch("deterministic-mode");
///command_line->AppendSwitch("deterministic-mode");

command_line->AppendSwitch("disable-ipc-flooding-protection");

command_line->AppendSwitch("enable-main-frame-before-activation");
//command_line->AppendSwitch("enable-main-frame-before-activation");

command_line->AppendSwitch("disable-backgrounding-occluded-windows");
}
1 change: 0 additions & 1 deletion afx-cefhud-interop/simple_handler.cc
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,6 @@ void SimpleHandler::DoCreateDrawing(const std::string& argStr, const std::string
CefWindowInfo window_info;
window_info.SetAsWindowless(NULL);
window_info.shared_texture_enabled = true;
//true;
window_info.external_begin_frame_enabled = true;
window_info.width = 640;
window_info.height = 360;
Expand Down
5 changes: 2 additions & 3 deletions afx-cefhud-interop/simple_handler.h
Original file line number Diff line number Diff line change
Expand Up @@ -330,8 +330,6 @@ class SimpleHandler : public CefClient,
*/
bool OnAfterRender(void* share_handle) {
std::unique_lock<std::mutex> lock2(m_DrawingMutex);
if (!m_Cleared)
return false;

m_Cleared = false;

Expand Down Expand Up @@ -469,7 +467,8 @@ class SimpleHandler : public CefClient,
m_Owner->Browser->GetHost()->WasResized();
}

m_Owner->Browser->GetHost()->SendExternalBeginFrame();
//m_Owner->Browser->GetHost()->Invalidate(PET_VIEW);
m_Owner->Browser->GetHost()->SendExternalBeginFrame();
} break;
case advancedfx::interop::HostMessage::CreateDrawing: {
std::string argUrl;
Expand Down

0 comments on commit 3b638d6

Please sign in to comment.