Translation: huwell
* The following content is selected from "Programming Games for Series 60", which is a paper specially organized by NOKIA, mainly telling the relevant content of game programming in the Symbian system. All system end events have such a general nature, that is, it can be captured by an application. When a system event occurs, the front application will lose focus. This can cause the HandleForegroundEventL function of the application user interface class (Caknappui). If you do not consider handling this function, the application can handle the relevant action, such as pause the program. The application needs to pay attention to memory savings, which is not only used in runtime memory, but also includes the size of compiled postcodes, in short, the most important principle in processing RAM is, we should release these allocated memory as soon as possible Do you have to do this? On the target machine, the core on the OS keeps tracking the memory of each thread and re-release them after the program exits. This ensures that all memory will be released when an application exits. If they are not properly released, there is a resource, and the result of a certain number of resources will be saved in the system. In the Symbian OS, each thread has its own memory stack, which is not possible when the thread has run, this stack size cannot be changed. The default stack size in S60 is only 20KB, so be careful when using it. It is important to note that when running on the simulator, it is not limited to this stack size, as it is running according to Windows, which is the program that the program should be tried in hardware (mobile phone). Most stack overflows are caused by descriptors in the stack, which can be avoided by allocating a descriptor on the heap. Note that the recursive use is consumed, if the recursive program is inevitable, then we will minimize each of our incoming parameters and some variables to prevent overflow. In order to reduce the size of the compiled postcode, we should follow the following policy :) 1, unless necessary, do not export Method 2, do not generate unnecessary virtual functions (with additional virtual functions, increase the volume) 3, do not excessively Use Trap to capture traps 4, avoid copy code 5, find a function of decomposable 6, using general control and components to be careful, not to avoid excessive use because they will grow code size. In Symbian OS, a lot of trap has been provided, we don't have to place our own trap :) In the game, because the bitmap will be used, the consumption of memory is particularly large, most effective The method is not to reduce the use of bitmaps, but reduce their color depth, Symbian support 24-bit bitmap, a total of 16777216 colors, but the actual color size is based on hardware, we should try to The color volume supported by the target hardware is limited, for example, a sprite, using 8bit color should meet most of the Sprite needs, and Mask should only use 1bit's bitmap! In Symbianos, one of the lack of services is Timing Services. Here, the OS does not support the underlying Timer Interrupts, which only provides a core time generator, and its maximum frequency is 64 Hz, and on the simulator, The largest Tick Rate can reach 10 Hz, which makes the program more cumbersome.
The maximum Tick Rate in the system can be obtained by accessing userhal :: tickperiod. It is defined in E32hal.h, you can see the following chart: Border = 0> (TimerSerivces.gif) The core-based Timer can be obtained by accessing the RTimer, which is a handle pointing to the system-end service. It provides a simple API to send three different time events: at a given time, events on a given time and an Event Which Completes at a Given Fraction of A SECOND. In order to be more convenient Using RTimer, Symbian OS provides an abstract activity object: CTimer, which encapsulates the use of RTimer, which can also be seen in the above picture, and the CTimer must have rtimer existence. Users only need to derive classes from CTimer, and also need to overload the Runl function, which is called when a request is completed. Because it is non-mellow, it may be delayed on the time slice, causing inaccurate, we should try to reduce the time of the code in RUNL. In addition, we should also refer to the highest priority of the activity objects of the process time, to prevent other objects. In Symbianos, two CTimer derived classes: Cperiodic and CheartBeat, Ceriodic, the interval between events in Microseconds, while in the checkbeat, intervals in a second segment, which is defined in the TTIMERLockSpec enumeration. The smallest time clip is 1/12 seconds, and CheartBeat provides a method to synchronize with the system time. When there is Timer Event miss, its callback function Synchronize will be called to take a way for the application to take a correction measures. Symbian OS is an event-driven system, all applications and services can be seen as an event processor. If the processing of the key event is shown below: border = 0> (KeyEventFlow.gif) The above is the key event flowchart after a user presses a key. When the user presses a button, Keyboard Hardware generates an interrupt, captured by Keyboard Driver, and decomposes the key code of this button event, then Driver sends it to a thread of the system - called Window Server, WINDOW Server will turn it in that application that is focused in Window Group, which is done using a Control Environment (CONE), which is an API function between Window Server and User Interface Library. At this time, it is time to the application. Here, the key event is processed by the OfferKeyEventl function (called by Window Server), each time the button will generate three different events, the first event is EEVENTKEYDOWN, it is when a button is After pressing, then EEVENTKEY, we usually be most interested in this event, and finally when the button is released, the type of EEVENTKEYUP, these events are indicated in the TEVENTCODE enumeration type, which is also passed to OfferKeyeventl The second parameter, the first is a structure, TKEYEVENT, which provides more information about this event.
If a button lasts more than 0.8 seconds, the Window Server will send another EEventKey to the program. This is the long button event; if the button is more than that limit, it is considered that this is Take a repeated button event, Window Server will send KEY REPEAT Events every 0.25 seconds. The intervals of these times are defined by the default value of S60, which can be changed in the program. TKEYEVEN has a member variable, Irepeats, which can be used to distinguish between long button events or repeated buttons. In general, if you want to distinguish the type of button event, you can view Irepeats. If it is 0, that is, the long button event, if it is not a repeating button event. Here Irepeats is a 32-bit band symbol integer. Because most of the button events will be dealt with in time, this variable does not define the number of actual repeated buttons. If you want to know how many keys are repeatedly pressed, the application will calculate the number of repeated buttons. Game, the processing of the button, it can set your own button repetition, call the key repeat time by calling the Window Server's setKeyboardRepetrate to call Key Repeat Time. It has two parameters. In the S60 series, most of the buttons are blocked, only the power button and the editing key are non-blocking. Because key operations are very important for games, such as the user can press the operation of the two keys at the same time. This is why S60 provides an API to cancel the key blocking. In the application's UI base class, Caknappui provides the setkeyblockmode method to cancel the key blocking. It uses TaknkeyBlockMode as a parameter, which can have two possible Values EdEfaultBlockMode and EnokeyBlock. Note that the operation of the key here is also the system's setting, we should return to the original default value when the game is backed by . In Symbianos, playing and managing sounds are processed by Media Server, and Media Server supports a wide variety of Audio file formats, such as WAV, AU, and WVE, and provides an API to expand new file formats. Media Server's client API is derived from three different interfaces: Audio Sample Editor, Audio Tone Player, and Audio Sample Player. Here Audio Sample Editor interface provides advanced Audio management methods that can be used to record, edit, and play. The Audio Tone Player interface allows the application to generate and play the integrated sound. The last Audio Sample PLAYER interface can be used to play back Sample Data Files. The use of the Media Servcer interface requires an Active Scheduler that they use together in the same thread. For most games, the Audio Sample Player interface can meet the general sound demand. This interface includes MMDaAudioplayerCallback and cmdaaudioplayERUTILITY classes. Here MMDaaudioplayerCallback is a mixed class that provides callbacks, which is used to complete the initialization or playback of SAMPLE to notify Client Class. The cmdaaudioplayerutility class provides a way to load and play an Sample, and can adjust the volume.
This class can only be associated with a Sample data, so if the program has multiple different Sample Data files, it is necessary to generate multiple instances of it. See the following code: // Create a sample player and load a sample from a file CMdaAudioPlayerUtility * samplePlayer = CMdaAudioPlayerUtility :: NewFilePlayerL (KSampleFileName, * this); // Play the sample samplePlayer-> Play (); in s60, each An application has a default sound for each key, which can be divided into short buttons, long buttons, or repeat buttons based on different key types. UI class s60 application, CAknAppUi, specify their own key voice for the application provides support, mainly in a resource file: RESOURCE AVKON_SKEY_LIST r_example_skey_list {list = {AVKON_SKEY_INFO {key = EStdKeyLeftArrow; sid = EAvkonSIDNoSound;}, AVKON_SKEY_INFO { key = EStdKeyLeftArrow; sid = EAvkonSIDNoSound; type = ESKeyTypeLong;}, AVKON_SKEY_INFO {key = EStdKeyLeftArrow; sid = EAvkonSIDNoSound; type = ESKeyTypeRepeat;}};} effective sound ids, SIDs, avkon.hrh specified in the header file. In the game, if a key is pressed for a long time, the Repeat Sound should be canceled, we can specify the sound ID of the button event to EavkonsidNOSound, because each time you receive a button repeat event, play a repetition sound Will consume a process time. If the program requires a subsequent sound, you should use Sample Player to replace it. Installation ---- The following example:; mygame.pkg; specifies an installation file for mygame; languages & en; header # {"mygame"}, (0x1000ABCD), 1, 0; Required Line for Series 60 devices (Added by NOKIA) (0x101F6F88), 0, 0, 0, { "Series60ProductID"} "epoc32releasethumburelMyGame.app" -. ":! systemappsMyGameMyGame.app" "epoc32releasethumburelMyGame.rsc" - ":! systemappsMyGameMyGame.rsc" Inside; the annotation of the annotation, the head is a non-headed line, refers to the supported language type. The SIS file can support multiple language options, just only one this installation at a time. The second line indicates the name and ID of the program, and the version number, and a build number. Finally, the S60 Product UID provides information installed on which S60 platform that the application is available.
A plurality s60 product Uid can be used, as follows: Nokia 7650 0x101F6F87 Nokia 3650 0x101F7962 Nokia N-Gage 0x101F8A64 SX1 0x101F9071 Series 60 Platform v0.9 0x101F6F88 Series 60 Platform v1.0 0x101F795F last lines illustrate the source to be packaged into sis Documents and target files, pay attention to use! Let the user freely select the storage medium. Graphics ---- The most important thing for game developers is I have supported the system for graphics. Let's talk about the support of graphics in the Symbian system. Graphics Architecture -------- The Symbian system defines graphics in the system's graphics device interface (GDI), GDI defines the original drawing function, provides a function to draw text, fractal processing, and bitmap processing. All graphics components in the system rely on GDI to process, see below: Border = 0> (GraphicsComponent.gif) In Symbianos, the drawing is processed by Graphics Contexts and Graphics Devices. GDI offers an abstract graphics context class, CGRAPHICSCONTEXT, which is the base class of all Graohics Context. It defines basic drawing settings, such as pen and paintings, and encapsulates the GDI graphics function that can be used in applications. When practical, we are done through Gracohics Device, and it is using the settings in Graphics Context. Here are the base class of the Device class: CGRAPHICSDEVICE, WHICH SPECIFIES The Attributes of a Device The Drawing is assigned to. As shown in Figure: (ContextDevice.gif) Specific Context and Device classes are completed in Bitgdi (see Figure), Which is a screen and bitmap-specific graphics component. It uses highly optimized assembly code to provide good fast graphics ability. The main task for managing fonts and bitmaps. So they can share between all threads in the system. This Allows for Major Memory Savings as Only One Instance of Partic Tai,. When the application is loaded from the user data area, FBS puts them on a shared heap. In this Server side, manage a reference count, which is used to count how many customers are using them. When this count is 0, it can be released safely. Window Server can directly access this heap so that you can reduce these unnecessary steps from the memory from the FBS's memory to Window Server. All ROM-based graphics and fonts can be used directly from the ROM. We can access FBS through the RFBSSession class, which is generated by Window Server. It is used by CfBsFont and Cfbsbitmap classes, which provide methods for managing fonts and bitmaps.