Java learning notes swing-Basic swing Program (distribution of map layers and storage of graphic resources)

Source: Internet
Author: User

Recently, many annoying things have been mentioned. In fact, mapseditor has no scruples, and there are not many functions available. There are so many ready-made functions available on the market, the well-developed map editor has not yet reached the realm of integration and integration for Java, and the useful class libraries are all completely unknown, so the recent steps have been hard, it may be easier for someone to walk together. Programmers need to exchange ideas ......

Recently, the csdn blog has finally been okay. At least my blog is back to normal and can be edited to display and aggregate ...... Thanks to the hard work of our management staff ...... There are also many incidents in the recent incidents. My mother is going to be hospitalized and frequently suffers from illness. She can only smile, but no one can talk to her ...... I think GF is not good enough to say anything to her. When people are still passing through the river, they are waiting for me to comfort and enlighten them. If they take care of me in turn, they will be a bit cool, at least I have to show what I can do now. Because of Gu's, there is no way to take care of it here, and there have been no new articles published for a long time. I think the text I wrote is the blood flowing in my blog. A long time of stagnation will cause tissue necrosis of the blood flowing through ...... There is no rigid rule on how much heartbeat is required for a minute, but at least it must ensure sound performance. The slow stream is also the stream ......

Back to mapseditor, you have to pay attention to two problems:1. Hierarchical display of the map. 2. Format and storage of map resources. 

