Skip to content

Commit

Permalink
wow ok wrong order commits vscode
Browse files Browse the repository at this point in the history
  • Loading branch information
TurtleP committed Apr 5, 2024
1 parent 58932cd commit b33f72b
Show file tree
Hide file tree
Showing 15 changed files with 345 additions and 68 deletions.
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ if (NINTENDO_WIIU)
add_subdirectory(platform/cafe)

target_compile_definitions(${PROJECT_NAME} PRIVATE
__CONSOLE__="Wii U" __OS__="Cafe" __LOVE_BIG_ENDIAN__
__CONSOLE__="Wii U" __OS__="Cafe" LOVE_BIG_ENDIAN
)

set(APP_ICON platform/cafe/icon.png)
Expand Down
14 changes: 14 additions & 0 deletions include/common/Result.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,16 +26,30 @@ namespace love
Result(T t) : value(t.value)
{}

/**
* @brief Check if the result was successful (>= 0).
*/
bool success() const
{
return this->value >= 0;
}

/**
* @brief Check if the result was a failure (< 0).
*/
bool failed() const
{
return this->value < 0;
}

/**
* @brief Check if the result was a failure with a specific error code.
*/
bool failed(uint32_t error) const
{
return this->value == error;
}

int32_t get() const
{
return this->value;
Expand Down
34 changes: 34 additions & 0 deletions include/driver/DigitalSound.tcc
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
#pragma once

#include "common/Singleton.tcc"
#include "common/map.hpp"

namespace love
{
template<class T>
class DigitalSoundBase : public Singleton<T>
{
public:
enum InterpretedFormat
{
FORMAT_MONO,
FORMAT_STEREO,
FORMAT_MAX_ENUM
};

enum EncodingFormat
{
ENCODING_PCM8 = 0x08,
ENCODING_PCM16 = 0x10,
ENCODING_MAX_ENUM
};

virtual void initialize()
{}

void update()
{
static_cast<T*>(this)->updateImpl();
}
};
} // namespace love
4 changes: 2 additions & 2 deletions include/modules/data/misc/LZ4Compressor.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ namespace love
throw love::Exception(E_OUT_OF_MEMORY);
}

#if defined(__LOVE_BIG_ENDIAN__)
#if defined(LOVE_BIG_ENDIAN)
*(uint32_t*)compressedBytes = swap_uint32((uint32_t)dataSize);
#else
*(uint32_t*)compressedBytes = (uint32_t)dataSize;
Expand Down Expand Up @@ -90,7 +90,7 @@ namespace love
if (dataSize < headerSize)
throw love::Exception("Invalid LZ4-compressed data size.");

#if defined(__LOVE_BIG_ENDIAN__)
#if defined(LOVE_BIG_ENDIAN)
uint32_t rawSize = swap_uint32(*(uint32_t*)data);
#else
uint32_t rawSize = *(uint32_t*)data;
Expand Down
31 changes: 17 additions & 14 deletions include/modules/joystick/Joystick.tcc
Original file line number Diff line number Diff line change
Expand Up @@ -217,20 +217,23 @@ namespace love
);

