Exemplo n.º 1
0
float TableDefinition::getValue(float index)
{
	if (!_parsed) parseDefinition();

	// Don't bother if we don't have any values to look up
	if (_values.empty())
	{
		return 0.0f;
	}

	if (_values.size() == 1)
	{
		return _values[0];
	}

	if (_clamp)
	{
		if (index > 1.0f) 
		{
			index = 1.0f - 1.0f / _values.size();
		}
		else if (index < 0.0f) 
		{
			index = 0.0f;
		}

		// Map the index to the [0..N-1] interval
		index *= _values.size() - 1;
	}
	else
	{
		// Only take the fractional part of the index
		index = std::fmod(index, 1.0f);

		// Map the index to the [0..N] interval
		index *= _values.size();
	}

	// If snap is active, round the values to the nearest integer
	if (_snap)
	{
		index = std::floor(index + 0.5f);

		return _values[static_cast<std::size_t>(index) % _values.size()];
	}
	else
	{
		// No snapping, pick the interpolation values
		std::size_t leftIdx = static_cast<std::size_t>(std::floor(index)) % _values.size();
		std::size_t rightIdx = (leftIdx + 1) % _values.size();

		float fraction = index - leftIdx;

		return (1-fraction)*_values[leftIdx] + fraction*_values[rightIdx];
	}
}
Exemplo n.º 2
0
int FlatteningConverter::addDefinitions(JSONArray *defs, int pack) {
//  if (pack == -1) {
//    pack = packs.length();
//    packs.append(QList<BlockInfo*>());
//  }
  int len = defs->length();
  for (int i = 0; i < len; i++)
    parseDefinition(dynamic_cast<JSONObject *>(defs->at(i)), NULL, pack);
  return pack;
}
Exemplo n.º 3
0
int BlockIdentifier::addDefinitions(JSONArray *defs, int pack) {
  if (pack == -1) {
    pack = packs.length();
    packs.append(QList<BlockInfo*>());
  }
  int len = defs->length();
  for (int i = 0; i < len; i++)
    parseDefinition(dynamic_cast<JSONObject *>(defs->at(i)), NULL, pack);
  // clear cache
  clearCache();
  return pack;
}
Exemplo n.º 4
0
std::unique_ptr<ParsedFile> parseFileSyntax(const FileForParsing& ffp) {
  auto file = std::unique_ptr<ParsedFile>(new ParsedFile());
  Lexer lexer(ffp);
  while(lexer.hasCurrentToken()) {
    if(lexer.currType()==STATEMENT_END) {
      lexer.advance(); //Eat ';'
      continue; //Extra semicolons are ok
    }
    bool pub = lexer.currType()==PUB;
    if(pub)
      lexer.advance();
    unique_ptr<Definition> definition = parseDefinition(lexer, pub);
    if(definition) { //A nice definition was returned, and has eaten it's own semicolon
      definition->printSignature();
      file->m_definitions.push_back(std::move(definition));
    }
    else if(lexer.hasCurrentToken()) //Error occurred, but already printed
      skipUntilNewDefinition(lexer);
  }
  terminateIfErrors();
  return file;
}
Exemplo n.º 5
0
void CMakeTool::parseFunctionDetailsOutput(const QString &output)
{
    QSet<QString> functionSet;
    functionSet.fromList(m_functions);

    bool expectDefinition = false;
    QString currentDefinition;

    const QStringList lines = output.split('\n');
    for (int i = 0; i < lines.count(); ++i) {
        const QString line = lines.at(i);

        if (line == "::") {
            expectDefinition = true;
            continue;
        }

        if (expectDefinition) {
            if (!line.startsWith(' ') && !line.isEmpty()) {
                expectDefinition = false;
                QStringList words = parseDefinition(currentDefinition);
                if (!words.isEmpty()) {
                    const QString command = words.takeFirst();
                    if (functionSet.contains(command)) {
                        QStringList tmp = words + m_functionArgs[command];
                        Utils::sort(tmp);
                        m_functionArgs[command] = Utils::filteredUnique(tmp);
                    }
                }
                if (!words.isEmpty() && functionSet.contains(words.at(0)))
                    m_functionArgs[words.at(0)];
                currentDefinition.clear();
            } else {
                currentDefinition.append(line.trimmed() + ' ');
            }
        }
    }
}
Exemplo n.º 6
0
void FlatteningConverter::parseDefinition(
        JSONObject *b,
        int *parentID,
        int pack) {

  // get the ancient block ID
  int bid, data(0);
  if (parentID == NULL) {
    bid = b->at("id")->asNumber();
  } else {
    bid = *parentID;
    data = b->at("data")->asNumber();
    bid |= data << 8;
  }

  // try to translate old block name into new flatname
  QString flatname;
  if (b->has("name")) {
    flatname = "minecraft:" + b->at("name")->asString().toLower().replace(" ", "_");
  } else if (parentID != NULL) {
    flatname = palette[*parentID].name;
  } else {
    flatname = "Unknown";
  }

  // or use provided flatname instead
  if (b->has("flatname"))
    flatname = b->at("flatname")->asString();

  palette[bid].name = flatname;
  palette[bid].hid  = qHash(palette[bid].name);
  if ((parentID == NULL) && (data == 0)) {
    // spread main block type for data == 0
    for (int d=1; d<16; d++) {
      int sid = bid | (d<<8);
      palette[sid].name = flatname;
      palette[sid].hid  = palette[bid].hid;
    }
  }
  //  packs[pack].append(block);

  // get optional mask value (or guess default)
  int mask = 0;
  if (b->has("mask")) {
    mask = b->at("mask")->asNumber();
  } else if (b->has("variants")) {
    mask = 0x0f;
  }

  // recursive parsing of variants (with data)
  if (b->has("variants")) {
    JSONArray *variants = dynamic_cast<JSONArray *>(b->at("variants"));
    int vlen = variants->length();
    for (int j = 0; j < vlen; j++) {
      parseDefinition(dynamic_cast<JSONObject *>(variants->at(j)), &bid, pack);
    }
    // spread variants in masked bid
    for (int j = vlen; j < 16; j++) {
      int id  = bid | (j << 8);
      int mid = bid | ((j & mask) << 8);
      palette[id].name = palette[mid].name;
      palette[id].hid  = palette[mid].hid;
    }
  }
}
Exemplo n.º 7
0
void BlockIdentifier::parseDefinition(JSONObject *b, BlockInfo *parent,
                                      int pack) {
  int id;
  if (parent == NULL) {
    id = b->at("id")->asNumber();
  } else {
    id = parent->id;
    int data = b->at("data")->asNumber();
    id |= data << 12;
  }
  BlockInfo *block = new BlockInfo();
  block->id = id;

  if (b->has("name"))
    block->setName(b->at("name")->asString());
  else if (parent != NULL)
    block->setName(parent->getName());
  else
    block->setName("Unknown");
  block->enabled = true;

  if (b->has("transparent")) {
    block->transparent = b->at("transparent")->asBool();
    block->rendernormal = false;  // for most cases except the following
    if (b->has("rendercube"))
      block->rendernormal = b->at("rendercube")->asBool();
    block->spawninside = false;  // for most cases except the following
    if (b->has("spawninside"))
      block->spawninside = b->at("spawninside")->asBool();
  } else if (parent != NULL) {
    block->transparent = parent->transparent;
    block->rendernormal = parent->rendernormal;
    block->spawninside = parent->spawninside;
  } else {
    block->transparent = false;
    block->rendernormal = true;
    block->spawninside = false;
  }

  if (b->has("liquid"))
    block->liquid = b->at("liquid")->asBool();
  else if (parent != NULL)
    block->liquid = parent->liquid;
  else
    block->liquid = false;

  if (b->has("canProvidePower"))
    block->providepower = b->at("canProvidePower")->asBool();
  else if (parent != NULL)
    block->providepower = parent->providepower;
  else
    block->providepower = false;

  if (b->has("alpha"))
    block->alpha = b->at("alpha")->asNumber();
  else if (parent != NULL)
    block->alpha = parent->alpha;
  else
    block->alpha = 1.0;

  QColor blockcolor;
  if (b->has("color")) {
    QString colorname = b->at("color")->asString();
    if (colorname.length() == 6) {
      // check if this is an old color definition with missing '#'
      bool ok;
      colorname.toInt(&ok,16);
      if (ok)
        colorname.push_front('#');
    }
    blockcolor.setNamedColor(colorname);
    assert(blockcolor.isValid());
  } else if (parent != NULL) {
    // copy brightest color from parent
    blockcolor = parent->colors[15];
  } else {
    // use hashed by name instead
    quint32 hue = qHash(block->getName());
    blockcolor.setHsv(hue % 360, 255, 255);
  }

  // pre-calculate light spectrum
  for (int i = 0; i < 16; i++) {
    // calculate light attenuation similar to Minecraft
    // except base 90% here, were Minecraft is using 80% per level
    double light_factor = pow(0.90,15-i);
    block->colors[i].setRgb(light_factor*blockcolor.red(),
                            light_factor*blockcolor.green(),
                            light_factor*blockcolor.blue(),
                            255*block->alpha );
  }

  if (b->has("mask"))
    block->mask = b->at("mask")->asNumber();
  else if (b->has("variants"))
    block->mask = 0x0f;
  else
    block->mask = 0x00;

  if (b->has("variants")) {
    JSONArray *variants = dynamic_cast<JSONArray *>(b->at("variants"));
    int vlen = variants->length();
    for (int j = 0; j < vlen; j++)
      parseDefinition(dynamic_cast<JSONObject *>(variants->at(j)), block, pack);
  }

  blocks[id].append(block);
  packs[pack].append(block);
}
Exemplo n.º 8
0
const std::string& SoundShader::getDisplayFolder() const
{
    if (!_contents) parseDefinition();
    return _contents->displayFolder;
}
Exemplo n.º 9
0
SoundFileList SoundShader::getSoundFileList() const
{
    if (!_contents) parseDefinition();
    return _contents->soundFiles;
}
Exemplo n.º 10
0
SoundRadii SoundShader::getRadii() const
{
    if (!_contents) parseDefinition();
    return _contents->soundRadii;
}
Exemplo n.º 11
0
int main(int argc, const char *argv[])
 {
  Definition  definition;
  Definition  definitions[MAX_DEFINITIONS];
  uint        definitionCount;
  int         z;
  struct stat statBuffer;
  uint64      size;
  const char  *inputFileName;
  FILE        *inputHandle;
  uint        deleteCount;
  byte        data;
  uint64      n;

  /* parse command line */
  CmdOption_init(COMMAND_LINE_OPTIONS,SIZE_OF_ARRAY(COMMAND_LINE_OPTIONS));
  if (!CmdOption_parse(argv,&argc,
                       COMMAND_LINE_OPTIONS,SIZE_OF_ARRAY(COMMAND_LINE_OPTIONS),
                       CMD_PRIORITY_ANY,
                       stderr,NULL
                      )
     )
  {
    return 1;
  }
  if (versionFlag)
  {
    printf("Destroyer version %s\n",VERSION);
    return 0;
  }
  if (helpFlag)
  {
    printUsage(argv[0]);
    return 0;
  }
  if (argc <= 1)
  {
    fprintf(stderr,"ERROR: No input file given!\n");
    exit(1);
  }
  inputFileName = argv[1];

  /* get file size */
  if (stat(inputFileName,&statBuffer) != 0)
  {
    fprintf(stderr,"ERROR: Cannot detect size of file '%s' (error: %s)\n",
            inputFileName,
            strerror(errno)
           );
    exit(1);
  }
  size = statBuffer.st_size;

  /* parse definitions */
  initRandom(size);
  definitionCount = 0;
  for (z = 2; z < argc; z++)
  {
    if (!parseDefinition(argv[z],&definition,size))
    {
      exit(1);
    }
    if (definitionCount >= MAX_DEFINITIONS)
    {
      fprintf(stderr,"ERROR: to many definitions! Max. %d possible.\n",MAX_DEFINITIONS);
    }
    definitions[definitionCount] = definition;
    definitionCount++;
  }

  /* open input file */
  inputHandle = fopen(inputFileName,"r");
  if (inputHandle == NULL)
  {
    fprintf(stderr,"ERROR: Cannot open file '%s' (error: %s)\n",
            inputFileName,
            strerror(errno)
           );
    exit(1);
  }

  /* destroy and write to stdout */
  deleteCount = 0;
  for (n = 0; n < size; n++)
  {
    /* read byte */
    data = fgetc(inputHandle);

    if (deleteCount == 0)
    {
      /* find matching definition */
      z = 0;
      while ((z < definitionCount) && (n != definitions[z].position))
      {
        z++;
      }

      /* output byte */
      if (z < definitionCount)
      {
        switch (definitions[z].type)
        {
          case DEFINITION_TYPE_MODIFY:
          case DEFINITION_TYPE_RANDOMIZE:
            fwrite(String_cString(definitions[z].value),1,String_length(definitions[z].value),stdout);
            deleteCount = String_length(definitions[z].value)-1;
            break;
          case DEFINITION_TYPE_INSERT:
            fwrite(String_cString(definitions[z].value),1,String_length(definitions[z].value),stdout);
            fputc(data,stdout);
            break;
          case DEFINITION_TYPE_DELETE:
            deleteCount = definitions[z].length-1;
            break;
        }
      }
      else
      {
        fputc(data,stdout);
      }
    }
    else
    {
      deleteCount--;
    }
  }

  /* close files */
  fclose(inputHandle);

  /* free resources */
  CmdOption_done(COMMAND_LINE_OPTIONS,SIZE_OF_ARRAY(COMMAND_LINE_OPTIONS));

  return 0;
 }