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