STRINGMAP_DECLARE(GamepadTypes, GamepadType,
{ "unknown", GAMEPAD_TYPE_UNKNOWN },
{ "3ds", GAMEPAD_TYPE_NINTENDO_3DS },
{ "3dsxl", GAMEPAD_TYPE_NINTENDO_3DS_XL },
{ "new3ds", GAMEPAD_TYPE_NEW_NINTENDO_3DS },
{ "new3dsxl", GAMEPAD_TYPE_NEW_NINTENDO_3DS_XL },
{ "2ds", GAMEPAD_TYPE_NINTENDO_2DS },
{ "new2dsxl", GAMEPAD_TYPE_NEW_NINTENDO_2DS_XL },
{ "switchhandheld", GAMEPAD_TYPE_NINTENDO_SWITCH_HANDHELD },
{ "switchpro", GAMEPAD_TYPE_NINTENDO_SWITCH_PRO },
{ "joyconleft", GAMEPAD_TYPE_JOYCON_LEFT },
{ "joyconright", GAMEPAD_TYPE_JOYCON_RIGHT },
{ "joyconpair", GAMEPAD_TYPE_JOYCON_PAIR },
{ "wiiugamepad", GAMEPAD_TYPE_WII_U_GAMEPAD },
{ "wiiupro", GAMEPAD_TYPE_WII_U_PRO }
{ "unknown", GAMEPAD_TYPE_UNKNOWN },
{ "3ds", GAMEPAD_TYPE_NINTENDO_3DS },
{ "3dsxl", GAMEPAD_TYPE_NINTENDO_3DS_XL },
{ "new3ds", GAMEPAD_TYPE_NEW_NINTENDO_3DS },
{ "new3dsxl", GAMEPAD_TYPE_NEW_NINTENDO_3DS_XL },
{ "2ds", GAMEPAD_TYPE_NINTENDO_2DS },
{ "new2dsxl", GAMEPAD_TYPE_NEW_NINTENDO_2DS_XL },
{ "wiiremote", GAMEPAD_TYPE_NINTENDO_WII_REMOTE },
{ "wiiremotenunchuck", GAMEPAD_TYPE_NINTENDO_WII_REMOTE_NUNCHUCK },
{ "wiiclassic", GAMEPAD_TYPE_NINTENDO_WII_CLASSIC },
{ "wiiugamepad", GAMEPAD_TYPE_NINTENDO_WII_U_GAMEPAD },
{ "wiiupro", GAMEPAD_TYPE_NINTENDO_WII_U_PRO },
{ "switchhandheld", GAMEPAD_TYPE_NINTENDO_SWITCH_HANDHELD },
{ "switchpro", GAMEPAD_TYPE_NINTENDO_SWITCH_PRO },
{ "joyconleft", GAMEPAD_TYPE_JOYCON_LEFT },
{ "joyconright", GAMEPAD_TYPE_JOYCON_RIGHT },
{ "joyconpair", GAMEPAD_TYPE_JOYCON_PAIR }
);

STRINGMAP_DECLARE(JoystickTypes, JoystickType,
Expand Down
14 changes: 4 additions & 10 deletions include/modules/joystick/JoystickModule.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,6 @@
#include <string>
#include <vector>

#if defined(__3DS__)
#define MAX_JOYSTICKS 1
#elif defined(__SWITCH__)
#define MAX_JOYSTICKS 8
#else
#define MAX_JOYSTICKS 2
#endif

namespace love
{
class JoystickModule : public Module
Expand All @@ -42,8 +34,8 @@ namespace love

std::string getDeviceGUID(int64_t deviceId) const;

std::vector<Joystick*> activeSticks;
std::list<Joystick*> joysticks;
std::vector<JoystickBase*> activeSticks;
std::list<JoystickBase*> joysticks;

std::map<std::string, bool> recentGamepadGUIDs;
};
Expand All @@ -55,5 +47,7 @@ namespace love
** This is implemented in the platform-specific code.
*/
int getJoystickCount();

JoystickBase* openJoystick(int index);
} // namespace joystick
} // namespace love
7 changes: 5 additions & 2 deletions include/utility/guid.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,16 @@ namespace love
GAMEPAD_TYPE_NEW_NINTENDO_3DS_XL,
GAMEPAD_TYPE_NINTENDO_2DS,
GAMEPAD_TYPE_NEW_NINTENDO_2DS_XL,
GAMEPAD_TYPE_NINTENDO_WII_REMOTE,
GAMEPAD_TYPE_NINTENDO_WII_REMOTE_NUNCHUCK,
GAMEPAD_TYPE_NINTENDO_WII_CLASSIC,
GAMEPAD_TYPE_NINTENDO_WII_U_GAMEPAD,
GAMEPAD_TYPE_NINTENDO_WII_U_PRO,
GAMEPAD_TYPE_NINTENDO_SWITCH_HANDHELD,
GAMEPAD_TYPE_NINTENDO_SWITCH_PRO,
GAMEPAD_TYPE_JOYCON_LEFT,
GAMEPAD_TYPE_JOYCON_RIGHT,
GAMEPAD_TYPE_JOYCON_PAIR,
GAMEPAD_TYPE_WII_U_GAMEPAD,
GAMEPAD_TYPE_WII_U_PRO,
GAMEPAD_TYPE_MAX_ENUM
};

Expand Down
2 changes: 2 additions & 0 deletions platform/cafe/include/driver/EventQueue.hpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#pragma once

#include "driver/EventQueue.tcc"
#include "modules/joystick/Joystick.hpp"

#include <vpad/input.h>

Expand All @@ -17,5 +18,6 @@ namespace love

private:
VPADTouchData previousTouch;
Joystick* gamepad;
};
} // namespace love
68 changes: 36 additions & 32 deletions platform/cafe/source/driver/EventQueue.cpp
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
#include "driver/EventQueue.hpp"

#include "modules/joystick/JoystickModule.hpp"
#include "utility/guid.hpp"

