Advertisement
cloudlink

crt_pi_configs.py zfast test

Jun 13th, 2018
271
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 9.82 KB | None | 0 0
  1. # creates cfg files for crt-pi
  2. # params are:
  3. # * core (eg mame2003 or fbalpha)
  4. # * screen width (eg 1920) OR curvature
  5. # * screen height (eg 1080)
  6. # example usage:
  7. # python crt_pi_configs.py mame2003 1920 1080
  8. # python crt_pi_configs.py fbalpha 1920 1080
  9. # python crt_pi_configs.py consoles 1920 1080
  10. # python -c "import crt_pi_configs; crt_pi_configs.createZip(False,1920,1080)"
  11.  
  12. from __future__ import division
  13. import sys
  14. import os
  15. import shutil
  16.  
  17.  
  18. def generateConfigs(core, curvature=False, screenWidth=0, screenHeight=0):
  19. console = False
  20. if "mame2003" in core:
  21. fileName = "resolution_db/mame2003.txt"
  22. coreName = "MAME 2003"
  23. elif "fbalpha" in core:
  24. fileName = "resolution_db/fbalpha.txt"
  25. coreName = "FB Alpha"
  26. elif "consoles" in core:
  27. fileName = "resolution_db/consoles.txt"
  28. # Initialise coreName for consoles to allow log file creation
  29. coreName = "Consoles"
  30. console = True
  31.  
  32. if not curvature:
  33. curvature = False
  34. # Tolerance for "scale to fit" in either axis - the unit is the percentage of the game size in that direction. Default is 25 (i.e. 25%)
  35. tolerance = 25
  36. resolution = str(screenWidth) + "x" + str(screenHeight)
  37. outputLogFile = open(coreName + "-" + resolution + ".csv", "w")
  38. outputLogFile.write("Tolerance : ,{}\n".format(tolerance))
  39. outputLogFile.write("ROM Name,X,Y,Orientation,Aspect1,Aspect2,ViewportWidth,ViewportHeight,HorizontalOffset,VerticalOffset,ScaleFactor\n")
  40.  
  41. resolutionDbFile = open(fileName, "r" )
  42. print("Opened database file {}".format(fileName))
  43. if not curvature:
  44. print("created log file ./{}".format(outputLogFile.name))
  45. print("Creating system-specific config files.\n")
  46. sys.stdout.write('[')
  47. sys.stdout.flush()
  48. gameCount = 0
  49.  
  50. for gameInfo in resolutionDbFile:
  51. gameCount = gameCount+1
  52. # strip line breaks
  53. gameInfo = gameInfo.rstrip()
  54.  
  55. # parse info
  56. gameInfo = gameInfo.split(",")
  57. gameName = gameInfo[0]
  58. gameOrientation = gameInfo[3]
  59. gameWidth = int(gameInfo[1])
  60. gameHeight = int(gameInfo[2])
  61. aspectRatio = int(gameInfo[9]) / int(gameInfo[10])
  62. gameType = gameInfo[4]
  63. #integerWidth = int(gameInfo[7])
  64. #integerHeight = int(gameInfo[8])
  65.  
  66. if console:
  67. coreName = gameName
  68.  
  69. cfgFileName = gameName + ".cfg"
  70.  
  71. # Create directory for cfgs, if it doesn"t already exist
  72. if curvature:
  73. path = "curvature" + "/" + coreName
  74. else:
  75. path = resolution + "/" + coreName
  76. if not os.path.isdir(path):
  77. os.makedirs (path)
  78.  
  79. # create cfg file
  80. if (gameCount%100 == 0):
  81. sys.stdout.write('.')
  82. sys.stdout.flush()
  83. newCfgFile = open(path + "/" + cfgFileName, "w")
  84.  
  85. if "V" in gameType:
  86. # Vector games shouldn"t use shaders, so clear it out
  87. newCfgFile.write("# Auto-generated vector .cfg\n")
  88. newCfgFile.write("# Place in /opt/retropie/configs/all/retroarch/config/{}/\n".format(coreName))
  89. newCfgFile.write("video_shader_enable = \"false\"\n")
  90.  
  91. else:
  92. if "V" in gameOrientation:
  93. if curvature:
  94. shader = "zfast_crt_curve_vertical.glslp"
  95. else:
  96. shader = "zfast_crt_standard_vertical.glslp"
  97. # flip vertical games
  98. gameWidth = int(gameInfo[2])
  99. gameHeight = int(gameInfo[1])
  100. # Calculate pixel 'squareness' and adjust gameHeight figure to keep the same aspect ratio, but with square pixels (keeping Width as-was to avoid scaling artifacts)
  101. pixelSquareness = ((gameWidth/gameHeight)/aspectRatio)
  102. gameHeight = int(gameHeight * pixelSquareness)
  103.  
  104. elif "H" in gameOrientation:
  105. if curvature:
  106. shader = "zfast_crt_curve.glslp"
  107. else:
  108. shader = "zfast_crt_standard.glslp"
  109. # Calculate pixel 'squareness' and adjust gameWidth figure to keep the same aspect ratio, but with square pixels (keeping Height as-was)
  110. pixelSquareness = ((gameWidth/gameHeight)/aspectRatio)
  111. gameWidth = int(gameWidth / pixelSquareness)
  112.  
  113. if not curvature:
  114. # Check scale factor in horizontal and vertical directions
  115. vScaling = screenHeight/gameHeight
  116. hScaling = screenWidth/gameWidth
  117.  
  118. # Keep whichever scaling factor is smaller.
  119. if vScaling < hScaling:
  120. scaleFactor = vScaling
  121. else:
  122. scaleFactor = hScaling
  123.  
  124. # For vertical format games, width multiplies by an integer scale factor, height can multiply by the actual scale factor.
  125. if "V" in gameOrientation:
  126. # Pick whichever integer scale factor is nearest to the actual scale factor for the width without going outside the screen area
  127. if (scaleFactor - int(scaleFactor) > 0.5 and gameWidth * int(scaleFactor + 1) < screenWidth):
  128. viewportWidth = gameWidth * int(scaleFactor + 1)
  129. else:
  130. viewportWidth = gameWidth * int(scaleFactor)
  131. viewportHeight = int(gameHeight * scaleFactor)
  132. # If, somehow, the viewport height is less than the screen height, but it's within tolerance of the game height, scale to fill the screen vertically
  133. if screenHeight - viewportHeight < (gameHeight * (tolerance / 100)):
  134. viewportHeight = screenHeight
  135.  
  136. # For horizontal games, scale both axes by the scaling factor. If the resulting viewport size is within our tolerance for the game height or width, expand it to fill in that direction
  137. else:
  138. viewportWidth = int(gameWidth * scaleFactor)
  139. if screenWidth - viewportWidth < (gameWidth * (tolerance / 100)):
  140. viewportWidth = screenWidth
  141. viewportHeight = int(gameHeight * scaleFactor)
  142. if screenHeight - viewportHeight < (gameHeight * (tolerance / 100)):
  143. viewportHeight = screenHeight
  144. # Add 'overscan' area for Nestopia consoles, as per original script (more or less)
  145. if ("console" and "Nestopia" in coreName):
  146. viewportHeight = viewportHeight + 8 * int(scaleFactor)
  147.  
  148. # centralise the image
  149. viewportX = int((screenWidth - viewportWidth) / 2)
  150. viewportY = int((screenHeight - viewportHeight) / 2)
  151.  
  152. #Write the output file
  153. newCfgFile.write("# Auto-generated {} .cfg\n".format(shader))
  154. newCfgFile.write("# Game Title : {} , Width : {}, Height : {}, Aspect : {}:{}, Scale Factor : {}\n".format(gameName, gameWidth, gameHeight, int(gameInfo[9]), int(gameInfo[10]),scaleFactor))
  155. if not curvature:
  156. newCfgFile.write("# Screen Width : {}, Screen Height : {}\n".format(screenWidth, screenHeight))
  157. newCfgFile.write("# Place in /opt/retropie/configs/all/retroarch/config/{}/\n".format(coreName))
  158.  
  159. # Disable shader if the scale is too small
  160. if scaleFactor >= 3:
  161. newCfgFile.write("video_shader_enable = \"true\"\n")
  162. newCfgFile.write("video_shader = \"/opt/retropie/configs/all/retroarch/shaders/{}\"\n".format(shader))
  163. newCfgFile.write("aspect_ratio_index = \"22\"\n")
  164. newCfgFile.write("custom_viewport_width = \"{}\"\n".format(viewportWidth))
  165. newCfgFile.write("custom_viewport_height = \"{}\"\n".format(viewportHeight))
  166. newCfgFile.write("custom_viewport_x = \"{}\"\n".format(viewportX))
  167. newCfgFile.write("custom_viewport_y = \"{}\"\n".format(viewportY))
  168. else:
  169. newCfgFile.write("# Insufficient resolution for good quality shader\n")
  170. newCfgFile.write("video_shader_enable = \"false\"\n")
  171.  
  172. outputLogFile.write("{},{},{},{},{},{},{},{},{},{},{}\n".format(gameInfo[0],gameInfo[1],gameInfo[2],gameInfo[3],gameInfo[9],gameInfo[10],viewportWidth,viewportHeight,viewportX,viewportY,scaleFactor))
  173.  
  174. newCfgFile.close()
  175.  
  176. resolutionDbFile.close()
  177. print("]\n")
  178. print("Done!\n")
  179. if not curvature:
  180. outputLogFile.close()
  181. print("Log written to ./{} <--Delete if not needed".format(outputLogFile.name))
  182. print("Files written to ./{}/\nPlease transfer files to /opt/retropie/configs/all/retroarch/config/{}/\n".format(path, coreName))
  183.  
  184.  
  185. def createZip(curvature=False, screenWidth=0, screenHeight=0):
  186. if curvature:
  187. outputFileName = "zfast_crt_curve_configs"
  188. path = "curvature"
  189. else:
  190. resolution = str(screenWidth) + "x" + str(screenHeight)
  191. outputFileName = "zfast_crt_standard_configs_" + resolution
  192. path = resolution
  193. outputFileName = outputFileName.replace(" ", "")
  194. outputFileName = outputFileName.lower()
  195.  
  196. print("Creating zipfile {}".format(outputFileName))
  197. shutil.make_archive(outputFileName, "zip", path)
  198.  
  199. # now delete config dirs
  200. print("Deleting temp directory: {}".format(path))
  201. shutil.rmtree(path)
  202.  
  203.  
  204. if __name__ == "__main__":
  205. if "curvature" in sys.argv[2]:
  206. generateConfigs(sys.argv[1], True)
  207. else:
  208. generateConfigs(sys.argv[1], False, int(sys.argv[2]), int(sys.argv[3]))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement