1. Список говнокодов пользователя 3Doomer

    Всего: 4

  2. Куча / Говнокод #13882

    +121

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    12. 12
    13. 13
    14. 14
    15. 15
    16. 16
    if
    	(MatchPattern MatData Pattern:"MeshID *: *") and (
    		local	Params = (FilterString (SubString MatData 8 -1) ":")
    		Params.Count == 2 and (
    			MatData = (TrimLeft (TrimRight Params[2]))
    			MID = (Params[1] as integer)
    			if
    				MID < 1 or
    				MID > 1000
    			then
    				InputOK = false
    		)
    	)
    then (
    	...
    )

    MAXScript
    Чумачечая валидация ввода информации о материале по несложному паттерну:
    MeshID <Mesh material ID, a number from 1 to 1000>: <Material name>
    ...
    Use LINQ, Luke!

    3Doomer, 01 Октября 2013

    Комментарии (7)
  3. Куча / Говнокод #13850

    +125

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    12. 12
    13. 13
    14. 14
    15. 15
    16. 16
    Синтаксический сахар в #MAXScript такой сахар!
    
    Надоели конструкции такого вида?
    if (SomeShit == undefined) then (...)
    
    Запили в парочку функций - и всё ок!
    fn Have Obj = (Obj != undefined)
    fn No Obj = (not (Have Obj))
    
    ...
    ......
    Профит!
    if (Have Beer) then (...)
    if (No Glass) then (...)
    
    Миллисекунда оверхеда на вызов функции - в подарок!

    Уроки ленивого программирования для самых ленивых или берегущих клавиатуру xD

    3Doomer, 24 Сентября 2013

    Комментарии (6)
  4. Куча / Говнокод #13694

    +125

    1. 001
    2. 002
    3. 003
    4. 004
    5. 005
    6. 006
    7. 007
    8. 008
    9. 009
    10. 010
    11. 011
    12. 012
    13. 013
    14. 014
    15. 015
    16. 016
    17. 017
    18. 018
    19. 019
    20. 020
    21. 021
    22. 022
    23. 023
    24. 024
    25. 025
    26. 026
    27. 027
    28. 028
    29. 029
    30. 030
    31. 031
    32. 032
    33. 033
    34. 034
    35. 035
    36. 036
    37. 037
    38. 038
    39. 039
    40. 040
    41. 041
    42. 042
    43. 043
    44. 044
    45. 045
    46. 046
    47. 047
    48. 048
    49. 049
    50. 050
    51. 051
    52. 052
    53. 053
    54. 054
    55. 055
    56. 056
    57. 057
    58. 058
    59. 059
    60. 060
    61. 061
    62. 062
    63. 063
    64. 064
    65. 065
    66. 066
    67. 067
    68. 068
    69. 069
    70. 070
    71. 071
    72. 072
    73. 073
    74. 074
    75. 075
    76. 076
    77. 077
    78. 078
    79. 079
    80. 080
    81. 081
    82. 082
    83. 083
    84. 084
    85. 085
    86. 086
    87. 087
    88. 088
    89. 089
    90. 090
    91. 091
    92. 092
    93. 093
    94. 094
    95. 095
    96. 096
    97. 097
    98. 098
    99. 099
    100. 100
    fn AsText Val BufferID:undefined AppendLast:false Prefix:"" Postfix:"" ArraySeparators:#("#(", ",", ")") ValClass:undefined AncestorName:undefined PushVar:undefined = (
    	if PushVar == undefined then PushVar = GIMS.Core.BufferMgr.PushVar
    	case (ClassOf Val) of (
    		ArrayParameter:
    			AsText Val BufferID:BufferID AppendLast:AppendLast Prefix:Prefix Postfix:Postfix ArraySeparators:ArraySeparators ValClass:Array AncestorName:AncestorName PushVar:PushVar
    		Array: (
    			if BufferID != undefined then (
    				PushVar BufferID (Prefix + ArraySeparators[1]) AppendLast:AppendLast
    				for ItemID = 1 to Val.Count do (
    					if ItemID != Val.Count then
    						AsText Val[ItemID] BufferID:BufferID AppendLast:AppendLast Postfix:ArraySeparators[2] AncestorName:AncestorName PushVar:PushVar
    					else
    						AsText Val[ItemID] BufferID:BufferID AppendLast:AppendLast AncestorName:AncestorName PushVar:PushVar
    				)
    				PushVar BufferID (ArraySeparators[3] + Postfix) AppendLast:AppendLast
    			) else (
    				local	Res = (Prefix + ArraySeparators[1])
    				for ItemID = 1 to Val.Count do (
    					if ItemID != Val.Count then
    						Res += (AsText Val[ItemID] Postfix:ArraySeparators[2] AncestorName:AncestorName PushVar:PushVar)
    					else
    						Res += (AsText Val[ItemID] AncestorName:AncestorName PushVar:PushVar)
    				)
    				Res += (ArraySeparators[3] + Postfix)
    			)
    			Res
    		)
    		String: (
    			if BufferID != undefined then
    				PushVar BufferID (Prefix + "\"" + (GIMS.Core.StringOps.ReplaceChars Val ReplaceTags:#(#("\"", "\\"), #("\\\"", "\\\\")) MultiChar:true) + "\"" + Postfix) AppendLast:AppendLast
    			else
    				(Prefix + "\"" + (GIMS.Core.StringOps.ReplaceChars Val ReplaceTags:#(#("\"", "\\"), #("\\\"", "\\\\")) MultiChar:true) + "\"" + Postfix)
    		)
    		Name: (
    			if BufferID != undefined then
    				PushVar BufferID (Prefix + "#" + Val as string + Postfix) AppendLast:AppendLast
    			else
    				(Prefix + "#" + Val as string + Postfix)
    		)
    		BitmapTexture: (
    			GIMS.Core.MaterialOps.FixTexName Val
    			local	FileName = (GetFileNameFile Val.FileName)
    			if BufferID != undefined then (
    				if (DoesFileExist Val.FileName) then (
    					local	FilePath = (GIMS.CurrentGame.ResourceCachePath + AncestorName + "/")
    					MakeDir FilePath All:true
    					CopyFile Val.FileName (FilePath + (FileNameFromPath Val.FileName))
    				)
    				PushVar BufferID (Prefix + "(GIMS.Core.MaterialOps.CreateBitmapFile (GIMS.CurrentGame.ResourceCachePath + \"" + AncestorName + "/\") \"" + FileName + "\")" + Postfix) AppendLast:AppendLast
    			) else
    				(Prefix + "(GIMS.Core.MaterialOps.CreateBitmapFile \"" + (GetFileNamePath Val.FileName) + "\" \"" + FileName + "\")" + Postfix)
    		)
    		default: (
    			local	VarType = (SuperClassOf Val)
    			if VarType == StructDef or VarType == GeometryClass or VarType == Material then (
    				if BufferID == undefined then
    					throw "Undefined BufferID!"
    				local	AllTagNames = (GetPropNames Val),
    						StructNameTagID = (FindItem AllTagNames #StructName),
    						StructName = (
    						if StructNameTagID != 0 then
    							(GetProperty Val AllTagNames[StructNameTagID])
    						else
    							((ClassOf Val) as string)
    						),
    						Tags = (
    							for TempTag in AllTagNames where
    								TempTag != #StructName and
    								not (IsKindOf (GetProperty Val TempTag) MAXScriptFunction)
    							collect
    								TempTag
    						)
    				if Tags.Count == 1 then
    					PushVar BufferID (Prefix + "(" + StructName + "())") AppendLast:AppendLast
    				else (
    					PushVar BufferID (Prefix + "(") AppendLast:AppendLast
    					PushVar BufferID (StructName + " \\") AppendLast:AppendLast
    					case VarType of (
    						GeometryClass: (
    							PushVar BufferID ("Name:" + (AsText Val.Name AncestorName:AncestorName PushVar:PushVar) + " \\") AppendLast:AppendLast
    							PushVar BufferID ("Pos:" + Val.Pos as string + " \\") AppendLast:AppendLast
    						)
    						Material: (
    							PushVar BufferID ("Name:" + (AsText Val.Name AncestorName:AncestorName PushVar:PushVar) + " \\") AppendLast:AppendLast
    							PushVar BufferID ("ShowInViewPort:" + Val.ShowInViewPort as string + " \\") AppendLast:AppendLast
    						)
    					)
    					for TagID = 1 to Tags.Count do
    						AsText (GetProperty Val Tags[TagID]) BufferID:BufferID AppendLast:AppendLast Prefix:(Tags[TagID] as String + ":") Postfix:" \\" AncestorName:AncestorName PushVar:PushVar
    					PushVar BufferID (")" + Postfix) AppendLast:AppendLast
    				)
    			) else (
    				if BufferID != undefined then
    					PushVar BufferID (Prefix + Val as string + Postfix) AppendLast:AppendLast
    				else
    					(Prefix + Val as string + Postfix)
    			)
    		)
    	)
    )

    MAXScript. Сериализация от бога!

    3Doomer, 29 Августа 2013

    Комментарии (4)
  5. Куча / Говнокод #13105

    +133

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    7. 7
    8. 8
    try
    	HeapSize += 268435456 -- +100500 могучих байт в кучу во имя производительности
    catch (
    	try
    		HeapSize += 67108864 -- жалкая попытка добавить хоть что - то
    	catch
    		GIMS.Core.SystemMgr.ThrowError "init error" "Cannot extend the heap :(" -- сглотнуть обиду, поднасрав в лог
    )

    GC, you shall not pass!
    Первая ступень попыток ускорить тормозной MAXScript

    3Doomer, 04 Июня 2013

    Комментарии (4)