Make chroma key stage fully customizable

This commit is contained in:
Llennpie 2022-03-16 03:06:25 -04:00
parent 9d62b55bd1
commit 55ded0990d
13 changed files with 185 additions and 9 deletions

View file

@ -359,6 +359,11 @@
#define GEO_BACKGROUND_COLOR(background) \
GEO_BACKGROUND(background, NULL)
// 0x21: Dynamic background color
#define GEO_BACKGROUND_DYN() \
CMD_BBH(0x21, 0x00, 0x0000), \
CMD_PTR(NULL)
/**
* 0x1A: No operation
*/

View file

@ -13,7 +13,7 @@ const GeoLayout sa_area_1[] = {
GEO_OPEN_NODE(),
GEO_NODE_ORTHO(100.0000),
GEO_OPEN_NODE(),
GEO_BACKGROUND_COLOR(0x07C1),
GEO_BACKGROUND_DYN(),
GEO_CLOSE_NODE(),
GEO_CLOSE_NODE(),
GEO_ZBUFFER(1),

View file

@ -5,6 +5,7 @@
#include "math_util.h"
#include "game/memory.h"
#include "graph_node.h"
#include "saturn/saturn.h"
typedef void (*GeoLayoutCommandProc)(void);
@ -42,6 +43,7 @@ GeoLayoutCommandProc GeoLayoutJumpTable[] = {
geo_layout_cmd_nop2,
geo_layout_cmd_nop3,
geo_layout_cmd_node_culling_radius,
geo_layout_cmd_dynamic_background,
};
struct GraphNode gObjParentGraphNode;
@ -701,6 +703,25 @@ void geo_layout_cmd_node_background(void) {
gGeoLayoutCommand += 0x08 << CMD_SIZE_SHIFT;
}
/*
0x21: Create background scene graph node
cmd+0x02: s16 background // background ID, or RGBA5551 color if backgroundFunc is null
cmd+0x04: GraphNodeFunc backgroundFunc
*/
void geo_layout_cmd_dynamic_background(void) {
struct GraphNodeBackground *graphNode;
graphNode = init_graph_node_background(
gGraphNodePool, NULL,
gChromaKeyColor, // background ID, or RGBA5551 color if asm function is null
NULL,
0);
register_scene_graph_node(&graphNode->fnNode.node);
gGeoLayoutCommand += 0x08 << CMD_SIZE_SHIFT;
}
// 0x1A: No operation
void geo_layout_cmd_nop(void) {
gGeoLayoutCommand += 0x08 << CMD_SIZE_SHIFT;

View file

@ -77,6 +77,7 @@ void geo_layout_cmd_node_shadow(void);
void geo_layout_cmd_node_object_parent(void);
void geo_layout_cmd_node_generated(void);
void geo_layout_cmd_node_background(void);
void geo_layout_cmd_dynamic_background(void);
void geo_layout_cmd_nop(void);
void geo_layout_cmd_copy_view(void);
void geo_layout_cmd_node_held_obj(void);

View file

@ -54,6 +54,8 @@ static s16 sScriptStatus;
static s32 sRegister;
static struct LevelCommand *sCurrentCmd;
bool mario_loaded = false;
static s32 eval_script_op(s8 op, s32 arg) {
s32 result = 0;
@ -435,6 +437,8 @@ static void level_cmd_init_mario(void) {
gMarioSpawnInfo->unk18 = gLoadedGraphNodes[CMD_GET(u8, 3)];
gMarioSpawnInfo->next = NULL;
mario_loaded = true;
sCurrentCmd = CMD_NEXT;
}

View file

@ -2,6 +2,7 @@
#define LEVEL_SCRIPT_H
#include <PR/ultratypes.h>
#include <stdbool.h>
struct LevelCommand;
@ -9,4 +10,6 @@ extern u8 level_script_entry[];
struct LevelCommand *level_script_execute(struct LevelCommand *cmd);
extern bool mario_loaded;
#endif // LEVEL_SCRIPT_H

View file

@ -119,6 +119,7 @@ enum HUDDisplayFlag {
u16 level_control_timer(s32 timerOp);
void fade_into_special_warp(u32 arg, u32 color);
void initiate_warp(s16 destLevel, s16 destArea, s16 destWarpNode, s32 arg3);
void load_level_init_text(u32 arg);
s16 level_trigger_warp(struct MarioState *m, s32 warpOp);
void level_set_transition(s16 length, void (*updateFunction)(s16 *));

View file

@ -6,6 +6,7 @@
#include "saturn/imgui/saturn_imgui_dynos.h"
#include "saturn/imgui/saturn_imgui_machinima.h"
#include "saturn/imgui/saturn_imgui_settings.h"
#include "saturn/imgui/saturn_imgui_chroma.h"
#include "saturn/libs/imgui/imgui.h"
#include "saturn/libs/imgui/imgui_internal.h"
#include "saturn/libs/imgui/imgui_impl_sdl.h"
@ -47,6 +48,7 @@ extern "C" {
#include "game/mario.h"
#include "game/game_init.h"
#include "game/camera.h"
#include "engine/level_script.h"
}
using namespace std;
@ -61,6 +63,7 @@ bool showWindowStats = false;
bool showWindowMachinima = false;
bool showWindowDynOS = false;
bool showWindowSettings = false;
bool showWindowChromaKey = false;
// Bundled Components
@ -153,24 +156,37 @@ void saturn_imgui_update() {
showWindowMachinima = false;
showWindowDynOS = false;
showWindowSettings = false;
showWindowChromaKey = false;
}
if (ImGui::MenuItem("Machinima")) {
showWindowMachinima = !showWindowMachinima;
showWindowStats = false;
showWindowMachinima = !showWindowMachinima;
showWindowDynOS = false;
showWindowSettings = false;
showWindowChromaKey = false;
}
if (ImGui::MenuItem("Appearance")) {
showWindowDynOS = !showWindowDynOS;
showWindowStats = false;
showWindowMachinima = false;
showWindowDynOS = !showWindowDynOS;
showWindowSettings = false;
showWindowChromaKey = false;
}
if (ImGui::MenuItem("Settings")) {
showWindowSettings = !showWindowSettings;
showWindowStats = false;
showWindowMachinima = false;
showWindowDynOS = false;
showWindowSettings = !showWindowSettings;
showWindowChromaKey = false;
}
if (gCurrLevelNum == LEVEL_SA) {
if (ImGui::MenuItem("CHROMA KEY")) {
showWindowStats = false;
showWindowMachinima = false;
showWindowDynOS = false;
showWindowSettings = false;
showWindowChromaKey = !showWindowChromaKey;
}
}
ImGui::EndMainMenuBar();
@ -230,6 +246,19 @@ void saturn_imgui_update() {
ImGui::PopStyleColor();
}
// Chroma Key
if (showWindowChromaKey && gCurrLevelNum == LEVEL_SA && mario_exists) {
ImGui::PushStyleColor(ImGuiCol_Border, ImVec4(0, 0, 0, 0));
ImGui::Begin("Chroma Key", NULL, ImGuiWindowFlags_NoTitleBar | ImGuiWindowFlags_NoResize | ImGuiWindowFlags_NoMove);
ImGui::SetWindowPos(ImVec2(10, 30));
ImGui::SetWindowSize(ImVec2(300, 125));
schroma_imgui_update();
ImGui::End();
ImGui::PopStyleColor();
}
//ImGui::ShowDemoWindow();
}

View file

@ -0,0 +1,58 @@
#include "saturn_imgui_chroma.h"
#include <string>
#include <iostream>
#include "saturn/libs/imgui/imgui.h"
#include "saturn/libs/imgui/imgui_internal.h"
#include "saturn/libs/imgui/imgui_impl_sdl.h"
#include "saturn/libs/imgui/imgui_impl_opengl3.h"
#include "saturn/saturn.h"
#include "saturn_imgui.h"
#include "pc/controller/controller_keyboard.h"
#include "data/dynos.cpp.h"
#include <SDL2/SDL.h>
extern "C" {
#include "pc/gfx/gfx_pc.h"
#include "pc/configfile.h"
#include "game/mario.h"
#include "game/camera.h"
#include "game/level_update.h"
#include "engine/level_script.h"
}
using namespace std;
// Variables
static ImVec4 uiChromaColor = ImVec4(0.0f / 255.0f, 255.0f / 255.0f, 0.0f / 255.0f, 255.0f / 255.0f);
void set_chroma_color() {
int r5 = ((int)(uiChromaColor.x * 255) * 31 / 255);
int g5 = ((int)(uiChromaColor.y * 255) * 31 / 255);
int b5 = ((int)(uiChromaColor.z * 255) * 31 / 255);
int rShift = (int) r5 << 11;
int bShift = (int) g5 << 6;
int gShift = (int) b5 << 1;
gChromaKeyColor = (int) (bShift | gShift | rShift | 1);
}
void schroma_imgui_init() {
set_chroma_color();
}
void schroma_imgui_update() {
ImGui::ColorEdit4("Chroma Key Color", (float*)&uiChromaColor, ImGuiColorEditFlags_NoAlpha | ImGuiColorEditFlags_InputRGB | ImGuiColorEditFlags_Uint8 | ImGuiColorEditFlags_NoLabel);
if (ImGui::IsItemActivated()) accept_text_input = false;
if (ImGui::IsItemDeactivated()) accept_text_input = true;
ImGui::SameLine(); ImGui::Text("Background");
if (ImGui::Button("Apply###apply_chroma_color")) {
set_chroma_color();
mario_loaded = false;
bool result = DynOS_Warp_RestartLevel();
}
ImGui::Checkbox("Shadows###chroma_shadows", &enable_shadows);
}

View file

@ -0,0 +1,15 @@
#ifndef SaturnImGuiChroma
#define SaturnImGuiChroma
#include "SDL2/SDL.h"
#ifdef __cplusplus
extern "C" {
#endif
void schroma_imgui_init(void);
void schroma_imgui_update(void);
#ifdef __cplusplus
}
#endif
#endif

View file

@ -19,6 +19,7 @@ extern "C" {
#include "game/mario.h"
#include "game/camera.h"
#include "game/level_update.h"
#include "engine/level_script.h"
}
using namespace std;
@ -80,11 +81,27 @@ void smachinima_imgui_update() {
} ImGui::SameLine(); ImGui::Checkbox("Loop", &is_anim_looped);
if (mario_exists) {
ImGui::Text("Now Playing: %s", saturn_animations[current_anim_id]);
if (is_anim_playing) {
ImGui::Text("Now Playing: %s", saturn_animations[current_anim_id]);
ImGui::SliderInt("Frame###animation_frames", &current_anim_frame, 0, current_anim_length);
ImGui::Checkbox("Paused###animation_paused", &is_anim_paused);
}
/*
ImGui::Dummy(ImVec2(0, 5));
if (gCurrLevelNum != LEVEL_SA) {
if (ImGui::Button("Warp to Chroma Key Stage")) {
initiate_warp(LEVEL_SA, 0x01, 0xF8, 0);
fade_into_special_warp(0,0);
}
} else {
if (ImGui::Button("Warp Home")) {
initiate_warp(LEVEL_CASTLE_GROUNDS, 0x01, 0x04, 0);
fade_into_special_warp(0,0);
}
}
*/
}
imgui_bundled_space(20, "Quick Toggles", NULL);

View file

@ -34,6 +34,7 @@ extern "C" {
#include "game/camera.h"
#include "game/area.h"
#include "game/level_update.h"
#include "engine/level_script.h"
#include "game/game_init.h"
#include "data/dynos.h"
#include "pc/configfile.h"
@ -49,7 +50,11 @@ using namespace std;
#define LOAD_ANIMATION 0x0200
#define TOGGLE_MENU 0x0400
unsigned int chromaKeyColorR = 0;
unsigned int chromaKeyColorG = 255;
unsigned int chromaKeyColorB = 0;
u16 gChromaKeyColor = 0x07C1;
// SATURN Machinima Functions
@ -83,8 +88,8 @@ void saturn_update() {
if (is_anim_paused) {
gMarioState->marioObj->header.gfx.unk38.animFrame = current_anim_frame;
gMarioState->marioObj->header.gfx.unk38.animFrameAccelAssist = current_anim_frame;
} else {
if (is_anim_playing && is_anim_at_end(gMarioState)) {
} else if (is_anim_playing) {
if (is_anim_at_end(gMarioState)) {
if (is_anim_looped) {
gMarioState->marioObj->header.gfx.unk38.animFrame = 0;
gMarioState->marioObj->header.gfx.unk38.animFrameAccelAssist = 0;
@ -92,7 +97,7 @@ void saturn_update() {
is_anim_playing = false;
}
}
if (is_anim_playing && selected_animation != gMarioState->marioObj->header.gfx.unk38.animID) {
if (selected_animation != gMarioState->marioObj->header.gfx.unk38.animID) {
is_anim_playing = false;
}
@ -106,7 +111,7 @@ void saturn_update() {
// Misc
mario_exists = (gMarioState->action != ACT_UNINITIALIZED);
mario_exists = (gMarioState->action != ACT_UNINITIALIZED & sCurrPlayMode != 2 & mario_loaded);
}
// Play Animation
@ -114,4 +119,13 @@ void saturn_update() {
void saturn_play_animation(MarioAnimID anim) {
set_mario_animation(gMarioState, anim);
is_anim_playing = true;
}
void saturn_warp_to(s16 destLevel, s16 destArea = 0x01, s16 destWarpNode = 0x0A) {
if (!mario_exists)
return;
mario_loaded = false;
initiate_warp(destLevel, destArea, destWarpNode, 0);
fade_into_special_warp(0,0);
}

View file

@ -2,6 +2,7 @@
#define Saturn
#include <stdio.h>
#include <PR/ultratypes.h>
#include <stdbool.h>
#include <mario_animation_ids.h>
@ -24,11 +25,18 @@ extern int current_anim_id;
extern int current_anim_length;
extern bool is_anim_paused;
extern unsigned int chromaKeyColorR;
extern unsigned int chromaKeyColorG;
extern unsigned int chromaKeyColorB;
extern u16 gChromaKeyColor;
#ifdef __cplusplus
extern "C" {
#endif
void saturn_update(void);
void saturn_play_animation(MarioAnimID);
void saturn_warp_to(s16, s16, s16);
#ifdef __cplusplus
}
#endif