From 2c5520cad0f63365be8eb3691920c8a2e5f8c4f8 Mon Sep 17 00:00:00 2001 From: David Anderson Date: Fri, 17 Mar 2006 22:50:13 +0000 Subject: [PATCH] added optimization tweaker added binary log maxsize support --- amxmodx/binlog.cpp | 15 +++++++++++++++ amxmodx/binlog.h | 1 + amxmodx/meta_api.cpp | 6 ++++++ amxmodx/modules.cpp | 5 ++++- amxmodx/optimizer.cpp | 27 +++++++++++++++++++-------- amxmodx/optimizer.h | 2 ++ 6 files changed, 47 insertions(+), 9 deletions(-) diff --git a/amxmodx/binlog.cpp b/amxmodx/binlog.cpp index 515c53eb..6965ff10 100644 --- a/amxmodx/binlog.cpp +++ b/amxmodx/binlog.cpp @@ -6,6 +6,7 @@ BinLog g_BinLog; int g_binlog_level = 0; +int g_binlog_maxsize = 0; bool BinLog::Open() { @@ -61,6 +62,20 @@ void BinLog::WriteOp(BinLogOp op, int plug, ...) if (!fp) return; + if (g_binlog_maxsize) + { + fseek(fp, 0, SEEK_END); + if (ftell(fp) > (g_binlog_maxsize * (1024 * 1024))) + { + fclose(fp); + Close(); + Open(); + fp = fopen(m_logfile.c_str(), "ab"); + if (!fp) + return; + } + } + unsigned char c = static_cast(op); time_t t = time(NULL); float gt = gpGlobals->time; diff --git a/amxmodx/binlog.h b/amxmodx/binlog.h index 733ba113..cf417011 100644 --- a/amxmodx/binlog.h +++ b/amxmodx/binlog.h @@ -69,6 +69,7 @@ private: extern BinLog g_BinLog; extern int g_binlog_level; +extern int g_binlog_maxsize; #endif //BINLOG_ENABLED diff --git a/amxmodx/meta_api.cpp b/amxmodx/meta_api.cpp index 818ca854..c9447b33 100755 --- a/amxmodx/meta_api.cpp +++ b/amxmodx/meta_api.cpp @@ -40,6 +40,7 @@ #include "newmenus.h" #include "natives.h" #include "binlog.h" +#include "optimizer.h" plugin_info_t Plugin_info = { @@ -305,8 +306,13 @@ int C_Spawn(edict_t *pent) LOG_ERROR(PLID, "Binary log failed to open."); } g_binlog_level = atoi(get_localinfo("bin_logging", "17")); + g_binlog_maxsize = atoi(get_localinfo("g_binlog_maxsize", "20")); #endif + g_opt_level = atoi(get_localinfo("optimizer", "7")); + if (!g_opt_level) + g_opt_level = 7; + // ###### Load AMX scripts g_plugins.loadPluginsFromFile(get_localinfo("amxx_plugins", "addons/amxmodx/configs/plugins.ini")); g_plugins.Finalize(); diff --git a/amxmodx/modules.cpp b/amxmodx/modules.cpp index 027a309e..e30d9fbc 100755 --- a/amxmodx/modules.cpp +++ b/amxmodx/modules.cpp @@ -267,7 +267,10 @@ int load_amxscript(AMX *amx, void **program, const char *filename, char error[64 #endif } - SetupOptimizer(amx); + if (g_opt_level != 65536) + { + SetupOptimizer(amx); + } if ((err = amx_Init(amx, *program)) != AMX_ERR_NONE) { diff --git a/amxmodx/optimizer.cpp b/amxmodx/optimizer.cpp index d89645cc..0a679025 100644 --- a/amxmodx/optimizer.cpp +++ b/amxmodx/optimizer.cpp @@ -1,6 +1,8 @@ #include #include "optimizer.h" +int g_opt_level = 0; + #define OP_SYSREQ_C 123 #define OP_NOP 134 #define OP_FLOAT_MUL 138 @@ -82,14 +84,23 @@ void _Setup_Optimizer_Stage2(AMX *amx, cell *oplist, cell *cip) opt->natives[i] = -1; amx->usertags[UT_OPTIMIZER] = (void *)opt; - - FIND_NATIVE("floatmul", N_Float_Mul); - FIND_NATIVE("floatdiv", N_Float_Div); - FIND_NATIVE("floatadd", N_Float_Add); - FIND_NATIVE("floatsub", N_Float_Sub); - FIND_NATIVE("float", N_Float_To); - FIND_NATIVE("floatround", N_Float_Round); - FIND_NATIVE("floatcmp", N_Float_Cmp); + + if (g_opt_level & 1) + { + FIND_NATIVE("floatmul", N_Float_Mul); + FIND_NATIVE("floatdiv", N_Float_Div); + FIND_NATIVE("floatadd", N_Float_Add); + FIND_NATIVE("floatsub", N_Float_Sub); + } + if (g_opt_level & 4) + { + FIND_NATIVE("float", N_Float_To); + FIND_NATIVE("floatround", N_Float_Round); + } + if (g_opt_level & 2) + { + FIND_NATIVE("floatcmp", N_Float_Cmp); + } //we don't do these yet because of radix stuff >:\ //FIND_NATIVE("floatsin", N_Float_Sin); //FIND_NATIVE("floatcos", N_Float_Cos); diff --git a/amxmodx/optimizer.h b/amxmodx/optimizer.h index 57c46c25..76690ffd 100644 --- a/amxmodx/optimizer.h +++ b/amxmodx/optimizer.h @@ -23,4 +23,6 @@ struct optimizer_s void SetupOptimizer(AMX *amx); +extern int g_opt_level; + #endif //_INCLUDE_AMXMODX_OPTIMIZER_H