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 ...
随机推荐
- 获取和设置用户id以及组id
#include<unistd.h> uid_t getuid(void); uid_t geteuid(void);//获取有效用户id gid_t getgid(void); gid_ ...
- linux 之sed
sed 用法 sed [-nefr] [action] -i 直接修改文件内容,而不是像其他命令那样只是输出到终端 a新增c取代d删除i插入p列印常与sed -n 使用s取代 有一点需要注意的是:如果 ...
- webpack 4 学习资料
webpack 4 学习资料 资料 网址 webpack 中文版 https://webpack.docschina.org/configuration/ webpack 4 教程 https://s ...
- npm安装教程(vue.js)
https://www.cnblogs.com/goldlong/p/8027997.html 首先理清nodejs和npm的关系: node.js是javascript的一种运行环境,是对Googl ...
- python多线程、多进程相关知识
Queue Queue用于建立和操作队列,常和threading类一起用来建立一个简单的线程队列. 首先,队列有很多种,根据进出顺序来分类,可以分成 Queue.Queue(maxsize) FIFO ...
- ElasticeSearch(五)分布式索引架构
关于分布式架构 首先将ES默认每个索引是5个分片,这样做得目的是两个一个索引的时候速度更快(将数据写到小分片的尾部比写入大分片尾部更加快):另外一个是当数据量达到一定程度之后,分片查询,在汇总(sca ...
- [转]关于ImportError: xxxx.so: undefined symbol: PyFPE_jbuf的解决方案
转自: http://blog.csdn.net/zixiximm/article/details/50505921 最近在学着用caffe,总是遇到各种各样奇怪的问题.有时候搜遍整个google也找 ...
- swiper4 一个页面多个轮播
<div class="swiper-container"> <div class="swiper-wrapper"> <div ...
- Keras/Tensorflow训练逻辑研究
Keras是什么,以及相关的基础知识,这里就不做详细介绍,请参考Keras学习站点http://keras-cn.readthedocs.io/en/latest/ Tensorflow作为backe ...
- mysqlli 的基本用法
Mysqli是php5之后才有的功能 需要修改php.ini的配置文件 查找下面的语句: ;extension=php_mysqli.dll 将其修改为:extension=php_mysqli.dl ...