]> git.localhorst.tv Git - blobs.git/blob - src/blobs.cpp
simple name generator
[blobs.git] / src / blobs.cpp
1 #include "app/Application.hpp"
2 #include "app/Assets.hpp"
3 #include "app/init.hpp"
4 #include "app/MasterState.hpp"
5 #include "creature/Creature.hpp"
6 #include "math/const.hpp"
7 #include "world/Planet.hpp"
8 #include "world/Set.hpp"
9 #include "world/Simulation.hpp"
10 #include "world/Sun.hpp"
11 #include "world/TileType.hpp"
12
13 #include <cstdint>
14 #include <iostream>
15
16
17 using namespace blobs;
18
19 namespace {
20
21 struct SwitchPanel {
22         SwitchPanel(world::Planet &p, app::Application &app, app::MasterState &state)
23         : planet(p), app(app), state(state) { }
24
25         void operator ()(creature::Creature &c) {
26                 if (planet.Creatures().empty()) {
27                         std::cout << "no more creatures, game over" << std::endl;
28                         while (app.HasState()) {
29                                 app.PopState();
30                         }
31                 } else {
32                         for (auto a : planet.Creatures()) {
33                                 if (a != &c) {
34                                         state.GetCreaturePanel().Show(*a);
35                                         a->OnDeath([&](creature::Creature &b) { (*this)(b); });
36                                         break;
37                                 }
38                         }
39                 }
40         }
41
42         world::Planet &planet;
43         app::Application &app;
44         app::MasterState &state;
45 };
46 }
47
48 int main(int argc, char *argv[]) {
49         app::Init init(true, 8);
50         app::Assets assets;
51
52         world::Sun sun;
53         sun.Mass(1.0e14);
54         sun.Radius(20.0);
55         sun.SurfaceTilt(glm::dvec2(PI * 0.25, PI * 0.25));
56         sun.AngularMomentum(1.0e13);
57
58         world::Planet planet(25);
59         planet.SetParent(sun);
60         planet.Mass(1.0e10);
61         planet.GetOrbit().SemiMajorAxis(941.7);
62         planet.SurfaceTilt(glm::dvec2(PI * 0.25, PI * 0.25));
63         planet.AxialTilt(glm::dvec2(PI * 0.127, 0.0));
64         planet.AngularMomentum(6.0e10);
65
66         world::Planet moon(3);
67         moon.SetParent(planet);
68         moon.Mass(1.0e6);
69         moon.GetOrbit().SemiMajorAxis(37.0);
70         moon.Rotation(PI * 0.25);
71         moon.AngularMomentum(1.0e4);
72
73         world::Planet second_planet(9);
74         second_planet.SetParent(sun);
75         second_planet.Mass(1.0e9);
76         second_planet.GetOrbit().SemiMajorAxis(350.0);
77         second_planet.SurfaceTilt(glm::dvec2(PI * 0.125, PI * 0.25));
78         second_planet.AxialTilt(glm::dvec2(PI * 0.95, 0.0));
79         second_planet.AngularMomentum(1.0e8);
80
81         world::Simulation sim(sun, assets);
82         sim.AddSun(sun);
83         sim.AddPlanet(planet);
84         sim.AddPlanet(second_planet);
85         sim.AddPlanet(moon);
86
87         world::GenerateEarthlike(assets.data.tile_types, planet);
88         planet.Atmosphere(assets.data.resources["air"].id);
89         world::GenerateTest(assets.data.tile_types, moon);
90         world::GenerateTest(assets.data.tile_types, second_planet);
91
92         std::cout << "length of year: " << planet.OrbitalPeriod() << "s" << std::endl;
93         std::cout << "length of moon cycle: " << moon.OrbitalPeriod() << "s" << std::endl;
94         std::cout << "length of day: " << planet.RotationalPeriod() << "s" << std::endl;
95         std::cout << "days per year: " << (planet.OrbitalPeriod() / planet.RotationalPeriod()) << std::endl;
96         std::cout << "moon cycle in days: " << (moon.OrbitalPeriod() / planet.RotationalPeriod()) << std::endl;
97         std::cout << "moon cycles per year: " << (planet.OrbitalPeriod() / moon.OrbitalPeriod()) << std::endl;
98
99         auto blob = new creature::Creature(sim);
100         blob->Name(assets.name.Sequential());
101         Spawn(*blob, planet);
102         blob->BuildVAO();
103
104         app::MasterState state(assets, sim);
105         state.GetCamera()
106                 .Reference(planet)
107                 // sunrise
108                 //.FirstPerson(0, glm::vec3(0.0f, 0.0f, 0.1f), glm::vec3(1.0f, -0.75f, 0.1f))
109                 // sunset
110                 //.FirstPerson(3, glm::vec3(0.0f, 0.0f, 0.1f), glm::vec3(1.0f, -0.75f, 0.1f))
111                 // from afar
112                 .MapView(0, glm::vec3(0.0f, 0.0f, 15.0f), 0.0f)
113                 // from afar, rotating
114                 //.Orbital(glm::vec3(-60.0f, 0.0f, 0.0f))
115         ;
116         // system view
117         //state.GetCamera()
118         //      .Reference(sun)
119         //      .Orbital(glm::vec3(-500.0f, 500.0f, 500.0f))
120         //;
121         state.GetCreaturePanel().Show(*blob);
122
123         app::Application app(init.window, init.viewport);
124         SwitchPanel swp(planet, app, state);
125         blob->OnDeath([&](creature::Creature &c) { swp(c); });
126         app.PushState(&state);
127         app.Run();
128
129         return 0;
130 }