synchronizing changes
authorBrendan Hansen <brendan.f.hansen@gmail.com>
Wed, 27 Oct 2021 22:12:05 +0000 (17:12 -0500)
committerBrendan Hansen <brendan.f.hansen@gmail.com>
Wed, 27 Oct 2021 22:12:05 +0000 (17:12 -0500)
.github/workflows/onyx-build.yml
.vimspector.json.old [deleted file]
core/container/bucket_array.onyx
core/container/list.onyx
misc/vscode/language-configuration.json
misc/vscode/onyx-0.0.1.vsix
misc/vscode/syntaxes/onyx.tmLanguage
modules/bmfont/bmfont_loader.onyx
modules/immediate_mode/immediate_renderer.onyx
tests/bucket_array
tests/bucket_array.onyx

index cfd52d65461452a93e0f1591cba41e1852094635..7a503ae0f6c940f842e7b0177286418218a7b7d4 100644 (file)
@@ -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 (file)
index b892307..0000000
+++ /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
-                    }
-                ]
-            }
-        }
-    }
-}
index 6947ff728c2c59ff8b061c7ffad81677b62cb6d7..83b9e7ce17a4c84d6d065cda86306882cf995e6b 100644 (file)
@@ -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);
index 4521c78789a2812d9f0b4a5759826102bcf0acc1..ceaaf3b2781df1ed32a51d059dbfd618c9a113ef 100644 (file)
@@ -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);
index 78b4387f280002633686e45b2de8d3089057c79f..31136ff4532536d7e9281644c401d5e7852cc0ef 100644 (file)
@@ -24,5 +24,6 @@
         ["[", "]"],
         ["(", ")"],
         ["\"", "\""]
-    ]
+    ],
+    "wordPattern": "(-?\\d*\\.\\d\\w*)|([^\\`\\~\\!\\@\\#\\%\\^\\&\\*\\(\\)\\-\\=\\+\\[\\{\\]\\}\\\\\\|\\;\\:\\'\\\"\\,\\.\\<\\>\\/\\?\\s]+)"
 }
\ No newline at end of file
index 3b6f9e23c7bb70e3af11a51d04ff83d6460d2768..420a7b7850a946bcd1b0b121ffd57b194b5629e0 100644 (file)
Binary files a/misc/vscode/onyx-0.0.1.vsix and b/misc/vscode/onyx-0.0.1.vsix differ
index d420035d5bed329224b211f8473aaed5a675988f..2f651c031b71462a7a7f0e30a8e0913626474e1d 100644 (file)
                                </dict>
                                <dict>
                                        <key>match</key>
-                                       <string>\b(str|cstr)\b</string>
+                                       <string>\b(str|cstr|type_expr|any)\b</string>
                                        <key>name</key>
                                        <string>storage.type.onyx</string>
                                </dict>
                                </dict>
                                <dict>
                                        <key>match</key>
-                                       <string>(\b[[:alpha:]_]+[[:alnum:]_]*\b)\s*[!]?\s*[\(]</string>
+                                       <string>(\b[[:alpha:]_]+[[:alnum:]_]*\b)\s*[:]\s*[:]\s*[\(]</string>
                                        <key>captures</key>
                                        <dict>
                                                <key>1</key>
                                                <dict>
                                                        <key>name</key>
-                                                       <string>support.function.onyx</string>
+                                                       <string>entity.name.function.onyx</string>
                                                </dict>
                                        </dict>
                                </dict>
index 2de49c74a8136100d878d61e7cf6f280b6d9a05f..413ef4fd62fb9b53b5987f520453c29bc1d2d89a 100644 (file)
@@ -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(),
+        };
+    }
+}
index 95f52f87c3a5bac352d624c264733814f5675690..13e873968a34b0bb04edc8f2f40e725ff39c93de 100644 (file)
@@ -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;
 
index 2f8f1c0b2286a621b65f0c8d07459f272229deb6..b5cb2f5e61e27e3682adf5a1f81397c250a2891e 100644 (file)
@@ -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
index 9307dca91e379b6a61c770a180135a4ada557d39..bc48b02af485614b17c2d021bf3da115340bbe57 100644 (file)
@@ -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