Daniele Bartolini 9 jaren geleden
bovenliggende
commit
3a54027f5a
2 gewijzigde bestanden met toevoegingen van 16 en 20 verwijderingen
  1. 11 10
      src/core/containers/event_stream.h
  2. 5 10
      src/world/world.cpp

+ 11 - 10
src/core/containers/event_stream.h

@@ -10,6 +10,12 @@
 
 namespace crown
 {
+struct EventHeader
+{
+	u32 type;
+	u32 size;
+};
+
 /// Array of generic event structs.
 ///
 /// @ingroup Containers
@@ -23,20 +29,14 @@ typedef Array<char> EventStream;
 /// @ingroup Containers
 namespace event_stream
 {
-	struct Header
-	{
-		u32 type;
-		u32 size;
-	};
-
 	/// Appends the @a event of the given @a type and @a size to the stream @a s.
 	inline void write(EventStream& s, u32 type, u32 size, const void* event)
 	{
-		Header header;
-		header.type = type;
-		header.size = size;
+		EventHeader eh;
+		eh.type = type;
+		eh.size = size;
 
-		array::push(s, (char*)&header, sizeof(Header));
+		array::push(s, (char*)&eh, sizeof(eh));
 		array::push(s, (char*)event, size);
 	}
 
@@ -47,4 +47,5 @@ namespace event_stream
 		event_stream::write(s, type, sizeof(T), &event);
 	}
 } // namespace event_stream
+
 } // namespace crown

+ 5 - 10
src/world/world.cpp

@@ -136,18 +136,16 @@ void World::update_scene(f32 dt)
 	u32 read = 0;
 	while (read < size)
 	{
-		event_stream::Header h;
+		const EventHeader* esh = (EventHeader*)&physics_events[read];
+		const char* data = (char*)&esh[1];
 
-		const char* data = &physics_events[read];
-		const char* ev   = data + sizeof(h);
+		read += sizeof(esh) + esh->size;
 
-		h = *(event_stream::Header*)data;
-
-		switch (h.type)
+		switch (esh->type)
 		{
 		case EventType::PHYSICS_TRANSFORM:
 			{
-				const PhysicsTransformEvent& ptev = *(PhysicsTransformEvent*)ev;
+				const PhysicsTransformEvent& ptev = *(PhysicsTransformEvent*)data;
 				const TransformInstance ti = _scene_graph->get(ptev.unit_id);
 				const Matrix4x4 pose = matrix4x4(ptev.rotation, ptev.position);
 				_scene_graph->set_world_pose(ti, pose);
@@ -164,9 +162,6 @@ void World::update_scene(f32 dt)
 			CE_FATAL("Unknown event type");
 			break;
 		}
-
-		read += sizeof(h);
-		read += h.size;
 	}
 	array::clear(physics_events);