|
|
|
@ -4,14 +4,18 @@
@@ -4,14 +4,18 @@
|
|
|
|
|
#include "Log.h" |
|
|
|
|
#include "URL.h" |
|
|
|
|
#include "WebResource.h" |
|
|
|
|
#include "scheduler.h" |
|
|
|
|
|
|
|
|
|
#include <ctime> |
|
|
|
|
#include <iostream> |
|
|
|
|
#include <sys/stat.h> |
|
|
|
|
|
|
|
|
|
const std::unique_ptr<Window> window = std::make_unique<Window>(); |
|
|
|
|
// why can't I const this?
|
|
|
|
|
std::unique_ptr<Scheduler> scheduler = std::make_unique<Scheduler>(); |
|
|
|
|
//URL currentURL;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
bool setWindowContent(URL const& url) { |
|
|
|
|
logDebug() << "main::setWindowContent - " << url << std::endl; |
|
|
|
|
|
|
|
|
@ -36,17 +40,19 @@ bool setWindowContent(URL const& url) {
@@ -36,17 +40,19 @@ bool setWindowContent(URL const& url) {
|
|
|
|
|
std::cout << "Rendering text document" << std::endl; |
|
|
|
|
std::shared_ptr<Node> rootNode = std::make_shared<Node>(NodeType::ROOT); |
|
|
|
|
std::shared_ptr<TagNode> tagNode = std::make_shared<TagNode>(); |
|
|
|
|
tagNode->tag="p"; |
|
|
|
|
// bind tag to root
|
|
|
|
|
tagNode->parent = rootNode; |
|
|
|
|
rootNode->children.push_back(tagNode); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
std::shared_ptr<TextNode> textNode = std::make_shared<TextNode>(); |
|
|
|
|
textNode->text = res.raw; |
|
|
|
|
tagNode->tag="p"; |
|
|
|
|
|
|
|
|
|
// bind text to tag
|
|
|
|
|
textNode->parent = tagNode; |
|
|
|
|
tagNode->children.push_back(textNode); |
|
|
|
|
|
|
|
|
|
// bind tag to root
|
|
|
|
|
tagNode->parent = rootNode; |
|
|
|
|
rootNode->children.push_back(tagNode); |
|
|
|
|
// send NodeTree to window
|
|
|
|
|
window->setDOM(rootNode); |
|
|
|
|
} else { |
|
|
|
@ -112,11 +118,19 @@ int main(int argc, char *argv[]) {
@@ -112,11 +118,19 @@ int main(int argc, char *argv[]) {
|
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
while (!glfwWindowShouldClose(window->window)) { |
|
|
|
|
//const std::clock_t begin = clock();
|
|
|
|
|
window->render(); |
|
|
|
|
glfwWaitEvents(); // block until something changes
|
|
|
|
|
scheduler->fireTimers(); // render may have taken some time
|
|
|
|
|
double next = scheduler->getNext(); |
|
|
|
|
//std::cout << "next timer at " << next << std::endl;
|
|
|
|
|
if (next == LONG_MAX) { |
|
|
|
|
glfwWaitEvents(); // block until something changes
|
|
|
|
|
} else { |
|
|
|
|
glfwWaitEventsTimeout(next / 1000); |
|
|
|
|
} |
|
|
|
|
scheduler->fireTimers(); // check before we go into render again
|
|
|
|
|
//glfwWaitEventsTimeout(1.0 / 60.0); // increase the cpu from 0% to 2% on idle
|
|
|
|
|
//const std::clock_t end = clock();
|
|
|
|
|
//std::cout << '\r' << std::fixed << (((static_cast<double>(end - begin)) / CLOCKS_PER_SEC) * 1000) << std::scientific << " ms/f " << std::flush;
|
|
|
|
|
} |
|
|
|
|