Exemplo n.º 1
0
void Multi_State::clock_tick() {
	// Defines what will happen each tick.
	player1.move(p1dir);
	player2.move(p2dir);

	check_collisions();

	if (p1parts_to_add != 0) {
		// If theres body to add, add one
		player1.add_parts(1);
		p1parts_to_add--;
	}

	if (p2parts_to_add != 0) {
		player2.add_parts(1);
		p2parts_to_add--;
	}

	carrot_tick++; // Is added every tick
	if (carrot_tick == 10) { // When it updates every 10th tick
		carrot = rotten_carrots.at(rotten_carrots.size() - 1);
		rotten_carrots.pop_back();
		do {
			sprite_x = get_engine()->rand_x();
			sprite_y = get_engine()->rand_y();
		} while (!is_free(sprite_x, sprite_y));
		carrot.x = sprite_x;
		carrot.y = sprite_y;
		std::vector<Obstacles>::iterator it;
		it = rotten_carrots.begin();
		// After we've removed the carrot we add it to the first position
		rotten_carrots.insert(it, carrot);
		carrot_tick = 0;
	}
}
Exemplo n.º 2
0
//-----------------------------------------------------------------------------
// Purpose       : Determines if entities are from the same engine.
//
// Creator       : Tyronne Lim (CAT)
//
// Creation Date : 08/01/03
//-----------------------------------------------------------------------------
CubitBoolean GeometryHealerTool::same_healer_engine( DLIList<TopologyEntity*> &topo_list ) const
{
   GeometryHealerEngine *gePtr1 = get_engine(topo_list.get_and_step());
   GeometryHealerEngine *gePtr2;

   for (int i = 1; i < topo_list.size(); i++)
   {
      gePtr2 = get_engine(topo_list.get_and_step());
      if (gePtr1 != gePtr2)
      {
         return CUBIT_FALSE;   
      }
   }
   return CUBIT_TRUE;
}
Exemplo n.º 3
0
int guiLuaApi::l_get_scriptdir(lua_State *L) {
	GUIEngine* engine = get_engine(L);
	assert(engine != 0);

	lua_pushstring(L,engine->getScriptDir().c_str());
	return 1;
}
Exemplo n.º 4
0
static int cfun_ai_get_targets(lua_State *L)
{
	move_map enemy_dst_src = get_readonly_context(L).get_enemy_dstsrc();
	std::vector<target> targets = get_engine(L).get_ai_context()->find_targets(enemy_dst_src);
	int i = 1;

	lua_createtable(L, 0, 0);
	for (std::vector<target>::iterator it = targets.begin(); it != targets.end(); it++)
	{
		lua_pushinteger(L, i);

		//to factor out
		lua_createtable(L, 3, 0);


		lua_pushstring(L, "type");
		lua_pushnumber(L, it->type);
		lua_rawset(L, -3);

		lua_pushstring(L, "loc");
		push_map_location(L, it->loc);
		lua_rawset(L, -3);

		lua_pushstring(L, "value");
		lua_pushnumber(L, it->value);
		lua_rawset(L, -3);

		lua_rawset(L, -3);
		++i;
	}
	return 1;
}
Exemplo n.º 5
0
int guiLuaApi::l_delete_world(lua_State *L)
{
	GUIEngine* engine = get_engine(L);
	assert(engine != 0);

	int worldidx	= luaL_checkinteger(L,1) -1;

	std::vector<WorldSpec> worlds = getAvailableWorlds();

	if ((worldidx >= 0) &&
		(worldidx < (int) worlds.size())) {

		WorldSpec spec = worlds[worldidx];

		std::vector<std::string> paths;
		paths.push_back(spec.path);
		fs::GetRecursiveSubPaths(spec.path, paths);

		// Delete files
		if (!fs::DeletePaths(paths)) {
			lua_pushstring(L, "Failed to delete world");
		}
		else {
			lua_pushnil(L);
		}
	}
	else {
		lua_pushstring(L, "Invalid world index");
	}
	return 1;
}
Exemplo n.º 6
0
int guiLuaApi::l_create_world(lua_State *L)
{
	GUIEngine* engine = get_engine(L);
	assert(engine != 0);

	const char *name	= luaL_checkstring(L, 1);
	int gameidx			= luaL_checkinteger(L,2) -1;

	std::string path = porting::path_user + DIR_DELIM
			"worlds" + DIR_DELIM
			+ name;

	std::vector<SubgameSpec> games = getAvailableGames();

	if ((gameidx >= 0) &&
			(gameidx < (int) games.size())) {

		// Create world if it doesn't exist
		if(!initializeWorld(path, games[gameidx].id)){
			lua_pushstring(L, "Failed to initialize world");

		}
		else {
		lua_pushnil(L);
		}
	}
	else {
		lua_pushstring(L, "Invalid game index");
	}
	return 1;
}
Exemplo n.º 7
0
 void server::start() {
     if (ssl_) {
         servant_.reset(new fiber(&ssl_server_engine::start, get_ssl_engine(engine_)));
     } else {
         servant_.reset(new fiber(&server_engine::start, get_engine(engine_)));
     }
 }
