Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Maniacs Feature: Add separate Width/Height parameters for scaling pictures, Picture StringVar, Tint Variable #3180

Merged
merged 3 commits into from
Apr 11, 2024

Conversation

ToolMan2k
Copy link
Contributor

@ToolMan2k ToolMan2k commented Dec 28, 2023

This commit allows for the use of separate Width/Height parameters for rendering pictures.
You can use this feature with ManiacPatch 211010 using the .scale2 parameter.

It also adds scaling support for "Maniac_ShowStringPic" and a quick fix for failed bitmap assertion.

EasyRPG-Scaling.mp4

Sister commit here: EasyRPG/liblcf#473

Added:

  • Added support for "scale_width" and "scale_height" for ShowPicture(), MovePicture() and Maniac_ShowStringPicture()
  • Maniac_GetPictureInfo returns the separate values of "width" and "height"
  • Set both Width and Height to Magnify if one of the following conditions are met:
    • ManiacPatch is not enabled;
    • Using the .scale parameter;
    • Picture Effects are enabled (parity with ManiacPatch, but can be disabled inside the source)
  • Maniac_ShowStringPicture now properly scales the picture (both with .scale and .scale2)
  • New variables for pictures:
    • scale_width
    • scale_height
    • current_scale_width
    • current_scale_height
    • finished_scale_width
    • finished_scale_height

Fixed:

  • Assertion failed when getting the Width/Height of an invalid bitmap (Now returns 0 instead).

Added:
- Separate Width and Height value as per .scale2 parameter in ManiacPatch 211010
- Set Height to Width when using picture effects (as per ManiacPatch)
- Set both Width and Height to Magnify when using .scale parameter

Bugfix:
- Fix ManiacPatch picture rotation not fully working
@ToolMan2k ToolMan2k changed the title Maniac Patch: Separate Width/Height data for scaling pictures Maniac Patch: Add separate Width/Height parameters for scaling pictures Dec 28, 2023
@ToolMan2k ToolMan2k changed the title Maniac Patch: Add separate Width/Height parameters for scaling pictures Maniac Patch: Add separate Width/Height parameters for scaling pictures Dec 28, 2023
@ToolMan2k ToolMan2k changed the title Maniac Patch: Add separate Width/Height parameters for scaling pictures Maniacs Feature: Add separate Width/Height parameters for scaling pictures Dec 28, 2023
@ToolMan2k
Copy link
Contributor Author

Looking at the failed test, we'll need to compile liblcf using a modified fields_easyrpg file.

@Ghabry
Copy link
Member

Ghabry commented Jan 2, 2024

The build failures are normal when depending on lcf changes.

You added new easyrpg chunks here. Did you check how maniac patch stores it in the save file? If it isn't something annoying like storing it in some upper bits we usually try to be compatible to mp here.

