Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update the new Config API, add C++ wrapper #64

Merged
merged 3 commits into from
Dec 16, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions .github/workflows/pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ jobs:
- name: clang-format
run: |
docker run --rm -v ${PWD}:/src ghcr.io/wiiu-env/clang-format:13.0.0-2 -r ./plugins/example_plugin/src
docker run --rm -v ${PWD}:/src ghcr.io/wiiu-env/clang-format:13.0.0-2 -r ./plugins/example_plugin_cpp/src
docker run --rm -v ${PWD}:/src ghcr.io/wiiu-env/clang-format:13.0.0-2 -r ./plugins/storage_test_plugin/src --exclude ./plugins/storage_test_plugin/src/catch2
build-examples:
runs-on: ubuntu-22.04
Expand All @@ -40,8 +41,10 @@ jobs:
run: |
docker build . -f Dockerfile.buildexamples -t builder
cd ./plugins/example_plugin
docker run --rm -v ${PWD}:/project builder make
cd ../storage_test_plugin
docker run --rm -v ${PWD}:/project builder make
cd ../example_plugin_cpp
docker run --rm -v ${PWD}:/project builder make
cd ../storage_test_plugin
docker run --rm -v ${PWD}:/project builder make
- uses: actions/upload-artifact@master
with:
Expand Down
8 changes: 6 additions & 2 deletions .github/workflows/push_image.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ jobs:
- name: clang-format
run: |
docker run --rm -v ${PWD}:/src ghcr.io/wiiu-env/clang-format:13.0.0-2 -r ./plugins/storage_test_plugin/src --exclude ./plugins/storage_test_plugin/src/catch2
docker run --rm -v ${PWD}:/src ghcr.io/wiiu-env/clang-format:13.0.0-2 -r ./plugins/example_plugin/src
docker run --rm -v ${PWD}:/src ghcr.io/wiiu-env/clang-format:13.0.0-2 -r ./plugins/example_plugin_cpp/src
build-examples:
runs-on: ubuntu-22.04
needs: clang-format-examples
Expand All @@ -42,8 +44,10 @@ jobs:
run: |
docker build . -f Dockerfile.buildexamples -t builder
cd ./plugins/example_plugin
docker run --rm -v ${PWD}:/project builder make
cd ../storage_test_plugin
docker run --rm -v ${PWD}:/project builder make
cd ./plugins/example_plugin_cpp
docker run --rm -v ${PWD}:/project builder make
cd ../storage_test_plugin
docker run --rm -v ${PWD}:/project builder make
build-and-push-image:
runs-on: ubuntu-latest
Expand Down
9 changes: 4 additions & 5 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ TOPDIR ?= $(CURDIR)
include $(TOPDIR)/share/wups_rules

export WUPS_MAJOR := 0
export WUPS_MINOR := 7
export WUPS_PATCH := 2
export WUPS_MINOR := 8
export WUPS_PATCH := 0

VERSION := $(WUPS_MAJOR).$(WUPS_MINOR).$(WUPS_PATCH)

Expand All @@ -23,15 +23,14 @@ INCLUDES := include
#---------------------------------------------------------------------------------
# options for code generation
#---------------------------------------------------------------------------------
CFLAGS := -g -Wall -Werror -save-temps \
CFLAGS := -g -O2 -Wall -Werror -save-temps \
-ffunction-sections -fdata-sections \
-fno-exceptions -fno-rtti \
$(MACHDEP) \
$(BUILD_CFLAGS)

CFLAGS += $(INCLUDE) -D__WIIU__ -D__WUT__ -D__WUPS__

CXXFLAGS := $(CFLAGS) -std=gnu++20
CXXFLAGS := $(CFLAGS) -std=c++20

ASFLAGS := -g $(MACHDEP)

Expand Down
2 changes: 1 addition & 1 deletion README.MD
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,4 @@ It's highly recommended to pin the version to the **latest date** instead of usi

## Format the code via docker

`docker run --rm -v ${PWD}:/src ghcr.io/wiiu-env/clang-format:13.0.0-2 -r ./include ./libraries ./plugins/example_plugin/src ./plugins/storage_test_plugin/src --exclude ./plugins/storage_test_plugin/src/catch2 -i`
`docker run --rm -v ${PWD}:/src ghcr.io/wiiu-env/clang-format:13.0.0-2 -r ./include ./libraries ./plugins/example_plugin/src ./plugins/example_plugin_cpp/src ./plugins/storage_test_plugin/src --exclude ./plugins/storage_test_plugin/src/catch2 -i`
10 changes: 1 addition & 9 deletions include/wups.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,4 @@
#include "wups/hooks.h"
#include "wups/meta.h"
#include "wups/storage.h"
#ifdef DEBUG
#include <coreinit/debug.h>
#endif

