29 #include <sys/types.h> 
   32 #include "eng3d/ui/ui.hpp" 
   33 #include "eng3d/ui/input.hpp" 
   34 #include "eng3d/ui/image.hpp" 
   35 #include "eng3d/ui/label.hpp" 
   36 #include "eng3d/ui/text.hpp" 
   37 #include "eng3d/ui/progress_bar.hpp" 
   38 #include "eng3d/audio.hpp" 
   39 #include "eng3d/string.hpp" 
   40 #include "eng3d/event.hpp" 
   41 #include "eng3d/serializer.hpp" 
   42 #include "eng3d/material.hpp" 
   43 #include "eng3d/model.hpp" 
   44 #include "eng3d/texture.hpp" 
   45 #include "eng3d/log.hpp" 
   46 #include "eng3d/camera.hpp" 
   47 #include "eng3d/interface.hpp" 
   69     map->camera->set_pos(capital.box_area.right, capital.box_area.bottom);
 
   70     map->map_render->request_update_visibility();
 
   71     map->map_render->update();
 
   80     if(this->
client != 
nullptr)
 
  100         ibtn.set_tooltip(msg.title);
 
  104     for(
auto& treaty : gs.
world->treaties) {
 
  106         auto iter = std::find(displayed_treaties.begin(), displayed_treaties.end(), treaty.get_id());
 
  107         if(iter != displayed_treaties.end()) 
continue;
 
  108         if(!treaty.does_participate(*gs.
curr_nation)) 
continue; 
 
  110         displayed_treaties.push_back(treaty);
 
  121         map->update_mapmode();
 
  131         if(!this->
run) 
break;
 
  136             const auto start_time = std::chrono::system_clock::now();
 
  141             } 