@@ -169,7 +181,9 @@ int Sprite_Picture::GetFrameWidth() const {
const auto& data = pic.data;

auto& bitmap = GetBitmap();
assert(bitmap);
if (!bitmap) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We use assert for "this should never ever happen during normal execution otherwise it is a bug in the code".
Can you explain how you triggered this "impossible" assert?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Playing around with my test project, I can consistently crash the engine whenever I do the following in this order:

  1. We modify a X and Y variable
  2. We immediately move an anchored picture and set its coordinates to X and Y.

Even if we add an wait period between both commands, it still crashes.
If we invert these steps, it doesn't happen anymore, go figure.

Here's the test project if you want to play around with:
PictureTest-assert.zip

@ToolMan2k
Copy link
Contributor Author

You added new easyrpg chunks here. Did you check how maniac patch stores it in the save file? If it isn't something annoying like storing it in some upper bits we usually try to be compatible to mp here.

This is definitely something that needs more love. I did try to load saves between original RPG_RT and EasyRPG, it does prints about "unknown chunks" inside the save file. Inside my above test project, you can make an instant save file by pressing SHIFT.

Here's the log I've posted on the bug tracker post:

Skipped Chunk 86 (1 byte) in lcf at 1F9 (SaveSystem)
01 
Skipped Chunk 87 (1 byte) in lcf at 1FD (SaveSystem)
04 
Reading Primitive of incorrect size 4 (expected 1) at 29D
SavePicture: Corrupted Chunk 0x06 (size: 4, pos: 0x29d): fixed_to_map : Read 7 bytes! Reseting...
Reading Primitive of incorrect size 3 (expected 1) at 2AD
SavePicture: Corrupted Chunk 0x09 (size: 3, pos: 0x2ad): use_transparent_color : Read 5 bytes! Reseting...
Skipped Chunk 0A (8 byte) in lcf at 2B2 (SavePicture)
00 00 00 00 00 60 73 40 
Skipped Chunk 24 (2 byte) in lcf at 2D0 (SavePicture)
82 36 
Skipped Chunk 0A (8 byte) in lcf at 345 (SavePicture)
00 00 00 00 00 60 73 40 
Skipped Chunk 1E (2 byte) in lcf at 362 (SavePicture)
82 20 
Skipped Chunk 24 (2 byte) in lcf at 37E (SavePicture)
82 36 
Debug: Loading Save Save01.lsd
Skipped Chunk 86 (1 byte) in lcf at 1F9 (SaveSystem)
01 
Skipped Chunk 87 (1 byte) in lcf at 1FD (SaveSystem)
04 
Reading Primitive of incorrect size 4 (expected 1) at 29D
SavePicture: Corrupted Chunk 0x06 (size: 4, pos: 0x29d): fixed_to_map : Read 7 bytes! Reseting...
Reading Primitive of incorrect size 3 (expected 1) at 2AD
SavePicture: Corrupted Chunk 0x09 (size: 3, pos: 0x2ad): use_transparent_color : Read 5 bytes! Reseting...
Skipped Chunk 0A (8 byte) in lcf at 2B2 (SavePicture)
00 00 00 00 00 60 73 40 
Skipped Chunk 24 (2 byte) in lcf at 2D0 (SavePicture)
82 36 
Skipped Chunk 0A (8 byte) in lcf at 345 (SavePicture)
00 00 00 00 00 60 73 40 
Skipped Chunk 1E (2 byte) in lcf at 362 (SavePicture)
82 20 
Skipped Chunk 24 (2 byte) in lcf at 37E (SavePicture)
82 36 
Debug: Savegame version 0 (RPG_RT or EasyRPG Player Pre-0.6.0)
Debug: Loaded Map Map0001.lmu
Debug: Tree: MAP0001

@ToolMan2k
Copy link
Contributor Author

While playing around, jumping between RPG_RT, saving, then reading the savefile using LCF2XML, I can determine the following things:

  1. Maniacs uses "current_magnify" and "finish_magnify" for the Width Parameter.
  2. When using the height parameter, it adds 8 bytes to the 0A chunk, and adds between 1 to 4 bytes in chunk 24.
  3. 0A seems to be the current height double, and 24 seems to be the final height integer.

@ToolMan2k
Copy link
Contributor Author

ToolMan2k commented Jan 5, 2024

I'll recompile liblcf with the proper indexes, then I'll let you know.
However, I have a quick question: is it safe to reuse a save chunk twice?

For instance, using the block 07 for both current_magnify and current_width_scale, since they're the same value internally.
Or would we have to change the name for everything, even though width/height is only for Maniac?

I would certainly keep magnify as it is for compatibility reasons.

@ToolMan2k
Copy link
Contributor Author

As per EasyRPG/liblcf#473, I've updated the chunk pointers.

Now I can save and load between Maniacs and EasyRPG, and scaling is kept between the twos.

Added the following:
- Check if we're using a string variable with com.parameters[17]
- Set the name parameter to the String Variable

Fixed the following:
- When using a String Var with ShowPicture, it no longers crash the game with picture ID -1
While testing, I found out the following things:
- You cannot mix multiple Variable types for each parameters
- When using Variables for Picture Tint, parameter 17 is set to 4096 (0x100),
- When using Var Indexes for Picture Tint, parameter 17 is set to 8192 (0x200),
- Before, parameters for red, green, blue and saturation were always constants.
- Surprisingly this feature doesn't work with ShowStringPicture

Added:
- Variable and VarIndex support for Tinting using ShowPicture and MovePicture using bitfields
Copy link
Member

@Ghabry Ghabry left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

redid parts of the patch so fix some issues. Is now fine for me.

@Ghabry Ghabry added this to the 0.8.1 milestone Mar 11, 2024
@Ghabry Ghabry changed the title Maniacs Feature: Add separate Width/Height parameters for scaling pictures Maniacs Feature: Add separate Width/Height parameters for scaling pictures, Picture StringVar, Tint Variable Mar 11, 2024
@Ghabry
Copy link
Member

Ghabry commented Mar 26, 2024

Jenkins: Test this please

@Ghabry Ghabry merged commit befa72a into EasyRPG:master Apr 11, 2024
13 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

Successfully merging this pull request may close these issues.

None yet

3 participants