#ifdef DEBUG
#define WUPS_DEBUG_REPORT(fmt, ...) OSReport(fmt, ##__VA_ARGS__)
#else
#define WUPS_DEBUG_REPORT(fmt, ...)
#endif
#include "wups/wups_debug.h"
158 changes: 140 additions & 18 deletions include/wups/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,26 +17,54 @@

#pragma once

#include <padscore/kpad.h>
#include <stdint.h>
#include <vpad/input.h>

#define WUPS_CONFIG_BUTTON_NONE 0
#define WUPS_CONFIG_BUTTON_LEFT (1 << 0)
#define WUPS_CONFIG_BUTTON_RIGHT (1 << 1)
#define WUPS_CONFIG_BUTTON_UP (1 << 2)
#define WUPS_CONFIG_BUTTON_DOWN (1 << 3)
#define WUPS_CONFIG_BUTTON_A (1 << 4)
#define WUPS_CONFIG_BUTTON_B (1 << 5)
#define WUPS_CONFIG_BUTTON_ZL (1 << 6)
#define WUPS_CONFIG_BUTTON_ZR (1 << 7)
#define WUPS_CONFIG_BUTTON_L (1 << 8)
#define WUPS_CONFIG_BUTTON_R (1 << 9)
#define WUPS_CONFIG_BUTTON_X (1 << 10)
#define WUPS_CONFIG_BUTTON_Y (1 << 11)
#define WUPS_CONFIG_BUTTON_STICK_L (1 << 12)
#define WUPS_CONFIG_BUTTON_STICK_R (1 << 13)
#define WUPS_CONFIG_BUTTON_PLUS (1 << 14)
#define WUPS_CONFIG_BUTTON_MINUS (1 << 15)
typedef int32_t WUPSConfigButtons;
typedef uint32_t WUPSConfigButtons;

typedef enum WUPS_CONFIG_SIMPLE_INPUT {
WUPS_CONFIG_BUTTON_NONE = 0,
WUPS_CONFIG_BUTTON_LEFT = (1 << 0),
WUPS_CONFIG_BUTTON_RIGHT = (1 << 1),
WUPS_CONFIG_BUTTON_UP = (1 << 2),
WUPS_CONFIG_BUTTON_DOWN = (1 << 3),
WUPS_CONFIG_BUTTON_A = (1 << 4),
WUPS_CONFIG_BUTTON_B = (1 << 5),
WUPS_CONFIG_BUTTON_ZL = (1 << 6),
WUPS_CONFIG_BUTTON_ZR = (1 << 7),
WUPS_CONFIG_BUTTON_L = (1 << 8),
WUPS_CONFIG_BUTTON_R = (1 << 9),
WUPS_CONFIG_BUTTON_X = (1 << 10),
WUPS_CONFIG_BUTTON_Y = (1 << 11),
WUPS_CONFIG_BUTTON_STICK_L = (1 << 12),
WUPS_CONFIG_BUTTON_STICK_R = (1 << 13),
WUPS_CONFIG_BUTTON_PLUS = (1 << 14),
WUPS_CONFIG_BUTTON_MINUS = (1 << 15),
} WUPS_CONFIG_SIMPLE_INPUT;

typedef struct {
WUPS_CONFIG_SIMPLE_INPUT buttons_h;
WUPS_CONFIG_SIMPLE_INPUT buttons_d;
WUPS_CONFIG_SIMPLE_INPUT buttons_r;
bool validPointer;
bool touched;
float pointerAngle;
int32_t x;
int32_t y;
} WUPSConfigSimplePadData;

typedef struct {
struct {
VPADReadError vpadError;
VPADTouchData tpCalib;
VPADStatus data;
} vpad;
struct {
KPADError kpadError[4];
KPADStatus data[4];
} kpad;
} WUPSConfigComplexPadData;

