我基本上需要一个while循环才能仅以30“ FPS”运行。我被告知要这样做:“在while循环中,创建一个deltaT,如果该delT小于33毫秒,请使用sleep(33-deltaT)。”
但是我真的不太确定如何初始化增量/设置此变量的方式。我也无法从提出此建议的人那里得到答复。
我也不确定为什么睡眠中的值是33而不是30。
有谁知道我能做些什么?
这主要是为了使游戏服务器以30FPS的速度更新玩家,但是由于我没有在服务器上进行任何渲染,因此我需要一种方法来使代码处于睡眠状态,以限制每秒可以运行多少次,否则它将处理玩家的速度过快。
我正在尝试制作两个使用两个不同wndproc的窗口.我创建了两个单独的wndproc和两个单独的窗口类,它们指向自己的wndproc回调.
但由于某种原因,两个窗口都使用相同的wndproc ....我的第二个窗口应该在技术上使用WndProcControl,但它使用WndProc像我的第一个窗口是...
它为什么这样做?这是我的代码:
// Edit.cpp : Defines the entry point for the application.
//
#include "stdafx.h"
#include "TaylorSoundEditor.h"
#define MAX_LOADSTRING 100
// Global Variables:
HINSTANCE hInst; // current instance
TCHAR szTitle[MAX_LOADSTRING]; // The title bar text
TCHAR szControl[MAX_LOADSTRING]; //The title bar for the Control window
TCHAR szWindowClass[MAX_LOADSTRING]; // the main window class name
TCHAR szControlClass[MAX_LOADSTRING]; //the control window class name
// Forward declarations of functions included in this code module:
ATOM MyRegisterClass(HINSTANCE hInstance);
ATOM MyRegisterControlClass(HINSTANCE hInstance);
BOOL InitInstance(HINSTANCE, int); …Run Code Online (Sandbox Code Playgroud) 我正试图通过Windows上的关闭按钮检查控制台何时关闭.我读到了SetConsoleCtrlHandler,我以为我会使用它,但我想在主函数中做一些清理工作.我将举一个小例子来描述我想为我的大型程序做些什么.
BOOL CtrlHandler( DWORD fdwCtrlType )
{
switch( fdwCtrlType )
{
//Cleanup exit
case CTRL_CLOSE_EVENT:
bool* programIsOn = &???; //How do I pass the address to that variable in this function?
*programIsOn = false;
return( TRUE );
default:
return FALSE;
}
}
int main(){
MyObject obj = new MyObject();
bool programIsOn = true;
//How do I pass the address of programIsOn here?
if(!SetConsoleCtrlHandler( (PHANDLER_ROUTINE) CtrlHandler, TRUE )){
cout << "Could not set CtrlHandler. Exiting." << endl;
return 0;
}
while(programIsOn){ …Run Code Online (Sandbox Code Playgroud) 函数中的默认值到底是如何工作的?我的问题与这个例子有关:
int func(int number, std::string name = "None", int anotherNumber);
..
int func(int number, std::string name, int anotherNumber){
...
}
func(1, 2);
^Error, name is NULL yet we've defined a default value?
Run Code Online (Sandbox Code Playgroud)
编译器给出一个错误,抱怨参数为 NULL 并且不应该为 NULL。但我已经为其定义了默认值。
为什么是这样?