Compare commits

..

No commits in common. "e193109570cc0bb93eb669833e42872c3765b1c5" and "60bec17d36aa2fd1bddb3ffd4413bbfe867b6716" have entirely different histories.

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) {
p = atlas.row;
} 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
* 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
macro Cache.cycle(&cache) {
macro Cache.cycle(&cache) @private {
cache.cycle_count++;
if (cache.cycle_count > CACHE_NCYCLES) {
for (usz i = 0; i < cache.present.data.len; i++) {
@ -64,14 +64,14 @@ fn Value*? Cache.search(&cache, Key id)
/* MISS, wrong key */
if (entry.key != id) {
cache.table.remove(id)!;
return NOT_FOUND~;
return NOT_FOUND?;
}
/* MISS, the data is not valid (not present) */
if (!cache.present[entry.value]) {
// if the data is not present but it is still in the table, remove it
cache.table.remove(id)!;
return NOT_FOUND~;
return NOT_FOUND?;
}
/* 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 */
/* If there is no free space left then just return the first position */
fn usz Cache.get_free_spot(&cache)
fn usz Cache.get_free_spot(&cache) @private
{
// TODO: in the upgrade to c3 1.7.5 use @bitsof()
const BITS = $typeof(cache.present.data[0]).sizeof*8;
@ -108,7 +108,7 @@ fn usz Cache.get_free_spot(&cache)
return 0;
}
fn Value*? Cache.insert_at(&cache, Value* g, Key id, usz index)
fn Value*? Cache.insert_at(&cache, Value* g, Key id, usz index) @private
{
// TODO: verify index, g and id
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);
if (catch e = c) {
if (e != NOT_FOUND) {
return e~;
return e?;
} else {
// if the element is new (inserted) set the is_new flag
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.layout = {};
if (is_new == false && elem.type != type) {
return WRONG_ELEMENT_TYPE~;
return WRONG_ELEMENT_TYPE?;
} else {
elem.type = type;
}
@ -272,7 +272,7 @@ fn void? Ctx.frame_end(&ctx)
{
Elem* root = ctx.get_active_div()!;
if (root.id != ROOT_ID) {
return WRONG_ID~;
return WRONG_ID?;
}
// 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);
if (font.sft.font == null) {
font.table.free();
return TTF_LOAD_FAILED~;
return TTF_LOAD_FAILED?;
}
schrift::SftLMetrics lmetrics;
@ -122,7 +122,7 @@ fn Glyph*? Font.get_glyph(&font, Codepoint code)
if (catch excuse = gp) {
if (excuse != NOT_FOUND) {
return excuse~;
return excuse?;
}
} else {
return gp;
@ -136,11 +136,11 @@ fn Glyph*? Font.get_glyph(&font, Codepoint code)
schrift::SftGMetrics gmtx;
if (schrift::lookup(&font.sft, (SftUChar)code, &gid) < 0) {
return MISSING_GLYPH~;
return MISSING_GLYPH?;
}
if (schrift::gmetrics(&font.sft, gid, &gmtx) < 0) {
return BAD_GLYPH_METRICS~;
return BAD_GLYPH_METRICS?;
}
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);
img.pixels = pixels;
if (schrift::render(&font.sft, gid, img) < 0) {
return RENDER_ERROR~;
return RENDER_ERROR?;
}
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
if (name.hash() != ctx.font.id) {
return WRONG_ID~;
return WRONG_ID?;
}
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)
{
if (width <= 0 || height <= 0) {
return INVALID_SIZE~;
return INVALID_SIZE?;
}
ctx.current_input.events.resize = ctx.width != width || ctx.height != height;
ctx.width = width;

View File

@ -1,4 +1,4 @@
module mtree<Type>;
module mtree{Type};
/* ================================================================================================
* MTree, Bitmap-based tree
@ -127,7 +127,7 @@ fn int? MTree.get_free_spot(&tree)
return spot;
}
}
return CAPACITY_EXCEEDED~;
return CAPACITY_EXCEEDED?;
}
<* @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
// anything since the references are immutable
if (new_next/BITS != subtree) {
return CAPACITY_EXCEEDED~;
return CAPACITY_EXCEEDED?;
}
tree.set_used(new_next);
tree.elements++;
@ -330,13 +330,13 @@ fn void MTree.prune(&tree, int parent)
fn Type? MTree.get(&tree, int ref) @operator([])
{
if (tree.is_used(ref)) return tree.elem_vec[ref];
return NOT_FOUND~;
return NOT_FOUND?;
}
<* @param [&in] tree *>
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;
}

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
if (type != ATLAS_R8G8B8A8) {
return INVALID_TYPE~;
return INVALID_TYPE?;
}
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};
fn short Rect.y_off(Rect bounds, short height, Anchor anchor)
fn short Rect.y_off(Rect bounds, short height, Anchor anchor) @local
{
short off;
@ -34,7 +34,7 @@ fn short Rect.y_off(Rect bounds, short height, Anchor anchor)
return off;
}
fn short Rect.x_off(Rect bounds, short width, Anchor anchor)
fn short Rect.x_off(Rect bounds, short width, Anchor anchor) @local
{
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
if (self.anchor != TOP_LEFT) {
if (self.line_idx >= self.lines.len()) {
return NO_MORE_ELEMENT~;
return NO_MORE_ELEMENT?;
}
LineInfo li = self.lines[self.line_idx];
@ -213,7 +213,7 @@ fn Rect? GlyphIterator.next(&self)
self.line_idx++;
if (self.line_idx >= self.lines.len()) {
return NO_MORE_ELEMENT~;
return NO_MORE_ELEMENT?;
}
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;
}
} else if (self.line_off >= self.text.len) {
return NO_MORE_ELEMENT~;
return NO_MORE_ELEMENT?;
}
String t;