Thursday, November 17, 2022
HomeGame Developmentc++ - Enhance efficiency of hexagonal tiles

c++ – Enhance efficiency of hexagonal tiles


I’m making an attempt to create a sport much like a board sport on a hexagonal grid (additionally much like Civilization sport).

I would like the tiles to have the ability to show numerous textures and naturally be capable of detect objects on there, and add enhancements to the tile and so on. So I wrote a C++ script to spawn every cell in a grid format. It seems good and appears to work however even a small grid actually slows down my laptop within the Unreal Editor.

I’m not certain if that is right down to my code, or my mannequin (which was only a easy hexagonal aircraft made in Maya utilizing 6-sided cylinder). I’ve a reasonably respectable system (6700k, 1660GTX, 32GB Ram) so I did not anticipate the dangerous efficiency from what I’ve created.

#embrace "Grid.h"

#embrace "GridCell.h"

// Units default values
AGrid::AGrid()
{
    // Set this actor to name Tick() each body.  You may flip this off to enhance efficiency for those who do not want it.
    PrimaryActorTick.bCanEverTick = true;

}

// Referred to as when the sport begins or when spawned
void AGrid::BeginPlay()
{
    Tremendous::BeginPlay();
    
    for(int y=0; y<Grid_Height; y++)
    {
        for(int x=0; x<Grid_Width; x++)
        {
            //Cells[x+(y*x)]=GetWorld()->SpawnActor<AGridCell>(Grid_Cell_BP->StaticClass());
            FVector location=FVector(x*100.f, y*75.f, 0);
            if(ypercent2!=0)
                location.X+=50.f;
            Cells.Add(GetWorld()->SpawnActor<AGridCell>(Grid_Cell_BP, location, FRotator::ZeroRotator));

        }
    }
}

// Referred to as each body
void AGrid::Tick(float DeltaTime)
{
    Tremendous::Tick(DeltaTime);

}


#embrace "GridCell.h"

// Units default values
AGridCell::AGridCell()
{
    // Set this actor to name Tick() each body.  You may flip this off to enhance efficiency for those who do not want it.
    PrimaryActorTick.bCanEverTick = true;

    Mesh=CreateDefaultSubobject<UStaticMeshComponent>("Mesh");
    RootComponent=Mesh;


}

// Referred to as when the sport begins or when spawned
void AGridCell::BeginPlay()
{
    Tremendous::BeginPlay();
    
}

// Referred to as each body
void AGridCell::Tick(float DeltaTime)
{
    Tremendous::Tick(DeltaTime);

}

My venture up to now, I simply have a “Grid” blueprint dragged into the scene. I set the values at 20×20 measurement grid.

Every thing does spawn and appears nice, however it is rather sluggish. I had hoped to have a lot bigger maps.

enter image description here

Is there one other strategy I might use, maybe that has one massive rectangle aircraft after which lay the hexagons over that possibly?

Additionally, I really feel it is in all probability a nasty thought to make every Cell an “AActor” . Does it must be, how might I do it with out it being an AActor?

Any concepts could be nice. Thanks.

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

- Advertisment -
Google search engine

Most Popular

Recent Comments