[]Laya.Pool用法

屏蔽的代码是想用pool实现的,结果不行,请指点:
 module com.bigao.h5.ProtoPool {
    import Pool = Laya.Pool;
    // import proto = com.bigao.h5.proto
    /**
     * 协议对象池
     * Author :Terry  
     * Created: 2017-08-07 09:44:25
     */
    export class ProtoPool {
        private static _dic: Laya.Dictionary;

        public static PROTO_HEAD: string = "proto_Head";
        public static PROTO_BINARY_REQUEST: string = "proto_BinaryRequest";

        public static PROTO_PARAMS: string = "proto_ParamsProto";
        public static PROTO_DOUBLE_VLAUE: string = "proto_ParamsProto";
        public static PROTO_FLOAT_VLAUE: string = "proto_ParamsProto";
        public static PROTO_INT64_VLAUE: string = "proto_ParamsProto";
        public static PROTO_BOOL_VLAUE: string = "proto_ParamsProto";
        public static PROTO_STRING_VALUE: string = "proto_ParamsProto";
        constructor() {
            // Pool.recover(ProtoPool.PROTO_HEAD, new com.bigao.h5.proto.Head());
            // Pool.recover(ProtoPool.PROTO_BINARY_REQUEST, new com.bigao.h5.proto.BinaryRequest());

            // Pool.recover(ProtoPool.PROTO_PARAMS, new com.bigao.h5.proto.ParamsProto());
            // Pool.recover(ProtoPool.PROTO_DOUBLE_VLAUE, new com.bigao.h5.proto.DoubleValue());
            // Pool.recover(ProtoPool.PROTO_FLOAT_VLAUE, new com.bigao.h5.proto.FloatValue());
            // Pool.recover(ProtoPool.PROTO_INT64_VLAUE, new com.bigao.h5.proto.Int64Value());
            // Pool.recover(ProtoPool.PROTO_BOOL_VLAUE, new com.bigao.h5.proto.BoolValue());
            // Pool.recover(ProtoPool.PROTO_STRING_VALUE, new com.bigao.h5.proto.StringValue());

            // _dic
            ProtoPool._dic = new Laya.Dictionary();
            ProtoPool._dic.set(ProtoPool.PROTO_HEAD, new com.bigao.h5.proto.Head());
            ProtoPool._dic.set(ProtoPool.PROTO_BINARY_REQUEST, new com.bigao.h5.proto.BinaryRequest());

            ProtoPool._dic.set(ProtoPool.PROTO_PARAMS, new com.bigao.h5.proto.ParamsProto());
            ProtoPool._dic.set(ProtoPool.PROTO_DOUBLE_VLAUE, new com.bigao.h5.proto.DoubleValue());
            ProtoPool._dic.set(ProtoPool.PROTO_FLOAT_VLAUE, new com.bigao.h5.proto.FloatValue());
            ProtoPool._dic.set(ProtoPool.PROTO_INT64_VLAUE, new com.bigao.h5.proto.Int64Value());
            ProtoPool._dic.set(ProtoPool.PROTO_BOOL_VLAUE, new com.bigao.h5.proto.BoolValue());
            ProtoPool._dic.set(ProtoPool.PROTO_STRING_VALUE, new com.bigao.h5.proto.StringValue());



        }
        // get getHead(): com.bigao.h5.proto.Head {
        //     return Pool.getItemByClass(ProtoPool.PROTO_HEAD, com.bigao.h5.proto.Head);
        // }
        // private aaaa: com.bigao.h5.proto.BinaryRequest;
        // get getBinaryRequest(): com.bigao.h5.proto.BinaryRequest {
        //     return this.aaaa = Pool.getItemByClass(ProtoPool.PROTO_BINARY_REQUEST, com.bigao.h5.proto.BinaryRequest);
        // }
        // get getParams(): com.bigao.h5.proto.ParamsProto {
        //     return Pool.getItemByClass(ProtoPool.PROTO_PARAMS, com.bigao.h5.proto.ParamsProto);
        // }
        // get getDouble(): com.bigao.h5.proto.DoubleValue {
        //     return Pool.getItemByClass(ProtoPool.PROTO_DOUBLE_VLAUE, com.bigao.h5.proto.DoubleValue);
        // }
        // get getFloat(): com.bigao.h5.proto.FloatValue {
        //     return Pool.getItemByClass(ProtoPool.PROTO_FLOAT_VLAUE, com.bigao.h5.proto.FloatValue);
        // }
        // get getInt64(): com.bigao.h5.proto.Int64Value {
        //     return Pool.getItemByClass(ProtoPool.PROTO_INT64_VLAUE, com.bigao.h5.proto.Int64Value);
        // }
        // get getBool(): com.bigao.h5.proto.BoolValue {
        //     return Pool.getItemByClass(ProtoPool.PROTO_BOOL_VLAUE, com.bigao.h5.proto.BoolValue);
        // }
        // get getString(): com.bigao.h5.proto.StringValue {
        //     return Pool.getItemByClass(ProtoPool.PROTO_STRING_VALUE, com.bigao.h5.proto.StringValue);
        // }

         get getHead(): com.bigao.h5.proto.Head {
            return  ProtoPool._dic.get(ProtoPool.PROTO_HEAD);
        }
        get getBinaryRequest(): com.bigao.h5.proto.BinaryRequest {
            return  ProtoPool._dic.get(ProtoPool.PROTO_BINARY_REQUEST);
        }
        get getParams(): com.bigao.h5.proto.ParamsProto {
            return  ProtoPool._dic.get(ProtoPool.PROTO_PARAMS);
        }
        get getDouble(): com.bigao.h5.proto.DoubleValue {
            return  ProtoPool._dic.get(ProtoPool.PROTO_DOUBLE_VLAUE);
        }
        get getFloat(): com.bigao.h5.proto.FloatValue {
            return  ProtoPool._dic.get(ProtoPool.PROTO_FLOAT_VLAUE);
        }
        get getInt64(): com.bigao.h5.proto.Int64Value {
            return  ProtoPool._dic.get(ProtoPool.PROTO_INT64_VLAUE);
        }
        get getBool(): com.bigao.h5.proto.BoolValue {
            return  ProtoPool._dic.get(ProtoPool.PROTO_BOOL_VLAUE);
        }
        get getString(): com.bigao.h5.proto.StringValue {
            return  ProtoPool._dic.get(ProtoPool.PROTO_STRING_VALUE);
        }


        private static _instance: ProtoPool;
        static get instance(): ProtoPool {
            if (this._instance == null) {
                this._instance = new ProtoPool();
            }
            return this._instance;
        }
    }
}
已邀请:

Monica - 知识达人

赞同来自:

你可以看下飞机大战的做法,源代码在交流群中,直接下载即可

要回复问题请先

商务合作
商务合作