Compare commits

..

10 Commits

Author SHA1 Message Date
ce1e9abc39
Remove the build status badge
All checks were successful
Build and test / build (push) Successful in 1m39s
It links to drone, which we have phased out in favor of Gitea Actions.
2024-03-29 20:50:14 +01:00
b803358ea3
editor: Fix creation of new files
The editor is supposed to create files if they don't exist, however before this commit stat() would fail and exit load_file() before we even got to File::open_or_create().
2024-03-29 20:50:14 +01:00
2e53f9999f
editor: Display only the basename of the current file in the window title 2024-03-29 20:50:14 +01:00
bd5a231936
terminal: Use widget->window() instead of the App's main window 2024-03-29 20:50:14 +01:00
cc3be43633
editor: Use TextInput as a base class 2024-03-29 20:50:14 +01:00
677bcb861e
libui: Add a TextInput base class to handle most input fields and add an InputField class for single-line inputs 2024-03-29 20:50:14 +01:00
5dc23d1a09
editor: Refuse to load non-regular file types 2024-03-29 20:50:13 +01:00
47538b16fd
editor: Remove insert mode and use the arrow keys to navigate, plus Ctrl+S to save 2024-03-29 20:50:13 +01:00
77737c2cd8
editor: Add basic loading and saving 2024-03-29 20:50:13 +01:00
622a044244
editor: Add a basic text editor 2024-03-29 20:50:13 +01:00
13 changed files with 11 additions and 306 deletions

View File

@ -98,13 +98,8 @@ extern "C"
* endptr if nonnull. */ * endptr if nonnull. */
unsigned long strtoul(const char* str, char** endptr, int base); unsigned long strtoul(const char* str, char** endptr, int base);
/* Parse an integer of the specified base from a string, storing the first non-number character in endptr if #define strtoll strtol
* nonnull. */ #define strtoull strtoul
long long strtoll(const char* str, char** endptr, int base);
/* Parse an unsigned integer of the specified base from a string, storing the first non-number character in
* endptr if nonnull. */
unsigned long long strtoull(const char* str, char** endptr, int base);
/* Return the next pseudorandom number. */ /* Return the next pseudorandom number. */
int rand(); int rand();

View File

@ -22,7 +22,6 @@
#define _POSIX_SYNCHRONIZED_IO 200112L #define _POSIX_SYNCHRONIZED_IO 200112L
#define _POSIX_SAVED_IDS 200112L #define _POSIX_SAVED_IDS 200112L
#define _POSIX_VDISABLE (-2) #define _POSIX_VDISABLE (-2)
#define _POSIX_VERSION 200112L
#ifdef __cplusplus #ifdef __cplusplus
extern "C" extern "C"

View File

@ -101,16 +101,6 @@ extern "C"
return rc; return rc;
} }
long long strtoll(const char* str, char** endptr, int base)
{
return strtol(str, endptr, base);
}
unsigned long long strtoull(const char* str, char** endptr, int base)
{
return strtoul(str, endptr, base);
}
__noreturn void abort() __noreturn void abort()
{ {
// First, try to unblock SIGABRT and then raise it. // First, try to unblock SIGABRT and then raise it.

View File

@ -69,13 +69,5 @@ namespace ui
* @param stride The number of pixels to skip to go to the next line. * @param stride The number of pixels to skip to go to the next line.
*/ */
void fill(u32* pixels, int stride); void fill(u32* pixels, int stride);
/**
* @brief Fill the canvas with pixels, without doing any extra processing.
*
* @param pixels The array of pixels (must be at least width*height).
* @param stride The number of pixels to skip to go to the next line.
*/
void copy(u32* pixels, int stride);
}; };
}; };

View File

@ -7,7 +7,6 @@
* *
*/ */
#include <luna/CString.h>
#include <ui/Canvas.h> #include <ui/Canvas.h>
namespace ui namespace ui
@ -60,16 +59,4 @@ namespace ui
p += stride * sizeof(Color); p += stride * sizeof(Color);
} }
} }
void Canvas::copy(u32* pixels, int _stride)
{
u8* p = ptr;
for (int i = 0; i < height; i++)
{
u32* colorp = (u32*)p;
memcpy(colorp, pixels, width * sizeof(u32));
pixels += _stride;
p += stride * sizeof(Color);
}
}
} }

