Merge remote-tracking branch 'remotes/origin/master' into asmjit

This commit is contained in:
Christoph Oelckers 2018-11-30 18:49:28 +01:00
commit 8e46cb3a21
30 changed files with 320 additions and 351 deletions

View file

@ -814,7 +814,8 @@ public:
virtual bool Massacre ();
// Transforms the actor into a finely-ground paste
virtual bool Grind(bool items);
bool Grind(bool items);
bool CallGrind(bool items);
// Get this actor's team
int GetTeam();

View file

@ -173,33 +173,6 @@ void AInventory::MarkPrecacheSounds() const
PickupSound.MarkUsed();
}
//===========================================================================
//
// AInventory :: Grind
//
//===========================================================================
bool AInventory::Grind(bool items)
{
// Does this grind request even care about items?
if (!items)
{
return false;
}
// Dropped items are normally destroyed by crushers. Set the DONTGIB flag,
// and they'll act like corpses with it set and be immune to crushers.
if (flags & MF_DROPPED)
{
if (!(flags3 & MF3_DONTGIB))
{
Destroy();
}
return false;
}
// Non-dropped items call the super method for compatibility.
return Super::Grind(items);
}
//===========================================================================
//
// AInventory :: BecomeItem

View file

@ -76,7 +76,6 @@ public:
virtual void OnDestroy() override;
virtual void Tick() override;
virtual bool Massacre() override;
virtual bool Grind(bool items) override;
bool CallTryPickup(AActor *toucher, AActor **toucher_return = NULL); // Wrapper for script function.

View file

@ -52,29 +52,6 @@ static void CollectExtensions()
int max = 0;
glGetIntegerv(GL_NUM_EXTENSIONS, &max);
if (max == 0)
{
// Try old method to collect extensions
const char *supported = (char *)glGetString(GL_EXTENSIONS);
if (nullptr != supported)
{
char *extensions = new char[strlen(supported) + 1];
strcpy(extensions, supported);
char *extension = strtok(extensions, " ");
while (extension)
{
m_Extensions.Push(FString(extension));
extension = strtok(nullptr, " ");
}
delete [] extensions;
}
}
else
{
// Use modern method to collect extensions
for (int i = 0; i < max; i++)
{
@ -82,7 +59,6 @@ static void CollectExtensions()
m_Extensions.Push(FString(extension));
}
}
}
//==========================================================================
//

View file

@ -6485,7 +6485,7 @@ void P_FindBelowIntersectors(AActor *actor)
void P_DoCrunch(AActor *thing, FChangePosition *cpos)
{
if (!(thing && thing->Grind(true) && cpos)) return;
if (!(thing && thing->CallGrind(true) && cpos)) return;
cpos->nofit = true;
if ((cpos->crushchange > 0) && !(level.maptime & 3))

View file

@ -1903,6 +1903,26 @@ bool AActor::Grind(bool items)
return true;
}
DEFINE_ACTION_FUNCTION(AActor, Grind)
{
PARAM_SELF_PROLOGUE(AActor);
PARAM_BOOL(items);
ACTION_RETURN_BOOL(self->Grind(items));
}
bool AActor::CallGrind(bool items)
{
IFVIRTUAL(AActor, Grind)
{
VMValue params[] = { (DObject*)this, items };
int retv;
VMReturn ret(&retv);
VMCall(func, params, 2, &ret, 1);
return !!retv;
}
return Grind(items);
}
//============================================================================
//
// AActor :: Massacre

View file

@ -869,7 +869,7 @@ void FPolyObj::ThrustMobj (AActor *actor, side_t *side)
P_TraceBleed (newdam > 0 ? newdam : crush, actor);
}
}
if (level.flags2 & LEVEL2_POLYGRIND) actor->Grind(false); // crush corpses that get caught in a polyobject's way
if (level.flags2 & LEVEL2_POLYGRIND) actor->CallGrind(false); // crush corpses that get caught in a polyobject's way
}
//==========================================================================

View file

