Exemplo n.º 1
0
void spawn_monster() {
    auto monster = spawn().lock();

    monster->act = monster_act;

    while(1) {
        AxialPosition p;

        int x = rnd(0, (int)game.map->width);
        int y = rnd(0, (int)game.map->height);

        game.map->from_data_coord(x, y, p);

        if(game.map->empty(p)) {
            monster->position = p;
            break;
        }
    }

    monster->energy_gain = rnd(100, 300);

    add_message("Added monster with %i energy gain", monster->energy_gain);
}
Exemplo n.º 2
0
void Emitter::update(float dt)
{
    accumulated_time_ += dt;
    while (accumulated_time_ >= spawn_rate_)
    {
        accumulated_time_ -= spawn_rate_;
        instances_.push_back(spawn());
    }

    size_t number = instances_.size();
    for (size_t i = 0; i < number; i++)
    {
        instances_[i]->update(dt);
        if (instances_[i]->done())
        {
            delete instances_[i];
            std::swap(instances_[i],instances_[number-1]);
            number--;
        }
    }

    instances_.erase(instances_.begin() + number,instances_.end());
}
Exemplo n.º 3
0
void
runorraise(const Arg *arg) {
    const char **app = arg->v;
    Arg a = { .ui = ~0 };
    Monitor *mon;
    Client *c;
    XClassHint hint = { NULL, NULL };

/* Tries to find the client */
  for (mon = mons; mon; mon = mon->next) {
    for (c = mon->clients; c; c = c->next) {
      XGetClassHint(dpy, c->win, &hint);
      if (hint.res_class && strcmp(app[2], hint.res_class) == 0) {
        a.ui = c->tags;
        view(&a);
        focus(c);
        return;
      }
    }
  }
  /* Client not found: spawn it */
  spawn(arg);
} 
Exemplo n.º 4
0
Arquivo: misc.c Projeto: deurk/ktx
void make_bubbles()
{
	gedict_t       *bubble;

	bubble = spawn();
	setmodel( bubble, "progs/s_bubble.spr" );
	setorigin( bubble, PASSVEC3( self->s.v.origin ) );
	bubble->s.v.movetype = MOVETYPE_NOCLIP;
	bubble->s.v.solid = SOLID_NOT;

	SetVector( bubble->s.v.velocity, 0, 0, 15 );
	bubble->s.v.nextthink = g_globalvars.time + 0.5;
	bubble->think = ( func_t ) bubble_bob;
	bubble->touch = ( func_t ) bubble_remove;
	bubble->classname = "bubble";
	bubble->s.v.frame = 0;
	bubble->cnt = 0;

	setsize( bubble, -8, -8, -8, 8, 8, 8 );

	self->s.v.nextthink = g_globalvars.time + g_random() + 0.5;
	self->think = ( func_t ) make_bubbles;
}
Exemplo n.º 5
0
void spawn_tdeath( vec3_t org, gedict_t * death_owner )
{

	gedict_t       *death;

	death = spawn();
	death->s.v.classname = "teledeath";
	death->s.v.movetype = MOVETYPE_NONE;
	death->s.v.solid = SOLID_TRIGGER;
	SetVector( death->s.v.angles, 0, 0, 0 );

	setsize( death, death_owner->s.v.mins[0] - 1, death_owner->s.v.mins[1] - 1,
		      death_owner->s.v.mins[2] - 1, death_owner->s.v.maxs[0] + 1,
		      death_owner->s.v.maxs[1] + 1, death_owner->s.v.maxs[2] + 1 );
	setorigin( death, PASSVEC3( org ) );

	death->s.v.touch = ( func_t ) tdeath_touch;
	death->s.v.nextthink = g_globalvars.time + 0.2;
	death->s.v.think = ( func_t ) SUB_Remove;
	death->s.v.owner = EDICT_TO_PROG( death_owner );

	g_globalvars.force_retouch = 2;	// make sure even still objects get hit
}
Exemplo n.º 6
0
/*
 * This function simply stops the service p.
 * @param s A Service_T object
 * @param flag TRUE if the monitoring should be disabled or FALSE if monitoring should continue (when stop is part of restart)
 * @return TRUE if the service was stopped otherwise FALSE
 */
