switching to cmake; alyson setup

This commit is contained in:
n0ffie 2025-02-06 22:47:32 +01:00
parent 9504620227
commit 23a40216de
20 changed files with 307 additions and 125300 deletions

3
.gitignore vendored
View file

@ -1,5 +1,8 @@
.bake_cache .bake_cache
.DS_Store .DS_Store
.vscode .vscode
.vs
gcov gcov
bin bin
build
.cache

72
CMakeLists.txt Normal file
View file

@ -0,0 +1,72 @@
cmake_minimum_required(VERSION 3.20)
project(colysis
LANGUAGES C CXX
VERSION 0.0.1
)
# Set C/C++ standards
set(CMAKE_C_STANDARD 11)
set(CMAKE_C_STANDARD_REQUIRED ON)
set(CMAKE_C_EXTENSIONS OFF)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)
# Set compiler flags
set(CMAKE_EXPORT_COMPILE_COMMANDS ON) # Generate compile commands (useful for IDEs)
set(USE_FOLDERS ON) # Organize targets into folders (for IDEs)
set(BUILD_SHARED_LIBS OFF CACHE BOOL "" FORCE) # Build static libraries by default
include(FetchContent)
# Raylib 5.5
FetchContent_Declare(
raylib
GIT_REPOSITORY https://github.com/raysan5/raylib.git
GIT_TAG 5.5
)
FetchContent_MakeAvailable(raylib)
# Flecs
FetchContent_Declare(
flecs
GIT_REPOSITORY https://github.com/SanderMertens/flecs.git
GIT_TAG v4.0.4
)
FetchContent_MakeAvailable(flecs)
## alyson engine (needs flecs and raylib)
set(ASSETS_PATH "${CMAKE_CURRENT_SOURCE_DIR}/assets/")
add_subdirectory(alyson)
## Colysis .game
include(cmake/utils.cmake)
# Get files in src/ and add them to the executable
find_files(colysis_src src cpp hpp cxx hxx c h)
add_executable(colysis
${colysis_src}
)
target_link_libraries(colysis
raylib
flecs::flecs_static
alyson
)
target_include_directories(colysis PUBLIC include
#${ALYSON_INCLUDE_DIR}
)
# put the assets folder path as a C preprocessor define
target_compile_definitions(colysis PRIVATE ASSETS_PATH="${ASSETS_PATH}")
put_targets_into_folder(FOLDER "thid_party" TARGETS raylib flecs::flecs_static)

206
README.md
View file

