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
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
#include <CEGUI/CEGUI.h>
#include "core.h"

#include "Headers/GUIConsole.h"
#include "Headers/GUIConsoleCommandParser.h"
#include "CEGUIAddons/Headers/CEGUIFormattedListBox.h"

#include "Core/Headers/Application.h"
#include "Core/Headers/ParamHandler.h"

#if defined(_MSC_VER)
#	pragma warning( push )
#		pragma warning( disable: 4324 ) //<structure was padded ...
#		pragma warning( disable: 4189 ) //<local variable is initialized but not referenced
#elif defined(__GNUC__)
#	pragma GCC diagnostic push
#		pragma GCC diagnostic ignored "-Wall"
#endif

#	ifndef CEGUI_DEFAULT_CONTEXT
#		define CEGUI_DEFAULT_CONTEXT CEGUI::System::getSingleton().getDefaultGUIContext()
#	endif


#if defined(_MSC_VER)
#	pragma warning( pop )
#elif defined(__GNUC__)
#	pragma GCC diagnostic pop
#endif

namespace Divide {

GUIConsole::GUIConsole() : _init(false),
                           _closing(false),
                           _editBox(nullptr),
                           _lastMsgError(false),
                           _inputHistoryIndex(0),
                           _outputWindow(nullptr),
                           _consoleWindow(nullptr),
                           _outputBuffer(_CEGUI_MAX_CONSOLE_ENTRIES)
{
    // we need a default command parser, so just create it here
    _cmdParser = MemoryManager_NEW GUIConsoleCommandParser();
}

GUIConsole::~GUIConsole()
{
	_closing = true;

    if (_consoleWindow) {
		setVisible(false);
		_init = false;
        CEGUI_DEFAULT_CONTEXT.getRootWindow()->removeChild(_consoleWindow);
		MemoryManager::DELETE(_consoleWindow);
    }
    MemoryManager::DELETE( _cmdParser );

    _outputBuffer.clear();
}

void GUIConsole::CreateCEGUIWindow(){
    if (_init) {
        ERROR_FN(Locale::get("ERROR_CONSOLE_DOUBLE_INIT"));
    }
    // load the console Window from the layout file
    const std::string& layoutFile = ParamHandler::getInstance().getParam<std::string>("GUI.consoleLayout");
    _consoleWindow = CEGUI::WindowManager::getSingletonPtr()->loadLayoutFromFile(layoutFile);

    if (_consoleWindow){
        // Add the Window to the GUI Root Sheet
        CEGUI_DEFAULT_CONTEXT.getRootWindow()->addChild(_consoleWindow);
        _outputWindow = static_cast<CEGUI::Listbox*>(_consoleWindow->getChild("ChatBox"));
        _editBox = static_cast<CEGUI::Editbox*>(_consoleWindow->getChild("EditBox"));
        // Now register the handlers for the events (Clicking, typing, etc)
        RegisterHandlers();
    }else{
        // Loading layout from file, failed, so output an error Message.
        CEGUI::Logger::getSingleton().logEvent("Error: Unable to load the ConsoleWindow from .layout");
        ERROR_FN(Locale::get("ERROR_CONSOLE_LAYOUT_FILE"),layoutFile.c_str());
    }

    _init = true;
    PRINT_FN(Locale::get("GUI_CONSOLE_CREATED"));
}

void GUIConsole::RegisterHandlers(){
    assert(_editBox != nullptr);
    //We need to monitor text/command submission from the editBox
    _editBox->subscribeEvent(CEGUI::Editbox::EventTextAccepted,
                             CEGUI::Event::Subscriber(&GUIConsole::Handle_TextSubmitted,this));
    //we also monitor any key presses to make sure we do not accidentally hide the console in the middle of a sentence
    _editBox->subscribeEvent(CEGUI::Editbox::EventKeyUp,
                             CEGUI::Event::Subscriber(&GUIConsole::Handle_TextInput,this));
}

bool GUIConsole::Handle_TextInput(const CEGUI::EventArgs &e){
    assert(_editBox != nullptr);
    const CEGUI::KeyEventArgs* keyEvent = static_cast<const CEGUI::KeyEventArgs*>(&e);
    //Just get the current text string from the editbox at each keypress. Performance isn't a issue for console commands
    if(!_inputHistory.empty()){
        if(keyEvent->scancode == CEGUI::Key::ArrowUp ){
            _inputHistoryIndex--;
            if(_inputHistoryIndex < 0)
                _inputHistoryIndex = (I16)_inputHistory.size()-1;
            _editBox->setText(_inputHistory[_inputHistoryIndex].c_str());
        }
        if(keyEvent->scancode == CEGUI::Key::ArrowDown){
            _inputHistoryIndex++;
            if(_inputHistoryIndex >= (I32)_inputHistory.size())
                _inputHistoryIndex = 0;
            _editBox->setText(_inputHistory[_inputHistoryIndex].c_str());
        }
    }

    _inputBuffer = _editBox->getText().c_str();
    return true;
}

bool GUIConsole::Handle_TextSubmitted(const CEGUI::EventArgs &e){
    assert(_editBox != nullptr);
    // Since we have that string, lets send it to the TextParser which will handle it from here
    _cmdParser->processCommand(_inputBuffer.c_str());
    // Now that we've finished with the text, we need to ensure that we clear out the EditBox.
    // This is what we would expect to happen after we press enter
    _editBox->setText("");
    _inputHistory.push_back(_inputBuffer);
    //Keep command history low
    if (_inputHistory.size() > _CEGUI_MAX_CONSOLE_ENTRIES) {
        _inputHistory.pop_front();
    }
    _inputHistoryIndex = (I16)_inputHistory.size()-1;
    //reset the inputbuffer so we can handle console closing properly
    _inputBuffer.clear();
    return true;
}

void GUIConsole::setVisible(bool visible){
	if (!_init) {
		CreateCEGUIWindow();
	}
    //if it's not the first key (e.g., if the toggle key is "~", then "lorem~ipsum" should not close the Window)
	if (!_inputBuffer.empty()){
		return;
	}
    assert(_editBox != nullptr);
    _consoleWindow->setVisible(visible);

    if(visible){
       _editBox->activate();
    }else{
       _editBox->deactivate();
       _editBox->setText("");
    }

    printText(visible ? "Toggling console display: ON" : "Toggling console display: OFF", false);
    if (_outputWindow->getItemCount() > 0 && visible) {
        _outputWindow->ensureItemIsVisible(_outputWindow->getListboxItemFromIndex(_outputWindow->getItemCount() - 1));
    }
}

bool GUIConsole::isVisible(){
    if (!_init) {
        return false;
    }
    return _consoleWindow->isVisible();
}

void GUIConsole::printText(const char* output, bool error){
    WriteLock w_lock(_outputLock);
    _outputBuffer.push_back(std::make_pair(output, error));
}

void GUIConsole::OutputText(const char* inMsg, const bool error) {
    if (_outputWindow->getItemCount() == _CEGUI_MAX_CONSOLE_ENTRIES - 1) {
        _outputWindow->removeItem(_outputWindow->getListboxItemFromIndex(0));
    }

    CEGUI::FormattedListboxTextItem* crtItem = nullptr;
    crtItem = new CEGUI::FormattedListboxTextItem(CEGUI::String(inMsg), 
                                                  error ? CEGUI::Colour(1.0f, 0.0f, 0.0f) : 
                                                          CEGUI::Colour(0.4f, 0.4f, 0.3f), 
                                                  CEGUI::HTF_WORDWRAP_LEFT_ALIGNED);
    crtItem->setTextParsingEnabled(false);
    _outputWindow->addItem(crtItem);
    _outputWindow->ensureItemIsVisible(crtItem);
}

void GUIConsole::update(const U64 deltaTime){
    if(!_init || !Application::getInstance().isMainThread() || _closing){
        return;
    }
    if (!isVisible()) {
        return;
    }
    WriteLock w_lock(_outputLock);
    std::pair<CEGUI::String, bool> message;
    while(!_outputBuffer.empty()){
        message = _outputBuffer.front();
        if (_lastMsgError != message.second){
            _lastMsgError = message.second;
            OutputText(_lastMsg.c_str(), _lastMsgError);
            _lastMsg.clear();
        }

        _lastMsg.append(message.first.c_str());
        _lastMsg.append("\n");
        _outputBuffer.pop_front();
    }
    _outputBuffer.clear();
     
    if(!_lastMsg.empty()){
        OutputText(_lastMsg.c_str(), _lastMsgError);
        _lastMsg.clear();
    }
}

};

