id
stringlengths
2
7
text
stringlengths
17
51.2k
title
stringclasses
1 value
c169700
== 0 && theInputState.prevTouchDurations[id] > 0 theInputState.m.RUnlock() return r }
c169701
s := theInputState.touchDurations[id] theInputState.m.RUnlock() return s }
c169702
return graphics.InternalImageSize(i.width), graphics.InternalImageSize(i.height) }
c169703
a value not only when an error occur but also it is closed. return err } } }
c169704
ch := make(chan struct{}) var err error funcs <- func() { err = f() close(ch) } <-ch return err }
c169705
return minInternalImageSize } r := 1 for r < x { r <<= 1 } return r }
c169706
i := 0; i < len(out); i++ { a := int16(volume * math.MaxInt16) if i%length < int(float64(length)*sequence) { a = -a } out[i] = a } }
c169707
:= (ebiten.MaxTPS()/2 - 2) * sampleRate / ebiten.MaxTPS() l := make([]int16, size) r := make([]int16, size) square(l, vol, freq, 0.25) square(r, vol, freq, 0.25) p, _ := audio.NewPlayerFromBytes(audioContext, toBytes(l, r)) p.Play() return rune(note) }
c169708
// Decay a := amp[j] * math.Exp(-5*float64(i)*freq/baseFreq/(x[j]*sampleRate)) v += a * math.Sin(2.0*math.Pi*float64(i)*freq*float64(j+1)/sampleRate) } return v / 5.0 }
c169709
:= audio.NewPlayerFromBytes(audioContext, pianoNoteSamples[f]) p.Play() }
c169710
op.StrokeColor) op := &ebiten.DrawTrianglesOptions{} op.Address = ebiten.AddressRepeat target.DrawTriangles(vs, is, emptyImage, op) } }
c169711
%f]]", g.a_1+1, g.b, g.tx, g.c, g.d_1+1, g.ty) }
c169712
g.d_1 = 0 g.tx = 0 g.ty = 0 }
c169713
other.tx c := other.c*(g.a_1+1) + (other.d_1+1)*g.c d := other.c*g.b + (other.d_1+1)*(g.d_1+1) ty := other.c*g.tx + (other.d_1+1)*g.ty + other.ty g.a_1 = a - 1 g.b = b g.c = c g.d_1 = d - 1 g.tx = tx g.ty = ty }
c169714
+ cos*g.c d := sin*g.b + cos*(g.d_1+1) ty := sin*g.tx + cos*g.ty g.a_1 = a - 1 g.b = b g.c = c g.d_1 = d - 1 g.tx = tx g.ty = ty }
c169715
(-(g.d_1+1)*g.tx + g.b*g.ty) / det ty := (g.c*g.tx + -(g.a_1+1)*g.ty) / det g.a_1 = a - 1 g.b = b g.c = c g.d_1 = d - 1 g.tx = tx g.ty = ty }
c169716
GeoM{} g.Scale(x, y) return g }
c169717
GeoM{} g.Translate(tx, ty) return g }
c169718
GeoM{} g.Rotate(theta) return g }
c169719
native, err := context.newFramebuffer(texture) if err != nil { return nil, err } return &framebuffer{ native: native, width: width, height: height, }, nil }
c169720
{ return &framebuffer{ native: context.getScreenFramebuffer(), width: width, height: height, } }
c169721
_, _, _, a := m.At(x, y).RGBA() if a != 0xffff { return false } } } return true }
c169722
} else { e.bw.Reset(e) } e.err = e.writeImage(e.bw, e.m, e.cb, levelToZlib(e.enc.CompressionLevel)) if e.err != nil { return } e.err = e.bw.Flush() }
c169723
return zlib.BestSpeed case BestCompression: return zlib.BestCompression default: return zlib.DefaultCompression } }
c169724
e Encoder return e.Encode(w, m) }
c169725
else if len(pal) <= 4 { e.cb = cbP2 } else if len(pal) <= 16 { e.cb = cbP4 } else { e.cb = cbP8 } } else { switch m.ColorModel() { case color.GrayModel: e.cb = cbG8 case color.Gray16Model: e.cb = cbG16 case color.RGBAModel, color.NRGBAModel, color.AlphaModel: if opaque(m) { e.cb = cbTC8 } else { e.cb = cbTCA8 } default: if opaque(m) { e.cb = cbTC16 } else { e.cb = cbTCA16 } } } _, e.err = io.WriteString(w, pngHeader) e.writeIHDR() if pal != nil { e.writePLTEAndTRNS(pal) } e.writeIDATs() e.writeIEND() return e.err }
c169726
graphicscommand.NewImage(width, height), } i.clear() theImages.add(i) return i }
c169727
graphicscommand.NewScreenFramebufferImage(width, height), screen: true, } i.clear() theImages.add(i) return i }
c169728
i.h2 = graphics.InternalImageSize(h) } return i.w2, i.h2 }
c169729
another stale image, this means that // the former image can be restored from the latest state of the latter image. }
c169730
i.makeStale() return } if x == 0 && y == 0 && width == w && height == h { if pixels != nil { if i.basePixels == nil { i.basePixels = &Pixels{ length: 4 * w * h, } } i.basePixels.CopyFrom(pixels, 0) } else { // If basePixels is nil, the restored pixels are cleared. // See restore() implementation. i.basePixels = nil } i.drawTrianglesHistory = nil i.stale = false return } if len(i.drawTrianglesHistory) > 0 { panic("restorable: ReplacePixels for a part after DrawTriangles is forbidden") } if i.stale { return } idx := 4 * (y*w + x) if pixels != nil { if i.basePixels == nil { i.basePixels = &Pixels{ length: 4 * w * h, } } for j := 0; j < height; j++ { i.basePixels.CopyFrom(pixels[4*j*width:4*(j+1)*width], idx) idx += 4 * w } } else if i.basePixels != nil { zeros := make([]byte, 4*width) for j := 0; j < height; j++ { i.basePixels.CopyFrom(zeros, idx) idx += 4 * w } } }
c169731
image") } if len(vertices) == 0 { return } theImages.makeStaleIfDependingOn(i) if img.stale || img.volatile || i.screen || !IsRestoringEnabled() || i.volatile { i.makeStale() } else { i.appendDrawTrianglesHistory(img, vertices, indices, colorm, mode, filter, address) } i.image.DrawTriangles(img.image, vertices, indices, colorm, mode, filter, address) }
c169732
care if image is stale or not here. item := &drawTrianglesHistoryItem{ image: image, vertices: vertices, indices: indices, colorm: colorm, mode: mode, filter: filter, address: address, } i.drawTrianglesHistory = append(i.drawTrianglesHistory, item) }
c169733
} if i.dependsOn(target) { i.makeStale() } }
c169734
len(pix), } i.drawTrianglesHistory = nil i.stale = false }
c169735
if i.volatile { return } if i.screen { return } if !i.stale { return } i.readPixelsFromGPU() }
c169736
i.drawTrianglesHistory { if c.image == target { return true } } return false }
c169737
:= range i.drawTrianglesHistory { r[c.image] = struct{}{} } return r }
c169738
len(i.drawTrianglesHistory) > 0 }
c169739
i.drawTrianglesHistory = nil i.stale = false }
c169740
!IsRestoringEnabled() { return false, nil } return i.image.IsInvalidated(), nil }
c169741
i, width: width, height: height, } theCommandQueue.Enqueue(c) return i }
c169742
} theCommandQueue.Enqueue(c) theCommandQueue.Flush() return c.result }
c169743
dst: i, src: src, } theCommandQueue.Enqueue(c) // The execution is basically same as replacing pixels. i.lastCommand = lastCommandReplacePixels }
c169744
{ return t.current.x, t.current.y }
c169745
t.next.x, t.next.y }
c169746
y: y, }, startPoppingCount: maxPoppingCount, } }
c169747
break } ii = ni jj = nj moved = true break } // next is the next state of the tile t. next := TileData{} next.value = t.current.value // If there is a tile at the next position (ii, jj), this should be // mergeable. Let's merge. if tt := currentOrNextTileAt(tiles, ii, jj); tt != t && tt != nil { next.value = t.current.value + tt.current.value tt.next.value = 0 tt.next.x = ii tt.next.y = jj tt.movingCount = maxMovingCount } next.x = ii next.y = jj if t.current != next { t.next = next t.movingCount = maxMovingCount } } } if !moved { for t := range tiles { t.next = TileData{} t.movingCount = 0 } } return moved }
c169748
t.next.value { t.poppingCount = maxPoppingCount } t.current = t.next t.next = TileData{} } case 0 < t.startPoppingCount: t.startPoppingCount-- case 0 < t.poppingCount: t.poppingCount-- } return nil }
c169749
b[1], b[5], b[9], b[13], t[1], b[2], b[6], b[10], b[14], t[2], b[3], b[7], b[11], b[15], t[3]) }
c169750
ColorM{} c.Scale(r, g, b, a) return c }
c169751
ColorM{} c.Translate(r, g, b, a) return c }
c169752
ColorM{} c.RotateHue(theta) return c }
c169753
if !os.IsNotExist(err) { return "", err } } name = fmt.Sprintf("%s%s_%d%s", prefix, now.Format(datetimeFormat), i, postfix) } return name, nil }
c169754
switch e.Type { case touch.TypeBegin, touch.TypeMove: s := getDeviceScale() x, y := float64(e.X)/s, float64(e.Y)/s // TODO: Is it ok to cast from int64 to int here? touches[e.Sequence] = &Touch{ ID: int(e.Sequence), X: int(x), Y: int(y), } case touch.TypeEnd: delete(touches, e.Sequence) } ts := []*Touch{} for _, t := range touches { ts = append(ts, t) } u.input.update(ts) } } }
c169755
if d == 1 { return true } if d >= delay && (d-delay)%interval == 0 { return true } return false }
c169756
float.SizeInBytes() * p.num } a.total = t return a.total }
c169757
context.newArrayBuffer(a.totalBytes() * graphics.IndicesNum) }
c169758
{ context.vertexAttribPointer(program, i, p.num, float, total, offset) offset += float.SizeInBytes() * p.num } }
c169759
i := range a.parts { context.disableVertexAttribArray(program, i) } }
c169760
graphics.FilterNearest, graphics.FilterLinear, graphics.FilterScreen, } { shaderFragmentColorMatrixNative, err := context.newShader(fragmentShader, fragmentShaderStr(c, f, a)) if err != nil { panic(fmt.Sprintf("graphics: shader compiling error:\n%s", err)) } defer context.deleteShader(shaderFragmentColorMatrixNative) program, err := context.newProgram([]shader{ shaderVertexModelviewNative, shaderFragmentColorMatrixNative, }, theArrayBufferLayout.names()) if err != nil { return err } s.programs[programKey{ useColorM: c, filter: f, address: a, }] = program } } } s.arrayBuffer = theArrayBufferLayout.newArrayBuffer(context) // Note that the indices passed to NewElementArrayBuffer is not under GC management // in opengl package due to unsafe-way. // See NewElementArrayBuffer in context_mobile.go. s.elementArrayBuffer = context.newElementArrayBuffer(graphics.IndicesNum * 2) return nil }
c169761
if a[i] != b[i] { return false } } return true }
c169762
{ return &InfiniteLoop{ src: src, lstart: introLength, llength: loopLength, pos: -1, } }
c169763
panic(fmt.Sprintf("audio: position must be <= length but not at (*InfiniteLoop).Read: pos: %d, length: %d", i.pos, i.length())) } if err != nil && err != io.EOF { return 0, err } if err == io.EOF || i.pos == i.length() { pos, err := i.Seek(i.lstart, io.SeekStart) if err != nil { return 0, err } i.pos = pos } return n, nil }
c169764
((next - i.lstart) % i.llength) + i.lstart } // Ignore the new position returned by Seek since the source position might not be match with the position // managed by this. if _, err := i.src.Seek(next, io.SeekStart); err != nil { return 0, err } i.pos = next return i.pos, nil }
c169765
i.makeStaleIfDependingOnImpl(img) delete(i.images, img) }
c169766
= nil for img := range i.images { img.resolveStale() } }
c169767
{ p.x16 -= mx } for my <= p.y16 { p.y16 -= my } for p.x16 < 0 { p.x16 += mx } for p.y16 < 0 { p.y16 += my } }
c169768
p.lean++ if maxLean < p.lean { p.lean = maxLean } }
c169769
p.lean-- if p.lean < -maxLean { p.lean = -maxLean } }
c169770
op.GeoM.Translate(float64(-x16)/16, float64(-y16)/16) op.GeoM.Translate(float64(-w*2), float64(-h*2)) op.GeoM.Rotate(float64(-a)*2*math.Pi/maxAngle + math.Pi*3.0/2.0) op.GeoM.Translate(float64(gw)/2, float64(gh)-32) ground.DrawImage(repeatedGophersImage, op) }
c169771
op.GeoM.Scale(1/z, 8) // 8 is an arbitrary number not to make empty lines. op.GeoM.Translate(float64(pw)/2, float64(j)/z) perspectiveGroundImage.DrawImage(ground.SubImage(image.Rect(0, j, gw, j+1)).(*ebiten.Image), op) } perspectiveGroundImage.DrawImage(fogImage, nil) op := &ebiten.DrawImageOptions{} op.GeoM.Translate(-float64(pw)/2, 0) op.GeoM.Rotate(-1 * float64(thePlayer.lean) / maxLean * math.Pi / 8) op.GeoM.Translate(float64(screenWidth)/2, screenHeight/3) screen.DrawImage(perspectiveGroundImage, op) }
c169772
return "Down" case DirLeft: return "Left" } panic("not reach") }
c169773
len(ts) >= 2 { break } if len(ts) == 1 { if ts[0] != i.touchID { i.touchState = touchStateInvalid } else { x, y := ebiten.TouchPosition(ts[0]) i.touchLastPosX = x i.touchLastPosY = y } break } if len(ts) == 0 { dx := i.touchLastPosX - i.touchInitPosX dy := i.touchLastPosY - i.touchInitPosY d, ok := vecToDir(dx, dy) if !ok { i.touchState = touchStateNone break } i.touchDir = d i.touchState = touchStateSettled } case touchStateSettled: i.touchState = touchStateNone case touchStateInvalid: if len(ebiten.TouchIDs()) == 0 { i.touchState = touchStateNone } } }
c169774
} if i.mouseState == mouseStateSettled { return i.mouseDir, true } if i.touchState == touchStateSettled { return i.touchDir, true } return 0, false }
c169775
buf[4*i+1] = byte(b >> 8) buf[4*i+2] = byte(b) buf[4*i+3] = byte(b >> 8) p++ } s.position += int64(len(buf)) s.position %= length * 4 if origBuf != nil { n := copy(origBuf, buf) s.remaining = buf[n:] return n, nil } return len(buf), nil }
c169776
:= i.Bounds().Size() return s.X, s.Y }
c169777
clr.RGBA() r, g, b, a := uint8(r16>>8), uint8(g16>>8), uint8(b16>>8), uint8(a16>>8) i.mipmap.original().Fill(r, g, b, a) i.disposeMipmaps() return nil }
c169778
return image.Rect(0, 0, w, h) } return i.bounds }
c169779
return nil } i.mipmap.dispose() i.resolvePendingPixels(false) return nil }
c169780
height) i := &Image{ mipmap: newMipmap(s), filter: filter, } i.addr = i return i, nil }
c169781
{ return } i.mipmap.orig.MakeVolatile() i.disposeMipmaps() }
c169782
isFullscreen") } return u.window.GetMonitor() != nil }
c169783
* u.getScale() * u.glfwScale()) h := int(float64(u.height) * u.getScale() * u.glfwScale()) return w, h }
c169784
sw := float64(v.Width) / u.glfwScale() / float64(u.width) sh := float64(v.Height) / u.glfwScale() / float64(u.height) s := sw if s > sh { s = sh } u.fullscreenScale = s } return u.fullscreenScale }
c169785
return u.getScale() * devicescale.GetAt(cm.x, cm.y) } return u.getScale() * devicescale.GetAt(u.currentMonitor().GetPos()) }
c169786
u.height == height && u.scale == scale && u.isFullscreen() == fullscreen && u.vsync == vsync { return false } u.forceSetScreenSize(width, height, scale, fullscreen, vsync) return true }
c169787
window belongs to. This requires OS API. return u.currentMonitorFromPosition() }
c169788
p := int(img.Pix[idx0]) bs[idx1] = palette[4*p] bs[idx1+1] = palette[4*p+1] bs[idx1+2] = palette[4*p+2] bs[idx1+3] = palette[4*p+3] idx0++ idx1 += 4 } idx0 += d } default: dstImg := &image.RGBA{ Pix: bs, Stride: 4 * w, Rect: image.Rect(0, 0, w, h), } draw.Draw(dstImg, image.Rect(0, 0, w, h), img, img.Bounds().Min, draw.Src) } return bs }
c169789
make([]float32, n)...) } copy(q.vertices[q.nvertices:], vertices) q.nvertices += len(vertices) }
c169790
q.appendVertices(vertices) q.appendIndices(indices, uint16(q.nextIndex)) q.nextIndex += len(vertices) / graphics.VertexFloatNum q.tmpNumIndices += len(indices) // TODO: If dst is the screen, reorder the command to be the last. q.doEnqueueDrawTrianglesCommand(dst, src, len(vertices), len(indices), color, mode, filter, address, split) }
c169791
last. q.commands = append(q.commands, command) }
c169792
return } if recordLog() { fmt.Printf("%s\n", c) } // TODO: indexOffset should be reset if the command type is different // from the previous one. This fix is needed when another drawing command is // introduced than drawTrianglesCommand. indexOffset += c.NumIndices() } if 0 < nc { // Call glFlush to prevent black flicking (especially on Android (#226) and iOS). theGraphicsDriver.Flush() } q.commands = q.commands[nc:] } theGraphicsDriver.End() q.commands = nil q.nvertices = 0 q.nindices = 0 q.tmpNumIndices = 0 q.nextIndex = 0 }
c169793
if err := theGraphicsDriver.Draw(c.nindices, indexOffset, c.mode, c.color, c.filter, c.address); err != nil { return err } return nil }
c169794
{ return false } if c.src != src { return false } if !c.color.Equals(color) { return false } if c.mode != mode { return false } if c.filter != filter { return false } if c.address != address { return false } return true }
c169795
{ c.dst.image.ReplacePixels(c.pixels, c.x, c.y, c.width, c.height) return nil }
c169796
:= c.img.image.Pixels() if err != nil { return err } c.result = p return nil }
c169797
c.target.image.Dispose() return nil }
c169798
!= nil { return err } c.result.image = i return nil }
c169799
err = theGraphicsDriver.NewScreenFramebufferImage(c.width, c.height) return err }