58 Commits

Author SHA1 Message Date
Aryadev Chavali
925c5e0372 Add raylib 5.5 to our codebase and statically link with it
This way you won't need to install raylib as a dependency in order to
use it.  You'll still need its dependencies, like glfw, but this
should remove one layer of indirection.
2025-12-12 06:12:38 +00:00
Aryadev Chavali
82604480c0 Setup variable in build script for user to adjust thread timers 2025-12-12 05:42:13 +00:00
Aryadev Chavali
ca3bb64aae Allow compiler-level declarations for the thread timers
We use a #define here to set these up - if you define them via a -D
block yourself, you can adjust these as you require.
2025-12-12 05:42:10 +00:00
Aryadev Chavali
0cb14af26e Push THREAD_GENERAL_DELAY to 100ms 2025-12-12 05:16:01 +00:00
Aryadev Chavali
01484a65ec Add a camera to move around the numberline, add text for the bounds 2025-12-12 05:15:17 +00:00
Aryadev Chavali
8cd700a9e0 Delete old main 2025-12-12 04:42:16 +00:00
Aryadev Chavali
38d531ca31 feat! Multithreading
commit a763bff532
Author: Aryadev Chavali <aryadev@aryadevchavali.com>
Date:   Fri Dec 12 04:33:13 2025 +0000

    Added release mode building

    Now the build script enables you to:
    - Build in debug mode (default no arguments)
    - Build in debug mode then run (`run` argument)
    - Build in release mode (`release` argument)

commit 7112937b0b
Author: Aryadev Chavali <aryadev@aryadevchavali.com>
Date:   Fri Dec 12 04:30:50 2025 +0000

    Better thread pool constructor

    statically define a number of threads, then setup the necessary
    machinery to make it work.

commit a5666328b7
Author: Aryadev Chavali <aryadev@aryadevchavali.com>
Date:   Fri Dec 12 04:29:32 2025 +0000

    Fixed the heap-use-after-free issue.

    Just standard multithreading stuff; access to the allocator while hot
    threads are running means stuff can change underneath us even /during/
    a read.  I've mutex locked state for stuff in the drawing domain which
    stops this issue.

commit 5d78cb20df
Author: Aryadev Chavali <aryadev@aryadevchavali.com>
Date:   Fri Dec 12 04:28:21 2025 +0000

    Adjust TODOs

commit 9d3a202c27
Author: Aryadev Chavali <aryadev@aryadevchavali.com>
Date:   Fri Dec 12 04:09:50 2025 +0000

    Implement stepping via KEY_SPACE

commit 424fab2e40
Author: Aryadev Chavali <aryadev@aryadevchavali.com>
Date:   Fri Dec 12 04:08:01 2025 +0000

    Weird bug in draw_tree

    Seems near the 100,000 node mark, the vector craps itself?  I keep
    getting "heap use after free" errors here when trying to access the
    allocator vector.  Disabling fsan just leads to a segment fault near
    the same point.

    I think we might need to introduce our own vector :)

commit 6ffa63f7ac
Author: Aryadev Chavali <aryadev@aryadevchavali.com>
Date:   Fri Dec 12 04:07:43 2025 +0000

    Make general delay 1ms

    Just for my puny eyes to see.

commit 2dbe3d0a58
Author: Aryadev Chavali <aryadev@aryadevchavali.com>
Date:   Fri Dec 12 03:54:30 2025 +0000

    merge generate_children into do_iteration

    Also fix this really weird slow down we get from doing direct mutation
    to a state.allocator.get_ref (i.e. a Node by reference).  Maybe the
    compiler just can't inline that instruction?  Regardless, this patch
    fixes the slow downs!

commit 7e801df280
Author: Aryadev Chavali <aryadev@aryadevchavali.com>
Date:   Fri Dec 12 03:53:51 2025 +0000

    no more numerics

commit f70517cf41
Author: Aryadev Chavali <aryadev@aryadevchavali.com>
Date:   Fri Dec 12 03:08:56 2025 +0000

    Simplify mutex locking scheme (lock at start, unlock at end)

commit 00858cf74f
Author: Aryadev Chavali <aryadev@aryadevchavali.com>
Date:   Fri Nov 28 17:24:33 2025 +0000

    Rewrite main to draw based on our new state/draw_state

    Arranges a thread set, draws based on draw_state.  No need to lock the
    mutex since drawing should only require reading.  Still has a timer in
    case we need to do timed checks.

