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
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
#include "stdafx.h"

#include "Headers/FrameListenerManager.h"

#include "Core/Headers/Console.h"
#include "Core/Headers/StringHelper.h"
#include "Core/Math/Headers/MathHelper.h"

#include "Utility/Headers/Localization.h"

namespace Divide {

FrameListenerManager::FrameListenerManager()
    : Singleton()
{
    for (EventTimeMap& map : _eventTimers) {
        map.reserve(256);
    }
}

FrameListenerManager::~FrameListenerManager()
{
}

/// Register a new Frame Listener to be processed every frame
void FrameListenerManager::registerFrameListener(FrameListener* listener,
                                                 U32 callOrder) {
    assert(listener != nullptr);

    // Check if the listener has a name or we should assign an id
    if (listener->getListenerName().empty()) {
        listener->setName(Util::StringFormat("generic_f_listener_%d", listener->getGUID()));
    }

    listener->setCallOrder(callOrder);

    WriteLock w_lock(_listenerLock);
    insert_sorted(_listeners, listener, std::less<>());
}

/// Remove an existent Frame Listener from our collection
void FrameListenerManager::removeFrameListener(FrameListener* const listener) {
    assert(listener != nullptr);

    I64 targetGUID = listener->getGUID();

    UpgradableReadLock ur_lock(_listenerLock);
    vectorImpl<FrameListener*>::const_iterator it;
    it = std::find_if(std::cbegin(_listeners), std::cend(_listeners),
                      [targetGUID](FrameListener const* fl) -> bool
                      {
                        return fl->getGUID() == targetGUID;
                      });

    if (it != std::cend(_listeners)) {
        UpgradeToWriteLock w_lock(ur_lock);
        _listeners.erase(it);
    } else {
        Console::errorfn(Locale::get(_ID("ERROR_FRAME_LISTENER_REMOVE")), listener->getListenerName().c_str());
    }
}

/// For each listener, notify of current event and check results
/// If any Listener returns false, the whole manager returns false for this
/// specific step
/// If the manager returns false at any step, the application exists
bool FrameListenerManager::frameEvent(const FrameEvent& evt) {
    switch (evt._type) {
        case FrameEventType::FRAME_EVENT_STARTED:
            return frameStarted(evt);
        case FrameEventType::FRAME_PRERENDER_START:
            return framePreRenderStarted(evt);
        case FrameEventType::FRAME_PRERENDER_END:
            return framePreRenderEnded(evt);
        case FrameEventType::FRAME_POSTRENDER_START:
            return framePostRenderStarted(evt);
        case FrameEventType::FRAME_POSTRENDER_END:
            return framePostRenderEnded(evt);
        case FrameEventType::FRAME_EVENT_PROCESS:
            return frameRenderingQueued(evt);
        case FrameEventType::FRAME_EVENT_ENDED:
            return frameEnded(evt);
    };

    return false;
}

bool FrameListenerManager::frameStarted(const FrameEvent& evt) {
    ReadLock r_lock(_listenerLock);
    for (FrameListener* listener : _listeners) {
        if (!listener->frameStarted(evt)) {
            return false;
        }
    }
    return true;
}

bool FrameListenerManager::framePreRenderStarted(const FrameEvent& evt) {
    ReadLock r_lock(_listenerLock);
    for (FrameListener* listener : _listeners) {
        if (!listener->framePreRenderStarted(evt)) {
            return false;
        }
    }
    return true;
}

bool FrameListenerManager::framePreRenderEnded(const FrameEvent& evt) {
    ReadLock r_lock(_listenerLock);
    for (FrameListener* listener : _listeners) {
        if (!listener->framePreRenderEnded(evt)) {
            return false;
        }
    }
    return true;
}

bool FrameListenerManager::frameRenderingQueued(const FrameEvent& evt) {
    ReadLock r_lock(_listenerLock);
    for (FrameListener* listener : _listeners) {
        if (!listener->frameRenderingQueued(evt)) {
            return false;
        }
    }
    return true;
}

bool FrameListenerManager::framePostRenderStarted(const FrameEvent& evt) {
    ReadLock r_lock(_listenerLock);
    for (FrameListener* listener : _listeners) {
        if (!listener->framePostRenderStarted(evt)) {
            return false;
        }
    }
    return true;
}

bool FrameListenerManager::framePostRenderEnded(const FrameEvent& evt) {
    ReadLock r_lock(_listenerLock);
    for (FrameListener* listener : _listeners) {
        if (!listener->framePostRenderEnded(evt)) {
            return false;
        }
    }
    return true;
}

bool FrameListenerManager::frameEnded(const FrameEvent& evt) {
    ReadLock r_lock(_listenerLock);
    for (FrameListener* listener : _listeners) {
        if (!listener->frameEnded(evt)) {
            return false;
        }
    }
    return true;
}

/// When the application is idle, we should really clear up old events
void FrameListenerManager::idle() {
}

/// Please see the Ogre3D documentation about this
void FrameListenerManager::createEvent(const U64 currentTimeUS, FrameEventType type, FrameEvent& evt) {
    evt._currentTimeUS = currentTimeUS;
    evt._timeSinceLastEventUS = calculateEventTime(evt._currentTimeUS, FrameEventType::FRAME_EVENT_ANY);
    evt._timeSinceLastFrameUS = calculateEventTime(evt._currentTimeUS, type);
    evt._type = type;
}

U64 FrameListenerManager::calculateEventTime(const U64 currentTimeUS, FrameEventType type) {
    EventTimeMap& times = _eventTimers[to_U32(type)];
    times.push_back(currentTimeUS);

    if (times.size() == 1) {
        return 0;
    }

    EventTimeMap::const_iterator it = std::cbegin(times);
    EventTimeMap::iterator end = std::end(times) - 2;

    while (it != end) {
        if (currentTimeUS - *it > 0) {
            ++it;
        } else {
            break;
        }
    }

    times.erase(std::cbegin(times), it);
    return (times.back() - times.front()) / Time::SecondsToMicroseconds(times.size() - 1);
}
};