Exemplo n.º 8
0
CubitStatus GeometryHealerTool::auto_heal_bodies( DLIList<Body*> &body_list, 
                                                  DLIList<Body*> &new_body_list,
                                                  DLIList<TopologyEntity*> &bad_geometry,
                                                  CubitBoolean rebuild, CubitBoolean keep_old,
                                                  CubitBoolean make_tolerant, FILE* logfile_ptr )
{
   DLIList<RefEntity*> ref_entity_list;
   CAST_LIST_TO_PARENT(body_list, ref_entity_list);

   if (!same_healer_engine(ref_entity_list, CUBIT_TRUE))
   {
      PRINT_ERROR("HEALING bodies from different\n"
                  "       geometry engines is not allowed.\n");
      return CUBIT_FAILURE;
   }

   GeometryHealerEngine* GHEPtr = get_engine(body_list.get());
   if (GHEPtr)
   {
      CubitStatus healer_status = GHEPtr->auto_heal_bodies(body_list, new_body_list, bad_geometry,
                                      rebuild, keep_old, make_tolerant, logfile_ptr);

      if( healer_status == CUBIT_SUCCESS )
        CubitObserver::notify_static_observers(NULL, HEALER_COMPLETED);

      return healer_status;
   }
   else
      PRINT_ERROR( "Bodies are of a geometry engine without a healer\n"
                   "         and cannot be healed.\n");
   return CUBIT_FAILURE;
}
Exemplo n.º 9
0
int guiLuaApi::l_get_worlds(lua_State *L)
{
	GUIEngine* engine = get_engine(L);
	assert(engine != 0);

	std::vector<WorldSpec> worlds = getAvailableWorlds();

	lua_newtable(L);
	int top = lua_gettop(L);
	unsigned int index = 1;

	for (unsigned int i = 0; i < worlds.size(); i++)
	{
		lua_pushnumber(L,index);

		lua_newtable(L);
		int top_lvl2 = lua_gettop(L);

		lua_pushstring(L,"path");
		lua_pushstring(L,worlds[i].path.c_str());
		lua_settable(L, top_lvl2);

		lua_pushstring(L,"name");
		lua_pushstring(L,worlds[i].name.c_str());
		lua_settable(L, top_lvl2);

		lua_pushstring(L,"gameid");
		lua_pushstring(L,worlds[i].gameid.c_str());
		lua_settable(L, top_lvl2);

		lua_settable(L, top);
		index++;
	}
	return 1;
}
Exemplo n.º 10
0
CubitStatus GeometryHealerTool::heal_bodies( DLIList<Body*> &body_list, 
                                             DLIList<Body*> &new_body_list,
                                             DLIList<TopologyEntity*> &bad_geometry,
                                             CubitBoolean rebuild, CubitBoolean keep_old,
                                             CubitBoolean make_tolerant, FILE* logfile_ptr )
{
   DLIList<RefEntity*> ref_entity_list;
   CAST_LIST_TO_PARENT(body_list, ref_entity_list);

   if (!same_healer_engine(ref_entity_list, CUBIT_TRUE))
   {
      PRINT_ERROR("HEALING bodies from different\n"
                  "       geometry engines is not allowed.\n");
      return CUBIT_FAILURE;
   }

   GeometryHealerEngine* GHEPtr = get_engine(body_list.get());
   if (GHEPtr)
      return GHEPtr->heal_bodies(body_list, new_body_list, bad_geometry,
                                 rebuild, keep_old, make_tolerant, logfile_ptr);
   else
      PRINT_ERROR( "Bodies are of a geometry engine without a healer\n"
                   "         and cannot be healed.\n");
   return CUBIT_FAILURE;
}
Exemplo n.º 11
0
CubitStatus GeometryHealerTool::heal_incremental( DLIList<Body*> &body_list, 
                                                  DLIList<Body*> &new_bodies,
                                                  DLIList<TopologyEntity*> &bad_geometry,
                                                  double simplify_tol, double stitch_min_tol,
                                                  double stitch_max_tol, double geombuild_tol,
                                                  double analytic_tol, double isospline_tol,
                                                  double reblend_classify_tol, double reblend_tol,
                                                  CubitBoolean keep_old, CubitBoolean make_tolerant,
                                                  FILE* logfile_ptr )
{
   DLIList<RefEntity*> ref_entity_list;
   CAST_LIST_TO_PARENT(body_list, ref_entity_list);

   if (!same_healer_engine(ref_entity_list, CUBIT_TRUE))
   {
      PRINT_ERROR("HEALING bodies from different\n"
                  "       geometry engines is not allowed.\n");
      return CUBIT_FAILURE;
   }

   GeometryHealerEngine* GHEPtr = get_engine(body_list.get());
   if (GHEPtr)
      return GHEPtr->heal_incremental(body_list, new_bodies, bad_geometry, simplify_tol, 
                                          stitch_min_tol, stitch_max_tol, geombuild_tol,
                                          analytic_tol, isospline_tol, reblend_classify_tol,
                                          reblend_tol, keep_old, make_tolerant, logfile_ptr);
   else
      PRINT_ERROR( "Bodies are of a geometry engine without a healer\n"
                   "         and cannot be healed.\n");
   return CUBIT_FAILURE;
}
Exemplo n.º 12
0
int guiLuaApi::l_set_background(lua_State *L)
{
	GUIEngine* engine = get_engine(L);
	assert(engine != 0);

	std::string backgroundlevel(luaL_checkstring(L, 1));
	std::string texturename(luaL_checkstring(L, 2));

	bool retval = false;

	if (backgroundlevel == "background") {
		retval |= engine->setTexture(TEX_LAYER_BACKGROUND,texturename);
	}

	if (backgroundlevel == "overlay") {
		retval |= engine->setTexture(TEX_LAYER_OVERLAY,texturename);
	}

	if (backgroundlevel == "header") {
		retval |= engine->setTexture(TEX_LAYER_HEADER,texturename);
	}

	if (backgroundlevel == "footer") {
		retval |= engine->setTexture(TEX_LAYER_FOOTER,texturename);
	}

	lua_pushboolean(L,retval);
	return 1;
}
Exemplo n.º 13
0
int Engine::get_node(lua_State *L) {
	int model = luaL_checkinteger(L, 1);

	Engine* engine = get_engine(L);
	//lua_pushinteger(L, engine->models[model-1]->node);
	return 1;
}
Exemplo n.º 14
0
/**
 * This function is not thread save and has to be called inside a omp critical
 * region.
 */
