Skip to content

Commit

Permalink
Tidied up code more, removed some more asserts and debug stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
Ben Slater authored and Ben Slater committed May 22, 2019
1 parent 10cd615 commit e9f95d3
Show file tree
Hide file tree
Showing 8 changed files with 74 additions and 70 deletions.
3 changes: 2 additions & 1 deletion Source/SysPSP/Graphics/GraphicsContext.cpp
Expand Up @@ -150,8 +150,9 @@ class IGraphicsContext : public CGraphicsContext
//*************************************************************************************
template<> bool CSingleton< CGraphicsContext >::Create()
{
#ifdef DAEDALUS_ENABLE_ASSERTS
DAEDALUS_ASSERT_Q(mpInstance == nullptr);

#endif
mpInstance = new IGraphicsContext();
return mpInstance->Initialise();
}
Expand Down
18 changes: 14 additions & 4 deletions Source/SysPSP/Graphics/NativeTexturePSP.cpp
Expand Up @@ -74,7 +74,9 @@ EPspTextureFormat GetPspTextureFormat( ETextureFormat texture_format )
case TexFmt_CI8_8888: return PspTexFmt_T8;
}

#ifdef DAEDALUS_DEBUG_CONSOLE
DAEDALUS_ERROR( "Unhandled texture format" );
#endif
return PspTexFmt_8888;
}

Expand Down Expand Up @@ -488,10 +490,11 @@ namespace

CRefPtr<CNativeTexture> texture = CNativeTexture::Create( width, height, texture_format );

#ifdef DAEDALUS_ENABLE_ASSERTS
DAEDALUS_ASSERT( texture->GetWidth() >= width, "Width is unexpectedly small" );
DAEDALUS_ASSERT( texture->GetHeight() >= height, "Height is unexpectedly small" );
DAEDALUS_ASSERT( texture_format == texture->GetFormat(), "Texture format doesn't match" );

#endif
u8 * p_dest( new u8[ texture->GetBytesRequired() ] );
if( !p_dest )
{
Expand All @@ -518,11 +521,15 @@ namespace

case TexFmt_CI4_8888:
case TexFmt_CI8_8888:
#ifdef DAEDALUS_DEBUG_CONSOLE
DAEDALUS_ERROR( "Can't use palettised format for png." );
#endif
break;

default:
#ifdef DAEDALUS_DEBUG_CONSOLE
DAEDALUS_ERROR( "Unhandled texture format" );
#endif
break;
}

Expand Down Expand Up @@ -568,10 +575,9 @@ void CNativeTexture::SetData( void * data, void * palette )

if( mpPalette != nullptr )
{
DAEDALUS_ASSERT( palette != nullptr, "No palette provided" );

#ifdef DAEDALUS_ENABLE_ASSERTS
mPaletteSet = true;
DAEDALUS_ASSERT( palette != nullptr, "No palette provided" );
mPaletteSet = true;
#endif

switch( mTextureFormat )
Expand All @@ -584,7 +590,9 @@ void CNativeTexture::SetData( void * data, void * palette )
break;

default:
#ifdef DAEDALUS_DEBUG_CONSOLE
DAEDALUS_ERROR( "Unhandled palette format" );
#endif
break;
}

Expand All @@ -597,7 +605,9 @@ void CNativeTexture::SetData( void * data, void * palette )
}
else
{
#ifdef DAEDALUS_ENABLE_ASSERTS
DAEDALUS_ASSERT( palette == nullptr, "Palette provided when not needed" );
#endif
}
}
}
Expand Down
3 changes: 2 additions & 1 deletion Source/SysPSP/Graphics/VideoMemoryManager.cpp
Expand Up @@ -44,8 +44,9 @@ class IVideoMemoryManager : public CVideoMemoryManager
//*****************************************************************************
template<> bool CSingleton< CVideoMemoryManager >::Create()
{
#ifdef DAEDALUS_ENABLE_ASSERTS
DAEDALUS_ASSERT_Q(mpInstance == nullptr);

#endif
mpInstance = new IVideoMemoryManager();
return mpInstance != nullptr;
}
Expand Down
28 changes: 14 additions & 14 deletions Source/SysPSP/HLEGraphics/ColourAdjuster.cpp
Expand Up @@ -49,7 +49,7 @@ void CColourAdjuster::Process( DaedalusVtx * p_vertices, u32 num_verts ) const

