aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorSan Jacobs2023-05-22 01:19:08 +0200
committerSan Jacobs2023-05-22 01:19:08 +0200
commitf047b06ea71ce015eea5747cc5c04008f5bb948a (patch)
treee54f7aad11ec1b04e170e5d23f29edb3da5465c5 /src
parent56ea120ff460aa072da30c30e70bdbd5fd71ba8d (diff)
downloadsatscalc-f047b06ea71ce015eea5747cc5c04008f5bb948a.tar.gz
satscalc-f047b06ea71ce015eea5747cc5c04008f5bb948a.tar.bz2
satscalc-f047b06ea71ce015eea5747cc5c04008f5bb948a.zip
The beginning of timelines!
Diffstat (limited to 'src')
-rw-r--r--src/main.odin107
-rw-r--r--src/time.odin11
2 files changed, 89 insertions, 29 deletions
diff --git a/src/main.odin b/src/main.odin
index 43a9d28..3dc9b9a 100644
--- a/src/main.odin
+++ b/src/main.odin
@@ -8,19 +8,24 @@ import rl "vendor:raylib"
main :: proc() {
+ // TODO: Replace the dynamic array of Workday-pointers with
+ // an actual array of Workdays, plus a length variable
+ // for cache reasons, and to simplify the process of
+ // adding new Workdays to the array.
+
workdays: [dynamic]^Workday
resize(&workdays, 3)
- workday0: = new_workday({10, 22, 4, 5, 2023},
- {00, 08, 5, 5, 2023},
- {00, 22, 5, 5, 2023},
- {30, 21, 5, 5, 2023})
+ workday0: = new_workday({10, 22, 3, 5, 2023},
+ {00, 08, 4, 5, 2023},
+ {00, 22, 4, 5, 2023},
+ {30, 21, 4, 5, 2023})
workdays[0] = &workday0
workday1: = new_workday(workday0.wrap,
- {00, 08, 7, 5, 2023},
- {30, 17, 7, 5, 2023},
- {30, 16, 7, 5, 2023})
+ {00, 08, 5, 5, 2023},
+ {30, 15, 5, 5, 2023},
+ {30, 16, 5, 5, 2023})
workdays[1] = &workday1
workday2: = new_workday(workday1.wrap,
@@ -39,6 +44,10 @@ main :: proc() {
wrap_text: = make([]byte, 6)
defer delete(wrap_text)
wrap_text[len(wrap_text)-1] = 0
+
+ date_text: = make([]byte, len(toString(workday0.call))+1 )
+ defer delete(date_text)
+ wrap_text[len(wrap_text)-1] = 0
total_sum: cstring = "3500 NOK + 26%"
inc_soc: cstring = "4276 NOK"
@@ -46,7 +55,7 @@ main :: proc() {
using rl
- width: i32 = 500
+ width: i32 = 700
height: i32 = 400
InitWindow(width, height, "satscalc")
@@ -68,17 +77,34 @@ main :: proc() {
big_font_size :: 24
big_font: Font = LoadFontEx("res/UbuntuMono-Regular.ttf", big_font_size, nil, 0)
defer UnloadFont(big_font)
+
+
+ // Setting up the timelines
+
+ for day in workdays {
+ beginning: Moment = {0, 0, day.call.day, day.call.month, day.call.year}
+
+ fmt.println("\nNew day!")
+
+ day.fractions[0] = daycount(diff(beginning, day.call))
+ fmt.println(day.fractions[0])
+
+ for each_block, i in day.blocks {
+ if i == day.total_timeblocks do break
+ day.fractions[i+1] = daycount(diff(beginning, each_block.end))
+ fmt.println(day.fractions[i+1])
+ }
+ }
-
- for !WindowShouldClose() {
+ for !WindowShouldClose() { // MAIN LOOP ---- MAIN LOOP ---- MAIN LOOP ---- MAIN LOOP
if IsWindowResized() {
height = GetScreenHeight()
width = GetScreenWidth()
fmt.println("Resized to:", width, 'x', height)
}
-
-
+
+
// TODO: Find a good way to calculate the size and location
// of all the timeblocks in every day.
//
@@ -92,40 +118,63 @@ main :: proc() {
// around the timeblock's timeline square, and display
// information about the block in the bottom left of
// the screen.
-
-
+
+
// DRAW
// ------------------------------------------
BeginDrawing()
+
ClearBackground(BGCOLOR)
- //DrawTextEx(font, "Test text", {20, 20}, 18, 0, RAYWHITE);
-
+ DrawTextEx(font, "Date", {20, 8}, font_size, 0, RAYWHITE);
+ DrawTextEx(font, "Calltime", {105, 8}, font_size, 0, RAYWHITE);
+ DrawTextEx(font, "Wraptime", {f32(width)-83, 8}, font_size, 0, RAYWHITE);
+
for day, i in workdays {
-
+
+ // TODO: The factions held inside Workday-s needs to come in pairs,
+ // just like moments come in pairs of timeblocks.
+ // Because that's a simple way to take care of reading out-of-bounds
+ // and a way to make this section of code a bit more readable.
+
DrawRectangle(10, DAY_HEIGHT*i32(i+1)-4, width-20, DAY_HEIGHT-1, PBGCOLOR)
- for block in day.blocks {
- DrawRectangle(80,
- DAY_HEIGHT*i32(i+1)-4, width-170, DAY_HEIGHT-1, BLUE)
+ for block, j in day.blocks {
+ if j == day.total_timeblocks do break
+ block_color: = GREEN
+ switch {
+ case block.value > 2.1:
+ block_color = PURPLE
+ case block.value > 1.6:
+ block_color = RED
+ case block.value > 1.1:
+ block_color = ORANGE
+ }
+
+ DrawRectangle(TIMELINE_START+i32(math.round(day.fractions[j]*f32(width+TIMELINE_END-TIMELINE_START))),
+ DAY_HEIGHT*i32(i+1)-4,
+ i32(math.round(f32(width+TIMELINE_END-TIMELINE_START)*(day.fractions[j+1]-day.fractions[j]))),
+ DAY_HEIGHT-1,
+ block_color)
}
-
+
copy(call_text, clockprint(day.call))
copy(wrap_text, clockprint(day.wrap))
-
+ copy(date_text, toString(day.call))
+
text_height = math.round(f32(i+1)*DAY_HEIGHT+(DAY_HEIGHT-font_size)*0.25)
-
- DrawTextEx(font, cstring(&call_text[0]), {20, text_height}, font_size, 0, RAYWHITE);
+
+ DrawTextEx(font, cstring(&date_text[0]), {20, text_height}, font_size, 0, RAYWHITE);
DrawTextEx(font, cstring(&wrap_text[0]), {f32(width)-70, text_height}, font_size, 0, RAYWHITE);
-
+
if i == len(workdays)-1 {
DrawTextEx(big_font, "+", {20, DAY_HEIGHT*f32(i+2)}, big_font_size, 0, RAYWHITE)
}
}
-
+
DrawRectangle(0, height-50, width+10, 60, PBGCOLOR)
-
+
DrawTextEx(small_font, total_sum, {f32(width)-120, f32(height)-43}, small_font_size, 0, RAYWHITE);
DrawTextEx(big_font, inc_soc, {f32(width)-120, f32(height)-29}, big_font_size, 0, RAYWHITE);
-
+
EndDrawing()
}
}
@@ -134,3 +183,5 @@ BGCOLOR : rl.Color : {30, 30, 30, 255}
PBGCOLOR : rl.Color : {40, 40, 40, 255}
DAY_HEIGHT :: 35
+TIMELINE_START :: 175
+TIMELINE_END :: -85
diff --git a/src/time.odin b/src/time.odin
index 700bed7..3bd4721 100644
--- a/src/time.odin
+++ b/src/time.odin
@@ -51,6 +51,7 @@ Workday :: struct {
// because lunch breaks
// cause more blocks
blocks : [16]Timeblock,
+ fractions : [16]f32,
total_timeblocks : int,
}
@@ -433,7 +434,7 @@ greatEq :: proc{greatEqMoment}
diff :: proc(moment_a: Moment, moment_b: Moment) -> (acc: Delta) {
- // TODO: Finish writing this
+ // FIXME: This seems to cause either infinite loops or crashes sometimes
// Uses what I call an accumulator-decumulator design
// Count how long it takes to approach a benchmark,
@@ -629,6 +630,14 @@ hourcount :: proc(block: Timeblock) -> f32 {
f32(days) * 24)
}
+daycount :: proc(delta: Delta) -> f32 {
+ using delta
+ assert(delta != {0,0,0})
+ return f32(f32(minutes)/60/24 +
+ f32(hours)/24 +
+ f32(days) )
+}
+
days_in :: proc(month: int, year: int) -> int {
switch month {
case 1: