heavily simplified main loop
This commit is contained in:
parent
5de6726140
commit
ba5ccea2fe
2 changed files with 17 additions and 42 deletions
|
@ -16,6 +16,13 @@
|
||||||
int main(int argc, char** argv) {
|
int main(int argc, char** argv) {
|
||||||
hazelnut::IvshmemDevice dev;
|
hazelnut::IvshmemDevice dev;
|
||||||
|
|
||||||
|
// Create a capture interface
|
||||||
|
auto pCaptureInterface = hazelnut::CreateDisplayCapture(hazelnut::GuessBestCaptureInterface());
|
||||||
|
if(!pCaptureInterface) {
|
||||||
|
printf("Failed to create a capture interface\n");
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
if(!dev.Open()) {
|
if(!dev.Open()) {
|
||||||
printf("Failed to open ivshmem device\n");
|
printf("Failed to open ivshmem device\n");
|
||||||
return 1;
|
return 1;
|
||||||
|
@ -29,56 +36,29 @@ int main(int argc, char** argv) {
|
||||||
// wipe the first 1mb
|
// wipe the first 1mb
|
||||||
memset(&ptr[0], 0, 1 * (1024 * 1024));
|
memset(&ptr[0], 0, 1 * (1024 * 1024));
|
||||||
|
|
||||||
printf("wiped memory\n");
|
// initalize laid-out IVSHMEM structs
|
||||||
|
|
||||||
// sex
|
|
||||||
auto* pHeader = new(&ptr[0]) hazelnut::IvshHeader {};
|
auto* pHeader = new(&ptr[0]) hazelnut::IvshHeader {};
|
||||||
auto* pFrameHeader = new(&ptr[0x1000]) hazelnut::FrameHeader {};
|
auto* pFrameHeader = new(&ptr[0x1000]) hazelnut::FrameHeader {};
|
||||||
|
|
||||||
// reset pingpong counter
|
// Reset session ID
|
||||||
|
|
||||||
pHeader->serverSessionId.store(rand());
|
pHeader->serverSessionId.store(rand());
|
||||||
|
|
||||||
// Create a capture interface
|
printf("Agent loop starting\n");
|
||||||
auto capture = hazelnut::CreateDisplayCapture(hazelnut::GuessBestCaptureInterface());
|
|
||||||
if(!capture) {
|
|
||||||
printf("Failed to create a capture interface\n");
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
printf("Successfully created a framebuffer capture interface\n");
|
|
||||||
|
|
||||||
bool firstFrame = true;
|
|
||||||
hazelnut::FramebufferInformation framebuffer {};
|
hazelnut::FramebufferInformation framebuffer {};
|
||||||
hazelnut::DiffInformation diff {};
|
hazelnut::DiffInformation diff {};
|
||||||
|
|
||||||
while(true) {
|
while(true) {
|
||||||
bool changed = false;
|
|
||||||
{
|
{
|
||||||
auto guard = pHeader->lock.lock();
|
auto guard = pHeader->lock.lock();
|
||||||
|
auto result = pCaptureInterface->CaptureFrameTemp(pFrameHeader->bits());
|
||||||
auto result = capture->CaptureFrameTemp(pFrameHeader->bits());
|
|
||||||
|
|
||||||
if(result == hazelnut::DisplayCaptureResult::Ok) {
|
if(result == hazelnut::DisplayCaptureResult::Ok) {
|
||||||
if(firstFrame == false) {
|
// Do nothing.
|
||||||
for(u32 y = 0; y < diff.diffMapHeight; ++y) {
|
|
||||||
for(u32 x = 0; x < diff.diffmapWidth; ++x) {
|
|
||||||
auto& bl = diff.pDiffMap[y * diff.diffmapWidth + x];
|
|
||||||
if(bl != 0) {
|
|
||||||
changed = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if(!changed)
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
} else if(result == hazelnut::DisplayCaptureResult::OkButResized) {
|
} else if(result == hazelnut::DisplayCaptureResult::OkButResized) {
|
||||||
// We resized. Notify of that
|
// We resized. Notify of that
|
||||||
framebuffer = capture->GetFramebufferInformation();
|
framebuffer = pCaptureInterface->GetFramebufferInformation();
|
||||||
diff = capture->GetDiffInformation();
|
diff = pCaptureInterface->GetDiffInformation();
|
||||||
firstFrame = true;
|
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
printf("Failed to capture\n");
|
printf("Failed to capture\n");
|
||||||
break;
|
break;
|
||||||
|
@ -87,13 +67,6 @@ int main(int argc, char** argv) {
|
||||||
pFrameHeader->serial.fetch_add(1);
|
pFrameHeader->serial.fetch_add(1);
|
||||||
pFrameHeader->width.store(framebuffer.width);
|
pFrameHeader->width.store(framebuffer.width);
|
||||||
pFrameHeader->height.store(framebuffer.height);
|
pFrameHeader->height.store(framebuffer.height);
|
||||||
|
|
||||||
// memcpy(pFrameHeader->bits(), &framebuffer.pFramebuffer[0], (framebuffer.width * framebuffer.height) * 4);
|
|
||||||
|
|
||||||
// printf("FRAME SERIAL %u loaded\n", pFrameHeader->serial.load());
|
|
||||||
|
|
||||||
if(firstFrame)
|
|
||||||
firstFrame = false;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,3 +1,5 @@
|
||||||
# shared code
|
# shared code
|
||||||
|
|
||||||
This is shared between the two ends. It is cross platform C++20.
|
This is all of the things shared between the agent and client ends.
|
||||||
|
|
||||||
|
It is cross platform C++20.
|
Loading…
Reference in a new issue