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,600
google/badwolf
bql/lexer/lexer.go
lexPredicateOrLiteral
func lexPredicateOrLiteral(l *lexer) stateFn { text := l.input[l.pos:] // Fix issue 39 (https://github.com/google/badwolf/issues/39) pIdx, lIdx := strings.Index(text, "\"@["), strings.Index(text, "\"^^type:") if pIdx < 0 && lIdx < 0 { l.emitError("failed to parse predicate or literal for opening \" delimiter") return nil } if pIdx > 0 && (lIdx < 0 || pIdx < lIdx) { return lexPredicate } return lexLiteral }
go
func lexPredicateOrLiteral(l *lexer) stateFn { text := l.input[l.pos:] // Fix issue 39 (https://github.com/google/badwolf/issues/39) pIdx, lIdx := strings.Index(text, "\"@["), strings.Index(text, "\"^^type:") if pIdx < 0 && lIdx < 0 { l.emitError("failed to parse predicate or literal for opening \" delimiter") return nil } if pIdx > 0 && (lIdx < 0 || pIdx < lIdx) { return lexPredicate } return lexLiteral }
[ "func", "lexPredicateOrLiteral", "(", "l", "*", "lexer", ")", "stateFn", "{", "text", ":=", "l", ".", "input", "[", "l", ".", "pos", ":", "]", "\n", "// Fix issue 39 (https://github.com/google/badwolf/issues/39)", "pIdx", ",", "lIdx", ":=", "strings", ".", "Index", "(", "text", ",", "\"", "\\\"", "\"", ")", ",", "strings", ".", "Index", "(", "text", ",", "\"", "\\\"", "\"", ")", "\n", "if", "pIdx", "<", "0", "&&", "lIdx", "<", "0", "{", "l", ".", "emitError", "(", "\"", "\\\"", "\"", ")", "\n", "return", "nil", "\n", "}", "\n", "if", "pIdx", ">", "0", "&&", "(", "lIdx", "<", "0", "||", "pIdx", "<", "lIdx", ")", "{", "return", "lexPredicate", "\n", "}", "\n", "return", "lexLiteral", "\n", "}" ]
// lexPredicateOrLiteral tries to lex a predicate or a literal out of the input.
[ "lexPredicateOrLiteral", "tries", "to", "lex", "a", "predicate", "or", "a", "literal", "out", "of", "the", "input", "." ]
f6c3103546450641440a719b2ed52cc74bae6237
https://github.com/google/badwolf/blob/f6c3103546450641440a719b2ed52cc74bae6237/bql/lexer/lexer.go#L676-L688
12,601
google/badwolf
bql/lexer/lexer.go
lexPredicate
func lexPredicate(l *lexer) stateFn { l.next() for done := false; !done; { switch r := l.next(); r { case backSlash: if nr := l.peek(); nr == quote { l.next() continue } case quote: l.backup() if !l.consume(anchor) { l.emitError("predicates require time anchor information; missing \"@[") return nil } var ( nr rune commas = 0 ) for { nr = l.next() if nr == comma { commas++ } if nr == rightSquarePar || nr == eof { break } } if nr != rightSquarePar { l.emitError("predicate's time anchors should end with ] delimiter") return nil } if commas > 1 { l.emitError("predicate bounds should only have one , to separate bounds") return nil } if commas == 0 { l.emit(ItemPredicate) } else { l.emit(ItemPredicateBound) } done = true case eof: l.emitError("literals needs to be properly terminated; missing \" and type") return nil } } return lexSpace }
go
func lexPredicate(l *lexer) stateFn { l.next() for done := false; !done; { switch r := l.next(); r { case backSlash: if nr := l.peek(); nr == quote { l.next() continue } case quote: l.backup() if !l.consume(anchor) { l.emitError("predicates require time anchor information; missing \"@[") return nil } var ( nr rune commas = 0 ) for { nr = l.next() if nr == comma { commas++ } if nr == rightSquarePar || nr == eof { break } } if nr != rightSquarePar { l.emitError("predicate's time anchors should end with ] delimiter") return nil } if commas > 1 { l.emitError("predicate bounds should only have one , to separate bounds") return nil } if commas == 0 { l.emit(ItemPredicate) } else { l.emit(ItemPredicateBound) } done = true case eof: l.emitError("literals needs to be properly terminated; missing \" and type") return nil } } return lexSpace }
[ "func", "lexPredicate", "(", "l", "*", "lexer", ")", "stateFn", "{", "l", ".", "next", "(", ")", "\n", "for", "done", ":=", "false", ";", "!", "done", ";", "{", "switch", "r", ":=", "l", ".", "next", "(", ")", ";", "r", "{", "case", "backSlash", ":", "if", "nr", ":=", "l", ".", "peek", "(", ")", ";", "nr", "==", "quote", "{", "l", ".", "next", "(", ")", "\n", "continue", "\n", "}", "\n", "case", "quote", ":", "l", ".", "backup", "(", ")", "\n", "if", "!", "l", ".", "consume", "(", "anchor", ")", "{", "l", ".", "emitError", "(", "\"", "\\\"", "\"", ")", "\n", "return", "nil", "\n", "}", "\n", "var", "(", "nr", "rune", "\n", "commas", "=", "0", "\n", ")", "\n", "for", "{", "nr", "=", "l", ".", "next", "(", ")", "\n", "if", "nr", "==", "comma", "{", "commas", "++", "\n", "}", "\n", "if", "nr", "==", "rightSquarePar", "||", "nr", "==", "eof", "{", "break", "\n", "}", "\n", "}", "\n", "if", "nr", "!=", "rightSquarePar", "{", "l", ".", "emitError", "(", "\"", "\"", ")", "\n", "return", "nil", "\n", "}", "\n", "if", "commas", ">", "1", "{", "l", ".", "emitError", "(", "\"", "\"", ")", "\n", "return", "nil", "\n", "}", "\n", "if", "commas", "==", "0", "{", "l", ".", "emit", "(", "ItemPredicate", ")", "\n", "}", "else", "{", "l", ".", "emit", "(", "ItemPredicateBound", ")", "\n", "}", "\n", "done", "=", "true", "\n", "case", "eof", ":", "l", ".", "emitError", "(", "\"", "\\\"", "\"", ")", "\n", "return", "nil", "\n", "}", "\n", "}", "\n", "return", "lexSpace", "\n", "}" ]
// lexPredicate lexes a predicate out of the input.
[ "lexPredicate", "lexes", "a", "predicate", "out", "of", "the", "input", "." ]
f6c3103546450641440a719b2ed52cc74bae6237
https://github.com/google/badwolf/blob/f6c3103546450641440a719b2ed52cc74bae6237/bql/lexer/lexer.go#L691-L739
12,602
google/badwolf
bql/lexer/lexer.go
lexLiteral
func lexLiteral(l *lexer) stateFn { l.next() for done := false; !done; { switch r := l.next(); r { case backSlash: if nr := l.peek(); nr == quote { l.next() continue } case quote: l.backup() if !l.consume(literalType) { l.emitError("literals require a type definintion; missing ^^type:") return nil } literalT := "" for { r := l.next() if !(unicode.IsLetter(r) || unicode.IsDigit(r)) || r == eof { break } literalT += string(r) } literalT = strings.ToLower(literalT) switch literalT { case literalBool, literalInt, literalFloat, literalText, literalBlob: l.backup() l.emit(ItemLiteral) done = true default: l.emitError("invalid literal type " + literalT) return nil } case eof: l.emitError("literals needs to be properly terminated; missing \" and type") return nil } } return lexSpace }
go
func lexLiteral(l *lexer) stateFn { l.next() for done := false; !done; { switch r := l.next(); r { case backSlash: if nr := l.peek(); nr == quote { l.next() continue } case quote: l.backup() if !l.consume(literalType) { l.emitError("literals require a type definintion; missing ^^type:") return nil } literalT := "" for { r := l.next() if !(unicode.IsLetter(r) || unicode.IsDigit(r)) || r == eof { break } literalT += string(r) } literalT = strings.ToLower(literalT) switch literalT { case literalBool, literalInt, literalFloat, literalText, literalBlob: l.backup() l.emit(ItemLiteral) done = true default: l.emitError("invalid literal type " + literalT) return nil } case eof: l.emitError("literals needs to be properly terminated; missing \" and type") return nil } } return lexSpace }
[ "func", "lexLiteral", "(", "l", "*", "lexer", ")", "stateFn", "{", "l", ".", "next", "(", ")", "\n", "for", "done", ":=", "false", ";", "!", "done", ";", "{", "switch", "r", ":=", "l", ".", "next", "(", ")", ";", "r", "{", "case", "backSlash", ":", "if", "nr", ":=", "l", ".", "peek", "(", ")", ";", "nr", "==", "quote", "{", "l", ".", "next", "(", ")", "\n", "continue", "\n", "}", "\n", "case", "quote", ":", "l", ".", "backup", "(", ")", "\n", "if", "!", "l", ".", "consume", "(", "literalType", ")", "{", "l", ".", "emitError", "(", "\"", "\"", ")", "\n", "return", "nil", "\n", "}", "\n", "literalT", ":=", "\"", "\"", "\n", "for", "{", "r", ":=", "l", ".", "next", "(", ")", "\n", "if", "!", "(", "unicode", ".", "IsLetter", "(", "r", ")", "||", "unicode", ".", "IsDigit", "(", "r", ")", ")", "||", "r", "==", "eof", "{", "break", "\n", "}", "\n", "literalT", "+=", "string", "(", "r", ")", "\n", "}", "\n", "literalT", "=", "strings", ".", "ToLower", "(", "literalT", ")", "\n", "switch", "literalT", "{", "case", "literalBool", ",", "literalInt", ",", "literalFloat", ",", "literalText", ",", "literalBlob", ":", "l", ".", "backup", "(", ")", "\n", "l", ".", "emit", "(", "ItemLiteral", ")", "\n", "done", "=", "true", "\n", "default", ":", "l", ".", "emitError", "(", "\"", "\"", "+", "literalT", ")", "\n", "return", "nil", "\n", "}", "\n", "case", "eof", ":", "l", ".", "emitError", "(", "\"", "\\\"", "\"", ")", "\n", "return", "nil", "\n", "}", "\n", "}", "\n", "return", "lexSpace", "\n", "}" ]
// lexLiteral lexes a literal out of the input.
[ "lexLiteral", "lexes", "a", "literal", "out", "of", "the", "input", "." ]
f6c3103546450641440a719b2ed52cc74bae6237
https://github.com/google/badwolf/blob/f6c3103546450641440a719b2ed52cc74bae6237/bql/lexer/lexer.go#L742-L781
12,603
google/badwolf
bql/lexer/lexer.go
consumeKeyword
func consumeKeyword(l *lexer, t TokenType) { for { if r := l.next(); !unicode.IsLetter(r) || r == eof { l.backup() l.emit(t) break } } }
go
func consumeKeyword(l *lexer, t TokenType) { for { if r := l.next(); !unicode.IsLetter(r) || r == eof { l.backup() l.emit(t) break } } }
[ "func", "consumeKeyword", "(", "l", "*", "lexer", ",", "t", "TokenType", ")", "{", "for", "{", "if", "r", ":=", "l", ".", "next", "(", ")", ";", "!", "unicode", ".", "IsLetter", "(", "r", ")", "||", "r", "==", "eof", "{", "l", ".", "backup", "(", ")", "\n", "l", ".", "emit", "(", "t", ")", "\n", "break", "\n", "}", "\n", "}", "\n", "}" ]
// consumeKeyword consume and emits a valid token
[ "consumeKeyword", "consume", "and", "emits", "a", "valid", "token" ]
f6c3103546450641440a719b2ed52cc74bae6237
https://github.com/google/badwolf/blob/f6c3103546450641440a719b2ed52cc74bae6237/bql/lexer/lexer.go#L784-L792
12,604
google/badwolf
bql/lexer/lexer.go
emitError
func (l *lexer) emitError(msg string) { l.tokens <- Token{ Type: ItemError, Text: l.input[l.start:l.pos], ErrorMessage: fmt.Sprintf("[lexer:%d:%d] %s", l.line, l.col, msg), } l.start = l.pos }
go
func (l *lexer) emitError(msg string) { l.tokens <- Token{ Type: ItemError, Text: l.input[l.start:l.pos], ErrorMessage: fmt.Sprintf("[lexer:%d:%d] %s", l.line, l.col, msg), } l.start = l.pos }
[ "func", "(", "l", "*", "lexer", ")", "emitError", "(", "msg", "string", ")", "{", "l", ".", "tokens", "<-", "Token", "{", "Type", ":", "ItemError", ",", "Text", ":", "l", ".", "input", "[", "l", ".", "start", ":", "l", ".", "pos", "]", ",", "ErrorMessage", ":", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "l", ".", "line", ",", "l", ".", "col", ",", "msg", ")", ",", "}", "\n", "l", ".", "start", "=", "l", ".", "pos", "\n", "}" ]
// emitError passes and error to the client with proper error messaging.
[ "emitError", "passes", "and", "error", "to", "the", "client", "with", "proper", "error", "messaging", "." ]
f6c3103546450641440a719b2ed52cc74bae6237
https://github.com/google/badwolf/blob/f6c3103546450641440a719b2ed52cc74bae6237/bql/lexer/lexer.go#L812-L819
12,605
google/badwolf
bql/lexer/lexer.go
accept
func (l *lexer) accept(r rune) bool { if unicode.ToLower(l.next()) == unicode.ToLower(r) { return true } l.backup() return false }
go
func (l *lexer) accept(r rune) bool { if unicode.ToLower(l.next()) == unicode.ToLower(r) { return true } l.backup() return false }
[ "func", "(", "l", "*", "lexer", ")", "accept", "(", "r", "rune", ")", "bool", "{", "if", "unicode", ".", "ToLower", "(", "l", ".", "next", "(", ")", ")", "==", "unicode", ".", "ToLower", "(", "r", ")", "{", "return", "true", "\n", "}", "\n", "l", ".", "backup", "(", ")", "\n", "return", "false", "\n", "}" ]
// accept consumes the next rune if it's equal to the one provided.
[ "accept", "consumes", "the", "next", "rune", "if", "it", "s", "equal", "to", "the", "one", "provided", "." ]
f6c3103546450641440a719b2ed52cc74bae6237
https://github.com/google/badwolf/blob/f6c3103546450641440a719b2ed52cc74bae6237/bql/lexer/lexer.go#L858-L864
12,606
google/badwolf
storage/memory/uuid.go
UUIDToBase64
func UUIDToBase64(uuid uuid.UUID) string { return base64.StdEncoding.EncodeToString([]byte(uuid)) }
go
func UUIDToBase64(uuid uuid.UUID) string { return base64.StdEncoding.EncodeToString([]byte(uuid)) }
[ "func", "UUIDToBase64", "(", "uuid", "uuid", ".", "UUID", ")", "string", "{", "return", "base64", ".", "StdEncoding", ".", "EncodeToString", "(", "[", "]", "byte", "(", "uuid", ")", ")", "\n", "}" ]
// UUIDToBase64 recodes it into a compact string.
[ "UUIDToBase64", "recodes", "it", "into", "a", "compact", "string", "." ]
f6c3103546450641440a719b2ed52cc74bae6237
https://github.com/google/badwolf/blob/f6c3103546450641440a719b2ed52cc74bae6237/storage/memory/uuid.go#L11-L13
12,607
google/badwolf
storage/memory/uuid.go
Base64ToUUID
func Base64ToUUID(b64 string) (uuid.UUID, error) { bs, err := base64.StdEncoding.DecodeString(b64) if err != nil { return nil, err } if got, want := len(bs), 16; got != want { return nil, fmt.Errorf("invalid UUID size; got %d, want %d", got, want) } return uuid.UUID(bs), nil }
go
func Base64ToUUID(b64 string) (uuid.UUID, error) { bs, err := base64.StdEncoding.DecodeString(b64) if err != nil { return nil, err } if got, want := len(bs), 16; got != want { return nil, fmt.Errorf("invalid UUID size; got %d, want %d", got, want) } return uuid.UUID(bs), nil }
[ "func", "Base64ToUUID", "(", "b64", "string", ")", "(", "uuid", ".", "UUID", ",", "error", ")", "{", "bs", ",", "err", ":=", "base64", ".", "StdEncoding", ".", "DecodeString", "(", "b64", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "if", "got", ",", "want", ":=", "len", "(", "bs", ")", ",", "16", ";", "got", "!=", "want", "{", "return", "nil", ",", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "got", ",", "want", ")", "\n", "}", "\n", "return", "uuid", ".", "UUID", "(", "bs", ")", ",", "nil", "\n", "}" ]
// Base64ToUUID attempts to decode a base 64 encoded UUID.
[ "Base64ToUUID", "attempts", "to", "decode", "a", "base", "64", "encoded", "UUID", "." ]
f6c3103546450641440a719b2ed52cc74bae6237
https://github.com/google/badwolf/blob/f6c3103546450641440a719b2ed52cc74bae6237/storage/memory/uuid.go#L16-L25
12,608
EngoEngine/engo
clock.go
Delta
func (c *Clock) Delta() float32 { return float32(float64(c.deltaStamp) / float64(secondsInNano)) }
go
func (c *Clock) Delta() float32 { return float32(float64(c.deltaStamp) / float64(secondsInNano)) }
[ "func", "(", "c", "*", "Clock", ")", "Delta", "(", ")", "float32", "{", "return", "float32", "(", "float64", "(", "c", ".", "deltaStamp", ")", "/", "float64", "(", "secondsInNano", ")", ")", "\n", "}" ]
// Delta is the amount of seconds between the last tick and the one before that
[ "Delta", "is", "the", "amount", "of", "seconds", "between", "the", "last", "tick", "and", "the", "one", "before", "that" ]
6f88a7379a25d81e976cf6e86ea3617f3b480b1a
https://github.com/EngoEngine/engo/blob/6f88a7379a25d81e976cf6e86ea3617f3b480b1a/clock.go#L66-L68
12,609
EngoEngine/engo
clock.go
Time
func (c *Clock) Time() float32 { currStamp := theTimer.Now() return float32(float64(currStamp-c.startStamp) / float64(secondsInNano)) }
go
func (c *Clock) Time() float32 { currStamp := theTimer.Now() return float32(float64(currStamp-c.startStamp) / float64(secondsInNano)) }
[ "func", "(", "c", "*", "Clock", ")", "Time", "(", ")", "float32", "{", "currStamp", ":=", "theTimer", ".", "Now", "(", ")", "\n", "return", "float32", "(", "float64", "(", "currStamp", "-", "c", ".", "startStamp", ")", "/", "float64", "(", "secondsInNano", ")", ")", "\n", "}" ]
// Time is the number of seconds the clock has been running
[ "Time", "is", "the", "number", "of", "seconds", "the", "clock", "has", "been", "running" ]
6f88a7379a25d81e976cf6e86ea3617f3b480b1a
https://github.com/EngoEngine/engo/blob/6f88a7379a25d81e976cf6e86ea3617f3b480b1a/clock.go#L76-L79
12,610
EngoEngine/engo
assets.go
Register
func (formats *Formats) Register(ext string, loader FileLoader) { formats.formats[ext] = loader }
go
func (formats *Formats) Register(ext string, loader FileLoader) { formats.formats[ext] = loader }
[ "func", "(", "formats", "*", "Formats", ")", "Register", "(", "ext", "string", ",", "loader", "FileLoader", ")", "{", "formats", ".", "formats", "[", "ext", "]", "=", "loader", "\n", "}" ]
// Register registers a resource loader for the given file format.
[ "Register", "registers", "a", "resource", "loader", "for", "the", "given", "file", "format", "." ]
6f88a7379a25d81e976cf6e86ea3617f3b480b1a
https://github.com/EngoEngine/engo/blob/6f88a7379a25d81e976cf6e86ea3617f3b480b1a/assets.go#L58-L60
12,611
EngoEngine/engo
assets.go
load
func (formats *Formats) load(url string) error { ext := getExt(url) if loader, ok := Files.formats[ext]; ok { f, err := openFile(filepath.Join(formats.root, url)) if err != nil { return fmt.Errorf("unable to open resource: %s", err) } defer f.Close() return loader.Load(url, f) } return fmt.Errorf("no `FileLoader` associated with this extension: %q in url %q", ext, url) }
go
func (formats *Formats) load(url string) error { ext := getExt(url) if loader, ok := Files.formats[ext]; ok { f, err := openFile(filepath.Join(formats.root, url)) if err != nil { return fmt.Errorf("unable to open resource: %s", err) } defer f.Close() return loader.Load(url, f) } return fmt.Errorf("no `FileLoader` associated with this extension: %q in url %q", ext, url) }
[ "func", "(", "formats", "*", "Formats", ")", "load", "(", "url", "string", ")", "error", "{", "ext", ":=", "getExt", "(", "url", ")", "\n", "if", "loader", ",", "ok", ":=", "Files", ".", "formats", "[", "ext", "]", ";", "ok", "{", "f", ",", "err", ":=", "openFile", "(", "filepath", ".", "Join", "(", "formats", ".", "root", ",", "url", ")", ")", "\n", "if", "err", "!=", "nil", "{", "return", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "err", ")", "\n", "}", "\n", "defer", "f", ".", "Close", "(", ")", "\n\n", "return", "loader", ".", "Load", "(", "url", ",", "f", ")", "\n", "}", "\n", "return", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "ext", ",", "url", ")", "\n", "}" ]
// load loads the given resource into memory.
[ "load", "loads", "the", "given", "resource", "into", "memory", "." ]
6f88a7379a25d81e976cf6e86ea3617f3b480b1a
https://github.com/EngoEngine/engo/blob/6f88a7379a25d81e976cf6e86ea3617f3b480b1a/assets.go#L74-L86
12,612
EngoEngine/engo
assets.go
LoadReaderData
func (formats *Formats) LoadReaderData(url string, f io.Reader) error { ext := getExt(url) if loader, ok := Files.formats[ext]; ok { return loader.Load(url, f) } return fmt.Errorf("no `FileLoader` associated with this extension: %q in url %q", ext, url) }
go
func (formats *Formats) LoadReaderData(url string, f io.Reader) error { ext := getExt(url) if loader, ok := Files.formats[ext]; ok { return loader.Load(url, f) } return fmt.Errorf("no `FileLoader` associated with this extension: %q in url %q", ext, url) }
[ "func", "(", "formats", "*", "Formats", ")", "LoadReaderData", "(", "url", "string", ",", "f", "io", ".", "Reader", ")", "error", "{", "ext", ":=", "getExt", "(", "url", ")", "\n", "if", "loader", ",", "ok", ":=", "Files", ".", "formats", "[", "ext", "]", ";", "ok", "{", "return", "loader", ".", "Load", "(", "url", ",", "f", ")", "\n", "}", "\n", "return", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "ext", ",", "url", ")", "\n", "}" ]
// LoadReaderData loads a resource when you already have the reader for it.
[ "LoadReaderData", "loads", "a", "resource", "when", "you", "already", "have", "the", "reader", "for", "it", "." ]
6f88a7379a25d81e976cf6e86ea3617f3b480b1a
https://github.com/EngoEngine/engo/blob/6f88a7379a25d81e976cf6e86ea3617f3b480b1a/assets.go#L100-L106
12,613
EngoEngine/engo
assets.go
Unload
func (formats *Formats) Unload(url string) error { ext := getExt(url) if loader, ok := Files.formats[ext]; ok { return loader.Unload(url) } return fmt.Errorf("no `FileLoader` associated with this extension: %q in url %q", ext, url) }
go
func (formats *Formats) Unload(url string) error { ext := getExt(url) if loader, ok := Files.formats[ext]; ok { return loader.Unload(url) } return fmt.Errorf("no `FileLoader` associated with this extension: %q in url %q", ext, url) }
[ "func", "(", "formats", "*", "Formats", ")", "Unload", "(", "url", "string", ")", "error", "{", "ext", ":=", "getExt", "(", "url", ")", "\n", "if", "loader", ",", "ok", ":=", "Files", ".", "formats", "[", "ext", "]", ";", "ok", "{", "return", "loader", ".", "Unload", "(", "url", ")", "\n", "}", "\n", "return", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "ext", ",", "url", ")", "\n", "}" ]
// Unload releases the given resource from memory.
[ "Unload", "releases", "the", "given", "resource", "from", "memory", "." ]
6f88a7379a25d81e976cf6e86ea3617f3b480b1a
https://github.com/EngoEngine/engo/blob/6f88a7379a25d81e976cf6e86ea3617f3b480b1a/assets.go#L109-L115
12,614
EngoEngine/engo
common/spritesheet.go
NewAsymmetricSpritesheetFromTexture
func NewAsymmetricSpritesheetFromTexture(tr *TextureResource, spriteRegions []SpriteRegion) *Spritesheet { return &Spritesheet{ texture: tr.Texture, width: tr.Width, height: tr.Height, cells: spriteRegions, cache: make(map[int]Texture), } }
go
func NewAsymmetricSpritesheetFromTexture(tr *TextureResource, spriteRegions []SpriteRegion) *Spritesheet { return &Spritesheet{ texture: tr.Texture, width: tr.Width, height: tr.Height, cells: spriteRegions, cache: make(map[int]Texture), } }
[ "func", "NewAsymmetricSpritesheetFromTexture", "(", "tr", "*", "TextureResource", ",", "spriteRegions", "[", "]", "SpriteRegion", ")", "*", "Spritesheet", "{", "return", "&", "Spritesheet", "{", "texture", ":", "tr", ".", "Texture", ",", "width", ":", "tr", ".", "Width", ",", "height", ":", "tr", ".", "Height", ",", "cells", ":", "spriteRegions", ",", "cache", ":", "make", "(", "map", "[", "int", "]", "Texture", ")", ",", "}", "\n", "}" ]
// NewAsymmetricSpritesheetFromTexture creates a new AsymmetricSpriteSheet from a // TextureResource. The data provided is the location and size of the sprites
[ "NewAsymmetricSpritesheetFromTexture", "creates", "a", "new", "AsymmetricSpriteSheet", "from", "a", "TextureResource", ".", "The", "data", "provided", "is", "the", "location", "and", "size", "of", "the", "sprites" ]
6f88a7379a25d81e976cf6e86ea3617f3b480b1a
https://github.com/EngoEngine/engo/blob/6f88a7379a25d81e976cf6e86ea3617f3b480b1a/common/spritesheet.go#L27-L35
12,615
EngoEngine/engo
common/spritesheet.go
NewAsymmetricSpritesheetFromFile
func NewAsymmetricSpritesheetFromFile(textureName string, spriteRegions []SpriteRegion) *Spritesheet { res, err := engo.Files.Resource(textureName) if err != nil { log.Println("[WARNING] [NewAsymmetricSpritesheetFromFile]: Received error:", err) return nil } img, ok := res.(TextureResource) if !ok { log.Println("[WARNING] [NewAsymmetricSpritesheetFromFile]: Resource not of type `TextureResource`:", textureName) return nil } return NewAsymmetricSpritesheetFromTexture(&img, spriteRegions) }
go
func NewAsymmetricSpritesheetFromFile(textureName string, spriteRegions []SpriteRegion) *Spritesheet { res, err := engo.Files.Resource(textureName) if err != nil { log.Println("[WARNING] [NewAsymmetricSpritesheetFromFile]: Received error:", err) return nil } img, ok := res.(TextureResource) if !ok { log.Println("[WARNING] [NewAsymmetricSpritesheetFromFile]: Resource not of type `TextureResource`:", textureName) return nil } return NewAsymmetricSpritesheetFromTexture(&img, spriteRegions) }
[ "func", "NewAsymmetricSpritesheetFromFile", "(", "textureName", "string", ",", "spriteRegions", "[", "]", "SpriteRegion", ")", "*", "Spritesheet", "{", "res", ",", "err", ":=", "engo", ".", "Files", ".", "Resource", "(", "textureName", ")", "\n", "if", "err", "!=", "nil", "{", "log", ".", "Println", "(", "\"", "\"", ",", "err", ")", "\n", "return", "nil", "\n", "}", "\n\n", "img", ",", "ok", ":=", "res", ".", "(", "TextureResource", ")", "\n", "if", "!", "ok", "{", "log", ".", "Println", "(", "\"", "\"", ",", "textureName", ")", "\n", "return", "nil", "\n", "}", "\n\n", "return", "NewAsymmetricSpritesheetFromTexture", "(", "&", "img", ",", "spriteRegions", ")", "\n", "}" ]
// NewAsymmetricSpritesheetFromFile creates a new AsymmetricSpriteSheet from a // file name. The data provided is the location and size of the sprites
[ "NewAsymmetricSpritesheetFromFile", "creates", "a", "new", "AsymmetricSpriteSheet", "from", "a", "file", "name", ".", "The", "data", "provided", "is", "the", "location", "and", "size", "of", "the", "sprites" ]
6f88a7379a25d81e976cf6e86ea3617f3b480b1a
https://github.com/EngoEngine/engo/blob/6f88a7379a25d81e976cf6e86ea3617f3b480b1a/common/spritesheet.go#L39-L53
12,616
EngoEngine/engo
common/spritesheet.go
NewSpritesheetFromTexture
func NewSpritesheetFromTexture(tr *TextureResource, cellWidth, cellHeight int) *Spritesheet { spriteRegions := generateSymmetricSpriteRegions(tr.Width, tr.Height, cellWidth, cellHeight, 0, 0) return NewAsymmetricSpritesheetFromTexture(tr, spriteRegions) }
go
func NewSpritesheetFromTexture(tr *TextureResource, cellWidth, cellHeight int) *Spritesheet { spriteRegions := generateSymmetricSpriteRegions(tr.Width, tr.Height, cellWidth, cellHeight, 0, 0) return NewAsymmetricSpritesheetFromTexture(tr, spriteRegions) }
[ "func", "NewSpritesheetFromTexture", "(", "tr", "*", "TextureResource", ",", "cellWidth", ",", "cellHeight", "int", ")", "*", "Spritesheet", "{", "spriteRegions", ":=", "generateSymmetricSpriteRegions", "(", "tr", ".", "Width", ",", "tr", ".", "Height", ",", "cellWidth", ",", "cellHeight", ",", "0", ",", "0", ")", "\n", "return", "NewAsymmetricSpritesheetFromTexture", "(", "tr", ",", "spriteRegions", ")", "\n", "}" ]
// NewSpritesheetFromTexture creates a new spritesheet from a texture resource.
[ "NewSpritesheetFromTexture", "creates", "a", "new", "spritesheet", "from", "a", "texture", "resource", "." ]
6f88a7379a25d81e976cf6e86ea3617f3b480b1a
https://github.com/EngoEngine/engo/blob/6f88a7379a25d81e976cf6e86ea3617f3b480b1a/common/spritesheet.go#L56-L59
12,617
EngoEngine/engo
common/spritesheet.go
NewSpritesheetFromFile
func NewSpritesheetFromFile(textureName string, cellWidth, cellHeight int) *Spritesheet { res, err := engo.Files.Resource(textureName) if err != nil { log.Println("[WARNING] [NewSpritesheetFromFile]: Received error:", err) return nil } img, ok := res.(TextureResource) if !ok { log.Println("[WARNING] [NewSpritesheetFromFile]: Resource not of type `TextureResource`:", textureName) return nil } return NewSpritesheetFromTexture(&img, cellWidth, cellHeight) }
go
func NewSpritesheetFromFile(textureName string, cellWidth, cellHeight int) *Spritesheet { res, err := engo.Files.Resource(textureName) if err != nil { log.Println("[WARNING] [NewSpritesheetFromFile]: Received error:", err) return nil } img, ok := res.(TextureResource) if !ok { log.Println("[WARNING] [NewSpritesheetFromFile]: Resource not of type `TextureResource`:", textureName) return nil } return NewSpritesheetFromTexture(&img, cellWidth, cellHeight) }
[ "func", "NewSpritesheetFromFile", "(", "textureName", "string", ",", "cellWidth", ",", "cellHeight", "int", ")", "*", "Spritesheet", "{", "res", ",", "err", ":=", "engo", ".", "Files", ".", "Resource", "(", "textureName", ")", "\n", "if", "err", "!=", "nil", "{", "log", ".", "Println", "(", "\"", "\"", ",", "err", ")", "\n", "return", "nil", "\n", "}", "\n\n", "img", ",", "ok", ":=", "res", ".", "(", "TextureResource", ")", "\n", "if", "!", "ok", "{", "log", ".", "Println", "(", "\"", "\"", ",", "textureName", ")", "\n", "return", "nil", "\n", "}", "\n\n", "return", "NewSpritesheetFromTexture", "(", "&", "img", ",", "cellWidth", ",", "cellHeight", ")", "\n", "}" ]
// NewSpritesheetFromFile is a simple handler for creating a new spritesheet from a file // textureName is the name of a texture already preloaded with engo.Files.Add
[ "NewSpritesheetFromFile", "is", "a", "simple", "handler", "for", "creating", "a", "new", "spritesheet", "from", "a", "file", "textureName", "is", "the", "name", "of", "a", "texture", "already", "preloaded", "with", "engo", ".", "Files", ".", "Add" ]
6f88a7379a25d81e976cf6e86ea3617f3b480b1a
https://github.com/EngoEngine/engo/blob/6f88a7379a25d81e976cf6e86ea3617f3b480b1a/common/spritesheet.go#L63-L77
12,618
EngoEngine/engo
common/spritesheet.go
NewSpritesheetWithBorderFromTexture
func NewSpritesheetWithBorderFromTexture(tr *TextureResource, cellWidth, cellHeight, borderWidth, borderHeight int) *Spritesheet { spriteRegions := generateSymmetricSpriteRegions(tr.Width, tr.Height, cellWidth, cellHeight, borderWidth, borderHeight) return NewAsymmetricSpritesheetFromTexture(tr, spriteRegions) }
go
func NewSpritesheetWithBorderFromTexture(tr *TextureResource, cellWidth, cellHeight, borderWidth, borderHeight int) *Spritesheet { spriteRegions := generateSymmetricSpriteRegions(tr.Width, tr.Height, cellWidth, cellHeight, borderWidth, borderHeight) return NewAsymmetricSpritesheetFromTexture(tr, spriteRegions) }
[ "func", "NewSpritesheetWithBorderFromTexture", "(", "tr", "*", "TextureResource", ",", "cellWidth", ",", "cellHeight", ",", "borderWidth", ",", "borderHeight", "int", ")", "*", "Spritesheet", "{", "spriteRegions", ":=", "generateSymmetricSpriteRegions", "(", "tr", ".", "Width", ",", "tr", ".", "Height", ",", "cellWidth", ",", "cellHeight", ",", "borderWidth", ",", "borderHeight", ")", "\n", "return", "NewAsymmetricSpritesheetFromTexture", "(", "tr", ",", "spriteRegions", ")", "\n", "}" ]
// NewSpritesheetWithBorderFromTexture creates a new spritesheet from a texture resource. // This sheet has sprites of a uniform width and height, but also have borders around // each sprite to prevent bleeding over
[ "NewSpritesheetWithBorderFromTexture", "creates", "a", "new", "spritesheet", "from", "a", "texture", "resource", ".", "This", "sheet", "has", "sprites", "of", "a", "uniform", "width", "and", "height", "but", "also", "have", "borders", "around", "each", "sprite", "to", "prevent", "bleeding", "over" ]
6f88a7379a25d81e976cf6e86ea3617f3b480b1a
https://github.com/EngoEngine/engo/blob/6f88a7379a25d81e976cf6e86ea3617f3b480b1a/common/spritesheet.go#L82-L85
12,619
EngoEngine/engo
common/spritesheet.go
NewSpritesheetWithBorderFromFile
func NewSpritesheetWithBorderFromFile(textureName string, cellWidth, cellHeight, borderWidth, borderHeight int) *Spritesheet { res, err := engo.Files.Resource(textureName) if err != nil { log.Println("[WARNING] [NewSpritesheetWithBorderFromFile]: Received error:", err) return nil } img, ok := res.(TextureResource) if !ok { log.Println("[WARNING] [NewSpritesheetWithBorderFromFile]: Resource not of type `TextureResource`:", textureName) return nil } return NewSpritesheetWithBorderFromTexture(&img, cellWidth, cellHeight, borderWidth, borderHeight) }
go
func NewSpritesheetWithBorderFromFile(textureName string, cellWidth, cellHeight, borderWidth, borderHeight int) *Spritesheet { res, err := engo.Files.Resource(textureName) if err != nil { log.Println("[WARNING] [NewSpritesheetWithBorderFromFile]: Received error:", err) return nil } img, ok := res.(TextureResource) if !ok { log.Println("[WARNING] [NewSpritesheetWithBorderFromFile]: Resource not of type `TextureResource`:", textureName) return nil } return NewSpritesheetWithBorderFromTexture(&img, cellWidth, cellHeight, borderWidth, borderHeight) }
[ "func", "NewSpritesheetWithBorderFromFile", "(", "textureName", "string", ",", "cellWidth", ",", "cellHeight", ",", "borderWidth", ",", "borderHeight", "int", ")", "*", "Spritesheet", "{", "res", ",", "err", ":=", "engo", ".", "Files", ".", "Resource", "(", "textureName", ")", "\n", "if", "err", "!=", "nil", "{", "log", ".", "Println", "(", "\"", "\"", ",", "err", ")", "\n", "return", "nil", "\n", "}", "\n\n", "img", ",", "ok", ":=", "res", ".", "(", "TextureResource", ")", "\n", "if", "!", "ok", "{", "log", ".", "Println", "(", "\"", "\"", ",", "textureName", ")", "\n", "return", "nil", "\n", "}", "\n\n", "return", "NewSpritesheetWithBorderFromTexture", "(", "&", "img", ",", "cellWidth", ",", "cellHeight", ",", "borderWidth", ",", "borderHeight", ")", "\n", "}" ]
// NewSpritesheetWithBorderFromFile creates a new spritesheet from a file // This sheet has sprites of a uniform width and height, but also have borders around // each sprite to prevent bleeding over
[ "NewSpritesheetWithBorderFromFile", "creates", "a", "new", "spritesheet", "from", "a", "file", "This", "sheet", "has", "sprites", "of", "a", "uniform", "width", "and", "height", "but", "also", "have", "borders", "around", "each", "sprite", "to", "prevent", "bleeding", "over" ]
6f88a7379a25d81e976cf6e86ea3617f3b480b1a
https://github.com/EngoEngine/engo/blob/6f88a7379a25d81e976cf6e86ea3617f3b480b1a/common/spritesheet.go#L90-L104
12,620
EngoEngine/engo
common/spritesheet.go
Cell
func (s *Spritesheet) Cell(index int) Texture { if r, ok := s.cache[index]; ok { return r } cell := s.cells[index] s.cache[index] = Texture{ id: s.texture, width: float32(cell.Width), height: float32(cell.Height), viewport: engo.AABB{ Min: engo.Point{ X: cell.Position.X / s.width, Y: cell.Position.Y / s.height, }, Max: engo.Point{ X: (cell.Position.X + float32(cell.Width)) / s.width, Y: (cell.Position.Y + float32(cell.Height)) / s.height, }, }, } return s.cache[index] }
go
func (s *Spritesheet) Cell(index int) Texture { if r, ok := s.cache[index]; ok { return r } cell := s.cells[index] s.cache[index] = Texture{ id: s.texture, width: float32(cell.Width), height: float32(cell.Height), viewport: engo.AABB{ Min: engo.Point{ X: cell.Position.X / s.width, Y: cell.Position.Y / s.height, }, Max: engo.Point{ X: (cell.Position.X + float32(cell.Width)) / s.width, Y: (cell.Position.Y + float32(cell.Height)) / s.height, }, }, } return s.cache[index] }
[ "func", "(", "s", "*", "Spritesheet", ")", "Cell", "(", "index", "int", ")", "Texture", "{", "if", "r", ",", "ok", ":=", "s", ".", "cache", "[", "index", "]", ";", "ok", "{", "return", "r", "\n", "}", "\n\n", "cell", ":=", "s", ".", "cells", "[", "index", "]", "\n", "s", ".", "cache", "[", "index", "]", "=", "Texture", "{", "id", ":", "s", ".", "texture", ",", "width", ":", "float32", "(", "cell", ".", "Width", ")", ",", "height", ":", "float32", "(", "cell", ".", "Height", ")", ",", "viewport", ":", "engo", ".", "AABB", "{", "Min", ":", "engo", ".", "Point", "{", "X", ":", "cell", ".", "Position", ".", "X", "/", "s", ".", "width", ",", "Y", ":", "cell", ".", "Position", ".", "Y", "/", "s", ".", "height", ",", "}", ",", "Max", ":", "engo", ".", "Point", "{", "X", ":", "(", "cell", ".", "Position", ".", "X", "+", "float32", "(", "cell", ".", "Width", ")", ")", "/", "s", ".", "width", ",", "Y", ":", "(", "cell", ".", "Position", ".", "Y", "+", "float32", "(", "cell", ".", "Height", ")", ")", "/", "s", ".", "height", ",", "}", ",", "}", ",", "}", "\n\n", "return", "s", ".", "cache", "[", "index", "]", "\n", "}" ]
// Cell gets the region at the index i, updates and pulls from cache if need be
[ "Cell", "gets", "the", "region", "at", "the", "index", "i", "updates", "and", "pulls", "from", "cache", "if", "need", "be" ]
6f88a7379a25d81e976cf6e86ea3617f3b480b1a
https://github.com/EngoEngine/engo/blob/6f88a7379a25d81e976cf6e86ea3617f3b480b1a/common/spritesheet.go#L107-L130
12,621
EngoEngine/engo
common/spritesheet.go
Drawables
func (s *Spritesheet) Drawables() []Drawable { drawables := make([]Drawable, s.CellCount()) for i := 0; i < s.CellCount(); i++ { drawables[i] = s.Drawable(i) } return drawables }
go
func (s *Spritesheet) Drawables() []Drawable { drawables := make([]Drawable, s.CellCount()) for i := 0; i < s.CellCount(); i++ { drawables[i] = s.Drawable(i) } return drawables }
[ "func", "(", "s", "*", "Spritesheet", ")", "Drawables", "(", ")", "[", "]", "Drawable", "{", "drawables", ":=", "make", "(", "[", "]", "Drawable", ",", "s", ".", "CellCount", "(", ")", ")", "\n\n", "for", "i", ":=", "0", ";", "i", "<", "s", ".", "CellCount", "(", ")", ";", "i", "++", "{", "drawables", "[", "i", "]", "=", "s", ".", "Drawable", "(", "i", ")", "\n", "}", "\n\n", "return", "drawables", "\n", "}" ]
// Drawables returns all the drawables on the sheet
[ "Drawables", "returns", "all", "the", "drawables", "on", "the", "sheet" ]
6f88a7379a25d81e976cf6e86ea3617f3b480b1a
https://github.com/EngoEngine/engo/blob/6f88a7379a25d81e976cf6e86ea3617f3b480b1a/common/spritesheet.go#L138-L146
12,622
EngoEngine/engo
common/spritesheet.go
Cells
func (s *Spritesheet) Cells() []Texture { cellsNo := s.CellCount() cells := make([]Texture, cellsNo) for i := 0; i < cellsNo; i++ { cells[i] = s.Cell(i) } return cells }
go
func (s *Spritesheet) Cells() []Texture { cellsNo := s.CellCount() cells := make([]Texture, cellsNo) for i := 0; i < cellsNo; i++ { cells[i] = s.Cell(i) } return cells }
[ "func", "(", "s", "*", "Spritesheet", ")", "Cells", "(", ")", "[", "]", "Texture", "{", "cellsNo", ":=", "s", ".", "CellCount", "(", ")", "\n", "cells", ":=", "make", "(", "[", "]", "Texture", ",", "cellsNo", ")", "\n", "for", "i", ":=", "0", ";", "i", "<", "cellsNo", ";", "i", "++", "{", "cells", "[", "i", "]", "=", "s", ".", "Cell", "(", "i", ")", "\n", "}", "\n\n", "return", "cells", "\n", "}" ]
// Cells returns all the cells on the sheet
[ "Cells", "returns", "all", "the", "cells", "on", "the", "sheet" ]
6f88a7379a25d81e976cf6e86ea3617f3b480b1a
https://github.com/EngoEngine/engo/blob/6f88a7379a25d81e976cf6e86ea3617f3b480b1a/common/spritesheet.go#L154-L162
12,623
EngoEngine/engo
common/render_shaders.go
colorToFloat32
func colorToFloat32(c color.Color) float32 { colorR, colorG, colorB, colorA := c.RGBA() colorR >>= 8 colorG >>= 8 colorB >>= 8 colorA >>= 8 red := colorR green := colorG << 8 blue := colorB << 16 alpha := colorA << 24 return math.Float32frombits((alpha | blue | green | red) & 0xfeffffff) }
go
func colorToFloat32(c color.Color) float32 { colorR, colorG, colorB, colorA := c.RGBA() colorR >>= 8 colorG >>= 8 colorB >>= 8 colorA >>= 8 red := colorR green := colorG << 8 blue := colorB << 16 alpha := colorA << 24 return math.Float32frombits((alpha | blue | green | red) & 0xfeffffff) }
[ "func", "colorToFloat32", "(", "c", "color", ".", "Color", ")", "float32", "{", "colorR", ",", "colorG", ",", "colorB", ",", "colorA", ":=", "c", ".", "RGBA", "(", ")", "\n", "colorR", ">>=", "8", "\n", "colorG", ">>=", "8", "\n", "colorB", ">>=", "8", "\n", "colorA", ">>=", "8", "\n\n", "red", ":=", "colorR", "\n", "green", ":=", "colorG", "<<", "8", "\n", "blue", ":=", "colorB", "<<", "16", "\n", "alpha", ":=", "colorA", "<<", "24", "\n\n", "return", "math", ".", "Float32frombits", "(", "(", "alpha", "|", "blue", "|", "green", "|", "red", ")", "&", "0xfeffffff", ")", "\n", "}" ]
// colorToFloat32 returns the float32 representation of the given color
[ "colorToFloat32", "returns", "the", "float32", "representation", "of", "the", "given", "color" ]
6f88a7379a25d81e976cf6e86ea3617f3b480b1a
https://github.com/EngoEngine/engo/blob/6f88a7379a25d81e976cf6e86ea3617f3b480b1a/common/render_shaders.go#L1215-L1228
12,624
EngoEngine/engo
common/render_shaders.go
LoadShader
func LoadShader(vertSrc, fragSrc string) (*gl.Program, error) { vertShader := engo.Gl.CreateShader(engo.Gl.VERTEX_SHADER) engo.Gl.ShaderSource(vertShader, vertSrc) engo.Gl.CompileShader(vertShader) if !engo.Gl.GetShaderiv(vertShader, engo.Gl.COMPILE_STATUS) { errorLog := engo.Gl.GetShaderInfoLog(vertShader) return nil, VertexShaderCompilationError{errorLog} } defer engo.Gl.DeleteShader(vertShader) fragShader := engo.Gl.CreateShader(engo.Gl.FRAGMENT_SHADER) engo.Gl.ShaderSource(fragShader, fragSrc) engo.Gl.CompileShader(fragShader) if !engo.Gl.GetShaderiv(fragShader, engo.Gl.COMPILE_STATUS) { errorLog := engo.Gl.GetShaderInfoLog(fragShader) return nil, FragmentShaderCompilationError{errorLog} } defer engo.Gl.DeleteShader(fragShader) program := engo.Gl.CreateProgram() engo.Gl.AttachShader(program, vertShader) engo.Gl.AttachShader(program, fragShader) engo.Gl.LinkProgram(program) return program, nil }
go
func LoadShader(vertSrc, fragSrc string) (*gl.Program, error) { vertShader := engo.Gl.CreateShader(engo.Gl.VERTEX_SHADER) engo.Gl.ShaderSource(vertShader, vertSrc) engo.Gl.CompileShader(vertShader) if !engo.Gl.GetShaderiv(vertShader, engo.Gl.COMPILE_STATUS) { errorLog := engo.Gl.GetShaderInfoLog(vertShader) return nil, VertexShaderCompilationError{errorLog} } defer engo.Gl.DeleteShader(vertShader) fragShader := engo.Gl.CreateShader(engo.Gl.FRAGMENT_SHADER) engo.Gl.ShaderSource(fragShader, fragSrc) engo.Gl.CompileShader(fragShader) if !engo.Gl.GetShaderiv(fragShader, engo.Gl.COMPILE_STATUS) { errorLog := engo.Gl.GetShaderInfoLog(fragShader) return nil, FragmentShaderCompilationError{errorLog} } defer engo.Gl.DeleteShader(fragShader) program := engo.Gl.CreateProgram() engo.Gl.AttachShader(program, vertShader) engo.Gl.AttachShader(program, fragShader) engo.Gl.LinkProgram(program) return program, nil }
[ "func", "LoadShader", "(", "vertSrc", ",", "fragSrc", "string", ")", "(", "*", "gl", ".", "Program", ",", "error", ")", "{", "vertShader", ":=", "engo", ".", "Gl", ".", "CreateShader", "(", "engo", ".", "Gl", ".", "VERTEX_SHADER", ")", "\n", "engo", ".", "Gl", ".", "ShaderSource", "(", "vertShader", ",", "vertSrc", ")", "\n", "engo", ".", "Gl", ".", "CompileShader", "(", "vertShader", ")", "\n", "if", "!", "engo", ".", "Gl", ".", "GetShaderiv", "(", "vertShader", ",", "engo", ".", "Gl", ".", "COMPILE_STATUS", ")", "{", "errorLog", ":=", "engo", ".", "Gl", ".", "GetShaderInfoLog", "(", "vertShader", ")", "\n", "return", "nil", ",", "VertexShaderCompilationError", "{", "errorLog", "}", "\n", "}", "\n", "defer", "engo", ".", "Gl", ".", "DeleteShader", "(", "vertShader", ")", "\n\n", "fragShader", ":=", "engo", ".", "Gl", ".", "CreateShader", "(", "engo", ".", "Gl", ".", "FRAGMENT_SHADER", ")", "\n", "engo", ".", "Gl", ".", "ShaderSource", "(", "fragShader", ",", "fragSrc", ")", "\n", "engo", ".", "Gl", ".", "CompileShader", "(", "fragShader", ")", "\n", "if", "!", "engo", ".", "Gl", ".", "GetShaderiv", "(", "fragShader", ",", "engo", ".", "Gl", ".", "COMPILE_STATUS", ")", "{", "errorLog", ":=", "engo", ".", "Gl", ".", "GetShaderInfoLog", "(", "fragShader", ")", "\n", "return", "nil", ",", "FragmentShaderCompilationError", "{", "errorLog", "}", "\n", "}", "\n", "defer", "engo", ".", "Gl", ".", "DeleteShader", "(", "fragShader", ")", "\n\n", "program", ":=", "engo", ".", "Gl", ".", "CreateProgram", "(", ")", "\n", "engo", ".", "Gl", ".", "AttachShader", "(", "program", ",", "vertShader", ")", "\n", "engo", ".", "Gl", ".", "AttachShader", "(", "program", ",", "fragShader", ")", "\n", "engo", ".", "Gl", ".", "LinkProgram", "(", "program", ")", "\n\n", "return", "program", ",", "nil", "\n", "}" ]
// LoadShader takes a Vertex-shader and Fragment-shader, compiles them and attaches them to a newly created glProgram. // It will log possible compilation errors
[ "LoadShader", "takes", "a", "Vertex", "-", "shader", "and", "Fragment", "-", "shader", "compiles", "them", "and", "attaches", "them", "to", "a", "newly", "created", "glProgram", ".", "It", "will", "log", "possible", "compilation", "errors" ]
6f88a7379a25d81e976cf6e86ea3617f3b480b1a
https://github.com/EngoEngine/engo/blob/6f88a7379a25d81e976cf6e86ea3617f3b480b1a/common/render_shaders.go#L1287-L1312
12,625
EngoEngine/engo
common/render.go
SetShader
func (r *RenderComponent) SetShader(s Shader) { r.shader = s engo.Mailbox.Dispatch(&renderChangeMessage{}) }
go
func (r *RenderComponent) SetShader(s Shader) { r.shader = s engo.Mailbox.Dispatch(&renderChangeMessage{}) }
[ "func", "(", "r", "*", "RenderComponent", ")", "SetShader", "(", "s", "Shader", ")", "{", "r", ".", "shader", "=", "s", "\n", "engo", ".", "Mailbox", ".", "Dispatch", "(", "&", "renderChangeMessage", "{", "}", ")", "\n", "}" ]
// SetShader sets the shader used by the RenderComponent.
[ "SetShader", "sets", "the", "shader", "used", "by", "the", "RenderComponent", "." ]
6f88a7379a25d81e976cf6e86ea3617f3b480b1a
https://github.com/EngoEngine/engo/blob/6f88a7379a25d81e976cf6e86ea3617f3b480b1a/common/render.go#L91-L94
12,626
EngoEngine/engo
common/render.go
SetZIndex
func (r *RenderComponent) SetZIndex(index float32) { r.zIndex = index engo.Mailbox.Dispatch(&renderChangeMessage{}) }
go
func (r *RenderComponent) SetZIndex(index float32) { r.zIndex = index engo.Mailbox.Dispatch(&renderChangeMessage{}) }
[ "func", "(", "r", "*", "RenderComponent", ")", "SetZIndex", "(", "index", "float32", ")", "{", "r", ".", "zIndex", "=", "index", "\n", "engo", ".", "Mailbox", ".", "Dispatch", "(", "&", "renderChangeMessage", "{", "}", ")", "\n", "}" ]
// SetZIndex sets the order that the RenderComponent is drawn to the screen. Higher z-indices are drawn on top of // lower ones if they overlap.
[ "SetZIndex", "sets", "the", "order", "that", "the", "RenderComponent", "is", "drawn", "to", "the", "screen", ".", "Higher", "z", "-", "indices", "are", "drawn", "on", "top", "of", "lower", "ones", "if", "they", "overlap", "." ]
6f88a7379a25d81e976cf6e86ea3617f3b480b1a
https://github.com/EngoEngine/engo/blob/6f88a7379a25d81e976cf6e86ea3617f3b480b1a/common/render.go#L125-L128
12,627
EngoEngine/engo
common/render.go
SetMinFilter
func (r *RenderComponent) SetMinFilter(z ZoomFilter) { r.minFilter = z engo.Mailbox.Dispatch(renderChangeMessage{}) }
go
func (r *RenderComponent) SetMinFilter(z ZoomFilter) { r.minFilter = z engo.Mailbox.Dispatch(renderChangeMessage{}) }
[ "func", "(", "r", "*", "RenderComponent", ")", "SetMinFilter", "(", "z", "ZoomFilter", ")", "{", "r", ".", "minFilter", "=", "z", "\n", "engo", ".", "Mailbox", ".", "Dispatch", "(", "renderChangeMessage", "{", "}", ")", "\n", "}" ]
// SetMinFilter sets the ZoomFilter used for minimizing the RenderComponent
[ "SetMinFilter", "sets", "the", "ZoomFilter", "used", "for", "minimizing", "the", "RenderComponent" ]
6f88a7379a25d81e976cf6e86ea3617f3b480b1a
https://github.com/EngoEngine/engo/blob/6f88a7379a25d81e976cf6e86ea3617f3b480b1a/common/render.go#L131-L134
12,628
EngoEngine/engo
common/render.go
SetMagFilter
func (r *RenderComponent) SetMagFilter(z ZoomFilter) { r.magFilter = z engo.Mailbox.Dispatch(renderChangeMessage{}) }
go
func (r *RenderComponent) SetMagFilter(z ZoomFilter) { r.magFilter = z engo.Mailbox.Dispatch(renderChangeMessage{}) }
[ "func", "(", "r", "*", "RenderComponent", ")", "SetMagFilter", "(", "z", "ZoomFilter", ")", "{", "r", ".", "magFilter", "=", "z", "\n", "engo", ".", "Mailbox", ".", "Dispatch", "(", "renderChangeMessage", "{", "}", ")", "\n", "}" ]
// SetMagFilter sets the ZoomFilter used for magnifying the RenderComponent
[ "SetMagFilter", "sets", "the", "ZoomFilter", "used", "for", "magnifying", "the", "RenderComponent" ]
6f88a7379a25d81e976cf6e86ea3617f3b480b1a
https://github.com/EngoEngine/engo/blob/6f88a7379a25d81e976cf6e86ea3617f3b480b1a/common/render.go#L137-L140
12,629
EngoEngine/engo
common/render.go
New
func (rs *RenderSystem) New(w *ecs.World) { rs.world = w rs.ids = make(map[uint64]struct{}) engo.Mailbox.Listen("NewCameraMessage", func(engo.Message) { rs.newCamera = true }) addCameraSystemOnce(w) if !engo.Headless() { if err := initShaders(w); err != nil { panic(err) } engo.Gl.Enable(engo.Gl.MULTISAMPLE) } engo.Mailbox.Listen("renderChangeMessage", func(engo.Message) { rs.sortingNeeded = true }) }
go
func (rs *RenderSystem) New(w *ecs.World) { rs.world = w rs.ids = make(map[uint64]struct{}) engo.Mailbox.Listen("NewCameraMessage", func(engo.Message) { rs.newCamera = true }) addCameraSystemOnce(w) if !engo.Headless() { if err := initShaders(w); err != nil { panic(err) } engo.Gl.Enable(engo.Gl.MULTISAMPLE) } engo.Mailbox.Listen("renderChangeMessage", func(engo.Message) { rs.sortingNeeded = true }) }
[ "func", "(", "rs", "*", "RenderSystem", ")", "New", "(", "w", "*", "ecs", ".", "World", ")", "{", "rs", ".", "world", "=", "w", "\n", "rs", ".", "ids", "=", "make", "(", "map", "[", "uint64", "]", "struct", "{", "}", ")", "\n\n", "engo", ".", "Mailbox", ".", "Listen", "(", "\"", "\"", ",", "func", "(", "engo", ".", "Message", ")", "{", "rs", ".", "newCamera", "=", "true", "\n", "}", ")", "\n\n", "addCameraSystemOnce", "(", "w", ")", "\n\n", "if", "!", "engo", ".", "Headless", "(", ")", "{", "if", "err", ":=", "initShaders", "(", "w", ")", ";", "err", "!=", "nil", "{", "panic", "(", "err", ")", "\n", "}", "\n", "engo", ".", "Gl", ".", "Enable", "(", "engo", ".", "Gl", ".", "MULTISAMPLE", ")", "\n", "}", "\n\n", "engo", ".", "Mailbox", ".", "Listen", "(", "\"", "\"", ",", "func", "(", "engo", ".", "Message", ")", "{", "rs", ".", "sortingNeeded", "=", "true", "\n", "}", ")", "\n", "}" ]
// New initializes the RenderSystem
[ "New", "initializes", "the", "RenderSystem" ]
6f88a7379a25d81e976cf6e86ea3617f3b480b1a
https://github.com/EngoEngine/engo/blob/6f88a7379a25d81e976cf6e86ea3617f3b480b1a/common/render.go#L234-L254
12,630
EngoEngine/engo
common/render.go
Add
func (rs *RenderSystem) Add(basic *ecs.BasicEntity, render *RenderComponent, space *SpaceComponent) { // Do nothing if entity already exists if _, ok := rs.ids[basic.ID()]; ok { return } rs.ids[basic.ID()] = struct{}{} render.ensureShader() // This is to prevent users from using the wrong one if render.shader == HUDShader { switch render.Drawable.(type) { case Triangle: render.shader = LegacyHUDShader case Circle: render.shader = LegacyHUDShader case Rectangle: render.shader = LegacyHUDShader case ComplexTriangles: render.shader = LegacyHUDShader case Text: render.shader = TextHUDShader default: render.shader = HUDShader } } // If the scale is zero, set it to one. if render.Scale.X == 0 { render.Scale.X = 1 } if render.Scale.Y == 0 { render.Scale.Y = 1 } rs.entities = append(rs.entities, renderEntity{basic, render, space}) rs.sortingNeeded = true }
go
func (rs *RenderSystem) Add(basic *ecs.BasicEntity, render *RenderComponent, space *SpaceComponent) { // Do nothing if entity already exists if _, ok := rs.ids[basic.ID()]; ok { return } rs.ids[basic.ID()] = struct{}{} render.ensureShader() // This is to prevent users from using the wrong one if render.shader == HUDShader { switch render.Drawable.(type) { case Triangle: render.shader = LegacyHUDShader case Circle: render.shader = LegacyHUDShader case Rectangle: render.shader = LegacyHUDShader case ComplexTriangles: render.shader = LegacyHUDShader case Text: render.shader = TextHUDShader default: render.shader = HUDShader } } // If the scale is zero, set it to one. if render.Scale.X == 0 { render.Scale.X = 1 } if render.Scale.Y == 0 { render.Scale.Y = 1 } rs.entities = append(rs.entities, renderEntity{basic, render, space}) rs.sortingNeeded = true }
[ "func", "(", "rs", "*", "RenderSystem", ")", "Add", "(", "basic", "*", "ecs", ".", "BasicEntity", ",", "render", "*", "RenderComponent", ",", "space", "*", "SpaceComponent", ")", "{", "// Do nothing if entity already exists", "if", "_", ",", "ok", ":=", "rs", ".", "ids", "[", "basic", ".", "ID", "(", ")", "]", ";", "ok", "{", "return", "\n", "}", "\n\n", "rs", ".", "ids", "[", "basic", ".", "ID", "(", ")", "]", "=", "struct", "{", "}", "{", "}", "\n\n", "render", ".", "ensureShader", "(", ")", "\n\n", "// This is to prevent users from using the wrong one", "if", "render", ".", "shader", "==", "HUDShader", "{", "switch", "render", ".", "Drawable", ".", "(", "type", ")", "{", "case", "Triangle", ":", "render", ".", "shader", "=", "LegacyHUDShader", "\n", "case", "Circle", ":", "render", ".", "shader", "=", "LegacyHUDShader", "\n", "case", "Rectangle", ":", "render", ".", "shader", "=", "LegacyHUDShader", "\n", "case", "ComplexTriangles", ":", "render", ".", "shader", "=", "LegacyHUDShader", "\n", "case", "Text", ":", "render", ".", "shader", "=", "TextHUDShader", "\n", "default", ":", "render", ".", "shader", "=", "HUDShader", "\n", "}", "\n", "}", "\n\n", "// If the scale is zero, set it to one.", "if", "render", ".", "Scale", ".", "X", "==", "0", "{", "render", ".", "Scale", ".", "X", "=", "1", "\n", "}", "\n", "if", "render", ".", "Scale", ".", "Y", "==", "0", "{", "render", ".", "Scale", ".", "Y", "=", "1", "\n", "}", "\n\n", "rs", ".", "entities", "=", "append", "(", "rs", ".", "entities", ",", "renderEntity", "{", "basic", ",", "render", ",", "space", "}", ")", "\n", "rs", ".", "sortingNeeded", "=", "true", "\n", "}" ]
// Add adds an entity to the RenderSystem. The entity needs a basic, render, and space component to be added to the system.
[ "Add", "adds", "an", "entity", "to", "the", "RenderSystem", ".", "The", "entity", "needs", "a", "basic", "render", "and", "space", "component", "to", "be", "added", "to", "the", "system", "." ]
6f88a7379a25d81e976cf6e86ea3617f3b480b1a
https://github.com/EngoEngine/engo/blob/6f88a7379a25d81e976cf6e86ea3617f3b480b1a/common/render.go#L275-L313
12,631
EngoEngine/engo
common/render.go
EntityExists
func (rs *RenderSystem) EntityExists(basic *ecs.BasicEntity) int { for index, entity := range rs.entities { if entity.ID() == basic.ID() { return index } } return -1 }
go
func (rs *RenderSystem) EntityExists(basic *ecs.BasicEntity) int { for index, entity := range rs.entities { if entity.ID() == basic.ID() { return index } } return -1 }
[ "func", "(", "rs", "*", "RenderSystem", ")", "EntityExists", "(", "basic", "*", "ecs", ".", "BasicEntity", ")", "int", "{", "for", "index", ",", "entity", ":=", "range", "rs", ".", "entities", "{", "if", "entity", ".", "ID", "(", ")", "==", "basic", ".", "ID", "(", ")", "{", "return", "index", "\n", "}", "\n", "}", "\n\n", "return", "-", "1", "\n", "}" ]
// EntityExists looks if the entity is already into the System's entities. It will return the index >= 0 of the object into de rs.entities or -1 if it could not be found.
[ "EntityExists", "looks", "if", "the", "entity", "is", "already", "into", "the", "System", "s", "entities", ".", "It", "will", "return", "the", "index", ">", "=", "0", "of", "the", "object", "into", "de", "rs", ".", "entities", "or", "-", "1", "if", "it", "could", "not", "be", "found", "." ]
6f88a7379a25d81e976cf6e86ea3617f3b480b1a
https://github.com/EngoEngine/engo/blob/6f88a7379a25d81e976cf6e86ea3617f3b480b1a/common/render.go#L316-L324
12,632
EngoEngine/engo
common/render.go
AddByInterface
func (rs *RenderSystem) AddByInterface(i ecs.Identifier) { o, _ := i.(Renderable) rs.Add(o.GetBasicEntity(), o.GetRenderComponent(), o.GetSpaceComponent()) }
go
func (rs *RenderSystem) AddByInterface(i ecs.Identifier) { o, _ := i.(Renderable) rs.Add(o.GetBasicEntity(), o.GetRenderComponent(), o.GetSpaceComponent()) }
[ "func", "(", "rs", "*", "RenderSystem", ")", "AddByInterface", "(", "i", "ecs", ".", "Identifier", ")", "{", "o", ",", "_", ":=", "i", ".", "(", "Renderable", ")", "\n", "rs", ".", "Add", "(", "o", ".", "GetBasicEntity", "(", ")", ",", "o", ".", "GetRenderComponent", "(", ")", ",", "o", ".", "GetSpaceComponent", "(", ")", ")", "\n", "}" ]
// AddByInterface adds any Renderable to the render system. Any Entity containing a BasicEntity,RenderComponent, and SpaceComponent anonymously does this automatically
[ "AddByInterface", "adds", "any", "Renderable", "to", "the", "render", "system", ".", "Any", "Entity", "containing", "a", "BasicEntity", "RenderComponent", "and", "SpaceComponent", "anonymously", "does", "this", "automatically" ]
6f88a7379a25d81e976cf6e86ea3617f3b480b1a
https://github.com/EngoEngine/engo/blob/6f88a7379a25d81e976cf6e86ea3617f3b480b1a/common/render.go#L327-L330
12,633
EngoEngine/engo
common/render.go
Remove
func (rs *RenderSystem) Remove(basic ecs.BasicEntity) { var d = rs.EntityExists(&basic) if d >= 0 { rs.entities = append(rs.entities[:d], rs.entities[d+1:]...) rs.sortingNeeded = true } delete(rs.ids, basic.ID()) }
go
func (rs *RenderSystem) Remove(basic ecs.BasicEntity) { var d = rs.EntityExists(&basic) if d >= 0 { rs.entities = append(rs.entities[:d], rs.entities[d+1:]...) rs.sortingNeeded = true } delete(rs.ids, basic.ID()) }
[ "func", "(", "rs", "*", "RenderSystem", ")", "Remove", "(", "basic", "ecs", ".", "BasicEntity", ")", "{", "var", "d", "=", "rs", ".", "EntityExists", "(", "&", "basic", ")", "\n", "if", "d", ">=", "0", "{", "rs", ".", "entities", "=", "append", "(", "rs", ".", "entities", "[", ":", "d", "]", ",", "rs", ".", "entities", "[", "d", "+", "1", ":", "]", "...", ")", "\n", "rs", ".", "sortingNeeded", "=", "true", "\n", "}", "\n", "delete", "(", "rs", ".", "ids", ",", "basic", ".", "ID", "(", ")", ")", "\n", "}" ]
// Remove removes an entity from the RenderSystem
[ "Remove", "removes", "an", "entity", "from", "the", "RenderSystem" ]
6f88a7379a25d81e976cf6e86ea3617f3b480b1a
https://github.com/EngoEngine/engo/blob/6f88a7379a25d81e976cf6e86ea3617f3b480b1a/common/render.go#L333-L340
12,634
EngoEngine/engo
common/render.go
Update
func (rs *RenderSystem) Update(dt float32) { if engo.Headless() { return } if rs.sortingNeeded { sort.Sort(rs.entities) rs.sortingNeeded = false } if rs.newCamera { newCamera(rs.world) rs.newCamera = false } engo.Gl.Clear(engo.Gl.COLOR_BUFFER_BIT) preparedCullingShaders := make(map[CullingShader]struct{}) var cullingShader CullingShader // current culling shader var prevShader Shader // shader of the previous entity var currentShader Shader // currently "active" shader // TODO: it's linear for now, but that might very well be a bad idea for _, e := range rs.entities { if e.RenderComponent.Hidden { continue // with other entities } // Retrieve a shader, may be the default one -- then use it if we aren't already using it shader := e.RenderComponent.shader if !compareShaders(shader, prevShader) { // to increase performance avoid the type assertions when possible prevShader = shader if cs, ok := shader.(CullingShader); ok { cullingShader = cs if _, isPrepared := preparedCullingShaders[cullingShader]; !isPrepared { cullingShader.PrepareCulling() preparedCullingShaders[cullingShader] = struct{}{} } } else { cullingShader = nil } } if cullingShader != nil && !cullingShader.ShouldDraw(e.RenderComponent, e.SpaceComponent) { continue } // Change Shader if we have to if !compareShaders(shader, currentShader) { if currentShader != nil { currentShader.Post() } shader.Pre() currentShader = shader } // Setting default scale to 1 if e.RenderComponent.Scale.X == 0 && e.RenderComponent.Scale.Y == 0 { e.RenderComponent.Scale = engo.Point{X: 1, Y: 1} } // Setting default to white if e.RenderComponent.Color == nil { e.RenderComponent.Color = color.White } currentShader.Draw(e.RenderComponent, e.SpaceComponent) } if currentShader != nil { currentShader.Post() } }
go
func (rs *RenderSystem) Update(dt float32) { if engo.Headless() { return } if rs.sortingNeeded { sort.Sort(rs.entities) rs.sortingNeeded = false } if rs.newCamera { newCamera(rs.world) rs.newCamera = false } engo.Gl.Clear(engo.Gl.COLOR_BUFFER_BIT) preparedCullingShaders := make(map[CullingShader]struct{}) var cullingShader CullingShader // current culling shader var prevShader Shader // shader of the previous entity var currentShader Shader // currently "active" shader // TODO: it's linear for now, but that might very well be a bad idea for _, e := range rs.entities { if e.RenderComponent.Hidden { continue // with other entities } // Retrieve a shader, may be the default one -- then use it if we aren't already using it shader := e.RenderComponent.shader if !compareShaders(shader, prevShader) { // to increase performance avoid the type assertions when possible prevShader = shader if cs, ok := shader.(CullingShader); ok { cullingShader = cs if _, isPrepared := preparedCullingShaders[cullingShader]; !isPrepared { cullingShader.PrepareCulling() preparedCullingShaders[cullingShader] = struct{}{} } } else { cullingShader = nil } } if cullingShader != nil && !cullingShader.ShouldDraw(e.RenderComponent, e.SpaceComponent) { continue } // Change Shader if we have to if !compareShaders(shader, currentShader) { if currentShader != nil { currentShader.Post() } shader.Pre() currentShader = shader } // Setting default scale to 1 if e.RenderComponent.Scale.X == 0 && e.RenderComponent.Scale.Y == 0 { e.RenderComponent.Scale = engo.Point{X: 1, Y: 1} } // Setting default to white if e.RenderComponent.Color == nil { e.RenderComponent.Color = color.White } currentShader.Draw(e.RenderComponent, e.SpaceComponent) } if currentShader != nil { currentShader.Post() } }
[ "func", "(", "rs", "*", "RenderSystem", ")", "Update", "(", "dt", "float32", ")", "{", "if", "engo", ".", "Headless", "(", ")", "{", "return", "\n", "}", "\n\n", "if", "rs", ".", "sortingNeeded", "{", "sort", ".", "Sort", "(", "rs", ".", "entities", ")", "\n", "rs", ".", "sortingNeeded", "=", "false", "\n", "}", "\n\n", "if", "rs", ".", "newCamera", "{", "newCamera", "(", "rs", ".", "world", ")", "\n", "rs", ".", "newCamera", "=", "false", "\n", "}", "\n\n", "engo", ".", "Gl", ".", "Clear", "(", "engo", ".", "Gl", ".", "COLOR_BUFFER_BIT", ")", "\n\n", "preparedCullingShaders", ":=", "make", "(", "map", "[", "CullingShader", "]", "struct", "{", "}", ")", "\n", "var", "cullingShader", "CullingShader", "// current culling shader", "\n", "var", "prevShader", "Shader", "// shader of the previous entity", "\n", "var", "currentShader", "Shader", "// currently \"active\" shader", "\n\n", "// TODO: it's linear for now, but that might very well be a bad idea", "for", "_", ",", "e", ":=", "range", "rs", ".", "entities", "{", "if", "e", ".", "RenderComponent", ".", "Hidden", "{", "continue", "// with other entities", "\n", "}", "\n\n", "// Retrieve a shader, may be the default one -- then use it if we aren't already using it", "shader", ":=", "e", ".", "RenderComponent", ".", "shader", "\n\n", "if", "!", "compareShaders", "(", "shader", ",", "prevShader", ")", "{", "// to increase performance avoid the type assertions when possible", "prevShader", "=", "shader", "\n", "if", "cs", ",", "ok", ":=", "shader", ".", "(", "CullingShader", ")", ";", "ok", "{", "cullingShader", "=", "cs", "\n", "if", "_", ",", "isPrepared", ":=", "preparedCullingShaders", "[", "cullingShader", "]", ";", "!", "isPrepared", "{", "cullingShader", ".", "PrepareCulling", "(", ")", "\n", "preparedCullingShaders", "[", "cullingShader", "]", "=", "struct", "{", "}", "{", "}", "\n", "}", "\n", "}", "else", "{", "cullingShader", "=", "nil", "\n", "}", "\n", "}", "\n\n", "if", "cullingShader", "!=", "nil", "&&", "!", "cullingShader", ".", "ShouldDraw", "(", "e", ".", "RenderComponent", ",", "e", ".", "SpaceComponent", ")", "{", "continue", "\n", "}", "\n\n", "// Change Shader if we have to", "if", "!", "compareShaders", "(", "shader", ",", "currentShader", ")", "{", "if", "currentShader", "!=", "nil", "{", "currentShader", ".", "Post", "(", ")", "\n", "}", "\n", "shader", ".", "Pre", "(", ")", "\n", "currentShader", "=", "shader", "\n", "}", "\n\n", "// Setting default scale to 1", "if", "e", ".", "RenderComponent", ".", "Scale", ".", "X", "==", "0", "&&", "e", ".", "RenderComponent", ".", "Scale", ".", "Y", "==", "0", "{", "e", ".", "RenderComponent", ".", "Scale", "=", "engo", ".", "Point", "{", "X", ":", "1", ",", "Y", ":", "1", "}", "\n", "}", "\n\n", "// Setting default to white", "if", "e", ".", "RenderComponent", ".", "Color", "==", "nil", "{", "e", ".", "RenderComponent", ".", "Color", "=", "color", ".", "White", "\n", "}", "\n\n", "currentShader", ".", "Draw", "(", "e", ".", "RenderComponent", ",", "e", ".", "SpaceComponent", ")", "\n", "}", "\n\n", "if", "currentShader", "!=", "nil", "{", "currentShader", ".", "Post", "(", ")", "\n", "}", "\n", "}" ]
// Update draws the entities in the RenderSystem to the OpenGL Surface.
[ "Update", "draws", "the", "entities", "in", "the", "RenderSystem", "to", "the", "OpenGL", "Surface", "." ]
6f88a7379a25d81e976cf6e86ea3617f3b480b1a
https://github.com/EngoEngine/engo/blob/6f88a7379a25d81e976cf6e86ea3617f3b480b1a/common/render.go#L343-L417
12,635
EngoEngine/engo
common/render.go
SetBackground
func SetBackground(c color.Color) { if !engo.Headless() { r, g, b, a := c.RGBA() engo.Gl.ClearColor(float32(r)/0xffff, float32(g)/0xffff, float32(b)/0xffff, float32(a)/0xffff) } }
go
func SetBackground(c color.Color) { if !engo.Headless() { r, g, b, a := c.RGBA() engo.Gl.ClearColor(float32(r)/0xffff, float32(g)/0xffff, float32(b)/0xffff, float32(a)/0xffff) } }
[ "func", "SetBackground", "(", "c", "color", ".", "Color", ")", "{", "if", "!", "engo", ".", "Headless", "(", ")", "{", "r", ",", "g", ",", "b", ",", "a", ":=", "c", ".", "RGBA", "(", ")", "\n\n", "engo", ".", "Gl", ".", "ClearColor", "(", "float32", "(", "r", ")", "/", "0xffff", ",", "float32", "(", "g", ")", "/", "0xffff", ",", "float32", "(", "b", ")", "/", "0xffff", ",", "float32", "(", "a", ")", "/", "0xffff", ")", "\n", "}", "\n", "}" ]
// SetBackground sets the OpenGL ClearColor to the provided color.
[ "SetBackground", "sets", "the", "OpenGL", "ClearColor", "to", "the", "provided", "color", "." ]
6f88a7379a25d81e976cf6e86ea3617f3b480b1a
https://github.com/EngoEngine/engo/blob/6f88a7379a25d81e976cf6e86ea3617f3b480b1a/common/render.go#L420-L426
12,636
EngoEngine/engo
common/audio.go
New
func (a *AudioSystem) New(w *ecs.World) { var err error switch engo.CurrentBackEnd { case engo.BackEndMobile: a.bufsize = 12288 default: a.bufsize = 8192 } if engo.Headless() { otoPlayer = &stepPlayer{ stepStart: make(chan []byte), stepDone: make(chan struct{}, 1), } } else { if otoPlayer == nil { otoPlayer, err = oto.NewPlayer(SampleRate, channelNum, bytesPerSample, a.bufsize) if err != nil { log.Printf("audio error. Unable to create new OtoPlayer: %v \n\r", err) } } else { closeCh <- struct{}{} <-loopClosedCh } } // run oto on a separate thread so it doesn't slow down updates closeCh = make(chan struct{}, 1) a.pauseCh = make(chan struct{}, 1) a.restartCh = make(chan struct{}, 1) a.playerCh = make(chan []*Player, 25) loopClosedCh = make(chan struct{}) go func() { players := make([]*Player, 0) loop: for { select { case <-closeCh: break loop case <-a.pauseCh: <-a.restartCh case players = <-a.playerCh: default: buf := make([]byte, 2048) a.read(buf, players) if _, err := otoPlayer.Write(buf); err != nil { log.Printf("error copying to OtoPlayer: %v \r\n", err) } } } loopClosedCh <- struct{}{} }() masterVolume = 1 }
go
func (a *AudioSystem) New(w *ecs.World) { var err error switch engo.CurrentBackEnd { case engo.BackEndMobile: a.bufsize = 12288 default: a.bufsize = 8192 } if engo.Headless() { otoPlayer = &stepPlayer{ stepStart: make(chan []byte), stepDone: make(chan struct{}, 1), } } else { if otoPlayer == nil { otoPlayer, err = oto.NewPlayer(SampleRate, channelNum, bytesPerSample, a.bufsize) if err != nil { log.Printf("audio error. Unable to create new OtoPlayer: %v \n\r", err) } } else { closeCh <- struct{}{} <-loopClosedCh } } // run oto on a separate thread so it doesn't slow down updates closeCh = make(chan struct{}, 1) a.pauseCh = make(chan struct{}, 1) a.restartCh = make(chan struct{}, 1) a.playerCh = make(chan []*Player, 25) loopClosedCh = make(chan struct{}) go func() { players := make([]*Player, 0) loop: for { select { case <-closeCh: break loop case <-a.pauseCh: <-a.restartCh case players = <-a.playerCh: default: buf := make([]byte, 2048) a.read(buf, players) if _, err := otoPlayer.Write(buf); err != nil { log.Printf("error copying to OtoPlayer: %v \r\n", err) } } } loopClosedCh <- struct{}{} }() masterVolume = 1 }
[ "func", "(", "a", "*", "AudioSystem", ")", "New", "(", "w", "*", "ecs", ".", "World", ")", "{", "var", "err", "error", "\n", "switch", "engo", ".", "CurrentBackEnd", "{", "case", "engo", ".", "BackEndMobile", ":", "a", ".", "bufsize", "=", "12288", "\n", "default", ":", "a", ".", "bufsize", "=", "8192", "\n", "}", "\n", "if", "engo", ".", "Headless", "(", ")", "{", "otoPlayer", "=", "&", "stepPlayer", "{", "stepStart", ":", "make", "(", "chan", "[", "]", "byte", ")", ",", "stepDone", ":", "make", "(", "chan", "struct", "{", "}", ",", "1", ")", ",", "}", "\n", "}", "else", "{", "if", "otoPlayer", "==", "nil", "{", "otoPlayer", ",", "err", "=", "oto", ".", "NewPlayer", "(", "SampleRate", ",", "channelNum", ",", "bytesPerSample", ",", "a", ".", "bufsize", ")", "\n", "if", "err", "!=", "nil", "{", "log", ".", "Printf", "(", "\"", "\\n", "\\r", "\"", ",", "err", ")", "\n", "}", "\n", "}", "else", "{", "closeCh", "<-", "struct", "{", "}", "{", "}", "\n", "<-", "loopClosedCh", "\n", "}", "\n", "}", "\n", "// run oto on a separate thread so it doesn't slow down updates", "closeCh", "=", "make", "(", "chan", "struct", "{", "}", ",", "1", ")", "\n", "a", ".", "pauseCh", "=", "make", "(", "chan", "struct", "{", "}", ",", "1", ")", "\n", "a", ".", "restartCh", "=", "make", "(", "chan", "struct", "{", "}", ",", "1", ")", "\n", "a", ".", "playerCh", "=", "make", "(", "chan", "[", "]", "*", "Player", ",", "25", ")", "\n", "loopClosedCh", "=", "make", "(", "chan", "struct", "{", "}", ")", "\n", "go", "func", "(", ")", "{", "players", ":=", "make", "(", "[", "]", "*", "Player", ",", "0", ")", "\n", "loop", ":", "for", "{", "select", "{", "case", "<-", "closeCh", ":", "break", "loop", "\n", "case", "<-", "a", ".", "pauseCh", ":", "<-", "a", ".", "restartCh", "\n", "case", "players", "=", "<-", "a", ".", "playerCh", ":", "default", ":", "buf", ":=", "make", "(", "[", "]", "byte", ",", "2048", ")", "\n", "a", ".", "read", "(", "buf", ",", "players", ")", "\n\n", "if", "_", ",", "err", ":=", "otoPlayer", ".", "Write", "(", "buf", ")", ";", "err", "!=", "nil", "{", "log", ".", "Printf", "(", "\"", "\\r", "\\n", "\"", ",", "err", ")", "\n", "}", "\n", "}", "\n", "}", "\n", "loopClosedCh", "<-", "struct", "{", "}", "{", "}", "\n", "}", "(", ")", "\n", "masterVolume", "=", "1", "\n", "}" ]
// New is called when the AudioSystem is added to the world.
[ "New", "is", "called", "when", "the", "AudioSystem", "is", "added", "to", "the", "world", "." ]
6f88a7379a25d81e976cf6e86ea3617f3b480b1a
https://github.com/EngoEngine/engo/blob/6f88a7379a25d81e976cf6e86ea3617f3b480b1a/common/audio.go#L78-L130
12,637
EngoEngine/engo
common/audio.go
Add
func (a *AudioSystem) Add(basic *ecs.BasicEntity, audio *AudioComponent) { a.entities = append(a.entities, audioEntity{basic, audio}) }
go
func (a *AudioSystem) Add(basic *ecs.BasicEntity, audio *AudioComponent) { a.entities = append(a.entities, audioEntity{basic, audio}) }
[ "func", "(", "a", "*", "AudioSystem", ")", "Add", "(", "basic", "*", "ecs", ".", "BasicEntity", ",", "audio", "*", "AudioComponent", ")", "{", "a", ".", "entities", "=", "append", "(", "a", ".", "entities", ",", "audioEntity", "{", "basic", ",", "audio", "}", ")", "\n", "}" ]
// Add adds an entity to the AudioSystem
[ "Add", "adds", "an", "entity", "to", "the", "AudioSystem" ]
6f88a7379a25d81e976cf6e86ea3617f3b480b1a
https://github.com/EngoEngine/engo/blob/6f88a7379a25d81e976cf6e86ea3617f3b480b1a/common/audio.go#L133-L135
12,638
EngoEngine/engo
common/audio.go
AddByInterface
func (a *AudioSystem) AddByInterface(i ecs.Identifier) { o, _ := i.(Audioable) a.Add(o.GetBasicEntity(), o.GetAudioComponent()) }
go
func (a *AudioSystem) AddByInterface(i ecs.Identifier) { o, _ := i.(Audioable) a.Add(o.GetBasicEntity(), o.GetAudioComponent()) }
[ "func", "(", "a", "*", "AudioSystem", ")", "AddByInterface", "(", "i", "ecs", ".", "Identifier", ")", "{", "o", ",", "_", ":=", "i", ".", "(", "Audioable", ")", "\n", "a", ".", "Add", "(", "o", ".", "GetBasicEntity", "(", ")", ",", "o", ".", "GetAudioComponent", "(", ")", ")", "\n", "}" ]
// AddByInterface Allows an Entity to be added directly using the Audioable interface, // which every entity containing the BasicEntity and AnimationComponent anonymously, // automatically satisfies.
[ "AddByInterface", "Allows", "an", "Entity", "to", "be", "added", "directly", "using", "the", "Audioable", "interface", "which", "every", "entity", "containing", "the", "BasicEntity", "and", "AnimationComponent", "anonymously", "automatically", "satisfies", "." ]
6f88a7379a25d81e976cf6e86ea3617f3b480b1a
https://github.com/EngoEngine/engo/blob/6f88a7379a25d81e976cf6e86ea3617f3b480b1a/common/audio.go#L140-L143
12,639
EngoEngine/engo
common/audio.go
Remove
func (a *AudioSystem) Remove(basic ecs.BasicEntity) { delete := -1 for index, e := range a.entities { if e.BasicEntity.ID() == basic.ID() { delete = index break } } if delete >= 0 { a.entities = append(a.entities[:delete], a.entities[delete+1:]...) } }
go
func (a *AudioSystem) Remove(basic ecs.BasicEntity) { delete := -1 for index, e := range a.entities { if e.BasicEntity.ID() == basic.ID() { delete = index break } } if delete >= 0 { a.entities = append(a.entities[:delete], a.entities[delete+1:]...) } }
[ "func", "(", "a", "*", "AudioSystem", ")", "Remove", "(", "basic", "ecs", ".", "BasicEntity", ")", "{", "delete", ":=", "-", "1", "\n", "for", "index", ",", "e", ":=", "range", "a", ".", "entities", "{", "if", "e", ".", "BasicEntity", ".", "ID", "(", ")", "==", "basic", ".", "ID", "(", ")", "{", "delete", "=", "index", "\n", "break", "\n", "}", "\n", "}", "\n", "if", "delete", ">=", "0", "{", "a", ".", "entities", "=", "append", "(", "a", ".", "entities", "[", ":", "delete", "]", ",", "a", ".", "entities", "[", "delete", "+", "1", ":", "]", "...", ")", "\n", "}", "\n", "}" ]
// Remove removes an entity from the AudioSystem
[ "Remove", "removes", "an", "entity", "from", "the", "AudioSystem" ]
6f88a7379a25d81e976cf6e86ea3617f3b480b1a
https://github.com/EngoEngine/engo/blob/6f88a7379a25d81e976cf6e86ea3617f3b480b1a/common/audio.go#L146-L157
12,640
EngoEngine/engo
common/audio.go
Update
func (a *AudioSystem) Update(dt float32) { if len(a.playerCh) >= 25 { //if the channel is full just return so we don't block the update loop return } players := make([]*Player, 0) for _, e := range a.entities { if e.Player.isPlaying { players = append(players, e.Player) } } a.playerCh <- players }
go
func (a *AudioSystem) Update(dt float32) { if len(a.playerCh) >= 25 { //if the channel is full just return so we don't block the update loop return } players := make([]*Player, 0) for _, e := range a.entities { if e.Player.isPlaying { players = append(players, e.Player) } } a.playerCh <- players }
[ "func", "(", "a", "*", "AudioSystem", ")", "Update", "(", "dt", "float32", ")", "{", "if", "len", "(", "a", ".", "playerCh", ")", ">=", "25", "{", "//if the channel is full just return so we don't block the update loop", "return", "\n", "}", "\n", "players", ":=", "make", "(", "[", "]", "*", "Player", ",", "0", ")", "\n", "for", "_", ",", "e", ":=", "range", "a", ".", "entities", "{", "if", "e", ".", "Player", ".", "isPlaying", "{", "players", "=", "append", "(", "players", ",", "e", ".", "Player", ")", "\n", "}", "\n", "}", "\n", "a", ".", "playerCh", "<-", "players", "\n", "}" ]
// Update doesn't do anything since audio is run on it's own thread
[ "Update", "doesn", "t", "do", "anything", "since", "audio", "is", "run", "on", "it", "s", "own", "thread" ]
6f88a7379a25d81e976cf6e86ea3617f3b480b1a
https://github.com/EngoEngine/engo/blob/6f88a7379a25d81e976cf6e86ea3617f3b480b1a/common/audio.go#L160-L171
12,641
EngoEngine/engo
common/audio.go
read
func (a *AudioSystem) read(b []byte, players []*Player) (int, error) { l := len(b) l &= mask if len(players) == 0 { copy(b, make([]byte, l)) return l, nil } b16s := [][]int16{} for _, player := range players { buf, err := player.bufferToInt16(l) if err != nil { return 0, err } b16s = append(b16s, buf) } for i := 0; i < l/2; i++ { x := 0 for _, b16 := range b16s { x += int(b16[i]) } if x > (1<<15)-1 { x = (1 << 15) - 1 } if x < -(1 << 15) { x = -(1 << 15) } b[2*i] = byte(x) b[2*i+1] = byte(x >> 8) } for _, player := range players { if player.eof() { if player.Repeat { player.Rewind() } else { player.Pause() } } } return l, nil }
go
func (a *AudioSystem) read(b []byte, players []*Player) (int, error) { l := len(b) l &= mask if len(players) == 0 { copy(b, make([]byte, l)) return l, nil } b16s := [][]int16{} for _, player := range players { buf, err := player.bufferToInt16(l) if err != nil { return 0, err } b16s = append(b16s, buf) } for i := 0; i < l/2; i++ { x := 0 for _, b16 := range b16s { x += int(b16[i]) } if x > (1<<15)-1 { x = (1 << 15) - 1 } if x < -(1 << 15) { x = -(1 << 15) } b[2*i] = byte(x) b[2*i+1] = byte(x >> 8) } for _, player := range players { if player.eof() { if player.Repeat { player.Rewind() } else { player.Pause() } } } return l, nil }
[ "func", "(", "a", "*", "AudioSystem", ")", "read", "(", "b", "[", "]", "byte", ",", "players", "[", "]", "*", "Player", ")", "(", "int", ",", "error", ")", "{", "l", ":=", "len", "(", "b", ")", "\n", "l", "&=", "mask", "\n\n", "if", "len", "(", "players", ")", "==", "0", "{", "copy", "(", "b", ",", "make", "(", "[", "]", "byte", ",", "l", ")", ")", "\n", "return", "l", ",", "nil", "\n", "}", "\n\n", "b16s", ":=", "[", "]", "[", "]", "int16", "{", "}", "\n", "for", "_", ",", "player", ":=", "range", "players", "{", "buf", ",", "err", ":=", "player", ".", "bufferToInt16", "(", "l", ")", "\n", "if", "err", "!=", "nil", "{", "return", "0", ",", "err", "\n", "}", "\n", "b16s", "=", "append", "(", "b16s", ",", "buf", ")", "\n", "}", "\n", "for", "i", ":=", "0", ";", "i", "<", "l", "/", "2", ";", "i", "++", "{", "x", ":=", "0", "\n", "for", "_", ",", "b16", ":=", "range", "b16s", "{", "x", "+=", "int", "(", "b16", "[", "i", "]", ")", "\n", "}", "\n", "if", "x", ">", "(", "1", "<<", "15", ")", "-", "1", "{", "x", "=", "(", "1", "<<", "15", ")", "-", "1", "\n", "}", "\n", "if", "x", "<", "-", "(", "1", "<<", "15", ")", "{", "x", "=", "-", "(", "1", "<<", "15", ")", "\n", "}", "\n", "b", "[", "2", "*", "i", "]", "=", "byte", "(", "x", ")", "\n", "b", "[", "2", "*", "i", "+", "1", "]", "=", "byte", "(", "x", ">>", "8", ")", "\n", "}", "\n\n", "for", "_", ",", "player", ":=", "range", "players", "{", "if", "player", ".", "eof", "(", ")", "{", "if", "player", ".", "Repeat", "{", "player", ".", "Rewind", "(", ")", "\n", "}", "else", "{", "player", ".", "Pause", "(", ")", "\n", "}", "\n", "}", "\n", "}", "\n\n", "return", "l", ",", "nil", "\n", "}" ]
// Read reads from all the currently playing entities and combines them into a // single stream that is passed to the oto player.
[ "Read", "reads", "from", "all", "the", "currently", "playing", "entities", "and", "combines", "them", "into", "a", "single", "stream", "that", "is", "passed", "to", "the", "oto", "player", "." ]
6f88a7379a25d81e976cf6e86ea3617f3b480b1a
https://github.com/EngoEngine/engo/blob/6f88a7379a25d81e976cf6e86ea3617f3b480b1a/common/audio.go#L175-L218
12,642
EngoEngine/engo
input.go
NewInputManager
func NewInputManager() *InputManager { return &InputManager{ Touches: make(map[int]Point), axes: make(map[string]Axis), buttons: make(map[string]Button), keys: NewKeyManager(), } }
go
func NewInputManager() *InputManager { return &InputManager{ Touches: make(map[int]Point), axes: make(map[string]Axis), buttons: make(map[string]Button), keys: NewKeyManager(), } }
[ "func", "NewInputManager", "(", ")", "*", "InputManager", "{", "return", "&", "InputManager", "{", "Touches", ":", "make", "(", "map", "[", "int", "]", "Point", ")", ",", "axes", ":", "make", "(", "map", "[", "string", "]", "Axis", ")", ",", "buttons", ":", "make", "(", "map", "[", "string", "]", "Button", ")", ",", "keys", ":", "NewKeyManager", "(", ")", ",", "}", "\n", "}" ]
// NewInputManager holds onto anything input related for engo
[ "NewInputManager", "holds", "onto", "anything", "input", "related", "for", "engo" ]
6f88a7379a25d81e976cf6e86ea3617f3b480b1a
https://github.com/EngoEngine/engo/blob/6f88a7379a25d81e976cf6e86ea3617f3b480b1a/input.go#L13-L20
12,643
EngoEngine/engo
input.go
RegisterAxis
func (im *InputManager) RegisterAxis(name string, pairs ...AxisPair) { im.axes[name] = Axis{ Name: name, Pairs: pairs, } }
go
func (im *InputManager) RegisterAxis(name string, pairs ...AxisPair) { im.axes[name] = Axis{ Name: name, Pairs: pairs, } }
[ "func", "(", "im", "*", "InputManager", ")", "RegisterAxis", "(", "name", "string", ",", "pairs", "...", "AxisPair", ")", "{", "im", ".", "axes", "[", "name", "]", "=", "Axis", "{", "Name", ":", "name", ",", "Pairs", ":", "pairs", ",", "}", "\n", "}" ]
// RegisterAxis registers a new axis which can be used to retrieve inputs which are spectrums.
[ "RegisterAxis", "registers", "a", "new", "axis", "which", "can", "be", "used", "to", "retrieve", "inputs", "which", "are", "spectrums", "." ]
6f88a7379a25d81e976cf6e86ea3617f3b480b1a
https://github.com/EngoEngine/engo/blob/6f88a7379a25d81e976cf6e86ea3617f3b480b1a/input.go#L43-L48
12,644
EngoEngine/engo
input.go
RegisterButton
func (im *InputManager) RegisterButton(name string, keys ...Key) { im.buttons[name] = Button{ Triggers: keys, Name: name, } }
go
func (im *InputManager) RegisterButton(name string, keys ...Key) { im.buttons[name] = Button{ Triggers: keys, Name: name, } }
[ "func", "(", "im", "*", "InputManager", ")", "RegisterButton", "(", "name", "string", ",", "keys", "...", "Key", ")", "{", "im", ".", "buttons", "[", "name", "]", "=", "Button", "{", "Triggers", ":", "keys", ",", "Name", ":", "name", ",", "}", "\n", "}" ]
// RegisterButton registers a new button input.
[ "RegisterButton", "registers", "a", "new", "button", "input", "." ]
6f88a7379a25d81e976cf6e86ea3617f3b480b1a
https://github.com/EngoEngine/engo/blob/6f88a7379a25d81e976cf6e86ea3617f3b480b1a/input.go#L51-L56
12,645
EngoEngine/engo
common/font.go
Create
func (f *Font) Create() error { // Read and parse the font ttfBytes, err := ioutil.ReadFile(f.URL) if err != nil { return err } ttf, err := freetype.ParseFont(ttfBytes) if err != nil { return err } f.TTF = ttf f.face = truetype.NewFace(f.TTF, &truetype.Options{ Size: f.Size, DPI: dpi, Hinting: font.HintingFull, }) return nil }
go
func (f *Font) Create() error { // Read and parse the font ttfBytes, err := ioutil.ReadFile(f.URL) if err != nil { return err } ttf, err := freetype.ParseFont(ttfBytes) if err != nil { return err } f.TTF = ttf f.face = truetype.NewFace(f.TTF, &truetype.Options{ Size: f.Size, DPI: dpi, Hinting: font.HintingFull, }) return nil }
[ "func", "(", "f", "*", "Font", ")", "Create", "(", ")", "error", "{", "// Read and parse the font", "ttfBytes", ",", "err", ":=", "ioutil", ".", "ReadFile", "(", "f", ".", "URL", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n\n", "ttf", ",", "err", ":=", "freetype", ".", "ParseFont", "(", "ttfBytes", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "f", ".", "TTF", "=", "ttf", "\n", "f", ".", "face", "=", "truetype", ".", "NewFace", "(", "f", ".", "TTF", ",", "&", "truetype", ".", "Options", "{", "Size", ":", "f", ".", "Size", ",", "DPI", ":", "dpi", ",", "Hinting", ":", "font", ".", "HintingFull", ",", "}", ")", "\n\n", "return", "nil", "\n", "}" ]
// Create is for loading fonts from the disk, given a location
[ "Create", "is", "for", "loading", "fonts", "from", "the", "disk", "given", "a", "location" ]
6f88a7379a25d81e976cf6e86ea3617f3b480b1a
https://github.com/EngoEngine/engo/blob/6f88a7379a25d81e976cf6e86ea3617f3b480b1a/common/font.go#L36-L55
12,646
EngoEngine/engo
common/font.go
TextDimensions
func (f *Font) TextDimensions(text string) (int, int, int) { fnt := f.TTF size := f.Size var ( totalWidth = fixed.Int26_6(0) totalHeight = fixed.Int26_6(size) maxYBearing = fixed.Int26_6(0) ) fupe := fixed.Int26_6(fnt.FUnitsPerEm()) for _, char := range text { idx := fnt.Index(char) hm := fnt.HMetric(fupe, idx) vm := fnt.VMetric(fupe, idx) g := truetype.GlyphBuf{} err := g.Load(fnt, fupe, idx, font.HintingNone) if err != nil { log.Println(err) return 0, 0, 0 } totalWidth += hm.AdvanceWidth yB := (vm.TopSideBearing * fixed.Int26_6(size)) / fupe if yB > maxYBearing { maxYBearing = yB } dY := (vm.AdvanceHeight * fixed.Int26_6(size)) / fupe if dY > totalHeight { totalHeight = dY } } // Scale to actual pixel size totalWidth *= fixed.Int26_6(size) totalWidth /= fupe return int(totalWidth), int(totalHeight), int(maxYBearing) }
go
func (f *Font) TextDimensions(text string) (int, int, int) { fnt := f.TTF size := f.Size var ( totalWidth = fixed.Int26_6(0) totalHeight = fixed.Int26_6(size) maxYBearing = fixed.Int26_6(0) ) fupe := fixed.Int26_6(fnt.FUnitsPerEm()) for _, char := range text { idx := fnt.Index(char) hm := fnt.HMetric(fupe, idx) vm := fnt.VMetric(fupe, idx) g := truetype.GlyphBuf{} err := g.Load(fnt, fupe, idx, font.HintingNone) if err != nil { log.Println(err) return 0, 0, 0 } totalWidth += hm.AdvanceWidth yB := (vm.TopSideBearing * fixed.Int26_6(size)) / fupe if yB > maxYBearing { maxYBearing = yB } dY := (vm.AdvanceHeight * fixed.Int26_6(size)) / fupe if dY > totalHeight { totalHeight = dY } } // Scale to actual pixel size totalWidth *= fixed.Int26_6(size) totalWidth /= fupe return int(totalWidth), int(totalHeight), int(maxYBearing) }
[ "func", "(", "f", "*", "Font", ")", "TextDimensions", "(", "text", "string", ")", "(", "int", ",", "int", ",", "int", ")", "{", "fnt", ":=", "f", ".", "TTF", "\n", "size", ":=", "f", ".", "Size", "\n", "var", "(", "totalWidth", "=", "fixed", ".", "Int26_6", "(", "0", ")", "\n", "totalHeight", "=", "fixed", ".", "Int26_6", "(", "size", ")", "\n", "maxYBearing", "=", "fixed", ".", "Int26_6", "(", "0", ")", "\n", ")", "\n", "fupe", ":=", "fixed", ".", "Int26_6", "(", "fnt", ".", "FUnitsPerEm", "(", ")", ")", "\n\n", "for", "_", ",", "char", ":=", "range", "text", "{", "idx", ":=", "fnt", ".", "Index", "(", "char", ")", "\n", "hm", ":=", "fnt", ".", "HMetric", "(", "fupe", ",", "idx", ")", "\n", "vm", ":=", "fnt", ".", "VMetric", "(", "fupe", ",", "idx", ")", "\n", "g", ":=", "truetype", ".", "GlyphBuf", "{", "}", "\n", "err", ":=", "g", ".", "Load", "(", "fnt", ",", "fupe", ",", "idx", ",", "font", ".", "HintingNone", ")", "\n", "if", "err", "!=", "nil", "{", "log", ".", "Println", "(", "err", ")", "\n", "return", "0", ",", "0", ",", "0", "\n", "}", "\n", "totalWidth", "+=", "hm", ".", "AdvanceWidth", "\n\n", "yB", ":=", "(", "vm", ".", "TopSideBearing", "*", "fixed", ".", "Int26_6", "(", "size", ")", ")", "/", "fupe", "\n", "if", "yB", ">", "maxYBearing", "{", "maxYBearing", "=", "yB", "\n", "}", "\n", "dY", ":=", "(", "vm", ".", "AdvanceHeight", "*", "fixed", ".", "Int26_6", "(", "size", ")", ")", "/", "fupe", "\n", "if", "dY", ">", "totalHeight", "{", "totalHeight", "=", "dY", "\n", "}", "\n", "}", "\n\n", "// Scale to actual pixel size", "totalWidth", "*=", "fixed", ".", "Int26_6", "(", "size", ")", "\n", "totalWidth", "/=", "fupe", "\n\n", "return", "int", "(", "totalWidth", ")", ",", "int", "(", "totalHeight", ")", ",", "int", "(", "maxYBearing", ")", "\n", "}" ]
// TextDimensions returns the total width, total height and total line size // of the input string written out in the Font.
[ "TextDimensions", "returns", "the", "total", "width", "total", "height", "and", "total", "line", "size", "of", "the", "input", "string", "written", "out", "in", "the", "Font", "." ]
6f88a7379a25d81e976cf6e86ea3617f3b480b1a
https://github.com/EngoEngine/engo/blob/6f88a7379a25d81e976cf6e86ea3617f3b480b1a/common/font.go#L80-L117
12,647
EngoEngine/engo
common/font.go
Render
func (f *Font) Render(text string) Texture { nrgba := f.RenderNRGBA(text) // Create texture imObj := NewImageObject(nrgba) return NewTextureSingle(imObj) }
go
func (f *Font) Render(text string) Texture { nrgba := f.RenderNRGBA(text) // Create texture imObj := NewImageObject(nrgba) return NewTextureSingle(imObj) }
[ "func", "(", "f", "*", "Font", ")", "Render", "(", "text", "string", ")", "Texture", "{", "nrgba", ":=", "f", ".", "RenderNRGBA", "(", "text", ")", "\n\n", "// Create texture", "imObj", ":=", "NewImageObject", "(", "nrgba", ")", "\n", "return", "NewTextureSingle", "(", "imObj", ")", "\n", "}" ]
// Render returns a Texture in the Font based on the input string.
[ "Render", "returns", "a", "Texture", "in", "the", "Font", "based", "on", "the", "input", "string", "." ]
6f88a7379a25d81e976cf6e86ea3617f3b480b1a
https://github.com/EngoEngine/engo/blob/6f88a7379a25d81e976cf6e86ea3617f3b480b1a/common/font.go#L166-L172
12,648
EngoEngine/engo
common/font.go
Width
func (t Text) Width() float32 { atlas, ok := atlasCache[*t.Font] if !ok { // Generate texture first atlas = t.Font.generateFontAtlas(200) atlasCache[*t.Font] = atlas } var currentX float32 var greatestX float32 for _, char := range t.Text { // TODO: this might not work for all characters switch { case char == '\n': if currentX > greatestX { greatestX = currentX } currentX = 0 continue case char < 32: // all system stuff should be ignored continue } currentX += atlas.Width[char] + float32(t.Font.Size)*t.LetterSpacing } if currentX > greatestX { return currentX } return greatestX }
go
func (t Text) Width() float32 { atlas, ok := atlasCache[*t.Font] if !ok { // Generate texture first atlas = t.Font.generateFontAtlas(200) atlasCache[*t.Font] = atlas } var currentX float32 var greatestX float32 for _, char := range t.Text { // TODO: this might not work for all characters switch { case char == '\n': if currentX > greatestX { greatestX = currentX } currentX = 0 continue case char < 32: // all system stuff should be ignored continue } currentX += atlas.Width[char] + float32(t.Font.Size)*t.LetterSpacing } if currentX > greatestX { return currentX } return greatestX }
[ "func", "(", "t", "Text", ")", "Width", "(", ")", "float32", "{", "atlas", ",", "ok", ":=", "atlasCache", "[", "*", "t", ".", "Font", "]", "\n", "if", "!", "ok", "{", "// Generate texture first", "atlas", "=", "t", ".", "Font", ".", "generateFontAtlas", "(", "200", ")", "\n", "atlasCache", "[", "*", "t", ".", "Font", "]", "=", "atlas", "\n", "}", "\n\n", "var", "currentX", "float32", "\n", "var", "greatestX", "float32", "\n\n", "for", "_", ",", "char", ":=", "range", "t", ".", "Text", "{", "// TODO: this might not work for all characters", "switch", "{", "case", "char", "==", "'\\n'", ":", "if", "currentX", ">", "greatestX", "{", "greatestX", "=", "currentX", "\n", "}", "\n", "currentX", "=", "0", "\n", "continue", "\n", "case", "char", "<", "32", ":", "// all system stuff should be ignored", "continue", "\n", "}", "\n\n", "currentX", "+=", "atlas", ".", "Width", "[", "char", "]", "+", "float32", "(", "t", ".", "Font", ".", "Size", ")", "*", "t", ".", "LetterSpacing", "\n", "}", "\n", "if", "currentX", ">", "greatestX", "{", "return", "currentX", "\n", "}", "\n", "return", "greatestX", "\n", "}" ]
// Width returns the width of the Text generated from a FontAtlas. This implements the common.Drawable interface.
[ "Width", "returns", "the", "width", "of", "the", "Text", "generated", "from", "a", "FontAtlas", ".", "This", "implements", "the", "common", ".", "Drawable", "interface", "." ]
6f88a7379a25d81e976cf6e86ea3617f3b480b1a
https://github.com/EngoEngine/engo/blob/6f88a7379a25d81e976cf6e86ea3617f3b480b1a/common/font.go#L297-L327
12,649
EngoEngine/engo
common/font.go
Height
func (t Text) Height() float32 { atlas, ok := atlasCache[*t.Font] if !ok { // Generate texture first atlas = t.Font.generateFontAtlas(200) atlasCache[*t.Font] = atlas } var currentY float32 var totalY float32 var tallest float32 for _, char := range t.Text { // TODO: this might not work for all characters switch { case char == '\n': totalY += tallest tallest = float32(0) continue case char < 32: // all system stuff should be ignored continue } currentY = atlas.Height[char] + t.LineSpacing*atlas.Height[char] if currentY > tallest { tallest = currentY } } return totalY + tallest }
go
func (t Text) Height() float32 { atlas, ok := atlasCache[*t.Font] if !ok { // Generate texture first atlas = t.Font.generateFontAtlas(200) atlasCache[*t.Font] = atlas } var currentY float32 var totalY float32 var tallest float32 for _, char := range t.Text { // TODO: this might not work for all characters switch { case char == '\n': totalY += tallest tallest = float32(0) continue case char < 32: // all system stuff should be ignored continue } currentY = atlas.Height[char] + t.LineSpacing*atlas.Height[char] if currentY > tallest { tallest = currentY } } return totalY + tallest }
[ "func", "(", "t", "Text", ")", "Height", "(", ")", "float32", "{", "atlas", ",", "ok", ":=", "atlasCache", "[", "*", "t", ".", "Font", "]", "\n", "if", "!", "ok", "{", "// Generate texture first", "atlas", "=", "t", ".", "Font", ".", "generateFontAtlas", "(", "200", ")", "\n", "atlasCache", "[", "*", "t", ".", "Font", "]", "=", "atlas", "\n", "}", "\n\n", "var", "currentY", "float32", "\n", "var", "totalY", "float32", "\n", "var", "tallest", "float32", "\n\n", "for", "_", ",", "char", ":=", "range", "t", ".", "Text", "{", "// TODO: this might not work for all characters", "switch", "{", "case", "char", "==", "'\\n'", ":", "totalY", "+=", "tallest", "\n", "tallest", "=", "float32", "(", "0", ")", "\n", "continue", "\n", "case", "char", "<", "32", ":", "// all system stuff should be ignored", "continue", "\n", "}", "\n", "currentY", "=", "atlas", ".", "Height", "[", "char", "]", "+", "t", ".", "LineSpacing", "*", "atlas", ".", "Height", "[", "char", "]", "\n", "if", "currentY", ">", "tallest", "{", "tallest", "=", "currentY", "\n", "}", "\n", "}", "\n", "return", "totalY", "+", "tallest", "\n", "}" ]
// Height returns the height the Text generated from a FontAtlas. This implements the common.Drawable interface.
[ "Height", "returns", "the", "height", "the", "Text", "generated", "from", "a", "FontAtlas", ".", "This", "implements", "the", "common", ".", "Drawable", "interface", "." ]
6f88a7379a25d81e976cf6e86ea3617f3b480b1a
https://github.com/EngoEngine/engo/blob/6f88a7379a25d81e976cf6e86ea3617f3b480b1a/common/font.go#L330-L358
12,650
EngoEngine/engo
common/mouse.go
New
func (m *MouseSystem) New(w *ecs.World) { m.world = w // First check if the CameraSystem is available for _, system := range m.world.Systems() { switch sys := system.(type) { case *CameraSystem: m.camera = sys } } if m.camera == nil { log.Println("ERROR: CameraSystem not found - have you added the `RenderSystem` before the `MouseSystem`?") return } }
go
func (m *MouseSystem) New(w *ecs.World) { m.world = w // First check if the CameraSystem is available for _, system := range m.world.Systems() { switch sys := system.(type) { case *CameraSystem: m.camera = sys } } if m.camera == nil { log.Println("ERROR: CameraSystem not found - have you added the `RenderSystem` before the `MouseSystem`?") return } }
[ "func", "(", "m", "*", "MouseSystem", ")", "New", "(", "w", "*", "ecs", ".", "World", ")", "{", "m", ".", "world", "=", "w", "\n\n", "// First check if the CameraSystem is available", "for", "_", ",", "system", ":=", "range", "m", ".", "world", ".", "Systems", "(", ")", "{", "switch", "sys", ":=", "system", ".", "(", "type", ")", "{", "case", "*", "CameraSystem", ":", "m", ".", "camera", "=", "sys", "\n", "}", "\n", "}", "\n\n", "if", "m", ".", "camera", "==", "nil", "{", "log", ".", "Println", "(", "\"", "\"", ")", "\n", "return", "\n", "}", "\n", "}" ]
// New initializes the MouseSystem. It is run before any updates.
[ "New", "initializes", "the", "MouseSystem", ".", "It", "is", "run", "before", "any", "updates", "." ]
6f88a7379a25d81e976cf6e86ea3617f3b480b1a
https://github.com/EngoEngine/engo/blob/6f88a7379a25d81e976cf6e86ea3617f3b480b1a/common/mouse.go#L130-L145
12,651
EngoEngine/engo
common/mouse.go
AddByInterface
func (m *MouseSystem) AddByInterface(i ecs.Identifier) { o, _ := i.(Mouseable) m.Add(o.GetBasicEntity(), o.GetMouseComponent(), o.GetSpaceComponent(), o.GetRenderComponent()) }
go
func (m *MouseSystem) AddByInterface(i ecs.Identifier) { o, _ := i.(Mouseable) m.Add(o.GetBasicEntity(), o.GetMouseComponent(), o.GetSpaceComponent(), o.GetRenderComponent()) }
[ "func", "(", "m", "*", "MouseSystem", ")", "AddByInterface", "(", "i", "ecs", ".", "Identifier", ")", "{", "o", ",", "_", ":=", "i", ".", "(", "Mouseable", ")", "\n", "m", ".", "Add", "(", "o", ".", "GetBasicEntity", "(", ")", ",", "o", ".", "GetMouseComponent", "(", ")", ",", "o", ".", "GetSpaceComponent", "(", ")", ",", "o", ".", "GetRenderComponent", "(", ")", ")", "\n", "}" ]
// AddByInterface adds the Entity to the system as long as it satisfies, Mouseable. Any Entity containing a BasicEntity,MouseComponent, and RenderComponent, automatically does this.
[ "AddByInterface", "adds", "the", "Entity", "to", "the", "system", "as", "long", "as", "it", "satisfies", "Mouseable", ".", "Any", "Entity", "containing", "a", "BasicEntity", "MouseComponent", "and", "RenderComponent", "automatically", "does", "this", "." ]
6f88a7379a25d81e976cf6e86ea3617f3b480b1a
https://github.com/EngoEngine/engo/blob/6f88a7379a25d81e976cf6e86ea3617f3b480b1a/common/mouse.go#L158-L161
12,652
EngoEngine/engo
common/mouse.go
Remove
func (m *MouseSystem) Remove(basic ecs.BasicEntity) { var delete = -1 for index, entity := range m.entities { if entity.ID() == basic.ID() { delete = index break } } if delete >= 0 { m.entities = append(m.entities[:delete], m.entities[delete+1:]...) } }
go
func (m *MouseSystem) Remove(basic ecs.BasicEntity) { var delete = -1 for index, entity := range m.entities { if entity.ID() == basic.ID() { delete = index break } } if delete >= 0 { m.entities = append(m.entities[:delete], m.entities[delete+1:]...) } }
[ "func", "(", "m", "*", "MouseSystem", ")", "Remove", "(", "basic", "ecs", ".", "BasicEntity", ")", "{", "var", "delete", "=", "-", "1", "\n", "for", "index", ",", "entity", ":=", "range", "m", ".", "entities", "{", "if", "entity", ".", "ID", "(", ")", "==", "basic", ".", "ID", "(", ")", "{", "delete", "=", "index", "\n", "break", "\n", "}", "\n", "}", "\n", "if", "delete", ">=", "0", "{", "m", ".", "entities", "=", "append", "(", "m", ".", "entities", "[", ":", "delete", "]", ",", "m", ".", "entities", "[", "delete", "+", "1", ":", "]", "...", ")", "\n", "}", "\n", "}" ]
// Remove removes an entity from the MouseSystem.
[ "Remove", "removes", "an", "entity", "from", "the", "MouseSystem", "." ]
6f88a7379a25d81e976cf6e86ea3617f3b480b1a
https://github.com/EngoEngine/engo/blob/6f88a7379a25d81e976cf6e86ea3617f3b480b1a/common/mouse.go#L164-L175
12,653
EngoEngine/engo
common/internal/decode/mp3/decode.go
Close
func (s *Stream) Close() error { if s.resampling != nil { return s.resampling.Close() } return nil }
go
func (s *Stream) Close() error { if s.resampling != nil { return s.resampling.Close() } return nil }
[ "func", "(", "s", "*", "Stream", ")", "Close", "(", ")", "error", "{", "if", "s", ".", "resampling", "!=", "nil", "{", "return", "s", ".", "resampling", ".", "Close", "(", ")", "\n", "}", "\n", "return", "nil", "\n", "}" ]
// Close is implementation of io.Closer's Close.
[ "Close", "is", "implementation", "of", "io", ".", "Closer", "s", "Close", "." ]
6f88a7379a25d81e976cf6e86ea3617f3b480b1a
https://github.com/EngoEngine/engo/blob/6f88a7379a25d81e976cf6e86ea3617f3b480b1a/common/internal/decode/mp3/decode.go#L32-L37
12,654
EngoEngine/engo
common/internal/decode/mp3/decode.go
Decode
func Decode(src convert.ReadSeekCloser, sr int) (*Stream, error) { d, err := mp3.NewDecoder(src) if err != nil { return nil, err } var r *convert.Resampling stream := &Stream{ orig: d, resampling: r, } if d.SampleRate() != sr { stream.resampling = convert.NewResampling(stream, stream.orig.Length(), stream.orig.SampleRate(), sr) } return stream, nil }
go
func Decode(src convert.ReadSeekCloser, sr int) (*Stream, error) { d, err := mp3.NewDecoder(src) if err != nil { return nil, err } var r *convert.Resampling stream := &Stream{ orig: d, resampling: r, } if d.SampleRate() != sr { stream.resampling = convert.NewResampling(stream, stream.orig.Length(), stream.orig.SampleRate(), sr) } return stream, nil }
[ "func", "Decode", "(", "src", "convert", ".", "ReadSeekCloser", ",", "sr", "int", ")", "(", "*", "Stream", ",", "error", ")", "{", "d", ",", "err", ":=", "mp3", ".", "NewDecoder", "(", "src", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "var", "r", "*", "convert", ".", "Resampling", "\n", "stream", ":=", "&", "Stream", "{", "orig", ":", "d", ",", "resampling", ":", "r", ",", "}", "\n", "if", "d", ".", "SampleRate", "(", ")", "!=", "sr", "{", "stream", ".", "resampling", "=", "convert", ".", "NewResampling", "(", "stream", ",", "stream", ".", "orig", ".", "Length", "(", ")", ",", "stream", ".", "orig", ".", "SampleRate", "(", ")", ",", "sr", ")", "\n", "}", "\n", "return", "stream", ",", "nil", "\n", "}" ]
// Decode decodes MP3 source and returns a decoded stream. // // Decode returns error when decoding fails or IO error happens. // // Decode automatically resamples the stream to fit with the audio context if necessary.
[ "Decode", "decodes", "MP3", "source", "and", "returns", "a", "decoded", "stream", ".", "Decode", "returns", "error", "when", "decoding", "fails", "or", "IO", "error", "happens", ".", "Decode", "automatically", "resamples", "the", "stream", "to", "fit", "with", "the", "audio", "context", "if", "necessary", "." ]
6f88a7379a25d81e976cf6e86ea3617f3b480b1a
https://github.com/EngoEngine/engo/blob/6f88a7379a25d81e976cf6e86ea3617f3b480b1a/common/internal/decode/mp3/decode.go#L57-L71
12,655
EngoEngine/engo
common/audio_filetype.go
Load
func (a *audioLoader) Load(url string, data io.Reader) error { var err error audioBytes, err := ioutil.ReadAll(data) if err != nil { return err } audioBuffer := bytes.NewReader(audioBytes) var player *Player switch getExt(url) { case ".wav": d, err := wav.Decode(&readSeekCloserBuffer{audioBuffer}, SampleRate) if err != nil { return err } player, err = newPlayer(d, url) if err != nil { return err } case ".mp3": d, err := mp3.Decode(&readSeekCloserBuffer{audioBuffer}, SampleRate) if err != nil { return err } player, err = newPlayer(d, url) if err != nil { return err } case ".ogg": d, err := vorbis.Decode(&readSeekCloserBuffer{audioBuffer}, SampleRate) if err != nil { return err } player, err = newPlayer(d, url) if err != nil { return err } } a.audios[url] = player return nil }
go
func (a *audioLoader) Load(url string, data io.Reader) error { var err error audioBytes, err := ioutil.ReadAll(data) if err != nil { return err } audioBuffer := bytes.NewReader(audioBytes) var player *Player switch getExt(url) { case ".wav": d, err := wav.Decode(&readSeekCloserBuffer{audioBuffer}, SampleRate) if err != nil { return err } player, err = newPlayer(d, url) if err != nil { return err } case ".mp3": d, err := mp3.Decode(&readSeekCloserBuffer{audioBuffer}, SampleRate) if err != nil { return err } player, err = newPlayer(d, url) if err != nil { return err } case ".ogg": d, err := vorbis.Decode(&readSeekCloserBuffer{audioBuffer}, SampleRate) if err != nil { return err } player, err = newPlayer(d, url) if err != nil { return err } } a.audios[url] = player return nil }
[ "func", "(", "a", "*", "audioLoader", ")", "Load", "(", "url", "string", ",", "data", "io", ".", "Reader", ")", "error", "{", "var", "err", "error", "\n", "audioBytes", ",", "err", ":=", "ioutil", ".", "ReadAll", "(", "data", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n\n", "audioBuffer", ":=", "bytes", ".", "NewReader", "(", "audioBytes", ")", "\n\n", "var", "player", "*", "Player", "\n", "switch", "getExt", "(", "url", ")", "{", "case", "\"", "\"", ":", "d", ",", "err", ":=", "wav", ".", "Decode", "(", "&", "readSeekCloserBuffer", "{", "audioBuffer", "}", ",", "SampleRate", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n\n", "player", ",", "err", "=", "newPlayer", "(", "d", ",", "url", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "case", "\"", "\"", ":", "d", ",", "err", ":=", "mp3", ".", "Decode", "(", "&", "readSeekCloserBuffer", "{", "audioBuffer", "}", ",", "SampleRate", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n\n", "player", ",", "err", "=", "newPlayer", "(", "d", ",", "url", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "case", "\"", "\"", ":", "d", ",", "err", ":=", "vorbis", ".", "Decode", "(", "&", "readSeekCloserBuffer", "{", "audioBuffer", "}", ",", "SampleRate", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n\n", "player", ",", "err", "=", "newPlayer", "(", "d", ",", "url", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "}", "\n\n", "a", ".", "audios", "[", "url", "]", "=", "player", "\n", "return", "nil", "\n", "}" ]
// Load processes the data stream and parses it as an audio file
[ "Load", "processes", "the", "data", "stream", "and", "parses", "it", "as", "an", "audio", "file" ]
6f88a7379a25d81e976cf6e86ea3617f3b480b1a
https://github.com/EngoEngine/engo/blob/6f88a7379a25d81e976cf6e86ea3617f3b480b1a/common/audio_filetype.go#L22-L67
12,656
EngoEngine/engo
common/audio_filetype.go
Unload
func (a *audioLoader) Unload(url string) error { delete(a.audios, url) return nil }
go
func (a *audioLoader) Unload(url string) error { delete(a.audios, url) return nil }
[ "func", "(", "a", "*", "audioLoader", ")", "Unload", "(", "url", "string", ")", "error", "{", "delete", "(", "a", ".", "audios", ",", "url", ")", "\n", "return", "nil", "\n", "}" ]
// Load removes the preloaded audio file from the cache
[ "Load", "removes", "the", "preloaded", "audio", "file", "from", "the", "cache" ]
6f88a7379a25d81e976cf6e86ea3617f3b480b1a
https://github.com/EngoEngine/engo/blob/6f88a7379a25d81e976cf6e86ea3617f3b480b1a/common/audio_filetype.go#L70-L73
12,657
EngoEngine/engo
common/audio_filetype.go
Resource
func (a *audioLoader) Resource(url string) (engo.Resource, error) { texture, ok := a.audios[url] if !ok { return nil, fmt.Errorf("resource not loaded by `FileLoader`: %q", url) } return texture, nil }
go
func (a *audioLoader) Resource(url string) (engo.Resource, error) { texture, ok := a.audios[url] if !ok { return nil, fmt.Errorf("resource not loaded by `FileLoader`: %q", url) } return texture, nil }
[ "func", "(", "a", "*", "audioLoader", ")", "Resource", "(", "url", "string", ")", "(", "engo", ".", "Resource", ",", "error", ")", "{", "texture", ",", "ok", ":=", "a", ".", "audios", "[", "url", "]", "\n", "if", "!", "ok", "{", "return", "nil", ",", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "url", ")", "\n", "}", "\n\n", "return", "texture", ",", "nil", "\n", "}" ]
// Resource retrieves the preloaded audio file, passed as a `AudioResource`
[ "Resource", "retrieves", "the", "preloaded", "audio", "file", "passed", "as", "a", "AudioResource" ]
6f88a7379a25d81e976cf6e86ea3617f3b480b1a
https://github.com/EngoEngine/engo/blob/6f88a7379a25d81e976cf6e86ea3617f3b480b1a/common/audio_filetype.go#L76-L83
12,658
EngoEngine/engo
math.go
Set
func (p *Point) Set(x, y float32) *Point { p.X = x p.Y = y return p }
go
func (p *Point) Set(x, y float32) *Point { p.X = x p.Y = y return p }
[ "func", "(", "p", "*", "Point", ")", "Set", "(", "x", ",", "y", "float32", ")", "*", "Point", "{", "p", ".", "X", "=", "x", "\n", "p", ".", "Y", "=", "y", "\n", "return", "p", "\n", "}" ]
// Set sets the coordinates of p to x and y
[ "Set", "sets", "the", "coordinates", "of", "p", "to", "x", "and", "y" ]
6f88a7379a25d81e976cf6e86ea3617f3b480b1a
https://github.com/EngoEngine/engo/blob/6f88a7379a25d81e976cf6e86ea3617f3b480b1a/math.go#L75-L79
12,659
EngoEngine/engo
math.go
AddScalar
func (p *Point) AddScalar(s float32) *Point { p.X += s p.Y += s return p }
go
func (p *Point) AddScalar(s float32) *Point { p.X += s p.Y += s return p }
[ "func", "(", "p", "*", "Point", ")", "AddScalar", "(", "s", "float32", ")", "*", "Point", "{", "p", ".", "X", "+=", "s", "\n", "p", ".", "Y", "+=", "s", "\n", "return", "p", "\n", "}" ]
// AddScalar adds s to each component of p
[ "AddScalar", "adds", "s", "to", "each", "component", "of", "p" ]
6f88a7379a25d81e976cf6e86ea3617f3b480b1a
https://github.com/EngoEngine/engo/blob/6f88a7379a25d81e976cf6e86ea3617f3b480b1a/math.go#L82-L86
12,660
EngoEngine/engo
math.go
SubtractScalar
func (p *Point) SubtractScalar(s float32) *Point { p.AddScalar(-s) return p }
go
func (p *Point) SubtractScalar(s float32) *Point { p.AddScalar(-s) return p }
[ "func", "(", "p", "*", "Point", ")", "SubtractScalar", "(", "s", "float32", ")", "*", "Point", "{", "p", ".", "AddScalar", "(", "-", "s", ")", "\n", "return", "p", "\n", "}" ]
// SubtractScalar subtracts s from each component of p
[ "SubtractScalar", "subtracts", "s", "from", "each", "component", "of", "p" ]
6f88a7379a25d81e976cf6e86ea3617f3b480b1a
https://github.com/EngoEngine/engo/blob/6f88a7379a25d81e976cf6e86ea3617f3b480b1a/math.go#L89-L92
12,661
EngoEngine/engo
math.go
MultiplyScalar
func (p *Point) MultiplyScalar(s float32) *Point { p.X *= s p.Y *= s return p }
go
func (p *Point) MultiplyScalar(s float32) *Point { p.X *= s p.Y *= s return p }
[ "func", "(", "p", "*", "Point", ")", "MultiplyScalar", "(", "s", "float32", ")", "*", "Point", "{", "p", ".", "X", "*=", "s", "\n", "p", ".", "Y", "*=", "s", "\n", "return", "p", "\n", "}" ]
// MultiplyScalar multiplies each component of p by s
[ "MultiplyScalar", "multiplies", "each", "component", "of", "p", "by", "s" ]
6f88a7379a25d81e976cf6e86ea3617f3b480b1a
https://github.com/EngoEngine/engo/blob/6f88a7379a25d81e976cf6e86ea3617f3b480b1a/math.go#L95-L99
12,662
EngoEngine/engo
math.go
Subtract
func (p *Point) Subtract(p2 Point) *Point { p.X -= p2.X p.Y -= p2.Y return p }
go
func (p *Point) Subtract(p2 Point) *Point { p.X -= p2.X p.Y -= p2.Y return p }
[ "func", "(", "p", "*", "Point", ")", "Subtract", "(", "p2", "Point", ")", "*", "Point", "{", "p", ".", "X", "-=", "p2", ".", "X", "\n", "p", ".", "Y", "-=", "p2", ".", "Y", "\n", "return", "p", "\n", "}" ]
// Subtract sets the components of p to the pointwise difference of p - p2
[ "Subtract", "sets", "the", "components", "of", "p", "to", "the", "pointwise", "difference", "of", "p", "-", "p2" ]
6f88a7379a25d81e976cf6e86ea3617f3b480b1a
https://github.com/EngoEngine/engo/blob/6f88a7379a25d81e976cf6e86ea3617f3b480b1a/math.go#L109-L113
12,663
EngoEngine/engo
math.go
Equal
func (p *Point) Equal(p2 Point) bool { return FloatEqual(p.X, p2.X) && FloatEqual(p.Y, p2.Y) }
go
func (p *Point) Equal(p2 Point) bool { return FloatEqual(p.X, p2.X) && FloatEqual(p.Y, p2.Y) }
[ "func", "(", "p", "*", "Point", ")", "Equal", "(", "p2", "Point", ")", "bool", "{", "return", "FloatEqual", "(", "p", ".", "X", ",", "p2", ".", "X", ")", "&&", "FloatEqual", "(", "p", ".", "Y", ",", "p2", ".", "Y", ")", "\n", "}" ]
// Equal indicates whether two points have the same value, avoiding issues with float precision
[ "Equal", "indicates", "whether", "two", "points", "have", "the", "same", "value", "avoiding", "issues", "with", "float", "precision" ]
6f88a7379a25d81e976cf6e86ea3617f3b480b1a
https://github.com/EngoEngine/engo/blob/6f88a7379a25d81e976cf6e86ea3617f3b480b1a/math.go#L123-L125
12,664
EngoEngine/engo
math.go
PointDistance
func (p *Point) PointDistance(p2 Point) float32 { return math.Sqrt(p.PointDistanceSquared(p2)) }
go
func (p *Point) PointDistance(p2 Point) float32 { return math.Sqrt(p.PointDistanceSquared(p2)) }
[ "func", "(", "p", "*", "Point", ")", "PointDistance", "(", "p2", "Point", ")", "float32", "{", "return", "math", ".", "Sqrt", "(", "p", ".", "PointDistanceSquared", "(", "p2", ")", ")", "\n", "}" ]
// PointDistance returns the euclidean distance between p and p2
[ "PointDistance", "returns", "the", "euclidean", "distance", "between", "p", "and", "p2" ]
6f88a7379a25d81e976cf6e86ea3617f3b480b1a
https://github.com/EngoEngine/engo/blob/6f88a7379a25d81e976cf6e86ea3617f3b480b1a/math.go#L128-L130
12,665
EngoEngine/engo
math.go
PointDistanceSquared
func (p *Point) PointDistanceSquared(p2 Point) float32 { return (p.X-p2.X)*(p.X-p2.X) + (p.Y-p2.Y)*(p.Y-p2.Y) }
go
func (p *Point) PointDistanceSquared(p2 Point) float32 { return (p.X-p2.X)*(p.X-p2.X) + (p.Y-p2.Y)*(p.Y-p2.Y) }
[ "func", "(", "p", "*", "Point", ")", "PointDistanceSquared", "(", "p2", "Point", ")", "float32", "{", "return", "(", "p", ".", "X", "-", "p2", ".", "X", ")", "*", "(", "p", ".", "X", "-", "p2", ".", "X", ")", "+", "(", "p", ".", "Y", "-", "p2", ".", "Y", ")", "*", "(", "p", ".", "Y", "-", "p2", ".", "Y", ")", "\n", "}" ]
// PointDistanceSquared returns the squared euclidean distance between p and p2
[ "PointDistanceSquared", "returns", "the", "squared", "euclidean", "distance", "between", "p", "and", "p2" ]
6f88a7379a25d81e976cf6e86ea3617f3b480b1a
https://github.com/EngoEngine/engo/blob/6f88a7379a25d81e976cf6e86ea3617f3b480b1a/math.go#L133-L135
12,666
EngoEngine/engo
math.go
ProjectOnto
func (p *Point) ProjectOnto(p2 Point) Point { dot := p.X*p2.X + p.Y*p2.Y denom := p2.X*p2.X + p2.Y*p2.Y if FloatEqual(denom, 0) { return Point{} } return Point{ dot / denom * p2.X, dot / denom * p2.Y, } }
go
func (p *Point) ProjectOnto(p2 Point) Point { dot := p.X*p2.X + p.Y*p2.Y denom := p2.X*p2.X + p2.Y*p2.Y if FloatEqual(denom, 0) { return Point{} } return Point{ dot / denom * p2.X, dot / denom * p2.Y, } }
[ "func", "(", "p", "*", "Point", ")", "ProjectOnto", "(", "p2", "Point", ")", "Point", "{", "dot", ":=", "p", ".", "X", "*", "p2", ".", "X", "+", "p", ".", "Y", "*", "p2", ".", "Y", "\n", "denom", ":=", "p2", ".", "X", "*", "p2", ".", "X", "+", "p2", ".", "Y", "*", "p2", ".", "Y", "\n", "if", "FloatEqual", "(", "denom", ",", "0", ")", "{", "return", "Point", "{", "}", "\n", "}", "\n", "return", "Point", "{", "dot", "/", "denom", "*", "p2", ".", "X", ",", "dot", "/", "denom", "*", "p2", ".", "Y", ",", "}", "\n", "}" ]
// ProjectOnto returns the vector produced by projecting p on to p2 // returns an empty Point if they can't project onto one another
[ "ProjectOnto", "returns", "the", "vector", "produced", "by", "projecting", "p", "on", "to", "p2", "returns", "an", "empty", "Point", "if", "they", "can", "t", "project", "onto", "one", "another" ]
6f88a7379a25d81e976cf6e86ea3617f3b480b1a
https://github.com/EngoEngine/engo/blob/6f88a7379a25d81e976cf6e86ea3617f3b480b1a/math.go#L139-L149
12,667
EngoEngine/engo
math.go
Normalize
func (p *Point) Normalize() (Point, float32) { if p.X == 0 && p.Y == 0 { return *p, 0 } mag := math.Sqrt(p.X*p.X + p.Y*p.Y) unit := Point{p.X / mag, p.Y / mag} return unit, mag }
go
func (p *Point) Normalize() (Point, float32) { if p.X == 0 && p.Y == 0 { return *p, 0 } mag := math.Sqrt(p.X*p.X + p.Y*p.Y) unit := Point{p.X / mag, p.Y / mag} return unit, mag }
[ "func", "(", "p", "*", "Point", ")", "Normalize", "(", ")", "(", "Point", ",", "float32", ")", "{", "if", "p", ".", "X", "==", "0", "&&", "p", ".", "Y", "==", "0", "{", "return", "*", "p", ",", "0", "\n", "}", "\n\n", "mag", ":=", "math", ".", "Sqrt", "(", "p", ".", "X", "*", "p", ".", "X", "+", "p", ".", "Y", "*", "p", ".", "Y", ")", "\n", "unit", ":=", "Point", "{", "p", ".", "X", "/", "mag", ",", "p", ".", "Y", "/", "mag", "}", "\n\n", "return", "unit", ",", "mag", "\n", "}" ]
// Normalize returns the unit vector from p, and its magnitude. // if you try to normalize the null vector, the return value will be null values
[ "Normalize", "returns", "the", "unit", "vector", "from", "p", "and", "its", "magnitude", ".", "if", "you", "try", "to", "normalize", "the", "null", "vector", "the", "return", "value", "will", "be", "null", "values" ]
6f88a7379a25d81e976cf6e86ea3617f3b480b1a
https://github.com/EngoEngine/engo/blob/6f88a7379a25d81e976cf6e86ea3617f3b480b1a/math.go#L153-L162
12,668
EngoEngine/engo
math.go
Set
func (m *Matrix) Set(val []float32) *Matrix { copy(m.Val[:], val) return m }
go
func (m *Matrix) Set(val []float32) *Matrix { copy(m.Val[:], val) return m }
[ "func", "(", "m", "*", "Matrix", ")", "Set", "(", "val", "[", "]", "float32", ")", "*", "Matrix", "{", "copy", "(", "m", ".", "Val", "[", ":", "]", ",", "val", ")", "\n", "return", "m", "\n", "}" ]
// Set sets the matrix to the given float slice and returns the matrix. The float // slice must have at least 9 elements. If the float slie contains more than 9 elements, // only the first 9 will be copied.
[ "Set", "sets", "the", "matrix", "to", "the", "given", "float", "slice", "and", "returns", "the", "matrix", ".", "The", "float", "slice", "must", "have", "at", "least", "9", "elements", ".", "If", "the", "float", "slie", "contains", "more", "than", "9", "elements", "only", "the", "first", "9", "will", "be", "copied", "." ]
6f88a7379a25d81e976cf6e86ea3617f3b480b1a
https://github.com/EngoEngine/engo/blob/6f88a7379a25d81e976cf6e86ea3617f3b480b1a/math.go#L172-L175
12,669
EngoEngine/engo
math.go
Identity
func (m *Matrix) Identity() *Matrix { m.Val[m00] = 1 m.Val[m10] = 0 m.Val[m20] = 0 m.Val[m01] = 0 m.Val[m11] = 1 m.Val[m21] = 0 m.Val[m02] = 0 m.Val[m12] = 0 m.Val[m22] = 1 return m }
go
func (m *Matrix) Identity() *Matrix { m.Val[m00] = 1 m.Val[m10] = 0 m.Val[m20] = 0 m.Val[m01] = 0 m.Val[m11] = 1 m.Val[m21] = 0 m.Val[m02] = 0 m.Val[m12] = 0 m.Val[m22] = 1 return m }
[ "func", "(", "m", "*", "Matrix", ")", "Identity", "(", ")", "*", "Matrix", "{", "m", ".", "Val", "[", "m00", "]", "=", "1", "\n", "m", ".", "Val", "[", "m10", "]", "=", "0", "\n", "m", ".", "Val", "[", "m20", "]", "=", "0", "\n", "m", ".", "Val", "[", "m01", "]", "=", "0", "\n", "m", ".", "Val", "[", "m11", "]", "=", "1", "\n", "m", ".", "Val", "[", "m21", "]", "=", "0", "\n", "m", ".", "Val", "[", "m02", "]", "=", "0", "\n", "m", ".", "Val", "[", "m12", "]", "=", "0", "\n", "m", ".", "Val", "[", "m22", "]", "=", "1", "\n", "return", "m", "\n", "}" ]
// Identity sets the matrix to the Identity matrix and returns the matrix.
[ "Identity", "sets", "the", "matrix", "to", "the", "Identity", "matrix", "and", "returns", "the", "matrix", "." ]
6f88a7379a25d81e976cf6e86ea3617f3b480b1a
https://github.com/EngoEngine/engo/blob/6f88a7379a25d81e976cf6e86ea3617f3b480b1a/math.go#L178-L189
12,670
EngoEngine/engo
math.go
Multiply
func (m *Matrix) Multiply(m2 *Matrix) *Matrix { multiplyMatricies(m.Val[:], m2.Val[:]) return m }
go
func (m *Matrix) Multiply(m2 *Matrix) *Matrix { multiplyMatricies(m.Val[:], m2.Val[:]) return m }
[ "func", "(", "m", "*", "Matrix", ")", "Multiply", "(", "m2", "*", "Matrix", ")", "*", "Matrix", "{", "multiplyMatricies", "(", "m", ".", "Val", "[", ":", "]", ",", "m2", ".", "Val", "[", ":", "]", ")", "\n", "return", "m", "\n", "}" ]
// Multiply postmultiplies m matrix with m2 and stores the result in m, returning m. // Multiplaction is the result of m2 times m.
[ "Multiply", "postmultiplies", "m", "matrix", "with", "m2", "and", "stores", "the", "result", "in", "m", "returning", "m", ".", "Multiplaction", "is", "the", "result", "of", "m2", "times", "m", "." ]
6f88a7379a25d81e976cf6e86ea3617f3b480b1a
https://github.com/EngoEngine/engo/blob/6f88a7379a25d81e976cf6e86ea3617f3b480b1a/math.go#L193-L196
12,671
EngoEngine/engo
math.go
TranslatePoint
func (m *Matrix) TranslatePoint(p Point) *Matrix { return m.Translate(p.X, p.Y) }
go
func (m *Matrix) TranslatePoint(p Point) *Matrix { return m.Translate(p.X, p.Y) }
[ "func", "(", "m", "*", "Matrix", ")", "TranslatePoint", "(", "p", "Point", ")", "*", "Matrix", "{", "return", "m", ".", "Translate", "(", "p", ".", "X", ",", "p", ".", "Y", ")", "\n", "}" ]
// TranslatePoint translates m by the point p.
[ "TranslatePoint", "translates", "m", "by", "the", "point", "p", "." ]
6f88a7379a25d81e976cf6e86ea3617f3b480b1a
https://github.com/EngoEngine/engo/blob/6f88a7379a25d81e976cf6e86ea3617f3b480b1a/math.go#L217-L219
12,672
EngoEngine/engo
math.go
ScaleComponent
func (m *Matrix) ScaleComponent() (x, y float32) { return m.Val[m00], m.Val[m11] }
go
func (m *Matrix) ScaleComponent() (x, y float32) { return m.Val[m00], m.Val[m11] }
[ "func", "(", "m", "*", "Matrix", ")", "ScaleComponent", "(", ")", "(", "x", ",", "y", "float32", ")", "{", "return", "m", ".", "Val", "[", "m00", "]", ",", "m", ".", "Val", "[", "m11", "]", "\n", "}" ]
// ScaleComponent returns the current scale component of m. // This assumes uniform scaling.
[ "ScaleComponent", "returns", "the", "current", "scale", "component", "of", "m", ".", "This", "assumes", "uniform", "scaling", "." ]
6f88a7379a25d81e976cf6e86ea3617f3b480b1a
https://github.com/EngoEngine/engo/blob/6f88a7379a25d81e976cf6e86ea3617f3b480b1a/math.go#L240-L242
12,673
EngoEngine/engo
math.go
TranslationComponent
func (m *Matrix) TranslationComponent() (x, y float32) { return m.Val[m02], m.Val[m12] }
go
func (m *Matrix) TranslationComponent() (x, y float32) { return m.Val[m02], m.Val[m12] }
[ "func", "(", "m", "*", "Matrix", ")", "TranslationComponent", "(", ")", "(", "x", ",", "y", "float32", ")", "{", "return", "m", ".", "Val", "[", "m02", "]", ",", "m", ".", "Val", "[", "m12", "]", "\n", "}" ]
// TranslationComponent returns the current translation component of m. // This assumes uniform scaling.
[ "TranslationComponent", "returns", "the", "current", "translation", "component", "of", "m", ".", "This", "assumes", "uniform", "scaling", "." ]
6f88a7379a25d81e976cf6e86ea3617f3b480b1a
https://github.com/EngoEngine/engo/blob/6f88a7379a25d81e976cf6e86ea3617f3b480b1a/math.go#L246-L248
12,674
EngoEngine/engo
math.go
RotationComponentRad
func (m *Matrix) RotationComponentRad() float32 { return math.Atan2(m.Val[m10], m.Val[m00]) }
go
func (m *Matrix) RotationComponentRad() float32 { return math.Atan2(m.Val[m10], m.Val[m00]) }
[ "func", "(", "m", "*", "Matrix", ")", "RotationComponentRad", "(", ")", "float32", "{", "return", "math", ".", "Atan2", "(", "m", ".", "Val", "[", "m10", "]", ",", "m", ".", "Val", "[", "m00", "]", ")", "\n", "}" ]
// RotationComponentRad returns the current rotation component of m in radians. // This assumes uniform scaling.
[ "RotationComponentRad", "returns", "the", "current", "rotation", "component", "of", "m", "in", "radians", ".", "This", "assumes", "uniform", "scaling", "." ]
6f88a7379a25d81e976cf6e86ea3617f3b480b1a
https://github.com/EngoEngine/engo/blob/6f88a7379a25d81e976cf6e86ea3617f3b480b1a/math.go#L258-L260
12,675
EngoEngine/engo
math.go
Rotate
func (m *Matrix) Rotate(deg float32) *Matrix { return m.RotateRad(deg * DegToRad) }
go
func (m *Matrix) Rotate(deg float32) *Matrix { return m.RotateRad(deg * DegToRad) }
[ "func", "(", "m", "*", "Matrix", ")", "Rotate", "(", "deg", "float32", ")", "*", "Matrix", "{", "return", "m", ".", "RotateRad", "(", "deg", "*", "DegToRad", ")", "\n", "}" ]
// Rotate rorates m counter-clockwise by deg degrees.
[ "Rotate", "rorates", "m", "counter", "-", "clockwise", "by", "deg", "degrees", "." ]
6f88a7379a25d81e976cf6e86ea3617f3b480b1a
https://github.com/EngoEngine/engo/blob/6f88a7379a25d81e976cf6e86ea3617f3b480b1a/math.go#L263-L265
12,676
EngoEngine/engo
math.go
RotateRad
func (m *Matrix) RotateRad(rad float32) *Matrix { if rad == 0 { return m } sin, cos := math.Sincos(rad) m.tmp[m00] = cos m.tmp[m10] = sin m.tmp[m20] = 0 m.tmp[m01] = -sin m.tmp[m11] = cos m.tmp[m21] = 0 m.tmp[m02] = 0 m.tmp[m12] = 0 m.tmp[m22] = 1 multiplyMatricies(m.Val[:], m.tmp[:]) return m }
go
func (m *Matrix) RotateRad(rad float32) *Matrix { if rad == 0 { return m } sin, cos := math.Sincos(rad) m.tmp[m00] = cos m.tmp[m10] = sin m.tmp[m20] = 0 m.tmp[m01] = -sin m.tmp[m11] = cos m.tmp[m21] = 0 m.tmp[m02] = 0 m.tmp[m12] = 0 m.tmp[m22] = 1 multiplyMatricies(m.Val[:], m.tmp[:]) return m }
[ "func", "(", "m", "*", "Matrix", ")", "RotateRad", "(", "rad", "float32", ")", "*", "Matrix", "{", "if", "rad", "==", "0", "{", "return", "m", "\n", "}", "\n", "sin", ",", "cos", ":=", "math", ".", "Sincos", "(", "rad", ")", "\n", "m", ".", "tmp", "[", "m00", "]", "=", "cos", "\n", "m", ".", "tmp", "[", "m10", "]", "=", "sin", "\n", "m", ".", "tmp", "[", "m20", "]", "=", "0", "\n\n", "m", ".", "tmp", "[", "m01", "]", "=", "-", "sin", "\n", "m", ".", "tmp", "[", "m11", "]", "=", "cos", "\n", "m", ".", "tmp", "[", "m21", "]", "=", "0", "\n\n", "m", ".", "tmp", "[", "m02", "]", "=", "0", "\n", "m", ".", "tmp", "[", "m12", "]", "=", "0", "\n", "m", ".", "tmp", "[", "m22", "]", "=", "1", "\n", "multiplyMatricies", "(", "m", ".", "Val", "[", ":", "]", ",", "m", ".", "tmp", "[", ":", "]", ")", "\n", "return", "m", "\n", "}" ]
// RotateRad rotates m counter-clockwise by rad radians.
[ "RotateRad", "rotates", "m", "counter", "-", "clockwise", "by", "rad", "radians", "." ]
6f88a7379a25d81e976cf6e86ea3617f3b480b1a
https://github.com/EngoEngine/engo/blob/6f88a7379a25d81e976cf6e86ea3617f3b480b1a/math.go#L268-L286
12,677
EngoEngine/engo
math.go
PointDistance
func (l *Line) PointDistance(point Point) float32 { return math.Sqrt(l.PointDistanceSquared(point)) }
go
func (l *Line) PointDistance(point Point) float32 { return math.Sqrt(l.PointDistanceSquared(point)) }
[ "func", "(", "l", "*", "Line", ")", "PointDistance", "(", "point", "Point", ")", "float32", "{", "return", "math", ".", "Sqrt", "(", "l", ".", "PointDistanceSquared", "(", "point", ")", ")", "\n", "}" ]
// PointDistance Returns the euclidean distance from the point p to the // line segment l
[ "PointDistance", "Returns", "the", "euclidean", "distance", "from", "the", "point", "p", "to", "the", "line", "segment", "l" ]
6f88a7379a25d81e976cf6e86ea3617f3b480b1a
https://github.com/EngoEngine/engo/blob/6f88a7379a25d81e976cf6e86ea3617f3b480b1a/math.go#L331-L333
12,678
EngoEngine/engo
math.go
PointDistanceSquared
func (l *Line) PointDistanceSquared(point Point) float32 { p1 := l.P1 p2 := l.P2 x0 := point.X y0 := point.Y x1 := p1.X y1 := p1.Y x2 := p2.X y2 := p2.Y l2 := (y2-y1)*(y2-y1) + (x2-x1)*(x2-x1) if l2 == 0 { return (y0-y1)*(y0-y1) + (x0-x1)*(x0-x1) } t := ((x0-x1)*(x2-x1) + (y0-y1)*(y2-y1)) / l2 if t < 0 { return (y0-y1)*(y0-y1) + (x0-x1)*(x0-x1) } else if t > 1 { return (y0-y2)*(y0-y2) + (x0-x2)*(x0-x2) } return (x0-(x1+t*(x2-x1)))*(x0-(x1+t*(x2-x1))) + (y0-(y1+t*(y2-y1)))*(y0-(y1+t*(y2-y1))) }
go
func (l *Line) PointDistanceSquared(point Point) float32 { p1 := l.P1 p2 := l.P2 x0 := point.X y0 := point.Y x1 := p1.X y1 := p1.Y x2 := p2.X y2 := p2.Y l2 := (y2-y1)*(y2-y1) + (x2-x1)*(x2-x1) if l2 == 0 { return (y0-y1)*(y0-y1) + (x0-x1)*(x0-x1) } t := ((x0-x1)*(x2-x1) + (y0-y1)*(y2-y1)) / l2 if t < 0 { return (y0-y1)*(y0-y1) + (x0-x1)*(x0-x1) } else if t > 1 { return (y0-y2)*(y0-y2) + (x0-x2)*(x0-x2) } return (x0-(x1+t*(x2-x1)))*(x0-(x1+t*(x2-x1))) + (y0-(y1+t*(y2-y1)))*(y0-(y1+t*(y2-y1))) }
[ "func", "(", "l", "*", "Line", ")", "PointDistanceSquared", "(", "point", "Point", ")", "float32", "{", "p1", ":=", "l", ".", "P1", "\n", "p2", ":=", "l", ".", "P2", "\n\n", "x0", ":=", "point", ".", "X", "\n", "y0", ":=", "point", ".", "Y", "\n", "x1", ":=", "p1", ".", "X", "\n", "y1", ":=", "p1", ".", "Y", "\n", "x2", ":=", "p2", ".", "X", "\n", "y2", ":=", "p2", ".", "Y", "\n\n", "l2", ":=", "(", "y2", "-", "y1", ")", "*", "(", "y2", "-", "y1", ")", "+", "(", "x2", "-", "x1", ")", "*", "(", "x2", "-", "x1", ")", "\n", "if", "l2", "==", "0", "{", "return", "(", "y0", "-", "y1", ")", "*", "(", "y0", "-", "y1", ")", "+", "(", "x0", "-", "x1", ")", "*", "(", "x0", "-", "x1", ")", "\n", "}", "\n\n", "t", ":=", "(", "(", "x0", "-", "x1", ")", "*", "(", "x2", "-", "x1", ")", "+", "(", "y0", "-", "y1", ")", "*", "(", "y2", "-", "y1", ")", ")", "/", "l2", "\n\n", "if", "t", "<", "0", "{", "return", "(", "y0", "-", "y1", ")", "*", "(", "y0", "-", "y1", ")", "+", "(", "x0", "-", "x1", ")", "*", "(", "x0", "-", "x1", ")", "\n", "}", "else", "if", "t", ">", "1", "{", "return", "(", "y0", "-", "y2", ")", "*", "(", "y0", "-", "y2", ")", "+", "(", "x0", "-", "x2", ")", "*", "(", "x0", "-", "x2", ")", "\n", "}", "\n\n", "return", "(", "x0", "-", "(", "x1", "+", "t", "*", "(", "x2", "-", "x1", ")", ")", ")", "*", "(", "x0", "-", "(", "x1", "+", "t", "*", "(", "x2", "-", "x1", ")", ")", ")", "+", "(", "y0", "-", "(", "y1", "+", "t", "*", "(", "y2", "-", "y1", ")", ")", ")", "*", "(", "y0", "-", "(", "y1", "+", "t", "*", "(", "y2", "-", "y1", ")", ")", ")", "\n", "}" ]
// PointDistanceSquared returns the squared euclidean distance from the point p // to the line segment l
[ "PointDistanceSquared", "returns", "the", "squared", "euclidean", "distance", "from", "the", "point", "p", "to", "the", "line", "segment", "l" ]
6f88a7379a25d81e976cf6e86ea3617f3b480b1a
https://github.com/EngoEngine/engo/blob/6f88a7379a25d81e976cf6e86ea3617f3b480b1a/math.go#L337-L363
12,679
EngoEngine/engo
math.go
Normal
func (l *Line) Normal() Point { dx := l.P2.X - l.P1.X dy := l.P2.Y - l.P1.Y inverse := Point{dy, -dx} unit, _ := inverse.Normalize() return unit }
go
func (l *Line) Normal() Point { dx := l.P2.X - l.P1.X dy := l.P2.Y - l.P1.Y inverse := Point{dy, -dx} unit, _ := inverse.Normalize() return unit }
[ "func", "(", "l", "*", "Line", ")", "Normal", "(", ")", "Point", "{", "dx", ":=", "l", ".", "P2", ".", "X", "-", "l", ".", "P1", ".", "X", "\n", "dy", ":=", "l", ".", "P2", ".", "Y", "-", "l", ".", "P1", ".", "Y", "\n", "inverse", ":=", "Point", "{", "dy", ",", "-", "dx", "}", "\n", "unit", ",", "_", ":=", "inverse", ".", "Normalize", "(", ")", "\n\n", "return", "unit", "\n", "}" ]
// Normal returns the left hand normal of the line segment l
[ "Normal", "returns", "the", "left", "hand", "normal", "of", "the", "line", "segment", "l" ]
6f88a7379a25d81e976cf6e86ea3617f3b480b1a
https://github.com/EngoEngine/engo/blob/6f88a7379a25d81e976cf6e86ea3617f3b480b1a/math.go#L366-L373
12,680
EngoEngine/engo
math.go
DotProduct
func DotProduct(this, that Point) float32 { return this.X*that.X + this.Y*that.Y }
go
func DotProduct(this, that Point) float32 { return this.X*that.X + this.Y*that.Y }
[ "func", "DotProduct", "(", "this", ",", "that", "Point", ")", "float32", "{", "return", "this", ".", "X", "*", "that", ".", "X", "+", "this", ".", "Y", "*", "that", ".", "Y", "\n", "}" ]
// DotProduct returns the dot product between this and that
[ "DotProduct", "returns", "the", "dot", "product", "between", "this", "and", "that" ]
6f88a7379a25d81e976cf6e86ea3617f3b480b1a
https://github.com/EngoEngine/engo/blob/6f88a7379a25d81e976cf6e86ea3617f3b480b1a/math.go#L381-L383
12,681
EngoEngine/engo
math.go
CrossProduct
func CrossProduct(this, that Point) float32 { return this.X*that.Y - this.Y*that.X }
go
func CrossProduct(this, that Point) float32 { return this.X*that.Y - this.Y*that.X }
[ "func", "CrossProduct", "(", "this", ",", "that", "Point", ")", "float32", "{", "return", "this", ".", "X", "*", "that", ".", "Y", "-", "this", ".", "Y", "*", "that", ".", "X", "\n", "}" ]
// CrossProduct returns the 2 dimensional cross product of this and that, // which represents the magnitude of the three dimensional cross product
[ "CrossProduct", "returns", "the", "2", "dimensional", "cross", "product", "of", "this", "and", "that", "which", "represents", "the", "magnitude", "of", "the", "three", "dimensional", "cross", "product" ]
6f88a7379a25d81e976cf6e86ea3617f3b480b1a
https://github.com/EngoEngine/engo/blob/6f88a7379a25d81e976cf6e86ea3617f3b480b1a/math.go#L387-L389
12,682
EngoEngine/engo
math.go
LineIntersection
func LineIntersection(one, two Line) (Point, bool) { p := one.P1 q := two.P1 r := one.P2 r.Subtract(p) s := two.P2 s.Subtract(q) // t = (q − p) × s / (r × s) // u = (q − p) × r / (r × s) // So then we define // qmp = (q - p) // rcs = (r × s) // and we get simply: // t = qmp × s / rcs // u = qmp × r / rcs qmp := q qmp.Subtract(p) qmpcs := CrossProduct(qmp, s) qmpcr := CrossProduct(qmp, r) rcs := CrossProduct(r, s) t := qmpcs / rcs u := qmpcr / rcs // if rcs == 0 then it's either collinear or parallel. It'll be +/- inf, so it'll skip this statement and return at the end if t >= 0 && t <= 1 && u >= 0 && u <= 1 { // the two line segments meet at the point p + t r = q + u s. return Point{p.X + t*r.X, p.Y + t*r.Y}, true } return Point{}, false }
go
func LineIntersection(one, two Line) (Point, bool) { p := one.P1 q := two.P1 r := one.P2 r.Subtract(p) s := two.P2 s.Subtract(q) // t = (q − p) × s / (r × s) // u = (q − p) × r / (r × s) // So then we define // qmp = (q - p) // rcs = (r × s) // and we get simply: // t = qmp × s / rcs // u = qmp × r / rcs qmp := q qmp.Subtract(p) qmpcs := CrossProduct(qmp, s) qmpcr := CrossProduct(qmp, r) rcs := CrossProduct(r, s) t := qmpcs / rcs u := qmpcr / rcs // if rcs == 0 then it's either collinear or parallel. It'll be +/- inf, so it'll skip this statement and return at the end if t >= 0 && t <= 1 && u >= 0 && u <= 1 { // the two line segments meet at the point p + t r = q + u s. return Point{p.X + t*r.X, p.Y + t*r.Y}, true } return Point{}, false }
[ "func", "LineIntersection", "(", "one", ",", "two", "Line", ")", "(", "Point", ",", "bool", ")", "{", "p", ":=", "one", ".", "P1", "\n", "q", ":=", "two", ".", "P1", "\n\n", "r", ":=", "one", ".", "P2", "\n", "r", ".", "Subtract", "(", "p", ")", "\n", "s", ":=", "two", ".", "P2", "\n", "s", ".", "Subtract", "(", "q", ")", "\n\n", "// t = (q − p) × s / (r × s)", "// u = (q − p) × r / (r × s)", "// So then we define", "// qmp = (q - p)", "// rcs = (r × s)", "// and we get simply:", "// t = qmp × s / rcs", "// u = qmp × r / rcs", "qmp", ":=", "q", "\n", "qmp", ".", "Subtract", "(", "p", ")", "\n", "qmpcs", ":=", "CrossProduct", "(", "qmp", ",", "s", ")", "\n", "qmpcr", ":=", "CrossProduct", "(", "qmp", ",", "r", ")", "\n", "rcs", ":=", "CrossProduct", "(", "r", ",", "s", ")", "\n\n", "t", ":=", "qmpcs", "/", "rcs", "\n", "u", ":=", "qmpcr", "/", "rcs", "\n", "// if rcs == 0 then it's either collinear or parallel. It'll be +/- inf, so it'll skip this statement and return at the end", "if", "t", ">=", "0", "&&", "t", "<=", "1", "&&", "u", ">=", "0", "&&", "u", "<=", "1", "{", "// the two line segments meet at the point p + t r = q + u s.", "return", "Point", "{", "p", ".", "X", "+", "t", "*", "r", ".", "X", ",", "p", ".", "Y", "+", "t", "*", "r", ".", "Y", "}", ",", "true", "\n", "}", "\n\n", "return", "Point", "{", "}", ",", "false", "\n", "}" ]
// LineIntersection returns the point where the line segments one and two // intersect and true if there is intersection, nil and false when line // segments one and two do not intersect
[ "LineIntersection", "returns", "the", "point", "where", "the", "line", "segments", "one", "and", "two", "intersect", "and", "true", "if", "there", "is", "intersection", "nil", "and", "false", "when", "line", "segments", "one", "and", "two", "do", "not", "intersect" ]
6f88a7379a25d81e976cf6e86ea3617f3b480b1a
https://github.com/EngoEngine/engo/blob/6f88a7379a25d81e976cf6e86ea3617f3b480b1a/math.go#L394-L426
12,683
EngoEngine/engo
math.go
LineTraceFraction
func LineTraceFraction(tracer, boundary Line) float32 { pt, intersect := LineIntersection(tracer, boundary) if !intersect { return 1 } traceMag := tracer.P1.PointDistance(pt) lineMag := tracer.P1.PointDistance(tracer.P2) return traceMag / lineMag }
go
func LineTraceFraction(tracer, boundary Line) float32 { pt, intersect := LineIntersection(tracer, boundary) if !intersect { return 1 } traceMag := tracer.P1.PointDistance(pt) lineMag := tracer.P1.PointDistance(tracer.P2) return traceMag / lineMag }
[ "func", "LineTraceFraction", "(", "tracer", ",", "boundary", "Line", ")", "float32", "{", "pt", ",", "intersect", ":=", "LineIntersection", "(", "tracer", ",", "boundary", ")", "\n", "if", "!", "intersect", "{", "return", "1", "\n", "}", "\n\n", "traceMag", ":=", "tracer", ".", "P1", ".", "PointDistance", "(", "pt", ")", "\n", "lineMag", ":=", "tracer", ".", "P1", ".", "PointDistance", "(", "tracer", ".", "P2", ")", "\n\n", "return", "traceMag", "/", "lineMag", "\n", "}" ]
// LineTraceFraction returns the trace fraction of tracer through boundary // 1 means no intersection // 0 means tracer's origin lies on the boundary line
[ "LineTraceFraction", "returns", "the", "trace", "fraction", "of", "tracer", "through", "boundary", "1", "means", "no", "intersection", "0", "means", "tracer", "s", "origin", "lies", "on", "the", "boundary", "line" ]
6f88a7379a25d81e976cf6e86ea3617f3b480b1a
https://github.com/EngoEngine/engo/blob/6f88a7379a25d81e976cf6e86ea3617f3b480b1a/math.go#L431-L441
12,684
EngoEngine/engo
math.go
LineTrace
func LineTrace(tracer Line, boundaries []Line) Trace { var t Trace t.Fraction = math.Inf(1) for _, cl := range boundaries { fraction := LineTraceFraction(tracer, cl) if fraction < t.Fraction { t.Fraction = fraction t.Line = cl moveVector := tracer.P2 moveVector.Subtract(tracer.P1) moveVector.MultiplyScalar(t.Fraction) t.EndPosition = tracer.P1 t.EndPosition.Add(moveVector) } } return t }
go
func LineTrace(tracer Line, boundaries []Line) Trace { var t Trace t.Fraction = math.Inf(1) for _, cl := range boundaries { fraction := LineTraceFraction(tracer, cl) if fraction < t.Fraction { t.Fraction = fraction t.Line = cl moveVector := tracer.P2 moveVector.Subtract(tracer.P1) moveVector.MultiplyScalar(t.Fraction) t.EndPosition = tracer.P1 t.EndPosition.Add(moveVector) } } return t }
[ "func", "LineTrace", "(", "tracer", "Line", ",", "boundaries", "[", "]", "Line", ")", "Trace", "{", "var", "t", "Trace", "\n", "t", ".", "Fraction", "=", "math", ".", "Inf", "(", "1", ")", "\n\n", "for", "_", ",", "cl", ":=", "range", "boundaries", "{", "fraction", ":=", "LineTraceFraction", "(", "tracer", ",", "cl", ")", "\n\n", "if", "fraction", "<", "t", ".", "Fraction", "{", "t", ".", "Fraction", "=", "fraction", "\n", "t", ".", "Line", "=", "cl", "\n\n", "moveVector", ":=", "tracer", ".", "P2", "\n", "moveVector", ".", "Subtract", "(", "tracer", ".", "P1", ")", "\n", "moveVector", ".", "MultiplyScalar", "(", "t", ".", "Fraction", ")", "\n", "t", ".", "EndPosition", "=", "tracer", ".", "P1", "\n", "t", ".", "EndPosition", ".", "Add", "(", "moveVector", ")", "\n", "}", "\n", "}", "\n\n", "return", "t", "\n", "}" ]
// LineTrace runs a series of line traces from tracer to each boundary line // and returns the nearest trace values
[ "LineTrace", "runs", "a", "series", "of", "line", "traces", "from", "tracer", "to", "each", "boundary", "line", "and", "returns", "the", "nearest", "trace", "values" ]
6f88a7379a25d81e976cf6e86ea3617f3b480b1a
https://github.com/EngoEngine/engo/blob/6f88a7379a25d81e976cf6e86ea3617f3b480b1a/math.go#L445-L465
12,685
EngoEngine/engo
math.go
MultiplyMatrixVector
func MultiplyMatrixVector(m *Matrix, v []float32) []float32 { if len(v) == 2 { v = []float32{v[0], v[1], 1} } v00 := m.Val[m00]*v[m00] + m.Val[m01]*v[m10] + m.Val[m02]*v[m20] v10 := m.Val[m10]*v[m00] + m.Val[m11]*v[m10] + m.Val[m12]*v[m20] v20 := m.Val[m20]*v[m00] + m.Val[m21]*v[m10] + m.Val[m22]*v[m20] return []float32{v00, v10, v20} }
go
func MultiplyMatrixVector(m *Matrix, v []float32) []float32 { if len(v) == 2 { v = []float32{v[0], v[1], 1} } v00 := m.Val[m00]*v[m00] + m.Val[m01]*v[m10] + m.Val[m02]*v[m20] v10 := m.Val[m10]*v[m00] + m.Val[m11]*v[m10] + m.Val[m12]*v[m20] v20 := m.Val[m20]*v[m00] + m.Val[m21]*v[m10] + m.Val[m22]*v[m20] return []float32{v00, v10, v20} }
[ "func", "MultiplyMatrixVector", "(", "m", "*", "Matrix", ",", "v", "[", "]", "float32", ")", "[", "]", "float32", "{", "if", "len", "(", "v", ")", "==", "2", "{", "v", "=", "[", "]", "float32", "{", "v", "[", "0", "]", ",", "v", "[", "1", "]", ",", "1", "}", "\n", "}", "\n", "v00", ":=", "m", ".", "Val", "[", "m00", "]", "*", "v", "[", "m00", "]", "+", "m", ".", "Val", "[", "m01", "]", "*", "v", "[", "m10", "]", "+", "m", ".", "Val", "[", "m02", "]", "*", "v", "[", "m20", "]", "\n", "v10", ":=", "m", ".", "Val", "[", "m10", "]", "*", "v", "[", "m00", "]", "+", "m", ".", "Val", "[", "m11", "]", "*", "v", "[", "m10", "]", "+", "m", ".", "Val", "[", "m12", "]", "*", "v", "[", "m20", "]", "\n", "v20", ":=", "m", ".", "Val", "[", "m20", "]", "*", "v", "[", "m00", "]", "+", "m", ".", "Val", "[", "m21", "]", "*", "v", "[", "m10", "]", "+", "m", ".", "Val", "[", "m22", "]", "*", "v", "[", "m20", "]", "\n", "return", "[", "]", "float32", "{", "v00", ",", "v10", ",", "v20", "}", "\n", "}" ]
// MultiplyMatrixVector multiplies the matrix m with the float32 vector v and returns the result. // The size of vector v MUST be 2 or 3. If v is size 2, a 3rd component is automatically added with // value of 1.0.
[ "MultiplyMatrixVector", "multiplies", "the", "matrix", "m", "with", "the", "float32", "vector", "v", "and", "returns", "the", "result", ".", "The", "size", "of", "vector", "v", "MUST", "be", "2", "or", "3", ".", "If", "v", "is", "size", "2", "a", "3rd", "component", "is", "automatically", "added", "with", "value", "of", "1", ".", "0", "." ]
6f88a7379a25d81e976cf6e86ea3617f3b480b1a
https://github.com/EngoEngine/engo/blob/6f88a7379a25d81e976cf6e86ea3617f3b480b1a/math.go#L525-L533
12,686
EngoEngine/engo
math.go
MultiplyMatrixVector
func (p *Point) MultiplyMatrixVector(m *Matrix) *Point { x := m.Val[m00]*p.X + m.Val[m01]*p.Y + m.Val[m02] y := m.Val[m10]*p.X + m.Val[m11]*p.Y + m.Val[m12] p.X, p.Y = x, y return p }
go
func (p *Point) MultiplyMatrixVector(m *Matrix) *Point { x := m.Val[m00]*p.X + m.Val[m01]*p.Y + m.Val[m02] y := m.Val[m10]*p.X + m.Val[m11]*p.Y + m.Val[m12] p.X, p.Y = x, y return p }
[ "func", "(", "p", "*", "Point", ")", "MultiplyMatrixVector", "(", "m", "*", "Matrix", ")", "*", "Point", "{", "x", ":=", "m", ".", "Val", "[", "m00", "]", "*", "p", ".", "X", "+", "m", ".", "Val", "[", "m01", "]", "*", "p", ".", "Y", "+", "m", ".", "Val", "[", "m02", "]", "\n", "y", ":=", "m", ".", "Val", "[", "m10", "]", "*", "p", ".", "X", "+", "m", ".", "Val", "[", "m11", "]", "*", "p", ".", "Y", "+", "m", ".", "Val", "[", "m12", "]", "\n", "p", ".", "X", ",", "p", ".", "Y", "=", "x", ",", "y", "\n", "return", "p", "\n", "}" ]
// MultiplyMatrixVector multiplies the matrix m with the point and returns the result.
[ "MultiplyMatrixVector", "multiplies", "the", "matrix", "m", "with", "the", "point", "and", "returns", "the", "result", "." ]
6f88a7379a25d81e976cf6e86ea3617f3b480b1a
https://github.com/EngoEngine/engo/blob/6f88a7379a25d81e976cf6e86ea3617f3b480b1a/math.go#L536-L541
12,687
EngoEngine/engo
common/render_filetype.go
UploadTexture
func UploadTexture(img Image) *gl.Texture { var id *gl.Texture if !engo.Headless() { id = engo.Gl.CreateTexture() engo.Gl.BindTexture(engo.Gl.TEXTURE_2D, id) engo.Gl.TexParameteri(engo.Gl.TEXTURE_2D, engo.Gl.TEXTURE_WRAP_S, engo.Gl.CLAMP_TO_EDGE) engo.Gl.TexParameteri(engo.Gl.TEXTURE_2D, engo.Gl.TEXTURE_WRAP_T, engo.Gl.CLAMP_TO_EDGE) engo.Gl.TexParameteri(engo.Gl.TEXTURE_2D, engo.Gl.TEXTURE_MIN_FILTER, engo.Gl.LINEAR) engo.Gl.TexParameteri(engo.Gl.TEXTURE_2D, engo.Gl.TEXTURE_MAG_FILTER, engo.Gl.NEAREST) if img.Data() == nil { panic("Texture image data is nil.") } engo.Gl.TexImage2D(engo.Gl.TEXTURE_2D, 0, engo.Gl.RGBA, engo.Gl.RGBA, engo.Gl.UNSIGNED_BYTE, img.Data()) } return id }
go
func UploadTexture(img Image) *gl.Texture { var id *gl.Texture if !engo.Headless() { id = engo.Gl.CreateTexture() engo.Gl.BindTexture(engo.Gl.TEXTURE_2D, id) engo.Gl.TexParameteri(engo.Gl.TEXTURE_2D, engo.Gl.TEXTURE_WRAP_S, engo.Gl.CLAMP_TO_EDGE) engo.Gl.TexParameteri(engo.Gl.TEXTURE_2D, engo.Gl.TEXTURE_WRAP_T, engo.Gl.CLAMP_TO_EDGE) engo.Gl.TexParameteri(engo.Gl.TEXTURE_2D, engo.Gl.TEXTURE_MIN_FILTER, engo.Gl.LINEAR) engo.Gl.TexParameteri(engo.Gl.TEXTURE_2D, engo.Gl.TEXTURE_MAG_FILTER, engo.Gl.NEAREST) if img.Data() == nil { panic("Texture image data is nil.") } engo.Gl.TexImage2D(engo.Gl.TEXTURE_2D, 0, engo.Gl.RGBA, engo.Gl.RGBA, engo.Gl.UNSIGNED_BYTE, img.Data()) } return id }
[ "func", "UploadTexture", "(", "img", "Image", ")", "*", "gl", ".", "Texture", "{", "var", "id", "*", "gl", ".", "Texture", "\n", "if", "!", "engo", ".", "Headless", "(", ")", "{", "id", "=", "engo", ".", "Gl", ".", "CreateTexture", "(", ")", "\n\n", "engo", ".", "Gl", ".", "BindTexture", "(", "engo", ".", "Gl", ".", "TEXTURE_2D", ",", "id", ")", "\n\n", "engo", ".", "Gl", ".", "TexParameteri", "(", "engo", ".", "Gl", ".", "TEXTURE_2D", ",", "engo", ".", "Gl", ".", "TEXTURE_WRAP_S", ",", "engo", ".", "Gl", ".", "CLAMP_TO_EDGE", ")", "\n", "engo", ".", "Gl", ".", "TexParameteri", "(", "engo", ".", "Gl", ".", "TEXTURE_2D", ",", "engo", ".", "Gl", ".", "TEXTURE_WRAP_T", ",", "engo", ".", "Gl", ".", "CLAMP_TO_EDGE", ")", "\n", "engo", ".", "Gl", ".", "TexParameteri", "(", "engo", ".", "Gl", ".", "TEXTURE_2D", ",", "engo", ".", "Gl", ".", "TEXTURE_MIN_FILTER", ",", "engo", ".", "Gl", ".", "LINEAR", ")", "\n", "engo", ".", "Gl", ".", "TexParameteri", "(", "engo", ".", "Gl", ".", "TEXTURE_2D", ",", "engo", ".", "Gl", ".", "TEXTURE_MAG_FILTER", ",", "engo", ".", "Gl", ".", "NEAREST", ")", "\n\n", "if", "img", ".", "Data", "(", ")", "==", "nil", "{", "panic", "(", "\"", "\"", ")", "\n", "}", "\n\n", "engo", ".", "Gl", ".", "TexImage2D", "(", "engo", ".", "Gl", ".", "TEXTURE_2D", ",", "0", ",", "engo", ".", "Gl", ".", "RGBA", ",", "engo", ".", "Gl", ".", "RGBA", ",", "engo", ".", "Gl", ".", "UNSIGNED_BYTE", ",", "img", ".", "Data", "(", ")", ")", "\n", "}", "\n", "return", "id", "\n", "}" ]
// UploadTexture sends the image to the GPU, to be kept in GPU RAM
[ "UploadTexture", "sends", "the", "image", "to", "the", "GPU", "to", "be", "kept", "in", "GPU", "RAM" ]
6f88a7379a25d81e976cf6e86ea3617f3b480b1a
https://github.com/EngoEngine/engo/blob/6f88a7379a25d81e976cf6e86ea3617f3b480b1a/common/render_filetype.go#L92-L111
12,688
EngoEngine/engo
common/render_filetype.go
NewTextureResource
func NewTextureResource(img Image) TextureResource { id := UploadTexture(img) return TextureResource{Texture: id, Width: float32(img.Width()), Height: float32(img.Height())} }
go
func NewTextureResource(img Image) TextureResource { id := UploadTexture(img) return TextureResource{Texture: id, Width: float32(img.Width()), Height: float32(img.Height())} }
[ "func", "NewTextureResource", "(", "img", "Image", ")", "TextureResource", "{", "id", ":=", "UploadTexture", "(", "img", ")", "\n", "return", "TextureResource", "{", "Texture", ":", "id", ",", "Width", ":", "float32", "(", "img", ".", "Width", "(", ")", ")", ",", "Height", ":", "float32", "(", "img", ".", "Height", "(", ")", ")", "}", "\n", "}" ]
// NewTextureResource sends the image to the GPU and returns a `TextureResource` for easy access
[ "NewTextureResource", "sends", "the", "image", "to", "the", "GPU", "and", "returns", "a", "TextureResource", "for", "easy", "access" ]
6f88a7379a25d81e976cf6e86ea3617f3b480b1a
https://github.com/EngoEngine/engo/blob/6f88a7379a25d81e976cf6e86ea3617f3b480b1a/common/render_filetype.go#L114-L117
12,689
EngoEngine/engo
common/render_filetype.go
NewTextureSingle
func NewTextureSingle(img Image) Texture { id := UploadTexture(img) return Texture{id, float32(img.Width()), float32(img.Height()), engo.AABB{Max: engo.Point{X: 1.0, Y: 1.0}}} }
go
func NewTextureSingle(img Image) Texture { id := UploadTexture(img) return Texture{id, float32(img.Width()), float32(img.Height()), engo.AABB{Max: engo.Point{X: 1.0, Y: 1.0}}} }
[ "func", "NewTextureSingle", "(", "img", "Image", ")", "Texture", "{", "id", ":=", "UploadTexture", "(", "img", ")", "\n", "return", "Texture", "{", "id", ",", "float32", "(", "img", ".", "Width", "(", ")", ")", ",", "float32", "(", "img", ".", "Height", "(", ")", ")", ",", "engo", ".", "AABB", "{", "Max", ":", "engo", ".", "Point", "{", "X", ":", "1.0", ",", "Y", ":", "1.0", "}", "}", "}", "\n", "}" ]
// NewTextureSingle sends the image to the GPU and returns a `Texture` with a viewport for single-sprite images
[ "NewTextureSingle", "sends", "the", "image", "to", "the", "GPU", "and", "returns", "a", "Texture", "with", "a", "viewport", "for", "single", "-", "sprite", "images" ]
6f88a7379a25d81e976cf6e86ea3617f3b480b1a
https://github.com/EngoEngine/engo/blob/6f88a7379a25d81e976cf6e86ea3617f3b480b1a/common/render_filetype.go#L120-L123
12,690
EngoEngine/engo
common/render_filetype.go
ImageToNRGBA
func ImageToNRGBA(img image.Image, width, height int) *image.NRGBA { newm := image.NewNRGBA(image.Rect(0, 0, width, height)) draw.Draw(newm, newm.Bounds(), img, image.Point{0, 0}, draw.Src) return newm }
go
func ImageToNRGBA(img image.Image, width, height int) *image.NRGBA { newm := image.NewNRGBA(image.Rect(0, 0, width, height)) draw.Draw(newm, newm.Bounds(), img, image.Point{0, 0}, draw.Src) return newm }
[ "func", "ImageToNRGBA", "(", "img", "image", ".", "Image", ",", "width", ",", "height", "int", ")", "*", "image", ".", "NRGBA", "{", "newm", ":=", "image", ".", "NewNRGBA", "(", "image", ".", "Rect", "(", "0", ",", "0", ",", "width", ",", "height", ")", ")", "\n", "draw", ".", "Draw", "(", "newm", ",", "newm", ".", "Bounds", "(", ")", ",", "img", ",", "image", ".", "Point", "{", "0", ",", "0", "}", ",", "draw", ".", "Src", ")", "\n\n", "return", "newm", "\n", "}" ]
// ImageToNRGBA takes a given `image.Image` and converts it into an `image.NRGBA`. Especially useful when transforming // image.Uniform to something usable by `engo`.
[ "ImageToNRGBA", "takes", "a", "given", "image", ".", "Image", "and", "converts", "it", "into", "an", "image", ".", "NRGBA", ".", "Especially", "useful", "when", "transforming", "image", ".", "Uniform", "to", "something", "usable", "by", "engo", "." ]
6f88a7379a25d81e976cf6e86ea3617f3b480b1a
https://github.com/EngoEngine/engo/blob/6f88a7379a25d81e976cf6e86ea3617f3b480b1a/common/render_filetype.go#L127-L132
12,691
EngoEngine/engo
common/render_filetype.go
Close
func (t Texture) Close() { if !engo.Headless() { engo.Gl.DeleteTexture(t.id) } }
go
func (t Texture) Close() { if !engo.Headless() { engo.Gl.DeleteTexture(t.id) } }
[ "func", "(", "t", "Texture", ")", "Close", "(", ")", "{", "if", "!", "engo", ".", "Headless", "(", ")", "{", "engo", ".", "Gl", ".", "DeleteTexture", "(", "t", ".", "id", ")", "\n", "}", "\n", "}" ]
// Close removes the Texture data from the GPU.
[ "Close", "removes", "the", "Texture", "data", "from", "the", "GPU", "." ]
6f88a7379a25d81e976cf6e86ea3617f3b480b1a
https://github.com/EngoEngine/engo/blob/6f88a7379a25d81e976cf6e86ea3617f3b480b1a/common/render_filetype.go#L204-L208
12,692
EngoEngine/engo
common/internal/decode/vorbis/decode.go
decode
func decode(in convert.ReadSeekCloser) (*decoded, int, int, error) { r, err := oggvorbis.NewReader(in) if err != nil { return nil, 0, 0, err } d := &decoded{ data: make([]float32, r.Length()*2), totalBytes: int(r.Length()) * 4, // TODO: What if length is 0? posInBytes: 0, source: in, decoder: r, } runtime.SetFinalizer(d, (*decoded).Close) if _, err := d.Read(make([]uint8, 65536)); err != nil { return nil, 0, 0, err } if _, err := d.Seek(0, io.SeekStart); err != nil { return nil, 0, 0, err } return d, r.Channels(), r.SampleRate(), nil }
go
func decode(in convert.ReadSeekCloser) (*decoded, int, int, error) { r, err := oggvorbis.NewReader(in) if err != nil { return nil, 0, 0, err } d := &decoded{ data: make([]float32, r.Length()*2), totalBytes: int(r.Length()) * 4, // TODO: What if length is 0? posInBytes: 0, source: in, decoder: r, } runtime.SetFinalizer(d, (*decoded).Close) if _, err := d.Read(make([]uint8, 65536)); err != nil { return nil, 0, 0, err } if _, err := d.Seek(0, io.SeekStart); err != nil { return nil, 0, 0, err } return d, r.Channels(), r.SampleRate(), nil }
[ "func", "decode", "(", "in", "convert", ".", "ReadSeekCloser", ")", "(", "*", "decoded", ",", "int", ",", "int", ",", "error", ")", "{", "r", ",", "err", ":=", "oggvorbis", ".", "NewReader", "(", "in", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "0", ",", "0", ",", "err", "\n", "}", "\n", "d", ":=", "&", "decoded", "{", "data", ":", "make", "(", "[", "]", "float32", ",", "r", ".", "Length", "(", ")", "*", "2", ")", ",", "totalBytes", ":", "int", "(", "r", ".", "Length", "(", ")", ")", "*", "4", ",", "// TODO: What if length is 0?", "posInBytes", ":", "0", ",", "source", ":", "in", ",", "decoder", ":", "r", ",", "}", "\n", "runtime", ".", "SetFinalizer", "(", "d", ",", "(", "*", "decoded", ")", ".", "Close", ")", "\n", "if", "_", ",", "err", ":=", "d", ".", "Read", "(", "make", "(", "[", "]", "uint8", ",", "65536", ")", ")", ";", "err", "!=", "nil", "{", "return", "nil", ",", "0", ",", "0", ",", "err", "\n", "}", "\n", "if", "_", ",", "err", ":=", "d", ".", "Seek", "(", "0", ",", "io", ".", "SeekStart", ")", ";", "err", "!=", "nil", "{", "return", "nil", ",", "0", ",", "0", ",", "err", "\n", "}", "\n", "return", "d", ",", "r", ".", "Channels", "(", ")", ",", "r", ".", "SampleRate", "(", ")", ",", "nil", "\n", "}" ]
// decode accepts an ogg stream and returns a decorded stream.
[ "decode", "accepts", "an", "ogg", "stream", "and", "returns", "a", "decorded", "stream", "." ]
6f88a7379a25d81e976cf6e86ea3617f3b480b1a
https://github.com/EngoEngine/engo/blob/6f88a7379a25d81e976cf6e86ea3617f3b480b1a/common/internal/decode/vorbis/decode.go#L140-L160
12,693
EngoEngine/engo
axis.go
Value
func (a Axis) Value() float32 { for _, pair := range a.Pairs { v := pair.Value() if v != AxisNeutral { return v } } return AxisNeutral }
go
func (a Axis) Value() float32 { for _, pair := range a.Pairs { v := pair.Value() if v != AxisNeutral { return v } } return AxisNeutral }
[ "func", "(", "a", "Axis", ")", "Value", "(", ")", "float32", "{", "for", "_", ",", "pair", ":=", "range", "a", ".", "Pairs", "{", "v", ":=", "pair", ".", "Value", "(", ")", "\n", "if", "v", "!=", "AxisNeutral", "{", "return", "v", "\n", "}", "\n", "}", "\n\n", "return", "AxisNeutral", "\n", "}" ]
// Value returns the value of an Axis.
[ "Value", "returns", "the", "value", "of", "an", "Axis", "." ]
6f88a7379a25d81e976cf6e86ea3617f3b480b1a
https://github.com/EngoEngine/engo/blob/6f88a7379a25d81e976cf6e86ea3617f3b480b1a/axis.go#L12-L21
12,694
EngoEngine/engo
axis.go
Value
func (keys AxisKeyPair) Value() float32 { if Input.keys.Get(keys.Max).Down() { return AxisMax } else if Input.keys.Get(keys.Min).Down() { return AxisMin } return AxisNeutral }
go
func (keys AxisKeyPair) Value() float32 { if Input.keys.Get(keys.Max).Down() { return AxisMax } else if Input.keys.Get(keys.Min).Down() { return AxisMin } return AxisNeutral }
[ "func", "(", "keys", "AxisKeyPair", ")", "Value", "(", ")", "float32", "{", "if", "Input", ".", "keys", ".", "Get", "(", "keys", ".", "Max", ")", ".", "Down", "(", ")", "{", "return", "AxisMax", "\n", "}", "else", "if", "Input", ".", "keys", ".", "Get", "(", "keys", ".", "Min", ")", ".", "Down", "(", ")", "{", "return", "AxisMin", "\n", "}", "\n\n", "return", "AxisNeutral", "\n", "}" ]
// Value returns the value of a keypress.
[ "Value", "returns", "the", "value", "of", "a", "keypress", "." ]
6f88a7379a25d81e976cf6e86ea3617f3b480b1a
https://github.com/EngoEngine/engo/blob/6f88a7379a25d81e976cf6e86ea3617f3b480b1a/axis.go#L35-L43
12,695
EngoEngine/engo
axis.go
NewAxisMouse
func NewAxisMouse(d AxisMouseDirection) *AxisMouse { old := Input.Mouse.Y if d == AxisMouseHori { old = Input.Mouse.X } return &AxisMouse{ direction: d, old: old, } }
go
func NewAxisMouse(d AxisMouseDirection) *AxisMouse { old := Input.Mouse.Y if d == AxisMouseHori { old = Input.Mouse.X } return &AxisMouse{ direction: d, old: old, } }
[ "func", "NewAxisMouse", "(", "d", "AxisMouseDirection", ")", "*", "AxisMouse", "{", "old", ":=", "Input", ".", "Mouse", ".", "Y", "\n", "if", "d", "==", "AxisMouseHori", "{", "old", "=", "Input", ".", "Mouse", ".", "X", "\n", "}", "\n\n", "return", "&", "AxisMouse", "{", "direction", ":", "d", ",", "old", ":", "old", ",", "}", "\n", "}" ]
// NewAxisMouse creates a new Mouse Axis in either direction AxisMouseVert or AxisMouseHori.
[ "NewAxisMouse", "creates", "a", "new", "Mouse", "Axis", "in", "either", "direction", "AxisMouseVert", "or", "AxisMouseHori", "." ]
6f88a7379a25d81e976cf6e86ea3617f3b480b1a
https://github.com/EngoEngine/engo/blob/6f88a7379a25d81e976cf6e86ea3617f3b480b1a/axis.go#L66-L76
12,696
EngoEngine/engo
axis.go
Value
func (am *AxisMouse) Value() float32 { var diff float32 if am.direction == AxisMouseHori { diff = (Input.Mouse.X - am.old + (ResizeXOffset / (2 * GetGlobalScale().X * CanvasScale()))) am.old = (Input.Mouse.X + (ResizeXOffset / (2 * GetGlobalScale().X * CanvasScale()))) } else { diff = (Input.Mouse.Y - am.old + (ResizeYOffset / (2 * GetGlobalScale().Y * CanvasScale()))) am.old = (Input.Mouse.Y + (ResizeYOffset / (2 * GetGlobalScale().Y * CanvasScale()))) } return diff }
go
func (am *AxisMouse) Value() float32 { var diff float32 if am.direction == AxisMouseHori { diff = (Input.Mouse.X - am.old + (ResizeXOffset / (2 * GetGlobalScale().X * CanvasScale()))) am.old = (Input.Mouse.X + (ResizeXOffset / (2 * GetGlobalScale().X * CanvasScale()))) } else { diff = (Input.Mouse.Y - am.old + (ResizeYOffset / (2 * GetGlobalScale().Y * CanvasScale()))) am.old = (Input.Mouse.Y + (ResizeYOffset / (2 * GetGlobalScale().Y * CanvasScale()))) } return diff }
[ "func", "(", "am", "*", "AxisMouse", ")", "Value", "(", ")", "float32", "{", "var", "diff", "float32", "\n\n", "if", "am", ".", "direction", "==", "AxisMouseHori", "{", "diff", "=", "(", "Input", ".", "Mouse", ".", "X", "-", "am", ".", "old", "+", "(", "ResizeXOffset", "/", "(", "2", "*", "GetGlobalScale", "(", ")", ".", "X", "*", "CanvasScale", "(", ")", ")", ")", ")", "\n", "am", ".", "old", "=", "(", "Input", ".", "Mouse", ".", "X", "+", "(", "ResizeXOffset", "/", "(", "2", "*", "GetGlobalScale", "(", ")", ".", "X", "*", "CanvasScale", "(", ")", ")", ")", ")", "\n", "}", "else", "{", "diff", "=", "(", "Input", ".", "Mouse", ".", "Y", "-", "am", ".", "old", "+", "(", "ResizeYOffset", "/", "(", "2", "*", "GetGlobalScale", "(", ")", ".", "Y", "*", "CanvasScale", "(", ")", ")", ")", ")", "\n", "am", ".", "old", "=", "(", "Input", ".", "Mouse", ".", "Y", "+", "(", "ResizeYOffset", "/", "(", "2", "*", "GetGlobalScale", "(", ")", ".", "Y", "*", "CanvasScale", "(", ")", ")", ")", ")", "\n", "}", "\n\n", "return", "diff", "\n", "}" ]
// Value returns the delta of a mouse movement.
[ "Value", "returns", "the", "delta", "of", "a", "mouse", "movement", "." ]
6f88a7379a25d81e976cf6e86ea3617f3b480b1a
https://github.com/EngoEngine/engo/blob/6f88a7379a25d81e976cf6e86ea3617f3b480b1a/axis.go#L79-L91
12,697
EngoEngine/engo
demos/demoutils/utils.go
NewBackground
func NewBackground(world *ecs.World, width, height int, colorA, colorB color.Color) *Background { rect := image.Rect(0, 0, width, height) img := image.NewNRGBA(rect) for i := rect.Min.X; i < rect.Max.X; i++ { for j := rect.Min.Y; j < rect.Max.Y; j++ { if i%40 > 20 { if j%40 > 20 { img.Set(i, j, colorA) } else { img.Set(i, j, colorB) } } else { if j%40 > 20 { img.Set(i, j, colorB) } else { img.Set(i, j, colorA) } } } } bgTexture := common.NewImageObject(img) bg := &Background{BasicEntity: ecs.NewBasic()} bg.RenderComponent = common.RenderComponent{Drawable: common.NewTextureSingle(bgTexture)} bg.SpaceComponent = common.SpaceComponent{ Position: engo.Point{0, 0}, Width: float32(width), Height: float32(height), } for _, system := range world.Systems() { switch sys := system.(type) { case *common.RenderSystem: sys.Add(&bg.BasicEntity, &bg.RenderComponent, &bg.SpaceComponent) } } return bg }
go
func NewBackground(world *ecs.World, width, height int, colorA, colorB color.Color) *Background { rect := image.Rect(0, 0, width, height) img := image.NewNRGBA(rect) for i := rect.Min.X; i < rect.Max.X; i++ { for j := rect.Min.Y; j < rect.Max.Y; j++ { if i%40 > 20 { if j%40 > 20 { img.Set(i, j, colorA) } else { img.Set(i, j, colorB) } } else { if j%40 > 20 { img.Set(i, j, colorB) } else { img.Set(i, j, colorA) } } } } bgTexture := common.NewImageObject(img) bg := &Background{BasicEntity: ecs.NewBasic()} bg.RenderComponent = common.RenderComponent{Drawable: common.NewTextureSingle(bgTexture)} bg.SpaceComponent = common.SpaceComponent{ Position: engo.Point{0, 0}, Width: float32(width), Height: float32(height), } for _, system := range world.Systems() { switch sys := system.(type) { case *common.RenderSystem: sys.Add(&bg.BasicEntity, &bg.RenderComponent, &bg.SpaceComponent) } } return bg }
[ "func", "NewBackground", "(", "world", "*", "ecs", ".", "World", ",", "width", ",", "height", "int", ",", "colorA", ",", "colorB", "color", ".", "Color", ")", "*", "Background", "{", "rect", ":=", "image", ".", "Rect", "(", "0", ",", "0", ",", "width", ",", "height", ")", "\n\n", "img", ":=", "image", ".", "NewNRGBA", "(", "rect", ")", "\n", "for", "i", ":=", "rect", ".", "Min", ".", "X", ";", "i", "<", "rect", ".", "Max", ".", "X", ";", "i", "++", "{", "for", "j", ":=", "rect", ".", "Min", ".", "Y", ";", "j", "<", "rect", ".", "Max", ".", "Y", ";", "j", "++", "{", "if", "i", "%", "40", ">", "20", "{", "if", "j", "%", "40", ">", "20", "{", "img", ".", "Set", "(", "i", ",", "j", ",", "colorA", ")", "\n", "}", "else", "{", "img", ".", "Set", "(", "i", ",", "j", ",", "colorB", ")", "\n", "}", "\n", "}", "else", "{", "if", "j", "%", "40", ">", "20", "{", "img", ".", "Set", "(", "i", ",", "j", ",", "colorB", ")", "\n", "}", "else", "{", "img", ".", "Set", "(", "i", ",", "j", ",", "colorA", ")", "\n", "}", "\n", "}", "\n", "}", "\n", "}", "\n\n", "bgTexture", ":=", "common", ".", "NewImageObject", "(", "img", ")", "\n\n", "bg", ":=", "&", "Background", "{", "BasicEntity", ":", "ecs", ".", "NewBasic", "(", ")", "}", "\n", "bg", ".", "RenderComponent", "=", "common", ".", "RenderComponent", "{", "Drawable", ":", "common", ".", "NewTextureSingle", "(", "bgTexture", ")", "}", "\n", "bg", ".", "SpaceComponent", "=", "common", ".", "SpaceComponent", "{", "Position", ":", "engo", ".", "Point", "{", "0", ",", "0", "}", ",", "Width", ":", "float32", "(", "width", ")", ",", "Height", ":", "float32", "(", "height", ")", ",", "}", "\n\n", "for", "_", ",", "system", ":=", "range", "world", ".", "Systems", "(", ")", "{", "switch", "sys", ":=", "system", ".", "(", "type", ")", "{", "case", "*", "common", ".", "RenderSystem", ":", "sys", ".", "Add", "(", "&", "bg", ".", "BasicEntity", ",", "&", "bg", ".", "RenderComponent", ",", "&", "bg", ".", "SpaceComponent", ")", "\n", "}", "\n", "}", "\n\n", "return", "bg", "\n", "}" ]
// NewBackground creates a background of colored tiles - might not be the most efficient way to do this // It gets added to the world as well, so we won't return anything.
[ "NewBackground", "creates", "a", "background", "of", "colored", "tiles", "-", "might", "not", "be", "the", "most", "efficient", "way", "to", "do", "this", "It", "gets", "added", "to", "the", "world", "as", "well", "so", "we", "won", "t", "return", "anything", "." ]
6f88a7379a25d81e976cf6e86ea3617f3b480b1a
https://github.com/EngoEngine/engo/blob/6f88a7379a25d81e976cf6e86ea3617f3b480b1a/demos/demoutils/utils.go#L22-L62
12,698
EngoEngine/engo
engo_mobile.go
openFile
func openFile(url string) (io.ReadCloser, error) { usedUrl := url if strings.HasPrefix(url, "assets/") { usedUrl = usedUrl[7:] } return asset.Open(usedUrl) }
go
func openFile(url string) (io.ReadCloser, error) { usedUrl := url if strings.HasPrefix(url, "assets/") { usedUrl = usedUrl[7:] } return asset.Open(usedUrl) }
[ "func", "openFile", "(", "url", "string", ")", "(", "io", ".", "ReadCloser", ",", "error", ")", "{", "usedUrl", ":=", "url", "\n", "if", "strings", ".", "HasPrefix", "(", "url", ",", "\"", "\"", ")", "{", "usedUrl", "=", "usedUrl", "[", "7", ":", "]", "\n", "}", "\n\n", "return", "asset", ".", "Open", "(", "usedUrl", ")", "\n", "}" ]
// openFile is the mobile-specific way of opening a file
[ "openFile", "is", "the", "mobile", "-", "specific", "way", "of", "opening", "a", "file" ]
6f88a7379a25d81e976cf6e86ea3617f3b480b1a
https://github.com/EngoEngine/engo/blob/6f88a7379a25d81e976cf6e86ea3617f3b480b1a/engo_mobile.go#L202-L209
12,699
EngoEngine/engo
engo_mobile_bind.go
RunPreparation
func RunPreparation(defaultScene Scene) { windowWidth = float32(opts.MobileWidth) canvasWidth = float32(opts.MobileWidth) windowHeight = float32(opts.MobileHeight) canvasHeight = float32(opts.MobileHeight) ResizeXOffset = gameWidth - canvasWidth ResizeYOffset = gameHeight - canvasHeight Gl.Viewport(0, 0, opts.MobileWidth, opts.MobileHeight) Time = NewClock() SetScene(defaultScene, false) }
go
func RunPreparation(defaultScene Scene) { windowWidth = float32(opts.MobileWidth) canvasWidth = float32(opts.MobileWidth) windowHeight = float32(opts.MobileHeight) canvasHeight = float32(opts.MobileHeight) ResizeXOffset = gameWidth - canvasWidth ResizeYOffset = gameHeight - canvasHeight Gl.Viewport(0, 0, opts.MobileWidth, opts.MobileHeight) Time = NewClock() SetScene(defaultScene, false) }
[ "func", "RunPreparation", "(", "defaultScene", "Scene", ")", "{", "windowWidth", "=", "float32", "(", "opts", ".", "MobileWidth", ")", "\n", "canvasWidth", "=", "float32", "(", "opts", ".", "MobileWidth", ")", "\n", "windowHeight", "=", "float32", "(", "opts", ".", "MobileHeight", ")", "\n", "canvasHeight", "=", "float32", "(", "opts", ".", "MobileHeight", ")", "\n", "ResizeXOffset", "=", "gameWidth", "-", "canvasWidth", "\n", "ResizeYOffset", "=", "gameHeight", "-", "canvasHeight", "\n\n", "Gl", ".", "Viewport", "(", "0", ",", "0", ",", "opts", ".", "MobileWidth", ",", "opts", ".", "MobileHeight", ")", "\n\n", "Time", "=", "NewClock", "(", ")", "\n", "SetScene", "(", "defaultScene", ",", "false", ")", "\n", "}" ]
// RunPreparation is called only once, and is called automatically when calling Open // It is only here for benchmarking in combination with OpenHeadlessNoRun
[ "RunPreparation", "is", "called", "only", "once", "and", "is", "called", "automatically", "when", "calling", "Open", "It", "is", "only", "here", "for", "benchmarking", "in", "combination", "with", "OpenHeadlessNoRun" ]
6f88a7379a25d81e976cf6e86ea3617f3b480b1a
https://github.com/EngoEngine/engo/blob/6f88a7379a25d81e976cf6e86ea3617f3b480b1a/engo_mobile_bind.go#L86-L98