Taking a plain C++ Program into Unreal

Alright its about time to get started!

In any case, I’ve got a fun little program capable of generating a tiled cave system. You feed it a width and a height(current maxes at 100), then you can feed it the max room size(3 is the min, 9 works great), then the max rooms you want(there’s a counter for failed rooms that keeps it from an infinite loop, so it might be slightly less than the max), and then its spits you out a nice map such as this:

(x:80, y:80, maxroom:40, maxroomsize:9)
http://i.imgur.com/RDvSa1al.png

Which the space can then be translated into useful 2d array of tile code(tiles numbered 1-9 starting at upper left of a room, ending at lower right, then 10 and 11 are corridor codes), which can then be read out into text then to excel for easier viewing, or just printed right into the terminal(terribly, because 10 and 11 dont play nice)

So the big question: can I use this plain old average C++ file in UE4, or will I have to recreate it using other functions of unreals design. I’m using the includes:

#include <iostream>
#include <string>
#include <cstdlib>
#include <ctime>
#include <math.h>
#include <fstream>//notreallynecessarybutniceanyways

and within codeblocks I get this flag on compile:
non-static data member initializers only available with -std=c++11 or -std=gnu++11 [enabled by default]

In reality the bulk of it is heavily nested if statements and checking consistencies in a 2D array, but there’s a LOT of potential off-by-1 errors I’d like to skip debugging again. Once I’ve got it in, I’ll use blueprints to build the level with 3D boxes(the 11 tile models already created in blender to fit perfectly together), then populate it, and start the fun work of coding AI and inventories and other things.

You can use plain old C++. Just make sure to have the following at the top of your plain CPP and H code (Before any other includes):

#include “AllowWindowsPlatformTypes.h”

and at the bottom:

#include “HideWindowsPlatformTypes.h”

UE4 uses its own types, so you will need to do some marshalling. Ideally, compile the generation logic (not the graphical part) as a static library, and use UE4 to draw.

Also, this thread might interest you.

I never found that thread, and its pretty close to what I’ve got going so far. The way mine works is by creating the rooms then connecting them all, ensuring that each room has at least 2 exits…normally, I’m not sure what happened to map_17, but the entry/exit(DARK GREEN) tile should never be in a situation like that due to formula that it uses. The variables can all be changed when I feel like it, but its currently set to 100x100 with 60 rooms, it creates a fairly interesting layout I think, and I’m not sure how many static meshes it would handle at once, the current variable settings produces around 4000 ±200 tiles(roughly 70km of walking area)

http://i.imgur.com/XOf5Dn0l.png

Tiles will be 4m^2 on the inside, at max 24 faces with only the inside having texturing.
http://i.imgur.com/bHKgc6Jl.png

This is the class file that contains all the code for the generation and exporting, would it be possible to just to put a copy of this file into the game folder and call the file use the class(I’m fuzzy on the including of files in other projects, didn’t do a lot of that in classes).
http://i.imgur.com/uG0tc5Rl.png

All I want to do is create the data array using:
worldMap var(maxX,maxY);
var.floorbuild(room,size);
var.cavebuild();
var.objbuild(density);

And then call the data from the position in the array using the .getObj(x,y), and run a loop from (0,0) to (100,100) that will spawn the tiles(and enemies if the tile is of the right type)

END GOAL: spawn on island > player has ability to chose size, dificulty, etc. > player drops into dungeon > load screen > blueprint runs the generation code then begins constructing level > blueprint then creates tiles, placing enemies and items on them > player spawns(drops) on entrance tile > player runs the gauntlet to the exit tile > assuming he lives, the exit tile will roll for a new dungeon level. It will have the levels saved, but only the one you are on is active.

One thing I saw that saxon said in his level generation, was that he saved his data into a text file(I’ve already got that in place) and then just read the text file, and this boosted performance, would reading form the text file be the same as in regular C++ or is there another method to it in unreal(and to be honest reading from a .txt is not something I have tried yet, I’ve only worked on importing the data into excel)

and here is what the enemy/item spawn would look like, the one on the left is 318 spawns(20%chance), and the right is 172(10% chance). I dont know if unreal would handle that many actors at once…
http://i.imgur.com/s2q9kkEl.png

Here is a wiki article on linking static libraries with your project. It is not extremely clear, but should get you started.

There is another wiki article on storing and using game data from Excel using DataTables, if it helps.

