[Orxonox-commit 7115] r11732 - code/branches/Presentation_HS17_merge/src/modules/asteroidmining
landauf at orxonox.net
landauf at orxonox.net
Sun Feb 11 18:04:01 CET 2018
Author: landauf
Date: 2018-02-11 18:04:01 +0100 (Sun, 11 Feb 2018)
New Revision: 11732
Modified:
code/branches/Presentation_HS17_merge/src/modules/asteroidmining/AsteroidMinable.cc
code/branches/Presentation_HS17_merge/src/modules/asteroidmining/AsteroidMinable.h
code/branches/Presentation_HS17_merge/src/modules/asteroidmining/SpicedAsteroidBelt.cc
Log:
[AsteroidMining_HS17] fixed a bunch of compile- and run-time errors due to illegal usage of arrays
Modified: code/branches/Presentation_HS17_merge/src/modules/asteroidmining/AsteroidMinable.cc
===================================================================
--- code/branches/Presentation_HS17_merge/src/modules/asteroidmining/AsteroidMinable.cc 2018-02-11 16:13:24 UTC (rev 11731)
+++ code/branches/Presentation_HS17_merge/src/modules/asteroidmining/AsteroidMinable.cc 2018-02-11 17:04:01 UTC (rev 11732)
@@ -84,6 +84,7 @@
#include "core/XMLPort.h"
#include "core/EventIncludes.h"
#include "network/NetworkFunction.h"
+#include "util/Convert.h"
#include "util/Math.h"
#include "../pickup/PickupSpawner.h"
@@ -151,9 +152,7 @@
// Add Model, random one of the 6 shapes
Model* hull = new Model(this->context);
- char meshThingy[] = "";
- sprintf(meshThingy, "ast%.0f.mesh", round(5*rnd())+1);
- hull->setMeshSource(meshThingy);
+ hull->setMeshSource("ast" + multi_cast<std::string>(1 + (int)rnd(0, 6)) + ".mesh");
hull->setScale(this->size);
this->attach(hull);
@@ -232,13 +231,13 @@
if(dropStuff){
PickupSpawner* thingy = new PickupSpawner(this->context);
- char tname[] = ""; // can-t overwrite strings easily in C (strcat etc.)
+ std::string tname;
if(this->size <= 5){
- strcat(tname, "smallmunitionpickup");
+ tname = "smallmunitionpickup";
}else if(this->size <= 20){
- strcat(tname, "mediummunitionpickup");
+ tname = "mediummunitionpickup";
}else{
- strcat(tname, "hugemunitionpickup");
+ tname = "hugemunitionpickup";
}
thingy->setPickupTemplateName(tname);
thingy->setPosition(this->getPosition());
@@ -259,16 +258,21 @@
int massRem = this->size-1; //some mass is lost
int num = round(rnd()*(massRem-1)) + 1; // random number of children, at least one
if(num > 10){num = 10;} // no max function in C?
- int masses[num]; // Masses of the asteroids
+ std::vector<int> masses(num); // Masses of the asteroids
// orxout() << "SpawnChildren(): Passed basic stuff. num = " << num << "; massRem(total) = "<< massRem << endl;
massRem = massRem-num; // mass must be at least one, add later.
// Randomnised spawning points for the new asteroids
- float phi[num];
- float theta[num];
+ std::vector<float> phi(num);
+ std::vector<float> theta(num);
// Discusting C stuff -> use that to initialise dynamic array values to 0.
- for(int twat = 0; twat<num; ++twat){masses[twat] = 0; phi[twat] = 0.0; theta[twat] = 0.0;}
+ for(int twat = 0; twat<num; ++twat)
+ {
+ masses[twat] = 0;
+ phi[twat] = 0.0f;
+ theta[twat] = 0.0f;
+ }
float piG = 3.1415927410125732421875; //pi; // Math.pi ist statisch oder so.
float d_p = 2*piG/num;
@@ -309,7 +313,7 @@
// Triangular, discrete probability "density" with max at the average value massRem/num. 50% chance to be below that.
if(massRem>0){
int c = massRem;
- float probDensity[c];
+ std::vector<float> probDensity(c);
int a = round(massRem/num);
int b = c-a;
@@ -404,56 +408,4 @@
// // this->getController()->hit(originator, contactpoint, damage); // changed to damage, why shielddamage?
// }
}
-
- // @brief Just for testing. Don-t work anyways.
- void AsteroidMinable::printArrayString(float thingy[]){ // Don-t work!
-
- orxout() << "[" ; //<< endl;
- char frag[] = "";
- int len = (int)(sizeof(thingy)/sizeof(thingy[0]));
- for(int m = 0; m< (len-2); ++m){
- sprintf(frag, "%.5f, ", thingy[m]);
- orxout() << frag << endl;//std::flush;
- }
- sprintf(frag, "%.5f]", thingy[len-1]);
- orxout() << frag << endl; // Just print it here! No ugly passing.
- }
-
- // @brief Just for testing. Don-t work anyways.
- void AsteroidMinable::printArrayString(int thingy[]){
-
- orxout() << "[" ; //<< endl;
- char frag[] = "";
- int len = (int)(sizeof(thingy)/sizeof(thingy[0]));
- for(int m = 0; m< (len-2); ++m){
- sprintf(frag, "%.0i, ", thingy[m]);
- orxout() << frag << endl;//std::flush;
- printf("TEst");
- }
-
- sprintf(frag, "%.0i]", thingy[len-1]); // last element
- orxout() << frag << endl; // Just print it here! No ugly passing.
- }
-
- // void AsteroidMinable::printArrayString(int thingy[]){
- // char res[] = "[";
- // //strcat(res, "[");
- // char frag[] = "";
-
- // int len = (int)(sizeof(thingy)/sizeof(thingy[0]));
- // for(int m = 0; m< (len-1); ++m){
- // sprintf(frag, "%.0i, ", thingy[m]);
- // strcat(res, frag);
- // }
- // sprintf(frag, "%.0i]", thingy[len]);
- // strcat(res, frag); // last element
-
- // orxout() << res << endl; // Just print it here! No ugly passing.
-
- // // static char result[(sizeof(res)/sizeof("")] = res; // define as static, would get deleted otherwise.
- // // char *result = malloc(sizeof(res)/sizeof("") + 1);
- // // *result = res;
- // // return result;
- // }
-
-}
\ No newline at end of file
+}
Modified: code/branches/Presentation_HS17_merge/src/modules/asteroidmining/AsteroidMinable.h
===================================================================
--- code/branches/Presentation_HS17_merge/src/modules/asteroidmining/AsteroidMinable.h 2018-02-11 16:13:24 UTC (rev 11731)
+++ code/branches/Presentation_HS17_merge/src/modules/asteroidmining/AsteroidMinable.h 2018-02-11 17:04:01 UTC (rev 11732)
@@ -136,11 +136,6 @@
// @brief If the option generateSmaller is enabled, individual fragments are added with this method.
virtual void spawnChildren();
- // @brief Just for testing. Don-t work anyways.
- void printArrayString(float thingy[]);
- // @brief Just for testing. Don-t work anyways.
- void printArrayString(int thingy[]);
-
}; // tolua_export
} // tolua_export
Modified: code/branches/Presentation_HS17_merge/src/modules/asteroidmining/SpicedAsteroidBelt.cc
===================================================================
--- code/branches/Presentation_HS17_merge/src/modules/asteroidmining/SpicedAsteroidBelt.cc 2018-02-11 16:13:24 UTC (rev 11731)
+++ code/branches/Presentation_HS17_merge/src/modules/asteroidmining/SpicedAsteroidBelt.cc 2018-02-11 17:04:01 UTC (rev 11732)
@@ -99,9 +99,6 @@
float radius = (this->radius1 + this->radius0) / 2.0;
int segmentCount = round(this->count / this->segments);
- SpicedAsteroidField* af[this->segments];
- (void)af[0]; // avoid nasty compiler warning
-
float dPhi = (2 * myPi) / this->segments;
float dTheta = 4.0*this->tiltBy/this->segments;
float sepp = -this->tiltAt;
@@ -116,7 +113,7 @@
}
Vector3* pos = new Vector3(radius*cos(sepp)*sin(globi), radius*sin(sepp)*sin(globi), radius*cos(globi));
- af[s] = new SpicedAsteroidField(this->context, this->position + *pos, this->minSize, this->maxSize, width, segmentCount, this->foggy, this->mDensity, this->fogDensity);
+ new SpicedAsteroidField(this->context, this->position + *pos, this->minSize, this->maxSize, width, segmentCount, this->foggy, this->mDensity, this->fogDensity);
}
More information about the Orxonox-commit
mailing list