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
#include "Headers/Console.h"

#include "Core/Time/Headers/ApplicationTimer.h"
#include <iomanip>
#include <stdarg.h>
#include <thread>
#include <iostream>

namespace Divide {

bool Console::_timestamps = false;
bool Console::_threadID = false;
bool Console::_enabled = true;

std::thread Console::_printThread;

std::atomic_bool Console::_running;
Console::ConsolePrintCallback Console::_guiConsoleCallback;

//Use moodycamel's implementation of a concurent queue due to its "Knock-your-socks-off blazing fast performance."
//https://github.com/cameron314/concurrentqueue
moodycamel::ConcurrentQueue<Console::OutputEntry> Console::_outputBuffer(MAX_CONSOLE_ENTRIES);

//! Do not remove the following license without express permission granted by DIVIDE-Studio
void Console::printCopyrightNotice() {
    std::cout << "-------------------------------------------------------------"
                 "-----------------\n";
    std::cout << "Copyright (c) 2017 DIVIDE-Studio\n";
    std::cout << "Copyright (c) 2009 Ionut Cava\n\n";
    std::cout << "This file is part of DIVIDE Framework.\n\n";
    std::cout << "Permission is hereby granted, free of charge, to any person "
                 "obtaining a copy of this software\n";
    std::cout << "and associated documentation files (the 'Software'), to deal "
                 "in the Software without restriction,\n";
    std::cout << "including without limitation the rights to use, copy, "
                 "modify, merge, publish, distribute, sublicense,\n";
    std::cout << "and/or sell copies of the Software, and to permit persons to "
                 "whom the Software is furnished to do so,\n";
    std::cout << "subject to the following conditions:\n\n";
    std::cout << "The above copyright notice and this permission notice shall "
                 "be included in all copies or substantial portions of the "
                 "Software.\n\n";
    std::cout << "THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY "
                 "KIND, EXPRESS OR IMPLIED,\n";
    std::cout << "INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF "
                 "MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND "
                 "NONINFRINGEMENT.\n";
    std::cout << "IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE "
                 "FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,\n";
    std::cout << "WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING "
                 "FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE\n";
    std::cout << "OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\n\n";
    std::cout << "For any problems or licensing issues I may have overlooked, "
                 "please contact: \n";
    std::cout << "E-mail: ionut.cava@divide-studio.com | Website: \n"
                 "http://wwww.divide-studio.com\n";
    std::cout << "-------------------------------------------------------------"
                 "------------------\n\n";
}

const char* Console::formatText(const char* format, ...) {
    static thread_local char textBuffer[CONSOLE_OUTPUT_BUFFER_SIZE + 1];
    va_list args;
    va_start(args, format);
    assert(_vscprintf(format, args) + 1 < CONSOLE_OUTPUT_BUFFER_SIZE);
    vsprintf(textBuffer, format, args);
    va_end(args);
    return textBuffer;
}

void Console::decorate(std::ostream& outStream, const char* text, const bool newline, const bool error) {
    if (_timestamps) {
        outStream << "[ " << std::internal
                          << std::setw(9)
                          << std::setprecision(3)
                          << std::setfill('0')
                          << std::fixed
                          << Time::ElapsedSeconds(true)
                  << " ] ";
    }
    if (_threadID) {
        outStream << "[ " << std::this_thread::get_id() << " ] ";
    }

    outStream << (error ? " Error: " : "");
    outStream << text;
    outStream << (newline ? "\n" : "");
}

void Console::output(std::ostream& outStream, const char* text, const bool newline, const bool error) {
    if (_enabled) {
        decorate(outStream, text, newline, error);
    }
}

void Console::output(const char* text, const bool newline, const bool error) {
    if (_enabled) {
        stringstreamImplBest outStream;
        decorate(outStream, text, newline, error);

        OutputEntry entry;
        entry._error = error;
        entry._text = outStream.str();

        //moodycamel::ProducerToken ptok(_outputBuffer);
        WAIT_FOR_CONDITION_TIMEOUT(_outputBuffer.enqueue(/*ptok, */entry),
                                   Time::SecondsToMilliseconds(1.0));
    }
}

void Console::outThread() {
    //moodycamel::ConsumerToken ctok(_outputBuffer);
    while (_running) {
        OutputEntry entry;
        if (_outputBuffer.try_dequeue(/*ctok, */entry)) {
            std::ostream& outStream = entry._error ? std::cerr : std::cout;
            outStream << entry._text.c_str();

            if (_guiConsoleCallback) {
                _guiConsoleCallback(entry._text.c_str(), entry._error);
            }
        }  else {
            std::this_thread::sleep_for(std::chrono::milliseconds(16));
        }
    }
}

void Console::start() {
    _running = true;
    _printThread = std::thread(&Console::outThread);
    setThreadName(&_printThread, "CONSOLE_OUT_THREAD");
}

void Console::stop() {
    _running = false;

    OutputEntry entry;
    entry._text = "------------------------------------------";
    _outputBuffer.enqueue(entry);
    _printThread.join();

    std::cerr << std::flush;
    std::cout << std::flush;
}
};

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