static int do_stop(Service_T s, int flag) {
        int rv = TRUE;
        ASSERT(s);
        if (s->depend_visited)
                return rv;
        s->depend_visited = TRUE;
        if (s->stop) {
                if (s->type != TYPE_PROCESS || Util_isProcessRunning(s, FALSE)) {
                        LogInfo("'%s' stop: %s\n", s->name, s->stop->arg[0]);
                        spawn(s, s->stop, NULL);
                        if (s->type == TYPE_PROCESS && (wait_process(s, Process_Stopped) != Process_Stopped)) // Only wait for process service types stop
                                rv = FALSE;
                }
        } else {
                LogDebug("'%s' stop skipped -- method not defined\n", s->name);
        }
        if (flag)
                Util_monitorUnset(s);
        else
                Util_resetInfo(s);
        
        return rv;
}
void
agent_spawn (bool opt_verbose)
{
  // start agent if needed (sfsagent -c)
  if (!isagentrunning ()) {
    if (opt_verbose)
      warn << "No existing agent found; spawning a new one...\n";
    str sa = find_program ("sfsagent");
    vec<char *> av;

    av.push_back (const_cast<char *> (sa.cstr ()));
    av.push_back ("-c");
    av.push_back (NULL);
    pid_t pid = spawn (av[0], av.base ());
    if (waitpid (pid, NULL, 0) < 0)
      fatal << "Could not spawn a new SFS agent: " <<
	strerror (errno) << "\n";
  }
  else {
    if (opt_verbose)
      warn << "Contacting existing agent...\n";
  }
}
Exemplo n.º 8
0
Arquivo: wmfs.c Projeto: wavebeem/wmfs
/** WMFS main loop.
 */
