Skip to content

Commit

Permalink
Implemented screencap rendering
Browse files Browse the repository at this point in the history
  • Loading branch information
PringlesGang committed Feb 7, 2025
1 parent 1a64efe commit 0c41d2a
Show file tree
Hide file tree
Showing 16 changed files with 102 additions and 31 deletions.
1 change: 1 addition & 0 deletions profiles/cc/game.lua
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ root.Vm = {
UseReturnIds = true,
ScrWorkChaStructSize = 40,
ScrWorkBgStructSize = 40,
ScrWorkCaptureStructSize = 40,
MaxLinkedBgBuffers = 2
};

Expand Down
1 change: 1 addition & 0 deletions profiles/cclcc/game.lua
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ root.Vm = {
UseReturnIds = true,
ScrWorkChaStructSize = 40,
ScrWorkBgStructSize = 40,
ScrWorkCaptureStructSize = 20,
MaxLinkedBgBuffers = 2
};

Expand Down
3 changes: 2 additions & 1 deletion profiles/chlcc/game.lua
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ root.Vm = {
GameInstructionSet = InstructionSet.CHLCC,
UseReturnIds = false,
ScrWorkChaStructSize = 20,
ScrWorkBgStructSize = 20
ScrWorkBgStructSize = 20,
ScrWorkCaptureStructSize = 20,
};

include('common/scriptinput.lua');
Expand Down
1 change: 1 addition & 0 deletions profiles/chn/game.lua
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ root.Vm = {
UseSeparateMsbArchive = true,
ScrWorkChaStructSize = 40,
ScrWorkBgStructSize = 40,
ScrWorkCaptureStructSize = 20,
MaxLinkedBgBuffers = 2
};

Expand Down
3 changes: 2 additions & 1 deletion profiles/darling/game.lua
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ root.Vm = {
GameInstructionSet = InstructionSet.Darling,
UseReturnIds = true,
ScrWorkChaStructSize = 40,
ScrWorkBgStructSize = 40
ScrWorkBgStructSize = 40,
ScrWorkCaptureStructSize = 20,
};

include('common/scriptinput.lua');
Expand Down
1 change: 1 addition & 0 deletions profiles/dash/game.lua
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ root.Vm = {
UseReturnIds = true,
ScrWorkChaStructSize = 40,
ScrWorkBgStructSize = 40,
ScrWorkCaptureStructSize = 20,
MaxLinkedBgBuffers = 2
};

Expand Down
3 changes: 2 additions & 1 deletion profiles/mo6tw/game.lua
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ root.Vm = {
UseReturnIds=false,
RestartMaskUsesThreadAlpha=true,
ScrWorkChaStructSize=20,
ScrWorkBgStructSize=20
ScrWorkBgStructSize=20,
ScrWorkCaptureStructSize=20,
};

include('common/scriptinput.lua');
Expand Down
1 change: 1 addition & 0 deletions profiles/mo7/game.lua
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ root.Vm = {
UseReturnIds = true,
ScrWorkChaStructSize = 40,
ScrWorkBgStructSize = 40,
ScrWorkCaptureStructSize = 20,
MaxLinkedBgBuffers = 2
};

Expand Down
1 change: 1 addition & 0 deletions profiles/mo8/game.lua
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ root.Vm = {
UseMsbStrings = true,
ScrWorkChaStructSize = 40,
ScrWorkBgStructSize = 40,
ScrWorkCaptureStructSize = 20,
MaxLinkedBgBuffers = 2
};

Expand Down
1 change: 1 addition & 0 deletions profiles/rne/game.lua
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ root.Vm = {
UseReturnIds = true,
ScrWorkChaStructSize = 40,
ScrWorkBgStructSize = 40,
ScrWorkCaptureStructSize = 20,
MaxLinkedBgBuffers = 2
};

Expand Down
3 changes: 2 additions & 1 deletion profiles/sgps3/game.lua
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ root.Vm = {
GameInstructionSet = InstructionSet.SGPS3,
UseReturnIds = false,
ScrWorkChaStructSize = 20,
ScrWorkBgStructSize = 20
ScrWorkBgStructSize = 20,
ScrWorkCaptureStructSize = 20,
};

include('common/scriptinput.lua');
Expand Down
73 changes: 51 additions & 22 deletions src/background2d.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -80,17 +80,53 @@ void Background2D::MainThreadOnLoad() {
}

