Compare commits
17 Commits
327a298383
...
lju/testin
| Author | SHA1 | Date | |
|---|---|---|---|
| f65d1099c2 | |||
| 110ff7ed7e | |||
| 0b70772009 | |||
| 2427601120 | |||
| c747dab1fc | |||
| 4c33da0ecd | |||
| f0284e7975 | |||
| 8f62ee83a6 | |||
| d16319084b | |||
| 46c9bee008 | |||
| 1594e663eb | |||
| c35097b3d3 | |||
| 384c811a29 | |||
| a4c9774c28 | |||
| 3e7e7e2547 | |||
| 5c9b60163a | |||
| 6f5ec1d811 |
28
.gitea/workflows/test.yml
Normal file
28
.gitea/workflows/test.yml
Normal file
@@ -0,0 +1,28 @@
|
||||
name: Gol CI
|
||||
|
||||
# Run on the merge of a pull request to the main branch
|
||||
on:
|
||||
pull_request:
|
||||
branches: [main]
|
||||
push:
|
||||
branches: [main]
|
||||
|
||||
jobs:
|
||||
build:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v2
|
||||
- name: Install dependencies
|
||||
run: |
|
||||
sudo apt-get update
|
||||
sudo apt-get install -y cmake libxrandr-dev libxinerama-dev libxcursor-dev libxi-dev libgl1-mesa-dev
|
||||
- name: Build and test
|
||||
run: |
|
||||
mkdir build
|
||||
cd build
|
||||
cmake ..
|
||||
make
|
||||
- uses: actions/upload-artifact@v2
|
||||
with:
|
||||
name: gol-linux-build
|
||||
path: /workspace/lejulien/GameOfLifeEditor/build/GameOfLifeEditor
|
||||
2
.gitignore
vendored
2
.gitignore
vendored
@@ -1,4 +1,6 @@
|
||||
build
|
||||
build_linux
|
||||
build_win
|
||||
enc_temp_folder
|
||||
out
|
||||
_deps
|
||||
|
||||
@@ -8,7 +8,8 @@ set(CMAKE_CXX_EXTENSIONS OFF)
|
||||
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
|
||||
|
||||
if(WIN32)
|
||||
set(IMGUI_BACKEND "imgui_impl_dx11.cpp") # DirectX 11 for Windows
|
||||
#set(IMGUI_BACKEND "imgui_impl_dx11.cpp") # DirectX 11 for Windows
|
||||
set(IMGUI_BACKEND "imgui_impl_opengl3.cpp") # OpenGL for Linux
|
||||
elseif(APPLE)
|
||||
set(IMGUI_BACKEND "imgui_impl_metal.mm") # Metal for macOS
|
||||
elseif(UNIX)
|
||||
@@ -69,12 +70,15 @@ include_directories(${imgui_SOURCE_DIR} ${rlImGui_SOURCE_DIR})
|
||||
set(SRC_CXX_FILES "./src/main.cpp"
|
||||
"./src/rules.cpp"
|
||||
"./src/world.cpp"
|
||||
"./src/grid.cpp"
|
||||
"./src/render.cpp"
|
||||
"./src/control_menu.cpp"
|
||||
"./src/settings_menu.cpp"
|
||||
"./src/selection_menu.cpp"
|
||||
"./src/selection.cpp"
|
||||
"./src/paterns_menu.cpp"
|
||||
"./src/patern_preview.cpp"
|
||||
"./src/snapping.cpp"
|
||||
"${rlImGui_SOURCE_DIR}/rlImGui.cpp"
|
||||
"${imgui_SOURCE_DIR}/imgui.cpp"
|
||||
"${imgui_SOURCE_DIR}/imgui_draw.cpp"
|
||||
@@ -88,3 +92,25 @@ add_executable(${NAME} ${SRC_CXX_FILES})
|
||||
|
||||
# Link raylib and raylib-cpp
|
||||
target_link_libraries(${NAME} PUBLIC raylib nlohmann_json::nlohmann_json)
|
||||
|
||||
# Windows cross-compilation rule
|
||||
|
||||
if (NOT DEFINED CMAKE_CROSSCOMPILE_WINDOWS_HELPER_ADDED)
|
||||
set(CMAKE_CROSSCOMPILE_WINDOWS_HELPER_ADDED TRUE)
|
||||
|
||||
set(WIN_TOOLCHAIN_FILE "${CMAKE_SOURCE_DIR}/toolchain-mingw-w64-x86_64.cmake" CACHE PATH "Toolchain for Win x86_64")
|
||||
|
||||
add_custom_target(cmake-win
|
||||
COMMAND ${CMAKE_COMMAND} -E echo "Configuring Windows x86_64 build in: ${CMAKE_SOURCE_DIR}/build-win-x86_64"
|
||||
COMMAND ${CMAKE_COMMAND}
|
||||
-S ${CMAKE_SOURCE_DIR}
|
||||
-B ${CMAKE_SOURCE_DIR}/build-win-x86_64
|
||||
-G "Ninja"
|
||||
-DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE}
|
||||
-DCMAKE_TOOLCHAIN_FILE=${WIN_TOOLCHAIN_FILE}
|
||||
COMMAND ${CMAKE_COMMAND} --build ${CMAKE_SOURCE_DIR}/build-win-x86_64 -- -v
|
||||
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
|
||||
COMMENT "Configure & build for Windows x86_64 (MinGW-w64)"
|
||||
VERBATIM
|
||||
)
|
||||
endif()
|
||||
|
||||
25
README.md
25
README.md
@@ -2,11 +2,17 @@
|
||||
|
||||
This is a simple Game Of Life editor written in C++ with raylib & dearImGUI
|
||||
|
||||
***
|
||||
---
|
||||
|
||||

