move patch rotation stuff into their own files
This commit is contained in:
1 parent
58e12d620f
commit
dc465733c7
15 files changed
+347
-289
No files matched your search
+3
-1
@@ -129,6 +129,7 @@ set(SRB2_CORE_RENDER_SOURCES
|
||||
r_fps.c
|
||||
r_main.c
|
||||
r_patch.c
|
||||
r_patchrotation.c
|
||||
r_plane.c
|
||||
r_segs.c
|
||||
r_sky.c
|
||||
@@ -143,7 +144,8 @@ set(SRB2_CORE_RENDER_SOURCES
|
||||
r_fps.h
|
||||
r_local.h
|
||||
r_main.h
|
||||
r_patch
|
||||
r_patch.h
|
||||
r_patchrotation.h
|
||||
r_plane.h
|
||||
r_segs.h
|
||||
r_sky.h
|
||||
|
||||
@@ -554,6 +554,7 @@ OBJS:=$(i_main_o) \
|
||||
$(OBJDIR)/r_sky.o \
|
||||
$(OBJDIR)/r_splats.o \
|
||||
$(OBJDIR)/r_patch.o \
|
||||
$(OBJDIR)/r_patchrotation.o \
|
||||
$(OBJDIR)/r_things.o \
|
||||
$(OBJDIR)/r_portal.o \
|
||||
$(OBJDIR)/screen.o \
|
||||
|
||||
+1
-1
@@ -28,7 +28,7 @@
|
||||
#include "p_local.h" // for var1 and var2, and some constants
|
||||
#include "p_setup.h"
|
||||
#include "r_data.h"
|
||||
#include "r_patch.h"
|
||||
#include "r_fps.h"
|
||||
#include "r_sky.h"
|
||||
#include "r_draw.h" // translation colormap consts (for lua)
|
||||
#include "fastcmp.h"
|
||||
|
||||
@@ -28,7 +28,7 @@
|
||||
#include "../v_video.h"
|
||||
#include "../r_draw.h"
|
||||
#include "../r_main.h"
|
||||
#include "../r_patch.h" // patch rotation
|
||||
#include "../r_patch.h"
|
||||
#include "../p_setup.h" // levelflats
|
||||
#include "../p_spec.h" // anim_t
|
||||
#include "../r_sky.h"
|
||||
|
||||
@@ -39,7 +39,6 @@
|
||||
#include "../r_fps.h"
|
||||
#include "../r_local.h"
|
||||
#include "../r_main.h" // cv_fov
|
||||
#include "../r_patch.h" // a mystery as to what this is for
|
||||
#include "../r_portal.h"
|
||||
#ifdef WALLSPLATS
|
||||
#include "../r_splats.h"
|
||||
@@ -56,7 +55,11 @@
|
||||
#include "../w_wad.h"
|
||||
#include "../z_zone.h"
|
||||
|
||||
#include "../qs22j.h" // fast qsort
|
||||
#ifdef ROTSPRITE
|
||||
#include "../r_patchrotation.h" // a mystery as to what this is for
|
||||
#endif
|
||||
|
||||
#include "../qs22j.h" // fast qsort
|
||||
|
||||
// ==========================================================================
|
||||
// Globals
|
||||
|
||||
@@ -48,6 +48,10 @@
|
||||
#include "hardware/hw_main.h"
|
||||
#endif
|
||||
|
||||
#ifdef ROTSPRITE
|
||||
#include "r_patchrotation.h"
|
||||
#endif
|
||||
|
||||
// Not sure if thats best place for that
|
||||
static mobjtype_t stardust = 0;
|
||||
static mobjtype_t watertrailunderlay = 0, watertrail = 0;
|
||||
|
||||
@@ -30,6 +30,10 @@
|
||||
#include "lua_hud.h"
|
||||
#include "lua_hook.h"
|
||||
|
||||
#ifdef ROTSPRITE
|
||||
#include "r_patchrotation.h"
|
||||
#endif
|
||||
|
||||
#define HUDONLY if (!hud_running) return luaL_error(L, "HUD rendering code should not be called outside of rendering hooks!");
|
||||
|
||||
boolean hud_running = false;
|
||||
|
||||
+3
-2
@@ -13,12 +13,13 @@
|
||||
|
||||
#include "doomdef.h"
|
||||
#include "g_game.h"
|
||||
|
||||
#include "r_fps.h"
|
||||
#include "r_local.h"
|
||||
#include "r_state.h"
|
||||
#include "r_portal.h" // Add seg portals
|
||||
|
||||
|
||||
#include "r_splats.h"
|
||||
|
||||
#include "p_local.h" // camera
|
||||
#include "p_slopes.h"
|
||||
#include "z_zone.h" // Check R_Prep3DFloors
|
||||
|
||||
+2
-252
@@ -13,12 +13,7 @@
|
||||
/// \brief Patch generation.
|
||||
|
||||
#include "byteptr.h"
|
||||
#include "dehacked.h"
|
||||
#include "doomdef.h"
|
||||
#include "i_video.h"
|
||||
#include "r_data.h"
|
||||
#include "r_draw.h"
|
||||
#include "r_fps.h"
|
||||
#include "r_patch.h"
|
||||
#include "r_things.h"
|
||||
#include "z_zone.h"
|
||||
@@ -462,7 +457,7 @@ void *Patch_CreateGL(patch_t *patch)
|
||||
// Convert a masked flat to a patch.
|
||||
// Explanation of "masked" flats in R_PatchToMaskedFlat.
|
||||
//
|
||||
static void *R_MaskedFlatToPatch(UINT16 *raw, INT16 width, INT16 height, INT16 leftoffset, INT16 topoffset, size_t *destsize)
|
||||
void *R_MaskedFlatToPatch(UINT16 *raw, INT16 width, INT16 height, INT16 leftoffset, INT16 topoffset, size_t *destsize)
|
||||
{
|
||||
INT16 x, y;
|
||||
UINT8 *img;
|
||||
@@ -577,7 +572,7 @@ static void *R_MaskedFlatToPatch(UINT16 *raw, INT16 width, INT16 height, INT16 l
|
||||
return converted;
|
||||
}
|
||||
|
||||
static UINT16 GetPatchPixel(patch_t *patch, INT32 x, INT32 y, boolean flip)
|
||||
UINT16 R_GetPatchPixel(patch_t *patch, INT32 x, INT32 y, boolean flip)
|
||||
{
|
||||
fixed_t ofs;
|
||||
column_t *column;
|
||||
@@ -619,248 +614,3 @@ static UINT16 GetPatchPixel(patch_t *patch, INT32 x, INT32 y, boolean flip)
|
||||
|
||||
return 0xFF00;
|
||||
}
|
||||
|
||||
#ifdef ROTSPRITE
|
||||
//
|
||||
// R_GetRollAngle
|
||||
//
|
||||
// Angles precalculated in R_InitSprites.
|
||||
//
|
||||
fixed_t rollcosang[ROTANGLES];
|
||||
fixed_t rollsinang[ROTANGLES];
|
||||
|
||||
INT32 R_GetRollAngle(angle_t rollangle)
|
||||
{
|
||||
INT32 ra = AngleFixed(rollangle)>>FRACBITS;
|
||||
#if (ROTANGDIFF > 1)
|
||||
ra += (ROTANGDIFF/2);
|
||||
#endif
|
||||
ra /= ROTANGDIFF;
|
||||
ra %= ROTANGLES;
|
||||
return ra;
|
||||
}
|
||||
|
||||
angle_t R_RotationAngle(angle_t ang, angle_t camang, interpmobjstate_t *interp)
|
||||
{
|
||||
return FixedMul(FINECOSINE((ang) >> ANGLETOFINESHIFT), interp->roll) +
|
||||
FixedMul(FINESINE((ang) >> ANGLETOFINESHIFT), interp->pitch) +
|
||||
FixedMul(FINECOSINE((camang) >> ANGLETOFINESHIFT), interp->sloperoll) +
|
||||
FixedMul(FINESINE((camang) >> ANGLETOFINESHIFT), interp->slopepitch);
|
||||
}
|
||||
|
||||
patch_t *Patch_GetRotatedSprite(spriteframe_t *sprite, size_t frame, size_t spriteangle, boolean flip, void *info, INT32 rotationangle)
|
||||
{
|
||||
rotsprite_t *rotsprite;
|
||||
spriteinfo_t *sprinfo = (spriteinfo_t *)info;
|
||||
INT32 idx = rotationangle;
|
||||
|
||||
if (rotationangle < 1 || rotationangle >= ROTANGLES)
|
||||
return NULL;
|
||||
|
||||
rotsprite = sprite->rotated[spriteangle];
|
||||
|
||||
if (rotsprite == NULL)
|
||||
{
|
||||
rotsprite = RotatedPatch_Create(ROTANGLES);
|
||||
sprite->rotated[spriteangle] = rotsprite;
|
||||
}
|
||||
|
||||
if (flip)
|
||||
idx += rotsprite->angles;
|
||||
|
||||
if (rotsprite->patches[idx] == NULL)
|
||||
{
|
||||
patch_t *patch;
|
||||
INT32 xpivot = 0, ypivot = 0;
|
||||
lumpnum_t lump = sprite->lumppat[spriteangle];
|
||||
|
||||
if (lump == LUMPERROR)
|
||||
return NULL;
|
||||
|
||||
patch = W_CachePatchNum(lump, PU_SPRITE);
|
||||
|
||||
if (sprinfo->available)
|
||||
{
|
||||
xpivot = sprinfo->pivot[frame].x;
|
||||
ypivot = sprinfo->pivot[frame].y;
|
||||
}
|
||||
else
|
||||
{
|
||||
xpivot = patch->leftoffset;
|
||||
ypivot = patch->height / 2;
|
||||
}
|
||||
|
||||
RotatedPatch_DoRotation(rotsprite, patch, rotationangle, xpivot, ypivot, flip);
|
||||
}
|
||||
|
||||
return rotsprite->patches[idx];
|
||||
}
|
||||
|
||||
rotsprite_t *RotatedPatch_Create(INT32 numangles)
|
||||
{
|
||||
rotsprite_t *rotsprite = Z_Calloc(sizeof(rotsprite_t), PU_STATIC, NULL);
|
||||
rotsprite->angles = numangles;
|
||||
rotsprite->patches = Z_Calloc(rotsprite->angles * 2 * sizeof(void *), PU_STATIC, NULL);
|
||||
return rotsprite;
|
||||
}
|
||||
|
||||
static void RotatedPatch_CalculateDimensions(
|
||||
INT32 width, INT32 height,
|
||||
fixed_t ca, fixed_t sa,
|
||||
INT32 *newwidth, INT32 *newheight)
|
||||
{
|
||||
fixed_t fixedwidth = (width * FRACUNIT);
|
||||
fixed_t fixedheight = (height * FRACUNIT);
|
||||
|
||||
fixed_t w1 = abs(FixedMul(fixedwidth, ca) - FixedMul(fixedheight, sa));
|
||||
fixed_t w2 = abs(FixedMul(-fixedwidth, ca) - FixedMul(fixedheight, sa));
|
||||
fixed_t h1 = abs(FixedMul(fixedwidth, sa) + FixedMul(fixedheight, ca));
|
||||
fixed_t h2 = abs(FixedMul(-fixedwidth, sa) + FixedMul(fixedheight, ca));
|
||||
|
||||
w1 = FixedInt(FixedCeil(w1 + (FRACUNIT/2)));
|
||||
w2 = FixedInt(FixedCeil(w2 + (FRACUNIT/2)));
|
||||
h1 = FixedInt(FixedCeil(h1 + (FRACUNIT/2)));
|
||||
h2 = FixedInt(FixedCeil(h2 + (FRACUNIT/2)));
|
||||
|
||||
*newwidth = max(width, max(w1, w2));
|
||||
*newheight = max(height, max(h1, h2));
|
||||
}
|
||||
|
||||
void RotatedPatch_DoRotation(rotsprite_t *rotsprite, patch_t *patch, INT32 angle, INT32 xpivot, INT32 ypivot, boolean flip)
|
||||
{
|
||||
UINT32 i;
|
||||
patch_t *rotated;
|
||||
|
||||
UINT16 *rawdst, *rawconv;
|
||||
size_t size;
|
||||
INT32 bflip = (flip != 0x00);
|
||||
|
||||
INT32 width = patch->width;
|
||||
INT32 height = patch->height;
|
||||
INT32 leftoffset = patch->leftoffset;
|
||||
INT32 newwidth, newheight;
|
||||
|
||||
fixed_t ca = rollcosang[angle];
|
||||
fixed_t sa = rollsinang[angle];
|
||||
fixed_t xcenter, ycenter;
|
||||
INT32 idx = angle;
|
||||
INT32 x, y;
|
||||
INT32 sx, sy;
|
||||
INT32 dx, dy;
|
||||
INT32 ox, oy;
|
||||
INT32 minx, miny, maxx, maxy;
|
||||
|
||||
// Don't cache angle = 0
|
||||
if (angle < 1 || angle >= ROTANGLES)
|
||||
return;
|
||||
|
||||
if (flip)
|
||||
{
|
||||
idx += rotsprite->angles;
|
||||
xpivot = width - xpivot;
|
||||
leftoffset = width - leftoffset;
|
||||
}
|
||||
|
||||
if (rotsprite->patches[idx])
|
||||
return;
|
||||
|
||||
// Find the dimensions of the rotated patch.
|
||||
RotatedPatch_CalculateDimensions(width, height, ca, sa, &newwidth, &newheight);
|
||||
|
||||
xcenter = (xpivot * FRACUNIT);
|
||||
ycenter = (ypivot * FRACUNIT);
|
||||
|
||||
if (xpivot != width / 2 || ypivot != height / 2)
|
||||
{
|
||||
newwidth *= 2;
|
||||
newheight *= 2;
|
||||
}
|
||||
|
||||
minx = newwidth;
|
||||
miny = newheight;
|
||||
maxx = 0;
|
||||
maxy = 0;
|
||||
|
||||
// Draw the rotated sprite to a temporary buffer.
|
||||
size = (newwidth * newheight);
|
||||
if (!size)
|
||||
size = (width * height);
|
||||
rawdst = Z_Malloc(size * sizeof(UINT16), PU_STATIC, NULL);
|
||||
|
||||
for (i = 0; i < size; i++)
|
||||
rawdst[i] = 0xFF00;
|
||||
|
||||
for (dy = 0; dy < newheight; dy++)
|
||||
{
|
||||
for (dx = 0; dx < newwidth; dx++)
|
||||
{
|
||||
x = (dx - (newwidth / 2)) * FRACUNIT;
|
||||
y = (dy - (newheight / 2)) * FRACUNIT;
|
||||
sx = FixedMul(x, ca) + FixedMul(y, sa) + xcenter;
|
||||
sy = -FixedMul(x, sa) + FixedMul(y, ca) + ycenter;
|
||||
|
||||
sx >>= FRACBITS;
|
||||
sy >>= FRACBITS;
|
||||
|
||||
if (sx >= 0 && sy >= 0 && sx < width && sy < height)
|
||||
{
|
||||
rawdst[(dy * newwidth) + dx] = GetPatchPixel(patch, sx, sy, bflip);
|
||||
|
||||
if (dx < minx)
|
||||
minx = dx;
|
||||
if (dy < miny)
|
||||
miny = dy;
|
||||
if (dx > maxx)
|
||||
maxx = dx;
|
||||
if (dy > maxy)
|
||||
maxy = dy;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
ox = (newwidth / 2) + (leftoffset - xpivot);
|
||||
oy = (newheight / 2) + (patch->topoffset - ypivot);
|
||||
width = (maxx - minx);
|
||||
height = (maxy - miny);
|
||||
|
||||
if ((unsigned)(width * height) > size)
|
||||
{
|
||||
UINT16 *src, *dest;
|
||||
|
||||
size = (width * height);
|
||||
rawconv = Z_Calloc(size * sizeof(UINT16), PU_STATIC, NULL);
|
||||
|
||||
src = &rawdst[(miny * newwidth) + minx];
|
||||
dest = rawconv;
|
||||
dy = height;
|
||||
|
||||
while (dy--)
|
||||
{
|
||||
M_Memcpy(dest, src, width * sizeof(UINT16));
|
||||
dest += width;
|
||||
src += newwidth;
|
||||
}
|
||||
|
||||
ox -= minx;
|
||||
oy -= miny;
|
||||
|
||||
Z_Free(rawdst);
|
||||
}
|
||||
else
|
||||
{
|
||||
rawconv = rawdst;
|
||||
width = newwidth;
|
||||
height = newheight;
|
||||
}
|
||||
|
||||
// make patch
|
||||
rotated = (patch_t *)R_MaskedFlatToPatch(rawconv, width, height, 0, 0, &size);
|
||||
|
||||
Z_ChangeTag(rotated, PU_PATCH_ROTATED);
|
||||
Z_SetUser(rotated, (void **)(&rotsprite->patches[idx]));
|
||||
Z_Free(rawconv);
|
||||
|
||||
rotated->leftoffset = ox;
|
||||
rotated->topoffset = oy;
|
||||
}
|
||||
#endif
|
||||
+2
-14
@@ -15,8 +15,6 @@
|
||||
#define __R_PATCH__
|
||||
|
||||
#include "r_defs.h"
|
||||
#include "r_fps.h"
|
||||
#include "doomdef.h"
|
||||
|
||||
// Structs
|
||||
typedef enum
|
||||
@@ -58,17 +56,7 @@ extern spriteinfo_t spriteinfo[NUMSPRITES];
|
||||
void R_LoadSpriteInfoLumps(UINT16 wadnum, UINT16 numlumps);
|
||||
void R_ParseSPRTINFOLump(UINT16 wadNum, UINT16 lumpNum);
|
||||
|
||||
// Sprite rotation
|
||||
#ifdef ROTSPRITE
|
||||
INT32 R_GetRollAngle(angle_t rollangle);
|
||||
angle_t R_RotationAngle(angle_t ang, angle_t camang, interpmobjstate_t *interp);
|
||||
|
||||
patch_t *Patch_GetRotatedSprite(spriteframe_t *sprite, size_t frame, size_t spriteangle, boolean flip, void *info, INT32 rotationangle);
|
||||
rotsprite_t *RotatedPatch_Create(INT32 numangles);
|
||||
void RotatedPatch_DoRotation(rotsprite_t *rotsprite, patch_t *patch, INT32 angle, INT32 xpivot, INT32 ypivot, boolean flip);
|
||||
|
||||
extern fixed_t rollcosang[ROTANGLES];
|
||||
extern fixed_t rollsinang[ROTANGLES];
|
||||
#endif
|
||||
void *R_MaskedFlatToPatch(UINT16 *raw, INT16 width, INT16 height, INT16 leftoffset, INT16 topoffset, size_t *destsize);
|
||||
UINT16 R_GetPatchPixel(patch_t *patch, INT32 x, INT32 y, boolean flip);
|
||||
|
||||
#endif // __R_PATCH__
|
||||
@@ -0,0 +1,262 @@
|
||||
// SONIC ROBO BLAST 2
|
||||
//-----------------------------------------------------------------------------
|
||||
// Copyright (C) 2020-2023 by Lactozilla.
|
||||
//
|
||||
// This program is free software distributed under the
|
||||
// terms of the GNU General Public License, version 2.
|
||||
// See the 'LICENSE' file for more details.
|
||||
//-----------------------------------------------------------------------------
|
||||
/// \file r_patchrotation.c
|
||||
/// \brief Patch rotation.
|
||||
|
||||
#include "doomdef.h"
|
||||
#include "r_fps.h"
|
||||
#include "r_patch.h"
|
||||
#include "r_patchrotation.h"
|
||||
#include "z_zone.h"
|
||||
#include "w_wad.h"
|
||||
|
||||
#ifdef ROTSPRITE
|
||||
//
|
||||
// R_GetRollAngle
|
||||
//
|
||||
// Angles precalculated in R_InitSprites.
|
||||
//
|
||||
fixed_t rollcosang[ROTANGLES];
|
||||
fixed_t rollsinang[ROTANGLES];
|
||||
|
||||
INT32 R_GetRollAngle(angle_t rollangle)
|
||||
{
|
||||
INT32 ra = AngleFixed(rollangle)>>FRACBITS;
|
||||
#if (ROTANGDIFF > 1)
|
||||
ra += (ROTANGDIFF/2);
|
||||
#endif
|
||||
ra /= ROTANGDIFF;
|
||||
ra %= ROTANGLES;
|
||||
return ra;
|
||||
}
|
||||
|
||||
angle_t R_RotationAngle(angle_t ang, angle_t camang, interpmobjstate_t *interp)
|
||||
{
|
||||
return FixedMul(FINECOSINE((ang) >> ANGLETOFINESHIFT), interp->roll) +
|
||||
FixedMul(FINESINE((ang) >> ANGLETOFINESHIFT), interp->pitch) +
|
||||
FixedMul(FINECOSINE((camang) >> ANGLETOFINESHIFT), interp->sloperoll) +
|
||||
FixedMul(FINESINE((camang) >> ANGLETOFINESHIFT), interp->slopepitch);
|
||||
}
|
||||
|
||||
patch_t *Patch_GetRotatedSprite(spriteframe_t *sprite, size_t frame, size_t spriteangle, boolean flip, void *info, INT32 rotationangle)
|
||||
{
|
||||
rotsprite_t *rotsprite;
|
||||
spriteinfo_t *sprinfo = (spriteinfo_t *)info;
|
||||
INT32 idx = rotationangle;
|
||||
|
||||
if (rotationangle < 1 || rotationangle >= ROTANGLES)
|
||||
return NULL;
|
||||
|
||||
rotsprite = sprite->rotated[spriteangle];
|
||||
|
||||
if (rotsprite == NULL)
|
||||
{
|
||||
rotsprite = RotatedPatch_Create(ROTANGLES);
|
||||
sprite->rotated[spriteangle] = rotsprite;
|
||||
}
|
||||
|
||||
if (flip)
|
||||
idx += rotsprite->angles;
|
||||
|
||||
if (rotsprite->patches[idx] == NULL)
|
||||
{
|
||||
patch_t *patch;
|
||||
INT32 xpivot = 0, ypivot = 0;
|
||||
lumpnum_t lump = sprite->lumppat[spriteangle];
|
||||
|
||||
if (lump == LUMPERROR)
|
||||
return NULL;
|
||||
|
||||
patch = W_CachePatchNum(lump, PU_SPRITE);
|
||||
|
||||
if (sprinfo->available)
|
||||
{
|
||||
xpivot = sprinfo->pivot[frame].x;
|
||||
ypivot = sprinfo->pivot[frame].y;
|
||||
}
|
||||
else
|
||||
{
|
||||
xpivot = patch->leftoffset;
|
||||
ypivot = patch->height / 2;
|
||||
}
|
||||
|
||||
RotatedPatch_DoRotation(rotsprite, patch, rotationangle, xpivot, ypivot, flip);
|
||||
}
|
||||
|
||||
return rotsprite->patches[idx];
|
||||
}
|
||||
|
||||
rotsprite_t *RotatedPatch_Create(INT32 numangles)
|
||||
{
|
||||
rotsprite_t *rotsprite = Z_Calloc(sizeof(rotsprite_t), PU_STATIC, NULL);
|
||||
rotsprite->angles = numangles;
|
||||
rotsprite->patches = Z_Calloc(rotsprite->angles * 2 * sizeof(void *), PU_STATIC, NULL);
|
||||
return rotsprite;
|
||||
}
|
||||
|
||||
static void RotatedPatch_CalculateDimensions(
|
||||
INT32 width, INT32 height,
|
||||
fixed_t ca, fixed_t sa,
|
||||
INT32 *newwidth, INT32 *newheight)
|
||||
{
|
||||
fixed_t fixedwidth = (width * FRACUNIT);
|
||||
fixed_t fixedheight = (height * FRACUNIT);
|
||||
|
||||
fixed_t w1 = abs(FixedMul(fixedwidth, ca) - FixedMul(fixedheight, sa));
|
||||
fixed_t w2 = abs(FixedMul(-fixedwidth, ca) - FixedMul(fixedheight, sa));
|
||||
fixed_t h1 = abs(FixedMul(fixedwidth, sa) + FixedMul(fixedheight, ca));
|
||||
fixed_t h2 = abs(FixedMul(-fixedwidth, sa) + FixedMul(fixedheight, ca));
|
||||
|
||||
w1 = FixedInt(FixedCeil(w1 + (FRACUNIT/2)));
|
||||
w2 = FixedInt(FixedCeil(w2 + (FRACUNIT/2)));
|
||||
h1 = FixedInt(FixedCeil(h1 + (FRACUNIT/2)));
|
||||
h2 = FixedInt(FixedCeil(h2 + (FRACUNIT/2)));
|
||||
|
||||
*newwidth = max(width, max(w1, w2));
|
||||
*newheight = max(height, max(h1, h2));
|
||||
}
|
||||
|
||||
void RotatedPatch_DoRotation(rotsprite_t *rotsprite, patch_t *patch, INT32 angle, INT32 xpivot, INT32 ypivot, boolean flip)
|
||||
{
|
||||
UINT32 i;
|
||||
patch_t *rotated;
|
||||
|
||||
UINT16 *rawdst, *rawconv;
|
||||
size_t size;
|
||||
INT32 bflip = (flip != 0x00);
|
||||
|
||||
INT32 width = patch->width;
|
||||
INT32 height = patch->height;
|
||||
INT32 leftoffset = patch->leftoffset;
|
||||
INT32 newwidth, newheight;
|
||||
|
||||
fixed_t ca = rollcosang[angle];
|
||||
fixed_t sa = rollsinang[angle];
|
||||
fixed_t xcenter, ycenter;
|
||||
INT32 idx = angle;
|
||||
INT32 x, y;
|
||||
INT32 sx, sy;
|
||||
INT32 dx, dy;
|
||||
INT32 ox, oy;
|
||||
INT32 minx, miny, maxx, maxy;
|
||||
|
||||
// Don't cache angle = 0
|
||||
if (angle < 1 || angle >= ROTANGLES)
|
||||
return;
|
||||
|
||||
if (flip)
|
||||
{
|
||||
idx += rotsprite->angles;
|
||||
xpivot = width - xpivot;
|
||||
leftoffset = width - leftoffset;
|
||||
}
|
||||
|
||||
if (rotsprite->patches[idx])
|
||||
return;
|
||||
|
||||
// Find the dimensions of the rotated patch.
|
||||
RotatedPatch_CalculateDimensions(width, height, ca, sa, &newwidth, &newheight);
|
||||
|
||||
xcenter = (xpivot * FRACUNIT);
|
||||
ycenter = (ypivot * FRACUNIT);
|
||||
|
||||
if (xpivot != width / 2 || ypivot != height / 2)
|
||||
{
|
||||
newwidth *= 2;
|
||||
newheight *= 2;
|
||||
}
|
||||
|
||||
minx = newwidth;
|
||||
miny = newheight;
|
||||
maxx = 0;
|
||||
maxy = 0;
|
||||
|
||||
// Draw the rotated sprite to a temporary buffer.
|
||||
size = (newwidth * newheight);
|
||||
if (!size)
|
||||
size = (width * height);
|
||||
rawdst = Z_Malloc(size * sizeof(UINT16), PU_STATIC, NULL);
|
||||
|
||||
for (i = 0; i < size; i++)
|
||||
rawdst[i] = 0xFF00;
|
||||
|
||||
for (dy = 0; dy < newheight; dy++)
|
||||
{
|
||||
for (dx = 0; dx < newwidth; dx++)
|
||||
{
|
||||
x = (dx - (newwidth / 2)) * FRACUNIT;
|
||||
y = (dy - (newheight / 2)) * FRACUNIT;
|
||||
sx = FixedMul(x, ca) + FixedMul(y, sa) + xcenter;
|
||||
sy = -FixedMul(x, sa) + FixedMul(y, ca) + ycenter;
|
||||
|
||||
sx >>= FRACBITS;
|
||||
sy >>= FRACBITS;
|
||||
|
||||
if (sx >= 0 && sy >= 0 && sx < width && sy < height)
|
||||
{
|
||||
rawdst[(dy * newwidth) + dx] = R_GetPatchPixel(patch, sx, sy, bflip);
|
||||
|
||||
if (dx < minx)
|
||||
minx = dx;
|
||||
if (dy < miny)
|
||||
miny = dy;
|
||||
if (dx > maxx)
|
||||
maxx = dx;
|
||||
if (dy > maxy)
|
||||
maxy = dy;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
ox = (newwidth / 2) + (leftoffset - xpivot);
|
||||
oy = (newheight / 2) + (patch->topoffset - ypivot);
|
||||
width = (maxx - minx);
|
||||
height = (maxy - miny);
|
||||
|
||||
if ((unsigned)(width * height) > size)
|
||||
{
|
||||
UINT16 *src, *dest;
|
||||
|
||||
size = (width * height);
|
||||
rawconv = Z_Calloc(size * sizeof(UINT16), PU_STATIC, NULL);
|
||||
|
||||
src = &rawdst[(miny * newwidth) + minx];
|
||||
dest = rawconv;
|
||||
dy = height;
|
||||
|
||||
while (dy--)
|
||||
{
|
||||
M_Memcpy(dest, src, width * sizeof(UINT16));
|
||||
dest += width;
|
||||
src += newwidth;
|
||||
}
|
||||
|
||||
ox -= minx;
|
||||
oy -= miny;
|
||||
|
||||
Z_Free(rawdst);
|
||||
}
|
||||
else
|
||||
{
|
||||
rawconv = rawdst;
|
||||
width = newwidth;
|
||||
height = newheight;
|
||||
}
|
||||
|
||||
// make patch
|
||||
rotated = (patch_t *)R_MaskedFlatToPatch(rawconv, width, height, 0, 0, &size);
|
||||
|
||||
Z_ChangeTag(rotated, PU_PATCH_ROTATED);
|
||||
Z_SetUser(rotated, (void **)(&rotsprite->patches[idx]));
|
||||
Z_Free(rawconv);
|
||||
|
||||
rotated->leftoffset = ox;
|
||||
rotated->topoffset = oy;
|
||||
}
|
||||
#endif
|
||||
@@ -0,0 +1,30 @@
|
||||
// SONIC ROBO BLAST 2
|
||||
//-----------------------------------------------------------------------------
|
||||
// Copyright (C) 2020-2023 by Lactozilla.
|
||||
//
|
||||
// This program is free software distributed under the
|
||||
// terms of the GNU General Public License, version 2.
|
||||
// See the 'LICENSE' file for more details.
|
||||
//-----------------------------------------------------------------------------
|
||||
/// \file r_patchrotation.h
|
||||
/// \brief Patch rotation.
|
||||
|
||||
#ifndef __R_PATCHROTATION__
|
||||
#define __R_PATCHROTATION__
|
||||
|
||||
#include "r_fps.h"
|
||||
|
||||
// Sprite rotation
|
||||
#ifdef ROTSPRITE
|
||||
INT32 R_GetRollAngle(angle_t rollangle);
|
||||
angle_t R_RotationAngle(angle_t ang, angle_t camang, interpmobjstate_t *interp);
|
||||
|
||||
rotsprite_t *RotatedPatch_Create(INT32 numangles);
|
||||
void RotatedPatch_DoRotation(rotsprite_t *rotsprite, patch_t *patch, INT32 angle, INT32 xpivot, INT32 ypivot, boolean flip);
|
||||
patch_t *Patch_GetRotatedSprite(spriteframe_t *sprite, size_t frame, size_t spriteangle, boolean flip, void *info, INT32 rotationangle);
|
||||
|
||||
extern fixed_t rollcosang[ROTANGLES];
|
||||
extern fixed_t rollsinang[ROTANGLES];
|
||||
#endif
|
||||
|
||||
#endif // __R_PATCHROTATION__
|
||||
+19
-15
@@ -11,34 +11,38 @@
|
||||
/// \file r_things.c
|
||||
/// \brief Refresh of things, i.e. objects represented by sprites
|
||||
|
||||
#include "doomdef.h"
|
||||
#include "console.h"
|
||||
#include "g_game.h"
|
||||
#include "r_local.h"
|
||||
#include "st_stuff.h"
|
||||
#include "w_wad.h"
|
||||
#include "z_zone.h"
|
||||
#include "m_misc.h"
|
||||
#include "i_video.h" // rendermode
|
||||
#include "r_main.h" // stplyr
|
||||
#include "r_fps.h"
|
||||
#include "r_things.h"
|
||||
#include "r_patch.h"
|
||||
#include "r_plane.h"
|
||||
#include "r_portal.h"
|
||||
#include "r_local.h"
|
||||
|
||||
#include "dehacked.h" // get_number (for thok)
|
||||
#include "doomdef.h"
|
||||
#include "d_netfil.h" // blargh. for nameonly().
|
||||
#include "console.h"
|
||||
#include "g_game.h"
|
||||
#include "k_kart.h" // SRB2kart
|
||||
#include "p_tick.h"
|
||||
#include "p_local.h"
|
||||
#include "p_setup.h"
|
||||
#include "p_slopes.h"
|
||||
#include "dehacked.h" // get_number (for thok)
|
||||
#include "d_netfil.h" // blargh. for nameonly().
|
||||
#include "st_stuff.h"
|
||||
#include "m_cheat.h" // objectplace
|
||||
#include "r_portal.h"
|
||||
#include "k_kart.h" // SRB2kart
|
||||
#include "p_local.h" // stplyr
|
||||
#include "m_misc.h"
|
||||
#include "i_video.h" // rendermode
|
||||
#include "w_wad.h"
|
||||
#include "z_zone.h"
|
||||
|
||||
#ifdef HWRENDER
|
||||
#include "hardware/hw_md2.h"
|
||||
#endif
|
||||
|
||||
#ifdef ROTSPRITE
|
||||
#include "r_patchrotation.h"
|
||||
#endif
|
||||
|
||||
#include "qs22j.h"
|
||||
|
||||
CV_PossibleValue_t Forceskin_cons_t[MAXSKINS+2];
|
||||
|
||||
@@ -897,6 +897,14 @@ SOURCE=..\r_patch.h
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=..\r_patchrotation.c
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=..\r_patchrotation.h
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=..\r_plane.c
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
+2
-1
@@ -58,6 +58,7 @@
|
||||
#include "dehacked.h"
|
||||
#include "d_clisrv.h"
|
||||
#include "r_defs.h"
|
||||
#include "r_patch.h"
|
||||
#include "i_system.h"
|
||||
#include "md5.h"
|
||||
#include "lua_script.h"
|
||||
@@ -72,7 +73,7 @@
|
||||
#endif
|
||||
|
||||
#ifdef ROTSPRITE
|
||||
#include "r_patch.h" // RotatedPatch_Create
|
||||
#include "r_patchrotation.h" // RotatedPatch_Create
|
||||
#endif
|
||||
|
||||
#ifndef O_BINARY
|
||||
|
||||
Reference in new issue
Block a user