replace ncurses with termios
This commit is contained in:
60
src/main.cpp
60
src/main.cpp
@@ -1,35 +1,45 @@
|
||||
// main.cpp
|
||||
#include "Aquarium.h"
|
||||
#include <cstdio>
|
||||
#include <cstdlib>
|
||||
#ifdef __OpenBSD__
|
||||
#include <unistd.h>
|
||||
#endif
|
||||
#include <chrono>
|
||||
#include <iostream>
|
||||
#include <thread>
|
||||
|
||||
int main(int argc, char *argv[]) {
|
||||
int opt;
|
||||
while ((opt = getopt(argc, argv, "r:")) != -1) {
|
||||
switch (opt) {
|
||||
case 'r':
|
||||
g_maxCells = std::atoi(optarg);
|
||||
break;
|
||||
default:
|
||||
fprintf(stderr, "Usage: %s [-r max_cells]\n", argv[0]);
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
int main() {
|
||||
// Get the singleton instance
|
||||
Aquarium &aquarium = Aquarium::getInstance();
|
||||
aquarium.resize();
|
||||
|
||||
#ifdef __OpenBSD__
|
||||
// Most restrictive pledge - no file access needed!
|
||||
if (pledge("stdio tty", NULL) == -1) {
|
||||
perror("pledge");
|
||||
return 1;
|
||||
}
|
||||
#endif
|
||||
|
||||
// Initialize the aquarium display
|
||||
aquarium.resize(); // Setup initial entities
|
||||
|
||||
// Main game loop
|
||||
while (true) {
|
||||
aquarium.redraw();
|
||||
int ch = getch();
|
||||
if (ch != ERR) {
|
||||
if (ch == 'q')
|
||||
break;
|
||||
if (ch == 'r')
|
||||
aquarium.resize();
|
||||
flushinp();
|
||||
usleep(100000);
|
||||
// Check for user input
|
||||
int input = aquarium.checkInput();
|
||||
if (input == 'q' || input == 'Q' || input == 27) { // ESC key
|
||||
break;
|
||||
}
|
||||
|
||||
// Check if terminal was resized
|
||||
if (aquarium.checkResize()) {
|
||||
aquarium.resize();
|
||||
}
|
||||
|
||||
// Redraw the aquarium
|
||||
aquarium.redraw();
|
||||
|
||||
// Control frame rate (~20 FPS)
|
||||
// std::this_thread::sleep_for(std::chrono::milliseconds(1));
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
||||
Reference in New Issue
Block a user