Skip to content

Commit

Permalink
Release 0.4.0
Browse files Browse the repository at this point in the history
* add support for C++
* update docs
* add A* example written in C++
* CI adaptions
  • Loading branch information
bernhardfritz committed Jul 11, 2022
1 parent 634879e commit b9f3f6f
Show file tree
Hide file tree
Showing 23 changed files with 9,730 additions and 12 deletions.
48 changes: 45 additions & 3 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,21 +7,62 @@ jobs:
matrix:
include:
- os: macos-latest
DIR: c++
USE_MINGW: 0
MINGW_CC: null
USE_EMSCRIPTEN: 0
TARGET: c++/build/libp8g++.dylib
- os: ubuntu-latest
DIR: c++
USE_MINGW: 0
MINGW_CC: null
USE_EMSCRIPTEN: 0
TARGET: c++/build/libp8g++.so
- os: ubuntu-latest
DIR: c++
USE_MINGW: 1
MINGW_CC: x86_64-w64-mingw32-g++
USE_EMSCRIPTEN: 0
TARGET: c++/build/p8g++.dll
- os: ubuntu-latest
DIR: c++
USE_MINGW: 0
MINGW_CC: null
USE_EMSCRIPTEN: 1
TARGET: c++/build/p8g++.wasm
- os: macos-latest
DIR: java
USE_MINGW: 0
MINGW_CC: null
USE_EMSCRIPTEN: 0
TARGET: java/build/libio_github_bernhardfritz_p8g_Sketch.dylib
- os: ubuntu-latest
DIR: java
USE_MINGW: 0
MINGW_CC: null
USE_EMSCRIPTEN: 0
TARGET: java/build/libio_github_bernhardfritz_p8g_Sketch.so
- os: ubuntu-latest
DIR: java
USE_MINGW: 1
MINGW_CC: x86_64-w64-mingw32-gcc
USE_EMSCRIPTEN: 0
TARGET: java/build/io_github_bernhardfritz_p8g_Sketch.dll
steps:
- uses: actions/checkout@v2
- run: |
cd java
cd ${{ matrix.DIR }}
if [ "${{ matrix.USE_MINGW }}" = 1 ]; then
sudo apt-get install -y mingw-w64
make CC=x86_64-w64-mingw32-gcc OS=Windows_NT JNI_MD_DIR=${JAVA_HOME}/include/linux
make CC=${{ matrix.MINGW_CC }} OS=Windows_NT JNI_MD_DIR=${JAVA_HOME}/include/linux
elif [ "${{ matrix.USE_EMSCRIPTEN }}" = 1 ]; then
git clone https://github.com/emscripten-core/emsdk.git
cd emsdk
./emsdk install latest
./emsdk activate latest
source ./emsdk_env.sh
cd ..
emmake make
else
make
fi
Expand All @@ -37,12 +78,13 @@ jobs:
- uses: actions/checkout@v2
- uses: actions/download-artifact@v3
- run: |
mv build/libp8g++.dylib build/libp8g++.so build/p8g++.dll build/p8g++.wasm c++
mv build java
cd java
make build/p8g.jar
rm -rf build/io
rm -f build/io_github_bernhardfritz_p8g_Sketch.dll build/libio_github_bernhardfritz_p8g_Sketch.dylib build/libio_github_bernhardfritz_p8g_Sketch.so
zip -jr p8g.zip build ../c/p8g.h ../c/p8g.html ../c/p8g.wasm
zip -jr p8g.zip build ../c/p8g.h ../c/p8g.html ../c/p8g.wasm ../c++/libp8g++.dylib ../c++/libp8g++.so ../c++/p8g++.dll ../c++/p8g++.wasm ../c++/p8g.hpp
- uses: softprops/action-gh-release@v1
if: startsWith(github.ref, 'refs/tags/')
with:
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

| Beginner friendly | Language-agnostic | Cross-platform |
| :--------------------------------------------------------------------------------------------------------------: | :--------------------------------------------------------------------------------------: | :----------------------------------------------------------------------------------------------------------------: |
| p8g has been developed for individuals interested in getting into creative programming no matter the experience. | p8g is available for both C and Java allowing further language bindings to be developed. | p8g applications can be developed on and built for all major operating systems including Windows, Linux and macOS as well as the web. |
| p8g has been developed for individuals interested in getting into creative programming no matter the experience. | p8g is available for C, C++ and Java allowing further language bindings to be developed. | p8g applications can be developed on and built for all major operating systems including Windows, Linux and macOS as well as the web. |

