Register for your free account! | Forgot your password?

Go Back   elitepvpers > MMORPGs > Conquer Online 2 > CO2 Private Server
You last visited: Today at 15:49

  • Please register to post and access all features, it's quick, easy and FREE!

Advertisement



Qestion: its a Math matter tho!

Discussion on Qestion: its a Math matter tho! within the CO2 Private Server forum part of the Conquer Online 2 category.

Reply
 
Old   #1
 
{ Angelius }'s Avatar
 
elite*gold: 0
Join Date: Aug 2010
Posts: 992
Received Thanks: 1,110
Qestion: its a Math matter tho!

is there any better way to define the Range?
PHP Code:
for (int i 018i++)
{
var 
Add from d in Dictionary.Clients
where Math
.Max(Math.Abs(d.Value.Client.X), Math.Abs(d.Value.Client.Y)) < i
select 
(d.Key);
foreach (
uint Char in Add)
if (!
Clients.Contains(Char))
Clients.Add(Char);
//i need to find another way to do it so i dont have to loop + foreach at the same time !

{ Angelius } is offline  
Old 03/15/2011, 03:15   #2
 
elite*gold: 21
Join Date: Jul 2005
Posts: 9,193
Received Thanks: 5,380
I don't see what the for 18 loop is being used for in that case...


What are you trying to actually do?

You're pulling distance and then lowering distance every time?... Depending on what it is you're trying to do I don't see what use the for loop has... You want to pull things within 18 dist... great then why do you keep looping over and over while lowering the range?
pro4never is offline  
Thanks
1 User
Old 03/15/2011, 03:33   #3
 
{ Angelius }'s Avatar
 
elite*gold: 0
Join Date: Aug 2010
Posts: 992
Received Thanks: 1,110
Quote:
Originally Posted by pro4never View Post
I don't see what the for 18 loop is being used for in that case...


What are you trying to actually do?

You're pulling distance and then lowering distance every time?... Depending on what it is you're trying to do I don't see what use the for loop has... You want to pull things within 18 dist... great then why do you keep looping over and over while lowering the range?
well here is the thing .

Code:
for (int i = 0; i < 18; i++)
{
var Add = from d in Dictionary.Clients
[COLOR="Red"]where Math.Max(Math.Abs(d.Value.X - Client.X), Math.Abs(d.Value.Y - Client.Y)) < i[/COLOR]
select (d.Key);
foreach (uint Char in Add)
if (!Clients.Contains(Char))
Clients.Add(Char);
the red line must pick from the Dictionary that contains all the game clients where the distance = i
so i dont have to foreach all the game clients looking for an = distance
that way it picks all the in range (18) players and add them to a list
and if i dident for loop than it'll pick only the whatever distance i ask it to look for

annnd when im done coding the whole thing i was like **** i did all that work to avoid the LONG foreach to end up with an = or maybe greater foreach time :P

and so i had to ask somebody
{ Angelius } is offline  
Old 03/15/2011, 03:38   #4
 
Nullable's Avatar
 
elite*gold: 0
Join Date: Nov 2009
Posts: 390
Received Thanks: 321
The first loop is useless.
Code:
var Add = from d in Dictionary.Clients
where Math.Max(Math.Abs(d.Value.X - Client.X), Math.Abs(d.Value.Y - Client.Y)) < [color="red"]18[/color]
select d.Key;
//continue your stuff here.
Nullable is offline  
Thanks
1 User
Old 03/15/2011, 03:42   #5
 
elite*gold: 0
Join Date: Jun 2009
Posts: 787
Received Thanks: 314
^
||


var query = from d in Dictionary.Clients
where Distance(d.Value.X, d.Value.Y, Client.X, Client.Y) <= 18
select d.Key;

Clients.AddRange(query); // (depending on the kind of collection clients is)

The way you're doing it looks at clients WITHIN 1 distance, then WITHIN 2 distance (inclusive of 1 distance, obviously), then 3.. then 4.. then 5.. all greater values are inclusive. You don't need to loop; the < operator works the way it should.
_tao4229_ is offline  
Thanks
1 User
Old 03/15/2011, 04:20   #6
 
{ Angelius }'s Avatar
 
elite*gold: 0
Join Date: Aug 2010
Posts: 992
Received Thanks: 1,110
all right guys thanks for the quick help/ answers but..

how come when i had the for loops placed all over the spawns voids it took like 0 to 1 cpu usage peer jump and when i removed it all it went up to 2/3 cpu usage peer jump ?
{ Angelius } is offline  
Old 03/15/2011, 20:28   #7


 
Korvacs's Avatar
 
elite*gold: 20
Join Date: Mar 2006
Posts: 6,126
Received Thanks: 2,518
The system your using is never going to be fast, because you query everyone either on the map or on the server, you need a spatial positioning system if you want it to be quick.
Korvacs is offline  
Old 03/15/2011, 21:08   #8
 
{ Angelius }'s Avatar
 
elite*gold: 0
Join Date: Aug 2010
Posts: 992
Received Thanks: 1,110
Quote:
Originally Posted by Korvacs View Post
The system your using is never going to be fast, because you query everyone either on the map or on the server, you need a spatial positioning system if you want it to be quick.
yes Korvacs i figured that thought but this is how im doing it by now i guess this way the i can control/edit/pull/only the current map clients/npcs/etc

i'll be providing this collection in every map
Quote:
public Map()
{
Mobs = new Dictionary<uint, Mob>();
Npcs = new Dictionary<uint, Npc>();
Clients = new Dictionary<uint, Character>();
Items = new Queue<Items.ItemGround>();
}

on creation lets say npcs i go like
Quote:
if (!Dictionary.Maps.ContainsKey(NPC.Map))
Dictionary.Maps.Add(NPC.Map, new Map(0));
if (!Dictionary.Maps[NPC.Map].Npcs.ContainsKey(NPC.UID))
{
Dictionary.Maps[NPC.Map].Npcs.Add(NPC.UID, NPC);
}
and when i need to pull the local npcs im doing like
Quote:
var Adds = from NPC in Dictionary.Maps[Client.Map].Npcs
where Math.Max(Math.Abs(NPC.Value.X - Client.X), Math.Abs(NPC.Value.Y - Client.Y)) < 18
select NPC.Value;
foreach (Npc N in Adds)
{
if (!Client.LocalNpcs.ContainsKey(N.UID))
{
Client.LocalNpcs.Add(N.UID, N);
Contacts.Send(Packets.NewNpc(N), Client);
}
}
and so it gose the same for players/mobs/etc

i dont know but thats what it seems to be the best way to deal with it
{ Angelius } is offline  
Old 03/17/2011, 19:43   #9
 
-PhysiX-'s Avatar
 
elite*gold: 0
Join Date: Dec 2008
Posts: 16
Received Thanks: 8
that plus the screen system in saints or hybrids source
-PhysiX- is offline  
Reply


Similar Threads Similar Threads
[Quest]math.cos und math.sin
08/22/2010 - Metin2 Private Server - 10 Replies
Hallo, anscheinend kennt Metin2 die Funktionen math.cos und math.sin nicht, gibt es trotzdem eine Möglichkeit die irgendwie zu benutzen? (Für den DT ;))
iSRO Math
08/03/2009 - Silkroad Online - 30 Replies
Close
Math/var help
07/02/2009 - CO2 Private Server - 1 Replies
Ok simplifying this post alot. How do I transfer things already loaded into the source from a database into the useitem area? Maybe I'm over complicating things but I am not able to do it.. In my Database.cs I have Struct.SPoints Port = new Struct.SPoints(); loading in things from the database. I need a way to apply those values to a similar code in UseItem.cs where I have my public static void ScrollPointTele(int PointId, int MapEnd, int PointX, int PointY, ClientSocket CSocket)
Any good at math
12/11/2006 - Eudemons Online - 3 Replies
Ok I posted a mesage earlier saying im wanting to hack this game. If you want email me for the VB code and i will send you a sample program (not compiled so its 100% virus free) to help you adjust game values. My program will be more usefull however when I find the real address for the character position. Now in replies to my earlier posts some dummy tried saying rotate 45 degrees bla bla bla. I've tried this and still havent got it right. Besides if you notice as you walk around there are no...



All times are GMT +1. The time now is 15:49.


Powered by vBulletin®
Copyright ©2000 - 2026, Jelsoft Enterprises Ltd.
SEO by vBSEO ©2011, Crawlability, Inc.
This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

Support | Contact Us | FAQ | Advertising | Privacy Policy | Terms of Service | Abuse
Copyright ©2026 elitepvpers All Rights Reserved.