Skip to content

Commit

Permalink
Move most of the remaining arrays out of the rendering loop. There is…
Browse files Browse the repository at this point in the history
… 1 remaining.
  • Loading branch information
mdsitton committed Jun 3, 2011
1 parent 14ad911 commit 8c3315b
Showing 1 changed file with 78 additions and 83 deletions.
161 changes: 78 additions & 83 deletions src/Neck.py
Expand Up @@ -151,6 +151,38 @@ def __init__(self, engine, instrument, playerObj):
[-w / 2+1.0, 0.4, l],
[-w / 2-1.0, 0.4, l]], dtype=np.float32)

self.board_col_flash = np.array([[color[0],color[1],color[2], 0],
[color[0],color[1],color[2], 0],
[color[0],color[1],color[2], self.vis],
[color[0],color[1],color[2], self.vis],
[color[0],color[1],color[2], self.vis],
[color[0],color[1],color[2], self.vis],
[color[0],color[1],color[2], 0],
[color[0],color[1],color[2], 0]], dtype=np.float32)

self.bpm_vtx = np.array([[-(w / 2), 0, 0],
[-(w / 2), 0, 0],
[(w / 2), 0, 0],
[(w / 2), 0, 0]], dtype=np.float32)

self.board_tex_static = np.array([[0.0, self.project(-2 * self.beatsPerUnit)],
[1.0, self.project(-2 * self.beatsPerUnit)],
[0.0, self.project(-1 * self.beatsPerUnit)],
[1.0, self.project(-1 * self.beatsPerUnit)],
[0.0, self.project(l * self.beatsPerUnit * .7)],
[1.0, self.project(l * self.beatsPerUnit * .7)],
[0.0, self.project(l * self.beatsPerUnit)],
[1.0, self.project(l * self.beatsPerUnit)]], dtype=np.float32)

self.board_tex = np.array([[0.0, 0],
[1.0, 0],
[0.0, 0],
[1.0, 0],
[0.0, 0],
[1.0, 0],
[0.0, 0],
[1.0, 0]], dtype=np.float32)

# evilynux - Just in case the type has became double, convert to float32
self.board_col = self.board_col.astype(np.float32)
self.board_vtx = self.board_vtx.astype(np.float32)
Expand All @@ -161,6 +193,10 @@ def __init__(self, engine, instrument, playerObj):
self.soloLightVtx2 = self.soloLightVtx2.astype(np.float32)
self.shader_neck_vtx = self.shader_neck_vtx.astype(np.float32)
self.track_vtx = self.track_vtx.astype(np.float32)
self.board_col_flash = self.board_col_flash.astype(np.float32)
self.bpm_vtx = self.bpm_vtx.astype(np.float32)
self.board_tex_static = self.board_tex_static.astype(np.float32)
self.board_tex = self.board_tex.astype(np.float32)

self.neckType = playerObj.neckType
if self.neckType == 0:
Expand Down Expand Up @@ -341,19 +377,10 @@ def renderIncomingNeck(self, visibility, song, pos, time, neckTexture): #MFH -
[-w / 2, 0, z + 2 + l],
[w / 2, 0, z + 2 + l]], dtype=np.float32)

board_tex = np.array([[0.0, self.project(-2 * self.beatsPerUnit)],
[1.0, self.project(-2 * self.beatsPerUnit)],
[0.0, self.project(-1 * self.beatsPerUnit)],
[1.0, self.project(-1 * self.beatsPerUnit)],
[0.0, self.project(l * self.beatsPerUnit * .7)],
[1.0, self.project(l * self.beatsPerUnit * .7)],
[0.0, self.project(l * self.beatsPerUnit)],
[1.0, self.project(l * self.beatsPerUnit)]], dtype=np.float32)

if neckTexture:
neckTexture.texture.bind()

cmgl.drawArrays(GL_TRIANGLE_STRIP, vertices=board_vtx, colors=self.board_col, texcoords=board_tex)
cmgl.drawArrays(GL_TRIANGLE_STRIP, vertices=board_vtx, colors=self.board_col, texcoords=self.board_tex_static)

glDisable(GL_TEXTURE_2D)

Expand All @@ -367,7 +394,6 @@ def renderIncomingNecks(self, visibility, song, pos):
boardWindowMax = pos + self.currentPeriod * self.beatsPerBoard
track = song.midiEventTrack[self.player]


