- Clipboard01.jpg (16.98 KiB) Viewed 26712 times
It's time for an update. Currently I work on the network code. Today I added a negative number of lines of code to the project. This means I reworked some code I had written earlier which did not work very well and wrote it so that it works better and achieved this with fewer lines. The classical example why quality is always much more important than quantity. Also the improvement was mainly making things easier. It turned out that all my previous thoughts were just to difficult and cumbersome. Now I have a simple and hopefully workable solution.
Still for just displaying a single line of text (title of an available scenario in a list selection) a lot of steps must be taken. Especially if there are potentially two computers and the second computer delivers the list of scenarios (as it's the case with multiplayer).
Just for fun and for those interested here a list of steps that take place internally to get to this result:
1. Create empty list view
2. Register this list view as destination of any network messages with a certain ID (number)
3. Send a certain request (specified by an ID) to the server asking for scenario titles
3.a Serialize this request and all attached data to a unicode string (json, pickle, xml, ..)
3.b Encode this unicode string into bytes
3.c Compress this byte sequence (zip, gzip, ..)
3.d Wrape this byte sequence in a Qt ByteArray (just keeps the length and can be sent as a whole)
3.e Send over TCP
4. Receive a request on the server side
4.a Obtain a Qt ByteArray
4.b Uncompress the byte sequence
4.c Decode into unicode string
4.d Deserialize into Python object
5. Look up table (in Python a dictionary) to find service associated with the ID and call this service
6. Service looks up all scenario files in the save games directory
7. Service reads all scenario files and memorizes scenario titles and file names
8. Service composes a Python object (response message) including this data
9. Server sends response message back to Client (see 3.a to 3.e)
10. Client receives response message (see 4.a to 4.d)
11. Client sends response message according to its ID to the list view (which had itself registered for it in step 2)
12. List view updates itself and shows scenario titles
13. List view deregisters itself (there won't be another message of this type coming)
14. User can see and select scenario titles
15. If user select a specific scenario client sends again message asking for more details and registers itself to obtain the answer for this new case
...
I hope this give a good insight into how you do such things programmatically. Fortunately for us in Python each of these steps is only a few lines of code (sometimes only one). In Java or C++ programming all this would probably take much, much more time.