3188: Fix weapon muzzle texture cutoff r=def- a=Jupeyy

As reported by Pipou on discord, the weapon muzzle is cut off, bcs of wrong values in content.py,

![this](https://cdn.discordapp.com/attachments/757720336274948198/769634017732853768/gamegrid.png)

changing them would result in a scale(it would look different), so i hardcoded a few values to let it look the same

new:
![screenshot_2020-10-25_14-15-08](https://user-images.githubusercontent.com/6654924/97108777-f2a6ef80-16cf-11eb-953c-4ad39de239c3.png)

old:
![screenshot_2020-10-24_22-56-03](https://user-images.githubusercontent.com/6654924/97108787-f9356700-16cf-11eb-802c-c7d3f2a762cc.png)


Tho i'd like to think about it, or maybe someone else thinks about it xd

Co-authored-by: Jupeyy <jupjopjap@gmail.com>
This commit is contained in:
bors[bot] 2020-10-25 14:50:32 +00:00 committed by GitHub
commit 7ff0534023
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 46 additions and 28 deletions

View file

@ -320,16 +320,16 @@ container.sprites.Add(Sprite("part9", set_game, 13,0,2,2))
container.sprites.Add(Sprite("weapon_gun_body", set_game, 2,4,4,2))
container.sprites.Add(Sprite("weapon_gun_cursor", set_game, 0,4,2,2))
container.sprites.Add(Sprite("weapon_gun_proj", set_game, 6,4,2,2))
container.sprites.Add(Sprite("weapon_gun_muzzle1", set_game, 8,4,3,2))
container.sprites.Add(Sprite("weapon_gun_muzzle2", set_game, 12,4,3,2))
container.sprites.Add(Sprite("weapon_gun_muzzle3", set_game, 16,4,3,2))
container.sprites.Add(Sprite("weapon_gun_muzzle1", set_game, 8,4,4,2))
container.sprites.Add(Sprite("weapon_gun_muzzle2", set_game, 12,4,4,2))
container.sprites.Add(Sprite("weapon_gun_muzzle3", set_game, 16,4,4,2))
container.sprites.Add(Sprite("weapon_shotgun_body", set_game, 2,6,8,2))
container.sprites.Add(Sprite("weapon_shotgun_cursor", set_game, 0,6,2,2))
container.sprites.Add(Sprite("weapon_shotgun_proj", set_game, 10,6,2,2))
container.sprites.Add(Sprite("weapon_shotgun_muzzle1", set_game, 12,6,3,2))
container.sprites.Add(Sprite("weapon_shotgun_muzzle2", set_game, 16,6,3,2))
container.sprites.Add(Sprite("weapon_shotgun_muzzle3", set_game, 20,6,3,2))
container.sprites.Add(Sprite("weapon_shotgun_muzzle1", set_game, 12,6,4,2))
container.sprites.Add(Sprite("weapon_shotgun_muzzle2", set_game, 16,6,4,2))
container.sprites.Add(Sprite("weapon_shotgun_muzzle3", set_game, 20,6,4,2))
container.sprites.Add(Sprite("weapon_grenade_body", set_game, 2,8,7,2))
container.sprites.Add(Sprite("weapon_grenade_cursor", set_game, 0,8,2,2))
@ -498,7 +498,14 @@ weapon.ammoregentime.Set(500)
weapon.visual_size.Set(64)
weapon.offsetx.Set(32)
weapon.offsety.Set(4)
weapon.muzzleoffsetx.Set(50)
# the number after the plus sign is the sprite scale, which is calculated for all sprites ( w / sqrt(w² * h²) ) of the additionally added x offset, which is added now,
# since the muzzle image is 32 pixels bigger, devided by 2, because a sprite's position is always at the center of the sprite image itself
# => the offset added, bcs the sprite is bigger now, but should not be shifted to the left
# => 96 / sqrt(64×64+96×96) (the original sprite scale)
# => 64 × original sprite scale (the actual size of the sprite ingame see weapon.visual_size above)
# => (actual image sprite) / 3 (the new sprite is 128 instead of 96, so 4 / 3 times as big(bcs it should look the same as before, not scaled down because of this bigger number), so basically, 1 / 3 of the original size is added)
# => (new sprite width) / 2 (bcs the sprite is at center, only add half of that new extra width)
weapon.muzzleoffsetx.Set(50 + 8.8752)
weapon.muzzleoffsety.Set(6)
container.weapons.gun.base.Set(weapon)
container.weapons.id.Add(weapon)
@ -508,7 +515,7 @@ weapon.firedelay.Set(500)
weapon.visual_size.Set(96)
weapon.offsetx.Set(24)
weapon.offsety.Set(-2)
weapon.muzzleoffsetx.Set(70)
weapon.muzzleoffsetx.Set(70 + 13.3128) # see gun for the number after the plus sign
weapon.muzzleoffsety.Set(6)
container.weapons.shotgun.base.Set(weapon)
container.weapons.id.Add(weapon)

View file

@ -373,16 +373,16 @@ container.sprites.Add(Sprite("part9", set_game, 13,0,2,2))
container.sprites.Add(Sprite("weapon_gun_body", set_game, 2,4,4,2))
container.sprites.Add(Sprite("weapon_gun_cursor", set_game, 0,4,2,2))
container.sprites.Add(Sprite("weapon_gun_proj", set_game, 6,4,2,2))
container.sprites.Add(Sprite("weapon_gun_muzzle1", set_game, 8,4,3,2))
container.sprites.Add(Sprite("weapon_gun_muzzle2", set_game, 12,4,3,2))
container.sprites.Add(Sprite("weapon_gun_muzzle3", set_game, 16,4,3,2))
container.sprites.Add(Sprite("weapon_gun_muzzle1", set_game, 8,4,4,2))
container.sprites.Add(Sprite("weapon_gun_muzzle2", set_game, 12,4,4,2))
container.sprites.Add(Sprite("weapon_gun_muzzle3", set_game, 16,4,4,2))
container.sprites.Add(Sprite("weapon_shotgun_body", set_game, 2,6,8,2))
container.sprites.Add(Sprite("weapon_shotgun_cursor", set_game, 0,6,2,2))
container.sprites.Add(Sprite("weapon_shotgun_proj", set_game, 10,6,2,2))
container.sprites.Add(Sprite("weapon_shotgun_muzzle1", set_game, 12,6,3,2))
container.sprites.Add(Sprite("weapon_shotgun_muzzle2", set_game, 16,6,3,2))
container.sprites.Add(Sprite("weapon_shotgun_muzzle3", set_game, 20,6,3,2))
container.sprites.Add(Sprite("weapon_shotgun_muzzle1", set_game, 12,6,4,2))
container.sprites.Add(Sprite("weapon_shotgun_muzzle2", set_game, 16,6,4,2))
container.sprites.Add(Sprite("weapon_shotgun_muzzle3", set_game, 20,6,4,2))
container.sprites.Add(Sprite("weapon_grenade_body", set_game, 2,8,7,2))
container.sprites.Add(Sprite("weapon_grenade_cursor", set_game, 0,8,2,2))
@ -633,7 +633,7 @@ weapon.ammoregentime.Set(500)
weapon.visual_size.Set(64)
weapon.offsetx.Set(32)
weapon.offsety.Set(-4)
weapon.muzzleoffsetx.Set(50)
weapon.muzzleoffsetx.Set(50 + 8.8752) # see gun in 0.6 content.py for the number after the plus sign (TODO: also copy the comment from 0.6 content.py, if it gets removed)
weapon.muzzleoffsety.Set(6)
container.weapons.gun.base.Set(weapon)
container.weapons.id.Add(weapon)
@ -644,7 +644,7 @@ weapon.damage.Set(1)
weapon.visual_size.Set(96)
weapon.offsetx.Set(24)
weapon.offsety.Set(-2)
weapon.muzzleoffsetx.Set(70)
weapon.muzzleoffsetx.Set(70 + 13.3128) # see gun in 0.6 content.py for the number after the plus sign (TODO: also copy the comment from 0.6 content.py, if it gets removed)
weapon.muzzleoffsety.Set(6)
container.weapons.shotgun.base.Set(weapon)
container.weapons.id.Add(weapon)

View file

@ -766,20 +766,29 @@ void CPlayers::OnInit()
{
if(g_pData->m_Weapons.m_aId[i].m_aSpriteMuzzles[n])
{
if(i == WEAPON_GUN || i == WEAPON_SHOTGUN)
{
// TODO: hardcoded for now to get the same particle size as before
RenderTools()->GetSpriteScaleImpl(96, 64, ScaleX, ScaleY);
}
else
RenderTools()->GetSpriteScale(g_pData->m_Weapons.m_aId[i].m_aSpriteMuzzles[n], ScaleX, ScaleY);
}
float SWidth = (g_pData->m_Weapons.m_aId[i].m_VisualSize * ScaleX) * (4.0f / 3.0f);
float SHeight = g_pData->m_Weapons.m_aId[i].m_VisualSize * ScaleY;
Graphics()->QuadsSetSubset(0, 0, 1, 1);
if(WEAPON_NINJA == i)
RenderTools()->QuadContainerAddSprite(m_WeaponSpriteMuzzleQuadContainerIndex[i], 160.f * ScaleX, 160.f * ScaleY);
else
RenderTools()->QuadContainerAddSprite(m_WeaponSpriteMuzzleQuadContainerIndex[i], g_pData->m_Weapons.m_aId[i].m_VisualSize * ScaleX, g_pData->m_Weapons.m_aId[i].m_VisualSize * ScaleY);
RenderTools()->QuadContainerAddSprite(m_WeaponSpriteMuzzleQuadContainerIndex[i], SWidth, SHeight);
Graphics()->QuadsSetSubset(0, 1, 1, 0);
if(WEAPON_NINJA == i)
RenderTools()->QuadContainerAddSprite(m_WeaponSpriteMuzzleQuadContainerIndex[i], 160.f * ScaleX, 160.f * ScaleY);
else
RenderTools()->QuadContainerAddSprite(m_WeaponSpriteMuzzleQuadContainerIndex[i], g_pData->m_Weapons.m_aId[i].m_VisualSize * ScaleX, g_pData->m_Weapons.m_aId[i].m_VisualSize * ScaleY);
RenderTools()->QuadContainerAddSprite(m_WeaponSpriteMuzzleQuadContainerIndex[i], SWidth, SHeight);
}
}

View file

@ -78,9 +78,7 @@ void CRenderTools::SelectSprite(CDataSprite *pSpr, int Flags, int sx, int sy)
int cx = pSpr->m_pSet->m_Gridx;
int cy = pSpr->m_pSet->m_Gridy;
float f = sqrtf(h * h + w * w);
gs_SpriteWScale = w / f;
gs_SpriteHScale = h / f;
GetSpriteScaleImpl(w, h, gs_SpriteWScale, gs_SpriteHScale);
float x1 = x / (float)cx + 0.5f / (float)(cx * 32);
float x2 = (x + w) / (float)cx - 0.5f / (float)(cx * 32);
@ -116,18 +114,14 @@ void CRenderTools::GetSpriteScale(client_data7::CDataSprite *pSprite, float &Sca
{
int w = pSprite->m_W;
int h = pSprite->m_H;
float f = sqrtf(h * h + w * w);
ScaleX = w / f;
ScaleY = h / f;
GetSpriteScaleImpl(w, h, ScaleX, ScaleY);
}
void CRenderTools::GetSpriteScale(struct CDataSprite *pSprite, float &ScaleX, float &ScaleY)
{
int w = pSprite->m_W;
int h = pSprite->m_H;
float f = sqrtf(h * h + w * w);
ScaleX = w / f;
ScaleY = h / f;
GetSpriteScaleImpl(w, h, ScaleX, ScaleY);
}
void CRenderTools::GetSpriteScale(int id, float &ScaleX, float &ScaleY)
@ -135,6 +129,13 @@ void CRenderTools::GetSpriteScale(int id, float &ScaleX, float &ScaleY)
GetSpriteScale(&g_pData->m_aSprites[id], ScaleX, ScaleY);
}
void CRenderTools::GetSpriteScaleImpl(int Width, int Height, float &ScaleX, float &ScaleY)
{
float f = sqrtf(Height * Height + Width * Width);
ScaleX = Width / f;
ScaleY = Height / f;
}
void CRenderTools::DrawSprite(float x, float y, float Size)
{
IGraphics::CQuadItem QuadItem(x, y, Size * gs_SpriteWScale, Size * gs_SpriteHScale);

View file

@ -69,6 +69,7 @@ public:
void GetSpriteScale(client_data7::CDataSprite *pSprite, float &ScaleX, float &ScaleY);
void GetSpriteScale(struct CDataSprite *pSprite, float &ScaleX, float &ScaleY);
void GetSpriteScale(int id, float &ScaleX, float &ScaleY);
void GetSpriteScaleImpl(int Width, int Height, float &ScaleX, float &ScaleY);
void DrawSprite(float x, float y, float size);
void DrawSprite(float x, float y, float ScaledWidth, float ScaledHeight);