Browse Source

Synchronisierungsmöglichkeit zu 2dObjekten hinzugefügt

Kolja Strohm 5 years ago
parent
commit
59ec506dad
2 changed files with 16 additions and 0 deletions
  1. 11 0
      Welt2D.cpp
  2. 5 0
      Welt2D.h

+ 11 - 0
Welt2D.cpp

@@ -15,6 +15,12 @@ Object2D::Object2D()
 Object2D::~Object2D()
 {}
 
+// Übergibt einen Void Funktionspointer auf eine Aktion die einmalig vom Hauptthread ausgeführt werden soll. (Passiert nach dem Tick)
+void Object2D::postAction( std::function< void() > action )
+{
+    actions.push( action );
+}
+
 void Object2D::explosion( Vertex worldPos, float intensity )
 {
     intensity /= ( position - worldPos ).getLengthSq();
@@ -125,6 +131,11 @@ bool Object2D::handleCollision( Object2D *obj )
 
 bool Object2D::tick( const WeltInfo &info, double zeit )
 {
+    while( !actions.empty() )
+    {
+        actions.front()( );
+        actions.pop();
+    }
     rotation += rSpeed * (float)zeit;
     while( rotation > PI * 2 )
         rotation -= (float)PI * 2;

+ 5 - 0
Welt2D.h

@@ -1,5 +1,7 @@
 #pragma once
 
+#include <queue>
+#include <functional>
 #include "Array.h"
 #include "Mat3.h"
 #include "Punkt.h"
@@ -21,6 +23,7 @@ namespace Framework
     class Object2D
     {
     protected:
+        std::queue< std::function< void() > > actions;
         Vertex position;
         Vertex speed;
         float rSpeed;
@@ -32,6 +35,8 @@ namespace Framework
     public:
         __declspec( dllexport ) Object2D();
         __declspec( dllexport ) virtual ~Object2D();
+        // Übergibt einen Void Funktionspointer auf eine Aktion die einmalig vom Hauptthread ausgeführt werden soll. (Passiert nach dem Tick)
+        __declspec( dllexport ) void postAction( std::function< void() > action );
         // Fügt einen Schub in die ausbreitungsrichtung der Explusion zur Bewegung des Objektes hinzu
         //  worldPos: Die Position des Explusionsuhrsprungs
         //  intensity: Die Intensität der Explusion