Subversion Repository Public Repository

Divide-Framework

This repository has no backups
This repository's network speed is throttled to 100KB/sec

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
#include "Headers/ApplicationTimer.h"
#include "Core/Headers/Console.h"
#include "Core/Math/Headers/MathHelper.h"
#include "Utility/Headers/Localization.h"

#pragma message("DIVIDE Framework uses U64 (unsigned long long) data types for timing with microsecond resolution!")
#pragma message("Use apropriate conversion in time sensitive code (see core.h)")

namespace Divide {

#if defined(_DEBUG) || defined(_PROFILE)
ProfileTimer::ProfileTimer() : _init(false), _paused(false), _timer(0.0), _timerAverage(0.0), _timerCounter(0)
{
}

ProfileTimer::~ProfileTimer()
{
    ApplicationTimer::getInstance().removeTimer(this);
    SAFE_DELETE(_name);
}

void ProfileTimer::reset() {
    _timerAverage = 0.0;
    _timerCounter = 0;
}

void ProfileTimer::start(){
    _timer = getUsToMs(ApplicationTimer::getInstance().getElapsedTime(true));
}

void ProfileTimer::stop(){
    if(_paused) {
        reset();
        return;
    }
    _timer = getUsToMs(ApplicationTimer::getInstance().getElapsedTime(true)) - _timer;
    _timerAverage = _timerAverage + _timer;
    _timerCounter++;
}

void ProfileTimer::create(const char* name){
    if(_init) return;

    _name = strdup(name);
    _init = true;
    // should never be called twice for the same object
    ApplicationTimer::getInstance().addTimer(this);
}

void ProfileTimer::print() const {
    if(!_paused)
        PRINT_FN("[ %s ] : [ %5.3f ms]", _name, _timerAverage / _timerCounter);
}

void ApplicationTimer::addTimer(ProfileTimer* const timer) {
    _profileTimers.push_back(timer);
}

void ApplicationTimer::removeTimer(ProfileTimer* const timer) {
    for(vectorImpl<ProfileTimer* >::iterator it = _profileTimers.begin(); it != _profileTimers.end(); ++it){
        if(strcmp((*it)->name(), timer->name()) == 0){
            _profileTimers.erase(it);
            return;
        }
    }
}
#endif

ApplicationTimer::ApplicationTimer() : _targetFrameRate(Config::TARGET_FRAME_RATE),
                                       _ticksPerMicrosecond(0.0),
                                       _speedfactor(1.0f),
                                       _elapsedTimeUs(0ULL),
                                       _init(false),
                                       _benchmark(false)
{
    _ticksPerSecond.QuadPart = 0LL;
    _frameDelay.QuadPart = 0LL;
    _startupTicks.QuadPart = 0LL;
    _currentTicks.QuadPart = 0LL;
}
#ifdef min
#undef min
#undef max
#endif
///No need for init to be threadsafe
void ApplicationTimer::init(U8 targetFrameRate) {
    assert(!_init);//<prevent double init

    _targetFrameRate = static_cast<U32>(targetFrameRate);

#if defined( OS_WINDOWS )
    if(!QueryPerformanceFrequency(&_ticksPerSecond))
        assert(false && "Current system does not support 'QueryPerformanceFrequency calls!");

    QueryPerformanceCounter(&_startupTicks);
#else
    gettimeofday(&_startupTicks,nullptr);
#endif

    _ticksPerMicrosecond = static_cast<D32>(_ticksPerSecond.QuadPart / 1000000.0);
    _frameDelay = _startupTicks;
    _init = true;
}

namespace {
    static U32 averageCount = 0;
    static F32 maxFps = std::numeric_limits<F32>::min();
    static F32 minFps = std::numeric_limits<F32>::max();
    static F32 averageFps = 0.0f;
    static F32 averageFpsTotal = 0.0f;
};

U64 ApplicationTimer::getElapsedTimeInternal() {
#if defined( OS_WINDOWS )
    QueryPerformanceCounter(&_currentTicks);
#else
    gettimeofday(&_currentTicks,nullptr);
#endif

    return static_cast<U64>((_currentTicks.QuadPart -_startupTicks.QuadPart) / _ticksPerMicrosecond);
}

void ApplicationTimer::update(U32 frameCount){
    _elapsedTimeUs = getElapsedTimeInternal();

    _speedfactor = static_cast<F32>((_currentTicks.QuadPart - _frameDelay.QuadPart) / 
                                    (_ticksPerSecond.QuadPart / static_cast<F32>(_targetFrameRate)));
    _frameDelay = _currentTicks;

    if(_speedfactor <= 0.0f)
       _speedfactor = 1.0f;

    _fps = _targetFrameRate / _speedfactor;
    _frameTime = 1000.0 / _fps;

    if (_benchmark) benchmarkInternal(frameCount);
}

void ApplicationTimer::benchmarkInternal(U32 frameCount){
    //Average FPS
    averageFps += _fps;
    averageCount++;

    //Min/Max FPS (after every target second)
    if(frameCount % _targetFrameRate == 0){
        maxFps = std::max(maxFps, _fps);
        minFps = std::min(minFps, _fps);
    }

    //Every 10 seconds (targeted)
    if(frameCount % (_targetFrameRate * 10) == 0){
        averageFpsTotal += averageFps;

        F32 avgFPS = averageFpsTotal / averageCount;
        PRINT_FN(Locale::get("FRAMERATE_FPS_OUTPUT"), avgFPS, maxFps, minFps, 1000.0f / avgFPS);
#if defined(_DEBUG) || defined(_PROFILE)
        for(vectorImpl<ProfileTimer* >::iterator it = _profileTimers.begin(); it != _profileTimers.end(); ++it){
            (*it)->print();
            (*it)->reset();
        }

#endif
        averageFps = 0;
    }
}

};