View File

@ -13,10 +13,8 @@ Name | Version | Description | URL
---|---|--- | --- ---|---|--- | ---
bc | 6.6.0 | An implementation of the POSIX bc calculator | https://github.com/gavinhoward/bc bc | 6.6.0 | An implementation of the POSIX bc calculator | https://github.com/gavinhoward/bc
binutils | 2.39 | The GNU suite of binary utilities | https://www.gnu.org/software/binutils binutils | 2.39 | The GNU suite of binary utilities | https://www.gnu.org/software/binutils
doomgeneric | 0.0.1 | Easily portable doom | https://github.com/ozkl/doomgeneric
gcc | 12.2.0 | The GNU Compiler Collection | https://www.gnu.org/software/gcc gcc | 12.2.0 | The GNU Compiler Collection | https://www.gnu.org/software/gcc
gmp | 6.3.0 | The GNU Multiple Precision Arithmetic Library | https://gmplib.org gmp | 6.3.0 | The GNU Multiple Precision Arithmetic Library | https://gmplib.org
libwind | 0.0.1 | A standalone implementation of the wind client protocol | https://git.cloudapio.eu/apio/libwind
minitar | 1.7.5 | Tiny and easy-to-use C library to read/write tar archives | https://git.cloudapio.eu/apio/minitar minitar | 1.7.5 | Tiny and easy-to-use C library to read/write tar archives | https://git.cloudapio.eu/apio/minitar
mpc | 1.3.1 | The GNU Multiple Precision Complex Library | https://www.multiprecision.org mpc | 1.3.1 | The GNU Multiple Precision Complex Library | https://www.multiprecision.org
mpfr | 4.2.0 | The GNU Multiple Precision Floating-Point Reliable Library | https://mpfr.org mpfr | 4.2.0 | The GNU Multiple Precision Floating-Point Reliable Library | https://mpfr.org

View File

@ -1,32 +0,0 @@
# Basic information
name="doomgeneric"
version="0.0.1"
dependencies=(libwind)
# Download options
format="git"
url="https://github.com/ozkl/doomgeneric.git"
# Build instructions
do_patch()
{
patch -ui $portdir/doomgeneric.patch -p 1 -d $srcdir
}
do_configure()
{
:
}
do_build()
{
cd $srcdir/doomgeneric
make
}
do_install()
{
cd $srcdir/doomgeneric
mkdir -p $installdir/usr/bin/
cp doomgeneric $installdir/usr/bin/
}

View File

