Просмотр исходного кода

update UnitCompiler according to Actor implementation

mikymod 12 лет назад
Родитель
Сommit
4a82f106c0
2 измененных файлов с 30 добавлено и 1 удалено
  1. 29 1
      engine/compilers/unit/UnitCompiler.cpp
  2. 1 0
      engine/compilers/unit/UnitCompiler.h

+ 29 - 1
engine/compilers/unit/UnitCompiler.cpp

@@ -40,6 +40,7 @@ namespace crown
 UnitCompiler::UnitCompiler()
 	: m_renderable(default_allocator())
 	, m_camera(default_allocator())
+	, m_actor(default_allocator())
 {
 }
 
@@ -113,9 +114,36 @@ size_t UnitCompiler::compile_impl(Filesystem& fs, const char* resource_path)
 		}
 	}
 
+	// check for actors
+	if (root.has_key("actor"))
+	{
+		JSONElement actor = root.key("actor");
+		uint32_t num_actors = actor.size();
+
+		for (uint32_t i = 0; i < num_actors; i++)
+		{
+			JSONElement actor_name = actor[i].key("name");
+			JSONElement actor_type = actor[i].key("type");
+			JSONElement actor_shape = actor[i].key("shape");
+			JSONElement actor_active = actor[i].key("active");
+
+			UnitActor ua;
+			ua.name = hash::murmur2_32(actor_name.string_value(), actor_name.size(), 0);
+			ua.type = string::strcmp(actor_type.string_value(), "STATIC") == 0 ? UnitActor::STATIC :
+					string::strcmp(actor_type.string_value(), "DYNAMIC") == 0 ? UnitActor::DYNAMIC : UnitActor::UNK_TYPE;
+			ua.shape = string::strcmp(actor_shape.string_value(), "SPHERE") == 0 ? UnitActor::SPHERE :
+						string::strcmp(actor_shape.string_value(), "BOX") == 0 ? UnitActor::BOX :
+						string::strcmp(actor_shape.string_value(), "PLANE") == 0 ? UnitActor::PLANE : UnitActor::UNK_SHAPE;
+			ua.active = actor_active.bool_value();
+
+			m_actor.push_back(ua);
+		}
+	}
+
 	return sizeof(UnitHeader) +
 			m_renderable.size() * sizeof(UnitRenderable) +
-			m_camera.size() * sizeof(UnitCamera);
+			m_camera.size() * sizeof(UnitCamera) +
+			m_actor.size() * sizeof(UnitActor);
 }
 
 //-----------------------------------------------------------------------------

+ 1 - 0
engine/compilers/unit/UnitCompiler.h

@@ -47,6 +47,7 @@ private:
 
 	List<UnitRenderable> m_renderable;
 	List<UnitCamera> m_camera;
+	List<UnitActor> m_actor;
 };
 
 } // namespace crown