Commits for Divide-Framework/trunk/Source Code/Core/ApplicationTimer.cpp

Diff revisions: vs.
Revision Author Commited Message
318 Diff Diff IonutCava picture IonutCava Sat 30 Aug, 2014 17:35:53 +0000

[Ionut]
- Wrapped the entire code in a “Divide” namespace
- VertexBuffers now call “shrink_to_fit” on all internal data storage
- Improved some vector performance by preferring “emplace_back” instead of “push_back” + proepr usage of reserve / resize
- Wrapped OIS specific types and classes in Divide::Input namespace
- Added the messageBox.layout file (forgot it in the previous few commits)

264 Diff Diff k1ngp1n picture k1ngp1n Tue 27 May, 2014 13:04:38 +0000

[Ionut] [[BR]]
- New camera system: [[BR]]
— Stack based (push/pop active camera) [[BR]]
— Per camera frustum [[BR]]
— Per camera projection [[BR]]
— Shadow mapping now uses the new camera system (each light has a shadow camera) [[BR]]
[[BR]]
- New terrain, water and vegetation system: [[BR]]
— Direct import of terrain from L3DT both as 8-bit grayscale and 16-bit raw formats [[BR]]
— Multiple alpha maps for texture splatting support [[BR]]
— Per texture detail map support [[BR]]
— Transform feedback based visibility culling for vegetation [[BR]]
— Alpha-map based vegetation placing on terrain [[BR]]
— Water now uses a refraction map instead of alpha blending for better refraction effects [[BR]]
[[BR]]
- SceneGraph improvements: [[BR]]
— Better bounding box updates from child to parent [[BR]]
— Better onDraw / postDraw implementation [[BR]]
[[BR]]
- Performance improvements: [[BR]]
— Batch 2D rendering tasks together as much as possible[[BR]]
— Improve renderStateBlock hash generation for better sorting [[BR]]
— Move most state related gfx changes from API implementation to the GFXDevice class [[BR]]
— Move viewport stack to the GFXDevice class [[BR]]
— Added various performance counters (frame duration with round-robin query system, draw call count, etc) [[BR]]
— Fixed and improved clip plane management [[BR]]
— Delete client-side texture data after GPU upload [[BR]]
[[BR]]
- New features: [[BR]]
— Added callback support to the Task class so that a specific task may call a function in the main thread upon completion [[BR]]
— Added mouse-wheel zoom support to Orbit/ThirdPerson cameras [[BR]]
— Added 2D Texture Array support (e.g. used for terrain textures) [[BR]]

259 Diff Diff k1ngp1n picture k1ngp1n Sun 27 Apr, 2014 18:24:52 +0000

