Jump to content


Photo

Best way to organize this code


  • Please log in to reply
4 replies to this topic

#1 greep

greep

    Menaces with Spikes

  • GMC Member
  • 2398 posts
  • Version:GM7

Posted 04 March 2012 - 01:14 AM

So, I'm designing a grid based world with grid based rooms. Each room is created with data that is then stored in a file, like so:
Spoiler


Those three bytes that are saved each make up the info for a tile. This code is fine, it just illustrates what I'm doing.

However, here's my problem: I wish to make the world "seamless" world by having a room that borders another room on the grid share the same 15-20 tiles on that border. I'm wondering what is the best way to go about doing this. The current way I'm thinking, which sounds bad but it's the only way I can think of that works, is to

A) design all the rooms and save them to their room data file
B) for each room on the grid, load the room data and neighboring room data and change the apropriate tiles, then save

But this is slow as molasses

The other method I'm thinking of is

A) design all the rooms but don't save them
B) go through the room and then change the appropriate grid points in that room
C) Then save them

But this hogs a buttload of RAM and is also probably slow.

Any ideas, including ones that would require me to redo this entire process in a different way, would be nice :) I'm sure there's a "right" way but I can't think of it.

Edit: Shoot, this won't even work very well, as any changes to border tiles would mean every time I save a room I'd have to save the shared tiles.

One idea I have is to just save the entire world in one massive file, but everyone time I save a room would involve saving the whole world, which wouldn't work.

Edit:Edit: Or maybe making each room 120x120 and have the outer parts made of 4 semi-rooms? Or a room and 4 corner parts and 4 side parts?

Edited by greep, 04 March 2012 - 01:56 AM.

  • 0

#2 FoxInABox

FoxInABox

    GMC Member

  • GMC Member
  • 5886 posts
  • Version:GM:Studio

Posted 04 March 2012 - 05:52 AM

aaaa bbbb
aaaa bbbb
aaaa bbbb
cccc dddd
cccc dddd
cccc dddd

you load everything into a 5x5 grid, but only show the ones from 1,1 to 3,3 .. the outer border is for transision..

so if you are in square 4,4 you see:
aab
aab
ccd

but what is loaded is:
aaabb
aaabb
cccdd
cccdd

then you cross over to 4,5 so the grid have to shift
aaabb
cccdd
cccdd
xxxxx

and you have to load the 5 missing tiles, should be possible without reading the whole file since you save them all as 3 bytes

meh, this would be some fun coding x3
  • 0

#3 greep

greep

    Menaces with Spikes

  • GMC Member
  • 2398 posts
  • Version:GM7

Posted 04 March 2012 - 06:30 AM

I'm having trouble understanding that bit. What are the a's and b's, room tiles or the world grid? Basically, a room is 160 tiles by 160 tiles, I load the entire room, and the world is (currently, but will eventually be a lot larger) 6 by 6 rooms. The player views about 30x30 tiles or so. The problem is when the player gets to near end of the room. I'm probably misunderstanding what's written above, because that would only work if I loaded 4 entire separate rooms...(9 really since I need to load each corner)? Is there overlapping tiles or no overlapping?

Edited by greep, 04 March 2012 - 06:42 AM.

  • 0

#4 FoxInABox

FoxInABox

    GMC Member

  • GMC Member
  • 5886 posts
  • Version:GM:Studio

Posted 04 March 2012 - 07:01 AM

yeah, sorry for that >< it's supposed to be tiles .. as if your rooms were 4x4 instead of 120x120

.. and since you show 30x30 tiles you would have 32x32 loaded at the same time, using file_bin_seek(fileid,pos) to get the exact tiles .. hm .. pfh, should I try to make a example .. that will take a moment ><

and no, there is no overlapping

Edited by FoxInABox, 04 March 2012 - 07:01 AM.

  • 0

#5 greep

greep

    Menaces with Spikes

  • GMC Member
  • 2398 posts
  • Version:GM7

Posted 04 March 2012 - 07:03 AM

Ah file bin seek. Sorry this is my first time doing binary files, I didn't take a full look at the functions. I'll take a look at that a bit, and see if I need more help in half an hour or so.

Edit: Ah that actually might not work. I need the whole room loaded basically because it's not just the player that needs to know the tile info, it's all the other units in the room. And I can't just have a partial room, since I can't have half a town running really.

I think I'm going to end up doing the 4corner(20x20)/4side(20x120)/1center(120x120, where the main area stuff is contained) style. This will make saving and loading a bunch easier, and for creation I could just load a full 160 grid and split the saving up. Unless you see foresee any problems with that method?

Edited by greep, 04 March 2012 - 07:46 AM.

  • 0




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users