From a55be25a9d9765ddd43cfad2ca82bf23caba86e1 Mon Sep 17 00:00:00 2001 From: Magnus Norddahl Date: Thu, 8 Mar 2018 00:55:37 +0100 Subject: [PATCH 01/89] - add const qualifier on top/bottom clip arrays usage --- src/swrenderer/line/r_fogboundary.cpp | 2 +- src/swrenderer/line/r_fogboundary.h | 2 +- src/swrenderer/line/r_renderdrawsegment.cpp | 12 +++---- src/swrenderer/things/r_visiblesprite.cpp | 39 +++++++++++---------- 4 files changed, 28 insertions(+), 27 deletions(-) diff --git a/src/swrenderer/line/r_fogboundary.cpp b/src/swrenderer/line/r_fogboundary.cpp index bd6ba50aa5..1b8f1c99d0 100644 --- a/src/swrenderer/line/r_fogboundary.cpp +++ b/src/swrenderer/line/r_fogboundary.cpp @@ -54,7 +54,7 @@ namespace swrenderer { - void RenderFogBoundary::Render(RenderThread *thread, int x1, int x2, short *uclip, short *dclip, int wallshade, float lightleft, float lightstep, FDynamicColormap *basecolormap) + void RenderFogBoundary::Render(RenderThread *thread, int x1, int x2, const short *uclip, const short *dclip, int wallshade, float lightleft, float lightstep, FDynamicColormap *basecolormap) { // This is essentially the same as R_MapVisPlane but with an extra step // to create new horizontal spans whenever the light changes enough that diff --git a/src/swrenderer/line/r_fogboundary.h b/src/swrenderer/line/r_fogboundary.h index 39005c0396..b506ec7f8e 100644 --- a/src/swrenderer/line/r_fogboundary.h +++ b/src/swrenderer/line/r_fogboundary.h @@ -31,7 +31,7 @@ namespace swrenderer class RenderFogBoundary { public: - void Render(RenderThread *thread, int x1, int x2, short *uclip, short *dclip, int wallshade, float lightleft, float lightstep, FDynamicColormap *basecolormap); + void Render(RenderThread *thread, int x1, int x2, const short *uclip, const short *dclip, int wallshade, float lightleft, float lightstep, FDynamicColormap *basecolormap); private: void RenderSection(RenderThread *thread, int y, int y2, int x1); diff --git a/src/swrenderer/line/r_renderdrawsegment.cpp b/src/swrenderer/line/r_renderdrawsegment.cpp index 89c73455c4..3550b7356b 100644 --- a/src/swrenderer/line/r_renderdrawsegment.cpp +++ b/src/swrenderer/line/r_renderdrawsegment.cpp @@ -130,8 +130,8 @@ namespace swrenderer bool notrelevant = false; if (ds->bFogBoundary) { - short *mfloorclip = ds->sprbottomclip - ds->x1; - short *mceilingclip = ds->sprtopclip - ds->x1; + const short *mfloorclip = ds->sprbottomclip - ds->x1; + const short *mceilingclip = ds->sprtopclip - ds->x1; RenderFogBoundary renderfog; renderfog.Render(Thread, x1, x2, mceilingclip, mfloorclip, wallshade, rw_light, rw_lightstep, basecolormap); @@ -179,8 +179,8 @@ namespace swrenderer tex = tex->GetRawTexture(); } - short *mfloorclip = ds->sprbottomclip - ds->x1; - short *mceilingclip = ds->sprtopclip - ds->x1; + const short *mfloorclip = ds->sprbottomclip - ds->x1; + const short *mceilingclip = ds->sprtopclip - ds->x1; float *MaskedSWall = ds->swall - ds->x1; float MaskedScaleY = ds->yscale; @@ -428,8 +428,8 @@ namespace swrenderer rw_lightstep = ds->lightstep; rw_light = ds->light + (x1 - ds->x1) * rw_lightstep; - short *mfloorclip = ds->sprbottomclip - ds->x1; - short *mceilingclip = ds->sprtopclip - ds->x1; + const short *mfloorclip = ds->sprbottomclip - ds->x1; + const short *mceilingclip = ds->sprtopclip - ds->x1; //double spryscale = ds->iscale + ds->iscalestep * (x1 - ds->x1); float *MaskedSWall = ds->swall - ds->x1; diff --git a/src/swrenderer/things/r_visiblesprite.cpp b/src/swrenderer/things/r_visiblesprite.cpp index 2a1d36eebe..a128734ead 100644 --- a/src/swrenderer/things/r_visiblesprite.cpp +++ b/src/swrenderer/things/r_visiblesprite.cpp @@ -62,10 +62,8 @@ namespace swrenderer VisibleSprite *spr = this; - int i; int x1, x2; short topclip, botclip; - short *clip1, *clip2; FSWColormap *colormap = spr->Light.BaseColormap; int colormapnum = spr->Light.ColormapNum; F3DFloor *rover; @@ -108,7 +106,7 @@ namespace swrenderer } sector_t *sec = nullptr; FDynamicColormap *mybasecolormap = nullptr; - for (i = spr->sector->e->XFloor.lightlist.Size() - 1; i >= 0; i--) + for (int i = spr->sector->e->XFloor.lightlist.Size() - 1; i >= 0; i--) { if (clip3d->sclipTop <= spr->sector->e->XFloor.lightlist[i].plane.Zat0()) { @@ -281,14 +279,16 @@ namespace swrenderer return; } - i = x2 - x1; - clip1 = clipbot + x1; - clip2 = cliptop + x1; - do { - *clip1++ = botclip; - *clip2++ = topclip; - } while (--i); + int i = x2 - x1; + short *clip1 = clipbot + x1; + short *clip2 = cliptop + x1; + do + { + *clip1++ = botclip; + *clip2++ = topclip; + } while (--i); + } // Scan drawsegs from end to start for obscuring segs. // The first drawseg that is closer than the sprite is the clip seg. @@ -338,9 +338,9 @@ namespace swrenderer int r2 = MIN(group.x2, x2); // Clip bottom - clip1 = clipbot + r1; - clip2 = group.sprbottomclip + r1 - group.x1; - i = r2 - r1; + short *clip1 = clipbot + r1; + const short *clip2 = group.sprbottomclip + r1 - group.x1; + int i = r2 - r1; do { if (*clip1 > *clip2) @@ -398,9 +398,9 @@ namespace swrenderer if (ds->silhouette & SIL_BOTTOM) //bottom sil { - clip1 = clipbot + r1; - clip2 = ds->sprbottomclip + r1 - ds->x1; - i = r2 - r1; + short *clip1 = clipbot + r1; + const short *clip2 = ds->sprbottomclip + r1 - ds->x1; + int i = r2 - r1; do { if (*clip1 > *clip2) @@ -412,9 +412,9 @@ namespace swrenderer if (ds->silhouette & SIL_TOP) // top sil { - clip1 = cliptop + r1; - clip2 = ds->sprtopclip + r1 - ds->x1; - i = r2 - r1; + short *clip1 = cliptop + r1; + const short *clip2 = ds->sprtopclip + r1 - ds->x1; + int i = r2 - r1; do { if (*clip1 < *clip2) @@ -438,6 +438,7 @@ namespace swrenderer // If it is completely clipped away, don't bother drawing it. if (cliptop[x2] >= clipbot[x2]) { + int i; for (i = x1; i < x2; ++i) { if (cliptop[i] < clipbot[i]) From 7cb4deabdddc878fdab5fd449564034d6a764ba2 Mon Sep 17 00:00:00 2001 From: Magnus Norddahl Date: Thu, 8 Mar 2018 01:28:23 +0100 Subject: [PATCH 02/89] - get rid of FAKE3D_REFRESHCLIP and fix holes in 3d floors with wrapped midtextures --- src/swrenderer/line/r_line.cpp | 2 +- src/swrenderer/line/r_renderdrawsegment.cpp | 21 +++++---------------- src/swrenderer/line/r_renderdrawsegment.h | 2 +- src/swrenderer/scene/r_3dfloors.h | 1 - src/swrenderer/scene/r_translucent_pass.cpp | 13 +++++++------ src/swrenderer/segments/r_drawsegment.h | 1 + 6 files changed, 15 insertions(+), 25 deletions(-) diff --git a/src/swrenderer/line/r_line.cpp b/src/swrenderer/line/r_line.cpp index 3f663defdd..1f68727b11 100644 --- a/src/swrenderer/line/r_line.cpp +++ b/src/swrenderer/line/r_line.cpp @@ -1055,7 +1055,7 @@ namespace swrenderer Clip3DFloors *clip3d = Thread->Clip3D.get(); // kg3D - fake planes clipping - if (clip3d->fake3D & FAKE3D_REFRESHCLIP) + if (clip3d->fake3D & FAKE3D_FAKEBACK) { auto ceilingclip = Thread->OpaquePass->ceilingclip; auto floorclip = Thread->OpaquePass->floorclip; diff --git a/src/swrenderer/line/r_renderdrawsegment.cpp b/src/swrenderer/line/r_renderdrawsegment.cpp index 3550b7356b..e00b08f5f3 100644 --- a/src/swrenderer/line/r_renderdrawsegment.cpp +++ b/src/swrenderer/line/r_renderdrawsegment.cpp @@ -123,8 +123,6 @@ namespace swrenderer } } - bool wrap = (curline->linedef->flags & ML_WRAP_MIDTEX) || (curline->sidedef->Flags & WALLF_WRAP_MIDTEX); - // [RH] Draw fog partition bool renderwall = true; bool notrelevant = false; @@ -145,7 +143,7 @@ namespace swrenderer } if (renderwall) - notrelevant = RenderWall(ds, x1, x2, walldrawerargs, columndrawerargs, visible, basecolormap, wallshade, wrap); + notrelevant = RenderWall(ds, x1, x2, walldrawerargs, columndrawerargs, visible, basecolormap, wallshade); if (ds->Has3DFloorFrontSectorWalls() || ds->Has3DFloorBackSectorWalls()) { @@ -153,22 +151,12 @@ namespace swrenderer } if (!notrelevant) { - if (clip3d->fake3D & FAKE3D_REFRESHCLIP) - { - if (!wrap) - { - assert(ds->bkup != nullptr); - memcpy(ds->sprtopclip, ds->bkup, (ds->x2 - ds->x1) * 2); - } - } - else - { - fillshort(ds->sprtopclip - ds->x1 + x1, x2 - x1, viewheight); - } + ds->sprclipped = true; + fillshort(ds->sprtopclip - ds->x1 + x1, x2 - x1, viewheight); } } - bool RenderDrawSegment::RenderWall(DrawSegment *ds, int x1, int x2, WallDrawerArgs &walldrawerargs, SpriteDrawerArgs &columndrawerargs, bool visible, FDynamicColormap *basecolormap, int wallshade, bool wrap) + bool RenderDrawSegment::RenderWall(DrawSegment *ds, int x1, int x2, WallDrawerArgs &walldrawerargs, SpriteDrawerArgs &columndrawerargs, bool visible, FDynamicColormap *basecolormap, int wallshade) { auto viewport = Thread->Viewport.get(); Clip3DFloors *clip3d = Thread->Clip3D.get(); @@ -220,6 +208,7 @@ namespace swrenderer double rowoffset = curline->sidedef->GetTextureYOffset(side_t::mid); + bool wrap = (curline->linedef->flags & ML_WRAP_MIDTEX) || (curline->sidedef->Flags & WALLF_WRAP_MIDTEX); if (!wrap) { // Texture does not wrap vertically. double textop; diff --git a/src/swrenderer/line/r_renderdrawsegment.h b/src/swrenderer/line/r_renderdrawsegment.h index 42a5ac5bc6..05a4b68c07 100644 --- a/src/swrenderer/line/r_renderdrawsegment.h +++ b/src/swrenderer/line/r_renderdrawsegment.h @@ -37,7 +37,7 @@ namespace swrenderer RenderThread *Thread = nullptr; private: - bool RenderWall(DrawSegment *ds, int x1, int x2, WallDrawerArgs &walldrawerargs, SpriteDrawerArgs &columndrawerargs, bool visible, FDynamicColormap *basecolormap, int wallshade, bool wrap); + bool RenderWall(DrawSegment *ds, int x1, int x2, WallDrawerArgs &walldrawerargs, SpriteDrawerArgs &columndrawerargs, bool visible, FDynamicColormap *basecolormap, int wallshade); void ClipMidtex(int x1, int x2); void RenderFakeWall(DrawSegment *ds, int x1, int x2, F3DFloor *rover, int wallshade, FDynamicColormap *basecolormap); void RenderFakeWallRange(DrawSegment *ds, int x1, int x2, int wallshade); diff --git a/src/swrenderer/scene/r_3dfloors.h b/src/swrenderer/scene/r_3dfloors.h index d697755b23..e1f52d1669 100644 --- a/src/swrenderer/scene/r_3dfloors.h +++ b/src/swrenderer/scene/r_3dfloors.h @@ -49,7 +49,6 @@ namespace swrenderer // sorting stage: FAKE3D_CLIPBOTTOM = 1, // clip bottom FAKE3D_CLIPTOP = 2, // clip top - FAKE3D_REFRESHCLIP = 4, // refresh clip info FAKE3D_DOWN2UP = 8, // rendering from down to up (floors) }; diff --git a/src/swrenderer/scene/r_translucent_pass.cpp b/src/swrenderer/scene/r_translucent_pass.cpp index e08486ef94..76677a6a0a 100644 --- a/src/swrenderer/scene/r_translucent_pass.cpp +++ b/src/swrenderer/scene/r_translucent_pass.cpp @@ -149,11 +149,6 @@ namespace swrenderer // render any remaining masked mid textures - if (renew) - { - Thread->Clip3D->fake3D |= FAKE3D_REFRESHCLIP; - } - for (unsigned int index = 0; index != drawseglist->SegmentsCount(); index++) { DrawSegment *ds = drawseglist->Segment(index); @@ -161,12 +156,18 @@ namespace swrenderer // [ZZ] the same as above if (ds->CurrentPortalUniq != renderportal->CurrentPortalUniq) continue; - if (ds->maskedtexturecol != nullptr || ds->bFogBoundary) + if (ds->maskedtexturecol || ds->bFogBoundary) { RenderDrawSegment renderer(Thread); renderer.Render(ds, ds->x1, ds->x2); if (renew && ds->bFogBoundary) // don't draw fogboundary again ds->bFogBoundary = false; + + if (renew && ds->sprclipped) + { + memcpy(ds->sprtopclip, ds->bkup, (ds->x2 - ds->x1) * sizeof(short)); + ds->sprclipped = false; + } } } } diff --git a/src/swrenderer/segments/r_drawsegment.h b/src/swrenderer/segments/r_drawsegment.h index c29b3a67a2..4e2943ab0f 100644 --- a/src/swrenderer/segments/r_drawsegment.h +++ b/src/swrenderer/segments/r_drawsegment.h @@ -47,6 +47,7 @@ namespace swrenderer fixed_t *maskedtexturecol = nullptr; float *swall = nullptr; short *bkup = nullptr; // sprtopclip backup, for mid and fake textures + bool sprclipped = false; // True if draw segment was used for clipping sprites FWallTmapVals tmapvals; From 71623198d271ec19fa91fa4d95a47c3d7ee58e0c Mon Sep 17 00:00:00 2001 From: Magnus Norddahl Date: Thu, 8 Mar 2018 04:05:35 +0100 Subject: [PATCH 03/89] - remove fake3D with structs and localize their usage instead of sharing global state --- src/swrenderer/line/r_farclip_line.cpp | 7 +- src/swrenderer/line/r_farclip_line.h | 3 +- src/swrenderer/line/r_line.cpp | 31 ++++---- src/swrenderer/line/r_line.h | 4 +- src/swrenderer/line/r_renderdrawsegment.cpp | 83 +++++++++++---------- src/swrenderer/line/r_renderdrawsegment.h | 3 +- src/swrenderer/plane/r_visibleplanelist.cpp | 5 +- src/swrenderer/plane/r_visibleplanelist.h | 2 +- src/swrenderer/scene/r_3dfloors.cpp | 1 - src/swrenderer/scene/r_3dfloors.h | 41 +++++----- src/swrenderer/scene/r_opaque_pass.cpp | 41 +++++----- src/swrenderer/scene/r_opaque_pass.h | 2 +- src/swrenderer/scene/r_translucent_pass.cpp | 46 +++++++----- src/swrenderer/scene/r_translucent_pass.h | 2 +- src/swrenderer/things/r_model.cpp | 2 +- src/swrenderer/things/r_model.h | 2 +- src/swrenderer/things/r_particle.cpp | 8 +- src/swrenderer/things/r_particle.h | 4 +- src/swrenderer/things/r_sprite.cpp | 2 +- src/swrenderer/things/r_sprite.h | 2 +- src/swrenderer/things/r_visiblesprite.cpp | 44 +++++------ src/swrenderer/things/r_visiblesprite.h | 4 +- src/swrenderer/things/r_voxel.cpp | 2 +- src/swrenderer/things/r_voxel.h | 2 +- src/swrenderer/things/r_wallsprite.cpp | 2 +- src/swrenderer/things/r_wallsprite.h | 2 +- 26 files changed, 185 insertions(+), 162 deletions(-) diff --git a/src/swrenderer/line/r_farclip_line.cpp b/src/swrenderer/line/r_farclip_line.cpp index f000744c25..5b55e654f4 100644 --- a/src/swrenderer/line/r_farclip_line.cpp +++ b/src/swrenderer/line/r_farclip_line.cpp @@ -65,13 +65,14 @@ namespace swrenderer Thread = thread; } - void FarClipLine::Render(seg_t *line, subsector_t *subsector, VisiblePlane *linefloorplane, VisiblePlane *lineceilingplane) + void FarClipLine::Render(seg_t *line, subsector_t *subsector, VisiblePlane *linefloorplane, VisiblePlane *lineceilingplane, Fake3DOpaque opaque3dfloor) { mSubsector = subsector; mFrontSector = mSubsector->sector; mLineSegment = line; mFloorPlane = linefloorplane; mCeilingPlane = lineceilingplane; + m3DFloor = opaque3dfloor; DVector2 pt1 = line->v1->fPos() - Thread->Viewport->viewpoint.Pos; DVector2 pt2 = line->v2->fPos() - Thread->Viewport->viewpoint.Pos; @@ -153,7 +154,7 @@ namespace swrenderer for (int x = x1; x < x2; ++x) { - short top = (clip3d->fakeFloor && clip3d->fake3D & FAKE3D_FAKECEILING) ? clip3d->fakeFloor->ceilingclip[x] : ceilingclip[x]; + short top = (clip3d->fakeFloor && m3DFloor.type == Fake3DOpaque::FakeCeiling) ? clip3d->fakeFloor->ceilingclip[x] : ceilingclip[x]; short bottom = MIN(walltop.ScreenY[x], floorclip[x]); if (top < bottom) { @@ -177,7 +178,7 @@ namespace swrenderer for (int x = x1; x < x2; ++x) { short top = MAX(wallbottom.ScreenY[x], ceilingclip[x]); - short bottom = (clip3d->fakeFloor && clip3d->fake3D & FAKE3D_FAKEFLOOR) ? clip3d->fakeFloor->floorclip[x] : floorclip[x]; + short bottom = (clip3d->fakeFloor && m3DFloor.type == Fake3DOpaque::FakeFloor) ? clip3d->fakeFloor->floorclip[x] : floorclip[x]; if (top < bottom) { assert(bottom <= viewheight); diff --git a/src/swrenderer/line/r_farclip_line.h b/src/swrenderer/line/r_farclip_line.h index c450a63836..05cba472d2 100644 --- a/src/swrenderer/line/r_farclip_line.h +++ b/src/swrenderer/line/r_farclip_line.h @@ -28,7 +28,7 @@ namespace swrenderer { public: FarClipLine(RenderThread *thread); - void Render(seg_t *line, subsector_t *subsector, VisiblePlane *linefloorplane, VisiblePlane *lineceilingplane); + void Render(seg_t *line, subsector_t *subsector, VisiblePlane *linefloorplane, VisiblePlane *lineceilingplane, Fake3DOpaque opaque3dfloor); RenderThread *Thread = nullptr; @@ -44,6 +44,7 @@ namespace swrenderer seg_t *mLineSegment; VisiblePlane *mFloorPlane; VisiblePlane *mCeilingPlane; + Fake3DOpaque m3DFloor; double mFrontCeilingZ1; double mFrontCeilingZ2; diff --git a/src/swrenderer/line/r_line.cpp b/src/swrenderer/line/r_line.cpp index 1f68727b11..b2c1fee72d 100644 --- a/src/swrenderer/line/r_line.cpp +++ b/src/swrenderer/line/r_line.cpp @@ -71,7 +71,7 @@ namespace swrenderer Thread = thread; } - void SWRenderLine::Render(seg_t *line, subsector_t *subsector, sector_t *sector, sector_t *fakebacksector, VisiblePlane *linefloorplane, VisiblePlane *lineceilingplane, bool infog, FDynamicColormap *colormap) + void SWRenderLine::Render(seg_t *line, subsector_t *subsector, sector_t *sector, sector_t *fakebacksector, VisiblePlane *linefloorplane, VisiblePlane *lineceilingplane, bool infog, FDynamicColormap *colormap, Fake3DOpaque opaque3dfloor) { mSubsector = subsector; mFrontSector = sector; @@ -81,6 +81,7 @@ namespace swrenderer foggy = infog; basecolormap = colormap; mLineSegment = line; + m3DFloor = opaque3dfloor; DVector2 pt1 = line->v1->fPos() - Thread->Viewport->viewpoint.Pos; DVector2 pt2 = line->v2->fPos() - Thread->Viewport->viewpoint.Pos; @@ -133,7 +134,7 @@ namespace swrenderer Clip3DFloors *clip3d = Thread->Clip3D.get(); - if (!(clip3d->fake3D & FAKE3D_FAKEBACK)) + if (m3DFloor.type != Fake3DOpaque::FakeBack) { mBackSector = line->backsector; } @@ -141,7 +142,7 @@ namespace swrenderer if (mBackSector) { // kg3D - its fake, no transfer_heights - if (!(clip3d->fake3D & FAKE3D_FAKEBACK)) + if (m3DFloor.type != Fake3DOpaque::FakeBack) { // killough 3/8/98, 4/4/98: hack for invisible ceilings / deep water mBackSector = Thread->OpaquePass->FakeFlat(mBackSector, &tempsec, nullptr, nullptr, mLineSegment, WallC.sx1, WallC.sx2, mFrontCeilingZ1, mFrontCeilingZ2); } @@ -151,15 +152,15 @@ namespace swrenderer mBackCeilingZ2 = mBackSector->ceilingplane.ZatPoint(line->v2); mBackFloorZ2 = mBackSector->floorplane.ZatPoint(line->v2); - if (clip3d->fake3D & FAKE3D_FAKEBACK) + if (m3DFloor.type == Fake3DOpaque::FakeBack) { if (mFrontFloorZ1 >= mBackFloorZ1 && mFrontFloorZ2 >= mBackFloorZ2) { - clip3d->fake3D |= FAKE3D_CLIPBOTFRONT; + m3DFloor.clipBotFront = true; } if (mFrontCeilingZ1 <= mBackCeilingZ1 && mFrontCeilingZ2 <= mBackCeilingZ2) { - clip3d->fake3D |= FAKE3D_CLIPTOPFRONT; + m3DFloor.clipTopFront = true; } } } @@ -325,7 +326,7 @@ namespace swrenderer // 3D floors code abuses the line render code to update plane clipping // lists but doesn't actually draw anything. - bool onlyUpdatePlaneClip = (clip3d->fake3D & FAKE3D_FAKEMASK) ? true : false; + bool onlyUpdatePlaneClip = (m3DFloor.type != Fake3DOpaque::Normal); if (!onlyUpdatePlaneClip) Thread->DrawSegments->Push(draw_segment); @@ -516,9 +517,9 @@ namespace swrenderer MarkFloorPlane(start, stop); Mark3DFloors(start, stop); - if (clip3d->fake3D & FAKE3D_FAKEMASK) + if (m3DFloor.type != Fake3DOpaque::Normal) { - return (clip3d->fake3D & FAKE3D_FAKEMASK) == 0; + return false; } MarkOpaquePassClip(start, stop); @@ -557,7 +558,7 @@ namespace swrenderer Thread->Portal->AddLinePortal(mLineSegment->linedef, draw_segment->x1, draw_segment->x2, draw_segment->sprtopclip, draw_segment->sprbottomclip); } - return (clip3d->fake3D & FAKE3D_FAKEMASK) == 0; + return m3DFloor.type == Fake3DOpaque::Normal; } bool SWRenderLine::ShouldMarkFloor() const @@ -1015,7 +1016,7 @@ namespace swrenderer for (int x = x1; x < x2; ++x) { - short top = (clip3d->fakeFloor && clip3d->fake3D & FAKE3D_FAKECEILING) ? clip3d->fakeFloor->ceilingclip[x] : ceilingclip[x]; + short top = (clip3d->fakeFloor && m3DFloor.type == Fake3DOpaque::FakeCeiling) ? clip3d->fakeFloor->ceilingclip[x] : ceilingclip[x]; short bottom = MIN(walltop.ScreenY[x], floorclip[x]); if (top < bottom) { @@ -1039,7 +1040,7 @@ namespace swrenderer for (int x = x1; x < x2; ++x) { short top = MAX(wallbottom.ScreenY[x], ceilingclip[x]); - short bottom = (clip3d->fakeFloor && clip3d->fake3D & FAKE3D_FAKEFLOOR) ? clip3d->fakeFloor->floorclip[x] : floorclip[x]; + short bottom = (clip3d->fakeFloor && m3DFloor.type == Fake3DOpaque::FakeFloor) ? clip3d->fakeFloor->floorclip[x] : floorclip[x]; if (top < bottom) { assert(bottom <= viewheight); @@ -1055,12 +1056,12 @@ namespace swrenderer Clip3DFloors *clip3d = Thread->Clip3D.get(); // kg3D - fake planes clipping - if (clip3d->fake3D & FAKE3D_FAKEBACK) + if (m3DFloor.type == Fake3DOpaque::FakeBack) { auto ceilingclip = Thread->OpaquePass->ceilingclip; auto floorclip = Thread->OpaquePass->floorclip; - if (clip3d->fake3D & FAKE3D_CLIPBOTFRONT) + if (m3DFloor.clipBotFront) { memcpy(clip3d->fakeFloor->floorclip + x1, wallbottom.ScreenY + x1, (x2 - x1) * sizeof(short)); } @@ -1072,7 +1073,7 @@ namespace swrenderer } memcpy(clip3d->fakeFloor->floorclip + x1, walllower.ScreenY + x1, (x2 - x1) * sizeof(short)); } - if (clip3d->fake3D & FAKE3D_CLIPTOPFRONT) + if (m3DFloor.clipTopFront) { memcpy(clip3d->fakeFloor->ceilingclip + x1, walltop.ScreenY + x1, (x2 - x1) * sizeof(short)); } diff --git a/src/swrenderer/line/r_line.h b/src/swrenderer/line/r_line.h index 1462410e58..a76f4dc7c4 100644 --- a/src/swrenderer/line/r_line.h +++ b/src/swrenderer/line/r_line.h @@ -25,6 +25,7 @@ #include "vectors.h" #include "r_wallsetup.h" #include "swrenderer/segments/r_clipsegment.h" +#include "swrenderer/scene/r_3dfloors.h" struct seg_t; struct subsector_t; @@ -71,7 +72,7 @@ namespace swrenderer { public: SWRenderLine(RenderThread *thread); - void Render(seg_t *line, subsector_t *subsector, sector_t *sector, sector_t *fakebacksector, VisiblePlane *floorplane, VisiblePlane *ceilingplane, bool foggy, FDynamicColormap *basecolormap); + void Render(seg_t *line, subsector_t *subsector, sector_t *sector, sector_t *fakebacksector, VisiblePlane *floorplane, VisiblePlane *ceilingplane, bool foggy, FDynamicColormap *basecolormap, Fake3DOpaque fake3DOpaque); RenderThread *Thread = nullptr; @@ -109,6 +110,7 @@ namespace swrenderer VisiblePlane *mFloorPlane; VisiblePlane *mCeilingPlane; seg_t *mLineSegment; + Fake3DOpaque m3DFloor; double mBackCeilingZ1; double mBackCeilingZ2; diff --git a/src/swrenderer/line/r_renderdrawsegment.cpp b/src/swrenderer/line/r_renderdrawsegment.cpp index e00b08f5f3..df6c8f7a1b 100644 --- a/src/swrenderer/line/r_renderdrawsegment.cpp +++ b/src/swrenderer/line/r_renderdrawsegment.cpp @@ -63,11 +63,12 @@ namespace swrenderer Thread = thread; } - void RenderDrawSegment::Render(DrawSegment *ds, int x1, int x2) + void RenderDrawSegment::Render(DrawSegment *ds, int x1, int x2, Fake3DTranslucent clip3DFloor) { auto viewport = Thread->Viewport.get(); curline = ds->curline; + m3DFloor = clip3DFloor; float alpha = (float)MIN(curline->linedef->alpha, 1.); bool additive = (curline->linedef->flags & ML_ADDTRANS) != 0; @@ -102,9 +103,9 @@ namespace swrenderer Clip3DFloors *clip3d = Thread->Clip3D.get(); - if (!(clip3d->fake3D & FAKE3D_CLIPTOP)) + if (!(m3DFloor.clipTop)) { - clip3d->sclipTop = sec->ceilingplane.ZatPoint(Thread->Viewport->viewpoint.Pos); + m3DFloor.sclipTop = sec->ceilingplane.ZatPoint(Thread->Viewport->viewpoint.Pos); } CameraLight *cameraLight = CameraLight::Instance(); @@ -112,7 +113,7 @@ namespace swrenderer { for (int i = frontsector->e->XFloor.lightlist.Size() - 1; i >= 0; i--) { - if (clip3d->sclipTop <= frontsector->e->XFloor.lightlist[i].plane.Zat0()) + if (m3DFloor.sclipTop <= frontsector->e->XFloor.lightlist[i].plane.Zat0()) { lightlist_t *lit = &frontsector->e->XFloor.lightlist[i]; basecolormap = GetColorTable(lit->extra_colormap, frontsector->SpecialColors[sector_t::walltop]); @@ -252,11 +253,11 @@ namespace swrenderer return false; } - if ((clip3d->fake3D & FAKE3D_CLIPBOTTOM) && textop < clip3d->sclipBottom - Thread->Viewport->viewpoint.Pos.Z) + if (m3DFloor.clipBottom && textop < m3DFloor.sclipBottom - Thread->Viewport->viewpoint.Pos.Z) { return true; } - if ((clip3d->fake3D & FAKE3D_CLIPTOP) && textop - texheight > clip3d->sclipTop - Thread->Viewport->viewpoint.Pos.Z) + if (m3DFloor.clipTop && textop - texheight > m3DFloor.sclipTop - Thread->Viewport->viewpoint.Pos.Z) { return true; } @@ -266,17 +267,17 @@ namespace swrenderer WallC.sx1 = ds->sx1; WallC.sx2 = ds->sx2; - if (clip3d->fake3D & FAKE3D_CLIPTOP) + if (m3DFloor.clipTop) { - wallupper.Project(Thread->Viewport.get(), textop < clip3d->sclipTop - Thread->Viewport->viewpoint.Pos.Z ? textop : clip3d->sclipTop - Thread->Viewport->viewpoint.Pos.Z, &WallC); + wallupper.Project(Thread->Viewport.get(), textop < m3DFloor.sclipTop - Thread->Viewport->viewpoint.Pos.Z ? textop : m3DFloor.sclipTop - Thread->Viewport->viewpoint.Pos.Z, &WallC); } else { wallupper.Project(Thread->Viewport.get(), textop, &WallC); } - if (clip3d->fake3D & FAKE3D_CLIPBOTTOM) + if (m3DFloor.clipBottom) { - walllower.Project(Thread->Viewport.get(), textop - texheight > clip3d->sclipBottom - Thread->Viewport->viewpoint.Pos.Z ? textop - texheight : clip3d->sclipBottom - Thread->Viewport->viewpoint.Pos.Z, &WallC); + walllower.Project(Thread->Viewport.get(), textop - texheight > m3DFloor.sclipBottom - Thread->Viewport->viewpoint.Pos.Z ? textop - texheight : m3DFloor.sclipBottom - Thread->Viewport->viewpoint.Pos.Z, &WallC); } else { @@ -366,9 +367,9 @@ namespace swrenderer } } - if (clip3d->fake3D & FAKE3D_CLIPTOP) + if (m3DFloor.clipTop) { - wallupper.Project(Thread->Viewport.get(), clip3d->sclipTop - Thread->Viewport->viewpoint.Pos.Z, &WallC); + wallupper.Project(Thread->Viewport.get(), m3DFloor.sclipTop - Thread->Viewport->viewpoint.Pos.Z, &WallC); for (int i = x1; i < x2; i++) { if (wallupper.ScreenY[i] < mceilingclip[i]) @@ -376,9 +377,9 @@ namespace swrenderer } mceilingclip = wallupper.ScreenY; } - if (clip3d->fake3D & FAKE3D_CLIPBOTTOM) + if (m3DFloor.clipBottom) { - walllower.Project(Thread->Viewport.get(), clip3d->sclipBottom - Thread->Viewport->viewpoint.Pos.Z, &WallC); + walllower.Project(Thread->Viewport.get(), m3DFloor.sclipBottom - Thread->Viewport->viewpoint.Pos.Z, &WallC); for (int i = x1; i < x2; i++) { if (walllower.ScreenY[i] > mfloorclip[i]) @@ -484,8 +485,8 @@ namespace swrenderer WallT = ds->tmapvals; Clip3DFloors *clip3d = Thread->Clip3D.get(); - wallupper.Project(Thread->Viewport.get(), clip3d->sclipTop - Thread->Viewport->viewpoint.Pos.Z, &WallC); - walllower.Project(Thread->Viewport.get(), clip3d->sclipBottom - Thread->Viewport->viewpoint.Pos.Z, &WallC); + wallupper.Project(Thread->Viewport.get(), m3DFloor.sclipTop - Thread->Viewport->viewpoint.Pos.Z, &WallC); + walllower.Project(Thread->Viewport.get(), m3DFloor.sclipBottom - Thread->Viewport->viewpoint.Pos.Z, &WallC); for (i = x1; i < x2; i++) { @@ -542,14 +543,14 @@ namespace swrenderer Clip3DFloors *clip3d = Thread->Clip3D.get(); // maybe fix clipheights - if (!(clip3d->fake3D & FAKE3D_CLIPBOTTOM)) clip3d->sclipBottom = floorHeight; - if (!(clip3d->fake3D & FAKE3D_CLIPTOP)) clip3d->sclipTop = ceilingHeight; + if (!m3DFloor.clipBottom) m3DFloor.sclipBottom = floorHeight; + if (!m3DFloor.clipTop) m3DFloor.sclipTop = ceilingHeight; // maybe not visible - if (clip3d->sclipBottom >= frontsector->CenterCeiling()) return; - if (clip3d->sclipTop <= frontsector->CenterFloor()) return; + if (m3DFloor.sclipBottom >= frontsector->CenterCeiling()) return; + if (m3DFloor.sclipTop <= frontsector->CenterFloor()) return; - if (clip3d->fake3D & FAKE3D_DOWN2UP) + if (m3DFloor.down2Up) { // bottom to viewz last = 0; for (i = backsector->e->XFloor.ffloors.Size() - 1; i >= 0; i--) @@ -560,7 +561,7 @@ namespace swrenderer // visible? passed = 0; if (!(rover->flags & FF_RENDERSIDES) || rover->top.plane->isSlope() || rover->bottom.plane->isSlope() || - rover->top.plane->Zat0() <= clip3d->sclipBottom || + rover->top.plane->Zat0() <= m3DFloor.sclipBottom || rover->bottom.plane->Zat0() >= ceilingHeight || rover->top.plane->Zat0() <= floorHeight) { @@ -575,7 +576,7 @@ namespace swrenderer } rw_pic = nullptr; - if (rover->bottom.plane->Zat0() >= clip3d->sclipTop || passed) + if (rover->bottom.plane->Zat0() >= m3DFloor.sclipTop || passed) { if (last) { @@ -597,8 +598,8 @@ namespace swrenderer if (fover->top.plane->isSlope() || fover->bottom.plane->isSlope()) continue; // visible? - if (fover->top.plane->Zat0() <= clip3d->sclipBottom) continue; // no - if (fover->bottom.plane->Zat0() >= clip3d->sclipTop) + if (fover->top.plane->Zat0() <= m3DFloor.sclipBottom) continue; // no + if (fover->bottom.plane->Zat0() >= m3DFloor.sclipTop) { // no, last possible fover = nullptr; break; @@ -650,8 +651,8 @@ namespace swrenderer if (fover->top.plane->isSlope() || fover->bottom.plane->isSlope()) continue; // visible? - if (fover->top.plane->Zat0() <= clip3d->sclipBottom) continue; // no - if (fover->bottom.plane->Zat0() >= clip3d->sclipTop) + if (fover->top.plane->Zat0() <= m3DFloor.sclipBottom) continue; // no + if (fover->bottom.plane->Zat0() >= m3DFloor.sclipTop) { // visible, last possible fover = nullptr; break; @@ -702,7 +703,7 @@ namespace swrenderer { for (j = backsector->e->XFloor.lightlist.Size() - 1; j >= 0; j--) { - if (clip3d->sclipTop <= backsector->e->XFloor.lightlist[j].plane.Zat0()) + if (m3DFloor.sclipTop <= backsector->e->XFloor.lightlist[j].plane.Zat0()) { lightlist_t *lit = &backsector->e->XFloor.lightlist[j]; basecolormap = GetColorTable(lit->extra_colormap, frontsector->SpecialColors[sector_t::walltop]); @@ -716,7 +717,7 @@ namespace swrenderer { for (j = frontsector->e->XFloor.lightlist.Size() - 1; j >= 0; j--) { - if (clip3d->sclipTop <= frontsector->e->XFloor.lightlist[j].plane.Zat0()) + if (m3DFloor.sclipTop <= frontsector->e->XFloor.lightlist[j].plane.Zat0()) { lightlist_t *lit = &frontsector->e->XFloor.lightlist[j]; basecolormap = GetColorTable(lit->extra_colormap, frontsector->SpecialColors[sector_t::walltop]); @@ -748,7 +749,7 @@ namespace swrenderer passed = 0; if (!(rover->flags & FF_RENDERSIDES) || rover->top.plane->isSlope() || rover->bottom.plane->isSlope() || - rover->bottom.plane->Zat0() >= clip3d->sclipTop || + rover->bottom.plane->Zat0() >= m3DFloor.sclipTop || rover->top.plane->Zat0() <= floorHeight || rover->bottom.plane->Zat0() >= ceilingHeight) { @@ -762,7 +763,7 @@ namespace swrenderer } } rw_pic = nullptr; - if (rover->top.plane->Zat0() <= clip3d->sclipBottom || passed) + if (rover->top.plane->Zat0() <= m3DFloor.sclipBottom || passed) { // maybe wall from inside rendering? fover = nullptr; for (j = 0; j < (int)frontsector->e->XFloor.ffloors.Size(); j++) @@ -779,8 +780,8 @@ namespace swrenderer if (fover->top.plane->isSlope() || fover->bottom.plane->isSlope()) continue; // visible? - if (fover->bottom.plane->Zat0() >= clip3d->sclipTop) continue; // no - if (fover->top.plane->Zat0() <= clip3d->sclipBottom) + if (fover->bottom.plane->Zat0() >= m3DFloor.sclipTop) continue; // no + if (fover->top.plane->Zat0() <= m3DFloor.sclipBottom) { // no, last possible fover = nullptr; break; @@ -831,8 +832,8 @@ namespace swrenderer if (fover->top.plane->isSlope() || fover->bottom.plane->isSlope()) continue; // visible? - if (fover->bottom.plane->Zat0() >= clip3d->sclipTop) continue; // no - if (fover->top.plane->Zat0() <= clip3d->sclipBottom) + if (fover->bottom.plane->Zat0() >= m3DFloor.sclipTop) continue; // no + if (fover->top.plane->Zat0() <= m3DFloor.sclipBottom) { // visible, last possible fover = nullptr; break; @@ -881,7 +882,7 @@ namespace swrenderer { for (j = backsector->e->XFloor.lightlist.Size() - 1; j >= 0; j--) { - if (clip3d->sclipTop <= backsector->e->XFloor.lightlist[j].plane.Zat0()) + if (m3DFloor.sclipTop <= backsector->e->XFloor.lightlist[j].plane.Zat0()) { lightlist_t *lit = &backsector->e->XFloor.lightlist[j]; basecolormap = GetColorTable(lit->extra_colormap, frontsector->SpecialColors[sector_t::walltop]); @@ -895,7 +896,7 @@ namespace swrenderer { for (j = frontsector->e->XFloor.lightlist.Size() - 1; j >= 0; j--) { - if (clip3d->sclipTop <= frontsector->e->XFloor.lightlist[j].plane.Zat0()) + if (m3DFloor.sclipTop <= frontsector->e->XFloor.lightlist[j].plane.Zat0()) { lightlist_t *lit = &frontsector->e->XFloor.lightlist[j]; basecolormap = GetColorTable(lit->extra_colormap, frontsector->SpecialColors[sector_t::walltop]); @@ -952,13 +953,13 @@ namespace swrenderer bot = MIN(frontfz1, frontfz2); Clip3DFloors *clip3d = Thread->Clip3D.get(); - if (clip3d->fake3D & FAKE3D_CLIPTOP) + if (m3DFloor.clipTop) { - top = MIN(top, clip3d->sclipTop); + top = MIN(top, m3DFloor.sclipTop); } - if (clip3d->fake3D & FAKE3D_CLIPBOTTOM) + if (m3DFloor.clipBottom) { - bot = MAX(bot, clip3d->sclipBottom); + bot = MAX(bot, m3DFloor.sclipBottom); } } } diff --git a/src/swrenderer/line/r_renderdrawsegment.h b/src/swrenderer/line/r_renderdrawsegment.h index 05a4b68c07..f54ff6b1a9 100644 --- a/src/swrenderer/line/r_renderdrawsegment.h +++ b/src/swrenderer/line/r_renderdrawsegment.h @@ -32,7 +32,7 @@ namespace swrenderer { public: RenderDrawSegment(RenderThread *thread); - void Render(DrawSegment *ds, int x1, int x2); + void Render(DrawSegment *ds, int x1, int x2, Fake3DTranslucent clip3DFloor); RenderThread *Thread = nullptr; @@ -47,6 +47,7 @@ namespace swrenderer sector_t *backsector = nullptr; seg_t *curline = nullptr; + Fake3DTranslucent m3DFloor; FWallCoords WallC; FWallTmapVals WallT; diff --git a/src/swrenderer/plane/r_visibleplanelist.cpp b/src/swrenderer/plane/r_visibleplanelist.cpp index 7a4f5a57c9..561930cc27 100644 --- a/src/swrenderer/plane/r_visibleplanelist.cpp +++ b/src/swrenderer/plane/r_visibleplanelist.cpp @@ -99,7 +99,7 @@ namespace swrenderer } } - VisiblePlane *VisiblePlaneList::FindPlane(const secplane_t &height, FTextureID picnum, int lightlevel, double Alpha, bool additive, const FTransform &xxform, int sky, FSectorPortal *portal, FDynamicColormap *basecolormap) + VisiblePlane *VisiblePlaneList::FindPlane(const secplane_t &height, FTextureID picnum, int lightlevel, double Alpha, bool additive, const FTransform &xxform, int sky, FSectorPortal *portal, FDynamicColormap *basecolormap, Fake3DOpaque::Type fakeFloorType, fixed_t fakeAlpha) { secplane_t plane; VisiblePlane *check; @@ -140,8 +140,7 @@ namespace swrenderer // kg3D - hack, store alpha in sky // i know there is ->alpha, but this also allows to identify fake plane // and ->alpha is for stacked sectors - Clip3DFloors *clip3d = Thread->Clip3D.get(); - if (clip3d->fake3D & (FAKE3D_FAKEFLOOR | FAKE3D_FAKECEILING)) sky = 0x80000000 | clip3d->fakeAlpha; + if (fakeFloorType == Fake3DOpaque::FakeFloor || fakeFloorType == Fake3DOpaque::FakeCeiling) sky = 0x80000000 | fakeAlpha; else sky = 0; // not skyflatnum so it can't be a sky portal = nullptr; alpha = OPAQUE; diff --git a/src/swrenderer/plane/r_visibleplanelist.h b/src/swrenderer/plane/r_visibleplanelist.h index c44c860eb7..a49479e6c6 100644 --- a/src/swrenderer/plane/r_visibleplanelist.h +++ b/src/swrenderer/plane/r_visibleplanelist.h @@ -40,7 +40,7 @@ namespace swrenderer void Clear(); void ClearKeepFakePlanes(); - VisiblePlane *FindPlane(const secplane_t &height, FTextureID picnum, int lightlevel, double Alpha, bool additive, const FTransform &xxform, int sky, FSectorPortal *portal, FDynamicColormap *basecolormap); + VisiblePlane *FindPlane(const secplane_t &height, FTextureID picnum, int lightlevel, double Alpha, bool additive, const FTransform &xxform, int sky, FSectorPortal *portal, FDynamicColormap *basecolormap, Fake3DOpaque::Type fakeFloorType, fixed_t fakeAlpha); VisiblePlane *GetRange(VisiblePlane *pl, int start, int stop); bool HasPortalPlanes() const; diff --git a/src/swrenderer/scene/r_3dfloors.cpp b/src/swrenderer/scene/r_3dfloors.cpp index 111cbf5041..d468c9611e 100644 --- a/src/swrenderer/scene/r_3dfloors.cpp +++ b/src/swrenderer/scene/r_3dfloors.cpp @@ -67,7 +67,6 @@ namespace swrenderer FakeFloors.clear(); fakeActive = false; - fake3D = 0; while (CurrentSkybox) { DeleteHeights(); diff --git a/src/swrenderer/scene/r_3dfloors.h b/src/swrenderer/scene/r_3dfloors.h index e1f52d1669..0237ca95eb 100644 --- a/src/swrenderer/scene/r_3dfloors.h +++ b/src/swrenderer/scene/r_3dfloors.h @@ -33,23 +33,33 @@ namespace swrenderer ClipStack *next; }; - enum Fake3DOpaque + // BSP stage + struct Fake3DOpaque { - // BSP stage: - FAKE3D_FAKEFLOOR = 1, // fake floor, mark seg as FAKE - FAKE3D_FAKECEILING = 2, // fake ceiling, mark seg as FAKE - FAKE3D_FAKEBACK = 4, // RenderLine with fake backsector, mark seg as FAKE - FAKE3D_FAKEMASK = 7, - FAKE3D_CLIPBOTFRONT = 8, // use front sector clipping info (bottom) - FAKE3D_CLIPTOPFRONT = 16, // use front sector clipping info (top) + enum Type + { + Normal, // Not a 3D floor + FakeFloor, // fake floor, mark seg as FAKE + FakeCeiling, // fake ceiling, mark seg as FAKE + FakeBack // RenderLine with fake backsector, mark seg as FAKE + }; + Type type = Normal; + + bool clipBotFront = false; // use front sector clipping info (bottom) + bool clipTopFront = false; // use front sector clipping info (top) + + Fake3DOpaque() { } + Fake3DOpaque(Type type) : type(type) { } }; - enum Fake3DTranslucent + // Drawing stage + struct Fake3DTranslucent { - // sorting stage: - FAKE3D_CLIPBOTTOM = 1, // clip bottom - FAKE3D_CLIPTOP = 2, // clip top - FAKE3D_DOWN2UP = 8, // rendering from down to up (floors) + bool clipBottom = false; + bool clipTop = false; + bool down2Up = false; // rendering from down to up (floors) + double sclipBottom = 0; + double sclipTop = 0; }; class FakeFloorClip @@ -81,13 +91,8 @@ namespace swrenderer RenderThread *Thread = nullptr; - int fake3D = 0; - FakeFloorClip *fakeFloor = nullptr; - fixed_t fakeAlpha = 0; bool fakeActive = false; - double sclipBottom = 0; - double sclipTop = 0; HeightLevel *height_top = nullptr; HeightLevel *height_cur = nullptr; int CurrentSkybox = 0; diff --git a/src/swrenderer/scene/r_opaque_pass.cpp b/src/swrenderer/scene/r_opaque_pass.cpp index f18cdc2ec3..4b0c6f1faa 100644 --- a/src/swrenderer/scene/r_opaque_pass.cpp +++ b/src/swrenderer/scene/r_opaque_pass.cpp @@ -450,7 +450,7 @@ namespace swrenderer } // kg3D - add fake segs, never rendered - void RenderOpaquePass::FakeDrawLoop(subsector_t *sub, VisiblePlane *floorplane, VisiblePlane *ceilingplane, bool foggy, FDynamicColormap *basecolormap) + void RenderOpaquePass::FakeDrawLoop(subsector_t *sub, VisiblePlane *floorplane, VisiblePlane *ceilingplane, bool foggy, FDynamicColormap *basecolormap, Fake3DOpaque opaque3dfloor) { int count; seg_t* line; @@ -462,7 +462,7 @@ namespace swrenderer { if ((line->sidedef) && !(line->sidedef->Flags & WALLF_POLYOBJ)) { - renderline.Render(line, InSubsector, frontsector, nullptr, floorplane, ceilingplane, foggy, basecolormap); + renderline.Render(line, InSubsector, frontsector, nullptr, floorplane, ceilingplane, foggy, basecolormap, opaque3dfloor); } line++; } @@ -565,7 +565,9 @@ namespace swrenderer frontsector->planes[sector_t::ceiling].xform, frontsector->sky, portal, - basecolormap + basecolormap, + Fake3DOpaque::Normal, + 0 ) : nullptr; if (ceilingplane) @@ -606,7 +608,9 @@ namespace swrenderer frontsector->planes[sector_t::floor].xform, frontsector->sky, portal, - basecolormap + basecolormap, + Fake3DOpaque::Normal, + 0 ) : nullptr; if (floorplane) @@ -634,7 +638,7 @@ namespace swrenderer if (!(clip3d->fakeFloor->fakeFloor->flags & FF_RENDERPLANES)) continue; if (clip3d->fakeFloor->fakeFloor->alpha == 0) continue; if (clip3d->fakeFloor->fakeFloor->flags & FF_THISINSIDE && clip3d->fakeFloor->fakeFloor->flags & FF_INVERTSECTOR) continue; - clip3d->fakeAlpha = MIN(Scale(clip3d->fakeFloor->fakeFloor->alpha, OPAQUE, 255), OPAQUE); + fixed_t fakeAlpha = MIN(Scale(clip3d->fakeFloor->fakeFloor->alpha, OPAQUE, 255), OPAQUE); if (clip3d->fakeFloor->validcount != validcount) { clip3d->fakeFloor->validcount = validcount; @@ -644,7 +648,6 @@ namespace swrenderer if (fakeHeight < Thread->Viewport->viewpoint.Pos.Z && fakeHeight > frontsector->floorplane.ZatPoint(frontsector->centerspot)) { - clip3d->fake3D = FAKE3D_FAKEFLOOR; tempsec = *clip3d->fakeFloor->fakeFloor->model; tempsec.floorplane = *clip3d->fakeFloor->fakeFloor->top.plane; tempsec.ceilingplane = *clip3d->fakeFloor->fakeFloor->bottom.plane; @@ -672,13 +675,14 @@ namespace swrenderer frontsector->planes[position].xform, frontsector->sky, nullptr, - basecolormap); + basecolormap, + Fake3DOpaque::FakeFloor, + fakeAlpha); if (floorplane) floorplane->AddLights(Thread, frontsector->lighthead); - FakeDrawLoop(sub, floorplane, ceilingplane, foggy, basecolormap); - clip3d->fake3D = 0; + FakeDrawLoop(sub, floorplane, ceilingplane, foggy, basecolormap, Fake3DOpaque::FakeFloor); frontsector = sub->sector; } } @@ -696,7 +700,7 @@ namespace swrenderer if (!(clip3d->fakeFloor->fakeFloor->flags & FF_RENDERPLANES)) continue; if (clip3d->fakeFloor->fakeFloor->alpha == 0) continue; if (!(clip3d->fakeFloor->fakeFloor->flags & FF_THISINSIDE) && (clip3d->fakeFloor->fakeFloor->flags & (FF_SWIMMABLE | FF_INVERTSECTOR)) == (FF_SWIMMABLE | FF_INVERTSECTOR)) continue; - clip3d->fakeAlpha = MIN(Scale(clip3d->fakeFloor->fakeFloor->alpha, OPAQUE, 255), OPAQUE); + fixed_t fakeAlpha = MIN(Scale(clip3d->fakeFloor->fakeFloor->alpha, OPAQUE, 255), OPAQUE); if (clip3d->fakeFloor->validcount != validcount) { @@ -707,7 +711,6 @@ namespace swrenderer if (fakeHeight > Thread->Viewport->viewpoint.Pos.Z && fakeHeight < frontsector->ceilingplane.ZatPoint(frontsector->centerspot)) { - clip3d->fake3D = FAKE3D_FAKECEILING; tempsec = *clip3d->fakeFloor->fakeFloor->model; tempsec.floorplane = *clip3d->fakeFloor->fakeFloor->top.plane; tempsec.ceilingplane = *clip3d->fakeFloor->fakeFloor->bottom.plane; @@ -738,13 +741,14 @@ namespace swrenderer frontsector->planes[position].xform, frontsector->sky, nullptr, - basecolormap); + basecolormap, + Fake3DOpaque::FakeCeiling, + fakeAlpha); if (ceilingplane) ceilingplane->AddLights(Thread, frontsector->lighthead); - FakeDrawLoop(sub, floorplane, ceilingplane, foggy, basecolormap); - clip3d->fake3D = 0; + FakeDrawLoop(sub, floorplane, ceilingplane, foggy, basecolormap, Fake3DOpaque::FakeCeiling); frontsector = sub->sector; } } @@ -787,7 +791,7 @@ namespace swrenderer if (dist1 > line_distance_cull && dist2 > line_distance_cull) { FarClipLine farclip(Thread); - farclip.Render(line, InSubsector, floorplane, ceilingplane); + farclip.Render(line, InSubsector, floorplane, ceilingplane, Fake3DOpaque::Normal); } else if (!outersubsector || line->sidedef == nullptr || !(line->sidedef->Flags & WALLF_POLYOBJ)) { @@ -805,7 +809,7 @@ namespace swrenderer if (!(clip3d->fakeFloor->fakeFloor->flags & FF_EXISTS)) continue; if (!(clip3d->fakeFloor->fakeFloor->flags & FF_RENDERPLANES)) continue; if (!clip3d->fakeFloor->fakeFloor->model) continue; - clip3d->fake3D = FAKE3D_FAKEBACK; + Fake3DOpaque opaque3dfloor = Fake3DOpaque::FakeBack; tempsec = *clip3d->fakeFloor->fakeFloor->model; tempsec.floorplane = *clip3d->fakeFloor->fakeFloor->top.plane; tempsec.ceilingplane = *clip3d->fakeFloor->fakeFloor->bottom.plane; @@ -814,14 +818,13 @@ namespace swrenderer clip3d->fakeFloor->validcount = validcount; clip3d->NewClip(); } - renderline.Render(line, InSubsector, frontsector, &tempsec, floorplane, ceilingplane, foggy, basecolormap); // fake + renderline.Render(line, InSubsector, frontsector, &tempsec, floorplane, ceilingplane, foggy, basecolormap, opaque3dfloor); // fake } clip3d->fakeFloor = nullptr; - clip3d->fake3D = 0; floorplane = backupfp; ceilingplane = backupcp; } - renderline.Render(line, InSubsector, frontsector, nullptr, floorplane, ceilingplane, foggy, basecolormap); // now real + renderline.Render(line, InSubsector, frontsector, nullptr, floorplane, ceilingplane, foggy, basecolormap, Fake3DOpaque::Normal); // now real } line++; } diff --git a/src/swrenderer/scene/r_opaque_pass.h b/src/swrenderer/scene/r_opaque_pass.h index c71dd3985f..e17a6109a1 100644 --- a/src/swrenderer/scene/r_opaque_pass.h +++ b/src/swrenderer/scene/r_opaque_pass.h @@ -82,7 +82,7 @@ namespace swrenderer bool CheckBBox(float *bspcoord); void AddPolyobjs(subsector_t *sub); - void FakeDrawLoop(subsector_t *sub, VisiblePlane *floorplane, VisiblePlane *ceilingplane, bool foggy, FDynamicColormap *basecolormap); + void FakeDrawLoop(subsector_t *sub, VisiblePlane *floorplane, VisiblePlane *ceilingplane, bool foggy, FDynamicColormap *basecolormap, Fake3DOpaque opaque3dfloor); void AddSprites(sector_t *sec, int lightlevel, WaterFakeSide fakeside, bool foggy, FDynamicColormap *basecolormap); diff --git a/src/swrenderer/scene/r_translucent_pass.cpp b/src/swrenderer/scene/r_translucent_pass.cpp index 76677a6a0a..d56fde2fd6 100644 --- a/src/swrenderer/scene/r_translucent_pass.cpp +++ b/src/swrenderer/scene/r_translucent_pass.cpp @@ -131,7 +131,7 @@ namespace swrenderer return false; } - void RenderTranslucentPass::DrawMaskedSingle(bool renew) + void RenderTranslucentPass::DrawMaskedSingle(bool renew, Fake3DTranslucent clip3DFloor) { RenderPortal *renderportal = Thread->Portal.get(); DrawSegmentList *drawseglist = Thread->DrawSegments.get(); @@ -143,7 +143,7 @@ namespace swrenderer if (sprite->IsCurrentPortalUniq(renderportal->CurrentPortalUniq)) { - sprite->Render(Thread); + sprite->Render(Thread, clip3DFloor); } } @@ -159,7 +159,7 @@ namespace swrenderer if (ds->maskedtexturecol || ds->bFogBoundary) { RenderDrawSegment renderer(Thread); - renderer.Render(ds, ds->x1, ds->x2); + renderer.Render(ds, ds->x1, ds->x2, clip3DFloor); if (renew && ds->bFogBoundary) // don't draw fogboundary again ds->bFogBoundary = false; @@ -184,48 +184,58 @@ namespace swrenderer Clip3DFloors *clip3d = Thread->Clip3D.get(); if (clip3d->height_top == nullptr) { // kg3D - no visible 3D floors, normal rendering - DrawMaskedSingle(false); + Fake3DTranslucent clip3DFloor; + DrawMaskedSingle(false, clip3DFloor); } else { // kg3D - correct sorting // ceilings for (HeightLevel *hl = clip3d->height_cur; hl != nullptr && hl->height >= Thread->Viewport->viewpoint.Pos.Z; hl = hl->prev) { + Fake3DTranslucent clip3DFloor; if (hl->next) { - clip3d->fake3D = FAKE3D_CLIPBOTTOM | FAKE3D_CLIPTOP; - clip3d->sclipTop = hl->next->height; + clip3DFloor.clipBottom = true; + clip3DFloor.clipTop = true; + clip3DFloor.sclipTop = hl->next->height; } else { - clip3d->fake3D = FAKE3D_CLIPBOTTOM; + clip3DFloor.clipBottom = true; } - clip3d->sclipBottom = hl->height; - DrawMaskedSingle(true); + clip3DFloor.sclipBottom = hl->height; + DrawMaskedSingle(true, clip3DFloor); Thread->PlaneList->RenderHeight(hl->height); } // floors - clip3d->fake3D = FAKE3D_DOWN2UP | FAKE3D_CLIPTOP; - clip3d->sclipTop = clip3d->height_top->height; - DrawMaskedSingle(true); + { + Fake3DTranslucent clip3DFloor; + clip3DFloor.clipTop = true; + clip3DFloor.down2Up = true; + clip3DFloor.sclipTop = clip3d->height_top->height; + DrawMaskedSingle(true, clip3DFloor); + } + for (HeightLevel *hl = clip3d->height_top; hl != nullptr && hl->height < Thread->Viewport->viewpoint.Pos.Z; hl = hl->next) { Thread->PlaneList->RenderHeight(hl->height); + Fake3DTranslucent clip3DFloor; if (hl->next) { - clip3d->fake3D = FAKE3D_DOWN2UP | FAKE3D_CLIPTOP | FAKE3D_CLIPBOTTOM; - clip3d->sclipTop = hl->next->height; + clip3DFloor.clipBottom = true; + clip3DFloor.clipTop = true; + clip3DFloor.down2Up = true; + clip3DFloor.sclipTop = hl->next->height; } else { - clip3d->fake3D = FAKE3D_DOWN2UP | FAKE3D_CLIPBOTTOM; + clip3DFloor.clipBottom = true; } - clip3d->sclipBottom = hl->height; - DrawMaskedSingle(true); + clip3DFloor.sclipBottom = hl->height; + DrawMaskedSingle(true, clip3DFloor); } clip3d->DeleteHeights(); - clip3d->fake3D = 0; } if (Thread->MainThread) diff --git a/src/swrenderer/scene/r_translucent_pass.h b/src/swrenderer/scene/r_translucent_pass.h index 47da285b54..5c28749a72 100644 --- a/src/swrenderer/scene/r_translucent_pass.h +++ b/src/swrenderer/scene/r_translucent_pass.h @@ -49,7 +49,7 @@ namespace swrenderer private: void CollectPortals(); - void DrawMaskedSingle(bool renew); + void DrawMaskedSingle(bool renew, Fake3DTranslucent clip3DFloor); TArray portaldrawsegs; }; diff --git a/src/swrenderer/things/r_model.cpp b/src/swrenderer/things/r_model.cpp index f86a7e3849..4b68db2194 100644 --- a/src/swrenderer/things/r_model.cpp +++ b/src/swrenderer/things/r_model.cpp @@ -64,7 +64,7 @@ namespace swrenderer this->idepth = idepth; } - void RenderModel::Render(RenderThread *thread, short *cliptop, short *clipbottom, int minZ, int maxZ) + void RenderModel::Render(RenderThread *thread, short *cliptop, short *clipbottom, int minZ, int maxZ, Fake3DTranslucent clip3DFloor) { SWModelRenderer renderer(thread); renderer.RenderModel(x, y, z, smf, actor); diff --git a/src/swrenderer/things/r_model.h b/src/swrenderer/things/r_model.h index 94ca1d9097..3f6fd0e906 100644 --- a/src/swrenderer/things/r_model.h +++ b/src/swrenderer/things/r_model.h @@ -40,7 +40,7 @@ namespace swrenderer static void Project(RenderThread *thread, float x, float y, float z, FSpriteModelFrame *smf, AActor *actor); protected: - void Render(RenderThread *thread, short *cliptop, short *clipbottom, int minZ, int maxZ) override; + void Render(RenderThread *thread, short *cliptop, short *clipbottom, int minZ, int maxZ, Fake3DTranslucent clip3DFloor) override; bool IsModel() const override { return true; } private: diff --git a/src/swrenderer/things/r_particle.cpp b/src/swrenderer/things/r_particle.cpp index ee791b56b3..0e167f7c4c 100644 --- a/src/swrenderer/things/r_particle.cpp +++ b/src/swrenderer/things/r_particle.cpp @@ -225,7 +225,7 @@ namespace swrenderer thread->SpriteList->Push(vis); } - void RenderParticle::Render(RenderThread *thread, short *cliptop, short *clipbottom, int minZ, int maxZ) + void RenderParticle::Render(RenderThread *thread, short *cliptop, short *clipbottom, int minZ, int maxZ, Fake3DTranslucent clip3DFloor) { auto vis = this; @@ -239,7 +239,7 @@ namespace swrenderer if (ycount <= 0 || countbase <= 0) return; - DrawMaskedSegsBehindParticle(thread); + DrawMaskedSegsBehindParticle(thread, clip3DFloor); uint32_t fg = LightBgra::shade_pal_index_simple(color, LightBgra::calc_light_multiplier(LIGHTSCALE(0, vis->Light.ColormapNum << FRACBITS))); @@ -278,7 +278,7 @@ namespace swrenderer } } - void RenderParticle::DrawMaskedSegsBehindParticle(RenderThread *thread) + void RenderParticle::DrawMaskedSegsBehindParticle(RenderThread *thread, const Fake3DTranslucent &clip3DFloor) { // Draw any masked textures behind this particle so that when the // particle is drawn, it will be in front of them. @@ -297,7 +297,7 @@ namespace swrenderer if (ds->CurrentPortalUniq == CurrentPortalUniq) { RenderDrawSegment renderer(thread); - renderer.Render(ds, MAX(ds->x1, x1), MIN(ds->x2, x2)); + renderer.Render(ds, MAX(ds->x1, x1), MIN(ds->x2, x2), clip3DFloor); } } } diff --git a/src/swrenderer/things/r_particle.h b/src/swrenderer/things/r_particle.h index 84bd10aae3..79d10b7c5f 100644 --- a/src/swrenderer/things/r_particle.h +++ b/src/swrenderer/things/r_particle.h @@ -14,10 +14,10 @@ namespace swrenderer protected: bool IsParticle() const override { return true; } - void Render(RenderThread *thread, short *cliptop, short *clipbottom, int minZ, int maxZ) override; + void Render(RenderThread *thread, short *cliptop, short *clipbottom, int minZ, int maxZ, Fake3DTranslucent clip3DFloor) override; private: - void DrawMaskedSegsBehindParticle(RenderThread *thread); + void DrawMaskedSegsBehindParticle(RenderThread *thread, const Fake3DTranslucent &clip3DFloor); fixed_t xscale = 0; fixed_t startfrac = 0; // horizontal position of x1 diff --git a/src/swrenderer/things/r_sprite.cpp b/src/swrenderer/things/r_sprite.cpp index b9ed668bc4..74a76a79f8 100644 --- a/src/swrenderer/things/r_sprite.cpp +++ b/src/swrenderer/things/r_sprite.cpp @@ -303,7 +303,7 @@ namespace swrenderer thread->SpriteList->Push(vis); } - void RenderSprite::Render(RenderThread *thread, short *mfloorclip, short *mceilingclip, int, int) + void RenderSprite::Render(RenderThread *thread, short *mfloorclip, short *mceilingclip, int, int, Fake3DTranslucent) { auto vis = this; diff --git a/src/swrenderer/things/r_sprite.h b/src/swrenderer/things/r_sprite.h index 55d504fc9a..8fe53080ec 100644 --- a/src/swrenderer/things/r_sprite.h +++ b/src/swrenderer/things/r_sprite.h @@ -10,7 +10,7 @@ namespace swrenderer static void Project(RenderThread *thread, AActor *thing, const DVector3 &pos, FTexture *tex, const DVector2 &spriteScale, int renderflags, WaterFakeSide fakeside, F3DFloor *fakefloor, F3DFloor *fakeceiling, sector_t *current_sector, int spriteshade, bool foggy, FDynamicColormap *basecolormap); protected: - void Render(RenderThread *thread, short *cliptop, short *clipbottom, int minZ, int maxZ) override; + void Render(RenderThread *thread, short *cliptop, short *clipbottom, int minZ, int maxZ, Fake3DTranslucent clip3DFloor) override; private: fixed_t xscale = 0; diff --git a/src/swrenderer/things/r_visiblesprite.cpp b/src/swrenderer/things/r_visiblesprite.cpp index a128734ead..5753d2e483 100644 --- a/src/swrenderer/things/r_visiblesprite.cpp +++ b/src/swrenderer/things/r_visiblesprite.cpp @@ -49,11 +49,11 @@ EXTERN_CVAR(Bool, r_fullbrightignoresectorcolor); namespace swrenderer { - void VisibleSprite::Render(RenderThread *thread) + void VisibleSprite::Render(RenderThread *thread, Fake3DTranslucent clip3DFloor) { if (IsModel()) { - Render(thread, nullptr, nullptr, 0, 0); + Render(thread, nullptr, nullptr, 0, 0, clip3DFloor); return; } @@ -74,10 +74,10 @@ namespace swrenderer if (spr->IsParticle()) { // kg3D - reject invisible parts - if ((clip3d->fake3D & FAKE3D_CLIPBOTTOM) && spr->gpos.Z <= clip3d->sclipBottom) return; - if ((clip3d->fake3D & FAKE3D_CLIPTOP) && spr->gpos.Z >= clip3d->sclipTop) return; + if (clip3DFloor.clipBottom && spr->gpos.Z <= clip3DFloor.sclipBottom) return; + if (clip3DFloor.clipTop && spr->gpos.Z >= clip3DFloor.sclipTop) return; - spr->Render(thread, nullptr, nullptr, 0, 0); + spr->Render(thread, nullptr, nullptr, 0, 0, clip3DFloor); return; } @@ -93,27 +93,27 @@ namespace swrenderer return; // kg3D - reject invisible parts - if ((clip3d->fake3D & FAKE3D_CLIPBOTTOM) && spr->gzt <= clip3d->sclipBottom) return; - if ((clip3d->fake3D & FAKE3D_CLIPTOP) && spr->gzb >= clip3d->sclipTop) return; + if (clip3DFloor.clipBottom && spr->gzt <= clip3DFloor.sclipBottom) return; + if (clip3DFloor.clipTop && spr->gzb >= clip3DFloor.sclipTop) return; // kg3D - correct colors now CameraLight *cameraLight = CameraLight::Instance(); if (!cameraLight->FixedColormap() && cameraLight->FixedLightLevel() < 0 && spr->sector->e && spr->sector->e->XFloor.lightlist.Size()) { - if (!(clip3d->fake3D & FAKE3D_CLIPTOP)) + if (!clip3DFloor.clipTop) { - clip3d->sclipTop = spr->sector->ceilingplane.ZatPoint(thread->Viewport->viewpoint.Pos); + clip3DFloor.sclipTop = spr->sector->ceilingplane.ZatPoint(thread->Viewport->viewpoint.Pos); } sector_t *sec = nullptr; FDynamicColormap *mybasecolormap = nullptr; for (int i = spr->sector->e->XFloor.lightlist.Size() - 1; i >= 0; i--) { - if (clip3d->sclipTop <= spr->sector->e->XFloor.lightlist[i].plane.Zat0()) + if (clip3DFloor.sclipTop <= spr->sector->e->XFloor.lightlist[i].plane.Zat0()) { rover = spr->sector->e->XFloor.lightlist[i].caster; if (rover) { - if (rover->flags & FF_DOUBLESHADOW && clip3d->sclipTop <= rover->bottom.plane->Zat0()) + if (rover->flags & FF_DOUBLESHADOW && clip3DFloor.sclipTop <= rover->bottom.plane->Zat0()) { break; } @@ -229,15 +229,15 @@ namespace swrenderer } } - if (clip3d->fake3D & FAKE3D_CLIPBOTTOM) + if (clip3DFloor.clipBottom) { if (!spr->IsVoxel()) { - double hz = clip3d->sclipBottom; + double hz = clip3DFloor.sclipBottom; if (spr->fakefloor) { double floorz = spr->fakefloor->top.plane->Zat0(); - if (viewport->viewpoint.Pos.Z > floorz && floorz == clip3d->sclipBottom) + if (viewport->viewpoint.Pos.Z > floorz && floorz == clip3DFloor.sclipBottom) { hz = spr->fakefloor->bottom.plane->Zat0(); } @@ -248,17 +248,17 @@ namespace swrenderer botclip = MAX(0, h); } } - hzb = MAX(hzb, clip3d->sclipBottom); + hzb = MAX(hzb, clip3DFloor.sclipBottom); } - if (clip3d->fake3D & FAKE3D_CLIPTOP) + if (clip3DFloor.clipTop) { if (!spr->IsVoxel()) { - double hz = clip3d->sclipTop; + double hz = clip3DFloor.sclipTop; if (spr->fakeceiling != nullptr) { double ceilingZ = spr->fakeceiling->bottom.plane->Zat0(); - if (viewport->viewpoint.Pos.Z < ceilingZ && ceilingZ == clip3d->sclipTop) + if (viewport->viewpoint.Pos.Z < ceilingZ && ceilingZ == clip3DFloor.sclipTop) { hz = spr->fakeceiling->top.plane->Zat0(); } @@ -269,7 +269,7 @@ namespace swrenderer topclip = short(MIN(h, viewheight)); } } - hzt = MIN(hzt, clip3d->sclipTop); + hzt = MIN(hzt, clip3DFloor.sclipTop); } if (topclip >= botclip) @@ -320,7 +320,7 @@ namespace swrenderer int r2 = MIN(ds->x2, x2); RenderDrawSegment renderer(thread); - renderer.Render(ds, r1, r2); + renderer.Render(ds, r1, r2, clip3DFloor); } } } @@ -431,7 +431,7 @@ namespace swrenderer if (!spr->IsVoxel()) { - spr->Render(thread, clipbot, cliptop, 0, 0); + spr->Render(thread, clipbot, cliptop, 0, 0, clip3DFloor); } else { @@ -465,7 +465,7 @@ namespace swrenderer } int minvoxely = spr->gzt <= hzt ? 0 : xs_RoundToInt((spr->gzt - hzt) / spr->yscale); int maxvoxely = spr->gzb > hzb ? INT_MAX : xs_RoundToInt((spr->gzt - hzb) / spr->yscale); - spr->Render(thread, cliptop, clipbot, minvoxely, maxvoxely); + spr->Render(thread, cliptop, clipbot, minvoxely, maxvoxely, clip3DFloor); } spr->Light.BaseColormap = colormap; spr->Light.ColormapNum = colormapnum; diff --git a/src/swrenderer/things/r_visiblesprite.h b/src/swrenderer/things/r_visiblesprite.h index c9fff33270..7821964863 100644 --- a/src/swrenderer/things/r_visiblesprite.h +++ b/src/swrenderer/things/r_visiblesprite.h @@ -38,7 +38,7 @@ namespace swrenderer VisibleSprite() { RenderStyle = STYLE_Normal; } virtual ~VisibleSprite() { } - void Render(RenderThread *thread); + void Render(RenderThread *thread, Fake3DTranslucent clip3DFloor); bool IsCurrentPortalUniq(int portalUniq) const { return CurrentPortalUniq == portalUniq; } const FVector3 &WorldPos() const { return gpos; } @@ -54,7 +54,7 @@ namespace swrenderer virtual bool IsWallSprite() const { return false; } virtual bool IsModel() const { return false; } - virtual void Render(RenderThread *thread, short *cliptop, short *clipbottom, int minZ, int maxZ) = 0; + virtual void Render(RenderThread *thread, short *cliptop, short *clipbottom, int minZ, int maxZ, Fake3DTranslucent clip3DFloor) = 0; FTexture *pic = nullptr; diff --git a/src/swrenderer/things/r_voxel.cpp b/src/swrenderer/things/r_voxel.cpp index 75b0a2c077..a3c12a8655 100644 --- a/src/swrenderer/things/r_voxel.cpp +++ b/src/swrenderer/things/r_voxel.cpp @@ -205,7 +205,7 @@ namespace swrenderer thread->SpriteList->Push(vis); } - void RenderVoxel::Render(RenderThread *thread, short *cliptop, short *clipbottom, int minZ, int maxZ) + void RenderVoxel::Render(RenderThread *thread, short *cliptop, short *clipbottom, int minZ, int maxZ, Fake3DTranslucent clip3DFloor) { auto spr = this; auto viewport = thread->Viewport.get(); diff --git a/src/swrenderer/things/r_voxel.h b/src/swrenderer/things/r_voxel.h index bef22d4808..7121d34982 100644 --- a/src/swrenderer/things/r_voxel.h +++ b/src/swrenderer/things/r_voxel.h @@ -64,7 +64,7 @@ namespace swrenderer protected: bool IsVoxel() const override { return true; } - void Render(RenderThread *thread, short *cliptop, short *clipbottom, int minZ, int maxZ) override; + void Render(RenderThread *thread, short *cliptop, short *clipbottom, int minZ, int maxZ, Fake3DTranslucent clip3DFloor) override; private: struct posang diff --git a/src/swrenderer/things/r_wallsprite.cpp b/src/swrenderer/things/r_wallsprite.cpp index 1555e7124b..be4c4195eb 100644 --- a/src/swrenderer/things/r_wallsprite.cpp +++ b/src/swrenderer/things/r_wallsprite.cpp @@ -145,7 +145,7 @@ namespace swrenderer thread->SpriteList->Push(vis); } - void RenderWallSprite::Render(RenderThread *thread, short *mfloorclip, short *mceilingclip, int, int) + void RenderWallSprite::Render(RenderThread *thread, short *mfloorclip, short *mceilingclip, int, int, Fake3DTranslucent) { auto spr = this; diff --git a/src/swrenderer/things/r_wallsprite.h b/src/swrenderer/things/r_wallsprite.h index 2c2ca269cb..c248c6c8c8 100644 --- a/src/swrenderer/things/r_wallsprite.h +++ b/src/swrenderer/things/r_wallsprite.h @@ -14,7 +14,7 @@ namespace swrenderer protected: bool IsWallSprite() const override { return true; } - void Render(RenderThread *thread, short *cliptop, short *clipbottom, int minZ, int maxZ) override; + void Render(RenderThread *thread, short *cliptop, short *clipbottom, int minZ, int maxZ, Fake3DTranslucent clip3DFloor) override; private: static void DrawColumn(RenderThread *thread, SpriteDrawerArgs &drawerargs, int x, FTexture *WallSpriteTile, const ProjectedWallTexcoords &walltexcoords, double texturemid, float maskedScaleY, bool sprflipvert, const short *mfloorclip, const short *mceilingclip); From 6ab58e56ad6fc356ebf0bfaf15cfd98b54796ca9 Mon Sep 17 00:00:00 2001 From: Magnus Norddahl Date: Thu, 8 Mar 2018 04:25:27 +0100 Subject: [PATCH 04/89] - fix simplify code slightly --- src/swrenderer/scene/r_translucent_pass.cpp | 17 ++++------------- 1 file changed, 4 insertions(+), 13 deletions(-) diff --git a/src/swrenderer/scene/r_translucent_pass.cpp b/src/swrenderer/scene/r_translucent_pass.cpp index d56fde2fd6..244bb43925 100644 --- a/src/swrenderer/scene/r_translucent_pass.cpp +++ b/src/swrenderer/scene/r_translucent_pass.cpp @@ -195,14 +195,10 @@ namespace swrenderer Fake3DTranslucent clip3DFloor; if (hl->next) { - clip3DFloor.clipBottom = true; clip3DFloor.clipTop = true; clip3DFloor.sclipTop = hl->next->height; } - else - { - clip3DFloor.clipBottom = true; - } + clip3DFloor.clipBottom = true; clip3DFloor.sclipBottom = hl->height; DrawMaskedSingle(true, clip3DFloor); Thread->PlaneList->RenderHeight(hl->height); @@ -212,27 +208,22 @@ namespace swrenderer { Fake3DTranslucent clip3DFloor; clip3DFloor.clipTop = true; - clip3DFloor.down2Up = true; clip3DFloor.sclipTop = clip3d->height_top->height; + clip3DFloor.down2Up = true; DrawMaskedSingle(true, clip3DFloor); } - for (HeightLevel *hl = clip3d->height_top; hl != nullptr && hl->height < Thread->Viewport->viewpoint.Pos.Z; hl = hl->next) { Thread->PlaneList->RenderHeight(hl->height); Fake3DTranslucent clip3DFloor; if (hl->next) { - clip3DFloor.clipBottom = true; clip3DFloor.clipTop = true; - clip3DFloor.down2Up = true; clip3DFloor.sclipTop = hl->next->height; } - else - { - clip3DFloor.clipBottom = true; - } + clip3DFloor.clipBottom = true; clip3DFloor.sclipBottom = hl->height; + clip3DFloor.down2Up = true; DrawMaskedSingle(true, clip3DFloor); } clip3d->DeleteHeights(); From 7f17121df8225409746cfa8a8b283d32076757ad Mon Sep 17 00:00:00 2001 From: "alexey.lysiuk" Date: Thu, 8 Mar 2018 11:38:02 +0200 Subject: [PATCH 05/89] Fixed crash in MIDI to wave writer --- src/sound/i_musicinterns.h | 2 +- src/sound/mididevices/music_wavewriter_mididevice.cpp | 6 +++--- src/sound/musicformats/music_midistream.cpp | 7 ++++++- 3 files changed, 10 insertions(+), 5 deletions(-) diff --git a/src/sound/i_musicinterns.h b/src/sound/i_musicinterns.h index 9679fec934..b7acf60b75 100644 --- a/src/sound/i_musicinterns.h +++ b/src/sound/i_musicinterns.h @@ -198,7 +198,7 @@ protected: class MIDIWaveWriter : public SoftSynthMIDIDevice { public: - MIDIWaveWriter(const char *filename, MIDIDevice *devtouse); + MIDIWaveWriter(const char *filename, SoftSynthMIDIDevice *devtouse); ~MIDIWaveWriter(); int Resume(); int Open(MidiCallback cb, void *userdata) diff --git a/src/sound/mididevices/music_wavewriter_mididevice.cpp b/src/sound/mididevices/music_wavewriter_mididevice.cpp index 1f109aea2c..99590ee883 100644 --- a/src/sound/mididevices/music_wavewriter_mididevice.cpp +++ b/src/sound/mididevices/music_wavewriter_mididevice.cpp @@ -87,11 +87,11 @@ struct FmtChunk // //========================================================================== -MIDIWaveWriter::MIDIWaveWriter(const char *filename, MIDIDevice *playdevice) - : SoftSynthMIDIDevice(playDevice->GetSampleRate()) +MIDIWaveWriter::MIDIWaveWriter(const char *filename, SoftSynthMIDIDevice *playdevice) + : SoftSynthMIDIDevice(playdevice->GetSampleRate()) { File = FileWriter::Open(filename); - playDevice = (SoftSynthMIDIDevice*) playdevice; + playDevice = playdevice; if (File != nullptr) { // Write wave header uint32_t work[3]; diff --git a/src/sound/musicformats/music_midistream.cpp b/src/sound/musicformats/music_midistream.cpp index 2b4e1c34e5..873f9d92f5 100644 --- a/src/sound/musicformats/music_midistream.cpp +++ b/src/sound/musicformats/music_midistream.cpp @@ -319,8 +319,13 @@ bool MIDIStreamer::DumpWave(const char *filename, int subsong, int samplerate) assert(MIDI == NULL); auto devtype = SelectMIDIDevice(DeviceType); + if (devtype == MDEV_MMAPI) + { + Printf("MMAPI device is not supported"); + return false; + } MIDI = CreateMIDIDevice(devtype, samplerate); - MIDI = new MIDIWaveWriter(filename, MIDI); + MIDI = new MIDIWaveWriter(filename, reinterpret_cast(MIDI)); return InitPlayback(); } From 53a9819283e26dedae13bb33d928eb733ee569d8 Mon Sep 17 00:00:00 2001 From: "alexey.lysiuk" Date: Thu, 8 Mar 2018 12:24:33 +0200 Subject: [PATCH 06/89] Disabled GCC loop vectorization for R_LoadKVX() function This prevents crash (unaligned memory access by SSE instruction) on loading voxels in Release (-O3) builds https://forum.zdoom.org/viewtopic.php?t=59656 --- src/r_data/voxels.cpp | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/r_data/voxels.cpp b/src/r_data/voxels.cpp index c982f03829..e9a9b89fc1 100644 --- a/src/r_data/voxels.cpp +++ b/src/r_data/voxels.cpp @@ -180,6 +180,11 @@ static void RemapVoxelSlabs(kvxslab_t *dest, int size, const uint8_t *remap) // //========================================================================== +#if defined __GNUC__ && !defined __clang__ +#pragma GCC push_options +#pragma GCC optimize ("-fno-tree-loop-vectorize") +#endif // __GNUC__ && !__clang__ + FVoxel *R_LoadKVX(int lumpnum) { const kvxslab_t *slabs[MAXVOXMIPS]; @@ -320,6 +325,10 @@ FVoxel *R_LoadKVX(int lumpnum) return voxel; } +#if defined __GNUC__ && !defined __clang__ +#pragma GCC pop_options +#endif // __GNUC__ && !__clang__ + //========================================================================== // // From 2589447d0e620da9d473db276c68b502de110381 Mon Sep 17 00:00:00 2001 From: Magnus Norddahl Date: Fri, 9 Mar 2018 01:30:47 +0100 Subject: [PATCH 07/89] - fixed midtex nowrap clipping bug when 3d floors are in view - made sure no code uses sclipTop or sclipBottom as a working variable --- src/swrenderer/line/r_renderdrawsegment.cpp | 69 ++++++++++----------- src/swrenderer/line/r_renderdrawsegment.h | 2 +- src/swrenderer/things/r_visiblesprite.cpp | 14 +++-- 3 files changed, 43 insertions(+), 42 deletions(-) diff --git a/src/swrenderer/line/r_renderdrawsegment.cpp b/src/swrenderer/line/r_renderdrawsegment.cpp index df6c8f7a1b..86f86c2cbe 100644 --- a/src/swrenderer/line/r_renderdrawsegment.cpp +++ b/src/swrenderer/line/r_renderdrawsegment.cpp @@ -103,17 +103,13 @@ namespace swrenderer Clip3DFloors *clip3d = Thread->Clip3D.get(); - if (!(m3DFloor.clipTop)) - { - m3DFloor.sclipTop = sec->ceilingplane.ZatPoint(Thread->Viewport->viewpoint.Pos); - } - CameraLight *cameraLight = CameraLight::Instance(); if (cameraLight->FixedLightLevel() < 0) { + double clipTop = m3DFloor.clipTop ? m3DFloor.sclipTop : sec->ceilingplane.ZatPoint(Thread->Viewport->viewpoint.Pos); for (int i = frontsector->e->XFloor.lightlist.Size() - 1; i >= 0; i--) { - if (m3DFloor.sclipTop <= frontsector->e->XFloor.lightlist[i].plane.Zat0()) + if (clipTop <= frontsector->e->XFloor.lightlist[i].plane.Zat0()) { lightlist_t *lit = &frontsector->e->XFloor.lightlist[i]; basecolormap = GetColorTable(lit->extra_colormap, frontsector->SpecialColors[sector_t::walltop]); @@ -267,13 +263,18 @@ namespace swrenderer WallC.sx1 = ds->sx1; WallC.sx2 = ds->sx2; + double top, bot; + GetMaskedWallTopBottom(ds, top, bot); + top -= Thread->Viewport->viewpoint.Pos.Z; + bot -= Thread->Viewport->viewpoint.Pos.Z; + if (m3DFloor.clipTop) { wallupper.Project(Thread->Viewport.get(), textop < m3DFloor.sclipTop - Thread->Viewport->viewpoint.Pos.Z ? textop : m3DFloor.sclipTop - Thread->Viewport->viewpoint.Pos.Z, &WallC); } else { - wallupper.Project(Thread->Viewport.get(), textop, &WallC); + wallupper.Project(Thread->Viewport.get(), MIN(textop, top), &WallC); } if (m3DFloor.clipBottom) { @@ -281,7 +282,7 @@ namespace swrenderer } else { - walllower.Project(Thread->Viewport.get(), textop - texheight, &WallC); + walllower.Project(Thread->Viewport.get(), MAX(textop - texheight, bot), &WallC); } for (int i = x1; i < x2; i++) @@ -402,7 +403,7 @@ namespace swrenderer } // kg3D - render one fake wall - void RenderDrawSegment::RenderFakeWall(DrawSegment *ds, int x1, int x2, F3DFloor *rover, int wallshade, FDynamicColormap *basecolormap) + void RenderDrawSegment::RenderFakeWall(DrawSegment *ds, int x1, int x2, F3DFloor *rover, int wallshade, FDynamicColormap *basecolormap, double clipTop, double clipBottom) { int i; double xscale; @@ -485,8 +486,8 @@ namespace swrenderer WallT = ds->tmapvals; Clip3DFloors *clip3d = Thread->Clip3D.get(); - wallupper.Project(Thread->Viewport.get(), m3DFloor.sclipTop - Thread->Viewport->viewpoint.Pos.Z, &WallC); - walllower.Project(Thread->Viewport.get(), m3DFloor.sclipBottom - Thread->Viewport->viewpoint.Pos.Z, &WallC); + wallupper.Project(Thread->Viewport.get(), clipTop - Thread->Viewport->viewpoint.Pos.Z, &WallC); + walllower.Project(Thread->Viewport.get(), clipBottom - Thread->Viewport->viewpoint.Pos.Z, &WallC); for (i = x1; i < x2; i++) { @@ -542,13 +543,12 @@ namespace swrenderer Clip3DFloors *clip3d = Thread->Clip3D.get(); - // maybe fix clipheights - if (!m3DFloor.clipBottom) m3DFloor.sclipBottom = floorHeight; - if (!m3DFloor.clipTop) m3DFloor.sclipTop = ceilingHeight; + double clipTop = m3DFloor.clipTop ? m3DFloor.sclipTop : ceilingHeight; + double clipBottom = m3DFloor.clipBottom ? m3DFloor.sclipBottom : floorHeight; // maybe not visible - if (m3DFloor.sclipBottom >= frontsector->CenterCeiling()) return; - if (m3DFloor.sclipTop <= frontsector->CenterFloor()) return; + if (clipBottom >= frontsector->CenterCeiling()) return; + if (clipTop <= frontsector->CenterFloor()) return; if (m3DFloor.down2Up) { // bottom to viewz @@ -561,7 +561,7 @@ namespace swrenderer // visible? passed = 0; if (!(rover->flags & FF_RENDERSIDES) || rover->top.plane->isSlope() || rover->bottom.plane->isSlope() || - rover->top.plane->Zat0() <= m3DFloor.sclipBottom || + rover->top.plane->Zat0() <= clipBottom || rover->bottom.plane->Zat0() >= ceilingHeight || rover->top.plane->Zat0() <= floorHeight) { @@ -576,7 +576,7 @@ namespace swrenderer } rw_pic = nullptr; - if (rover->bottom.plane->Zat0() >= m3DFloor.sclipTop || passed) + if (rover->bottom.plane->Zat0() >= clipTop || passed) { if (last) { @@ -598,8 +598,8 @@ namespace swrenderer if (fover->top.plane->isSlope() || fover->bottom.plane->isSlope()) continue; // visible? - if (fover->top.plane->Zat0() <= m3DFloor.sclipBottom) continue; // no - if (fover->bottom.plane->Zat0() >= m3DFloor.sclipTop) + if (fover->top.plane->Zat0() <= clipBottom) continue; // no + if (fover->bottom.plane->Zat0() >= clipTop) { // no, last possible fover = nullptr; break; @@ -651,8 +651,8 @@ namespace swrenderer if (fover->top.plane->isSlope() || fover->bottom.plane->isSlope()) continue; // visible? - if (fover->top.plane->Zat0() <= m3DFloor.sclipBottom) continue; // no - if (fover->bottom.plane->Zat0() >= m3DFloor.sclipTop) + if (fover->top.plane->Zat0() <= clipBottom) continue; // no + if (fover->bottom.plane->Zat0() >= clipTop) { // visible, last possible fover = nullptr; break; @@ -703,7 +703,7 @@ namespace swrenderer { for (j = backsector->e->XFloor.lightlist.Size() - 1; j >= 0; j--) { - if (m3DFloor.sclipTop <= backsector->e->XFloor.lightlist[j].plane.Zat0()) + if (clipTop <= backsector->e->XFloor.lightlist[j].plane.Zat0()) { lightlist_t *lit = &backsector->e->XFloor.lightlist[j]; basecolormap = GetColorTable(lit->extra_colormap, frontsector->SpecialColors[sector_t::walltop]); @@ -717,7 +717,7 @@ namespace swrenderer { for (j = frontsector->e->XFloor.lightlist.Size() - 1; j >= 0; j--) { - if (m3DFloor.sclipTop <= frontsector->e->XFloor.lightlist[j].plane.Zat0()) + if (clipTop <= frontsector->e->XFloor.lightlist[j].plane.Zat0()) { lightlist_t *lit = &frontsector->e->XFloor.lightlist[j]; basecolormap = GetColorTable(lit->extra_colormap, frontsector->SpecialColors[sector_t::walltop]); @@ -732,7 +732,7 @@ namespace swrenderer if (rw_pic != DONT_DRAW) { - RenderFakeWall(ds, x1, x2, fover ? fover : rover, wallshade, basecolormap); + RenderFakeWall(ds, x1, x2, fover ? fover : rover, wallshade, basecolormap, clipTop, clipBottom); } else rw_pic = nullptr; break; @@ -749,7 +749,7 @@ namespace swrenderer passed = 0; if (!(rover->flags & FF_RENDERSIDES) || rover->top.plane->isSlope() || rover->bottom.plane->isSlope() || - rover->bottom.plane->Zat0() >= m3DFloor.sclipTop || + rover->bottom.plane->Zat0() >= clipTop || rover->top.plane->Zat0() <= floorHeight || rover->bottom.plane->Zat0() >= ceilingHeight) { @@ -763,7 +763,7 @@ namespace swrenderer } } rw_pic = nullptr; - if (rover->top.plane->Zat0() <= m3DFloor.sclipBottom || passed) + if (rover->top.plane->Zat0() <= clipBottom || passed) { // maybe wall from inside rendering? fover = nullptr; for (j = 0; j < (int)frontsector->e->XFloor.ffloors.Size(); j++) @@ -780,8 +780,8 @@ namespace swrenderer if (fover->top.plane->isSlope() || fover->bottom.plane->isSlope()) continue; // visible? - if (fover->bottom.plane->Zat0() >= m3DFloor.sclipTop) continue; // no - if (fover->top.plane->Zat0() <= m3DFloor.sclipBottom) + if (fover->bottom.plane->Zat0() >= clipTop) continue; // no + if (fover->top.plane->Zat0() <= clipBottom) { // no, last possible fover = nullptr; break; @@ -832,8 +832,8 @@ namespace swrenderer if (fover->top.plane->isSlope() || fover->bottom.plane->isSlope()) continue; // visible? - if (fover->bottom.plane->Zat0() >= m3DFloor.sclipTop) continue; // no - if (fover->top.plane->Zat0() <= m3DFloor.sclipBottom) + if (fover->bottom.plane->Zat0() >= clipTop) continue; // no + if (fover->top.plane->Zat0() <= clipBottom) { // visible, last possible fover = nullptr; break; @@ -882,7 +882,7 @@ namespace swrenderer { for (j = backsector->e->XFloor.lightlist.Size() - 1; j >= 0; j--) { - if (m3DFloor.sclipTop <= backsector->e->XFloor.lightlist[j].plane.Zat0()) + if (clipTop <= backsector->e->XFloor.lightlist[j].plane.Zat0()) { lightlist_t *lit = &backsector->e->XFloor.lightlist[j]; basecolormap = GetColorTable(lit->extra_colormap, frontsector->SpecialColors[sector_t::walltop]); @@ -896,7 +896,7 @@ namespace swrenderer { for (j = frontsector->e->XFloor.lightlist.Size() - 1; j >= 0; j--) { - if (m3DFloor.sclipTop <= frontsector->e->XFloor.lightlist[j].plane.Zat0()) + if (clipTop <= frontsector->e->XFloor.lightlist[j].plane.Zat0()) { lightlist_t *lit = &frontsector->e->XFloor.lightlist[j]; basecolormap = GetColorTable(lit->extra_colormap, frontsector->SpecialColors[sector_t::walltop]); @@ -911,7 +911,7 @@ namespace swrenderer if (rw_pic != DONT_DRAW) { - RenderFakeWall(ds, x1, x2, fover ? fover : rover, wallshade, basecolormap); + RenderFakeWall(ds, x1, x2, fover ? fover : rover, wallshade, basecolormap, clipTop, clipBottom); } else { @@ -952,7 +952,6 @@ namespace swrenderer top = MAX(frontcz1, frontcz2); bot = MIN(frontfz1, frontfz2); - Clip3DFloors *clip3d = Thread->Clip3D.get(); if (m3DFloor.clipTop) { top = MIN(top, m3DFloor.sclipTop); diff --git a/src/swrenderer/line/r_renderdrawsegment.h b/src/swrenderer/line/r_renderdrawsegment.h index f54ff6b1a9..82186f3174 100644 --- a/src/swrenderer/line/r_renderdrawsegment.h +++ b/src/swrenderer/line/r_renderdrawsegment.h @@ -39,7 +39,7 @@ namespace swrenderer private: bool RenderWall(DrawSegment *ds, int x1, int x2, WallDrawerArgs &walldrawerargs, SpriteDrawerArgs &columndrawerargs, bool visible, FDynamicColormap *basecolormap, int wallshade); void ClipMidtex(int x1, int x2); - void RenderFakeWall(DrawSegment *ds, int x1, int x2, F3DFloor *rover, int wallshade, FDynamicColormap *basecolormap); + void RenderFakeWall(DrawSegment *ds, int x1, int x2, F3DFloor *rover, int wallshade, FDynamicColormap *basecolormap, double clipTop, double clipBottom); void RenderFakeWallRange(DrawSegment *ds, int x1, int x2, int wallshade); void GetMaskedWallTopBottom(DrawSegment *ds, double &top, double &bot); diff --git a/src/swrenderer/things/r_visiblesprite.cpp b/src/swrenderer/things/r_visiblesprite.cpp index 5753d2e483..458e83dbb0 100644 --- a/src/swrenderer/things/r_visiblesprite.cpp +++ b/src/swrenderer/things/r_visiblesprite.cpp @@ -100,20 +100,22 @@ namespace swrenderer CameraLight *cameraLight = CameraLight::Instance(); if (!cameraLight->FixedColormap() && cameraLight->FixedLightLevel() < 0 && spr->sector->e && spr->sector->e->XFloor.lightlist.Size()) { - if (!clip3DFloor.clipTop) - { - clip3DFloor.sclipTop = spr->sector->ceilingplane.ZatPoint(thread->Viewport->viewpoint.Pos); - } + double clipTop; + if (clip3DFloor.clipTop) + clipTop = clip3DFloor.clipTop; + else + clipTop = spr->sector->ceilingplane.ZatPoint(thread->Viewport->viewpoint.Pos); + sector_t *sec = nullptr; FDynamicColormap *mybasecolormap = nullptr; for (int i = spr->sector->e->XFloor.lightlist.Size() - 1; i >= 0; i--) { - if (clip3DFloor.sclipTop <= spr->sector->e->XFloor.lightlist[i].plane.Zat0()) + if (clipTop <= spr->sector->e->XFloor.lightlist[i].plane.Zat0()) { rover = spr->sector->e->XFloor.lightlist[i].caster; if (rover) { - if (rover->flags & FF_DOUBLESHADOW && clip3DFloor.sclipTop <= rover->bottom.plane->Zat0()) + if (rover->flags & FF_DOUBLESHADOW && clipTop <= rover->bottom.plane->Zat0()) { break; } From 1d28a7f8e048841a50b1d5c8fba48b7b241afad8 Mon Sep 17 00:00:00 2001 From: "alexey.lysiuk" Date: Fri, 9 Mar 2018 10:47:01 +0200 Subject: [PATCH 08/89] Updated Travis CI configuration to use Clang 6.0 --- .travis.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.travis.yml b/.travis.yml index f457d5f999..40466de093 100644 --- a/.travis.yml +++ b/.travis.yml @@ -70,15 +70,15 @@ matrix: - os: linux compiler: clang env: - - CLANG_VERSION=5.0 + - CLANG_VERSION=6.0 - CMAKE_OPTIONS="-DCMAKE_BUILD_TYPE=MinSizeRel -DDYN_OPENAL=NO -DDYN_SNDFILE=NO -DDYN_MPG123=NO -DDYN_FLUIDSYNTH=NO" addons: apt: sources: - ubuntu-toolchain-r-test - - llvm-toolchain-trusty-5.0 + - llvm-toolchain-trusty-6.0 packages: - - clang-5.0 + - clang-6.0 - libstdc++-5-dev - libsdl2-dev - libgme-dev From f5d5430804da052d75535b39c88feb32766dfb41 Mon Sep 17 00:00:00 2001 From: "alexey.lysiuk" Date: Fri, 9 Mar 2018 12:53:41 +0200 Subject: [PATCH 09/89] Added ability to build without thread_local support https://forum.zdoom.org/viewtopic.php?t=58043 --- src/CMakeLists.txt | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 1ded86fb8d..9248964391 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -403,6 +403,16 @@ if( ZD_CMAKE_COMPILER_IS_GNUCXX_COMPATIBLE ) endif() endif() +# Check for thread_local keyword, it's optional at the moment + +CHECK_CXX_SOURCE_COMPILES("thread_local int i; int main() { i = 0; }" + HAVE_THREAD_LOCAL) + +if( NOT HAVE_THREAD_LOCAL ) + message( WARNING "C++ compiler doesn't support thread_local storage duration specifier" ) + add_definitions( -Dthread_local= ) +endif() + # Check for functions that may or may not exist. CHECK_FUNCTION_EXISTS( filelength FILELENGTH_EXISTS ) From 7dce4cfaf9d1d1973e9be7b002be17b71cdd392a Mon Sep 17 00:00:00 2001 From: "alexey.lysiuk" Date: Fri, 9 Mar 2018 15:20:55 +0200 Subject: [PATCH 10/89] Added CMake option to suppress zipdir output Cleaned up add_pk3() function a bit --- CMakeLists.txt | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 5809118d89..ddbdc70ad3 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -55,23 +55,24 @@ function( assort_pk3_source_folder FOLDER_NAME PK3_DIR ) endforeach() endfunction() +option( PK3_QUIET_ZIPDIR "Do not list files processed by zipdir" NO ) +if( PK3_QUIET_ZIPDIR ) + set( PK3_ZIPDIR_OPTIONS "-q" ) +endif() + # Simplify pk3 building, add_pk3(filename srcdirectory) function( add_pk3 PK3_NAME PK3_DIR ) - # message(STATUS "Creating build rule for PK3 ${PK3_NAME} ${PK3_DIR}") # Generate target name. Just use "pk3" for main pk3 target. string( REPLACE "." "_" PK3_TARGET ${PK3_NAME} ) - if( ${PK3_TARGET} STREQUAL "zdoom_pk3" ) - set( PK3_TARGET "pk3" ) - endif() if( NOT ZDOOM_OUTPUT_OLDSTYLE ) add_custom_command( OUTPUT ${ZDOOM_OUTPUT_DIR}/${PK3_NAME} - COMMAND zipdir -udf ${ZDOOM_OUTPUT_DIR}/${PK3_NAME} ${PK3_DIR} + COMMAND zipdir -udf ${PK3_ZIPDIR_OPTIONS} ${ZDOOM_OUTPUT_DIR}/${PK3_NAME} ${PK3_DIR} COMMAND ${CMAKE_COMMAND} -E copy_if_different ${ZDOOM_OUTPUT_DIR}/${PK3_NAME} $/${PK3_NAME} DEPENDS zipdir ) else() add_custom_command( OUTPUT ${ZDOOM_OUTPUT_DIR}/${PK3_NAME} - COMMAND zipdir -udf ${ZDOOM_OUTPUT_DIR}/${PK3_NAME} ${PK3_DIR} + COMMAND zipdir -udf ${PK3_ZIPDIR_OPTIONS} ${ZDOOM_OUTPUT_DIR}/${PK3_NAME} ${PK3_DIR} DEPENDS zipdir ) endif() # Create a list of source files for this PK3, for use in the IDE From d8e43dffbb93114c903ae75852bd398b922c5fc1 Mon Sep 17 00:00:00 2001 From: "alexey.lysiuk" Date: Fri, 9 Mar 2018 15:23:50 +0200 Subject: [PATCH 11/89] Enabled quiet pk3 creation in CI configurations Half of build log was polluted with useless file listings --- .appveyor.yml | 2 +- .travis.yml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.appveyor.yml b/.appveyor.yml index 486eb2d78a..e34cc0af67 100644 --- a/.appveyor.yml +++ b/.appveyor.yml @@ -32,7 +32,7 @@ environment: build_script: - md build - cd build - - cmake -G "%GENERATOR%" -T "%TOOLSET%" .. + - cmake -G "%GENERATOR%" -T "%TOOLSET%" -DPK3_QUIET_ZIPDIR=YES .. - cmake --build . --config "%CONFIGURATION%" -- /verbosity:minimal after_build: diff --git a/.travis.yml b/.travis.yml index 40466de093..4db8a3ec57 100644 --- a/.travis.yml +++ b/.travis.yml @@ -98,7 +98,7 @@ script: - echo ${TRAVIS_BUILD_DIR} - mkdir build - cd build - - cmake ${CMAKE_OPTIONS} .. + - cmake ${CMAKE_OPTIONS} -DPK3_QUIET_ZIPDIR=YES .. - make -j2 notifications: From fc981bf5d44143896755e64688c1c99fc03d8e7a Mon Sep 17 00:00:00 2001 From: "alexey.lysiuk" Date: Fri, 9 Mar 2018 18:13:16 +0200 Subject: [PATCH 12/89] Extended profilethinkers CVAR with sorting ability Sorting modes are 1 - by name, from A to Z 2 - by name, from Z to A 3 - number of calls, ascending 4 - number of calls, descending 5 - total time, ascending anything else - total time, descending --- src/dthinker.cpp | 40 ++++++++++++++++++++++++++++++++++++++-- 1 file changed, 38 insertions(+), 2 deletions(-) diff --git a/src/dthinker.cpp b/src/dthinker.cpp index a415dff030..7b0cfb8244 100644 --- a/src/dthinker.cpp +++ b/src/dthinker.cpp @@ -462,7 +462,7 @@ void DThinker::DestroyThinkersInList (FThinkerList &list) // // //========================================================================== -CVAR(Bool, profilethinkers, false, 0) +CVAR(Int, profilethinkers, 0, 0) struct ProfileInfo { @@ -526,12 +526,48 @@ void DThinker::RunThinkers () count += ProfileThinkers(&FreshThinkers[i], &Thinkers[i]); } } while (count != 0); + + struct SortedProfileInfo + { + const char* className; + int numcalls; + double time; + }; + + TArray sorted; + sorted.Grow(Profiles.CountUsed()); + auto it = TMap::Iterator(Profiles); TMap::Pair *pair; while (it.NextPair(pair)) { - Printf("%s, %dx, %fms\n", pair->Key.GetChars(), pair->Value.numcalls, pair->Value.timer.TimeMS()); + sorted.Push({ pair->Key.GetChars(), pair->Value.numcalls, pair->Value.timer.TimeMS() }); } + + std::sort(sorted.begin(), sorted.end(), [](const SortedProfileInfo& left, const SortedProfileInfo& right) + { + switch (profilethinkers) + { + case 1: // by name, from A to Z + return stricmp(left.className, right.className) < 0; + case 2: // by name, from Z to A + return stricmp(right.className, left.className) < 0; + case 3: // number of calls, ascending + return left.numcalls < right.numcalls; + case 4: // number of calls, descending + return right.numcalls < left.numcalls; + case 5: // total time, ascending + return left.time < right.time; + default: // total time, descending + return right.time < left.time; + } + }); + + for (const SortedProfileInfo& info : sorted) + { + Printf("%s, %dx, %fms\n", info.className, info.numcalls, info.time); + } + profilethinkers = false; } From 9cd5b415c1d44c8abb5bbdcc16ecae5c12b8be63 Mon Sep 17 00:00:00 2001 From: "alexey.lysiuk" Date: Sat, 10 Mar 2018 11:04:31 +0200 Subject: [PATCH 13/89] Improved profilethinkers in various ways Added features: * Formatted table * Average time per one actor * Sorting column highlight * Rows limit * Usage help --- src/dthinker.cpp | 76 ++++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 71 insertions(+), 5 deletions(-) diff --git a/src/dthinker.cpp b/src/dthinker.cpp index 7b0cfb8244..39de2e9d68 100644 --- a/src/dthinker.cpp +++ b/src/dthinker.cpp @@ -41,6 +41,8 @@ #include "serializer.h" #include "d_player.h" #include "vm.h" +#include "c_dispatch.h" +#include "v_text.h" static int ThinkCount; @@ -462,7 +464,57 @@ void DThinker::DestroyThinkersInList (FThinkerList &list) // // //========================================================================== -CVAR(Int, profilethinkers, 0, 0) +static unsigned int profilethinkers, profilelimit; + +CCMD(profilethinkers) +{ + const int argc = argv.argc(); + + if (argc == 2 || argc == 3) + { + const char *str = argv[1]; + bool ascend = true; + + if (*str == '+') + { + ++str; + } + else if (*str == '-') + { + ascend = false; + ++str; + } + + int mode = 0; + + switch (*str) + { + case 't': mode = ascend ? 7 : 8; break; + case 'a': mode = ascend ? 5 : 6; break; + case '#': mode = ascend ? 3 : 4; break; + case 'c': mode = ascend ? 1 : 2; break; + default: mode = atoi(str); break; + } + + profilethinkers = mode; + profilelimit = argc == 3 ? atoi(argv[2]) : 0; + } + else + { + Printf( + "Usage: profilethinkers [+|-][t|a|#|c] [limit]\n" + " profilethinkers [1..8] [limit]\n\n" + "Sorting modes:\n" + TEXTCOLOR_YELLOW "c +c 1 " TEXTCOLOR_NORMAL "actor class, ascending\n" + TEXTCOLOR_YELLOW " -c 2 " TEXTCOLOR_NORMAL "actor class, descending\n" + TEXTCOLOR_YELLOW "# +# 3 " TEXTCOLOR_NORMAL "number of calls, ascending\n" + TEXTCOLOR_YELLOW " -# 4 " TEXTCOLOR_NORMAL "number of calls, descending\n" + TEXTCOLOR_YELLOW "a +a 5 " TEXTCOLOR_NORMAL "average time, ascending\n" + TEXTCOLOR_YELLOW " -a 6 " TEXTCOLOR_NORMAL "average time, descending\n" + TEXTCOLOR_YELLOW "t +t 7 " TEXTCOLOR_NORMAL "total time, ascending\n" + TEXTCOLOR_YELLOW " -t 8 " TEXTCOLOR_NORMAL "total time, descending\n"); + } +} struct ProfileInfo { @@ -556,19 +608,33 @@ void DThinker::RunThinkers () return left.numcalls < right.numcalls; case 4: // number of calls, descending return right.numcalls < left.numcalls; - case 5: // total time, ascending + case 5: // average time, ascending + return left.time / left.numcalls < right.time / right.numcalls; + case 6: // average time, descending + return right.time / right.numcalls < left.time / left.numcalls; + case 7: // total time, ascending return left.time < right.time; default: // total time, descending return right.time < left.time; } }); - for (const SortedProfileInfo& info : sorted) + Printf(TEXTCOLOR_YELLOW "Total, ms Averg, ms Calls Actor class\n"); + Printf(TEXTCOLOR_YELLOW "---------- ---------- ------ --------------------\n"); + + const unsigned count = MIN(profilelimit > 0 ? profilelimit : UINT_MAX, sorted.Size()); + + for (unsigned i = 0; i < count; ++i) { - Printf("%s, %dx, %fms\n", info.className, info.numcalls, info.time); + const SortedProfileInfo& info = sorted[i]; + Printf("%s%10.6f %s%10.6f %s%6d %s%s\n", + profilethinkers >= 7 ? TEXTCOLOR_YELLOW : TEXTCOLOR_WHITE, info.time, + profilethinkers == 5 || profilethinkers == 6 ? TEXTCOLOR_YELLOW : TEXTCOLOR_WHITE, info.time / info.numcalls, + profilethinkers == 3 || profilethinkers == 4 ? TEXTCOLOR_YELLOW : TEXTCOLOR_WHITE, info.numcalls, + profilethinkers == 1 || profilethinkers == 2 ? TEXTCOLOR_YELLOW : TEXTCOLOR_WHITE, info.className); } - profilethinkers = false; + profilethinkers = 0; } ThinkCycles.Unclock(); From 26e948357eaf077818f7f9f3054739462a56c965 Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Sat, 10 Mar 2018 13:46:35 +0100 Subject: [PATCH 14/89] - added an abstract FileReader wrapper. The idea here is to decouple the actual reader creation from the code using them so that, for example, the Open function can decide if it wants to open the file regularly or memory mapped and return different readers as deemed useful. For that to work the exposed object needs to be an abstract wrapper so that this can be done without having to use pointers and all the drawbacks coming from that. So far put to use in a few parts of the music code so the general functionality could be tested. --- src/files.cpp | 28 ++++ src/files.h | 157 ++++++++++++++++++ src/sound/i_music.cpp | 13 +- .../mididevices/music_opl_mididevice.cpp | 4 +- src/sound/midisources/midisource.h | 8 +- src/sound/midisources/midisource_hmi.cpp | 4 +- src/sound/midisources/midisource_mus.cpp | 7 +- src/sound/midisources/midisource_smf.cpp | 4 +- src/sound/midisources/midisource_xmi.cpp | 4 +- src/sound/timidity/timidity.cpp | 6 +- src/w_wad.cpp | 28 ++++ src/w_wad.h | 7 +- 12 files changed, 242 insertions(+), 28 deletions(-) diff --git a/src/files.cpp b/src/files.cpp index 1b0e5db1fd..d429c20808 100644 --- a/src/files.cpp +++ b/src/files.cpp @@ -687,3 +687,31 @@ size_t BufferWriter::Write(const void *buffer, size_t len) return len; } + +////////////////////////////////////// +// +// The new wrapper +// +////////////////////////////////////// + +bool FileRdr::OpenFile(const char *filename) +{ + mReader = new FileReader; + if (mReader->Open(filename)) return true; + delete mReader; + mReader = nullptr; + return false; +} + +bool FileRdr::OpenMemory(const void *mem, FileRdr::Size length) +{ + mReader = new MemoryReader((const char *)mem, (long)length); + return true; +} + +bool FileRdr::OpenMemoryArray(const void *mem, FileRdr::Size length) +{ + mReader = new MemoryArrayReader((const char *)mem, (long)length); + return true; +} + diff --git a/src/files.h b/src/files.h index 808f24d94d..5e4b918123 100644 --- a/src/files.h +++ b/src/files.h @@ -167,6 +167,61 @@ protected: bool CloseOnDestruct; }; +// This will need a cleaner implementation once the outer interface is done. +// As a first step this only needs to work properly in the non-error case. +class FileReaderRedirect : public FileReader +{ + FileReader *mReader; +public: + FileReaderRedirect(FileReader *parent, long start, long length) + { + mReader = parent; + StartPos = start; + Length = length; + } + + virtual long Tell() const + { + auto l = mReader->Tell() - StartPos; + if (l < StartPos || l >= StartPos + Length) return -1; // out of scope + return l - StartPos; + } + + virtual long Seek(long offset, int origin) + { + switch (origin) + { + case SEEK_SET: + offset += StartPos; + break; + + case SEEK_END: + offset += StartPos + Length; + break; + + case SEEK_CUR: + offset += mReader->Tell(); + break; + } + if (offset < StartPos || offset >= StartPos + Length) return -1; // out of scope + return mReader->Seek(offset, SEEK_SET); + } + + virtual long Read(void *buffer, long len) + { + // This still needs better range checks + return mReader->Read(buffer, len); + } + virtual char *Gets(char *strbuf, int len) + { + return mReader->Gets(strbuf, len); + } + + long GetLength() const { return Length; } +}; + + + // Wraps around a FileReader to decompress a zlib stream class FileReaderZ : public FileReaderBase { @@ -438,4 +493,106 @@ public: + +class FileRdr // this is just a temporary name, until the old FileReader hierarchy can be made private. +{ + FileReader *mReader = nullptr; + + FileRdr() {} + FileRdr(const FileRdr &r) = delete; +public: + enum ESeek + { + SeekSet = SEEK_SET, + SeekCur = SEEK_CUR, + SeekEnd = SEEK_END + }; + + typedef ptrdiff_t Size; // let's not use 'long' here. + + FileRdr(FileReader *r) + { + mReader = r; + } + + FileRdr(FileRdr &&r) + { + mReader = r.mReader; + r.mReader = nullptr; + } + + ~FileRdr() + { + if (mReader != nullptr) delete mReader; + mReader = nullptr; + } + + bool OpenFile(const char *filename); + bool OpenFilePart(FileReader *parent, Size start, Size length); // later + bool OpenMemory(const void *mem, Size length); // read directly from the buffer + bool OpenMemoryArray(const void *mem, Size length); // read from a copy of the buffer. + + Size Tell() const + { + return mReader->Tell(); + } + + Size Seek(Size offset, ESeek origin) + { + return mReader->Seek((long)offset, origin); + } + + Size Read(void *buffer, Size len) + { + return mReader->Read(buffer, (long)len); + } + + char *Gets(char *strbuf, Size len) + { + return mReader->Gets(strbuf, (int)len); + } + + Size GetLength() const + { + return mReader->GetLength(); + } + + FileRdr &operator>> (uint8_t &v) + { + mReader->Read(&v, 1); + return *this; + } + + FileRdr &operator>> (int8_t &v) + { + mReader->Read(&v, 1); + return *this; + } + + FileRdr &operator>> (uint16_t &v) + { + mReader->Read(&v, 2); + v = LittleShort(v); + return *this; + } + + FileRdr &operator>> (int16_t &v) + { + mReader->Read(&v, 2); + v = LittleShort(v); + return *this; + } + + FileRdr &operator>> (uint32_t &v) + { + mReader->Read(&v, 4); + v = LittleLong(v); + return *this; + } + + friend class FWadCollection; +}; + + + #endif diff --git a/src/sound/i_music.cpp b/src/sound/i_music.cpp index cbea4ee2ca..717bff8de7 100644 --- a/src/sound/i_music.cpp +++ b/src/sound/i_music.cpp @@ -309,7 +309,7 @@ MusInfo *MusInfo::GetWaveDumper(const char *filename, int rate) // //========================================================================== -static MIDISource *CreateMIDISource(FileReader &reader, EMIDIType miditype) +static MIDISource *CreateMIDISource(FileRdr &reader, EMIDIType miditype) { MIDISource *source = nullptr; switch (miditype) @@ -452,11 +452,14 @@ MusInfo *I_RegisterSong (FileReader *reader, MidiDeviceSetting *device) EMIDIType miditype = IdentifyMIDIType(id, sizeof(id)); if (miditype != MIDI_NOTMIDI) { - auto source = CreateMIDISource(*reader, miditype); + // temporary hack so we can test before converting more. + FileRdr rdr(reader); + reader = nullptr; + + auto source = CreateMIDISource(rdr, miditype); if (source == nullptr) return 0; if (!source->isValid()) { - delete reader; delete source; return 0; } @@ -719,10 +722,10 @@ static MIDISource *GetMIDISource(const char *fn) return nullptr; } - FWadLump wlump = Wads.OpenLumpNum(lump); + auto wlump = Wads.OpenLumpReader(lump); uint32_t id[32 / 4]; - if (wlump.Read(id, 32) != 32 || wlump.Seek(-32, SEEK_CUR) != 0) + if (wlump.Read(id, 32) != 32 || wlump.Seek(-32, FileRdr::SeekCur) != 0) { Printf("Unable to read lump %s\n", src.GetChars()); return nullptr; diff --git a/src/sound/mididevices/music_opl_mididevice.cpp b/src/sound/mididevices/music_opl_mididevice.cpp index a373585207..48aa8104f9 100644 --- a/src/sound/mididevices/music_opl_mididevice.cpp +++ b/src/sound/mididevices/music_opl_mididevice.cpp @@ -83,7 +83,9 @@ OPLMIDIDevice::OPLMIDIDevice(const char *args) { OPL_SetCore(args); FullPan = opl_fullpan; - FWadLump data = Wads.OpenLumpName("GENMIDI"); + auto lump = Wads.CheckNumForName("GENMIDI", ns_global); + if (lump < 0) I_Error("No GENMIDI lump found"); + auto data = Wads.OpenLumpReader(lump); uint8_t filehdr[8]; data.Read(filehdr, 8); diff --git a/src/sound/midisources/midisource.h b/src/sound/midisources/midisource.h index 7e7381eae4..f7ce85e4cf 100644 --- a/src/sound/midisources/midisource.h +++ b/src/sound/midisources/midisource.h @@ -76,7 +76,7 @@ public: class MUSSong2 : public MIDISource { public: - MUSSong2(FileReader &reader); + MUSSong2(FileRdr &reader); ~MUSSong2(); protected: @@ -99,7 +99,7 @@ private: class MIDISong2 : public MIDISource { public: - MIDISong2(FileReader &reader); + MIDISong2(FileRdr &reader); ~MIDISong2(); protected: @@ -153,7 +153,7 @@ protected: class HMISong : public MIDISource { public: - HMISong(FileReader &reader); + HMISong(FileRdr &reader); ~HMISong(); protected: @@ -193,7 +193,7 @@ private: class XMISong : public MIDISource { public: - XMISong(FileReader &reader); + XMISong(FileRdr &reader); ~XMISong(); protected: diff --git a/src/sound/midisources/midisource_hmi.cpp b/src/sound/midisources/midisource_hmi.cpp index c2ce9b1fc2..e0939de273 100644 --- a/src/sound/midisources/midisource_hmi.cpp +++ b/src/sound/midisources/midisource_hmi.cpp @@ -126,9 +126,9 @@ struct HMISong::TrackInfo // //========================================================================== -HMISong::HMISong (FileReader &reader) +HMISong::HMISong (FileRdr &reader) { - int len = reader.GetLength(); + auto len = reader.GetLength(); if (len < 0x100) { // Way too small to be HMI. return; diff --git a/src/sound/midisources/midisource_mus.cpp b/src/sound/midisources/midisource_mus.cpp index feddfe67c8..9b6fe06bca 100644 --- a/src/sound/midisources/midisource_mus.cpp +++ b/src/sound/midisources/midisource_mus.cpp @@ -33,11 +33,6 @@ // HEADER FILES ------------------------------------------------------------ -#if !defined(__FreeBSD__) && !defined(__APPLE__) && !defined(__OpenBSD__) -#include -#else -#include -#endif #include "i_musicinterns.h" #include "templates.h" #include "doomdef.h" @@ -93,7 +88,7 @@ static const uint8_t CtrlTranslate[15] = // //========================================================================== -MUSSong2::MUSSong2 (FileReader &reader) +MUSSong2::MUSSong2 (FileRdr &reader) : MusHeader(0), MusBuffer(0) { uint8_t front[32]; diff --git a/src/sound/midisources/midisource_smf.cpp b/src/sound/midisources/midisource_smf.cpp index 6385bf997c..15c5fbabed 100644 --- a/src/sound/midisources/midisource_smf.cpp +++ b/src/sound/midisources/midisource_smf.cpp @@ -99,13 +99,13 @@ struct MIDISong2::TrackInfo // //========================================================================== -MIDISong2::MIDISong2 (FileReader &reader) +MIDISong2::MIDISong2 (FileRdr &reader) : MusHeader(0), Tracks(0) { int p; int i; - SongLen = reader.GetLength(); + SongLen = (int)reader.GetLength(); MusHeader = new uint8_t[SongLen]; if (reader.Read(MusHeader, SongLen) != SongLen) return; diff --git a/src/sound/midisources/midisource_xmi.cpp b/src/sound/midisources/midisource_xmi.cpp index b593081763..50e6b06e35 100644 --- a/src/sound/midisources/midisource_xmi.cpp +++ b/src/sound/midisources/midisource_xmi.cpp @@ -105,10 +105,10 @@ struct XMISong::TrackInfo // //========================================================================== -XMISong::XMISong (FileReader &reader) +XMISong::XMISong (FileRdr &reader) : MusHeader(0), Songs(0) { - SongLen = reader.GetLength(); + SongLen = (int)reader.GetLength(); MusHeader = new uint8_t[SongLen]; if (reader.Read(MusHeader, SongLen) != SongLen) return; diff --git a/src/sound/timidity/timidity.cpp b/src/sound/timidity/timidity.cpp index 455ed1713d..4c9efe0ac7 100644 --- a/src/sound/timidity/timidity.cpp +++ b/src/sound/timidity/timidity.cpp @@ -590,7 +590,7 @@ int LoadDMXGUS() if (lump == -1) lump = Wads.CheckNumForName("DMXGUSC"); if (lump == -1) return LoadConfig(midi_config); - FWadLump data = Wads.OpenLumpNum(lump); + auto data = Wads.OpenLumpReader(lump); if (data.GetLength() == 0) return LoadConfig(midi_config); // Check if we got some GUS data before using it. @@ -613,7 +613,7 @@ int LoadDMXGUS() gus_sfreader.reset(psreader); char readbuffer[1024]; - long size = data.GetLength(); + auto size = data.GetLength(); long read = 0; uint8_t remap[256]; @@ -624,7 +624,7 @@ int LoadDMXGUS() int status = -1; int gusbank = (gus_memsize >= 1 && gus_memsize <= 4) ? gus_memsize : -1; - data.Seek(0, SEEK_SET); + data.Seek(0, FileRdr::SeekSet); while (data.Gets(readbuffer, 1024) && read < size) { diff --git a/src/w_wad.cpp b/src/w_wad.cpp index 21c35e6693..30b9fdecc9 100644 --- a/src/w_wad.cpp +++ b/src/w_wad.cpp @@ -1352,6 +1352,34 @@ FWadLump *FWadCollection::ReopenLumpNumNewFile (int lump) return new FWadLump(lump, LumpInfo[lump].lump); } +//========================================================================== +// +// OpenLumpReader +// +// uses a more abstract interface to allow for easier low level optimization later +// +//========================================================================== + + +FileRdr FWadCollection::OpenLumpReader(int lump) +{ + FileRdr rdr; + + if ((unsigned)lump >= (unsigned)LumpInfo.Size()) + { + I_Error("W_OpenLumpNum: %u >= NumLumps", lump); + } + + rdr.mReader = new FWadLump(LumpInfo[lump].lump); + return rdr; +} + +FileRdr FWadCollection::ReopenLumpReader(int lump, bool alwayscache) +{ + FileRdr rdr; + rdr.mReader = alwayscache ? ReopenLumpNumNewFile(lump) : ReopenLumpNum(lump); + return rdr; +} //========================================================================== // diff --git a/src/w_wad.h b/src/w_wad.h index 11e4a954d7..73f8185645 100644 --- a/src/w_wad.h +++ b/src/w_wad.h @@ -177,13 +177,13 @@ public: FMemLump ReadLump (int lump); FMemLump ReadLump (const char *name) { return ReadLump (GetNumForName (name)); } + FileRdr OpenLumpReader(int lump); // opens a reader that redirects to the containing file's one. + FileRdr ReopenLumpReader(int lump, bool alwayscache = false); // opens an independent reader. + FWadLump OpenLumpNum (int lump); - FWadLump OpenLumpName (const char *name) { return OpenLumpNum (GetNumForName (name)); } FWadLump *ReopenLumpNum (int lump); // Opens a new, independent FILE FWadLump *ReopenLumpNumNewFile (int lump); // Opens a new, independent FILE - FileReader * GetFileReader(int wadnum); // Gets a FileReader object to the entire WAD - int FindLump (const char *name, int *lastlump, bool anyns=false); // [RH] Find lumps with duplication int FindLumpMulti (const char **names, int *lastlump, bool anyns = false, int *nameindex = NULL); // same with multiple possible names bool CheckLumpName (int lump, const char *name); // [RH] True if lump's name == name @@ -237,6 +237,7 @@ private: void RenameNerve(); void FixMacHexen(); void DeleteAll(); + FileReader * GetFileReader(int wadnum); // Gets a FileReader object to the entire WAD }; extern FWadCollection Wads; From 37fa3fa25e9690f802d23fbe46ab9add17562ed8 Mon Sep 17 00:00:00 2001 From: Rachael Alexanderson Date: Sat, 10 Mar 2018 10:36:43 -0500 Subject: [PATCH 15/89] - add variables 'am_unexploredsecretcolor' and 'am_ovunexploredsecretcolor' to mark undiscovered secrets differently in the automap --- src/am_map.cpp | 27 ++++++++++++++++++++------- 1 file changed, 20 insertions(+), 7 deletions(-) diff --git a/src/am_map.cpp b/src/am_map.cpp index 452f82b785..c6e6ba19ba 100644 --- a/src/am_map.cpp +++ b/src/am_map.cpp @@ -138,6 +138,7 @@ CVAR (Color, am_lockedcolor, 0x007800, CVAR_ARCHIVE); CVAR (Color, am_intralevelcolor, 0x0000ff, CVAR_ARCHIVE); CVAR (Color, am_interlevelcolor, 0xff0000, CVAR_ARCHIVE); CVAR (Color, am_secretsectorcolor, 0xff00ff, CVAR_ARCHIVE); +CVAR (Color, am_unexploredsecretcolor, 0xff00ff, CVAR_ARCHIVE); CVAR (Color, am_thingcolor_friend, 0xfcfcfc, CVAR_ARCHIVE); CVAR (Color, am_thingcolor_monster, 0xfcfcfc, CVAR_ARCHIVE); CVAR (Color, am_thingcolor_ncmonster, 0xfcfcfc, CVAR_ARCHIVE); @@ -158,6 +159,7 @@ CVAR (Color, am_ovunseencolor, 0x00226e, CVAR_ARCHIVE); CVAR (Color, am_ovtelecolor, 0xffff00, CVAR_ARCHIVE); CVAR (Color, am_ovinterlevelcolor, 0xffff00, CVAR_ARCHIVE); CVAR (Color, am_ovsecretsectorcolor,0x00ffff, CVAR_ARCHIVE); +CVAR (Color, am_ovunexploredsecretcolor,0x00ffff, CVAR_ARCHIVE); CVAR (Color, am_ovthingcolor, 0xe88800, CVAR_ARCHIVE); CVAR (Color, am_ovthingcolor_friend, 0xe88800, CVAR_ARCHIVE); CVAR (Color, am_ovthingcolor_monster, 0xe88800, CVAR_ARCHIVE); @@ -230,6 +232,7 @@ static const char *ColorNames[] = { "IntraTeleportColor", "InterTeleportColor", "SecretSectorColor", + "UnexploredSecretColor", "PortalColor", "AlmostBackgroundColor", NULL @@ -261,6 +264,7 @@ struct AMColorset IntraTeleportColor, InterTeleportColor, SecretSectorColor, + UnexploredSecretColor, PortalColor, AlmostBackgroundColor, AM_NUM_COLORS @@ -362,6 +366,7 @@ static FColorCVar *cv_standard[] = { &am_intralevelcolor, &am_interlevelcolor, &am_secretsectorcolor, + &am_unexploredsecretcolor, &am_portalcolor }; @@ -388,6 +393,7 @@ static FColorCVar *cv_overlay[] = { &am_ovtelecolor, &am_ovinterlevelcolor, &am_ovsecretsectorcolor, + &am_ovunexploredsecretcolor, &am_ovportalcolor }; @@ -430,6 +436,7 @@ static unsigned char DoomColors[]= { NOT_USED, // intrateleport NOT_USED, // interteleport NOT_USED, // secretsector + NOT_USED, // unexploredsecretsector 0x10,0x10,0x10, // almostbackground 0x40,0x40,0x40 // portal }; @@ -457,6 +464,7 @@ static unsigned char StrifeColors[]= { NOT_USED, // intrateleport NOT_USED, // interteleport NOT_USED, // secretsector + NOT_USED, // unexploredsecretsector 0x10,0x10,0x10, // almostbackground 0x40,0x40,0x40 // portal }; @@ -484,6 +492,7 @@ static unsigned char RavenColors[]= { NOT_USED, // intrateleport NOT_USED, // interteleport NOT_USED, // secretsector + NOT_USED, // unexploredsecretsector 0x10,0x10,0x10, // almostbackground 0x50,0x50,0x50 // portal }; @@ -2209,7 +2218,7 @@ void AM_drawSubsectors() // //============================================================================= -static bool AM_CheckSecret(line_t *line) +static int AM_CheckSecret(line_t *line) { if (AMColors.isValid(AMColors.SecretSectorColor)) { @@ -2217,20 +2226,20 @@ static bool AM_CheckSecret(line_t *line) { if (line->frontsector->wasSecret()) { - if (am_map_secrets!=0 && !line->frontsector->isSecret()) return true; - if (am_map_secrets==2 && !(line->flags & ML_SECRET)) return true; + if (am_map_secrets!=0 && !line->frontsector->isSecret()) return 1; + if (am_map_secrets==2 && !(line->flags & ML_SECRET)) return 2; } } if (line->backsector != NULL) { if (line->backsector->wasSecret()) { - if (am_map_secrets!=0 && !line->backsector->isSecret()) return true; - if (am_map_secrets==2 && !(line->flags & ML_SECRET)) return true; + if (am_map_secrets!=0 && !line->backsector->isSecret()) return 1; + if (am_map_secrets==2 && !(line->flags & ML_SECRET)) return 2; } } } - return false; + return 0; } @@ -2584,11 +2593,15 @@ void AM_drawWalls (bool allmap) { AM_drawMline(&l, AMColors.PortalColor); } - else if (AM_CheckSecret(&line)) + else if (AM_CheckSecret(&line) == 1) { // map secret sectors like Boom AM_drawMline(&l, AMColors.SecretSectorColor); } + else if (AM_CheckSecret(&line) == 2) + { + AM_drawMline(&l, AMColors.UnexploredSecretColor); + } else if (line.flags & ML_SECRET) { // secret door if (am_cheat != 0 && line.backsector != NULL) From 9600cfde3cf5556a47330d9239eeb7904f9ae75a Mon Sep 17 00:00:00 2001 From: Rachael Alexanderson Date: Sat, 10 Mar 2018 10:55:24 -0500 Subject: [PATCH 16/89] - put unexplored secret color picker in the menu --- wadsrc/static/language.enu | 1 + wadsrc/static/menudef.txt | 1 + 2 files changed, 2 insertions(+) diff --git a/wadsrc/static/language.enu b/wadsrc/static/language.enu index eabe3b2f52..155ce839d0 100644 --- a/wadsrc/static/language.enu +++ b/wadsrc/static/language.enu @@ -1979,6 +1979,7 @@ MAPCOLORMNU_LOCKEDCOLOR = "Locked doors"; MAPCOLORMNU_INTRALEVELCOLOR = "Teleporter to the same map"; MAPCOLORMNU_INTERLEVELCOLOR = "Teleporter to a different map"; MAPCOLORMNU_SECRETSECTORCOLOR = "Secret sector"; +MAPCOLORMNU_UNEXPLOREDSECRETCOLOR = "Unexplored secret"; MAPCOLORMNU_SPECIALWALLCOLOR = "Special trigger lines"; MAPCOLORMNU_CHEATMODE = "Cheat Mode"; MAPCOLORMNU_TSWALLCOLOR = "Invisible 2-sided walls"; diff --git a/wadsrc/static/menudef.txt b/wadsrc/static/menudef.txt index 09604328cf..744e4d4c78 100644 --- a/wadsrc/static/menudef.txt +++ b/wadsrc/static/menudef.txt @@ -1157,6 +1157,7 @@ OptionMenu MapColorMenu protected ColorPicker "$MAPCOLORMNU_INTRALEVELCOLOR", "am_intralevelcolor" ColorPicker "$MAPCOLORMNU_INTERLEVELCOLOR", "am_interlevelcolor" ColorPicker "$MAPCOLORMNU_SECRETSECTORCOLOR", "am_secretsectorcolor" + ColorPicker "$MAPCOLORMNU_UNEXPLOREDSECRETCOLOR", "am_unexploredsecretcolor" ColorPicker "$MAPCOLORMNU_SPECIALWALLCOLOR", "am_specialwallcolor" ColorPicker "$MAPCOLORMNU_PORTAL", "am_portalcolor" StaticText " " From 5fa63c396d797306b64424398d7b41d82e80f5ff Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Sat, 10 Mar 2018 18:45:11 +0100 Subject: [PATCH 17/89] - sound code and most of texture code converted to FileRdr. This allowed to remove a lot of bad pointer voodoo in the music loader, because the new class does not allow duplication of the reader object --- src/c_cmds.cpp | 2 +- src/files.cpp | 41 ++++++++--- src/files.h | 27 ++++++- src/p_setup.cpp | 6 +- src/r_data/colormaps.cpp | 2 +- src/s_playlist.cpp | 10 +-- src/s_playlist.h | 4 +- src/s_sound.cpp | 19 +++-- src/sound/i_music.cpp | 78 ++++++++------------- src/sound/i_music.h | 4 +- src/sound/i_musicinterns.h | 12 ++-- src/sound/i_sound.cpp | 17 ++--- src/sound/i_sound.h | 6 +- src/sound/i_soundinternal.h | 6 +- src/sound/midisources/midisource_hmi.cpp | 2 +- src/sound/mpg123_decoder.cpp | 24 ++++--- src/sound/mpg123_decoder.h | 5 +- src/sound/musicformats/music_cd.cpp | 10 +-- src/sound/musicformats/music_dumb.cpp | 13 ++-- src/sound/musicformats/music_gme.cpp | 22 +++--- src/sound/musicformats/music_libsndfile.cpp | 60 ++++++++-------- src/sound/musicformats/music_opl.cpp | 4 +- src/sound/musicformats/music_stream.cpp | 2 +- src/sound/oalsound.cpp | 21 +++--- src/sound/oalsound.h | 2 +- src/sound/oplsynth/opl_mus_player.cpp | 6 +- src/sound/oplsynth/opl_mus_player.h | 4 +- src/sound/sndfile_decoder.cpp | 22 +++--- src/sound/sndfile_decoder.h | 5 +- src/swrenderer/r_swcolormaps.cpp | 4 +- src/textures/automaptexture.cpp | 2 +- src/textures/ddstexture.cpp | 36 +++++----- src/textures/emptytexture.cpp | 4 +- src/textures/flattexture.cpp | 6 +- src/textures/imgztexture.cpp | 4 +- src/textures/jpegtexture.cpp | 20 +++--- src/textures/multipatchtexture.cpp | 2 +- src/textures/patchtexture.cpp | 8 +-- src/textures/pcxtexture.cpp | 34 ++++----- src/textures/pngtexture.cpp | 8 +-- src/textures/rawpagetexture.cpp | 6 +- src/textures/texture.cpp | 26 +++---- src/textures/texturemanager.cpp | 10 ++- src/textures/tgatexture.cpp | 18 ++--- src/v_font.cpp | 10 +-- src/win32/st_start.cpp | 6 +- 46 files changed, 333 insertions(+), 307 deletions(-) diff --git a/src/c_cmds.cpp b/src/c_cmds.cpp index 842516ba34..f74eae569b 100644 --- a/src/c_cmds.cpp +++ b/src/c_cmds.cpp @@ -1224,7 +1224,7 @@ CCMD(secret) int lumpno=Wads.CheckNumForName("SECRETS"); if (lumpno < 0) return; - FWadLump lump = Wads.OpenLumpNum(lumpno); + auto lump = Wads.OpenLumpReader(lumpno); FString maphdr; maphdr.Format("[%s]", mapname); diff --git a/src/files.cpp b/src/files.cpp index d429c20808..cfd13cb7f9 100644 --- a/src/files.cpp +++ b/src/files.cpp @@ -563,10 +563,13 @@ char *MemoryReader::Gets(char *strbuf, int len) MemoryArrayReader::MemoryArrayReader (const char *buffer, long length) { - buf.Resize(length); - memcpy(&buf[0], buffer, length); - Length=length; - FilePos=0; + if (length > 0) + { + buf.Resize(length); + memcpy(&buf[0], buffer, length); + } + Length = length; + FilePos=0; } MemoryArrayReader::~MemoryArrayReader () @@ -696,22 +699,42 @@ size_t BufferWriter::Write(const void *buffer, size_t len) bool FileRdr::OpenFile(const char *filename) { - mReader = new FileReader; - if (mReader->Open(filename)) return true; - delete mReader; - mReader = nullptr; - return false; + auto reader = new FileReader; + if (!reader->Open(filename)) return false; + Close(); + mReader = reader; + return true; } bool FileRdr::OpenMemory(const void *mem, FileRdr::Size length) { + Close(); mReader = new MemoryReader((const char *)mem, (long)length); return true; } bool FileRdr::OpenMemoryArray(const void *mem, FileRdr::Size length) { + Close(); mReader = new MemoryArrayReader((const char *)mem, (long)length); return true; } +bool FileRdr::OpenMemoryArray(std::function&)> getter) +{ + auto reader = new MemoryArrayReader(nullptr, 0); + if (getter(reader->GetArray())) + { + Close(); + reader->UpdateLength(); + mReader = reader; + return true; + } + else + { + // This will keep the old + delete reader; + return false; + } +} + diff --git a/src/files.h b/src/files.h index 5e4b918123..c8a330315b 100644 --- a/src/files.h +++ b/src/files.h @@ -38,6 +38,7 @@ #include #include +#include #include "bzlib.h" #include "doomtype.h" #include "m_swap.h" @@ -498,8 +499,8 @@ class FileRdr // this is just a temporary name, until the old FileReader hierarc { FileReader *mReader = nullptr; - FileRdr() {} FileRdr(const FileRdr &r) = delete; + FileRdr &operator=(const FileRdr &r) = delete; public: enum ESeek { @@ -510,10 +511,19 @@ public: typedef ptrdiff_t Size; // let's not use 'long' here. + FileRdr() {} + + // These two functions are only needed as long as the FileReader has not been fully replaced throughout the code. FileRdr(FileReader *r) { mReader = r; } + FileReader *Reader() + { + auto r = mReader; + mReader = nullptr; + return r; + } FileRdr(FileRdr &&r) { @@ -521,7 +531,21 @@ public: r.mReader = nullptr; } + FileRdr& operator =(FileRdr &&r) + { + Close(); + mReader = r.mReader; + r.mReader = nullptr; + return *this; + } + + ~FileRdr() + { + Close(); + } + + void Close() { if (mReader != nullptr) delete mReader; mReader = nullptr; @@ -531,6 +555,7 @@ public: bool OpenFilePart(FileReader *parent, Size start, Size length); // later bool OpenMemory(const void *mem, Size length); // read directly from the buffer bool OpenMemoryArray(const void *mem, Size length); // read from a copy of the buffer. + bool OpenMemoryArray(std::function&)> getter); // read contents to a buffer and return a reader to it Size Tell() const { diff --git a/src/p_setup.cpp b/src/p_setup.cpp index 4f2a64bde2..1ca2496070 100644 --- a/src/p_setup.cpp +++ b/src/p_setup.cpp @@ -2500,17 +2500,17 @@ static void P_LoopSidedefs (bool firstloop) int P_DetermineTranslucency (int lumpnum) { - FWadLump tranmap = Wads.OpenLumpNum (lumpnum); + auto tranmap = Wads.OpenLumpReader (lumpnum); uint8_t index; PalEntry newcolor; PalEntry newcolor2; - tranmap.Seek (GPalette.BlackIndex * 256 + GPalette.WhiteIndex, SEEK_SET); + tranmap.Seek (GPalette.BlackIndex * 256 + GPalette.WhiteIndex, FileRdr::SeekSet); tranmap.Read (&index, 1); newcolor = GPalette.BaseColors[GPalette.Remap[index]]; - tranmap.Seek (GPalette.WhiteIndex * 256 + GPalette.BlackIndex, SEEK_SET); + tranmap.Seek (GPalette.WhiteIndex * 256 + GPalette.BlackIndex, FileRdr::SeekSet); tranmap.Read (&index, 1); newcolor2 = GPalette.BaseColors[GPalette.Remap[index]]; if (newcolor2.r == 255) // if black on white results in white it's either diff --git a/src/r_data/colormaps.cpp b/src/r_data/colormaps.cpp index cce900a80b..791101dd36 100644 --- a/src/r_data/colormaps.cpp +++ b/src/r_data/colormaps.cpp @@ -232,7 +232,7 @@ void R_InitColormaps () if (Wads.LumpLength (fakecmaps[j].lump) >= 256) { int k, r, g, b; - FWadLump lump = Wads.OpenLumpNum (fakecmaps[j].lump); + auto lump = Wads.OpenLumpReader (fakecmaps[j].lump); lump.Read(map, 256); r = g = b = 0; diff --git a/src/s_playlist.cpp b/src/s_playlist.cpp index 315a2ac763..4fcf8ee28b 100644 --- a/src/s_playlist.cpp +++ b/src/s_playlist.cpp @@ -54,7 +54,7 @@ bool FPlayList::ChangeList (const char *path) { FString playlistdir; FString song; - FileReader fr; + FileRdr fr; bool first; bool pls; int i; @@ -62,7 +62,7 @@ bool FPlayList::ChangeList (const char *path) Songs.Clear(); Position = 0; - if (!fr.Open(path)) + if (!fr.OpenFile(path)) { Printf ("Could not open " TEXTCOLOR_BOLD "%s" TEXTCOLOR_NORMAL ": %s\n", path, strerror(errno)); return false; @@ -71,7 +71,7 @@ bool FPlayList::ChangeList (const char *path) first = true; pls = false; playlistdir = ExtractFilePath(path); - while ((song = NextLine(&fr)).IsNotEmpty()) + while ((song = NextLine(fr)).IsNotEmpty()) { if (first) { @@ -133,14 +133,14 @@ bool FPlayList::ChangeList (const char *path) return Songs.Size() != 0; } -FString FPlayList::NextLine (FileReader *file) +FString FPlayList::NextLine (FileRdr &file) { char buffer[512]; char *skipper; do { - if (NULL == file->Gets (buffer, countof(buffer))) + if (nullptr == file.Gets (buffer, countof(buffer))) return ""; for (skipper = buffer; *skipper != 0 && *skipper <= ' '; skipper++) diff --git a/src/s_playlist.h b/src/s_playlist.h index 859f0bce41..049040a0f6 100644 --- a/src/s_playlist.h +++ b/src/s_playlist.h @@ -34,7 +34,7 @@ #ifndef __S_PLAYLIST_H__ #define __S_PLAYLIST_H__ -class FileReader; +class FileRdr; class FPlayList { @@ -53,7 +53,7 @@ public: const char *GetSong (int position) const; private: - static FString NextLine (FileReader *file); + static FString NextLine (FileRdr &file); unsigned int Position; TArray Songs; diff --git a/src/s_sound.cpp b/src/s_sound.cpp index f9ee262c17..6885fcb0c8 100644 --- a/src/s_sound.cpp +++ b/src/s_sound.cpp @@ -1430,7 +1430,7 @@ sfxinfo_t *S_LoadSound(sfxinfo_t *sfx, FSoundLoadBuffer *pBuffer) int size = Wads.LumpLength(sfx->lumpnum); if (size > 0) { - FWadLump wlump = Wads.OpenLumpNum(sfx->lumpnum); + auto wlump = Wads.OpenLumpReader(sfx->lumpnum); uint8_t *sfxdata = new uint8_t[size]; wlump.Read(sfxdata, size); int32_t dmxlen = LittleLong(((int32_t *)sfxdata)[1]); @@ -1498,7 +1498,7 @@ static void S_LoadSound3D(sfxinfo_t *sfx, FSoundLoadBuffer *pBuffer) int size = Wads.LumpLength(sfx->lumpnum); if (size <= 0) return; - FWadLump wlump = Wads.OpenLumpNum(sfx->lumpnum); + auto wlump = Wads.OpenLumpReader(sfx->lumpnum); uint8_t *sfxdata = new uint8_t[size]; wlump.Read(sfxdata, size); int32_t dmxlen = LittleLong(((int32_t *)sfxdata)[1]); @@ -2609,7 +2609,7 @@ bool S_ChangeMusic (const char *musicname, int order, bool looping, bool force) musicname += 7; } - FileReader *reader = NULL; + FileRdr reader; if (!FileExists (musicname)) { if ((lumpnum = Wads.CheckNumForFullName (musicname, true, ns_music)) == -1) @@ -2623,17 +2623,16 @@ bool S_ChangeMusic (const char *musicname, int order, bool looping, bool force) { return false; } - reader = Wads.ReopenLumpNumNewFile(lumpnum); - if (reader == NULL) - { - return false; - } + reader = Wads.ReopenLumpReader(lumpnum); } } else { // Load an external file. - reader = new FileReader(musicname); + if (!reader.OpenFile(musicname)) + { + return false; + } } // shutdown old music @@ -2646,7 +2645,6 @@ bool S_ChangeMusic (const char *musicname, int order, bool looping, bool force) mus_playing.name = musicname; mus_playing.baseorder = order; LastSong = musicname; - delete reader; return true; } @@ -2654,7 +2652,6 @@ bool S_ChangeMusic (const char *musicname, int order, bool looping, bool force) if (handle != NULL) { mus_playing.handle = handle; - delete reader; } else { diff --git a/src/sound/i_music.cpp b/src/sound/i_music.cpp index 717bff8de7..1042d0c5e1 100644 --- a/src/sound/i_music.cpp +++ b/src/sound/i_music.cpp @@ -398,7 +398,7 @@ static EMIDIType IdentifyMIDIType(uint32_t *id, int size) // //========================================================================== -MusInfo *I_RegisterSong (FileReader *reader, MidiDeviceSetting *device) +MusInfo *I_RegisterSong (FileRdr &reader, MidiDeviceSetting *device) { MusInfo *info = nullptr; const char *fmt; @@ -406,14 +406,12 @@ MusInfo *I_RegisterSong (FileReader *reader, MidiDeviceSetting *device) if (nomusic) { - delete reader; - return 0; + return nullptr; } - if(reader->Read(id, 32) != 32 || reader->Seek(-32, SEEK_CUR) != 0) + if(reader.Read(id, 32) != 32 || reader.Seek(-32, FileRdr::SeekCur) != 0) { - delete reader; - return 0; + return nullptr; } // Check for gzip compression. Some formats are expected to have players @@ -421,47 +419,38 @@ MusInfo *I_RegisterSong (FileReader *reader, MidiDeviceSetting *device) // gzippable. if ((id[0] & MAKE_ID(255, 255, 255, 0)) == GZIP_ID) { - int len = reader->GetLength(); - uint8_t *gzipped = new uint8_t[len]; - if (reader->Read(gzipped, len) != len) + + if (!reader.OpenMemoryArray([&reader](TArray &array) { + bool res = false; + auto len = reader.GetLength(); + uint8_t *gzipped = new uint8_t[len]; + if (reader.Read(gzipped, len) == len) + { + res = ungzip(gzipped, (int)len, array); + } delete[] gzipped; - delete reader; + return res; + })) + { return nullptr; } - delete reader; - MemoryArrayReader *memreader = new MemoryArrayReader(nullptr, 0); - if (!ungzip(gzipped, len, memreader->GetArray())) + if (reader.Read(id, 32) != 32 || reader.Seek(-32, FileRdr::SeekCur) != 0) { - delete[] gzipped; - delete memreader; - return 0; + return nullptr; } - delete[] gzipped; - memreader->UpdateLength(); - - if (memreader->Read(id, 32) != 32 || memreader->Seek(-32, SEEK_CUR) != 0) - { - delete memreader; - return 0; - } - reader = memreader; } EMIDIType miditype = IdentifyMIDIType(id, sizeof(id)); if (miditype != MIDI_NOTMIDI) { - // temporary hack so we can test before converting more. - FileRdr rdr(reader); - reader = nullptr; - - auto source = CreateMIDISource(rdr, miditype); - if (source == nullptr) return 0; + auto source = CreateMIDISource(reader, miditype); + if (source == nullptr) return nullptr; if (!source->isValid()) { delete source; - return 0; + return nullptr; } EMidiDevice devtype = device == nullptr? MDEV_DEFAULT : (EMidiDevice)device->device; @@ -474,9 +463,8 @@ MusInfo *I_RegisterSong (FileReader *reader, MidiDeviceSetting *device) MIDIStreamer *streamer = CreateMIDIStreamer(devtype, device != nullptr? device->args.GetChars() : ""); if (streamer == nullptr) { - delete reader; delete source; - return 0; + return nullptr; } streamer->SetMIDISource(source); info = streamer; @@ -488,22 +476,21 @@ MusInfo *I_RegisterSong (FileReader *reader, MidiDeviceSetting *device) (id[0] == MAKE_ID('D','B','R','A') && id[1] == MAKE_ID('W','O','P','L')) || // DosBox Raw OPL (id[0] == MAKE_ID('A','D','L','I') && *((uint8_t *)id + 4) == 'B')) // Martin Fernandez's modified IMF { - info = new OPLMUSSong (*reader, device != nullptr? device->args.GetChars() : ""); + info = new OPLMUSSong (reader, device != nullptr? device->args.GetChars() : ""); } // Check for game music else if ((fmt = GME_CheckFormat(id[0])) != nullptr && fmt[0] != '\0') { - info = GME_OpenSong(*reader, fmt); + info = GME_OpenSong(reader, fmt); } // Check for module formats else { - info = MOD_OpenSong(*reader); + info = MOD_OpenSong(reader); } if (info == nullptr) { - info = SndFile_OpenSong(*reader); - if (info != nullptr) reader = nullptr; + info = SndFile_OpenSong(reader); } if (info == nullptr) @@ -513,24 +500,21 @@ MusInfo *I_RegisterSong (FileReader *reader, MidiDeviceSetting *device) { uint32_t subid; - reader->Seek(8, SEEK_CUR); - if (reader->Read (&subid, 4) != 4) + reader.Seek(8, FileRdr::SeekCur); + if (reader.Read (&subid, 4) != 4) { - delete reader; - return 0; + return nullptr; } - reader->Seek(-12, SEEK_CUR); + reader.Seek(-12, FileRdr::SeekCur); if (subid == (('C')|(('D')<<8)|(('D')<<16)|(('A')<<24))) { // This is a CDDA file - info = new CDDAFile (*reader); + info = new CDDAFile (reader); } } } - if (reader != nullptr) delete reader; - if (info && !info->IsValid ()) { delete info; diff --git a/src/sound/i_music.h b/src/sound/i_music.h index 9a7b0836b7..167d73157e 100644 --- a/src/sound/i_music.h +++ b/src/sound/i_music.h @@ -37,7 +37,7 @@ #include "doomdef.h" #include "i_soundinternal.h" -class FileReader; +class FileRdr; struct FOptionValues; // @@ -55,7 +55,7 @@ void I_SetMusicVolume (float volume); // Registers a song handle to song data. class MusInfo; struct MidiDeviceSetting; -MusInfo *I_RegisterSong (FileReader *reader, MidiDeviceSetting *device); +MusInfo *I_RegisterSong (FileRdr &reader, MidiDeviceSetting *device); MusInfo *I_RegisterCDSong (int track, int cdid = 0); // The base music class. Everything is derived from this -------------------- diff --git a/src/sound/i_musicinterns.h b/src/sound/i_musicinterns.h index b7acf60b75..81a1fa415b 100644 --- a/src/sound/i_musicinterns.h +++ b/src/sound/i_musicinterns.h @@ -408,7 +408,7 @@ protected: class StreamSong : public MusInfo { public: - StreamSong (FileReader *reader); + StreamSong (FileRdr &reader); ~StreamSong (); void Play (bool looping, int subsong); void Pause (); @@ -431,7 +431,7 @@ protected: class OPLMUSSong : public StreamSong { public: - OPLMUSSong (FileReader &reader, const char *args); + OPLMUSSong (FileRdr &reader, const char *args); ~OPLMUSSong (); void Play (bool looping, int subsong); bool IsPlaying (); @@ -480,18 +480,18 @@ protected: class CDDAFile : public CDSong { public: - CDDAFile (FileReader &reader); + CDDAFile (FileRdr &reader); }; // Module played via foo_dumb ----------------------------------------------- -MusInfo *MOD_OpenSong(FileReader &reader); +MusInfo *MOD_OpenSong(FileRdr &reader); // Music played via Game Music Emu ------------------------------------------ const char *GME_CheckFormat(uint32_t header); -MusInfo *GME_OpenSong(FileReader &reader, const char *fmt); -MusInfo *SndFile_OpenSong(FileReader &fr); +MusInfo *GME_OpenSong(FileRdr &reader, const char *fmt); +MusInfo *SndFile_OpenSong(FileRdr &fr); // -------------------------------------------------------------------------- diff --git a/src/sound/i_sound.cpp b/src/sound/i_sound.cpp index 562945d197..e37a3adb12 100644 --- a/src/sound/i_sound.cpp +++ b/src/sound/i_sound.cpp @@ -159,9 +159,8 @@ public: { return NULL; } - SoundStream *OpenStream (FileReader *reader, int flags) + SoundStream *OpenStream (FileRdr &reader, int flags) { - delete reader; return NULL; } @@ -371,13 +370,15 @@ FString SoundRenderer::GatherStats () short *SoundRenderer::DecodeSample(int outlen, const void *coded, int sizebytes, ECodecType ctype) { - MemoryReader reader((const char*)coded, sizebytes); + FileRdr reader; short *samples = (short*)calloc(1, outlen); ChannelConfig chans; SampleType type; int srate; - SoundDecoder *decoder = CreateDecoder(&reader); + reader.OpenMemory(coded, sizebytes); + + SoundDecoder *decoder = CreateDecoder(reader); if(!decoder) return samples; decoder->getInfo(&srate, &chans, &type); @@ -577,16 +578,16 @@ std::pair SoundRenderer::LoadSoundBuffered(FSoundLoadBuffer * return std::make_pair(retval, true); } -SoundDecoder *SoundRenderer::CreateDecoder(FileReader *reader) +SoundDecoder *SoundRenderer::CreateDecoder(FileRdr &reader) { SoundDecoder *decoder = NULL; - int pos = reader->Tell(); + auto pos = reader.Tell(); #ifdef HAVE_SNDFILE decoder = new SndFileDecoder; if (decoder->open(reader)) return decoder; - reader->Seek(pos, SEEK_SET); + reader.Seek(pos, FileRdr::SeekSet); delete decoder; decoder = NULL; @@ -595,7 +596,7 @@ SoundDecoder *SoundRenderer::CreateDecoder(FileReader *reader) decoder = new MPG123Decoder; if (decoder->open(reader)) return decoder; - reader->Seek(pos, SEEK_SET); + reader.Seek(pos, FileRdr::SeekSet); delete decoder; decoder = NULL; diff --git a/src/sound/i_sound.h b/src/sound/i_sound.h index 333eda2293..e92062d88c 100644 --- a/src/sound/i_sound.h +++ b/src/sound/i_sound.h @@ -38,7 +38,7 @@ #include "doomtype.h" #include "i_soundinternal.h" -class FileReader; +class FileRdr; enum ECodecType { @@ -118,7 +118,7 @@ public: // Streaming sounds. virtual SoundStream *CreateStream (SoundStreamCallback callback, int buffbytes, int flags, int samplerate, void *userdata) = 0; - virtual SoundStream *OpenStream (FileReader *reader, int flags) = 0; + virtual SoundStream *OpenStream (FileRdr &reader, int flags) = 0; // Starts a sound. virtual FISoundChannel *StartSound (SoundHandle sfx, float vol, int pitch, int chanflags, FISoundChannel *reuse_chan) = 0; @@ -168,7 +168,7 @@ public: virtual void DrawWaveDebug(int mode); - static SoundDecoder *CreateDecoder(FileReader *reader); + static SoundDecoder *CreateDecoder(FileRdr &reader); }; extern SoundRenderer *GSnd; diff --git a/src/sound/i_soundinternal.h b/src/sound/i_soundinternal.h index e1ae802902..39a478790d 100644 --- a/src/sound/i_soundinternal.h +++ b/src/sound/i_soundinternal.h @@ -7,7 +7,7 @@ #include "vectors.h" #include "tarray.h" -class FileReader; +class FileRdr; // For convenience, this structure matches FMOD_REVERB_PROPERTIES. // Since I can't very well #include system-specific stuff in the @@ -112,7 +112,7 @@ struct FISoundChannel }; -void FindLoopTags(FileReader *fr, uint32_t *start, bool *startass, uint32_t *end, bool *endass); +void FindLoopTags(FileRdr &fr, uint32_t *start, bool *startass, uint32_t *end, bool *endass); enum SampleType @@ -143,7 +143,7 @@ struct SoundDecoder virtual ~SoundDecoder() { } protected: - virtual bool open(FileReader *reader) = 0; + virtual bool open(FileRdr &reader) = 0; friend class SoundRenderer; private: diff --git a/src/sound/midisources/midisource_hmi.cpp b/src/sound/midisources/midisource_hmi.cpp index e0939de273..9029acb060 100644 --- a/src/sound/midisources/midisource_hmi.cpp +++ b/src/sound/midisources/midisource_hmi.cpp @@ -128,7 +128,7 @@ struct HMISong::TrackInfo HMISong::HMISong (FileRdr &reader) { - auto len = reader.GetLength(); + int len = (int)reader.GetLength(); if (len < 0x100) { // Way too small to be HMI. return; diff --git a/src/sound/mpg123_decoder.cpp b/src/sound/mpg123_decoder.cpp index f8d946429d..db3489aa06 100644 --- a/src/sound/mpg123_decoder.cpp +++ b/src/sound/mpg123_decoder.cpp @@ -74,28 +74,28 @@ static bool inited = false; off_t MPG123Decoder::file_lseek(void *handle, off_t offset, int whence) { - FileReader *reader = reinterpret_cast(handle)->Reader; + auto &reader = reinterpret_cast(handle)->Reader; if(whence == SEEK_CUR) { - if(offset < 0 && reader->Tell()+offset < 0) + if(offset < 0 && reader.Tell()+offset < 0) return -1; } else if(whence == SEEK_END) { - if(offset < 0 && reader->GetLength()+offset < 0) + if(offset < 0 && reader.GetLength()+offset < 0) return -1; } - if(reader->Seek(offset, whence) != 0) + if(reader.Seek(offset, (FileRdr::ESeek)whence) != 0) return -1; - return reader->Tell(); + return (off_t)reader.Tell(); } ssize_t MPG123Decoder::file_read(void *handle, void *buffer, size_t bytes) { - FileReader *reader = reinterpret_cast(handle)->Reader; - return (ssize_t)reader->Read(buffer, (long)bytes); + auto &reader = reinterpret_cast(handle)->Reader; + return (ssize_t)reader.Read(buffer, (long)bytes); } @@ -109,7 +109,7 @@ MPG123Decoder::~MPG123Decoder() } } -bool MPG123Decoder::open(FileReader *reader) +bool MPG123Decoder::open(FileRdr &reader) { if(!inited) { @@ -118,7 +118,7 @@ bool MPG123Decoder::open(FileReader *reader) inited = true; } - Reader = reader; + Reader = std::move(reader); { MPG123 = mpg123_new(NULL, NULL); @@ -214,8 +214,10 @@ bool MPG123Decoder::seek(size_t ms_offset, bool ms, bool mayrestart) mpg123_delete(MPG123); MPG123 = 0; } - Reader->Seek(0, SEEK_SET); - return open(Reader); + Reader.Seek(0, FileRdr::SeekSet); + // Do not call open with our own reader variable, that would be catastrophic. + auto reader = std::move(Reader); + return open(reader); } } size_t MPG123Decoder::getSampleOffset() diff --git a/src/sound/mpg123_decoder.h b/src/sound/mpg123_decoder.h index 02af11a165..e2b0701496 100644 --- a/src/sound/mpg123_decoder.h +++ b/src/sound/mpg123_decoder.h @@ -2,6 +2,7 @@ #define MPG123_DECODER_H #include "i_soundinternal.h" +#include "files.h" #ifdef HAVE_MPG123 @@ -29,13 +30,13 @@ struct MPG123Decoder : public SoundDecoder virtual ~MPG123Decoder(); protected: - virtual bool open(FileReader *reader); + virtual bool open(FileRdr &reader); private: mpg123_handle *MPG123; bool Done; - FileReader *Reader; + FileRdr Reader; static off_t file_lseek(void *handle, off_t offset, int whence); static ssize_t file_read(void *handle, void *buffer, size_t bytes); diff --git a/src/sound/musicformats/music_cd.cpp b/src/sound/musicformats/music_cd.cpp index 7d5a8e4a3e..8ad648c488 100644 --- a/src/sound/musicformats/music_cd.cpp +++ b/src/sound/musicformats/music_cd.cpp @@ -112,17 +112,17 @@ bool CDSong::IsPlaying () return m_Status != STATE_Stopped; } -CDDAFile::CDDAFile (FileReader &reader) +CDDAFile::CDDAFile (FileRdr &reader) : CDSong () { uint32_t chunk; uint16_t track; uint32_t discid; - long endpos = reader.Tell() + reader.GetLength() - 8; + auto endpos = reader.Tell() + reader.GetLength() - 8; // I_RegisterSong already identified this as a CDDA file, so we // just need to check the contents we're interested in. - reader.Seek(12, SEEK_CUR); + reader.Seek(12, FileRdr::SeekCur); while (reader.Tell() < endpos) { @@ -130,11 +130,11 @@ CDDAFile::CDDAFile (FileReader &reader) if (chunk != (('f')|(('m')<<8)|(('t')<<16)|((' ')<<24))) { reader.Read(&chunk, 4); - reader.Seek(chunk, SEEK_CUR); + reader.Seek(chunk, FileRdr::SeekCur); } else { - reader.Seek(6, SEEK_CUR); + reader.Seek(6, FileRdr::SeekCur); reader.Read(&track, 2); reader.Read(&discid, 4); diff --git a/src/sound/musicformats/music_dumb.cpp b/src/sound/musicformats/music_dumb.cpp index 7706ff9477..310f197ff3 100644 --- a/src/sound/musicformats/music_dumb.cpp +++ b/src/sound/musicformats/music_dumb.cpp @@ -550,7 +550,7 @@ static DUMBFILE_SYSTEM mem_dfs = { // //========================================================================== -DUMBFILE *dumb_read_allfile(dumbfile_mem_status *filestate, uint8_t *start, FileReader &reader, int lenhave, int lenfull) +DUMBFILE *dumb_read_allfile(dumbfile_mem_status *filestate, uint8_t *start, FileRdr &reader, int lenhave, int lenfull) { filestate->size = lenfull; filestate->offset = 0; @@ -765,7 +765,7 @@ static void MOD_SetAutoChip(DUH *duh) // //========================================================================== -MusInfo *MOD_OpenSong(FileReader &reader) +MusInfo *MOD_OpenSong(FileRdr &reader) { DUH *duh = 0; int headsize; @@ -776,7 +776,6 @@ MusInfo *MOD_OpenSong(FileReader &reader) }; dumbfile_mem_status filestate; DUMBFILE *f = NULL; - long fpos = 0; input_mod *state = NULL; bool is_it = false; @@ -784,8 +783,8 @@ MusInfo *MOD_OpenSong(FileReader &reader) atterm(dumb_exit); - int size = reader.GetLength(); - fpos = reader.Tell(); + int size = (int)reader.GetLength(); + auto fpos = reader.Tell(); filestate.ptr = start; filestate.offset = 0; @@ -903,7 +902,7 @@ MusInfo *MOD_OpenSong(FileReader &reader) { if (!(f = dumb_read_allfile(&filestate, start, reader, headsize, size))) { - reader.Seek(fpos, SEEK_SET); + reader.Seek(fpos, FileRdr::SeekSet); return NULL; } } @@ -944,7 +943,7 @@ MusInfo *MOD_OpenSong(FileReader &reader) else { // Reposition file pointer for other codecs to do their checks. - reader.Seek(fpos, SEEK_SET); + reader.Seek(fpos, FileRdr::SeekSet); } if (filestate.ptr != (uint8_t *)start) { diff --git a/src/sound/musicformats/music_gme.cpp b/src/sound/musicformats/music_gme.cpp index 88aeabcaba..06f7c99d7d 100644 --- a/src/sound/musicformats/music_gme.cpp +++ b/src/sound/musicformats/music_gme.cpp @@ -113,7 +113,7 @@ const char *GME_CheckFormat(uint32_t id) // //========================================================================== -MusInfo *GME_OpenSong(FileReader &reader, const char *fmt) +MusInfo *GME_OpenSong(FileRdr &reader, const char *fmt) { gme_type_t type; gme_err_t err; @@ -128,31 +128,31 @@ MusInfo *GME_OpenSong(FileReader &reader, const char *fmt) } sample_rate = (int)GSnd->GetOutputRate(); emu = gme_new_emu(type, sample_rate); - if (emu == NULL) + if (emu == nullptr) { - return NULL; + return nullptr; } - int fpos = reader.Tell(); - int len = reader.GetLength(); + auto fpos = reader.Tell(); + auto len = reader.GetLength(); song = new uint8_t[len]; if (reader.Read(song, len) != len) { delete[] song; gme_delete(emu); - reader.Seek(fpos, SEEK_SET); - return NULL; + reader.Seek(fpos, FileRdr::SeekSet); + return nullptr; } - err = gme_load_data(emu, song, len); + err = gme_load_data(emu, song, (long)len); delete[] song; - if (err != NULL) + if (err != nullptr) { Printf("Failed loading song: %s\n", err); gme_delete(emu); - reader.Seek(fpos, SEEK_SET); - return NULL; + reader.Seek(fpos, FileRdr::SeekSet); + return nullptr; } gme_set_stereo_depth(emu, clamp(*gme_stereodepth, 0.f, 1.f)); return new GMESong(emu, sample_rate); diff --git a/src/sound/musicformats/music_libsndfile.cpp b/src/sound/musicformats/music_libsndfile.cpp index af53ac37f0..d9a9c8f8b8 100644 --- a/src/sound/musicformats/music_libsndfile.cpp +++ b/src/sound/musicformats/music_libsndfile.cpp @@ -48,7 +48,7 @@ class SndFileSong : public StreamSong { public: - SndFileSong(FileReader *reader, SoundDecoder *decoder, uint32_t loop_start, uint32_t loop_end, bool startass, bool endass); + SndFileSong(FileRdr &reader, SoundDecoder *decoder, uint32_t loop_start, uint32_t loop_end, bool startass, bool endass); ~SndFileSong(); bool SetSubsong(int subsong); void Play(bool looping, int subsong); @@ -56,7 +56,7 @@ public: protected: FCriticalSection CritSec; - FileReader *Reader; + FileRdr Reader; SoundDecoder *Decoder; int Channels; int SampleRate; @@ -105,23 +105,23 @@ CUSTOM_CVAR(Int, snd_streambuffersize, 64, CVAR_ARCHIVE | CVAR_GLOBALCONFIG) // //========================================================================== -static void ParseVorbisComments(FileReader *fr, uint32_t *start, bool *startass, uint32_t *end, bool *endass) +static void ParseVorbisComments(FileRdr &fr, uint32_t *start, bool *startass, uint32_t *end, bool *endass) { uint8_t vc_data[4]; // The VC block starts with a 32LE integer for the vendor string length, // followed by the vendor string - if(fr->Read(vc_data, 4) != 4) + if(fr.Read(vc_data, 4) != 4) return; uint32_t vndr_len = vc_data[0] | (vc_data[1]<<8) | (vc_data[2]<<16) | (vc_data[3]<<24); // Skip vendor string - if(fr->Seek(vndr_len, SEEK_CUR) == -1) + if(fr.Seek(vndr_len, FileRdr::SeekCur) == -1) return; // Following the vendor string is a 32LE integer for the number of // comments, followed by each comment. - if(fr->Read(vc_data, 4) != 4) + if(fr.Read(vc_data, 4) != 4) return; size_t count = vc_data[0] | (vc_data[1]<<8) | (vc_data[2]<<16) | (vc_data[3]<<24); @@ -129,20 +129,20 @@ static void ParseVorbisComments(FileReader *fr, uint32_t *start, bool *startass, { // Each comment is a 32LE integer for the comment length, followed by // the comment text (not null terminated!) - if(fr->Read(vc_data, 4) != 4) + if(fr.Read(vc_data, 4) != 4) return; uint32_t length = vc_data[0] | (vc_data[1]<<8) | (vc_data[2]<<16) | (vc_data[3]<<24); if(length >= 128) { // If the comment is "big", skip it - if(fr->Seek(length, SEEK_CUR) == -1) + if(fr.Seek(length, FileRdr::SeekCur) == -1) return; continue; } char strdat[128]; - if(fr->Read(strdat, length) != (long)length) + if(fr.Read(strdat, length) != (long)length) return; strdat[length] = 0; @@ -153,13 +153,13 @@ static void ParseVorbisComments(FileReader *fr, uint32_t *start, bool *startass, } } -static void FindFlacComments(FileReader *fr, uint32_t *loop_start, bool *startass, uint32_t *loop_end, bool *endass) +static void FindFlacComments(FileRdr &fr, uint32_t *loop_start, bool *startass, uint32_t *loop_end, bool *endass) { // Already verified the fLaC marker, so we're 4 bytes into the file bool lastblock = false; uint8_t header[4]; - while(!lastblock && fr->Read(header, 4) == 4) + while(!lastblock && fr.Read(header, 4) == 4) { // The first byte of the block header contains the type and a flag // indicating the last metadata block @@ -175,18 +175,18 @@ static void FindFlacComments(FileReader *fr, uint32_t *loop_start, bool *startas return; } - if(fr->Seek(blocksize, SEEK_CUR) == -1) + if(fr.Seek(blocksize, FileRdr::SeekCur) == -1) break; } } -static void FindOggComments(FileReader *fr, uint32_t *loop_start, bool *startass, uint32_t *loop_end, bool *endass) +static void FindOggComments(FileRdr &fr, uint32_t *loop_start, bool *startass, uint32_t *loop_end, bool *endass) { uint8_t ogghead[27]; // We already read and verified the OggS marker, so skip the first 4 bytes // of the Ogg page header. - while(fr->Read(ogghead+4, 23) == 23) + while(fr.Read(ogghead+4, 23) == 23) { // The 19th byte of the Ogg header is a 32LE integer for the page // number, and the 27th is a uint8 for the number of segments in the @@ -199,7 +199,7 @@ static void FindOggComments(FileReader *fr, uint32_t *loop_start, bool *startass // each segment in the page. The page segment data follows contiguously // after. uint8_t segsizes[256]; - if(fr->Read(segsizes, ogg_segments) != ogg_segments) + if(fr.Read(segsizes, ogg_segments) != ogg_segments) break; // Find the segment with the Vorbis Comment packet (type 3) @@ -210,7 +210,7 @@ static void FindOggComments(FileReader *fr, uint32_t *loop_start, bool *startass if(segsize > 16) { uint8_t vorbhead[7]; - if(fr->Read(vorbhead, 7) != 7) + if(fr.Read(vorbhead, 7) != 7) return; if(vorbhead[0] == 3 && memcmp(vorbhead+1, "vorbis", 6) == 0) @@ -237,7 +237,7 @@ static void FindOggComments(FileReader *fr, uint32_t *loop_start, bool *startass segsize -= 7; } - if(fr->Seek(segsize, SEEK_CUR) == -1) + if(fr.Seek(segsize, FileRdr::SeekCur) == -1) return; } @@ -245,16 +245,16 @@ static void FindOggComments(FileReader *fr, uint32_t *loop_start, bool *startass if(ogg_pagenum >= 2) break; - if(fr->Read(ogghead, 4) != 4 || memcmp(ogghead, "OggS", 4) != 0) + if(fr.Read(ogghead, 4) != 4 || memcmp(ogghead, "OggS", 4) != 0) break; } } -void FindLoopTags(FileReader *fr, uint32_t *start, bool *startass, uint32_t *end, bool *endass) +void FindLoopTags(FileRdr &fr, uint32_t *start, bool *startass, uint32_t *end, bool *endass) { uint8_t signature[4]; - fr->Read(signature, 4); + fr.Read(signature, 4); if(memcmp(signature, "fLaC", 4) == 0) FindFlacComments(fr, start, startass, end, endass); else if(memcmp(signature, "OggS", 4) == 0) @@ -268,18 +268,18 @@ void FindLoopTags(FileReader *fr, uint32_t *start, bool *startass, uint32_t *end // //========================================================================== -MusInfo *SndFile_OpenSong(FileReader &fr) +MusInfo *SndFile_OpenSong(FileRdr &fr) { - fr.Seek(0, SEEK_SET); + fr.Seek(0, FileRdr::SeekSet); uint32_t loop_start = 0, loop_end = ~0u; bool startass = false, endass = false; - FindLoopTags(&fr, &loop_start, &startass, &loop_end, &endass); + FindLoopTags(fr, &loop_start, &startass, &loop_end, &endass); - fr.Seek(0, SEEK_SET); - auto decoder = SoundRenderer::CreateDecoder(&fr); + fr.Seek(0, FileRdr::SeekSet); + auto decoder = SoundRenderer::CreateDecoder(fr); if (decoder == nullptr) return nullptr; - return new SndFileSong(&fr, decoder, loop_start, loop_end, startass, endass); + return new SndFileSong(fr, decoder, loop_start, loop_end, startass, endass); } //========================================================================== @@ -288,7 +288,7 @@ MusInfo *SndFile_OpenSong(FileReader &fr) // //========================================================================== -SndFileSong::SndFileSong(FileReader *reader, SoundDecoder *decoder, uint32_t loop_start, uint32_t loop_end, bool startass, bool endass) +SndFileSong::SndFileSong(FileRdr &reader, SoundDecoder *decoder, uint32_t loop_start, uint32_t loop_end, bool startass, bool endass) { ChannelConfig iChannels; SampleType Type; @@ -300,7 +300,7 @@ SndFileSong::SndFileSong(FileReader *reader, SoundDecoder *decoder, uint32_t loo Loop_Start = loop_start; Loop_End = clamp(loop_end, 0, (uint32_t)decoder->getSampleLength()); - Reader = reader; + Reader = std::move(reader); Decoder = decoder; Channels = iChannels == ChannelConfig_Stereo? 2:1; m_Stream = GSnd->CreateStream(Read, snd_streambuffersize * 1024, iChannels == ChannelConfig_Stereo? 0 : SoundStream::Mono, SampleRate, this); @@ -324,10 +324,6 @@ SndFileSong::~SndFileSong() { delete Decoder; } - if (Reader != nullptr) - { - delete Reader; - } } diff --git a/src/sound/musicformats/music_opl.cpp b/src/sound/musicformats/music_opl.cpp index 64596c2fbe..518f76906d 100644 --- a/src/sound/musicformats/music_opl.cpp +++ b/src/sound/musicformats/music_opl.cpp @@ -69,12 +69,12 @@ void OPL_SetCore(const char *args) if (args != NULL && *args >= '0' && *args < '4') current_opl_core = *args - '0'; } -OPLMUSSong::OPLMUSSong (FileReader &reader, const char *args) +OPLMUSSong::OPLMUSSong (FileRdr &reader, const char *args) { int samples = int(OPL_SAMPLE_RATE / 14); OPL_SetCore(args); - Music = new OPLmusicFile (&reader); + Music = new OPLmusicFile (reader); m_Stream = GSnd->CreateStream (FillStream, samples*4, (current_opl_core == 0 ? SoundStream::Mono : 0) | SoundStream::Float, int(OPL_SAMPLE_RATE), this); diff --git a/src/sound/musicformats/music_stream.cpp b/src/sound/musicformats/music_stream.cpp index dbb5a85f22..019fd4125d 100644 --- a/src/sound/musicformats/music_stream.cpp +++ b/src/sound/musicformats/music_stream.cpp @@ -85,7 +85,7 @@ StreamSong::~StreamSong () } } -StreamSong::StreamSong (FileReader *reader) +StreamSong::StreamSong (FileRdr &reader) { m_Stream = GSnd->OpenStream (reader, SoundStream::Loop); } diff --git a/src/sound/oalsound.cpp b/src/sound/oalsound.cpp index d234b0b050..ac2d346e99 100644 --- a/src/sound/oalsound.cpp +++ b/src/sound/oalsound.cpp @@ -228,7 +228,7 @@ class OpenALSoundStream : public SoundStream ALfloat Volume; - FileReader *Reader; + FileRdr Reader; SoundDecoder *Decoder; static bool DecoderCallback(SoundStream *_sstream, void *ptr, int length, void *user) { @@ -317,7 +317,6 @@ public: getALError(); delete Decoder; - delete Reader; } @@ -604,17 +603,15 @@ public: return true; } - bool Init(FileReader *reader, bool loop) + bool Init(FileRdr &reader, bool loop) { if(!SetupSource()) { - delete reader; return false; } if(Decoder) delete Decoder; - if(Reader) delete Reader; - Reader = reader; + Reader = std::move(reader); Decoder = Renderer->CreateDecoder(Reader); if(!Decoder) return false; @@ -1279,7 +1276,7 @@ std::pair OpenALSoundRenderer::LoadSoundRaw(uint8_t *sfxdata, std::pair OpenALSoundRenderer::LoadSound(uint8_t *sfxdata, int length, bool monoize, FSoundLoadBuffer *pBuffer) { SoundHandle retval = { NULL }; - MemoryReader reader((const char*)sfxdata, length); + FileRdr reader; ALenum format = AL_NONE; ChannelConfig chans; SampleType type; @@ -1290,10 +1287,12 @@ std::pair OpenALSoundRenderer::LoadSound(uint8_t *sfxdata, int /* Only downmix to mono if we can't spatialize multi-channel sounds. */ monoize = monoize && !AL.SOFT_source_spatialize; - FindLoopTags(&reader, &loop_start, &startass, &loop_end, &endass); + reader.OpenMemory(sfxdata, length); - reader.Seek(0, SEEK_SET); - std::unique_ptr decoder(CreateDecoder(&reader)); + FindLoopTags(reader, &loop_start, &startass, &loop_end, &endass); + + reader.Seek(0, FileRdr::SeekSet); + std::unique_ptr decoder(CreateDecoder(reader)); if (!decoder) return std::make_pair(retval, true); decoder->getInfo(&srate, &chans, &type); @@ -1530,7 +1529,7 @@ SoundStream *OpenALSoundRenderer::CreateStream(SoundStreamCallback callback, int return stream; } -SoundStream *OpenALSoundRenderer::OpenStream(FileReader *reader, int flags) +SoundStream *OpenALSoundRenderer::OpenStream(FileRdr &reader, int flags) { if(StreamThread.get_id() == std::thread::id()) StreamThread = std::thread(std::mem_fn(&OpenALSoundRenderer::BackgroundProc), this); diff --git a/src/sound/oalsound.h b/src/sound/oalsound.h index 92d2235aa0..9369adf33d 100644 --- a/src/sound/oalsound.h +++ b/src/sound/oalsound.h @@ -136,7 +136,7 @@ public: // Streaming sounds. virtual SoundStream *CreateStream(SoundStreamCallback callback, int buffbytes, int flags, int samplerate, void *userdata); - virtual SoundStream *OpenStream(FileReader *reader, int flags); + virtual SoundStream *OpenStream(FileRdr &reader, int flags); // Starts a sound. virtual FISoundChannel *StartSound(SoundHandle sfx, float vol, int pitch, int chanflags, FISoundChannel *reuse_chan); diff --git a/src/sound/oplsynth/opl_mus_player.cpp b/src/sound/oplsynth/opl_mus_player.cpp index 6b70be34fc..8042a84d0a 100644 --- a/src/sound/oplsynth/opl_mus_player.cpp +++ b/src/sound/oplsynth/opl_mus_player.cpp @@ -84,8 +84,8 @@ void OPLmusicBlock::Restart() LastOffset = 0; } -OPLmusicFile::OPLmusicFile (FileReader *reader) - : ScoreLen (reader->GetLength()) +OPLmusicFile::OPLmusicFile (FileRdr &reader) + : ScoreLen ((int)reader.GetLength()) { if (io == NULL) { @@ -94,7 +94,7 @@ OPLmusicFile::OPLmusicFile (FileReader *reader) scoredata = new uint8_t[ScoreLen]; - if (reader->Read(scoredata, ScoreLen) != ScoreLen) + if (reader.Read(scoredata, ScoreLen) != ScoreLen) { fail: delete[] scoredata; scoredata = NULL; diff --git a/src/sound/oplsynth/opl_mus_player.h b/src/sound/oplsynth/opl_mus_player.h index 52ef4be764..26b4ab8023 100644 --- a/src/sound/oplsynth/opl_mus_player.h +++ b/src/sound/oplsynth/opl_mus_player.h @@ -1,7 +1,7 @@ #include "critsec.h" #include "musicblock.h" -class FileReader; +class FileRdr; class OPLmusicBlock : public musicBlock { @@ -34,7 +34,7 @@ protected: class OPLmusicFile : public OPLmusicBlock { public: - OPLmusicFile(FileReader *reader); + OPLmusicFile(FileRdr &reader); OPLmusicFile(const OPLmusicFile *source, const char *filename); virtual ~OPLmusicFile(); diff --git a/src/sound/sndfile_decoder.cpp b/src/sound/sndfile_decoder.cpp index 6fa5c5c075..07c7c81c31 100644 --- a/src/sound/sndfile_decoder.cpp +++ b/src/sound/sndfile_decoder.cpp @@ -72,23 +72,23 @@ bool IsSndFilePresent() sf_count_t SndFileDecoder::file_get_filelen(void *user_data) { - FileReader *reader = reinterpret_cast(user_data)->Reader; - return reader->GetLength(); + auto &reader = reinterpret_cast(user_data)->Reader; + return reader.GetLength(); } sf_count_t SndFileDecoder::file_seek(sf_count_t offset, int whence, void *user_data) { - FileReader *reader = reinterpret_cast(user_data)->Reader; + auto &reader = reinterpret_cast(user_data)->Reader; - if(reader->Seek((long)offset, whence) != 0) + if(reader.Seek((long)offset, (FileRdr::ESeek)whence) != 0) return -1; - return reader->Tell(); + return reader.Tell(); } sf_count_t SndFileDecoder::file_read(void *ptr, sf_count_t count, void *user_data) { - FileReader *reader = reinterpret_cast(user_data)->Reader; - return reader->Read(ptr, (long)count); + auto &reader = reinterpret_cast(user_data)->Reader; + return reader.Read(ptr, (long)count); } sf_count_t SndFileDecoder::file_write(const void *ptr, sf_count_t count, void *user_data) @@ -98,8 +98,8 @@ sf_count_t SndFileDecoder::file_write(const void *ptr, sf_count_t count, void *u sf_count_t SndFileDecoder::file_tell(void *user_data) { - FileReader *reader = reinterpret_cast(user_data)->Reader; - return reader->Tell(); + auto &reader = reinterpret_cast(user_data)->Reader; + return reader.Tell(); } @@ -110,13 +110,13 @@ SndFileDecoder::~SndFileDecoder() SndFile = 0; } -bool SndFileDecoder::open(FileReader *reader) +bool SndFileDecoder::open(FileRdr &reader) { if (!IsSndFilePresent()) return false; SF_VIRTUAL_IO sfio = { file_get_filelen, file_seek, file_read, file_write, file_tell }; - Reader = reader; + Reader = std::move(reader); SndInfo.format = 0; SndFile = sf_open_virtual(&sfio, SFM_READ, &SndInfo, this); if (SndFile) diff --git a/src/sound/sndfile_decoder.h b/src/sound/sndfile_decoder.h index 0d5c83a417..12087a5bff 100644 --- a/src/sound/sndfile_decoder.h +++ b/src/sound/sndfile_decoder.h @@ -2,6 +2,7 @@ #define SNDFILE_DECODER_H #include "i_soundinternal.h" +#include "files.h" #ifdef HAVE_SNDFILE @@ -25,13 +26,13 @@ struct SndFileDecoder : public SoundDecoder virtual ~SndFileDecoder(); protected: - virtual bool open(FileReader *reader); + virtual bool open(FileRdr &reader); private: SNDFILE *SndFile; SF_INFO SndInfo; - FileReader *Reader; + FileRdr Reader; static sf_count_t file_get_filelen(void *user_data); static sf_count_t file_seek(sf_count_t offset, int whence, void *user_data); static sf_count_t file_read(void *ptr, sf_count_t count, void *user_data); diff --git a/src/swrenderer/r_swcolormaps.cpp b/src/swrenderer/r_swcolormaps.cpp index 318ccead22..13c66706b3 100644 --- a/src/swrenderer/r_swcolormaps.cpp +++ b/src/swrenderer/r_swcolormaps.cpp @@ -366,7 +366,7 @@ void SetDefaultColormap (const char *name) } else { - FWadLump lumpr = Wads.OpenLumpNum (lump); + auto lumpr = Wads.OpenLumpReader (lump); // [RH] The colormap may not have been designed for the specific // palette we are using, so remap it to match the current palette. @@ -427,7 +427,7 @@ static void InitBoomColormaps () if (Wads.LumpLength (fakecmaps[j].lump) >= (NUMCOLORMAPS+1)*256) { int k, r; - FWadLump lump = Wads.OpenLumpNum (fakecmaps[j].lump); + auto lump = Wads.OpenLumpReader (fakecmaps[j].lump); uint8_t *const map = realcolormaps.Maps + NUMCOLORMAPS*256*j; for (k = 0; k < NUMCOLORMAPS; ++k) diff --git a/src/textures/automaptexture.cpp b/src/textures/automaptexture.cpp index 3bd16f5bca..1f17b239ae 100644 --- a/src/textures/automaptexture.cpp +++ b/src/textures/automaptexture.cpp @@ -72,7 +72,7 @@ private: // //========================================================================== -FTexture *AutomapTexture_TryCreate(FileReader &data, int lumpnum) +FTexture *AutomapTexture_TryCreate(FileRdr &data, int lumpnum) { if (data.GetLength() < 320) return NULL; if (!Wads.CheckLumpName(lumpnum, "AUTOPAGE")) return NULL; diff --git a/src/textures/ddstexture.cpp b/src/textures/ddstexture.cpp index e340d4e81a..e3b645424b 100644 --- a/src/textures/ddstexture.cpp +++ b/src/textures/ddstexture.cpp @@ -156,7 +156,7 @@ struct DDSFileHeader class FDDSTexture : public FTexture { public: - FDDSTexture (FileReader &lump, int lumpnum, void *surfdesc); + FDDSTexture (FileRdr &lump, int lumpnum, void *surfdesc); ~FDDSTexture (); const uint8_t *GetColumn (unsigned int column, const Span **spans_out); @@ -181,10 +181,10 @@ protected: static void CalcBitShift (uint32_t mask, uint8_t *lshift, uint8_t *rshift); void MakeTexture (); - void ReadRGB (FWadLump &lump, uint8_t *tcbuf = NULL); - void DecompressDXT1 (FWadLump &lump, uint8_t *tcbuf = NULL); - void DecompressDXT3 (FWadLump &lump, bool premultiplied, uint8_t *tcbuf = NULL); - void DecompressDXT5 (FWadLump &lump, bool premultiplied, uint8_t *tcbuf = NULL); + void ReadRGB (FileRdr &lump, uint8_t *tcbuf = NULL); + void DecompressDXT1 (FileRdr &lump, uint8_t *tcbuf = NULL); + void DecompressDXT3 (FileRdr &lump, bool premultiplied, uint8_t *tcbuf = NULL); + void DecompressDXT5 (FileRdr &lump, bool premultiplied, uint8_t *tcbuf = NULL); int CopyTrueColorPixels(FBitmap *bmp, int x, int y, int rotate, FCopyInfo *inf = NULL); bool UseBasePalette(); @@ -199,11 +199,11 @@ protected: // //========================================================================== -static bool CheckDDS (FileReader &file) +static bool CheckDDS (FileRdr &file) { DDSFileHeader Header; - file.Seek (0, SEEK_SET); + file.Seek(0, FileRdr::SeekSet); if (file.Read (&Header, sizeof(Header)) != sizeof(Header)) { return false; @@ -222,7 +222,7 @@ static bool CheckDDS (FileReader &file) // //========================================================================== -FTexture *DDSTexture_TryCreate (FileReader &data, int lumpnum) +FTexture *DDSTexture_TryCreate (FileRdr &data, int lumpnum) { union { @@ -232,7 +232,7 @@ FTexture *DDSTexture_TryCreate (FileReader &data, int lumpnum) if (!CheckDDS(data)) return NULL; - data.Seek (4, SEEK_SET); + data.Seek(4, FileRdr::SeekSet); data.Read (&surfdesc, sizeof(surfdesc)); #ifdef __BIG_ENDIAN__ @@ -286,7 +286,7 @@ FTexture *DDSTexture_TryCreate (FileReader &data, int lumpnum) // //========================================================================== -FDDSTexture::FDDSTexture (FileReader &lump, int lumpnum, void *vsurfdesc) +FDDSTexture::FDDSTexture (FileRdr &lump, int lumpnum, void *vsurfdesc) : FTexture(NULL, lumpnum), Pixels(0), Spans(0) { DDSURFACEDESC2 *surf = (DDSURFACEDESC2 *)vsurfdesc; @@ -488,11 +488,11 @@ const uint8_t *FDDSTexture::GetPixels () void FDDSTexture::MakeTexture () { - FWadLump lump = Wads.OpenLumpNum (SourceLump); + auto lump = Wads.OpenLumpReader (SourceLump); Pixels = new uint8_t[Width*Height]; - lump.Seek (sizeof(DDSURFACEDESC2) + 4, SEEK_SET); + lump.Seek (sizeof(DDSURFACEDESC2) + 4, FileRdr::SeekSet); if (Format >= 1 && Format <= 4) // RGB: Format is # of bytes per pixel { @@ -518,7 +518,7 @@ void FDDSTexture::MakeTexture () // //========================================================================== -void FDDSTexture::ReadRGB (FWadLump &lump, uint8_t *tcbuf) +void FDDSTexture::ReadRGB (FileRdr &lump, uint8_t *tcbuf) { uint32_t x, y; uint32_t amask = AMask == 0 ? 0 : 0x80000000 >> AShiftL; @@ -587,7 +587,7 @@ void FDDSTexture::ReadRGB (FWadLump &lump, uint8_t *tcbuf) // //========================================================================== -void FDDSTexture::DecompressDXT1 (FWadLump &lump, uint8_t *tcbuf) +void FDDSTexture::DecompressDXT1 (FileRdr &lump, uint8_t *tcbuf) { const long blocklinelen = ((Width + 3) >> 2) << 3; uint8_t *blockbuff = new uint8_t[blocklinelen]; @@ -685,7 +685,7 @@ void FDDSTexture::DecompressDXT1 (FWadLump &lump, uint8_t *tcbuf) // //========================================================================== -void FDDSTexture::DecompressDXT3 (FWadLump &lump, bool premultiplied, uint8_t *tcbuf) +void FDDSTexture::DecompressDXT3 (FileRdr &lump, bool premultiplied, uint8_t *tcbuf) { const long blocklinelen = ((Width + 3) >> 2) << 4; uint8_t *blockbuff = new uint8_t[blocklinelen]; @@ -767,7 +767,7 @@ void FDDSTexture::DecompressDXT3 (FWadLump &lump, bool premultiplied, uint8_t *t // //========================================================================== -void FDDSTexture::DecompressDXT5 (FWadLump &lump, bool premultiplied, uint8_t *tcbuf) +void FDDSTexture::DecompressDXT5 (FileRdr &lump, bool premultiplied, uint8_t *tcbuf) { const long blocklinelen = ((Width + 3) >> 2) << 4; uint8_t *blockbuff = new uint8_t[blocklinelen]; @@ -881,11 +881,11 @@ void FDDSTexture::DecompressDXT5 (FWadLump &lump, bool premultiplied, uint8_t *t int FDDSTexture::CopyTrueColorPixels(FBitmap *bmp, int x, int y, int rotate, FCopyInfo *inf) { - FWadLump lump = Wads.OpenLumpNum (SourceLump); + auto lump = Wads.OpenLumpReader (SourceLump); uint8_t *TexBuffer = new uint8_t[4*Width*Height]; - lump.Seek (sizeof(DDSURFACEDESC2) + 4, SEEK_SET); + lump.Seek (sizeof(DDSURFACEDESC2) + 4, FileRdr::SeekSet); if (Format >= 1 && Format <= 4) // RGB: Format is # of bytes per pixel { diff --git a/src/textures/emptytexture.cpp b/src/textures/emptytexture.cpp index 7013809930..ce72656584 100644 --- a/src/textures/emptytexture.cpp +++ b/src/textures/emptytexture.cpp @@ -68,11 +68,11 @@ protected: // //========================================================================== -FTexture *EmptyTexture_TryCreate(FileReader & file, int lumpnum) +FTexture *EmptyTexture_TryCreate(FileRdr & file, int lumpnum) { char check[8]; if (file.GetLength() != 8) return NULL; - file.Seek(0, SEEK_SET); + file.Seek(0, FileRdr::SeekSet); if (file.Read(check, 8) != 8) return NULL; if (memcmp(check, "\0\0\0\0\0\0\0\0", 8)) return NULL; diff --git a/src/textures/flattexture.cpp b/src/textures/flattexture.cpp index 6e584f6948..18105c947a 100644 --- a/src/textures/flattexture.cpp +++ b/src/textures/flattexture.cpp @@ -74,7 +74,7 @@ protected: // //========================================================================== -FTexture *FlatTexture_TryCreate(FileReader & file, int lumpnum) +FTexture *FlatTexture_TryCreate(FileRdr & file, int lumpnum) { return new FFlatTexture(lumpnum); } @@ -194,9 +194,9 @@ const uint8_t *FFlatTexture::GetPixels () void FFlatTexture::MakeTexture () { - FWadLump lump = Wads.OpenLumpNum (SourceLump); + auto lump = Wads.OpenLumpReader (SourceLump); Pixels = new uint8_t[Width*Height]; - long numread = lump.Read (Pixels, Width*Height); + auto numread = lump.Read (Pixels, Width*Height); if (numread < Width*Height) { memset (Pixels + numread, 0xBB, Width*Height - numread); diff --git a/src/textures/imgztexture.cpp b/src/textures/imgztexture.cpp index 1689289d09..edd15b15ac 100644 --- a/src/textures/imgztexture.cpp +++ b/src/textures/imgztexture.cpp @@ -83,13 +83,13 @@ protected: // //========================================================================== -FTexture *IMGZTexture_TryCreate(FileReader & file, int lumpnum) +FTexture *IMGZTexture_TryCreate(FileRdr & file, int lumpnum) { uint32_t magic = 0; uint16_t w, h; int16_t l, t; - file.Seek(0, SEEK_SET); + file.Seek(0, FileRdr::SeekSet); if (file.Read(&magic, 4) != 4) return NULL; if (magic != MAKE_ID('I','M','G','Z')) return NULL; file >> w >> h >> l >> t; diff --git a/src/textures/jpegtexture.cpp b/src/textures/jpegtexture.cpp index 02bb828294..f8bc836146 100644 --- a/src/textures/jpegtexture.cpp +++ b/src/textures/jpegtexture.cpp @@ -50,11 +50,11 @@ extern "C" struct FLumpSourceMgr : public jpeg_source_mgr { - FileReader *Lump; + FileRdr *Lump; JOCTET Buffer[4096]; bool StartOfFile; - FLumpSourceMgr (FileReader *lump, j_decompress_ptr cinfo); + FLumpSourceMgr (FileRdr *lump, j_decompress_ptr cinfo); static void InitSource (j_decompress_ptr cinfo); static boolean FillInputBuffer (j_decompress_ptr cinfo); static void SkipInputData (j_decompress_ptr cinfo, long num_bytes); @@ -82,7 +82,7 @@ void FLumpSourceMgr::InitSource (j_decompress_ptr cinfo) boolean FLumpSourceMgr::FillInputBuffer (j_decompress_ptr cinfo) { FLumpSourceMgr *me = (FLumpSourceMgr *)(cinfo->src); - long nbytes = me->Lump->Read (me->Buffer, sizeof(me->Buffer)); + auto nbytes = me->Lump->Read (me->Buffer, sizeof(me->Buffer)); if (nbytes <= 0) { @@ -113,7 +113,7 @@ void FLumpSourceMgr::SkipInputData (j_decompress_ptr cinfo, long num_bytes) else { num_bytes -= (long)me->bytes_in_buffer; - me->Lump->Seek (num_bytes, SEEK_CUR); + me->Lump->Seek (num_bytes, FileRdr::SeekCur); FillInputBuffer (cinfo); } } @@ -134,7 +134,7 @@ void FLumpSourceMgr::TermSource (j_decompress_ptr cinfo) // //========================================================================== -FLumpSourceMgr::FLumpSourceMgr (FileReader *lump, j_decompress_ptr cinfo) +FLumpSourceMgr::FLumpSourceMgr (FileRdr *lump, j_decompress_ptr cinfo) : Lump (lump) { cinfo->src = this; @@ -208,7 +208,7 @@ protected: // //========================================================================== -FTexture *JPEGTexture_TryCreate(FileReader & data, int lumpnum) +FTexture *JPEGTexture_TryCreate(FileRdr & data, int lumpnum) { union { @@ -217,7 +217,7 @@ FTexture *JPEGTexture_TryCreate(FileReader & data, int lumpnum) uint8_t b[4]; } first4bytes; - data.Seek(0, SEEK_SET); + data.Seek(0, FileRdr::SeekSet); if (data.Read(&first4bytes, 4) < 4) return NULL; if (first4bytes.b[0] != 0xFF || first4bytes.b[1] != 0xD8 || first4bytes.b[2] != 0xFF) @@ -231,7 +231,7 @@ FTexture *JPEGTexture_TryCreate(FileReader & data, int lumpnum) { return NULL; } - data.Seek (BigShort(first4bytes.w[0]) - 2, SEEK_CUR); + data.Seek (BigShort(first4bytes.w[0]) - 2, FileRdr::SeekCur); if (data.Read (first4bytes.b + 2, 2) != 2 || first4bytes.b[2] != 0xFF) { return NULL; @@ -364,7 +364,7 @@ const uint8_t *FJPEGTexture::GetPixels () void FJPEGTexture::MakeTexture () { - FWadLump lump = Wads.OpenLumpNum (SourceLump); + auto lump = Wads.OpenLumpReader (SourceLump); JSAMPLE *buff = NULL; jpeg_decompress_struct cinfo; @@ -468,7 +468,7 @@ int FJPEGTexture::CopyTrueColorPixels(FBitmap *bmp, int x, int y, int rotate, FC { PalEntry pe[256]; - FWadLump lump = Wads.OpenLumpNum (SourceLump); + auto lump = Wads.OpenLumpReader (SourceLump); JSAMPLE *buff = NULL; jpeg_decompress_struct cinfo; diff --git a/src/textures/multipatchtexture.cpp b/src/textures/multipatchtexture.cpp index 46b652e297..b00bd16067 100644 --- a/src/textures/multipatchtexture.cpp +++ b/src/textures/multipatchtexture.cpp @@ -814,7 +814,7 @@ void FTextureManager::AddTexturesLump (const void *lumpdata, int lumpsize, int d } { - FWadLump pnames = Wads.OpenLumpNum (patcheslump); + auto pnames = Wads.OpenLumpReader (patcheslump); pnames >> numpatches; diff --git a/src/textures/patchtexture.cpp b/src/textures/patchtexture.cpp index 2393357bd5..49769213fc 100644 --- a/src/textures/patchtexture.cpp +++ b/src/textures/patchtexture.cpp @@ -81,12 +81,12 @@ protected: // //========================================================================== -static bool CheckIfPatch(FileReader & file) +static bool CheckIfPatch(FileRdr & file) { if (file.GetLength() < 13) return false; // minimum length of a valid Doom patch uint8_t *data = new uint8_t[file.GetLength()]; - file.Seek(0, SEEK_SET); + file.Seek(0, FileRdr::SeekSet); file.Read(data, file.GetLength()); const patch_t *foo = (const patch_t *)data; @@ -129,12 +129,12 @@ static bool CheckIfPatch(FileReader & file) // //========================================================================== -FTexture *PatchTexture_TryCreate(FileReader & file, int lumpnum) +FTexture *PatchTexture_TryCreate(FileRdr & file, int lumpnum) { patch_t header; if (!CheckIfPatch(file)) return NULL; - file.Seek(0, SEEK_SET); + file.Seek(0, FileRdr::SeekSet); file >> header.width >> header.height >> header.leftoffset >> header.topoffset; return new FPatchTexture(lumpnum, &header); } diff --git a/src/textures/pcxtexture.cpp b/src/textures/pcxtexture.cpp index 757877b035..609188b210 100644 --- a/src/textures/pcxtexture.cpp +++ b/src/textures/pcxtexture.cpp @@ -99,10 +99,10 @@ protected: uint8_t *Pixels; Span DummySpans[2]; - void ReadPCX1bit (uint8_t *dst, FileReader & lump, PCXHeader *hdr); - void ReadPCX4bits (uint8_t *dst, FileReader & lump, PCXHeader *hdr); - void ReadPCX8bits (uint8_t *dst, FileReader & lump, PCXHeader *hdr); - void ReadPCX24bits (uint8_t *dst, FileReader & lump, PCXHeader *hdr, int planes); + void ReadPCX1bit (uint8_t *dst, FileRdr & lump, PCXHeader *hdr); + void ReadPCX4bits (uint8_t *dst, FileRdr & lump, PCXHeader *hdr); + void ReadPCX8bits (uint8_t *dst, FileRdr & lump, PCXHeader *hdr); + void ReadPCX24bits (uint8_t *dst, FileRdr & lump, PCXHeader *hdr, int planes); virtual void MakeTexture (); @@ -116,11 +116,11 @@ protected: // //========================================================================== -FTexture * PCXTexture_TryCreate(FileReader & file, int lumpnum) +FTexture * PCXTexture_TryCreate(FileRdr & file, int lumpnum) { PCXHeader hdr; - file.Seek(0, SEEK_SET); + file.Seek(0, FileRdr::SeekSet); if (file.Read(&hdr, sizeof(hdr)) != sizeof(hdr)) { return NULL; @@ -141,7 +141,7 @@ FTexture * PCXTexture_TryCreate(FileReader & file, int lumpnum) if (hdr.padding[i] != 0) return NULL; } - file.Seek(0, SEEK_SET); + file.Seek(0, FileRdr::SeekSet); file.Read(&hdr, sizeof(hdr)); return new FPCXTexture(lumpnum, hdr); @@ -256,7 +256,7 @@ const uint8_t *FPCXTexture::GetPixels () // //========================================================================== -void FPCXTexture::ReadPCX1bit (uint8_t *dst, FileReader & lump, PCXHeader *hdr) +void FPCXTexture::ReadPCX1bit (uint8_t *dst, FileRdr & lump, PCXHeader *hdr) { int y, i, bytes; int rle_count = 0; @@ -304,7 +304,7 @@ void FPCXTexture::ReadPCX1bit (uint8_t *dst, FileReader & lump, PCXHeader *hdr) // //========================================================================== -void FPCXTexture::ReadPCX4bits (uint8_t *dst, FileReader & lump, PCXHeader *hdr) +void FPCXTexture::ReadPCX4bits (uint8_t *dst, FileRdr & lump, PCXHeader *hdr) { int rle_count = 0, rle_value = 0; int x, y, c; @@ -367,7 +367,7 @@ void FPCXTexture::ReadPCX4bits (uint8_t *dst, FileReader & lump, PCXHeader *hdr) // //========================================================================== -void FPCXTexture::ReadPCX8bits (uint8_t *dst, FileReader & lump, PCXHeader *hdr) +void FPCXTexture::ReadPCX8bits (uint8_t *dst, FileRdr & lump, PCXHeader *hdr) { int rle_count = 0, rle_value = 0; int y, bytes; @@ -409,7 +409,7 @@ void FPCXTexture::ReadPCX8bits (uint8_t *dst, FileReader & lump, PCXHeader *hdr) // //========================================================================== -void FPCXTexture::ReadPCX24bits (uint8_t *dst, FileReader & lump, PCXHeader *hdr, int planes) +void FPCXTexture::ReadPCX24bits (uint8_t *dst, FileRdr & lump, PCXHeader *hdr, int planes) { int rle_count = 0, rle_value = 0; int y, c; @@ -463,7 +463,7 @@ void FPCXTexture::MakeTexture() PCXHeader header; int bitcount; - FWadLump lump = Wads.OpenLumpNum(SourceLump); + auto lump = Wads.OpenLumpReader(SourceLump); lump.Read(&header, sizeof(header)); @@ -494,7 +494,7 @@ void FPCXTexture::MakeTexture() else if (bitcount == 8) { uint8_t c; - lump.Seek(-769, SEEK_END); + lump.Seek(-769, FileRdr::SeekEnd); lump >> c; //if (c !=0x0c) memcpy(PaletteMap, GrayMap, 256); // Fallback for files without palette //else @@ -504,7 +504,7 @@ void FPCXTexture::MakeTexture() lump >> r >> g >> b; PaletteMap[i] = ColorMatcher.Pick(r,g,b); } - lump.Seek(sizeof(header), SEEK_SET); + lump.Seek(sizeof(header), FileRdr::SeekSet); ReadPCX8bits (Pixels, lump, &header); } if (Width == Height) @@ -552,7 +552,7 @@ int FPCXTexture::CopyTrueColorPixels(FBitmap *bmp, int x, int y, int rotate, FCo int bitcount; uint8_t * Pixels; - FWadLump lump = Wads.OpenLumpNum(SourceLump); + auto lump = Wads.OpenLumpReader(SourceLump); lump.Read(&header, sizeof(header)); @@ -583,7 +583,7 @@ int FPCXTexture::CopyTrueColorPixels(FBitmap *bmp, int x, int y, int rotate, FCo else if (bitcount == 8) { uint8_t c; - lump.Seek(-769, SEEK_END); + lump.Seek(-769, FileRdr::SeekEnd); lump >> c; c=0x0c; // Apparently there's many non-compliant PCXs out there... if (c !=0x0c) @@ -596,7 +596,7 @@ int FPCXTexture::CopyTrueColorPixels(FBitmap *bmp, int x, int y, int rotate, FCo lump >> r >> g >> b; pe[i] = PalEntry(255, r,g,b); } - lump.Seek(sizeof(header), SEEK_SET); + lump.Seek(sizeof(header), FileRdr::SeekSet); ReadPCX8bits (Pixels, lump, &header); } bmp->CopyPixelData(x, y, Pixels, Width, Height, 1, Width, rotate, pe, inf); diff --git a/src/textures/pngtexture.cpp b/src/textures/pngtexture.cpp index 63948bceaa..7ca1a32c67 100644 --- a/src/textures/pngtexture.cpp +++ b/src/textures/pngtexture.cpp @@ -90,7 +90,7 @@ protected: // //========================================================================== -FTexture *PNGTexture_TryCreate(FileReader & data, int lumpnum) +FTexture *PNGTexture_TryCreate(FileRdr & data, int lumpnum) { union { @@ -106,7 +106,7 @@ FTexture *PNGTexture_TryCreate(FileReader & data, int lumpnum) // first 4 bytes match, but later bytes don't, we assume it's // a corrupt PNG.) - data.Seek(0, SEEK_SET); + data.Seek(0, FileRdr::SeekSet); if (data.Read (first4bytes.b, 4) != 4) return NULL; if (first4bytes.dw != MAKE_ID(137,'P','N','G')) return NULL; if (data.Read (first4bytes.b, 4) != 4) return NULL; @@ -136,7 +136,7 @@ FTexture *PNGTexture_TryCreate(FileReader & data, int lumpnum) } // Just for completeness, make sure the PNG has something more than an IHDR. - data.Seek (4, SEEK_CUR); + data.Seek (4, FileRdr::SeekSet); data.Read (first4bytes.b, 4); if (first4bytes.dw == 0) { @@ -147,7 +147,7 @@ FTexture *PNGTexture_TryCreate(FileReader & data, int lumpnum) } } - return new FPNGTexture (data, lumpnum, FString(), BigLong((int)width), BigLong((int)height), + return new FPNGTexture (*data.Reader(), lumpnum, FString(), BigLong((int)width), BigLong((int)height), bitdepth, colortype, interlace); } diff --git a/src/textures/rawpagetexture.cpp b/src/textures/rawpagetexture.cpp index bdcebbbafb..834a4c7ab4 100644 --- a/src/textures/rawpagetexture.cpp +++ b/src/textures/rawpagetexture.cpp @@ -70,7 +70,7 @@ protected: // //========================================================================== -static bool CheckIfRaw(FileReader & data) +static bool CheckIfRaw(FileRdr & data) { if (data.GetLength() != 64000) return false; @@ -80,7 +80,7 @@ static bool CheckIfRaw(FileReader & data) int width; foo = (patch_t *)M_Malloc (data.GetLength()); - data.Seek (0, SEEK_SET); + data.Seek (0, FileRdr::SeekSet); data.Read (foo, data.GetLength()); height = LittleShort(foo->height); @@ -148,7 +148,7 @@ static bool CheckIfRaw(FileReader & data) // //========================================================================== -FTexture *RawPageTexture_TryCreate(FileReader & file, int lumpnum) +FTexture *RawPageTexture_TryCreate(FileRdr & file, int lumpnum) { if (!CheckIfRaw(file)) return NULL; return new FRawPageTexture(lumpnum); diff --git a/src/textures/texture.cpp b/src/textures/texture.cpp index b446c43c60..165518098c 100644 --- a/src/textures/texture.cpp +++ b/src/textures/texture.cpp @@ -48,7 +48,7 @@ #include "v_palette.h" typedef bool (*CheckFunc)(FileReader & file); -typedef FTexture * (*CreateFunc)(FileReader & file, int lumpnum); +typedef FTexture * (*CreateFunc)(FileRdr & file, int lumpnum); struct TexCreateInfo { @@ -66,17 +66,17 @@ void FTexture::InitGrayMap() } } -FTexture *IMGZTexture_TryCreate(FileReader &, int lumpnum); -FTexture *PNGTexture_TryCreate(FileReader &, int lumpnum); -FTexture *JPEGTexture_TryCreate(FileReader &, int lumpnum); -FTexture *DDSTexture_TryCreate(FileReader &, int lumpnum); -FTexture *PCXTexture_TryCreate(FileReader &, int lumpnum); -FTexture *TGATexture_TryCreate(FileReader &, int lumpnum); -FTexture *RawPageTexture_TryCreate(FileReader &, int lumpnum); -FTexture *FlatTexture_TryCreate(FileReader &, int lumpnum); -FTexture *PatchTexture_TryCreate(FileReader &, int lumpnum); -FTexture *EmptyTexture_TryCreate(FileReader &, int lumpnum); -FTexture *AutomapTexture_TryCreate(FileReader &, int lumpnum); +FTexture *IMGZTexture_TryCreate(FileRdr &, int lumpnum); +FTexture *PNGTexture_TryCreate(FileRdr &, int lumpnum); +FTexture *JPEGTexture_TryCreate(FileRdr &, int lumpnum); +FTexture *DDSTexture_TryCreate(FileRdr &, int lumpnum); +FTexture *PCXTexture_TryCreate(FileRdr &, int lumpnum); +FTexture *TGATexture_TryCreate(FileRdr &, int lumpnum); +FTexture *RawPageTexture_TryCreate(FileRdr &, int lumpnum); +FTexture *FlatTexture_TryCreate(FileRdr &, int lumpnum); +FTexture *PatchTexture_TryCreate(FileRdr &, int lumpnum); +FTexture *EmptyTexture_TryCreate(FileRdr &, int lumpnum); +FTexture *AutomapTexture_TryCreate(FileRdr &, int lumpnum); // Examines the lump contents to decide what type of texture to create, @@ -99,7 +99,7 @@ FTexture * FTexture::CreateTexture (int lumpnum, int usetype) if (lumpnum == -1) return NULL; - FWadLump data = Wads.OpenLumpNum (lumpnum); + auto data = Wads.OpenLumpReader (lumpnum); for(size_t i = 0; i < countof(CreateInfo); i++) { diff --git a/src/textures/texturemanager.cpp b/src/textures/texturemanager.cpp index 613aa3be9f..ad3eb0b9a5 100644 --- a/src/textures/texturemanager.cpp +++ b/src/textures/texturemanager.cpp @@ -764,16 +764,16 @@ void FTextureManager::LoadTextureDefs(int wadnum, const char *lumpname) void FTextureManager::AddPatches (int lumpnum) { - FWadLump *file = Wads.ReopenLumpNum (lumpnum); + auto file = Wads.ReopenLumpReader (lumpnum, true); uint32_t numpatches, i; char name[9]; - *file >> numpatches; + file >> numpatches; name[8] = '\0'; for (i = 0; i < numpatches; ++i) { - file->Read (name, 8); + file.Read (name, 8); if (CheckForTexture (name, FTexture::TEX_WallPatch, 0) == -1) { @@ -781,8 +781,6 @@ void FTextureManager::AddPatches (int lumpnum) } StartScreen->Progress(); } - - delete file; } @@ -1187,7 +1185,7 @@ int FTextureManager::CountLumpTextures (int lumpnum) { if (lumpnum >= 0) { - FWadLump file = Wads.OpenLumpNum (lumpnum); + auto file = Wads.OpenLumpReader (lumpnum); uint32_t numtex; file >> numtex; diff --git a/src/textures/tgatexture.cpp b/src/textures/tgatexture.cpp index 702da82b1e..23e9b4315f 100644 --- a/src/textures/tgatexture.cpp +++ b/src/textures/tgatexture.cpp @@ -94,7 +94,7 @@ protected: uint8_t *Pixels; Span **Spans; - void ReadCompressed(FileReader &lump, uint8_t * buffer, int bytesperpixel); + void ReadCompressed(FileRdr &lump, uint8_t * buffer, int bytesperpixel); virtual void MakeTexture (); @@ -107,13 +107,13 @@ protected: // //========================================================================== -FTexture *TGATexture_TryCreate(FileReader & file, int lumpnum) +FTexture *TGATexture_TryCreate(FileRdr & file, int lumpnum) { TGAHeader hdr; if (file.GetLength() < (long)sizeof(hdr)) return NULL; - file.Seek(0, SEEK_SET); + file.Seek(0, FileRdr::SeekSet); file.Read(&hdr, sizeof(hdr)); hdr.width = LittleShort(hdr.width); hdr.height = LittleShort(hdr.height); @@ -127,7 +127,7 @@ FTexture *TGATexture_TryCreate(FileReader & file, int lumpnum) if (hdr.img_type >=4 && hdr.img_type <= 8) return NULL; if ((hdr.img_desc & 16) != 0) return NULL; - file.Seek(0, SEEK_SET); + file.Seek(0, FileRdr::SeekSet); file.Read(&hdr, sizeof(hdr)); hdr.width = LittleShort(hdr.width); hdr.height = LittleShort(hdr.height); @@ -250,7 +250,7 @@ const uint8_t *FTGATexture::GetPixels () // //========================================================================== -void FTGATexture::ReadCompressed(FileReader &lump, uint8_t * buffer, int bytesperpixel) +void FTGATexture::ReadCompressed(FileRdr &lump, uint8_t * buffer, int bytesperpixel) { uint8_t b; uint8_t data[4]; @@ -290,7 +290,7 @@ void FTGATexture::ReadCompressed(FileReader &lump, uint8_t * buffer, int bytespe void FTGATexture::MakeTexture () { uint8_t PaletteMap[256]; - FWadLump lump = Wads.OpenLumpNum (SourceLump); + auto lump = Wads.OpenLumpReader (SourceLump); TGAHeader hdr; uint16_t w; uint8_t r,g,b,a; @@ -298,7 +298,7 @@ void FTGATexture::MakeTexture () Pixels = new uint8_t[Width*Height]; lump.Read(&hdr, sizeof(hdr)); - lump.Seek(hdr.id_len, SEEK_CUR); + lump.Seek(hdr.id_len, FileRdr::SeekCur); hdr.width = LittleShort(hdr.width); hdr.height = LittleShort(hdr.height); @@ -491,7 +491,7 @@ void FTGATexture::MakeTexture () int FTGATexture::CopyTrueColorPixels(FBitmap *bmp, int x, int y, int rotate, FCopyInfo *inf) { PalEntry pe[256]; - FWadLump lump = Wads.OpenLumpNum (SourceLump); + auto lump = Wads.OpenLumpReader (SourceLump); TGAHeader hdr; uint16_t w; uint8_t r,g,b,a; @@ -499,7 +499,7 @@ int FTGATexture::CopyTrueColorPixels(FBitmap *bmp, int x, int y, int rotate, FCo int transval = 0; lump.Read(&hdr, sizeof(hdr)); - lump.Seek(hdr.id_len, SEEK_CUR); + lump.Seek(hdr.id_len, FileRdr::SeekCur); hdr.width = LittleShort(hdr.width); hdr.height = LittleShort(hdr.height); diff --git a/src/v_font.cpp b/src/v_font.cpp index 9716f27444..1d362f61b3 100644 --- a/src/v_font.cpp +++ b/src/v_font.cpp @@ -321,7 +321,7 @@ FFont *V_GetFont(const char *name) { uint32_t head; { - FWadLump lumpy = Wads.OpenLumpNum (lump); + auto lumpy = Wads.OpenLumpReader (lump); lumpy.Read (&head, 4); } if ((head & MAKE_ID(255,255,255,0)) == MAKE_ID('F','O','N',0) || @@ -1855,7 +1855,7 @@ void FFontChar2::SetSourceRemap(const uint8_t *sourceremap) void FFontChar2::MakeTexture () { - FWadLump lump = Wads.OpenLumpNum (SourceLump); + auto lump = Wads.OpenLumpReader (SourceLump); int destSize = Width * Height; uint8_t max = 255; bool rle = true; @@ -1868,18 +1868,18 @@ void FFontChar2::MakeTexture () { lump.Read (buff, 7); max = buff[6]; - lump.Seek (SourcePos - 11, SEEK_CUR); + lump.Seek (SourcePos - 11, FileRdr::SeekCur); } else if (buff[3] == 0x1A) { lump.Read(buff, 13); max = buff[12] - 1; - lump.Seek (SourcePos - 17, SEEK_CUR); + lump.Seek (SourcePos - 17, FileRdr::SeekCur); rle = false; } else { - lump.Seek (SourcePos - 4, SEEK_CUR); + lump.Seek (SourcePos - 4, FileRdr::SeekCur); } } diff --git a/src/win32/st_start.cpp b/src/win32/st_start.cpp index 5ba3848c76..75aacdc4e3 100644 --- a/src/win32/st_start.cpp +++ b/src/win32/st_start.cpp @@ -966,8 +966,8 @@ FStrifeStartupScreen::FStrifeStartupScreen(int max_progress, HRESULT &hr) // Fill bitmap with the startup image. memset (ST_Util_BitsForBitmap(StartupBitmap), 0xF0, 64000); - FWadLump lumpr = Wads.OpenLumpNum (startup_lump); - lumpr.Seek (57 * 320, SEEK_SET); + auto lumpr = Wads.OpenLumpReader (startup_lump); + lumpr.Seek (57 * 320, FileRdr::SeekSet); lumpr.Read (ST_Util_BitsForBitmap(StartupBitmap) + 41 * 320, 95 * 320); // Load the animated overlays. @@ -978,7 +978,7 @@ FStrifeStartupScreen::FStrifeStartupScreen(int max_progress, HRESULT &hr) if (lumpnum >= 0 && (lumplen = Wads.LumpLength (lumpnum)) == StrifeStartupPicSizes[i]) { - FWadLump lumpr = Wads.OpenLumpNum (lumpnum); + auto lumpr = Wads.OpenLumpReader (lumpnum); StartupPics[i] = new uint8_t[lumplen]; lumpr.Read (StartupPics[i], lumplen); } From c4387459bbe6613f2be878143403edbbf846257b Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Sat, 10 Mar 2018 19:22:26 +0100 Subject: [PATCH 18/89] - use FileRdr in the PNG code, in particular to sanitize the savepic handling. --- src/files.h | 5 +++ src/m_png.cpp | 41 ++++++++++------------ src/m_png.h | 12 +++---- src/menu/loadsavemenu.cpp | 52 ++++++++++++---------------- src/menu/menu.h | 1 - src/textures/pngtexture.cpp | 68 +++++++++++++++++++------------------ 6 files changed, 84 insertions(+), 95 deletions(-) diff --git a/src/files.h b/src/files.h index c8a330315b..b40526c2c0 100644 --- a/src/files.h +++ b/src/files.h @@ -545,6 +545,11 @@ public: Close(); } + bool isOpen() const + { + return mReader != nullptr; + } + void Close() { if (mReader != nullptr) delete mReader; diff --git a/src/m_png.cpp b/src/m_png.cpp index a7f82ed8f4..63e57e35ce 100644 --- a/src/m_png.cpp +++ b/src/m_png.cpp @@ -75,22 +75,17 @@ struct IHDR uint8_t Interlace; }; -PNGHandle::PNGHandle (FILE *file) : File(0), bDeleteFilePtr(true), ChunkPt(0) +PNGHandle::PNGHandle (FileRdr &file) : File(0), bDeleteFilePtr(true), ChunkPt(0) { - File = new FileReader(file); + File = std::move(file); } -PNGHandle::PNGHandle (FileReader *file, bool takereader) : File(file), bDeleteFilePtr(takereader), ChunkPt(0) {} PNGHandle::~PNGHandle () { for (unsigned int i = 0; i < TextChunks.Size(); ++i) { delete[] TextChunks[i]; } - if (bDeleteFilePtr) - { - delete File; - } } // EXTERNAL FUNCTION PROTOTYPES -------------------------------------------- @@ -309,7 +304,7 @@ unsigned int M_NextPNGChunk (PNGHandle *png, uint32_t id) { if (png->Chunks[png->ChunkPt].ID == id) { // Found the chunk - png->File->Seek (png->Chunks[png->ChunkPt++].Offset, SEEK_SET); + png->File.Seek (png->Chunks[png->ChunkPt++].Offset, FileRdr::SeekSet); return png->Chunks[png->ChunkPt - 1].Size; } } @@ -374,46 +369,43 @@ bool M_GetPNGText (PNGHandle *png, const char *keyword, char *buffer, size_t buf // //========================================================================== -PNGHandle *M_VerifyPNG (FileReader *filer, bool takereader) +PNGHandle *M_VerifyPNG (FileRdr &filer) { PNGHandle::Chunk chunk; PNGHandle *png; uint32_t data[2]; bool sawIDAT = false; - if (filer->Read(&data, 8) != 8) + if (filer.Read(&data, 8) != 8) { - if (takereader) delete filer; return NULL; } if (data[0] != MAKE_ID(137,'P','N','G') || data[1] != MAKE_ID(13,10,26,10)) { // Does not have PNG signature - if (takereader) delete filer; return NULL; } - if (filer->Read (&data, 8) != 8) + if (filer.Read (&data, 8) != 8) { - if (takereader) delete filer; return NULL; } if (data[1] != MAKE_ID('I','H','D','R')) { // IHDR must be the first chunk - if (takereader) delete filer; return NULL; } // It looks like a PNG so far, so start creating a PNGHandle for it - png = new PNGHandle (filer, takereader); + png = new PNGHandle (filer); + // filer is no longer valid after the above line! chunk.ID = data[1]; chunk.Offset = 16; chunk.Size = BigLong((unsigned int)data[0]); png->Chunks.Push (chunk); - filer->Seek (16, SEEK_SET); + png->File.Seek (16, FileRdr::SeekSet); - while (filer->Seek (chunk.Size + 4, SEEK_CUR) == 0) + while (png->File.Seek (chunk.Size + 4, FileRdr::SeekCur) == 0) { // If the file ended before an IEND was encountered, it's not a PNG. - if (filer->Read (&data, 8) != 8) + if (png->File.Read (&data, 8) != 8) { break; } @@ -432,7 +424,7 @@ PNGHandle *M_VerifyPNG (FileReader *filer, bool takereader) sawIDAT = true; } chunk.ID = data[1]; - chunk.Offset = filer->Tell(); + chunk.Offset = (uint32_t)png->File.Tell(); chunk.Size = BigLong((unsigned int)data[0]); png->Chunks.Push (chunk); @@ -441,7 +433,7 @@ PNGHandle *M_VerifyPNG (FileReader *filer, bool takereader) { char *str = new char[chunk.Size + 1]; - if (filer->Read (str, chunk.Size) != (long)chunk.Size) + if (png->File.Read (str, chunk.Size) != chunk.Size) { delete[] str; break; @@ -452,6 +444,7 @@ PNGHandle *M_VerifyPNG (FileReader *filer, bool takereader) } } + filer = std::move(png->File); // need to get the reader back if this function failed. delete png; return NULL; } @@ -477,7 +470,7 @@ void M_FreePNG (PNGHandle *png) // //========================================================================== -bool M_ReadIDAT (FileReader *file, uint8_t *buffer, int width, int height, int pitch, +bool M_ReadIDAT (FileRdr &file, uint8_t *buffer, int width, int height, int pitch, uint8_t bitdepth, uint8_t colortype, uint8_t interlace, unsigned int chunklen) { // Uninterlaced images are treated as a conceptual eighth pass by these tables. @@ -574,7 +567,7 @@ bool M_ReadIDAT (FileReader *file, uint8_t *buffer, int width, int height, int p if (stream.avail_in == 0 && chunklen > 0) { stream.next_in = chunkbuffer; - stream.avail_in = (uInt)file->Read (chunkbuffer, MIN(chunklen,sizeof(chunkbuffer))); + stream.avail_in = (uInt)file.Read (chunkbuffer, MIN(chunklen,sizeof(chunkbuffer))); chunklen -= stream.avail_in; } @@ -666,7 +659,7 @@ bool M_ReadIDAT (FileReader *file, uint8_t *buffer, int width, int height, int p { uint32_t x[3]; - if (file->Read (x, 12) != 12) + if (file.Read (x, 12) != 12) { lastIDAT = true; } diff --git a/src/m_png.h b/src/m_png.h index 7bc9b474f0..814e7b281f 100644 --- a/src/m_png.h +++ b/src/m_png.h @@ -36,8 +36,8 @@ #include #include "doomtype.h" #include "v_video.h" +#include "files.h" -class FileReader; class FileWriter; // PNG Writing -------------------------------------------------------------- @@ -64,7 +64,6 @@ bool M_SaveBitmap(const uint8_t *from, ESSType color_type, int width, int height // PNG Reading -------------------------------------------------------------- -class FileReader; struct PNGHandle { struct Chunk @@ -74,14 +73,13 @@ struct PNGHandle uint32_t Size; }; - FileReader *File; + FileRdr File; bool bDeleteFilePtr; TArray Chunks; TArray TextChunks; unsigned int ChunkPt; - PNGHandle(FILE *file); - PNGHandle(FileReader *file, bool takereader = false); + PNGHandle(FileRdr &file); ~PNGHandle(); }; @@ -89,7 +87,7 @@ struct PNGHandle // the signature, but also checking for the IEND chunk. CRC checking of // each chunk is not done. If it is valid, you get a PNGHandle to pass to // the following functions. -PNGHandle *M_VerifyPNG (FileReader *file, bool takereader = false); +PNGHandle *M_VerifyPNG (FileRdr &file); // Finds a chunk in a PNG file. The file pointer will be positioned at the // beginning of the chunk data, and its length will be returned. A return @@ -108,7 +106,7 @@ bool M_GetPNGText (PNGHandle *png, const char *keyword, char *buffer, size_t buf // The file must be positioned at the start of the first IDAT. It reads // image data into the provided buffer. Returns true on success. -bool M_ReadIDAT (FileReader *file, uint8_t *buffer, int width, int height, int pitch, +bool M_ReadIDAT (FileRdr &file, uint8_t *buffer, int width, int height, int pitch, uint8_t bitdepth, uint8_t colortype, uint8_t interlace, unsigned int idatlen); diff --git a/src/menu/loadsavemenu.cpp b/src/menu/loadsavemenu.cpp index c9fb7aebaf..d66a3ab079 100644 --- a/src/menu/loadsavemenu.cpp +++ b/src/menu/loadsavemenu.cpp @@ -236,8 +236,8 @@ void FSavegameManager::ReadSaveStrings() } else // check for old formats. { - FileReader file; - if (file.Open(filepath)) + FileRdr file; + if (file.OpenFile(filepath)) { PNGHandle *png; char sig[16]; @@ -255,7 +255,7 @@ void FSavegameManager::ReadSaveStrings() title[OLDSAVESTRINGSIZE] = 0; - if (nullptr != (png = M_VerifyPNG(&file, false))) + if (nullptr != (png = M_VerifyPNG(file))) { char *ver = M_GetPNGText(png, "ZDoom Save Version"); if (ver != nullptr) @@ -272,7 +272,7 @@ void FSavegameManager::ReadSaveStrings() } else { - file.Seek(0, SEEK_SET); + file.Seek(0, FileRdr::SeekSet); if (file.Read(sig, 16) == 16) { @@ -496,29 +496,26 @@ unsigned FSavegameManager::ExtractSaveData(int index) FResourceLump *pic = resf->FindLump("savepic.png"); if (pic != nullptr) { - FileReader *reader = pic->NewReader(); - if (reader != nullptr) + FileRdr picreader; + + picreader.OpenMemoryArray([=](TArray &array) { - // copy to a memory buffer which gets accessed through a memory reader and PNGHandle. - // We cannot use the actual lump as backing for the texture because that requires keeping the - // savegame file open. - SavePicData.Resize(pic->LumpSize); - reader->Read(&SavePicData[0], pic->LumpSize); - reader = new MemoryReader(&SavePicData[0], SavePicData.Size()); - PNGHandle *png = M_VerifyPNG(reader); - if (png != nullptr) + auto cache = pic->CacheLump(); + array.Resize(pic->LumpSize); + memcpy(&array[0], cache, pic->LumpSize); + pic->ReleaseCache(); + return true; + }); + PNGHandle *png = M_VerifyPNG(picreader); + if (png != nullptr) + { + SavePic = PNGTexture_CreateFromFile(png, node->Filename); + delete png; + if (SavePic->GetWidth() == 1 && SavePic->GetHeight() == 1) { - SavePic = PNGTexture_CreateFromFile(png, node->Filename); - currentSavePic = reader; // must be kept so that the texture can read from it. - delete png; - if (SavePic->GetWidth() == 1 && SavePic->GetHeight() == 1) - { - delete SavePic; - SavePic = nullptr; - delete currentSavePic; - currentSavePic = nullptr; - SavePicData.Clear(); - } + delete SavePic; + SavePic = nullptr; + SavePicData.Clear(); } } } @@ -551,14 +548,9 @@ void FSavegameManager::UnloadSaveData() { V_FreeBrokenLines(SaveComment); } - if (currentSavePic != nullptr) - { - delete currentSavePic; - } SavePic = nullptr; SaveComment = nullptr; - currentSavePic = nullptr; SavePicData.Clear(); } diff --git a/src/menu/menu.h b/src/menu/menu.h index d5211421ff..71595903c2 100644 --- a/src/menu/menu.h +++ b/src/menu/menu.h @@ -71,7 +71,6 @@ private: FSaveGameNode NewSaveNode; int LastSaved = -1; int LastAccessed = -1; - FileReader *currentSavePic = nullptr; TArray SavePicData; FTexture *SavePic = nullptr; FBrokenLines *SaveComment = nullptr; diff --git a/src/textures/pngtexture.cpp b/src/textures/pngtexture.cpp index 7ca1a32c67..a7e2d05347 100644 --- a/src/textures/pngtexture.cpp +++ b/src/textures/pngtexture.cpp @@ -51,7 +51,7 @@ class FPNGTexture : public FTexture { public: - FPNGTexture (FileReader &lump, int lumpnum, const FString &filename, int width, int height, uint8_t bitdepth, uint8_t colortype, uint8_t interlace); + FPNGTexture (FileRdr &lump, int lumpnum, const FString &filename, int width, int height, uint8_t bitdepth, uint8_t colortype, uint8_t interlace); ~FPNGTexture (); const uint8_t *GetColumn (unsigned int column, const Span **spans_out); @@ -66,7 +66,7 @@ protected: FString SourceFile; uint8_t *Pixels; Span **Spans; - FileReader *fr; + FileRdr fr; uint8_t BitDepth; uint8_t ColorType; @@ -147,7 +147,7 @@ FTexture *PNGTexture_TryCreate(FileRdr & data, int lumpnum) } } - return new FPNGTexture (*data.Reader(), lumpnum, FString(), BigLong((int)width), BigLong((int)height), + return new FPNGTexture (data, lumpnum, FString(), BigLong((int)width), BigLong((int)height), bitdepth, colortype, interlace); } @@ -168,9 +168,9 @@ FTexture *PNGTexture_CreateFromFile(PNGHandle *png, const FString &filename) } // Check the IHDR to make sure it's a type of PNG we support. - png->File->Read(&width, 4); - png->File->Read(&height, 4); - (*png->File) >> bitdepth >> colortype >> compression >> filter >> interlace; + png->File.Read(&width, 4); + png->File.Read(&height, 4); + png->File >> bitdepth >> colortype >> compression >> filter >> interlace; if (compression != 0 || filter != 0 || interlace > 1) { @@ -185,7 +185,7 @@ FTexture *PNGTexture_CreateFromFile(PNGHandle *png, const FString &filename) return NULL; } - return new FPNGTexture (*png->File, -1, filename, BigLong((int)width), BigLong((int)height), + return new FPNGTexture (png->File, -1, filename, BigLong((int)width), BigLong((int)height), bitdepth, colortype, interlace); } @@ -195,7 +195,7 @@ FTexture *PNGTexture_CreateFromFile(PNGHandle *png, const FString &filename) // //========================================================================== -FPNGTexture::FPNGTexture (FileReader &lump, int lumpnum, const FString &filename, int width, int height, +FPNGTexture::FPNGTexture (FileRdr &lump, int lumpnum, const FString &filename, int width, int height, uint8_t depth, uint8_t colortype, uint8_t interlace) : FTexture(NULL, lumpnum), SourceFile(filename), Pixels(0), Spans(0), BitDepth(depth), ColorType(colortype), Interlace(interlace), HaveTrans(false), @@ -210,9 +210,6 @@ FPNGTexture::FPNGTexture (FileReader &lump, int lumpnum, const FString &filename uint32_t len, id; int i; - if (lumpnum == -1) fr = &lump; - else fr = nullptr; - UseType = TEX_MiscPatch; LeftOffset = 0; TopOffset = 0; @@ -225,7 +222,7 @@ FPNGTexture::FPNGTexture (FileReader &lump, int lumpnum, const FString &filename memset(trans, 255, 256); // Parse pre-IDAT chunks. I skip the CRCs. Is that bad? - lump.Seek(33, SEEK_SET); + lump.Seek(33, FileRdr::SeekSet); lump.Read(&len, 4); lump.Read(&id, 4); @@ -235,7 +232,7 @@ FPNGTexture::FPNGTexture (FileReader &lump, int lumpnum, const FString &filename switch (id) { default: - lump.Seek (len, SEEK_CUR); + lump.Seek (len, FileRdr::SeekCur); break; case MAKE_ID('g','r','A','b'): @@ -268,7 +265,7 @@ FPNGTexture::FPNGTexture (FileReader &lump, int lumpnum, const FString &filename lump.Read (p.pngpal, PaletteSize * 3); if (PaletteSize * 3 != (int)len) { - lump.Seek (len - PaletteSize * 3, SEEK_CUR); + lump.Seek (len - PaletteSize * 3, FileRdr::SeekCur); } for (i = PaletteSize - 1; i >= 0; --i) { @@ -290,12 +287,12 @@ FPNGTexture::FPNGTexture (FileReader &lump, int lumpnum, const FString &filename bMasked = true; break; } - lump.Seek(4, SEEK_CUR); // Skip CRC + lump.Seek(4, FileRdr::SeekCur); // Skip CRC lump.Read(&len, 4); id = MAKE_ID('I','E','N','D'); lump.Read(&id, 4); } - StartOfIDAT = lump.Tell() - 8; + StartOfIDAT = (uint32_t)lump.Tell() - 8; switch (colortype) { @@ -342,6 +339,8 @@ FPNGTexture::FPNGTexture (FileReader &lump, int lumpnum, const FString &filename bMasked = HaveTrans; break; } + // If this is a savegame we must keep the reader. + if (lumpnum == -1) fr = std::move(lump); } //========================================================================== @@ -457,15 +456,17 @@ const uint8_t *FPNGTexture::GetPixels () void FPNGTexture::MakeTexture () { - FileReader *lump; + FileRdr *lump; + FileRdr lfr; if (SourceLump >= 0) { - lump = new FWadLump(Wads.OpenLumpNum(SourceLump)); + lfr = Wads.OpenLumpReader(SourceLump); + lump = 𝔩 } else { - lump = fr;// new FileReader(SourceFile.GetChars()); + lump = &fr; } Pixels = new uint8_t[Width*Height]; @@ -476,13 +477,13 @@ void FPNGTexture::MakeTexture () else { uint32_t len, id; - lump->Seek (StartOfIDAT, SEEK_SET); + lump->Seek (StartOfIDAT, FileRdr::SeekSet); lump->Read(&len, 4); lump->Read(&id, 4); if (ColorType == 0 || ColorType == 3) /* Grayscale and paletted */ { - M_ReadIDAT (lump, Pixels, Width, Height, Width, BitDepth, ColorType, Interlace, BigLong((unsigned int)len)); + M_ReadIDAT (*lump, Pixels, Width, Height, Width, BitDepth, ColorType, Interlace, BigLong((unsigned int)len)); if (Width == Height) { @@ -518,7 +519,7 @@ void FPNGTexture::MakeTexture () uint8_t *in, *out; int x, y, pitch, backstep; - M_ReadIDAT (lump, tempix, Width, Height, Width*bytesPerPixel, BitDepth, ColorType, Interlace, BigLong((unsigned int)len)); + M_ReadIDAT (*lump, tempix, Width, Height, Width*bytesPerPixel, BitDepth, ColorType, Interlace, BigLong((unsigned int)len)); in = tempix; out = Pixels; @@ -602,7 +603,6 @@ void FPNGTexture::MakeTexture () delete[] tempix; } } - if (lump != fr) delete lump; } //=========================================================================== @@ -616,21 +616,24 @@ int FPNGTexture::CopyTrueColorPixels(FBitmap *bmp, int x, int y, int rotate, FCo // Parse pre-IDAT chunks. I skip the CRCs. Is that bad? PalEntry pe[256]; uint32_t len, id; - FileReader *lump; static char bpp[] = {1, 0, 3, 1, 2, 0, 4}; int pixwidth = Width * bpp[ColorType]; int transpal = false; + FileRdr *lump; + FileRdr lfr; + if (SourceLump >= 0) { - lump = new FWadLump(Wads.OpenLumpNum(SourceLump)); + lfr = Wads.OpenLumpReader(SourceLump); + lump = 𝔩 } else { - lump = fr;// new FileReader(SourceFile.GetChars()); + lump = &fr; } - lump->Seek(33, SEEK_SET); + lump->Seek(33, FileRdr::SeekSet); for(int i = 0; i < 256; i++) // default to a gray map pe[i] = PalEntry(255,i,i,i); @@ -642,7 +645,7 @@ int FPNGTexture::CopyTrueColorPixels(FBitmap *bmp, int x, int y, int rotate, FCo switch (id) { default: - lump->Seek (len, SEEK_CUR); + lump->Seek (len, FileRdr::SeekCur); break; case MAKE_ID('P','L','T','E'): @@ -664,11 +667,11 @@ int FPNGTexture::CopyTrueColorPixels(FBitmap *bmp, int x, int y, int rotate, FCo } else { - lump->Seek(len, SEEK_CUR); + lump->Seek(len, FileRdr::SeekCur); } break; } - lump->Seek(4, SEEK_CUR); // Skip CRC + lump->Seek(4, FileRdr::SeekCur); // Skip CRC lump->Read(&len, 4); id = MAKE_ID('I','E','N','D'); lump->Read(&id, 4); @@ -682,11 +685,10 @@ int FPNGTexture::CopyTrueColorPixels(FBitmap *bmp, int x, int y, int rotate, FCo uint8_t * Pixels = new uint8_t[pixwidth * Height]; - lump->Seek (StartOfIDAT, SEEK_SET); + lump->Seek (StartOfIDAT, FileRdr::SeekSet); lump->Read(&len, 4); lump->Read(&id, 4); - M_ReadIDAT (lump, Pixels, Width, Height, pixwidth, BitDepth, ColorType, Interlace, BigLong((unsigned int)len)); - if (lump != fr) delete lump; + M_ReadIDAT (*lump, Pixels, Width, Height, pixwidth, BitDepth, ColorType, Interlace, BigLong((unsigned int)len)); switch (ColorType) { From 56991a9acec18b9847c2379d67ee607e3c087221 Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Sat, 10 Mar 2018 20:10:17 +0100 Subject: [PATCH 19/89] - Removed FileReader from SoundFont manager. - renamed close_file to tf_close for consistency. --- src/sound/i_soundfont.cpp | 58 ++++++++--------- src/sound/i_soundfont.h | 22 +++---- src/sound/timidity/instrum.cpp | 27 +++----- src/sound/timidity/instrum_font.cpp | 7 +- src/sound/timidity/instrum_sf2.cpp | 99 ++++++++++++++--------------- src/sound/timidity/sf2.h | 2 +- src/sound/timidity/timidity.cpp | 34 +--------- src/sound/timidity/timidity.h | 5 +- src/sound/timiditypp/common.cpp | 28 ++++---- src/sound/timiditypp/common.h | 4 +- src/sound/timiditypp/configfile.cpp | 6 +- src/sound/timiditypp/instrum.cpp | 10 +-- src/sound/timiditypp/smplfile.cpp | 20 +++--- src/sound/timiditypp/sndfont.cpp | 11 ++-- src/sound/wildmidi/file_io.cpp | 11 ++-- src/sound/wildmidi/wildmidi_lib.cpp | 2 +- 16 files changed, 147 insertions(+), 199 deletions(-) diff --git a/src/sound/i_soundfont.cpp b/src/sound/i_soundfont.cpp index 4a073bc5e9..38b1f70b77 100644 --- a/src/sound/i_soundfont.cpp +++ b/src/sound/i_soundfont.cpp @@ -50,7 +50,7 @@ FSoundFontManager sfmanager; // //========================================================================== -std::pair FSoundFontReader::LookupFile(const char *name) +std::pair FSoundFontReader::LookupFile(const char *name) { if (!IsAbsPath(name)) { @@ -58,12 +58,12 @@ std::pair FSoundFontReader::LookupFile(const char *name) { FString fullname = mPaths[i] + name; auto fr = OpenFile(fullname); - if (fr != nullptr) return std::make_pair(fr, fullname); + if (fr.isOpen()) return std::make_pair(std::move(fr), fullname); } } auto fr = OpenFile(name); - if (fr != nullptr) return std::make_pair(fr, name); - return std::make_pair(nullptr, FString()); + if (!fr.isOpen()) name = ""; + return std::make_pair(std::move(fr), name); } //========================================================================== @@ -117,7 +117,7 @@ FSF2Reader::FSF2Reader(const char *fn) // //========================================================================== -FileReader *FSF2Reader::OpenMainConfigFile() +FileRdr FSF2Reader::OpenMainConfigFile() { if (mMainConfigForSF2.IsNotEmpty()) { @@ -126,15 +126,14 @@ FileReader *FSF2Reader::OpenMainConfigFile() return nullptr; } -FileReader *FSF2Reader::OpenFile(const char *name) +FileRdr FSF2Reader::OpenFile(const char *name) { + FileRdr fr; if (mFilename.CompareNoCase(name) == 0) { - auto fr = new FileReader; - if (fr->Open(name)) return fr; - delete fr; + fr.OpenFile(name); } - return nullptr; + return fr; } //========================================================================== @@ -153,12 +152,12 @@ FZipPatReader::~FZipPatReader() if (resf != nullptr) delete resf; } -FileReader *FZipPatReader::OpenMainConfigFile() +FileRdr FZipPatReader::OpenMainConfigFile() { return OpenFile("timidity.cfg"); } -FileReader *FZipPatReader::OpenFile(const char *name) +FileRdr FZipPatReader::OpenFile(const char *name) { if (resf != nullptr) { @@ -194,8 +193,8 @@ FPatchSetReader::FPatchSetReader(const char *filename) }; #endif mAllowAbsolutePaths = true; - FileReader *fr = new FileReader; - if (fr->Open(filename)) + FileRdr fr; + if (fr.OpenFile(filename)) { mFullPathToConfig = filename; } @@ -204,7 +203,7 @@ FPatchSetReader::FPatchSetReader(const char *filename) for(auto c : paths) { FStringf fullname("%s/%s", c, filename); - if (fr->Open(fullname)) + if (fr.OpenFile(fullname)) { mFullPathToConfig = fullname; } @@ -224,23 +223,21 @@ FPatchSetReader::FPatchSetReader() mAllowAbsolutePaths = true; } -FileReader *FPatchSetReader::OpenMainConfigFile() +FileRdr FPatchSetReader::OpenMainConfigFile() { - auto fr = new FileReader; - if (fr->Open(mFullPathToConfig)) return fr; - delete fr; - return nullptr; + FileRdr fr; + fr.OpenFile(mFullPathToConfig); + return fr; } -FileReader *FPatchSetReader::OpenFile(const char *name) +FileRdr FPatchSetReader::OpenFile(const char *name) { FString path; if (IsAbsPath(name)) path = name; else path = mBasePath + name; - auto fr = new FileReader; - if (fr->Open(path)) return fr; - delete fr; - return nullptr; + FileRdr fr; + fr.OpenFile(path); + return fr; } //========================================================================== @@ -252,7 +249,6 @@ FileReader *FPatchSetReader::OpenFile(const char *name) FLumpPatchSetReader::FLumpPatchSetReader(const char *filename) { mLumpIndex = Wads.CheckNumForFullName(filename); - FileReader *fr = new FileReader; mBasePath = filename; FixPathSeperator(mBasePath); @@ -260,19 +256,19 @@ FLumpPatchSetReader::FLumpPatchSetReader(const char *filename) if (mBasePath.Len() > 0 && mBasePath.Back() != '/') mBasePath += '/'; } -FileReader *FLumpPatchSetReader::OpenMainConfigFile() +FileRdr FLumpPatchSetReader::OpenMainConfigFile() { return Wads.ReopenLumpNum(mLumpIndex); } -FileReader *FLumpPatchSetReader::OpenFile(const char *name) +FileRdr FLumpPatchSetReader::OpenFile(const char *name) { FString path; - if (IsAbsPath(name)) return nullptr; // no absolute paths in the lump directory. + if (IsAbsPath(name)) return FileRdr(); // no absolute paths in the lump directory. path = mBasePath + name; auto index = Wads.CheckNumForFullName(path); - if (index < 0) return nullptr; - return Wads.ReopenLumpNum(index); + if (index < 0) return FileRdr(); + return Wads.ReopenLumpReader(index); } //========================================================================== diff --git a/src/sound/i_soundfont.h b/src/sound/i_soundfont.h index 9208351e48..a6864d9d78 100644 --- a/src/sound/i_soundfont.h +++ b/src/sound/i_soundfont.h @@ -41,9 +41,9 @@ protected: public: virtual ~FSoundFontReader() {} - virtual FileReader *OpenMainConfigFile() = 0; // this is special because it needs to be synthesized for .sf files and set some restrictions for patch sets - virtual FileReader *OpenFile(const char *name) = 0; - std::pair LookupFile(const char *name); + virtual FileRdr OpenMainConfigFile() = 0; // this is special because it needs to be synthesized for .sf files and set some restrictions for patch sets + virtual FileRdr OpenFile(const char *name) = 0; + std::pair LookupFile(const char *name); void AddPath(const char *str); virtual FString basePath() const { @@ -63,8 +63,8 @@ class FSF2Reader : public FSoundFontReader FString mFilename; public: FSF2Reader(const char *filename); - virtual FileReader *OpenMainConfigFile() override; - virtual FileReader *OpenFile(const char *name) override; + virtual FileRdr OpenMainConfigFile() override; + virtual FileRdr OpenFile(const char *name) override; }; //========================================================================== @@ -79,8 +79,8 @@ class FZipPatReader : public FSoundFontReader public: FZipPatReader(const char *filename); ~FZipPatReader(); - virtual FileReader *OpenMainConfigFile() override; - virtual FileReader *OpenFile(const char *name) override; + virtual FileRdr OpenMainConfigFile() override; + virtual FileRdr OpenFile(const char *name) override; bool isOk() { return resf != nullptr; } }; @@ -97,8 +97,8 @@ class FLumpPatchSetReader : public FSoundFontReader public: FLumpPatchSetReader(const char *filename); - virtual FileReader *OpenMainConfigFile() override; - virtual FileReader *OpenFile(const char *name) override; + virtual FileRdr OpenMainConfigFile() override; + virtual FileRdr OpenFile(const char *name) override; virtual FString basePath() const override { return mBasePath; @@ -120,8 +120,8 @@ class FPatchSetReader : public FSoundFontReader public: FPatchSetReader(); FPatchSetReader(const char *filename); - virtual FileReader *OpenMainConfigFile() override; - virtual FileReader *OpenFile(const char *name) override; + virtual FileRdr OpenMainConfigFile() override; + virtual FileRdr OpenFile(const char *name) override; virtual FString basePath() const override { return mBasePath; diff --git a/src/sound/timidity/instrum.cpp b/src/sound/timidity/instrum.cpp index d92f7eb81e..32ccd121ff 100644 --- a/src/sound/timidity/instrum.cpp +++ b/src/sound/timidity/instrum.cpp @@ -153,7 +153,6 @@ static Instrument *load_instrument(Renderer *song, const char *name, int percuss { Instrument *ip; Sample *sp; - FileReader *fp; GF1PatchHeader header; GF1InstrumentData idata; GF1LayerData layer_data; @@ -164,19 +163,19 @@ static Instrument *load_instrument(Renderer *song, const char *name, int percuss if (!name || gus_sfreader == nullptr) return nullptr; /* Open patch file */ - fp = gus_sfreader->LookupFile(name).first; - if (fp == NULL) + auto fp = gus_sfreader->LookupFile(name).first; + if (!fp.isOpen()) { /* Try with various extensions */ FString tmp = name; tmp += ".pat"; fp = gus_sfreader->LookupFile(tmp).first; - if (fp == NULL) + if (!fp.isOpen()) { #ifdef __unix__ // Windows isn't case-sensitive. tmp.ToUpper(); fp = gus_sfreader->LookupFile(tmp).first; - if (fp == NULL) + if (!fp.isOpen()) #endif { noluck = true; @@ -194,26 +193,23 @@ static Instrument *load_instrument(Renderer *song, const char *name, int percuss /* Read some headers and do cursory sanity checks. */ - if (sizeof(header) != fp->Read(&header, sizeof(header))) + if (sizeof(header) != fp.Read(&header, sizeof(header))) { failread: cmsg(CMSG_ERROR, VERB_NORMAL, "%s: Error reading instrument.\n", name); - delete fp; return 0; } if (strncmp(header.Header, GF1_HEADER_TEXT, HEADER_SIZE - 4) != 0) { cmsg(CMSG_ERROR, VERB_NORMAL, "%s: Not an instrument.\n", name); - delete fp; return 0; } if (strcmp(header.Header + 8, "110") < 0) { cmsg(CMSG_ERROR, VERB_NORMAL, "%s: Is an old and unsupported patch version.\n", name); - delete fp; return 0; } - if (sizeof(idata) != fp->Read(&idata, sizeof(idata))) + if (sizeof(idata) != fp.Read(&idata, sizeof(idata))) { goto failread; } @@ -226,18 +222,16 @@ failread: if (header.Instruments != 1 && header.Instruments != 0) /* instruments. To some patch makers, 0 means 1 */ { cmsg(CMSG_ERROR, VERB_NORMAL, "Can't handle patches with %d instruments.\n", header.Instruments); - delete fp; return 0; } if (idata.Layers != 1 && idata.Layers != 0) /* layers. What's a layer? */ { cmsg(CMSG_ERROR, VERB_NORMAL, "Can't handle instruments with %d layers.\n", idata.Layers); - delete fp; return 0; } - if (sizeof(layer_data) != fp->Read(&layer_data, sizeof(layer_data))) + if (sizeof(layer_data) != fp.Read(&layer_data, sizeof(layer_data))) { goto failread; } @@ -245,7 +239,6 @@ failread: if (layer_data.Samples == 0) { cmsg(CMSG_ERROR, VERB_NORMAL, "Instrument has 0 samples.\n"); - delete fp; return 0; } @@ -255,12 +248,11 @@ failread: memset(ip->sample, 0, sizeof(Sample) * layer_data.Samples); for (i = 0; i < layer_data.Samples; ++i) { - if (sizeof(patch_data) != fp->Read(&patch_data, sizeof(patch_data))) + if (sizeof(patch_data) != fp.Read(&patch_data, sizeof(patch_data))) { fail: cmsg(CMSG_ERROR, VERB_NORMAL, "Error reading sample %d.\n", i); delete ip; - delete fp; return 0; } @@ -422,7 +414,7 @@ fail: } sp->data = (sample_t *)safe_malloc(sp->data_length); - if (sp->data_length != fp->Read(sp->data, sp->data_length)) + if (sp->data_length != fp.Read(sp->data, sp->data_length)) goto fail; convert_sample_data(sp, sp->data); @@ -469,7 +461,6 @@ fail: sp->data_length = sp->loop_end; } } - delete fp; return ip; } diff --git a/src/sound/timidity/instrum_font.cpp b/src/sound/timidity/instrum_font.cpp index 41709809c9..680641b813 100644 --- a/src/sound/timidity/instrum_font.cpp +++ b/src/sound/timidity/instrum_font.cpp @@ -17,7 +17,7 @@ namespace Timidity FontFile *Fonts; extern std::unique_ptr gus_sfreader; -FontFile *ReadDLS(const char *filename, FileReader *f) +FontFile *ReadDLS(const char *filename, FileRdr &f) { return NULL; } @@ -57,15 +57,14 @@ void font_add(const char *filename, int load_order) } else { - FileReader *fp = gus_sfreader->LookupFile(filename).first; + FileRdr fp = gus_sfreader->LookupFile(filename).first; - if (fp != NULL) + if (fp.isOpen()) { if ((font = ReadSF2(filename, fp)) || (font = ReadDLS(filename, fp))) { font->SetAllOrders(load_order); } - delete fp; } } } diff --git a/src/sound/timidity/instrum_sf2.cpp b/src/sound/timidity/instrum_sf2.cpp index dccbf53ac0..02696f63c7 100644 --- a/src/sound/timidity/instrum_sf2.cpp +++ b/src/sound/timidity/instrum_sf2.cpp @@ -28,7 +28,7 @@ class CBadVer {}; struct ListHandler { uint32_t ID; - void (*Parser)(SFFile *sf2, FileReader *f, uint32_t chunkid, uint32_t chunklen); + void (*Parser)(SFFile *sf2, FileRdr &f, uint32_t chunkid, uint32_t chunklen); }; enum @@ -162,15 +162,15 @@ static const SFGenComposite DefaultGenerators = -1 // overridingRootKey }; -static void ParseIfil(SFFile *sf2, FileReader *f, uint32_t chunkid, uint32_t chunklen); -static void ParseSmpl(SFFile *sf2, FileReader *f, uint32_t chunkid, uint32_t chunklen); -static void ParseSm24(SFFile *sf2, FileReader *f, uint32_t chunkid, uint32_t chunklen); -static void ParsePhdr(SFFile *sf2, FileReader *f, uint32_t chunkid, uint32_t chunklen); -static void ParseBag(SFFile *sf2, FileReader *f, uint32_t chunkid, uint32_t chunklen); -static void ParseMod(SFFile *sf2, FileReader *f, uint32_t chunkid, uint32_t chunklen); -static void ParseGen(SFFile *sf2, FileReader *f, uint32_t chunkid, uint32_t chunklen); -static void ParseInst(SFFile *sf2, FileReader *f, uint32_t chunkid, uint32_t chunklen); -static void ParseShdr(SFFile *sf2, FileReader *f, uint32_t chunkid, uint32_t chunklen); +static void ParseIfil(SFFile *sf2, FileRdr &f, uint32_t chunkid, uint32_t chunklen); +static void ParseSmpl(SFFile *sf2, FileRdr &f, uint32_t chunkid, uint32_t chunklen); +static void ParseSm24(SFFile *sf2, FileRdr &f, uint32_t chunkid, uint32_t chunklen); +static void ParsePhdr(SFFile *sf2, FileRdr &f, uint32_t chunkid, uint32_t chunklen); +static void ParseBag(SFFile *sf2, FileRdr &f, uint32_t chunkid, uint32_t chunklen); +static void ParseMod(SFFile *sf2, FileRdr &f, uint32_t chunkid, uint32_t chunklen); +static void ParseGen(SFFile *sf2, FileRdr &f, uint32_t chunkid, uint32_t chunklen); +static void ParseInst(SFFile *sf2, FileRdr &f, uint32_t chunkid, uint32_t chunklen); +static void ParseShdr(SFFile *sf2, FileRdr &f, uint32_t chunkid, uint32_t chunklen); ListHandler INFOHandlers[] = { @@ -225,87 +225,87 @@ static int32_t calc_rate(Renderer *song, int diff, double sec) } -static inline uint32_t read_id(FileReader *f) +static inline uint32_t read_id(FileRdr &f) { uint32_t id; - if (f->Read(&id, 4) != 4) + if (f.Read(&id, 4) != 4) { throw CIOErr(); } return id; } -static inline int read_byte(FileReader *f) +static inline int read_byte(FileRdr &f) { uint8_t x; - if (f->Read(&x, 1) != 1) + if (f.Read(&x, 1) != 1) { throw CIOErr(); } return x; } -static inline int read_char(FileReader *f) +static inline int read_char(FileRdr &f) { int8_t x; - if (f->Read(&x, 1) != 1) + if (f.Read(&x, 1) != 1) { throw CIOErr(); } return x; } -static inline int read_uword(FileReader *f) +static inline int read_uword(FileRdr &f) { uint16_t x; - if (f->Read(&x, 2) != 2) + if (f.Read(&x, 2) != 2) { throw CIOErr(); } return LittleShort(x); } -static inline int read_sword(FileReader *f) +static inline int read_sword(FileRdr &f) { int16_t x; - if (f->Read(&x, 2) != 2) + if (f.Read(&x, 2) != 2) { throw CIOErr(); } return LittleShort(x); } -static inline uint32_t read_dword(FileReader *f) +static inline uint32_t read_dword(FileRdr &f) { uint32_t x; - if (f->Read(&x, 4) != 4) + if (f.Read(&x, 4) != 4) { throw CIOErr(); } return LittleLong(x); } -static inline void read_name(FileReader *f, char name[21]) +static inline void read_name(FileRdr &f, char name[21]) { - if (f->Read(name, 20) != 20) + if (f.Read(name, 20) != 20) { throw CIOErr(); } name[20] = 0; } -static inline void skip_chunk(FileReader *f, uint32_t len) +static inline void skip_chunk(FileRdr &f, uint32_t len) { // RIFF, like IFF, adds an extra pad byte to the end of // odd-sized chunks so that new chunks are always on even // byte boundaries. - if (f->Seek(len + (len & 1), SEEK_CUR) != 0) + if (f.Seek(len + (len & 1), FileRdr::SeekCur) != 0) { throw CIOErr(); } } -static void check_list(FileReader *f, uint32_t id, uint32_t filelen, uint32_t &chunklen) +static void check_list(FileRdr &f, uint32_t id, uint32_t filelen, uint32_t &chunklen) { if (read_id(f) != ID_LIST) { @@ -322,7 +322,7 @@ static void check_list(FileReader *f, uint32_t id, uint32_t filelen, uint32_t &c } } -static void ParseIfil(SFFile *sf2, FileReader *f, uint32_t chunkid, uint32_t chunklen) +static void ParseIfil(SFFile *sf2, FileRdr &f, uint32_t chunkid, uint32_t chunklen) { uint16_t major, minor; @@ -341,7 +341,7 @@ static void ParseIfil(SFFile *sf2, FileReader *f, uint32_t chunkid, uint32_t chu sf2->MinorVersion = minor; } -static void ParseLIST(SFFile *sf2, FileReader *f, uint32_t chunklen, ListHandler *handlers) +static void ParseLIST(SFFile *sf2, FileRdr &f, uint32_t chunklen, ListHandler *handlers) { ListHandler *handler; uint32_t id; @@ -375,7 +375,7 @@ static void ParseLIST(SFFile *sf2, FileReader *f, uint32_t chunklen, ListHandler } } -static void ParseINFO(SFFile *sf2, FileReader *f, uint32_t chunklen) +static void ParseINFO(SFFile *sf2, FileRdr &f, uint32_t chunklen) { sf2->MinorVersion = -1; @@ -387,7 +387,7 @@ static void ParseINFO(SFFile *sf2, FileReader *f, uint32_t chunklen) } } -static void ParseSdta(SFFile *sf2, FileReader *f, uint32_t chunklen) +static void ParseSdta(SFFile *sf2, FileRdr &f, uint32_t chunklen) { ParseLIST(sf2, f, chunklen, SdtaHandlers); if (sf2->SampleDataOffset == 0) @@ -404,7 +404,7 @@ static void ParseSdta(SFFile *sf2, FileReader *f, uint32_t chunklen) } } -static void ParseSmpl(SFFile *sf2, FileReader *f, uint32_t chunkid, uint32_t chunklen) +static void ParseSmpl(SFFile *sf2, FileRdr &f, uint32_t chunkid, uint32_t chunklen) { // Only use the first smpl chunk. (Or should we reject files with more than one?) if (sf2->SampleDataOffset == 0) @@ -413,13 +413,13 @@ static void ParseSmpl(SFFile *sf2, FileReader *f, uint32_t chunkid, uint32_t chu { // Chunk must be an even number of bytes. throw CBadForm(); } - sf2->SampleDataOffset = f->Tell(); + sf2->SampleDataOffset = (uint32_t)f.Tell(); sf2->SizeSampleData = chunklen >> 1; } skip_chunk(f, chunklen); } -static void ParseSm24(SFFile *sf2, FileReader *f, uint32_t chunkid, uint32_t chunklen) +static void ParseSm24(SFFile *sf2, FileRdr &f, uint32_t chunkid, uint32_t chunklen) { // The sm24 chunk is ignored if the file version is < 2.04 if (sf2->MinorVersion >= 4) @@ -427,19 +427,19 @@ static void ParseSm24(SFFile *sf2, FileReader *f, uint32_t chunkid, uint32_t chu // Only use the first sm24 chunk. (Or should we reject files with more than one?) if (sf2->SampleDataLSBOffset == 0) { - sf2->SampleDataLSBOffset = f->Tell(); + sf2->SampleDataLSBOffset = (uint32_t)f.Tell(); sf2->SizeSampleDataLSB = chunklen; } } skip_chunk(f, chunklen); } -static void ParsePdta(SFFile *sf2, FileReader *f, uint32_t chunklen) +static void ParsePdta(SFFile *sf2, FileRdr &f, uint32_t chunklen) { ParseLIST(sf2, f, chunklen, PdtaHandlers); } -static void ParsePhdr(SFFile *sf2, FileReader *f, uint32_t chunkid, uint32_t chunklen) +static void ParsePhdr(SFFile *sf2, FileRdr &f, uint32_t chunkid, uint32_t chunklen) { SFPreset *preset; @@ -477,7 +477,7 @@ static void ParsePhdr(SFFile *sf2, FileReader *f, uint32_t chunkid, uint32_t chu } } -static void ParseBag(SFFile *sf2, FileReader *f, uint32_t chunkid, uint32_t chunklen) +static void ParseBag(SFFile *sf2, FileRdr &f, uint32_t chunkid, uint32_t chunklen) { SFBag *bags, *bag; uint16_t prev_mod = 0; @@ -539,7 +539,7 @@ static void ParseBag(SFFile *sf2, FileReader *f, uint32_t chunkid, uint32_t chun } } -static void ParseMod(SFFile *sf2, FileReader *f, uint32_t chunkid, uint32_t chunklen) +static void ParseMod(SFFile *sf2, FileRdr &f, uint32_t chunkid, uint32_t chunklen) { // Section 7.4, page 23: // It [the PMOD sub-chunk] is always a multiple of ten bytes in length, @@ -552,7 +552,7 @@ static void ParseMod(SFFile *sf2, FileReader *f, uint32_t chunkid, uint32_t chun skip_chunk(f, chunklen); } -static void ParseGen(SFFile *sf2, FileReader *f, uint32_t chunkid, uint32_t chunklen) +static void ParseGen(SFFile *sf2, FileRdr &f, uint32_t chunkid, uint32_t chunklen) { SFGenList *gens, *gen; int numgens; @@ -604,7 +604,7 @@ static void ParseGen(SFFile *sf2, FileReader *f, uint32_t chunkid, uint32_t chun } } -static void ParseInst(SFFile *sf2, FileReader *f, uint32_t chunkid, uint32_t chunklen) +static void ParseInst(SFFile *sf2, FileRdr &f, uint32_t chunkid, uint32_t chunklen) { int i; SFInst *inst; @@ -639,7 +639,7 @@ static void ParseInst(SFFile *sf2, FileReader *f, uint32_t chunkid, uint32_t chu } } -static void ParseShdr(SFFile *sf2, FileReader *f, uint32_t chunkid, uint32_t chunklen) +static void ParseShdr(SFFile *sf2, FileRdr &f, uint32_t chunkid, uint32_t chunklen) { int i; SFSample *sample; @@ -698,7 +698,7 @@ static void ParseShdr(SFFile *sf2, FileReader *f, uint32_t chunkid, uint32_t chu } -SFFile *ReadSF2(const char *filename, FileReader *f) +SFFile *ReadSF2(const char *filename, FileRdr &f) { SFFile *sf2 = NULL; uint32_t filelen; @@ -1508,33 +1508,32 @@ void SFFile::ApplyGeneratorsToRegion(SFGenComposite *gen, SFSample *sfsamp, Rend void SFFile::LoadSample(SFSample *sample) { - FileReader *fp = gus_sfreader->LookupFile(Filename).first; + FileRdr fp = gus_sfreader->LookupFile(Filename).first; uint32_t i; - if (fp == NULL) + if (!fp.isOpen()) { return; } sample->InMemoryData = new float[sample->End - sample->Start + 1]; - fp->Seek(SampleDataOffset + sample->Start * 2, SEEK_SET); + fp.Seek(SampleDataOffset + sample->Start * 2, FileRdr::SeekSet); // Load 16-bit sample data. for (i = 0; i < sample->End - sample->Start; ++i) { int16_t samp; - *fp >> samp; + fp >> samp; sample->InMemoryData[i] = samp / 32768.f; } if (SampleDataLSBOffset != 0) { // Load lower 8 bits of 24-bit sample data. - fp->Seek(SampleDataLSBOffset + sample->Start, SEEK_SET); + fp.Seek(SampleDataLSBOffset + sample->Start, FileRdr::SeekSet); for (i = 0; i < sample->End - sample->Start; ++i) { uint8_t samp; - *fp >> samp; + fp >> samp; sample->InMemoryData[i] = ((((int32_t(sample->InMemoryData[i] * 32768) << 8) | samp) << 8) >> 8) / 8388608.f; } } // Final 0 byte is for interpolation. sample->InMemoryData[i] = 0; - delete fp; } diff --git a/src/sound/timidity/sf2.h b/src/sound/timidity/sf2.h index 26d413ab56..ada4ff2020 100644 --- a/src/sound/timidity/sf2.h +++ b/src/sound/timidity/sf2.h @@ -315,4 +315,4 @@ struct SFFile : public Timidity::FontFile int NumSamples; }; -SFFile *ReadSF2(const char *filename, FileReader *f); +SFFile *ReadSF2(const char *filename, FileRdr &f); diff --git a/src/sound/timidity/timidity.cpp b/src/sound/timidity/timidity.cpp index 4c9efe0ac7..34f66b248f 100644 --- a/src/sound/timidity/timidity.cpp +++ b/src/sound/timidity/timidity.cpp @@ -82,7 +82,7 @@ static bool InitReader(const char *config_file) static int read_config_file(const char *name, bool ismain) { - FileReader *fp; + FileRdr fp; char tmp[1024], *cp; ToneBank *bank = NULL; int i, j, k, line = 0, words; @@ -103,12 +103,12 @@ static int read_config_file(const char *name, bool ismain) { fp = gus_sfreader->LookupFile(name).first; } - if (fp == nullptr) + if (!fp .isOpen()) { return -1; } - while (fp->Gets(tmp, sizeof(tmp))) + while (fp.Gets(tmp, sizeof(tmp))) { line++; FCommandLine w(tmp, true); @@ -207,7 +207,6 @@ static int read_config_file(const char *name, bool ismain) if (words < 2) { Printf("%s: line %d: No soundfont given\n", name, line); - delete fp; return -2; } if (words > 2 && !strcmp(w[2], "remove")) @@ -223,7 +222,6 @@ static int read_config_file(const char *name, bool ismain) if (!(cp = strchr(w[i], '='))) { Printf("%s: line %d: bad soundfont option %s\n", name, line, w[i]); - delete fp; return -2; } } @@ -241,7 +239,6 @@ static int read_config_file(const char *name, bool ismain) if (words < 3) { Printf("%s: line %d: syntax error\n", name, line); - delete fp; return -2; } @@ -258,7 +255,6 @@ static int read_config_file(const char *name, bool ismain) else { Printf("%s: line %d: font subcommand must be 'order' or 'exclude'\n", name, line); - delete fp; return -2; } if (i < words) @@ -312,7 +308,6 @@ static int read_config_file(const char *name, bool ismain) if (words < 2) { Printf("%s: line %d: No directory given\n", name, line); - delete fp; return -2; } for (i = 1; i < words; i++) @@ -340,7 +335,6 @@ static int read_config_file(const char *name, bool ismain) if (words != 2) { Printf("%s: line %d: Must specify exactly one patch name\n", name, line); - delete fp; return -2; } def_instr_name = w[1]; @@ -350,14 +344,12 @@ static int read_config_file(const char *name, bool ismain) if (words < 2) { Printf("%s: line %d: No drum set number given\n", name, line); - delete fp; return -2; } i = atoi(w[1]); if (i < 0 || i > 127) { Printf("%s: line %d: Drum set must be between 0 and 127\n", name, line); - delete fp; return -2; } if (drumset[i] == NULL) @@ -371,14 +363,12 @@ static int read_config_file(const char *name, bool ismain) if (words < 2) { Printf("%s: line %d: No bank number given\n", name, line); - delete fp; return -2; } i = atoi(w[1]); if (i < 0 || i > 127) { Printf("%s: line %d: Tone bank must be between 0 and 127\n", name, line); - delete fp; return -2; } if (tonebank[i] == NULL) @@ -392,20 +382,17 @@ static int read_config_file(const char *name, bool ismain) if ((words < 2) || (*w[0] < '0' || *w[0] > '9')) { Printf("%s: line %d: syntax error\n", name, line); - delete fp; return -2; } i = atoi(w[0]); if (i < 0 || i > 127) { Printf("%s: line %d: Program must be between 0 and 127\n", name, line); - delete fp; return -2; } if (bank == NULL) { Printf("%s: line %d: Must specify tone bank or drum set before assignment\n", name, line); - delete fp; return -2; } bank->tone[i].note = bank->tone[i].pan = @@ -440,7 +427,6 @@ static int read_config_file(const char *name, bool ismain) if (!(cp=strchr(w[j], '='))) { Printf("%s: line %d: bad patch option %s\n", name, line, w[j]); - delete fp; return -2; } *cp++ = 0; @@ -454,7 +440,6 @@ static int read_config_file(const char *name, bool ismain) if ((k < 0 || k > 127) || (*cp < '0' || *cp > '9')) { Printf("%s: line %d: note must be between 0 and 127\n", name, line); - delete fp; return -2; } bank->tone[i].note = k; @@ -474,7 +459,6 @@ static int read_config_file(const char *name, bool ismain) { Printf("%s: line %d: panning must be left, right, " "center, or between -100 and 100\n", name, line); - delete fp; return -2; } bank->tone[i].pan = k; @@ -488,7 +472,6 @@ static int read_config_file(const char *name, bool ismain) else { Printf("%s: line %d: keep must be env or loop\n", name, line); - delete fp; return -2; } } @@ -503,28 +486,17 @@ static int read_config_file(const char *name, bool ismain) else { Printf("%s: line %d: strip must be env, loop, or tail\n", name, line); - delete fp; return -2; } } else { Printf("%s: line %d: bad patch option %s\n", name, line, w[j]); - delete fp; return -2; } } } } - /* - if (ferror(fp)) - { - Printf("Can't read %s: %s\n", name, strerror(errno)); - close_file(fp); - return -2; - } - */ - delete fp; return 0; } diff --git a/src/sound/timidity/timidity.h b/src/sound/timidity/timidity.h index 2f923b6977..710aecc558 100644 --- a/src/sound/timidity/timidity.h +++ b/src/sound/timidity/timidity.h @@ -21,8 +21,7 @@ #define TIMIDITY_H #include "doomtype.h" - -class FileReader; +#include "files.h" namespace Timidity { @@ -362,7 +361,7 @@ void font_order(int order, int bank, int preset, int keynote); Instrument *load_instrument_font(struct Renderer *song, const char *font, int drum, int bank, int instrument); Instrument *load_instrument_font_order(struct Renderer *song, int order, int drum, int bank, int instrument); -FontFile *ReadDLS(const char *filename, FileReader *f); +FontFile *ReadDLS(const char *filename, FileRdr &f); /* mix.h diff --git a/src/sound/timiditypp/common.cpp b/src/sound/timiditypp/common.cpp index b323a85d7e..62f331c870 100644 --- a/src/sound/timiditypp/common.cpp +++ b/src/sound/timiditypp/common.cpp @@ -130,7 +130,7 @@ double flt_rand() struct timidity_file *open_file(const char *name, FSoundFontReader *sfreader) { - FileReader *fr; + FileRdr fr; FString filename; if (name == nullptr) { @@ -140,60 +140,56 @@ struct timidity_file *open_file(const char *name, FSoundFontReader *sfreader) else { auto res = sfreader->LookupFile(name); - fr = res.first; + fr = std::move(res.first); filename = res.second; } - if (fr == nullptr) return nullptr; + if (!fr.isOpen()) return nullptr; auto tf = new timidity_file; - tf->url = fr; + tf->url = std::move(fr); tf->filename = filename.GetChars(); return tf; } /* This closes files opened with open_file */ -void close_file(struct timidity_file *tf) +void tf_close(struct timidity_file *tf) { - if (tf->url != NULL) - { - tf->url->Close(); - delete tf->url; - } + tf->url.Close(); delete tf; } /* This is meant for skipping a few bytes. */ void skip(struct timidity_file *tf, size_t len) { - tf->url->Seek((long)len, SEEK_CUR); + tf->url.Seek((long)len, FileRdr::SeekCur); } char *tf_gets(char *buff, int n, struct timidity_file *tf) { - return tf->url->Gets(buff, n); + return tf->url.Gets(buff, n); } int tf_getc(struct timidity_file *tf) { unsigned char c; - auto read = tf->url->Read(&c, 1); + auto read = tf->url.Read(&c, 1); return read == 0 ? EOF : c; } long tf_read(void *buff, int32_t size, int32_t nitems, struct timidity_file *tf) { - return tf->url->Read(buff, size * nitems) / size; + return (long)tf->url.Read(buff, size * nitems) / size; } long tf_seek(struct timidity_file *tf, long offset, int whence) { - return tf->url->Seek(offset, whence); + return (long)tf->url.Seek(offset, (FileRdr::ESeek)whence); } long tf_tell(struct timidity_file *tf) { - return tf->url->Tell(); + return (long)tf->url.Tell(); } } diff --git a/src/sound/timiditypp/common.h b/src/sound/timiditypp/common.h index d288a1f0f7..c0d721a567 100644 --- a/src/sound/timiditypp/common.h +++ b/src/sound/timiditypp/common.h @@ -35,12 +35,12 @@ namespace TimidityPlus struct timidity_file { - FileReader *url; + FileRdr url; std::string filename; }; extern struct timidity_file *open_file(const char *name, FSoundFontReader *); -extern void close_file(struct timidity_file *tf); +extern void tf_close(struct timidity_file *tf); extern void skip(struct timidity_file *tf, size_t len); extern char *tf_gets(char *buff, int n, struct timidity_file *tf); int tf_getc(struct timidity_file *tf); diff --git a/src/sound/timiditypp/configfile.cpp b/src/sound/timiditypp/configfile.cpp index 80b4f54f58..4d728f5ed1 100644 --- a/src/sound/timiditypp/configfile.cpp +++ b/src/sound/timiditypp/configfile.cpp @@ -43,7 +43,7 @@ namespace TimidityPlus ctl_cmsg(CMSG_ERROR, VERB_NORMAL, \ "Too many errors... Give up read %s", name); \ reuse_mblock(&varbuf); \ - close_file(tf); return 1; } + tf_close(tf); return 1; } typedef struct { @@ -1427,7 +1427,7 @@ int Instruments::read_config_file(const char *name, int self, int allow_missing_ continue; case READ_CONFIG_RECURSION: reuse_mblock(&varbuf); - close_file(tf); + tf_close(tf); return READ_CONFIG_RECURSION; case READ_CONFIG_FILE_NOT_FOUND: break; @@ -1610,7 +1610,7 @@ int Instruments::read_config_file(const char *name, int self, int allow_missing_ } } reuse_mblock(&varbuf); - close_file(tf); + tf_close(tf); return (errcnt == 0) ? READ_CONFIG_SUCCESS : READ_CONFIG_ERROR; } diff --git a/src/sound/timiditypp/instrum.cpp b/src/sound/timiditypp/instrum.cpp index 988da87307..86053e5186 100644 --- a/src/sound/timiditypp/instrum.cpp +++ b/src/sound/timiditypp/instrum.cpp @@ -667,20 +667,20 @@ Instrument *Instruments::load_gus_instrument(char *name, ToneBank *bank, int dr, && memcmp(tmp, "GF1PATCH100\0ID#000002", 22))) { /* don't know what the differences are */ ctl_cmsg(CMSG_ERROR, VERB_NORMAL, "%s: not an instrument", name); - close_file(tf); + tf_close(tf); return 0; } /* instruments. To some patch makers, 0 means 1 */ if (tmp[82] != 1 && tmp[82] != 0) { ctl_cmsg(CMSG_ERROR, VERB_NORMAL, "Can't handle patches with %d instruments", tmp[82]); - close_file(tf); + tf_close(tf); return 0; } if (tmp[151] != 1 && tmp[151] != 0) { /* layers. What's a layer? */ ctl_cmsg(CMSG_ERROR, VERB_NORMAL, "Can't handle instruments with %d layers", tmp[151]); - close_file(tf); + tf_close(tf); return 0; } ip = (Instrument *)safe_malloc(sizeof(Instrument)); @@ -697,7 +697,7 @@ Instrument *Instruments::load_gus_instrument(char *name, ToneBank *bank, int dr, free(ip->sample[j].data); free(ip->sample); free(ip); - close_file(tf); + tf_close(tf); return 0; } sp = &(ip->sample[i]); @@ -964,7 +964,7 @@ Instrument *Instruments::load_gus_instrument(char *name, ToneBank *bank, int dr, ctl_cmsg(CMSG_INFO, VERB_DEBUG, " - Stripping tail"); } } - close_file(tf); + tf_close(tf); store_instrument_cache(ip, name, panning, amp, note_to_use, strip_loop, strip_envelope, strip_tail); return ip; diff --git a/src/sound/timiditypp/smplfile.cpp b/src/sound/timiditypp/smplfile.cpp index e34703004d..b482796dbf 100644 --- a/src/sound/timiditypp/smplfile.cpp +++ b/src/sound/timiditypp/smplfile.cpp @@ -283,10 +283,10 @@ int Instruments::import_wave_discriminant(char *sample_file) if (tf_read(buf, 12, 1, tf) != 1 || memcmp(&buf[0], "RIFF", 4) != 0 || memcmp(&buf[8], "WAVE", 4) != 0) { - close_file(tf); + tf_close(tf); return 1; } - close_file(tf); + tf_close(tf); return 0; } @@ -314,7 +314,7 @@ int Instruments::import_wave_load(char *sample_file, Instrument *inst) if (tf_read(buf, 12, 1, tf) != 1 || memcmp(&buf[0], "RIFF", 4) != 0 || memcmp(&buf[8], "WAVE", 4) != 0) { - close_file(tf); + tf_close(tf); return 1; } //ctl_cmsg(CMSG_INFO,VERB_NOISY,"Loading WAV: %s", sample_file); @@ -378,7 +378,7 @@ int Instruments::import_wave_load(char *sample_file, Instrument *inst) type_index = 4 - (chunk_size & 1); type_size = 8 + (chunk_size & 1); } - close_file(tf); + tf_close(tf); if (chunk_flags & WAVE_CHUNKFLAG_SAMPLER) { uint8_t modes; @@ -557,10 +557,10 @@ int Instruments::import_aiff_discriminant(char *sample_file) || memcmp(&buf[0], "FORM", 4) != 0 || memcmp(&buf[8], "AIF", 3) != 0 || (buf[8 + 3] != 'F' && buf[8 + 3] != 'C')) { - close_file(tf); + tf_close(tf); return 1; } - close_file(tf); + tf_close(tf); return 0; } @@ -597,7 +597,7 @@ int Instruments::import_aiff_load(char *sample_file, Instrument *inst) || memcmp(&buf[0], "FORM", 4) != 0 || memcmp(&buf[8], "AIF", 3) != 0 || (buf[8 + 3] != 'F' && buf[8 + 3] != 'C')) { - close_file(tf); + tf_close(tf); return 1; } compressed = buf[8 + 3] == 'C'; @@ -684,7 +684,7 @@ int Instruments::import_aiff_load(char *sample_file, Instrument *inst) { if (marker_data != NULL) free(marker_data); - close_file(tf); + tf_close(tf); return -1; } if (!(chunk_flags & AIFF_CHUNKFLAG_SOUNDREAD)) @@ -693,7 +693,7 @@ int Instruments::import_aiff_load(char *sample_file, Instrument *inst) { if (marker_data != NULL) free(marker_data); - close_file(tf); + tf_close(tf); return 1; } } @@ -729,7 +729,7 @@ int Instruments::import_aiff_load(char *sample_file, Instrument *inst) } if (marker_data != NULL) free(marker_data); - close_file(tf); + tf_close(tf); return 0; } diff --git a/src/sound/timiditypp/sndfont.cpp b/src/sound/timiditypp/sndfont.cpp index 9e0e51d18f..e969e4de40 100644 --- a/src/sound/timiditypp/sndfont.cpp +++ b/src/sound/timiditypp/sndfont.cpp @@ -223,10 +223,7 @@ void Instruments::free_soundfonts() SFInsts *sf, *next; for (sf = sfrecs; sf != NULL; sf = next) { - if ((sf->tf != NULL) && (sf->tf->url != NULL)) - free(sf->tf->url); - if (sf->tf != NULL) - free(sf->tf); + tf_close(sf->tf); reuse_mblock(&sf->pool); next = sf->next; free(sf); @@ -308,7 +305,7 @@ void Instruments::init_sf(SFInsts *rec) free_soundfont(&sfinfo); if (opt_sf_close_each_file) { - close_file(rec->tf); + tf_close(rec->tf); rec->tf = NULL; } } @@ -324,7 +321,7 @@ void Instruments::init_load_soundfont(void) void Instruments::end_soundfont(SFInsts *rec) { if (rec->tf) { - close_file(rec->tf); + tf_close(rec->tf); rec->tf = NULL; } @@ -383,7 +380,7 @@ Instrument *Instruments::try_load_soundfont(SFInsts *rec, int order, int bank,in inst = load_from_file(rec, ip); if (opt_sf_close_each_file) { - close_file(rec->tf); + tf_close(rec->tf); rec->tf = NULL; } diff --git a/src/sound/wildmidi/file_io.cpp b/src/sound/wildmidi/file_io.cpp index fa7910a2c3..6d20ccba5c 100644 --- a/src/sound/wildmidi/file_io.cpp +++ b/src/sound/wildmidi/file_io.cpp @@ -60,7 +60,7 @@ bool _WM_InitReader(const char *config_file) unsigned char *_WM_BufferFile(const char *filename, unsigned long int *size) { - FileReader *fp; + FileRdr fp; if (filename == nullptr) { @@ -72,13 +72,13 @@ unsigned char *_WM_BufferFile(const char *filename, unsigned long int *size) fp = wm_sfreader->OpenFile(filename); } - if (fp == NULL) + if (!fp.isOpen()) { _WM_ERROR(__FUNCTION__, __LINE__, WM_ERR_LOAD, filename, errno); return NULL; } - long fsize = fp->GetLength(); + auto fsize = fp.GetLength(); if (fsize > WM_MAXFILESIZE) { @@ -95,9 +95,8 @@ unsigned char *_WM_BufferFile(const char *filename, unsigned long int *size) return NULL; } - fp->Read(data, fsize); - delete fp; + fp.Read(data, fsize); data[fsize] = 0; - *size = fsize; + *size = (long)fsize; return data; } diff --git a/src/sound/wildmidi/wildmidi_lib.cpp b/src/sound/wildmidi/wildmidi_lib.cpp index 87afc16ded..ee0f085eee 100644 --- a/src/sound/wildmidi/wildmidi_lib.cpp +++ b/src/sound/wildmidi/wildmidi_lib.cpp @@ -676,7 +676,7 @@ static int WM_LoadConfig(const char *config_file, bool main) { int token_count = 0; auto config_parm = config_file; - FileReader *fr = nullptr; + FileRdr fr; if (main) { if (!_WM_InitReader(config_file)) return -1; // unable to open this as a config file. From b315bc3be060dfe4875f63cf4b768f6238bbd3cc Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Sat, 10 Mar 2018 20:33:49 +0100 Subject: [PATCH 20/89] - added a few more FileRdr replacements - fixed: The streaming music player must return the file reader if it fails to open, so that the next player can still use it. - fixed: Timidity++'s Instruments class did not delete the sound font when it was destroyed. ..- --- src/d_dehacked.cpp | 6 +++--- src/g_game.cpp | 4 ++-- src/m_misc.cpp | 6 +++--- src/sc_man.cpp | 4 ++-- src/sound/i_soundfont.cpp | 12 ++++++------ src/sound/mpg123_decoder.cpp | 3 ++- src/sound/sndfile_decoder.cpp | 3 ++- src/sound/timiditypp/instrum.cpp | 2 ++ src/textures/buildtexture.cpp | 6 +++--- 9 files changed, 25 insertions(+), 21 deletions(-) diff --git a/src/d_dehacked.cpp b/src/d_dehacked.cpp index ddabdb7721..d92aef424c 100644 --- a/src/d_dehacked.cpp +++ b/src/d_dehacked.cpp @@ -2492,11 +2492,11 @@ bool D_LoadDehLump(int lumpnum) bool D_LoadDehFile(const char *patchfile) { - FileReader fr; + FileRdr fr; - if (fr.Open(patchfile)) + if (fr.OpenFile(patchfile)) { - PatchSize = fr.GetLength(); + PatchSize = (int)fr.GetLength(); PatchName = copystring(patchfile); PatchFile = new char[PatchSize + 1]; diff --git a/src/g_game.cpp b/src/g_game.cpp index 2ca349631e..836805677f 100644 --- a/src/g_game.cpp +++ b/src/g_game.cpp @@ -2801,8 +2801,8 @@ void G_DoPlayDemo (void) { FixPathSeperator (defdemoname); DefaultExtension (defdemoname, ".lmp"); - FileReader fr; - if (!fr.Open(defdemoname)) + FileRdr fr; + if (!fr.OpenFile(defdemoname)) { I_Error("Unable to open demo '%s'", defdemoname.GetChars()); } diff --git a/src/m_misc.cpp b/src/m_misc.cpp index 481f956b51..4f13802ce0 100644 --- a/src/m_misc.cpp +++ b/src/m_misc.cpp @@ -121,15 +121,15 @@ void M_FindResponseFile (void) if (added_stuff < limit) { // READ THE RESPONSE FILE INTO MEMORY - FileReader fr; - if (!fr.Open(Args->GetArg(i) + 1)) + FileRdr fr; + if (!fr.OpenFile(Args->GetArg(i) + 1)) { // [RH] Make this a warning, not an error. Printf ("No such response file (%s)!\n", Args->GetArg(i) + 1); } else { Printf ("Found response file %s!\n", Args->GetArg(i) + 1); - size = fr.GetLength(); + size = (int)fr.GetLength(); file = new char[size+1]; fr.Read (file, size); file[size] = 0; diff --git a/src/sc_man.cpp b/src/sc_man.cpp index b78b7a305e..2056ca60b0 100644 --- a/src/sc_man.cpp +++ b/src/sc_man.cpp @@ -248,8 +248,8 @@ bool FScanner::OpenFile (const char *name) { Close (); - FileReader fr; - if (!fr.Open(name)) return false; + FileRdr fr; + if (!fr.OpenFile(name)) return false; auto filesize = fr.GetLength(); auto filebuf = new uint8_t[filesize]; if (fr.Read(filebuf, filesize) != filesize) diff --git a/src/sound/i_soundfont.cpp b/src/sound/i_soundfont.cpp index 38b1f70b77..e807261107 100644 --- a/src/sound/i_soundfont.cpp +++ b/src/sound/i_soundfont.cpp @@ -291,8 +291,8 @@ void FSoundFontManager::ProcessOneFile(const FString &fn) if (!sfi.mName.CompareNoCase(fb)) return; } - FileReader fr; - if (fr.Open(fn)) + FileRdr fr; + if (fr.OpenFile(fn)) { // Try to identify. We only accept .sf2 and .zip by content. All other archives are intentionally ignored. char head[16] = { 0}; @@ -433,8 +433,8 @@ FSoundFontReader *FSoundFontManager::OpenSoundFont(const char *name, int allowed // Next check if the file is a .sf file if (allowed & SF_SF2) { - FileReader fr; - if (fr.Open(name)) + FileRdr fr; + if (fr.OpenFile(name)) { char head[16] = { 0}; fr.Read(head, 16); @@ -447,8 +447,8 @@ FSoundFontReader *FSoundFontManager::OpenSoundFont(const char *name, int allowed } if (allowed & SF_GUS) { - FileReader fr; - if (fr.Open(name)) + FileRdr fr; + if (fr.OpenFile(name)) { char head[16] = { 0 }; fr.Read(head, 2); diff --git a/src/sound/mpg123_decoder.cpp b/src/sound/mpg123_decoder.cpp index db3489aa06..0a2f9fa2e8 100644 --- a/src/sound/mpg123_decoder.cpp +++ b/src/sound/mpg123_decoder.cpp @@ -145,7 +145,8 @@ bool MPG123Decoder::open(FileRdr &reader) MPG123 = 0; } - return false; + reader = std::move(Reader); // need to give it back. + return false; } void MPG123Decoder::getInfo(int *samplerate, ChannelConfig *chans, SampleType *type) diff --git a/src/sound/sndfile_decoder.cpp b/src/sound/sndfile_decoder.cpp index 07c7c81c31..ef24748aa5 100644 --- a/src/sound/sndfile_decoder.cpp +++ b/src/sound/sndfile_decoder.cpp @@ -127,7 +127,8 @@ bool SndFileDecoder::open(FileRdr &reader) sf_close(SndFile); SndFile = 0; } - return false; + reader = std::move(Reader); // need to give it back. + return false; } void SndFileDecoder::getInfo(int *samplerate, ChannelConfig *chans, SampleType *type) diff --git a/src/sound/timiditypp/instrum.cpp b/src/sound/timiditypp/instrum.cpp index 86053e5186..ddd0d8fab2 100644 --- a/src/sound/timiditypp/instrum.cpp +++ b/src/sound/timiditypp/instrum.cpp @@ -75,6 +75,8 @@ Instruments::~Instruments() free_tone_bank(); free_instrument_map(); + + if (sfreader != nullptr) delete sfreader; } void Instruments::free_instrument(Instrument *ip) diff --git a/src/textures/buildtexture.cpp b/src/textures/buildtexture.cpp index d23e5e6f2f..78d606a7ef 100644 --- a/src/textures/buildtexture.cpp +++ b/src/textures/buildtexture.cpp @@ -306,14 +306,14 @@ int FTextureManager::CountBuildTiles () FString artpath = rffpath; artpath += artfile; - FileReader fr; + FileRdr fr; - if (!fr.Open(artpath)) + if (!fr.OpenFile(artpath)) { break; } - long len = fr.GetLength(); + auto len = fr.GetLength(); uint8_t *art = new uint8_t[len]; if (fr.Read (art, len) != len || (numtiles = CountTiles(art)) == 0) { From 6f8ca2eace1ca5ea346d4c3d4c475d104826065b Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Sat, 10 Mar 2018 20:47:17 +0100 Subject: [PATCH 21/89] - fixed a few issues from implicit FileReader conversion. --- src/files.h | 2 +- src/sound/i_soundfont.cpp | 12 +++++++----- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/src/files.h b/src/files.h index b40526c2c0..dc7022882b 100644 --- a/src/files.h +++ b/src/files.h @@ -514,7 +514,7 @@ public: FileRdr() {} // These two functions are only needed as long as the FileReader has not been fully replaced throughout the code. - FileRdr(FileReader *r) + explicit FileRdr(FileReader *r) { mReader = r; } diff --git a/src/sound/i_soundfont.cpp b/src/sound/i_soundfont.cpp index e807261107..1416e380ea 100644 --- a/src/sound/i_soundfont.cpp +++ b/src/sound/i_soundfont.cpp @@ -119,11 +119,12 @@ FSF2Reader::FSF2Reader(const char *fn) FileRdr FSF2Reader::OpenMainConfigFile() { + FileRdr fr; if (mMainConfigForSF2.IsNotEmpty()) { - return new MemoryReader(mMainConfigForSF2.GetChars(), (long)mMainConfigForSF2.Len()); + fr.OpenMemory(mMainConfigForSF2.GetChars(), mMainConfigForSF2.Len()); } - return nullptr; + return fr; } FileRdr FSF2Reader::OpenFile(const char *name) @@ -159,15 +160,16 @@ FileRdr FZipPatReader::OpenMainConfigFile() FileRdr FZipPatReader::OpenFile(const char *name) { + FileRdr fr; if (resf != nullptr) { auto lump = resf->FindLump(name); if (lump != nullptr) { - return lump->NewReader(); + return FileRdr(lump->NewReader()); // temporary workaround } } - return nullptr; + return fr; } //========================================================================== @@ -258,7 +260,7 @@ FLumpPatchSetReader::FLumpPatchSetReader(const char *filename) FileRdr FLumpPatchSetReader::OpenMainConfigFile() { - return Wads.ReopenLumpNum(mLumpIndex); + return Wads.ReopenLumpReader(mLumpIndex); } FileRdr FLumpPatchSetReader::OpenFile(const char *name) From 247785bca27572eff381e9471997065167675116 Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Sat, 10 Mar 2018 21:48:33 +0100 Subject: [PATCH 22/89] - converted map loader to FileRdr and took the opportunity to clean up its interface. --- src/md5.cpp | 6 +-- src/md5.h | 4 +- src/p_acs.cpp | 4 +- src/p_acs.h | 6 +-- src/p_conversation.cpp | 27 ++++++-------- src/p_conversation.h | 2 +- src/p_glnodes.cpp | 14 +++---- src/p_setup.cpp | 85 ++++++++++++++++++++---------------------- src/p_setup.h | 83 +++++++++++++++++++++++++---------------- src/p_usdf.cpp | 6 +-- src/w_wad.cpp | 16 ++++---- 11 files changed, 131 insertions(+), 122 deletions(-) diff --git a/src/md5.cpp b/src/md5.cpp index d345e00d61..e8257b597e 100644 --- a/src/md5.cpp +++ b/src/md5.cpp @@ -95,16 +95,16 @@ void MD5Context::Update(const uint8_t *buf, unsigned len) memcpy(in, buf, len); } -void MD5Context::Update(FileReader *file, unsigned len) +void MD5Context::Update(FileRdr &file, unsigned len) { uint8_t readbuf[8192]; long t; - while (len != 0) + while (len > 0) { t = MIN(len, sizeof(readbuf)); len -= t; - t = file->Read(readbuf, t); + t = (long)file.Read(readbuf, t); Update(readbuf, t); } } diff --git a/src/md5.h b/src/md5.h index a645919db1..61714cd34c 100644 --- a/src/md5.h +++ b/src/md5.h @@ -18,7 +18,7 @@ #ifndef MD5_H #define MD5_H -class FileReader; +class FileRdr; struct MD5Context { @@ -26,7 +26,7 @@ struct MD5Context void Init(); void Update(const uint8_t *buf, unsigned len); - void Update(FileReader *file, unsigned len); + void Update(FileRdr &file, unsigned len); void Final(uint8_t digest[16]); private: diff --git a/src/p_acs.cpp b/src/p_acs.cpp index 1b6c472d80..8d1f039c35 100644 --- a/src/p_acs.cpp +++ b/src/p_acs.cpp @@ -2116,7 +2116,7 @@ void FBehavior::StaticLoadDefaultModules () } } -FBehavior *FBehavior::StaticLoadModule (int lumpnum, FileReader *fr, int len) +FBehavior *FBehavior::StaticLoadModule (int lumpnum, FileRdr *fr, int len) { if (lumpnum == -1 && fr == NULL) return NULL; @@ -2392,7 +2392,7 @@ FBehavior::FBehavior() } -bool FBehavior::Init(int lumpnum, FileReader * fr, int len) +bool FBehavior::Init(int lumpnum, FileRdr * fr, int len) { uint8_t *object; int i; diff --git a/src/p_acs.h b/src/p_acs.h index 7b0d18bd82..80853a523d 100644 --- a/src/p_acs.h +++ b/src/p_acs.h @@ -41,7 +41,7 @@ #define NUM_MAPVARS 128 class FFont; -class FileReader; +class FileRdr; struct line_t; @@ -348,7 +348,7 @@ class FBehavior public: FBehavior (); ~FBehavior (); - bool Init(int lumpnum, FileReader * fr = NULL, int len = 0); + bool Init(int lumpnum, FileRdr * fr = NULL, int len = 0); bool IsGood (); uint8_t *FindChunk (uint32_t id) const; @@ -380,7 +380,7 @@ public: BoundsCheckingArray MapVars; - static FBehavior *StaticLoadModule (int lumpnum, FileReader * fr=NULL, int len=0); + static FBehavior *StaticLoadModule (int lumpnum, FileRdr *fr = nullptr, int len=0); static void StaticLoadDefaultModules (); static void StaticUnloadModules (); static bool StaticCheckAllGood (); diff --git a/src/p_conversation.cpp b/src/p_conversation.cpp index 5d3a872a4a..e177c600ba 100644 --- a/src/p_conversation.cpp +++ b/src/p_conversation.cpp @@ -116,9 +116,9 @@ static int ConversationMenuY; static int ConversationPauseTic; static int StaticLastReply; -static bool LoadScriptFile(int lumpnum, FileReader *lump, int numnodes, bool include, int type); -static FStrifeDialogueNode *ReadRetailNode (FileReader *lump, uint32_t &prevSpeakerType); -static FStrifeDialogueNode *ReadTeaserNode (FileReader *lump, uint32_t &prevSpeakerType); +static bool LoadScriptFile(int lumpnum, FileRdr &lump, int numnodes, bool include, int type); +static FStrifeDialogueNode *ReadRetailNode (FileRdr &lump, uint32_t &prevSpeakerType); +static FStrifeDialogueNode *ReadTeaserNode (FileRdr &lump, uint32_t &prevSpeakerType); static void ParseReplies (FStrifeDialogueReply **replyptr, Response *responses); static bool DrawConversationMenu (); static void PickConversationReply (int replyindex); @@ -190,8 +190,7 @@ void P_LoadStrifeConversations (MapData *map, const char *mapname) P_FreeStrifeConversations (); if (map->Size(ML_CONVERSATION) > 0) { - map->Seek(ML_CONVERSATION); - LoadScriptFile (map->lumpnum, map->file, map->Size(ML_CONVERSATION), false, 0); + LoadScriptFile (map->lumpnum, map->Reader(ML_CONVERSATION), map->Size(ML_CONVERSATION), false, 0); } else { @@ -228,28 +227,26 @@ void P_LoadStrifeConversations (MapData *map, const char *mapname) bool LoadScriptFile (const char *name, bool include, int type) { int lumpnum = Wads.CheckNumForName (name); - FileReader *lump; if (lumpnum < 0) { return false; } - lump = Wads.ReopenLumpNum (lumpnum); + FileRdr lump = Wads.ReopenLumpReader (lumpnum); bool res = LoadScriptFile(lumpnum, lump, Wads.LumpLength(lumpnum), include, type); - delete lump; return res; } -static bool LoadScriptFile(int lumpnum, FileReader *lump, int numnodes, bool include, int type) +static bool LoadScriptFile(int lumpnum, FileRdr &lump, int numnodes, bool include, int type) { int i; uint32_t prevSpeakerType; FStrifeDialogueNode *node; char buffer[4]; - lump->Read(buffer, 4); - lump->Seek(-4, SEEK_CUR); + lump.Read(buffer, 4); + lump.Seek(-4, FileRdr::SeekCur); // The binary format is so primitive that this check is enough to detect it. bool isbinary = (buffer[0] == 0 || buffer[1] == 0 || buffer[2] == 0 || buffer[3] == 0); @@ -318,7 +315,7 @@ static bool LoadScriptFile(int lumpnum, FileReader *lump, int numnodes, bool inc // //============================================================================ -static FStrifeDialogueNode *ReadRetailNode (FileReader *lump, uint32_t &prevSpeakerType) +static FStrifeDialogueNode *ReadRetailNode (FileRdr &lump, uint32_t &prevSpeakerType) { FStrifeDialogueNode *node; Speech speech; @@ -328,7 +325,7 @@ static FStrifeDialogueNode *ReadRetailNode (FileReader *lump, uint32_t &prevSpea node = new FStrifeDialogueNode; - lump->Read (&speech, sizeof(speech)); + lump.Read (&speech, sizeof(speech)); // Byte swap all the ints in the original data speech.SpeakerType = LittleLong(speech.SpeakerType); @@ -394,7 +391,7 @@ static FStrifeDialogueNode *ReadRetailNode (FileReader *lump, uint32_t &prevSpea // //============================================================================ -static FStrifeDialogueNode *ReadTeaserNode (FileReader *lump, uint32_t &prevSpeakerType) +static FStrifeDialogueNode *ReadTeaserNode (FileRdr &lump, uint32_t &prevSpeakerType) { FStrifeDialogueNode *node; TeaserSpeech speech; @@ -404,7 +401,7 @@ static FStrifeDialogueNode *ReadTeaserNode (FileReader *lump, uint32_t &prevSpea node = new FStrifeDialogueNode; - lump->Read (&speech, sizeof(speech)); + lump.Read (&speech, sizeof(speech)); // Byte swap all the ints in the original data speech.SpeakerType = LittleLong(speech.SpeakerType); diff --git a/src/p_conversation.h b/src/p_conversation.h index 7cabc746c1..620b6f4e8d 100644 --- a/src/p_conversation.h +++ b/src/p_conversation.h @@ -78,7 +78,7 @@ void P_ResumeConversation (); void P_ConversationCommand (int netcode, int player, uint8_t **stream); class FileReader; -bool P_ParseUSDF(int lumpnum, FileReader *lump, int lumplen); +bool P_ParseUSDF(int lumpnum, FileRdr &lump, int lumplen); #endif diff --git a/src/p_glnodes.cpp b/src/p_glnodes.cpp index 60c666e82a..096eaf904e 100644 --- a/src/p_glnodes.cpp +++ b/src/p_glnodes.cpp @@ -75,7 +75,7 @@ void P_GetPolySpots (MapData * lump, TArray &spots, TA CVAR(Bool, gl_cachenodes, true, CVAR_ARCHIVE|CVAR_GLOBALCONFIG) CVAR(Float, gl_cachetime, 0.6f, CVAR_ARCHIVE|CVAR_GLOBALCONFIG) -void P_LoadZNodes (FileReader &dalump, uint32_t id); +void P_LoadZNodes (FileRdr &dalump, uint32_t id); static bool CheckCachedNodes(MapData *map); static void CreateCachedNodes(MapData *map); @@ -823,7 +823,7 @@ static int FindGLNodesInFile(FResourceFile * f, const char * label) bool P_LoadGLNodes(MapData * map) { - if (map->MapLumps[ML_GLZNODES].Reader && map->MapLumps[ML_GLZNODES].Reader->GetLength() != 0) + if (map->Size(ML_GLZNODES) != 0) { const int idcheck1a = MAKE_ID('Z','G','L','N'); const int idcheck2a = MAKE_ID('Z','G','L','2'); @@ -833,8 +833,8 @@ bool P_LoadGLNodes(MapData * map) const int idcheck3b = MAKE_ID('X','G','L','3'); int id; - map->Seek(ML_GLZNODES); - map->file->Read (&id, 4); + auto &file = map->Reader(ML_GLZNODES); + file.Read (&id, 4); if (id == idcheck1a || id == idcheck2a || id == idcheck3a || id == idcheck1b || id == idcheck2b || id == idcheck3b) { @@ -843,7 +843,7 @@ bool P_LoadGLNodes(MapData * map) level.subsectors.Clear(); level.segs.Clear(); level.nodes.Clear(); - P_LoadZNodes (*map->file, id); + P_LoadZNodes (file, id); return true; } catch (CRecoverableError &) @@ -1162,9 +1162,9 @@ static bool CheckCachedNodes(MapData *map) uint32_t *verts = NULL; FString path = CreateCacheName(map, false); - FileReader fr; + FileRdr fr; - if (!fr.Open(path)) return false; + if (!fr.OpenFile(path)) return false; if (fr.Read(magic, 4) != 4) goto errorout; if (memcmp(magic, "CACH", 4)) goto errorout; diff --git a/src/p_setup.cpp b/src/p_setup.cpp index 1ca2496070..ece2e301ac 100644 --- a/src/p_setup.cpp +++ b/src/p_setup.cpp @@ -281,7 +281,7 @@ MapData *P_OpenMapData(const char * mapname, bool justcheck) { // The following lump is from a different file so whatever this is, // it is not a multi-lump Doom level so let's assume it is a Build map. - map->MapLumps[0].Reader = map->file = Wads.ReopenLumpNum(lump_name); + map->MapLumps[0].Reader = Wads.ReopenLumpReader(lump_name); if (!P_IsBuildMap(map)) { delete map; @@ -292,7 +292,7 @@ MapData *P_OpenMapData(const char * mapname, bool justcheck) // This case can only happen if the lump is inside a real WAD file. // As such any special handling for other types of lumps is skipped. - map->MapLumps[0].Reader = map->file = Wads.ReopenLumpNum(lump_name); + map->MapLumps[0].Reader = Wads.ReopenLumpReader(lump_name); strncpy(map->MapLumps[0].Name, Wads.GetLumpFullName(lump_name), 8); map->Encrypted = Wads.IsEncryptedFile(lump_name); map->InWad = true; @@ -335,14 +335,14 @@ MapData *P_OpenMapData(const char * mapname, bool justcheck) // The next lump is not part of this map anymore if (index < 0) break; - map->MapLumps[index].Reader = Wads.ReopenLumpNum(lump_name + i); + map->MapLumps[index].Reader = Wads.ReopenLumpReader(lump_name + i); strncpy(map->MapLumps[index].Name, lumpname, 8); } } else { map->isText = true; - map->MapLumps[1].Reader = Wads.ReopenLumpNum(lump_name + 1); + map->MapLumps[1].Reader = Wads.ReopenLumpReader(lump_name + 1); for(int i = 2;; i++) { const char * lumpname = Wads.GetLumpFullName(lump_name + i); @@ -378,7 +378,7 @@ MapData *P_OpenMapData(const char * mapname, bool justcheck) break; } else continue; - map->MapLumps[index].Reader = Wads.ReopenLumpNum(lump_name + i); + map->MapLumps[index].Reader = Wads.ReopenLumpReader(lump_name + i); strncpy(map->MapLumps[index].Name, lumpname, 8); } } @@ -412,7 +412,7 @@ MapData *P_OpenMapData(const char * mapname, bool justcheck) char maplabel[9]=""; int index=0; - map->MapLumps[0].Reader = map->resource->GetLump(0)->NewReader(); + map->MapLumps[0].Reader = FileRdr(map->resource->GetLump(0)->NewReader()); strncpy(map->MapLumps[0].Name, map->resource->GetLump(0)->Name, 8); for(uint32_t i = 1; i < map->resource->LumpCount(); i++) @@ -422,7 +422,7 @@ MapData *P_OpenMapData(const char * mapname, bool justcheck) if (i == 1 && !strnicmp(lumpname, "TEXTMAP", 8)) { map->isText = true; - map->MapLumps[ML_TEXTMAP].Reader = map->resource->GetLump(i)->NewReader(); + map->MapLumps[ML_TEXTMAP].Reader = FileRdr(map->resource->GetLump(i)->NewReader()); strncpy(map->MapLumps[ML_TEXTMAP].Name, lumpname, 8); for(int i = 2;; i++) { @@ -454,7 +454,7 @@ MapData *P_OpenMapData(const char * mapname, bool justcheck) return map; } else continue; - map->MapLumps[index].Reader = map->resource->GetLump(i)->NewReader(); + map->MapLumps[index].Reader = FileRdr(map->resource->GetLump(i)->NewReader()); strncpy(map->MapLumps[index].Name, lumpname, 8); } } @@ -486,7 +486,7 @@ MapData *P_OpenMapData(const char * mapname, bool justcheck) maplabel[8]=0; } - map->MapLumps[index].Reader = map->resource->GetLump(i)->NewReader(); + map->MapLumps[index].Reader = FileRdr(map->resource->GetLump(i)->NewReader()); strncpy(map->MapLumps[index].Name, lumpname, 8); } } @@ -526,29 +526,19 @@ void MapData::GetChecksum(uint8_t cksum[16]) if (isText) { - Seek(ML_TEXTMAP); - if (file != NULL) md5.Update(file, Size(ML_TEXTMAP)); + md5.Update(Reader(ML_TEXTMAP), Size(ML_TEXTMAP)); } else { - if (Size(ML_LABEL) != 0) - { - Seek(ML_LABEL); - if (file != NULL) md5.Update(file, Size(ML_LABEL)); - } - Seek(ML_THINGS); - if (file != NULL) md5.Update(file, Size(ML_THINGS)); - Seek(ML_LINEDEFS); - if (file != NULL) md5.Update(file, Size(ML_LINEDEFS)); - Seek(ML_SIDEDEFS); - if (file != NULL) md5.Update(file, Size(ML_SIDEDEFS)); - Seek(ML_SECTORS); - if (file != NULL) md5.Update(file, Size(ML_SECTORS)); + md5.Update(Reader(ML_LABEL), Size(ML_LABEL)); + md5.Update(Reader(ML_THINGS), Size(ML_THINGS)); + md5.Update(Reader(ML_LINEDEFS), Size(ML_LINEDEFS)); + md5.Update(Reader(ML_SIDEDEFS), Size(ML_SIDEDEFS)); + md5.Update(Reader(ML_SECTORS), Size(ML_SECTORS)); } if (HasBehavior) { - Seek(ML_BEHAVIOR); - if (file != NULL) md5.Update(file, Size(ML_BEHAVIOR)); + md5.Update(Reader(ML_BEHAVIOR), Size(ML_BEHAVIOR)); } md5.Final(cksum); } @@ -847,14 +837,14 @@ void P_LoadVertexes (MapData * map) level.vertexes.Alloc(numvertexes); vertexdatas.Clear(); - map->Seek(ML_VERTEXES); + auto &fr = map->Reader(ML_VERTEXES); // Copy and convert vertex coordinates, internal representation as fixed. for (auto &v : level.vertexes) { int16_t x, y; - (*map->file) >> x >> y; + fr >> x >> y; v.set(double(x), double(y)); } } @@ -1104,7 +1094,7 @@ void LoadZNodes(FileReaderBase &data, int glnodes) // //=========================================================================== -void P_LoadZNodes (FileReader &dalump, uint32_t id) +void P_LoadZNodes (FileRdr &dalump, uint32_t id) { int type; bool compressed; @@ -1155,14 +1145,15 @@ void P_LoadZNodes (FileReader &dalump, uint32_t id) return; } + auto daptr = dalump.Reader(); if (compressed) { - FileReaderZ data (dalump); + FileReaderZ data (*daptr); LoadZNodes(data, type); } else { - LoadZNodes(dalump, type); + LoadZNodes(*daptr, type); } } @@ -1398,7 +1389,7 @@ void P_LoadSubsectors (MapData * map) auto &subsectors = level.subsectors; subsectors.Alloc(numsubsectors); - map->Seek(ML_SSECTORS); + auto &fr = map->Reader(ML_SSECTORS); memset (&subsectors[0], 0, numsubsectors*sizeof(subsector_t)); @@ -1406,7 +1397,7 @@ void P_LoadSubsectors (MapData * map) { subsectortype subd; - (*map->file) >> subd.numsegs >> subd.firstseg; + fr >> subd.numsegs >> subd.firstseg; if (subd.numsegs == 0) { @@ -3311,7 +3302,7 @@ void P_LoadReject (MapData * map, bool junk) const int neededsize = (level.sectors.Size() * level.sectors.Size() + 7) >> 3; int rejectsize; - if (strnicmp (map->MapLumps[ML_REJECT].Name, "REJECT", 8) != 0) + if (!map->CheckName(ML_REJECT, "REJECT")) { rejectsize = 0; } @@ -3335,8 +3326,7 @@ void P_LoadReject (MapData * map, bool junk) rejectsize = MIN (rejectsize, neededsize); level.rejectmatrix.Alloc(rejectsize); - map->Seek(ML_REJECT); - map->file->Read (&level.rejectmatrix[0], rejectsize); + map->Read (ML_REJECT, &level.rejectmatrix[0], rejectsize); int qwords = rejectsize / 8; int i; @@ -3375,8 +3365,7 @@ void P_LoadBehavior(MapData * map) { if (map->Size(ML_BEHAVIOR) > 0) { - map->Seek(ML_BEHAVIOR); - FBehavior::StaticLoadModule(-1, map->file, map->Size(ML_BEHAVIOR)); + FBehavior::StaticLoadModule(-1, &map->Reader(ML_BEHAVIOR), map->Size(ML_BEHAVIOR)); } if (!FBehavior::StaticCheckAllGood()) { @@ -3635,8 +3624,10 @@ void P_FreeExtraLevelData() void P_SetupLevel (const char *lumpname, int position) { cycle_t times[20]; +#if 0 FMapThing *buildthings; int numbuildthings; +#endif int i; bool buildmap; const int *oldvertextable = NULL; @@ -3709,16 +3700,18 @@ void P_SetupLevel (const char *lumpname, int position) // [RH] Support loading Build maps (because I felt like it. :-) buildmap = false; +#if 0 + // deactivated because broken. if (map->Size(0) > 0) { uint8_t *mapdata = new uint8_t[map->Size(0)]; - map->Seek(0); - map->file->Read(mapdata, map->Size(0)); + map->Read(0, mapdata); times[0].Clock(); buildmap = P_LoadBuildMap (mapdata, map->Size(0), &buildthings, &numbuildthings); times[0].Unclock(); delete[] mapdata; } +#endif if (!buildmap) { @@ -3858,19 +3851,19 @@ void P_SetupLevel (const char *lumpname, int position) if (!ForceNodeBuild) { // Check for compressed nodes first, then uncompressed nodes - FWadLump test; + FileRdr *fr; uint32_t id = MAKE_ID('X','x','X','x'), idcheck = 0, idcheck2 = 0, idcheck3 = 0, idcheck4 = 0, idcheck5 = 0, idcheck6 = 0; if (map->Size(ML_ZNODES) != 0) { // Test normal nodes first - map->Seek(ML_ZNODES); + fr = &map->Reader(ML_ZNODES); idcheck = MAKE_ID('Z','N','O','D'); idcheck2 = MAKE_ID('X','N','O','D'); } else if (map->Size(ML_GLZNODES) != 0) { - map->Seek(ML_GLZNODES); + fr = &map->Reader(ML_GLZNODES); idcheck = MAKE_ID('Z','G','L','N'); idcheck2 = MAKE_ID('Z','G','L','2'); idcheck3 = MAKE_ID('Z','G','L','3'); @@ -3879,12 +3872,12 @@ void P_SetupLevel (const char *lumpname, int position) idcheck6 = MAKE_ID('X','G','L','3'); } - map->file->Read (&id, 4); + fr->Read (&id, 4); if (id != 0 && (id == idcheck || id == idcheck2 || id == idcheck3 || id == idcheck4 || id == idcheck5 || id == idcheck6)) { try { - P_LoadZNodes (*map->file, id); + P_LoadZNodes (*fr, id); } catch (CRecoverableError &error) { @@ -4067,6 +4060,7 @@ void P_SetupLevel (const char *lumpname, int position) P_TranslateTeleportThings (); // [RH] Assign teleport destination TIDs times[15].Unclock(); } +#if 0 // There is no such thing as a build map. else { for (i = 0; i < numbuildthings; ++i) @@ -4075,6 +4069,7 @@ void P_SetupLevel (const char *lumpname, int position) } delete[] buildthings; } +#endif delete map; if (oldvertextable != NULL) { diff --git a/src/p_setup.h b/src/p_setup.h index dae64160b7..0607442e4c 100644 --- a/src/p_setup.h +++ b/src/p_setup.h @@ -34,69 +34,86 @@ struct MapData { +private: struct MapLump { - char Name[8]; - FileReader *Reader; + char Name[8] = { 0 }; + FileRdr Reader; } MapLumps[ML_MAX]; - bool HasBehavior; - bool Encrypted; - bool isText; - bool InWad; - int lumpnum; - FileReader * file; - FResourceFile * resource; - - MapData() - { - memset(MapLumps, 0, sizeof(MapLumps)); - file = NULL; - resource = NULL; - lumpnum = -1; - HasBehavior = false; - Encrypted = false; - isText = false; - InWad = false; - } + FileRdr nofile; +public: + bool HasBehavior = false; + bool Encrypted = false; + bool isText = false; + bool InWad = false; + int lumpnum = -1; + FResourceFile * resource = nullptr; ~MapData() { - for (unsigned int i = 0;i < ML_MAX;++i) - delete MapLumps[i].Reader; - - delete resource; - resource = NULL; + if (resource != nullptr) delete resource; + resource = nullptr; } + /* void Seek(unsigned int lumpindex) { if (lumpindexSeek(0, SEEK_SET); + file = &MapLumps[lumpindex].Reader; + file->Seek(0, FileRdr::SeekSet); } } + */ + + FileRdr &Reader(unsigned int lumpindex) + { + if (lumpindex < countof(MapLumps)) + { + auto &file = MapLumps[lumpindex].Reader; + file.Seek(0, FileRdr::SeekSet); + return file; + } + return nofile; + } void Read(unsigned int lumpindex, void * buffer, int size = -1) { if (lumpindexGetLength(); - Seek(lumpindex); - file->Read(buffer, size); + if (size == -1) size = Size(lumpindex); + if (size > 0) + { + auto &file = MapLumps[lumpindex].Reader; + file.Seek(0, FileRdr::SeekSet); + file.Read(buffer, size); + } } } uint32_t Size(unsigned int lumpindex) { - if (lumpindexGetLength(); + return (uint32_t)MapLumps[lumpindex].Reader.GetLength(); } return 0; } + bool CheckName(unsigned int lumpindex, const char *name) + { + if (lumpindex < countof(MapLumps)) + { + return !strnicmp(MapLumps[lumpindex].Name, name, 8); + } + return false; + } + void GetChecksum(uint8_t cksum[16]); + + friend bool P_LoadGLNodes(MapData * map); + friend MapData *P_OpenMapData(const char * mapname, bool justcheck); + }; MapData * P_OpenMapData(const char * mapname, bool justcheck); diff --git a/src/p_usdf.cpp b/src/p_usdf.cpp index 015dd97930..fe0143e94d 100644 --- a/src/p_usdf.cpp +++ b/src/p_usdf.cpp @@ -474,10 +474,10 @@ class USDFParser : public UDMFParserBase //=========================================================================== public: - bool Parse(int lumpnum, FileReader *lump, int lumplen) + bool Parse(int lumpnum, FileRdr &lump, int lumplen) { char *buffer = new char[lumplen]; - lump->Read(buffer, lumplen); + lump.Read(buffer, lumplen); sc.OpenMem(Wads.GetLumpFullName(lumpnum), buffer, lumplen); delete [] buffer; sc.SetCMode(true); @@ -532,7 +532,7 @@ public: -bool P_ParseUSDF(int lumpnum, FileReader *lump, int lumplen) +bool P_ParseUSDF(int lumpnum, FileRdr &lump, int lumplen) { USDFParser parse; diff --git a/src/w_wad.cpp b/src/w_wad.cpp index 30b9fdecc9..716b7f3222 100644 --- a/src/w_wad.cpp +++ b/src/w_wad.cpp @@ -309,7 +309,8 @@ void FWadCollection::AddFile (const char *filename, FileReader *wadinfo) { MD5Context md5; reader->Seek(0, SEEK_SET); - md5.Update(reader, reader->GetLength()); +#pragma message("This does not work!"); + //md5.Update(FileRdr(reader), reader->GetLength()); md5.Final(cksum); for (size_t j = 0; j < sizeof(cksum); ++j) @@ -329,10 +330,8 @@ void FWadCollection::AddFile (const char *filename, FileReader *wadinfo) if (!(lump->Flags & LUMPF_EMBEDDED)) { - reader = lump->NewReader(); - MD5Context md5; - md5.Update(reader, lump->LumpSize); + md5.Update(FileRdr(lump->NewReader()), lump->LumpSize); md5.Final(cksum); for (size_t j = 0; j < sizeof(cksum); ++j) @@ -343,8 +342,6 @@ void FWadCollection::AddFile (const char *filename, FileReader *wadinfo) fprintf(hashfile, "file: %s, lump: %s, hash: %s, size: %d\n", filename, lump->FullName.IsNotEmpty() ? lump->FullName.GetChars() : lump->Name, cksumout, lump->LumpSize); - - delete reader; } } } @@ -942,7 +939,8 @@ void FWadCollection::RenameNerve () } fr->Seek(0, SEEK_SET); MD5Context md5; - md5.Update(fr, fr->GetLength()); +#pragma message("This does not work yet!"); + //md5.Update(fr, fr->GetLength()); md5.Final(cksum); if (memcmp(nerve, cksum, 16) == 0) { @@ -1008,7 +1006,9 @@ void FWadCollection::FixMacHexen() uint8_t checksum[16]; MD5Context md5; - md5.Update(reader, iwadSize); + +#pragma message("This does not work yet!"); + //md5.Update(reader, iwadSize); md5.Final(checksum); static const uint8_t HEXEN_DEMO_MD5[16] = From b14ee50d0d0fad3e2de236a01d7d2dfdab83d3c9 Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Sun, 11 Mar 2018 12:33:46 +0100 Subject: [PATCH 23/89] - transition to new FileReader interface complete, but untested. --- src/CMakeLists.txt | 1 + src/d_iwad.cpp | 6 +- src/d_main.cpp | 10 +- src/files.cpp | 822 +++++++++------------------ src/files.h | 628 +++++--------------- src/files_decompress.cpp | 607 ++++++++++++++++++++ src/g_game.cpp | 4 +- src/md5.cpp | 4 +- src/menu/loadsavemenu.cpp | 4 +- src/p_conversation.h | 2 +- src/p_glnodes.cpp | 52 +- src/p_setup.cpp | 34 +- src/resourcefiles/ancientzip.cpp | 10 +- src/resourcefiles/ancientzip.h | 6 +- src/resourcefiles/file_7z.cpp | 42 +- src/resourcefiles/file_directory.cpp | 26 +- src/resourcefiles/file_grp.cpp | 20 +- src/resourcefiles/file_lump.cpp | 10 +- src/resourcefiles/file_pak.cpp | 23 +- src/resourcefiles/file_rff.cpp | 26 +- src/resourcefiles/file_wad.cpp | 232 +------- src/resourcefiles/file_zip.cpp | 82 ++- src/resourcefiles/file_zip.h | 4 +- src/resourcefiles/resourcefile.cpp | 90 ++- src/resourcefiles/resourcefile.h | 24 +- src/sound/i_soundfont.cpp | 6 +- src/textures/texture.cpp | 1 - src/textures/textures.h | 2 - src/w_wad.cpp | 326 ++--------- src/w_wad.h | 47 +- src/w_zip.h | 8 - 31 files changed, 1352 insertions(+), 1807 deletions(-) create mode 100644 src/files_decompress.cpp diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 9248964391..7dfaa9e53f 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -886,6 +886,7 @@ set (PCH_SOURCES edata.cpp f_wipe.cpp files.cpp + files_decompress.cpp g_doomedmap.cpp g_game.cpp g_hub.cpp diff --git a/src/d_iwad.cpp b/src/d_iwad.cpp index fadb9e65ba..29c3ea98b8 100644 --- a/src/d_iwad.cpp +++ b/src/d_iwad.cpp @@ -243,7 +243,7 @@ void FIWadManager::ParseIWadInfo(const char *fn, const char *data, int datasize, FIWadManager::FIWadManager(const char *fn) { - FResourceFile *resfile = FResourceFile::OpenResourceFile(fn, NULL, true); + FResourceFile *resfile = FResourceFile::OpenResourceFile(fn, true); if (resfile != NULL) { uint32_t cnt = resfile->LumpCount(); @@ -276,7 +276,7 @@ FIWadManager::FIWadManager(const char *fn) int FIWadManager::ScanIWAD (const char *iwad) { - FResourceFile *iwadfile = FResourceFile::OpenResourceFile(iwad, NULL, true); + FResourceFile *iwadfile = FResourceFile::OpenResourceFile(iwad, true); mLumpsFound.Resize(mIWadInfos.Size()); @@ -332,7 +332,7 @@ int FIWadManager::ScanIWAD (const char *iwad) int FIWadManager::CheckIWADInfo(const char *fn) { - FResourceFile *resfile = FResourceFile::OpenResourceFile(fn, NULL, true); + FResourceFile *resfile = FResourceFile::OpenResourceFile(fn, true); if (resfile != NULL) { uint32_t cnt = resfile->LumpCount(); diff --git a/src/d_main.cpp b/src/d_main.cpp index 0b03cf0987..9ec546d565 100644 --- a/src/d_main.cpp +++ b/src/d_main.cpp @@ -1947,7 +1947,6 @@ static FString CheckGameInfo(TArray & pwads) for(int i=pwads.Size()-1; i>=0; i--) { bool isdir = false; - FileReader *wadinfo; FResourceFile *resfile; const char *filename = pwads[i]; @@ -1960,16 +1959,13 @@ static FString CheckGameInfo(TArray & pwads) if (!isdir) { - try - { - wadinfo = new FileReader(filename); - } - catch (CRecoverableError &) + FileRdr fr; + if (!fr.OpenFile(filename)) { // Didn't find file continue; } - resfile = FResourceFile::OpenResourceFile(filename, wadinfo, true); + resfile = FResourceFile::OpenResourceFile(filename, fr, true); } else resfile = FResourceFile::OpenDirectory(filename, true); diff --git a/src/files.cpp b/src/files.cpp index cfd13cb7f9..b445c27898 100644 --- a/src/files.cpp +++ b/src/files.cpp @@ -33,150 +33,252 @@ ** */ -// This also pulls in windows.h -#include "LzmaDec.h" - #include "files.h" #include "i_system.h" #include "templates.h" #include "m_misc.h" + //========================================================================== // -// FileReader +// StdFileReader // -// reads data from an uncompressed file or part of it +// reads data from an stdio FILE* or part of it. // //========================================================================== -FILE *FileReader::openfd(const char *filename) +class StdFileReader : public FileReaderInterface { - return fopen(filename, "rb"); -} + FILE *File = nullptr; + long Length = 0; + long StartPos = 0; + long FilePos = 0; -FileReader::FileReader () -: File(NULL), Length(0), StartPos(0), FilePos(0), CloseOnDestruct(false) -{ -} +public: + StdFileReader() + {} -FileReader::FileReader (const FileReader &other, long length) -: File(other.File), Length(length), CloseOnDestruct(false) -{ - FilePos = StartPos = ftell (other.File); -} - -FileReader::FileReader (const char *filename) -: File(NULL), Length(0), StartPos(0), FilePos(0), CloseOnDestruct(false) -{ - if (!Open(filename)) + ~StdFileReader() { - I_Error ("Could not open %s", filename); + if (File != nullptr) + { + fclose(File); + } + File = nullptr; } -} -FileReader::FileReader (FILE *file) -: File(file), Length(0), StartPos(0), FilePos(0), CloseOnDestruct(false) -{ - Length = CalcFileLen(); -} - -FileReader::FileReader (FILE *file, long length) -: File(file), Length(length), CloseOnDestruct(true) -{ - FilePos = StartPos = ftell (file); -} - -FileReader::~FileReader() -{ - Close(); -} - -void FileReader::Close() -{ - if (CloseOnDestruct && File != NULL) + bool Open(const char *filename, long startpos = 0, long len = -1) { - fclose (File); + File = fopen(filename, "rb"); + if (File == nullptr) return false; + FilePos = startpos; + StartPos = startpos; + Length = CalcFileLen(); + if (len >= 0 && len < Length) Length = len; + if (startpos > 0) Seek(startpos, SEEK_SET); + return true; } - File = NULL; -} -bool FileReader::Open (const char *filename) -{ - File = openfd (filename); - if (File == NULL) return false; - FilePos = 0; - StartPos = 0; - CloseOnDestruct = true; - Length = CalcFileLen(); - return true; -} - - -void FileReader::ResetFilePtr () -{ - FilePos = ftell (File); -} - -long FileReader::Tell () const -{ - return FilePos - StartPos; -} - -long FileReader::Seek (long offset, int origin) -{ - if (origin == SEEK_SET) + long Tell() const override { - offset += StartPos; + return FilePos - StartPos; } - else if (origin == SEEK_CUR) + + long Seek(long offset, int origin) override { + if (origin == SEEK_SET) + { + offset += StartPos; + } + else if (origin == SEEK_CUR) + { + offset += FilePos; + } + else if (origin == SEEK_END) + { + offset += StartPos + Length; + } + if (offset < StartPos || offset >= StartPos + Length) return -1; // out of scope + + if (0 == fseek(File, offset, SEEK_SET)) + { + FilePos = offset; + return 0; + } + return -1; + } + + long Read(void *buffer, long len) override + { + assert(len >= 0); + if (len <= 0) return 0; + if (FilePos + len > StartPos + Length) + { + len = Length - FilePos + StartPos; + } + len = (long)fread(buffer, 1, len, File); + FilePos += len; + return len; + } + + char *Gets(char *strbuf, int len) override + { + if (len <= 0 || FilePos >= StartPos + Length) return NULL; + char *p = fgets(strbuf, len, File); + if (p != NULL) + { + int old = FilePos; + FilePos = ftell(File); + if (FilePos - StartPos > Length) + { + strbuf[Length - old + StartPos] = 0; + } + } + return p; + } + +private: + long CalcFileLen() const + { + long endpos; + + fseek(File, 0, SEEK_END); + endpos = ftell(File); + fseek(File, 0, SEEK_SET); + return endpos; + } +}; + +//========================================================================== +// +// FileReaderRedirect +// +// like the above, but uses another File reader as its backing data +// +//========================================================================== + +class FileReaderRedirect : public FileReaderInterface +{ + FileRdr *mReader = nullptr; + long Length = 0; + long StartPos = 0; + long FilePos = 0; + +public: + FileReaderRedirect(FileRdr &parent, long start, long length) + { + mReader = &parent; + FilePos = start; + StartPos = start; + Length = length; + Seek(0, SEEK_SET); + } + + virtual long Tell() const override + { + return FilePos - StartPos; + } + + virtual long Seek(long offset, int origin) + { + switch (origin) + { + case SEEK_SET: + offset += StartPos; + break; + + case SEEK_END: + offset += StartPos + Length; + break; + + case SEEK_CUR: + offset += (long)mReader->Tell(); + break; + } + if (offset < StartPos || offset >= StartPos + Length) return -1; // out of scope + if (mReader->Seek(offset, FileRdr::SeekSet) == 0) + { + FilePos = offset; + return 0; + } + return -1; + } + + virtual long Read(void *buffer, long len) + { + assert(len >= 0); + if (len <= 0) return 0; + if (FilePos + len > StartPos + Length) + { + len = Length - FilePos + StartPos; + } + len = (long)mReader->Read(buffer, len); + FilePos += len; + return len; + } + + virtual char *Gets(char *strbuf, int len) + { + if (len <= 0 || FilePos >= StartPos + Length) return NULL; + char *p = mReader->Gets(strbuf, len); + if (p != NULL) + { + int old = FilePos; + FilePos = (long)mReader->Tell(); + if (FilePos - StartPos > Length) + { + strbuf[Length - old + StartPos] = 0; + } + } + return p; + } + +}; + +//========================================================================== +// +// MemoryReader +// +// reads data from a block of memory +// +//========================================================================== + +long MemoryReader::Tell() const +{ + return FilePos; +} + +long MemoryReader::Seek(long offset, int origin) +{ + switch (origin) + { + case SEEK_CUR: offset += FilePos; + break; + + case SEEK_END: + offset += Length; + break; + } - else if (origin == SEEK_END) - { - offset += StartPos + Length; - } - if (0 == fseek (File, offset, SEEK_SET)) - { - FilePos = offset; - return 0; - } - return -1; + if (offset < 0 || offset >= Length) return -1; + FilePos = clamp(offset, 0, Length); + return 0; } -long FileReader::Read (void *buffer, long len) +long MemoryReader::Read(void *buffer, long len) { - assert(len >= 0); - if (len <= 0) return 0; - if (FilePos + len > StartPos + Length) - { - len = Length - FilePos + StartPos; - } - len = (long)fread (buffer, 1, len, File); + if (len>Length - FilePos) len = Length - FilePos; + if (len<0) len = 0; + memcpy(buffer, bufptr + FilePos, len); FilePos += len; return len; } -char *FileReader::Gets(char *strbuf, int len) +char *MemoryReader::Gets(char *strbuf, int len) { - if (len <= 0 || FilePos >= StartPos + Length) return NULL; - char *p = fgets(strbuf, len, File); - if (p != NULL) - { - int old = FilePos; - FilePos = ftell(File); - if (FilePos - StartPos > Length) - { - strbuf[Length - old + StartPos] = 0; - } - } - return p; -} - -char *FileReader::GetsFromBuffer(const char * bufptr, char *strbuf, int len) -{ - if (len>Length-FilePos) len=Length-FilePos; + if (len>Length - FilePos) len = Length - FilePos; if (len <= 0) return NULL; char *p = strbuf; @@ -191,7 +293,7 @@ char *FileReader::GetsFromBuffer(const char * bufptr, char *strbuf, int len) { *p++ = bufptr[FilePos]; len--; - if (bufptr[FilePos] == '\n') + if (bufptr[FilePos] == '\n') { FilePos++; break; @@ -199,360 +301,11 @@ char *FileReader::GetsFromBuffer(const char * bufptr, char *strbuf, int len) } FilePos++; } - if (p==strbuf) return NULL; - *p++=0; + if (p == strbuf) return NULL; + *p++ = 0; return strbuf; } -long FileReader::CalcFileLen() const -{ - long endpos; - - fseek (File, 0, SEEK_END); - endpos = ftell (File); - fseek (File, 0, SEEK_SET); - return endpos; -} - -//========================================================================== -// -// FileReaderZ -// -// The zlib wrapper -// reads data from a ZLib compressed stream -// -//========================================================================== - -FileReaderZ::FileReaderZ (FileReader &file, bool zip) -: File(file), SawEOF(false) -{ - int err; - - FillBuffer (); - - Stream.zalloc = Z_NULL; - Stream.zfree = Z_NULL; - - if (!zip) err = inflateInit (&Stream); - else err = inflateInit2 (&Stream, -MAX_WBITS); - - if (err != Z_OK) - { - I_Error ("FileReaderZ: inflateInit failed: %s\n", M_ZLibError(err).GetChars()); - } -} - -FileReaderZ::~FileReaderZ () -{ - inflateEnd (&Stream); -} - -long FileReaderZ::Read (void *buffer, long len) -{ - int err; - - Stream.next_out = (Bytef *)buffer; - Stream.avail_out = len; - - do - { - err = inflate (&Stream, Z_SYNC_FLUSH); - if (Stream.avail_in == 0 && !SawEOF) - { - FillBuffer (); - } - } while (err == Z_OK && Stream.avail_out != 0); - - if (err != Z_OK && err != Z_STREAM_END) - { - I_Error ("Corrupt zlib stream"); - } - - if (Stream.avail_out != 0) - { - I_Error ("Ran out of data in zlib stream"); - } - - return len - Stream.avail_out; -} - -void FileReaderZ::FillBuffer () -{ - long numread = File.Read (InBuff, BUFF_SIZE); - - if (numread < BUFF_SIZE) - { - SawEOF = true; - } - Stream.next_in = InBuff; - Stream.avail_in = numread; -} - -//========================================================================== -// -// FileReaderZ -// -// The bzip2 wrapper -// reads data from a libbzip2 compressed stream -// -//========================================================================== - -FileReaderBZ2::FileReaderBZ2 (FileReader &file) -: File(file), SawEOF(false) -{ - int err; - - FillBuffer (); - - Stream.bzalloc = NULL; - Stream.bzfree = NULL; - Stream.opaque = NULL; - - err = BZ2_bzDecompressInit(&Stream, 0, 0); - - if (err != BZ_OK) - { - I_Error ("FileReaderBZ2: bzDecompressInit failed: %d\n", err); - } -} - -FileReaderBZ2::~FileReaderBZ2 () -{ - BZ2_bzDecompressEnd (&Stream); -} - -long FileReaderBZ2::Read (void *buffer, long len) -{ - int err; - - Stream.next_out = (char *)buffer; - Stream.avail_out = len; - - do - { - err = BZ2_bzDecompress(&Stream); - if (Stream.avail_in == 0 && !SawEOF) - { - FillBuffer (); - } - } while (err == BZ_OK && Stream.avail_out != 0); - - if (err != BZ_OK && err != BZ_STREAM_END) - { - I_Error ("Corrupt bzip2 stream"); - } - - if (Stream.avail_out != 0) - { - I_Error ("Ran out of data in bzip2 stream"); - } - - return len - Stream.avail_out; -} - -void FileReaderBZ2::FillBuffer () -{ - long numread = File.Read(InBuff, BUFF_SIZE); - - if (numread < BUFF_SIZE) - { - SawEOF = true; - } - Stream.next_in = (char *)InBuff; - Stream.avail_in = numread; -} - -//========================================================================== -// -// bz_internal_error -// -// libbzip2 wants this, since we build it with BZ_NO_STDIO set. -// -//========================================================================== - -extern "C" void bz_internal_error (int errcode) -{ - I_FatalError("libbzip2: internal error number %d\n", errcode); -} - -//========================================================================== -// -// FileReaderLZMA -// -// The lzma wrapper -// reads data from a LZMA compressed stream -// -//========================================================================== - -// This is retarded but necessary to work around the inclusion of windows.h in recent -// LZMA versions, meaning it's no longer possible to include the LZMA headers in files.h. -// As a result we cannot declare the CLzmaDec member in the header so we work around -// it my wrapping it into another struct that can be declared anonymously in the header. -struct FileReaderLZMA::StreamPointer -{ - CLzmaDec Stream; -}; - -static void *SzAlloc(ISzAllocPtr, size_t size) { return malloc(size); } -static void SzFree(ISzAllocPtr, void *address) { free(address); } -ISzAlloc g_Alloc = { SzAlloc, SzFree }; - -FileReaderLZMA::FileReaderLZMA (FileReader &file, size_t uncompressed_size, bool zip) -: File(file), SawEOF(false) -{ - uint8_t header[4 + LZMA_PROPS_SIZE]; - int err; - - assert(zip == true); - - Size = uncompressed_size; - OutProcessed = 0; - - // Read zip LZMA properties header - if (File.Read(header, sizeof(header)) < (long)sizeof(header)) - { - I_Error("FileReaderLZMA: File too shart\n"); - } - if (header[2] + header[3] * 256 != LZMA_PROPS_SIZE) - { - I_Error("FileReaderLZMA: LZMA props size is %d (expected %d)\n", - header[2] + header[3] * 256, LZMA_PROPS_SIZE); - } - - FillBuffer(); - - Streamp = new StreamPointer; - LzmaDec_Construct(&Streamp->Stream); - err = LzmaDec_Allocate(&Streamp->Stream, header + 4, LZMA_PROPS_SIZE, &g_Alloc); - - if (err != SZ_OK) - { - I_Error("FileReaderLZMA: LzmaDec_Allocate failed: %d\n", err); - } - - LzmaDec_Init(&Streamp->Stream); -} - -FileReaderLZMA::~FileReaderLZMA () -{ - LzmaDec_Free(&Streamp->Stream, &g_Alloc); - delete Streamp; -} - -long FileReaderLZMA::Read (void *buffer, long len) -{ - int err; - Byte *next_out = (Byte *)buffer; - - do - { - ELzmaFinishMode finish_mode = LZMA_FINISH_ANY; - ELzmaStatus status; - size_t out_processed = len; - size_t in_processed = InSize; - - err = LzmaDec_DecodeToBuf(&Streamp->Stream, next_out, &out_processed, InBuff + InPos, &in_processed, finish_mode, &status); - InPos += in_processed; - InSize -= in_processed; - next_out += out_processed; - len = (long)(len - out_processed); - if (err != SZ_OK) - { - I_Error ("Corrupt LZMA stream"); - } - if (in_processed == 0 && out_processed == 0) - { - if (status != LZMA_STATUS_FINISHED_WITH_MARK) - { - I_Error ("Corrupt LZMA stream"); - } - } - if (InSize == 0 && !SawEOF) - { - FillBuffer (); - } - } while (err == SZ_OK && len != 0); - - if (err != Z_OK && err != Z_STREAM_END) - { - I_Error ("Corrupt LZMA stream"); - } - - if (len != 0) - { - I_Error ("Ran out of data in LZMA stream"); - } - - return (long)(next_out - (Byte *)buffer); -} - -void FileReaderLZMA::FillBuffer () -{ - long numread = File.Read(InBuff, BUFF_SIZE); - - if (numread < BUFF_SIZE) - { - SawEOF = true; - } - InPos = 0; - InSize = numread; -} - -//========================================================================== -// -// MemoryReader -// -// reads data from a block of memory -// -//========================================================================== - -MemoryReader::MemoryReader (const char *buffer, long length) -{ - bufptr=buffer; - Length=length; - FilePos=0; -} - -MemoryReader::~MemoryReader () -{ -} - -long MemoryReader::Tell () const -{ - return FilePos; -} - -long MemoryReader::Seek (long offset, int origin) -{ - switch (origin) - { - case SEEK_CUR: - offset+=FilePos; - break; - - case SEEK_END: - offset+=Length; - break; - - } - FilePos=clamp(offset,0,Length); - return 0; -} - -long MemoryReader::Read (void *buffer, long len) -{ - if (len>Length-FilePos) len=Length-FilePos; - if (len<0) len=0; - memcpy(buffer,bufptr+FilePos,len); - FilePos+=len; - return len; -} - -char *MemoryReader::Gets(char *strbuf, int len) -{ - return GetsFromBuffer(bufptr, strbuf, len); -} - //========================================================================== // // MemoryArrayReader @@ -561,57 +314,88 @@ char *MemoryReader::Gets(char *strbuf, int len) // //========================================================================== -MemoryArrayReader::MemoryArrayReader (const char *buffer, long length) +class MemoryArrayReader : public MemoryReader { - if (length > 0) + TArray buf; + +public: + MemoryArrayReader(const char *buffer, long length) { - buf.Resize(length); - memcpy(&buf[0], buffer, length); + if (length > 0) + { + buf.Resize(length); + memcpy(&buf[0], buffer, length); + } + Length = length; + FilePos = 0; + bufptr = (const char *)&buf[0]; } - Length = length; - FilePos=0; -} -MemoryArrayReader::~MemoryArrayReader () + TArray &GetArray() { return buf; } + + void UpdateLength() { Length = buf.Size(); } +}; + + + +//========================================================================== +// +// FileReader +// +// this wraps the different reader types in an object with value semantics. +// +//========================================================================== + +bool FileRdr::OpenFile(const char *filename, FileRdr::Size start, FileRdr::Size length) { + auto reader = new StdFileReader; + if (!reader->Open(filename, (long)start, (long)length)) return false; + Close(); + mReader = reader; + return true; } -long MemoryArrayReader::Tell () const +bool FileRdr::OpenFilePart(FileRdr &parent, FileRdr::Size start, FileRdr::Size length) { - return FilePos; + auto reader = new FileReaderRedirect(parent, (long)start, (long)length); + Close(); + mReader = reader; + return true; } -long MemoryArrayReader::Seek (long offset, int origin) +bool FileRdr::OpenMemory(const void *mem, FileRdr::Size length) { - switch (origin) - { - case SEEK_CUR: - offset+=FilePos; - break; - - case SEEK_END: - offset+=Length; - break; - - } - FilePos=clamp(offset,0,Length); - return 0; + Close(); + mReader = new MemoryReader((const char *)mem, (long)length); + return true; } -long MemoryArrayReader::Read (void *buffer, long len) +bool FileRdr::OpenMemoryArray(const void *mem, FileRdr::Size length) { - if (len>Length-FilePos) len=Length-FilePos; - if (len<0) len=0; - memcpy(buffer,&buf[FilePos],len); - FilePos+=len; - return len; + Close(); + mReader = new MemoryArrayReader((const char *)mem, (long)length); + return true; } -char *MemoryArrayReader::Gets(char *strbuf, int len) +bool FileRdr::OpenMemoryArray(std::function&)> getter) { - return GetsFromBuffer((char*)&buf[0], strbuf, len); + auto reader = new MemoryArrayReader(nullptr, 0); + if (getter(reader->GetArray())) + { + Close(); + reader->UpdateLength(); + mReader = reader; + return true; + } + else + { + // This will keep the old buffer, if one existed + delete reader; + return false; + } } + //========================================================================== // // FileWriter (the motivation here is to have a buffer writing subclass) @@ -671,7 +455,6 @@ long FileWriter::Seek(long offset, int mode) } } - size_t FileWriter::Printf(const char *fmt, ...) { va_list ap; @@ -689,52 +472,3 @@ size_t BufferWriter::Write(const void *buffer, size_t len) memcpy(&mBuffer[ofs], buffer, len); return len; } - - -////////////////////////////////////// -// -// The new wrapper -// -////////////////////////////////////// - -bool FileRdr::OpenFile(const char *filename) -{ - auto reader = new FileReader; - if (!reader->Open(filename)) return false; - Close(); - mReader = reader; - return true; -} - -bool FileRdr::OpenMemory(const void *mem, FileRdr::Size length) -{ - Close(); - mReader = new MemoryReader((const char *)mem, (long)length); - return true; -} - -bool FileRdr::OpenMemoryArray(const void *mem, FileRdr::Size length) -{ - Close(); - mReader = new MemoryArrayReader((const char *)mem, (long)length); - return true; -} - -bool FileRdr::OpenMemoryArray(std::function&)> getter) -{ - auto reader = new MemoryArrayReader(nullptr, 0); - if (getter(reader->GetArray())) - { - Close(); - reader->UpdateLength(); - mReader = reader; - return true; - } - else - { - // This will keep the old - delete reader; - return false; - } -} - diff --git a/src/files.h b/src/files.h index dc7022882b..c567baac81 100644 --- a/src/files.h +++ b/src/files.h @@ -43,411 +43,197 @@ #include "doomtype.h" #include "m_swap.h" -class FileReaderBase +// Zip compression methods, extended by some internal types to be passed to FileReader::OpenDecompressor +enum +{ + METHOD_STORED = 0, + METHOD_SHRINK = 1, + METHOD_IMPLODE = 6, + METHOD_DEFLATE = 8, + METHOD_BZIP2 = 12, + METHOD_LZMA = 14, + METHOD_PPMD = 98, + METHOD_LZSS = 1337, // not used in Zips - this is for Console Doom compression + METHOD_ZLIB = 1338, // Zlib stream with header, used by compressed nodes. +}; + +class FileReaderInterface { public: - virtual ~FileReaderBase() {} + long Length = -1; + virtual ~FileReaderInterface() {} + virtual long Tell () const = 0; + virtual long Seek (long offset, int origin) = 0; virtual long Read (void *buffer, long len) = 0; - - FileReaderBase &operator>> (uint8_t &v) - { - Read (&v, 1); - return *this; - } - - FileReaderBase &operator>> (int8_t &v) - { - Read (&v, 1); - return *this; - } - - FileReaderBase &operator>> (uint16_t &v) - { - Read (&v, 2); - v = LittleShort(v); - return *this; - } - - FileReaderBase &operator>> (int16_t &v) - { - Read (&v, 2); - v = LittleShort(v); - return *this; - } - - FileReaderBase &operator>> (uint32_t &v) - { - Read (&v, 4); - v = LittleLong(v); - return *this; - } - - FileReaderBase &operator>> (int &v) - { - Read (&v, 4); - v = LittleLong(v); - return *this; - } - -}; - - -class FileReader : public FileReaderBase -{ -protected: - FILE *openfd(const char *filename); -public: - FileReader (); - FileReader (const char *filename); - FileReader (FILE *file); - FileReader (FILE *file, long length); - bool Open (const char *filename); - void Close(); - virtual ~FileReader (); - - virtual long Tell () const; - virtual long Seek (long offset, int origin); - virtual long Read (void *buffer, long len); - virtual char *Gets(char *strbuf, int len); + virtual char *Gets(char *strbuf, int len) = 0; + virtual const char *GetBuffer() const { return nullptr; } long GetLength () const { return Length; } - - // If you use the underlying FILE without going through this class, - // you must call ResetFilePtr() before using this class again. - void ResetFilePtr (); - - FILE *GetFile () const { return File; } - virtual const char *GetBuffer() const { return NULL; } - - FileReader &operator>> (uint8_t &v) - { - Read (&v, 1); - return *this; - } - - FileReader &operator>> (int8_t &v) - { - Read (&v, 1); - return *this; - } - - FileReader &operator>> (uint16_t &v) - { - Read (&v, 2); - v = LittleShort(v); - return *this; - } - - FileReader &operator>> (int16_t &v) - { - Read (&v, 2); - v = LittleShort(v); - return *this; - } - - FileReader &operator>> (uint32_t &v) - { - Read (&v, 4); - v = LittleLong(v); - return *this; - } - - -protected: - FileReader (const FileReader &other, long length); - - char *GetsFromBuffer(const char * bufptr, char *strbuf, int len); - - FILE *File; - long Length; - long StartPos; - long FilePos; - -private: - long CalcFileLen () const; -protected: - bool CloseOnDestruct; }; -// This will need a cleaner implementation once the outer interface is done. -// As a first step this only needs to work properly in the non-error case. -class FileReaderRedirect : public FileReader +class MemoryReader : public FileReaderInterface { - FileReader *mReader; +protected: + const char * bufptr = nullptr; + long FilePos = 0; + + MemoryReader() + {} + public: - FileReaderRedirect(FileReader *parent, long start, long length) + MemoryReader(const char *buffer, long length) { - mReader = parent; - StartPos = start; + bufptr = buffer; Length = length; + FilePos = 0; } - virtual long Tell() const - { - auto l = mReader->Tell() - StartPos; - if (l < StartPos || l >= StartPos + Length) return -1; // out of scope - return l - StartPos; - } - - virtual long Seek(long offset, int origin) - { - switch (origin) - { - case SEEK_SET: - offset += StartPos; - break; - - case SEEK_END: - offset += StartPos + Length; - break; - - case SEEK_CUR: - offset += mReader->Tell(); - break; - } - if (offset < StartPos || offset >= StartPos + Length) return -1; // out of scope - return mReader->Seek(offset, SEEK_SET); - } - - virtual long Read(void *buffer, long len) - { - // This still needs better range checks - return mReader->Read(buffer, len); - } - virtual char *Gets(char *strbuf, int len) - { - return mReader->Gets(strbuf, len); - } - - long GetLength() const { return Length; } + long Tell() const override; + long Seek(long offset, int origin) override; + long Read(void *buffer, long len) override; + char *Gets(char *strbuf, int len) override; + virtual const char *GetBuffer() const override { return bufptr; } }; -// Wraps around a FileReader to decompress a zlib stream -class FileReaderZ : public FileReaderBase +class FileRdr // this is just a temporary name, until the old FileReader hierarchy can be made private. { -public: - FileReaderZ (FileReader &file, bool zip=false); - ~FileReaderZ (); + FileReaderInterface *mReader = nullptr; - virtual long Read (void *buffer, long len); - - FileReaderZ &operator>> (uint8_t &v) - { - Read (&v, 1); - return *this; - } - - FileReaderZ &operator>> (int8_t &v) - { - Read (&v, 1); - return *this; - } - - FileReaderZ &operator>> (uint16_t &v) - { - Read (&v, 2); - v = LittleShort(v); - return *this; - } - - FileReaderZ &operator>> (int16_t &v) - { - Read (&v, 2); - v = LittleShort(v); - return *this; - } - - FileReaderZ &operator>> (uint32_t &v) - { - Read (&v, 4); - v = LittleLong(v); - return *this; - } - - FileReaderZ &operator>> (int &v) - { - Read (&v, 4); - v = LittleLong(v); - return *this; - } - -private: - enum { BUFF_SIZE = 4096 }; - - FileReader &File; - bool SawEOF; - z_stream Stream; - uint8_t InBuff[BUFF_SIZE]; - - void FillBuffer (); - - FileReaderZ &operator= (const FileReaderZ &) { return *this; } -}; - -// Wraps around a FileReader to decompress a bzip2 stream -class FileReaderBZ2 : public FileReaderBase -{ -public: - FileReaderBZ2 (FileReader &file); - ~FileReaderBZ2 (); - - long Read (void *buffer, long len); - - FileReaderBZ2 &operator>> (uint8_t &v) - { - Read (&v, 1); - return *this; - } - - FileReaderBZ2 &operator>> (int8_t &v) - { - Read (&v, 1); - return *this; - } - - FileReaderBZ2 &operator>> (uint16_t &v) - { - Read (&v, 2); - v = LittleShort(v); - return *this; - } - - FileReaderBZ2 &operator>> (int16_t &v) - { - Read (&v, 2); - v = LittleShort(v); - return *this; - } - - FileReaderBZ2 &operator>> (uint32_t &v) - { - Read (&v, 4); - v = LittleLong(v); - return *this; - } - - FileReaderBZ2 &operator>> (int &v) - { - Read (&v, 4); - v = LittleLong(v); - return *this; - } - -private: - enum { BUFF_SIZE = 4096 }; - - FileReader &File; - bool SawEOF; - bz_stream Stream; - uint8_t InBuff[BUFF_SIZE]; - - void FillBuffer (); - - FileReaderBZ2 &operator= (const FileReaderBZ2 &) { return *this; } -}; - -// Wraps around a FileReader to decompress a lzma stream -class FileReaderLZMA : public FileReaderBase -{ - struct StreamPointer; + FileRdr(const FileRdr &r) = delete; + FileRdr &operator=(const FileRdr &r) = delete; public: - FileReaderLZMA (FileReader &file, size_t uncompressed_size, bool zip); - ~FileReaderLZMA (); - - long Read (void *buffer, long len); - - FileReaderLZMA &operator>> (uint8_t &v) + enum ESeek { - Read (&v, 1); + SeekSet = SEEK_SET, + SeekCur = SEEK_CUR, + SeekEnd = SEEK_END + }; + + typedef ptrdiff_t Size; // let's not use 'long' here. + + FileRdr() {} + + // These two functions are only needed as long as the FileReader has not been fully replaced throughout the code. + explicit FileRdr(FileReaderInterface *r) + { + mReader = r; + } + + FileRdr(FileRdr &&r) + { + mReader = r.mReader; + r.mReader = nullptr; + } + + FileRdr& operator =(FileRdr &&r) + { + Close(); + mReader = r.mReader; + r.mReader = nullptr; return *this; } - FileReaderLZMA &operator>> (int8_t &v) + + ~FileRdr() { - Read (&v, 1); + Close(); + } + + bool isOpen() const + { + return mReader != nullptr; + } + + void Close() + { + if (mReader != nullptr) delete mReader; + mReader = nullptr; + } + + bool OpenFile(const char *filename, Size start = 0, Size length = -1); + bool OpenFilePart(FileRdr &parent, Size start, Size length); + bool OpenMemory(const void *mem, Size length); // read directly from the buffer + bool OpenMemoryArray(const void *mem, Size length); // read from a copy of the buffer. + bool OpenMemoryArray(std::function&)> getter); // read contents to a buffer and return a reader to it + bool OpenDecompressor(FileRdr &parent, Size length, int method, bool seekable); // creates a decompressor stream. 'seekable' uses a buffered version so that the Seek and Tell methods can be used. + + Size Tell() const + { + return mReader->Tell(); + } + + Size Seek(Size offset, ESeek origin) + { + return mReader->Seek((long)offset, origin); + } + + Size Read(void *buffer, Size len) + { + return mReader->Read(buffer, (long)len); + } + + char *Gets(char *strbuf, Size len) + { + return mReader->Gets(strbuf, (int)len); + } + + const char *GetBuffer() + { + return mReader->GetBuffer(); + } + + Size GetLength() const + { + return mReader->GetLength(); + } + + // Note: These need to go because they are fundamentally unsafe to use on a binary stream. + FileRdr &operator>> (uint8_t &v) + { + mReader->Read(&v, 1); return *this; } - FileReaderLZMA &operator>> (uint16_t &v) + FileRdr &operator>> (int8_t &v) { - Read (&v, 2); + mReader->Read(&v, 1); + return *this; + } + + FileRdr &operator>> (uint16_t &v) + { + mReader->Read(&v, 2); v = LittleShort(v); return *this; } - FileReaderLZMA &operator>> (int16_t &v) + FileRdr &operator>> (int16_t &v) { - Read (&v, 2); + mReader->Read(&v, 2); v = LittleShort(v); return *this; } - FileReaderLZMA &operator>> (uint32_t &v) + FileRdr &operator>> (uint32_t &v) { - Read (&v, 4); + mReader->Read(&v, 4); v = LittleLong(v); return *this; } - FileReaderLZMA &operator>> (int &v) + FileRdr &operator>> (int32_t &v) { - Read (&v, 4); + mReader->Read(&v, 4); v = LittleLong(v); return *this; } -private: - enum { BUFF_SIZE = 4096 }; - - FileReader &File; - bool SawEOF; - StreamPointer *Streamp; // anonymous pointer to LKZA decoder struct - to avoid including the LZMA headers globally - size_t Size; - size_t InPos, InSize; - size_t OutProcessed; - uint8_t InBuff[BUFF_SIZE]; - - void FillBuffer (); - - FileReaderLZMA &operator= (const FileReaderLZMA &) { return *this; } + friend class FWadCollection; }; -class MemoryReader : public FileReader -{ -public: - MemoryReader (const char *buffer, long length); - ~MemoryReader (); - virtual long Tell () const; - virtual long Seek (long offset, int origin); - virtual long Read (void *buffer, long len); - virtual char *Gets(char *strbuf, int len); - virtual const char *GetBuffer() const { return bufptr; } - -protected: - const char * bufptr; -}; - -class MemoryArrayReader : public FileReader -{ -public: - MemoryArrayReader (const char *buffer, long length); - ~MemoryArrayReader (); - - virtual long Tell () const; - virtual long Seek (long offset, int origin); - virtual long Read (void *buffer, long len); - virtual char *Gets(char *strbuf, int len); - virtual const char *GetBuffer() const { return (char*)&buf[0]; } - TArray &GetArray() { return buf; } - - void UpdateLength() { Length = buf.Size(); } - -protected: - TArray buf; -}; class FileWriter @@ -491,138 +277,4 @@ public: TArray *GetBuffer() { return &mBuffer; } }; - - - - -class FileRdr // this is just a temporary name, until the old FileReader hierarchy can be made private. -{ - FileReader *mReader = nullptr; - - FileRdr(const FileRdr &r) = delete; - FileRdr &operator=(const FileRdr &r) = delete; -public: - enum ESeek - { - SeekSet = SEEK_SET, - SeekCur = SEEK_CUR, - SeekEnd = SEEK_END - }; - - typedef ptrdiff_t Size; // let's not use 'long' here. - - FileRdr() {} - - // These two functions are only needed as long as the FileReader has not been fully replaced throughout the code. - explicit FileRdr(FileReader *r) - { - mReader = r; - } - FileReader *Reader() - { - auto r = mReader; - mReader = nullptr; - return r; - } - - FileRdr(FileRdr &&r) - { - mReader = r.mReader; - r.mReader = nullptr; - } - - FileRdr& operator =(FileRdr &&r) - { - Close(); - mReader = r.mReader; - r.mReader = nullptr; - return *this; - } - - - ~FileRdr() - { - Close(); - } - - bool isOpen() const - { - return mReader != nullptr; - } - - void Close() - { - if (mReader != nullptr) delete mReader; - mReader = nullptr; - } - - bool OpenFile(const char *filename); - bool OpenFilePart(FileReader *parent, Size start, Size length); // later - bool OpenMemory(const void *mem, Size length); // read directly from the buffer - bool OpenMemoryArray(const void *mem, Size length); // read from a copy of the buffer. - bool OpenMemoryArray(std::function&)> getter); // read contents to a buffer and return a reader to it - - Size Tell() const - { - return mReader->Tell(); - } - - Size Seek(Size offset, ESeek origin) - { - return mReader->Seek((long)offset, origin); - } - - Size Read(void *buffer, Size len) - { - return mReader->Read(buffer, (long)len); - } - - char *Gets(char *strbuf, Size len) - { - return mReader->Gets(strbuf, (int)len); - } - - Size GetLength() const - { - return mReader->GetLength(); - } - - FileRdr &operator>> (uint8_t &v) - { - mReader->Read(&v, 1); - return *this; - } - - FileRdr &operator>> (int8_t &v) - { - mReader->Read(&v, 1); - return *this; - } - - FileRdr &operator>> (uint16_t &v) - { - mReader->Read(&v, 2); - v = LittleShort(v); - return *this; - } - - FileRdr &operator>> (int16_t &v) - { - mReader->Read(&v, 2); - v = LittleShort(v); - return *this; - } - - FileRdr &operator>> (uint32_t &v) - { - mReader->Read(&v, 4); - v = LittleLong(v); - return *this; - } - - friend class FWadCollection; -}; - - - #endif diff --git a/src/files_decompress.cpp b/src/files_decompress.cpp new file mode 100644 index 0000000000..4b295fe383 --- /dev/null +++ b/src/files_decompress.cpp @@ -0,0 +1,607 @@ +/* +** files.cpp +** Implements classes for reading from files or memory blocks +** +**--------------------------------------------------------------------------- +** Copyright 1998-2008 Randy Heit +** Copyright 2005-2008 Christoph Oelckers +** All rights reserved. +** +** Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions +** are met: +** +** 1. Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** 2. Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in the +** documentation and/or other materials provided with the distribution. +** 3. The name of the author may not be used to endorse or promote products +** derived from this software without specific prior written permission. +** +** THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR +** IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES +** OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. +** IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, +** INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT +** NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF +** THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +**--------------------------------------------------------------------------- +** +*/ + +// This also pulls in windows.h +#include "LzmaDec.h" + +#include "files.h" +#include "i_system.h" +#include "templates.h" +#include "m_misc.h" + + +class DecompressorBase : public FileReaderInterface +{ +public: + // These do not work but need to be defined to satisfy the FileReader interface + long Tell () const override + { + I_Error("Cannot get position of decompressor stream"); + return 0; + } + virtual long Seek (long offset, int origin) override + { + I_Error("Cannot seek in decompressor stream"); + return 0; + } + virtual char *Gets(char *strbuf, int len) override + { + I_Error("Cannot use Gets on decompressor stream"); + return nullptr; + } +}; + +//========================================================================== +// +// DecompressorZ +// +// The zlib wrapper +// reads data from a ZLib compressed stream +// +//========================================================================== + +class DecompressorZ : public DecompressorBase +{ + enum { BUFF_SIZE = 4096 }; + + FileRdr &File; + bool SawEOF; + z_stream Stream; + uint8_t InBuff[BUFF_SIZE]; + +public: + DecompressorZ (FileRdr &file, bool zip) + : File(file), SawEOF(false) + { + int err; + + FillBuffer (); + + Stream.zalloc = Z_NULL; + Stream.zfree = Z_NULL; + + if (!zip) err = inflateInit (&Stream); + else err = inflateInit2 (&Stream, -MAX_WBITS); + + if (err != Z_OK) + { + I_Error ("DecompressorZ: inflateInit failed: %s\n", M_ZLibError(err).GetChars()); + } + } + + ~DecompressorZ () + { + inflateEnd (&Stream); + } + + long Read (void *buffer, long len) override + { + int err; + + Stream.next_out = (Bytef *)buffer; + Stream.avail_out = len; + + do + { + err = inflate (&Stream, Z_SYNC_FLUSH); + if (Stream.avail_in == 0 && !SawEOF) + { + FillBuffer (); + } + } while (err == Z_OK && Stream.avail_out != 0); + + if (err != Z_OK && err != Z_STREAM_END) + { + I_Error ("Corrupt zlib stream"); + } + + if (Stream.avail_out != 0) + { + I_Error ("Ran out of data in zlib stream"); + } + + return len - Stream.avail_out; + } + + void FillBuffer () + { + auto numread = File.Read (InBuff, BUFF_SIZE); + + if (numread < BUFF_SIZE) + { + SawEOF = true; + } + Stream.next_in = InBuff; + Stream.avail_in = (uInt)numread; + } +}; + + +//========================================================================== +// +// DecompressorZ +// +// The bzip2 wrapper +// reads data from a libbzip2 compressed stream +// +//========================================================================== + +class DecompressorBZ2 : public DecompressorBase +{ + enum { BUFF_SIZE = 4096 }; + + FileRdr &File; + bool SawEOF; + bz_stream Stream; + uint8_t InBuff[BUFF_SIZE]; + +public: + DecompressorBZ2 (FileRdr &file) + : File(file), SawEOF(false) + { + int err; + + FillBuffer (); + + Stream.bzalloc = NULL; + Stream.bzfree = NULL; + Stream.opaque = NULL; + + err = BZ2_bzDecompressInit(&Stream, 0, 0); + + if (err != BZ_OK) + { + I_Error ("DecompressorBZ2: bzDecompressInit failed: %d\n", err); + } + } + + ~DecompressorBZ2 () + { + BZ2_bzDecompressEnd (&Stream); + } + + long Read (void *buffer, long len) override + { + int err; + + Stream.next_out = (char *)buffer; + Stream.avail_out = len; + + do + { + err = BZ2_bzDecompress(&Stream); + if (Stream.avail_in == 0 && !SawEOF) + { + FillBuffer (); + } + } while (err == BZ_OK && Stream.avail_out != 0); + + if (err != BZ_OK && err != BZ_STREAM_END) + { + I_Error ("Corrupt bzip2 stream"); + } + + if (Stream.avail_out != 0) + { + I_Error ("Ran out of data in bzip2 stream"); + } + + return len - Stream.avail_out; + } + + void FillBuffer () + { + auto numread = File.Read(InBuff, BUFF_SIZE); + + if (numread < BUFF_SIZE) + { + SawEOF = true; + } + Stream.next_in = (char *)InBuff; + Stream.avail_in = (unsigned)numread; + } + +}; + +//========================================================================== +// +// bz_internal_error +// +// libbzip2 wants this, since we build it with BZ_NO_STDIO set. +// +//========================================================================== + +extern "C" void bz_internal_error (int errcode) +{ + I_FatalError("libbzip2: internal error number %d\n", errcode); +} + +//========================================================================== +// +// DecompressorLZMA +// +// The lzma wrapper +// reads data from a LZMA compressed stream +// +//========================================================================== + +static void *SzAlloc(ISzAllocPtr, size_t size) { return malloc(size); } +static void SzFree(ISzAllocPtr, void *address) { free(address); } +ISzAlloc g_Alloc = { SzAlloc, SzFree }; + +// Wraps around a Decompressor to decompress a lzma stream +class DecompressorLZMA : public DecompressorBase +{ + enum { BUFF_SIZE = 4096 }; + + FileRdr &File; + bool SawEOF; + CLzmaDec Stream; + size_t Size; + size_t InPos, InSize; + size_t OutProcessed; + uint8_t InBuff[BUFF_SIZE]; + +public: + + DecompressorLZMA (FileRdr &file, size_t uncompressed_size) + : File(file), SawEOF(false) + { + uint8_t header[4 + LZMA_PROPS_SIZE]; + int err; + + Size = uncompressed_size; + OutProcessed = 0; + + // Read zip LZMA properties header + if (File.Read(header, sizeof(header)) < (long)sizeof(header)) + { + I_Error("DecompressorLZMA: File too short\n"); + } + if (header[2] + header[3] * 256 != LZMA_PROPS_SIZE) + { + I_Error("DecompressorLZMA: LZMA props size is %d (expected %d)\n", + header[2] + header[3] * 256, LZMA_PROPS_SIZE); + } + + FillBuffer(); + + LzmaDec_Construct(&Stream); + err = LzmaDec_Allocate(&Stream, header + 4, LZMA_PROPS_SIZE, &g_Alloc); + + if (err != SZ_OK) + { + I_Error("DecompressorLZMA: LzmaDec_Allocate failed: %d\n", err); + } + + LzmaDec_Init(&Stream); + } + + ~DecompressorLZMA () + { + LzmaDec_Free(&Stream, &g_Alloc); + } + + long Read (void *buffer, long len) override + { + int err; + Byte *next_out = (Byte *)buffer; + + do + { + ELzmaFinishMode finish_mode = LZMA_FINISH_ANY; + ELzmaStatus status; + size_t out_processed = len; + size_t in_processed = InSize; + + err = LzmaDec_DecodeToBuf(&Stream, next_out, &out_processed, InBuff + InPos, &in_processed, finish_mode, &status); + InPos += in_processed; + InSize -= in_processed; + next_out += out_processed; + len = (long)(len - out_processed); + if (err != SZ_OK) + { + I_Error ("Corrupt LZMA stream"); + } + if (in_processed == 0 && out_processed == 0) + { + if (status != LZMA_STATUS_FINISHED_WITH_MARK) + { + I_Error ("Corrupt LZMA stream"); + } + } + if (InSize == 0 && !SawEOF) + { + FillBuffer (); + } + } while (err == SZ_OK && len != 0); + + if (err != Z_OK && err != Z_STREAM_END) + { + I_Error ("Corrupt LZMA stream"); + } + + if (len != 0) + { + I_Error ("Ran out of data in LZMA stream"); + } + + return (long)(next_out - (Byte *)buffer); + } + + void FillBuffer () + { + auto numread = File.Read(InBuff, BUFF_SIZE); + + if (numread < BUFF_SIZE) + { + SawEOF = true; + } + InPos = 0; + InSize = numread; + } + +}; + +//========================================================================== +// +// Console Doom LZSS wrapper. +// +//========================================================================== + +class DecompressorLZSS : public DecompressorBase +{ + enum { BUFF_SIZE = 4096, WINDOW_SIZE = 4096, INTERNAL_BUFFER_SIZE = 128 }; + + FileRdr &File; + bool SawEOF; + uint8_t InBuff[BUFF_SIZE]; + + enum StreamState + { + STREAM_EMPTY, + STREAM_BITS, + STREAM_FLUSH, + STREAM_FINAL + }; + struct + { + StreamState State; + + uint8_t *In; + unsigned int AvailIn; + unsigned int InternalOut; + + uint8_t CFlags, Bits; + + uint8_t Window[WINDOW_SIZE+INTERNAL_BUFFER_SIZE]; + const uint8_t *WindowData; + uint8_t *InternalBuffer; + } Stream; + + void FillBuffer() + { + if(Stream.AvailIn) + memmove(InBuff, Stream.In, Stream.AvailIn); + + auto numread = File.Read(InBuff+Stream.AvailIn, BUFF_SIZE-Stream.AvailIn); + + if (numread < BUFF_SIZE) + { + SawEOF = true; + } + Stream.In = InBuff; + Stream.AvailIn = (unsigned)numread+Stream.AvailIn; + } + + // Reads a flag byte. + void PrepareBlocks() + { + assert(Stream.InternalBuffer == Stream.WindowData); + Stream.CFlags = *Stream.In++; + --Stream.AvailIn; + Stream.Bits = 0xFF; + Stream.State = STREAM_BITS; + } + + // Reads the next chunk in the block. Returns true if successful and + // returns false if it ran out of input data. + bool UncompressBlock() + { + if(Stream.CFlags & 1) + { + // Check to see if we have enough input + if(Stream.AvailIn < 2) + return false; + Stream.AvailIn -= 2; + + uint16_t pos = BigShort(*(uint16_t*)Stream.In); + uint8_t len = (pos & 0xF)+1; + pos >>= 4; + Stream.In += 2; + if(len == 1) + { + // We've reached the end of the stream. + Stream.State = STREAM_FINAL; + return true; + } + + const uint8_t* copyStart = Stream.InternalBuffer-pos-1; + + // Complete overlap: Single byte repeated + if(pos == 0) + memset(Stream.InternalBuffer, *copyStart, len); + // No overlap: One copy + else if(pos >= len) + memcpy(Stream.InternalBuffer, copyStart, len); + else + { + // Partial overlap: Copy in 2 or 3 chunks. + do + { + unsigned int copy = MIN(len, pos+1); + memcpy(Stream.InternalBuffer, copyStart, copy); + Stream.InternalBuffer += copy; + Stream.InternalOut += copy; + len -= copy; + pos += copy; // Increase our position since we can copy twice as much the next round. + } + while(len); + } + + Stream.InternalOut += len; + Stream.InternalBuffer += len; + } + else + { + // Uncompressed byte. + *Stream.InternalBuffer++ = *Stream.In++; + --Stream.AvailIn; + ++Stream.InternalOut; + } + + Stream.CFlags >>= 1; + Stream.Bits >>= 1; + + // If we're done with this block, flush the output + if(Stream.Bits == 0) + Stream.State = STREAM_FLUSH; + + return true; + } + +public: + DecompressorLZSS(FileRdr &file) : File(file), SawEOF(false) + { + Stream.State = STREAM_EMPTY; + Stream.WindowData = Stream.InternalBuffer = Stream.Window+WINDOW_SIZE; + Stream.InternalOut = 0; + Stream.AvailIn = 0; + + FillBuffer(); + } + + ~DecompressorLZSS() + { + } + + long Read(void *buffer, long len) override + { + + uint8_t *Out = (uint8_t*)buffer; + long AvailOut = len; + + do + { + while(Stream.AvailIn) + { + if(Stream.State == STREAM_EMPTY) + PrepareBlocks(); + else if(Stream.State == STREAM_BITS && !UncompressBlock()) + break; + else + break; + } + + unsigned int copy = MIN(Stream.InternalOut, AvailOut); + if(copy > 0) + { + memcpy(Out, Stream.WindowData, copy); + Out += copy; + AvailOut -= copy; + + // Slide our window + memmove(Stream.Window, Stream.Window+copy, WINDOW_SIZE+INTERNAL_BUFFER_SIZE-copy); + Stream.InternalBuffer -= copy; + Stream.InternalOut -= copy; + } + + if(Stream.State == STREAM_FINAL) + break; + + if(Stream.InternalOut == 0 && Stream.State == STREAM_FLUSH) + Stream.State = STREAM_EMPTY; + + if(Stream.AvailIn < 2) + FillBuffer(); + } + while(AvailOut && Stream.State != STREAM_FINAL); + + assert(AvailOut == 0); + return (long)(Out - (uint8_t*)buffer); + } +}; + + +bool FileRdr::OpenDecompressor(FileRdr &parent, Size length, int method, bool seekable) +{ + DecompressorBase *dec = nullptr; + switch (method) + { + case METHOD_DEFLATE: + case METHOD_ZLIB: + dec = new DecompressorZ(parent, method == METHOD_DEFLATE); + break; + + case METHOD_BZIP2: + dec = new DecompressorBZ2(parent); + break; + + case METHOD_LZMA: + dec = new DecompressorLZMA(parent, length); + break; + + case METHOD_LZSS: + dec = new DecompressorLZSS(parent); + break; + + // todo: METHOD_IMPLODE, METHOD_SHRINK + default: + return false; + } + dec->Length = (long)length; + if (!seekable) + { + Close(); + mReader = dec; + return true; + } + else + { + // todo: create a wrapper. for now this fails + delete dec; + return false; + } +} diff --git a/src/g_game.cpp b/src/g_game.cpp index 836805677f..e61c440fde 100644 --- a/src/g_game.cpp +++ b/src/g_game.cpp @@ -1930,7 +1930,7 @@ void G_DoLoadGame () hidecon = gameaction == ga_loadgamehidecon; gameaction = ga_nothing; - std::unique_ptr resfile(FResourceFile::OpenResourceFile(savename.GetChars(), nullptr, true, true)); + std::unique_ptr resfile(FResourceFile::OpenResourceFile(savename.GetChars(), true, true)); if (resfile == nullptr) { Printf ("Could not read savegame '%s'\n", savename.GetChars()); @@ -2372,7 +2372,7 @@ void G_DoSaveGame (bool okForQuicksave, FString filename, const char *descriptio savegame_content[2].Clean(); // Check whether the file is ok by trying to open it. - FResourceFile *test = FResourceFile::OpenResourceFile(filename, nullptr, true); + FResourceFile *test = FResourceFile::OpenResourceFile(filename, true); if (test != nullptr) { delete test; diff --git a/src/md5.cpp b/src/md5.cpp index e8257b597e..f5d8ba6043 100644 --- a/src/md5.cpp +++ b/src/md5.cpp @@ -269,8 +269,8 @@ CCMD (md5sum) } for (int i = 1; i < argv.argc(); ++i) { - FileReader fr; - if (!fr.Open(argv[i])) + FileRdr fr; + if (!fr.OpenFile(argv[i])) { Printf("%s: %s\n", argv[i], strerror(errno)); } diff --git a/src/menu/loadsavemenu.cpp b/src/menu/loadsavemenu.cpp index d66a3ab079..424073ba57 100644 --- a/src/menu/loadsavemenu.cpp +++ b/src/menu/loadsavemenu.cpp @@ -174,7 +174,7 @@ void FSavegameManager::ReadSaveStrings() // I_FindName only returns the file's name and not its full path FString filepath = G_BuildSaveName(I_FindName(&c_file), -1); - FResourceFile *savegame = FResourceFile::OpenResourceFile(filepath, nullptr, true, true); + FResourceFile *savegame = FResourceFile::OpenResourceFile(filepath, true, true); if (savegame != nullptr) { bool oldVer = false; @@ -469,7 +469,7 @@ unsigned FSavegameManager::ExtractSaveData(int index) (node = SaveGames[index]) && !node->Filename.IsEmpty() && !node->bOldVersion && - (resf = FResourceFile::OpenResourceFile(node->Filename.GetChars(), nullptr, true)) != nullptr) + (resf = FResourceFile::OpenResourceFile(node->Filename.GetChars(), true)) != nullptr) { FResourceLump *info = resf->FindLump("info.json"); if (info == nullptr) diff --git a/src/p_conversation.h b/src/p_conversation.h index 620b6f4e8d..90423ffe30 100644 --- a/src/p_conversation.h +++ b/src/p_conversation.h @@ -77,7 +77,7 @@ void P_ResumeConversation (); void P_ConversationCommand (int netcode, int player, uint8_t **stream); -class FileReader; +class FileRdr; bool P_ParseUSDF(int lumpnum, FileRdr &lump, int lumplen); diff --git a/src/p_glnodes.cpp b/src/p_glnodes.cpp index 096eaf904e..09e9ef28d8 100644 --- a/src/p_glnodes.cpp +++ b/src/p_glnodes.cpp @@ -215,18 +215,18 @@ bool P_CheckForGLNodes() static int firstglvertex; static bool format5; -static bool LoadGLVertexes(FileReader * lump) +static bool LoadGLVertexes(FileRdr &lump) { uint8_t *gldata; int i; firstglvertex = level.vertexes.Size(); - int gllen=lump->GetLength(); + auto gllen=lump.GetLength(); gldata = new uint8_t[gllen]; - lump->Seek(0, SEEK_SET); - lump->Read(gldata, gllen); + lump.Seek(0, FileRdr::SeekSet); + lump.Read(gldata, gllen); if (*(int *)gldata == gNd5) { @@ -246,7 +246,7 @@ static bool LoadGLVertexes(FileReader * lump) else format5=false; mapglvertex_t* mgl = (mapglvertex_t *)(gldata + GL_VERT_OFFSET); - unsigned numvertexes = firstglvertex + (gllen - GL_VERT_OFFSET)/sizeof(mapglvertex_t); + unsigned numvertexes = (unsigned)(firstglvertex + (gllen - GL_VERT_OFFSET)/sizeof(mapglvertex_t)); auto oldvertexes = &level.vertexes[0]; level.vertexes.Resize(numvertexes); @@ -293,16 +293,16 @@ static inline int checkGLVertex3(int num) // //========================================================================== -static bool LoadGLSegs(FileReader * lump) +static bool LoadGLSegs(FileRdr &lump) { char *data; int i; line_t *ldef=NULL; - int numsegs = lump->GetLength(); + int numsegs = (int)lump.GetLength(); data= new char[numsegs]; - lump->Seek(0, SEEK_SET); - lump->Read(data, numsegs); + lump.Seek(0, FileRdr::SeekSet); + lump.Read(data, numsegs); auto &segs = level.segs; #ifdef _MSC_VER @@ -437,15 +437,15 @@ static bool LoadGLSegs(FileReader * lump) // //========================================================================== -static bool LoadGLSubsectors(FileReader * lump) +static bool LoadGLSubsectors(FileRdr &lump) { char * datab; int i; - auto numsubsectors = lump->GetLength(); + int numsubsectors = (int)lump.GetLength(); datab = new char[numsubsectors]; - lump->Seek(0, SEEK_SET); - lump->Read(datab, numsubsectors); + lump.Seek(0, FileRdr::SeekSet); + lump.Read(datab, numsubsectors); if (numsubsectors == 0) { @@ -521,7 +521,7 @@ static bool LoadGLSubsectors(FileReader * lump) // //========================================================================== -static bool LoadNodes (FileReader * lump) +static bool LoadNodes (FileRdr &lump) { const int NF_SUBSECTOR = 0x8000; const int GL5_NF_SUBSECTOR = (1 << 31); @@ -534,15 +534,15 @@ static bool LoadNodes (FileReader * lump) if (!format5) { mapnode_t* mn, * basemn; - unsigned numnodes = unsigned(lump->GetLength() / sizeof(mapnode_t)); + unsigned numnodes = unsigned(lump.GetLength() / sizeof(mapnode_t)); if (numnodes == 0) return false; level.nodes.Alloc(numnodes); - lump->Seek(0, SEEK_SET); + lump.Seek(0, FileRdr::SeekSet); basemn = mn = new mapnode_t[numnodes]; - lump->Read(mn, lump->GetLength()); + lump.Read(mn, lump.GetLength()); used = (uint16_t *)alloca (sizeof(uint16_t)*numnodes); memset (used, 0, sizeof(uint16_t)*numnodes); @@ -594,15 +594,15 @@ static bool LoadNodes (FileReader * lump) else { gl5_mapnode_t* mn, * basemn; - auto numnodes = unsigned(lump->GetLength() / sizeof(gl5_mapnode_t)); + auto numnodes = unsigned(lump.GetLength() / sizeof(gl5_mapnode_t)); if (numnodes == 0) return false; level.nodes.Alloc(numnodes); - lump->Seek(0, SEEK_SET); + lump.Seek(0, FileRdr::SeekSet); basemn = mn = new gl5_mapnode_t[numnodes]; - lump->Read(mn, lump->GetLength()); + lump.Read(mn, lump.GetLength()); used = (uint16_t *)alloca (sizeof(uint16_t)*numnodes); memset (used, 0, sizeof(uint16_t)*numnodes); @@ -660,7 +660,7 @@ static bool LoadNodes (FileReader * lump) // //========================================================================== -static bool DoLoadGLNodes(FileReader ** lumps) +static bool DoLoadGLNodes(FileRdr * lumps) { int missing = 0; @@ -803,7 +803,7 @@ static int FindGLNodesInFile(FResourceFile * f, const char * label) if (mustcheck) { char check[16]={0}; - FileReader *fr = f->GetLump(i)->GetReader(); + auto fr = f->GetLump(i)->GetReader(); fr->Read(check, 16); if (MatchHeader(label, check)) return i; } @@ -857,7 +857,7 @@ bool P_LoadGLNodes(MapData * map) if (!CheckCachedNodes(map)) { - FileReader *gwalumps[4] = { NULL, NULL, NULL, NULL }; + FileRdr gwalumps[4]; char path[256]; int li; int lumpfile = Wads.GetLumpFile(map->lumpnum); @@ -875,7 +875,7 @@ bool P_LoadGLNodes(MapData * map) // GL nodes are loaded with a WAD for(int i=0;i<4;i++) { - gwalumps[i]=Wads.ReopenLumpNum(li+i+1); + gwalumps[i]=Wads.ReopenLumpReader(li+i+1); } return DoLoadGLNodes(gwalumps); } @@ -889,7 +889,7 @@ bool P_LoadGLNodes(MapData * map) strcpy(ext, ".gwa"); // Todo: Compare file dates - f_gwa = FResourceFile::OpenResourceFile(path, NULL, true); + f_gwa = FResourceFile::OpenResourceFile(path, true); if (f_gwa==NULL) return false; strncpy(map->MapLumps[0].Name, Wads.GetLumpFullName(map->lumpnum), 8); @@ -918,8 +918,6 @@ bool P_LoadGLNodes(MapData * map) if (f_gwa != map->resource) delete f_gwa; - for(unsigned int i = 0;i < 4;++i) - delete gwalumps[i]; return result; } else return true; diff --git a/src/p_setup.cpp b/src/p_setup.cpp index ece2e301ac..8438e4074a 100644 --- a/src/p_setup.cpp +++ b/src/p_setup.cpp @@ -240,7 +240,7 @@ static int GetMapIndex(const char *mapname, int lastindex, const char *lumpname, MapData *P_OpenMapData(const char * mapname, bool justcheck) { MapData * map = new MapData; - FileReader * wadReader = NULL; + FileRdr * wadReader = nullptr; bool externalfile = !strnicmp(mapname, "file:", 5); if (externalfile) @@ -251,7 +251,7 @@ MapData *P_OpenMapData(const char * mapname, bool justcheck) delete map; return NULL; } - map->resource = FResourceFile::OpenResourceFile(mapname, NULL, true); + map->resource = FResourceFile::OpenResourceFile(mapname, true); wadReader = map->resource->GetReader(); } else @@ -396,7 +396,7 @@ MapData *P_OpenMapData(const char * mapname, bool justcheck) return NULL; } map->lumpnum = lump_wad; - map->resource = FResourceFile::OpenResourceFile(Wads.GetLumpFullName(lump_wad), Wads.ReopenLumpNum(lump_wad), true); + map->resource = FResourceFile::OpenResourceFile(Wads.GetLumpFullName(lump_wad), Wads.ReopenLumpReader(lump_wad), true); wadReader = map->resource->GetReader(); } } @@ -404,7 +404,7 @@ MapData *P_OpenMapData(const char * mapname, bool justcheck) // Although we're using the resource system, we still want to be sure we're // reading from a wad file. - wadReader->Seek(0, SEEK_SET); + wadReader->Seek(0, FileRdr::SeekSet); wadReader->Read(&id, sizeof(id)); if (id == IWAD_ID || id == PWAD_ID) @@ -412,7 +412,7 @@ MapData *P_OpenMapData(const char * mapname, bool justcheck) char maplabel[9]=""; int index=0; - map->MapLumps[0].Reader = FileRdr(map->resource->GetLump(0)->NewReader()); + map->MapLumps[0].Reader = map->resource->GetLump(0)->NewReader(); strncpy(map->MapLumps[0].Name, map->resource->GetLump(0)->Name, 8); for(uint32_t i = 1; i < map->resource->LumpCount(); i++) @@ -422,7 +422,7 @@ MapData *P_OpenMapData(const char * mapname, bool justcheck) if (i == 1 && !strnicmp(lumpname, "TEXTMAP", 8)) { map->isText = true; - map->MapLumps[ML_TEXTMAP].Reader = FileRdr(map->resource->GetLump(i)->NewReader()); + map->MapLumps[ML_TEXTMAP].Reader = map->resource->GetLump(i)->NewReader(); strncpy(map->MapLumps[ML_TEXTMAP].Name, lumpname, 8); for(int i = 2;; i++) { @@ -454,7 +454,7 @@ MapData *P_OpenMapData(const char * mapname, bool justcheck) return map; } else continue; - map->MapLumps[index].Reader = FileRdr(map->resource->GetLump(i)->NewReader()); + map->MapLumps[index].Reader = map->resource->GetLump(i)->NewReader(); strncpy(map->MapLumps[index].Name, lumpname, 8); } } @@ -486,7 +486,7 @@ MapData *P_OpenMapData(const char * mapname, bool justcheck) maplabel[8]=0; } - map->MapLumps[index].Reader = FileRdr(map->resource->GetLump(i)->NewReader()); + map->MapLumps[index].Reader = map->resource->GetLump(i)->NewReader(); strncpy(map->MapLumps[index].Name, lumpname, 8); } } @@ -855,7 +855,7 @@ void P_LoadVertexes (MapData * map) // //=========================================================================== -void P_LoadZSegs (FileReaderBase &data) +void P_LoadZSegs (FileRdr &data) { for (auto &seg : level.segs) { @@ -891,7 +891,7 @@ void P_LoadZSegs (FileReaderBase &data) // //=========================================================================== -void P_LoadGLZSegs (FileReaderBase &data, int type) +void P_LoadGLZSegs (FileRdr &data, int type) { for (unsigned i = 0; i < level.subsectors.Size(); ++i) { @@ -961,7 +961,7 @@ void P_LoadGLZSegs (FileReaderBase &data, int type) // //=========================================================================== -void LoadZNodes(FileReaderBase &data, int glnodes) +void LoadZNodes(FileRdr &data, int glnodes) { // Read extra vertices added during node building uint32_t orgVerts, newVerts; @@ -980,7 +980,7 @@ void LoadZNodes(FileReaderBase &data, int glnodes) } for (i = 0; i < newVerts; ++i) { - fixed_t x, y; + int32_t x, y; data >> x >> y; level.vertexes[i + orgVerts].set(x, y); } @@ -1145,15 +1145,17 @@ void P_LoadZNodes (FileRdr &dalump, uint32_t id) return; } - auto daptr = dalump.Reader(); if (compressed) { - FileReaderZ data (*daptr); - LoadZNodes(data, type); + FileRdr zip; + if (zip.OpenDecompressor(dalump, -1, METHOD_ZLIB, false)) + { + LoadZNodes(zip, type); + } } else { - LoadZNodes(*daptr, type); + LoadZNodes(dalump, type); } } diff --git a/src/resourcefiles/ancientzip.cpp b/src/resourcefiles/ancientzip.cpp index a56d9adeb3..8439cc5fbd 100644 --- a/src/resourcefiles/ancientzip.cpp +++ b/src/resourcefiles/ancientzip.cpp @@ -70,7 +70,7 @@ if (bs < be) \ c = ReadBuf[bs++]; \ else { \ - be = In->Read(&ReadBuf, sizeof(ReadBuf)); \ + be = (decltype(be))In->Read(&ReadBuf, sizeof(ReadBuf)); \ c = ReadBuf[0]; \ bs = 1; \ } \ @@ -259,7 +259,7 @@ int FZipExploder::DecodeSF(TArray &decoder, int numvals) } int FZipExploder::Explode(unsigned char *out, unsigned int outsize, - FileReader *in, unsigned int insize, + FileRdr &in, unsigned int insize, int flags) { int c, i, minMatchLen = 3, len, dist; @@ -268,7 +268,7 @@ int FZipExploder::Explode(unsigned char *out, unsigned int outsize, Hold = 0; Bits = 0; - In = in; + In = ∈ InLeft = insize; bs = be = 0; @@ -337,9 +337,9 @@ int FZipExploder::Explode(unsigned char *out, unsigned int outsize, #define FREE_CODE HSIZE /* 0x2000 (code is unused or was cleared) */ #define HAS_CHILD (HSIZE << 1) /* 0x4000 (code has a child--do not clear) */ -int ShrinkLoop(unsigned char *out, unsigned int outsize, - FileReader *In, unsigned int InLeft) +int ShrinkLoop(unsigned char *out, unsigned int outsize, FileRdr &_In, unsigned int InLeft) { + FileRdr *In = &_In; unsigned char ReadBuf[256]; unsigned short Parent[HSIZE]; unsigned char Value[HSIZE], Stack[HSIZE]; diff --git a/src/resourcefiles/ancientzip.h b/src/resourcefiles/ancientzip.h index d51e89ca59..53725b27c7 100644 --- a/src/resourcefiles/ancientzip.h +++ b/src/resourcefiles/ancientzip.h @@ -4,7 +4,7 @@ class FZipExploder { unsigned int Hold, Bits; - FileReader *In; + FileRdr *In; unsigned int InLeft; /**************************************************************** @@ -38,7 +38,7 @@ class FZipExploder int DecodeSFValue(const TArray ¤tTree); int DecodeSF(TArray &decoder, int numvals); public: - int Explode(unsigned char *out, unsigned int outsize, FileReader *in, unsigned int insize, int flags); + int Explode(unsigned char *out, unsigned int outsize, FileRdr &in, unsigned int insize, int flags); }; class CExplosionError : CRecoverableError @@ -47,4 +47,4 @@ public: CExplosionError(const char *message) : CRecoverableError(message) {} }; -int ShrinkLoop(unsigned char *out, unsigned int outsize, FileReader *in, unsigned int insize); \ No newline at end of file +int ShrinkLoop(unsigned char *out, unsigned int outsize, FileRdr &in, unsigned int insize); \ No newline at end of file diff --git a/src/resourcefiles/file_7z.cpp b/src/resourcefiles/file_7z.cpp index aa5018eb30..cb2f310a84 100644 --- a/src/resourcefiles/file_7z.cpp +++ b/src/resourcefiles/file_7z.cpp @@ -58,19 +58,19 @@ extern ISzAlloc g_Alloc; struct CZDFileInStream { ISeekInStream s; - FileReader *File; + FileRdr &File; - CZDFileInStream(FileReader *_file) + CZDFileInStream(FileRdr &_file) + : File(_file) { s.Read = Read; s.Seek = Seek; - File = _file; } static SRes Read(const ISeekInStream *pp, void *buf, size_t *size) { CZDFileInStream *p = (CZDFileInStream *)pp; - long numread = p->File->Read(buf, (long)*size); + auto numread = p->File.Read(buf, (long)*size); if (numread < 0) { *size = 0; @@ -83,26 +83,26 @@ struct CZDFileInStream static SRes Seek(const ISeekInStream *pp, Int64 *pos, ESzSeek origin) { CZDFileInStream *p = (CZDFileInStream *)pp; - int move_method; + FileRdr::ESeek move_method; int res; if (origin == SZ_SEEK_SET) { - move_method = SEEK_SET; + move_method = FileRdr::SeekSet; } else if (origin == SZ_SEEK_CUR) { - move_method = SEEK_CUR; + move_method = FileRdr::SeekCur; } else if (origin == SZ_SEEK_END) { - move_method = SEEK_END; + move_method = FileRdr::SeekEnd; } else { return 1; } - res = p->File->Seek((long)*pos, move_method); - *pos = p->File->Tell(); + res = (int)p->File.Seek((long)*pos, move_method); + *pos = p->File.Tell(); return res; } }; @@ -117,13 +117,13 @@ struct C7zArchive Byte *OutBuffer; size_t OutBufferSize; - C7zArchive(FileReader *file) : ArchiveStream(file) + C7zArchive(FileRdr &file) : ArchiveStream(file) { if (g_CrcTable[1] == 0) { CrcGenerateTable(); } - file->Seek(0, SEEK_SET); + file.Seek(0, FileRdr::SeekSet); LookToRead2_CreateVTable(&LookStream, false); LookStream.realStream = &ArchiveStream.s; LookToRead2_Init(&LookStream); @@ -192,7 +192,7 @@ class F7ZFile : public FResourceFile C7zArchive *Archive; public: - F7ZFile(const char * filename, FileReader *filer); + F7ZFile(const char * filename, FileRdr &filer); bool Open(bool quiet); virtual ~F7ZFile(); virtual FResourceLump *GetLump(int no) { return ((unsigned)no < NumLumps)? &Lumps[no] : NULL; } @@ -206,7 +206,7 @@ public: // //========================================================================== -F7ZFile::F7ZFile(const char * filename, FileReader *filer) +F7ZFile::F7ZFile(const char * filename, FileRdr &filer) : FResourceFile(filename, filer) { Lumps = NULL; @@ -295,7 +295,7 @@ bool F7ZFile::Open(bool quiet) lump_p->LumpNameSetup(name); lump_p->LumpSize = static_cast(SzArEx_GetFileSize(archPtr, i)); lump_p->Owner = this; - lump_p->Flags = LUMPF_ZIPFILE; + lump_p->Flags = LUMPF_ZIPFILE|LUMPF_COMPRESSED; lump_p->Position = i; lump_p->CheckEmbedded(); lump_p++; @@ -361,21 +361,21 @@ int F7ZLump::FillCache() // //========================================================================== -FResourceFile *Check7Z(const char *filename, FileReader *file, bool quiet) +FResourceFile *Check7Z(const char *filename, FileRdr &file, bool quiet) { char head[k7zSignatureSize]; - if (file->GetLength() >= k7zSignatureSize) + if (file.GetLength() >= k7zSignatureSize) { - file->Seek(0, SEEK_SET); - file->Read(&head, k7zSignatureSize); - file->Seek(0, SEEK_SET); + file.Seek(0, FileRdr::SeekSet); + file.Read(&head, k7zSignatureSize); + file.Seek(0, FileRdr::SeekSet); if (!memcmp(head, k7zSignature, k7zSignatureSize)) { FResourceFile *rf = new F7ZFile(filename, file); if (rf->Open(quiet)) return rf; - rf->Reader = NULL; // to avoid destruction of reader + file = std::move(rf->Reader); // to avoid destruction of reader delete rf; } } diff --git a/src/resourcefiles/file_directory.cpp b/src/resourcefiles/file_directory.cpp index 2e5630169a..534a6fe382 100644 --- a/src/resourcefiles/file_directory.cpp +++ b/src/resourcefiles/file_directory.cpp @@ -55,7 +55,7 @@ struct FDirectoryLump : public FResourceLump { - virtual FileReader *NewReader(); + virtual FileRdr NewReader(); virtual int FillCache(); FString mFullPath; @@ -90,7 +90,7 @@ public: //========================================================================== FDirectory::FDirectory(const char * directory) -: FResourceFile(NULL, NULL) +: FResourceFile(NULL, FileRdr()) { FString dirname; @@ -287,16 +287,11 @@ void FDirectory::AddEntry(const char *fullpath, int size) // //========================================================================== -FileReader *FDirectoryLump::NewReader() +FileRdr FDirectoryLump::NewReader() { - try - { - return new FileReader(mFullPath); - } - catch (CRecoverableError &) - { - return NULL; - } + FileRdr fr; + fr.OpenFile(mFullPath); + return fr; } //========================================================================== @@ -307,15 +302,14 @@ FileReader *FDirectoryLump::NewReader() int FDirectoryLump::FillCache() { + FileRdr fr; Cache = new char[LumpSize]; - FileReader *reader = NewReader(); - if (reader == NULL) + if (!fr.OpenFile(mFullPath)) { memset(Cache, 0, LumpSize); return 0; } - reader->Read(Cache, LumpSize); - delete reader; + fr.Read(Cache, LumpSize); RefCount = 1; return 1; } @@ -326,7 +320,7 @@ int FDirectoryLump::FillCache() // //========================================================================== -FResourceFile *CheckDir(const char *filename, FileReader *file, bool quiet) +FResourceFile *CheckDir(const char *filename, bool quiet) { FResourceFile *rf = new FDirectory(filename); if (rf->Open(quiet)) return rf; diff --git a/src/resourcefiles/file_grp.cpp b/src/resourcefiles/file_grp.cpp index 663aeb16eb..72543d356a 100644 --- a/src/resourcefiles/file_grp.cpp +++ b/src/resourcefiles/file_grp.cpp @@ -73,7 +73,7 @@ struct GrpLump class FGrpFile : public FUncompressedFile { public: - FGrpFile(const char * filename, FileReader *file); + FGrpFile(const char * filename, FileRdr &file); bool Open(bool quiet); }; @@ -84,7 +84,7 @@ public: // //========================================================================== -FGrpFile::FGrpFile(const char *filename, FileReader *file) +FGrpFile::FGrpFile(const char *filename, FileRdr &file) : FUncompressedFile(filename, file) { Lumps = NULL; @@ -100,11 +100,11 @@ bool FGrpFile::Open(bool quiet) { GrpInfo header; - Reader->Read(&header, sizeof(header)); + Reader.Read(&header, sizeof(header)); NumLumps = LittleLong(header.NumLumps); GrpLump *fileinfo = new GrpLump[NumLumps]; - Reader->Read (fileinfo, NumLumps * sizeof(GrpLump)); + Reader.Read (fileinfo, NumLumps * sizeof(GrpLump)); Lumps = new FUncompressedLump[NumLumps]; @@ -134,21 +134,21 @@ bool FGrpFile::Open(bool quiet) // //========================================================================== -FResourceFile *CheckGRP(const char *filename, FileReader *file, bool quiet) +FResourceFile *CheckGRP(const char *filename, FileRdr &file, bool quiet) { char head[12]; - if (file->GetLength() >= 12) + if (file.GetLength() >= 12) { - file->Seek(0, SEEK_SET); - file->Read(&head, 12); - file->Seek(0, SEEK_SET); + file.Seek(0, FileRdr::SeekSet); + file.Read(&head, 12); + file.Seek(0, FileRdr::SeekSet); if (!memcmp(head, "KenSilverman", 12)) { FResourceFile *rf = new FGrpFile(filename, file); if (rf->Open(quiet)) return rf; - rf->Reader = NULL; // to avoid destruction of reader + file = std::move(rf->Reader); // to avoid destruction of reader delete rf; } } diff --git a/src/resourcefiles/file_lump.cpp b/src/resourcefiles/file_lump.cpp index ee8751de37..feb8e56d90 100644 --- a/src/resourcefiles/file_lump.cpp +++ b/src/resourcefiles/file_lump.cpp @@ -46,7 +46,7 @@ class FLumpFile : public FUncompressedFile { public: - FLumpFile(const char * filename, FileReader *file); + FLumpFile(const char * filename, FileRdr &file); bool Open(bool quiet); }; @@ -57,7 +57,8 @@ public: // //========================================================================== -FLumpFile::FLumpFile(const char *filename, FileReader *file) : FUncompressedFile(filename, file) +FLumpFile::FLumpFile(const char *filename, FileRdr &file) + : FUncompressedFile(filename, file) { } @@ -76,7 +77,7 @@ bool FLumpFile::Open(bool quiet) Lumps->Name[8] = 0; Lumps->Owner = this; Lumps->Position = 0; - Lumps->LumpSize = Reader->GetLength(); + Lumps->LumpSize = (int)Reader.GetLength(); Lumps->Namespace = ns_global; Lumps->Flags = 0; Lumps->FullName = NULL; @@ -94,11 +95,12 @@ bool FLumpFile::Open(bool quiet) // //========================================================================== -FResourceFile *CheckLump(const char *filename, FileReader *file, bool quiet) +FResourceFile *CheckLump(const char *filename, FileRdr &file, bool quiet) { // always succeeds FResourceFile *rf = new FLumpFile(filename, file); if (rf->Open(quiet)) return rf; + file = std::move(rf->Reader); // to avoid destruction of reader delete rf; return NULL; } diff --git a/src/resourcefiles/file_pak.cpp b/src/resourcefiles/file_pak.cpp index b76a937c8f..42923092bf 100644 --- a/src/resourcefiles/file_pak.cpp +++ b/src/resourcefiles/file_pak.cpp @@ -66,7 +66,7 @@ struct dpackheader_t class FPakFile : public FUncompressedFile { public: - FPakFile(const char * filename, FileReader *file); + FPakFile(const char * filename, FileRdr &file); bool Open(bool quiet); }; @@ -79,7 +79,8 @@ public: // //========================================================================== -FPakFile::FPakFile(const char *filename, FileReader *file) : FUncompressedFile(filename, file) +FPakFile::FPakFile(const char *filename, FileRdr &file) + : FUncompressedFile(filename, file) { Lumps = NULL; } @@ -94,13 +95,13 @@ bool FPakFile::Open(bool quiet) { dpackheader_t header; - Reader->Read(&header, sizeof(header)); + Reader.Read(&header, sizeof(header)); NumLumps = LittleLong(header.dirlen) / sizeof(dpackfile_t); header.dirofs = LittleLong(header.dirofs); dpackfile_t *fileinfo = new dpackfile_t[NumLumps]; - Reader->Seek (header.dirofs, SEEK_SET); - Reader->Read (fileinfo, NumLumps * sizeof(dpackfile_t)); + Reader.Seek (header.dirofs, FileRdr::SeekSet); + Reader.Read (fileinfo, NumLumps * sizeof(dpackfile_t)); Lumps = new FUncompressedLump[NumLumps]; @@ -126,21 +127,21 @@ bool FPakFile::Open(bool quiet) // //========================================================================== -FResourceFile *CheckPak(const char *filename, FileReader *file, bool quiet) +FResourceFile *CheckPak(const char *filename, FileRdr &file, bool quiet) { char head[4]; - if (file->GetLength() >= 12) + if (file.GetLength() >= 12) { - file->Seek(0, SEEK_SET); - file->Read(&head, 4); - file->Seek(0, SEEK_SET); + file.Seek(0, FileRdr::SeekSet); + file.Read(&head, 4); + file.Seek(0, FileRdr::SeekSet); if (!memcmp(head, "PACK", 4)) { FResourceFile *rf = new FPakFile(filename, file); if (rf->Open(quiet)) return rf; - rf->Reader = NULL; // to avoid destruction of reader + file = std::move(rf->Reader); // to avoid destruction of reader delete rf; } } diff --git a/src/resourcefiles/file_rff.cpp b/src/resourcefiles/file_rff.cpp index ba73dfc8bc..43a4a454fe 100644 --- a/src/resourcefiles/file_rff.cpp +++ b/src/resourcefiles/file_rff.cpp @@ -75,7 +75,7 @@ struct RFFLump struct FRFFLump : public FUncompressedLump { - virtual FileReader *GetReader(); + virtual FileRdr *GetReader(); virtual int FillCache(); uint32_t IndexNum; @@ -111,7 +111,7 @@ class FRFFFile : public FResourceFile FRFFLump *Lumps; public: - FRFFFile(const char * filename, FileReader *file); + FRFFFile(const char * filename, FileRdr &file); virtual ~FRFFFile(); virtual bool Open(bool quiet); virtual FResourceLump *GetLump(int no) { return ((unsigned)no < NumLumps)? &Lumps[no] : NULL; } @@ -124,7 +124,7 @@ public: // //========================================================================== -FRFFFile::FRFFFile(const char *filename, FileReader *file) +FRFFFile::FRFFFile(const char *filename, FileRdr &file) : FResourceFile(filename, file) { Lumps = NULL; @@ -141,13 +141,13 @@ bool FRFFFile::Open(bool quiet) RFFLump *lumps; RFFInfo header; - Reader->Read(&header, sizeof(header)); + Reader.Read(&header, sizeof(header)); NumLumps = LittleLong(header.NumLumps); header.DirOfs = LittleLong(header.DirOfs); lumps = new RFFLump[header.NumLumps]; - Reader->Seek (header.DirOfs, SEEK_SET); - Reader->Read (lumps, header.NumLumps * sizeof(RFFLump)); + Reader.Seek (header.DirOfs, FileRdr::SeekSet); + Reader.Read (lumps, header.NumLumps * sizeof(RFFLump)); BloodCrypt (lumps, header.DirOfs, header.NumLumps * sizeof(RFFLump)); Lumps = new FRFFLump[NumLumps]; @@ -203,7 +203,7 @@ FRFFFile::~FRFFFile() // //========================================================================== -FileReader *FRFFLump::GetReader() +FileRdr *FRFFLump::GetReader() { // Don't return the reader if this lump is encrypted // In that case always force caching of the lump @@ -247,21 +247,21 @@ int FRFFLump::FillCache() // //========================================================================== -FResourceFile *CheckRFF(const char *filename, FileReader *file, bool quiet) +FResourceFile *CheckRFF(const char *filename, FileRdr &file, bool quiet) { char head[4]; - if (file->GetLength() >= 16) + if (file.GetLength() >= 16) { - file->Seek(0, SEEK_SET); - file->Read(&head, 4); - file->Seek(0, SEEK_SET); + file.Seek(0, FileRdr::SeekSet); + file.Read(&head, 4); + file.Seek(0, FileRdr::SeekSet); if (!memcmp(head, "RFF\x1a", 4)) { FResourceFile *rf = new FRFFFile(filename, file); if (rf->Open(quiet)) return rf; - rf->Reader = NULL; // to avoid destruction of reader + file = std::move(rf->Reader); // to avoid destruction of reader delete rf; } } diff --git a/src/resourcefiles/file_wad.cpp b/src/resourcefiles/file_wad.cpp index 477bda8e10..fce8ee1fdb 100644 --- a/src/resourcefiles/file_wad.cpp +++ b/src/resourcefiles/file_wad.cpp @@ -40,191 +40,7 @@ #include "w_wad.h" #include "gi.h" #include "i_system.h" - -// Console Doom LZSS wrapper. -class FileReaderLZSS : public FileReaderBase -{ -private: - enum { BUFF_SIZE = 4096, WINDOW_SIZE = 4096, INTERNAL_BUFFER_SIZE = 128 }; - - FileReader &File; - bool SawEOF; - uint8_t InBuff[BUFF_SIZE]; - - enum StreamState - { - STREAM_EMPTY, - STREAM_BITS, - STREAM_FLUSH, - STREAM_FINAL - }; - struct - { - StreamState State; - - uint8_t *In; - unsigned int AvailIn; - unsigned int InternalOut; - - uint8_t CFlags, Bits; - - uint8_t Window[WINDOW_SIZE+INTERNAL_BUFFER_SIZE]; - const uint8_t *WindowData; - uint8_t *InternalBuffer; - } Stream; - - void FillBuffer() - { - if(Stream.AvailIn) - memmove(InBuff, Stream.In, Stream.AvailIn); - - long numread = File.Read(InBuff+Stream.AvailIn, BUFF_SIZE-Stream.AvailIn); - - if (numread < BUFF_SIZE) - { - SawEOF = true; - } - Stream.In = InBuff; - Stream.AvailIn = numread+Stream.AvailIn; - } - - // Reads a flag byte. - void PrepareBlocks() - { - assert(Stream.InternalBuffer == Stream.WindowData); - Stream.CFlags = *Stream.In++; - --Stream.AvailIn; - Stream.Bits = 0xFF; - Stream.State = STREAM_BITS; - } - - // Reads the next chunk in the block. Returns true if successful and - // returns false if it ran out of input data. - bool UncompressBlock() - { - if(Stream.CFlags & 1) - { - // Check to see if we have enough input - if(Stream.AvailIn < 2) - return false; - Stream.AvailIn -= 2; - - uint16_t pos = BigShort(*(uint16_t*)Stream.In); - uint8_t len = (pos & 0xF)+1; - pos >>= 4; - Stream.In += 2; - if(len == 1) - { - // We've reached the end of the stream. - Stream.State = STREAM_FINAL; - return true; - } - - const uint8_t* copyStart = Stream.InternalBuffer-pos-1; - - // Complete overlap: Single byte repeated - if(pos == 0) - memset(Stream.InternalBuffer, *copyStart, len); - // No overlap: One copy - else if(pos >= len) - memcpy(Stream.InternalBuffer, copyStart, len); - else - { - // Partial overlap: Copy in 2 or 3 chunks. - do - { - unsigned int copy = MIN(len, pos+1); - memcpy(Stream.InternalBuffer, copyStart, copy); - Stream.InternalBuffer += copy; - Stream.InternalOut += copy; - len -= copy; - pos += copy; // Increase our position since we can copy twice as much the next round. - } - while(len); - } - - Stream.InternalOut += len; - Stream.InternalBuffer += len; - } - else - { - // Uncompressed byte. - *Stream.InternalBuffer++ = *Stream.In++; - --Stream.AvailIn; - ++Stream.InternalOut; - } - - Stream.CFlags >>= 1; - Stream.Bits >>= 1; - - // If we're done with this block, flush the output - if(Stream.Bits == 0) - Stream.State = STREAM_FLUSH; - - return true; - } - -public: - FileReaderLZSS(FileReader &file) : File(file), SawEOF(false) - { - Stream.State = STREAM_EMPTY; - Stream.WindowData = Stream.InternalBuffer = Stream.Window+WINDOW_SIZE; - Stream.InternalOut = 0; - Stream.AvailIn = 0; - - FillBuffer(); - } - - ~FileReaderLZSS() - { - } - - long Read(void *buffer, long len) - { - - uint8_t *Out = (uint8_t*)buffer; - long AvailOut = len; - - do - { - while(Stream.AvailIn) - { - if(Stream.State == STREAM_EMPTY) - PrepareBlocks(); - else if(Stream.State == STREAM_BITS && !UncompressBlock()) - break; - else - break; - } - - unsigned int copy = MIN(Stream.InternalOut, AvailOut); - if(copy > 0) - { - memcpy(Out, Stream.WindowData, copy); - Out += copy; - AvailOut -= copy; - - // Slide our window - memmove(Stream.Window, Stream.Window+copy, WINDOW_SIZE+INTERNAL_BUFFER_SIZE-copy); - Stream.InternalBuffer -= copy; - Stream.InternalOut -= copy; - } - - if(Stream.State == STREAM_FINAL) - break; - - if(Stream.InternalOut == 0 && Stream.State == STREAM_FLUSH) - Stream.State = STREAM_EMPTY; - - if(Stream.AvailIn < 2) - FillBuffer(); - } - while(AvailOut && Stream.State != STREAM_FINAL); - - assert(AvailOut == 0); - return (long)(Out - (uint8_t*)buffer); - } -}; +#include "w_zip.h" //========================================================================== // @@ -239,12 +55,12 @@ public: int Position; int GetFileOffset() { return Position; } - FileReader *GetReader() + FileRdr *GetReader() { if(!Compressed) { - Owner->Reader->Seek(Position, SEEK_SET); - return Owner->Reader; + Owner->Reader.Seek(Position, FileRdr::SeekSet); + return &Owner->Reader; } return NULL; } @@ -252,7 +68,7 @@ public: { if(!Compressed) { - const char * buffer = Owner->Reader->GetBuffer(); + const char * buffer = Owner->Reader.GetBuffer(); if (buffer != NULL) { @@ -263,16 +79,19 @@ public: } } - Owner->Reader->Seek(Position, SEEK_SET); + Owner->Reader.Seek(Position, FileRdr::SeekSet); Cache = new char[LumpSize]; if(Compressed) { - FileReaderLZSS lzss(*Owner->Reader); - lzss.Read(Cache, LumpSize); + FileRdr lzss; + if (lzss.OpenDecompressor(Owner->Reader, LumpSize, METHOD_LZSS, false)) + { + lzss.Read(Cache, LumpSize); + } } else - Owner->Reader->Read(Cache, LumpSize); + Owner->Reader.Read(Cache, LumpSize); RefCount = 1; return 1; @@ -294,7 +113,7 @@ class FWadFile : public FResourceFile void SkinHack (); public: - FWadFile(const char * filename, FileReader *file); + FWadFile(const char * filename, FileRdr &file); ~FWadFile(); void FindStrifeTeaserVoices (); FResourceLump *GetLump(int lump) { return &Lumps[lump]; } @@ -310,7 +129,8 @@ public: // //========================================================================== -FWadFile::FWadFile(const char *filename, FileReader *file) : FResourceFile(filename, file) +FWadFile::FWadFile(const char *filename, FileRdr &file) + : FResourceFile(filename, file) { Lumps = NULL; } @@ -331,9 +151,9 @@ bool FWadFile::Open(bool quiet) wadinfo_t header; uint32_t InfoTableOfs; bool isBigEndian = false; // Little endian is assumed until proven otherwise - const long wadSize = Reader->GetLength(); + auto wadSize = Reader.GetLength(); - Reader->Read(&header, sizeof(header)); + Reader.Read(&header, sizeof(header)); NumLumps = LittleLong(header.NumLumps); InfoTableOfs = LittleLong(header.InfoTableOfs); @@ -353,8 +173,8 @@ bool FWadFile::Open(bool quiet) } wadlump_t *fileinfo = new wadlump_t[NumLumps]; - Reader->Seek (InfoTableOfs, SEEK_SET); - Reader->Read (fileinfo, NumLumps * sizeof(wadlump_t)); + Reader.Seek (InfoTableOfs, FileRdr::SeekSet); + Reader.Read (fileinfo, NumLumps * sizeof(wadlump_t)); Lumps = new FWadFileLump[NumLumps]; @@ -369,7 +189,7 @@ bool FWadFile::Open(bool quiet) Lumps[i].Position = isBigEndian ? BigLong(fileinfo[i].FilePos) : LittleLong(fileinfo[i].FilePos); Lumps[i].LumpSize = isBigEndian ? BigLong(fileinfo[i].Size) : LittleLong(fileinfo[i].Size); Lumps[i].Namespace = ns_global; - Lumps[i].Flags = 0; + Lumps[i].Flags = Lumps[i].Compressed? LUMPF_COMPRESSED : 0; Lumps[i].FullName = NULL; } @@ -655,21 +475,21 @@ void FWadFile::FindStrifeTeaserVoices () // //========================================================================== -FResourceFile *CheckWad(const char *filename, FileReader *file, bool quiet) +FResourceFile *CheckWad(const char *filename, FileRdr &file, bool quiet) { char head[4]; - if (file->GetLength() >= 12) + if (file.GetLength() >= 12) { - file->Seek(0, SEEK_SET); - file->Read(&head, 4); - file->Seek(0, SEEK_SET); + file.Seek(0, FileRdr::SeekSet); + file.Read(&head, 4); + file.Seek(0, FileRdr::SeekSet); if (!memcmp(head, "IWAD", 4) || !memcmp(head, "PWAD", 4)) { FResourceFile *rf = new FWadFile(filename, file); if (rf->Open(quiet)) return rf; - rf->Reader = NULL; // to avoid destruction of reader + file = std::move(rf->Reader); // to avoid destruction of reader delete rf; } } diff --git a/src/resourcefiles/file_zip.cpp b/src/resourcefiles/file_zip.cpp index 3d842131d3..a2015ac58b 100644 --- a/src/resourcefiles/file_zip.cpp +++ b/src/resourcefiles/file_zip.cpp @@ -51,7 +51,7 @@ // //========================================================================== -static bool UncompressZipLump(char *Cache, FileReader *Reader, int Method, int LumpSize, int CompressedSize, int GPFlags) +static bool UncompressZipLump(char *Cache, FileRdr &Reader, int Method, int LumpSize, int CompressedSize, int GPFlags) { try { @@ -59,31 +59,23 @@ static bool UncompressZipLump(char *Cache, FileReader *Reader, int Method, int L { case METHOD_STORED: { - Reader->Read(Cache, LumpSize); + Reader.Read(Cache, LumpSize); break; } case METHOD_DEFLATE: - { - FileReaderZ frz(*Reader, true); - frz.Read(Cache, LumpSize); - break; - } - case METHOD_BZIP2: - { - FileReaderBZ2 frz(*Reader); - frz.Read(Cache, LumpSize); - break; - } - case METHOD_LZMA: { - FileReaderLZMA frz(*Reader, LumpSize, true); - frz.Read(Cache, LumpSize); + FileRdr frz; + if (frz.OpenDecompressor(Reader, LumpSize, Method, false)) + { + frz.Read(Cache, LumpSize); + } break; } + // Fixme: These should also use a stream case METHOD_IMPLODE: { FZipExploder exploder; @@ -112,8 +104,9 @@ static bool UncompressZipLump(char *Cache, FileReader *Reader, int Method, int L bool FCompressedBuffer::Decompress(char *destbuffer) { - MemoryReader mr(mBuffer, mCompressedSize); - return UncompressZipLump(destbuffer, &mr, mMethod, mSize, mCompressedSize, mZipFlags); + FileRdr mr; + mr.OpenMemory(mBuffer, mCompressedSize); + return UncompressZipLump(destbuffer, mr, mMethod, mSize, mCompressedSize, mZipFlags); } //----------------------------------------------------------------------- @@ -123,7 +116,7 @@ bool FCompressedBuffer::Decompress(char *destbuffer) // //----------------------------------------------------------------------- -static uint32_t Zip_FindCentralDir(FileReader * fin) +static uint32_t Zip_FindCentralDir(FileRdr &fin) { unsigned char buf[BUFREADCOMMENT + 4]; uint32_t FileSize; @@ -131,9 +124,9 @@ static uint32_t Zip_FindCentralDir(FileReader * fin) uint32_t uMaxBack; // maximum size of global comment uint32_t uPosFound=0; - fin->Seek(0, SEEK_END); + fin.Seek(0, FileRdr::SeekEnd); - FileSize = fin->Tell(); + FileSize = (uint32_t)fin.Tell(); uMaxBack = MIN(0xffff, FileSize); uBackRead = 4; @@ -149,9 +142,9 @@ static uint32_t Zip_FindCentralDir(FileReader * fin) uReadSize = MIN((BUFREADCOMMENT + 4), (FileSize - uReadPos)); - if (fin->Seek(uReadPos, SEEK_SET) != 0) break; + if (fin.Seek(uReadPos, FileRdr::SeekSet) != 0) break; - if (fin->Read(buf, (int32_t)uReadSize) != (int32_t)uReadSize) break; + if (fin.Read(buf, (int32_t)uReadSize) != (int32_t)uReadSize) break; for (i = (int)uReadSize - 3; (i--) > 0;) { @@ -174,7 +167,7 @@ static uint32_t Zip_FindCentralDir(FileReader * fin) // //========================================================================== -FZipFile::FZipFile(const char * filename, FileReader *file) +FZipFile::FZipFile(const char * filename, FileRdr &file) : FResourceFile(filename, file) { Lumps = NULL; @@ -195,8 +188,8 @@ bool FZipFile::Open(bool quiet) } // Read the central directory info. - Reader->Seek(centraldir, SEEK_SET); - Reader->Read(&info, sizeof(FZipEndOfCentralDirectory)); + Reader.Seek(centraldir, FileRdr::SeekSet); + Reader.Read(&info, sizeof(FZipEndOfCentralDirectory)); // No multi-disk zips! if (info.NumEntries != info.NumEntriesOnAllDisks || @@ -212,8 +205,8 @@ bool FZipFile::Open(bool quiet) // Load the entire central directory. Too bad that this contains variable length entries... int dirsize = LittleLong(info.DirectorySize); void *directory = malloc(dirsize); - Reader->Seek(LittleLong(info.DirectoryOffset), SEEK_SET); - Reader->Read(directory, dirsize); + Reader.Seek(LittleLong(info.DirectoryOffset), FileRdr::SeekSet); + Reader.Read(directory, dirsize); char *dirptr = (char*)directory; FZipLump *lump_p = Lumps; @@ -349,6 +342,7 @@ bool FZipFile::Open(bool quiet) // The start of the Reader will be determined the first time it is accessed. lump_p->Flags = LUMPF_ZIPFILE | LUMPFZIP_NEEDFILESTART; lump_p->Method = uint8_t(zip_fh->Method); + if (lump_p->Method != METHOD_STORED) lump_p->Flags |= LUMPF_COMPRESSED; lump_p->GPFlags = zip_fh->Flags; lump_p->CRC32 = zip_fh->CRC32; lump_p->CompressedSize = LittleLong(zip_fh->CompressedSize); @@ -394,8 +388,8 @@ FCompressedBuffer FZipLump::GetRawData() { FCompressedBuffer cbuf = { (unsigned)LumpSize, (unsigned)CompressedSize, Method, GPFlags, CRC32, new char[CompressedSize] }; if (Flags & LUMPFZIP_NEEDFILESTART) SetLumpAddress(); - Owner->Reader->Seek(Position, SEEK_SET); - Owner->Reader->Read(cbuf.mBuffer, CompressedSize); + Owner->Reader.Seek(Position, FileRdr::SeekSet); + Owner->Reader.Read(cbuf.mBuffer, CompressedSize); return cbuf; } @@ -413,10 +407,8 @@ void FZipLump::SetLumpAddress() FZipLocalFileHeader localHeader; int skiplen; - FileReader *file = Owner->Reader; - - file->Seek(Position, SEEK_SET); - file->Read(&localHeader, sizeof(localHeader)); + Owner->Reader.Seek(Position, FileRdr::SeekSet); + Owner->Reader.Read(&localHeader, sizeof(localHeader)); skiplen = LittleShort(localHeader.NameLength) + LittleShort(localHeader.ExtraLength); Position += sizeof(localHeader) + skiplen; Flags &= ~LUMPFZIP_NEEDFILESTART; @@ -428,15 +420,15 @@ void FZipLump::SetLumpAddress() // //========================================================================== -FileReader *FZipLump::GetReader() +FileRdr *FZipLump::GetReader() { // Don't return the reader if this lump is encrypted // In that case always force caching of the lump if (Method == METHOD_STORED) { if (Flags & LUMPFZIP_NEEDFILESTART) SetLumpAddress(); - Owner->Reader->Seek(Position, SEEK_SET); - return Owner->Reader; + Owner->Reader.Seek(Position, FileRdr::SeekSet); + return &Owner->Reader; } else return NULL; } @@ -452,7 +444,7 @@ int FZipLump::FillCache() if (Flags & LUMPFZIP_NEEDFILESTART) SetLumpAddress(); const char *buffer; - if (Method == METHOD_STORED && (buffer = Owner->Reader->GetBuffer()) != NULL) + if (Method == METHOD_STORED && (buffer = Owner->Reader.GetBuffer()) != NULL) { // This is an in-memory file so the cache can point directly to the file's data. Cache = const_cast(buffer) + Position; @@ -460,7 +452,7 @@ int FZipLump::FillCache() return -1; } - Owner->Reader->Seek(Position, SEEK_SET); + Owner->Reader.Seek(Position, FileRdr::SeekSet); Cache = new char[LumpSize]; UncompressZipLump(Cache, Owner->Reader, Method, LumpSize, CompressedSize, GPFlags); RefCount = 1; @@ -486,21 +478,21 @@ int FZipLump::GetFileOffset() // //========================================================================== -FResourceFile *CheckZip(const char *filename, FileReader *file, bool quiet) +FResourceFile *CheckZip(const char *filename, FileRdr &file, bool quiet) { char head[4]; - if (file->GetLength() >= (long)sizeof(FZipLocalFileHeader)) + if (file.GetLength() >= (long)sizeof(FZipLocalFileHeader)) { - file->Seek(0, SEEK_SET); - file->Read(&head, 4); - file->Seek(0, SEEK_SET); + file.Seek(0, FileRdr::SeekSet); + file.Read(&head, 4); + file.Seek(0, FileRdr::SeekSet); if (!memcmp(head, "PK\x3\x4", 4)) { FResourceFile *rf = new FZipFile(filename, file); if (rf->Open(quiet)) return rf; - rf->Reader = NULL; // to avoid destruction of reader + file = std::move(rf->Reader); // to avoid destruction of reader delete rf; } } diff --git a/src/resourcefiles/file_zip.h b/src/resourcefiles/file_zip.h index 1078a07145..48f9a100ec 100644 --- a/src/resourcefiles/file_zip.h +++ b/src/resourcefiles/file_zip.h @@ -22,7 +22,7 @@ struct FZipLump : public FResourceLump int Position; unsigned CRC32; - virtual FileReader *GetReader(); + virtual FileRdr *GetReader(); virtual int FillCache(); private: @@ -43,7 +43,7 @@ class FZipFile : public FResourceFile FZipLump *Lumps; public: - FZipFile(const char * filename, FileReader *file); + FZipFile(const char * filename, FileRdr &file); virtual ~FZipFile(); bool Open(bool quiet); virtual FResourceLump *GetLump(int no) { return ((unsigned)no < NumLumps)? &Lumps[no] : NULL; } diff --git a/src/resourcefiles/resourcefile.cpp b/src/resourcefiles/resourcefile.cpp index 18a6b6f15b..f5fca6b098 100644 --- a/src/resourcefiles/resourcefile.cpp +++ b/src/resourcefiles/resourcefile.cpp @@ -45,7 +45,7 @@ //========================================================================== // -// FileReader that reads from a lump's cache +// File reader that reads from a lump's cache // //========================================================================== @@ -212,11 +212,11 @@ FCompressedBuffer FResourceLump::GetRawData() //========================================================================== // -// Returns the owner's FileReader if it can be used to access this lump +// Returns the owner's FileRdr if it can be used to access this lump // //========================================================================== -FileReader *FResourceLump::GetReader() +FileRdr *FResourceLump::GetReader() { return NULL; } @@ -227,9 +227,9 @@ FileReader *FResourceLump::GetReader() // //========================================================================== -FileReader *FResourceLump::NewReader() +FileRdr FResourceLump::NewReader() { - return new FLumpReader(this); + return FileRdr(new FLumpReader(this)); } //========================================================================== @@ -276,46 +276,45 @@ int FResourceLump::ReleaseCache() // //========================================================================== -typedef FResourceFile * (*CheckFunc)(const char *filename, FileReader *file, bool quiet); +typedef FResourceFile * (*CheckFunc)(const char *filename, FileRdr &file, bool quiet); -FResourceFile *CheckWad(const char *filename, FileReader *file, bool quiet); -FResourceFile *CheckGRP(const char *filename, FileReader *file, bool quiet); -FResourceFile *CheckRFF(const char *filename, FileReader *file, bool quiet); -FResourceFile *CheckPak(const char *filename, FileReader *file, bool quiet); -FResourceFile *CheckZip(const char *filename, FileReader *file, bool quiet); -FResourceFile *Check7Z(const char *filename, FileReader *file, bool quiet); -FResourceFile *CheckLump(const char *filename, FileReader *file, bool quiet); -FResourceFile *CheckDir(const char *filename, FileReader *file, bool quiet); +FResourceFile *CheckWad(const char *filename, FileRdr &file, bool quiet); +FResourceFile *CheckGRP(const char *filename, FileRdr &file, bool quiet); +FResourceFile *CheckRFF(const char *filename, FileRdr &file, bool quiet); +FResourceFile *CheckPak(const char *filename, FileRdr &file, bool quiet); +FResourceFile *CheckZip(const char *filename, FileRdr &file, bool quiet); +FResourceFile *Check7Z(const char *filename, FileRdr &file, bool quiet); +FResourceFile *CheckLump(const char *filename,FileRdr &file, bool quiet); +FResourceFile *CheckDir(const char *filename, bool quiet); static CheckFunc funcs[] = { CheckWad, CheckZip, Check7Z, CheckPak, CheckGRP, CheckRFF, CheckLump }; -FResourceFile *FResourceFile::OpenResourceFile(const char *filename, FileReader *file, bool quiet, bool containeronly) +FResourceFile *FResourceFile::DoOpenResourceFile(const char *filename, FileRdr &file, bool quiet, bool containeronly) { - bool mustclose = false; - if (file == NULL) - { - try - { - file = new FileReader(filename); - mustclose = true; - } - catch (CRecoverableError &) - { - return NULL; - } - } for(size_t i = 0; i < countof(funcs) - containeronly; i++) { FResourceFile *resfile = funcs[i](filename, file, quiet); if (resfile != NULL) return resfile; } - if (mustclose) delete file; return NULL; } +FResourceFile *FResourceFile::OpenResourceFile(const char *filename, FileRdr &file, bool quiet, bool containeronly) +{ + return DoOpenResourceFile(filename, file, quiet, containeronly); +} + + +FResourceFile *FResourceFile::OpenResourceFile(const char *filename, bool quiet, bool containeronly) +{ + FileRdr file; + if (!file.OpenFile(filename)) return nullptr; + return DoOpenResourceFile(filename, file, quiet, containeronly); +} + FResourceFile *FResourceFile::OpenDirectory(const char *filename, bool quiet) { - return CheckDir(filename, NULL, quiet); + return CheckDir(filename, quiet); } //========================================================================== @@ -324,18 +323,17 @@ FResourceFile *FResourceFile::OpenDirectory(const char *filename, bool quiet) // //========================================================================== -FResourceFile::FResourceFile(const char *filename, FileReader *r) +FResourceFile::FResourceFile(const char *filename, FileRdr &r) { if (filename != NULL) Filename = copystring(filename); else Filename = NULL; - Reader = r; + Reader = std::move(r); } FResourceFile::~FResourceFile() { if (Filename != NULL) delete [] Filename; - delete Reader; } int lumpcmp(const void * a, const void * b) @@ -607,10 +605,10 @@ FResourceLump *FResourceFile::FindLump(const char *name) // //========================================================================== -FileReader *FUncompressedLump::GetReader() +FileRdr *FUncompressedLump::GetReader() { - Owner->Reader->Seek(Position, SEEK_SET); - return Owner->Reader; + Owner->Reader.Seek(Position, FileRdr::SeekSet); + return &Owner->Reader; } //========================================================================== @@ -621,7 +619,7 @@ FileReader *FUncompressedLump::GetReader() int FUncompressedLump::FillCache() { - const char * buffer = Owner->Reader->GetBuffer(); + const char * buffer = Owner->Reader.GetBuffer(); if (buffer != NULL) { @@ -631,9 +629,9 @@ int FUncompressedLump::FillCache() return -1; } - Owner->Reader->Seek(Position, SEEK_SET); + Owner->Reader.Seek(Position, FileRdr::SeekSet); Cache = new char[LumpSize]; - Owner->Reader->Read(Cache, LumpSize); + Owner->Reader.Read(Cache, LumpSize); RefCount = 1; return 1; } @@ -644,7 +642,7 @@ int FUncompressedLump::FillCache() // //========================================================================== -FUncompressedFile::FUncompressedFile(const char *filename, FileReader *r) +FUncompressedFile::FUncompressedFile(const char *filename, FileRdr &r) : FResourceFile(filename, r) { Lumps = NULL; @@ -669,11 +667,11 @@ FExternalLump::FExternalLump(const char *_filename, int filesize) if (filesize == -1) { - FileReader f; + FileRdr f; - if (f.Open(_filename)) + if (f.OpenFile(_filename)) { - LumpSize = f.GetLength(); + LumpSize = (int)f.GetLength(); } else { @@ -702,9 +700,9 @@ FExternalLump::~FExternalLump() int FExternalLump::FillCache() { Cache = new char[LumpSize]; - FileReader f; + FileRdr f; - if (f.Open(filename)) + if (f.OpenFile(filename)) { f.Read(Cache, LumpSize); } @@ -728,7 +726,7 @@ bool FMemoryFile::Open(bool quiet) Lumps->FullName = fname; Lumps->Owner = this; Lumps->Position = 0; - Lumps->LumpSize = Reader->GetLength(); + Lumps->LumpSize = (int)Reader.GetLength(); Lumps->Namespace = ns_global; Lumps->Flags = 0; Lumps->FullName = NULL; diff --git a/src/resourcefiles/resourcefile.h b/src/resourcefiles/resourcefile.h index f7cc806e2b..0d795fae37 100644 --- a/src/resourcefiles/resourcefile.h +++ b/src/resourcefiles/resourcefile.h @@ -62,8 +62,8 @@ struct FResourceLump } virtual ~FResourceLump(); - virtual FileReader *GetReader(); - virtual FileReader *NewReader(); + virtual FileRdr *GetReader(); + virtual FileRdr NewReader(); virtual int GetFileOffset() { return -1; } virtual int GetIndexNum() const { return 0; } void LumpNameSetup(FString iname); @@ -81,12 +81,12 @@ protected: class FResourceFile { public: - FileReader *Reader; + FileRdr Reader; const char *Filename; protected: uint32_t NumLumps; - FResourceFile(const char *filename, FileReader *r); + FResourceFile(const char *filename, FileRdr &r); // for archives that can contain directories void PostProcessArchive(void *lumps, size_t lumpsize); @@ -98,12 +98,14 @@ private: int FilterLumpsByGameType(int gametype, void *lumps, size_t lumpsize, uint32_t max); bool FindPrefixRange(FString filter, void *lumps, size_t lumpsize, uint32_t max, uint32_t &start, uint32_t &end); void JunkLeftoverFilters(void *lumps, size_t lumpsize, uint32_t max); + static FResourceFile *DoOpenResourceFile(const char *filename, FileRdr &file, bool quiet, bool containeronly); public: - static FResourceFile *OpenResourceFile(const char *filename, FileReader *file, bool quiet = false, bool containeronly = false); + static FResourceFile *OpenResourceFile(const char *filename, FileRdr &file, bool quiet = false, bool containeronly = false); + static FResourceFile *OpenResourceFile(const char *filename, bool quiet = false, bool containeronly = false); static FResourceFile *OpenDirectory(const char *filename, bool quiet = false); virtual ~FResourceFile(); - FileReader *GetReader() const { return Reader; } + FileRdr *GetReader() { return &Reader; } uint32_t LumpCount() const { return NumLumps; } uint32_t GetFirstLump() const { return FirstLump; } void SetFirstLump(uint32_t f) { FirstLump = f; } @@ -118,7 +120,7 @@ struct FUncompressedLump : public FResourceLump { int Position; - virtual FileReader *GetReader(); + virtual FileRdr *GetReader(); virtual int FillCache(); virtual int GetFileOffset() { return Position; } @@ -132,7 +134,7 @@ protected: FUncompressedLump * Lumps; - FUncompressedFile(const char *filename, FileReader *r); + FUncompressedFile(const char *filename, FileRdr &r); virtual ~FUncompressedFile(); virtual FResourceLump *GetLump(int no) { return ((unsigned)no < NumLumps)? &Lumps[no] : NULL; } @@ -152,12 +154,10 @@ struct FExternalLump : public FResourceLump struct FMemoryFile : public FUncompressedFile { - MemoryArrayReader mr; - FMemoryFile(const char *_filename, const void *sdata, int length) - : FUncompressedFile(_filename, nullptr), mr((const char *)sdata, length) + : FUncompressedFile(_filename, FileRdr()) { - Reader = &mr; + Reader.OpenMemoryArray(sdata, length); } bool Open(bool quiet); diff --git a/src/sound/i_soundfont.cpp b/src/sound/i_soundfont.cpp index 1416e380ea..587143fa49 100644 --- a/src/sound/i_soundfont.cpp +++ b/src/sound/i_soundfont.cpp @@ -145,7 +145,7 @@ FileRdr FSF2Reader::OpenFile(const char *name) FZipPatReader::FZipPatReader(const char *filename) { - resf = FResourceFile::OpenResourceFile(filename, nullptr, true); + resf = FResourceFile::OpenResourceFile(filename, true); } FZipPatReader::~FZipPatReader() @@ -166,7 +166,7 @@ FileRdr FZipPatReader::OpenFile(const char *name) auto lump = resf->FindLump(name); if (lump != nullptr) { - return FileRdr(lump->NewReader()); // temporary workaround + return lump->NewReader(); } } return fr; @@ -306,7 +306,7 @@ void FSoundFontManager::ProcessOneFile(const FString &fn) } else if (!memcmp(head, "PK", 2)) { - auto zip = FResourceFile::OpenResourceFile(fn, nullptr, true); + auto zip = FResourceFile::OpenResourceFile(fn, true); if (zip != nullptr) { if (zip->LumpCount() > 1) // Anything with just one lump cannot possibly be a packed GUS patch set so skip it right away and simplify the lookup code diff --git a/src/textures/texture.cpp b/src/textures/texture.cpp index 165518098c..69c1ee5ef4 100644 --- a/src/textures/texture.cpp +++ b/src/textures/texture.cpp @@ -47,7 +47,6 @@ #include "textures/textures.h" #include "v_palette.h" -typedef bool (*CheckFunc)(FileReader & file); typedef FTexture * (*CreateFunc)(FileRdr & file, int lumpnum); struct TexCreateInfo diff --git a/src/textures/textures.h b/src/textures/textures.h index c80abf87b2..006d24bb7f 100644 --- a/src/textures/textures.h +++ b/src/textures/textures.h @@ -147,8 +147,6 @@ struct patch_t // the [0] is &columnofs[width] }; -class FileReader; - // All FTextures present their data to the world in 8-bit format, but if // the source data is something else, this is it. enum FTextureFormat diff --git a/src/w_wad.cpp b/src/w_wad.cpp index 716b7f3222..9b995332b5 100644 --- a/src/w_wad.cpp +++ b/src/w_wad.cpp @@ -225,12 +225,13 @@ int FWadCollection::AddExternalFile(const char *filename) // [RH] Removed reload hack //========================================================================== -void FWadCollection::AddFile (const char *filename, FileReader *wadinfo) +void FWadCollection::AddFile (const char *filename, FileRdr *wadr) { int startlump; bool isdir = false; + FileRdr wadreader; - if (wadinfo == NULL) + if (wadr == nullptr) { // Does this exist? If so, is it a directory? if (!DirEntryExists(filename, &isdir)) @@ -242,18 +243,15 @@ void FWadCollection::AddFile (const char *filename, FileReader *wadinfo) if (!isdir) { - try - { - wadinfo = new FileReader(filename); - } - catch (CRecoverableError &err) + if (!wadreader.OpenFile(filename)) { // Didn't find file - Printf (TEXTCOLOR_RED "%s\n", err.GetMessage()); + Printf (TEXTCOLOR_RED "%s: File not found\n", filename); PrintLastError (); return; } } } + else wadreader = std::move(*wadr); if (!batchrun) Printf (" adding %s", filename); startlump = NumLumps; @@ -261,7 +259,7 @@ void FWadCollection::AddFile (const char *filename, FileReader *wadinfo) FResourceFile *resfile; if (!isdir) - resfile = FResourceFile::OpenResourceFile(filename, wadinfo); + resfile = FResourceFile::OpenResourceFile(filename, wadreader); else resfile = FResourceFile::OpenDirectory(filename); @@ -292,8 +290,8 @@ void FWadCollection::AddFile (const char *filename, FileReader *wadinfo) { FString path; path.Format("%s:%s", filename, lump->FullName.GetChars()); - FileReader *embedded = lump->NewReader(); - AddFile(path, embedded); + auto embedded = lump->NewReader(); + AddFile(path, &embedded); } } @@ -303,14 +301,11 @@ void FWadCollection::AddFile (const char *filename, FileReader *wadinfo) char cksumout[33]; memset(cksumout, 0, sizeof(cksumout)); - FileReader *reader = wadinfo; - - if (reader != NULL) + if (wadreader.isOpen()) { MD5Context md5; - reader->Seek(0, SEEK_SET); -#pragma message("This does not work!"); - //md5.Update(FileRdr(reader), reader->GetLength()); + wadreader.Seek(0, FileRdr::SeekSet); + md5.Update(wadreader, (unsigned)wadreader.GetLength()); md5.Final(cksum); for (size_t j = 0; j < sizeof(cksum); ++j) @@ -318,7 +313,7 @@ void FWadCollection::AddFile (const char *filename, FileReader *wadinfo) sprintf(cksumout + (j * 2), "%02X", cksum[j]); } - fprintf(hashfile, "file: %s, hash: %s, size: %ld\n", filename, cksumout, reader->GetLength()); + fprintf(hashfile, "file: %s, hash: %s, size: %lld\n", filename, cksumout, (int64_t)wadreader.GetLength()); } else @@ -331,7 +326,7 @@ void FWadCollection::AddFile (const char *filename, FileReader *wadinfo) if (!(lump->Flags & LUMPF_EMBEDDED)) { MD5Context md5; - md5.Update(FileRdr(lump->NewReader()), lump->LumpSize); + md5.Update(lump->NewReader(), lump->LumpSize); md5.Final(cksum); for (size_t j = 0; j < sizeof(cksum); ++j) @@ -926,7 +921,7 @@ void FWadCollection::RenameNerve () int w = GetIwadNum(); while (++w < GetNumWads()) { - FileReader *fr = GetFileReader(w); + auto fr = GetFileReader(w); if (fr == NULL) { continue; @@ -937,10 +932,9 @@ void FWadCollection::RenameNerve () // cheaper way to know this is not the file continue; } - fr->Seek(0, SEEK_SET); + fr->Seek(0, FileRdr::SeekSet); MD5Context md5; -#pragma message("This does not work yet!"); - //md5.Update(fr, fr->GetLength()); + md5.Update(*fr, (unsigned)fr->GetLength()); md5.Final(cksum); if (memcmp(nerve, cksum, 16) == 0) { @@ -988,8 +982,8 @@ void FWadCollection::FixMacHexen() return; } - FileReader* const reader = GetFileReader(GetIwadNum()); - const long iwadSize = reader->GetLength(); + FileRdr *reader = GetFileReader(GetIwadNum()); + auto iwadSize = reader->GetLength(); static const long DEMO_SIZE = 13596228; static const long BETA_SIZE = 13749984; @@ -1002,13 +996,12 @@ void FWadCollection::FixMacHexen() return; } - reader->Seek(0, SEEK_SET); + reader->Seek(0, FileRdr::SeekSet); uint8_t checksum[16]; MD5Context md5; -#pragma message("This does not work yet!"); - //md5.Update(reader, iwadSize); + md5.Update(*reader, (unsigned)iwadSize); md5.Final(checksum); static const uint8_t HEXEN_DEMO_MD5[16] = @@ -1271,9 +1264,9 @@ int FWadCollection::GetLumpFile (int lump) const void FWadCollection::ReadLump (int lump, void *dest) { - FWadLump lumpr = OpenLumpNum (lump); - long size = lumpr.GetLength (); - long numread = lumpr.Read (dest, size); + auto lumpr = OpenLumpReader (lump); + auto size = lumpr.GetLength (); + auto numread = lumpr.Read (dest, size); if (numread != size) { @@ -1303,55 +1296,6 @@ DEFINE_ACTION_FUNCTION(_Wads, ReadLump) ACTION_RETURN_STRING(isLumpValid ? Wads.ReadLump(lump).GetString() : FString()); } -//========================================================================== -// -// OpenLumpNum -// -// Returns a copy of the file object for a lump's wad and positions its -// file pointer at the beginning of the lump. -// -//========================================================================== - -FWadLump FWadCollection::OpenLumpNum (int lump) -{ - if ((unsigned)lump >= (unsigned)LumpInfo.Size()) - { - I_Error ("W_OpenLumpNum: %u >= NumLumps", lump); - } - - return FWadLump(LumpInfo[lump].lump); -} - -//========================================================================== -// -// ReopenLumpNum -// -// Similar to OpenLumpNum, except a new, independant file object is created -// for the lump's wad. Use this when you won't read the lump's data all at -// once (e.g. for streaming an Ogg Vorbis stream from a wad as music). -// -//========================================================================== - -FWadLump *FWadCollection::ReopenLumpNum (int lump) -{ - if ((unsigned)lump >= (unsigned)LumpInfo.Size()) - { - I_Error ("W_ReopenLumpNum: %u >= NumLumps", lump); - } - - return new FWadLump(LumpInfo[lump].lump, true); -} - -FWadLump *FWadCollection::ReopenLumpNumNewFile (int lump) -{ - if ((unsigned)lump >= (unsigned)LumpInfo.Size()) - { - return NULL; - } - - return new FWadLump(lump, LumpInfo[lump].lump); -} - //========================================================================== // // OpenLumpReader @@ -1363,34 +1307,56 @@ FWadLump *FWadCollection::ReopenLumpNumNewFile (int lump) FileRdr FWadCollection::OpenLumpReader(int lump) { - FileRdr rdr; - if ((unsigned)lump >= (unsigned)LumpInfo.Size()) { I_Error("W_OpenLumpNum: %u >= NumLumps", lump); } - rdr.mReader = new FWadLump(LumpInfo[lump].lump); - return rdr; + auto rl = LumpInfo[lump].lump; + auto rd = rl->GetReader(); + + if (rl->RefCount == 0 && rd != nullptr && !rd->GetBuffer() && !(rl->Flags & (LUMPF_BLOODCRYPT | LUMPF_COMPRESSED))) + { + FileRdr rdr; + rdr.OpenFilePart(*rd, rl->GetFileOffset(), rl->LumpSize); + return rdr; + } + return rl->NewReader(); // This always gets a reader to the cache } FileRdr FWadCollection::ReopenLumpReader(int lump, bool alwayscache) { - FileRdr rdr; - rdr.mReader = alwayscache ? ReopenLumpNumNewFile(lump) : ReopenLumpNum(lump); - return rdr; + if ((unsigned)lump >= (unsigned)LumpInfo.Size()) + { + I_Error("ReopenLumpReader: %u >= NumLumps", lump); + } + + auto rl = LumpInfo[lump].lump; + auto rd = rl->GetReader(); + + if (rl->RefCount == 0 && rd != nullptr && !rd->GetBuffer() && !alwayscache && !(rl->Flags & (LUMPF_BLOODCRYPT|LUMPF_COMPRESSED))) + { + int fileno = Wads.GetLumpFile(lump); + const char *filename = Wads.GetWadFullName(fileno); + FileRdr fr; + if (fr.OpenFile(filename, rl->GetFileOffset(), rl->LumpSize)) + { + return fr; + } + } + return rl->NewReader(); // This always gets a reader to the cache } //========================================================================== // // GetFileReader // -// Retrieves the FileReader object to access the given WAD +// Retrieves the File reader object to access the given WAD // Careful: This is only useful for real WAD files! // //========================================================================== -FileReader *FWadCollection::GetFileReader(int wadnum) +FileRdr *FWadCollection::GetFileReader(int wadnum) { if ((uint32_t)wadnum >= Files.Size()) { @@ -1486,31 +1452,6 @@ const char *FWadCollection::GetWadFullName (int wadnum) const } -//========================================================================== -// -// IsUncompressedFile -// -// Returns true when the lump is available as an uncompressed portion of -// a file. The music player can play such lumps by streaming but anything -// else has to be loaded into memory first. -// -//========================================================================== - -bool FWadCollection::IsUncompressedFile(int lump) const -{ - if ((unsigned)lump >= (unsigned)NumLumps) - { - I_Error ("IsUncompressedFile: %u >= NumLumps",lump); - } - - FResourceLump *l = LumpInfo[lump].lump; - FileReader *f = l->GetReader(); - - // We can access the file only if we get the FILE pointer from the FileReader here. - // Any other case means it won't work. - return (f != NULL && f->GetFile() != NULL); -} - //========================================================================== // // IsEncryptedFile @@ -1529,157 +1470,6 @@ bool FWadCollection::IsEncryptedFile(int lump) const } -// FWadLump ----------------------------------------------------------------- - -FWadLump::FWadLump () -: FileReader(), Lump(NULL) -{ -} - -FWadLump::FWadLump (const FWadLump ©) -: FileReader() -{ - // This must be defined isn't called. - File = copy.File; - Length = copy.Length; - FilePos = copy.FilePos; - StartPos = copy.StartPos; - CloseOnDestruct = false; - if ((Lump = copy.Lump)) Lump->CacheLump(); -} - -#ifdef _DEBUG -FWadLump & FWadLump::operator= (const FWadLump ©) -{ - // Only the debug build actually calls this! - File = copy.File; - Length = copy.Length; - FilePos = copy.FilePos; - StartPos = copy.StartPos; - CloseOnDestruct = false; - if ((Lump = copy.Lump)) Lump->CacheLump(); - return *this; -} -#endif - - -FWadLump::FWadLump(FResourceLump *lump, bool alwayscache) -: FileReader() -{ - FileReader *f = lump->GetReader(); - - if (f != NULL && f->GetFile() != NULL && !alwayscache) - { - // Uncompressed lump in a file - File = f->GetFile(); - Length = lump->LumpSize; - StartPos = FilePos = lump->GetFileOffset(); - Lump = NULL; - } - else - { - File = NULL; - Length = lump->LumpSize; - StartPos = FilePos = 0; - Lump = lump; - Lump->CacheLump(); - } -} - -FWadLump::FWadLump(int lumpnum, FResourceLump *lump) -: FileReader() -{ - FileReader *f = lump->GetReader(); - - if (f != NULL && f->GetFile() != NULL) - { - // Uncompressed lump in a file. For this we will have to open a new FILE, since we need it for streaming - int fileno = Wads.GetLumpFile(lumpnum); - const char *filename = Wads.GetWadFullName(fileno); - File = openfd(filename); - if (File != NULL) - { - Length = lump->LumpSize; - StartPos = FilePos = lump->GetFileOffset(); - Lump = NULL; - CloseOnDestruct = true; - Seek(0, SEEK_SET); - return; - } - } - File = NULL; - Length = lump->LumpSize; - StartPos = FilePos = 0; - Lump = lump; - Lump->CacheLump(); -} - -FWadLump::~FWadLump() -{ - if (Lump != NULL) - { - Lump->ReleaseCache(); - } -} - -long FWadLump::Seek (long offset, int origin) -{ - if (Lump != NULL) - { - switch (origin) - { - case SEEK_CUR: - offset += FilePos; - break; - - case SEEK_END: - offset += Length; - break; - - default: - break; - } - FilePos = clamp (offset, 0, Length); - return 0; - } - return FileReader::Seek(offset, origin); -} - -long FWadLump::Read (void *buffer, long len) -{ - long numread; - long startread = FilePos; - - if (Lump != NULL) - { - if (FilePos + len > Length) - { - len = Length - FilePos; - } - memcpy(buffer, Lump->Cache + FilePos, len); - FilePos += len; - numread = len; - } - else - { - numread = FileReader::Read(buffer, len); - } - return numread; -} - -char *FWadLump::Gets(char *strbuf, int len) -{ - if (Lump != NULL) - { - return GetsFromBuffer(Lump->Cache, strbuf, len); - } - else - { - return FileReader::Gets(strbuf, len); - } - return strbuf; -} - // FMemLump ----------------------------------------------------------------- FMemLump::FMemLump () @@ -1708,10 +1498,10 @@ FMemLump::~FMemLump () FString::FString (ELumpNum lumpnum) { - FWadLump lumpr = Wads.OpenLumpNum ((int)lumpnum); - long size = lumpr.GetLength (); + auto lumpr = Wads.OpenLumpReader ((int)lumpnum); + auto size = lumpr.GetLength (); AllocBuffer (1 + size); - long numread = lumpr.Read (&Chars[0], size); + auto numread = lumpr.Read (&Chars[0], size); Chars[size] = '\0'; if (numread != size) diff --git a/src/w_wad.h b/src/w_wad.h index 73f8185645..398c80f662 100644 --- a/src/w_wad.h +++ b/src/w_wad.h @@ -68,44 +68,18 @@ typedef enum { enum ELumpFlags { - LUMPF_MAYBEFLAT=1, - LUMPF_ZIPFILE=2, - LUMPF_EMBEDDED=4, - LUMPF_BLOODCRYPT = 8, + LUMPF_MAYBEFLAT=1, // might be a flat outside F_START/END + LUMPF_ZIPFILE=2, // contains a full path + LUMPF_EMBEDDED=4, // from an embedded WAD + LUMPF_BLOODCRYPT = 8, // encrypted + LUMPF_COMPRESSED = 16, // compressed + LUMPF_SEQUENTIAL = 32, // compressed but a sequential reader can be retrieved. }; // [RH] Copy an 8-char string and uppercase it. void uppercopy (char *to, const char *from); -// A very loose reference to a lump on disk. This is really just a wrapper -// around the main wad's FILE object with a different length recorded. Since -// two lumps from the same wad share the same FILE, you cannot read from -// both of them independantly. -class FWadLump : public FileReader -{ -public: - FWadLump (); - FWadLump (const FWadLump ©); -#ifdef _DEBUG - FWadLump & operator= (const FWadLump ©); -#endif - ~FWadLump(); - - long Seek (long offset, int origin); - long Read (void *buffer, long len); - char *Gets(char *strbuf, int len); - -private: - FWadLump (FResourceLump *Lump, bool alwayscache = false); - FWadLump(int lumpnum, FResourceLump *lump); - - FResourceLump *Lump; - - friend class FWadCollection; -}; - - // A lump in memory. class FMemLump { @@ -138,7 +112,7 @@ public: void SetIwadNum(int x) { IwadIndex = x; } void InitMultipleFiles (TArray &filenames); - void AddFile (const char *filename, FileReader *wadinfo = NULL); + void AddFile (const char *filename, FileRdr *wadinfo = NULL); int CheckIfWadLoaded (const char *name); const char *GetWadName (int wadnum) const; @@ -180,10 +154,6 @@ public: FileRdr OpenLumpReader(int lump); // opens a reader that redirects to the containing file's one. FileRdr ReopenLumpReader(int lump, bool alwayscache = false); // opens an independent reader. - FWadLump OpenLumpNum (int lump); - FWadLump *ReopenLumpNum (int lump); // Opens a new, independent FILE - FWadLump *ReopenLumpNumNewFile (int lump); // Opens a new, independent FILE - int FindLump (const char *name, int *lastlump, bool anyns=false); // [RH] Find lumps with duplication int FindLumpMulti (const char **names, int *lastlump, bool anyns = false, int *nameindex = NULL); // same with multiple possible names bool CheckLumpName (int lump, const char *name); // [RH] True if lump's name == name @@ -202,7 +172,6 @@ public: int GetLumpIndexNum (int lump) const; // Returns the RFF index number for this lump bool CheckLumpName (int lump, const char *name) const; // [RH] Returns true if the names match - bool IsUncompressedFile(int lump) const; bool IsEncryptedFile(int lump) const; int GetNumLumps () const; @@ -237,7 +206,7 @@ private: void RenameNerve(); void FixMacHexen(); void DeleteAll(); - FileReader * GetFileReader(int wadnum); // Gets a FileReader object to the entire WAD + FileRdr * GetFileReader(int wadnum); // Gets a FileRdr object to the entire WAD }; extern FWadCollection Wads; diff --git a/src/w_zip.h b/src/w_zip.h index 6120e629bf..0a2ce6d4e4 100644 --- a/src/w_zip.h +++ b/src/w_zip.h @@ -62,14 +62,6 @@ struct FZipLocalFileHeader #define ZIP_CENTRALFILE MAKE_ID('P','K',1,2) #define ZIP_ENDOFDIR MAKE_ID('P','K',5,6) -#define METHOD_STORED 0 -#define METHOD_SHRINK 1 -#define METHOD_IMPLODE 6 -#define METHOD_DEFLATE 8 -#define METHOD_BZIP2 12 -#define METHOD_LZMA 14 -#define METHOD_PPMD 98 - // File header flags. #define ZF_ENCRYPTED 0x1 From 8bbfd39f423433f8049c7b16b77f69f435a05d0c Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Sun, 11 Mar 2018 13:26:30 +0100 Subject: [PATCH 24/89] - fixed some remaining issues: * initial positioning in a subsection of a file failed. This mainly affected music playback. * made the FileRdr constructor which takes a FileReaderInterface private so that everything that needs it must be explicitly declared as friend. * removed a few redundant construction initializers for FileRdrs. * loading compressed nodes needs to check the validity of its reader. * use GetLength to detemine the size of a Zip file instead of doing another seek to the end. * removed duplicate Length variables. --- src/files.cpp | 8 +++----- src/files.h | 28 ++++++++++++++++++++-------- src/files_decompress.cpp | 33 ++++++++++++++------------------- src/m_png.cpp | 2 +- src/p_setup.cpp | 4 ++-- src/resourcefiles/file_zip.cpp | 4 +--- src/sound/oalsound.cpp | 2 +- 7 files changed, 42 insertions(+), 39 deletions(-) diff --git a/src/files.cpp b/src/files.cpp index b445c27898..f0939c9236 100644 --- a/src/files.cpp +++ b/src/files.cpp @@ -51,7 +51,6 @@ class StdFileReader : public FileReaderInterface { FILE *File = nullptr; - long Length = 0; long StartPos = 0; long FilePos = 0; @@ -76,7 +75,7 @@ public: StartPos = startpos; Length = CalcFileLen(); if (len >= 0 && len < Length) Length = len; - if (startpos > 0) Seek(startpos, SEEK_SET); + if (startpos > 0) Seek(0, SEEK_SET); return true; } @@ -99,7 +98,7 @@ public: { offset += StartPos + Length; } - if (offset < StartPos || offset >= StartPos + Length) return -1; // out of scope + if (offset < StartPos || offset > StartPos + Length) return -1; // out of scope if (0 == fseek(File, offset, SEEK_SET)) { @@ -161,7 +160,6 @@ private: class FileReaderRedirect : public FileReaderInterface { FileRdr *mReader = nullptr; - long Length = 0; long StartPos = 0; long FilePos = 0; @@ -196,7 +194,7 @@ public: offset += (long)mReader->Tell(); break; } - if (offset < StartPos || offset >= StartPos + Length) return -1; // out of scope + if (offset < StartPos || offset > StartPos + Length) return -1; // out of scope if (mReader->Seek(offset, FileRdr::SeekSet) == 0) { FilePos = offset; diff --git a/src/files.h b/src/files.h index c567baac81..f4cf5c10f1 100644 --- a/src/files.h +++ b/src/files.h @@ -43,7 +43,7 @@ #include "doomtype.h" #include "m_swap.h" -// Zip compression methods, extended by some internal types to be passed to FileReader::OpenDecompressor +// Zip compression methods, extended by some internal types to be passed to OpenDecompressor enum { METHOD_STORED = 0, @@ -70,6 +70,16 @@ public: long GetLength () const { return Length; } }; +class DecompressorBase : public FileReaderInterface +{ +public: + // These do not work but need to be defined to satisfy the FileReaderInterface. + // They will just error out when called. + long Tell() const override; + long Seek(long offset, int origin) override; + char *Gets(char *strbuf, int len) override; +}; + class MemoryReader : public FileReaderInterface { protected: @@ -95,14 +105,22 @@ public: }; +struct FResourceLump; -class FileRdr // this is just a temporary name, until the old FileReader hierarchy can be made private. +class FileRdr { + friend struct FResourceLump; // needs access to the private constructor. + FileReaderInterface *mReader = nullptr; FileRdr(const FileRdr &r) = delete; FileRdr &operator=(const FileRdr &r) = delete; + explicit FileRdr(FileReaderInterface *r) + { + mReader = r; + } + public: enum ESeek { @@ -115,12 +133,6 @@ public: FileRdr() {} - // These two functions are only needed as long as the FileReader has not been fully replaced throughout the code. - explicit FileRdr(FileReaderInterface *r) - { - mReader = r; - } - FileRdr(FileRdr &&r) { mReader = r.mReader; diff --git a/src/files_decompress.cpp b/src/files_decompress.cpp index 4b295fe383..0e8c905ba2 100644 --- a/src/files_decompress.cpp +++ b/src/files_decompress.cpp @@ -42,26 +42,21 @@ #include "m_misc.h" -class DecompressorBase : public FileReaderInterface +long DecompressorBase::Tell () const { -public: - // These do not work but need to be defined to satisfy the FileReader interface - long Tell () const override - { - I_Error("Cannot get position of decompressor stream"); - return 0; - } - virtual long Seek (long offset, int origin) override - { - I_Error("Cannot seek in decompressor stream"); - return 0; - } - virtual char *Gets(char *strbuf, int len) override - { - I_Error("Cannot use Gets on decompressor stream"); - return nullptr; - } -}; + I_Error("Cannot get position of decompressor stream"); + return 0; +} +long DecompressorBase::Seek (long offset, int origin) +{ + I_Error("Cannot seek in decompressor stream"); + return 0; +} +char *DecompressorBase::Gets(char *strbuf, int len) +{ + I_Error("Cannot use Gets on decompressor stream"); + return nullptr; +} //========================================================================== // diff --git a/src/m_png.cpp b/src/m_png.cpp index 63e57e35ce..ee73e02706 100644 --- a/src/m_png.cpp +++ b/src/m_png.cpp @@ -75,7 +75,7 @@ struct IHDR uint8_t Interlace; }; -PNGHandle::PNGHandle (FileRdr &file) : File(0), bDeleteFilePtr(true), ChunkPt(0) +PNGHandle::PNGHandle (FileRdr &file) : bDeleteFilePtr(true), ChunkPt(0) { File = std::move(file); } diff --git a/src/p_setup.cpp b/src/p_setup.cpp index 8438e4074a..f02c8f121f 100644 --- a/src/p_setup.cpp +++ b/src/p_setup.cpp @@ -3853,7 +3853,7 @@ void P_SetupLevel (const char *lumpname, int position) if (!ForceNodeBuild) { // Check for compressed nodes first, then uncompressed nodes - FileRdr *fr; + FileRdr *fr = nullptr; uint32_t id = MAKE_ID('X','x','X','x'), idcheck = 0, idcheck2 = 0, idcheck3 = 0, idcheck4 = 0, idcheck5 = 0, idcheck6 = 0; if (map->Size(ML_ZNODES) != 0) @@ -3874,7 +3874,7 @@ void P_SetupLevel (const char *lumpname, int position) idcheck6 = MAKE_ID('X','G','L','3'); } - fr->Read (&id, 4); + if (fr != nullptr && fr->isOpen()) fr->Read (&id, 4); if (id != 0 && (id == idcheck || id == idcheck2 || id == idcheck3 || id == idcheck4 || id == idcheck5 || id == idcheck6)) { try diff --git a/src/resourcefiles/file_zip.cpp b/src/resourcefiles/file_zip.cpp index a2015ac58b..684a3424ff 100644 --- a/src/resourcefiles/file_zip.cpp +++ b/src/resourcefiles/file_zip.cpp @@ -124,9 +124,7 @@ static uint32_t Zip_FindCentralDir(FileRdr &fin) uint32_t uMaxBack; // maximum size of global comment uint32_t uPosFound=0; - fin.Seek(0, FileRdr::SeekEnd); - - FileSize = (uint32_t)fin.Tell(); + FileSize = (uint32_t)fin.GetLength(); uMaxBack = MIN(0xffff, FileSize); uBackRead = 4; diff --git a/src/sound/oalsound.cpp b/src/sound/oalsound.cpp index ac2d346e99..a08077844c 100644 --- a/src/sound/oalsound.cpp +++ b/src/sound/oalsound.cpp @@ -290,7 +290,7 @@ class OpenALSoundStream : public SoundStream public: OpenALSoundStream(OpenALSoundRenderer *renderer) - : Renderer(renderer), Source(0), Playing(false), Looping(false), Volume(1.0f), Reader(NULL), Decoder(NULL) + : Renderer(renderer), Source(0), Playing(false), Looping(false), Volume(1.0f), Decoder(NULL) { memset(Buffers, 0, sizeof(Buffers)); Renderer->AddStream(this); From 833dbee1673172222e2cc1526f64efed3f003822 Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Sun, 11 Mar 2018 14:35:36 +0100 Subject: [PATCH 25/89] - fixed some issues with m_swap's design. The native byte order converters were defined as macros which hid some issues due to lack of type checks. Additionally the ???Long variants taking 'long' variables were removed, because longs are not always 32 bits so this could be destructive. As a result of this, removed several DWORDs from struct definitions in i_crash.cpp. --- src/m_png.cpp | 2 +- src/m_swap.h | 78 +++++++++++-------- src/resourcefiles/file_zip.cpp | 41 +++++----- .../music_wavewriter_mididevice.cpp | 16 ++-- src/win32/i_crash.cpp | 53 ++++++------- 5 files changed, 104 insertions(+), 86 deletions(-) diff --git a/src/m_png.cpp b/src/m_png.cpp index ee73e02706..23b7e57ce8 100644 --- a/src/m_png.cpp +++ b/src/m_png.cpp @@ -264,7 +264,7 @@ bool M_AppendPNGText (FileWriter *file, const char *keyword, const char *text) { crc = AddCRC32 (crc, (uint8_t *)text, len); } - crc = BigLong((unsigned int)crc); + crc = BigLong(crc); return file->Write (&crc, 4) == 4; } return false; diff --git a/src/m_swap.h b/src/m_swap.h index a68a0837b7..a3e03bea2a 100644 --- a/src/m_swap.h +++ b/src/m_swap.h @@ -46,16 +46,6 @@ inline unsigned int LittleLong(unsigned int x) return OSSwapLittleToHostInt32(x); } -inline int LittleLong(long x) -{ - return OSSwapLittleToHostInt32((uint32_t)x); -} - -inline unsigned int LittleLong(unsigned long x) -{ - return OSSwapLittleToHostInt32((uint32_t)x); -} - inline short BigShort(short x) { return (short)OSSwapBigToHostInt16((uint16_t)x); @@ -76,8 +66,7 @@ inline unsigned int BigLong(unsigned int x) return OSSwapBigToHostInt32(x); } -#else -#ifdef __BIG_ENDIAN__ +#elif defined __BIG_ENDIAN__ // Swap 16bit, that is, MSB and LSB byte. // No masking with 0xFF should be necessary. @@ -120,42 +109,66 @@ inline int LittleLong (int x) | (((unsigned int)x)<<24)); } -inline unsigned int LittleLong(unsigned long x) +inline short BigShort(short x) { - return LittleLong((unsigned int)x); + return x; } -inline int LittleLong(long x) +inline unsigned short BigShort(unsigned short x) { - return LittleLong((int)x); + return x; } -#define BigShort(x) (x) -#define BigLong(x) (x) +inline unsigned int BigLong(unsigned int &x) +{ + return x; +} + +inline int BigLong(int &x) +{ + return x; +} #else -#define LittleShort(x) (x) -#define LittleLong(x) (x) +inline short LittleShort(short x) +{ + return x; +} -#if defined(_MSC_VER) +inline unsigned short LittleShort(unsigned short x) +{ + return x; +} -inline short BigShort (short x) +inline unsigned int LittleLong(unsigned int x) +{ + return x; +} + +inline int LittleLong(int x) +{ + return x; +} + +#ifdef _MSC_VER + +inline short BigShort(short x) { return (short)_byteswap_ushort((unsigned short)x); } -inline unsigned short BigShort (unsigned short x) +inline unsigned short BigShort(unsigned short x) { return _byteswap_ushort(x); } -inline int BigLong (int x) +inline int BigLong(int x) { return (int)_byteswap_ulong((unsigned long)x); } -inline unsigned int BigLong (unsigned int x) +inline unsigned int BigLong(unsigned int x) { return (unsigned int)_byteswap_ulong((unsigned long)x); } @@ -190,10 +203,16 @@ inline int BigLong (int x) | ((((unsigned int)x)<<8) & 0xff0000) | (((unsigned int)x)<<24)); } + #endif #endif // __BIG_ENDIAN__ -#endif // __APPLE__ + +// These may be destructive so they should create errors +unsigned long BigLong(unsigned long) = delete; +long BigLong(long) = delete; +unsigned long LittleLong(unsigned long) = delete; +long LittleLong(long) = delete; // Data accessors, since some data is highly likely to be unaligned. @@ -206,10 +225,6 @@ inline int GetInt(const unsigned char *foo) { return *(const int *)foo; } -inline int GetBigInt(const unsigned char *foo) -{ - return BigLong(GetInt(foo)); -} #else inline int GetShort(const unsigned char *foo) { @@ -219,11 +234,12 @@ inline int GetInt(const unsigned char *foo) { return int(foo[0] | (foo[1] << 8) | (foo[2] << 16) | (foo[3] << 24)); } +#endif inline int GetBigInt(const unsigned char *foo) { return int((foo[0] << 24) | (foo[1] << 16) | (foo[2] << 8) | foo[3]); } -#endif + #ifdef __BIG_ENDIAN__ inline int GetNativeInt(const unsigned char *foo) { diff --git a/src/resourcefiles/file_zip.cpp b/src/resourcefiles/file_zip.cpp index 684a3424ff..9bce04a52c 100644 --- a/src/resourcefiles/file_zip.cpp +++ b/src/resourcefiles/file_zip.cpp @@ -507,17 +507,19 @@ FResourceFile *CheckZip(const char *filename, FileRdr &file, bool quiet) // //========================================================================== -static void time_to_dos(struct tm *time, unsigned short *dosdate, unsigned short *dostime) +static std::pair time_to_dos(struct tm *time) { + std::pair val; if (time == NULL || time->tm_year < 80) { - *dosdate = *dostime = 0; + val.first = val.second = 0; } else { - *dosdate = LittleShort((time->tm_year - 80) * 512 + (time->tm_mon + 1) * 32 + time->tm_mday); - *dostime = LittleShort(time->tm_hour * 2048 + time->tm_min * 32 + time->tm_sec / 2); + val.first = (time->tm_year - 80) * 512 + (time->tm_mon + 1) * 32 + time->tm_mday; + val.second= time->tm_hour * 2048 + time->tm_min * 32 + time->tm_sec / 2; } + return val; } //========================================================================== @@ -532,7 +534,7 @@ static void time_to_dos(struct tm *time, unsigned short *dosdate, unsigned short // //========================================================================== -int AppendToZip(FileWriter *zip_file, const char *filename, FCompressedBuffer &content, uint16_t date, uint16_t time) +int AppendToZip(FileWriter *zip_file, const char *filename, FCompressedBuffer &content, std::pair &dostime) { FZipLocalFileHeader local; int position; @@ -540,10 +542,10 @@ int AppendToZip(FileWriter *zip_file, const char *filename, FCompressedBuffer &c local.Magic = ZIP_LOCALFILE; local.VersionToExtract[0] = 20; local.VersionToExtract[1] = 0; - local.Flags = content.mMethod == METHOD_DEFLATE ? LittleShort(2) : LittleShort((uint16_t)content.mZipFlags); - local.Method = LittleShort(content.mMethod); - local.ModDate = date; - local.ModTime = time; + local.Flags = content.mMethod == METHOD_DEFLATE ? LittleShort((uint16_t)2) : LittleShort((uint16_t)content.mZipFlags); + local.Method = LittleShort((uint16_t)content.mMethod); + local.ModDate = LittleShort(dostime.first); + local.ModTime = LittleShort(dostime.second); local.CRC32 = content.mCRC32; local.UncompressedSize = LittleLong(content.mSize); local.CompressedSize = LittleLong(content.mCompressedSize); @@ -573,7 +575,7 @@ int AppendToZip(FileWriter *zip_file, const char *filename, FCompressedBuffer &c // //========================================================================== -int AppendCentralDirectory(FileWriter *zip_file, const char *filename, FCompressedBuffer &content, uint16_t date, uint16_t time, int position) +int AppendCentralDirectory(FileWriter *zip_file, const char *filename, FCompressedBuffer &content, std::pair &dostime, int position) { FZipCentralDirectoryInfo dir; @@ -582,10 +584,10 @@ int AppendCentralDirectory(FileWriter *zip_file, const char *filename, FCompress dir.VersionMadeBy[1] = 0; dir.VersionToExtract[0] = 20; dir.VersionToExtract[1] = 0; - dir.Flags = content.mMethod == METHOD_DEFLATE ? LittleShort(2) : LittleShort((uint16_t)content.mZipFlags); - dir.Method = LittleShort(content.mMethod); - dir.ModTime = time; - dir.ModDate = date; + dir.Flags = content.mMethod == METHOD_DEFLATE ? LittleShort((uint16_t)2) : LittleShort((uint16_t)content.mZipFlags); + dir.Method = LittleShort((uint16_t)content.mMethod); + dir.ModTime = LittleShort(dostime.first); + dir.ModDate = LittleShort(dostime.second); dir.CRC32 = content.mCRC32; dir.CompressedSize = LittleLong(content.mCompressedSize); dir.UncompressedSize = LittleLong(content.mSize); @@ -610,10 +612,9 @@ bool WriteZip(const char *filename, TArray &filenames, TArray positions; @@ -624,7 +625,7 @@ bool WriteZip(const char *filename, TArray &filenames, TArray &filenames, TArrayTell(); for (unsigned i = 0; i < filenames.Size(); i++) { - if (AppendCentralDirectory(f, filenames[i], content[i], mydate, mytime, positions[i]) < 0) + if (AppendCentralDirectory(f, filenames[i], content[i], dostime, positions[i]) < 0) { delete f; remove(filename); @@ -650,9 +651,9 @@ bool WriteZip(const char *filename, TArray &filenames, TArrayTell() - dirofs); + dirend.DirectorySize = LittleLong((uint32_t)(f->Tell() - dirofs)); dirend.ZipCommentLength = 0; if (f->Write(&dirend, sizeof(dirend)) != sizeof(dirend)) { diff --git a/src/sound/mididevices/music_wavewriter_mididevice.cpp b/src/sound/mididevices/music_wavewriter_mididevice.cpp index 99590ee883..6bf585636b 100644 --- a/src/sound/mididevices/music_wavewriter_mididevice.cpp +++ b/src/sound/mididevices/music_wavewriter_mididevice.cpp @@ -106,18 +106,18 @@ MIDIWaveWriter::MIDIWaveWriter(const char *filename, SoftSynthMIDIDevice *playde playDevice->CalcTickRate(); fmt.ChunkID = MAKE_ID('f','m','t',' '); fmt.ChunkLen = LittleLong(uint32_t(sizeof(fmt) - 8)); - fmt.FormatTag = LittleShort(0xFFFE); // WAVE_FORMAT_EXTENSIBLE - fmt.Channels = LittleShort(2); + fmt.FormatTag = LittleShort((uint16_t)0xFFFE); // WAVE_FORMAT_EXTENSIBLE + fmt.Channels = LittleShort((uint16_t)2); fmt.SamplesPerSec = LittleLong(SampleRate); fmt.AvgBytesPerSec = LittleLong(SampleRate * 8); - fmt.BlockAlign = LittleShort(8); - fmt.BitsPerSample = LittleShort(32); - fmt.ExtensionSize = LittleShort(2 + 4 + 16); - fmt.ValidBitsPerSample = LittleShort(32); + fmt.BlockAlign = LittleShort((uint16_t)8); + fmt.BitsPerSample = LittleShort((uint16_t)32); + fmt.ExtensionSize = LittleShort((uint16_t)(2 + 4 + 16)); + fmt.ValidBitsPerSample = LittleShort((uint16_t)32); fmt.ChannelMask = LittleLong(3); fmt.SubFormatA = LittleLong(0x00000003); // Set subformat to KSDATAFORMAT_SUBTYPE_IEEE_FLOAT - fmt.SubFormatB = LittleShort(0x0000); - fmt.SubFormatC = LittleShort(0x0010); + fmt.SubFormatB = 0x0000; + fmt.SubFormatC = LittleShort((uint16_t)0x0010); fmt.SubFormatD[0] = 0x80; fmt.SubFormatD[1] = 0x00; fmt.SubFormatD[2] = 0x00; diff --git a/src/win32/i_crash.cpp b/src/win32/i_crash.cpp index 2e904cc0f5..4caa954e1e 100644 --- a/src/win32/i_crash.cpp +++ b/src/win32/i_crash.cpp @@ -166,49 +166,49 @@ namespace zip #pragma pack(push,1) struct LocalFileHeader { - DWORD Magic; // 0 + uint32_t Magic; // 0 uint8_t VersionToExtract[2]; // 4 uint16_t Flags; // 6 uint16_t Method; // 8 uint16_t ModTime; // 10 uint16_t ModDate; // 12 - DWORD CRC32; // 14 - DWORD CompressedSize; // 18 - DWORD UncompressedSize; // 22 + uint32_t CRC32; // 14 + uint32_t CompressedSize; // 18 + uint32_t UncompressedSize; // 22 uint16_t NameLength; // 26 uint16_t ExtraLength; // 28 }; struct CentralDirectoryEntry { - DWORD Magic; - uint8_t VersionMadeBy[2]; - uint8_t VersionToExtract[2]; + uint32_t Magic; + uint8_t VersionMadeBy[2]; + uint8_t VersionToExtract[2]; uint16_t Flags; uint16_t Method; uint16_t ModTime; uint16_t ModDate; - DWORD CRC32; - DWORD CompressedSize; - DWORD UncompressedSize; + uint32_t CRC32; + uint32_t CompressedSize; + uint32_t UncompressedSize; uint16_t NameLength; uint16_t ExtraLength; uint16_t CommentLength; uint16_t StartingDiskNumber; uint16_t InternalAttributes; - DWORD ExternalAttributes; - DWORD LocalHeaderOffset; + uint32_t ExternalAttributes; + uint32_t LocalHeaderOffset; }; struct EndOfCentralDirectory { - DWORD Magic; + uint32_t Magic; uint16_t DiskNumber; uint16_t FirstDisk; uint16_t NumEntries; uint16_t NumEntriesOnAllDisks; - DWORD DirectorySize; - DWORD DirectoryOffset; + uint32_t DirectorySize; + uint32_t DirectoryOffset; uint16_t ZipCommentLength; }; #pragma pack(pop) @@ -219,9 +219,9 @@ struct TarFile HANDLE File; const char *Filename; int ZipOffset; - DWORD UncompressedSize; - DWORD CompressedSize; - DWORD CRC32; + uint32_t UncompressedSize; + uint32_t CompressedSize; + uint32_t CRC32; bool Deflated; }; @@ -1513,7 +1513,8 @@ static HANDLE MakeZip () struct tm *nowtm; int i, numfiles; HANDLE file; - DWORD len, dirsize; + DWORD len; + uint32_t dirsize; size_t namelen; if (NumFiles == 0) @@ -1553,7 +1554,7 @@ static HANDLE MakeZip () central.ModTime = dostime; central.ModDate = dosdate; - dirend.DirectoryOffset = LittleLong(SetFilePointer (file, 0, NULL, FILE_CURRENT)); + dirend.DirectoryOffset = LittleLong((uint32_t)SetFilePointer (file, 0, NULL, FILE_CURRENT)); for (i = 0, numfiles = 0, dirsize = 0; i < NumFiles; ++i) { @@ -1565,8 +1566,8 @@ static HANDLE MakeZip () numfiles++; if (TarFiles[i].Deflated) { - central.Flags = LittleShort(2); - central.Method = LittleShort(8); + central.Flags = LittleShort((uint16_t)2); + central.Method = LittleShort((uint16_t)8); } else { @@ -1577,7 +1578,7 @@ static HANDLE MakeZip () central.InternalAttributes = 0; if (namelen > 4 && stricmp(TarFiles[i].Filename - 4, ".txt") == 0) { // Bit 0 set indicates this is probably a text file. But do any tools use it? - central.InternalAttributes = LittleShort(1); + central.InternalAttributes = LittleShort((uint16_t)1); } central.CRC32 = LittleLong(TarFiles[i].CRC32); central.CompressedSize = LittleLong(TarFiles[i].CompressedSize); @@ -1590,7 +1591,7 @@ static HANDLE MakeZip () } // Write the directory terminator - dirend.NumEntriesOnAllDisks = dirend.NumEntries = LittleShort(numfiles); + dirend.NumEntriesOnAllDisks = dirend.NumEntries = LittleShort((uint16_t)numfiles); dirend.DirectorySize = LittleLong(dirsize); WriteFile (file, &dirend, sizeof(dirend), &len, NULL); @@ -1635,7 +1636,7 @@ static void AddZipFile (HANDLE ziphandle, TarFile *whichfile, short dosdate, sho if (gzip) { - local.Method = LittleShort(8); + local.Method = LittleShort((uint16_t)8); whichfile->Deflated = true; stream.next_out = outbuf; stream.avail_out = sizeof(outbuf); @@ -1643,7 +1644,7 @@ static void AddZipFile (HANDLE ziphandle, TarFile *whichfile, short dosdate, sho // Write out the header and filename. local.VersionToExtract[0] = 20; - local.Flags = gzip ? LittleShort(2) : 0; + local.Flags = gzip ? LittleShort((uint16_t)2) : 0; local.ModTime = dostime; local.ModDate = dosdate; local.UncompressedSize = LittleLong(whichfile->UncompressedSize); From 0be1ed252bde0554cd1b9c6d1b9b0f4ddc40fc45 Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Sun, 11 Mar 2018 18:20:49 +0100 Subject: [PATCH 26/89] - rewrote the operator>> methods of FileReader as normal functions for clarity. --- src/files.cpp | 13 +++-- src/files.h | 62 +++++++++++++++--------- src/p_setup.cpp | 77 +++++++++++++----------------- src/sound/timidity/instrum_sf2.cpp | 6 +-- src/textures/imgztexture.cpp | 5 +- src/textures/multipatchtexture.cpp | 5 +- src/textures/patchtexture.cpp | 5 +- src/textures/pcxtexture.cpp | 16 +++---- src/textures/pngtexture.cpp | 37 +++++++------- src/textures/texturemanager.cpp | 5 +- src/textures/tgatexture.cpp | 37 ++++++++------ src/v_font.cpp | 15 ++---- 12 files changed, 150 insertions(+), 133 deletions(-) diff --git a/src/files.cpp b/src/files.cpp index f0939c9236..f4196b1004 100644 --- a/src/files.cpp +++ b/src/files.cpp @@ -324,14 +324,17 @@ public: buf.Resize(length); memcpy(&buf[0], buffer, length); } - Length = length; - FilePos = 0; - bufptr = (const char *)&buf[0]; + UpdateBuffer(); } TArray &GetArray() { return buf; } - void UpdateLength() { Length = buf.Size(); } + void UpdateBuffer() + { + bufptr = (const char*)&buf[0]; + FilePos = 0; + Length = buf.Size(); + } }; @@ -381,7 +384,7 @@ bool FileRdr::OpenMemoryArray(std::function&)> getter) if (getter(reader->GetArray())) { Close(); - reader->UpdateLength(); + reader->UpdateBuffer(); mReader = reader; return true; } diff --git a/src/files.h b/src/files.h index f4cf5c10f1..cd4b4b9291 100644 --- a/src/files.h +++ b/src/files.h @@ -201,47 +201,63 @@ public: return mReader->GetLength(); } - // Note: These need to go because they are fundamentally unsafe to use on a binary stream. - FileRdr &operator>> (uint8_t &v) + uint8_t ReadUInt8() { - mReader->Read(&v, 1); - return *this; + uint8_t v; + Read(&v, 1); + return v; } - FileRdr &operator>> (int8_t &v) + int8_t ReadInt8() { - mReader->Read(&v, 1); - return *this; + int8_t v; + Read(&v, 1); + return v; } - FileRdr &operator>> (uint16_t &v) + uint16_t ReadUInt16() { - mReader->Read(&v, 2); - v = LittleShort(v); - return *this; + uint16_t v; + Read(&v, 2); + return LittleShort(v); } - FileRdr &operator>> (int16_t &v) + int16_t ReadInt16() { - mReader->Read(&v, 2); - v = LittleShort(v); - return *this; + uint16_t v; + Read(&v, 2); + return LittleShort(v); } - FileRdr &operator>> (uint32_t &v) + uint32_t ReadUInt32() { - mReader->Read(&v, 4); - v = LittleLong(v); - return *this; + uint32_t v; + Read(&v, 4); + return LittleLong(v); } - FileRdr &operator>> (int32_t &v) + int32_t ReadInt32() { - mReader->Read(&v, 4); - v = LittleLong(v); - return *this; + uint32_t v; + Read(&v, 4); + return LittleLong(v); } + uint32_t ReadUInt32BE() + { + uint32_t v; + Read(&v, 4); + return BigLong(v); + } + + int32_t ReadInt32BE() + { + uint32_t v; + Read(&v, 4); + return BigLong(v); + } + + friend class FWadCollection; }; diff --git a/src/p_setup.cpp b/src/p_setup.cpp index f02c8f121f..9f640c4b18 100644 --- a/src/p_setup.cpp +++ b/src/p_setup.cpp @@ -842,9 +842,9 @@ void P_LoadVertexes (MapData * map) // Copy and convert vertex coordinates, internal representation as fixed. for (auto &v : level.vertexes) { - int16_t x, y; + int16_t x = fr.ReadInt16(); + int16_t y = fr.ReadInt16(); - fr >> x >> y; v.set(double(x), double(y)); } } @@ -860,11 +860,10 @@ void P_LoadZSegs (FileRdr &data) for (auto &seg : level.segs) { line_t *ldef; - uint32_t v1, v2; - uint16_t line; - uint8_t side; - - data >> v1 >> v2 >> line >> side; + uint32_t v1 = data.ReadUInt32(); + uint32_t v2 = data.ReadUInt32(); + uint16_t line = data.ReadUInt16(); + uint8_t side = data.ReadUInt8(); seg.v1 = &level.vertexes[v1]; seg.v2 = &level.vertexes[v2]; @@ -899,22 +898,20 @@ void P_LoadGLZSegs (FileRdr &data, int type) for (size_t j = 0; j < level.subsectors[i].numlines; ++j) { seg_t *seg; - uint32_t v1, partner; + uint32_t v1 = data.ReadUInt32(); + uint32_t partner = data.ReadUInt32(); uint32_t line; - uint16_t lineword; - uint8_t side; - data >> v1 >> partner; if (type >= 2) { - data >> line; + line = data.ReadUInt32(); } else { - data >> lineword; - line = lineword == 0xFFFF ? 0xFFFFFFFF : lineword; + line = data.ReadUInt16(); + if (line == 0xffff) line = 0xffffffff; } - data >> side; + uint8_t side = data.ReadUInt8(); seg = level.subsectors[i].firstline + j; seg->v1 = &level.vertexes[v1]; @@ -964,10 +961,10 @@ void P_LoadGLZSegs (FileRdr &data, int type) void LoadZNodes(FileRdr &data, int glnodes) { // Read extra vertices added during node building - uint32_t orgVerts, newVerts; unsigned int i; - data >> orgVerts >> newVerts; + uint32_t orgVerts = data.ReadUInt32(); + uint32_t newVerts = data.ReadUInt32(); if (orgVerts > level.vertexes.Size()) { // These nodes are based on a map with more vertex data than we have. // We can't use them. @@ -980,8 +977,8 @@ void LoadZNodes(FileRdr &data, int glnodes) } for (i = 0; i < newVerts; ++i) { - int32_t x, y; - data >> x >> y; + fixed_t x = data.ReadInt32(); + fixed_t y = data.ReadInt32(); level.vertexes[i + orgVerts].set(x, y); } if (oldvertexes != &level.vertexes[0]) @@ -994,26 +991,21 @@ void LoadZNodes(FileRdr &data, int glnodes) } // Read the subsectors - uint32_t numSubs, currSeg; - - data >> numSubs; + uint32_t currSeg; + uint32_t numSubs = data.ReadUInt32(); level.subsectors.Alloc(numSubs); memset (&level.subsectors[0], 0, level.subsectors.Size()*sizeof(subsector_t)); for (i = currSeg = 0; i < numSubs; ++i) { - uint32_t numsegs; - - data >> numsegs; + uint32_t numsegs = data.ReadUInt32(); level.subsectors[i].firstline = (seg_t *)(size_t)currSeg; // Oh damn. I should have stored the seg count sooner. level.subsectors[i].numlines = numsegs; currSeg += numsegs; } // Read the segs - uint32_t numSegs; - - data >> numSegs; + uint32_t numSegs = data.ReadUInt32(); // The number of segs stored should match the number of // segs used by subsectors. @@ -1040,9 +1032,8 @@ void LoadZNodes(FileRdr &data, int glnodes) } // Read nodes - uint32_t numNodes; + uint32_t numNodes = data.ReadUInt32(); - data >> numNodes; auto &nodes = level.nodes; nodes.Alloc(numNodes); memset (&nodes[0], 0, sizeof(node_t)*numNodes); @@ -1051,31 +1042,28 @@ void LoadZNodes(FileRdr &data, int glnodes) { if (glnodes < 3) { - int16_t x, y, dx, dy; - - data >> x >> y >> dx >> dy; - nodes[i].x = x << FRACBITS; - nodes[i].y = y << FRACBITS; - nodes[i].dx = dx << FRACBITS; - nodes[i].dy = dy << FRACBITS; + nodes[i].x = data.ReadInt16() * FRACUNIT; + nodes[i].y = data.ReadInt16() * FRACUNIT; + nodes[i].dx = data.ReadInt16() * FRACUNIT; + nodes[i].dy = data.ReadInt16() * FRACUNIT; } else { - data >> nodes[i].x >> nodes[i].y >> nodes[i].dx >> nodes[i].dy; + nodes[i].x = data.ReadInt32(); + nodes[i].y = data.ReadInt32(); + nodes[i].dx = data.ReadInt32(); + nodes[i].dy = data.ReadInt32(); } for (int j = 0; j < 2; ++j) { for (int k = 0; k < 4; ++k) { - int16_t coord; - data >> coord; - nodes[i].bbox[j][k] = coord; + nodes[i].bbox[j][k] = data.ReadInt16(); } } for (int m = 0; m < 2; ++m) { - uint32_t child; - data >> child; + uint32_t child = data.ReadUInt32(); if (child & 0x80000000) { nodes[i].children[m] = (uint8_t *)&level.subsectors[child & 0x7FFFFFFF] + 1; @@ -1399,7 +1387,8 @@ void P_LoadSubsectors (MapData * map) { subsectortype subd; - fr >> subd.numsegs >> subd.firstseg; + subd.numsegs = sizeof(subd.numsegs) == 2 ? fr.ReadUInt16() : fr.ReadUInt32(); + subd.firstseg = sizeof(subd.firstseg) == 2 ? fr.ReadUInt16() : fr.ReadUInt32(); if (subd.numsegs == 0) { diff --git a/src/sound/timidity/instrum_sf2.cpp b/src/sound/timidity/instrum_sf2.cpp index 02696f63c7..69f6070326 100644 --- a/src/sound/timidity/instrum_sf2.cpp +++ b/src/sound/timidity/instrum_sf2.cpp @@ -1520,8 +1520,7 @@ void SFFile::LoadSample(SFSample *sample) // Load 16-bit sample data. for (i = 0; i < sample->End - sample->Start; ++i) { - int16_t samp; - fp >> samp; + int16_t samp = fp.ReadInt16(); sample->InMemoryData[i] = samp / 32768.f; } if (SampleDataLSBOffset != 0) @@ -1529,8 +1528,7 @@ void SFFile::LoadSample(SFSample *sample) fp.Seek(SampleDataLSBOffset + sample->Start, FileRdr::SeekSet); for (i = 0; i < sample->End - sample->Start; ++i) { - uint8_t samp; - fp >> samp; + uint8_t samp = fp.ReadUInt8(); sample->InMemoryData[i] = ((((int32_t(sample->InMemoryData[i] * 32768) << 8) | samp) << 8) >> 8) / 8388608.f; } } diff --git a/src/textures/imgztexture.cpp b/src/textures/imgztexture.cpp index edd15b15ac..91b7b74405 100644 --- a/src/textures/imgztexture.cpp +++ b/src/textures/imgztexture.cpp @@ -92,7 +92,10 @@ FTexture *IMGZTexture_TryCreate(FileRdr & file, int lumpnum) file.Seek(0, FileRdr::SeekSet); if (file.Read(&magic, 4) != 4) return NULL; if (magic != MAKE_ID('I','M','G','Z')) return NULL; - file >> w >> h >> l >> t; + w = file.ReadUInt16(); + h = file.ReadUInt16(); + l = file.ReadInt16(); + t = file.ReadInt16(); return new FIMGZTexture(lumpnum, w, h, l, t); } diff --git a/src/textures/multipatchtexture.cpp b/src/textures/multipatchtexture.cpp index b00bd16067..e5beb246ff 100644 --- a/src/textures/multipatchtexture.cpp +++ b/src/textures/multipatchtexture.cpp @@ -814,9 +814,8 @@ void FTextureManager::AddTexturesLump (const void *lumpdata, int lumpsize, int d } { - auto pnames = Wads.OpenLumpReader (patcheslump); - - pnames >> numpatches; + auto pnames = Wads.OpenLumpReader(patcheslump); + numpatches = pnames.ReadUInt32(); // Check whether the amount of names reported is correct. if ((signed)numpatches < 0) diff --git a/src/textures/patchtexture.cpp b/src/textures/patchtexture.cpp index 49769213fc..4e8268c094 100644 --- a/src/textures/patchtexture.cpp +++ b/src/textures/patchtexture.cpp @@ -135,7 +135,10 @@ FTexture *PatchTexture_TryCreate(FileRdr & file, int lumpnum) if (!CheckIfPatch(file)) return NULL; file.Seek(0, FileRdr::SeekSet); - file >> header.width >> header.height >> header.leftoffset >> header.topoffset; + header.width = file.ReadUInt16(); + header.height = file.ReadUInt16(); + header.leftoffset = file.ReadInt16(); + header.topoffset = file.ReadInt16(); return new FPatchTexture(lumpnum, &header); } diff --git a/src/textures/pcxtexture.cpp b/src/textures/pcxtexture.cpp index 609188b210..4d7dbdae70 100644 --- a/src/textures/pcxtexture.cpp +++ b/src/textures/pcxtexture.cpp @@ -493,15 +493,15 @@ void FPCXTexture::MakeTexture() } else if (bitcount == 8) { - uint8_t c; lump.Seek(-769, FileRdr::SeekEnd); - lump >> c; + uint8_t c = lump.ReadUInt8(); //if (c !=0x0c) memcpy(PaletteMap, GrayMap, 256); // Fallback for files without palette //else for(int i=0;i<256;i++) { - uint8_t r,g,b; - lump >> r >> g >> b; + uint8_t r = lump.ReadUInt8(); + uint8_t g = lump.ReadUInt8(); + uint8_t b = lump.ReadUInt8(); PaletteMap[i] = ColorMatcher.Pick(r,g,b); } lump.Seek(sizeof(header), FileRdr::SeekSet); @@ -582,9 +582,8 @@ int FPCXTexture::CopyTrueColorPixels(FBitmap *bmp, int x, int y, int rotate, FCo } else if (bitcount == 8) { - uint8_t c; lump.Seek(-769, FileRdr::SeekEnd); - lump >> c; + uint8_t c = lump.ReadUInt8(); c=0x0c; // Apparently there's many non-compliant PCXs out there... if (c !=0x0c) { @@ -592,8 +591,9 @@ int FPCXTexture::CopyTrueColorPixels(FBitmap *bmp, int x, int y, int rotate, FCo } else for(int i=0;i<256;i++) { - uint8_t r,g,b; - lump >> r >> g >> b; + uint8_t r = lump.ReadUInt8(); + uint8_t g = lump.ReadUInt8(); + uint8_t b = lump.ReadUInt8(); pe[i] = PalEntry(255, r,g,b); } lump.Seek(sizeof(header), FileRdr::SeekSet); diff --git a/src/textures/pngtexture.cpp b/src/textures/pngtexture.cpp index a7e2d05347..b187339be7 100644 --- a/src/textures/pngtexture.cpp +++ b/src/textures/pngtexture.cpp @@ -99,8 +99,6 @@ FTexture *PNGTexture_TryCreate(FileRdr & data, int lumpnum) uint8_t b[4]; } first4bytes; - uint32_t width, height; - uint8_t bitdepth, colortype, compression, filter, interlace; // This is most likely a PNG, but make sure. (Note that if the // first 4 bytes match, but later bytes don't, we assume it's @@ -118,9 +116,13 @@ FTexture *PNGTexture_TryCreate(FileRdr & data, int lumpnum) // The PNG looks valid so far. Check the IHDR to make sure it's a // type of PNG we support. - data.Read(&width, 4); - data.Read(&height, 4); - data >> bitdepth >> colortype >> compression >> filter >> interlace; + int width = data.ReadInt32BE(); + int height = data.ReadInt32BE(); + uint8_t bitdepth = data.ReadUInt8(); + uint8_t colortype = data.ReadUInt8(); + uint8_t compression = data.ReadUInt8(); + uint8_t filter = data.ReadUInt8(); + uint8_t interlace = data.ReadUInt8(); if (compression != 0 || filter != 0 || interlace > 1) { @@ -147,8 +149,7 @@ FTexture *PNGTexture_TryCreate(FileRdr & data, int lumpnum) } } - return new FPNGTexture (data, lumpnum, FString(), BigLong((int)width), BigLong((int)height), - bitdepth, colortype, interlace); + return new FPNGTexture (data, lumpnum, FString(), width, height, bitdepth, colortype, interlace); } //========================================================================== @@ -159,8 +160,6 @@ FTexture *PNGTexture_TryCreate(FileRdr & data, int lumpnum) FTexture *PNGTexture_CreateFromFile(PNGHandle *png, const FString &filename) { - uint32_t width, height; - uint8_t bitdepth, colortype, compression, filter, interlace; if (M_FindPNGChunk(png, MAKE_ID('I','H','D','R')) == 0) { @@ -168,9 +167,14 @@ FTexture *PNGTexture_CreateFromFile(PNGHandle *png, const FString &filename) } // Check the IHDR to make sure it's a type of PNG we support. - png->File.Read(&width, 4); - png->File.Read(&height, 4); - png->File >> bitdepth >> colortype >> compression >> filter >> interlace; + auto &data = png->File; + int width = data.ReadInt32BE(); + int height = data.ReadInt32BE(); + uint8_t bitdepth = data.ReadUInt8(); + uint8_t colortype = data.ReadUInt8(); + uint8_t compression = data.ReadUInt8(); + uint8_t filter = data.ReadUInt8(); + uint8_t interlace = data.ReadUInt8(); if (compression != 0 || filter != 0 || interlace > 1) { @@ -185,8 +189,7 @@ FTexture *PNGTexture_CreateFromFile(PNGHandle *png, const FString &filename) return NULL; } - return new FPNGTexture (png->File, -1, filename, BigLong((int)width), BigLong((int)height), - bitdepth, colortype, interlace); + return new FPNGTexture (png->File, -1, filename, width, height, bitdepth, colortype, interlace); } //========================================================================== @@ -651,7 +654,9 @@ int FPNGTexture::CopyTrueColorPixels(FBitmap *bmp, int x, int y, int rotate, FCo case MAKE_ID('P','L','T','E'): for(int i = 0; i < PaletteSize; i++) { - (*lump) >> pe[i].r >> pe[i].g >> pe[i].b; + pe[i].r = lump->ReadUInt8(); + pe[i].g = lump->ReadUInt8(); + pe[i].b = lump->ReadUInt8(); } break; @@ -660,7 +665,7 @@ int FPNGTexture::CopyTrueColorPixels(FBitmap *bmp, int x, int y, int rotate, FCo { for(uint32_t i = 0; i < len; i++) { - (*lump) >> pe[i].a; + pe[i].a = lump->ReadUInt8(); if (pe[i].a != 0 && pe[i].a != 255) transpal = true; } diff --git a/src/textures/texturemanager.cpp b/src/textures/texturemanager.cpp index ad3eb0b9a5..cdaf17a49f 100644 --- a/src/textures/texturemanager.cpp +++ b/src/textures/texturemanager.cpp @@ -768,7 +768,7 @@ void FTextureManager::AddPatches (int lumpnum) uint32_t numpatches, i; char name[9]; - file >> numpatches; + numpatches = file.ReadUInt32(); name[8] = '\0'; for (i = 0; i < numpatches; ++i) @@ -1186,9 +1186,8 @@ int FTextureManager::CountLumpTextures (int lumpnum) if (lumpnum >= 0) { auto file = Wads.OpenLumpReader (lumpnum); - uint32_t numtex; + uint32_t numtex = file.ReadUInt32();; - file >> numtex; return int(numtex) >= 0 ? numtex : 0; } return 0; diff --git a/src/textures/tgatexture.cpp b/src/textures/tgatexture.cpp index 23e9b4315f..1355397210 100644 --- a/src/textures/tgatexture.cpp +++ b/src/textures/tgatexture.cpp @@ -252,13 +252,12 @@ const uint8_t *FTGATexture::GetPixels () void FTGATexture::ReadCompressed(FileRdr &lump, uint8_t * buffer, int bytesperpixel) { - uint8_t b; uint8_t data[4]; int Size = Width * Height; while (Size > 0) { - lump >> b; + uint8_t b = lump.ReadUInt8(); if (b & 128) { b&=~128; @@ -314,7 +313,7 @@ void FTGATexture::MakeTexture () { case 15: case 16: - lump >> w; + w = lump.ReadUInt16(); r = (w & 0x001F) << 3; g = (w & 0x03E0) >> 2; b = (w & 0x7C00) >> 7; @@ -322,12 +321,17 @@ void FTGATexture::MakeTexture () break; case 24: - lump >> b >> g >> r; + b = lump.ReadUInt8(); + g = lump.ReadUInt8(); + r = lump.ReadUInt8(); a=255; break; case 32: - lump >> b >> g >> r >> a; + b = lump.ReadUInt8(); + g = lump.ReadUInt8(); + r = lump.ReadUInt8(); + a = lump.ReadUInt8(); if ((hdr.img_desc&15)!=8) a=255; break; @@ -515,24 +519,29 @@ int FTGATexture::CopyTrueColorPixels(FBitmap *bmp, int x, int y, int rotate, FCo { case 15: case 16: - lump >> w; + w = lump.ReadUInt16(); r = (w & 0x001F) << 3; g = (w & 0x03E0) >> 2; b = (w & 0x7C00) >> 7; a = 255; break; - + case 24: - lump >> b >> g >> r; - a=255; + b = lump.ReadUInt8(); + g = lump.ReadUInt8(); + r = lump.ReadUInt8(); + a = 255; break; - + case 32: - lump >> b >> g >> r >> a; - if ((hdr.img_desc&15)!=8) a=255; - else if (a!=0 && a!=255) transval = true; + b = lump.ReadUInt8(); + g = lump.ReadUInt8(); + r = lump.ReadUInt8(); + a = lump.ReadUInt8(); + if ((hdr.img_desc & 15) != 8) a = 255; + else if (a != 0 && a != 255) transval = true; break; - + default: // should never happen r=g=b=a=0; break; diff --git a/src/v_font.cpp b/src/v_font.cpp index 1d362f61b3..5fc5ba7e96 100644 --- a/src/v_font.cpp +++ b/src/v_font.cpp @@ -1899,9 +1899,7 @@ void FFontChar2::MakeTexture () { if (runlen != 0) { - uint8_t color; - - lump >> color; + uint8_t color = lump.ReadUInt8(); color = MIN (color, max); if (SourceRemap != NULL) { @@ -1921,18 +1919,14 @@ void FFontChar2::MakeTexture () } else { - int8_t code; - - lump >> code; + int8_t code = lump.ReadInt8(); if (code >= 0) { runlen = code + 1; } else if (code != -128) { - uint8_t color; - - lump >> color; + uint8_t color = lump.ReadUInt8(); setlen = (-code) + 1; setval = MIN (color, max); if (SourceRemap != NULL) @@ -1951,8 +1945,7 @@ void FFontChar2::MakeTexture () { for (int x = Width; x != 0; --x) { - uint8_t color; - lump >> color; + uint8_t color = lump.ReadUInt8(); if (color > max) { color = max; From b9398368469d439d79967ec492acd6dd4e36b08b Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Sun, 11 Mar 2018 18:32:00 +0100 Subject: [PATCH 27/89] - renamed FileRdr back to FileReader. --- src/CMakeLists.txt | 5 +- src/d_dehacked.cpp | 2 +- src/d_main.cpp | 2 +- src/files.cpp | 16 ++--- src/files.h | 20 +++--- src/files_decompress.cpp | 18 ++--- src/g_game.cpp | 2 +- src/m_misc.cpp | 2 +- src/m_png.cpp | 12 ++-- src/m_png.h | 8 +-- src/md5.cpp | 4 +- src/md5.h | 4 +- src/menu/loadsavemenu.cpp | 6 +- src/p_acs.cpp | 4 +- src/p_acs.h | 6 +- src/p_conversation.cpp | 16 ++--- src/p_conversation.h | 4 +- src/p_glnodes.cpp | 26 ++++---- src/p_setup.cpp | 21 +++--- src/p_setup.h | 12 ++-- src/p_usdf.cpp | 4 +- src/resourcefiles/ancientzip.cpp | 6 +- src/resourcefiles/ancientzip.h | 6 +- src/resourcefiles/file_7z.cpp | 26 ++++---- src/resourcefiles/file_directory.cpp | 10 +-- src/resourcefiles/file_grp.cpp | 10 +-- src/resourcefiles/file_lump.cpp | 6 +- src/resourcefiles/file_pak.cpp | 12 ++-- src/resourcefiles/file_rff.cpp | 16 ++--- src/resourcefiles/file_wad.cpp | 20 +++--- src/resourcefiles/file_zip.cpp | 32 ++++----- src/resourcefiles/file_zip.h | 4 +- src/resourcefiles/resourcefile.cpp | 44 ++++++------ src/resourcefiles/resourcefile.h | 20 +++--- src/s_playlist.cpp | 4 +- src/s_playlist.h | 4 +- src/s_sound.cpp | 2 +- src/sc_man.cpp | 2 +- src/sound/i_music.cpp | 14 ++-- src/sound/i_music.h | 4 +- src/sound/i_musicinterns.h | 12 ++-- src/sound/i_sound.cpp | 10 +-- src/sound/i_sound.h | 6 +- src/sound/i_soundfont.cpp | 40 +++++------ src/sound/i_soundfont.h | 22 +++--- src/sound/i_soundinternal.h | 6 +- src/sound/midisources/midisource.h | 8 +-- src/sound/midisources/midisource_hmi.cpp | 2 +- src/sound/midisources/midisource_mus.cpp | 2 +- src/sound/midisources/midisource_smf.cpp | 2 +- src/sound/midisources/midisource_xmi.cpp | 2 +- src/sound/mpg123_decoder.cpp | 6 +- src/sound/mpg123_decoder.h | 4 +- src/sound/musicformats/music_cd.cpp | 8 +-- src/sound/musicformats/music_dumb.cpp | 8 +-- src/sound/musicformats/music_gme.cpp | 6 +- src/sound/musicformats/music_libsndfile.cpp | 28 ++++---- src/sound/musicformats/music_opl.cpp | 2 +- src/sound/musicformats/music_stream.cpp | 2 +- src/sound/oalsound.cpp | 10 +-- src/sound/oalsound.h | 2 +- src/sound/oplsynth/opl_mus_player.cpp | 2 +- src/sound/oplsynth/opl_mus_player.h | 4 +- src/sound/sndfile_decoder.cpp | 4 +- src/sound/sndfile_decoder.h | 4 +- src/sound/timidity/instrum_font.cpp | 4 +- src/sound/timidity/instrum_sf2.cpp | 74 ++++++++++----------- src/sound/timidity/sf2.h | 2 +- src/sound/timidity/timidity.cpp | 4 +- src/sound/timidity/timidity.h | 2 +- src/sound/timiditypp/common.cpp | 6 +- src/sound/timiditypp/common.h | 2 +- src/sound/wildmidi/file_io.cpp | 2 +- src/sound/wildmidi/wildmidi_lib.cpp | 2 +- src/textures/automaptexture.cpp | 2 +- src/textures/buildtexture.cpp | 2 +- src/textures/ddstexture.cpp | 32 ++++----- src/textures/emptytexture.cpp | 4 +- src/textures/flattexture.cpp | 2 +- src/textures/imgztexture.cpp | 4 +- src/textures/jpegtexture.cpp | 14 ++-- src/textures/patchtexture.cpp | 8 +-- src/textures/pcxtexture.cpp | 30 ++++----- src/textures/pngtexture.cpp | 40 +++++------ src/textures/rawpagetexture.cpp | 6 +- src/textures/texture.cpp | 24 +++---- src/textures/tgatexture.cpp | 14 ++-- src/v_font.cpp | 6 +- src/w_wad.cpp | 22 +++--- src/w_wad.h | 8 +-- src/win32/st_start.cpp | 2 +- 91 files changed, 479 insertions(+), 477 deletions(-) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 7dfaa9e53f..9fb9936971 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -660,8 +660,6 @@ file( GLOB HEADER_FILES g_inventory/*.h intermission/*.h menu/*.h - sound/oplsynth/*.h - sound/oplsynth/dosbox/*.h posix/*.h posix/cocoa/*.h posix/sdl/*.h @@ -677,6 +675,9 @@ file( GLOB HEADER_FILES scripting/decorate/*.h scripting/zscript/*.h scripting/vm/*.h + sound/midisources/*.h + sound/oplsynth/*.h + sound/oplsynth/dosbox/*.h sound/timidity/*.h sound/timiditypp/*.h sound/wildmidi/*.h diff --git a/src/d_dehacked.cpp b/src/d_dehacked.cpp index d92aef424c..76bcc19313 100644 --- a/src/d_dehacked.cpp +++ b/src/d_dehacked.cpp @@ -2492,7 +2492,7 @@ bool D_LoadDehLump(int lumpnum) bool D_LoadDehFile(const char *patchfile) { - FileRdr fr; + FileReader fr; if (fr.OpenFile(patchfile)) { diff --git a/src/d_main.cpp b/src/d_main.cpp index 9ec546d565..73450cc0a5 100644 --- a/src/d_main.cpp +++ b/src/d_main.cpp @@ -1959,7 +1959,7 @@ static FString CheckGameInfo(TArray & pwads) if (!isdir) { - FileRdr fr; + FileReader fr; if (!fr.OpenFile(filename)) { // Didn't find file diff --git a/src/files.cpp b/src/files.cpp index f4196b1004..93a2f45870 100644 --- a/src/files.cpp +++ b/src/files.cpp @@ -159,12 +159,12 @@ private: class FileReaderRedirect : public FileReaderInterface { - FileRdr *mReader = nullptr; + FileReader *mReader = nullptr; long StartPos = 0; long FilePos = 0; public: - FileReaderRedirect(FileRdr &parent, long start, long length) + FileReaderRedirect(FileReader &parent, long start, long length) { mReader = &parent; FilePos = start; @@ -195,7 +195,7 @@ public: break; } if (offset < StartPos || offset > StartPos + Length) return -1; // out of scope - if (mReader->Seek(offset, FileRdr::SeekSet) == 0) + if (mReader->Seek(offset, FileReader::SeekSet) == 0) { FilePos = offset; return 0; @@ -347,7 +347,7 @@ public: // //========================================================================== -bool FileRdr::OpenFile(const char *filename, FileRdr::Size start, FileRdr::Size length) +bool FileReader::OpenFile(const char *filename, FileReader::Size start, FileReader::Size length) { auto reader = new StdFileReader; if (!reader->Open(filename, (long)start, (long)length)) return false; @@ -356,7 +356,7 @@ bool FileRdr::OpenFile(const char *filename, FileRdr::Size start, FileRdr::Size return true; } -bool FileRdr::OpenFilePart(FileRdr &parent, FileRdr::Size start, FileRdr::Size length) +bool FileReader::OpenFilePart(FileReader &parent, FileReader::Size start, FileReader::Size length) { auto reader = new FileReaderRedirect(parent, (long)start, (long)length); Close(); @@ -364,21 +364,21 @@ bool FileRdr::OpenFilePart(FileRdr &parent, FileRdr::Size start, FileRdr::Size l return true; } -bool FileRdr::OpenMemory(const void *mem, FileRdr::Size length) +bool FileReader::OpenMemory(const void *mem, FileReader::Size length) { Close(); mReader = new MemoryReader((const char *)mem, (long)length); return true; } -bool FileRdr::OpenMemoryArray(const void *mem, FileRdr::Size length) +bool FileReader::OpenMemoryArray(const void *mem, FileReader::Size length) { Close(); mReader = new MemoryArrayReader((const char *)mem, (long)length); return true; } -bool FileRdr::OpenMemoryArray(std::function&)> getter) +bool FileReader::OpenMemoryArray(std::function&)> getter) { auto reader = new MemoryArrayReader(nullptr, 0); if (getter(reader->GetArray())) diff --git a/src/files.h b/src/files.h index cd4b4b9291..9424fd0315 100644 --- a/src/files.h +++ b/src/files.h @@ -107,16 +107,16 @@ public: struct FResourceLump; -class FileRdr +class FileReader { friend struct FResourceLump; // needs access to the private constructor. FileReaderInterface *mReader = nullptr; - FileRdr(const FileRdr &r) = delete; - FileRdr &operator=(const FileRdr &r) = delete; + FileReader(const FileReader &r) = delete; + FileReader &operator=(const FileReader &r) = delete; - explicit FileRdr(FileReaderInterface *r) + explicit FileReader(FileReaderInterface *r) { mReader = r; } @@ -131,15 +131,15 @@ public: typedef ptrdiff_t Size; // let's not use 'long' here. - FileRdr() {} + FileReader() {} - FileRdr(FileRdr &&r) + FileReader(FileReader &&r) { mReader = r.mReader; r.mReader = nullptr; } - FileRdr& operator =(FileRdr &&r) + FileReader& operator =(FileReader &&r) { Close(); mReader = r.mReader; @@ -148,7 +148,7 @@ public: } - ~FileRdr() + ~FileReader() { Close(); } @@ -165,11 +165,11 @@ public: } bool OpenFile(const char *filename, Size start = 0, Size length = -1); - bool OpenFilePart(FileRdr &parent, Size start, Size length); + bool OpenFilePart(FileReader &parent, Size start, Size length); bool OpenMemory(const void *mem, Size length); // read directly from the buffer bool OpenMemoryArray(const void *mem, Size length); // read from a copy of the buffer. bool OpenMemoryArray(std::function&)> getter); // read contents to a buffer and return a reader to it - bool OpenDecompressor(FileRdr &parent, Size length, int method, bool seekable); // creates a decompressor stream. 'seekable' uses a buffered version so that the Seek and Tell methods can be used. + bool OpenDecompressor(FileReader &parent, Size length, int method, bool seekable); // creates a decompressor stream. 'seekable' uses a buffered version so that the Seek and Tell methods can be used. Size Tell() const { diff --git a/src/files_decompress.cpp b/src/files_decompress.cpp index 0e8c905ba2..56d11a99f2 100644 --- a/src/files_decompress.cpp +++ b/src/files_decompress.cpp @@ -71,13 +71,13 @@ class DecompressorZ : public DecompressorBase { enum { BUFF_SIZE = 4096 }; - FileRdr &File; + FileReader &File; bool SawEOF; z_stream Stream; uint8_t InBuff[BUFF_SIZE]; public: - DecompressorZ (FileRdr &file, bool zip) + DecompressorZ (FileReader &file, bool zip) : File(file), SawEOF(false) { int err; @@ -157,13 +157,13 @@ class DecompressorBZ2 : public DecompressorBase { enum { BUFF_SIZE = 4096 }; - FileRdr &File; + FileReader &File; bool SawEOF; bz_stream Stream; uint8_t InBuff[BUFF_SIZE]; public: - DecompressorBZ2 (FileRdr &file) + DecompressorBZ2 (FileReader &file) : File(file), SawEOF(false) { int err; @@ -261,7 +261,7 @@ class DecompressorLZMA : public DecompressorBase { enum { BUFF_SIZE = 4096 }; - FileRdr &File; + FileReader &File; bool SawEOF; CLzmaDec Stream; size_t Size; @@ -271,7 +271,7 @@ class DecompressorLZMA : public DecompressorBase public: - DecompressorLZMA (FileRdr &file, size_t uncompressed_size) + DecompressorLZMA (FileReader &file, size_t uncompressed_size) : File(file), SawEOF(false) { uint8_t header[4 + LZMA_PROPS_SIZE]; @@ -380,7 +380,7 @@ class DecompressorLZSS : public DecompressorBase { enum { BUFF_SIZE = 4096, WINDOW_SIZE = 4096, INTERNAL_BUFFER_SIZE = 128 }; - FileRdr &File; + FileReader &File; bool SawEOF; uint8_t InBuff[BUFF_SIZE]; @@ -498,7 +498,7 @@ class DecompressorLZSS : public DecompressorBase } public: - DecompressorLZSS(FileRdr &file) : File(file), SawEOF(false) + DecompressorLZSS(FileReader &file) : File(file), SawEOF(false) { Stream.State = STREAM_EMPTY; Stream.WindowData = Stream.InternalBuffer = Stream.Window+WINDOW_SIZE; @@ -560,7 +560,7 @@ public: }; -bool FileRdr::OpenDecompressor(FileRdr &parent, Size length, int method, bool seekable) +bool FileReader::OpenDecompressor(FileReader &parent, Size length, int method, bool seekable) { DecompressorBase *dec = nullptr; switch (method) diff --git a/src/g_game.cpp b/src/g_game.cpp index e61c440fde..b2f58990c4 100644 --- a/src/g_game.cpp +++ b/src/g_game.cpp @@ -2801,7 +2801,7 @@ void G_DoPlayDemo (void) { FixPathSeperator (defdemoname); DefaultExtension (defdemoname, ".lmp"); - FileRdr fr; + FileReader fr; if (!fr.OpenFile(defdemoname)) { I_Error("Unable to open demo '%s'", defdemoname.GetChars()); diff --git a/src/m_misc.cpp b/src/m_misc.cpp index 4f13802ce0..ea55a906c2 100644 --- a/src/m_misc.cpp +++ b/src/m_misc.cpp @@ -121,7 +121,7 @@ void M_FindResponseFile (void) if (added_stuff < limit) { // READ THE RESPONSE FILE INTO MEMORY - FileRdr fr; + FileReader fr; if (!fr.OpenFile(Args->GetArg(i) + 1)) { // [RH] Make this a warning, not an error. Printf ("No such response file (%s)!\n", Args->GetArg(i) + 1); diff --git a/src/m_png.cpp b/src/m_png.cpp index 23b7e57ce8..ac2035ee67 100644 --- a/src/m_png.cpp +++ b/src/m_png.cpp @@ -75,7 +75,7 @@ struct IHDR uint8_t Interlace; }; -PNGHandle::PNGHandle (FileRdr &file) : bDeleteFilePtr(true), ChunkPt(0) +PNGHandle::PNGHandle (FileReader &file) : bDeleteFilePtr(true), ChunkPt(0) { File = std::move(file); } @@ -304,7 +304,7 @@ unsigned int M_NextPNGChunk (PNGHandle *png, uint32_t id) { if (png->Chunks[png->ChunkPt].ID == id) { // Found the chunk - png->File.Seek (png->Chunks[png->ChunkPt++].Offset, FileRdr::SeekSet); + png->File.Seek (png->Chunks[png->ChunkPt++].Offset, FileReader::SeekSet); return png->Chunks[png->ChunkPt - 1].Size; } } @@ -369,7 +369,7 @@ bool M_GetPNGText (PNGHandle *png, const char *keyword, char *buffer, size_t buf // //========================================================================== -PNGHandle *M_VerifyPNG (FileRdr &filer) +PNGHandle *M_VerifyPNG (FileReader &filer) { PNGHandle::Chunk chunk; PNGHandle *png; @@ -400,9 +400,9 @@ PNGHandle *M_VerifyPNG (FileRdr &filer) chunk.Offset = 16; chunk.Size = BigLong((unsigned int)data[0]); png->Chunks.Push (chunk); - png->File.Seek (16, FileRdr::SeekSet); + png->File.Seek (16, FileReader::SeekSet); - while (png->File.Seek (chunk.Size + 4, FileRdr::SeekCur) == 0) + while (png->File.Seek (chunk.Size + 4, FileReader::SeekCur) == 0) { // If the file ended before an IEND was encountered, it's not a PNG. if (png->File.Read (&data, 8) != 8) @@ -470,7 +470,7 @@ void M_FreePNG (PNGHandle *png) // //========================================================================== -bool M_ReadIDAT (FileRdr &file, uint8_t *buffer, int width, int height, int pitch, +bool M_ReadIDAT (FileReader &file, uint8_t *buffer, int width, int height, int pitch, uint8_t bitdepth, uint8_t colortype, uint8_t interlace, unsigned int chunklen) { // Uninterlaced images are treated as a conceptual eighth pass by these tables. diff --git a/src/m_png.h b/src/m_png.h index 814e7b281f..10fd4c8e6b 100644 --- a/src/m_png.h +++ b/src/m_png.h @@ -73,13 +73,13 @@ struct PNGHandle uint32_t Size; }; - FileRdr File; + FileReader File; bool bDeleteFilePtr; TArray Chunks; TArray TextChunks; unsigned int ChunkPt; - PNGHandle(FileRdr &file); + PNGHandle(FileReader &file); ~PNGHandle(); }; @@ -87,7 +87,7 @@ struct PNGHandle // the signature, but also checking for the IEND chunk. CRC checking of // each chunk is not done. If it is valid, you get a PNGHandle to pass to // the following functions. -PNGHandle *M_VerifyPNG (FileRdr &file); +PNGHandle *M_VerifyPNG (FileReader &file); // Finds a chunk in a PNG file. The file pointer will be positioned at the // beginning of the chunk data, and its length will be returned. A return @@ -106,7 +106,7 @@ bool M_GetPNGText (PNGHandle *png, const char *keyword, char *buffer, size_t buf // The file must be positioned at the start of the first IDAT. It reads // image data into the provided buffer. Returns true on success. -bool M_ReadIDAT (FileRdr &file, uint8_t *buffer, int width, int height, int pitch, +bool M_ReadIDAT (FileReader &file, uint8_t *buffer, int width, int height, int pitch, uint8_t bitdepth, uint8_t colortype, uint8_t interlace, unsigned int idatlen); diff --git a/src/md5.cpp b/src/md5.cpp index f5d8ba6043..1e0f724404 100644 --- a/src/md5.cpp +++ b/src/md5.cpp @@ -95,7 +95,7 @@ void MD5Context::Update(const uint8_t *buf, unsigned len) memcpy(in, buf, len); } -void MD5Context::Update(FileRdr &file, unsigned len) +void MD5Context::Update(FileReader &file, unsigned len) { uint8_t readbuf[8192]; long t; @@ -269,7 +269,7 @@ CCMD (md5sum) } for (int i = 1; i < argv.argc(); ++i) { - FileRdr fr; + FileReader fr; if (!fr.OpenFile(argv[i])) { Printf("%s: %s\n", argv[i], strerror(errno)); diff --git a/src/md5.h b/src/md5.h index 61714cd34c..82d4f32dc1 100644 --- a/src/md5.h +++ b/src/md5.h @@ -18,7 +18,7 @@ #ifndef MD5_H #define MD5_H -class FileRdr; +class FileReader; struct MD5Context { @@ -26,7 +26,7 @@ struct MD5Context void Init(); void Update(const uint8_t *buf, unsigned len); - void Update(FileRdr &file, unsigned len); + void Update(FileReader &file, unsigned len); void Final(uint8_t digest[16]); private: diff --git a/src/menu/loadsavemenu.cpp b/src/menu/loadsavemenu.cpp index 424073ba57..7d4b1ebf49 100644 --- a/src/menu/loadsavemenu.cpp +++ b/src/menu/loadsavemenu.cpp @@ -236,7 +236,7 @@ void FSavegameManager::ReadSaveStrings() } else // check for old formats. { - FileRdr file; + FileReader file; if (file.OpenFile(filepath)) { PNGHandle *png; @@ -272,7 +272,7 @@ void FSavegameManager::ReadSaveStrings() } else { - file.Seek(0, FileRdr::SeekSet); + file.Seek(0, FileReader::SeekSet); if (file.Read(sig, 16) == 16) { @@ -496,7 +496,7 @@ unsigned FSavegameManager::ExtractSaveData(int index) FResourceLump *pic = resf->FindLump("savepic.png"); if (pic != nullptr) { - FileRdr picreader; + FileReader picreader; picreader.OpenMemoryArray([=](TArray &array) { diff --git a/src/p_acs.cpp b/src/p_acs.cpp index 8d1f039c35..1b6c472d80 100644 --- a/src/p_acs.cpp +++ b/src/p_acs.cpp @@ -2116,7 +2116,7 @@ void FBehavior::StaticLoadDefaultModules () } } -FBehavior *FBehavior::StaticLoadModule (int lumpnum, FileRdr *fr, int len) +FBehavior *FBehavior::StaticLoadModule (int lumpnum, FileReader *fr, int len) { if (lumpnum == -1 && fr == NULL) return NULL; @@ -2392,7 +2392,7 @@ FBehavior::FBehavior() } -bool FBehavior::Init(int lumpnum, FileRdr * fr, int len) +bool FBehavior::Init(int lumpnum, FileReader * fr, int len) { uint8_t *object; int i; diff --git a/src/p_acs.h b/src/p_acs.h index 80853a523d..8ccf629820 100644 --- a/src/p_acs.h +++ b/src/p_acs.h @@ -41,7 +41,7 @@ #define NUM_MAPVARS 128 class FFont; -class FileRdr; +class FileReader; struct line_t; @@ -348,7 +348,7 @@ class FBehavior public: FBehavior (); ~FBehavior (); - bool Init(int lumpnum, FileRdr * fr = NULL, int len = 0); + bool Init(int lumpnum, FileReader * fr = NULL, int len = 0); bool IsGood (); uint8_t *FindChunk (uint32_t id) const; @@ -380,7 +380,7 @@ public: BoundsCheckingArray MapVars; - static FBehavior *StaticLoadModule (int lumpnum, FileRdr *fr = nullptr, int len=0); + static FBehavior *StaticLoadModule (int lumpnum, FileReader *fr = nullptr, int len=0); static void StaticLoadDefaultModules (); static void StaticUnloadModules (); static bool StaticCheckAllGood (); diff --git a/src/p_conversation.cpp b/src/p_conversation.cpp index e177c600ba..37903021ea 100644 --- a/src/p_conversation.cpp +++ b/src/p_conversation.cpp @@ -116,9 +116,9 @@ static int ConversationMenuY; static int ConversationPauseTic; static int StaticLastReply; -static bool LoadScriptFile(int lumpnum, FileRdr &lump, int numnodes, bool include, int type); -static FStrifeDialogueNode *ReadRetailNode (FileRdr &lump, uint32_t &prevSpeakerType); -static FStrifeDialogueNode *ReadTeaserNode (FileRdr &lump, uint32_t &prevSpeakerType); +static bool LoadScriptFile(int lumpnum, FileReader &lump, int numnodes, bool include, int type); +static FStrifeDialogueNode *ReadRetailNode (FileReader &lump, uint32_t &prevSpeakerType); +static FStrifeDialogueNode *ReadTeaserNode (FileReader &lump, uint32_t &prevSpeakerType); static void ParseReplies (FStrifeDialogueReply **replyptr, Response *responses); static bool DrawConversationMenu (); static void PickConversationReply (int replyindex); @@ -232,13 +232,13 @@ bool LoadScriptFile (const char *name, bool include, int type) { return false; } - FileRdr lump = Wads.ReopenLumpReader (lumpnum); + FileReader lump = Wads.ReopenLumpReader (lumpnum); bool res = LoadScriptFile(lumpnum, lump, Wads.LumpLength(lumpnum), include, type); return res; } -static bool LoadScriptFile(int lumpnum, FileRdr &lump, int numnodes, bool include, int type) +static bool LoadScriptFile(int lumpnum, FileReader &lump, int numnodes, bool include, int type) { int i; uint32_t prevSpeakerType; @@ -246,7 +246,7 @@ static bool LoadScriptFile(int lumpnum, FileRdr &lump, int numnodes, bool includ char buffer[4]; lump.Read(buffer, 4); - lump.Seek(-4, FileRdr::SeekCur); + lump.Seek(-4, FileReader::SeekCur); // The binary format is so primitive that this check is enough to detect it. bool isbinary = (buffer[0] == 0 || buffer[1] == 0 || buffer[2] == 0 || buffer[3] == 0); @@ -315,7 +315,7 @@ static bool LoadScriptFile(int lumpnum, FileRdr &lump, int numnodes, bool includ // //============================================================================ -static FStrifeDialogueNode *ReadRetailNode (FileRdr &lump, uint32_t &prevSpeakerType) +static FStrifeDialogueNode *ReadRetailNode (FileReader &lump, uint32_t &prevSpeakerType) { FStrifeDialogueNode *node; Speech speech; @@ -391,7 +391,7 @@ static FStrifeDialogueNode *ReadRetailNode (FileRdr &lump, uint32_t &prevSpeaker // //============================================================================ -static FStrifeDialogueNode *ReadTeaserNode (FileRdr &lump, uint32_t &prevSpeakerType) +static FStrifeDialogueNode *ReadTeaserNode (FileReader &lump, uint32_t &prevSpeakerType) { FStrifeDialogueNode *node; TeaserSpeech speech; diff --git a/src/p_conversation.h b/src/p_conversation.h index 90423ffe30..bc2e56be15 100644 --- a/src/p_conversation.h +++ b/src/p_conversation.h @@ -77,8 +77,8 @@ void P_ResumeConversation (); void P_ConversationCommand (int netcode, int player, uint8_t **stream); -class FileRdr; -bool P_ParseUSDF(int lumpnum, FileRdr &lump, int lumplen); +class FileReader; +bool P_ParseUSDF(int lumpnum, FileReader &lump, int lumplen); #endif diff --git a/src/p_glnodes.cpp b/src/p_glnodes.cpp index 09e9ef28d8..540812a0ab 100644 --- a/src/p_glnodes.cpp +++ b/src/p_glnodes.cpp @@ -75,7 +75,7 @@ void P_GetPolySpots (MapData * lump, TArray &spots, TA CVAR(Bool, gl_cachenodes, true, CVAR_ARCHIVE|CVAR_GLOBALCONFIG) CVAR(Float, gl_cachetime, 0.6f, CVAR_ARCHIVE|CVAR_GLOBALCONFIG) -void P_LoadZNodes (FileRdr &dalump, uint32_t id); +void P_LoadZNodes (FileReader &dalump, uint32_t id); static bool CheckCachedNodes(MapData *map); static void CreateCachedNodes(MapData *map); @@ -215,7 +215,7 @@ bool P_CheckForGLNodes() static int firstglvertex; static bool format5; -static bool LoadGLVertexes(FileRdr &lump) +static bool LoadGLVertexes(FileReader &lump) { uint8_t *gldata; int i; @@ -225,7 +225,7 @@ static bool LoadGLVertexes(FileRdr &lump) auto gllen=lump.GetLength(); gldata = new uint8_t[gllen]; - lump.Seek(0, FileRdr::SeekSet); + lump.Seek(0, FileReader::SeekSet); lump.Read(gldata, gllen); if (*(int *)gldata == gNd5) @@ -293,7 +293,7 @@ static inline int checkGLVertex3(int num) // //========================================================================== -static bool LoadGLSegs(FileRdr &lump) +static bool LoadGLSegs(FileReader &lump) { char *data; int i; @@ -301,7 +301,7 @@ static bool LoadGLSegs(FileRdr &lump) int numsegs = (int)lump.GetLength(); data= new char[numsegs]; - lump.Seek(0, FileRdr::SeekSet); + lump.Seek(0, FileReader::SeekSet); lump.Read(data, numsegs); auto &segs = level.segs; @@ -437,14 +437,14 @@ static bool LoadGLSegs(FileRdr &lump) // //========================================================================== -static bool LoadGLSubsectors(FileRdr &lump) +static bool LoadGLSubsectors(FileReader &lump) { char * datab; int i; int numsubsectors = (int)lump.GetLength(); datab = new char[numsubsectors]; - lump.Seek(0, FileRdr::SeekSet); + lump.Seek(0, FileReader::SeekSet); lump.Read(datab, numsubsectors); if (numsubsectors == 0) @@ -521,7 +521,7 @@ static bool LoadGLSubsectors(FileRdr &lump) // //========================================================================== -static bool LoadNodes (FileRdr &lump) +static bool LoadNodes (FileReader &lump) { const int NF_SUBSECTOR = 0x8000; const int GL5_NF_SUBSECTOR = (1 << 31); @@ -539,7 +539,7 @@ static bool LoadNodes (FileRdr &lump) if (numnodes == 0) return false; level.nodes.Alloc(numnodes); - lump.Seek(0, FileRdr::SeekSet); + lump.Seek(0, FileReader::SeekSet); basemn = mn = new mapnode_t[numnodes]; lump.Read(mn, lump.GetLength()); @@ -599,7 +599,7 @@ static bool LoadNodes (FileRdr &lump) if (numnodes == 0) return false; level.nodes.Alloc(numnodes); - lump.Seek(0, FileRdr::SeekSet); + lump.Seek(0, FileReader::SeekSet); basemn = mn = new gl5_mapnode_t[numnodes]; lump.Read(mn, lump.GetLength()); @@ -660,7 +660,7 @@ static bool LoadNodes (FileRdr &lump) // //========================================================================== -static bool DoLoadGLNodes(FileRdr * lumps) +static bool DoLoadGLNodes(FileReader * lumps) { int missing = 0; @@ -857,7 +857,7 @@ bool P_LoadGLNodes(MapData * map) if (!CheckCachedNodes(map)) { - FileRdr gwalumps[4]; + FileReader gwalumps[4]; char path[256]; int li; int lumpfile = Wads.GetLumpFile(map->lumpnum); @@ -1160,7 +1160,7 @@ static bool CheckCachedNodes(MapData *map) uint32_t *verts = NULL; FString path = CreateCacheName(map, false); - FileRdr fr; + FileReader fr; if (!fr.OpenFile(path)) return false; diff --git a/src/p_setup.cpp b/src/p_setup.cpp index 9f640c4b18..2eae2b3f93 100644 --- a/src/p_setup.cpp +++ b/src/p_setup.cpp @@ -240,7 +240,7 @@ static int GetMapIndex(const char *mapname, int lastindex, const char *lumpname, MapData *P_OpenMapData(const char * mapname, bool justcheck) { MapData * map = new MapData; - FileRdr * wadReader = nullptr; + FileReader * wadReader = nullptr; bool externalfile = !strnicmp(mapname, "file:", 5); if (externalfile) @@ -404,7 +404,7 @@ MapData *P_OpenMapData(const char * mapname, bool justcheck) // Although we're using the resource system, we still want to be sure we're // reading from a wad file. - wadReader->Seek(0, FileRdr::SeekSet); + wadReader->Seek(0, FileReader::SeekSet); wadReader->Read(&id, sizeof(id)); if (id == IWAD_ID || id == PWAD_ID) @@ -855,7 +855,7 @@ void P_LoadVertexes (MapData * map) // //=========================================================================== -void P_LoadZSegs (FileRdr &data) +void P_LoadZSegs (FileReader &data) { for (auto &seg : level.segs) { @@ -890,7 +890,7 @@ void P_LoadZSegs (FileRdr &data) // //=========================================================================== -void P_LoadGLZSegs (FileRdr &data, int type) +void P_LoadGLZSegs (FileReader &data, int type) { for (unsigned i = 0; i < level.subsectors.Size(); ++i) { @@ -958,7 +958,7 @@ void P_LoadGLZSegs (FileRdr &data, int type) // //=========================================================================== -void LoadZNodes(FileRdr &data, int glnodes) +void LoadZNodes(FileReader &data, int glnodes) { // Read extra vertices added during node building unsigned int i; @@ -1082,7 +1082,7 @@ void LoadZNodes(FileRdr &data, int glnodes) // //=========================================================================== -void P_LoadZNodes (FileRdr &dalump, uint32_t id) +void P_LoadZNodes (FileReader &dalump, uint32_t id) { int type; bool compressed; @@ -1135,7 +1135,7 @@ void P_LoadZNodes (FileRdr &dalump, uint32_t id) if (compressed) { - FileRdr zip; + FileReader zip; if (zip.OpenDecompressor(dalump, -1, METHOD_ZLIB, false)) { LoadZNodes(zip, type); @@ -2487,12 +2487,12 @@ int P_DetermineTranslucency (int lumpnum) PalEntry newcolor; PalEntry newcolor2; - tranmap.Seek (GPalette.BlackIndex * 256 + GPalette.WhiteIndex, FileRdr::SeekSet); + tranmap.Seek (GPalette.BlackIndex * 256 + GPalette.WhiteIndex, FileReader::SeekSet); tranmap.Read (&index, 1); newcolor = GPalette.BaseColors[GPalette.Remap[index]]; - tranmap.Seek (GPalette.WhiteIndex * 256 + GPalette.BlackIndex, FileRdr::SeekSet); + tranmap.Seek (GPalette.WhiteIndex * 256 + GPalette.BlackIndex, FileReader::SeekSet); tranmap.Read (&index, 1); newcolor2 = GPalette.BaseColors[GPalette.Remap[index]]; if (newcolor2.r == 255) // if black on white results in white it's either @@ -3842,7 +3842,7 @@ void P_SetupLevel (const char *lumpname, int position) if (!ForceNodeBuild) { // Check for compressed nodes first, then uncompressed nodes - FileRdr *fr = nullptr; + FileReader *fr = nullptr; uint32_t id = MAKE_ID('X','x','X','x'), idcheck = 0, idcheck2 = 0, idcheck3 = 0, idcheck4 = 0, idcheck5 = 0, idcheck6 = 0; if (map->Size(ML_ZNODES) != 0) @@ -4280,3 +4280,4 @@ CCMD (lineloc) lines[linenum].v2->fY()); } #endif + diff --git a/src/p_setup.h b/src/p_setup.h index 0607442e4c..cd14f17a22 100644 --- a/src/p_setup.h +++ b/src/p_setup.h @@ -38,9 +38,9 @@ private: struct MapLump { char Name[8] = { 0 }; - FileRdr Reader; + FileReader Reader; } MapLumps[ML_MAX]; - FileRdr nofile; + FileReader nofile; public: bool HasBehavior = false; bool Encrypted = false; @@ -61,17 +61,17 @@ public: if (lumpindexSeek(0, FileRdr::SeekSet); + file->Seek(0, FileReader::SeekSet); } } */ - FileRdr &Reader(unsigned int lumpindex) + FileReader &Reader(unsigned int lumpindex) { if (lumpindex < countof(MapLumps)) { auto &file = MapLumps[lumpindex].Reader; - file.Seek(0, FileRdr::SeekSet); + file.Seek(0, FileReader::SeekSet); return file; } return nofile; @@ -85,7 +85,7 @@ public: if (size > 0) { auto &file = MapLumps[lumpindex].Reader; - file.Seek(0, FileRdr::SeekSet); + file.Seek(0, FileReader::SeekSet); file.Read(buffer, size); } } diff --git a/src/p_usdf.cpp b/src/p_usdf.cpp index fe0143e94d..8161866224 100644 --- a/src/p_usdf.cpp +++ b/src/p_usdf.cpp @@ -474,7 +474,7 @@ class USDFParser : public UDMFParserBase //=========================================================================== public: - bool Parse(int lumpnum, FileRdr &lump, int lumplen) + bool Parse(int lumpnum, FileReader &lump, int lumplen) { char *buffer = new char[lumplen]; lump.Read(buffer, lumplen); @@ -532,7 +532,7 @@ public: -bool P_ParseUSDF(int lumpnum, FileRdr &lump, int lumplen) +bool P_ParseUSDF(int lumpnum, FileReader &lump, int lumplen) { USDFParser parse; diff --git a/src/resourcefiles/ancientzip.cpp b/src/resourcefiles/ancientzip.cpp index 8439cc5fbd..0088d1f008 100644 --- a/src/resourcefiles/ancientzip.cpp +++ b/src/resourcefiles/ancientzip.cpp @@ -259,7 +259,7 @@ int FZipExploder::DecodeSF(TArray &decoder, int numvals) } int FZipExploder::Explode(unsigned char *out, unsigned int outsize, - FileRdr &in, unsigned int insize, + FileReader &in, unsigned int insize, int flags) { int c, i, minMatchLen = 3, len, dist; @@ -337,9 +337,9 @@ int FZipExploder::Explode(unsigned char *out, unsigned int outsize, #define FREE_CODE HSIZE /* 0x2000 (code is unused or was cleared) */ #define HAS_CHILD (HSIZE << 1) /* 0x4000 (code has a child--do not clear) */ -int ShrinkLoop(unsigned char *out, unsigned int outsize, FileRdr &_In, unsigned int InLeft) +int ShrinkLoop(unsigned char *out, unsigned int outsize, FileReader &_In, unsigned int InLeft) { - FileRdr *In = &_In; + FileReader *In = &_In; unsigned char ReadBuf[256]; unsigned short Parent[HSIZE]; unsigned char Value[HSIZE], Stack[HSIZE]; diff --git a/src/resourcefiles/ancientzip.h b/src/resourcefiles/ancientzip.h index 53725b27c7..cffd239ad3 100644 --- a/src/resourcefiles/ancientzip.h +++ b/src/resourcefiles/ancientzip.h @@ -4,7 +4,7 @@ class FZipExploder { unsigned int Hold, Bits; - FileRdr *In; + FileReader *In; unsigned int InLeft; /**************************************************************** @@ -38,7 +38,7 @@ class FZipExploder int DecodeSFValue(const TArray ¤tTree); int DecodeSF(TArray &decoder, int numvals); public: - int Explode(unsigned char *out, unsigned int outsize, FileRdr &in, unsigned int insize, int flags); + int Explode(unsigned char *out, unsigned int outsize, FileReader &in, unsigned int insize, int flags); }; class CExplosionError : CRecoverableError @@ -47,4 +47,4 @@ public: CExplosionError(const char *message) : CRecoverableError(message) {} }; -int ShrinkLoop(unsigned char *out, unsigned int outsize, FileRdr &in, unsigned int insize); \ No newline at end of file +int ShrinkLoop(unsigned char *out, unsigned int outsize, FileReader &in, unsigned int insize); \ No newline at end of file diff --git a/src/resourcefiles/file_7z.cpp b/src/resourcefiles/file_7z.cpp index cb2f310a84..9e675682c8 100644 --- a/src/resourcefiles/file_7z.cpp +++ b/src/resourcefiles/file_7z.cpp @@ -58,9 +58,9 @@ extern ISzAlloc g_Alloc; struct CZDFileInStream { ISeekInStream s; - FileRdr &File; + FileReader &File; - CZDFileInStream(FileRdr &_file) + CZDFileInStream(FileReader &_file) : File(_file) { s.Read = Read; @@ -83,19 +83,19 @@ struct CZDFileInStream static SRes Seek(const ISeekInStream *pp, Int64 *pos, ESzSeek origin) { CZDFileInStream *p = (CZDFileInStream *)pp; - FileRdr::ESeek move_method; + FileReader::ESeek move_method; int res; if (origin == SZ_SEEK_SET) { - move_method = FileRdr::SeekSet; + move_method = FileReader::SeekSet; } else if (origin == SZ_SEEK_CUR) { - move_method = FileRdr::SeekCur; + move_method = FileReader::SeekCur; } else if (origin == SZ_SEEK_END) { - move_method = FileRdr::SeekEnd; + move_method = FileReader::SeekEnd; } else { @@ -117,13 +117,13 @@ struct C7zArchive Byte *OutBuffer; size_t OutBufferSize; - C7zArchive(FileRdr &file) : ArchiveStream(file) + C7zArchive(FileReader &file) : ArchiveStream(file) { if (g_CrcTable[1] == 0) { CrcGenerateTable(); } - file.Seek(0, FileRdr::SeekSet); + file.Seek(0, FileReader::SeekSet); LookToRead2_CreateVTable(&LookStream, false); LookStream.realStream = &ArchiveStream.s; LookToRead2_Init(&LookStream); @@ -192,7 +192,7 @@ class F7ZFile : public FResourceFile C7zArchive *Archive; public: - F7ZFile(const char * filename, FileRdr &filer); + F7ZFile(const char * filename, FileReader &filer); bool Open(bool quiet); virtual ~F7ZFile(); virtual FResourceLump *GetLump(int no) { return ((unsigned)no < NumLumps)? &Lumps[no] : NULL; } @@ -206,7 +206,7 @@ public: // //========================================================================== -F7ZFile::F7ZFile(const char * filename, FileRdr &filer) +F7ZFile::F7ZFile(const char * filename, FileReader &filer) : FResourceFile(filename, filer) { Lumps = NULL; @@ -361,15 +361,15 @@ int F7ZLump::FillCache() // //========================================================================== -FResourceFile *Check7Z(const char *filename, FileRdr &file, bool quiet) +FResourceFile *Check7Z(const char *filename, FileReader &file, bool quiet) { char head[k7zSignatureSize]; if (file.GetLength() >= k7zSignatureSize) { - file.Seek(0, FileRdr::SeekSet); + file.Seek(0, FileReader::SeekSet); file.Read(&head, k7zSignatureSize); - file.Seek(0, FileRdr::SeekSet); + file.Seek(0, FileReader::SeekSet); if (!memcmp(head, k7zSignature, k7zSignatureSize)) { FResourceFile *rf = new F7ZFile(filename, file); diff --git a/src/resourcefiles/file_directory.cpp b/src/resourcefiles/file_directory.cpp index 534a6fe382..38aa44986c 100644 --- a/src/resourcefiles/file_directory.cpp +++ b/src/resourcefiles/file_directory.cpp @@ -55,7 +55,7 @@ struct FDirectoryLump : public FResourceLump { - virtual FileRdr NewReader(); + virtual FileReader NewReader(); virtual int FillCache(); FString mFullPath; @@ -90,7 +90,7 @@ public: //========================================================================== FDirectory::FDirectory(const char * directory) -: FResourceFile(NULL, FileRdr()) +: FResourceFile(NULL, FileReader()) { FString dirname; @@ -287,9 +287,9 @@ void FDirectory::AddEntry(const char *fullpath, int size) // //========================================================================== -FileRdr FDirectoryLump::NewReader() +FileReader FDirectoryLump::NewReader() { - FileRdr fr; + FileReader fr; fr.OpenFile(mFullPath); return fr; } @@ -302,7 +302,7 @@ FileRdr FDirectoryLump::NewReader() int FDirectoryLump::FillCache() { - FileRdr fr; + FileReader fr; Cache = new char[LumpSize]; if (!fr.OpenFile(mFullPath)) { diff --git a/src/resourcefiles/file_grp.cpp b/src/resourcefiles/file_grp.cpp index 72543d356a..4155e3485b 100644 --- a/src/resourcefiles/file_grp.cpp +++ b/src/resourcefiles/file_grp.cpp @@ -73,7 +73,7 @@ struct GrpLump class FGrpFile : public FUncompressedFile { public: - FGrpFile(const char * filename, FileRdr &file); + FGrpFile(const char * filename, FileReader &file); bool Open(bool quiet); }; @@ -84,7 +84,7 @@ public: // //========================================================================== -FGrpFile::FGrpFile(const char *filename, FileRdr &file) +FGrpFile::FGrpFile(const char *filename, FileReader &file) : FUncompressedFile(filename, file) { Lumps = NULL; @@ -134,15 +134,15 @@ bool FGrpFile::Open(bool quiet) // //========================================================================== -FResourceFile *CheckGRP(const char *filename, FileRdr &file, bool quiet) +FResourceFile *CheckGRP(const char *filename, FileReader &file, bool quiet) { char head[12]; if (file.GetLength() >= 12) { - file.Seek(0, FileRdr::SeekSet); + file.Seek(0, FileReader::SeekSet); file.Read(&head, 12); - file.Seek(0, FileRdr::SeekSet); + file.Seek(0, FileReader::SeekSet); if (!memcmp(head, "KenSilverman", 12)) { FResourceFile *rf = new FGrpFile(filename, file); diff --git a/src/resourcefiles/file_lump.cpp b/src/resourcefiles/file_lump.cpp index feb8e56d90..244ff5c6a5 100644 --- a/src/resourcefiles/file_lump.cpp +++ b/src/resourcefiles/file_lump.cpp @@ -46,7 +46,7 @@ class FLumpFile : public FUncompressedFile { public: - FLumpFile(const char * filename, FileRdr &file); + FLumpFile(const char * filename, FileReader &file); bool Open(bool quiet); }; @@ -57,7 +57,7 @@ public: // //========================================================================== -FLumpFile::FLumpFile(const char *filename, FileRdr &file) +FLumpFile::FLumpFile(const char *filename, FileReader &file) : FUncompressedFile(filename, file) { } @@ -95,7 +95,7 @@ bool FLumpFile::Open(bool quiet) // //========================================================================== -FResourceFile *CheckLump(const char *filename, FileRdr &file, bool quiet) +FResourceFile *CheckLump(const char *filename, FileReader &file, bool quiet) { // always succeeds FResourceFile *rf = new FLumpFile(filename, file); diff --git a/src/resourcefiles/file_pak.cpp b/src/resourcefiles/file_pak.cpp index 42923092bf..776138d704 100644 --- a/src/resourcefiles/file_pak.cpp +++ b/src/resourcefiles/file_pak.cpp @@ -66,7 +66,7 @@ struct dpackheader_t class FPakFile : public FUncompressedFile { public: - FPakFile(const char * filename, FileRdr &file); + FPakFile(const char * filename, FileReader &file); bool Open(bool quiet); }; @@ -79,7 +79,7 @@ public: // //========================================================================== -FPakFile::FPakFile(const char *filename, FileRdr &file) +FPakFile::FPakFile(const char *filename, FileReader &file) : FUncompressedFile(filename, file) { Lumps = NULL; @@ -100,7 +100,7 @@ bool FPakFile::Open(bool quiet) header.dirofs = LittleLong(header.dirofs); dpackfile_t *fileinfo = new dpackfile_t[NumLumps]; - Reader.Seek (header.dirofs, FileRdr::SeekSet); + Reader.Seek (header.dirofs, FileReader::SeekSet); Reader.Read (fileinfo, NumLumps * sizeof(dpackfile_t)); Lumps = new FUncompressedLump[NumLumps]; @@ -127,15 +127,15 @@ bool FPakFile::Open(bool quiet) // //========================================================================== -FResourceFile *CheckPak(const char *filename, FileRdr &file, bool quiet) +FResourceFile *CheckPak(const char *filename, FileReader &file, bool quiet) { char head[4]; if (file.GetLength() >= 12) { - file.Seek(0, FileRdr::SeekSet); + file.Seek(0, FileReader::SeekSet); file.Read(&head, 4); - file.Seek(0, FileRdr::SeekSet); + file.Seek(0, FileReader::SeekSet); if (!memcmp(head, "PACK", 4)) { FResourceFile *rf = new FPakFile(filename, file); diff --git a/src/resourcefiles/file_rff.cpp b/src/resourcefiles/file_rff.cpp index 43a4a454fe..6843904c07 100644 --- a/src/resourcefiles/file_rff.cpp +++ b/src/resourcefiles/file_rff.cpp @@ -75,7 +75,7 @@ struct RFFLump struct FRFFLump : public FUncompressedLump { - virtual FileRdr *GetReader(); + virtual FileReader *GetReader(); virtual int FillCache(); uint32_t IndexNum; @@ -111,7 +111,7 @@ class FRFFFile : public FResourceFile FRFFLump *Lumps; public: - FRFFFile(const char * filename, FileRdr &file); + FRFFFile(const char * filename, FileReader &file); virtual ~FRFFFile(); virtual bool Open(bool quiet); virtual FResourceLump *GetLump(int no) { return ((unsigned)no < NumLumps)? &Lumps[no] : NULL; } @@ -124,7 +124,7 @@ public: // //========================================================================== -FRFFFile::FRFFFile(const char *filename, FileRdr &file) +FRFFFile::FRFFFile(const char *filename, FileReader &file) : FResourceFile(filename, file) { Lumps = NULL; @@ -146,7 +146,7 @@ bool FRFFFile::Open(bool quiet) NumLumps = LittleLong(header.NumLumps); header.DirOfs = LittleLong(header.DirOfs); lumps = new RFFLump[header.NumLumps]; - Reader.Seek (header.DirOfs, FileRdr::SeekSet); + Reader.Seek (header.DirOfs, FileReader::SeekSet); Reader.Read (lumps, header.NumLumps * sizeof(RFFLump)); BloodCrypt (lumps, header.DirOfs, header.NumLumps * sizeof(RFFLump)); @@ -203,7 +203,7 @@ FRFFFile::~FRFFFile() // //========================================================================== -FileRdr *FRFFLump::GetReader() +FileReader *FRFFLump::GetReader() { // Don't return the reader if this lump is encrypted // In that case always force caching of the lump @@ -247,15 +247,15 @@ int FRFFLump::FillCache() // //========================================================================== -FResourceFile *CheckRFF(const char *filename, FileRdr &file, bool quiet) +FResourceFile *CheckRFF(const char *filename, FileReader &file, bool quiet) { char head[4]; if (file.GetLength() >= 16) { - file.Seek(0, FileRdr::SeekSet); + file.Seek(0, FileReader::SeekSet); file.Read(&head, 4); - file.Seek(0, FileRdr::SeekSet); + file.Seek(0, FileReader::SeekSet); if (!memcmp(head, "RFF\x1a", 4)) { FResourceFile *rf = new FRFFFile(filename, file); diff --git a/src/resourcefiles/file_wad.cpp b/src/resourcefiles/file_wad.cpp index fce8ee1fdb..2e0ebb1dc3 100644 --- a/src/resourcefiles/file_wad.cpp +++ b/src/resourcefiles/file_wad.cpp @@ -55,11 +55,11 @@ public: int Position; int GetFileOffset() { return Position; } - FileRdr *GetReader() + FileReader *GetReader() { if(!Compressed) { - Owner->Reader.Seek(Position, FileRdr::SeekSet); + Owner->Reader.Seek(Position, FileReader::SeekSet); return &Owner->Reader; } return NULL; @@ -79,12 +79,12 @@ public: } } - Owner->Reader.Seek(Position, FileRdr::SeekSet); + Owner->Reader.Seek(Position, FileReader::SeekSet); Cache = new char[LumpSize]; if(Compressed) { - FileRdr lzss; + FileReader lzss; if (lzss.OpenDecompressor(Owner->Reader, LumpSize, METHOD_LZSS, false)) { lzss.Read(Cache, LumpSize); @@ -113,7 +113,7 @@ class FWadFile : public FResourceFile void SkinHack (); public: - FWadFile(const char * filename, FileRdr &file); + FWadFile(const char * filename, FileReader &file); ~FWadFile(); void FindStrifeTeaserVoices (); FResourceLump *GetLump(int lump) { return &Lumps[lump]; } @@ -129,7 +129,7 @@ public: // //========================================================================== -FWadFile::FWadFile(const char *filename, FileRdr &file) +FWadFile::FWadFile(const char *filename, FileReader &file) : FResourceFile(filename, file) { Lumps = NULL; @@ -173,7 +173,7 @@ bool FWadFile::Open(bool quiet) } wadlump_t *fileinfo = new wadlump_t[NumLumps]; - Reader.Seek (InfoTableOfs, FileRdr::SeekSet); + Reader.Seek (InfoTableOfs, FileReader::SeekSet); Reader.Read (fileinfo, NumLumps * sizeof(wadlump_t)); Lumps = new FWadFileLump[NumLumps]; @@ -475,15 +475,15 @@ void FWadFile::FindStrifeTeaserVoices () // //========================================================================== -FResourceFile *CheckWad(const char *filename, FileRdr &file, bool quiet) +FResourceFile *CheckWad(const char *filename, FileReader &file, bool quiet) { char head[4]; if (file.GetLength() >= 12) { - file.Seek(0, FileRdr::SeekSet); + file.Seek(0, FileReader::SeekSet); file.Read(&head, 4); - file.Seek(0, FileRdr::SeekSet); + file.Seek(0, FileReader::SeekSet); if (!memcmp(head, "IWAD", 4) || !memcmp(head, "PWAD", 4)) { FResourceFile *rf = new FWadFile(filename, file); diff --git a/src/resourcefiles/file_zip.cpp b/src/resourcefiles/file_zip.cpp index 9bce04a52c..bf51cd2a40 100644 --- a/src/resourcefiles/file_zip.cpp +++ b/src/resourcefiles/file_zip.cpp @@ -51,7 +51,7 @@ // //========================================================================== -static bool UncompressZipLump(char *Cache, FileRdr &Reader, int Method, int LumpSize, int CompressedSize, int GPFlags) +static bool UncompressZipLump(char *Cache, FileReader &Reader, int Method, int LumpSize, int CompressedSize, int GPFlags) { try { @@ -67,7 +67,7 @@ static bool UncompressZipLump(char *Cache, FileRdr &Reader, int Method, int Lump case METHOD_BZIP2: case METHOD_LZMA: { - FileRdr frz; + FileReader frz; if (frz.OpenDecompressor(Reader, LumpSize, Method, false)) { frz.Read(Cache, LumpSize); @@ -104,7 +104,7 @@ static bool UncompressZipLump(char *Cache, FileRdr &Reader, int Method, int Lump bool FCompressedBuffer::Decompress(char *destbuffer) { - FileRdr mr; + FileReader mr; mr.OpenMemory(mBuffer, mCompressedSize); return UncompressZipLump(destbuffer, mr, mMethod, mSize, mCompressedSize, mZipFlags); } @@ -116,7 +116,7 @@ bool FCompressedBuffer::Decompress(char *destbuffer) // //----------------------------------------------------------------------- -static uint32_t Zip_FindCentralDir(FileRdr &fin) +static uint32_t Zip_FindCentralDir(FileReader &fin) { unsigned char buf[BUFREADCOMMENT + 4]; uint32_t FileSize; @@ -140,7 +140,7 @@ static uint32_t Zip_FindCentralDir(FileRdr &fin) uReadSize = MIN((BUFREADCOMMENT + 4), (FileSize - uReadPos)); - if (fin.Seek(uReadPos, FileRdr::SeekSet) != 0) break; + if (fin.Seek(uReadPos, FileReader::SeekSet) != 0) break; if (fin.Read(buf, (int32_t)uReadSize) != (int32_t)uReadSize) break; @@ -165,7 +165,7 @@ static uint32_t Zip_FindCentralDir(FileRdr &fin) // //========================================================================== -FZipFile::FZipFile(const char * filename, FileRdr &file) +FZipFile::FZipFile(const char * filename, FileReader &file) : FResourceFile(filename, file) { Lumps = NULL; @@ -186,7 +186,7 @@ bool FZipFile::Open(bool quiet) } // Read the central directory info. - Reader.Seek(centraldir, FileRdr::SeekSet); + Reader.Seek(centraldir, FileReader::SeekSet); Reader.Read(&info, sizeof(FZipEndOfCentralDirectory)); // No multi-disk zips! @@ -203,7 +203,7 @@ bool FZipFile::Open(bool quiet) // Load the entire central directory. Too bad that this contains variable length entries... int dirsize = LittleLong(info.DirectorySize); void *directory = malloc(dirsize); - Reader.Seek(LittleLong(info.DirectoryOffset), FileRdr::SeekSet); + Reader.Seek(LittleLong(info.DirectoryOffset), FileReader::SeekSet); Reader.Read(directory, dirsize); char *dirptr = (char*)directory; @@ -386,7 +386,7 @@ FCompressedBuffer FZipLump::GetRawData() { FCompressedBuffer cbuf = { (unsigned)LumpSize, (unsigned)CompressedSize, Method, GPFlags, CRC32, new char[CompressedSize] }; if (Flags & LUMPFZIP_NEEDFILESTART) SetLumpAddress(); - Owner->Reader.Seek(Position, FileRdr::SeekSet); + Owner->Reader.Seek(Position, FileReader::SeekSet); Owner->Reader.Read(cbuf.mBuffer, CompressedSize); return cbuf; } @@ -405,7 +405,7 @@ void FZipLump::SetLumpAddress() FZipLocalFileHeader localHeader; int skiplen; - Owner->Reader.Seek(Position, FileRdr::SeekSet); + Owner->Reader.Seek(Position, FileReader::SeekSet); Owner->Reader.Read(&localHeader, sizeof(localHeader)); skiplen = LittleShort(localHeader.NameLength) + LittleShort(localHeader.ExtraLength); Position += sizeof(localHeader) + skiplen; @@ -418,14 +418,14 @@ void FZipLump::SetLumpAddress() // //========================================================================== -FileRdr *FZipLump::GetReader() +FileReader *FZipLump::GetReader() { // Don't return the reader if this lump is encrypted // In that case always force caching of the lump if (Method == METHOD_STORED) { if (Flags & LUMPFZIP_NEEDFILESTART) SetLumpAddress(); - Owner->Reader.Seek(Position, FileRdr::SeekSet); + Owner->Reader.Seek(Position, FileReader::SeekSet); return &Owner->Reader; } else return NULL; @@ -450,7 +450,7 @@ int FZipLump::FillCache() return -1; } - Owner->Reader.Seek(Position, FileRdr::SeekSet); + Owner->Reader.Seek(Position, FileReader::SeekSet); Cache = new char[LumpSize]; UncompressZipLump(Cache, Owner->Reader, Method, LumpSize, CompressedSize, GPFlags); RefCount = 1; @@ -476,15 +476,15 @@ int FZipLump::GetFileOffset() // //========================================================================== -FResourceFile *CheckZip(const char *filename, FileRdr &file, bool quiet) +FResourceFile *CheckZip(const char *filename, FileReader &file, bool quiet) { char head[4]; if (file.GetLength() >= (long)sizeof(FZipLocalFileHeader)) { - file.Seek(0, FileRdr::SeekSet); + file.Seek(0, FileReader::SeekSet); file.Read(&head, 4); - file.Seek(0, FileRdr::SeekSet); + file.Seek(0, FileReader::SeekSet); if (!memcmp(head, "PK\x3\x4", 4)) { FResourceFile *rf = new FZipFile(filename, file); diff --git a/src/resourcefiles/file_zip.h b/src/resourcefiles/file_zip.h index 48f9a100ec..466292e40c 100644 --- a/src/resourcefiles/file_zip.h +++ b/src/resourcefiles/file_zip.h @@ -22,7 +22,7 @@ struct FZipLump : public FResourceLump int Position; unsigned CRC32; - virtual FileRdr *GetReader(); + virtual FileReader *GetReader(); virtual int FillCache(); private: @@ -43,7 +43,7 @@ class FZipFile : public FResourceFile FZipLump *Lumps; public: - FZipFile(const char * filename, FileRdr &file); + FZipFile(const char * filename, FileReader &file); virtual ~FZipFile(); bool Open(bool quiet); virtual FResourceLump *GetLump(int no) { return ((unsigned)no < NumLumps)? &Lumps[no] : NULL; } diff --git a/src/resourcefiles/resourcefile.cpp b/src/resourcefiles/resourcefile.cpp index f5fca6b098..0a3b899162 100644 --- a/src/resourcefiles/resourcefile.cpp +++ b/src/resourcefiles/resourcefile.cpp @@ -212,11 +212,11 @@ FCompressedBuffer FResourceLump::GetRawData() //========================================================================== // -// Returns the owner's FileRdr if it can be used to access this lump +// Returns the owner's FileReader if it can be used to access this lump // //========================================================================== -FileRdr *FResourceLump::GetReader() +FileReader *FResourceLump::GetReader() { return NULL; } @@ -227,9 +227,9 @@ FileRdr *FResourceLump::GetReader() // //========================================================================== -FileRdr FResourceLump::NewReader() +FileReader FResourceLump::NewReader() { - return FileRdr(new FLumpReader(this)); + return FileReader(new FLumpReader(this)); } //========================================================================== @@ -276,20 +276,20 @@ int FResourceLump::ReleaseCache() // //========================================================================== -typedef FResourceFile * (*CheckFunc)(const char *filename, FileRdr &file, bool quiet); +typedef FResourceFile * (*CheckFunc)(const char *filename, FileReader &file, bool quiet); -FResourceFile *CheckWad(const char *filename, FileRdr &file, bool quiet); -FResourceFile *CheckGRP(const char *filename, FileRdr &file, bool quiet); -FResourceFile *CheckRFF(const char *filename, FileRdr &file, bool quiet); -FResourceFile *CheckPak(const char *filename, FileRdr &file, bool quiet); -FResourceFile *CheckZip(const char *filename, FileRdr &file, bool quiet); -FResourceFile *Check7Z(const char *filename, FileRdr &file, bool quiet); -FResourceFile *CheckLump(const char *filename,FileRdr &file, bool quiet); +FResourceFile *CheckWad(const char *filename, FileReader &file, bool quiet); +FResourceFile *CheckGRP(const char *filename, FileReader &file, bool quiet); +FResourceFile *CheckRFF(const char *filename, FileReader &file, bool quiet); +FResourceFile *CheckPak(const char *filename, FileReader &file, bool quiet); +FResourceFile *CheckZip(const char *filename, FileReader &file, bool quiet); +FResourceFile *Check7Z(const char *filename, FileReader &file, bool quiet); +FResourceFile *CheckLump(const char *filename,FileReader &file, bool quiet); FResourceFile *CheckDir(const char *filename, bool quiet); static CheckFunc funcs[] = { CheckWad, CheckZip, Check7Z, CheckPak, CheckGRP, CheckRFF, CheckLump }; -FResourceFile *FResourceFile::DoOpenResourceFile(const char *filename, FileRdr &file, bool quiet, bool containeronly) +FResourceFile *FResourceFile::DoOpenResourceFile(const char *filename, FileReader &file, bool quiet, bool containeronly) { for(size_t i = 0; i < countof(funcs) - containeronly; i++) { @@ -299,7 +299,7 @@ FResourceFile *FResourceFile::DoOpenResourceFile(const char *filename, FileRdr & return NULL; } -FResourceFile *FResourceFile::OpenResourceFile(const char *filename, FileRdr &file, bool quiet, bool containeronly) +FResourceFile *FResourceFile::OpenResourceFile(const char *filename, FileReader &file, bool quiet, bool containeronly) { return DoOpenResourceFile(filename, file, quiet, containeronly); } @@ -307,7 +307,7 @@ FResourceFile *FResourceFile::OpenResourceFile(const char *filename, FileRdr &fi FResourceFile *FResourceFile::OpenResourceFile(const char *filename, bool quiet, bool containeronly) { - FileRdr file; + FileReader file; if (!file.OpenFile(filename)) return nullptr; return DoOpenResourceFile(filename, file, quiet, containeronly); } @@ -323,7 +323,7 @@ FResourceFile *FResourceFile::OpenDirectory(const char *filename, bool quiet) // //========================================================================== -FResourceFile::FResourceFile(const char *filename, FileRdr &r) +FResourceFile::FResourceFile(const char *filename, FileReader &r) { if (filename != NULL) Filename = copystring(filename); else Filename = NULL; @@ -605,9 +605,9 @@ FResourceLump *FResourceFile::FindLump(const char *name) // //========================================================================== -FileRdr *FUncompressedLump::GetReader() +FileReader *FUncompressedLump::GetReader() { - Owner->Reader.Seek(Position, FileRdr::SeekSet); + Owner->Reader.Seek(Position, FileReader::SeekSet); return &Owner->Reader; } @@ -629,7 +629,7 @@ int FUncompressedLump::FillCache() return -1; } - Owner->Reader.Seek(Position, FileRdr::SeekSet); + Owner->Reader.Seek(Position, FileReader::SeekSet); Cache = new char[LumpSize]; Owner->Reader.Read(Cache, LumpSize); RefCount = 1; @@ -642,7 +642,7 @@ int FUncompressedLump::FillCache() // //========================================================================== -FUncompressedFile::FUncompressedFile(const char *filename, FileRdr &r) +FUncompressedFile::FUncompressedFile(const char *filename, FileReader &r) : FResourceFile(filename, r) { Lumps = NULL; @@ -667,7 +667,7 @@ FExternalLump::FExternalLump(const char *_filename, int filesize) if (filesize == -1) { - FileRdr f; + FileReader f; if (f.OpenFile(_filename)) { @@ -700,7 +700,7 @@ FExternalLump::~FExternalLump() int FExternalLump::FillCache() { Cache = new char[LumpSize]; - FileRdr f; + FileReader f; if (f.OpenFile(filename)) { diff --git a/src/resourcefiles/resourcefile.h b/src/resourcefiles/resourcefile.h index 0d795fae37..50dfaefecc 100644 --- a/src/resourcefiles/resourcefile.h +++ b/src/resourcefiles/resourcefile.h @@ -62,8 +62,8 @@ struct FResourceLump } virtual ~FResourceLump(); - virtual FileRdr *GetReader(); - virtual FileRdr NewReader(); + virtual FileReader *GetReader(); + virtual FileReader NewReader(); virtual int GetFileOffset() { return -1; } virtual int GetIndexNum() const { return 0; } void LumpNameSetup(FString iname); @@ -81,12 +81,12 @@ protected: class FResourceFile { public: - FileRdr Reader; + FileReader Reader; const char *Filename; protected: uint32_t NumLumps; - FResourceFile(const char *filename, FileRdr &r); + FResourceFile(const char *filename, FileReader &r); // for archives that can contain directories void PostProcessArchive(void *lumps, size_t lumpsize); @@ -98,14 +98,14 @@ private: int FilterLumpsByGameType(int gametype, void *lumps, size_t lumpsize, uint32_t max); bool FindPrefixRange(FString filter, void *lumps, size_t lumpsize, uint32_t max, uint32_t &start, uint32_t &end); void JunkLeftoverFilters(void *lumps, size_t lumpsize, uint32_t max); - static FResourceFile *DoOpenResourceFile(const char *filename, FileRdr &file, bool quiet, bool containeronly); + static FResourceFile *DoOpenResourceFile(const char *filename, FileReader &file, bool quiet, bool containeronly); public: - static FResourceFile *OpenResourceFile(const char *filename, FileRdr &file, bool quiet = false, bool containeronly = false); + static FResourceFile *OpenResourceFile(const char *filename, FileReader &file, bool quiet = false, bool containeronly = false); static FResourceFile *OpenResourceFile(const char *filename, bool quiet = false, bool containeronly = false); static FResourceFile *OpenDirectory(const char *filename, bool quiet = false); virtual ~FResourceFile(); - FileRdr *GetReader() { return &Reader; } + FileReader *GetReader() { return &Reader; } uint32_t LumpCount() const { return NumLumps; } uint32_t GetFirstLump() const { return FirstLump; } void SetFirstLump(uint32_t f) { FirstLump = f; } @@ -120,7 +120,7 @@ struct FUncompressedLump : public FResourceLump { int Position; - virtual FileRdr *GetReader(); + virtual FileReader *GetReader(); virtual int FillCache(); virtual int GetFileOffset() { return Position; } @@ -134,7 +134,7 @@ protected: FUncompressedLump * Lumps; - FUncompressedFile(const char *filename, FileRdr &r); + FUncompressedFile(const char *filename, FileReader &r); virtual ~FUncompressedFile(); virtual FResourceLump *GetLump(int no) { return ((unsigned)no < NumLumps)? &Lumps[no] : NULL; } @@ -155,7 +155,7 @@ struct FExternalLump : public FResourceLump struct FMemoryFile : public FUncompressedFile { FMemoryFile(const char *_filename, const void *sdata, int length) - : FUncompressedFile(_filename, FileRdr()) + : FUncompressedFile(_filename, FileReader()) { Reader.OpenMemoryArray(sdata, length); } diff --git a/src/s_playlist.cpp b/src/s_playlist.cpp index 4fcf8ee28b..979bbb67a0 100644 --- a/src/s_playlist.cpp +++ b/src/s_playlist.cpp @@ -54,7 +54,7 @@ bool FPlayList::ChangeList (const char *path) { FString playlistdir; FString song; - FileRdr fr; + FileReader fr; bool first; bool pls; int i; @@ -133,7 +133,7 @@ bool FPlayList::ChangeList (const char *path) return Songs.Size() != 0; } -FString FPlayList::NextLine (FileRdr &file) +FString FPlayList::NextLine (FileReader &file) { char buffer[512]; char *skipper; diff --git a/src/s_playlist.h b/src/s_playlist.h index 049040a0f6..e1f4978799 100644 --- a/src/s_playlist.h +++ b/src/s_playlist.h @@ -34,7 +34,7 @@ #ifndef __S_PLAYLIST_H__ #define __S_PLAYLIST_H__ -class FileRdr; +class FileReader; class FPlayList { @@ -53,7 +53,7 @@ public: const char *GetSong (int position) const; private: - static FString NextLine (FileRdr &file); + static FString NextLine (FileReader &file); unsigned int Position; TArray Songs; diff --git a/src/s_sound.cpp b/src/s_sound.cpp index 6885fcb0c8..088f9404dd 100644 --- a/src/s_sound.cpp +++ b/src/s_sound.cpp @@ -2609,7 +2609,7 @@ bool S_ChangeMusic (const char *musicname, int order, bool looping, bool force) musicname += 7; } - FileRdr reader; + FileReader reader; if (!FileExists (musicname)) { if ((lumpnum = Wads.CheckNumForFullName (musicname, true, ns_music)) == -1) diff --git a/src/sc_man.cpp b/src/sc_man.cpp index 2056ca60b0..216a5527af 100644 --- a/src/sc_man.cpp +++ b/src/sc_man.cpp @@ -248,7 +248,7 @@ bool FScanner::OpenFile (const char *name) { Close (); - FileRdr fr; + FileReader fr; if (!fr.OpenFile(name)) return false; auto filesize = fr.GetLength(); auto filebuf = new uint8_t[filesize]; diff --git a/src/sound/i_music.cpp b/src/sound/i_music.cpp index 1042d0c5e1..e93ba1b091 100644 --- a/src/sound/i_music.cpp +++ b/src/sound/i_music.cpp @@ -309,7 +309,7 @@ MusInfo *MusInfo::GetWaveDumper(const char *filename, int rate) // //========================================================================== -static MIDISource *CreateMIDISource(FileRdr &reader, EMIDIType miditype) +static MIDISource *CreateMIDISource(FileReader &reader, EMIDIType miditype) { MIDISource *source = nullptr; switch (miditype) @@ -398,7 +398,7 @@ static EMIDIType IdentifyMIDIType(uint32_t *id, int size) // //========================================================================== -MusInfo *I_RegisterSong (FileRdr &reader, MidiDeviceSetting *device) +MusInfo *I_RegisterSong (FileReader &reader, MidiDeviceSetting *device) { MusInfo *info = nullptr; const char *fmt; @@ -409,7 +409,7 @@ MusInfo *I_RegisterSong (FileRdr &reader, MidiDeviceSetting *device) return nullptr; } - if(reader.Read(id, 32) != 32 || reader.Seek(-32, FileRdr::SeekCur) != 0) + if(reader.Read(id, 32) != 32 || reader.Seek(-32, FileReader::SeekCur) != 0) { return nullptr; } @@ -436,7 +436,7 @@ MusInfo *I_RegisterSong (FileRdr &reader, MidiDeviceSetting *device) return nullptr; } - if (reader.Read(id, 32) != 32 || reader.Seek(-32, FileRdr::SeekCur) != 0) + if (reader.Read(id, 32) != 32 || reader.Seek(-32, FileReader::SeekCur) != 0) { return nullptr; } @@ -500,12 +500,12 @@ MusInfo *I_RegisterSong (FileRdr &reader, MidiDeviceSetting *device) { uint32_t subid; - reader.Seek(8, FileRdr::SeekCur); + reader.Seek(8, FileReader::SeekCur); if (reader.Read (&subid, 4) != 4) { return nullptr; } - reader.Seek(-12, FileRdr::SeekCur); + reader.Seek(-12, FileReader::SeekCur); if (subid == (('C')|(('D')<<8)|(('D')<<16)|(('A')<<24))) { @@ -709,7 +709,7 @@ static MIDISource *GetMIDISource(const char *fn) auto wlump = Wads.OpenLumpReader(lump); uint32_t id[32 / 4]; - if (wlump.Read(id, 32) != 32 || wlump.Seek(-32, FileRdr::SeekCur) != 0) + if (wlump.Read(id, 32) != 32 || wlump.Seek(-32, FileReader::SeekCur) != 0) { Printf("Unable to read lump %s\n", src.GetChars()); return nullptr; diff --git a/src/sound/i_music.h b/src/sound/i_music.h index 167d73157e..7976c1d48a 100644 --- a/src/sound/i_music.h +++ b/src/sound/i_music.h @@ -37,7 +37,7 @@ #include "doomdef.h" #include "i_soundinternal.h" -class FileRdr; +class FileReader; struct FOptionValues; // @@ -55,7 +55,7 @@ void I_SetMusicVolume (float volume); // Registers a song handle to song data. class MusInfo; struct MidiDeviceSetting; -MusInfo *I_RegisterSong (FileRdr &reader, MidiDeviceSetting *device); +MusInfo *I_RegisterSong (FileReader &reader, MidiDeviceSetting *device); MusInfo *I_RegisterCDSong (int track, int cdid = 0); // The base music class. Everything is derived from this -------------------- diff --git a/src/sound/i_musicinterns.h b/src/sound/i_musicinterns.h index 81a1fa415b..011a739e54 100644 --- a/src/sound/i_musicinterns.h +++ b/src/sound/i_musicinterns.h @@ -408,7 +408,7 @@ protected: class StreamSong : public MusInfo { public: - StreamSong (FileRdr &reader); + StreamSong (FileReader &reader); ~StreamSong (); void Play (bool looping, int subsong); void Pause (); @@ -431,7 +431,7 @@ protected: class OPLMUSSong : public StreamSong { public: - OPLMUSSong (FileRdr &reader, const char *args); + OPLMUSSong (FileReader &reader, const char *args); ~OPLMUSSong (); void Play (bool looping, int subsong); bool IsPlaying (); @@ -480,18 +480,18 @@ protected: class CDDAFile : public CDSong { public: - CDDAFile (FileRdr &reader); + CDDAFile (FileReader &reader); }; // Module played via foo_dumb ----------------------------------------------- -MusInfo *MOD_OpenSong(FileRdr &reader); +MusInfo *MOD_OpenSong(FileReader &reader); // Music played via Game Music Emu ------------------------------------------ const char *GME_CheckFormat(uint32_t header); -MusInfo *GME_OpenSong(FileRdr &reader, const char *fmt); -MusInfo *SndFile_OpenSong(FileRdr &fr); +MusInfo *GME_OpenSong(FileReader &reader, const char *fmt); +MusInfo *SndFile_OpenSong(FileReader &fr); // -------------------------------------------------------------------------- diff --git a/src/sound/i_sound.cpp b/src/sound/i_sound.cpp index e37a3adb12..ac05783c53 100644 --- a/src/sound/i_sound.cpp +++ b/src/sound/i_sound.cpp @@ -159,7 +159,7 @@ public: { return NULL; } - SoundStream *OpenStream (FileRdr &reader, int flags) + SoundStream *OpenStream (FileReader &reader, int flags) { return NULL; } @@ -370,7 +370,7 @@ FString SoundRenderer::GatherStats () short *SoundRenderer::DecodeSample(int outlen, const void *coded, int sizebytes, ECodecType ctype) { - FileRdr reader; + FileReader reader; short *samples = (short*)calloc(1, outlen); ChannelConfig chans; SampleType type; @@ -578,7 +578,7 @@ std::pair SoundRenderer::LoadSoundBuffered(FSoundLoadBuffer * return std::make_pair(retval, true); } -SoundDecoder *SoundRenderer::CreateDecoder(FileRdr &reader) +SoundDecoder *SoundRenderer::CreateDecoder(FileReader &reader) { SoundDecoder *decoder = NULL; auto pos = reader.Tell(); @@ -587,7 +587,7 @@ SoundDecoder *SoundRenderer::CreateDecoder(FileRdr &reader) decoder = new SndFileDecoder; if (decoder->open(reader)) return decoder; - reader.Seek(pos, FileRdr::SeekSet); + reader.Seek(pos, FileReader::SeekSet); delete decoder; decoder = NULL; @@ -596,7 +596,7 @@ SoundDecoder *SoundRenderer::CreateDecoder(FileRdr &reader) decoder = new MPG123Decoder; if (decoder->open(reader)) return decoder; - reader.Seek(pos, FileRdr::SeekSet); + reader.Seek(pos, FileReader::SeekSet); delete decoder; decoder = NULL; diff --git a/src/sound/i_sound.h b/src/sound/i_sound.h index e92062d88c..ce02f73569 100644 --- a/src/sound/i_sound.h +++ b/src/sound/i_sound.h @@ -38,7 +38,7 @@ #include "doomtype.h" #include "i_soundinternal.h" -class FileRdr; +class FileReader; enum ECodecType { @@ -118,7 +118,7 @@ public: // Streaming sounds. virtual SoundStream *CreateStream (SoundStreamCallback callback, int buffbytes, int flags, int samplerate, void *userdata) = 0; - virtual SoundStream *OpenStream (FileRdr &reader, int flags) = 0; + virtual SoundStream *OpenStream (FileReader &reader, int flags) = 0; // Starts a sound. virtual FISoundChannel *StartSound (SoundHandle sfx, float vol, int pitch, int chanflags, FISoundChannel *reuse_chan) = 0; @@ -168,7 +168,7 @@ public: virtual void DrawWaveDebug(int mode); - static SoundDecoder *CreateDecoder(FileRdr &reader); + static SoundDecoder *CreateDecoder(FileReader &reader); }; extern SoundRenderer *GSnd; diff --git a/src/sound/i_soundfont.cpp b/src/sound/i_soundfont.cpp index 587143fa49..3e30af7411 100644 --- a/src/sound/i_soundfont.cpp +++ b/src/sound/i_soundfont.cpp @@ -50,7 +50,7 @@ FSoundFontManager sfmanager; // //========================================================================== -std::pair FSoundFontReader::LookupFile(const char *name) +std::pair FSoundFontReader::LookupFile(const char *name) { if (!IsAbsPath(name)) { @@ -117,9 +117,9 @@ FSF2Reader::FSF2Reader(const char *fn) // //========================================================================== -FileRdr FSF2Reader::OpenMainConfigFile() +FileReader FSF2Reader::OpenMainConfigFile() { - FileRdr fr; + FileReader fr; if (mMainConfigForSF2.IsNotEmpty()) { fr.OpenMemory(mMainConfigForSF2.GetChars(), mMainConfigForSF2.Len()); @@ -127,9 +127,9 @@ FileRdr FSF2Reader::OpenMainConfigFile() return fr; } -FileRdr FSF2Reader::OpenFile(const char *name) +FileReader FSF2Reader::OpenFile(const char *name) { - FileRdr fr; + FileReader fr; if (mFilename.CompareNoCase(name) == 0) { fr.OpenFile(name); @@ -153,14 +153,14 @@ FZipPatReader::~FZipPatReader() if (resf != nullptr) delete resf; } -FileRdr FZipPatReader::OpenMainConfigFile() +FileReader FZipPatReader::OpenMainConfigFile() { return OpenFile("timidity.cfg"); } -FileRdr FZipPatReader::OpenFile(const char *name) +FileReader FZipPatReader::OpenFile(const char *name) { - FileRdr fr; + FileReader fr; if (resf != nullptr) { auto lump = resf->FindLump(name); @@ -195,7 +195,7 @@ FPatchSetReader::FPatchSetReader(const char *filename) }; #endif mAllowAbsolutePaths = true; - FileRdr fr; + FileReader fr; if (fr.OpenFile(filename)) { mFullPathToConfig = filename; @@ -225,19 +225,19 @@ FPatchSetReader::FPatchSetReader() mAllowAbsolutePaths = true; } -FileRdr FPatchSetReader::OpenMainConfigFile() +FileReader FPatchSetReader::OpenMainConfigFile() { - FileRdr fr; + FileReader fr; fr.OpenFile(mFullPathToConfig); return fr; } -FileRdr FPatchSetReader::OpenFile(const char *name) +FileReader FPatchSetReader::OpenFile(const char *name) { FString path; if (IsAbsPath(name)) path = name; else path = mBasePath + name; - FileRdr fr; + FileReader fr; fr.OpenFile(path); return fr; } @@ -258,18 +258,18 @@ FLumpPatchSetReader::FLumpPatchSetReader(const char *filename) if (mBasePath.Len() > 0 && mBasePath.Back() != '/') mBasePath += '/'; } -FileRdr FLumpPatchSetReader::OpenMainConfigFile() +FileReader FLumpPatchSetReader::OpenMainConfigFile() { return Wads.ReopenLumpReader(mLumpIndex); } -FileRdr FLumpPatchSetReader::OpenFile(const char *name) +FileReader FLumpPatchSetReader::OpenFile(const char *name) { FString path; - if (IsAbsPath(name)) return FileRdr(); // no absolute paths in the lump directory. + if (IsAbsPath(name)) return FileReader(); // no absolute paths in the lump directory. path = mBasePath + name; auto index = Wads.CheckNumForFullName(path); - if (index < 0) return FileRdr(); + if (index < 0) return FileReader(); return Wads.ReopenLumpReader(index); } @@ -293,7 +293,7 @@ void FSoundFontManager::ProcessOneFile(const FString &fn) if (!sfi.mName.CompareNoCase(fb)) return; } - FileRdr fr; + FileReader fr; if (fr.OpenFile(fn)) { // Try to identify. We only accept .sf2 and .zip by content. All other archives are intentionally ignored. @@ -435,7 +435,7 @@ FSoundFontReader *FSoundFontManager::OpenSoundFont(const char *name, int allowed // Next check if the file is a .sf file if (allowed & SF_SF2) { - FileRdr fr; + FileReader fr; if (fr.OpenFile(name)) { char head[16] = { 0}; @@ -449,7 +449,7 @@ FSoundFontReader *FSoundFontManager::OpenSoundFont(const char *name, int allowed } if (allowed & SF_GUS) { - FileRdr fr; + FileReader fr; if (fr.OpenFile(name)) { char head[16] = { 0 }; diff --git a/src/sound/i_soundfont.h b/src/sound/i_soundfont.h index a6864d9d78..5ef60102cc 100644 --- a/src/sound/i_soundfont.h +++ b/src/sound/i_soundfont.h @@ -41,9 +41,9 @@ protected: public: virtual ~FSoundFontReader() {} - virtual FileRdr OpenMainConfigFile() = 0; // this is special because it needs to be synthesized for .sf files and set some restrictions for patch sets - virtual FileRdr OpenFile(const char *name) = 0; - std::pair LookupFile(const char *name); + virtual FileReader OpenMainConfigFile() = 0; // this is special because it needs to be synthesized for .sf files and set some restrictions for patch sets + virtual FileReader OpenFile(const char *name) = 0; + std::pair LookupFile(const char *name); void AddPath(const char *str); virtual FString basePath() const { @@ -63,8 +63,8 @@ class FSF2Reader : public FSoundFontReader FString mFilename; public: FSF2Reader(const char *filename); - virtual FileRdr OpenMainConfigFile() override; - virtual FileRdr OpenFile(const char *name) override; + virtual FileReader OpenMainConfigFile() override; + virtual FileReader OpenFile(const char *name) override; }; //========================================================================== @@ -79,8 +79,8 @@ class FZipPatReader : public FSoundFontReader public: FZipPatReader(const char *filename); ~FZipPatReader(); - virtual FileRdr OpenMainConfigFile() override; - virtual FileRdr OpenFile(const char *name) override; + virtual FileReader OpenMainConfigFile() override; + virtual FileReader OpenFile(const char *name) override; bool isOk() { return resf != nullptr; } }; @@ -97,8 +97,8 @@ class FLumpPatchSetReader : public FSoundFontReader public: FLumpPatchSetReader(const char *filename); - virtual FileRdr OpenMainConfigFile() override; - virtual FileRdr OpenFile(const char *name) override; + virtual FileReader OpenMainConfigFile() override; + virtual FileReader OpenFile(const char *name) override; virtual FString basePath() const override { return mBasePath; @@ -120,8 +120,8 @@ class FPatchSetReader : public FSoundFontReader public: FPatchSetReader(); FPatchSetReader(const char *filename); - virtual FileRdr OpenMainConfigFile() override; - virtual FileRdr OpenFile(const char *name) override; + virtual FileReader OpenMainConfigFile() override; + virtual FileReader OpenFile(const char *name) override; virtual FString basePath() const override { return mBasePath; diff --git a/src/sound/i_soundinternal.h b/src/sound/i_soundinternal.h index 39a478790d..a75aebb659 100644 --- a/src/sound/i_soundinternal.h +++ b/src/sound/i_soundinternal.h @@ -7,7 +7,7 @@ #include "vectors.h" #include "tarray.h" -class FileRdr; +class FileReader; // For convenience, this structure matches FMOD_REVERB_PROPERTIES. // Since I can't very well #include system-specific stuff in the @@ -112,7 +112,7 @@ struct FISoundChannel }; -void FindLoopTags(FileRdr &fr, uint32_t *start, bool *startass, uint32_t *end, bool *endass); +void FindLoopTags(FileReader &fr, uint32_t *start, bool *startass, uint32_t *end, bool *endass); enum SampleType @@ -143,7 +143,7 @@ struct SoundDecoder virtual ~SoundDecoder() { } protected: - virtual bool open(FileRdr &reader) = 0; + virtual bool open(FileReader &reader) = 0; friend class SoundRenderer; private: diff --git a/src/sound/midisources/midisource.h b/src/sound/midisources/midisource.h index f7ce85e4cf..7e7381eae4 100644 --- a/src/sound/midisources/midisource.h +++ b/src/sound/midisources/midisource.h @@ -76,7 +76,7 @@ public: class MUSSong2 : public MIDISource { public: - MUSSong2(FileRdr &reader); + MUSSong2(FileReader &reader); ~MUSSong2(); protected: @@ -99,7 +99,7 @@ private: class MIDISong2 : public MIDISource { public: - MIDISong2(FileRdr &reader); + MIDISong2(FileReader &reader); ~MIDISong2(); protected: @@ -153,7 +153,7 @@ protected: class HMISong : public MIDISource { public: - HMISong(FileRdr &reader); + HMISong(FileReader &reader); ~HMISong(); protected: @@ -193,7 +193,7 @@ private: class XMISong : public MIDISource { public: - XMISong(FileRdr &reader); + XMISong(FileReader &reader); ~XMISong(); protected: diff --git a/src/sound/midisources/midisource_hmi.cpp b/src/sound/midisources/midisource_hmi.cpp index 9029acb060..7b9276f1f6 100644 --- a/src/sound/midisources/midisource_hmi.cpp +++ b/src/sound/midisources/midisource_hmi.cpp @@ -126,7 +126,7 @@ struct HMISong::TrackInfo // //========================================================================== -HMISong::HMISong (FileRdr &reader) +HMISong::HMISong (FileReader &reader) { int len = (int)reader.GetLength(); if (len < 0x100) diff --git a/src/sound/midisources/midisource_mus.cpp b/src/sound/midisources/midisource_mus.cpp index 9b6fe06bca..f978b888f5 100644 --- a/src/sound/midisources/midisource_mus.cpp +++ b/src/sound/midisources/midisource_mus.cpp @@ -88,7 +88,7 @@ static const uint8_t CtrlTranslate[15] = // //========================================================================== -MUSSong2::MUSSong2 (FileRdr &reader) +MUSSong2::MUSSong2 (FileReader &reader) : MusHeader(0), MusBuffer(0) { uint8_t front[32]; diff --git a/src/sound/midisources/midisource_smf.cpp b/src/sound/midisources/midisource_smf.cpp index 15c5fbabed..5330d74d48 100644 --- a/src/sound/midisources/midisource_smf.cpp +++ b/src/sound/midisources/midisource_smf.cpp @@ -99,7 +99,7 @@ struct MIDISong2::TrackInfo // //========================================================================== -MIDISong2::MIDISong2 (FileRdr &reader) +MIDISong2::MIDISong2 (FileReader &reader) : MusHeader(0), Tracks(0) { int p; diff --git a/src/sound/midisources/midisource_xmi.cpp b/src/sound/midisources/midisource_xmi.cpp index 50e6b06e35..3fbfdeb5db 100644 --- a/src/sound/midisources/midisource_xmi.cpp +++ b/src/sound/midisources/midisource_xmi.cpp @@ -105,7 +105,7 @@ struct XMISong::TrackInfo // //========================================================================== -XMISong::XMISong (FileRdr &reader) +XMISong::XMISong (FileReader &reader) : MusHeader(0), Songs(0) { SongLen = (int)reader.GetLength(); diff --git a/src/sound/mpg123_decoder.cpp b/src/sound/mpg123_decoder.cpp index 0a2f9fa2e8..716553c521 100644 --- a/src/sound/mpg123_decoder.cpp +++ b/src/sound/mpg123_decoder.cpp @@ -87,7 +87,7 @@ off_t MPG123Decoder::file_lseek(void *handle, off_t offset, int whence) return -1; } - if(reader.Seek(offset, (FileRdr::ESeek)whence) != 0) + if(reader.Seek(offset, (FileReader::ESeek)whence) != 0) return -1; return (off_t)reader.Tell(); } @@ -109,7 +109,7 @@ MPG123Decoder::~MPG123Decoder() } } -bool MPG123Decoder::open(FileRdr &reader) +bool MPG123Decoder::open(FileReader &reader) { if(!inited) { @@ -215,7 +215,7 @@ bool MPG123Decoder::seek(size_t ms_offset, bool ms, bool mayrestart) mpg123_delete(MPG123); MPG123 = 0; } - Reader.Seek(0, FileRdr::SeekSet); + Reader.Seek(0, FileReader::SeekSet); // Do not call open with our own reader variable, that would be catastrophic. auto reader = std::move(Reader); return open(reader); diff --git a/src/sound/mpg123_decoder.h b/src/sound/mpg123_decoder.h index e2b0701496..dad0f11fee 100644 --- a/src/sound/mpg123_decoder.h +++ b/src/sound/mpg123_decoder.h @@ -30,13 +30,13 @@ struct MPG123Decoder : public SoundDecoder virtual ~MPG123Decoder(); protected: - virtual bool open(FileRdr &reader); + virtual bool open(FileReader &reader); private: mpg123_handle *MPG123; bool Done; - FileRdr Reader; + FileReader Reader; static off_t file_lseek(void *handle, off_t offset, int whence); static ssize_t file_read(void *handle, void *buffer, size_t bytes); diff --git a/src/sound/musicformats/music_cd.cpp b/src/sound/musicformats/music_cd.cpp index 8ad648c488..52de04a576 100644 --- a/src/sound/musicformats/music_cd.cpp +++ b/src/sound/musicformats/music_cd.cpp @@ -112,7 +112,7 @@ bool CDSong::IsPlaying () return m_Status != STATE_Stopped; } -CDDAFile::CDDAFile (FileRdr &reader) +CDDAFile::CDDAFile (FileReader &reader) : CDSong () { uint32_t chunk; @@ -122,7 +122,7 @@ CDDAFile::CDDAFile (FileRdr &reader) // I_RegisterSong already identified this as a CDDA file, so we // just need to check the contents we're interested in. - reader.Seek(12, FileRdr::SeekCur); + reader.Seek(12, FileReader::SeekCur); while (reader.Tell() < endpos) { @@ -130,11 +130,11 @@ CDDAFile::CDDAFile (FileRdr &reader) if (chunk != (('f')|(('m')<<8)|(('t')<<16)|((' ')<<24))) { reader.Read(&chunk, 4); - reader.Seek(chunk, FileRdr::SeekCur); + reader.Seek(chunk, FileReader::SeekCur); } else { - reader.Seek(6, FileRdr::SeekCur); + reader.Seek(6, FileReader::SeekCur); reader.Read(&track, 2); reader.Read(&discid, 4); diff --git a/src/sound/musicformats/music_dumb.cpp b/src/sound/musicformats/music_dumb.cpp index 310f197ff3..19f76cb02b 100644 --- a/src/sound/musicformats/music_dumb.cpp +++ b/src/sound/musicformats/music_dumb.cpp @@ -550,7 +550,7 @@ static DUMBFILE_SYSTEM mem_dfs = { // //========================================================================== -DUMBFILE *dumb_read_allfile(dumbfile_mem_status *filestate, uint8_t *start, FileRdr &reader, int lenhave, int lenfull) +DUMBFILE *dumb_read_allfile(dumbfile_mem_status *filestate, uint8_t *start, FileReader &reader, int lenhave, int lenfull) { filestate->size = lenfull; filestate->offset = 0; @@ -765,7 +765,7 @@ static void MOD_SetAutoChip(DUH *duh) // //========================================================================== -MusInfo *MOD_OpenSong(FileRdr &reader) +MusInfo *MOD_OpenSong(FileReader &reader) { DUH *duh = 0; int headsize; @@ -902,7 +902,7 @@ MusInfo *MOD_OpenSong(FileRdr &reader) { if (!(f = dumb_read_allfile(&filestate, start, reader, headsize, size))) { - reader.Seek(fpos, FileRdr::SeekSet); + reader.Seek(fpos, FileReader::SeekSet); return NULL; } } @@ -943,7 +943,7 @@ MusInfo *MOD_OpenSong(FileRdr &reader) else { // Reposition file pointer for other codecs to do their checks. - reader.Seek(fpos, FileRdr::SeekSet); + reader.Seek(fpos, FileReader::SeekSet); } if (filestate.ptr != (uint8_t *)start) { diff --git a/src/sound/musicformats/music_gme.cpp b/src/sound/musicformats/music_gme.cpp index 06f7c99d7d..b0dff3da1c 100644 --- a/src/sound/musicformats/music_gme.cpp +++ b/src/sound/musicformats/music_gme.cpp @@ -113,7 +113,7 @@ const char *GME_CheckFormat(uint32_t id) // //========================================================================== -MusInfo *GME_OpenSong(FileRdr &reader, const char *fmt) +MusInfo *GME_OpenSong(FileReader &reader, const char *fmt) { gme_type_t type; gme_err_t err; @@ -140,7 +140,7 @@ MusInfo *GME_OpenSong(FileRdr &reader, const char *fmt) { delete[] song; gme_delete(emu); - reader.Seek(fpos, FileRdr::SeekSet); + reader.Seek(fpos, FileReader::SeekSet); return nullptr; } @@ -151,7 +151,7 @@ MusInfo *GME_OpenSong(FileRdr &reader, const char *fmt) { Printf("Failed loading song: %s\n", err); gme_delete(emu); - reader.Seek(fpos, FileRdr::SeekSet); + reader.Seek(fpos, FileReader::SeekSet); return nullptr; } gme_set_stereo_depth(emu, clamp(*gme_stereodepth, 0.f, 1.f)); diff --git a/src/sound/musicformats/music_libsndfile.cpp b/src/sound/musicformats/music_libsndfile.cpp index d9a9c8f8b8..b87492a4eb 100644 --- a/src/sound/musicformats/music_libsndfile.cpp +++ b/src/sound/musicformats/music_libsndfile.cpp @@ -48,7 +48,7 @@ class SndFileSong : public StreamSong { public: - SndFileSong(FileRdr &reader, SoundDecoder *decoder, uint32_t loop_start, uint32_t loop_end, bool startass, bool endass); + SndFileSong(FileReader &reader, SoundDecoder *decoder, uint32_t loop_start, uint32_t loop_end, bool startass, bool endass); ~SndFileSong(); bool SetSubsong(int subsong); void Play(bool looping, int subsong); @@ -56,7 +56,7 @@ public: protected: FCriticalSection CritSec; - FileRdr Reader; + FileReader Reader; SoundDecoder *Decoder; int Channels; int SampleRate; @@ -105,7 +105,7 @@ CUSTOM_CVAR(Int, snd_streambuffersize, 64, CVAR_ARCHIVE | CVAR_GLOBALCONFIG) // //========================================================================== -static void ParseVorbisComments(FileRdr &fr, uint32_t *start, bool *startass, uint32_t *end, bool *endass) +static void ParseVorbisComments(FileReader &fr, uint32_t *start, bool *startass, uint32_t *end, bool *endass) { uint8_t vc_data[4]; @@ -116,7 +116,7 @@ static void ParseVorbisComments(FileRdr &fr, uint32_t *start, bool *startass, ui uint32_t vndr_len = vc_data[0] | (vc_data[1]<<8) | (vc_data[2]<<16) | (vc_data[3]<<24); // Skip vendor string - if(fr.Seek(vndr_len, FileRdr::SeekCur) == -1) + if(fr.Seek(vndr_len, FileReader::SeekCur) == -1) return; // Following the vendor string is a 32LE integer for the number of @@ -136,7 +136,7 @@ static void ParseVorbisComments(FileRdr &fr, uint32_t *start, bool *startass, ui if(length >= 128) { // If the comment is "big", skip it - if(fr.Seek(length, FileRdr::SeekCur) == -1) + if(fr.Seek(length, FileReader::SeekCur) == -1) return; continue; } @@ -153,7 +153,7 @@ static void ParseVorbisComments(FileRdr &fr, uint32_t *start, bool *startass, ui } } -static void FindFlacComments(FileRdr &fr, uint32_t *loop_start, bool *startass, uint32_t *loop_end, bool *endass) +static void FindFlacComments(FileReader &fr, uint32_t *loop_start, bool *startass, uint32_t *loop_end, bool *endass) { // Already verified the fLaC marker, so we're 4 bytes into the file bool lastblock = false; @@ -175,12 +175,12 @@ static void FindFlacComments(FileRdr &fr, uint32_t *loop_start, bool *startass, return; } - if(fr.Seek(blocksize, FileRdr::SeekCur) == -1) + if(fr.Seek(blocksize, FileReader::SeekCur) == -1) break; } } -static void FindOggComments(FileRdr &fr, uint32_t *loop_start, bool *startass, uint32_t *loop_end, bool *endass) +static void FindOggComments(FileReader &fr, uint32_t *loop_start, bool *startass, uint32_t *loop_end, bool *endass) { uint8_t ogghead[27]; @@ -237,7 +237,7 @@ static void FindOggComments(FileRdr &fr, uint32_t *loop_start, bool *startass, u segsize -= 7; } - if(fr.Seek(segsize, FileRdr::SeekCur) == -1) + if(fr.Seek(segsize, FileReader::SeekCur) == -1) return; } @@ -250,7 +250,7 @@ static void FindOggComments(FileRdr &fr, uint32_t *loop_start, bool *startass, u } } -void FindLoopTags(FileRdr &fr, uint32_t *start, bool *startass, uint32_t *end, bool *endass) +void FindLoopTags(FileReader &fr, uint32_t *start, bool *startass, uint32_t *end, bool *endass) { uint8_t signature[4]; @@ -268,15 +268,15 @@ void FindLoopTags(FileRdr &fr, uint32_t *start, bool *startass, uint32_t *end, b // //========================================================================== -MusInfo *SndFile_OpenSong(FileRdr &fr) +MusInfo *SndFile_OpenSong(FileReader &fr) { - fr.Seek(0, FileRdr::SeekSet); + fr.Seek(0, FileReader::SeekSet); uint32_t loop_start = 0, loop_end = ~0u; bool startass = false, endass = false; FindLoopTags(fr, &loop_start, &startass, &loop_end, &endass); - fr.Seek(0, FileRdr::SeekSet); + fr.Seek(0, FileReader::SeekSet); auto decoder = SoundRenderer::CreateDecoder(fr); if (decoder == nullptr) return nullptr; return new SndFileSong(fr, decoder, loop_start, loop_end, startass, endass); @@ -288,7 +288,7 @@ MusInfo *SndFile_OpenSong(FileRdr &fr) // //========================================================================== -SndFileSong::SndFileSong(FileRdr &reader, SoundDecoder *decoder, uint32_t loop_start, uint32_t loop_end, bool startass, bool endass) +SndFileSong::SndFileSong(FileReader &reader, SoundDecoder *decoder, uint32_t loop_start, uint32_t loop_end, bool startass, bool endass) { ChannelConfig iChannels; SampleType Type; diff --git a/src/sound/musicformats/music_opl.cpp b/src/sound/musicformats/music_opl.cpp index 518f76906d..fe29bb145f 100644 --- a/src/sound/musicformats/music_opl.cpp +++ b/src/sound/musicformats/music_opl.cpp @@ -69,7 +69,7 @@ void OPL_SetCore(const char *args) if (args != NULL && *args >= '0' && *args < '4') current_opl_core = *args - '0'; } -OPLMUSSong::OPLMUSSong (FileRdr &reader, const char *args) +OPLMUSSong::OPLMUSSong (FileReader &reader, const char *args) { int samples = int(OPL_SAMPLE_RATE / 14); diff --git a/src/sound/musicformats/music_stream.cpp b/src/sound/musicformats/music_stream.cpp index 019fd4125d..01f75fb4b8 100644 --- a/src/sound/musicformats/music_stream.cpp +++ b/src/sound/musicformats/music_stream.cpp @@ -85,7 +85,7 @@ StreamSong::~StreamSong () } } -StreamSong::StreamSong (FileRdr &reader) +StreamSong::StreamSong (FileReader &reader) { m_Stream = GSnd->OpenStream (reader, SoundStream::Loop); } diff --git a/src/sound/oalsound.cpp b/src/sound/oalsound.cpp index a08077844c..033f40b89e 100644 --- a/src/sound/oalsound.cpp +++ b/src/sound/oalsound.cpp @@ -228,7 +228,7 @@ class OpenALSoundStream : public SoundStream ALfloat Volume; - FileRdr Reader; + FileReader Reader; SoundDecoder *Decoder; static bool DecoderCallback(SoundStream *_sstream, void *ptr, int length, void *user) { @@ -603,7 +603,7 @@ public: return true; } - bool Init(FileRdr &reader, bool loop) + bool Init(FileReader &reader, bool loop) { if(!SetupSource()) { @@ -1276,7 +1276,7 @@ std::pair OpenALSoundRenderer::LoadSoundRaw(uint8_t *sfxdata, std::pair OpenALSoundRenderer::LoadSound(uint8_t *sfxdata, int length, bool monoize, FSoundLoadBuffer *pBuffer) { SoundHandle retval = { NULL }; - FileRdr reader; + FileReader reader; ALenum format = AL_NONE; ChannelConfig chans; SampleType type; @@ -1291,7 +1291,7 @@ std::pair OpenALSoundRenderer::LoadSound(uint8_t *sfxdata, int FindLoopTags(reader, &loop_start, &startass, &loop_end, &endass); - reader.Seek(0, FileRdr::SeekSet); + reader.Seek(0, FileReader::SeekSet); std::unique_ptr decoder(CreateDecoder(reader)); if (!decoder) return std::make_pair(retval, true); @@ -1529,7 +1529,7 @@ SoundStream *OpenALSoundRenderer::CreateStream(SoundStreamCallback callback, int return stream; } -SoundStream *OpenALSoundRenderer::OpenStream(FileRdr &reader, int flags) +SoundStream *OpenALSoundRenderer::OpenStream(FileReader &reader, int flags) { if(StreamThread.get_id() == std::thread::id()) StreamThread = std::thread(std::mem_fn(&OpenALSoundRenderer::BackgroundProc), this); diff --git a/src/sound/oalsound.h b/src/sound/oalsound.h index 9369adf33d..a2a7869cea 100644 --- a/src/sound/oalsound.h +++ b/src/sound/oalsound.h @@ -136,7 +136,7 @@ public: // Streaming sounds. virtual SoundStream *CreateStream(SoundStreamCallback callback, int buffbytes, int flags, int samplerate, void *userdata); - virtual SoundStream *OpenStream(FileRdr &reader, int flags); + virtual SoundStream *OpenStream(FileReader &reader, int flags); // Starts a sound. virtual FISoundChannel *StartSound(SoundHandle sfx, float vol, int pitch, int chanflags, FISoundChannel *reuse_chan); diff --git a/src/sound/oplsynth/opl_mus_player.cpp b/src/sound/oplsynth/opl_mus_player.cpp index 8042a84d0a..6cb33348e5 100644 --- a/src/sound/oplsynth/opl_mus_player.cpp +++ b/src/sound/oplsynth/opl_mus_player.cpp @@ -84,7 +84,7 @@ void OPLmusicBlock::Restart() LastOffset = 0; } -OPLmusicFile::OPLmusicFile (FileRdr &reader) +OPLmusicFile::OPLmusicFile (FileReader &reader) : ScoreLen ((int)reader.GetLength()) { if (io == NULL) diff --git a/src/sound/oplsynth/opl_mus_player.h b/src/sound/oplsynth/opl_mus_player.h index 26b4ab8023..17f5521e25 100644 --- a/src/sound/oplsynth/opl_mus_player.h +++ b/src/sound/oplsynth/opl_mus_player.h @@ -1,7 +1,7 @@ #include "critsec.h" #include "musicblock.h" -class FileRdr; +class FileReader; class OPLmusicBlock : public musicBlock { @@ -34,7 +34,7 @@ protected: class OPLmusicFile : public OPLmusicBlock { public: - OPLmusicFile(FileRdr &reader); + OPLmusicFile(FileReader &reader); OPLmusicFile(const OPLmusicFile *source, const char *filename); virtual ~OPLmusicFile(); diff --git a/src/sound/sndfile_decoder.cpp b/src/sound/sndfile_decoder.cpp index ef24748aa5..f23ac23378 100644 --- a/src/sound/sndfile_decoder.cpp +++ b/src/sound/sndfile_decoder.cpp @@ -80,7 +80,7 @@ sf_count_t SndFileDecoder::file_seek(sf_count_t offset, int whence, void *user_d { auto &reader = reinterpret_cast(user_data)->Reader; - if(reader.Seek((long)offset, (FileRdr::ESeek)whence) != 0) + if(reader.Seek((long)offset, (FileReader::ESeek)whence) != 0) return -1; return reader.Tell(); } @@ -110,7 +110,7 @@ SndFileDecoder::~SndFileDecoder() SndFile = 0; } -bool SndFileDecoder::open(FileRdr &reader) +bool SndFileDecoder::open(FileReader &reader) { if (!IsSndFilePresent()) return false; diff --git a/src/sound/sndfile_decoder.h b/src/sound/sndfile_decoder.h index 12087a5bff..cbbcf8714f 100644 --- a/src/sound/sndfile_decoder.h +++ b/src/sound/sndfile_decoder.h @@ -26,13 +26,13 @@ struct SndFileDecoder : public SoundDecoder virtual ~SndFileDecoder(); protected: - virtual bool open(FileRdr &reader); + virtual bool open(FileReader &reader); private: SNDFILE *SndFile; SF_INFO SndInfo; - FileRdr Reader; + FileReader Reader; static sf_count_t file_get_filelen(void *user_data); static sf_count_t file_seek(sf_count_t offset, int whence, void *user_data); static sf_count_t file_read(void *ptr, sf_count_t count, void *user_data); diff --git a/src/sound/timidity/instrum_font.cpp b/src/sound/timidity/instrum_font.cpp index 680641b813..22fd5d50da 100644 --- a/src/sound/timidity/instrum_font.cpp +++ b/src/sound/timidity/instrum_font.cpp @@ -17,7 +17,7 @@ namespace Timidity FontFile *Fonts; extern std::unique_ptr gus_sfreader; -FontFile *ReadDLS(const char *filename, FileRdr &f) +FontFile *ReadDLS(const char *filename, FileReader &f) { return NULL; } @@ -57,7 +57,7 @@ void font_add(const char *filename, int load_order) } else { - FileRdr fp = gus_sfreader->LookupFile(filename).first; + FileReader fp = gus_sfreader->LookupFile(filename).first; if (fp.isOpen()) { diff --git a/src/sound/timidity/instrum_sf2.cpp b/src/sound/timidity/instrum_sf2.cpp index 69f6070326..dd7f8dd617 100644 --- a/src/sound/timidity/instrum_sf2.cpp +++ b/src/sound/timidity/instrum_sf2.cpp @@ -28,7 +28,7 @@ class CBadVer {}; struct ListHandler { uint32_t ID; - void (*Parser)(SFFile *sf2, FileRdr &f, uint32_t chunkid, uint32_t chunklen); + void (*Parser)(SFFile *sf2, FileReader &f, uint32_t chunkid, uint32_t chunklen); }; enum @@ -162,15 +162,15 @@ static const SFGenComposite DefaultGenerators = -1 // overridingRootKey }; -static void ParseIfil(SFFile *sf2, FileRdr &f, uint32_t chunkid, uint32_t chunklen); -static void ParseSmpl(SFFile *sf2, FileRdr &f, uint32_t chunkid, uint32_t chunklen); -static void ParseSm24(SFFile *sf2, FileRdr &f, uint32_t chunkid, uint32_t chunklen); -static void ParsePhdr(SFFile *sf2, FileRdr &f, uint32_t chunkid, uint32_t chunklen); -static void ParseBag(SFFile *sf2, FileRdr &f, uint32_t chunkid, uint32_t chunklen); -static void ParseMod(SFFile *sf2, FileRdr &f, uint32_t chunkid, uint32_t chunklen); -static void ParseGen(SFFile *sf2, FileRdr &f, uint32_t chunkid, uint32_t chunklen); -static void ParseInst(SFFile *sf2, FileRdr &f, uint32_t chunkid, uint32_t chunklen); -static void ParseShdr(SFFile *sf2, FileRdr &f, uint32_t chunkid, uint32_t chunklen); +static void ParseIfil(SFFile *sf2, FileReader &f, uint32_t chunkid, uint32_t chunklen); +static void ParseSmpl(SFFile *sf2, FileReader &f, uint32_t chunkid, uint32_t chunklen); +static void ParseSm24(SFFile *sf2, FileReader &f, uint32_t chunkid, uint32_t chunklen); +static void ParsePhdr(SFFile *sf2, FileReader &f, uint32_t chunkid, uint32_t chunklen); +static void ParseBag(SFFile *sf2, FileReader &f, uint32_t chunkid, uint32_t chunklen); +static void ParseMod(SFFile *sf2, FileReader &f, uint32_t chunkid, uint32_t chunklen); +static void ParseGen(SFFile *sf2, FileReader &f, uint32_t chunkid, uint32_t chunklen); +static void ParseInst(SFFile *sf2, FileReader &f, uint32_t chunkid, uint32_t chunklen); +static void ParseShdr(SFFile *sf2, FileReader &f, uint32_t chunkid, uint32_t chunklen); ListHandler INFOHandlers[] = { @@ -225,7 +225,7 @@ static int32_t calc_rate(Renderer *song, int diff, double sec) } -static inline uint32_t read_id(FileRdr &f) +static inline uint32_t read_id(FileReader &f) { uint32_t id; if (f.Read(&id, 4) != 4) @@ -235,7 +235,7 @@ static inline uint32_t read_id(FileRdr &f) return id; } -static inline int read_byte(FileRdr &f) +static inline int read_byte(FileReader &f) { uint8_t x; if (f.Read(&x, 1) != 1) @@ -245,7 +245,7 @@ static inline int read_byte(FileRdr &f) return x; } -static inline int read_char(FileRdr &f) +static inline int read_char(FileReader &f) { int8_t x; if (f.Read(&x, 1) != 1) @@ -255,7 +255,7 @@ static inline int read_char(FileRdr &f) return x; } -static inline int read_uword(FileRdr &f) +static inline int read_uword(FileReader &f) { uint16_t x; if (f.Read(&x, 2) != 2) @@ -265,7 +265,7 @@ static inline int read_uword(FileRdr &f) return LittleShort(x); } -static inline int read_sword(FileRdr &f) +static inline int read_sword(FileReader &f) { int16_t x; if (f.Read(&x, 2) != 2) @@ -275,7 +275,7 @@ static inline int read_sword(FileRdr &f) return LittleShort(x); } -static inline uint32_t read_dword(FileRdr &f) +static inline uint32_t read_dword(FileReader &f) { uint32_t x; if (f.Read(&x, 4) != 4) @@ -285,7 +285,7 @@ static inline uint32_t read_dword(FileRdr &f) return LittleLong(x); } -static inline void read_name(FileRdr &f, char name[21]) +static inline void read_name(FileReader &f, char name[21]) { if (f.Read(name, 20) != 20) { @@ -294,18 +294,18 @@ static inline void read_name(FileRdr &f, char name[21]) name[20] = 0; } -static inline void skip_chunk(FileRdr &f, uint32_t len) +static inline void skip_chunk(FileReader &f, uint32_t len) { // RIFF, like IFF, adds an extra pad byte to the end of // odd-sized chunks so that new chunks are always on even // byte boundaries. - if (f.Seek(len + (len & 1), FileRdr::SeekCur) != 0) + if (f.Seek(len + (len & 1), FileReader::SeekCur) != 0) { throw CIOErr(); } } -static void check_list(FileRdr &f, uint32_t id, uint32_t filelen, uint32_t &chunklen) +static void check_list(FileReader &f, uint32_t id, uint32_t filelen, uint32_t &chunklen) { if (read_id(f) != ID_LIST) { @@ -322,7 +322,7 @@ static void check_list(FileRdr &f, uint32_t id, uint32_t filelen, uint32_t &chun } } -static void ParseIfil(SFFile *sf2, FileRdr &f, uint32_t chunkid, uint32_t chunklen) +static void ParseIfil(SFFile *sf2, FileReader &f, uint32_t chunkid, uint32_t chunklen) { uint16_t major, minor; @@ -341,7 +341,7 @@ static void ParseIfil(SFFile *sf2, FileRdr &f, uint32_t chunkid, uint32_t chunkl sf2->MinorVersion = minor; } -static void ParseLIST(SFFile *sf2, FileRdr &f, uint32_t chunklen, ListHandler *handlers) +static void ParseLIST(SFFile *sf2, FileReader &f, uint32_t chunklen, ListHandler *handlers) { ListHandler *handler; uint32_t id; @@ -375,7 +375,7 @@ static void ParseLIST(SFFile *sf2, FileRdr &f, uint32_t chunklen, ListHandler *h } } -static void ParseINFO(SFFile *sf2, FileRdr &f, uint32_t chunklen) +static void ParseINFO(SFFile *sf2, FileReader &f, uint32_t chunklen) { sf2->MinorVersion = -1; @@ -387,7 +387,7 @@ static void ParseINFO(SFFile *sf2, FileRdr &f, uint32_t chunklen) } } -static void ParseSdta(SFFile *sf2, FileRdr &f, uint32_t chunklen) +static void ParseSdta(SFFile *sf2, FileReader &f, uint32_t chunklen) { ParseLIST(sf2, f, chunklen, SdtaHandlers); if (sf2->SampleDataOffset == 0) @@ -404,7 +404,7 @@ static void ParseSdta(SFFile *sf2, FileRdr &f, uint32_t chunklen) } } -static void ParseSmpl(SFFile *sf2, FileRdr &f, uint32_t chunkid, uint32_t chunklen) +static void ParseSmpl(SFFile *sf2, FileReader &f, uint32_t chunkid, uint32_t chunklen) { // Only use the first smpl chunk. (Or should we reject files with more than one?) if (sf2->SampleDataOffset == 0) @@ -419,7 +419,7 @@ static void ParseSmpl(SFFile *sf2, FileRdr &f, uint32_t chunkid, uint32_t chunkl skip_chunk(f, chunklen); } -static void ParseSm24(SFFile *sf2, FileRdr &f, uint32_t chunkid, uint32_t chunklen) +static void ParseSm24(SFFile *sf2, FileReader &f, uint32_t chunkid, uint32_t chunklen) { // The sm24 chunk is ignored if the file version is < 2.04 if (sf2->MinorVersion >= 4) @@ -434,12 +434,12 @@ static void ParseSm24(SFFile *sf2, FileRdr &f, uint32_t chunkid, uint32_t chunkl skip_chunk(f, chunklen); } -static void ParsePdta(SFFile *sf2, FileRdr &f, uint32_t chunklen) +static void ParsePdta(SFFile *sf2, FileReader &f, uint32_t chunklen) { ParseLIST(sf2, f, chunklen, PdtaHandlers); } -static void ParsePhdr(SFFile *sf2, FileRdr &f, uint32_t chunkid, uint32_t chunklen) +static void ParsePhdr(SFFile *sf2, FileReader &f, uint32_t chunkid, uint32_t chunklen) { SFPreset *preset; @@ -477,7 +477,7 @@ static void ParsePhdr(SFFile *sf2, FileRdr &f, uint32_t chunkid, uint32_t chunkl } } -static void ParseBag(SFFile *sf2, FileRdr &f, uint32_t chunkid, uint32_t chunklen) +static void ParseBag(SFFile *sf2, FileReader &f, uint32_t chunkid, uint32_t chunklen) { SFBag *bags, *bag; uint16_t prev_mod = 0; @@ -539,7 +539,7 @@ static void ParseBag(SFFile *sf2, FileRdr &f, uint32_t chunkid, uint32_t chunkle } } -static void ParseMod(SFFile *sf2, FileRdr &f, uint32_t chunkid, uint32_t chunklen) +static void ParseMod(SFFile *sf2, FileReader &f, uint32_t chunkid, uint32_t chunklen) { // Section 7.4, page 23: // It [the PMOD sub-chunk] is always a multiple of ten bytes in length, @@ -552,7 +552,7 @@ static void ParseMod(SFFile *sf2, FileRdr &f, uint32_t chunkid, uint32_t chunkle skip_chunk(f, chunklen); } -static void ParseGen(SFFile *sf2, FileRdr &f, uint32_t chunkid, uint32_t chunklen) +static void ParseGen(SFFile *sf2, FileReader &f, uint32_t chunkid, uint32_t chunklen) { SFGenList *gens, *gen; int numgens; @@ -604,7 +604,7 @@ static void ParseGen(SFFile *sf2, FileRdr &f, uint32_t chunkid, uint32_t chunkle } } -static void ParseInst(SFFile *sf2, FileRdr &f, uint32_t chunkid, uint32_t chunklen) +static void ParseInst(SFFile *sf2, FileReader &f, uint32_t chunkid, uint32_t chunklen) { int i; SFInst *inst; @@ -639,7 +639,7 @@ static void ParseInst(SFFile *sf2, FileRdr &f, uint32_t chunkid, uint32_t chunkl } } -static void ParseShdr(SFFile *sf2, FileRdr &f, uint32_t chunkid, uint32_t chunklen) +static void ParseShdr(SFFile *sf2, FileReader &f, uint32_t chunkid, uint32_t chunklen) { int i; SFSample *sample; @@ -698,7 +698,7 @@ static void ParseShdr(SFFile *sf2, FileRdr &f, uint32_t chunkid, uint32_t chunkl } -SFFile *ReadSF2(const char *filename, FileRdr &f) +SFFile *ReadSF2(const char *filename, FileReader &f) { SFFile *sf2 = NULL; uint32_t filelen; @@ -1508,7 +1508,7 @@ void SFFile::ApplyGeneratorsToRegion(SFGenComposite *gen, SFSample *sfsamp, Rend void SFFile::LoadSample(SFSample *sample) { - FileRdr fp = gus_sfreader->LookupFile(Filename).first; + FileReader fp = gus_sfreader->LookupFile(Filename).first; uint32_t i; if (!fp.isOpen()) @@ -1516,7 +1516,7 @@ void SFFile::LoadSample(SFSample *sample) return; } sample->InMemoryData = new float[sample->End - sample->Start + 1]; - fp.Seek(SampleDataOffset + sample->Start * 2, FileRdr::SeekSet); + fp.Seek(SampleDataOffset + sample->Start * 2, FileReader::SeekSet); // Load 16-bit sample data. for (i = 0; i < sample->End - sample->Start; ++i) { @@ -1525,7 +1525,7 @@ void SFFile::LoadSample(SFSample *sample) } if (SampleDataLSBOffset != 0) { // Load lower 8 bits of 24-bit sample data. - fp.Seek(SampleDataLSBOffset + sample->Start, FileRdr::SeekSet); + fp.Seek(SampleDataLSBOffset + sample->Start, FileReader::SeekSet); for (i = 0; i < sample->End - sample->Start; ++i) { uint8_t samp = fp.ReadUInt8(); diff --git a/src/sound/timidity/sf2.h b/src/sound/timidity/sf2.h index ada4ff2020..c68cd24adf 100644 --- a/src/sound/timidity/sf2.h +++ b/src/sound/timidity/sf2.h @@ -315,4 +315,4 @@ struct SFFile : public Timidity::FontFile int NumSamples; }; -SFFile *ReadSF2(const char *filename, FileRdr &f); +SFFile *ReadSF2(const char *filename, FileReader &f); diff --git a/src/sound/timidity/timidity.cpp b/src/sound/timidity/timidity.cpp index 34f66b248f..104407e2a3 100644 --- a/src/sound/timidity/timidity.cpp +++ b/src/sound/timidity/timidity.cpp @@ -82,7 +82,7 @@ static bool InitReader(const char *config_file) static int read_config_file(const char *name, bool ismain) { - FileRdr fp; + FileReader fp; char tmp[1024], *cp; ToneBank *bank = NULL; int i, j, k, line = 0, words; @@ -596,7 +596,7 @@ int LoadDMXGUS() int status = -1; int gusbank = (gus_memsize >= 1 && gus_memsize <= 4) ? gus_memsize : -1; - data.Seek(0, FileRdr::SeekSet); + data.Seek(0, FileReader::SeekSet); while (data.Gets(readbuffer, 1024) && read < size) { diff --git a/src/sound/timidity/timidity.h b/src/sound/timidity/timidity.h index 710aecc558..f297f35bb7 100644 --- a/src/sound/timidity/timidity.h +++ b/src/sound/timidity/timidity.h @@ -361,7 +361,7 @@ void font_order(int order, int bank, int preset, int keynote); Instrument *load_instrument_font(struct Renderer *song, const char *font, int drum, int bank, int instrument); Instrument *load_instrument_font_order(struct Renderer *song, int order, int drum, int bank, int instrument); -FontFile *ReadDLS(const char *filename, FileRdr &f); +FontFile *ReadDLS(const char *filename, FileReader &f); /* mix.h diff --git a/src/sound/timiditypp/common.cpp b/src/sound/timiditypp/common.cpp index 62f331c870..77df91798a 100644 --- a/src/sound/timiditypp/common.cpp +++ b/src/sound/timiditypp/common.cpp @@ -130,7 +130,7 @@ double flt_rand() struct timidity_file *open_file(const char *name, FSoundFontReader *sfreader) { - FileRdr fr; + FileReader fr; FString filename; if (name == nullptr) { @@ -161,7 +161,7 @@ void tf_close(struct timidity_file *tf) /* This is meant for skipping a few bytes. */ void skip(struct timidity_file *tf, size_t len) { - tf->url.Seek((long)len, FileRdr::SeekCur); + tf->url.Seek((long)len, FileReader::SeekCur); } char *tf_gets(char *buff, int n, struct timidity_file *tf) @@ -184,7 +184,7 @@ long tf_read(void *buff, int32_t size, int32_t nitems, struct timidity_file *tf) long tf_seek(struct timidity_file *tf, long offset, int whence) { - return (long)tf->url.Seek(offset, (FileRdr::ESeek)whence); + return (long)tf->url.Seek(offset, (FileReader::ESeek)whence); } long tf_tell(struct timidity_file *tf) diff --git a/src/sound/timiditypp/common.h b/src/sound/timiditypp/common.h index c0d721a567..74c7070df1 100644 --- a/src/sound/timiditypp/common.h +++ b/src/sound/timiditypp/common.h @@ -35,7 +35,7 @@ namespace TimidityPlus struct timidity_file { - FileRdr url; + FileReader url; std::string filename; }; diff --git a/src/sound/wildmidi/file_io.cpp b/src/sound/wildmidi/file_io.cpp index 6d20ccba5c..b1d3d2dd5e 100644 --- a/src/sound/wildmidi/file_io.cpp +++ b/src/sound/wildmidi/file_io.cpp @@ -60,7 +60,7 @@ bool _WM_InitReader(const char *config_file) unsigned char *_WM_BufferFile(const char *filename, unsigned long int *size) { - FileRdr fp; + FileReader fp; if (filename == nullptr) { diff --git a/src/sound/wildmidi/wildmidi_lib.cpp b/src/sound/wildmidi/wildmidi_lib.cpp index ee0f085eee..f4b4a254c1 100644 --- a/src/sound/wildmidi/wildmidi_lib.cpp +++ b/src/sound/wildmidi/wildmidi_lib.cpp @@ -676,7 +676,7 @@ static int WM_LoadConfig(const char *config_file, bool main) { int token_count = 0; auto config_parm = config_file; - FileRdr fr; + FileReader fr; if (main) { if (!_WM_InitReader(config_file)) return -1; // unable to open this as a config file. diff --git a/src/textures/automaptexture.cpp b/src/textures/automaptexture.cpp index 1f17b239ae..3bd16f5bca 100644 --- a/src/textures/automaptexture.cpp +++ b/src/textures/automaptexture.cpp @@ -72,7 +72,7 @@ private: // //========================================================================== -FTexture *AutomapTexture_TryCreate(FileRdr &data, int lumpnum) +FTexture *AutomapTexture_TryCreate(FileReader &data, int lumpnum) { if (data.GetLength() < 320) return NULL; if (!Wads.CheckLumpName(lumpnum, "AUTOPAGE")) return NULL; diff --git a/src/textures/buildtexture.cpp b/src/textures/buildtexture.cpp index 78d606a7ef..dd95455531 100644 --- a/src/textures/buildtexture.cpp +++ b/src/textures/buildtexture.cpp @@ -306,7 +306,7 @@ int FTextureManager::CountBuildTiles () FString artpath = rffpath; artpath += artfile; - FileRdr fr; + FileReader fr; if (!fr.OpenFile(artpath)) { diff --git a/src/textures/ddstexture.cpp b/src/textures/ddstexture.cpp index e3b645424b..9cde88ced8 100644 --- a/src/textures/ddstexture.cpp +++ b/src/textures/ddstexture.cpp @@ -156,7 +156,7 @@ struct DDSFileHeader class FDDSTexture : public FTexture { public: - FDDSTexture (FileRdr &lump, int lumpnum, void *surfdesc); + FDDSTexture (FileReader &lump, int lumpnum, void *surfdesc); ~FDDSTexture (); const uint8_t *GetColumn (unsigned int column, const Span **spans_out); @@ -181,10 +181,10 @@ protected: static void CalcBitShift (uint32_t mask, uint8_t *lshift, uint8_t *rshift); void MakeTexture (); - void ReadRGB (FileRdr &lump, uint8_t *tcbuf = NULL); - void DecompressDXT1 (FileRdr &lump, uint8_t *tcbuf = NULL); - void DecompressDXT3 (FileRdr &lump, bool premultiplied, uint8_t *tcbuf = NULL); - void DecompressDXT5 (FileRdr &lump, bool premultiplied, uint8_t *tcbuf = NULL); + void ReadRGB (FileReader &lump, uint8_t *tcbuf = NULL); + void DecompressDXT1 (FileReader &lump, uint8_t *tcbuf = NULL); + void DecompressDXT3 (FileReader &lump, bool premultiplied, uint8_t *tcbuf = NULL); + void DecompressDXT5 (FileReader &lump, bool premultiplied, uint8_t *tcbuf = NULL); int CopyTrueColorPixels(FBitmap *bmp, int x, int y, int rotate, FCopyInfo *inf = NULL); bool UseBasePalette(); @@ -199,11 +199,11 @@ protected: // //========================================================================== -static bool CheckDDS (FileRdr &file) +static bool CheckDDS (FileReader &file) { DDSFileHeader Header; - file.Seek(0, FileRdr::SeekSet); + file.Seek(0, FileReader::SeekSet); if (file.Read (&Header, sizeof(Header)) != sizeof(Header)) { return false; @@ -222,7 +222,7 @@ static bool CheckDDS (FileRdr &file) // //========================================================================== -FTexture *DDSTexture_TryCreate (FileRdr &data, int lumpnum) +FTexture *DDSTexture_TryCreate (FileReader &data, int lumpnum) { union { @@ -232,7 +232,7 @@ FTexture *DDSTexture_TryCreate (FileRdr &data, int lumpnum) if (!CheckDDS(data)) return NULL; - data.Seek(4, FileRdr::SeekSet); + data.Seek(4, FileReader::SeekSet); data.Read (&surfdesc, sizeof(surfdesc)); #ifdef __BIG_ENDIAN__ @@ -286,7 +286,7 @@ FTexture *DDSTexture_TryCreate (FileRdr &data, int lumpnum) // //========================================================================== -FDDSTexture::FDDSTexture (FileRdr &lump, int lumpnum, void *vsurfdesc) +FDDSTexture::FDDSTexture (FileReader &lump, int lumpnum, void *vsurfdesc) : FTexture(NULL, lumpnum), Pixels(0), Spans(0) { DDSURFACEDESC2 *surf = (DDSURFACEDESC2 *)vsurfdesc; @@ -492,7 +492,7 @@ void FDDSTexture::MakeTexture () Pixels = new uint8_t[Width*Height]; - lump.Seek (sizeof(DDSURFACEDESC2) + 4, FileRdr::SeekSet); + lump.Seek (sizeof(DDSURFACEDESC2) + 4, FileReader::SeekSet); if (Format >= 1 && Format <= 4) // RGB: Format is # of bytes per pixel { @@ -518,7 +518,7 @@ void FDDSTexture::MakeTexture () // //========================================================================== -void FDDSTexture::ReadRGB (FileRdr &lump, uint8_t *tcbuf) +void FDDSTexture::ReadRGB (FileReader &lump, uint8_t *tcbuf) { uint32_t x, y; uint32_t amask = AMask == 0 ? 0 : 0x80000000 >> AShiftL; @@ -587,7 +587,7 @@ void FDDSTexture::ReadRGB (FileRdr &lump, uint8_t *tcbuf) // //========================================================================== -void FDDSTexture::DecompressDXT1 (FileRdr &lump, uint8_t *tcbuf) +void FDDSTexture::DecompressDXT1 (FileReader &lump, uint8_t *tcbuf) { const long blocklinelen = ((Width + 3) >> 2) << 3; uint8_t *blockbuff = new uint8_t[blocklinelen]; @@ -685,7 +685,7 @@ void FDDSTexture::DecompressDXT1 (FileRdr &lump, uint8_t *tcbuf) // //========================================================================== -void FDDSTexture::DecompressDXT3 (FileRdr &lump, bool premultiplied, uint8_t *tcbuf) +void FDDSTexture::DecompressDXT3 (FileReader &lump, bool premultiplied, uint8_t *tcbuf) { const long blocklinelen = ((Width + 3) >> 2) << 4; uint8_t *blockbuff = new uint8_t[blocklinelen]; @@ -767,7 +767,7 @@ void FDDSTexture::DecompressDXT3 (FileRdr &lump, bool premultiplied, uint8_t *tc // //========================================================================== -void FDDSTexture::DecompressDXT5 (FileRdr &lump, bool premultiplied, uint8_t *tcbuf) +void FDDSTexture::DecompressDXT5 (FileReader &lump, bool premultiplied, uint8_t *tcbuf) { const long blocklinelen = ((Width + 3) >> 2) << 4; uint8_t *blockbuff = new uint8_t[blocklinelen]; @@ -885,7 +885,7 @@ int FDDSTexture::CopyTrueColorPixels(FBitmap *bmp, int x, int y, int rotate, FCo uint8_t *TexBuffer = new uint8_t[4*Width*Height]; - lump.Seek (sizeof(DDSURFACEDESC2) + 4, FileRdr::SeekSet); + lump.Seek (sizeof(DDSURFACEDESC2) + 4, FileReader::SeekSet); if (Format >= 1 && Format <= 4) // RGB: Format is # of bytes per pixel { diff --git a/src/textures/emptytexture.cpp b/src/textures/emptytexture.cpp index ce72656584..45039cae29 100644 --- a/src/textures/emptytexture.cpp +++ b/src/textures/emptytexture.cpp @@ -68,11 +68,11 @@ protected: // //========================================================================== -FTexture *EmptyTexture_TryCreate(FileRdr & file, int lumpnum) +FTexture *EmptyTexture_TryCreate(FileReader & file, int lumpnum) { char check[8]; if (file.GetLength() != 8) return NULL; - file.Seek(0, FileRdr::SeekSet); + file.Seek(0, FileReader::SeekSet); if (file.Read(check, 8) != 8) return NULL; if (memcmp(check, "\0\0\0\0\0\0\0\0", 8)) return NULL; diff --git a/src/textures/flattexture.cpp b/src/textures/flattexture.cpp index 18105c947a..408acb0997 100644 --- a/src/textures/flattexture.cpp +++ b/src/textures/flattexture.cpp @@ -74,7 +74,7 @@ protected: // //========================================================================== -FTexture *FlatTexture_TryCreate(FileRdr & file, int lumpnum) +FTexture *FlatTexture_TryCreate(FileReader & file, int lumpnum) { return new FFlatTexture(lumpnum); } diff --git a/src/textures/imgztexture.cpp b/src/textures/imgztexture.cpp index 91b7b74405..1f623d084f 100644 --- a/src/textures/imgztexture.cpp +++ b/src/textures/imgztexture.cpp @@ -83,13 +83,13 @@ protected: // //========================================================================== -FTexture *IMGZTexture_TryCreate(FileRdr & file, int lumpnum) +FTexture *IMGZTexture_TryCreate(FileReader & file, int lumpnum) { uint32_t magic = 0; uint16_t w, h; int16_t l, t; - file.Seek(0, FileRdr::SeekSet); + file.Seek(0, FileReader::SeekSet); if (file.Read(&magic, 4) != 4) return NULL; if (magic != MAKE_ID('I','M','G','Z')) return NULL; w = file.ReadUInt16(); diff --git a/src/textures/jpegtexture.cpp b/src/textures/jpegtexture.cpp index f8bc836146..c9f19c1daf 100644 --- a/src/textures/jpegtexture.cpp +++ b/src/textures/jpegtexture.cpp @@ -50,11 +50,11 @@ extern "C" struct FLumpSourceMgr : public jpeg_source_mgr { - FileRdr *Lump; + FileReader *Lump; JOCTET Buffer[4096]; bool StartOfFile; - FLumpSourceMgr (FileRdr *lump, j_decompress_ptr cinfo); + FLumpSourceMgr (FileReader *lump, j_decompress_ptr cinfo); static void InitSource (j_decompress_ptr cinfo); static boolean FillInputBuffer (j_decompress_ptr cinfo); static void SkipInputData (j_decompress_ptr cinfo, long num_bytes); @@ -113,7 +113,7 @@ void FLumpSourceMgr::SkipInputData (j_decompress_ptr cinfo, long num_bytes) else { num_bytes -= (long)me->bytes_in_buffer; - me->Lump->Seek (num_bytes, FileRdr::SeekCur); + me->Lump->Seek (num_bytes, FileReader::SeekCur); FillInputBuffer (cinfo); } } @@ -134,7 +134,7 @@ void FLumpSourceMgr::TermSource (j_decompress_ptr cinfo) // //========================================================================== -FLumpSourceMgr::FLumpSourceMgr (FileRdr *lump, j_decompress_ptr cinfo) +FLumpSourceMgr::FLumpSourceMgr (FileReader *lump, j_decompress_ptr cinfo) : Lump (lump) { cinfo->src = this; @@ -208,7 +208,7 @@ protected: // //========================================================================== -FTexture *JPEGTexture_TryCreate(FileRdr & data, int lumpnum) +FTexture *JPEGTexture_TryCreate(FileReader & data, int lumpnum) { union { @@ -217,7 +217,7 @@ FTexture *JPEGTexture_TryCreate(FileRdr & data, int lumpnum) uint8_t b[4]; } first4bytes; - data.Seek(0, FileRdr::SeekSet); + data.Seek(0, FileReader::SeekSet); if (data.Read(&first4bytes, 4) < 4) return NULL; if (first4bytes.b[0] != 0xFF || first4bytes.b[1] != 0xD8 || first4bytes.b[2] != 0xFF) @@ -231,7 +231,7 @@ FTexture *JPEGTexture_TryCreate(FileRdr & data, int lumpnum) { return NULL; } - data.Seek (BigShort(first4bytes.w[0]) - 2, FileRdr::SeekCur); + data.Seek (BigShort(first4bytes.w[0]) - 2, FileReader::SeekCur); if (data.Read (first4bytes.b + 2, 2) != 2 || first4bytes.b[2] != 0xFF) { return NULL; diff --git a/src/textures/patchtexture.cpp b/src/textures/patchtexture.cpp index 4e8268c094..c964b9a53d 100644 --- a/src/textures/patchtexture.cpp +++ b/src/textures/patchtexture.cpp @@ -81,12 +81,12 @@ protected: // //========================================================================== -static bool CheckIfPatch(FileRdr & file) +static bool CheckIfPatch(FileReader & file) { if (file.GetLength() < 13) return false; // minimum length of a valid Doom patch uint8_t *data = new uint8_t[file.GetLength()]; - file.Seek(0, FileRdr::SeekSet); + file.Seek(0, FileReader::SeekSet); file.Read(data, file.GetLength()); const patch_t *foo = (const patch_t *)data; @@ -129,12 +129,12 @@ static bool CheckIfPatch(FileRdr & file) // //========================================================================== -FTexture *PatchTexture_TryCreate(FileRdr & file, int lumpnum) +FTexture *PatchTexture_TryCreate(FileReader & file, int lumpnum) { patch_t header; if (!CheckIfPatch(file)) return NULL; - file.Seek(0, FileRdr::SeekSet); + file.Seek(0, FileReader::SeekSet); header.width = file.ReadUInt16(); header.height = file.ReadUInt16(); header.leftoffset = file.ReadInt16(); diff --git a/src/textures/pcxtexture.cpp b/src/textures/pcxtexture.cpp index 4d7dbdae70..75331caa50 100644 --- a/src/textures/pcxtexture.cpp +++ b/src/textures/pcxtexture.cpp @@ -99,10 +99,10 @@ protected: uint8_t *Pixels; Span DummySpans[2]; - void ReadPCX1bit (uint8_t *dst, FileRdr & lump, PCXHeader *hdr); - void ReadPCX4bits (uint8_t *dst, FileRdr & lump, PCXHeader *hdr); - void ReadPCX8bits (uint8_t *dst, FileRdr & lump, PCXHeader *hdr); - void ReadPCX24bits (uint8_t *dst, FileRdr & lump, PCXHeader *hdr, int planes); + void ReadPCX1bit (uint8_t *dst, FileReader & lump, PCXHeader *hdr); + void ReadPCX4bits (uint8_t *dst, FileReader & lump, PCXHeader *hdr); + void ReadPCX8bits (uint8_t *dst, FileReader & lump, PCXHeader *hdr); + void ReadPCX24bits (uint8_t *dst, FileReader & lump, PCXHeader *hdr, int planes); virtual void MakeTexture (); @@ -116,11 +116,11 @@ protected: // //========================================================================== -FTexture * PCXTexture_TryCreate(FileRdr & file, int lumpnum) +FTexture * PCXTexture_TryCreate(FileReader & file, int lumpnum) { PCXHeader hdr; - file.Seek(0, FileRdr::SeekSet); + file.Seek(0, FileReader::SeekSet); if (file.Read(&hdr, sizeof(hdr)) != sizeof(hdr)) { return NULL; @@ -141,7 +141,7 @@ FTexture * PCXTexture_TryCreate(FileRdr & file, int lumpnum) if (hdr.padding[i] != 0) return NULL; } - file.Seek(0, FileRdr::SeekSet); + file.Seek(0, FileReader::SeekSet); file.Read(&hdr, sizeof(hdr)); return new FPCXTexture(lumpnum, hdr); @@ -256,7 +256,7 @@ const uint8_t *FPCXTexture::GetPixels () // //========================================================================== -void FPCXTexture::ReadPCX1bit (uint8_t *dst, FileRdr & lump, PCXHeader *hdr) +void FPCXTexture::ReadPCX1bit (uint8_t *dst, FileReader & lump, PCXHeader *hdr) { int y, i, bytes; int rle_count = 0; @@ -304,7 +304,7 @@ void FPCXTexture::ReadPCX1bit (uint8_t *dst, FileRdr & lump, PCXHeader *hdr) // //========================================================================== -void FPCXTexture::ReadPCX4bits (uint8_t *dst, FileRdr & lump, PCXHeader *hdr) +void FPCXTexture::ReadPCX4bits (uint8_t *dst, FileReader & lump, PCXHeader *hdr) { int rle_count = 0, rle_value = 0; int x, y, c; @@ -367,7 +367,7 @@ void FPCXTexture::ReadPCX4bits (uint8_t *dst, FileRdr & lump, PCXHeader *hdr) // //========================================================================== -void FPCXTexture::ReadPCX8bits (uint8_t *dst, FileRdr & lump, PCXHeader *hdr) +void FPCXTexture::ReadPCX8bits (uint8_t *dst, FileReader & lump, PCXHeader *hdr) { int rle_count = 0, rle_value = 0; int y, bytes; @@ -409,7 +409,7 @@ void FPCXTexture::ReadPCX8bits (uint8_t *dst, FileRdr & lump, PCXHeader *hdr) // //========================================================================== -void FPCXTexture::ReadPCX24bits (uint8_t *dst, FileRdr & lump, PCXHeader *hdr, int planes) +void FPCXTexture::ReadPCX24bits (uint8_t *dst, FileReader & lump, PCXHeader *hdr, int planes) { int rle_count = 0, rle_value = 0; int y, c; @@ -493,7 +493,7 @@ void FPCXTexture::MakeTexture() } else if (bitcount == 8) { - lump.Seek(-769, FileRdr::SeekEnd); + lump.Seek(-769, FileReader::SeekEnd); uint8_t c = lump.ReadUInt8(); //if (c !=0x0c) memcpy(PaletteMap, GrayMap, 256); // Fallback for files without palette //else @@ -504,7 +504,7 @@ void FPCXTexture::MakeTexture() uint8_t b = lump.ReadUInt8(); PaletteMap[i] = ColorMatcher.Pick(r,g,b); } - lump.Seek(sizeof(header), FileRdr::SeekSet); + lump.Seek(sizeof(header), FileReader::SeekSet); ReadPCX8bits (Pixels, lump, &header); } if (Width == Height) @@ -582,7 +582,7 @@ int FPCXTexture::CopyTrueColorPixels(FBitmap *bmp, int x, int y, int rotate, FCo } else if (bitcount == 8) { - lump.Seek(-769, FileRdr::SeekEnd); + lump.Seek(-769, FileReader::SeekEnd); uint8_t c = lump.ReadUInt8(); c=0x0c; // Apparently there's many non-compliant PCXs out there... if (c !=0x0c) @@ -596,7 +596,7 @@ int FPCXTexture::CopyTrueColorPixels(FBitmap *bmp, int x, int y, int rotate, FCo uint8_t b = lump.ReadUInt8(); pe[i] = PalEntry(255, r,g,b); } - lump.Seek(sizeof(header), FileRdr::SeekSet); + lump.Seek(sizeof(header), FileReader::SeekSet); ReadPCX8bits (Pixels, lump, &header); } bmp->CopyPixelData(x, y, Pixels, Width, Height, 1, Width, rotate, pe, inf); diff --git a/src/textures/pngtexture.cpp b/src/textures/pngtexture.cpp index b187339be7..480502c33f 100644 --- a/src/textures/pngtexture.cpp +++ b/src/textures/pngtexture.cpp @@ -51,7 +51,7 @@ class FPNGTexture : public FTexture { public: - FPNGTexture (FileRdr &lump, int lumpnum, const FString &filename, int width, int height, uint8_t bitdepth, uint8_t colortype, uint8_t interlace); + FPNGTexture (FileReader &lump, int lumpnum, const FString &filename, int width, int height, uint8_t bitdepth, uint8_t colortype, uint8_t interlace); ~FPNGTexture (); const uint8_t *GetColumn (unsigned int column, const Span **spans_out); @@ -66,7 +66,7 @@ protected: FString SourceFile; uint8_t *Pixels; Span **Spans; - FileRdr fr; + FileReader fr; uint8_t BitDepth; uint8_t ColorType; @@ -90,7 +90,7 @@ protected: // //========================================================================== -FTexture *PNGTexture_TryCreate(FileRdr & data, int lumpnum) +FTexture *PNGTexture_TryCreate(FileReader & data, int lumpnum) { union { @@ -104,7 +104,7 @@ FTexture *PNGTexture_TryCreate(FileRdr & data, int lumpnum) // first 4 bytes match, but later bytes don't, we assume it's // a corrupt PNG.) - data.Seek(0, FileRdr::SeekSet); + data.Seek(0, FileReader::SeekSet); if (data.Read (first4bytes.b, 4) != 4) return NULL; if (first4bytes.dw != MAKE_ID(137,'P','N','G')) return NULL; if (data.Read (first4bytes.b, 4) != 4) return NULL; @@ -138,7 +138,7 @@ FTexture *PNGTexture_TryCreate(FileRdr & data, int lumpnum) } // Just for completeness, make sure the PNG has something more than an IHDR. - data.Seek (4, FileRdr::SeekSet); + data.Seek (4, FileReader::SeekSet); data.Read (first4bytes.b, 4); if (first4bytes.dw == 0) { @@ -198,7 +198,7 @@ FTexture *PNGTexture_CreateFromFile(PNGHandle *png, const FString &filename) // //========================================================================== -FPNGTexture::FPNGTexture (FileRdr &lump, int lumpnum, const FString &filename, int width, int height, +FPNGTexture::FPNGTexture (FileReader &lump, int lumpnum, const FString &filename, int width, int height, uint8_t depth, uint8_t colortype, uint8_t interlace) : FTexture(NULL, lumpnum), SourceFile(filename), Pixels(0), Spans(0), BitDepth(depth), ColorType(colortype), Interlace(interlace), HaveTrans(false), @@ -225,7 +225,7 @@ FPNGTexture::FPNGTexture (FileRdr &lump, int lumpnum, const FString &filename, i memset(trans, 255, 256); // Parse pre-IDAT chunks. I skip the CRCs. Is that bad? - lump.Seek(33, FileRdr::SeekSet); + lump.Seek(33, FileReader::SeekSet); lump.Read(&len, 4); lump.Read(&id, 4); @@ -235,7 +235,7 @@ FPNGTexture::FPNGTexture (FileRdr &lump, int lumpnum, const FString &filename, i switch (id) { default: - lump.Seek (len, FileRdr::SeekCur); + lump.Seek (len, FileReader::SeekCur); break; case MAKE_ID('g','r','A','b'): @@ -268,7 +268,7 @@ FPNGTexture::FPNGTexture (FileRdr &lump, int lumpnum, const FString &filename, i lump.Read (p.pngpal, PaletteSize * 3); if (PaletteSize * 3 != (int)len) { - lump.Seek (len - PaletteSize * 3, FileRdr::SeekCur); + lump.Seek (len - PaletteSize * 3, FileReader::SeekCur); } for (i = PaletteSize - 1; i >= 0; --i) { @@ -290,7 +290,7 @@ FPNGTexture::FPNGTexture (FileRdr &lump, int lumpnum, const FString &filename, i bMasked = true; break; } - lump.Seek(4, FileRdr::SeekCur); // Skip CRC + lump.Seek(4, FileReader::SeekCur); // Skip CRC lump.Read(&len, 4); id = MAKE_ID('I','E','N','D'); lump.Read(&id, 4); @@ -459,8 +459,8 @@ const uint8_t *FPNGTexture::GetPixels () void FPNGTexture::MakeTexture () { - FileRdr *lump; - FileRdr lfr; + FileReader *lump; + FileReader lfr; if (SourceLump >= 0) { @@ -480,7 +480,7 @@ void FPNGTexture::MakeTexture () else { uint32_t len, id; - lump->Seek (StartOfIDAT, FileRdr::SeekSet); + lump->Seek (StartOfIDAT, FileReader::SeekSet); lump->Read(&len, 4); lump->Read(&id, 4); @@ -623,8 +623,8 @@ int FPNGTexture::CopyTrueColorPixels(FBitmap *bmp, int x, int y, int rotate, FCo int pixwidth = Width * bpp[ColorType]; int transpal = false; - FileRdr *lump; - FileRdr lfr; + FileReader *lump; + FileReader lfr; if (SourceLump >= 0) { @@ -636,7 +636,7 @@ int FPNGTexture::CopyTrueColorPixels(FBitmap *bmp, int x, int y, int rotate, FCo lump = &fr; } - lump->Seek(33, FileRdr::SeekSet); + lump->Seek(33, FileReader::SeekSet); for(int i = 0; i < 256; i++) // default to a gray map pe[i] = PalEntry(255,i,i,i); @@ -648,7 +648,7 @@ int FPNGTexture::CopyTrueColorPixels(FBitmap *bmp, int x, int y, int rotate, FCo switch (id) { default: - lump->Seek (len, FileRdr::SeekCur); + lump->Seek (len, FileReader::SeekCur); break; case MAKE_ID('P','L','T','E'): @@ -672,11 +672,11 @@ int FPNGTexture::CopyTrueColorPixels(FBitmap *bmp, int x, int y, int rotate, FCo } else { - lump->Seek(len, FileRdr::SeekCur); + lump->Seek(len, FileReader::SeekCur); } break; } - lump->Seek(4, FileRdr::SeekCur); // Skip CRC + lump->Seek(4, FileReader::SeekCur); // Skip CRC lump->Read(&len, 4); id = MAKE_ID('I','E','N','D'); lump->Read(&id, 4); @@ -690,7 +690,7 @@ int FPNGTexture::CopyTrueColorPixels(FBitmap *bmp, int x, int y, int rotate, FCo uint8_t * Pixels = new uint8_t[pixwidth * Height]; - lump->Seek (StartOfIDAT, FileRdr::SeekSet); + lump->Seek (StartOfIDAT, FileReader::SeekSet); lump->Read(&len, 4); lump->Read(&id, 4); M_ReadIDAT (*lump, Pixels, Width, Height, pixwidth, BitDepth, ColorType, Interlace, BigLong((unsigned int)len)); diff --git a/src/textures/rawpagetexture.cpp b/src/textures/rawpagetexture.cpp index 834a4c7ab4..99354bb66c 100644 --- a/src/textures/rawpagetexture.cpp +++ b/src/textures/rawpagetexture.cpp @@ -70,7 +70,7 @@ protected: // //========================================================================== -static bool CheckIfRaw(FileRdr & data) +static bool CheckIfRaw(FileReader & data) { if (data.GetLength() != 64000) return false; @@ -80,7 +80,7 @@ static bool CheckIfRaw(FileRdr & data) int width; foo = (patch_t *)M_Malloc (data.GetLength()); - data.Seek (0, FileRdr::SeekSet); + data.Seek (0, FileReader::SeekSet); data.Read (foo, data.GetLength()); height = LittleShort(foo->height); @@ -148,7 +148,7 @@ static bool CheckIfRaw(FileRdr & data) // //========================================================================== -FTexture *RawPageTexture_TryCreate(FileRdr & file, int lumpnum) +FTexture *RawPageTexture_TryCreate(FileReader & file, int lumpnum) { if (!CheckIfRaw(file)) return NULL; return new FRawPageTexture(lumpnum); diff --git a/src/textures/texture.cpp b/src/textures/texture.cpp index 69c1ee5ef4..212f53a031 100644 --- a/src/textures/texture.cpp +++ b/src/textures/texture.cpp @@ -47,7 +47,7 @@ #include "textures/textures.h" #include "v_palette.h" -typedef FTexture * (*CreateFunc)(FileRdr & file, int lumpnum); +typedef FTexture * (*CreateFunc)(FileReader & file, int lumpnum); struct TexCreateInfo { @@ -65,17 +65,17 @@ void FTexture::InitGrayMap() } } -FTexture *IMGZTexture_TryCreate(FileRdr &, int lumpnum); -FTexture *PNGTexture_TryCreate(FileRdr &, int lumpnum); -FTexture *JPEGTexture_TryCreate(FileRdr &, int lumpnum); -FTexture *DDSTexture_TryCreate(FileRdr &, int lumpnum); -FTexture *PCXTexture_TryCreate(FileRdr &, int lumpnum); -FTexture *TGATexture_TryCreate(FileRdr &, int lumpnum); -FTexture *RawPageTexture_TryCreate(FileRdr &, int lumpnum); -FTexture *FlatTexture_TryCreate(FileRdr &, int lumpnum); -FTexture *PatchTexture_TryCreate(FileRdr &, int lumpnum); -FTexture *EmptyTexture_TryCreate(FileRdr &, int lumpnum); -FTexture *AutomapTexture_TryCreate(FileRdr &, int lumpnum); +FTexture *IMGZTexture_TryCreate(FileReader &, int lumpnum); +FTexture *PNGTexture_TryCreate(FileReader &, int lumpnum); +FTexture *JPEGTexture_TryCreate(FileReader &, int lumpnum); +FTexture *DDSTexture_TryCreate(FileReader &, int lumpnum); +FTexture *PCXTexture_TryCreate(FileReader &, int lumpnum); +FTexture *TGATexture_TryCreate(FileReader &, int lumpnum); +FTexture *RawPageTexture_TryCreate(FileReader &, int lumpnum); +FTexture *FlatTexture_TryCreate(FileReader &, int lumpnum); +FTexture *PatchTexture_TryCreate(FileReader &, int lumpnum); +FTexture *EmptyTexture_TryCreate(FileReader &, int lumpnum); +FTexture *AutomapTexture_TryCreate(FileReader &, int lumpnum); // Examines the lump contents to decide what type of texture to create, diff --git a/src/textures/tgatexture.cpp b/src/textures/tgatexture.cpp index 1355397210..97e381e6b3 100644 --- a/src/textures/tgatexture.cpp +++ b/src/textures/tgatexture.cpp @@ -94,7 +94,7 @@ protected: uint8_t *Pixels; Span **Spans; - void ReadCompressed(FileRdr &lump, uint8_t * buffer, int bytesperpixel); + void ReadCompressed(FileReader &lump, uint8_t * buffer, int bytesperpixel); virtual void MakeTexture (); @@ -107,13 +107,13 @@ protected: // //========================================================================== -FTexture *TGATexture_TryCreate(FileRdr & file, int lumpnum) +FTexture *TGATexture_TryCreate(FileReader & file, int lumpnum) { TGAHeader hdr; if (file.GetLength() < (long)sizeof(hdr)) return NULL; - file.Seek(0, FileRdr::SeekSet); + file.Seek(0, FileReader::SeekSet); file.Read(&hdr, sizeof(hdr)); hdr.width = LittleShort(hdr.width); hdr.height = LittleShort(hdr.height); @@ -127,7 +127,7 @@ FTexture *TGATexture_TryCreate(FileRdr & file, int lumpnum) if (hdr.img_type >=4 && hdr.img_type <= 8) return NULL; if ((hdr.img_desc & 16) != 0) return NULL; - file.Seek(0, FileRdr::SeekSet); + file.Seek(0, FileReader::SeekSet); file.Read(&hdr, sizeof(hdr)); hdr.width = LittleShort(hdr.width); hdr.height = LittleShort(hdr.height); @@ -250,7 +250,7 @@ const uint8_t *FTGATexture::GetPixels () // //========================================================================== -void FTGATexture::ReadCompressed(FileRdr &lump, uint8_t * buffer, int bytesperpixel) +void FTGATexture::ReadCompressed(FileReader &lump, uint8_t * buffer, int bytesperpixel) { uint8_t data[4]; int Size = Width * Height; @@ -297,7 +297,7 @@ void FTGATexture::MakeTexture () Pixels = new uint8_t[Width*Height]; lump.Read(&hdr, sizeof(hdr)); - lump.Seek(hdr.id_len, FileRdr::SeekCur); + lump.Seek(hdr.id_len, FileReader::SeekCur); hdr.width = LittleShort(hdr.width); hdr.height = LittleShort(hdr.height); @@ -503,7 +503,7 @@ int FTGATexture::CopyTrueColorPixels(FBitmap *bmp, int x, int y, int rotate, FCo int transval = 0; lump.Read(&hdr, sizeof(hdr)); - lump.Seek(hdr.id_len, FileRdr::SeekCur); + lump.Seek(hdr.id_len, FileReader::SeekCur); hdr.width = LittleShort(hdr.width); hdr.height = LittleShort(hdr.height); diff --git a/src/v_font.cpp b/src/v_font.cpp index 5fc5ba7e96..a8afa079c2 100644 --- a/src/v_font.cpp +++ b/src/v_font.cpp @@ -1868,18 +1868,18 @@ void FFontChar2::MakeTexture () { lump.Read (buff, 7); max = buff[6]; - lump.Seek (SourcePos - 11, FileRdr::SeekCur); + lump.Seek (SourcePos - 11, FileReader::SeekCur); } else if (buff[3] == 0x1A) { lump.Read(buff, 13); max = buff[12] - 1; - lump.Seek (SourcePos - 17, FileRdr::SeekCur); + lump.Seek (SourcePos - 17, FileReader::SeekCur); rle = false; } else { - lump.Seek (SourcePos - 4, FileRdr::SeekCur); + lump.Seek (SourcePos - 4, FileReader::SeekCur); } } diff --git a/src/w_wad.cpp b/src/w_wad.cpp index 9b995332b5..30e6fe0813 100644 --- a/src/w_wad.cpp +++ b/src/w_wad.cpp @@ -225,11 +225,11 @@ int FWadCollection::AddExternalFile(const char *filename) // [RH] Removed reload hack //========================================================================== -void FWadCollection::AddFile (const char *filename, FileRdr *wadr) +void FWadCollection::AddFile (const char *filename, FileReader *wadr) { int startlump; bool isdir = false; - FileRdr wadreader; + FileReader wadreader; if (wadr == nullptr) { @@ -304,7 +304,7 @@ void FWadCollection::AddFile (const char *filename, FileRdr *wadr) if (wadreader.isOpen()) { MD5Context md5; - wadreader.Seek(0, FileRdr::SeekSet); + wadreader.Seek(0, FileReader::SeekSet); md5.Update(wadreader, (unsigned)wadreader.GetLength()); md5.Final(cksum); @@ -932,7 +932,7 @@ void FWadCollection::RenameNerve () // cheaper way to know this is not the file continue; } - fr->Seek(0, FileRdr::SeekSet); + fr->Seek(0, FileReader::SeekSet); MD5Context md5; md5.Update(*fr, (unsigned)fr->GetLength()); md5.Final(cksum); @@ -982,7 +982,7 @@ void FWadCollection::FixMacHexen() return; } - FileRdr *reader = GetFileReader(GetIwadNum()); + FileReader *reader = GetFileReader(GetIwadNum()); auto iwadSize = reader->GetLength(); static const long DEMO_SIZE = 13596228; @@ -996,7 +996,7 @@ void FWadCollection::FixMacHexen() return; } - reader->Seek(0, FileRdr::SeekSet); + reader->Seek(0, FileReader::SeekSet); uint8_t checksum[16]; MD5Context md5; @@ -1305,7 +1305,7 @@ DEFINE_ACTION_FUNCTION(_Wads, ReadLump) //========================================================================== -FileRdr FWadCollection::OpenLumpReader(int lump) +FileReader FWadCollection::OpenLumpReader(int lump) { if ((unsigned)lump >= (unsigned)LumpInfo.Size()) { @@ -1317,14 +1317,14 @@ FileRdr FWadCollection::OpenLumpReader(int lump) if (rl->RefCount == 0 && rd != nullptr && !rd->GetBuffer() && !(rl->Flags & (LUMPF_BLOODCRYPT | LUMPF_COMPRESSED))) { - FileRdr rdr; + FileReader rdr; rdr.OpenFilePart(*rd, rl->GetFileOffset(), rl->LumpSize); return rdr; } return rl->NewReader(); // This always gets a reader to the cache } -FileRdr FWadCollection::ReopenLumpReader(int lump, bool alwayscache) +FileReader FWadCollection::ReopenLumpReader(int lump, bool alwayscache) { if ((unsigned)lump >= (unsigned)LumpInfo.Size()) { @@ -1338,7 +1338,7 @@ FileRdr FWadCollection::ReopenLumpReader(int lump, bool alwayscache) { int fileno = Wads.GetLumpFile(lump); const char *filename = Wads.GetWadFullName(fileno); - FileRdr fr; + FileReader fr; if (fr.OpenFile(filename, rl->GetFileOffset(), rl->LumpSize)) { return fr; @@ -1356,7 +1356,7 @@ FileRdr FWadCollection::ReopenLumpReader(int lump, bool alwayscache) // //========================================================================== -FileRdr *FWadCollection::GetFileReader(int wadnum) +FileReader *FWadCollection::GetFileReader(int wadnum) { if ((uint32_t)wadnum >= Files.Size()) { diff --git a/src/w_wad.h b/src/w_wad.h index 398c80f662..114a37039f 100644 --- a/src/w_wad.h +++ b/src/w_wad.h @@ -112,7 +112,7 @@ public: void SetIwadNum(int x) { IwadIndex = x; } void InitMultipleFiles (TArray &filenames); - void AddFile (const char *filename, FileRdr *wadinfo = NULL); + void AddFile (const char *filename, FileReader *wadinfo = NULL); int CheckIfWadLoaded (const char *name); const char *GetWadName (int wadnum) const; @@ -151,8 +151,8 @@ public: FMemLump ReadLump (int lump); FMemLump ReadLump (const char *name) { return ReadLump (GetNumForName (name)); } - FileRdr OpenLumpReader(int lump); // opens a reader that redirects to the containing file's one. - FileRdr ReopenLumpReader(int lump, bool alwayscache = false); // opens an independent reader. + FileReader OpenLumpReader(int lump); // opens a reader that redirects to the containing file's one. + FileReader ReopenLumpReader(int lump, bool alwayscache = false); // opens an independent reader. int FindLump (const char *name, int *lastlump, bool anyns=false); // [RH] Find lumps with duplication int FindLumpMulti (const char **names, int *lastlump, bool anyns = false, int *nameindex = NULL); // same with multiple possible names @@ -206,7 +206,7 @@ private: void RenameNerve(); void FixMacHexen(); void DeleteAll(); - FileRdr * GetFileReader(int wadnum); // Gets a FileRdr object to the entire WAD + FileReader * GetFileReader(int wadnum); // Gets a FileReader object to the entire WAD }; extern FWadCollection Wads; diff --git a/src/win32/st_start.cpp b/src/win32/st_start.cpp index 75aacdc4e3..98034f002a 100644 --- a/src/win32/st_start.cpp +++ b/src/win32/st_start.cpp @@ -967,7 +967,7 @@ FStrifeStartupScreen::FStrifeStartupScreen(int max_progress, HRESULT &hr) // Fill bitmap with the startup image. memset (ST_Util_BitsForBitmap(StartupBitmap), 0xF0, 64000); auto lumpr = Wads.OpenLumpReader (startup_lump); - lumpr.Seek (57 * 320, FileRdr::SeekSet); + lumpr.Seek (57 * 320, FileReader::SeekSet); lumpr.Read (ST_Util_BitsForBitmap(StartupBitmap) + 41 * 320, 95 * 320); // Load the animated overlays. From 8c0925dd5dcc456f3e5d6b7686ccbbc3e8ba544e Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Sun, 11 Mar 2018 22:05:28 +0100 Subject: [PATCH 28/89] - fixed some compile errors which were only reported on GCC/Clang. --- src/resourcefiles/resourcefile.cpp | 18 ++++++++++++------ src/resourcefiles/resourcefile.h | 7 +++---- 2 files changed, 15 insertions(+), 10 deletions(-) diff --git a/src/resourcefiles/resourcefile.cpp b/src/resourcefiles/resourcefile.cpp index 0a3b899162..17c7e87391 100644 --- a/src/resourcefiles/resourcefile.cpp +++ b/src/resourcefiles/resourcefile.cpp @@ -323,13 +323,17 @@ FResourceFile *FResourceFile::OpenDirectory(const char *filename, bool quiet) // //========================================================================== -FResourceFile::FResourceFile(const char *filename, FileReader &r) +FResourceFile::FResourceFile(const char *filename) { if (filename != NULL) Filename = copystring(filename); else Filename = NULL; - Reader = std::move(r); } +FResourceFile::FResourceFile(const char *filename, FileReader &r) + : FResourceFile(filename) +{ + Reader = std::move(r); +} FResourceFile::~FResourceFile() { @@ -642,11 +646,13 @@ int FUncompressedLump::FillCache() // //========================================================================== +FUncompressedFile::FUncompressedFile(const char *filename) +: FResourceFile(filename) +{} + FUncompressedFile::FUncompressedFile(const char *filename, FileReader &r) -: FResourceFile(filename, r) -{ - Lumps = NULL; -} + : FResourceFile(filename, r) +{} FUncompressedFile::~FUncompressedFile() { diff --git a/src/resourcefiles/resourcefile.h b/src/resourcefiles/resourcefile.h index 50dfaefecc..3d8d8fe457 100644 --- a/src/resourcefiles/resourcefile.h +++ b/src/resourcefiles/resourcefile.h @@ -86,6 +86,7 @@ public: protected: uint32_t NumLumps; + FResourceFile(const char *filename); FResourceFile(const char *filename, FileReader &r); // for archives that can contain directories @@ -131,14 +132,12 @@ struct FUncompressedLump : public FResourceLump class FUncompressedFile : public FResourceFile { protected: - FUncompressedLump * Lumps; - + FUncompressedLump * Lumps = nullptr; + FUncompressedFile(const char *filename); FUncompressedFile(const char *filename, FileReader &r); virtual ~FUncompressedFile(); virtual FResourceLump *GetLump(int no) { return ((unsigned)no < NumLumps)? &Lumps[no] : NULL; } - -public: }; From b72ccba5f5597ca73f5f6a9fbe658df58208b15c Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Sun, 11 Mar 2018 22:17:50 +0100 Subject: [PATCH 29/89] - missed one bit. --- src/resourcefiles/resourcefile.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/resourcefiles/resourcefile.h b/src/resourcefiles/resourcefile.h index 3d8d8fe457..0f51d8d10b 100644 --- a/src/resourcefiles/resourcefile.h +++ b/src/resourcefiles/resourcefile.h @@ -154,7 +154,7 @@ struct FExternalLump : public FResourceLump struct FMemoryFile : public FUncompressedFile { FMemoryFile(const char *_filename, const void *sdata, int length) - : FUncompressedFile(_filename, FileReader()) + : FUncompressedFile(_filename) { Reader.OpenMemoryArray(sdata, length); } From 011bf9d9aa4ba769ba2546e55ecf33abcdcae198 Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Sun, 11 Mar 2018 22:44:05 +0100 Subject: [PATCH 30/89] - another one... --- src/p_setup.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/p_setup.cpp b/src/p_setup.cpp index 2eae2b3f93..022eba0645 100644 --- a/src/p_setup.cpp +++ b/src/p_setup.cpp @@ -396,7 +396,8 @@ MapData *P_OpenMapData(const char * mapname, bool justcheck) return NULL; } map->lumpnum = lump_wad; - map->resource = FResourceFile::OpenResourceFile(Wads.GetLumpFullName(lump_wad), Wads.ReopenLumpReader(lump_wad), true); + auto reader = Wads.ReopenLumpReader(lump_wad); + map->resource = FResourceFile::OpenResourceFile(Wads.GetLumpFullName(lump_wad), reader, true); wadReader = map->resource->GetReader(); } } From 54061ad50c86732120cafe3650f9dd87f84e394b Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Sun, 11 Mar 2018 23:25:30 +0100 Subject: [PATCH 31/89] - another one. This would be easier if Travis CI didn't abort compilation after each single error... --- src/w_wad.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/w_wad.cpp b/src/w_wad.cpp index 30e6fe0813..fc6121b738 100644 --- a/src/w_wad.cpp +++ b/src/w_wad.cpp @@ -313,7 +313,7 @@ void FWadCollection::AddFile (const char *filename, FileReader *wadr) sprintf(cksumout + (j * 2), "%02X", cksum[j]); } - fprintf(hashfile, "file: %s, hash: %s, size: %lld\n", filename, cksumout, (int64_t)wadreader.GetLength()); + fprintf(hashfile, "file: %s, hash: %s, size: %d\n", filename, cksumout, (int)wadreader.GetLength()); } else @@ -326,7 +326,8 @@ void FWadCollection::AddFile (const char *filename, FileReader *wadr) if (!(lump->Flags & LUMPF_EMBEDDED)) { MD5Context md5; - md5.Update(lump->NewReader(), lump->LumpSize); + auto reader = lump->NewReader(); + md5.Update(reader, lump->LumpSize); md5.Final(cksum); for (size_t j = 0; j < sizeof(cksum); ++j) From c01554c6c8221b774d38c20348cf2359c16c98e1 Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Sun, 11 Mar 2018 23:32:40 +0100 Subject: [PATCH 32/89] - feeding another one to Travis CI... --- src/resourcefiles/file_directory.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/resourcefiles/file_directory.cpp b/src/resourcefiles/file_directory.cpp index 38aa44986c..3897e03410 100644 --- a/src/resourcefiles/file_directory.cpp +++ b/src/resourcefiles/file_directory.cpp @@ -90,7 +90,7 @@ public: //========================================================================== FDirectory::FDirectory(const char * directory) -: FResourceFile(NULL, FileReader()) +: FResourceFile(NULL) { FString dirname; From 1f6e201bf1cc94bd9131f84cb99f1864b6d69828 Mon Sep 17 00:00:00 2001 From: "alexey.lysiuk" Date: Mon, 12 Mar 2018 10:28:53 +0200 Subject: [PATCH 33/89] Do not stop Travis build after the first error --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 4db8a3ec57..b195f64b60 100644 --- a/.travis.yml +++ b/.travis.yml @@ -99,7 +99,7 @@ script: - mkdir build - cd build - cmake ${CMAKE_OPTIONS} -DPK3_QUIET_ZIPDIR=YES .. - - make -j2 + - make -j2 -k notifications: email: false From e0f7c9949651494b3791ee926b93d98146c61e1a Mon Sep 17 00:00:00 2001 From: "alexey.lysiuk" Date: Mon, 12 Mar 2018 11:00:40 +0200 Subject: [PATCH 34/89] Fixed crash on loading directories --- src/w_wad.cpp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/w_wad.cpp b/src/w_wad.cpp index fc6121b738..18bf2aa390 100644 --- a/src/w_wad.cpp +++ b/src/w_wad.cpp @@ -1363,7 +1363,10 @@ FileReader *FWadCollection::GetFileReader(int wadnum) { return NULL; } - return Files[wadnum]->GetReader(); + + // Return reader for real files only and nullptr otherwise + FileReader* const reader = Files[wadnum]->GetReader(); + return reader->isOpen() ? reader : nullptr; } //========================================================================== From def5e1d61b5b90fe1ed1979421950dac0ac5d038 Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Mon, 12 Mar 2018 10:19:16 +0100 Subject: [PATCH 35/89] Added proper handling for default parameter values of virtual overrides Due to how the VM handles default parameters, these must always be identical to the parent to prevent undefined behavior. So now, if such parameters are encountered, the compiler will either abort (for script version >= 3.3) or print a warning (for older versions.) Any defaults being specified for older versions will be ignored, though, and the defaults of the parent function be copied to the override. --- src/scripting/zscript/zcc_compile.cpp | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/src/scripting/zscript/zcc_compile.cpp b/src/scripting/zscript/zcc_compile.cpp index e4773f1c68..0722ed6945 100644 --- a/src/scripting/zscript/zcc_compile.cpp +++ b/src/scripting/zscript/zcc_compile.cpp @@ -2494,6 +2494,7 @@ void ZCCCompiler::CompileFunction(ZCC_StructWork *c, ZCC_FuncDeclarator *f, bool bool hasoptionals = false; if (p != nullptr) { + bool overridemsg = false; do { int elementcount = 1; @@ -2528,6 +2529,22 @@ void ZCCCompiler::CompileFunction(ZCC_StructWork *c, ZCC_FuncDeclarator *f, bool { flags |= VARF_Optional; hasoptionals = true; + + if ((varflags & VARF_Override) && !overridemsg) + { + // This is illegal, but in older compilers wasn't checked, so there it has to be demoted to a warning. + // Virtual calls always need to get their defaults from the base virtual method. + if (mVersion >= MakeVersion(3, 3)) + { + Error(p, "Default values for parameter of virtual override not allowed"); + } + else + { + Warn(p, "Default values for parameter of virtual override will be ignored!"); + } + overridemsg = true; + } + FxExpression *x = new FxTypeCast(ConvertNode(p->Default), type, false); FCompileContext ctx(OutNamespace, c->Type(), false); @@ -2721,6 +2738,13 @@ void ZCCCompiler::CompileFunction(ZCC_StructWork *c, ZCC_FuncDeclarator *f, bool clstype->Virtuals[vindex] = sym->Variants[0].Implementation; sym->Variants[0].Implementation->VirtualIndex = vindex; sym->Variants[0].Implementation->VarFlags = sym->Variants[0].Flags; + + // Defaults must be identical to parent class + if (parentfunc->Variants[0].Implementation->DefaultArgs.Size() > 0) + { + Printf("Copying defaults from %s to %s\n", parentfunc->Variants[0].Implementation->PrintableName.GetChars(), sym->Variants[0].Implementation->PrintableName.GetChars()); + sym->Variants[0].Implementation->DefaultArgs = parentfunc->Variants[0].Implementation->DefaultArgs; + } } } else From c85389c976e9060c08cf2592a90e2e25cb1f6807 Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Mon, 12 Mar 2018 10:26:36 +0100 Subject: [PATCH 36/89] Re-fixed 95d74614 This should be dealt with at the source, not one level up, so that it also works properly if the GetReader function of the ResourceFile object is called directly and not through the resource manager. --- src/resourcefiles/resourcefile.h | 3 ++- src/w_wad.cpp | 4 +--- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/src/resourcefiles/resourcefile.h b/src/resourcefiles/resourcefile.h index 0f51d8d10b..9b39b09082 100644 --- a/src/resourcefiles/resourcefile.h +++ b/src/resourcefiles/resourcefile.h @@ -106,7 +106,8 @@ public: static FResourceFile *OpenResourceFile(const char *filename, bool quiet = false, bool containeronly = false); static FResourceFile *OpenDirectory(const char *filename, bool quiet = false); virtual ~FResourceFile(); - FileReader *GetReader() { return &Reader; } + // If this FResourceFile represents a directory, the Reader object is not usable so don't return it. + FileReader *GetReader() { return Reader.isOpen()? &Reader : nullptr; } uint32_t LumpCount() const { return NumLumps; } uint32_t GetFirstLump() const { return FirstLump; } void SetFirstLump(uint32_t f) { FirstLump = f; } diff --git a/src/w_wad.cpp b/src/w_wad.cpp index 18bf2aa390..e084d4c749 100644 --- a/src/w_wad.cpp +++ b/src/w_wad.cpp @@ -1364,9 +1364,7 @@ FileReader *FWadCollection::GetFileReader(int wadnum) return NULL; } - // Return reader for real files only and nullptr otherwise - FileReader* const reader = Files[wadnum]->GetReader(); - return reader->isOpen() ? reader : nullptr; + return Files[wadnum]->GetReader(); } //========================================================================== From 4851c5bfde70112ed107135607b69c5a4001e2ce Mon Sep 17 00:00:00 2001 From: Major Cooke Date: Mon, 12 Mar 2018 11:53:25 -0500 Subject: [PATCH 37/89] Insert an extra line after printing the warnings. --- src/scripting/zscript/zcc_parser.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/scripting/zscript/zcc_parser.cpp b/src/scripting/zscript/zcc_parser.cpp index 02d78021bd..6902753da9 100644 --- a/src/scripting/zscript/zcc_parser.cpp +++ b/src/scripting/zscript/zcc_parser.cpp @@ -484,7 +484,7 @@ static void DoParse(int lumpnum) else if (FScriptPosition::WarnCounter > 0) { // If we got warnings, but no errors, print the information but continue. - Printf(TEXTCOLOR_ORANGE "%d warnings while compiling %s", FScriptPosition::WarnCounter, Wads.GetLumpFullPath(lumpnum).GetChars()); + Printf(TEXTCOLOR_ORANGE "%d warnings while compiling %s\n", FScriptPosition::WarnCounter, Wads.GetLumpFullPath(lumpnum).GetChars()); } } From 13ef97c4ace5f07f672c190da2f4bf4541a77afa Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Mon, 12 Mar 2018 18:47:49 +0100 Subject: [PATCH 38/89] - removed debug message. --- src/scripting/zscript/zcc_compile.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/src/scripting/zscript/zcc_compile.cpp b/src/scripting/zscript/zcc_compile.cpp index 0722ed6945..279d9adda3 100644 --- a/src/scripting/zscript/zcc_compile.cpp +++ b/src/scripting/zscript/zcc_compile.cpp @@ -2742,7 +2742,6 @@ void ZCCCompiler::CompileFunction(ZCC_StructWork *c, ZCC_FuncDeclarator *f, bool // Defaults must be identical to parent class if (parentfunc->Variants[0].Implementation->DefaultArgs.Size() > 0) { - Printf("Copying defaults from %s to %s\n", parentfunc->Variants[0].Implementation->PrintableName.GetChars(), sym->Variants[0].Implementation->PrintableName.GetChars()); sym->Variants[0].Implementation->DefaultArgs = parentfunc->Variants[0].Implementation->DefaultArgs; } } From 73248e7f86a8f216a0f3bf83e6dd112b88391251 Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Mon, 12 Mar 2018 18:55:05 +0100 Subject: [PATCH 39/89] - added a missing nullptr check in Instruments::free_soundfonts() --- src/sound/timiditypp/sndfont.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/sound/timiditypp/sndfont.cpp b/src/sound/timiditypp/sndfont.cpp index e969e4de40..b7bf005110 100644 --- a/src/sound/timiditypp/sndfont.cpp +++ b/src/sound/timiditypp/sndfont.cpp @@ -223,7 +223,8 @@ void Instruments::free_soundfonts() SFInsts *sf, *next; for (sf = sfrecs; sf != NULL; sf = next) { - tf_close(sf->tf); + if (sf->tf != nullptr) tf_close(sf->tf); + sf->tf = nullptr; reuse_mblock(&sf->pool); next = sf->next; free(sf); From 5d436cd3ed36a32a4b768014105b5e1193f4350f Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Mon, 12 Mar 2018 19:14:56 +0100 Subject: [PATCH 40/89] - forward the error state of the translation parser to the calling code so that it can print a message pointing to the problem content. --- src/r_data/r_translate.cpp | 44 +++++++++++++++------------ src/r_data/r_translate.h | 12 ++++---- src/scripting/thingdef_properties.cpp | 8 ++++- 3 files changed, 38 insertions(+), 26 deletions(-) diff --git a/src/r_data/r_translate.cpp b/src/r_data/r_translate.cpp index 2313d573de..ad07840f85 100644 --- a/src/r_data/r_translate.cpp +++ b/src/r_data/r_translate.cpp @@ -51,6 +51,7 @@ #include "r_data/sprites.h" #include "r_state.h" #include "vm.h" +#include "v_text.h" #include "gi.h" #include "stats.h" @@ -84,7 +85,7 @@ static bool IndexOutOfRange(const int color) if (outOfRange) { - Printf("Palette index %i is out of range [0..255]\n", color); + Printf(TEXTCOLOR_ORANGE "Palette index %i is out of range [0..255]\n", color); } return outOfRange; @@ -370,11 +371,11 @@ FNativePalette *FRemapTable::GetNative() // //---------------------------------------------------------------------------- -void FRemapTable::AddIndexRange(int start, int end, int pal1, int pal2) +bool FRemapTable::AddIndexRange(int start, int end, int pal1, int pal2) { if (IndexOutOfRange(start, end, pal1, pal2)) { - return; + return false; } double palcol, palstep; @@ -391,7 +392,7 @@ void FRemapTable::AddIndexRange(int start, int end, int pal1, int pal2) Remap[start] = pal1; Palette[start] = GPalette.BaseColors[pal1]; Palette[start].a = start == 0 ? 0 : 255; - return; + return true; } palcol = pal1; palstep = (pal2 - palcol) / (end - start); @@ -402,6 +403,7 @@ void FRemapTable::AddIndexRange(int start, int end, int pal1, int pal2) Palette[j] = GPalette.BaseColors[k]; Palette[j].a = j == 0 ? 0 : 255; } + return true; } //---------------------------------------------------------------------------- @@ -410,11 +412,11 @@ void FRemapTable::AddIndexRange(int start, int end, int pal1, int pal2) // //---------------------------------------------------------------------------- -void FRemapTable::AddColorRange(int start, int end, int _r1,int _g1, int _b1, int _r2, int _g2, int _b2) +bool FRemapTable::AddColorRange(int start, int end, int _r1,int _g1, int _b1, int _r2, int _g2, int _b2) { if (IndexOutOfRange(start, end)) { - return; + return false; } double r1 = _r1; @@ -466,6 +468,7 @@ void FRemapTable::AddColorRange(int start, int end, int _r1,int _g1, int _b1, in b += bs; } } + return true; } //---------------------------------------------------------------------------- @@ -474,11 +477,11 @@ void FRemapTable::AddColorRange(int start, int end, int _r1,int _g1, int _b1, in // //---------------------------------------------------------------------------- -void FRemapTable::AddDesaturation(int start, int end, double r1, double g1, double b1, double r2, double g2, double b2) +bool FRemapTable::AddDesaturation(int start, int end, double r1, double g1, double b1, double r2, double g2, double b2) { if (IndexOutOfRange(start, end)) { - return; + return false; } r1 = clamp(r1, 0.0, 2.0); @@ -519,6 +522,7 @@ void FRemapTable::AddDesaturation(int start, int end, double r1, double g1, doub Palette[cc] = pe; Palette[cc].a = cc == 0 ? 0:255; } + return true; } //---------------------------------------------------------------------------- @@ -527,11 +531,11 @@ void FRemapTable::AddDesaturation(int start, int end, double r1, double g1, doub // //---------------------------------------------------------------------------- -void FRemapTable::AddColourisation(int start, int end, int r, int g, int b) +bool FRemapTable::AddColourisation(int start, int end, int r, int g, int b) { if (IndexOutOfRange(start, end)) { - return; + return false; } for (int i = start; i < end; ++i) @@ -549,6 +553,7 @@ void FRemapTable::AddColourisation(int start, int end, int r, int g, int b) Palette[j] = PalEntry(j == 0 ? 0 : 255, int(br), int(bg), int(bb)); Remap[j] = ColorMatcher.Pick(Palette[j]); } + return true; } //---------------------------------------------------------------------------- @@ -557,11 +562,11 @@ void FRemapTable::AddColourisation(int start, int end, int r, int g, int b) // //---------------------------------------------------------------------------- -void FRemapTable::AddTint(int start, int end, int r, int g, int b, int amount) +bool FRemapTable::AddTint(int start, int end, int r, int g, int b, int amount) { if (IndexOutOfRange(start, end)) { - return; + return false; } for (int i = start; i < end; ++i) @@ -579,6 +584,7 @@ void FRemapTable::AddTint(int start, int end, int r, int g, int b, int amount) Palette[j] = PalEntry(j == 0 ? 0 : 255, int(br), int(bg), int(bb)); Remap[j] = ColorMatcher.Pick(Palette[j]); } + return true; } //---------------------------------------------------------------------------- @@ -587,7 +593,7 @@ void FRemapTable::AddTint(int start, int end, int r, int g, int b, int amount) // //---------------------------------------------------------------------------- -void FRemapTable::AddToTranslation(const char *range) +bool FRemapTable::AddToTranslation(const char *range) { int start,end; bool desaturated = false; @@ -607,7 +613,7 @@ void FRemapTable::AddToTranslation(const char *range) if (start < 0 || start > 255 || end < 0 || end > 255) { sc.ScriptError("Palette index out of range"); - return; + return false; } sc.MustGetAnyToken(); @@ -643,7 +649,7 @@ void FRemapTable::AddToTranslation(const char *range) b2 = sc.Number; sc.MustGetToken(']'); - AddColorRange(start, end, r1, g1, b1, r2, g2, b2); + return AddColorRange(start, end, r1, g1, b1, r2, g2, b2); } else if (sc.TokenType == '%') { @@ -683,7 +689,7 @@ void FRemapTable::AddToTranslation(const char *range) b2 = sc.Float; sc.MustGetToken(']'); - AddDesaturation(start, end, r1, g1, b1, r2, g2, b2); + return AddDesaturation(start, end, r1, g1, b1, r2, g2, b2); } else if (sc.TokenType == '#') { @@ -700,7 +706,7 @@ void FRemapTable::AddToTranslation(const char *range) b = sc.Number; sc.MustGetToken(']'); - AddColourisation(start, end, r, g, b); + return AddColourisation(start, end, r, g, b); } else if (sc.TokenType == '@') { @@ -720,7 +726,7 @@ void FRemapTable::AddToTranslation(const char *range) b = sc.Number; sc.MustGetToken(']'); - AddTint(start, end, r, g, b, a); + return AddTint(start, end, r, g, b, a); } else { @@ -731,7 +737,7 @@ void FRemapTable::AddToTranslation(const char *range) sc.MustGetToken(':'); sc.MustGetToken(TK_IntConst); pal2 = sc.Number; - AddIndexRange(start, end, pal1, pal2); + return AddIndexRange(start, end, pal1, pal2); } } catch (CRecoverableError &err) diff --git a/src/r_data/r_translate.h b/src/r_data/r_translate.h index 7c8f821b02..143a8097ee 100644 --- a/src/r_data/r_translate.h +++ b/src/r_data/r_translate.h @@ -39,12 +39,12 @@ struct FRemapTable bool IsIdentity() const; void Serialize(FSerializer &arc); static void StaticSerializeTranslations(FSerializer &arc); - void AddIndexRange(int start, int end, int pal1, int pal2); - void AddColorRange(int start, int end, int r1,int g1, int b1, int r2, int g2, int b2); - void AddDesaturation(int start, int end, double r1, double g1, double b1, double r2, double g2, double b2); - void AddColourisation(int start, int end, int r, int g, int b); - void AddTint(int start, int end, int r, int g, int b, int amount); - void AddToTranslation(const char * range); + bool AddIndexRange(int start, int end, int pal1, int pal2); + bool AddColorRange(int start, int end, int r1,int g1, int b1, int r2, int g2, int b2); + bool AddDesaturation(int start, int end, double r1, double g1, double b1, double r2, double g2, double b2); + bool AddColourisation(int start, int end, int r, int g, int b); + bool AddTint(int start, int end, int r, int g, int b, int amount); + bool AddToTranslation(const char * range); int StoreTranslation(int slot); uint8_t *Remap; // For the software renderer diff --git a/src/scripting/thingdef_properties.cpp b/src/scripting/thingdef_properties.cpp index 03ad9c1ccb..76339417fb 100644 --- a/src/scripting/thingdef_properties.cpp +++ b/src/scripting/thingdef_properties.cpp @@ -761,6 +761,7 @@ DEFINE_PROPERTY(translation, L, Actor) else { FRemapTable CurrentTranslation; + bool success = true; CurrentTranslation.MakeIdentity(); for(int i = 1; i < PROP_PARM_COUNT; i++) @@ -774,10 +775,15 @@ DEFINE_PROPERTY(translation, L, Actor) } else { - CurrentTranslation.AddToTranslation(str); + // parse all ranges to get a complete list of errors, if more than one range fails. + success |= CurrentTranslation.AddToTranslation(str); } } defaults->Translation = CurrentTranslation.StoreTranslation (TRANSLATION_Decorate); + if (!success) + { + bag.ScriptPosition.Message(MSG_WARNING, "Failed to parse translation"); + } } } From c15e868b0fed901edb52f3c9f052a6854b55fd35 Mon Sep 17 00:00:00 2001 From: Rachael Alexanderson Date: Sun, 4 Mar 2018 23:49:01 -0500 Subject: [PATCH 41/89] - implemented anonymous stats collector --- src/d_main.cpp | 3 +++ src/d_stats.cpp | 52 ++++++++++++++++++++++++++++++++++++++++++ src/win32/hardware.cpp | 45 ++++++++++++++++++++++++++++++++++++ src/win32/i_system.cpp | 14 +++++++++++- 4 files changed, 113 insertions(+), 1 deletion(-) create mode 100644 src/d_stats.cpp diff --git a/src/d_main.cpp b/src/d_main.cpp index 73450cc0a5..15fcaada34 100644 --- a/src/d_main.cpp +++ b/src/d_main.cpp @@ -118,6 +118,7 @@ #include "vm.h" #include "types.h" #include "r_data/r_vanillatrans.h" +#include "d_stats.cpp" EXTERN_CVAR(Bool, hud_althud) void DrawHUD(); @@ -2744,6 +2745,8 @@ void D_DoomMain (void) setmodeneeded = false; // This may be set to true here, but isn't needed for a restart } + D_DoAnonStats(); + if (I_FriendlyWindowTitle) I_SetWindowTitle(DoomStartupInfo.Name.GetChars()); diff --git a/src/d_stats.cpp b/src/d_stats.cpp new file mode 100644 index 0000000000..797cd3ccc4 --- /dev/null +++ b/src/d_stats.cpp @@ -0,0 +1,52 @@ +#if defined(_WIN32) +#include + +EXTERN_CVAR(Bool, gl_legacy_mode) +EXTERN_CVAR(Bool, vid_glswfb) +extern int currentrenderer, sys_ostype, restart; +CVAR(String, sys_statshost, "gzstats.drdteam.org", CVAR_ARCHIVE|CVAR_GLOBALCONFIG) +CVAR(Int, sys_statsport, 80, CVAR_ARCHIVE|CVAR_GLOBALCONFIG) +void D_DoHTTPRequest(char* request); + +#endif + +void D_DoAnonStats() +{ +#if defined(_WIN32) + uint8_t astat_render, astat_sysbits; + static char* requeststring = new char[512]; + // astat_render: + // 0: Unaccelerated (Software) + // 1: Direct3D (Software) + // 2: OpenGL (Software) + // 3: Legacy OpenGL mode + // 4: Modern OpenGL (>3.3) path + + // sys_ostype: + // 0: unknown/outdated + // 1: legacy (XP/Vista) + // 2: supported (7/8/8.1) + // 3: modern (10+) + + // astat_sysbits: + // 0: 32-bit + // 1: 64-bit + + if (!restart) + { + astat_render = (currentrenderer == 1) ? + (gl_legacy_mode ? 3 : 4) : // opengl + (!(screen->Accel2D)) ? 0 : (vid_glswfb ? 2 : 1); // software +#ifdef _WIN64 + astat_sysbits = 1; +#else + astat_sysbits = 0; +#endif + sprintf(requeststring, "GET /stats.php?render=%i&bits=%i&os=%i HTTP/1.1\nHost: %s\nConnection: close\nUser-Agent: %s %s\n\n", + astat_render, astat_sysbits, sys_ostype, sys_statshost.GetHumanString(), GAMENAME, VERSIONSTR); + //Printf("%s", requeststring); + std::thread t1(D_DoHTTPRequest, requeststring); + t1.detach(); + } +#endif +} diff --git a/src/win32/hardware.cpp b/src/win32/hardware.cpp index 58a611d3e7..df0bb3cdb8 100644 --- a/src/win32/hardware.cpp +++ b/src/win32/hardware.cpp @@ -510,3 +510,48 @@ CCMD (vid_currentmode) Printf ("%dx%dx%d\n", DisplayWidth, DisplayHeight, DisplayBits); } + +#include +EXTERN_CVAR(String, sys_statshost) +EXTERN_CVAR(Int, sys_statsport) + +void D_DoHTTPRequest(char* request) +{ + if (sys_statshost.GetHumanString() == NULL) + return; // no host, disable + + WSADATA wsaData; + if (WSAStartup(MAKEWORD(2, 2), &wsaData) != 0) + { + DPrintf(DMSG_ERROR, "WSAStartup failed.\n"); + return; + } + SOCKET Socket = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP); + struct hostent *host; + host = gethostbyname(sys_statshost.GetHumanString()); + SOCKADDR_IN SockAddr; + SockAddr.sin_port = htons(sys_statsport); + SockAddr.sin_family = AF_INET; + SockAddr.sin_addr.s_addr = *((uint32_t*)host->h_addr); + DPrintf(DMSG_NOTIFY, "Connecting to host %s\n", sys_statshost.GetHumanString()); + if (connect(Socket, (SOCKADDR*)(&SockAddr), sizeof(SockAddr)) != 0) + { + DPrintf(DMSG_ERROR, "Connection to host %s failed!\n", sys_statshost.GetHumanString()); + return; + } + send(Socket, request, strlen(request), 0); + char buffer[1024]; + int nDataLength; + while ((nDataLength = recv(Socket, buffer, 1024, 0)) > 0) + { + int i = 0; + while (buffer[i] >= 32 || buffer[i] == '\n' || buffer[i] == '\r') + { + i++; + } + } + closesocket(Socket); + WSACleanup(); + DPrintf(DMSG_NOTIFY, "Stats send successful.\n"); + return; +} diff --git a/src/win32/i_system.cpp b/src/win32/i_system.cpp index a537329e40..ba829d959c 100644 --- a/src/win32/i_system.cpp +++ b/src/win32/i_system.cpp @@ -154,6 +154,7 @@ uint32_t LanguageIDs[4]; UINT TimerPeriod; bool gameisdead; +int sys_ostype = 0; // PRIVATE DATA DEFINITIONS ------------------------------------------------ @@ -229,10 +230,12 @@ void I_DetectOS(void) if (info.dwMinorVersion == 1) { osname = "XP"; + sys_ostype = 1; // legacy OS } else if (info.dwMinorVersion == 2) { osname = "Server 2003"; + sys_ostype = 1; // legacy OS } } else if (info.dwMajorVersion == 6) @@ -240,10 +243,12 @@ void I_DetectOS(void) if (info.dwMinorVersion == 0) { osname = (info.wProductType == VER_NT_WORKSTATION) ? "Vista" : "Server 2008"; + sys_ostype = 1; // legacy OS } else if (info.dwMinorVersion == 1) { osname = (info.wProductType == VER_NT_WORKSTATION) ? "7" : "Server 2008 R2"; + sys_ostype = 2; // supported OS } else if (info.dwMinorVersion == 2) { @@ -251,16 +256,23 @@ void I_DetectOS(void) // the highest version of Windows you support, which will also be the // highest version of Windows this function returns. osname = (info.wProductType == VER_NT_WORKSTATION) ? "8" : "Server 2012"; + sys_ostype = 2; // supported OS } else if (info.dwMinorVersion == 3) { osname = (info.wProductType == VER_NT_WORKSTATION) ? "8.1" : "Server 2012 R2"; + sys_ostype = 2; // supported OS } else if (info.dwMinorVersion == 4) { - osname = (info.wProductType == VER_NT_WORKSTATION) ? "10 (or higher)" : "Server 10 (or higher)"; + osname = (info.wProductType == VER_NT_WORKSTATION) ? "10 (beta)" : "Server 10 (beta)"; } } + else if (info.dwMajorVersion == 10) + { + osname = (info.wProductType == VER_NT_WORKSTATION) ? "10 (or higher)" : "Server 10 (or higher)"; + sys_ostype = 3; // modern OS + } break; default: From d2fa4d0ff903513b4b7c72fae2cd997ffa638666 Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Tue, 13 Feb 2018 23:06:59 +0100 Subject: [PATCH 42/89] - most stat stuff done. --- src/CMakeLists.txt | 1 + src/d_main.cpp | 3 +- src/d_stats.cpp | 165 ++++++++++++++++++++++++--------- src/gl/system/gl_interface.cpp | 14 ++- src/posix/cocoa/i_system.mm | 5 + src/posix/sdl/i_system.cpp | 6 ++ src/v_video.h | 1 + src/win32/hardware.cpp | 12 +-- src/win32/i_system.cpp | 2 +- src/win32/win32swiface.h | 1 + src/x86.cpp | 3 + src/x86.h | 1 + 12 files changed, 160 insertions(+), 54 deletions(-) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 9fb9936971..58ca6a9ba9 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -874,6 +874,7 @@ set (PCH_SOURCES d_dehacked.cpp d_iwad.cpp d_main.cpp + d_stats.cpp d_net.cpp d_netinfo.cpp d_protocol.cpp diff --git a/src/d_main.cpp b/src/d_main.cpp index 15fcaada34..6338f9b042 100644 --- a/src/d_main.cpp +++ b/src/d_main.cpp @@ -118,10 +118,11 @@ #include "vm.h" #include "types.h" #include "r_data/r_vanillatrans.h" -#include "d_stats.cpp" EXTERN_CVAR(Bool, hud_althud) void DrawHUD(); +void D_DoAnonStats(); + // MACROS ------------------------------------------------------------------ diff --git a/src/d_stats.cpp b/src/d_stats.cpp index 797cd3ccc4..a2df443183 100644 --- a/src/d_stats.cpp +++ b/src/d_stats.cpp @@ -1,52 +1,131 @@ #if defined(_WIN32) -#include - -EXTERN_CVAR(Bool, gl_legacy_mode) -EXTERN_CVAR(Bool, vid_glswfb) -extern int currentrenderer, sys_ostype, restart; -CVAR(String, sys_statshost, "gzstats.drdteam.org", CVAR_ARCHIVE|CVAR_GLOBALCONFIG) -CVAR(Int, sys_statsport, 80, CVAR_ARCHIVE|CVAR_GLOBALCONFIG) -void D_DoHTTPRequest(char* request); +#define _WIN32_WINNT 0x0501 +#define WIN32_LEAN_AND_MEAN +#include +extern int sys_ostype; #endif +#include +#include "c_cvars.h" +#include "x86.h" +#include "version.h" +#include "v_video.h" + +EXTERN_CVAR(Bool, vid_glswfb) +extern int currentrenderer; +CVAR(String, sys_statshost, "gzstats.drdteam.org", CVAR_ARCHIVE|CVAR_GLOBALCONFIG|CVAR_NOSET) +CVAR(Int, sys_statsport, 80, CVAR_ARCHIVE|CVAR_GLOBALCONFIG|CVAR_NOSET) + +// Each machine will only send two reports, one when started with hardware rendering and one when started with software rendering. +CVAR(Bool, sentstats_swr, false, CVAR_ARCHIVE | CVAR_GLOBALCONFIG | CVAR_NOSET) +CVAR(Bool, sentstats_hwr, false, CVAR_ARCHIVE | CVAR_GLOBALCONFIG | CVAR_NOSET) + +std::pair gl_getInfo(); +bool I_HTTPRequest(const char* request); + + +static int GetOSVersion() +{ +#ifdef _WIN32 + if (sys_ostype == 1) return 1; + if (sizeof(void*) == 4) // 32 bit + { + BOOL res; + if (IsWow64Process(GetCurrentProcess(), &res)) + { + return 6; + } + if (sys_ostype == 2) return 2; + else return 4; + } + else + { + if (sys_ostype == 2) return 3; + else return 5; + } + +#elif defined __APPLE__ + + if (sizeof(void*) == 4) // 32 bit + { + return 7; + } + else + { + return 8; + } + +#else + + // Todo: PPC + ARM + + if (sizeof(void*) == 4) // 32 bit + { + return 11; + } + else + { + return 12; + } + + +#endif +} + +static int GetCoreInfo() +{ + int cores = std::thread::hardware_concurrency(); + if (CPU.HyperThreading) cores /= 2; + return cores < 2? 0 : cores < 4? 1 : cores < 6? 2 : cores < 8? 3 : 4; +} + +static int GetRenderInfo() +{ + if (currentrenderer == 0) + { + if (!screen->Accel2D) return 0; + if (vid_glswfb) return 2; + if (screen->LegacyHardware()) return 6; + return 1; + } + else + { + auto info = gl_getInfo(); + if (info.first < 3.3) return 3; // Legacy OpenGL. Don't care about Intel HD 3000 on Windows being run in 'risky' mode. + if (!info.second) return 4; + return 5; + } +} + +static void D_DoHTTPRequest(const char *request) +{ + if (I_HTTPRequest(request)) + { + if (currentrenderer == 0) + { + cvar_forceset("sentstats_swr", "1"); + } + else + { + cvar_forceset("sentstats_hwr", "1"); + } + } +} + void D_DoAnonStats() { -#if defined(_WIN32) - uint8_t astat_render, astat_sysbits; - static char* requeststring = new char[512]; - // astat_render: - // 0: Unaccelerated (Software) - // 1: Direct3D (Software) - // 2: OpenGL (Software) - // 3: Legacy OpenGL mode - // 4: Modern OpenGL (>3.3) path + static bool done = false; // do this only once per session. + if (done) return; + done = true; - // sys_ostype: - // 0: unknown/outdated - // 1: legacy (XP/Vista) - // 2: supported (7/8/8.1) - // 3: modern (10+) + // Do not repeat if already sent. + if (currentrenderer == 0 && sentstats_swr) return; + if (currentrenderer == 1 && sentstats_hwr) return; - // astat_sysbits: - // 0: 32-bit - // 1: 64-bit - - if (!restart) - { - astat_render = (currentrenderer == 1) ? - (gl_legacy_mode ? 3 : 4) : // opengl - (!(screen->Accel2D)) ? 0 : (vid_glswfb ? 2 : 1); // software -#ifdef _WIN64 - astat_sysbits = 1; -#else - astat_sysbits = 0; -#endif - sprintf(requeststring, "GET /stats.php?render=%i&bits=%i&os=%i HTTP/1.1\nHost: %s\nConnection: close\nUser-Agent: %s %s\n\n", - astat_render, astat_sysbits, sys_ostype, sys_statshost.GetHumanString(), GAMENAME, VERSIONSTR); - //Printf("%s", requeststring); - std::thread t1(D_DoHTTPRequest, requeststring); - t1.detach(); - } -#endif + FStringf requeststring("GET /stats.php?render=%i&cores=%i&os=%i HTTP/1.1\nHost: %s\nConnection: close\nUser-Agent: %s %s\n\n", + GetRenderInfo(), GetCoreInfo(), GetOSVersion(), sys_statshost.GetHumanString(), GAMENAME, VERSIONSTR); + DPrintf(DMSG_NOTIFY, "Sending %s", requeststring); + std::thread t1(D_DoHTTPRequest, requeststring); + t1.detach(); } diff --git a/src/gl/system/gl_interface.cpp b/src/gl/system/gl_interface.cpp index 1ac8b33fe3..3f0fe4dbf3 100644 --- a/src/gl/system/gl_interface.cpp +++ b/src/gl/system/gl_interface.cpp @@ -41,6 +41,7 @@ void gl_PatchMenu(); static TArray m_Extensions; RenderContext gl; +static double realglversion; // this is public so the statistics code can access it. EXTERN_CVAR(Bool, gl_legacy_mode) extern int currentrenderer; @@ -59,7 +60,7 @@ static void CollectExtensions() int max = 0; glGetIntegerv(GL_NUM_EXTENSIONS, &max); - if (0 == max) + if (max == 0) { // Try old method to collect extensions const char *supported = (char *)glGetString(GL_EXTENSIONS); @@ -144,6 +145,8 @@ void gl_LoadExtensions() } const char *version = Args->CheckValue("-glversion"); + realglversion = strtod(glversion, NULL); + if (version == NULL) { @@ -152,9 +155,8 @@ void gl_LoadExtensions() else { double v1 = strtod(version, NULL); - double v2 = strtod(glversion, NULL); if (v1 >= 3.0 && v1 < 3.3) v1 = 3.3; // promote '3' to 3.3 to avoid falling back to the legacy path. - if (v2 < v1) version = glversion; + if (realglversion < v1) version = glversion; else Printf("Emulating OpenGL v %s\n", version); } @@ -385,3 +387,9 @@ void gl_PrintStartupLog() } +std::pair gl_getInfo() +{ + // gl_ARB_bindless_texture is the closest we can get to determine Vulkan support from OpenGL. + // This isn't foolproof because Intel doesn't support it but for NVidia and AMD support of this extension means Vulkan support. + return std::make_pair(realglversion, CheckExtension("GL_ARB_bindless_texture")); +} \ No newline at end of file diff --git a/src/posix/cocoa/i_system.mm b/src/posix/cocoa/i_system.mm index 3be9a067ce..4de8047e9a 100644 --- a/src/posix/cocoa/i_system.mm +++ b/src/posix/cocoa/i_system.mm @@ -386,3 +386,8 @@ TArray I_GetGogPaths() // GOG's Doom games are Windows only at the moment return TArray(); } + +bool I_HTTPRequest(const char* request) +{ + // todo +} diff --git a/src/posix/sdl/i_system.cpp b/src/posix/sdl/i_system.cpp index f980e25983..b3fa1eda7e 100644 --- a/src/posix/sdl/i_system.cpp +++ b/src/posix/sdl/i_system.cpp @@ -489,3 +489,9 @@ TArray I_GetGogPaths() // GOG's Doom games are Windows only at the moment return TArray(); } + + +bool I_HTTPRequest(const char* request) +{ + // todo +} diff --git a/src/v_video.h b/src/v_video.h index 1d7abd581f..4d30cb0efa 100644 --- a/src/v_video.h +++ b/src/v_video.h @@ -405,6 +405,7 @@ public: virtual void SetBlendingRect (int x1, int y1, int x2, int y2); bool Accel2D; // If true, 2D drawing can be accelerated. + virtual bool LegacyHardware() const { return false; } // only for reporting SM1.4 support to the stat collector // Begin 2D drawing operations. This is like Update, but it doesn't end // the scene, and it doesn't present the image yet. If you are going to diff --git a/src/win32/hardware.cpp b/src/win32/hardware.cpp index df0bb3cdb8..17da1ff6de 100644 --- a/src/win32/hardware.cpp +++ b/src/win32/hardware.cpp @@ -515,16 +515,16 @@ CCMD (vid_currentmode) EXTERN_CVAR(String, sys_statshost) EXTERN_CVAR(Int, sys_statsport) -void D_DoHTTPRequest(char* request) +bool I_HTTPRequest(const char* request) { if (sys_statshost.GetHumanString() == NULL) - return; // no host, disable + return false; // no host, disable WSADATA wsaData; if (WSAStartup(MAKEWORD(2, 2), &wsaData) != 0) { DPrintf(DMSG_ERROR, "WSAStartup failed.\n"); - return; + return false; } SOCKET Socket = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP); struct hostent *host; @@ -537,9 +537,9 @@ void D_DoHTTPRequest(char* request) if (connect(Socket, (SOCKADDR*)(&SockAddr), sizeof(SockAddr)) != 0) { DPrintf(DMSG_ERROR, "Connection to host %s failed!\n", sys_statshost.GetHumanString()); - return; + return false; } - send(Socket, request, strlen(request), 0); + send(Socket, request, (int)strlen(request), 0); char buffer[1024]; int nDataLength; while ((nDataLength = recv(Socket, buffer, 1024, 0)) > 0) @@ -553,5 +553,5 @@ void D_DoHTTPRequest(char* request) closesocket(Socket); WSACleanup(); DPrintf(DMSG_NOTIFY, "Stats send successful.\n"); - return; + return true; } diff --git a/src/win32/i_system.cpp b/src/win32/i_system.cpp index ba829d959c..50bc7d8d0f 100644 --- a/src/win32/i_system.cpp +++ b/src/win32/i_system.cpp @@ -243,7 +243,7 @@ void I_DetectOS(void) if (info.dwMinorVersion == 0) { osname = (info.wProductType == VER_NT_WORKSTATION) ? "Vista" : "Server 2008"; - sys_ostype = 1; // legacy OS + sys_ostype = 2; // legacy OS } else if (info.dwMinorVersion == 1) { diff --git a/src/win32/win32swiface.h b/src/win32/win32swiface.h index d2cea20241..d3523e17bc 100644 --- a/src/win32/win32swiface.h +++ b/src/win32/win32swiface.h @@ -147,6 +147,7 @@ public: HRESULT GetHR (); bool Is8BitMode() { return false; } virtual int GetTrueHeight() { return TrueHeight; } + virtual bool LegacyHardware() const { return SM14; } private: friend class D3DTex; diff --git a/src/x86.cpp b/src/x86.cpp index b8c2d01d0c..877bd726d3 100644 --- a/src/x86.cpp +++ b/src/x86.cpp @@ -143,6 +143,8 @@ haveid: cpu->FeatureFlags[1] = foo[2]; // Store extended feature flags cpu->FeatureFlags[2] = foo[3]; // Store feature flags + cpu->HyperThreading = (foo[3] & (1 << 28)) > 0; + // If CLFLUSH instruction is supported, get the real cache line size. if (foo[3] & (1 << 19)) { @@ -251,6 +253,7 @@ void DumpCPUInfo(const CPUInfo *cpu) if (cpu->bSSE42) Printf(" SSE4.2"); if (cpu->b3DNow) Printf(" 3DNow!"); if (cpu->b3DNowPlus) Printf(" 3DNow!+"); + if (cpu->HyperThreading) Printf(" HyperThreading"); Printf ("\n"); } } diff --git a/src/x86.h b/src/x86.h index 1839e2c352..9c0f0f170c 100644 --- a/src/x86.h +++ b/src/x86.h @@ -20,6 +20,7 @@ struct CPUInfo // 92 bytes uint8_t Model; uint8_t Family; uint8_t Type; + uint8_t HyperThreading; union { From 033a11a0286fef90c2cd429b7d5273db8932f36c Mon Sep 17 00:00:00 2001 From: Rachael Alexanderson Date: Sun, 4 Mar 2018 23:51:26 -0500 Subject: [PATCH 43/89] - fix compile on clang - implement TCP connections in Linux - fix passing of request string to a thread - implement OS stats for ARM and PPC on Linux --- src/d_stats.cpp | 12 +++- src/posix/sdl/i_system.cpp | 128 +++++++++++++++++++++++++++---------- 2 files changed, 102 insertions(+), 38 deletions(-) diff --git a/src/d_stats.cpp b/src/d_stats.cpp index a2df443183..7150b9a9a0 100644 --- a/src/d_stats.cpp +++ b/src/d_stats.cpp @@ -58,8 +58,12 @@ static int GetOSVersion() #else - // Todo: PPC + ARM - +// fall-through linux stuff here +#ifdef __arm__ + return 10; +#elif __ppc__ + return 9; +#else if (sizeof(void*) == 4) // 32 bit { return 11; @@ -68,6 +72,7 @@ static int GetOSVersion() { return 12; } +#endif #endif @@ -123,7 +128,8 @@ void D_DoAnonStats() if (currentrenderer == 0 && sentstats_swr) return; if (currentrenderer == 1 && sentstats_hwr) return; - FStringf requeststring("GET /stats.php?render=%i&cores=%i&os=%i HTTP/1.1\nHost: %s\nConnection: close\nUser-Agent: %s %s\n\n", + static char requeststring[1024]; + sprintf(requeststring, "GET /stats.php?render=%i&cores=%i&os=%i HTTP/1.1\nHost: %s\nConnection: close\nUser-Agent: %s %s\n\n", GetRenderInfo(), GetCoreInfo(), GetOSVersion(), sys_statshost.GetHumanString(), GAMENAME, VERSIONSTR); DPrintf(DMSG_NOTIFY, "Sending %s", requeststring); std::thread t1(D_DoHTTPRequest, requeststring); diff --git a/src/posix/sdl/i_system.cpp b/src/posix/sdl/i_system.cpp index b3fa1eda7e..f6d05f3094 100644 --- a/src/posix/sdl/i_system.cpp +++ b/src/posix/sdl/i_system.cpp @@ -36,6 +36,11 @@ #include +#include +#include +#include +#include + #include "doomerrors.h" #include @@ -69,6 +74,8 @@ #include "g_level.h" EXTERN_CVAR (String, language) +EXTERN_CVAR(String, sys_statshost) +EXTERN_CVAR(Int, sys_statsport) extern "C" { @@ -94,7 +101,7 @@ void I_Tactile (int /*on*/, int /*off*/, int /*total*/) ticcmd_t emptycmd; ticcmd_t *I_BaseTiccmd(void) { - return &emptycmd; + return &emptycmd; } void I_BeginRead(void) @@ -129,7 +136,7 @@ void I_Init (void) DumpCPUInfo (&CPU); atterm (I_ShutdownSound); - I_InitSound (); + I_InitSound (); } // @@ -139,9 +146,9 @@ static int has_exited; void I_Quit (void) { - has_exited = 1; /* Prevent infinitely recursive exits -- killough */ + has_exited = 1; /* Prevent infinitely recursive exits -- killough */ - if (demorecording) + if (demorecording) G_CheckDemoStatus(); C_DeinitConsole(); @@ -191,11 +198,11 @@ void Linux_I_FatalError(const char* errortext) void I_FatalError (const char *error, ...) { - static bool alreadyThrown = false; - gameisdead = true; + static bool alreadyThrown = false; + gameisdead = true; - if (!alreadyThrown) // ignore all but the first message -- killough - { + if (!alreadyThrown) // ignore all but the first message -- killough + { alreadyThrown = true; char errortext[MAX_ERRORTEXT]; int index; @@ -221,25 +228,25 @@ void I_FatalError (const char *error, ...) // throw CFatalError (errortext); fprintf (stderr, "%s\n", errortext); exit (-1); - } + } - if (!has_exited) // If it hasn't exited yet, exit now -- killough - { + if (!has_exited) // If it hasn't exited yet, exit now -- killough + { has_exited = 1; // Prevent infinitely recursive exits -- killough exit(-1); - } + } } void I_Error (const char *error, ...) { - va_list argptr; - char errortext[MAX_ERRORTEXT]; + va_list argptr; + char errortext[MAX_ERRORTEXT]; - va_start (argptr, error); - vsprintf (errortext, error, argptr); - va_end (argptr); + va_start (argptr, error); + vsprintf (errortext, error, argptr); + va_end (argptr); - throw CRecoverableError (errortext); + throw CRecoverableError (errortext); } void I_SetIWADInfo () @@ -291,8 +298,8 @@ int I_PickIWad (WadStuff *wads, int numwads, bool showwin, int defaultiwad) { FString cmd("kdialog --title \"" GAMESIG " "); cmd << GetVersionString() << ": Select an IWAD to use\"" - " --menu \"" GAMENAME " found more than one IWAD\n" - "Select from the list below to determine which one to use:\""; + " --menu \"" GAMENAME " found more than one IWAD\n" + "Select from the list below to determine which one to use:\""; for(i = 0; i < numwads; ++i) { @@ -380,7 +387,7 @@ static int matchfile (struct dirent *ent) static int matchfile (const struct dirent *ent) #endif { - return fnmatch (pattern, ent->d_name, FNM_NOESCAPE) == 0; + return fnmatch (pattern, ent->d_name, FNM_NOESCAPE) == 0; } void *I_FindFirst (const char *filespec, findstate_t *fileinfo) @@ -399,22 +406,22 @@ void *I_FindFirst (const char *filespec, findstate_t *fileinfo) dir = "."; } - fileinfo->current = 0; - fileinfo->count = scandir (dir.GetChars(), &fileinfo->namelist, + fileinfo->current = 0; + fileinfo->count = scandir (dir.GetChars(), &fileinfo->namelist, matchfile, alphasort); - if (fileinfo->count > 0) - { + if (fileinfo->count > 0) + { return fileinfo; - } - return (void*)-1; + } + return (void*)-1; } int I_FindNext (void *handle, findstate_t *fileinfo) { - findstate_t *state = (findstate_t *)handle; - if (state->current < fileinfo->count) - { - return ++state->current < fileinfo->count ? 0 : -1; + findstate_t *state = (findstate_t *)handle; + if (state->current < fileinfo->count) + { + return ++state->current < fileinfo->count ? 0 : -1; } return -1; } @@ -486,12 +493,63 @@ unsigned int I_MakeRNGSeed() TArray I_GetGogPaths() { - // GOG's Doom games are Windows only at the moment - return TArray(); + // GOG's Doom games are Windows only at the moment + return TArray(); } - bool I_HTTPRequest(const char* request) { - // todo + if (sys_statshost.GetHumanString() == NULL || sys_statshost.GetHumanString()[0] == 0) + return false; // no host, disable + + int sockfd, portno, n; + struct sockaddr_in serv_addr; + struct hostent *server; + + portno = sys_statsport; + sockfd = socket(AF_INET, SOCK_STREAM, 0); + + if (sockfd < 0) + { + DPrintf(DMSG_ERROR, "Error opening TCP socket.\n"); + return false; + } + + server = gethostbyname(sys_statshost.GetHumanString()); + if (server == NULL) + { + DPrintf(DMSG_ERROR, "Error looking up hostname.\n"); + return false; + } + bzero((char*) &serv_addr, sizeof(serv_addr)); + serv_addr.sin_family = AF_INET; + bcopy((char *)server->h_addr, + (char *)&serv_addr.sin_addr.s_addr, + server->h_length); + serv_addr.sin_port = htons(portno); + + DPrintf(DMSG_NOTIFY, "Connecting to host %s\n", sys_statshost.GetHumanString()); + if (connect(sockfd, (struct sockaddr *)&serv_addr, sizeof(serv_addr)) < 0) + { + DPrintf(DMSG_ERROR, "Connection to host %s failed!\n", sys_statshost.GetHumanString()); + return false; + } + + char buffer[1024]; + sprintf(buffer, "%s", request); + Printf("Buffer: %s", buffer); + n = write(sockfd, (char*)buffer, (int)strlen(request)); + if (n<0) + { + DPrintf(DMSG_ERROR, "Error writing to socket.\n"); + close(sockfd); + return false; + } + bzero(buffer, 1024); + + n = read(sockfd, buffer, 1023); + close(sockfd); + DPrintf(DMSG_NOTIFY, "Stats send successful.\n"); + return true; } + From f2f649bf77b8121fe31d538321022f8709f189c3 Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Sun, 4 Mar 2018 17:51:07 +0100 Subject: [PATCH 44/89] - put all stats related code into one file. --- src/d_stats.cpp | 122 ++++++++++++++++++++++++++++++++++--- src/posix/sdl/i_system.cpp | 63 ------------------- src/win32/hardware.cpp | 46 -------------- 3 files changed, 114 insertions(+), 117 deletions(-) diff --git a/src/d_stats.cpp b/src/d_stats.cpp index 7150b9a9a0..3cb089b4d2 100644 --- a/src/d_stats.cpp +++ b/src/d_stats.cpp @@ -2,8 +2,13 @@ #define _WIN32_WINNT 0x0501 #define WIN32_LEAN_AND_MEAN #include +#include extern int sys_ostype; - +#else +#include +#include +#include +#include #endif #include @@ -18,13 +23,114 @@ CVAR(String, sys_statshost, "gzstats.drdteam.org", CVAR_ARCHIVE|CVAR_GLOBALCONFI CVAR(Int, sys_statsport, 80, CVAR_ARCHIVE|CVAR_GLOBALCONFIG|CVAR_NOSET) // Each machine will only send two reports, one when started with hardware rendering and one when started with software rendering. -CVAR(Bool, sentstats_swr, false, CVAR_ARCHIVE | CVAR_GLOBALCONFIG | CVAR_NOSET) -CVAR(Bool, sentstats_hwr, false, CVAR_ARCHIVE | CVAR_GLOBALCONFIG | CVAR_NOSET) +#define CHECKVERSION 330 +#define CHECKVERSIONSTR "330" +CVAR(Int, sentstats_swr_done, 0, CVAR_ARCHIVE | CVAR_GLOBALCONFIG | CVAR_NOSET) +CVAR(Int, sentstats_hwr_done, 0, CVAR_ARCHIVE | CVAR_GLOBALCONFIG | CVAR_NOSET) std::pair gl_getInfo(); -bool I_HTTPRequest(const char* request); +#ifdef _WIN32 + +bool I_HTTPRequest(const char* request) +{ + if (sys_statshost.GetHumanString() == NULL) + return false; // no host, disable + + WSADATA wsaData; + if (WSAStartup(MAKEWORD(2, 2), &wsaData) != 0) + { + DPrintf(DMSG_ERROR, "WSAStartup failed.\n"); + return false; + } + SOCKET Socket = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP); + struct hostent *host; + host = gethostbyname(sys_statshost.GetHumanString()); + SOCKADDR_IN SockAddr; + SockAddr.sin_port = htons(sys_statsport); + SockAddr.sin_family = AF_INET; + SockAddr.sin_addr.s_addr = *((uint32_t*)host->h_addr); + DPrintf(DMSG_NOTIFY, "Connecting to host %s\n", sys_statshost.GetHumanString()); + if (connect(Socket, (SOCKADDR*)(&SockAddr), sizeof(SockAddr)) != 0) + { + DPrintf(DMSG_ERROR, "Connection to host %s failed!\n", sys_statshost.GetHumanString()); + return false; + } + send(Socket, request, (int)strlen(request), 0); + char buffer[1024]; + int nDataLength; + while ((nDataLength = recv(Socket, buffer, 1024, 0)) > 0) + { + int i = 0; + while (buffer[i] >= 32 || buffer[i] == '\n' || buffer[i] == '\r') + { + i++; + } + } + closesocket(Socket); + WSACleanup(); + DPrintf(DMSG_NOTIFY, "Stats send successful.\n"); + return true; +} +#else +bool I_HTTPRequest(const char* request) +{ + if (sys_statshost.GetHumanString() == NULL || sys_statshost.GetHumanString()[0] == 0) + return false; // no host, disable + + int sockfd, portno, n; + struct sockaddr_in serv_addr; + struct hostent *server; + + portno = sys_statsport; + sockfd = socket(AF_INET, SOCK_STREAM, 0); + + if (sockfd < 0) + { + DPrintf(DMSG_ERROR, "Error opening TCP socket.\n"); + return false; + } + + server = gethostbyname(sys_statshost.GetHumanString()); + if (server == NULL) + { + DPrintf(DMSG_ERROR, "Error looking up hostname.\n"); + return false; + } + bzero((char*) &serv_addr, sizeof(serv_addr)); + serv_addr.sin_family = AF_INET; + bcopy((char *)server->h_addr, + (char *)&serv_addr.sin_addr.s_addr, + server->h_length); + serv_addr.sin_port = htons(portno); + + DPrintf(DMSG_NOTIFY, "Connecting to host %s\n", sys_statshost.GetHumanString()); + if (connect(sockfd, (struct sockaddr *)&serv_addr, sizeof(serv_addr)) < 0) + { + DPrintf(DMSG_ERROR, "Connection to host %s failed!\n", sys_statshost.GetHumanString()); + return false; + } + + char buffer[1024]; + sprintf(buffer, "%s", request); + Printf("Buffer: %s", buffer); + n = write(sockfd, (char*)buffer, (int)strlen(request)); + if (n<0) + { + DPrintf(DMSG_ERROR, "Error writing to socket.\n"); + close(sockfd); + return false; + } + bzero(buffer, 1024); + + n = read(sockfd, buffer, 1023); + close(sockfd); + DPrintf(DMSG_NOTIFY, "Stats send successful.\n"); + return true; +} +#endif + static int GetOSVersion() { #ifdef _WIN32 @@ -109,11 +215,11 @@ static void D_DoHTTPRequest(const char *request) { if (currentrenderer == 0) { - cvar_forceset("sentstats_swr", "1"); + cvar_forceset("sentstats_swr_done", CHECKVERSIONSTR); } else { - cvar_forceset("sentstats_hwr", "1"); + cvar_forceset("sentstats_hwr_done", CHECKVERSIONSTR); } } } @@ -125,8 +231,8 @@ void D_DoAnonStats() done = true; // Do not repeat if already sent. - if (currentrenderer == 0 && sentstats_swr) return; - if (currentrenderer == 1 && sentstats_hwr) return; + if (currentrenderer == 0 && sentstats_swr_done >= CHECKVERSION) return; + if (currentrenderer == 1 && sentstats_hwr_done >= CHECKVERSION) return; static char requeststring[1024]; sprintf(requeststring, "GET /stats.php?render=%i&cores=%i&os=%i HTTP/1.1\nHost: %s\nConnection: close\nUser-Agent: %s %s\n\n", diff --git a/src/posix/sdl/i_system.cpp b/src/posix/sdl/i_system.cpp index f6d05f3094..1f41788a04 100644 --- a/src/posix/sdl/i_system.cpp +++ b/src/posix/sdl/i_system.cpp @@ -36,11 +36,6 @@ #include -#include -#include -#include -#include - #include "doomerrors.h" #include @@ -74,8 +69,6 @@ #include "g_level.h" EXTERN_CVAR (String, language) -EXTERN_CVAR(String, sys_statshost) -EXTERN_CVAR(Int, sys_statsport) extern "C" { @@ -497,59 +490,3 @@ TArray I_GetGogPaths() return TArray(); } -bool I_HTTPRequest(const char* request) -{ - if (sys_statshost.GetHumanString() == NULL || sys_statshost.GetHumanString()[0] == 0) - return false; // no host, disable - - int sockfd, portno, n; - struct sockaddr_in serv_addr; - struct hostent *server; - - portno = sys_statsport; - sockfd = socket(AF_INET, SOCK_STREAM, 0); - - if (sockfd < 0) - { - DPrintf(DMSG_ERROR, "Error opening TCP socket.\n"); - return false; - } - - server = gethostbyname(sys_statshost.GetHumanString()); - if (server == NULL) - { - DPrintf(DMSG_ERROR, "Error looking up hostname.\n"); - return false; - } - bzero((char*) &serv_addr, sizeof(serv_addr)); - serv_addr.sin_family = AF_INET; - bcopy((char *)server->h_addr, - (char *)&serv_addr.sin_addr.s_addr, - server->h_length); - serv_addr.sin_port = htons(portno); - - DPrintf(DMSG_NOTIFY, "Connecting to host %s\n", sys_statshost.GetHumanString()); - if (connect(sockfd, (struct sockaddr *)&serv_addr, sizeof(serv_addr)) < 0) - { - DPrintf(DMSG_ERROR, "Connection to host %s failed!\n", sys_statshost.GetHumanString()); - return false; - } - - char buffer[1024]; - sprintf(buffer, "%s", request); - Printf("Buffer: %s", buffer); - n = write(sockfd, (char*)buffer, (int)strlen(request)); - if (n<0) - { - DPrintf(DMSG_ERROR, "Error writing to socket.\n"); - close(sockfd); - return false; - } - bzero(buffer, 1024); - - n = read(sockfd, buffer, 1023); - close(sockfd); - DPrintf(DMSG_NOTIFY, "Stats send successful.\n"); - return true; -} - diff --git a/src/win32/hardware.cpp b/src/win32/hardware.cpp index 17da1ff6de..a8ecfccae9 100644 --- a/src/win32/hardware.cpp +++ b/src/win32/hardware.cpp @@ -509,49 +509,3 @@ CCMD (vid_currentmode) { Printf ("%dx%dx%d\n", DisplayWidth, DisplayHeight, DisplayBits); } - - -#include -EXTERN_CVAR(String, sys_statshost) -EXTERN_CVAR(Int, sys_statsport) - -bool I_HTTPRequest(const char* request) -{ - if (sys_statshost.GetHumanString() == NULL) - return false; // no host, disable - - WSADATA wsaData; - if (WSAStartup(MAKEWORD(2, 2), &wsaData) != 0) - { - DPrintf(DMSG_ERROR, "WSAStartup failed.\n"); - return false; - } - SOCKET Socket = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP); - struct hostent *host; - host = gethostbyname(sys_statshost.GetHumanString()); - SOCKADDR_IN SockAddr; - SockAddr.sin_port = htons(sys_statsport); - SockAddr.sin_family = AF_INET; - SockAddr.sin_addr.s_addr = *((uint32_t*)host->h_addr); - DPrintf(DMSG_NOTIFY, "Connecting to host %s\n", sys_statshost.GetHumanString()); - if (connect(Socket, (SOCKADDR*)(&SockAddr), sizeof(SockAddr)) != 0) - { - DPrintf(DMSG_ERROR, "Connection to host %s failed!\n", sys_statshost.GetHumanString()); - return false; - } - send(Socket, request, (int)strlen(request), 0); - char buffer[1024]; - int nDataLength; - while ((nDataLength = recv(Socket, buffer, 1024, 0)) > 0) - { - int i = 0; - while (buffer[i] >= 32 || buffer[i] == '\n' || buffer[i] == '\r') - { - i++; - } - } - closesocket(Socket); - WSACleanup(); - DPrintf(DMSG_NOTIFY, "Stats send successful.\n"); - return true; -} From fbc4831072af6303724dfbb313baf290b8b38b7b Mon Sep 17 00:00:00 2001 From: Rachael Alexanderson Date: Sun, 4 Mar 2018 23:52:12 -0500 Subject: [PATCH 45/89] - remove empty Mac I_HTTPRequest prototype since it's not used --- src/posix/cocoa/i_system.mm | 4 ---- 1 file changed, 4 deletions(-) diff --git a/src/posix/cocoa/i_system.mm b/src/posix/cocoa/i_system.mm index 4de8047e9a..c8f066be5b 100644 --- a/src/posix/cocoa/i_system.mm +++ b/src/posix/cocoa/i_system.mm @@ -387,7 +387,3 @@ TArray I_GetGogPaths() return TArray(); } -bool I_HTTPRequest(const char* request) -{ - // todo -} From 5a4e9decd97ef5f01fe5c2e05adb776f79fdda01 Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Sun, 4 Mar 2018 19:24:50 +0100 Subject: [PATCH 46/89] - added missing #include --- src/d_stats.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/d_stats.cpp b/src/d_stats.cpp index 3cb089b4d2..d2005d4cdc 100644 --- a/src/d_stats.cpp +++ b/src/d_stats.cpp @@ -9,6 +9,7 @@ extern int sys_ostype; #include #include #include +#include #endif #include From 5fccdd9acd818556fc4acb87da8fbc717ee102ab Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Mon, 12 Mar 2018 21:18:11 +0100 Subject: [PATCH 47/89] - added missing return to translation code. - a bit of header cleanup. * moved and from files.h to files_decompress.cpp because they are no longer needed for defining the interface. * added to the precompiled header --- src/files.h | 2 -- src/files_decompress.cpp | 2 ++ src/g_pch.h | 1 + src/r_data/r_translate.cpp | 1 + src/sound/timiditypp/reverb.cpp | 1 + src/sound/timiditypp/timidity.h | 1 - 6 files changed, 5 insertions(+), 3 deletions(-) diff --git a/src/files.h b/src/files.h index 9424fd0315..096452269f 100644 --- a/src/files.h +++ b/src/files.h @@ -37,9 +37,7 @@ #define FILES_H #include -#include #include -#include "bzlib.h" #include "doomtype.h" #include "m_swap.h" diff --git a/src/files_decompress.cpp b/src/files_decompress.cpp index 56d11a99f2..b6ba8fbcb3 100644 --- a/src/files_decompress.cpp +++ b/src/files_decompress.cpp @@ -35,6 +35,8 @@ // This also pulls in windows.h #include "LzmaDec.h" +#include +#include #include "files.h" #include "i_system.h" diff --git a/src/g_pch.h b/src/g_pch.h index cad5a84098..bf2833cf81 100644 --- a/src/g_pch.h +++ b/src/g_pch.h @@ -23,6 +23,7 @@ #include #include #include +#include // These two headers get included nearly everywhere so it doesn't matter if changing them forces a few more recompiles. // The overall savings from PCHing them are more significant. diff --git a/src/r_data/r_translate.cpp b/src/r_data/r_translate.cpp index ad07840f85..f122745a07 100644 --- a/src/r_data/r_translate.cpp +++ b/src/r_data/r_translate.cpp @@ -743,6 +743,7 @@ bool FRemapTable::AddToTranslation(const char *range) catch (CRecoverableError &err) { Printf("Error in translation '%s':\n%s\n", range, err.GetMessage()); + return false; } } diff --git a/src/sound/timiditypp/reverb.cpp b/src/sound/timiditypp/reverb.cpp index c0446c8c62..c83e1f568d 100644 --- a/src/sound/timiditypp/reverb.cpp +++ b/src/sound/timiditypp/reverb.cpp @@ -29,6 +29,7 @@ */ #include +#include #include "timidity.h" #include "tables.h" #include "common.h" diff --git a/src/sound/timiditypp/timidity.h b/src/sound/timiditypp/timidity.h index cc6b8a22fa..0c78505682 100644 --- a/src/sound/timiditypp/timidity.h +++ b/src/sound/timiditypp/timidity.h @@ -28,7 +28,6 @@ #ifndef TIMIDITY_H_INCLUDED #define TIMIDITY_H_INCLUDED 1 -#include "c_cvars.h" #include "controls.h" #include "mblock.h" From 9b7bef59d288ce44721ad46d399d8d766dda6563 Mon Sep 17 00:00:00 2001 From: Magnus Norddahl Date: Mon, 12 Mar 2018 21:44:55 +0100 Subject: [PATCH 48/89] - fixed Intel rendering glitch with uDynLightColor --- wadsrc/static/shaders/glsl/material_normal.fp | 21 ++++++----- .../static/shaders/glsl/material_specular.fp | 35 +++++++++---------- 2 files changed, 27 insertions(+), 29 deletions(-) diff --git a/wadsrc/static/shaders/glsl/material_normal.fp b/wadsrc/static/shaders/glsl/material_normal.fp index 610a239d27..b048f45597 100644 --- a/wadsrc/static/shaders/glsl/material_normal.fp +++ b/wadsrc/static/shaders/glsl/material_normal.fp @@ -34,13 +34,12 @@ vec3 lightContribution(int i, vec3 normal) vec3 ProcessMaterial(vec3 material, vec3 color) { + vec4 dynlight = uDynLightColor; + vec3 normal = ApplyNormalMap(); + if (uLightIndex >= 0) { - vec4 dynlight = uDynLightColor; - vec3 normal = ApplyNormalMap(); - ivec4 lightRange = ivec4(lights[uLightIndex]) + ivec4(uLightIndex + 1); - if (lightRange.z > lightRange.x) { // modulated lights @@ -55,9 +54,13 @@ vec3 ProcessMaterial(vec3 material, vec3 color) dynlight.rgb -= lightContribution(i, normal); } } + } - vec3 frag = material * clamp(color + desaturate(dynlight).rgb, 0.0, 1.4); + vec3 frag = material * clamp(color + desaturate(dynlight).rgb, 0.0, 1.4); + if (uLightIndex >= 0) + { + ivec4 lightRange = ivec4(lights[uLightIndex]) + ivec4(uLightIndex + 1); if (lightRange.w > lightRange.z) { vec4 addlight = vec4(0.0,0.0,0.0,0.0); @@ -70,11 +73,7 @@ vec3 ProcessMaterial(vec3 material, vec3 color) frag = clamp(frag + desaturate(addlight).rgb, 0.0, 1.0); } + } - return frag; - } - else - { - return material * clamp(color + desaturate(uDynLightColor).rgb, 0.0, 1.4); - } + return frag; } diff --git a/wadsrc/static/shaders/glsl/material_specular.fp b/wadsrc/static/shaders/glsl/material_specular.fp index ab61d6cf9f..dff6347370 100644 --- a/wadsrc/static/shaders/glsl/material_specular.fp +++ b/wadsrc/static/shaders/glsl/material_specular.fp @@ -36,16 +36,15 @@ vec2 lightAttenuation(int i, vec3 normal, vec3 viewdir, float lightcolorA) vec3 ProcessMaterial(vec3 material, vec3 color) { + vec4 dynlight = uDynLightColor; + vec4 specular = vec4(0.0, 0.0, 0.0, 1.0); + + vec3 normal = ApplyNormalMap(); + vec3 viewdir = normalize(uCameraPos.xyz - pixelpos.xyz); + if (uLightIndex >= 0) { - vec4 dynlight = uDynLightColor; - vec4 specular = vec4(0.0, 0.0, 0.0, 1.0); - - vec3 normal = ApplyNormalMap(); - vec3 viewdir = normalize(uCameraPos.xyz - pixelpos.xyz); - ivec4 lightRange = ivec4(lights[uLightIndex]) + ivec4(uLightIndex + 1); - if (lightRange.z > lightRange.x) { // modulated lights @@ -66,17 +65,21 @@ vec3 ProcessMaterial(vec3 material, vec3 color) specular.rgb -= lightcolor.rgb * attenuation.y; } } + } - dynlight.rgb = clamp(color + desaturate(dynlight).rgb, 0.0, 1.4); - specular.rgb = clamp(desaturate(specular).rgb, 0.0, 1.4); + dynlight.rgb = clamp(color + desaturate(dynlight).rgb, 0.0, 1.4); + specular.rgb = clamp(desaturate(specular).rgb, 0.0, 1.4); - vec4 materialSpec = texture(speculartexture, vTexCoord.st); - vec3 frag = material * dynlight.rgb + materialSpec.rgb * specular.rgb; + vec4 materialSpec = texture(speculartexture, vTexCoord.st); + vec3 frag = material * dynlight.rgb + materialSpec.rgb * specular.rgb; + if (uLightIndex >= 0) + { + ivec4 lightRange = ivec4(lights[uLightIndex]) + ivec4(uLightIndex + 1); if (lightRange.w > lightRange.z) { vec4 addlight = vec4(0.0,0.0,0.0,0.0); - + // additive lights for(int i=lightRange.z; i Date: Mon, 12 Mar 2018 22:45:49 +0100 Subject: [PATCH 49/89] - p_glnodes.cpp must include zlib.h --- src/p_glnodes.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/p_glnodes.cpp b/src/p_glnodes.cpp index 540812a0ab..7d0e373397 100644 --- a/src/p_glnodes.cpp +++ b/src/p_glnodes.cpp @@ -45,6 +45,7 @@ #endif +#include #include "templates.h" #include "m_alloc.h" #include "m_argv.h" From fb5eae8aaa0a3e59fe76aa689d4860ebf0cf7cad Mon Sep 17 00:00:00 2001 From: Marisa Kirisame Date: Tue, 13 Mar 2018 00:01:19 +0100 Subject: [PATCH 50/89] Added some missing zlib.h and stdint.h includes --- src/resourcefiles/resourcefile.cpp | 1 + src/serializer.cpp | 1 + src/sound/i_music.cpp | 1 + src/sound/timiditypp/configfile.cpp | 1 + src/sound/timiditypp/sfitem.cpp | 3 ++- 5 files changed, 6 insertions(+), 1 deletion(-) diff --git a/src/resourcefiles/resourcefile.cpp b/src/resourcefiles/resourcefile.cpp index 17c7e87391..adb484d32c 100644 --- a/src/resourcefiles/resourcefile.cpp +++ b/src/resourcefiles/resourcefile.cpp @@ -34,6 +34,7 @@ ** */ +#include #include "resourcefile.h" #include "cmdlib.h" #include "w_wad.h" diff --git a/src/serializer.cpp b/src/serializer.cpp index c41fec1f37..75f96d581b 100644 --- a/src/serializer.cpp +++ b/src/serializer.cpp @@ -37,6 +37,7 @@ #define RAPIDJSON_HAS_CXX11_RANGE_FOR 1 #define RAPIDJSON_PARSE_DEFAULT_FLAGS kParseFullPrecisionFlag +#include #include "rapidjson/rapidjson.h" #include "rapidjson/writer.h" #include "rapidjson/prettywriter.h" diff --git a/src/sound/i_music.cpp b/src/sound/i_music.cpp index e93ba1b091..273ddb1152 100644 --- a/src/sound/i_music.cpp +++ b/src/sound/i_music.cpp @@ -45,6 +45,7 @@ #include #include #include +#include #include "i_musicinterns.h" #include "doomtype.h" diff --git a/src/sound/timiditypp/configfile.cpp b/src/sound/timiditypp/configfile.cpp index 4d728f5ed1..1344a9cd6c 100644 --- a/src/sound/timiditypp/configfile.cpp +++ b/src/sound/timiditypp/configfile.cpp @@ -20,6 +20,7 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA #include #include +#include #include diff --git a/src/sound/timiditypp/sfitem.cpp b/src/sound/timiditypp/sfitem.cpp index 1e2173c1d5..fc7d55e691 100644 --- a/src/sound/timiditypp/sfitem.cpp +++ b/src/sound/timiditypp/sfitem.cpp @@ -24,6 +24,7 @@ *================================================================*/ #include +#include #include "timidity.h" #include "common.h" #include "sflayer.h" @@ -95,4 +96,4 @@ const LayerItem static_layer_items[SF_EOF] = { {L_OVWRT, T_NOCONV, 0, 127, -1}, /* rootKey */ }; -} \ No newline at end of file +} From 251f0c8459c39857fd8b67e8ea70538ec188274e Mon Sep 17 00:00:00 2001 From: raa-eruanna Date: Mon, 12 Mar 2018 22:39:50 -0400 Subject: [PATCH 51/89] - add one more missing include to make GCC happy --- src/sound/timiditypp/timidity.h | 1 + 1 file changed, 1 insertion(+) diff --git a/src/sound/timiditypp/timidity.h b/src/sound/timiditypp/timidity.h index 0c78505682..5fe3667f63 100644 --- a/src/sound/timiditypp/timidity.h +++ b/src/sound/timiditypp/timidity.h @@ -30,6 +30,7 @@ #include "controls.h" #include "mblock.h" +#include #ifdef _MSC_VER #pragma warning(disable:4244) // double->float truncation occurs so often in here that it's pointless to fix it all. From d83456e9cc8321d4b6bc7b5ca37660078410827d Mon Sep 17 00:00:00 2001 From: Rachael Alexanderson Date: Tue, 13 Mar 2018 09:34:15 -0400 Subject: [PATCH 52/89] - fixed: stats checker was not actually checking if it was being run in WOW64 mode --- src/d_stats.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/d_stats.cpp b/src/d_stats.cpp index d2005d4cdc..ebec250bb4 100644 --- a/src/d_stats.cpp +++ b/src/d_stats.cpp @@ -139,7 +139,7 @@ static int GetOSVersion() if (sizeof(void*) == 4) // 32 bit { BOOL res; - if (IsWow64Process(GetCurrentProcess(), &res)) + if (IsWow64Process(GetCurrentProcess(), &res) && res) { return 6; } From 49f590c79742991b22b86599fd210a3a433ba8a2 Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Tue, 13 Mar 2018 20:04:41 +0100 Subject: [PATCH 53/89] - Use the Windows system function to determine the number of physical CPU cores. The generic version does not appear to work as intended. --- src/d_stats.cpp | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/src/d_stats.cpp b/src/d_stats.cpp index ebec250bb4..9f00d2a5cf 100644 --- a/src/d_stats.cpp +++ b/src/d_stats.cpp @@ -185,12 +185,49 @@ static int GetOSVersion() #endif } + +#ifdef _WIN32 + +static int GetCoreInfo() +{ + PSYSTEM_LOGICAL_PROCESSOR_INFORMATION buffer = NULL; + PSYSTEM_LOGICAL_PROCESSOR_INFORMATION ptr = NULL; + DWORD returnLength = 0; + int cores = 0; + uint32_t byteOffset = 0; + + auto rc = GetLogicalProcessorInformation(buffer, &returnLength); + + if (GetLastError() == ERROR_INSUFFICIENT_BUFFER) + { + buffer = (PSYSTEM_LOGICAL_PROCESSOR_INFORMATION)malloc(returnLength); + if (!GetLogicalProcessorInformation(buffer, &returnLength)) return 0; + } + else + { + return 0; + } + + ptr = buffer; + + while (byteOffset + sizeof(SYSTEM_LOGICAL_PROCESSOR_INFORMATION) <= returnLength) + { + if (ptr->Relationship == RelationProcessorCore) cores++; + byteOffset += sizeof(SYSTEM_LOGICAL_PROCESSOR_INFORMATION); + ptr++; + } + free(buffer); + return cores < 2 ? 0 : cores < 4 ? 1 : cores < 6 ? 2 : cores < 8 ? 3 : 4; +} + +#else static int GetCoreInfo() { int cores = std::thread::hardware_concurrency(); if (CPU.HyperThreading) cores /= 2; return cores < 2? 0 : cores < 4? 1 : cores < 6? 2 : cores < 8? 3 : 4; } +#endif static int GetRenderInfo() { From bdeae23a56609dabdefa5908417e242b80bc4a0e Mon Sep 17 00:00:00 2001 From: "alexey.lysiuk" Date: Wed, 14 Mar 2018 10:20:46 +0200 Subject: [PATCH 54/89] Added native UI dialog to confirm stats collection Implemented only for Windows so far Need good message to explain purpose of this feature --- src/d_main.cpp | 3 +++ src/d_stats.cpp | 30 ++++++++++++++++++++++++++++++ 2 files changed, 33 insertions(+) diff --git a/src/d_main.cpp b/src/d_main.cpp index 6338f9b042..007af39d51 100644 --- a/src/d_main.cpp +++ b/src/d_main.cpp @@ -2352,6 +2352,9 @@ void D_DoomMain (void) D_DoomInit(); + extern void D_ConfirmSendStats(); + D_ConfirmSendStats(); + // [RH] Make sure zdoom.pk3 is always loaded, // as it contains magic stuff we need. wad = BaseFileSearch (BASEWAD, NULL, true); diff --git a/src/d_stats.cpp b/src/d_stats.cpp index 9f00d2a5cf..73db23740e 100644 --- a/src/d_stats.cpp +++ b/src/d_stats.cpp @@ -20,6 +20,8 @@ extern int sys_ostype; EXTERN_CVAR(Bool, vid_glswfb) extern int currentrenderer; + +CVAR(Int, sys_statsenabled, -1, CVAR_ARCHIVE | CVAR_GLOBALCONFIG | CVAR_NOSET) CVAR(String, sys_statshost, "gzstats.drdteam.org", CVAR_ARCHIVE|CVAR_GLOBALCONFIG|CVAR_NOSET) CVAR(Int, sys_statsport, 80, CVAR_ARCHIVE|CVAR_GLOBALCONFIG|CVAR_NOSET) @@ -264,6 +266,11 @@ static void D_DoHTTPRequest(const char *request) void D_DoAnonStats() { + if (sys_statsenabled != 1) + { + return; + } + static bool done = false; // do this only once per session. if (done) return; done = true; @@ -279,3 +286,26 @@ void D_DoAnonStats() std::thread t1(D_DoHTTPRequest, requeststring); t1.detach(); } + +void D_ConfirmSendStats() +{ + if (sys_statsenabled >= 0) + { + return; + } + + // TODO: texts + static const char *const MESSAGE_TEXT = "send stats?"; + static const char *const TITLE_TEXT = GAMENAME; + + UCVarValue enabled = { 0 }; + +#ifdef _WIN32 + extern HWND Window; + enabled = { MessageBox(Window, MESSAGE_TEXT, TITLE_TEXT, MB_ICONQUESTION | MB_YESNO) == IDYES }; +#else + // TODO +#endif + + sys_statsenabled.ForceSet(enabled, CVAR_Int); +} From 549a290a2f6c193d75f5514289abd3f5b6370a4c Mon Sep 17 00:00:00 2001 From: Rachael Alexanderson Date: Wed, 14 Mar 2018 11:40:47 -0400 Subject: [PATCH 55/89] - add 'renderconfig' for the stats script to easily differentiate between OpenGL and software --- src/d_stats.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/d_stats.cpp b/src/d_stats.cpp index 9f00d2a5cf..330fa75eca 100644 --- a/src/d_stats.cpp +++ b/src/d_stats.cpp @@ -273,8 +273,8 @@ void D_DoAnonStats() if (currentrenderer == 1 && sentstats_hwr_done >= CHECKVERSION) return; static char requeststring[1024]; - sprintf(requeststring, "GET /stats.php?render=%i&cores=%i&os=%i HTTP/1.1\nHost: %s\nConnection: close\nUser-Agent: %s %s\n\n", - GetRenderInfo(), GetCoreInfo(), GetOSVersion(), sys_statshost.GetHumanString(), GAMENAME, VERSIONSTR); + sprintf(requeststring, "GET /stats.php?render=%i&cores=%i&os=%i&renderconfig=%i HTTP/1.1\nHost: %s\nConnection: close\nUser-Agent: %s %s\n\n", + GetRenderInfo(), GetCoreInfo(), GetOSVersion(), currentrenderer, sys_statshost.GetHumanString(), GAMENAME, VERSIONSTR); DPrintf(DMSG_NOTIFY, "Sending %s", requeststring); std::thread t1(D_DoHTTPRequest, requeststring); t1.detach(); From f1bfc3514dd2809bfed60849652f4918d3936e31 Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Wed, 14 Mar 2018 19:52:30 +0100 Subject: [PATCH 56/89] - fixed: For proper recognition of optional function arguments, the argflags must also be copied from the parent function to ensure they are itdentical on the override. --- src/scripting/zscript/zcc_compile.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/scripting/zscript/zcc_compile.cpp b/src/scripting/zscript/zcc_compile.cpp index 279d9adda3..4d530c8a58 100644 --- a/src/scripting/zscript/zcc_compile.cpp +++ b/src/scripting/zscript/zcc_compile.cpp @@ -2743,6 +2743,7 @@ void ZCCCompiler::CompileFunction(ZCC_StructWork *c, ZCC_FuncDeclarator *f, bool if (parentfunc->Variants[0].Implementation->DefaultArgs.Size() > 0) { sym->Variants[0].Implementation->DefaultArgs = parentfunc->Variants[0].Implementation->DefaultArgs; + sym->Variants[0].ArgFlags = parentfunc->Variants[0].ArgFlags; } } } From a9802f82f41e8918a997798733b88073fcfef4cc Mon Sep 17 00:00:00 2001 From: "alexey.lysiuk" Date: Wed, 14 Mar 2018 22:19:33 +0200 Subject: [PATCH 57/89] Replaced usages of sprintf() in stats sender --- src/d_stats.cpp | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/src/d_stats.cpp b/src/d_stats.cpp index 330fa75eca..5886d4cef5 100644 --- a/src/d_stats.cpp +++ b/src/d_stats.cpp @@ -113,18 +113,15 @@ bool I_HTTPRequest(const char* request) return false; } - char buffer[1024]; - sprintf(buffer, "%s", request); - Printf("Buffer: %s", buffer); - n = write(sockfd, (char*)buffer, (int)strlen(request)); + n = write(sockfd, request, strlen(request)); if (n<0) { DPrintf(DMSG_ERROR, "Error writing to socket.\n"); close(sockfd); return false; } - bzero(buffer, 1024); + char buffer[1024] = {}; n = read(sockfd, buffer, 1023); close(sockfd); DPrintf(DMSG_NOTIFY, "Stats send successful.\n"); @@ -273,7 +270,7 @@ void D_DoAnonStats() if (currentrenderer == 1 && sentstats_hwr_done >= CHECKVERSION) return; static char requeststring[1024]; - sprintf(requeststring, "GET /stats.php?render=%i&cores=%i&os=%i&renderconfig=%i HTTP/1.1\nHost: %s\nConnection: close\nUser-Agent: %s %s\n\n", + mysnprintf(requeststring, sizeof requeststring, "GET /stats.php?render=%i&cores=%i&os=%i&renderconfig=%i HTTP/1.1\nHost: %s\nConnection: close\nUser-Agent: %s %s\n\n", GetRenderInfo(), GetCoreInfo(), GetOSVersion(), currentrenderer, sys_statshost.GetHumanString(), GAMENAME, VERSIONSTR); DPrintf(DMSG_NOTIFY, "Sending %s", requeststring); std::thread t1(D_DoHTTPRequest, requeststring); From 9a737a06226e44dd295231b500f9418d3d5104fc Mon Sep 17 00:00:00 2001 From: "alexey.lysiuk" Date: Fri, 16 Mar 2018 15:47:23 +0200 Subject: [PATCH 58/89] Added ability to turn off sending of stats in CMake configuration --- src/CMakeLists.txt | 6 ++++++ src/d_stats.cpp | 11 +++++++++++ 2 files changed, 17 insertions(+) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 58ca6a9ba9..e75798a549 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -639,6 +639,12 @@ elseif( FLUIDSYNTH_FOUND ) add_definitions( -DHAVE_FLUIDSYNTH ) endif() +option( SEND_ANON_STATS "Enable sending of anonymous hardware statistics" ON ) + +if( NOT SEND_ANON_STATS ) + add_definitions( -DNO_SEND_STATS ) +endif() + # Project files should be aware of the header files. We can GLOB these since # there's generally a new cpp for every header so this file will get changed if( WIN32 ) diff --git a/src/d_stats.cpp b/src/d_stats.cpp index 5886d4cef5..9ea3e80b57 100644 --- a/src/d_stats.cpp +++ b/src/d_stats.cpp @@ -1,3 +1,12 @@ + +#ifdef NO_SEND_STATS + +void D_DoAnonStats() +{ +} + +#else // !NO_SEND_STATS + #if defined(_WIN32) #define _WIN32_WINNT 0x0501 #define WIN32_LEAN_AND_MEAN @@ -276,3 +285,5 @@ void D_DoAnonStats() std::thread t1(D_DoHTTPRequest, requeststring); t1.detach(); } + +#endif // NO_SEND_STATS From a2b9a70835aaac8613c1903e44865c94c8c21ef0 Mon Sep 17 00:00:00 2001 From: Magnus Norddahl Date: Sat, 17 Mar 2018 00:09:43 +0100 Subject: [PATCH 59/89] - Fix crash when reloading a map --- src/polyrenderer/scene/poly_cull.cpp | 31 +++++++++------------------ src/polyrenderer/scene/poly_cull.h | 4 ++-- src/polyrenderer/scene/poly_scene.cpp | 9 ++++---- 3 files changed, 17 insertions(+), 27 deletions(-) diff --git a/src/polyrenderer/scene/poly_cull.cpp b/src/polyrenderer/scene/poly_cull.cpp index a3361fd627..d53e0e1bfc 100644 --- a/src/polyrenderer/scene/poly_cull.cpp +++ b/src/polyrenderer/scene/poly_cull.cpp @@ -33,26 +33,15 @@ void PolyCull::CullScene(const PolyClipPlane &portalClipPlane) ClearSolidSegments(); MarkViewFrustum(); - if (level.LevelName != lastLevelName) // Is this the best way to detect a level change? - { - lastLevelName = level.LevelName; - SubsectorDepths.clear(); - SubsectorDepths.resize(level.subsectors.Size(), 0xffffffff); - SectorSeen.clear(); - SectorSeen.resize(level.sectors.Size()); - } - else - { - for (const auto &sub : PvsSectors) - SubsectorDepths[sub->Index()] = 0xffffffff; - SubsectorDepths.resize(level.subsectors.Size(), 0xffffffff); + for (uint32_t sub : PvsSubsectors) + SubsectorDepths[sub] = 0xffffffff; + SubsectorDepths.resize(level.subsectors.Size(), 0xffffffff); - for (const auto §or : SeenSectors) - SectorSeen[sector->Index()] = false; - SectorSeen.resize(level.sectors.Size()); - } + for (uint32_t sector : SeenSectors) + SectorSeen[sector] = false; + SectorSeen.resize(level.sectors.Size()); - PvsSectors.clear(); + PvsSubsectors.clear(); SeenSectors.clear(); NextPvsLineStart = 0; @@ -125,10 +114,10 @@ void PolyCull::CullSubsector(subsector_t *sub) FirstSkyHeight = false; } - uint32_t subsectorDepth = (uint32_t)PvsSectors.size(); + uint32_t subsectorDepth = (uint32_t)PvsSubsectors.size(); // Mark that we need to render this - PvsSectors.push_back(sub); + PvsSubsectors.push_back(sub->Index()); PvsLineStart.push_back(NextPvsLineStart); DVector3 viewpos = PolyRenderer::Instance()->Viewpoint.Pos; @@ -169,7 +158,7 @@ void PolyCull::CullSubsector(subsector_t *sub) if (!SectorSeen[sub->sector->Index()]) { SectorSeen[sub->sector->Index()] = true; - SeenSectors.push_back(sub->sector); + SeenSectors.push_back(sub->sector->Index()); } SubsectorDepths[sub->Index()] = subsectorDepth; diff --git a/src/polyrenderer/scene/poly_cull.h b/src/polyrenderer/scene/poly_cull.h index 474a33bb6c..4b851373e6 100644 --- a/src/polyrenderer/scene/poly_cull.h +++ b/src/polyrenderer/scene/poly_cull.h @@ -36,11 +36,11 @@ public: return PvsLineVisible[PvsLineStart[subsectorDepth] + lineIndex]; } - std::vector PvsSectors; + std::vector PvsSubsectors; double MaxCeilingHeight = 0.0; double MinFloorHeight = 0.0; - std::vector SeenSectors; + std::vector SeenSectors; std::vector SectorSeen; std::vector SubsectorDepths; diff --git a/src/polyrenderer/scene/poly_scene.cpp b/src/polyrenderer/scene/poly_scene.cpp index 02ad1842ed..42f6e815b0 100644 --- a/src/polyrenderer/scene/poly_scene.cpp +++ b/src/polyrenderer/scene/poly_scene.cpp @@ -69,8 +69,8 @@ void RenderPolyScene::RenderSectors() { PolyRenderThread *mainthread = PolyRenderer::Instance()->Threads.MainThread(); - int totalcount = (int)Cull.PvsSectors.size(); - auto subsectors = Cull.PvsSectors.data(); + int totalcount = (int)Cull.PvsSubsectors.size(); + uint32_t *subsectors = Cull.PvsSubsectors.data(); TranslucentObjects.resize(PolyRenderer::Instance()->Threads.NumThreads()); @@ -82,7 +82,7 @@ void RenderPolyScene::RenderSectors() int end = thread->End; for (int i = start; i < end; i++) { - RenderSubsector(thread, subsectors[i], i); + RenderSubsector(thread, &level.subsectors[subsectors[i]], i); } }, [&](PolyRenderThread *thread) { @@ -372,8 +372,9 @@ void RenderPolyScene::RenderTranslucent(int portalDepth) } const auto &viewpoint = PolyRenderer::Instance()->Viewpoint; - for (sector_t *sector : Cull.SeenSectors) + for (uint32_t sectorIndex : Cull.SeenSectors) { + sector_t *sector = &level.sectors[sectorIndex]; for (AActor *thing = sector->thinglist; thing != nullptr; thing = thing->snext) { DVector2 left, right; From b4d37153452f9b63156d907eb92d5225dc66400e Mon Sep 17 00:00:00 2001 From: "alexey.lysiuk" Date: Sat, 17 Mar 2018 12:29:55 +0200 Subject: [PATCH 60/89] Fixed status bar chain wiggling when paused Made ZScript implementation of chain wiggling in Heretic status bar as close as possible to C++ SBARINFO one https://forum.zdoom.org/viewtopic.php?t=59840 --- wadsrc/static/zscript/statusbar/heretic_sbar.txt | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/wadsrc/static/zscript/statusbar/heretic_sbar.txt b/wadsrc/static/zscript/statusbar/heretic_sbar.txt index 691a89e332..8d490444e2 100644 --- a/wadsrc/static/zscript/statusbar/heretic_sbar.txt +++ b/wadsrc/static/zscript/statusbar/heretic_sbar.txt @@ -6,6 +6,7 @@ class HereticStatusBar : BaseStatusBar HUDFont mBigFont; InventoryBarState diparms; InventoryBarState diparms_sbar; + private int wiggle; override void Init() @@ -40,6 +41,12 @@ class HereticStatusBar : BaseStatusBar { Super.Tick(); mHealthInterpolator.Update(CPlayer.health); + + // wiggle the chain if it moves + if (level.time & 1) + { + wiggle = (mHealthInterpolator.GetValue() != CPlayer.health) && Random[ChainWiggle](0, 1); + } } override void Draw (int state, double TicFrac) @@ -73,7 +80,6 @@ class HereticStatusBar : BaseStatusBar DrawImage("CHAINCAC", (0, 190), DI_ITEM_OFFSETS); // wiggle the chain if it moves int inthealth = mHealthInterpolator.GetValue(); - int wiggle = (inthealth != CPlayer.health) && Random[ChainWiggle](0, 1); DrawGem("CHAIN", "LIFEGEM2",inthealth, CPlayer.mo.GetMaxHealth(true), (2, 191 + wiggle), 15, 25, 16, (multiplayer? DI_TRANSLATABLE : 0) | DI_ITEM_LEFT_TOP); DrawImage("LTFACE", (0, 190), DI_ITEM_OFFSETS); DrawImage("RTFACE", (276, 190), DI_ITEM_OFFSETS); From ecff13ac2eecaf7cc6fe0dbfb8759ca59d8cae20 Mon Sep 17 00:00:00 2001 From: "alexey.lysiuk" Date: Sat, 17 Mar 2018 22:38:41 +0200 Subject: [PATCH 61/89] Fixed crash on attempt to send stats without network connection https://forum.zdoom.org/viewtopic.php?t=59844 --- src/d_stats.cpp | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/d_stats.cpp b/src/d_stats.cpp index 9ea3e80b57..58c83dfae1 100644 --- a/src/d_stats.cpp +++ b/src/d_stats.cpp @@ -57,6 +57,11 @@ bool I_HTTPRequest(const char* request) SOCKET Socket = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP); struct hostent *host; host = gethostbyname(sys_statshost.GetHumanString()); + if (host == nullptr) + { + DPrintf(DMSG_ERROR, "Error looking up hostname.\n"); + return false; + } SOCKADDR_IN SockAddr; SockAddr.sin_port = htons(sys_statsport); SockAddr.sin_family = AF_INET; From 75782e6b349e12ebfdf43b43090747fdc7655d54 Mon Sep 17 00:00:00 2001 From: "alexey.lysiuk" Date: Sun, 18 Mar 2018 11:02:21 +0200 Subject: [PATCH 62/89] Exported Inventory.AltHUDIcon field to ZScript https://forum.zdoom.org/viewtopic.php?t=59842 --- src/g_inventory/a_pickups.cpp | 2 ++ wadsrc/static/zscript/inventory/inventory.txt | 1 + 2 files changed, 3 insertions(+) diff --git a/src/g_inventory/a_pickups.cpp b/src/g_inventory/a_pickups.cpp index ff98ea4219..2ed33954b1 100644 --- a/src/g_inventory/a_pickups.cpp +++ b/src/g_inventory/a_pickups.cpp @@ -82,6 +82,7 @@ DEFINE_FIELD(AInventory, MaxAmount) DEFINE_FIELD(AInventory, InterHubAmount) DEFINE_FIELD(AInventory, RespawnTics) DEFINE_FIELD(AInventory, Icon) +DEFINE_FIELD(AInventory, AltHUDIcon) DEFINE_FIELD(AInventory, DropTime) DEFINE_FIELD(AInventory, SpawnPointClass) DEFINE_FIELD(AInventory, PickupFlash) @@ -147,6 +148,7 @@ void AInventory::Serialize(FSerializer &arc) ("respawntics", RespawnTics, def->RespawnTics) ("itemflags", ItemFlags, def->ItemFlags) ("icon", Icon, def->Icon) + ("althudicon", AltHUDIcon, def->AltHUDIcon) ("pickupsound", PickupSound, def->PickupSound) ("spawnpointclass", SpawnPointClass, def->SpawnPointClass) ("droptime", DropTime, def->DropTime); diff --git a/wadsrc/static/zscript/inventory/inventory.txt b/wadsrc/static/zscript/inventory/inventory.txt index e7786059b0..1bc3f42a6a 100644 --- a/wadsrc/static/zscript/inventory/inventory.txt +++ b/wadsrc/static/zscript/inventory/inventory.txt @@ -16,6 +16,7 @@ class Inventory : Actor native native int InterHubAmount; // Amount of item that can be kept between hubs or levels native int RespawnTics; // Tics from pickup time to respawn time native TextureID Icon; // Icon to show on status bar or HUD + native TextureID AltHUDIcon; native int DropTime; // Countdown after dropping native Class SpawnPointClass; // For respawning like Heretic's mace native Class PickupFlash; // actor to spawn as pickup flash From 341a9bcf91054dd2c6346126d2418f8e0d1692c1 Mon Sep 17 00:00:00 2001 From: "alexey.lysiuk" Date: Sun, 18 Mar 2018 11:23:24 +0200 Subject: [PATCH 63/89] Added target and last enemy to linetarget CCMD output https://forum.zdoom.org/viewtopic.php?t=59716 --- src/p_mobj.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/p_mobj.cpp b/src/p_mobj.cpp index 371e3f9773..e27ab198c0 100644 --- a/src/p_mobj.cpp +++ b/src/p_mobj.cpp @@ -8516,5 +8516,7 @@ void PrintMiscActorInfo(AActor *query) query->Speed, query->Vel.X, query->Vel.Y, query->Vel.Z, query->Vel.Length()); Printf("Scale: x:%f, y:%f\n", query->Scale.X, query->Scale.Y); Printf("FriendlySeeBlocks: %d\n", query->friendlyseeblocks); + Printf("Target: %s\n", query->target ? query->target->GetClass()->TypeName.GetChars() : "-"); + Printf("Last enemy: %s\n", query->lastenemy ? query->lastenemy->GetClass()->TypeName.GetChars() : "-"); } } From 102d2647d36b20f5685ce118d65904b20ed125ac Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Sun, 18 Mar 2018 11:57:41 +0100 Subject: [PATCH 64/89] - removed support for loading Build palettes as the main game palette. This was implemented in a way that made it entirely impossible to load Build resources and make them usable for modding. ZDoom had Build texture support for many years but the limitations the palette handling imposed made it impossible to use them. It wasn't usable for anything more than to load Build maps and have them display properly - a feature that had to be removed because it was irreparably broken already. With the forced palette override out of the way it should now be possible to implement loading of Build ART files as actually usable resources. --- src/v_palette.cpp | 26 +++++--------------------- 1 file changed, 5 insertions(+), 21 deletions(-) diff --git a/src/v_palette.cpp b/src/v_palette.cpp index 11e3f69456..436fe84dcd 100644 --- a/src/v_palette.cpp +++ b/src/v_palette.cpp @@ -377,32 +377,16 @@ void InitPalette () bool usingBuild = false; int lump; - if ((lump = Wads.CheckNumForFullName ("palette.dat")) >= 0 && Wads.LumpLength (lump) >= 768) - { - usingBuild = FixBuildPalette (pal, lump, false); - } - else if ((lump = Wads.CheckNumForFullName ("blood.pal")) >= 0 && Wads.LumpLength (lump) >= 768) - { - usingBuild = FixBuildPalette (pal, lump, true); - } - - if (!usingBuild) - { - ReadPalette(Wads.CheckNumForName("PLAYPAL"), pal); - } + ReadPalette(Wads.CheckNumForName("PLAYPAL"), pal); GPalette.SetPalette (pal); GPalette.MakeGoodRemap (); ColorMatcher.SetPalette ((uint32_t *)GPalette.BaseColors); - // The BUILD engine already has a transparent color, so it doesn't need any remapping. - if (!usingBuild) - { - if (GPalette.Remap[0] == 0) - { // No duplicates, so settle for something close to color 0 - GPalette.Remap[0] = BestColor ((uint32_t *)GPalette.BaseColors, - GPalette.BaseColors[0].r, GPalette.BaseColors[0].g, GPalette.BaseColors[0].b, 1, 255); - } + if (GPalette.Remap[0] == 0) + { // No duplicates, so settle for something close to color 0 + GPalette.Remap[0] = BestColor ((uint32_t *)GPalette.BaseColors, + GPalette.BaseColors[0].r, GPalette.BaseColors[0].g, GPalette.BaseColors[0].b, 1, 255); } // Colormaps have to be initialized before actors are loaded, From 832fc42e07caff1a4f09503cdc23cb1d3195366f Mon Sep 17 00:00:00 2001 From: "alexey.lysiuk" Date: Sun, 18 Mar 2018 13:26:04 +0200 Subject: [PATCH 65/89] Added native UI dialog to confirm stats collection --- src/d_main.cpp | 3 +++ src/d_stats.cpp | 66 +++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 69 insertions(+) diff --git a/src/d_main.cpp b/src/d_main.cpp index 6338f9b042..007af39d51 100644 --- a/src/d_main.cpp +++ b/src/d_main.cpp @@ -2352,6 +2352,9 @@ void D_DoomMain (void) D_DoomInit(); + extern void D_ConfirmSendStats(); + D_ConfirmSendStats(); + // [RH] Make sure zdoom.pk3 is always loaded, // as it contains magic stuff we need. wad = BaseFileSearch (BASEWAD, NULL, true); diff --git a/src/d_stats.cpp b/src/d_stats.cpp index 58c83dfae1..6205bf60f3 100644 --- a/src/d_stats.cpp +++ b/src/d_stats.cpp @@ -5,6 +5,10 @@ void D_DoAnonStats() { } +void D_ConfirmSendStats() +{ +} + #else // !NO_SEND_STATS #if defined(_WIN32) @@ -14,6 +18,11 @@ void D_DoAnonStats() #include extern int sys_ostype; #else +#ifdef __APPLE__ +#include +#else // !__APPLE__ +#include +#endif // __APPLE__ #include #include #include @@ -29,6 +38,7 @@ extern int sys_ostype; EXTERN_CVAR(Bool, vid_glswfb) extern int currentrenderer; +CVAR(Int, sys_statsenabled, -1, CVAR_ARCHIVE | CVAR_GLOBALCONFIG | CVAR_NOSET) CVAR(String, sys_statshost, "gzstats.drdteam.org", CVAR_ARCHIVE|CVAR_GLOBALCONFIG|CVAR_NOSET) CVAR(Int, sys_statsport, 80, CVAR_ARCHIVE|CVAR_GLOBALCONFIG|CVAR_NOSET) @@ -275,6 +285,11 @@ static void D_DoHTTPRequest(const char *request) void D_DoAnonStats() { + if (sys_statsenabled != 1) + { + return; + } + static bool done = false; // do this only once per session. if (done) return; done = true; @@ -291,4 +306,55 @@ void D_DoAnonStats() t1.detach(); } +void D_ConfirmSendStats() +{ + if (sys_statsenabled >= 0) + { + return; + } + + // TODO: texts + static const char *const MESSAGE_TEXT = "send stats?"; + static const char *const TITLE_TEXT = GAMENAME; + + UCVarValue enabled = { 0 }; + +#ifdef _WIN32 + extern HWND Window; + enabled.Int = MessageBox(Window, MESSAGE_TEXT, TITLE_TEXT, MB_ICONQUESTION | MB_YESNO) == IDYES; +#elif defined __APPLE__ + const CFStringRef messageString = CFStringCreateWithCStringNoCopy(kCFAllocatorDefault, MESSAGE_TEXT, kCFStringEncodingASCII, kCFAllocatorNull); + const CFStringRef titleString = CFStringCreateWithCStringNoCopy(kCFAllocatorDefault, TITLE_TEXT, kCFStringEncodingASCII, kCFAllocatorNull); + if (messageString != nullptr && titleString != nullptr) + { + CFOptionFlags response; + const SInt32 result = CFUserNotificationDisplayAlert(0, kCFUserNotificationNoteAlertLevel, nullptr, nullptr, nullptr, + titleString, messageString, CFSTR("Yes"), CFSTR("No"), nullptr, &response); + enabled.Int = result == 0 && (response & 3) == kCFUserNotificationDefaultResponse; + CFRelease(titleString); + CFRelease(messageString); + } +#else // !__APPLE__ + const SDL_MessageBoxButtonData buttons[] = + { + { SDL_MESSAGEBOX_BUTTON_RETURNKEY_DEFAULT, 0, "Yes" }, + { SDL_MESSAGEBOX_BUTTON_ESCAPEKEY_DEFAULT, 1, "No" }, + }; + const SDL_MessageBoxData messageboxdata = + { + SDL_MESSAGEBOX_INFORMATION, + nullptr, + TITLE_TEXT, + MESSAGE_TEXT, + SDL_arraysize(buttons), + buttons, + nullptr + }; + int buttonid; + enabled.Int = SDL_ShowMessageBox(&messageboxdata, &buttonid) == 0 && buttonid == 0; +#endif // _WIN32 + + sys_statsenabled.ForceSet(enabled, CVAR_Int); +} + #endif // NO_SEND_STATS From 7e169eb76fbe41900e7496cb3fa133d872b88256 Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Sun, 18 Mar 2018 12:36:14 +0100 Subject: [PATCH 66/89] - split out the span generation from most texture classes Until now each subclass of FTexture had to implement the entire span generation itself, presumably so that a few classes can use simpler structures. This does not work if a texture can have more than one pixel buffer as is needed for alpha textures. Even though it means that some classes will allocate more data now, it's the only way to do it properly. In addition this removes a significant amount of mostly redundant code from the texture classes. - added alpha texture processing to all converted classes As of now this is not active and not tested. Note that as part of the conversion even those textures that were working as alphatextures will not look correct until the higher level code gets adjusted. --- src/CMakeLists.txt | 1 + src/gl/textures/gl_texture.cpp | 21 +- src/gl/textures/gl_texture.h | 14 +- src/r_data/models/models_voxel.cpp | 75 ++----- src/swrenderer/line/r_walldraw.cpp | 1 - src/textures/automaptexture.cpp | 93 +-------- src/textures/bitmap.cpp | 3 +- src/textures/bitmap.h | 10 + src/textures/ddstexture.cpp | 230 ++++++++------------ src/textures/emptytexture.cpp | 47 +---- src/textures/flattexture.cpp | 103 +-------- src/textures/imgztexture.cpp | 111 +--------- src/textures/jpegtexture.cpp | 325 ++++++++++++----------------- src/textures/multipatchtexture.cpp | 147 ++++--------- src/textures/patchtexture.cpp | 163 +++------------ src/textures/pcxtexture.cpp | 110 ++-------- src/textures/pngtexture.cpp | 205 ++++++------------ src/textures/rawpagetexture.cpp | 98 +-------- src/textures/texture.cpp | 9 +- src/textures/textures.h | 34 ++- src/textures/tgatexture.cpp | 126 ++--------- 21 files changed, 497 insertions(+), 1429 deletions(-) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index e75798a549..cfd970d6db 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -1110,6 +1110,7 @@ set (PCH_SOURCES textures/tgatexture.cpp textures/warptexture.cpp textures/skyboxtexture.cpp + textures/worldtexture.cpp xlat/parse_xlat.cpp fragglescript/t_func.cpp fragglescript/t_load.cpp diff --git a/src/gl/textures/gl_texture.cpp b/src/gl/textures/gl_texture.cpp index 0d3e84e4b3..0680ccdd69 100644 --- a/src/gl/textures/gl_texture.cpp +++ b/src/gl/textures/gl_texture.cpp @@ -523,24 +523,11 @@ FBrightmapTexture::FBrightmapTexture (FTexture *source) SourceLump = -1; } -FBrightmapTexture::~FBrightmapTexture () -{ -} - -const uint8_t *FBrightmapTexture::GetColumn (unsigned int column, const Span **spans_out) -{ - // not needed - return NULL; -} - -const uint8_t *FBrightmapTexture::GetPixels () -{ - // not needed - return NULL; -} - -void FBrightmapTexture::Unload () +uint8_t *FBrightmapTexture::MakeTexture(FRenderStyle style) { + // This function is only necessary to satisfy the parent class's interface. + // This will never be called. + return nullptr; } int FBrightmapTexture::CopyTrueColorPixels(FBitmap *bmp, int x, int y, int rotate, FCopyInfo *inf) diff --git a/src/gl/textures/gl_texture.h b/src/gl/textures/gl_texture.h index 80eede02ff..44016f181a 100644 --- a/src/gl/textures/gl_texture.h +++ b/src/gl/textures/gl_texture.h @@ -4,23 +4,17 @@ #include "r_defs.h" #include "textures/textures.h" -class FBrightmapTexture : public FTexture +class FBrightmapTexture : public FWorldTexture { public: FBrightmapTexture (FTexture *source); - ~FBrightmapTexture (); - const uint8_t *GetColumn (unsigned int column, const Span **spans_out); - const uint8_t *GetPixels (); - void Unload (); - - int CopyTrueColorPixels(FBitmap *bmp, int x, int y, int rotate, FCopyInfo *inf); - bool UseBasePalette() { return false; } + uint8_t *MakeTexture(FRenderStyle style) override; + int CopyTrueColorPixels(FBitmap *bmp, int x, int y, int rotate, FCopyInfo *inf) override; + bool UseBasePalette() override { return false; } protected: FTexture *SourcePic; - //uint8_t *Pixels; - //Span **Spans; }; diff --git a/src/r_data/models/models_voxel.cpp b/src/r_data/models/models_voxel.cpp index 848f5a54d3..9533aca690 100644 --- a/src/r_data/models/models_voxel.cpp +++ b/src/r_data/models/models_voxel.cpp @@ -53,23 +53,17 @@ // //=========================================================================== -class FVoxelTexture : public FTexture +class FVoxelTexture : public FWorldTexture { public: - FVoxelTexture(FVoxel *voxel); - ~FVoxelTexture(); - const uint8_t *GetColumn (unsigned int column, const Span **spans_out); - const uint8_t *GetPixels (); - void Unload (); - int CopyTrueColorPixels(FBitmap *bmp, int x, int y, int rotate, FCopyInfo *inf); - bool UseBasePalette() { return false; } + int CopyTrueColorPixels(FBitmap *bmp, int x, int y, int rotate, FCopyInfo *inf) override; + bool UseBasePalette() override { return false; } + uint8_t *MakeTexture(FRenderStyle style) override; protected: FVoxel *SourceVox; - uint8_t *Pixels; - }; //=========================================================================== @@ -86,7 +80,6 @@ FVoxelTexture::FVoxelTexture(FVoxel *vox) WidthBits = 4; HeightBits = 4; WidthMask = 15; - Pixels = NULL; gl_info.bNoFilter = true; gl_info.bNoCompress = true; } @@ -97,54 +90,32 @@ FVoxelTexture::FVoxelTexture(FVoxel *vox) // //=========================================================================== -FVoxelTexture::~FVoxelTexture() -{ -} - -const uint8_t *FVoxelTexture::GetColumn (unsigned int column, const Span **spans_out) -{ - // not needed - return NULL; -} - -const uint8_t *FVoxelTexture::GetPixels () +uint8_t *FVoxelTexture::MakeTexture (FRenderStyle style) { // GetPixels gets called when a translated palette is used so we still need to implement it here. - if (Pixels == NULL) + auto Pixels = new uint8_t[256]; + uint8_t *pp = SourceVox->Palette; + + if(pp != NULL) { - Pixels = new uint8_t[256]; - - uint8_t *pp = SourceVox->Palette; - - if(pp != NULL) + for(int i=0;i<256;i++, pp+=3) { - for(int i=0;i<256;i++, pp+=3) - { - PalEntry pe; - pe.r = (pp[0] << 2) | (pp[0] >> 4); - pe.g = (pp[1] << 2) | (pp[1] >> 4); - pe.b = (pp[2] << 2) | (pp[2] >> 4); - Pixels[i] = ColorMatcher.Pick(pe); - } + PalEntry pe; + pe.r = (pp[0] << 2) | (pp[0] >> 4); + pe.g = (pp[1] << 2) | (pp[1] >> 4); + pe.b = (pp[2] << 2) | (pp[2] >> 4); + // Alphatexture handling is just for completeness, but rather unlikely to be used ever. + Pixels[i] = (style.Flags & STYLEF_RedIsAlpha)? pe.r : ColorMatcher.Pick(pe); } - else - { - for(int i=0;i<256;i++, pp+=3) - { - Pixels[i] = (uint8_t)i; - } - } } - return Pixels; -} - -void FVoxelTexture::Unload () -{ - if (Pixels != NULL) + else { - delete[] Pixels; - Pixels = NULL; - } + for(int i=0;i<256;i++, pp+=3) + { + Pixels[i] = (uint8_t)i; + } + } + return Pixels; } //=========================================================================== diff --git a/src/swrenderer/line/r_walldraw.cpp b/src/swrenderer/line/r_walldraw.cpp index 5b7518440a..ac277a0aee 100644 --- a/src/swrenderer/line/r_walldraw.cpp +++ b/src/swrenderer/line/r_walldraw.cpp @@ -330,7 +330,6 @@ namespace swrenderer if (rw_pic->UseType == FTexture::TEX_Null) return; - rw_pic->GetHeight(); // To ensure that rw_pic->HeightBits has been set int fracbits = 32 - rw_pic->HeightBits; if (fracbits == 32) { // Hack for one pixel tall textures diff --git a/src/textures/automaptexture.cpp b/src/textures/automaptexture.cpp index 3bd16f5bca..27080669ee 100644 --- a/src/textures/automaptexture.cpp +++ b/src/textures/automaptexture.cpp @@ -38,6 +38,7 @@ #include "doomtype.h" #include "files.h" #include "w_wad.h" +#include "v_palette.h" #include "textures/textures.h" //========================================================================== @@ -46,21 +47,12 @@ // //========================================================================== -class FAutomapTexture : public FTexture +class FAutomapTexture : public FWorldTexture { public: + FAutomapTexture(int lumpnum); ~FAutomapTexture (); - - const uint8_t *GetColumn (unsigned int column, const Span **spans_out); - const uint8_t *GetPixels (); - void Unload (); - void MakeTexture (); - - FAutomapTexture (int lumpnum); - -private: - uint8_t *Pixels; - Span DummySpan[2]; + uint8_t *MakeTexture (FRenderStyle style); }; @@ -86,16 +78,11 @@ FTexture *AutomapTexture_TryCreate(FileReader &data, int lumpnum) //========================================================================== FAutomapTexture::FAutomapTexture (int lumpnum) -: FTexture(NULL, lumpnum), Pixels(NULL) +: FWorldTexture(NULL, lumpnum) { Width = 320; Height = uint16_t(Wads.LumpLength(lumpnum) / 320); CalcBitSize (); - - DummySpan[0].TopOffset = 0; - DummySpan[0].Length = Height; - DummySpan[1].TopOffset = 0; - DummySpan[1].Length = 0; } //========================================================================== @@ -104,84 +91,22 @@ FAutomapTexture::FAutomapTexture (int lumpnum) // //========================================================================== -FAutomapTexture::~FAutomapTexture () -{ - Unload (); -} - -//========================================================================== -// -// -// -//========================================================================== - -void FAutomapTexture::Unload () -{ - if (Pixels != NULL) - { - delete[] Pixels; - Pixels = NULL; - } - FTexture::Unload(); -} - -//========================================================================== -// -// -// -//========================================================================== - -void FAutomapTexture::MakeTexture () +uint8_t *FAutomapTexture::MakeTexture (FRenderStyle style) { int x, y; FMemLump data = Wads.ReadLump (SourceLump); const uint8_t *indata = (const uint8_t *)data.GetMem(); - Pixels = new uint8_t[Width * Height]; + auto Pixels = new uint8_t[Width * Height]; for (x = 0; x < Width; ++x) { for (y = 0; y < Height; ++y) { - Pixels[x*Height+y] = indata[x+320*y]; + auto p = indata[x + 320 * y]; + Pixels[x*Height + y] = (style.Flags & STYLEF_RedIsAlpha) ? p : GPalette.Remap[p]; } } -} - -//========================================================================== -// -// -// -//========================================================================== - -const uint8_t *FAutomapTexture::GetPixels () -{ - if (Pixels == NULL) - { - MakeTexture (); - } return Pixels; } -//========================================================================== -// -// -// -//========================================================================== - -const uint8_t *FAutomapTexture::GetColumn (unsigned int column, const Span **spans_out) -{ - if (Pixels == NULL) - { - MakeTexture (); - } - if ((unsigned)column >= (unsigned)Width) - { - column %= Width; - } - if (spans_out != NULL) - { - *spans_out = DummySpan; - } - return Pixels + column*Height; -} diff --git a/src/textures/bitmap.cpp b/src/textures/bitmap.cpp index cdeb645e38..33cfe2141b 100644 --- a/src/textures/bitmap.cpp +++ b/src/textures/bitmap.cpp @@ -193,13 +193,14 @@ typedef void (*CopyFunc)(uint8_t *pout, const uint8_t *pin, int count, int step, iCopyColors, \ iCopyColors, \ iCopyColors, \ + iCopyColors, \ iCopyColors, \ iCopyColors, \ iCopyColors, \ iCopyColors, \ iCopyColors \ } -static const CopyFunc copyfuncs[][10]={ +static const CopyFunc copyfuncs[][11]={ COPY_FUNCS(bCopy), COPY_FUNCS(bBlend), COPY_FUNCS(bAdd), diff --git a/src/textures/bitmap.h b/src/textures/bitmap.h index 0811eaa701..51d857ac44 100644 --- a/src/textures/bitmap.h +++ b/src/textures/bitmap.h @@ -235,6 +235,15 @@ struct cCMYK static __forceinline int Gray(const unsigned char * p) { return (R(p)*77 + G(p)*143 + B(p)*36)>>8; } }; +struct cYCbCr +{ + static __forceinline unsigned char R(const unsigned char * p) { return clamp((int)(p[0] + 1.40200 * (int(p[2]) - 0x80)), 0, 255); } + static __forceinline unsigned char G(const unsigned char * p) { return clamp((int)(p[0] - 0.34414 * (int(p[1] - 0x80)) - 0.71414 * (int(p[2]) - 0x80)), 0, 255); } + static __forceinline unsigned char B(const unsigned char * p) { return clamp((int)(p[0] + 1.77200 * (int(p[1]) - 0x80)), 0, 255); } + static __forceinline unsigned char A(const unsigned char * p, uint8_t x, uint8_t y, uint8_t z) { return 255; } + static __forceinline int Gray(const unsigned char * p) { return (R(p) * 77 + G(p) * 143 + B(p) * 36) >> 8; } +}; + struct cBGR { static __forceinline unsigned char R(const unsigned char * p) { return p[2]; } @@ -310,6 +319,7 @@ enum ColorType CF_RGBA, CF_IA, CF_CMYK, + CF_YCbCr, CF_BGR, CF_BGRA, CF_I16, diff --git a/src/textures/ddstexture.cpp b/src/textures/ddstexture.cpp index 9cde88ced8..313682f14d 100644 --- a/src/textures/ddstexture.cpp +++ b/src/textures/ddstexture.cpp @@ -153,22 +153,21 @@ struct DDSFileHeader // //========================================================================== -class FDDSTexture : public FTexture +class FDDSTexture : public FWorldTexture { + enum + { + PIX_Palette = 0, + PIX_Alphatex = 1, + PIX_ARGB = 2 + }; public: FDDSTexture (FileReader &lump, int lumpnum, void *surfdesc); - ~FDDSTexture (); - const uint8_t *GetColumn (unsigned int column, const Span **spans_out); - const uint8_t *GetPixels (); - void Unload (); - FTextureFormat GetFormat (); + FTextureFormat GetFormat () override; + uint8_t *MakeTexture(FRenderStyle style) override; protected: - - uint8_t *Pixels; - Span **Spans; - uint32_t Format; uint32_t RMask, GMask, BMask, AMask; @@ -180,11 +179,10 @@ protected: static void CalcBitShift (uint32_t mask, uint8_t *lshift, uint8_t *rshift); - void MakeTexture (); - void ReadRGB (FileReader &lump, uint8_t *tcbuf = NULL); - void DecompressDXT1 (FileReader &lump, uint8_t *tcbuf = NULL); - void DecompressDXT3 (FileReader &lump, bool premultiplied, uint8_t *tcbuf = NULL); - void DecompressDXT5 (FileReader &lump, bool premultiplied, uint8_t *tcbuf = NULL); + void ReadRGB (FileReader &lump, uint8_t *buffer, int pixelmode); + void DecompressDXT1 (FileReader &lump, uint8_t *buffer, int pixelmode); + void DecompressDXT3 (FileReader &lump, bool premultiplied, uint8_t *buffer, int pixelmode); + void DecompressDXT5 (FileReader &lump, bool premultiplied, uint8_t *buffer, int pixelmode); int CopyTrueColorPixels(FBitmap *bmp, int x, int y, int rotate, FCopyInfo *inf = NULL); bool UseBasePalette(); @@ -287,7 +285,7 @@ FTexture *DDSTexture_TryCreate (FileReader &data, int lumpnum) //========================================================================== FDDSTexture::FDDSTexture (FileReader &lump, int lumpnum, void *vsurfdesc) -: FTexture(NULL, lumpnum), Pixels(0), Spans(0) +: FWorldTexture(NULL, lumpnum) { DDSURFACEDESC2 *surf = (DDSURFACEDESC2 *)vsurfdesc; @@ -381,38 +379,6 @@ void FDDSTexture::CalcBitShift (uint32_t mask, uint8_t *lshiftp, uint8_t *rshift // //========================================================================== -FDDSTexture::~FDDSTexture () -{ - Unload (); - if (Spans != NULL) - { - FreeSpans (Spans); - Spans = NULL; - } -} - -//========================================================================== -// -// -// -//========================================================================== - -void FDDSTexture::Unload () -{ - if (Pixels != NULL) - { - delete[] Pixels; - Pixels = NULL; - } - FTexture::Unload(); -} - -//========================================================================== -// -// -// -//========================================================================== - FTextureFormat FDDSTexture::GetFormat() { #if 0 @@ -437,88 +403,41 @@ FTextureFormat FDDSTexture::GetFormat() // //========================================================================== -const uint8_t *FDDSTexture::GetColumn (unsigned int column, const Span **spans_out) +uint8_t *FDDSTexture::MakeTexture (FRenderStyle style) { - if (Pixels == NULL) - { - MakeTexture (); - } - if ((unsigned)column >= (unsigned)Width) - { - if (WidthMask + 1 == Width) - { - column &= WidthMask; - } - else - { - column %= Width; - } - } - if (spans_out != NULL) - { - if (Spans == NULL) - { - Spans = CreateSpans (Pixels); - } - *spans_out = Spans[column]; - } - return Pixels + column*Height; -} + auto lump = Wads.OpenLumpReader (SourceLump); -//========================================================================== -// -// -// -//========================================================================== + auto Pixels = new uint8_t[Width*Height]; -const uint8_t *FDDSTexture::GetPixels () -{ - if (Pixels == NULL) + lump.Seek (sizeof(DDSURFACEDESC2) + 4, FileReader::SeekSet); + + int pmode = (style.Flags & STYLEF_RedIsAlpha) ? PIX_Alphatex : PIX_Palette; + if (Format >= 1 && Format <= 4) // RGB: Format is # of bytes per pixel { - MakeTexture (); + ReadRGB (lump, Pixels, pmode); + } + else if (Format == ID_DXT1) + { + DecompressDXT1 (lump, Pixels, pmode); + } + else if (Format == ID_DXT3 || Format == ID_DXT2) + { + DecompressDXT3 (lump, Format == ID_DXT2, Pixels, pmode); + } + else if (Format == ID_DXT5 || Format == ID_DXT4) + { + DecompressDXT5 (lump, Format == ID_DXT4, Pixels, pmode); } return Pixels; } //========================================================================== // -// +// Note that pixel size == 8 is column-major, but 32 is row-major! // //========================================================================== -void FDDSTexture::MakeTexture () -{ - auto lump = Wads.OpenLumpReader (SourceLump); - - Pixels = new uint8_t[Width*Height]; - - lump.Seek (sizeof(DDSURFACEDESC2) + 4, FileReader::SeekSet); - - if (Format >= 1 && Format <= 4) // RGB: Format is # of bytes per pixel - { - ReadRGB (lump); - } - else if (Format == ID_DXT1) - { - DecompressDXT1 (lump); - } - else if (Format == ID_DXT3 || Format == ID_DXT2) - { - DecompressDXT3 (lump, Format == ID_DXT2); - } - else if (Format == ID_DXT5 || Format == ID_DXT4) - { - DecompressDXT5 (lump, Format == ID_DXT4); - } -} - -//========================================================================== -// -// -// -//========================================================================== - -void FDDSTexture::ReadRGB (FileReader &lump, uint8_t *tcbuf) +void FDDSTexture::ReadRGB (FileReader &lump, uint8_t *buffer, int pixelmode) { uint32_t x, y; uint32_t amask = AMask == 0 ? 0 : 0x80000000 >> AShiftL; @@ -527,7 +446,7 @@ void FDDSTexture::ReadRGB (FileReader &lump, uint8_t *tcbuf) for (y = Height; y > 0; --y) { uint8_t *buffp = linebuff; - uint8_t *pixelp = tcbuf? tcbuf + 4*y*Height : Pixels + y; + uint8_t *pixelp = pixelmode == PIX_ARGB? buffer + 4*y*Height : buffer + y; lump.Read (linebuff, Pitch); for (x = Width; x > 0; --x) { @@ -548,14 +467,21 @@ void FDDSTexture::ReadRGB (FileReader &lump, uint8_t *tcbuf) { c = *buffp++; } - if (!tcbuf) + if (pixelmode != PIX_ARGB) { if (amask == 0 || (c & amask)) { uint32_t r = (c & RMask) << RShiftL; r |= r >> RShiftR; - uint32_t g = (c & GMask) << GShiftL; g |= g >> GShiftR; - uint32_t b = (c & BMask) << BShiftL; b |= b >> BShiftR; - *pixelp = RGB256k.RGB[r >> 26][g >> 26][b >> 26]; + if (pixelmode == PIX_Palette) + { + uint32_t g = (c & GMask) << GShiftL; g |= g >> GShiftR; + uint32_t b = (c & BMask) << BShiftL; b |= b >> BShiftR; + *pixelp = RGB256k.RGB[r >> 26][g >> 26][b >> 26]; + } + else + { + *pixelp = uint8_t(r >> 24); + } } else { @@ -587,13 +513,13 @@ void FDDSTexture::ReadRGB (FileReader &lump, uint8_t *tcbuf) // //========================================================================== -void FDDSTexture::DecompressDXT1 (FileReader &lump, uint8_t *tcbuf) +void FDDSTexture::DecompressDXT1 (FileReader &lump, uint8_t *buffer, int pixelmode) { const long blocklinelen = ((Width + 3) >> 2) << 3; uint8_t *blockbuff = new uint8_t[blocklinelen]; uint8_t *block; PalEntry color[4]; - uint8_t palcol[4]; + uint8_t palcol[4] = { 0,0,0,0 }; // shut up compiler warnings. int ox, oy, x, y, i; color[0].a = 255; @@ -639,9 +565,12 @@ void FDDSTexture::DecompressDXT1 (FileReader &lump, uint8_t *tcbuf) bMasked = true; } // Pick colors from the palette for each of the four colors. - /*if (!tcbuf)*/ for (i = 3; i >= 0; --i) + if (pixelmode != PIX_ARGB) for (i = 3; i >= 0; --i) { - palcol[i] = color[i].a ? RGB256k.RGB[color[i].r >> 2][color[i].g >> 2][color[i].b >> 2] : 0; + if (pixelmode == PIX_Palette) + palcol[i] = color[i].a ? RGB256k.RGB[color[i].r >> 2][color[i].g >> 2][color[i].b >> 2] : 0; + else + palcol[i] = (color[i].a * color[i].r) / 255; // use the same logic as the hardware renderer. } // Now decode this 4x4 block to the pixel buffer. for (y = 0; y < 4; ++y) @@ -658,13 +587,13 @@ void FDDSTexture::DecompressDXT1 (FileReader &lump, uint8_t *tcbuf) break; } int ci = (yslice >> (x + x)) & 3; - if (!tcbuf) + if (pixelmode != PIX_ARGB) { - Pixels[oy + y + (ox + x) * Height] = palcol[ci]; + buffer[oy + y + (ox + x) * Height] = palcol[ci]; } else { - uint8_t * tcp = &tcbuf[(ox + x)*4 + (oy + y) * Width*4]; + uint8_t * tcp = &buffer[(ox + x)*4 + (oy + y) * Width*4]; tcp[0] = color[ci].r; tcp[1] = color[ci].g; tcp[2] = color[ci].b; @@ -685,13 +614,13 @@ void FDDSTexture::DecompressDXT1 (FileReader &lump, uint8_t *tcbuf) // //========================================================================== -void FDDSTexture::DecompressDXT3 (FileReader &lump, bool premultiplied, uint8_t *tcbuf) +void FDDSTexture::DecompressDXT3 (FileReader &lump, bool premultiplied, uint8_t *buffer, int pixelmode) { const long blocklinelen = ((Width + 3) >> 2) << 4; uint8_t *blockbuff = new uint8_t[blocklinelen]; uint8_t *block; PalEntry color[4]; - uint8_t palcol[4]; + uint8_t palcol[4] = { 0,0,0,0 }; int ox, oy, x, y, i; for (oy = 0; oy < Height; oy += 4) @@ -719,10 +648,14 @@ void FDDSTexture::DecompressDXT3 (FileReader &lump, bool premultiplied, uint8_t color[3].b = (color[0].b + color[1].b + color[1].b + 1) / 3; // Pick colors from the palette for each of the four colors. - if (!tcbuf) for (i = 3; i >= 0; --i) + if (pixelmode != PIX_ARGB) for (i = 3; i >= 0; --i) { - palcol[i] = RGB256k.RGB[color[i].r >> 2][color[i].g >> 2][color[i].b >> 2]; + if (pixelmode == PIX_Palette) + palcol[i] = color[i].a ? RGB256k.RGB[color[i].r >> 2][color[i].g >> 2][color[i].b >> 2] : 0; + else + palcol[i] = (color[i].a * color[i].r) / 255; // use the same logic as the hardware renderer. } + // Now decode this 4x4 block to the pixel buffer. for (y = 0; y < 4; ++y) { @@ -738,14 +671,14 @@ void FDDSTexture::DecompressDXT3 (FileReader &lump, bool premultiplied, uint8_t { break; } - if (!tcbuf) + if (pixelmode != PIX_ARGB) { - Pixels[oy + y + (ox + x) * Height] = ((yalphaslice >> (x*4)) & 15) < 8 ? + buffer[oy + y + (ox + x) * Height] = ((yalphaslice >> (x*4)) & 15) < 8 ? (bMasked = true, 0) : palcol[(yslice >> (x + x)) & 3]; } else { - uint8_t * tcp = &tcbuf[(ox + x)*4 + (oy + y) * Width*4]; + uint8_t * tcp = &buffer[(ox + x)*4 + (oy + y) * Width*4]; int c = (yslice >> (x + x)) & 3; tcp[0] = color[c].r; tcp[1] = color[c].g; @@ -767,13 +700,13 @@ void FDDSTexture::DecompressDXT3 (FileReader &lump, bool premultiplied, uint8_t // //========================================================================== -void FDDSTexture::DecompressDXT5 (FileReader &lump, bool premultiplied, uint8_t *tcbuf) +void FDDSTexture::DecompressDXT5 (FileReader &lump, bool premultiplied, uint8_t *buffer, int pixelmode) { const long blocklinelen = ((Width + 3) >> 2) << 4; uint8_t *blockbuff = new uint8_t[blocklinelen]; uint8_t *block; PalEntry color[4]; - uint8_t palcol[4]; + uint8_t palcol[4] = { 0,0,0,0 }; uint32_t yalphaslice = 0; int ox, oy, x, y, i; @@ -824,9 +757,12 @@ void FDDSTexture::DecompressDXT5 (FileReader &lump, bool premultiplied, uint8_t color[3].b = (color[0].b + color[1].b + color[1].b + 1) / 3; // Pick colors from the palette for each of the four colors. - if (!tcbuf) for (i = 3; i >= 0; --i) + if (pixelmode != PIX_ARGB) for (i = 3; i >= 0; --i) { - palcol[i] = RGB256k.RGB[color[i].r >> 2][color[i].g >> 2][color[i].b >> 2]; + if (pixelmode == PIX_Palette) + palcol[i] = color[i].a ? RGB256k.RGB[color[i].r >> 2][color[i].g >> 2][color[i].b >> 2] : 0; + else + palcol[i] = (color[i].a * color[i].r) / 255; // use the same logic as the hardware renderer. } // Now decode this 4x4 block to the pixel buffer. for (y = 0; y < 4; ++y) @@ -851,14 +787,14 @@ void FDDSTexture::DecompressDXT5 (FileReader &lump, bool premultiplied, uint8_t { break; } - if (!tcbuf) + if (pixelmode == 8) { - Pixels[oy + y + (ox + x) * Height] = alpha[((yalphaslice >> (x*3)) & 7)] < 128 ? + buffer[oy + y + (ox + x) * Height] = alpha[((yalphaslice >> (x*3)) & 7)] < 128 ? (bMasked = true, 0) : palcol[(yslice >> (x + x)) & 3]; } else { - uint8_t * tcp = &tcbuf[(ox + x)*4 + (oy + y) * Width*4]; + uint8_t * tcp = &buffer[(ox + x)*4 + (oy + y) * Width*4]; int c = (yslice >> (x + x)) & 3; tcp[0] = color[c].r; tcp[1] = color[c].g; @@ -889,19 +825,19 @@ int FDDSTexture::CopyTrueColorPixels(FBitmap *bmp, int x, int y, int rotate, FCo if (Format >= 1 && Format <= 4) // RGB: Format is # of bytes per pixel { - ReadRGB (lump, TexBuffer); + ReadRGB (lump, TexBuffer, PIX_ARGB); } else if (Format == ID_DXT1) { - DecompressDXT1 (lump, TexBuffer); + DecompressDXT1 (lump, TexBuffer, PIX_ARGB); } else if (Format == ID_DXT3 || Format == ID_DXT2) { - DecompressDXT3 (lump, Format == ID_DXT2, TexBuffer); + DecompressDXT3 (lump, Format == ID_DXT2, TexBuffer, PIX_ARGB); } else if (Format == ID_DXT5 || Format == ID_DXT4) { - DecompressDXT5 (lump, Format == ID_DXT4, TexBuffer); + DecompressDXT5 (lump, Format == ID_DXT4, TexBuffer, PIX_ARGB); } // All formats decompress to RGBA. diff --git a/src/textures/emptytexture.cpp b/src/textures/emptytexture.cpp index 45039cae29..19698551f2 100644 --- a/src/textures/emptytexture.cpp +++ b/src/textures/emptytexture.cpp @@ -1,7 +1,8 @@ /* -** flattexture.cpp +** emptytexture.cpp ** Texture class for empty placeholder textures ** (essentially patches with dimensions and offsets of (0,0) ) +** These need special treatment because a texture size of 0 is illegal ** **--------------------------------------------------------------------------- ** Copyright 2009 Christoph Oelckers @@ -41,30 +42,21 @@ //========================================================================== // -// A texture defined between F_START and F_END markers +// // //========================================================================== -class FEmptyTexture : public FTexture +class FEmptyTexture : public FWorldTexture { + uint8_t Pixel = 0; public: FEmptyTexture (int lumpnum); - - const uint8_t *GetColumn (unsigned int column, const Span **spans_out); - const uint8_t *GetPixels (); - void Unload() {} - -protected: - uint8_t Pixels[1]; - Span DummySpans[1]; + uint8_t *MakeTexture(FRenderStyle style) override; }; - - //========================================================================== // -// Since there is no way to detect the validity of a flat -// they can't be used anywhere else but between F_START and F_END +// // //========================================================================== @@ -86,15 +78,13 @@ FTexture *EmptyTexture_TryCreate(FileReader & file, int lumpnum) //========================================================================== FEmptyTexture::FEmptyTexture (int lumpnum) -: FTexture(NULL, lumpnum) +: FWorldTexture(NULL, lumpnum) { bMasked = true; WidthBits = HeightBits = 1; Width = Height = 1; WidthMask = 0; - DummySpans[0].TopOffset = 0; - DummySpans[0].Length = 0; - Pixels[0] = 0; + PixelsAreStatic = 3; } //========================================================================== @@ -103,23 +93,8 @@ FEmptyTexture::FEmptyTexture (int lumpnum) // //========================================================================== -const uint8_t *FEmptyTexture::GetColumn (unsigned int column, const Span **spans_out) +uint8_t *FEmptyTexture::MakeTexture(FRenderStyle style) { - if (spans_out != NULL) - { - *spans_out = DummySpans; - } - return Pixels; -} - -//========================================================================== -// -// -// -//========================================================================== - -const uint8_t *FEmptyTexture::GetPixels () -{ - return Pixels; + return &Pixel; } diff --git a/src/textures/flattexture.cpp b/src/textures/flattexture.cpp index 408acb0997..7581b3a6e2 100644 --- a/src/textures/flattexture.cpp +++ b/src/textures/flattexture.cpp @@ -45,24 +45,11 @@ // //========================================================================== -class FFlatTexture : public FTexture +class FFlatTexture : public FWorldTexture { public: FFlatTexture (int lumpnum); - ~FFlatTexture (); - - const uint8_t *GetColumn (unsigned int column, const Span **spans_out); - const uint8_t *GetPixels (); - void Unload (); - -protected: - uint8_t *Pixels; - Span DummySpans[2]; - - - void MakeTexture (); - - friend class FTexture; + uint8_t *MakeTexture (FRenderStyle style) override; }; @@ -86,7 +73,7 @@ FTexture *FlatTexture_TryCreate(FileReader & file, int lumpnum) //========================================================================== FFlatTexture::FFlatTexture (int lumpnum) -: FTexture(NULL, lumpnum), Pixels(0) +: FWorldTexture(NULL, lumpnum) { int area; int bits; @@ -108,10 +95,6 @@ FFlatTexture::FFlatTexture (int lumpnum) WidthBits = HeightBits = bits; Width = Height = 1 << bits; WidthMask = (1 << bits) - 1; - DummySpans[0].TopOffset = 0; - DummySpans[0].Length = Height; - DummySpans[1].TopOffset = 0; - DummySpans[1].Length = 0; } //========================================================================== @@ -120,87 +103,17 @@ FFlatTexture::FFlatTexture (int lumpnum) // //========================================================================== -FFlatTexture::~FFlatTexture () -{ - Unload (); -} - -//========================================================================== -// -// -// -//========================================================================== - -void FFlatTexture::Unload () -{ - if (Pixels != NULL) - { - delete[] Pixels; - Pixels = NULL; - } - FTexture::Unload(); -} - -//========================================================================== -// -// -// -//========================================================================== - -const uint8_t *FFlatTexture::GetColumn (unsigned int column, const Span **spans_out) -{ - if (Pixels == NULL) - { - MakeTexture (); - } - if ((unsigned)column >= (unsigned)Width) - { - if (WidthMask + 1 == Width) - { - column &= WidthMask; - } - else - { - column %= Width; - } - } - if (spans_out != NULL) - { - *spans_out = DummySpans; - } - return Pixels + column*Height; -} - -//========================================================================== -// -// -// -//========================================================================== - -const uint8_t *FFlatTexture::GetPixels () -{ - if (Pixels == NULL) - { - MakeTexture (); - } - return Pixels; -} - -//========================================================================== -// -// -// -//========================================================================== - -void FFlatTexture::MakeTexture () +uint8_t *FFlatTexture::MakeTexture (FRenderStyle style) { auto lump = Wads.OpenLumpReader (SourceLump); - Pixels = new uint8_t[Width*Height]; + auto Pixels = new uint8_t[Width*Height]; auto numread = lump.Read (Pixels, Width*Height); if (numread < Width*Height) { memset (Pixels + numread, 0xBB, Width*Height - numread); } - FlipSquareBlockRemap (Pixels, Width, Height, GPalette.Remap); + if (!(style.Flags & STYLEF_RedIsAlpha)) FTexture::FlipSquareBlockRemap (Pixels, Width, Height, GPalette.Remap); + else FTexture::FlipSquareBlock(Pixels, Width, Height); + return Pixels; } diff --git a/src/textures/imgztexture.cpp b/src/textures/imgztexture.cpp index 1f623d084f..e210740559 100644 --- a/src/textures/imgztexture.cpp +++ b/src/textures/imgztexture.cpp @@ -36,6 +36,7 @@ #include "doomtype.h" #include "files.h" #include "w_wad.h" +#include "v_palette.h" #include "textures/textures.h" @@ -47,7 +48,7 @@ // //========================================================================== -class FIMGZTexture : public FTexture +class FIMGZTexture : public FWorldTexture { struct ImageHeader { @@ -62,18 +63,7 @@ class FIMGZTexture : public FTexture public: FIMGZTexture (int lumpnum, uint16_t w, uint16_t h, int16_t l, int16_t t); - ~FIMGZTexture (); - - const uint8_t *GetColumn (unsigned int column, const Span **spans_out); - const uint8_t *GetPixels (); - void Unload (); - -protected: - - uint8_t *Pixels; - Span **Spans; - - void MakeTexture (); + uint8_t *MakeTexture (FRenderStyle style) override; }; @@ -106,7 +96,7 @@ FTexture *IMGZTexture_TryCreate(FileReader & file, int lumpnum) //========================================================================== FIMGZTexture::FIMGZTexture (int lumpnum, uint16_t w, uint16_t h, int16_t l, int16_t t) - : FTexture(NULL, lumpnum), Pixels(0), Spans(0) + : FWorldTexture(NULL, lumpnum) { Wads.GetLumpName (Name, lumpnum); Width = w; @@ -122,88 +112,7 @@ FIMGZTexture::FIMGZTexture (int lumpnum, uint16_t w, uint16_t h, int16_t l, int1 // //========================================================================== -FIMGZTexture::~FIMGZTexture () -{ - Unload (); - if (Spans != NULL) - { - FreeSpans (Spans); - Spans = NULL; - } -} - -//========================================================================== -// -// -// -//========================================================================== - -void FIMGZTexture::Unload () -{ - if (Pixels != NULL) - { - delete[] Pixels; - Pixels = NULL; - } - FTexture::Unload(); -} - -//========================================================================== -// -// -// -//========================================================================== - -const uint8_t *FIMGZTexture::GetColumn (unsigned int column, const Span **spans_out) -{ - if (Pixels == NULL) - { - MakeTexture (); - } - if ((unsigned)column >= (unsigned)Width) - { - if (WidthMask + 1 == Width) - { - column &= WidthMask; - } - else - { - column %= Width; - } - } - if (spans_out != NULL) - { - if (Spans == NULL) - { - Spans = CreateSpans (Pixels); - } - *spans_out = Spans[column]; - } - return Pixels + column*Height; -} - -//========================================================================== -// -// -// -//========================================================================== - -const uint8_t *FIMGZTexture::GetPixels () -{ - if (Pixels == NULL) - { - MakeTexture (); - } - return Pixels; -} - -//========================================================================== -// -// -// -//========================================================================== - -void FIMGZTexture::MakeTexture () +uint8_t *FIMGZTexture::MakeTexture (FRenderStyle style) { FMemLump lump = Wads.ReadLump (SourceLump); const ImageHeader *imgz = (const ImageHeader *)lump.GetMem(); @@ -222,7 +131,7 @@ void FIMGZTexture::MakeTexture () int dest_rew = Width * Height - 1; CalcBitSize (); - Pixels = new uint8_t[Width*Height]; + auto Pixels = new uint8_t[Width*Height]; dest_p = Pixels; // Convert the source image from row-major to column-major format @@ -232,7 +141,8 @@ void FIMGZTexture::MakeTexture () { for (int x = Width; x != 0; --x) { - *dest_p = *data; + auto p = *data; + *dest_p = (style.Flags & STYLEF_RedIsAlpha) ? p : GPalette.Remap[p]; dest_p += dest_adv; data++; } @@ -251,8 +161,8 @@ void FIMGZTexture::MakeTexture () { if (runlen != 0) { - uint8_t color = *data; - *dest_p = color; + auto p = *data; + *dest_p = (style.Flags & STYLEF_RedIsAlpha) ? p : GPalette.Remap[p]; dest_p += dest_adv; data++; x--; @@ -282,5 +192,6 @@ void FIMGZTexture::MakeTexture () dest_p -= dest_rew; } } + return Pixels; } diff --git a/src/textures/jpegtexture.cpp b/src/textures/jpegtexture.cpp index c9f19c1daf..abf1e34ec4 100644 --- a/src/textures/jpegtexture.cpp +++ b/src/textures/jpegtexture.cpp @@ -179,27 +179,16 @@ void JPEG_OutputMessage (j_common_ptr cinfo) // //========================================================================== -class FJPEGTexture : public FTexture +class FJPEGTexture : public FWorldTexture { public: FJPEGTexture (int lumpnum, int width, int height); ~FJPEGTexture (); - const uint8_t *GetColumn (unsigned int column, const Span **spans_out); - const uint8_t *GetPixels (); - void Unload (); - FTextureFormat GetFormat (); - int CopyTrueColorPixels(FBitmap *bmp, int x, int y, int rotate, FCopyInfo *inf = NULL); - bool UseBasePalette(); - -protected: - - uint8_t *Pixels; - Span DummySpans[2]; - - void MakeTexture (); - - friend class FTexture; + FTextureFormat GetFormat () override; + int CopyTrueColorPixels(FBitmap *bmp, int x, int y, int rotate, FCopyInfo *inf = NULL) override; + bool UseBasePalette() override; + uint8_t *MakeTexture (FRenderStyle style) override; }; //========================================================================== @@ -259,7 +248,7 @@ FTexture *JPEGTexture_TryCreate(FileReader & data, int lumpnum) //========================================================================== FJPEGTexture::FJPEGTexture (int lumpnum, int width, int height) -: FTexture(NULL, lumpnum), Pixels(0) +: FWorldTexture(NULL, lumpnum) { UseType = TEX_MiscPatch; LeftOffset = 0; @@ -269,35 +258,6 @@ FJPEGTexture::FJPEGTexture (int lumpnum, int width, int height) Width = width; Height = height; CalcBitSize (); - - DummySpans[0].TopOffset = 0; - DummySpans[0].Length = Height; - DummySpans[1].TopOffset = 0; - DummySpans[1].Length = 0; -} - -//========================================================================== -// -// -// -//========================================================================== - -FJPEGTexture::~FJPEGTexture () -{ - Unload (); -} - -//========================================================================== -// -// -// -//========================================================================== - -void FJPEGTexture::Unload () -{ - delete[] Pixels; - Pixels = NULL; - FTexture::Unload(); } //========================================================================== @@ -317,142 +277,123 @@ FTextureFormat FJPEGTexture::GetFormat() // //========================================================================== -const uint8_t *FJPEGTexture::GetColumn (unsigned int column, const Span **spans_out) -{ - if (Pixels == NULL) - { - MakeTexture (); - } - if ((unsigned)column >= (unsigned)Width) - { - if (WidthMask + 1 == Width) - { - column &= WidthMask; - } - else - { - column %= Width; - } - } - if (spans_out != NULL) - { - *spans_out = DummySpans; - } - return Pixels + column*Height; -} - -//========================================================================== -// -// -// -//========================================================================== - -const uint8_t *FJPEGTexture::GetPixels () -{ - if (Pixels == NULL) - { - MakeTexture (); - } - return Pixels; -} - -//========================================================================== -// -// -// -//========================================================================== - -void FJPEGTexture::MakeTexture () +uint8_t *FJPEGTexture::MakeTexture (FRenderStyle style) { auto lump = Wads.OpenLumpReader (SourceLump); JSAMPLE *buff = NULL; + bool doalpha = !!(style.Flags & STYLEF_RedIsAlpha); jpeg_decompress_struct cinfo; jpeg_error_mgr jerr; - Pixels = new uint8_t[Width * Height]; + auto Pixels = new uint8_t[Width * Height]; memset (Pixels, 0xBA, Width * Height); cinfo.err = jpeg_std_error(&jerr); cinfo.err->output_message = JPEG_OutputMessage; cinfo.err->error_exit = JPEG_ErrorExit; jpeg_create_decompress(&cinfo); + + FLumpSourceMgr sourcemgr(&lump, &cinfo); try { - FLumpSourceMgr sourcemgr(&lump, &cinfo); jpeg_read_header(&cinfo, TRUE); if (!((cinfo.out_color_space == JCS_RGB && cinfo.num_components == 3) || - (cinfo.out_color_space == JCS_CMYK && cinfo.num_components == 4) || - (cinfo.out_color_space == JCS_GRAYSCALE && cinfo.num_components == 1))) + (cinfo.out_color_space == JCS_CMYK && cinfo.num_components == 4) || + (cinfo.out_color_space == JCS_YCbCr && cinfo.num_components == 3) || + (cinfo.out_color_space == JCS_GRAYSCALE && cinfo.num_components == 1))) { - Printf (TEXTCOLOR_ORANGE "Unsupported color format\n"); - throw -1; + Printf(TEXTCOLOR_ORANGE, "Unsupported color format in %s\n", Wads.GetLumpFullPath(SourceLump).GetChars()); } - - jpeg_start_decompress(&cinfo); - - int y = 0; - buff = new uint8_t[cinfo.output_width * cinfo.output_components]; - - while (cinfo.output_scanline < cinfo.output_height) + else { - int num_scanlines = jpeg_read_scanlines(&cinfo, &buff, 1); - uint8_t *in = buff; - uint8_t *out = Pixels + y; - switch (cinfo.out_color_space) + jpeg_start_decompress(&cinfo); + + int y = 0; + buff = new uint8_t[cinfo.output_width * cinfo.output_components]; + + while (cinfo.output_scanline < cinfo.output_height) { - case JCS_RGB: - for (int x = Width; x > 0; --x) + int num_scanlines = jpeg_read_scanlines(&cinfo, &buff, 1); + uint8_t *in = buff; + uint8_t *out = Pixels + y; + switch (cinfo.out_color_space) { - *out = RGB256k.RGB[in[0]>>2][in[1]>>2][in[2]>>2]; - out += Height; - in += 3; - } - break; + case JCS_RGB: + for (int x = Width; x > 0; --x) + { + *out = !doalpha? RGB256k.RGB[in[0] >> 2][in[1] >> 2][in[2] >> 2] : in[0]; + out += Height; + in += 3; + } + break; - case JCS_GRAYSCALE: - for (int x = Width; x > 0; --x) - { - *out = GrayMap[in[0]]; - out += Height; - in += 1; - } - break; + case JCS_GRAYSCALE: + for (int x = Width; x > 0; --x) + { + *out = !doalpha ? FTexture::GrayMap[in[0]] : in[0]; + out += Height; + in += 1; + } + break; - case JCS_CMYK: - // What are you doing using a CMYK image? :) - for (int x = Width; x > 0; --x) - { - // To be precise, these calculations should use 255, but - // 256 is much faster and virtually indistinguishable. - int r = in[3] - (((256-in[0])*in[3]) >> 8); - int g = in[3] - (((256-in[1])*in[3]) >> 8); - int b = in[3] - (((256-in[2])*in[3]) >> 8); - *out = RGB256k.RGB[r >> 2][g >> 2][b >> 2]; - out += Height; - in += 4; - } - break; + case JCS_CMYK: + // What are you doing using a CMYK image? :) + for (int x = Width; x > 0; --x) + { + // To be precise, these calculations should use 255, but + // 256 is much faster and virtually indistinguishable. + int r = in[3] - (((256 - in[0])*in[3]) >> 8); + if (!doalpha) + { + int g = in[3] - (((256 - in[1])*in[3]) >> 8); + int b = in[3] - (((256 - in[2])*in[3]) >> 8); + *out = RGB256k.RGB[r >> 2][g >> 2][b >> 2]; + } + else *out = (uint8_t)r; + out += Height; + in += 4; + } + break; - default: - // The other colorspaces were considered above and discarded, - // but GCC will complain without a default for them here. - break; + case JCS_YCbCr: + // Probably useless but since I had the formula available... + for (int x = Width; x > 0; --x) + { + double Y = in[0], Cb = in[1], Cr = in[2]; + int r = clamp((int)(Y + 1.40200 * (Cr - 0x80)), 0, 255); + if (!doalpha) + { + int g = clamp((int)(Y - 0.34414 * (Cb - 0x80) - 0.71414 * (Cr - 0x80)), 0, 255); + int b = clamp((int)(Y + 1.77200 * (Cb - 0x80)), 0, 255); + *out = RGB256k.RGB[r >> 2][g >> 2][b >> 2]; + } + else *out = (uint8_t)r; + out += Height; + in += 4; + } + break; + + default: + // The other colorspaces were considered above and discarded, + // but GCC will complain without a default for them here. + break; + } + y++; } - y++; + jpeg_finish_decompress(&cinfo); } - jpeg_finish_decompress(&cinfo); - jpeg_destroy_decompress(&cinfo); } catch (int) { - Printf (TEXTCOLOR_ORANGE " in texture %s\n", Name.GetChars()); - jpeg_destroy_decompress(&cinfo); + Printf(TEXTCOLOR_ORANGE, "JPEG error in %s\n", Wads.GetLumpFullPath(SourceLump).GetChars()); } + jpeg_destroy_decompress(&cinfo); if (buff != NULL) { delete[] buff; } + return Pixels; } @@ -479,58 +420,66 @@ int FJPEGTexture::CopyTrueColorPixels(FBitmap *bmp, int x, int y, int rotate, FC cinfo.err->error_exit = JPEG_ErrorExit; jpeg_create_decompress(&cinfo); + FLumpSourceMgr sourcemgr(&lump, &cinfo); try { - FLumpSourceMgr sourcemgr(&lump, &cinfo); jpeg_read_header(&cinfo, TRUE); if (!((cinfo.out_color_space == JCS_RGB && cinfo.num_components == 3) || - (cinfo.out_color_space == JCS_CMYK && cinfo.num_components == 4) || - (cinfo.out_color_space == JCS_GRAYSCALE && cinfo.num_components == 1))) + (cinfo.out_color_space == JCS_CMYK && cinfo.num_components == 4) || + (cinfo.out_color_space == JCS_YCbCr && cinfo.num_components == 3) || + (cinfo.out_color_space == JCS_GRAYSCALE && cinfo.num_components == 1))) { - Printf (TEXTCOLOR_ORANGE "Unsupported color format\n"); - throw -1; + Printf(TEXTCOLOR_ORANGE, "Unsupported color format in %s\n", Wads.GetLumpFullPath(SourceLump).GetChars()); } - jpeg_start_decompress(&cinfo); - - int yc = 0; - buff = new uint8_t[cinfo.output_height * cinfo.output_width * cinfo.output_components]; - - - while (cinfo.output_scanline < cinfo.output_height) + else { - uint8_t * ptr = buff + cinfo.output_width * cinfo.output_components * yc; - jpeg_read_scanlines(&cinfo, &ptr, 1); - yc++; + jpeg_start_decompress(&cinfo); + + int yc = 0; + buff = new uint8_t[cinfo.output_height * cinfo.output_width * cinfo.output_components]; + + + while (cinfo.output_scanline < cinfo.output_height) + { + uint8_t * ptr = buff + cinfo.output_width * cinfo.output_components * yc; + jpeg_read_scanlines(&cinfo, &ptr, 1); + yc++; + } + + switch (cinfo.out_color_space) + { + case JCS_RGB: + bmp->CopyPixelDataRGB(x, y, buff, cinfo.output_width, cinfo.output_height, + 3, cinfo.output_width * cinfo.output_components, rotate, CF_RGB, inf); + break; + + case JCS_GRAYSCALE: + for (int i = 0; i < 256; i++) pe[i] = PalEntry(255, i, i, i); // default to a gray map + bmp->CopyPixelData(x, y, buff, cinfo.output_width, cinfo.output_height, + 1, cinfo.output_width, rotate, pe, inf); + break; + + case JCS_CMYK: + bmp->CopyPixelDataRGB(x, y, buff, cinfo.output_width, cinfo.output_height, + 4, cinfo.output_width * cinfo.output_components, rotate, CF_CMYK, inf); + break; + + case JCS_YCbCr: + bmp->CopyPixelDataRGB(x, y, buff, cinfo.output_width, cinfo.output_height, + 4, cinfo.output_width * cinfo.output_components, rotate, CF_YCbCr, inf); + break; + + default: + assert(0); + break; + } + jpeg_finish_decompress(&cinfo); } - - switch (cinfo.out_color_space) - { - case JCS_RGB: - bmp->CopyPixelDataRGB(x, y, buff, cinfo.output_width, cinfo.output_height, - 3, cinfo.output_width * cinfo.output_components, rotate, CF_RGB, inf); - break; - - case JCS_GRAYSCALE: - for(int i=0;i<256;i++) pe[i]=PalEntry(255,i,i,i); // default to a gray map - bmp->CopyPixelData(x, y, buff, cinfo.output_width, cinfo.output_height, - 1, cinfo.output_width, rotate, pe, inf); - break; - - case JCS_CMYK: - bmp->CopyPixelDataRGB(x, y, buff, cinfo.output_width, cinfo.output_height, - 4, cinfo.output_width * cinfo.output_components, rotate, CF_CMYK, inf); - break; - - default: - assert(0); - break; - } - jpeg_finish_decompress(&cinfo); } - catch(int) + catch (int) { - Printf (TEXTCOLOR_ORANGE " in JPEG texture %s\n", Name.GetChars()); + Printf(TEXTCOLOR_ORANGE, "JPEG error in %s\n", Wads.GetLumpFullPath(SourceLump).GetChars()); } jpeg_destroy_decompress(&cinfo); if (buff != NULL) delete [] buff; diff --git a/src/textures/multipatchtexture.cpp b/src/textures/multipatchtexture.cpp index e5beb246ff..e2bf932e9f 100644 --- a/src/textures/multipatchtexture.cpp +++ b/src/textures/multipatchtexture.cpp @@ -148,24 +148,21 @@ struct FPatchLookup // //========================================================================== -class FMultiPatchTexture : public FTexture +class FMultiPatchTexture : public FWorldTexture { public: FMultiPatchTexture (const void *texdef, FPatchLookup *patchlookup, int maxpatchnum, bool strife, int deflump); FMultiPatchTexture (FScanner &sc, int usetype); ~FMultiPatchTexture (); - const uint8_t *GetColumn (unsigned int column, const Span **spans_out); - const uint8_t *GetPixels (); - FTextureFormat GetFormat(); - bool UseBasePalette() ; - void Unload (); - virtual void SetFrontSkyLayer (); + FTextureFormat GetFormat() override; + bool UseBasePalette() override; + virtual void SetFrontSkyLayer () override; - int CopyTrueColorPixels(FBitmap *bmp, int x, int y, int rotate, FCopyInfo *inf = NULL); - int GetSourceLump() { return DefinitionLump; } - FTexture *GetRedirect(bool wantwarped); - FTexture *GetRawTexture(); + int CopyTrueColorPixels(FBitmap *bmp, int x, int y, int rotate, FCopyInfo *inf = NULL) override; + int GetSourceLump() override { return DefinitionLump; } + FTexture *GetRedirect(bool wantwarped) override; + FTexture *GetRawTexture() override; void ResolvePatches(); protected: @@ -201,7 +198,7 @@ protected: bool bRedirect:1; bool bTranslucentPatches:1; - void MakeTexture (); + uint8_t *MakeTexture (FRenderStyle style); private: void CheckForHacks (); @@ -323,11 +320,6 @@ FMultiPatchTexture::~FMultiPatchTexture () delete[] Inits; Inits = nullptr; } - if (Spans != NULL) - { - FreeSpans (Spans); - Spans = NULL; - } } //========================================================================== @@ -345,80 +337,6 @@ void FMultiPatchTexture::SetFrontSkyLayer () bNoRemap0 = true; } -//========================================================================== -// -// FMultiPatchTexture :: Unload -// -//========================================================================== - -void FMultiPatchTexture::Unload () -{ - if (Pixels != NULL) - { - delete[] Pixels; - Pixels = NULL; - } - FTexture::Unload(); -} - -//========================================================================== -// -// FMultiPatchTexture :: GetPixels -// -//========================================================================== - -const uint8_t *FMultiPatchTexture::GetPixels () -{ - if (bRedirect) - { - return Parts->Texture->GetPixels (); - } - if (Pixels == NULL) - { - MakeTexture (); - } - return Pixels; -} - -//========================================================================== -// -// FMultiPatchTexture :: GetColumn -// -//========================================================================== - -const uint8_t *FMultiPatchTexture::GetColumn (unsigned int column, const Span **spans_out) -{ - if (bRedirect) - { - return Parts->Texture->GetColumn (column, spans_out); - } - if (Pixels == NULL) - { - MakeTexture (); - } - if ((unsigned)column >= (unsigned)Width) - { - if (WidthMask + 1 == Width) - { - column &= WidthMask; - } - else - { - column %= Width; - } - } - if (spans_out != NULL) - { - if (Spans == NULL) - { - Spans = CreateSpans (Pixels); - } - *spans_out = Spans[column]; - } - return Pixels + column*Height; -} - - //========================================================================== // // GetBlendMap @@ -427,7 +345,6 @@ const uint8_t *FMultiPatchTexture::GetColumn (unsigned int column, const Span ** uint8_t *GetBlendMap(PalEntry blend, uint8_t *blendwork) { - switch (blend.a==0 ? int(blend) : -1) { case BLEND_ICEMAP: @@ -480,39 +397,54 @@ uint8_t *GetBlendMap(PalEntry blend, uint8_t *blendwork) // //========================================================================== -void FMultiPatchTexture::MakeTexture () +uint8_t *FMultiPatchTexture::MakeTexture (FRenderStyle style) { // Add a little extra space at the end if the texture's height is not // a power of 2, in case somebody accidentally makes it repeat vertically. int numpix = Width * Height + (1 << HeightBits) - Height; uint8_t blendwork[256]; - bool hasTranslucent = false; + bool buildrgb = bComplex; - Pixels = new uint8_t[numpix]; + auto Pixels = new uint8_t[numpix]; memset (Pixels, 0, numpix); - for (int i = 0; i < NumParts; ++i) + if (style.Flags & STYLEF_RedIsAlpha) { - if (Parts[i].op != OP_COPY) + // The rules here are as follows: + // A texture uses its palette index as alpha only if it reports to use the base palette. + // In summary this means: + // If a texture is marked 'complex', it will use the red channel. + // If a texture uses non-base-palette patches, it will use the red channel for all pixels, even those coming from a base palette patch. + // If a texture only uses base-palette patches and no compositing effects it will use the palette index. + // + buildrgb = !UseBasePalette(); + } + else + { + // For regular textures we can use paletted compositing if all patches are just being copied because they all can create a paletted buffer. + if (!buildrgb) for (int i = 0; i < NumParts; ++i) { - hasTranslucent = true; + if (Parts[i].op != OP_COPY) + { + buildrgb = true; + } } } - if (!hasTranslucent) - { + if (!buildrgb) + { for (int i = 0; i < NumParts; ++i) { if (Parts[i].Texture->bHasCanvas) continue; // cannot use camera textures as patch. - uint8_t *trans = Parts[i].Translation ? Parts[i].Translation->Remap : NULL; + uint8_t *trans = Parts[i].Translation? Parts[i].Translation->Remap : nullptr; { if (Parts[i].Blend != 0) { trans = GetBlendMap(Parts[i].Blend, blendwork); } Parts[i].Texture->CopyToBlock (Pixels, Width, Height, - Parts[i].OriginX, Parts[i].OriginY, Parts[i].Rotate, trans); + Parts[i].OriginX, Parts[i].OriginY, Parts[i].Rotate, trans, style); } } } @@ -531,7 +463,7 @@ void FMultiPatchTexture::MakeTexture () { if (*out == 0 && in[3] != 0) { - *out = RGB256k.RGB[in[2]>>2][in[1]>>2][in[0]>>2]; + *out = (style.Flags & STYLEF_RedIsAlpha)? in[2]*in[3] : RGB256k.RGB[in[2]>>2][in[1]>>2][in[0]>>2]; } out += Height; in += 4; @@ -539,6 +471,7 @@ void FMultiPatchTexture::MakeTexture () } delete [] buffer; } + return Pixels; } //=========================================================================== @@ -755,14 +688,6 @@ void FMultiPatchTexture::CheckForHacks () break; } } - - if (i == NumParts) - { - for (i = 0; i < NumParts; ++i) - { - Parts[i].Texture->HackHack(256); - } - } } } diff --git a/src/textures/patchtexture.cpp b/src/textures/patchtexture.cpp index c964b9a53d..b4a8e3909d 100644 --- a/src/textures/patchtexture.cpp +++ b/src/textures/patchtexture.cpp @@ -39,6 +39,7 @@ #include "templates.h" #include "v_palette.h" #include "textures/textures.h" +#include "r_data/r_translate.h" // posts are runs of non masked source pixels @@ -55,24 +56,13 @@ struct column_t // //========================================================================== -class FPatchTexture : public FTexture +class FPatchTexture : public FWorldTexture { + bool badflag = false; public: FPatchTexture (int lumpnum, patch_t *header); - ~FPatchTexture (); - - const uint8_t *GetColumn (unsigned int column, const Span **spans_out); - const uint8_t *GetPixels (); - void Unload (); - -protected: - uint8_t *Pixels; - Span **Spans; - bool hackflag; - - - virtual void MakeTexture (); - void HackHack (int newheight); + uint8_t *MakeTexture (FRenderStyle style) override; + void DetectBadPatches(); }; //========================================================================== @@ -149,12 +139,13 @@ FTexture *PatchTexture_TryCreate(FileReader & file, int lumpnum) //========================================================================== FPatchTexture::FPatchTexture (int lumpnum, patch_t * header) -: FTexture(NULL, lumpnum), Pixels(0), Spans(0), hackflag(false) +: FWorldTexture(NULL, lumpnum) { Width = header->width; Height = header->height; LeftOffset = header->leftoffset; TopOffset = header->topoffset; + DetectBadPatches(); CalcBitSize (); } @@ -164,89 +155,7 @@ FPatchTexture::FPatchTexture (int lumpnum, patch_t * header) // //========================================================================== -FPatchTexture::~FPatchTexture () -{ - Unload (); - if (Spans != NULL) - { - FreeSpans (Spans); - Spans = NULL; - } -} - -//========================================================================== -// -// -// -//========================================================================== - -void FPatchTexture::Unload () -{ - if (Pixels != NULL) - { - delete[] Pixels; - Pixels = NULL; - } - FTexture::Unload(); -} - -//========================================================================== -// -// -// -//========================================================================== - -const uint8_t *FPatchTexture::GetPixels () -{ - if (Pixels == NULL) - { - MakeTexture (); - } - return Pixels; -} - -//========================================================================== -// -// -// -//========================================================================== - -const uint8_t *FPatchTexture::GetColumn (unsigned int column, const Span **spans_out) -{ - if (Pixels == NULL) - { - MakeTexture (); - } - if ((unsigned)column >= (unsigned)Width) - { - if (WidthMask + 1 == Width) - { - column &= WidthMask; - } - else - { - column %= Width; - } - } - if (spans_out != NULL) - { - if (Spans == NULL) - { - Spans = CreateSpans(Pixels); - } - *spans_out = Spans[column]; - } - return Pixels + column*Height; -} - - -//========================================================================== -// -// -// -//========================================================================== - -void FPatchTexture::MakeTexture () +uint8_t *FPatchTexture::MakeTexture (FRenderStyle style) { uint8_t *remap, remaptable[256]; int numspans; @@ -258,23 +167,11 @@ void FPatchTexture::MakeTexture () maxcol = (const column_t *)((const uint8_t *)patch + Wads.LumpLength (SourceLump) - 3); - // Check for badly-sized patches -#if 0 // Such textures won't be created so there's no need to check here - if (LittleShort(patch->width) <= 0 || LittleShort(patch->height) <= 0) + if (style.Flags & STYLEF_RedIsAlpha) { - lump = Wads.ReadLump ("-BADPATC"); - patch = (const patch_t *)lump.GetMem(); - Printf (PRINT_BOLD, "Patch %s has a non-positive size.\n", Name); + remap = translationtables[TRANSLATION_Standard][8]->Remap; } - else if (LittleShort(patch->width) > 2048 || LittleShort(patch->height) > 2048) - { - lump = Wads.ReadLump ("-BADPATC"); - patch = (const patch_t *)lump.GetMem(); - Printf (PRINT_BOLD, "Patch %s is too big.\n", Name); - } -#endif - - if (bNoRemap0) + else if (bNoRemap0) { memcpy (remaptable, GPalette.Remap, 256); remaptable[0] = 0; @@ -286,9 +183,9 @@ void FPatchTexture::MakeTexture () } - if (hackflag) + if (badflag) { - Pixels = new uint8_t[Width * Height]; + auto Pixels = new uint8_t[Width * Height]; uint8_t *out; // Draw the image to the buffer @@ -302,7 +199,7 @@ void FPatchTexture::MakeTexture () out++, in++; } } - return; + return Pixels; } // Add a little extra space at the end if the texture's height is not @@ -311,7 +208,7 @@ void FPatchTexture::MakeTexture () numspans = Width; - Pixels = new uint8_t[numpix]; + auto Pixels = new uint8_t[numpix]; memset (Pixels, 0, numpix); // Draw the image to the buffer @@ -355,6 +252,7 @@ void FPatchTexture::MakeTexture () column = (const column_t *)((const uint8_t *)column + column->length + 4); } } + return Pixels; } @@ -364,8 +262,11 @@ void FPatchTexture::MakeTexture () // //========================================================================== -void FPatchTexture::HackHack (int newheight) +void FPatchTexture::DetectBadPatches () { + // The patch must look like it is large enough for the rules to apply to avoid using this on truly empty patches. + if (Wads.LumpLength(SourceLump) < Width * Height / 2) return; + // Check if this patch is likely to be a problem. // It must be 256 pixels tall, and all its columns must have exactly // one post, where each post has a supposed length of 0. @@ -381,29 +282,17 @@ void FPatchTexture::HackHack (int newheight) const column_t *col = (column_t*)((uint8_t*)realpatch+LittleLong(cofs[x])); if (col->topdelta != 0 || col->length != 0) { - break; // It's not bad! + return; // It's not bad! } col = (column_t *)((uint8_t *)col + 256 + 4); if (col->topdelta != 0xFF) { - break; // More than one post in a column! + return; // More than one post in a column! } } - if (x == x2) - { - // If all the columns were checked, it needs fixing. - Unload (); - if (Spans != NULL) - { - FreeSpans (Spans); - } - - Height = newheight; - LeftOffset = 0; - TopOffset = 0; - - hackflag = true; - bMasked = false; // Hacked textures don't have transparent parts. - } + LeftOffset = 0; + TopOffset = 0; + badflag = true; + bMasked = false; // Hacked textures don't have transparent parts. } } diff --git a/src/textures/pcxtexture.cpp b/src/textures/pcxtexture.cpp index 75331caa50..efe12e3c21 100644 --- a/src/textures/pcxtexture.cpp +++ b/src/textures/pcxtexture.cpp @@ -81,32 +81,24 @@ struct PCXHeader // //========================================================================== -class FPCXTexture : public FTexture +class FPCXTexture : public FWorldTexture { public: FPCXTexture (int lumpnum, PCXHeader &); ~FPCXTexture (); - const uint8_t *GetColumn (unsigned int column, const Span **spans_out); - const uint8_t *GetPixels (); - void Unload (); - FTextureFormat GetFormat (); + FTextureFormat GetFormat () override; - int CopyTrueColorPixels(FBitmap *bmp, int x, int y, int rotate, FCopyInfo *inf = NULL); - bool UseBasePalette(); + int CopyTrueColorPixels(FBitmap *bmp, int x, int y, int rotate, FCopyInfo *inf = NULL) override; + bool UseBasePalette() override; protected: - uint8_t *Pixels; - Span DummySpans[2]; - void ReadPCX1bit (uint8_t *dst, FileReader & lump, PCXHeader *hdr); void ReadPCX4bits (uint8_t *dst, FileReader & lump, PCXHeader *hdr); void ReadPCX8bits (uint8_t *dst, FileReader & lump, PCXHeader *hdr); void ReadPCX24bits (uint8_t *dst, FileReader & lump, PCXHeader *hdr, int planes); - virtual void MakeTexture (); - - friend class FTexture; + uint8_t *MakeTexture (FRenderStyle style) override; }; @@ -154,44 +146,12 @@ FTexture * PCXTexture_TryCreate(FileReader & file, int lumpnum) //========================================================================== FPCXTexture::FPCXTexture(int lumpnum, PCXHeader & hdr) -: FTexture(NULL, lumpnum), Pixels(0) +: FWorldTexture(NULL, lumpnum) { bMasked = false; Width = LittleShort(hdr.xmax) - LittleShort(hdr.xmin) + 1; Height = LittleShort(hdr.ymax) - LittleShort(hdr.ymin) + 1; CalcBitSize(); - - DummySpans[0].TopOffset = 0; - DummySpans[0].Length = Height; - DummySpans[1].TopOffset = 0; - DummySpans[1].Length = 0; -} - -//========================================================================== -// -// -// -//========================================================================== - -FPCXTexture::~FPCXTexture () -{ - Unload (); -} - -//========================================================================== -// -// -// -//========================================================================== - -void FPCXTexture::Unload () -{ - if (Pixels != NULL) - { - delete[] Pixels; - Pixels = NULL; - } - FTexture::Unload(); } //========================================================================== @@ -211,51 +171,6 @@ FTextureFormat FPCXTexture::GetFormat() // //========================================================================== -const uint8_t *FPCXTexture::GetColumn (unsigned int column, const Span **spans_out) -{ - if (Pixels == NULL) - { - MakeTexture (); - } - if ((unsigned)column >= (unsigned)Width) - { - if (WidthMask + 1 == Width) - { - column &= WidthMask; - } - else - { - column %= Width; - } - } - if (spans_out != NULL) - { - *spans_out = DummySpans; - } - return Pixels + column*Height; -} - -//========================================================================== -// -// -// -//========================================================================== - -const uint8_t *FPCXTexture::GetPixels () -{ - if (Pixels == NULL) - { - MakeTexture (); - } - return Pixels; -} - -//========================================================================== -// -// -// -//========================================================================== - void FPCXTexture::ReadPCX1bit (uint8_t *dst, FileReader & lump, PCXHeader *hdr) { int y, i, bytes; @@ -457,18 +372,19 @@ void FPCXTexture::ReadPCX24bits (uint8_t *dst, FileReader & lump, PCXHeader *hdr // //========================================================================== -void FPCXTexture::MakeTexture() +uint8_t *FPCXTexture::MakeTexture(FRenderStyle style) { uint8_t PaletteMap[256]; PCXHeader header; int bitcount; + bool alphatex = !!(style.Flags & STYLEF_RedIsAlpha); auto lump = Wads.OpenLumpReader(SourceLump); lump.Read(&header, sizeof(header)); bitcount = header.bitsPerPixel * header.numColorPlanes; - Pixels = new uint8_t[Width*Height]; + auto Pixels = new uint8_t[Width*Height]; if (bitcount < 24) { @@ -476,7 +392,8 @@ void FPCXTexture::MakeTexture() { for (int i=0;i<16;i++) { - PaletteMap[i] = ColorMatcher.Pick(header.palette[i*3],header.palette[i*3+1],header.palette[i*3+2]); + if (!alphatex) PaletteMap[i] = ColorMatcher.Pick(header.palette[i * 3], header.palette[i * 3 + 1], header.palette[i * 3 + 2]); + else PaletteMap[i] = header.palette[i * 3]; } switch (bitcount) @@ -502,7 +419,7 @@ void FPCXTexture::MakeTexture() uint8_t r = lump.ReadUInt8(); uint8_t g = lump.ReadUInt8(); uint8_t b = lump.ReadUInt8(); - PaletteMap[i] = ColorMatcher.Pick(r,g,b); + PaletteMap[i] = !alphatex? ColorMatcher.Pick(r,g,b) : r; } lump.Seek(sizeof(header), FileReader::SeekSet); ReadPCX8bits (Pixels, lump, &header); @@ -529,12 +446,13 @@ void FPCXTexture::MakeTexture() { for(int x=0; x < Width; x++) { - Pixels[y+Height*x] = RGB256k.RGB[row[0]>>2][row[1]>>2][row[2]>>2]; + Pixels[y + Height * x] = !alphatex? RGB256k.RGB[row[0] >> 2][row[1] >> 2][row[2] >> 2] : row[0]; row+=3; } } delete [] buffer; } + return Pixels; } //=========================================================================== diff --git a/src/textures/pngtexture.cpp b/src/textures/pngtexture.cpp index 480502c33f..00a7ba7018 100644 --- a/src/textures/pngtexture.cpp +++ b/src/textures/pngtexture.cpp @@ -48,24 +48,21 @@ // //========================================================================== -class FPNGTexture : public FTexture +class FPNGTexture : public FWorldTexture { public: FPNGTexture (FileReader &lump, int lumpnum, const FString &filename, int width, int height, uint8_t bitdepth, uint8_t colortype, uint8_t interlace); - ~FPNGTexture (); + ~FPNGTexture(); - const uint8_t *GetColumn (unsigned int column, const Span **spans_out); - const uint8_t *GetPixels (); - void Unload (); - FTextureFormat GetFormat (); - int CopyTrueColorPixels(FBitmap *bmp, int x, int y, int rotate, FCopyInfo *inf = NULL); - bool UseBasePalette(); + FTextureFormat GetFormat () override; + int CopyTrueColorPixels(FBitmap *bmp, int x, int y, int rotate, FCopyInfo *inf = NULL) override; + bool UseBasePalette() override; + uint8_t *MakeTexture(FRenderStyle style) override; protected: + void ReadAlphaRemap(FileReader *lump, uint8_t *alpharemap); FString SourceFile; - uint8_t *Pixels; - Span **Spans; FileReader fr; uint8_t BitDepth; @@ -74,13 +71,10 @@ protected: bool HaveTrans; uint16_t NonPaletteTrans[3]; - uint8_t *PaletteMap; - int PaletteSize; - uint32_t StartOfIDAT; - - void MakeTexture (); - - friend class FTexture; + uint8_t *PaletteMap = nullptr; + int PaletteSize = 0; + uint32_t StartOfIDAT = 0; + uint32_t StartOfPalette = 0; }; @@ -200,9 +194,8 @@ FTexture *PNGTexture_CreateFromFile(PNGHandle *png, const FString &filename) FPNGTexture::FPNGTexture (FileReader &lump, int lumpnum, const FString &filename, int width, int height, uint8_t depth, uint8_t colortype, uint8_t interlace) -: FTexture(NULL, lumpnum), SourceFile(filename), Pixels(0), Spans(0), - BitDepth(depth), ColorType(colortype), Interlace(interlace), HaveTrans(false), - PaletteMap(0), PaletteSize(0), StartOfIDAT(0) +: FWorldTexture(NULL, lumpnum), SourceFile(filename), + BitDepth(depth), ColorType(colortype), Interlace(interlace), HaveTrans(false) { union { @@ -265,6 +258,7 @@ FPNGTexture::FPNGTexture (FileReader &lump, int lumpnum, const FString &filename case MAKE_ID('P','L','T','E'): PaletteSize = MIN (len / 3, 256); + StartOfPalette = (uint32_t)lump.Tell(); lump.Read (p.pngpal, PaletteSize * 3); if (PaletteSize * 3 != (int)len) { @@ -284,11 +278,6 @@ FPNGTexture::FPNGTexture (FileReader &lump, int lumpnum, const FString &filename NonPaletteTrans[1] = uint16_t(trans[2] * 256 + trans[3]); NonPaletteTrans[2] = uint16_t(trans[4] * 256 + trans[5]); break; - - case MAKE_ID('a','l','P','h'): - bAlphaTexture = true; - bMasked = true; - break; } lump.Seek(4, FileReader::SeekCur); // Skip CRC lump.Read(&len, 4); @@ -304,20 +293,17 @@ FPNGTexture::FPNGTexture (FileReader &lump, int lumpnum, const FString &filename // intentional fall-through case 0: // Grayscale - if (!bAlphaTexture) + if (colortype == 0 && HaveTrans && NonPaletteTrans[0] < 256) { - if (colortype == 0 && HaveTrans && NonPaletteTrans[0] < 256) - { - bMasked = true; - PaletteSize = 256; - PaletteMap = new uint8_t[256]; - memcpy (PaletteMap, GrayMap, 256); - PaletteMap[NonPaletteTrans[0]] = 0; - } - else - { - PaletteMap = GrayMap; - } + bMasked = true; + PaletteSize = 256; + PaletteMap = new uint8_t[256]; + memcpy (PaletteMap, GrayMap, 256); + PaletteMap[NonPaletteTrans[0]] = 0; + } + else + { + PaletteMap = GrayMap; } break; @@ -354,16 +340,10 @@ FPNGTexture::FPNGTexture (FileReader &lump, int lumpnum, const FString &filename FPNGTexture::~FPNGTexture () { - Unload (); - if (Spans != NULL) - { - FreeSpans (Spans); - Spans = NULL; - } - if (PaletteMap != NULL && PaletteMap != GrayMap) + if (PaletteMap != nullptr && PaletteMap != FTexture::GrayMap) { delete[] PaletteMap; - PaletteMap = NULL; + PaletteMap = nullptr; } } @@ -373,19 +353,6 @@ FPNGTexture::~FPNGTexture () // //========================================================================== -void FPNGTexture::Unload () -{ - delete[] Pixels; - Pixels = NULL; - FTexture::Unload(); -} - -//========================================================================== -// -// -// -//========================================================================== - FTextureFormat FPNGTexture::GetFormat() { #if 0 @@ -407,32 +374,18 @@ FTextureFormat FPNGTexture::GetFormat() // //========================================================================== -const uint8_t *FPNGTexture::GetColumn (unsigned int column, const Span **spans_out) +void FPNGTexture::ReadAlphaRemap(FileReader *lump, uint8_t *alpharemap) { - if (Pixels == NULL) + auto p = lump->Tell(); + lump->Seek(StartOfPalette, FileReader::SeekSet); + for (int i = 0; i < PaletteSize; i++) { - MakeTexture (); + uint8_t r = lump->ReadUInt8(); + lump->ReadUInt8(); // Skip g and b. + lump->ReadUInt8(); + alpharemap[i] = PaletteMap[i] == 0? 0 : r; } - if ((unsigned)column >= (unsigned)Width) - { - if (WidthMask + 1 == Width) - { - column &= WidthMask; - } - else - { - column %= Width; - } - } - if (spans_out != NULL) - { - if (Spans == NULL) - { - Spans = CreateSpans (Pixels); - } - *spans_out = Spans[column]; - } - return Pixels + column*Height; + lump->Seek(p, FileReader::SeekSet); } //========================================================================== @@ -441,26 +394,11 @@ const uint8_t *FPNGTexture::GetColumn (unsigned int column, const Span **spans_o // //========================================================================== -const uint8_t *FPNGTexture::GetPixels () -{ - if (Pixels == NULL) - { - MakeTexture (); - } - return Pixels; -} - - -//========================================================================== -// -// -// -//========================================================================== - -void FPNGTexture::MakeTexture () +uint8_t *FPNGTexture::MakeTexture (FRenderStyle style) { FileReader *lump; FileReader lfr; + bool alphatex = !!(style.Flags & STYLEF_RedIsAlpha); if (SourceLump >= 0) { @@ -472,7 +410,7 @@ void FPNGTexture::MakeTexture () lump = &fr; } - Pixels = new uint8_t[Width*Height]; + auto Pixels = new uint8_t[Width*Height]; if (StartOfIDAT == 0) { memset (Pixels, 0x99, Width*Height); @@ -490,25 +428,37 @@ void FPNGTexture::MakeTexture () if (Width == Height) { - if (PaletteMap != NULL) + if (!alphatex) { - FlipSquareBlockRemap (Pixels, Width, Height, PaletteMap); + FTexture::FlipSquareBlockRemap (Pixels, Width, Height, PaletteMap); + } + else if (ColorType == 0) + { + FTexture::FlipSquareBlock (Pixels, Width, Height); } else { - FlipSquareBlock (Pixels, Width, Height); + uint8_t alpharemap[256]; + ReadAlphaRemap(lump, alpharemap); + FTexture::FlipSquareBlockRemap(Pixels, Width, Height, alpharemap); } } else { uint8_t *newpix = new uint8_t[Width*Height]; - if (PaletteMap != NULL) + if (!alphatex) { - FlipNonSquareBlockRemap (newpix, Pixels, Width, Height, Width, PaletteMap); + FTexture::FlipNonSquareBlockRemap (newpix, Pixels, Width, Height, Width, PaletteMap); + } + else if (ColorType == 0) + { + FTexture::FlipNonSquareBlock (newpix, Pixels, Width, Height, Width); } else { - FlipNonSquareBlock (newpix, Pixels, Width, Height, Width); + uint8_t alpharemap[256]; + ReadAlphaRemap(lump, alpharemap); + FTexture::FlipNonSquareBlockRemap(newpix, Pixels, Width, Height, Width, alpharemap); } uint8_t *oldpix = Pixels; Pixels = newpix; @@ -537,22 +487,13 @@ void FPNGTexture::MakeTexture () { for (y = Height; y > 0; --y) { - if (!HaveTrans) + if (HaveTrans && in[0] == NonPaletteTrans[0] && in[1] == NonPaletteTrans[1] && in[2] == NonPaletteTrans[2]) { - *out++ = RGB256k.RGB[in[0]>>2][in[1]>>2][in[2]>>2]; + *out++ = 0; } else { - if (in[0] == NonPaletteTrans[0] && - in[1] == NonPaletteTrans[1] && - in[2] == NonPaletteTrans[2]) - { - *out++ = 0; - } - else - { - *out++ = RGB256k.RGB[in[0]>>2][in[1]>>2][in[2]>>2]; - } + *out++ = alphatex? in[0] : RGB256k.RGB[in[0]>>2][in[1]>>2][in[2]>>2]; } in += pitch; } @@ -563,29 +504,14 @@ void FPNGTexture::MakeTexture () case 4: // Grayscale + Alpha pitch = Width * 2; backstep = Height * pitch - 2; - if (PaletteMap != NULL) + for (x = Width; x > 0; --x) { - for (x = Width; x > 0; --x) + for (y = Height; y > 0; --y) { - for (y = Height; y > 0; --y) - { - *out++ = in[1] < 128 ? 0 : PaletteMap[in[0]]; - in += pitch; - } - in -= backstep; - } - } - else - { - for (x = Width; x > 0; --x) - { - for (y = Height; y > 0; --y) - { - *out++ = in[1] < 128 ? 0 : in[0]; - in += pitch; - } - in -= backstep; + *out++ = alphatex? ((in[0] * in[1]) >> 8) : in[1] < 128 ? 0 : PaletteMap[in[0]]; + in += pitch; } + in -= backstep; } break; @@ -596,7 +522,7 @@ void FPNGTexture::MakeTexture () { for (y = Height; y > 0; --y) { - *out++ = in[3] < 128 ? 0 : RGB256k.RGB[in[0]>>2][in[1]>>2][in[2]>>2]; + *out++ = alphatex? ((in[0] * in[3]) >> 8) : in[3] < 128 ? 0 : RGB256k.RGB[in[0]>>2][in[1]>>2][in[2]>>2]; in += pitch; } in -= backstep; @@ -606,6 +532,7 @@ void FPNGTexture::MakeTexture () delete[] tempix; } } + return Pixels; } //=========================================================================== diff --git a/src/textures/rawpagetexture.cpp b/src/textures/rawpagetexture.cpp index 99354bb66c..7e9268c6e4 100644 --- a/src/textures/rawpagetexture.cpp +++ b/src/textures/rawpagetexture.cpp @@ -46,21 +46,12 @@ // //========================================================================== -class FRawPageTexture : public FTexture +class FRawPageTexture : public FWorldTexture { public: FRawPageTexture (int lumpnum); ~FRawPageTexture (); - - const uint8_t *GetColumn (unsigned int column, const Span **spans_out); - const uint8_t *GetPixels (); - void Unload (); - -protected: - uint8_t *Pixels; - static const Span DummySpans[2]; - - void MakeTexture (); + uint8_t *MakeTexture (FRenderStyle style) override; }; //========================================================================== @@ -155,17 +146,6 @@ FTexture *RawPageTexture_TryCreate(FileReader & file, int lumpnum) } -//========================================================================== -// -// -// -//========================================================================== - -const FTexture::Span FRawPageTexture::DummySpans[2] = -{ - { 0, 200 }, { 0, 0 } -}; - //========================================================================== // // @@ -173,7 +153,7 @@ const FTexture::Span FRawPageTexture::DummySpans[2] = //========================================================================== FRawPageTexture::FRawPageTexture (int lumpnum) -: FTexture(NULL, lumpnum), Pixels(0) +: FWorldTexture(NULL, lumpnum) { Width = 320; Height = 200; @@ -188,79 +168,14 @@ FRawPageTexture::FRawPageTexture (int lumpnum) // //========================================================================== -FRawPageTexture::~FRawPageTexture () -{ - Unload (); -} - -//========================================================================== -// -// -// -//========================================================================== - -void FRawPageTexture::Unload () -{ - if (Pixels != NULL) - { - delete[] Pixels; - Pixels = NULL; - } - FTexture::Unload(); -} - -//========================================================================== -// -// -// -//========================================================================== - -const uint8_t *FRawPageTexture::GetColumn (unsigned int column, const Span **spans_out) -{ - if (Pixels == NULL) - { - MakeTexture (); - } - if ((unsigned)column >= (unsigned)Width) - { - column %= 320; - } - if (spans_out != NULL) - { - *spans_out = DummySpans; - } - return Pixels + column*Height; -} - -//========================================================================== -// -// -// -//========================================================================== - -const uint8_t *FRawPageTexture::GetPixels () -{ - if (Pixels == NULL) - { - MakeTexture (); - } - return Pixels; -} - -//========================================================================== -// -// -// -//========================================================================== - -void FRawPageTexture::MakeTexture () +uint8_t *FRawPageTexture::MakeTexture (FRenderStyle style) { FMemLump lump = Wads.ReadLump (SourceLump); const uint8_t *source = (const uint8_t *)lump.GetMem(); const uint8_t *source_p = source; uint8_t *dest_p; - Pixels = new uint8_t[Width*Height]; + auto Pixels = new uint8_t[Width*Height]; dest_p = Pixels; // Convert the source image from row-major to column-major format @@ -268,11 +183,12 @@ void FRawPageTexture::MakeTexture () { for (int x = 320; x != 0; --x) { - *dest_p = GPalette.Remap[*source_p]; + *dest_p = (style.Flags & STYLEF_RedIsAlpha)? *source_p : GPalette.Remap[*source_p]; dest_p += 200; source_p++; } dest_p -= 200*320-1; } + return Pixels; } diff --git a/src/textures/texture.cpp b/src/textures/texture.cpp index 212f53a031..154efb222c 100644 --- a/src/textures/texture.cpp +++ b/src/textures/texture.cpp @@ -248,10 +248,6 @@ void FTexture::CalcBitSize () HeightBits = i; } -void FTexture::HackHack (int newheight) -{ -} - FTexture::Span **FTexture::CreateSpans (const uint8_t *pixels) const { Span **spans, *span; @@ -554,14 +550,15 @@ void FTexture::GenerateBgraMipmapsFast() } } -void FTexture::CopyToBlock (uint8_t *dest, int dwidth, int dheight, int xpos, int ypos, int rotate, const uint8_t *translation) +void FTexture::CopyToBlock (uint8_t *dest, int dwidth, int dheight, int xpos, int ypos, int rotate, const uint8_t *translation, FRenderStyle style) { - const uint8_t *pixels = GetPixels(); + const uint8_t *pixels = GetPixels(/*style*/); int srcwidth = Width; int srcheight = Height; int step_x = Height; int step_y = 1; FClipRect cr = {0, 0, dwidth, dheight}; + if (style.Flags & STYLEF_RedIsAlpha) translation = nullptr; // do not apply translations to alpha textures. if (ClipCopyPixelRect(&cr, xpos, ypos, pixels, srcwidth, srcheight, step_x, step_y, rotate)) { diff --git a/src/textures/textures.h b/src/textures/textures.h index 006d24bb7f..0aede45625 100644 --- a/src/textures/textures.h +++ b/src/textures/textures.h @@ -37,6 +37,7 @@ #include "doomtype.h" #include "vectors.h" +#include "r_data/renderstyle.h" #include struct FloatRect @@ -225,13 +226,15 @@ public: }; // Returns a single column of the texture - virtual const uint8_t *GetColumn (unsigned int column, const Span **spans_out) = 0; + virtual const uint8_t *GetColumn(unsigned int column, const Span **spans_out) = 0;// delete; + //virtual const uint8_t *GetColumn(FRenderStyle style, unsigned int column, const Span **spans_out) = 0; // Returns a single column of the texture, in BGRA8 format virtual const uint32_t *GetColumnBgra(unsigned int column, const Span **spans_out); // Returns the whole texture, stored in column-major order - virtual const uint8_t *GetPixels () = 0; + virtual const uint8_t *GetPixels() = 0;// delete; + //virtual const uint8_t *GetPixels(FRenderStyle style) = 0; // Returns the whole texture, stored in column-major order, in BGRA8 format virtual const uint32_t *GetPixelsBgra(); @@ -277,12 +280,7 @@ public: virtual void SetFrontSkyLayer(); - void CopyToBlock (uint8_t *dest, int dwidth, int dheight, int x, int y, const uint8_t *translation=NULL) - { - CopyToBlock(dest, dwidth, dheight, x, y, 0, translation); - } - - void CopyToBlock (uint8_t *dest, int dwidth, int dheight, int x, int y, int rotate, const uint8_t *translation=NULL); + void CopyToBlock (uint8_t *dest, int dwidth, int dheight, int x, int y, int rotate, const uint8_t *translation, FRenderStyle style); // Returns true if the next call to GetPixels() will return an image different from the // last call to GetPixels(). This should be considered valid only if a call to CheckModified() @@ -307,8 +305,6 @@ public: PalEntry GetSkyCapColor(bool bottom); static PalEntry averageColor(const uint32_t *data, int size, int maxout); - virtual void HackHack (int newheight); // called by FMultipatchTexture to discover corrupt patches. - protected: uint16_t Width, Height, WidthMask; static uint8_t GrayMap[256]; @@ -585,6 +581,24 @@ public: }; }; +// base class for everything that can be used as a world texture. +// This intermediate class encapsulates the buffers for the software renderer. +class FWorldTexture : public FTexture +{ +protected: + uint8_t *Pixeldata[2] = { nullptr, nullptr }; + Span **Spandata[2] = { nullptr, nullptr }; + + FWorldTexture(const char *name = nullptr, int lumpnum = -1); + ~FWorldTexture(); + // These should not be overridden. If that is needed, a class should inherit from something else + const uint8_t *GetColumn(unsigned int column, const Span **spans_out) override final; + const uint8_t *GetPixels() override final; + void Unload() override final; // should be removed after refactoring. + virtual void MakeTexture() = delete; + virtual uint8_t *MakeTexture(FRenderStyle style) = 0; +}; + // A texture that doesn't really exist class FDummyTexture : public FTexture { diff --git a/src/textures/tgatexture.cpp b/src/textures/tgatexture.cpp index 97e381e6b3..4b64308370 100644 --- a/src/textures/tgatexture.cpp +++ b/src/textures/tgatexture.cpp @@ -76,29 +76,18 @@ struct TGAHeader // //========================================================================== -class FTGATexture : public FTexture +class FTGATexture : public FWorldTexture { public: FTGATexture (int lumpnum, TGAHeader *); - ~FTGATexture (); - const uint8_t *GetColumn (unsigned int column, const Span **spans_out); - const uint8_t *GetPixels (); - void Unload (); - FTextureFormat GetFormat (); - - int CopyTrueColorPixels(FBitmap *bmp, int x, int y, int rotate, FCopyInfo *inf = NULL); - bool UseBasePalette(); + FTextureFormat GetFormat () override; + int CopyTrueColorPixels(FBitmap *bmp, int x, int y, int rotate, FCopyInfo *inf = NULL) override; + bool UseBasePalette() override; protected: - uint8_t *Pixels; - Span **Spans; - void ReadCompressed(FileReader &lump, uint8_t * buffer, int bytesperpixel); - - virtual void MakeTexture (); - - friend class FTexture; + uint8_t *MakeTexture (FRenderStyle style) override; }; //========================================================================== @@ -142,7 +131,7 @@ FTexture *TGATexture_TryCreate(FileReader & file, int lumpnum) //========================================================================== FTGATexture::FTGATexture (int lumpnum, TGAHeader * hdr) -: FTexture(NULL, lumpnum), Pixels(0), Spans(0) +: FWorldTexture(NULL, lumpnum) { Wads.GetLumpName (Name, lumpnum); Width = hdr->width; @@ -158,38 +147,6 @@ FTGATexture::FTGATexture (int lumpnum, TGAHeader * hdr) // //========================================================================== -FTGATexture::~FTGATexture () -{ - Unload (); - if (Spans != NULL) - { - FreeSpans (Spans); - Spans = NULL; - } -} - -//========================================================================== -// -// -// -//========================================================================== - -void FTGATexture::Unload () -{ - if (Pixels != NULL) - { - delete[] Pixels; - Pixels = NULL; - } - FTexture::Unload(); -} - -//========================================================================== -// -// -// -//========================================================================== - FTextureFormat FTGATexture::GetFormat() { return TEX_RGB; @@ -201,55 +158,6 @@ FTextureFormat FTGATexture::GetFormat() // //========================================================================== -const uint8_t *FTGATexture::GetColumn (unsigned int column, const Span **spans_out) -{ - if (Pixels == NULL) - { - MakeTexture (); - } - if ((unsigned)column >= (unsigned)Width) - { - if (WidthMask + 1 == Width) - { - column &= WidthMask; - } - else - { - column %= Width; - } - } - if (spans_out != NULL) - { - if (Spans == NULL) - { - Spans = CreateSpans (Pixels); - } - *spans_out = Spans[column]; - } - return Pixels + column*Height; -} - -//========================================================================== -// -// -// -//========================================================================== - -const uint8_t *FTGATexture::GetPixels () -{ - if (Pixels == NULL) - { - MakeTexture (); - } - return Pixels; -} - -//========================================================================== -// -// -// -//========================================================================== - void FTGATexture::ReadCompressed(FileReader &lump, uint8_t * buffer, int bytesperpixel) { uint8_t data[4]; @@ -286,7 +194,7 @@ void FTGATexture::ReadCompressed(FileReader &lump, uint8_t * buffer, int bytespe // //========================================================================== -void FTGATexture::MakeTexture () +uint8_t *FTGATexture::MakeTexture (FRenderStyle style) { uint8_t PaletteMap[256]; auto lump = Wads.OpenLumpReader (SourceLump); @@ -294,8 +202,9 @@ void FTGATexture::MakeTexture () uint16_t w; uint8_t r,g,b,a; uint8_t * buffer; + bool alphatex = !!(style.Flags & STYLEF_RedIsAlpha); - Pixels = new uint8_t[Width*Height]; + auto Pixels = new uint8_t[Width*Height]; lump.Read(&hdr, sizeof(hdr)); lump.Seek(hdr.id_len, FileReader::SeekCur); @@ -339,7 +248,7 @@ void FTGATexture::MakeTexture () r=g=b=a=0; break; } - PaletteMap[i] = a>=128? ColorMatcher.Pick(r, g, b) : 0; + PaletteMap[i] = !alphatex? (a>=128? ColorMatcher.Pick(r, g, b) : 0) : (r * a) >> 8; } } @@ -397,8 +306,8 @@ void FTGATexture::MakeTexture () uint16_t * p = (uint16_t*)(ptr + y * Pitch); for(int x=0;x>10) & 0x1f)*2][((v>>5) & 0x1f)*2][(v & 0x1f)*2]; + int v = LittleShort(*p); + Pixels[x*Height + y] = !alphatex ? RGB256k.RGB[((v >> 10) & 0x1f) * 2][((v >> 5) & 0x1f) * 2][(v & 0x1f) * 2] : ((v >> 10) & 0x1f) * 8; p+=step_x; } } @@ -410,7 +319,7 @@ void FTGATexture::MakeTexture () uint8_t * p = ptr + y * Pitch; for(int x=0;x>2][p[1]>>2][p[0]>>2]; + Pixels[x*Height + y] = !alphatex ? RGB256k.RGB[p[2] >> 2][p[1] >> 2][p[0] >> 2] : p[2]; p+=step_x; } } @@ -424,7 +333,7 @@ void FTGATexture::MakeTexture () uint8_t * p = ptr + y * Pitch; for(int x=0;x>2][p[1]>>2][p[0]>>2]; + Pixels[x*Height + y] = !alphatex ? RGB256k.RGB[p[2] >> 2][p[1] >> 2][p[0] >> 2] : p[2]; p+=step_x; } } @@ -436,7 +345,7 @@ void FTGATexture::MakeTexture () uint8_t * p = ptr + y * Pitch; for(int x=0;x= 128? RGB256k.RGB[p[2]>>2][p[1]>>2][p[0]>>2] : 0; + Pixels[x*Height + y] = !alphatex ? (p[3] >= 128 ? RGB256k.RGB[p[2] >> 2][p[1] >> 2][p[0] >> 2] : 0) : (p[2] * p[3]) >> 8; p+=step_x; } } @@ -457,7 +366,7 @@ void FTGATexture::MakeTexture () uint8_t * p = ptr + y * Pitch; for(int x=0;x Date: Sun, 18 Mar 2018 12:54:14 +0100 Subject: [PATCH 67/89] - added worldtexture.cpp --- src/textures/worldtexture.cpp | 133 ++++++++++++++++++++++++++++++++++ 1 file changed, 133 insertions(+) create mode 100644 src/textures/worldtexture.cpp diff --git a/src/textures/worldtexture.cpp b/src/textures/worldtexture.cpp new file mode 100644 index 0000000000..0370bf3e81 --- /dev/null +++ b/src/textures/worldtexture.cpp @@ -0,0 +1,133 @@ +/* +** worldtexture.cpp +** Intermediate class for some common code for several classes +** +**--------------------------------------------------------------------------- +** Copyright 2018 Christoph Oelckers +** All rights reserved. +** +** Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions +** are met: +** +** 1. Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** 2. Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in the +** documentation and/or other materials provided with the distribution. +** 3. The name of the author may not be used to endorse or promote products +** derived from this software without specific prior written permission. +** +** THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR +** IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES +** OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. +** IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, +** INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT +** NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF +** THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +**--------------------------------------------------------------------------- +** +** +*/ + +#include "textures.h" + + +//========================================================================== +// +// +// +//========================================================================== + +FWorldTexture::FWorldTexture(const char *name, int lumpnum) + : FTexture(name, lumpnum) +{ +} + +//========================================================================== +// +// +// +//========================================================================== + +FWorldTexture::~FWorldTexture() +{ + Unload(); + for(int i = 0; i < 2; i++) + { + if (Spandata[i] != nullptr) + { + FreeSpans (Spandata[i]); + Spandata[i] = nullptr; + } + } +} + +//========================================================================== +// +// +// +//========================================================================== + +void FWorldTexture::Unload () +{ + for(int i = 0; i < 2; i++) + { + if (!(PixelsAreStatic & (1 << i))) + { + delete[] Pixeldata[i]; + } + Pixeldata[i] = nullptr; + } + FTexture::Unload(); +} + +//========================================================================== +// +// +// +//========================================================================== + +const uint8_t *FWorldTexture::GetColumn (unsigned int column, const Span **spans_out) +{ + GetPixels(); + if ((unsigned)column >= (unsigned)Width) + { + if (WidthMask + 1 == Width) + { + column &= WidthMask; + } + else + { + column %= Width; + } + } + if (spans_out != nullptr) + { + if (Spandata[0] == nullptr) + { + Spandata[0] = CreateSpans (Pixeldata[0]); + } + *spans_out = Spandata[0][column]; + } + return Pixeldata[0] + column*Height; +} + +//========================================================================== +// +// +// +//========================================================================== + +const uint8_t *FWorldTexture::GetPixels () +{ + if (Pixeldata[0] == nullptr) + { + Pixeldata[0] = MakeTexture (LegacyRenderStyles[STYLE_Normal]); + } + return Pixeldata[0]; +} + From 494504229f8accc15f10241edce72e19c3151ca6 Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Sun, 18 Mar 2018 12:54:40 +0100 Subject: [PATCH 68/89] - fixed the BarShader texture. Even though unlikely, this should work as a regular texture because it can be used as such. As a result of the above, true color generation needs to be done explicitly now. --- src/r_data/renderstyle.h | 7 +++--- src/textures/shadertexture.cpp | 44 ++++++++++++++++++++++++---------- src/textures/textures.h | 1 + 3 files changed, 36 insertions(+), 16 deletions(-) diff --git a/src/r_data/renderstyle.h b/src/r_data/renderstyle.h index b1fd98a5ce..68bc9a2421 100644 --- a/src/r_data/renderstyle.h +++ b/src/r_data/renderstyle.h @@ -139,10 +139,9 @@ union FRenderStyle bool IsVisible(double alpha) const throw(); private: // Code that compares an actor's render style with a legacy render - // style value should be updated. Making these conversion operators - // private will catch those cases. - operator ERenderStyle() const { return STYLE_Normal; } - operator int() const { return STYLE_Normal; } + // style value should be updated. + operator ERenderStyle() = delete; + operator int() const = delete; }; extern FRenderStyle LegacyRenderStyles[STYLE_Count]; diff --git a/src/textures/shadertexture.cpp b/src/textures/shadertexture.cpp index 93e4234702..2834c93189 100644 --- a/src/textures/shadertexture.cpp +++ b/src/textures/shadertexture.cpp @@ -49,9 +49,11 @@ #include "r_defs.h" #include "r_state.h" #include "r_data/r_translate.h" +#include "r_data/renderstyle.h" +#include "bitmap.h" -class FBarShader : public FTexture +class FBarShader : public FWorldTexture { public: FBarShader(bool vertical, bool reverse) @@ -62,6 +64,7 @@ public: Width = vertical ? 2 : 256; Height = vertical ? 256 : 2; CalcBitSize(); + PixelsAreStatic = 2; // The alpha buffer is static, but if this gets used as a regular texture, a separate buffer needs to be made. // Fill the column/row with shading values. // Vertical shaders have have minimum alpha at the top @@ -106,24 +109,41 @@ public: } } } - DummySpan[0].TopOffset = 0; - DummySpan[0].Length = vertical ? 256 : 2; - DummySpan[1].TopOffset = 0; - DummySpan[1].Length = 0; } - const uint8_t *GetColumn(unsigned int column, const Span **spans_out) + + uint8_t *MakeTexture(FRenderStyle style) override { - if (spans_out != NULL) + if (style.Flags & STYLEF_RedIsAlpha) { - *spans_out = DummySpan; + return Pixels; + } + else + { + // Since this presents itself to the game as a regular named texture + // it can easily be used on walls and flats and should work as such, + // even if it makes little sense. + auto Pix = new uint8_t[512]; + for (int i = 0; i < 512; i++) + { + Pix[i] = GrayMap[Pixels[i]]; + } + return Pix; } - return Pixels + ((column & WidthMask) << HeightBits); } - const uint8_t *GetPixels() { return Pixels; } - void Unload() {} + + int CopyTrueColorPixels(FBitmap *bmp, int x, int y, int rotate, FCopyInfo *inf = NULL) override + { + bmp->CopyPixelData(x, y, Pixels, Width, Height, Height, 1, rotate, translationtables[TRANSLATION_Standard][8]->Palette, inf); + } + + bool UseBasePalette() override + { + return false; + } + + private: uint8_t Pixels[512]; - Span DummySpan[2]; }; diff --git a/src/textures/textures.h b/src/textures/textures.h index 0aede45625..675a9d4a39 100644 --- a/src/textures/textures.h +++ b/src/textures/textures.h @@ -588,6 +588,7 @@ class FWorldTexture : public FTexture protected: uint8_t *Pixeldata[2] = { nullptr, nullptr }; Span **Spandata[2] = { nullptr, nullptr }; + uint8_t PixelsAreStatic = 0; // can be set by subclasses which provide static pixel buffers. FWorldTexture(const char *name = nullptr, int lumpnum = -1); ~FWorldTexture(); From de8db297a6e04c02dc4772c6a239fe33160994ca Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Sun, 18 Mar 2018 13:12:25 +0100 Subject: [PATCH 69/89] - made the backdrop texture also inherit from FWorldTexture. In this case the only benefit is one less piece of GetColumn duplication - this texture is simply not usable in-game, unlike the BarShader. --- src/textures/backdroptexture.cpp | 47 ++++++-------------------------- 1 file changed, 8 insertions(+), 39 deletions(-) diff --git a/src/textures/backdroptexture.cpp b/src/textures/backdroptexture.cpp index aec95cc2e7..05d3f2541a 100644 --- a/src/textures/backdroptexture.cpp +++ b/src/textures/backdroptexture.cpp @@ -56,7 +56,7 @@ // //============================================================================= -struct FBackdropTexture : public FTexture +class FBackdropTexture : public FWorldTexture { enum { @@ -77,15 +77,12 @@ struct FBackdropTexture : public FTexture public: FBackdropTexture(); - const uint8_t *GetColumn(unsigned int column, const Span **spans_out); - const uint8_t *GetPixels(); - void Unload(); - bool CheckModified(); + bool CheckModified() override; + uint8_t *MakeTexture(FRenderStyle style) override; protected: uint32_t costab[COS_SIZE]; - uint8_t *Pixels; - static const Span DummySpan[2]; + uint8_t Pixels[160*144]; int LastRenderTic; uint32_t time1, time2, time3, time4; @@ -170,8 +167,6 @@ static uint8_t pattern2[1024] = 7, 7, 0, 5, 1, 6, 7, 9,12, 9,12,21,22,25,24,22,23,25,24,18,24,22,17,13,10, 9,10, 9, 6,11, 6, 5, }; -const FTexture::Span FBackdropTexture::DummySpan[2] = { { 0, 160 }, { 0, 0 } }; - //============================================================================= // // @@ -180,7 +175,7 @@ const FTexture::Span FBackdropTexture::DummySpan[2] = { { 0, 160 }, { 0, 0 } }; FBackdropTexture::FBackdropTexture() { - Pixels = nullptr; + PixelsAreStatic = 3; Width = 144; Height = 160; WidthBits = 8; @@ -214,39 +209,14 @@ bool FBackdropTexture::CheckModified() return LastRenderTic != gametic; } -void FBackdropTexture::Unload() -{ - if (Pixels != nullptr) delete[] Pixels; - Pixels = nullptr; -} - //============================================================================= // -// +// There's no point making this work as a regular texture as it is made to +// work with special translations. As an alpha texture it should be fine. // //============================================================================= -const uint8_t *FBackdropTexture::GetColumn(unsigned int column, const Span **spans_out) -{ - if (LastRenderTic != gametic) - { - Render(); - } - column = clamp(column, 0u, 143u); - if (spans_out != nullptr) - { - *spans_out = DummySpan; - } - return Pixels + column*160; -} - -//============================================================================= -// -// -// -//============================================================================= - -const uint8_t *FBackdropTexture::GetPixels() +uint8_t *FBackdropTexture::MakeTexture(FRenderStyle style) { if (LastRenderTic != gametic) { @@ -266,7 +236,6 @@ void FBackdropTexture::Render() uint8_t *from; int width, height, pitch; - if (Pixels == nullptr) Pixels = new uint8_t[160 * 144]; width = 160; height = 144; pitch = width; From 94eadb1a8c1aee1b83d7ccab059158e8b21601be Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Sun, 18 Mar 2018 13:47:40 +0100 Subject: [PATCH 70/89] - made it compile again. --- src/am_map.cpp | 2 +- src/r_data/renderstyle.h | 1 - src/textures/automaptexture.cpp | 1 - src/textures/jpegtexture.cpp | 1 - src/textures/pcxtexture.cpp | 1 - src/textures/rawpagetexture.cpp | 1 - src/textures/shadertexture.cpp | 1 + src/v_palette.cpp | 4 +--- 8 files changed, 3 insertions(+), 9 deletions(-) diff --git a/src/am_map.cpp b/src/am_map.cpp index c6e6ba19ba..2f6c04c6d8 100644 --- a/src/am_map.cpp +++ b/src/am_map.cpp @@ -3088,7 +3088,7 @@ static void DrawMarker (FTexture *tex, double x, double y, int yadjust, DTA_TranslationIndex, translation, DTA_Alpha, alpha, DTA_FillColor, fillcolor, - DTA_RenderStyle, uint32_t(renderstyle), + DTA_RenderStyle, renderstyle.AsDWORD, TAG_DONE); } diff --git a/src/r_data/renderstyle.h b/src/r_data/renderstyle.h index 68bc9a2421..21c41278a5 100644 --- a/src/r_data/renderstyle.h +++ b/src/r_data/renderstyle.h @@ -133,7 +133,6 @@ union FRenderStyle uint32_t AsDWORD; inline FRenderStyle &operator= (ERenderStyle legacy); - operator uint32_t() const { return AsDWORD; } bool operator==(const FRenderStyle &o) const { return AsDWORD == o.AsDWORD; } void CheckFuzz(); bool IsVisible(double alpha) const throw(); diff --git a/src/textures/automaptexture.cpp b/src/textures/automaptexture.cpp index 27080669ee..c07eded6ed 100644 --- a/src/textures/automaptexture.cpp +++ b/src/textures/automaptexture.cpp @@ -51,7 +51,6 @@ class FAutomapTexture : public FWorldTexture { public: FAutomapTexture(int lumpnum); - ~FAutomapTexture (); uint8_t *MakeTexture (FRenderStyle style); }; diff --git a/src/textures/jpegtexture.cpp b/src/textures/jpegtexture.cpp index abf1e34ec4..93aac09ca0 100644 --- a/src/textures/jpegtexture.cpp +++ b/src/textures/jpegtexture.cpp @@ -183,7 +183,6 @@ class FJPEGTexture : public FWorldTexture { public: FJPEGTexture (int lumpnum, int width, int height); - ~FJPEGTexture (); FTextureFormat GetFormat () override; int CopyTrueColorPixels(FBitmap *bmp, int x, int y, int rotate, FCopyInfo *inf = NULL) override; diff --git a/src/textures/pcxtexture.cpp b/src/textures/pcxtexture.cpp index efe12e3c21..f5635c7a38 100644 --- a/src/textures/pcxtexture.cpp +++ b/src/textures/pcxtexture.cpp @@ -85,7 +85,6 @@ class FPCXTexture : public FWorldTexture { public: FPCXTexture (int lumpnum, PCXHeader &); - ~FPCXTexture (); FTextureFormat GetFormat () override; diff --git a/src/textures/rawpagetexture.cpp b/src/textures/rawpagetexture.cpp index 7e9268c6e4..adf8abffff 100644 --- a/src/textures/rawpagetexture.cpp +++ b/src/textures/rawpagetexture.cpp @@ -50,7 +50,6 @@ class FRawPageTexture : public FWorldTexture { public: FRawPageTexture (int lumpnum); - ~FRawPageTexture (); uint8_t *MakeTexture (FRenderStyle style) override; }; diff --git a/src/textures/shadertexture.cpp b/src/textures/shadertexture.cpp index 2834c93189..67d4db683a 100644 --- a/src/textures/shadertexture.cpp +++ b/src/textures/shadertexture.cpp @@ -134,6 +134,7 @@ public: int CopyTrueColorPixels(FBitmap *bmp, int x, int y, int rotate, FCopyInfo *inf = NULL) override { bmp->CopyPixelData(x, y, Pixels, Width, Height, Height, 1, rotate, translationtables[TRANSLATION_Standard][8]->Palette, inf); + return 0; } bool UseBasePalette() override diff --git a/src/v_palette.cpp b/src/v_palette.cpp index 436fe84dcd..af4aae4fba 100644 --- a/src/v_palette.cpp +++ b/src/v_palette.cpp @@ -374,9 +374,7 @@ static bool FixBuildPalette (uint8_t *opal, int lump, bool blood) void InitPalette () { uint8_t pal[768]; - bool usingBuild = false; - int lump; - + ReadPalette(Wads.CheckNumForName("PLAYPAL"), pal); GPalette.SetPalette (pal); From 47bfbb5e0825c01a80c813f3f08f0f5a86674e98 Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Sun, 18 Mar 2018 14:18:19 +0100 Subject: [PATCH 71/89] - Make BuildTexture inherit from worldtexture. - handle WorldTextures that can change their content automatically. --- src/textures/buildtexture.cpp | 67 +++-------------------------------- src/textures/worldtexture.cpp | 6 +++- 2 files changed, 9 insertions(+), 64 deletions(-) diff --git a/src/textures/buildtexture.cpp b/src/textures/buildtexture.cpp index dd95455531..7223286675 100644 --- a/src/textures/buildtexture.cpp +++ b/src/textures/buildtexture.cpp @@ -48,18 +48,14 @@ // //========================================================================== -class FBuildTexture : public FTexture +class FBuildTexture : public FWorldTexture { public: FBuildTexture (int tilenum, const uint8_t *pixels, int width, int height, int left, int top); - ~FBuildTexture (); - - const uint8_t *GetColumn (unsigned int column, const Span **spans_out); - const uint8_t *GetPixels (); + uint8_t *MakeTexture(FRenderStyle style) override { return const_cast(Pixels); } // This is only to make it compile for now and will be changed later. protected: const uint8_t *Pixels; - Span **Spans; }; @@ -70,8 +66,9 @@ protected: //========================================================================== FBuildTexture::FBuildTexture (int tilenum, const uint8_t *pixels, int width, int height, int left, int top) -: Pixels (pixels), Spans (NULL) +: Pixels (pixels) { + PixelsAreStatic = 3; Width = width; Height = height; LeftOffset = left; @@ -81,62 +78,6 @@ FBuildTexture::FBuildTexture (int tilenum, const uint8_t *pixels, int width, int UseType = TEX_Build; } -//========================================================================== -// -// -// -//========================================================================== - -FBuildTexture::~FBuildTexture () -{ - if (Spans != NULL) - { - FreeSpans (Spans); - Spans = NULL; - } -} - -//========================================================================== -// -// -// -//========================================================================== - -const uint8_t *FBuildTexture::GetPixels () -{ - return Pixels; -} - -//========================================================================== -// -// -// -//========================================================================== - -const uint8_t *FBuildTexture::GetColumn (unsigned int column, const Span **spans_out) -{ - if (column >= Width) - { - if (WidthMask + 1 == Width) - { - column &= WidthMask; - } - else - { - column %= Width; - } - } - if (spans_out != NULL) - { - if (Spans == NULL) - { - Spans = CreateSpans (Pixels); - } - *spans_out = Spans[column]; - } - return Pixels + column*Height; -} - //=========================================================================== // // AddTiles diff --git a/src/textures/worldtexture.cpp b/src/textures/worldtexture.cpp index 0370bf3e81..8968902360 100644 --- a/src/textures/worldtexture.cpp +++ b/src/textures/worldtexture.cpp @@ -91,7 +91,7 @@ void FWorldTexture::Unload () // //========================================================================== -const uint8_t *FWorldTexture::GetColumn (unsigned int column, const Span **spans_out) +const uint8_t *FWorldTexture::GetColumn(unsigned int column, const Span **spans_out) { GetPixels(); if ((unsigned)column >= (unsigned)Width) @@ -124,6 +124,10 @@ const uint8_t *FWorldTexture::GetColumn (unsigned int column, const Span **spans const uint8_t *FWorldTexture::GetPixels () { + if (CheckModified()) + { + Unload(); + } if (Pixeldata[0] == nullptr) { Pixeldata[0] = MakeTexture (LegacyRenderStyles[STYLE_Normal]); From a399d79f8a3a211b5a2404d4b9ccb5100a8a8ae8 Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Sun, 18 Mar 2018 14:18:42 +0100 Subject: [PATCH 72/89] - minor reformatting. --- src/textures/canvastexture.cpp | 2 +- src/textures/skyboxtexture.cpp | 2 +- src/textures/skyboxtexture.h | 2 +- src/textures/texture.cpp | 12 +++--------- src/textures/textures.h | 9 ++++----- src/textures/warptexture.cpp | 2 +- src/v_font.cpp | 10 +++++----- src/v_video.cpp | 2 +- 8 files changed, 17 insertions(+), 24 deletions(-) diff --git a/src/textures/canvastexture.cpp b/src/textures/canvastexture.cpp index d2530017bf..bb6b3d6856 100644 --- a/src/textures/canvastexture.cpp +++ b/src/textures/canvastexture.cpp @@ -65,7 +65,7 @@ FCanvasTexture::~FCanvasTexture () Unload (); } -const uint8_t *FCanvasTexture::GetColumn (unsigned int column, const Span **spans_out) +const uint8_t *FCanvasTexture::GetColumn(unsigned int column, const Span **spans_out) { bNeedsUpdate = true; if (Canvas == NULL) diff --git a/src/textures/skyboxtexture.cpp b/src/textures/skyboxtexture.cpp index 9c3b21b674..7f19e7f855 100644 --- a/src/textures/skyboxtexture.cpp +++ b/src/textures/skyboxtexture.cpp @@ -59,7 +59,7 @@ FSkyBox::~FSkyBox() // //----------------------------------------------------------------------------- -const uint8_t *FSkyBox::GetColumn (unsigned int column, const Span **spans_out) +const uint8_t *FSkyBox::GetColumn(unsigned int column, const Span **spans_out) { if (faces[0]) return faces[0]->GetColumn(column, spans_out); return NULL; diff --git a/src/textures/skyboxtexture.h b/src/textures/skyboxtexture.h index 3a4edd042d..74fc68bbef 100644 --- a/src/textures/skyboxtexture.h +++ b/src/textures/skyboxtexture.h @@ -17,7 +17,7 @@ public: FSkyBox(); ~FSkyBox(); - const uint8_t *GetColumn (unsigned int column, const Span **spans_out); + const uint8_t *GetColumn(unsigned int column, const Span **spans_out); const uint8_t *GetPixels (); int CopyTrueColorPixels(FBitmap *bmp, int x, int y, int rotate, FCopyInfo *inf); bool UseBasePalette(); diff --git a/src/textures/texture.cpp b/src/textures/texture.cpp index 154efb222c..c81b691c42 100644 --- a/src/textures/texture.cpp +++ b/src/textures/texture.cpp @@ -961,15 +961,9 @@ void FDummyTexture::SetSize (int width, int height) } // This must never be called -const uint8_t *FDummyTexture::GetColumn (unsigned int column, const Span **spans_out) +uint8_t *FDummyTexture::MakeTexture (FRenderStyle) { - return NULL; -} - -// And this also must never be called -const uint8_t *FDummyTexture::GetPixels () -{ - return NULL; + return nullptr; } //========================================================================== @@ -996,7 +990,7 @@ CCMD (printspans) { const FTexture::Span *spans; Printf ("%4d:", x); - tex->GetColumn (x, &spans); + tex->GetColumn(x, &spans); while (spans->Length != 0) { Printf (" (%4d,%4d)", spans->TopOffset, spans->TopOffset+spans->Length-1); diff --git a/src/textures/textures.h b/src/textures/textures.h index 675a9d4a39..17cef6e1cb 100644 --- a/src/textures/textures.h +++ b/src/textures/textures.h @@ -601,12 +601,11 @@ protected: }; // A texture that doesn't really exist -class FDummyTexture : public FTexture +class FDummyTexture : public FWorldTexture { public: FDummyTexture (); - const uint8_t *GetColumn (unsigned int column, const Span **spans_out); - const uint8_t *GetPixels (); + uint8_t *MakeTexture(FRenderStyle); void SetSize (int width, int height); }; @@ -618,7 +617,7 @@ public: ~FWarpTexture (); virtual int CopyTrueColorPixels(FBitmap *bmp, int x, int y, int rotate=0, FCopyInfo *inf = NULL); - const uint8_t *GetColumn (unsigned int column, const Span **spans_out); + const uint8_t *GetColumn(unsigned int column, const Span **spans_out); const uint8_t *GetPixels (); const uint32_t *GetPixelsBgra() override; void Unload (); @@ -653,7 +652,7 @@ public: FCanvasTexture (const char *name, int width, int height); ~FCanvasTexture (); - const uint8_t *GetColumn (unsigned int column, const Span **spans_out); + const uint8_t *GetColumn(unsigned int column, const Span **spans_out); const uint8_t *GetPixels (); const uint32_t *GetPixelsBgra() override; void Unload (); diff --git a/src/textures/warptexture.cpp b/src/textures/warptexture.cpp index 2e073c1869..41920849d0 100644 --- a/src/textures/warptexture.cpp +++ b/src/textures/warptexture.cpp @@ -117,7 +117,7 @@ const uint32_t *FWarpTexture::GetPixelsBgra() return PixelsBgra.data(); } -const uint8_t *FWarpTexture::GetColumn (unsigned int column, const Span **spans_out) +const uint8_t *FWarpTexture::GetColumn(unsigned int column, const Span **spans_out) { uint64_t time =screen->FrameTime; diff --git a/src/v_font.cpp b/src/v_font.cpp index a8afa079c2..1b36c22191 100644 --- a/src/v_font.cpp +++ b/src/v_font.cpp @@ -177,7 +177,7 @@ class FFontChar1 : public FTexture { public: FFontChar1 (FTexture *sourcelump); - const uint8_t *GetColumn (unsigned int column, const Span **spans_out); + const uint8_t *GetColumn(unsigned int column, const Span **spans_out); const uint8_t *GetPixels (); void SetSourceRemap(const uint8_t *sourceremap); void Unload (); @@ -198,7 +198,7 @@ public: FFontChar2 (int sourcelump, int sourcepos, int width, int height, int leftofs=0, int topofs=0); ~FFontChar2 (); - const uint8_t *GetColumn (unsigned int column, const Span **spans_out); + const uint8_t *GetColumn(unsigned int column, const Span **spans_out); const uint8_t *GetPixels (); void SetSourceRemap(const uint8_t *sourceremap); void Unload (); @@ -559,7 +559,7 @@ void RecordTextureColors (FTexture *pic, uint8_t *usedcolors) for (x = pic->GetWidth() - 1; x >= 0; x--) { const FTexture::Span *spans; - const uint8_t *column = pic->GetColumn (x, &spans); + const uint8_t *column = pic->GetColumn(x, &spans); while (spans->Length != 0) { @@ -1692,7 +1692,7 @@ void FFontChar1::MakeTexture () // //========================================================================== -const uint8_t *FFontChar1::GetColumn (unsigned int column, const Span **spans_out) +const uint8_t *FFontChar1::GetColumn(unsigned int column, const Span **spans_out) { if (Pixels == NULL) { @@ -1814,7 +1814,7 @@ const uint8_t *FFontChar2::GetPixels () // //========================================================================== -const uint8_t *FFontChar2::GetColumn (unsigned int column, const Span **spans_out) +const uint8_t *FFontChar2::GetColumn(unsigned int column, const Span **spans_out) { if (Pixels == NULL) { diff --git a/src/v_video.cpp b/src/v_video.cpp index ca2e8b62ae..77f83b285d 100644 --- a/src/v_video.cpp +++ b/src/v_video.cpp @@ -1008,7 +1008,7 @@ void FPaletteTester::SetTranslation(int num) // //========================================================================== -const uint8_t *FPaletteTester::GetColumn (unsigned int column, const Span **spans_out) +const uint8_t *FPaletteTester::GetColumn(unsigned int column, const Span **spans_out) { if (CurTranslation != WantTranslation) { From f4d9ad1123d912c63d300aa8965043330d6f8a66 Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Sun, 18 Mar 2018 21:33:44 +0100 Subject: [PATCH 73/89] - extended FTexture::GetPixels and FTexture::GetColumn by a RenderStyle parameter. Now it is no longer necessary to provide specially set up textures for rendering shaded decals, they can use any PNG texture now that contains a proper red channel. Handling of the alPh chunk has been removed as a result as it in no longer needed. --- src/gl/textures/gl_material.cpp | 5 +- src/gl/textures/gl_texture.cpp | 2 +- src/polyrenderer/drawers/poly_draw_args.cpp | 41 +++++---- src/polyrenderer/drawers/poly_draw_args.h | 10 +-- src/polyrenderer/poly_renderthread.cpp | 6 +- src/polyrenderer/poly_renderthread.h | 2 +- src/polyrenderer/scene/poly_model.cpp | 4 +- src/polyrenderer/scene/poly_plane.cpp | 4 +- src/polyrenderer/scene/poly_sky.cpp | 2 +- src/polyrenderer/scene/poly_wall.cpp | 2 +- src/polyrenderer/scene/poly_wallsprite.cpp | 2 +- src/r_data/renderstyle.h | 10 +++ src/swrenderer/line/r_renderdrawsegment.cpp | 5 +- src/swrenderer/line/r_walldraw.cpp | 4 +- src/swrenderer/plane/r_skyplane.cpp | 4 +- src/swrenderer/r_renderthread.cpp | 6 +- src/swrenderer/r_renderthread.h | 2 +- src/swrenderer/r_swcanvas.cpp | 2 +- src/swrenderer/r_swrenderer.cpp | 8 +- src/swrenderer/things/r_decal.cpp | 8 +- src/swrenderer/things/r_decal.h | 2 +- src/swrenderer/things/r_model.cpp | 4 +- src/swrenderer/things/r_playersprite.cpp | 4 +- src/swrenderer/things/r_sprite.cpp | 4 +- src/swrenderer/things/r_wallsprite.cpp | 8 +- src/swrenderer/things/r_wallsprite.h | 2 +- src/swrenderer/viewport/r_skydrawer.cpp | 4 +- src/swrenderer/viewport/r_spandrawer.cpp | 4 +- src/swrenderer/viewport/r_spritedrawer.cpp | 4 +- src/swrenderer/viewport/r_spritedrawer.h | 2 +- src/textures/backdroptexture.cpp | 4 +- src/textures/canvastexture.cpp | 12 +-- src/textures/multipatchtexture.cpp | 10 ++- src/textures/skyboxtexture.cpp | 8 +- src/textures/skyboxtexture.h | 4 +- src/textures/texture.cpp | 39 +++++---- src/textures/textures.h | 52 ++++++----- src/textures/warptexture.cpp | 97 ++++----------------- src/textures/worldtexture.cpp | 35 +++++--- src/v_font.cpp | 28 +++--- src/v_video.cpp | 12 +-- 41 files changed, 218 insertions(+), 250 deletions(-) diff --git a/src/gl/textures/gl_material.cpp b/src/gl/textures/gl_material.cpp index 859706772a..98f0559d94 100644 --- a/src/gl/textures/gl_material.cpp +++ b/src/gl/textures/gl_material.cpp @@ -31,6 +31,7 @@ #include "r_utility.h" #include "templates.h" #include "sc_man.h" +#include "r_data/renderstyle.h" #include "colormatcher.h" #include "textures/warpbuffer.h" #include "textures/bitmap.h" @@ -297,7 +298,7 @@ const FHardwareTexture *FGLTexture::Bind(int texunit, int clampmode, int transla if (hwtex) { // Texture has become invalid - if ((!tex->bHasCanvas && (!tex->bWarped || gl.legacyMode)) && tex->CheckModified()) + if ((!tex->bHasCanvas && (!tex->bWarped || gl.legacyMode)) && tex->CheckModified(DefaultRenderStyle())) { Clean(true); hwtex = CreateHwTexture(); @@ -323,7 +324,7 @@ const FHardwareTexture *FGLTexture::Bind(int texunit, int clampmode, int transla WarpBuffer((uint32_t*)warpbuffer, (const uint32_t*)buffer, w, h, wt->WidthOffsetMultiplier, wt->HeightOffsetMultiplier, screen->FrameTime, wt->Speed, tex->bWarped); delete[] buffer; buffer = warpbuffer; - wt->GenTime = screen->FrameTime; + wt->GenTime[0] = screen->FrameTime; } tex->ProcessData(buffer, w, h, false); } diff --git a/src/gl/textures/gl_texture.cpp b/src/gl/textures/gl_texture.cpp index 0680ccdd69..f228d21235 100644 --- a/src/gl/textures/gl_texture.cpp +++ b/src/gl/textures/gl_texture.cpp @@ -238,7 +238,7 @@ void FTexture::CreateDefaultBrightmap() ) { // May have one - let's check when we use this texture - const uint8_t *texbuf = GetPixels(); + const uint8_t *texbuf = GetPixels(DefaultRenderStyle()); const int white = ColorMatcher.Pick(255,255,255); int size = GetWidth() * GetHeight(); diff --git a/src/polyrenderer/drawers/poly_draw_args.cpp b/src/polyrenderer/drawers/poly_draw_args.cpp index 466a39f4ab..312cb3e32b 100644 --- a/src/polyrenderer/drawers/poly_draw_args.cpp +++ b/src/polyrenderer/drawers/poly_draw_args.cpp @@ -46,20 +46,21 @@ void PolyDrawArgs::SetTexture(const uint8_t *texels, int width, int height) mTranslation = nullptr; } -void PolyDrawArgs::SetTexture(FTexture *texture) +void PolyDrawArgs::SetTexture(FTexture *texture, FRenderStyle style) { mTextureWidth = texture->GetWidth(); mTextureHeight = texture->GetHeight(); if (PolyRenderer::Instance()->RenderTarget->IsBgra()) mTexturePixels = (const uint8_t *)texture->GetPixelsBgra(); else - mTexturePixels = texture->GetPixels(); + mTexturePixels = texture->GetPixels(style); mTranslation = nullptr; } -void PolyDrawArgs::SetTexture(FTexture *texture, uint32_t translationID, bool forcePal) +void PolyDrawArgs::SetTexture(FTexture *texture, uint32_t translationID, FRenderStyle style) { - if (translationID != 0xffffffff && translationID != 0) + // Alphatexture overrides translations. + if (translationID != 0xffffffff && translationID != 0 && !(style.Flags & STYLEF_RedIsAlpha)) { FRemapTable *table = TranslationToTable(translationID); if (table != nullptr && !table->Inactive) @@ -71,20 +72,20 @@ void PolyDrawArgs::SetTexture(FTexture *texture, uint32_t translationID, bool fo mTextureWidth = texture->GetWidth(); mTextureHeight = texture->GetHeight(); - mTexturePixels = texture->GetPixels(); + mTexturePixels = texture->GetPixels(style); return; } } - if (forcePal) + if (style.Flags & STYLEF_RedIsAlpha) { mTextureWidth = texture->GetWidth(); mTextureHeight = texture->GetHeight(); - mTexturePixels = texture->GetPixels(); + mTexturePixels = texture->GetPixels(style); } else { - SetTexture(texture); + SetTexture(texture, style); } } @@ -164,8 +165,7 @@ void PolyDrawArgs::DrawElements(PolyRenderThread *thread, const TriVertex *verti void PolyDrawArgs::SetStyle(const FRenderStyle &renderstyle, double alpha, uint32_t fillcolor, uint32_t translationID, FTexture *tex, bool fullbright) { - bool forcePal = (renderstyle == LegacyRenderStyles[STYLE_Shaded] || renderstyle == LegacyRenderStyles[STYLE_AddShaded]); - SetTexture(tex, translationID, forcePal); + SetTexture(tex, translationID, renderstyle); if (renderstyle == LegacyRenderStyles[STYLE_Normal] || (r_drawfuzz == 0 && renderstyle == LegacyRenderStyles[STYLE_OptFuzzy])) { @@ -232,20 +232,20 @@ void RectDrawArgs::SetTexture(const uint8_t *texels, int width, int height) mTranslation = nullptr; } -void RectDrawArgs::SetTexture(FTexture *texture) +void RectDrawArgs::SetTexture(FTexture *texture, FRenderStyle style) { mTextureWidth = texture->GetWidth(); mTextureHeight = texture->GetHeight(); if (PolyRenderer::Instance()->RenderTarget->IsBgra()) mTexturePixels = (const uint8_t *)texture->GetPixelsBgra(); else - mTexturePixels = texture->GetPixels(); + mTexturePixels = texture->GetPixels(style); mTranslation = nullptr; } -void RectDrawArgs::SetTexture(FTexture *texture, uint32_t translationID, bool forcePal) +void RectDrawArgs::SetTexture(FTexture *texture, uint32_t translationID, FRenderStyle style) { - if (translationID != 0xffffffff && translationID != 0) + if (translationID != 0xffffffff && translationID != 0 && !(style.Flags & STYLEF_RedIsAlpha)) { FRemapTable *table = TranslationToTable(translationID); if (table != nullptr && !table->Inactive) @@ -257,20 +257,20 @@ void RectDrawArgs::SetTexture(FTexture *texture, uint32_t translationID, bool fo mTextureWidth = texture->GetWidth(); mTextureHeight = texture->GetHeight(); - mTexturePixels = texture->GetPixels(); + mTexturePixels = texture->GetPixels(style); return; } } - if (forcePal) + if (style.Flags & STYLEF_RedIsAlpha) { mTextureWidth = texture->GetWidth(); mTextureHeight = texture->GetHeight(); - mTexturePixels = texture->GetPixels(); + mTexturePixels = texture->GetPixels(style); } else { - SetTexture(texture); + SetTexture(texture, style); } } @@ -315,10 +315,9 @@ void RectDrawArgs::Draw(PolyRenderThread *thread, double x0, double x1, double y thread->DrawQueue->Push(*this); } -void RectDrawArgs::SetStyle(const FRenderStyle &renderstyle, double alpha, uint32_t fillcolor, uint32_t translationID, FTexture *tex, bool fullbright) +void RectDrawArgs::SetStyle(FRenderStyle renderstyle, double alpha, uint32_t fillcolor, uint32_t translationID, FTexture *tex, bool fullbright) { - bool forcePal = (renderstyle == LegacyRenderStyles[STYLE_Shaded] || renderstyle == LegacyRenderStyles[STYLE_AddShaded]); - SetTexture(tex, translationID, forcePal); + SetTexture(tex, translationID, renderstyle); if (renderstyle == LegacyRenderStyles[STYLE_Normal] || (r_drawfuzz == 0 && renderstyle == LegacyRenderStyles[STYLE_OptFuzzy])) { diff --git a/src/polyrenderer/drawers/poly_draw_args.h b/src/polyrenderer/drawers/poly_draw_args.h index eb543bbbf5..05ad0862d9 100644 --- a/src/polyrenderer/drawers/poly_draw_args.h +++ b/src/polyrenderer/drawers/poly_draw_args.h @@ -67,8 +67,8 @@ class PolyDrawArgs public: void SetClipPlane(int index, const PolyClipPlane &plane) { mClipPlane[index] = plane; } void SetTexture(const uint8_t *texels, int width, int height); - void SetTexture(FTexture *texture); - void SetTexture(FTexture *texture, uint32_t translationID, bool forcePal = false); + void SetTexture(FTexture *texture, FRenderStyle style); + void SetTexture(FTexture *texture, uint32_t translationID, FRenderStyle style); void SetLight(FSWColormap *basecolormap, uint32_t lightlevel, double globVis, bool fixed); void SetDepthTest(bool enable) { mDepthTest = enable; } void SetStencilTestValue(uint8_t stencilTestValue) { mStencilTestValue = stencilTestValue; } @@ -186,11 +186,11 @@ class RectDrawArgs { public: void SetTexture(const uint8_t *texels, int width, int height); - void SetTexture(FTexture *texture); - void SetTexture(FTexture *texture, uint32_t translationID, bool forcePal = false); + void SetTexture(FTexture *texture, FRenderStyle style); + void SetTexture(FTexture *texture, uint32_t translationID, FRenderStyle style); void SetLight(FSWColormap *basecolormap, uint32_t lightlevel); void SetStyle(TriBlendMode blendmode, double srcalpha = 1.0, double destalpha = 1.0) { mBlendMode = blendmode; mSrcAlpha = (uint32_t)(srcalpha * 256.0 + 0.5); mDestAlpha = (uint32_t)(destalpha * 256.0 + 0.5); } - void SetStyle(const FRenderStyle &renderstyle, double alpha, uint32_t fillcolor, uint32_t translationID, FTexture *texture, bool fullbright); + void SetStyle(FRenderStyle renderstyle, double alpha, uint32_t fillcolor, uint32_t translationID, FTexture *texture, bool fullbright); void SetColor(uint32_t bgra, uint8_t palindex); void Draw(PolyRenderThread *thread, double x0, double x1, double y0, double y1, double u0, double u1, double v0, double v1); diff --git a/src/polyrenderer/poly_renderthread.cpp b/src/polyrenderer/poly_renderthread.cpp index 9c3b331226..55d1c84696 100644 --- a/src/polyrenderer/poly_renderthread.cpp +++ b/src/polyrenderer/poly_renderthread.cpp @@ -74,7 +74,7 @@ void PolyRenderThread::FlushDrawQueue() } } -void PolyRenderThread::PrepareTexture(FTexture *texture) +void PolyRenderThread::PrepareTexture(FTexture *texture, FRenderStyle style) { if (texture == nullptr) return; @@ -91,9 +91,9 @@ void PolyRenderThread::PrepareTexture(FTexture *texture) std::unique_lock lock(loadmutex); - texture->GetPixels(); + texture->GetPixels(style); const FTexture::Span *spans; - texture->GetColumn(0, &spans); + texture->GetColumn(style, 0, &spans); if (PolyRenderer::Instance()->RenderTarget->IsBgra()) { texture->GetPixelsBgra(); diff --git a/src/polyrenderer/poly_renderthread.h b/src/polyrenderer/poly_renderthread.h index af10fd45c8..afed28b193 100644 --- a/src/polyrenderer/poly_renderthread.h +++ b/src/polyrenderer/poly_renderthread.h @@ -47,7 +47,7 @@ public: DrawerCommandQueuePtr DrawQueue; // Make sure texture can accessed safely - void PrepareTexture(FTexture *texture); + void PrepareTexture(FTexture *texture, FRenderStyle style); // Setup poly object in a threadsafe manner void PreparePolyObject(subsector_t *sub); diff --git a/src/polyrenderer/scene/poly_model.cpp b/src/polyrenderer/scene/poly_model.cpp index c952625c31..b2ce178cce 100644 --- a/src/polyrenderer/scene/poly_model.cpp +++ b/src/polyrenderer/scene/poly_model.cpp @@ -147,7 +147,7 @@ void PolyModelRenderer::DrawArrays(int start, int count) args.SetStencilTestValue(StencilValue); args.SetClipPlane(0, PolyClipPlane()); args.SetStyle(TriBlendMode::TextureOpaque); - args.SetTexture(SkinTexture); + args.SetTexture(SkinTexture, DefaultRenderStyle()); args.SetDepthTest(true); args.SetWriteDepth(true); args.SetWriteStencil(false); @@ -181,7 +181,7 @@ void PolyModelRenderer::DrawElements(int numIndices, size_t offset) args.SetStencilTestValue(StencilValue); args.SetClipPlane(0, PolyClipPlane()); args.SetStyle(TriBlendMode::TextureOpaque); - args.SetTexture(SkinTexture); + args.SetTexture(SkinTexture, DefaultRenderStyle()); args.SetDepthTest(true); args.SetWriteDepth(true); args.SetWriteStencil(false); diff --git a/src/polyrenderer/scene/poly_plane.cpp b/src/polyrenderer/scene/poly_plane.cpp index f5485d0969..874fe26306 100644 --- a/src/polyrenderer/scene/poly_plane.cpp +++ b/src/polyrenderer/scene/poly_plane.cpp @@ -81,7 +81,7 @@ void RenderPolyPlane::RenderNormal(PolyRenderThread *thread, const TriMatrix &wo args.SetStencilTestValue(stencilValue); args.SetWriteStencil(true, stencilValue + 1); args.SetClipPlane(0, clipPlane); - args.SetTexture(tex); + args.SetTexture(tex, DefaultRenderStyle()); args.SetStyle(TriBlendMode::TextureOpaque); args.DrawArray(thread, vertices, fakeflat.Subsector->numlines, PolyDrawMode::TriangleFan); } @@ -572,7 +572,7 @@ void Render3DFloorPlane::Render(PolyRenderThread *thread, const TriMatrix &world args.SetFaceCullCCW(true); args.SetStencilTestValue(stencilValue); args.SetWriteStencil(true, stencilValue + 1); - args.SetTexture(tex); + args.SetTexture(tex, DefaultRenderStyle()); args.SetClipPlane(0, clipPlane); args.DrawArray(thread, vertices, sub->numlines, PolyDrawMode::TriangleFan); } diff --git a/src/polyrenderer/scene/poly_sky.cpp b/src/polyrenderer/scene/poly_sky.cpp index 06cb7a8ece..eafa4c94c0 100644 --- a/src/polyrenderer/scene/poly_sky.cpp +++ b/src/polyrenderer/scene/poly_sky.cpp @@ -91,7 +91,7 @@ void PolySkyDome::Render(PolyRenderThread *thread, const TriMatrix &worldToClip) RenderCapColorRow(thread, args, mCurrentSetup.frontskytex, 0, false); RenderCapColorRow(thread, args, mCurrentSetup.frontskytex, rc, true); - args.SetTexture(mCurrentSetup.frontskytex); + args.SetTexture(mCurrentSetup.frontskytex, DefaultRenderStyle()); uint32_t topcapcolor = mCurrentSetup.frontskytex->GetSkyCapColor(false); uint32_t bottomcapcolor = mCurrentSetup.frontskytex->GetSkyCapColor(true); diff --git a/src/polyrenderer/scene/poly_wall.cpp b/src/polyrenderer/scene/poly_wall.cpp index 20b9a1ade2..fb75f7bf45 100644 --- a/src/polyrenderer/scene/poly_wall.cpp +++ b/src/polyrenderer/scene/poly_wall.cpp @@ -327,7 +327,7 @@ void RenderPolyWall::Render(PolyRenderThread *thread, const TriMatrix &worldToCl args.SetStencilTestValue(StencilValue); args.SetWriteStencil(true, StencilValue + 1); if (Texture && !Polyportal) - args.SetTexture(Texture); + args.SetTexture(Texture, DefaultRenderStyle()); args.SetClipPlane(0, clipPlane); SetDynLights(thread, args); diff --git a/src/polyrenderer/scene/poly_wallsprite.cpp b/src/polyrenderer/scene/poly_wallsprite.cpp index 846524f9dd..7da68c5e54 100644 --- a/src/polyrenderer/scene/poly_wallsprite.cpp +++ b/src/polyrenderer/scene/poly_wallsprite.cpp @@ -105,7 +105,7 @@ void RenderPolyWallSprite::Render(PolyRenderThread *thread, const TriMatrix &wor args.SetTransform(&worldToClip); args.SetFaceCullCCW(true); args.SetStencilTestValue(stencilValue); - args.SetTexture(tex); + args.SetTexture(tex, thing->RenderStyle); args.SetClipPlane(0, clipPlane); args.SetDepthTest(true); args.SetWriteDepth(false); diff --git a/src/r_data/renderstyle.h b/src/r_data/renderstyle.h index 21c41278a5..afb82d3800 100644 --- a/src/r_data/renderstyle.h +++ b/src/r_data/renderstyle.h @@ -145,6 +145,16 @@ private: extern FRenderStyle LegacyRenderStyles[STYLE_Count]; +inline FRenderStyle DefaultRenderStyle() +{ + return LegacyRenderStyles[STYLE_Normal]; +} + +inline FRenderStyle BadRenderStyle() // This is just a marker to find places where work is still needed. +{ + return LegacyRenderStyles[STYLE_Normal]; +} + inline FRenderStyle &FRenderStyle::operator= (ERenderStyle legacy) { if (legacy < STYLE_None || legacy >= STYLE_Count) diff --git a/src/swrenderer/line/r_renderdrawsegment.cpp b/src/swrenderer/line/r_renderdrawsegment.cpp index 86f86c2cbe..f46fbc1331 100644 --- a/src/swrenderer/line/r_renderdrawsegment.cpp +++ b/src/swrenderer/line/r_renderdrawsegment.cpp @@ -155,6 +155,7 @@ namespace swrenderer bool RenderDrawSegment::RenderWall(DrawSegment *ds, int x1, int x2, WallDrawerArgs &walldrawerargs, SpriteDrawerArgs &columndrawerargs, bool visible, FDynamicColormap *basecolormap, int wallshade) { + auto renderstyle = DefaultRenderStyle(); auto viewport = Thread->Viewport.get(); Clip3DFloors *clip3d = Thread->Clip3D.get(); @@ -314,7 +315,7 @@ namespace swrenderer // draw the columns one at a time if (visible) { - Thread->PrepareTexture(tex); + Thread->PrepareTexture(tex, renderstyle); for (int x = x1; x < x2; ++x) { if (cameraLight->FixedColormap() == nullptr && cameraLight->FixedLightLevel() < 0) @@ -329,7 +330,7 @@ namespace swrenderer else sprtopscreen = viewport->CenterY - texturemid * spryscale; - columndrawerargs.DrawMaskedColumn(Thread, x, iscale, tex, maskedtexturecol[x], spryscale, sprtopscreen, sprflipvert, mfloorclip, mceilingclip); + columndrawerargs.DrawMaskedColumn(Thread, x, iscale, tex, maskedtexturecol[x], spryscale, sprtopscreen, sprflipvert, mfloorclip, mceilingclip, renderstyle); rw_light += rw_lightstep; spryscale += rw_scalestep; diff --git a/src/swrenderer/line/r_walldraw.cpp b/src/swrenderer/line/r_walldraw.cpp index ac277a0aee..0b9c9131d9 100644 --- a/src/swrenderer/line/r_walldraw.cpp +++ b/src/swrenderer/line/r_walldraw.cpp @@ -97,7 +97,7 @@ namespace swrenderer col = width + (col % width); } - source = texture->GetColumn(col, nullptr); + source = texture->GetColumn(DefaultRenderStyle(), col, nullptr); source2 = nullptr; texturefracx = 0; } @@ -530,7 +530,7 @@ namespace swrenderer this->rw_pic = pic; this->mask = mask; - Thread->PrepareTexture(pic); + Thread->PrepareTexture(pic, DefaultRenderStyle()); // Get correct render style? Shaded won't get here. if (rw_pic->GetHeight() != 1 << rw_pic->HeightBits) { diff --git a/src/swrenderer/plane/r_skyplane.cpp b/src/swrenderer/plane/r_skyplane.cpp index ef7a6b898b..e95abbd463 100644 --- a/src/swrenderer/plane/r_skyplane.cpp +++ b/src/swrenderer/plane/r_skyplane.cpp @@ -172,8 +172,8 @@ namespace swrenderer drawerargs.SetLight(&NormalLight, 0, 0); } - Thread->PrepareTexture(frontskytex); - Thread->PrepareTexture(backskytex); + Thread->PrepareTexture(frontskytex, DefaultRenderStyle()); + Thread->PrepareTexture(backskytex, DefaultRenderStyle()); DrawSky(pl); } diff --git a/src/swrenderer/r_renderthread.cpp b/src/swrenderer/r_renderthread.cpp index bb2816a948..986879618a 100644 --- a/src/swrenderer/r_renderthread.cpp +++ b/src/swrenderer/r_renderthread.cpp @@ -89,7 +89,7 @@ namespace swrenderer return pal_drawers.get(); } - void RenderThread::PrepareTexture(FTexture *texture) + void RenderThread::PrepareTexture(FTexture *texture, FRenderStyle style) { if (texture == nullptr) return; @@ -106,9 +106,9 @@ namespace swrenderer std::unique_lock lock(loadmutex); - texture->GetPixels(); + texture->GetPixels(style); const FTexture::Span *spans; - texture->GetColumn(0, &spans); + texture->GetColumn(style, 0, &spans); if (Viewport->RenderTarget->IsBgra()) { texture->GetPixelsBgra(); diff --git a/src/swrenderer/r_renderthread.h b/src/swrenderer/r_renderthread.h index 3e559155bf..34beab6ae3 100644 --- a/src/swrenderer/r_renderthread.h +++ b/src/swrenderer/r_renderthread.h @@ -84,7 +84,7 @@ namespace swrenderer SWPixelFormatDrawers *Drawers(RenderViewport *viewport); // Make sure texture can accessed safely - void PrepareTexture(FTexture *texture); + void PrepareTexture(FTexture *texture, FRenderStyle style); // Setup poly object in a threadsafe manner void PreparePolyObject(subsector_t *sub); diff --git a/src/swrenderer/r_swcanvas.cpp b/src/swrenderer/r_swcanvas.cpp index 0330d4d6eb..5522d89dcd 100644 --- a/src/swrenderer/r_swcanvas.cpp +++ b/src/swrenderer/r_swcanvas.cpp @@ -196,7 +196,7 @@ void SWCanvas::DrawTexture(DCanvas *canvas, FTexture *img, DrawParms &parms) while (x < x2_i) { - drawerargs.DrawMaskedColumn(&thread, x, iscale, img, frac, spryscale, sprtopscreen, sprflipvert, mfloorclip, mceilingclip, !parms.masked); + drawerargs.DrawMaskedColumn(&thread, x, iscale, img, frac, spryscale, sprtopscreen, sprflipvert, mfloorclip, mceilingclip, parms.style, !parms.masked); x++; frac += xiscale_i; } diff --git a/src/swrenderer/r_swrenderer.cpp b/src/swrenderer/r_swrenderer.cpp index 3c18e62188..c31908a177 100644 --- a/src/swrenderer/r_swrenderer.cpp +++ b/src/swrenderer/r_swrenderer.cpp @@ -105,14 +105,14 @@ void FSoftwareRenderer::PrecacheTexture(FTexture *tex, int cache) if (isbgra) tex->GetColumnBgra(0, &spanp); else - tex->GetColumn(0, &spanp); + tex->GetColumn(DefaultRenderStyle(), 0, &spanp); } else if (cache != 0) { if (isbgra) tex->GetPixelsBgra(); else - tex->GetPixels (); + tex->GetPixels (DefaultRenderStyle()); } else { @@ -282,7 +282,7 @@ void FSoftwareRenderer::RenderTextureView (FCanvasTexture *tex, AActor *viewpoin cameraViewpoint = r_viewpoint; cameraViewwindow = r_viewwindow; - uint8_t *Pixels = renderTarget->IsBgra() ? (uint8_t*)tex->GetPixelsBgra() : (uint8_t*)tex->GetPixels(); + uint8_t *Pixels = renderTarget->IsBgra() ? (uint8_t*)tex->GetPixelsBgra() : (uint8_t*)tex->GetPixels(DefaultRenderStyle()); DSimpleCanvas *Canvas = renderTarget->IsBgra() ? tex->GetCanvasBgra() : tex->GetCanvas(); // curse Doom's overuse of global variables in the renderer. @@ -328,7 +328,7 @@ void FSoftwareRenderer::RenderTextureView (FCanvasTexture *tex, AActor *viewpoin // We need to make sure that both pixel buffers contain data: int width = tex->GetWidth(); int height = tex->GetHeight(); - uint8_t *palbuffer = (uint8_t *)tex->GetPixels(); + uint8_t *palbuffer = (uint8_t *)tex->GetPixels(DefaultRenderStyle()); uint32_t *bgrabuffer = (uint32_t*)tex->GetPixelsBgra(); for (int x = 0; x < width; x++) { diff --git a/src/swrenderer/things/r_decal.cpp b/src/swrenderer/things/r_decal.cpp index b1711d9e3b..8361a8061f 100644 --- a/src/swrenderer/things/r_decal.cpp +++ b/src/swrenderer/things/r_decal.cpp @@ -312,14 +312,14 @@ namespace swrenderer if (visible) { - thread->PrepareTexture(WallSpriteTile); + thread->PrepareTexture(WallSpriteTile, decal->RenderStyle); while (x < x2) { if (calclighting) { // calculate lighting drawerargs.SetLight(usecolormap, light, wallshade); } - DrawColumn(thread, drawerargs, x, WallSpriteTile, walltexcoords, texturemid, maskedScaleY, sprflipvert, mfloorclip, mceilingclip); + DrawColumn(thread, drawerargs, x, WallSpriteTile, walltexcoords, texturemid, maskedScaleY, sprflipvert, mfloorclip, mceilingclip, decal->RenderStyle); light += lightstep; x++; } @@ -333,7 +333,7 @@ namespace swrenderer } while (needrepeat--); } - void RenderDecal::DrawColumn(RenderThread *thread, SpriteDrawerArgs &drawerargs, int x, FTexture *WallSpriteTile, const ProjectedWallTexcoords &walltexcoords, double texturemid, float maskedScaleY, bool sprflipvert, const short *mfloorclip, const short *mceilingclip) + void RenderDecal::DrawColumn(RenderThread *thread, SpriteDrawerArgs &drawerargs, int x, FTexture *WallSpriteTile, const ProjectedWallTexcoords &walltexcoords, double texturemid, float maskedScaleY, bool sprflipvert, const short *mfloorclip, const short *mceilingclip, FRenderStyle style) { auto viewport = thread->Viewport.get(); @@ -345,6 +345,6 @@ namespace swrenderer else sprtopscreen = viewport->CenterY - texturemid * spryscale; - drawerargs.DrawMaskedColumn(thread, x, FLOAT2FIXED(iscale), WallSpriteTile, walltexcoords.UPos[x], spryscale, sprtopscreen, sprflipvert, mfloorclip, mceilingclip); + drawerargs.DrawMaskedColumn(thread, x, FLOAT2FIXED(iscale), WallSpriteTile, walltexcoords.UPos[x], spryscale, sprtopscreen, sprflipvert, mfloorclip, mceilingclip, style); } } diff --git a/src/swrenderer/things/r_decal.h b/src/swrenderer/things/r_decal.h index 712e829003..e617b04a6a 100644 --- a/src/swrenderer/things/r_decal.h +++ b/src/swrenderer/things/r_decal.h @@ -16,6 +16,6 @@ namespace swrenderer private: static void Render(RenderThread *thread, side_t *wall, DBaseDecal *first, DrawSegment *clipper, int wallshade, float lightleft, float lightstep, seg_t *curline, const FWallCoords &wallC, bool foggy, FDynamicColormap *basecolormap, const short *walltop, const short *wallbottom, bool drawsegPass); - static void DrawColumn(RenderThread *thread, SpriteDrawerArgs &drawerargs, int x, FTexture *WallSpriteTile, const ProjectedWallTexcoords &walltexcoords, double texturemid, float maskedScaleY, bool sprflipvert, const short *mfloorclip, const short *mceilingclip); + static void DrawColumn(RenderThread *thread, SpriteDrawerArgs &drawerargs, int x, FTexture *WallSpriteTile, const ProjectedWallTexcoords &walltexcoords, double texturemid, float maskedScaleY, bool sprflipvert, const short *mfloorclip, const short *mceilingclip, FRenderStyle style); }; } diff --git a/src/swrenderer/things/r_model.cpp b/src/swrenderer/things/r_model.cpp index 4b68db2194..b6f5fe0c77 100644 --- a/src/swrenderer/things/r_model.cpp +++ b/src/swrenderer/things/r_model.cpp @@ -199,7 +199,7 @@ namespace swrenderer if (Thread->Viewport->RenderTarget->IsBgra()) args.SetTexture((const uint8_t *)SkinTexture->GetPixelsBgra(), SkinTexture->GetWidth(), SkinTexture->GetHeight()); else - args.SetTexture(SkinTexture->GetPixels(), SkinTexture->GetWidth(), SkinTexture->GetHeight()); + args.SetTexture(SkinTexture->GetPixels(DefaultRenderStyle()), SkinTexture->GetWidth(), SkinTexture->GetHeight()); args.SetDepthTest(true); args.SetWriteDepth(true); @@ -237,7 +237,7 @@ namespace swrenderer if (Thread->Viewport->RenderTarget->IsBgra()) args.SetTexture((const uint8_t *)SkinTexture->GetPixelsBgra(), SkinTexture->GetWidth(), SkinTexture->GetHeight()); else - args.SetTexture(SkinTexture->GetPixels(), SkinTexture->GetWidth(), SkinTexture->GetHeight()); + args.SetTexture(SkinTexture->GetPixels(DefaultRenderStyle()), SkinTexture->GetWidth(), SkinTexture->GetHeight()); args.SetDepthTest(true); args.SetWriteDepth(true); diff --git a/src/swrenderer/things/r_playersprite.cpp b/src/swrenderer/things/r_playersprite.cpp index 41ec47239f..924c7a7d82 100644 --- a/src/swrenderer/things/r_playersprite.cpp +++ b/src/swrenderer/things/r_playersprite.cpp @@ -545,10 +545,10 @@ namespace swrenderer short *mceilingclip = zeroarray; fixed_t frac = startfrac; - thread->PrepareTexture(pic); + thread->PrepareTexture(pic, RenderStyle); for (int x = x1; x < x2; x++) { - drawerargs.DrawMaskedColumn(thread, x, iscale, pic, frac + xiscale / 2, spryscale, sprtopscreen, sprflipvert, mfloorclip, mceilingclip, false); + drawerargs.DrawMaskedColumn(thread, x, iscale, pic, frac + xiscale / 2, spryscale, sprtopscreen, sprflipvert, mfloorclip, mceilingclip, RenderStyle, false); frac += xiscale; } diff --git a/src/swrenderer/things/r_sprite.cpp b/src/swrenderer/things/r_sprite.cpp index 74a76a79f8..be26ad7c2e 100644 --- a/src/swrenderer/things/r_sprite.cpp +++ b/src/swrenderer/things/r_sprite.cpp @@ -361,11 +361,11 @@ namespace swrenderer { RenderTranslucentPass *translucentPass = thread->TranslucentPass.get(); - thread->PrepareTexture(tex); + thread->PrepareTexture(tex, vis->RenderStyle); while (x < x2) { if (!translucentPass->ClipSpriteColumnWithPortals(x, vis)) - drawerargs.DrawMaskedColumn(thread, x, iscale, tex, frac, spryscale, sprtopscreen, sprflipvert, mfloorclip, mceilingclip, false); + drawerargs.DrawMaskedColumn(thread, x, iscale, tex, frac, spryscale, sprtopscreen, sprflipvert, mfloorclip, mceilingclip, vis->RenderStyle, false); x++; frac += xiscale; } diff --git a/src/swrenderer/things/r_wallsprite.cpp b/src/swrenderer/things/r_wallsprite.cpp index be4c4195eb..f44d88e2a5 100644 --- a/src/swrenderer/things/r_wallsprite.cpp +++ b/src/swrenderer/things/r_wallsprite.cpp @@ -239,7 +239,7 @@ namespace swrenderer { RenderTranslucentPass *translucentPass = thread->TranslucentPass.get(); - thread->PrepareTexture(WallSpriteTile); + thread->PrepareTexture(WallSpriteTile, spr->RenderStyle); while (x < x2) { if (calclighting) @@ -247,14 +247,14 @@ namespace swrenderer drawerargs.SetLight(usecolormap, light, shade); } if (!translucentPass->ClipSpriteColumnWithPortals(x, spr)) - DrawColumn(thread, drawerargs, x, WallSpriteTile, walltexcoords, texturemid, maskedScaleY, sprflipvert, mfloorclip, mceilingclip); + DrawColumn(thread, drawerargs, x, WallSpriteTile, walltexcoords, texturemid, maskedScaleY, sprflipvert, mfloorclip, mceilingclip, spr->RenderStyle); light += lightstep; x++; } } } - void RenderWallSprite::DrawColumn(RenderThread *thread, SpriteDrawerArgs &drawerargs, int x, FTexture *WallSpriteTile, const ProjectedWallTexcoords &walltexcoords, double texturemid, float maskedScaleY, bool sprflipvert, const short *mfloorclip, const short *mceilingclip) + void RenderWallSprite::DrawColumn(RenderThread *thread, SpriteDrawerArgs &drawerargs, int x, FTexture *WallSpriteTile, const ProjectedWallTexcoords &walltexcoords, double texturemid, float maskedScaleY, bool sprflipvert, const short *mfloorclip, const short *mceilingclip, FRenderStyle style) { auto viewport = thread->Viewport.get(); @@ -266,6 +266,6 @@ namespace swrenderer else sprtopscreen = viewport->CenterY - texturemid * spryscale; - drawerargs.DrawMaskedColumn(thread, x, FLOAT2FIXED(iscale), WallSpriteTile, walltexcoords.UPos[x], spryscale, sprtopscreen, sprflipvert, mfloorclip, mceilingclip); + drawerargs.DrawMaskedColumn(thread, x, FLOAT2FIXED(iscale), WallSpriteTile, walltexcoords.UPos[x], spryscale, sprtopscreen, sprflipvert, mfloorclip, mceilingclip, style); } } diff --git a/src/swrenderer/things/r_wallsprite.h b/src/swrenderer/things/r_wallsprite.h index c248c6c8c8..fa127ccf45 100644 --- a/src/swrenderer/things/r_wallsprite.h +++ b/src/swrenderer/things/r_wallsprite.h @@ -17,7 +17,7 @@ namespace swrenderer void Render(RenderThread *thread, short *cliptop, short *clipbottom, int minZ, int maxZ, Fake3DTranslucent clip3DFloor) override; private: - static void DrawColumn(RenderThread *thread, SpriteDrawerArgs &drawerargs, int x, FTexture *WallSpriteTile, const ProjectedWallTexcoords &walltexcoords, double texturemid, float maskedScaleY, bool sprflipvert, const short *mfloorclip, const short *mceilingclip); + static void DrawColumn(RenderThread *thread, SpriteDrawerArgs &drawerargs, int x, FTexture *WallSpriteTile, const ProjectedWallTexcoords &walltexcoords, double texturemid, float maskedScaleY, bool sprflipvert, const short *mfloorclip, const short *mceilingclip, FRenderStyle style); FWallCoords wallc; uint32_t Translation = 0; diff --git a/src/swrenderer/viewport/r_skydrawer.cpp b/src/swrenderer/viewport/r_skydrawer.cpp index 16e2d2ab38..c134a46e2b 100644 --- a/src/swrenderer/viewport/r_skydrawer.cpp +++ b/src/swrenderer/viewport/r_skydrawer.cpp @@ -56,7 +56,7 @@ namespace swrenderer } else { - dc_source = texture->GetColumn(column, nullptr); + dc_source = texture->GetColumn(DefaultRenderStyle(), column, nullptr); dc_sourceheight = texture->GetHeight(); } } @@ -75,7 +75,7 @@ namespace swrenderer } else { - dc_source2 = texture->GetColumn(column, nullptr); + dc_source2 = texture->GetColumn(DefaultRenderStyle(), column, nullptr); dc_sourceheight2 = texture->GetHeight(); } } diff --git a/src/swrenderer/viewport/r_spandrawer.cpp b/src/swrenderer/viewport/r_spandrawer.cpp index ffc4dfc5ff..e5adf54094 100644 --- a/src/swrenderer/viewport/r_spandrawer.cpp +++ b/src/swrenderer/viewport/r_spandrawer.cpp @@ -32,7 +32,7 @@ namespace swrenderer void SpanDrawerArgs::SetTexture(RenderThread *thread, FTexture *tex) { - thread->PrepareTexture(tex); + thread->PrepareTexture(tex, DefaultRenderStyle()); ds_texwidth = tex->GetWidth(); ds_texheight = tex->GetHeight(); @@ -47,7 +47,7 @@ namespace swrenderer ds_ybits--; } - ds_source = thread->Viewport->RenderTarget->IsBgra() ? (const uint8_t*)tex->GetPixelsBgra() : tex->GetPixels(); + ds_source = thread->Viewport->RenderTarget->IsBgra() ? (const uint8_t*)tex->GetPixelsBgra() : tex->GetPixels(DefaultRenderStyle()); // Get correct render style? Shaded won't get here. ds_source_mipmapped = tex->Mipmapped() && tex->GetWidth() > 1 && tex->GetHeight() > 1; } diff --git a/src/swrenderer/viewport/r_spritedrawer.cpp b/src/swrenderer/viewport/r_spritedrawer.cpp index 0dbb387166..20abfca51e 100644 --- a/src/swrenderer/viewport/r_spritedrawer.cpp +++ b/src/swrenderer/viewport/r_spritedrawer.cpp @@ -43,7 +43,7 @@ namespace swrenderer colfunc = &SWPixelFormatDrawers::DrawColumn; } - void SpriteDrawerArgs::DrawMaskedColumn(RenderThread *thread, int x, fixed_t iscale, FTexture *tex, fixed_t col, double spryscale, double sprtopscreen, bool sprflipvert, const short *mfloorclip, const short *mceilingclip, bool unmasked) + void SpriteDrawerArgs::DrawMaskedColumn(RenderThread *thread, int x, fixed_t iscale, FTexture *tex, fixed_t col, double spryscale, double sprtopscreen, bool sprflipvert, const short *mfloorclip, const short *mceilingclip, FRenderStyle style, bool unmasked) { if (x < thread->X1 || x >= thread->X2) return; @@ -67,7 +67,7 @@ namespace swrenderer if (viewport->RenderTarget->IsBgra() && !drawer_needs_pal_input) column = (const uint8_t *)tex->GetColumnBgra(col >> FRACBITS, &span); else - column = tex->GetColumn(col >> FRACBITS, &span); + column = tex->GetColumn(style, col >> FRACBITS, &span); FTexture::Span unmaskedSpan[2]; if (unmasked) diff --git a/src/swrenderer/viewport/r_spritedrawer.h b/src/swrenderer/viewport/r_spritedrawer.h index e1df5e926e..f6a3aae79f 100644 --- a/src/swrenderer/viewport/r_spritedrawer.h +++ b/src/swrenderer/viewport/r_spritedrawer.h @@ -33,7 +33,7 @@ namespace swrenderer void SetSolidColor(int color) { dc_color = color; dc_color_bgra = GPalette.BaseColors[color]; } void SetDynamicLight(uint32_t color) { dynlightcolor = color; } - void DrawMaskedColumn(RenderThread *thread, int x, fixed_t iscale, FTexture *texture, fixed_t column, double spryscale, double sprtopscreen, bool sprflipvert, const short *mfloorclip, const short *mceilingclip, bool unmasked = false); + void DrawMaskedColumn(RenderThread *thread, int x, fixed_t iscale, FTexture *texture, fixed_t column, double spryscale, double sprtopscreen, bool sprflipvert, const short *mfloorclip, const short *mceilingclip, FRenderStyle style, bool unmasked = false); void FillColumn(RenderThread *thread); void DrawVoxelBlocks(RenderThread *thread, const VoxelBlock *blocks, int blockcount); diff --git a/src/textures/backdroptexture.cpp b/src/textures/backdroptexture.cpp index 05d3f2541a..9d9049fae1 100644 --- a/src/textures/backdroptexture.cpp +++ b/src/textures/backdroptexture.cpp @@ -77,7 +77,7 @@ class FBackdropTexture : public FWorldTexture public: FBackdropTexture(); - bool CheckModified() override; + bool CheckModified(FRenderStyle style) override; uint8_t *MakeTexture(FRenderStyle style) override; protected: @@ -204,7 +204,7 @@ FBackdropTexture::FBackdropTexture() // //============================================================================= -bool FBackdropTexture::CheckModified() +bool FBackdropTexture::CheckModified(FRenderStyle) { return LastRenderTic != gametic; } diff --git a/src/textures/canvastexture.cpp b/src/textures/canvastexture.cpp index bb6b3d6856..e13dd6d3d3 100644 --- a/src/textures/canvastexture.cpp +++ b/src/textures/canvastexture.cpp @@ -65,12 +65,12 @@ FCanvasTexture::~FCanvasTexture () Unload (); } -const uint8_t *FCanvasTexture::GetColumn(unsigned int column, const Span **spans_out) +const uint8_t *FCanvasTexture::GetColumn(FRenderStyle style, unsigned int column, const Span **spans_out) { bNeedsUpdate = true; if (Canvas == NULL) { - MakeTexture (); + MakeTexture (style); } if ((unsigned)column >= (unsigned)Width) { @@ -90,12 +90,12 @@ const uint8_t *FCanvasTexture::GetColumn(unsigned int column, const Span **spans return Pixels + column*Height; } -const uint8_t *FCanvasTexture::GetPixels () +const uint8_t *FCanvasTexture::GetPixels (FRenderStyle style) { bNeedsUpdate = true; if (Canvas == NULL) { - MakeTexture (); + MakeTexture (style); } return Pixels; } @@ -110,7 +110,7 @@ const uint32_t *FCanvasTexture::GetPixelsBgra() return PixelsBgra; } -void FCanvasTexture::MakeTexture () +void FCanvasTexture::MakeTexture (FRenderStyle) // This ignores the render style because making it work as alpha texture is impractical. { Canvas = new DSimpleCanvas (Width, Height, false); Canvas->Lock (); @@ -183,7 +183,7 @@ void FCanvasTexture::Unload () FTexture::Unload(); } -bool FCanvasTexture::CheckModified () +bool FCanvasTexture::CheckModified (FRenderStyle) { if (bDidUpdate) { diff --git a/src/textures/multipatchtexture.cpp b/src/textures/multipatchtexture.cpp index e2bf932e9f..8571f820be 100644 --- a/src/textures/multipatchtexture.cpp +++ b/src/textures/multipatchtexture.cpp @@ -195,11 +195,17 @@ protected: int NumParts; TexPart *Parts; TexInit *Inits; - bool bRedirect:1; - bool bTranslucentPatches:1; + bool bRedirect; + bool bTranslucentPatches; uint8_t *MakeTexture (FRenderStyle style); + // The getters must optionally redirect if it's a simple one-patch texture. + const uint8_t *GetPixels(FRenderStyle style) override { return bRedirect ? Parts->Texture->GetPixels(style) : FWorldTexture::GetPixels(style); } + const uint8_t *GetColumn(FRenderStyle style, unsigned int col, const Span **out) override + { return bRedirect ? Parts->Texture->GetColumn(style, col, out) : FWorldTexture::GetColumn(style, col, out); } + + private: void CheckForHacks (); void ParsePatch(FScanner &sc, TexPart & part, TexInit &init); diff --git a/src/textures/skyboxtexture.cpp b/src/textures/skyboxtexture.cpp index 7f19e7f855..5270af9374 100644 --- a/src/textures/skyboxtexture.cpp +++ b/src/textures/skyboxtexture.cpp @@ -59,9 +59,9 @@ FSkyBox::~FSkyBox() // //----------------------------------------------------------------------------- -const uint8_t *FSkyBox::GetColumn(unsigned int column, const Span **spans_out) +const uint8_t *FSkyBox::GetColumn(FRenderStyle style, unsigned int column, const Span **spans_out) { - if (faces[0]) return faces[0]->GetColumn(column, spans_out); + if (faces[0]) return faces[0]->GetColumn(style, column, spans_out); return NULL; } @@ -71,9 +71,9 @@ const uint8_t *FSkyBox::GetColumn(unsigned int column, const Span **spans_out) // //----------------------------------------------------------------------------- -const uint8_t *FSkyBox::GetPixels () +const uint8_t *FSkyBox::GetPixels (FRenderStyle style) { - if (faces[0]) return faces[0]->GetPixels(); + if (faces[0]) return faces[0]->GetPixels(style); return NULL; } diff --git a/src/textures/skyboxtexture.h b/src/textures/skyboxtexture.h index 74fc68bbef..a6048ce583 100644 --- a/src/textures/skyboxtexture.h +++ b/src/textures/skyboxtexture.h @@ -17,8 +17,8 @@ public: FSkyBox(); ~FSkyBox(); - const uint8_t *GetColumn(unsigned int column, const Span **spans_out); - const uint8_t *GetPixels (); + const uint8_t *GetColumn(FRenderStyle style, unsigned int column, const Span **spans_out); + const uint8_t *GetPixels (FRenderStyle style); int CopyTrueColorPixels(FBitmap *bmp, int x, int y, int rotate, FCopyInfo *inf); bool UseBasePalette(); void Unload (); diff --git a/src/textures/texture.cpp b/src/textures/texture.cpp index c81b691c42..2b6ec321c7 100644 --- a/src/textures/texture.cpp +++ b/src/textures/texture.cpp @@ -183,19 +183,20 @@ void FTexture::Unload() const uint32_t *FTexture::GetColumnBgra(unsigned int column, const Span **spans_out) { const uint32_t *pixels = GetPixelsBgra(); + if (pixels == nullptr) return nullptr; column %= Width; if (spans_out != nullptr) - GetColumn(column, spans_out); + GetColumn(DefaultRenderStyle(), column, spans_out); // This isn't the right way to create the spans. return pixels + column * Height; } const uint32_t *FTexture::GetPixelsBgra() { - if (PixelsBgra.empty() || CheckModified()) + if (PixelsBgra.empty() || CheckModified(DefaultRenderStyle())) { - if (!GetColumn(0, nullptr)) + if (!GetColumn(DefaultRenderStyle(), 0, nullptr)) return nullptr; FBitmap bitmap; @@ -206,7 +207,7 @@ const uint32_t *FTexture::GetPixelsBgra() return PixelsBgra.data(); } -bool FTexture::CheckModified () +bool FTexture::CheckModified (FRenderStyle) { return false; } @@ -282,6 +283,7 @@ FTexture::Span **FTexture::CreateSpans (const uint8_t *pixels) const newspan = true; for (y = numrows; y > 0; --y) { + if (*data_p++ == 0) { if (!newspan) @@ -552,7 +554,7 @@ void FTexture::GenerateBgraMipmapsFast() void FTexture::CopyToBlock (uint8_t *dest, int dwidth, int dheight, int xpos, int ypos, int rotate, const uint8_t *translation, FRenderStyle style) { - const uint8_t *pixels = GetPixels(/*style*/); + const uint8_t *pixels = GetPixels(style); int srcwidth = Width; int srcheight = Height; int step_x = Height; @@ -720,7 +722,7 @@ FNativeTexture *FTexture::GetNative(bool wrapping) } else { - if (CheckModified()) + if (CheckModified(DefaultRenderStyle())) { Native->Update(); } @@ -740,12 +742,6 @@ void FTexture::KillNative() } } -// For this generic implementation, we just call GetPixels and copy that data -// to the buffer. Texture formats that can do better than paletted images -// should provide their own implementation that may preserve the original -// color data. Note that the buffer expects row-major data, since that's -// generally more convenient for any non-Doom image formats, and it doesn't -// need to be used by any of Doom's column drawing routines. void FTexture::FillBuffer(uint8_t *buff, int pitch, int height, FTextureFormat fmt) { const uint8_t *pix; @@ -758,7 +754,7 @@ void FTexture::FillBuffer(uint8_t *buff, int pitch, int height, FTextureFormat f { case TEX_Pal: case TEX_Gray: - pix = GetPixels(); + pix = GetPixels(DefaultRenderStyle()); stride = pitch - w; for (y = 0; y < h; ++y) { @@ -802,14 +798,14 @@ int FTexture::CopyTrueColorPixels(FBitmap *bmp, int x, int y, int rotate, FCopyI { PalEntry *palette = screen->GetPalette(); for(int i=1;i<256;i++) palette[i].a = 255; // set proper alpha values - bmp->CopyPixelData(x, y, GetPixels(), Width, Height, Height, 1, rotate, palette, inf); + bmp->CopyPixelData(x, y, GetPixels(DefaultRenderStyle()), Width, Height, Height, 1, rotate, palette, inf); for(int i=1;i<256;i++) palette[i].a = 0; return 0; } int FTexture::CopyTrueColorTranslated(FBitmap *bmp, int x, int y, int rotate, PalEntry *remap, FCopyInfo *inf) { - bmp->CopyPixelData(x, y, GetPixels(), Width, Height, Height, 1, rotate, remap, inf); + bmp->CopyPixelData(x, y, GetPixels(DefaultRenderStyle()), Width, Height, Height, 1, rotate, remap, inf); return 0; } @@ -920,7 +916,7 @@ int FTexture::CheckRealHeight() for (int i = 0; i < GetWidth(); ++i) { - GetColumn(i, &span); + GetColumn(DefaultRenderStyle(), i, &span); while (span->Length != 0) { if (span->TopOffset < miny) @@ -960,8 +956,13 @@ void FDummyTexture::SetSize (int width, int height) CalcBitSize (); } -// This must never be called -uint8_t *FDummyTexture::MakeTexture (FRenderStyle) +// These only get called from the texture precacher which discards the result. +const uint8_t *FDummyTexture::GetColumn(FRenderStyle style, unsigned int column, const Span **spans_out) +{ + return nullptr; +} + +const uint8_t *FDummyTexture::GetPixels(FRenderStyle style) { return nullptr; } @@ -990,7 +991,7 @@ CCMD (printspans) { const FTexture::Span *spans; Printf ("%4d:", x); - tex->GetColumn(x, &spans); + tex->GetColumn(DefaultRenderStyle(), x, &spans); while (spans->Length != 0) { Printf (" (%4d,%4d)", spans->TopOffset, spans->TopOffset+spans->Length-1); diff --git a/src/textures/textures.h b/src/textures/textures.h index 17cef6e1cb..3b517ddf1e 100644 --- a/src/textures/textures.h +++ b/src/textures/textures.h @@ -226,15 +226,15 @@ public: }; // Returns a single column of the texture - virtual const uint8_t *GetColumn(unsigned int column, const Span **spans_out) = 0;// delete; - //virtual const uint8_t *GetColumn(FRenderStyle style, unsigned int column, const Span **spans_out) = 0; + virtual const uint8_t *GetColumn(unsigned int column, const Span **spans_out) = delete; + virtual const uint8_t *GetColumn(FRenderStyle style, unsigned int column, const Span **spans_out) = 0; // Returns a single column of the texture, in BGRA8 format virtual const uint32_t *GetColumnBgra(unsigned int column, const Span **spans_out); // Returns the whole texture, stored in column-major order - virtual const uint8_t *GetPixels() = 0;// delete; - //virtual const uint8_t *GetPixels(FRenderStyle style) = 0; + virtual const uint8_t *GetPixels() = delete; + virtual const uint8_t *GetPixels(FRenderStyle style) = 0; // Returns the whole texture, stored in column-major order, in BGRA8 format virtual const uint32_t *GetPixelsBgra(); @@ -285,7 +285,7 @@ public: // Returns true if the next call to GetPixels() will return an image different from the // last call to GetPixels(). This should be considered valid only if a call to CheckModified() // is immediately followed by a call to GetPixels(). - virtual bool CheckModified (); + virtual bool CheckModified (FRenderStyle style); static void InitGrayMap(); @@ -592,52 +592,50 @@ protected: FWorldTexture(const char *name = nullptr, int lumpnum = -1); ~FWorldTexture(); - // These should not be overridden. If that is needed, a class should inherit from something else - const uint8_t *GetColumn(unsigned int column, const Span **spans_out) override final; - const uint8_t *GetPixels() override final; - void Unload() override final; // should be removed after refactoring. + + const uint8_t *GetColumn(FRenderStyle style, unsigned int column, const Span **spans_out) override; + const uint8_t *GetPixels(FRenderStyle style) override; + void Unload() override; virtual void MakeTexture() = delete; virtual uint8_t *MakeTexture(FRenderStyle style) = 0; + void FreeAllSpans(); }; // A texture that doesn't really exist -class FDummyTexture : public FWorldTexture +class FDummyTexture : public FTexture { public: FDummyTexture (); - uint8_t *MakeTexture(FRenderStyle); + const uint8_t *GetColumn(FRenderStyle style, unsigned int column, const Span **spans_out) override; + const uint8_t *GetPixels(FRenderStyle style) override; void SetSize (int width, int height); }; // A texture that returns a wiggly version of another texture. -class FWarpTexture : public FTexture +class FWarpTexture : public FWorldTexture { public: FWarpTexture (FTexture *source, int warptype); ~FWarpTexture (); + void Unload() override; - virtual int CopyTrueColorPixels(FBitmap *bmp, int x, int y, int rotate=0, FCopyInfo *inf = NULL); - const uint8_t *GetColumn(unsigned int column, const Span **spans_out); - const uint8_t *GetPixels (); + virtual int CopyTrueColorPixels(FBitmap *bmp, int x, int y, int rotate=0, FCopyInfo *inf = NULL) override; const uint32_t *GetPixelsBgra() override; - void Unload (); - bool CheckModified (); + bool CheckModified (FRenderStyle) override; float GetSpeed() const { return Speed; } int GetSourceLump() { return SourcePic->GetSourceLump(); } void SetSpeed(float fac) { Speed = fac; } FTexture *GetRedirect(bool wantwarped); - uint64_t GenTime; - uint64_t GenTimeBgra; - float Speed; + uint64_t GenTime[2] = { 0, 0 }; + uint64_t GenTimeBgra = 0; + float Speed = 1.f; int WidthOffsetMultiplier, HeightOffsetMultiplier; // [mxd] protected: FTexture *SourcePic; - uint8_t *Pixels; - Span **Spans; - virtual void MakeTexture (uint64_t time); + uint8_t *MakeTexture (FRenderStyle style) override; int NextPo2 (int v); // [mxd] void SetupMultipliers (int width, int height); // [mxd] }; @@ -652,17 +650,17 @@ public: FCanvasTexture (const char *name, int width, int height); ~FCanvasTexture (); - const uint8_t *GetColumn(unsigned int column, const Span **spans_out); - const uint8_t *GetPixels (); + const uint8_t *GetColumn(FRenderStyle style, unsigned int column, const Span **spans_out); + const uint8_t *GetPixels (FRenderStyle style); const uint32_t *GetPixelsBgra() override; void Unload (); - bool CheckModified (); + bool CheckModified (FRenderStyle) override; void NeedUpdate() { bNeedsUpdate=true; } void SetUpdated() { bNeedsUpdate = false; bDidUpdate = true; bFirstUpdate = false; } DSimpleCanvas *GetCanvas() { return Canvas; } DSimpleCanvas *GetCanvasBgra() { return CanvasBgra; } bool Mipmapped() override { return false; } - void MakeTexture (); + void MakeTexture (FRenderStyle style); void MakeTextureBgra (); protected: diff --git a/src/textures/warptexture.cpp b/src/textures/warptexture.cpp index 41920849d0..d78bc52498 100644 --- a/src/textures/warptexture.cpp +++ b/src/textures/warptexture.cpp @@ -44,7 +44,7 @@ FWarpTexture::FWarpTexture (FTexture *source, int warptype) -: GenTime (0), GenTimeBgra(0), Speed (1.f), SourcePic (source), Pixels (0), Spans (0) + : SourcePic (source) { CopyInfo(source); if (warptype == 2) SetupMultipliers(256, 128); @@ -55,53 +55,25 @@ FWarpTexture::FWarpTexture (FTexture *source, int warptype) FWarpTexture::~FWarpTexture () { Unload (); - if (Spans != NULL) - { - FreeSpans (Spans); - Spans = NULL; - } delete SourcePic; } void FWarpTexture::Unload () { - if (Pixels != NULL) - { - delete[] Pixels; - Pixels = NULL; - } - if (Spans != NULL) - { - FreeSpans (Spans); - Spans = NULL; - } SourcePic->Unload (); - FTexture::Unload(); + FWorldTexture::Unload(); + FreeAllSpans(); } -bool FWarpTexture::CheckModified () +bool FWarpTexture::CheckModified (FRenderStyle style) { - return screen->FrameTime != GenTime; -} - -const uint8_t *FWarpTexture::GetPixels () -{ - uint64_t time = screen->FrameTime; - - if (Pixels == NULL || time != GenTime) - { - MakeTexture (time); - } - return Pixels; + return screen->FrameTime != GenTime[!!(style.Flags & STYLEF_RedIsAlpha)]; } const uint32_t *FWarpTexture::GetPixelsBgra() { - uint64_t time = screen->FrameTime; - if (Pixels == NULL || time != GenTime) - MakeTexture(time); - - if (PixelsBgra.empty() || time != GenTimeBgra) + auto Pixels = GetPixels(DefaultRenderStyle()); + if (PixelsBgra.empty() || GenTime[0] != GenTimeBgra) { CreatePixelsBgraWithMipmaps(); for (int i = 0; i < Width * Height; i++) @@ -112,58 +84,21 @@ const uint32_t *FWarpTexture::GetPixelsBgra() PixelsBgra[i] = 0; } GenerateBgraMipmapsFast(); - GenTimeBgra = time; + GenTimeBgra = GenTime[0]; } return PixelsBgra.data(); } -const uint8_t *FWarpTexture::GetColumn(unsigned int column, const Span **spans_out) + +uint8_t *FWarpTexture::MakeTexture(FRenderStyle style) { - uint64_t time =screen->FrameTime; - - if (Pixels == NULL || time != GenTime) - { - MakeTexture (time); - } - if ((unsigned)column >= (unsigned)Width) - { - if (WidthMask + 1 == Width) - { - column &= WidthMask; - } - else - { - column %= Width; - } - } - if (spans_out != NULL) - { - if (Spans == NULL) - { - Spans = CreateSpans (Pixels); - } - *spans_out = Spans[column]; - } - return Pixels + column*Height; -} - - -void FWarpTexture::MakeTexture(uint64_t time) -{ - const uint8_t *otherpix = SourcePic->GetPixels(); - - if (Pixels == NULL) - { - Pixels = new uint8_t[Width * Height]; - } - if (Spans != NULL) - { - FreeSpans(Spans); - Spans = NULL; - } - - GenTime = time; + uint64_t time = screen->FrameTime; + const uint8_t *otherpix = SourcePic->GetPixels(style); + auto Pixels = new uint8_t[Width * Height]; WarpBuffer(Pixels, otherpix, Width, Height, WidthOffsetMultiplier, HeightOffsetMultiplier, time, Speed, bWarped); + FreeAllSpans(); + GenTime[!!(style.Flags & STYLEF_RedIsAlpha)] = time; + return Pixels; } // [mxd] Non power of 2 textures need different offset multipliers, otherwise warp animation won't sync across texture diff --git a/src/textures/worldtexture.cpp b/src/textures/worldtexture.cpp index 8968902360..db50c7fb4b 100644 --- a/src/textures/worldtexture.cpp +++ b/src/textures/worldtexture.cpp @@ -56,6 +56,17 @@ FWorldTexture::FWorldTexture(const char *name, int lumpnum) FWorldTexture::~FWorldTexture() { Unload(); + FreeAllSpans(); +} + +//========================================================================== +// +// +// +//========================================================================== + +void FWorldTexture::FreeAllSpans() +{ for(int i = 0; i < 2; i++) { if (Spandata[i] != nullptr) @@ -91,9 +102,10 @@ void FWorldTexture::Unload () // //========================================================================== -const uint8_t *FWorldTexture::GetColumn(unsigned int column, const Span **spans_out) +const uint8_t *FWorldTexture::GetColumn(FRenderStyle style, unsigned int column, const Span **spans_out) { - GetPixels(); + int index = !!(style.Flags & STYLEF_RedIsAlpha); + GetPixels(style); if ((unsigned)column >= (unsigned)Width) { if (WidthMask + 1 == Width) @@ -107,13 +119,13 @@ const uint8_t *FWorldTexture::GetColumn(unsigned int column, const Span **spans_ } if (spans_out != nullptr) { - if (Spandata[0] == nullptr) + if (Spandata[index] == nullptr) { - Spandata[0] = CreateSpans (Pixeldata[0]); + Spandata[index] = CreateSpans (Pixeldata[index]); } - *spans_out = Spandata[0][column]; + *spans_out = Spandata[index][column]; } - return Pixeldata[0] + column*Height; + return Pixeldata[index] + column*Height; } //========================================================================== @@ -122,16 +134,17 @@ const uint8_t *FWorldTexture::GetColumn(unsigned int column, const Span **spans_ // //========================================================================== -const uint8_t *FWorldTexture::GetPixels () +const uint8_t *FWorldTexture::GetPixels (FRenderStyle style) { - if (CheckModified()) + if (CheckModified(style)) { Unload(); } - if (Pixeldata[0] == nullptr) + int index = !!(style.Flags & STYLEF_RedIsAlpha); + if (Pixeldata[index] == nullptr) { - Pixeldata[0] = MakeTexture (LegacyRenderStyles[STYLE_Normal]); + Pixeldata[index] = MakeTexture (style); } - return Pixeldata[0]; + return Pixeldata[index]; } diff --git a/src/v_font.cpp b/src/v_font.cpp index 1b36c22191..e38ecfbdee 100644 --- a/src/v_font.cpp +++ b/src/v_font.cpp @@ -177,8 +177,8 @@ class FFontChar1 : public FTexture { public: FFontChar1 (FTexture *sourcelump); - const uint8_t *GetColumn(unsigned int column, const Span **spans_out); - const uint8_t *GetPixels (); + const uint8_t *GetColumn(FRenderStyle style, unsigned int column, const Span **spans_out); + const uint8_t *GetPixels (FRenderStyle style); void SetSourceRemap(const uint8_t *sourceremap); void Unload (); ~FFontChar1 (); @@ -198,8 +198,8 @@ public: FFontChar2 (int sourcelump, int sourcepos, int width, int height, int leftofs=0, int topofs=0); ~FFontChar2 (); - const uint8_t *GetColumn(unsigned int column, const Span **spans_out); - const uint8_t *GetPixels (); + const uint8_t *GetColumn(FRenderStyle style, unsigned int column, const Span **spans_out); + const uint8_t *GetPixels (FRenderStyle style); void SetSourceRemap(const uint8_t *sourceremap); void Unload (); @@ -559,7 +559,7 @@ void RecordTextureColors (FTexture *pic, uint8_t *usedcolors) for (x = pic->GetWidth() - 1; x >= 0; x--) { const FTexture::Span *spans; - const uint8_t *column = pic->GetColumn(x, &spans); + const uint8_t *column = pic->GetColumn(DefaultRenderStyle(), x, &spans); // This shouldn't use the spans... while (spans->Length != 0) { @@ -1649,9 +1649,11 @@ FFontChar1::FFontChar1 (FTexture *sourcelump) // // FFontChar1 :: GetPixels // +// Render style is not relevant for fonts. This must not use it! +// //========================================================================== -const uint8_t *FFontChar1::GetPixels () +const uint8_t *FFontChar1::GetPixels (FRenderStyle) { if (Pixels == NULL) { @@ -1666,12 +1668,12 @@ const uint8_t *FFontChar1::GetPixels () // //========================================================================== -void FFontChar1::MakeTexture () +void FFontChar1::MakeTexture () { // Make the texture as normal, then remap it so that all the colors // are at the low end of the palette Pixels = new uint8_t[Width*Height]; - const uint8_t *pix = BaseTexture->GetPixels(); + const uint8_t *pix = BaseTexture->GetPixels(DefaultRenderStyle()); if (!SourceRemap) { @@ -1692,14 +1694,14 @@ void FFontChar1::MakeTexture () // //========================================================================== -const uint8_t *FFontChar1::GetColumn(unsigned int column, const Span **spans_out) +const uint8_t *FFontChar1::GetColumn(FRenderStyle, unsigned int column, const Span **spans_out) { if (Pixels == NULL) { MakeTexture (); } - BaseTexture->GetColumn(column, spans_out); + BaseTexture->GetColumn(DefaultRenderStyle(), column, spans_out); return Pixels + column*Height; } @@ -1797,9 +1799,11 @@ void FFontChar2::Unload () // // FFontChar2 :: GetPixels // +// Like for FontChar1, the render style has no relevance here as well. +// //========================================================================== -const uint8_t *FFontChar2::GetPixels () +const uint8_t *FFontChar2::GetPixels (FRenderStyle) { if (Pixels == NULL) { @@ -1814,7 +1818,7 @@ const uint8_t *FFontChar2::GetPixels () // //========================================================================== -const uint8_t *FFontChar2::GetColumn(unsigned int column, const Span **spans_out) +const uint8_t *FFontChar2::GetColumn(FRenderStyle, unsigned int column, const Span **spans_out) { if (Pixels == NULL) { diff --git a/src/v_video.cpp b/src/v_video.cpp index 77f83b285d..5e86b915bc 100644 --- a/src/v_video.cpp +++ b/src/v_video.cpp @@ -135,9 +135,9 @@ class FPaletteTester : public FTexture public: FPaletteTester (); - const uint8_t *GetColumn(unsigned int column, const Span **spans_out); - const uint8_t *GetPixels(); - bool CheckModified(); + const uint8_t *GetColumn(FRenderStyle, unsigned int column, const Span **spans_out) override; + const uint8_t *GetPixels(FRenderStyle); + bool CheckModified(FRenderStyle); void SetTranslation(int num); protected: @@ -983,7 +983,7 @@ FPaletteTester::FPaletteTester() // //========================================================================== -bool FPaletteTester::CheckModified() +bool FPaletteTester::CheckModified(FRenderStyle) { return CurTranslation != WantTranslation; } @@ -1008,7 +1008,7 @@ void FPaletteTester::SetTranslation(int num) // //========================================================================== -const uint8_t *FPaletteTester::GetColumn(unsigned int column, const Span **spans_out) +const uint8_t *FPaletteTester::GetColumn(FRenderStyle, unsigned int column, const Span **spans_out) { if (CurTranslation != WantTranslation) { @@ -1028,7 +1028,7 @@ const uint8_t *FPaletteTester::GetColumn(unsigned int column, const Span **spans // //========================================================================== -const uint8_t *FPaletteTester::GetPixels () +const uint8_t *FPaletteTester::GetPixels (FRenderStyle) { if (CurTranslation != WantTranslation) { From 04b8a12ca46d2f86906bf79d5fdc6f7909fffcb5 Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Mon, 19 Mar 2018 20:02:38 +0100 Subject: [PATCH 74/89] - Build texture work. Currently broken. --- src/resourcefiles/file_zip.cpp | 2 + src/textures/buildtexture.cpp | 238 +++++++++++++++++++------------- src/textures/texturemanager.cpp | 12 +- src/textures/textures.h | 9 +- src/v_palette.cpp | 31 ----- src/w_wad.cpp | 13 ++ src/w_wad.h | 1 + 7 files changed, 163 insertions(+), 143 deletions(-) diff --git a/src/resourcefiles/file_zip.cpp b/src/resourcefiles/file_zip.cpp index bf51cd2a40..b3bfa7a2dc 100644 --- a/src/resourcefiles/file_zip.cpp +++ b/src/resourcefiles/file_zip.cpp @@ -280,6 +280,8 @@ bool FZipFile::Open(bool quiet) } } } + // If it ran through the list without finding anything it should not attempt any path remapping. + if (!foundspeciallump) name0 = ""; dirptr = (char*)directory; lump_p = Lumps; diff --git a/src/textures/buildtexture.cpp b/src/textures/buildtexture.cpp index 7223286675..9984e8a19b 100644 --- a/src/textures/buildtexture.cpp +++ b/src/textures/buildtexture.cpp @@ -39,8 +39,13 @@ #include "templates.h" #include "cmdlib.h" #include "st_start.h" +#include "colormatcher.h" +#include "bitmap.h" #include "textures/textures.h" #include "r_data/sprites.h" +#include "r_data/r_translate.h" +#include "resourcefiles/resourcefile.h" + //========================================================================== // @@ -51,11 +56,15 @@ class FBuildTexture : public FWorldTexture { public: - FBuildTexture (int tilenum, const uint8_t *pixels, int width, int height, int left, int top); - uint8_t *MakeTexture(FRenderStyle style) override { return const_cast(Pixels); } // This is only to make it compile for now and will be changed later. + FBuildTexture (const FString &pathprefix, int tilenum, const uint8_t *pixels, int translation, int width, int height, int left, int top); + uint8_t *MakeTexture(FRenderStyle style) override; + int CopyTrueColorPixels(FBitmap *bmp, int x, int y, int rotate, FCopyInfo *inf = NULL) override; + bool UseBasePalette() override { return false; } + FTextureFormat GetFormat() override { return TEX_RGB; } protected: - const uint8_t *Pixels; + const uint8_t *RawPixels; + int Translation; }; @@ -65,8 +74,8 @@ protected: // //========================================================================== -FBuildTexture::FBuildTexture (int tilenum, const uint8_t *pixels, int width, int height, int left, int top) -: Pixels (pixels) +FBuildTexture::FBuildTexture(const FString &pathprefix, int tilenum, const uint8_t *pixels, int translation, int width, int height, int left, int top) +: RawPixels (pixels), Translation(translation) { PixelsAreStatic = 3; Width = width; @@ -74,8 +83,29 @@ FBuildTexture::FBuildTexture (int tilenum, const uint8_t *pixels, int width, int LeftOffset = left; TopOffset = top; CalcBitSize (); - Name.Format("BTIL%04d", tilenum); - UseType = TEX_Build; + Name.Format("%sBTIL%04d", pathprefix.GetChars(), tilenum); + UseType = TEX_Override; + PixelsAreStatic = 3; // test +} + +uint8_t *FBuildTexture::MakeTexture(FRenderStyle style) +{ + auto Pixels = new uint8_t[Width * Height]; + auto Remap = translationtables[TRANSLATION_Standard][Translation]; + for (int i = 0; i < Width*Height; i++) + { + auto c = RawPixels[i]; + Pixels[i] = c;// (style.Flags & STYLEF_RedIsAlpha) ? Remap->Palette[c].r : Remap->Remap[c]; + } + return (uint8_t*)RawPixels; +} + +int FBuildTexture::CopyTrueColorPixels(FBitmap *bmp, int x, int y, int rotate, FCopyInfo *inf) +{ + auto Remap = translationtables[TRANSLATION_Standard][Translation]->Palette; + bmp->CopyPixelData(x, y, RawPixels, Width, Height, Height, 1, rotate, Remap, inf); + return 0; + } //=========================================================================== @@ -86,15 +116,16 @@ FBuildTexture::FBuildTexture (int tilenum, const uint8_t *pixels, int width, int // //=========================================================================== -void FTextureManager::AddTiles (void *tiles) +void FTextureManager::AddTiles (const FString &pathprefix, const void *tiles, int translation) { + // int numtiles = LittleLong(((uint32_t *)tiles)[1]); // This value is not reliable int tilestart = LittleLong(((uint32_t *)tiles)[2]); int tileend = LittleLong(((uint32_t *)tiles)[3]); const uint16_t *tilesizx = &((const uint16_t *)tiles)[8]; const uint16_t *tilesizy = &tilesizx[tileend - tilestart + 1]; const uint32_t *picanm = (const uint32_t *)&tilesizy[tileend - tilestart + 1]; - uint8_t *tiledata = (uint8_t *)&picanm[tileend - tilestart + 1]; + const uint8_t *tiledata = (const uint8_t *)&picanm[tileend - tilestart + 1]; for (int i = tilestart; i <= tileend; ++i) { @@ -110,15 +141,11 @@ void FTextureManager::AddTiles (void *tiles) if (width <= 0 || height <= 0) continue; - tex = new FBuildTexture (i, tiledata, width, height, xoffs, yoffs); + tex = new FBuildTexture (pathprefix, i, tiledata, translation, width, height, xoffs, yoffs); texnum = AddTexture (tex); - while (size > 0) - { - *tiledata = 255 - *tiledata; - tiledata++; - size--; - } - StartScreen->Progress(); + + // reactivate only if the texture counter works here. + //StartScreen->Progress(); if ((picanm[pic] & 63) && (picanm[pic] & 192)) { @@ -192,7 +219,7 @@ void FTextureManager::AddTiles (void *tiles) // //=========================================================================== -int FTextureManager::CountTiles (void *tiles) +static int CountTiles (const void *tiles) { int version = LittleLong(*(uint32_t *)tiles); if (version != 1) @@ -206,6 +233,60 @@ int FTextureManager::CountTiles (void *tiles) return tileend >= tilestart ? tileend - tilestart + 1 : 0; } +//=========================================================================== +// +// Create palette data and remap table for the tile set's palette +// +//=========================================================================== + +static int BuildPaletteTranslation(int lump) +{ + if (Wads.LumpLength(lump) < 768) + { + return false; + } + + FMemLump data = Wads.ReadLump(lump); + const uint8_t *ipal = (const uint8_t *)data.GetMem(); + FRemapTable opal; + + bool blood = false; + for (int c = 0; c < 765; c++) // Build used VGA palettes (color values 0..63), Blood used full palettes (0..255) Let's hope this doesn't screw up... + { + if (ipal[c] >= 64) + { + blood = true; + break; + } + } + + for (int c = 0; c < 255; c++) + { + int r, g, b; + if (!blood) + { + r = (ipal[3*c ] << 2) | (ipal[3 * c ] >> 4); + g = (ipal[3*c + 1] << 2) | (ipal[3 * c + 1] >> 4); + b = (ipal[3*c + 2] << 2) | (ipal[3 * c + 2] >> 4); + } + else + { + r = ipal[3 * c] << 2; + g = ipal[3 * c + 1] << 2; + b = ipal[3 * c + 2] << 2; + } + opal.Palette[c] = PalEntry(r, g, b, 255); + opal.Remap[c] = ColorMatcher.Pick(r, g, b); + } + // The last entry is transparent. + opal.Palette[255] = 0; + opal.Remap[255] = 0; + // Store the remap table in the translation manager so that we do not need to keep track of it ourselves. + // Slot 0 for internal translations is a convenient location because normally it only contains a small number of translations. + return GetTranslationType(opal.StoreTranslation(TRANSLATION_Standard)); +} + + //=========================================================================== // // R_CountBuildTiles @@ -215,98 +296,59 @@ int FTextureManager::CountTiles (void *tiles) // //=========================================================================== -int FTextureManager::CountBuildTiles () +void FTextureManager::InitBuildTiles() { - int numartfiles = 0; - char artfile[] = "tilesXXX.art"; int lumpnum; int numtiles; int totaltiles = 0; - lumpnum = Wads.CheckNumForFullName ("blood.pal"); - if (lumpnum >= 0) + // The search rules are as follows: + // - scan the entire lump directory for palette.dat files. + // - if one is found, process the directory for .ART files and add textures for them. + // - once all have been found, process all directories that may contain Build data. + // - the root is not excluded which allows to read this from .GRP files as well. + // - Blood support has been removed because it is not useful for modding to have loose .ART files. + // + // Unfortunately neither the palettes nor the .ART files contain any usable identifying marker + // so this can only go by the file names. + + int numlumps = Wads.GetNumLumps(); + for (int i = 0; i < numlumps; i++) { - // Blood's tiles are external resources. (Why did they do it like that?) - FString rffpath = Wads.GetWadFullName (Wads.GetLumpFile (lumpnum)); - int slashat = rffpath.LastIndexOf ('/'); - if (slashat >= 0) + const char *name = Wads.GetLumpFullName(i); + if (Wads.CheckNumForFullName(name) != i) continue; // This palette is hidden by a later one. Do not process + FString base = ExtractFileBase(name, true); + base.ToLower(); + if (base.Compare("palette.dat") == 0 && Wads.LumpLength(i) >= 768) // must be a valid palette, i.e. at least 256 colors. { - rffpath.Truncate (slashat + 1); - } - else - { - rffpath += '/'; - } + FString path = ExtractFilePath(name); + if (path.IsNotEmpty() && path.Back() != '/') path += '/'; - for (; numartfiles < 1000; numartfiles++) - { - artfile[5] = numartfiles / 100 + '0'; - artfile[6] = numartfiles / 10 % 10 + '0'; - artfile[7] = numartfiles % 10 + '0'; - - FString artpath = rffpath; - artpath += artfile; - - FileReader fr; - - if (!fr.OpenFile(artpath)) + int translation = BuildPaletteTranslation(i); + for (int numartfiles = 0; numartfiles < 1000; numartfiles++) { - break; - } + FStringf artpath("%stiles%03d.art", path.GetChars(), numartfiles); + // only read from the same source as the palette. + // The entire format here is just too volatile to allow liberal mixing. + // An .ART set must be treated as one unit. + lumpnum = Wads.CheckNumForFullName(artpath, Wads.GetLumpFile(i)); + if (lumpnum < 0) + { + break; + } - auto len = fr.GetLength(); - uint8_t *art = new uint8_t[len]; - if (fr.Read (art, len) != len || (numtiles = CountTiles(art)) == 0) - { - delete[] art; - } - else - { - BuildTileFiles.Push (art); - totaltiles += numtiles; + BuildTileData.Reserve(1); + auto &artdata = BuildTileData.Last(); + artdata.Resize(Wads.LumpLength(lumpnum)); + Wads.ReadLump(lumpnum, &artdata[0]); + + if ((numtiles = CountTiles(&artdata[0])) > 0) + { + AddTiles(path, &artdata[0], translation); + totaltiles += numtiles; + } } } } - - for (; numartfiles < 1000; numartfiles++) - { - artfile[5] = numartfiles / 100 + '0'; - artfile[6] = numartfiles / 10 % 10 + '0'; - artfile[7] = numartfiles % 10 + '0'; - lumpnum = Wads.CheckNumForFullName (artfile); - if (lumpnum < 0) - { - break; - } - - uint8_t *art = new uint8_t[Wads.LumpLength (lumpnum)]; - Wads.ReadLump (lumpnum, art); - - if ((numtiles = CountTiles(art)) == 0) - { - delete[] art; - } - else - { - BuildTileFiles.Push (art); - totaltiles += numtiles; - } - } - return totaltiles; } -//=========================================================================== -// -// R_InitBuildTiles -// -// [RH] Support Build tiles! -// -//=========================================================================== - -void FTextureManager::InitBuildTiles () -{ - for (unsigned int i = 0; i < BuildTileFiles.Size(); ++i) - { - AddTiles (BuildTileFiles[i]); - } -} diff --git a/src/textures/texturemanager.cpp b/src/textures/texturemanager.cpp index cdaf17a49f..b16b5bd5ef 100644 --- a/src/textures/texturemanager.cpp +++ b/src/textures/texturemanager.cpp @@ -137,12 +137,7 @@ void FTextureManager::DeleteAll() } } mAnimatedDoors.Clear(); - - for (unsigned int i = 0; i < BuildTileFiles.Size(); ++i) - { - delete[] BuildTileFiles[i]; - } - BuildTileFiles.Clear(); + BuildTileData.Clear(); } //========================================================================== @@ -982,8 +977,7 @@ void FTextureManager::Init() { DeleteAll(); SpriteFrames.Clear(); - // Init Build Tile data if it hasn't been done already - if (BuildTileFiles.Size() == 0) CountBuildTiles (); + //if (BuildTileFiles.Size() == 0) CountBuildTiles (); FTexture::InitGrayMap(); // Texture 0 is a dummy texture used to indicate "no texture" @@ -1131,7 +1125,7 @@ int FTextureManager::GuesstimateNumTextures () } } - numtex += CountBuildTiles (); + //numtex += CountBuildTiles (); // this cannot be done with a lot of overhead so just leave it out. numtex += CountTexturesX (); return numtex; } diff --git a/src/textures/textures.h b/src/textures/textures.h index 3b517ddf1e..f9aec0b9ba 100644 --- a/src/textures/textures.h +++ b/src/textures/textures.h @@ -207,7 +207,6 @@ public: TEX_Flat, TEX_Sprite, TEX_WallPatch, - TEX_Build, TEX_SkinSprite, TEX_Decal, TEX_MiscPatch, @@ -524,9 +523,8 @@ private: int CountLumpTextures (int lumpnum); // Build tiles - void AddTiles (void *tiles); - int CountTiles (void *tiles); - int CountBuildTiles (); + void AddTiles (const FString &pathprefix, const void *, int translation); + //int CountBuildTiles (); void InitBuildTiles (); // Animation stuff @@ -568,11 +566,12 @@ private: FTextureID DefaultTexture; TArray FirstTextureForFile; TMap PalettedVersions; // maps from normal -> paletted version + TArray > BuildTileData; TArray mAnimations; TArray mSwitchDefs; TArray mAnimatedDoors; - TArray BuildTileFiles; + public: short sintable[2048]; // for texture warping enum diff --git a/src/v_palette.cpp b/src/v_palette.cpp index af4aae4fba..654526a205 100644 --- a/src/v_palette.cpp +++ b/src/v_palette.cpp @@ -340,37 +340,6 @@ void ReadPalette(int lumpnum, uint8_t *buffer) } } -static bool FixBuildPalette (uint8_t *opal, int lump, bool blood) -{ - if (Wads.LumpLength (lump) < 768) - { - return false; - } - - FMemLump data = Wads.ReadLump (lump); - const uint8_t *ipal = (const uint8_t *)data.GetMem(); - - // Reverse the palette because BUILD used entry 255 as - // transparent, but we use 0 as transparent. - - for (int c = 0; c < 768; c += 3) - { - if (!blood) - { - opal[c] = (ipal[765-c] << 2) | (ipal[765-c] >> 4); - opal[c+1] = (ipal[766-c] << 2) | (ipal[766-c] >> 4); - opal[c+2] = (ipal[767-c] << 2) | (ipal[767-c] >> 4); - } - else - { - opal[c] = ipal[765-c]; - opal[c+1] = ipal[766-c]; - opal[c+2] = ipal[767-c]; - } - } - return true; -} - void InitPalette () { uint8_t pal[768]; diff --git a/src/w_wad.cpp b/src/w_wad.cpp index e084d4c749..31e65cd9bc 100644 --- a/src/w_wad.cpp +++ b/src/w_wad.cpp @@ -1255,6 +1255,19 @@ int FWadCollection::GetLumpFile (int lump) const return LumpInfo[lump].wadnum; } +//========================================================================== +// +// W_GetLumpFile +// +//========================================================================== + +FResourceLump *FWadCollection::GetLumpRecord(int lump) const +{ + if ((size_t)lump >= LumpInfo.Size()) + return nullptr; + return LumpInfo[lump].lump; +} + //========================================================================== // // W_ReadLump diff --git a/src/w_wad.h b/src/w_wad.h index 114a37039f..9f33ac2c1c 100644 --- a/src/w_wad.h +++ b/src/w_wad.h @@ -170,6 +170,7 @@ public: int GetLumpFile (int lump) const; // [RH] Returns wadnum for a specified lump int GetLumpNamespace (int lump) const; // [RH] Returns the namespace a lump belongs to int GetLumpIndexNum (int lump) const; // Returns the RFF index number for this lump + FResourceLump *GetLumpRecord(int lump) const; // Returns the FResourceLump, in case the caller wants to have direct access to the lump cache. bool CheckLumpName (int lump, const char *name) const; // [RH] Returns true if the names match bool IsEncryptedFile(int lump) const; From bf2003fe6abf0239e8e306b3b51d257584067ef1 Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Mon, 19 Mar 2018 20:09:32 +0100 Subject: [PATCH 75/89] - fixed pixel address. Colors still need work. --- src/textures/buildtexture.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/textures/buildtexture.cpp b/src/textures/buildtexture.cpp index 9984e8a19b..a78f7fc6ed 100644 --- a/src/textures/buildtexture.cpp +++ b/src/textures/buildtexture.cpp @@ -143,6 +143,7 @@ void FTextureManager::AddTiles (const FString &pathprefix, const void *tiles, in tex = new FBuildTexture (pathprefix, i, tiledata, translation, width, height, xoffs, yoffs); texnum = AddTexture (tex); + tiledata += size; // reactivate only if the texture counter works here. //StartScreen->Progress(); From 16f6a8868016b7a05a9cae63149c01909ed6e515 Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Mon, 19 Mar 2018 20:56:04 +0100 Subject: [PATCH 76/89] - fixed Build tiles and removed test code. --- src/textures/buildtexture.cpp | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/src/textures/buildtexture.cpp b/src/textures/buildtexture.cpp index a78f7fc6ed..27eff0bff4 100644 --- a/src/textures/buildtexture.cpp +++ b/src/textures/buildtexture.cpp @@ -85,24 +85,23 @@ FBuildTexture::FBuildTexture(const FString &pathprefix, int tilenum, const uint8 CalcBitSize (); Name.Format("%sBTIL%04d", pathprefix.GetChars(), tilenum); UseType = TEX_Override; - PixelsAreStatic = 3; // test } uint8_t *FBuildTexture::MakeTexture(FRenderStyle style) { auto Pixels = new uint8_t[Width * Height]; - auto Remap = translationtables[TRANSLATION_Standard][Translation]; + FRemapTable *Remap = translationtables[TRANSLATION_Standard][Translation]; for (int i = 0; i < Width*Height; i++) { auto c = RawPixels[i]; - Pixels[i] = c;// (style.Flags & STYLEF_RedIsAlpha) ? Remap->Palette[c].r : Remap->Remap[c]; + Pixels[i] = (style.Flags & STYLEF_RedIsAlpha) ? Remap->Palette[c].r : Remap->Remap[c]; } return (uint8_t*)RawPixels; } int FBuildTexture::CopyTrueColorPixels(FBitmap *bmp, int x, int y, int rotate, FCopyInfo *inf) { - auto Remap = translationtables[TRANSLATION_Standard][Translation]->Palette; + PalEntry *Remap = translationtables[TRANSLATION_Standard][Translation]->Palette; bmp->CopyPixelData(x, y, RawPixels, Width, Height, Height, 1, rotate, Remap, inf); return 0; @@ -276,7 +275,7 @@ static int BuildPaletteTranslation(int lump) g = ipal[3 * c + 1] << 2; b = ipal[3 * c + 2] << 2; } - opal.Palette[c] = PalEntry(r, g, b, 255); + opal.Palette[c] = PalEntry(255, r, g, b); opal.Remap[c] = ColorMatcher.Pick(r, g, b); } // The last entry is transparent. @@ -284,7 +283,7 @@ static int BuildPaletteTranslation(int lump) opal.Remap[255] = 0; // Store the remap table in the translation manager so that we do not need to keep track of it ourselves. // Slot 0 for internal translations is a convenient location because normally it only contains a small number of translations. - return GetTranslationType(opal.StoreTranslation(TRANSLATION_Standard)); + return GetTranslationIndex(opal.StoreTranslation(TRANSLATION_Standard)); } From cf67883e6a9b3b50c4a133df2f3e1420f819744d Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Mon, 19 Mar 2018 21:01:32 +0100 Subject: [PATCH 77/89] - changed copyright notice. --- src/textures/buildtexture.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/textures/buildtexture.cpp b/src/textures/buildtexture.cpp index 27eff0bff4..96e24af218 100644 --- a/src/textures/buildtexture.cpp +++ b/src/textures/buildtexture.cpp @@ -1,9 +1,10 @@ /* ** buildtexture.cpp -** Handling Build textures +** Handling Build textures (now as a usable editing feature!) ** **--------------------------------------------------------------------------- ** Copyright 2004-2006 Randy Heit +** Copyright 2018 Christoph Oelckers ** All rights reserved. ** ** Redistribution and use in source and binary forms, with or without From 5f4e4d859eaae617d303a5543e1c1181a2ef61d5 Mon Sep 17 00:00:00 2001 From: Magnus Norddahl Date: Tue, 20 Mar 2018 01:28:25 +0100 Subject: [PATCH 78/89] - Fix netgame freeze situation --- src/d_net.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/d_net.cpp b/src/d_net.cpp index 57dbb93b74..9535a43426 100644 --- a/src/d_net.cpp +++ b/src/d_net.cpp @@ -1914,6 +1914,10 @@ void TryRunTics (void) // Check possible stall conditions Net_CheckLastReceived (counts); + // Update time returned by I_GetTime, but only if we are stuck in this loop + if (lowtic >= gametic + counts) + I_SetFrameTime(); + // don't stay in here forever -- give the menu a chance to work if (I_GetTime () - entertic >= 1) { From 09c0bed74fe38653c7e7c59606a2ee09d39e161a Mon Sep 17 00:00:00 2001 From: Magnus Norddahl Date: Tue, 20 Mar 2018 01:29:43 +0100 Subject: [PATCH 79/89] - Oops, last commit had its check inverted --- src/d_net.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/d_net.cpp b/src/d_net.cpp index 9535a43426..7681626d0e 100644 --- a/src/d_net.cpp +++ b/src/d_net.cpp @@ -1915,7 +1915,7 @@ void TryRunTics (void) Net_CheckLastReceived (counts); // Update time returned by I_GetTime, but only if we are stuck in this loop - if (lowtic >= gametic + counts) + if (lowtic < gametic + counts) I_SetFrameTime(); // don't stay in here forever -- give the menu a chance to work From 6f68b6c3520f66ae0a54346c6f357a5f53dedec0 Mon Sep 17 00:00:00 2001 From: "alexey.lysiuk" Date: Tue, 20 Mar 2018 10:29:28 +0200 Subject: [PATCH 80/89] Fixed JPEG errors reporting GCC/Clang reported these warnings: src/textures/jpegtexture.cpp:305:29: warning: data argument not used by format string [-Wformat-extra-args] src/textures/jpegtexture.cpp:388:28: warning: data argument not used by format string [-Wformat-extra-args] src/textures/jpegtexture.cpp:432:29: warning: data argument not used by format string [-Wformat-extra-args] src/textures/jpegtexture.cpp:481:28: warning: data argument not used by format string [-Wformat-extra-args] --- src/textures/jpegtexture.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/textures/jpegtexture.cpp b/src/textures/jpegtexture.cpp index 93aac09ca0..33ecaf1488 100644 --- a/src/textures/jpegtexture.cpp +++ b/src/textures/jpegtexture.cpp @@ -302,7 +302,7 @@ uint8_t *FJPEGTexture::MakeTexture (FRenderStyle style) (cinfo.out_color_space == JCS_YCbCr && cinfo.num_components == 3) || (cinfo.out_color_space == JCS_GRAYSCALE && cinfo.num_components == 1))) { - Printf(TEXTCOLOR_ORANGE, "Unsupported color format in %s\n", Wads.GetLumpFullPath(SourceLump).GetChars()); + Printf(TEXTCOLOR_ORANGE "Unsupported color format in %s\n", Wads.GetLumpFullPath(SourceLump).GetChars()); } else { @@ -385,7 +385,7 @@ uint8_t *FJPEGTexture::MakeTexture (FRenderStyle style) } catch (int) { - Printf(TEXTCOLOR_ORANGE, "JPEG error in %s\n", Wads.GetLumpFullPath(SourceLump).GetChars()); + Printf(TEXTCOLOR_ORANGE "JPEG error in %s\n", Wads.GetLumpFullPath(SourceLump).GetChars()); } jpeg_destroy_decompress(&cinfo); if (buff != NULL) @@ -429,7 +429,7 @@ int FJPEGTexture::CopyTrueColorPixels(FBitmap *bmp, int x, int y, int rotate, FC (cinfo.out_color_space == JCS_YCbCr && cinfo.num_components == 3) || (cinfo.out_color_space == JCS_GRAYSCALE && cinfo.num_components == 1))) { - Printf(TEXTCOLOR_ORANGE, "Unsupported color format in %s\n", Wads.GetLumpFullPath(SourceLump).GetChars()); + Printf(TEXTCOLOR_ORANGE "Unsupported color format in %s\n", Wads.GetLumpFullPath(SourceLump).GetChars()); } else { @@ -478,7 +478,7 @@ int FJPEGTexture::CopyTrueColorPixels(FBitmap *bmp, int x, int y, int rotate, FC } catch (int) { - Printf(TEXTCOLOR_ORANGE, "JPEG error in %s\n", Wads.GetLumpFullPath(SourceLump).GetChars()); + Printf(TEXTCOLOR_ORANGE "JPEG error in %s\n", Wads.GetLumpFullPath(SourceLump).GetChars()); } jpeg_destroy_decompress(&cinfo); if (buff != NULL) delete [] buff; From f242f0631b19e4fbb9991ca07c246a1c12af9615 Mon Sep 17 00:00:00 2001 From: "alexey.lysiuk" Date: Tue, 20 Mar 2018 18:01:35 +0200 Subject: [PATCH 81/89] Fixed crash in when MP3 length guesstimation failed https://forum.zdoom.org/viewtopic.php?t=59881 --- src/sound/musicformats/music_libsndfile.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/sound/musicformats/music_libsndfile.cpp b/src/sound/musicformats/music_libsndfile.cpp index b87492a4eb..3a44d9f56a 100644 --- a/src/sound/musicformats/music_libsndfile.cpp +++ b/src/sound/musicformats/music_libsndfile.cpp @@ -298,8 +298,9 @@ SndFileSong::SndFileSong(FileReader &reader, SoundDecoder *decoder, uint32_t loo if (!startass) loop_start = Scale(loop_start, SampleRate, 1000); if (!endass) loop_end = Scale(loop_end, SampleRate, 1000); + const uint32_t sampleLength = (uint32_t)decoder->getSampleLength(); Loop_Start = loop_start; - Loop_End = clamp(loop_end, 0, (uint32_t)decoder->getSampleLength()); + Loop_End = sampleLength == 0 ? loop_end : clamp(loop_end, 0, sampleLength); Reader = std::move(reader); Decoder = decoder; Channels = iChannels == ChannelConfig_Stereo? 2:1; From b0c96ac43d5867bb35373af4a62de21cf4a5dd93 Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Tue, 20 Mar 2018 18:29:54 +0100 Subject: [PATCH 82/89] - fixed uninitialized variables in files.h. --- src/files.h | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/files.h b/src/files.h index 096452269f..89e6a091d0 100644 --- a/src/files.h +++ b/src/files.h @@ -201,56 +201,56 @@ public: uint8_t ReadUInt8() { - uint8_t v; + uint8_t v = 0; Read(&v, 1); return v; } int8_t ReadInt8() { - int8_t v; + int8_t v = 0; Read(&v, 1); return v; } uint16_t ReadUInt16() { - uint16_t v; + uint16_t v = 0; Read(&v, 2); return LittleShort(v); } int16_t ReadInt16() { - uint16_t v; + uint16_t v = 0; Read(&v, 2); return LittleShort(v); } uint32_t ReadUInt32() { - uint32_t v; + uint32_t v = 0; Read(&v, 4); return LittleLong(v); } int32_t ReadInt32() { - uint32_t v; + uint32_t v = 0; Read(&v, 4); return LittleLong(v); } uint32_t ReadUInt32BE() { - uint32_t v; + uint32_t v = 0; Read(&v, 4); return BigLong(v); } int32_t ReadInt32BE() { - uint32_t v; + uint32_t v = 0; Read(&v, 4); return BigLong(v); } From 568d439c242bfac33ed85b84ee073da91621fb7a Mon Sep 17 00:00:00 2001 From: "alexey.lysiuk" Date: Tue, 20 Mar 2018 10:13:10 +0200 Subject: [PATCH 83/89] Removed deleted virtual functions This solves linking errors on macOS with missing ___cxa_deleted_virtual symbol --- src/textures/textures.h | 3 --- 1 file changed, 3 deletions(-) diff --git a/src/textures/textures.h b/src/textures/textures.h index f9aec0b9ba..52fd089c84 100644 --- a/src/textures/textures.h +++ b/src/textures/textures.h @@ -225,14 +225,12 @@ public: }; // Returns a single column of the texture - virtual const uint8_t *GetColumn(unsigned int column, const Span **spans_out) = delete; virtual const uint8_t *GetColumn(FRenderStyle style, unsigned int column, const Span **spans_out) = 0; // Returns a single column of the texture, in BGRA8 format virtual const uint32_t *GetColumnBgra(unsigned int column, const Span **spans_out); // Returns the whole texture, stored in column-major order - virtual const uint8_t *GetPixels() = delete; virtual const uint8_t *GetPixels(FRenderStyle style) = 0; // Returns the whole texture, stored in column-major order, in BGRA8 format @@ -595,7 +593,6 @@ protected: const uint8_t *GetColumn(FRenderStyle style, unsigned int column, const Span **spans_out) override; const uint8_t *GetPixels(FRenderStyle style) override; void Unload() override; - virtual void MakeTexture() = delete; virtual uint8_t *MakeTexture(FRenderStyle style) = 0; void FreeAllSpans(); }; From 4ad769572f054b7337152359e47606a7b4cf0d73 Mon Sep 17 00:00:00 2001 From: Rachael Alexanderson Date: Tue, 20 Mar 2018 22:02:18 -0400 Subject: [PATCH 84/89] - bump stats version string, send stats to new stats script instead --- src/d_stats.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/d_stats.cpp b/src/d_stats.cpp index bf3855dadc..47c8108c05 100644 --- a/src/d_stats.cpp +++ b/src/d_stats.cpp @@ -35,8 +35,8 @@ CVAR(String, sys_statshost, "gzstats.drdteam.org", CVAR_ARCHIVE|CVAR_GLOBALCONFI CVAR(Int, sys_statsport, 80, CVAR_ARCHIVE|CVAR_GLOBALCONFIG|CVAR_NOSET) // Each machine will only send two reports, one when started with hardware rendering and one when started with software rendering. -#define CHECKVERSION 330 -#define CHECKVERSIONSTR "330" +#define CHECKVERSION 331 +#define CHECKVERSIONSTR "331" CVAR(Int, sentstats_swr_done, 0, CVAR_ARCHIVE | CVAR_GLOBALCONFIG | CVAR_NOSET) CVAR(Int, sentstats_hwr_done, 0, CVAR_ARCHIVE | CVAR_GLOBALCONFIG | CVAR_NOSET) @@ -291,7 +291,7 @@ void D_DoAnonStats() if (currentrenderer == 1 && sentstats_hwr_done >= CHECKVERSION) return; static char requeststring[1024]; - mysnprintf(requeststring, sizeof requeststring, "GET /stats.php?render=%i&cores=%i&os=%i&renderconfig=%i HTTP/1.1\nHost: %s\nConnection: close\nUser-Agent: %s %s\n\n", + mysnprintf(requeststring, sizeof requeststring, "GET /stats.py?render=%i&cores=%i&os=%i&renderconfig=%i HTTP/1.1\nHost: %s\nConnection: close\nUser-Agent: %s %s\n\n", GetRenderInfo(), GetCoreInfo(), GetOSVersion(), currentrenderer, sys_statshost.GetHumanString(), GAMENAME, VERSIONSTR); DPrintf(DMSG_NOTIFY, "Sending %s", requeststring); std::thread t1(D_DoHTTPRequest, requeststring); From fae6f22a2bcc313336b33f2eaa2b3b39e430b40e Mon Sep 17 00:00:00 2001 From: Rachael Alexanderson Date: Wed, 21 Mar 2018 03:50:47 -0400 Subject: [PATCH 85/89] - fix botched merge --- src/d_stats.cpp | 24 ------------------------ 1 file changed, 24 deletions(-) diff --git a/src/d_stats.cpp b/src/d_stats.cpp index dad85837ac..e6c0e196b4 100644 --- a/src/d_stats.cpp +++ b/src/d_stats.cpp @@ -38,7 +38,6 @@ extern int sys_ostype; EXTERN_CVAR(Bool, vid_glswfb) extern int currentrenderer; - CVAR(Int, sys_statsenabled, -1, CVAR_ARCHIVE | CVAR_GLOBALCONFIG | CVAR_NOSET) CVAR(String, sys_statshost, "gzstats.drdteam.org", CVAR_ARCHIVE|CVAR_GLOBALCONFIG|CVAR_NOSET) CVAR(Int, sys_statsport, 80, CVAR_ARCHIVE|CVAR_GLOBALCONFIG|CVAR_NOSET) @@ -359,26 +358,3 @@ void D_ConfirmSendStats() } #endif // NO_SEND_STATS - -void D_ConfirmSendStats() -{ - if (sys_statsenabled >= 0) - { - return; - } - - // TODO: texts - static const char *const MESSAGE_TEXT = "send stats?"; - static const char *const TITLE_TEXT = GAMENAME; - - UCVarValue enabled = { 0 }; - -#ifdef _WIN32 - extern HWND Window; - enabled = { MessageBox(Window, MESSAGE_TEXT, TITLE_TEXT, MB_ICONQUESTION | MB_YESNO) == IDYES }; -#else - // TODO -#endif - - sys_statsenabled.ForceSet(enabled, CVAR_Int); -} From d58169f1b028df0b5dd36b24c14464a155c529d1 Mon Sep 17 00:00:00 2001 From: "alexey.lysiuk" Date: Wed, 21 Mar 2018 12:28:12 +0200 Subject: [PATCH 86/89] Fixed crash with very short music loop https://forum.zdoom.org/viewtopic.php?t=59883 --- src/sound/musicformats/music_libsndfile.cpp | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/src/sound/musicformats/music_libsndfile.cpp b/src/sound/musicformats/music_libsndfile.cpp index 3a44d9f56a..61be6b56c0 100644 --- a/src/sound/musicformats/music_libsndfile.cpp +++ b/src/sound/musicformats/music_libsndfile.cpp @@ -420,12 +420,17 @@ bool SndFileSong::Read(SoundStream *stream, void *vbuff, int ilen, void *userdat // This looks a bit more complicated than necessary because libmpg123 will not read the full requested length for the last block in the file. if (currentpos + framestoread > song->Loop_End) { - size_t endblock = (song->Loop_End - currentpos) * song->Channels * 2; - size_t endlen = song->Decoder->read(buff, endblock); + // Loop can be very short, make sure the current position doesn't exceed it + if (currentpos < song->Loop_End) + { + size_t endblock = (song->Loop_End - currentpos) * song->Channels * 2; + size_t endlen = song->Decoder->read(buff, endblock); + + // Even if zero bytes was read give it a chance to start from the beginning + buff += endlen; + len -= endlen; + } - // Even if zero bytes was read give it a chance to start from the beginning - buff = buff + endlen; - len -= endlen; song->Decoder->seek(song->Loop_Start, false, true); } while (len > 0) From 88bebaec3999335d8d79601c9a0191ebcb450858 Mon Sep 17 00:00:00 2001 From: drfrag Date: Tue, 20 Mar 2018 18:36:00 +0100 Subject: [PATCH 87/89] - Fixed not getting the 'old and unsupported DeHackEd patch' error message for some old patch versions. --- src/d_dehacked.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/d_dehacked.cpp b/src/d_dehacked.cpp index 76bcc19313..75e873648f 100644 --- a/src/d_dehacked.cpp +++ b/src/d_dehacked.cpp @@ -2536,7 +2536,7 @@ static bool DoDehPatch() cont = 0; if (0 == strncmp (PatchFile, "Patch File for DeHackEd v", 25)) { - if (PatchFile[25] < '3' && PatchFile[25] != '2' && PatchFile[27] != '3') + if (PatchFile[25] < '3' && (PatchFile[25] < '2' || PatchFile[27] < '3')) { Printf (PRINT_BOLD, "\"%s\" is an old and unsupported DeHackEd patch\n", PatchName); delete[] PatchName; From 92f10febe86d0bb39de53711c5926a4609848b7e Mon Sep 17 00:00:00 2001 From: "alexey.lysiuk" Date: Wed, 21 Mar 2018 13:03:44 +0200 Subject: [PATCH 88/89] Fixed crash on loading malformed DeHackEd patches Lump that contains only "Patch File for DeHackEd v3.0" (without line break at the end) caused a crash --- src/d_dehacked.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/d_dehacked.cpp b/src/d_dehacked.cpp index 75e873648f..b7587bd2d5 100644 --- a/src/d_dehacked.cpp +++ b/src/d_dehacked.cpp @@ -564,6 +564,8 @@ static void stripwhite (char *str) static char *igets (void) { + assert(PatchPt != nullptr); + char *line; if (*PatchPt == '\0' || PatchPt >= PatchFile + PatchSize ) @@ -2550,7 +2552,7 @@ static bool DoDehPatch() } PatchPt = strchr (PatchFile, '\n'); - while ((cont = GetLine()) == 1) + while (PatchPt != nullptr && (cont = GetLine()) == 1) { CHECKKEY ("Doom version", dversion) else CHECKKEY ("Patch format", pversion) From de0a8152153f2682bb864915557bf77462c90136 Mon Sep 17 00:00:00 2001 From: "alexey.lysiuk" Date: Wed, 21 Mar 2018 13:06:41 +0200 Subject: [PATCH 89/89] Fixed error reporting on loading malformed DeHackEd patches --- src/d_dehacked.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/d_dehacked.cpp b/src/d_dehacked.cpp index b7587bd2d5..a3e2773afb 100644 --- a/src/d_dehacked.cpp +++ b/src/d_dehacked.cpp @@ -2559,9 +2559,9 @@ static bool DoDehPatch() } if (!cont || dversion == -1 || pversion == -1) { + Printf (PRINT_BOLD, "\"%s\" is not a DeHackEd patch file\n", PatchName); delete[] PatchName; delete[] PatchFile; - Printf (PRINT_BOLD, "\"%s\" is not a DeHackEd patch file\n", PatchFile); return false; } }