示例#1
0
	void build_team_stage_one()
	{
		//initialize the context variables and flags, find relevant tags, set up everything
		init();

		//find out the correct qty of gold and handle gold carryover.
		gold();

		//create a new instance of team and push it to back of resources::teams vector
		new_team();

		assert(t_!=NULL);

		//set team objectives if necessary
		objectives();

		// If the game state specifies additional units that can be recruited by the player, add them.
		previous_recruits();

		//place leader
		leader();

		//prepare units, populate obvious recall lists elements
		prepare_units();

	}
示例#2
0
文件: ggob.cpp 项目: argarak/tw-light
void GobGame::add_gobplayer(Control *control)
{
	STACKTRACE;
	int i = gobplayers;
	gobplayers += 1;
	gobplayer = (GobPlayer**) realloc(gobplayer, sizeof(GobPlayer*) * gobplayers);
	gobplayer[i] = new GobPlayer();
	gobplayer[i]->init(control, new_team());
	add_focus(control, control->channel);
	return;
}
示例#3
0
文件: team.c 项目: 0mp/freebsd
void
gomp_team_start (void (*fn) (void *), void *data, unsigned nthreads,
		 struct gomp_work_share *work_share)
{
  struct gomp_thread_start_data *start_data;
  struct gomp_thread *thr, *nthr;
  struct gomp_team *team;
  bool nested;
  unsigned i, n, old_threads_used = 0;
  pthread_attr_t thread_attr, *attr;

  thr = gomp_thread ();
  nested = thr->ts.team != NULL;

  team = new_team (nthreads, work_share);

  /* Always save the previous state, even if this isn't a nested team.
     In particular, we should save any work share state from an outer
     orphaned work share construct.  */
  team->prev_ts = thr->ts;

  thr->ts.team = team;
  thr->ts.work_share = work_share;
  thr->ts.team_id = 0;
  thr->ts.work_share_generation = 0;
  thr->ts.static_trip = 0;

  if (nthreads == 1)
    return;

  i = 1;

  /* We only allow the reuse of idle threads for non-nested PARALLEL
     regions.  This appears to be implied by the semantics of
     threadprivate variables, but perhaps that's reading too much into
     things.  Certainly it does prevent any locking problems, since
     only the initial program thread will modify gomp_threads.  */
  if (!nested)
    {
      old_threads_used = gomp_threads_used;

      if (nthreads <= old_threads_used)
	n = nthreads;
      else if (old_threads_used == 0)
	{
	  n = 0;
	  gomp_barrier_init (&gomp_threads_dock, nthreads);
	}
      else
	{
	  n = old_threads_used;

	  /* Increase the barrier threshold to make sure all new
	     threads arrive before the team is released.  */
	  gomp_barrier_reinit (&gomp_threads_dock, nthreads);
	}

      /* Not true yet, but soon will be.  We're going to release all
	 threads from the dock, and those that aren't part of the 
	 team will exit.  */
      gomp_threads_used = nthreads;

      /* Release existing idle threads.  */
      for (; i < n; ++i)
	{
	  nthr = gomp_threads[i];
	  nthr->ts.team = team;
	  nthr->ts.work_share = work_share;
	  nthr->ts.team_id = i;
	  nthr->ts.work_share_generation = 0;
	  nthr->ts.static_trip = 0;
	  nthr->fn = fn;
	  nthr->data = data;
	  team->ordered_release[i] = &nthr->release;
	}

      if (i == nthreads)
	goto do_release;

      /* If necessary, expand the size of the gomp_threads array.  It is
	 expected that changes in the number of threads is rare, thus we
	 make no effort to expand gomp_threads_size geometrically.  */
      if (nthreads >= gomp_threads_size)
	{
	  gomp_threads_size = nthreads + 1;
	  gomp_threads
	    = gomp_realloc (gomp_threads,
			    gomp_threads_size
			    * sizeof (struct gomp_thread_data *));
	}
    }

  attr = &gomp_thread_attr;
  if (gomp_cpu_affinity != NULL)
    {
      size_t stacksize;
      pthread_attr_init (&thread_attr);
      pthread_attr_setdetachstate (&thread_attr, PTHREAD_CREATE_DETACHED);
      if (! pthread_attr_getstacksize (&gomp_thread_attr, &stacksize))
	pthread_attr_setstacksize (&thread_attr, stacksize);
      attr = &thread_attr;
    }

  start_data = gomp_alloca (sizeof (struct gomp_thread_start_data)
			    * (nthreads-i));

  /* Launch new threads.  */
  for (; i < nthreads; ++i, ++start_data)
    {
      pthread_t pt;
      int err;

      start_data->ts.team = team;
      start_data->ts.work_share = work_share;
      start_data->ts.team_id = i;
      start_data->ts.work_share_generation = 0;
      start_data->ts.static_trip = 0;
      start_data->fn = fn;
      start_data->fn_data = data;
      start_data->nested = nested;

      if (gomp_cpu_affinity != NULL)
	gomp_init_thread_affinity (attr);

      err = pthread_create (&pt, attr, gomp_thread_start, start_data);
      if (err != 0)
	gomp_fatal ("Thread creation failed: %s", strerror (err));
    }

