mirror of
https://github.com/Dingo-Shenanigans/ReSkate.git
synced 2026-10-23 14:15:53 +02:00
- contrib/plugins/reskate-test calls every plugin API and says what worked: ptest all, ptest <module>, ptest list. Its 45 checks cover the base set, timers, the level, package files, JSON, require, the console, storage and the sandbox. It is the example to copy for a plugin. - contrib/plugins/reskate-hostile attacks the sandbox, one attack per command (hostile list): loops, memory and buffer bombs, caught errors, error and log floods, timers, recursion, an unload that never ends, and 17 ways out. Each must end stopped or refused. - dingosdk_plugin_tests runs both from the repository: every reskate-test check passes, and every hostile attack is stopped or refused with nothing escaping. - Taken from Domination (PR 279) for the plugin API to use: the trick watch (when a trick starts, lands and what it scored, or a slam breaks it; Domination's spots left out) in Extension/Skater/trick_watch.h with its tests, the score HUD reader in score_hud.h, and teleport_local_skater_heading, whose hunks are the PR's own. Neither is wired to anything yet.
53 lines
1.8 KiB
C++
53 lines
1.8 KiB
C++
#include "trick_watch.h"
|
|
#include <algorithm>
|
|
#include <utility>
|
|
|
|
namespace dingosdk::tricks {
|
|
namespace {
|
|
// The line's points before the multiplier.
|
|
float unscaled(float score, float multiplier) { return multiplier > 0.01f ? score / multiplier : score; }
|
|
}
|
|
|
|
TrickEvent TrickWatch::update(const TrickSignals& in) {
|
|
if (!std::exchange(seen_, true)) {
|
|
score_ = in.line_score;
|
|
multiplier_ = in.multiplier;
|
|
}
|
|
// A slam or a wipeout: skate. drops the line, and the trick going on scores nothing.
|
|
if (in.slam || in.wipeout) {
|
|
const bool had = action_ || waiting_;
|
|
action_ = false;
|
|
waiting_ = 0;
|
|
score_ = in.line_score;
|
|
multiplier_ = in.multiplier;
|
|
return had ? TrickEvent{TrickEvent::Kind::broken} : TrickEvent{};
|
|
}
|
|
if (in.action) {
|
|
if (action_) return {};
|
|
// A trick starts (a previous one whose points never came scored nothing).
|
|
action_ = true;
|
|
waiting_ = 0;
|
|
return {TrickEvent::Kind::started};
|
|
}
|
|
if (action_) { // the trick ended this tick: its points show in the line's score shortly
|
|
action_ = false;
|
|
waiting_ = wait_ticks_;
|
|
}
|
|
if (waiting_ > 0) {
|
|
if (in.line_score > score_ + 0.5f) {
|
|
const float scale = in.multiplier > 0.01f ? in.multiplier : 1.0f;
|
|
const float points = std::max(0.0f, (unscaled(in.line_score, in.multiplier) - unscaled(score_, multiplier_)) * scale);
|
|
score_ = in.line_score;
|
|
multiplier_ = in.multiplier;
|
|
waiting_ = 0;
|
|
return {TrickEvent::Kind::landed, points, scale};
|
|
}
|
|
if (--waiting_ > 0) return {};
|
|
}
|
|
// No trick pending: the line's score follows whatever else moves it (its end resets it to 0).
|
|
score_ = in.line_score;
|
|
multiplier_ = in.multiplier;
|
|
return {};
|
|
}
|
|
}
|