[ros-diffs] [greatlrd] 24625: rewrite D3DParseUnknownCommand to use switch case instead it looks better. Add a summer of msdn documentions how the first input parameter works. So u do not need read the whole doc for it. Add some more comment in the code

greatlrd at svn.reactos.org greatlrd at svn.reactos.org
Mon Oct 23 19:37:52 CEST 2006


Author: greatlrd
Date: Mon Oct 23 21:37:51 2006
New Revision: 24625

URL: http://svn.reactos.org/svn/reactos?rev=24625&view=rev
Log:
rewrite D3DParseUnknownCommand to use switch case instead 
it looks better. Add a summer of msdn documentions how the first input parameter works. So u do not need read the whole doc for it. Add some more comment in the code

Modified:
    trunk/reactos/dll/directx/ddraw/main.c

Modified: trunk/reactos/dll/directx/ddraw/main.c
URL: http://svn.reactos.org/svn/reactos/trunk/reactos/dll/directx/ddraw/main.c?rev=24625&r1=24624&r2=24625&view=diff
==============================================================================
--- trunk/reactos/dll/directx/ddraw/main.c (original)
+++ trunk/reactos/dll/directx/ddraw/main.c Mon Oct 23 21:37:51 2006
@@ -128,11 +128,26 @@
 
    for more info about this command 
 
- */
-
-/*
- * UNIMPLEMENT 
- * Status FIXME need be implement and this code is realy need be tested
+   summuer the msdn 
+
+    The buffer start with D3DHAL_DP2COMMAND struct afer that it follow either one struct or no struct at at all
+    example for command D3DDP2OP_VIEWPORTINFO
+
+    then lpCmd will look like this 
+    ----------------------------------------
+    | struct                 | Pos         |
+    ----------------------------------------
+    | D3DHAL_DP2COMMAND      | 0x00 - 0x03 |
+    ---------------------------------------
+    | D3DHAL_DP2VIEWPORTINFO | 0x04 - xxxx |
+    ---------------------------------------
+
+    to calc end of the lpCmd buffer in this exmaple 
+    D3DHAL_DP2COMMAND->wStateCount * sizeof(D3DHAL_DP2VIEWPORTINFO);
+    now you got number of bytes but we need add the size of D3DHAL_DP2COMMAND 
+    to get this right. the end should be 
+    sizeof(D3DHAL_DP2COMMAND) + ( D3DHAL_DP2COMMAND->wStateCount * sizeof(D3DHAL_DP2VIEWPORTINFO));
+    to get the xxxx end positions. 
  */
 
 HRESULT 
@@ -140,10 +155,9 @@
 D3DParseUnknownCommand( LPVOID lpCmd, 
                         LPVOID *lpRetCmd)
 {
+    DWORD retCode = DD_OK;
     LPD3DHAL_DP2COMMAND dp2command = lpCmd;
-
-    DWORD retCode = D3DERR_COMMAND_UNPARSED; 
-    
+         
     /* prevent it crash if null pointer are being sent */
     if ( (lpCmd == NULL) || (lpRetCmd == NULL) )
     {
@@ -151,35 +165,40 @@
     }
     
     *lpRetCmd = lpCmd;
-    
-    /* check for vaild command, only 3 command is vaild */
-    if (dp2command->bCommand == D3DDP2OP_VIEWPORTINFO) 
-    {    	
-        /* dp2command->wStateCount * sizeof D3DHAL_DP2VIEWPORTINFO + 4 bytes */
-        *(PBYTE)lpRetCmd += ((dp2command->wStateCount * sizeof(D3DHAL_DP2VIEWPORTINFO)) + sizeof(ULONG_PTR));
-        retCode = 0;
-    }                                                                                          
-    else if (dp2command->bCommand == D3DDP2OP_WINFO) 
-    {	
-        /* dp2command->wStateCount * sizeof D3DHAL_DP2WINFO + 4 bytes */
-        *(PBYTE)lpRetCmd += (dp2command->wStateCount * sizeof(D3DHAL_DP2WINFO)) + sizeof(ULONG_PTR);                                                          
-        retCode = 0;
-    } 
-	else if (dp2command->bCommand == 0x0d) 
-    {	
-        /* dp2command->wStateCount * how many wStateCount ? + 4 bytes */
-        *(PBYTE)lpRetCmd += ((dp2command->wStateCount * dp2command->bReserved) + sizeof(ULONG_PTR));               
-        retCode = 0;
-    }
-   
-	/* set error code for command 0 to 3, 8 and 15 to 255 */    
-    else if ( (dp2command->bCommand <= D3DDP2OP_INDEXEDTRIANGLELIST) || // dp2command->bCommand  <= with 0 to 3
+
+    switch (dp2command->bCommand)
+    {
+       /* check for vaild command, only 3 command is vaild */
+       case D3DDP2OP_VIEWPORTINFO:
+           *(PBYTE)lpRetCmd += ((dp2command->wStateCount * sizeof(D3DHAL_DP2VIEWPORTINFO)) + sizeof(D3DHAL_DP2COMMAND));
+           break;
+
+       case D3DDP2OP_WINFO:
+           *(PBYTE)lpRetCmd += (dp2command->wStateCount * sizeof(D3DHAL_DP2WINFO)) + sizeof(D3DHAL_DP2COMMAND);
+           break;
+
+       case 0x0d: /* Undocumented in MSDN */
+           *(PBYTE)lpRetCmd += ((dp2command->wStateCount * dp2command->bReserved) + sizeof(D3DHAL_DP2COMMAND));
+           break;
+
+       
+       /* set the error code */
+       default:
+               
+           if ( (dp2command->bCommand <= D3DDP2OP_INDEXEDTRIANGLELIST) || // dp2command->bCommand  <= with 0 to 3
               (dp2command->bCommand == D3DDP2OP_RENDERSTATE) ||  // dp2command->bCommand  == with 8
               (dp2command->bCommand >= D3DDP2OP_LINELIST) )  // dp2command->bCommand  >= with 15 to 255
-    {
-       retCode = E_FAIL; 
+           {
+               /* set error code for command 0 to 3, 8 and 15 to 255 */
+               retCode = E_FAIL; 
+           }
+           else
+           {   /* set error code for 4 - 7, 9 - 12, 14  */
+               retCode = D3DERR_COMMAND_UNPARSED; 
+           }
+            
     }
-      
+
     return retCode;
 }
 




More information about the Ros-diffs mailing list