Skip to content

Commit

Permalink
Fix the map glitching around when scrolling if the map is not large e…
Browse files Browse the repository at this point in the history
…nough to fill the entire screen
  • Loading branch information
ZivDero committed Feb 9, 2025
1 parent 89b4c5b commit 4640968
Show file tree
Hide file tree
Showing 4 changed files with 86 additions and 1 deletion.
2 changes: 2 additions & 0 deletions CREDITS.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ This page lists all the individual contributions to the project by their author.
- **Belonit (Gluk-v48)**:
- Check for Changelog/Documentation/Credits in Pull Requests.
- Docs dark theme switcher.
- Fix the map glitching around when scrolling if the map is not large enough to fill the entire screen.
- **CCHyper/tomsons26**:
- Vinifera foundations: TS++, game.exe hooker, extension system and other core features
- Implement `CurleyShuffle` for AircraftTypes
Expand Down Expand Up @@ -212,4 +213,5 @@ This page lists all the individual contributions to the project by their author.
- Allow disabling the ActLike check on construction yards to allow for faction-specific MCVs.
- Finalize the feature for animations to spawn additional animations.
- VehicleTypes with Jumpjet locomotion now take damage in flight.
- Fix the map glitching around when scrolling if the map is not large enough to fill the entire screen.

1 change: 1 addition & 0 deletions docs/Bugfixes.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,3 +64,4 @@ This page lists all vanilla bugs fixed by Vinifera.
- Fix a bug where AI players would send teams to attack their allies.
- `[CombatDamage]->MinDamage` now works as expected and damage is no long always a minimum of `1`.
- VehicleTypes with Jumpjet locomotion now take damage in flight.
- Fix the map glitching around when scrolling if the map is not large enough to fill the entire screen.
1 change: 1 addition & 0 deletions docs/Whats-New.md
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,7 @@ Vanilla fixes:
- Fix a bug where AI players would send teams to attack their allies (by ZivDero)
- `[CombatDamage]->MinDamage` now works as expected and damage is no long always a minimum of `1` (by ZivDero)
- VehicleTypes with Jumpjet locomotion now take damage in flight (by ZivDero)
- Fix the map glitching around when scrolling if the map is not large enough to fill the entire screen (by Belonit, ZivDero)

</details>

83 changes: 82 additions & 1 deletion src/extensions/tactical/tacticalext_hooks.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ class TacticalExt : public Tactical
void _Draw_Band_Box();
void _Select_These(Rect& rect, void (*selection_func)(ObjectClass* obj));
void _Draw_Rally_Points(bool blit);

bool _Clamp_To_Tactical_Rect(Point2D& pixel);

public:

Expand All @@ -94,6 +94,44 @@ int TacticalExt::SelectedCount = 0;
bool TacticalExt::FilterSelection = false;


/**
* Changes the function that clamps a point to the tactical rect
* to prevent jitter when the map is smaller than the screen.
*
* @authors: Belonit, ZivDero
*/
bool TacticalExt::_Clamp_To_Tactical_Rect(Point2D& pixel)
{
int xmin = CELL_PIXEL_W * (Map.MapLocalSize.X - (Map.MapSize.Width / 2)) + (TacticalRect.Width / 2);
int xmax = std::max(CELL_PIXEL_W * Map.MapLocalSize.Width - TacticalRect.Width + xmin, xmin);

int ymin = CELL_PIXEL_H * (Map.MapLocalSize.Y + (Map.MapSize.Width / 2)) + (TacticalRect.Height / 2) - int(2.5 * CELL_PIXEL_H);
int ymax = std::max(CELL_PIXEL_H * Map.MapLocalSize.Height - TacticalRect.Height + int(4.5 * CELL_PIXEL_H) + ymin, ymin);

bool clamped = false;

if (pixel.Y < ymin) {
pixel.Y = ymin;
clamped = true;
}
else if (pixel.Y > ymax) {
pixel.Y = ymax;
clamped = true;
}

if (pixel.X < xmin) {
pixel.X = xmin;
clamped = true;
}
else if (pixel.X > xmax) {
pixel.X = xmax;
clamped = true;
}

return(clamped);
}


/**
* Reimplements Tactical::Draw_Band_Box.
*
Expand Down Expand Up @@ -801,6 +839,46 @@ DECLARE_PATCH(_Tactical_Center_On_Location_Unfollow_Object_Patch)
}


/**
* Fills the remaining space of the Tactical screen with black.
*
* @authors: Belonit, ZivDero
*/
static void _Fill_With_Black()
{
const int max_width = TacticalRect.Width - Map.MapLocalSize.Width * CELL_PIXEL_W;
if (max_width > 0) {
Rect rect = {
TacticalRect.Width - max_width,
0,
max_width,
TacticalRect.Height };
CompositeSurface->Fill_Rect(rect, COLOR_TBLACK);
}

const int max_height = TacticalRect.Height - Map.MapLocalSize.Height * CELL_PIXEL_H - int(4.5 * CELL_PIXEL_H);
if (max_height > 0) {
Rect rect = {
0,
TacticalRect.Height - max_height,
TacticalRect.Width,
max_height };
CompositeSurface->Fill_Rect(rect, COLOR_TBLACK);
}
}


DECLARE_PATCH(_Tactical_Render_Fill_With_Black_Patch)
{
_Fill_With_Black();

// Stolen instructions
_asm {mov eax, [esp+0x18]}
_asm {mov ecx, ebx}
JMP_REG(EDX, 0x00611BC1);
}


/**
* Main function for patching the hooks.
*/
Expand Down Expand Up @@ -835,4 +913,7 @@ void TacticalExtension_Hooks()

Patch_Jump(0x00616940, &TacticalExt::_Select_These);
Patch_Jump(0x00479150, &Vinifera_Bandbox_Select);

Patch_Jump(0x00614EC0, &TacticalExt::_Clamp_To_Tactical_Rect);
Patch_Jump(0x00611BBB, &_Tactical_Render_Fill_With_Black_Patch);
}

0 comments on commit 4640968

Please sign in to comment.