- cleanup of 3D viewport code.

Removes all the hackery that Polymost needed and now uses a sane struct to store the info.
This commit is contained in:
Christoph Oelckers 2022-08-04 23:47:01 +02:00
parent 4ec748a92b
commit c2fc7577db
29 changed files with 192 additions and 221 deletions

View file

@ -116,9 +116,6 @@ enum {
inline int32_t g_visibility = 512, g_relvisibility = 0;
EXTERN vec2_t windowxy1, windowxy2;
EXTERN int32_t xdim, ydim;
extern uint8_t globalr, globalg, globalb;
enum {
@ -133,11 +130,6 @@ EXTERN int32_t enginecompatibility_mode;
void engineInit(void);
void videoSetViewableArea(int32_t x1, int32_t y1, int32_t x2, int32_t y2);
FCanvasTexture *renderSetTarget(int16_t tilenume);
void renderRestoreTarget();
void setVideoMode();
class F2DDrawer;

View file

@ -628,72 +628,6 @@ void rotatepoint(vec2_t const pivot, vec2_t p, int16_t const daang, vec2_t * con
p2->Y = DMulScale(p.Y, dacos, p.X, dasin, 14) + pivot.Y;
}
//
// setview
//
void videoSetViewableArea(int32_t x1, int32_t y1, int32_t x2, int32_t y2)
{
windowxy1.X = x1;
windowxy1.Y = y1;
windowxy2.X = x2;
windowxy2.Y = y2;
}
#include "v_2ddrawer.h"
//MUST USE RESTOREFORDRAWROOMS AFTER DRAWING
static int32_t setviewcnt = 0; // interface layers use this now
static int32_t bakxsiz, bakysiz;
static vec2_t bakwindowxy1, bakwindowxy2;
//
// setviewtotile
//
FCanvasTexture* renderSetTarget(int16_t tilenume)
{
auto tex = tileGetTexture(tilenume);
if (!tex || !tex->isHardwareCanvas()) return nullptr;
auto canvas = static_cast<FCanvasTexture*>(tex->GetTexture());
if (!canvas) return nullptr;
int xsiz = tex->GetTexelWidth(), ysiz = tex->GetTexelHeight();
if (setviewcnt > 0 || xsiz <= 0 || ysiz <= 0)
return nullptr;
//DRAWROOMS TO TILE BACKUP&SET CODE
bakxsiz = xdim; bakysiz = ydim;
bakwindowxy1 = windowxy1;
bakwindowxy2 = windowxy2;
setviewcnt++;
xdim = ysiz;
ydim = xsiz;
videoSetViewableArea(0,0,ysiz-1,xsiz-1);
return canvas;
}
//
// setviewback
//
void renderRestoreTarget()
{
if (setviewcnt <= 0) return;
setviewcnt--;
xdim = bakxsiz;
ydim = bakysiz;
videoSetViewableArea(bakwindowxy1.X,bakwindowxy1.Y,
bakwindowxy2.X,bakwindowxy2.Y);
}
int tilehasmodelorvoxel(int const tilenume, int pal)
{
return

View file

@ -796,19 +796,19 @@ void F2DDrawer::AddPoly(FGameTexture *texture, FVector2 *points, int npoints,
//
//==========================================================================
void F2DDrawer::AddPoly(FGameTexture* img, FVector4* vt, size_t vtcount, const unsigned int* ind, size_t idxcount, int translation, PalEntry color, FRenderStyle style, int clipx1, int clipy1, int clipx2, int clipy2)
void F2DDrawer::AddPoly(FGameTexture* img, FVector4* vt, size_t vtcount, const unsigned int* ind, size_t idxcount, int translation, PalEntry color, FRenderStyle style, const IntRect* clip)
{
RenderCommand dg;
if (!img || !img->isValid()) return;
dg.mType = DrawTypeTriangles;
if (clipx1 > 0 || clipy1 > 0 || clipx2 < GetWidth() - 1 || clipy2 < GetHeight() - 1)
if (clip != nullptr)
{
dg.mScissor[0] = clipx1 + int(offset.X);
dg.mScissor[1] = clipy1 + int(offset.Y);
dg.mScissor[2] = clipx2 + 1 + int(offset.X);
dg.mScissor[3] = clipy2 + 1 + int(offset.Y);
dg.mScissor[0] = clip->Left() + int(offset.X);
dg.mScissor[1] = clip->Top() + int(offset.Y);
dg.mScissor[2] = clip->Right() + int(offset.X);
dg.mScissor[3] = clip->Bottom() + int(offset.Y);
dg.mFlags |= DTF_Scissor;
}
@ -1040,19 +1040,19 @@ void F2DDrawer::ClearScreen(PalEntry color)
//
//==========================================================================
void F2DDrawer::AddLine(double x1, double y1, double x2, double y2, int clipx1, int clipy1, int clipx2, int clipy2, uint32_t color, uint8_t alpha)
void F2DDrawer::AddLine(double x1, double y1, double x2, double y2, const IntRect* clip, uint32_t color, uint8_t alpha)
{
PalEntry p = (PalEntry)color;
p.a = alpha;
RenderCommand dg;
if (clipx1 > 0 || clipy1 > 0 || clipx2 < GetWidth()- 1 || clipy2 < GetHeight() - 1)
if (clip != nullptr)
{
dg.mScissor[0] = clipx1 + int(offset.X);
dg.mScissor[1] = clipy1 + int(offset.Y);
dg.mScissor[2] = clipx2 + 1 + int(offset.X);
dg.mScissor[3] = clipy2 + 1 + int(offset.Y);
dg.mScissor[0] = clip->Left() + int(offset.X);
dg.mScissor[1] = clip->Top() + int(offset.Y);
dg.mScissor[2] = clip->Right() + int(offset.X);
dg.mScissor[3] = clip->Bottom() + int(offset.Y);
dg.mFlags |= DTF_Scissor;
}

View file

@ -11,6 +11,7 @@
struct DrawParms;
struct FColormap;
struct IntRect;
class DShape2DTransform : public DObject
{
@ -215,7 +216,7 @@ public:
void AddPoly(FGameTexture *texture, FVector2 *points, int npoints,
double originx, double originy, double scalex, double scaley,
DAngle rotation, const FColormap &colormap, PalEntry flatcolor, double lightlevel, uint32_t *indices, size_t indexcount);
void AddPoly(FGameTexture* img, FVector4 *vt, size_t vtcount, const unsigned int *ind, size_t idxcount, int translation, PalEntry color, FRenderStyle style, int clipx1, int clipy1, int clipx2, int clipy2);
void AddPoly(FGameTexture* img, FVector4 *vt, size_t vtcount, const unsigned int *ind, size_t idxcount, int translation, PalEntry color, FRenderStyle style, const IntRect* clip);
void FillPolygon(int* rx1, int* ry1, int* xb1, int32_t npoints, int picnum, int palette, int shade, int props, const FVector2& xtex, const FVector2& ytex, const FVector2& otex,
int clipx1, int clipy1, int clipx2, int clipy2);
void AddFlatFill(int left, int top, int right, int bottom, FGameTexture *src, int local_origin = false, double flatscale = 1.0, PalEntry color = 0xffffffff, ERenderStyle rs = STYLE_Normal);
@ -226,7 +227,7 @@ public:
void AddClear(int left, int top, int right, int bottom, int palcolor, uint32_t color);
void AddLine(double x1, double y1, double x2, double y2, int cx, int cy, int cx2, int cy2, uint32_t color, uint8_t alpha = 255);
void AddLine(double x1, double y1, double x2, double y2, const IntRect* clip, uint32_t color, uint8_t alpha = 255);
void AddThickLine(int x1, int y1, int x2, int y2, double thickness, uint32_t color, uint8_t alpha = 255);
void AddPixel(int x1, int y1, uint32_t color);

View file

@ -1564,7 +1564,7 @@ void VirtualToRealCoordsInt(F2DDrawer *drawer, int &x, int &y, int &w, int &h,
static void DrawLine(int x0, int y0, int x1, int y1, uint32_t realcolor, int alpha)
{
if (!twod->HasBegun2D()) ThrowAbortException(X_OTHER, "Attempt to draw to screen outside a draw function");
twod->AddLine((float)x0, (float)y0, (float)x1, (float)y1, -1, -1, INT_MAX, INT_MAX, realcolor | MAKEARGB(255, 0, 0, 0), alpha);
twod->AddLine((float)x0, (float)y0, (float)x1, (float)y1, nullptr, realcolor | MAKEARGB(255, 0, 0, 0), alpha);
}
DEFINE_ACTION_FUNCTION_NATIVE(_Screen, DrawLine, DrawLine)
@ -1589,7 +1589,7 @@ DEFINE_ACTION_FUNCTION(FCanvas, DrawLine)
PARAM_INT(y1);
PARAM_INT(color);
PARAM_INT(alpha);
self->Drawer.AddLine((float)x0, (float)y0, (float)x1, (float)y1, -1, -1, INT_MAX, INT_MAX, color | MAKEARGB(255, 0, 0, 0), alpha);
self->Drawer.AddLine((float)x0, (float)y0, (float)x1, (float)y1, nullptr, color | MAKEARGB(255, 0, 0, 0), alpha);
self->Tex->NeedUpdate();
return 0;
}

View file

@ -6,7 +6,6 @@ struct IntRect
int left, top;
int width, height;
void Offset(int xofs, int yofs)
{
left += xofs;
@ -26,6 +25,37 @@ struct IntRect
height = y - top;
}
int Left() const
{
return left;
}
int Top() const
{
return top;
}
int Right() const
{
return left + width;
}
int Bottom() const
{
return top + height;
}
int Width() const
{
return width;
}
int Height() const
{
return height;
}
};

View file

@ -324,7 +324,7 @@ void drawlinergb(int32_t x1, int32_t y1, int32_t x2, int32_t y2, PalEntry p)
twod->AddThickLine(x1 / 4096, y1 / 4096, x2 / 4096, y2 / 4096, am_linethickness, p, uint8_t(am_linealpha * 255));
} else {
// Use more efficient thin line drawing routine.
twod->AddLine(x1 / 4096.f, y1 / 4096.f, x2 / 4096.f, y2 / 4096.f, windowxy1.X, windowxy1.Y, windowxy2.X, windowxy2.Y, p, uint8_t(am_linealpha * 255));
twod->AddLine(x1 / 4096.f, y1 / 4096.f, x2 / 4096.f, y2 / 4096.f, &viewport3d, p, uint8_t(am_linealpha * 255));
}
}
@ -600,7 +600,7 @@ void renderDrawMapView(int cposx, int cposy, int czoom, int cang)
}
twod->AddPoly(tileGetTexture(picnum, true), vertices.Data(), vertices.Size(), (unsigned*)indices->Data(), indices->Size(), translation, light,
LegacyRenderStyles[STYLE_Translucent], windowxy1.X, windowxy1.Y, windowxy2.X + 1, windowxy2.Y + 1);
LegacyRenderStyles[STYLE_Translucent], &viewport3d);
}
}
qsort(floorsprites.Data(), floorsprites.Size(), sizeof(DCoreActor*), [](const void* a, const void* b)
@ -644,8 +644,7 @@ void renderDrawMapView(int cposx, int cposy, int czoom, int cang)
int picnum = actor->spr.picnum;
gotpic.Set(picnum);
const static unsigned indices[] = { 0, 1, 2, 0, 2, 3 };
twod->AddPoly(tileGetTexture(picnum, true), vertices.Data(), vertices.Size(), indices, 6, translation, color, rs,
windowxy1.X, windowxy1.Y, windowxy2.X + 1, windowxy2.Y + 1);
twod->AddPoly(tileGetTexture(picnum, true), vertices.Data(), vertices.Size(), indices, 6, translation, color, rs, &viewport3d);
}
}

