1
This commit is contained in:
parent
0ff472e8e9
commit
3d912791f6
@ -2,12 +2,31 @@
|
||||
|
||||
#include "mt/MetaMgr.h"
|
||||
#include "mt/Param.h"
|
||||
#include "app.h"
|
||||
|
||||
namespace mt
|
||||
{
|
||||
|
||||
void MetaMgr::Init()
|
||||
{
|
||||
if (!f8::IsOnlineEnv()) {
|
||||
if (f8::IsTestEnv()) {
|
||||
res_path_ = a8::Format("../../../conf_test/game%d/gameserver.test/res%d/",
|
||||
{
|
||||
GAME_ID,
|
||||
App::Instance()->instance_id
|
||||
});
|
||||
} else {
|
||||
res_path_ = a8::Format("../../../conf_test/game%d/gameserver.dev/res%d/",
|
||||
{
|
||||
GAME_ID,
|
||||
App::Instance()->instance_id
|
||||
});
|
||||
}
|
||||
} else {
|
||||
res_path_ = "../res/";
|
||||
}
|
||||
|
||||
RegMetaTable<Param>();
|
||||
}
|
||||
|
||||
|
@ -133,6 +133,7 @@ namespace mt
|
||||
|
||||
private:
|
||||
std::vector<MetaTable*> meta_tables;
|
||||
std::string res_path_;
|
||||
};
|
||||
|
||||
}
|
||||
|
@ -1,50 +1,14 @@
|
||||
#pragma once
|
||||
|
||||
#include "mt/macro.h"
|
||||
#include "mtb/Parameter.h"
|
||||
|
||||
namespace mt
|
||||
{
|
||||
|
||||
#define DECLARE_COMMON_HEAD(classname, base, filename, key, tbl_type) \
|
||||
class classname : public base \
|
||||
{ \
|
||||
protected: \
|
||||
friend class MetaMgr; \
|
||||
static constexpr int table_type = tbl_type; \
|
||||
static constexpr const char* prim_key = #key; \
|
||||
static constexpr const char* table_name= #filename; \
|
||||
static std::vector<classname*> raw_list; \
|
||||
static std::map<long long, classname*> id_hash; \
|
||||
static std::map<std::string, classname*> name_hash;
|
||||
|
||||
#define DECLARE_ID_TABLE(classname, base, filename, key) \
|
||||
DECLARE_COMMON_HEAD(classname, base, filename, key, 1) \
|
||||
public: \
|
||||
static classname* GetById(long long id) \
|
||||
{ \
|
||||
auto itr = id_hash.find(id); \
|
||||
return itr != id_hash.end() ? itr->second : nullptr; \
|
||||
};
|
||||
|
||||
#define DECLARE_AUTO_ID_TABLE(classname, base, filename) \
|
||||
DECLARE_COMMON_HEAD(classname, base, filename, key, 0) \
|
||||
public: \
|
||||
static classname* GetById(long long id) \
|
||||
{ \
|
||||
auto itr = id_hash.find(id); \
|
||||
return itr != id_hash.end() ? itr->second : nullptr; \
|
||||
};
|
||||
|
||||
#define DECLARE_NAME_TABLE(classname, base, filename, key) \
|
||||
DECLARE_COMMON_HEAD(classname, base, filename, key, 2) \
|
||||
public: \
|
||||
static classname* GetByName(const std::string& name) \
|
||||
{ \
|
||||
auto itr = name_hash.find(name); \
|
||||
return itr != name_hash.end() ? itr->second : nullptr; \
|
||||
};
|
||||
|
||||
DECLARE_ID_TABLE(Param, mtb::Parameter, "", "")
|
||||
DECLARE_ID_TABLE(Param, mtb::Parameter,
|
||||
"parameter@parameter.csv",
|
||||
"param_name")
|
||||
public:
|
||||
int gas_inactive_time = 10;
|
||||
float kill_param = 0.0f;
|
||||
|
40
server/gameserver/mt/macro.h
Normal file
40
server/gameserver/mt/macro.h
Normal file
@ -0,0 +1,40 @@
|
||||
#pragma once
|
||||
|
||||
#define DECLARE_COMMON_HEAD(classname, base, filename, key, tbl_type) \
|
||||
class classname : public base \
|
||||
{ \
|
||||
protected: \
|
||||
friend class MetaMgr; \
|
||||
static constexpr int table_type = tbl_type; \
|
||||
static constexpr const char* prim_key = #key; \
|
||||
static constexpr const char* table_name= #filename; \
|
||||
static std::vector<classname*> raw_list; \
|
||||
static std::map<long long, classname*> id_hash; \
|
||||
static std::map<std::string, classname*> name_hash;
|
||||
|
||||
#define DECLARE_ID_TABLE(classname, base, filename, key) \
|
||||
DECLARE_COMMON_HEAD(classname, base, filename, key, 1) \
|
||||
public: \
|
||||
static classname* GetById(long long id) \
|
||||
{ \
|
||||
auto itr = id_hash.find(id); \
|
||||
return itr != id_hash.end() ? itr->second : nullptr; \
|
||||
};
|
||||
|
||||
#define DECLARE_AUTO_ID_TABLE(classname, base, filename) \
|
||||
DECLARE_COMMON_HEAD(classname, base, filename, key, 0) \
|
||||
public: \
|
||||
static classname* GetById(long long id) \
|
||||
{ \
|
||||
auto itr = id_hash.find(id); \
|
||||
return itr != id_hash.end() ? itr->second : nullptr; \
|
||||
};
|
||||
|
||||
#define DECLARE_NAME_TABLE(classname, base, filename, key) \
|
||||
DECLARE_COMMON_HEAD(classname, base, filename, key, 2) \
|
||||
public: \
|
||||
static classname* GetByName(const std::string& name) \
|
||||
{ \
|
||||
auto itr = name_hash.find(name); \
|
||||
return itr != name_hash.end() ? itr->second : nullptr; \
|
||||
};
|
Loading…
x
Reference in New Issue
Block a user