catch(
const std::exception& e) {
 
  147             std::this_thread::sleep_until(start_time + delta);
 
  158         if(!entries.empty()) {
 
  159             const int music_index = rand() % entries.size();
 
  160             auto audio = this->
audio_man.
load(entries[music_index]->get_abs_path());
 
  162             Eng3D::Log::debug(
"music", 
"Now playing music file " + entries[music_index]->get_abs_path());
 
  174     this->
world->events.clear();
 
  181     if(
map != 
nullptr) 
map->camera->set_screen(width, height);
 
  191                     if(!entries.empty()) {
 
  192                         auto audio = 
audio_man.
load(entries[rand() % entries.size()]->get_abs_path());
 
  201             map->handle_mouse_button(e);
 
  215                 map->handle_mouse_button(e);
 
  231         map->handle_mouse_motions(e);
 
  261             if(this->
map != 
nullptr)
 
  262                 this->
map->reload_shaders();
 
  284                 map->camera->move(0.f, -1.f, 0.f);
 
  288                 map->camera->move(0.f, 1.f, 0.f);
 
  292                 map->camera->move(-1.f, 0.f, 0.f);
 
  296                 map->camera->move(1.f, 0.f, 0.f);
 
  305     std::vector<std::string> pkg_paths;
 
  306     for(
int i = 1; i < argc; i++) {
 
  307         std::string arg = std::string(argv[i]);
 
  312             arg = std::string(argv[i]);
 
  313             pkg_paths.push_back(arg);
 
  322     map_layer->managed = 
false;
 
  324     auto *bg_img = 
new UI::Image(-(gs.width / 2.f), -(gs.height / 2.f), gs.width, gs.height);
 
  327     if(!load_screen_entries.empty())
 
  328         bg_img->current_texture = gs.
tex_man.
load(load_screen_entries[rand() % load_screen_entries.size()]->get_abs_path());
 
  331     load_pbar->set_text(
translate(
"Initializing game resources"));
 
  334     load_pbar->on_update = ([&gs, load_pbar] (
UI::Widget&) {
 
  339     new UI::Image(0, 0, mod_logo_tex->width, mod_logo_tex->height, mod_logo_tex);
 
  372     map_layer->managed = 
false;
 
  373     gs.
map = std::make_unique<Map>(gs, *gs.
world, map_layer, gs.width, gs.height);
 
  376     gs.
map->camera->move(0.f, 50.f, 10.f);
 
  380     load_world_th.join();
 
  388         bool is_built = 
false;
 
  389         for(
auto& building_type : gs.
world->building_types) {
 
  391                 auto& province = gs.
world->provinces[province_id];
 
  392                 auto& building = province.get_buildings()[building_type];
 
  394                 if(building.is_working_on_unit()) {
 
  420             gs.
map->map_render->update();
 
  429             gs.
map->camera->move(0.05f, 0.f, 0.f);
 
  438         gs.
map->camera->update();
 
  444 int main(
int argc, 
char** argv) 
try {
 
  454     std::vector<TreatyId> displayed_treaties;
 
  458         ([&gs](){ 
return gs.
run == 
true; }),
 
  459         ([&displayed_treaties, &gs]() { 
client_update(gs, displayed_treaties); }),
 
  464 } 
catch(
const std::exception& e) {
 
const std::shared_ptr< Audio > load(const std::string &path)
std::vector< std::shared_ptr< Eng3D::Audio > > sound_queue
std::vector< std::shared_ptr< Eng3D::Audio > > music_queue
std::vector< std::shared_ptr< Eng3D::IO::Asset::Base > > get_multiple_prefix(const Eng3D::IO::Path &path)
Obtains all assets starting with a given prefix.
std::shared_ptr< Eng3D::IO::Asset::Base > get_unique(const Eng3D::IO::Path &path)
Obtaining an unique asset means the "first-found" policy applies.
Eng3D::AudioManager audio_man
void do_run(std::function< bool(void)> cond, std::function< void(void)> event, std::function< void(void)> render)
Perform the main game loop.
std::atomic< bool > run
Variable telling if the game should quit, honored by most event loops but should be used explicitly i...
Eng3D::TextureManager tex_man
Eng3D::IO::PackageManager package_man
std::shared_ptr< Eng3D::Texture > load(const std::string &path, TextureOptions options=default_options)
Finds a texture in the list of a texture manager if the texture is already in the list we load the sa...
void handle_mouse_btn(const Eng3D::Event::MouseButton &) override
UI::Widget * event_tray_grp
void handle_mouse_wheel(const Eng3D::Event::MouseWheel &) override
std::unique_ptr< Client > client
std::atomic< bool > paused
void handle_resize() override
void handle_mouse_motion(const Eng3D::Event::MouseMotion &) override
void handle_key(const Eng3D::Event::Key &) override
std::atomic< bool > loaded_world
std::atomic< bool > update_tick
std::atomic< bool > loaded_map
UI::Widget * profiler_view
std::unique_ptr< Map > map
std::shared_ptr< Eng3D::Texture > get_nation_flag(const Nation &nation)
std::atomic< int > ms_delay_speed
std::vector< UnitTypeId > production_queue
std::vector< ProvinceId > controlled_provinces
std::deque< Event > inbox
void render_all()
Render all widgets.
void do_tick()
Will call on_tick on all widgets.
bool check_mouse_released(glm::ivec2 mouse_pos)
Release the dragging of the widget.
void prompt(const std::string &title, const std::string &text)
bool check_text_input(const char *input)
Will give keyboard input to Input Widget if one is selected.
void check_drag(glm::ivec2 mouse_pos)
Check for on_drag events, will move Window widgets with is_pinned = false.
bool check_wheel(glm::ivec2 mouse_pos, int y)
Check if the mouse is above a widget and scroll widget.
bool check_hover(glm::ivec2 mouse_pos)
Check for on_hover events If the mouse is above a widget call the widgets on_hover or show its toolti...
bool check_click(glm::ivec2 mouse_pos)
Check for on_click events. Check if the mouse is above a widget and call the widgets on_click if poss...
void clear()
Removes all widgets.
void set_cursor_pos(glm::ivec2 pos)
Grouping to keep widgets together without triggering events.
Image widget, can display pictures or effects on the screen.
static World & get_instance()
void client_update(GameState &gs, std::vector< TreatyId > &displayed_treaties)
int main(int argc, char **argv)
void create_startup_ui(GameState &gs)
void update_production_queue(GameState &gs)
void handle_popups(std::vector< TreatyId > &displayed_treaties, GameState &gs)
void client_render(GameState &gs)
std::vector< std::string > parse_arguments(int argc, char **argv)
void startup(GameState &gs)
std::string translate(const std::string_view str)
void error(const std::string_view category, const std::string_view msg)
void debug(const std::string_view category, const std::string_view msg)
std::string string_format(const std::string_view format, Args &&... args)
String formatter.
std::string translate_format(const std::string_view format, Args &&... args)
String formatter, with translation.
static Eng3D::Networking::Packet form_packet(const Province &province, const BuildingType &building_type, const Nation &nation, const UnitType &unit_type)
static Eng3D::Networking::Packet form_packet(const Nation &nation)
Primitive color type used through the engine.
Eng3D::Event::Key::Type type
bool hold
Whetever the key is being held.
void invoke_registered_callback(const std::string &name)
Some UI functions are hardcoded, for example the main menu is hardcoded to appear when the game start...
void stop(const std::string &name)
void start(const std::string &name)
const char * c_str() const
Eng3D::StringRef ref_name
#define CXX_THROW(class,...)