1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316
| package Working;
using System;
using System.Draw;
using System.Application;
using System.Math;
function RANDOM_FLOAT( v1, v2 )
{
return v1 + (v2-v1)*(System.Random( )*1.0f)/(1.0f*0x7fff);
}
object OStatsMaker
{
public var _avgFPS;
public var _bestFPS;
public var _lastFPS;
public var _worstFPS;
public var _bestFrameTime;
public var _worstFrameTime;
public var _lastTime;
public var _lastSecond;
public var _frameCount;
method resetStats( )
{
_avgFPS = _bestFPS = _lastFPS = 0.0;
_worstFPS = 999.0;
_bestFrameTime = 999999;
_worstFrameTime = 0.0;
_lastTime = _lastSecond = System.TimeGetTime( );
_frameCount = 0;
}
public var AverageFPS
{
get { return _avgFPS * 1000000; }
}
public var BestFPS
{
get { return _bestFPS * 1000000; }
}
public var LastFPS
{
get { return _lastFPS * 1000000; }
}
public var WorstFPS
{
get { return _worstFPS * 1000000; }
}
public var BestFrameTime
{
get { return _bestFrameTime; }
}
public var WorstFrameTime
{
get { return _worstFrameTime; }
}
method updateStats( )
{
++_frameCount;
var thisTime = System.TimeGetTime( );
// check frame time
var frameTime = thisTime - _lastTime;
_lastTime = thisTime ;
_bestFrameTime = System.Math.Min(_bestFrameTime, frameTime);
_worstFrameTime = System.Math.Max(_worstFrameTime, frameTime);
// check if new second (update only once per second)
if (thisTime - _lastSecond > 1000)
{
// new second - not 100% precise
_lastFPS = _frameCount / ((thisTime - _lastSecond) * 1000.0);
if (_avgFPS == 0)
_avgFPS = _lastFPS;
else
_avgFPS = (_avgFPS + _lastFPS) / 2; // not strictly correct, but good enough
_bestFPS = System.Math.Max(_bestFPS, _lastFPS);
_worstFPS = System.Math.Min(_worstFPS, _lastFPS);
_lastSecond = thisTime;
_frameCount = 0;
}
}
};
object OObject extends System.Object
{
public var _position;
public var Position
{
set { _position = value; }
get { return _position; }
}
};
object OCube extends OObject
{
public var m_size;
public var m_angleX;
public var m_angleY;
public var m_angleZ;
public var r;
public var g;
public var b;
public var _lastTime;
public var _lastSecond;
public var _increasing;
method setSize( size )
{
m_size = size;
}
method getSize( )
{
return m_size;
}
method create( size, position )
{
super->Position = position;
self->setSize( size );
r = g = b = 0.0;
_lastTime = _lastSecond = System.TimeGetTime( );
_increasing = @true;
m_angleX = m_angleY = m_angleZ = 0.0;
}
method RandomColor( a, b, c )
{
System.Draw.glColor3f( a, b, c );
}
method draw( )
{
var thisTime = System.TimeGetTime( );
// check frame time
var frameTime = thisTime - _lastTime;
if (thisTime - _lastSecond > 2000)
{
r = RANDOM_FLOAT( 255, 0 ) / 255;
g = RANDOM_FLOAT( 255, 0 ) / 255;
b = RANDOM_FLOAT( 255, 0 ) / 255;
_lastSecond = thisTime;
}
System.Draw.glPushMatrix( );
System.Draw.glTranslatef( super->Position[0], super->Position[1], super->Position[2] );
System.Draw.glRotatef( m_angleX, 1.0, 0.0, 0.0 );
System.Draw.glRotatef( m_angleY, 0.0, 1.0, 0.0 );
System.Draw.glRotatef( m_angleZ, 0.0, 0.0, 1.0 );
m_angleX += 1.0;
m_angleY += 10.0;
m_angleZ += 5.0;
System.Draw.glBegin( 0x0008 );
System.Draw.glColor3f( r, 0.0, b );
System.Draw.glVertex3f( -0.5, 0.5, 0.5 );
System.Draw.glColor3f( r, 0.0, 0.0 );
System.Draw.glVertex3f( -0.5, -0.5, 0.5 );
System.Draw.glColor3f( r, g, b );
System.Draw.glVertex3f( 0.5, 0.5, 0.5 );
System.Draw.glColor3f( r, g, 0.0 );
System.Draw.glVertex3f( 0.5, -0.5, 0.5 );
System.Draw.glColor3f( 0.0, g, b );
System.Draw.glVertex3f( 0.5, 0.5, -0.5 );
System.Draw.glColor3f( 0.0, g, 0.0 );
System.Draw.glVertex3f( 0.5, -0.5, -0.5 );
System.Draw.glColor3f( 0.0, 0.0, b );
System.Draw.glVertex3f( -0.5, 0.5, -0.5 );
System.Draw.glColor3f( 0.0, 0.0, 0.0 );
System.Draw.glVertex3f( -0.5, -0.5, -0.5 );
System.Draw.glColor3f( r, 0.0, b );
System.Draw.glVertex3f( -0.5, 0.5, 0.5 );
System.Draw.glColor3f( r, 0.0, 0.0 );
System.Draw.glVertex3f( -0.5, -0.5, 0.5 );
System.Draw.glEnd( );
System.Draw.glBegin( 0x0007 );
System.Draw.glColor3f( r, 0.0, b );
System.Draw.glVertex3f( -0.5, 0.5, 0.5 );
System.Draw.glColor3f( r, g, b );
System.Draw.glVertex3f( 0.5, 0.5, 0.5 );
System.Draw.glColor3f( 0.0, g, b );
System.Draw.glVertex3f( 0.5, 0.5, -0.5 );
System.Draw.glColor3f( 0.0, 0.0, b );
System.Draw.glVertex3f( -0.5, 0.5, -0.5 );
System.Draw.glEnd( );
System.Draw.glBegin( 0x0007 );
System.Draw.glColor3f( r, 0.0, 0.0 );
System.Draw.glVertex3f( -0.5, -0.5, 0.5 );
System.Draw.glColor3f( r, g, 0.0 );
System.Draw.glVertex3f( 0.5, -0.5, 0.5 );
System.Draw.glColor3f( 0.0, g, 0.0 );
System.Draw.glVertex3f( 0.5, -0.5, -0.5 );
System.Draw.glColor3f( 0.0, 0.0, 0.0 );
System.Draw.glVertex3f( -0.5, -0.5, -0.5 );
System.Draw.glEnd( );
System.Draw.glPopMatrix( );
}
}
var objList = #[ ];
var statsMaker = new OStatsMaker;
function addObject( size, position )
{
var newObj = new OCube;
newObj->create( size, position );
objList[ lengthof( objList ) ] = newObj;
}
function drawList( )
{
var it;
foreach( it in objList )
it->draw( );
}
function initializeApplication( )
{
addObject( 1, #[ 3.5, 3.5, -4.5 ] );
addObject( 1, #[ 3.5, -3.5, -4.5 ] );
addObject( 1, #[ -3.5, 3.5, -4.5 ] );
addObject( 1, #[ -3.5, -3.5, -4.5 ] );
addObject( 1, #[ 0, 0, -2 ] );
statsMaker->resetStats( );
System.Application.CreateApplication( "Test OOP", 1024, 768, @true );
}
function destroyApplication( )
{
System.Application.DestroyApplication( );
}
var g_FrameInterval = 0.0f;
function main( )
{
initializeApplication( );
var strFrameRate;
var strBestAndBad;
while( System.Draw.FrameBegin( ) )
{
System.Draw.glClearColor( 1.0, 0.71, 0.16, 0.0 );
System.Draw.glClear( 0x00004000 | 0x00000100 );
drawList( );
statsMaker->updateStats( );
strFrameRate = System.SPrintf( "FPS : %f\nTest", statsMaker->AverageFPS );
strBestAndBad = System.SPrintf( "Worst FPS : %f | Best FPS : %f", statsMaker->WorstFPS, statsMaker->BestFPS );
System.Draw.DrawString( #[ (1024/2-120), 700 ], "HHO Engine Is Performant !", #[ 1, 0.5, 1, 1.0 ] );
System.Draw.DrawString( #[ (1024/2-120), 680 ], strFrameRate, #[ 1, 0.5, 1, 1.0 ] );
System.Draw.DrawString( #[ (1024/2-120), 660 ], strBestAndBad, #[ 1, 0.5, 1, 1.0 ] );
System.Draw.FrameEnd( );
System.Sleep( 7 );
}
destroyApplication( );
System.Exit( -1 );
return 1;
}
main( ); |
Partager