@ -1,197 +0,0 @@
diff --git a/doomgeneric/Makefile b/doomgeneric/Makefile
index 503e0dc..5c44a6d 100644
--- a/doomgeneric/Makefile
+++ b/doomgeneric/Makefile
@@ -12,17 +12,16 @@ else
endif
-CC=clang # gcc or g++
-CFLAGS+=-ggdb3 -Os
+CC=$(LUNA_ARCH)-luna-gcc
LDFLAGS+=-Wl,--gc-sections
-CFLAGS+=-ggdb3 -Wall -DNORMALUNIX -DLINUX -DSNDSERV -D_DEFAULT_SOURCE # -DUSEASM
-LIBS+=-lm -lc -lX11
+CFLAGS+=-ggdb3 -Os -Wall -fno-omit-frame-pointer -DNORMALUNIX -DLINUX -DSNDSERV -D_DEFAULT_SOURCE # -DUSEASM
+LIBS+=-lc -lwind
# subdirectory for objects
OBJDIR=build
OUTPUT=doomgeneric
-SRC_DOOM = dummy.o am_map.o doomdef.o doomstat.o dstrings.o d_event.o d_items.o d_iwad.o d_loop.o d_main.o d_mode.o d_net.o f_finale.o f_wipe.o g_game.o hu_lib.o hu_stuff.o info.o i_cdmus.o i_endoom.o i_joystick.o i_scale.o i_sound.o i_system.o i_timer.o memio.o m_argv.o m_bbox.o m_cheat.o m_config.o m_controls.o m_fixed.o m_menu.o m_misc.o m_random.o p_ceilng.o p_doors.o p_enemy.o p_floor.o p_inter.o p_lights.o p_map.o p_maputl.o p_mobj.o p_plats.o p_pspr.o p_saveg.o p_setup.o p_sight.o p_spec.o p_switch.o p_telept.o p_tick.o p_user.o r_bsp.o r_data.o r_draw.o r_main.o r_plane.o r_segs.o r_sky.o r_things.o sha1.o sounds.o statdump.o st_lib.o st_stuff.o s_sound.o tables.o v_video.o wi_stuff.o w_checksum.o w_file.o w_main.o w_wad.o z_zone.o w_file_stdc.o i_input.o i_video.o doomgeneric.o doomgeneric_xlib.o
+SRC_DOOM = dummy.o am_map.o doomdef.o doomstat.o dstrings.o d_event.o d_items.o d_iwad.o d_loop.o d_main.o d_mode.o d_net.o f_finale.o f_wipe.o g_game.o hu_lib.o hu_stuff.o info.o i_cdmus.o i_endoom.o i_joystick.o i_scale.o i_sound.o i_system.o i_timer.o memio.o m_argv.o m_bbox.o m_cheat.o m_config.o m_controls.o m_fixed.o m_menu.o m_misc.o m_random.o p_ceilng.o p_doors.o p_enemy.o p_floor.o p_inter.o p_lights.o p_map.o p_maputl.o p_mobj.o p_plats.o p_pspr.o p_saveg.o p_setup.o p_sight.o p_spec.o p_switch.o p_telept.o p_tick.o p_user.o r_bsp.o r_data.o r_draw.o r_main.o r_plane.o r_segs.o r_sky.o r_things.o sha1.o sounds.o statdump.o st_lib.o st_stuff.o s_sound.o tables.o v_video.o wi_stuff.o w_checksum.o w_file.o w_main.o w_wad.o z_zone.o w_file_stdc.o i_input.o i_video.o doomgeneric.o doomgeneric_luna.o
OBJS += $(addprefix $(OBJDIR)/, $(SRC_DOOM))
all: $(OUTPUT)
@@ -51,4 +50,3 @@ $(OBJDIR)/%.o: %.c
print:
@echo OBJS: $(OBJS)
-
diff --git a/doomgeneric/doomgeneric_luna.c b/doomgeneric/doomgeneric_luna.c
new file mode 100644
index 0000000..4d37ddc
--- /dev/null
+++ b/doomgeneric/doomgeneric_luna.c
@@ -0,0 +1,160 @@
+#include "doomgeneric.h"
+#include "wind.h"
+#include <string.h>
+#include <time.h>
+#include <unistd.h>
+#include <sys/time.h>
+#include <stdio.h>
+#include "doomkeys.h"
+
+static wind_client_t g_client;
+static wind_window_t g_window;
+
+#define KEYQUEUE_SIZE 16
+
+static unsigned short s_KeyQueue[KEYQUEUE_SIZE];
+static unsigned int s_KeyQueueWriteIndex = 0;
+static unsigned int s_KeyQueueReadIndex = 0;
+
+static unsigned char convertToDoomKey(enum wind_keycode scancode)
+{
+ unsigned char key = 0;
+
+ switch (scancode)
+ {
+ case wind_key_Enter:
+ key = KEY_ENTER;
+ break;
+ case wind_key_Esc:
+ key = KEY_ESCAPE;
+ break;
+ case wind_key_LeftArrow:
+ key = KEY_LEFTARROW;
+ break;
+ case wind_key_RightArrow:
+ key = KEY_RIGHTARROW;
+ break;
+ case wind_key_UpArrow:
+ key = KEY_UPARROW;
+ break;
+ case wind_key_DownArrow:
+ key = KEY_DOWNARROW;
+ break;
+ case wind_key_LeftControl:
+ key = KEY_FIRE;
+ break;
+ case wind_key_RightControl:
+ key = KEY_USE;
+ break;
+ case wind_key_RightShift:
+ key = KEY_RSHIFT;
+ break;
+ case wind_key_CH18:
+ key = 'y';
+ break;
+ default:
+ break;
+ }
+
+ return key;
+}
+
+static void addKeyToQueue(int pressed, enum wind_keycode keyCode)
+{
+ unsigned char key = convertToDoomKey(keyCode);
+
+ unsigned short keyData = (pressed << 8) | key;
+
+ s_KeyQueue[s_KeyQueueWriteIndex] = keyData;
+ s_KeyQueueWriteIndex++;
+ s_KeyQueueWriteIndex %= KEYQUEUE_SIZE;
+}
+
+static int event_handler(wind_client_t*, uint8_t event, void*)
+{
+ switch (event)
+ {
+ case wind_MouseEvent: {
+ struct wind_mouse_event_request event_data;
+ wind_read_response(&g_client, event, &event_data, sizeof event_data);
+ break;
+ }
+ case wind_MouseLeave: {
+ struct wind_mouse_leave_request event_data;
+ wind_read_response(&g_client, event, &event_data, sizeof event_data);
+ break;
+ }
+ case wind_KeyEvent: {
+ struct wind_key_event_request event_data;
+ wind_read_response(&g_client, event, &event_data, sizeof event_data);
+ addKeyToQueue(event_data.pressed, event_data.code);
+ break;
+ }
+
+ default:
+ break;
+ }
+
+ return 0;
+}
+
+void DG_Init() {
+ wind_connect(&g_client, WIND_SOCKET_PATH, 0);
+ wind_set_handler(&g_client, event_handler, NULL);
+
+ struct wind_rect rect = {
+ .pos = {0,0},
+ .width = DOOMGENERIC_RESX,
+ .height =DOOMGENERIC_RESY
+ };
+
+ int result = wind_create_window(&g_client, &g_window, rect);
+ if(result < 0) perror("wind_create_window");
+}
+
+void DG_DrawFrame() {
+ wind_check_for_messages(&g_client);
+
+ memcpy(g_window.canvas, DG_ScreenBuffer, DOOMGENERIC_RESX*DOOMGENERIC_RESY*4);
+ wind_invalidate(&g_client, &g_window);
+}
+
+int DG_GetKey(int *pressed, unsigned char *doomKey) { if (s_KeyQueueReadIndex == s_KeyQueueWriteIndex)
+ {
+ //key queue is empty
+
+ return 0;
+ }
+ else
+ {
+ unsigned short keyData = s_KeyQueue[s_KeyQueueReadIndex];
+ s_KeyQueueReadIndex++;
+ s_KeyQueueReadIndex %= KEYQUEUE_SIZE;
+
+ *pressed = keyData >> 8;
+ *doomKey = keyData & 0xFF;
+
+ return 1;
+ } }
+
+void DG_SleepMs(uint32_t ms) { usleep(ms * 1000); }
+
+void DG_SetWindowTitle(const char *title) { wind_set_window_title(&g_client, &g_window, title); }
+
+uint32_t DG_GetTicksMs() {
+ struct timespec ts;
+ clock_gettime(CLOCK_MONOTONIC, &ts);
+ return (ts.tv_sec * 1000) + (ts.tv_nsec / 1000000);
+}
+
+int main(int argc, char **argv)
+{
+ doomgeneric_Create(argc, argv);
+
+ while (1)
+ {
+ doomgeneric_Tick();
+ }
+
+ return 0;
+}

