Horizon Official Technical Documentation
GameLogicProcess.hpp
Go to the documentation of this file.
1/***************************************************
2 * _ _ _ *
3 * | | | | (_) *
4 * | |_| | ___ _ __ _ _______ _ __ *
5 * | _ |/ _ \| '__| |_ / _ \| '_ \ *
6 * | | | | (_) | | | |/ / (_) | | | | *
7 * \_| |_/\___/|_| |_/___\___/|_| |_| *
8 ***************************************************
9 * This file is part of Horizon (c).
10 *
11 * Copyright (c) 2019 Sagun K. (sagunxp@gmail.com).
12 * Copyright (c) 2019 Horizon Dev Team.
13 *
14 * Base Author - Sagun K. (sagunxp@gmail.com)
15 *
16 * This library is free software; you can redistribute it and/or modify
17 * it under the terms of the GNU General Public License as published by
18 * the Free Software Foundation, either version 3 of the License, or
19 * (at your option) any later version.
20 *
21 * This library is distributed in the hope that it will be useful,
22 * but WITHOUT ANY WARRANTY; without even the implied warranty of
23 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24 * GNU General Public License for more details.
25 *
26 * You should have received a copy of the GNU General Public License
27 * along with this library. If not, see <http://www.gnu.org/licenses/>.
28 **************************************************/
29
30#ifndef HORIZON_ZONE_GAME_GAMELOGICPROCESS_HPP
31#define HORIZON_ZONE_GAME_GAMELOGICPROCESS_HPP
32
37#include "Server/Zone/Zone.hpp"
38namespace Horizon
39{
40namespace Zone
41{
42 namespace Units
43 {
44 class Monster;
45 }
46 class Map;
48{
49
51{
52public:
54
55 void initialize(std::shared_ptr<GameLogicProcess> game_logic_process)
56 {
57 _game_logic_process = game_logic_process;
58 }
59
60 void finalize();
61
62 std::shared_ptr<GameLogicProcess> get_container() { return _game_logic_process.lock(); }
63
64 void spawn_monsters(std::string map_name);
65
66 void reschedule_single_monster_spawn(std::shared_ptr<Horizon::Zone::Units::Monster> monster);
67
68 void spawn_monster_internal(std::shared_ptr<Map> map, int spawn_dataset_id, int monster_id, int16_t amount, int16_t x, int16_t y, int16_t x_area, int16_t y_area);
69 void despawn_monsters(std::string map_name);
70
71 void register_monster_spawn_info(uint32_t id, std::shared_ptr<monster_spawn_data> data) { _monster_spawn_db.insert(id, data); }
72 std::shared_ptr<monster_spawn_data> get_monster_spawn_info(uint32_t id) { return _monster_spawn_db.at(id); }
74
76private:
77 std::weak_ptr<GameLogicProcess> _game_logic_process;
79};
80
81public:
83
84 void initialize(int segment_number = 1) override;
85 void finalize() override;
86 void update(uint64_t diff);
87
88 bool is_initialized() override { return _is_initialized.load(); }
89 bool is_finalized() override { return _is_finalized.load(); }
90
91 /* Map / Maps */
92 bool load_map_cache();
93 void start_internal();
94
96
97 void on_map_update(int64_t diff);
98
100
102
103protected:
104 std::atomic<bool> _is_initialized{false};
105 std::atomic<bool> _is_finalized{false};
106
107 using PrimaryResource = SharedPriorityResourceMedium<s_segment_storage<std::string /* Map Name */, std::shared_ptr<Map>>>;
112public:
114
115private:
118 std::thread _thread;
119 std::map<std::string, map_data> _maps; // Temporary map cache asset holder until maps are loaded.
121};
122}
123}
124
125#endif /* HORIZON_ZONE_GAME_GAMELOGICPROCESS_HPP */
Definition: GameLogicProcess.hpp:51
LockedLookupTable< uint32_t, std::shared_ptr< monster_spawn_data > > _monster_spawn_db
Definition: GameLogicProcess.hpp:78
std::shared_ptr< GameLogicProcess > get_container()
Definition: GameLogicProcess.hpp:62
int32_t _last_monster_spawn_id
Definition: GameLogicProcess.hpp:75
void register_monster_spawn_info(uint32_t id, std::shared_ptr< monster_spawn_data > data)
Definition: GameLogicProcess.hpp:71
void initialize(std::shared_ptr< GameLogicProcess > game_logic_process)
Definition: GameLogicProcess.hpp:55
std::weak_ptr< GameLogicProcess > _game_logic_process
Definition: GameLogicProcess.hpp:77
void despawn_monsters(std::string map_name)
Definition: GameLogicProcess.cpp:328
~MonsterSpawnAgent()
Definition: GameLogicProcess.cpp:220
std::shared_ptr< monster_spawn_data > get_monster_spawn_info(uint32_t id)
Definition: GameLogicProcess.hpp:72
void reschedule_single_monster_spawn(std::shared_ptr< Horizon::Zone::Units::Monster > monster)
Definition: GameLogicProcess.cpp:225
void spawn_monsters(std::string map_name)
Definition: GameLogicProcess.cpp:264
void spawn_monster_internal(std::shared_ptr< Map > map, int spawn_dataset_id, int monster_id, int16_t amount, int16_t x, int16_t y, int16_t x_area, int16_t y_area)
Definition: GameLogicProcess.cpp:352
void clear_monster_spawn_info()
Definition: GameLogicProcess.hpp:73
Definition: GameLogicProcess.hpp:48
GameLogicProcess(struct s_game_process_configuration config)
Definition: GameLogicProcess.cpp:57
std::atomic< bool > _is_initialized
Definition: GameLogicProcess.hpp:104
void start_internal()
Definition: GameLogicProcess.cpp:159
TaskScheduler _scheduler
Definition: GameLogicProcess.hpp:117
bool is_initialized() override
Definition: GameLogicProcess.hpp:88
std::map< std::string, map_data > _maps
Definition: GameLogicProcess.hpp:119
bool load_map_cache()
Definition: GameLogicProcess.cpp:117
MonsterSpawnAgent _monster_spawn_agent
Definition: GameLogicProcess.hpp:116
std::atomic< bool > _is_finalized
Definition: GameLogicProcess.hpp:105
MonsterSpawnAgent & get_monster_spawn_agent()
Definition: GameLogicProcess.hpp:99
void on_map_update(int64_t diff)
ResourceManager _resource_manager
Definition: GameLogicProcess.hpp:111
struct s_game_process_configuration & game_config()
Definition: GameLogicProcess.hpp:101
struct s_game_process_configuration _config
Definition: GameLogicProcess.hpp:120
void finalize() override
Definition: GameLogicProcess.cpp:98
TaskScheduler & getScheduler()
Definition: GameLogicProcess.hpp:95
void update(uint64_t diff)
Definition: GameLogicProcess.cpp:194
void initialize(int segment_number=1) override
Definition: GameLogicProcess.cpp:68
std::thread _thread
Definition: GameLogicProcess.hpp:118
ResourceManager & get_resource_manager()
Definition: GameLogicProcess.hpp:113
bool is_finalized() override
Definition: GameLogicProcess.hpp:89
The class Map is the representation of a map in the game. It contains all the cells and the grid hold...
Definition: Map.hpp:62
Definition: Monster.hpp:47
Definition: Server.hpp:192
Definition: LockedLookupTable.hpp:44
void clear()
Definition: LockedLookupTable.hpp:112
void insert(const Key &key, const Value &value)
Definition: LockedLookupTable.hpp:68
Value at(Key const &key, Value const &default_value=Value()) const
Definition: LockedLookupTable.hpp:63
Definition: Server.hpp:113
The TaskScheduler class provides the ability to schedule std::function's in the near future....
Definition: TaskScheduler.hpp:58
Definition: Element.hpp:7
Definition: Server.hpp:93