1 // NeL - MMORPG Framework <http://dev.ryzom.com/projects/nel/>
2 // Copyright (C) 2010 Winch Gate Property Limited
4 // This program is free software: you can redistribute it and/or modify
5 // it under the terms of the GNU Affero General Public License as
6 // published by the Free Software Foundation, either version 3 of the
7 // License, or (at your option) any later version.
9 // This program is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU Affero General Public License for more details.
14 // You should have received a copy of the GNU Affero General Public License
15 // along with this program. If not, see <http://www.gnu.org/licenses/>.
27 #include <nel/misc/types_nl.h>
28 #include <nel/misc/vector.h>
29 #include <nel/misc/matrix.h>
30 #include <nel/misc/command.h>
32 #include <nel/3d/u_material.h>
33 #include <nel/3d/u_camera.h>
34 #include <nel/3d/u_driver.h>
35 #include <nel/3d/u_text_context.h>
36 #include <nel/3d/u_texture.h>
37 #include <nel/3d/driver.h>
38 #include <nel/3d/vertex_buffer.h>
39 #include <nel/3d/material.h>
40 #include <nel/3d/driver_user.h>
46 using namespace NLMISC
;
54 vector
<CGraph
*> *CGraph::_Graphs
= NULL
;
56 bool CGraph::Display
= true;
57 bool CGraph::DisplayAverageValue
= true;
63 void CGraph::render (NL3D::UDriver
*Driver
, NL3D::UTextContext
*TextContext
)
65 // Display the background
67 Driver
->getWindowSize (w
, h
);
68 float ScreenWidth
= (float) w
;
69 float ScreenHeight
= (float) h
;
70 Driver
->setMatrixMode2D (CFrustum (0.0f
, ScreenWidth
, 0.0f
, ScreenHeight
, 0.0f
, 1.0f
, false));
71 Driver
->drawQuad (X
, Y
, X
+Width
, Y
+Height
, BackColor
);
77 material
.initUnlit ();
78 material
.setColor (CRGBA (255,255,255,BackColor
.A
));
79 material
.setBlend (true);
82 CVertexBuffer vbuffer
;
83 vbuffer
.setVertexFormat (CVertexBuffer::PositionFlag
);
84 vbuffer
.setNumVertices ((uint32
)Values
.size() * 2);
86 float pos
= X
+Width
-1;
88 for (deque
<float>::reverse_iterator it
= Values
.rbegin(); it
!= Values
.rend(); it
++)
90 // get a read accessor to the VB
91 CVertexBufferRead vba
;
94 float value
= (*it
) * Height
/ MaxValue
;
95 if (value
> Height
) value
= Height
;
97 CVector
*vect1
= (CVector
*)vba
.getVertexCoordPointer(i
*2+0);
100 CVector
*vect2
= (CVector
*)vba
.getVertexCoordPointer(i
*2+1);
104 // Driver->drawLine (pos, Y, pos, Y+value, CRGBA (255,255,255,BackColor.A));
106 if ((*it
) > Peak
) Peak
= *it
;
112 IDriver
*drv
= ((CDriverUser
*)Driver
)->getDriver();
113 drv
->activeVertexBuffer(vbuffer
);
116 float value
= Peak
* Height
/ MaxValue
;
117 if (value
> Height
) value
= Height
;
118 CRGBA
frontCol (min(BackColor
.R
*2,255),min(BackColor
.G
*2,255),min(BackColor
.B
*2,255),min(BackColor
.A
*2,255));
119 float peakval
= Y
+value
;
120 Driver
->drawLine (X
, peakval
, X
+Width
, peakval
, frontCol
);
122 TextContext
->setHotSpot (UTextContext::MiddleLeft
);
123 TextContext
->setColor (frontCol
);
124 TextContext
->setFontSize (10);
125 TextContext
->printfAt ((X
+Width
+2)/ScreenWidth
, (Y
+value
)/ScreenHeight
, "%.2f", Peak
);
128 float average
= sum
/ (float)Values
.size();
129 value
= average
* Height
/ MaxValue
;
130 if (value
> Height
) value
= Height
;
131 float avrval
= Y
+value
;
132 Driver
->drawLine (X
, avrval
, X
+Width
, avrval
, frontCol
);
134 if (DisplayAverageValue
)
136 if (avrval
+10<peakval
-10 || avrval
-10>peakval
+10)
138 TextContext
->setHotSpot (UTextContext::MiddleLeft
);
139 TextContext
->setColor (frontCol
);
140 TextContext
->setFontSize (10);
141 TextContext
->printfAt ((X
+Width
+2)/ScreenWidth
, (Y
+value
)/ScreenHeight
, "%.2f", average
);
146 TextContext
->setHotSpot (UTextContext::TopLeft
);
147 TextContext
->printfAt ((X
+1)/ScreenWidth
, (Y
+Height
-1)/ScreenHeight
, Name
.c_str());
150 void CGraph::addOneValue (float value
)
152 if (value
< 0.0f
) value
= 0.0f
;
154 Values
.push_back (value
);
155 while (Values
.size () > Width
)
158 // if (Values.back() > Peak)
159 // Peak = Values.back();
163 void CGraph::addValue (float value
)
165 TTime currentTime
= CTime::getLocalTime ();
167 while (Values
.size () == 0 || currentTime
> CurrentQuantumStart
+ Quantum
)
169 CurrentQuantumStart
+= Quantum
;
173 Values
.back() += value
;
175 // if (Values.back() > Peak)
176 // Peak = Values.back();
183 CGraph FpsGraph ("fps", 10.0f, 110.0f, 100.0f, 100.0f, CRGBA(128,0,0,128), 1000, 150.0f);
184 CGraph SpfGraph ("spf", 10.0f, 10.0f, 100.0f, 100.0f, CRGBA(0,128,0,128), 0, 100.0f);
186 CGraph DownloadGraph ("download", 10.0f, 260.0f, 100.0f, 100.0f, CRGBA(0,0,128,128), 1000, 2000.0f);
187 CGraph UploadGraph ("upload", 10.0f, 360.0f, 100.0f, 100.0f, CRGBA(0,128,128,128), 1000, 2000.0f);
189 CGraph DpfGraph ("dpf", 150.0f, 260.0f, 100.0f, 100.0f, CRGBA(128,0,128,128), 100000, 180.0f);
190 CGraph UpfGraph ("upf", 150.0f, 360.0f, 100.0f, 100.0f, CRGBA(128,128,0,128), 100000, 180.0f);
193 CGraph UserLWatchGraph ("ul", 10.0f, 490.0f, 100.0f, 100.0f, CRGBA(0,64,128,128), 100000, 1000.0f);
194 CGraph CycleWatchGraph ("cl", 150.0f, 490.0f, 100.0f, 100.0f, CRGBA(0,128,64,128), 100000, 1000.0f);
195 CGraph ReceiveWatchGraph ("rl", 300.0f, 490.0f, 100.0f, 100.0f, CRGBA(128,64,0,128), 100000, 100.0f);
196 CGraph SendWatchGraph ("sl", 450.0f, 490.0f, 100.0f, 100.0f, CRGBA(128,0,64,128), 100000, 100.0f);
197 CGraph PriorityAmountGraph ("prio amount", 150.0f, 110.0f, 100.0f, 100.0f, CRGBA(128,64,64,128), 100000, 16.0f);
198 CGraph SeenEntitiesGraph( "seen entities", 150.0f, 10.0f, 100.0f, 100.0f, CRGBA(64,128,64,128), 100000, 256);
205 void CGraph::render (NL3D::UDriver
&driver
, NL3D::UTextContext
&tc
)
207 if (!Display
) return;
209 if (_Graphs
== NULL
) return;
211 for (uint i
= 0; i
< _Graphs
->size(); i
++)
213 (*_Graphs
)[i
]->render (&driver
, &tc
);
218 NLMISC_VARIABLE(bool, GraphShow, "Display or not graphs");
219 NLMISC_VARIABLE(bool, GraphDisplayAverageValue, "Display or not average values");