Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 11732


Ignore:
Timestamp:
Feb 11, 2018, 6:04:01 PM (6 years ago)
Author:
landauf
Message:

[AsteroidMining_HS17] fixed a bunch of compile- and run-time errors due to illegal usage of arrays

Location:
code/branches/Presentation_HS17_merge/src/modules/asteroidmining
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • code/branches/Presentation_HS17_merge/src/modules/asteroidmining/AsteroidMinable.cc

    r11667 r11732  
    8585#include "core/EventIncludes.h"
    8686#include "network/NetworkFunction.h"
     87#include "util/Convert.h"
    8788#include "util/Math.h"
    8889
     
    152153        // Add Model, random one of the 6 shapes
    153154        Model* hull = new Model(this->context);
    154         char meshThingy[] = "";
    155         sprintf(meshThingy, "ast%.0f.mesh", round(5*rnd())+1);
    156         hull->setMeshSource(meshThingy);
     155        hull->setMeshSource("ast" + multi_cast<std::string>(1 + (int)rnd(0, 6)) + ".mesh");
    157156        hull->setScale(this->size);
    158157        this->attach(hull);
     
    233232            PickupSpawner* thingy = new PickupSpawner(this->context);
    234233
    235             char tname[] = ""; // can-t overwrite strings easily in C (strcat etc.)
     234            std::string tname;
    236235            if(this->size <= 5){
    237                 strcat(tname, "smallmunitionpickup");
     236                tname = "smallmunitionpickup";
    238237            }else if(this->size <= 20){
    239                 strcat(tname, "mediummunitionpickup");
     238                tname = "mediummunitionpickup";
    240239            }else{
    241                 strcat(tname, "hugemunitionpickup");
     240                tname = "hugemunitionpickup";
    242241            }
    243242            thingy->setPickupTemplateName(tname);
     
    260259    int num = round(rnd()*(massRem-1)) + 1; // random number of children, at least one
    261260    if(num > 10){num = 10;} // no max function in C?
    262     int masses[num]; // Masses of the asteroids
     261    std::vector<int> masses(num); // Masses of the asteroids
    263262    // orxout() << "SpawnChildren(): Passed basic stuff. num = " << num << "; massRem(total) = "<< massRem << endl;
    264263    massRem = massRem-num; // mass must be at least one, add later. 
    265264
    266265    // Randomnised spawning points for the new asteroids
    267     float phi[num];
    268     float theta[num];
     266    std::vector<float> phi(num);
     267    std::vector<float> theta(num);
    269268
    270269    // Discusting C stuff -> use that to initialise dynamic array values to 0.
    271     for(int twat = 0; twat<num; ++twat){masses[twat] = 0; phi[twat] = 0.0; theta[twat] = 0.0;}
     270    for(int twat = 0; twat<num; ++twat)
     271    {
     272        masses[twat] = 0;
     273        phi[twat] = 0.0f;
     274        theta[twat] = 0.0f;
     275    }
    272276
    273277    float piG = 3.1415927410125732421875; //pi; // Math.pi ist statisch oder so.
     
    310314    if(massRem>0){
    311315        int c = massRem;
    312         float probDensity[c];
     316        std::vector<float> probDensity(c);
    313317
    314318        int a = round(massRem/num);
     
    405409        // }
    406410    }
    407 
    408     // @brief Just for testing. Don-t work anyways.
    409     void AsteroidMinable::printArrayString(float thingy[]){ // Don-t work!
    410 
    411         orxout() << "[" ; //<< endl; 
    412         char frag[] = "";
    413         int len = (int)(sizeof(thingy)/sizeof(thingy[0]));
    414         for(int m = 0; m< (len-2); ++m){
    415             sprintf(frag, "%.5f, ", thingy[m]);
    416             orxout() << frag << endl;//std::flush;
    417         }
    418         sprintf(frag, "%.5f]", thingy[len-1]);
    419         orxout() << frag << endl; // Just print it here! No ugly passing.
    420     }
    421 
    422     // @brief Just for testing. Don-t work anyways.
    423     void AsteroidMinable::printArrayString(int thingy[]){
    424 
    425         orxout() << "[" ; //<< endl;
    426         char frag[] = "";
    427         int len = (int)(sizeof(thingy)/sizeof(thingy[0]));
    428         for(int m = 0; m< (len-2); ++m){
    429             sprintf(frag, "%.0i, ", thingy[m]);
    430             orxout() << frag << endl;//std::flush;
    431             printf("TEst");
    432         }
    433 
    434         sprintf(frag, "%.0i]", thingy[len-1]); // last element
    435         orxout() << frag << endl; // Just print it here! No ugly passing.
    436     }
    437 
    438     // void AsteroidMinable::printArrayString(int thingy[]){
    439     //     char res[] = "[";
    440     //     //strcat(res, "[");
    441     //     char frag[] = "";
    442 
    443     //     int len = (int)(sizeof(thingy)/sizeof(thingy[0]));
    444     //     for(int m = 0; m< (len-1); ++m){
    445     //         sprintf(frag, "%.0i, ", thingy[m]);
    446     //         strcat(res, frag);
    447     //     }
    448     //     sprintf(frag, "%.0i]", thingy[len]);
    449     //     strcat(res, frag); // last element
    450 
    451     //     orxout() << res << endl; // Just print it here! No ugly passing.
    452 
    453     //     // static char result[(sizeof(res)/sizeof("")] = res; // define as static, would get deleted otherwise.
    454     //     // char *result = malloc(sizeof(res)/sizeof("") + 1);
    455     //     // *result = res;
    456     //     // return result;
    457     // }
    458 
    459411}
  • code/branches/Presentation_HS17_merge/src/modules/asteroidmining/AsteroidMinable.h

    r11731 r11732  
    137137            virtual void spawnChildren();
    138138
    139             // @brief Just for testing. Don-t work anyways.
    140             void printArrayString(float thingy[]);
    141             // @brief Just for testing. Don-t work anyways.
    142             void printArrayString(int thingy[]);
    143 
    144139    }; // tolua_export
    145140} // tolua_export
  • code/branches/Presentation_HS17_merge/src/modules/asteroidmining/SpicedAsteroidBelt.cc

    r11667 r11732  
    100100        int segmentCount = round(this->count / this->segments);
    101101
    102         SpicedAsteroidField* af[this->segments];
    103         (void)af[0]; // avoid nasty compiler warning
    104 
    105102        float dPhi = (2 * myPi) / this->segments;
    106103        float dTheta = 4.0*this->tiltBy/this->segments;
     
    117114           
    118115            Vector3* pos = new Vector3(radius*cos(sepp)*sin(globi), radius*sin(sepp)*sin(globi), radius*cos(globi));
    119             af[s] = new SpicedAsteroidField(this->context, this->position + *pos, this->minSize, this->maxSize, width, segmentCount, this->foggy, this->mDensity, this->fogDensity);
     116            new SpicedAsteroidField(this->context, this->position + *pos, this->minSize, this->maxSize, width, segmentCount, this->foggy, this->mDensity, this->fogDensity);
    120117           
    121118        }
Note: See TracChangeset for help on using the changeset viewer.