Game development basis (7)

zhaozj2021-02-16  48

Game development basis (7)

The first section of the first section of the eighth chapter, the first section of the first section DDinit (): Ddinit () is the enumeration driver, its specific operation process is as follows: First call DirectDrawenumeRate (), this function is in the fifth chapter DirectDraw deep into the article Section III selection has been talked in the DirectDraw driver. The parameters of this function in this routine are & DdenumCallback and null, & DDENumCallback refers to the address of the callback function DdenumCallback (), and null means that there is no pointer to the application data. The role of the callback function DdenumCallback () is to store the GUDI, description and name of the enumerated driver into a structural array AddDevs []. Select later. Second section define command line parameters 1. Determine the operation mode according to the command line parameter First, use the while (lpcmdline [0] == '-' || lpcmdline [0] == '/') detect the identifier of the command line parameters, Then use Switch (* LPCMDLINE ) to define the meaning of the partial parameter: -e use emulator (using software simulation) -s no Sound -1 NO BackBuffer (not used back buffer) -2 One Backbuffer (a backup Buffer) -4 Three BackBuffers -s Use Stretch (using a drawing algorithm, that is, when changing the shape of the window in window mode, the graphic uses the pull algorithm to make the image smile smile.) - X Demo or Stress Mode 2. Determine the display mode to the number of pixels at the horizontal axis direction of the display mode, the number of pixels in the vertical axis direction gamemode.bpp call GetInt ( CHAR ** P, INT DEF) acquires command line parameters to set up these items. The running process of the getint (char ** p, int dev) function is: first detect whether the command line parameters are "" "/ r", "/ t", "/ n" or "x". If it is to make the pointer P from 1 and continue to detect, otherwise it is detected whether the character is less than 9 greater than 0. If the character is not less than 9 greater than 0, it returns a default value, and vice versa, via while (is_num (** p) i = i * 10 * (* p) - '0' will enter the ASCII value of the character Transition into values. Then pass while (is_space (** p)) (* p) ; check whether the characters behind "", "/ r", "/ t", "/ n" or "x", If you make the pointer P from 1 and continue detection until the other characters or strings appear. Section III initialize the Windows program in this part calls the initApplication (Hinstance Hinstance, int ncmdshow "function to initialize Windows.initance (Hinstance Hinstance) , int ncmdshow first defines the window class as: Style: Indicates a message that the class sends a mouse to send a mouse to the window. 1pfnWndProc: Indicates the pointer to the window function, which points to mainwndproc. Cbclsextra: Specify the distribution of the window structure The number of bytes is 0. CBWndextra: Specifies the number of bytes assigned after the window instance is 0. Hinstance: The application instant handle of the registration window class is Hinstance.

HiConhicon: The icon displayed when the window minimized the window is obtained by calling LoadCon (Hinstance, Makeintatom (Fox_ICON)). HCURSORHCURSOR: Defines the cursor used by the application by calling LoadCursor (NULL, IDC_ARROW). HBRBACKGROUND: Background brush identifier is obtained by calling getStockObject (Black_brush). 1pszMenuname: The resource name of the menu is NULL. 1pszclassName: The name of the window class is WinfoxClass. This window class is then registered with if (! Rc) {return false;} and ends the program when the registration fails. The window is then created with hWndmain = CREATEWINDOWEX (...) and assigns the handle of the window to hwndmain. This window is created as: The extension format of the window is the WS_EX_APPWindow window class "WINFOXCLASS" window name "WIR_APP_NAME window format is WS_Visible | WS_SYSMENU | WS_POPUP (Create an overwhelming window with a system menu on the initial state visible title bar or pop-up window or pop-up window The X coordinate 0 window in the upper left corner 0 Window Y coordinate 0 Window Width GetSystemMetrics (SM_CXSCREEN) window Height GetSystemMeen (SM_CYSCREEN) (SM_Cyscreen) Handle Null, Window Menu Null, window The example of the program is the Hinstance 32-bit additional information is NULL and then creates whether it is successful with if (! Hwndmain) {return false;} detection window, and end the program when creating fails. Finally call UpdateWindow (HWndmain) and setfocus (hwndmain) The display window and the keyboard input is defined in the window (ie, the game window) referred to in HWndMain. The display of the Help information is called here to call the MessageBoxa (HWnd HWnd, LPCSTR LPTEXT, LPCSTR LPCAPTION, UINT UTYPE) function. It calls The way is as follows: if (bhelp) {MessageBox (hwndmain, "f12 - quit / n" "Numpad 2 - crouch / n" "Numpad 3 - Apple / N" "Numpad 4 - Right / N" "Numpad 5 - Stop / N "Numpad 6 - Left / N" "Numpad 7 - Jump / N" "/ n" "Command line parameters / n" "/ n" "- e use emulator / n" "- s nooid / n" 1 no backbuffer / n "" - 2 One backbuffer / n "" - 4 three backbuffers / n "" - s use stretch / n "" - x demo or stress mode / n ", out_app_name, mb_ok);} Its meaning Yes: If BHELP is TURE, create a message box in the window pointed to by HWndMain. The content of this message box is "" "included, the title is OUR_APP_NAME (there is #defi in foxbear.c) Neur_App_name "WIN FOX Application" statement), and this message box displays an OK button.

Section 5 Initialization Game This section is just calling the initGame (void) function, its call mode is: if (! InitGame ()) {return false;}, if the call fails, then the program is completed. INITGAME (Void) is the largest part of the entire initialization part, which has completed the rest of the initialization. In the later sections of this chapter, we will explain some of this part of this function. Sixth Internally Modified Refreshfounded Since the window accepts the defined message is defined as changing the display mode, you need to reinitialize the game, so you will be the initgame. The function is called (this function is called, for example, when the message VK_F8 is time). At this time, the call occurs when the game is running, and the more important pointers in the game run have been used (pointing to a certain memory area) while the memory has been assigned. If the memory is not released at this time, the initialization will occur in the future initialization will occur later at this time that the pointer points to null. Therefore, the exitgame () function has been called the EXITGAME () function in the run of the function. The running process of the exitgame () is: First, detect the three pointers of LPFramerate, LPINFO, LPPALETTE, if not 0, release the memory it refers to, and make it null to restore it to the initial state (provided by using the iUuknown interface) The function release () decrements the internal reference value of the pointer until the reference value is 0 releases the assigned memory). Then, the call function destroyGame () continues to release the memory. The running process of DestroyGame () is: First, detect if the HBuffer is non-0, if not 0, call the following functions: DestroyTiles (HtileList) - Release the partial memory block referred to in the handle HtileList. DestroyPlane (HForeground) - Releases the memory block pointed to HForeground and HForeground-> HBM. Destroyplane (HMIDGROUND) - Releases the memory between HMIDGROUND and HMIDGROUND-> HBM. DestroyPlane (HBackground) - Releases the memory block pointed to HBackground and HBackground-> HBM. DestroyBuffer - Releases the memory occupied by all bitmaps and the memory area pointed to by LPCLIPPER, LPBACKBuffer, LPFrontBuffer. DESTROYSOUND () - Releases all the memory occupied by the sound effect and the memory area pointed to by LPDS. Finally, Htilelist, HForeground, Hmidground, HBackground, and Hbuffer point to empty. Section 7 Initialization Sound This part mainly calls the function Iinitsound () works in the playback of DirectSound to initialize and sound. Its work process is: call dsenable (hwndowner) to initialize DirectSound: first use busedsound = getprofileint ("foxbear", "us_dsound", bwantsound) Select playback device; then pass if (! Busedsound) {LPDS = null; return true } IF (LPDS! = NULL) {MSG ("DSENABLE, Already Enabled"); return true;} Detecting whether the selection is successful and sound has been initialized.

Then dsrval = DirectSoundCreate (NULL, & lpDS, NULL); if (dsrval = DS_OK!) {Msg ( "DirectSoundCreate FAILED"); return FALSE;} dsrval = IDirectSound_SetCooperativeLevel (lpDS, hwnd, DSSCL_NORMAL);! If (dsrval = DS_OK ) {Dsdisable (); msg ("setcooperativeEvel failed"); Return False;} The object used to create DirectSound and detect whether it is successful and set up a collaboration and detects whether the settings are successful. An object is created here for the default device, and the cooperation layer is set to normal (DSSCL_NORMAL), even if the application of the sound card can be sequentially switched. After calling DSEnable () with the statement: for (idx = 0; idx

The function gfxbegin () completes the setting of the display mode (by calling the DDENABLE function), the work is created (by calling the function DDCREATEFLIPINGSURFACE (Void), the display of the initialization screen (by calling the function splash ()). The running process of the function Ddenable (Void) is as follows: 1. Get system information (using getprofileint () function) and decide whether to use software simulation (apply DirectDrawCreate () to create an object to the drive mode and use DirectDraw_QueryInterface () Query whether the object is .. support) .2 detection display mode first determine whether to use full-screen mode, if you use IDirectDraw_SetCooperativeLevel ((lpdd, hWndMain, DDSCL_ALLOWMODEX | DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN) create cooperation layer of the display device can maximize control, and then use IDirectDraw_EnumDisplayModes ( lpdd, DDEDM_STANDARDVGAMODES, NULL, 0, EnumDisplayModesCallback) enumerate the display mode VGA mode. If the enumeration fails, call IDirectDraw_EnumDisplayModes (lpdd, 0, NULL, 0, EnumDisplayModesCallback) (enumerates all display modes). Without the use of Full-screen mode, call ddrval = idirectdraw_setcooPERATIVALAVELEVEL (LPDD, HWNDMAIN, DDSCL_NORMAL) (Create a partner layer in DDSCL_NORMAL mode, using a general Windows application method). Subsequently placed in the structural array modelist []. If the collaborative layer creation fails, the error message is returned and the game is returned. Next is to select the display mode section. First determine if the full screen mode is used. If it is determined which display size and color number of color. If you do not use full screen mode, get the system current The device and the number of colors used, the attributes of the window in the window mode and the determination of whether the drawing algorithm is used and the size of the user area is set according to the judgment result (using setRect (& RC, 0, 0, Gamemode.cx * 2, Gamemode.cy * 2) and SETRECT (& RC, 0, 0, Gamemode.cx, Gamemo de.cy), then set the size of the window according to the size of the user area and the window properties of the window style, and determine the window in the case where the window is in the case of the multi-window. Using the iDirectDraw_getcaps (LPDD, & DDCAPS, NULL "function to obtain the features supported by the device and determine those feature by software simulation, those feature supported by hardware. The value of the buffer is determined by the value of nbuffercount. Finally, the maximum display mode is determined by the characteristics supported by the device. Function DDCREATEFLIPPINGSURFACE (Void) Running: First get hardware support (Application IDirectDraw_getcaps (LPDD, & DDCAPS, NULL)). Then fill in 0 in the buffer. When the full screen mode and the number of buffers are greater than 1, create a surface row of DD_CAPS as a flag and a backup buffer number of DDSD_BACKBufferCount as flags, and assign DDSCAPS_PRIMARYSURFACE, DDSCAPS_FLIP, and DDSCAPS_COMPLEX to the surface function zone ( For these three signs, please read the DirectDraw in-depth articles.

Next, DDSCAPS.DWCAPS = DDSCAPS_BACKBUFFER; DDRVAL = iDirectdrawsurface_getattable, & ddscaps, & lpBackBuffer, to acquire the pointer to the backup buffer. If you use a tensile algorithm or DDCAPS.DWCAPS to DDCaps_BankSwitched, create a buffer for the tensile algorithm (you will find the DDCReateSurface (DWord Width, DWord Height, Bool Sysmem, Bool Trans). The creation method of the buffer is almost the creation of buffers above, but only two buffers recorded on the height and width, and use system memory, please note this skill). Here is how to create a surface in the full screen mode and a buffer. In this step, you can see that the program only creates a surface ribbon and has no bakement count, and the part of the pointer to the back buffer is acquired by idirectdrawsurface_addref (lpfrontbuffer); lpBackBuffer = lpfrontbuffer; replace. Then you set a buffer in window mode, first create a surface ribbon (in VRAM) and create a back buffer with lpBackBuffer = DDCREATESURFACE (GaMesize.cx, GameSize.cy, False, False) (in system memory in). Next is the setting of the shearing plate, first create a shear board (DDRVAL = iDirectdraw_createclipper), then acquires the cutting board (ddrval = idirectddrawclipper_sethwnd (lpclipper, 0, hwndmain)) Finally, connect the shear plate to the surface (ddrval = idirectdrawsurface_setclipper (lpfrontbuffer, lpclipper)). The following is the operation of the color, first use iDirectdrawsurface_getpixelformat (lpfrontbuffer, & ddpf) to get the pixel format of the surface, then set colorKey, if the 8-bit color, the colorKe is 256, which is 16-bit color. Section 9 User Zone Size and Palette Settings 1. User Zone Size Sets In this section, first is the size setting of the user area in the case of a full screen mode or using the stretch algorithm, and then the settings in window mode. In these settings, it may be necessary to explain why GAMEMODE.CX - GameSize.cx is equal to GAMEMODE.CX, which is due to GAMERECT.LEFT (or GAMERECT.RIGHT) means the horizontal length of the user area (lower right corner) And GameMode.cx refers to the width (full screen) of the entire user area and GameSize.cx = GameMode.cx / 2. So GameRect.Eft = GameMode.cx - GameSize.cx. Other computing forms of GameRect.top, GameRect.right, and GameRect.Bottom are similar to the calculation method of GAMERECT.LEFT.

2 The functionality of this part of the program is mainly due to the function readpalfile (), which is the introduction of a palette file. If the specified file is not found, the default palette is used, and this default The establishment of the palette is the following statement: for (i = 0; i <256; i ) {PAL.APE [i] .pered = (Byte) (((i >> 5) & 0x07) * 255/7); PAL.APE [I] .pegreen = (((i >> 2) & 0x07) * 255/7); Pal.ape [i] .peblue = (byte) ((i) >> 0) & 0x03) * 255/3); Pal.ape [i] .peflags = (byte) 0;} / * In structure array PAL.APE [i] to store 256 sets of colors consisting of four values Value * / and functions ddrval = idirectdraw_createpalette (LPDD, DDPCAPS_8bit, Pal.ape, & PPAL, NULL). From these statements we can see a 256-color palette (8-bit color). After calling the palette, connect the palette to the surface with idiretdrawsurface_setpalette (). Section 10 Demonstrating the Image This section is implemented by calling the initializegame () function. The running process of the initializegame () function is: first call the splash () function, the function of this function is written to the backup buffer as blue and test all buffers (with DDCLEAR () functions) and output FoxBear is loading to the screen. ..... device. Then use the loadbitmaps (void) function from the FoxBear.Art file and stored in the structural array hbitmaplist []. Followed by: InitTiles (& hTileList, hBitmapList, C_TILETOTAL); InitPlane (& hForeground, & hForePosList, "FORELIST", C_FORE_W, C_FORE_H, C_FORE_DENOM); TilePlane (hForeground, hTileList, hForePosList); InitPlane (& hMidground, & hMidPosList, "MIDLIST", C_MID_W, C_MID_H, C_MID_DENOM); TilePlane (hMidground, hTileList, hMidPosList); InitPlane (& hBackground, & hBackPosList, "bACKLIST", C_BACK_W, C_BACK_H, C_BACK_DENOM); TilePlane (hBackground, hTileList, hBackPosList); InitSurface (& hSurfaceList, "SURFLIST", C_FORE_W, C_FORE_H); SurfacePlane (hForeground, hSurfaceList); InitFox (& hFox, hBitmapList); InitBear (& hBear, hBitmapList); InitApple (& hApple, hBitmapList); these statements hBitmapList [] in the bitmap classified into the appropriate list and establish The respective memory areas.

转载请注明原文地址:https://www.9cbs.com/read-23328.html

New Post(0)