2024-01-13 15:21:17 +11:00
|
|
|
|
2024-01-14 17:50:43 +11:00
|
|
|
#include "reactor/builder.hpp"
|
2024-01-14 17:07:45 +11:00
|
|
|
#include "reactor/control/control_rod.hpp"
|
|
|
|
#include "reactor/fuel/fuel_rod.hpp"
|
|
|
|
#include "reactor/coolant/pipe.hpp"
|
2024-01-16 23:36:11 +11:00
|
|
|
#include "reactor/coolant/heater.hpp"
|
2024-01-15 15:29:28 +11:00
|
|
|
#include "reactor/coolant/vessel.hpp"
|
2024-01-16 20:30:22 +11:00
|
|
|
#include "coolant/fluid_t.hpp"
|
2024-01-18 18:00:39 +11:00
|
|
|
#include "coolant/valve.hpp"
|
2024-01-18 19:41:13 +11:00
|
|
|
#include "coolant/pump.hpp"
|
2024-01-14 16:57:13 +11:00
|
|
|
#include "display.hpp"
|
2024-01-13 15:21:17 +11:00
|
|
|
|
2024-01-15 15:29:28 +11:00
|
|
|
#include <cmath>
|
2024-01-13 21:54:21 +11:00
|
|
|
#include <sstream>
|
2024-01-13 15:21:17 +11:00
|
|
|
#include <unistd.h>
|
2024-01-13 21:54:21 +11:00
|
|
|
#include <curses.h>
|
2024-01-17 11:21:40 +11:00
|
|
|
#include <sys/time.h>
|
|
|
|
|
2024-01-18 18:00:39 +11:00
|
|
|
const bool do_graphics = true;
|
|
|
|
const bool do_clock = true;
|
|
|
|
|
2024-01-17 11:21:40 +11:00
|
|
|
unsigned long get_now()
|
|
|
|
{
|
|
|
|
struct timeval tv;
|
|
|
|
gettimeofday(&tv, nullptr);
|
|
|
|
return (unsigned long)tv.tv_sec * 1000000 + tv.tv_usec;
|
|
|
|
}
|
2024-01-13 21:54:21 +11:00
|
|
|
|
2024-01-13 15:21:17 +11:00
|
|
|
int main()
|
|
|
|
{
|
2024-01-18 18:00:39 +11:00
|
|
|
std::random_device rd;
|
|
|
|
std::mt19937 rand(rd());
|
|
|
|
|
|
|
|
if(do_graphics)
|
|
|
|
{
|
|
|
|
initscr();
|
|
|
|
cbreak();
|
|
|
|
noecho();
|
|
|
|
keypad(stdscr, TRUE);
|
|
|
|
nodelay(stdscr, TRUE);
|
|
|
|
curs_set(0);
|
|
|
|
}
|
2024-01-13 21:54:21 +11:00
|
|
|
|
2024-01-16 20:30:22 +11:00
|
|
|
sim::reactor::coolant::vessel vessel(200, 400, sim::coolant::WATER);
|
2024-01-14 17:50:43 +11:00
|
|
|
sim::reactor::reactor<5, 5> reactor = sim::reactor::builder<5, 5>(
|
2024-01-17 11:21:40 +11:00
|
|
|
sim::reactor::fuel::fuel_rod(2000, 4000),
|
2024-01-18 18:00:39 +11:00
|
|
|
sim::reactor::control::control_rod(vessel, 10000, 1),
|
2024-01-15 15:29:28 +11:00
|
|
|
sim::reactor::coolant::pipe(vessel), {
|
2024-01-18 18:00:39 +11:00
|
|
|
"#C#C#",
|
|
|
|
"CFCFC",
|
|
|
|
"#C#C#",
|
|
|
|
"CFCFC",
|
|
|
|
"#C#C#"
|
2024-01-14 17:50:43 +11:00
|
|
|
});
|
2024-01-13 15:21:17 +11:00
|
|
|
|
2024-01-18 19:41:13 +11:00
|
|
|
sim::coolant::valve<sim::reactor::coolant::vessel> valve(vessel, 1, 500);
|
|
|
|
sim::coolant::pump<sim::reactor::coolant::vessel> pump(vessel, 1e4, 15);
|
2024-01-18 18:00:39 +11:00
|
|
|
|
2024-01-14 23:44:36 +11:00
|
|
|
double secs = 0;
|
2024-01-17 11:21:40 +11:00
|
|
|
long clock = get_now();
|
2024-01-17 18:58:04 +11:00
|
|
|
double speed = 1;
|
2024-01-17 14:14:59 +11:00
|
|
|
int framerate = 100;
|
2024-01-18 18:00:39 +11:00
|
|
|
int steps_extra = 1;
|
2024-01-14 23:44:36 +11:00
|
|
|
|
2024-01-13 15:21:17 +11:00
|
|
|
for(;;)
|
|
|
|
{
|
2024-01-14 23:44:36 +11:00
|
|
|
std::stringstream ss;
|
2024-01-15 15:29:28 +11:00
|
|
|
ss << "Reactor Core\n\n";
|
2024-01-14 23:44:36 +11:00
|
|
|
|
2024-01-15 15:29:28 +11:00
|
|
|
{
|
|
|
|
long mins = secs / 60;
|
2024-01-17 14:14:59 +11:00
|
|
|
long hours = mins / 60;
|
|
|
|
long days = hours / 24;
|
|
|
|
long years = days / 365;
|
2024-01-15 15:29:28 +11:00
|
|
|
double s = fmod(secs, 60);
|
|
|
|
|
|
|
|
mins %= 60;
|
|
|
|
hours %= 24;
|
|
|
|
days %= 365;
|
|
|
|
|
|
|
|
ss << "Time:\n";
|
|
|
|
|
2024-01-17 14:14:59 +11:00
|
|
|
if(years > 0) goto years;
|
|
|
|
if(days > 0) goto days;
|
|
|
|
if(hours > 0) goto hours;
|
|
|
|
if(mins > 0) goto mins;
|
|
|
|
goto secs;
|
|
|
|
|
|
|
|
years: ss << years << "y ";
|
|
|
|
days: ss << days << "d ";
|
|
|
|
hours: ss << hours << "h ";
|
|
|
|
mins: ss << mins << "m ";
|
2024-01-17 18:58:04 +11:00
|
|
|
secs: ss << s << "s\n";
|
|
|
|
|
|
|
|
ss << "Speed: " << speed << "x\n\n";
|
|
|
|
}
|
|
|
|
|
2024-01-18 18:00:39 +11:00
|
|
|
for(int i = 0; i < steps_extra; i++)
|
2024-01-17 18:58:04 +11:00
|
|
|
{
|
2024-01-18 18:00:39 +11:00
|
|
|
double dt = speed / framerate / steps_extra;
|
|
|
|
reactor.update(rand, dt);
|
2024-01-18 19:41:13 +11:00
|
|
|
pump.update(dt);
|
2024-01-18 18:00:39 +11:00
|
|
|
valve.update(dt);
|
2024-01-18 19:41:13 +11:00
|
|
|
vessel.update();
|
2024-01-18 18:00:39 +11:00
|
|
|
secs += dt;
|
2024-01-17 14:14:59 +11:00
|
|
|
}
|
2024-01-15 15:29:28 +11:00
|
|
|
|
|
|
|
ss << "Vessel\n" << vessel << "\n";
|
2024-01-18 18:00:39 +11:00
|
|
|
ss << "Steam Valve\n" << valve << "\n";
|
2024-01-18 19:41:13 +11:00
|
|
|
ss << "Coolant Pump\n" << pump << "\n";
|
2024-01-13 15:21:17 +11:00
|
|
|
|
2024-01-18 18:00:39 +11:00
|
|
|
if(do_graphics)
|
|
|
|
{
|
|
|
|
erase();
|
|
|
|
display::draw_text(1, 0, ss.str().c_str());
|
|
|
|
}
|
2024-01-13 21:54:21 +11:00
|
|
|
|
2024-01-17 13:00:51 +11:00
|
|
|
const int X = 1, Y = 30;
|
2024-01-17 14:14:59 +11:00
|
|
|
const int W = 36, H = 11;
|
2024-01-13 21:54:21 +11:00
|
|
|
|
2024-01-14 16:57:13 +11:00
|
|
|
for(int x = 0; x < reactor.width; x++)
|
|
|
|
for(int y = 0; y < reactor.height; y++)
|
2024-01-13 21:54:21 +11:00
|
|
|
{
|
2024-01-18 18:00:39 +11:00
|
|
|
int id = y * reactor.width + x;
|
|
|
|
sim::reactor::rod* r = reactor.rods[id];
|
2024-01-15 12:45:22 +11:00
|
|
|
|
|
|
|
if(!r->should_display())
|
|
|
|
{
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
std::stringstream ss;
|
2024-01-14 18:35:12 +11:00
|
|
|
ss << *r;
|
2024-01-13 21:54:21 +11:00
|
|
|
|
|
|
|
int px = X + (H - 1) * y;
|
|
|
|
int py = Y + (W - 1) * x;
|
|
|
|
|
2024-01-18 18:00:39 +11:00
|
|
|
if(do_graphics)
|
|
|
|
{
|
|
|
|
display::draw_text(px + 1, py + 2, ss.str().c_str());
|
|
|
|
display::draw_box(px, py, H, W);
|
|
|
|
}
|
2024-01-14 18:35:12 +11:00
|
|
|
|
2024-01-18 18:00:39 +11:00
|
|
|
if(do_graphics && r->should_select() && id == reactor.cursor)
|
2024-01-14 18:35:12 +11:00
|
|
|
{
|
|
|
|
display::draw_text(px + 1, py + W - 5, "[ ]");
|
|
|
|
}
|
|
|
|
|
2024-01-18 18:00:39 +11:00
|
|
|
if(do_graphics && r->is_selected())
|
2024-01-14 18:35:12 +11:00
|
|
|
{
|
|
|
|
display::draw_text(px + 1, py + W - 4, "#");
|
|
|
|
}
|
2024-01-13 21:54:21 +11:00
|
|
|
}
|
|
|
|
|
2024-01-18 18:00:39 +11:00
|
|
|
int c = 0;
|
2024-01-14 18:35:12 +11:00
|
|
|
|
2024-01-18 18:00:39 +11:00
|
|
|
if(do_graphics)
|
|
|
|
{
|
|
|
|
refresh();
|
|
|
|
c = getch();
|
|
|
|
}
|
2024-01-14 18:35:12 +11:00
|
|
|
|
|
|
|
switch(c)
|
|
|
|
{
|
|
|
|
case KEY_LEFT:
|
|
|
|
reactor.move_cursor(-1);
|
|
|
|
break;
|
|
|
|
case KEY_RIGHT:
|
|
|
|
reactor.move_cursor(1);
|
|
|
|
break;
|
|
|
|
case KEY_UP:
|
2024-01-18 18:00:39 +11:00
|
|
|
reactor.update_selected(1);
|
2024-01-14 18:35:12 +11:00
|
|
|
break;
|
|
|
|
case KEY_DOWN:
|
2024-01-18 18:00:39 +11:00
|
|
|
reactor.update_selected(-1);
|
2024-01-14 18:35:12 +11:00
|
|
|
break;
|
|
|
|
case ' ':
|
|
|
|
reactor.toggle_selected();
|
|
|
|
break;
|
2024-01-17 18:58:04 +11:00
|
|
|
case 't':
|
|
|
|
speed *= 10;
|
|
|
|
break;
|
|
|
|
case 'g':
|
|
|
|
speed /= 10;
|
|
|
|
break;
|
2024-01-18 18:00:39 +11:00
|
|
|
case 'r':
|
|
|
|
valve.open(0.001);
|
|
|
|
break;
|
|
|
|
case 'f':
|
|
|
|
valve.open(-0.001);
|
|
|
|
break;
|
2024-01-18 19:41:13 +11:00
|
|
|
case 'e':
|
|
|
|
pump.change_speed(0.01);
|
|
|
|
break;
|
|
|
|
case 'd':
|
|
|
|
pump.change_speed(-0.01);
|
|
|
|
break;
|
2024-01-14 18:35:12 +11:00
|
|
|
}
|
2024-01-17 11:21:40 +11:00
|
|
|
|
2024-01-18 18:00:39 +11:00
|
|
|
if(do_clock)
|
2024-01-17 11:21:40 +11:00
|
|
|
{
|
2024-01-18 18:00:39 +11:00
|
|
|
long now = get_now();
|
|
|
|
|
|
|
|
while(clock + 1e6 / framerate > now)
|
|
|
|
{
|
|
|
|
usleep(clock + 1e6 / framerate - now);
|
|
|
|
now = get_now();
|
|
|
|
}
|
2024-01-17 11:21:40 +11:00
|
|
|
|
2024-01-18 18:00:39 +11:00
|
|
|
clock += 1e6 / framerate;
|
|
|
|
}
|
2024-01-13 15:21:17 +11:00
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|