int
nest::sli_neuron::execute_sli_protected( DictionaryDatum state, Name cmd )
{
  SLIInterpreter& i = get_engine();

  i.DStack->push( state ); // push state dictionary as top namespace
  size_t exitlevel = i.EStack.load();
  i.EStack.push( new NameDatum( cmd ) );
  int result = i.execute_( exitlevel );
  i.DStack->pop(); // pop neuron's namespace

  if ( state->known( "error" ) )
  {
    assert( state->known( names::global_id ) );
    index g_id = ( *state )[ names::global_id ];
    std::string model = getValue< std::string >( ( *state )[ names::model ] );
    std::string msg =
      String::compose( "Error in %1 with global id %2.", model, g_id );

    LOG( M_ERROR, cmd.toString().c_str(), msg.c_str() );
    LOG( M_ERROR, "execute_sli_protected", "Terminating." );

    kernel().simulation_manager.terminate();
  }

  return result;
}
Exemplo n.º 15
0
Multi_State::Multi_State() {
	// Initalises player1 with number one sprite
	// which gives shows us 'player1' in the head of the sprite.
	player1.init(1);
	player2.init(2);

	// Assigns the objects, and sends a SDL_Surface* which is returned
	// from load_image as a argument.
	apple = Obstacles(Snake_Engine::load_image("./img/apple.bmp"));
	carrot = Obstacles(Snake_Engine::load_image("./img/carrot.bmp"));

	// Get a random position until we find a free one.
	do {
		sprite_x = get_engine()->rand_x();
		sprite_y = get_engine()->rand_y();
	} while (!is_free(sprite_x, sprite_y));
	apple.x = sprite_x;
	apple.y = sprite_y;

	// Does the same thing but spawns 35 carrots.
	for (int i = 0; i != 35; i++) {
		do {
			sprite_x = get_engine()->rand_x();
			sprite_y = get_engine()->rand_y();
		} while (!is_free(sprite_x, sprite_y));
		carrot.x = sprite_x;
		carrot.y = sprite_y;
		rotten_carrots.push_back(carrot);
	}
	carrot_tick = 0;

	green_background.x = 16;
	green_background.y = 16;
	green_background.w = 608;
	green_background.h = 448;

	finished = false;

	// Direction is initalized to right in the beginning
	p1dir = 2;
	p2dir = 2;
	p1points = 0;
	p2points = 0;
	p1parts_to_add = 0;
	p2parts_to_add = 0;
}
Exemplo n.º 16
0
 server::~server() {
     stop();
     if (ssl_) {
         delete get_ssl_engine(engine_);
     } else {
         delete get_engine(engine_);
     }
 }
