Register for your free account! | Forgot your password?

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

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

Advertisement



just confuse about this

Discussion on just confuse about this within the CO2 Private Server forum part of the Conquer Online 2 category.

Reply
 
Old   #1
 
marlyandedsel's Avatar
 
elite*gold: 0
Join Date: Aug 2010
Posts: 343
Received Thanks: 21
just confuse about this

can you guys tell me whats good for this code and tell me if this is good or not...Im really learning here but sometime just got confuse or something....

PHP Code:
 public bool Add(Interfaces.IMapObject _object)
        {
            try
            {                
                if (!
_objects.ContainsKey(_object.UID))
                {
                    if (
ServerBase.Kernel.GetDistance(_object.X_object.YOwner.Entity.XOwner.Entity.Y) <= ServerBase.Constants.pScreenDistance)
                    {
                        
_objects.Add(_object.UID_object);
                        
UpdateArray();
                        return 
true;
                    }
                }
                else
                {
                    if (
_objects[_object.UID] == null)
                    {
                        
_objects.Remove(_object.UID);
                        if (
ServerBase.Kernel.GetDistance(_object.X_object.YOwner.Entity.XOwner.Entity.Y) <= ServerBase.Constants.pScreenDistance)
                        {
                            
_objects.Add(_object.UID_object);
                            
UpdateArray();
                            return 
true;
                        }
                    }
                }                
            }
            catch (
Exception e) { Program.SaveException(e); }
          
//  finally { /*Monitor.Exit(_objects);*/ }
            
return false;
        }

        public 
bool Remove(Interfaces.IMapObject _object)
        {
            try
            {
                
//if (Monitor.TryEnter(_objects, 10))
                //{
                
if (_objects.ContainsKey(_object.UID))
                {
                    if (
_object.MapObjType == MapObjectType.Item)
                    {
                        
Network.GamePackets.FloorItem item _object as Network.GamePackets.FloorItem;
                        
item.Type Network.GamePackets.FloorItem.Remove;
                        
item.SendSpawn(Ownerfalse);
                        
item.Type Network.GamePackets.FloorItem.Drop;
                    }
                    else if (
_object.MapObjType == MapObjectType.Player)
                    {
                        
Owner.Send(new Network.GamePackets.Data(true) { UID _object.UIDID Network.GamePackets.Data.RemoveEntity });
                    }
                    
_objects.Remove(_object.UID);
                    
UpdateArray();
                    return 
true;
                }
                
//}
            
}
            catch (
Exception e) { Program.SaveException(e); }
           
// finally { /*Monitor.Exit(_objects);*/ }
            
return false;
        } 
Thank you in advance
marlyandedsel is offline  
Old 09/10/2012, 11:41   #2


 
Korvacs's Avatar
 
elite*gold: 20
Join Date: Mar 2006
Posts: 6,126
Received Thanks: 2,518
That code forms part of a wrapper for a dictionary that adds and removes objects and updates the clients at the same time. I suspect this is part of a screen class.
Korvacs is offline  
Thanks
2 Users
Old 09/10/2012, 15:31   #3
 
marlyandedsel's Avatar
 
elite*gold: 0
Join Date: Aug 2010
Posts: 343
Received Thanks: 21
yes it is part of the screen class.. I just want to know if this is good coding style or bad
marlyandedsel is offline  
Old 09/10/2012, 16:06   #4


 
Korvacs's Avatar
 
elite*gold: 20
Join Date: Mar 2006
Posts: 6,126
Received Thanks: 2,518
Pros and cons to it, its not very concurrent so i would suggest more cons than pros. Its not what i would describe as bad code however.
Korvacs is offline  
Old 09/10/2012, 18:54   #5
 
shadowman123's Avatar
 
elite*gold: 0
Join Date: Aug 2007
Posts: 1,525
Received Thanks: 230
Quote:
Originally Posted by Korvacs View Post
Pros and cons to it, its not very concurrent so i would suggest more cons than pros. Its not what i would describe as bad code however.
could u tell me what are cons / Pros ?
shadowman123 is offline  
Old 09/10/2012, 22:54   #6
 
elite*gold: 21
Join Date: Jul 2005
Posts: 9,193
Received Thanks: 5,380
Quote:
Originally Posted by shadowman123 View Post
could u tell me what are cons / Pros ?
He already said it's not concurrent. Therefor it is going to have issues when you start having multiple threads accessing non thread safe resources.

You're not locking collections or using any concurrent ones.

Simplest solution IMO would be to convert to a ConcurrentCollection so that things cannot be screwed up while you iterate through them.
pro4never is offline  
Thanks
2 Users
Old 09/12/2012, 04:21   #7
 
marlyandedsel's Avatar
 
elite*gold: 0
Join Date: Aug 2010
Posts: 343
Received Thanks: 21
how about if I do like this
PHP Code:
lock(_objects)
                            
_objects.Add(_object.UID_object);
                        
UpdateArray();
                        return 
true
is it okay?
marlyandedsel is offline  
Old 09/12/2012, 14:16   #8
 
elite*gold: 21
Join Date: Jul 2005
Posts: 9,193
Received Thanks: 5,380
Locking creates its own set of issues (deadlocks as well as inefficiency of threads waiting for their turn for objects to be released)

As I said... just use ConcurrentCollections such as ConcurrentDictionary or whatever and you'll be much better off.
pro4never is offline  
Thanks
2 Users
Reply


Similar Threads Similar Threads
Please help here! a little confuse!
07/19/2012 - WarRock - 1 Replies
Can any1 here help me how to find WarRock PH: PlayerPointer ServerPointer NR SnS GlassWalls STW BoneShot
just confuse
06/01/2012 - CO2 Private Server - 7 Replies
what is correct by doing this two option for (int x = 0; x < items.Count; x++) { Interfaces.IConquerItem item = new Network.GamePackets.ConquerItem(true); item.ID = items.Id; item.UID = items.Uid; item.Durability = items.Durability;
How to confuse an Idiot
04/26/2011 - Off Topic - 1 Replies
Wirklich Interessant.
how to confuse a idiot
07/28/2008 - Off Topic - 2 Replies
http://666kb.com/i/b0pdjrsr41xgzexoa.png
kind of confuse
07/28/2008 - Lin2 Exploits, Hacks, Bots, Tools & Macros - 0 Replies
hi, guys i have red most of the important thread ive never use bots in l2 and i wanted to start using it but its really confusing cuz there s no like specific thread that talk about how to use the bots i would like to know if anyone could explain me a lil about the bots cuz i know about the l2walker but dont know wat it actually do and about the l2divine i didn t see nothing that explain wat it is so i was hoping that someone could explain me how to use them properly. thx in advance.



All times are GMT +1. The time now is 08:01.


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.