Skip to content
This repository was archived by the owner on Apr 24, 2025. It is now read-only.

Commit e962979

Browse files
author
Sharkbyteprojects
committed
UPD
1 parent c8773a0 commit e962979

File tree

3 files changed

+54
-95
lines changed

3 files changed

+54
-95
lines changed

Readme.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,5 @@ To build and run it, read the readme in the folder "pong"
55
PONG Demo Video: https://www.youtube.com/watch?v=k8m1xTdgU7g
66

77
To build this, you need Visual Studio with C++ Desktopdev and an installation of VCPKG (https://vcpkg.io/en/getting-started.html)
8+
9+
Something is working ONLY in Release x64 Builds!

pong/Readme.txt

Lines changed: 0 additions & 21 deletions
This file was deleted.

pong/pong.cpp

Lines changed: 52 additions & 74 deletions
Original file line numberDiff line numberDiff line change
@@ -291,14 +291,18 @@ void renderThreadp(
291291
//PREPARE RECORD
292292
bool preco = (record != nullptr ? *record : false),
293293
featureRec = record != nullptr;
294-
std::queue<Texture> records;
294+
size_t sizevid = size[0] * size[1] * sizeof(unsigned char);
295+
296+
unsigned char* calced = (unsigned char*)malloc(sizevid * 3);
297+
VideoCapture vc;
298+
vc.Init(size[0], size[1], 24, 400000);
295299
//END PREPARE RECORD
296300

297301
//GL CONTEXT
298302
window->setActive(true);
299303
timer fpsTime;
300304
fpsTime.beginTime();
301-
305+
bool rec = 0;
302306
const int fps[]{ 25, 400 };
303307

304308
window->setFramerateLimit(fps[preco ? 0 : 1]);
@@ -311,16 +315,24 @@ void renderThreadp(
311315
window->setFramerateLimit(fps[preco ? 0 : 1]);
312316
}
313317
if (preco) {
314-
if (10000 >= records.size() + 1) {
315-
sf::Vector2u windowSize = window->getSize();
316-
sf::Texture texture;
317-
texture.create(windowSize.x, windowSize.y);
318-
texture.update(*window);
319-
records.push(texture);
320-
//records.push_back(texture);
318+
sf::Vector2u windowSize = window->getSize();
319+
sf::Texture texture;
320+
texture.create(windowSize.x, windowSize.y);
321+
texture.update(*window);
322+
Image i = texture.copyToImage();
323+
const unsigned char* ux = i.getPixelsPtr();
324+
//RGBA TO RGB:
325+
for (size_t xr{ 0 }, xct{ 0 }, srx{ 0 }; xr < (sizevid * 4); xr++) {
326+
if (xct >= 3) {
327+
xct = 0;
328+
continue;
329+
}
330+
calced[srx] = ux[xr];
331+
xct++;
332+
srx++;
321333
}
322-
else
323-
*record = false;
334+
vc.AddFrame(calced);
335+
rec = 1;
324336
}
325337
}
326338

@@ -342,69 +354,35 @@ void renderThreadp(
342354
}
343355

344356
//SAVE RECORDED IMAGES
345-
if (records.size() > 0) {
346-
const char rp[] = " Recorded Video";
347-
if (MessageBoxA(NULL,
348-
("We need to Save your " + std::to_string(records.size()) + rp +
349-
"\nThis can take some time").c_str(),
350-
gm, MB_OKCANCEL
351-
| MB_DEFBUTTON2 |
352-
MB_ICONINFORMATION |
353-
MB_TOPMOST) == IDCANCEL)
354-
return;
355-
356-
size_t sizevid = size[0] * size[1] * sizeof(unsigned char);
357-
unsigned char* calced = (unsigned char*)malloc(sizevid * 3);
358-
VideoCapture vc;
359-
vc.Init(size[0], size[1], 24, 400000);
360-
while (records.size() > 0) {
361-
Image i = records.front().copyToImage();
362-
records.pop();
363-
const unsigned char* ux = i.getPixelsPtr();
364-
//RGBA TO RGB:
365-
for (size_t xr{ 0 }, xct{ 0 }, srx{ 0 }; xr < (sizevid * 4); xr++) {
366-
if (xct >= 3) {
367-
xct = 0;
368-
continue;
369-
}
370-
calced[srx] = ux[xr];
371-
xct++;
372-
srx++;
373-
}
374-
375-
vc.AddFrame(calced);
376-
}
377-
free(calced);
378-
vc.Finish();
379-
380-
//MOVE
381-
auto dp = std::string(getDocPath()),
382-
np = std::string(rndst(10));
383-
retryFs:
384-
385-
if (std::filesystem::exists(dp + "\\" + np + ".mp4")) {
386-
np = rndst(16);
387-
goto retryFs;
388-
}
389-
390-
std::string cfn = (dp + "\\" + np + ".mp4");
391-
const char tmpn[] = "recordTMP.mp4";
392-
bool ok = false;
393-
if (std::filesystem::exists(tmpn)) {
394-
ok = std::filesystem::copy_file(tmpn, cfn.c_str());
395-
if (ok)
396-
std::filesystem::remove(tmpn);
397-
}
357+
free(calced);
358+
vc.Finish();
359+
360+
//MOVE
361+
auto dp = std::string(getDocPath()),
362+
np = std::string(rndst(10));
363+
retryFs:
364+
if (!rec) return;
365+
if (std::filesystem::exists(dp + "\\" + np + ".mp4")) {
366+
np = rndst(16);
367+
goto retryFs;
368+
}
398369

370+
std::string cfn = (dp + "\\" + np + ".mp4");
371+
const char tmpn[] = "recordTMP.mp4";
372+
bool ok = false;
373+
if (std::filesystem::exists(tmpn)) {
374+
ok = std::filesystem::copy_file(tmpn, cfn.c_str());
399375
if (ok)
400-
MessageBoxA(NULL,
401-
("Saved all your " + std::to_string(records.size()) + rp +
402-
" to \"" + cfn + "\"").c_str(),
403-
gm, MB_OK | MB_ICONINFORMATION | MB_TOPMOST);
404-
else
405-
MessageBoxA(NULL,
406-
("Failue during Save of your" + std::string(rp)).c_str(),
407-
gm, MB_OK | MB_ICONHAND | MB_TOPMOST);
408-
//}
376+
std::filesystem::remove(tmpn);
409377
}
410-
}
378+
379+
if (ok)
380+
MessageBoxA(NULL,
381+
("Saved your Video to \"" + cfn + "\"").c_str(),
382+
gm, MB_OK | MB_ICONINFORMATION | MB_TOPMOST);
383+
else
384+
MessageBoxA(NULL,
385+
"Failue during Save of your Video",
386+
gm, MB_OK | MB_ICONHAND | MB_TOPMOST);
387+
//}
388+
}

0 commit comments

Comments
 (0)