Exemplo n.º 17
0
 void server::stop() {
     if (servant_) {
         if (ssl_) {
             get_ssl_engine(engine_)->close();
         } else {
             get_engine(engine_)->close();
         }
     }
 }
Exemplo n.º 18
0
void context::pop() {
    if (m_trail.get_num_scopes() == 0) {
        throw default_exception("there are no backtracking points to pop to");
    }
    if(m_engine.get()) {
        if(get_engine() != DUALITY_ENGINE)
            throw default_exception("operation is not supported by engine");
    }
    m_trail.pop_scope(1);
}
Exemplo n.º 19
0
int guiLuaApi::l_set_clouds(lua_State *L)
{
	GUIEngine* engine = get_engine(L);
	assert(engine != 0);

	bool value = lua_toboolean(L,1);

	engine->m_clouds_enabled = value;

	return 0;
}
Exemplo n.º 20
0
int guiLuaApi::l_get_games(lua_State *L)
{
	GUIEngine* engine = get_engine(L);
	assert(engine != 0);

	std::vector<SubgameSpec> games = getAvailableGames();

	lua_newtable(L);
	int top = lua_gettop(L);
	unsigned int index = 1;

	for (unsigned int i = 0; i < games.size(); i++)
	{
		lua_pushnumber(L,index);
		lua_newtable(L);
		int top_lvl2 = lua_gettop(L);

		lua_pushstring(L,"id");
		lua_pushstring(L,games[i].id.c_str());
		lua_settable(L, top_lvl2);

		lua_pushstring(L,"path");
		lua_pushstring(L,games[i].path.c_str());
		lua_settable(L, top_lvl2);

		lua_pushstring(L,"gamemods_path");
		lua_pushstring(L,games[i].gamemods_path.c_str());
		lua_settable(L, top_lvl2);

		lua_pushstring(L,"name");
		lua_pushstring(L,games[i].name.c_str());
		lua_settable(L, top_lvl2);

		lua_pushstring(L,"menuicon_path");
		lua_pushstring(L,games[i].menuicon_path.c_str());
		lua_settable(L, top_lvl2);

		lua_pushstring(L,"addon_mods_paths");
		lua_newtable(L);
		int table2 = lua_gettop(L);
		int internal_index=1;
		for (std::set<std::string>::iterator iter = games[i].addon_mods_paths.begin();
				iter != games[i].addon_mods_paths.end(); iter++) {
			lua_pushnumber(L,internal_index);
			lua_pushstring(L,(*iter).c_str());
			lua_settable(L, table2);
			internal_index++;
		}
		lua_settable(L, top_lvl2);
		lua_settable(L, top);
		index++;
	}
	return 1;
}
Exemplo n.º 21
0
int guiLuaApi::l_get_modstore_list(lua_State *L)
{
	GUIEngine* engine = get_engine(L);
	assert(engine != 0);

	std::string listtype = "local";

	if (!lua_isnone(L,1)) {
		listtype = luaL_checkstring(L,1);
	}
	Json::Value mods;
	std::string url = "";
	try{
		url = g_settings->get("modstore_listmods_url");
	}
	catch(SettingNotFoundException &e) {
		lua_pushnil(L);
		return 1;
	}

	mods = getModstoreUrl(url);

	std::vector<ModStoreMod> moddata = readModStoreList(mods);

	lua_newtable(L);
	int top = lua_gettop(L);
	unsigned int index = 1;

	for (unsigned int i = 0; i < moddata.size(); i++)
	{
		if (moddata[i].valid) {
			lua_pushnumber(L,index);
			lua_newtable(L);

			int top_lvl2 = lua_gettop(L);

			lua_pushstring(L,"id");
			lua_pushnumber(L,moddata[i].id);
			lua_settable(L, top_lvl2);

			lua_pushstring(L,"title");
			lua_pushstring(L,moddata[i].title.c_str());
			lua_settable(L, top_lvl2);

			lua_pushstring(L,"basename");
			lua_pushstring(L,moddata[i].basename.c_str());
			lua_settable(L, top_lvl2);

			lua_settable(L, top);
			index++;
		}
	}
	return 1;
}
Exemplo n.º 22
0
int guiLuaApi::l_close(lua_State *L)
{
	GUIEngine* engine = get_engine(L);
	assert(engine != 0);

	engine->m_data->kill = true;

	//close menu next time
	engine->m_startgame = true;
	engine->m_menu->quitMenu();
	return 0;
}
Exemplo n.º 23
0
int guiLuaApi::l_show_keys_menu(lua_State *L)
{
	GUIEngine* engine = get_engine(L);
	assert(engine != 0);

	GUIKeyChangeMenu *kmenu
		= new GUIKeyChangeMenu(	engine->m_device->getGUIEnvironment(),
								engine->m_parent,
								-1,
								engine->m_menumanager);
	kmenu->drop();
	return 0;
}
Exemplo n.º 24
0
int guiLuaApi::l_set_topleft_text(lua_State *L)
{
	GUIEngine* engine = get_engine(L);
	assert(engine != 0);

	std::string text = "";

	if (!lua_isnone(L,1) &&	!lua_isnil(L,1))
		text = luaL_checkstring(L, 1);

	engine->setTopleftText(text);
	return 0;
}
Exemplo n.º 25
0
 server::server(settings s)
 : ssl_(s.ctx)
 {
     if(ssl_) {
         engine_=reinterpret_cast<impl *>(new ssl_server_engine(s.ctx,
                                                                s.address,
                                                                s.port,
                                                                get_default_host_name<ssl::tcp_stream>(s.port),
                                                                std::move(s.default_request_handler)));
         get_ssl_engine(engine_)->read_timeout_=s.read_timeout;
         get_ssl_engine(engine_)->write_timeout_=s.write_timeout;
         get_ssl_engine(engine_)->max_keep_alive_=s.max_keep_alive;
     } else {
         engine_=reinterpret_cast<impl *>(new server_engine(0,
                                                            s.address,
                                                            s.port,
                                                            get_default_host_name<tcp_stream>(s.port),
                                                            std::move(s.default_request_handler)));
         get_engine(engine_)->read_timeout_=s.read_timeout;
         get_engine(engine_)->write_timeout_=s.write_timeout;
         get_engine(engine_)->max_keep_alive_=s.max_keep_alive;
     }
 }
