tmp
This commit is contained in:
parent
25fd52294f
commit
16af8dc809
6 changed files with 140 additions and 42 deletions
|
|
@ -6,46 +6,124 @@
|
|||
|
||||
#include "imgui.h"
|
||||
|
||||
int main() {
|
||||
tp::ModuleManifest* deps[] = { &tp::gModuleGraphics, nullptr };
|
||||
tp::ModuleManifest testModule("Example", nullptr, nullptr, deps);
|
||||
using namespace tp;
|
||||
|
||||
if (!testModule.initialize()) {
|
||||
return 1;
|
||||
class Application {
|
||||
public:
|
||||
Application() :
|
||||
mApplicaitonModule("Application", nullptr, nullptr, mModuleDeps) {
|
||||
mInitialized = mApplicaitonModule.initialize();
|
||||
if (!mInitialized) return;
|
||||
|
||||
mWindow = Window::createWindow();
|
||||
|
||||
mDrawTimer.setDuration(1000.f / mDrawPerSecond);
|
||||
mProcTimer.setDuration(1000.f / mProcPerSecond);
|
||||
mPerSecondTimer.setDuration(1000.f);
|
||||
}
|
||||
|
||||
int frames = 0;
|
||||
int fps = 0;
|
||||
tp::Timer timer(1000);
|
||||
void run() {
|
||||
Graphics graphics(mWindow);
|
||||
auto eventHandler = new EventHandler();
|
||||
|
||||
auto window = tp::Window::createWindow();
|
||||
mWindow->setEventHandler(eventHandler);
|
||||
|
||||
{
|
||||
tp::Graphics graphics(window);
|
||||
mDrawTimer.reset();
|
||||
mProcTimer.reset();
|
||||
mPerSecondTimer.reset();
|
||||
|
||||
if (window) {
|
||||
while (!window->shouldClose()) {
|
||||
window->processEvents();
|
||||
graphics.proc();
|
||||
bool redrawNeeded = false;
|
||||
|
||||
ImGui::Text("fps: %i", fps);
|
||||
while (!mWindow->shouldClose()) {
|
||||
if (mProcTimer.isTimeout()) {
|
||||
|
||||
graphics.draw();
|
||||
window->draw();
|
||||
mWindow->processEvents();
|
||||
|
||||
if (timer.isTimeout()) {
|
||||
fps = frames;
|
||||
frames = 0;
|
||||
timer.reset();
|
||||
while (eventHandler->isEvents()) {
|
||||
eventHandler->processEvent();
|
||||
processFrame(eventHandler);
|
||||
|
||||
redrawNeeded = true;
|
||||
mFramesProcessed++;
|
||||
}
|
||||
|
||||
frames++;
|
||||
// graphics.procBegin();
|
||||
// graphics.procEnd();
|
||||
redrawNeeded = true;
|
||||
mFramesProcessed++;
|
||||
|
||||
mProcTimer.wait();
|
||||
mProcTimer.reset();
|
||||
}
|
||||
|
||||
if (mDrawTimer.isTimeout()) {
|
||||
mDrawTimer.reset();
|
||||
|
||||
if (redrawNeeded) {
|
||||
graphics.drawBegin();
|
||||
|
||||
drawFrame(graphics.getCanvas());
|
||||
|
||||
graphics.drawEnd();
|
||||
|
||||
mWindow->draw();
|
||||
|
||||
redrawNeeded = false;
|
||||
mFramesDrawn++;
|
||||
}
|
||||
}
|
||||
|
||||
if (mPerSecondTimer.isTimeout()) {
|
||||
mPerSecondTimer.reset();
|
||||
|
||||
mFramesProcessedPerSecond = mFramesProcessed;
|
||||
mFramesDrawnPerSecond = mFramesDrawn;
|
||||
|
||||
mFramesDrawn = 0;
|
||||
mFramesProcessed = 0;
|
||||
}
|
||||
}
|
||||
|
||||
delete eventHandler;
|
||||
}
|
||||
|
||||
tp::Window::destroyWindow(window);
|
||||
virtual void processFrame(EventHandler* eventHandler) {
|
||||
}
|
||||
|
||||
testModule.deinitialize();
|
||||
virtual void drawFrame(Canvas* canvas) {
|
||||
ImGui::Text("Frames processed per second: %f", mFramesProcessedPerSecond);
|
||||
ImGui::Text("Frames drawn per second: %f", mFramesDrawnPerSecond);
|
||||
}
|
||||
|
||||
~Application() {
|
||||
if (!mInitialized) return;
|
||||
Window::destroyWindow(mWindow);
|
||||
mApplicaitonModule.deinitialize();
|
||||
}
|
||||
|
||||
private:
|
||||
ModuleManifest* mModuleDeps[2] = { &gModuleGraphics, nullptr };
|
||||
ModuleManifest mApplicaitonModule;
|
||||
|
||||
Window* mWindow = nullptr;
|
||||
|
||||
bool mInitialized = false;
|
||||
|
||||
ualni mDrawPerSecond = 60;
|
||||
ualni mProcPerSecond = 1000;
|
||||
|
||||
Timer mDrawTimer;
|
||||
Timer mProcTimer;
|
||||
Timer mPerSecondTimer;
|
||||
|
||||
halnf mFramesProcessedPerSecond = 0;
|
||||
halnf mFramesDrawnPerSecond = 0;
|
||||
|
||||
halnf mFramesProcessed = 0;
|
||||
halnf mFramesDrawn = 0;
|
||||
};
|
||||
|
||||
int main() {
|
||||
Application app;
|
||||
app.run();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -135,11 +135,11 @@ void Canvas::deleteImageHandle(ImageHandle image) {
|
|||
}
|
||||
}
|
||||
|
||||
void Canvas::proc() {
|
||||
void Canvas::drawBegin() {
|
||||
const auto size = mContext->window->getSize();
|
||||
nvgBeginFrame(mContext->vg, size.x, size.y, 1.0);
|
||||
}
|
||||
|
||||
void Canvas::draw() {
|
||||
void Canvas::drawEnd() {
|
||||
nvgEndFrame(mContext->vg);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -47,7 +47,7 @@ DebugGUI::~DebugGUI() {
|
|||
delete mContext;
|
||||
}
|
||||
|
||||
void DebugGUI::proc() {
|
||||
void DebugGUI::drawBegin() {
|
||||
tp::HeapAllocGlobal::startIgnore();
|
||||
|
||||
ImGui_ImplOpenGL3_NewFrame();
|
||||
|
|
@ -57,7 +57,7 @@ void DebugGUI::proc() {
|
|||
tp::HeapAllocGlobal::stopIgnore();
|
||||
}
|
||||
|
||||
void DebugGUI::draw() {
|
||||
void DebugGUI::drawEnd() {
|
||||
ImGui::Render();
|
||||
ImGui_ImplOpenGL3_RenderDrawData(ImGui::GetDrawData());
|
||||
}
|
||||
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
#include "Window.hpp"
|
||||
|
||||
class GLFWwindow;
|
||||
struct GLFWwindow;
|
||||
|
||||
namespace tp {
|
||||
|
||||
|
|
|
|||
|
|
@ -63,8 +63,8 @@ namespace tp {
|
|||
void postEvent(InputID inputID, InputEvent inputEvent); // Record event
|
||||
|
||||
public: // User interface
|
||||
bool isEvents();
|
||||
void processEvent();
|
||||
bool isEvents() { return false; }
|
||||
void processEvent() {}
|
||||
|
||||
const Vec2F& getPointer() const;
|
||||
|
||||
|
|
|
|||
|
|
@ -17,8 +17,11 @@ namespace tp {
|
|||
explicit DebugGUI(Window* window);
|
||||
~DebugGUI();
|
||||
|
||||
void proc();
|
||||
void draw();
|
||||
void procBegin() {}
|
||||
void procEnd() {}
|
||||
|
||||
void drawBegin();
|
||||
void drawEnd();
|
||||
};
|
||||
|
||||
class Canvas {
|
||||
|
|
@ -29,8 +32,11 @@ namespace tp {
|
|||
explicit Canvas(Window* window);
|
||||
~Canvas();
|
||||
|
||||
void proc();
|
||||
void draw();
|
||||
void procBegin() {}
|
||||
void procEnd() {}
|
||||
|
||||
void drawBegin();
|
||||
void drawEnd();
|
||||
|
||||
public:
|
||||
enum Align : int2 {
|
||||
|
|
@ -67,14 +73,28 @@ namespace tp {
|
|||
public:
|
||||
explicit Graphics(Window* window) : mGui(window), mCanvas(window) {}
|
||||
|
||||
void proc() {
|
||||
mCanvas.proc();
|
||||
mGui.proc();
|
||||
void procBegin() {
|
||||
mCanvas.procBegin();
|
||||
mGui.procBegin();
|
||||
}
|
||||
|
||||
void draw() {
|
||||
mCanvas.draw();
|
||||
mGui.draw();
|
||||
void procEnd() {
|
||||
mCanvas.procEnd();
|
||||
mGui.procEnd();
|
||||
}
|
||||
|
||||
void drawBegin() {
|
||||
mCanvas.drawBegin();
|
||||
mGui.drawBegin();
|
||||
}
|
||||
|
||||
void drawEnd() {
|
||||
mCanvas.drawEnd();
|
||||
mGui.drawEnd();
|
||||
}
|
||||
|
||||
Canvas* getCanvas() {
|
||||
return &mCanvas;
|
||||
}
|
||||
|
||||
private:
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue