ECS とデータ指向モデルを使用してエンジンを作成しています。呼び出しごとにキャッシュが破棄されるのを避けるために、継承と動的ディスパッチを回避しようとしていupdate()
ます。私が思いついたのはこれでした:
struct transformComponent {
const unsigned short id;
vecShort p;
transformComponent(unsigned short id, short x, short y): p(x, y), id(id) {}
transformComponent(unsigned short id): p(0, 0), id(id) {}
};
struct physicsComponent {
const unsigned short id;
unsigned short mass;
double invmass;
vecShort v, a, f;
physicsComponent(unsigned short id, unsigned short mass):
id(id), mass(mass), invmass(1/mass) {}
physicsComponent(unsigned short id): id(id) {}
};
//...
struct component {
enum compType {transform, physics, behavior, collision, rendering};
union {
transformComponent tra;
physicsComponent phy;
//...
};
template<typename ...argtypes>
component(compType type, unsigned short id, argtypes... args) {
switch(type) {
case transform:
tra(id, std::forward<argtypes>(args)...);
break;
case physics:
phy(id, std::forward<argtypes>(args)...);
break;
//...
}
}
};
次にroom
、メモリ プールを介してすべてのシステムとコンポーネントを保持するクラス (マネージャ) を作成します。問題は、
template<typename ...argtypes>
component(compType type, unsigned short id, argtypes... args) {
switch(type) {
case transform:
tra(id, std::forward<argtypes>(args)...);
break;
コンパイラが不平を言う部分:
src\inc/components.h: In instantiation of 'component::component(component::compType, short unsigned
int, argtypes ...) [with argtypes = {}]':
src\inc/components.h:94:71: required from here
src\inc/components.h:57:5: error: no match for call to '(transformComponent) (short unsigned int&)'
57 | tra(id, std::forward<argtypes>(args)...);
| ^~~
楕円を動かそうとしましたが、効果がありませんでした。私が本質的にやろうとしているのは、すべてのフレームでテンプレートと動的ディスパッチの両方を使用しないようにすることですが、初期化にはテンプレートが必要です。基本的な構文が間違っていますか? 私は何かを完全に見逃していますか?私はデータ指向のパラダイムに慣れていないので、喜んでアドバイスをいたします。最小限の再現可能な例: https://godbolt.org/z/zGAfXS