id
int32 0
167k
| repo
stringlengths 5
54
| path
stringlengths 4
155
| func_name
stringlengths 1
118
| original_string
stringlengths 52
85.5k
| language
stringclasses 1
value | code
stringlengths 52
85.5k
| code_tokens
listlengths 21
1.41k
| docstring
stringlengths 6
2.61k
| docstring_tokens
listlengths 3
215
| sha
stringlengths 40
40
| url
stringlengths 85
252
|
---|---|---|---|---|---|---|---|---|---|---|---|
12,700 | EngoEngine/engo | engo_mobile_bind.go | RunIteration | func RunIteration() {
runtime.LockOSThread()
defer runtime.UnlockOSThread()
select {
case drawEvent <- struct{}{}:
for {
select {
case <-worker.WorkAvailable():
worker.DoWork()
case <-drawDone:
return
}
}
case <-time.After(500 * time.Millisecond):
return
}
} | go | func RunIteration() {
runtime.LockOSThread()
defer runtime.UnlockOSThread()
select {
case drawEvent <- struct{}{}:
for {
select {
case <-worker.WorkAvailable():
worker.DoWork()
case <-drawDone:
return
}
}
case <-time.After(500 * time.Millisecond):
return
}
} | [
"func",
"RunIteration",
"(",
")",
"{",
"runtime",
".",
"LockOSThread",
"(",
")",
"\n",
"defer",
"runtime",
".",
"UnlockOSThread",
"(",
")",
"\n\n",
"select",
"{",
"case",
"drawEvent",
"<-",
"struct",
"{",
"}",
"{",
"}",
":",
"for",
"{",
"select",
"{",
"case",
"<-",
"worker",
".",
"WorkAvailable",
"(",
")",
":",
"worker",
".",
"DoWork",
"(",
")",
"\n",
"case",
"<-",
"drawDone",
":",
"return",
"\n",
"}",
"\n",
"}",
"\n",
"case",
"<-",
"time",
".",
"After",
"(",
"500",
"*",
"time",
".",
"Millisecond",
")",
":",
"return",
"\n",
"}",
"\n",
"}"
]
| // RunIteration runs every time android calls to update the screen | [
"RunIteration",
"runs",
"every",
"time",
"android",
"calls",
"to",
"update",
"the",
"screen"
]
| 6f88a7379a25d81e976cf6e86ea3617f3b480b1a | https://github.com/EngoEngine/engo/blob/6f88a7379a25d81e976cf6e86ea3617f3b480b1a/engo_mobile_bind.go#L101-L118 |
12,701 | EngoEngine/engo | engo_mobile_bind.go | mobileDraw | func mobileDraw(defaultScene Scene) {
if !initalized {
var ctx mgl.Context
ctx, worker = mgl.NewContext()
Gl = gl.NewContext(ctx)
}
<-drawEvent
defer func() {
drawDone <- struct{}{}
}()
if !initalized {
RunPreparation(defaultScene)
ticker = time.NewTicker(time.Duration(int(time.Second) / opts.FPSLimit))
initalized = true
}
select {
case <-ticker.C:
case <-resetLoopTicker:
ticker.Stop()
ticker = time.NewTicker(time.Duration(int(time.Second) / opts.FPSLimit))
}
Time.Tick()
if !opts.HeadlessMode {
Input.update()
}
// Then update the world and all Systems
currentUpdater.Update(Time.Delta())
Input.Mouse.Action = Neutral
} | go | func mobileDraw(defaultScene Scene) {
if !initalized {
var ctx mgl.Context
ctx, worker = mgl.NewContext()
Gl = gl.NewContext(ctx)
}
<-drawEvent
defer func() {
drawDone <- struct{}{}
}()
if !initalized {
RunPreparation(defaultScene)
ticker = time.NewTicker(time.Duration(int(time.Second) / opts.FPSLimit))
initalized = true
}
select {
case <-ticker.C:
case <-resetLoopTicker:
ticker.Stop()
ticker = time.NewTicker(time.Duration(int(time.Second) / opts.FPSLimit))
}
Time.Tick()
if !opts.HeadlessMode {
Input.update()
}
// Then update the world and all Systems
currentUpdater.Update(Time.Delta())
Input.Mouse.Action = Neutral
} | [
"func",
"mobileDraw",
"(",
"defaultScene",
"Scene",
")",
"{",
"if",
"!",
"initalized",
"{",
"var",
"ctx",
"mgl",
".",
"Context",
"\n",
"ctx",
",",
"worker",
"=",
"mgl",
".",
"NewContext",
"(",
")",
"\n",
"Gl",
"=",
"gl",
".",
"NewContext",
"(",
"ctx",
")",
"\n",
"}",
"\n",
"<-",
"drawEvent",
"\n",
"defer",
"func",
"(",
")",
"{",
"drawDone",
"<-",
"struct",
"{",
"}",
"{",
"}",
"\n",
"}",
"(",
")",
"\n\n",
"if",
"!",
"initalized",
"{",
"RunPreparation",
"(",
"defaultScene",
")",
"\n",
"ticker",
"=",
"time",
".",
"NewTicker",
"(",
"time",
".",
"Duration",
"(",
"int",
"(",
"time",
".",
"Second",
")",
"/",
"opts",
".",
"FPSLimit",
")",
")",
"\n",
"initalized",
"=",
"true",
"\n",
"}",
"\n\n",
"select",
"{",
"case",
"<-",
"ticker",
".",
"C",
":",
"case",
"<-",
"resetLoopTicker",
":",
"ticker",
".",
"Stop",
"(",
")",
"\n",
"ticker",
"=",
"time",
".",
"NewTicker",
"(",
"time",
".",
"Duration",
"(",
"int",
"(",
"time",
".",
"Second",
")",
"/",
"opts",
".",
"FPSLimit",
")",
")",
"\n",
"}",
"\n",
"Time",
".",
"Tick",
"(",
")",
"\n",
"if",
"!",
"opts",
".",
"HeadlessMode",
"{",
"Input",
".",
"update",
"(",
")",
"\n",
"}",
"\n",
"// Then update the world and all Systems",
"currentUpdater",
".",
"Update",
"(",
"Time",
".",
"Delta",
"(",
")",
")",
"\n",
"Input",
".",
"Mouse",
".",
"Action",
"=",
"Neutral",
"\n",
"}"
]
| // mobileDraw runs once per frame. RunIteration for the other backends | [
"mobileDraw",
"runs",
"once",
"per",
"frame",
".",
"RunIteration",
"for",
"the",
"other",
"backends"
]
| 6f88a7379a25d81e976cf6e86ea3617f3b480b1a | https://github.com/EngoEngine/engo/blob/6f88a7379a25d81e976cf6e86ea3617f3b480b1a/engo_mobile_bind.go#L139-L169 |
12,702 | EngoEngine/engo | common/animation.go | NewAnimationComponent | func NewAnimationComponent(drawables []Drawable, rate float32) AnimationComponent {
return AnimationComponent{
Animations: make(map[string]*Animation),
Drawables: drawables,
Rate: rate,
}
} | go | func NewAnimationComponent(drawables []Drawable, rate float32) AnimationComponent {
return AnimationComponent{
Animations: make(map[string]*Animation),
Drawables: drawables,
Rate: rate,
}
} | [
"func",
"NewAnimationComponent",
"(",
"drawables",
"[",
"]",
"Drawable",
",",
"rate",
"float32",
")",
"AnimationComponent",
"{",
"return",
"AnimationComponent",
"{",
"Animations",
":",
"make",
"(",
"map",
"[",
"string",
"]",
"*",
"Animation",
")",
",",
"Drawables",
":",
"drawables",
",",
"Rate",
":",
"rate",
",",
"}",
"\n",
"}"
]
| // NewAnimationComponent creates an AnimationComponent containing all given
// drawables. Animations will be played using the given rate. | [
"NewAnimationComponent",
"creates",
"an",
"AnimationComponent",
"containing",
"all",
"given",
"drawables",
".",
"Animations",
"will",
"be",
"played",
"using",
"the",
"given",
"rate",
"."
]
| 6f88a7379a25d81e976cf6e86ea3617f3b480b1a | https://github.com/EngoEngine/engo/blob/6f88a7379a25d81e976cf6e86ea3617f3b480b1a/common/animation.go#L30-L36 |
12,703 | EngoEngine/engo | common/animation.go | SelectAnimationByName | func (ac *AnimationComponent) SelectAnimationByName(name string) {
ac.CurrentAnimation = ac.Animations[name]
ac.index = 0
} | go | func (ac *AnimationComponent) SelectAnimationByName(name string) {
ac.CurrentAnimation = ac.Animations[name]
ac.index = 0
} | [
"func",
"(",
"ac",
"*",
"AnimationComponent",
")",
"SelectAnimationByName",
"(",
"name",
"string",
")",
"{",
"ac",
".",
"CurrentAnimation",
"=",
"ac",
".",
"Animations",
"[",
"name",
"]",
"\n",
"ac",
".",
"index",
"=",
"0",
"\n",
"}"
]
| // SelectAnimationByName sets the current animation. The name must be
// registered. | [
"SelectAnimationByName",
"sets",
"the",
"current",
"animation",
".",
"The",
"name",
"must",
"be",
"registered",
"."
]
| 6f88a7379a25d81e976cf6e86ea3617f3b480b1a | https://github.com/EngoEngine/engo/blob/6f88a7379a25d81e976cf6e86ea3617f3b480b1a/common/animation.go#L40-L43 |
12,704 | EngoEngine/engo | common/animation.go | SelectAnimationByAction | func (ac *AnimationComponent) SelectAnimationByAction(action *Animation) {
ac.CurrentAnimation = action
ac.index = 0
} | go | func (ac *AnimationComponent) SelectAnimationByAction(action *Animation) {
ac.CurrentAnimation = action
ac.index = 0
} | [
"func",
"(",
"ac",
"*",
"AnimationComponent",
")",
"SelectAnimationByAction",
"(",
"action",
"*",
"Animation",
")",
"{",
"ac",
".",
"CurrentAnimation",
"=",
"action",
"\n",
"ac",
".",
"index",
"=",
"0",
"\n",
"}"
]
| // SelectAnimationByAction sets the current animation.
// An nil action value selects the default animation. | [
"SelectAnimationByAction",
"sets",
"the",
"current",
"animation",
".",
"An",
"nil",
"action",
"value",
"selects",
"the",
"default",
"animation",
"."
]
| 6f88a7379a25d81e976cf6e86ea3617f3b480b1a | https://github.com/EngoEngine/engo/blob/6f88a7379a25d81e976cf6e86ea3617f3b480b1a/common/animation.go#L47-L50 |
12,705 | EngoEngine/engo | common/animation.go | AddDefaultAnimation | func (ac *AnimationComponent) AddDefaultAnimation(action *Animation) {
ac.AddAnimation(action)
ac.def = action
} | go | func (ac *AnimationComponent) AddDefaultAnimation(action *Animation) {
ac.AddAnimation(action)
ac.def = action
} | [
"func",
"(",
"ac",
"*",
"AnimationComponent",
")",
"AddDefaultAnimation",
"(",
"action",
"*",
"Animation",
")",
"{",
"ac",
".",
"AddAnimation",
"(",
"action",
")",
"\n",
"ac",
".",
"def",
"=",
"action",
"\n",
"}"
]
| // AddDefaultAnimation adds an animation which is used when no other animation is playing. | [
"AddDefaultAnimation",
"adds",
"an",
"animation",
"which",
"is",
"used",
"when",
"no",
"other",
"animation",
"is",
"playing",
"."
]
| 6f88a7379a25d81e976cf6e86ea3617f3b480b1a | https://github.com/EngoEngine/engo/blob/6f88a7379a25d81e976cf6e86ea3617f3b480b1a/common/animation.go#L53-L56 |
12,706 | EngoEngine/engo | common/animation.go | AddAnimation | func (ac *AnimationComponent) AddAnimation(action *Animation) {
ac.Animations[action.Name] = action
} | go | func (ac *AnimationComponent) AddAnimation(action *Animation) {
ac.Animations[action.Name] = action
} | [
"func",
"(",
"ac",
"*",
"AnimationComponent",
")",
"AddAnimation",
"(",
"action",
"*",
"Animation",
")",
"{",
"ac",
".",
"Animations",
"[",
"action",
".",
"Name",
"]",
"=",
"action",
"\n",
"}"
]
| // AddAnimation registers an animation under its name, making it available
// through SelectAnimationByName. | [
"AddAnimation",
"registers",
"an",
"animation",
"under",
"its",
"name",
"making",
"it",
"available",
"through",
"SelectAnimationByName",
"."
]
| 6f88a7379a25d81e976cf6e86ea3617f3b480b1a | https://github.com/EngoEngine/engo/blob/6f88a7379a25d81e976cf6e86ea3617f3b480b1a/common/animation.go#L60-L62 |
12,707 | EngoEngine/engo | common/animation.go | AddAnimations | func (ac *AnimationComponent) AddAnimations(actions []*Animation) {
for _, action := range actions {
ac.AddAnimation(action)
}
} | go | func (ac *AnimationComponent) AddAnimations(actions []*Animation) {
for _, action := range actions {
ac.AddAnimation(action)
}
} | [
"func",
"(",
"ac",
"*",
"AnimationComponent",
")",
"AddAnimations",
"(",
"actions",
"[",
"]",
"*",
"Animation",
")",
"{",
"for",
"_",
",",
"action",
":=",
"range",
"actions",
"{",
"ac",
".",
"AddAnimation",
"(",
"action",
")",
"\n",
"}",
"\n",
"}"
]
| // AddAnimations registers all given animations. | [
"AddAnimations",
"registers",
"all",
"given",
"animations",
"."
]
| 6f88a7379a25d81e976cf6e86ea3617f3b480b1a | https://github.com/EngoEngine/engo/blob/6f88a7379a25d81e976cf6e86ea3617f3b480b1a/common/animation.go#L65-L69 |
12,708 | EngoEngine/engo | common/animation.go | Cell | func (ac *AnimationComponent) Cell() Drawable {
if len(ac.CurrentAnimation.Frames) == 0 {
log.Println("No frame data for this animation. Selecting zeroth drawable. If this is incorrect, add an action to the animation.")
return ac.Drawables[0]
}
idx := ac.CurrentAnimation.Frames[ac.index]
return ac.Drawables[idx]
} | go | func (ac *AnimationComponent) Cell() Drawable {
if len(ac.CurrentAnimation.Frames) == 0 {
log.Println("No frame data for this animation. Selecting zeroth drawable. If this is incorrect, add an action to the animation.")
return ac.Drawables[0]
}
idx := ac.CurrentAnimation.Frames[ac.index]
return ac.Drawables[idx]
} | [
"func",
"(",
"ac",
"*",
"AnimationComponent",
")",
"Cell",
"(",
")",
"Drawable",
"{",
"if",
"len",
"(",
"ac",
".",
"CurrentAnimation",
".",
"Frames",
")",
"==",
"0",
"{",
"log",
".",
"Println",
"(",
"\"",
"\"",
")",
"\n",
"return",
"ac",
".",
"Drawables",
"[",
"0",
"]",
"\n",
"}",
"\n",
"idx",
":=",
"ac",
".",
"CurrentAnimation",
".",
"Frames",
"[",
"ac",
".",
"index",
"]",
"\n\n",
"return",
"ac",
".",
"Drawables",
"[",
"idx",
"]",
"\n",
"}"
]
| // Cell returns the drawable for the current frame. | [
"Cell",
"returns",
"the",
"drawable",
"for",
"the",
"current",
"frame",
"."
]
| 6f88a7379a25d81e976cf6e86ea3617f3b480b1a | https://github.com/EngoEngine/engo/blob/6f88a7379a25d81e976cf6e86ea3617f3b480b1a/common/animation.go#L72-L80 |
12,709 | EngoEngine/engo | common/animation.go | NextFrame | func (ac *AnimationComponent) NextFrame() {
if len(ac.CurrentAnimation.Frames) == 0 {
log.Println("No frame data for this animation")
return
}
ac.index++
ac.change = 0
if ac.index >= len(ac.CurrentAnimation.Frames) {
ac.index = 0
if !ac.CurrentAnimation.Loop {
ac.CurrentAnimation = nil
return
}
}
} | go | func (ac *AnimationComponent) NextFrame() {
if len(ac.CurrentAnimation.Frames) == 0 {
log.Println("No frame data for this animation")
return
}
ac.index++
ac.change = 0
if ac.index >= len(ac.CurrentAnimation.Frames) {
ac.index = 0
if !ac.CurrentAnimation.Loop {
ac.CurrentAnimation = nil
return
}
}
} | [
"func",
"(",
"ac",
"*",
"AnimationComponent",
")",
"NextFrame",
"(",
")",
"{",
"if",
"len",
"(",
"ac",
".",
"CurrentAnimation",
".",
"Frames",
")",
"==",
"0",
"{",
"log",
".",
"Println",
"(",
"\"",
"\"",
")",
"\n",
"return",
"\n",
"}",
"\n\n",
"ac",
".",
"index",
"++",
"\n",
"ac",
".",
"change",
"=",
"0",
"\n",
"if",
"ac",
".",
"index",
">=",
"len",
"(",
"ac",
".",
"CurrentAnimation",
".",
"Frames",
")",
"{",
"ac",
".",
"index",
"=",
"0",
"\n\n",
"if",
"!",
"ac",
".",
"CurrentAnimation",
".",
"Loop",
"{",
"ac",
".",
"CurrentAnimation",
"=",
"nil",
"\n",
"return",
"\n",
"}",
"\n",
"}",
"\n",
"}"
]
| // NextFrame advances the current animation by one frame. | [
"NextFrame",
"advances",
"the",
"current",
"animation",
"by",
"one",
"frame",
"."
]
| 6f88a7379a25d81e976cf6e86ea3617f3b480b1a | https://github.com/EngoEngine/engo/blob/6f88a7379a25d81e976cf6e86ea3617f3b480b1a/common/animation.go#L83-L99 |
12,710 | EngoEngine/engo | common/animation.go | Add | func (a *AnimationSystem) Add(basic *ecs.BasicEntity, anim *AnimationComponent, render *RenderComponent) {
if a.entities == nil {
a.entities = make(map[uint64]animationEntity)
}
a.entities[basic.ID()] = animationEntity{anim, render}
} | go | func (a *AnimationSystem) Add(basic *ecs.BasicEntity, anim *AnimationComponent, render *RenderComponent) {
if a.entities == nil {
a.entities = make(map[uint64]animationEntity)
}
a.entities[basic.ID()] = animationEntity{anim, render}
} | [
"func",
"(",
"a",
"*",
"AnimationSystem",
")",
"Add",
"(",
"basic",
"*",
"ecs",
".",
"BasicEntity",
",",
"anim",
"*",
"AnimationComponent",
",",
"render",
"*",
"RenderComponent",
")",
"{",
"if",
"a",
".",
"entities",
"==",
"nil",
"{",
"a",
".",
"entities",
"=",
"make",
"(",
"map",
"[",
"uint64",
"]",
"animationEntity",
")",
"\n",
"}",
"\n",
"a",
".",
"entities",
"[",
"basic",
".",
"ID",
"(",
")",
"]",
"=",
"animationEntity",
"{",
"anim",
",",
"render",
"}",
"\n",
"}"
]
| // Add starts tracking the given entity. | [
"Add",
"starts",
"tracking",
"the",
"given",
"entity",
"."
]
| 6f88a7379a25d81e976cf6e86ea3617f3b480b1a | https://github.com/EngoEngine/engo/blob/6f88a7379a25d81e976cf6e86ea3617f3b480b1a/common/animation.go#L112-L117 |
12,711 | EngoEngine/engo | common/animation.go | AddByInterface | func (a *AnimationSystem) AddByInterface(i ecs.Identifier) {
o, _ := i.(Animationable)
a.Add(o.GetBasicEntity(), o.GetAnimationComponent(), o.GetRenderComponent())
} | go | func (a *AnimationSystem) AddByInterface(i ecs.Identifier) {
o, _ := i.(Animationable)
a.Add(o.GetBasicEntity(), o.GetAnimationComponent(), o.GetRenderComponent())
} | [
"func",
"(",
"a",
"*",
"AnimationSystem",
")",
"AddByInterface",
"(",
"i",
"ecs",
".",
"Identifier",
")",
"{",
"o",
",",
"_",
":=",
"i",
".",
"(",
"Animationable",
")",
"\n",
"a",
".",
"Add",
"(",
"o",
".",
"GetBasicEntity",
"(",
")",
",",
"o",
".",
"GetAnimationComponent",
"(",
")",
",",
"o",
".",
"GetRenderComponent",
"(",
")",
")",
"\n",
"}"
]
| // AddByInterface Allows an Entity to be added directly using the Animtionable interface. which every entity containing the BasicEntity,AnimationComponent,and RenderComponent anonymously, automatically satisfies. | [
"AddByInterface",
"Allows",
"an",
"Entity",
"to",
"be",
"added",
"directly",
"using",
"the",
"Animtionable",
"interface",
".",
"which",
"every",
"entity",
"containing",
"the",
"BasicEntity",
"AnimationComponent",
"and",
"RenderComponent",
"anonymously",
"automatically",
"satisfies",
"."
]
| 6f88a7379a25d81e976cf6e86ea3617f3b480b1a | https://github.com/EngoEngine/engo/blob/6f88a7379a25d81e976cf6e86ea3617f3b480b1a/common/animation.go#L120-L123 |
12,712 | EngoEngine/engo | common/animation.go | Remove | func (a *AnimationSystem) Remove(basic ecs.BasicEntity) {
if a.entities != nil {
delete(a.entities, basic.ID())
}
} | go | func (a *AnimationSystem) Remove(basic ecs.BasicEntity) {
if a.entities != nil {
delete(a.entities, basic.ID())
}
} | [
"func",
"(",
"a",
"*",
"AnimationSystem",
")",
"Remove",
"(",
"basic",
"ecs",
".",
"BasicEntity",
")",
"{",
"if",
"a",
".",
"entities",
"!=",
"nil",
"{",
"delete",
"(",
"a",
".",
"entities",
",",
"basic",
".",
"ID",
"(",
")",
")",
"\n",
"}",
"\n",
"}"
]
| // Remove stops tracking the given entity. | [
"Remove",
"stops",
"tracking",
"the",
"given",
"entity",
"."
]
| 6f88a7379a25d81e976cf6e86ea3617f3b480b1a | https://github.com/EngoEngine/engo/blob/6f88a7379a25d81e976cf6e86ea3617f3b480b1a/common/animation.go#L126-L130 |
12,713 | EngoEngine/engo | common/animation.go | Update | func (a *AnimationSystem) Update(dt float32) {
for _, e := range a.entities {
if e.AnimationComponent.CurrentAnimation == nil {
if e.AnimationComponent.def == nil {
continue
}
e.AnimationComponent.SelectAnimationByAction(e.AnimationComponent.def)
}
e.AnimationComponent.change += dt
if e.AnimationComponent.change >= e.AnimationComponent.Rate {
e.RenderComponent.Drawable = e.AnimationComponent.Cell()
e.AnimationComponent.NextFrame()
}
}
} | go | func (a *AnimationSystem) Update(dt float32) {
for _, e := range a.entities {
if e.AnimationComponent.CurrentAnimation == nil {
if e.AnimationComponent.def == nil {
continue
}
e.AnimationComponent.SelectAnimationByAction(e.AnimationComponent.def)
}
e.AnimationComponent.change += dt
if e.AnimationComponent.change >= e.AnimationComponent.Rate {
e.RenderComponent.Drawable = e.AnimationComponent.Cell()
e.AnimationComponent.NextFrame()
}
}
} | [
"func",
"(",
"a",
"*",
"AnimationSystem",
")",
"Update",
"(",
"dt",
"float32",
")",
"{",
"for",
"_",
",",
"e",
":=",
"range",
"a",
".",
"entities",
"{",
"if",
"e",
".",
"AnimationComponent",
".",
"CurrentAnimation",
"==",
"nil",
"{",
"if",
"e",
".",
"AnimationComponent",
".",
"def",
"==",
"nil",
"{",
"continue",
"\n",
"}",
"\n",
"e",
".",
"AnimationComponent",
".",
"SelectAnimationByAction",
"(",
"e",
".",
"AnimationComponent",
".",
"def",
")",
"\n",
"}",
"\n\n",
"e",
".",
"AnimationComponent",
".",
"change",
"+=",
"dt",
"\n",
"if",
"e",
".",
"AnimationComponent",
".",
"change",
">=",
"e",
".",
"AnimationComponent",
".",
"Rate",
"{",
"e",
".",
"RenderComponent",
".",
"Drawable",
"=",
"e",
".",
"AnimationComponent",
".",
"Cell",
"(",
")",
"\n",
"e",
".",
"AnimationComponent",
".",
"NextFrame",
"(",
")",
"\n",
"}",
"\n",
"}",
"\n",
"}"
]
| // Update advances the animations of all tracked entities. | [
"Update",
"advances",
"the",
"animations",
"of",
"all",
"tracked",
"entities",
"."
]
| 6f88a7379a25d81e976cf6e86ea3617f3b480b1a | https://github.com/EngoEngine/engo/blob/6f88a7379a25d81e976cf6e86ea3617f3b480b1a/common/animation.go#L133-L148 |
12,714 | EngoEngine/engo | engo_vulkan.go | SetTitle | func SetTitle(title string) {
if opts.HeadlessMode {
log.Println("Title set to:", title)
} else {
Window.SetTitle(title)
}
} | go | func SetTitle(title string) {
if opts.HeadlessMode {
log.Println("Title set to:", title)
} else {
Window.SetTitle(title)
}
} | [
"func",
"SetTitle",
"(",
"title",
"string",
")",
"{",
"if",
"opts",
".",
"HeadlessMode",
"{",
"log",
".",
"Println",
"(",
"\"",
"\"",
",",
"title",
")",
"\n",
"}",
"else",
"{",
"Window",
".",
"SetTitle",
"(",
"title",
")",
"\n",
"}",
"\n",
"}"
]
| // SetTitle sets the title of the window | [
"SetTitle",
"sets",
"the",
"title",
"of",
"the",
"window"
]
| 6f88a7379a25d81e976cf6e86ea3617f3b480b1a | https://github.com/EngoEngine/engo/blob/6f88a7379a25d81e976cf6e86ea3617f3b480b1a/engo_vulkan.go#L209-L215 |
12,715 | EngoEngine/engo | quadtree.go | NewQuadtree | func NewQuadtree(bounds AABB, usePool bool, maxObjects int) *Quadtree {
qt := &Quadtree{MaxObjects: maxObjects, usePool: usePool}
qt.root = qt.newNode(bounds, 0)
qt.MaxLevels = calcMaxLevel(aabbWidth(bounds), aabbHeight(bounds))
return qt
} | go | func NewQuadtree(bounds AABB, usePool bool, maxObjects int) *Quadtree {
qt := &Quadtree{MaxObjects: maxObjects, usePool: usePool}
qt.root = qt.newNode(bounds, 0)
qt.MaxLevels = calcMaxLevel(aabbWidth(bounds), aabbHeight(bounds))
return qt
} | [
"func",
"NewQuadtree",
"(",
"bounds",
"AABB",
",",
"usePool",
"bool",
",",
"maxObjects",
"int",
")",
"*",
"Quadtree",
"{",
"qt",
":=",
"&",
"Quadtree",
"{",
"MaxObjects",
":",
"maxObjects",
",",
"usePool",
":",
"usePool",
"}",
"\n",
"qt",
".",
"root",
"=",
"qt",
".",
"newNode",
"(",
"bounds",
",",
"0",
")",
"\n",
"qt",
".",
"MaxLevels",
"=",
"calcMaxLevel",
"(",
"aabbWidth",
"(",
"bounds",
")",
",",
"aabbHeight",
"(",
"bounds",
")",
")",
"\n",
"return",
"qt",
"\n",
"}"
]
| // NewQuadtree creates a new quadtree for the given bounds.
// When setting usePool to true, the internal values will be taken from a sync.Pool which reduces the allocation overhead.
// maxObjects tells the tree how many objects should be stored within a level before the quadtree cell is split. | [
"NewQuadtree",
"creates",
"a",
"new",
"quadtree",
"for",
"the",
"given",
"bounds",
".",
"When",
"setting",
"usePool",
"to",
"true",
"the",
"internal",
"values",
"will",
"be",
"taken",
"from",
"a",
"sync",
".",
"Pool",
"which",
"reduces",
"the",
"allocation",
"overhead",
".",
"maxObjects",
"tells",
"the",
"tree",
"how",
"many",
"objects",
"should",
"be",
"stored",
"within",
"a",
"level",
"before",
"the",
"quadtree",
"cell",
"is",
"split",
"."
]
| 6f88a7379a25d81e976cf6e86ea3617f3b480b1a | https://github.com/EngoEngine/engo/blob/6f88a7379a25d81e976cf6e86ea3617f3b480b1a/quadtree.go#L108-L113 |
12,716 | EngoEngine/engo | quadtree.go | Destroy | func (qt *Quadtree) Destroy() {
qt.freeQuadtreeNode(qt.root)
qt.root = nil
} | go | func (qt *Quadtree) Destroy() {
qt.freeQuadtreeNode(qt.root)
qt.root = nil
} | [
"func",
"(",
"qt",
"*",
"Quadtree",
")",
"Destroy",
"(",
")",
"{",
"qt",
".",
"freeQuadtreeNode",
"(",
"qt",
".",
"root",
")",
"\n",
"qt",
".",
"root",
"=",
"nil",
"\n",
"}"
]
| // Destroy frees the nodes if the Quadtree uses the node pool | [
"Destroy",
"frees",
"the",
"nodes",
"if",
"the",
"Quadtree",
"uses",
"the",
"node",
"pool"
]
| 6f88a7379a25d81e976cf6e86ea3617f3b480b1a | https://github.com/EngoEngine/engo/blob/6f88a7379a25d81e976cf6e86ea3617f3b480b1a/quadtree.go#L116-L119 |
12,717 | EngoEngine/engo | quadtree.go | split | func (qt *quadtreeNode) split() {
if qt.hasNodes {
return
}
qt.hasNodes = true
nextLevel := qt.Level + 1
subWidth := aabbWidth(qt.Bounds) / 2
subHeight := aabbHeight(qt.Bounds) / 2
x := qt.Bounds.Min.X
y := qt.Bounds.Min.Y
//top right node (0)
qt.Nodes[0] = qt.Tree.newNode(aabbRect(x+subWidth, y, subWidth, subHeight), nextLevel)
//top left node (1)
qt.Nodes[1] = qt.Tree.newNode(aabbRect(x, y, subWidth, subHeight), nextLevel)
//bottom left node (2)
qt.Nodes[2] = qt.Tree.newNode(aabbRect(x, y+subHeight, subWidth, subHeight), nextLevel)
//bottom right node (3)
qt.Nodes[3] = qt.Tree.newNode(aabbRect(x+subWidth, y+subHeight, subWidth, subHeight), nextLevel)
} | go | func (qt *quadtreeNode) split() {
if qt.hasNodes {
return
}
qt.hasNodes = true
nextLevel := qt.Level + 1
subWidth := aabbWidth(qt.Bounds) / 2
subHeight := aabbHeight(qt.Bounds) / 2
x := qt.Bounds.Min.X
y := qt.Bounds.Min.Y
//top right node (0)
qt.Nodes[0] = qt.Tree.newNode(aabbRect(x+subWidth, y, subWidth, subHeight), nextLevel)
//top left node (1)
qt.Nodes[1] = qt.Tree.newNode(aabbRect(x, y, subWidth, subHeight), nextLevel)
//bottom left node (2)
qt.Nodes[2] = qt.Tree.newNode(aabbRect(x, y+subHeight, subWidth, subHeight), nextLevel)
//bottom right node (3)
qt.Nodes[3] = qt.Tree.newNode(aabbRect(x+subWidth, y+subHeight, subWidth, subHeight), nextLevel)
} | [
"func",
"(",
"qt",
"*",
"quadtreeNode",
")",
"split",
"(",
")",
"{",
"if",
"qt",
".",
"hasNodes",
"{",
"return",
"\n",
"}",
"\n",
"qt",
".",
"hasNodes",
"=",
"true",
"\n\n",
"nextLevel",
":=",
"qt",
".",
"Level",
"+",
"1",
"\n",
"subWidth",
":=",
"aabbWidth",
"(",
"qt",
".",
"Bounds",
")",
"/",
"2",
"\n",
"subHeight",
":=",
"aabbHeight",
"(",
"qt",
".",
"Bounds",
")",
"/",
"2",
"\n",
"x",
":=",
"qt",
".",
"Bounds",
".",
"Min",
".",
"X",
"\n",
"y",
":=",
"qt",
".",
"Bounds",
".",
"Min",
".",
"Y",
"\n\n",
"//top right node (0)",
"qt",
".",
"Nodes",
"[",
"0",
"]",
"=",
"qt",
".",
"Tree",
".",
"newNode",
"(",
"aabbRect",
"(",
"x",
"+",
"subWidth",
",",
"y",
",",
"subWidth",
",",
"subHeight",
")",
",",
"nextLevel",
")",
"\n\n",
"//top left node (1)",
"qt",
".",
"Nodes",
"[",
"1",
"]",
"=",
"qt",
".",
"Tree",
".",
"newNode",
"(",
"aabbRect",
"(",
"x",
",",
"y",
",",
"subWidth",
",",
"subHeight",
")",
",",
"nextLevel",
")",
"\n\n",
"//bottom left node (2)",
"qt",
".",
"Nodes",
"[",
"2",
"]",
"=",
"qt",
".",
"Tree",
".",
"newNode",
"(",
"aabbRect",
"(",
"x",
",",
"y",
"+",
"subHeight",
",",
"subWidth",
",",
"subHeight",
")",
",",
"nextLevel",
")",
"\n\n",
"//bottom right node (3)",
"qt",
".",
"Nodes",
"[",
"3",
"]",
"=",
"qt",
".",
"Tree",
".",
"newNode",
"(",
"aabbRect",
"(",
"x",
"+",
"subWidth",
",",
"y",
"+",
"subHeight",
",",
"subWidth",
",",
"subHeight",
")",
",",
"nextLevel",
")",
"\n",
"}"
]
| // split - split the node into 4 subnodes | [
"split",
"-",
"split",
"the",
"node",
"into",
"4",
"subnodes"
]
| 6f88a7379a25d81e976cf6e86ea3617f3b480b1a | https://github.com/EngoEngine/engo/blob/6f88a7379a25d81e976cf6e86ea3617f3b480b1a/quadtree.go#L174-L197 |
12,718 | EngoEngine/engo | quadtree.go | Insert | func (qt *Quadtree) Insert(item AABBer) {
qt.Total++
pRect := item.AABB()
qt.root.Insert(qt.newQuadtreeNodeData(item, pRect))
} | go | func (qt *Quadtree) Insert(item AABBer) {
qt.Total++
pRect := item.AABB()
qt.root.Insert(qt.newQuadtreeNodeData(item, pRect))
} | [
"func",
"(",
"qt",
"*",
"Quadtree",
")",
"Insert",
"(",
"item",
"AABBer",
")",
"{",
"qt",
".",
"Total",
"++",
"\n",
"pRect",
":=",
"item",
".",
"AABB",
"(",
")",
"\n",
"qt",
".",
"root",
".",
"Insert",
"(",
"qt",
".",
"newQuadtreeNodeData",
"(",
"item",
",",
"pRect",
")",
")",
"\n",
"}"
]
| // Insert inserts the given item to the quadtree | [
"Insert",
"inserts",
"the",
"given",
"item",
"to",
"the",
"quadtree"
]
| 6f88a7379a25d81e976cf6e86ea3617f3b480b1a | https://github.com/EngoEngine/engo/blob/6f88a7379a25d81e976cf6e86ea3617f3b480b1a/quadtree.go#L247-L251 |
12,719 | EngoEngine/engo | quadtree.go | Remove | func (qt *Quadtree) Remove(item AABBer) {
bounds := item.AABB()
qt.root.Remove(item, bounds)
} | go | func (qt *Quadtree) Remove(item AABBer) {
bounds := item.AABB()
qt.root.Remove(item, bounds)
} | [
"func",
"(",
"qt",
"*",
"Quadtree",
")",
"Remove",
"(",
"item",
"AABBer",
")",
"{",
"bounds",
":=",
"item",
".",
"AABB",
"(",
")",
"\n",
"qt",
".",
"root",
".",
"Remove",
"(",
"item",
",",
"bounds",
")",
"\n",
"}"
]
| // Remove removes the given item from the quadtree | [
"Remove",
"removes",
"the",
"given",
"item",
"from",
"the",
"quadtree"
]
| 6f88a7379a25d81e976cf6e86ea3617f3b480b1a | https://github.com/EngoEngine/engo/blob/6f88a7379a25d81e976cf6e86ea3617f3b480b1a/quadtree.go#L307-L310 |
12,720 | EngoEngine/engo | quadtree.go | Retrieve | func (qt *quadtreeNode) Retrieve(pRect AABB) []AABBer {
index := qt.getIndex(pRect)
// Array with all detected objects
result := make([]AABBer, len(qt.Objects))
for i, o := range qt.Objects {
result[i] = o.Value
}
//if we have subnodes ...
if qt.hasNodes {
//if pRect fits into a subnode ..
if index != -1 {
result = append(result, qt.Nodes[index].Retrieve(pRect)...)
} else {
//if pRect does not fit into a subnode, check it against all subnodes
for i := 0; i < 4; i++ {
result = append(result, qt.Nodes[i].Retrieve(pRect)...)
}
}
}
return result
} | go | func (qt *quadtreeNode) Retrieve(pRect AABB) []AABBer {
index := qt.getIndex(pRect)
// Array with all detected objects
result := make([]AABBer, len(qt.Objects))
for i, o := range qt.Objects {
result[i] = o.Value
}
//if we have subnodes ...
if qt.hasNodes {
//if pRect fits into a subnode ..
if index != -1 {
result = append(result, qt.Nodes[index].Retrieve(pRect)...)
} else {
//if pRect does not fit into a subnode, check it against all subnodes
for i := 0; i < 4; i++ {
result = append(result, qt.Nodes[i].Retrieve(pRect)...)
}
}
}
return result
} | [
"func",
"(",
"qt",
"*",
"quadtreeNode",
")",
"Retrieve",
"(",
"pRect",
"AABB",
")",
"[",
"]",
"AABBer",
"{",
"index",
":=",
"qt",
".",
"getIndex",
"(",
"pRect",
")",
"\n\n",
"// Array with all detected objects",
"result",
":=",
"make",
"(",
"[",
"]",
"AABBer",
",",
"len",
"(",
"qt",
".",
"Objects",
")",
")",
"\n",
"for",
"i",
",",
"o",
":=",
"range",
"qt",
".",
"Objects",
"{",
"result",
"[",
"i",
"]",
"=",
"o",
".",
"Value",
"\n",
"}",
"\n\n",
"//if we have subnodes ...",
"if",
"qt",
".",
"hasNodes",
"{",
"//if pRect fits into a subnode ..",
"if",
"index",
"!=",
"-",
"1",
"{",
"result",
"=",
"append",
"(",
"result",
",",
"qt",
".",
"Nodes",
"[",
"index",
"]",
".",
"Retrieve",
"(",
"pRect",
")",
"...",
")",
"\n",
"}",
"else",
"{",
"//if pRect does not fit into a subnode, check it against all subnodes",
"for",
"i",
":=",
"0",
";",
"i",
"<",
"4",
";",
"i",
"++",
"{",
"result",
"=",
"append",
"(",
"result",
",",
"qt",
".",
"Nodes",
"[",
"i",
"]",
".",
"Retrieve",
"(",
"pRect",
")",
"...",
")",
"\n",
"}",
"\n",
"}",
"\n",
"}",
"\n\n",
"return",
"result",
"\n\n",
"}"
]
| // Retrieve returns all objects that could collide with the given bounding box | [
"Retrieve",
"returns",
"all",
"objects",
"that",
"could",
"collide",
"with",
"the",
"given",
"bounding",
"box"
]
| 6f88a7379a25d81e976cf6e86ea3617f3b480b1a | https://github.com/EngoEngine/engo/blob/6f88a7379a25d81e976cf6e86ea3617f3b480b1a/quadtree.go#L313-L337 |
12,721 | EngoEngine/engo | quadtree.go | Retrieve | func (qt *Quadtree) Retrieve(find AABB, filter func(aabb AABBer) bool) []AABBer {
var foundIntersections []AABBer
potentials := qt.root.Retrieve(find)
for _, p := range potentials {
if aabbOverlaps(find, p.AABB()) && (filter == nil || filter(p)) {
foundIntersections = append(foundIntersections, p)
}
}
return foundIntersections
} | go | func (qt *Quadtree) Retrieve(find AABB, filter func(aabb AABBer) bool) []AABBer {
var foundIntersections []AABBer
potentials := qt.root.Retrieve(find)
for _, p := range potentials {
if aabbOverlaps(find, p.AABB()) && (filter == nil || filter(p)) {
foundIntersections = append(foundIntersections, p)
}
}
return foundIntersections
} | [
"func",
"(",
"qt",
"*",
"Quadtree",
")",
"Retrieve",
"(",
"find",
"AABB",
",",
"filter",
"func",
"(",
"aabb",
"AABBer",
")",
"bool",
")",
"[",
"]",
"AABBer",
"{",
"var",
"foundIntersections",
"[",
"]",
"AABBer",
"\n\n",
"potentials",
":=",
"qt",
".",
"root",
".",
"Retrieve",
"(",
"find",
")",
"\n",
"for",
"_",
",",
"p",
":=",
"range",
"potentials",
"{",
"if",
"aabbOverlaps",
"(",
"find",
",",
"p",
".",
"AABB",
"(",
")",
")",
"&&",
"(",
"filter",
"==",
"nil",
"||",
"filter",
"(",
"p",
")",
")",
"{",
"foundIntersections",
"=",
"append",
"(",
"foundIntersections",
",",
"p",
")",
"\n",
"}",
"\n",
"}",
"\n\n",
"return",
"foundIntersections",
"\n",
"}"
]
| // Retrieve returns all objects that could collide with the given bounding box and passing the given filter function. | [
"Retrieve",
"returns",
"all",
"objects",
"that",
"could",
"collide",
"with",
"the",
"given",
"bounding",
"box",
"and",
"passing",
"the",
"given",
"filter",
"function",
"."
]
| 6f88a7379a25d81e976cf6e86ea3617f3b480b1a | https://github.com/EngoEngine/engo/blob/6f88a7379a25d81e976cf6e86ea3617f3b480b1a/quadtree.go#L340-L351 |
12,722 | EngoEngine/engo | quadtree.go | Clear | func (qt *Quadtree) Clear() {
bounds := qt.root.Bounds
qt.freeQuadtreeNode(qt.root)
qt.root = qt.newNode(bounds, 0)
qt.Total = 0
} | go | func (qt *Quadtree) Clear() {
bounds := qt.root.Bounds
qt.freeQuadtreeNode(qt.root)
qt.root = qt.newNode(bounds, 0)
qt.Total = 0
} | [
"func",
"(",
"qt",
"*",
"Quadtree",
")",
"Clear",
"(",
")",
"{",
"bounds",
":=",
"qt",
".",
"root",
".",
"Bounds",
"\n",
"qt",
".",
"freeQuadtreeNode",
"(",
"qt",
".",
"root",
")",
"\n",
"qt",
".",
"root",
"=",
"qt",
".",
"newNode",
"(",
"bounds",
",",
"0",
")",
"\n",
"qt",
".",
"Total",
"=",
"0",
"\n",
"}"
]
| //Clear removes all items from the quadtree | [
"Clear",
"removes",
"all",
"items",
"from",
"the",
"quadtree"
]
| 6f88a7379a25d81e976cf6e86ea3617f3b480b1a | https://github.com/EngoEngine/engo/blob/6f88a7379a25d81e976cf6e86ea3617f3b480b1a/quadtree.go#L354-L359 |
12,723 | EngoEngine/engo | common/fps.go | New | func (f *FPSSystem) New(w *ecs.World) {
if f.Display {
if err := engo.Files.LoadReaderData("gomonobold_fps.ttf", bytes.NewReader(gomonobold.TTF)); err != nil {
panic("unable to load gomonobold.ttf for the fps system! Error was: " + err.Error())
}
f.fnt = &Font{
URL: "gomonobold_fps.ttf",
FG: color.White,
BG: color.Black,
Size: 32,
}
if err := f.fnt.CreatePreloaded(); err != nil {
panic("unable to create gomonobold.ttf for the fps system! Error was: " + err.Error())
}
txt := Text{
Font: f.fnt,
Text: "Hello world!",
}
b := ecs.NewBasic()
f.entity.BasicEntity = &b
f.entity.RenderComponent = &RenderComponent{
Drawable: txt,
}
f.entity.RenderComponent.SetShader(HUDShader)
f.entity.RenderComponent.SetZIndex(1000)
f.entity.SpaceComponent = &SpaceComponent{}
for _, system := range w.Systems() {
switch sys := system.(type) {
case *RenderSystem:
sys.Add(f.entity.BasicEntity, f.entity.RenderComponent, f.entity.SpaceComponent)
}
}
}
} | go | func (f *FPSSystem) New(w *ecs.World) {
if f.Display {
if err := engo.Files.LoadReaderData("gomonobold_fps.ttf", bytes.NewReader(gomonobold.TTF)); err != nil {
panic("unable to load gomonobold.ttf for the fps system! Error was: " + err.Error())
}
f.fnt = &Font{
URL: "gomonobold_fps.ttf",
FG: color.White,
BG: color.Black,
Size: 32,
}
if err := f.fnt.CreatePreloaded(); err != nil {
panic("unable to create gomonobold.ttf for the fps system! Error was: " + err.Error())
}
txt := Text{
Font: f.fnt,
Text: "Hello world!",
}
b := ecs.NewBasic()
f.entity.BasicEntity = &b
f.entity.RenderComponent = &RenderComponent{
Drawable: txt,
}
f.entity.RenderComponent.SetShader(HUDShader)
f.entity.RenderComponent.SetZIndex(1000)
f.entity.SpaceComponent = &SpaceComponent{}
for _, system := range w.Systems() {
switch sys := system.(type) {
case *RenderSystem:
sys.Add(f.entity.BasicEntity, f.entity.RenderComponent, f.entity.SpaceComponent)
}
}
}
} | [
"func",
"(",
"f",
"*",
"FPSSystem",
")",
"New",
"(",
"w",
"*",
"ecs",
".",
"World",
")",
"{",
"if",
"f",
".",
"Display",
"{",
"if",
"err",
":=",
"engo",
".",
"Files",
".",
"LoadReaderData",
"(",
"\"",
"\"",
",",
"bytes",
".",
"NewReader",
"(",
"gomonobold",
".",
"TTF",
")",
")",
";",
"err",
"!=",
"nil",
"{",
"panic",
"(",
"\"",
"\"",
"+",
"err",
".",
"Error",
"(",
")",
")",
"\n",
"}",
"\n",
"f",
".",
"fnt",
"=",
"&",
"Font",
"{",
"URL",
":",
"\"",
"\"",
",",
"FG",
":",
"color",
".",
"White",
",",
"BG",
":",
"color",
".",
"Black",
",",
"Size",
":",
"32",
",",
"}",
"\n",
"if",
"err",
":=",
"f",
".",
"fnt",
".",
"CreatePreloaded",
"(",
")",
";",
"err",
"!=",
"nil",
"{",
"panic",
"(",
"\"",
"\"",
"+",
"err",
".",
"Error",
"(",
")",
")",
"\n",
"}",
"\n",
"txt",
":=",
"Text",
"{",
"Font",
":",
"f",
".",
"fnt",
",",
"Text",
":",
"\"",
"\"",
",",
"}",
"\n",
"b",
":=",
"ecs",
".",
"NewBasic",
"(",
")",
"\n",
"f",
".",
"entity",
".",
"BasicEntity",
"=",
"&",
"b",
"\n",
"f",
".",
"entity",
".",
"RenderComponent",
"=",
"&",
"RenderComponent",
"{",
"Drawable",
":",
"txt",
",",
"}",
"\n",
"f",
".",
"entity",
".",
"RenderComponent",
".",
"SetShader",
"(",
"HUDShader",
")",
"\n",
"f",
".",
"entity",
".",
"RenderComponent",
".",
"SetZIndex",
"(",
"1000",
")",
"\n",
"f",
".",
"entity",
".",
"SpaceComponent",
"=",
"&",
"SpaceComponent",
"{",
"}",
"\n",
"for",
"_",
",",
"system",
":=",
"range",
"w",
".",
"Systems",
"(",
")",
"{",
"switch",
"sys",
":=",
"system",
".",
"(",
"type",
")",
"{",
"case",
"*",
"RenderSystem",
":",
"sys",
".",
"Add",
"(",
"f",
".",
"entity",
".",
"BasicEntity",
",",
"f",
".",
"entity",
".",
"RenderComponent",
",",
"f",
".",
"entity",
".",
"SpaceComponent",
")",
"\n",
"}",
"\n",
"}",
"\n",
"}",
"\n",
"}"
]
| // New is called when FPSSystem is added to the world | [
"New",
"is",
"called",
"when",
"FPSSystem",
"is",
"added",
"to",
"the",
"world"
]
| 6f88a7379a25d81e976cf6e86ea3617f3b480b1a | https://github.com/EngoEngine/engo/blob/6f88a7379a25d81e976cf6e86ea3617f3b480b1a/common/fps.go#L29-L62 |
12,724 | EngoEngine/engo | common/fps.go | Update | func (f *FPSSystem) Update(dt float32) {
f.elapsed += dt
f.frames += 1
text := "FPS: " + strconv.FormatFloat(float64(f.frames/f.elapsed), 'G', 5, 32)
if f.elapsed >= 1 {
if f.Display {
f.entity.Drawable = Text{
Font: f.fnt,
Text: text,
}
}
if f.Terminal {
log.Println(text)
}
f.frames = 0
f.elapsed -= 1
}
} | go | func (f *FPSSystem) Update(dt float32) {
f.elapsed += dt
f.frames += 1
text := "FPS: " + strconv.FormatFloat(float64(f.frames/f.elapsed), 'G', 5, 32)
if f.elapsed >= 1 {
if f.Display {
f.entity.Drawable = Text{
Font: f.fnt,
Text: text,
}
}
if f.Terminal {
log.Println(text)
}
f.frames = 0
f.elapsed -= 1
}
} | [
"func",
"(",
"f",
"*",
"FPSSystem",
")",
"Update",
"(",
"dt",
"float32",
")",
"{",
"f",
".",
"elapsed",
"+=",
"dt",
"\n",
"f",
".",
"frames",
"+=",
"1",
"\n",
"text",
":=",
"\"",
"\"",
"+",
"strconv",
".",
"FormatFloat",
"(",
"float64",
"(",
"f",
".",
"frames",
"/",
"f",
".",
"elapsed",
")",
",",
"'G'",
",",
"5",
",",
"32",
")",
"\n",
"if",
"f",
".",
"elapsed",
">=",
"1",
"{",
"if",
"f",
".",
"Display",
"{",
"f",
".",
"entity",
".",
"Drawable",
"=",
"Text",
"{",
"Font",
":",
"f",
".",
"fnt",
",",
"Text",
":",
"text",
",",
"}",
"\n",
"}",
"\n",
"if",
"f",
".",
"Terminal",
"{",
"log",
".",
"Println",
"(",
"text",
")",
"\n",
"}",
"\n",
"f",
".",
"frames",
"=",
"0",
"\n",
"f",
".",
"elapsed",
"-=",
"1",
"\n",
"}",
"\n",
"}"
]
| // Update changes the dipslayed text and prints to the terminal every second
// to report the FPS | [
"Update",
"changes",
"the",
"dipslayed",
"text",
"and",
"prints",
"to",
"the",
"terminal",
"every",
"second",
"to",
"report",
"the",
"FPS"
]
| 6f88a7379a25d81e976cf6e86ea3617f3b480b1a | https://github.com/EngoEngine/engo/blob/6f88a7379a25d81e976cf6e86ea3617f3b480b1a/common/fps.go#L72-L89 |
12,725 | EngoEngine/engo | common/tmx_filetype.go | Load | func (t *tmxLoader) Load(url string, data io.Reader) error {
lvl, err := createLevelFromTmx(data, url)
if err != nil {
return err
}
t.levels[url] = TMXResource{Level: lvl, url: url}
return nil
} | go | func (t *tmxLoader) Load(url string, data io.Reader) error {
lvl, err := createLevelFromTmx(data, url)
if err != nil {
return err
}
t.levels[url] = TMXResource{Level: lvl, url: url}
return nil
} | [
"func",
"(",
"t",
"*",
"tmxLoader",
")",
"Load",
"(",
"url",
"string",
",",
"data",
"io",
".",
"Reader",
")",
"error",
"{",
"lvl",
",",
"err",
":=",
"createLevelFromTmx",
"(",
"data",
",",
"url",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n\n",
"t",
".",
"levels",
"[",
"url",
"]",
"=",
"TMXResource",
"{",
"Level",
":",
"lvl",
",",
"url",
":",
"url",
"}",
"\n",
"return",
"nil",
"\n",
"}"
]
| // Load will load the tmx file and any other image resources that are needed | [
"Load",
"will",
"load",
"the",
"tmx",
"file",
"and",
"any",
"other",
"image",
"resources",
"that",
"are",
"needed"
]
| 6f88a7379a25d81e976cf6e86ea3617f3b480b1a | https://github.com/EngoEngine/engo/blob/6f88a7379a25d81e976cf6e86ea3617f3b480b1a/common/tmx_filetype.go#L29-L37 |
12,726 | EngoEngine/engo | common/tmx_filetype.go | Unload | func (t *tmxLoader) Unload(url string) error {
delete(t.levels, url)
return nil
} | go | func (t *tmxLoader) Unload(url string) error {
delete(t.levels, url)
return nil
} | [
"func",
"(",
"t",
"*",
"tmxLoader",
")",
"Unload",
"(",
"url",
"string",
")",
"error",
"{",
"delete",
"(",
"t",
".",
"levels",
",",
"url",
")",
"\n",
"return",
"nil",
"\n",
"}"
]
| // Unload removes the preloaded level from the cache | [
"Unload",
"removes",
"the",
"preloaded",
"level",
"from",
"the",
"cache"
]
| 6f88a7379a25d81e976cf6e86ea3617f3b480b1a | https://github.com/EngoEngine/engo/blob/6f88a7379a25d81e976cf6e86ea3617f3b480b1a/common/tmx_filetype.go#L40-L43 |
12,727 | EngoEngine/engo | common/tmx_filetype.go | Resource | func (t *tmxLoader) Resource(url string) (engo.Resource, error) {
tmx, ok := t.levels[url]
if !ok {
return nil, fmt.Errorf("resource not loaded by `FileLoader`: %q", url)
}
return tmx, nil
} | go | func (t *tmxLoader) Resource(url string) (engo.Resource, error) {
tmx, ok := t.levels[url]
if !ok {
return nil, fmt.Errorf("resource not loaded by `FileLoader`: %q", url)
}
return tmx, nil
} | [
"func",
"(",
"t",
"*",
"tmxLoader",
")",
"Resource",
"(",
"url",
"string",
")",
"(",
"engo",
".",
"Resource",
",",
"error",
")",
"{",
"tmx",
",",
"ok",
":=",
"t",
".",
"levels",
"[",
"url",
"]",
"\n",
"if",
"!",
"ok",
"{",
"return",
"nil",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"url",
")",
"\n",
"}",
"\n\n",
"return",
"tmx",
",",
"nil",
"\n",
"}"
]
| // Resource retrieves and returns the preloaded level of type 'TMXResource' | [
"Resource",
"retrieves",
"and",
"returns",
"the",
"preloaded",
"level",
"of",
"type",
"TMXResource"
]
| 6f88a7379a25d81e976cf6e86ea3617f3b480b1a | https://github.com/EngoEngine/engo/blob/6f88a7379a25d81e976cf6e86ea3617f3b480b1a/common/tmx_filetype.go#L46-L53 |
12,728 | EngoEngine/engo | common/level.go | Bounds | func (l *Level) Bounds() engo.AABB {
switch l.Orientation {
case orth:
return engo.AABB{
Min: l.screenPoint(engo.Point{X: 0, Y: 0}),
Max: l.screenPoint(engo.Point{X: float32(l.width), Y: float32(l.height)}),
}
case iso:
xMin := l.screenPoint(engo.Point{X: 0, Y: float32(l.height)}).X + float32(l.TileWidth)/2
xMax := l.screenPoint(engo.Point{X: float32(l.width), Y: 0}).X + float32(l.TileWidth)/2
yMin := l.screenPoint(engo.Point{X: 0, Y: 0}).Y
yMax := l.screenPoint(engo.Point{X: float32(l.width), Y: float32(l.height)}).Y + float32(l.TileHeight)/2
return engo.AABB{
Min: engo.Point{X: xMin, Y: yMin},
Max: engo.Point{X: xMax, Y: yMax},
}
}
return engo.AABB{}
} | go | func (l *Level) Bounds() engo.AABB {
switch l.Orientation {
case orth:
return engo.AABB{
Min: l.screenPoint(engo.Point{X: 0, Y: 0}),
Max: l.screenPoint(engo.Point{X: float32(l.width), Y: float32(l.height)}),
}
case iso:
xMin := l.screenPoint(engo.Point{X: 0, Y: float32(l.height)}).X + float32(l.TileWidth)/2
xMax := l.screenPoint(engo.Point{X: float32(l.width), Y: 0}).X + float32(l.TileWidth)/2
yMin := l.screenPoint(engo.Point{X: 0, Y: 0}).Y
yMax := l.screenPoint(engo.Point{X: float32(l.width), Y: float32(l.height)}).Y + float32(l.TileHeight)/2
return engo.AABB{
Min: engo.Point{X: xMin, Y: yMin},
Max: engo.Point{X: xMax, Y: yMax},
}
}
return engo.AABB{}
} | [
"func",
"(",
"l",
"*",
"Level",
")",
"Bounds",
"(",
")",
"engo",
".",
"AABB",
"{",
"switch",
"l",
".",
"Orientation",
"{",
"case",
"orth",
":",
"return",
"engo",
".",
"AABB",
"{",
"Min",
":",
"l",
".",
"screenPoint",
"(",
"engo",
".",
"Point",
"{",
"X",
":",
"0",
",",
"Y",
":",
"0",
"}",
")",
",",
"Max",
":",
"l",
".",
"screenPoint",
"(",
"engo",
".",
"Point",
"{",
"X",
":",
"float32",
"(",
"l",
".",
"width",
")",
",",
"Y",
":",
"float32",
"(",
"l",
".",
"height",
")",
"}",
")",
",",
"}",
"\n",
"case",
"iso",
":",
"xMin",
":=",
"l",
".",
"screenPoint",
"(",
"engo",
".",
"Point",
"{",
"X",
":",
"0",
",",
"Y",
":",
"float32",
"(",
"l",
".",
"height",
")",
"}",
")",
".",
"X",
"+",
"float32",
"(",
"l",
".",
"TileWidth",
")",
"/",
"2",
"\n",
"xMax",
":=",
"l",
".",
"screenPoint",
"(",
"engo",
".",
"Point",
"{",
"X",
":",
"float32",
"(",
"l",
".",
"width",
")",
",",
"Y",
":",
"0",
"}",
")",
".",
"X",
"+",
"float32",
"(",
"l",
".",
"TileWidth",
")",
"/",
"2",
"\n",
"yMin",
":=",
"l",
".",
"screenPoint",
"(",
"engo",
".",
"Point",
"{",
"X",
":",
"0",
",",
"Y",
":",
"0",
"}",
")",
".",
"Y",
"\n",
"yMax",
":=",
"l",
".",
"screenPoint",
"(",
"engo",
".",
"Point",
"{",
"X",
":",
"float32",
"(",
"l",
".",
"width",
")",
",",
"Y",
":",
"float32",
"(",
"l",
".",
"height",
")",
"}",
")",
".",
"Y",
"+",
"float32",
"(",
"l",
".",
"TileHeight",
")",
"/",
"2",
"\n",
"return",
"engo",
".",
"AABB",
"{",
"Min",
":",
"engo",
".",
"Point",
"{",
"X",
":",
"xMin",
",",
"Y",
":",
"yMin",
"}",
",",
"Max",
":",
"engo",
".",
"Point",
"{",
"X",
":",
"xMax",
",",
"Y",
":",
"yMax",
"}",
",",
"}",
"\n",
"}",
"\n",
"return",
"engo",
".",
"AABB",
"{",
"}",
"\n",
"}"
]
| // Bounds returns the level boundaries as an engo.AABB object | [
"Bounds",
"returns",
"the",
"level",
"boundaries",
"as",
"an",
"engo",
".",
"AABB",
"object"
]
| 6f88a7379a25d81e976cf6e86ea3617f3b480b1a | https://github.com/EngoEngine/engo/blob/6f88a7379a25d81e976cf6e86ea3617f3b480b1a/common/level.go#L176-L194 |
12,729 | EngoEngine/engo | common/level.go | mapPoint | func (l *Level) mapPoint(screenPt engo.Point) engo.Point {
switch l.Orientation {
case orth:
screenPt.Multiply(engo.Point{X: 1 / float32(l.TileWidth), Y: 1 / float32(l.TileHeight)})
return screenPt
case iso:
return engo.Point{
X: (screenPt.X / float32(l.TileWidth)) + (screenPt.Y / float32(l.TileHeight)),
Y: (screenPt.Y / float32(l.TileHeight)) - (screenPt.X / float32(l.TileWidth)),
}
}
return engo.Point{X: 0, Y: 0}
} | go | func (l *Level) mapPoint(screenPt engo.Point) engo.Point {
switch l.Orientation {
case orth:
screenPt.Multiply(engo.Point{X: 1 / float32(l.TileWidth), Y: 1 / float32(l.TileHeight)})
return screenPt
case iso:
return engo.Point{
X: (screenPt.X / float32(l.TileWidth)) + (screenPt.Y / float32(l.TileHeight)),
Y: (screenPt.Y / float32(l.TileHeight)) - (screenPt.X / float32(l.TileWidth)),
}
}
return engo.Point{X: 0, Y: 0}
} | [
"func",
"(",
"l",
"*",
"Level",
")",
"mapPoint",
"(",
"screenPt",
"engo",
".",
"Point",
")",
"engo",
".",
"Point",
"{",
"switch",
"l",
".",
"Orientation",
"{",
"case",
"orth",
":",
"screenPt",
".",
"Multiply",
"(",
"engo",
".",
"Point",
"{",
"X",
":",
"1",
"/",
"float32",
"(",
"l",
".",
"TileWidth",
")",
",",
"Y",
":",
"1",
"/",
"float32",
"(",
"l",
".",
"TileHeight",
")",
"}",
")",
"\n",
"return",
"screenPt",
"\n",
"case",
"iso",
":",
"return",
"engo",
".",
"Point",
"{",
"X",
":",
"(",
"screenPt",
".",
"X",
"/",
"float32",
"(",
"l",
".",
"TileWidth",
")",
")",
"+",
"(",
"screenPt",
".",
"Y",
"/",
"float32",
"(",
"l",
".",
"TileHeight",
")",
")",
",",
"Y",
":",
"(",
"screenPt",
".",
"Y",
"/",
"float32",
"(",
"l",
".",
"TileHeight",
")",
")",
"-",
"(",
"screenPt",
".",
"X",
"/",
"float32",
"(",
"l",
".",
"TileWidth",
")",
")",
",",
"}",
"\n",
"}",
"\n",
"return",
"engo",
".",
"Point",
"{",
"X",
":",
"0",
",",
"Y",
":",
"0",
"}",
"\n",
"}"
]
| // mapPoint returns the map point of the passed in screen point | [
"mapPoint",
"returns",
"the",
"map",
"point",
"of",
"the",
"passed",
"in",
"screen",
"point"
]
| 6f88a7379a25d81e976cf6e86ea3617f3b480b1a | https://github.com/EngoEngine/engo/blob/6f88a7379a25d81e976cf6e86ea3617f3b480b1a/common/level.go#L197-L209 |
12,730 | EngoEngine/engo | common/level.go | screenPoint | func (l *Level) screenPoint(mapPt engo.Point) engo.Point {
switch l.Orientation {
case orth:
mapPt.Multiply(engo.Point{X: float32(l.TileWidth), Y: float32(l.TileHeight)})
return mapPt
case iso:
return engo.Point{
X: (mapPt.X - mapPt.Y) * float32(l.TileWidth) / 2,
Y: (mapPt.X + mapPt.Y) * float32(l.TileHeight) / 2,
}
}
return engo.Point{X: 0, Y: 0}
} | go | func (l *Level) screenPoint(mapPt engo.Point) engo.Point {
switch l.Orientation {
case orth:
mapPt.Multiply(engo.Point{X: float32(l.TileWidth), Y: float32(l.TileHeight)})
return mapPt
case iso:
return engo.Point{
X: (mapPt.X - mapPt.Y) * float32(l.TileWidth) / 2,
Y: (mapPt.X + mapPt.Y) * float32(l.TileHeight) / 2,
}
}
return engo.Point{X: 0, Y: 0}
} | [
"func",
"(",
"l",
"*",
"Level",
")",
"screenPoint",
"(",
"mapPt",
"engo",
".",
"Point",
")",
"engo",
".",
"Point",
"{",
"switch",
"l",
".",
"Orientation",
"{",
"case",
"orth",
":",
"mapPt",
".",
"Multiply",
"(",
"engo",
".",
"Point",
"{",
"X",
":",
"float32",
"(",
"l",
".",
"TileWidth",
")",
",",
"Y",
":",
"float32",
"(",
"l",
".",
"TileHeight",
")",
"}",
")",
"\n",
"return",
"mapPt",
"\n",
"case",
"iso",
":",
"return",
"engo",
".",
"Point",
"{",
"X",
":",
"(",
"mapPt",
".",
"X",
"-",
"mapPt",
".",
"Y",
")",
"*",
"float32",
"(",
"l",
".",
"TileWidth",
")",
"/",
"2",
",",
"Y",
":",
"(",
"mapPt",
".",
"X",
"+",
"mapPt",
".",
"Y",
")",
"*",
"float32",
"(",
"l",
".",
"TileHeight",
")",
"/",
"2",
",",
"}",
"\n",
"}",
"\n",
"return",
"engo",
".",
"Point",
"{",
"X",
":",
"0",
",",
"Y",
":",
"0",
"}",
"\n",
"}"
]
| // screenPoint returns the screen point of the passed in map point | [
"screenPoint",
"returns",
"the",
"screen",
"point",
"of",
"the",
"passed",
"in",
"map",
"point"
]
| 6f88a7379a25d81e976cf6e86ea3617f3b480b1a | https://github.com/EngoEngine/engo/blob/6f88a7379a25d81e976cf6e86ea3617f3b480b1a/common/level.go#L212-L224 |
12,731 | EngoEngine/engo | common/level.go | View | func (t *Tile) View() (float32, float32, float32, float32) {
return t.Image.View()
} | go | func (t *Tile) View() (float32, float32, float32, float32) {
return t.Image.View()
} | [
"func",
"(",
"t",
"*",
"Tile",
")",
"View",
"(",
")",
"(",
"float32",
",",
"float32",
",",
"float32",
",",
"float32",
")",
"{",
"return",
"t",
".",
"Image",
".",
"View",
"(",
")",
"\n",
"}"
]
| // View returns the tile's viewport's min and max X & Y | [
"View",
"returns",
"the",
"tile",
"s",
"viewport",
"s",
"min",
"and",
"max",
"X",
"&",
"Y"
]
| 6f88a7379a25d81e976cf6e86ea3617f3b480b1a | https://github.com/EngoEngine/engo/blob/6f88a7379a25d81e976cf6e86ea3617f3b480b1a/common/level.go#L273-L275 |
12,732 | EngoEngine/engo | common/font_filetype.go | Load | func (i *fontLoader) Load(url string, data io.Reader) error {
ttfBytes, err := ioutil.ReadAll(data)
if err != nil {
return err
}
ttf, err := freetype.ParseFont(ttfBytes)
if err != nil {
return err
}
i.fonts[url] = FontResource{Font: ttf, url: url}
return nil
} | go | func (i *fontLoader) Load(url string, data io.Reader) error {
ttfBytes, err := ioutil.ReadAll(data)
if err != nil {
return err
}
ttf, err := freetype.ParseFont(ttfBytes)
if err != nil {
return err
}
i.fonts[url] = FontResource{Font: ttf, url: url}
return nil
} | [
"func",
"(",
"i",
"*",
"fontLoader",
")",
"Load",
"(",
"url",
"string",
",",
"data",
"io",
".",
"Reader",
")",
"error",
"{",
"ttfBytes",
",",
"err",
":=",
"ioutil",
".",
"ReadAll",
"(",
"data",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n\n",
"ttf",
",",
"err",
":=",
"freetype",
".",
"ParseFont",
"(",
"ttfBytes",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n\n",
"i",
".",
"fonts",
"[",
"url",
"]",
"=",
"FontResource",
"{",
"Font",
":",
"ttf",
",",
"url",
":",
"url",
"}",
"\n",
"return",
"nil",
"\n",
"}"
]
| // Load processes the data stream and parses it as a freetype font | [
"Load",
"processes",
"the",
"data",
"stream",
"and",
"parses",
"it",
"as",
"a",
"freetype",
"font"
]
| 6f88a7379a25d81e976cf6e86ea3617f3b480b1a | https://github.com/EngoEngine/engo/blob/6f88a7379a25d81e976cf6e86ea3617f3b480b1a/common/font_filetype.go#L31-L44 |
12,733 | EngoEngine/engo | common/font_filetype.go | Unload | func (i *fontLoader) Unload(url string) error {
delete(i.fonts, url)
return nil
} | go | func (i *fontLoader) Unload(url string) error {
delete(i.fonts, url)
return nil
} | [
"func",
"(",
"i",
"*",
"fontLoader",
")",
"Unload",
"(",
"url",
"string",
")",
"error",
"{",
"delete",
"(",
"i",
".",
"fonts",
",",
"url",
")",
"\n",
"return",
"nil",
"\n",
"}"
]
| // Load removes the preloaded font from the cache | [
"Load",
"removes",
"the",
"preloaded",
"font",
"from",
"the",
"cache"
]
| 6f88a7379a25d81e976cf6e86ea3617f3b480b1a | https://github.com/EngoEngine/engo/blob/6f88a7379a25d81e976cf6e86ea3617f3b480b1a/common/font_filetype.go#L47-L50 |
12,734 | EngoEngine/engo | common/font_filetype.go | Resource | func (i *fontLoader) Resource(url string) (engo.Resource, error) {
texture, ok := i.fonts[url]
if !ok {
return nil, fmt.Errorf("resource not loaded by `FileLoader`: %q", url)
}
return texture, nil
} | go | func (i *fontLoader) Resource(url string) (engo.Resource, error) {
texture, ok := i.fonts[url]
if !ok {
return nil, fmt.Errorf("resource not loaded by `FileLoader`: %q", url)
}
return texture, nil
} | [
"func",
"(",
"i",
"*",
"fontLoader",
")",
"Resource",
"(",
"url",
"string",
")",
"(",
"engo",
".",
"Resource",
",",
"error",
")",
"{",
"texture",
",",
"ok",
":=",
"i",
".",
"fonts",
"[",
"url",
"]",
"\n",
"if",
"!",
"ok",
"{",
"return",
"nil",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"url",
")",
"\n",
"}",
"\n\n",
"return",
"texture",
",",
"nil",
"\n",
"}"
]
| // Resource retrieves the preloaded font, passed as a `FontResource` | [
"Resource",
"retrieves",
"the",
"preloaded",
"font",
"passed",
"as",
"a",
"FontResource"
]
| 6f88a7379a25d81e976cf6e86ea3617f3b480b1a | https://github.com/EngoEngine/engo/blob/6f88a7379a25d81e976cf6e86ea3617f3b480b1a/common/font_filetype.go#L53-L60 |
12,735 | EngoEngine/engo | common/audio_player.go | Close | func (p *Player) Close() error {
runtime.SetFinalizer(p, nil)
p.isPlaying = false
select {
case p.closeCh <- struct{}{}:
<-p.closedCh
return nil
case <-p.readLoopEndedCh:
return fmt.Errorf("audio: the player is already closed")
}
} | go | func (p *Player) Close() error {
runtime.SetFinalizer(p, nil)
p.isPlaying = false
select {
case p.closeCh <- struct{}{}:
<-p.closedCh
return nil
case <-p.readLoopEndedCh:
return fmt.Errorf("audio: the player is already closed")
}
} | [
"func",
"(",
"p",
"*",
"Player",
")",
"Close",
"(",
")",
"error",
"{",
"runtime",
".",
"SetFinalizer",
"(",
"p",
",",
"nil",
")",
"\n",
"p",
".",
"isPlaying",
"=",
"false",
"\n\n",
"select",
"{",
"case",
"p",
".",
"closeCh",
"<-",
"struct",
"{",
"}",
"{",
"}",
":",
"<-",
"p",
".",
"closedCh",
"\n",
"return",
"nil",
"\n",
"case",
"<-",
"p",
".",
"readLoopEndedCh",
":",
"return",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"}"
]
| // Close removes the player from the audio system's players, which are currently playing players.
// it then finalizes and frees the data from the player. Do not use a player after it has been
// closed | [
"Close",
"removes",
"the",
"player",
"from",
"the",
"audio",
"system",
"s",
"players",
"which",
"are",
"currently",
"playing",
"players",
".",
"it",
"then",
"finalizes",
"and",
"frees",
"the",
"data",
"from",
"the",
"player",
".",
"Do",
"not",
"use",
"a",
"player",
"after",
"it",
"has",
"been",
"closed"
]
| 6f88a7379a25d81e976cf6e86ea3617f3b480b1a | https://github.com/EngoEngine/engo/blob/6f88a7379a25d81e976cf6e86ea3617f3b480b1a/common/audio_player.go#L91-L102 |
12,736 | EngoEngine/engo | common/audio_player.go | Seek | func (p *Player) Seek(offset time.Duration) error {
o := int64(offset) * bytesPerSample * channelNum * int64(p.sampleRate) / int64(time.Second)
o &= mask
select {
case p.seekCh <- seekArgs{o, io.SeekStart}:
return <-p.seekedCh
case <-p.readLoopEndedCh:
return fmt.Errorf("audio: the player is already closed")
}
} | go | func (p *Player) Seek(offset time.Duration) error {
o := int64(offset) * bytesPerSample * channelNum * int64(p.sampleRate) / int64(time.Second)
o &= mask
select {
case p.seekCh <- seekArgs{o, io.SeekStart}:
return <-p.seekedCh
case <-p.readLoopEndedCh:
return fmt.Errorf("audio: the player is already closed")
}
} | [
"func",
"(",
"p",
"*",
"Player",
")",
"Seek",
"(",
"offset",
"time",
".",
"Duration",
")",
"error",
"{",
"o",
":=",
"int64",
"(",
"offset",
")",
"*",
"bytesPerSample",
"*",
"channelNum",
"*",
"int64",
"(",
"p",
".",
"sampleRate",
")",
"/",
"int64",
"(",
"time",
".",
"Second",
")",
"\n",
"o",
"&=",
"mask",
"\n",
"select",
"{",
"case",
"p",
".",
"seekCh",
"<-",
"seekArgs",
"{",
"o",
",",
"io",
".",
"SeekStart",
"}",
":",
"return",
"<-",
"p",
".",
"seekedCh",
"\n",
"case",
"<-",
"p",
".",
"readLoopEndedCh",
":",
"return",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"}"
]
| // Seek seeks the position with the given offset.
//
// Seek returns error when seeking the source stream returns error. | [
"Seek",
"seeks",
"the",
"position",
"with",
"the",
"given",
"offset",
".",
"Seek",
"returns",
"error",
"when",
"seeking",
"the",
"source",
"stream",
"returns",
"error",
"."
]
| 6f88a7379a25d81e976cf6e86ea3617f3b480b1a | https://github.com/EngoEngine/engo/blob/6f88a7379a25d81e976cf6e86ea3617f3b480b1a/common/audio_player.go#L253-L262 |
12,737 | EngoEngine/engo | common/audio_player.go | Current | func (p *Player) Current() time.Duration {
sample := int64(0)
p.sync(func() {
sample = p.pos / bytesPerSample / channelNum
})
return time.Duration(sample) * time.Second / time.Duration(p.sampleRate)
} | go | func (p *Player) Current() time.Duration {
sample := int64(0)
p.sync(func() {
sample = p.pos / bytesPerSample / channelNum
})
return time.Duration(sample) * time.Second / time.Duration(p.sampleRate)
} | [
"func",
"(",
"p",
"*",
"Player",
")",
"Current",
"(",
")",
"time",
".",
"Duration",
"{",
"sample",
":=",
"int64",
"(",
"0",
")",
"\n",
"p",
".",
"sync",
"(",
"func",
"(",
")",
"{",
"sample",
"=",
"p",
".",
"pos",
"/",
"bytesPerSample",
"/",
"channelNum",
"\n",
"}",
")",
"\n",
"return",
"time",
".",
"Duration",
"(",
"sample",
")",
"*",
"time",
".",
"Second",
"/",
"time",
".",
"Duration",
"(",
"p",
".",
"sampleRate",
")",
"\n",
"}"
]
| // Current returns the current position. | [
"Current",
"returns",
"the",
"current",
"position",
"."
]
| 6f88a7379a25d81e976cf6e86ea3617f3b480b1a | https://github.com/EngoEngine/engo/blob/6f88a7379a25d81e976cf6e86ea3617f3b480b1a/common/audio_player.go#L270-L276 |
12,738 | EngoEngine/engo | common/audio_player.go | GetVolume | func (p *Player) GetVolume() float64 {
v := 0.0
p.sync(func() {
v = p.volume
})
return v
} | go | func (p *Player) GetVolume() float64 {
v := 0.0
p.sync(func() {
v = p.volume
})
return v
} | [
"func",
"(",
"p",
"*",
"Player",
")",
"GetVolume",
"(",
")",
"float64",
"{",
"v",
":=",
"0.0",
"\n",
"p",
".",
"sync",
"(",
"func",
"(",
")",
"{",
"v",
"=",
"p",
".",
"volume",
"\n",
"}",
")",
"\n",
"return",
"v",
"\n",
"}"
]
| // GetVolume gets the Player's volume | [
"GetVolume",
"gets",
"the",
"Player",
"s",
"volume"
]
| 6f88a7379a25d81e976cf6e86ea3617f3b480b1a | https://github.com/EngoEngine/engo/blob/6f88a7379a25d81e976cf6e86ea3617f3b480b1a/common/audio_player.go#L279-L285 |
12,739 | EngoEngine/engo | common/audio_player.go | SetVolume | func (p *Player) SetVolume(volume float64) {
// The condition must be true when volume is NaN.
if volume < 0 || volume > 1 {
log.Println("Volume can only be set between zero and one. Volume was not set.")
return
}
p.sync(func() {
p.volume = volume * masterVolume
})
} | go | func (p *Player) SetVolume(volume float64) {
// The condition must be true when volume is NaN.
if volume < 0 || volume > 1 {
log.Println("Volume can only be set between zero and one. Volume was not set.")
return
}
p.sync(func() {
p.volume = volume * masterVolume
})
} | [
"func",
"(",
"p",
"*",
"Player",
")",
"SetVolume",
"(",
"volume",
"float64",
")",
"{",
"// The condition must be true when volume is NaN.",
"if",
"volume",
"<",
"0",
"||",
"volume",
">",
"1",
"{",
"log",
".",
"Println",
"(",
"\"",
"\"",
")",
"\n",
"return",
"\n",
"}",
"\n\n",
"p",
".",
"sync",
"(",
"func",
"(",
")",
"{",
"p",
".",
"volume",
"=",
"volume",
"*",
"masterVolume",
"\n",
"}",
")",
"\n",
"}"
]
| // SetVolume sets the Player's volume
// volume can only be set from 0 to 1 | [
"SetVolume",
"sets",
"the",
"Player",
"s",
"volume",
"volume",
"can",
"only",
"be",
"set",
"from",
"0",
"to",
"1"
]
| 6f88a7379a25d81e976cf6e86ea3617f3b480b1a | https://github.com/EngoEngine/engo/blob/6f88a7379a25d81e976cf6e86ea3617f3b480b1a/common/audio_player.go#L289-L299 |
12,740 | EngoEngine/engo | math/imath/math.go | Nextafter | func Nextafter(x, y int) (r int) {
return engoimath.Nextafter(x, y)
} | go | func Nextafter(x, y int) (r int) {
return engoimath.Nextafter(x, y)
} | [
"func",
"Nextafter",
"(",
"x",
",",
"y",
"int",
")",
"(",
"r",
"int",
")",
"{",
"return",
"engoimath",
".",
"Nextafter",
"(",
"x",
",",
"y",
")",
"\n",
"}"
]
| // Nextafter returns the next representable int value after x towards y. | [
"Nextafter",
"returns",
"the",
"next",
"representable",
"int",
"value",
"after",
"x",
"towards",
"y",
"."
]
| 6f88a7379a25d81e976cf6e86ea3617f3b480b1a | https://github.com/EngoEngine/engo/blob/6f88a7379a25d81e976cf6e86ea3617f3b480b1a/math/imath/math.go#L85-L87 |
12,741 | EngoEngine/engo | message.go | Dispatch | func (mm *MessageManager) Dispatch(message Message) {
mm.RLock()
mm.clearRemovedHandlers()
handlers := make([]MessageHandler, len(mm.listeners[message.Type()]))
pairs := mm.listeners[message.Type()]
for i := range pairs {
handlers[i] = pairs[i].MessageHandler
}
mm.RUnlock()
for _, handler := range handlers {
handler(message)
}
} | go | func (mm *MessageManager) Dispatch(message Message) {
mm.RLock()
mm.clearRemovedHandlers()
handlers := make([]MessageHandler, len(mm.listeners[message.Type()]))
pairs := mm.listeners[message.Type()]
for i := range pairs {
handlers[i] = pairs[i].MessageHandler
}
mm.RUnlock()
for _, handler := range handlers {
handler(message)
}
} | [
"func",
"(",
"mm",
"*",
"MessageManager",
")",
"Dispatch",
"(",
"message",
"Message",
")",
"{",
"mm",
".",
"RLock",
"(",
")",
"\n",
"mm",
".",
"clearRemovedHandlers",
"(",
")",
"\n",
"handlers",
":=",
"make",
"(",
"[",
"]",
"MessageHandler",
",",
"len",
"(",
"mm",
".",
"listeners",
"[",
"message",
".",
"Type",
"(",
")",
"]",
")",
")",
"\n",
"pairs",
":=",
"mm",
".",
"listeners",
"[",
"message",
".",
"Type",
"(",
")",
"]",
"\n",
"for",
"i",
":=",
"range",
"pairs",
"{",
"handlers",
"[",
"i",
"]",
"=",
"pairs",
"[",
"i",
"]",
".",
"MessageHandler",
"\n",
"}",
"\n",
"mm",
".",
"RUnlock",
"(",
")",
"\n\n",
"for",
"_",
",",
"handler",
":=",
"range",
"handlers",
"{",
"handler",
"(",
"message",
")",
"\n",
"}",
"\n\n",
"}"
]
| // Dispatch sends a message to all subscribed handlers of the message's type
// To prevent any data races, be aware that these listeners occur as callbacks and can be
// executed at any time. If variables are altered in the handler, utilize channels, locks,
// semaphores, or any other method necessary to ensure the memory is not altered by multiple
// functions simultaneously. | [
"Dispatch",
"sends",
"a",
"message",
"to",
"all",
"subscribed",
"handlers",
"of",
"the",
"message",
"s",
"type",
"To",
"prevent",
"any",
"data",
"races",
"be",
"aware",
"that",
"these",
"listeners",
"occur",
"as",
"callbacks",
"and",
"can",
"be",
"executed",
"at",
"any",
"time",
".",
"If",
"variables",
"are",
"altered",
"in",
"the",
"handler",
"utilize",
"channels",
"locks",
"semaphores",
"or",
"any",
"other",
"method",
"necessary",
"to",
"ensure",
"the",
"memory",
"is",
"not",
"altered",
"by",
"multiple",
"functions",
"simultaneously",
"."
]
| 6f88a7379a25d81e976cf6e86ea3617f3b480b1a | https://github.com/EngoEngine/engo/blob/6f88a7379a25d81e976cf6e86ea3617f3b480b1a/message.go#L49-L63 |
12,742 | EngoEngine/engo | message.go | Listen | func (mm *MessageManager) Listen(messageType string, handler MessageHandler) MessageHandlerId {
mm.Lock()
defer mm.Unlock()
if mm.listeners == nil {
mm.listeners = make(map[string][]HandlerIDPair)
}
handlerID := getNewHandlerID()
newHandlerIDPair := HandlerIDPair{MessageHandlerId: handlerID, MessageHandler: handler}
mm.listeners[messageType] = append(mm.listeners[messageType], newHandlerIDPair)
return handlerID
} | go | func (mm *MessageManager) Listen(messageType string, handler MessageHandler) MessageHandlerId {
mm.Lock()
defer mm.Unlock()
if mm.listeners == nil {
mm.listeners = make(map[string][]HandlerIDPair)
}
handlerID := getNewHandlerID()
newHandlerIDPair := HandlerIDPair{MessageHandlerId: handlerID, MessageHandler: handler}
mm.listeners[messageType] = append(mm.listeners[messageType], newHandlerIDPair)
return handlerID
} | [
"func",
"(",
"mm",
"*",
"MessageManager",
")",
"Listen",
"(",
"messageType",
"string",
",",
"handler",
"MessageHandler",
")",
"MessageHandlerId",
"{",
"mm",
".",
"Lock",
"(",
")",
"\n",
"defer",
"mm",
".",
"Unlock",
"(",
")",
"\n",
"if",
"mm",
".",
"listeners",
"==",
"nil",
"{",
"mm",
".",
"listeners",
"=",
"make",
"(",
"map",
"[",
"string",
"]",
"[",
"]",
"HandlerIDPair",
")",
"\n",
"}",
"\n",
"handlerID",
":=",
"getNewHandlerID",
"(",
")",
"\n",
"newHandlerIDPair",
":=",
"HandlerIDPair",
"{",
"MessageHandlerId",
":",
"handlerID",
",",
"MessageHandler",
":",
"handler",
"}",
"\n",
"mm",
".",
"listeners",
"[",
"messageType",
"]",
"=",
"append",
"(",
"mm",
".",
"listeners",
"[",
"messageType",
"]",
",",
"newHandlerIDPair",
")",
"\n",
"return",
"handlerID",
"\n",
"}"
]
| // Listen subscribes to the specified message type and calls the specified handler when fired | [
"Listen",
"subscribes",
"to",
"the",
"specified",
"message",
"type",
"and",
"calls",
"the",
"specified",
"handler",
"when",
"fired"
]
| 6f88a7379a25d81e976cf6e86ea3617f3b480b1a | https://github.com/EngoEngine/engo/blob/6f88a7379a25d81e976cf6e86ea3617f3b480b1a/message.go#L66-L76 |
12,743 | EngoEngine/engo | message.go | StopListen | func (mm *MessageManager) StopListen(messageType string, handlerID MessageHandlerId) {
if mm.handlersToRemove == nil {
mm.handlersToRemove = make(map[string][]MessageHandlerId)
}
mm.handlersToRemove[messageType] = append(mm.handlersToRemove[messageType], handlerID)
} | go | func (mm *MessageManager) StopListen(messageType string, handlerID MessageHandlerId) {
if mm.handlersToRemove == nil {
mm.handlersToRemove = make(map[string][]MessageHandlerId)
}
mm.handlersToRemove[messageType] = append(mm.handlersToRemove[messageType], handlerID)
} | [
"func",
"(",
"mm",
"*",
"MessageManager",
")",
"StopListen",
"(",
"messageType",
"string",
",",
"handlerID",
"MessageHandlerId",
")",
"{",
"if",
"mm",
".",
"handlersToRemove",
"==",
"nil",
"{",
"mm",
".",
"handlersToRemove",
"=",
"make",
"(",
"map",
"[",
"string",
"]",
"[",
"]",
"MessageHandlerId",
")",
"\n",
"}",
"\n",
"mm",
".",
"handlersToRemove",
"[",
"messageType",
"]",
"=",
"append",
"(",
"mm",
".",
"handlersToRemove",
"[",
"messageType",
"]",
",",
"handlerID",
")",
"\n",
"}"
]
| // StopListen removes a previously added handler from the listener queue | [
"StopListen",
"removes",
"a",
"previously",
"added",
"handler",
"from",
"the",
"listener",
"queue"
]
| 6f88a7379a25d81e976cf6e86ea3617f3b480b1a | https://github.com/EngoEngine/engo/blob/6f88a7379a25d81e976cf6e86ea3617f3b480b1a/message.go#L88-L93 |
12,744 | EngoEngine/engo | message.go | removeHandler | func (mm *MessageManager) removeHandler(messageType string, handlerID MessageHandlerId) {
indexOfHandler := -1
for i, activeHandler := range mm.listeners[messageType] {
if activeHandler.MessageHandlerId == handlerID {
indexOfHandler = i
break
}
}
// A handler might have already been removed during a previous Dispatch(), no action necessary
if indexOfHandler == -1 {
return
}
mm.listeners[messageType] = append(mm.listeners[messageType][:indexOfHandler], mm.listeners[messageType][indexOfHandler+1:]...)
} | go | func (mm *MessageManager) removeHandler(messageType string, handlerID MessageHandlerId) {
indexOfHandler := -1
for i, activeHandler := range mm.listeners[messageType] {
if activeHandler.MessageHandlerId == handlerID {
indexOfHandler = i
break
}
}
// A handler might have already been removed during a previous Dispatch(), no action necessary
if indexOfHandler == -1 {
return
}
mm.listeners[messageType] = append(mm.listeners[messageType][:indexOfHandler], mm.listeners[messageType][indexOfHandler+1:]...)
} | [
"func",
"(",
"mm",
"*",
"MessageManager",
")",
"removeHandler",
"(",
"messageType",
"string",
",",
"handlerID",
"MessageHandlerId",
")",
"{",
"indexOfHandler",
":=",
"-",
"1",
"\n",
"for",
"i",
",",
"activeHandler",
":=",
"range",
"mm",
".",
"listeners",
"[",
"messageType",
"]",
"{",
"if",
"activeHandler",
".",
"MessageHandlerId",
"==",
"handlerID",
"{",
"indexOfHandler",
"=",
"i",
"\n",
"break",
"\n",
"}",
"\n",
"}",
"\n",
"// A handler might have already been removed during a previous Dispatch(), no action necessary",
"if",
"indexOfHandler",
"==",
"-",
"1",
"{",
"return",
"\n",
"}",
"\n",
"mm",
".",
"listeners",
"[",
"messageType",
"]",
"=",
"append",
"(",
"mm",
".",
"listeners",
"[",
"messageType",
"]",
"[",
":",
"indexOfHandler",
"]",
",",
"mm",
".",
"listeners",
"[",
"messageType",
"]",
"[",
"indexOfHandler",
"+",
"1",
":",
"]",
"...",
")",
"\n",
"}"
]
| // Removes a single handler from the handler queue, called during cleanup of all handlers scheduled for removal | [
"Removes",
"a",
"single",
"handler",
"from",
"the",
"handler",
"queue",
"called",
"during",
"cleanup",
"of",
"all",
"handlers",
"scheduled",
"for",
"removal"
]
| 6f88a7379a25d81e976cf6e86ea3617f3b480b1a | https://github.com/EngoEngine/engo/blob/6f88a7379a25d81e976cf6e86ea3617f3b480b1a/message.go#L106-L119 |
12,745 | EngoEngine/engo | scene.go | SetScene | func SetScene(s Scene, forceNewWorld bool) {
// Break down currentScene
if currentScene != nil {
if hider, ok := currentScene.(Hider); ok {
hider.Hide()
}
}
// Register Scene if needed
sceneMutex.RLock()
wrapper, registered := scenes[s.Type()]
sceneMutex.RUnlock()
if !registered {
RegisterScene(s)
sceneMutex.RLock()
wrapper = scenes[s.Type()]
sceneMutex.RUnlock()
}
// Initialize new Scene / World if needed
var doSetup bool
if wrapper.update == nil || forceNewWorld {
t := reflect.Indirect(reflect.ValueOf(currentUpdater)).Type()
v := reflect.New(t)
wrapper.update = v.Interface().(Updater)
wrapper.mailbox = &MessageManager{}
doSetup = true
}
// Do the switch
currentScene = s
currentUpdater = wrapper.update
Mailbox = wrapper.mailbox
// doSetup is true whenever we're (re)initializing the Scene
if doSetup {
s.Preload()
wrapper.mailbox.listeners = make(map[string][]HandlerIDPair)
s.Setup(wrapper.update)
} else {
if shower, ok := currentScene.(Shower); ok {
shower.Show()
}
}
} | go | func SetScene(s Scene, forceNewWorld bool) {
// Break down currentScene
if currentScene != nil {
if hider, ok := currentScene.(Hider); ok {
hider.Hide()
}
}
// Register Scene if needed
sceneMutex.RLock()
wrapper, registered := scenes[s.Type()]
sceneMutex.RUnlock()
if !registered {
RegisterScene(s)
sceneMutex.RLock()
wrapper = scenes[s.Type()]
sceneMutex.RUnlock()
}
// Initialize new Scene / World if needed
var doSetup bool
if wrapper.update == nil || forceNewWorld {
t := reflect.Indirect(reflect.ValueOf(currentUpdater)).Type()
v := reflect.New(t)
wrapper.update = v.Interface().(Updater)
wrapper.mailbox = &MessageManager{}
doSetup = true
}
// Do the switch
currentScene = s
currentUpdater = wrapper.update
Mailbox = wrapper.mailbox
// doSetup is true whenever we're (re)initializing the Scene
if doSetup {
s.Preload()
wrapper.mailbox.listeners = make(map[string][]HandlerIDPair)
s.Setup(wrapper.update)
} else {
if shower, ok := currentScene.(Shower); ok {
shower.Show()
}
}
} | [
"func",
"SetScene",
"(",
"s",
"Scene",
",",
"forceNewWorld",
"bool",
")",
"{",
"// Break down currentScene",
"if",
"currentScene",
"!=",
"nil",
"{",
"if",
"hider",
",",
"ok",
":=",
"currentScene",
".",
"(",
"Hider",
")",
";",
"ok",
"{",
"hider",
".",
"Hide",
"(",
")",
"\n",
"}",
"\n",
"}",
"\n\n",
"// Register Scene if needed",
"sceneMutex",
".",
"RLock",
"(",
")",
"\n",
"wrapper",
",",
"registered",
":=",
"scenes",
"[",
"s",
".",
"Type",
"(",
")",
"]",
"\n",
"sceneMutex",
".",
"RUnlock",
"(",
")",
"\n\n",
"if",
"!",
"registered",
"{",
"RegisterScene",
"(",
"s",
")",
"\n\n",
"sceneMutex",
".",
"RLock",
"(",
")",
"\n",
"wrapper",
"=",
"scenes",
"[",
"s",
".",
"Type",
"(",
")",
"]",
"\n",
"sceneMutex",
".",
"RUnlock",
"(",
")",
"\n",
"}",
"\n\n",
"// Initialize new Scene / World if needed",
"var",
"doSetup",
"bool",
"\n\n",
"if",
"wrapper",
".",
"update",
"==",
"nil",
"||",
"forceNewWorld",
"{",
"t",
":=",
"reflect",
".",
"Indirect",
"(",
"reflect",
".",
"ValueOf",
"(",
"currentUpdater",
")",
")",
".",
"Type",
"(",
")",
"\n",
"v",
":=",
"reflect",
".",
"New",
"(",
"t",
")",
"\n",
"wrapper",
".",
"update",
"=",
"v",
".",
"Interface",
"(",
")",
".",
"(",
"Updater",
")",
"\n",
"wrapper",
".",
"mailbox",
"=",
"&",
"MessageManager",
"{",
"}",
"\n\n",
"doSetup",
"=",
"true",
"\n",
"}",
"\n\n",
"// Do the switch",
"currentScene",
"=",
"s",
"\n",
"currentUpdater",
"=",
"wrapper",
".",
"update",
"\n",
"Mailbox",
"=",
"wrapper",
".",
"mailbox",
"\n\n",
"// doSetup is true whenever we're (re)initializing the Scene",
"if",
"doSetup",
"{",
"s",
".",
"Preload",
"(",
")",
"\n\n",
"wrapper",
".",
"mailbox",
".",
"listeners",
"=",
"make",
"(",
"map",
"[",
"string",
"]",
"[",
"]",
"HandlerIDPair",
")",
"\n\n",
"s",
".",
"Setup",
"(",
"wrapper",
".",
"update",
")",
"\n",
"}",
"else",
"{",
"if",
"shower",
",",
"ok",
":=",
"currentScene",
".",
"(",
"Shower",
")",
";",
"ok",
"{",
"shower",
".",
"Show",
"(",
")",
"\n",
"}",
"\n",
"}",
"\n",
"}"
]
| // SetScene sets the currentScene to the given Scene, and
// optionally forcing to create a new ecs.World that goes with it. | [
"SetScene",
"sets",
"the",
"currentScene",
"to",
"the",
"given",
"Scene",
"and",
"optionally",
"forcing",
"to",
"create",
"a",
"new",
"ecs",
".",
"World",
"that",
"goes",
"with",
"it",
"."
]
| 6f88a7379a25d81e976cf6e86ea3617f3b480b1a | https://github.com/EngoEngine/engo/blob/6f88a7379a25d81e976cf6e86ea3617f3b480b1a/scene.go#L68-L118 |
12,746 | EngoEngine/engo | scene.go | RegisterScene | func RegisterScene(s Scene) {
sceneMutex.RLock()
_, ok := scenes[s.Type()]
sceneMutex.RUnlock()
if !ok {
sceneMutex.Lock()
scenes[s.Type()] = &sceneWrapper{scene: s}
sceneMutex.Unlock()
}
} | go | func RegisterScene(s Scene) {
sceneMutex.RLock()
_, ok := scenes[s.Type()]
sceneMutex.RUnlock()
if !ok {
sceneMutex.Lock()
scenes[s.Type()] = &sceneWrapper{scene: s}
sceneMutex.Unlock()
}
} | [
"func",
"RegisterScene",
"(",
"s",
"Scene",
")",
"{",
"sceneMutex",
".",
"RLock",
"(",
")",
"\n",
"_",
",",
"ok",
":=",
"scenes",
"[",
"s",
".",
"Type",
"(",
")",
"]",
"\n",
"sceneMutex",
".",
"RUnlock",
"(",
")",
"\n",
"if",
"!",
"ok",
"{",
"sceneMutex",
".",
"Lock",
"(",
")",
"\n",
"scenes",
"[",
"s",
".",
"Type",
"(",
")",
"]",
"=",
"&",
"sceneWrapper",
"{",
"scene",
":",
"s",
"}",
"\n",
"sceneMutex",
".",
"Unlock",
"(",
")",
"\n",
"}",
"\n",
"}"
]
| // RegisterScene registers the `Scene`, so it can later be used by `SetSceneByName` | [
"RegisterScene",
"registers",
"the",
"Scene",
"so",
"it",
"can",
"later",
"be",
"used",
"by",
"SetSceneByName"
]
| 6f88a7379a25d81e976cf6e86ea3617f3b480b1a | https://github.com/EngoEngine/engo/blob/6f88a7379a25d81e976cf6e86ea3617f3b480b1a/scene.go#L121-L130 |
12,747 | EngoEngine/engo | keys.go | NewKeyManager | func NewKeyManager() *KeyManager {
return &KeyManager{
dirtmap: make(map[Key]Key),
mapper: make(map[Key]KeyState),
}
} | go | func NewKeyManager() *KeyManager {
return &KeyManager{
dirtmap: make(map[Key]Key),
mapper: make(map[Key]KeyState),
}
} | [
"func",
"NewKeyManager",
"(",
")",
"*",
"KeyManager",
"{",
"return",
"&",
"KeyManager",
"{",
"dirtmap",
":",
"make",
"(",
"map",
"[",
"Key",
"]",
"Key",
")",
",",
"mapper",
":",
"make",
"(",
"map",
"[",
"Key",
"]",
"KeyState",
")",
",",
"}",
"\n",
"}"
]
| // NewKeyManager creates a new KeyManager. | [
"NewKeyManager",
"creates",
"a",
"new",
"KeyManager",
"."
]
| 6f88a7379a25d81e976cf6e86ea3617f3b480b1a | https://github.com/EngoEngine/engo/blob/6f88a7379a25d81e976cf6e86ea3617f3b480b1a/keys.go#L19-L24 |
12,748 | EngoEngine/engo | keys.go | Set | func (km *KeyManager) Set(k Key, state bool) {
km.mutex.Lock()
ks := km.mapper[k]
ks.set(state)
km.mapper[k] = ks
km.dirtmap[k] = k
km.mutex.Unlock()
} | go | func (km *KeyManager) Set(k Key, state bool) {
km.mutex.Lock()
ks := km.mapper[k]
ks.set(state)
km.mapper[k] = ks
km.dirtmap[k] = k
km.mutex.Unlock()
} | [
"func",
"(",
"km",
"*",
"KeyManager",
")",
"Set",
"(",
"k",
"Key",
",",
"state",
"bool",
")",
"{",
"km",
".",
"mutex",
".",
"Lock",
"(",
")",
"\n\n",
"ks",
":=",
"km",
".",
"mapper",
"[",
"k",
"]",
"\n",
"ks",
".",
"set",
"(",
"state",
")",
"\n",
"km",
".",
"mapper",
"[",
"k",
"]",
"=",
"ks",
"\n",
"km",
".",
"dirtmap",
"[",
"k",
"]",
"=",
"k",
"\n\n",
"km",
".",
"mutex",
".",
"Unlock",
"(",
")",
"\n",
"}"
]
| // Set is used for updating whether or not a key is held down, or not held down. | [
"Set",
"is",
"used",
"for",
"updating",
"whether",
"or",
"not",
"a",
"key",
"is",
"held",
"down",
"or",
"not",
"held",
"down",
"."
]
| 6f88a7379a25d81e976cf6e86ea3617f3b480b1a | https://github.com/EngoEngine/engo/blob/6f88a7379a25d81e976cf6e86ea3617f3b480b1a/keys.go#L34-L43 |
12,749 | EngoEngine/engo | keys.go | Get | func (km *KeyManager) Get(k Key) KeyState {
km.mutex.RLock()
ks := km.mapper[k]
km.mutex.RUnlock()
return ks
} | go | func (km *KeyManager) Get(k Key) KeyState {
km.mutex.RLock()
ks := km.mapper[k]
km.mutex.RUnlock()
return ks
} | [
"func",
"(",
"km",
"*",
"KeyManager",
")",
"Get",
"(",
"k",
"Key",
")",
"KeyState",
"{",
"km",
".",
"mutex",
".",
"RLock",
"(",
")",
"\n",
"ks",
":=",
"km",
".",
"mapper",
"[",
"k",
"]",
"\n",
"km",
".",
"mutex",
".",
"RUnlock",
"(",
")",
"\n\n",
"return",
"ks",
"\n",
"}"
]
| // Get retrieves a keys state. | [
"Get",
"retrieves",
"a",
"keys",
"state",
"."
]
| 6f88a7379a25d81e976cf6e86ea3617f3b480b1a | https://github.com/EngoEngine/engo/blob/6f88a7379a25d81e976cf6e86ea3617f3b480b1a/keys.go#L46-L52 |
12,750 | EngoEngine/engo | keys.go | State | func (key *KeyState) State() int {
if key.lastState {
if key.currentState {
return KeyStateDown
}
return KeyStateJustUp
}
if key.currentState {
return KeyStateJustDown
}
return KeyStateUp
} | go | func (key *KeyState) State() int {
if key.lastState {
if key.currentState {
return KeyStateDown
}
return KeyStateJustUp
}
if key.currentState {
return KeyStateJustDown
}
return KeyStateUp
} | [
"func",
"(",
"key",
"*",
"KeyState",
")",
"State",
"(",
")",
"int",
"{",
"if",
"key",
".",
"lastState",
"{",
"if",
"key",
".",
"currentState",
"{",
"return",
"KeyStateDown",
"\n",
"}",
"\n",
"return",
"KeyStateJustUp",
"\n",
"}",
"\n",
"if",
"key",
".",
"currentState",
"{",
"return",
"KeyStateJustDown",
"\n",
"}",
"\n",
"return",
"KeyStateUp",
"\n",
"}"
]
| // State returns the raw state of a key. | [
"State",
"returns",
"the",
"raw",
"state",
"of",
"a",
"key",
"."
]
| 6f88a7379a25d81e976cf6e86ea3617f3b480b1a | https://github.com/EngoEngine/engo/blob/6f88a7379a25d81e976cf6e86ea3617f3b480b1a/keys.go#L81-L92 |
12,751 | EngoEngine/engo | button.go | Down | func (b Button) Down() bool {
for _, trigger := range b.Triggers {
v := Input.keys.Get(trigger).Down()
if v {
return v
}
}
return false
} | go | func (b Button) Down() bool {
for _, trigger := range b.Triggers {
v := Input.keys.Get(trigger).Down()
if v {
return v
}
}
return false
} | [
"func",
"(",
"b",
"Button",
")",
"Down",
"(",
")",
"bool",
"{",
"for",
"_",
",",
"trigger",
":=",
"range",
"b",
".",
"Triggers",
"{",
"v",
":=",
"Input",
".",
"keys",
".",
"Get",
"(",
"trigger",
")",
".",
"Down",
"(",
")",
"\n",
"if",
"v",
"{",
"return",
"v",
"\n",
"}",
"\n",
"}",
"\n\n",
"return",
"false",
"\n",
"}"
]
| // Down checks whether the current input is being held down. | [
"Down",
"checks",
"whether",
"the",
"current",
"input",
"is",
"being",
"held",
"down",
"."
]
| 6f88a7379a25d81e976cf6e86ea3617f3b480b1a | https://github.com/EngoEngine/engo/blob/6f88a7379a25d81e976cf6e86ea3617f3b480b1a/button.go#L34-L43 |
12,752 | EngoEngine/engo | engo.go | Run | func Run(o RunOptions, defaultScene Scene) {
// Setting defaults
if o.FPSLimit == 0 {
o.FPSLimit = 60
}
if o.MSAA < 0 {
panic("MSAA has to be greater or equal to 0")
}
if o.MSAA == 0 {
o.MSAA = 1
}
if len(o.AssetsRoot) == 0 {
o.AssetsRoot = "assets"
}
if o.Update == nil {
o.Update = &ecs.World{}
}
if o.GlobalScale.X <= 0 || o.GlobalScale.Y <= 0 {
o.GlobalScale = Point{X: 1, Y: 1}
}
opts = o
// Create input
Input = NewInputManager()
if opts.StandardInputs {
log.Println("Using standard inputs")
Input.RegisterButton("jump", KeySpace)
Input.RegisterButton("action", KeyEnter)
Input.RegisterAxis(DefaultHorizontalAxis, AxisKeyPair{KeyA, KeyD}, AxisKeyPair{KeyArrowLeft, KeyArrowRight})
Input.RegisterAxis(DefaultVerticalAxis, AxisKeyPair{KeyW, KeyS}, AxisKeyPair{KeyArrowUp, KeyArrowDown})
Input.RegisterAxis(DefaultMouseXAxis, NewAxisMouse(AxisMouseHori))
Input.RegisterAxis(DefaultMouseYAxis, NewAxisMouse(AxisMouseVert))
}
Files.SetRoot(opts.AssetsRoot)
currentUpdater = opts.Update
// And run the game
if opts.HeadlessMode {
if opts.Width == 0 {
opts.Width = headlessWidth
}
if opts.Height == 0 {
opts.Height = headlessHeight
}
windowWidth = float32(opts.Width)
windowHeight = float32(opts.Height)
gameWidth = float32(opts.Width)
gameHeight = float32(opts.Height)
canvasWidth = float32(opts.Width)
canvasHeight = float32(opts.Height)
if !opts.NoRun {
runHeadless(defaultScene)
} else {
SetScene(defaultScene, true)
}
} else {
CreateWindow(opts.Title, opts.Width, opts.Height, opts.Fullscreen, opts.MSAA)
defer DestroyWindow()
if !opts.NoRun {
runLoop(defaultScene, false)
}
}
} | go | func Run(o RunOptions, defaultScene Scene) {
// Setting defaults
if o.FPSLimit == 0 {
o.FPSLimit = 60
}
if o.MSAA < 0 {
panic("MSAA has to be greater or equal to 0")
}
if o.MSAA == 0 {
o.MSAA = 1
}
if len(o.AssetsRoot) == 0 {
o.AssetsRoot = "assets"
}
if o.Update == nil {
o.Update = &ecs.World{}
}
if o.GlobalScale.X <= 0 || o.GlobalScale.Y <= 0 {
o.GlobalScale = Point{X: 1, Y: 1}
}
opts = o
// Create input
Input = NewInputManager()
if opts.StandardInputs {
log.Println("Using standard inputs")
Input.RegisterButton("jump", KeySpace)
Input.RegisterButton("action", KeyEnter)
Input.RegisterAxis(DefaultHorizontalAxis, AxisKeyPair{KeyA, KeyD}, AxisKeyPair{KeyArrowLeft, KeyArrowRight})
Input.RegisterAxis(DefaultVerticalAxis, AxisKeyPair{KeyW, KeyS}, AxisKeyPair{KeyArrowUp, KeyArrowDown})
Input.RegisterAxis(DefaultMouseXAxis, NewAxisMouse(AxisMouseHori))
Input.RegisterAxis(DefaultMouseYAxis, NewAxisMouse(AxisMouseVert))
}
Files.SetRoot(opts.AssetsRoot)
currentUpdater = opts.Update
// And run the game
if opts.HeadlessMode {
if opts.Width == 0 {
opts.Width = headlessWidth
}
if opts.Height == 0 {
opts.Height = headlessHeight
}
windowWidth = float32(opts.Width)
windowHeight = float32(opts.Height)
gameWidth = float32(opts.Width)
gameHeight = float32(opts.Height)
canvasWidth = float32(opts.Width)
canvasHeight = float32(opts.Height)
if !opts.NoRun {
runHeadless(defaultScene)
} else {
SetScene(defaultScene, true)
}
} else {
CreateWindow(opts.Title, opts.Width, opts.Height, opts.Fullscreen, opts.MSAA)
defer DestroyWindow()
if !opts.NoRun {
runLoop(defaultScene, false)
}
}
} | [
"func",
"Run",
"(",
"o",
"RunOptions",
",",
"defaultScene",
"Scene",
")",
"{",
"// Setting defaults",
"if",
"o",
".",
"FPSLimit",
"==",
"0",
"{",
"o",
".",
"FPSLimit",
"=",
"60",
"\n",
"}",
"\n\n",
"if",
"o",
".",
"MSAA",
"<",
"0",
"{",
"panic",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"if",
"o",
".",
"MSAA",
"==",
"0",
"{",
"o",
".",
"MSAA",
"=",
"1",
"\n",
"}",
"\n\n",
"if",
"len",
"(",
"o",
".",
"AssetsRoot",
")",
"==",
"0",
"{",
"o",
".",
"AssetsRoot",
"=",
"\"",
"\"",
"\n",
"}",
"\n\n",
"if",
"o",
".",
"Update",
"==",
"nil",
"{",
"o",
".",
"Update",
"=",
"&",
"ecs",
".",
"World",
"{",
"}",
"\n",
"}",
"\n\n",
"if",
"o",
".",
"GlobalScale",
".",
"X",
"<=",
"0",
"||",
"o",
".",
"GlobalScale",
".",
"Y",
"<=",
"0",
"{",
"o",
".",
"GlobalScale",
"=",
"Point",
"{",
"X",
":",
"1",
",",
"Y",
":",
"1",
"}",
"\n",
"}",
"\n\n",
"opts",
"=",
"o",
"\n\n",
"// Create input",
"Input",
"=",
"NewInputManager",
"(",
")",
"\n",
"if",
"opts",
".",
"StandardInputs",
"{",
"log",
".",
"Println",
"(",
"\"",
"\"",
")",
"\n\n",
"Input",
".",
"RegisterButton",
"(",
"\"",
"\"",
",",
"KeySpace",
")",
"\n",
"Input",
".",
"RegisterButton",
"(",
"\"",
"\"",
",",
"KeyEnter",
")",
"\n\n",
"Input",
".",
"RegisterAxis",
"(",
"DefaultHorizontalAxis",
",",
"AxisKeyPair",
"{",
"KeyA",
",",
"KeyD",
"}",
",",
"AxisKeyPair",
"{",
"KeyArrowLeft",
",",
"KeyArrowRight",
"}",
")",
"\n",
"Input",
".",
"RegisterAxis",
"(",
"DefaultVerticalAxis",
",",
"AxisKeyPair",
"{",
"KeyW",
",",
"KeyS",
"}",
",",
"AxisKeyPair",
"{",
"KeyArrowUp",
",",
"KeyArrowDown",
"}",
")",
"\n\n",
"Input",
".",
"RegisterAxis",
"(",
"DefaultMouseXAxis",
",",
"NewAxisMouse",
"(",
"AxisMouseHori",
")",
")",
"\n",
"Input",
".",
"RegisterAxis",
"(",
"DefaultMouseYAxis",
",",
"NewAxisMouse",
"(",
"AxisMouseVert",
")",
")",
"\n",
"}",
"\n\n",
"Files",
".",
"SetRoot",
"(",
"opts",
".",
"AssetsRoot",
")",
"\n",
"currentUpdater",
"=",
"opts",
".",
"Update",
"\n\n",
"// And run the game",
"if",
"opts",
".",
"HeadlessMode",
"{",
"if",
"opts",
".",
"Width",
"==",
"0",
"{",
"opts",
".",
"Width",
"=",
"headlessWidth",
"\n",
"}",
"\n",
"if",
"opts",
".",
"Height",
"==",
"0",
"{",
"opts",
".",
"Height",
"=",
"headlessHeight",
"\n",
"}",
"\n",
"windowWidth",
"=",
"float32",
"(",
"opts",
".",
"Width",
")",
"\n",
"windowHeight",
"=",
"float32",
"(",
"opts",
".",
"Height",
")",
"\n",
"gameWidth",
"=",
"float32",
"(",
"opts",
".",
"Width",
")",
"\n",
"gameHeight",
"=",
"float32",
"(",
"opts",
".",
"Height",
")",
"\n",
"canvasWidth",
"=",
"float32",
"(",
"opts",
".",
"Width",
")",
"\n",
"canvasHeight",
"=",
"float32",
"(",
"opts",
".",
"Height",
")",
"\n\n",
"if",
"!",
"opts",
".",
"NoRun",
"{",
"runHeadless",
"(",
"defaultScene",
")",
"\n",
"}",
"else",
"{",
"SetScene",
"(",
"defaultScene",
",",
"true",
")",
"\n",
"}",
"\n",
"}",
"else",
"{",
"CreateWindow",
"(",
"opts",
".",
"Title",
",",
"opts",
".",
"Width",
",",
"opts",
".",
"Height",
",",
"opts",
".",
"Fullscreen",
",",
"opts",
".",
"MSAA",
")",
"\n",
"defer",
"DestroyWindow",
"(",
")",
"\n\n",
"if",
"!",
"opts",
".",
"NoRun",
"{",
"runLoop",
"(",
"defaultScene",
",",
"false",
")",
"\n",
"}",
"\n",
"}",
"\n",
"}"
]
| // Run is called to create a window, initialize everything, and start the main loop. Once this function returns,
// the game window has been closed already. You can supply a lot of options within `RunOptions`, and your starting
// `Scene` should be defined in `defaultScene`. | [
"Run",
"is",
"called",
"to",
"create",
"a",
"window",
"initialize",
"everything",
"and",
"start",
"the",
"main",
"loop",
".",
"Once",
"this",
"function",
"returns",
"the",
"game",
"window",
"has",
"been",
"closed",
"already",
".",
"You",
"can",
"supply",
"a",
"lot",
"of",
"options",
"within",
"RunOptions",
"and",
"your",
"starting",
"Scene",
"should",
"be",
"defined",
"in",
"defaultScene",
"."
]
| 6f88a7379a25d81e976cf6e86ea3617f3b480b1a | https://github.com/EngoEngine/engo/blob/6f88a7379a25d81e976cf6e86ea3617f3b480b1a/engo.go#L158-L232 |
12,753 | EngoEngine/engo | engo.go | SetFPSLimit | func SetFPSLimit(limit int) error {
if limit <= 0 {
return fmt.Errorf("FPS Limit out of bounds. Requires > 0")
}
opts.FPSLimit = limit
resetLoopTicker <- true
return nil
} | go | func SetFPSLimit(limit int) error {
if limit <= 0 {
return fmt.Errorf("FPS Limit out of bounds. Requires > 0")
}
opts.FPSLimit = limit
resetLoopTicker <- true
return nil
} | [
"func",
"SetFPSLimit",
"(",
"limit",
"int",
")",
"error",
"{",
"if",
"limit",
"<=",
"0",
"{",
"return",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"opts",
".",
"FPSLimit",
"=",
"limit",
"\n",
"resetLoopTicker",
"<-",
"true",
"\n",
"return",
"nil",
"\n",
"}"
]
| // SetFPSLimit can be used to change the value in the given `RunOpts` after already having called `engo.Run`. | [
"SetFPSLimit",
"can",
"be",
"used",
"to",
"change",
"the",
"value",
"in",
"the",
"given",
"RunOpts",
"after",
"already",
"having",
"called",
"engo",
".",
"Run",
"."
]
| 6f88a7379a25d81e976cf6e86ea3617f3b480b1a | https://github.com/EngoEngine/engo/blob/6f88a7379a25d81e976cf6e86ea3617f3b480b1a/engo.go#L245-L252 |
12,754 | EngoEngine/engo | engo_mobile_bind_ios.go | TouchEvent | func TouchEvent(x, y, id, action int) {
Input.Mouse.X = float32(x) / opts.GlobalScale.X
Input.Mouse.Y = float32(y) / opts.GlobalScale.Y
switch action {
case C.UITouchPhaseBegan, C.UITouchPhaseStationary:
Input.Mouse.Action = Press
Input.Touches[id] = Point{
X: float32(x) / opts.GlobalScale.X,
Y: float32(y) / opts.GlobalScale.Y,
}
case C.UITouchPhaseEnded, C.UITouchPhaseCancelled:
Input.Mouse.Action = Release
delete(Input.Touches, id)
case C.UITouchPhaseMoved:
Input.Mouse.Action = Move
Input.Touches[id] = Point{
X: float32(x) / opts.GlobalScale.X,
Y: float32(y) / opts.GlobalScale.Y,
}
}
} | go | func TouchEvent(x, y, id, action int) {
Input.Mouse.X = float32(x) / opts.GlobalScale.X
Input.Mouse.Y = float32(y) / opts.GlobalScale.Y
switch action {
case C.UITouchPhaseBegan, C.UITouchPhaseStationary:
Input.Mouse.Action = Press
Input.Touches[id] = Point{
X: float32(x) / opts.GlobalScale.X,
Y: float32(y) / opts.GlobalScale.Y,
}
case C.UITouchPhaseEnded, C.UITouchPhaseCancelled:
Input.Mouse.Action = Release
delete(Input.Touches, id)
case C.UITouchPhaseMoved:
Input.Mouse.Action = Move
Input.Touches[id] = Point{
X: float32(x) / opts.GlobalScale.X,
Y: float32(y) / opts.GlobalScale.Y,
}
}
} | [
"func",
"TouchEvent",
"(",
"x",
",",
"y",
",",
"id",
",",
"action",
"int",
")",
"{",
"Input",
".",
"Mouse",
".",
"X",
"=",
"float32",
"(",
"x",
")",
"/",
"opts",
".",
"GlobalScale",
".",
"X",
"\n",
"Input",
".",
"Mouse",
".",
"Y",
"=",
"float32",
"(",
"y",
")",
"/",
"opts",
".",
"GlobalScale",
".",
"Y",
"\n",
"switch",
"action",
"{",
"case",
"C",
".",
"UITouchPhaseBegan",
",",
"C",
".",
"UITouchPhaseStationary",
":",
"Input",
".",
"Mouse",
".",
"Action",
"=",
"Press",
"\n",
"Input",
".",
"Touches",
"[",
"id",
"]",
"=",
"Point",
"{",
"X",
":",
"float32",
"(",
"x",
")",
"/",
"opts",
".",
"GlobalScale",
".",
"X",
",",
"Y",
":",
"float32",
"(",
"y",
")",
"/",
"opts",
".",
"GlobalScale",
".",
"Y",
",",
"}",
"\n",
"case",
"C",
".",
"UITouchPhaseEnded",
",",
"C",
".",
"UITouchPhaseCancelled",
":",
"Input",
".",
"Mouse",
".",
"Action",
"=",
"Release",
"\n",
"delete",
"(",
"Input",
".",
"Touches",
",",
"id",
")",
"\n",
"case",
"C",
".",
"UITouchPhaseMoved",
":",
"Input",
".",
"Mouse",
".",
"Action",
"=",
"Move",
"\n",
"Input",
".",
"Touches",
"[",
"id",
"]",
"=",
"Point",
"{",
"X",
":",
"float32",
"(",
"x",
")",
"/",
"opts",
".",
"GlobalScale",
".",
"X",
",",
"Y",
":",
"float32",
"(",
"y",
")",
"/",
"opts",
".",
"GlobalScale",
".",
"Y",
",",
"}",
"\n",
"}",
"\n",
"}"
]
| //TouchEvent handles the touch events sent from ios and puts them in the InputManager | [
"TouchEvent",
"handles",
"the",
"touch",
"events",
"sent",
"from",
"ios",
"and",
"puts",
"them",
"in",
"the",
"InputManager"
]
| 6f88a7379a25d81e976cf6e86ea3617f3b480b1a | https://github.com/EngoEngine/engo/blob/6f88a7379a25d81e976cf6e86ea3617f3b480b1a/engo_mobile_bind_ios.go#L13-L33 |
12,755 | EngoEngine/engo | engo_js.go | SetTitle | func SetTitle(title string) {
if opts.HeadlessMode {
log.Println("Title set to:", title)
} else {
document.Set("title", title)
}
} | go | func SetTitle(title string) {
if opts.HeadlessMode {
log.Println("Title set to:", title)
} else {
document.Set("title", title)
}
} | [
"func",
"SetTitle",
"(",
"title",
"string",
")",
"{",
"if",
"opts",
".",
"HeadlessMode",
"{",
"log",
".",
"Println",
"(",
"\"",
"\"",
",",
"title",
")",
"\n",
"}",
"else",
"{",
"document",
".",
"Set",
"(",
"\"",
"\"",
",",
"title",
")",
"\n",
"}",
"\n",
"}"
]
| // SetTitle changes the title of the page to the given string | [
"SetTitle",
"changes",
"the",
"title",
"of",
"the",
"page",
"to",
"the",
"given",
"string"
]
| 6f88a7379a25d81e976cf6e86ea3617f3b480b1a | https://github.com/EngoEngine/engo/blob/6f88a7379a25d81e976cf6e86ea3617f3b480b1a/engo_js.go#L163-L169 |
12,756 | EngoEngine/engo | engo_js.go | WindowSize | func WindowSize() (w, h int) {
w = int(WindowWidth())
h = int(WindowHeight())
return
} | go | func WindowSize() (w, h int) {
w = int(WindowWidth())
h = int(WindowHeight())
return
} | [
"func",
"WindowSize",
"(",
")",
"(",
"w",
",",
"h",
"int",
")",
"{",
"w",
"=",
"int",
"(",
"WindowWidth",
"(",
")",
")",
"\n",
"h",
"=",
"int",
"(",
"WindowHeight",
"(",
")",
")",
"\n",
"return",
"\n",
"}"
]
| // WindowSize returns the width and height of the current window | [
"WindowSize",
"returns",
"the",
"width",
"and",
"height",
"of",
"the",
"current",
"window"
]
| 6f88a7379a25d81e976cf6e86ea3617f3b480b1a | https://github.com/EngoEngine/engo/blob/6f88a7379a25d81e976cf6e86ea3617f3b480b1a/engo_js.go#L172-L176 |
12,757 | EngoEngine/engo | engo_js.go | jsPollKeys | func jsPollKeys() {
pollLock.Lock()
defer pollLock.Unlock()
for key, state := range poll {
Input.keys.Set(Key(key), state)
delete(poll, key)
}
} | go | func jsPollKeys() {
pollLock.Lock()
defer pollLock.Unlock()
for key, state := range poll {
Input.keys.Set(Key(key), state)
delete(poll, key)
}
} | [
"func",
"jsPollKeys",
"(",
")",
"{",
"pollLock",
".",
"Lock",
"(",
")",
"\n",
"defer",
"pollLock",
".",
"Unlock",
"(",
")",
"\n\n",
"for",
"key",
",",
"state",
":=",
"range",
"poll",
"{",
"Input",
".",
"keys",
".",
"Set",
"(",
"Key",
"(",
"key",
")",
",",
"state",
")",
"\n",
"delete",
"(",
"poll",
",",
"key",
")",
"\n",
"}",
"\n",
"}"
]
| // jsPollKeys polls the keys collected by the javascript callback
// this ensures the keys only get updated once per frame, since the
// callback has no information about the frames and is invoked several
// times between frames. This makes Input.Button.JustPressed and JustReleased
// able to return true properly. | [
"jsPollKeys",
"polls",
"the",
"keys",
"collected",
"by",
"the",
"javascript",
"callback",
"this",
"ensures",
"the",
"keys",
"only",
"get",
"updated",
"once",
"per",
"frame",
"since",
"the",
"callback",
"has",
"no",
"information",
"about",
"the",
"frames",
"and",
"is",
"invoked",
"several",
"times",
"between",
"frames",
".",
"This",
"makes",
"Input",
".",
"Button",
".",
"JustPressed",
"and",
"JustReleased",
"able",
"to",
"return",
"true",
"properly",
"."
]
| 6f88a7379a25d81e976cf6e86ea3617f3b480b1a | https://github.com/EngoEngine/engo/blob/6f88a7379a25d81e976cf6e86ea3617f3b480b1a/engo_js.go#L258-L266 |
12,758 | EngoEngine/engo | engo_js.go | RunPreparation | func RunPreparation() {
Time = NewClock()
if !opts.HeadlessMode {
window.Call("addEventListener", "onbeforeunload", js.NewEventCallback(js.PreventDefault, func(event js.Value) {
window.Call("alert", "You're closing")
}))
}
} | go | func RunPreparation() {
Time = NewClock()
if !opts.HeadlessMode {
window.Call("addEventListener", "onbeforeunload", js.NewEventCallback(js.PreventDefault, func(event js.Value) {
window.Call("alert", "You're closing")
}))
}
} | [
"func",
"RunPreparation",
"(",
")",
"{",
"Time",
"=",
"NewClock",
"(",
")",
"\n\n",
"if",
"!",
"opts",
".",
"HeadlessMode",
"{",
"window",
".",
"Call",
"(",
"\"",
"\"",
",",
"\"",
"\"",
",",
"js",
".",
"NewEventCallback",
"(",
"js",
".",
"PreventDefault",
",",
"func",
"(",
"event",
"js",
".",
"Value",
")",
"{",
"window",
".",
"Call",
"(",
"\"",
"\"",
",",
"\"",
"\"",
")",
"\n",
"}",
")",
")",
"\n",
"}",
"\n",
"}"
]
| // RunPreparation is called automatically when calling Open. It should only be called once. | [
"RunPreparation",
"is",
"called",
"automatically",
"when",
"calling",
"Open",
".",
"It",
"should",
"only",
"be",
"called",
"once",
"."
]
| 6f88a7379a25d81e976cf6e86ea3617f3b480b1a | https://github.com/EngoEngine/engo/blob/6f88a7379a25d81e976cf6e86ea3617f3b480b1a/engo_js.go#L278-L286 |
12,759 | EngoEngine/engo | engo_js.go | SetCursor | func SetCursor(c Cursor) {
switch c {
case CursorNone:
document.Get("body").Get("style").Set("cursor", "default")
case CursorHand:
document.Get("body").Get("style").Set("cursor", "hand")
}
} | go | func SetCursor(c Cursor) {
switch c {
case CursorNone:
document.Get("body").Get("style").Set("cursor", "default")
case CursorHand:
document.Get("body").Get("style").Set("cursor", "hand")
}
} | [
"func",
"SetCursor",
"(",
"c",
"Cursor",
")",
"{",
"switch",
"c",
"{",
"case",
"CursorNone",
":",
"document",
".",
"Get",
"(",
"\"",
"\"",
")",
".",
"Get",
"(",
"\"",
"\"",
")",
".",
"Set",
"(",
"\"",
"\"",
",",
"\"",
"\"",
")",
"\n",
"case",
"CursorHand",
":",
"document",
".",
"Get",
"(",
"\"",
"\"",
")",
".",
"Get",
"(",
"\"",
"\"",
")",
".",
"Set",
"(",
"\"",
"\"",
",",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"}"
]
| // SetCursor changes the cursor | [
"SetCursor",
"changes",
"the",
"cursor"
]
| 6f88a7379a25d81e976cf6e86ea3617f3b480b1a | https://github.com/EngoEngine/engo/blob/6f88a7379a25d81e976cf6e86ea3617f3b480b1a/engo_js.go#L357-L364 |
12,760 | EngoEngine/engo | engo_sdl.go | CreateWindow | func CreateWindow(title string, width, height int, fullscreen bool, msaa int) {
CurrentBackEnd = BackEndSDL
err := sdl.Init(sdl.INIT_EVERYTHING)
fatalErr(err)
if !opts.HeadlessMode {
cursorNone = sdl.CreateSystemCursor(sdl.SYSTEM_CURSOR_NO)
cursorArrow = sdl.CreateSystemCursor(sdl.SYSTEM_CURSOR_ARROW)
cursorIBeam = sdl.CreateSystemCursor(sdl.SYSTEM_CURSOR_IBEAM)
cursorCrosshair = sdl.CreateSystemCursor(sdl.SYSTEM_CURSOR_CROSSHAIR)
cursorHand = sdl.CreateSystemCursor(sdl.SYSTEM_CURSOR_HAND)
cursorHResize = sdl.CreateSystemCursor(sdl.SYSTEM_CURSOR_SIZENS)
cursorVResize = sdl.CreateSystemCursor(sdl.SYSTEM_CURSOR_SIZEWE)
}
sdl.GLSetAttribute(sdl.GL_CONTEXT_MAJOR_VERSION, 2)
sdl.GLSetAttribute(sdl.GL_CONTEXT_MINOR_VERSION, 1)
if msaa > 0 {
sdl.GLSetAttribute(sdl.GL_MULTISAMPLEBUFFERS, 1)
sdl.GLSetAttribute(sdl.GL_MULTISAMPLESAMPLES, msaa)
}
SetVSync(opts.VSync)
Window, err = sdl.CreateWindow(title, sdl.WINDOWPOS_UNDEFINED,
sdl.WINDOWPOS_UNDEFINED, int32(width), int32(height), sdl.WINDOW_OPENGL)
fatalErr(err)
sdlGLContext, err = Window.GLCreateContext()
fatalErr(err)
Gl = gl.NewContext()
if fullscreen {
Window.SetFullscreen(sdl.WINDOW_FULLSCREEN)
}
if opts.NotResizable {
Window.SetResizable(false)
} else {
Window.SetResizable(true)
}
gameWidth, gameHeight = float32(width), float32(height)
w, h := Window.GetSize()
windowWidth, windowHeight = float32(w), float32(h)
fw, fh := Window.GLGetDrawableSize()
canvasWidth, canvasHeight = float32(fw), float32(fh)
if windowWidth <= canvasWidth && windowHeight <= canvasHeight {
scale = canvasWidth / windowWidth
}
} | go | func CreateWindow(title string, width, height int, fullscreen bool, msaa int) {
CurrentBackEnd = BackEndSDL
err := sdl.Init(sdl.INIT_EVERYTHING)
fatalErr(err)
if !opts.HeadlessMode {
cursorNone = sdl.CreateSystemCursor(sdl.SYSTEM_CURSOR_NO)
cursorArrow = sdl.CreateSystemCursor(sdl.SYSTEM_CURSOR_ARROW)
cursorIBeam = sdl.CreateSystemCursor(sdl.SYSTEM_CURSOR_IBEAM)
cursorCrosshair = sdl.CreateSystemCursor(sdl.SYSTEM_CURSOR_CROSSHAIR)
cursorHand = sdl.CreateSystemCursor(sdl.SYSTEM_CURSOR_HAND)
cursorHResize = sdl.CreateSystemCursor(sdl.SYSTEM_CURSOR_SIZENS)
cursorVResize = sdl.CreateSystemCursor(sdl.SYSTEM_CURSOR_SIZEWE)
}
sdl.GLSetAttribute(sdl.GL_CONTEXT_MAJOR_VERSION, 2)
sdl.GLSetAttribute(sdl.GL_CONTEXT_MINOR_VERSION, 1)
if msaa > 0 {
sdl.GLSetAttribute(sdl.GL_MULTISAMPLEBUFFERS, 1)
sdl.GLSetAttribute(sdl.GL_MULTISAMPLESAMPLES, msaa)
}
SetVSync(opts.VSync)
Window, err = sdl.CreateWindow(title, sdl.WINDOWPOS_UNDEFINED,
sdl.WINDOWPOS_UNDEFINED, int32(width), int32(height), sdl.WINDOW_OPENGL)
fatalErr(err)
sdlGLContext, err = Window.GLCreateContext()
fatalErr(err)
Gl = gl.NewContext()
if fullscreen {
Window.SetFullscreen(sdl.WINDOW_FULLSCREEN)
}
if opts.NotResizable {
Window.SetResizable(false)
} else {
Window.SetResizable(true)
}
gameWidth, gameHeight = float32(width), float32(height)
w, h := Window.GetSize()
windowWidth, windowHeight = float32(w), float32(h)
fw, fh := Window.GLGetDrawableSize()
canvasWidth, canvasHeight = float32(fw), float32(fh)
if windowWidth <= canvasWidth && windowHeight <= canvasHeight {
scale = canvasWidth / windowWidth
}
} | [
"func",
"CreateWindow",
"(",
"title",
"string",
",",
"width",
",",
"height",
"int",
",",
"fullscreen",
"bool",
",",
"msaa",
"int",
")",
"{",
"CurrentBackEnd",
"=",
"BackEndSDL",
"\n\n",
"err",
":=",
"sdl",
".",
"Init",
"(",
"sdl",
".",
"INIT_EVERYTHING",
")",
"\n",
"fatalErr",
"(",
"err",
")",
"\n\n",
"if",
"!",
"opts",
".",
"HeadlessMode",
"{",
"cursorNone",
"=",
"sdl",
".",
"CreateSystemCursor",
"(",
"sdl",
".",
"SYSTEM_CURSOR_NO",
")",
"\n",
"cursorArrow",
"=",
"sdl",
".",
"CreateSystemCursor",
"(",
"sdl",
".",
"SYSTEM_CURSOR_ARROW",
")",
"\n",
"cursorIBeam",
"=",
"sdl",
".",
"CreateSystemCursor",
"(",
"sdl",
".",
"SYSTEM_CURSOR_IBEAM",
")",
"\n",
"cursorCrosshair",
"=",
"sdl",
".",
"CreateSystemCursor",
"(",
"sdl",
".",
"SYSTEM_CURSOR_CROSSHAIR",
")",
"\n",
"cursorHand",
"=",
"sdl",
".",
"CreateSystemCursor",
"(",
"sdl",
".",
"SYSTEM_CURSOR_HAND",
")",
"\n",
"cursorHResize",
"=",
"sdl",
".",
"CreateSystemCursor",
"(",
"sdl",
".",
"SYSTEM_CURSOR_SIZENS",
")",
"\n",
"cursorVResize",
"=",
"sdl",
".",
"CreateSystemCursor",
"(",
"sdl",
".",
"SYSTEM_CURSOR_SIZEWE",
")",
"\n",
"}",
"\n\n",
"sdl",
".",
"GLSetAttribute",
"(",
"sdl",
".",
"GL_CONTEXT_MAJOR_VERSION",
",",
"2",
")",
"\n",
"sdl",
".",
"GLSetAttribute",
"(",
"sdl",
".",
"GL_CONTEXT_MINOR_VERSION",
",",
"1",
")",
"\n\n",
"if",
"msaa",
">",
"0",
"{",
"sdl",
".",
"GLSetAttribute",
"(",
"sdl",
".",
"GL_MULTISAMPLEBUFFERS",
",",
"1",
")",
"\n",
"sdl",
".",
"GLSetAttribute",
"(",
"sdl",
".",
"GL_MULTISAMPLESAMPLES",
",",
"msaa",
")",
"\n",
"}",
"\n\n",
"SetVSync",
"(",
"opts",
".",
"VSync",
")",
"\n\n",
"Window",
",",
"err",
"=",
"sdl",
".",
"CreateWindow",
"(",
"title",
",",
"sdl",
".",
"WINDOWPOS_UNDEFINED",
",",
"sdl",
".",
"WINDOWPOS_UNDEFINED",
",",
"int32",
"(",
"width",
")",
",",
"int32",
"(",
"height",
")",
",",
"sdl",
".",
"WINDOW_OPENGL",
")",
"\n",
"fatalErr",
"(",
"err",
")",
"\n\n",
"sdlGLContext",
",",
"err",
"=",
"Window",
".",
"GLCreateContext",
"(",
")",
"\n",
"fatalErr",
"(",
"err",
")",
"\n\n",
"Gl",
"=",
"gl",
".",
"NewContext",
"(",
")",
"\n\n",
"if",
"fullscreen",
"{",
"Window",
".",
"SetFullscreen",
"(",
"sdl",
".",
"WINDOW_FULLSCREEN",
")",
"\n",
"}",
"\n",
"if",
"opts",
".",
"NotResizable",
"{",
"Window",
".",
"SetResizable",
"(",
"false",
")",
"\n",
"}",
"else",
"{",
"Window",
".",
"SetResizable",
"(",
"true",
")",
"\n",
"}",
"\n\n",
"gameWidth",
",",
"gameHeight",
"=",
"float32",
"(",
"width",
")",
",",
"float32",
"(",
"height",
")",
"\n\n",
"w",
",",
"h",
":=",
"Window",
".",
"GetSize",
"(",
")",
"\n",
"windowWidth",
",",
"windowHeight",
"=",
"float32",
"(",
"w",
")",
",",
"float32",
"(",
"h",
")",
"\n\n",
"fw",
",",
"fh",
":=",
"Window",
".",
"GLGetDrawableSize",
"(",
")",
"\n",
"canvasWidth",
",",
"canvasHeight",
"=",
"float32",
"(",
"fw",
")",
",",
"float32",
"(",
"fh",
")",
"\n\n",
"if",
"windowWidth",
"<=",
"canvasWidth",
"&&",
"windowHeight",
"<=",
"canvasHeight",
"{",
"scale",
"=",
"canvasWidth",
"/",
"windowWidth",
"\n",
"}",
"\n",
"}"
]
| // CreateWindow opens the window and gets a GL surface for rendering | [
"CreateWindow",
"opens",
"the",
"window",
"and",
"gets",
"a",
"GL",
"surface",
"for",
"rendering"
]
| 6f88a7379a25d81e976cf6e86ea3617f3b480b1a | https://github.com/EngoEngine/engo/blob/6f88a7379a25d81e976cf6e86ea3617f3b480b1a/engo_sdl.go#L51-L106 |
12,761 | EngoEngine/engo | engo_sdl.go | WindowSize | func WindowSize() (w, h int) {
width, height := Window.GetSize()
return int(width), int(height)
} | go | func WindowSize() (w, h int) {
width, height := Window.GetSize()
return int(width), int(height)
} | [
"func",
"WindowSize",
"(",
")",
"(",
"w",
",",
"h",
"int",
")",
"{",
"width",
",",
"height",
":=",
"Window",
".",
"GetSize",
"(",
")",
"\n",
"return",
"int",
"(",
"width",
")",
",",
"int",
"(",
"height",
")",
"\n",
"}"
]
| // WindowSize gets the current window size | [
"WindowSize",
"gets",
"the",
"current",
"window",
"size"
]
| 6f88a7379a25d81e976cf6e86ea3617f3b480b1a | https://github.com/EngoEngine/engo/blob/6f88a7379a25d81e976cf6e86ea3617f3b480b1a/engo_sdl.go#L273-L276 |
12,762 | EngoEngine/engo | engo_mobile_bind_android.go | TouchEvent | func TouchEvent(x, y, id, action int) {
Input.Mouse.X = float32(x) / opts.GlobalScale.X
Input.Mouse.Y = float32(y) / opts.GlobalScale.Y
switch action {
case 0, 5:
Input.Mouse.Action = Press
Input.Touches[id] = Point{
X: float32(x) / opts.GlobalScale.X,
Y: float32(y) / opts.GlobalScale.Y,
}
case 1, 6:
Input.Mouse.Action = Release
delete(Input.Touches, id)
case 2:
Input.Mouse.Action = Move
Input.Touches[id] = Point{
X: float32(x) / opts.GlobalScale.X,
Y: float32(y) / opts.GlobalScale.Y,
}
}
} | go | func TouchEvent(x, y, id, action int) {
Input.Mouse.X = float32(x) / opts.GlobalScale.X
Input.Mouse.Y = float32(y) / opts.GlobalScale.Y
switch action {
case 0, 5:
Input.Mouse.Action = Press
Input.Touches[id] = Point{
X: float32(x) / opts.GlobalScale.X,
Y: float32(y) / opts.GlobalScale.Y,
}
case 1, 6:
Input.Mouse.Action = Release
delete(Input.Touches, id)
case 2:
Input.Mouse.Action = Move
Input.Touches[id] = Point{
X: float32(x) / opts.GlobalScale.X,
Y: float32(y) / opts.GlobalScale.Y,
}
}
} | [
"func",
"TouchEvent",
"(",
"x",
",",
"y",
",",
"id",
",",
"action",
"int",
")",
"{",
"Input",
".",
"Mouse",
".",
"X",
"=",
"float32",
"(",
"x",
")",
"/",
"opts",
".",
"GlobalScale",
".",
"X",
"\n",
"Input",
".",
"Mouse",
".",
"Y",
"=",
"float32",
"(",
"y",
")",
"/",
"opts",
".",
"GlobalScale",
".",
"Y",
"\n",
"switch",
"action",
"{",
"case",
"0",
",",
"5",
":",
"Input",
".",
"Mouse",
".",
"Action",
"=",
"Press",
"\n",
"Input",
".",
"Touches",
"[",
"id",
"]",
"=",
"Point",
"{",
"X",
":",
"float32",
"(",
"x",
")",
"/",
"opts",
".",
"GlobalScale",
".",
"X",
",",
"Y",
":",
"float32",
"(",
"y",
")",
"/",
"opts",
".",
"GlobalScale",
".",
"Y",
",",
"}",
"\n",
"case",
"1",
",",
"6",
":",
"Input",
".",
"Mouse",
".",
"Action",
"=",
"Release",
"\n",
"delete",
"(",
"Input",
".",
"Touches",
",",
"id",
")",
"\n",
"case",
"2",
":",
"Input",
".",
"Mouse",
".",
"Action",
"=",
"Move",
"\n",
"Input",
".",
"Touches",
"[",
"id",
"]",
"=",
"Point",
"{",
"X",
":",
"float32",
"(",
"x",
")",
"/",
"opts",
".",
"GlobalScale",
".",
"X",
",",
"Y",
":",
"float32",
"(",
"y",
")",
"/",
"opts",
".",
"GlobalScale",
".",
"Y",
",",
"}",
"\n",
"}",
"\n",
"}"
]
| //TouchEvent handles the touch events sent from Android and puts them in the InputManager | [
"TouchEvent",
"handles",
"the",
"touch",
"events",
"sent",
"from",
"Android",
"and",
"puts",
"them",
"in",
"the",
"InputManager"
]
| 6f88a7379a25d81e976cf6e86ea3617f3b480b1a | https://github.com/EngoEngine/engo/blob/6f88a7379a25d81e976cf6e86ea3617f3b480b1a/engo_mobile_bind_android.go#L6-L26 |
12,763 | EngoEngine/engo | common/camera.go | New | func (cam *CameraSystem) New(w *ecs.World) {
num := 0
for _, sys := range w.Systems() {
switch sys.(type) {
case *CameraSystem:
num++
}
}
if num > 0 { //initalizer is called before added to w.systems
warning("More than one CameraSystem was added to the World. The RenderSystem adds a CameraSystem if none exist when it's added.")
}
if CameraBounds.Max.X == 0 && CameraBounds.Max.Y == 0 {
CameraBounds.Max = engo.Point{X: engo.GameWidth(), Y: engo.GameHeight()}
}
cam.x = CameraBounds.Max.X / 2
cam.y = CameraBounds.Max.Y / 2
cam.z = 1
cam.longTasks = make(map[CameraAxis]*CameraMessage)
engo.Mailbox.Listen("CameraMessage", func(msg engo.Message) {
cammsg, ok := msg.(CameraMessage)
if !ok {
return
}
// Stop with whatever we're doing now
if _, ok := cam.longTasks[cammsg.Axis]; ok {
delete(cam.longTasks, cammsg.Axis)
}
if cammsg.Duration > time.Duration(0) {
cam.longTasks[cammsg.Axis] = &cammsg
return // because it's handled incrementally
}
if cammsg.Incremental {
switch cammsg.Axis {
case XAxis:
cam.moveX(cammsg.Value)
case YAxis:
cam.moveY(cammsg.Value)
case ZAxis:
cam.zoom(cammsg.Value)
case Angle:
cam.rotate(cammsg.Value)
}
} else {
switch cammsg.Axis {
case XAxis:
cam.moveToX(cammsg.Value)
case YAxis:
cam.moveToY(cammsg.Value)
case ZAxis:
cam.zoomTo(cammsg.Value)
case Angle:
cam.rotateTo(cammsg.Value)
}
}
})
engo.Mailbox.Dispatch(NewCameraMessage{})
} | go | func (cam *CameraSystem) New(w *ecs.World) {
num := 0
for _, sys := range w.Systems() {
switch sys.(type) {
case *CameraSystem:
num++
}
}
if num > 0 { //initalizer is called before added to w.systems
warning("More than one CameraSystem was added to the World. The RenderSystem adds a CameraSystem if none exist when it's added.")
}
if CameraBounds.Max.X == 0 && CameraBounds.Max.Y == 0 {
CameraBounds.Max = engo.Point{X: engo.GameWidth(), Y: engo.GameHeight()}
}
cam.x = CameraBounds.Max.X / 2
cam.y = CameraBounds.Max.Y / 2
cam.z = 1
cam.longTasks = make(map[CameraAxis]*CameraMessage)
engo.Mailbox.Listen("CameraMessage", func(msg engo.Message) {
cammsg, ok := msg.(CameraMessage)
if !ok {
return
}
// Stop with whatever we're doing now
if _, ok := cam.longTasks[cammsg.Axis]; ok {
delete(cam.longTasks, cammsg.Axis)
}
if cammsg.Duration > time.Duration(0) {
cam.longTasks[cammsg.Axis] = &cammsg
return // because it's handled incrementally
}
if cammsg.Incremental {
switch cammsg.Axis {
case XAxis:
cam.moveX(cammsg.Value)
case YAxis:
cam.moveY(cammsg.Value)
case ZAxis:
cam.zoom(cammsg.Value)
case Angle:
cam.rotate(cammsg.Value)
}
} else {
switch cammsg.Axis {
case XAxis:
cam.moveToX(cammsg.Value)
case YAxis:
cam.moveToY(cammsg.Value)
case ZAxis:
cam.zoomTo(cammsg.Value)
case Angle:
cam.rotateTo(cammsg.Value)
}
}
})
engo.Mailbox.Dispatch(NewCameraMessage{})
} | [
"func",
"(",
"cam",
"*",
"CameraSystem",
")",
"New",
"(",
"w",
"*",
"ecs",
".",
"World",
")",
"{",
"num",
":=",
"0",
"\n",
"for",
"_",
",",
"sys",
":=",
"range",
"w",
".",
"Systems",
"(",
")",
"{",
"switch",
"sys",
".",
"(",
"type",
")",
"{",
"case",
"*",
"CameraSystem",
":",
"num",
"++",
"\n",
"}",
"\n",
"}",
"\n",
"if",
"num",
">",
"0",
"{",
"//initalizer is called before added to w.systems",
"warning",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"if",
"CameraBounds",
".",
"Max",
".",
"X",
"==",
"0",
"&&",
"CameraBounds",
".",
"Max",
".",
"Y",
"==",
"0",
"{",
"CameraBounds",
".",
"Max",
"=",
"engo",
".",
"Point",
"{",
"X",
":",
"engo",
".",
"GameWidth",
"(",
")",
",",
"Y",
":",
"engo",
".",
"GameHeight",
"(",
")",
"}",
"\n",
"}",
"\n\n",
"cam",
".",
"x",
"=",
"CameraBounds",
".",
"Max",
".",
"X",
"/",
"2",
"\n",
"cam",
".",
"y",
"=",
"CameraBounds",
".",
"Max",
".",
"Y",
"/",
"2",
"\n",
"cam",
".",
"z",
"=",
"1",
"\n\n",
"cam",
".",
"longTasks",
"=",
"make",
"(",
"map",
"[",
"CameraAxis",
"]",
"*",
"CameraMessage",
")",
"\n\n",
"engo",
".",
"Mailbox",
".",
"Listen",
"(",
"\"",
"\"",
",",
"func",
"(",
"msg",
"engo",
".",
"Message",
")",
"{",
"cammsg",
",",
"ok",
":=",
"msg",
".",
"(",
"CameraMessage",
")",
"\n",
"if",
"!",
"ok",
"{",
"return",
"\n",
"}",
"\n\n",
"// Stop with whatever we're doing now",
"if",
"_",
",",
"ok",
":=",
"cam",
".",
"longTasks",
"[",
"cammsg",
".",
"Axis",
"]",
";",
"ok",
"{",
"delete",
"(",
"cam",
".",
"longTasks",
",",
"cammsg",
".",
"Axis",
")",
"\n",
"}",
"\n\n",
"if",
"cammsg",
".",
"Duration",
">",
"time",
".",
"Duration",
"(",
"0",
")",
"{",
"cam",
".",
"longTasks",
"[",
"cammsg",
".",
"Axis",
"]",
"=",
"&",
"cammsg",
"\n",
"return",
"// because it's handled incrementally",
"\n",
"}",
"\n\n",
"if",
"cammsg",
".",
"Incremental",
"{",
"switch",
"cammsg",
".",
"Axis",
"{",
"case",
"XAxis",
":",
"cam",
".",
"moveX",
"(",
"cammsg",
".",
"Value",
")",
"\n",
"case",
"YAxis",
":",
"cam",
".",
"moveY",
"(",
"cammsg",
".",
"Value",
")",
"\n",
"case",
"ZAxis",
":",
"cam",
".",
"zoom",
"(",
"cammsg",
".",
"Value",
")",
"\n",
"case",
"Angle",
":",
"cam",
".",
"rotate",
"(",
"cammsg",
".",
"Value",
")",
"\n",
"}",
"\n",
"}",
"else",
"{",
"switch",
"cammsg",
".",
"Axis",
"{",
"case",
"XAxis",
":",
"cam",
".",
"moveToX",
"(",
"cammsg",
".",
"Value",
")",
"\n",
"case",
"YAxis",
":",
"cam",
".",
"moveToY",
"(",
"cammsg",
".",
"Value",
")",
"\n",
"case",
"ZAxis",
":",
"cam",
".",
"zoomTo",
"(",
"cammsg",
".",
"Value",
")",
"\n",
"case",
"Angle",
":",
"cam",
".",
"rotateTo",
"(",
"cammsg",
".",
"Value",
")",
"\n",
"}",
"\n",
"}",
"\n",
"}",
")",
"\n\n",
"engo",
".",
"Mailbox",
".",
"Dispatch",
"(",
"NewCameraMessage",
"{",
"}",
")",
"\n",
"}"
]
| // New initializes the CameraSystem. | [
"New",
"initializes",
"the",
"CameraSystem",
"."
]
| 6f88a7379a25d81e976cf6e86ea3617f3b480b1a | https://github.com/EngoEngine/engo/blob/6f88a7379a25d81e976cf6e86ea3617f3b480b1a/common/camera.go#L66-L130 |
12,764 | EngoEngine/engo | common/camera.go | Update | func (cam *CameraSystem) Update(dt float32) {
for axis, longTask := range cam.longTasks {
if !longTask.Incremental {
longTask.Incremental = true
switch axis {
case XAxis:
longTask.Value -= cam.x
case YAxis:
longTask.Value -= cam.y
case ZAxis:
longTask.Value -= cam.z
case Angle:
longTask.Value -= cam.angle
}
}
// Set speed if needed
if longTask.speed == 0 {
longTask.speed = longTask.Value / float32(longTask.Duration.Seconds())
}
dAxis := longTask.speed * dt
switch axis {
case XAxis:
cam.moveX(dAxis)
case YAxis:
cam.moveY(dAxis)
case ZAxis:
cam.zoom(dAxis)
case Angle:
cam.rotate(dAxis)
}
longTask.Duration -= time.Duration(dt)
if longTask.Duration <= time.Duration(0) {
delete(cam.longTasks, axis)
}
}
if cam.tracking.BasicEntity == nil {
return
}
if cam.tracking.SpaceComponent == nil {
log.Println("Should be tracking", cam.tracking.BasicEntity.ID(), "but SpaceComponent is nil")
cam.tracking.BasicEntity = nil
return
}
cam.centerCam(cam.tracking.SpaceComponent.Position.X+cam.tracking.SpaceComponent.Width/2,
cam.tracking.SpaceComponent.Position.Y+cam.tracking.SpaceComponent.Height/2,
cam.z,
)
if cam.trackRotation {
cam.rotateTo(cam.tracking.SpaceComponent.Rotation)
}
} | go | func (cam *CameraSystem) Update(dt float32) {
for axis, longTask := range cam.longTasks {
if !longTask.Incremental {
longTask.Incremental = true
switch axis {
case XAxis:
longTask.Value -= cam.x
case YAxis:
longTask.Value -= cam.y
case ZAxis:
longTask.Value -= cam.z
case Angle:
longTask.Value -= cam.angle
}
}
// Set speed if needed
if longTask.speed == 0 {
longTask.speed = longTask.Value / float32(longTask.Duration.Seconds())
}
dAxis := longTask.speed * dt
switch axis {
case XAxis:
cam.moveX(dAxis)
case YAxis:
cam.moveY(dAxis)
case ZAxis:
cam.zoom(dAxis)
case Angle:
cam.rotate(dAxis)
}
longTask.Duration -= time.Duration(dt)
if longTask.Duration <= time.Duration(0) {
delete(cam.longTasks, axis)
}
}
if cam.tracking.BasicEntity == nil {
return
}
if cam.tracking.SpaceComponent == nil {
log.Println("Should be tracking", cam.tracking.BasicEntity.ID(), "but SpaceComponent is nil")
cam.tracking.BasicEntity = nil
return
}
cam.centerCam(cam.tracking.SpaceComponent.Position.X+cam.tracking.SpaceComponent.Width/2,
cam.tracking.SpaceComponent.Position.Y+cam.tracking.SpaceComponent.Height/2,
cam.z,
)
if cam.trackRotation {
cam.rotateTo(cam.tracking.SpaceComponent.Rotation)
}
} | [
"func",
"(",
"cam",
"*",
"CameraSystem",
")",
"Update",
"(",
"dt",
"float32",
")",
"{",
"for",
"axis",
",",
"longTask",
":=",
"range",
"cam",
".",
"longTasks",
"{",
"if",
"!",
"longTask",
".",
"Incremental",
"{",
"longTask",
".",
"Incremental",
"=",
"true",
"\n\n",
"switch",
"axis",
"{",
"case",
"XAxis",
":",
"longTask",
".",
"Value",
"-=",
"cam",
".",
"x",
"\n",
"case",
"YAxis",
":",
"longTask",
".",
"Value",
"-=",
"cam",
".",
"y",
"\n",
"case",
"ZAxis",
":",
"longTask",
".",
"Value",
"-=",
"cam",
".",
"z",
"\n",
"case",
"Angle",
":",
"longTask",
".",
"Value",
"-=",
"cam",
".",
"angle",
"\n",
"}",
"\n",
"}",
"\n\n",
"// Set speed if needed",
"if",
"longTask",
".",
"speed",
"==",
"0",
"{",
"longTask",
".",
"speed",
"=",
"longTask",
".",
"Value",
"/",
"float32",
"(",
"longTask",
".",
"Duration",
".",
"Seconds",
"(",
")",
")",
"\n",
"}",
"\n\n",
"dAxis",
":=",
"longTask",
".",
"speed",
"*",
"dt",
"\n",
"switch",
"axis",
"{",
"case",
"XAxis",
":",
"cam",
".",
"moveX",
"(",
"dAxis",
")",
"\n",
"case",
"YAxis",
":",
"cam",
".",
"moveY",
"(",
"dAxis",
")",
"\n",
"case",
"ZAxis",
":",
"cam",
".",
"zoom",
"(",
"dAxis",
")",
"\n",
"case",
"Angle",
":",
"cam",
".",
"rotate",
"(",
"dAxis",
")",
"\n",
"}",
"\n\n",
"longTask",
".",
"Duration",
"-=",
"time",
".",
"Duration",
"(",
"dt",
")",
"\n",
"if",
"longTask",
".",
"Duration",
"<=",
"time",
".",
"Duration",
"(",
"0",
")",
"{",
"delete",
"(",
"cam",
".",
"longTasks",
",",
"axis",
")",
"\n",
"}",
"\n",
"}",
"\n\n",
"if",
"cam",
".",
"tracking",
".",
"BasicEntity",
"==",
"nil",
"{",
"return",
"\n",
"}",
"\n\n",
"if",
"cam",
".",
"tracking",
".",
"SpaceComponent",
"==",
"nil",
"{",
"log",
".",
"Println",
"(",
"\"",
"\"",
",",
"cam",
".",
"tracking",
".",
"BasicEntity",
".",
"ID",
"(",
")",
",",
"\"",
"\"",
")",
"\n",
"cam",
".",
"tracking",
".",
"BasicEntity",
"=",
"nil",
"\n",
"return",
"\n",
"}",
"\n\n",
"cam",
".",
"centerCam",
"(",
"cam",
".",
"tracking",
".",
"SpaceComponent",
".",
"Position",
".",
"X",
"+",
"cam",
".",
"tracking",
".",
"SpaceComponent",
".",
"Width",
"/",
"2",
",",
"cam",
".",
"tracking",
".",
"SpaceComponent",
".",
"Position",
".",
"Y",
"+",
"cam",
".",
"tracking",
".",
"SpaceComponent",
".",
"Height",
"/",
"2",
",",
"cam",
".",
"z",
",",
")",
"\n",
"if",
"cam",
".",
"trackRotation",
"{",
"cam",
".",
"rotateTo",
"(",
"cam",
".",
"tracking",
".",
"SpaceComponent",
".",
"Rotation",
")",
"\n",
"}",
"\n",
"}"
]
| // Update updates the camera. lLong tasks are attempted to update incrementally in batches. | [
"Update",
"updates",
"the",
"camera",
".",
"lLong",
"tasks",
"are",
"attempted",
"to",
"update",
"incrementally",
"in",
"batches",
"."
]
| 6f88a7379a25d81e976cf6e86ea3617f3b480b1a | https://github.com/EngoEngine/engo/blob/6f88a7379a25d81e976cf6e86ea3617f3b480b1a/common/camera.go#L137-L194 |
12,765 | EngoEngine/engo | common/camera.go | FollowEntity | func (cam *CameraSystem) FollowEntity(basic *ecs.BasicEntity, space *SpaceComponent, trackRotation bool) {
cam.tracking = cameraEntity{basic, space}
cam.trackRotation = trackRotation
} | go | func (cam *CameraSystem) FollowEntity(basic *ecs.BasicEntity, space *SpaceComponent, trackRotation bool) {
cam.tracking = cameraEntity{basic, space}
cam.trackRotation = trackRotation
} | [
"func",
"(",
"cam",
"*",
"CameraSystem",
")",
"FollowEntity",
"(",
"basic",
"*",
"ecs",
".",
"BasicEntity",
",",
"space",
"*",
"SpaceComponent",
",",
"trackRotation",
"bool",
")",
"{",
"cam",
".",
"tracking",
"=",
"cameraEntity",
"{",
"basic",
",",
"space",
"}",
"\n",
"cam",
".",
"trackRotation",
"=",
"trackRotation",
"\n",
"}"
]
| // FollowEntity sets the camera to follow the entity with BasicEntity basic
// and SpaceComponent space. | [
"FollowEntity",
"sets",
"the",
"camera",
"to",
"follow",
"the",
"entity",
"with",
"BasicEntity",
"basic",
"and",
"SpaceComponent",
"space",
"."
]
| 6f88a7379a25d81e976cf6e86ea3617f3b480b1a | https://github.com/EngoEngine/engo/blob/6f88a7379a25d81e976cf6e86ea3617f3b480b1a/common/camera.go#L198-L201 |
12,766 | EngoEngine/engo | common/camera.go | Update | func (c *KeyboardScroller) Update(dt float32) {
c.keysMu.RLock()
defer c.keysMu.RUnlock()
m := engo.Point{
X: engo.Input.Axis(c.horizontalAxis).Value(),
Y: engo.Input.Axis(c.verticalAxis).Value(),
}
n, _ := m.Normalize()
engo.Mailbox.Dispatch(CameraMessage{Axis: XAxis, Value: n.X * c.ScrollSpeed * dt, Incremental: true})
engo.Mailbox.Dispatch(CameraMessage{Axis: YAxis, Value: n.Y * c.ScrollSpeed * dt, Incremental: true})
} | go | func (c *KeyboardScroller) Update(dt float32) {
c.keysMu.RLock()
defer c.keysMu.RUnlock()
m := engo.Point{
X: engo.Input.Axis(c.horizontalAxis).Value(),
Y: engo.Input.Axis(c.verticalAxis).Value(),
}
n, _ := m.Normalize()
engo.Mailbox.Dispatch(CameraMessage{Axis: XAxis, Value: n.X * c.ScrollSpeed * dt, Incremental: true})
engo.Mailbox.Dispatch(CameraMessage{Axis: YAxis, Value: n.Y * c.ScrollSpeed * dt, Incremental: true})
} | [
"func",
"(",
"c",
"*",
"KeyboardScroller",
")",
"Update",
"(",
"dt",
"float32",
")",
"{",
"c",
".",
"keysMu",
".",
"RLock",
"(",
")",
"\n",
"defer",
"c",
".",
"keysMu",
".",
"RUnlock",
"(",
")",
"\n\n",
"m",
":=",
"engo",
".",
"Point",
"{",
"X",
":",
"engo",
".",
"Input",
".",
"Axis",
"(",
"c",
".",
"horizontalAxis",
")",
".",
"Value",
"(",
")",
",",
"Y",
":",
"engo",
".",
"Input",
".",
"Axis",
"(",
"c",
".",
"verticalAxis",
")",
".",
"Value",
"(",
")",
",",
"}",
"\n",
"n",
",",
"_",
":=",
"m",
".",
"Normalize",
"(",
")",
"\n",
"engo",
".",
"Mailbox",
".",
"Dispatch",
"(",
"CameraMessage",
"{",
"Axis",
":",
"XAxis",
",",
"Value",
":",
"n",
".",
"X",
"*",
"c",
".",
"ScrollSpeed",
"*",
"dt",
",",
"Incremental",
":",
"true",
"}",
")",
"\n",
"engo",
".",
"Mailbox",
".",
"Dispatch",
"(",
"CameraMessage",
"{",
"Axis",
":",
"YAxis",
",",
"Value",
":",
"n",
".",
"Y",
"*",
"c",
".",
"ScrollSpeed",
"*",
"dt",
",",
"Incremental",
":",
"true",
"}",
")",
"\n",
"}"
]
| // Update updates the camera based on keyboard input. | [
"Update",
"updates",
"the",
"camera",
"based",
"on",
"keyboard",
"input",
"."
]
| 6f88a7379a25d81e976cf6e86ea3617f3b480b1a | https://github.com/EngoEngine/engo/blob/6f88a7379a25d81e976cf6e86ea3617f3b480b1a/common/camera.go#L326-L337 |
12,767 | EngoEngine/engo | common/camera.go | BindKeyboard | func (c *KeyboardScroller) BindKeyboard(hori, vert string) {
c.keysMu.Lock()
c.verticalAxis = vert
c.horizontalAxis = hori
defer c.keysMu.Unlock()
} | go | func (c *KeyboardScroller) BindKeyboard(hori, vert string) {
c.keysMu.Lock()
c.verticalAxis = vert
c.horizontalAxis = hori
defer c.keysMu.Unlock()
} | [
"func",
"(",
"c",
"*",
"KeyboardScroller",
")",
"BindKeyboard",
"(",
"hori",
",",
"vert",
"string",
")",
"{",
"c",
".",
"keysMu",
".",
"Lock",
"(",
")",
"\n\n",
"c",
".",
"verticalAxis",
"=",
"vert",
"\n",
"c",
".",
"horizontalAxis",
"=",
"hori",
"\n\n",
"defer",
"c",
".",
"keysMu",
".",
"Unlock",
"(",
")",
"\n",
"}"
]
| // BindKeyboard sets the vertical and horizontal axes used by the KeyboardScroller. | [
"BindKeyboard",
"sets",
"the",
"vertical",
"and",
"horizontal",
"axes",
"used",
"by",
"the",
"KeyboardScroller",
"."
]
| 6f88a7379a25d81e976cf6e86ea3617f3b480b1a | https://github.com/EngoEngine/engo/blob/6f88a7379a25d81e976cf6e86ea3617f3b480b1a/common/camera.go#L340-L347 |
12,768 | EngoEngine/engo | common/camera.go | NewKeyboardScroller | func NewKeyboardScroller(scrollSpeed float32, hori, vert string) *KeyboardScroller {
kbs := &KeyboardScroller{
ScrollSpeed: scrollSpeed,
}
kbs.BindKeyboard(hori, vert)
return kbs
} | go | func NewKeyboardScroller(scrollSpeed float32, hori, vert string) *KeyboardScroller {
kbs := &KeyboardScroller{
ScrollSpeed: scrollSpeed,
}
kbs.BindKeyboard(hori, vert)
return kbs
} | [
"func",
"NewKeyboardScroller",
"(",
"scrollSpeed",
"float32",
",",
"hori",
",",
"vert",
"string",
")",
"*",
"KeyboardScroller",
"{",
"kbs",
":=",
"&",
"KeyboardScroller",
"{",
"ScrollSpeed",
":",
"scrollSpeed",
",",
"}",
"\n\n",
"kbs",
".",
"BindKeyboard",
"(",
"hori",
",",
"vert",
")",
"\n\n",
"return",
"kbs",
"\n",
"}"
]
| // NewKeyboardScroller creates a new KeyboardScroller system using the provided scrollSpeed,
// and horizontal and vertical axes. | [
"NewKeyboardScroller",
"creates",
"a",
"new",
"KeyboardScroller",
"system",
"using",
"the",
"provided",
"scrollSpeed",
"and",
"horizontal",
"and",
"vertical",
"axes",
"."
]
| 6f88a7379a25d81e976cf6e86ea3617f3b480b1a | https://github.com/EngoEngine/engo/blob/6f88a7379a25d81e976cf6e86ea3617f3b480b1a/common/camera.go#L351-L359 |
12,769 | EngoEngine/engo | common/camera.go | New | func (c *EntityScroller) New(*ecs.World) {
offsetX, offsetY := engo.GameWidth()/2, engo.GameHeight()/2
CameraBounds.Min.X = c.TrackingBounds.Min.X + (offsetX / engo.GetGlobalScale().X)
CameraBounds.Min.Y = c.TrackingBounds.Min.Y + (offsetY / engo.GetGlobalScale().Y)
CameraBounds.Max.X = c.TrackingBounds.Max.X - (offsetX / engo.GetGlobalScale().X)
CameraBounds.Max.Y = c.TrackingBounds.Max.Y - (offsetY / engo.GetGlobalScale().Y)
} | go | func (c *EntityScroller) New(*ecs.World) {
offsetX, offsetY := engo.GameWidth()/2, engo.GameHeight()/2
CameraBounds.Min.X = c.TrackingBounds.Min.X + (offsetX / engo.GetGlobalScale().X)
CameraBounds.Min.Y = c.TrackingBounds.Min.Y + (offsetY / engo.GetGlobalScale().Y)
CameraBounds.Max.X = c.TrackingBounds.Max.X - (offsetX / engo.GetGlobalScale().X)
CameraBounds.Max.Y = c.TrackingBounds.Max.Y - (offsetY / engo.GetGlobalScale().Y)
} | [
"func",
"(",
"c",
"*",
"EntityScroller",
")",
"New",
"(",
"*",
"ecs",
".",
"World",
")",
"{",
"offsetX",
",",
"offsetY",
":=",
"engo",
".",
"GameWidth",
"(",
")",
"/",
"2",
",",
"engo",
".",
"GameHeight",
"(",
")",
"/",
"2",
"\n\n",
"CameraBounds",
".",
"Min",
".",
"X",
"=",
"c",
".",
"TrackingBounds",
".",
"Min",
".",
"X",
"+",
"(",
"offsetX",
"/",
"engo",
".",
"GetGlobalScale",
"(",
")",
".",
"X",
")",
"\n",
"CameraBounds",
".",
"Min",
".",
"Y",
"=",
"c",
".",
"TrackingBounds",
".",
"Min",
".",
"Y",
"+",
"(",
"offsetY",
"/",
"engo",
".",
"GetGlobalScale",
"(",
")",
".",
"Y",
")",
"\n\n",
"CameraBounds",
".",
"Max",
".",
"X",
"=",
"c",
".",
"TrackingBounds",
".",
"Max",
".",
"X",
"-",
"(",
"offsetX",
"/",
"engo",
".",
"GetGlobalScale",
"(",
")",
".",
"X",
")",
"\n",
"CameraBounds",
".",
"Max",
".",
"Y",
"=",
"c",
".",
"TrackingBounds",
".",
"Max",
".",
"Y",
"-",
"(",
"offsetY",
"/",
"engo",
".",
"GetGlobalScale",
"(",
")",
".",
"Y",
")",
"\n",
"}"
]
| // New adjusts CameraBounds to the bounds of EntityScroller. | [
"New",
"adjusts",
"CameraBounds",
"to",
"the",
"bounds",
"of",
"EntityScroller",
"."
]
| 6f88a7379a25d81e976cf6e86ea3617f3b480b1a | https://github.com/EngoEngine/engo/blob/6f88a7379a25d81e976cf6e86ea3617f3b480b1a/common/camera.go#L369-L377 |
12,770 | EngoEngine/engo | common/camera.go | Update | func (c *EntityScroller) Update(dt float32) {
if c.SpaceComponent == nil {
return
}
width, height := c.SpaceComponent.Width, c.SpaceComponent.Height
pos := c.SpaceComponent.Position
trackToX := pos.X + width/2
trackToY := pos.Y + height/2
engo.Mailbox.Dispatch(CameraMessage{Axis: XAxis, Value: trackToX, Incremental: false})
engo.Mailbox.Dispatch(CameraMessage{Axis: YAxis, Value: trackToY, Incremental: false})
if c.Rotation {
engo.Mailbox.Dispatch(CameraMessage{Axis: Angle, Value: c.SpaceComponent.Rotation, Incremental: false})
}
} | go | func (c *EntityScroller) Update(dt float32) {
if c.SpaceComponent == nil {
return
}
width, height := c.SpaceComponent.Width, c.SpaceComponent.Height
pos := c.SpaceComponent.Position
trackToX := pos.X + width/2
trackToY := pos.Y + height/2
engo.Mailbox.Dispatch(CameraMessage{Axis: XAxis, Value: trackToX, Incremental: false})
engo.Mailbox.Dispatch(CameraMessage{Axis: YAxis, Value: trackToY, Incremental: false})
if c.Rotation {
engo.Mailbox.Dispatch(CameraMessage{Axis: Angle, Value: c.SpaceComponent.Rotation, Incremental: false})
}
} | [
"func",
"(",
"c",
"*",
"EntityScroller",
")",
"Update",
"(",
"dt",
"float32",
")",
"{",
"if",
"c",
".",
"SpaceComponent",
"==",
"nil",
"{",
"return",
"\n",
"}",
"\n\n",
"width",
",",
"height",
":=",
"c",
".",
"SpaceComponent",
".",
"Width",
",",
"c",
".",
"SpaceComponent",
".",
"Height",
"\n\n",
"pos",
":=",
"c",
".",
"SpaceComponent",
".",
"Position",
"\n",
"trackToX",
":=",
"pos",
".",
"X",
"+",
"width",
"/",
"2",
"\n",
"trackToY",
":=",
"pos",
".",
"Y",
"+",
"height",
"/",
"2",
"\n\n",
"engo",
".",
"Mailbox",
".",
"Dispatch",
"(",
"CameraMessage",
"{",
"Axis",
":",
"XAxis",
",",
"Value",
":",
"trackToX",
",",
"Incremental",
":",
"false",
"}",
")",
"\n",
"engo",
".",
"Mailbox",
".",
"Dispatch",
"(",
"CameraMessage",
"{",
"Axis",
":",
"YAxis",
",",
"Value",
":",
"trackToY",
",",
"Incremental",
":",
"false",
"}",
")",
"\n",
"if",
"c",
".",
"Rotation",
"{",
"engo",
".",
"Mailbox",
".",
"Dispatch",
"(",
"CameraMessage",
"{",
"Axis",
":",
"Angle",
",",
"Value",
":",
"c",
".",
"SpaceComponent",
".",
"Rotation",
",",
"Incremental",
":",
"false",
"}",
")",
"\n",
"}",
"\n",
"}"
]
| // Update moves the camera to the center of the space component.
// Values are automatically clamped to TrackingBounds by the camera. | [
"Update",
"moves",
"the",
"camera",
"to",
"the",
"center",
"of",
"the",
"space",
"component",
".",
"Values",
"are",
"automatically",
"clamped",
"to",
"TrackingBounds",
"by",
"the",
"camera",
"."
]
| 6f88a7379a25d81e976cf6e86ea3617f3b480b1a | https://github.com/EngoEngine/engo/blob/6f88a7379a25d81e976cf6e86ea3617f3b480b1a/common/camera.go#L388-L404 |
12,771 | EngoEngine/engo | common/camera.go | Update | func (c *MouseZoomer) Update(float32) {
if engo.Input.Mouse.ScrollY != 0 {
engo.Mailbox.Dispatch(CameraMessage{Axis: ZAxis, Value: engo.Input.Mouse.ScrollY * c.ZoomSpeed, Incremental: true})
}
} | go | func (c *MouseZoomer) Update(float32) {
if engo.Input.Mouse.ScrollY != 0 {
engo.Mailbox.Dispatch(CameraMessage{Axis: ZAxis, Value: engo.Input.Mouse.ScrollY * c.ZoomSpeed, Incremental: true})
}
} | [
"func",
"(",
"c",
"*",
"MouseZoomer",
")",
"Update",
"(",
"float32",
")",
"{",
"if",
"engo",
".",
"Input",
".",
"Mouse",
".",
"ScrollY",
"!=",
"0",
"{",
"engo",
".",
"Mailbox",
".",
"Dispatch",
"(",
"CameraMessage",
"{",
"Axis",
":",
"ZAxis",
",",
"Value",
":",
"engo",
".",
"Input",
".",
"Mouse",
".",
"ScrollY",
"*",
"c",
".",
"ZoomSpeed",
",",
"Incremental",
":",
"true",
"}",
")",
"\n",
"}",
"\n",
"}"
]
| // Update zooms the camera in and out based on the movement of the scroll wheel. | [
"Update",
"zooms",
"the",
"camera",
"in",
"and",
"out",
"based",
"on",
"the",
"movement",
"of",
"the",
"scroll",
"wheel",
"."
]
| 6f88a7379a25d81e976cf6e86ea3617f3b480b1a | https://github.com/EngoEngine/engo/blob/6f88a7379a25d81e976cf6e86ea3617f3b480b1a/common/camera.go#L467-L471 |
12,772 | EngoEngine/engo | common/camera.go | Update | func (c *MouseRotator) Update(float32) {
if engo.Input.Mouse.Button == engo.MouseButtonMiddle && engo.Input.Mouse.Action == engo.Press {
c.pressed = true
}
if engo.Input.Mouse.Action == engo.Release {
c.pressed = false
}
if c.pressed {
engo.Mailbox.Dispatch(CameraMessage{Axis: Angle, Value: (c.oldX - engo.Input.Mouse.X) * -c.RotationSpeed, Incremental: true})
}
c.oldX = engo.Input.Mouse.X
} | go | func (c *MouseRotator) Update(float32) {
if engo.Input.Mouse.Button == engo.MouseButtonMiddle && engo.Input.Mouse.Action == engo.Press {
c.pressed = true
}
if engo.Input.Mouse.Action == engo.Release {
c.pressed = false
}
if c.pressed {
engo.Mailbox.Dispatch(CameraMessage{Axis: Angle, Value: (c.oldX - engo.Input.Mouse.X) * -c.RotationSpeed, Incremental: true})
}
c.oldX = engo.Input.Mouse.X
} | [
"func",
"(",
"c",
"*",
"MouseRotator",
")",
"Update",
"(",
"float32",
")",
"{",
"if",
"engo",
".",
"Input",
".",
"Mouse",
".",
"Button",
"==",
"engo",
".",
"MouseButtonMiddle",
"&&",
"engo",
".",
"Input",
".",
"Mouse",
".",
"Action",
"==",
"engo",
".",
"Press",
"{",
"c",
".",
"pressed",
"=",
"true",
"\n",
"}",
"\n\n",
"if",
"engo",
".",
"Input",
".",
"Mouse",
".",
"Action",
"==",
"engo",
".",
"Release",
"{",
"c",
".",
"pressed",
"=",
"false",
"\n",
"}",
"\n\n",
"if",
"c",
".",
"pressed",
"{",
"engo",
".",
"Mailbox",
".",
"Dispatch",
"(",
"CameraMessage",
"{",
"Axis",
":",
"Angle",
",",
"Value",
":",
"(",
"c",
".",
"oldX",
"-",
"engo",
".",
"Input",
".",
"Mouse",
".",
"X",
")",
"*",
"-",
"c",
".",
"RotationSpeed",
",",
"Incremental",
":",
"true",
"}",
")",
"\n",
"}",
"\n\n",
"c",
".",
"oldX",
"=",
"engo",
".",
"Input",
".",
"Mouse",
".",
"X",
"\n",
"}"
]
| // Update rotates the camera if the scroll wheel is pressed down. | [
"Update",
"rotates",
"the",
"camera",
"if",
"the",
"scroll",
"wheel",
"is",
"pressed",
"down",
"."
]
| 6f88a7379a25d81e976cf6e86ea3617f3b480b1a | https://github.com/EngoEngine/engo/blob/6f88a7379a25d81e976cf6e86ea3617f3b480b1a/common/camera.go#L492-L506 |
12,773 | EngoEngine/engo | common/collision.go | Corners | func (sc SpaceComponent) Corners() (points [4]engo.Point) {
points[0].X = sc.Position.X
points[0].Y = sc.Position.Y
sin, cos := math.Sincos(sc.Rotation * math.Pi / 180)
points[1].X = points[0].X + sc.Width*cos
points[1].Y = points[0].Y + sc.Width*sin
points[2].X = points[0].X - sc.Height*sin
points[2].Y = points[0].Y + sc.Height*cos
points[3].X = points[0].X + sc.Width*cos - sc.Height*sin
points[3].Y = points[0].Y + sc.Height*cos + sc.Width*sin
return
} | go | func (sc SpaceComponent) Corners() (points [4]engo.Point) {
points[0].X = sc.Position.X
points[0].Y = sc.Position.Y
sin, cos := math.Sincos(sc.Rotation * math.Pi / 180)
points[1].X = points[0].X + sc.Width*cos
points[1].Y = points[0].Y + sc.Width*sin
points[2].X = points[0].X - sc.Height*sin
points[2].Y = points[0].Y + sc.Height*cos
points[3].X = points[0].X + sc.Width*cos - sc.Height*sin
points[3].Y = points[0].Y + sc.Height*cos + sc.Width*sin
return
} | [
"func",
"(",
"sc",
"SpaceComponent",
")",
"Corners",
"(",
")",
"(",
"points",
"[",
"4",
"]",
"engo",
".",
"Point",
")",
"{",
"points",
"[",
"0",
"]",
".",
"X",
"=",
"sc",
".",
"Position",
".",
"X",
"\n",
"points",
"[",
"0",
"]",
".",
"Y",
"=",
"sc",
".",
"Position",
".",
"Y",
"\n\n",
"sin",
",",
"cos",
":=",
"math",
".",
"Sincos",
"(",
"sc",
".",
"Rotation",
"*",
"math",
".",
"Pi",
"/",
"180",
")",
"\n\n",
"points",
"[",
"1",
"]",
".",
"X",
"=",
"points",
"[",
"0",
"]",
".",
"X",
"+",
"sc",
".",
"Width",
"*",
"cos",
"\n",
"points",
"[",
"1",
"]",
".",
"Y",
"=",
"points",
"[",
"0",
"]",
".",
"Y",
"+",
"sc",
".",
"Width",
"*",
"sin",
"\n\n",
"points",
"[",
"2",
"]",
".",
"X",
"=",
"points",
"[",
"0",
"]",
".",
"X",
"-",
"sc",
".",
"Height",
"*",
"sin",
"\n",
"points",
"[",
"2",
"]",
".",
"Y",
"=",
"points",
"[",
"0",
"]",
".",
"Y",
"+",
"sc",
".",
"Height",
"*",
"cos",
"\n\n",
"points",
"[",
"3",
"]",
".",
"X",
"=",
"points",
"[",
"0",
"]",
".",
"X",
"+",
"sc",
".",
"Width",
"*",
"cos",
"-",
"sc",
".",
"Height",
"*",
"sin",
"\n",
"points",
"[",
"3",
"]",
".",
"Y",
"=",
"points",
"[",
"0",
"]",
".",
"Y",
"+",
"sc",
".",
"Height",
"*",
"cos",
"+",
"sc",
".",
"Width",
"*",
"sin",
"\n\n",
"return",
"\n",
"}"
]
| // Corners returns the location of the four corners of the rectangular plane defined by the `SpaceComponent`, taking
// into account any possible rotation. | [
"Corners",
"returns",
"the",
"location",
"of",
"the",
"four",
"corners",
"of",
"the",
"rectangular",
"plane",
"defined",
"by",
"the",
"SpaceComponent",
"taking",
"into",
"account",
"any",
"possible",
"rotation",
"."
]
| 6f88a7379a25d81e976cf6e86ea3617f3b480b1a | https://github.com/EngoEngine/engo/blob/6f88a7379a25d81e976cf6e86ea3617f3b480b1a/common/collision.go#L122-L138 |
12,774 | EngoEngine/engo | common/collision.go | triangleArea | func triangleArea(p1, p2, p3 engo.Point) float32 {
// Law of cosines states: (note a2 = math.Pow(a, 2))
// a2 = b2 + c2 - 2bc*cos(alpha)
// This ends in: alpha = arccos ((-a2 + b2 + c2)/(2bc))
a := p1.PointDistance(p3)
b := p1.PointDistance(p2)
c := p2.PointDistance(p3)
alpha := math.Acos((-math.Pow(a, 2) + math.Pow(b, 2) + math.Pow(c, 2)) / (2 * b * c))
// Law of sines state: a / sin(alpha) = c / sin(gamma)
height := (c / math.Sin(math.Pi/2)) * math.Sin(alpha)
return (b * height) / 2
} | go | func triangleArea(p1, p2, p3 engo.Point) float32 {
// Law of cosines states: (note a2 = math.Pow(a, 2))
// a2 = b2 + c2 - 2bc*cos(alpha)
// This ends in: alpha = arccos ((-a2 + b2 + c2)/(2bc))
a := p1.PointDistance(p3)
b := p1.PointDistance(p2)
c := p2.PointDistance(p3)
alpha := math.Acos((-math.Pow(a, 2) + math.Pow(b, 2) + math.Pow(c, 2)) / (2 * b * c))
// Law of sines state: a / sin(alpha) = c / sin(gamma)
height := (c / math.Sin(math.Pi/2)) * math.Sin(alpha)
return (b * height) / 2
} | [
"func",
"triangleArea",
"(",
"p1",
",",
"p2",
",",
"p3",
"engo",
".",
"Point",
")",
"float32",
"{",
"// Law of cosines states: (note a2 = math.Pow(a, 2))",
"// a2 = b2 + c2 - 2bc*cos(alpha)",
"// This ends in: alpha = arccos ((-a2 + b2 + c2)/(2bc))",
"a",
":=",
"p1",
".",
"PointDistance",
"(",
"p3",
")",
"\n",
"b",
":=",
"p1",
".",
"PointDistance",
"(",
"p2",
")",
"\n",
"c",
":=",
"p2",
".",
"PointDistance",
"(",
"p3",
")",
"\n",
"alpha",
":=",
"math",
".",
"Acos",
"(",
"(",
"-",
"math",
".",
"Pow",
"(",
"a",
",",
"2",
")",
"+",
"math",
".",
"Pow",
"(",
"b",
",",
"2",
")",
"+",
"math",
".",
"Pow",
"(",
"c",
",",
"2",
")",
")",
"/",
"(",
"2",
"*",
"b",
"*",
"c",
")",
")",
"\n\n",
"// Law of sines state: a / sin(alpha) = c / sin(gamma)",
"height",
":=",
"(",
"c",
"/",
"math",
".",
"Sin",
"(",
"math",
".",
"Pi",
"/",
"2",
")",
")",
"*",
"math",
".",
"Sin",
"(",
"alpha",
")",
"\n\n",
"return",
"(",
"b",
"*",
"height",
")",
"/",
"2",
"\n",
"}"
]
| // triangleArea computes the area of the triangle given by the three points | [
"triangleArea",
"computes",
"the",
"area",
"of",
"the",
"triangle",
"given",
"by",
"the",
"three",
"points"
]
| 6f88a7379a25d81e976cf6e86ea3617f3b480b1a | https://github.com/EngoEngine/engo/blob/6f88a7379a25d81e976cf6e86ea3617f3b480b1a/common/collision.go#L209-L222 |
12,775 | EngoEngine/engo | common/collision.go | Add | func (c *CollisionSystem) Add(basic *ecs.BasicEntity, collision *CollisionComponent, space *SpaceComponent) {
c.entities = append(c.entities, collisionEntity{basic, collision, space})
} | go | func (c *CollisionSystem) Add(basic *ecs.BasicEntity, collision *CollisionComponent, space *SpaceComponent) {
c.entities = append(c.entities, collisionEntity{basic, collision, space})
} | [
"func",
"(",
"c",
"*",
"CollisionSystem",
")",
"Add",
"(",
"basic",
"*",
"ecs",
".",
"BasicEntity",
",",
"collision",
"*",
"CollisionComponent",
",",
"space",
"*",
"SpaceComponent",
")",
"{",
"c",
".",
"entities",
"=",
"append",
"(",
"c",
".",
"entities",
",",
"collisionEntity",
"{",
"basic",
",",
"collision",
",",
"space",
"}",
")",
"\n",
"}"
]
| // Add adds an entity to the CollisionSystem. To be added, the entity has to have a basic, collision, and space component. | [
"Add",
"adds",
"an",
"entity",
"to",
"the",
"CollisionSystem",
".",
"To",
"be",
"added",
"the",
"entity",
"has",
"to",
"have",
"a",
"basic",
"collision",
"and",
"space",
"component",
"."
]
| 6f88a7379a25d81e976cf6e86ea3617f3b480b1a | https://github.com/EngoEngine/engo/blob/6f88a7379a25d81e976cf6e86ea3617f3b480b1a/common/collision.go#L273-L275 |
12,776 | EngoEngine/engo | common/collision.go | AddByInterface | func (c *CollisionSystem) AddByInterface(i ecs.Identifier) {
o, _ := i.(Collisionable)
c.Add(o.GetBasicEntity(), o.GetCollisionComponent(), o.GetSpaceComponent())
} | go | func (c *CollisionSystem) AddByInterface(i ecs.Identifier) {
o, _ := i.(Collisionable)
c.Add(o.GetBasicEntity(), o.GetCollisionComponent(), o.GetSpaceComponent())
} | [
"func",
"(",
"c",
"*",
"CollisionSystem",
")",
"AddByInterface",
"(",
"i",
"ecs",
".",
"Identifier",
")",
"{",
"o",
",",
"_",
":=",
"i",
".",
"(",
"Collisionable",
")",
"\n",
"c",
".",
"Add",
"(",
"o",
".",
"GetBasicEntity",
"(",
")",
",",
"o",
".",
"GetCollisionComponent",
"(",
")",
",",
"o",
".",
"GetSpaceComponent",
"(",
")",
")",
"\n",
"}"
]
| // AddByInterface Provides a simple way to add an entity to the system that satisfies Collisionable. Any entity containing, BasicEntity,CollisionComponent, and SpaceComponent anonymously, automatically does this. | [
"AddByInterface",
"Provides",
"a",
"simple",
"way",
"to",
"add",
"an",
"entity",
"to",
"the",
"system",
"that",
"satisfies",
"Collisionable",
".",
"Any",
"entity",
"containing",
"BasicEntity",
"CollisionComponent",
"and",
"SpaceComponent",
"anonymously",
"automatically",
"does",
"this",
"."
]
| 6f88a7379a25d81e976cf6e86ea3617f3b480b1a | https://github.com/EngoEngine/engo/blob/6f88a7379a25d81e976cf6e86ea3617f3b480b1a/common/collision.go#L278-L281 |
12,777 | EngoEngine/engo | common/collision.go | IsIntersecting | func IsIntersecting(rect1 engo.AABB, rect2 engo.AABB) bool {
if rect1.Max.X > rect2.Min.X && rect1.Min.X < rect2.Max.X && rect1.Max.Y > rect2.Min.Y && rect1.Min.Y < rect2.Max.Y {
return true
}
return false
} | go | func IsIntersecting(rect1 engo.AABB, rect2 engo.AABB) bool {
if rect1.Max.X > rect2.Min.X && rect1.Min.X < rect2.Max.X && rect1.Max.Y > rect2.Min.Y && rect1.Min.Y < rect2.Max.Y {
return true
}
return false
} | [
"func",
"IsIntersecting",
"(",
"rect1",
"engo",
".",
"AABB",
",",
"rect2",
"engo",
".",
"AABB",
")",
"bool",
"{",
"if",
"rect1",
".",
"Max",
".",
"X",
">",
"rect2",
".",
"Min",
".",
"X",
"&&",
"rect1",
".",
"Min",
".",
"X",
"<",
"rect2",
".",
"Max",
".",
"X",
"&&",
"rect1",
".",
"Max",
".",
"Y",
">",
"rect2",
".",
"Min",
".",
"Y",
"&&",
"rect1",
".",
"Min",
".",
"Y",
"<",
"rect2",
".",
"Max",
".",
"Y",
"{",
"return",
"true",
"\n",
"}",
"\n\n",
"return",
"false",
"\n",
"}"
]
| // IsIntersecting tells if two engo.AABBs intersect. | [
"IsIntersecting",
"tells",
"if",
"two",
"engo",
".",
"AABBs",
"intersect",
"."
]
| 6f88a7379a25d81e976cf6e86ea3617f3b480b1a | https://github.com/EngoEngine/engo/blob/6f88a7379a25d81e976cf6e86ea3617f3b480b1a/common/collision.go#L369-L375 |
12,778 | EngoEngine/engo | common/collision.go | MinimumTranslation | func MinimumTranslation(rect1 engo.AABB, rect2 engo.AABB) engo.Point {
mtd := engo.Point{}
left := rect2.Min.X - rect1.Max.X
right := rect2.Max.X - rect1.Min.X
top := rect2.Min.Y - rect1.Max.Y
bottom := rect2.Max.Y - rect1.Min.Y
if left > 0 || right < 0 {
log.Println("Box aint intercepting")
return mtd
//box doesn't intercept
}
if top > 0 || bottom < 0 {
log.Println("Box aint intercepting")
return mtd
//box doesn't intercept
}
if math.Abs(left) < right {
mtd.X = left
} else {
mtd.X = right
}
if math.Abs(top) < bottom {
mtd.Y = top
} else {
mtd.Y = bottom
}
if math.Abs(mtd.X) < math.Abs(mtd.Y) {
mtd.Y = 0
} else {
mtd.X = 0
}
return mtd
} | go | func MinimumTranslation(rect1 engo.AABB, rect2 engo.AABB) engo.Point {
mtd := engo.Point{}
left := rect2.Min.X - rect1.Max.X
right := rect2.Max.X - rect1.Min.X
top := rect2.Min.Y - rect1.Max.Y
bottom := rect2.Max.Y - rect1.Min.Y
if left > 0 || right < 0 {
log.Println("Box aint intercepting")
return mtd
//box doesn't intercept
}
if top > 0 || bottom < 0 {
log.Println("Box aint intercepting")
return mtd
//box doesn't intercept
}
if math.Abs(left) < right {
mtd.X = left
} else {
mtd.X = right
}
if math.Abs(top) < bottom {
mtd.Y = top
} else {
mtd.Y = bottom
}
if math.Abs(mtd.X) < math.Abs(mtd.Y) {
mtd.Y = 0
} else {
mtd.X = 0
}
return mtd
} | [
"func",
"MinimumTranslation",
"(",
"rect1",
"engo",
".",
"AABB",
",",
"rect2",
"engo",
".",
"AABB",
")",
"engo",
".",
"Point",
"{",
"mtd",
":=",
"engo",
".",
"Point",
"{",
"}",
"\n\n",
"left",
":=",
"rect2",
".",
"Min",
".",
"X",
"-",
"rect1",
".",
"Max",
".",
"X",
"\n",
"right",
":=",
"rect2",
".",
"Max",
".",
"X",
"-",
"rect1",
".",
"Min",
".",
"X",
"\n",
"top",
":=",
"rect2",
".",
"Min",
".",
"Y",
"-",
"rect1",
".",
"Max",
".",
"Y",
"\n",
"bottom",
":=",
"rect2",
".",
"Max",
".",
"Y",
"-",
"rect1",
".",
"Min",
".",
"Y",
"\n\n",
"if",
"left",
">",
"0",
"||",
"right",
"<",
"0",
"{",
"log",
".",
"Println",
"(",
"\"",
"\"",
")",
"\n",
"return",
"mtd",
"\n",
"//box doesn't intercept",
"}",
"\n\n",
"if",
"top",
">",
"0",
"||",
"bottom",
"<",
"0",
"{",
"log",
".",
"Println",
"(",
"\"",
"\"",
")",
"\n",
"return",
"mtd",
"\n",
"//box doesn't intercept",
"}",
"\n",
"if",
"math",
".",
"Abs",
"(",
"left",
")",
"<",
"right",
"{",
"mtd",
".",
"X",
"=",
"left",
"\n",
"}",
"else",
"{",
"mtd",
".",
"X",
"=",
"right",
"\n",
"}",
"\n\n",
"if",
"math",
".",
"Abs",
"(",
"top",
")",
"<",
"bottom",
"{",
"mtd",
".",
"Y",
"=",
"top",
"\n",
"}",
"else",
"{",
"mtd",
".",
"Y",
"=",
"bottom",
"\n",
"}",
"\n\n",
"if",
"math",
".",
"Abs",
"(",
"mtd",
".",
"X",
")",
"<",
"math",
".",
"Abs",
"(",
"mtd",
".",
"Y",
")",
"{",
"mtd",
".",
"Y",
"=",
"0",
"\n",
"}",
"else",
"{",
"mtd",
".",
"X",
"=",
"0",
"\n",
"}",
"\n\n",
"return",
"mtd",
"\n",
"}"
]
| // MinimumTranslation tells how much an entity has to move to no longer overlap another entity. | [
"MinimumTranslation",
"tells",
"how",
"much",
"an",
"entity",
"has",
"to",
"move",
"to",
"no",
"longer",
"overlap",
"another",
"entity",
"."
]
| 6f88a7379a25d81e976cf6e86ea3617f3b480b1a | https://github.com/EngoEngine/engo/blob/6f88a7379a25d81e976cf6e86ea3617f3b480b1a/common/collision.go#L378-L416 |
12,779 | hashicorp/raft-mdb | mdb_store.go | NewMDBStoreWithSize | func NewMDBStoreWithSize(base string, maxSize uint64) (*MDBStore, error) {
// Get the paths
path := filepath.Join(base, mdbPath)
if err := os.MkdirAll(path, 0755); err != nil {
return nil, err
}
// Set the maxSize if not given
if maxSize == 0 {
maxSize = dbMaxMapSize
}
// Create the env
env, err := mdb.NewEnv()
if err != nil {
return nil, err
}
// Create the struct
store := &MDBStore{
env: env,
path: path,
maxSize: maxSize,
}
// Initialize the db
if err := store.initialize(); err != nil {
env.Close()
return nil, err
}
return store, nil
} | go | func NewMDBStoreWithSize(base string, maxSize uint64) (*MDBStore, error) {
// Get the paths
path := filepath.Join(base, mdbPath)
if err := os.MkdirAll(path, 0755); err != nil {
return nil, err
}
// Set the maxSize if not given
if maxSize == 0 {
maxSize = dbMaxMapSize
}
// Create the env
env, err := mdb.NewEnv()
if err != nil {
return nil, err
}
// Create the struct
store := &MDBStore{
env: env,
path: path,
maxSize: maxSize,
}
// Initialize the db
if err := store.initialize(); err != nil {
env.Close()
return nil, err
}
return store, nil
} | [
"func",
"NewMDBStoreWithSize",
"(",
"base",
"string",
",",
"maxSize",
"uint64",
")",
"(",
"*",
"MDBStore",
",",
"error",
")",
"{",
"// Get the paths",
"path",
":=",
"filepath",
".",
"Join",
"(",
"base",
",",
"mdbPath",
")",
"\n",
"if",
"err",
":=",
"os",
".",
"MkdirAll",
"(",
"path",
",",
"0755",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"// Set the maxSize if not given",
"if",
"maxSize",
"==",
"0",
"{",
"maxSize",
"=",
"dbMaxMapSize",
"\n",
"}",
"\n\n",
"// Create the env",
"env",
",",
"err",
":=",
"mdb",
".",
"NewEnv",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"// Create the struct",
"store",
":=",
"&",
"MDBStore",
"{",
"env",
":",
"env",
",",
"path",
":",
"path",
",",
"maxSize",
":",
"maxSize",
",",
"}",
"\n\n",
"// Initialize the db",
"if",
"err",
":=",
"store",
".",
"initialize",
"(",
")",
";",
"err",
"!=",
"nil",
"{",
"env",
".",
"Close",
"(",
")",
"\n",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"return",
"store",
",",
"nil",
"\n",
"}"
]
| // NewMDBStore returns a new MDBStore and potential
// error. Requres a base directory from which to operate,
// and a maximum size. If maxSize is not 0, a default value is used. | [
"NewMDBStore",
"returns",
"a",
"new",
"MDBStore",
"and",
"potential",
"error",
".",
"Requres",
"a",
"base",
"directory",
"from",
"which",
"to",
"operate",
"and",
"a",
"maximum",
"size",
".",
"If",
"maxSize",
"is",
"not",
"0",
"a",
"default",
"value",
"is",
"used",
"."
]
| 9ee9663b6ffaec215bb1f71a20bb6018225f9521 | https://github.com/hashicorp/raft-mdb/blob/9ee9663b6ffaec215bb1f71a20bb6018225f9521/mdb_store.go#L38-L69 |
12,780 | hashicorp/raft-mdb | mdb_store.go | initialize | func (m *MDBStore) initialize() error {
// Allow up to 2 sub-dbs
if err := m.env.SetMaxDBs(mdb.DBI(2)); err != nil {
return err
}
// Increase the maximum map size
if err := m.env.SetMapSize(m.maxSize); err != nil {
return err
}
// Open the DB
if err := m.env.Open(m.path, mdb.NOTLS, 0755); err != nil {
return err
}
// Create all the tables
tx, _, err := m.startTxn(false, dbLogs, dbConf)
if err != nil {
tx.Abort()
return err
}
return tx.Commit()
} | go | func (m *MDBStore) initialize() error {
// Allow up to 2 sub-dbs
if err := m.env.SetMaxDBs(mdb.DBI(2)); err != nil {
return err
}
// Increase the maximum map size
if err := m.env.SetMapSize(m.maxSize); err != nil {
return err
}
// Open the DB
if err := m.env.Open(m.path, mdb.NOTLS, 0755); err != nil {
return err
}
// Create all the tables
tx, _, err := m.startTxn(false, dbLogs, dbConf)
if err != nil {
tx.Abort()
return err
}
return tx.Commit()
} | [
"func",
"(",
"m",
"*",
"MDBStore",
")",
"initialize",
"(",
")",
"error",
"{",
"// Allow up to 2 sub-dbs",
"if",
"err",
":=",
"m",
".",
"env",
".",
"SetMaxDBs",
"(",
"mdb",
".",
"DBI",
"(",
"2",
")",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n\n",
"// Increase the maximum map size",
"if",
"err",
":=",
"m",
".",
"env",
".",
"SetMapSize",
"(",
"m",
".",
"maxSize",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n\n",
"// Open the DB",
"if",
"err",
":=",
"m",
".",
"env",
".",
"Open",
"(",
"m",
".",
"path",
",",
"mdb",
".",
"NOTLS",
",",
"0755",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n\n",
"// Create all the tables",
"tx",
",",
"_",
",",
"err",
":=",
"m",
".",
"startTxn",
"(",
"false",
",",
"dbLogs",
",",
"dbConf",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"tx",
".",
"Abort",
"(",
")",
"\n",
"return",
"err",
"\n",
"}",
"\n",
"return",
"tx",
".",
"Commit",
"(",
")",
"\n",
"}"
]
| // initialize is used to setup the mdb store | [
"initialize",
"is",
"used",
"to",
"setup",
"the",
"mdb",
"store"
]
| 9ee9663b6ffaec215bb1f71a20bb6018225f9521 | https://github.com/hashicorp/raft-mdb/blob/9ee9663b6ffaec215bb1f71a20bb6018225f9521/mdb_store.go#L72-L95 |
12,781 | hashicorp/raft-mdb | mdb_store.go | startTxn | func (m *MDBStore) startTxn(readonly bool, open ...string) (*mdb.Txn, []mdb.DBI, error) {
var txFlags uint = 0
var dbFlags uint = 0
if readonly {
txFlags |= mdb.RDONLY
} else {
dbFlags |= mdb.CREATE
}
tx, err := m.env.BeginTxn(nil, txFlags)
if err != nil {
return nil, nil, err
}
var dbs []mdb.DBI
for _, name := range open {
dbi, err := tx.DBIOpen(name, dbFlags)
if err != nil {
tx.Abort()
return nil, nil, err
}
dbs = append(dbs, dbi)
}
return tx, dbs, nil
} | go | func (m *MDBStore) startTxn(readonly bool, open ...string) (*mdb.Txn, []mdb.DBI, error) {
var txFlags uint = 0
var dbFlags uint = 0
if readonly {
txFlags |= mdb.RDONLY
} else {
dbFlags |= mdb.CREATE
}
tx, err := m.env.BeginTxn(nil, txFlags)
if err != nil {
return nil, nil, err
}
var dbs []mdb.DBI
for _, name := range open {
dbi, err := tx.DBIOpen(name, dbFlags)
if err != nil {
tx.Abort()
return nil, nil, err
}
dbs = append(dbs, dbi)
}
return tx, dbs, nil
} | [
"func",
"(",
"m",
"*",
"MDBStore",
")",
"startTxn",
"(",
"readonly",
"bool",
",",
"open",
"...",
"string",
")",
"(",
"*",
"mdb",
".",
"Txn",
",",
"[",
"]",
"mdb",
".",
"DBI",
",",
"error",
")",
"{",
"var",
"txFlags",
"uint",
"=",
"0",
"\n",
"var",
"dbFlags",
"uint",
"=",
"0",
"\n",
"if",
"readonly",
"{",
"txFlags",
"|=",
"mdb",
".",
"RDONLY",
"\n",
"}",
"else",
"{",
"dbFlags",
"|=",
"mdb",
".",
"CREATE",
"\n",
"}",
"\n\n",
"tx",
",",
"err",
":=",
"m",
".",
"env",
".",
"BeginTxn",
"(",
"nil",
",",
"txFlags",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"var",
"dbs",
"[",
"]",
"mdb",
".",
"DBI",
"\n",
"for",
"_",
",",
"name",
":=",
"range",
"open",
"{",
"dbi",
",",
"err",
":=",
"tx",
".",
"DBIOpen",
"(",
"name",
",",
"dbFlags",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"tx",
".",
"Abort",
"(",
")",
"\n",
"return",
"nil",
",",
"nil",
",",
"err",
"\n",
"}",
"\n",
"dbs",
"=",
"append",
"(",
"dbs",
",",
"dbi",
")",
"\n",
"}",
"\n\n",
"return",
"tx",
",",
"dbs",
",",
"nil",
"\n",
"}"
]
| // startTxn is used to start a transaction and open all the associated sub-databases | [
"startTxn",
"is",
"used",
"to",
"start",
"a",
"transaction",
"and",
"open",
"all",
"the",
"associated",
"sub",
"-",
"databases"
]
| 9ee9663b6ffaec215bb1f71a20bb6018225f9521 | https://github.com/hashicorp/raft-mdb/blob/9ee9663b6ffaec215bb1f71a20bb6018225f9521/mdb_store.go#L104-L129 |
12,782 | hashicorp/raft-mdb | mdb_store.go | GetLog | func (m *MDBStore) GetLog(index uint64, logOut *raft.Log) error {
key := uint64ToBytes(index)
tx, dbis, err := m.startTxn(true, dbLogs)
if err != nil {
return err
}
defer tx.Abort()
val, err := tx.Get(dbis[0], key)
if err == mdb.NotFound {
return raft.ErrLogNotFound
} else if err != nil {
return err
}
// Convert the value to a log
return decodeMsgPack(val, logOut)
} | go | func (m *MDBStore) GetLog(index uint64, logOut *raft.Log) error {
key := uint64ToBytes(index)
tx, dbis, err := m.startTxn(true, dbLogs)
if err != nil {
return err
}
defer tx.Abort()
val, err := tx.Get(dbis[0], key)
if err == mdb.NotFound {
return raft.ErrLogNotFound
} else if err != nil {
return err
}
// Convert the value to a log
return decodeMsgPack(val, logOut)
} | [
"func",
"(",
"m",
"*",
"MDBStore",
")",
"GetLog",
"(",
"index",
"uint64",
",",
"logOut",
"*",
"raft",
".",
"Log",
")",
"error",
"{",
"key",
":=",
"uint64ToBytes",
"(",
"index",
")",
"\n\n",
"tx",
",",
"dbis",
",",
"err",
":=",
"m",
".",
"startTxn",
"(",
"true",
",",
"dbLogs",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"defer",
"tx",
".",
"Abort",
"(",
")",
"\n\n",
"val",
",",
"err",
":=",
"tx",
".",
"Get",
"(",
"dbis",
"[",
"0",
"]",
",",
"key",
")",
"\n",
"if",
"err",
"==",
"mdb",
".",
"NotFound",
"{",
"return",
"raft",
".",
"ErrLogNotFound",
"\n",
"}",
"else",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n\n",
"// Convert the value to a log",
"return",
"decodeMsgPack",
"(",
"val",
",",
"logOut",
")",
"\n",
"}"
]
| // Gets a log entry at a given index | [
"Gets",
"a",
"log",
"entry",
"at",
"a",
"given",
"index"
]
| 9ee9663b6ffaec215bb1f71a20bb6018225f9521 | https://github.com/hashicorp/raft-mdb/blob/9ee9663b6ffaec215bb1f71a20bb6018225f9521/mdb_store.go#L180-L198 |
12,783 | hashicorp/raft-mdb | mdb_store.go | StoreLog | func (m *MDBStore) StoreLog(log *raft.Log) error {
return m.StoreLogs([]*raft.Log{log})
} | go | func (m *MDBStore) StoreLog(log *raft.Log) error {
return m.StoreLogs([]*raft.Log{log})
} | [
"func",
"(",
"m",
"*",
"MDBStore",
")",
"StoreLog",
"(",
"log",
"*",
"raft",
".",
"Log",
")",
"error",
"{",
"return",
"m",
".",
"StoreLogs",
"(",
"[",
"]",
"*",
"raft",
".",
"Log",
"{",
"log",
"}",
")",
"\n",
"}"
]
| // Stores a log entry | [
"Stores",
"a",
"log",
"entry"
]
| 9ee9663b6ffaec215bb1f71a20bb6018225f9521 | https://github.com/hashicorp/raft-mdb/blob/9ee9663b6ffaec215bb1f71a20bb6018225f9521/mdb_store.go#L201-L203 |
12,784 | hashicorp/raft-mdb | mdb_store.go | StoreLogs | func (m *MDBStore) StoreLogs(logs []*raft.Log) error {
// Start write txn
tx, dbis, err := m.startTxn(false, dbLogs)
if err != nil {
return err
}
for _, log := range logs {
// Convert to an on-disk format
key := uint64ToBytes(log.Index)
val, err := encodeMsgPack(log)
if err != nil {
tx.Abort()
return err
}
// Write to the table
if err := tx.Put(dbis[0], key, val.Bytes(), 0); err != nil {
tx.Abort()
return err
}
}
return tx.Commit()
} | go | func (m *MDBStore) StoreLogs(logs []*raft.Log) error {
// Start write txn
tx, dbis, err := m.startTxn(false, dbLogs)
if err != nil {
return err
}
for _, log := range logs {
// Convert to an on-disk format
key := uint64ToBytes(log.Index)
val, err := encodeMsgPack(log)
if err != nil {
tx.Abort()
return err
}
// Write to the table
if err := tx.Put(dbis[0], key, val.Bytes(), 0); err != nil {
tx.Abort()
return err
}
}
return tx.Commit()
} | [
"func",
"(",
"m",
"*",
"MDBStore",
")",
"StoreLogs",
"(",
"logs",
"[",
"]",
"*",
"raft",
".",
"Log",
")",
"error",
"{",
"// Start write txn",
"tx",
",",
"dbis",
",",
"err",
":=",
"m",
".",
"startTxn",
"(",
"false",
",",
"dbLogs",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n\n",
"for",
"_",
",",
"log",
":=",
"range",
"logs",
"{",
"// Convert to an on-disk format",
"key",
":=",
"uint64ToBytes",
"(",
"log",
".",
"Index",
")",
"\n",
"val",
",",
"err",
":=",
"encodeMsgPack",
"(",
"log",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"tx",
".",
"Abort",
"(",
")",
"\n",
"return",
"err",
"\n",
"}",
"\n\n",
"// Write to the table",
"if",
"err",
":=",
"tx",
".",
"Put",
"(",
"dbis",
"[",
"0",
"]",
",",
"key",
",",
"val",
".",
"Bytes",
"(",
")",
",",
"0",
")",
";",
"err",
"!=",
"nil",
"{",
"tx",
".",
"Abort",
"(",
")",
"\n",
"return",
"err",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"tx",
".",
"Commit",
"(",
")",
"\n",
"}"
]
| // Stores multiple log entries | [
"Stores",
"multiple",
"log",
"entries"
]
| 9ee9663b6ffaec215bb1f71a20bb6018225f9521 | https://github.com/hashicorp/raft-mdb/blob/9ee9663b6ffaec215bb1f71a20bb6018225f9521/mdb_store.go#L206-L229 |
12,785 | hashicorp/raft-mdb | mdb_store.go | DeleteRange | func (m *MDBStore) DeleteRange(minIdx, maxIdx uint64) error {
// Start write txn
tx, dbis, err := m.startTxn(false, dbLogs)
if err != nil {
return err
}
defer tx.Abort()
// Hack around an LMDB bug by running the delete multiple
// times until there are no further rows.
var num int
DELETE:
num, err = m.innerDeleteRange(tx, dbis, minIdx, maxIdx)
if err != nil {
return err
}
if num > 0 {
goto DELETE
}
return tx.Commit()
} | go | func (m *MDBStore) DeleteRange(minIdx, maxIdx uint64) error {
// Start write txn
tx, dbis, err := m.startTxn(false, dbLogs)
if err != nil {
return err
}
defer tx.Abort()
// Hack around an LMDB bug by running the delete multiple
// times until there are no further rows.
var num int
DELETE:
num, err = m.innerDeleteRange(tx, dbis, minIdx, maxIdx)
if err != nil {
return err
}
if num > 0 {
goto DELETE
}
return tx.Commit()
} | [
"func",
"(",
"m",
"*",
"MDBStore",
")",
"DeleteRange",
"(",
"minIdx",
",",
"maxIdx",
"uint64",
")",
"error",
"{",
"// Start write txn",
"tx",
",",
"dbis",
",",
"err",
":=",
"m",
".",
"startTxn",
"(",
"false",
",",
"dbLogs",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"defer",
"tx",
".",
"Abort",
"(",
")",
"\n\n",
"// Hack around an LMDB bug by running the delete multiple",
"// times until there are no further rows.",
"var",
"num",
"int",
"\n",
"DELETE",
":",
"num",
",",
"err",
"=",
"m",
".",
"innerDeleteRange",
"(",
"tx",
",",
"dbis",
",",
"minIdx",
",",
"maxIdx",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"if",
"num",
">",
"0",
"{",
"goto",
"DELETE",
"\n",
"}",
"\n",
"return",
"tx",
".",
"Commit",
"(",
")",
"\n",
"}"
]
| // Deletes a range of log entries. The range is inclusive. | [
"Deletes",
"a",
"range",
"of",
"log",
"entries",
".",
"The",
"range",
"is",
"inclusive",
"."
]
| 9ee9663b6ffaec215bb1f71a20bb6018225f9521 | https://github.com/hashicorp/raft-mdb/blob/9ee9663b6ffaec215bb1f71a20bb6018225f9521/mdb_store.go#L232-L252 |
12,786 | cloudfoundry/gosigar | psnotify/psnotify.go | NewWatcher | func NewWatcher() (*Watcher, error) {
listener, err := createListener()
if err != nil {
return nil, err
}
w := &Watcher{
listener: listener,
watches: make(map[int]*watch),
watchesMutex: &sync.Mutex{},
Fork: make(chan *ProcEventFork),
Exec: make(chan *ProcEventExec),
Exit: make(chan *ProcEventExit),
Error: make(chan error),
done: make(chan bool, 1),
closedMutex: &sync.Mutex{},
}
go w.readEvents()
return w, nil
} | go | func NewWatcher() (*Watcher, error) {
listener, err := createListener()
if err != nil {
return nil, err
}
w := &Watcher{
listener: listener,
watches: make(map[int]*watch),
watchesMutex: &sync.Mutex{},
Fork: make(chan *ProcEventFork),
Exec: make(chan *ProcEventExec),
Exit: make(chan *ProcEventExit),
Error: make(chan error),
done: make(chan bool, 1),
closedMutex: &sync.Mutex{},
}
go w.readEvents()
return w, nil
} | [
"func",
"NewWatcher",
"(",
")",
"(",
"*",
"Watcher",
",",
"error",
")",
"{",
"listener",
",",
"err",
":=",
"createListener",
"(",
")",
"\n\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"w",
":=",
"&",
"Watcher",
"{",
"listener",
":",
"listener",
",",
"watches",
":",
"make",
"(",
"map",
"[",
"int",
"]",
"*",
"watch",
")",
",",
"watchesMutex",
":",
"&",
"sync",
".",
"Mutex",
"{",
"}",
",",
"Fork",
":",
"make",
"(",
"chan",
"*",
"ProcEventFork",
")",
",",
"Exec",
":",
"make",
"(",
"chan",
"*",
"ProcEventExec",
")",
",",
"Exit",
":",
"make",
"(",
"chan",
"*",
"ProcEventExit",
")",
",",
"Error",
":",
"make",
"(",
"chan",
"error",
")",
",",
"done",
":",
"make",
"(",
"chan",
"bool",
",",
"1",
")",
",",
"closedMutex",
":",
"&",
"sync",
".",
"Mutex",
"{",
"}",
",",
"}",
"\n\n",
"go",
"w",
".",
"readEvents",
"(",
")",
"\n",
"return",
"w",
",",
"nil",
"\n",
"}"
]
| // Initialize event listener and channels | [
"Initialize",
"event",
"listener",
"and",
"channels"
]
| 50ddd08d81d770b1e0ce2c969a46e46c73580e2a | https://github.com/cloudfoundry/gosigar/blob/50ddd08d81d770b1e0ce2c969a46e46c73580e2a/psnotify/psnotify.go#L48-L69 |
12,787 | cloudfoundry/gosigar | psnotify/psnotify.go | finish | func (w *Watcher) finish() {
close(w.Fork)
close(w.Exec)
close(w.Exit)
close(w.Error)
} | go | func (w *Watcher) finish() {
close(w.Fork)
close(w.Exec)
close(w.Exit)
close(w.Error)
} | [
"func",
"(",
"w",
"*",
"Watcher",
")",
"finish",
"(",
")",
"{",
"close",
"(",
"w",
".",
"Fork",
")",
"\n",
"close",
"(",
"w",
".",
"Exec",
")",
"\n",
"close",
"(",
"w",
".",
"Exit",
")",
"\n",
"close",
"(",
"w",
".",
"Error",
")",
"\n",
"}"
]
| // Close event channels when done message is received | [
"Close",
"event",
"channels",
"when",
"done",
"message",
"is",
"received"
]
| 50ddd08d81d770b1e0ce2c969a46e46c73580e2a | https://github.com/cloudfoundry/gosigar/blob/50ddd08d81d770b1e0ce2c969a46e46c73580e2a/psnotify/psnotify.go#L72-L77 |
12,788 | cloudfoundry/gosigar | psnotify/psnotify.go | Close | func (w *Watcher) Close() error {
w.closedMutex.Lock()
defer w.closedMutex.Unlock()
if w.isClosed {
return nil
}
w.isClosed = true
w.watchesMutex.Lock()
for pid := range w.watches {
delete(w.watches, pid)
w.unregister(pid)
}
w.watchesMutex.Unlock()
w.done <- true
w.listener.close()
return nil
} | go | func (w *Watcher) Close() error {
w.closedMutex.Lock()
defer w.closedMutex.Unlock()
if w.isClosed {
return nil
}
w.isClosed = true
w.watchesMutex.Lock()
for pid := range w.watches {
delete(w.watches, pid)
w.unregister(pid)
}
w.watchesMutex.Unlock()
w.done <- true
w.listener.close()
return nil
} | [
"func",
"(",
"w",
"*",
"Watcher",
")",
"Close",
"(",
")",
"error",
"{",
"w",
".",
"closedMutex",
".",
"Lock",
"(",
")",
"\n",
"defer",
"w",
".",
"closedMutex",
".",
"Unlock",
"(",
")",
"\n\n",
"if",
"w",
".",
"isClosed",
"{",
"return",
"nil",
"\n",
"}",
"\n",
"w",
".",
"isClosed",
"=",
"true",
"\n\n",
"w",
".",
"watchesMutex",
".",
"Lock",
"(",
")",
"\n",
"for",
"pid",
":=",
"range",
"w",
".",
"watches",
"{",
"delete",
"(",
"w",
".",
"watches",
",",
"pid",
")",
"\n",
"w",
".",
"unregister",
"(",
"pid",
")",
"\n",
"}",
"\n",
"w",
".",
"watchesMutex",
".",
"Unlock",
"(",
")",
"\n\n",
"w",
".",
"done",
"<-",
"true",
"\n\n",
"w",
".",
"listener",
".",
"close",
"(",
")",
"\n\n",
"return",
"nil",
"\n",
"}"
]
| // Closes the OS specific event listener,
// removes all watches and closes all event channels. | [
"Closes",
"the",
"OS",
"specific",
"event",
"listener",
"removes",
"all",
"watches",
"and",
"closes",
"all",
"event",
"channels",
"."
]
| 50ddd08d81d770b1e0ce2c969a46e46c73580e2a | https://github.com/cloudfoundry/gosigar/blob/50ddd08d81d770b1e0ce2c969a46e46c73580e2a/psnotify/psnotify.go#L81-L102 |
12,789 | cloudfoundry/gosigar | psnotify/psnotify.go | RemoveWatch | func (w *Watcher) RemoveWatch(pid int) error {
w.watchesMutex.Lock()
defer w.watchesMutex.Unlock()
_, ok := w.watches[pid]
if !ok {
msg := fmt.Sprintf("watch for pid=%d does not exist", pid)
return errors.New(msg)
}
delete(w.watches, pid)
return w.unregister(pid)
} | go | func (w *Watcher) RemoveWatch(pid int) error {
w.watchesMutex.Lock()
defer w.watchesMutex.Unlock()
_, ok := w.watches[pid]
if !ok {
msg := fmt.Sprintf("watch for pid=%d does not exist", pid)
return errors.New(msg)
}
delete(w.watches, pid)
return w.unregister(pid)
} | [
"func",
"(",
"w",
"*",
"Watcher",
")",
"RemoveWatch",
"(",
"pid",
"int",
")",
"error",
"{",
"w",
".",
"watchesMutex",
".",
"Lock",
"(",
")",
"\n",
"defer",
"w",
".",
"watchesMutex",
".",
"Unlock",
"(",
")",
"\n\n",
"_",
",",
"ok",
":=",
"w",
".",
"watches",
"[",
"pid",
"]",
"\n",
"if",
"!",
"ok",
"{",
"msg",
":=",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"pid",
")",
"\n",
"return",
"errors",
".",
"New",
"(",
"msg",
")",
"\n",
"}",
"\n",
"delete",
"(",
"w",
".",
"watches",
",",
"pid",
")",
"\n",
"return",
"w",
".",
"unregister",
"(",
"pid",
")",
"\n",
"}"
]
| // Remove pid from the watched process set. | [
"Remove",
"pid",
"from",
"the",
"watched",
"process",
"set",
"."
]
| 50ddd08d81d770b1e0ce2c969a46e46c73580e2a | https://github.com/cloudfoundry/gosigar/blob/50ddd08d81d770b1e0ce2c969a46e46c73580e2a/psnotify/psnotify.go#L134-L145 |
12,790 | cloudfoundry/gosigar | sys/windows/privileges.go | LookupPrivilegeName | func LookupPrivilegeName(systemName string, luid int64) (string, error) {
buf := make([]uint16, 256)
bufSize := uint32(len(buf))
err := _LookupPrivilegeName(systemName, &luid, &buf[0], &bufSize)
if err != nil {
return "", errors.Wrapf(err, "LookupPrivilegeName failed for luid=%v", luid)
}
return syscall.UTF16ToString(buf), nil
} | go | func LookupPrivilegeName(systemName string, luid int64) (string, error) {
buf := make([]uint16, 256)
bufSize := uint32(len(buf))
err := _LookupPrivilegeName(systemName, &luid, &buf[0], &bufSize)
if err != nil {
return "", errors.Wrapf(err, "LookupPrivilegeName failed for luid=%v", luid)
}
return syscall.UTF16ToString(buf), nil
} | [
"func",
"LookupPrivilegeName",
"(",
"systemName",
"string",
",",
"luid",
"int64",
")",
"(",
"string",
",",
"error",
")",
"{",
"buf",
":=",
"make",
"(",
"[",
"]",
"uint16",
",",
"256",
")",
"\n",
"bufSize",
":=",
"uint32",
"(",
"len",
"(",
"buf",
")",
")",
"\n",
"err",
":=",
"_LookupPrivilegeName",
"(",
"systemName",
",",
"&",
"luid",
",",
"&",
"buf",
"[",
"0",
"]",
",",
"&",
"bufSize",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"\"",
"\"",
",",
"errors",
".",
"Wrapf",
"(",
"err",
",",
"\"",
"\"",
",",
"luid",
")",
"\n",
"}",
"\n\n",
"return",
"syscall",
".",
"UTF16ToString",
"(",
"buf",
")",
",",
"nil",
"\n",
"}"
]
| // LookupPrivilegeName looks up a privilege name given a LUID value. | [
"LookupPrivilegeName",
"looks",
"up",
"a",
"privilege",
"name",
"given",
"a",
"LUID",
"value",
"."
]
| 50ddd08d81d770b1e0ce2c969a46e46c73580e2a | https://github.com/cloudfoundry/gosigar/blob/50ddd08d81d770b1e0ce2c969a46e46c73580e2a/sys/windows/privileges.go#L110-L119 |
12,791 | cloudfoundry/gosigar | sys/windows/privileges.go | mapPrivileges | func mapPrivileges(names []string) ([]int64, error) {
var privileges []int64
privNameMutex.Lock()
defer privNameMutex.Unlock()
for _, name := range names {
p, ok := privNames[name]
if !ok {
err := _LookupPrivilegeValue("", name, &p)
if err != nil {
return nil, errors.Wrapf(err, "LookupPrivilegeValue failed on '%v'", name)
}
privNames[name] = p
}
privileges = append(privileges, p)
}
return privileges, nil
} | go | func mapPrivileges(names []string) ([]int64, error) {
var privileges []int64
privNameMutex.Lock()
defer privNameMutex.Unlock()
for _, name := range names {
p, ok := privNames[name]
if !ok {
err := _LookupPrivilegeValue("", name, &p)
if err != nil {
return nil, errors.Wrapf(err, "LookupPrivilegeValue failed on '%v'", name)
}
privNames[name] = p
}
privileges = append(privileges, p)
}
return privileges, nil
} | [
"func",
"mapPrivileges",
"(",
"names",
"[",
"]",
"string",
")",
"(",
"[",
"]",
"int64",
",",
"error",
")",
"{",
"var",
"privileges",
"[",
"]",
"int64",
"\n",
"privNameMutex",
".",
"Lock",
"(",
")",
"\n",
"defer",
"privNameMutex",
".",
"Unlock",
"(",
")",
"\n",
"for",
"_",
",",
"name",
":=",
"range",
"names",
"{",
"p",
",",
"ok",
":=",
"privNames",
"[",
"name",
"]",
"\n",
"if",
"!",
"ok",
"{",
"err",
":=",
"_LookupPrivilegeValue",
"(",
"\"",
"\"",
",",
"name",
",",
"&",
"p",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"errors",
".",
"Wrapf",
"(",
"err",
",",
"\"",
"\"",
",",
"name",
")",
"\n",
"}",
"\n",
"privNames",
"[",
"name",
"]",
"=",
"p",
"\n",
"}",
"\n",
"privileges",
"=",
"append",
"(",
"privileges",
",",
"p",
")",
"\n",
"}",
"\n",
"return",
"privileges",
",",
"nil",
"\n",
"}"
]
| // mapPrivileges maps privilege names to LUID values. | [
"mapPrivileges",
"maps",
"privilege",
"names",
"to",
"LUID",
"values",
"."
]
| 50ddd08d81d770b1e0ce2c969a46e46c73580e2a | https://github.com/cloudfoundry/gosigar/blob/50ddd08d81d770b1e0ce2c969a46e46c73580e2a/sys/windows/privileges.go#L122-L138 |
12,792 | cloudfoundry/gosigar | sys/windows/privileges.go | EnableTokenPrivileges | func EnableTokenPrivileges(token syscall.Token, privileges ...string) error {
privValues, err := mapPrivileges(privileges)
if err != nil {
return err
}
var b bytes.Buffer
binary.Write(&b, binary.LittleEndian, uint32(len(privValues)))
for _, p := range privValues {
binary.Write(&b, binary.LittleEndian, p)
binary.Write(&b, binary.LittleEndian, uint32(_SE_PRIVILEGE_ENABLED))
}
success, err := _AdjustTokenPrivileges(token, false, &b.Bytes()[0], uint32(b.Len()), nil, nil)
if !success {
return err
}
if err == ERROR_NOT_ALL_ASSIGNED {
return errors.Wrap(err, "error not all privileges were assigned")
}
return nil
} | go | func EnableTokenPrivileges(token syscall.Token, privileges ...string) error {
privValues, err := mapPrivileges(privileges)
if err != nil {
return err
}
var b bytes.Buffer
binary.Write(&b, binary.LittleEndian, uint32(len(privValues)))
for _, p := range privValues {
binary.Write(&b, binary.LittleEndian, p)
binary.Write(&b, binary.LittleEndian, uint32(_SE_PRIVILEGE_ENABLED))
}
success, err := _AdjustTokenPrivileges(token, false, &b.Bytes()[0], uint32(b.Len()), nil, nil)
if !success {
return err
}
if err == ERROR_NOT_ALL_ASSIGNED {
return errors.Wrap(err, "error not all privileges were assigned")
}
return nil
} | [
"func",
"EnableTokenPrivileges",
"(",
"token",
"syscall",
".",
"Token",
",",
"privileges",
"...",
"string",
")",
"error",
"{",
"privValues",
",",
"err",
":=",
"mapPrivileges",
"(",
"privileges",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n\n",
"var",
"b",
"bytes",
".",
"Buffer",
"\n",
"binary",
".",
"Write",
"(",
"&",
"b",
",",
"binary",
".",
"LittleEndian",
",",
"uint32",
"(",
"len",
"(",
"privValues",
")",
")",
")",
"\n",
"for",
"_",
",",
"p",
":=",
"range",
"privValues",
"{",
"binary",
".",
"Write",
"(",
"&",
"b",
",",
"binary",
".",
"LittleEndian",
",",
"p",
")",
"\n",
"binary",
".",
"Write",
"(",
"&",
"b",
",",
"binary",
".",
"LittleEndian",
",",
"uint32",
"(",
"_SE_PRIVILEGE_ENABLED",
")",
")",
"\n",
"}",
"\n\n",
"success",
",",
"err",
":=",
"_AdjustTokenPrivileges",
"(",
"token",
",",
"false",
",",
"&",
"b",
".",
"Bytes",
"(",
")",
"[",
"0",
"]",
",",
"uint32",
"(",
"b",
".",
"Len",
"(",
")",
")",
",",
"nil",
",",
"nil",
")",
"\n",
"if",
"!",
"success",
"{",
"return",
"err",
"\n",
"}",
"\n",
"if",
"err",
"==",
"ERROR_NOT_ALL_ASSIGNED",
"{",
"return",
"errors",
".",
"Wrap",
"(",
"err",
",",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"return",
"nil",
"\n",
"}"
]
| // EnableTokenPrivileges enables the specified privileges in the given
// Token. The token must have TOKEN_ADJUST_PRIVILEGES access. If the token
// does not already contain the privilege it cannot be enabled. | [
"EnableTokenPrivileges",
"enables",
"the",
"specified",
"privileges",
"in",
"the",
"given",
"Token",
".",
"The",
"token",
"must",
"have",
"TOKEN_ADJUST_PRIVILEGES",
"access",
".",
"If",
"the",
"token",
"does",
"not",
"already",
"contain",
"the",
"privilege",
"it",
"cannot",
"be",
"enabled",
"."
]
| 50ddd08d81d770b1e0ce2c969a46e46c73580e2a | https://github.com/cloudfoundry/gosigar/blob/50ddd08d81d770b1e0ce2c969a46e46c73580e2a/sys/windows/privileges.go#L143-L165 |
12,793 | cloudfoundry/gosigar | sys/windows/privileges.go | GetTokenUser | func GetTokenUser(token syscall.Token) (User, error) {
tokenUser, err := token.GetTokenUser()
if err != nil {
return User{}, errors.Wrap(err, "GetTokenUser failed")
}
var user User
user.SID, err = tokenUser.User.Sid.String()
if err != nil {
return user, errors.Wrap(err, "ConvertSidToStringSid failed")
}
user.Account, user.Domain, user.Type, err = tokenUser.User.Sid.LookupAccount("")
if err != nil {
return user, errors.Wrap(err, "LookupAccountSid failed")
}
return user, nil
} | go | func GetTokenUser(token syscall.Token) (User, error) {
tokenUser, err := token.GetTokenUser()
if err != nil {
return User{}, errors.Wrap(err, "GetTokenUser failed")
}
var user User
user.SID, err = tokenUser.User.Sid.String()
if err != nil {
return user, errors.Wrap(err, "ConvertSidToStringSid failed")
}
user.Account, user.Domain, user.Type, err = tokenUser.User.Sid.LookupAccount("")
if err != nil {
return user, errors.Wrap(err, "LookupAccountSid failed")
}
return user, nil
} | [
"func",
"GetTokenUser",
"(",
"token",
"syscall",
".",
"Token",
")",
"(",
"User",
",",
"error",
")",
"{",
"tokenUser",
",",
"err",
":=",
"token",
".",
"GetTokenUser",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"User",
"{",
"}",
",",
"errors",
".",
"Wrap",
"(",
"err",
",",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"var",
"user",
"User",
"\n",
"user",
".",
"SID",
",",
"err",
"=",
"tokenUser",
".",
"User",
".",
"Sid",
".",
"String",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"user",
",",
"errors",
".",
"Wrap",
"(",
"err",
",",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"user",
".",
"Account",
",",
"user",
".",
"Domain",
",",
"user",
".",
"Type",
",",
"err",
"=",
"tokenUser",
".",
"User",
".",
"Sid",
".",
"LookupAccount",
"(",
"\"",
"\"",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"user",
",",
"errors",
".",
"Wrap",
"(",
"err",
",",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"return",
"user",
",",
"nil",
"\n",
"}"
]
| // GetTokenUser returns the User associated with the given Token. | [
"GetTokenUser",
"returns",
"the",
"User",
"associated",
"with",
"the",
"given",
"Token",
"."
]
| 50ddd08d81d770b1e0ce2c969a46e46c73580e2a | https://github.com/cloudfoundry/gosigar/blob/50ddd08d81d770b1e0ce2c969a46e46c73580e2a/sys/windows/privileges.go#L222-L240 |
12,794 | cloudfoundry/gosigar | sys/windows/privileges.go | GetDebugInfo | func GetDebugInfo() (*DebugInfo, error) {
h, err := windows.GetCurrentProcess()
if err != nil {
return nil, err
}
var token syscall.Token
err = syscall.OpenProcessToken(syscall.Handle(h), syscall.TOKEN_QUERY, &token)
if err != nil {
return nil, err
}
privs, err := GetTokenPrivileges(token)
if err != nil {
return nil, err
}
user, err := GetTokenUser(token)
if err != nil {
return nil, err
}
return &DebugInfo{
User: user,
ProcessPrivs: privs,
OSVersion: GetWindowsVersion(),
Arch: runtime.GOARCH,
NumCPU: runtime.NumCPU(),
}, nil
} | go | func GetDebugInfo() (*DebugInfo, error) {
h, err := windows.GetCurrentProcess()
if err != nil {
return nil, err
}
var token syscall.Token
err = syscall.OpenProcessToken(syscall.Handle(h), syscall.TOKEN_QUERY, &token)
if err != nil {
return nil, err
}
privs, err := GetTokenPrivileges(token)
if err != nil {
return nil, err
}
user, err := GetTokenUser(token)
if err != nil {
return nil, err
}
return &DebugInfo{
User: user,
ProcessPrivs: privs,
OSVersion: GetWindowsVersion(),
Arch: runtime.GOARCH,
NumCPU: runtime.NumCPU(),
}, nil
} | [
"func",
"GetDebugInfo",
"(",
")",
"(",
"*",
"DebugInfo",
",",
"error",
")",
"{",
"h",
",",
"err",
":=",
"windows",
".",
"GetCurrentProcess",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"var",
"token",
"syscall",
".",
"Token",
"\n",
"err",
"=",
"syscall",
".",
"OpenProcessToken",
"(",
"syscall",
".",
"Handle",
"(",
"h",
")",
",",
"syscall",
".",
"TOKEN_QUERY",
",",
"&",
"token",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"privs",
",",
"err",
":=",
"GetTokenPrivileges",
"(",
"token",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"user",
",",
"err",
":=",
"GetTokenUser",
"(",
"token",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"return",
"&",
"DebugInfo",
"{",
"User",
":",
"user",
",",
"ProcessPrivs",
":",
"privs",
",",
"OSVersion",
":",
"GetWindowsVersion",
"(",
")",
",",
"Arch",
":",
"runtime",
".",
"GOARCH",
",",
"NumCPU",
":",
"runtime",
".",
"NumCPU",
"(",
")",
",",
"}",
",",
"nil",
"\n",
"}"
]
| // GetDebugInfo returns general debug info about the current process. | [
"GetDebugInfo",
"returns",
"general",
"debug",
"info",
"about",
"the",
"current",
"process",
"."
]
| 50ddd08d81d770b1e0ce2c969a46e46c73580e2a | https://github.com/cloudfoundry/gosigar/blob/50ddd08d81d770b1e0ce2c969a46e46c73580e2a/sys/windows/privileges.go#L243-L272 |
12,795 | cloudfoundry/gosigar | psnotify/psnotify_bsd.go | createListener | func createListener() (eventListener, error) {
listener := &kqueueListener{}
kq, err := syscall.Kqueue()
listener.kq = kq
return listener, err
} | go | func createListener() (eventListener, error) {
listener := &kqueueListener{}
kq, err := syscall.Kqueue()
listener.kq = kq
return listener, err
} | [
"func",
"createListener",
"(",
")",
"(",
"eventListener",
",",
"error",
")",
"{",
"listener",
":=",
"&",
"kqueueListener",
"{",
"}",
"\n",
"kq",
",",
"err",
":=",
"syscall",
".",
"Kqueue",
"(",
")",
"\n",
"listener",
".",
"kq",
"=",
"kq",
"\n",
"return",
"listener",
",",
"err",
"\n",
"}"
]
| // Initialize bsd implementation of the eventListener interface | [
"Initialize",
"bsd",
"implementation",
"of",
"the",
"eventListener",
"interface"
]
| 50ddd08d81d770b1e0ce2c969a46e46c73580e2a | https://github.com/cloudfoundry/gosigar/blob/50ddd08d81d770b1e0ce2c969a46e46c73580e2a/psnotify/psnotify_bsd.go#L26-L31 |
12,796 | cloudfoundry/gosigar | psnotify/psnotify_bsd.go | kevent | func (w *Watcher) kevent(pid int, fflags uint32, flags int) error {
listener, _ := w.listener.(*kqueueListener)
event := &listener.buf[0]
syscall.SetKevent(event, pid, syscall.EVFILT_PROC, flags)
event.Fflags = fflags
_, err := syscall.Kevent(listener.kq, listener.buf[:], nil, nil)
return err
} | go | func (w *Watcher) kevent(pid int, fflags uint32, flags int) error {
listener, _ := w.listener.(*kqueueListener)
event := &listener.buf[0]
syscall.SetKevent(event, pid, syscall.EVFILT_PROC, flags)
event.Fflags = fflags
_, err := syscall.Kevent(listener.kq, listener.buf[:], nil, nil)
return err
} | [
"func",
"(",
"w",
"*",
"Watcher",
")",
"kevent",
"(",
"pid",
"int",
",",
"fflags",
"uint32",
",",
"flags",
"int",
")",
"error",
"{",
"listener",
",",
"_",
":=",
"w",
".",
"listener",
".",
"(",
"*",
"kqueueListener",
")",
"\n",
"event",
":=",
"&",
"listener",
".",
"buf",
"[",
"0",
"]",
"\n\n",
"syscall",
".",
"SetKevent",
"(",
"event",
",",
"pid",
",",
"syscall",
".",
"EVFILT_PROC",
",",
"flags",
")",
"\n",
"event",
".",
"Fflags",
"=",
"fflags",
"\n\n",
"_",
",",
"err",
":=",
"syscall",
".",
"Kevent",
"(",
"listener",
".",
"kq",
",",
"listener",
".",
"buf",
"[",
":",
"]",
",",
"nil",
",",
"nil",
")",
"\n\n",
"return",
"err",
"\n",
"}"
]
| // Initialize Kevent_t fields and propagate changelist for the given pid | [
"Initialize",
"Kevent_t",
"fields",
"and",
"propagate",
"changelist",
"for",
"the",
"given",
"pid"
]
| 50ddd08d81d770b1e0ce2c969a46e46c73580e2a | https://github.com/cloudfoundry/gosigar/blob/50ddd08d81d770b1e0ce2c969a46e46c73580e2a/psnotify/psnotify_bsd.go#L34-L44 |
12,797 | cloudfoundry/gosigar | psnotify/psnotify_bsd.go | unregister | func (w *Watcher) unregister(pid int) error {
return w.kevent(pid, 0, syscall.EV_DELETE)
} | go | func (w *Watcher) unregister(pid int) error {
return w.kevent(pid, 0, syscall.EV_DELETE)
} | [
"func",
"(",
"w",
"*",
"Watcher",
")",
"unregister",
"(",
"pid",
"int",
")",
"error",
"{",
"return",
"w",
".",
"kevent",
"(",
"pid",
",",
"0",
",",
"syscall",
".",
"EV_DELETE",
")",
"\n",
"}"
]
| // Delete filter for given pid from the queue | [
"Delete",
"filter",
"for",
"given",
"pid",
"from",
"the",
"queue"
]
| 50ddd08d81d770b1e0ce2c969a46e46c73580e2a | https://github.com/cloudfoundry/gosigar/blob/50ddd08d81d770b1e0ce2c969a46e46c73580e2a/psnotify/psnotify_bsd.go#L47-L49 |
12,798 | cloudfoundry/gosigar | psnotify/psnotify_bsd.go | register | func (w *Watcher) register(pid int, flags uint32) error {
return w.kevent(pid, flags, syscall.EV_ADD|syscall.EV_ENABLE)
} | go | func (w *Watcher) register(pid int, flags uint32) error {
return w.kevent(pid, flags, syscall.EV_ADD|syscall.EV_ENABLE)
} | [
"func",
"(",
"w",
"*",
"Watcher",
")",
"register",
"(",
"pid",
"int",
",",
"flags",
"uint32",
")",
"error",
"{",
"return",
"w",
".",
"kevent",
"(",
"pid",
",",
"flags",
",",
"syscall",
".",
"EV_ADD",
"|",
"syscall",
".",
"EV_ENABLE",
")",
"\n",
"}"
]
| // Add and enable filter for given pid in the queue | [
"Add",
"and",
"enable",
"filter",
"for",
"given",
"pid",
"in",
"the",
"queue"
]
| 50ddd08d81d770b1e0ce2c969a46e46c73580e2a | https://github.com/cloudfoundry/gosigar/blob/50ddd08d81d770b1e0ce2c969a46e46c73580e2a/psnotify/psnotify_bsd.go#L52-L54 |
12,799 | cloudfoundry/gosigar | psnotify/psnotify_bsd.go | readEvents | func (w *Watcher) readEvents() {
listener, _ := w.listener.(*kqueueListener)
events := make([]syscall.Kevent_t, 10)
for {
if w.isDone() {
return
}
n, err := syscall.Kevent(listener.kq, nil, events, nil)
if err != nil {
w.Error <- err
continue
}
for _, ev := range events[:n] {
pid := int(ev.Ident)
switch ev.Fflags {
case syscall.NOTE_FORK:
w.Fork <- &ProcEventFork{ParentPid: pid}
case syscall.NOTE_EXEC:
w.Exec <- &ProcEventExec{Pid: pid}
case syscall.NOTE_EXIT:
w.RemoveWatch(pid)
w.Exit <- &ProcEventExit{Pid: pid}
}
}
}
} | go | func (w *Watcher) readEvents() {
listener, _ := w.listener.(*kqueueListener)
events := make([]syscall.Kevent_t, 10)
for {
if w.isDone() {
return
}
n, err := syscall.Kevent(listener.kq, nil, events, nil)
if err != nil {
w.Error <- err
continue
}
for _, ev := range events[:n] {
pid := int(ev.Ident)
switch ev.Fflags {
case syscall.NOTE_FORK:
w.Fork <- &ProcEventFork{ParentPid: pid}
case syscall.NOTE_EXEC:
w.Exec <- &ProcEventExec{Pid: pid}
case syscall.NOTE_EXIT:
w.RemoveWatch(pid)
w.Exit <- &ProcEventExit{Pid: pid}
}
}
}
} | [
"func",
"(",
"w",
"*",
"Watcher",
")",
"readEvents",
"(",
")",
"{",
"listener",
",",
"_",
":=",
"w",
".",
"listener",
".",
"(",
"*",
"kqueueListener",
")",
"\n",
"events",
":=",
"make",
"(",
"[",
"]",
"syscall",
".",
"Kevent_t",
",",
"10",
")",
"\n\n",
"for",
"{",
"if",
"w",
".",
"isDone",
"(",
")",
"{",
"return",
"\n",
"}",
"\n\n",
"n",
",",
"err",
":=",
"syscall",
".",
"Kevent",
"(",
"listener",
".",
"kq",
",",
"nil",
",",
"events",
",",
"nil",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"w",
".",
"Error",
"<-",
"err",
"\n",
"continue",
"\n",
"}",
"\n\n",
"for",
"_",
",",
"ev",
":=",
"range",
"events",
"[",
":",
"n",
"]",
"{",
"pid",
":=",
"int",
"(",
"ev",
".",
"Ident",
")",
"\n\n",
"switch",
"ev",
".",
"Fflags",
"{",
"case",
"syscall",
".",
"NOTE_FORK",
":",
"w",
".",
"Fork",
"<-",
"&",
"ProcEventFork",
"{",
"ParentPid",
":",
"pid",
"}",
"\n",
"case",
"syscall",
".",
"NOTE_EXEC",
":",
"w",
".",
"Exec",
"<-",
"&",
"ProcEventExec",
"{",
"Pid",
":",
"pid",
"}",
"\n",
"case",
"syscall",
".",
"NOTE_EXIT",
":",
"w",
".",
"RemoveWatch",
"(",
"pid",
")",
"\n",
"w",
".",
"Exit",
"<-",
"&",
"ProcEventExit",
"{",
"Pid",
":",
"pid",
"}",
"\n",
"}",
"\n",
"}",
"\n",
"}",
"\n",
"}"
]
| // Poll the kqueue file descriptor and dispatch to the Event channels | [
"Poll",
"the",
"kqueue",
"file",
"descriptor",
"and",
"dispatch",
"to",
"the",
"Event",
"channels"
]
| 50ddd08d81d770b1e0ce2c969a46e46c73580e2a | https://github.com/cloudfoundry/gosigar/blob/50ddd08d81d770b1e0ce2c969a46e46c73580e2a/psnotify/psnotify_bsd.go#L57-L86 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.