## Links

Expand Down
48 changes: 48 additions & 0 deletions c++/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
ifeq ($(origin CC),default)
CC = g++
endif
MKDIR_P ?= mkdir -p
P8G_DIR := ../c
SRC_DIR := .
_SRCS := p8g.cpp
SRCS := $(_SRCS:%=$(SRC_DIR)/%)
BUILD_DIR := build
_OBJS := $(_SRCS:%.cpp=%.o)
OBJS := $(_SRCS:%.cpp=$(BUILD_DIR)/%.o)
ifeq ($(OS),Windows_NT)
UNAME_S := Windows
else
UNAME_S := $(shell uname -s)
endif
ifeq ($(UNAME_S),Windows)
TARGET := p8g++.dll
FLAGS := -lp8g
endif
ifeq ($(UNAME_S),Linux)
TARGET := libp8g++.so
FLAGS := -lp8g -Wl,-rpath='$$ORIGIN'
endif
ifeq ($(UNAME_S),Darwin)
TARGET := libp8g++.dylib
FLAGS := -lp8g -install_name @rpath/$(TARGET)
endif
ifdef EMSCRIPTEN
TARGET := p8g++.wasm
FLAGS := ../c/p8g.wasm
endif

$(BUILD_DIR)/%.o: $(SRC_DIR)/%.cpp
$(CC) -std=c++11 -c -fPIC $< -o $@ -I$(P8G_DIR)

all: $(OBJS)
$(CC) $(if $(EMSCRIPTEN),-s SIDE_MODULE,-shared) -o $(BUILD_DIR)/$(TARGET) $< -L$(P8G_DIR) $(FLAGS)

$(OBJS): | $(BUILD_DIR)

$(BUILD_DIR):
$(MKDIR_P) $(BUILD_DIR)

.PHONY: clean

clean:
$(RM) -r $(BUILD_DIR)
254 changes: 254 additions & 0 deletions c++/p8g.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,254 @@
#include "p8g.hpp"

namespace {
int colorMode;
void draw(float deltaTime) {
p8g::deltaTime = deltaTime * 1000.f;
p8g::draw();
}
void keyPressed(int keyCode) {
p8g::keyCode = keyCode;
p8g::keyIsPressed = true;
p8g::keyPressed();
}
void keyReleased(int keyCode) {
p8g::keyCode = keyCode;
p8g::keyIsPressed = false;
p8g::keyReleased();
}
void mouseMoved(float mouseX, float mouseY) {
p8g::mouseX = mouseX;
p8g::mouseY = mouseY;
p8g::mouseMoved();
}
void mousePressed(int mouseButton) {
p8g::mouseButton = mouseButton;
p8g::mouseIsPressed = true;
p8g::mousePressed();
}
void mouseReleased(int mouseButton) {
p8g::mouseButton = mouseButton;
p8g::mouseIsPressed = false;
p8g::mouseReleased();
}
void mouseWheel(float deltaX, float deltaY) {
p8g::mouseWheel(deltaY);
}
}

int p8g::width, p8g::height;
int p8g::keyCode;
bool p8g::keyIsPressed;
float p8g::mouseX, p8g::mouseY;
int p8g::mouseButton;
bool p8g::mouseIsPressed;
float p8g::deltaTime;

void p8g::draw() {}
void p8g::keyPressed() {}
void p8g::keyReleased() {}
void p8g::mouseMoved() {}
void p8g::mousePressed() {}
void p8g::mouseReleased() {}
void p8g::mouseWheel(float delta) {}

void p8g::applyMatrix(float a, float b, float c, float d, float e, float f) {
p8g_apply_matrix(a, b, c, d, e, f);
}

void p8g::background(float gray) {
float background[] = { gray, gray, gray, ::colorMode == p8g::RGB ? 255.f : 1.f };
p8g_background(background);
}

void p8g::background(float gray, float alpha) {
float background[] = { gray, gray, gray, alpha };
p8g_background(background);
}

void p8g::background(float v1, float v2, float v3) {
float background[] = { v1, v2, v3, ::colorMode == p8g::RGB ? 255.f : 1.f };
p8g_background(background);
}

void p8g::background(float v1, float v2, float v3, float alpha) {
float background[] = { v1, v2, v3, alpha };
p8g_background(background);
}

void p8g::background(float color[4]) {
p8g_background(color);
}

void p8g::colorMode(int mode) {
p8g_color_mode((p8g_color_mode_t) mode);
}

