Nymph Game Engine
Chaiscript based Game Engine
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
scene_generator.h
Go to the documentation of this file.
1 #ifndef SCENE_GENERATOR_H
2 #define SCENE_GENERATOR_H
3 #include <memory>
4 #include <map>
6 #include "graphics/vertex_data.h"
9 #include "graphics/renderable.h"
11 #include "component_manager.h"
12 #include "entity.h"
13 #include "scene.h"
14 #include "map.h"
15 #include "sprite_movement.h"
16 //= SCRIPTABLE
17 
18 namespace Game {
20  private:
21 
22  struct AnimationPlaceholder {
23  std::string sprite_name;
24  SpriteMovementMotor::SpriteState default_animation;
25  int x_pos;
26  int y_pos;
27  float z_order;
28  };
29 
30  struct MapRenderables {
31  std::vector<std::shared_ptr<Entity>> entities;
32  std::vector<AnimationPlaceholder> dynamic_animations;
33  };
34 
35  struct DynamicAnimation {
36  std::shared_ptr<Entity> entity;
37  std::shared_ptr<Graphics::TileAnimator<SpriteMovementMotor::SpriteState>> animator;
38  };
39 
40  std::weak_ptr<Graphics::TextureManager> texture_manager;
41  std::weak_ptr<Graphics::ShaderManager> shader_manager;
42  std::map<std::string, DynamicAnimation> dynamic_animations;
43 
44  unsigned int ui_z_slots;
45 
46  Graphics::VertexData generateBasisCube();
47  Graphics::VertexData generateBasisTile(const unsigned int base_width, const unsigned int base_height, const unsigned int current_width, const unsigned int current_height, const unsigned int x_pos = 0, const unsigned int y_pos = 0, const unsigned int offset_x = 0, const unsigned int offset_y = 0);
48  std::shared_ptr<Graphics::BaseTexture> textureFromTileset(const Tmx::Tileset* tileset, const std::string& path);
49  std::shared_ptr<Graphics::BaseTexture> normalTextureFromTileset(const Tmx::Tileset* tileset, const std::string& path);
50  std::shared_ptr<Graphics::BaseTexture> displacementTextureFromTileset(const Tmx::Tileset* tileset, const std::string& path);
51  std::vector<glm::vec2> generateTextureCoords(const Tmx::TileLayer* layer, const unsigned int x_pos, const unsigned int y_pos, const unsigned int texture_width, const unsigned int texture_height, const unsigned int tile_width, const unsigned int tile_height);
52  std::vector<glm::vec3> generateVertexCoords(const unsigned int base_width, const unsigned int base_height, const unsigned int current_width, const unsigned int current_height, const unsigned int x_pos = 0, const unsigned int y_pos = 0, const unsigned int offset_x = 0, const unsigned int offset_y = 0);
53 
54 
55  MapRenderables createRenderablesFromMap(const unsigned int patch_width_tiles, const unsigned int patch_height_tiles, const Map& map);
56  std::vector<std::shared_ptr<Entity>> createStaticallyAnimatedTilesFromMap(const Map& map);
57  std::map<std::string, DynamicAnimation> createAnimationsFromAnimationMap(const Map& map);
58  std::vector<std::shared_ptr<Component>> createLightsFromMap(const Map& map);
59  std::shared_ptr<Physics::CollisionData> createCollisionDataFromMap(const Map& map);
60 
61  SpriteMovementMotor::SpriteState transformStateStringToEnum(const std::string& state);
62 
63  float calculateZ(unsigned int layer_index, unsigned int layers_total);
64  public:
65  SceneGenerator() = delete;
67 
68  //= BEGIN SCRIPTABLE
69 
77  SceneGenerator(const Map& animation_index, std::shared_ptr<Graphics::TextureManager> texture_manager, std::shared_ptr<Graphics::ShaderManager> shader_manager, const unsigned int ui_z_slots);
83  SceneGenerator(const SceneGenerator& s) = default;
91  SceneGenerator& operator=(const SceneGenerator& other) = default;
92 
102  std::shared_ptr<Scene> createSceneFromMap(const unsigned int patch_width_tiles, const unsigned int patch_height_tiles, const Map& map);
103 
111  std::shared_ptr<Entity> getDynamicEntityByName(const std::string& name);
112 
118  std::vector<std::string> getDynamicEntityNames() const noexcept;
119 
127  std::string getStrippedMapName(const std::string path);
128  //= END SCRIPTABLE
129  };
130 }
131 
132 #endif
SceneGenerator & operator=(const SceneGenerator &other)=default
SceneGenerator equal operator.
SpriteState
Sprite state enum.
Definition: sprite_movement.h:21
Class for vertex data.
Definition: vertex_data.h:17
std::string getStrippedMapName(const std::string path)
Strips path specification from map name.
Definition: scene_generator.cpp:668
std::shared_ptr< Entity > getDynamicEntityByName(const std::string &name)
Gets a dynamic entity by name.
Definition: scene_generator.cpp:310
std::vector< std::string > getDynamicEntityNames() const noexcept
Gets all dynamic entity names.
Definition: scene_generator.cpp:319
Class wrapper for Tmx::Map.
Definition: map.h:11
Definition: scene_generator.h:19
~SceneGenerator()
Definition: scene_generator.cpp:24
std::shared_ptr< Scene > createSceneFromMap(const unsigned int patch_width_tiles, const unsigned int patch_height_tiles, const Map &map)
Creates a scene from a map.
Definition: scene_generator.cpp:276