Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/Texture_Cleanup' into softwaresc…
Browse files Browse the repository at this point in the history
…aling
  • Loading branch information
Rachael Alexanderson committed Dec 15, 2018
2 parents 2e927c7 + 1aba331 commit 3fc9dd4
Show file tree
Hide file tree
Showing 16 changed files with 179 additions and 253 deletions.
64 changes: 19 additions & 45 deletions src/d_dehacked.cpp
Expand Up @@ -223,8 +223,7 @@ DEFINE_FIELD_X(DehInfo, DehInfo, BlueAC)

TArray<PClassActor *> TouchedActors;

char *UnchangedSpriteNames;
int NumUnchangedSprites;
TArray<uint32_t> UnchangedSpriteNames;
bool changedStates;

// Sprite<->Class map for DehackedPickup::DetermineType
Expand Down Expand Up @@ -395,17 +394,10 @@ static bool HandleKey (const struct Key *keys, void *structure, const char *key,

static int FindSprite (const char *sprname)
{
int i;
uint32_t nameint = *((uint32_t *)sprname);

for (i = 0; i < NumUnchangedSprites; ++i)
{
if (*((uint32_t *)&UnchangedSpriteNames[i*4]) == nameint)
{
return i;
}
}
return -1;
uint32_t nameint;
memcpy(&nameint, sprname, 4);
auto f = UnchangedSpriteNames.Find(nameint);
return f == UnchangedSpriteNames.Size() ? -1 : f;
}

static FState *FindState (int statenum)
Expand Down Expand Up @@ -2665,31 +2657,16 @@ static void UnloadDehSupp ()
// that was altered by the first. So we need to keep the
// StateMap around until all patches have been applied.
DehUseCount = 0;
Actions.Clear();
Actions.ShrinkToFit();
OrgHeights.Clear();
OrgHeights.ShrinkToFit();
CodePConv.Clear();
CodePConv.ShrinkToFit();
OrgSprNames.Clear();
OrgSprNames.ShrinkToFit();
SoundMap.Clear();
SoundMap.ShrinkToFit();
InfoNames.Clear();
InfoNames.ShrinkToFit();
BitNames.Clear();
BitNames.ShrinkToFit();
StyleNames.Clear();
StyleNames.ShrinkToFit();
AmmoNames.Clear();
AmmoNames.ShrinkToFit();

if (UnchangedSpriteNames != NULL)
{
delete[] UnchangedSpriteNames;
UnchangedSpriteNames = NULL;
NumUnchangedSprites = 0;
}
Actions.Reset();
OrgHeights.Reset();
CodePConv.Reset();
OrgSprNames.Reset();
SoundMap.Reset();
InfoNames.Reset();
BitNames.Reset();
StyleNames.Reset();
AmmoNames.Reset();
UnchangedSpriteNames.Reset();
if (EnglishStrings != NULL)
{
delete EnglishStrings;
Expand Down Expand Up @@ -2731,14 +2708,11 @@ static bool LoadDehSupp ()
EnglishStrings->LoadStrings (true);
}

if (UnchangedSpriteNames == NULL)

UnchangedSpriteNames.Resize(sprites.Size());
for (unsigned i = 0; i < UnchangedSpriteNames.Size(); ++i)
{
UnchangedSpriteNames = new char[sprites.Size()*4];
NumUnchangedSprites = sprites.Size();
for (i = 0; i < NumUnchangedSprites; ++i)
{
memcpy (UnchangedSpriteNames+i*4, &sprites[i].name, 4);
}
memcpy (&UnchangedSpriteNames[i], &sprites[i].name, 4);
}

FScanner sc;
Expand Down
2 changes: 1 addition & 1 deletion src/d_main.cpp
Expand Up @@ -2709,7 +2709,7 @@ void D_DoomMain (void)
DestroyCVarsFlagged(CVAR_MOD); // Delete any cvar left by mods
FS_Close(); // destroy the global FraggleScript.
DeinitMenus();
LightDefaults.Clear(); // this can leak heap memory if it isn't cleared.
LightDefaults.DeleteAndClear(); // this can leak heap memory if it isn't cleared.

// delete DoomStartupInfo data
DoomStartupInfo.Name = (const char*)0;
Expand Down
2 changes: 1 addition & 1 deletion src/g_shared/a_dynlight.h
Expand Up @@ -85,7 +85,7 @@ class FLightDefaults
}