using namespace love;

#define JOYSTICK_MODULE() Module::getInstance<JoystickModule>(Module::M_JOYSTICK)

namespace love
{
EventQueue::EventQueue()
EventQueue::EventQueue() : gamepad(nullptr), previousTouch {}
{}

EventQueue::~EventQueue()
Expand All @@ -19,46 +20,49 @@ namespace love
if (!JOYSTICK_MODULE())
return;

auto& status = ((Joystick*)JOYSTICK_MODULE()->getJoystickFromID(0))->getVPADStatus();
auto touchType = SUBTYPE_TOUCHPRESS;

if (status.tpNormal.touched)
for (int index = 0; index < joystick::getJoystickCount(); index++)
{
// clang-format off
VPADGetTPCalibratedPointEx(VPAD_CHAN_0, VPAD_TP_854X480, &status.tpNormal, &status.tpNormal);
// clang-format on
auto* joystick = JOYSTICK_MODULE()->getJoystick(index);

float x = status.tpNormal.x, y = status.tpNormal.y;
float dx = 0, dy = 0;
if (joystick->getGamepadType() == GAMEPAD_TYPE_WII_U_GAMEPAD)
this->gamepad = (Joystick*)joystick;

dx = (status.tpNormal.x - this->previousTouch.x);
dy = (status.tpNormal.y - this->previousTouch.y);
JOYSTICK_MODULE()->getJoystick(index)->update();
}

if (dx == 0 && dy == 0)
touchType = SUBTYPE_TOUCHPRESS;
else
touchType = SUBTYPE_TOUCHMOVED;
if (this->gamepad)
{
auto& status = this->gamepad->getVPADStatus();
SubEventType touchType;

this->sendTouchEvent(touchType, 0, x, y, dx, dy, 1.0f);
this->previousTouch = status.tpNormal;
if (status.tpNormal.touched)
{
// clang-format off
VPADGetTPCalibratedPointEx(VPAD_CHAN_0, VPAD_TP_854X480, &status.tpNormal, &status.tpNormal);
// clang-format on

if (touchType == SUBTYPE_TOUCHMOVED && !dx && !dy)
this->events.pop_back();
}
else
{
const auto& previous = this->previousTouch;
this->sendTouchEvent(SUBTYPE_TOUCHRELEASE, 0, previous.x, previous.y, 0, 0, 1.0f);
}
float x = status.tpNormal.x, y = status.tpNormal.y;
float dx = 0, dy = 0;

for (size_t index = 0; index < JOYSTICK_MODULE()->getJoystickCount(); index++)
{
auto* joystick = JOYSTICK_MODULE()->getJoystick(index);
dx = (status.tpNormal.x - this->previousTouch.x);
dy = (status.tpNormal.y - this->previousTouch.y);

if (dx == 0 && dy == 0)
touchType = SUBTYPE_TOUCHPRESS;
else
touchType = SUBTYPE_TOUCHMOVED;

if (joystick == nullptr)
continue;
this->sendTouchEvent(touchType, 0, x, y, dx, dy, 1.0f);
this->previousTouch = status.tpNormal;

joystick->update();
if (touchType == SUBTYPE_TOUCHMOVED && !dx && !dy)
this->events.pop_back();
}
else
{
const auto& previous = this->previousTouch;
this->sendTouchEvent(SUBTYPE_TOUCHRELEASE, 0, previous.x, previous.y, 0, 0, 1.0f);
}
}
}
} // namespace love
23 changes: 18 additions & 5 deletions platform/cafe/source/modules/joystick/JoystickModule.cpp
Original file line number Diff line number Diff line change
@@ -1,16 +1,21 @@
#include "modules/joystick/JoystickModule.hpp"

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

namespace love::joystick
{
/**
* The Wii U Gamepad is always connected.
* So the count starts at 1.
*/
int getJoystickCount()
{
int count = 1;
int count = 0;

VPADStatus status {};
VPADReadError error = VPAD_READ_SUCCESS;

VPADRead(VPAD_CHAN_0, &status, 1, &error);

if (error == VPAD_READ_SUCCESS)
count++;

for (int channel = 0; channel < 4; channel++)
{
Expand All @@ -25,4 +30,12 @@ namespace love::joystick

return count;
}

/*
** TODO: open either vpad::Joystick or kpad::Joystick based on what opens first.
*/
JoystickBase* openJoystick(int index)
{
return nullptr;
}
} // namespace love::joystick
Loading

0 comments on commit b33f72b

Please sign in to comment.