#include "../example_base.hpp"
time_passed += data->
get_dt();
++frame_count;
}
system("cls");
std::cout << "Framerate collection finished!\n";
std::cout << "Game time passed: " << time_passed << "\n";
std::cout << "Total frames counted: " << frame_count << std::endl;
}
~count_frames_task() override {
}
double time_passed = 0.0;
long long frame_count = 0;
};
struct print_fps_task : count_frames_task {
print_fps_task(count_frames_task& count_task) : count_task(count_task) {}
count_frames_task::eztask_execute(data);
if (count_task.time_passed > 0.0f && this->time_passed >= 1.0f) {
double fps = static_cast<double>(count_task.frame_count)
/ count_task.time_passed;
system("cls");
std::cout << "Frames last second: " << this->frame_count << "\n";
std::cout << "Average FPS: " << fps << std::endl;
this->time_passed = 0.0f;
this->frame_count = 0;
}
}
count_frames_task& count_task;
};
void example_base() {
con_allocate(true);
from::make_unique<count_frames_task>();
from::make_unique<print_fps_task>(*count_task);
if (!from::DLSY::wait_for_system(5'000)) {
std::cout << "wait_for_system timed out!" << std::endl;
return;
}
count_task->register_task(from::CS::CSTaskGroup::FrameBegin);
print_task->register_task(from::CS::CSTaskGroup::Flip);
Sleep(60'000);
}
Inherit from this minimal task interface to create a custom task.
Definition task.hpp:51
virtual LIBERAPI void free_task()
Free the task, suspending its execution after it has been registered.
virtual void eztask_execute(FD4::FD4TaskData *data)=0
Virtual method that is called when a CS::CSEzTask is executed.
from::unique_ptr based on std::unique_ptr
std::unique_ptr< T, from::delay_delete< T, AllocatorTag > > unique_ptr
std::unique_ptr with from::allocator and from::delay_delete.
Definition from_unique_ptr.hpp:22
The data passed to tasks on execution.
Definition fd4_task.hpp:55
float get_dt() const noexcept
Get the delta time.
Definition fd4_task.hpp:61
Dantelion2 system properties.
Namespace CS task interface.
#include "../example_base.hpp"
public:
if (group == other->get_task_group())
std::terminate();
auto next_group = static_cast<from::CS::CSTaskGroup>(int(group) + 1);
if (next_group == from::CS::CSTaskGroup::SIZE)
next_group = from::CS::CSTaskGroup::FrameBegin;
other->register_task(next_group);
}
wandering_task* other;
};
void example_base() {
con_allocate(true);
wandering_task* first = new wandering_task;
wandering_task* second = new wandering_task;
first->other = second;
second->other = first;
if (!from::DLSY::wait_for_system(5'000)) {
std::cout << "wait_for_system timed out!" << std::endl;
return;
}
first->register_task(from::CS::CSTaskGroup::FrameBegin);
second->register_task(from::CS::CSTaskGroup::SteamThread0);
}
CS::CSTaskGroup get_task_group() const noexcept
Get the task group.
Definition fd4_task.hpp:70