ID:153276
Jul 22 2004, 6:10 am
|
|
I have to do it. For my night procedure I have to loop through all obj and all turfs and turn their icon_states to "night". But this obviously causes massive lag because my map is quite large. My first question is, would I be better off looping through all atoms in the world and have it only affect turfs and objs, or have two loops, one for objs, one for turfs? My second question is, does anyone have any ideas how I can cut down on the lag that the world is going to experience during these changes. Thanks for your help in advance.
|
Jul 22 2004, 7:06 am
|
|
I would suggest figuring out a way to only show weather effects on parts of the map players are inhabiting.
|
A good alternative for night-time effects is simply to blanket all <code>/area</code>s with a dither overlay. This is MUCH faster, and it means you don't have to make "night" states for everything; unfortunately, a dither doesn't look quite as good. You'll have to decide whether you're willing to make that trade-off. I had to make that choice with Thieves, but the game became a lot easier to make once I decided to go with dithers.
If you're a BYONDscape subscriber or can pay the $1 necessary to subscribe, you can get Shadowdarke's sd_DynamicAreaLighting library, which is great for lighting effects of all kinds (including day/night cycles); I used it for Thieves. It's pretty robust and makes the game look purty. I believe he has a demo of it on the hub somewhere if you want to try before you buy. It uses the areas-with-dithers method too. -------------------- But if you really don't like dithers, here is a collection of thoughts on the matter... You can quickly grab all turfs in the world using block(), as follows: block(locate(1,1,1),locate(world.maxx, world.maxy, world.maxz)) That will enable you to loop through them slightly faster, as DS won't have to go through every single atom in the world and check if it's a turf. How big is your map? Are you really using all those turfs? If not, cutting down on unused turfs could really speed it up. As Jot mentioned, if you can keep track of where players are and update only those regions as needed, that can help a lot. Probably the simplest way to break the map into regions is via Z levels (assuming you have lots of multiple Z levels rather than one or two huge continuous maps). You will need to make sure you update Z levels when players move onto them, though. A decent robust system for this is complicated, so reply here if you want me to elaborate; otherwise I won't bother. =) |
In response to Crispy
|
|
Please, elaborate. :)
|
In response to Jotdaniel
|
|
This is why I always wondered why BYOND didn't have a dynamic map system, and preset what is displayed to all players. I'd much prefer the ability to manually tell BYOND exactly what goes to whom. (But this would be too complex for most users to grasp right away.) I suggest one of two things. Both are bad suggestions. Every atom in the world as two /image objects. All are in lists at the start. one being global/list/day, the other global/list/night. If you want to do this, the overhead will be HUGE. every player that logs in, the list is added to the player's image objects. (Login() if(day) src.client.images.Add(day))
At night, all are removed... this makes it too complex, however. I would normally suggest the dithered terrain overlay. Bad idea, but still much better than the huge lag. Now, here's the second just as bad suggestion. Gather blocks of the view around the players, change those into night. When a player moves, it tries to change that small area into night. This too will be laggy. Don't do either, go with dithered terrain. |
In response to Ter13
|
|
Yes but I have the night icons already done. One thing I was thinking was maybe Putting area/night for example , over all of the turfs and objs I want to change their icon_states to "night". I was also thinking putting all turfs and obj that's states need to change under either turf/night and obj/night so that I'm not changing the turfs and obj I dont need to change. But I really don't like the looks of dithered icons. Any other suggestions?
Also, I was wondering if there is a way to stop all running mob procedures. |
In response to Troglodyte
|
|
Troglodyte wrote:
Yes but I have the night icons already done. Yeah, but you still have to do twice as much work if you ever want to add or change an icon. =) One thing I was thinking was maybe Putting area/night for example , over all of the turfs and objs I want to change their icon_states to "night". I was also thinking putting all turfs and obj that's states need to change under either turf/night and obj/night so that I'm not changing the turfs and obj I dont need to change. You'd still have to loop through all the turfs and objs; it'd be just as slow. But I really don't like the looks of dithered icons. Neither did I, at first. It grows on you. =) Also, I was wondering if there is a way to stop all running mob procedures. Um... well, deleting the mobs would work. =P Short of that, no, not automatically. What exactly are you trying to do? Please, elaborate. :) Damn. So much for being lazy. =P Okay. First you need to keep track of what Z levels are being used. Not too hard. Here's how I'd do it: // We'll use this as an associative list. Now usedZlevels will contain an associative list of each Z level number and the number of players currently on it. It might look something like this: usedZlevels = list("0" = 3 // Z level 0 has three people I had to use strings as the key values, because you can't use plain numbers as key values in DM. Now we have a way of finding out if a Z level is active. So we can do something like this when we change day/night: for (var/Zlevel in usedZlevels) There's only one problem left; if a Z level is inactive and somebody enters it, the day/night cycle won't have updated there, so it will sometimes be wrong. You can fix this by "reviving" the Z level if it's inactive but somebody then enters it; I'll let you try and figure that out yourself. (Hint: mob/Move() would be a good place to start.) This is slightly better than updating everything in the world at once, but it will still create incredible lag spikes (unless your maps are about 10x10 tiles big and you have one player in the game at once), so even though I've just spent 25 minutes writing this up, I recommend you don't do anything I just said. =D But if you're set on it... *shrug* Whatever, it's up to you. It's your game, after all. =) |
Troglodyte wrote:
I have to do it. For my night procedure I have to loop through all obj and all turfs and turn their icon_states to "night". But this obviously causes massive lag because my map is quite large. My first question is, would I be better off looping through all atoms in the world and have it only affect turfs and objs, or have two loops, one for objs, one for turfs? My second question is, does anyone have any ideas how I can cut down on the lag that the world is going to experience during these changes. Thanks for your help in advance. Well you don't have to change the states of all the turfs since it's only a visual effect. Just set the turfs state whevener they get 1 tile outside of the players view. mob/Move() Just replace currenttimestate with something that gets what state a turf or obj should be in at the current game time. Also this doesn't handle objects moving into view but if all your objects are stationary this should be no problem and be nice and quick. |