View file

@ -257,10 +257,10 @@ static bool System_DisableTextureFilter()
static IntRect System_GetSceneRect()
{
int viewbottom = windowxy2.Y + 1;
int viewheight = viewbottom - windowxy1.Y;
int viewright = windowxy2.X + 1;
int viewwidth = viewright - windowxy1.X;
int viewbottom = viewport3d.Bottom();
int viewheight = viewport3d.Height();
int viewright = viewport3d.Right();
int viewwidth = viewport3d.Width();
int renderheight;
@ -268,8 +268,8 @@ static IntRect System_GetSceneRect()
else renderheight = (viewwidth * screen->GetHeight() / screen->GetWidth()) & ~7;
IntRect mSceneViewport;
mSceneViewport.left = windowxy1.X;
mSceneViewport.top = screen->GetHeight() - (renderheight + windowxy1.Y - ((renderheight - viewheight) / 2));
mSceneViewport.left = viewport3d.Left();
mSceneViewport.top = screen->GetHeight() - (renderheight + viewport3d.Top() - ((renderheight - viewheight) / 2));
mSceneViewport.width = viewwidth;
mSceneViewport.height = renderheight;
return mSceneViewport;
@ -1184,10 +1184,10 @@ void LoadVoxelModels(void);
void setVideoMode()
{
xdim = screen->GetWidth();
ydim = screen->GetHeight();
int xdim = screen->GetWidth();
int ydim = screen->GetHeight();
V_UpdateModeSize(xdim, ydim);
videoSetViewableArea(0, 0, xdim - 1, ydim - 1);
viewport3d = { 0, 0, xdim, ydim };
}
//==========================================================================
@ -1460,7 +1460,7 @@ void DrawCrosshair(int deftile, int health, double xdelta, double ydelta, double
double crosshair_scale = crosshairscale * scale;
DrawTexture(twod, tile, 160 + xdelta, 100 + ydelta, DTA_Color, color,
DTA_FullscreenScale, FSMode_Fit320x200, DTA_ScaleX, crosshair_scale, DTA_ScaleY, crosshair_scale, DTA_CenterOffsetRel, true,
DTA_ViewportX, windowxy1.X, DTA_ViewportY, windowxy1.Y, DTA_ViewportWidth, windowxy2.X - windowxy1.X + 1, DTA_ViewportHeight, windowxy2.Y - windowxy1.Y + 1, TAG_DONE);
DTA_ViewportX, viewport3d.Left(), DTA_ViewportY, viewport3d.Top(), DTA_ViewportWidth, viewport3d.Width(), DTA_ViewportHeight, viewport3d.Height(), TAG_DONE);
return;
}
@ -1468,8 +1468,8 @@ void DrawCrosshair(int deftile, int health, double xdelta, double ydelta, double
// 0 means 'game provided crosshair' - use type 2 as fallback.
ST_LoadCrosshair(crosshair == 0 ? 2 : *crosshair, false);
double xpos = (windowxy1.X + windowxy2.X) / 2 + xdelta * (windowxy2.Y - windowxy1.Y) / 240.;
double ypos = (windowxy1.Y + windowxy2.Y) / 2;
double xpos = viewport3d.Width() * 0.5 + xdelta * viewport3d.Height() / 240.;
double ypos = viewport3d.Height() * 0.5;
ST_DrawCrosshair(health, xpos, ypos, 1);
}
}
@ -1573,10 +1573,10 @@ bool validFilter(const char* str)
DEFINE_ACTION_FUNCTION(_Screen, GetViewWindow)
{
PARAM_PROLOGUE;
if (numret > 0) ret[0].SetInt(windowxy1.X);
if (numret > 1) ret[1].SetInt(windowxy1.Y);
if (numret > 2) ret[2].SetInt(windowxy2.X - windowxy1.X + 1);
if (numret > 3) ret[3].SetInt(windowxy2.Y - windowxy1.Y + 1);
if (numret > 0) ret[0].SetInt(viewport3d.Left());
if (numret > 1) ret[1].SetInt(viewport3d.Top());
if (numret > 2) ret[2].SetInt(viewport3d.Width());
if (numret > 3) ret[3].SetInt(viewport3d.Height());
return min(numret, 4);
}

