Example #1
0
void Board::move(Direction dir)
{
    // simple move
    int currLoc;
    int nextLoc = initPos(dir);

    for(int i = 0; i < 4; ++i)
    {
        bool swapped;
        int initNext = nextLoc;
        do
        {
            swapped = false;
            for(int j = 0; j < 3; ++j)
            {
                currLoc = nextLoc;
                nextLoc = next(dir, nextLoc);
                if(m_state[nextLoc] == 0 && m_state[currLoc] != 0)
                {
                    swap(currLoc, nextLoc);
                    swapped = true;
                }
            }
            nextLoc = initNext;
        }
        while(swapped);
        nextLoc = nextRow(dir, next(dir, currLoc));
    }
}
Example #2
0
// 初始化動畫
BouncyLogo::BouncyLogo(QCanvas* canvas) :
    QCanvasSprite(0,canvas)
{
    static QCanvasPixmapArray logo("qt-trans.xpm"); // 動畫有多個frame
    setSequence(&logo); // 設定logo
    setAnimated(TRUE); // 動畫可移動
    initPos();
}
/**
 * @brief Init Wall follow controller
 */
void wallFollow_init()
{
	pid_Wallfollow_init();
	initPos();
	eMove=FORWARD;
	currentDir=UP_DIR;
	avrSpeed=AVG_SPEED_FWD;
}
Example #4
0
void HandgripItem::mousePressEvent(QGraphicsSceneMouseEvent *event)
{
    if (event->button() == Qt::LeftButton)
    {
        m_moving = true;
        emit initPos( event->scenePos() );
    }
    else
    {
        QGraphicsPathItem::mousePressEvent(event);
    }
}
Example #5
0
void Grandf::deal( const QList<KCard*> & cardsToDeal )
{
    setKeyboardModeActive( false );

    QList<KCard*> cards = cardsToDeal;

    QPointF initPos( 1.4 * 3 * deck()->cardWidth(), 1.2 * deck()->cardHeight() );

    int start = 0;
    int stop = 7-1;
    int dir = 1;

    for (int round=0; round < 7; round++)
    {
        int i = start;
        do
        {
            if (!cards.isEmpty())
                addCardForDeal( store[i], cards.takeLast(), (i == start), initPos );
            i += dir;
        } while ( i != stop + dir);
        int t = start;
        start = stop;
        stop = t+dir;
        dir = -dir;
    }

    int i = 0;
    while (!cards.isEmpty())
    {
        addCardForDeal( store[i+1], cards.takeLast(), true, initPos );
        i = (i+1)%6;
    }

    for (int round=0; round < 7; round++)
    {
        KCard *c = store[round]->topCard();
        if (c)
            c->setFaceUp(true);
    }

    startDealAnimation();
}
Example #6
0
//--------------------------------------------------------------
void testApp::setup(){
    ofBackground(255);
    ofEnableSmoothing();
    ofSetVerticalSync(true);
    
    ofVec2f initPos(0, ofGetHeight()/2);
  
    vehicles.resize(100);
    
    for(unsigned int i = 0; i < vehicles.size(); i++){
        ofVec2f location(ofGetWidth(), ofGetHeight());

        vehicles[i].setup(location, ofRandom(2,4), 0.3);
    }
    
    newPath();
    
    
}
Example #7
0
void Board::collapse(Direction dir)
{
    dir = reversePosition(dir);
    int currLoc;
    int nextLoc = initPos(dir);

    for(int i = 0; i < 4; ++i)
    {
        for(int j = 0; j < 3; ++j)
        {
            currLoc = nextLoc;
            nextLoc = next(dir, nextLoc);
            if((m_state[nextLoc] != 0) && (m_state[currLoc] == m_state[nextLoc]))
            {
                m_state[nextLoc] *= 2;
                m_state[currLoc] = 0;
            }
        }
        nextLoc = nextRow(dir, next(dir, currLoc));
    }
}
Example #8
0
void Player::reinit(){

    //stop timers
    dieTimer.stop();
    jumpTimer.stop();
    died = false;

    //reset velocities
    mVelX = 0;
    lastVelX = 0;
    mVelY = 0;

    if(inventory->hasItem(2)){
        inventory->getItems().at(2)->setDisabled(true); //disable the super jump by default
        superJump = false;
    }

    initPos();

    init = true;
}
bool FaceFeatureRecognitionApp::MouseReleased( const OIS::MouseEvent &arg, OIS::MouseButtonID id )
{
    if (mMouseMode == MM_Mark_KeyPoint)
    {
        int hPos = arg.state.Y.abs - 10;
        int wPos = arg.state.X.abs - 110;
        SynthesizeData(wPos, hPos);
    }
    else if (mMouseMode == MM_Test_KeyPoint)
    {
        int hPos = arg.state.Y.abs - 10;
        int wPos = arg.state.X.abs - 110;
        std::vector<double> initPos(2);
        initPos.at(0) = hPos;
        initPos.at(1) = wPos;
        cv::Mat img = mpF2DObj->GetFaceImage();
        std::vector<double> finalPos;
        mpFfd->PoseRegression(img, initPos, finalPos);
        UpdateDisplayImage(&initPos, &finalPos);
        //UpdateDisplayImage(&initPos, NULL);
    }
    else if (mMouseMode == MM_Test_Shape)
    {
        int hPos = arg.state.Y.abs - 10;
        int wPos = arg.state.X.abs - 110;
        cv::Mat img = mpF2DObj->GetFaceImage();
        std::vector<double> meanFace = mpShapeRegression->GetMeanFace();
        int markSize = meanFace.size() / 2;
        for (int markId = 0; markId < markSize; markId++)
        {
            meanFace.at(markId * 2) += hPos;
            meanFace.at(markId * 2 + 1) += wPos;
        }
        std::vector<double> finalFace;
        mpShapeRegression->ShapeRegression(img, meanFace, finalFace);
        UpdateDisplayImage(NULL, &finalFace);
    }

    return true;
}
void vkeGameRendererDynamic::initRenderer(){
	VulkanDC *dc = VulkanDC::Get();
	VulkanDC::Device *device = dc->getDevice();

	m_instance_count = 128;

	glWaitVkSemaphoreNV = (PFNGLWAITVKSEMAPHORENVPROC)NVPWindow::sysGetProcAddress("glWaitVkSemaphoreNV");
	glSignalVkSemaphoreNV = (PFNGLSIGNALVKSEMAPHORENVPROC)NVPWindow::sysGetProcAddress("glSignalVkSemaphoreNV");
	glSignalVkFenceNV = (PFNGLSIGNALVKFENCENVPROC)NVPWindow::sysGetProcAddress("glSignalVkFenceNV");
	glDrawVkImageNV = (PFNGLDRAWVKIMAGENVPROC)NVPWindow::sysGetProcAddress("glDrawVkImageNV");

	VkSemaphoreCreateInfo semInfo = { VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO };
	VkFenceCreateInfo fenceInfo = {VK_STRUCTURE_TYPE_FENCE_CREATE_INFO};

	VKA_CHECK_ERROR(vkCreateSemaphore(device->getVKDevice(), &semInfo, NULL, &m_present_done[0]), "Could not create present done semaphore.\n");
	VKA_CHECK_ERROR(vkCreateSemaphore(device->getVKDevice(), &semInfo, NULL, &m_render_done[0]), "Could not create render done semaphore.\n");
	VKA_CHECK_ERROR(vkCreateSemaphore(device->getVKDevice(), &semInfo, NULL, &m_present_done[1]), "Could not create present done semaphore.\n");
	VKA_CHECK_ERROR(vkCreateSemaphore(device->getVKDevice(), &semInfo, NULL, &m_render_done[1]), "Could not create render done semaphore.\n");

	VKA_CHECK_ERROR(vkCreateFence(device->getVKDevice(), &fenceInfo, NULL, &m_update_fence[0]), "Could not create update fence.\n");
	fenceInfo.flags = VK_FENCE_CREATE_SIGNALED_BIT;
	VKA_CHECK_ERROR(vkCreateFence(device->getVKDevice(), &fenceInfo, NULL, &m_update_fence[1]), "Could not create update fence.\n");

	m_terrain_command[0] = VK_NULL_HANDLE;
	m_terrain_command[1] = VK_NULL_HANDLE;
	m_framebuffers[0] = VK_NULL_HANDLE;
	m_framebuffers[1] = VK_NULL_HANDLE;
	m_update_commands[0] = VK_NULL_HANDLE;
	m_update_commands[1] = VK_NULL_HANDLE;

	m_is_first_frame = true;


	nv_math::vec3f table[128][128];

	for (int v = 0; v < 128; ++v){
		for (int u = 0; u < 128; ++u){

			nv_math::vec2f vctr(quickRandomUVD(), quickRandomUVD());
			vctr = nv_math::normalize(vctr);

			table[u][v] = nv_math::vec3f(vctr.x, vctr.y, vctr.x);
		}
	}

	m_cube_textures.newTexture(1)->loadCubeDDS("environ.dds");
	m_screen_quad.initQuadData();
	m_terrain_quad.initQuadData();

	m_textures.newTexture(0)->setFormat(VK_FORMAT_R32G32B32_SFLOAT);
	m_textures.getTexture(0)->loadTextureFloatData((float *)&(table[0][0].x), 128, 128, 3);


	m_flight_paths = (FlightPath**)malloc(sizeof(FlightPath*) * m_instance_count);

	for (uint32_t i = 0; i < m_instance_count; ++i){

		nv_math::vec2f initPos(quickRandomUVD()*100.0, -200 + (quickRandomUVD() * 20));
		nv_math::vec2f endPos(quickRandomUVD()*100.0, 200 + (quickRandomUVD() * 20));
		m_flight_paths[i] = new FlightPath(initPos, endPos, quickRandomUVD() * 0.5 + 0.5, quickRandomUVD() * 4 + 10);

	}

	/*
	Just initialises the draw call objects
	not the threads. They store thread local
	data for the threaded cmd buffer builds.
	*/
	initDrawCalls();


	/*
	Create primary command pool for the
	*/
	VkCommandPoolCreateInfo cmdPoolInfo = { VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO };
	cmdPoolInfo.queueFamilyIndex = 0;
	cmdPoolInfo.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;

	VKA_CHECK_ERROR(vkCreateCommandPool(device->getVKDevice(), &cmdPoolInfo, NULL, &m_primary_buffer_cmd_pool), "Could not create primary command pool.\n");

	m_primary_commands[0] = VK_NULL_HANDLE;
	m_primary_commands[1] = VK_NULL_HANDLE;

	VkCommandBufferAllocateInfo cmdBufInfo = { VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO };
	cmdBufInfo.commandBufferCount = 2;
	cmdBufInfo.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
	cmdBufInfo.commandPool = m_primary_buffer_cmd_pool;



	VKA_CHECK_ERROR(vkAllocateCommandBuffers(device->getVKDevice(), &cmdBufInfo, m_primary_commands), "Could not allocate primary command buffers.\n");
	VKA_CHECK_ERROR(vkAllocateCommandBuffers(device->getVKDevice(), &cmdBufInfo, m_update_commands), "Could not allocate primary command buffers.\n");

	m_current_buffer_index = 0;

}
Example #11
0
void ParallelACOPTVEstimator::Loop() {
    Random rd;
    int i, j, k, h, next, err = 0;
    float tau, delta_tau, l, Lk, bestLk = INT_MAX, lbestLk;
    //final result
    int *rf0, *rf1, *lrf0, *lrf1, in = 1;

    int np = this->num_particles_;
    int na = this->num_ants_;
    int nl = this->num_loops_;

    HostVector<int, int> initPos(na);

    cl::Kernel* kernel = DeviceManager::Instance().FindKernel(
                             "ships.video.aco_ptv.one_step");
    cl::Kernel* kernel1 = DeviceManager::Instance().FindKernel(
                              "ships.video.aco_ptv.update");
    cl::Kernel* kernel2 = DeviceManager::Instance().FindKernel(
                              "ships.video.aco_ptv.update_rho");

    if (kernel == NULL)
        throw InvalidKernelException();
    if (kernel1 == NULL)
        throw InvalidKernelException();
    if(kernel2 == NULL)
        throw InvalidKernelException();

    int gx = this->num_particles_;
    int	gy =(this->num_particles_ * this->num_ants_) <= this->num_threads_ ? this->num_ants_ : this->num_threads_ / this->num_particles_;

    int lx = gx / this->num_blocks_;
    int ly = gy;

    cl::NDRange global(gx, gy);
    cl::NDRange local(lx, ly);

    this->tau_->GetArray().UnMap();
    //Lk.GetArray().UnMap();
    this->N_->GetArray().UnMap();
    this->f0_->GetArray().UnMap();
    this->f1_->GetArray().UnMap();

    for (i = 0; i < nl; i++) { //for nl number of loops.
        //rd.SRand();

        //if (this->cluster_size_ < this->cluster_max_)
        //	this->cluster_size_++;

        Vector<int, int> Tk0(np * na);
        Vector<int, int> Tk1(np * na);
        Vector<float, float> Lk(na);

        //generate random init positions.
        rd.NextN(initPos.GetArray().GetData(), na, 0, np, false);

        //init start positions for each ant.
        for (j = 0; j < na; j++) {
            Lk.Set(2, j);
            for (k = 0; k < np; k++) {
                Tk0.Set((k + this->num_particles_ - initPos.Get(j))
                        % this->num_particles_, j * np + k);
                Tk1.Set(0, j * np + k);
            }
        }

        //LOG4CXX_INFO(Sp::video_logger,Lk.ToString());
        this->Init(this->N_,"init_bufferi",1,this->num_particles_,this->num_ants_);
        Lk.GetArray().UnMap();
        //initPos.GetArray().UnMap();
        Tk0.GetArray().UnMap();
        Tk1.GetArray().UnMap();

        {   //run one_step kernel
            err = kernel->setArg(0,
                                 this->cf0f1_->GetArray().GetMemoryModel().GetImage2D());
            if (err != CL_SUCCESS)
                LOG4CXX_ERROR(video_logger,"error in setting kernel arg 0: "<<err);
            err
                = kernel->setArg(
                      1,
                      this->clusters01_->GetArray().GetMemoryModel().GetImage2D());
            if (err != CL_SUCCESS)
                LOG4CXX_ERROR(video_logger,"error in setting kernel arg 1: "<<err);
            err = kernel->setArg(2,
                                 this->tau_->GetArray().GetMemoryModel().GetBuffer());
            if (err != CL_SUCCESS)
                LOG4CXX_ERROR(video_logger,"error in setting kernel arg 2: "<<err);
            err = kernel->setArg(3, Lk.GetArray().GetMemoryModel().GetBuffer());
            if (err != CL_SUCCESS)
                LOG4CXX_ERROR(video_logger,"error in setting kernel arg 3: "<<err);
            err
                = kernel->setArg(4,
                                 Tk0.GetArray().GetMemoryModel().GetBuffer());
            if (err != CL_SUCCESS)
                LOG4CXX_ERROR(video_logger,"error in setting kernel arg 4: "<<err);
            err
                = kernel->setArg(5,
                                 Tk1.GetArray().GetMemoryModel().GetBuffer());
            if (err != CL_SUCCESS)
                LOG4CXX_ERROR(video_logger,"error in setting kernel arg 5: "<<err);
            err = kernel->setArg(6,
                                 this->N_->GetArray().GetMemoryModel().GetBuffer());
            if (err != CL_SUCCESS)
                LOG4CXX_ERROR(video_logger,"error in setting kernel arg 6: "<<err);
            err = kernel->setArg(7, this->num_particles_);
            if (err != CL_SUCCESS)
                LOG4CXX_ERROR(video_logger,"error in setting kernel arg 7: "<<err);
            err = kernel->setArg(8, this->num_ants_);
            if (err != CL_SUCCESS)
                LOG4CXX_ERROR(video_logger,"error in setting kernel arg 8: "<<err);
            err = kernel->setArg(9, this->cluster01_max_);
            if (err != CL_SUCCESS)
                LOG4CXX_ERROR(video_logger,"error in setting kernel arg 9: "<<err);
            err = kernel->setArg(10, this->cluster_max_);
            if (err != CL_SUCCESS)
                LOG4CXX_ERROR(video_logger,"error in setting kernel arg 10: "<<err);
            err = kernel->setArg(11, this->cluster_size_);
            if (err != CL_SUCCESS)
                LOG4CXX_ERROR(video_logger,"error in setting kernel arg 11: "<<err);

            err = this->queue_.enqueueNDRangeKernel(*kernel, cl::NullRange,
                                                    global, local);
            if (err != CL_SUCCESS)
                LOG4CXX_ERROR(Sp::video_logger, "error in running kernel:"<<err);

            this->queue_.finish();

        }
        {   //update tau matrix

            err = kernel2->setArg(0,
                                  this->tau_->GetArray().GetMemoryModel().GetBuffer());
            if (err != CL_SUCCESS)
                LOG4CXX_ERROR(video_logger,"error in setting kernel<2> arg 0: "<<err);
            err = kernel2->setArg(1, this->num_particles_);
            if (err != CL_SUCCESS)
                LOG4CXX_ERROR(video_logger,"error in setting kernel<2> arg 1: "<<err);

            err = this->queue_.enqueueNDRangeKernel(*kernel2, cl::NullRange,
                                                    cl::NDRange(this->num_particles_, this->num_threads_/ this->num_particles_),
                                                    cl::NDRange(this->num_particles_ / this->num_blocks_, this->num_threads_ / this->num_particles_));
            if(err!=CL_SUCCESS)
            {
                LOG4CXX_ERROR(Sp::video_logger,"an error occurred when running update_rho kernel");
                return;
            }
            this->queue_.finish();

        }
        {   //run update kernel

            err = kernel1->setArg(0,
                                  this->tau_->GetArray().GetMemoryModel().GetBuffer());
            if (err != CL_SUCCESS)
                LOG4CXX_ERROR(video_logger,"error in setting kernel<1> arg 0: "<<err);
            err
                = kernel1->setArg(1,
                                  Lk.GetArray().GetMemoryModel().GetBuffer());
            if (err != CL_SUCCESS)
                LOG4CXX_ERROR(video_logger,"error in setting kernel<1> arg 1: "<<err);
            err = kernel1->setArg(2,
                                  Tk0.GetArray().GetMemoryModel().GetBuffer());
            if (err != CL_SUCCESS)
                LOG4CXX_ERROR(video_logger,"error in setting kernel<1> arg 2: "<<err);
            err = kernel1->setArg(3,
                                  Tk1.GetArray().GetMemoryModel().GetBuffer());
            if (err != CL_SUCCESS)
                LOG4CXX_ERROR(video_logger,"error in setting kernel<1> arg 3: "<<err);
            err = kernel1->setArg(4, this->num_ants_);
            if (err != CL_SUCCESS)
                LOG4CXX_ERROR(video_logger,"error in setting kernel<1> arg 4: "<<err);
            err = kernel1->setArg(5, this->num_particles_);
            if (err != CL_SUCCESS)
                LOG4CXX_ERROR(video_logger,"error in setting kernel<1> arg 5: "<<err);

            err = this->queue_.enqueueNDRangeKernel(*kernel1, cl::NullRange,
                                                    global, local);

            this->queue_.finish();

        }

        if (i == (nl - 1)) {

            Tk0.GetArray().Map();
            Tk1.GetArray().Map();
            Lk.GetArray().Map();

            //LOG4CXX_INFO(Sp::video_logger,"Lk: \n"<<Lk.ToString());
            //walk through the Lk array to find the smallest total distance.
            this->result_ = new HostMatrix<int, int> (2, np);
            bestLk = INT_MAX;
            int ibestLk;

            for (j = 0; j < na; j++) {
                if (bestLk > Lk.Get(j)) {
                    bestLk = Lk.Get(j);
                    ibestLk = j;
                }
            }
            for (j = 0; j < np; j++) {
                this->result_->Set(Tk0.Get(ibestLk * np + j), j, 0);//(rf0[i], i, 0);
                this->result_->Set(Tk1.Get(ibestLk * np + j), j, 1);//(rf1[i], i, 1);
            }
        }
    }

}
Example #12
0
void block::init(){
  initTypeAndState();
  initPos();
}
Example #13
0
void Particles::initFbo(int w,int h){
    
    // Seting the textures where the information ( position and velocity ) will be
//    textureResx*textureResy = numParticles;
//    textureResx/textureResy = scrw/scrh;
 
    textureRes2.x = (int)sqrt((float)numParticles* w/ h);
    textureRes2.y = (int)numParticles/textureRes2.x;
    
    textureRes = (int)sqrt((float)numParticles);
    numParticles = textureRes* textureRes;
    
    // Load this information in to the FBO´s texture
if(!noReset){
        posPingPong.allocate(textureRes, textureRes,GL_RGB32F);

    
    // Load this information in to the FBO´s texture
    velPingPong.allocate(textureRes, textureRes,GL_RGB32F);
    origins.allocate(textureRes, textureRes,GL_RGB32F);
    
    
    // 1. Making arrays of float pixels with position information
    float * pos = new float[numParticles*3];
    for (int x = 0; x < textureRes; x++){
        for (int y = 0; y < textureRes; y++){
            int i = textureRes * y + x;
            
            pos[i*3 + 0] = x*1.0/textureRes;
            pos[i*3 + 1] = y*1.0/(textureRes);
            pos[i*3 + 2] = 0.5;
        }
    }
    

    posPingPong.src->getTextureReference().loadData(pos, textureRes, textureRes, GL_RGB);
    posPingPong.dst->getTextureReference().loadData(pos, textureRes, textureRes, GL_RGB);
       
    
    origins.getTextureReference().loadData(pos, textureRes, textureRes, GL_RGB);
    
    delete [] pos;    // Delete the array
    
    
    
    
    
    // 2. Making arrays of float pixels with velocity information and the load it to a texture
    float * vel = new float[numParticles*3];
    for (int i = 0; i < numParticles; i++){
        vel[i*3 + 0] = 0.0;
        vel[i*3 + 1] = 0.0;
        vel[i*3 + 2] = 0.0;//i*1.0/numParticles ;
    }

    velPingPong.src->getTextureReference().loadData(vel, textureRes, textureRes, GL_RGB);
    velPingPong.dst->getTextureReference().loadData(vel, textureRes, textureRes, GL_RGB);
    delete [] vel; // Delete the array
    

    }
    else{
        
            posPingPong.src->allocate(textureRes, textureRes,GL_RGB32F);
            posPingPong.src->begin();
            posPingPong.dst->draw(0,0);
            posPingPong.src->end();
            posPingPong.dst->allocate(textureRes,textureRes,GL_RGB32F);
       
    }
    partVbo.clear();
    partVbo.disableColors();
    partVbo.disableNormals();
    partVbo.disableTexCoords();
    partVbo.disableIndices();
    vector<ofVec3f> initPos (numParticles);
    for(int x = 0 ; x < textureRes ; x++){
        for(int y = 0 ; y < textureRes ; y++){
            initPos[x*textureRes+y] = ofVec3f(x,y,0);
        }
    }
    partVbo.setVertexData(&initPos[0],numParticles,GL_STATIC_DRAW);

 
}
Example #14
0
int main(int argc, char ** argv)
{
char *domain=0, *chassis=0, *nodestr=0, *service=0;
char *termcmd=0, *cards=0, *termtype=0;
int port=0, sock, printit=0;

    if(!argv[1] || argv[1][0]=='-') usage();

    if(argc==4) {
        domain=argv[1];
        nodestr=argv[2];
        service=argv[3];
    }
    else if(argc==3) {
    
        domain=argv[1];
        service=argv[2];
    }
    else if(argc==2) {
    
        domain=argv[1];
    
    }
    else usage();
    
    if(strlen(argv[0]) >= INFOSIZE
        && !strcmp(argv[0]+strlen(argv[0])-INFOSIZE,INFONAME)) 
            printit=1;
        
    // look for the last non-numeric character in the chassis name
    {
    char *p=domain+strlen(domain)-1;
    
        while(p>domain) {
            if(isdigit(*p)) {
                p--;
                continue;
            }
            chassis=strdup(p+1);
            *(p+1)='\0';
            break;
        }
    }
    
    if((nodestr || service) && !chassis) usage();
    
    if(!(termcmd=getenv("TERMCMD"))) termcmd="gnome-terminal";
    cards=getenv("CARDS");
    if(service) termtype=service;
    else if(!(termtype=getenv("TERMTYPE"))) termtype="telnet";
    
    // open the domains file and find this domain
    port=listDomains(domain);
    
    // open a connection to the local pfd server for this domain
    {
    int on=1;
        if((sock=socket(AF_INET, SOCK_STREAM, 0)) >= 0) {
            struct sockaddr_in addr;
            addr.sin_addr.s_addr=INADDR_ANY;
            addr.sin_family=AF_INET;
            addr.sin_port=htons(port);
            
            setsockopt(sock, SOL_SOCKET, SO_REUSEADDR, &on, sizeof on);

            if(connect(sock, (struct sockaddr *) &addr, sizeof(addr)))
                dbg (0,1,1,"Could not connect to local PFD server on port %d\n", port);
        }
        else dbg(0,1,1,"Could not open socket");
    }
    
    // write the command
    {
    FILE *fsock=fdopen(sock, "w");
    
        if(!chassis[0]) chassis="0";
        if(service) fprintf(fsock, "a %s %s\n", chassis, service);
        else fprintf(fsock, "a %s\n", chassis);
        fflush(fsock);
        // read the reponce and print it
        {
            #define MAXBYTES (1024*1024)
            char *buf=(char*)calloc(1, MAXBYTES+1), *p;
            int n, total=0, retries=1, nwins=0, ny, nx, nxc, nyc;
            char status[10];
            char ip[40], pstr[20], svc[20], domain[20], inst[40];

            fcntl(sock, F_SETFL, O_NONBLOCK);

            while(total < MAXBYTES) {
            
                if((n=read(sock, buf+total, MAXBYTES-total))<0) {
                    if(errno==EAGAIN) {
                        if(retries--) {
                            usleep(100);
                            continue;
                        } else break;
                    }
                    dbg(0,1,1,"Read error");
                }
                total += n;
            }
            dbg(1,0,0, "Got answer '%s'\n", buf);
            // replace all '\n' by '\0'
            for(n=0;n<total;n++) if(buf[n]=='\n') buf[n]='\0';
            
            // count number of windows
            for(p=buf; *p; p+=strlen(p)+1) {

                if(sscanf(p, "%10s %40s %20s %20s %20s %40s\n",
                    status, ip, pstr, svc, domain, inst)==6){ 

                    if(strcmp(status, "ok")) dbg(0,0,1,"Error returned by server\n");
                    if(nodestr && strcmp(inst, nodestr)) continue;
                    // check card match
                    if(cards && !strstr(cards, inst)) continue;
                    // check service match
                    if(strcmp(termtype, svc)) continue;
                    nwins++;
                }
            }
            if(!nwins) {
            
                dbg(0,0,1,"No match found for node (%s) cards (%s) type (%s)\n",
                    nodestr?nodestr:"all",
                    cards?cards:"all",
                    termtype); 
            }
            
            
            // init position and size
            if(!printit) {
                initPos(nwins, &ny, &nx);
                nxc=(nx-10)/8;
                nyc=(ny-10)/16;
            }

            for(p=buf; *p; p+=strlen(p)+1) {

                if(sscanf(p, "%10s %40s %20s %20s %20s %40s\n",
                    status, ip, pstr, svc, domain, inst)==6){ 

                    if(strcmp(status, "ok")) dbg(0,0,1,"Error returned by server\n");
                    if(nodestr && strcmp(inst, nodestr)) continue;
                    if(printit) {
                        dbg(0,0,0,"%s %s %-12s %-10s %10s\n", ip, pstr, svc, domain, inst);
                    } else {
                        dbg(1,0,0,"%s %s %-12s %-10s %10s\n", ip, pstr, svc, domain, inst);
                        int ypos, xpos;
                        // check card match
                        if(cards && !strstr(cards, inst)) continue;
                        // check service match
                        if(strcmp(termtype, svc)) continue;
                        //
                        // ok. Start term.
                        getPos(&xpos, &ypos);
                        if(!fork()){
                            char cmd[200];
                            snprintf(cmd,sizeof cmd, 
                                "%s --geometry %dx%d+%d+%d --title %s:%s:%s -e 'telnet %s %s' 1>/dev/null 2>&1", 
                                termcmd,
                                nxc,nyc,xpos,ypos,
                                domain, inst, svc,
                                ip, pstr);
                            system(cmd);
                            exit(0);
                        }
                    }
                }
            }
        }
    }
    exit(0);
}
Example #15
0
main(int argc, char *argv[])
{
    Agraph_t **gs;
    Agraph_t **ccs;
    Agraph_t *g;
    Agraph_t *gp;
    char *fname;
    FILE *fp;
    int cnt;
    int i;

    init(argc, argv);
    if (!Files) {
	fprintf(stderr, "No input files given\n");
	exit(1);
    }

    PSinputscale = POINTS_PER_INCH;
    if (doComps) {
	if (verbose)
	    fprintf(stderr, "do Comps\n");
	while (fname = *Files++) {
	    fp = fopen(fname, "r");
	    if (!fp) {
		fprintf(stderr, "Could not open %s\n", fname);
		continue;
	    }
	    g = agread(fp);
	    fclose(fp);
	    if (!g) {
		fprintf(stderr, "Could not read graph\n");
		continue;
	    }
	    printf("%s %d nodes %d edges %sconnected\n",
		   g->name, agnnodes(g), agnedges(g),
		   (isConnected(g) ? "" : "not "));
	    gs = ccomps(g, &cnt, "abc");
	    for (i = 0; i < cnt; i++) {
		gp = gs[i];
		printf(" %s %d nodes %d edges\n", gp->name, agnnodes(gp),
		       agnedges(gp));
	    }
	}
    } else {
	gs = N_GNEW(nFiles, Agraph_t *);
	cnt = 0;
	while (fname = Files[cnt]) {
	    fp = fopen(fname, "r");
	    if (!fp) {
		fprintf(stderr, "Could not open %s\n", fname);
		exit(1);
	    }
	    g = agread(fp);
	    fclose(fp);
	    if (!g) {
		fprintf(stderr, "Could not read graph\n");
		exit(1);
	    }
	    if (!single) {
		graph_init(g);
		ptest_initGraph(g);
	    }
	    initPos(g);
	    /* if (Verbose) dumpG (g); */
	    gs[cnt++] = g;
	}
	if (single) {
	    Agraph_t *root;
	    Agnode_t *n;
	    Agnode_t *np;
	    Agnode_t *tp;
	    Agnode_t *hp;
	    Agedge_t *e;
	    Agedge_t *ep;
	    root = agopen("root", 0);
	    agedgeattr(root, "pos", "");
	    for (i = 0; i < cnt; i++) {
		g = gs[i];
		for (n = agfstnode(g); n; n = agnxtnode(g, n)) {
		    if (agfindnode(root, n->name)) {
			fprintf(stderr,
				"Error: node %s in graph %d (%s) previously added\n",
				n->name, i, Files[i]);
			exit(1);
		    }
		    np = agnode(root, n->name);
		    ND_pos(np)[0] = ND_pos(n)[0];
		    ND_pos(np)[1] = ND_pos(n)[1];
		    ND_coord_i(np).x = ND_coord_i(n).x;
		    ND_coord_i(np).y = ND_coord_i(n).y;
		}
		for (n = agfstnode(g); n; n = agnxtnode(g, n)) {
		    tp = agfindnode(root, n->name);
		    for (e = agfstout(g, n); e; e = agnxtout(g, e)) {
			hp = agfindnode(root, e->head->name);
			ep = agedge(root, tp, hp);
			ED_spl(ep) = ED_spl(e);
		    }
		}
	    }
	    graph_init(root);
	    ptest_initGraph(root);
	    ccs = ccomps(root, &cnt, 0);
	    packGraphs(cnt, ccs, root, margin, doEdges);
	    if (!doEdges)
		copyPos(root);
	    else
		State = GVSPLINES;
	    attach_attrs(root);
	    for (i = 0; i < cnt; i++) {
		agdelete(root, ccs[i]);
	    }
	    agwrite(root, stdout);
	} else {
	    packGraphs(cnt, gs, 0, margin, doEdges);
	    if (doEdges)
		State = GVSPLINES;
	    for (i = 0; i < cnt; i++) {
		if (!doEdges)
		    copyPos(gs[i]);
		attach_attrs(gs[i]);
		agwrite(gs[i], stdout);
	    }
	}
    }
}
Example #16
0
Player::Player(SDL_Renderer* gRenderer, SDL_Window* gWindow, BallisticEngine* ballisEngine, PlayerInventory* inv)
 : IRenderedElement(), ballisticEngine(ballisEngine), inventory(inv) {

    initPos();

    //initialize animation textures
    gAnimRight = new LTexture(gRenderer, true);
    gAnimLeft = new LTexture(gRenderer, true);
    gJumpTextureRight = new LTexture(gRenderer, true);
    gJumpTextureLeft = new LTexture(gRenderer, true);
    gFireTextureRight = new LTexture(gRenderer, true);
    gFireTextureLeft = new LTexture(gRenderer, true);
    gAnimDeath = new LTexture(gRenderer, true);

    SDL_Color colorK = { 0xFF, 0xFF, 0xFF };

    //Load sprite sheet texture
    if( !gAnimRight->loadFromFile( "img/playerAnimRight.png", colorK) ){
        printf( "Failed to load sprite sheet texture!\n" );
    }

    if( !gAnimLeft->loadFromFile( "img/playerAnimLeft.png", colorK) ){
        printf( "Failed to load sprite sheet texture!\n" );
    }

    //Set top left sprite
    gSpriteClips[ 0 ].x = 0;
    gSpriteClips[ 0 ].y = 0;
    gSpriteClips[ 0 ].w = 30;
    gSpriteClips[ 0 ].h = 55;

    //Set top right sprite
    gSpriteClips[ 1 ].x = 30;
    gSpriteClips[ 1 ].y =  0;
    gSpriteClips[ 1 ].w = 30;
    gSpriteClips[ 1 ].h = 55;

    //Set bottom left sprite
    gSpriteClips[ 2 ].x = 60;
    gSpriteClips[ 2 ].y = 0;
    gSpriteClips[ 2 ].w = 30;
    gSpriteClips[ 2 ].h = 55;

    //Set bottom right sprite
    gSpriteClips[ 3 ].x = 90;
    gSpriteClips[ 3 ].y = 0;
    gSpriteClips[ 3 ].w = 30;
    gSpriteClips[ 3 ].h = 55;

    if( !gJumpTextureRight->loadFromFile( "img/playerJumpRight.png", colorK ) ){
        printf( "Failed to load sprite sheet texture: playerJumpRight!\n" );
    }
    if( !gJumpTextureLeft->loadFromFile( "img/playerJumpLeft.png", colorK ) ){
        printf( "Failed to load sprite sheet texture: playerJumpLeft!\n" );
    }
    if( !gFireTextureRight->loadFromFile( "img/playerFireRight.png", colorK ) ){
        printf( "Failed to load sprite sheet texture: playerFireRight!\n" );
    }
    if( !gFireTextureLeft->loadFromFile( "img/playerFireLeft.png", colorK ) ){
        printf( "Failed to load sprite sheet texture: playerFireLeft!\n" );
    }
    if( !gAnimDeath->loadFromFile( "img/playerDeathAnim.png", colorK ) ){
        printf( "Failed to load sprite sheet texture: playerDeathAnim!\n" );
    }
}