Beispiel #1
0
        static string NetworkCallback(gamedef.CodeGenPeer peer, string msgType)
        {
            var prefix = "Msg_" + peer.Name + "_";

            var namepack = msgType.Split('.');

            if (namepack.Length == 2)
            {
                var rawName = namepack[1];
                return(prefix + rawName);
            }

            return(prefix + msgType);
        }
Beispiel #2
0
        static void NetworkCallbackBody(CodeGenerator gen, DataContext rootContext, gamedef.CodeGenPeer peer, string msgType)
        {
            // Presenter类已经存在函数了, 不再生成
            if (IsStringExists(rootContext, NetworkCallback(peer, msgType)))
            {
                return;
            }

            gen.PrintLine("public void ", NetworkCallback(peer, msgType), "( NetworkPeer peer, ", msgType, " msg )");
            gen.PrintLine("{");
            gen.In();

            gen.PrintLine();

            gen.Out();
            gen.PrintLine("}");

            gen.PrintLine();
        }
Beispiel #3
0
        static void NetworkRegisterBody(CodeGenerator gen, gamedef.CodeGenPeer peer)
        {
            gen.PrintLine(NetworkPeerInstance(peer), " = PeerManager.Instance.Get(\"", peer.Name, "\");");
            gen.PrintLine();

            foreach (string msgType in peer.RecvMessage)
            {
                gen.PrintLine(NetworkPeerInstance(peer), ".RegisterMessage<", msgType, ">( obj =>");
                gen.PrintLine("{");
                gen.In();

                gen.PrintLine(NetworkCallback(peer, msgType), "( ", NetworkPeerInstance(peer), ", obj as ", msgType, " );");

                gen.Out();
                gen.PrintLine("});");

                gen.PrintLine();
            }
        }
Beispiel #4
0
 static string NetworkPeerInstance(gamedef.CodeGenPeer peer)
 {
     return("_" + peer.Name + "Peer");
 }
Beispiel #5
0
 static void NetworkDeclare(CodeGenerator gen, gamedef.CodeGenPeer peer)
 {
     gen.PrintLine("NetworkPeer ", NetworkPeerInstance(peer), ";");
     gen.PrintLine();
 }