DXGL r235 - Code Review

Jump to navigation Jump to search
Repository:DXGL
Revision:r234‎ | r235 | r236 >
Date:16:41, 11 August 2012
Author:admin
Status:new
Tags:
Comment:
Support D3DTA_ALPHAREPLICATE
Use registry path for TortoiseSVN
Use Wayback Machine for HTML Help Workshop
Modified paths:
  • /buildtool/buildtool.cpp (modified) (history)
  • /ddraw/shadergen.cpp (modified) (history)

Diff [purge]

Index: buildtool/buildtool.cpp
@@ -28,7 +28,6 @@
2929 char pathbase[FILENAME_MAX+1];
3030 char pathin[FILENAME_MAX+1];
3131 char pathout[FILENAME_MAX+1];
32 - char command[1024];
3332 strncpy(pathbase,path,FILENAME_MAX);
3433 strncpy(pathin,path,FILENAME_MAX);
3534 strncpy(pathout,path,FILENAME_MAX);
@@ -35,33 +34,49 @@
3635 pathbase[strlen(pathbase)-7] = 0;
3736 strncat(pathin,"\\rev.in",FILENAME_MAX-strlen(pathin));
3837 strncat(pathout,"\\rev",FILENAME_MAX-strlen(pathin));
39 - strcpy(command,"subwcrev ");
40 - strcat(command,pathbase);
41 - strcat(command," ");
42 - strcat(command,pathin);
43 - strcat(command," ");
44 - strcat(command,pathout);
45 - STARTUPINFOA startinfo;
46 - ZeroMemory(&startinfo,sizeof(STARTUPINFOA));
47 - startinfo.cb = sizeof(STARTUPINFO);
48 - PROCESS_INFORMATION process;
49 - if(CreateProcessA(NULL,command,NULL,NULL,FALSE,0,NULL,NULL,&startinfo,&process))
 38+ HKEY hKey;
 39+ char svnpath[(MAX_PATH+1)*4];
 40+ bool foundsvn = false;
 41+ DWORD buffersize = MAX_PATH+1;
 42+ if(RegOpenKeyExA(HKEY_LOCAL_MACHINE,"Software\\TortoiseSVN",0,KEY_READ,&hKey) == ERROR_SUCCESS)
5043 {
51 - WaitForSingleObject(process.hProcess,INFINITE);
52 - CloseHandle(process.hProcess);
53 - CloseHandle(process.hThread);
54 - FILE *revfile = fopen(pathout,"r");
55 - if(!revfile)
 44+ if(RegQueryValueExA(hKey,"Directory",NULL,NULL,(LPBYTE)svnpath,&buffersize) == ERROR_SUCCESS)
5645 {
57 - cout << "WARNING: Failed to create revision file" << endl;
58 - return 0;
 46+ foundsvn = true;
 47+ strcat(svnpath,"bin\\subwcrev.exe ");
 48+ strcat(svnpath,pathbase);
 49+ strcat(svnpath," ");
 50+ strcat(svnpath,pathin);
 51+ strcat(svnpath," ");
 52+ strcat(svnpath,pathout);
 53+ STARTUPINFOA startinfo;
 54+ ZeroMemory(&startinfo,sizeof(STARTUPINFOA));
 55+ startinfo.cb = sizeof(STARTUPINFO);
 56+ PROCESS_INFORMATION process;
 57+ cout << svnpath << endl;
 58+ if(CreateProcessA(NULL,svnpath,NULL,NULL,FALSE,0,NULL,NULL,&startinfo,&process))
 59+ {
 60+ WaitForSingleObject(process.hProcess,INFINITE);
 61+ CloseHandle(process.hProcess);
 62+ CloseHandle(process.hThread);
 63+ FILE *revfile = fopen(pathout,"r");
 64+ if(!revfile)
 65+ {
 66+ cout << "WARNING: Failed to create revision file" << endl;
 67+ RegCloseKey(hKey);
 68+ return 0;
 69+ }
 70+ char revstring[32];
 71+ fgets(revstring,32,revfile);
 72+ fclose(revfile);
 73+ RegCloseKey(hKey);
 74+ return atoi(revstring);
 75+ }
 76+ else foundsvn = false;
5977 }
60 - char revstring[32];
61 - fgets(revstring,32,revfile);
62 - fclose(revfile);
63 - return atoi(revstring);
 78+ RegCloseKey(hKey);
6479 }
65 - else
 80+ if(!foundsvn)
6681 {
6782 int result = MessageBoxA(NULL,"Could not find subwcrev.exe, would you like to download TortoiseSVN?","TortoiseSVN not found",
6883 MB_YESNO|MB_ICONWARNING);
@@ -73,6 +88,7 @@
7489 }
7590 else return 0;
7691 }
 92+ return 0;
