void SPaperExtractSpritesDialog::CreateExtractedSprites()
{
	FAssetToolsModule& AssetToolsModule = FModuleManager::Get().LoadModuleChecked<FAssetToolsModule>("AssetTools");
	FContentBrowserModule& ContentBrowserModule = FModuleManager::LoadModuleChecked<FContentBrowserModule>("ContentBrowser");

	TArray<UObject*> ObjectsToSync;

	// Create the factory used to generate the sprite
	auto SpriteFactory = NewObject<UPaperSpriteFactory>();
	SpriteFactory->InitialTexture = SourceTexture;

	// Create the sprite
	FString Name;
	FString PackageName;

	FScopedSlowTask Feedback(ExtractedSprites.Num(), NSLOCTEXT("Paper2D", "Paper2D_ExtractSpritesFromTexture", "Extracting Sprites From Texture"));
	Feedback.MakeDialog(true);

	for (const FPaperExtractedSprite ExtractedSprite : ExtractedSprites)
	{
		Feedback.EnterProgressFrame(1, NSLOCTEXT("Paper2D", "Paper2D_ExtractSpritesFromTexture", "Extracting Sprites From Texture"));

		SpriteFactory->bUseSourceRegion = true;
		const FIntRect& ExtractedRect = ExtractedSprite.Rect;
		SpriteFactory->InitialSourceUV = FVector2D(ExtractedRect.Min.X, ExtractedRect.Min.Y);
		SpriteFactory->InitialSourceDimension = FVector2D(ExtractedRect.Width(), ExtractedRect.Height());

		// Get a unique name for the sprite
		// Extracted sprite name is a name, we insert a _ as we're appending this to the texture name
		// Opens up doors to renaming the sprites in the editor, and still ending up with TextureName_UserSpriteName
		FString Suffix = TEXT("_");
		Suffix.Append(ExtractedSprite.Name);

		AssetToolsModule.Get().CreateUniqueAssetName(SourceTexture->GetOutermost()->GetName(), Suffix, /*out*/ PackageName, /*out*/ Name);
		const FString PackagePath = FPackageName::GetLongPackagePath(PackageName);

		if (UObject* NewAsset = AssetToolsModule.Get().CreateAsset(Name, PackagePath, UPaperSprite::StaticClass(), SpriteFactory))
		{
			ObjectsToSync.Add(NewAsset);
		}

		if (GWarn->ReceivedUserCancel())
		{
			break;
		}
	}

	if (ObjectsToSync.Num() > 0)
	{
		ContentBrowserModule.Get().SyncBrowserToAssets(ObjectsToSync);
	}
}
Exemplo n.º 2
0
/*
!!!! This function is designed for the controller !!!!!

Purpose: Parse the message into each of the components and then distrubute the commands as nessesary
  Input: Recieve Queue
 Output: none
*/
void Parse_Data(void)
{
	// Local variables for assigning the bytes too
	unsigned char node;
	unsigned char sub_comp;
	unsigned char instruction;
	
	// Grab the three bytes and sort according to their representation
	node = rxdata[0];
	sub_comp = rxdata[1];
	instruction = rxdata[2];
	
	SCIprintf("%d%d%d", rxdata[0], rxdata[1], rxdata[2]);
	
	//putsSCI(rxdata);
	
	switch (node)
	{
	    case PID:
	        Feedback(sub_comp, instruction);
	        break;
		// Elevator Car
		case CAR:
			Car(sub_comp, instruction);
			break;
		// Floor 1
		case F1:
			Floor(F1, sub_comp, instruction);
			break;
		// Floor 2
		case F2:
		    Floor(F2, sub_comp, instruction);
			break;
		// Floor 3
		case F3:
		    Floor(F3, sub_comp, instruction);
			break;
		default:
			    msDELAY(100);
			    break;
	}
}
Exemplo n.º 3
0
  Feedback Game::move(Cell from, Cell to, MoveResult force_result) {
    Element from_element = board[from.get_id()];
    Element to_element = board[to.get_id()];
    assert(!from_element.is_empty());
    assert(from.get_type() != Headquarter);
    bool occupy_state[4631] = {0};
    for(int i=0; i<4631; i++) {
      if(is_valid_cell_id(i)) {
	occupy_state[i] = !board[i].is_empty();
      }
    }
    MoveResult result;
    std::list<Cell> route;
    bool show_flag = false;
    if(!from_element.is_unknown() && !to_element.is_unknown()) {
      assert(force_result == Nothing);
      // count the number of 40
      int n_of_40_before = 0;
      if(!from_element.is_empty() && piece_of(from_element) == Piece(40)) {
	n_of_40_before++;
      }
      if(!to_element.is_empty() && piece_of(to_element) == Piece(40)) {
	n_of_40_before++;
      }
      // process board
      if(!to_element.is_empty()) {
	result = Piece::attack(piece_of(from_element), piece_of(to_element));
      } else {
	result = Nothing;
      }
      route = get_route(
	  from, to, occupy_state, piece_of(from_element) == Piece(32)
      );
      assert(!route.empty());
      if(result == Nothing || result == Bigger) {
	board[to.get_id()] = from_element;
      } else if(result == Equal) {
	board[to.get_id()] = Element();
      }
      board[from.get_id()] = Element();
      // count the number of 40
      int n_of_40_after = 0;
      Element target = board[to.get_id()];
      if(!target.is_empty() && !target.is_unknown()) {
	if(piece_of(target) == Piece(40)) {
	  n_of_40_after++;
	}
      }
      if(n_of_40_after < n_of_40_before) {
	show_flag = true;
      }
    } else {
      assert(force_result != Nothing);
      result = force_result;
      route = get_route(from, to, occupy_state, true);
      assert(!route.empty());
      if(result == Nothing || result == Bigger) {
	board[to.get_id()] = from_element;
      } else if(result == Equal) {
	board[to.get_id()] = Element();
      }
      board[from.get_id()] = Element();
    }
    steps++;
    last_feedback = Feedback(result, route, show_flag);
    return last_feedback;
  }
