Skip to content
This repository was archived by the owner on Jan 5, 2024. It is now read-only.

Commit 74bcde8

Browse files
committed
Refactor screen capture methods
1 parent 8b04269 commit 74bcde8

File tree

2 files changed

+160
-182
lines changed

2 files changed

+160
-182
lines changed

Managers/FrameMan.cpp

Lines changed: 126 additions & 163 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,8 @@ namespace RTE {
5555
m_PlayerScreen = 0;
5656
m_PlayerScreenWidth = 0;
5757
m_PlayerScreenHeight = 0;
58-
m_ScreendumpBuffer = 0;
58+
m_ScreenDumpBuffer = 0;
59+
m_WorldDumpBuffer = 0;
5960
m_BackBuffer8 = 0;
6061
m_BackBuffer32 = 0;
6162
m_DrawNetworkBackBuffer = false;
@@ -290,6 +291,8 @@ namespace RTE {
290291
}
291292
destroy_bitmap(m_BackBuffer32);
292293
destroy_bitmap(m_PlayerScreen);
294+
destroy_bitmap(m_ScreenDumpBuffer);
295+
destroy_bitmap(m_WorldDumpBuffer);
293296
delete m_GUIScreen;
294297
delete m_LargeFont;
295298
delete m_SmallFont;
@@ -535,16 +538,70 @@ namespace RTE {
535538
return true;
536539
}
537540

541+
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
542+
543+
int FrameMan::SaveBitmap(SaveBitmapMode modeToSave, const char *nameBase, BITMAP *bitmapToSave) {
544+
if (modeToSave == WorldDump && !g_ActivityMan.ActivityRunning()) {
538545
return 0;
539546
}
540547

548+
if (nameBase == 0 || strlen(nameBase) <= 0) {
549+
return -1;
541550
}
542551

552+
unsigned short fileNumber = 0;
553+
unsigned short maxFileTrys = 1000;
554+
char fullFileName[256];
543555

556+
while (fileNumber < maxFileTrys) {
557+
// Check for the file namebase001.bmp; if it exists, try 002, etc.
558+
sprintf_s(fullFileName, sizeof(fullFileName), "%s%03i.bmp", nameBase, fileNumber++);
559+
if (!std::experimental::filesystem::exists(fullFileName)) {
560+
break;
544561
}
562+
}
545563

564+
PALETTE palette;
565+
get_palette(palette);
546566

567+
switch (modeToSave) {
568+
case SingleBitmap:
569+
if (bitmapToSave) {
570+
save_bmp(fullFileName, bitmapToSave, palette);
571+
g_ConsoleMan.PrintString("SYSTEM: Bitmap was dumped to: " + std::string(fullFileName));
572+
return 0;
573+
}
574+
break;
575+
case ScreenDump:
576+
if (screen) {
577+
if (!m_ScreenDumpBuffer) { m_ScreenDumpBuffer = create_bitmap(screen->w, screen->h); }
578+
579+
blit(screen, m_ScreenDumpBuffer, 0, 0, 0, 0, screen->w, screen->h);
580+
save_bmp(fullFileName, m_ScreenDumpBuffer, palette);
581+
g_ConsoleMan.PrintString("SYSTEM: Screen was dumped to: " + std::string(fullFileName));
582+
return 0;
583+
}
584+
break;
585+
case WorldDump:
586+
if (!m_WorldDumpBuffer) {
587+
m_WorldDumpBuffer = create_bitmap(g_SceneMan.GetSceneWidth(), g_SceneMan.GetSceneHeight());
588+
} else {
589+
// Recreate the buffer if the dimensions don't match the current scene.
590+
if (m_WorldDumpBuffer->w != g_SceneMan.GetSceneWidth() || m_WorldDumpBuffer->h != g_SceneMan.GetSceneHeight()) {
591+
m_WorldDumpBuffer = create_bitmap(g_SceneMan.GetSceneWidth(), g_SceneMan.GetSceneHeight());
592+
}
593+
DrawWorldDump();
594+
save_bmp(fullFileName, m_WorldDumpBuffer, palette);
595+
g_ConsoleMan.PrintString("SYSTEM: World was dumped to: " + string(fullFileName));
596+
return 0;
597+
}
598+
break;
599+
default:
600+
g_ConsoleMan.PrintString("ERROR: Wrong bitmap save mode passed in, no bitmap was saved!");
601+
return -1;
547602
}
603+
g_ConsoleMan.PrintString("ERROR: Unable to save bitmap to: " + std::string(fullFileName));
604+
return -1;
548605
}
549606

550607
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
@@ -646,168 +703,6 @@ namespace RTE {
646703
return skipped;
647704
}
648705

649-
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
650-
651-
int FrameMan::SaveScreenToBMP(const char *nameBase) {
652-
int filenumber = 0;
653-
char fullfilename[256];
654-
int maxFileTrys = 1000;
655-
656-
if (nameBase == 0 || strlen(nameBase) <= 0) {
657-
return -1;
658-
}
659-
660-
do {
661-
// Check for the file namebase001.bmp; if it exists, try 002, etc.
662-
sprintf_s(fullfilename, sizeof(fullfilename), "%s%03i.bmp", nameBase, filenumber++);
663-
if (!std::experimental::filesystem::exists(fullfilename)) {
664-
break;
665-
}
666-
} while (filenumber < maxFileTrys);
667-
668-
// Save out the screen bitmap, after making a copy of it, faster sometimes
669-
if (screen) {
670-
if (!m_ScreendumpBuffer) { m_ScreendumpBuffer = create_bitmap(screen->w, screen->h); }
671-
672-
blit(screen, m_ScreendumpBuffer, 0, 0, 0, 0, screen->w, screen->h);
673-
PALETTE palette;
674-
get_palette(palette);
675-
save_bmp(fullfilename, m_ScreendumpBuffer, palette);
676-
677-
g_ConsoleMan.PrintString("SYSTEM: Screen was dumped to: " + string(fullfilename));
678-
}
679-
return 0;
680-
}
681-
682-
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
683-
684-
int FrameMan::SaveWorldToBMP(const char *nameBase) {
685-
if (!g_ActivityMan.ActivityRunning()) {
686-
return 0;
687-
}
688-
689-
int filenumber = 0;
690-
char fullfilename[256];
691-
int maxFileTrys = 1000;
692-
693-
// Make sure its not a 0 name base
694-
if (nameBase == 0 || strlen(nameBase) <= 0) {
695-
return -1;
696-
}
697-
698-
do {
699-
// Check for the file namebase001.bmp; if it exists, try 002, etc.
700-
sprintf_s(fullfilename, sizeof(fullfilename), "%s%03i.bmp", nameBase, filenumber++);
701-
if (!std::experimental::filesystem::exists(fullfilename)) {
702-
break;
703-
}
704-
} while (filenumber < maxFileTrys);
705-
706-
707-
BITMAP * pWorldBitmap = create_bitmap_ex(32, g_SceneMan.GetSceneWidth(), g_SceneMan.GetSceneHeight());
708-
Vector targetPos(0, 0);
709-
std::list<PostEffect> postEffects;
710-
711-
if (pWorldBitmap) {
712-
clear_to_color(pWorldBitmap, makecol32(132, 192, 252)); // Light blue color
713-
714-
//Draw sky gradient
715-
for (int i = 0; i < pWorldBitmap->h; i++) {
716-
hline(pWorldBitmap, 0, i, pWorldBitmap->w - 1, makecol32(64 + (((float)i / (float)pWorldBitmap->h) * (128 - 64)), 64 + (((float)i / (float)pWorldBitmap->h) * (192 - 64)), 96 + ((float)i / (float)pWorldBitmap->h) * (255 - 96)));
717-
}
718-
719-
// Draw scene
720-
draw_sprite(pWorldBitmap, g_SceneMan.GetTerrain()->GetBGColorBitmap(), 0, 0);
721-
draw_sprite(pWorldBitmap, g_SceneMan.GetTerrain()->GetFGColorBitmap(), 0, 0);
722-
723-
//Draw objects
724-
draw_sprite(pWorldBitmap, g_SceneMan.GetMOColorBitmap(), 0, 0);
725-
726-
g_PostProcessMan.GetPostScreenEffectsWrapped(targetPos, pWorldBitmap->w, pWorldBitmap->h, postEffects, -1);
727-
728-
//Draw post-effects
729-
BITMAP *pBitmap = 0;
730-
int effectPosX = 0;
731-
int effectPosY = 0;
732-
int strength = 0;
733-
float angle = 0;
734-
735-
for (list<PostEffect>::iterator eItr = postEffects.begin(); eItr != postEffects.end(); ++eItr) {
736-
pBitmap = (*eItr).m_Bitmap;
737-
strength = (*eItr).m_Strength;
738-
set_screen_blender(strength, strength, strength, strength);
739-
effectPosX = (*eItr).m_Pos.GetFloorIntX() - (pBitmap->w / 2);
740-
effectPosY = (*eItr).m_Pos.GetFloorIntY() - (pBitmap->h / 2);
741-
angle = (*eItr).m_Angle;
742-
743-
if (angle == 0) {
744-
draw_trans_sprite(pWorldBitmap, pBitmap, effectPosX, effectPosY);
745-
} else {
746-
BITMAP * pTargetBitmap;
747-
748-
if (pBitmap->w < 16 && pBitmap->h < 16) {
749-
pTargetBitmap = g_PostProcessMan.GetTempEffectBitmap(16);
750-
} else if (pBitmap->w < 32 && pBitmap->h < 32) {
751-
pTargetBitmap = g_PostProcessMan.GetTempEffectBitmap(32);
752-
} else if (pBitmap->w < 64 && pBitmap->h < 64) {
753-
pTargetBitmap = g_PostProcessMan.GetTempEffectBitmap(64);
754-
} else if (pBitmap->w < 128 && pBitmap->h < 128) {
755-
pTargetBitmap = g_PostProcessMan.GetTempEffectBitmap(128);
756-
} else if (pBitmap->w < 256 && pBitmap->h < 256) {
757-
pTargetBitmap = g_PostProcessMan.GetTempEffectBitmap(256);
758-
} else {
759-
pTargetBitmap = g_PostProcessMan.GetTempEffectBitmap(512);
760-
}
761-
clear_to_color(pTargetBitmap, 0);
762-
763-
fixed fAngle;
764-
fAngle = fixmul(angle, radtofix_r);
765-
766-
rotate_sprite(pTargetBitmap, pBitmap, 0, 0, fAngle);
767-
draw_trans_sprite(pWorldBitmap, pTargetBitmap, effectPosX, effectPosY);
768-
}
769-
}
770-
771-
PALETTE palette;
772-
get_palette(palette);
773-
save_bmp(fullfilename, pWorldBitmap, palette);
774-
775-
g_ConsoleMan.PrintString("SYSTEM: World was dumped to: " + string(fullfilename));
776-
777-
destroy_bitmap(pWorldBitmap);
778-
}
779-
return 0;
780-
}
781-
782-
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
783-
784-
int FrameMan::SaveBitmapToBMP(BITMAP *bitmap, const char *nameBase) {
785-
int filenumber = 0;
786-
char fullfilename[256];
787-
int maxFileTrys = 1000;
788-
789-
// Make sure its not a 0 name base
790-
if (nameBase == 0 || strlen(nameBase) <= 0) {
791-
return -1;
792-
}
793-
794-
do {
795-
// Check for the file namebase001.bmp; if it exists, try 002, etc.
796-
sprintf_s(fullfilename, sizeof(fullfilename), "%s%03i.bmp", nameBase, filenumber++);
797-
if (!std::experimental::filesystem::exists(fullfilename)) {
798-
break;
799-
}
800-
} while (filenumber < maxFileTrys);
801-
802-
// Save out the bitmap
803-
if (bitmap) {
804-
PALETTE palette;
805-
get_palette(palette);
806-
save_bmp(fullfilename, bitmap, palette);
807-
}
808-
return 0;
809-
}
810-
811706
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
812707

813708
GUIFont * FrameMan::GetFont(bool isSmall) {
@@ -1131,4 +1026,72 @@ namespace RTE {
11311026
if (m_FlashTimer[playerScreen].IsPastRealTimeLimit()) { m_FlashScreenColor[playerScreen] = -1; }
11321027
}
11331028
}
1029+
1030+
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
1031+
1032+
void FrameMan::DrawWorldDump() {
1033+
float worldBitmapWidth = static_cast<float>(m_WorldDumpBuffer->w);
1034+
float worldBitmapHeight = static_cast<float>(m_WorldDumpBuffer->h);
1035+
BITMAP *bitmap = 0;
1036+
int effectPosX = 0;
1037+
int effectPosY = 0;
1038+
int strength = 0;
1039+
float angle = 0;
1040+
Vector targetPos(0, 0);
1041+
std::list<PostEffect> postEffects;
1042+
1043+
clear_to_color(m_WorldDumpBuffer, makecol32(132, 192, 252)); // Light blue color
1044+
1045+
// Draw sky gradient
1046+
for (int i = 0; i < m_WorldDumpBuffer->h; i++) {
1047+
int lineColor = makecol32(64 + ((static_cast<float>(i) / worldBitmapHeight) * (128 - 64)), 64 + ((static_cast<float>(i) / worldBitmapHeight) * (192 - 64)), 96 + ((static_cast<float>(i) / worldBitmapHeight) * (255 - 96)));
1048+
hline(m_WorldDumpBuffer, 0, i, worldBitmapWidth - 1, lineColor);
1049+
}
1050+
1051+
// Draw scene
1052+
draw_sprite(m_WorldDumpBuffer, g_SceneMan.GetTerrain()->GetBGColorBitmap(), 0, 0);
1053+
draw_sprite(m_WorldDumpBuffer, g_SceneMan.GetTerrain()->GetFGColorBitmap(), 0, 0);
1054+
1055+
// Draw objects
1056+
draw_sprite(m_WorldDumpBuffer, g_SceneMan.GetMOColorBitmap(), 0, 0);
1057+
1058+
//Draw post-effects
1059+
g_PostProcessMan.GetPostScreenEffectsWrapped(targetPos, worldBitmapWidth, worldBitmapHeight, postEffects, -1);
1060+
1061+
for (list<PostEffect>::iterator eItr = postEffects.begin(); eItr != postEffects.end(); ++eItr) {
1062+
bitmap = (*eItr).m_Bitmap;
1063+
strength = (*eItr).m_Strength;
1064+
set_screen_blender(strength, strength, strength, strength);
1065+
effectPosX = (*eItr).m_Pos.GetFloorIntX() - (bitmap->w / 2);
1066+
effectPosY = (*eItr).m_Pos.GetFloorIntY() - (bitmap->h / 2);
1067+
angle = (*eItr).m_Angle;
1068+
1069+
if (angle == 0) {
1070+
draw_trans_sprite(m_WorldDumpBuffer, bitmap, effectPosX, effectPosY);
1071+
} else {
1072+
BITMAP * targetBitmap;
1073+
1074+
if (bitmap->w < 16 && bitmap->h < 16) {
1075+
targetBitmap = g_PostProcessMan.GetTempEffectBitmap(16);
1076+
} else if (bitmap->w < 32 && bitmap->h < 32) {
1077+
targetBitmap = g_PostProcessMan.GetTempEffectBitmap(32);
1078+
} else if (bitmap->w < 64 && bitmap->h < 64) {
1079+
targetBitmap = g_PostProcessMan.GetTempEffectBitmap(64);
1080+
} else if (bitmap->w < 128 && bitmap->h < 128) {
1081+
targetBitmap = g_PostProcessMan.GetTempEffectBitmap(128);
1082+
} else if (bitmap->w < 256 && bitmap->h < 256) {
1083+
targetBitmap = g_PostProcessMan.GetTempEffectBitmap(256);
1084+
} else {
1085+
targetBitmap = g_PostProcessMan.GetTempEffectBitmap(512);
1086+
}
1087+
clear_to_color(targetBitmap, 0);
1088+
1089+
fixed fAngle;
1090+
fAngle = fixmul(angle, radtofix_r);
1091+
1092+
rotate_sprite(targetBitmap, bitmap, 0, 0, fAngle);
1093+
draw_trans_sprite(m_WorldDumpBuffer, targetBitmap, effectPosX, effectPosY);
1094+
}
1095+
}
1096+
}
11341097
}

0 commit comments

Comments
 (0)