7793 }
7894
7995 int ProcessHeaders(char *path)
@@ -212,7 +228,9 @@
213229 {
214230 int result = MessageBoxA(NULL,"Could not find HTML Help Workshop, would you like to download it?","HTML Help Workshop not found",
215231 MB_YESNO|MB_ICONERROR);
216 - if(result == IDYES) ShellExecuteA(NULL,"open","http://www.microsoft.com/en-us/download/details.aspx?id=21138",NULL,NULL,SW_SHOWNORMAL);
 232+ if(result == IDYES) ShellExecuteA(NULL,"open",
 233+ "http://web.archive.org/web/20070216084201/http://download.microsoft.com/download/0/A/9/0A939EF6-E31C-430F-A3DF-DFAE7960D564/htmlhelp.exe"
 234+ ,NULL,NULL,SW_SHOWNORMAL);
217235 cout << "ERROR: HTML Help Compiler not found." << endl;
218236 return -1;
219237 }
Index: ddraw/shadergen.cpp
@@ -605,8 +605,8 @@
606606 string arg1,arg2;
607607 int args[4];
608608 bool texfail;
609 - const string blendargs[] = {"color.rgb","gl_Color","texture2DProj(texX,gl_TexCoord[Y]).rgb",
610 - "texture2DProj(texX,gl_TexCoord[Y]).a","texfactor","gl_SecondaryColor","vec3(1,1,1)","1",".rgb",".a","color.a"};
 609+ const string blendargs[] = {"color","gl_Color","texture2DProj(texX,gl_TexCoord[Y])",
 610+ "","texfactor","gl_SecondaryColor","vec3(1,1,1)","1",".rgb",".a",".aaa"};
611611 for(i = 0; i < 8; i++)
612612 {
613613 if((texstate[i].shaderid & 31) == D3DTOP_DISABLE)break;
@@ -620,7 +620,7 @@
621621 arg1 = blendargs[0];
622622 break;
623623 case D3DTA_DIFFUSE:
624 - arg1 = blendargs[1]+blendargs[8];
 624+ arg1 = blendargs[1];
625625 break;
626626 case D3DTA_TEXTURE:
627627 if((texstate[i].shaderid >> 59)&1)
@@ -636,11 +636,12 @@
637637 arg1 = blendargs[4];
638638 break;
639639 case D3DTA_SPECULAR:
640 - arg1 = blendargs[5]+blendargs[8];
 640+ arg1 = blendargs[5];
641641 break;
642642 }
643 - if(args[0] & D3DTA_COMPLEMENT)
644 - arg1 = "(1.0 - " + arg1 + ")";
 643+ if(args[0] & D3DTA_COMPLEMENT) arg1 = "(1.0 - " + arg1 + ")";
 644+ if(args[0] & D3DTA_ALPHAREPLICATE) arg1.append(blendargs[10]);
 645+ else arg1.append(blendargs[8]);
645646 args[1] = (texstate[i].shaderid>>11)&63;
646647 switch(args[1]&7) //arg2
647648 {
@@ -649,7 +650,7 @@
650651 arg2 = blendargs[0];
651652 break;
652653 case D3DTA_DIFFUSE:
653 - arg2 = blendargs[1]+blendargs[8];
 654+ arg2 = blendargs[1];
654655 break;
655656 case D3DTA_TEXTURE:
656657 if((texstate[i].shaderid >> 59)&1)
@@ -662,14 +663,15 @@
663664 break;
664665 case D3DTA_TFACTOR:
665666 FIXME("Support texture factor value");
666 - arg2 = blendargs[4]+blendargs[8];
 667+ arg2 = blendargs[4];
667668 break;
668669 case D3DTA_SPECULAR:
669 - arg2 = blendargs[5]+blendargs[8];
 670+ arg2 = blendargs[5];
670671 break;
671672 }
672 - if(args[1] & D3DTA_COMPLEMENT)
673 - arg2 = "(1.0 - " + arg2 + ")";
 673+ if(args[1] & D3DTA_COMPLEMENT) arg2 = "(1.0 - " + arg2 + ")";
 674+ if(args[1] & D3DTA_ALPHAREPLICATE) arg2.append(blendargs[10]);
 675+ else arg2.append(blendargs[8]);
674676 if(!texfail) switch(texstate[i].shaderid & 31)
675677 {
676678 case D3DTOP_DISABLE:
@@ -714,7 +716,7 @@
715717 {
716718 case D3DTA_CURRENT:
717719 default:
718 - arg1 = blendargs[10];
 720+ arg1 = blendargs[0]+blendargs[9];
719721 break;
720722 case D3DTA_DIFFUSE:
721723 arg1 = blendargs[1]+blendargs[9];
@@ -722,7 +724,7 @@
723725 case D3DTA_TEXTURE:
724726 if((texstate[i].shaderid >> 59)&1)
725727 {
726 - arg1 = blendargs[3];
 728+ arg1 = blendargs[2]+blendargs[9];
727729 arg1.replace(17,1,_itoa(i,idstring,10));
728730 arg1.replace(31,1,_itoa((texstate[i].shaderid>>54)&7,idstring,10));
729731 }
@@ -743,7 +745,7 @@
744746 {
745747 case D3DTA_CURRENT:
746748 default:
747 - arg2 = blendargs[10];
 749+ arg2 = blendargs[1]+blendargs[9];
748750 break;
749751 case D3DTA_DIFFUSE:
750752 arg2 = blendargs[1]+blendargs[9];
@@ -751,7 +753,7 @@
752754 case D3DTA_TEXTURE:
753755 if((texstate[i].shaderid >> 59)&1)
754756 {
755 - arg2 = blendargs[3];
 757+ arg2 = blendargs[2]+blendargs[9];
756758 arg2.replace(17,1,_itoa(i,idstring,10));
757759 arg2.replace(31,1,_itoa((texstate[i].shaderid>>54)&7,idstring,10));
758760 }