static void
mainloop(void)
{
     XEvent ev;
     pthread_t th_status;

     if (estatus && conf.status_timing == 0)
          conf.status_pid = spawn(conf.status_path);
     else if (estatus && pthread_create(&th_status, NULL, thread_status, NULL) != 0) {
          warnx("pthread_create");
          estatus = False;
     }

     while (!exiting && !XNextEvent(dpy, &ev)) {
          getevent(ev);
          wait_childs_and_status();
     }

     if (estatus)
          pthread_join(th_status, NULL);

     return;
}
Exemplo n.º 9
0
// spawn the actual holo
void HoloDood ( )
{
	gedict_t *holo;
	vec3_t vtemp;

	sound( self, 1, "weapons/railgr1a.wav", 0.6, 1 );
	holo = spawn(  );
	holo->s.v.owner = EDICT_TO_PROG( self );
	vtemp[0] =
		self->s.v.origin[0];
	vtemp[1] =
		self->s.v.origin[1];
	vtemp[2] =
		self->s.v.origin[2] + 24;
	setorigin( holo, PASSVEC3( vtemp ) );
	holo->s.v.angles[1] = self->s.v.angles[1];
	holo->s.v.angles[0] = self->s.v.angles[0];
	holo->s.v.skin = self->s.v.skin;
	holo->s.v.frame = self->s.v.frame;
	holo->s.v.colormap = self->s.v.colormap;
	holo->s.v.flags = 256;
	holo->s.v.solid = SOLID_TRIGGER;
	holo->s.v.effects = EF_DIMLIGHT;
	holo->s.v.movetype = MOVETYPE_TOSS;
	setmodel( holo, "progs/player.mdl" );
	setsize( holo, -16, -16, -24, 16, 16, 32 );
	holo->s.v.classname = "holo";
	holo->playerclass = 0;
	holo->s.v.nextthink = g_globalvars.time + 1;
	holo->s.v.think = ( func_t ) HoloHumm;
	trap_WriteByte( MSG_MULTICAST, SVC_TEMPENTITY );
	trap_WriteByte( MSG_MULTICAST, 11 );
	trap_WriteCoord( MSG_MULTICAST, self->s.v.origin[0] );
	trap_WriteCoord( MSG_MULTICAST, self->s.v.origin[1] );
	trap_WriteCoord( MSG_MULTICAST, self->s.v.origin[2] );
	trap_multicast( PASSVEC3( self->s.v.origin ), 1 );
}
Exemplo n.º 10
0
int
run_main (int, ACE_TCHAR *[])
{
  ACE_START_TEST (ACE_TEXT ("MM_Shared_Memory_Test"));

#if !defined (ACE_LACKS_MMAP) && !defined (ACE_DISABLE_MKTEMP)
  ACE_TCHAR temp_file[MAXPATHLEN + 1];

  // Get the temporary directory,
  // The - 24 is for the filename, mm_shared_mem_testXXXXXX
  if (ACE::get_temp_dir (temp_file, MAXPATHLEN - 24) == -1)
    ACE_ERROR_RETURN ((LM_ERROR, ACE_TEXT ("Temporary path too long\n")), -1);

  // Add the filename to the end
  ACE_OS::strcat (temp_file, ACE_TEXT ("mm_shared_mem_testXXXXXX"));

  // Store in the global variable.
  shm_key = temp_file;

  if (ACE_OS::mktemp (shm_key) == 0
      || (ACE_OS::unlink (shm_key) == -1
          && errno == EPERM))
    ACE_ERROR_RETURN ((LM_ERROR,
                       ACE_TEXT ("(%P|%t) %p\n"),
                       shm_key),
                      1);
  spawn ();

#else /* !ACE_LACKS_MMAP */
  ACE_ERROR ((LM_INFO,
              ACE_TEXT ("mmap and mktemp")
              ACE_TEXT ("are required for this test\n")));
#endif /* !ACE_LACKS_MMAP */

  ACE_END_TEST;
  return 0;
}
Exemplo n.º 11
0
////////////////
// GlobalParams:
// time
// self
// params
///////////////
void SpectatorConnect()
{
	gedict_t *p;
	int diff = (int)(PROG_TO_EDICT(self->s.v.goalentity) - world);

	if ( !SpecCanConnect( self ) )
	{
		stuffcmd(self, "disconnect\n"); // FIXME: stupid way
		return;
	}

	SpecDecodeLevelParms();

	self->ct = ctSpec;
	self->s.v.classname = "spectator"; // Added this in for kick code
	self->k_accepted = 1; // spectator has no restriction to connect

	for ( p = world; (p = ( match_in_progress == 2 && !cvar("k_ann") ) ? find_spc( p ) : find_client( p )); )
		if ( p != self )  // does't show msg for self
			G_sprint( p, PRINT_HIGH, "Spectator %s entered the game\n", self->s.v.netname  );

	if ( diff < 0 || diff >= MAX_EDICTS ) // something wrong happen - fixing
		self->s.v.goalentity = EDICT_TO_PROG( world );

	VIP_ShowRights( self );
	CheckRate(self, "");

	if ( match_in_progress != 2 ) {
		self->wizard = spawn();
		self->wizard->s.v.classname = "spectator_wizard";
		self->wizard->s.v.think = ( func_t ) wizard_think;
		self->wizard->s.v.nextthink = g_globalvars.time + 0.1;
	}

	// Wait until you do stuffing
	MakeMOTD();
}
/**
 * Run a script. argv[2] is already NULL.
 */
