2016-06-20 22:17:12 +03:00
|
|
|
//#define FULL_DISABLE_PROFILER
|
2016-02-16 23:21:12 +03:00
|
|
|
#include "profiler/profiler.h"
|
2016-02-18 00:49:32 +03:00
|
|
|
#include <chrono>
|
|
|
|
#include <thread>
|
2016-02-18 23:50:10 +03:00
|
|
|
#include <vector>
|
|
|
|
#include <iostream>
|
2016-02-18 00:49:32 +03:00
|
|
|
|
2016-02-18 23:50:10 +03:00
|
|
|
void loadingResources(){
|
2016-03-04 12:17:50 +03:00
|
|
|
PROFILER_BEGIN_FUNCTION_BLOCK_GROUPED(profiler::colors::Lightcyan);
|
2016-06-20 22:17:12 +03:00
|
|
|
std::this_thread::sleep_for(std::chrono::milliseconds(50));
|
2016-02-18 00:49:32 +03:00
|
|
|
}
|
|
|
|
|
2016-05-01 23:32:46 +03:00
|
|
|
|
|
|
|
|
2016-02-18 23:50:10 +03:00
|
|
|
void prepareMath(){
|
2016-03-04 12:17:50 +03:00
|
|
|
PROFILER_BEGIN_FUNCTION_BLOCK_GROUPED(profiler::colors::Blue);
|
2016-06-20 22:17:12 +03:00
|
|
|
//std::this_thread::sleep_for(std::chrono::milliseconds(3));
|
2016-02-18 23:50:10 +03:00
|
|
|
}
|
|
|
|
|
2016-05-01 23:32:46 +03:00
|
|
|
void calcIntersect(){
|
|
|
|
PROFILER_BEGIN_FUNCTION_BLOCK_GROUPED(profiler::colors::Blue);
|
2016-06-20 22:17:12 +03:00
|
|
|
//std::this_thread::sleep_for(std::chrono::milliseconds(4));
|
2016-05-01 23:32:46 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void calcPhys(){
|
|
|
|
PROFILER_BEGIN_FUNCTION_BLOCK_GROUPED(profiler::colors::Blue);
|
|
|
|
calcIntersect();
|
|
|
|
}
|
|
|
|
|
|
|
|
void calcBrain(){
|
|
|
|
PROFILER_BEGIN_FUNCTION_BLOCK_GROUPED(profiler::colors::Blue);
|
2016-06-20 22:17:12 +03:00
|
|
|
//std::this_thread::sleep_for(std::chrono::milliseconds(3));
|
2016-05-01 23:32:46 +03:00
|
|
|
}
|
|
|
|
|
2016-02-18 23:50:10 +03:00
|
|
|
void calculateBehavior(){
|
2016-03-04 12:17:50 +03:00
|
|
|
PROFILER_BEGIN_FUNCTION_BLOCK_GROUPED(profiler::colors::Lightblue);
|
2016-05-01 23:32:46 +03:00
|
|
|
calcPhys();
|
|
|
|
calcBrain();
|
2016-02-18 23:50:10 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void modellingStep(){
|
2016-03-04 12:17:50 +03:00
|
|
|
PROFILER_BEGIN_FUNCTION_BLOCK_GROUPED(profiler::colors::Navy);
|
2016-02-18 23:50:10 +03:00
|
|
|
prepareMath();
|
|
|
|
calculateBehavior();
|
2016-02-18 00:49:32 +03:00
|
|
|
}
|
|
|
|
|
2016-02-18 23:50:10 +03:00
|
|
|
void prepareRender(){
|
2016-03-04 12:17:50 +03:00
|
|
|
PROFILER_BEGIN_FUNCTION_BLOCK_GROUPED(profiler::colors::Lightred);
|
2016-06-20 22:17:12 +03:00
|
|
|
//std::this_thread::sleep_for(std::chrono::milliseconds(8));
|
2016-02-18 23:50:10 +03:00
|
|
|
|
|
|
|
}
|
2016-02-18 00:49:32 +03:00
|
|
|
|
2016-02-18 23:50:10 +03:00
|
|
|
void calculatePhysics(){
|
2016-03-04 12:17:50 +03:00
|
|
|
PROFILER_BEGIN_FUNCTION_BLOCK_GROUPED(profiler::colors::Red);
|
2016-06-20 22:17:12 +03:00
|
|
|
//std::this_thread::sleep_for(std::chrono::milliseconds(8));
|
2016-02-18 23:50:10 +03:00
|
|
|
}
|
2016-02-16 23:21:12 +03:00
|
|
|
|
2016-02-18 23:50:10 +03:00
|
|
|
void frame(){
|
2016-03-04 12:17:50 +03:00
|
|
|
PROFILER_BEGIN_FUNCTION_BLOCK_GROUPED(profiler::colors::Magenta);
|
2016-02-18 23:50:10 +03:00
|
|
|
prepareRender();
|
|
|
|
calculatePhysics();
|
|
|
|
}
|
|
|
|
|
|
|
|
void loadingResourcesThread(){
|
|
|
|
for(int i = 0; i < 10; i++){
|
|
|
|
loadingResources();
|
2016-03-04 12:17:50 +03:00
|
|
|
PROFILER_ADD_EVENT_GROUPED("Resources Loading!",profiler::colors::Cyan);
|
2016-06-20 22:17:12 +03:00
|
|
|
std::this_thread::sleep_for(std::chrono::milliseconds(20));
|
2016-02-18 23:50:10 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void modellingThread(){
|
2016-06-20 22:17:12 +03:00
|
|
|
for (int i = 0; i < 160000; i++){
|
2016-02-18 23:50:10 +03:00
|
|
|
modellingStep();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void renderThread(){
|
2016-06-20 22:17:12 +03:00
|
|
|
for (int i = 0; i < 100000; i++){
|
2016-02-18 23:50:10 +03:00
|
|
|
frame();
|
|
|
|
}
|
|
|
|
}
|
2016-06-20 23:33:14 +03:00
|
|
|
|
|
|
|
void four()
|
|
|
|
{
|
|
|
|
PROFILER_BEGIN_FUNCTION_BLOCK_GROUPED(profiler::colors::Red);
|
|
|
|
std::this_thread::sleep_for(std::chrono::milliseconds(20));
|
|
|
|
}
|
|
|
|
|
|
|
|
void five()
|
|
|
|
{
|
|
|
|
PROFILER_BEGIN_FUNCTION_BLOCK_GROUPED(profiler::colors::Red);
|
|
|
|
std::this_thread::sleep_for(std::chrono::milliseconds(20));
|
|
|
|
}
|
|
|
|
void six()
|
|
|
|
{
|
|
|
|
PROFILER_BEGIN_FUNCTION_BLOCK_GROUPED(profiler::colors::Red);
|
|
|
|
std::this_thread::sleep_for(std::chrono::milliseconds(20));
|
|
|
|
}
|
|
|
|
|
|
|
|
void three()
|
|
|
|
{
|
|
|
|
PROFILER_BEGIN_FUNCTION_BLOCK_GROUPED(profiler::colors::Red);
|
|
|
|
four();
|
|
|
|
five();
|
|
|
|
six();
|
|
|
|
}
|
|
|
|
|
|
|
|
void seven()
|
|
|
|
{
|
|
|
|
PROFILER_BEGIN_FUNCTION_BLOCK_GROUPED(profiler::colors::Red);
|
|
|
|
std::this_thread::sleep_for(std::chrono::milliseconds(20));
|
|
|
|
}
|
|
|
|
|
|
|
|
void two()
|
|
|
|
{
|
|
|
|
PROFILER_BEGIN_FUNCTION_BLOCK_GROUPED(profiler::colors::Red);
|
|
|
|
std::this_thread::sleep_for(std::chrono::milliseconds(20));
|
|
|
|
}
|
|
|
|
|
|
|
|
void one()
|
|
|
|
{
|
|
|
|
PROFILER_BEGIN_FUNCTION_BLOCK_GROUPED(profiler::colors::Red);
|
|
|
|
two();
|
|
|
|
three();
|
|
|
|
seven();
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
one
|
|
|
|
two
|
|
|
|
three
|
|
|
|
four
|
|
|
|
five
|
|
|
|
six
|
|
|
|
seven
|
|
|
|
|
|
|
|
*/
|
2016-02-16 23:21:12 +03:00
|
|
|
int main()
|
|
|
|
{
|
2016-02-18 23:50:10 +03:00
|
|
|
auto start = std::chrono::system_clock::now();
|
|
|
|
PROFILER_ENABLE;
|
2016-02-16 23:21:12 +03:00
|
|
|
|
2016-06-20 23:33:14 +03:00
|
|
|
one();
|
|
|
|
/*std::thread render = std::thread(renderThread);
|
2016-02-18 23:50:10 +03:00
|
|
|
std::thread modelling = std::thread(modellingThread);
|
2016-02-16 23:21:12 +03:00
|
|
|
|
2016-02-18 23:50:10 +03:00
|
|
|
std::vector<std::thread> threads;
|
|
|
|
for(int i=0; i < 3; i++){
|
|
|
|
threads.emplace_back(std::thread(loadingResourcesThread));
|
|
|
|
}
|
2016-02-16 23:21:12 +03:00
|
|
|
|
2016-02-18 23:50:10 +03:00
|
|
|
render.join();
|
|
|
|
modelling.join();
|
|
|
|
for(auto& t : threads){
|
|
|
|
t.join();
|
|
|
|
}
|
2016-06-20 23:33:14 +03:00
|
|
|
*/
|
|
|
|
|
2016-02-18 23:50:10 +03:00
|
|
|
auto end = std::chrono::system_clock::now();
|
|
|
|
auto elapsed =
|
|
|
|
std::chrono::duration_cast<std::chrono::microseconds>(end - start);
|
|
|
|
|
2016-06-20 22:17:12 +03:00
|
|
|
std::cout << elapsed.count() << " usec" << std::endl;
|
2016-02-18 23:50:10 +03:00
|
|
|
//block count ~810
|
2016-02-16 23:21:12 +03:00
|
|
|
return 0;
|
2016-02-16 23:25:12 +03:00
|
|
|
}
|