  if (gomp_cpu_affinity != NULL)
    pthread_attr_destroy (&thread_attr);

 do_release:
  gomp_barrier_wait (nested ? &team->barrier : &gomp_threads_dock);

  /* Decrease the barrier threshold to match the number of threads
     that should arrive back at the end of this team.  The extra
     threads should be exiting.  Note that we arrange for this test
     to never be true for nested teams.  */
  if (nthreads < old_threads_used)
    gomp_barrier_reinit (&gomp_threads_dock, nthreads);
}
示例#4
0
文件: mmain.cpp 项目: Yurand/tw-light
REGISTER_FILE
#include "scp.h"
#include "frame.h"

#include "mmain.h"
#include "mview.h"
#include "mcontrol.h"
#include "other/planet3d.h"
#include "mshppan.h"
#include "mship.h"
#include "mlog.h"
//#include "mnet1.h"
#include "mitems.h"
#include "mfleet.h"

#include "games/gflmelee.h"

#include "other/twconfig.h"

int NormalGame::add_player (Control *c, int team_index, const char *name, const char *fleet_section, const char *fleet_file)
{
	int i = num_players;
	num_players += 1;
	player_control = (Control**) realloc(player_control,   sizeof(Control*)   * num_players);
	player_name    =    (char**) realloc(player_name,      sizeof(char*)      * num_players);
	//	player_panel = (ShipPanel**) realloc(player_panel,     sizeof(ShipPanel*) * num_players);
	player_fleet =     (Fleet**) realloc(player_fleet,     sizeof(Fleet *)    * num_players);
	player_team =    (TeamCode*) realloc(player_team,      sizeof(TeamCode)   * num_players);
	player_control[i] = c;
	add_focus(c, c->channel);
	//	player_panel[i] = NULL;
	player_fleet[i] = new Fleet();
	player_fleet[i]->reset();
	player_name[i] = strdup(name);
	if (team_index >= team_table_size) {
		int i = team_table_size;
		team_table_size = team_index + 1;
		team_table = (TeamCode*) realloc(team_table, sizeof(TeamCode) * team_table_size);
		for (; i < team_table_size; i += 1) {
			if (i) team_table[i] = new_team();
			else team_table[i] = 0;
		}
	}
	if (team_index) player_team[i] = team_table[team_index];
	else player_team[i] = new_team();
	char sect[40];
	sprintf(sect, "Player%d", i+1);
	if (c->channel == channel_none) {
		tw_error("channel_none not allowed here");
		//log_file(fleet_file);
		//::fleet->load(NULL, fleet_section);
	}
	else if (log->get_direction(c->channel) & Log::direction_write) {
		player_fleet[i]->load(fleet_file, fleet_section);
		log_fleet(c->channel, player_fleet[i]);
		c->target_sign_color = ((3+i) % 7) + 1;
	} else {
		log_fleet(c->channel, player_fleet[i]);
	}
	tw_set_config_file(home_ini_full_path("tmp.ini"));
	set_config_string(sect, "Name", name);
	set_config_string(sect, "Type", c->getTypeName());
	set_config_int(sect, "Team", team_index);
	set_config_int(sect, "Channel", c->channel);
	set_config_int(sect, "StartingFleetCost", player_fleet[i]->getCost());
	set_config_int(sect, "StartingFleetSize", player_fleet[i]->getSize());
	player_fleet[i]->save(NULL, sect);
	player_fleet[i]->save("fleets.tmp", sect);
	return i;
}
示例#5
0
文件: ggob.cpp 项目: argarak/tw-light
void GobGame::init(Log *_log)
{
	STACKTRACE;
	int i;
	/*	switch(_log->type) {
	//		case Log::log_net1server:
	//		case Log::log_net1client: {
	//			error("unsupported game/log type");
	//		}
	//		break;
			default: {
			}
			break;
		}/**/
	Game::init(_log);

	log_file(home_ini_full_path("server.ini"));
	max_enemies = get_config_int("Gob", "MaxEnemies", 32);
	int starting_starbucks, starting_buckazoids;
	starting_starbucks = get_config_int("Gob", "StartingStarbucks", 0);
	starting_buckazoids = get_config_int("Gob", "StartingBuckazoids", 0);
	gobenemy = (GobEnemy**) malloc(sizeof(GobEnemy*) * max_enemies);

	size = Vector2(24000, 24000);

	enemy_team = new_team();
	station_team = new_team();

	//	set_resolution(videosystem.width, videosystem.height);

	TW_DATAFILE *tmpdata;
	tmpdata = tw_load_datafile_object(data_full_path("gob.dat").c_str(), "station0sprite");
	if (!tmpdata)
		tw_error( "couldn't find gob.dat#station0sprite");
	stationSprite[0] = new SpaceSprite(tmpdata, 1, SpaceSprite::MASKED | SpaceSprite::MIPMAPED, 64);
	tw_unload_datafile_object(tmpdata);
	stationSprite[0]->permanent_phase_shift(8);

	tmpdata = tw_load_datafile_object(data_full_path("gob.dat").c_str(), "station1sprite");
	if (!tmpdata)
		tw_error ("couldn't find gob.dat#station1sprite");
	stationSprite[1] = new SpaceSprite(tmpdata, 1, SpaceSprite::MASKED | SpaceSprite::MIPMAPED, 64);
	tw_unload_datafile_object(tmpdata);
	stationSprite[1]->permanent_phase_shift(8);

	tmpdata = tw_load_datafile_object(data_full_path("gob.dat").c_str(), "station2sprite");
	if (!tmpdata)
		tw_error ("couldn't find gob.dat#station2sprite");
	stationSprite[2] = new SpaceSprite(tmpdata, 1, SpaceSprite::MASKED | SpaceSprite::MIPMAPED, 64);
	tw_unload_datafile_object(tmpdata);
	stationSprite[2]->permanent_phase_shift(8);

	tmpdata = tw_load_datafile_object(data_full_path("gob.dat").c_str(), "defender");
	if (!tmpdata)
		tw_error ("couldn't find gob.dat#defender");
	defenderSprite = new SpaceSprite(tmpdata, 1, SpaceSprite::MASKED | SpaceSprite::MIPMAPED);
	tw_unload_datafile_object(tmpdata);

	station_pic_name[0] = "gob.dat#station0picture.bmp";
	station_pic_name[1] = "gob.dat#station1picture.bmp";
	station_pic_name[2] = "gob.dat#station2picture.bmp";
	station_build_name[0] = "supbl";
	station_build_name[1] = "orzne";
	station_build_name[2] = "kohma";

	prepare();

	add(new Stars());

	num_planets = 0;
	i = 0;
	add_planet_and_station(meleedata.planetSprite, i, stationSprite[i], station_build_name[i], station_pic_name[i]);
	i = 1;
	add_planet_and_station(meleedata.planetSprite, i, stationSprite[i], station_build_name[i], station_pic_name[i]);
	i = 2;
	add_planet_and_station(meleedata.planetSprite, i, stationSprite[i], station_build_name[i], station_pic_name[i]);
	i = random() % 3;
	add_planet_and_station(meleedata.planetSprite, i, stationSprite[i], "utwju", station_pic_name[i]);

	for (i = 0; i < 42; i += 1) add(new GobAsteroid());

	int server_players, client_players;
	set_config_file("client.ini");
	server_players = client_players = get_config_int("Gob", "NumPlayers", 1);
	if (!lag_frames) client_players = 0;
	log_int(channel_server, server_players);
	log_int(channel_client, client_players);
	for (i = 0; i < server_players; i += 1) {
		char buffy[256];
		sprintf(buffy, "Config%d", i);
		add_gobplayer(create_control(channel_server, "Human", buffy));
		gobplayer[i]->new_ship(shiptype("supbl"));
		gobplayer[i]->starbucks = starting_starbucks+0;
		gobplayer[i]->buckazoids = starting_buckazoids+0;
		Ship *s = gobplayer[i]->ship;
		s->translate(size/2-s->normal_pos());
		double angle = PI2 * i / (client_players + server_players);
		s->translate(rotate(Vector2(260, 120), angle));
		s->accelerate(s, PI2/3 + angle, 0.17, MAX_SPEED);
	}
	for (i = server_players; i < client_players + server_players; i += 1) {
		char buffy[256];
		sprintf(buffy, "Config%d", i - server_players);
		add_gobplayer(create_control(channel_client, "Human", buffy));
		gobplayer[i]->new_ship(shiptype("supbl"));
		gobplayer[i]->starbucks = starting_starbucks;
		gobplayer[i]->buckazoids = starting_buckazoids;
		Ship *s = gobplayer[i]->ship;
		s->translate(size/2-s->normal_pos());
		double angle = PI2 * i / (client_players + server_players);
		s->translate(rotate(Vector2(260, 120), angle));
		s->accelerate(s, PI2/3 + angle, 0.17, MAX_SPEED);
	}

	for (i = 0; i < gobplayers+0; i += 1) add ( new RainbowRift() );

	next_add_new_enemy_time = 1000;
	this->change_view("Hero");
	//view = get_view ( "Hero", NULL );
	view_locked = true;
	view->window->locate(
		0,0,
		0,0,
		0,0.9,
		0,1
		);

	add_new_enemy();
	add_new_enemy();
	return;
}