Exemplo n.º 1
0
void setSpawns(player_t *p1, player_t *p2) {
    uint8_t myFlip = random(0, 255);
    uint8_t hisFlip = 0;
    Serial1.write(myFlip);
    while (hisFlip == 0) {
        if (Serial1.available()) {
            hisFlip = Serial1.read();
            if (myFlip > hisFlip) {
                getSpawns(p1, p2);
                Serial1.write((uint8_t)p1->currentPosition.x);
                Serial1.write((uint8_t)p1->currentPosition.y);
                Serial1.write((int8_t)p1->direction.x);
                Serial1.write((int8_t)p1->direction.y);
                Serial1.write((uint8_t)p2->currentPosition.x);
                Serial1.write((uint8_t)p2->currentPosition.y);
                Serial1.write((int8_t)p2->direction.x);
                Serial1.write((int8_t)p2->direction.y);
            } else {
                p2->currentPosition.x = getUint();
                p2->currentPosition.y = getUint();
                p2->direction.x = getInt();
                p2->direction.y = getInt();
                p1->currentPosition.x = getUint();
                p1->currentPosition.y = getUint();
                p1->direction.x = getInt();
                p1->direction.y = getInt();
            }
        }
    }
}
Exemplo n.º 2
0
	unsigned int DataBuffer::latticeReadUintArray( iobFile *infile )
	{
		unsigned int sz, inand, inor;

		infile->readUI( sz );
		inand = newUintArray( sz );
		infile->readUIArray( uintArrays[inand]->u, sz );

		infile->readUI( sz );
		inor = newUintArray( sz );
		infile->readUIArray( uintArrays[inor]->u, sz );

		unsigned int returnid = newUintArray( sz );
		unsigned int prev = 0;

		for (unsigned int i=0; i<sz; i++)
		{
			unsigned int iand = getUint( inand, i );
			unsigned int ior = getUint( inor, i );
			unsigned int b = (prev & iand) | (~prev & ior);

			addUint( returnid, b );
			prev = b;
		}

		deleteUintArray( inand );
		deleteUintArray( inor );

		return returnid;
	}
Exemplo n.º 3
0
bool GFF4Struct::getTalkString(uint32 field, Common::Encoding encoding,
                               std::vector<uint32> &strRefs, std::vector<Common::UString> &strs) const {


	const Field *f;
	Common::SeekableReadStream *data = getField(field, f);
	if (!data)
		return false;

	if (f->type != kIFieldTypeTlkString)
		throw Common::Exception("GFF4: Field is not of TalkString type");

	const uint32 count = getListCount(*data, *f);

	strRefs.resize(count);
	strs.resize(count);

	std::vector<uint32> offsets;
	offsets.resize(count);

	for (uint32 i = 0; i < count; i++) {
		strRefs[i] = getUint(*data, kIFieldTypeUint32);

		const uint32 offset = getUint(*data, kIFieldTypeUint32);
		if ((offset != 0xFFFFFFFF) && (offset != 0))
			strs[i] = getString(*data, encoding, _parent->getDataOffset() + offset);
	}

	return true;
}
Exemplo n.º 4
0
	unsigned int DataBuffer::compareArraysNumberOfErrors( unsigned int id1, unsigned int id2 )
	{
		unsigned int err = 0;

		assert( id1 < ((unsigned int) floatArrays.size()) );
		assert( id2 < ((unsigned int) floatArrays.size()) );

		if (floatArrays[id1]->sz != floatArrays[id2]->sz) return floatArrays[id1]->sz + floatArrays[id2]->sz;

		for (unsigned int i=0; i<floatArrays[id1]->sz; i++)
		{
			err += getUint(floatArrays[id1]->qid,i) != getUint(floatArrays[id2]->qid,i) ? 1 : 0;
		}

		return err;
	}
Exemplo n.º 5
0
	unsigned int DataBuffer::readQuantizedArray( iobFile *infile )
	{
		unsigned int sz, ri;
		unsigned char bits;
		float minf, maxf;

		infile->readUC( bits );
		infile->readF( minf );
		infile->readF( maxf );
		infile->readUI( sz );

		ri = newFloatArray( sz );

		infile->readUIArray( uintArrays[floatArrays[ri]->qid]->u, sz );

		floatArrays[ri]->minf = minf;
		floatArrays[ri]->maxf = maxf;
		floatArrays[ri]->bits = bits;

		double intervalScale = double(floatArrays[ri]->maxf - floatArrays[ri]->minf) / double(1 << bits);

		for (unsigned int i=0; i<floatArrays[ri]->sz; i++)
		{
			double normf = double(getUint( floatArrays[ri]->qid, i )*intervalScale + floatArrays[ri]->minf);
			floatArrays[ri]->f[i] = float(normf);
		}

		return ri;
	}
