forked from rich/ReWalker
Update main.cpp
changed to using smart pointer for window in main()
This commit is contained in:
24
main.cpp
24
main.cpp
@@ -7,12 +7,18 @@
|
||||
#include <rewindow/types/window.h>
|
||||
#include <rewindow/logger/logger.h>
|
||||
#include <GL/gl.h>
|
||||
#include <memory>
|
||||
#include <cmath>
|
||||
#include <cstdlib>
|
||||
#include <iostream>
|
||||
|
||||
// define window size and dot size (dot size should be odd)
|
||||
// Define window size and dot size (dot size should be odd)
|
||||
#define WIDTH 800
|
||||
#define HEIGHT 600
|
||||
#define DOT_SIZE 5
|
||||
|
||||
#define DEBUG 0
|
||||
|
||||
struct Walker {
|
||||
float x, y;
|
||||
|
||||
@@ -26,25 +32,33 @@ struct Walker {
|
||||
|
||||
x = std::clamp(x + dx, 0.0f, static_cast<float>(WIDTH - 1));
|
||||
y = std::clamp(y + dy, 0.0f, static_cast<float>(HEIGHT - 1));
|
||||
|
||||
#if DEBUG
|
||||
std::cout << "Walker Position: (" << x << ", " << y << ")\n";
|
||||
#endif
|
||||
}
|
||||
};
|
||||
|
||||
class RandomWalkerWindow : public ReWindow::RWindow {
|
||||
public:
|
||||
RandomWalkerWindow(const std::string& title, int width, int height)
|
||||
: ReWindow::RWindow(title, width, height) {}
|
||||
: ReWindow::RWindow(title, width, height), walker(std::make_unique<Walker>()) {}
|
||||
|
||||
void OnRefresh(float elapsed) override {
|
||||
glClearColor(1.0f, 1.0f, 1.0f, 1.0f); // Clear with white
|
||||
glClear(GL_COLOR_BUFFER_BIT);
|
||||
|
||||
walker->step(); // Move walker in each frame
|
||||
|
||||
GLSwapBuffers();
|
||||
}
|
||||
|
||||
private:
|
||||
std::unique_ptr<Walker> walker; // Use smart pointer for ownership
|
||||
};
|
||||
|
||||
int main() {
|
||||
|
||||
std::unique_ptr<RandomWalkerWindow> window =
|
||||
std::make_unique<RandomWalkerWindow>("Random Walker with ReWindow", WIDTH, HEIGHT);
|
||||
auto window = std::make_unique<RandomWalkerWindow>("Random Walker with ReWindow", WIDTH, HEIGHT);
|
||||
|
||||
window->SetRenderer(RenderingAPI::OPENGL);
|
||||
window->Open();
|
||||
|
Reference in New Issue
Block a user