View file

@ -26,6 +26,8 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
#include "coreactor.h"
#include "interpolate.h"
IntRect viewport3d;
//---------------------------------------------------------------------------
//
// Unified chasecam function for all games.

View file

@ -4,6 +4,9 @@
#include "binaryangle.h"
#include "build.h"
#include "coreactor.h"
#include "intrect.h"
extern IntRect viewport3d;
// breadth first search, this gets used multiple times throughout the engine, mainly for iterating over sectors.
// Only works on indices, this has no knowledge of the actual objects being looked at.

View file

@ -65,8 +65,8 @@ void hud_drawsprite(double sx, double sy, double sz, double a, int picnum, int d
DTA_ScaleX, sz, DTA_ScaleY, sz,
DTA_Color, shadeToLight(dashade),
DTA_TranslationIndex, palid,
DTA_ViewportX, windowxy1.X, DTA_ViewportY, windowxy1.Y,
DTA_ViewportWidth, windowxy2.X - windowxy1.X + 1, DTA_ViewportHeight, windowxy2.Y - windowxy1.Y + 1,
DTA_ViewportX, viewport3d.Left(), DTA_ViewportY, viewport3d.Top(),
DTA_ViewportWidth, viewport3d.Width(), DTA_ViewportHeight, viewport3d.Height(),
DTA_FullscreenScale, (dastat & RS_STRETCH)? FSMode_ScaleToScreen: FSMode_ScaleToHeight, DTA_VirtualWidth, 320, DTA_VirtualHeight, 200,
DTA_CenterOffsetRel, (dastat & (RS_TOPLEFT | RS_CENTER))? 0:2,
DTA_TopLeft, !!(dastat & RS_TOPLEFT),

View file

@ -240,7 +240,7 @@ DEFINE_ACTION_FUNCTION(_UserMapMenu, DrawPreview)
auto point2 = &entry->walls[wal.point2];
twod->AddLine(dcenterx + (wal.pos.X - centerx) * scale, dcentery + (wal.pos.Y - centery) * scale,
dcenterx + (point2->pos.X - centerx) * scale, dcentery + (point2->pos.Y - centery) * scale,
-1, -1, INT_MAX, INT_MAX, 0xff808080);
nullptr, 0xff808080);
}
for (auto& wal : entry->walls)
{
@ -248,7 +248,7 @@ DEFINE_ACTION_FUNCTION(_UserMapMenu, DrawPreview)
auto point2 = &entry->walls[wal.point2];
twod->AddLine(dcenterx + (wal.pos.X - centerx) * scale, dcentery + (wal.pos.Y - centery) * scale,
dcenterx + (point2->pos.X - centerx) * scale, dcentery + (point2->pos.Y - centery) * scale,
-1, -1, INT_MAX, INT_MAX, 0xffffffff);
nullptr, 0xffffffff);
}
return 0;
}

