English 中文(简体)
添加到阵列C++
原标题:Adding to arrays C++

只是想知道,我将如何以下列方式为阵列添加插头;

我正为我的游戏制定平均框架,但从我所理解的,如果我创造一系列[10],我就没有本土办法在阵列的开始中增加一些。

我想这样做。

myInt[0] = 60
myInt[1] = 59
myInt[2] = 61

我要说的是,在我的Int[0]上加上30处,并且把目前的IInt[0] —— *** 和 l —— 1-2. ,因此,它只是把所有事情推向一线,并从阵列中 drop掉最后的愤怒。

我迄今为止试图做的只是改动[0],使我的平均计算无用。 另外,利用SDL_GetTicks()来挽救目前已经过去的时间。

Is there a better way to do average framerate?

问题回答

如你想要通知。 我将调查“%”的操作者,并附有对照框架。 你的框架反常,你更新了我的Int[框架_counter % MY_INT_LENGTH],然后绘制了由MY_INT_LENGTH缩小我Int和分裂的地图。

我建议,将最后8或16个框架比率而不是10。 这使 mo经营人成为一片面罩。

EDIT

如果你想要达到平均基准率,那么你应该真正做到的是检查三角体。

在您的校对或观察员的旁观中,每个框架都起到了反作用。 然后问到,时间差异究竟有多少框架和差距。 你们可以轻率地调查平均框架,并重新制定投票框架。

st:主子是你应该使用而不是阵列的东西,尽管如此:

快速/中文本显示如何发挥作用:

int sum = 0; // should be wrapped in a class or something
const int max_size = 10;

void add(std::queue<int>& q, int fps) {
  q.push(fps);
  if(q.size() > max_size) {
    sum -= q.front();
    q.pop();
  }
  sum += fps;
}

int avg(std::queue<int>& q) {
  return sum / q.size();
}

//...

std::queue<int> myQ;
add(myQ, 60);
add(myQ, 61);
add(myQ, 50);
std::cout << avg(myQ);

你们应当能够看到你似乎理解的方法。

是否有更好的方式来平均制定计划?

Why yes....

在此,我以前曾使用过一些密码,以跟踪录像带应用的“框架率”。 该文件是供视窗阅读的。 如果您使用Windows,则将以下所有“DWORD”类型改为“未签署。 用SDL_getps()功能取代“GetTickCount”电话。 它非常直截了当。 每当你提出一个新的框架时,就呼吁阵线。 每当你们想要知道它时,就要叫GetFrameRate。

class CFrameRateMonitor
{
private:
    static const DWORD DEFAULT_INTERVAL = 2000;
    bool m_fFirstFrame;
    DWORD m_dwInterval;  // how often we recompute the average
    DWORD m_dwFrames;
    DWORD m_dwStartTime;
    DWORD m_dwComputedRate;
public:
    CFrameRateMonitor();

    void Reset();
    void OnFrame();
    DWORD GetFrameRate();
    void SetInterval(DWORD dwInterval);
};



CFrameRateMonitor::CFrameRateMonitor()
{
    Reset();
    m_dwInterval = DEFAULT_INTERVAL;
}

void CFrameRateMonitor::SetInterval(DWORD dwInterval)
{
    m_dwInterval = dwInterval;
}

void CFrameRateMonitor::Reset()
{
    m_dwFrames = 0;
    m_dwStartTime = 0;
    m_dwComputedRate = 0;
    m_fFirstFrame = true;
}

DWORD CFrameRateMonitor::GetFrameRate()
{
    return m_dwComputedRate;
}

void CFrameRateMonitor::OnFrame()
{
    DWORD dwCurrentTime = GetTickCount();
    DWORD dwActualInterval = dwCurrentTime - m_dwStartTime;

    if (m_fFirstFrame)
    {
        m_dwStartTime = dwCurrentTime;
        m_fFirstFrame = false;
    }
    else
    {
        m_dwFrames++;
        if (dwActualInterval >= m_dwInterval)
        {
            // enough time has passed to compute a new interval
            // + 500 to "round up"
            m_dwComputedRate = (m_dwFrames * 1000 + 500) / dwActualInterval; 
            // reset counting
            m_dwStartTime = dwCurrentTime;
            m_dwFrames = 0;
        }
    }
}




相关问题
Undefined reference

I m getting this linker error. I know a way around it, but it s bugging me because another part of the project s linking fine and it s designed almost identically. First, I have namespace LCD. Then I ...

C++ Equivalent of Tidy

Is there an equivalent to tidy for HTML code for C++? I have searched on the internet, but I find nothing but C++ wrappers for tidy, etc... I think the keyword tidy is what has me hung up. I am ...

Template Classes in C++ ... a required skill set?

I m new to C++ and am wondering how much time I should invest in learning how to implement template classes. Are they widely used in industry, or is this something I should move through quickly?

Print possible strings created from a Number

Given a 10 digit Telephone Number, we have to print all possible strings created from that. The mapping of the numbers is the one as exactly on a phone s keypad. i.e. for 1,0-> No Letter for 2->...

typedef ing STL wstring

Why is it when i do the following i get errors when relating to with wchar_t? namespace Foo { typedef std::wstring String; } Now i declare all my strings as Foo::String through out the program, ...

C# Marshal / Pinvoke CBitmap?

I cannot figure out how to marshal a C++ CBitmap to a C# Bitmap or Image class. My import looks like this: [DllImport(@"test.dll", CharSet = CharSet.Unicode)] public static extern IntPtr ...

Window iconification status via Xlib

Is it possible to check with the means of pure X11/Xlib only whether the given window is iconified/minimized, and, if it is, how?

热门标签