game area
Moderator: General Moderators
- elecktricity
- Forum Contributor
- Posts: 128
- Joined: Sun Sep 25, 2005 8:57 pm
- Location: Trapped in my own little world.
- Contact:
game area
Me and my partner are in the process of making a game, we decided on 10,000 by 10,000 spots which is 100,000,000, obviously if you have that many rows in a database it would go ultra slow, im not really sure how else to go about doing this, its for a game so the array would need to have info on that part of land like whats on it and such, so we could easily just seperate theinfo but semicolons and explode it, but this might go majorly slow, it would need to display about 10 by 10 on each page, would a huge array like that make the site run slow? If so is there any other way going about doing this?
- Christopher
- Site Administrator
- Posts: 13596
- Joined: Wed Aug 25, 2004 7:54 pm
- Location: New York, NY, US
- elecktricity
- Forum Contributor
- Posts: 128
- Joined: Sun Sep 25, 2005 8:57 pm
- Location: Trapped in my own little world.
- Contact:
He means only add the coordinates of which you use instead of having all of the coordinates in the table.
I also tried something similar to this and this method is the best way. NO, it will not be slow, it just depends on how you handle the array.
For a 10x10 array you are talking milliseconds, depending on how you run through the array and optimizations you do.
The table can have the x, y coordinates.
First person: 0,0
The surrounding coordinates would be the ones you fetch for 0,0. If the row does not exist then you know that there is no one there.
SQL would be something like this:
I also tried something similar to this and this method is the best way. NO, it will not be slow, it just depends on how you handle the array.
For a 10x10 array you are talking milliseconds, depending on how you run through the array and optimizations you do.
The table can have the x, y coordinates.
First person: 0,0
The surrounding coordinates would be the ones you fetch for 0,0. If the row does not exist then you know that there is no one there.
Code: Select all
-1,1 | 0,1 | 1,1
-1,0 | 0,0 | 1,0
-1,-1| 0, -1 | 1, -1Code: Select all
$x = 0;
$y = 0;
$sql = "SELECT * FROM coordinates WHERE x BETWEEN ". ($x-1) ." AND ". ($x+1) ." AND y BETWEEN ". ($y-1) ." AND ". ($y+1);
Last edited by santosj on Sun May 28, 2006 7:06 pm, edited 1 time in total.
You could take the 'interesting/un-interesting' approach.
Only store locations that have interesting qualities, and all that aren't stored are un-interesting.
For example, lets say its an old medeival style game, and you have plots of land that have pigs, or woods, or the like.
Then you might have 1 in 10 plots that have a resource. The rest would all be "uninteresting", and as a result would contain no resources.
It all depends on how you want to parcel things out, but its a winning strategy that a number of games have used.
In addition, you can also (or instead) use the 'explored/unexplored' method, where you only store sectors that have been explored. The problem with that approach is that you end up with the database growing substantially over time, unless those plots can change/move after being explored.
Explain further how you want a parcel/sector/unit of land to act, and we can give better specifics.
Only store locations that have interesting qualities, and all that aren't stored are un-interesting.
For example, lets say its an old medeival style game, and you have plots of land that have pigs, or woods, or the like.
Then you might have 1 in 10 plots that have a resource. The rest would all be "uninteresting", and as a result would contain no resources.
It all depends on how you want to parcel things out, but its a winning strategy that a number of games have used.
In addition, you can also (or instead) use the 'explored/unexplored' method, where you only store sectors that have been explored. The problem with that approach is that you end up with the database growing substantially over time, unless those plots can change/move after being explored.
Explain further how you want a parcel/sector/unit of land to act, and we can give better specifics.
- elecktricity
- Forum Contributor
- Posts: 128
- Joined: Sun Sep 25, 2005 8:57 pm
- Location: Trapped in my own little world.
- Contact:
I like the idea santosj menchioned but each segment of land would be in more than one type of thing:
1-1 would display:
2-1 would display:
2-2 would display:
I dont really thing the 'unexplored/explored' method would help much, I would like an endless type of thing but would really strain how much space I have, I could easily use to much, hosts dont like that.
I think the idea to only store things that are different than others, I might do some brainstorming on that idea, would this might be easier in a different language or something like java or something of the sorts, would have to randomly place stuff places, so it might timeout while im adding things to the database not really sure, ill have to do some tests.
Any more ideas out there? would love to hear them.
1-1 would display:
Code: Select all
1-1 | 1-2 | 1-3 |... |1-10
2-1 | 2-2 | 2-3|... |2-10
3-1 | 3-2 | 3-3|... |3-10
...
10-1 | 10-2 | 10-3| ... | 10-10Code: Select all
2-1 | 2-2 | 2-3|... |2-10
3-1 | 3-2 | 3-3|... |3-10
4-1 | 4-2 | 4-3|... |4-10
...
11-1 | 11-2 | 11-3| ... | 11-10Code: Select all
2-2 | 2-3 | 2-4|... |2-11
3-2 | 3-3 | 3-4|... |3-11
4-2 | 4-3 | 4-4|... |4-11
...
11-2 | 11-3 | 11-4| ... | 11-11I think the idea to only store things that are different than others, I might do some brainstorming on that idea, would this might be easier in a different language or something like java or something of the sorts, would have to randomly place stuff places, so it might timeout while im adding things to the database not really sure, ill have to do some tests.
Any more ideas out there? would love to hear them.
I think that, that would work best for our world. I'll start workin' on a bit of that too..Perhaps instead of creating a huge grid you could store the record keys the nine adjacent squares in each square record. Then you could start with the first square and add adjacent rows as you add them. Also that way you do not have to have a contiguous, rectangular world.
Well, if you only store the coordinates and what is in it, then that would only be 3 to 5 fields. If you set the type of the field correctly, then the table should be small enough and if you optimize the query well enough then it shouldn't be that much of a strain space and processing wise. If you use PHPmyAdmin, then it will help you decide what the field types should be.
I was going to use this method also... wait I am using this method. I don't have enough players to know if it works well or not. It was pretty easy to implement.
I was going to use this method also... wait I am using this method. I don't have enough players to know if it works well or not. It was pretty easy to implement.
- Christopher
- Site Administrator
- Posts: 13596
- Joined: Wed Aug 25, 2004 7:54 pm
- Location: New York, NY, US