[Ionut][[BR]]
- Implemented Exponential Stable Cascaded Shadow Maps for directional lights (still buggy, but basically working) [[BR]]
— CSM settings (resolution, number of splits, etc) are part of the scene render state [[BR]]
- SGN can skip rendering for the current frame if they are not ready (e.g. OnDraw can now return false or materials can fail to bind) [[BR]]
- Frustum class is now using the Plane class [[BR]]
- Removed Math SIMD implementation as the compiler generated code will always be faster and safer [[BR]]
- Added a “STUBBED” macro for outputing to the error stream of important messages (instead of using #pragma message) [[BR]]
- Added “freeze time” logic to pause/resume updates with or without freezing the GUI too [[BR]]
- Added “processGUI” method the every Scene class to separate time-sensitive GUI updates from game logic loop [[BR]]
- GLSL <-> Vertex Buffer bind locations are automatically set for every vertex shader [[BR]]
- Added basic support for compute shaders [[BR]]
- Removed most OS define checks to make porting to a new platform easier [[BR]]
- Texture transparency check per-pixel is now using OpenMP [[BR]]
- Texture samplers can now set a border color for CLAMP_TO_BORDER wrap mode [[BR]]
- Removed “Object” suffix from GFX Classes (pixel buffer, vertex buffer, frame buffer, etc) [[BR]]
- Stop processing scene input when application looses focus [[BR]]
- SceneGraphNode class is now responsible for updating SGNComponents on draw and calling its _node’s OnDraw method [[BR]]
- UBOs can now list all of the active uniforms inside a block with info such as type and offset [[BR]]
- Removed deprecated ‘GLCheck’ macro [[BR]]
- A lot of bug fixes and performance improvements in various places [[BR]]

249 Diff Diff k1ngp1n picture k1ngp1n Mon 31 Mar, 2014 20:42:31 +0000

[Ionut] [[BR]]
- Migrated to platform toolset v100 [[BR]]
- Updated boost to 1.55 [[BR]]
- Moved from “NULL” to “nullptr” [[BR]]
- DevIL is now linked dynamically [[BR]]

247 Diff Diff k1ngp1n picture k1ngp1n Sun 16 Feb, 2014 16:36:06 +0000

[Ionut] [[BR]]
- Fixed VSM rendering [[BR]]
- Added Z-prePass as a separate render stage [[BR]]
- Added GL error checking and asserts to “Profile” builds [[BR]]
- Fixed bad XML material dump (invalid file name bug) [[BR]]
- Fixed random crashes [[BR]]
- Shadow cast/receive is now a node property, and not a material property [[BR]]
- Fixed an issue with previous RenderPassManager lock mechanism (clearing the queue on frame end to prevent infinite lock) [[BR]]
- Added depth buffer preview (F10 key) [[BR]]

224 Diff Diff k1ngp1n picture k1ngp1n Thu 09 Jan, 2014 21:30:55 +0000

[Ionut] [[BR]]
- More work and bugfixes with the branch reintegration [[BR]]
- Fixed GPU performance queries [[BR]]
- Fixed some FBO creation issues with multisampled textures [[BR]]
- Current issues: [[BR]]
— Terrain rendering not working on AMD [[BR]]
— Reflections not working on AMD & nVidia [[BR]]
— Grass rendering using TRIANGLE_STRIPS not complete yet [[BR]]

221 Diff Diff k1ngp1n picture k1ngp1n Wed 08 Jan, 2014 18:50:02 +0000

[Ionut] [[BR]]
- Merged branch “Shadows And Animations” back into trunk [[BR]]
- Added DoxygenGUI project file [[BR]]

  • Buggy *
213 Diff Diff k1ngp1n picture k1ngp1n Mon 06 Jan, 2014 23:13:05 +0000

[Ionut] [[BR]]
- Removed FTGL text rendering and replaced it with Mikko Mononen’s Font-stash library (https://github.com/memononen/fontstash)[[BR]]
— Used 3.3 Core Profile rendering (VAO with GL_STREAM_DRAW) with fontstash [[BR]]

201 Diff Diff k1ngp1n picture k1ngp1n Sat 07 Dec, 2013 19:28:42 +0000

[Ionut] [[BR]]
- More work on the fixed-timestep implementation [[BR]]

199 k1ngp1n picture k1ngp1n Fri 06 Dec, 2013 20:07:47 +0000

[Ionut] [[BR]]
- High precision, microsecond level, U64 timing system [[BR]]
— Framerate renamed to ApplicationTimer and moved to Core [[BR]]
— A lot of possible bugs. Not everything was tested for proper conversion [[BR]]
- Window focus detection [[BR]]
— Disable input if window is out of focus [[BR]]