protected:
FName m_Name;
FName m_Name = NAME_None;
int m_Args[5] = { 0,0,0,0,0 };
double m_Param = 0;
DVector3 m_Pos = { 0,0,0 };
Expand Down
3 changes: 2 additions & 1 deletion src/g_statusbar/sbarinfo.cpp
Expand Up @@ -1379,7 +1379,8 @@ class DSBarInfo
width = font->GetCharWidth((unsigned char) *str);
else
width = font->GetCharWidth((unsigned char) script->spacingCharacter);
FTexture* c = font->GetChar((unsigned char) *str, &width);
bool redirected = false;
FTexture* c = font->GetChar((unsigned char) *str, fontcolor, &width);
if(c == NULL) //missing character.
{
str++;
Expand Down
2 changes: 1 addition & 1 deletion src/g_statusbar/shared_sbar.cpp
Expand Up @@ -1513,7 +1513,7 @@ void DBaseStatusBar::DrawString(FFont *font, const FString &cstring, double x, d
}

int width;
FTexture* c = font->GetChar((unsigned char)ch, &width);
FTexture* c = font->GetChar((unsigned char)ch, fontcolor, &width);
if (c == NULL) //missing character.
{
continue;
Expand Down
4 changes: 2 additions & 2 deletions src/gl/renderer/gl_renderbuffers.cpp
Expand Up @@ -966,11 +966,11 @@ void FGLRenderBuffers::RenderEffect(const FString &name)
auto &shader = GLShaders[step.ShaderName];

// Set uniforms
if (step.Uniforms.Size > 0)
if (step.Uniforms.Data.Size() > 0)
{
if (!shader->Uniforms)
shader->Uniforms.reset(screen->CreateDataBuffer(POSTPROCESS_BINDINGPOINT, false));
shader->Uniforms->SetData(step.Uniforms.Size, step.Uniforms.Data);
shader->Uniforms->SetData(step.Uniforms.Data.Size(), step.Uniforms.Data.Data());
shader->Uniforms->BindBase();
}

Expand Down
42 changes: 7 additions & 35 deletions src/hwrenderer/postprocessing/hw_postprocess.h
Expand Up @@ -38,12 +38,7 @@ class PPUniforms

PPUniforms(const PPUniforms &src)
{
if (src.Size > 0)
{
Data = new uint8_t[src.Size];
Size = src.Size;
memcpy(Data, src.Data, Size);
}
Data = src.Data;
}

~PPUniforms()
Expand All @@ -53,49 +48,26 @@ class PPUniforms

PPUniforms &operator=(const PPUniforms &src)
{
if (this != &src)
{
if (src.Size > 0)
{
Data = new uint8_t[src.Size];
Size = src.Size;
memcpy(Data, src.Data, Size);
}
else
{
delete[] Data;
Data = nullptr;
Size = 0;
}
}

Data = src.Data;
return *this;
}

void Clear()
{
delete[] Data;
Data = nullptr;
Size = 0;
Data.Clear();
}

template<typename T>
void Set(const T &v)
{
if (Size != (int)sizeof(T))
if (Data.Size() != (int)sizeof(T))
{
delete[] Data;
Data = nullptr;
Size = 0;

Data = new uint8_t[sizeof(T)];
Size = sizeof(T);
memcpy(Data, &v, Size);
Data.Resize(sizeof(T));
memcpy(Data.Data(), &v, Data.Size());
}
}

uint8_t *Data = nullptr;
int Size = 0;
TArray<uint8_t> Data;
};

class PPStep
Expand Down
2 changes: 1 addition & 1 deletion src/intermission/intermission.cpp
Expand Up @@ -337,7 +337,7 @@ void DIntermissionScreenText::Drawer ()
continue;
}

pic = SmallFont->GetChar (c, &w);
pic = SmallFont->GetChar (c, mTextColor, &w);
w += kerning;
w *= CleanXfac;
if (cx + w > SCREENWIDTH)
Expand Down
45 changes: 15 additions & 30 deletions src/p_effect.cpp
Expand Up @@ -59,10 +59,9 @@ FRandom pr_railtrail("RailTrail");
#define FADEFROMTTL(a) (1.f/(a))

// [RH] particle globals
uint16_t NumParticles;
uint16_t ActiveParticles;
uint16_t InactiveParticles;
particle_t *Particles;
uint32_t ActiveParticles;
uint32_t InactiveParticles;
TArray<particle_t> Particles;
TArray<uint16_t> ParticlesInSubsec;