The hierarchical display of a map is particularly important. Aside from the Editable and reusable tones that can be optimized in the future, it is necessary for the display effect alone, in the future, the convenience of reuse will become more obvious. First, let alone direct program plotting (no longer loading the map editor into the resource range). The map you want to display is of course an external image file, so transparent pictures become necessary resources. For example, there are two images: And. If we want to put a wooden fence on a green lawn, the result should be that the landscape behind the fence is green. Therefore, the front of the wooden fence should be transparent pictures, put it in the grass layer, and set the layer to Transparent Display, then you can put a wooden fence on the grass terrain, rather than as shown above, the background of the fence area is blue-gray. If so, isn't it very strange to place a fence on the grass ?! Only the lower end of the fence is inserted in the grass (the real world ). Therefore, we need to define many layers (in fact, we should mention in the previous article about layers that we just want to make it clear here. There is really no new article about it recently. It's good to stir-fry it, can taste good ......), The underlying layers are used to place basic terrain, such as lawns, common mountains, snow, and mud. They do not need to be transparent (if all objects in a layer are not transparent, so there is no need to set the transparent attribute for this layer. Of course, this is for storing image resources here ). The upper layer requires transparency. In addition to a fence placed on the grass, such as a stone tablet, a desert bone, and so on. If you want to draw a Landscape Map for each object in different backgrounds (such as snow and grass), it is a redundant resource and a waste of space! Make it transparent and put it on the top, because the transparent effect is automatically displayed and the scenery is not better. In fact, this is generally something that everyone can think. (Note: From the game perspective, the roles must be independent of each other. They must move on the terrain and expose the background color. The menus are at the top, because menu calling must cover all game pictures. Of course, these layers are not covered by the map editor, Because maps alone do not save these layers. However, like Warcraft 3, event editing, map editing, and task scheduling can all be done together, making the game task writing very independent. One task is a file, including maps, characters, tasks, text descriptions, and so on, this will enable players to make full use of their imagination, compile and implement their own game scripts, of course, these resources are pre-fixed.In fact, the map file not only saves the terrain, but also saves the entire mapRemovable flag Matrix(A temporary name, that is, a two-dimensional Boolean matrix of the same size as the map, indicates whether the terrain of the point can be moved ). Of course, maybe this is more suitable for RPG games, andTattooDifferent categories of games have different movable terrain. For example, the server guard can only move on non-mountain land, while the dragon rider can move anywhere on the map (relative to the wild ). Therefore, a single two-dimensional array with only true and false is not competent. The current idea is to apply different moving losses to different terrain, only when the mobility of a profession is larger than the loss of mobility can it be moved to this place, but it is quite special for the flying dragon because they are less concerned with the terrain, any terrain (relative to the wild) for them, it consumes 1 point of moving power. The terrain should store its ownMoving force loss valueCan be recorded in a static array, corresponding to the moving force loss of the terrain, when the editor outputs a map file, it also outputs a string to record the loss value on the terrain (obtained by querying the corresponding moving force loss value array through the terrain index ). In fact, the loss value on this map can be converted into a two-dimensional array to calculate the movement loss of the corresponding terrain in the program after reading some map symbols, however, considering that the computing workload may take a longer time than I/O reading, it is also on a mobile phone (although I believe in arm performance), but it is always not faster than the processing speed of a PC, at least for now. In addition, the tests are carried out on PCs. Maybe your computer thinks that clock loss is just like hongmao, but maybe your mobile phone doesn't think so ...... (Note: These movement Force loss strings are not used by the map editor. Of course, they can also be used to display the movement force requirement to test the balance and difficulty of a level task. In map files, they are all Unicode or ASCII encoded characters. to distinguish between map tags and data such as map size and moving force loss values, they must be treated separately, we recommend that you use the map file tag to retain keywords! Although it is similar to the method used by programming languages, it does work too well. No one says that reserved words can only be used in Java, C ++, and Delphi ~ Of course, when reading a map file, you need to filter it out, which is out of the scope of this article.)

As mentioned above, the issue of resource utilization should not be too wasteful. Now we will discuss the second issue. Think of something about the server program. In the past, when I was doing network programming, a server response program thought it was good and everything was done on the server. The access end only sent a few control signals, the server sends back a large string of data, such as what was previously doneHoroscope fortune teller(Of course, the data is given by the teacher, and I have not yet reached this level). All constellation information is on the server side, and the client only needs to send the date of birth to the server, the server locally calls up and queries the corresponding birthday information, and sends the corresponding description string to the client. After receiving the message, the client simply performs the display on the console. Although very small programs, but careful deduction can still cause many problems. After compiling the program, I thought it was quite good. It looked like a decent one. When you sent a date of birth, you immediately returned some introductions, comments, and so on, however, as long as many people (for example, 500 clients) Initiate queries at the same time (of course, thread is done, otherwise it is not really funny to wait one by one), the speed will be much slower. Later, I considered the long-distance issue. For example, I sent this server to a friend in the United States. When they opened it, I went to a client to access it, and the speed was even slower ~ Why? 1. One access is not worth mentioning for the current clock-frequency PC. A flash completes service return information, but when multiple people initiate service requests at the same time, naturally, there is a processing limit. When the load is exceeded, requests outside the load are put on hold. 2. This network program also needs to take into account the congestion of the network. To be honest, the transmission speed in the United States and China is really bad. When a large file is returned, it's natural that the speed is slow (people will give you slice, route-based transmission ...... Restructuring at the target end ...... USA ~ You and so on ). In the first case, it really depends on your machine's capabilities ~ In the second case, how can I ensure that the problem on the road is not an ATM? Who calls it the Internet? People have adhered to the glorious tradition of the Chinese nation: no matter whether they do not do it, then again, face is important, I just do what I can. However, these two problems can be solved in one place ~ The key to the first problem is that once the server load is full, the work will not be quickly solved, so I will place the heavy tasks to the local client (of course, it is impractical for the fortune-telling program of this constellation. If the query is stored locally, what else do I need your server to do ). The second problem is that the speed of sending all the data files is too large and is affected by the unstable speed. If the server sends several control information to the client, then, when the client displays the data based on the control information sent from the server (Data localization), the latency caused by external instability of small data is much smaller than that caused by big data (obviously, it is the same as that caused by high-rise buildings, A process delay, such as the delivery of construction materials, will delay the completion time of the entire building). If you give him fewer opportunities for errors, it will naturally reduce the chance of errors. This is what many 3D online games do now. If all the data on the screen is sent from servers, it is estimated that backbone fiber connections will be used between them to ensure smooth gaming ...... In terms of map resources, although the problem is not the same, the solution is similar. A map resource is an image. When an external file is loaded, an exception is thrown due to such reasons. In this case, a problem occurs in basic and no resources are available. How can this problem be solved! For example, in some previous articles, my map file is a single 16 × 16 PNG image. If one of them goes wrong, then the whole program will get worse, the result is nothing more than running, and an error is reported during running. If there is a problem with the logic, it will also cause the display to fail ...... If so many terrain are made into 16x16, as long as each external file has a 1% probability of loading, 10 terrain is fine, if it is 100 terrain, I don't have to be tested for 100 times, 1% even if it's okay for the first 99 times. When I met this 100th times, I still don't cry, and I just passed the first 10 terrain, but it still needs to be tested for 1% times! In addition, each file has its own data format, that is, the file contains the data part and the tag part. Not to mention the data part. The mark part records the file format, file size, and other related information. A question that can be calculated after I graduated from elementary school: If a PNG image is used as a mark, it will be 1 kb (of course not so much, for example, it is just for convenience of calculation, if the size of a PNG Image of 256x256 is 257 kb for the moment (purely for convenience), the KB is used to record the image data. If it is divided into 16x16 files, a total of 256 16x16 small images can be divided, the size of each file is 256 kb 256 + 1 = 2kb, the total file size will be 2x256 = kb. Compared with the original kb, the file size will be quite burstable ~ Of course, the actual tag information cannot reach 1 kb. However, if you divide the file into smaller ones, the proportion of the tag information to the entire file will also increase, the calculation results (two times larger) are displayed when the data size is equal to the image data size and the marked data size ). Therefore, no matter what you do, as long as the image is separated, there will be data redundancy. Of course, redundancy is not necessarily bad, but here we can see that there is no need to cause such redundancy, but how to control it depends on the needs of individuals and projects. If there is no redundancy, but it causes difficulties in use and control, then moderate redundancy is feasible. Back to the question, as shown in the preceding two questions:Error ProbabilityAndData redundancyThis makes it necessary to make all these map resources into a graphical file! When reading a file, you only need to worry about 1% at a time, and there is only one copy of the tag information, minimizing redundancy. One solution for two problems ~ Haha. However, the operating memory and storage capacity of mobile phones are two concepts. This is like the memory on PC machines and hard disks. Nowadays, mobile phone storage space is often called mobile phone memory, whether it's the size of the running space or the size of the storage program, it's all called memory ...... (I don't know if this is the case. I just think about it myself. If it's hard to say that it's all about memory, maybe it's hard to say that the runtime space and the bucket space are public, maybe ...... Khan !) Graphics are actually in the machine. They are useful in the memory, that is, the dot matrix data of some graphics ...... Khan !), Marking Data is useless. You may need to specify the size when creating an array of graphic data. When all the terrain is loaded, the available runtime space is reduced, and the terrain that is not used (displayed) in the current map is wasted in memory. The performance problem after a file is made is not mentioned. This is a problem to be solved in the program optimization stage. The problem to be solved now is how to split the file to be read, take the part we need! In fact, this is a commonly used method in most 2D flat games. It not only reduces the I/O read error probability, but also effectively reduces data redundancy. The next key question is how to split the image. As we mentioned above, this map editor runs on a PC, in fact, according to the current PC's massive storage and system security perspective, creating a single resource file does not have a big impact, but considering that this game has not started to be made in the main program phase, I started with the map editor, so it is also intended to allow later main programs to use the methods used here (reuse, in fact, it is laziness), so we can start to do it here, although it is completely feasible to use two different resource systems in the game and map editor, it is not what you see or what you get. Isn't mobile phone a PC.

Haha, I am a little tired. I finally sorted out my recent ideas and put them here neatly. This is a bit tricky, because the most critical issue of segmentation has not been solved. Yes, because I have only one idea, but I have not put it into practice, and I have not read the specific splitting technology. I just know that there is such a method, I can only write it here, but in the next article, the key is to solve the image segmentation in the memory. Hey hey, it's starting to look like it ~ Recently, I am about to start school. I am busy. If you are interested in this kind of technology, you are willing to discuss it or instruct me to add a QQ group: 8882320. It doesn't matter if it's not Java, I think the idea is the most important. As for the language to be implemented, it is a tool problem. Tools can be mastered, while ideas and ideas are inherent. I hope you will not be stingy with us. Pai_^

 

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.