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

#include "Headers/Console.h"

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

namespace Divide {

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

std::thread Console::_printThread;
std::atomic_bool Console::_running = false;
vectorImpl<Console::ConsolePrintCallback> Console::_guiConsoleCallbacks;

//Use moodycamel's implementation of a concurent queue due to its "Knock-your-socks-off blazing fast performance."
//https://github.com/cameron314/concurrentqueue
namespace {
    struct MyTraits : public moodycamel::ConcurrentQueueDefaultTraits
    {
        static const size_t BLOCK_SIZE = MAX_CONSOLE_ENTRIES;
    };

    moodycamel::BlockingConcurrentQueue<Console::OutputEntry, MyTraits>& outBuffer() {
        static moodycamel::BlockingConcurrentQueue<Console::OutputEntry, MyTraits> outputBuffer;
        return outputBuffer;
    }

};

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

const char* Console::formatText(const char* format, ...) noexcept {
    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 EntryType type) {
    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 << (type == EntryType::Error ? " Error: " : type == EntryType::Warning ? " Warning: " : "");
    outStream << text;
    outStream << (newline ? "\n" : "");
}

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

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

        OutputEntry entry;
        entry._text = outStream.str();
        entry._type = type;

        //moodycamel::ProducerToken ptok(outBuffer());
        if (!outBuffer().enqueue(/*ptok, */entry)) {
            // ToDo: Something happened. Handle it, maybe? -Ionut
        }
    }
}

void Console::outThread() {
    //moodycamel::ConsumerToken ctok(outBuffer());
    OutputEntry entry;
    while (_running) {
        if (outBuffer().wait_dequeue_timed(/*ctok, */entry, Time::Milliseconds(16))) {
            ((entry._type == EntryType::Error && _errorStreamEnabled) ? std::cerr : std::cout) << entry._text.c_str();

            for (const Console::ConsolePrintCallback& cbk : _guiConsoleCallbacks) {
                cbk(entry);
            }
        } else {
            std::this_thread::yield();
        }
    }
    std::cout << "------------------------------------------" << std::endl
              << std::endl << std::endl << std::endl;

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

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

void Console::stop() {
    if (_running) {
        _enabled = false;
        _running = false;
        _printThread.join();
    }
}
};

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

Diff revisions: vs.
Revision Author Commited Message
1012 Diff Diff IonutCava picture IonutCava Mon 15 Jan, 2018 17:21:32 +0000

[Ionut]
- Update boost to v1.66
- Performance optimizations

1011 Diff Diff IonutCava picture IonutCava Fri 12 Jan, 2018 17:21:29 +0000

[Ionut]
- Performance improvements

993 Diff Diff IonutCava picture IonutCava Sun 10 Dec, 2017 20:07:57 +0000

[Ionut]
- Finished initial port of the old scene graph system to the new ECS based system.
- Finished converting 2 components to the new ECS system: Transform and RigidBody
- Fixed the “Deploy” build error with the CEGUI OpenGL renderer.
- Compilation now needs C++14 support (it’s sufficiently wide-spread now)

977 Diff Diff IonutCava picture IonutCava Mon 20 Nov, 2017 17:13:16 +0000

[Ionut]
- Add an “ApplicationOutput” class that the Editor uses to show console entries and parse commands
- Add “Warning” messages to console outputs

945 Diff Diff IonutCava picture IonutCava Wed 13 Sep, 2017 11:50:59 +0000

[Ionut]
- Rework Task <-> TaskPool work status signalling
- Add UniqueLock typedef

944 Diff Diff IonutCava picture IonutCava Tue 12 Sep, 2017 14:49:05 +0000

[Ionut]
- Fix the Console producer/consumer conditional variable system
- Re-enable Prio queues in TaskPool, but specify only FIFO queues in Kernel (to help debugging later on)

919 Diff Diff IonutCava picture IonutCava Wed 26 Jul, 2017 22:37:18 +0000

[Ionut]
- Add a configurable log printing system to the networking library.
- Remove the need to specify swap buffer necessity with endFrame calls. Swap buffer requirement is now a per-window property.
- Do not load an image file multiple times for the same texture. cache data for each array layer to speed up duplicates. ToDo: Cache data globally?
- Other small bugfixes

918 Diff Diff IonutCava picture IonutCava Fri 21 Jul, 2017 13:16:04 +0000

[Ionut]
- Platform code robustness tweaks

891 Diff Diff IonutCava picture IonutCava Mon 15 May, 2017 16:18:45 +0000

[Ionut]
- Some memory-friendly optimizations

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

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