Commits for Divide-Framework/trunk/Source Code/Managers/FrameListenerManager.cpp

Diff revisions: vs.
Revision Author Commited Message
970 Diff Diff IonutCava picture IonutCava Mon 13 Nov, 2017 17:16:44 +0000

[Ionut]
- ImWindow <-> DisplayWindow fixes

968 Diff Diff IonutCava picture IonutCava Tue 07 Nov, 2017 17:32:31 +0000

[Ionut]
- Consistent naming between timing variables

890 Diff Diff IonutCava picture IonutCava Sun 14 May, 2017 20:54:59 +0000

[Ionut]
- Add pre-compiled header support
- Initial code for per-stage tessellation computation

867 Diff Diff IonutCava picture IonutCava Mon 20 Feb, 2017 17:01:12 +0000

[IonutCava]
- Rename to_XNN and to_const_XNN functions to reflect the target data type they are converting to.
- Cleanup Angle namespace and remove all “inDegrees” parameters from rotation functions. Use aliases to differentiate between Degree and Radian parameters.
- Profile guided optimizations.

830 Diff Diff IonutCava picture IonutCava Wed 25 Jan, 2017 17:29:44 +0000

[IonutCava]
- Add a new Platform element: File
— Move all predefined paths to FileManagement System
- Split MathHelper into MathHelper and StringHelper

818 Diff Diff IonutCava picture IonutCava Mon 16 Jan, 2017 17:23:20 +0000

[IonutCava]
- Units get their bound node setup by the SGN UnitComponent and not during creation
- Profile guided optimizations

817 Diff Diff IonutCava picture IonutCava Sun 15 Jan, 2017 21:29:59 +0000

[IonutCava]
- Add a new Unit component to SGNs that holds NPC/Player/etc. objects
- Add support for multiple keyboard+mouse combos and joysticks and add mapping between these and players

804 Diff Diff IonutCava picture IonutCava Thu 01 Dec, 2016 17:20:59 +0000

[IonutCava]
- Singleton elimination update Part I: get it to compile
— The following classes are no longer Singletons: GFXDevice, GL_API, DX_API, SFXWrapper, FmodWrapper, SDLWrapper, ALWrapper, PXDevice, InputInterface, RenderPassManager, SceneManager and ResourceManager;
— Refactor system to a Context / Component based implementation (Pass relevant context to objects: e.g. GFXDevice object to Textures, GUI to GUIElements, etc)
— Make devices and managers components of the kernel
— Allow multiple Resource caches to co-exist. This may prove useful for later when a more fragmented memory model is need (per frame / per scene / global caches / etc)

  • next steps: part II – cleanup/refactor new code, part III – optimise code, part IV – remove remaining Singletons (e.g. Application, ParamHandler, FrameListenerManager, Recast, PostFX and DebugInterface)
714 Diff Diff IonutCava picture IonutCava Thu 26 May, 2016 16:26:23 +0000

[IonutCava]
- Initial code for multithreaded scene load:
— Tasks can have a “sync with gpu” flag that will cause them to use a shared context (so they can call GL functions)
- Added per scene GUI lists that get passed to the main GUI class (still need a base class to hold the map and accessors to avoid code duplication)
- Re-enabled threading unit tests

680 IonutCava picture IonutCava Thu 14 Apr, 2016 16:15:38 +0000

[IonutCava]
- Added a mat2 class (untested)
- Added static asserts to matrices, vectors and quaternions to allow only arithmetic (sans bool) data types
- Added more vector unit tests
- Added unit tests for matrices
- D32 finally renamed to D64 as the VC++ compiler is considered as the reference compiler