From: Brendan Hansen Date: Wed, 27 Oct 2021 22:12:05 +0000 (-0500) Subject: synchronizing changes X-Git-Url: https://git.brendanfh.com/?a=commitdiff_plain;h=8b0bdfd5534abe4414b28dbe1f627b885521a9ec;p=onyx.git synchronizing changes --- diff --git a/.github/workflows/onyx-build.yml b/.github/workflows/onyx-build.yml index cfd52d65..7a503ae0 100644 --- a/.github/workflows/onyx-build.yml +++ b/.github/workflows/onyx-build.yml @@ -15,6 +15,8 @@ jobs: - uses: actions/checkout@v2 - name: make build.sh executable run: chmod +x build.sh + - name: make build directory + run: mkdir -p build - name: build onyx run: ./build.sh - name: run tests diff --git a/.vimspector.json.old b/.vimspector.json.old deleted file mode 100644 index b8923072..00000000 --- a/.vimspector.json.old +++ /dev/null @@ -1,24 +0,0 @@ -{ "configurations": { - "cpptools-run": { - "adapter": "vscode-cpptools", - "configuration": { - "type": "cppdbg", - "request": "launch", - "program": "/home/brendan/dev/c/onyx/bin/onyx-debug", - "args": ["-VVV", "-I", "/home/brendan/dev/c/onyx", "-o", "site/analyzer.wasm", "-r", "js", "--no-colors", "src/build.onyx", "--doc", "doc/source_reference" ], - "stopAtEntry": true, - "cwd": "/home/brendan/dev/onyx/wasm_analyzer", - "environment": [], - "externalConsole": false, - "MIMode": "gdb", - "setupCommands": [ - { - "description": "Enable pretty-printing for gdb", - "text": "-enable-pretty-printing", - "ignoreFailures": true - } - ] - } - } - } -} diff --git a/core/container/bucket_array.onyx b/core/container/bucket_array.onyx index 6947ff72..83b9e7ce 100644 --- a/core/container/bucket_array.onyx +++ b/core/container/bucket_array.onyx @@ -50,6 +50,11 @@ clear :: (use b: ^Bucket_Array($T)) { return get(^b, idx); } +#operator ^[] macro (b: Bucket_Array($T), idx: i32) -> ^T { + get_ptr :: get_ptr + return get_ptr(^b, idx); +} + get :: (use b: ^Bucket_Array($T), idx: i32) -> T { bucket_index := idx / elements_per_bucket; elem_index := idx % elements_per_bucket; @@ -96,6 +101,43 @@ for_each :: macro (b: Bucket_Array($T), body: Code) { } } +iterator :: (b: ^Bucket_Array($T)) -> Iterator(T) { + Context :: struct (T: type_expr) { + ba : ^Bucket_Array(T); + bucket_idx : i32; + elem_idx : i32; + } + + c := new(#type Context(T)); + c.ba = b; + c.bucket_idx = 0; + c.elem_idx = 0; + + next :: (use c: ^Context($T)) -> (T, bool) { + use package core.intrinsics.onyx + + bucket := ^ba.buckets[bucket_idx]; + while elem_idx == bucket.count { + bucket_idx += 1; + if bucket_idx == ba.buckets.count do return __zero_value(T), false; + + bucket = ^ba.buckets[bucket_idx]; + elem_idx = 0; + } + + defer elem_idx += 1; + return bucket.data[elem_idx], true; + } + + close :: (x: rawptr) => cfree(x); + + return .{ + data = c, + next = #solidify next { T=T }, + close = close, + }; +} + #private alloc_bucket :: (use b: ^Bucket_Array($T)) -> Bucket_Array.Bucket(T) { data := raw_alloc(allocator, sizeof T * elements_per_bucket); diff --git a/core/container/list.onyx b/core/container/list.onyx index 4521c787..ceaaf3b2 100644 --- a/core/container/list.onyx +++ b/core/container/list.onyx @@ -120,6 +120,4 @@ get_iterator :: (list: ^List($T)) -> Iterator(T) { } #private_file -allocate_elem :: (list: ^List($T)) -> ^ListElem(T) { - return new(#type ListElem(T), allocator=list.allocator); -} +allocate_elem :: macro (list: ^List($T)) => new(#type ListElem(T), allocator=list.allocator); diff --git a/misc/vscode/language-configuration.json b/misc/vscode/language-configuration.json index 78b4387f..31136ff4 100644 --- a/misc/vscode/language-configuration.json +++ b/misc/vscode/language-configuration.json @@ -24,5 +24,6 @@ ["[", "]"], ["(", ")"], ["\"", "\""] - ] + ], + "wordPattern": "(-?\\d*\\.\\d\\w*)|([^\\`\\~\\!\\@\\#\\%\\^\\&\\*\\(\\)\\-\\=\\+\\[\\{\\]\\}\\\\\\|\\;\\:\\'\\\"\\,\\.\\<\\>\\/\\?\\s]+)" } \ No newline at end of file diff --git a/misc/vscode/onyx-0.0.1.vsix b/misc/vscode/onyx-0.0.1.vsix index 3b6f9e23..420a7b78 100644 Binary files a/misc/vscode/onyx-0.0.1.vsix and b/misc/vscode/onyx-0.0.1.vsix differ diff --git a/misc/vscode/syntaxes/onyx.tmLanguage b/misc/vscode/syntaxes/onyx.tmLanguage index d420035d..2f651c03 100644 --- a/misc/vscode/syntaxes/onyx.tmLanguage +++ b/misc/vscode/syntaxes/onyx.tmLanguage @@ -267,7 +267,7 @@ match - \b(str|cstr)\b + \b(str|cstr|type_expr|any)\b name storage.type.onyx @@ -303,13 +303,13 @@ match - (\b[[:alpha:]_]+[[:alnum:]_]*\b)\s*[!]?\s*[\(] + (\b[[:alpha:]_]+[[:alnum:]_]*\b)\s*[:]\s*[:]\s*[\(] captures 1 name - support.function.onyx + entity.name.function.onyx diff --git a/modules/bmfont/bmfont_loader.onyx b/modules/bmfont/bmfont_loader.onyx index 2de49c74..413ef4fd 100644 --- a/modules/bmfont/bmfont_loader.onyx +++ b/modules/bmfont/bmfont_loader.onyx @@ -1,14 +1,10 @@ package bmfont use package core - +#private_file json :: package json load_bmfont :: (fnt_data: [] u8) -> BMFont { - bmf: BMFont; - memory.set(^bmf, 0, sizeof BMFont); - - map.init(^bmf.pages); - map.init(^bmf.glyphs); + bmf := create_bmfont(); parse_bmfont(fnt_data, ^bmf); @@ -22,6 +18,26 @@ load_bmfont :: (fnt_data: [] u8) -> BMFont { return bmf; } +load_bmfont_from_json :: (fnt_data: [] u8) -> BMFont { + bmf := create_bmfont(); + + j := json.decode(fnt_data); + defer json.free(j); + + extract_bmfont_from_json(^bmf, j.root); +} + +#private_file +create_bmfont :: () -> BMFont { + bmf: BMFont; + memory.set(^bmf, 0, sizeof BMFont); + + map.init(^bmf.pages); + map.init(^bmf.glyphs); + + return bmf; +} + #private_file parse_bmfont :: (fnt_data: [] u8, font: ^BMFont) { R :: package core.string.reader @@ -134,3 +150,64 @@ parse_bmfont :: (fnt_data: [] u8, font: ^BMFont) { elseif key == "blueChnl" do common.blue_channel = ~~ conv.str_to_i64(value); } } + +#private_file +extract_bmfont_from_json :: (font: ^BMFont, root: ^json.Value) { + font_info := root["info"]; + font.info.face_name = font_info["face"]->as_str(); + font.info.size = ~~font_info["size"]->as_int(); + font.info.bold = font_info["bold"]->as_int() != 0; + font.info.italic = font_info["italic"]->as_int() != 0; + font.info.unicode = font_info["unicode"]->as_int() != 0; + font.info.stretchH = ~~font_info["stretchH"]->as_int(); + font.info.smooth = font_info["smooth"]->as_int() != 0; + font.info.supersampling = ~~font_info["aa"]->as_int(); + + font_padding := font_info["padding"]; + font.info.padding.top = ~~font_padding[0]->as_int(); + font.info.padding.right = ~~font_padding[1]->as_int(); + font.info.padding.bottom = ~~font_padding[2]->as_int(); + font.info.padding.left = ~~font_padding[3]->as_int(); + + font_spacing := font_info["spacing"]; + font.info.spacing.horizontal = ~~font_spacing[0]->as_int(); + font.info.spacing.vertical = ~~font_spacing[1]->as_int(); + + font_common := root["common"]; + font.common.line_height = ~~font_common["lineHeight"]->as_int(); + font.common.baseline = ~~font_common["base"]->as_int(); + font.common.scale_width = ~~font_common["scaleW"]->as_int(); + font.common.scale_height = ~~font_common["scaleH"]->as_int(); + font.common.page_count = ~~font_common["pages"]->as_int(); + font.common.packed = font_common["packed"]->as_int() != 0; + font.common.alpha_channel = ~~font_common["alphaChnl"]->as_int(); + font.common.red_channel = ~~font_common["redChnl"]->as_int(); + font.common.green_channel = ~~font_common["greenChnl"]->as_int(); + font.common.blue_channel = ~~font_common["blueChnl"]->as_int(); + + i := 0; + for page: root["pages"]->as_array() { + defer i += 1; + + font.pages[i] = page->as_str(); + } + + for ch: root["chars"]->as_array() { + id := cast(i32) ch["id"]->as_int(); + font.glyphs[id] = .{ + id = id, + + x = ~~ch["x"]->as_int(), + y = ~~ch["y"]->as_int(), + w = ~~ch["width"]->as_int(), + h = ~~ch["height"]->as_int(), + + xoffset = ~~ch["xoffset"]->as_int(), + yoffset = ~~ch["yoffset"]->as_int(), + xadvance = ~~ch["xadvance"]->as_int(), + + page = ~~ch["page"]->as_int(), + channel = ~~ch["chnl"]->as_int(), + }; + } +} diff --git a/modules/immediate_mode/immediate_renderer.onyx b/modules/immediate_mode/immediate_renderer.onyx index 95f52f87..13e87396 100644 --- a/modules/immediate_mode/immediate_renderer.onyx +++ b/modules/immediate_mode/immediate_renderer.onyx @@ -279,7 +279,7 @@ Immediate_Renderer :: struct { gl.uniform1i(active_shader.texture_uniform, math.max(texture_id, 0)); } - use_ortho_projection :: (use ir: ^Immediate_Renderer, left: f32, right: f32, top: f32, bottom: f32) { + use_ortho_projection :: (use ir: ^Immediate_Renderer, left, right, top, bottom: f32) { projection_matrix := f32.[ 2 / (right - left), 0, 0, 0, 0, 2 / (top - bottom), 0, 0, @@ -297,7 +297,7 @@ Immediate_Renderer :: struct { gl.useProgram(active_shader.program); } - push_scissor :: (use ir: ^Immediate_Renderer, x: f32, y: f32, w: f32, h: f32) { + push_scissor :: (use ir: ^Immediate_Renderer, x, y, w, h: f32) { if vertex_count > 0 do ir->flush(); if !gl.isEnabled(gl.SCISSOR_TEST) { @@ -367,7 +367,7 @@ Immediate_Renderer :: struct { } } - set_window_size :: (use ir: ^Immediate_Renderer, width: i32, height: i32) { + set_window_size :: (use ir: ^Immediate_Renderer, width, height: i32) { window_width = width; window_height = height; diff --git a/tests/bucket_array b/tests/bucket_array index 2f8f1c0b..b5cb2f5e 100644 --- a/tests/bucket_array +++ b/tests/bucket_array @@ -23,4 +23,28 @@ ba[10] is 10. [1] -> 21 [2] -> 22 [3] -> 23 +0 +1 +2 +3 +4 +5 +6 +7 +8 +9 +10 +11 +12 +13 +14 +15 +16 +17 +18 +19 +20 +21 +22 +23 Sum is 276 diff --git a/tests/bucket_array.onyx b/tests/bucket_array.onyx index 9307dca9..bc48b02a 100644 --- a/tests/bucket_array.onyx +++ b/tests/bucket_array.onyx @@ -14,5 +14,9 @@ main :: (args: [] cstr) { sum += *it; }); + for it: bucket_array.iterator(^ba) { + printf("{}\n", it); + } + printf("Sum is {}\n", sum); } \ No newline at end of file