Selaa lähdekoodia

Fix type icompabilities

- float32 does not exist anymore (using float instead)
- userdata isn't stored in a void pointer anymore (class b2UserData)
DricomDragon 4 vuotta sitten
vanhempi
commit
bb0a5776bd
2 muutettua tiedostoa jossa 15 lisäystä ja 15 poistoa
  1. 7 7
      Missiles.cpp
  2. 8 8
      main.cpp

+ 7 - 7
Missiles.cpp

@@ -21,7 +21,7 @@ void updateMissiles( b2World &world, b2Body* target, bool foresee )
 	for ( b2Body* b( world.GetBodyList() ); b; b = b->GetNext() )
     {
     	// Description de l'entité
-        descr = (Entity*)b->GetUserData();
+        descr = (Entity*)b->GetUserData().pointer;
 
         // Skip entités non missile
         if ( descr == 0x0 || descr->id == LAND || descr->id == PLANE )
@@ -70,7 +70,7 @@ void updateMissiles( b2World &world, b2Body* target, bool foresee )
     // Destruction des missiles détruits
     for ( unsigned int k(0); k < dustbin.size(); k++ )
     {
-    	delete (Entity*)dustbin[k]->GetUserData() ;
+    	delete (Entity*)dustbin[k]->GetUserData().pointer;
 
     	world.DestroyBody( dustbin[k] );
     	dustbin[k] = nullptr;
@@ -82,7 +82,7 @@ void createInert( b2Vec2 from, b2Body* target, b2World &world, Identity missile
 	// Body
 	b2BodyDef bodyDef;
 	bodyDef.position = from;
-    bodyDef.userData = new Entity( {0.01f, missile} );
+    bodyDef.userData.pointer = (uintptr_t) new Entity( {0.01f, missile} );
 
     bodyDef.type = b2_dynamicBody;
     bodyDef.linearDamping = 0.01f;
@@ -133,19 +133,19 @@ b2Vec2 anticipate( b2Body* missile, b2Body* target )
 {
     // Vecteur entre le missile et la cible
     b2Vec2 destination( target->GetPosition() - missile->GetPosition() );
-    float32 distance( destination.Length() );
+    float distance( destination.Length() );
     destination *= ( 1.0f / distance );
 
     // Données sur le missile
     b2Vec2 vMissile_vec( missile->GetLinearVelocity() );
 
     // Vitesse d'approche
-    float32 incoming( b2Dot(vMissile_vec, destination) );
+    float incoming( b2Dot(vMissile_vec, destination) );
     if ( incoming == 0.0f )
         return target->GetPosition() ;
 
     // Temps d'approche
-    float32 tau( distance / incoming );
+    float tau( distance / incoming );
 
     // Données de la cible
     b2Vec2 vPlane_vec( target->GetLinearVelocity() );
@@ -155,4 +155,4 @@ b2Vec2 anticipate( b2Body* missile, b2Body* target )
 
     // Fin du calcul
     return rep;
-}
+}

+ 8 - 8
main.cpp

@@ -84,24 +84,24 @@ int main(int argc, char** argv)
     std::vector<b2Body*> deadBodies;
 
     // Simulation settings
-    float32 timeStep = 1.0f / frameRate;
+    float timeStep = 1.0f / frameRate;
     int32 velocityIterations = 8;
     int32 positionIterations = 3;
 
     // Variables
     b2Vec2 position, force;
-    float32 angle;
+    float angle;
     Entity* descr( nullptr );
 
 	// Define the edge body
 	b2BodyDef bodyDef;
 	bodyDef.position.Set(0.0f, 0.0f);
-    bodyDef.userData = new Entity( {0.0f, LAND} );
+    bodyDef.userData.pointer = (uintptr_t) new Entity( {0.0f, LAND} );
 	b2Body* areaBody = world.CreateBody(&bodyDef);
 
 	b2Vec2 vs[4];
-	float32 areah( (float32)screen->h / MULTI );
-	float32 areaw( (float32)screen->w / MULTI );
+	float areah( (float)screen->h / MULTI );
+	float areaw( (float)screen->w / MULTI );
 	vs[0].Set( 0.0f, 0.0f );
 	vs[1].Set( 0.0f, areah );
 	vs[2].Set( areaw, areah );
@@ -113,7 +113,7 @@ int main(int argc, char** argv)
     // Define the plane body
     bodyDef.type = b2_dynamicBody;
     bodyDef.position.Set(areaw * 0.5f, areaw * 0.5f );
-    bodyDef.userData = new Entity( {0.05f, PLANE} );
+    bodyDef.userData.pointer = (uintptr_t) new Entity( {0.05f, PLANE} );
     bodyDef.linearDamping = 0.01f;
     bodyDef.fixedRotation = true ;
     b2Body* plane = world.CreateBody(&bodyDef);
@@ -250,7 +250,7 @@ int main(int argc, char** argv)
                 break;
             case SDL_MOUSEBUTTONDOWN:
                 std::cout << "Création tourelle." << std::endl;
-                tourelle.push_back({b2Vec2( (float32)mouse.x/MULTI, (float32)mouse.y/MULTI),
+                tourelle.push_back({b2Vec2( (float)mouse.x/MULTI, (float)mouse.y/MULTI),
                                     missile,
                                     SDL_GetTicks(),
                                     weap_wait});
@@ -321,7 +321,7 @@ int main(int argc, char** argv)
         for ( b2Body* b( world.GetBodyList() ); b; b = b->GetNext() )
         {
             // Besoin d'afficher ?
-            descr = (Entity*)b->GetUserData();
+            descr = (Entity*)b->GetUserData().pointer;
 
             if ( descr == nullptr || descr->id == LAND )
                 continue ;