Add dynamic array debug - resize on every item added, fix window bug

This commit is contained in:
Krzosa Karol
2024-08-08 06:35:37 +02:00
parent 2565cefe70
commit b3b50715b4
4 changed files with 22 additions and 21 deletions

View File

@@ -358,6 +358,14 @@ Slice<T> GetSlice(Slice<T> &arr, int64_t first_index = 0, int64_t one_past_last_
return result;
}
// Make arrays resize on every item
#define ARRAY_DEBUG 1
#if ARRAY_DEBUG
#define ARRAY_IF_DEBUG_ELSE(IF, ELSE) IF
#else
#define ARRAY_IF_DEBUG_ELSE(IF, ELSE) ELSE
#endif
template <class T>
struct Array {
Allocator allocator;
@@ -408,7 +416,7 @@ void Reserve(Array<T> *arr, int64_t size) {
template <class T>
void TryGrowing(Array<T> *arr) {
if (arr->len + 1 > arr->cap) {
int64_t new_size = ClampBottom((int64_t)16, arr->cap * 2);
int64_t new_size = ClampBottom((int64_t)16, arr->cap ARRAY_IF_DEBUG_ELSE(+1, *2));
Reserve(arr, new_size);
}
}
@@ -416,7 +424,7 @@ void TryGrowing(Array<T> *arr) {
template <class T>
void TryGrowing(Array<T> *arr, int64_t item_count) {
if (arr->len + item_count > arr->cap) {
int64_t new_size = ClampBottom((int64_t)16, (arr->cap + item_count) * 2);
int64_t new_size = ClampBottom((int64_t)16, (arr->cap + item_count) ARRAY_IF_DEBUG_ELSE(+1, *2));
Reserve(arr, new_size);
}
}

View File

@@ -219,12 +219,8 @@ Buffer *BufferOpenFile(String path) {
buffer = CreateBuffer(sys_allocator, path, 4096 * 2);
buffer->is_directory = true;
int i = 1;
for (FileIter it = IterateFiles(scratch, path); IsValid(it); Advance(&it)) {
IKnowWhatImDoing_Appendf(buffer, "%.*s", FmtString(it.filename));
if ((i % 8) == 0) IKnowWhatImDoing_Append(buffer, L"\n");
else IKnowWhatImDoing_Append(buffer, L" ");
i += 1;
IKnowWhatImDoing_Appendf(buffer, "%.*s ", FmtString(it.filename));
}
} else {
path = GetAbsolutePath(sys_allocator, path);

View File

@@ -1,5 +1,3 @@
- delete raylib utils, delete WaitForExit?
- remove pointers from ids since they will quickly get invalidated, move fully to array stuff
- Attach BufferID to process, append to that buffer
- kill all processes on exit https://devblogs.microsoft.com/oldnewthing/20131209-00/?p=2433
- AppendToConsole should scroll only if caret is at end and one caret otherwise the carets should not change
@@ -15,9 +13,6 @@
- drag and drop file into the window
- exe icon
- combine glyph and selection rendering
- debugging: resize dynamic array on every item add
- search as a command to execute which is going to be in the title bar
- search backwards
@@ -41,6 +36,7 @@
- draw indentation levels like in sublime (those lines) - we render chars one by one so seems relatively easy to figure out if whitespace belongs to beginning of line (make sure to add max value like 40 because of big files)
- code sections, visual demarkation if beginning of line has a very specific text + goto next / goto prev section hotkey!
- change size of command window because it's wacky
- combine glyph and selection rendering

View File

@@ -38,7 +38,7 @@ Array<Int> GetWindowZOrder(Allocator allocator) {
return order;
}
Window *CreateTitlebar(Window *parent_window) {
Window *CreateTitlebar(WindowID parent_window_id) {
Window *window = CreateWindow();
window->draw_scrollbar = false;
window->dont_save_in_active_window_history = true;
@@ -53,6 +53,7 @@ Window *CreateTitlebar(Window *parent_window) {
View *v = CreateView(b->id);
window->active_view = v->id;
Window *parent_window = GetWindow(parent_window_id);
parent_window->title_bar_window = window->id;
window->title_bar_window = parent_window->id;
@@ -74,7 +75,7 @@ void AddColumnWindow() {
window->is_column = true;
View *view = OpenBufferView("*scratch*");
window->active_view = view->id;
CreateTitlebar(window);
CreateTitlebar(window->id);
}
void AddRowWindow() {
@@ -83,7 +84,7 @@ void AddRowWindow() {
View *view = OpenBufferView("*scratch*");
window->active_view = view->id;
CreateTitlebar(window);
CreateTitlebar(window->id);
Window *active_window = GetActiveWindow();
int64_t active_window_index = GetIndex(Windows, *active_window);
@@ -133,7 +134,7 @@ void InitWindows() {
LoadUnicode(buffer);
// LoadBigTextAndBigLine(buffer, 10000000);
window->active_view = view->id;
CreateTitlebar(window);
CreateTitlebar(window->id);
}
{
@@ -146,7 +147,7 @@ void InitWindows() {
View *view = CreateView(buffer->id);
window->active_view = view->id;
CreateTitlebar(window);
CreateTitlebar(window->id);
SetVisibility(window, false);
ConsoleWindowID = window->id;
@@ -166,7 +167,7 @@ void InitWindows() {
View *view = CreateView(buffer->id);
window->z = 2;
window->active_view = view->id;
Window *titlebar = CreateTitlebar(window);
Window *titlebar = CreateTitlebar(window->id);
titlebar->z = 2;
SetVisibility(window, false);
DebugWindowID = window->id;
@@ -189,7 +190,7 @@ void InitWindows() {
w->active_view = v->id;
w->z = 1;
Window *titlebar = CreateTitlebar(w);
Window *titlebar = CreateTitlebar(w->id);
titlebar->z = 1;
SetVisibility(w, false);
@@ -209,7 +210,7 @@ void InitWindows() {
View *v = CreateView(b->id);
w->active_view = v->id;
CreateTitlebar(w);
CreateTitlebar(w->id);
SetVisibility(w, false);
SearchBufferID = b->id;
@@ -231,7 +232,7 @@ void InitWindows() {
View *v = CreateView(b->id);
w->active_view = v->id;
Window *infobar = CreateTitlebar(w);
Window *infobar = CreateTitlebar(w->id);
infobar->z = 2;
SetVisibility(w, false);