entry_selector : u16;
range_shift : u16;
- table_map : I32Map(TTTableInfo);
+ table_map : i32map.I32Map(TTTableInfo);
char_maps : [..] TTCmap;
version : u32;
ttf_create :: proc (ttf_data: [] u8) -> TrueTypeFont {
ttf : TrueTypeFont;
ttf.reader = binary_reader_create(ttf_data);
- i32map_init(^ttf.table_map);
- array_init(^ttf.char_maps);
+ i32map.init(^ttf.table_map);
+ array.init(^ttf.char_maps);
ttf_read_offset_table(^ttf);
ttf_read_head_table(^ttf);
ttf_read_cmap_table(^ttf);
table_info.offset = read_u32(^reader);
table_info.length = read_u32(^reader);
- i32map_put(^table_map, tag_int, table_info);
+ i32map.put(^table_map, tag_int, table_info);
- if !string_equal(tag, "head") {
+ if !str.equal(tag, "head") {
csum := ttf_calc_table_checksum(^reader, table_info.offset, table_info.length);
if table_info.checksum != csum {
print("WARNING: Checksum for table '");
ttf_read_head_table :: proc (use ttf: ^TrueTypeFont) {
empty_table_hack := TTTableInfo.{};
- head_table_info := i32map_get(^table_map, string_to_beu32("head"), empty_table_hack);
+ head_table_info := i32map.get(^table_map, string_to_beu32("head"), empty_table_hack);
seek(^reader, head_table_info.offset);
version = read_u32(^reader);
ttf_lookup_glyph_offset :: proc (use ttf: ^TrueTypeFont, glyph_index: i32) -> u32 {
empty_table_hack := TTTableInfo.{};
- loca_table_info := i32map_get(^table_map, string_to_beu32("loca"), empty_table_hack);
- glyf_table_info := i32map_get(^table_map, string_to_beu32("glyf"), empty_table_hack);
+ loca_table_info := i32map.get(^table_map, string_to_beu32("loca"), empty_table_hack);
+ glyf_table_info := i32map.get(^table_map, string_to_beu32("glyf"), empty_table_hack);
old: u32;
defer seek(^reader, old);
offset := ttf_lookup_glyph_offset(ttf, glyph_index);
empty_table_hack := TTTableInfo.{};
- glyf_table_info := i32map_get(^table_map, string_to_beu32("glyf"), empty_table_hack);
+ glyf_table_info := i32map.get(^table_map, string_to_beu32("glyf"), empty_table_hack);
if offset >= glyf_table_info.offset + glyf_table_info.length do return null;
}
ttf_glyph_destroy :: proc (glyph: ^TTGlyph) {
- array_free(^glyph.contour_ends);
- array_free(^glyph.points);
+ array.free(^glyph.contour_ends);
+ array.free(^glyph.points);
cfree(glyph);
}
#private_file
ttf_read_simple_glyph :: proc (use ttf: ^TrueTypeFont, glyph: ^TTGlyph) {
- array_init(^glyph.contour_ends, ~~glyph.contour_count);
- array_init(^glyph.points);
+ array.init(^glyph.contour_ends, ~~glyph.contour_count);
+ array.init(^glyph.points);
for i: 0 .. ~~glyph.contour_count {
- array_push(^glyph.contour_ends, read_u16(^reader));
+ array.push(^glyph.contour_ends, read_u16(^reader));
}
seek(^reader, ~~read_u16(^reader) + tell(^reader));
if glyph.contour_count == ~~0 do return;
- num_points := array_fold(^glyph.contour_ends, cast(u16) 0, max_poly) + ~~1;
+ num_points := array.fold(^glyph.contour_ends, cast(u16) 0, math.max) + ~~1;
flags : [..] TTGlyphFlags;
- array_init(^flags);
- defer array_free(^flags);
+ array.init(^flags);
+ defer array.free(^flags);
for i: 0 .. ~~num_points {
flag := cast(TTGlyphFlags) read_u8(^reader);
- array_push(^flags, flag);
- array_push(^glyph.points, TTGlyphPoint.{ on_curve = (flag & TTGlyphFlags.On_Curve) != ~~0 });
+ array.push(^flags, flag);
+ array.push(^glyph.points, TTGlyphPoint.{ on_curve = (flag & TTGlyphFlags.On_Curve) != ~~0 });
if (flag & TTGlyphFlags.Repeat) != ~~0 {
rep_count := read_u8(^reader);
i += ~~rep_count;
for i: 0 .. ~~rep_count {
- array_push(^flags, flag);
- array_push(^glyph.points, TTGlyphPoint.{ on_curve = (flag & TTGlyphFlags.On_Curve) != ~~0 });
+ array.push(^flags, flag);
+ array.push(^glyph.points, TTGlyphPoint.{ on_curve = (flag & TTGlyphFlags.On_Curve) != ~~0 });
}
}
}
ttf_glyph_count :: proc (use ttf: ^TrueTypeFont) -> u32 {
empty_table_hack := TTTableInfo.{};
- maxp_table_info := i32map_get(^table_map, string_to_beu32("maxp"), empty_table_hack);
+ maxp_table_info := i32map.get(^table_map, string_to_beu32("maxp"), empty_table_hack);
old := seek(^reader, maxp_table_info.offset + 4);
defer seek(^reader, old);
ttf_read_cmap_table :: proc (use ttf: ^TrueTypeFont) {
empty_table_hack := TTTableInfo.{};
- cmap_table_info := i32map_get(^table_map, string_to_beu32("cmap"), empty_table_hack);
+ cmap_table_info := i32map.get(^table_map, string_to_beu32("cmap"), empty_table_hack);
seek(^reader, cmap_table_info.offset);
version := read_u16(^reader);
range_shift : u16;
segments : [..] TTSegment;
- cache : I32Map(i32);
+ cache : i32map.I32Map(i32);
}
TTSegment :: struct {
cmap.cmap0.format = TTCmapFormat.Simple;
glyphs : [..] u8;
- array_init(^glyphs, 256);
- for i: 0 .. 256 do array_push(^glyphs, read_u8(^reader));
+ array.init(^glyphs, 256);
+ for i: 0 .. 256 do array.push(^glyphs, read_u8(^reader));
- cmap.cmap0.glyph_indicies = array_to_slice(^glyphs);
+ cmap.cmap0.glyph_indicies = array.to_slice(^glyphs);
- array_push(^char_maps, cmap);
+ array.push(^char_maps, cmap);
}
ttf_read_cmap4 :: proc (use ttf: ^TrueTypeFont) {
cmap : TTCmap;
cmap.cmap4.format = TTCmapFormat.Segmented;
map := ^cmap.cmap4;
- i32map_init(^map.cache);
+ i32map.init(^map.cache);
map.seg_count = read_u16(^reader) >> ~~1;
map.search_range = read_u16(^reader);
map.entry_selector = read_u16(^reader);
map.range_shift = read_u16(^reader);
- array_init(^map.segments, ~~map.seg_count);
+ array.init(^map.segments, ~~map.seg_count);
map.segments.count = cast(u32) map.seg_count;
for ^seg: map.segments do seg.end_code = read_u16(^reader);
if seg.id_range_offset != ~~0 do seg.id_range_offset += ~~(tell(^reader) - 2);
}
- array_push(^char_maps, cmap);
+ array.push(^char_maps, cmap);
}
ttf_lookup_glyph_by_char :: proc (use ttf: ^TrueTypeFont, charcode: u32) -> u32 {
#private_file
ttf_lookup_in_cmap4 :: proc (use ttf: ^TrueTypeFont, cmap: ^TTCmap4, charcode: u32) -> u32 {
- if i32map_has(^cmap.cache, charcode) do return i32map_get(^cmap.cache, charcode);
+ if i32map.has(^cmap.cache, charcode) do return i32map.get(^cmap.cache, charcode);
index := 0;
for ^seg: cmap.segments {
}
}
- i32map_put(^cmap.cache, charcode, index);
+ i32map.put(^cmap.cache, charcode, index);
return index;
}
ttf_read_hhea_table :: proc (use ttf: ^TrueTypeFont) {
empty_table_hack := TTTableInfo.{};
- hhea_table_info := i32map_get(^table_map, string_to_beu32("hhea"), empty_table_hack);
+ hhea_table_info := i32map.get(^table_map, string_to_beu32("hhea"), empty_table_hack);
seek(^reader, hhea_table_info.offset);
hhea.version = read_u32(^reader);
ttf_lookup_horizontal_metrics :: proc (use ttf: ^TrueTypeFont, glyph_index: u32) -> TTHorizontalMetrics {
empty_table_hack := TTTableInfo.{};
- hmtx_table_info := i32map_get(^table_map, string_to_beu32("hmtx"), empty_table_hack);
+ hmtx_table_info := i32map.get(^table_map, string_to_beu32("hmtx"), empty_table_hack);
offset := hmtx_table_info.offset;
hmtx : TTHorizontalMetrics;
curr_y := 0;
poly_points : [..] V2i;
- array_init(^poly_points, 16);
- defer array_free(^poly_points);
+ array.init(^poly_points, 16);
+ defer array.free(^poly_points);
for i: 0 .. glyph.points.count {
p := glyph.points[i];
curr_x = cast(i32) p.x;
curr_y = cast(i32) p.y;
- array_push(^poly_points, V2i.{ ~~p.x, ~~p.y });
+ array.push(^poly_points, V2i.{ ~~p.x, ~~p.y });
state = 1;
}
curr_x = cast(i32) p.x;
curr_y = cast(i32) p.y;
- array_push(^poly_points, V2i.{ ~~p.x, ~~p.y });
+ array.push(^poly_points, V2i.{ ~~p.x, ~~p.y });
} else {
state = 2;
for t: 1 .. 5 {
s := bezier_curve(~~t / 4.0f, bps);
- array_push(^poly_points, V2i.{ ~~s.x, ~~s.y });
+ array.push(^poly_points, V2i.{ ~~s.x, ~~s.y });
}
curr_x = cast(i32) p.x;
for t: 1 .. 5 {
s := bezier_curve(~~t / 4.0f, bps);
- array_push(^poly_points, V2i.{ ~~s.x, ~~s.y });
+ array.push(^poly_points, V2i.{ ~~s.x, ~~s.y });
}
curr_x = cast(i32) bp[2].x;
for t: 1 .. 5 {
s := bezier_curve(~~t / 4.0f, bps);
- array_push(^poly_points, V2i.{ ~~s.x, ~~s.y });
+ array.push(^poly_points, V2i.{ ~~s.x, ~~s.y });
}
} else {
for t: 1 .. 5 {
s := bezier_curve(~~t / 4.0f, bps);
- array_push(^poly_points, V2i.{ ~~s.x, ~~s.y });
+ array.push(^poly_points, V2i.{ ~~s.x, ~~s.y });
}
}
sx := x * ~~units_per_em / width;
sy := y * ~~units_per_em / height;
- if is_inside_polygon(array_to_slice(^poly_points), V2i.{ sx, sy }) {
+ if is_inside_polygon(array.to_slice(^poly_points), V2i.{ sx, sy }) {
curr := data[x + (height - 1 - y) * width];
if curr == ~~0 do data[x + (height - 1 - y) * width] = cast(u8) 255;
else do data[x + (height - 1 - y) * width] = cast(u8) 0;
}
}
- array_clear(^poly_points);
+ array.clear(^poly_points);
}
}
-package gfx
+package gfx.atlas
use package core
use package gl as gl
use package gl_utils as gl_utils
+use package gfx.texture as texture
+use package gfx.quad_renderer { Quad }
Atlas :: struct {
- texture : ^Texture;
- map : I32Map(AtlasSprite);
+ texture : ^texture.Texture;
+ map : i32map.I32Map(AtlasSprite);
}
AtlasSprite :: struct {
h : f32 = 0.0f;
}
-atlas_create :: proc (tex: ^Texture) -> Atlas {
+create :: proc (tex: ^texture.Texture) -> Atlas {
atlas : Atlas;
atlas.texture = tex;
- i32map_init(^atlas.map);
+ i32map.init(^atlas.map);
return atlas;
}
-atlas_map :: proc (use atlas: ^Atlas, id: i32, sprite: AtlasSprite) {
- i32map_put(^map, id, sprite);
+map :: proc (use atlas: ^Atlas, id: i32, sprite: AtlasSprite) {
+ i32map.put(^map, id, sprite);
}
-atlas_lookup :: proc (use atlas: ^Atlas, id: i32, offset := 0) -> AtlasSprite {
- sprite := i32map_get(^map, id, AtlasSprite.{});
+lookup :: proc (use atlas: ^Atlas, id: i32, offset := 0) -> AtlasSprite {
+ sprite := i32map.get(^map, id, AtlasSprite.{});
if offset != 0 {
sprite.x += ~~offset * sprite.w;
return sprite;
}
-atlas_apply_to_quad :: proc (use atlas: ^Atlas, id: i32, quad: ^Quad) {
- sprite := i32map_get(^map, id, AtlasSprite.{});
+apply_to_quad :: proc (use atlas: ^Atlas, id: i32, quad: ^Quad) {
+ sprite := i32map.get(^map, id, AtlasSprite.{});
quad.tex_size.x = sprite.w / ~~texture.width;
quad.tex_size.y = sprite.h / ~~texture.height;
quad.tex_pos.x = sprite.x / ~~texture.width;
-package gfx
+package gfx.font
use package core
use package globals
use package vecmath
use package main { RenderContext, draw_textured_rect }
+use package gfx.atlas as atlas
#private_file
-font_chars := "0123456789!\"#$% ABCDEFGHIJKLMNOPQRSTUVWXYZ'()*+,abcdefghijklmnopqrstuvwxyz,-./\\,^:;<=>?[]~|_";
+chars := "0123456789!\"#$% ABCDEFGHIJKLMNOPQRSTUVWXYZ'()*+,abcdefghijklmnopqrstuvwxyz,-./\\,^:;<=>?[]~|_";
#private_file
char_to_tex_offset :: proc (ch: u8) -> u32 {
loc := 0;
- for c: font_chars {
+ for c: chars {
if c == ch do break;
loc += 1;
}
font_size := scale * 16.0f;
for ch: s {
- char_sprite := atlas_lookup(^atlas, 2, char_to_tex_offset(ch));
+ char_sprite := atlas.lookup(^main_atlas, 2, char_to_tex_offset(ch));
draw_textured_rect(renderer, x, y, font_size, font_size, char_sprite.x, char_sprite.y, char_sprite.w, char_sprite.h);
x += font_size * 0.85f;
}
-}
\ No newline at end of file
+}
-package gfx
+package gfx.quad_renderer
use package core
use package gl as gl
color : Color4f32 = Color4f32.{ 0f, 0f, 0f, 0f };
}
-quad_renderer_init :: proc (use qr: ^QuadRenderer, initial_quads := 10) {
+init :: proc (use qr: ^QuadRenderer, initial_quads := 10) {
vertexArray = gl.createVertexArray();
gl.bindVertexArray(vertexArray);
gl.vertexAttribPointer(0, 2, gl.FLOAT, false, 2 * sizeof gl.GLfloat, 0);
gl.bindBuffer(gl.ARRAY_BUFFER, -1);
- array_init(^quad_data, initial_quads);
+ array.init(^quad_data, initial_quads);
default_quad := Quad.{};
for i: 0 .. initial_quads {
- array_push(^quad_data, default_quad);
+ array.push(^quad_data, default_quad);
}
quadBuffer = gl.createBuffer();
}
u_proj_loc = gl.getUniformLocation(quad_program, "u_proj");
- quad_renderer_update_view(qr);
+ update_view(qr);
u_world_loc = gl.getUniformLocation(quad_program, "u_world");
- quad_renderer_update_world(qr);
+ update_world(qr);
}
-quad_renderer_draw :: proc (use qr: ^QuadRenderer, count := -1) {
+draw :: proc (use qr: ^QuadRenderer, count := -1) {
c := count;
if count == -1 do c = quad_data.count;
gl.bindVertexArray(-1);
}
-quad_renderer_update_view :: proc (use qr: ^QuadRenderer) {
+update_view :: proc (use qr: ^QuadRenderer) {
proj_mat : [4 * 4] gl.GLfloat;
for ^it: proj_mat do *it = 0.0f;
gl.uniformMatrix4(u_proj_loc, true, proj_mat);
}
-quad_renderer_update_world :: proc (use qr: ^QuadRenderer,
+update_world :: proc (use qr: ^QuadRenderer,
scale_x := 1.0f, scale_y := 1.0f, trans_x := 0.0f, trans_y := 0.0f) {
world_mat : [4 * 4] gl.GLfloat;
for ^it: world_mat do *it = 0.0f;
gl.uniformMatrix4(u_world_loc, false, world_mat);
}
-quad_update_at_index :: proc (use qr: ^QuadRenderer, idx: i32, quad: Quad) {
+update_at_index :: proc (use qr: ^QuadRenderer, idx: i32, quad: Quad) {
quad_data[idx] = quad;
is_data_dirty = true;
}
-quad_rebuffer_data :: proc (use qr: ^QuadRenderer) {
+rebuffer_data :: proc (use qr: ^QuadRenderer) {
if !is_data_dirty do return;
gl.bindBuffer(gl.ARRAY_BUFFER, quadBuffer);
-package gfx
+package gfx.texture
use package core
use package gl as gl
smile : Texture;
}
-textures_init :: proc () {
- textures.tilemap = texture_create(#file_contents "res/tilemap.data", 256, 256);
- textures.smile = texture_create(#file_contents "res/smile.data", 32, 32);
+init :: proc () {
+ textures.tilemap = create(#file_contents "res/tilemap.data", 256, 256);
+ textures.smile = create(#file_contents "res/smile.data", 32, 32);
- texture_prepare(^textures.tilemap);
- texture_prepare(^textures.smile);
+ prepare(^textures.tilemap);
+ prepare(^textures.smile);
}
}
// NOTE: This assumes that the data is raw u8 RGB packed color data.
-texture_create :: proc (texdata: [] u8, width: i32, height: i32, data_mode := TextureDataMode.RGB) -> Texture {
+create :: proc (texdata: [] u8, width: i32, height: i32, data_mode := TextureDataMode.RGB) -> Texture {
tex : Texture;
tex.data = texdata;
tex.width = width;
return tex;
}
-texture_prepare :: proc (use tex: ^Texture) {
+prepare :: proc (use tex: ^Texture) {
if texture_id != -1 do return;
format := gl.RGB;
gl.bindTexture(gl.TEXTURE_2D, -1);
}
-texture_use :: proc (use tex: ^Texture) {
+use_texture :: proc (use tex: ^Texture) {
gl.bindTexture(gl.TEXTURE_2D, texture_id);
}
use package input as input
use package main
-use package gfx
+use package gfx as gfx
+use package gfx.atlas as atlas
use package quad_tree
window_width := 0
renderer : RenderContext
input_state : input.InputState
-atlas : Atlas
+main_atlas : atlas.Atlas
dudes : [..] Dude
dude_tree : QuadTree(Dude)
use package core
use package gfx
+use package gfx.quad_renderer { Color4f32, Quad, QuadRenderer }
use package gl as gl
use package event as event
use package input as input { Key }
NUM_QUADS :: 1 << 17
RenderContext :: struct {
- quad_renderer: ^QuadRenderer;
+ quads: ^QuadRenderer;
curr_quad_idx: i32 = 0;
max_quad_idx: i32 = 0;
if aqr == null {
aqr = calloc(sizeof QuadRenderer);
- quad_renderer_init(aqr, NUM_QUADS);
+ quad_renderer.init(aqr, NUM_QUADS);
}
*rc = RenderContext.{
- quad_renderer = aqr,
+ quads = aqr,
max_quad_idx = qr.quad_data.count,
};
}
draw_rect :: proc (use rc: ^RenderContext, x: f32, y: f32, w: f32, h: f32) {
if curr_quad_idx >= max_quad_idx do return;
- quad_update_at_index(quad_renderer, curr_quad_idx, Quad.{
+ quad_renderer.update_at_index(quads, curr_quad_idx, Quad.{
pos = V2f.{ x, y },
size = V2f.{ w, h },
color = color,
draw_textured_rect :: proc (use rc: ^RenderContext, x: f32, y: f32, w: f32, h: f32, tx: f32, ty: f32, tw: f32, th: f32) {
if curr_quad_idx >= max_quad_idx do return;
- quad_update_at_index(quad_renderer, curr_quad_idx, Quad.{
+ quad_renderer.update_at_index(quads, curr_quad_idx, Quad.{
pos = V2f.{ x, y },
size = V2f.{ w, h },
color = color,
draw_quad :: proc (use rc: ^RenderContext, quad: ^Quad) {
if curr_quad_idx >= max_quad_idx do return;
- quad_update_at_index(quad_renderer, curr_quad_idx, *quad);
+ quad_renderer.update_at_index(quads, curr_quad_idx, *quad);
curr_quad_idx += 1;
}
render_context_ui :: proc (use rc: ^RenderContext) {
- quad_renderer_update_world(quad_renderer, 1.0f, 1.0f, ~~-half_window_width, ~~-half_window_height);
- quad_rebuffer_data(quad_renderer);
- quad_renderer_draw(quad_renderer, curr_quad_idx);
+ quad_renderer.update_world(quads, 1.0f, 1.0f, ~~-half_window_width, ~~-half_window_height);
+ quad_renderer.rebuffer_data(quads);
+ quad_renderer.draw(quads, curr_quad_idx);
curr_quad_idx = 0;
}
render_context_transformation :: proc (use rc: ^RenderContext) {
- quad_renderer_update_world(quad_renderer, scale, scale, trans_x, trans_y);
- quad_rebuffer_data(quad_renderer);
- quad_renderer_draw(quad_renderer, curr_quad_idx);
+ quad_renderer.update_world(quads, scale, scale, trans_x, trans_y);
+ quad_renderer.rebuffer_data(quads);
+ quad_renderer.draw(quads, curr_quad_idx);
curr_quad_idx = 0;
}
gl.canvasSize(window_width, window_height);
gl.viewport(0, 0, window_width, window_height);
- quad_renderer_update_view(renderer.quad_renderer);
+ quad_renderer.update_view(renderer.quads);
}
case #default do input.process_event(^input_state, ^ev);
}
if simulating {
- quad_scratch : ScratchState;
+ quad_scratch : allocator.ScratchState;
quad_alloc : Allocator;
- scratch_state_init(^quad_scratch, ~~quad_scratch_buffer, 512 * 1024);
- scratch_alloc_init(^quad_alloc, ^quad_scratch);
+ allocator.scratch_state_init(^quad_scratch, ~~quad_scratch_buffer, 512 * 1024);
+ allocator.scratch_alloc_init(^quad_alloc, ^quad_scratch);
quadtree_init(^dude_tree, AABB.{ 0.0f, 0.0f, ~~tilemap.width * TILE_SIZE, ~~tilemap.height * TILE_SIZE});
for ^d: dudes do quadtree_insert(^dude_tree, d, quad_alloc);
gl.clear(gl.COLOR_BUFFER_BIT);
// World Rendering
- texture_use(^textures.tilemap);
+ texture.use_texture(^texture.textures.tilemap);
tilemap_draw(^tilemap, ^renderer);
// draw_quad_tree(^dude_tree);
- dude_sprite := atlas_lookup(^atlas, 0);
+ dude_sprite := atlas.lookup(^main_atlas, 0);
for ^d: dudes {
aabb := dude_get_aabb(d);
renderer.color = d.color;
draw_rect(^renderer, 10.0f, 10.0f, 1000.0f, 50.0f);
renderer.color = Color4f32.{ 0.0f, 0.0f, 0.0f, 1.0f };
- draw_text(^renderer, "Hello. Test(12486)", V2f.{ 10.0f, 10.0f }, 2.0f);
+ font.draw_text(^renderer, "Hello. Test(12486)", V2f.{ 10.0f, 10.0f }, 2.0f);
draw_rect(^renderer, ~~input_state.mouse.x, ~~input_state.mouse.y, 10f, 10f);
render_context_ui(^renderer);
println("Setting up WebGL2 canvas...");
time_now :: proc () -> u32 #foreign "time" "now" ---;
- random_seed(time_now());
+ random.set_seed(time_now());
if !gl.init("gamecanvas") {
print("Failed to initialize GL canvas.");
gl.blendFunc(gl.SRC_ALPHA, gl.ONE_MINUS_SRC_ALPHA);
render_context_init(^renderer, null);
- textures_init();
+ texture.init();
- atlas = atlas_create(^textures.tilemap);
- atlas_map(^atlas, 0, AtlasSprite.{ x = 16.0f, y = 0.0f, w = 16.0f, h = 16.0f });
- atlas_map(^atlas, 1, AtlasSprite.{ x = 32.0f, y = 0.0f, w = 16.0f, h = 16.0f });
+ main_atlas = atlas.create(^texture.textures.tilemap);
+ atlas.map(^main_atlas, 0, atlas.AtlasSprite.{ x = 16.0f, y = 0.0f, w = 16.0f, h = 16.0f });
+ atlas.map(^main_atlas, 1, atlas.AtlasSprite.{ x = 32.0f, y = 0.0f, w = 16.0f, h = 16.0f });
- atlas_map(^atlas, 2, AtlasSprite.{ x = 0.0f, y = 160.0f, w = 16.0f, h = 16.0f });
+ atlas.map(^main_atlas, 2, atlas.AtlasSprite.{ x = 0.0f, y = 160.0f, w = 16.0f, h = 16.0f });
event.init();
input.init(^input_state);
Dude_Color_Table[1] = Color4f32.{ 0.2f, 1.0f, 0.2f, 1.0f };
Dude_Color_Table[2] = Color4f32.{ 0.2f, 0.2f, 1.0f, 1.0f };
- array_init(^dudes);
+ array.init(^dudes);
for i: 0 .. 2000 {
- array_push(^dudes, dude_create_random());
+ array.push(^dudes, dude_create_random());
}
tilemap_init(^tilemap, 250, 140);
dude_create_random :: proc () -> Dude {
return Dude.{
- pos = V2f.{ random_float(0.0f, 1200.0f), random_float(0.0f, 1200.0f) },
- vel = V2f.{ random_float(-3.0f, 3.0f), random_float(-3.0f, 3.0f) },
- size = random_float(4.0f, 6.0f),
- color = Dude_Color_Table[random() % 3],
+ pos = V2f.{ random.float(0.0f, 1200.0f), random.float(0.0f, 1200.0f) },
+ vel = V2f.{ random.float(-3.0f, 3.0f), random.float(-3.0f, 3.0f) },
+ size = random.float(4.0f, 6.0f),
+ color = Dude_Color_Table[random.int() % 3],
// BUG: These should not have to be here but because of the "use entity" in the defintion of Dude, they do.
// I presume this is because entity counts as toward the number of needed elements, even though it shouldn't.
}
dude_update :: proc (use dude: ^Dude, dt: f32, other_dudes: ^QuadTree(Dude)) {
- if random_between(0, 100) < 1 || couldnt_move_count >= ~~2 {
- vel.x = random_float(-300.0f, 300.0f);
- vel.y = random_float(-300.0f, 300.0f);
+ if random.between(0, 100) < 1 || couldnt_move_count >= ~~2 {
+ vel.x = random.float(-300.0f, 300.0f);
+ vel.y = random.float(-300.0f, 300.0f);
couldnt_move_count = ~~0;
}
old_pos := pos;
potential_dudes : [..] ^Dude;
- array_init(^potential_dudes);
- defer array_free(^potential_dudes);
+ array.init(^potential_dudes);
+ defer array.free(^potential_dudes);
around := AABB.{ x = pos.x - size * 5.0f, y = pos.y - size * 5.0f, w = size * 10.0f, h = size * 10.0f };
quadtree_query(other_dudes, around, ^potential_dudes);
tilemap_init :: proc (use tm: ^Tilemap, w := 10, h := 10) {
width = w;
height = h;
- alloc_slice(^tiles, width * height);
+ allocator.alloc_slice(^tiles, width * height);
printf("The tilemap takes up %i kibibytes.\n", (width * height * sizeof Tile) >> 10);
quadtree_query :: proc (use qt: ^QuadTree($T), r: AABB, p: ^[..] ^T) {
if !aabb_intersects(region, r) do return;
- while i := 0; i < points_count {
- if aabb_contains(r, points[i].pos) do array_push(p, points[i]);
- i += 1;
+ // while i := 0; i < points_count {
+ // if aabb_contains(r, points[i].pos) do array_push(p, points[i]);
+ // i += 1;
+ // }
+
+ for i: 0 .. points_count {
+ if aabb_contains(r, points[i].pos) do array.push(p, points[i]);
}
if nw == null do return;
package gl_utils
-use package core { string_make }
+use package core.str { make as string_make }
use package gl as gl
compile_shader :: proc (shader_type: gl.GLenum, source: string) -> gl.GLShader {
// assumes a b and c are colinear
v2_on_segment :: proc (a: V2($T), b: V2(T), c: V2(T)) -> bool {
- return b.x <= max_poly(a.x, c.x)
- && b.x >= min_poly(a.x, c.x)
- && b.y <= max_poly(a.y, c.y)
- && b.y >= min_poly(a.y, c.y);
+ return b.x <= math.max(a.x, c.x)
+ && b.x >= math.min(a.x, c.x)
+ && b.y <= math.max(a.y, c.y)
+ && b.y >= math.min(a.y, c.y);
}