An object-oriented approach to the difference between data exchange networks--the development of seamless switching to single game C/s mode

Source: Internet
Author: User

Previous This article describes the differences between the development process of describing data support points, here is another feature shown here: the development of seamless switching to independent C/s mode

The general C/S model faces a problem:

is the debugging problem in the development process, because it involves the client and the service-side related methods, it is also a simple matter to write by someone.

The assumption is written by 2 people, which brings some differences in platform and coding.

To put it simply, let's say that we completely avoid C/S at development, and then through a mechanism that allows the module to run directly to the server, it will increase your development speed by several magnification.

There is no agreement, no interaction, no network, then from the beginning to the end, is also a relatively simple thing, no dedicated service end of the main course (looks like the man is unemployed ...). ><.

First of all, the combination of differentiated network data interactive mode of development mode, compared to a more round.

In terms of patterns, the traditional MVC pattern is much more similar.

1.Model layer, define and describe the entire scene, refinement to each data object, HP,MP, etc.

2.View (UI) layer,

2.1 Bind the corresponding data to a display element on the UI, and refresh the data on the UI when the data changes.

2.2 When a user activates a control, issues a command and, when the command responds, runs the appropriate callback method

3.Control layer, the logic of the corresponding application layer, for example, change a certain value


This is the local single-machine development mode, and then is the focus of this article, how to switch the standalone mode to the C/S mode.

The previous article, if the synchronization problem between the 2 model,

Then the M/C 2 layer is copied to the server, and then synchronize the local model and the remote model through the synchronization protocol, the switch succeeds.

Take a look at the remote process:

Ui-> local model-> issuing command, waiting for callback----Send to Remote Run command---- change remote model-> get return value and differential data

The local model activates UI churn events with return values and differential data synchronization, and changes the binding UI element, run callbacks

Single-Machine development process:

Ui-> Local model-> Issue command, wait for callback---run command--change model-> Activate UI churn event, change binding UI element, run callback

You can switch to the C/S mode only after a simple layer of bridging between the callbacks and the callback.

Here is a demo example of the difference between the agent layer and the actual control layer

    public class Model:System.ComponentModel.INotifyPropertyChanged {private string _name = null;        private int _count = 0;            public string Name {get {return _name;}                    set {if (_name! = value) {_name = value;                OnPropertyChanged ("Name");            }}} public int Count {get {return _count;}                    set {if (_count! = value) {_count = value;                OnPropertyChanged ("Count");        }}} public event System.ComponentModel.PropertyChangedEventHandler propertychanged; public void OnPropertyChanged (string name) {if (propertychanged! = null) {Pr            Opertychanged (This, new PropertyChangedEventArgs (name)); }}//<summary>    Actual Control class///</summary> public class Modelcontrol:model {public virtual void ChangeName (stri ng name, Action callback) {this.            name = name;            if (callback! = NULL) {callback (); }} public virtual void Changecount (int count, Action callback) {this.            Count = Count;            if (callback! = NULL) {callback ();               }}}///<summary>///Agent///</summary> public class Remotemodelcontrol:model { public void Changecount (int count, Action callback) {Remotecall.buildrequest (callback, "        Changecount ", count,null); The public void ChangeName (string name, Action callback) {Remotecall.buildrequest (callback, "Chan        Gename ", name, NULL); }    }


An object-oriented approach to the difference between data exchange networks--the development of seamless switching to single game C/s mode

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.