mirror of
https://github.com/vlang/v.git
synced 2025-09-14 06:52:36 +03:00
fmt: fix alignment of struct init fields (#22025)
This commit is contained in:
parent
99da5726db
commit
c51d30bf53
671 changed files with 18817 additions and 18787 deletions
|
@ -133,7 +133,7 @@ fn new_gen_vc(flag_options FlagOptions) &GenVC {
|
||||||
}
|
}
|
||||||
return &GenVC{
|
return &GenVC{
|
||||||
options: flag_options
|
options: flag_options
|
||||||
logger: logger
|
logger: logger
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -171,14 +171,14 @@ pub fn (ws &WebhookServer) reset() {
|
||||||
// parse flags to FlagOptions struct
|
// parse flags to FlagOptions struct
|
||||||
fn parse_flags(mut fp flag.FlagParser) FlagOptions {
|
fn parse_flags(mut fp flag.FlagParser) FlagOptions {
|
||||||
return FlagOptions{
|
return FlagOptions{
|
||||||
serve: fp.bool('serve', 0, false, 'run in webhook server mode')
|
serve: fp.bool('serve', 0, false, 'run in webhook server mode')
|
||||||
work_dir: fp.string('work-dir', 0, work_dir, 'gen_vc working directory')
|
work_dir: fp.string('work-dir', 0, work_dir, 'gen_vc working directory')
|
||||||
purge: fp.bool('purge', 0, false, 'force purge the local repositories')
|
purge: fp.bool('purge', 0, false, 'force purge the local repositories')
|
||||||
port: fp.int('port', 0, server_port, 'port for web server to listen on')
|
port: fp.int('port', 0, server_port, 'port for web server to listen on')
|
||||||
log_to: fp.string('log-to', 0, log_to, "log to is 'file' or 'terminal'")
|
log_to: fp.string('log-to', 0, log_to, "log to is 'file' or 'terminal'")
|
||||||
log_file: fp.string('log-file', 0, log_file, "log file to use when log-to is 'file'")
|
log_file: fp.string('log-file', 0, log_file, "log file to use when log-to is 'file'")
|
||||||
dry_run: fp.bool('dry-run', 0, dry_run, 'when specified dont push anything to remote repo')
|
dry_run: fp.bool('dry-run', 0, dry_run, 'when specified dont push anything to remote repo')
|
||||||
force: fp.bool('force', 0, false, 'force update even if already up to date')
|
force: fp.bool('force', 0, false, 'force update even if already up to date')
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -84,13 +84,13 @@ fn process_files(files []string) ! {
|
||||||
fn new_parser(path string, comments_mode scanner.CommentsMode, table &ast.Table, pref_ &pref.Preferences) &parser.Parser {
|
fn new_parser(path string, comments_mode scanner.CommentsMode, table &ast.Table, pref_ &pref.Preferences) &parser.Parser {
|
||||||
mut p := &parser.Parser{
|
mut p := &parser.Parser{
|
||||||
scanner: scanner.new_scanner_file(path, comments_mode, pref_) or { panic(err) }
|
scanner: scanner.new_scanner_file(path, comments_mode, pref_) or { panic(err) }
|
||||||
table: table
|
table: table
|
||||||
pref: pref_
|
pref: pref_
|
||||||
scope: &ast.Scope{
|
scope: &ast.Scope{
|
||||||
start_pos: 0
|
start_pos: 0
|
||||||
parent: table.global_scope
|
parent: table.global_scope
|
||||||
}
|
}
|
||||||
errors: []errors.Error{}
|
errors: []errors.Error{}
|
||||||
warnings: []errors.Warning{}
|
warnings: []errors.Warning{}
|
||||||
}
|
}
|
||||||
p.set_path(path)
|
p.set_path(path)
|
||||||
|
|
|
@ -79,13 +79,13 @@ fn process_files(files []string) ! {
|
||||||
fn new_parser(path string, comments_mode scanner.CommentsMode, table &ast.Table, pref_ &pref.Preferences) &parser.Parser {
|
fn new_parser(path string, comments_mode scanner.CommentsMode, table &ast.Table, pref_ &pref.Preferences) &parser.Parser {
|
||||||
mut p := &parser.Parser{
|
mut p := &parser.Parser{
|
||||||
scanner: scanner.new_scanner_file(path, comments_mode, pref_) or { panic(err) }
|
scanner: scanner.new_scanner_file(path, comments_mode, pref_) or { panic(err) }
|
||||||
table: table
|
table: table
|
||||||
pref: pref_
|
pref: pref_
|
||||||
scope: &ast.Scope{
|
scope: &ast.Scope{
|
||||||
start_pos: 0
|
start_pos: 0
|
||||||
parent: table.global_scope
|
parent: table.global_scope
|
||||||
}
|
}
|
||||||
errors: []errors.Error{}
|
errors: []errors.Error{}
|
||||||
warnings: []errors.Warning{}
|
warnings: []errors.Warning{}
|
||||||
}
|
}
|
||||||
p.set_path(path)
|
p.set_path(path)
|
||||||
|
|
|
@ -117,22 +117,22 @@ mut:
|
||||||
|
|
||||||
fn (mut ts TestSession) append_message(kind MessageKind, msg string, mtc MessageThreadContext) {
|
fn (mut ts TestSession) append_message(kind MessageKind, msg string, mtc MessageThreadContext) {
|
||||||
ts.nmessages <- LogMessage{
|
ts.nmessages <- LogMessage{
|
||||||
file: mtc.file
|
file: mtc.file
|
||||||
flow_id: mtc.flow_id
|
flow_id: mtc.flow_id
|
||||||
message: msg
|
message: msg
|
||||||
kind: kind
|
kind: kind
|
||||||
when: time.now()
|
when: time.now()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn (mut ts TestSession) append_message_with_duration(kind MessageKind, msg string, d time.Duration, mtc MessageThreadContext) {
|
fn (mut ts TestSession) append_message_with_duration(kind MessageKind, msg string, d time.Duration, mtc MessageThreadContext) {
|
||||||
ts.nmessages <- LogMessage{
|
ts.nmessages <- LogMessage{
|
||||||
file: mtc.file
|
file: mtc.file
|
||||||
flow_id: mtc.flow_id
|
flow_id: mtc.flow_id
|
||||||
message: msg
|
message: msg
|
||||||
kind: kind
|
kind: kind
|
||||||
when: time.now()
|
when: time.now()
|
||||||
took: d
|
took: d
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -310,16 +310,16 @@ pub fn new_test_session(_vargs string, will_compile bool) TestSession {
|
||||||
os.setenv('VCOLORS', 'always', true)
|
os.setenv('VCOLORS', 'always', true)
|
||||||
}
|
}
|
||||||
mut ts := TestSession{
|
mut ts := TestSession{
|
||||||
vexe: vexe
|
vexe: vexe
|
||||||
vroot: vroot
|
vroot: vroot
|
||||||
skip_files: skip_files
|
skip_files: skip_files
|
||||||
fail_fast: testing.fail_fast
|
fail_fast: testing.fail_fast
|
||||||
show_stats: '-stats' in vargs.split(' ')
|
show_stats: '-stats' in vargs.split(' ')
|
||||||
show_asserts: '-show-asserts' in vargs.split(' ')
|
show_asserts: '-show-asserts' in vargs.split(' ')
|
||||||
vargs: vargs
|
vargs: vargs
|
||||||
vtmp_dir: new_vtmp_dir
|
vtmp_dir: new_vtmp_dir
|
||||||
hash: hash
|
hash: hash
|
||||||
silent_mode: _vargs.contains('-silent')
|
silent_mode: _vargs.contains('-silent')
|
||||||
progress_mode: _vargs.contains('-progress')
|
progress_mode: _vargs.contains('-progress')
|
||||||
}
|
}
|
||||||
ts.handle_test_runner_option()
|
ts.handle_test_runner_option()
|
||||||
|
@ -493,7 +493,7 @@ fn worker_trunner(mut p pool.PoolProcessor, idx int, thread_id int) voidptr {
|
||||||
}
|
}
|
||||||
file := os.real_path(relative_file)
|
file := os.real_path(relative_file)
|
||||||
mtc := MessageThreadContext{
|
mtc := MessageThreadContext{
|
||||||
file: file
|
file: file
|
||||||
flow_id: thread_id.str()
|
flow_id: thread_id.str()
|
||||||
}
|
}
|
||||||
normalised_relative_file := relative_file.replace('\\', '/')
|
normalised_relative_file := relative_file.replace('\\', '/')
|
||||||
|
|
|
@ -44,15 +44,15 @@ mut:
|
||||||
|
|
||||||
fn (mut c Context) compile_oldv_if_needed() {
|
fn (mut c Context) compile_oldv_if_needed() {
|
||||||
c.vgcontext = vgit.VGitContext{
|
c.vgcontext = vgit.VGitContext{
|
||||||
workdir: c.vgo.workdir
|
workdir: c.vgo.workdir
|
||||||
v_repo_url: c.vgo.v_repo_url
|
v_repo_url: c.vgo.v_repo_url
|
||||||
vc_repo_url: c.vgo.vc_repo_url
|
vc_repo_url: c.vgo.vc_repo_url
|
||||||
cc: c.cc
|
cc: c.cc
|
||||||
commit_v: c.commit_v
|
commit_v: c.commit_v
|
||||||
path_v: c.path_v
|
path_v: c.path_v
|
||||||
path_vc: c.path_vc
|
path_vc: c.path_vc
|
||||||
make_fresh_tcc: c.fresh_tcc
|
make_fresh_tcc: c.fresh_tcc
|
||||||
show_vccommit: c.show_vccommit
|
show_vccommit: c.show_vccommit
|
||||||
}
|
}
|
||||||
c.vgcontext.compile_oldv_if_needed()
|
c.vgcontext.compile_oldv_if_needed()
|
||||||
c.commit_v_hash = c.vgcontext.commit_v__hash
|
c.commit_v_hash = c.vgcontext.commit_v__hash
|
||||||
|
|
|
@ -25,9 +25,9 @@ mut:
|
||||||
|
|
||||||
fn new_context() Context {
|
fn new_context() Context {
|
||||||
return Context{
|
return Context{
|
||||||
cwd: os.getwd()
|
cwd: os.getwd()
|
||||||
commit_after: 'master'
|
commit_after: 'master'
|
||||||
warmups: 4
|
warmups: 4
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -80,12 +80,12 @@ fn (c &Context) prepare_v(cdir string, commit string) {
|
||||||
cc = 'cc'
|
cc = 'cc'
|
||||||
}
|
}
|
||||||
mut vgit_context := vgit.VGitContext{
|
mut vgit_context := vgit.VGitContext{
|
||||||
cc: cc
|
cc: cc
|
||||||
commit_v: commit
|
commit_v: commit
|
||||||
path_v: cdir
|
path_v: cdir
|
||||||
path_vc: c.vc
|
path_vc: c.vc
|
||||||
workdir: c.vgo.workdir
|
workdir: c.vgo.workdir
|
||||||
v_repo_url: c.vgo.v_repo_url
|
v_repo_url: c.vgo.v_repo_url
|
||||||
vc_repo_url: c.vgo.vc_repo_url
|
vc_repo_url: c.vgo.vc_repo_url
|
||||||
}
|
}
|
||||||
vgit_context.compile_oldv_if_needed()
|
vgit_context.compile_oldv_if_needed()
|
||||||
|
|
|
@ -126,9 +126,9 @@ fn json(file string) string {
|
||||||
pref_.is_fmt = true
|
pref_.is_fmt = true
|
||||||
|
|
||||||
mut t := Tree{
|
mut t := Tree{
|
||||||
root: new_object()
|
root: new_object()
|
||||||
table: ast.new_table()
|
table: ast.new_table()
|
||||||
pref: pref_
|
pref: pref_
|
||||||
}
|
}
|
||||||
// parse file with comment
|
// parse file with comment
|
||||||
ast_file := parser.parse_file(file, mut t.table, .parse_comments, t.pref)
|
ast_file := parser.parse_file(file, mut t.table, .parse_comments, t.pref)
|
||||||
|
|
|
@ -144,10 +144,10 @@ Try ${tool_name} -h for more help...')
|
||||||
|
|
||||||
options := Options{
|
options := Options{
|
||||||
show_help: fp.bool('help', `h`, false, 'Show this help text.')
|
show_help: fp.bool('help', `h`, false, 'Show this help text.')
|
||||||
patch: fp.bool('patch', `p`, false, 'Bump the patch version.')
|
patch: fp.bool('patch', `p`, false, 'Bump the patch version.')
|
||||||
minor: fp.bool('minor', `n`, false, 'Bump the minor version.')
|
minor: fp.bool('minor', `n`, false, 'Bump the minor version.')
|
||||||
major: fp.bool('major', `m`, false, 'Bump the major version.')
|
major: fp.bool('major', `m`, false, 'Bump the major version.')
|
||||||
skip: fp.string('skip', `s`, '', 'Skip lines matching this substring.').trim_space()
|
skip: fp.string('skip', `s`, '', 'Skip lines matching this substring.').trim_space()
|
||||||
}
|
}
|
||||||
|
|
||||||
remaining := fp.finalize() or {
|
remaining := fp.finalize() or {
|
||||||
|
|
|
@ -23,7 +23,7 @@ struct BumpTestCase {
|
||||||
const test_cases = [
|
const test_cases = [
|
||||||
BumpTestCase{
|
BumpTestCase{
|
||||||
file_name: 'v.mod'
|
file_name: 'v.mod'
|
||||||
contents: "Module {
|
contents: "Module {
|
||||||
name: 'Sample'
|
name: 'Sample'
|
||||||
description: 'Sample project'
|
description: 'Sample project'
|
||||||
version: '1.2.6'
|
version: '1.2.6'
|
||||||
|
@ -32,28 +32,28 @@ const test_cases = [
|
||||||
}
|
}
|
||||||
|
|
||||||
"
|
"
|
||||||
line: 3
|
line: 3
|
||||||
expected_patch: " version: '1.2.7'"
|
expected_patch: " version: '1.2.7'"
|
||||||
expected_minor: " version: '1.3.0'"
|
expected_minor: " version: '1.3.0'"
|
||||||
expected_major: " version: '2.0.0'"
|
expected_major: " version: '2.0.0'"
|
||||||
},
|
},
|
||||||
BumpTestCase{
|
BumpTestCase{
|
||||||
file_name: 'random_versions.vv'
|
file_name: 'random_versions.vv'
|
||||||
contents: "
|
contents: "
|
||||||
1.1.2
|
1.1.2
|
||||||
1.2.5
|
1.2.5
|
||||||
3.21.73
|
3.21.73
|
||||||
version = '1.5.1'
|
version = '1.5.1'
|
||||||
|
|
||||||
"
|
"
|
||||||
line: 4
|
line: 4
|
||||||
expected_patch: "version = '1.5.2'"
|
expected_patch: "version = '1.5.2'"
|
||||||
expected_minor: "version = '1.6.0'"
|
expected_minor: "version = '1.6.0'"
|
||||||
expected_major: "version = '2.0.0'"
|
expected_major: "version = '2.0.0'"
|
||||||
},
|
},
|
||||||
BumpTestCase{
|
BumpTestCase{
|
||||||
file_name: 'sample_tool.v'
|
file_name: 'sample_tool.v'
|
||||||
contents: "// Module comment and copyright information
|
contents: "// Module comment and copyright information
|
||||||
import os
|
import os
|
||||||
import flag
|
import flag
|
||||||
|
|
||||||
|
@ -64,7 +64,7 @@ fn main() {
|
||||||
// stuff
|
// stuff
|
||||||
}
|
}
|
||||||
"
|
"
|
||||||
line: 5
|
line: 5
|
||||||
expected_patch: "const tool_version = '0.1.34'"
|
expected_patch: "const tool_version = '0.1.34'"
|
||||||
expected_minor: "const tool_version = '0.2.0'"
|
expected_minor: "const tool_version = '0.2.0'"
|
||||||
expected_major: "const tool_version = '1.0.0'"
|
expected_major: "const tool_version = '1.0.0'"
|
||||||
|
@ -111,7 +111,7 @@ struct SkipTestCase {
|
||||||
const skip_test_cases = [
|
const skip_test_cases = [
|
||||||
SkipTestCase{
|
SkipTestCase{
|
||||||
file_name: 'CITATION.cff'
|
file_name: 'CITATION.cff'
|
||||||
contents: 'abstract: A sample CLI tool made in V that prints geometric shapes to the screen.
|
contents: 'abstract: A sample CLI tool made in V that prints geometric shapes to the screen.
|
||||||
authors:
|
authors:
|
||||||
- alias: hungrybluedev
|
- alias: hungrybluedev
|
||||||
family-names: Haldar
|
family-names: Haldar
|
||||||
|
@ -125,8 +125,8 @@ title: geo
|
||||||
url: https://github.com/hungrybluedev/geo
|
url: https://github.com/hungrybluedev/geo
|
||||||
version: 0.2.4
|
version: 0.2.4
|
||||||
'
|
'
|
||||||
line: 12
|
line: 12
|
||||||
skip: 'cff-version'
|
skip: 'cff-version'
|
||||||
expected_patch: 'version: 0.2.5'
|
expected_patch: 'version: 0.2.5'
|
||||||
expected_minor: 'version: 0.3.0'
|
expected_minor: 'version: 0.3.0'
|
||||||
expected_major: 'version: 1.0.0'
|
expected_major: 'version: 1.0.0'
|
||||||
|
|
|
@ -34,10 +34,10 @@ pub mut:
|
||||||
|
|
||||||
fn (v1 CheckResult) + (v2 CheckResult) CheckResult {
|
fn (v1 CheckResult) + (v2 CheckResult) CheckResult {
|
||||||
return CheckResult{
|
return CheckResult{
|
||||||
files: v1.files + v2.files
|
files: v1.files + v2.files
|
||||||
warnings: v1.warnings + v2.warnings
|
warnings: v1.warnings + v2.warnings
|
||||||
errors: v1.errors + v2.errors
|
errors: v1.errors + v2.errors
|
||||||
oks: v1.oks + v2.oks
|
oks: v1.oks + v2.oks
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -77,8 +77,8 @@ fn main() {
|
||||||
}
|
}
|
||||||
mut mdfile := MDFile{
|
mut mdfile := MDFile{
|
||||||
skip_line_length_check: skip_line_length_check
|
skip_line_length_check: skip_line_length_check
|
||||||
path: file_path
|
path: file_path
|
||||||
lines: lines
|
lines: lines
|
||||||
}
|
}
|
||||||
res += mdfile.check()
|
res += mdfile.check()
|
||||||
}
|
}
|
||||||
|
@ -243,7 +243,7 @@ fn (mut f MDFile) parse_line(lnumber int, line string) {
|
||||||
command += ' ${default_command}'
|
command += ' ${default_command}'
|
||||||
}
|
}
|
||||||
f.current = VCodeExample{
|
f.current = VCodeExample{
|
||||||
sline: lnumber
|
sline: lnumber
|
||||||
command: command
|
command: command
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -305,7 +305,7 @@ fn (mut ad AnchorData) add_links(line_number int, line string) {
|
||||||
re.match_string(elem)
|
re.match_string(elem)
|
||||||
link := re.get_group_by_name(elem, 'link')
|
link := re.get_group_by_name(elem, 'link')
|
||||||
ad.links[link] << AnchorLink{
|
ad.links[link] << AnchorLink{
|
||||||
line: line_number
|
line: line_number
|
||||||
label: re.get_group_by_name(elem, 'label')
|
label: re.get_group_by_name(elem, 'label')
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -317,7 +317,7 @@ fn (mut ad AnchorData) add_link_targets(line_number int, line string) {
|
||||||
headline := line.substr(headline_start_pos + 1, line.len)
|
headline := line.substr(headline_start_pos + 1, line.len)
|
||||||
link := create_ref_link(headline)
|
link := create_ref_link(headline)
|
||||||
ad.anchors[link] << Headline{
|
ad.anchors[link] << Headline{
|
||||||
line: line_number
|
line: line_number
|
||||||
label: headline
|
label: headline
|
||||||
level: headline_start_pos
|
level: headline_start_pos
|
||||||
}
|
}
|
||||||
|
@ -634,7 +634,7 @@ fn (mut f MDFile) check_examples() CheckResult {
|
||||||
}
|
}
|
||||||
return CheckResult{
|
return CheckResult{
|
||||||
errors: errors
|
errors: errors
|
||||||
oks: oks
|
oks: oks
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -81,9 +81,9 @@ fn (mut ctx Context) process_target(tfile string) ! {
|
||||||
for {
|
for {
|
||||||
row := reader.read() or { break }
|
row := reader.read() or { break }
|
||||||
mut cline := CounterLine{
|
mut cline := CounterLine{
|
||||||
meta: row[0]
|
meta: row[0]
|
||||||
point: row[1].int()
|
point: row[1].int()
|
||||||
hits: row[2].u64()
|
hits: row[2].u64()
|
||||||
}
|
}
|
||||||
m := ctx.meta[cline.meta] or {
|
m := ctx.meta[cline.meta] or {
|
||||||
ctx.verbose('> skipping invalid meta: ${cline.meta} in file: ${cline.file}, csvfile: ${tfile}')
|
ctx.verbose('> skipping invalid meta: ${cline.meta} in file: ${cline.file}, csvfile: ${tfile}')
|
||||||
|
|
|
@ -5,7 +5,7 @@ import os
|
||||||
fn (mut c Create) set_bin_project_files() {
|
fn (mut c Create) set_bin_project_files() {
|
||||||
base := if c.new_dir { c.name } else { '' }
|
base := if c.new_dir { c.name } else { '' }
|
||||||
c.files << ProjectFiles{
|
c.files << ProjectFiles{
|
||||||
path: os.join_path(base, 'src', 'main.v')
|
path: os.join_path(base, 'src', 'main.v')
|
||||||
content: "module main
|
content: "module main
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
|
|
|
@ -5,7 +5,7 @@ import os
|
||||||
fn (mut c Create) set_lib_project_files() {
|
fn (mut c Create) set_lib_project_files() {
|
||||||
base := if c.new_dir { c.name } else { '' }
|
base := if c.new_dir { c.name } else { '' }
|
||||||
c.files << ProjectFiles{
|
c.files << ProjectFiles{
|
||||||
path: os.join_path(base, 'src', c.name + '.v')
|
path: os.join_path(base, 'src', c.name + '.v')
|
||||||
content: 'module ${c.name}
|
content: 'module ${c.name}
|
||||||
|
|
||||||
// square calculates the second power of `x`
|
// square calculates the second power of `x`
|
||||||
|
@ -15,7 +15,7 @@ pub fn square(x int) int {
|
||||||
'
|
'
|
||||||
}
|
}
|
||||||
c.files << ProjectFiles{
|
c.files << ProjectFiles{
|
||||||
path: os.join_path(base, 'tests', 'square_test.v')
|
path: os.join_path(base, 'tests', 'square_test.v')
|
||||||
content: 'import ${c.name}
|
content: 'import ${c.name}
|
||||||
|
|
||||||
fn test_square() {
|
fn test_square() {
|
||||||
|
|
|
@ -5,7 +5,7 @@ import os { join_path }
|
||||||
fn (mut c Create) set_web_project_files() {
|
fn (mut c Create) set_web_project_files() {
|
||||||
base := if c.new_dir { c.name } else { '' }
|
base := if c.new_dir { c.name } else { '' }
|
||||||
c.files << ProjectFiles{
|
c.files << ProjectFiles{
|
||||||
path: join_path(base, 'src', 'databases', 'config_databases_sqlite.v')
|
path: join_path(base, 'src', 'databases', 'config_databases_sqlite.v')
|
||||||
content: "module databases
|
content: "module databases
|
||||||
|
|
||||||
import db.sqlite // can change to 'db.mysql', 'db.pg'
|
import db.sqlite // can change to 'db.mysql', 'db.pg'
|
||||||
|
@ -17,7 +17,7 @@ pub fn create_db_connection() !sqlite.DB {
|
||||||
"
|
"
|
||||||
}
|
}
|
||||||
c.files << ProjectFiles{
|
c.files << ProjectFiles{
|
||||||
path: join_path(base, 'src', 'templates', 'header_component.html')
|
path: join_path(base, 'src', 'templates', 'header_component.html')
|
||||||
content: "<nav>
|
content: "<nav>
|
||||||
<div class='nav-wrapper'>
|
<div class='nav-wrapper'>
|
||||||
<a href='javascript:window.history.back();' class='left'>
|
<a href='javascript:window.history.back();' class='left'>
|
||||||
|
@ -36,7 +36,7 @@ pub fn create_db_connection() !sqlite.DB {
|
||||||
"
|
"
|
||||||
}
|
}
|
||||||
c.files << ProjectFiles{
|
c.files << ProjectFiles{
|
||||||
path: join_path(base, 'src', 'templates', 'products.css')
|
path: join_path(base, 'src', 'templates', 'products.css')
|
||||||
content: 'h1.title {
|
content: 'h1.title {
|
||||||
font-family: Arial, Helvetica, sans-serif;
|
font-family: Arial, Helvetica, sans-serif;
|
||||||
color: #3b7bbf;
|
color: #3b7bbf;
|
||||||
|
@ -50,7 +50,7 @@ div.products-table {
|
||||||
}'
|
}'
|
||||||
}
|
}
|
||||||
c.files << ProjectFiles{
|
c.files << ProjectFiles{
|
||||||
path: join_path(base, 'src', 'templates', 'products.html')
|
path: join_path(base, 'src', 'templates', 'products.html')
|
||||||
content: "<!DOCTYPE html>
|
content: "<!DOCTYPE html>
|
||||||
<html>
|
<html>
|
||||||
<head>
|
<head>
|
||||||
|
@ -147,7 +147,7 @@ div.products-table {
|
||||||
</html>"
|
</html>"
|
||||||
}
|
}
|
||||||
c.files << ProjectFiles{
|
c.files << ProjectFiles{
|
||||||
path: join_path(base, 'src', 'auth_controllers.v')
|
path: join_path(base, 'src', 'auth_controllers.v')
|
||||||
content: "module main
|
content: "module main
|
||||||
|
|
||||||
import vweb
|
import vweb
|
||||||
|
@ -164,7 +164,7 @@ pub fn (mut app App) controller_auth(username string, password string) vweb.Resu
|
||||||
"
|
"
|
||||||
}
|
}
|
||||||
c.files << ProjectFiles{
|
c.files << ProjectFiles{
|
||||||
path: join_path(base, 'src', 'auth_dto.v')
|
path: join_path(base, 'src', 'auth_dto.v')
|
||||||
content: 'module main
|
content: 'module main
|
||||||
|
|
||||||
struct AuthRequestDto {
|
struct AuthRequestDto {
|
||||||
|
@ -174,7 +174,7 @@ struct AuthRequestDto {
|
||||||
'
|
'
|
||||||
}
|
}
|
||||||
c.files << ProjectFiles{
|
c.files << ProjectFiles{
|
||||||
path: join_path(base, 'src', 'auth_services.v')
|
path: join_path(base, 'src', 'auth_services.v')
|
||||||
content: "module main
|
content: "module main
|
||||||
|
|
||||||
import crypto.hmac
|
import crypto.hmac
|
||||||
|
@ -269,7 +269,7 @@ fn auth_verify(token string) bool {
|
||||||
"
|
"
|
||||||
}
|
}
|
||||||
c.files << ProjectFiles{
|
c.files << ProjectFiles{
|
||||||
path: join_path(base, 'src', 'index.html')
|
path: join_path(base, 'src', 'index.html')
|
||||||
content: "<!DOCTYPE html>
|
content: "<!DOCTYPE html>
|
||||||
<html>
|
<html>
|
||||||
<head>
|
<head>
|
||||||
|
@ -348,7 +348,7 @@ fn auth_verify(token string) bool {
|
||||||
"
|
"
|
||||||
}
|
}
|
||||||
c.files << ProjectFiles{
|
c.files << ProjectFiles{
|
||||||
path: join_path(base, 'src', 'main.v')
|
path: join_path(base, 'src', 'main.v')
|
||||||
content: "module main
|
content: "module main
|
||||||
|
|
||||||
import vweb
|
import vweb
|
||||||
|
@ -391,7 +391,7 @@ pub fn (mut app App) index() vweb.Result {
|
||||||
"
|
"
|
||||||
}
|
}
|
||||||
c.files << ProjectFiles{
|
c.files << ProjectFiles{
|
||||||
path: join_path(base, 'src', 'product_controller.v')
|
path: join_path(base, 'src', 'product_controller.v')
|
||||||
content: "module main
|
content: "module main
|
||||||
|
|
||||||
import vweb
|
import vweb
|
||||||
|
@ -457,7 +457,7 @@ pub fn (mut app App) controller_create_product(product_name string) vweb.Result
|
||||||
"
|
"
|
||||||
}
|
}
|
||||||
c.files << ProjectFiles{
|
c.files << ProjectFiles{
|
||||||
path: join_path(base, 'src', 'product_entities.v')
|
path: join_path(base, 'src', 'product_entities.v')
|
||||||
content: "module main
|
content: "module main
|
||||||
|
|
||||||
@[table: 'products']
|
@[table: 'products']
|
||||||
|
@ -470,7 +470,7 @@ struct Product {
|
||||||
"
|
"
|
||||||
}
|
}
|
||||||
c.files << ProjectFiles{
|
c.files << ProjectFiles{
|
||||||
path: join_path(base, 'src', 'product_service.v')
|
path: join_path(base, 'src', 'product_service.v')
|
||||||
content: "module main
|
content: "module main
|
||||||
|
|
||||||
import databases
|
import databases
|
||||||
|
@ -517,7 +517,7 @@ fn (mut app App) service_get_all_products_from(user_id int) ![]Product {
|
||||||
"
|
"
|
||||||
}
|
}
|
||||||
c.files << ProjectFiles{
|
c.files << ProjectFiles{
|
||||||
path: join_path(base, 'src', 'product_view_api.v')
|
path: join_path(base, 'src', 'product_view_api.v')
|
||||||
content: "module main
|
content: "module main
|
||||||
|
|
||||||
import json
|
import json
|
||||||
|
@ -556,7 +556,7 @@ pub fn get_product(token string) ![]User {
|
||||||
"
|
"
|
||||||
}
|
}
|
||||||
c.files << ProjectFiles{
|
c.files << ProjectFiles{
|
||||||
path: join_path(base, 'src', 'product_view.v')
|
path: join_path(base, 'src', 'product_view.v')
|
||||||
content: "module main
|
content: "module main
|
||||||
|
|
||||||
import vweb
|
import vweb
|
||||||
|
@ -578,7 +578,7 @@ pub fn (mut app App) products() !vweb.Result {
|
||||||
"
|
"
|
||||||
}
|
}
|
||||||
c.files << ProjectFiles{
|
c.files << ProjectFiles{
|
||||||
path: join_path(base, 'src', 'user_controllers.v')
|
path: join_path(base, 'src', 'user_controllers.v')
|
||||||
content: "module main
|
content: "module main
|
||||||
|
|
||||||
import vweb
|
import vweb
|
||||||
|
@ -648,7 +648,7 @@ pub fn (mut app App) controller_create_user(username string, password string) vw
|
||||||
"
|
"
|
||||||
}
|
}
|
||||||
c.files << ProjectFiles{
|
c.files << ProjectFiles{
|
||||||
path: join_path(base, 'src', 'user_entities.v')
|
path: join_path(base, 'src', 'user_entities.v')
|
||||||
content: "module main
|
content: "module main
|
||||||
|
|
||||||
@[table: 'users']
|
@[table: 'users']
|
||||||
|
@ -663,7 +663,7 @@ mut:
|
||||||
"
|
"
|
||||||
}
|
}
|
||||||
c.files << ProjectFiles{
|
c.files << ProjectFiles{
|
||||||
path: join_path(base, 'src', 'user_services.v')
|
path: join_path(base, 'src', 'user_services.v')
|
||||||
content: "module main
|
content: "module main
|
||||||
|
|
||||||
import crypto.bcrypt
|
import crypto.bcrypt
|
||||||
|
@ -732,7 +732,7 @@ fn (mut app App) service_get_user(id int) !User {
|
||||||
"
|
"
|
||||||
}
|
}
|
||||||
c.files << ProjectFiles{
|
c.files << ProjectFiles{
|
||||||
path: join_path(base, 'src', 'user_view_api.v')
|
path: join_path(base, 'src', 'user_view_api.v')
|
||||||
content: "module main
|
content: "module main
|
||||||
|
|
||||||
import json
|
import json
|
||||||
|
|
|
@ -34,35 +34,35 @@ enum Template {
|
||||||
fn main() {
|
fn main() {
|
||||||
flags := [
|
flags := [
|
||||||
Flag{
|
Flag{
|
||||||
flag: .bool
|
flag: .bool
|
||||||
name: 'bin'
|
name: 'bin'
|
||||||
description: 'Use the template for an executable application [default].'
|
description: 'Use the template for an executable application [default].'
|
||||||
},
|
},
|
||||||
Flag{
|
Flag{
|
||||||
flag: .bool
|
flag: .bool
|
||||||
name: 'lib'
|
name: 'lib'
|
||||||
description: 'Use the template for a library project.'
|
description: 'Use the template for a library project.'
|
||||||
},
|
},
|
||||||
Flag{
|
Flag{
|
||||||
flag: .bool
|
flag: .bool
|
||||||
name: 'web'
|
name: 'web'
|
||||||
description: 'Use the template for a vweb project.'
|
description: 'Use the template for a vweb project.'
|
||||||
},
|
},
|
||||||
]
|
]
|
||||||
mut cmd := Command{
|
mut cmd := Command{
|
||||||
flags: [
|
flags: [
|
||||||
Flag{
|
Flag{
|
||||||
flag: .bool
|
flag: .bool
|
||||||
name: 'help'
|
name: 'help'
|
||||||
description: 'Print help information.'
|
description: 'Print help information.'
|
||||||
global: true
|
global: true
|
||||||
},
|
},
|
||||||
]
|
]
|
||||||
posix_mode: true
|
posix_mode: true
|
||||||
commands: [
|
commands: [
|
||||||
Command{
|
Command{
|
||||||
name: 'new'
|
name: 'new'
|
||||||
usage: '<project_name>'
|
usage: '<project_name>'
|
||||||
description: [
|
description: [
|
||||||
'Creates a new V project in a directory with the specified project name.',
|
'Creates a new V project in a directory with the specified project name.',
|
||||||
'',
|
'',
|
||||||
|
@ -73,13 +73,13 @@ fn main() {
|
||||||
parent: &Command{
|
parent: &Command{
|
||||||
name: 'v'
|
name: 'v'
|
||||||
}
|
}
|
||||||
posix_mode: true
|
posix_mode: true
|
||||||
flags: flags
|
flags: flags
|
||||||
pre_execute: validate
|
pre_execute: validate
|
||||||
execute: new_project
|
execute: new_project
|
||||||
},
|
},
|
||||||
Command{
|
Command{
|
||||||
name: 'init'
|
name: 'init'
|
||||||
description: [
|
description: [
|
||||||
'Sets up a V project within the current directory.',
|
'Sets up a V project within the current directory.',
|
||||||
'',
|
'',
|
||||||
|
@ -90,10 +90,10 @@ fn main() {
|
||||||
parent: &Command{
|
parent: &Command{
|
||||||
name: 'v'
|
name: 'v'
|
||||||
}
|
}
|
||||||
posix_mode: true
|
posix_mode: true
|
||||||
flags: flags
|
flags: flags
|
||||||
pre_execute: validate
|
pre_execute: validate
|
||||||
execute: init_project
|
execute: init_project
|
||||||
},
|
},
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
@ -115,7 +115,7 @@ fn validate(cmd Command) ! {
|
||||||
fn new_project(cmd Command) ! {
|
fn new_project(cmd Command) ! {
|
||||||
mut c := Create{
|
mut c := Create{
|
||||||
template: get_template(cmd)
|
template: get_template(cmd)
|
||||||
new_dir: true
|
new_dir: true
|
||||||
}
|
}
|
||||||
c.prompt(cmd.args)
|
c.prompt(cmd.args)
|
||||||
println('Initialising ...')
|
println('Initialising ...')
|
||||||
|
|
|
@ -134,7 +134,7 @@ fn (mut vd VDoc) collect_search_index(out Output) {
|
||||||
}
|
}
|
||||||
vd.search_module_data << SearchModuleResult{
|
vd.search_module_data << SearchModuleResult{
|
||||||
description: trim_doc_node_description(mod, comments)
|
description: trim_doc_node_description(mod, comments)
|
||||||
link: vd.get_file_name(mod, out)
|
link: vd.get_file_name(mod, out)
|
||||||
}
|
}
|
||||||
for _, dn in doc.contents {
|
for _, dn in doc.contents {
|
||||||
vd.create_search_results(mod, dn, out)
|
vd.create_search_results(mod, dn, out)
|
||||||
|
@ -155,10 +155,14 @@ fn (mut vd VDoc) create_search_results(mod string, dn doc.DocNode, out Output) {
|
||||||
dn_description := trim_doc_node_description(dn.name, comments)
|
dn_description := trim_doc_node_description(dn.name, comments)
|
||||||
vd.search_index << dn.name
|
vd.search_index << dn.name
|
||||||
vd.search_data << SearchResult{
|
vd.search_data << SearchResult{
|
||||||
prefix: if dn.parent_name != '' { '${dn.kind} (${dn.parent_name})' } else { '${dn.kind} ' }
|
prefix: if dn.parent_name != '' {
|
||||||
|
'${dn.kind} (${dn.parent_name})'
|
||||||
|
} else {
|
||||||
|
'${dn.kind} '
|
||||||
|
}
|
||||||
description: dn_description
|
description: dn_description
|
||||||
badge: mod
|
badge: mod
|
||||||
link: vd.get_file_name(mod, out) + '#' + get_node_id(dn)
|
link: vd.get_file_name(mod, out) + '#' + get_node_id(dn)
|
||||||
}
|
}
|
||||||
for child in dn.children {
|
for child in dn.children {
|
||||||
vd.create_search_results(mod, child, out)
|
vd.create_search_results(mod, child, out)
|
||||||
|
|
|
@ -55,7 +55,7 @@ fn main() {
|
||||||
}
|
}
|
||||||
// Config is immutable from this point on
|
// Config is immutable from this point on
|
||||||
mut vd := &VDoc{
|
mut vd := &VDoc{
|
||||||
cfg: cfg
|
cfg: cfg
|
||||||
manifest: vmod.Manifest{}
|
manifest: vmod.Manifest{}
|
||||||
}
|
}
|
||||||
vd.vprintln('Setting output type to "${cfg.output_type}"')
|
vd.vprintln('Setting output type to "${cfg.output_type}"')
|
||||||
|
|
|
@ -258,7 +258,7 @@ fn (mut vd VDoc) generate_docs_from_file() {
|
||||||
cfg := vd.cfg
|
cfg := vd.cfg
|
||||||
mut out := Output{
|
mut out := Output{
|
||||||
path: cfg.output_path
|
path: cfg.output_path
|
||||||
typ: cfg.output_type
|
typ: cfg.output_type
|
||||||
}
|
}
|
||||||
if out.path == '' {
|
if out.path == '' {
|
||||||
if cfg.output_type == .unset {
|
if cfg.output_type == .unset {
|
||||||
|
@ -300,7 +300,7 @@ fn (mut vd VDoc) generate_docs_from_file() {
|
||||||
} else if out.typ == .html && cfg.is_multi {
|
} else if out.typ == .html && cfg.is_multi {
|
||||||
vd.docs << doc.Doc{
|
vd.docs << doc.Doc{
|
||||||
head: doc.DocNode{
|
head: doc.DocNode{
|
||||||
name: 'README'
|
name: 'README'
|
||||||
comments: [comment]
|
comments: [comment]
|
||||||
}
|
}
|
||||||
time_generated: time.now()
|
time_generated: time.now()
|
||||||
|
|
|
@ -51,7 +51,7 @@ fn (mut a App) collect_info() {
|
||||||
if os_kind == 'windows' {
|
if os_kind == 'windows' {
|
||||||
arch_details << a.cmd(
|
arch_details << a.cmd(
|
||||||
command: 'wmic cpu get name /format:table'
|
command: 'wmic cpu get name /format:table'
|
||||||
line: 1
|
line: 1
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
//
|
//
|
||||||
|
@ -87,7 +87,7 @@ fn (mut a App) collect_info() {
|
||||||
} else if os_kind == 'windows' {
|
} else if os_kind == 'windows' {
|
||||||
wmic_info := a.cmd(
|
wmic_info := a.cmd(
|
||||||
command: 'wmic os get * /format:value'
|
command: 'wmic os get * /format:value'
|
||||||
line: -1
|
line: -1
|
||||||
)
|
)
|
||||||
p := a.parse(wmic_info, '=')
|
p := a.parse(wmic_info, '=')
|
||||||
caption, build_number, os_arch := p['caption'], p['buildnumber'], p['osarchitecture']
|
caption, build_number, os_arch := p['caption'], p['buildnumber'], p['osarchitecture']
|
||||||
|
|
|
@ -44,16 +44,16 @@ fn main() {
|
||||||
util.set_vroot_folder(os.dir(os.dir(os.dir(toolexe))))
|
util.set_vroot_folder(os.dir(os.dir(os.dir(toolexe))))
|
||||||
args := util.join_env_vflags_and_os_args()
|
args := util.join_env_vflags_and_os_args()
|
||||||
mut foptions := FormatOptions{
|
mut foptions := FormatOptions{
|
||||||
is_c: '-c' in args
|
is_c: '-c' in args
|
||||||
is_l: '-l' in args
|
is_l: '-l' in args
|
||||||
is_w: '-w' in args
|
is_w: '-w' in args
|
||||||
is_diff: '-diff' in args
|
is_diff: '-diff' in args
|
||||||
is_verbose: '-verbose' in args || '--verbose' in args
|
is_verbose: '-verbose' in args || '--verbose' in args
|
||||||
is_worker: '-worker' in args
|
is_worker: '-worker' in args
|
||||||
is_debug: '-debug' in args
|
is_debug: '-debug' in args
|
||||||
is_noerror: '-noerror' in args
|
is_noerror: '-noerror' in args
|
||||||
is_verify: '-verify' in args
|
is_verify: '-verify' in args
|
||||||
is_backup: '-backup' in args
|
is_backup: '-backup' in args
|
||||||
in_process: '-inprocess' in args
|
in_process: '-inprocess' in args
|
||||||
}
|
}
|
||||||
if term_colors {
|
if term_colors {
|
||||||
|
|
|
@ -162,9 +162,9 @@ fn main() {
|
||||||
|
|
||||||
// Collect tool options
|
// Collect tool options
|
||||||
mut opt := Options{
|
mut opt := Options{
|
||||||
verbose: fp.bool('verbose', `v`, false, "Be verbose about the tool's progress.")
|
verbose: fp.bool('verbose', `v`, false, "Be verbose about the tool's progress.")
|
||||||
compare_only: fp.bool('compare-only', `c`, false, "Don't generate screenshots - only compare input directories")
|
compare_only: fp.bool('compare-only', `c`, false, "Don't generate screenshots - only compare input directories")
|
||||||
root_path: fp.string('root-path', `r`, v_root, 'Root path of the comparison')
|
root_path: fp.string('root-path', `r`, v_root, 'Root path of the comparison')
|
||||||
}
|
}
|
||||||
|
|
||||||
toml_conf := fp.string('toml-config', `t`, default_toml, 'Path or string with TOML configuration')
|
toml_conf := fp.string('toml-config', `t`, default_toml, 'Path or string with TOML configuration')
|
||||||
|
@ -446,7 +446,7 @@ fn new_config(root_path string, toml_config string) !Config {
|
||||||
compare_flags := doc.value('compare.flags').default_to(empty_toml_array).array().as_strings()
|
compare_flags := doc.value('compare.flags').default_to(empty_toml_array).array().as_strings()
|
||||||
default_compare := CompareOptions{
|
default_compare := CompareOptions{
|
||||||
method: compare_method
|
method: compare_method
|
||||||
flags: compare_flags
|
flags: compare_flags
|
||||||
}
|
}
|
||||||
capture_method := doc.value('capture.method').default_to('gg_record').string()
|
capture_method := doc.value('capture.method').default_to('gg_record').string()
|
||||||
capture_flags := doc.value('capture.flags').default_to(empty_toml_array).array().as_strings()
|
capture_flags := doc.value('capture.flags').default_to(empty_toml_array).array().as_strings()
|
||||||
|
@ -454,9 +454,9 @@ fn new_config(root_path string, toml_config string) !Config {
|
||||||
mut capture_regions := []CaptureRegion{}
|
mut capture_regions := []CaptureRegion{}
|
||||||
for capture_region_any in capture_regions_any {
|
for capture_region_any in capture_regions_any {
|
||||||
region := CaptureRegion{
|
region := CaptureRegion{
|
||||||
x: capture_region_any.value('x').default_to(0).int()
|
x: capture_region_any.value('x').default_to(0).int()
|
||||||
y: capture_region_any.value('y').default_to(0).int()
|
y: capture_region_any.value('y').default_to(0).int()
|
||||||
width: capture_region_any.value('width').default_to(0).int()
|
width: capture_region_any.value('width').default_to(0).int()
|
||||||
height: capture_region_any.value('height').default_to(0).int()
|
height: capture_region_any.value('height').default_to(0).int()
|
||||||
}
|
}
|
||||||
capture_regions << region
|
capture_regions << region
|
||||||
|
@ -468,11 +468,11 @@ fn new_config(root_path string, toml_config string) !Config {
|
||||||
env_map[k] = v.string()
|
env_map[k] = v.string()
|
||||||
}
|
}
|
||||||
default_capture := CaptureOptions{
|
default_capture := CaptureOptions{
|
||||||
method: capture_method
|
method: capture_method
|
||||||
wait_ms: capture_wait_ms
|
wait_ms: capture_wait_ms
|
||||||
flags: capture_flags
|
flags: capture_flags
|
||||||
regions: capture_regions
|
regions: capture_regions
|
||||||
env: env_map
|
env: env_map
|
||||||
}
|
}
|
||||||
|
|
||||||
apps_any := doc.value('apps').default_to(empty_toml_array).array()
|
apps_any := doc.value('apps').default_to(empty_toml_array).array()
|
||||||
|
@ -503,9 +503,9 @@ fn new_config(root_path string, toml_config string) !Config {
|
||||||
mut app_capture_regions := []CaptureRegion{}
|
mut app_capture_regions := []CaptureRegion{}
|
||||||
for capture_region_any in app_capture_regions_any {
|
for capture_region_any in app_capture_regions_any {
|
||||||
region := CaptureRegion{
|
region := CaptureRegion{
|
||||||
x: capture_region_any.value('x').default_to(0).int()
|
x: capture_region_any.value('x').default_to(0).int()
|
||||||
y: capture_region_any.value('y').default_to(0).int()
|
y: capture_region_any.value('y').default_to(0).int()
|
||||||
width: capture_region_any.value('width').default_to(0).int()
|
width: capture_region_any.value('width').default_to(0).int()
|
||||||
height: capture_region_any.value('height').default_to(0).int()
|
height: capture_region_any.value('height').default_to(0).int()
|
||||||
}
|
}
|
||||||
app_capture_regions << region
|
app_capture_regions << region
|
||||||
|
@ -536,9 +536,9 @@ fn new_config(root_path string, toml_config string) !Config {
|
||||||
merged_capture.validate()!
|
merged_capture.validate()!
|
||||||
|
|
||||||
app_config := AppConfig{
|
app_config := AppConfig{
|
||||||
compare: merged_compare
|
compare: merged_compare
|
||||||
capture: merged_capture
|
capture: merged_capture
|
||||||
path: rel_path
|
path: rel_path
|
||||||
abs_path: os.join_path(path, rel_path).trim_right('/')
|
abs_path: os.join_path(path, rel_path).trim_right('/')
|
||||||
}
|
}
|
||||||
apps << app_config
|
apps << app_config
|
||||||
|
|
|
@ -63,9 +63,9 @@ const server_not_found_err = error_with_code('Language server is not installed n
|
||||||
101)
|
101)
|
||||||
|
|
||||||
const json_enc = json2.Encoder{
|
const json_enc = json2.Encoder{
|
||||||
newline: `\n`
|
newline: `\n`
|
||||||
newline_spaces_count: 2
|
newline_spaces_count: 2
|
||||||
escape_unicode: false
|
escape_unicode: false
|
||||||
}
|
}
|
||||||
|
|
||||||
fn (upd VlsUpdater) check_or_create_vls_folder() ! {
|
fn (upd VlsUpdater) check_or_create_vls_folder() ! {
|
||||||
|
|
|
@ -74,10 +74,10 @@ fn (opt &Options) collect_undocumented_functions_in_file(nfile string) []Undocum
|
||||||
if comments.len == 0 {
|
if comments.len == 0 {
|
||||||
clean_line := line.all_before_last(' {')
|
clean_line := line.all_before_last(' {')
|
||||||
list << UndocumentedFN{
|
list << UndocumentedFN{
|
||||||
line: i + 1
|
line: i + 1
|
||||||
signature: clean_line
|
signature: clean_line
|
||||||
tags: tags
|
tags: tags
|
||||||
file: file
|
file: file
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
tags = []
|
tags = []
|
||||||
|
@ -229,16 +229,16 @@ fn main() {
|
||||||
|
|
||||||
// Collect tool options
|
// Collect tool options
|
||||||
mut opt := Options{
|
mut opt := Options{
|
||||||
show_help: fp.bool('help', `h`, false, 'Show this help text.')
|
show_help: fp.bool('help', `h`, false, 'Show this help text.')
|
||||||
deprecated: fp.bool('deprecated', `d`, false, 'Include deprecated functions in output.')
|
deprecated: fp.bool('deprecated', `d`, false, 'Include deprecated functions in output.')
|
||||||
private: fp.bool('private', `p`, false, 'Include private functions in output.')
|
private: fp.bool('private', `p`, false, 'Include private functions in output.')
|
||||||
js: fp.bool('js', 0, false, 'Include JavaScript functions in output.')
|
js: fp.bool('js', 0, false, 'Include JavaScript functions in output.')
|
||||||
no_line_numbers: fp.bool('no-line-numbers', `n`, false, 'Exclude line numbers in output.')
|
no_line_numbers: fp.bool('no-line-numbers', `n`, false, 'Exclude line numbers in output.')
|
||||||
collect_tags: fp.bool('tags', `t`, false, 'Also print function tags if any is found.')
|
collect_tags: fp.bool('tags', `t`, false, 'Also print function tags if any is found.')
|
||||||
exclude: fp.string_multi('exclude', `e`, '')
|
exclude: fp.string_multi('exclude', `e`, '')
|
||||||
relative_paths: fp.bool('relative-paths', `r`, false, 'Use relative paths in output.')
|
relative_paths: fp.bool('relative-paths', `r`, false, 'Use relative paths in output.')
|
||||||
diff: fp.bool('diff', 0, false, 'exit(1) and show difference between two PATH inputs, return 0 otherwise.')
|
diff: fp.bool('diff', 0, false, 'exit(1) and show difference between two PATH inputs, return 0 otherwise.')
|
||||||
verify: fp.bool('verify', 0, false, 'exit(1) if documentation is missing, 0 otherwise.')
|
verify: fp.bool('verify', 0, false, 'exit(1) if documentation is missing, 0 otherwise.')
|
||||||
}
|
}
|
||||||
|
|
||||||
opt.additional_args = fp.finalize() or { panic(err) }
|
opt.additional_args = fp.finalize() or { panic(err) }
|
||||||
|
|
|
@ -114,13 +114,13 @@ fn (mut p Parser) parse_module(m string) {
|
||||||
mod_path := normalize_mod_path(os.join_path(if kind == .http { publisher } else { '' },
|
mod_path := normalize_mod_path(os.join_path(if kind == .http { publisher } else { '' },
|
||||||
manifest.name))
|
manifest.name))
|
||||||
Module{
|
Module{
|
||||||
name: manifest.name
|
name: manifest.name
|
||||||
url: ident
|
url: ident
|
||||||
version: version
|
version: version
|
||||||
install_path: os.real_path(os.join_path(settings.vmodules_path, mod_path))
|
install_path: os.real_path(os.join_path(settings.vmodules_path, mod_path))
|
||||||
is_external: true
|
is_external: true
|
||||||
tmp_path: tmp_path
|
tmp_path: tmp_path
|
||||||
manifest: manifest
|
manifest: manifest
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// VPM registered module.
|
// VPM registered module.
|
||||||
|
@ -170,13 +170,13 @@ fn (mut p Parser) parse_module(m string) {
|
||||||
vmod.Manifest{}
|
vmod.Manifest{}
|
||||||
}
|
}
|
||||||
Module{
|
Module{
|
||||||
name: info.name
|
name: info.name
|
||||||
url: info.url
|
url: info.url
|
||||||
version: version
|
version: version
|
||||||
vcs: vcs
|
vcs: vcs
|
||||||
install_path: os.real_path(os.join_path(settings.vmodules_path, mod_path))
|
install_path: os.real_path(os.join_path(settings.vmodules_path, mod_path))
|
||||||
tmp_path: tmp_path
|
tmp_path: tmp_path
|
||||||
manifest: manifest
|
manifest: manifest
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
mod.install_path_fmted = fmt_mod_path(mod.install_path)
|
mod.install_path_fmted = fmt_mod_path(mod.install_path)
|
||||||
|
|
|
@ -44,16 +44,16 @@ fn init_settings() VpmSettings {
|
||||||
}
|
}
|
||||||
|
|
||||||
return VpmSettings{
|
return VpmSettings{
|
||||||
is_help: '-h' in opts || '--help' in opts || 'help' in cmds
|
is_help: '-h' in opts || '--help' in opts || 'help' in cmds
|
||||||
is_once: '--once' in opts
|
is_once: '--once' in opts
|
||||||
is_verbose: '-v' in opts || '--verbose' in opts
|
is_verbose: '-v' in opts || '--verbose' in opts
|
||||||
is_force: '-f' in opts || '--force' in opts
|
is_force: '-f' in opts || '--force' in opts
|
||||||
server_urls: cmdline.options(args, '--server-urls')
|
server_urls: cmdline.options(args, '--server-urls')
|
||||||
vcs: if '--hg' in opts { .hg } else { .git }
|
vcs: if '--hg' in opts { .hg } else { .git }
|
||||||
vmodules_path: vmodules_path
|
vmodules_path: vmodules_path
|
||||||
tmp_path: os.join_path(os.vtmp_dir(), 'vpm_modules')
|
tmp_path: os.join_path(os.vtmp_dir(), 'vpm_modules')
|
||||||
no_dl_count_increment: is_ci || is_no_inc
|
no_dl_count_increment: is_ci || is_no_inc
|
||||||
fail_on_prompt: os.getenv('VPM_FAIL_ON_PROMPT') != ''
|
fail_on_prompt: os.getenv('VPM_FAIL_ON_PROMPT') != ''
|
||||||
logger: logger
|
logger: logger
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -35,22 +35,22 @@ fn init_vcs_info() !map[VCS]VCSInfo {
|
||||||
}
|
}
|
||||||
return {
|
return {
|
||||||
VCS.git: VCSInfo{
|
VCS.git: VCSInfo{
|
||||||
dir: '.git'
|
dir: '.git'
|
||||||
args: struct {
|
args: struct {
|
||||||
install: git_install_cmd
|
install: git_install_cmd
|
||||||
version: '--single-branch -b'
|
version: '--single-branch -b'
|
||||||
update: 'pull --recurse-submodules' // pulling with `--depth=1` leads to conflicts when the upstream has more than 1 new commits.
|
update: 'pull --recurse-submodules' // pulling with `--depth=1` leads to conflicts when the upstream has more than 1 new commits.
|
||||||
path: '-C'
|
path: '-C'
|
||||||
outdated: ['fetch', 'rev-parse @', 'rev-parse @{u}']
|
outdated: ['fetch', 'rev-parse @', 'rev-parse @{u}']
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
VCS.hg: VCSInfo{
|
VCS.hg: VCSInfo{
|
||||||
dir: '.hg'
|
dir: '.hg'
|
||||||
args: struct {
|
args: struct {
|
||||||
install: 'clone'
|
install: 'clone'
|
||||||
version: '--rev'
|
version: '--rev'
|
||||||
update: 'pull --update'
|
update: 'pull --update'
|
||||||
path: '-R'
|
path: '-R'
|
||||||
outdated: ['incoming']
|
outdated: ['incoming']
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -59,8 +59,8 @@ mut:
|
||||||
fn new_aints(ovals []i64, extreme_mins int, extreme_maxs int) Aints {
|
fn new_aints(ovals []i64, extreme_mins int, extreme_maxs int) Aints {
|
||||||
mut res := Aints{
|
mut res := Aints{
|
||||||
values: ovals // remember the original values
|
values: ovals // remember the original values
|
||||||
nmins: extreme_mins
|
nmins: extreme_mins
|
||||||
nmaxs: extreme_maxs
|
nmaxs: extreme_maxs
|
||||||
}
|
}
|
||||||
// discard the extremes, if needed:
|
// discard the extremes, if needed:
|
||||||
mut vals := []i64{}
|
mut vals := []i64{}
|
||||||
|
|
|
@ -90,8 +90,8 @@ fn new_repl(folder string) Repl {
|
||||||
readline: readline.Readline{
|
readline: readline.Readline{
|
||||||
skip_empty: true
|
skip_empty: true
|
||||||
}
|
}
|
||||||
folder: folder
|
folder: folder
|
||||||
modules: ['os', 'time', 'math']
|
modules: ['os', 'time', 'math']
|
||||||
vstartup_lines: vstartup_source
|
vstartup_lines: vstartup_source
|
||||||
// Test file used to check if a function as a void return or a value return.
|
// Test file used to check if a function as a void return or a value return.
|
||||||
eval_func_lines: vstartup_source
|
eval_func_lines: vstartup_source
|
||||||
|
|
|
@ -84,10 +84,10 @@ fn main() {
|
||||||
fp.skip_executable()
|
fp.skip_executable()
|
||||||
// Collect tool options
|
// Collect tool options
|
||||||
opt := Options{
|
opt := Options{
|
||||||
show_help: fp.bool('help', `h`, false, 'Show this help text.')
|
show_help: fp.bool('help', `h`, false, 'Show this help text.')
|
||||||
force_update: fp.bool('force-update', `u`, false, 'Force update of the sokol-shdc tool.')
|
force_update: fp.bool('force-update', `u`, false, 'Force update of the sokol-shdc tool.')
|
||||||
verbose: fp.bool('verbose', `v`, false, 'Be verbose about the tools progress.')
|
verbose: fp.bool('verbose', `v`, false, 'Be verbose about the tools progress.')
|
||||||
slangs: fp.string_multi('slang', `l`, 'Shader dialects to generate code for. Default is all.\n Available dialects: ${supported_slangs}')
|
slangs: fp.string_multi('slang', `l`, 'Shader dialects to generate code for. Default is all.\n Available dialects: ${supported_slangs}')
|
||||||
}
|
}
|
||||||
if opt.show_help {
|
if opt.show_help {
|
||||||
println(fp.usage())
|
println(fp.usage())
|
||||||
|
@ -161,8 +161,8 @@ fn compile_shaders(opt Options, input_path string) ! {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
co := CompileOptions{
|
co := CompileOptions{
|
||||||
verbose: opt.verbose
|
verbose: opt.verbose
|
||||||
slangs: opt.slangs
|
slangs: opt.slangs
|
||||||
invoke_path: path
|
invoke_path: path
|
||||||
}
|
}
|
||||||
// Currently sokol-shdc allows for multiple --input flags
|
// Currently sokol-shdc allows for multiple --input flags
|
||||||
|
|
|
@ -86,15 +86,15 @@ mut:
|
||||||
fn get_all_commands() []Command {
|
fn get_all_commands() []Command {
|
||||||
mut res := []Command{}
|
mut res := []Command{}
|
||||||
res << Command{
|
res << Command{
|
||||||
line: '${vexe} examples/hello_world.v'
|
line: '${vexe} examples/hello_world.v'
|
||||||
okmsg: 'V can compile hello world.'
|
okmsg: 'V can compile hello world.'
|
||||||
rmfile: 'examples/hello_world'
|
rmfile: 'examples/hello_world'
|
||||||
}
|
}
|
||||||
$if linux {
|
$if linux {
|
||||||
if l2w_crosscc != '' {
|
if l2w_crosscc != '' {
|
||||||
res << Command{
|
res << Command{
|
||||||
line: '${vexe} -os windows examples/hello_world.v'
|
line: '${vexe} -os windows examples/hello_world.v'
|
||||||
okmsg: 'V cross compiles hello_world.v on linux, to a windows .exe file'
|
okmsg: 'V cross compiles hello_world.v on linux, to a windows .exe file'
|
||||||
rmfile: 'examples/hello_world.exe'
|
rmfile: 'examples/hello_world.exe'
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
@ -102,54 +102,54 @@ fn get_all_commands() []Command {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
res << Command{
|
res << Command{
|
||||||
line: '${vexe} -o hhww.c examples/hello_world.v'
|
line: '${vexe} -o hhww.c examples/hello_world.v'
|
||||||
okmsg: 'V can output a .c file, without compiling further.'
|
okmsg: 'V can output a .c file, without compiling further.'
|
||||||
rmfile: 'hhww.c'
|
rmfile: 'hhww.c'
|
||||||
}
|
}
|
||||||
res << Command{
|
res << Command{
|
||||||
line: '${vexe} -skip-unused examples/hello_world.v'
|
line: '${vexe} -skip-unused examples/hello_world.v'
|
||||||
okmsg: 'V can compile hello world with -skip-unused.'
|
okmsg: 'V can compile hello world with -skip-unused.'
|
||||||
rmfile: 'examples/hello_world'
|
rmfile: 'examples/hello_world'
|
||||||
}
|
}
|
||||||
res << Command{
|
res << Command{
|
||||||
line: '${vexe} -skip-unused test vlib/builtin'
|
line: '${vexe} -skip-unused test vlib/builtin'
|
||||||
okmsg: 'V can test vlib/builtin with -skip-unused'
|
okmsg: 'V can test vlib/builtin with -skip-unused'
|
||||||
}
|
}
|
||||||
res << Command{
|
res << Command{
|
||||||
line: '${vexe} -skip-unused -profile - examples/hello_world.v'
|
line: '${vexe} -skip-unused -profile - examples/hello_world.v'
|
||||||
okmsg: 'V can compile hello world with both -skip-unused and -profile .'
|
okmsg: 'V can compile hello world with both -skip-unused and -profile .'
|
||||||
rmfile: 'examples/hello_world'
|
rmfile: 'examples/hello_world'
|
||||||
}
|
}
|
||||||
res << Command{
|
res << Command{
|
||||||
line: '${vexe} -e "print(84/2)"'
|
line: '${vexe} -e "print(84/2)"'
|
||||||
okmsg: 'V can run code given after `-e`'
|
okmsg: 'V can run code given after `-e`'
|
||||||
runcmd: .execute
|
runcmd: .execute
|
||||||
expect: '42'
|
expect: '42'
|
||||||
}
|
}
|
||||||
res << Command{
|
res << Command{
|
||||||
line: '${vexe} -e "import os; import math; print(os.args#[1..]) print(math.sin(math.pi/2).str())" arg1 arg2'
|
line: '${vexe} -e "import os; import math; print(os.args#[1..]) print(math.sin(math.pi/2).str())" arg1 arg2'
|
||||||
okmsg: 'V can run code with `-e`, that use semicolons and several imports, and that accepts CLI parameters.'
|
okmsg: 'V can run code with `-e`, that use semicolons and several imports, and that accepts CLI parameters.'
|
||||||
runcmd: .execute
|
runcmd: .execute
|
||||||
expect: "['arg1', 'arg2']1.0"
|
expect: "['arg1', 'arg2']1.0"
|
||||||
}
|
}
|
||||||
res << Command{
|
res << Command{
|
||||||
line: '${vexe} -o calling_c.exe run examples/call_c_from_v/main.c.v'
|
line: '${vexe} -o calling_c.exe run examples/call_c_from_v/main.c.v'
|
||||||
okmsg: 'V can run main.c.v files'
|
okmsg: 'V can run main.c.v files'
|
||||||
runcmd: .execute
|
runcmd: .execute
|
||||||
contains: 'V can call C functions like `puts` too.'
|
contains: 'V can call C functions like `puts` too.'
|
||||||
}
|
}
|
||||||
$if linux || macos {
|
$if linux || macos {
|
||||||
res << Command{
|
res << Command{
|
||||||
line: '${vexe} run examples/hello_world.v'
|
line: '${vexe} run examples/hello_world.v'
|
||||||
okmsg: 'V can run hello world.'
|
okmsg: 'V can run hello world.'
|
||||||
runcmd: .execute
|
runcmd: .execute
|
||||||
expect: 'Hello, World!\n'
|
expect: 'Hello, World!\n'
|
||||||
}
|
}
|
||||||
if clang_path != '' {
|
if clang_path != '' {
|
||||||
res << Command{
|
res << Command{
|
||||||
line: '${vexe} -os freebsd -gc none examples/hello_world.v'
|
line: '${vexe} -os freebsd -gc none examples/hello_world.v'
|
||||||
okmsg: 'V cross compiles hello_world.v, to a FreeBSD executable'
|
okmsg: 'V cross compiles hello_world.v, to a FreeBSD executable'
|
||||||
rmfile: 'examples/hello_world'
|
rmfile: 'examples/hello_world'
|
||||||
after_cb: fn () ! {
|
after_cb: fn () ! {
|
||||||
for file in ['examples/hello_world',
|
for file in ['examples/hello_world',
|
||||||
os.join_path(os.vmodules_dir(), 'freebsdroot/usr/include/stdio.h')] {
|
os.join_path(os.vmodules_dir(), 'freebsdroot/usr/include/stdio.h')] {
|
||||||
|
@ -166,8 +166,8 @@ fn get_all_commands() []Command {
|
||||||
for compiler_name in ['clang', 'gcc'] {
|
for compiler_name in ['clang', 'gcc'] {
|
||||||
if _ := os.find_abs_path_of_executable(compiler_name) {
|
if _ := os.find_abs_path_of_executable(compiler_name) {
|
||||||
res << Command{
|
res << Command{
|
||||||
line: '${vexe} -cc ${compiler_name} -gc boehm run examples/hello_world.v'
|
line: '${vexe} -cc ${compiler_name} -gc boehm run examples/hello_world.v'
|
||||||
okmsg: '`v -cc ${compiler_name} -gc boehm run examples/hello_world.v` works'
|
okmsg: '`v -cc ${compiler_name} -gc boehm run examples/hello_world.v` works'
|
||||||
runcmd: .execute
|
runcmd: .execute
|
||||||
expect: 'Hello, World!\n'
|
expect: 'Hello, World!\n'
|
||||||
}
|
}
|
||||||
|
@ -175,25 +175,25 @@ fn get_all_commands() []Command {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
res << Command{
|
res << Command{
|
||||||
line: '${vexe} interpret examples/hello_world.v'
|
line: '${vexe} interpret examples/hello_world.v'
|
||||||
okmsg: 'V can interpret hello world.'
|
okmsg: 'V can interpret hello world.'
|
||||||
runcmd: .execute
|
runcmd: .execute
|
||||||
expect: 'Hello, World!\n'
|
expect: 'Hello, World!\n'
|
||||||
}
|
}
|
||||||
res << Command{
|
res << Command{
|
||||||
line: '${vexe} interpret examples/hanoi.v'
|
line: '${vexe} interpret examples/hanoi.v'
|
||||||
okmsg: 'V can interpret hanoi.v'
|
okmsg: 'V can interpret hanoi.v'
|
||||||
runcmd: .execute
|
runcmd: .execute
|
||||||
starts_with: 'Disc 1 from A to C...\n'
|
starts_with: 'Disc 1 from A to C...\n'
|
||||||
ends_with: 'Disc 1 from A to C...\n'
|
ends_with: 'Disc 1 from A to C...\n'
|
||||||
contains: 'Disc 7 from A to C...\n'
|
contains: 'Disc 7 from A to C...\n'
|
||||||
}
|
}
|
||||||
res << Command{
|
res << Command{
|
||||||
line: '${vexe} -o - examples/hello_world.v | grep "#define V_COMMIT_HASH" > /dev/null'
|
line: '${vexe} -o - examples/hello_world.v | grep "#define V_COMMIT_HASH" > /dev/null'
|
||||||
okmsg: 'V prints the generated source code to stdout with `-o -` .'
|
okmsg: 'V prints the generated source code to stdout with `-o -` .'
|
||||||
}
|
}
|
||||||
res << Command{
|
res << Command{
|
||||||
line: '${vexe} run examples/v_script.vsh > /dev/null'
|
line: '${vexe} run examples/v_script.vsh > /dev/null'
|
||||||
okmsg: 'V can run the .VSH script file examples/v_script.vsh'
|
okmsg: 'V can run the .VSH script file examples/v_script.vsh'
|
||||||
}
|
}
|
||||||
// Note: -experimental is used here, just to suppress the warnings,
|
// Note: -experimental is used here, just to suppress the warnings,
|
||||||
|
@ -201,13 +201,13 @@ fn get_all_commands() []Command {
|
||||||
// until globals and hash statements *are implemented*:
|
// until globals and hash statements *are implemented*:
|
||||||
$if linux {
|
$if linux {
|
||||||
res << Command{
|
res << Command{
|
||||||
line: '${vexe} -experimental -b native run examples/native/hello_world.v > /dev/null'
|
line: '${vexe} -experimental -b native run examples/native/hello_world.v > /dev/null'
|
||||||
okmsg: 'V compiles and runs examples/native/hello_world.v on the native backend for linux'
|
okmsg: 'V compiles and runs examples/native/hello_world.v on the native backend for linux'
|
||||||
}
|
}
|
||||||
res << Command{
|
res << Command{
|
||||||
line: '${vexe} -no-builtin -experimental -b native examples/hello_world.v > /dev/null'
|
line: '${vexe} -no-builtin -experimental -b native examples/hello_world.v > /dev/null'
|
||||||
okmsg: 'V compiles examples/hello_world.v on the native backend for linux with `-no-builtin` & the executable is <= ${hw_native_no_builtin_size_limit} bytes'
|
okmsg: 'V compiles examples/hello_world.v on the native backend for linux with `-no-builtin` & the executable is <= ${hw_native_no_builtin_size_limit} bytes'
|
||||||
rmfile: 'examples/hello_world'
|
rmfile: 'examples/hello_world'
|
||||||
after_cb: fn () ! {
|
after_cb: fn () ! {
|
||||||
file := 'examples/hello_world'
|
file := 'examples/hello_world'
|
||||||
if !os.exists(file) {
|
if !os.exists(file) {
|
||||||
|
@ -221,88 +221,88 @@ fn get_all_commands() []Command {
|
||||||
}
|
}
|
||||||
// only compilation:
|
// only compilation:
|
||||||
res << Command{
|
res << Command{
|
||||||
line: '${vexe} -os linux -experimental -b native -o hw.linux examples/hello_world.v'
|
line: '${vexe} -os linux -experimental -b native -o hw.linux examples/hello_world.v'
|
||||||
okmsg: 'V compiles hello_world.v on the native backend for linux'
|
okmsg: 'V compiles hello_world.v on the native backend for linux'
|
||||||
rmfile: 'hw.linux'
|
rmfile: 'hw.linux'
|
||||||
}
|
}
|
||||||
res << Command{
|
res << Command{
|
||||||
line: '${vexe} -os macos -experimental -b native -o hw.macos examples/hello_world.v'
|
line: '${vexe} -os macos -experimental -b native -o hw.macos examples/hello_world.v'
|
||||||
okmsg: 'V compiles hello_world.v on the native backend for macos'
|
okmsg: 'V compiles hello_world.v on the native backend for macos'
|
||||||
rmfile: 'hw.macos'
|
rmfile: 'hw.macos'
|
||||||
}
|
}
|
||||||
$if windows {
|
$if windows {
|
||||||
res << Command{
|
res << Command{
|
||||||
line: '${vexe} -os windows -experimental -b native -o hw.exe examples/hello_world.v'
|
line: '${vexe} -os windows -experimental -b native -o hw.exe examples/hello_world.v'
|
||||||
okmsg: 'V compiles hello_world.v on the native backend for windows'
|
okmsg: 'V compiles hello_world.v on the native backend for windows'
|
||||||
rmfile: 'hw.exe'
|
rmfile: 'hw.exe'
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
//
|
//
|
||||||
res << Command{
|
res << Command{
|
||||||
line: '${vexe} -b js -o hw.js examples/hello_world.v'
|
line: '${vexe} -b js -o hw.js examples/hello_world.v'
|
||||||
okmsg: 'V compiles hello_world.v on the JS backend'
|
okmsg: 'V compiles hello_world.v on the JS backend'
|
||||||
rmfile: 'hw.js'
|
rmfile: 'hw.js'
|
||||||
}
|
}
|
||||||
res << Command{
|
res << Command{
|
||||||
line: '${vexe} -skip-unused -b js -o hw_skip_unused.js examples/hello_world.v'
|
line: '${vexe} -skip-unused -b js -o hw_skip_unused.js examples/hello_world.v'
|
||||||
okmsg: 'V compiles hello_world.v on the JS backend, with -skip-unused'
|
okmsg: 'V compiles hello_world.v on the JS backend, with -skip-unused'
|
||||||
rmfile: 'hw_skip_unused.js'
|
rmfile: 'hw_skip_unused.js'
|
||||||
}
|
}
|
||||||
res << Command{
|
res << Command{
|
||||||
line: '${vexe} -skip-unused examples/2048'
|
line: '${vexe} -skip-unused examples/2048'
|
||||||
okmsg: 'V can compile 2048 with -skip-unused.'
|
okmsg: 'V can compile 2048 with -skip-unused.'
|
||||||
rmfile: 'examples/2048/2048'
|
rmfile: 'examples/2048/2048'
|
||||||
}
|
}
|
||||||
if _ := os.find_abs_path_of_executable('emcc') {
|
if _ := os.find_abs_path_of_executable('emcc') {
|
||||||
res << Command{
|
res << Command{
|
||||||
line: '${vexe} -os wasm32_emscripten examples/2048'
|
line: '${vexe} -os wasm32_emscripten examples/2048'
|
||||||
okmsg: 'V can compile 2048 with -os wasm32_emscripten, using emcc.'
|
okmsg: 'V can compile 2048 with -os wasm32_emscripten, using emcc.'
|
||||||
rmfile: 'examples/2048/2048'
|
rmfile: 'examples/2048/2048'
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
println('> emcc not found, skipping `v -os wasm32_emscripten examples/2048`.')
|
println('> emcc not found, skipping `v -os wasm32_emscripten examples/2048`.')
|
||||||
}
|
}
|
||||||
res << Command{
|
res << Command{
|
||||||
line: '${vexe} -skip-unused -live examples/hot_reload/bounce.v'
|
line: '${vexe} -skip-unused -live examples/hot_reload/bounce.v'
|
||||||
okmsg: 'V can compile the hot code reloading bounce.v example with both: -skip-unused -live'
|
okmsg: 'V can compile the hot code reloading bounce.v example with both: -skip-unused -live'
|
||||||
rmfile: 'examples/hot_reload/bounce'
|
rmfile: 'examples/hot_reload/bounce'
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
res << Command{
|
res << Command{
|
||||||
line: '${vexe} -o vtmp cmd/v'
|
line: '${vexe} -o vtmp cmd/v'
|
||||||
okmsg: 'V can compile itself.'
|
okmsg: 'V can compile itself.'
|
||||||
rmfile: 'vtmp'
|
rmfile: 'vtmp'
|
||||||
}
|
}
|
||||||
res << Command{
|
res << Command{
|
||||||
line: '${vexe} -o vtmp_werror -cstrict cmd/v'
|
line: '${vexe} -o vtmp_werror -cstrict cmd/v'
|
||||||
okmsg: 'V can compile itself with -cstrict.'
|
okmsg: 'V can compile itself with -cstrict.'
|
||||||
rmfile: 'vtmp_werror'
|
rmfile: 'vtmp_werror'
|
||||||
}
|
}
|
||||||
res << Command{
|
res << Command{
|
||||||
line: '${vexe} -o vtmp_autofree -autofree cmd/v'
|
line: '${vexe} -o vtmp_autofree -autofree cmd/v'
|
||||||
okmsg: 'V can compile itself with -autofree.'
|
okmsg: 'V can compile itself with -autofree.'
|
||||||
rmfile: 'vtmp_autofree'
|
rmfile: 'vtmp_autofree'
|
||||||
}
|
}
|
||||||
res << Command{
|
res << Command{
|
||||||
line: '${vexe} -o vtmp_prealloc -prealloc cmd/v'
|
line: '${vexe} -o vtmp_prealloc -prealloc cmd/v'
|
||||||
okmsg: 'V can compile itself with -prealloc.'
|
okmsg: 'V can compile itself with -prealloc.'
|
||||||
rmfile: 'vtmp_prealloc'
|
rmfile: 'vtmp_prealloc'
|
||||||
}
|
}
|
||||||
res << Command{
|
res << Command{
|
||||||
line: '${vexe} -o vtmp_unused -skip-unused cmd/v'
|
line: '${vexe} -o vtmp_unused -skip-unused cmd/v'
|
||||||
okmsg: 'V can compile itself with -skip-unused.'
|
okmsg: 'V can compile itself with -skip-unused.'
|
||||||
rmfile: 'vtmp_unused'
|
rmfile: 'vtmp_unused'
|
||||||
}
|
}
|
||||||
$if linux {
|
$if linux {
|
||||||
res << Command{
|
res << Command{
|
||||||
line: '${vexe} -cc gcc -keepc -freestanding -o bel vlib/os/bare/bare_example_linux.v'
|
line: '${vexe} -cc gcc -keepc -freestanding -o bel vlib/os/bare/bare_example_linux.v'
|
||||||
okmsg: 'V can compile with -freestanding on Linux with GCC.'
|
okmsg: 'V can compile with -freestanding on Linux with GCC.'
|
||||||
rmfile: 'bel'
|
rmfile: 'bel'
|
||||||
}
|
}
|
||||||
|
|
||||||
res << Command{
|
res << Command{
|
||||||
line: '${vexe} -cc gcc -keepc -freestanding -o str_array vlib/strconv/bare/str_array_example.v'
|
line: '${vexe} -cc gcc -keepc -freestanding -o str_array vlib/strconv/bare/str_array_example.v'
|
||||||
okmsg: 'V can compile & allocate memory with -freestanding on Linux with GCC.'
|
okmsg: 'V can compile & allocate memory with -freestanding on Linux with GCC.'
|
||||||
rmfile: 'str_array'
|
rmfile: 'str_array'
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -311,15 +311,15 @@ fn get_all_commands() []Command {
|
||||||
common_shared_flags := '-shared -skip-unused -d no_backtrace -o library examples/dynamic_library_loader/modules/library/library.v'
|
common_shared_flags := '-shared -skip-unused -d no_backtrace -o library examples/dynamic_library_loader/modules/library/library.v'
|
||||||
$if macos {
|
$if macos {
|
||||||
res << Command{
|
res << Command{
|
||||||
line: '${vexe} ${common_shared_flags}'
|
line: '${vexe} ${common_shared_flags}'
|
||||||
okmsg: 'V compiles library.v with -shared on macos'
|
okmsg: 'V compiles library.v with -shared on macos'
|
||||||
rmfile: 'library.dylib'
|
rmfile: 'library.dylib'
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
$if linux {
|
$if linux {
|
||||||
res << Command{
|
res << Command{
|
||||||
line: '${vexe} ${common_shared_flags}'
|
line: '${vexe} ${common_shared_flags}'
|
||||||
okmsg: 'V compiles library.v with -shared on linux'
|
okmsg: 'V compiles library.v with -shared on linux'
|
||||||
rmfile: 'library.so'
|
rmfile: 'library.so'
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -327,8 +327,8 @@ fn get_all_commands() []Command {
|
||||||
$if linux {
|
$if linux {
|
||||||
if l2w_crosscc != '' {
|
if l2w_crosscc != '' {
|
||||||
res << Command{
|
res << Command{
|
||||||
line: '${vexe} -os windows ${common_shared_flags}'
|
line: '${vexe} -os windows ${common_shared_flags}'
|
||||||
okmsg: 'V cross compiles library.v with -shared on linux, to a windows library.dll file'
|
okmsg: 'V cross compiles library.v with -shared on linux, to a windows library.dll file'
|
||||||
rmfile: 'library.dll'
|
rmfile: 'library.dll'
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
@ -337,92 +337,92 @@ fn get_all_commands() []Command {
|
||||||
}
|
}
|
||||||
////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////
|
||||||
res << Command{
|
res << Command{
|
||||||
line: '${vexe} ${vargs} -progress test-cleancode'
|
line: '${vexe} ${vargs} -progress test-cleancode'
|
||||||
okmsg: 'All .v files are invariant when processed with `v fmt`'
|
okmsg: 'All .v files are invariant when processed with `v fmt`'
|
||||||
}
|
}
|
||||||
res << Command{
|
res << Command{
|
||||||
line: '${vexe} ${vargs} -progress test-fmt'
|
line: '${vexe} ${vargs} -progress test-fmt'
|
||||||
okmsg: 'All .v files can be processed with `v fmt`. Note: the result may not always be compilable, but `v fmt` should not crash.'
|
okmsg: 'All .v files can be processed with `v fmt`. Note: the result may not always be compilable, but `v fmt` should not crash.'
|
||||||
}
|
}
|
||||||
res << Command{
|
res << Command{
|
||||||
line: '${vexe} ${vargs} -progress test-self'
|
line: '${vexe} ${vargs} -progress test-self'
|
||||||
okmsg: 'There are no _test.v file regressions.'
|
okmsg: 'There are no _test.v file regressions.'
|
||||||
}
|
}
|
||||||
res << Command{
|
res << Command{
|
||||||
line: '${vexe} ${vargs} -progress -N -W build-tools'
|
line: '${vexe} ${vargs} -progress -N -W build-tools'
|
||||||
okmsg: 'All tools can be compiled.'
|
okmsg: 'All tools can be compiled.'
|
||||||
}
|
}
|
||||||
res << Command{
|
res << Command{
|
||||||
line: '${vexe} ${vargs} -progress -N -W build-examples'
|
line: '${vexe} ${vargs} -progress -N -W build-examples'
|
||||||
okmsg: 'All examples can be compiled.'
|
okmsg: 'All examples can be compiled.'
|
||||||
}
|
}
|
||||||
res << Command{
|
res << Command{
|
||||||
line: '${vexe} check-md -hide-warnings .'
|
line: '${vexe} check-md -hide-warnings .'
|
||||||
label: 'Check ```v ``` code examples and formatting of .MD files...'
|
label: 'Check ```v ``` code examples and formatting of .MD files...'
|
||||||
okmsg: 'All .md files look good.'
|
okmsg: 'All .md files look good.'
|
||||||
}
|
}
|
||||||
res << Command{
|
res << Command{
|
||||||
line: '${vexe} install nedpals.args'
|
line: '${vexe} install nedpals.args'
|
||||||
okmsg: '`v install` works.'
|
okmsg: '`v install` works.'
|
||||||
}
|
}
|
||||||
res << Command{
|
res << Command{
|
||||||
okmsg: 'Running net.http with -d trace_http_request works.'
|
okmsg: 'Running net.http with -d trace_http_request works.'
|
||||||
line: '${vexe} -d trace_http_request -e \'import net.http; x := http.fetch(url: "https://vpm.url4e.com/some/unknown/url")!; println(x.status_code)\''
|
line: '${vexe} -d trace_http_request -e \'import net.http; x := http.fetch(url: "https://vpm.url4e.com/some/unknown/url")!; println(x.status_code)\''
|
||||||
runcmd: .execute
|
runcmd: .execute
|
||||||
starts_with: '> GET /some/unknown/url HTTP/1.1'
|
starts_with: '> GET /some/unknown/url HTTP/1.1'
|
||||||
contains: 'User-Agent: v.http'
|
contains: 'User-Agent: v.http'
|
||||||
ends_with: '404\n'
|
ends_with: '404\n'
|
||||||
}
|
}
|
||||||
res << Command{
|
res << Command{
|
||||||
okmsg: 'Running net.http with -d trace_http_response works.'
|
okmsg: 'Running net.http with -d trace_http_response works.'
|
||||||
line: '${vexe} -d trace_http_response -e \'import net.http; x := http.fetch(url: "https://vpm.url4e.com/some/unknown/url")!; println(x.status_code)\''
|
line: '${vexe} -d trace_http_response -e \'import net.http; x := http.fetch(url: "https://vpm.url4e.com/some/unknown/url")!; println(x.status_code)\''
|
||||||
runcmd: .execute
|
runcmd: .execute
|
||||||
starts_with: '< HTTP/1.1 404 Not Found'
|
starts_with: '< HTTP/1.1 404 Not Found'
|
||||||
contains: 'Server: nginx'
|
contains: 'Server: nginx'
|
||||||
ends_with: '404\n'
|
ends_with: '404\n'
|
||||||
}
|
}
|
||||||
res << Command{
|
res << Command{
|
||||||
line: '${vexe} -usecache -cg examples/hello_world.v'
|
line: '${vexe} -usecache -cg examples/hello_world.v'
|
||||||
okmsg: '`v -usecache -cg` works.'
|
okmsg: '`v -usecache -cg` works.'
|
||||||
rmfile: 'examples/hello_world'
|
rmfile: 'examples/hello_world'
|
||||||
}
|
}
|
||||||
// Note: test that a program that depends on thirdparty libraries with its
|
// Note: test that a program that depends on thirdparty libraries with its
|
||||||
// own #flags (tetris depends on gg, which uses sokol) can be compiled
|
// own #flags (tetris depends on gg, which uses sokol) can be compiled
|
||||||
// with -usecache:
|
// with -usecache:
|
||||||
res << Command{
|
res << Command{
|
||||||
line: '${vexe} -usecache examples/tetris/tetris.v'
|
line: '${vexe} -usecache examples/tetris/tetris.v'
|
||||||
okmsg: '`v -usecache` works.'
|
okmsg: '`v -usecache` works.'
|
||||||
rmfile: 'examples/tetris/tetris'
|
rmfile: 'examples/tetris/tetris'
|
||||||
}
|
}
|
||||||
$if macos || linux {
|
$if macos || linux {
|
||||||
res << Command{
|
res << Command{
|
||||||
line: '${vexe} -o v.c cmd/v && cc -Werror v.c -lpthread -lm && rm -rf a.out'
|
line: '${vexe} -o v.c cmd/v && cc -Werror v.c -lpthread -lm && rm -rf a.out'
|
||||||
label: 'v.c should be buildable with no warnings...'
|
label: 'v.c should be buildable with no warnings...'
|
||||||
okmsg: 'v.c can be compiled without warnings. This is good :)'
|
okmsg: 'v.c can be compiled without warnings. This is good :)'
|
||||||
rmfile: 'v.c'
|
rmfile: 'v.c'
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
$if linux {
|
$if linux {
|
||||||
res << Command{
|
res << Command{
|
||||||
line: '${vexe} vlib/v/tests/bench/bench_stbi_load.v && prlimit -v10485760 vlib/v/tests/bench/bench_stbi_load'
|
line: '${vexe} vlib/v/tests/bench/bench_stbi_load.v && prlimit -v10485760 vlib/v/tests/bench/bench_stbi_load'
|
||||||
okmsg: 'STBI load does not leak with GC on, when loading images multiple times (use < 10MB)'
|
okmsg: 'STBI load does not leak with GC on, when loading images multiple times (use < 10MB)'
|
||||||
runcmd: .execute
|
runcmd: .execute
|
||||||
contains: 'logo.png 1000 times.'
|
contains: 'logo.png 1000 times.'
|
||||||
rmfile: 'vlib/v/tests/bench/bench_stbi_load'
|
rmfile: 'vlib/v/tests/bench/bench_stbi_load'
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
$if !windows {
|
$if !windows {
|
||||||
res << Command{
|
res << Command{
|
||||||
line: '${vexe} -raw-vsh-tmp-prefix tmp vlib/v/tests/script_with_no_extension'
|
line: '${vexe} -raw-vsh-tmp-prefix tmp vlib/v/tests/script_with_no_extension'
|
||||||
okmsg: 'V can crun a script, that lacks a .vsh extension'
|
okmsg: 'V can crun a script, that lacks a .vsh extension'
|
||||||
runcmd: .execute
|
runcmd: .execute
|
||||||
expect: 'Test\n'
|
expect: 'Test\n'
|
||||||
rmfile: 'vlib/v/tests/tmp.script_with_no_extension'
|
rmfile: 'vlib/v/tests/tmp.script_with_no_extension'
|
||||||
}
|
}
|
||||||
|
|
||||||
res << Command{
|
res << Command{
|
||||||
line: '${vexe} -raw-vsh-tmp-prefix tmp run vlib/v/tests/script_with_no_extension'
|
line: '${vexe} -raw-vsh-tmp-prefix tmp run vlib/v/tests/script_with_no_extension'
|
||||||
okmsg: 'V can run a script, that lacks a .vsh extension'
|
okmsg: 'V can run a script, that lacks a .vsh extension'
|
||||||
runcmd: .execute
|
runcmd: .execute
|
||||||
expect: 'Test\n'
|
expect: 'Test\n'
|
||||||
}
|
}
|
||||||
|
|
|
@ -20,11 +20,11 @@ struct App {
|
||||||
|
|
||||||
fn new_app() App {
|
fn new_app() App {
|
||||||
return App{
|
return App{
|
||||||
is_verbose: '-v' in os.args
|
is_verbose: '-v' in os.args
|
||||||
is_prod: '-prod' in os.args
|
is_prod: '-prod' in os.args
|
||||||
vexe: vexe
|
vexe: vexe
|
||||||
vroot: vroot
|
vroot: vroot
|
||||||
skip_v_self: '-skip_v_self' in os.args
|
skip_v_self: '-skip_v_self' in os.args
|
||||||
skip_current: '-skip_current' in os.args
|
skip_current: '-skip_current' in os.args
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -41,12 +41,12 @@ fn (mut vt Vet) error(msg string, line int, fix FixKind) {
|
||||||
line_nr: line + 1
|
line_nr: line + 1
|
||||||
}
|
}
|
||||||
vt.errors << VetError{
|
vt.errors << VetError{
|
||||||
message: msg
|
message: msg
|
||||||
file_path: vt.file
|
file_path: vt.file
|
||||||
pos: pos
|
pos: pos
|
||||||
kind: .error
|
kind: .error
|
||||||
fix: fix
|
fix: fix
|
||||||
typ: .default
|
typ: .default
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -55,12 +55,12 @@ fn (mut vt Vet) warn(msg string, line int, fix FixKind) {
|
||||||
line_nr: line + 1
|
line_nr: line + 1
|
||||||
}
|
}
|
||||||
mut w := VetError{
|
mut w := VetError{
|
||||||
message: msg
|
message: msg
|
||||||
file_path: vt.file
|
file_path: vt.file
|
||||||
pos: pos
|
pos: pos
|
||||||
kind: .warning
|
kind: .warning
|
||||||
fix: fix
|
fix: fix
|
||||||
typ: .default
|
typ: .default
|
||||||
}
|
}
|
||||||
if vt.opt.is_werror {
|
if vt.opt.is_werror {
|
||||||
w.kind = .error
|
w.kind = .error
|
||||||
|
@ -75,12 +75,12 @@ fn (mut vt Vet) notice(msg string, line int, fix FixKind) {
|
||||||
line_nr: line + 1
|
line_nr: line + 1
|
||||||
}
|
}
|
||||||
vt.notices << VetError{
|
vt.notices << VetError{
|
||||||
message: msg
|
message: msg
|
||||||
file_path: vt.file
|
file_path: vt.file
|
||||||
pos: pos
|
pos: pos
|
||||||
kind: .notice
|
kind: .notice
|
||||||
fix: fix
|
fix: fix
|
||||||
typ: .default
|
typ: .default
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -39,11 +39,12 @@ fn main() {
|
||||||
vet_options := cmdline.options_after(os.args, ['vet'])
|
vet_options := cmdline.options_after(os.args, ['vet'])
|
||||||
mut vt := Vet{
|
mut vt := Vet{
|
||||||
opt: Options{
|
opt: Options{
|
||||||
is_werror: '-W' in vet_options
|
is_werror: '-W' in vet_options
|
||||||
is_verbose: '-verbose' in vet_options || '-v' in vet_options
|
is_verbose: '-verbose' in vet_options || '-v' in vet_options
|
||||||
show_warnings: '-hide-warnings' !in vet_options && '-w' !in vet_options
|
show_warnings: '-hide-warnings' !in vet_options && '-w' !in vet_options
|
||||||
use_color: '-color' in vet_options || (term_colors && '-nocolor' !in vet_options)
|
|
||||||
doc_private_fns_too: '-p' in vet_options
|
doc_private_fns_too: '-p' in vet_options
|
||||||
|
use_color: '-color' in vet_options
|
||||||
|
|| (term_colors && '-nocolor' !in vet_options)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
mut paths := cmdline.only_non_options(vet_options)
|
mut paths := cmdline.only_non_options(vet_options)
|
||||||
|
|
32
doc/docs.md
32
doc/docs.md
|
@ -1600,9 +1600,9 @@ fn (mut t MyTime) century() int {
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
mut my_time := MyTime{
|
mut my_time := MyTime{
|
||||||
year: 2020
|
year: 2020
|
||||||
month: 12
|
month: 12
|
||||||
day: 25
|
day: 25
|
||||||
}
|
}
|
||||||
println(time.new(my_time).utc_string())
|
println(time.new(my_time).utc_string())
|
||||||
println('Century: ${my_time.century()}')
|
println('Century: ${my_time.century()}')
|
||||||
|
@ -2436,7 +2436,7 @@ fn register(u User) User {
|
||||||
|
|
||||||
mut user := User{
|
mut user := User{
|
||||||
name: 'abc'
|
name: 'abc'
|
||||||
age: 23
|
age: 23
|
||||||
}
|
}
|
||||||
user = register(user)
|
user = register(user)
|
||||||
println(user)
|
println(user)
|
||||||
|
@ -2464,9 +2464,9 @@ struct Button {
|
||||||
|
|
||||||
fn new_button(c ButtonConfig) &Button {
|
fn new_button(c ButtonConfig) &Button {
|
||||||
return &Button{
|
return &Button{
|
||||||
width: c.width
|
width: c.width
|
||||||
height: c.height
|
height: c.height
|
||||||
text: c.text
|
text: c.text
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2535,7 +2535,7 @@ struct Book {
|
||||||
book := Book{
|
book := Book{
|
||||||
author: struct {
|
author: struct {
|
||||||
name: 'Samantha Black'
|
name: 'Samantha Black'
|
||||||
age: 24
|
age: 24
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
assert book.author.name == 'Samantha Black'
|
assert book.author.name == 'Samantha Black'
|
||||||
|
@ -2666,7 +2666,7 @@ the struct `Size`, which allows you to do:
|
||||||
|
|
||||||
```v oksyntax
|
```v oksyntax
|
||||||
mut button := Button{
|
mut button := Button{
|
||||||
title: 'Click me'
|
title: 'Click me'
|
||||||
height: 2
|
height: 2
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2701,7 +2701,7 @@ You can also initialize an embedded struct:
|
||||||
```v oksyntax
|
```v oksyntax
|
||||||
mut button := Button{
|
mut button := Button{
|
||||||
Size: Size{
|
Size: Size{
|
||||||
width: 3
|
width: 3
|
||||||
height: 2
|
height: 2
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -2711,7 +2711,7 @@ or assign values:
|
||||||
|
|
||||||
```v oksyntax
|
```v oksyntax
|
||||||
button.Size = Size{
|
button.Size = Size{
|
||||||
width: 4
|
width: 4
|
||||||
height: 5
|
height: 5
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
@ -4588,7 +4588,7 @@ struct User {
|
||||||
|
|
||||||
mut data := map[string]int{}
|
mut data := map[string]int{}
|
||||||
user := &User{
|
user := &User{
|
||||||
name: 'Pierre'
|
name: 'Pierre'
|
||||||
score: 1024
|
score: 1024
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -5157,8 +5157,8 @@ sql db {
|
||||||
|
|
||||||
// insert a new customer:
|
// insert a new customer:
|
||||||
new_customer := Customer{
|
new_customer := Customer{
|
||||||
name: 'Bob'
|
name: 'Bob'
|
||||||
country: 'uk'
|
country: 'uk'
|
||||||
nr_orders: 10
|
nr_orders: 10
|
||||||
}
|
}
|
||||||
sql db {
|
sql db {
|
||||||
|
@ -5166,8 +5166,8 @@ sql db {
|
||||||
}!
|
}!
|
||||||
|
|
||||||
us_customer := Customer{
|
us_customer := Customer{
|
||||||
name: 'Martin'
|
name: 'Martin'
|
||||||
country: 'us'
|
country: 'us'
|
||||||
nr_orders: 5
|
nr_orders: 5
|
||||||
}
|
}
|
||||||
sql db {
|
sql db {
|
||||||
|
@ -5175,8 +5175,8 @@ sql db {
|
||||||
}!
|
}!
|
||||||
|
|
||||||
none_country_customer := Customer{
|
none_country_customer := Customer{
|
||||||
name: 'Dennis'
|
name: 'Dennis'
|
||||||
country: none
|
country: none
|
||||||
nr_orders: 2
|
nr_orders: 2
|
||||||
}
|
}
|
||||||
sql db {
|
sql db {
|
||||||
|
|
|
@ -48,12 +48,12 @@ struct Theme {
|
||||||
|
|
||||||
const themes = [
|
const themes = [
|
||||||
&Theme{
|
&Theme{
|
||||||
bg_color: gx.rgb(250, 248, 239)
|
bg_color: gx.rgb(250, 248, 239)
|
||||||
padding_color: gx.rgb(143, 130, 119)
|
padding_color: gx.rgb(143, 130, 119)
|
||||||
victory_color: gx.rgb(100, 160, 100)
|
victory_color: gx.rgb(100, 160, 100)
|
||||||
game_over_color: gx.rgb(190, 50, 50)
|
game_over_color: gx.rgb(190, 50, 50)
|
||||||
text_color: gx.black
|
text_color: gx.black
|
||||||
tile_colors: [
|
tile_colors: [
|
||||||
gx.rgb(205, 193, 180), // Empty / 0 tile
|
gx.rgb(205, 193, 180), // Empty / 0 tile
|
||||||
gx.rgb(238, 228, 218), // 2
|
gx.rgb(238, 228, 218), // 2
|
||||||
gx.rgb(237, 224, 200), // 4
|
gx.rgb(237, 224, 200), // 4
|
||||||
|
@ -69,12 +69,12 @@ const themes = [
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
&Theme{
|
&Theme{
|
||||||
bg_color: gx.rgb(55, 55, 55)
|
bg_color: gx.rgb(55, 55, 55)
|
||||||
padding_color: gx.rgb(68, 60, 59)
|
padding_color: gx.rgb(68, 60, 59)
|
||||||
victory_color: gx.rgb(100, 160, 100)
|
victory_color: gx.rgb(100, 160, 100)
|
||||||
game_over_color: gx.rgb(190, 50, 50)
|
game_over_color: gx.rgb(190, 50, 50)
|
||||||
text_color: gx.white
|
text_color: gx.white
|
||||||
tile_colors: [
|
tile_colors: [
|
||||||
gx.rgb(123, 115, 108),
|
gx.rgb(123, 115, 108),
|
||||||
gx.rgb(142, 136, 130),
|
gx.rgb(142, 136, 130),
|
||||||
gx.rgb(142, 134, 120),
|
gx.rgb(142, 134, 120),
|
||||||
|
@ -90,12 +90,12 @@ const themes = [
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
&Theme{
|
&Theme{
|
||||||
bg_color: gx.rgb(38, 38, 66)
|
bg_color: gx.rgb(38, 38, 66)
|
||||||
padding_color: gx.rgb(58, 50, 74)
|
padding_color: gx.rgb(58, 50, 74)
|
||||||
victory_color: gx.rgb(100, 160, 100)
|
victory_color: gx.rgb(100, 160, 100)
|
||||||
game_over_color: gx.rgb(190, 50, 50)
|
game_over_color: gx.rgb(190, 50, 50)
|
||||||
text_color: gx.white
|
text_color: gx.white
|
||||||
tile_colors: [
|
tile_colors: [
|
||||||
gx.rgb(92, 86, 140),
|
gx.rgb(92, 86, 140),
|
||||||
gx.rgb(106, 99, 169),
|
gx.rgb(106, 99, 169),
|
||||||
gx.rgb(106, 97, 156),
|
gx.rgb(106, 97, 156),
|
||||||
|
@ -489,56 +489,56 @@ fn (app &App) label_format(kind LabelKind) gx.TextCfg {
|
||||||
match kind {
|
match kind {
|
||||||
.keys {
|
.keys {
|
||||||
return gx.TextCfg{
|
return gx.TextCfg{
|
||||||
color: gx.Color{150, 150, 255, 200}
|
color: gx.Color{150, 150, 255, 200}
|
||||||
align: .center
|
align: .center
|
||||||
vertical_align: .bottom
|
vertical_align: .bottom
|
||||||
size: app.ui.font_size / 4
|
size: app.ui.font_size / 4
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
.points {
|
.points {
|
||||||
return gx.TextCfg{
|
return gx.TextCfg{
|
||||||
color: if app.state in [.over, .victory] { gx.white } else { app.theme.text_color }
|
color: if app.state in [.over, .victory] { gx.white } else { app.theme.text_color }
|
||||||
align: .left
|
align: .left
|
||||||
size: app.ui.font_size / 2
|
size: app.ui.font_size / 2
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
.moves {
|
.moves {
|
||||||
return gx.TextCfg{
|
return gx.TextCfg{
|
||||||
color: if app.state in [.over, .victory] { gx.white } else { app.theme.text_color }
|
color: if app.state in [.over, .victory] { gx.white } else { app.theme.text_color }
|
||||||
align: .right
|
align: .right
|
||||||
size: app.ui.font_size / 2
|
size: app.ui.font_size / 2
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
.tile {
|
.tile {
|
||||||
return gx.TextCfg{
|
return gx.TextCfg{
|
||||||
color: app.theme.text_color
|
color: app.theme.text_color
|
||||||
align: .center
|
align: .center
|
||||||
vertical_align: .middle
|
vertical_align: .middle
|
||||||
size: app.ui.font_size
|
size: app.ui.font_size
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
.victory {
|
.victory {
|
||||||
return gx.TextCfg{
|
return gx.TextCfg{
|
||||||
color: app.theme.victory_color
|
color: app.theme.victory_color
|
||||||
align: .center
|
align: .center
|
||||||
vertical_align: .middle
|
vertical_align: .middle
|
||||||
size: app.ui.font_size * 2
|
size: app.ui.font_size * 2
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
.game_over {
|
.game_over {
|
||||||
return gx.TextCfg{
|
return gx.TextCfg{
|
||||||
color: app.theme.game_over_color
|
color: app.theme.game_over_color
|
||||||
align: .center
|
align: .center
|
||||||
vertical_align: .middle
|
vertical_align: .middle
|
||||||
size: app.ui.font_size * 2
|
size: app.ui.font_size * 2
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
.score_end {
|
.score_end {
|
||||||
return gx.TextCfg{
|
return gx.TextCfg{
|
||||||
color: gx.white
|
color: gx.white
|
||||||
align: .center
|
align: .center
|
||||||
vertical_align: .middle
|
vertical_align: .middle
|
||||||
size: app.ui.font_size * 3 / 4
|
size: app.ui.font_size * 3 / 4
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -597,7 +597,7 @@ fn (app &App) draw() {
|
||||||
app.gg.draw_text(ww / 2, (m * 6 / 10) + ypad, msg, gx.TextCfg{
|
app.gg.draw_text(ww / 2, (m * 6 / 10) + ypad, msg, gx.TextCfg{
|
||||||
...f
|
...f
|
||||||
color: gx.white
|
color: gx.white
|
||||||
size: f.size * 3 / 4
|
size: f.size * 3 / 4
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
if app.state == .victory {
|
if app.state == .victory {
|
||||||
|
@ -660,7 +660,7 @@ fn (app &App) draw_tiles() {
|
||||||
app.gg.draw_text(xpos + app.ui.tile_size / 10, ypos - app.ui.tile_size / 8,
|
app.gg.draw_text(xpos + app.ui.tile_size / 10, ypos - app.ui.tile_size / 8,
|
||||||
'${tidx}', gx.TextCfg{
|
'${tidx}', gx.TextCfg{
|
||||||
...fmt
|
...fmt
|
||||||
size: fs2
|
size: fs2
|
||||||
align: gx.HorizontalAlign.left
|
align: gx.HorizontalAlign.left
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
@ -900,16 +900,16 @@ fn main() {
|
||||||
font_path = 'fonts/RobotoMono-Regular.ttf'
|
font_path = 'fonts/RobotoMono-Regular.ttf'
|
||||||
}
|
}
|
||||||
app.gg = gg.new_context(
|
app.gg = gg.new_context(
|
||||||
bg_color: app.theme.bg_color
|
bg_color: app.theme.bg_color
|
||||||
width: default_window_width
|
width: default_window_width
|
||||||
height: default_window_height
|
height: default_window_height
|
||||||
sample_count: 2 // higher quality curves
|
sample_count: 2 // higher quality curves
|
||||||
window_title: 'V 2048'
|
window_title: 'V 2048'
|
||||||
frame_fn: frame
|
frame_fn: frame
|
||||||
event_fn: on_event
|
event_fn: on_event
|
||||||
init_fn: init
|
init_fn: init
|
||||||
user_data: app
|
user_data: app
|
||||||
font_path: font_path
|
font_path: font_path
|
||||||
)
|
)
|
||||||
app.gg.run()
|
app.gg.run()
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,35 +5,35 @@ import os
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
mut cmd := Command{
|
mut cmd := Command{
|
||||||
name: 'cli'
|
name: 'cli'
|
||||||
description: 'An example of the cli library.'
|
description: 'An example of the cli library.'
|
||||||
version: '1.0.0'
|
version: '1.0.0'
|
||||||
}
|
}
|
||||||
mut greet_cmd := Command{
|
mut greet_cmd := Command{
|
||||||
name: 'greet'
|
name: 'greet'
|
||||||
description: 'Prints greeting in different languages.'
|
description: 'Prints greeting in different languages.'
|
||||||
usage: '<name>'
|
usage: '<name>'
|
||||||
required_args: 1
|
required_args: 1
|
||||||
pre_execute: greet_pre_func
|
pre_execute: greet_pre_func
|
||||||
execute: greet_func
|
execute: greet_func
|
||||||
post_execute: greet_post_func
|
post_execute: greet_post_func
|
||||||
}
|
}
|
||||||
greet_cmd.add_flag(Flag{
|
greet_cmd.add_flag(Flag{
|
||||||
flag: .string
|
flag: .string
|
||||||
required: true
|
required: true
|
||||||
name: 'language'
|
name: 'language'
|
||||||
abbrev: 'l'
|
abbrev: 'l'
|
||||||
description: 'Language of the message.'
|
description: 'Language of the message.'
|
||||||
})
|
})
|
||||||
greet_cmd.add_flag(Flag{
|
greet_cmd.add_flag(Flag{
|
||||||
flag: .int
|
flag: .int
|
||||||
name: 'times'
|
name: 'times'
|
||||||
default_value: ['3']
|
default_value: ['3']
|
||||||
description: 'Number of times the message gets printed.'
|
description: 'Number of times the message gets printed.'
|
||||||
})
|
})
|
||||||
greet_cmd.add_flag(Flag{
|
greet_cmd.add_flag(Flag{
|
||||||
flag: .string_array
|
flag: .string_array
|
||||||
name: 'fun'
|
name: 'fun'
|
||||||
description: 'Just a dumby flags to show multiple.'
|
description: 'Just a dumby flags to show multiple.'
|
||||||
})
|
})
|
||||||
cmd.add_command(greet_cmd)
|
cmd.add_command(greet_cmd)
|
||||||
|
|
|
@ -155,15 +155,15 @@ fn main() {
|
||||||
mut app := &App{}
|
mut app := &App{}
|
||||||
|
|
||||||
app.gg = gg.new_context(
|
app.gg = gg.new_context(
|
||||||
width: design_size
|
width: design_size
|
||||||
height: design_size
|
height: design_size
|
||||||
window_title: 'Clock!'
|
window_title: 'Clock!'
|
||||||
bg_color: gx.white
|
bg_color: gx.white
|
||||||
user_data: app
|
user_data: app
|
||||||
frame_fn: on_frame
|
frame_fn: on_frame
|
||||||
event_fn: on_event
|
event_fn: on_event
|
||||||
init_fn: on_init
|
init_fn: on_init
|
||||||
font_path: font_path
|
font_path: font_path
|
||||||
)
|
)
|
||||||
|
|
||||||
app.gg.run()
|
app.gg.run()
|
||||||
|
|
|
@ -2,11 +2,11 @@ import db.mysql
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
mut conn := mysql.connect(
|
mut conn := mysql.connect(
|
||||||
host: 'localhost'
|
host: 'localhost'
|
||||||
port: 3306
|
port: 3306
|
||||||
username: 'root'
|
username: 'root'
|
||||||
password: ''
|
password: ''
|
||||||
dbname: 'mysql'
|
dbname: 'mysql'
|
||||||
)!
|
)!
|
||||||
res := conn.query('show tables')!
|
res := conn.query('show tables')!
|
||||||
for row in res.rows() {
|
for row in res.rows() {
|
||||||
|
|
|
@ -77,7 +77,7 @@ fn sqlite3_array() ! {
|
||||||
create table Child
|
create table Child
|
||||||
}!
|
}!
|
||||||
par := Parent{
|
par := Parent{
|
||||||
name: 'test'
|
name: 'test'
|
||||||
children: [
|
children: [
|
||||||
Child{
|
Child{
|
||||||
name: 'abc'
|
name: 'abc'
|
||||||
|
@ -99,11 +99,11 @@ fn sqlite3_array() ! {
|
||||||
fn msql_array() ! {
|
fn msql_array() ! {
|
||||||
eprintln('------------ ${@METHOD} -----------------')
|
eprintln('------------ ${@METHOD} -----------------')
|
||||||
mut db := mysql.connect(
|
mut db := mysql.connect(
|
||||||
host: mysql_host
|
host: mysql_host
|
||||||
port: mysql_port
|
port: mysql_port
|
||||||
username: mysql_user
|
username: mysql_user
|
||||||
password: mysql_pass
|
password: mysql_pass
|
||||||
dbname: mysql_db
|
dbname: mysql_db
|
||||||
)!
|
)!
|
||||||
defer {
|
defer {
|
||||||
sql db {
|
sql db {
|
||||||
|
@ -119,7 +119,7 @@ fn msql_array() ! {
|
||||||
create table Child
|
create table Child
|
||||||
}!
|
}!
|
||||||
par := Parent{
|
par := Parent{
|
||||||
name: 'test'
|
name: 'test'
|
||||||
children: [
|
children: [
|
||||||
Child{
|
Child{
|
||||||
name: 'abc'
|
name: 'abc'
|
||||||
|
@ -152,7 +152,7 @@ fn psql_array() ! {
|
||||||
create table Child
|
create table Child
|
||||||
}!
|
}!
|
||||||
par := Parent{
|
par := Parent{
|
||||||
name: 'test'
|
name: 'test'
|
||||||
children: [
|
children: [
|
||||||
Child{
|
Child{
|
||||||
name: 'abc'
|
name: 'abc'
|
||||||
|
@ -189,11 +189,11 @@ fn sqlite3() ! {
|
||||||
create table User
|
create table User
|
||||||
}!
|
}!
|
||||||
mod := Module{
|
mod := Module{
|
||||||
name: 'test'
|
name: 'test'
|
||||||
nr_downloads: 10
|
nr_downloads: 10
|
||||||
creator: User{
|
creator: User{
|
||||||
age: 21
|
age: 21
|
||||||
name: 'VUser'
|
name: 'VUser'
|
||||||
is_customer: true
|
is_customer: true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -209,11 +209,11 @@ fn sqlite3() ! {
|
||||||
fn msql() ! {
|
fn msql() ! {
|
||||||
eprintln('------------ ${@METHOD} -----------------')
|
eprintln('------------ ${@METHOD} -----------------')
|
||||||
mut conn := mysql.connect(
|
mut conn := mysql.connect(
|
||||||
host: mysql_host
|
host: mysql_host
|
||||||
port: mysql_port
|
port: mysql_port
|
||||||
username: mysql_user
|
username: mysql_user
|
||||||
password: mysql_pass
|
password: mysql_pass
|
||||||
dbname: mysql_db
|
dbname: mysql_db
|
||||||
)!
|
)!
|
||||||
defer {
|
defer {
|
||||||
conn.query('DROP TABLE IF EXISTS Module') or { eprintln(err) }
|
conn.query('DROP TABLE IF EXISTS Module') or { eprintln(err) }
|
||||||
|
@ -230,11 +230,11 @@ fn msql() ! {
|
||||||
create table User
|
create table User
|
||||||
}!
|
}!
|
||||||
mod := Module{
|
mod := Module{
|
||||||
name: 'test'
|
name: 'test'
|
||||||
nr_downloads: 10
|
nr_downloads: 10
|
||||||
creator: User{
|
creator: User{
|
||||||
age: 21
|
age: 21
|
||||||
name: 'VUser'
|
name: 'VUser'
|
||||||
is_customer: true
|
is_customer: true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -260,11 +260,11 @@ fn psql() ! {
|
||||||
create table User
|
create table User
|
||||||
}!
|
}!
|
||||||
mod := Module{
|
mod := Module{
|
||||||
name: 'test'
|
name: 'test'
|
||||||
nr_downloads: 10
|
nr_downloads: 10
|
||||||
creator: User{
|
creator: User{
|
||||||
age: 21
|
age: 21
|
||||||
name: 'VUser'
|
name: 'VUser'
|
||||||
is_customer: true
|
is_customer: true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -19,7 +19,7 @@ const default_paths = [
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
mut dl_loader := loader.get_or_create_dynamic_lib_loader(
|
mut dl_loader := loader.get_or_create_dynamic_lib_loader(
|
||||||
key: cfolder + '/library'
|
key: cfolder + '/library'
|
||||||
paths: default_paths
|
paths: default_paths
|
||||||
)!
|
)!
|
||||||
defer {
|
defer {
|
||||||
|
|
|
@ -28,7 +28,7 @@ struct UserAgent {
|
||||||
|
|
||||||
url := 'http://ifconfig.co/json'
|
url := 'http://ifconfig.co/json'
|
||||||
resp := http.fetch(
|
resp := http.fetch(
|
||||||
url: url
|
url: url
|
||||||
user_agent: 'Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:109.0) Gecko/20100101 Firefox/117.0'
|
user_agent: 'Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:109.0) Gecko/20100101 Firefox/117.0'
|
||||||
) or {
|
) or {
|
||||||
eprintln('failed to fetch data from the server, error: ${err}')
|
eprintln('failed to fetch data from the server, error: ${err}')
|
||||||
|
|
|
@ -103,14 +103,14 @@ fn main() {
|
||||||
app.ui = objects.get_params()
|
app.ui = objects.get_params()
|
||||||
|
|
||||||
app.gg = gg.new_context(
|
app.gg = gg.new_context(
|
||||||
width: app.ui.width
|
width: app.ui.width
|
||||||
height: app.ui.height
|
height: app.ui.height
|
||||||
window_title: 'Fireworks!'
|
window_title: 'Fireworks!'
|
||||||
bg_color: gx.black
|
bg_color: gx.black
|
||||||
user_data: app
|
user_data: app
|
||||||
frame_fn: on_frame
|
frame_fn: on_frame
|
||||||
event_fn: on_event
|
event_fn: on_event
|
||||||
font_path: font_path
|
font_path: font_path
|
||||||
)
|
)
|
||||||
|
|
||||||
app.gg.run()
|
app.gg.run()
|
||||||
|
|
|
@ -50,7 +50,7 @@ pub fn (mut rocket Rocket) tick(mut ctx gg.Context) {
|
||||||
pub fn new_rocket() Rocket {
|
pub fn new_rocket() Rocket {
|
||||||
return Rocket{
|
return Rocket{
|
||||||
color: random_color()
|
color: random_color()
|
||||||
pos: Vector{
|
pos: Vector{
|
||||||
x: rand.f32_in_range(50, get_params().width - 50) or { 50 }
|
x: rand.f32_in_range(50, get_params().width - 50) or { 50 }
|
||||||
}
|
}
|
||||||
vel: Vector{
|
vel: Vector{
|
||||||
|
@ -63,7 +63,7 @@ pub fn new_rocket() Rocket {
|
||||||
pub fn (mut rocket Rocket) spawn_particle() {
|
pub fn (mut rocket Rocket) spawn_particle() {
|
||||||
rocket.particles << Particle{
|
rocket.particles << Particle{
|
||||||
color: rocket.color
|
color: rocket.color
|
||||||
pos: rocket.pos
|
pos: rocket.pos
|
||||||
accel: random_vector_in_circle().mult(2)
|
accel: random_vector_in_circle().mult(2)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -53,7 +53,7 @@ fn frame(mut app App) {
|
||||||
}
|
}
|
||||||
|
|
||||||
help_text := flag.to_doc[DocTest](
|
help_text := flag.to_doc[DocTest](
|
||||||
version: '1.0'
|
version: '1.0'
|
||||||
description: 'Hello! This should show an *animated* example application description.
|
description: 'Hello! This should show an *animated* example application description.
|
||||||
We are at frame ${app.frame}.
|
We are at frame ${app.frame}.
|
||||||
Press ESCAPE or Ctrl+C to exit'
|
Press ESCAPE or Ctrl+C to exit'
|
||||||
|
@ -82,11 +82,11 @@ type FrameFn = fn (voidptr)
|
||||||
fn main() {
|
fn main() {
|
||||||
mut app := &App{}
|
mut app := &App{}
|
||||||
app.tui = tui.init(
|
app.tui = tui.init(
|
||||||
user_data: app
|
user_data: app
|
||||||
event_fn: EventFn(event)
|
event_fn: EventFn(event)
|
||||||
frame_fn: FrameFn(frame)
|
frame_fn: FrameFn(frame)
|
||||||
hide_cursor: true
|
hide_cursor: true
|
||||||
frame_rate: 60
|
frame_rate: 60
|
||||||
)
|
)
|
||||||
app.tui.run()!
|
app.tui.run()!
|
||||||
}
|
}
|
||||||
|
|
|
@ -211,8 +211,8 @@ Editing property: ${app.edit}, value: ${value}')
|
||||||
Press ESCAPE or Ctrl+C to exit and print layout code'
|
Press ESCAPE or Ctrl+C to exit and print layout code'
|
||||||
footer: '
|
footer: '
|
||||||
Press ESCAPE or Ctrl+C to exit and print layout code'
|
Press ESCAPE or Ctrl+C to exit and print layout code'
|
||||||
fields: unsafe { field_docs }
|
fields: unsafe { field_docs }
|
||||||
layout: app.layout
|
layout: app.layout
|
||||||
options: app.options
|
options: app.options
|
||||||
) or { '' }
|
) or { '' }
|
||||||
|
|
||||||
|
@ -233,11 +233,11 @@ fn main() {
|
||||||
println('${app.options}')
|
println('${app.options}')
|
||||||
}) or {}
|
}) or {}
|
||||||
app.tui = tui.init(
|
app.tui = tui.init(
|
||||||
user_data: app
|
user_data: app
|
||||||
event_fn: EventFn(event)
|
event_fn: EventFn(event)
|
||||||
frame_fn: FrameFn(frame)
|
frame_fn: FrameFn(frame)
|
||||||
hide_cursor: true
|
hide_cursor: true
|
||||||
frame_rate: 60
|
frame_rate: 60
|
||||||
)
|
)
|
||||||
app.tui.run()!
|
app.tui.run()!
|
||||||
}
|
}
|
||||||
|
|
|
@ -153,13 +153,13 @@ fn (mut app App) update() {
|
||||||
holl_position := math.round(rand.f64() * (app.height - delta_bord * 2.0 - pipe_holl)) +
|
holl_position := math.round(rand.f64() * (app.height - delta_bord * 2.0 - pipe_holl)) +
|
||||||
delta_bord
|
delta_bord
|
||||||
app.pipes << Pipe{
|
app.pipes << Pipe{
|
||||||
x: app.width
|
x: app.width
|
||||||
y: 0
|
y: 0
|
||||||
height: holl_position
|
height: holl_position
|
||||||
}
|
}
|
||||||
app.pipes << Pipe{
|
app.pipes << Pipe{
|
||||||
x: app.width
|
x: app.width
|
||||||
y: holl_position + pipe_holl
|
y: holl_position + pipe_holl
|
||||||
height: app.height
|
height: app.height
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -178,20 +178,20 @@ fn main() {
|
||||||
font_path = 'fonts/RobotoMono-Regular.ttf'
|
font_path = 'fonts/RobotoMono-Regular.ttf'
|
||||||
}
|
}
|
||||||
app.gg = gg.new_context(
|
app.gg = gg.new_context(
|
||||||
bg_color: gx.white
|
bg_color: gx.white
|
||||||
width: win_width
|
width: win_width
|
||||||
height: win_height
|
height: win_height
|
||||||
create_window: true
|
create_window: true
|
||||||
window_title: 'flappylearning-v'
|
window_title: 'flappylearning-v'
|
||||||
frame_fn: frame
|
frame_fn: frame
|
||||||
event_fn: on_event
|
event_fn: on_event
|
||||||
user_data: app
|
user_data: app
|
||||||
init_fn: app.init_images_wrapper
|
init_fn: app.init_images_wrapper
|
||||||
font_path: font_path
|
font_path: font_path
|
||||||
)
|
)
|
||||||
app.nv = neuroevolution.Generations{
|
app.nv = neuroevolution.Generations{
|
||||||
population: 50
|
population: 50
|
||||||
network: [2, 2, 1]
|
network: [2, 2, 1]
|
||||||
}
|
}
|
||||||
app.start()
|
app.start()
|
||||||
spawn app.run()
|
spawn app.run()
|
||||||
|
|
|
@ -281,7 +281,7 @@ pub fn (mut gs Generations) generate() []Network {
|
||||||
|
|
||||||
pub fn (mut gs Generations) network_score(network Network, score int) {
|
pub fn (mut gs Generations) network_score(network Network, score int) {
|
||||||
gs.add_genome(Genome{
|
gs.add_genome(Genome{
|
||||||
score: score
|
score: score
|
||||||
network: network.get_save()
|
network: network.get_save()
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
|
@ -40,14 +40,14 @@ fn main() {
|
||||||
a: automaton.gun()
|
a: automaton.gun()
|
||||||
}
|
}
|
||||||
app.gg = gg.new_context(
|
app.gg = gg.new_context(
|
||||||
bg_color: gx.white
|
bg_color: gx.white
|
||||||
frame_fn: frame
|
frame_fn: frame
|
||||||
user_data: &app
|
user_data: &app
|
||||||
width: screen_width
|
width: screen_width
|
||||||
height: screen_height
|
height: screen_height
|
||||||
create_window: true
|
create_window: true
|
||||||
resizable: false
|
resizable: false
|
||||||
window_title: 'v life (with gg, gx)'
|
window_title: 'v life (with gg, gx)'
|
||||||
)
|
)
|
||||||
app.gg.run()
|
app.gg.run()
|
||||||
}
|
}
|
||||||
|
|
|
@ -70,7 +70,7 @@ fn new_automaton(ftext string) Automaton {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return Automaton{
|
return Automaton{
|
||||||
field: field
|
field: field
|
||||||
new_field: new_field
|
new_field: new_field
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -21,12 +21,12 @@ pub fn (mut window Window) draw(_ voidptr) {
|
||||||
window.ctx.begin()
|
window.ctx.begin()
|
||||||
|
|
||||||
myconfig := gg.DrawImageConfig{
|
myconfig := gg.DrawImageConfig{
|
||||||
img: &window.image
|
img: &window.image
|
||||||
img_id: window.image.id
|
img_id: window.image.id
|
||||||
img_rect: gg.Rect{
|
img_rect: gg.Rect{
|
||||||
x: 400 - window.image.width / 2
|
x: 400 - window.image.width / 2
|
||||||
y: 300 - window.image.height / 2
|
y: 300 - window.image.height / 2
|
||||||
width: window.image.width
|
width: window.image.width
|
||||||
height: window.image.height
|
height: window.image.height
|
||||||
}
|
}
|
||||||
rotation: f32(window.ctx.frame)
|
rotation: f32(window.ctx.frame)
|
||||||
|
@ -42,7 +42,7 @@ pub fn (mut window Window) draw(_ voidptr) {
|
||||||
x: myconfig.img_rect.x + f32(math.sin(f32(window.ctx.frame) / 10.0) * 60)
|
x: myconfig.img_rect.x + f32(math.sin(f32(window.ctx.frame) / 10.0) * 60)
|
||||||
y: myconfig.img_rect.y + f32(math.cos(f32(window.ctx.frame) / 10.0) * 60)
|
y: myconfig.img_rect.y + f32(math.cos(f32(window.ctx.frame) / 10.0) * 60)
|
||||||
}
|
}
|
||||||
color: gx.Color{255, 0, 0, 255}
|
color: gx.Color{255, 0, 0, 255}
|
||||||
effect: .add
|
effect: .add
|
||||||
})
|
})
|
||||||
|
|
||||||
|
@ -54,7 +54,7 @@ pub fn (mut window Window) draw(_ voidptr) {
|
||||||
x: myconfig.img_rect.x + f32(math.sin(f32(window.ctx.frame) / 10.0) * 80)
|
x: myconfig.img_rect.x + f32(math.sin(f32(window.ctx.frame) / 10.0) * 80)
|
||||||
y: myconfig.img_rect.y + f32(math.cos(f32(window.ctx.frame) / 10.0) * 80)
|
y: myconfig.img_rect.y + f32(math.cos(f32(window.ctx.frame) / 10.0) * 80)
|
||||||
}
|
}
|
||||||
color: gx.Color{0, 255, 0, 255}
|
color: gx.Color{0, 255, 0, 255}
|
||||||
effect: .add
|
effect: .add
|
||||||
})
|
})
|
||||||
|
|
||||||
|
@ -66,7 +66,7 @@ pub fn (mut window Window) draw(_ voidptr) {
|
||||||
x: myconfig.img_rect.x + f32(math.sin(f32(window.ctx.frame) / 10.0) * 100)
|
x: myconfig.img_rect.x + f32(math.sin(f32(window.ctx.frame) / 10.0) * 100)
|
||||||
y: myconfig.img_rect.y + f32(math.cos(f32(window.ctx.frame) / 10.0) * 100)
|
y: myconfig.img_rect.y + f32(math.cos(f32(window.ctx.frame) / 10.0) * 100)
|
||||||
}
|
}
|
||||||
color: gx.Color{0, 0, 255, 255}
|
color: gx.Color{0, 0, 255, 255}
|
||||||
effect: .add
|
effect: .add
|
||||||
})
|
})
|
||||||
|
|
||||||
|
@ -78,7 +78,7 @@ pub fn (mut window Window) draw(_ voidptr) {
|
||||||
x: 50
|
x: 50
|
||||||
y: 0
|
y: 0
|
||||||
}
|
}
|
||||||
color: gx.Color{255, 0, 0, 255}
|
color: gx.Color{255, 0, 0, 255}
|
||||||
effect: .add
|
effect: .add
|
||||||
})
|
})
|
||||||
|
|
||||||
|
@ -89,7 +89,7 @@ pub fn (mut window Window) draw(_ voidptr) {
|
||||||
x: 50
|
x: 50
|
||||||
y: 50
|
y: 50
|
||||||
}
|
}
|
||||||
color: gx.Color{0, 255, 0, 255}
|
color: gx.Color{0, 255, 0, 255}
|
||||||
effect: .add
|
effect: .add
|
||||||
})
|
})
|
||||||
|
|
||||||
|
@ -100,7 +100,7 @@ pub fn (mut window Window) draw(_ voidptr) {
|
||||||
x: 50
|
x: 50
|
||||||
y: 100
|
y: 100
|
||||||
}
|
}
|
||||||
color: gx.Color{0, 0, 255, 255}
|
color: gx.Color{0, 0, 255, 255}
|
||||||
effect: .add
|
effect: .add
|
||||||
})
|
})
|
||||||
|
|
||||||
|
@ -112,12 +112,12 @@ fn main() {
|
||||||
|
|
||||||
window.ctx = gg.new_context(
|
window.ctx = gg.new_context(
|
||||||
window_title: 'Additive colors & image rotation'
|
window_title: 'Additive colors & image rotation'
|
||||||
width: 800
|
width: 800
|
||||||
height: 600
|
height: 600
|
||||||
user_data: window
|
user_data: window
|
||||||
bg_color: gx.gray
|
bg_color: gx.gray
|
||||||
// FNs
|
// FNs
|
||||||
init_fn: window.init
|
init_fn: window.init
|
||||||
frame_fn: window.draw
|
frame_fn: window.draw
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
|
@ -33,14 +33,14 @@ mut:
|
||||||
fn main() {
|
fn main() {
|
||||||
mut app := &App{}
|
mut app := &App{}
|
||||||
app.gg = gg.new_context(
|
app.gg = gg.new_context(
|
||||||
width: win_width
|
width: win_width
|
||||||
height: win_height
|
height: win_height
|
||||||
create_window: true
|
create_window: true
|
||||||
window_title: 'Arcs and Slices'
|
window_title: 'Arcs and Slices'
|
||||||
user_data: app
|
user_data: app
|
||||||
bg_color: bg_color
|
bg_color: bg_color
|
||||||
frame_fn: on_frame
|
frame_fn: on_frame
|
||||||
event_fn: on_event
|
event_fn: on_event
|
||||||
)
|
)
|
||||||
app.gg.run()
|
app.gg.run()
|
||||||
}
|
}
|
||||||
|
|
|
@ -14,12 +14,12 @@ mut:
|
||||||
fn main() {
|
fn main() {
|
||||||
mut app := &App{}
|
mut app := &App{}
|
||||||
app.gg = gg.new_context(
|
app.gg = gg.new_context(
|
||||||
bg_color: gx.rgb(174, 198, 255)
|
bg_color: gx.rgb(174, 198, 255)
|
||||||
width: 600
|
width: 600
|
||||||
height: 400
|
height: 400
|
||||||
window_title: 'Cubic Bézier curve'
|
window_title: 'Cubic Bézier curve'
|
||||||
frame_fn: frame
|
frame_fn: frame
|
||||||
user_data: app
|
user_data: app
|
||||||
)
|
)
|
||||||
app.gg.run()
|
app.gg.run()
|
||||||
}
|
}
|
||||||
|
|
|
@ -34,12 +34,12 @@ fn main() {
|
||||||
anim: &Anim{}
|
anim: &Anim{}
|
||||||
}
|
}
|
||||||
app.gg = gg.new_context(
|
app.gg = gg.new_context(
|
||||||
bg_color: gx.rgb(174, 198, 255)
|
bg_color: gx.rgb(174, 198, 255)
|
||||||
width: 600
|
width: 600
|
||||||
height: 400
|
height: 400
|
||||||
window_title: 'Animated cubic Bézier curve'
|
window_title: 'Animated cubic Bézier curve'
|
||||||
frame_fn: frame
|
frame_fn: frame
|
||||||
user_data: app
|
user_data: app
|
||||||
)
|
)
|
||||||
app.gg.run()
|
app.gg.run()
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,10 +6,10 @@ import sokol.sapp
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
mut ctx := gg.new_context(
|
mut ctx := gg.new_context(
|
||||||
bg_color: gx.white
|
bg_color: gx.white
|
||||||
window_title: 'Cursor'
|
window_title: 'Cursor'
|
||||||
frame_fn: frame
|
frame_fn: frame
|
||||||
init_fn: init
|
init_fn: init
|
||||||
)
|
)
|
||||||
ctx.run()
|
ctx.run()
|
||||||
}
|
}
|
||||||
|
|
|
@ -37,12 +37,12 @@ fn main() {
|
||||||
|
|
||||||
fn rain(mut app App) {
|
fn rain(mut app App) {
|
||||||
app.ctx = gg.new_context(
|
app.ctx = gg.new_context(
|
||||||
bg_color: gx.rgb(0, 0, 0)
|
bg_color: gx.rgb(0, 0, 0)
|
||||||
width: app.screen_size.width
|
width: app.screen_size.width
|
||||||
height: app.screen_size.height
|
height: app.screen_size.height
|
||||||
user_data: app
|
user_data: app
|
||||||
window_title: 'Digital Rain'
|
window_title: 'Digital Rain'
|
||||||
init_fn: fn (mut app App) {
|
init_fn: fn (mut app App) {
|
||||||
gg.toggle_fullscreen()
|
gg.toggle_fullscreen()
|
||||||
}
|
}
|
||||||
event_fn: fn (event &gg.Event, mut app App) {
|
event_fn: fn (event &gg.Event, mut app App) {
|
||||||
|
@ -99,9 +99,9 @@ fn vprintln(msg string) {
|
||||||
fn calc_sizes(mut app App) {
|
fn calc_sizes(mut app App) {
|
||||||
app.screen_size = gg.window_size()
|
app.screen_size = gg.window_size()
|
||||||
app.ctx.set_text_cfg(gx.TextCfg{
|
app.ctx.set_text_cfg(gx.TextCfg{
|
||||||
size: font_size
|
size: font_size
|
||||||
color: gx.green
|
color: gx.green
|
||||||
mono: true
|
mono: true
|
||||||
})
|
})
|
||||||
// figure out how big character is in pixels
|
// figure out how big character is in pixels
|
||||||
// Pad it or it looks too squashed
|
// Pad it or it looks too squashed
|
||||||
|
@ -139,7 +139,7 @@ fn draw_rain_column(rc RainColumn, app App) {
|
||||||
}
|
}
|
||||||
at_head := i == rc.head - 1
|
at_head := i == rc.head - 1
|
||||||
cfg := gx.TextCfg{
|
cfg := gx.TextCfg{
|
||||||
size: font_size
|
size: font_size
|
||||||
color: gg.Color{
|
color: gg.Color{
|
||||||
r: if at_head { u8(255) } else { 0 }
|
r: if at_head { u8(255) } else { 0 }
|
||||||
g: 255
|
g: 255
|
||||||
|
@ -163,8 +163,8 @@ fn draw_rain_column(rc RainColumn, app App) {
|
||||||
fn random_rain_column(max_col int, max_height int) RainColumn {
|
fn random_rain_column(max_col int, max_height int) RainColumn {
|
||||||
min_len := 6
|
min_len := 6
|
||||||
mut rc := RainColumn{
|
mut rc := RainColumn{
|
||||||
col: rand.int_in_range(0, max_col) or { 0 }
|
col: rand.int_in_range(0, max_col) or { 0 }
|
||||||
len: rand.int_in_range(min_len, max_height / 4 * 3) or { min_len }
|
len: rand.int_in_range(min_len, max_height / 4 * 3) or { min_len }
|
||||||
drops: []u8{cap: max_height}
|
drops: []u8{cap: max_height}
|
||||||
}
|
}
|
||||||
for _ in 0 .. max_height {
|
for _ in 0 .. max_height {
|
||||||
|
|
|
@ -19,17 +19,17 @@ fn main() {
|
||||||
mut font_path := os.resource_abs_path(os.join_path('..', 'assets', 'fonts', 'RobotoMono-Regular.ttf'))
|
mut font_path := os.resource_abs_path(os.join_path('..', 'assets', 'fonts', 'RobotoMono-Regular.ttf'))
|
||||||
mut app := &App{}
|
mut app := &App{}
|
||||||
app.gg = gg.new_context(
|
app.gg = gg.new_context(
|
||||||
bg_color: gx.rgb(174, 198, 255)
|
bg_color: gx.rgb(174, 198, 255)
|
||||||
width: 600
|
width: 600
|
||||||
height: 400
|
height: 400
|
||||||
window_title: 'Drag and drop'
|
window_title: 'Drag and drop'
|
||||||
frame_fn: frame
|
frame_fn: frame
|
||||||
font_path: font_path
|
font_path: font_path
|
||||||
user_data: app
|
user_data: app
|
||||||
event_fn: my_event_manager
|
event_fn: my_event_manager
|
||||||
// drag & drop
|
// drag & drop
|
||||||
enable_dragndrop: true
|
enable_dragndrop: true
|
||||||
max_dropped_files: max_files
|
max_dropped_files: max_files
|
||||||
max_dropped_file_path_length: 2048
|
max_dropped_file_path_length: 2048
|
||||||
)
|
)
|
||||||
app.gg.run()
|
app.gg.run()
|
||||||
|
@ -52,7 +52,7 @@ fn frame(mut app App) {
|
||||||
mut txt_conf := gx.TextCfg{
|
mut txt_conf := gx.TextCfg{
|
||||||
color: gx.black
|
color: gx.black
|
||||||
align: .left
|
align: .left
|
||||||
size: int(text_size * app.gg.scale + 0.5)
|
size: int(text_size * app.gg.scale + 0.5)
|
||||||
}
|
}
|
||||||
app.gg.draw_text(12, 12, text, txt_conf)
|
app.gg.draw_text(12, 12, text, txt_conf)
|
||||||
|
|
||||||
|
|
|
@ -28,12 +28,12 @@ fn main() {
|
||||||
pixels: pixels
|
pixels: pixels
|
||||||
}
|
}
|
||||||
app.gg = gg.new_context(
|
app.gg = gg.new_context(
|
||||||
bg_color: gx.rgb(174, 198, 255)
|
bg_color: gx.rgb(174, 198, 255)
|
||||||
width: 100
|
width: 100
|
||||||
height: 100
|
height: 100
|
||||||
window_title: 'Set Pixels'
|
window_title: 'Set Pixels'
|
||||||
frame_fn: frame
|
frame_fn: frame
|
||||||
user_data: app
|
user_data: app
|
||||||
)
|
)
|
||||||
app.gg.run()
|
app.gg.run()
|
||||||
}
|
}
|
||||||
|
|
|
@ -63,14 +63,14 @@ fn main() {
|
||||||
app.buf << []int{len: width, init: 36} // white fire base
|
app.buf << []int{len: width, init: 36} // white fire base
|
||||||
|
|
||||||
app.gg = gg.new_context(
|
app.gg = gg.new_context(
|
||||||
event_fn: event
|
event_fn: event
|
||||||
frame_fn: frame
|
frame_fn: frame
|
||||||
init_fn: retile
|
init_fn: retile
|
||||||
window_title: 'Fire Animation'
|
window_title: 'Fire Animation'
|
||||||
user_data: app
|
user_data: app
|
||||||
bg_color: palette[0]
|
bg_color: palette[0]
|
||||||
width: win_width
|
width: win_width
|
||||||
height: win_height
|
height: win_height
|
||||||
)
|
)
|
||||||
app.gg.run()
|
app.gg.run()
|
||||||
}
|
}
|
||||||
|
|
|
@ -75,8 +75,8 @@ fn (mut state AppState) update() {
|
||||||
for start := 0; start < pheight; start += chunk_height {
|
for start := 0; start < pheight; start += chunk_height {
|
||||||
chunk_channel <- MandelChunk{
|
chunk_channel <- MandelChunk{
|
||||||
cview: cview
|
cview: cview
|
||||||
ymin: start
|
ymin: start
|
||||||
ymax: start + chunk_height
|
ymax: start + chunk_height
|
||||||
}
|
}
|
||||||
nchunks++
|
nchunks++
|
||||||
}
|
}
|
||||||
|
@ -225,17 +225,17 @@ fn graphics_keydown(code gg.KeyCode, mod gg.Modifier, mut state AppState) {
|
||||||
fn main() {
|
fn main() {
|
||||||
mut state := &AppState{}
|
mut state := &AppState{}
|
||||||
state.gg = gg.new_context(
|
state.gg = gg.new_context(
|
||||||
width: 800
|
width: 800
|
||||||
height: 600
|
height: 600
|
||||||
create_window: true
|
create_window: true
|
||||||
window_title: 'The Mandelbrot Set'
|
window_title: 'The Mandelbrot Set'
|
||||||
init_fn: graphics_init
|
init_fn: graphics_init
|
||||||
frame_fn: graphics_frame
|
frame_fn: graphics_frame
|
||||||
click_fn: graphics_click
|
click_fn: graphics_click
|
||||||
move_fn: graphics_move
|
move_fn: graphics_move
|
||||||
keydown_fn: graphics_keydown
|
keydown_fn: graphics_keydown
|
||||||
scroll_fn: graphics_scroll
|
scroll_fn: graphics_scroll
|
||||||
user_data: state
|
user_data: state
|
||||||
)
|
)
|
||||||
spawn state.update()
|
spawn state.update()
|
||||||
state.gg.run()
|
state.gg.run()
|
||||||
|
|
|
@ -47,10 +47,10 @@ fn frame(mut ctx gg.Context) {
|
||||||
fn main() {
|
fn main() {
|
||||||
mut ctx := gg.new_context(
|
mut ctx := gg.new_context(
|
||||||
window_title: 'Many Thousands of Circles'
|
window_title: 'Many Thousands of Circles'
|
||||||
bg_color: gx.black
|
bg_color: gx.black
|
||||||
width: 600
|
width: 600
|
||||||
height: 400
|
height: 400
|
||||||
frame_fn: frame
|
frame_fn: frame
|
||||||
)
|
)
|
||||||
ctx.run()
|
ctx.run()
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,13 +2,13 @@ import gg
|
||||||
|
|
||||||
gg.start(
|
gg.start(
|
||||||
window_title: 'Hello'
|
window_title: 'Hello'
|
||||||
bg_color: gg.Color{240, 240, 128, 255}
|
bg_color: gg.Color{240, 240, 128, 255}
|
||||||
width: 320
|
width: 320
|
||||||
height: 240
|
height: 240
|
||||||
frame_fn: fn (ctx &gg.Context) {
|
frame_fn: fn (ctx &gg.Context) {
|
||||||
ctx.begin()
|
ctx.begin()
|
||||||
ctx.draw_text(40, 100, 'GG frame: ${ctx.frame:06}',
|
ctx.draw_text(40, 100, 'GG frame: ${ctx.frame:06}',
|
||||||
size: 30
|
size: 30
|
||||||
color: gg.Color{50, 50, 255, 255}
|
color: gg.Color{50, 50, 255, 255}
|
||||||
)
|
)
|
||||||
ctx.show_fps()
|
ctx.show_fps()
|
||||||
|
|
|
@ -76,15 +76,15 @@ fn main() {
|
||||||
|
|
||||||
// setting values of app
|
// setting values of app
|
||||||
app.gg = gg.new_context(
|
app.gg = gg.new_context(
|
||||||
bg_color: gx.black // background color
|
bg_color: gx.black // background color
|
||||||
width: window_width // window width
|
width: window_width // window width
|
||||||
height: window_height // window height
|
height: window_height // window height
|
||||||
create_window: true // this will create a different window
|
create_window: true // this will create a different window
|
||||||
window_title: 'A* Path finding algorithm visusalizer' // title of the window
|
window_title: 'A* Path finding algorithm visusalizer' // title of the window
|
||||||
frame_fn: frame // this is frame function update the frame
|
frame_fn: frame // this is frame function update the frame
|
||||||
event_fn: on_event // it calls on every event
|
event_fn: on_event // it calls on every event
|
||||||
init_fn: init_images // run at start of application
|
init_fn: init_images // run at start of application
|
||||||
user_data: app // store user data
|
user_data: app // store user data
|
||||||
)
|
)
|
||||||
mut grid := initialise_grid() // initialize the grid variable and populate the matrix with each cell as empty
|
mut grid := initialise_grid() // initialize the grid variable and populate the matrix with each cell as empty
|
||||||
app.grid = grid // set grid to app attribute so you can access it by just passing app variable or with method of app
|
app.grid = grid // set grid to app attribute so you can access it by just passing app variable or with method of app
|
||||||
|
@ -244,15 +244,15 @@ fn initialise_grid() [][]Cell {
|
||||||
for i := 0; i < nrows; i++ {
|
for i := 0; i < nrows; i++ {
|
||||||
for j := 0; j < nrows; j++ {
|
for j := 0; j < nrows; j++ {
|
||||||
grid[i][j] = &Cell{
|
grid[i][j] = &Cell{
|
||||||
row: i
|
row: i
|
||||||
col: j
|
col: j
|
||||||
width: gap
|
width: gap
|
||||||
pos: &Point{
|
pos: &Point{
|
||||||
x: j * gap
|
x: j * gap
|
||||||
y: i * gap
|
y: i * gap
|
||||||
}
|
}
|
||||||
color: gx.white
|
color: gx.white
|
||||||
flag: 0
|
flag: 0
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -331,7 +331,7 @@ fn astar_path_finding(mut app App, mut grid [][]Cell, start Point, end Point) {
|
||||||
f_score[start.x][start.y] = g_score[start.x][start.y] + hf(start, end)
|
f_score[start.x][start.y] = g_score[start.x][start.y] + hf(start, end)
|
||||||
priority_queue.insert(&Node{
|
priority_queue.insert(&Node{
|
||||||
f_score: f_score[start.x][start.y]
|
f_score: f_score[start.x][start.y]
|
||||||
cell: &Point{
|
cell: &Point{
|
||||||
x: start.x
|
x: start.x
|
||||||
y: start.y
|
y: start.y
|
||||||
}
|
}
|
||||||
|
@ -362,8 +362,8 @@ fn astar_path_finding(mut app App, mut grid [][]Cell, start Point, end Point) {
|
||||||
if !(neighbor.x == start.x && neighbor.y == start.y) {
|
if !(neighbor.x == start.x && neighbor.y == start.y) {
|
||||||
priority_queue.insert(&Node{
|
priority_queue.insert(&Node{
|
||||||
f_score: g_score[neighbor.x][neighbor.y] + hf(neighbor, end)
|
f_score: g_score[neighbor.x][neighbor.y] + hf(neighbor, end)
|
||||||
cell: neighbor
|
cell: neighbor
|
||||||
count: curr_node.count + 1
|
count: curr_node.count + 1
|
||||||
})
|
})
|
||||||
came_from[neighbor.x][neighbor.y] = curr_pos
|
came_from[neighbor.x][neighbor.y] = curr_pos
|
||||||
set_cell_type(mut grid, neighbor.x, neighbor.y, 'open')
|
set_cell_type(mut grid, neighbor.x, neighbor.y, 'open')
|
||||||
|
|
|
@ -5,11 +5,11 @@ import gx
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
mut context := gg.new_context(
|
mut context := gg.new_context(
|
||||||
bg_color: gx.rgb(174, 198, 255)
|
bg_color: gx.rgb(174, 198, 255)
|
||||||
width: 600
|
width: 600
|
||||||
height: 400
|
height: 400
|
||||||
window_title: 'Polygons'
|
window_title: 'Polygons'
|
||||||
frame_fn: frame
|
frame_fn: frame
|
||||||
)
|
)
|
||||||
context.run()
|
context.run()
|
||||||
}
|
}
|
||||||
|
|
|
@ -50,13 +50,13 @@ fn graphics_frame(mut state AppState) {
|
||||||
fn main() {
|
fn main() {
|
||||||
mut state := &AppState{}
|
mut state := &AppState{}
|
||||||
state.gg = gg.new_context(
|
state.gg = gg.new_context(
|
||||||
width: 800
|
width: 800
|
||||||
height: 600
|
height: 600
|
||||||
create_window: true
|
create_window: true
|
||||||
window_title: 'Random Static'
|
window_title: 'Random Static'
|
||||||
init_fn: graphics_init
|
init_fn: graphics_init
|
||||||
frame_fn: graphics_frame
|
frame_fn: graphics_frame
|
||||||
user_data: state
|
user_data: state
|
||||||
)
|
)
|
||||||
spawn state.update()
|
spawn state.update()
|
||||||
state.gg.run()
|
state.gg.run()
|
||||||
|
|
|
@ -67,14 +67,14 @@ fn main() {
|
||||||
font_path = 'fonts/RobotoMono-Regular.ttf'
|
font_path = 'fonts/RobotoMono-Regular.ttf'
|
||||||
}
|
}
|
||||||
app.gg = gg.new_context(
|
app.gg = gg.new_context(
|
||||||
width: win_width
|
width: win_width
|
||||||
height: win_height
|
height: win_height
|
||||||
create_window: true
|
create_window: true
|
||||||
window_title: 'Raven text'
|
window_title: 'Raven text'
|
||||||
user_data: app
|
user_data: app
|
||||||
bg_color: bg_color
|
bg_color: bg_color
|
||||||
frame_fn: frame
|
frame_fn: frame
|
||||||
font_path: font_path // window_user_ptr: ctx
|
font_path: font_path // window_user_ptr: ctx
|
||||||
// native_rendering: true
|
// native_rendering: true
|
||||||
)
|
)
|
||||||
app.gg.run()
|
app.gg.run()
|
||||||
|
|
|
@ -55,13 +55,13 @@ fn main() {
|
||||||
calc_deltas(mut app)
|
calc_deltas(mut app)
|
||||||
|
|
||||||
app.ctx = gg.new_context(
|
app.ctx = gg.new_context(
|
||||||
user_data: &app
|
user_data: &app
|
||||||
window_title: 'Raycaster Demo'
|
window_title: 'Raycaster Demo'
|
||||||
width: 1024
|
width: 1024
|
||||||
height: 512
|
height: 512
|
||||||
bg_color: gx.gray
|
bg_color: gx.gray
|
||||||
frame_fn: draw
|
frame_fn: draw
|
||||||
event_fn: handle_events
|
event_fn: handle_events
|
||||||
)
|
)
|
||||||
|
|
||||||
app.ctx.run()
|
app.ctx.run()
|
||||||
|
@ -217,7 +217,7 @@ fn draw_rays_and_walls(app App) {
|
||||||
wall_offset := max_wall_height / 2 - wall_height / 2
|
wall_offset := max_wall_height / 2 - wall_height / 2
|
||||||
app.ctx.draw_line_with_config(step * line_thickeness + offset_3d_view, wall_offset,
|
app.ctx.draw_line_with_config(step * line_thickeness + offset_3d_view, wall_offset,
|
||||||
step * line_thickeness + offset_3d_view, wall_offset + wall_height, gg.PenConfig{
|
step * line_thickeness + offset_3d_view, wall_offset + wall_height, gg.PenConfig{
|
||||||
color: color
|
color: color
|
||||||
thickness: line_thickeness
|
thickness: line_thickeness
|
||||||
})
|
})
|
||||||
// step to next ray angle
|
// step to next ray angle
|
||||||
|
|
|
@ -16,14 +16,14 @@ mut:
|
||||||
fn main() {
|
fn main() {
|
||||||
mut app := &App{}
|
mut app := &App{}
|
||||||
app.gg = gg.new_context(
|
app.gg = gg.new_context(
|
||||||
bg_color: gx.white
|
bg_color: gx.white
|
||||||
width: win_width
|
width: win_width
|
||||||
height: win_height
|
height: win_height
|
||||||
create_window: true
|
create_window: true
|
||||||
window_title: 'Rectangles'
|
window_title: 'Rectangles'
|
||||||
frame_fn: frame
|
frame_fn: frame
|
||||||
user_data: app
|
user_data: app
|
||||||
init_fn: init_images
|
init_fn: init_images
|
||||||
)
|
)
|
||||||
mut logo_path := os.resource_abs_path(os.join_path('..', 'assets', 'logo.png'))
|
mut logo_path := os.resource_abs_path(os.join_path('..', 'assets', 'logo.png'))
|
||||||
app.image = app.gg.create_image(logo_path)!.id
|
app.image = app.gg.create_image(logo_path)!.id
|
||||||
|
|
|
@ -43,12 +43,12 @@ fn main() {
|
||||||
mut window := &Window{}
|
mut window := &Window{}
|
||||||
window.ctx = gg.new_context(
|
window.ctx = gg.new_context(
|
||||||
window_title: 'Rotating V logo'
|
window_title: 'Rotating V logo'
|
||||||
bg_color: gx.light_green
|
bg_color: gx.light_green
|
||||||
width: 800
|
width: 800
|
||||||
height: 800
|
height: 800
|
||||||
user_data: window
|
user_data: window
|
||||||
init_fn: window.init
|
init_fn: window.init
|
||||||
frame_fn: window.draw
|
frame_fn: window.draw
|
||||||
)
|
)
|
||||||
window.ctx.run()
|
window.ctx.run()
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,12 +8,12 @@ fn main() {
|
||||||
scount := os.args[1] or { '2' }.int()
|
scount := os.args[1] or { '2' }.int()
|
||||||
println('> sample count: ${scount}')
|
println('> sample count: ${scount}')
|
||||||
mut ctx := gg.new_context(
|
mut ctx := gg.new_context(
|
||||||
bg_color: gx.white
|
bg_color: gx.white
|
||||||
window_title: 'sample_count: ${scount}'
|
window_title: 'sample_count: ${scount}'
|
||||||
width: 320
|
width: 320
|
||||||
height: 240
|
height: 240
|
||||||
sample_count: scount
|
sample_count: scount
|
||||||
frame_fn: fn (mut ctx gg.Context) {
|
frame_fn: fn (mut ctx gg.Context) {
|
||||||
ctx.begin()
|
ctx.begin()
|
||||||
ctx.draw_rounded_rect_empty(110, 70, 100, 100, 10, gx.blue)
|
ctx.draw_rounded_rect_empty(110, 70, 100, 100, 10, gx.blue)
|
||||||
ctx.draw_circle_empty(160, 120, 100, gx.red)
|
ctx.draw_circle_empty(160, 120, 100, gx.red)
|
||||||
|
|
|
@ -19,11 +19,11 @@ mut k := 497
|
||||||
mut scale := 200
|
mut scale := 200
|
||||||
gg.start(
|
gg.start(
|
||||||
window_title: 'Spirograph'
|
window_title: 'Spirograph'
|
||||||
bg_color: background
|
bg_color: background
|
||||||
width: 900
|
width: 900
|
||||||
height: 950
|
height: 950
|
||||||
sample_count: 2
|
sample_count: 2
|
||||||
frame_fn: fn [mut k, mut scale] (mut ctx gg.Context) {
|
frame_fn: fn [mut k, mut scale] (mut ctx gg.Context) {
|
||||||
wsize := gg.window_size()
|
wsize := gg.window_size()
|
||||||
ctx.begin()
|
ctx.begin()
|
||||||
ctx.draw_rect_filled(0, 0, wsize.width, wsize.height, gg.Color{10, 1, 30, 60})
|
ctx.draw_rect_filled(0, 0, wsize.width, wsize.height, gg.Color{10, 1, 30, 60})
|
||||||
|
|
|
@ -43,18 +43,18 @@ mut:
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
mut app := &App{
|
mut app := &App{
|
||||||
stars: []Star{len: max_stars}
|
stars: []Star{len: max_stars}
|
||||||
v_letters: []VLetter{len: max_v_letters}
|
v_letters: []VLetter{len: max_v_letters}
|
||||||
}
|
}
|
||||||
app.gg = gg.new_context(
|
app.gg = gg.new_context(
|
||||||
bg_color: gx.black
|
bg_color: gx.black
|
||||||
width: win_width
|
width: win_width
|
||||||
height: win_height
|
height: win_height
|
||||||
create_window: true
|
create_window: true
|
||||||
window_title: 'Star Vield'
|
window_title: 'Star Vield'
|
||||||
frame_fn: frame
|
frame_fn: frame
|
||||||
init_fn: init_images
|
init_fn: init_images
|
||||||
user_data: app
|
user_data: app
|
||||||
)
|
)
|
||||||
for i in 0 .. max_stars {
|
for i in 0 .. max_stars {
|
||||||
app.stars[i].x = rand.f32_in_range(-200.0, 200.0) or { -200.0 }
|
app.stars[i].x = rand.f32_in_range(-200.0, 200.0) or { -200.0 }
|
||||||
|
|
|
@ -24,14 +24,14 @@ mut:
|
||||||
fn main() {
|
fn main() {
|
||||||
mut app := &App{}
|
mut app := &App{}
|
||||||
app.gg = gg.new_context(
|
app.gg = gg.new_context(
|
||||||
width: win_width
|
width: win_width
|
||||||
height: win_height
|
height: win_height
|
||||||
create_window: true
|
create_window: true
|
||||||
window_title: 'Counter'
|
window_title: 'Counter'
|
||||||
user_data: app
|
user_data: app
|
||||||
bg_color: bg_color
|
bg_color: bg_color
|
||||||
frame_fn: frame
|
frame_fn: frame
|
||||||
init_fn: init
|
init_fn: init
|
||||||
)
|
)
|
||||||
app.gg.run()
|
app.gg.run()
|
||||||
}
|
}
|
||||||
|
|
|
@ -24,21 +24,21 @@ const width = 50
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
mut game := &Game{
|
mut game := &Game{
|
||||||
dx: 2
|
dx: 2
|
||||||
dy: 2
|
dy: 2
|
||||||
height: window_height
|
height: window_height
|
||||||
width: window_width
|
width: window_width
|
||||||
draw_fn: 0
|
draw_fn: 0
|
||||||
}
|
}
|
||||||
game.gg = gg.new_context(
|
game.gg = gg.new_context(
|
||||||
width: window_width
|
width: window_width
|
||||||
height: window_height
|
height: window_height
|
||||||
font_size: 20
|
font_size: 20
|
||||||
user_data: game
|
user_data: game
|
||||||
window_title: 'Hot code reloading demo'
|
window_title: 'Hot code reloading demo'
|
||||||
create_window: true
|
create_window: true
|
||||||
frame_fn: frame
|
frame_fn: frame
|
||||||
bg_color: gx.white
|
bg_color: gx.white
|
||||||
)
|
)
|
||||||
// window.onkeydown(key_down)
|
// window.onkeydown(key_down)
|
||||||
println('Starting the game loop...')
|
println('Starting the game loop...')
|
||||||
|
|
|
@ -16,15 +16,15 @@ mut:
|
||||||
fn main() {
|
fn main() {
|
||||||
mut context := &Context{}
|
mut context := &Context{}
|
||||||
context.gg = gg.new_context(
|
context.gg = gg.new_context(
|
||||||
width: size
|
width: size
|
||||||
height: size
|
height: size
|
||||||
font_size: 20
|
font_size: 20
|
||||||
user_data: context
|
user_data: context
|
||||||
window_title: 'Graph builder'
|
window_title: 'Graph builder'
|
||||||
create_window: true
|
create_window: true
|
||||||
frame_fn: frame
|
frame_fn: frame
|
||||||
resizable: true
|
resizable: true
|
||||||
bg_color: gx.white
|
bg_color: gx.white
|
||||||
)
|
)
|
||||||
context.gg.run()
|
context.gg.run()
|
||||||
}
|
}
|
||||||
|
|
|
@ -162,9 +162,9 @@ fn v_sqlite_file() !FrameworkBenchmarkResponse {
|
||||||
// res := http.get(url) or { panic(err) }
|
// res := http.get(url) or { panic(err) }
|
||||||
// framework_benchmark_response := json.decode(FrameworkBenchmarkResponse, res.body)!
|
// framework_benchmark_response := json.decode(FrameworkBenchmarkResponse, res.body)!
|
||||||
framework_benchmark_response := FrameworkBenchmarkResponse{
|
framework_benchmark_response := FrameworkBenchmarkResponse{
|
||||||
insert: []
|
insert: []
|
||||||
@select: []
|
@select: []
|
||||||
update: []
|
update: []
|
||||||
}
|
}
|
||||||
return framework_benchmark_response
|
return framework_benchmark_response
|
||||||
}
|
}
|
||||||
|
|
|
@ -53,7 +53,7 @@ pub fn (mut app App) sqlite_memory(count int) vweb.Result {
|
||||||
} or { panic(err) }
|
} or { panic(err) }
|
||||||
|
|
||||||
task_model := Task{
|
task_model := Task{
|
||||||
title: 'a'
|
title: 'a'
|
||||||
status: 'done'
|
status: 'done'
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -93,9 +93,9 @@ pub fn (mut app App) sqlite_memory(count int) vweb.Result {
|
||||||
} or { panic(err) }
|
} or { panic(err) }
|
||||||
|
|
||||||
response := Response{
|
response := Response{
|
||||||
insert: insert_stopwatchs
|
insert: insert_stopwatchs
|
||||||
@select: select_stopwatchs
|
@select: select_stopwatchs
|
||||||
update: update_stopwatchs
|
update: update_stopwatchs
|
||||||
}
|
}
|
||||||
return app.json(response)
|
return app.json(response)
|
||||||
}
|
}
|
||||||
|
@ -103,9 +103,9 @@ pub fn (mut app App) sqlite_memory(count int) vweb.Result {
|
||||||
@['/sqlite-file/:count']
|
@['/sqlite-file/:count']
|
||||||
pub fn (mut app App) sqlite_file(count int) vweb.Result {
|
pub fn (mut app App) sqlite_file(count int) vweb.Result {
|
||||||
response := Response{
|
response := Response{
|
||||||
insert: []
|
insert: []
|
||||||
@select: []
|
@select: []
|
||||||
update: []
|
update: []
|
||||||
}
|
}
|
||||||
return app.json(response)
|
return app.json(response)
|
||||||
}
|
}
|
||||||
|
@ -113,9 +113,9 @@ pub fn (mut app App) sqlite_file(count int) vweb.Result {
|
||||||
@['/postgres/:count']
|
@['/postgres/:count']
|
||||||
pub fn (mut app App) postgres(count int) vweb.Result {
|
pub fn (mut app App) postgres(count int) vweb.Result {
|
||||||
response := Response{
|
response := Response{
|
||||||
insert: []
|
insert: []
|
||||||
@select: []
|
@select: []
|
||||||
update: []
|
update: []
|
||||||
}
|
}
|
||||||
return app.json(response)
|
return app.json(response)
|
||||||
}
|
}
|
||||||
|
@ -123,9 +123,9 @@ pub fn (mut app App) postgres(count int) vweb.Result {
|
||||||
@['/mysql/:count']
|
@['/mysql/:count']
|
||||||
pub fn (mut app App) mysql(count int) vweb.Result {
|
pub fn (mut app App) mysql(count int) vweb.Result {
|
||||||
response := Response{
|
response := Response{
|
||||||
insert: []
|
insert: []
|
||||||
@select: []
|
@select: []
|
||||||
update: []
|
update: []
|
||||||
}
|
}
|
||||||
return app.json(response)
|
return app.json(response)
|
||||||
}
|
}
|
||||||
|
|
|
@ -39,11 +39,11 @@ fn linearrelationship(independent_variable []int, dependent_variable []int) Line
|
||||||
// R2 = n(∑xy) - (∑x)(∑y) / sqrt([n(∑x²)-(∑x)²][n(∑y²)-(∑y)²]
|
// R2 = n(∑xy) - (∑x)(∑y) / sqrt([n(∑x²)-(∑x)²][n(∑y²)-(∑y)²]
|
||||||
r2_value := f64((independent_variable.len * sum_xy) - (sum_x * sum_y)) / math.sqrt(f64((sum_r2_x * independent_variable.len) - (sum_x * sum_x)) * f64((sum_r2_y * dependent_variable.len) - (sum_y * sum_y)))
|
r2_value := f64((independent_variable.len * sum_xy) - (sum_x * sum_y)) / math.sqrt(f64((sum_r2_x * independent_variable.len) - (sum_x * sum_x)) * f64((sum_r2_y * dependent_variable.len) - (sum_y * sum_y)))
|
||||||
return LinearResult{
|
return LinearResult{
|
||||||
r2: r2_value
|
r2: r2_value
|
||||||
intercept: intercept_value
|
intercept: intercept_value
|
||||||
slope: slope_value
|
slope: slope_value
|
||||||
independent_variable_means: x_means
|
independent_variable_means: x_means
|
||||||
dependent_variable_means: y_means
|
dependent_variable_means: y_means
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -52,10 +52,10 @@ fn main() {
|
||||||
|
|
||||||
my_app.tray_info = C.tray_app_init(TrayParams{
|
my_app.tray_info = C.tray_app_init(TrayParams{
|
||||||
items: [TrayMenuItem{
|
items: [TrayMenuItem{
|
||||||
id: 'hello'
|
id: 'hello'
|
||||||
text: 'Hello'
|
text: 'Hello'
|
||||||
}, TrayMenuItem{
|
}, TrayMenuItem{
|
||||||
id: 'quit'
|
id: 'quit'
|
||||||
text: 'Quit!'
|
text: 'Quit!'
|
||||||
}]
|
}]
|
||||||
on_click: my_app.on_menu_item_click
|
on_click: my_app.on_menu_item_click
|
||||||
|
|
|
@ -88,9 +88,9 @@ struct Image {
|
||||||
fn new_image(w int, h int) Image {
|
fn new_image(w int, h int) Image {
|
||||||
vecsize := int(sizeof(Vec))
|
vecsize := int(sizeof(Vec))
|
||||||
return Image{
|
return Image{
|
||||||
width: w
|
width: w
|
||||||
height: h
|
height: h
|
||||||
data: unsafe { &Vec(vcalloc(vecsize * w * h)) }
|
data: unsafe { &Vec(vcalloc(vecsize * w * h)) }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -166,154 +166,154 @@ const cen = Vec{50, 40.8, -860} // used by scene 1
|
||||||
const spheres = [
|
const spheres = [
|
||||||
[// scene 0 cornnel box
|
[// scene 0 cornnel box
|
||||||
Sphere{
|
Sphere{
|
||||||
rad: 1e+5
|
rad: 1e+5
|
||||||
p: Vec{1e+5 + 1, 40.8, 81.6}
|
p: Vec{1e+5 + 1, 40.8, 81.6}
|
||||||
e: Vec{}
|
e: Vec{}
|
||||||
c: Vec{.75, .25, .25}
|
c: Vec{.75, .25, .25}
|
||||||
refl: .diff
|
refl: .diff
|
||||||
}, // Left
|
}, // Left
|
||||||
Sphere{
|
Sphere{
|
||||||
rad: 1e+5
|
rad: 1e+5
|
||||||
p: Vec{-1e+5 + 99, 40.8, 81.6}
|
p: Vec{-1e+5 + 99, 40.8, 81.6}
|
||||||
e: Vec{}
|
e: Vec{}
|
||||||
c: Vec{.25, .25, .75}
|
c: Vec{.25, .25, .75}
|
||||||
refl: .diff
|
refl: .diff
|
||||||
}, // Rght
|
}, // Rght
|
||||||
Sphere{
|
Sphere{
|
||||||
rad: 1e+5
|
rad: 1e+5
|
||||||
p: Vec{50, 40.8, 1e+5}
|
p: Vec{50, 40.8, 1e+5}
|
||||||
e: Vec{}
|
e: Vec{}
|
||||||
c: Vec{.75, .75, .75}
|
c: Vec{.75, .75, .75}
|
||||||
refl: .diff
|
refl: .diff
|
||||||
}, // Back
|
}, // Back
|
||||||
Sphere{
|
Sphere{
|
||||||
rad: 1e+5
|
rad: 1e+5
|
||||||
p: Vec{50, 40.8, -1e+5 + 170}
|
p: Vec{50, 40.8, -1e+5 + 170}
|
||||||
e: Vec{}
|
e: Vec{}
|
||||||
c: Vec{}
|
c: Vec{}
|
||||||
refl: .diff
|
refl: .diff
|
||||||
}, // Frnt
|
}, // Frnt
|
||||||
Sphere{
|
Sphere{
|
||||||
rad: 1e+5
|
rad: 1e+5
|
||||||
p: Vec{50, 1e+5, 81.6}
|
p: Vec{50, 1e+5, 81.6}
|
||||||
e: Vec{}
|
e: Vec{}
|
||||||
c: Vec{.75, .75, .75}
|
c: Vec{.75, .75, .75}
|
||||||
refl: .diff
|
refl: .diff
|
||||||
}, // Botm
|
}, // Botm
|
||||||
Sphere{
|
Sphere{
|
||||||
rad: 1e+5
|
rad: 1e+5
|
||||||
p: Vec{50, -1e+5 + 81.6, 81.6}
|
p: Vec{50, -1e+5 + 81.6, 81.6}
|
||||||
e: Vec{}
|
e: Vec{}
|
||||||
c: Vec{.75, .75, .75}
|
c: Vec{.75, .75, .75}
|
||||||
refl: .diff
|
refl: .diff
|
||||||
}, // Top
|
}, // Top
|
||||||
Sphere{
|
Sphere{
|
||||||
rad: 16.5
|
rad: 16.5
|
||||||
p: Vec{27, 16.5, 47}
|
p: Vec{27, 16.5, 47}
|
||||||
e: Vec{}
|
e: Vec{}
|
||||||
c: Vec{1, 1, 1}.mult_s(.999)
|
c: Vec{1, 1, 1}.mult_s(.999)
|
||||||
refl: .spec
|
refl: .spec
|
||||||
}, // Mirr
|
}, // Mirr
|
||||||
Sphere{
|
Sphere{
|
||||||
rad: 16.5
|
rad: 16.5
|
||||||
p: Vec{73, 16.5, 78}
|
p: Vec{73, 16.5, 78}
|
||||||
e: Vec{}
|
e: Vec{}
|
||||||
c: Vec{1, 1, 1}.mult_s(.999)
|
c: Vec{1, 1, 1}.mult_s(.999)
|
||||||
refl: .refr
|
refl: .refr
|
||||||
}, // Glas
|
}, // Glas
|
||||||
Sphere{
|
Sphere{
|
||||||
rad: 600
|
rad: 600
|
||||||
p: Vec{50, 681.6 - .27, 81.6}
|
p: Vec{50, 681.6 - .27, 81.6}
|
||||||
e: Vec{12, 12, 12}
|
e: Vec{12, 12, 12}
|
||||||
c: Vec{}
|
c: Vec{}
|
||||||
refl: .diff
|
refl: .diff
|
||||||
}, // Lite
|
}, // Lite
|
||||||
],
|
],
|
||||||
[// scene 1 sunset
|
[// scene 1 sunset
|
||||||
Sphere{
|
Sphere{
|
||||||
rad: 1600
|
rad: 1600
|
||||||
p: Vec{1.0, 0.0, 2.0}.mult_s(3000)
|
p: Vec{1.0, 0.0, 2.0}.mult_s(3000)
|
||||||
e: Vec{1.0, .9, .8}.mult_s(1.2e+1 * 1.56 * 2)
|
e: Vec{1.0, .9, .8}.mult_s(1.2e+1 * 1.56 * 2)
|
||||||
c: Vec{}
|
c: Vec{}
|
||||||
refl: .diff
|
refl: .diff
|
||||||
}, // sun
|
}, // sun
|
||||||
Sphere{
|
Sphere{
|
||||||
rad: 1560
|
rad: 1560
|
||||||
p: Vec{1, 0, 2}.mult_s(3500)
|
p: Vec{1, 0, 2}.mult_s(3500)
|
||||||
e: Vec{1.0, .5, .05}.mult_s(4.8e+1 * 1.56 * 2)
|
e: Vec{1.0, .5, .05}.mult_s(4.8e+1 * 1.56 * 2)
|
||||||
c: Vec{}
|
c: Vec{}
|
||||||
refl: .diff
|
refl: .diff
|
||||||
}, // horizon sun2
|
}, // horizon sun2
|
||||||
Sphere{
|
Sphere{
|
||||||
rad: 10000
|
rad: 10000
|
||||||
p: cen + Vec{0, 0, -200}
|
p: cen + Vec{0, 0, -200}
|
||||||
e: Vec{0.00063842, 0.02001478, 0.28923243}.mult_s(6e-2 * 8)
|
e: Vec{0.00063842, 0.02001478, 0.28923243}.mult_s(6e-2 * 8)
|
||||||
c: Vec{.7, .7, 1}.mult_s(.25)
|
c: Vec{.7, .7, 1}.mult_s(.25)
|
||||||
refl: .diff
|
refl: .diff
|
||||||
}, // sky
|
}, // sky
|
||||||
Sphere{
|
Sphere{
|
||||||
rad: 100000
|
rad: 100000
|
||||||
p: Vec{50, -100000, 0}
|
p: Vec{50, -100000, 0}
|
||||||
e: Vec{}
|
e: Vec{}
|
||||||
c: Vec{.3, .3, .3}
|
c: Vec{.3, .3, .3}
|
||||||
refl: .diff
|
refl: .diff
|
||||||
}, // grnd
|
}, // grnd
|
||||||
Sphere{
|
Sphere{
|
||||||
rad: 110000
|
rad: 110000
|
||||||
p: Vec{50, -110048.5, 0}
|
p: Vec{50, -110048.5, 0}
|
||||||
e: Vec{.9, .5, .05}.mult_s(4)
|
e: Vec{.9, .5, .05}.mult_s(4)
|
||||||
c: Vec{}
|
c: Vec{}
|
||||||
refl: .diff
|
refl: .diff
|
||||||
}, // horizon brightener
|
}, // horizon brightener
|
||||||
Sphere{
|
Sphere{
|
||||||
rad: 4e+4
|
rad: 4e+4
|
||||||
p: Vec{50, -4e+4 - 30, -3000}
|
p: Vec{50, -4e+4 - 30, -3000}
|
||||||
e: Vec{}
|
e: Vec{}
|
||||||
c: Vec{.2, .2, .2}
|
c: Vec{.2, .2, .2}
|
||||||
refl: .diff
|
refl: .diff
|
||||||
}, // mountains
|
}, // mountains
|
||||||
Sphere{
|
Sphere{
|
||||||
rad: 26.5
|
rad: 26.5
|
||||||
p: Vec{22, 26.5, 42}
|
p: Vec{22, 26.5, 42}
|
||||||
e: Vec{}
|
e: Vec{}
|
||||||
c: Vec{1, 1, 1}.mult_s(.596)
|
c: Vec{1, 1, 1}.mult_s(.596)
|
||||||
refl: .spec
|
refl: .spec
|
||||||
}, // white Mirr
|
}, // white Mirr
|
||||||
Sphere{
|
Sphere{
|
||||||
rad: 13
|
rad: 13
|
||||||
p: Vec{75, 13, 82}
|
p: Vec{75, 13, 82}
|
||||||
e: Vec{}
|
e: Vec{}
|
||||||
c: Vec{.96, .96, .96}.mult_s(.96)
|
c: Vec{.96, .96, .96}.mult_s(.96)
|
||||||
refl: .refr
|
refl: .refr
|
||||||
}, // Glas
|
}, // Glas
|
||||||
Sphere{
|
Sphere{
|
||||||
rad: 22
|
rad: 22
|
||||||
p: Vec{87, 22, 24}
|
p: Vec{87, 22, 24}
|
||||||
e: Vec{}
|
e: Vec{}
|
||||||
c: Vec{.6, .6, .6}.mult_s(.696)
|
c: Vec{.6, .6, .6}.mult_s(.696)
|
||||||
refl: .refr
|
refl: .refr
|
||||||
}, // Glas2
|
}, // Glas2
|
||||||
],
|
],
|
||||||
[// scene 3 Psychedelic
|
[// scene 3 Psychedelic
|
||||||
Sphere{
|
Sphere{
|
||||||
rad: 150
|
rad: 150
|
||||||
p: Vec{50 + 75, 28, 62}
|
p: Vec{50 + 75, 28, 62}
|
||||||
e: Vec{1, 1, 1}.mult_s(0e-3)
|
e: Vec{1, 1, 1}.mult_s(0e-3)
|
||||||
c: Vec{1, .9, .8}.mult_s(.93)
|
c: Vec{1, .9, .8}.mult_s(.93)
|
||||||
refl: .refr
|
refl: .refr
|
||||||
},
|
},
|
||||||
Sphere{
|
Sphere{
|
||||||
rad: 28
|
rad: 28
|
||||||
p: Vec{50 + 5, -28, 62}
|
p: Vec{50 + 5, -28, 62}
|
||||||
e: Vec{1, 1, 1}.mult_s(1e+1)
|
e: Vec{1, 1, 1}.mult_s(1e+1)
|
||||||
c: Vec{1, 1, 1}.mult_s(0)
|
c: Vec{1, 1, 1}.mult_s(0)
|
||||||
refl: .diff
|
refl: .diff
|
||||||
},
|
},
|
||||||
Sphere{
|
Sphere{
|
||||||
rad: 300
|
rad: 300
|
||||||
p: Vec{50, 28, 62}
|
p: Vec{50, 28, 62}
|
||||||
e: Vec{1, 1, 1}.mult_s(0e-3)
|
e: Vec{1, 1, 1}.mult_s(0e-3)
|
||||||
c: Vec{1, 1, 1}.mult_s(.93)
|
c: Vec{1, 1, 1}.mult_s(.93)
|
||||||
refl: .spec
|
refl: .spec
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
|
|
|
@ -50,7 +50,7 @@ fn main() {
|
||||||
spawn app.gg.run()
|
spawn app.gg.run()
|
||||||
|
|
||||||
sim.run(app.args.params,
|
sim.run(app.args.params,
|
||||||
grid: app.args.grid
|
grid: app.args.grid
|
||||||
on_request: sim.SimRequestHandler(handle_request)
|
on_request: sim.SimRequestHandler(handle_request)
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
|
@ -28,19 +28,19 @@ pub fn new_app(args simargs.ParallelArgs) &App {
|
||||||
total_pixels := args.grid.height * args.grid.width
|
total_pixels := args.grid.height * args.grid.width
|
||||||
|
|
||||||
mut app := &App{
|
mut app := &App{
|
||||||
args: args
|
args: args
|
||||||
pixels: []u32{len: total_pixels}
|
pixels: []u32{len: total_pixels}
|
||||||
request_chan: chan &sim.SimRequest{cap: args.grid.width}
|
request_chan: chan &sim.SimRequest{cap: args.grid.width}
|
||||||
}
|
}
|
||||||
app.gg = gg.new_context(
|
app.gg = gg.new_context(
|
||||||
width: args.grid.width
|
width: args.grid.width
|
||||||
height: args.grid.height
|
height: args.grid.height
|
||||||
create_window: true
|
create_window: true
|
||||||
window_title: 'V Pendulum Simulation'
|
window_title: 'V Pendulum Simulation'
|
||||||
user_data: app
|
user_data: app
|
||||||
bg_color: anim.bg_color
|
bg_color: anim.bg_color
|
||||||
frame_fn: frame
|
frame_fn: frame
|
||||||
init_fn: init
|
init_fn: init
|
||||||
)
|
)
|
||||||
return app
|
return app
|
||||||
}
|
}
|
||||||
|
|
|
@ -69,23 +69,23 @@ fn parse_sequential_args() !SequentialArgs {
|
||||||
}
|
}
|
||||||
|
|
||||||
params := sim.sim_params(
|
params := sim.sim_params(
|
||||||
rope_length: rope_length
|
rope_length: rope_length
|
||||||
bearing_mass: bearing_mass
|
bearing_mass: bearing_mass
|
||||||
magnet_spacing: magnet_spacing
|
magnet_spacing: magnet_spacing
|
||||||
magnet_height: magnet_height
|
magnet_height: magnet_height
|
||||||
magnet_strength: magnet_strength
|
magnet_strength: magnet_strength
|
||||||
gravity: gravity
|
gravity: gravity
|
||||||
)
|
)
|
||||||
|
|
||||||
grid := sim.new_grid_settings(
|
grid := sim.new_grid_settings(
|
||||||
width: width
|
width: width
|
||||||
height: height
|
height: height
|
||||||
)
|
)
|
||||||
|
|
||||||
args := SequentialArgs{
|
args := SequentialArgs{
|
||||||
params: params
|
params: params
|
||||||
filename: filename
|
filename: filename
|
||||||
grid: grid
|
grid: grid
|
||||||
}
|
}
|
||||||
|
|
||||||
sim.log('${args}')
|
sim.log('${args}')
|
||||||
|
@ -122,24 +122,24 @@ fn parse_parallel_args(extra_workers int) !ParallelArgs {
|
||||||
}
|
}
|
||||||
|
|
||||||
params := sim.sim_params(
|
params := sim.sim_params(
|
||||||
rope_length: rope_length
|
rope_length: rope_length
|
||||||
bearing_mass: bearing_mass
|
bearing_mass: bearing_mass
|
||||||
magnet_spacing: magnet_spacing
|
magnet_spacing: magnet_spacing
|
||||||
magnet_height: magnet_height
|
magnet_height: magnet_height
|
||||||
magnet_strength: magnet_strength
|
magnet_strength: magnet_strength
|
||||||
gravity: gravity
|
gravity: gravity
|
||||||
)
|
)
|
||||||
|
|
||||||
grid := sim.new_grid_settings(
|
grid := sim.new_grid_settings(
|
||||||
width: width
|
width: width
|
||||||
height: height
|
height: height
|
||||||
)
|
)
|
||||||
|
|
||||||
args := ParallelArgs{
|
args := ParallelArgs{
|
||||||
params: params
|
params: params
|
||||||
filename: filename
|
filename: filename
|
||||||
grid: grid
|
grid: grid
|
||||||
workers: get_workers(workers, extra_workers)
|
workers: get_workers(workers, extra_workers)
|
||||||
}
|
}
|
||||||
sim.log('${args}')
|
sim.log('${args}')
|
||||||
|
|
||||||
|
|
|
@ -20,14 +20,14 @@ pub fn new_image_settings(settings ImageSettings) ImageSettings {
|
||||||
|
|
||||||
pub fn image_settings_from_grid(grid sim.GridSettings) ImageSettings {
|
pub fn image_settings_from_grid(grid sim.GridSettings) ImageSettings {
|
||||||
return ImageSettings{
|
return ImageSettings{
|
||||||
width: grid.width
|
width: grid.width
|
||||||
height: grid.height
|
height: grid.height
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn (s ImageSettings) to_grid_settings() sim.GridSettings {
|
pub fn (s ImageSettings) to_grid_settings() sim.GridSettings {
|
||||||
return sim.GridSettings{
|
return sim.GridSettings{
|
||||||
width: s.width
|
width: s.width
|
||||||
height: s.height
|
height: s.height
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -42,7 +42,7 @@ mut:
|
||||||
pub fn ppm_writer_for_fname(fname string, settings ImageSettings) !&PPMWriter {
|
pub fn ppm_writer_for_fname(fname string, settings ImageSettings) !&PPMWriter {
|
||||||
mut writer := &PPMWriter{
|
mut writer := &PPMWriter{
|
||||||
cache_size: settings.cache_size
|
cache_size: settings.cache_size
|
||||||
cache: []u8{cap: settings.cache_size}
|
cache: []u8{cap: settings.cache_size}
|
||||||
}
|
}
|
||||||
writer.start_for_file(fname, settings)!
|
writer.start_for_file(fname, settings)!
|
||||||
return writer
|
return writer
|
||||||
|
|
|
@ -23,9 +23,9 @@ pub fn new_image_writer(mut writer PPMWriter, settings ImageSettings) &ImageWrit
|
||||||
valid: false
|
valid: false
|
||||||
}}
|
}}
|
||||||
return &ImageWriter{
|
return &ImageWriter{
|
||||||
writer: writer
|
writer: writer
|
||||||
settings: settings
|
settings: settings
|
||||||
buffer: buffer
|
buffer: buffer
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -3,12 +3,12 @@ module sim
|
||||||
import math
|
import math
|
||||||
|
|
||||||
const params_test_mock_params = SimParams{
|
const params_test_mock_params = SimParams{
|
||||||
rope_length: 0.25
|
rope_length: 0.25
|
||||||
bearing_mass: 0.03
|
bearing_mass: 0.03
|
||||||
magnet_spacing: 0.05
|
magnet_spacing: 0.05
|
||||||
magnet_height: 0.03
|
magnet_height: 0.03
|
||||||
magnet_strength: 10
|
magnet_strength: 10
|
||||||
gravity: 4.9
|
gravity: 4.9
|
||||||
}
|
}
|
||||||
const params_test_mock_state = SimState{
|
const params_test_mock_state = SimState{
|
||||||
position: vector(
|
position: vector(
|
||||||
|
|
|
@ -70,8 +70,8 @@ pub fn run(params SimParams, settings RunnerSettings) {
|
||||||
|
|
||||||
state.satisfy_rope_constraint(params)
|
state.satisfy_rope_constraint(params)
|
||||||
request := &SimRequest{
|
request := &SimRequest{
|
||||||
id: index
|
id: index
|
||||||
state: state
|
state: state
|
||||||
params: params
|
params: params
|
||||||
}
|
}
|
||||||
settings.on_request(request) or {
|
settings.on_request(request) or {
|
||||||
|
|
|
@ -1,12 +1,12 @@
|
||||||
module sim
|
module sim
|
||||||
|
|
||||||
const sim_test_mock_params = SimParams{
|
const sim_test_mock_params = SimParams{
|
||||||
rope_length: 0.25
|
rope_length: 0.25
|
||||||
bearing_mass: 0.03
|
bearing_mass: 0.03
|
||||||
magnet_spacing: 0.05
|
magnet_spacing: 0.05
|
||||||
magnet_height: 0.03
|
magnet_height: 0.03
|
||||||
magnet_strength: 10
|
magnet_strength: 10
|
||||||
gravity: 4.9
|
gravity: 4.9
|
||||||
}
|
}
|
||||||
const sim_test_mock_state = SimState{
|
const sim_test_mock_state = SimState{
|
||||||
position: vector(
|
position: vector(
|
||||||
|
|
|
@ -56,8 +56,8 @@ pub fn compute_result(request SimRequest) &SimResult {
|
||||||
id := request.id
|
id := request.id
|
||||||
|
|
||||||
return &SimResult{
|
return &SimResult{
|
||||||
id: id
|
id: id
|
||||||
state: state
|
state: state
|
||||||
magnet1_distance: m1_dist
|
magnet1_distance: m1_dist
|
||||||
magnet2_distance: m2_dist
|
magnet2_distance: m2_dist
|
||||||
magnet3_distance: m3_dist
|
magnet3_distance: m3_dist
|
||||||
|
|
|
@ -1,12 +1,12 @@
|
||||||
module sim
|
module sim
|
||||||
|
|
||||||
const worker_test_mock_params = SimParams{
|
const worker_test_mock_params = SimParams{
|
||||||
rope_length: 0.25
|
rope_length: 0.25
|
||||||
bearing_mass: 0.03
|
bearing_mass: 0.03
|
||||||
magnet_spacing: 0.05
|
magnet_spacing: 0.05
|
||||||
magnet_height: 0.03
|
magnet_height: 0.03
|
||||||
magnet_strength: 10
|
magnet_strength: 10
|
||||||
gravity: 4.9
|
gravity: 4.9
|
||||||
}
|
}
|
||||||
const worker_test_mock_state = SimState{
|
const worker_test_mock_state = SimState{
|
||||||
position: vector(
|
position: vector(
|
||||||
|
@ -28,9 +28,9 @@ const worker_test_mock_state = SimState{
|
||||||
|
|
||||||
fn test_compute_result() {
|
fn test_compute_result() {
|
||||||
request := SimRequest{
|
request := SimRequest{
|
||||||
id: 0
|
id: 0
|
||||||
params: sim.worker_test_mock_params
|
params: sim.worker_test_mock_params
|
||||||
state: sim.worker_test_mock_state
|
state: sim.worker_test_mock_state
|
||||||
}
|
}
|
||||||
expected_state := SimState{
|
expected_state := SimState{
|
||||||
position: vector(
|
position: vector(
|
||||||
|
@ -50,8 +50,8 @@ fn test_compute_result() {
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
expected := &SimResult{
|
expected := &SimResult{
|
||||||
state: expected_state
|
state: expected_state
|
||||||
id: 0
|
id: 0
|
||||||
magnet1_distance: 0.07993696666249225
|
magnet1_distance: 0.07993696666249225
|
||||||
magnet2_distance: 0.07993696666249224
|
magnet2_distance: 0.07993696666249224
|
||||||
magnet3_distance: 0.03609361938278008
|
magnet3_distance: 0.03609361938278008
|
||||||
|
|
|
@ -58,8 +58,8 @@ fn main() {
|
||||||
|
|
||||||
state.satisfy_rope_constraint(args.params)
|
state.satisfy_rope_constraint(args.params)
|
||||||
request := &sim.SimRequest{
|
request := &sim.SimRequest{
|
||||||
id: request_index
|
id: request_index
|
||||||
state: state
|
state: state
|
||||||
params: args.params
|
params: args.params
|
||||||
}
|
}
|
||||||
select {
|
select {
|
||||||
|
|
|
@ -44,7 +44,7 @@ fn main() {
|
||||||
}
|
}
|
||||||
|
|
||||||
sim.run(args.params,
|
sim.run(args.params,
|
||||||
grid: args.grid
|
grid: args.grid
|
||||||
on_request: sim.SimRequestHandler(handle_request)
|
on_request: sim.SimRequestHandler(handle_request)
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,7 +10,7 @@ const http_response = 'HTTP/1.1 200 OK\r\nContent-type: text/html\r\nContent-len
|
||||||
fn main() {
|
fn main() {
|
||||||
println('Starting webserver on http://localhost:${port}/ ...')
|
println('Starting webserver on http://localhost:${port}/ ...')
|
||||||
mut pico := picoev.new(
|
mut pico := picoev.new(
|
||||||
port: port
|
port: port
|
||||||
raw_cb: handle_conn
|
raw_cb: handle_conn
|
||||||
)!
|
)!
|
||||||
pico.serve()
|
pico.serve()
|
||||||
|
@ -19,8 +19,8 @@ fn main() {
|
||||||
fn handle_conn(mut pv picoev.Picoev, fd int, events int) {
|
fn handle_conn(mut pv picoev.Picoev, fd int, events int) {
|
||||||
// setup a nonblocking tcp connection
|
// setup a nonblocking tcp connection
|
||||||
mut conn := &net.TcpConn{
|
mut conn := &net.TcpConn{
|
||||||
sock: net.tcp_socket_from_handle_raw(fd)
|
sock: net.tcp_socket_from_handle_raw(fd)
|
||||||
handle: fd
|
handle: fd
|
||||||
is_blocking: false
|
is_blocking: false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -14,11 +14,11 @@ const timer_period = 40 * time.millisecond // defaulted at 25 fps
|
||||||
|
|
||||||
const font_small = gx.TextCfg{
|
const font_small = gx.TextCfg{
|
||||||
color: gx.black
|
color: gx.black
|
||||||
size: 20
|
size: 20
|
||||||
}
|
}
|
||||||
const font_large = gx.TextCfg{
|
const font_large = gx.TextCfg{
|
||||||
color: gx.black
|
color: gx.black
|
||||||
size: 40
|
size: 40
|
||||||
}
|
}
|
||||||
|
|
||||||
struct App {
|
struct App {
|
||||||
|
@ -96,9 +96,9 @@ fn (mut app App) insert_particles() {
|
||||||
mut x := rand_minmax(0, gridh) * grid
|
mut x := rand_minmax(0, gridh) * grid
|
||||||
mut y := rand_minmax(0, gridv) * grid
|
mut y := rand_minmax(0, gridv) * grid
|
||||||
mut random_particle := datatypes.AABB{
|
mut random_particle := datatypes.AABB{
|
||||||
x: x
|
x: x
|
||||||
y: y
|
y: y
|
||||||
width: rand_minmax(1, 4) * grid
|
width: rand_minmax(1, 4) * grid
|
||||||
height: rand_minmax(1, 4) * grid
|
height: rand_minmax(1, 4) * grid
|
||||||
}
|
}
|
||||||
app.particles << Particle{random_particle, 0.0, 0.0}
|
app.particles << Particle{random_particle, 0.0, 0.0}
|
||||||
|
@ -115,15 +115,15 @@ fn main() {
|
||||||
gg: unsafe { nil }
|
gg: unsafe { nil }
|
||||||
}
|
}
|
||||||
app.gg = gg.new_context(
|
app.gg = gg.new_context(
|
||||||
bg_color: gx.white
|
bg_color: gx.white
|
||||||
width: win_width
|
width: win_width
|
||||||
height: win_height
|
height: win_height
|
||||||
create_window: true
|
create_window: true
|
||||||
window_title: 'Quadtree Demo'
|
window_title: 'Quadtree Demo'
|
||||||
frame_fn: frame
|
frame_fn: frame
|
||||||
event_fn: on_event
|
event_fn: on_event
|
||||||
user_data: app
|
user_data: app
|
||||||
font_path: os.resource_abs_path('../assets/fonts/RobotoMono-Regular.ttf')
|
font_path: os.resource_abs_path('../assets/fonts/RobotoMono-Regular.ttf')
|
||||||
)
|
)
|
||||||
app.qt = app.qt.create(0, 0, 1340, 640, 8, 4, 0)
|
app.qt = app.qt.create(0, 0, 1340, 640, 8, 4, 0)
|
||||||
app.start()
|
app.start()
|
||||||
|
|
|
@ -19,17 +19,17 @@ fn main() {
|
||||||
subject := os.input('Subject: ')
|
subject := os.input('Subject: ')
|
||||||
body := os.input('Body: ')
|
body := os.input('Body: ')
|
||||||
client_cfg := smtp.Client{
|
client_cfg := smtp.Client{
|
||||||
server: mailserver
|
server: mailserver
|
||||||
from: from
|
from: from
|
||||||
port: mailport
|
port: mailport
|
||||||
username: username
|
username: username
|
||||||
password: password
|
password: password
|
||||||
}
|
}
|
||||||
send_cfg := smtp.Mail{
|
send_cfg := smtp.Mail{
|
||||||
to: to
|
to: to
|
||||||
subject: subject
|
subject: subject
|
||||||
body_type: .html
|
body_type: .html
|
||||||
body: body
|
body: body
|
||||||
}
|
}
|
||||||
mut client := smtp.new_client(client_cfg) or { panic('Error with configuring smtp: ${err}') }
|
mut client := smtp.new_client(client_cfg) or { panic('Error with configuring smtp: ${err}') }
|
||||||
client.send(send_cfg) or { panic('Error resolving email address: ${err}') }
|
client.send(send_cfg) or { panic('Error resolving email address: ${err}') }
|
||||||
|
|
|
@ -152,10 +152,10 @@ fn on_frame(mut app App) {
|
||||||
// drawing top
|
// drawing top
|
||||||
app.gg.draw_rect(0, 0, canvas_size, top_height, gx.black)
|
app.gg.draw_rect(0, 0, canvas_size, top_height, gx.black)
|
||||||
app.gg.draw_text(350, top_height / 2, 'Score: ${app.score}', gx.TextCfg{
|
app.gg.draw_text(350, top_height / 2, 'Score: ${app.score}', gx.TextCfg{
|
||||||
color: gx.white
|
color: gx.white
|
||||||
align: .center
|
align: .center
|
||||||
vertical_align: .middle
|
vertical_align: .middle
|
||||||
size: 80
|
size: 80
|
||||||
})
|
})
|
||||||
|
|
||||||
// checking if snake bit itself
|
// checking if snake bit itself
|
||||||
|
@ -179,15 +179,15 @@ fn main() {
|
||||||
app.reset_game()
|
app.reset_game()
|
||||||
|
|
||||||
app.gg = gg.new_context(
|
app.gg = gg.new_context(
|
||||||
bg_color: gx.white
|
bg_color: gx.white
|
||||||
frame_fn: on_frame
|
frame_fn: on_frame
|
||||||
keydown_fn: on_keydown
|
keydown_fn: on_keydown
|
||||||
user_data: &app
|
user_data: &app
|
||||||
width: canvas_size
|
width: canvas_size
|
||||||
height: top_height + canvas_size
|
height: top_height + canvas_size
|
||||||
create_window: true
|
create_window: true
|
||||||
resizable: false
|
resizable: false
|
||||||
window_title: 'snek'
|
window_title: 'snek'
|
||||||
html5_canvas_name: 'canvas'
|
html5_canvas_name: 'canvas'
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
|
@ -140,16 +140,16 @@ fn on_frame(mut app App) {
|
||||||
// draw score bar
|
// draw score bar
|
||||||
app.gg.draw_rect_filled(0, 0, canvas_size, top_height, gx.black)
|
app.gg.draw_rect_filled(0, 0, canvas_size, top_height, gx.black)
|
||||||
app.gg.draw_text(150, top_height / 2, 'Score: ${app.score}', gx.TextCfg{
|
app.gg.draw_text(150, top_height / 2, 'Score: ${app.score}', gx.TextCfg{
|
||||||
color: gx.white
|
color: gx.white
|
||||||
align: .center
|
align: .center
|
||||||
vertical_align: .middle
|
vertical_align: .middle
|
||||||
size: 65
|
size: 65
|
||||||
})
|
})
|
||||||
app.gg.draw_text(canvas_size - 150, top_height / 2, 'Best: ${app.best}', gx.TextCfg{
|
app.gg.draw_text(canvas_size - 150, top_height / 2, 'Best: ${app.best}', gx.TextCfg{
|
||||||
color: gx.white
|
color: gx.white
|
||||||
align: .center
|
align: .center
|
||||||
vertical_align: .middle
|
vertical_align: .middle
|
||||||
size: 65
|
size: 65
|
||||||
})
|
})
|
||||||
|
|
||||||
if progress == 1 {
|
if progress == 1 {
|
||||||
|
@ -200,15 +200,15 @@ fn main() {
|
||||||
}
|
}
|
||||||
|
|
||||||
app.gg = gg.new_context(
|
app.gg = gg.new_context(
|
||||||
bg_color: gx.white
|
bg_color: gx.white
|
||||||
frame_fn: on_frame
|
frame_fn: on_frame
|
||||||
keydown_fn: on_keydown
|
keydown_fn: on_keydown
|
||||||
user_data: &app
|
user_data: &app
|
||||||
width: canvas_size
|
width: canvas_size
|
||||||
height: top_height + canvas_size
|
height: top_height + canvas_size
|
||||||
create_window: true
|
create_window: true
|
||||||
resizable: false
|
resizable: false
|
||||||
window_title: 'snek'
|
window_title: 'snek'
|
||||||
font_bytes_normal: font_bytes
|
font_bytes_normal: font_bytes
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
|
@ -33,16 +33,16 @@ mut:
|
||||||
fn create_texture(w int, h int, buf &u8) (gfx.Image, gfx.Sampler) {
|
fn create_texture(w int, h int, buf &u8) (gfx.Image, gfx.Sampler) {
|
||||||
sz := w * h * 4
|
sz := w * h * 4
|
||||||
mut img_desc := gfx.ImageDesc{
|
mut img_desc := gfx.ImageDesc{
|
||||||
width: w
|
width: w
|
||||||
height: h
|
height: h
|
||||||
num_mipmaps: 0
|
num_mipmaps: 0
|
||||||
// usage: .dynamic
|
// usage: .dynamic
|
||||||
label: &u8(0)
|
label: &u8(0)
|
||||||
d3d11_texture: 0
|
d3d11_texture: 0
|
||||||
}
|
}
|
||||||
// comment, if .dynamic is enabled
|
// comment, if .dynamic is enabled
|
||||||
img_desc.data.subimage[0][0] = gfx.Range{
|
img_desc.data.subimage[0][0] = gfx.Range{
|
||||||
ptr: buf
|
ptr: buf
|
||||||
size: usize(sz)
|
size: usize(sz)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -51,8 +51,8 @@ fn create_texture(w int, h int, buf &u8) (gfx.Image, gfx.Sampler) {
|
||||||
mut smp_desc := gfx.SamplerDesc{
|
mut smp_desc := gfx.SamplerDesc{
|
||||||
min_filter: .linear
|
min_filter: .linear
|
||||||
mag_filter: .linear
|
mag_filter: .linear
|
||||||
wrap_u: .clamp_to_edge
|
wrap_u: .clamp_to_edge
|
||||||
wrap_v: .clamp_to_edge
|
wrap_v: .clamp_to_edge
|
||||||
}
|
}
|
||||||
|
|
||||||
sg_smp := gfx.make_sampler(&smp_desc)
|
sg_smp := gfx.make_sampler(&smp_desc)
|
||||||
|
@ -68,7 +68,7 @@ fn update_text_texture(sg_img gfx.Image, w int, h int, buf &u8) {
|
||||||
sz := w * h * 4
|
sz := w * h * 4
|
||||||
mut tmp_sbc := gfx.ImageData{}
|
mut tmp_sbc := gfx.ImageData{}
|
||||||
tmp_sbc.subimage[0][0] = gfx.Range{
|
tmp_sbc.subimage[0][0] = gfx.Range{
|
||||||
ptr: buf
|
ptr: buf
|
||||||
size: usize(sz)
|
size: usize(sz)
|
||||||
}
|
}
|
||||||
gfx.update_image(sg_img, &tmp_sbc)
|
gfx.update_image(sg_img, &tmp_sbc)
|
||||||
|
@ -311,7 +311,7 @@ fn my_init(mut app App) {
|
||||||
|
|
||||||
color_state := gfx.ColorTargetState{
|
color_state := gfx.ColorTargetState{
|
||||||
blend: gfx.BlendState{
|
blend: gfx.BlendState{
|
||||||
enabled: true
|
enabled: true
|
||||||
src_factor_rgb: .src_alpha
|
src_factor_rgb: .src_alpha
|
||||||
dst_factor_rgb: .one_minus_src_alpha
|
dst_factor_rgb: .one_minus_src_alpha
|
||||||
}
|
}
|
||||||
|
@ -320,7 +320,7 @@ fn my_init(mut app App) {
|
||||||
|
|
||||||
pipdesc.depth = gfx.DepthState{
|
pipdesc.depth = gfx.DepthState{
|
||||||
write_enabled: true
|
write_enabled: true
|
||||||
compare: .less_equal
|
compare: .less_equal
|
||||||
}
|
}
|
||||||
pipdesc.cull_mode = .back
|
pipdesc.cull_mode = .back
|
||||||
app.pip_3d = sgl.make_pipeline(&pipdesc)
|
app.pip_3d = sgl.make_pipeline(&pipdesc)
|
||||||
|
@ -381,15 +381,15 @@ fn my_event_manager(mut ev gg.Event, mut app App) {
|
||||||
fn main() {
|
fn main() {
|
||||||
mut app := &App{}
|
mut app := &App{}
|
||||||
app.gg = gg.new_context(
|
app.gg = gg.new_context(
|
||||||
width: win_width
|
width: win_width
|
||||||
height: win_height
|
height: win_height
|
||||||
create_window: true
|
create_window: true
|
||||||
window_title: '3D Cube Demo'
|
window_title: '3D Cube Demo'
|
||||||
user_data: app
|
user_data: app
|
||||||
bg_color: bg_color
|
bg_color: bg_color
|
||||||
frame_fn: frame
|
frame_fn: frame
|
||||||
init_fn: my_init
|
init_fn: my_init
|
||||||
event_fn: my_event_manager
|
event_fn: my_event_manager
|
||||||
)
|
)
|
||||||
app.gg.run()
|
app.gg.run()
|
||||||
}
|
}
|
||||||
|
|
|
@ -56,16 +56,16 @@ mut:
|
||||||
fn create_texture(w int, h int, buf &u8) (gfx.Image, gfx.Sampler) {
|
fn create_texture(w int, h int, buf &u8) (gfx.Image, gfx.Sampler) {
|
||||||
sz := w * h * 4
|
sz := w * h * 4
|
||||||
mut img_desc := gfx.ImageDesc{
|
mut img_desc := gfx.ImageDesc{
|
||||||
width: w
|
width: w
|
||||||
height: h
|
height: h
|
||||||
num_mipmaps: 0
|
num_mipmaps: 0
|
||||||
// usage: .dynamic
|
// usage: .dynamic
|
||||||
label: &u8(0)
|
label: &u8(0)
|
||||||
d3d11_texture: 0
|
d3d11_texture: 0
|
||||||
}
|
}
|
||||||
// comment if .dynamic is enabled
|
// comment if .dynamic is enabled
|
||||||
img_desc.data.subimage[0][0] = gfx.Range{
|
img_desc.data.subimage[0][0] = gfx.Range{
|
||||||
ptr: buf
|
ptr: buf
|
||||||
size: usize(sz)
|
size: usize(sz)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -74,8 +74,8 @@ fn create_texture(w int, h int, buf &u8) (gfx.Image, gfx.Sampler) {
|
||||||
mut smp_desc := gfx.SamplerDesc{
|
mut smp_desc := gfx.SamplerDesc{
|
||||||
min_filter: .linear
|
min_filter: .linear
|
||||||
mag_filter: .linear
|
mag_filter: .linear
|
||||||
wrap_u: .clamp_to_edge
|
wrap_u: .clamp_to_edge
|
||||||
wrap_v: .clamp_to_edge
|
wrap_v: .clamp_to_edge
|
||||||
}
|
}
|
||||||
|
|
||||||
sg_smp := gfx.make_sampler(&smp_desc)
|
sg_smp := gfx.make_sampler(&smp_desc)
|
||||||
|
@ -91,7 +91,7 @@ fn update_text_texture(sg_img gfx.Image, w int, h int, buf &u8) {
|
||||||
sz := w * h * 4
|
sz := w * h * 4
|
||||||
mut tmp_sbc := gfx.ImageData{}
|
mut tmp_sbc := gfx.ImageData{}
|
||||||
tmp_sbc.subimage[0][0] = gfx.Range{
|
tmp_sbc.subimage[0][0] = gfx.Range{
|
||||||
ptr: buf
|
ptr: buf
|
||||||
size: usize(sz)
|
size: usize(sz)
|
||||||
}
|
}
|
||||||
gfx.update_image(sg_img, &tmp_sbc)
|
gfx.update_image(sg_img, &tmp_sbc)
|
||||||
|
@ -304,7 +304,7 @@ fn init_cube_glsl(mut app App) {
|
||||||
|
|
||||||
vert_buffer_desc.size = usize(vertices.len * int(sizeof(Vertex_t)))
|
vert_buffer_desc.size = usize(vertices.len * int(sizeof(Vertex_t)))
|
||||||
vert_buffer_desc.data = gfx.Range{
|
vert_buffer_desc.data = gfx.Range{
|
||||||
ptr: vertices.data
|
ptr: vertices.data
|
||||||
size: usize(vertices.len * int(sizeof(Vertex_t)))
|
size: usize(vertices.len * int(sizeof(Vertex_t)))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -331,7 +331,7 @@ fn init_cube_glsl(mut app App) {
|
||||||
|
|
||||||
index_buffer_desc.size = usize(indices.len * int(sizeof(u16)))
|
index_buffer_desc.size = usize(indices.len * int(sizeof(u16)))
|
||||||
index_buffer_desc.data = gfx.Range{
|
index_buffer_desc.data = gfx.Range{
|
||||||
ptr: indices.data
|
ptr: indices.data
|
||||||
size: usize(indices.len * int(sizeof(u16)))
|
size: usize(indices.len * int(sizeof(u16)))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -356,7 +356,7 @@ fn init_cube_glsl(mut app App) {
|
||||||
|
|
||||||
pipdesc.depth = gfx.DepthState{
|
pipdesc.depth = gfx.DepthState{
|
||||||
write_enabled: true
|
write_enabled: true
|
||||||
compare: .less_equal
|
compare: .less_equal
|
||||||
}
|
}
|
||||||
pipdesc.cull_mode = .back
|
pipdesc.cull_mode = .back
|
||||||
|
|
||||||
|
@ -407,7 +407,7 @@ fn draw_cube_glsl(app App) {
|
||||||
// passing the view matrix as uniform
|
// passing the view matrix as uniform
|
||||||
// res is a 4x4 matrix of f32 thus: 4*16 byte of size
|
// res is a 4x4 matrix of f32 thus: 4*16 byte of size
|
||||||
vs_uniforms_range := gfx.Range{
|
vs_uniforms_range := gfx.Range{
|
||||||
ptr: &tr_matrix
|
ptr: &tr_matrix
|
||||||
size: usize(4 * 16)
|
size: usize(4 * 16)
|
||||||
}
|
}
|
||||||
gfx.apply_uniforms(.vs, C.SLOT_vs_params, &vs_uniforms_range)
|
gfx.apply_uniforms(.vs, C.SLOT_vs_params, &vs_uniforms_range)
|
||||||
|
@ -421,7 +421,7 @@ fn draw_cube_glsl(app App) {
|
||||||
0, // padding 4 Bytes == 1 f32
|
0, // padding 4 Bytes == 1 f32
|
||||||
]!
|
]!
|
||||||
fs_uniforms_range := gfx.Range{
|
fs_uniforms_range := gfx.Range{
|
||||||
ptr: unsafe { &text_res }
|
ptr: unsafe { &text_res }
|
||||||
size: usize(4 * 4)
|
size: usize(4 * 4)
|
||||||
}
|
}
|
||||||
gfx.apply_uniforms(.fs, C.SLOT_fs_params, &fs_uniforms_range)
|
gfx.apply_uniforms(.fs, C.SLOT_fs_params, &fs_uniforms_range)
|
||||||
|
@ -528,7 +528,7 @@ fn my_init(mut app App) {
|
||||||
|
|
||||||
color_state := gfx.ColorTargetState{
|
color_state := gfx.ColorTargetState{
|
||||||
blend: gfx.BlendState{
|
blend: gfx.BlendState{
|
||||||
enabled: true
|
enabled: true
|
||||||
src_factor_rgb: .src_alpha
|
src_factor_rgb: .src_alpha
|
||||||
dst_factor_rgb: .one_minus_src_alpha
|
dst_factor_rgb: .one_minus_src_alpha
|
||||||
}
|
}
|
||||||
|
@ -537,7 +537,7 @@ fn my_init(mut app App) {
|
||||||
|
|
||||||
pipdesc.depth = gfx.DepthState{
|
pipdesc.depth = gfx.DepthState{
|
||||||
write_enabled: true
|
write_enabled: true
|
||||||
compare: .less_equal
|
compare: .less_equal
|
||||||
}
|
}
|
||||||
pipdesc.cull_mode = .back
|
pipdesc.cull_mode = .back
|
||||||
|
|
||||||
|
@ -610,15 +610,15 @@ fn main() {
|
||||||
println(a)
|
println(a)
|
||||||
|
|
||||||
app.gg = gg.new_context(
|
app.gg = gg.new_context(
|
||||||
width: win_width
|
width: win_width
|
||||||
height: win_height
|
height: win_height
|
||||||
create_window: true
|
create_window: true
|
||||||
window_title: '3D Cube Demo'
|
window_title: '3D Cube Demo'
|
||||||
user_data: app
|
user_data: app
|
||||||
bg_color: bg_color
|
bg_color: bg_color
|
||||||
frame_fn: frame
|
frame_fn: frame
|
||||||
init_fn: my_init
|
init_fn: my_init
|
||||||
event_fn: my_event_manager
|
event_fn: my_event_manager
|
||||||
)
|
)
|
||||||
|
|
||||||
app.ticks = time.ticks()
|
app.ticks = time.ticks()
|
||||||
|
|
|
@ -55,20 +55,20 @@ mut:
|
||||||
fn create_texture(w int, h int, buf &u8) (gfx.Image, gfx.Sampler) {
|
fn create_texture(w int, h int, buf &u8) (gfx.Image, gfx.Sampler) {
|
||||||
sz := w * h * 4
|
sz := w * h * 4
|
||||||
mut img_desc := gfx.ImageDesc{
|
mut img_desc := gfx.ImageDesc{
|
||||||
width: w
|
width: w
|
||||||
height: h
|
height: h
|
||||||
num_mipmaps: 0
|
num_mipmaps: 0
|
||||||
// min_filter: .linear
|
// min_filter: .linear
|
||||||
// mag_filter: .linear
|
// mag_filter: .linear
|
||||||
// usage: .dynamic
|
// usage: .dynamic
|
||||||
// wrap_u: .clamp_to_edge
|
// wrap_u: .clamp_to_edge
|
||||||
// wrap_v: .clamp_to_edge
|
// wrap_v: .clamp_to_edge
|
||||||
label: &u8(0)
|
label: &u8(0)
|
||||||
d3d11_texture: 0
|
d3d11_texture: 0
|
||||||
}
|
}
|
||||||
// comment if .dynamic is enabled
|
// comment if .dynamic is enabled
|
||||||
img_desc.data.subimage[0][0] = gfx.Range{
|
img_desc.data.subimage[0][0] = gfx.Range{
|
||||||
ptr: buf
|
ptr: buf
|
||||||
size: usize(sz)
|
size: usize(sz)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -77,8 +77,8 @@ fn create_texture(w int, h int, buf &u8) (gfx.Image, gfx.Sampler) {
|
||||||
mut smp_desc := gfx.SamplerDesc{
|
mut smp_desc := gfx.SamplerDesc{
|
||||||
min_filter: .linear
|
min_filter: .linear
|
||||||
mag_filter: .linear
|
mag_filter: .linear
|
||||||
wrap_u: .clamp_to_edge
|
wrap_u: .clamp_to_edge
|
||||||
wrap_v: .clamp_to_edge
|
wrap_v: .clamp_to_edge
|
||||||
}
|
}
|
||||||
|
|
||||||
sg_smp := gfx.make_sampler(&smp_desc)
|
sg_smp := gfx.make_sampler(&smp_desc)
|
||||||
|
@ -94,7 +94,7 @@ fn update_text_texture(sg_img gfx.Image, w int, h int, buf &u8) {
|
||||||
sz := w * h * 4
|
sz := w * h * 4
|
||||||
mut tmp_sbc := gfx.ImageData{}
|
mut tmp_sbc := gfx.ImageData{}
|
||||||
tmp_sbc.subimage[0][0] = gfx.Range{
|
tmp_sbc.subimage[0][0] = gfx.Range{
|
||||||
ptr: buf
|
ptr: buf
|
||||||
size: usize(sz)
|
size: usize(sz)
|
||||||
}
|
}
|
||||||
gfx.update_image(sg_img, &tmp_sbc)
|
gfx.update_image(sg_img, &tmp_sbc)
|
||||||
|
@ -171,7 +171,7 @@ fn init_cube_glsl(mut app App) {
|
||||||
|
|
||||||
vert_buffer_desc.size = usize(vertices.len * int(sizeof(Vertex_t)))
|
vert_buffer_desc.size = usize(vertices.len * int(sizeof(Vertex_t)))
|
||||||
vert_buffer_desc.data = gfx.Range{
|
vert_buffer_desc.data = gfx.Range{
|
||||||
ptr: vertices.data
|
ptr: vertices.data
|
||||||
size: usize(vertices.len * int(sizeof(Vertex_t)))
|
size: usize(vertices.len * int(sizeof(Vertex_t)))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -197,7 +197,7 @@ fn init_cube_glsl(mut app App) {
|
||||||
|
|
||||||
index_buffer_desc.size = usize(indices.len * int(sizeof(u16)))
|
index_buffer_desc.size = usize(indices.len * int(sizeof(u16)))
|
||||||
index_buffer_desc.data = gfx.Range{
|
index_buffer_desc.data = gfx.Range{
|
||||||
ptr: indices.data
|
ptr: indices.data
|
||||||
size: usize(indices.len * int(sizeof(u16)))
|
size: usize(indices.len * int(sizeof(u16)))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -222,7 +222,7 @@ fn init_cube_glsl(mut app App) {
|
||||||
|
|
||||||
pipdesc.depth = gfx.DepthState{
|
pipdesc.depth = gfx.DepthState{
|
||||||
write_enabled: true
|
write_enabled: true
|
||||||
compare: .less_equal
|
compare: .less_equal
|
||||||
}
|
}
|
||||||
pipdesc.cull_mode = .back
|
pipdesc.cull_mode = .back
|
||||||
|
|
||||||
|
@ -284,7 +284,7 @@ fn draw_cube_glsl(app App) {
|
||||||
// passing the view matrix as uniform
|
// passing the view matrix as uniform
|
||||||
// res is a 4x4 matrix of f32 thus: 4*16 byte of size
|
// res is a 4x4 matrix of f32 thus: 4*16 byte of size
|
||||||
vs_uniforms_range := gfx.Range{
|
vs_uniforms_range := gfx.Range{
|
||||||
ptr: &tr_matrix
|
ptr: &tr_matrix
|
||||||
size: usize(4 * 16)
|
size: usize(4 * 16)
|
||||||
}
|
}
|
||||||
gfx.apply_uniforms(.vs, C.SLOT_vs_params, &vs_uniforms_range)
|
gfx.apply_uniforms(.vs, C.SLOT_vs_params, &vs_uniforms_range)
|
||||||
|
@ -302,7 +302,7 @@ fn draw_cube_glsl(app App) {
|
||||||
0, // padding bytes , see "fs_params" struct paddings in rt_glsl.h
|
0, // padding bytes , see "fs_params" struct paddings in rt_glsl.h
|
||||||
]!
|
]!
|
||||||
fs_uniforms_range := gfx.Range{
|
fs_uniforms_range := gfx.Range{
|
||||||
ptr: unsafe { &tmp_fs_params }
|
ptr: unsafe { &tmp_fs_params }
|
||||||
size: usize(sizeof(tmp_fs_params))
|
size: usize(sizeof(tmp_fs_params))
|
||||||
}
|
}
|
||||||
gfx.apply_uniforms(.fs, C.SLOT_fs_params, &fs_uniforms_range)
|
gfx.apply_uniforms(.fs, C.SLOT_fs_params, &fs_uniforms_range)
|
||||||
|
@ -410,15 +410,15 @@ fn my_event_manager(mut ev gg.Event, mut app App) {
|
||||||
fn main() {
|
fn main() {
|
||||||
mut app := &App{}
|
mut app := &App{}
|
||||||
app.gg = gg.new_context(
|
app.gg = gg.new_context(
|
||||||
width: win_width
|
width: win_width
|
||||||
height: win_height
|
height: win_height
|
||||||
create_window: true
|
create_window: true
|
||||||
window_title: '3D Ray Marching Cube'
|
window_title: '3D Ray Marching Cube'
|
||||||
user_data: app
|
user_data: app
|
||||||
bg_color: bg_color
|
bg_color: bg_color
|
||||||
frame_fn: frame
|
frame_fn: frame
|
||||||
init_fn: my_init
|
init_fn: my_init
|
||||||
event_fn: my_event_manager
|
event_fn: my_event_manager
|
||||||
)
|
)
|
||||||
app.ticks = time.ticks()
|
app.ticks = time.ticks()
|
||||||
app.gg.run()
|
app.gg.run()
|
||||||
|
|
|
@ -47,19 +47,19 @@ mut:
|
||||||
fn create_texture(w int, h int, buf byteptr) (gfx.Image, gfx.Sampler) {
|
fn create_texture(w int, h int, buf byteptr) (gfx.Image, gfx.Sampler) {
|
||||||
sz := w * h * 4
|
sz := w * h * 4
|
||||||
mut img_desc := gfx.ImageDesc{
|
mut img_desc := gfx.ImageDesc{
|
||||||
width: w
|
width: w
|
||||||
height: h
|
height: h
|
||||||
}
|
}
|
||||||
img_desc.data.subimage[0][0] = gfx.Range{
|
img_desc.data.subimage[0][0] = gfx.Range{
|
||||||
ptr: buf
|
ptr: buf
|
||||||
size: usize(sz)
|
size: usize(sz)
|
||||||
}
|
}
|
||||||
sg_img := gfx.make_image(&img_desc)
|
sg_img := gfx.make_image(&img_desc)
|
||||||
mut smp_desc := gfx.SamplerDesc{
|
mut smp_desc := gfx.SamplerDesc{
|
||||||
min_filter: .linear
|
min_filter: .linear
|
||||||
mag_filter: .linear
|
mag_filter: .linear
|
||||||
wrap_u: .clamp_to_edge
|
wrap_u: .clamp_to_edge
|
||||||
wrap_v: .clamp_to_edge
|
wrap_v: .clamp_to_edge
|
||||||
}
|
}
|
||||||
sg_smp := gfx.make_sampler(&smp_desc)
|
sg_smp := gfx.make_sampler(&smp_desc)
|
||||||
return sg_img, sg_smp
|
return sg_img, sg_smp
|
||||||
|
@ -326,13 +326,13 @@ fn (mut app App) on_event(ev &gg.Event, x voidptr) {
|
||||||
fn main() {
|
fn main() {
|
||||||
mut app := &App{}
|
mut app := &App{}
|
||||||
app.gg = gg.new_context(
|
app.gg = gg.new_context(
|
||||||
width: 800
|
width: 800
|
||||||
height: 800
|
height: 800
|
||||||
window_title: '3D Dual shader Cube - click and rotate with the mouse'
|
window_title: '3D Dual shader Cube - click and rotate with the mouse'
|
||||||
user_data: app
|
user_data: app
|
||||||
frame_fn: app.frame
|
frame_fn: app.frame
|
||||||
init_fn: app.on_init
|
init_fn: app.on_init
|
||||||
event_fn: app.on_event
|
event_fn: app.on_event
|
||||||
)
|
)
|
||||||
app.gg.run()
|
app.gg.run()
|
||||||
}
|
}
|
||||||
|
|
Some files were not shown because too many files have changed in this diff Show more
Loading…
Add table
Add a link
Reference in a new issue