目前,我的应用程序包含三种类型的类。它应该遵循面向数据的设计,如果不是,请纠正我。这是三种类型的类。代码示例并不那么重要,您可以根据需要跳过它们。他们只是为了给人留下印象。我的问题是,我应该向我的类型类添加方法吗?
类型只是保存值。
struct Person {
Person() : Walking(false), Jumping(false) {}
float Height, Mass;
bool Walking, Jumping;
};
Run Code Online (Sandbox Code Playgroud)
每个模块实现一个独特的功能。它们可以访问所有类型,因为它们是全局存储的。
class Renderer : public Module {
public:
void Init() {
// init opengl and glew
// ...
}
void Update() {
// fetch all instances of one type
unordered_map<uint64_t, *Model> models = Entity->Get<Model>();
for (auto i : models) {
uint64_t id = i.first;
Model *model = i.second;
// fetch single instance by id
Transform *transform = Entity->Get<Transform>(id);
// …Run Code Online (Sandbox Code Playgroud) 当然,Debug版本比Release版本慢.但是当我在Release模式下构建时,应用程序在从资源管理器中手动启动时比在Visual Studio中启动时执行得更好.例如,文件系统访问在我的项目中需要大约10倍.由于它是相同的可执行文件,我认为它应该运行相同的指令.
为什么在Visual Studio中启动Release版本如此之慢?如何获得完整的原生速度?
我正在寻找一个我想在我的PHP名称生成器脚本中使用的正则表达式模式.
它应检测该字符串是否包含三个连续的辅音.但如果三个连续辅音的两个连续辅音是相同的,它就不应该检测到弦.
例:
"hello" -> False, because there aren't 3 consecutive consonants.
"matching" -> True, because there are 3 consecutive consonants.
"apple" -> False, although there are 3 consecutive consonants, because two consecutive of them are the same.
Run Code Online (Sandbox Code Playgroud)
请帮我找到这样的正则表达式.
这个问题是关于使用 OpenGL 的图形应用程序。(当时我正在使用 GLFW 框架,但我考虑更改它。)
我的目标是让用户(尽可能多)在全屏模式和窗口模式之间不断切换。此过程应该花费不到一秒的时间,并且可以在运行时发生。例如,看看游戏《我的世界》,用户可以几乎没有延迟地切换全屏。
窗口重新创建过程并不需要太多时间。但问题是,关闭窗口会破坏我的 OpenGL 上下文,我必须重新加载所有着色器和缓冲区。
如何在不破坏 OpenGL 上下文的情况下重新创建图形应用程序的窗口?(我想使用 GLFW,但我对替代框架或自己的实现持开放态度。)
对于事件管理器,我需要在向量中存储许多指向函数的指针,以便在触发事件时调用它们.(我将在本问题的最后提供EventFunction助手类的源代码.)
// an event is defined by a string name and a number
typedef pair<string, int> EventKey;
// EventFunction holds a pointer to a listener function with or without data parameter
typedef unordered_map<EventKey, vector<EventFunction>> ListEvent;
// stores all events and their listeners
ListEvent List;
Run Code Online (Sandbox Code Playgroud)
注册侦听器可以通过调用第一个或第二个函数来完成,具体取决于您是否希望接收其他数据.(此代码来自我的事件管理器类.)
public:
typedef void (*EventFunctionPointer)();
typedef void (*EventFunctionPointerData)(void* Data);
// let components register for events by functions with or without data parameter,
// internally simple create a EventFunction object and call the private function
void …Run Code Online (Sandbox Code Playgroud) 目前,我通过帧缓冲区的 ID 和渲染目标的数量来存储帧缓冲区。但要绘制到帧缓冲区中,我需要使用设置正确的绘制缓冲区glDrawBuffers。现在我就这样做。
vector<GLenum> buffers;
for(int i = 0; i < targets; ++i)
{
buffers.push_back(GL_COLOR_ATTACHMENT0 + i);
}
glDrawBuffers(targets, &buffers[0]);
Run Code Online (Sandbox Code Playgroud)
为简单起见,我不想再自己存储渲染目标的数量。我想 OpenGL 无论如何都会这样做。有没有办法获取绑定到帧缓冲区的颜色附件,例如 using 调用glFramebufferTexture2D?
我想提供静态帮助函数来处理类的数据类型.我考虑将它们包含在课堂上.它们是为每个新的类实例实例化还是仅实例化一次?
有三种类型的序列,也就是说std::string,int,int.在C++中是否有一个模板允许函数将无限数量的序列作为参数?
Function("Peter", 27, 89,
"Max", 25, 72,
"Frank", 32, 94,
"David", 31, 98);
Run Code Online (Sandbox Code Playgroud) a中有一个静态成员struct,因为它在析构函数中是必需的.
struct Form
{
// ...
~Form()
{
// access World here
}
static btDynamicsWorld *World;
};
Run Code Online (Sandbox Code Playgroud)
有没有办法从另一个函数中初始化这个静态成员?
void ModulePhysics::Init()
{
// ...
btDynamicsWorld *Form::World = /* ... */;
}
Run Code Online (Sandbox Code Playgroud)
我当前的代码导致这两个编译器错误.
错误1错误C2655:'Form :: World':当前范围内的定义或重新声明非法
错误2错误C2086:'btDynamicsWorld*Form :: World':重新定义
从我读到的,静态文件应该由服务器直接提供,而不是使用Python和Django.但我需要限制文件访问上传它们的用户.遗憾的是,该文档没有关于提供用户在生产环境中上传的静态文件的部分.
如果我是对的,Facebook会使用难以猜测的长网址.这听起来像是一种合理的方法.如何在Django中自动生成长ID并将其用于上传的媒体文件?
c++ ×6
function ×2
opengl ×2
static ×2
architecture ×1
build ×1
c++11 ×1
django ×1
events ×1
framebuffer ×1
fullscreen ×1
graphics ×1
inheritance ×1
logic ×1
member ×1
methods ×1
parameters ×1
performance ×1
php ×1
random ×1
regex ×1
scope ×1
security ×1
static-files ×1
string ×1
templates ×1
window ×1