Compare commits

...

2 Commits

8 changed files with 28 additions and 28 deletions

View File

@ -108,7 +108,7 @@ fn Point? Atlas.place(&atlas, char[] pixels, ushort w, ushort h, ushort stride)
if (atlas.row.x + w <= atlas.width && atlas.row.y + h <= atlas.height) { if (atlas.row.x + w <= atlas.width && atlas.row.y + h <= atlas.height) {
p = atlas.row; p = atlas.row;
} else { } else {
return CANNOT_PLACE?; return CANNOT_PLACE~;
} }
} }

View File

@ -1,4 +1,4 @@
module cache{Key, Value, SIZE}; module cache<Key, Value, SIZE>;
/* LRU Cache /* LRU Cache
* The cache uses a pool (array) to store all the elements, each element has * The cache uses a pool (array) to store all the elements, each element has
@ -29,7 +29,7 @@ struct Cache {
} }
// Every CACHE_CYCLES operations mark as not-present the unused elements // Every CACHE_CYCLES operations mark as not-present the unused elements
macro Cache.cycle(&cache) @private { macro Cache.cycle(&cache) {
cache.cycle_count++; cache.cycle_count++;
if (cache.cycle_count > CACHE_NCYCLES) { if (cache.cycle_count > CACHE_NCYCLES) {
for (usz i = 0; i < cache.present.data.len; i++) { for (usz i = 0; i < cache.present.data.len; i++) {
@ -64,14 +64,14 @@ fn Value*? Cache.search(&cache, Key id)
/* MISS, wrong key */ /* MISS, wrong key */
if (entry.key != id) { if (entry.key != id) {
cache.table.remove(id)!; cache.table.remove(id)!;
return NOT_FOUND?; return NOT_FOUND~;
} }
/* MISS, the data is not valid (not present) */ /* MISS, the data is not valid (not present) */
if (!cache.present[entry.value]) { if (!cache.present[entry.value]) {
// if the data is not present but it is still in the table, remove it // if the data is not present but it is still in the table, remove it
cache.table.remove(id)!; cache.table.remove(id)!;
return NOT_FOUND?; return NOT_FOUND~;
} }
/* HIT, set as recently used */ /* HIT, set as recently used */
@ -94,7 +94,7 @@ fn void Cache.remove(&cache, Key id)
/* Look for a free spot in the present bitmap and return its index */ /* Look for a free spot in the present bitmap and return its index */
/* If there is no free space left then just return the first position */ /* If there is no free space left then just return the first position */
fn usz Cache.get_free_spot(&cache) @private fn usz Cache.get_free_spot(&cache)
{ {
// TODO: in the upgrade to c3 1.7.5 use @bitsof() // TODO: in the upgrade to c3 1.7.5 use @bitsof()
const BITS = $typeof(cache.present.data[0]).sizeof*8; const BITS = $typeof(cache.present.data[0]).sizeof*8;
@ -108,7 +108,7 @@ fn usz Cache.get_free_spot(&cache) @private
return 0; return 0;
} }
fn Value*? Cache.insert_at(&cache, Value* g, Key id, usz index) @private fn Value*? Cache.insert_at(&cache, Value* g, Key id, usz index)
{ {
// TODO: verify index, g and id // TODO: verify index, g and id
Value* spot; Value* spot;
@ -136,7 +136,7 @@ fn Value*? Cache.get_or_insert(&cache, Value* g, Key id, bool *is_new = null)
Value*? c = cache.search(id); Value*? c = cache.search(id);
if (catch e = c) { if (catch e = c) {
if (e != NOT_FOUND) { if (e != NOT_FOUND) {
return e?; return e~;
} else { } else {
// if the element is new (inserted) set the is_new flag // if the element is new (inserted) set the is_new flag
if (is_new) *is_new = true; if (is_new) *is_new = true;

View File

@ -183,7 +183,7 @@ fn PElemTuple? Ctx.get_elem(&ctx, Id id, ElemType type)
elem.id = id; elem.id = id;
elem.layout = {}; elem.layout = {};
if (is_new == false && elem.type != type) { if (is_new == false && elem.type != type) {
return WRONG_ELEMENT_TYPE?; return WRONG_ELEMENT_TYPE~;
} else { } else {
elem.type = type; elem.type = type;
} }
@ -272,7 +272,7 @@ fn void? Ctx.frame_end(&ctx)
{ {
Elem* root = ctx.get_active_div()!; Elem* root = ctx.get_active_div()!;
if (root.id != ROOT_ID) { if (root.id != ROOT_ID) {
return WRONG_ID?; return WRONG_ID~;
} }
// 2. clear input fields // 2. clear input fields

View File

@ -90,7 +90,7 @@ fn void? Font.load(&font, Allocator allocator, String name, ZString path, uint h
font.sft.font = schrift::loadfile(path); font.sft.font = schrift::loadfile(path);
if (font.sft.font == null) { if (font.sft.font == null) {
font.table.free(); font.table.free();
return TTF_LOAD_FAILED?; return TTF_LOAD_FAILED~;
} }
schrift::SftLMetrics lmetrics; schrift::SftLMetrics lmetrics;
@ -122,7 +122,7 @@ fn Glyph*? Font.get_glyph(&font, Codepoint code)
if (catch excuse = gp) { if (catch excuse = gp) {
if (excuse != NOT_FOUND) { if (excuse != NOT_FOUND) {
return excuse?; return excuse~;
} }
} else { } else {
return gp; return gp;
@ -136,11 +136,11 @@ fn Glyph*? Font.get_glyph(&font, Codepoint code)
schrift::SftGMetrics gmtx; schrift::SftGMetrics gmtx;
if (schrift::lookup(&font.sft, (SftUChar)code, &gid) < 0) { if (schrift::lookup(&font.sft, (SftUChar)code, &gid) < 0) {
return MISSING_GLYPH?; return MISSING_GLYPH~;
} }
if (schrift::gmetrics(&font.sft, gid, &gmtx) < 0) { if (schrift::gmetrics(&font.sft, gid, &gmtx) < 0) {
return BAD_GLYPH_METRICS?; return BAD_GLYPH_METRICS~;
} }
schrift::SftImage img = { schrift::SftImage img = {
@ -150,7 +150,7 @@ fn Glyph*? Font.get_glyph(&font, Codepoint code)
char[] pixels = mem::new_array(char, (usz)img.width * img.height); char[] pixels = mem::new_array(char, (usz)img.width * img.height);
img.pixels = pixels; img.pixels = pixels;
if (schrift::render(&font.sft, gid, img) < 0) { if (schrift::render(&font.sft, gid, img) < 0) {
return RENDER_ERROR?; return RENDER_ERROR~;
} }
glyph.code = code; glyph.code = code;
@ -217,7 +217,7 @@ fn Atlas*? Ctx.get_font_atlas(&ctx, String name)
{ {
// TODO: use the font name, for now there is only one font // TODO: use the font name, for now there is only one font
if (name.hash() != ctx.font.id) { if (name.hash() != ctx.font.id) {
return WRONG_ID?; return WRONG_ID~;
} }
return &ctx.font.atlas; return &ctx.font.atlas;

View File

@ -88,7 +88,7 @@ fn bool Ctx.check_key_combo(&ctx, ModKeys mod, String ...keys)
fn void? Ctx.input_window_size(&ctx, short width, short height) fn void? Ctx.input_window_size(&ctx, short width, short height)
{ {
if (width <= 0 || height <= 0) { if (width <= 0 || height <= 0) {
return INVALID_SIZE?; return INVALID_SIZE~;
} }
ctx.current_input.events.resize = ctx.width != width || ctx.height != height; ctx.current_input.events.resize = ctx.width != width || ctx.height != height;
ctx.width = width; ctx.width = width;

View File

@ -1,4 +1,4 @@
module mtree{Type}; module mtree<Type>;
/* ================================================================================================ /* ================================================================================================
* MTree, Bitmap-based tree * MTree, Bitmap-based tree
@ -127,7 +127,7 @@ fn int? MTree.get_free_spot(&tree)
return spot; return spot;
} }
} }
return CAPACITY_EXCEEDED?; return CAPACITY_EXCEEDED~;
} }
<* @require idx >= 0 *> <* @require idx >= 0 *>
@ -207,7 +207,7 @@ fn int? MTree.add(&tree, int parent, Type t)
// if the new node does not land in the same subtree as the child we cannot do // if the new node does not land in the same subtree as the child we cannot do
// anything since the references are immutable // anything since the references are immutable
if (new_next/BITS != subtree) { if (new_next/BITS != subtree) {
return CAPACITY_EXCEEDED?; return CAPACITY_EXCEEDED~;
} }
tree.set_used(new_next); tree.set_used(new_next);
tree.elements++; tree.elements++;
@ -330,13 +330,13 @@ fn void MTree.prune(&tree, int parent)
fn Type? MTree.get(&tree, int ref) @operator([]) fn Type? MTree.get(&tree, int ref) @operator([])
{ {
if (tree.is_used(ref)) return tree.elem_vec[ref]; if (tree.is_used(ref)) return tree.elem_vec[ref];
return NOT_FOUND?; return NOT_FOUND~;
} }
<* @param [&in] tree *> <* @param [&in] tree *>
fn Type? MTree.parentof(&tree, int ref) fn Type? MTree.parentof(&tree, int ref)
{ {
if (!tree.is_used(ref)) return NOT_FOUND?; if (!tree.is_used(ref)) return NOT_FOUND~;
return tree.refs_vec[ref].parent; return tree.refs_vec[ref].parent;
} }

View File

@ -35,7 +35,7 @@ fn void? SpriteAtlas.init(&this, String name, AtlasType type, ushort width, usho
{ {
// FIXME: for now only R8G8B8A8 format is supported // FIXME: for now only R8G8B8A8 format is supported
if (type != ATLAS_R8G8B8A8) { if (type != ATLAS_R8G8B8A8) {
return INVALID_TYPE?; return INVALID_TYPE~;
} }
this.id = name.hash(); this.id = name.hash();

View File

@ -13,7 +13,7 @@ macro usz LineInfo.len(li) => li.end-li.start;
alias LineStack @local = list::List{LineInfo}; alias LineStack @local = list::List{LineInfo};
fn short Rect.y_off(Rect bounds, short height, Anchor anchor) @local fn short Rect.y_off(Rect bounds, short height, Anchor anchor)
{ {
short off; short off;
@ -34,7 +34,7 @@ fn short Rect.y_off(Rect bounds, short height, Anchor anchor) @local
return off; return off;
} }
fn short Rect.x_off(Rect bounds, short width, Anchor anchor) @local fn short Rect.x_off(Rect bounds, short width, Anchor anchor)
{ {
short off; short off;
@ -205,7 +205,7 @@ fn Rect? GlyphIterator.next(&self)
// check if there is a next glyph and maybe update the line and offset indices // check if there is a next glyph and maybe update the line and offset indices
if (self.anchor != TOP_LEFT) { if (self.anchor != TOP_LEFT) {
if (self.line_idx >= self.lines.len()) { if (self.line_idx >= self.lines.len()) {
return NO_MORE_ELEMENT?; return NO_MORE_ELEMENT~;
} }
LineInfo li = self.lines[self.line_idx]; LineInfo li = self.lines[self.line_idx];
@ -213,7 +213,7 @@ fn Rect? GlyphIterator.next(&self)
self.line_idx++; self.line_idx++;
if (self.line_idx >= self.lines.len()) { if (self.line_idx >= self.lines.len()) {
return NO_MORE_ELEMENT?; return NO_MORE_ELEMENT~;
} }
self.line_off = 0; self.line_off = 0;
@ -223,7 +223,7 @@ fn Rect? GlyphIterator.next(&self)
self.o.x = self.bounds.x + self.bounds.x_off(li.width, self.anchor) - li.first_off; self.o.x = self.bounds.x + self.bounds.x_off(li.width, self.anchor) - li.first_off;
} }
} else if (self.line_off >= self.text.len) { } else if (self.line_off >= self.text.len) {
return NO_MORE_ELEMENT?; return NO_MORE_ELEMENT~;
} }
String t; String t;