View File

@ -1,26 +0,0 @@
# Basic information
name="libwind"
version="0.0.1"
# Download options
format="git"
url="https://git.cloudapio.eu/apio/libwind.git"
# Build instructions
do_configure()
{
:
}
do_build()
{
cd $srcdir
make
}
do_install()
{
export DESTDIR=$installdir/usr
cd $srcdir
make install
}

0
tools/exec/luna-pkg-config Executable file → Normal file
View File

View File

@ -83,7 +83,6 @@ case $SUBCOMMAND in
;; ;;
generate-diff) generate-diff)
cd ${srcdir:-$WORKDIR/$name-$version} cd ${srcdir:-$WORKDIR/$name-$version}
git add -N .
git diff > $LUNA_ROOT/ports/$name/$name.patch git diff > $LUNA_ROOT/ports/$name/$name.patch
echo "Created $LUNA_ROOT/ports/$name/$name.patch. Remember to add patching code to the PACKAGE file!" echo "Created $LUNA_ROOT/ports/$name/$name.patch. Remember to add patching code to the PACKAGE file!"
;; ;;

View File

@ -19,11 +19,11 @@
_expr_rc.release_value(); \ _expr_rc.release_value(); \
}) })
#define CHECK_WINDOW_ID(request, context) \ #define CHECK_WINDOW_ID(request) \
do { \ do { \
if ((usize)request.window >= client.windows.size() || !client.windows[request.window]) \ if ((usize)request.window >= client.windows.size() || !client.windows[request.window]) \
{ \ { \
os::eprintln("wind: Window id is invalid! (%s)", context); \ os::eprintln("wind: Window id is invalid!"); \
return {}; \ return {}; \
} \ } \
} while (0) } while (0)
@ -76,7 +76,7 @@ static Result<void> handle_remove_shm_message(Client& client)
ui::RemoveSharedMemoryRequest request; ui::RemoveSharedMemoryRequest request;
if (!TRY(client.conn->read_message(request))) return {}; if (!TRY(client.conn->read_message(request))) return {};
CHECK_WINDOW_ID(request, "RemoveShm"); CHECK_WINDOW_ID(request);
shm_unlink(client.windows[request.window]->shm_path.chars()); shm_unlink(client.windows[request.window]->shm_path.chars());
@ -92,7 +92,7 @@ static Result<void> handle_set_window_title_message(Client& client)
os::println("wind: SetWindowTitle(\"%s\") for window %d", name.chars(), request.window); os::println("wind: SetWindowTitle(\"%s\") for window %d", name.chars(), request.window);
CHECK_WINDOW_ID(request, "SetWindowTitle"); CHECK_WINDOW_ID(request);
client.windows[request.window]->name = move(name); client.windows[request.window]->name = move(name);
@ -104,7 +104,7 @@ static Result<void> handle_invalidate_message(Client& client)
ui::InvalidateRequest request; ui::InvalidateRequest request;
if (!TRY(client.conn->read_message(request))) return {}; if (!TRY(client.conn->read_message(request))) return {};
CHECK_WINDOW_ID(request, "Invalidate"); CHECK_WINDOW_ID(request);
client.windows[request.window]->dirty = true; client.windows[request.window]->dirty = true;
@ -116,7 +116,7 @@ static Result<void> handle_close_window_message(Client& client)
ui::CloseWindowRequest request; ui::CloseWindowRequest request;
if (!TRY(client.conn->read_message(request))) return {}; if (!TRY(client.conn->read_message(request))) return {};
CHECK_WINDOW_ID(request, "CloseWindow"); CHECK_WINDOW_ID(request);
auto* window = client.windows[request.window]; auto* window = client.windows[request.window];
client.windows[request.window] = nullptr; client.windows[request.window] = nullptr;
@ -146,7 +146,7 @@ static Result<void> handle_set_titlebar_height_message(Client& client)
if (request.height < 0) request.height = 0; if (request.height < 0) request.height = 0;
CHECK_WINDOW_ID(request, "SetTitlebarHeight"); CHECK_WINDOW_ID(request);
auto* window = client.windows[request.window]; auto* window = client.windows[request.window];
@ -173,7 +173,7 @@ static Result<void> handle_set_special_window_attributes_message(Client& client)
return {}; return {};
} }
CHECK_WINDOW_ID(request, "SetSpecialWindowAttributes"); CHECK_WINDOW_ID(request);
client.windows[request.window]->attributes = request.attributes; client.windows[request.window]->attributes = request.attributes;

View File

@ -12,7 +12,7 @@ void Window::draw(ui::Canvas& screen)
dirty = false; dirty = false;
auto window = screen.subcanvas(surface); auto window = screen.subcanvas(surface);
window.copy(pixels, surface.width); window.fill(pixels, surface.width);
} }
void Window::focus() void Window::focus()