SpiecsEngine
 
Loading...
Searching...
No Matches
WorldFunctions.cpp
Go to the documentation of this file.
1/**
2* @file WorldFunctions.cpp.
3* @brief The WorldFunctions Class Implementation.
4* @author Spices.
5*/
6
7#include "Pchheader.h"
9#include "World/Entity.h"
10
11namespace Spices {
12
13 void WorldFunctions::CreateMeshEntity(
14 World* world ,
15 const std::string& name ,
16 std::function<std::shared_ptr<Mesh>()> onMeshCreated ,
17 std::function<void(Entity&)> onAdded
18 )
19 {
20 AsyncTask(ThreadPoolEnum::Custom, [=]() {
21
22 SPICES_PROFILE_ZONEN("CreateBasicMeshEntity");
23
24 auto mesh = onMeshCreated();
25
26 CreateMeshEntity(world, name, mesh, onAdded);
27 });
28 }
29
30 void WorldFunctions::CreateMeshEntity(
31 World* world ,
32 const std::string& name ,
33 const std::shared_ptr<Mesh>& mesh ,
34 std::function<void(Entity&)> onAdded
35 )
36 {
37 AsyncMainTask(ThreadPoolEnum::Main, [=]() {
38
39 SPICES_PROFILE_ZONEN("CreateMeshEntity");
40
41 Entity entity = world->CreateEntity(name);
42 auto& meshComp = entity.AddComponent<MeshComponent>();
43
44 meshComp.SetMesh(mesh);
45
46 if(onAdded) onAdded(entity);
47
48 /**
49 * @brief Mark World with MeshAddedToWorld bits.
50 */
51 world->Mark(World::WorldMarkBits::MeshAddedToWorld);
52 });
53 }
54}
#define SPICES_PROFILE_ZONEN(...)
Entity Class. This class defines the specific behaves of Entity.
Definition Entity.h:20
MeshRenderer Class. This class is a wrapper of mashpack.
Definition Mesh.h:21
World Functions Class.
World Class. This class defines the basic behaves of World. When we create an new world,...
Definition World.h:41