Commits for Divide-Framework/trunk/Source Code/GUI/GUIConsole.cpp

Diff revisions: vs.
Revision Author Commited Message
331 Diff Diff IonutCava picture IonutCava Sat 06 Dec, 2014 20:53:45 +0000

[Ionut]
- Limited line length to 132 characters to improve readability and diff-comparisons
- Refactored memory allocation/deallocation functions
- Fixed a few compatibility issues with HashMap.h
- Fixed a bug in GPU Skinning shaders (cast a float to int)

326 Diff Diff IonutCava picture IonutCava Tue 30 Sep, 2014 21:11:32 +0000

[Ionut]
- Fixed more memory leaks
- Simplified Task interface and timing System
- Improved compatibility between Boost, STL and EASTL with random combinations of vectors, strings and maps
- Simplified Light class by removing the “slot” member
- Random optimizations

325 Diff Diff IonutCava picture IonutCava Wed 17 Sep, 2014 20:06:13 +0000

[Ionut]
- Reworked transform system:
— Parent transform chain system moved from Transform class to the PhysicsComponent
— PhysicsComponent now returns all transform values needed both global and local (still needs heavy optimization and caching)

- Reworked SceneGraph node management:
— Proper ref counting of SceneNodes and proper removing of resource (ResourceCache is now empty on destruction, as it should be)
— Removed parent transform tracking as that’s the PhysicsComponent’s responsibility
— Only nodes loaded via the ResourceCache are allowed to be added to the SceneGraph (added proper loaders for Impostors, Sky, etc)