@ -331,7 +331,7 @@ void ScreenTriangle::Draw(const TriDrawTriangleArgs *args, PolyTriangleThreadDat
if (x > xstart)
{
if (writeColor)
drawfunc(y, xstart, x, args);
drawfunc(y, xstart, x, args, thread);
if (writeStencil)
{
@ -528,7 +528,7 @@ void StepSpan(int y, int x0, int x1, const TriDrawTriangleArgs *args, PolyTriang
for (int x = x0; x < x1; x += 4)
{
__m128 rcp_posW = _mm_rcp_ps(mposW);
__m128 rcp_posW = _mm_div_ps(_mm_set1_ps(1.0f), mposW); // precision of _mm_rcp_ps(mposW) is terrible!
if (OptT::Flags & SWOPT_DynLights)
{

View file

@ -36,15 +36,69 @@
void PolyRenderModel(PolyRenderThread *thread, const Mat4f &worldToClip, uint32_t stencilValue, float x, float y, float z, FSpriteModelFrame *smf, AActor *actor)
{
PolyModelRenderer renderer(thread, worldToClip, stencilValue);
renderer.sector = actor->Sector;
renderer.RenderStyle = actor->RenderStyle;
renderer.RenderAlpha = (float)actor->Alpha;
if (!renderer.RenderStyle.IsVisible(renderer.RenderAlpha))
return;
bool foggy = false;
int actualextralight = foggy ? 0 : PolyRenderer::Instance()->Viewpoint.extralight << 4;
bool fullbrightSprite = ((actor->renderflags & RF_FULLBRIGHT) || (actor->flags5 & MF5_BRIGHT));
renderer.lightlevel = fullbrightSprite ? 255 : actor->Sector->lightlevel + actualextralight;
renderer.visibility = PolyRenderer::Instance()->Light.SpriteGlobVis(foggy);
renderer.fillcolor = actor->fillcolor;
renderer.Translation = actor->Translation;
renderer.AddLights(actor);
renderer.RenderModel(x, y, z, smf, actor, r_viewpoint.TicFrac);
PolyTriangleDrawer::SetModelVertexShader(thread->DrawQueue, -1, -1, 0.0f);
PolyTriangleDrawer::SetTransform(thread->DrawQueue, thread->FrameMemory->NewObject<Mat4f>(worldToClip), nullptr);
}
static bool isBright(DPSprite *psp)
{
if (psp != nullptr && psp->GetState() != nullptr)
{
bool disablefullbright = false;
FTextureID lump = sprites[psp->GetSprite()].GetSpriteFrame(psp->GetFrame(), 0, 0., nullptr);
if (lump.isValid())
{
FTexture * tex = TexMan(lump);
if (tex) disablefullbright = tex->bDisableFullbright;
}
return psp->GetState()->GetFullbright() && !disablefullbright;
}
return false;
}
void PolyRenderHUDModel(PolyRenderThread *thread, const Mat4f &worldToClip, uint32_t stencilValue, DPSprite *psp, float ofsx, float ofsy)
{
PolyModelRenderer renderer(thread, worldToClip, stencilValue);
AActor *playermo = players[consoleplayer].camera;
auto rs = psp->GetRenderStyle(playermo->RenderStyle, playermo->Alpha);
renderer.sector = playermo->Sector;
renderer.RenderStyle = rs.first;
renderer.RenderAlpha = rs.second;
if (psp->Flags & PSPF_FORCEALPHA) renderer.RenderAlpha = 0.0f;
if (!renderer.RenderStyle.IsVisible(renderer.RenderAlpha))
return;
bool foggy = false;
int actualextralight = foggy ? 0 : PolyRenderer::Instance()->Viewpoint.extralight << 4;
bool fullbrightSprite = isBright(psp);
renderer.lightlevel = fullbrightSprite ? 255 : playermo->Sector->lightlevel + actualextralight;
renderer.visibility = PolyRenderer::Instance()->Light.SpriteGlobVis(foggy);
PalEntry ThingColor = (playermo->RenderStyle.Flags & STYLEF_ColorIsFixed) ? playermo->fillcolor : 0xffffff;
ThingColor.a = 255;
renderer.fillcolor = fullbrightSprite ? ThingColor : ThingColor.Modulate(playermo->Sector->SpecialColors[sector_t::sprites]);
renderer.Translation = 0xffffffff;// playermo->Translation;
renderer.RenderHUDModel(psp, ofsx, ofsy);
PolyTriangleDrawer::SetModelVertexShader(thread->DrawQueue, -1, -1, 0.0f);
}
@ -121,7 +175,6 @@ void PolyModelRenderer::AddLights(AActor *actor)
void PolyModelRenderer::BeginDrawModel(AActor *actor, FSpriteModelFrame *smf, const VSMatrix &objectToWorldMatrix, bool mirrored)
{
ModelActor = actor;
const_cast<VSMatrix &>(objectToWorldMatrix).copy(ObjectToWorld.Matrix);
SetTransform();
@ -135,8 +188,6 @@ void PolyModelRenderer::EndDrawModel(AActor *actor, FSpriteModelFrame *smf)
if (actor->RenderStyle == LegacyRenderStyles[STYLE_Normal] || !!(smf->flags & MDL_DONTCULLBACKFACES))
PolyTriangleDrawer::SetTwoSided(Thread->DrawQueue, false);
PolyTriangleDrawer::SetCullCCW(Thread->DrawQueue, true);
ModelActor = nullptr;
}
IModelVertexBuffer *PolyModelRenderer::CreateVertexBuffer(bool needindex, bool singleframe)
@ -162,7 +213,6 @@ VSMatrix PolyModelRenderer::GetViewToWorldMatrix()
void PolyModelRenderer::BeginDrawHUDModel(AActor *actor, const VSMatrix &objectToWorldMatrix, bool mirrored)
{
ModelActor = actor;
const_cast<VSMatrix &>(objectToWorldMatrix).copy(ObjectToWorld.Matrix);
SetTransform();
PolyTriangleDrawer::SetWeaponScene(Thread->DrawQueue, true);
@ -174,7 +224,6 @@ void PolyModelRenderer::BeginDrawHUDModel(AActor *actor, const VSMatrix &objectT
void PolyModelRenderer::EndDrawHUDModel(AActor *actor)
{
ModelActor = nullptr;
PolyTriangleDrawer::SetWeaponScene(Thread->DrawQueue, false);
if (actor->RenderStyle == LegacyRenderStyles[STYLE_Normal])
@ -206,21 +255,12 @@ void PolyModelRenderer::SetTransform()
void PolyModelRenderer::DrawArrays(int start, int count)
{
const auto &viewpoint = PolyRenderer::Instance()->Viewpoint;
bool foggy = false;
int actualextralight = foggy ? 0 : viewpoint.extralight << 4;
sector_t *sector = ModelActor->Sector;
bool fullbrightSprite = ((ModelActor->renderflags & RF_FULLBRIGHT) || (ModelActor->flags5 & MF5_BRIGHT));
int lightlevel = fullbrightSprite ? 255 : ModelActor->Sector->lightlevel + actualextralight;
PolyDrawArgs args;
args.SetLight(GetColorTable(sector->Colormap, sector->SpecialColors[sector_t::sprites], true), lightlevel, PolyRenderer::Instance()->Light.SpriteGlobVis(foggy), fullbrightSprite);
args.SetLight(GetColorTable(sector->Colormap, sector->SpecialColors[sector_t::sprites], true), lightlevel, visibility, fullbrightSprite);
args.SetLights(Lights, NumLights);
args.SetStencilTestValue(StencilValue);
args.SetClipPlane(0, PolyClipPlane());
args.SetStyle(ModelActor->RenderStyle, ModelActor->Alpha, ModelActor->fillcolor, ModelActor->Translation, SkinTexture, fullbrightSprite);
args.SetStyle(RenderStyle, RenderAlpha, fillcolor, Translation, SkinTexture, fullbrightSprite);
args.SetDepthTest(true);
args.SetWriteDepth(true);
args.SetWriteStencil(false);
@ -229,21 +269,12 @@ void PolyModelRenderer::DrawArrays(int start, int count)
void PolyModelRenderer::DrawElements(int numIndices, size_t offset)
{
const auto &viewpoint = PolyRenderer::Instance()->Viewpoint;
bool foggy = false;
int actualextralight = foggy ? 0 : viewpoint.extralight << 4;
sector_t *sector = ModelActor->Sector;
bool fullbrightSprite = ((ModelActor->renderflags & RF_FULLBRIGHT) || (ModelActor->flags5 & MF5_BRIGHT));
int lightlevel = fullbrightSprite ? 255 : ModelActor->Sector->lightlevel + actualextralight;
PolyDrawArgs args;
args.SetLight(GetColorTable(sector->Colormap, sector->SpecialColors[sector_t::sprites], true), lightlevel, PolyRenderer::Instance()->Light.SpriteGlobVis(foggy), fullbrightSprite);
args.SetLight(GetColorTable(sector->Colormap, sector->SpecialColors[sector_t::sprites], true), lightlevel, visibility, fullbrightSprite);
args.SetLights(Lights, NumLights);
args.SetStencilTestValue(StencilValue);
args.SetClipPlane(0, PolyClipPlane());
args.SetStyle(ModelActor->RenderStyle, ModelActor->Alpha, ModelActor->fillcolor, ModelActor->Translation, SkinTexture, fullbrightSprite);
args.SetStyle(RenderStyle, RenderAlpha, fillcolor, Translation, SkinTexture, fullbrightSprite);
args.SetDepthTest(true);
args.SetWriteDepth(true);
args.SetWriteStencil(false);

View file

@ -55,7 +55,15 @@ public:
const Mat4f &WorldToClip;
uint32_t StencilValue = 0;
AActor *ModelActor = nullptr;
FRenderStyle RenderStyle;
float RenderAlpha;
sector_t *sector;
bool fullbrightSprite;
int lightlevel;
double visibility;
uint32_t fillcolor;
uint32_t Translation;
Mat4f ObjectToWorld;
FTexture *SkinTexture = nullptr;
unsigned int *IndexBuffer = nullptr;

View file

@ -236,7 +236,7 @@ bool FOBJModel::Load(const char* fn, int lumpnum, const char* buffer, int length
*/
template<typename T, size_t L> void FOBJModel::ParseVector(TArray<T> &array)
{
float *coord = new float[L];
float coord[L];
for (size_t axis = 0; axis < L; axis++)
{
sc.MustGetFloat();
@ -244,7 +244,6 @@ template<typename T, size_t L> void FOBJModel::ParseVector(TArray<T> &array)
}
T vec(coord);
array.Push(vec);
delete[] coord;
}
/**

View file

@ -150,8 +150,7 @@ FSoundChan *Channels;
FSoundChan *FreeChannels;
FRolloffInfo S_Rolloff;
uint8_t *S_SoundCurve;
int S_SoundCurveSize;
TArray<uint8_t> S_SoundCurve;
FBoolCVar noisedebug ("noise", false, 0); // [RH] Print sound debugging info?
CUSTOM_CVAR (Int, snd_channels, 128, CVAR_ARCHIVE|CVAR_GLOBALCONFIG) // number of channels available
@ -311,20 +310,16 @@ void S_Init ()
atterm (S_Shutdown);
// remove old data (S_Init can be called multiple times!)
if (S_SoundCurve != NULL)
{
delete[] S_SoundCurve;
S_SoundCurve = NULL;
}
// Heretic and Hexen have sound curve lookup tables. Doom does not.
curvelump = Wads.CheckNumForName ("SNDCURVE");
if (curvelump >= 0)
{
S_SoundCurveSize = Wads.LumpLength (curvelump);
S_SoundCurve = new uint8_t[S_SoundCurveSize];
Wads.ReadLump(curvelump, S_SoundCurve);
S_SoundCurve.Resize(Wads.LumpLength (curvelump));
Wads.ReadLump(curvelump, S_SoundCurve.Data());
}
else
{
S_SoundCurve.Clear();
}
// Free all channels for use.
@ -376,11 +371,6 @@ void S_Shutdown ()
}
FreeChannels = NULL;
if (S_SoundCurve != NULL)
{
delete[] S_SoundCurve;
S_SoundCurve = NULL;
}
if (PlayList != NULL)
{
delete PlayList;
@ -1504,34 +1494,32 @@ sfxinfo_t *S_LoadSound(sfxinfo_t *sfx, FSoundLoadBuffer *pBuffer)
if (size > 0)
{
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]);
auto sfxdata = wlump.Read(size);
int32_t dmxlen = LittleLong(((int32_t *)sfxdata.Data())[1]);
std::pair<SoundHandle,bool> snd;
// If the sound is voc, use the custom loader.
if (strncmp ((const char *)sfxdata, "Creative Voice File", 19) == 0)
if (strncmp ((const char *)sfxdata.Data(), "Creative Voice File", 19) == 0)
{
snd = GSnd->LoadSoundVoc(sfxdata, size);
snd = GSnd->LoadSoundVoc(sfxdata.Data(), size);
}
// If the sound is raw, just load it as such.
else if (sfx->bLoadRAW)
{
snd = GSnd->LoadSoundRaw(sfxdata, size, sfx->RawRate, 1, 8, sfx->LoopStart);
snd = GSnd->LoadSoundRaw(sfxdata.Data(), size, sfx->RawRate, 1, 8, sfx->LoopStart);
}
// Otherwise, try the sound as DMX format.
else if (((uint8_t *)sfxdata)[0] == 3 && ((uint8_t *)sfxdata)[1] == 0 && dmxlen <= size - 8)
else if (((uint8_t *)sfxdata.Data())[0] == 3 && ((uint8_t *)sfxdata.Data())[1] == 0 && dmxlen <= size - 8)
{
int frequency = LittleShort(((uint16_t *)sfxdata)[1]);
int frequency = LittleShort(((uint16_t *)sfxdata.Data())[1]);
if (frequency == 0) frequency = 11025;
snd = GSnd->LoadSoundRaw(sfxdata+8, dmxlen, frequency, 1, 8, sfx->LoopStart);
snd = GSnd->LoadSoundRaw(sfxdata.Data()+8, dmxlen, frequency, 1, 8, sfx->LoopStart);
}
// If that fails, let the sound system try and figure it out.
else
{
snd = GSnd->LoadSound(sfxdata, size, false, pBuffer);
snd = GSnd->LoadSound(sfxdata.Data(), size, false, pBuffer);
}
delete[] sfxdata;
sfx->data = snd.first;
if(snd.second)
@ -1572,33 +1560,31 @@ static void S_LoadSound3D(sfxinfo_t *sfx, FSoundLoadBuffer *pBuffer)
if (size <= 0) return;
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]);
auto sfxdata = wlump.Read(size);
int32_t dmxlen = LittleLong(((int32_t *)sfxdata.Data())[1]);
// If the sound is voc, use the custom loader.
if (strncmp((const char *)sfxdata, "Creative Voice File", 19) == 0)
if (strncmp((const char *)sfxdata.Data(), "Creative Voice File", 19) == 0)
{
snd = GSnd->LoadSoundVoc(sfxdata, size, true);
snd = GSnd->LoadSoundVoc(sfxdata.Data(), size, true);
}
// If the sound is raw, just load it as such.
else if (sfx->bLoadRAW)
{
snd = GSnd->LoadSoundRaw(sfxdata, size, sfx->RawRate, 1, 8, sfx->LoopStart, true);
snd = GSnd->LoadSoundRaw(sfxdata.Data(), size, sfx->RawRate, 1, 8, sfx->LoopStart, true);
}
// Otherwise, try the sound as DMX format.
else if (((uint8_t *)sfxdata)[0] == 3 && ((uint8_t *)sfxdata)[1] == 0 && dmxlen <= size - 8)
else if (((uint8_t *)sfxdata.Data())[0] == 3 && ((uint8_t *)sfxdata.Data())[1] == 0 && dmxlen <= size - 8)
{
int frequency = LittleShort(((uint16_t *)sfxdata)[1]);
int frequency = LittleShort(((uint16_t *)sfxdata.Data())[1]);
if (frequency == 0) frequency = 11025;
snd = GSnd->LoadSoundRaw(sfxdata + 8, dmxlen, frequency, 1, 8, sfx->LoopStart, -1, true);
snd = GSnd->LoadSoundRaw(sfxdata.Data() + 8, dmxlen, frequency, 1, 8, sfx->LoopStart, -1, true);
}
// If that fails, let the sound system try and figure it out.
else
{
snd = GSnd->LoadSound(sfxdata, size, true, pBuffer);
snd = GSnd->LoadSound(sfxdata.Data(), size, true, pBuffer);
}
delete[] sfxdata;
}
sfx->data3d = snd.first;
@ -2274,9 +2260,9 @@ float S_GetRolloff(FRolloffInfo *rolloff, float distance, bool logarithmic)
}
float volume = (rolloff->MaxDistance - distance) / (rolloff->MaxDistance - rolloff->MinDistance);
if (rolloff->RolloffType == ROLLOFF_Custom && S_SoundCurve != NULL)
if (rolloff->RolloffType == ROLLOFF_Custom && S_SoundCurve.Size() > 0)
{
volume = S_SoundCurve[int(S_SoundCurveSize * (1 - volume))] / 127.f;
volume = S_SoundCurve[int(S_SoundCurve.Size() * (1 - volume))] / 127.f;
}
if (logarithmic)
{

View file

@ -165,8 +165,8 @@ public:
};
extern FRolloffInfo S_Rolloff;
extern uint8_t *S_SoundCurve;
extern int S_SoundCurveSize;
extern TArray<uint8_t> S_SoundCurve;
// Information about one playing sound.
struct sector_t;

View file

@ -249,14 +249,10 @@ bool FScanner::OpenFile (const char *name)
FileReader fr;
if (!fr.OpenFile(name)) return false;
auto filesize = fr.GetLength();
auto filebuf = new uint8_t[filesize];
if (fr.Read(filebuf, filesize) != filesize)
{
delete[] filebuf;
return false;
}
ScriptBuffer = FString((const char *)filebuf, filesize);
delete[] filebuf;
auto filebuff = fr.Read();
if (filebuff.Size() == 0 && filesize > 0) return false;
ScriptBuffer = FString((const char *)filebuff.Data(), filesize);
ScriptName = name; // This is used for error messages so the full file name is preferable
LumpNum = -1;
PrepareScript ();

View file

@ -688,8 +688,8 @@ static float GetRolloff(const FRolloffInfo *rolloff, float distance)
if(rolloff->RolloffType == ROLLOFF_Linear)
return volume;
if(rolloff->RolloffType == ROLLOFF_Custom && S_SoundCurve != NULL)
return S_SoundCurve[int(S_SoundCurveSize * (1.f - volume))] / 127.f;
if(rolloff->RolloffType == ROLLOFF_Custom && S_SoundCurve.Size() > 0)
return S_SoundCurve[int(S_SoundCurve.Size() * (1.f - volume))] / 127.f;
return (powf(10.f, volume) - 1.f) / 9.f;
}

View file

@ -181,7 +181,7 @@ void FSoftwareRenderer::RenderView(player_t *player, DCanvas *target, void *vide
void FSoftwareRenderer::WriteSavePic (player_t *player, FileWriter *file, int width, int height)
{
DSimpleCanvas pic(width, height, false);
DCanvas pic(width, height, false);
PalEntry palette[256];
// Take a snapshot of the player's view
@ -241,7 +241,7 @@ void FSoftwareRenderer::RenderTextureView (FCanvasTexture *tex, AActor *viewpoin
cameraViewwindow = r_viewwindow;
uint8_t *Pixels = renderTarget->IsBgra() ? (uint8_t*)tex->GetPixelsBgra() : (uint8_t*)tex->GetPixels(DefaultRenderStyle());
DSimpleCanvas *Canvas = renderTarget->IsBgra() ? tex->GetCanvasBgra() : tex->GetCanvas();
DCanvas *Canvas = renderTarget->IsBgra() ? tex->GetCanvasBgra() : tex->GetCanvas();
// curse Doom's overuse of global variables in the renderer.
// These get clobbered by rendering to a camera texture but they need to be preserved so the final rendering can be done with the correct palette.

View file

@ -96,7 +96,7 @@ sector_t *SWSceneDrawer::RenderView(player_t *player)
mat->AddTextureLayer(PaletteTexture.get());
Canvas.reset();
Canvas.reset(new DSimpleCanvas(screen->GetWidth(), screen->GetHeight(), V_IsTrueColor()));
Canvas.reset(new DCanvas(screen->GetWidth(), screen->GetHeight(), V_IsTrueColor()));
}
auto buf = fbtex->SystemTexture[0]->MapBuffer();

View file

@ -16,7 +16,7 @@ class SWSceneDrawer
std::unique_ptr<FWrapperTexture> FBTexture[2];
int FBTextureIndex = 0;
bool FBIsTruecolor = false;
std::unique_ptr<DSimpleCanvas> Canvas;
std::unique_ptr<DCanvas> Canvas;
public:
SWSceneDrawer();

View file

@ -75,6 +75,22 @@ namespace swrenderer
void RenderModel::Render(RenderThread *thread, short *cliptop, short *clipbottom, int minZ, int maxZ, Fake3DTranslucent clip3DFloor)
{
SWModelRenderer renderer(thread, clip3DFloor, &WorldToClip, MirrorWorldToClip);
renderer.sector = actor->Sector;
renderer.RenderStyle = actor->RenderStyle;
renderer.RenderAlpha = (float)actor->Alpha;
if (!renderer.RenderStyle.IsVisible(renderer.RenderAlpha))
return;
bool foggy = false;
int actualextralight = foggy ? 0 : PolyRenderer::Instance()->Viewpoint.extralight << 4;
bool fullbrightSprite = ((actor->renderflags & RF_FULLBRIGHT) || (actor->flags5 & MF5_BRIGHT));
renderer.lightlevel = fullbrightSprite ? 255 : actor->Sector->lightlevel + actualextralight;
renderer.visibility = PolyRenderer::Instance()->Light.SpriteGlobVis(foggy);
renderer.fillcolor = actor->fillcolor;
renderer.Translation = actor->Translation;
renderer.AddLights(actor);
renderer.RenderModel(x, y, z, smf, actor, r_viewpoint.TicFrac);
PolyTriangleDrawer::SetModelVertexShader(thread->DrawQueue, -1, -1, 0.0f);
@ -82,9 +98,47 @@ namespace swrenderer
/////////////////////////////////////////////////////////////////////////////
static bool isBright(DPSprite *psp)
{
if (psp != nullptr && psp->GetState() != nullptr)
{
bool disablefullbright = false;
FTextureID lump = sprites[psp->GetSprite()].GetSpriteFrame(psp->GetFrame(), 0, 0., nullptr);
if (lump.isValid())
{
FTexture * tex = TexMan(lump);
if (tex) disablefullbright = tex->bDisableFullbright;
}
return psp->GetState()->GetFullbright() && !disablefullbright;
}
return false;
}
void RenderHUDModel(RenderThread *thread, DPSprite *psp, float ofsx, float ofsy)
{
SWModelRenderer renderer(thread, Fake3DTranslucent(), &thread->Viewport->WorldToClip, false);
AActor *playermo = players[consoleplayer].camera;
auto rs = psp->GetRenderStyle(playermo->RenderStyle, playermo->Alpha);
renderer.sector = playermo->Sector;
renderer.RenderStyle = rs.first;
renderer.RenderAlpha = rs.second;
if (psp->Flags & PSPF_FORCEALPHA) renderer.RenderAlpha = 0.0f;
if (!renderer.RenderStyle.IsVisible(renderer.RenderAlpha))
return;
bool foggy = false;
int actualextralight = foggy ? 0 : PolyRenderer::Instance()->Viewpoint.extralight << 4;
bool fullbrightSprite = isBright(psp);
renderer.lightlevel = fullbrightSprite ? 255 : playermo->Sector->lightlevel + actualextralight;
renderer.visibility = PolyRenderer::Instance()->Light.SpriteGlobVis(foggy);
PalEntry ThingColor = (playermo->RenderStyle.Flags & STYLEF_ColorIsFixed) ? playermo->fillcolor : 0xffffff;
ThingColor.a = 255;
renderer.fillcolor = fullbrightSprite ? ThingColor : ThingColor.Modulate(playermo->Sector->SpecialColors[sector_t::sprites]);
renderer.Translation = 0xffffffff;// playermo->Translation;
renderer.RenderHUDModel(psp, ofsx, ofsy);
PolyTriangleDrawer::SetModelVertexShader(thread->DrawQueue, -1, -1, 0.0f);
}
@ -162,7 +216,6 @@ namespace swrenderer
void SWModelRenderer::BeginDrawModel(AActor *actor, FSpriteModelFrame *smf, const VSMatrix &objectToWorldMatrix, bool mirrored)
{
ModelActor = actor;
const_cast<VSMatrix &>(objectToWorldMatrix).copy(ObjectToWorld.Matrix);
ClipTop = {};
@ -209,8 +262,6 @@ namespace swrenderer
if (actor->RenderStyle == LegacyRenderStyles[STYLE_Normal] || !!(smf->flags & MDL_DONTCULLBACKFACES))
PolyTriangleDrawer::SetTwoSided(Thread->DrawQueue, false);
PolyTriangleDrawer::SetCullCCW(Thread->DrawQueue, true);
ModelActor = nullptr;
}
IModelVertexBuffer *SWModelRenderer::CreateVertexBuffer(bool needindex, bool singleframe)
@ -255,7 +306,6 @@ namespace swrenderer
void SWModelRenderer::BeginDrawHUDModel(AActor *actor, const VSMatrix &objectToWorldMatrix, bool mirrored)
{
ModelActor = actor;
const_cast<VSMatrix &>(objectToWorldMatrix).copy(ObjectToWorld.Matrix);
ClipTop = {};
ClipBottom = {};
@ -269,7 +319,6 @@ namespace swrenderer
void SWModelRenderer::EndDrawHUDModel(AActor *actor)
{
ModelActor = nullptr;
PolyTriangleDrawer::SetWeaponScene(Thread->DrawQueue, false);
if (actor->RenderStyle == LegacyRenderStyles[STYLE_Normal])
@ -301,20 +350,11 @@ namespace swrenderer
void SWModelRenderer::DrawArrays(int start, int count)
{
const auto &viewpoint = Thread->Viewport->viewpoint;
bool foggy = false;
int actualextralight = foggy ? 0 : viewpoint.extralight << 4;
sector_t *sector = ModelActor->Sector;
bool fullbrightSprite = ((ModelActor->renderflags & RF_FULLBRIGHT) || (ModelActor->flags5 & MF5_BRIGHT));
int lightlevel = fullbrightSprite ? 255 : ModelActor->Sector->lightlevel + actualextralight;
PolyDrawArgs args;
args.SetLight(GetColorTable(sector->Colormap, sector->SpecialColors[sector_t::sprites], true), lightlevel, Thread->Light->SpriteGlobVis(foggy), fullbrightSprite);
args.SetLight(GetColorTable(sector->Colormap, sector->SpecialColors[sector_t::sprites], true), lightlevel, visibility, fullbrightSprite);
args.SetLights(Lights, NumLights);
args.SetNormal(FVector3(0.0f, 0.0f, 0.0f));
args.SetStyle(ModelActor->RenderStyle, ModelActor->Alpha, ModelActor->fillcolor, ModelActor->Translation, SkinTexture, fullbrightSprite);
args.SetStyle(RenderStyle, RenderAlpha, fillcolor, Translation, SkinTexture, fullbrightSprite);
args.SetDepthTest(true);
args.SetWriteDepth(true);
args.SetWriteStencil(false);
@ -327,20 +367,11 @@ namespace swrenderer
void SWModelRenderer::DrawElements(int numIndices, size_t offset)
{
const auto &viewpoint = Thread->Viewport->viewpoint;
bool foggy = false;
int actualextralight = foggy ? 0 : viewpoint.extralight << 4;
sector_t *sector = ModelActor->Sector;
bool fullbrightSprite = ((ModelActor->renderflags & RF_FULLBRIGHT) || (ModelActor->flags5 & MF5_BRIGHT));
int lightlevel = fullbrightSprite ? 255 : ModelActor->Sector->lightlevel + actualextralight;
PolyDrawArgs args;
args.SetLight(GetColorTable(sector->Colormap, sector->SpecialColors[sector_t::sprites], true), lightlevel, Thread->Light->SpriteGlobVis(foggy), fullbrightSprite);
args.SetLight(GetColorTable(sector->Colormap, sector->SpecialColors[sector_t::sprites], true), lightlevel, visibility, fullbrightSprite);
args.SetLights(Lights, NumLights);
args.SetNormal(FVector3(0.0f, 0.0f, 0.0f));
args.SetStyle(ModelActor->RenderStyle, ModelActor->Alpha, ModelActor->fillcolor, ModelActor->Translation, SkinTexture, fullbrightSprite);
args.SetStyle(RenderStyle, RenderAlpha, fillcolor, Translation, SkinTexture, fullbrightSprite);
args.SetDepthTest(true);
args.SetWriteDepth(true);
args.SetWriteStencil(false);

View file

@ -78,7 +78,15 @@ namespace swrenderer
RenderThread *Thread = nullptr;
Fake3DTranslucent Clip3DFloor;
AActor *ModelActor = nullptr;
FRenderStyle RenderStyle;
float RenderAlpha;
sector_t *sector;
bool fullbrightSprite;
int lightlevel;
double visibility;
uint32_t fillcolor;
uint32_t Translation;
Mat4f ObjectToWorld;
PolyClipPlane ClipTop, ClipBottom;
FTexture *SkinTexture = nullptr;

View file

@ -108,7 +108,7 @@ const uint32_t *FCanvasTexture::GetPixelsBgra()
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 = new DCanvas (Width, Height, false);
if (Width != Height || Width != Canvas->GetPitch())
{
@ -128,7 +128,7 @@ void FCanvasTexture::MakeTexture (FRenderStyle) // This ignores the render style
void FCanvasTexture::MakeTextureBgra()
{
CanvasBgra = new DSimpleCanvas(Width, Height, true);
CanvasBgra = new DCanvas(Width, Height, true);
if (Width != Height || Width != CanvasBgra->GetPitch())
{

View file

@ -754,7 +754,7 @@ protected:
};
// A texture that can be drawn to.
class DSimpleCanvas;
class DCanvas;
class AActor;
class FCanvasTexture : public FTexture
@ -770,16 +770,16 @@ public:
bool CheckModified (FRenderStyle) override;
void NeedUpdate() { bNeedsUpdate=true; }
void SetUpdated() { bNeedsUpdate = false; bDidUpdate = true; bFirstUpdate = false; }
DSimpleCanvas *GetCanvas() { return Canvas; }
DSimpleCanvas *GetCanvasBgra() { return CanvasBgra; }
DCanvas *GetCanvas() { return Canvas; }
DCanvas *GetCanvasBgra() { return CanvasBgra; }
bool Mipmapped() override { return false; }
void MakeTexture (FRenderStyle style);
void MakeTextureBgra ();
protected:
DSimpleCanvas *Canvas = nullptr;
DSimpleCanvas *CanvasBgra = nullptr;
DCanvas *Canvas = nullptr;
DCanvas *CanvasBgra = nullptr;
uint8_t *Pixels = nullptr;
uint32_t *PixelsBgra = nullptr;
Span DummySpans[2];

View file

@ -357,7 +357,7 @@ FFont::FFont (const char *name, const char *nametemplate, int first, int count,
int i;
FTextureID lump;
char buffer[12];
FTexture **charlumps;
TArray<FTexture*> charLumps;
int maxyoffs;
bool doomtemplate = gameinfo.gametype & GAME_DoomChex ? strncmp (nametemplate, "STCFN", 5) == 0 : false;
bool stcfn121 = false;
@ -365,7 +365,7 @@ FFont::FFont (const char *name, const char *nametemplate, int first, int count,
noTranslate = notranslate;
Lump = fdlump;
Chars = new CharData[count];
charlumps = new FTexture *[count];
charLumps.Resize(count);
PatchRemap = new uint8_t[256];
FirstChar = first;
LastChar = first + count - 1;
@ -381,7 +381,7 @@ FFont::FFont (const char *name, const char *nametemplate, int first, int count,
for (i = 0; i < count; i++)
{
charlumps[i] = NULL;
charLumps[i] = NULL;
mysnprintf (buffer, countof(buffer), nametemplate, i + start);
lump = TexMan.CheckForTexture(buffer, ETextureType::MiscPatch);
@ -395,7 +395,7 @@ FFont::FFont (const char *name, const char *nametemplate, int first, int count,
!TexMan.CheckForTexture("STCFN122", ETextureType::MiscPatch).isValid())
{
// insert the incorrectly named '|' graphic in its correct position.
if (count > 124-start) charlumps[124-start] = TexMan[lump];
if (count > 124-start) charLumps[124-start] = TexMan[lump];
lump.SetInvalid();
stcfn121 = true;
}
@ -408,7 +408,7 @@ FFont::FFont (const char *name, const char *nametemplate, int first, int count,
{
// set the lump here only if it represents a valid texture
if (i != 124-start || !stcfn121)
charlumps[i] = pic;
charLumps[i] = pic;
int height = pic->GetScaledHeight();
int yoffs = pic->GetScaledTopOffset(0);
@ -425,10 +425,10 @@ FFont::FFont (const char *name, const char *nametemplate, int first, int count,
}
}
if (charlumps[i] != NULL)
if (charLumps[i] != nullptr)
{
if (!noTranslate) Chars[i].Pic = new FFontChar1 (charlumps[i]);
else Chars[i].Pic = charlumps[i];
if (!noTranslate) Chars[i].Pic = new FFontChar1 (charLumps[i]);
else Chars[i].Pic = charLumps[i];
Chars[i].XMove = Chars[i].Pic->GetScaledWidth();
}
else
@ -454,8 +454,6 @@ FFont::FFont (const char *name, const char *nametemplate, int first, int count,
FixXMoves();
if (!noTranslate) LoadTranslations();
delete[] charlumps;
}
//==========================================================================

View file

@ -82,87 +82,6 @@ void DFrameBuffer::CalcGamma (float gamma, uint8_t gammalookup[256])
}
}
//==========================================================================
//
// DSimpleCanvas Constructor
//
// A simple canvas just holds a buffer in main memory.
//
//==========================================================================
DSimpleCanvas::DSimpleCanvas (int width, int height, bool bgra)
: DCanvas (width, height, bgra)
{
PixelBuffer = nullptr;
Resize(width, height);
}
void DSimpleCanvas::Resize(int width, int height)
{
Width = width;
Height = height;
if (PixelBuffer != NULL)
{
delete[] PixelBuffer;
PixelBuffer = NULL;
}
// Making the pitch a power of 2 is very bad for performance
// Try to maximize the number of cache lines that can be filled
// for each column drawing operation by making the pitch slightly
// longer than the width. The values used here are all based on
// empirical evidence.
if (width <= 640)
{
// For low resolutions, just keep the pitch the same as the width.
// Some speedup can be seen using the technique below, but the speedup
// is so marginal that I don't consider it worthwhile.
Pitch = width;
}
else
{
// If we couldn't figure out the CPU's L1 cache line size, assume
// it's 32 bytes wide.
if (CPU.DataL1LineSize == 0)
{
CPU.DataL1LineSize = 32;
}
// The Athlon and P3 have very different caches, apparently.
// I am going to generalize the Athlon's performance to all AMD
// processors and the P3's to all non-AMD processors. I don't know
// how smart that is, but I don't have a vast plethora of
// processors to test with.
if (CPU.bIsAMD)
{
Pitch = width + CPU.DataL1LineSize;
}
else
{
Pitch = width + MAX(0, CPU.DataL1LineSize - 8);
}
}
int bytes_per_pixel = Bgra ? 4 : 1;
PixelBuffer = new uint8_t[Pitch * height * bytes_per_pixel];
memset (PixelBuffer, 0, Pitch * height * bytes_per_pixel);
}
//==========================================================================
//
// DSimpleCanvas Destructor
//
//==========================================================================
DSimpleCanvas::~DSimpleCanvas ()
{
if (PixelBuffer != NULL)
{
delete[] PixelBuffer;
PixelBuffer = NULL;
}
}
//==========================================================================
//
// DFrameBuffer Constructor

View file

@ -177,6 +177,7 @@ DCanvas::DCanvas (int _width, int _height, bool _bgra)
Width = _width;
Height = _height;
Bgra = _bgra;
Resize(_width, _height);
}
//==========================================================================
@ -189,6 +190,58 @@ DCanvas::~DCanvas ()
{
}
//==========================================================================
//
//
//
//==========================================================================
void DCanvas::Resize(int width, int height)
{
Width = width;
Height = height;
// Making the pitch a power of 2 is very bad for performance
// Try to maximize the number of cache lines that can be filled
// for each column drawing operation by making the pitch slightly
// longer than the width. The values used here are all based on
// empirical evidence.
if (width <= 640)
{
// For low resolutions, just keep the pitch the same as the width.
// Some speedup can be seen using the technique below, but the speedup
// is so marginal that I don't consider it worthwhile.
Pitch = width;
}
else
{
// If we couldn't figure out the CPU's L1 cache line size, assume
// it's 32 bytes wide.
if (CPU.DataL1LineSize == 0)
{
CPU.DataL1LineSize = 32;
}
// The Athlon and P3 have very different caches, apparently.
// I am going to generalize the Athlon's performance to all AMD
// processors and the P3's to all non-AMD processors. I don't know
// how smart that is, but I don't have a vast plethora of
// processors to test with.
if (CPU.bIsAMD)
{
Pitch = width + CPU.DataL1LineSize;
}
else
{
Pitch = width + MAX(0, CPU.DataL1LineSize - 8);
}
}
int bytes_per_pixel = Bgra ? 4 : 1;
Pixels.Resize(Pitch * height * bytes_per_pixel);
memset (Pixels.Data(), 0, Pixels.Size());
}
//==========================================================================
//
// V_GetColorFromString

View file

@ -292,53 +292,29 @@ struct VMVa_List
//
// VIDEO
//
// [RH] Made screens more implementation-independant:
//
class DCanvas
{
public:
DCanvas (int width, int height, bool bgra);
virtual ~DCanvas ();
~DCanvas ();
void Resize(int width, int height);
// Member variable access
inline uint8_t *GetPixels () const { return PixelBuffer; }
inline uint8_t *GetPixels () const { return Pixels.Data(); }
inline int GetWidth () const { return Width; }
inline int GetHeight () const { return Height; }
inline int GetPitch () const { return Pitch; }
inline bool IsBgra() const { return Bgra; }
// Note: pitch here is in pixels, not bytes.
bool SetBuffer(int width, int height, int pitch, uint8_t *buffer)
{
assert(buffer);
Width = width;
Height = height;
Pitch = pitch;
PixelBuffer = buffer;
return true;
}
protected:
uint8_t *PixelBuffer;
TArray<uint8_t> Pixels;
int Width;
int Height;
int Pitch;
bool Bgra;
};
// A canvas in system memory.
class DSimpleCanvas : public DCanvas
{
typedef DCanvas Super;
public:
DSimpleCanvas (int width, int height, bool bgra);
~DSimpleCanvas ();
void Resize(int width, int height);
};
class FUniquePalette;
class IHardwareTexture;
class FTexture;
@ -349,7 +325,6 @@ class FTexture;
class DFrameBuffer
{
typedef DSimpleCanvas Super;
protected:
void DrawTextureV(FTexture *img, double x, double y, uint32_t tag, va_list tags) = delete;

View file

@ -2530,22 +2530,7 @@ OPTSTR_SIMPLEARROW = "Simple arrow";
OPTSTR_HERETIC = "Heretic";
OPTSTR_CHEX = "Chex";
OPTSTR_SYSTEMCURSOR = "System cursor";
OPTSTR_DIRECTSOUND = "DirectSound";
OPTSTR_WASAPI = "Vista WASAPI";
OPTSTR_ASIO = "ASIO";
OPTSTR_WAVEOUT = "WaveOut";
OPTSTR_NOSOUND = "No Sound";
OPTSTR_OSS = "OSS";
OPTSTR_ALSA = "ALSA";
OPTSTR_SDL = "SDL";
OPTSTR_ESD = "ESD";
OPTSTR_PULSEAUDIO = "PulseAudio";
OPTSTR_COREAUDIO = "Core Audio";
OPTSTR_PCM8BIT = "8-bit";
OPTSTR_PCM16BIT = "16-bit";
OPTSTR_PCM24BIT = "24-bit";
OPTSTR_PCM32BIT = "32-bit";
OPTSTR_PCMFLOAT = "32-bit float";
OPTSTR_AUTO = "Auto";
OPTSTR_MONO = "Mono";
OPTSTR_STEREO = "Stereo";

View file

@ -1553,16 +1553,6 @@ OptionString ALResamplers
// filled in by the sound code
}
OptionString OutputFormats
{
"PCM-8", "$OPTSTR_PCM8BIT"
"PCM-16", "$OPTSTR_PCM16BIT"
"PCM-24", "$OPTSTR_PCM24BIT"
"PCM-32", "$OPTSTR_PCM32BIT"
"PCM-Float", "$OPTSTR_PCMFLOAT"
}
OptionString SpeakerModes
{
"Auto", "$OPTSTR_AUTO"
@ -1585,12 +1575,6 @@ OptionString Resamplers
}
OptionString SoundBackendsOpenALOnly
{
"openal", "$OPTSTR_OPENAL"
"null", "$OPTSTR_NOSOUND"
}
OptionMenu OpenALSoundItems protected
{
Title "$OPENALMNU_TITLE"
@ -1616,23 +1600,8 @@ OptionMenu SoundOptions protected
Option "$SNDMNU_UNDERWATERREVERB", "snd_waterreverb", "OnOff"
Option "$SNDMNU_RANDOMIZEPITCHES", "snd_pitched", "OnOff"
Slider "$SNDMNU_CHANNELS", "snd_channels", 64, 256, 8, 0
StaticText " "
Option "$SNDMNU_BACKGROUND", "i_soundinbackground", "OnOff"
StaticText " "
ifoption(openal)
{
Option "$SNDMNU_BACKEND", "snd_backend", "SoundBackendsOpenALOnly"
Submenu "$SNDMNU_OPENAL", "OpenALSoundItems"
}
StaticText " "
Command "$SNDMNU_RESTART", "snd_reset"
StaticText " "
Submenu "$SNDMNU_ADVANCED", "AdvSoundOptions"
Submenu "$SNDMNU_MIDIPLAYER", "MidiPlayerOptions"
Submenu "$SNDMNU_MODREPLAYER", "ModReplayerOptions"
StaticText " "
Submenu "$OPTMNU_REVERB", "ReverbEdit"
}
@ -1665,6 +1634,21 @@ OptionMenu AdvSoundOptions protected
Title "$ADVSNDMNU_TITLE"
Option "$ADVSNDMNU_SAMPLERATE", "snd_samplerate", "SampleRates"
Option "$ADVSNDMNU_HRTF", "snd_hrtf", "AutoOffOn"
StaticText " "
Option "$SNDMNU_BACKGROUND", "i_soundinbackground", "OnOff"
StaticText " "
ifoption(openal)
{
StaticText " "
Submenu "$SNDMNU_OPENAL", "OpenALSoundItems"
}
StaticText " "
Submenu "$SNDMNU_MIDIPLAYER", "MidiPlayerOptions"
Submenu "$SNDMNU_MODREPLAYER", "ModReplayerOptions"
StaticText " "
Command "$SNDMNU_RESTART", "snd_reset"
}
OptionMenu GusConfigMenu protected

View file

@ -581,6 +581,7 @@ class Actor : Thinker native
native void ClearCounters();
native bool GiveBody (int num, int max=0);
native bool HitFloor();
native virtual bool Grind(bool items);
native clearscope bool isTeammate(Actor other) const;
native clearscope int PlayerNumber() const;
native void SetFriendPlayer(PlayerInfo player);

View file

@ -145,6 +145,32 @@ class Inventory : Actor native
}
}
//===========================================================================
//
// AInventory :: Grind
//
//===========================================================================
override bool Grind(bool items)
{
// Does this grind request even care about items?
if (!items)
{
return false;
}
// Dropped items are normally destroyed by crushers. Set the DONTGIB flag,
// and they'll act like corpses with it set and be immune to crushers.
if (bDropped)
{
if (!bDontGib)
{
Destroy();
}
return false;
}
// Non-dropped items call the super method for compatibility.
return Super.Grind(items);
}
//===========================================================================
//