Exemplo n.º 26
0
int guiLuaApi::l_get_textlist_index(lua_State *L)
{
	GUIEngine* engine = get_engine(L);
	assert(engine != 0);

	std::string listboxname(luaL_checkstring(L, 1));

	int selection = engine->m_menu->getListboxIndex(listboxname);

	if (selection >= 0)
		selection++;

	lua_pushinteger(L, selection);
	return 1;
}
TEST(StrictInterfaces, Boat) {

  {
    auto boat0 = Boat(std::make_shared<YamahaEngine>(), 6.7f);
    auto boat1 = boat0;
    // ... and does not realize that the oil amount applies to both boats
    boat1.set_length(8.56f);
    boat1.get_engine()->set_oil_amount(3.4f);
  }

  {
    auto&& boat0 = BoatNoncopyable{std::make_shared<YamahaEngine>(), 6.7f}; // [auto&& is needed in current version of MSVC]
    // Below code won't compile, the second programmer will have to find another solution compliant with the limitations of the Boat
    /* auto boat1 = boat0; */
  }
}
Exemplo n.º 28
0
int guiLuaApi::l_update_formspec(lua_State *L)
{
	GUIEngine* engine = get_engine(L);
	assert(engine != 0);

	if (engine->m_startgame)
		return 0;

	//read formspec
	std::string formspec(luaL_checkstring(L, 1));

	if (engine->m_formspecgui != 0) {
		engine->m_formspecgui->setForm(formspec);
	}

	return 0;
}
Exemplo n.º 29
0
int Engine::rotate_node(lua_State *L) {
	Vector3 axis[] = {
			{1, 0, 0},
			{0, 0, 1},
			{0, 1, 0},
	};

	int node = luaL_checkinteger(L, 1);
	int axis_idx = luaL_checkinteger(L, 2);
	double ang = luaL_checknumber(L, 3);

	Engine* engine = get_engine(L);

	Matrix4 rotationMatrix = Matrix4::rotationMatrix(Quaternion::make(axis[axis_idx], ang));
	engine->scene_graph.transform_node(node, rotationMatrix);

	return 0;
}
Exemplo n.º 30
0
void GeometryHealerTool::clean_attributes( DLIList<Body*>& body_list )
{
   DLIList<RefEntity*> ref_entity_list;
   CAST_LIST_TO_PARENT(body_list, ref_entity_list);

   if (!same_healer_engine(ref_entity_list, CUBIT_TRUE))
   {
      PRINT_ERROR("HEALING bodies from different\n"
                  "       geometry engines is not allowed.\n");
   }

   GeometryHealerEngine* GHEPtr = get_engine(body_list.get());
   if (GHEPtr)
      GHEPtr->clean_attributes(body_list);
   else
      PRINT_ERROR( "Bodies are of a geometry engine without a healer\n"
                   "         and cannot be healed.\n");
}