setPublicID() public method

public setPublicID ( int id ) : void
id int
return void
Exemplo n.º 1
0
        //MapContent::~MapContent()
        //{
        //    for (int i = 0; i < 256; ++i)
        //    {
        //        delete buckets[i];
        //    }
        //    delete[] zones;
        //}
        public bool allocate(Actor obj)
        {
            // First, try allocating from the last used bucket.
            ObjectBucket b=buckets[last_bucket];
            int i=b.allocate();
            if(i>=0)
            {
                b.objects[i]=obj;
                obj.setPublicID(last_bucket*256+i);
                return true;
            }

            /* If the last used bucket is already full, scan all the buckets for an
               empty place. If none is available, create a new bucket. */
            for(i=0; i<256; ++i)
            {
                b=buckets[i];
                if(b!=null)
                {
                    /* Buckets are created in order. If there is nothing at position i,
                       there will not be anything in the next positions. So create a
                       new bucket. */
                    b=new ObjectBucket();
                    buckets[i]=b;
                    Logger.Write(LogLevel.Debug, "New bucket created");
                }
                int j=b.allocate();
                if(j>=0)
                {
                    last_bucket=i;
                    b.objects[j]=obj;
                    obj.setPublicID(last_bucket*256+j);
                    return true;
                }
            }

            // All the IDs are currently used, fail.
            Logger.Write(LogLevel.Error, "unable to allocate id");
            return false;
        }