static int grey1, grey2, grey3, grey4, red, green, blue, yellow, black,
Expand Down Expand Up @@ -105,13 +104,13 @@ static const struct ColorList {

inline particle_t *NewParticle (void)
{
particle_t *result = NULL;
particle_t *result = nullptr;
if (InactiveParticles != NO_PARTICLE)
{
result = Particles + InactiveParticles;
result = &Particles[InactiveParticles];
InactiveParticles = result->tnext;
result->tnext = ActiveParticles;
ActiveParticles = uint16_t(result - Particles);
ActiveParticles = uint32_t(result - Particles.Data());
}
return result;
}
Expand All @@ -120,7 +119,6 @@ inline particle_t *NewParticle (void)
// [RH] Particle functions
//
void P_InitParticles ();
void P_DeinitParticles ();

// [BC] Allow the maximum number of particles to be specified by a cvar (so people
// with lots of nice hardware can have lots of particles!).
Expand All @@ -135,7 +133,6 @@ CUSTOM_CVAR( Int, r_maxparticles, 4000, CVAR_ARCHIVE )

if ( gamestate != GS_STARTUP )
{
P_DeinitParticles( );
P_InitParticles( );
}
}
Expand All @@ -152,33 +149,21 @@ void P_InitParticles ()
num = r_maxparticles;

// This should be good, but eh...
NumParticles = (uint16_t)clamp<int>(num, 100, 65535);
int NumParticles = clamp<int>(num, 100, 65535);

P_DeinitParticles();
Particles = new particle_t[NumParticles];
Particles.Resize(NumParticles);
P_ClearParticles ();
atterm (P_DeinitParticles);
}

void P_DeinitParticles()
{
if (Particles != NULL)
{
delete[] Particles;
Particles = NULL;
}
}

void P_ClearParticles ()
{
int i;

memset (Particles, 0, NumParticles * sizeof(particle_t));
int i = 0;
memset (Particles.Data(), 0, Particles.Size() * sizeof(particle_t));
ActiveParticles = NO_PARTICLE;
InactiveParticles = 0;
for (i = 0; i < NumParticles-1; i++)
Particles[i].tnext = i + 1;
Particles[i].tnext = NO_PARTICLE;
for (auto &p : Particles)
p.tnext = ++i;
Particles.Last().tnext = NO_PARTICLE;
}

// Group particles by subsectors. Because particles are always
Expand Down Expand Up @@ -255,7 +240,7 @@ void P_ThinkParticles ()
prev = NULL;
while (i != NO_PARTICLE)
{
particle = Particles + i;
particle = &Particles[i];
i = particle->tnext;
if (!particle->notimefreeze && ((bglobal.freeze) || (level.flags2 & LEVEL2_FROZEN)))
{
Expand All @@ -274,7 +259,7 @@ void P_ThinkParticles ()
else
ActiveParticles = i;
particle->tnext = InactiveParticles;
InactiveParticles = (int)(particle - Particles);
InactiveParticles = (int)(particle - Particles.Data());
continue;
}

Expand Down
2 changes: 1 addition & 1 deletion src/p_effect.h
Expand Up @@ -62,7 +62,7 @@ struct particle_t
uint16_t snext;
};

extern particle_t *Particles;
extern TArray<particle_t> Particles;
extern TArray<uint16_t> ParticlesInSubsec;

const uint16_t NO_PARTICLE = 0xffff;
Expand Down
2 changes: 1 addition & 1 deletion src/polyrenderer/scene/poly_scene.cpp
Expand Up @@ -189,7 +189,7 @@ void RenderPolyScene::RenderSubsector(PolyRenderThread *thread, subsector_t *sub
int subsectorIndex = sub->Index();
for (int i = ParticlesInSubsec[subsectorIndex]; i != NO_PARTICLE; i = Particles[i].snext)
{
particle_t *particle = Particles + i;
particle_t *particle = &Particles[i];
thread->TranslucentObjects.push_back(thread->FrameMemory->NewObject<PolyTranslucentParticle>(particle, sub, subsectorDepth, CurrentViewpoint->StencilValue));
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/r_data/gldefs.cpp
Expand Up @@ -1758,7 +1758,7 @@ void ParseGLDefs()
{
const char *defsLump = NULL;

LightDefaults.Clear();
LightDefaults.DeleteAndClear();
//gl_DestroyUserShaders(); function says 'todo'
switch (gameinfo.gametype)
{
Expand Down
2 changes: 1 addition & 1 deletion src/swrenderer/scene/r_opaque_pass.cpp
Expand Up @@ -616,7 +616,7 @@ namespace swrenderer
int shade = LightVisibility::LightLevelToShade((floorlightlevel + ceilinglightlevel) / 2 + LightVisibility::ActualExtraLight(foggy, Thread->Viewport.get()), foggy);
for (int i = ParticlesInSubsec[sub->Index()]; i != NO_PARTICLE; i = Particles[i].snext)
{
RenderParticle::Project(Thread, Particles + i, sub->sector, shade, FakeSide, foggy);
RenderParticle::Project(Thread, &Particles[i], sub->sector, shade, FakeSide, foggy);
}
}

Expand Down

0 comments on commit 3fc9dd4

Please sign in to comment.