转自: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. shell dict 操作

    shell 读取文件,利用dict 合并第一列 . #!/bin/bash result_file="a" declare -A mydict total=`cat ${resul ...

  2. centos7升级自带的php5.4版本到php5.6

    history命令历史 8 yum provides php #自带的只有5.4版本 9 rpm -Uvh https://mirror.webtatic.com/yum/el7/epel-relea ...

  3. mongodb--Profiling慢查询详解

    官方查询地址:https://docs.mongodb.com/v3.2/tutorial/manage-the-database-profiler/ 在很多情况下,DBA都要对数据库的性能进行分析处 ...

  4. Docker容器挂载主机目录访问出现Permission denied的解决办法

    Docker挂载主机目录,访问相应的文件出现Premission denied的权限访问问题 挂载后,查看相应的文件出现如下的提示: [root@ba471da26d07 soft]# lsls: c ...

  5. c# 一些细节

    1.动态对象和匿名对象偶然看到一个语法,觉得特别方便然后频繁使用,但是没有深究,直到今天忽然发现我潜意思中对它的认知居然是错误的. var data=new { State=1,Message=&qu ...

  6. HanLP用户自定义词典源码分析详解

    1. 官方文档及参考链接 l 关于词典问题Issue,首先参考:FAQ l 自定义词典其实是基于规则的分词,它的用法参考这个issue l 如果有些数量词.字母词需要分词,可参考:P2P和C2C这种词 ...

  7. hadoop发行版本之间的区别

    Hadoop是一个能够对大量数据进行分布式处理的软件框架. Hadoop 以一种可靠.高效.可伸缩的方式进行数据处理.Hadoop的发行版除了有Apache hadoop外cloudera,horto ...

  8. sqlalchemy操作----多表关联

    有二张表,一张作者表,一张书表,一个作者写多本书,一本书可以由多个作者写,与是通过新加一张关系表把他们联系起来 #!/usr/bin/env python # -*- coding: utf-8 -* ...

  9. Delphi实现菜单项上出现提示

    type TMenuHintWindow = class(THintWindow) private FTimerShow: TTimer; FTimerHide: TTimer; procedure ...

  10. [1] 注解(Annotation)-- 深入理解Java:注解(Annotation)基本概念

    转载 http://www.cnblogs.com/peida/archive/2013/04/23/3036035.html 深入理解Java:注解(Annotation)基本概念 什么是注解(An ...