Exemplo n.º 6
0
Common::UString GFF3Struct::getString(const Common::UString &field,
                                      const Common::UString &def) const {

	const Field *f = getField(field);
	if (!f)
		return def;

	if (f->type == kFieldTypeExoString) {
		Common::SeekableReadStream &data = getData(*f);

		const uint32 length = data.readUint32LE();
		return Common::readStringFixed(data, Common::kEncodingASCII, length);
	}

	if (f->type == kFieldTypeResRef) {
		Common::SeekableReadStream &data = getData(*f);

		const uint32 length = data.readByte();
		return Common::readStringFixed(data, Common::kEncodingASCII, length);
	}

	if ((f->type == kFieldTypeByte  ) ||
	    (f->type == kFieldTypeUint16) ||
	    (f->type == kFieldTypeUint32) ||
	    (f->type == kFieldTypeUint64) ||
	    (f->type == kFieldTypeStrRef)) {

		return Common::UString::format("%lu", getUint(field));
	}

	if ((f->type == kFieldTypeChar  ) ||
	    (f->type == kFieldTypeSint16) ||
	    (f->type == kFieldTypeSint32) ||
	    (f->type == kFieldTypeSint64)) {

		return Common::UString::format("%ld", getSint(field));
	}

	if ((f->type == kFieldTypeFloat) ||
	    (f->type == kFieldTypeDouble)) {

		return Common::UString::format("%lf", getDouble(field));
	}

	if (f->type == kFieldTypeVector) {
		float x, y, z;

		getVector(field, x, y, z);
		return Common::UString::format("%f/%f/%f", x, y, z);
	}

	if (f->type == kFieldTypeOrientation) {
		float a, b, c, d;

		getOrientation(field, a, b, c, d);
		return Common::UString::format("%f/%f/%f/%f", a, b, c, d);
	}

	throw Common::Exception("GFF3: Field is not a string(able) type");
}
Exemplo n.º 7
0
uint64 GFF4Struct::getUint(uint32 field, uint64 def) const {
	const Field *f;
	Common::SeekableReadStream *data = getField(field, f);
	if (!data)
		return def;

	if (f->isList)
		throw Common::Exception("GFF4: Tried reading list as singular value");

	return getUint(*data, f->type);
}
Exemplo n.º 8
0
bool GFF4Struct::getTalkString(uint32 field, Common::Encoding encoding,
                               uint32 &strRef, Common::UString &str) const {

	const Field *f;
	Common::SeekableReadStream *data = getField(field, f);
	if (!data)
		return false;

	if (f->type != kIFieldTypeTlkString)
		throw Common::Exception("GFF4: Field is not of TalkString type");
	if (f->isList)
		throw Common::Exception("GFF4: Tried reading list as singular value");

	strRef = getUint(*data, kIFieldTypeUint32);

	const uint32 offset = getUint(*data, kIFieldTypeUint32);

	str.clear();
	if ((offset != 0xFFFFFFFF) && (offset != 0))
		str = getString(*data, encoding, _parent->getDataOffset() + offset);

	return true;
}
Exemplo n.º 9
0
bool GFF4Struct::getBool(uint32 field, std::vector<bool> &list) const {
	const Field *f;
	Common::SeekableReadStream *data = getField(field, f);
	if (!data)
		return false;

	const uint32 count = getListCount(*data, *f);

	list.resize(count);
	for (uint32 i = 0; i < count; i++)
		list[i] = getUint(*data, f->type) != 0;

	return true;
}
Exemplo n.º 10
0
    void Graphics::drawSection( std::string texture, int rectX, int rectY, int rectW, int rectH, int posX, int posY, int rotation )
    {
        uint id= getUint( texture );
        int textureWidth;
        int textureHeight;

        glEnable( GL_TEXTURE_2D );
        glBindTexture( GL_TEXTURE_2D, id );


        // Get width and height of the texture
        glGetTexLevelParameteriv( GL_TEXTURE_2D, 0, GL_TEXTURE_WIDTH, &textureWidth );
        glGetTexLevelParameteriv( GL_TEXTURE_2D, 0, GL_TEXTURE_HEIGHT, &textureHeight );


        double texLeft = (double)rectX / (double)textureWidth;
        double texRight = ((double)rectX + (double)rectW) / (double)textureWidth;
        double texTop = (double)rectY / (double)textureHeight;
        double texBottom = ((double)rectY + (double)rectH) / (double)textureHeight;

        glPushMatrix();

        // Rotation
        glTranslatef(rectX + rectW/2,rectY + rectH/2,0);
        glRotatef(rotation,0,0,1);
        glTranslatef(-rectX - rectW/2,-rectY - rectH/2,0);

        glBegin( GL_QUADS );
            glTexCoord2f(texLeft,texTop); glVertex2f( posX, posY );
            glTexCoord2f(texRight,texTop); glVertex2f( posX+rectW, posY );
            glTexCoord2f(texRight,texBottom); glVertex2f( posX+rectW, posY+rectH );
        glTexCoord2f(texLeft,texBottom); glVertex2f( posX, posY+rectH );
        glEnd();
        glDisable( GL_TEXTURE_2D );

        glPopMatrix();
        //glLoadIdentity();

        glDisable( GL_TEXTURE_2D );
    }
