Alright, so I've been thinking of something awesome, but the downside is that I will be forced into looping through a certain type of tile in a specified Z-layer.
I am pretty much new at this, so help on how to do this would be very much appreciated.
May 20 2013, 5:50 pm
|
|
You could loop through every turf in the world and only check ones whose Z level is what you want, or if you don't want to do this every time you can keep a list of turfs for each Z level and search through that list.
|
Keeping lists of things you need to quick access to is always the best way to do this because it uses more memory but less CPU.
For example, every time a turf of the type you care about is created, you can add it to a list... var/list/turfs_cared_about = list() |
Below allows you to store the turfs wanted in specific lists to their specified Z level.
var/global/Get_Turfs/Turf_Datum=new/Get_Turfs |
In response to Kozuma3
|
|
Why did you use a datum for those two procs?
|
In response to Albro1
|
|
Albro1 wrote:
Why did you use a datum for those two procs? For future use, if anything is needed. |
I end up with this code:
[code] set background = 1 var/global/list/tiles = list() for(var/turf/space/T in world) if(T.z == 1) tiles.Add(T) T.icon = 'poop.dmi'[/code] It works just fine and doesn't seem to lag in the slightest, so I think I'm going to stick to the easy and small code here, but your help was appreciated. And I did get to learn how others would do this. So thank you. |
Galactic Soldier wrote:
I have a few points to make:
I made a better alternative based off your schematic: var/zCycle/zCycle = new Doesn't work, please test it before posting. |
After bench-marking both of them, I see no difference.
Profile results (total time) |
I'm doing this logically, by increasing the map_size and such.
There isn't a point calling it over and over 100,000 times. |
I think you're doing something wrong ^^.
And I don't think listening to you would help me approve seeing as how you gave bad code right from the beginning. |
50 - 70 ms across 100,000 calls isn't even worth even quibbling over, when the total magnitude of this is still measured in sub-one second for said 100,000 calls.
What would make more sense, if you are going to get pedantic, is to discuss maintainability, and readability. Truthfully, though? Whatever! Really, you could do either solution and that would be just fine and dandy. OP can use either solution, quite happily. |
Galactic Soldier wrote:
Sorry, I misread. But mine appendages the list, while yours creates an entire new one for no explicit reasoning. Of course mine would perform a little slower but it'd give intended results, unlike yours. They do the exact same thing - are you sure you tested mine? |
Galactic Soldier wrote:
Kozuma3 wrote: Silly? That's your opinion, Please continue learning. ^^ |
Galactic Soldier wrote:
Kozuma3 wrote: I guess you could remove it then ^^, it's commented out after all. I gave you advice. Take it and learn from it. Poor "advice" at that. |
Can I ask you two to take this discussion offline or to your pager? This back and forth has long stopped being a useful thing for the topic it's in.
|
Galactic Soldier wrote:
It serves functionality in the code I provided, but not yours. Poor advice isn't advice that serves as an improvement. Remove the simple comment on it then so you'll stop ranting. I really think you should consult the DM Guide, you used things out of intended context like using the global modifier in the global scope. Absolutely redundant. It helps for readability. Anything else you want to go on about? |
In response to Stephen001
|
|
Stephen001 wrote:
Can I ask you two to take this discussion offline or to your pager? This back and forth has long stopped being a useful thing for the topic it's in. Will do. |