游戏引擎有这个类:
class MouseListener{
public :
MouseListener();
virtual void OnMouseDown(int mx,int my);
virtual void OnMouseUp(int mx,int my);
.
.
.
};
Run Code Online (Sandbox Code Playgroud)
每个想要监听鼠标输入的对象都必须固有该类并覆盖它的方法.为了不必每次都声明一个新类型,该类被修改为:
class MouseListener{
public :
MouseListener();
std::function <void(MouseListener*,int,int)>OnMouseDown;
std::function <void(MouseListener*,int,int)>OnMouseUp;
.
.
.
};
Run Code Online (Sandbox Code Playgroud)
现在使用这个类可以这样做:
MouseListener * m = new MouseListener();
m->OnMouseDown = [](MouseListener * thiz,int x,int y){
//// do something
};
Run Code Online (Sandbox Code Playgroud)
在输入系统中,只调用非空(已分配)的MouseListener函数(使用thiz =鼠标侦听器).知道该类是从外部库(静态链接)使用的,这在性能方面更好吗?
注意:除非收到鼠标事件,否则不会调用这些函数,当发生这种情况时,会为每个听取鼠标输入的对象调用相应的函数(不应该是批次,<50)
在我工作的公司中,我们为其他公司提供了一个解决方案,我们希望每个公司都有一个该解决方案的单独实例,这包括一个单独的数据库实例,数据库是Firebase,这种选择创建一个新的单独实例根据我们工作所在国家/地区的数据隐私法,这是必需的。
我正在编写一个脚本,当新客户端注册触发时,它会开始创建新的解决方案实例,包括创建新Firebase项目,我正在使用firebase-tools CLI和gcloud CLI。
项目创建正确,并且管理员帐户已创建,唯一剩下的就是允许管理员能够登录新项目Firebase。这通常是Firebase web console通过启用登录提供程序(Email&Password在我的例子中是登录提供程序)手动完成的。这部分过程不是自动化的,因为我找不到应该传递给项目Firebase-tools或gcloud ClI在项目中启用登录提供程序的命令Firebase。
您可以传递什么命令来Firebase tools更改gcloud CLIfirebase 项目配置以启用登录提供程序?在这种情况下使用 登录Email&Passsword..或者有没有办法使用Google client libraries?
在这些条件下,我编写了下一个Singleton类:
1 - 我想要一个且只有一个类的实例存在并且可以从整个游戏引擎访问.
2 - Singleton被密集使用(每帧数千次)所以我不想写一个额外的GetInstance()函数,我试图避免任何额外的函数调用性能
3 - 一种可能性是让GetInstance()像内联一样这个 :
inline Singleton* Singleton::GetInstance()
{
static Singleton * singleton = new Singleton();
return singleton;
}
Run Code Online (Sandbox Code Playgroud)
但这会引起一个引用问题,每次调用时都会有一个对单例的新引用,用于修复用c ++编写的内容:
class Singleton{
private:
static Singleton* singleton;
Singleton(){}
public:
static inline Singleton* GetInstance() // now can be inlined !
{
return singleton;
}
static void Init()
{
// ofc i have to check first if this function
// is active only once
if(singleton != nullptr)
{
delete singleton;
}
singleton = new Singleton();
} …Run Code Online (Sandbox Code Playgroud)