Skip to content

Commit

Permalink
Implemented cclcc character fading
Browse files Browse the repository at this point in the history
  • Loading branch information
PringlesGang committed Feb 7, 2025
1 parent 0c41d2a commit 2e6ef1a
Show file tree
Hide file tree
Showing 22 changed files with 168 additions and 42 deletions.
1 change: 1 addition & 0 deletions profiles/cc/game.lua
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ root.Vm = {
ScrWorkChaStructSize = 40,
ScrWorkBgStructSize = 40,
ScrWorkCaptureStructSize = 40,
ScrWorkBgEffStructSize = 30,
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 @@ -19,6 +19,7 @@ root.Vm = {
ScrWorkChaStructSize = 40,
ScrWorkBgStructSize = 40,
ScrWorkCaptureStructSize = 20,
ScrWorkBgEffStructSize = 30,
MaxLinkedBgBuffers = 2
};

Expand Down
1 change: 1 addition & 0 deletions profiles/chlcc/game.lua
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ root.Vm = {
ScrWorkChaStructSize = 20,
ScrWorkBgStructSize = 20,
ScrWorkCaptureStructSize = 20,
ScrWorkBgEffStructSize = 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 @@ -19,6 +19,7 @@ root.Vm = {
ScrWorkChaStructSize = 40,
ScrWorkBgStructSize = 40,
ScrWorkCaptureStructSize = 20,
ScrWorkBgEffStructSize = 30,
MaxLinkedBgBuffers = 2
};

Expand Down
18 changes: 16 additions & 2 deletions profiles/common/scriptvars.lua
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,9 @@ root.ScriptVars = {
SW_MASK1ALPHA_OFS=2786,
SW_MASK2ALPHA_OFS=2787,
SW_MASK3ALPHA_OFS=2788,
SW_BGEFF1_OFSX=2800,
SW_BGEFF1_OFSY=2801,
SW_BGEFF1_ALPHA_OFS=2806,
SW_MAINTHDP=3304,
SW_RESTARTMASK=3318,
SW_PLATFORM=3319,
Expand Down Expand Up @@ -153,6 +156,7 @@ root.ScriptVars = {
SW_BG1ALPHA=4513,
SW_BG1MASKNO=4514,
SW_BG1MASKFADERANGE=4515,
SW_BG1PRI2=4518,
SW_CAP1POSX=5000,
SW_CAP1POSY=5001,
SW_CAP1SX=5002,
Expand Down Expand Up @@ -237,6 +241,7 @@ root.ScriptVars = {
SW_CHA1FADETYPE=5115,
SW_CHA1ANIME_EYE=5118,
SW_CHA1ANIME_MOUTH=5119,
SW_CHA1PRI2=5120,
SW_CHA1BASESIZE=5121,
SW_CHA1POSX_OFS=2500,
SW_CHA1POSY_OFS=2501,
Expand Down Expand Up @@ -320,8 +325,16 @@ root.ScriptVars = {
SW_AR_ROTMIN=6412,
SW_AR_ROTMAX=6413,
SW_POKECOMIRUOHFOV=6428,
SW_BGEFF_ALPHA=6613,
SW_BGEFF_MODE=6614,
SW_BGEFF1_PRI=6611,
SW_BGEFF1_FADECT=6613,
SW_BGEFF1_MODE=6614,
SW_BGEFF1_ALPHA=6618,
SW_BGEFF1_MASKNO=6619,
SW_BGEFF1_MASKFADERANGE=6620,
SW_BGEFF1_PRI2=6621,
SW_BGEFF1_POSX=6624,
SW_BGEFF1_POSY=6625,
SW_BGEFF1_CAP_BUF=7000,
SW_SAVEMENUMODE=7999, -- This is our own
-- FlagWork
SF_CLR_FLAG=800,
Expand Down Expand Up @@ -369,6 +382,7 @@ root.ScriptVars = {
SF_FACEEX1DISP=2427,
SF_CAP1NOALPHACHK=2458,
SF_CAP2NOALPHACHK=2459,
SF_BGEFF1DISP=2470,
SF_REVADDDISABLE=2483,
SF_MESWINDOW0OPENFL=2502,
SF_Phone_Open=2600,
Expand Down
1 change: 1 addition & 0 deletions profiles/darling/game.lua
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ root.Vm = {
ScrWorkChaStructSize = 40,
ScrWorkBgStructSize = 40,
ScrWorkCaptureStructSize = 20,
ScrWorkBgEffStructSize = 30,
};

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 @@ -15,6 +15,7 @@ root.Vm = {
ScrWorkChaStructSize = 40,
ScrWorkBgStructSize = 40,
ScrWorkCaptureStructSize = 20,
ScrWorkBgEffStructSize = 30,
MaxLinkedBgBuffers = 2
};

Expand Down
1 change: 1 addition & 0 deletions profiles/mo6tw/game.lua
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ root.Vm = {
ScrWorkChaStructSize=20,
ScrWorkBgStructSize=20,
ScrWorkCaptureStructSize=20,
ScrWorkBgEffStructSize = 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 @@ -20,6 +20,7 @@ root.Vm = {
ScrWorkChaStructSize = 40,
ScrWorkBgStructSize = 40,
ScrWorkCaptureStructSize = 20,
ScrWorkBgEffStructSize = 30,
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 @@ -19,6 +19,7 @@ root.Vm = {
ScrWorkChaStructSize = 40,
ScrWorkBgStructSize = 40,
ScrWorkCaptureStructSize = 20,
ScrWorkBgEffStructSize = 30,
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 @@ -15,6 +15,7 @@ root.Vm = {
ScrWorkChaStructSize = 40,
ScrWorkBgStructSize = 40,
ScrWorkCaptureStructSize = 20,
ScrWorkBgEffStructSize = 30,
MaxLinkedBgBuffers = 2
};

Expand Down
1 change: 1 addition & 0 deletions profiles/sgps3/game.lua
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ root.Vm = {
ScrWorkChaStructSize = 20,
ScrWorkBgStructSize = 20,
ScrWorkCaptureStructSize = 20,
ScrWorkBgEffStructSize = 20,
};

include('common/scriptinput.lua');
Expand Down
49 changes: 39 additions & 10 deletions src/background2d.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ void Background2D::UnloadSync() {
BgSpriteSheet.DesignWidth = 0.0f;
BgSpriteSheet.Texture = 0;
Show = false;
Layer = -1;
std::fill(Layers.begin(), Layers.end(), -1);
}

void Background2D::MainThreadOnLoad() {
Expand All @@ -76,13 +76,15 @@ void Background2D::MainThreadOnLoad() {
BgSprite.Bounds =
RectF(0.0f, 0.0f, BgSpriteSheet.DesignWidth, BgSpriteSheet.DesignHeight);
Show = false;
Layer = -1;
std::fill(Layers.begin(), Layers.end(), -1);
}

void Background2D::Render(int bgId, int layer) {
if (Status != LS_Loaded || Layer != layer || !Show) return;
bool Background2D::OnLayer(int layer) {
return std::find(Layers.begin(), Layers.end(), layer) != Layers.end();
}

IsScreencap = false;
void Background2D::Render(int bgId, int layer) {
if (Status != LS_Loaded || !OnLayer(layer) || !Show) return;

MaskNumber = ScrWork[SW_BG1MASKNO + ScrWorkBgStructSize * bgId];
FadeCount = ScrWork[SW_BG1FADECT + ScrWorkBgStructSize * bgId];
Expand All @@ -99,8 +101,9 @@ void Background2D::Render(int bgId, int layer) {
break;

case Vm::InstructionSet::CC:
if (ScrWork[SW_BGEFF_MODE + 30 * bgId] == 1)
col.a = ScrWork[SW_BGEFF_ALPHA + 30 * bgId] / 256.0f;
if (ScrWork[SW_BGEFF1_MODE + ScrWorkBgEffStructSize * bgId] == 1)
col.a =
ScrWork[SW_BGEFF1_ALPHA + ScrWorkBgEffStructSize * bgId] / 256.0f;

default:
break;
Expand All @@ -111,9 +114,7 @@ void Background2D::Render(int bgId, int layer) {
}

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

IsScreencap = true;
if (Status != LS_Loaded || !OnLayer(layer) || !Show) return;

MaskNumber = ScrWork[SW_CAP1MASKNO + ScrWorkCaptureStructSize * capId];
FadeCount = ScrWork[SW_CAP1FADECT + ScrWorkCaptureStructSize * capId];
Expand All @@ -129,6 +130,34 @@ void Background2D::RenderCapture(int capId, int layer) {
BackgroundRenderTable[renderType](this, col);
}

void Background2D::RenderBgEff(int bgId, int layer) {
if (Status != LS_Loaded) return;

const int structSize = ScrWorkBgEffStructSize;

MaskNumber = ScrWork[SW_BGEFF1_MASKNO + structSize * bgId];
FadeCount = 256 - ScrWork[SW_BGEFF1_FADECT + structSize * bgId];
FadeRange = ScrWork[SW_BGEFF1_MASKFADERANGE + structSize * bgId];

float x = ScrWork[SW_BGEFF1_OFSX + 20 * bgId] +
ScrWork[SW_BGEFF1_POSX + structSize * bgId];
float y = ScrWork[SW_BGEFF1_OFSY + 20 * bgId] +
ScrWork[SW_BGEFF1_POSY + structSize * bgId];
x *= Profile::DesignWidth / 1280.0f;
y *= Profile::DesignHeight / 720.0f;
DisplayCoords = glm::vec2(-x, -y);

BgSprite.BaseScale = glm::vec2(1.0f);

glm::vec4 col = glm::vec4(1.0f);
col.a = (ScrWork[SW_BGEFF1_ALPHA + structSize * bgId] +
ScrWork[SW_BGEFF1_ALPHA_OFS + 20 * bgId]) /
256.0f;

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

BackgroundRenderer(RenderRegular) {
Renderer->DrawSprite(
bg->BgSprite,
Expand Down
6 changes: 5 additions & 1 deletion src/background2d.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,18 +46,22 @@ class Background2D : public Loadable<Background2D> {
bool Show;
bool IsScreencap = false;

int Layer;
std::array<int, 2> Layers;
LinkState Links[MaxLinks];

void Render(int bgId, int layer);
void RenderCapture(int capId, int layer);
void RenderBgEff(int bgId, int layer);

void LoadSolidColor(uint32_t color, int width, int height);

protected:
bool LoadSync(uint32_t bgId);
void UnloadSync();
void MainThreadOnLoad();

bool OnLayer(int layer);

private:
Texture BgTexture;
SpriteSheet BgSpriteSheet;
Expand Down
43 changes: 23 additions & 20 deletions src/character2d.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ void Character2D::UnloadSync() {
CharaSpriteSheet.DesignWidth = 0.0f;
CharaSpriteSheet.Texture = 0;
Show = false;
Layer = -1;
std::fill(Layers.begin(), Layers.end(), -1);
if (MvlVertices) {
MvlVerticesCount = 0;
free(MvlVertices);
Expand All @@ -161,7 +161,7 @@ void Character2D::MainThreadOnLoad() {
CharaSprite.Bounds = RectF(0.0f, 0.0f, CharaSpriteSheet.DesignWidth,
CharaSpriteSheet.DesignHeight);
Show = false;
Layer = -1;
std::fill(Layers.begin(), Layers.end(), -1);
}

void Character2D::Update(float dt) {
Expand Down Expand Up @@ -197,25 +197,28 @@ void Character2D::Update(float dt) {
}
}

bool Character2D::OnLayer(int layer) {
return std::find(Layers.begin(), Layers.end(), layer) != Layers.end();
}

void Character2D::Render(int layer) {
if (Status == LS_Loaded && Layer == layer && Show) {
if (Profile::CharaIsMvl) {
Renderer->DrawCharacterMvl(CharaSprite, glm::vec2(OffsetX, OffsetY),
MvlVerticesCount, MvlVertices, MvlIndicesCount,
MvlIndices, false, Tint,
glm::vec2(ScaleX, ScaleY));
} else {
for (auto id : StatesToDraw) {
if (States.count(id)) {
Character2DState state = States[id];
for (int i = 0; i < state.Count; i++) {
CharaSprite.Bounds = RectF(state.TextureCoords[i].x,
state.TextureCoords[i].y, 30.0f, 30.0f);
Renderer->DrawSprite(CharaSprite,
glm::vec2(state.ScreenCoords[i].x + OffsetX,
state.ScreenCoords[i].y + OffsetY),
Tint);
}
if (Status != LS_Loaded || !OnLayer(layer) || !Show) return;

if (Profile::CharaIsMvl) {
Renderer->DrawCharacterMvl(
CharaSprite, glm::vec2(OffsetX, OffsetY), MvlVerticesCount, MvlVertices,
MvlIndicesCount, MvlIndices, false, Tint, glm::vec2(ScaleX, ScaleY));
} else {
for (auto id : StatesToDraw) {
if (States.count(id)) {
Character2DState state = States[id];
for (int i = 0; i < state.Count; i++) {
CharaSprite.Bounds = RectF(state.TextureCoords[i].x,
state.TextureCoords[i].y, 30.0f, 30.0f);
Renderer->DrawSprite(CharaSprite,
glm::vec2(state.ScreenCoords[i].x + OffsetX,
state.ScreenCoords[i].y + OffsetY),
Tint);
}
}
}
Expand Down
4 changes: 3 additions & 1 deletion src/character2d.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ class Character2D : public Loadable<Character2D> {
int LipFrame;
int EyeFrame;
bool Show;
int Layer;
std::array<int, 2> Layers;
glm::vec4 Tint = glm::vec4(1.0f);
void Update(float dt);
void Render(int layer);
Expand All @@ -50,6 +50,8 @@ class Character2D : public Loadable<Character2D> {
void UnloadSync();
void MainThreadOnLoad();

bool OnLayer(int layer);

private:
Texture CharaTexture;
SpriteSheet CharaSpriteSheet;
Expand Down
6 changes: 4 additions & 2 deletions src/debugmenu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -859,7 +859,8 @@ void ShowObjects() {
ImGui::Spacing();
ImGui::BulletText("IsShown: %d", Backgrounds[i].Show);
ImGui::Spacing();
ImGui::BulletText("Layer: %d", Backgrounds[i].Layer);
ImGui::BulletText("Layers: %d, %d", Backgrounds[i].Layers[0],
Backgrounds[i].Layers[1]);
ImGui::Spacing();
ImGui::BulletText("Display coords: (x: %f, y: %f)",
Backgrounds[i].DisplayCoords.x,
Expand Down Expand Up @@ -910,7 +911,8 @@ void ShowObjects() {
ImGui::Spacing();
ImGui::BulletText("IsShown: %d", Characters2D[i].Show);
ImGui::Spacing();
ImGui::BulletText("Layer: %d", Characters2D[i].Layer);
ImGui::BulletText("Layers: %d, %d", Characters2D[i].Layers[0],
Characters2D[i].Layers[1]);
ImGui::Spacing();
ImGui::BulletText("Display coords: (x: %f, y: %f)",
Characters2D[i].OffsetX, Characters2D[i].OffsetY);
Expand Down
Loading

0 comments on commit 2e6ef1a

Please sign in to comment.