Remove restriction for CGraph::MAX_VALUES to be a power of two

By using `% MAX_VALUES` instead of `& (MAX_VALUES - 1)` to wrap the index. Both work the same, but the latter only does for powers of two.
This commit is contained in:
Robert Müller 2022-08-12 14:08:30 +02:00
parent b314db5454
commit 3daa177830
2 changed files with 3 additions and 4 deletions

View file

@ -104,7 +104,7 @@ void CGraph::Scale()
void CGraph::Add(float v, float r, float g, float b)
{
m_Index = (m_Index + 1) & (MAX_VALUES - 1);
m_Index = (m_Index + 1) % MAX_VALUES;
m_aValues[m_Index] = v;
m_aColors[m_Index][0] = r;
m_aColors[m_Index][1] = g;
@ -149,8 +149,8 @@ void CGraph::Render(IGraphics *pGraphics, IGraphics::CTextureHandle FontTexture,
{
float a0 = (i - 1) / (float)MAX_VALUES;
float a1 = i / (float)MAX_VALUES;
int i0 = (m_Index + i - 1) & (MAX_VALUES - 1);
int i1 = (m_Index + i) & (MAX_VALUES - 1);
int i0 = (m_Index + i - 1) % MAX_VALUES;
int i1 = (m_Index + i) % MAX_VALUES;
float v0 = (m_aValues[i0] - m_Min) / (m_Max - m_Min);
float v1 = (m_aValues[i1] - m_Min) / (m_Max - m_Min);

View file

@ -44,7 +44,6 @@ class CGraph
public:
enum
{
// restrictions: Must be power of two
MAX_VALUES = 128,
};