summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 0da2f21)
raw | patch | inline | side by side (parent: 0da2f21)
author | Ketmar Dark <ketmar@ketmar.no-ip.org> | |
Thu, 17 Aug 2017 08:49:23 +0000 (11:49 +0300) | ||
committer | Ketmar Dark <ketmar@ketmar.no-ip.org> | |
Thu, 17 Aug 2017 14:41:07 +0000 (17:41 +0300) |
src/game/g_game.pas | patch | blob | history | |
src/shared/xprofiler.pas | patch | blob | history |
diff --git a/src/game/g_game.pas b/src/game/g_game.pas
index f45ac3d7e55ae8284caabcf6987912b6bdb3c905..bfdea2d2ac4247d48cf2feab32745d172cc81085 100644 (file)
--- a/src/game/g_game.pas
+++ b/src/game/g_game.pas
wdt, hgt: Integer;
yy: Integer;
+ {
procedure drawItems ();
begin
repeat
- e_TextureFontPrintEx(x+2+4*xprofItDepth, yy, Format('%s: %d', [xprofItName, xprofItMicro]), gStdFont, 255, 255, 0, 1, false);
+ e_TextureFontPrintEx(x+2+4*xprofItLevel, yy, Format('%s: %d', [xprofItName, Integer(xprofItMicro)]), gStdFont, 255, 255, 0, 1, false);
Inc(yy, 16+2);
if xprofItHasChildren then
begin
drawItems();
xprofItPop();
end;
- until xprofItNext();
+ until not xprofItNext();
+ end;
+ }
+
+ procedure drawItems ();
+ var
+ ii, idx: Integer;
+ begin
+ for ii := 0 to xprofTotalCount-1 do
+ begin
+ e_TextureFontPrintEx(x+2+4*xprofLevelAt(ii), yy, Format('%s: %d', [xprofNameAt(ii), Integer(xprofMicroAt(ii))]), gStdFont, 255, 255, 0, 1, false);
+ Inc(yy, 16+2);
+ end;
end;
begin
wdt := 256;
hgt := 16+2+xprofTotalCount*(16+2); // title, items
// background
- e_DrawFillQuad(x, y, x+wdt-1, y+hgt-1, 255, 255, 255, 200, B_BLEND);
+ //e_DrawFillQuad(x, y, x+wdt-1, y+hgt-1, 255, 255, 255, 200, B_BLEND);
+ e_DrawFillQuad(x, y, x+wdt-1, y+hgt-1, 20, 20, 20, 0, B_NONE);
// title
e_TextureFontPrintEx(x+2, y+2, Format('%s: %d', [title, Integer(xprofTotalMicro)]), gStdFont, 255, 255, 0, 1, false);
yy := y+16+2;
- //drawItems();
+ drawItems();
end;
index 4dc4eaf603072203db39deceed1c06ddca6c903f..9b711117cf8db070933666fed282409482be99ce 100644 (file)
--- a/src/shared/xprofiler.pas
+++ b/src/shared/xprofiler.pas
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*)
// stopwatch timer to measure short periods (like frame rendering phases)
-// based on the code by Inoussa OUEDRAOGO, Copyright (c) 2012
+// TStopWatch is based on the code by Inoussa OUEDRAOGO, Copyright (c) 2012
{$INCLUDE a_modes.inc}
unit xprofiler;
class property isHighResolution : Boolean read mIsHighResolution;
public
+ procedure clear (); inline; // full clear
procedure start (); // start or restart timer
procedure stop ();
procedure xprofBeginSection (name: AnsiString);
procedure xprofEndSection ();
+function xprofNameAt (idx: Integer): AnsiString;
+function xprofMicroAt (idx: Integer): Int64;
+function xprofMilliAt (idx: Integer): Int64;
+function xprofHasChildrenAt (idx: Integer): Boolean;
+function xprofLevelAt (idx: Integer): Integer;
+
// iterator
function xprofItReset (): Boolean; // false: no sections
function xprofItCount (): Integer; // from current item to eol (not including children, but including current item)
function xprofItMilli (): Int64; // current section duration, milliseconds
function xprofItHasChildren (): Boolean;
function xprofItIsChild (): Boolean;
-function xprofItDepth (): Integer; // 0: top
+function xprofItLevel (): Integer; // 0: top
function xprofItDive (): Boolean; // dive into childrens
function xprofItPop (): Boolean; // pop into parent
class function TStopWatch.Create (): TStopWatch;
begin
initTimerIntr();
- FillChar(result, sizeof(result), 0);
+ result.clear();
end;
end;
+procedure TStopWatch.clear ();
+begin
+ //FillChar(self, sizeof(self), 0);
+ mElapsed := 0;
+ mRunning := false;
+ //mStartPosition: TBaseMesure;
+end;
+
+
procedure TStopWatch.start ();
begin
//if mRunning then exit;
if (mFrequency = 0) then initTimerIntr();
mRunning := true;
+ mElapsed := 0;
{$IF DEFINED(LINUX)}
clock_gettime(CLOCK_MONOTONIC, @mStartPosition);
{$ELSE}
parent: Integer; // section index in xpsecs or -1
firstChild: Integer; // first child, or -1
next: Integer; // next sibling, or -1
+ level: Integer;
end;
var
xpsecs: array of TProfSection = nil;
xpsused: Integer = 0;
xpscur: Integer = -1; // currently running section
+ xpslevel: Integer = 0;
xitcur: Integer = -1; // for iterator
- xitdepth: Integer = 0;
// call this on frame start
xpsused := 0;
xpscur := -1;
xitcur := -1; // reset iterator
- xitdepth := 0;
+ xpslevel := 0;
+ xptimer.clear();
if reallyActivate then xptimer.start();
end;
// don't fuckup pairing of there, 'cause they can be nested!
+//FIXME: rewrite without schlemiel's algo!
procedure xprofBeginSection (name: AnsiString);
var
sid, t: Integer;
pss: PProfSection;
begin
if not xptimer.isRunning then exit;
+ if (Length(xpsecs) = 0) then SetLength(xpsecs, 65536); // why not?
+ if (xpsused >= Length(xpsecs)) then raise Exception.Create('too many profile sections');
sid := xpsused;
Inc(xpsused);
- if (sid = Length(xpsecs)) then SetLength(xpsecs, sid+1024);
pss := @xpsecs[sid];
pss.name := name;
+ pss.timer.clear();
pss.parent := xpscur;
pss.firstChild := -1;
pss.next := -1;
- // link to children
- if xpscur <> -1 then
+ pss.level := xpslevel;
+ Inc(xpslevel);
+ // link to list
+ if (xpscur <> -1) then
begin
+ // child
t := xpsecs[xpscur].firstChild;
- if t = -1 then
+ if (t = -1) then
begin
xpsecs[xpscur].firstChild := sid;
end
else
begin
- //FIXME: rewrite without schlemiel's algo!
while (xpsecs[t].next <> -1) do t := xpsecs[t].next;
xpsecs[t].next := sid;
end;
end
else
begin
+ // top level
+ if (sid <> 0) then
+ begin
+ t := 0;
+ while (xpsecs[t].next <> -1) do t := xpsecs[t].next;
+ xpsecs[t].next := sid;
+ end;
end;
xpscur := sid;
pss.timer.start();
begin
if not xptimer.isRunning then exit;
if (xpscur = -1) then exit; // this is bug, but meh...
+ Dec(xpslevel);
pss := @xpsecs[xpscur];
pss.timer.stop();
// go back to parent
procedure xprofGlobalInit ();
begin
//SetLength(xpsecs, 1024); // 'cause why not? 'cause don't pay for something you may not need
+ xptimer.clear();
end;
end;
+function xprofNameAt (idx: Integer): AnsiString; begin if xptimer.isRunning or (idx < 0) or (idx >= xpsused) then result := '' else result := xpsecs[idx].name; end;
+function xprofMicroAt (idx: Integer): Int64; begin if xptimer.isRunning or (idx < 0) or (idx >= xpsused) then result := 0 else result := xpsecs[idx].timer.elapsedMicro; end;
+function xprofMilliAt (idx: Integer): Int64; begin if xptimer.isRunning or (idx < 0) or (idx >= xpsused) then result := 0 else result := xpsecs[idx].timer.elapsedMilli; end;
+function xprofHasChildrenAt (idx: Integer): Boolean; begin if xptimer.isRunning or (idx < 0) or (idx >= xpsused) then result := false else result := (xpsecs[idx].firstChild <> -1); end;
+function xprofLevelAt (idx: Integer): Integer; begin if xptimer.isRunning or (idx < 0) or (idx >= xpsused) then result := 0 else result := xpsecs[idx].level; end;
+
+
// false: no sections
function xprofItReset (): Boolean;
begin
result := false;
xitcur := -1;
- xitdepth := 0;
if xptimer.isRunning then exit;
if (xpsused = 0) then exit; // no sections
xitcur := 0;
@@ -388,7 +427,7 @@ function xprofItMicro (): Int64; begin if (xitcur = -1) then result := 0 else re
function xprofItMilli (): Int64; begin if (xitcur = -1) then result := 0 else result := xpsecs[xitcur].timer.elapsedMilli; end;
function xprofItHasChildren (): Boolean; begin if (xitcur = -1) then result := false else result := (xpsecs[xitcur].firstChild <> -1); end;
function xprofItIsChild (): Boolean; begin if (xitcur = -1) then result := false else result := (xpsecs[xitcur].parent <> -1); end;
-function xprofItDepth (): Integer; begin result := xitdepth; end;
+function xprofItLevel (): Integer; begin if (xitcur = -1) then result := 0 else result := xpsecs[xitcur].level; end;
// dive into childrens
function xprofItDive (): Boolean;
begin
result := true;
xitcur := xpsecs[xitcur].firstChild;
- Inc(xitdepth);
end;
end;
begin
result := true;
xitcur := xpsecs[xitcur].parent;
- Dec(xitdepth);
end;
end;
function xprofTotalMilli (): Int64; begin result := 0; end;
function xprofTotalCount (): Integer; begin result := 0; end;
+function xprofNameAt (idx: Integer): AnsiString; begin result := ''; end;
+function xprofMicroAt (idx: Integer): Int64; begin result := 0; end;
+function xprofMilliAt (idx: Integer): Int64; begin result := 0; end;
+function xprofHasChildrenAt (idx: Integer): Boolean; begin result := false; end;
+function xprofLevelAt (idx: Integer): Integer; begin result := 0; end;
+
function xprofItReset (): Boolean; begin result := false; end;
function xprofItCount (): Integer; begin result := 0; end;
// current item info