void Background2D::Render(int bgId, int layer) {
if (Status == LS_Loaded && Layer == layer && Show) {
glm::vec4 col = glm::vec4(1.0f);
if (GameInstructionSet == +Vm::InstructionSet::Dash) {
if (Status != LS_Loaded || Layer != layer || !Show) return;

IsScreencap = false;

MaskNumber = ScrWork[SW_BG1MASKNO + ScrWorkBgStructSize * bgId];
FadeCount = ScrWork[SW_BG1FADECT + ScrWorkBgStructSize * bgId];
FadeRange = ScrWork[SW_BG1MASKFADERANGE + ScrWorkBgStructSize * bgId];

glm::vec4 col = glm::vec4(1.0f);
col.a = (ScrWork[SW_BG1ALPHA + ScrWorkBgStructSize * bgId] +
ScrWork[SW_BG1ALPHA_OFS + 10 * bgId]) /
256.0f;

switch (GameInstructionSet) {
case Vm::InstructionSet::Dash:
col.a = ScrWork[SW_BG1ALPHA + ScrWorkBgStructSize * bgId] / 256.0f;
} else if (GameInstructionSet == +Vm::InstructionSet::CC) {
break;

case Vm::InstructionSet::CC:
if (ScrWork[SW_BGEFF_MODE + 30 * bgId] == 1)
col.a = ScrWork[SW_BGEFF_ALPHA + 30 * bgId] / 256.0f;
}
int renderType = ScrWork[SW_BG1FADETYPE + ScrWorkBgStructSize * bgId];
BackgroundRenderTable[renderType](this, bgId, col);

default:
break;
}

const int renderType = ScrWork[SW_BG1FADETYPE + ScrWorkBgStructSize * bgId];
BackgroundRenderTable[renderType](this, col);
}

void Background2D::RenderCapture(int capId, int layer) {
if (Status != LS_Loaded || Layer != layer || !Show) return;

IsScreencap = true;

MaskNumber = ScrWork[SW_CAP1MASKNO + ScrWorkCaptureStructSize * capId];
FadeCount = ScrWork[SW_CAP1FADECT + ScrWorkCaptureStructSize * capId];
FadeRange = ScrWork[SW_CAP1MASKFADERANGE + ScrWorkCaptureStructSize * capId];

glm::vec4 col = glm::vec4(1.0f);
col.a = (ScrWork[SW_CAP1ALPHA + ScrWorkCaptureStructSize * capId] +
ScrWork[SW_CAP1ALPHA_OFS + 10 * capId]) /
256.0f;

const int renderType =
ScrWork[SW_CAP1FADETYPE + ScrWorkCaptureStructSize * capId];
BackgroundRenderTable[renderType](this, col);
}

BackgroundRenderer(RenderRegular) {
Expand All @@ -99,6 +135,7 @@ BackgroundRenderer(RenderRegular) {
RectF(bg->DisplayCoords.x, bg->DisplayCoords.y,
bg->BgSprite.ScaledWidth(), bg->BgSprite.ScaledHeight()),
col, 0.0f, false, bg->IsScreencap);

for (int i = 0; i < MaxLinkedBgBuffers; i++) {
if (bg->Links[i].Direction != LD_Off && bg->Links[i].LinkedBuffer != NULL) {
Renderer->DrawSprite(
Expand All @@ -113,37 +150,29 @@ BackgroundRenderer(RenderRegular) {

BackgroundRenderer(RenderMasked) {
Renderer->DrawMaskedSprite(
bg->BgSprite,
Masks2D[ScrWork[SW_BG1MASKNO + ScrWorkBgStructSize * bgId]].MaskSprite,
bg->BgSprite, Masks2D[bg->MaskNumber].MaskSprite,
RectF(bg->DisplayCoords.x, bg->DisplayCoords.y,
bg->BgSprite.ScaledWidth(), bg->BgSprite.ScaledHeight()),
col, ScrWork[SW_BG1FADECT + ScrWorkBgStructSize * bgId],
ScrWork[SW_BG1MASKFADERANGE + ScrWorkBgStructSize * bgId],
bg->IsScreencap);
col, bg->FadeCount, bg->FadeRange, bg->IsScreencap);
}

BackgroundRenderer(RenderMaskedInverted) {
Renderer->DrawMaskedSprite(
bg->BgSprite,
Masks2D[ScrWork[SW_BG1MASKNO + ScrWorkBgStructSize * bgId]].MaskSprite,
bg->BgSprite, Masks2D[bg->MaskNumber].MaskSprite,
RectF(bg->DisplayCoords.x, bg->DisplayCoords.y,
bg->BgSprite.ScaledWidth(), bg->BgSprite.ScaledHeight()),
col, ScrWork[SW_BG1FADECT + ScrWorkBgStructSize * bgId],
ScrWork[SW_BG1MASKFADERANGE + ScrWorkBgStructSize * bgId],
bg->IsScreencap, true);
col, bg->FadeCount, bg->FadeRange, bg->IsScreencap, true);
}

BackgroundRenderer(RenderFade) {
col.a = ((ScrWork[SW_BG1FADECT + ScrWorkBgStructSize * bgId] *
(ScrWork[SW_BG1ALPHA + ScrWorkBgStructSize * bgId] +
ScrWork[SW_BG1ALPHA_OFS + 10 * bgId])) >>
8) /
256.0f;
col.a *= bg->FadeCount / 256.0f;

Renderer->DrawSprite(
bg->BgSprite,
RectF(bg->DisplayCoords.x, bg->DisplayCoords.y,
bg->BgSprite.ScaledWidth(), bg->BgSprite.ScaledHeight()),
col, 0.0f, false, bg->IsScreencap);

for (int i = 0; i < MaxLinkedBgBuffers; i++) {
if (bg->Links[i].Direction != LD_Off && bg->Links[i].LinkedBuffer != NULL) {
Renderer->DrawSprite(
Expand Down
16 changes: 12 additions & 4 deletions src/background2d.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@
#include "spritesheet.h"
#include "loadable.h"

#define BackgroundRenderer(name) \
void name(Background2D* bg, int bgId, glm::vec4 col)
#define BackgroundRenderer(name) void name(Background2D* bg, glm::vec4 col)

namespace Impacto {

Expand Down Expand Up @@ -37,12 +36,21 @@ class Background2D : public Loadable<Background2D> {
static void Init();

Sprite BgSprite;

glm::vec2 DisplayCoords;
LinkState Links[MaxLinks];
int MaskNumber;

int FadeCount;
int FadeRange;

bool Show;
bool IsScreencap = false;

int Layer;
LinkState Links[MaxLinks];

void Render(int bgId, int layer);
void RenderCapture(int capId, int layer);
void LoadSolidColor(uint32_t color, int width, int height);

protected:
Expand All @@ -55,7 +63,7 @@ class Background2D : public Loadable<Background2D> {
SpriteSheet BgSpriteSheet;
};

typedef void (*BackgroundRenderProc)(Background2D* bg, int bgId, glm::vec4 col);
typedef void (*BackgroundRenderProc)(Background2D* bg, glm::vec4 col);

int constexpr MaxBackgrounds2D = 8;
int constexpr MaxScreencaptures = 2;
Expand Down
11 changes: 11 additions & 0 deletions src/game.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -355,6 +355,17 @@ void Render() {
}
}

for (size_t capId = 0; capId <= 1; capId++) {
if (!GetFlag(SF_CAP1DISP + capId)) continue;

for (size_t capLayer = 0; capLayer <= 1; capLayer++) {
if (ScrWork[SW_CAP1PRI + capLayer * 10 + capLayer * 8] ==
layer) {
Screencaptures[capId].RenderCapture(capId, layer);
}
}
}

if (Profile::UseScreenCapEffects) {
if (ScrWork[SW_EFF_CAP_BUF] &&
ScrWork[SW_EFF_CAP_PRI] == static_cast<int>(layer)) {
Expand Down
8 changes: 7 additions & 1 deletion src/profile/vm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,24 @@ void Configure() {

StartScript = EnsureGetMemberUint("StartScript");
StartScriptBuffer = EnsureGetMemberUint("StartScriptBuffer");

GameInstructionSet = Impacto::Vm::InstructionSet::_from_integral_unchecked(
EnsureGetMemberInt("GameInstructionSet"));

UseReturnIds = EnsureGetMemberBool("UseReturnIds");
TryGetMemberBool("UseMsbStrings", UseMsbStrings);
TryGetMemberBool("UseSeparateMsbArchive", UseSeparateMsbArchive);
TryGetMemberBool("RestartMaskUsesThreadAlpha", RestartMaskUsesThreadAlpha);

ScrWorkChaStructSize = EnsureGetMemberInt("ScrWorkChaStructSize");
ScrWorkBgStructSize = EnsureGetMemberInt("ScrWorkBgStructSize");
ScrWorkCaptureStructSize = EnsureGetMemberInt("ScrWorkCaptureStructSize");

TryGetMemberInt("MaxLinkedBgBuffers", MaxLinkedBgBuffers);
TryGetMemberInt("SystemScriptBuffer", SystemScriptBuffer);

TryGetMemberInt("SpeakerPortraitsScrWorkOffset",
SpeakerPortraitsScrWorkOffset);
TryGetMemberBool("RestartMaskUsesThreadAlpha", RestartMaskUsesThreadAlpha);

Pop();
}
Expand Down
6 changes: 6 additions & 0 deletions src/profile/vm.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,22 @@ namespace Vm {

inline uint32_t StartScript;
inline uint32_t StartScriptBuffer;

inline Impacto::Vm::InstructionSet GameInstructionSet =
Impacto::Vm::InstructionSet::RNE;

inline bool UseReturnIds = true;
inline bool UseMsbStrings = false;
inline bool UseSeparateMsbArchive = false;
inline bool RestartMaskUsesThreadAlpha = false;

inline int ScrWorkChaStructSize;
inline int ScrWorkBgStructSize;
inline int ScrWorkCaptureStructSize;

inline int MaxLinkedBgBuffers = 1;
inline int SystemScriptBuffer = 1;

inline int SpeakerPortraitsScrWorkOffset = 8;

void Configure();
Expand Down

0 comments on commit 0c41d2a

Please sign in to comment.