View file

@ -238,28 +238,15 @@ void DoWriteSavePic(FileWriter* file, uint8_t* scr, int width, int height, bool
bool writingsavepic;
FileWriter* savefile;
int savewidth, saveheight;
void PM_WriteSavePic(FileWriter* file, int width, int height);
void WriteSavePic(FileWriter* file, int width, int height)
{
int oldx = xdim;
int oldy = ydim;
auto oldwindowxy1 = windowxy1;
auto oldwindowxy2 = windowxy2;
xdim = width;
ydim = height;
videoSetViewableArea(0, 0, width - 1, height - 1);
writingsavepic = true;
savefile = file;
savewidth = width;
saveheight = height;
/*bool didit =*/ gi->GenerateSavePic();
writingsavepic = false;
xdim = oldx;
ydim = oldy;
videoSetViewableArea(oldwindowxy1.X, oldwindowxy1.Y, oldwindowxy2.X, oldwindowxy2.Y);
}
void RenderToSavePic(FRenderViewpoint& vp, FileWriter* file, int width, int height)

View file

@ -118,7 +118,7 @@ static int SaveScreenshot()
int pitch;
ESSType ctype;
auto imgBuf = screen->GetScreenshotBuffer(pitch, ctype, gamma);
WritePNGfile(fil, imgBuf.Data(), Palette, ctype, xdim, ydim, pitch, gamma);
WritePNGfile(fil, imgBuf.Data(), Palette, ctype, screen->GetWidth(), screen->GetHeight(), pitch, gamma);
delete fil;
Printf("screenshot saved\n");
return 0;

View file

@ -62,6 +62,7 @@
#include "razemenu.h"
#include "mapinfo.h"
#include "razefont.h"
#include "gamefuncs.h"
#include "../version.h"
@ -112,26 +113,26 @@ void setViewport(int viewSize)
if (viewSize > Hud_Stbar)
{
x0 = 0;
x1 = xdim - 1;
x1 = xdim;
y0 = reserved.top;
y1 = ydim - 1;
y1 = ydim;
}
else
{
x0 = 0;
y0 = reserved.top;
x1 = xdim - 1;
y1 = ydim - 1 - reserved.statusbar;
x1 = xdim;
y1 = ydim - reserved.statusbar;
int height = y1 - y0;
int frameheight = (height * (5 - viewSize) / 20);
int framewidth = Scale(frameheight, xdim, y1+1);
int framewidth = Scale(frameheight, xdim, y1);
x0 += framewidth;
x1 -= framewidth;
y0 += frameheight;
y1 -= frameheight;
}
videoSetViewableArea(x0, y0, x1, y1);
viewport3d = { x0, y0, x1 - x0, y1 - y0 };
}
//============================================================================

View file

@ -845,6 +845,26 @@ void tileUpdateAnimations()
}
}
//===========================================================================
//
// validates the texture for rendering to a given tilenum
//
//===========================================================================
FCanvasTexture* tileGetCanvas(int tilenum)
{
auto tex = tileGetTexture(tilenum);
if (!tex || !tex->isHardwareCanvas()) return nullptr;
auto canvas = static_cast<FCanvasTexture*>(tex->GetTexture());
if (!canvas) return nullptr;
int xsiz = tex->GetTexelWidth(), ysiz = tex->GetTexelHeight();
if (xsiz <= 0 || ysiz <= 0)
return nullptr;
return canvas;
}
//===========================================================================
//
// Parsing stuff for tile data comes below.

View file

@ -508,6 +508,7 @@ struct SetAnim
void processSetAnim(const char* cmd, FScriptPosition& pos, SetAnim& imp);
class FGameTexture;
bool PickTexture(FGameTexture* tex, int paletteid, TexturePick& pick, bool wantindexed = false);
FCanvasTexture* tileGetCanvas(int tilenum);
inline FixedBitArray<MAXTILES> gotpic;

View file

@ -99,7 +99,7 @@ void CGameMenuItemQAV::Draw(void)
if (bWideScreen)
{
int xdim43 = Scale(ydim, 4, 3);
int xdim43 = Scale(twod->GetHeight(), 4, 3);
int nCount = (twod->GetWidth() + xdim43 - 1) / xdim43;
int backX = data->x;
for (int i = 0; i < nCount; i++)

View file

@ -55,15 +55,15 @@ static void UpdateFrame(void)
int width = twod->GetWidth();
int height = twod->GetHeight();
twod->AddFlatFill(0, 0, width, windowxy1.Y - 3, tex);
twod->AddFlatFill(0, windowxy2.Y + 4, width, height, tex);
twod->AddFlatFill(0, windowxy1.Y - 3, windowxy1.X - 3, windowxy2.Y + 4, tex);
twod->AddFlatFill(windowxy2.X + 4, windowxy1.Y - 3, width, windowxy2.Y + 4, tex);
twod->AddFlatFill(0, 0, width, viewport3d.Top() - 3, tex);
twod->AddFlatFill(0, viewport3d.Bottom() + 3, width, height, tex);
twod->AddFlatFill(0, viewport3d.Top() - 3, viewport3d.Left() - 3, viewport3d.Bottom() + 3, tex);
twod->AddFlatFill(viewport3d.Right() + 3, viewport3d.Top() - 3, width, viewport3d.Bottom() + 3, tex);
twod->AddFlatFill(windowxy1.X - 3, windowxy1.Y - 3, windowxy1.X, windowxy2.Y + 1, tex, 0, 1, 0xff545454);
twod->AddFlatFill(windowxy1.X, windowxy1.Y - 3, windowxy2.X + 4, windowxy1.Y, tex, 0, 1, 0xff545454);
twod->AddFlatFill(windowxy2.X + 1, windowxy1.Y, windowxy2.X + 4, windowxy2.Y + 4, tex, 0, 1, 0xff2a2a2a);
twod->AddFlatFill(windowxy1.X - 3, windowxy2.Y + 1, windowxy2.X + 1, windowxy2.Y + 4, tex, 0, 1, 0xff2a2a2a);
twod->AddFlatFill(viewport3d.Left() - 3, viewport3d.Top() - 3, viewport3d.Left(), viewport3d.Bottom(), tex, 0, 1, 0xff545454);
twod->AddFlatFill(viewport3d.Left(), viewport3d.Top() - 3, viewport3d.Right() + 3, viewport3d.Top(), tex, 0, 1, 0xff545454);
twod->AddFlatFill(viewport3d.Right(), viewport3d.Top(), viewport3d.Right() + 3, viewport3d.Bottom() + 3, tex, 0, 1, 0xff2a2a2a);
twod->AddFlatFill(viewport3d.Left() - 3, viewport3d.Bottom(), viewport3d.Right(), viewport3d.Bottom() + 3, tex, 0, 1, 0xff2a2a2a);
}
//---------------------------------------------------------------------------