Exemplo n.º 11
0
int main(int argc, TCHAR **argv) {
//  _tprintf(_T("sizeof(long double):%s\n"), FSZ(sizeof(long double)));
//  _tprintf(_T("sizeof(Double80:%s\n"), FSZ(sizeof(Double80)));

  unsigned __int64 ui64max = _UI64_MAX;
  Double80         dui64 = ui64max;
  unsigned __int64 rui64 = getUint64(dui64);

  for (;;) {
    double x = inputDouble(_T("Enter x:"));
//    double y = inputDouble(_T("Enter y:"));
    Double80 x80 = x; // , y80 = y;
//    Double80 z80 = pow(x80, y80);
    Double80 z80 = exp2(x80);
    double z64 = getDouble(z80);
    _tprintf(_T("exp2(%lg)=%le\n"), x, z64);
  }
  Double80 x;
  Double80 y;
  unsigned long l1 = 1;
  x = 1;
  y = 2.3;
  Double80 z = x + y;
  double z64 = getDouble(z);
  _tprintf(_T("x+y:%le\n"), z64);

  x = 9.7;
  y = 4;
  z = fmod(x, y);
  z64 = getDouble(z);

  x = M_PI;
  x *= 2;
  x /= 3;
  double x64 = getDouble(x);
  Double80 c = x, s;
  sincos(c, s);
  double c64 = getDouble(c);
  double s64 = getDouble(s);
  z = cos(x);
  z64 = getDouble(z);

  double e10 = 9.999e20;
  Double80 d1080 = e10;
  int expo10 = Double80::getExpo10(d1080);

  Double80 exp80 = exp(z);
  double exp64 = getDouble(exp80);
  const long             maxi32     = 0x7fffffff;
  Double80               zi32(maxi32);
  const long             i32_1      = getInt(zi32);

  const unsigned long    ui32_a1    = maxi32;
  Double80               dui32_a(ui32_a1);
  const unsigned long    ui32_a2    = getUint(dui32_a);

  const unsigned long    ui32_b1    = (unsigned long)maxi32 + 1;
  Double80               dui32_b(ui32_b1);
  const unsigned long    ui32_b2    = getUint(dui32_b);

  const __int64          maxi64     = 0x7fffffffffffffffui64;
  Double80               di64(maxi64);
  const __int64          i64_1      = getInt64(di64);

  const unsigned __int64 ui64_a1    = maxi64;
  Double80               dui64_a(ui64_a1);
  const unsigned __int64 ui64_a2    = getUint64(dui64_a);

  const unsigned __int64 ui64_b1    = (unsigned __int64)maxi64 + 1;
  Double80               dui64_b(ui64_b1);
  const unsigned __int64 ui64_b2    = getUint64(dui64_b);

  const float            f1         = 1.23456f;
  Double80               zf(f1);
  const float            f2         = getFloat(zf);

  return 0;
}
Exemplo n.º 12
0
Common::UString GFF3Struct::getString(const Common::UString &field,
                                      const Common::UString &def) const {

	const Field *f = getField(field);
	if (!f)
		return def;

	// Direct string
	if (f->type == kFieldTypeExoString) {
		Common::SeekableReadStream &data = getData(*f);

		const uint32 length = data.readUint32LE();
		return Common::readStringFixed(data, Common::kEncodingASCII, length);
	}

	// ResRef, resource reference, a shorter string
	if (f->type == kFieldTypeResRef) {
		Common::SeekableReadStream &data = getData(*f);

		const uint32 length = data.readByte();
		return Common::readStringFixed(data, Common::kEncodingASCII, length);
	}

	// LocString, a localized string
	if (f->type == kFieldTypeLocString) {
		LocString locString;
		getLocString(field, locString);

		return locString.getString();
	}

	// Unsigned integer type, compose a string representation
	if ((f->type == kFieldTypeByte  ) ||
	    (f->type == kFieldTypeUint16) ||
	    (f->type == kFieldTypeUint32) ||
	    (f->type == kFieldTypeUint64) ||
	    (f->type == kFieldTypeStrRef)) {

		return Common::composeString(getUint(field));
	}

	// Signed integer type, compose a string representation
	if ((f->type == kFieldTypeChar  ) ||
	    (f->type == kFieldTypeSint16) ||
	    (f->type == kFieldTypeSint32) ||
	    (f->type == kFieldTypeSint64)) {

		return Common::composeString(getSint(field));
	}

	// Floating point type, compose a string representation
	if ((f->type == kFieldTypeFloat) ||
	    (f->type == kFieldTypeDouble)) {

		return Common::composeString(getDouble(field));
	}

	// Vector, consisting of 3 floats
	if (f->type == kFieldTypeVector) {
		float x = 0.0, y = 0.0, z = 0.0;

		getVector(field, x, y, z);
		return Common::composeString(x) + "/" +
		       Common::composeString(y) + "/" +
		       Common::composeString(z);
	}

	// Orientation, consisting of 4 floats
	if (f->type == kFieldTypeOrientation) {
		float a = 0.0, b = 0.0, c = 0.0, d = 0.0;

		getOrientation(field, a, b, c, d);
		return Common::composeString(a) + "/" +
		       Common::composeString(b) + "/" +
		       Common::composeString(c) + "/" +
		       Common::composeString(d);
	}

	throw Common::Exception("GFF3: Field is not a string(able) type");
}
Exemplo n.º 13
0
bool GFF3Struct::getBool(const Common::UString &field, bool def) const {
	return getUint(field, def) != 0;
}
Exemplo n.º 14
0
bool GFF4Struct::getBool(uint32 field, bool def) const {
	return getUint(field, def) != 0;
}
Exemplo n.º 15
0
uint AmarokMediaPlayer::getPlayListLength()
{
	kdebugf();
	return getUint("playlist", "getTotalTrackCount");
	kdebugf2();
}
Exemplo n.º 16
0
Common::UString GFF3Struct::getString(const Common::UString &field,
                                      const Common::UString &def) const {

	const Field *f = getField(field);
	if (!f)
		return def;

	if (f->type == kFieldTypeExoString) {
		Common::SeekableReadStream &data = getData(*f);

		const uint32 length = data.readUint32LE();
		return Common::readStringFixed(data, Common::kEncodingASCII, length);
	}

	if (f->type == kFieldTypeResRef) {
		Common::SeekableReadStream &data = getData(*f);

		const uint32 length = data.readByte();
		return Common::readStringFixed(data, Common::kEncodingASCII, length);
	}

	if (f->type == kFieldTypeLocString) {
		LocString locString;
		getLocString(field, locString);

		return locString.getString();
	}

	if ((f->type == kFieldTypeByte  ) ||
	    (f->type == kFieldTypeUint16) ||
	    (f->type == kFieldTypeUint32) ||
	    (f->type == kFieldTypeUint64) ||
	    (f->type == kFieldTypeStrRef)) {

		return Common::composeString(getUint(field));
	}

	if ((f->type == kFieldTypeChar  ) ||
	    (f->type == kFieldTypeSint16) ||
	    (f->type == kFieldTypeSint32) ||
	    (f->type == kFieldTypeSint64)) {

		return Common::composeString(getSint(field));
	}

	if ((f->type == kFieldTypeFloat) ||
	    (f->type == kFieldTypeDouble)) {

		return Common::composeString(getDouble(field));
	}

	if (f->type == kFieldTypeVector) {
		float x = 0.0, y = 0.0, z = 0.0;

		getVector(field, x, y, z);
		return Common::composeString(x) + "/" +
		       Common::composeString(y) + "/" +
		       Common::composeString(z);
	}

	if (f->type == kFieldTypeOrientation) {
		float a = 0.0, b = 0.0, c = 0.0, d = 0.0;

		getOrientation(field, a, b, c, d);
		return Common::composeString(a) + "/" +
		       Common::composeString(b) + "/" +
		       Common::composeString(c) + "/" +
		       Common::composeString(d);
	}

	throw Common::Exception("GFF3: Field is not a string(able) type");
}