2
0
mirror of https://github.com/rehlds/metamod-r.git synced 2025-01-13 23:28:23 +03:00

Refactoring

This commit is contained in:
asmodai 2017-05-05 19:36:56 +03:00
parent 29b0f402f1
commit f667a85282
9 changed files with 33 additions and 41 deletions

View File

@ -23,7 +23,7 @@ option_t *MConfig::find(const char* lookup) const
} }
} }
return NULL; return nullptr;
} }
bool MConfig::set(const char* key, const char* value) const bool MConfig::set(const char* key, const char* value) const
@ -97,18 +97,16 @@ bool MConfig::set(option_t* setp, const char* setstr)
bool MConfig::load(const char* fn) bool MConfig::load(const char* fn)
{ {
FILE* fp;
char loadfile[PATH_MAX]; char loadfile[PATH_MAX];
char line[MAX_CONF_LEN]; char line[MAX_CONF_LEN];
char *optname, *optval; char *optname, *optval;
option_t* optp; option_t* optp;
int ln;
// Make full pathname (from gamedir if relative, collapse "..", // Make full pathname (from gamedir if relative, collapse "..",
// backslashes, etc). // backslashes, etc).
full_gamedir_path(fn, loadfile); full_gamedir_path(fn, loadfile);
fp = fopen(loadfile, "r"); FILE* fp = fopen(loadfile, "r");
if (!fp) if (!fp)
{ {
META_ERROR("unable to open config file '%s': %s", loadfile, strerror(errno)); META_ERROR("unable to open config file '%s': %s", loadfile, strerror(errno));
@ -116,7 +114,7 @@ bool MConfig::load(const char* fn)
} }
META_DEBUG(2, "Loading from config file: %s", loadfile); META_DEBUG(2, "Loading from config file: %s", loadfile);
for (ln = 1; !feof(fp) && fgets(line, sizeof line, fp); ln++) for (int ln = 1; !feof(fp) && fgets(line, sizeof line, fp); ln++)
{ {
if (line[0] == '#' || line[0] == ';' || !Q_strncmp(line, "//", 2)) if (line[0] == '#' || line[0] == ';' || !Q_strncmp(line, "//", 2))
continue; continue;
@ -127,7 +125,7 @@ bool MConfig::load(const char* fn)
continue; continue;
} }
if (!(optval = strtok(NULL, "\r\n"))) if (!(optval = strtok(nullptr, "\r\n")))
{ {
META_ERROR("'%s' line %d: bad config format: missing value", loadfile, ln); META_ERROR("'%s' line %d: bad config format: missing value", loadfile, ln);
continue; continue;
@ -183,7 +181,7 @@ void MConfig::show() const
void MConfig::set_directory() void MConfig::set_directory()
{ {
#ifdef _WIN32 #ifdef _WIN32
HMODULE hModule = NULL; HMODULE hModule = nullptr;
GetModuleHandleEx(GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS | GET_MODULE_HANDLE_EX_FLAG_UNCHANGED_REFCOUNT, (LPCTSTR)GiveFnptrsToDll, &hModule); GetModuleHandleEx(GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS | GET_MODULE_HANDLE_EX_FLAG_UNCHANGED_REFCOUNT, (LPCTSTR)GiveFnptrsToDll, &hModule);
GetModuleFileName(hModule, m_directory, sizeof m_directory); GetModuleFileName(hModule, m_directory, sizeof m_directory);
#else #else

View File

@ -45,10 +45,6 @@ private:
option_t *find(const char *lookup) const; option_t *find(const char *lookup) const;
static bool set(option_t *setp, const char *value); static bool set(option_t *setp, const char *value);
// Private; to satisfy -Weffc++ "has pointer data members but does
// not override" copy/assignment constructor.
void operator=(const MConfig &src);
MConfig(const MConfig &src);
}; };
inline const char *MConfig::directory() const inline const char *MConfig::directory() const

View File

@ -14,7 +14,7 @@ const game_modinfo_t g_known_games[] = {
{ "czero", "cs.so", "mp.dll", "Counter-Strike:Condition Zero" }, { "czero", "cs.so", "mp.dll", "Counter-Strike:Condition Zero" },
// End of list terminator: // End of list terminator:
{ NULL, NULL, NULL, NULL } { nullptr, nullptr, nullptr, nullptr }
}; };
// Find a modinfo corresponding to the given game name. // Find a modinfo corresponding to the given game name.

View File

@ -884,7 +884,7 @@ struct Backend
size_t buffsize_; size_t buffsize_;
size_t size_; size_t size_;
Backend(void* pbuff = NULL, size_t buffsize = 0) : pbuff_((uint8*) pbuff), buffsize_(buffsize), size_(0) Backend(void* pbuff = nullptr, size_t buffsize = 0) : pbuff_((uint8*) pbuff), buffsize_(buffsize), size_(0)
{ {
memset(pbuff, 0xCC, buffsize); // INT3 memset(pbuff, 0xCC, buffsize); // INT3
} }
@ -1323,7 +1323,7 @@ namespace detail
size_t buffsize_; size_t buffsize_;
public: public:
CodeBuffer() : pbuff_(NULL), codesize_(0), buffsize_(0) {} CodeBuffer() : pbuff_(nullptr), codesize_(0), buffsize_(0) {}
~CodeBuffer() {Reset(0);} ~CodeBuffer() {Reset(0);}
void* GetPointer() const {return pbuff_;} void* GetPointer() const {return pbuff_;}
@ -1338,13 +1338,13 @@ namespace detail
#else #else
munmap(pbuff_, buffsize_); munmap(pbuff_, buffsize_);
#endif #endif
pbuff_ = NULL; pbuff_ = nullptr;
codesize_ = 0; codesize_ = 0;
buffsize_ = 0; buffsize_ = 0;
} }
if (codesize) { if (codesize) {
#if defined(JITASM_WIN) #if defined(JITASM_WIN)
void* pbuff = ::VirtualAlloc(NULL, codesize, MEM_COMMIT, PAGE_EXECUTE_READWRITE); void* pbuff = ::VirtualAlloc(nullptr, codesize, MEM_COMMIT, PAGE_EXECUTE_READWRITE);
if (!pbuff) { if (!pbuff) {
JITASM_ASSERT(0); JITASM_ASSERT(0);
return false; return false;
@ -1355,7 +1355,7 @@ namespace detail
#else #else
int pagesize = getpagesize(); int pagesize = getpagesize();
size_t buffsize = (codesize + pagesize - 1) / pagesize * pagesize; size_t buffsize = (codesize + pagesize - 1) / pagesize * pagesize;
void* pbuff = mmap(NULL, buffsize, PROT_READ | PROT_WRITE | PROT_EXEC, MAP_PRIVATE | MAP_ANON, -1, 0); void* pbuff = mmap(nullptr, buffsize, PROT_READ | PROT_WRITE | PROT_EXEC, MAP_PRIVATE | MAP_ANON, -1, 0);
if (!pbuff) { if (!pbuff) {
JITASM_ASSERT(0); JITASM_ASSERT(0);
return false; return false;
@ -5584,7 +5584,7 @@ namespace compiler
} }
// build interval // build interval
BitVector *last_liveness = NULL; BitVector *last_liveness = nullptr;
std::vector<uint32> reg_assignables; std::vector<uint32> reg_assignables;
bool last_reg_constraints = false; bool last_reg_constraints = false;
bool last_stack_vars = false; bool last_stack_vars = false;
@ -5648,7 +5648,7 @@ namespace compiler
for (size_t v = 0; v < use_points.size(); ++v) { for (size_t v = 0; v < use_points.size(); ++v) {
RegUsePointRange range(use_points[v]); RegUsePointRange range(use_points[v]);
for (size_t i = 0; i < intervals.size(); ++i) { for (size_t i = 0; i < intervals.size(); ++i) {
const Interval *next_interval = i + 1 < intervals.size() ? &intervals[i + 1] : NULL; const Interval *next_interval = i + 1 < intervals.size() ? &intervals[i + 1] : nullptr;
intervals[i].UpdateUse(v, range, next_interval); intervals[i].UpdateUse(v, range, next_interval);
} }
} }
@ -5664,7 +5664,7 @@ namespace compiler
for (size_t v = 0; v < use_points.size(); ++v) { for (size_t v = 0; v < use_points.size(); ++v) {
RegUsePointRange range(use_points[v]); RegUsePointRange range(use_points[v]);
for (size_t i = interval_idx; i < interval_idx + 2; ++i) { for (size_t i = interval_idx; i < interval_idx + 2; ++i) {
const Interval *next_interval = i + 1 < intervals.size() ? &intervals[i + 1] : NULL; const Interval *next_interval = i + 1 < intervals.size() ? &intervals[i + 1] : nullptr;
intervals[i].UpdateUse(v, range, next_interval); intervals[i].UpdateUse(v, range, next_interval);
} }
} }
@ -5921,7 +5921,7 @@ namespace compiler
size_t loop_depth; ///< Loop nesting depth size_t loop_depth; ///< Loop nesting depth
Lifetime lifetime[3]; ///< Variable lifetime (0: GP, 1: MMX, 2: XMM/YMM) Lifetime lifetime[3]; ///< Variable lifetime (0: GP, 1: MMX, 2: XMM/YMM)
BasicBlock(size_t instr_begin_, size_t instr_end_, BasicBlock *successor0 = NULL, BasicBlock *successor1 = NULL) : instr_begin(instr_begin_), instr_end(instr_end_), depth((size_t)-1), dfs_parent(NULL), immediate_dominator(NULL), loop_depth(0) { BasicBlock(size_t instr_begin_, size_t instr_end_, BasicBlock *successor0 = nullptr, BasicBlock *successor1 = nullptr) : instr_begin(instr_begin_), instr_end(instr_end_), depth((size_t)-1), dfs_parent(nullptr), immediate_dominator(nullptr), loop_depth(0) {
successor[0] = successor0; successor[0] = successor0;
successor[1] = successor1; successor[1] = successor1;
} }
@ -6054,7 +6054,7 @@ namespace compiler
dom[w] = dom[dom[w]]; dom[w] = dom[dom[w]];
depth_first_blocks[w]->immediate_dominator = depth_first_blocks[dom[w]]; depth_first_blocks[w]->immediate_dominator = depth_first_blocks[dom[w]];
} }
depth_first_blocks[0]->immediate_dominator = NULL; depth_first_blocks[0]->immediate_dominator = nullptr;
} }
}; };
@ -6156,7 +6156,7 @@ namespace compiler
new_block->successor[1] = target_block->successor[1]; new_block->successor[1] = target_block->successor[1];
new_block->predecessor.push_back(target_block); new_block->predecessor.push_back(target_block);
target_block->successor[0] = new_block; target_block->successor[0] = new_block;
target_block->successor[1] = NULL; target_block->successor[1] = nullptr;
target_block->instr_end = instr_idx; target_block->instr_end = instr_idx;
// replace predecessor of successors // replace predecessor of successors
@ -6584,14 +6584,14 @@ namespace compiler
} }
uint32 used_reg = 0; uint32 used_reg = 0;
const Lifetime::Interval *last_interval = NULL; const Lifetime::Interval *last_interval = nullptr;
size_t last_loop_depth = 0; size_t last_loop_depth = 0;
for (ControlFlowGraph::BlockList::iterator block = cfg.dfs_begin(); block != cfg.dfs_end(); ++block) { for (ControlFlowGraph::BlockList::iterator block = cfg.dfs_begin(); block != cfg.dfs_end(); ++block) {
Lifetime& lifetime = (*block)->lifetime[reg_family]; Lifetime& lifetime = (*block)->lifetime[reg_family];
const size_t loop_depth = (*block)->loop_depth; const size_t loop_depth = (*block)->loop_depth;
// Spill identification // Spill identification
lifetime.SpillIdentification(available_reg_count, total_spill_cost, (*block)->GetFrequency(), last_loop_depth == loop_depth ? last_interval : NULL, var_attrs); lifetime.SpillIdentification(available_reg_count, total_spill_cost, (*block)->GetFrequency(), last_loop_depth == loop_depth ? last_interval : nullptr, var_attrs);
// Register assignment // Register assignment
used_reg |= lifetime.AssignRegister(available_reg, last_interval); used_reg |= lifetime.AssignRegister(available_reg, last_interval);

View File

@ -150,7 +150,6 @@ void metamod_startup()
// until later. // until later.
if (g_config->m_debuglevel != 0) if (g_config->m_debuglevel != 0)
CVAR_SET_FLOAT("meta_debug", g_config->m_debuglevel); CVAR_SET_FLOAT("meta_debug", g_config->m_debuglevel);
if (!g_config->m_clientmeta) if (!g_config->m_clientmeta)
disable_clientcommand_fwd(); disable_clientcommand_fwd();

View File

@ -243,7 +243,7 @@ MPlugin* MPluginList::add(MPlugin* padd)
if (!iplug) if (!iplug)
{ {
META_ERROR("Couldn't add plugin '%s' to list; reached max plugins (%d)", padd->m_file, MAX_PLUGINS); META_ERROR("Couldn't add plugin '%s' to list; reached max plugins (%d)", padd->m_file, MAX_PLUGINS);
return NULL; return nullptr;
} }
// copy filename into this free slot // copy filename into this free slot
@ -321,7 +321,7 @@ bool MPluginList::ini_startup()
// Check for a matching platform with different platform specifics // Check for a matching platform with different platform specifics
// level. // level.
if (NULL != (pmatch = find_match(&m_plist[n]))) if (nullptr != (pmatch = find_match(&m_plist[n])))
{ {
if (pmatch->m_pfspecific >= m_plist[n].m_pfspecific) if (pmatch->m_pfspecific >= m_plist[n].m_pfspecific)
{ {
@ -390,7 +390,7 @@ bool MPluginList::ini_refresh()
{ {
// Check for a matching platform with higher platform specifics // Check for a matching platform with higher platform specifics
// level. // level.
if (NULL != (pl_found = find_match(&pl_temp))) if (nullptr != (pl_found = find_match(&pl_temp)))
{ {
if (pl_found->m_pfspecific >= pl_temp.m_pfspecific) if (pl_found->m_pfspecific >= pl_temp.m_pfspecific)
{ {

View File

@ -133,7 +133,7 @@ const char* CSysModule::getloaderror()
const char *str_GetLastError() const char *str_GetLastError()
{ {
static char buf[MAX_STRBUF_LEN]; static char buf[MAX_STRBUF_LEN];
FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS, NULL, GetLastError(), MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), (LPTSTR)&buf, MAX_STRBUF_LEN - 1, NULL); FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS, nullptr, GetLastError(), MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), (LPTSTR)&buf, MAX_STRBUF_LEN - 1, nullptr);
return buf; return buf;
} }
#endif #endif

View File

@ -45,7 +45,7 @@ void UTIL_HudMessage(edict_t *pEntity, const hudtextparms_t &textparms, const ch
if (FNullEnt(pEntity) || pEntity->free) if (FNullEnt(pEntity) || pEntity->free)
return; return;
MESSAGE_BEGIN(MSG_ONE, SVC_TEMPENTITY, NULL, pEntity); MESSAGE_BEGIN(MSG_ONE, SVC_TEMPENTITY, nullptr, pEntity);
WRITE_BYTE(TE_TEXTMESSAGE); WRITE_BYTE(TE_TEXTMESSAGE);
WRITE_BYTE(textparms.channel & 0xFF); WRITE_BYTE(textparms.channel & 0xFF);

View File

@ -17,7 +17,7 @@ char* ENTITY_KEYVALUE(edict_t* entity, char* key)
const char* LOCALINFO(char* key) const char* LOCALINFO(char* key)
{ {
return ENTITY_KEYVALUE(NULL, key); return ENTITY_KEYVALUE(nullptr, key);
} }
static_allocator::static_allocator(memory_protection protection) : m_protection(protection) static_allocator::static_allocator(memory_protection protection) : m_protection(protection)
@ -61,9 +61,9 @@ size_t static_allocator::memory_used() const
void static_allocator::allocate_page() void static_allocator::allocate_page()
{ {
#ifdef WIN32 #ifdef WIN32
auto page = VirtualAlloc(NULL, Pagesize, MEM_COMMIT, PAGE_EXECUTE_READWRITE); auto page = VirtualAlloc(nullptr, Pagesize, MEM_COMMIT, PAGE_EXECUTE_READWRITE);
#else #else
auto page = mmap(NULL, Pagesize, PROT_READ | PROT_WRITE | PROT_EXEC, MAP_ANONYMOUS | MAP_PRIVATE, 0, 0); auto page = mmap(nullptr, Pagesize, PROT_READ | PROT_WRITE | PROT_EXEC, MAP_ANONYMOUS | MAP_PRIVATE, 0, 0);
#endif #endif
m_used = 0; m_used = 0;
@ -103,7 +103,7 @@ char *trimbuf(char *str)
{ {
char *ibuf; char *ibuf;
if (str == NULL) return NULL; if (str == nullptr) return nullptr;
for (ibuf = str; *ibuf && (byte)(*ibuf) < (byte)0x80 && isspace(*ibuf); ++ibuf) for (ibuf = str; *ibuf && (byte)(*ibuf) < (byte)0x80 && isspace(*ibuf); ++ibuf)
; ;
@ -147,20 +147,19 @@ bool IsAbsolutePath(const char *path)
#ifdef _WIN32 #ifdef _WIN32
char *realpath(const char *file_name, char *resolved_name) char *realpath(const char *file_name, char *resolved_name)
{ {
int ret = GetFullPathName(file_name, PATH_MAX, resolved_name, NULL); int ret = GetFullPathName(file_name, PATH_MAX, resolved_name, nullptr);
if (ret > PATH_MAX) { if (ret > PATH_MAX) {
errno = ENAMETOOLONG; errno = ENAMETOOLONG;
return NULL; return nullptr;
} }
if (ret > 0) { if (ret > 0) {
HANDLE handle;
WIN32_FIND_DATA find_data; WIN32_FIND_DATA find_data;
handle = FindFirstFile(resolved_name, &find_data); HANDLE handle = FindFirstFile(resolved_name, &find_data);
if (INVALID_HANDLE_VALUE == handle) { if (INVALID_HANDLE_VALUE == handle) {
errno = ENOENT; errno = ENOENT;
return NULL; return nullptr;
} }
FindClose(handle); FindClose(handle);
@ -168,6 +167,6 @@ char *realpath(const char *file_name, char *resolved_name)
return resolved_name; return resolved_name;
} }
return NULL; return nullptr;
} }
#endif // _WIN32 #endif // _WIN32