Diff revisions: vs.
Revision Author Commited Message
869 Diff Diff IonutCava picture IonutCava Sun 26 Feb, 2017 23:25:54 +0000

[IonutCava]
- Reduce loading time using profile guided optimizations
- Camera/Quaternion work in an attempt to fix a weird Yaw-rotation bug.

836 Diff Diff IonutCava picture IonutCava Fri 27 Jan, 2017 14:59:56 +0000

[IonutCava]
- Update copyright notice

833 Diff Diff IonutCava picture IonutCava Thu 26 Jan, 2017 22:04:33 +0000

[IonutCava]
- Fix most build errors. Divide-Server does not build for now.

758 Diff Diff IonutCava picture IonutCava Tue 02 Aug, 2016 16:05:09 +0000

[IonutCava]
- Added a cross platform method of naming threads (helps with debugging)
- Reduced dependency on VAR.dvd_drawID in shaders.
- Work on Single/Multi thread toggle for GFX resource loading (crashes, bugs, etc)
- Fix a bug in TaskPool where task states were never actually updated properly
- Change threadpool implementation to use std::thread instead of boost::thread

728 Diff Diff IonutCava picture IonutCava Wed 15 Jun, 2016 16:04:33 +0000

[IonutCava]
- Updates and fixes to shadow mapping.
- Fixed a race condition in console::output regarding redirection of events to the GUI
- Attempting to fix particle emitter:
— Rewrite GenericVertexData for easier debugging/processing
— Split attributes and buffers into separate classes
— Not finished / buggy / crashes
- Fixed an issue with scene switching regarding PhysicsSceneInterface. Caused race conditions related crashes
- Fixed an issue with scene save data loading. Moved Load system to main thread after loading finishes

712 Diff Diff IonutCava picture IonutCava Tue 24 May, 2016 16:18:37 +0000

[IonutCava]
- Added the concept of “buffer” to be used by GenericVertexData and ShaderBuffer without caring if it’s persistent or not.
— Persistent buffers handle their own locking instead of relying on the parent class
- HiZ occlusion culling fixes and optimizations

693 Diff Diff IonutCava picture IonutCava Thu 28 Apr, 2016 16:19:35 +0000

[IonutCava]
- Cleanup Time and Profiling code

689 Diff Diff IonutCava picture IonutCava Fri 22 Apr, 2016 21:12:33 +0000

[IonutCava]
- More code cleanup (profile timers)
- Changed project build settings for better performance in both Debug and Profile targets

679 Diff Diff IonutCava picture IonutCava Wed 13 Apr, 2016 21:21:51 +0000

[IonutCava]
- Add unit tests for task system
- Adapt task system for better modularity
- Split Divide-Game into Game lib and Game executable projects
- Cleanup unit test projects

671 IonutCava picture IonutCava Fri 08 Apr, 2016 16:26:49 +0000

[Ionut]
- Custom memory allocation system part 1:
— Add http://www.codeproject.com/Articles/1089905/A-Custom-STL-std-allocator-Replacement-Improves-Pe
— Add custom allocators to strings and vectors
— Add custom allocators to a few test classes
— No support for aligned memory yet, so vec4<F32> and mat4<F32> vectors use the old allocation system
- Replace more std::async call with our custom task system