sle/src/main.c

63 lines
1.7 KiB
C

/* SPDX-License-Identifier: GPL-3.0-or-later */
/* Copyright (C) 2021 KikooDX */
#include "editing_area/main.h"
#include "shared_data.h"
#include "tile_picker/main.h"
#include <raylib.h>
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include <sys/mman.h>
#include <sys/types.h>
#include <unistd.h>
static void *create_shared_memory(size_t size);
/* The editor fork to create two windows. One will be the level editor
* and the other the tile selection. This is done to allow the user to
* organize these panels in the way they want to. */
int main(int argc, char **argv)
{
struct SharedData *shared_data =
(struct SharedData *)create_shared_memory(
sizeof(struct SharedData));
shared_data->end_child = false;
shared_data->selected_tile = 69;
pid_t child_process;
/* set log level */
SetTraceLogLevel(LOG_ERROR);
/* check for argument count */
if (argc != 3) {
fprintf(stderr, "ERROR: expected 2 arguments, got %d\n",
argc - 1);
return EXIT_FAILURE;
};
/* forking here */
child_process = fork();
if (child_process < 0) {
fprintf(stderr, "ERROR: process couldn't fork");
return EXIT_FAILURE;
} else if (child_process == 0) {
/* child process, start the tile picker */
return tile_picker_main(argc, argv, shared_data);
} else {
/* main process, start the editing area */
editing_area_main(argc, argv, shared_data);
return EXIT_SUCCESS;
}
}
static void *create_shared_memory(size_t size)
{
/* shared memory will be read & write */
int protection = PROT_READ | PROT_WRITE;
/* anonymous and shared, only child process will be able to
* access it */
int visibility = MAP_SHARED | MAP_ANONYMOUS;
return mmap(NULL, size, protection, visibility, -1, 0);
}