- Optimized some of the math classes (mat4, mat3)

321 Diff Diff IonutCava picture IonutCava Wed 03 Sep, 2014 22:05:15 +0000

[Ionut]
- Added support (and enabled by default) for the EASTL library (http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2007/n2271.html / https://github.com/paulhodge/EASTL)
— Strings, vectors and hash_maps can be combined from EASTL, STL and Boost (not all combinations work. e.g. EASTL strings with STL/Boost containers due to the lack of a proper hash function)

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)

309 Diff Diff IonutCava picture IonutCava Sat 16 Aug, 2014 22:57:33 +0000

[Ionut]
- Added an InputAggregator interface to standardize input event handling

308 Diff Diff IonutCava picture IonutCava Sat 16 Aug, 2014 19:49:31 +0000

[Ionut]
- Moved Transform from SceneGraphNode to PhysicsComponent and modified BoundingBox update system based on transform update
- Added PhysicsAsset to PhysicsComponent for interfacing with PshysicsAPIs (e.g. PhysXActor inherits PhysicsAsset)
- PhysicsAsset keeps track of the parent PhysicsComponent to have direct access to a node’s transform
- Rewrote GUIConsole to only print items when visible, and use a single circular buffer for entries.
- Updated GUI input system to match the interface that both Kernel and SceneManager share (should probably abstract all the input methods in a class and have Kernel, SceneManager, Scene and GUI inherit from that. In next commit.)
- Updated CEGUI to probably match the OIS states(mouse, keyboard, etc) and properly inject time inputs.

285 Diff Diff IonutCava picture IonutCava Wed 02 Jul, 2014 18:33:25 +0000

[Ionut][[BR]]
- Per SGN shader data implementation part 1.75 / 2 [[BR]]
— Upload node data into a SSBO in one single call [[BR]]
- Re-factored LightManager to upload light info and shadow info in single upload calls [[BR]]
- Improved GUIConsole load performance by using a boost::circular_buffer for initial messages [[BR]]

268 Diff Diff IonutCava picture IonutCava Wed 04 Jun, 2014 10:20:27 +0000

[IonutCava] [[BR]]
- Terrain and vegetation updates: [[BR]]
— Use standard phong lighting model [[BR]]
— Separate grass patches per chunk [[BR]]
— Reduce number of required texture bind points for terrain by adding both textures and normal maps in a single texture array [[BR]]
— Draw terrain with 2 drawcalls (using glMultiDrawElements twice, once for LoD == 0 and once for LoD > 0) [[BR]]
[[BR]]
- Buffer management updates: [[BR]]
— Unified buffer binding system [[BR]]
— Made Uniform buffer objects visible to all classes and moved lightUBO to LightManager, matricesUBO to GFXDevice etc [[BR]]
— Added initial support for Shader Buffer Objects [[BR]]
— Moved viewport management to GFXDevice class [[BR]]
[[BR]]
- Rendering improvements: [[BR]]
— Added Hi-Z occlusion culling to instanceCull shader (using Hi-Z depth buffer constructed in GFXDevice class) [[BR]]
— Resolved issues with shadow maps overriding texture bind locations [[[BR]]
— Improved shader and shader program loading [[BR]]
— Improved material transparency support [[BR]]
— Added buffer lock manager class from “Approaching Zero Driver Overhead in OpenGL (Presented by NVIDIA)” speech at GDC14 [[BR]]

265 k1ngp1n picture k1ngp1n Tue 27 May, 2014 19:47:56 +0000

[Ionut] [[BR]]
- reworked uniform buffer binding [[BR]]
- modified framebuffer mipmap update [[BR]]