commit 3e065e50a9
Author: Aryadev Chavali <aryadev@aryadevchavali.com>
Date:   Fri Nov 28 17:24:12 2025 +0000

    Disable previous work

    We're going to rewrite this

commit ab0f152742
Author: Aryadev Chavali <aryadev@aryadevchavali.com>
Date:   Fri Nov 28 17:23:05 2025 +0000

    Define `worker` function which a thread should run

    Pauses until state.pause_work is false (checking every
    THREAD_PAUSE_DELAY), then performs an iteration.  Quits when
    state.quit_work is true (based on loop).  Generally delays itself by
    THREAD_GENERAL_DELAY.

commit 014821ceb5
Author: Aryadev Chavali <aryadev@aryadevchavali.com>
Date:   Fri Nov 28 17:22:39 2025 +0000

    Added booleans for thread workers to look at when running

    pause_work temporarily stops work, but should keep the thread alive.

    stop_work should kill the thread.

commit 1bd8a9f7b2
Author: Aryadev Chavali <aryadev@aryadevchavali.com>
Date:   Fri Nov 28 17:21:21 2025 +0000

    Add run component to build script, activated by passing argument `run`

commit 6f620644bf
Author: Aryadev Chavali <aryadev@aryadevchavali.com>
Date:   Thu Nov 27 01:57:10 2025 +0000

    Define constructors for state.hpp explicitly

commit 0008c31f53
Author: Aryadev Chavali <aryadev@aryadevchavali.com>
Date:   Thu Nov 27 01:53:10 2025 +0000

    Add src/worker.cpp to build pipeline

commit f8068c4a15
Author: Aryadev Chavali <aryadev@aryadevchavali.com>
Date:   Thu Nov 27 01:52:52 2025 +0000

    Implement the two worker functions

commit 66c56f2c15
Author: Aryadev Chavali <aryadev@aryadevchavali.com>
Date:   Thu Nov 27 01:51:41 2025 +0000

    Define thread safe worker functions for generating new children on the tree

commit 6247f2af49
Author: Aryadev Chavali <aryadev@aryadevchavali.com>
Date:   Thu Nov 27 01:44:23 2025 +0000

    Add src/state.cpp to the build pipeline

commit 40e07e03f2
Author: Aryadev Chavali <aryadev@aryadevchavali.com>
Date:   Thu Nov 27 01:42:24 2025 +0000

    Add mutexes to state for the queue and the allocator

    Our threads need to negotiate access and mutation to the two
    resources - we don't want them treading on each others toes when
    generating new child nodes /or/ when trying to remove/add work to the
    queue.  The former situation is particularly worrisome due to how weak
    the indexing system is with the allocator.

commit 0abd353368
Author: Aryadev Chavali <aryadev@aryadevchavali.com>
Date:   Thu Nov 27 01:30:35 2025 +0000

    Implement cw::state::DrawState::compute_bounds

commit 0ac316ada4
Author: Aryadev Chavali <aryadev@aryadevchavali.com>
Date:   Thu Nov 27 01:30:21 2025 +0000

    Define the general state of the sim (extract from main.cpp)

commit a03fa13a07
Author: Aryadev Chavali <aryadev@aryadevchavali.com>
Date:   Thu Nov 27 01:19:52 2025 +0000

    Implementation (copied from numerics)

commit ff9a2851d4
Author: Aryadev Chavali <aryadev@aryadevchavali.com>
Date:   Thu Nov 27 01:19:41 2025 +0000

    Switch to using i64's instead of optional u64 in Node

commit 6c2bc93874
Author: Aryadev Chavali <aryadev@aryadevchavali.com>
Date:   Thu Nov 27 01:12:35 2025 +0000

    remove index_t definition

    conflicts with prev code base.

    Also std::optional doubles the size of the underlying type.
    horrifying!  I don't want to have to give 16 bytes over for something
    that could be embedded in the 8 bytes of the u64 directly.  I'm
    thinking we could just use i64's instead, sacrificing that top bit to
    indicate if the value is present or not.

commit 7a4d158d2f
Author: Aryadev Chavali <aryadev@aryadevchavali.com>
Date:   Thu Nov 27 01:02:31 2025 +0000

    Add gcd to base.hpp

