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 ...
随机推荐
- HDU1370(中国剩余定理)
昨天我细致一想,发现自己之前的分类(用OJ来划分,毫无意义啊.)太失败了,所以我又一次划分了一下大分类,在分到数论的时候,我就想起了中国剩余定理了.于是乎今天就刷了一题中国剩余定理的题目了.话说太久没 ...
- PowerDesigner基础使用 ---- 入门学习
1:入门级使用PowerDesigner软件创建数据库(直接上图怎么创建,其他的概念知识可自行学习) 我的PowerDesigner版本是16.5的,如若版本不一样,请自行参考学习即可.(打开软件即是 ...
- VBA: 怎样批量数据从Excel派出到Visio
上周派到了个case, 是批量从Excel导出数据导Visio每个图形中. 花了些时间实现了这个功能. 原理如下: 打开Excel 新建/打开表单 指向所选择的表单 遍历所在列的所有数据 打开Visi ...
- python实现tail -f 功能
这篇文章最初是因为reboot的群里,有人去面试,笔试题有这个题,不知道怎么做,什么思路,就发群里大家讨论 我想了一下,简单说一下我的想法吧,当然,也有很好用的pyinotify模块专门监听文件变化, ...
- Hive 数据类型
1. hive的数据类型Hive的内置数据类型可以分为两大类:(1).基础数据类型:(2).复杂数据类型2. hive基本数据类型基础数据类型包括: TINYINT,SMALLINT,INT,BIGI ...
- 记一次揪心的MySQL数据恢复过程
https://blog.csdn.net/poxiaonie/article/details/78304699 === 先说下背景,公司其中一个项目所有服务都部署在客户的机房内,机房较小,没有UPS ...
- android利用provider查询同一个数据库中没有对外暴露出来的表
[原创]转载请加本篇博客地址http://www.cnblogs.com/scarecrow-blog/p/6266042.html 个人感觉这是android provider 的一个漏洞, 废话少 ...
- WPF Demo15 MVVM
项目结构如下: <Window x:Class="MVVMDemo.MainWindow" xmlns="http://schemas.microsoft.com/ ...
- 【linux】之查看物理CPU个数、核数、逻辑CPU个数
# 总核数 = 物理CPU个数 X 每颗物理CPU的核数 # 总逻辑CPU数 = 物理CPU个数 X 每颗物理CPU的核数 X 超线程数 # 查看物理CPU个数 cat /proc/cpuinfo| ...
- 在windows 7中vagrant up 无反应,没任何信息输出
本文转载自:https://blog.csdn.net/cow66/article/details/77993908 我的系统是windows 7 安装了vagrant,当运行vagrant up时, ...