void p8g::ellipse(float x, float y, float w, float h) {
p8g_ellipse(x, y, w, h);
}

void p8g::ellipseMode(int mode) {
p8g_ellipse_mode((p8g_ellipse_mode_t) mode);
}

void p8g::fill(float gray) {
float fill[] = { gray, gray, gray, ::colorMode == p8g::RGB ? 255.f : 1.f };
p8g_fill(fill);
}

void p8g::fill(float gray, float alpha) {
float fill[] = { gray, gray, gray, alpha };
p8g_fill(fill);
}

void p8g::fill(float v1, float v2, float v3) {
float fill[] = { v1, v2, v3, ::colorMode == p8g::RGB ? 255.f : 1.f };
p8g_fill(fill);
}

void p8g::fill(float v1, float v2, float v3, float alpha) {
float fill[] = { v1, v2, v3, alpha };
p8g_fill(fill);
}

void p8g::fill(float color[4]) {
p8g_fill(color);
}

void p8g::line(float x1, float y1, float x2, float y2) {
p8g_line(x1, y1, x2, y2);
}

void p8g::noFill() {
p8g_no_fill();
}

void p8g::noSmooth() {
p8g_no_smooth();
}

void p8g::noStroke() {
p8g_no_stroke();
}

void p8g::point(float x, float y) {
p8g_point(x, y);
}

void p8g::pop() {
p8g_pop();
}

void p8g::push() {
p8g_push();
}

void p8g::rect(float x, float y, float w, float h) {
p8g_rect(x, y, w, h);
}

void p8g::rectMode(int mode) {
p8g_rect_mode((p8g_rect_mode_t) mode);
}

void p8g::resetMatrix() {
p8g_reset_matrix();
}

void p8g::rotate(float angle) {
p8g_rotate(angle);
}

void p8g::run() {
p8g_run((p8g_sketch_t) {
.draw = ::draw,
.key_pressed = ::keyPressed,
.key_released = ::keyReleased,
.mouse_moved = ::mouseMoved,
.mouse_pressed = ::mousePressed,
.mouse_released = ::mouseReleased,
.mouse_wheel = ::mouseWheel,
});
}

void p8g::run(int width, int height) {
p8g::width = width;
p8g::height = height;
p8g_run((p8g_sketch_t) {
.width = width,
.height = height,
.draw = ::draw,
.key_pressed = ::keyPressed,
.key_released = ::keyReleased,
.mouse_moved = ::mouseMoved,
.mouse_pressed = ::mousePressed,
.mouse_released = ::mouseReleased,
.mouse_wheel = ::mouseWheel,
});
}

void p8g::run(int width, int height, std::string title) {
p8g::width = width;
p8g::height = height;
p8g_run((p8g_sketch_t) {
.width = width,
.height = height,
.title = title.c_str(),
.draw = ::draw,
.key_pressed = ::keyPressed,
.key_released = ::keyReleased,
.mouse_moved = ::mouseMoved,
.mouse_pressed = ::mousePressed,
.mouse_released = ::mouseReleased,
.mouse_wheel = ::mouseWheel,
});
}

void p8g::scale(float s) {
p8g_scale(s, s);
}

void p8g::scale(float x, float y) {
p8g_scale(x, y);
}

void p8g::smooth() {
p8g_smooth();
}

void p8g::stroke(float gray) {
float stroke[] = { gray, gray, gray, ::colorMode == p8g::RGB ? 255.f : 1.f };
p8g_stroke(stroke);
}

void p8g::stroke(float gray, float alpha) {
float stroke[] = { gray, gray, gray, alpha };
p8g_stroke(stroke);
}

void p8g::stroke(float v1, float v2, float v3) {
float stroke[] = { v1, v2, v3, ::colorMode == p8g::RGB ? 255.f : 1.f };
p8g_stroke(stroke);
}

void p8g::stroke(float v1, float v2, float v3, float alpha) {
float stroke[] = { v1, v2, v3, alpha };
p8g_stroke(stroke);
}

void p8g::stroke(float color[4]) {
p8g_stroke(color);
}

void p8g::strokeWeight(float weight) {
p8g_stroke_weight(weight);
}

void p8g::translate(float x, float y) {
p8g_translate(x, y);
}

void p8g::triangle(float x1, float y1, float x2, float y2, float x3, float y3) {
p8g_triangle(x1, y1, x2, y2, x3, y3);
}
Loading

0 comments on commit b9f3f6f

Please sign in to comment.