Exemplo n.º 4
0
// Searches for an obviously optimal strategy.
// If one exists, returns the total cost of the strategy.
// Otherwise, returns -1.
// @todo Change return type to StrategyCost.
static int fill_obviously_optimal_strategy(
	Engine &e,
	CodewordRange secrets,
	bool min_depth,    // whether to minimize the worst-case depth
	int max_depth,     // maximum number of extra guesses, not counting
	                   // the initial guess
	StrategyTree &tree // Strategy tree that stores the best strategy
	)
{
	int extra;
	//Codeword guess = ObviousStrategy(e).make_guess(secrets, &extra);
	Codeword guess = make_less_obvious_guess(e, secrets, &extra);
	--extra;
	// @todo Take into account the lower-bound estimate of non-possible
	// guesses.
	if (!guess || (extra > max_depth) || (min_depth && extra > 1))
		return -1;

	//	VERBOSE_COUT << "Found obvious guess: " << obvious << std::endl;

	// Automatically fill the strategy tree using this guess.This requires
	// all cells in the partition to have no more than two possibilities.
	// This is equivalent to Knuth's 'x' notation in writing a strategy.
	Feedback perfect = Feedback::perfectValue(e.rules());
	FeedbackList fbs;
	e.compare(guess, secrets, fbs);
	size_t n = secrets.size();
	int depth = tree.currentDepth();
	int cost = 0;

	for (size_t j = 0; j < Feedback::size(e.rules()); ++j)
	{
		Codeword first;
		for (size_t i = 0; i < n; ++i)
		{
			if (fbs[i] == Feedback(j))
			{
				if (!first)
				{
					++cost;
					first = secrets[i];
					StrategyTree::Node node(depth + 1, guess, fbs[i]);
					tree.append(node);
					if (fbs[i] != perfect)
					{
						++cost;
						StrategyTree::Node leaf(depth + 2, first, perfect);
						tree.append(leaf);
					}
				}
				else
				{
					cost += 3;
					tree.append(StrategyTree::Node(depth + 2,
						first, e.compare(secrets[i], first)));
					tree.append(StrategyTree::Node(depth + 3,
						secrets[i], perfect));
				}
			}
		}
	}
	return cost;
	// @todo: try guesses from non-secrets.
}
	void CreateSpritesFromTextures(TArray<UTexture2D*>& Textures)
	{
		const FString DefaultSuffix = TEXT("_Sprite");

		FAssetToolsModule& AssetToolsModule = FModuleManager::Get().LoadModuleChecked<FAssetToolsModule>("AssetTools");
		FContentBrowserModule& ContentBrowserModule = FModuleManager::LoadModuleChecked<FContentBrowserModule>("ContentBrowser");

		TArray<UObject*> ObjectsToSync;

		for (auto TextureIt = Textures.CreateConstIterator(); TextureIt; ++TextureIt)
		{
			UTexture2D* Texture = *TextureIt;

			// Create the factory used to generate the sprite
			UPaperSpriteFactory* SpriteFactory = ConstructObject<UPaperSpriteFactory>(UPaperSpriteFactory::StaticClass());
			SpriteFactory->InitialTexture = Texture;

			// Create the sprite
			FString Name;
			FString PackageName;

			if (!bExtractSprites)
			{
				// Get a unique name for the sprite
				AssetToolsModule.Get().CreateUniqueAssetName(Texture->GetOutermost()->GetName(), DefaultSuffix, /*out*/ PackageName, /*out*/ Name);
				const FString PackagePath = FPackageName::GetLongPackagePath(PackageName);

				if (UObject* NewAsset = AssetToolsModule.Get().CreateAsset(Name, PackagePath, UPaperSprite::StaticClass(), SpriteFactory))
				{
					ObjectsToSync.Add(NewAsset);
				}
			}
			else
			{
				FScopedSlowTask Feedback(1, NSLOCTEXT("Paper2D", "Paper2D_ExtractSpritesFromTexture", "Extracting Sprites From Texture"));
				Feedback.MakeDialog(true);

				// First extract the rects from the texture
				TArray<FIntRect> ExtractedRects;
				UPaperSprite::ExtractRectsFromTexture(Texture, /*out*/ ExtractedRects);

				// Sort the rectangles by approximate row
				struct FRectangleSortHelper
				{
					FRectangleSortHelper(TArray<FIntRect>& InOutSprites)
					{
						// Sort by Y, then by X (top left corner), descending order (so we can use it as a stack from the top row down)
						TArray<FIntRect> SpritesLeft = InOutSprites;
						SpritesLeft.Sort([](const FIntRect& A, const FIntRect& B) { return (A.Min.Y == B.Min.Y) ? (A.Min.X > B.Min.X) : (A.Min.Y > B.Min.Y); });
						InOutSprites.Reset();

						// Start pulling sprites out, the first one in each row will dominate remaining ones and cause them to get labeled
						TArray<FIntRect> DominatedSprites;
						DominatedSprites.Empty(SpritesLeft.Num());
 						while (SpritesLeft.Num())
 						{
							FIntRect DominatingSprite = SpritesLeft.Pop();
							DominatedSprites.Add(DominatingSprite);

							// Find the sprites that are dominated (intersect the infinite horizontal band described by the dominating sprite)
							for (int32 Index = 0; Index < SpritesLeft.Num();)
							{
								const FIntRect& CurElement = SpritesLeft[Index];
								if ((CurElement.Min.Y <= DominatingSprite.Max.Y) && (CurElement.Max.Y >= DominatingSprite.Min.Y))
								{
									DominatedSprites.Add(CurElement);
									SpritesLeft.RemoveAt(Index, /*Count=*/ 1, /*bAllowShrinking=*/ false);
								}
								else
								{
									++Index;
								}
							}

							// Sort the sprites in the band by X and add them to the result
							DominatedSprites.Sort([](const FIntRect& A, const FIntRect& B) { return (A.Min.X < B.Min.X); });
							InOutSprites.Append(DominatedSprites);
							DominatedSprites.Reset();
 						}
					}
				};
				FRectangleSortHelper RectSorter(ExtractedRects);

				Feedback.TotalAmountOfWork = ExtractedRects.Num();

				for (int ExtractedRectIndex = 0; ExtractedRectIndex < ExtractedRects.Num(); ++ExtractedRectIndex)
				{
					Feedback.EnterProgressFrame(1, NSLOCTEXT("Paper2D", "Paper2D_ExtractSpritesFromTexture", "Extracting Sprites From Texture"));

					FIntRect& ExtractedRect = ExtractedRects[ExtractedRectIndex];
					SpriteFactory->bUseSourceRegion = true;
					SpriteFactory->InitialSourceUV = FVector2D(ExtractedRect.Min.X, ExtractedRect.Min.Y);
					SpriteFactory->InitialSourceDimension = FVector2D(ExtractedRect.Width(), ExtractedRect.Height());

					// Get a unique name for the sprite
					const FString Suffix = FString::Printf(TEXT("%s_%d"), *DefaultSuffix, ExtractedRectIndex);
					AssetToolsModule.Get().CreateUniqueAssetName(Texture->GetOutermost()->GetName(), Suffix, /*out*/ PackageName, /*out*/ Name);
					const FString PackagePath = FPackageName::GetLongPackagePath(PackageName);

					if (UObject* NewAsset = AssetToolsModule.Get().CreateAsset(Name, PackagePath, UPaperSprite::StaticClass(), SpriteFactory))
					{
						ObjectsToSync.Add(NewAsset);
					}

					if (GWarn->ReceivedUserCancel()) 
					{
						break;
					}
				}
			}
		}

		if (ObjectsToSync.Num() > 0)
		{
			ContentBrowserModule.Get().SyncBrowserToAssets(ObjectsToSync);
		}
	}