I am working on a terrain stitching algorithm, and I think I know just enough Python (hopefully) to make one. Right now I am trying to figure out the best way to get the x,y location of each terrain piece. Currently I am planning on a 2D tuple that contains the terrain pieces in a grid and only 9 will be loaded at any given time. Here are the two things I am considering:
Make each piece of terrain an object consisting of its file name, mesh name, texture name, and position in the 2D array. I’m not sure yet what information I will need, but these seem like a good place to start.
simply derive its location in the 2D tuple on the fly using a nested index() function
Number one seems more convenient, because I can throw the object name of the terrain into the save file and have all the data I need when the player loads it, but I am worried about efficiency. Number two seems like it might be simpler, but it seems like it would add unnecessary loops.
Thanks for any help! Feel free to offer an option I haven’t considered, this is all new to me!
I’m not sure exactly what you’re referring to - are you loading the pieces externally from a file, or from a variable that is already present in the script? If the pieces are in-game, you can just find them with a near sensor or by looping through a list and comparing positions, so I would assume that’s not what you’re referring to.
@Ortiz: Thanks for the link, that looks very interesting!
@Solar: I am going to be loading and unloading the terrains from a different file so that all the terrains don’t have to be loaded into memory at once. I am hoping to store them in a 2d grid so I can just use the array’s “x,y” to keep the math easy. Here is my pseudocode so far:
terrains may have to be objects with their index stored as a variable
get the terrain the player is currently standing on from the save file
if a brand new game get the starting terrain
load the terrain
load the 8 terrains around that terrain if that many terrains exist
for each of the terrain pieces:
get the terrain’s position from the 2D array based on the player’s location
if there is no terrain at the position, check the next terrain
if it exists
get the terrain’s filename from the 2D array
load the terrain into the scene in its appropriate location relative to
the terrain occupied by the player
if the player is at the terrain located at 1,1 in the array then E = 1,2
W = 1,0 N = 0,1 S = 2,1 NW = 0,0 NE = 0,1 SW = 2,0 SE = 2,2 assuming the
terrains are loaded top to bottom and left to right
Okay, now I understand. So you’ll want to load the terrains using a string of the Player’s position in terrain cell positions, right? The idea you have seems like it would work fine.