Esempio n. 1
0
	void simulate() {
		cout << "Simulating..." << endl;
		
		for (int i = 0; i < 5; i++) {
			cout << "#" << i << endl; 
			nextStage();
			cout << "Tracing..." << endl;
			traceRays(h_rays, scene);
			nextStage();
			cout << "Interacting..." << endl;
			interactRays(h_rays);
		}
	}
Esempio n. 2
0
void EndlessGameWidget::advance()
{
  // Add the frame count
  ++frameCount;

  // Advance the controller
  controller->advance();

  // Go to next stage if the score has been reached
  if (progressBar->getCurrent() >= progressBar->getMax())
  {
    bool allStable = true;
    for (int i = 0;i < gameboardInfo->totalBallCounts();++i)
      if ((!controller->balls[i]) ||
          controller->balls[i]->getState() != Ball::Stable)
      {
        allStable = false;
        break;
      }

    if (allStable)
      nextStage();
    return;
  }
}
Esempio n. 3
0
void Physics::step(void) {
  dynamicWorld->stepSimulation(1.f/60.f);
  graphics->animate();
  int numManifolds = dynamicWorld->getDispatcher()->getNumManifolds();
  for (int i = 0; i < numManifolds; i++) {
    btPersistentManifold* contactManifold =  dynamicWorld->getDispatcher()->getManifoldByIndexInternal(i);
    btCollisionObject* obA = static_cast<btCollisionObject*>(contactManifold->getBody0());
    btCollisionObject* obB = static_cast<btCollisionObject*>(contactManifold->getBody1());
    btBroadphaseProxy* obA_proxy = obA->getBroadphaseHandle();
    btBroadphaseProxy* obB_proxy = obB->getBroadphaseHandle();
    if (obA_proxy->m_collisionFilterGroup & obB_proxy->m_collisionFilterMask) {
      if (obA_proxy->m_collisionFilterGroup == COL_PENGUIN && obB_proxy->m_collisionFilterGroup == COL_KILLBOX) {
        PhysicsBody* object = reinterpret_cast<PhysicsBody*>(obA->getUserPointer());
        resetObject(object);
      } else if (obA_proxy->m_collisionFilterGroup == COL_PENGUIN && obB_proxy->m_collisionFilterGroup == COL_GOAL) {
        nextStage();
        graphics->playSound(2);
      } else if (obA_proxy->m_collisionFilterGroup == COL_PENGUIN && obB_proxy->m_collisionFilterGroup == COL_CHECKPOINT) {
        btVector3 checkpoint2 = obB->getWorldTransform().getOrigin();
        btBoxShape* shape = reinterpret_cast<btBoxShape*>(obB->getCollisionShape());
        checkpoint2 += btVector3(0, shape->getHalfExtentsWithoutMargin().y(), 0);
        checkpoint2 += btVector3(0, 25, 0);
        PhysicsBody* object = reinterpret_cast<PhysicsBody*>(obA->getUserPointer());
        btRigidBody* body = object->getBody();
        btVector3 translate = body->getCenterOfMassPosition();
        if (checkpoint2 != checkpoint && translate.y() >= checkpoint2.y()) {
          graphics->playSound(1);
          checkpoint = checkpoint2;
        }
      }
    }
  }
}
Esempio n. 4
0
void *quant_thread(void *args)
{
	gmactime_t s, t;

	barrier_wait(&barrierInit);

	getTime(&s);
	gmac_sem_post(&s_quant.free, 1);
	nextStage(&s_quant, &s_idct);
	getTime(&t);
	printTime(&s, &t, "Quant:SendRecv: ", "\n");

	ecl::config localSize(blockSize, blockSize);
	ecl::config globalSize(width, height);
	if(width  % blockSize) globalSize.x += blockSize;
	if(height % blockSize) globalSize.y += blockSize;
	ecl::error err;
	ecl::kernel k("quant", err);
	assert(err == eclSuccess);

	assert(k.setArg(2, width)       == eclSuccess);
	assert(k.setArg(3, height)      == eclSuccess);
	assert(k.setArg(4, float(1e-6)) == eclSuccess);

	for(unsigned i = 0; i < frames; i++) {
		getTime(&s);
		assert(k.setArg(0, s_quant.in)  == eclSuccess);
		assert(k.setArg(1, s_quant.out) == eclSuccess);
		assert(k.callNDRange(globalSize, localSize) == eclSuccess);
		getTime(&t);
		printTime(&s, &t, "Quant:Run: ", "\n");

		getTime(&s);
		nextStage(&s_quant, &s_idct);
		getTime(&t);
		printTime(&s, &t, "Quant:SendRecv: ", "\n");
	}

	// Move one stage the pipeline stages the pipeline
	getTime(&s);
	nextStage(&s_quant, &s_idct);
	getTime(&t);
	printTime(&s, &t, "Quant:SendRecv: ", "\n");

	return NULL;
}
Esempio n. 5
0
    bool FontPropertyManager::readFamilyMapping(NameMap *rc, QString *errorMessage)
    {
        rc->clear();
        const QString fileName = QLatin1String(":/trolltech/propertyeditor/fontmapping.xml");
        QFile file(fileName);
        if (!file.open(QIODevice::ReadOnly)) {
            *errorMessage = QString::fromUtf8("Unable to open %1: %2").arg(fileName, file.errorString());
            return false;
        }

        QXmlStreamReader reader(&file);
        QXmlStreamReader::TokenType token;

        QString family;
        ParseStage stage = ParseBeginning;
        do {
            token = reader.readNext();
            switch (token) {
            case QXmlStreamReader::Invalid:
                *errorMessage = msgXmlError(reader, fileName);
                 return false;
            case QXmlStreamReader::StartElement:
                stage = nextStage(stage, reader.name());
                switch (stage) {
                case ParseError:
                    reader.raiseError(QString::fromUtf8("Unexpected element <%1>.").arg(reader.name().toString()));
                    *errorMessage = msgXmlError(reader, fileName);
                    return false;
                case ParseWithinFamily:
                    family = reader.readElementText();
                    break;
                case ParseWithinDisplay:
                    rc->insert(family, reader.readElementText());
                    break;
                default:
                    break;
                }
            default:
                break;
            }
        } while (token != QXmlStreamReader::EndDocument);
        return true;
    }
