diff --git a/src/creatureviewer/main_cw.cpp b/src/creatureviewer/main_cw.cpp index b306ba6..cf53305 100644 --- a/src/creatureviewer/main_cw.cpp +++ b/src/creatureviewer/main_cw.cpp @@ -101,6 +101,7 @@ int main(int argc, char *argv[]) cw.showMaximized(); splash.finish(&cw); + // DOESN'T WORK ?!? // First launch QSettings mySettings; diff --git a/src/genecraft/apps/genecraft/creatureviewer/ui/creatureviewerwindow.cpp b/src/genecraft/apps/genecraft/creatureviewer/ui/creatureviewerwindow.cpp index 7f9163d..4caed56 100644 --- a/src/genecraft/apps/genecraft/creatureviewer/ui/creatureviewerwindow.cpp +++ b/src/genecraft/apps/genecraft/creatureviewer/ui/creatureviewerwindow.cpp @@ -265,7 +265,7 @@ void CreatureViewerWindow::init() { // ------------------ // Welcome - WelcomeWidget *welcomeWidget = new WelcomeWidget(); + WelcomeWidget *welcomeWidget = new WelcomeWidget(this); welcomeWidget->setMaximumSize(400, 166725); ui->dwWelcome->setWidget(welcomeWidget); @@ -292,9 +292,10 @@ void CreatureViewerWindow::init() { bonePropertiesController = new BonePropertiesController(); bonePropertiesController->connectToInspectorInputManager(cvim); ui->dwBone->setWidget(bonePropertiesController); + simulationManager->addGraphicalWidget(bonePropertiesController); // Stats - statsPropertiesController = new StatisticsPropertiesController(); + statsPropertiesController = new StatisticsPropertiesController(this); ui->dwStats->setWidget(statsPropertiesController); statsPropertiesController->connectToInspectorInputManager(cvim); @@ -360,7 +361,6 @@ void CreatureViewerWindow::init() { //entitySpawner->start(); connect(entitySpawner, SIGNAL(timeout()), this, SLOT(spawnNew())); - switchToWelcomeMode(); } diff --git a/src/genecraft/core/engines/bullet/shapes/btbone.cpp b/src/genecraft/core/engines/bullet/shapes/btbone.cpp index 5a2eed2..91839e4 100644 --- a/src/genecraft/core/engines/bullet/shapes/btbone.cpp +++ b/src/genecraft/core/engines/bullet/shapes/btbone.cpp @@ -94,6 +94,7 @@ void btBone::init(btScalar length, this->rigidBody = new btRigidBody(mass,motionState,shape,localInertia); this->rigidBody->setFriction(friction); + this->rigidBody->setActivationState(DISABLE_DEACTIVATION); } void btBone::setup() diff --git a/src/genecraft/core/engines/bullet/shapes/btbox.cpp b/src/genecraft/core/engines/bullet/shapes/btbox.cpp index f444b60..44221fc 100644 --- a/src/genecraft/core/engines/bullet/shapes/btbox.cpp +++ b/src/genecraft/core/engines/bullet/shapes/btbox.cpp @@ -47,10 +47,6 @@ void btBox::init(btVector3 size, const btTransform &transform, const btScalar de btScalar friction = 0.9; - qDebug() << transform.getOrigin().x(); - qDebug() << transform.getOrigin().y(); - qDebug() << transform.getOrigin().z(); - // shape this->shape = new btBoxShape(btVector3(size.x()/2.0,size.y()/2.0,size.z()/2.0)); this->motionState = new btDefaultMotionState(transform); diff --git a/src/genecraft/core/engines/simulationmanager.cpp b/src/genecraft/core/engines/simulationmanager.cpp index 4f322ce..25a791d 100644 --- a/src/genecraft/core/engines/simulationmanager.cpp +++ b/src/genecraft/core/engines/simulationmanager.cpp @@ -114,6 +114,7 @@ namespace GeneCraftCore { if(fitness) fitness->step(); + } void SimulationManager::renderUpdate() { @@ -132,6 +133,12 @@ namespace GeneCraftCore { this->eventsManager->afterStep(); //this->translationEngine->afterStep(); this->renderEngine->afterStep(); + + // Update some graphical widgets + foreach(GraphicalWidget* wi, graphWidgets) { + wi->step(); + } + } void SimulationManager::setPhysicsFreq(int stepBySec) { @@ -140,5 +147,9 @@ namespace GeneCraftCore { stepBySec = 1; this->stepTimer->setInterval(1000/stepBySec); } + + void SimulationManager::addGraphicalWidget(GraphicalWidget *widget) { + this->graphWidgets.append(widget); + } } diff --git a/src/genecraft/core/engines/simulationmanager.h b/src/genecraft/core/engines/simulationmanager.h index 69919dd..f68f656 100644 --- a/src/genecraft/core/engines/simulationmanager.h +++ b/src/genecraft/core/engines/simulationmanager.h @@ -22,11 +22,13 @@ along with Genecraft-Project. If not, see . #include "genecraftcoreclasses.h" #include "widgets/plot/fitnessplot.h" +#include "widgets/graphicalwidget.h" #include #include #include #include +#include namespace GeneCraftCore { @@ -40,6 +42,7 @@ namespace GeneCraftCore { SimulationManager(QMap, QObject *parent = 0); void addEngine(QString name, Engine *engine); + void addGraphicalWidget(GraphicalWidget* widget); void removeEngine(QString name); inline int getPhysicsFreq() @@ -72,6 +75,8 @@ namespace GeneCraftCore { Engine* translationEngine; Engine* eventsManager; + QList graphWidgets; + // Execution timer int nbSteps; int stepBySec; diff --git a/src/genecraft/core/engines/terrain/terrain.cpp b/src/genecraft/core/engines/terrain/terrain.cpp index 121128b..22cb0fe 100644 --- a/src/genecraft/core/engines/terrain/terrain.cpp +++ b/src/genecraft/core/engines/terrain/terrain.cpp @@ -108,6 +108,9 @@ namespace GeneCraftCore { break; } + if(x == 0 && z == 0) + y = 1; + btVector3 size(terrain->width, terrain->height + terrain->randomHeight, terrain->width); btVector3 pos(x*terrain->width, @@ -180,6 +183,7 @@ namespace GeneCraftCore { void Terrain::removeTerrain(TerrainData* terrain) { this->terrains.removeAll(terrain); + qDeleteAll(terrain->blocs); delete terrain; } } diff --git a/src/genecraft/core/entities/body/bone.cpp b/src/genecraft/core/entities/body/bone.cpp index e8dccbe..bfe1ab1 100644 --- a/src/genecraft/core/entities/body/bone.cpp +++ b/src/genecraft/core/entities/body/bone.cpp @@ -50,6 +50,7 @@ Bone::Bone(btShapesFactory *shapesFactory, btScalar yAxis, btScalar zAxis, btSca : QObject(), yAxis(yAxis), zAxis(zAxis), parentFix(NULL), motorsEffector(NULL) { + motorModifierData = QVariant(); parentCt = 0; body = shapesFactory->createBone(length, radius, endFixRadius, initTransform); @@ -63,6 +64,9 @@ Bone::Bone(btShapesFactory *shapesFactory, btScalar yAxis, btScalar zAxis, btSca endFix = new Fixation(shapesFactory, rigidBody, endFixRadius, endTransform, this); this->shapesFactory = shapesFactory; + this->ref = NULL; + this->sym = NULL; + this->rec = NULL; } Bone::~Bone() @@ -76,13 +80,6 @@ Bone::~Bone() } void Bone::remove() { - -// do it out of here, else bones are remove from fix and can't be deleted because we lose the pointer... -// if(parentFix != NULL) { -// parentFix->removeBone(this); -// parentFix = NULL; -// } - endFix->remove(); entity->removeLinksToEffector(this->motorsEffector); disconnectMotor(0); @@ -233,7 +230,28 @@ void Bone::connectMotor(int i) // ---------------------- void Bone::setyAxis(btScalar yAxis) { + + // Apply this to all referees + foreach(Bone* b, this->referees) { + b->setyAxis(yAxis); + } + + // Do the local modification + QVariantMap localOrientation; + localOrientation["y"] = yAxis; + localOrientation["z"] = zAxis; + + QVariantMap boneMap; + boneMap["endFix"] = QVariantMap(); // don't care + boneMap["localRotation"] = localOrientation; + + foreach(GenomeModifier* modifier, this->usedModifiers) { + boneMap = modifier->modify(boneMap).toMap(); + } + + yAxis = boneMap["localRotation"].toMap()["y"].toFloat(); this->yAxis = yAxis; + btQuaternion local1; local1.setRotation(btVector3(0, 1, 0), yAxis); btQuaternion local2; @@ -244,6 +262,30 @@ void Bone::setyAxis(btScalar yAxis) { } void Bone::setZAxis(btScalar zAxis) { + // Apply this to all referees + foreach(Bone* b, this->referees) { + b->setZAxis(zAxis); + } + + // Do the local modification + QVariantMap localOrientation; + localOrientation["y"] = yAxis; + localOrientation["z"] = zAxis; + + QVariantMap boneMap; + QVariantMap endMap; + endMap["radius"] = 0; // don't care + boneMap["endFix"] = endMap; + boneMap["localRotation"] = localOrientation; + + foreach(GenomeModifier* modifier, this->usedModifiers) { + boneMap = modifier->modify(boneMap).toMap(); + } + + zAxis = boneMap["localRotation"].toMap()["z"].toFloat(); + this->zAxis = zAxis; + + this->zAxis = zAxis; btQuaternion local1; local1.setRotation(btVector3(0, 1, 0), yAxis); @@ -390,6 +432,25 @@ void Bone::setSelected(bool selected) void Bone::setSize(btScalar radius, btScalar length) { + foreach(Bone* referee, referees) { + referee->setSize(radius, length); + } + + // Calculate the new size + QVariantMap boneMap; + boneMap["length"] = length; + boneMap["radius"] = radius; + QVariantMap endFixMap; + endFixMap["radius"] = 0; // Don't care + boneMap["endFix"] = endFixMap; + + foreach(GenomeModifier* modifier, this->usedModifiers) { + boneMap = modifier->modify(boneMap).toMap(); + } + + length = boneMap["length"].toFloat(); + radius = boneMap["radius"].toFloat(); + btScalar oldLength = this->getLength(); body->setSize(radius,length); @@ -405,6 +466,21 @@ void Bone::setSize(btScalar radius, btScalar length) void Bone::setEndFixationRadius(btScalar radius) { + + // Calculate the new size + QVariantMap boneMap; + boneMap["length"] = 0; // Don't care + boneMap["radius"] = 0; // Don't care + QVariantMap endFixMap; + endFixMap["radius"] = radius; + boneMap["endFix"] = endFixMap; + + foreach(GenomeModifier* modifier, this->usedModifiers) { + boneMap = modifier->modify(boneMap).toMap(); + } + + radius = boneMap["endFix"].toMap()["radius"].toFloat(); + body->setEndFixationRadius(radius); // adapt children connections diff --git a/src/genecraft/core/entities/body/bone.h b/src/genecraft/core/entities/body/bone.h index 15ae54c..3942c04 100644 --- a/src/genecraft/core/entities/body/bone.h +++ b/src/genecraft/core/entities/body/bone.h @@ -21,6 +21,7 @@ along with Genecraft-Project. If not, see . #define BONE_H #include +#include #include #include "genecraftcoreclasses.h" @@ -28,8 +29,16 @@ along with Genecraft-Project. If not, see . #include "BulletDynamics/ConstraintSolver/btGeneric6DofConstraint.h" #include "bullet/shapes/btbone.h" +#include "genome/genomemodifier.h" + +#include "symmetry.h" +#include "recursion.h" + namespace GeneCraftCore { + class Symmetry; + class Recursion; + class Bone : public QObject { @@ -49,6 +58,7 @@ class Bone : public QObject * @param initTransform the initial position of the muscle */ Bone(btShapesFactory *shapesFactory, btScalar yAxis, btScalar zAxis, btScalar radius, btScalar lenght, btScalar endFixRadius, const btTransform &initTransform); + /** * @brief destruct and free used ressources * @@ -260,6 +270,24 @@ class Bone : public QObject */ void disconnectMotor(int i); + /** + Referent bone + */ + void setRef(Bone* ref) { this->ref = ref; } + Bone* getRef() { return this->ref;} + void addReferee(Bone* referee) { this->referees.prepend(referee); } + QList getReferees() { return this->referees; } + + void setModifiers(QList modifiers) { this->usedModifiers.append(modifiers); qDebug() << "used: " << usedModifiers.size(); } + + /** + Special genome element + */ + void setSymmetry(Symmetry* sym) { this->sym = sym; } + Symmetry* getSymmetry() { return this->sym; } + void setRecursion(Recursion* rec) { this->rec = rec; } + Recursion* getRecursion() { return this->rec; } + protected: // Shape @@ -288,6 +316,14 @@ class Bone : public QObject // Shape factory btShapesFactory* shapesFactory; /**< TODO */ + // Referent bone + Bone* ref; + QList referees; + QList usedModifiers; + + Symmetry* sym; + Recursion* rec; + }; } diff --git a/src/genecraft/core/entities/body/fixation.cpp b/src/genecraft/core/entities/body/fixation.cpp index b102fe3..fe63391 100644 --- a/src/genecraft/core/entities/body/fixation.cpp +++ b/src/genecraft/core/entities/body/fixation.cpp @@ -482,11 +482,4 @@ namespace GeneCraftCore { return true; } - - // ----------- - // -- UTILS -- - // ----------- -// btWorld *Fixation::getWorld() { -// return sphere->getWorld(); -// } } diff --git a/src/genecraft/core/entities/body/recursion.cpp b/src/genecraft/core/entities/body/recursion.cpp new file mode 100644 index 0000000..e9bf195 --- /dev/null +++ b/src/genecraft/core/entities/body/recursion.cpp @@ -0,0 +1,9 @@ +#include "recursion.h" +#include "bone.h" + +namespace GeneCraftCore { + Recursion::Recursion(QObject *parent) : + QObject(parent) + { + } +} diff --git a/src/genecraft/core/entities/body/recursion.h b/src/genecraft/core/entities/body/recursion.h new file mode 100644 index 0000000..d5c1c0e --- /dev/null +++ b/src/genecraft/core/entities/body/recursion.h @@ -0,0 +1,37 @@ +#ifndef RECURSION_H +#define RECURSION_H + +#include +#include + +#include "genome/genomemodifier.h" +#include "btBulletCollisionCommon.h" + +namespace GeneCraftCore { + + class Bone; + + class Recursion : public QObject + { + Q_OBJECT + public: + explicit Recursion(QObject *parent = 0); + + btScalar physScale; + btScalar neuralAlpha; + btScalar neuralDelta; + int depth; + QList tail; + QList childs; + Bone* model; + QList modifiers; + + signals: + + public slots: + + }; + +} + +#endif // RECURSION_H diff --git a/src/genecraft/core/entities/body/symmetry.cpp b/src/genecraft/core/entities/body/symmetry.cpp new file mode 100644 index 0000000..adbd810 --- /dev/null +++ b/src/genecraft/core/entities/body/symmetry.cpp @@ -0,0 +1,10 @@ +#include "symmetry.h" + +namespace GeneCraftCore { + +Symmetry::Symmetry(QObject *parent) : + QObject(parent) +{ +} + +} diff --git a/src/genecraft/core/entities/body/symmetry.h b/src/genecraft/core/entities/body/symmetry.h new file mode 100644 index 0000000..adf43bb --- /dev/null +++ b/src/genecraft/core/entities/body/symmetry.h @@ -0,0 +1,31 @@ +#ifndef SYMMETRY_H +#define SYMMETRY_H + +#include +#include +#include "genome/genomemodifier.h" +#include "btBulletCollisionCommon.h" +#include "body/bone.h" + +namespace GeneCraftCore { + + class Symmetry : public QObject + { + Q_OBJECT + public: + explicit Symmetry(QObject *parent = 0); + + btScalar physSymmetry; + btScalar neuralSymmetry; + Bone* model; + Bone* copy; + QList modifiers; + + signals: + + public slots: + + }; +} + +#endif // SYMMETRY_H diff --git a/src/genecraft/core/entities/families/genericfamily.cpp b/src/genecraft/core/entities/families/genericfamily.cpp index 5504dd9..3e9675c 100644 --- a/src/genecraft/core/entities/families/genericfamily.cpp +++ b/src/genecraft/core/entities/families/genericfamily.cpp @@ -45,42 +45,6 @@ GenericFamily::GenericFamily() { } -Entity *GenericFamily::createEntity(QVariant genotype, - btShapesFactory *shapesFactory, - const btVector3 &initialPosition) -{ - QVariantMap entityMap = genotype.toMap(); - - // Entity & origins - QVariantMap origins = entityMap.value("origins").toMap(); - Entity * entity = new Entity(origins.value("name").toString(), - origins.value("family").toString(), - "generic", - origins.value("generation").toInt()); - // Brain - entity->setBrain(new BrainFunctional(entityMap.value("brain"))); - - // Body - QVariantMap body = entityMap.value("body").toMap(); - if(body.value("shapeType").toString().compare(QString("TreeShape")) == 0) - { - TreeShape* treeShape = new TreeShape(shapesFactory); - - btTransform initTransform; - initTransform.setIdentity(); - initTransform.setOrigin(initialPosition); - - Fixation* root = GenericFamily::createRootFromGenotype(shapesFactory, body.value("shape"), initTransform); - treeShape->setRoot(root); - entity->setShape(treeShape); - GenericFamily::buildFixFromGenotype(shapesFactory, root, root,body.value("shape").toMap().value("rootFix")); - } - - - return entity; -} - - Entity *GenericFamily::createVirginEntity(btShapesFactory *shapesFactory, btScalar rootFixRadius, const btVector3 &initialPosition) @@ -99,114 +63,4 @@ Entity *GenericFamily::createVirginEntity(btShapesFactory *shapesFactory, return entity; } - -Fixation* GenericFamily::createRootFromGenotype(btShapesFactory *shapesFactory, QVariant genotype, btTransform initTransform) { - QVariantMap treeShapeMap = genotype.toMap(); - - // Root fix - QVariantMap rootFixMap = treeShapeMap.value("rootFix").toMap(); - - return new Fixation(shapesFactory, rootFixMap.value("radius").toDouble(), initTransform); - -} - -void GenericFamily::buildFixFromGenotype(btShapesFactory *shapesFactory, Fixation *fix, Fixation* root, QVariant fixGenotype) -{ - - // ------------- - // -- sensors -- - // ------------- - foreach(QVariant sensorData, fixGenotype.toMap()["sensors"].toList()) { - QVariantMap sensorMap = sensorData.toMap(); - switch((SensorType)sensorMap["type"].toInt()) { - case accelerometerSensor: { - fix->addSensor(new AccelerometerSensor(sensorData, fix)); - } - break; - case gyroscopicSensor: { - - fix->addSensor(new GyroscopicSensor(sensorData, fix)); - } - break; - case positionSensor:{ - - fix->addSensor(new PositionSensor(sensorData, root, fix)); - } - break; - case contactSensor:{ - - fix->addSensor(new ContactSensor(sensorData, fix)); - } - break; - case boxSmellSensor:{ - - fix->addSensor(new BoxSmellSensor(sensorData, fix)); - - break; - } - case distanceSensor:{ - - fix->addSensor(new DistanceSensor(sensorData, fix)); - } - break; - } - } - - // -------------- - // -- effector -- - // -------------- - foreach(QVariant effector, fixGenotype.toMap()["effectors"].toList()) { - QVariantMap effectorMap = effector.toMap(); - switch((EffectorType)effectorMap["type"].toInt()) { - - case rotationalMotorEffector: break; - case gripperEffector: { - fix->addEffector(new GripperEffector(effectorMap, fix)); - } - break; - case flyingEffector:{ - fix->addEffector(new FlyingEffector(effectorMap, fix)); - } - break; - } - } - - // ----------- - // -- bones -- - // ----------- - QVariantList bonesVariantList = fixGenotype.toMap().value("bones").toList(); - - foreach(QVariant bone, bonesVariantList) - { - QVariantMap boneMap = bone.toMap(); - - // Radius & lenght - btScalar boneRadius = boneMap.value("radius").toDouble(); - btScalar boneLength = boneMap.value("length").toDouble(); - - btScalar endFixRadius = boneMap.value("endFix").toMap().value("radius").toDouble(); - - // Yaw & Roll (local) - QVariantMap localRotationMap = boneMap.value("localRotation").toMap(); - btScalar yAxisRot = localRotationMap.value("y").toDouble(); - btScalar zAxisRot = localRotationMap.value("z").toDouble(); - - // Limits - btVector3 lowerLimits, upperLimits; - QVariantMap lowerLimitsMap = boneMap.value("lowerLimits").toMap(); - QVariantMap upperLimitsMap = boneMap.value("upperLimits").toMap(); - - lowerLimits.setValue(lowerLimitsMap.value("x").toDouble(), - lowerLimitsMap.value("y").toDouble(), - lowerLimitsMap.value("z").toDouble()); - upperLimits.setValue(upperLimitsMap.value("x").toDouble(), - upperLimitsMap.value("y").toDouble(), - upperLimitsMap.value("z").toDouble()); - - Bone *bone = fix->addBone(yAxisRot,zAxisRot,boneRadius,boneLength,endFixRadius,lowerLimits,upperLimits); - bone->setMotorModifierData(boneMap["muscle"]); - // Add bone recurcively - GenericFamily::buildFixFromGenotype(shapesFactory, bone->getEndFixation(), root, boneMap.value("endFix")); - } -} } diff --git a/src/genecraft/core/entities/families/genericfamily.h b/src/genecraft/core/entities/families/genericfamily.h index c07364f..a4ecc5e 100644 --- a/src/genecraft/core/entities/families/genericfamily.h +++ b/src/genecraft/core/entities/families/genericfamily.h @@ -42,10 +42,6 @@ class GenericFamily GenericFamily(); - // To create an entity with its genome - static Entity *createEntity(QVariant genotype, - btShapesFactory *shapesFactory, - const btVector3 &initialPosition); // To create a virgin entity static Entity *createVirginEntity(btShapesFactory *shapesFactory, @@ -53,10 +49,6 @@ class GenericFamily const btVector3 &initialPosition); - static Fixation* createRootFromGenotype(btShapesFactory *shapesFactory, QVariant genotype, btTransform initTransform); - static void buildFixFromGenotype(btShapesFactory *shapesFactory, Fixation *fix, Fixation* root, QVariant fixGenotype); - - }; } #endif // GENERICFAMILY_H diff --git a/src/genecraft/core/entities/sensors/contactsensor.h b/src/genecraft/core/entities/sensors/contactsensor.h index 58c75c7..4ef05f6 100644 --- a/src/genecraft/core/entities/sensors/contactsensor.h +++ b/src/genecraft/core/entities/sensors/contactsensor.h @@ -70,6 +70,56 @@ class ContactSensor : public Sensor }; +//struct ContactSensorCallback : public btCollisionWorld::ContactResultCallback { + +// //! Constructor, pass whatever context you want to have available when processing contacts +// /*! You may also want to set m_collisionFilterGroup and m_collisionFilterMask +// * (supplied by the superclass) for needsCollision() */ +// ContactSensorCallback(btRigidBody *tgtBody , ContactSensor *context /*, ... */) +// : btCollisionWorld::ContactResultCallback(), body(tgtBody), ctxt(context) { } + +// btRigidBody *body; //!< The body the sensor is monitoring +// ContactSensor *ctxt; //!< External information for contact processing + +// //! If you don't want to consider collisions where the bodies are joined by a constraint, override needsCollision: +// /*! However, if you use a btCollisionObject for #body instead of a btRigidBody, +// * then this is unnecessary—checkCollideWithOverride isn't available */ +// virtual bool needsCollision(btBroadphaseProxy* proxy) const { +// // superclass will check m_collisionFilterGroup and m_collisionFilterMask +//// if(!btCollisionWorld::ContactResultCallback::needsCollision(proxy)) +//// return false; +//// // if passed filters, may also want to avoid contacts between constraints +//// return body.checkCollideWithOverride(static_cast(proxy->m_clientObject)); +// return true; +// } + +// //! Called with each contact for your own processing (e.g. test if contacts fall in within sensor parameters) +// virtual btScalar addSingleResult(btManifoldPoint& cp, +// const btCollisionObject* colObj0,int partId0,int index0, +// const btCollisionObject* colObj1,int partId1,int index1) +// { +// const btCollisionObject *object; + +// btVector3 pt; // will be set to point of collision relative to body +// if(colObj0 == (btCollisionObject *) body) { +// pt = cp.m_localPointA; +// object = colObj0; + +// } else { +// //assert(colObj1==body && "body does not match either collision object"); +// pt = cp.m_localPointB; +// object = colObj1; +// } + +// // do stuff with the collision point +// if(object->isStaticObject()) +// { +// ctxt->collideStaticObject(object,pt); +// } + +// return 0; // not actually sure if return value is used for anything...? +// } +//}; } #endif // CONTACTSENSOR_H diff --git a/src/genecraft/core/factories/base/creaturefactory.cpp b/src/genecraft/core/factories/base/creaturefactory.cpp index 7e56f35..0848d97 100644 --- a/src/genecraft/core/factories/base/creaturefactory.cpp +++ b/src/genecraft/core/factories/base/creaturefactory.cpp @@ -18,6 +18,7 @@ along with Genecraft-Project. If not, see . */ #include "creaturefactory.h" +#include "genome/genomebuilder.h" #include "families/genericfamily.h" #include "entity.h" @@ -48,10 +49,10 @@ namespace GeneCraftCore { // Generic entity if(entityData["type"].toString() == "generic") - return GenericFamily::createEntity(entityData, shapesFactory, position); + return GenomeBuilder::buildEntity(entityData, shapesFactory, position); // Whatever else if(entityData["type"].toString() == "symetric") - return GenericFamily::createEntity(entityData, shapesFactory, position); + return GenomeBuilder::buildEntity(entityData, shapesFactory, position); // Whatever else return NULL; } diff --git a/src/genecraft/core/factories/genome/genomebuilder.cpp b/src/genecraft/core/factories/genome/genomebuilder.cpp new file mode 100644 index 0000000..e770d6f --- /dev/null +++ b/src/genecraft/core/factories/genome/genomebuilder.cpp @@ -0,0 +1,296 @@ +#include "genomebuilder.h" + +#include + +#include "body/bone.h" +#include "body/fixation.h" +#include "body/treeshape.h" + +#include "sensors/sensor.h" +#include "sensors/accelerometersensor.h" +#include "sensors/boxsmellsensor.h" +#include "sensors/contactsensor.h" +#include "sensors/distancesensor.h" +#include "sensors/gyroscopicsensor.h" +#include "sensors/positionsensor.h" +#include "sensors/smellsensor.h" + +#include "effectors/effector.h" +#include "effectors/flyingeffector.h" +#include "effectors/grippereffector.h" +#include "effectors/rotationalmotorseffector.h" + +namespace GeneCraftCore { + + GenomeBuilder::GenomeBuilder(QObject *parent) : + QObject(parent) + { + } + + Entity *GenomeBuilder::buildEntity(QVariant genotype, + btShapesFactory *shapesFactory, + const btVector3 &initialPosition) + { + QVariantMap entityMap = genotype.toMap(); + + // Entity & origins + QVariantMap origins = entityMap.value("origins").toMap(); + Entity * entity = new Entity(origins.value("name").toString(), + origins.value("family").toString(), + "generic", + origins.value("generation").toInt()); + // Brain + entity->setBrain(new BrainFunctional(entityMap.value("brain"))); + + // Body + QVariantMap body = entityMap.value("body").toMap(); + if(body.value("shapeType").toString().compare(QString("TreeShape")) == 0) + { + TreeShape* treeShape = new TreeShape(shapesFactory); + + btTransform initTransform; + initTransform.setIdentity(); + initTransform.setOrigin(initialPosition); + + Fixation* root = GenomeBuilder::buildRoot(shapesFactory, body.value("shape"), initTransform); + treeShape->setRoot(root); + entity->setShape(treeShape); + + QList modifiers; + GenomeBuilder::buildElement(shapesFactory, root, modifiers, body.value("shape").toMap().value("rootFix"), NULL); + } + + + return entity; + } + + + Fixation* GenomeBuilder::buildElement(btShapesFactory* shapesFactory, Fixation *parent, + QList modifiers, QVariant genome, Bone* ref) { + + QVariantMap map = genome.toMap(); + + // If it's not a bone nor a fixation + // It should be a symmetry or a recursion + if(map.contains("type")) { + QString type = map["type"].toString(); + if(type == "symmetry") { + // Create the symmetry modifier + GenomeModifier* modifier = new GenomeModifier(); + modifier->setNeuralSymmetry(map["neuralSymmetry"].toFloat()); + modifier->setPhysicalSymmetry(map["physicalSymmetry"].toFloat()); + QList newModifiers; + newModifiers.append(modifiers); + newModifiers.append(modifier); + + // The symmetry element, for further modification / serialisation + Symmetry* sym = new Symmetry(); + sym->physSymmetry = map["physicalSymmetry"].toFloat(); + sym->neuralSymmetry = map["neuralSymmetry"].toFloat(); + sym->modifiers.append(modifier); + + // Build the original child and the symmetric one, and we arbitrary return the new one + Fixation* refFix = GenomeBuilder::buildElement(shapesFactory, parent, modifiers, map["element"], ref); + Fixation* last = GenomeBuilder::buildElement(shapesFactory, parent, newModifiers, map["element"], refFix->getParentBone()); + + sym->model = refFix->getParentBone(); + sym->copy = last->getParentBone(); + refFix->getParentBone()->setSymmetry(sym); + return last; + + } else if (type == "recursive") { + // Create the recursion modifier + GenomeModifier* modifier = new GenomeModifier(); + modifier->setNeuralRotation(map["neuralAlpha"].toFloat(), map["neuralDelta"].toFloat()); + modifier->setPhysicalScale(map["physicalScale"].toFloat()); + QList newModifiers; + newModifiers.append(modifiers); + + // The recursion element, for further modification / serialisation + Recursion* rec = new Recursion(); + rec->depth = map["depth"].toInt(); + rec->physScale = map["physicalScale"].toFloat(); + rec->neuralAlpha = map["neuralAlpha"].toFloat(); + rec->neuralDelta = map["neuralDelta"].toFloat(); + rec->modifiers.append(modifier); + + // Construct the n-th recursions of the element + int nb = map["depth"].toInt(); + Fixation* refFix = parent = GenomeBuilder::buildElement(shapesFactory, parent, newModifiers, map["element"], ref); + refFix->getParentBone()->setRecursion(rec); + rec->model = refFix->getParentBone(); + for(int i = 0; i < nb; i++) { + newModifiers.append(modifier); + parent = GenomeBuilder::buildElement(shapesFactory, parent, newModifiers, map["element"], refFix->getParentBone()); + rec->childs << parent->getParentBone(); + } + + // Create the tail and add it to the rec + Bone* tailRef = NULL; + if(ref && ref->getRecursion()) { + tailRef = ref->getRecursion()->tail.first(); + } + Fixation* last = GenomeBuilder::buildElement(shapesFactory, parent, modifiers, map["tail"], tailRef); + rec->tail.append(last->getParentBone()); + return last; + } else { + qDebug() << "GenomeBuilder: Could not recognize the type !"; + } + } + + // So it's a fix/bones + if(map.contains("bones")) // Fixation + return GenomeBuilder::buildFix(shapesFactory, parent, modifiers, genome, ref); + else if(map.contains("endFix")) // Bone + return GenomeBuilder::buildBone(shapesFactory, parent, modifiers, genome, ref); + } + + Fixation* GenomeBuilder::buildBone(btShapesFactory* shapesFactory, Fixation *parent, + QList modifiers, QVariant boneGenome, Bone* ref) { + + // We apply the actual modifiers to this genome element + foreach(GenomeModifier* modifier, modifiers) + boneGenome = modifier->modify(boneGenome); + + QVariantMap boneMap = boneGenome.toMap(); + + // Radius & lenght + btScalar boneRadius = boneMap.value("radius").toDouble(); + btScalar boneLength = boneMap.value("length").toDouble(); + + btScalar endFixRadius = boneMap.value("endFix").toMap().value("radius").toDouble(); + + // Yaw & Roll (local) + QVariantMap localRotationMap = boneMap.value("localRotation").toMap(); + btScalar yAxisRot = localRotationMap.value("y").toDouble(); + btScalar zAxisRot = localRotationMap.value("z").toDouble(); + + // Limits + btVector3 lowerLimits, upperLimits; + QVariantMap lowerLimitsMap = boneMap.value("lowerLimits").toMap(); + QVariantMap upperLimitsMap = boneMap.value("upperLimits").toMap(); + + lowerLimits.setValue(lowerLimitsMap.value("x").toDouble(), + lowerLimitsMap.value("y").toDouble(), + lowerLimitsMap.value("z").toDouble()); + upperLimits.setValue(upperLimitsMap.value("x").toDouble(), + upperLimitsMap.value("y").toDouble(), + upperLimitsMap.value("z").toDouble()); + + Bone *bone = parent->addBone(yAxisRot,zAxisRot,boneRadius,boneLength,endFixRadius,lowerLimits,upperLimits); + bone->setMotorModifierData(boneMap["muscle"]); + + + // Get the correct ref + while(ref && ref->getRef()) { + ref = ref->getRef(); + } + // Set a back replication + bone->setRef(ref); + if(ref) + ref->addReferee(bone); + // Set the modifier in case of modification + bone->setModifiers(modifiers); + + + // Add bone recurcively + return GenomeBuilder::buildFix(shapesFactory, bone->getEndFixation(), modifiers, boneMap.value("endFix"), ref); + } + + Fixation* GenomeBuilder::buildFix( btShapesFactory* shapesFactory, Fixation *fix, + QList modifiers, QVariant fixGenotype, Bone* ref) { + + // We apply the actual modifiers to this genome element + foreach(GenomeModifier* modifier, modifiers) + fixGenotype = modifier->modify(fixGenotype); + + // ------------- + // -- sensors -- + // ------------- + foreach(QVariant sensorData, fixGenotype.toMap()["sensors"].toList()) { + QVariantMap sensorMap = sensorData.toMap(); + switch((SensorType)sensorMap["type"].toInt()) { + case accelerometerSensor: { + fix->addSensor(new AccelerometerSensor(sensorData, fix)); + } + break; + case gyroscopicSensor: { + + fix->addSensor(new GyroscopicSensor(sensorData, fix)); + } + break; + case positionSensor:{ + Fixation* referent = fix; + if(fix->getParentBone() && fix->getParentBone()->getParentFixation()) { + referent = fix->getParentBone()->getParentFixation(); + } + fix->addSensor(new PositionSensor(sensorData, fix->getEntity()->getShape()->getRoot(), fix)); + } + break; + case contactSensor:{ + + fix->addSensor(new ContactSensor(sensorData, fix)); + } + break; + case boxSmellSensor:{ + + fix->addSensor(new BoxSmellSensor(sensorData, fix)); + + break; + } + case distanceSensor:{ + + fix->addSensor(new DistanceSensor(sensorData, fix)); + } + break; + } + } + + // -------------- + // -- effector -- + // -------------- + foreach(QVariant effector, fixGenotype.toMap()["effectors"].toList()) { + QVariantMap effectorMap = effector.toMap(); + switch((EffectorType)effectorMap["type"].toInt()) { + + case rotationalMotorEffector: break; + case gripperEffector: { + fix->addEffector(new GripperEffector(effectorMap, fix)); + } + break; + case flyingEffector:{ + fix->addEffector(new FlyingEffector(effectorMap, fix)); + } + break; + } + } + + // ----------- + // -- bones -- + // ----------- + QVariantList bonesVariantList = fixGenotype.toMap().value("bones").toList(); + + Bone* correctRef = NULL; + int i = 0; + foreach(QVariant bone, bonesVariantList) + { + if(ref) + correctRef = ref->getEndFixation()->getBones()[i]; + + GenomeBuilder::buildElement(shapesFactory, fix, modifiers, bone, correctRef); + i++; + } + + return fix; + } + + Fixation* GenomeBuilder::buildRoot(btShapesFactory* shapesFactory, QVariant genotype, + btTransform initPos) { + // Get the data + QVariantMap treeShapeMap = genotype.toMap(); + QVariantMap rootFixMap = treeShapeMap.value("rootFix").toMap(); + // Construct the fixation + return new Fixation(shapesFactory, rootFixMap.value("radius").toDouble(), initPos); + } + +} diff --git a/src/genecraft/core/factories/genome/genomebuilder.h b/src/genecraft/core/factories/genome/genomebuilder.h new file mode 100644 index 0000000..6f2c341 --- /dev/null +++ b/src/genecraft/core/factories/genome/genomebuilder.h @@ -0,0 +1,45 @@ +#ifndef GENOMEBUILDER_H +#define GENOMEBUILDER_H + +#include +#include +#include +#include + +#include "entity.h" + +#include "genomemodifier.h" + +namespace GeneCraftCore { + +class GenomeBuilder : public QObject +{ + Q_OBJECT +public: + explicit GenomeBuilder(QObject *parent = 0); + + // To create an entity with its genome + static Entity* buildEntity(QVariant genotype, + btShapesFactory *shapesFactory, + const btVector3 &initialPosition); + + // Create the root fixation + //static Fixation* createRootFromGenotype(btShapesFactory *shapesFactory, QVariant genotype, btTransform initTransform); + + // Build a fixation from the genome + //static void buildFixFromGenotype(btShapesFactory *shapesFactory, Fixation *fix, Fixation* root, QVariant fixGenotype); + + static Fixation* buildBone(btShapesFactory* shapesFactory, Fixation *parent, QList modifier, QVariant genome, Bone* ref); + static Fixation* buildFix(btShapesFactory* shapesFactory, Fixation *fix, QList modifier, QVariant genome, Bone* ref); + static Fixation* buildElement(btShapesFactory* shapesFactory, Fixation *parent, QList modifier, QVariant genome, Bone* ref); + static Fixation* buildRoot(btShapesFactory* shapesFactory, QVariant genotype, btTransform initPos); +signals: + +public slots: + +}; + +} + +#endif // GENOMEBUILDER_H + diff --git a/src/genecraft/core/factories/genome/genomemodifier.cpp b/src/genecraft/core/factories/genome/genomemodifier.cpp new file mode 100644 index 0000000..5e086b7 --- /dev/null +++ b/src/genecraft/core/factories/genome/genomemodifier.cpp @@ -0,0 +1,116 @@ +#include "genomemodifier.h" +#include + +namespace GeneCraftCore { + + GenomeModifier::GenomeModifier(QObject *parent) : + QObject(parent) + { + isPhysSym = false; + isPhysScale = false; + isNeuralSym = false; + isNeuralRot = false; + + physSym = 0.; + physScale = 1.; + neuralSym = 0.; + neuralAlpha = 0.; + neuralDelta = 0.; + + } + + // Set the modifications parameters + void GenomeModifier::setPhysicalSymmetry(btScalar alpha) { + isPhysSym = true; + physSym = alpha; + } + + void GenomeModifier::setPhysicalScale (btScalar scale) { + isPhysScale = true; + physScale = scale; + } + + void GenomeModifier::setNeuralSymmetry (btScalar alpha) { + isNeuralSym = true; + neuralSym = alpha; + } + + void GenomeModifier::setNeuralRotation (btScalar alpha, btScalar delta) { + isNeuralRot = true; + neuralAlpha = alpha; + neuralDelta = delta; + } + + // The modification will be applied to the bone element and all bone childs + QVariant GenomeModifier::modify(QVariant element) { + QVariantMap map = element.toMap(); + QString type = map["type"].toString(); + if(map.contains("endFix")) { // Bone + // Modify physical parameters + if(isPhysSym) + applyBoneSymmetry(map); + + if(isPhysScale) + applyBoneScale(map); + + } else if(map.contains("bones")) { // Fixation + + // Modify physical parameters + if(isPhysSym) + applyFixSymmetry(map); + + if(isPhysScale) + applyFixScale(map); + } + + return map; + } + + + void GenomeModifier::applyBoneSymmetry(QVariantMap& element) { + + // moving X by sym + // inversing y + QVariantMap rot = element["localRotation"].toMap(); + rot["z"] = rot["z"].toFloat() + physSym; + rot["y"] = -rot["y"].toFloat(); + element["localRotation"] = rot; + + // inversiong some freedom degree to keep coherence + QVariantMap lo = element["lowerLimits"].toMap(); + QVariantMap hi = element["upperLimits"].toMap(); + btScalar loX, loY; + loX = lo["x"].toFloat(); + loY = lo["y"].toFloat(); + lo["x"] = -hi["x"].toFloat(); + hi["x"] = -loX; + lo["y"] = -hi["y"].toFloat(); + hi["y"] = -loY; + element["lowerLimits"] = lo; + element["upperLimits"] = hi; + + } + + void GenomeModifier::applyBoneScale (QVariantMap& element) { + // Reduce length and radius + element["length"] = element["length"].toFloat()*physScale; + element["radius"] = element["radius"].toFloat()*physScale; + + QVariantMap endFix = element["endFix"].toMap(); + this->applyFixScale(endFix); + + element["endFix"] = endFix; + + } + + + void GenomeModifier::applyFixSymmetry(QVariantMap& element) { + // Nothing to do... + } + + void GenomeModifier::applyFixScale(QVariantMap& element) { + // Radius + element["radius"] = element["radius"].toFloat()*physScale; + } + +} diff --git a/src/genecraft/core/factories/genome/genomemodifier.h b/src/genecraft/core/factories/genome/genomemodifier.h new file mode 100644 index 0000000..41965e5 --- /dev/null +++ b/src/genecraft/core/factories/genome/genomemodifier.h @@ -0,0 +1,52 @@ +#ifndef GENOMEMODIFIER_H +#define GENOMEMODIFIER_H + +#include +#include +#include +#include "btBulletCollisionCommon.h" + +namespace GeneCraftCore { + +class GenomeModifier : public QObject +{ + Q_OBJECT +public: + explicit GenomeModifier(QObject *parent = 0); + + // Set the modifications parameters + void setPhysicalSymmetry(btScalar alpha); + void setPhysicalScale (btScalar scale); + void setNeuralSymmetry (btScalar alpha); + void setNeuralRotation (btScalar alpha, btScalar delta); + + // The modification will be applied to the bone element and all bone childs + QVariant modify(QVariant element); + + void applyBoneSymmetry(QVariantMap& element); + void applyBoneScale (QVariantMap& element); + + void applyFixSymmetry(QVariantMap& element); + void applyFixScale(QVariantMap& element); + + +protected: + bool isPhysSym; + bool isPhysScale; + bool isNeuralSym; + bool isNeuralRot; + + btScalar physSym; + btScalar physScale; + btScalar neuralSym; + btScalar neuralAlpha; + btScalar neuralDelta; + +signals: + +public slots: + +}; + +} +#endif // GENOMEMODIFIER_H diff --git a/src/genecraft/core/ui/widgets/entities/bonepropertiescontroller.cpp b/src/genecraft/core/ui/widgets/entities/bonepropertiescontroller.cpp index 6e46b24..b72879b 100644 --- a/src/genecraft/core/ui/widgets/entities/bonepropertiescontroller.cpp +++ b/src/genecraft/core/ui/widgets/entities/bonepropertiescontroller.cpp @@ -57,7 +57,7 @@ btScalar roundPrecision(btScalar n, int precision = 2) } BonePropertiesController::BonePropertiesController(QWidget *parent) : - QWidget(parent), ui(new Ui::BonePropertiesController), bone(0) + GraphicalWidget(parent), ui(new Ui::BonePropertiesController), bone(0) { ui->setupUi(this); @@ -132,8 +132,8 @@ void BonePropertiesController::entityDeleted(Entity *) { setBone(NULL); } -void BonePropertiesController::update() { - if(this->bone != NULL) { +void BonePropertiesController::step() { + /*if(this->bone != NULL && this->bone->getRotationalMotorsEffector() != NULL) { // X BrainOutMotor* muscle = this->bone->getRotationalMotorsEffector()->getBrainOutputs(0); if(muscle) { @@ -161,7 +161,7 @@ void BonePropertiesController::update() { this->ui->lblContractZ->setText(QString::number(0)); this->ui->lblExpandZ->setText(QString::number(0)); } - } + }*/ } void BonePropertiesController::setOutFrom() @@ -202,6 +202,34 @@ void BonePropertiesController::changeRadiusFromSlider(int value) void BonePropertiesController::deleteBone() { + // Symmetric bone ? + + // Recursiv bone ? + if(bone->getSymmetry()) { + Symmetry* sym = bone->getSymmetry(); + // Need to delete the copy + if(sym->copy->getParentFixation() != NULL) + sym->copy->getParentFixation()->removeBone(sym->copy); + + sym->copy->remove(); + emit sBoneDeleted(sym->copy); // will set bone to NULL + delete sym->copy; + + } else if(bone->getRecursion()) { + // Delete as usual, that'll delete child too + } else { // Delete copy also + // Delete the same on the other side + foreach(Bone* b, bone->getReferees()) { + if(b->getParentFixation() != NULL) + b->getParentFixation()->removeBone(bone); + + b->remove(); + emit sBoneDeleted(b); // will set bone to NULL + delete b; + } + } + + if(bone->getParentFixation() != NULL) bone->getParentFixation()->removeBone(bone); @@ -213,6 +241,41 @@ void BonePropertiesController::deleteBone() void BonePropertiesController::deleteBoneAndAttachChildrenToParent() { + if(bone->getSymmetry()) { + // Delete the copy as-well + Bone* b = bone->getSymmetry()->copy; + + if(b->getParentFixation() != NULL) + b->getParentFixation()->removeBone(b); + + b->remove(); + emit sBoneDeleted(b); // will set bone to NULL + delete b; + + } else if(bone->getRecursion()) { + // Delete all child and child-tree + foreach(Bone* b, bone->getRecursion()->childs) { + + if(b->getParentFixation() != NULL) + b->getParentFixation()->removeBone(b); + + b->remove(); + emit sBoneDeleted(b); // will set bone to NULL + delete b; + } + } else { + // Delete the same on the other side + foreach(Bone* b, bone->getReferees()) { + if(b->getParentFixation() != NULL) + b->getParentFixation()->removeBone(b); + + b->removeOnly(); + emit sBoneDeleted(b); // will set bone to NULL + delete b; + } + } + + if(bone->getParentFixation() != NULL) bone->getParentFixation()->removeBone(bone); @@ -310,10 +373,17 @@ void BonePropertiesController::saveChanges() void BonePropertiesController::setBone(Bone * bone) { - this->bone = bone; + if(bone) { + // Try to get the ref + while(bone->getRef()) { + bone = bone->getRef(); + } + + this->bone = bone; + this->setEnabled(true); // Bone outputs diff --git a/src/genecraft/core/ui/widgets/entities/bonepropertiescontroller.h b/src/genecraft/core/ui/widgets/entities/bonepropertiescontroller.h index b001ab9..28d3d1a 100644 --- a/src/genecraft/core/ui/widgets/entities/bonepropertiescontroller.h +++ b/src/genecraft/core/ui/widgets/entities/bonepropertiescontroller.h @@ -25,6 +25,7 @@ along with Genecraft-Project. If not, see . #include "genecraftcoreclasses.h" #include "sensors/sensor.h" #include "BulletDynamics/Dynamics/btRigidBody.h" +#include "widgets/graphicalwidget.h" using namespace GeneCraftCore; @@ -32,7 +33,7 @@ namespace Ui { class BonePropertiesController; } -class BonePropertiesController : public QWidget +class BonePropertiesController : public GraphicalWidget { Q_OBJECT @@ -40,6 +41,7 @@ class BonePropertiesController : public QWidget explicit BonePropertiesController(QWidget *parent = 0); ~BonePropertiesController(); void connectToInspectorInputManager(InspectorsInputManager * iim); + virtual void step(); signals: @@ -51,7 +53,6 @@ public slots: void setBone(Bone * bone); void boneDeleted(Bone *bone); void entityDeleted(Entity *entity); - void update(); private: Ui::BonePropertiesController *ui; diff --git a/src/genecraft/core/ui/widgets/entities/brainpropertiescontroller.cpp b/src/genecraft/core/ui/widgets/entities/brainpropertiescontroller.cpp index cf71862..055b106 100644 --- a/src/genecraft/core/ui/widgets/entities/brainpropertiescontroller.cpp +++ b/src/genecraft/core/ui/widgets/entities/brainpropertiescontroller.cpp @@ -180,20 +180,8 @@ void BrainPropertiesController::selectSensorFixation() void BrainPropertiesController::setBrainFrequency() { if(entity){ - entity->getBrain()->setFrequency(ui->sBrainFrequency->value()); ui->lBrainFrequency->setText(QString::number(entity->getBrain()->getFrequency())); - - //int size = pow(2,ui->cbBrainSize->currentIndex() + 1); - //int size = ui->sBrainPluggridSize->value(); - //ui->lBrainPluggridSize->setText(QString::number(ui->sBrainPluggridSize->value())); - //entity->getBrain()->getPlugGrid()->setSize(size); - - // update brain in inspectors (important to refresh neurons (QGraphicsRectItem)) - //this->brainViz->setBrain(entity->getBrain()); - //this->brainDezViz->setBrain(entity->getBrain()); - - //emit sEntityUpdated(entity); } } diff --git a/src/genecraft/core/ui/widgets/entities/statisticspropertiescontroller.cpp b/src/genecraft/core/ui/widgets/entities/statisticspropertiescontroller.cpp index 2477546..f4c1356 100644 --- a/src/genecraft/core/ui/widgets/entities/statisticspropertiescontroller.cpp +++ b/src/genecraft/core/ui/widgets/entities/statisticspropertiescontroller.cpp @@ -49,7 +49,7 @@ StatisticsPropertiesController::StatisticsPropertiesController(QWidget *parent) setEnabled(false); - fitness = new FitnessPlot(this); + fitness = new FitnessPlot(parent); ui->tab_2->layout()->addWidget(fitness); } diff --git a/src/genecraft/core/ui/widgets/graphicalwidget.cpp b/src/genecraft/core/ui/widgets/graphicalwidget.cpp new file mode 100644 index 0000000..ebd932b --- /dev/null +++ b/src/genecraft/core/ui/widgets/graphicalwidget.cpp @@ -0,0 +1,8 @@ +#include "graphicalwidget.h" + +namespace GeneCraftCore { +GraphicalWidget::GraphicalWidget(QWidget *parent) : + QWidget(parent) +{ +} +} diff --git a/src/genecraft/core/ui/widgets/graphicalwidget.h b/src/genecraft/core/ui/widgets/graphicalwidget.h new file mode 100644 index 0000000..6453d33 --- /dev/null +++ b/src/genecraft/core/ui/widgets/graphicalwidget.h @@ -0,0 +1,20 @@ +#ifndef GRAPHICALWIDGET_H +#define GRAPHICALWIDGET_H + +#include + +namespace GeneCraftCore { +class GraphicalWidget : public QWidget +{ + Q_OBJECT +public: + explicit GraphicalWidget(QWidget *parent = 0); + + virtual void step() = 0; +signals: + +public slots: + +}; +} +#endif // GRAPHICALWIDGET_H diff --git a/src/genecraft/core/utils/tools.h b/src/genecraft/core/utils/tools.h index 6350813..8fa8bd5 100644 --- a/src/genecraft/core/utils/tools.h +++ b/src/genecraft/core/utils/tools.h @@ -42,6 +42,10 @@ class Tools // Used to remove not empty directory (recursively delete) static bool removeDir(QString dirPath); + + static int sign(int v) { + return v > 0 ? 1 : (v < 0 ? -1 : 0); + } }; } diff --git a/src/genecraft/core/world/base/scene.cpp b/src/genecraft/core/world/base/scene.cpp index 0c9398f..16a8bda 100644 --- a/src/genecraft/core/world/base/scene.cpp +++ b/src/genecraft/core/world/base/scene.cpp @@ -66,7 +66,7 @@ namespace GeneCraftCore { QVariantList staticShapesList = data.value("shapes").toList(); - //floor["type"] = "randomBoxes"; + floor["type"] = "randomBoxes"; // Add the entry to the terrain engine terrainEngine->setShapesFactory(world->getShapesFactory()); terrainData = terrainEngine->addTerrain(floor); diff --git a/src/genecraft/core/world/bulletogre/btoscene.cpp b/src/genecraft/core/world/bulletogre/btoscene.cpp index 3d94001..fb25a48 100644 --- a/src/genecraft/core/world/bulletogre/btoscene.cpp +++ b/src/genecraft/core/world/bulletogre/btoscene.cpp @@ -85,7 +85,6 @@ namespace GeneCraftCore { // flatland if(floor["type"].toString() == "flatland") { - qDebug() << "first"; /*mGlobals = OGRE_NEW Ogre::TerrainGlobalOptions(); mGlobals->setMaxPixelError(0); diff --git a/src/genecraft_core.pri b/src/genecraft_core.pri index 275c589..118ba88 100644 --- a/src/genecraft_core.pri +++ b/src/genecraft_core.pri @@ -109,7 +109,11 @@ SOURCES += \ genecraft/core/experiment/resultsmanager.cpp \ genecraft/core/utils/tools.cpp \ genecraft/core/engines/terrain/terrain.cpp \ - genecraft/core/entities/effectors/brainoutmotor.cpp + genecraft/core/entities/effectors/brainoutmotor.cpp \ + genecraft/core/entities/body/symmetry.cpp \ + genecraft/core/entities/body/recursion.cpp \ + genecraft/core/factories/genome/genomemodifier.cpp \ + genecraft/core/factories/genome/genomebuilder.cpp HEADERS += \ genecraft/core/engines/engine.h \ @@ -170,9 +174,17 @@ HEADERS += \ genecraft/core/experiment/resultsmanager.h \ genecraft/core/utils/tools.h \ genecraft/core/engines/terrain/terrain.h \ - genecraft/core/entities/effectors/brainoutmotor.h + genecraft/core/entities/effectors/brainoutmotor.h \ + genecraft/core/entities/body/symmetry.h \ + genecraft/core/entities/body/recursion.h \ + genecraft/core/factories/genome/genomemodifier.h \ + genecraft/core/factories/genome/genomebuilder.h RESOURCES += \ genecraft/core/ressources/core.qrc + + + + diff --git a/src/genecraft_ui.pri b/src/genecraft_ui.pri index 5e1030e..09aca32 100644 --- a/src/genecraft_ui.pri +++ b/src/genecraft_ui.pri @@ -42,7 +42,8 @@ SOURCES += \ genecraft/core/ui/widgets/experiments/conversionctrl.cpp \ genecraft/core/ui/widgets/plot/fitnessplot.cpp \ genecraft/core/ui/widgets/experiments/floordialog.cpp \ - genecraft/core/utils/uitools.cpp + genecraft/core/utils/uitools.cpp \ + genecraft/core/ui/widgets/graphicalwidget.cpp HEADERS += \ genecraft/core/ui/widgets/experiments/structuralmutationcontroller.h \ @@ -67,7 +68,8 @@ HEADERS += \ genecraft/core/ui/widgets/experiments/conversionctrl.h \ genecraft/core/ui/widgets/plot/fitnessplot.h \ genecraft/core/ui/widgets/experiments/floordialog.h \ - genecraft/core/utils/uitools.h + genecraft/core/utils/uitools.h \ + genecraft/core/ui/widgets/graphicalwidget.h FORMS += \ genecraft/core/ui/widgets/entities/generic6dofconstraintcontroller.ui \ @@ -90,3 +92,5 @@ FORMS += \ RESOURCES += \ genecraft/core/ressources/ressources.qrc + +