if self.incomingNeckMode > 0: #if enabled
if self.useMidiSoloMarkers:
for time, event in track.getEvents(boardWindowMin, boardWindowMax):
Expand Down Expand Up @@ -419,31 +445,19 @@ def renderIncomingNecks(self, visibility, song, pos):

def renderNeckMethod(self, visibility, offset, neck, alpha = False): #blazingamer: New neck rendering method

color = (1,1,1)

v = visibility
l = self.boardLength

glEnable(GL_TEXTURE_2D)

board_tex = np.array([[0.0, self.project(offset - 2 * self.beatsPerUnit)],
[1.0, self.project(offset - 2 * self.beatsPerUnit)],
[0.0, self.project(offset - 1 * self.beatsPerUnit)],
[1.0, self.project(offset - 1 * self.beatsPerUnit)],
[0.0, self.project(offset + l * self.beatsPerUnit * .7)],
[1.0, self.project(offset + l * self.beatsPerUnit * .7)],
[0.0, self.project(offset + l * self.beatsPerUnit)],
[1.0, self.project(offset + l * self.beatsPerUnit)]], dtype=np.float32)

#must be separate for neck flashing.
board_col = np.array([[color[0],color[1],color[2], 0],
[color[0],color[1],color[2], 0],
[color[0],color[1],color[2], v],
[color[0],color[1],color[2], v],
[color[0],color[1],color[2], v],
[color[0],color[1],color[2], v],
[color[0],color[1],color[2], 0],
[color[0],color[1],color[2], 0]], dtype=np.float32)
if offset == 0:
board_tex = self.board_tex_static
else:
board_tex = self.board_tex

if self.failcount == v:
board_col = self.board_col_flash
else:
board_col = self.board_col

if alpha == True:
glBlendFunc(GL_ONE, GL_ONE)
Expand Down Expand Up @@ -562,21 +576,10 @@ def drawTrack(self, visibility, song, pos):
if not song.readyToGo:
return

l = self.boardLength

if self.staticStrings:
offset = 0
track_tex = self.board_tex_static
else:
offset = (pos - self.lastBpmChange) / self.currentPeriod + self.baseBeat

track_tex = np.array([[0.0, self.project(offset - 2 * self.beatsPerUnit)],
[1.0, self.project(offset - 2 * self.beatsPerUnit)],
[0.0, self.project(offset - 1 * self.beatsPerUnit)],
[1.0, self.project(offset - 1 * self.beatsPerUnit)],
[0.0, self.project(offset + l * self.beatsPerUnit * .7)],
[1.0, self.project(offset + l * self.beatsPerUnit * .7)],
[0.0, self.project(offset + l * self.beatsPerUnit)],
[1.0, self.project(offset + l * self.beatsPerUnit)]], dtype=np.float32)
track_tex = self.board_tex

glEnable(GL_TEXTURE_2D)

Expand All @@ -588,11 +591,8 @@ def drawTrack(self, visibility, song, pos):
else:
if self.centerLines:
self.centerLines.texture.bind()

if self.staticStrings: #MFH
cmgl.drawArrays(GL_TRIANGLE_STRIP, vertices=self.track_vtx, colors=self.board_col, texcoords=track_tex)
else: #MFH: original moving strings
cmgl.drawArrays(GL_TRIANGLE_STRIP, vertices=self.track_vtx, colors=self.board_col, texcoords=track_tex)

cmgl.drawArrays(GL_TRIANGLE_STRIP, vertices=self.track_vtx, colors=self.board_col, texcoords=track_tex)

glDisable(GL_TEXTURE_2D)

Expand All @@ -605,29 +605,12 @@ def drawSideBars(self, visibility, song, pos):
color = (1,1,1)

v = visibility
w = self.boardWidth + 0.15
l = self.boardLength

offset = (pos - self.lastBpmChange) / self.currentPeriod + self.baseBeat
w = self.boardWidth + 0.15