|
||||
|
||||
---
|
||||
|
||||
## How to compile the project
|
||||
|
||||
Ensure you have g++, cmake and the thendependencies of raylib
|
||||
### Linux
|
||||
|
||||
Ensure you have g++, cmake and the dependencies of raylib
|
||||
|
||||
```shell
|
||||
mkdir build
|
||||
@@ -15,4 +21,17 @@ cmake ..
|
||||
make
|
||||
```
|
||||
|
||||
> As for now I will not make this program Windows compatible.
|
||||
### Windows
|
||||
|
||||
If you're compiling for windows on linux, you can use mingw-w64
|
||||
|
||||
```shell
|
||||
sudo apt install mingw-w64
|
||||
mkdir build
|
||||
cd build
|
||||
cmake .. -DCMAKE_TOOLCHAIN_FILE=../toolchain-ming-w64-x86_64.cmake
|
||||
make
|
||||
```
|
||||
If you're compiling for windows on windows, use your usual cmake workflow
|
||||
|
||||
|
||||
|
||||
@@ -22,6 +22,7 @@ class SelectionMenu;
|
||||
class ControlMenu;
|
||||
class Selection;
|
||||
class PaternsMenu;
|
||||
class PaternPreview;
|
||||
|
||||
typedef struct ctx {
|
||||
std::shared_ptr<World> world = nullptr;
|
||||
@@ -32,6 +33,7 @@ typedef struct ctx {
|
||||
std::shared_ptr<ControlMenu> control_menu = nullptr;
|
||||
std::shared_ptr<Selection> selection = nullptr;
|
||||
std::shared_ptr<PaternsMenu> paterns_menu = nullptr;
|
||||
std::shared_ptr<PaternPreview> patern_preview = nullptr;
|
||||
nlohmann::json config_json;
|
||||
std::filesystem::path program_dir;
|
||||
} ctx;
|
||||
|
||||
28
includes/grid.hpp
Normal file
28
includes/grid.hpp
Normal file
@@ -0,0 +1,28 @@
|
||||
/*
|
||||
* File name: grid.hpp
|
||||
* Author: lejulien
|
||||
* Date created: 01-01-1970 00:59:59
|
||||
// Date modified: 12-01-2026 21:30:10
|
||||
* ------
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <context.hpp>
|
||||
#include <memory>
|
||||
#include <settings_menu.hpp>
|
||||
#include <world.hpp>
|
||||
|
||||
namespace gol {
|
||||
|
||||
class Grid {
|
||||
public:
|
||||
Grid(std::shared_ptr<ctx>);
|
||||
~Grid() = default;
|
||||
void display();
|
||||
|
||||
private:
|
||||
std::shared_ptr<ctx> context_;
|
||||
};
|
||||
|
||||
}; // namespace gol
|
||||
33
includes/patern_preview.hpp
Normal file
33
includes/patern_preview.hpp
Normal file
@@ -0,0 +1,33 @@
|
||||
/*
|
||||
* File name: patern_preview.hpp
|
||||
* Author: lejulien
|
||||
* Date created: 01-01-1970 00:59:59
|
||||
// Date modified: 12-01-2026 21:30:10
|
||||
* ------
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <memory>
|
||||
|
||||
#include <raylib.h>
|
||||
|
||||
#include <context.hpp>
|
||||
|
||||
namespace gol {
|
||||
|
||||
class PaternPreview {
|
||||
public:
|
||||
PaternPreview(std::shared_ptr<ctx>);
|
||||
~PaternPreview() = default;
|
||||
void update();
|
||||
void display();
|
||||
void start();
|
||||
private:
|
||||
bool is_started = false;
|
||||
std::shared_ptr<ctx> context_;
|
||||
Vector2 mouse_pos_ = {0, 0};
|
||||
bool is_unplacable_ = false;
|
||||
};
|
||||
|
||||
} // namespace gol
|
||||
@@ -30,6 +30,7 @@ private:
|
||||
std::shared_ptr<ctx> context_ = nullptr;
|
||||
std::map<std::string,std::string> paterns_paths_list_;
|
||||
std::vector<std::string> paterns_name_list_;
|
||||
public:
|
||||
int patern_width_ = 0;
|
||||
int patern_height_ = 0;
|
||||
std::vector<uint32_t> loaded_patern_;
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* File name: selection.cpp
|
||||
* File name: snapping.hpp
|
||||
* Author: lejulien
|
||||
* Date created: 01-01-1970 00:59:59
|
||||
// Date modified: 12-01-2026 21:30:10
|
||||
@@ -13,12 +13,6 @@
|
||||
#include <raylib.h>
|
||||
#include <cmath>
|
||||
|
||||
Vector2 snapToGrid(Vector2 screen, int cell_size) {
|
||||
return {static_cast<float>(round(screen.x / cell_size) * cell_size),
|
||||
static_cast<float>(round(screen.y / cell_size) * cell_size)};
|
||||
}
|
||||
Vector2 snapToGrid(Vector2 screen, int cell_size);
|
||||
|
||||
Vector2i screenToGrid(Vector2 screen, int cell_size) {
|
||||
return {static_cast<int>(round(screen.x / cell_size)),
|
||||
static_cast<int>(round(screen.y / cell_size))};
|
||||
}
|
||||
Vector2i screenToGrid(Vector2 screen, int cell_size);
|
||||
|
||||
@@ -37,6 +37,7 @@ public:
|
||||
void setCell(int x, int y);
|
||||
void resize(int width, int height); // destructive
|
||||
std::vector<uint32_t> getSelection(Vector2i &origin, Vector2i &size);
|
||||
void setSelection(Vector2i &origin, Vector2i &size, std::vector<uint32_t> &data);
|
||||
|
||||
// Private members
|
||||
private:
|
||||
|
||||
BIN
preview.png
Normal file
BIN
preview.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 29 KiB |
27
src/grid.cpp
Normal file
27
src/grid.cpp
Normal file
@@ -0,0 +1,27 @@
|
||||
/*
|
||||
* File name: grid.cpp
|
||||
* Author: lejulien
|
||||
* Date created: 01-01-1970 00:59:59
|
||||
// Date modified: 12-01-2026 21:30:10
|
||||
* ------
|
||||
*/
|
||||
|
||||
#include <raylib.h>
|
||||
|
||||
#include <grid.hpp>
|
||||
|
||||
namespace gol {
|
||||
|
||||
Grid::Grid(std::shared_ptr<ctx> context) : context_(context) {}
|
||||
|
||||
void Grid::display() {
|
||||
auto cell_size = context_->settings_menu->getCellSize();
|
||||
for (int j = 0; j < context_->world->getHeight(); j++) {
|
||||
for (int i = 0; i < context_->world->getWidth(); i++) {
|
||||
DrawRectangleLines(i * cell_size, j * cell_size, cell_size, cell_size,
|
||||
GRAY);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace gol
|
||||
104
src/main.cpp
104
src/main.cpp
@@ -6,11 +6,84 @@
|
||||
* ------
|
||||
*/
|
||||
|
||||
#if defined(_WIN32)
|
||||
// Prevent windows.h from defining many symbols that clash with raylib
|
||||
#define NOGDICAPMASKS
|
||||
#define NOVIRTUALKEYCODES
|
||||
#define NOWINMESSAGES
|
||||
#define NOWINSTYLES
|
||||
#define NOSYSMETRICS
|
||||
#define NOMENUS
|
||||
#define NOICONS
|
||||
#define NOKEYSTATES
|
||||
#define NOSYSCOMMANDS
|
||||
#define NORASTEROPS
|
||||
#define NOSHOWWINDOW
|
||||
#define OEMRESOURCE
|
||||
#define NOATOM
|
||||
#define NOCLIPBOARD
|
||||
#define NOCOLOR
|
||||
#define NOCTLMGR
|
||||
#define NODRAWTEXT
|
||||
#define NOGDI
|
||||
#define NOKERNEL
|
||||
#define NOUSER
|
||||
#define NOMB
|
||||
#define NOMEMMGR
|
||||
#define NOMETAFILE
|
||||
#define NOMINMAX
|
||||
#define NOMSG
|
||||
#define NOOPENFILE
|
||||
#define NOSCROLL
|
||||
#define NOSERVICE
|
||||
#define NOSOUND
|
||||
#define NOTEXTMETRIC
|
||||
#define NOWH
|
||||
#define NOWINOFFSETS
|
||||
#define NOCOMM
|
||||
#define NOKANJI
|
||||
#define NOHELP
|
||||
#define NOPROFILER
|
||||
#define NODEFERWINDOWPOS
|
||||
#define NOMCX
|
||||
|
||||
// Some code expects LPMSG; provide minimal typedef before windows.h
|
||||
typedef struct tagMSG *LPMSG;
|
||||
|
||||
#include <windows.h>
|
||||
|
||||
#undef PlaySound
|
||||
// Define a minimal BITMAPINFOHEADER if needed by downstream code
|
||||
typedef struct tagBITMAPINFOHEADER {
|
||||
DWORD biSize;
|
||||
LONG biWidth;
|
||||
LONG biHeight;
|
||||
WORD biPlanes;
|
||||
WORD biBitCount;
|
||||
DWORD biCompression;
|
||||
DWORD biSizeImage;
|
||||
LONG biXPelsPerMeter;
|
||||
LONG biYPelsPerMeter;
|
||||
DWORD biClrUsed;
|
||||
DWORD biClrImportant;
|
||||
} BITMAPINFOHEADER, *PBITMAPINFOHEADER;
|
||||
|
||||
#include <objbase.h>
|
||||
#include <mmreg.h>
|
||||
#include <mmsystem.h>
|
||||
|
||||
#if defined(_MSC_VER) || defined(__TINYC__)
|
||||
#include "propidl.h"
|
||||
#endif
|
||||
|
||||
#else
|
||||
#include <unistd.h>
|
||||
#endif
|
||||
|
||||
#include <fstream>
|
||||
#include <iostream>
|
||||
#include <unistd.h>
|
||||
#include <nlohmann/json.hpp>
|
||||
|
||||
#include <nlohmann/json.hpp>
|
||||
#include <imgui.h>
|
||||
#include <raylib.h>
|
||||
#include <rlImGui.h>
|
||||
@@ -25,6 +98,8 @@
|
||||
#include <selection_menu.hpp>
|
||||
#include <selection.hpp>
|
||||
#include <paterns_menu.hpp>
|
||||
#include <patern_preview.hpp>
|
||||
#include <grid.hpp>
|
||||
|
||||
int main(int ac, char **av) {
|
||||
std::shared_ptr<gol::ctx> context = std::make_shared<gol::ctx>();
|
||||
@@ -84,11 +159,31 @@ int main(int ac, char **av) {
|
||||
|
||||
// Get program directory
|
||||
char path_buf[1024];
|
||||
#if defined(_WIN32)
|
||||
std::wstring wbuf;
|
||||
DWORD size = MAX_PATH;
|
||||
for (;;) {
|
||||
wbuf.resize(size);
|
||||
DWORD result = GetModuleFileNameW(NULL, wbuf.data(), size);
|
||||
if (result == 0) {
|
||||
std::cerr << "Failed to determine program directory" << std::endl;
|
||||
return 1;
|
||||
}
|
||||
if (result < size) {
|
||||
wbuf.resize(result);
|
||||
break;
|
||||
}
|
||||
size *= 2;
|
||||
}
|
||||
path_buf[0] = '\0';
|
||||
WideCharToMultiByte(CP_UTF8, 0, wbuf.c_str(), -1, path_buf, sizeof(path_buf), NULL, NULL);
|
||||
#else
|
||||
ssize_t len = readlink("/proc/self/exe", path_buf, sizeof(path_buf)-1);
|
||||
if (len == -1) {
|
||||
std::cerr << "Failed to determine program directory" << std::endl;
|
||||
return 1;
|
||||
}
|
||||
#endif
|
||||
context->program_dir = std::filesystem::path(path_buf).parent_path();
|
||||
|
||||
InitWindow(context->config_json["screen_width"], context->config_json["screen_height"],
|
||||
@@ -107,6 +202,8 @@ int main(int ac, char **av) {
|
||||
context->selection_menu = std::make_shared<gol::SelectionMenu>(context);
|
||||
context->selection = std::make_shared<gol::Selection>(context);
|
||||
context->paterns_menu = std::make_shared<gol::PaternsMenu>(context);
|
||||
context->patern_preview = std::make_shared<gol::PaternPreview>(context);
|
||||
gol::Grid grid(context);
|
||||
|
||||
// Speed handling values
|
||||
float sim_speed = 1.0f;
|
||||
@@ -136,6 +233,7 @@ int main(int ac, char **av) {
|
||||
|
||||
// Selection behaviour
|
||||
context->selection->update();
|
||||
context->patern_preview->update();
|
||||
context->selection_menu->update();
|
||||
context->settings_menu->update();
|
||||
|
||||
@@ -152,8 +250,10 @@ int main(int ac, char **av) {
|
||||
}
|
||||
BeginDrawing();
|
||||
ClearBackground(BLACK);
|
||||
grid.display();
|
||||
context->render->display(context->world);
|
||||
context->selection->display();
|
||||
context->patern_preview->display();
|
||||
// Start ImGui frame
|
||||
rlImGuiBegin();
|
||||
context->control_menu->display();
|
||||
|
||||
69
src/patern_preview.cpp
Normal file
69
src/patern_preview.cpp
Normal file
@@ -0,0 +1,69 @@
|
||||
/*
|
||||
* File name: patern_preview.cpp
|
||||
* Author: lejulien
|
||||
* Date created: 01-01-1970 00:59:59
|
||||
// Date modified: 12-01-2026 21:30:10
|
||||
* ------
|
||||
*/
|
||||
|
||||
#include <imgui.h>
|
||||
#include <raylib.h>
|
||||
#include <rlImGui.h>
|
||||
|
||||
#include <patern_preview.hpp>
|
||||
#include <paterns_menu.hpp>
|
||||
#include <settings_menu.hpp>
|
||||
#include <snapping.hpp>
|
||||
#include <world.hpp>
|
||||
|
||||
namespace gol {
|
||||
|
||||
PaternPreview::PaternPreview(std::shared_ptr<ctx> context)
|
||||
: context_(context) {}
|
||||
|
||||
void PaternPreview::start() { is_started = true; }
|
||||
|
||||
void PaternPreview::update() {
|
||||
if (!is_started) return;
|
||||
mouse_pos_ = GetMousePosition();
|
||||
if (ImGui::IsMouseClicked(1)) {
|
||||
is_started = false;
|
||||
return;
|
||||
}
|
||||
if (ImGui::IsMouseClicked(0) && !is_unplacable_) {
|
||||
auto selection_pos =
|
||||
screenToGrid(mouse_pos_, context_->settings_menu->getCellSize());
|
||||
Vector2i size = {context_->paterns_menu->patern_width_,
|
||||
context_->paterns_menu->patern_height_};
|
||||
context_->world->setSelection(selection_pos, size,
|
||||
context_->paterns_menu->loaded_patern_);
|
||||
is_started = false;
|
||||
}
|
||||
// mouse should pass through any present windows
|
||||
}
|
||||
|
||||
void PaternPreview::display() {
|
||||
if (!is_started) return;
|
||||
auto cell_size = context_->settings_menu->getCellSize();
|
||||
auto mouse_in_grid =
|
||||
screenToGrid(mouse_pos_, context_->settings_menu->getCellSize());
|
||||
is_unplacable_ =
|
||||
((mouse_in_grid.x + context_->paterns_menu->patern_width_ >
|
||||
context_->world->getWidth()) ||
|
||||
(mouse_in_grid.y + context_->paterns_menu->patern_height_ >
|
||||
context_->world->getHeight()));
|
||||
for (int j = 0; j < context_->paterns_menu->patern_height_; j++) {
|
||||
for (int i = 0; i < context_->paterns_menu->patern_width_; i++) {
|
||||
auto cell =
|
||||
context_->paterns_menu
|
||||
->loaded_patern_[i + (j * context_->paterns_menu->patern_width_)];
|
||||
if (cell) {
|
||||
DrawRectangle((i + mouse_in_grid.x) * cell_size,
|
||||
(j + mouse_in_grid.y) * cell_size, cell_size, cell_size,
|
||||
(is_unplacable_) ? RED : BLUE);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}; // namespace gol
|
||||
@@ -14,6 +14,7 @@
|
||||
#include <fstream>
|
||||
#include <iostream>
|
||||
#include <paterns_menu.hpp>
|
||||
#include <patern_preview.hpp>
|
||||
#include <sstream>
|
||||
|
||||
namespace gol {
|
||||
@@ -34,8 +35,14 @@ void PaternsMenu::refresh() {
|
||||
std::filesystem::directory_iterator(paterns_path)) {
|
||||
if (!std::filesystem::is_directory(entry) &&
|
||||
entry.path().has_filename()) {
|
||||
#if defined(_WIN32)
|
||||
paterns_paths_list_[entry.path().filename().string()] =
|
||||
entry.path().string();
|
||||
paterns_name_list_.push_back(entry.path().filename().string());
|
||||
#else
|
||||
paterns_paths_list_[entry.path().filename()] = entry.path();
|
||||
paterns_name_list_.push_back(entry.path().filename());
|
||||
#endif
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -63,7 +70,7 @@ bool PaternsMenu::loadPatern(std::string &path) {
|
||||
}
|
||||
} catch (std::exception &e) {
|
||||
std::cerr << "Failure in loading patern : " << path << std::endl;
|
||||
return 1;
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
@@ -78,8 +85,7 @@ void PaternsMenu::display() {
|
||||
ImGui::PushID(patern_name.c_str());
|
||||
if (ImGui::Button(patern_name.c_str()) &&
|
||||
loadPatern(paterns_paths_list_[patern_name])) {
|
||||
// TODO: If patern is loaded successfuly, start the preview in the
|
||||
// editor
|
||||
context_->patern_preview->start();
|
||||
}
|
||||
ImGui::PopID();
|
||||
ImGui::SameLine(ImGui::GetWindowWidth() - 57.);
|
||||
|
||||
19
src/snapping.cpp
Normal file
19
src/snapping.cpp
Normal file
@@ -0,0 +1,19 @@
|
||||
/*
|
||||
* File name: snapping.hpp
|
||||
* Author: lejulien
|
||||
* Date created: 01-01-1970 00:59:59
|
||||
// Date modified: 12-01-2026 21:30:10
|
||||
* ------
|
||||
*/
|
||||
|
||||
#include <snapping.hpp>
|
||||
|
||||
Vector2 snapToGrid(Vector2 screen, int cell_size) {
|
||||
return {static_cast<float>(round(screen.x / cell_size) * cell_size),
|
||||
static_cast<float>(round(screen.y / cell_size) * cell_size)};
|
||||
}
|
||||
|
||||
Vector2i screenToGrid(Vector2 screen, int cell_size) {
|
||||
return {static_cast<int>(round(screen.x / cell_size)),
|
||||
static_cast<int>(round(screen.y / cell_size))};
|
||||
}
|
||||
@@ -143,7 +143,6 @@ void World::resize(int width, int height) {
|
||||
}
|
||||
|
||||
std::vector<uint32_t> World::getSelection(Vector2i &origin, Vector2i &size) {
|
||||
// We assume the selection is in the grid for now
|
||||
std::vector<uint32_t> data = {static_cast<uint32_t>(size.x),
|
||||
static_cast<uint32_t>(size.y)};
|
||||
for (int y = origin.y; y < origin.y + size.y; y++) {
|
||||
@@ -153,3 +152,12 @@ std::vector<uint32_t> World::getSelection(Vector2i &origin, Vector2i &size) {
|
||||
}
|
||||
return data;
|
||||
}
|
||||
|
||||
void World::setSelection(Vector2i &origin, Vector2i &size, std::vector<uint32_t> &data) {
|
||||
|
||||
for (int y = 0; y < size.y; y++) {
|
||||
for (int x = 0; x < size.x; x++) {
|
||||
(*_data)[(x + origin.x) + (y + origin.y) * _width] = data[x + y * size.x];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
21
toolchain-mingw-w64-x86_64.cmake
Normal file
21
toolchain-mingw-w64-x86_64.cmake
Normal file
@@ -0,0 +1,21 @@
|
||||
set(CMAKE_SYSTEM_NAME Windows)
|
||||
set(CMAKE_SYSTEM_VERSION 1)
|
||||
set(CMAKE_CROSSCOMPILING TRUE)
|
||||
|
||||
set(MINGW_TRIPLET "x86_64-w64-mingw32")
|
||||
|
||||
set(CMAKE_C_COMPILER ${MINGW_TRIPLET}-gcc)
|
||||
set(CMAKE_CXX_COMPILER ${MINGW_TRIPLET}-g++)
|
||||
set(CMAKE_RC_COMPILER ${MINGW_TRIPLET}-windres)
|
||||
set(CMAKE_AR ${MINGW_TRIPLET}-ar)
|
||||
set(CMAKE_RANLIB ${MINGW_TRIPLET}-ranlib)
|
||||
set(CMAKE_OBJCOPY ${MINGW_TRIPLET}-objcopy)
|
||||
|
||||
set(CMAKE_FIND_ROOT_PATH /usr/${MINGW_TRIPLET})
|
||||
set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
|
||||
set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
|
||||
set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)
|
||||
|
||||
set(CMAKE_C_FLAGS_INIT "-static -static-libgcc -static-libstdc++")
|
||||
set(CMAKE_CXX_FLAGS_INIT "-static -static-libgcc -static-libstdc++")
|
||||
|
||||
Reference in New Issue
Block a user