case COL32_MASK_RGBA:
{
for(u32 v = 0; v < num_verts; v++)
for(u32 v {} ; v < num_verts; v++)
{
p_vertices[v].Colour = mSetColour;
}
Expand All @@ -58,10 +58,10 @@ void CColourAdjuster::Process( DaedalusVtx * p_vertices, u32 num_verts ) const

default:
{
u32 clear_bits( ~mSetMask );
u32 set_bits( mSetColour.GetColour() & mSetMask );
u32 clear_bits {~mSetMask};
u32 set_bits {mSetColour.GetColour() & mSetMask};

for(u32 v = 0; v < num_verts; v++)
for(u32 v {}; v < num_verts; v++)
{
p_vertices[v].Colour = c32( (p_vertices[v].Colour.GetColour() & clear_bits) | set_bits );
}
Expand All @@ -73,7 +73,7 @@ void CColourAdjuster::Process( DaedalusVtx * p_vertices, u32 num_verts ) const
{
case COL32_MASK_RGB:
{
for(u32 v = 0; v < num_verts; v++)
for(u32 v {}; v < num_verts; v++)
{
p_vertices[v].Colour = p_vertices[v].Colour.SubRGB( mSubtractColour );
}
Expand All @@ -82,7 +82,7 @@ void CColourAdjuster::Process( DaedalusVtx * p_vertices, u32 num_verts ) const

case COL32_MASK_A:
{
for(u32 v = 0; v < num_verts; v++)
for(u32 v {}; v < num_verts; v++)
{
p_vertices[v].Colour = p_vertices[v].Colour.SubA( mSubtractColour );
}
Expand Down Expand Up @@ -112,7 +112,7 @@ void CColourAdjuster::Process( DaedalusVtx * p_vertices, u32 num_verts ) const

case COL32_MASK_A:
{
for(u32 v = 0; v < num_verts; v++)
for(u32 v {}; v < num_verts; v++)
{
p_vertices[v].Colour = p_vertices[v].Colour.ModulateA( mModulateColour );
}
Expand All @@ -121,7 +121,7 @@ void CColourAdjuster::Process( DaedalusVtx * p_vertices, u32 num_verts ) const

case COL32_MASK_RGBA:
{
for(u32 v = 0; v < num_verts; v++)
for(u32 v {}; v < num_verts; v++)
{
p_vertices[v].Colour = p_vertices[v].Colour.Modulate( mModulateColour );
}
Expand All @@ -141,8 +141,8 @@ void CColourAdjuster::Set( u32 mask, c32 colour )
#endif
mSetMask |= mask;

u32 current( mSetColour.GetColour() );
u32 col( colour.GetColour() );
u32 current {mSetColour.GetColour()};
u32 col {colour.GetColour()};

mSetColour = c32( ( current & ~mask) | (col & mask) );
}
Expand All @@ -157,8 +157,8 @@ void CColourAdjuster::Modulate( u32 mask, c32 colour )
#endif
mModulateMask |= mask;

u32 current( mModulateColour.GetColour() );
u32 col( colour.GetColour() );
u32 current {mModulateColour.GetColour()};
u32 col {colour.GetColour()};

mModulateColour = c32( ( current & ~mask) | (col & mask) );
}
Expand All @@ -173,8 +173,8 @@ void CColourAdjuster::Subtract( u32 mask, c32 colour )
#endif
mSubtractMask |= mask;

u32 current( mSubtractColour.GetColour() );
u32 col( colour.GetColour() );
u32 current {mSubtractColour.GetColour()};
u32 col {colour.GetColour() };

mSubtractColour = c32( ( current & ~mask) | (col & mask) );
}
6 changes: 3 additions & 3 deletions Source/SysPSP/HLEGraphics/GraphicsPluginPSP.cpp
Expand Up @@ -57,7 +57,7 @@ namespace
//u32 gVblCount = 0;
u32 gFlipCount {};
//float gCurrentVblrate = 0.0f;
float gCurrentFramerate = 0.0f;
float gCurrentFramerate {0.0f};
u64 gLastFramerateCalcTime {};
u64 gTicksPerSecond {};

Expand All @@ -74,7 +74,7 @@ static void UpdateFramerate()
#endif
gFlipCount++;

u64 now;
u64 now {};
NTiming::GetPreciseTime( &now );

if(gLastFramerateCalcTime == 0)
Expand Down Expand Up @@ -238,7 +238,7 @@ void CGraphicsPluginImpl::UpdateScreen()
HandleEndOfFrame();
}

static u32 current_frame = 0;
static u32 current_frame {};
current_frame++;


Expand Down
74 changes: 37 additions & 37 deletions Source/SysPSP/HLEGraphics/RendererPSP.cpp
Expand Up @@ -324,12 +324,12 @@ void RendererPSP::RenderTriangles( DaedalusVtx * p_vertices, u32 num_vertices, b
{
UpdateTileSnapshots( mTextureTile );

const CNativeTexture * texture = mBoundTexture[0];
const CNativeTexture * texture {mBoundTexture[0]};

if( texture && (mTnL.Flags._u32 & (TNL_LIGHT|TNL_TEXGEN)) != (TNL_LIGHT|TNL_TEXGEN) )
{
float scale_x = texture->GetScaleX();
float scale_y = texture->GetScaleY();
float scale_x {texture->GetScaleX()};
float scale_y {texture->GetScaleY()};

// Hack to fix the sun in Zelda OOT/MM
if( g_ROM.ZELDA_HACK && (gRDPOtherMode.L == 0x0c184241) ) //&& ti.GetFormat() == G_IM_FMT_I && (ti.GetWidth() == 64)
Expand Down Expand Up @@ -365,12 +365,12 @@ inline void RendererPSP::RenderFog( DaedalusVtx * p_vertices, u32 num_vertices,
sceGuDisable(GU_ALPHA_TEST);
sceGuBlendFunc(GU_ADD, GU_SRC_ALPHA, GU_ONE_MINUS_SRC_ALPHA, 0, 0);

u32 FogColor = mFogColour.GetColour();
u32 FogColor {mFogColour.GetColour()};

//Copy fog color to vertices
for(u32 i = 0 ; i < num_vertices ; i++)
for(u32 i {} ; i < num_vertices ; i++)
{
u32 alpha = p_vertices[i].Colour.GetColour() & 0xFF000000;
u32 alpha {p_vertices[i].Colour.GetColour() & 0xFF000000};
p_vertices[i].Colour = (c32)(alpha | FogColor);
}

Expand All @@ -382,7 +382,7 @@ inline void RendererPSP::RenderFog( DaedalusVtx * p_vertices, u32 num_vertices,

void RendererPSP::RenderUsingCurrentBlendMode( DaedalusVtx * p_vertices, u32 num_vertices, u32 triangle_mode, u32 render_mode, bool disable_zbuffer )
{
static bool ZFightingEnabled( false );
static bool ZFightingEnabled {false};

DAEDALUS_PROFILE( "RendererPSP::RenderUsingCurrentBlendMode" );

Expand Down Expand Up @@ -436,7 +436,7 @@ void RendererPSP::RenderUsingCurrentBlendMode( DaedalusVtx * p_vertices, u32 num
sceGuTexFilter(GU_NEAREST,GU_NEAREST);
}

u32 cycle_mode = gRDPOtherMode.cycle_type;
u32 cycle_mode {gRDPOtherMode.cycle_type};

// Initiate Blender
//
Expand All @@ -453,7 +453,7 @@ void RendererPSP::RenderUsingCurrentBlendMode( DaedalusVtx * p_vertices, u32 num
//
if( (gRDPOtherMode.alpha_compare == G_AC_THRESHOLD) && !gRDPOtherMode.alpha_cvg_sel )
{
u8 alpha_threshold = mBlendColour.GetA();
u8 alpha_threshold {mBlendColour.GetA()};
sceGuAlphaFunc( (alpha_threshold | g_ROM.ALPHA_HACK) ? GU_GEQUAL : GU_GREATER, alpha_threshold, 0xff);
sceGuEnable(GU_ALPHA_TEST);
}
Expand All @@ -479,7 +479,7 @@ void RendererPSP::RenderUsingCurrentBlendMode( DaedalusVtx * p_vertices, u32 num
case CYCLE_2CYCLE: blend_entry = LookupBlendState( mMux, true ); break;
}

u32 render_flags( GU_TEXTURE_32BITF | GU_COLOR_8888 | GU_VERTEX_32BITF | render_mode );
u32 render_flags {GU_TEXTURE_32BITF | GU_COLOR_8888 | GU_VERTEX_32BITF | render_mode};

#ifdef DAEDALUS_DEBUG_DISPLAYLIST
// Used for Blend Explorer, or Nasty texture
Expand Down Expand Up @@ -508,11 +508,11 @@ void RendererPSP::RenderUsingCurrentBlendMode( DaedalusVtx * p_vertices, u32 num

blend_entry.OverrideFunction( details );

bool installed_texture( false );
bool installed_texture {false};

if( details.InstallTexture )
{
u32 texture_idx = g_ROM.T1_HACK ? 1 : 0;
u32 texture_idx {g_ROM.T1_HACK ? 1 : 0};

if( mBoundTexture[ texture_idx ] )
{
Expand Down Expand Up @@ -584,7 +584,7 @@ void RendererPSP::RenderUsingRenderSettings( const CBlendStates * states, Daedal
memcpy( mVtx_Save, p_vertices, num_vertices * sizeof( DaedalusVtx ) );
}

for( u32 i = 0; i < states->GetNumStates(); ++i )
for( u32 i {}; i < states->GetNumStates(); ++i )
{
const CRenderSettings * settings( states->GetColourSettings( i ) );

Expand Down Expand Up @@ -613,13 +613,13 @@ void RendererPSP::RenderUsingRenderSettings( const CBlendStates * states, Daedal
out.VertexExpressionA->ApplyExpressionAlpha( state );
}

bool installed_texture = false;
bool installed_texture {false};

u32 texture_idx = 0;
u32 texture_idx {};

if(install_texture0 || install_texture1)
{
u32 tfx( GU_TFX_MODULATE );
u32 tfx {GU_TFX_MODULATE};
switch( out.BlendMode )
{
case PBM_MODULATE: tfx = GU_TFX_MODULATE; break;
Expand Down Expand Up @@ -720,7 +720,7 @@ void RendererPSP::TexRect( u32 tile_idx, const v2 & xy0, const v2 & xy1, TexCoor
DL_PF( " Screen: %.1f,%.1f -> %.1f,%.1f", screen0.x, screen0.y, screen1.x, screen1.y );
DL_PF( " Texture: %.1f,%.1f -> %.1f,%.1f", uv0.x, uv0.y, uv1.x, uv1.y );
#endif
const f32 depth = gRDPOtherMode.depth_source ? mPrimDepth : 0.0f;
const f32 depth {gRDPOtherMode.depth_source ? mPrimDepth : 0.0f};

#if 1 //1->SPRITE, 0->STRIP
DaedalusVtx * p_vertices = static_cast<DaedalusVtx *>(sceGuGetMemory(2 * sizeof(DaedalusVtx)));
Expand Down Expand Up @@ -1024,30 +1024,30 @@ void RendererPSP::Draw2DTextureBlit(f32 x, f32 y, f32 width, f32 height,
return;
}

f32 cur_v = v0;
f32 cur_y = y;
f32 v_end = v1;
f32 y_end = height;
f32 vslice = 512.f;
f32 ystep = (height/(v1-v0) * vslice);
f32 vstep = ((v1-v0) > 0 ? vslice : -vslice);
f32 cur_v {v0};
f32 cur_y {y};
f32 v_end {v1};
f32 y_end {height};
f32 vslice {512.f};
f32 ystep {(height/(v1-v0) * vslice)};
f32 vstep {(v1-v0) > 0 ? vslice : -vslice};

f32 x_end = width;
f32 uslice = 64.f;
f32 x_end {width};
f32 uslice {64.f};
//f32 ustep = (u1-u0)/width * xslice;
f32 xstep = (width/(u1-u0) * uslice);
f32 ustep = ((u1-u0) > 0 ? uslice : -uslice);
f32 xstep {(width/(u1-u0) * uslice)};
f32 ustep {(u1-u0) > 0 ? uslice : -uslice};

const u8* data = static_cast<const u8*>(texture->GetData());
const u8* data {static_cast<const u8*>(texture->GetData())};

for ( ; cur_y < y_end; cur_y+=ystep, cur_v+=vstep )
{
f32 cur_u = u0;
f32 cur_x = x;
f32 u_end = u1;
f32 cur_u {u0};
f32 cur_x {x};
f32 u_end {u1};

f32 poly_height = ((cur_y+ystep) > y_end) ? (y_end-cur_y) : ystep;
f32 source_height = vstep;
f32 poly_height {((cur_y+ystep) > y_end) ? (y_end-cur_y) : ystep};
f32 source_height {vstep};

// support negative vsteps
if ((vstep > 0) && (cur_v+vstep > v_end))
Expand All @@ -1059,7 +1059,7 @@ void RendererPSP::Draw2DTextureBlit(f32 x, f32 y, f32 width, f32 height,
source_height = (cur_v-v_end);
}

const u8* udata = data;
const u8* udata {data};
// blit maximizing the use of the texture-cache
for( ; cur_x < x_end; cur_x+=xstep, cur_u+=ustep )
{
Expand All @@ -1076,8 +1076,8 @@ void RendererPSP::Draw2DTextureBlit(f32 x, f32 y, f32 width, f32 height,
TextureVtx *p_verts = (TextureVtx*)sceGuGetMemory(2*sizeof(TextureVtx));

//f32 poly_width = ((cur_x+xstep) > x_end) ? (x_end-cur_x) : xstep;
f32 poly_width = xstep;
f32 source_width = ustep;
f32 poly_width {xstep};
f32 source_width {ustep};

// support negative usteps
if ((ustep > 0) && (cur_u+ustep > u_end))
Expand Down

0 comments on commit e9f95d3

Please sign in to comment.