View file

@ -466,7 +466,7 @@ int32_t g_frameRate;
static void DrawMap(DBloodActor* view)
{
int tm = 0;
if (windowxy1.X > 0)
if (viewport3d.Left() > 0)
{
setViewport(Hud_Stbar);
tm = 1;
@ -630,7 +630,6 @@ void renderCrystalBall()
drawrooms(vd8, vd4, vd0, v50, v54, vcc);
viewProcessSprites(vd8, vd4, vd0, v50, gInterpolate);
renderDrawMasks();
renderRestoreTarget();
#endif
}
@ -875,8 +874,8 @@ bool GameInterface::DrawAutomapPlayer(int mx, int my, int x, int y, int z, int a
int oy = my - y;
int x1 = DMulScale(ox, xvect, -oy, yvect, 16);
int y1 = DMulScale(oy, xvect, ox, yvect, 16);
int xx = xdim / 2. + x1 / 4096.;
int yy = ydim / 2. + y1 / 4096.;
int xx = twod->GetWidth() / 2. + x1 / 4096.;
int yy = twod->GetHeight() / 2. + y1 / 4096.;
if (i == gView->nPlayer || gGameOptions.nGameType == 1)
{
@ -889,11 +888,11 @@ bool GameInterface::DrawAutomapPlayer(int mx, int my, int x, int y, int z, int a
int nScale = (actor->spr.yrepeat + ((floorZ - nBottom) >> 8)) * z;
nScale = ClipRange(nScale, 8000, 65536 << 1);
// Players on automap
double xsize = xdim / 2. + x1 / double(1 << 12);
double ysize = ydim / 2. + y1 / double(1 << 12);
double xsize = twod->GetWidth() / 2. + x1 / double(1 << 12);
double ysize = twod->GetHeight() / 2. + y1 / double(1 << 12);
// This very likely needs fixing later
DrawTexture(twod, tileGetTexture(nTile, true), xx, yy, DTA_ClipLeft, windowxy1.X, DTA_ClipTop, windowxy1.Y, DTA_ScaleX, z / 1536., DTA_ScaleY, z / 1536., DTA_CenterOffset, true,
DTA_ClipRight, windowxy2.X + 1, DTA_ClipBottom, windowxy2.Y + 1, DTA_Alpha, (actor->spr.cstat & CSTAT_SPRITE_TRANSLUCENT ? 0.5 : 1.), TAG_DONE);
DrawTexture(twod, tileGetTexture(nTile, true), xx, yy, DTA_ClipLeft, viewport3d.Left(), DTA_ClipTop, viewport3d.Top(), DTA_ScaleX, z / 1536., DTA_ScaleY, z / 1536., DTA_CenterOffset, true,
DTA_ClipRight, viewport3d.Right(), DTA_ClipBottom, viewport3d.Bottom(), DTA_Alpha, (actor->spr.cstat & CSTAT_SPRITE_TRANSLUCENT ? 0.5 : 1.), TAG_DONE);
}
}
return true;

View file

@ -326,8 +326,8 @@ void cameratext(DDukeActor *cam)
{
auto drawitem = [=](int tile, double x, double y, bool flipx, bool flipy)
{
DrawTexture(twod, tileGetTexture(tile), x, y, DTA_ViewportX, windowxy1.X, DTA_ViewportY, windowxy1.Y, DTA_ViewportWidth, windowxy2.X - windowxy1.X + 1, DTA_CenterOffsetRel, 2,
DTA_ViewportHeight, windowxy2.Y - windowxy1.Y + 1, DTA_FlipX, flipx, DTA_FlipY, flipy, DTA_FullscreenScale, FSMode_Fit320x200, TAG_DONE);
DrawTexture(twod, tileGetTexture(tile), x, y, DTA_ViewportX, viewport3d.Left(), DTA_ViewportY, viewport3d.Top(), DTA_ViewportWidth, viewport3d.Width(),
DTA_ViewportHeight, viewport3d.Height(), DTA_FlipX, flipx, DTA_FlipY, flipy, DTA_CenterOffsetRel, 2, DTA_FullscreenScale, FSMode_Fit320x200, TAG_DONE);
};
if (!cam->temp_data[0])
{
@ -404,6 +404,9 @@ bool GameInterface::DrawAutomapPlayer(int mx, int my, int cposx, int cposy, int
xvect = -bsin(cang) * czoom;
yvect = -bcos(cang) * czoom;
int xdim = twod->GetWidth() << 11;
int ydim = twod->GetHeight() << 11;
//Draw sprites
auto pactor = ps[screenpeek].GetActor();
for (unsigned ii = 0; ii < sector.Size(); ii++)
@ -438,12 +441,9 @@ bool GameInterface::DrawAutomapPlayer(int mx, int my, int cposx, int cposy, int
x3 = x2;
y3 = y2;
drawlinergb(x1 - x2 + (xdim << 11), y1 - y3 + (ydim << 11),
x1 + x2 + (xdim << 11), y1 + y3 + (ydim << 11), col);
drawlinergb(x1 - y2 + (xdim << 11), y1 + x3 + (ydim << 11),
x1 + x2 + (xdim << 11), y1 + y3 + (ydim << 11), col);
drawlinergb(x1 + y2 + (xdim << 11), y1 - x3 + (ydim << 11),
x1 + x2 + (xdim << 11), y1 + y3 + (ydim << 11), col);
drawlinergb(x1 - x2 + xdim, y1 - y3 + ydim, x1 + x2 + xdim, y1 + y3 + ydim, col);
drawlinergb(x1 - y2 + xdim, y1 + x3 + ydim, x1 + x2 + xdim, y1 + y3 + ydim, col);
drawlinergb(x1 + y2 + xdim, y1 - x3 + ydim, x1 + x2 + xdim, y1 + y3 + ydim, col);
break;
case CSTAT_SPRITE_ALIGNMENT_WALL:
@ -475,8 +475,8 @@ bool GameInterface::DrawAutomapPlayer(int mx, int my, int cposx, int cposy, int
x2 = DMulScale(ox, xvect, -oy, yvect, 16);
y2 = DMulScale(oy, xvect, ox, yvect, 16);
drawlinergb(x1 + (xdim << 11), y1 + (ydim << 11),
x2 + (xdim << 11), y2 + (ydim << 11), col);
drawlinergb(x1 + xdim, y1 + ydim,
x2 + xdim, y2 + ydim, col);
}
break;
@ -538,17 +538,17 @@ bool GameInterface::DrawAutomapPlayer(int mx, int my, int cposx, int cposy, int
x4 = DMulScale(ox, xvect, -oy, yvect, 16);
y4 = DMulScale(oy, xvect, ox, yvect, 16);
drawlinergb(x1 + (xdim << 11), y1 + (ydim << 11),
x2 + (xdim << 11), y2 + (ydim << 11), col);
drawlinergb(x1 + xdim, y1 + ydim,
x2 + xdim, y2 + ydim, col);
drawlinergb(x2 + (xdim << 11), y2 + (ydim << 11),
x3 + (xdim << 11), y3 + (ydim << 11), col);
drawlinergb(x2 + xdim, y2 + ydim,
x3 + xdim, y3 + ydim, col);
drawlinergb(x3 + (xdim << 11), y3 + (ydim << 11),
x4 + (xdim << 11), y4 + (ydim << 11), col);
drawlinergb(x3 + xdim, y3 + ydim,
x4 + xdim, y4 + ydim, col);
drawlinergb(x4 + (xdim << 11), y4 + (ydim << 11),
x1 + (xdim << 11), y1 + (ydim << 11), col);
drawlinergb(x4 + xdim, y4 + ydim,
x1 + xdim, y1 + ydim, col);
break;
}
@ -564,8 +564,8 @@ bool GameInterface::DrawAutomapPlayer(int mx, int my, int cposx, int cposy, int
oy = my - cposy;
x1 = DMulScale(ox, xvect, -oy, yvect, 16);
y1 = DMulScale(oy, xvect, ox, yvect, 16);
int xx = xdim / 2. + x1 / 4096.;
int yy = ydim / 2. + y1 / 4096.;
int xx = twod->GetWidth() / 2. + x1 / 4096.;
int yy = twod->GetHeight() / 2. + y1 / 4096.;
daang = ((!SyncInput() ? act->spr.ang : act->interpolatedang(smoothratio)) - cang) & 2047;

View file

@ -86,7 +86,7 @@ void GameInterface::UpdateCameras(double smoothratio)
auto tex = tileGetTexture(camsprite->spr.picnum);
TileFiles.MakeCanvas(TILE_VIEWSCR, (int)tex->GetDisplayWidth(), (int)tex->GetDisplayHeight());
auto canvas = renderSetTarget(TILE_VIEWSCR);
auto canvas = tileGetCanvas(TILE_VIEWSCR);
if (!canvas) return;
screen->RenderTextureView(canvas, [=](IntRect& rect)
@ -100,7 +100,6 @@ void GameInterface::UpdateCameras(double smoothratio)
camera->spr.cstat = cstat;
display_mirror = 0;
});
renderRestoreTarget();
}
}

View file

@ -53,28 +53,28 @@ void DrawBorder()
auto tex = tileGetTexture(TILE_SCREENBORDER);
if (tex != nullptr && tex->isValid())
{
if (windowxy1.Y > 0)
if (viewport3d.Top() > 0)
{
twod->AddFlatFill(0, 0, twod->GetWidth(), windowxy1.Y, tex, false, 1);
twod->AddFlatFill(0, 0, twod->GetWidth(), viewport3d.Top(), tex, false, 1);
}
if (windowxy2.Y + 1 < twod->GetHeight())
if (viewport3d.Bottom() < twod->GetHeight())
{
twod->AddFlatFill(0, windowxy2.Y + 1, twod->GetWidth(), twod->GetHeight(), tex, false, 1);
twod->AddFlatFill(0, viewport3d.Bottom(), twod->GetWidth(), twod->GetHeight(), tex, false, 1);
}
if (windowxy1.X > 0)
if (viewport3d.Left() > 0)
{
twod->AddFlatFill(0, windowxy1.Y, windowxy1.X, windowxy2.Y + 1, tex, false, 1);
twod->AddFlatFill(0, viewport3d.Top(), viewport3d.Left(), viewport3d.Bottom(), tex, false, 1);
}
if (windowxy2.X + 1 < twod->GetWidth())
if (viewport3d.Right() < twod->GetWidth())
{
twod->AddFlatFill(windowxy2.X + 1, windowxy1.Y, twod->GetWidth(), windowxy2.Y + 1, tex, false, 1);
twod->AddFlatFill(viewport3d.Right(), viewport3d.Top(), twod->GetWidth(), viewport3d.Bottom(), tex, false, 1);
}
auto vb = tileGetTexture(TILE_VIEWBORDER);
auto ve = tileGetTexture(TILE_VIEWBORDER + 1);
int x1 = windowxy1.X - 4;
int y1 = windowxy1.Y - 4;
int x2 = windowxy2.X + 5;
int y2 = windowxy2.Y + 5;
int x1 = viewport3d.Left() - 4;
int y1 = viewport3d.Top() - 4;
int x2 = viewport3d.Right() + 4;
int y2 = viewport3d.Bottom() + 4;
twod->AddFlatFill(x1, y1, x2, y1 + 4, vb, 5);
twod->AddFlatFill(x1, y2 - 4, x2, y2, vb, 6);
twod->AddFlatFill(x1, y1, x1 + 4, y2, vb, 1);

View file

@ -81,8 +81,8 @@ bool GameInterface::DrawAutomapPlayer(int mx, int my, int x, int y, int z, int a
int oy = my - y;
int x1 = DMulScale(ox, xvect, -oy, yvect, 16);
int y1 = DMulScale(oy, xvect, ox, yvect, 16);
int xx = xdim / 2. + x1 / 4096.;
int yy = ydim / 2. + y1 / 4096.;
int xx = twod->GetWidth() / 2. + x1 / 4096.;
int yy = twod->GetHeight() / 2. + y1 / 4096.;
if (i == nLocalPlayer)// || gGameOptions.nGameType == 1)
{
@ -95,8 +95,8 @@ bool GameInterface::DrawAutomapPlayer(int mx, int my, int x, int y, int z, int a
int nScale = (pPlayerActor->spr.yrepeat + ((floorZ - nBottom) >> 8)) * z;
nScale = clamp(nScale, 8000, 65536 << 1);
// This very likely needs fixing later
DrawTexture(twod, tileGetTexture(nTile /*+ ((PlayClock >> 4) & 3)*/, true), xx, yy, DTA_ClipLeft, windowxy1.X, DTA_ClipTop, windowxy1.Y, DTA_ScaleX, z / 1536., DTA_ScaleY, z / 1536., DTA_CenterOffset, true,
DTA_ClipRight, windowxy2.X + 1, DTA_ClipBottom, windowxy2.Y + 1, DTA_Alpha, (pPlayerActor->spr.cstat & CSTAT_SPRITE_TRANSLUCENT ? 0.5 : 1.), TAG_DONE);
DrawTexture(twod, tileGetTexture(nTile /*+ ((PlayClock >> 4) & 3)*/, true), xx, yy, DTA_ClipLeft, viewport3d.Left(), DTA_ClipTop, viewport3d.Top(), DTA_ScaleX, z / 1536., DTA_ScaleY, z / 1536., DTA_CenterOffset, true,
DTA_ClipRight, viewport3d.Right(), DTA_ClipBottom, viewport3d.Bottom(), DTA_Alpha, (pPlayerActor->spr.cstat & CSTAT_SPRITE_TRANSLUCENT ? 0.5 : 1.), TAG_DONE);
break;
}
}

View file

@ -122,15 +122,15 @@ void UpdateFrame()
{
auto tex = tileGetTexture(nBackgroundPic);
twod->AddFlatFill(0, 0, xdim, windowxy1.Y - 3, tex);
twod->AddFlatFill(0, windowxy2.Y + 4, xdim, ydim, tex);
twod->AddFlatFill(0, windowxy1.Y - 3, windowxy1.X - 3, windowxy2.Y + 4, tex);
twod->AddFlatFill(windowxy2.X + 4, windowxy1.Y - 3, xdim, windowxy2.Y + 4, tex);
twod->AddFlatFill(0, 0, twod->GetWidth(), viewport3d.Top() - 3, tex);
twod->AddFlatFill(0, viewport3d.Bottom() + 3, twod->GetWidth(), twod->GetHeight(), tex);
twod->AddFlatFill(0, viewport3d.Top() - 3, viewport3d.Left() - 3, viewport3d.Bottom() + 3, tex);
twod->AddFlatFill(viewport3d.Right() + 3, viewport3d.Top() - 3, twod->GetWidth(), viewport3d.Bottom() + 3, tex);
twod->AddFlatFill(windowxy1.X - 3, windowxy1.Y - 3, windowxy1.X, windowxy2.Y + 1, tex, 0, 1, 0xff545454);
twod->AddFlatFill(windowxy1.X, windowxy1.Y - 3, windowxy2.X + 4, windowxy1.Y, tex, 0, 1, 0xff545454);
twod->AddFlatFill(windowxy2.X + 1, windowxy1.Y, windowxy2.X + 4, windowxy2.Y + 4, tex, 0, 1, 0xff2a2a2a);
twod->AddFlatFill(windowxy1.X - 3, windowxy2.Y + 1, windowxy2.X + 1, windowxy2.Y + 4, tex, 0, 1, 0xff2a2a2a);
twod->AddFlatFill(viewport3d.Left() - 3, viewport3d.Top() - 3, viewport3d.Left(), viewport3d.Bottom(), tex, 0, 1, 0xff545454);
twod->AddFlatFill(viewport3d.Left(), viewport3d.Top() - 3, viewport3d.Right() + 3, viewport3d.Top(), tex, 0, 1, 0xff545454);
twod->AddFlatFill(viewport3d.Right(), viewport3d.Top(), viewport3d.Right() + 3, viewport3d.Bottom() + 3, tex, 0, 1, 0xff2a2a2a);
twod->AddFlatFill(viewport3d.Left() - 3, viewport3d.Bottom(), viewport3d.Right(), viewport3d.Bottom() + 3, tex, 0, 1, 0xff2a2a2a);
}
void StatusMessage(int messageTime, const char* fmt, ...)

View file

@ -323,7 +323,8 @@ void DrawView(double smoothRatio, bool sceneonly)
if (nFreeze == 2 || nFreeze == 1)
{
nSnakeCam = -1;
videoSetViewableArea(0, 0, xdim - 1, ydim - 1);
//???
viewport3d = { 0, 0, screen->GetWidth(), screen->GetHeight() };
}
UpdateMap();

View file

@ -1600,6 +1600,8 @@ bool GameInterface::DrawAutomapPlayer(int mx, int my, int cposx, int cposy, int
xvect = -bsin(cang) * czoom;
yvect = -bcos(cang) * czoom;
int xdim = twod->GetWidth() << 11;
int ydim = twod->GetHeight() << 11;
// Draw sprites
auto peekActor = Player[screenpeek].actor;
@ -1648,8 +1650,8 @@ bool GameInterface::DrawAutomapPlayer(int mx, int my, int cposx, int cposy, int
oy = my - cposy;
x1 = DMulScale(ox, xvect, -oy, yvect, 16);
y1 = DMulScale(oy, xvect, ox, yvect, 16);
int xx = xdim / 2. + x1 / 4096.;
int yy = ydim / 2. + y1 / 4096.;
int xx = twod->GetWidth() / 2. + x1 / 4096.;
int yy = twod->GetHeight() / 2. + y1 / 4096.;
if (czoom > 192)
{
@ -1704,8 +1706,7 @@ bool GameInterface::DrawAutomapPlayer(int mx, int my, int cposx, int cposy, int
x2 = MulScale(ox, xvect, 16) - MulScale(oy, yvect, 16);
y2 = MulScale(oy, xvect, 16) + MulScale(ox, yvect, 16);
drawlinergb(x1 + (xdim << 11), y1 + (ydim << 11),
x2 + (xdim << 11), y2 + (ydim << 11), col);
drawlinergb(x1 + xdim, y1 + ydim, x2 + xdim, y2 + ydim, col);
break;
case 32: // Floor sprite
@ -1762,17 +1763,17 @@ bool GameInterface::DrawAutomapPlayer(int mx, int my, int cposx, int cposy, int
x4 = MulScale(ox, xvect, 16) - MulScale(oy, yvect, 16);
y4 = MulScale(oy, xvect, 16) + MulScale(ox, yvect, 16);
drawlinergb(x1 + (xdim << 11), y1 + (ydim << 11),
x2 + (xdim << 11), y2 + (ydim << 11), col);
drawlinergb(x1 + xdim, y1 + ydim,
x2 + xdim, y2 + ydim, col);
drawlinergb(x2 + (xdim << 11), y2 + (ydim << 11),
x3 + (xdim << 11), y3 + (ydim << 11), col);
drawlinergb(x2 + xdim, y2 + ydim,
x3 + xdim, y3 + ydim, col);
drawlinergb(x3 + (xdim << 11), y3 + (ydim << 11),
x4 + (xdim << 11), y4 + (ydim << 11), col);
drawlinergb(x3 + xdim, y3 + ydim,
x4 + xdim, y4 + ydim, col);
drawlinergb(x4 + (xdim << 11), y4 + (ydim << 11),
x1 + (xdim << 11), y1 + (ydim << 11), col);
drawlinergb(x4 + xdim, y4 + ydim,
x1 + xdim, y1 + ydim, col);
}
break;

View file

@ -405,7 +405,7 @@ void JS_InitMirrors(void)
void drawroomstotile(int daposx, int daposy, int daposz,
binangle ang, fixedhoriz horiz, sectortype* dacursect, short tilenume, double smoothratio)
{
auto canvas = renderSetTarget(tilenume);
auto canvas = tileGetCanvas(tilenume);
if (!canvas) return;
screen->RenderTextureView(canvas, [=](IntRect& rect)
@ -413,7 +413,6 @@ void drawroomstotile(int daposx, int daposy, int daposz,
render_camtex(nullptr, { daposx, daposy, daposz }, dacursect, ang, horiz, buildang(0), tileGetTexture(tilenume), rect, smoothratio);
});
renderRestoreTarget();
}
void

View file

@ -56,16 +56,18 @@ static void UpdateFrame(void)
{
static const int kBackTile = 51;
auto tex = tileGetTexture(kBackTile);
int width = twod->GetWidth();
int height = twod->GetHeight();
twod->AddFlatFill(0, 0, xdim, windowxy1.Y - 3, tex);
twod->AddFlatFill(0, windowxy2.Y + 4, xdim, ydim, tex);
twod->AddFlatFill(0, windowxy1.Y - 3, windowxy1.X - 3, windowxy2.Y + 4, tex);
twod->AddFlatFill(windowxy2.X + 4, windowxy1.Y - 3, xdim, windowxy2.Y + 4, tex);
twod->AddFlatFill(0, 0, width, viewport3d.Top() - 3, tex);
twod->AddFlatFill(0, viewport3d.Bottom() + 3, width, height, tex);
twod->AddFlatFill(0, viewport3d.Top() - 3, viewport3d.Left() - 3, viewport3d.Bottom() + 3, tex);
twod->AddFlatFill(viewport3d.Right() + 3, viewport3d.Top() - 3, width, viewport3d.Bottom() + 3, tex);
twod->AddFlatFill(windowxy1.X - 3, windowxy1.Y - 3, windowxy1.X, windowxy2.Y + 1, tex, 0, 1, 0xff545454);
twod->AddFlatFill(windowxy1.X, windowxy1.Y - 3, windowxy2.X + 4, windowxy1.Y, tex, 0, 1, 0xff545454);
twod->AddFlatFill(windowxy2.X + 1, windowxy1.Y, windowxy2.X + 4, windowxy2.Y + 4, tex, 0, 1, 0xff2a2a2a);
twod->AddFlatFill(windowxy1.X - 3, windowxy2.Y + 1, windowxy2.X + 1, windowxy2.Y + 4, tex, 0, 1, 0xff2a2a2a);
twod->AddFlatFill(viewport3d.Left() - 3, viewport3d.Top() - 3, viewport3d.Left(), viewport3d.Bottom(), tex, 0, 1, 0xff545454);
twod->AddFlatFill(viewport3d.Left(), viewport3d.Top() - 3, viewport3d.Right() + 3, viewport3d.Top(), tex, 0, 1, 0xff545454);
twod->AddFlatFill(viewport3d.Right(), viewport3d.Top(), viewport3d.Right() + 3, viewport3d.Bottom() + 3, tex, 0, 1, 0xff2a2a2a);
twod->AddFlatFill(viewport3d.Left() - 3, viewport3d.Bottom(), viewport3d.Right(), viewport3d.Bottom() + 3, tex, 0, 1, 0xff2a2a2a);
}
//---------------------------------------------------------------------------