大作業中的部分殘廢代碼片demo
不太會看powershell的ps命令結果,要是有能拿到進程使用的精確到字節的內存大小的辦法的話再測試一下要不要換boost的reflect,,,
Reflect.hpp
#ifndef REFLECT_H
#define REFLECT_H
#include <PreCompile.h>
template<typename ClassName, typename KeyType, typename FuncType>
struct FuncReflectHelper final {
public:
explicit
FuncReflectHelper(QHash<KeyType, FuncType>& saver, KeyType&& key, FuncType func) {
std::cout << "construct\n";
saver[std::forward<KeyType>(key)] = func;
this->~FuncReflectHelper();
}
~FuncReflectHelper() {
std::cout << "destruct\n";
};
};
#endif // REFLECT_H
PokemonSkill.h
#ifndef POKEMONSKILL_H
#define POKEMONSKILL_H
#include <PreCompile.h>
#include <Reflect.hpp>
#define SKILL_FUNC_DEF(_func_) \
static void _func_(PokemonBase* user, PokemonBase* dest)
#define SKILL_FUNC(_func_) \
void PokemonSkill::_func_(PokemonBase* user, PokemonBase* dest)
#define REGISTER_METHOD(_method_) \
static FuncReflectHelper<PokemonSkill, QString, PokemonSkill::SkillFunc> \
_method_(PokemonSkill::s_skillMap, #_method_, &PokemonSkill::_method_); \
SKILL_FUNC(_method_) \
class PokemonBase;
class PokemonSkill {
public:
using SkillFunc = void(/*PokemonSkill::*/*)(PokemonBase*, PokemonBase*);
public FUNCTION:
PokemonSkill() = delete;
~PokemonSkill() = default;
static void
useSkillByName(
QString&& name,
PokemonBase* user = nullptr,
PokemonBase* dest = nullptr)
{
s_skillMap[name](user, dest);
}
SKILL_FUNC_DEF(FireBall);
SKILL_FUNC_DEF(GreassLeaf);
SKILL_FUNC_DEF(WaterBullet);
SKILL_FUNC_DEF(WindBreath);
public RESOURCE:
static
QHash<QString, SkillFunc>
s_skillMap;
static std::random_device rdev;
};
#endif // POKEMONSKILL_H
PokemonSkill.cpp
#include "PokemonSkill.h"
#define REGISTER_SKILL REGISTER_METHOD
QHash<QString, PokemonSkill::SkillFunc> PokemonSkill::s_skillMap = {};
REGISTER_SKILL(FireBall) {
std::cout << "FireBall!\n";
}
REGISTER_SKILL(GreassLeaf) {
std::cout << "GreassLeaf!\n";
}
REGISTER_SKILL(WaterBullet) {
std::cout << "WaterBullet!\n";
}
REGISTER_SKILL(WindBreath) {
std::cout << "WindBreath!\n";
}