project restructure (removed some files that are not needed for this project from the template & moved the files containing utils like features to the utils folder)

This commit is contained in:
Stefan Stefanov 2024-04-23 12:49:44 +03:00
parent 0faa687d05
commit 194550335d
7 changed files with 10 additions and 148 deletions

View file

@ -448,7 +448,6 @@ open_file_dialog :: proc() {
fmt.println("Got an empty path from the file dialog!")
}
case .OutputFolder:
file := cstring(
diag.select_folder_dialog(

View file

@ -1,8 +0,0 @@
package game
Vec2i :: [2]int
Vec2 :: [2]f32
vec2_from_vec2i :: proc(p: Vec2i) -> Vec2 {
return {f32(p.x), f32(p.y)}
}

View file

@ -1,70 +0,0 @@
package game
import "core:slice"
import rl "vendor:raylib"
Texture :: rl.Texture
Color :: rl.Color
texture_rect :: proc(tex: Texture, flip_x: bool) -> Rect {
return(
{
x = 0,
y = 0,
width = flip_x ? -f32(tex.width) : f32(tex.width),
height = f32(tex.height),
} \
)
}
load_premultiplied_alpha_ttf_from_memory :: proc(file_data: []byte, font_size: int) -> rl.Font {
font := rl.Font {
baseSize = i32(font_size),
glyphCount = 95,
}
font.glyphs = rl.LoadFontData(
&file_data[0],
i32(len(file_data)),
font.baseSize,
{},
font.glyphCount,
.DEFAULT,
)
if font.glyphs != nil {
font.glyphPadding = 4
atlas := rl.GenImageFontAtlas(
font.glyphs,
&font.recs,
font.glyphCount,
font.baseSize,
font.glyphPadding,
0,
)
atlas_u8 := slice.from_ptr((^u8)(atlas.data), int(atlas.width * atlas.height * 2))
for i in 0 ..< atlas.width * atlas.height {
a := atlas_u8[i * 2 + 1]
v := atlas_u8[i * 2]
atlas_u8[i * 2] = u8(f32(v) * (f32(a) / 255))
}
font.texture = rl.LoadTextureFromImage(atlas)
rl.SetTextureFilter(font.texture, .BILINEAR)
// Update glyphs[i].image to use alpha, required to be used on ImageDrawText()
for i in 0 ..< font.glyphCount {
rl.UnloadImage(font.glyphs[i].image)
font.glyphs[i].image = rl.ImageFromImage(atlas, font.recs[i])
}
//TRACELOG(LOG_INFO, "FONT: Data loaded successfully (%i pixel size | %i glyphs)", font.baseSize, font.glyphCount);
rl.UnloadImage(atlas)
} else {
font = rl.GetFontDefault()
}
return font
}

View file

@ -1,66 +0,0 @@
// procs for modifying and managing rects
package game
import rl "vendor:raylib"
Rect :: rl.Rectangle
RectEmpty :: Rect{}
split_rect_top :: proc(r: Rect, y: f32, m: f32) -> (top, bottom: Rect) {
top = r
bottom = r
top.y += m
top.height = y
bottom.y += y + m
bottom.height -= y + m
return
}
split_rect_left :: proc(r: Rect, x: f32, m: f32) -> (left, right: Rect) {
left = r
right = r
left.width = x
right.x += x + m
right.width -= x + m
return
}
split_rect_bottom :: proc(r: rl.Rectangle, y: f32, m: f32) -> (top, bottom: rl.Rectangle) {
top = r
top.height -= y + m
bottom = r
bottom.y = top.y + top.height + m
bottom.height = y
return
}
split_rect_right :: proc(r: Rect, x: f32, m: f32) -> (left, right: Rect) {
left = r
right = r
right.width = x
left.width -= x + m
right.x = left.x + left.width
return
}
rect_middle :: proc(r: Rect) -> Vec2 {
return {r.x + f32(r.width) * 0.5, r.y + f32(r.height) * 0.5}
}
inset_rect :: proc(r: Rect, x: f32, y: f32) -> Rect {
return {r.x + x, r.y + y, r.width - x * 2, r.height - y * 2}
}
rect_add_pos :: proc(r: Rect, p: Vec2) -> Rect {
return {r.x + p.x, r.y + p.y, r.width, r.height}
}
mouse_in_rect :: proc(r: Rect) -> bool {
return rl.CheckCollisionPointRec(rl.GetMousePosition(), r)
}
mouse_in_world_rect :: proc(r: Rect, camera: rl.Camera2D) -> bool {
return rl.CheckCollisionPointRec(rl.GetScreenToWorld2D(rl.GetMousePosition(), camera), r)
}

View file

@ -4,7 +4,7 @@
// `animation_rect` when you wish to know the source rect to use in the texture
// With the source rect you can run rl.DrawTextureRec to draw the current frame.
package game
package utils
import "core:log"

View file

@ -3,7 +3,7 @@
// that makes sure you don't get bugs when slots are re-used.
// Read more about it here: https://floooh.github.io/2018/06/17/handles-vs-pointers.html */
package game
package utils
Handle :: struct($T: typeid) {
// idx 0 means unused. Note that slot 0 is a dummy slot, it can never be used.

View file

@ -1,6 +1,6 @@
// generic odin helpers
package game
package utils
import "core:intrinsics"
import "core:reflect"
@ -39,3 +39,10 @@ remap :: proc "contextless" (
}
return clamp(((old_value - old_min) / old_range) * new_range + new_min, new_min, new_max)
}
Vec2i :: [2]int
Vec2 :: [2]f32
vec2_from_vec2i :: proc(p: Vec2i) -> Vec2 {
return {f32(p.x), f32(p.y)}
}