| Conditions | 2 |
| Total Lines | 86 |
| Lines | 0 |
| Ratio | 0 % |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
| 1 | from ed2d import window |
||
| 20 | def __init__(self): |
||
| 21 | |||
| 22 | self.width = 800 |
||
| 23 | self.height = 600 |
||
| 24 | self.title = "Edge Engine - Texture Filtering Demo" |
||
| 25 | self.running = False |
||
| 26 | |||
| 27 | self.fpsTimer = timing.FpsCounter() |
||
| 28 | self.fpsEstimate = 0 |
||
| 29 | |||
| 30 | self.events = events.Events() |
||
| 31 | self.window = window.Window(self.title, self.width, self.height, window.WindowedMode) |
||
| 32 | self.context = context.Context(3, 3, 2) |
||
| 33 | self.context.window = self.window |
||
| 34 | |||
| 35 | self.events.add_listener(self.process_event) |
||
| 36 | |||
| 37 | self.keys = [] |
||
| 38 | |||
| 39 | gl.init() |
||
| 40 | major = pgl.glGetInteger(gl.GL_MAJOR_VERSION) |
||
| 41 | minor = pgl.glGetInteger(gl.GL_MINOR_VERSION) |
||
| 42 | print ('OpenGL Version: {}.{}'.format(major, minor)) |
||
| 43 | |||
| 44 | gl.glViewport(0, 0, self.width, self.height) |
||
| 45 | |||
| 46 | # Shaders setup |
||
| 47 | vsPath = files.resolve_path('data', 'shaders', 'main.vs') |
||
| 48 | fsPath = files.resolve_path('data', 'shaders', 'texturefiltering.fs') |
||
| 49 | |||
| 50 | vertex = shaders.VertexShader(vsPath) |
||
| 51 | fragment = shaders.FragmentShader(fsPath) |
||
| 52 | self.program = shaders.ShaderProgram(vertex, fragment) |
||
| 53 | self.program.use() |
||
| 54 | self.orthoID = self.program.new_uniform(b'ortho') |
||
| 55 | self.viewPortID = self.program.new_uniform(b'viewPortResolution') |
||
| 56 | |||
| 57 | self.vao = pgl.glGenVertexArrays(1) |
||
| 58 | |||
| 59 | # Load character image into new opengl texture |
||
| 60 | imagePath = files.resolve_path('data', 'images', 'cubix.png') |
||
| 61 | self.texAtlas = texture.Texture(imagePath, self.program) |
||
| 62 | |||
| 63 | ### Physics Scene ### |
||
| 64 | |||
| 65 | # Create a physics engine |
||
| 66 | self.physicsEngineTest = physengine.PhysEngine() |
||
| 67 | |||
| 68 | ### Player physical model ### |
||
| 69 | |||
| 70 | # Create a rectangle the long way, this will be the player |
||
| 71 | self.cModelTestRect = rectangle.Rectangle(0.0, 0.0, width=800, height=600) |
||
| 72 | self.cModelTestRect.update() |
||
| 73 | |||
| 74 | # Creating a object steps: |
||
| 75 | # Create a collision model object |
||
| 76 | # Create a physics object to simulate |
||
| 77 | # Create a mesh object to render |
||
| 78 | self.cModelTest = cmodel.cModel(self.cModelTestRect) |
||
| 79 | self.physicsObjectTest = physobj.PhysObj(self.cModelTest, vector.Vector(3, data=[0.0, 0.0, 1.0])) |
||
| 80 | self.physicsEngineTest.addObject(self.physicsObjectTest) |
||
| 81 | self.meshObjectTest = mesh.Mesh() |
||
| 82 | |||
| 83 | self.meshObjectTest.fromData(data=[ |
||
| 84 | [0.0, 1.0, 0.0], |
||
| 85 | [1.0, 1.0, 0.0], |
||
| 86 | [0.0, 0.0, 0.0], |
||
| 87 | [1.0, 0.0, 0.0]]) |
||
| 88 | |||
| 89 | self.meshObjectTest.setBuffers() |
||
| 90 | self.meshObjectTest.addProgram(self.program) |
||
| 91 | self.meshObjectTest.addTexture(self.texAtlas) |
||
| 92 | self.meshObjectTest.addPhysicsObject(self.physicsObjectTest) |
||
| 93 | |||
| 94 | ### End Player ### |
||
| 95 | |||
| 96 | # Setup projection |
||
| 97 | self.ortho = matrix.orthographic(0.0, self.width, self.height, 0.0, -1.0, 1.0) |
||
| 98 | |||
| 99 | # Update the uniforms in the shaders |
||
| 100 | self.program.set_uniform_matrix(self.orthoID, self.ortho) |
||
| 101 | self.program.set_uniform_array(self.viewPortID, [float(self.width), float(self.height)]) |
||
| 102 | |||
| 103 | glerr = gl.glGetError() |
||
| 104 | if glerr != 0: |
||
| 105 | print ('GLError:', glerr) |
||
| 106 | |||
| 163 |
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.