Replicating a 2D dynamic array
转自: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的更多相关文章
- lsof and dynamic array in bash/shell
https://unix.stackexchange.com/questions/171519/lsof-warning-cant-stat-fuse-gvfsd-fuse-file-system F ...
- 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 ...
- 【转】如何使用Unity创造动态的2D水体效果
原文:http://gamerboom.com/archives/83080 作者:Alex Rose 在本篇教程中,我们将使用简单的物理机制模拟一个动态的2D水体.我们将使用一个线性渲染器.网格渲染 ...
- OpenGL ES: Array Texture初体验
[TOC] Array Texture这个东西的意思是,一个纹理对象,可以存储不止一张图片信息,就是说是是一个数组,每个元素都是一张图片.这样免了频繁地去切换当前需要bind的纹理,而且可以节省系统资 ...
- 不一样的dynamic解析json 万能方法
写过javascript的人都知道js解析json 1:(JSON) 字符串转换为对象. var str = '{"name":"lsw","hobb ...
- Poco::JSON::Array 中object 设置preserveInsertionOrder 时,stringify出错-->深入解析
在使用poco version 1.6.0时 Poco::JSON::Array 在object 设置preserveInsertionOrder =true 时 调用 array.stringif ...
- c语言实现动态指针数组Dynamic arrays
c语言实现动态数组.其它c的数据结构实现,hashTable參考点击打开链接 treeStruct參考点击打开链接 基本原理:事先准备好一个固定长度的数组. 假设长度不够的时候.realloc一块区域 ...
- 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- ...
- Python笔记 #07# NumPy 文档地址 & Subsetting 2D Arrays
文档地址:np.array() 1.<class 'numpy.ndarray'> ndarray 表示 n 维度(n D)数组 (= n 行数组). 2.打印 array 结构 —— n ...
随机推荐
- Where关键词的用法
where(泛型类型约束) where关键词一个最重要的用法就是在泛型的声明.定义中做出约束. 约束又分为接口约束.基类约束.构造函数约束.函数方法的约束,我们慢慢介绍. 接口约束 顾名思义,泛型参数 ...
- Odoo 开源协议讨论
Odoo 开源协议讨论 Odoo 9 开始使用的 LGPL 开源协议,所以模块的加密并不会违反 Odoo 的开源协议. 如果使用 Odoo 8 (含)以前的版本开发模块,那么你在分发模块时也必须给使用 ...
- redis之 3.0集群安装
1. 集群 即使有了主从复制,每个数据库都要保存整个集群中的所有数据,容易形成木桶效应. 使用Jedis实现了分片集群,是由客户端控制哪些key数据保存到哪个数据库中,如果在水平扩容时就必须手动进行数 ...
- 使用 Travis 进行持续集成
廖雪峰教程:https://www.liaoxuefeng.com/article/0014631488240837e3633d3d180476cb684ba7c10fda6f6000
- maven 内置变量
${basedir} 项目根目录 ${project.build.directory} 构建目录,缺省为target ${project.build.outputDirectory} 构建过程输出目录 ...
- base64 base64urlsafe
1. base64 不算是加密算法,只能说是一种转码.使用64 个可见的字符来代替 ASCII码 中的256 个字符. 2. ASCII码占用一个字节,可以有0-255共256个取值.前128个为常用 ...
- ubuntu防火墙ufw使用教程
查看ubuntu版本cat /etc/issue或者lsb_release -a 防火墙 由于Linux原始的防火墙工具iptables过于繁琐,所以ubuntu默认提供了一个基于iptable之上的 ...
- eclipse中如何去掉复制代码有行号的数字
当我想查找别人资料,想复制别人的代码,但别人的代码中序号行数数字,怎么能快速去除呢,如以下截图所示 首先将你的带有行号的代码拷到一个类中.你会看到一大堆的错误,不用急. 注意将视图切换到java ...
- Python正则表达式指南 (转)
本文http://www.cnblogs.com/huxi/archive/2010/07/04/1771073.html 正则表达式经常被用到,而自己总是记不全,转载一份完整的以备不时之需. 1. ...
- ASP.NET AJAX入门系列(11):在多个UpdatePanle中使用Timer控件
本文将使用Timer控件更新两个UpdatePanel控件,Timer控件将放在UpdatePanel控件的外面,并将它配置为UpdatePanel的触发器,翻译自官方文档. 主要内容 在多个Upda ...