Hi, I’m the guy from the other thread and I wanna say you are doing really great work!

I used to use just straight up .TXT files back when i first made the generator sometime ago. That approach sucks imo because you need to write your own importer for unreal engine 4. While I did that too and it works great, but unreal handles CSV naively, no reason to reinvent the wheel like i did, you can find that importer work here if you are interested. But really you should look here and the above link.

I would really look into forcing your map generator to generate a CSV file instead that being said, It could be simple as adding a delimiter parameter and changing the file extension to CSV when writing. But i have no idea how you do it there are many different ways to program a cat. If you need help I can try.

That was… startlingly simple… I changed a space to a coma, and .txt to .csv, but for purposes of reading/writing to a csv file I would like to know weather its possible to go by column number and row number, or if I need to actually add in column and row names, because that in fact becomes quite more difficult.(I may have overthought that, and might have just made it simple)

(edit: it was indeed again, extraordinarily easy, and I was trying to over-complicate it again, unfortunately column 0 and row 0 were casualties, and now I only have 99x99. But they were a buffer anyways, filled with 0s for intial map generation to stop rooms from running out of bounds)

All I would truly want to do is say: mapfile.getValueAt(x,y), which would produce an integer, and then the blueprint generates the mesh/colision/anythingcontainedwithin based on that integer.

You can thank

  • Quoted from @ my thread.

This is how i get rows and columns. It’s quite the code!

I encountered a problem when trying to import the table through the UE editor(not sure what exactly it didn’t like about it, 0,0 was blank and then I had the rows as 1-99, and columns as 1-99. So for right now I’m working on creating a static library so I can call the functions and just create the array in unreal and then access it. And theres another thing, how do I take my C++ class and use and abuse it with the blueprint functions?

Oof, the library is completed, but I’m still having quite a bit of trouble connecting it to the project, going to attempt just adding in the code itself(its only 600 lines) in the project, and then have it create an array of map objects to pull data from. At some point I found a place to just add in code to the project, but I’ve forgotten where, shouldn’t be too hard to find again however.

Yeah I would add your generation to ue4 code instead of importing the csv file in the editor although it can be done. I’d extend actor personally, i like to have ‘brain’ bp actors in the world so i can edit it’s values at run-time and get dungeons where ever whenever.

i don’t use any names on any rows or columns i even use ‘a1’ i just plot all of my data into the file with no padding. and i use single and double letters for tiles so i can manage 676 different tiles in a simple 2 letter data even more like 2704 different tiles if i use upper and lower case. (idk maybe using numbers would be a smaller footprint idk)

Are you looking for the add code to project from file menu in ue editor ?

Hey i found some really great stuff for you to check out. It should help you allot.
A new, community-hosted Unreal Engine Wiki - Announcements and Releases - Unreal Engine Forums,Read%26_Write_Any_Data_to_Compressed_Binary_Files#Custom_Save_System_To_Binary_Files

I’ve always had a penchant for over complicating things, what I should be doing is finding where the c++ fps adds in the actor/default terrain, nuke the terrain, drop in a delay for his spawn, gen the world, spawn the current floor, and then drop the actor in on an island where he can drop in a hole that will portal him to the entrance. I’ll still need to look into saving to the csv, assuming it is more efficient than having a vector of arrays of 10k integers floating around.

The save system should come in handy when I start working on the full thing. Currently I’m attempting to get the dungeon sprint working(single floor, survive to the end), then I’ll work on the “choose your own adventure”(player decides ALL the variables,still governed by sprint rules), and once I’m done with that I’ll start creating the full experience.

Alright, I’ve taken the summer off to work on manufacturing techniques,built a Cnc, a 3d printer, and a ton if 3d modeling. I’m the intersection of engineering, computer science and art(specializing in ceramics, further specialization instrument crafting), kinda run out of time in the day to run all the experiments, code programs, and make all the things.

I’ve finaly built and tuned and run the machines for a couple hundred hours, and every major project in that realm finished. I’m about to get back inhibit CS studies, so I’m making the transition back into this project. SO, I could use a quick refresher on a few things:

  1. I’m needing help in creating a new class within a project, one in which I can rewrite my worldgen code, that will create a 3D array
  2. How to make this code where I’m capable of using it in a blueprint, passing it parameters then having the code generate the array, and then being able to pull data from an (x,y,z) from the data table(I’ll worry about saving data at a later point, will probably implement seeds instead).