typedef enum WUPSConfigAPIStatus {
WUPSCONFIG_API_RESULT_SUCCESS = 0,
Expand Down Expand Up @@ -76,17 +104,111 @@ typedef struct {
void (*onDelete)(void *context);
} WUPSConfigAPIItemCallbacksV1;

typedef struct {
/**
* Set the string which is displayed for an item
* @param context The context which has been passed to the item during creating
* @param out_buf Buffer where the string should be written to
* @param out_size Size of out_buf
*
* \result non-zero result indicates an error.
*/
int32_t (*getCurrentValueDisplay)(void *context, char *out_buf, int32_t out_size);

/**
* Set the string which is displayed for an item when the cursor is on is item
* @param context The context which has been passed to the item during creating
* @param out_buf Buffer where the string should be written to
* @param out_size Size of out_buf
*
* \result non-zero result indicates an error.
*/
int32_t (*getCurrentValueSelectedDisplay)(void *context, char *out_buf, int32_t out_size);

/**
* Called when the cursor enters or leaves this item
* @param context The context which has been passed to the item during creating
* @param isSelected True if the item cursor is now pointing to this item, \n
* False if it's not pointing to this item anymore
*/
void (*onSelected)(void *context, bool isSelected);

/**
* Called when the current value of this item should be set to the default value
* @param context The context which has been passed to the item during creating
*/
void (*restoreDefault)(void *context);

/**
* Determines if movement to different item is allowed.
* @param context The context which has been passed to the item during creating
* \return True if it should be not possible to select a different item or exit the current category \n
* False if it should be possible to select a different item or exit the current category
*/
bool (*isMovementAllowed)(void *context);

/**
* Called when the config menu has been closed
* @param context The context which has been passed to the item during creating
*/
void (*onCloseCallback)(void *context);

/**
* This function is called on each frame and provides information about the current inputs.
* The inputs are simplified and all 5 possible controller inputs (from Gamepad and up to 4 Wiimotes/Pro Controller)
* are unified in this single unified struct.
*
* @param context The context which has been passed to the item during creating
* @param input Simplified version of the current inputs
*
* \note To get the full input for all possible controllers see "onInputEx"
*
* @see onInputEx
*/
void (*onInput)(void *context, WUPSConfigSimplePadData input);

/**
* This function is called on each frame and provides information about the current inputs.
* The structs contains information for current individual Gampepad and Wiimote/Pro Contoller inputs.
*
* @param context The context which has been passed to the item during creating
* @param input current input for all possibles controller
*
* \note To get a simplified input callback that combines all controller into a single struct see "onInput"
*
* @see onInput
*/
void (*onInputEx)(void *context, WUPSConfigComplexPadData input);

/**
* This function is called when the item is about to be deleted. It can be used to free any alloated memory.
*
* @param context The context which has been passed to the item during creating
*/
void (*onDelete)(void *context);
} WUPSConfigAPIItemCallbacksV2;

#define WUPS_API_ITEM_OPTION_VERSION_V1 1
#define WUPS_API_ITEM_OPTION_VERSION_V2 2

typedef struct WUPSConfigAPIItemOptionsV1 {
const char *configId;
const char *displayName;
void *context;
WUPSConfigAPIItemCallbacksV1 callbacks;
} WUPSConfigAPIItemOptionsV1;

typedef struct WUPSConfigAPIItemOptionsV2 {
const char *displayName;
void *context;
WUPSConfigAPIItemCallbacksV2 callbacks;
} WUPSConfigAPIItemOptionsV2;

typedef struct WUPSConfigAPICreateItemOptions {
uint32_t version;
union {
WUPSConfigAPIItemOptionsV1 v1;
WUPSConfigAPIItemOptionsV2 v2;
} data;
} WUPSConfigAPICreateItemOptions;

Expand Down
51 changes: 51 additions & 0 deletions include/wups/config/WUPSConfigCategory.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
#pragma once

#ifdef __cplusplus

#include "WUPSConfigItem.h"
#include <optional>
#include <stdexcept>
#include <string>

class WUPSConfigCategory {
public:
explicit WUPSConfigCategory(WUPSConfigCategoryHandle handle) noexcept;
virtual ~WUPSConfigCategory();

WUPSConfigCategory(const WUPSConfigCategory &) = delete;

WUPSConfigCategory(WUPSConfigCategory &&src) noexcept : mHandle(src.mHandle) {
src.mHandle = {};
}

WUPSConfigCategory &operator=(WUPSConfigCategory &&src) noexcept {
if (this != &src) {
src.mHandle = {};
}
return *this;
}

static std::optional<WUPSConfigCategory> Create(std::string_view name, WUPSConfigAPIStatus &error) noexcept;

static WUPSConfigCategory Create(std::string_view name);

bool add(WUPSConfigCategory &&cat, WUPSConfigAPIStatus &error) noexcept;

void add(WUPSConfigCategory &&cat);

bool add(WUPSConfigItem &&item, WUPSConfigAPIStatus &error) noexcept;

void add(WUPSConfigItem &&item);

[[nodiscard]] const WUPSConfigCategoryHandle &getHandle() const {
return mHandle;
}

void release() {
mHandle = {};
}

private:
WUPSConfigCategoryHandle mHandle = {};
};
#endif
41 changes: 41 additions & 0 deletions include/wups/config/WUPSConfigItem.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
#pragma once

#ifdef __cplusplus

#include "wups/config.h"
#include <coreinit/debug.h>

class WUPSConfigItem {
protected:
explicit WUPSConfigItem(WUPSConfigItemHandle itemHandle) : mHandle(itemHandle) {
}

public:
virtual ~WUPSConfigItem();

WUPSConfigItem(const WUPSConfigItem &) = delete;

WUPSConfigItem(WUPSConfigItem &&src) noexcept : mHandle(src.mHandle) {
src.mHandle = {};
}

WUPSConfigItem &operator=(WUPSConfigItem &&src) noexcept {
if (this != &src) {
src.mHandle = {};
}
return *this;
}

[[nodiscard]] const WUPSConfigItemHandle &getHandle() const {
return mHandle;
}

void release() {
mHandle = {};
}

private:
WUPSConfigItemHandle mHandle = {};
};

#endif
Loading
Loading