commit e032303773
Author: Aryadev Chavali <aryadev@aryadevchavali.com>
Date:   Thu Nov 27 00:56:45 2025 +0000

    Define node.hpp (move definitions away from numerics.hpp)

commit 9821a2ab15
Author: Aryadev Chavali <aryadev@aryadevchavali.com>
Date:   Thu Nov 27 00:55:44 2025 +0000

    Define basic type aliases and useful functions/macros for use throughout the system
2025-12-12 04:33:54 +00:00
Aryadev Chavali
739409d3be Use a shell script over a makefile
Simpler build system, easier to read.
2025-11-27 00:45:51 +00:00
Aryadev Chavali
9d8215bd45 Adjusted copyright template for code files 2025-11-27 00:39:01 +00:00
Aryadev Chavali
5e9e8d8010 Refined the TODOs 2025-11-17 01:31:35 +00:00
Aryadev Chavali
15b3f9fb12 Add some notes 2025-11-17 01:22:45 +00:00
Aryadev Chavali
8a2214f2fb Simulation only runs if SPACE is held or PERIOD is pressed.
KEY_SPACE, held, will keep the simulation running.

KEY_PERIOD will do exactly one iteration per press.
2025-11-17 01:10:46 +00:00
Aryadev Chavali
bd96755654 Added README 2024-07-27 02:25:52 +01:00
Aryadev Chavali
564bac363f Clean up and use the right initial fraction for CW tree 2024-07-27 02:20:31 +01:00
Aryadev Chavali
76d407ae1b Added timer to automatically do iterations
Looks very cool.
2024-07-27 01:44:07 +01:00
Aryadev Chavali
f1b878c991 Left and right fractions are now drawn at the top with counter 2024-07-27 01:35:43 +01:00
Aryadev Chavali
feabcf24a0 Draw the three iteration nodes in special colours
green for the centre, blue for the new nodes generated.
2024-07-27 01:25:27 +01:00
Aryadev Chavali
1c06a4b613 iterate now returns a tuple of the three fractions worked on
The left, currently processed (centre) and right fractions are
returned by iterate.  This allows us to see exactly what fractions
have been generated/worked on in every iteration.
2024-07-27 01:23:31 +01:00
Aryadev Chavali
32314708d5 Made nested Bounds structure to encapsulate work with bounds
Looks a bit nicer, probably increases padding but whatever.
2024-07-26 21:58:53 +01:00
Aryadev Chavali
bb6ded706f Move all functions and state into one struct
One God structure which will hold all the necessary state, ensuring I
only need to compute stuff like bounds at most once, better than
computing it on every draw (which is WAY slower at scale).
2024-07-26 21:44:08 +01:00
Aryadev Chavali
ca7931e0c2 NodeAllocator constructor now reserves space in vector
This is different to vec{capacity}, which would adjust vec::size.
This adjusts vec::capacity instead, which is what I want.
2024-07-26 21:43:19 +01:00
Aryadev Chavali
7720544e07 NodeAllocator has default constructor
capacity at 0 by default, because it screws with usage of size later.
2024-07-26 21:25:40 +01:00
Aryadev Chavali
0eaa851114 Increase font size, other small changes 2024-07-26 21:08:59 +01:00
Aryadev Chavali
2ddf2d0b48 Clean up count drawing logic a bit, add iterations to the count text 2024-07-26 21:07:18 +01:00
Aryadev Chavali
edc0383132 Added counter to draw loop to show the amount of nodes computed 2024-07-26 21:03:56 +01:00
Aryadev Chavali
a614626b21 Functioning main loop which draws number lines and iterations
Pretty cool!
2024-07-26 21:02:24 +01:00
Aryadev Chavali
950706fdaf Function to draw the complete number line
Draws a guide line, computes bounds (which we should defer), draws all
nodes in the tree then draws the bounds.
2024-07-26 21:00:34 +01:00
Aryadev Chavali
89fd812981 Make draw_node_number_line non recursive
Using a stack or queue, we can replace a function recursive tree
traversal with a single call.  A stack would make it a DFS while a
queue would be a BFS.  Since there's only ever two children, and at
high iteration counts we're getting quite large depth, it would be
best to do a DFS, hence the stack.
2024-07-26 20:53:54 +01:00
Aryadev Chavali
01468f793f recursive function to draw tree in a number line
Draws the current node by converting its norm value (which is in
(lower, upper)) to a screen value, drawing a line there.