board_tex = np.array([[0.0, self.project(offset - 2 * self.beatsPerUnit)],
[1.0, self.project(offset - 2 * self.beatsPerUnit)],
[0.0, self.project(offset - 1 * self.beatsPerUnit)],
[1.0, self.project(offset - 1 * self.beatsPerUnit)],
[0.0, self.project(offset + l * self.beatsPerUnit * .7)],
[1.0, self.project(offset + l * self.beatsPerUnit * .7)],
[0.0, self.project(offset + l * self.beatsPerUnit)],
[1.0, self.project(offset + l * self.beatsPerUnit)]], dtype=np.float32)

#must be separate for sidebar flashing.
board_col = np.array([[color[0],color[1],color[2], 0],
[color[0],color[1],color[2], 0],
[color[0],color[1],color[2], v],
[color[0],color[1],color[2], v],
[color[0],color[1],color[2], v],
[color[0],color[1],color[2], v],
[color[0],color[1],color[2], 0],
[color[0],color[1],color[2], 0]], dtype=np.float32)
if self.failcount == v:
board_col = self.board_col_flash
else:
board_col = self.board_col

glEnable(GL_TEXTURE_2D)
if self.instrument.starPowerActive and self.oSideBars:
Expand All @@ -638,7 +621,7 @@ def drawSideBars(self, visibility, song, pos):
self.failSideBars.texture.bind()
else:
self.sideBars.texture.bind()
cmgl.drawArrays(GL_TRIANGLE_STRIP, vertices=self.sidebars_vtx, colors=board_col, texcoords=board_tex)
cmgl.drawArrays(GL_TRIANGLE_STRIP, vertices=self.sidebars_vtx, colors=board_col, texcoords=self.board_tex)
glDisable(GL_TEXTURE_2D)

if shaders.enable("sololight"):
Expand All @@ -656,10 +639,8 @@ def drawBPM(self, visibility, song, pos):
if not song.readyToGo:
return


w = self.boardWidth


track = song.track[self.player]

glEnable(GL_TEXTURE_2D)
Expand All @@ -672,13 +653,11 @@ def drawBPM(self, visibility, song, pos):
z = ((time - pos) / self.currentPeriod) / self.beatsPerUnit
sw = 0.1 #width



bpm_vtx = np.array([[-(w / 2), 0, z + sw],
[-(w / 2), 0, z - sw],
[(w / 2), 0, z + sw],
[(w / 2), 0, z - sw]], dtype=np.float32)

for i in range(0,4):
if i == 0 or i == 2:
self.bpm_vtx[i][2] = z + sw
else:
self.bpm_vtx[i][2] = z - sw

if event.barType == 0: #half-beat
self.bpm_halfbeat.texture.bind()
Expand All @@ -687,13 +666,16 @@ def drawBPM(self, visibility, song, pos):
elif event.barType == 2: #measure
self.bpm_measure.texture.bind()

cmgl.drawArrays(GL_TRIANGLE_STRIP, vertices=bpm_vtx, colors=self.bpm_col, texcoords=self.bpm_tex)
cmgl.drawArrays(GL_TRIANGLE_STRIP, vertices=self.bpm_vtx, colors=self.bpm_col, texcoords=self.bpm_tex)

glPopMatrix()

glDisable(GL_TEXTURE_2D)

def render(self, visibility, song, pos):

l = self.boardLength

self.currentPeriod = self.instrument.neckSpeed

if self.isFailing == True:
Expand Down Expand Up @@ -751,11 +733,24 @@ def render(self, visibility, song, pos):

if not (self.instrument.coOpFailed and not self.instrument.coOpRestart):

offset = (pos - self.lastBpmChange) / self.currentPeriod + self.baseBeat

#basically sets the scrolling of the necks
self.board_tex[0][1] = self.board_tex[1][1] = self.project(offset - 2 * self.beatsPerUnit)
self.board_tex[2][1] = self.board_tex[3][1] = self.project(offset - 1 * self.beatsPerUnit)
self.board_tex[4][1] = self.board_tex[5][1] = self.project(offset + l * self.beatsPerUnit * .7)
self.board_tex[6][1] = self.board_tex[7][1] = self.project(offset + l * self.beatsPerUnit)

if self.ocount < 1:
self.ocount += .1
else:
self.ocount = 1

#used for fail flashing.
if self.isFailing:
for i in range(2,6):
self.board_col_flash[i][3] = self.failcount

self.vis = visibility
if self.doNecksRender == True:
self.renderNeck(visibility, song, pos)
Expand Down

0 comments on commit 8c3315b

Please sign in to comment.