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

Add encode() and decode() to Id

Daniele Bartolini 12 лет назад
Родитель
Сommit
27278a8630
1 измененных файлов с 12 добавлено и 5 удалено
  1. 12 5
      engine/core/containers/IdTable.h

+ 12 - 5
engine/core/containers/IdTable.h

@@ -37,12 +37,19 @@ namespace crown
 
 struct Id
 {
-	union
+	uint16_t id;
+	uint16_t index;
+
+	void decode(uint32_t id_and_index)
 	{
-		uint32_t id : 16;
-		uint32_t index : 16;
-		uint32_t value;
-	};
+		id = (id_and_index & 0xFFFF0000) >> 16;
+		index = id_and_index & 0xFFFF;
+	}
+
+	uint32_t encode()
+	{
+		return (uint32_t(id) << 16) | uint32_t(index);
+	}
 };
 
 /// Table of Ids.