It then recurs on the children of the node.
2024-07-26 20:46:39 +01:00
Aryadev Chavali
3a911db312 Helper to draw a fraction as text at point (x, y) 2024-07-26 20:46:34 +01:00
Aryadev Chavali
99d3794749 Helper to convert a value in (min, max) to an equivalent in (0, width) 2024-07-26 20:46:34 +01:00
Aryadev Chavali
096c1089ca Helpers to get the rightmost and leftmost node
This, due to the properties of a cw tree, will be the largest and
smallest fraction of the tree.
2024-07-26 20:46:34 +01:00
Aryadev Chavali
08e890ee4a Define some constants and include a ton of stuff 2024-07-26 20:46:34 +01:00
Aryadev Chavali
163f1e691a NodeAllocator can now get nodes by value or by reference
Abstracting the interface more, such that callers can use functions
rather than accessing internals directly, allows me to refactor the
allocator without having to do a ton of edits all across the source
tree.
2024-07-26 17:01:20 +01:00
Aryadev Chavali
8cbc602799 Changed from int64_t to optional<word_t> for pointers in Node 2024-07-26 17:00:59 +01:00
Aryadev Chavali
c96c4630d5 Make window in Raylib 2024-07-26 03:17:09 +01:00
Aryadev Chavali
66330a9479 Ignore TAGS 2024-07-26 03:15:09 +01:00
Aryadev Chavali
4cc1af94f6 iterate now computes highest value fraction it generated.
Not very useful, but isn't a massive performance waster (I think) and
it will be useful when thinking about colour schemes in graphics.
2024-07-26 03:13:24 +01:00
Aryadev Chavali
84c07870e4 Rework MAX macro to use < operator
MAX now works with Fraction's
2024-07-26 03:13:14 +01:00
Aryadev Chavali
7f7a609d30 Introduce normalised value in fraction class
Bit of a cheat but it would allow us to do some interesting graphical
stuff later.
2024-07-26 03:11:58 +01:00
Aryadev Chavali
f58a7e80ef Add numerics to build system
Successfully compiles and runs!
2024-07-26 02:59:48 +01:00
Aryadev Chavali
6a6ed5a545 Change main to use new numerics module. 2024-07-26 02:59:38 +01:00
Aryadev Chavali
8207d49211 Implemented numerics in numerics.cpp
Simple implementation, few refactors from the main.cpp version based
on API changes.
2024-07-26 02:59:31 +01:00
Aryadev Chavali
139f2e9e5a Rework node constructor and general procedure API
Node constructor is now completely default constructed i.e. no
constructor arguments required.  The iterate function takes the queue
by reference, so it can update the caller's state.

Finally, to_string for a Node now uses the node allocator and an index
to print out trees.  Seems simpler and more in line with the current
implementation.
2024-07-26 02:55:58 +01:00
Aryadev Chavali
d73ecff38a Made header file for a separate numerics file
Separates the (basically) completed cw_tree implementation in a
separate module so we can spend time implementing graphics in main.

NOTE: nodes are now generated from a node allocator, which just wraps
around the vector.  We also take an allocator and queue by reference
in the iterate procedure now.
2024-07-26 02:54:02 +01:00
Aryadev Chavali
9ea4341a80 A simple test, iterating 10 times and printing out the generated tree
Seems to work!
2024-07-26 02:54:02 +01:00
Aryadev Chavali
93d3ce89cc Fix up indenting and empty children in to_string for node 2024-07-26 02:54:02 +01:00
Aryadev Chavali
6dfd820772 Added to_string for Nodes
Recursive implementation with proper indenting!
2024-07-26 02:54:02 +01:00
Aryadev Chavali
5cbdf7a045 Added to_string for fractions 2024-07-26 02:54:02 +01:00
Aryadev Chavali
aad22a1b20 Rework binary tree to use indexes in nodes vector
An index is a pointer, and they don't change if the vector decides to
reallocate internally unlike the bastardised pointers I was rolling up
before.  This simplifies design a bit.
2024-07-26 02:54:02 +01:00