MCPcopy Create free account
hub / github.com/chrxh/alien / createCellDescription

Method createCellDescription

source/EngineImpl/DescriptionConverter.cpp:363–520  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

361}
362
363CellDescription DescriptionConverter::createCellDescription(DataTO const& dataTO, int cellIndex) const
364{
365 CellDescription result;
366
367 auto const& cellTO = dataTO.cells[cellIndex];
368 result.id = cellTO.id;
369 result.pos = RealVector2D(cellTO.pos.x, cellTO.pos.y);
370 result.vel = RealVector2D(cellTO.vel.x, cellTO.vel.y);
371 result.energy = cellTO.energy;
372 result.stiffness = cellTO.stiffness;
373 result.maxConnections = cellTO.maxConnections;
374 std::vector<ConnectionDescription> connections;
375 for (int i = 0; i < cellTO.numConnections; ++i) {
376 auto const& connectionTO = cellTO.connections[i];
377 ConnectionDescription connection;
378 if (connectionTO.cellIndex != -1) {
379 connection.cellId = dataTO.cells[connectionTO.cellIndex].id;
380 } else {
381 connection.cellId = 0;
382 }
383 connection.distance = connectionTO.distance;
384 connection.angleFromPrevious = connectionTO.angleFromPrevious;
385 connections.emplace_back(connection);
386 }
387 result.connections = connections;
388 result.livingState = cellTO.livingState;
389 result.creatureId = cellTO.creatureId;
390 result.mutationId = cellTO.mutationId;
391 result.ancestorMutationId = cellTO.ancestorMutationId;
392 result.inputExecutionOrderNumber = cellTO.inputExecutionOrderNumber >= 0 ? std::make_optional(cellTO.inputExecutionOrderNumber) : std::nullopt;
393 result.outputBlocked = cellTO.outputBlocked;
394 result.executionOrderNumber = cellTO.executionOrderNumber;
395 result.barrier = cellTO.barrier;
396 result.age = cellTO.age;
397 result.color = cellTO.color;
398 result.genomeComplexity = cellTO.genomeComplexity;
399 result.detectedByCreatureId = cellTO.detectedByCreatureId;
400 result.cellFunctionUsed = cellTO.cellFunctionUsed;
401
402 auto const& metadataTO = cellTO.metadata;
403 auto metadata = CellMetadataDescription();
404 if (metadataTO.nameSize > 0) {
405 auto const name = std::string(reinterpret_cast<char*>(&dataTO.auxiliaryData[metadataTO.nameDataIndex]), metadataTO.nameSize);
406 metadata.setName(name);
407 }
408 if (metadataTO.descriptionSize > 0) {
409 auto const description =
410 std::string(reinterpret_cast<char*>(&dataTO.auxiliaryData[metadataTO.descriptionDataIndex]), metadataTO.descriptionSize);
411 metadata.setDescription(description);
412 }
413 result.metadata = metadata;
414
415 switch (cellTO.cellFunction) {
416 case CellFunction_Neuron: {
417 NeuronDescription neuron;
418 std::vector<float> weigthsAndBias;
419 convert(dataTO, sizeof(float) * MAX_CHANNELS * (MAX_CHANNELS + 1), cellTO.cellFunctionData.neuron.weightsAndBiasesDataIndex, weigthsAndBias);
420 std::tie(neuron.weights, neuron.biases) = splitWeightsAndBias(weigthsAndBias);

Callers

nothing calls this directly

Calls 4

RealVector2DClass · 0.85
splitWeightsAndBiasFunction · 0.85
convertFunction · 0.70

Tested by

no test coverage detected