Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
I hit my head and got a really good idea... (seriously)
#1
Okay right now, for NPCs everytime they're supposed to start moving, the server does a for i = 1 to max_maps, then inside of that it does a for x = 1 to max_map_npcs (or something like that).... wouldn't it be much better... to use a multi-dimensional array, to store the NPCs location (map, x/y), so you could avoid those two loops altogether? Would it make more sense to constantly update memory with their locations rather than run thousands of loops every X amount of time? (2500 Maps x 20 Map Npcs... lots of loops just to MOVE them)

My thought was just, as soon as they spawn... store their location in an array. Then just update from there, rather than return hundreds and hundreds of 'exit subs/functions' because it ran through an unnecessary loop...
Reply
#2
But dont you still need to loop the same amount of times to run (map, x,y)?

Cause you still need to loop through Map, x and y.
Reply
#3
Well, an array that side could work, but just imagine the memory. The stored value much be Byte(imagining you have 20 npcs each map). Now considering your 2500 maps and lets say a 0-15,0-11(16X12 map). So its 2500X16X12 bytes, each byte variable uses 1 byte(lol). That's 480000 bytes. Or 480k bytes. Is not that much, is almost nothing xD. Now, lets say you'll need to check if a players is close to a npc and looking at him. You'll have the player's map and then check if an npc's x is the player's x + 1, simple... Just do check the table and see it there is any npc over there. If there is, use the value stored as the mapnpcnum. It seams to work and seams to be faster, do a few tests and tell us about it. ^^
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)