static int run(char *argv[3], struct in_addr *ip)
{
	int status;
	char *addr = addr; /* for gcc */
	const char *fmt = "%s %s %s" + 3;

	VDBG("%s run %s %s\n", intf, argv[0], argv[1]);

	if (ip) {
		addr = inet_ntoa(*ip);
		setenv("ip", addr, 1);
		fmt -= 3;
	}
	bb_info_msg(fmt, argv[1], intf, addr);

	status = wait4pid(spawn(argv));
	if (status < 0) {
		bb_perror_msg("%s %s %s" + 3, argv[1], intf);
		return -errno;
	}
	if (status != 0)
		bb_error_msg("script %s %s failed, exitcode=%d", argv[0], argv[1], status);
	return status;
}
Exemplo n.º 13
0
void CreatureManager::loadSpawns(const std::string& fileName)
{
    if(!isLoaded()) {
        g_logger.warning("creatures aren't loaded yet to load spawns.");
        return;
    }

    if(m_spawnLoaded) {
        g_logger.warning("attempt to reload spawns.");
        return;
    }

    try {
        TiXmlDocument doc;
        doc.Parse(g_resources.readFileContents(fileName).c_str());
        if(doc.Error())
            stdext::throw_exception(stdext::format("cannot load spawns xml file '%s: '%s'", fileName, doc.ErrorDesc()));

        TiXmlElement* root = doc.FirstChildElement();
        if(!root || root->ValueStr() != "spawns")
            stdext::throw_exception("malformed spawns file");

        for(TiXmlElement* node = root->FirstChildElement(); node; node = node->NextSiblingElement()) {
            if(node->ValueTStr() != "spawn")
                stdext::throw_exception("invalid spawn node");

            SpawnPtr spawn(new Spawn);
            spawn->load(node);
            m_spawns.insert(std::make_pair(spawn->getCenterPos(), spawn));
        }
        doc.Clear();
        m_spawnLoaded = true;
    } catch(std::exception& e) {
        g_logger.error(stdext::format("Failed to load '%s': %s", fileName, e.what()));
    }
}
Exemplo n.º 14
0
Arquivo: player.c Projeto: deurk/ktx
gedict_t *ThrowGib( char *gibname, float dm )
{
	gedict_t       *newent;
	int			    k_short_gib = cvar( "k_short_gib" ); // if set - remove faster

	newent = spawn();
	VectorCopy( self->s.v.origin, newent->s.v.origin );
	setmodel( newent, gibname );
	setsize( newent, 0, 0, 0, 0, 0, 0 );
	VelocityForDamage( dm, newent->s.v.velocity );
	newent->s.v.movetype = MOVETYPE_BOUNCE;
	newent->isMissile = true;
	newent->s.v.solid = SOLID_NOT;
	newent->s.v.avelocity[0] = g_random() * 600;
	newent->s.v.avelocity[1] = g_random() * 600;
	newent->s.v.avelocity[2] = g_random() * 600;
	newent->think = ( func_t ) SUB_Remove;
	newent->s.v.ltime = g_globalvars.time;
	newent->s.v.nextthink = g_globalvars.time + ( k_short_gib ? 2 : ( 10 + g_random() * 10 ) );
	newent->s.v.frame = 0;
	newent->s.v.flags = 0;

	return newent;
}
Exemplo n.º 15
0
int main (int argc, char *argv[]){
	char* arg_list[10] = {};
	/*no argmuments*/
	if(argc <= 1){
	  childParent();
   	  return 0;
	}else if(argc == 2){/*one argument*/
	  spawnOne(argv[1]);
	}else{/*multiple arguments*/
	  int i = 0;
	  while(i<argc){
	    if(i+1==argc){
	      arg_list[i] = NULL;
	    }
	    else{
	      arg_list[i] = argv[i+1];
	    }
	    i++;
	  }
	  spawn (argv[1], arg_list);
	}
	printf("done with main program\n");
	return 0;
}
Exemplo n.º 16
0
/* Call a script with a par file and env vars */
void FAST_FUNC udhcp_run_script(struct dhcp_packet *packet, const char *name)
{
	char **envp, **curr;
	char *argv[3];

	if (client_config.script == NULL)
		return;

	envp = fill_envp(packet);

	/* call script */
	log1("Executing %s", client_config.script);
	argv[0] = (char*) client_config.script;
	argv[1] = (char*) name;
	argv[2] = NULL;
	wait4pid(spawn(argv));

	for (curr = envp; *curr; curr++) {
		log2(" %s", *curr);
		bb_unsetenv(*curr);
		free(*curr);
	}
	free(envp);
}
Exemplo n.º 17
0
Game::Game()
{
  //  start = new Start();
    scene = new QGraphicsScene();

    player = new Player();
    scene->addItem(player);

  /*  QGraphicsPixmapItem *drum = new QGraphicsPixmapItem();
    drum->setPixmap(QPixmap(":/images/testdrum2.png"));
    drum->setPos(0,143);
    scene->addItem(drum);*/

    player->setFlag(QGraphicsItem::ItemIsFocusable);
    player->setFocus();

    setScene(scene);
    setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
    setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
    setFixedSize(768,557);

    scene->setSceneRect(0,0,768,557);
    scene->setBackgroundBrush(QBrush(QPixmap(":/image/bgg6.png")));

    //create the score
    score = new Score();
    scene->addItem(score);

    QTimer * timer = new QTimer();
    QObject::connect(timer,SIGNAL(timeout()),player,SLOT(spawn()));
    timer->start(1200);

    mytimer = new Mytimer();
    scene->addItem(mytimer);

}
Exemplo n.º 18
0
void SpawnMgr::spawnEntity(ai::Zone& zone, network::messages::NpcType start, network::messages::NpcType end, int maxAmount) {
	const int offset = start + 1;
	int count[end - offset];
	memset(count, 0, sizeof(count));
	zone.execute([start, end, offset, &count] (const ai::AIPtr& ai) {
		const AICharacter& chr = ai::character_cast<AICharacter>(ai->getCharacter());
		const Npc& npc = chr.getNpc();
		const network::messages::NpcType type = npc.npcType();
		if (type <= start || type >= end)
			return;
		const int index = type - offset;
		++count[index];
	});

	const int size = SDL_arraysize(count);
	for (int i = 0; i < size; ++i) {
		if (count[i] >= maxAmount)
			continue;

		const int needToSpawn = maxAmount - count[i];
		network::messages::NpcType type = static_cast<network::messages::NpcType>(offset + i);
		spawn(zone, type, needToSpawn);
	}
}
Exemplo n.º 19
0
void user_k( void ) {
	int i;
	int pid;
	char buf[16];

	write( FD_CONSOLE, "User K running\n", 0 );
	write( FD_SIO, "K", 1 );

	for( i = 0; i < 3 ; ++i ) {
		pid = spawn( user_x );
		if( pid < 0 ) {
			write( FD_CONSOLE, "User K spawn() #", 0 );
			pid = itos10( buf, i );
			write( FD_CONSOLE, buf, pid );
			write( FD_CONSOLE, " failed\n", 0 );
		} else {
			sleep( SECONDS_TO_MS(30) );
			write( FD_SIO, "K", 1 );
		}
	}

	write( FD_CONSOLE, "User K exiting\n", 0 );
	exit();
}
Exemplo n.º 20
0
void user_j( void ) {
	int i;
	int pid;
	char buf[16];

	write( FD_CONSOLE, "User J running\n", 0 );
	write( FD_SIO, "J", 1 );

	for( i = 0; i < N_PROCS * 2 ; ++i ) {
		pid = spawn( user_y );
		if( pid < 0 ) {
			write( FD_SIO, "j", 1 );
			write( FD_CONSOLE, "User J spawn() #", 0 );
			pid = itos10( buf, i );
			write( FD_CONSOLE, buf, pid );
			write( FD_CONSOLE, " failed\n", 0 );
		} else {
			write( FD_SIO, "J", 1 );
		}
	}

	write( FD_CONSOLE, "User J exiting\n", 0 );
	exit();
}
Exemplo n.º 21
0
void GOBall::tick() {
	GameObject::tick();
	
    if (!m_Alive)
        return;

    m_ScoreObject->updateScore(m_Score);

	jump();
	updateVelocity();
	
	// sync the position of the physics and graphics objects
	CPhysicsObject* physicsComponent = (CPhysicsObject*)getComponent(CPhysicsObject::classTypeID());
	b2Body* body = physicsComponent->getBody();
	
	b2Vec2 position = body->GetPosition();
	float32 angle = body->GetAngle();

    if (position.y < -200)
        spawn();

	CGraphicsObject* graphicsComponent = (CGraphicsObject*)getComponent(CGraphicsObject::classTypeID());
	graphicsComponent->setPosition(position.x, position.y, 0.0f);
}
Exemplo n.º 22
0
bool
LiveFile::start(const void * arg)
{
    int ret = 0;

    const char * file = (const char *)arg;

    m_hlslive = new HLSLive();

    if (!m_hlslive->build("E:\\nginx\\nginx-1.9.9\\html\\hls", ///< path
                          "camera",                            ///< output prefix
                          "camera.m3u8",                       ///< index file name
                          "camera/",                           ///< URI prefix
                          10,                                  ///< max segment duration
                          6))                                  ///< max segments
    {
        goto fail;
    }

    ret = ::av_file_map(file, &m_filedata, &m_datasize, 0, NULL);
    if (ret < 0)
    {
        fprintf(stderr, "unable to map input file: %s\n", av_err2str(ret));
        goto fail;
    }

    spawn();

    return true;

fail:

    stop();

    return false;
}
Exemplo n.º 23
0
int main( void ) {
	int i;
	int pid;
	time_t time;

	time = gettime();
	c_printf( "User L running, initial time %u\n", time );
	writech( 'L' );

	for( i = 0; i < 3 ; ++i ) {
		time = gettime();
		pid = spawn( "/USER_X.B" );
		if( pid < 0 ) {
			c_printf( "User L spawn() #%d failed @%08u\n", i, time );
		} else {
			sleep( 0 );
			writech( 'L' );
		}
	}

	time = gettime();
	c_printf( "User L exiting at time %u\n", time );
	exit();
}
Exemplo n.º 24
0
void DropQuad( float timeleft )
{
	gedict_t       *item;

	item = spawn();
	VectorCopy( self->s.v.origin, item->s.v.origin );

	item->s.v.velocity[2] = 300;
	item->s.v.velocity[0] = -100 + ( g_random() * 200 );
	item->s.v.velocity[1] = -100 + ( g_random() * 200 );

	item->s.v.flags = FL_ITEM;
	item->s.v.solid = SOLID_TRIGGER;
	item->s.v.movetype = MOVETYPE_TOSS;
	item->s.v.noise = "items/damage.wav";

	setmodel( item, "progs/quaddama.mdl" );
	setsize( item, -16, -16, -24, 16, 16, 32 );

	item->cnt = g_globalvars.time + timeleft;
	item->s.v.touch = ( func_t ) q_touch;
	item->s.v.nextthink = g_globalvars.time + timeleft;	// remove it with the time left on it
	item->s.v.think = ( func_t ) SUB_Remove;
}
Exemplo n.º 25
0
void forasync3D_flat(void *forasync_arg) {
    forasync3D_t *forasync = (forasync3D_t *) forasync_arg;
    hclib_loop_domain_t loop0 = forasync->loop[0];
    hclib_loop_domain_t loop1 = forasync->loop[1];
    hclib_loop_domain_t loop2 = forasync->loop[2];
    int low0, low1, low2;
    for(low0=loop0.low; low0<loop0.high; low0+=loop0.tile) {
        int high0 = (low0+loop0.tile)>loop0.high?loop0.high:(low0+loop0.tile);
#if DEBUG_FORASYNC
        printf("Scheduling Task Loop1 %d %d\n",low0,high0);
#endif
        for(low1=loop1.low; low1<loop1.high; low1+=loop1.tile) {
            int high1 = (low1+loop1.tile)>loop1.high?loop1.high:(low1+loop1.tile);
#if DEBUG_FORASYNC
            printf("Scheduling Task Loop2 %d %d\n",low1,high1);
#endif
            for(low2=loop2.low; low2<loop2.high; low2+=loop2.tile) {
                int high2 = (low2+loop2.tile)>loop2.high?loop2.high:(low2+loop2.tile);
#if DEBUG_FORASYNC
                printf("Scheduling Task %d %d\n",low2,high2);
#endif
                forasync3D_task_t *new_forasync_task = allocate_forasync3D_task();
                new_forasync_task->forasync_task._fp = forasync3D_runner;
                new_forasync_task->forasync_task.args = &(new_forasync_task->def);
                new_forasync_task->def.base.user = forasync->base.user;
                hclib_loop_domain_t new_loop0 = {low0, high0, loop0.stride, loop0.tile};
                new_forasync_task->def.loop[0] = new_loop0;
                hclib_loop_domain_t new_loop1 = {low1, high1, loop1.stride, loop1.tile};
                new_forasync_task->def.loop[1] = new_loop1;
                hclib_loop_domain_t new_loop2 = {low2, high2, loop2.stride, loop2.tile};
                new_forasync_task->def.loop[2] = new_loop2;
                spawn((hclib_task_t *)new_forasync_task);
            }
        }
    }
}
Exemplo n.º 26
0
void respawn_children() {
	int i, delta = -1;
	time_t now;
	alarm(0);
	if ((now = time(NULL)) == 0) now = 1;
	for(i = 0; i < numcmd; i++) {
		if(inittab[i].pid < 0) {	/* Start jobs */
			if(stopped)
				inittab[i].pid = -1;
			else
				spawn(i);
		}
		/* Check for naughty jobs */
		if (inittab[i].nextrun > now) {
		int d;
			d = inittab[i].nextrun - now;
			if (delta < 0 || d < delta)
				delta = d;
		}
	}
	if (delta > 0) {
		alarm(delta);
	}
}
Exemplo n.º 27
0
void SmokeSource::animate()
{
  float up_scale = Window::delta_time / 2000.0f;
  float side_scale = Window::delta_time / 6000.0f;

  // update velocity
  for (unsigned int i = 0; i < particles; i++)
    velocity_data[i * 3 + 1] += up_scale * -1.0f;

  // update position
  for (unsigned int i = 0; i < particles; i++)
  {
    position_data[i * 3 + 0] += velocity_data[i * 3 + 0] * side_scale;
    position_data[i * 3 + 1] += velocity_data[i * 3 + 1] * side_scale;
    position_data[i * 3 + 2] += velocity_data[i * 3 + 2] * side_scale;
  }

  // kill and respawn particles
  for (unsigned int i = 0; i < particles; i++)
  {
    if (position_data[i * 3 + 1] <= 0.0f)
    {
      if (particles <= desired_particles)
        spawn(i);
      else
      {
        kill(i); // kill and swap with last particle
        i--; // check again on this position, since another particle will be here
      }
    }
  }

  // update data in buffer
  glBindBuffer(GL_ARRAY_BUFFER, position_buffer);
  glBufferSubData(GL_ARRAY_BUFFER, 0, particles * 3 * sizeof(GLfloat), position_data);
}
Exemplo n.º 28
0
int
main(void)
{
	int sig;
	size_t i;

	if (getpid() != 1)
		return 1;
	chdir("/");
	sigfillset(&set);
	sigprocmask(SIG_BLOCK, &set, NULL);
	spawn(rcinitcmd);
	while (1) {
		sigwait(&set, &sig);
		for (i = 0; i < LEN(sigmap); i++) {
			if (sigmap[i].sig == sig) {
				sigmap[i].handler();
				break;
			}
		}
	}
	/* not reachable */
	return 0;
}
Exemplo n.º 29
0
int main( int argc, char **argv)
{
	int my_stdin = 0, my_stdout = 0, my_stderr = 0;
	pid_t child_pid;
	ssize_t bytes_read;
	char *command = { "/usr/bin/echo" };
	char *buffer[1024];
	
	if ( argv[1] )
	{
		spawn( command, argv, NULL, &my_stdin, &my_stdout, &my_stderr, &child_pid );
	}
	
	bytes_read = read( my_stdout, buffer, 1023 );
	
	printf( "read return value: %d\n", bytes_read );
	printf( "%s\n", buffer );
	
	bytes_read = read( my_stderr, buffer, 1023 );
	fprintf( stderr, "Bytes read from stderr: %d\n", bytes_read );
	fprintf( stderr, "%s\n", buffer );
	
	return 0;
}
Exemplo n.º 30
0
    static void test_common()
    {
        try
        {
            std::size_t user_thr_num = 5;
            std::size_t my_actor_size = 10;
            attributes attrs;
            attrs.mixin_num_ = user_thr_num + 1;
            context ctx(attrs);

            mixin_t base = spawn(ctx);
            aid_t base_id = base.get_aid();

            boost::thread_group thrs;
            for (std::size_t i=0; i<user_thr_num; ++i)
            {
                thrs.create_thread(
                    boost::bind(
                        &match_ut::my_thr,
                        boost::ref(ctx), base_id
                    )
                );
            }

            thrs.join_all();

            for (std::size_t i=0; i<my_actor_size; ++i)
            {
                recv(base, 1);
            }
        }
        catch (std::exception& ex)
        {
            std::cerr << ex.what() << std::endl;
        }
    }