转自:https://forums.unrealengine.com/community/community-content-tools-and-tutorials/105-saxonrahs-tutorial-thread-random-maze-generation-solving/page2?47-SaxonRahs-Tutorial-Thread-Random-Maze-Generation-amp-Solving=&viewfull=1

I made my own USTRUCT system for having a multi-dimensional UPROPERTY() friendly dynamic array version of your maze data structure.

Here's that code for you and others to enjoy!

USTRUCT()
struct FMazeGridRow
{
GENERATED_USTRUCT_BODY() UPROPERTY()
TArray<AStaticMeshActor*> Columns; void AddNewColumn()
{
Columns.Add(NULL);
}
//default properties
FMazeGridRow()
{ }
};
USTRUCT()
struct FMazeGrid
{
GENERATED_USTRUCT_BODY() UPROPERTY()
TArray<FMazeGridRow> Rows; void AddNewRow()
{
Rows.Add(FMazeGridRow());
} void AddUninitialized(const int32 RowCount, const int32 ColCount)
{
//Add Rows
for(int32 v = ; v < RowCount; v++)
{
AddNewRow();
} //Add Columns
for(int32 v = ; v < RowCount; v++)
{
for(int32 b = ; b < ColCount; b++)
{
Rows[v].AddNewColumn();
}
}
} void Clear()
{
if(Rows.Num() <= ) return;
//~~~~~~~~~~~~~~~ //Destroy any walls
const int32 RowTotal = Rows.Num();
const int32 ColTotal = Rows[].Columns.Num(); for(int32 v = ; v < RowTotal; v++)
{
for(int32 b = ; b < ColTotal; b++)
{
if(Rows[v].Columns[b] && Rows[v].Columns[b]->IsValidLowLevel() )
{
Rows[v].Columns[b]->Destroy();
}
}
} //Empty
for(int32 v = ; v < Rows.Num(); v++)
{
Rows[v].Columns.Empty();
}
Rows.Empty();
}
//default properties
FMazeGrid()
{ }
};
//Now you have dynamic array benefits and also UPROPERTY()!
UPROPERTY()
FMazeGrid JoyMazeGrid;
//Init Maze
JoyMazeGrid.Clear();
JoyMazeGrid.AddUninitialized(tileX, tileY); //Sample usage
//JoyMazeGrid.Rows[x].Columns[y] = SpawnBP<AStaticMeshActor>(GetWorld(), ...

Summary

The final result of all of this is that you have

1. dynamic array benefits (easily change the maze size and regenerate during runtime)

2. global access to the MazeGrid Actors, even from other classes

3. GC protection from the UPROPERTY() (if not using actors/objects for some reason)

4. And yet the syntax for 2D array using UPROPERTY() and TArray is still clean and clear and precise

JoyMazeGrid.Rows[x].Columns[y]

Enjoy!

Rama

Replicating a 2D dynamic array的更多相关文章

  1. lsof and dynamic array in bash/shell

    https://unix.stackexchange.com/questions/171519/lsof-warning-cant-stat-fuse-gvfsd-fuse-file-system F ...

  2. The correct way to initialize a dynamic pointer to a multidimensional array

    From:https://stackoverflow.com/questions/18273370/the-correct-way-to-initialize-a-dynamic-pointer-to ...

  3. 【转】如何使用Unity创造动态的2D水体效果

    原文:http://gamerboom.com/archives/83080 作者:Alex Rose 在本篇教程中,我们将使用简单的物理机制模拟一个动态的2D水体.我们将使用一个线性渲染器.网格渲染 ...

  4. OpenGL ES: Array Texture初体验

    [TOC] Array Texture这个东西的意思是,一个纹理对象,可以存储不止一张图片信息,就是说是是一个数组,每个元素都是一张图片.这样免了频繁地去切换当前需要bind的纹理,而且可以节省系统资 ...

  5. 不一样的dynamic解析json 万能方法

    写过javascript的人都知道js解析json 1:(JSON) 字符串转换为对象. var str = '{"name":"lsw","hobb ...

  6. Poco::JSON::Array 中object 设置preserveInsertionOrder 时,stringify出错-->深入解析

    在使用poco version 1.6.0时 Poco::JSON::Array 在object  设置preserveInsertionOrder =true 时 调用 array.stringif ...

  7. c语言实现动态指针数组Dynamic arrays

    c语言实现动态数组.其它c的数据结构实现,hashTable參考点击打开链接 treeStruct參考点击打开链接 基本原理:事先准备好一个固定长度的数组. 假设长度不够的时候.realloc一块区域 ...

  8. Intro to Python for Data Science Learning 7 - 2D NumPy Arrays

    2D NumPy Arrays from:https://campus.datacamp.com/courses/intro-to-python-for-data-science/chapter-4- ...

  9. Python笔记 #07# NumPy 文档地址 & Subsetting 2D Arrays

    文档地址:np.array() 1.<class 'numpy.ndarray'> ndarray 表示 n 维度(n D)数组 (= n 行数组). 2.打印 array 结构 —— n ...

随机推荐

  1. 剑指offer-反向遍历链表-栈和递归2种方法(一次性跑通)

  2. MySQL Binlog信息查看

    ##=====================================## ## 在MySQL内部查看binlog文件列表 ## SHOW BINARY LOGS; ##=========== ...

  3. python super()函数

    super()函数是用来调用父类(超类)的一个方法 super()的语法: python 2 的用法: super(Class, self).xxx  # class是子类的名称 class A(ob ...

  4. python的requests快速上手、高级用法和身份认证

    https://blog.csdn.net/qq_25134989/article/details/78800209 快速上手 迫不及待了吗?本页内容为如何入门 Requests 提供了很好的指引.其 ...

  5. php获取指定文件夹中文件名称

    /** * php获取指定文件夹中文件名称 * @author jackie <2018.10.10> */ public static function getFileName($fil ...

  6. CF 316G3 Good Substrings——广义后缀自动机

    题目:http://codeforces.com/contest/316/problem/G3 对询问串和模式串一起建一个后缀自动机,做出在每个串上的 right 集合大小之后枚举自动机上的每个点看看 ...

  7. Ubuntu Nginx Ruby, Rails Mysql 安装

    1. Nginx 安装 sudo apt-get install nginx 2. Ruby 安装 sudo apt-get install ruby 查看版本 ruby -v 3. Rails 安装 ...

  8. Spring Cloud(Dalston.SR5)--Hystrix 断路器-缓存

    在 Spring Cloud 中可以使用注解的方式来支持 Hystrix 的缓存,缓存与合并请求功能需要先初始化请求上下文才能实现,因此,必须实现 javax.servlet.Filter 用于创建和 ...

  9. xilinx AXI相关IP核学习

    xilinx AXI相关IP核学习 1.阅读PG044 (1)AXI4‐Stream to Video Out Top‐Level Signaling Interface (2)AXI4‐Stream ...

  10. 计算MySQL的内存峰值公式 (转)

    -- 计算MySQL的内存峰值公式,计算所有的连接满了的情况下: select (@@key_buffer_size + @@query_cache_size + @@tmp_table_size   ...