Добавлен Faion,
не публикуется
Решил вести небольшую барахолку систем проекта, дабы в случае чего всегда были под рукой, ну и мб кому нить тоже пригодится:)
Ниже сорц удобной системы для отладки:
Debug System Source
// v1.5
// by Faion (Bezarius), 2012
// by DoctorGester (Doc), 2011
#define
{
Debug = true
PerformanceEnable = true;
ShowDebugLogInGame = true;
SavePath = STALKER\\Logs
PerformanceSavePath = STALKER\\PerformanceLogs
SaveOnHardDrive = true
HardDriveLetter = C
AutoSaveLog = true
LogSavePeriod = 5.0
LocalDebug = false
}
#define BJDebugMsg(s) =
{
#if Debug && LocalDebug
DebugLog_LogAdd(`FUNCNAME` + s);
#if ShowDebugLogInGame
BJ##DebugMsg(`FUNCNAME`+ DebugLog_GetCurrentTime() +": " + s);
#endif
#endif
}
#define BJDebugMsg(cond, s) =
{
#if Debug
if (cond){BJDebugMsg(s)}
#endif
}
#define BJDebugMsg(cond, s1, s2) =
{
#if Debug
if (cond){BJDebugMsg(s1)}
else { BJDebugMsg(s2)}
#endif
}
#if Debug
library DebugLog uses TimerRecycle
{
public bool EnableLogging = true
private string array DebugLog
private int CurrentString = 0
private int miliSeconds = 0
private int Seconds = 0
private int Minutes = 0
private int Hours = 0
private constant int StringLimit = 150
#if PerformanceEnable
private string array PerformanceDebugLog
private int pastVal = 0;
private int PerformanceString = 0
#endif
public string GetCurrentTime()
{
string min = I2S(Minutes)
string sec = I2S(Seconds)
string msec = I2S(miliSeconds)
if (Minutes < 10)
{
min = "0" + min
}
if (Seconds < 10)
{
sec = "0" + sec
}
if (miliSeconds < 10)
{
msec = "0" + msec
}
return "[" + I2S(Hours)+":" + min + ":" + sec + ":" + msec + "] ";
}
#if PerformanceEnable
private void PerformanceLogAdd()
{
if (!EnableLogging){return}
location loc = Location(0,0);
int hId = GetHandleId(loc);
RemoveLocation(loc);
loc = null;
PerformanceDebugLog[PerformanceString] = PerformanceDebugLog[PerformanceString] + (GetCurrentTime()+ I2S(hId-0x100000) + "\n")
if (StringLength(PerformanceDebugLog[PerformanceString]) >= StringLimit){PerformanceString++}
}
#endif
public void LogAdd(string s)
{
if (!EnableLogging){return}
DebugLog[CurrentString] = DebugLog[CurrentString] + (GetCurrentTime() + s + "\n")
if (StringLength(DebugLog[CurrentString]) >= StringLimit){CurrentString++}
}
public void LogClear()
{
int i = 0
while (i <= CurrentString)
{
DebugLog[i] = ""
i++
}
CurrentString = 0
}
private void LogUpdate()
{
if (!EnableLogging)
{
return
}
PreloadGenClear()
PreloadGenStart()
for(int i = 0; i < CurrentString; i++)
{
Preload("\")\n" + DebugLog[i] + "\n(\"")
}
#if SaveOnHardDrive
PreloadGenEnd(`HardDriveLetter` + ":\\" + `SavePath` + ".txt")
#else
PreloadGenEnd("\\" + `SavePath` + ".txt")
#endif
}
#if PerformanceEnable
private void PerformanceLogUpdate()
{
if (!EnableLogging)
{
return
}
PreloadGenClear()
PreloadGenStart()
for(int i = 0; i < CurrentString; i++)
{
Preload("\")\n" + PerformanceDebugLog[i] + "\n(\"")
}
#if SaveOnHardDrive
PreloadGenEnd(`HardDriveLetter` + ":\\" + `PerformanceSavePath` + ".txt")
#else
PreloadGenEnd("\\" + `PerformanceSavePath` + ".txt")
#endif
}
#endif
callback onInit()
{
#if AutoSaveLog
TimerStart(TimerRecycle_Get(), LogSavePeriod, true, function LogUpdate)
#if PerformanceEnable
TimerStart(TimerRecycle_Get(), LogSavePeriod, true, function PerformanceLogUpdate)
#endif
#endif
// счетчик
TimerStart(TimerRecycle_Get(), 0.01, true, lambda void(){
miliSeconds++
if (miliSeconds > 99)
{
miliSeconds = 0
Seconds++
if (Seconds > 59)
{
Seconds = 0
Minutes++
if (Minutes > 59)
{
Minutes = 0
Hours++
}
}
}
})
#if PerformanceEnable
TimerStart(TimerRecycle_Get(), 0.10, true, function PerformanceLogAdd)
#endif
BJDebugMsg("Debug Enable! Last compilation: " + `DATE` + " " + `TIME`)
AddCmd("-debugoff", false, BJDebugMsg("Дебагер отключен");EnableLogging = false)
AddCmd("-debugon", false, BJDebugMsg("Дебагер включен");EnableLogging = true)
}
}
#endif
маленькая либа юзаемая в этой системе
library ChatEvent
{
#define AddCmd(cmdString, flag, action) =
{
vblock
{
trigger t = CreateTrigger()
for(int i = 0; i < 12; i++)
{
TriggerRegisterPlayerChatEvent(t, Player(i), cmdString, flag )
}
TriggerAddAction(t, lambda void() { action })
t = null;
}
}
}
Собсно как юзать кратко рассмотрим ниже:
Вариант 1:
Обычное отладочное сообщение:
BJDebugMsg("сообщение");
Вариант 2:
BJDebugMsg(jass condition , "сообщение если выполнилось заданное условие");
Данный вариант позволяет удобным образом задать условие при котором нужно выводить данное сообщение.
Пример:
BJDebugMsg(FirstOfGroup(g) != null , "то отобразится данное сообщение");
Вариант 3:
BJDebugMsg(jass condition , "если условие выполнилось, то высветится это сообщение", "иначе это");
Плюсы
В отличии от остальных вариантов в этой системе более удобные инструкции, так же можно всегда вырубить систему как ингейм использовав команду -debugoff. Так же можно с помощью конфига системы Debug , можно дать скопилировать проект без дебаг инструкций проще говоря препроцессор будет исключать debug'и на этапе компиляции, и не нужно будет потом выпиливать дебаги их кода. Если нужно что б ингейм отображались логи, то нужно поставить ShowDebugLogInGame - true.
ВНИМАНИЕ!! ДЛЯ РАБОТЫ ЭТОЙ БИБЛИОТЕКИ ТРЕБУЕТСЯ ПОСЛЕДНЯЯ ВЕРСИЯ cJASS!!!
`
ОЖИДАНИЕ РЕКЛАМЫ...
0
Darklight
12 лет назад
0
Лучше бы написали требуемую версию cJass
3
Faion
12 лет назад
3
Darklight:
:facepalm:
0
MpW
3 года назад
0
зачем каждый раз обновлять буфер таймером? Объясните смысл? смотрите, заводим массив строк. Каждый интервал 0.03 сек чистим буфер, потом записываем массив. И?
Чтобы оставить комментарий, пожалуйста, войдите на сайт.