Esempio n. 6
0
bool DeviceProfile::fromXml(const QString &xml, QString *errorMessage)
{
    DeviceProfileData &d = *m_d;
    d.fromSystem();

    QXmlStreamReader reader(xml);

    ParseStage ps = ParseBeginning;
    QXmlStreamReader::TokenType tt = QXmlStreamReader::NoToken;
    int iv = 0;
    do {
        tt = reader.readNext();
        if (tt == QXmlStreamReader::StartElement) {
            ps = nextStage(ps, reader.name());
            switch (ps) {
            case ParseBeginning:
            case ParseWithinRoot:
                break;
            case ParseError:
                reader.raiseError(QApplication::translate("DeviceProfile", "An invalid tag <%1> was encountered.").arg(reader.name().toString()));
                tt = QXmlStreamReader::Invalid;
                break;
            case ParseName:
                d.m_name = reader.readElementText();
                break;
            case ParseFontFamily:
                d.m_fontFamily = reader.readElementText();
                break;
            case ParseFontPointSize:
                if (readIntegerElement(reader, &iv)) {
                    d.m_fontPointSize = iv;
                } else {
                    tt = QXmlStreamReader::Invalid;
                }
                break;
            case ParseDPIX:
                if (readIntegerElement(reader, &iv)) {
                    d.m_dpiX = iv;
                } else {
                    tt = QXmlStreamReader::Invalid;
                }
                break;
            case ParseDPIY:
                if (readIntegerElement(reader, &iv)) {
                    d.m_dpiY = iv;
                } else {
                    tt = QXmlStreamReader::Invalid;
                }
                break;
            case ParseStyle:
                d.m_style = reader.readElementText();
                break;
            }
        }
    } while (tt != QXmlStreamReader::Invalid && tt != QXmlStreamReader::EndDocument);

    if (reader.hasError()) {
        *errorMessage = reader.errorString();
        return false;
    }

    return true;
}
Esempio n. 7
0
void *idct_thread(void *args)
{
	gmactime_t s, t;

	barrier_wait(&barrierInit);

	getTime(&s);
	gmac_sem_post(&s_idct.free, 1);
	ecl::deviceSendReceive(s_dct.id);
	nextStage(&s_idct, NULL);
	getTime(&t);
	printTime(&s, &t, "IDCT:SendRecv: ", "\n");

	getTime(&s);
	gmac_sem_post(&s_idct.free, 1);
	ecl::deviceSendReceive(s_dct.id);
	getTime(&t);
	nextStage(&s_idct, NULL);
	getTime(&t);
	printTime(&s, &t, "IDCT:SendRecv: ", "\n");

	ecl::config localSize(blockSize, blockSize);
	ecl::config globalSize(width, height);
	if(width  % blockSize) globalSize.x += blockSize;
	if(height % blockSize) globalSize.y += blockSize;
	ecl::error err;
	ecl::kernel k("idct", err);
	assert(err == eclSuccess);

	assert(k.setArg(2, width)   == eclSuccess);
	assert(k.setArg(3, height)  == eclSuccess);

	for(unsigned i = 0; i < frames; i++) {
		getTime(&s);
		assert(k.setArg(0, s_idct.in)  == eclSuccess);
		assert(k.setArg(1, s_idct.out) == eclSuccess);
		assert(k.callNDRange(globalSize, localSize) == eclSuccess);
		getTime(&t);
		printTime(&s, &t, "IDCT:Run: ", "\n");

		getTime(&s);
		assert(ecl::free(s_idct.in) == eclSuccess);
		assert(ecl::free(s_idct.out) == eclSuccess);
		getTime(&t);
		printTime(&s, &t, "IDCT:Free: ", "\n");

		getTime(&s);
		ecl::deviceSendReceive(s_dct.id);
		nextStage(&s_idct, NULL);
		getTime(&t);
		printTime(&s, &t, "IDCT:SendRecv: ", "\n");
	}

	getTime(&s);
	ecl::free(s_idct.in);
	ecl::free(s_idct.out);
	getTime(&t);
	printTime(&s, &t, "IDCT:Free: ", "\n");

	return NULL;
}
Esempio n. 8
0
int main()
{
	GOOGLE_PROTOBUF_VERIFY_VERSION;
	shiny::RenderRequest renreq;
  
	Render render;
	
	nextStage();
	
	render.eye    = Vector3(0, 1, 0);
	render.target = Vector3(0, 1, -1);
	
	render.scene.addSphere(-3, 1, -8, 3);
	render.scene.addSphere(3, 1.5, -7, 2);
	render.scene.spheres[1].material.emission = Vector3(0.5, 0.5, 0);
	
	render.start();
	
	cout << "Serializing..." << endl;
	
	auto script = stages;
	
	/*
	[
		[
			["add", "vector", {
				"n": 1,                              // Number of vectors
				"data": [[1, 1, 1], [1, 2, 3]],                        // Array of alternating start and end points,
				"line": true,                        // Whether to draw vector lines
				"arrow": true,                       // Whether to draw arrowheads
				"size": 0.07,                         // Size of the arrowhead relative to the stage
			}],
		]
	]
	*/
	
	ujson::value jsonScript{ script };
	ujson::value jsonScene = to_json(render.scene);
	
  	ofstream dataFile;
	dataFile.open (OUTPUT_FILE);
	dataFile << "window.mathboxScript = " << jsonScript << ";" << endl;
	dataFile << "window.mathboxScene = " << jsonScene << ";" << endl;
	dataFile.close();
  	
	
	
	/*
	Server server;
	
	server.start();
	
	while (!server.exit) {
		shSleep(1);
	}
	
	server.stop();
	//*/
	
  	google::protobuf::ShutdownProtobufLibrary();
	
	cout << "Done!" << endl;
	  
	/*
	thrust::host_vector<Vector3f> h_rpos(n);
	thrust::host_vector<Vector3f> h_rdir(n);
	
	thrust::host_vector<Vector3i> h_pos(n);
	thrust::host_vector<Vector3i> h_step(n);
	thrust::host_vector<Vector3f> h_tmax(n);
	thrust::host_vector<Vector3f> h_tdelta(n);
	thrust::host_vector<CubeSide> h_side(n);
	
	for (int i = 0; i < n; i++) {
		Vector3f *p;
		p = &h_rpos[i];
		p->set(0.5f, 0.5f, 0.5f);
		p = &h_rdir[i];
		p->set(0.01f, 1.f, -0.01f);
	}
	
	initTrace(n, h_rpos, h_rdir, h_pos, h_step, h_tmax, h_tdelta, h_side);
	
	printElement(0, h_rpos, h_rdir, h_pos, h_step, h_tmax, h_tdelta, h_side);
	
	step(n, h_pos, h_step, h_tmax, h_tdelta, h_side);
	
	printElement(0, h_rpos, h_rdir, h_pos, h_step, h_tmax, h_tdelta, h_side);
	*/
	
	return 0;
}