@ -1,194 +1,36 @@
### I do not own these libraries # Colysis
_This is a template that I have made using both Raylib and Flecs libraries using the bake compiler._ A little Videogame with a custom engine written in C/C++.
It uses [Flecs](https://github.com/SanderMertens/flecs) as a ECS framework and [Raylib](https://www.raylib.com/) as a 2D graphics library.
_Please note that neither Raylib (https://github.com/raysan5/raylib) nor Flecs (https://github.com/SanderMertens/flecs/tree/master) belong to me. I have only created this template for ease-of-use for any developers who desire to start using Flecs and Raylib._ ## Building
To build the project, you need to have [CMake](https://cmake.org/) installed.
# ------ SETTING UP THE PROJECT ------ ### Linux
If this is your first time setting up a project, I will walk you through all of the steps for getting started.
## MacOS or Linux
**1. First, install Brew.**
If you're using MacOS or Linux you will first need to install **Brew**. Open a new terminal and run this command:
```bash ```bash
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)" mkdir build
cd build
cmake ..
make
``` ```
**2. Install Git CLI**
Once that's finished, install the **GitHub CLI** (Command Line Imterface). This is what we will use to install the **bake** compiler. ### Windows
```bash ```bash
brew install git mkdir build
cd build
cmake -G "Visual Studio 17 2022" ..
cmake --build . --config Release
``` ```
> Run `git --version` to make sure it installed correctly. The result should be something like `git version 2.49.1`.
**3. Install Bake** ### macOS
Go to this link ([Bake Compiler](https://github.com/SanderMertens/bake)) and click "Code" and download the zip file.
Once downloaded, open the folder. Open a new terminal and drag and drop `setup.sh` into the terminal window. Press return (or enter) in the terminal, enter your password if asked, and close the terminal when done.
> Again, ensure it installed correctly with `bake --version`
**4. Raylib and Flecs Libraries**
Download this zip file [Unix Raylib Library](https://github.com/user-attachments/files/17962571/libraylib.a.zip) and unzip it once it's downloaded.
Open your device root folder (for example: "Macintosh HD" in finder) then go to Users/*you*/bake/lib (or equivalent on Linux) and put this raylib library in it.
Download the raylib source files by running,
```bash ```bash
cd mkdir build
git clone https://github.com/raysan5/raylib.git cd build
cmake -G "Xcode" ..
cmake --build . --config Release
``` ```
Download this [flecs package](https://github.com/user-attachments/files/17963061/flecs.zip), unzip it, and run: ## Running
``` After building, you can run the game by executing the `colysis` executable.
cd /path/to/flecs
bake
```
> Note: if this package is moved, you have to run `bake` again.
**5. Build the Template** ## License
This `colysis` is currently closed source and will not be open sourced. The engine will be licensed under the [MIT license](LICENSE) as soon as it is finished.
Now let's build the template.
Simply open a terminal and go to a location where you would like to put the template. I will put mine into "~/bake/src/bake/templates".
Once there, run these commands:
```bash
git clone https://github.com/aog05/Raylib-and-Flecs-Template
bake Raylib-and-Flecs-Template
```
**6. Create the Project**
Go to a folder where you like this project to be. I put mine in a folder called, _"Raylib Projects"_ and run this command.
```bash
bake new your_project_name -t RaFT
```
Run the program with: `bake run`.
If you ever want to make a new project, all you have to do is repeat step this step.
## Windows
Windows is a slightly tougher version to build for, so if there are any problems, you can report them here or on Discord.
**1. Install Git CLI**
If you haven't already download the GitHub CLI (Command Line Interface) run the command below.
```powershell
winget install --id Git.Git -e --source winget
```
> Note: this command only works on Windows 11. Go [here](https://git-scm.com/downloads/win) for previous versions.
**2. Install Visual Studio Build Tools**
First, follow this link ([Download Bulid Tools](https://visualstudio.microsoft.com/downloads/#build-tools-for-visual-studio-2022)) and go down to "Tools for Visual Studio" and click download on "Build Tools for Visual Studio" at the bottom of the selection.
Once it finishes downloading, open the Visual Studio Installer and click "Modify". After that, select "Desktop Development with C++" and click "Modify" in the bottom right. You can close the installer once it finishes installing.
**3. Install Bake**
Go to this link ([Bake Compiler](https://github.com/SanderMertens/bake)) and click "Code" and download the zip file.
Once downloaded, right-click the zip folder and click "Extract All...". open the folder. Open a new terminal, type `cd`, drag and drop the folder inside (should be called "bake-master") into the terminal window, and hit enter.
```powershell
# The command should look like this
cd C:\Users\your_username\Downloads\bake-master\bake-master
```
Run `./setup.bat` after that.
> Again, ensure it installed correctly with `bake --version`
**4. Raylib and Flecs libraries**
Download this zip file ([Raylib for x32](https://github.com/user-attachments/files/18310969/raylibdll.zip) or [Raylib for x64](https://github.com/user-attachments/files/18310976/raylibdll.zip)) and unzip it once it's downloaded.
Open "File Explorer" and go to C:\Users\*you*\bake\lib and put this raylib library in it.
Download the raylib source files by running,
```powershell
cd
git clone https://github.com/raysan5/raylib.git
```
Download this [flecs package](https://github.com/user-attachments/files/17963061/flecs.zip), unzip it, and run:
```
cd \path\to\flecs
bake
```
> Note: if this package is moved, you have to run `bake` again.
**5. Build the Template**
Now let's build the template.
Simply open a terminal and go to a location where you would like to put the template. I will put mine into "~/bake/src/bake/templates".
Once there, run these commands:
```powershell
git clone https://github.com/aog05/Raylib-and-Flecs-Template
bake Raylib-and-Flecs-Template
```
**6. Create the Project**
Go to a folder where you like this project to be. I put mine in a folder called, _"Raylib Projects"_ and run this command.
```powershell
bake new your_project_name -t RaFT
```
Run the program with: `bake run`.
If you ever want to make a new project, all you have to do is repeat this step.
## Build for Web
In your existing project, run these commands for your specific platform.
**For all platforms and languages**
```powershell
bake --target em
```
**Web MacOS and Linux**
Copy and paste this at the root of your project.
```bash
emcc -o bin/game.html .bake_cache/Em-debug/obj/main.o .bake_cache/Em-debug/obj/flecs.o -Wall -std=c99 -D_DEFAULT_SOURCE -Wno-missing-braces -Wunused-result --embed-file assets -Os -I ~/raylib/src -I ~/raylib/src/external -I include -I deps -s USE_GLFW=3 -s ASYNCIFY -s TOTAL_MEMORY=67108864 -s FORCE_FILESYSTEM=1 --shell-file ~/raylib/src/minshell.html ~/raylib/src/web/libraylib.a -DPLATFORM_WEB -s 'EXPORTED_FUNCTIONS=["_free","_malloc","_main"]' -s EXPORTED_RUNTIME_METHODS=ccall
```
**Web Windows**
Copy and paste this at the root of your project.
```powershell
emcc -o bin/game.html .bake_cache/Em-debug/obj/main.o .bake_cache/Em-debug/obj/flecs.o -Wall -std=c99 -D_DEFAULT_SOURCE -Wno-missing-braces -Wunused-result --embed-file assets -Os -I C:/raylib/src -I C:/raylib/src/external -I include -I deps -s USE_GLFW=3 -s ASYNCIFY -s TOTAL_MEMORY=67108864 -s FORCE_FILESYSTEM=1 --shell-file C:/raylib/src/minshell.html C:/raylib/src/web/libraylib.a -DPLATFORM_WEB -s 'EXPORTED_FUNCTIONS=["_free","_malloc","_main"]' -s EXPORTED_RUNTIME_METHODS=ccall
```
**Test on the Web**
This will produce an HTML file where you can run your game.
```bash
// If you have npm, use
npx http-server /path/to/game.html
// If you have python, use
// It may also be "py", "python3", or "py -3" depending on your OS
python -m http.server
```
By the way, if this is for itch.io, you have to take the HTML, JS, and WASM and compress them to a zip file. You can upload the zip file for web games on itch!
# ------ REFERENCES ------
Reference Articles:
Flecs Quickstart: https://www.flecs.dev/flecs/md_docs_2Quickstart.html
Raylib Examples: https://www.raylib.com/examples.html
Raylib CheatSheet: https://www.raylib.com/cheatsheet/cheatsheet.html
Bake Compiler: https://github.com/SanderMertens/bake

27
alyson/CMakeLists.txt Normal file
View file

@ -0,0 +1,27 @@
project(alyson
VERSION 0.0.1
LANGUAGES C CXX
)
cmake_minimum_required(VERSION 3.20)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)
include(../cmake/utils.cmake)
add_library(alyson)
target_include_directories(alyson PUBLIC includes)
target_link_libraries(alyson PUBLIC raylib)
target_link_libraries(alyson PUBLIC flecs::flecs_static)
target_compile_definitions(alyson PRIVATE ASSETS_PATH="${ASSETS_PATH}")
# Add alyson files
find_files(alyson_src src cpp hpp cxx hxx c h)
target_sources(alyson PRIVATE ${alyson_src})
# set(ALYSON_INCLUDE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/alyson/include)

View file

@ -0,0 +1,17 @@
#pragma once
#ifndef ALYSON_HPP
#define ALYSON_HPP
#ifndef ASSETS_PATH
#define ASSETS_PATH "./assets/"
#endif
#define MANGLE_RES_PATH(path) ASSETS_PATH "/" path
int init();
void update(float dt);
void render(float dt);
#endif // ALYSON_HPP

42
alyson/includes/rlyson.h Normal file
View file

@ -0,0 +1,42 @@
#ifndef RLYSON_HPP
#define RLYSON_HPP
#include <raylib.h>
/*
the following functions are not part of the raylib API,
but are used by alyson and can be used by other projects using alyson
*/
typedef enum {
TEXT_ORIENTATION_LEFT,
TEXT_ORIENTATION_RIGHT,
TEXT_ORIENTATION_CENTER
} text_orientation_t;
/*
* Draws a text with all possible parameters
* @function DrawTextFull
* @param font Font to use
* @param text Text to draw
* @param origin Position to draw the text from
* @param orientation Text orientation
* @param fontSize Font size
* @param spacing Spacing between letters
* @param lineSpacing Line spacing
* @param tint Tint of the text
*/
void DrawTextFull(
Font font,
const char *text,
Vector2 origin,
text_orientation_t orientation,
float fontSize,
float spacing,
float lineSpacing,
Color tint
);
#endif // RLYSON_HPP

43
alyson/src/alyson.cpp Normal file
View file

@ -0,0 +1,43 @@
#include <alyson.hpp>
#include <raylib.h>
#include <iostream>
#include <string>
#include <rlyson.h>
#define WINDOW_TITLE "Alyson Engine"
int main(int argc, char *argv[]) {
SetTargetFPS(60);
InitWindow(900, 500, WINDOW_TITLE " -- 900x500");
Texture2D logo = LoadTexture(MANGLE_RES_PATH("Raylib_logo.png"));
std::cout << "alyson: init" << std::endl;
int g = init();
if(g != 0) {
std::cout << "alyson: init failed with error code " << g << std::endl;
return g;
}
while (!WindowShouldClose()) {
if (IsWindowResized()) {
SetWindowTitle((std::string(WINDOW_TITLE) + " -- " + std::to_string(GetScreenWidth()) + "x" + std::to_string(GetScreenHeight())).c_str());
}
BeginDrawing();
DrawTexture(logo, GetScreenWidth() / 2 - logo.width / 2, GetScreenHeight() / 2 - logo.height / 2, WHITE);
DrawTextFull(GetFontDefault(), WINDOW_TITLE, { GetScreenWidth() / 2.f, GetScreenHeight() - 60.f }, TEXT_ORIENTATION_CENTER, 40.f, 0.f, 0.f, WHITE);
ClearBackground(RAYWHITE);
EndDrawing();
}
UnloadTexture(logo);
CloseWindow();
return 0;
}

28
alyson/src/rlyson.c Normal file
View file

@ -0,0 +1,28 @@
#include <rlyson.h>
void DrawTextFull(
Font font,
const char *text,
Vector2 origin,
text_orientation_t orientation,
float fontSize,
float spacing,
float lineSpacing,
Color tint
)
{
Vector2 textSize = MeasureTextEx(font, text, fontSize, spacing);
switch (orientation) {
case TEXT_ORIENTATION_LEFT:
origin.x -= textSize.x;
break;
case TEXT_ORIENTATION_RIGHT:
origin.x += textSize.x;
break;
case TEXT_ORIENTATION_CENTER:
origin.x -= textSize.x / 2;
break;
}
DrawTextPro(font, text, textSize, origin, 0, spacing, lineSpacing, tint);
}

33
cmake/utils.cmake Normal file
View file

@ -0,0 +1,33 @@
function(put_targets_into_folder)
set(oneValueArgs FOLDER)
set(multiValueArgs TARGETS)
cmake_parse_arguments(ARGS "" "${oneValueArgs}" "${multiValueArgs}" ${ARGN})
foreach(target ${ARGS_TARGETS})
# Check if target exists
if (NOT TARGET ${target})
message(FATAL_ERROR "${target} target not found")
endif()
# Get the actual target (if it is aliased)
get_target_property(actual_target ${target} ALIASED_TARGET)
if (NOT actual_target)
set(actual_target ${target})
endif()
# Set the folder property for the target
set_target_properties(${actual_target} PROPERTIES FOLDER ${ARGS_FOLDER})
endforeach()
endfunction()
function(find_files var_name path)
set(sources)
foreach(ext ${ARGN})
file(GLOB_RECURSE files "${path}/*.${ext}")
list(APPEND sources ${files})
endforeach()
set(${var_name} ${${var_name}} ${sources} PARENT_SCOPE)
endfunction()

43
deps/dependee.json vendored
View file

@ -1,43 +0,0 @@
{
"dependee": {
"lang.c": {
"${cfg sanitize}": {
"defines": [
"FLECS_SANITIZE"
]
}
},
"lang.cpp": {
"${cfg sanitize}": {
"defines": [
"FLECS_SANITIZE"
]
}
}
},
"lang.c": {
"${os linux}": {
"lib": [
"rt",
"pthread",
"m"
],
"${cfg debug}": {
"export-symbols": true
},
"${cfg sanitize}": {
"export-symbols": true
}
},
"${os windows}": {
"lib": [
"ws2_32"
]
},
"${cfg sanitize}": {
"defines": [
"FLECS_SANITIZE"
]
}
}
}

81507
deps/flecs.c vendored

File diff suppressed because it is too large Load diff

33512
deps/flecs.h vendored

File diff suppressed because it is too large Load diff

View file

@ -1,16 +1,12 @@
#ifndef COLYSIS_H #ifndef COLYSIS_H
#define COLYSIS_H #define COLYSIS_H
/* This generated file contains includes for project dependencies */
#include "colysis/bake_config.h"
#include "raylib.h"
#include "raymath.h"
#include "rlgl.h"
#ifdef __cplusplus #ifdef __cplusplus
extern "C" { extern "C" {
#endif #endif
#ifdef __cplusplus #ifdef __cplusplus
} }
#endif #endif

View file

@ -1,24 +0,0 @@
/*
)
(.)
.|.
| |
_.--| |--._
.-'; ;`-'& ; `&.
\ & ; & &_/
|"""---...---"""|
\ | | | | | | | /
`---.|.|.|.---'
* This file is generated by bake.lang.c for your convenience. Headers of
* dependencies will automatically show up in this file. Include bake_config.h
* in your main project file. Do not edit! */
#ifndef COLYSIS_BAKE_CONFIG_H
#define COLYSIS_BAKE_CONFIG_H
/* Headers of public dependencies */
#include "../../deps/flecs.h"
#endif

File diff suppressed because it is too large Load diff

File diff suppressed because it is too large Load diff

File diff suppressed because it is too large Load diff

View file

@ -1,80 +0,0 @@
{
"id": "colysis",
"type": "application",
"value": {
"author": "Sander Mertens and Raysan5",
"description": "A template including both Raylib and Flecs!",
"use": [
"flecs"
],
"standalone": true
},
"lang.c": {
"${os linux}": {
"lib": [
"rt",
"pthread",
"m",
"GL",
"X11",
"Xi",
"Xcursor",
"dl",
"raylib"
]
},
"${os windows}": {
"lib": [
"raylibdll.lib",
"ws2_32",
"gdi32",
"opengl32",
"winmm",
"kernel32"
],
"defines": [
"_WINDOWS",
"_USRDLL",
"CGLM_EXPORTS",
"CGLM_DLL"
]
},
"${cfg sanitize}": {
"defines": [
"FLECS_SANITIZE"
]
},
"${os darwin}": {
"lib": [
"raylib"
],
"ldflags": [
"-framework Cocoa",
"-framework CoreVideo",
"-framework IOKit",
"-framework GLUT",
"-framework OpenGL"
]
},
"${target em}": {
"libpath": [
"~\/raylib\/src"
],
"embed": [
"assets"
],
"ldflags": [
"-I ~\/raylib\/src",
"-I ~\/raylib\/src\/external",
"-s USE_GLFW=3",
"-s ASYNCIFY",
"-s TOTAL_MEMORY=67108864",
"-s FORCE_FILESYSTEM=1",
"-s EXPORTED_FUNCTIONS=['_free','_malloc','_main']",
"-s EXPORTED_RUNTIME_METHODS=ccall",
"--shell-file ~\/raylib\/src\/minshell.html ~\/raylib\/src\/web\/libraylib.a",
"-D PLATFORM_WEB"
]
}
}
}

View file

@ -1,27 +0,0 @@
#include <colysis.h>
int main(int argc, char *argv[]) {
SetTargetFPS(60);
InitWindow(900, 500, "Colysis");
ecs_world_t *world = ecs_init();
ecs_entity_t ray = ecs_entity(world, { .name = "raysan5" });
puts(ecs_get_name(world, ray));
Texture2D logo = LoadTexture("assets/Raylib_logo.png");
while (!WindowShouldClose()) {
BeginDrawing();
DrawTexture(logo, GetScreenWidth() / 2 - logo.width / 2, GetScreenHeight() / 2 - logo.height / 2, WHITE);
DrawText(ecs_get_name(world, ray), GetScreenWidth() / 2 - 25 * 3.5f, GetScreenHeight() - 50, 50, BLACK);
ClearBackground(RAYWHITE);
EndDrawing();
}
UnloadTexture(logo);
CloseWindow();
return ecs_fini(world);
}

16
src/main.cpp Normal file
View file

@ -0,0 +1,16 @@
#include <colysis.h>
#include <iostream>
#include <alyson.hpp>
int init() {
std::cout << "colysis: init" << std::endl;
return 0;
}
void update(float dt) {
}
void render(float dt) {
}