BCSTM-Player |

This commit is contained in:
tobid7 2021-07-23 13:58:16 +00:00
parent f51ddecf3d
commit c537fc095a
101 changed files with 39980 additions and 0 deletions

320
external/fs.c vendored Normal file
View File

@ -0,0 +1,320 @@
#include "external/fs.h"
#include <stdio.h>
#include <string.h>
void Utils_U8_To_U16(u16 *buf, const u8 *input, size_t bufsize) {
ssize_t units = utf8_to_utf16(buf, input, bufsize);
if (units < 0)
units = 0;
buf[units] = 0;
}
FS_Archive archive, sdmc_archive, nand_archive;
Result FS_OpenArchive(FS_Archive *archive, FS_ArchiveID archiveID) {
Result ret = 0;
if (R_FAILED(ret = FSUSER_OpenArchive(archive, archiveID, fsMakePath(PATH_EMPTY, ""))))
return ret;
return 0;
}
Result FS_CloseArchive(FS_Archive archive) {
Result ret = 0;
if (R_FAILED(ret = FSUSER_CloseArchive(archive)))
return ret;
return 0;
}
Result FS_OpenDir(Handle *handle, FS_Archive archive, const char *path) {
Result ret = 0;
u16 path_u16[strlen(path) + 1];
Utils_U8_To_U16(path_u16, (const u8 *)path, strlen(path) + 1);
if (R_FAILED(ret = FSUSER_OpenDirectory(handle, archive, fsMakePath(PATH_UTF16, path_u16))))
return ret;
return 0;
}
Result FS_OpenFile(Handle *handle, FS_Archive archive, const char *path, u32 flags, u32 attributes) {
Result ret = 0;
u16 path_u16[strlen(path) + 1];
Utils_U8_To_U16(path_u16, (const u8 *)path, strlen(path) + 1);
if (R_FAILED(ret = FSUSER_OpenFile(handle, archive, fsMakePath(PATH_UTF16, path_u16), flags, attributes)))
return ret;
return 0;
}
Result FS_MakeDir(FS_Archive archive, const char *path) {
Result ret = 0;
u16 path_u16[strlen(path) + 1];
Utils_U8_To_U16(path_u16, (const u8 *)path, strlen(path) + 1);
if (R_FAILED(ret = FSUSER_CreateDirectory(archive, fsMakePath(PATH_UTF16, path_u16), 0)))
return ret;
return 0;
}
Result FS_CreateFile(FS_Archive archive, const char *path, u64 size) {
Result ret = 0;
u16 path_u16[strlen(path) + 1];
Utils_U8_To_U16(path_u16, (const u8 *)path, strlen(path) + 1);
if (R_FAILED(ret = FSUSER_CreateFile(archive, fsMakePath(PATH_UTF16, path_u16), 0, size)))
return ret;
return 0;
}
Result FS_RecursiveMakeDir(FS_Archive archive, const char *path) {
Result ret = 0;
char buf[256];
char *p = NULL;
size_t len;
snprintf(buf, sizeof(buf), "%s", path);
len = strlen(buf);
if (buf[len - 1] == '/')
buf[len - 1] = 0;
for (p = buf + 1; *p; p++) {
if (*p == '/') {
*p = 0;
if (!FS_DirExists(archive, buf))
ret = FS_MakeDir(archive, buf);
*p = '/';
}
if (!FS_DirExists(archive, buf))
ret = FS_MakeDir(archive, buf);
}
return ret;
}
bool FS_FileExists(FS_Archive archive, const char *path) {
Handle handle;
u16 path_u16[strlen(path) + 1];
Utils_U8_To_U16(path_u16, (const u8 *)path, strlen(path) + 1);
if (R_FAILED(FSUSER_OpenFile(&handle, archive, fsMakePath(PATH_UTF16, path_u16), FS_OPEN_READ, 0)))
return false;
if (R_FAILED(FSFILE_Close(handle)))
return false;
return true;
}
bool FS_DirExists(FS_Archive archive, const char *path) {
Handle handle;
u16 path_u16[strlen(path) + 1];
Utils_U8_To_U16(path_u16, (const u8 *)path, strlen(path) + 1);
if (R_FAILED(FSUSER_OpenDirectory(&handle, archive, fsMakePath(PATH_UTF16, path_u16))))
return false;
if (R_FAILED(FSDIR_Close(handle)))
return false;
return true;
}
Result FS_GetFileSize(FS_Archive archive, const char *path, u64 *size) {
Result ret = 0;
Handle handle;
u16 path_u16[strlen(path) + 1];
Utils_U8_To_U16(path_u16, (const u8 *)path, strlen(path) + 1);
if (R_FAILED(ret = FSUSER_OpenFile(&handle, archive, fsMakePath(PATH_UTF16, path_u16), FS_OPEN_READ, 0)))
return ret;
if (R_FAILED(ret = FSFILE_GetSize(handle, size))) {
FSFILE_Close(handle);
return ret;
}
if (R_FAILED(ret = FSFILE_Close(handle)))
return ret;
return 0;
}
u64 FS_GetFreeStorage(FS_SystemMediaType media_type) {
FS_ArchiveResource resource = {0};
if (R_SUCCEEDED(FSUSER_GetArchiveResource(&resource, media_type)))
return (((u64)resource.freeClusters * (u64)resource.clusterSize));
return 0;
}
u64 FS_GetTotalStorage(FS_SystemMediaType media_type) {
FS_ArchiveResource resource = {0};
if (R_SUCCEEDED(FSUSER_GetArchiveResource(&resource, media_type)))
return (((u64)resource.totalClusters * (u64)resource.clusterSize));
return 0;
}
u64 FS_GetUsedStorage(FS_SystemMediaType media_type) {
return (FS_GetTotalStorage(media_type) - FS_GetUsedStorage(media_type));
}
Result FS_RemoveFile(FS_Archive archive, const char *path) {
Result ret = 0;
u16 path_u16[strlen(path) + 1];
Utils_U8_To_U16(path_u16, (const u8 *)path, strlen(path) + 1);
if (R_FAILED(ret = FSUSER_DeleteFile(archive, fsMakePath(PATH_UTF16, path_u16))))
return ret;
return 0;
}
Result FS_RemoveDir(FS_Archive archive, const char *path) {
Result ret = 0;
u16 path_u16[strlen(path) + 1];
Utils_U8_To_U16(path_u16, (const u8 *)path, strlen(path) + 1);
if (R_FAILED(ret = FSUSER_DeleteDirectory(archive, fsMakePath(PATH_UTF16, path_u16))))
return ret;
return 0;
}
Result FS_RemoveDirRecursive(FS_Archive archive, const char *path) {
Result ret = 0;
u16 path_u16[strlen(path) + 1];
Utils_U8_To_U16(path_u16, (const u8 *)path, strlen(path) + 1);
if (R_FAILED(ret = FSUSER_DeleteDirectoryRecursively(archive, fsMakePath(PATH_UTF16, path_u16))))
return ret;
return 0;
}
Result FS_RenameFile(FS_Archive archive, const char *old_filename, const char *new_filename) {
Result ret = 0;
u16 old_filename_u16[strlen(old_filename) + 1];
Utils_U8_To_U16(old_filename_u16, (const u8 *)old_filename, strlen(old_filename) + 1);
u16 new_filename_u16[strlen(new_filename) + 1];
Utils_U8_To_U16(new_filename_u16, (const u8 *)new_filename, strlen(new_filename) + 1);
if (R_FAILED(ret = FSUSER_RenameFile(archive, fsMakePath(PATH_UTF16, old_filename_u16), archive, fsMakePath(PATH_UTF16, new_filename_u16))))
return ret;
return 0;
}
Result FS_RenameDir(FS_Archive archive, const char *old_dirname, const char *new_dirname) {
Result ret = 0;
u16 old_dirname_u16[strlen(old_dirname) + 1];
Utils_U8_To_U16(old_dirname_u16, (const u8 *)old_dirname, strlen(old_dirname) + 1);
u16 new_dirname_u16[strlen(new_dirname) + 1];
Utils_U8_To_U16(new_dirname_u16, (const u8 *)new_dirname, strlen(new_dirname) + 1);
if (R_FAILED(ret = FSUSER_RenameDirectory(archive, fsMakePath(PATH_UTF16, old_dirname_u16), archive, fsMakePath(PATH_UTF16, new_dirname_u16))))
return ret;
return 0;
}
Result FS_Read(FS_Archive archive, const char *path, u64 size, void *buf) {
Result ret = 0;
Handle handle;
u32 bytes_read = 0;
if (R_FAILED(ret = FS_OpenFile(&handle, archive, path, FS_OPEN_READ, 0)))
return ret;
if (R_FAILED(ret = FSFILE_Read(handle, &bytes_read, 0, buf, size))) {
FSFILE_Close(handle);
return ret;
}
if (R_FAILED(ret = FSFILE_Close(handle)))
return ret;
return 0;
}
Result FS_Write(FS_Archive archive, const char *path, const void *buf, u32 size) {
Result ret = 0;
Handle handle;
u32 bytes_written = 0;
if (FS_FileExists(archive, path))
FS_RemoveFile(archive, path);
u16 path_u16[strlen(path) + 1];
Utils_U8_To_U16(path_u16, (const u8 *)path, strlen(path) + 1);
if (R_FAILED(ret = FSUSER_CreateFile(archive, fsMakePath(PATH_UTF16, path_u16), 0, size)))
return ret;
if (R_FAILED(ret = FSUSER_OpenFile(&handle, archive, fsMakePath(PATH_UTF16, path_u16), FS_OPEN_WRITE, 0)))
return ret;
if (R_FAILED(ret = FSFILE_Write(handle, &bytes_written, 0, buf, size, FS_WRITE_FLUSH))) {
FSFILE_Close(handle);
return ret;
}
if (R_FAILED(ret = FSFILE_Close(handle)))
return ret;
return 0;
}
char *FS_GetFileTimestamp(const char *path) {
static char timeStr[60];
u64 mtime = 0;
if (R_SUCCEEDED(archive_getmtime(path, &mtime))) {
time_t mt = mtime;
struct tm *timeStruct = gmtime(&mt);
int hours = timeStruct->tm_hour;
int minutes = timeStruct->tm_min;
int day = timeStruct->tm_mday;
int month = timeStruct->tm_mon + 1; // January being 0
int year = timeStruct->tm_year + 1900;
snprintf(timeStr, 60, "%d/%d/%d %2i:%02i", year, month, day, hours, minutes);
}
else
return NULL;
return timeStr;
}

30
external/fs.h vendored Normal file
View File

@ -0,0 +1,30 @@
#ifndef _3D_SHELL_FS_H
#define _3D_SHELL_FS_H
#include <3ds.h>
extern FS_Archive archive, sdmc_archive, nand_archive;
Result FS_OpenArchive(FS_Archive *archive, FS_ArchiveID id);
Result FS_CloseArchive(FS_Archive archive);
Result FS_OpenDir(Handle *handle, FS_Archive archive, const char *path);
Result FS_OpenFile(Handle *handle, FS_Archive archive, const char *path, u32 flags, u32 attributes);
Result FS_MakeDir(FS_Archive archive, const char *path);
Result FS_CreateFile(FS_Archive archive, const char *path, u64 size);
Result FS_RecursiveMakeDir(FS_Archive archive, const char *path);
bool FS_FileExists(FS_Archive archive, const char *path);
bool FS_DirExists(FS_Archive archive, const char *path);
Result FS_GetFileSize(FS_Archive archive, const char *path, u64 *size);
u64 FS_GetFreeStorage(FS_SystemMediaType media_type);
u64 FS_GetTotalStorage(FS_SystemMediaType media_type);
u64 FS_GetUsedStorage(FS_SystemMediaType media_type);
Result FS_RemoveFile(FS_Archive archive, const char *path);
Result FS_RemoveDir(FS_Archive archive, const char *path);
Result FS_RemoveDirRecursive(FS_Archive archive, const char *path);
Result FS_RenameFile(FS_Archive archive, const char *old_filename, const char *new_filename);
Result FS_RenameDir(FS_Archive archive, const char *old_dirname, const char *new_dirname);
Result FS_Read(FS_Archive archive, const char *path, u64 size, void *buf);
Result FS_Write(FS_Archive archive, const char *path, const void *buf, u32 size);
char *FS_GetFileTimestamp(const char *path);
#endif

25447
external/json.hpp vendored Normal file

File diff suppressed because it is too large Load Diff

6464
external/lodepng.cpp vendored Normal file

File diff suppressed because it is too large Load Diff

1977
external/lodepng.h vendored Normal file

File diff suppressed because it is too large Load Diff

44
external/tween-engine/Makefile vendored Normal file
View File

@ -0,0 +1,44 @@
PROJECT = libtween
CXX = arm-none-eabi-g++
AR = arm-none-eabi-ar
CXXFLAGS = -g -Wall -pedantic -std=c++11 -fno-rtti -fno-exceptions
INCLUDES = -Iinclude/
SOURCES = $(wildcard src/*.cpp) $(wildcard src/*/*.cpp)
OBJECTS = $(SOURCES:src/%.cpp=build/arm/%.o)
TEST_CXX = g++
TEST_AR = ar
TEST_CXXFLAGS = -g -Wall -pedantic -std=c++11 -fno-rtti -fno-exceptions -DTESTING
TEST_OBJECTS = $(SOURCES:src/%.cpp=build/test/%.o)
.PHONY: all dir clean test
all: dir $(PROJECT).a
test: dir $(PROJECT)-test.a
dir:
@mkdir -p build/arm/equations
@mkdir -p build/arm/paths
@mkdir -p build/test/equations
@mkdir -p build/test/paths
@mkdir -p lib
$(PROJECT).a: $(OBJECTS)
$(AR) rvs lib/$@ $^
$(PROJECT)-test.a: $(TEST_OBJECTS)
$(TEST_AR) rvs lib/$@ $^
clean:
@rm -rf build
@rm -rf lib
@echo "Successfully cleaned."
build/arm/%.o: src/%.cpp
$(CXX) $(INCLUDES) $(CXXFLAGS) -c $< -o $@
$(CXX) -MM $< > build/arm/$*.d
build/test/%.o: src/%.cpp
$(TEST_CXX) $(INCLUDES) $(TEST_CXXFLAGS) -c $< -o $@
$(TEST_CXX) -MM $< > build/test/$*.d

View File

@ -0,0 +1 @@
BaseTween.o: src/BaseTween.cpp

Binary file not shown.

View File

@ -0,0 +1 @@
Tween.o: src/Tween.cpp

BIN
external/tween-engine/build/arm/Tween.o vendored Normal file

Binary file not shown.

View File

@ -0,0 +1 @@
TweenEquations.o: src/TweenEquations.cpp

Binary file not shown.

View File

@ -0,0 +1 @@
TweenManager.o: src/TweenManager.cpp

Binary file not shown.

View File

@ -0,0 +1 @@
TweenPaths.o: src/TweenPaths.cpp

Binary file not shown.

View File

@ -0,0 +1 @@
TweenPool.o: src/TweenPool.cpp

Binary file not shown.

View File

@ -0,0 +1 @@
Back.o: src/equations/Back.cpp

Binary file not shown.

View File

@ -0,0 +1 @@
Bounce.o: src/equations/Bounce.cpp

Binary file not shown.

View File

@ -0,0 +1 @@
Circ.o: src/equations/Circ.cpp

Binary file not shown.

View File

@ -0,0 +1 @@
Cubic.o: src/equations/Cubic.cpp

Binary file not shown.

View File

@ -0,0 +1 @@
Elastic.o: src/equations/Elastic.cpp

Binary file not shown.

View File

@ -0,0 +1 @@
Expo.o: src/equations/Expo.cpp

Binary file not shown.

View File

@ -0,0 +1 @@
Linear.o: src/equations/Linear.cpp

Binary file not shown.

View File

@ -0,0 +1 @@
Quad.o: src/equations/Quad.cpp

Binary file not shown.

View File

@ -0,0 +1 @@
Quart.o: src/equations/Quart.cpp

Binary file not shown.

View File

@ -0,0 +1 @@
Quint.o: src/equations/Quint.cpp

Binary file not shown.

View File

@ -0,0 +1 @@
Sine.o: src/equations/Sine.cpp

Binary file not shown.

View File

@ -0,0 +1 @@
CatmullRom.o: src/paths/CatmullRom.cpp

Binary file not shown.

View File

@ -0,0 +1 @@
LinearPath.o: src/paths/LinearPath.cpp

Binary file not shown.

View File

@ -0,0 +1,172 @@
//
// BaseTween.h
//
// This code is derived from Universal Tween Engine
// Licensed under Apache License 2.0 - http://www.apache.org/licenses/LICENSE-2.0
//
/**
* BaseTween is the base class of Tween and Timeline. It defines the
* iteration engine used to play animations for any number of times, and in
* any direction, at any speed.
* <p/>
*
* It is responsible for calling the different callbacks at the right moments,
* and for making sure that every callbacks are triggered, even if the update
* engine gets a big delta time at once.
*
* @see Tween
* @see Timeline
* @author Aurelien Ribon | http://www.aurelienribon.com/
*/
#ifndef __BaseTween__
#define __BaseTween__
#include <functional>
#include <map>
#include <TweenEngine/TweenCallback.h>
namespace TweenEngine
{
class TweenManager;
typedef std::function<void(BaseTween* source)> TweenCallbackFunction;
class BaseTween
{
private:
// General
int step;
int repeatCnt;
bool isIterationStep;
bool isYoyoFlag;
// Timings
float repeatDelay;
float currentTime;
float deltaTime;
bool isStartedFlag; // true when the object is started
bool isInitializedFlag; // true after the delay
bool isFinishedFlag; // true when all repetitions are done
bool isKilledFlag; // true if kill() was called
bool isPausedFlag; // true if pause() was called
// Misc
TweenCallback *callback;
int callbackTriggers;
void *userData;
std::map<int, TweenCallbackFunction> callbacks;
// Update
void initialize();
void testRelaunch();
void updateStep();
void testCompletion();
protected:
// Timings
float delayStart;
float duration;
virtual void reset();
virtual void forceStartValues() = 0;
virtual void forceEndValues() = 0;
virtual void initializeOverride();
virtual void updateOverride(int step, int lastStep, bool isIterationStep, float delta);
virtual void forceToStart();
virtual void forceToEnd(float time);
void callCallback(int type);
bool isReverse(int step);
bool isValid(int step);
public:
virtual ~BaseTween() {}
virtual int getTweenCount() = 0;
virtual int getTimelineCount() = 0;
// Package access
bool isAutoRemoveEnabled;
bool isAutoStartEnabled;
virtual BaseTween &build();
BaseTween &start();
BaseTween &start(TweenManager &manager);
BaseTween &delay(float delay);
void kill();
virtual void free();
void pause();
void resume();
BaseTween &repeat(int count, float delay);
BaseTween &repeatYoyo(int count, float delay);
BaseTween &setCallback(TweenCallback *callback);
BaseTween &setCallback(int type, const TweenCallbackFunction& callback);
BaseTween &setCallbackTriggers(int flags);
BaseTween &setUserData(void *data);
// Getters
float getDelay();
float getDuration();
int getRepeatCount();
float getRepeatDelay();
float getFullDuration();
void *getUserData();
int getStep();
float getCurrentTime();
bool isStarted();
bool isInitialized();
bool isFinished();
bool isYoyo();
bool isPaused();
// Update
void update(float delta);
};
}
#endif /* defined(__BaseTween__) */

View File

@ -0,0 +1,100 @@
//
// Pool.h
//
// This code is derived from Universal Tween Engine
// Licensed under Apache License 2.0 - http://www.apache.org/licenses/LICENSE-2.0
//
/**
* A light pool of objects that can be resused to avoid allocation.
* Based on Nathan Sweet pool implementation
*/
#ifndef __Pool__
#define __Pool__
#include <vector>
#include <algorithm>
namespace TweenEngine
{
template<typename T>
class PoolCallback
{
public:
virtual void onPool(T *obj) = 0;
virtual void onUnPool(T *obj) = 0;
};
template<typename T>
class Pool
{
private:
std::vector<T *> objects;
PoolCallback<T> *callback;
protected:
virtual ~Pool() {}
virtual T *create()=0;
public:
Pool(int initCapacity, PoolCallback<T> *callback);
T *get();
void free(T *obj);
void clear();
int size();
void ensureCapacity(int minCapacity);
};
// Implementation
template <typename T>
Pool<T>::Pool(int initCapacity, PoolCallback<T> *cb) : objects(initCapacity), callback(cb)
{
}
template <typename T>
T *Pool<T>::get()
{
T *obj = nullptr;
if (objects.empty())
{
obj = create();
}
else
{
obj = objects.back();
objects.pop_back();
if (obj == nullptr) obj = create();
}
if (callback != nullptr) callback->onUnPool(obj);
return obj;
}
template <typename T>
void Pool<T>::free(T *obj)
{
if (obj == nullptr) return;
bool contains = (std::find(objects.begin(), objects.end(), obj) != objects.end());
if (!contains)
{
if (callback != nullptr) callback->onPool(obj);
objects.push_back(obj);
}
}
template <typename T>
void Pool<T>::clear() { objects.clear(); }
template <typename T>
int Pool<T>::size() { return objects.size(); }
template <typename T>
void Pool<T>::ensureCapacity(int minCapacity) { objects.reserve(minCapacity); }
}
#endif /* defined(__Pool__) */

View File

@ -0,0 +1,116 @@
//
// Tween.h
//
// This code is derived from Universal Tween Engine
// Licensed under Apache License 2.0 - http://www.apache.org/licenses/LICENSE-2.0
//
#ifndef __Tween__
#define __Tween__
#include <TweenEngine/Tweenable.h>
#include <TweenEngine/BaseTween.h>
#include <TweenEngine/Pool.h>
#include <TweenEngine/TweenEquation.h>
#include <TweenEngine/TweenPath.h>
#include <TweenEngine/TweenEquations.h>
#include <TweenEngine/TweenPaths.h>
namespace TweenEngine
{
class TweenPool;
class TweenPoolCallback;
class Tween : public BaseTween
{
friend class TweenPoolCallback;
private:
static int combinedAttrsLimit;
static int waypointsLimit;
// Main
Tweenable *targetObj;
int type;
TweenEquation *equation;
TweenPath *pathAlgorithm;
// General
bool isFrom;
bool isRelative;
int combinedAttrsCnt;
int waypointsCnt;
// Values
float* startValues;
float* targetValues;
float* waypoints;
// Buffers
float *accessorBuffer;
int accessorBufferSize;
float *pathBuffer;
int pathBufferSize;
//static TweenPoolCallback *poolCallback;
static TweenPool &pool;
void setup(Tweenable *target, int tweenType, float duration);
protected:
virtual void reset();
virtual void forceStartValues();
virtual void forceEndValues();
virtual void initializeOverride();
virtual void updateOverride(int step, int lastStep, bool isIterationStep, float delta);
public:
static const int ACCESSOR_READ = 0;
static const int ACCESSOR_WRITE = 1;
static void setCombinedAttributesLimit(int limit);
static void setWaypointsLimit(int limit);
static const char *getVersion();
static int getPoolSize();
static void ensurePoolCapacity(int minCapacity);
static Tween &to(Tweenable& target, int tweenType, float duration);
static Tween &from(Tweenable& target, int tweenType, float duration);
static Tween &set(Tweenable& target, int tweenType);
static Tween &call(TweenCallback &callback);
static Tween &mark();
Tween();
~Tween();
virtual int getTweenCount();
virtual int getTimelineCount();
virtual Tween &build();
virtual void free();
Tween &ease(TweenEquation &easeEquation);
Tween &target(float targetValue);
Tween &target(float targetValue1, float targetValue2);
Tween &target(float targetValue1, float targetValue2, float targetValue3);
Tween &target(float *targetValues, int len);
Tween &targetRelative(float targetValue);
Tween &targetRelative(float targetValue1, float targetValue2);
Tween &targetRelative(float targetValue1, float targetValue2, float targetValue3);
Tween &targetRelative(float *targetValues, int len);
Tween &waypoint(float targetValue);
Tween &waypoint(float targetValue1, float targetValue2);
Tween &waypoint(float targetValue1, float targetValue2, float targetValue3);
Tween &waypoint(float *targetValues, int len);
Tween &path(TweenPath &path);
int getType();
TweenEquation *getEasing();
float *getTargetValues();
int getCombinedAttributesCount();
};
}
#endif /* defined(__Tween__) */

View File

@ -0,0 +1,103 @@
//
// TweenAccessor.h
//
// This code is derived from Universal Tween Engine
// Licensed under Apache License 2.0 - http://www.apache.org/licenses/LICENSE-2.0
//
/**
* The TweenAccessor interface lets you interpolate any attribute from any
* object. Just implement it as you want and register it to the engine by
* calling {@link Tween#registerAccessor}.
* <p/>
*
* <h2>Example</h2>
*
* The following code snippet presents an example of implementation for tweening
* a Particle class. This Particle class is supposed to only define a position
* with an "x" and an "y" fields, and their associated getters and setters.
* <p/>
*
* <pre> {@code
* public class ParticleAccessor implements TweenAccessor<Particle> {
* public static final int X = 1;
* public static final int Y = 2;
* public static final int XY = 3;
*
* public int getValues(Particle target, int tweenType, float[] returnValues) {
* switch (tweenType) {
* case X: returnValues[0] = target.getX(); return 1;
* case Y: returnValues[0] = target.getY(); return 1;
* case XY:
* returnValues[0] = target.getX();
* returnValues[1] = target.getY();
* return 2;
* default: assert false; return 0;
* }
* }
*
* public void setValues(Particle target, int tweenType, float[] newValues) {
* switch (tweenType) {
* case X: target.setX(newValues[0]); break;
* case Y: target.setY(newValues[1]); break;
* case XY:
* target.setX(newValues[0]);
* target.setY(newValues[1]);
* break;
* default: assert false; break;
* }
* }
* }
* }</pre>
*
* Once done, you only need to register this TweenAccessor once to be able to
* use it for every Particle objects in your application:
* <p/>
*
* <pre> {@code
* Tween.registerAccessor(Particle.class, new ParticleAccessor());
* }</pre>
*
* And that's all, the Tween Engine can no work with all your particles!
*
* @author Aurelien Ribon | http://www.aurelienribon.com/
*/
#ifndef __TweenAccessor__
#define __TweenAccessor__
namespace TweenEngine
{
template<class T>
class TweenAccessor
{
public:
virtual ~TweenAccessor() {}
/**
* Gets one or many values from the target object associated to the
* given tween type. It is used by the Tween Engine to determine starting
* values.
*
* @param target The target object of the tween.
* @param tweenType An integer representing the tween type.
* @param returnValues An array which should be modified by this method.
* @return The count of modified slots from the returnValues array.
*/
virtual int getValues(T& target, int tweenType, float *returnValues) = 0;
/**
* This method is called by the Tween Engine each time a running tween
* associated with the current target object has been updated.
*
* @param target The target object of the tween.
* @param tweenType An integer representing the tween type.
* @param newValues The new values determined by the Tween Engine.
*/
virtual void setValues(T& target, int tweenType, float *newValues) = 0;
};
}
#endif /* defined(__TweenAccessor__) */

View File

@ -0,0 +1,65 @@
//
// TweenCallback.h
//
// This code is derived from Universal Tween Engine
// Licensed under Apache License 2.0 - http://www.apache.org/licenses/LICENSE-2.0
//
/**
* TweenCallbacks are used to trigger actions at some specific times. They are
* used in both Tweens and Timelines. The moment when the callback is
* triggered depends on its registered triggers:
* <p/>
*
* <b>BEGIN</b>: right after the delay (if any)<br/>
* <b>START</b>: at each iteration beginning<br/>
* <b>END</b>: at each iteration ending, before the repeat delay<br/>
* <b>COMPLETE</b>: at last END event<br/>
* <b>BACK_BEGIN</b>: at the beginning of the first backward iteration<br/>
* <b>BACK_START</b>: at each backward iteration beginning, after the repeat delay<br/>
* <b>BACK_END</b>: at each backward iteration ending<br/>
* <b>BACK_COMPLETE</b>: at last BACK_END event
* <p/>
*
* <pre> {@code
* forward : BEGIN COMPLETE
* forward : START END START END START END
* |--------------[XXXXXXXXXX]------[XXXXXXXXXX]------[XXXXXXXXXX]
* backward: bEND bSTART bEND bSTART bEND bSTART
* backward: bCOMPLETE bBEGIN
* }</pre>
*
* @see Tween
* @see Timeline
* @author Aurelien Ribon | http://www.aurelienribon.com/
*/
#ifndef __TweenCallback__
#define __TweenCallback__
namespace TweenEngine
{
class BaseTween;
class TweenCallback
{
public:
static const int BEGIN = 0x01;
static const int START = 0x02;
static const int END = 0x04;
static const int COMPLETE = 0x08;
static const int BACK_BEGIN = 0x10;
static const int BACK_START = 0x20;
static const int BACK_END = 0x40;
static const int BACK_COMPLETE = 0x80;
static const int ANY_FORWARD = 0x0F;
static const int ANY_BACKWARD = 0xF0;
static const int ANY = 0xFF;
virtual ~TweenCallback() {}
virtual void onEvent(int type, BaseTween *source) = 0;
};
}
#endif /* defined(__TweenCallback__) */

View File

@ -0,0 +1,46 @@
//
// TweenEquation.h
//
// This code is derived from Universal Tween Engine
// Licensed under Apache License 2.0 - http://www.apache.org/licenses/LICENSE-2.0
//
/**
* Base class for every easing equation. You can create your own equations
* and directly use them in the Tween engine by inheriting from this class.
*
* @see Tween
* @author Aurelien Ribon | http://www.aurelienribon.com/
*/
#ifndef __TweenEquation__
#define __TweenEquation__
//#include <string.h>
namespace TweenEngine
{
class TweenEquation
{
public:
/**
* Computes the next value of the interpolation.
*
* @param t The current time, between 0 and 1.
* @return The current value.
*/
virtual float compute(float t) = 0;
virtual const char *toString() = 0;
/**
* Returns true if the given string is the name of this equation (the name
* is returned in the toString() method, don't forget to override it).
* This method is usually used to save/load a tween to/from a text file.
*/
//bool isValueOf(const char *str) { return !strcmp(str, toString()); };
};
}
#endif /* defined(__TweenEquation__) */

View File

@ -0,0 +1,63 @@
//
// TweenEquations.h
//
// This code is derived from Universal Tween Engine
// Licensed under Apache License 2.0 - http://www.apache.org/licenses/LICENSE-2.0
//
#ifndef __TweenEquations__
#define __TweenEquations__
#include <TweenEngine/equations/Quad.h>
#include <TweenEngine/equations/Linear.h>
#include <TweenEngine/equations/Back.h>
#include <TweenEngine/equations/Bounce.h>
#include <TweenEngine/equations/Circ.h>
#include <TweenEngine/equations/Cubic.h>
#include <TweenEngine/equations/Elastic.h>
#include <TweenEngine/equations/Expo.h>
#include <TweenEngine/equations/Quart.h>
#include <TweenEngine/equations/Quint.h>
#include <TweenEngine/equations/Sine.h>
namespace TweenEngine
{
class TweenEquations
{
public:
static TweenEquation &easeInQuad;
static TweenEquation &easeOutQuad;
static TweenEquation &easeInOutQuad;
static TweenEquation &easeInOutLinear;
static TweenEquation &easeInBack;
static TweenEquation &easeOutBack;
static TweenEquation &easeInOutBack;
static TweenEquation &easeInBounce;
static TweenEquation &easeOutBounce;
static TweenEquation &easeInOutBounce;
static TweenEquation &easeInCirc;
static TweenEquation &easeOutCirc;
static TweenEquation &easeInOutCirc;
static TweenEquation &easeInCubic;
static TweenEquation &easeOutCubic;
static TweenEquation &easeInOutCubic;
static TweenEquation &easeInElastic;
static TweenEquation &easeOutElastic;
static TweenEquation &easeInOutElastic;
static TweenEquation &easeInExpo;
static TweenEquation &easeOutExpo;
static TweenEquation &easeInOutExpo;
static TweenEquation &easeInQuart;
static TweenEquation &easeOutQuart;
static TweenEquation &easeInOutQuart;
static TweenEquation &easeInQuint;
static TweenEquation &easeOutQuint;
static TweenEquation &easeInOutQuint;
static TweenEquation &easeInSine;
static TweenEquation &easeOutSine;
static TweenEquation &easeInOutSine;
};
}
#endif /* defined(__TweenEquations__) */

View File

@ -0,0 +1,61 @@
//
// TweenManager.h
//
// This code is derived from Universal Tween Engine
// Licensed under Apache License 2.0 - http://www.apache.org/licenses/LICENSE-2.0
//
/**
* A TweenManager updates all your tweens and timelines at once.
* Its main interest is that it handles the tween/timeline life-cycles for you,
* as well as the pooling constraints (if object pooling is enabled).
* <p/>
*
* Just give it a bunch of tweens or timelines and call update() periodically,
* you don't need to care for anything else! Relax and enjoy your animations.
*
* @see Tween
* @see Timeline
* @author Aurelien Ribon | http://www.aurelienribon.com/
*/
#ifndef __TweenManager__
#define __TweenManager__
#include <algorithm>
#include <vector>
#include <TweenEngine/BaseTween.h>
namespace TweenEngine
{
class TweenManager
{
private:
std::vector<BaseTween *>objects;
bool isPaused = false;
public:
TweenManager();
static void setAutoRemove(BaseTween &object, bool value);
static void setAutoStart(BaseTween &object, bool value);
TweenManager &add(BaseTween &object);
void killAll();
void ensureCapacity(int minCapacity);
void pause();
void resume();
void update(float delta);
int size();
// Debug Helpers
int getRunningTweensCount();
int getRunningTimelinesCount();
std::vector<BaseTween *> &getObjects();
};
}
#endif /* defined(__TweenManager__) */

View File

@ -0,0 +1,37 @@
//
// TweenPath.h
//
// This code is derived from Universal Tween Engine
// Licensed under Apache License 2.0 - http://www.apache.org/licenses/LICENSE-2.0
//
/**
* Base class for every paths. You can create your own paths and directly use
* them in the Tween engine by inheriting from this class.
*
* @author Aurelien Ribon | http://www.aurelienribon.com/
*/
#ifndef __TweenPath__
#define __TweenPath__
namespace TweenEngine
{
class TweenPath
{
public:
/**
* Computes the next value of the interpolation, based on its waypoints and
* the current progress.
*
* @param t The progress of the interpolation, between 0 and 1. May be out
* of these bounds if the easing equation involves some kind of rebounds.
* @param points The waypoints of the tween, from start to target values.
* @param pointsCnt The number of valid points in the array.
* @return The next value of the interpolation.
*/
virtual float compute(float t, float *points, int pointsCnt) = 0;
};
}
#endif /* defined(__TweenPath__) */

View File

@ -0,0 +1,23 @@
//
// TweenPaths.h
//
// This code is derived from Universal Tween Engine
// Licensed under Apache License 2.0 - http://www.apache.org/licenses/LICENSE-2.0
//
#ifndef __TweenPaths__
#define __TweenPaths__
#include <TweenEngine/TweenPath.h>
namespace TweenEngine
{
class TweenPaths
{
public:
static TweenPath &linear;
static TweenPath &catmullRom;
};
}
#endif /* defined(__TweenPaths__) */

View File

@ -0,0 +1,32 @@
//
// TweenPool.h
//
// This code is derived from Universal Tween Engine
// Licensed under Apache License 2.0 - http://www.apache.org/licenses/LICENSE-2.0
//
#ifndef __TweenPool__
#define __TweenPool__
#include <TweenEngine/Pool.h>
#include <TweenEngine/Tween.h>
namespace TweenEngine
{
class TweenPoolCallback : public PoolCallback<Tween>
{
public:
void onPool(Tween *obj);
void onUnPool(Tween *obj);
};
class TweenPool : public Pool<Tween>
{
protected:
Tween *create();
public:
TweenPool();
};
}
#endif /* defined(__TweenPool__) */

View File

@ -0,0 +1,12 @@
#ifndef __Tweenable__
#define __Tweenable__
namespace TweenEngine {
class Tweenable {
public:
virtual int getValues(int tweenType, float *returnValues) = 0;
virtual void setValues(int tweenType, float *newValues) = 0;
};
}
#endif

View File

@ -0,0 +1,37 @@
//
// Back.h
//
// This code is derived from Universal Tween Engine
// Licensed under Apache License 2.0 - http://www.apache.org/licenses/LICENSE-2.0
//
#ifndef __Back__
#define __Back__
#include <TweenEngine/TweenEquation.h>
namespace TweenEngine
{
class BackIn : public TweenEquation
{
~BackIn();
float compute(float t);
const char *toString();
};
class BackOut : public TweenEquation
{
~BackOut();
float compute(float t);
const char *toString();
};
class BackInOut : public TweenEquation
{
~BackInOut();
float compute(float t);
const char *toString();
};
}
#endif /* defined(__Back__) */

View File

@ -0,0 +1,38 @@
//
// Bounce.h
//
// This code is derived from Universal Tween Engine
// Licensed under Apache License 2.0 - http://www.apache.org/licenses/LICENSE-2.0
//
#ifndef __Bounce__
#define __Bounce__
#include <TweenEngine/TweenEquation.h>
namespace TweenEngine
{
class BounceIn : public TweenEquation
{
~BounceIn();
float compute(float t);
const char *toString();
};
class BounceOut : public TweenEquation
{
~BounceOut();
float compute(float t);
const char *toString();
};
class BounceInOut : public TweenEquation
{
~BounceInOut();
float compute(float t);
const char *toString();
};
}
#endif /* defined(__Bounce__) */

View File

@ -0,0 +1,37 @@
//
// Circ.h
//
// This code is derived from Universal Tween Engine
// Licensed under Apache License 2.0 - http://www.apache.org/licenses/LICENSE-2.0
//
#ifndef __Circ__
#define __Circ__
#include <TweenEngine/TweenEquation.h>
namespace TweenEngine
{
class CircIn : public TweenEquation
{
~CircIn();
float compute(float t);
const char *toString();
};
class CircOut : public TweenEquation
{
~CircOut();
float compute(float t);
const char *toString();
};
class CircInOut : public TweenEquation
{
~CircInOut();
float compute(float t);
const char *toString();
};
}
#endif /* defined(__Circ__) */

View File

@ -0,0 +1,37 @@
//
// Cubic.h
//
// This code is derived from Universal Tween Engine
// Licensed under Apache License 2.0 - http://www.apache.org/licenses/LICENSE-2.0
//
#ifndef __Cubic__
#define __Cubic__
#include <TweenEngine/TweenEquation.h>
namespace TweenEngine
{
class CubicIn : public TweenEquation
{
~CubicIn();
float compute(float t);
const char *toString();
};
class CubicOut : public TweenEquation
{
~CubicOut();
float compute(float t);
const char *toString();
};
class CubicInOut : public TweenEquation
{
~CubicInOut();
float compute(float t);
const char *toString();
};
}
#endif /* defined(__Cubic__) */

View File

@ -0,0 +1,61 @@
//
// Elastic.h
//
// This code is derived from Universal Tween Engine
// Licensed under Apache License 2.0 - http://www.apache.org/licenses/LICENSE-2.0
//
#ifndef __Elastic__
#define __Elastic__
#include <TweenEngine/TweenEquation.h>
namespace TweenEngine
{
class ElasticIn : public TweenEquation
{
private:
float amplitude;
float period;
bool isAmplitudeSet;
bool isPeriodSet;
public:
~ElasticIn();
float compute(float t);
const char *toString();
void setAmplitude(float a);
void setPeriod(float p);
};
class ElasticOut : public TweenEquation
{
private:
float amplitude;
float period;
bool isAmplitudeSet;
bool isPeriodSet;
public:
~ElasticOut();
float compute(float t);
const char *toString();
void setAmplitude(float a);
void setPeriod(float p);
};
class ElasticInOut : public TweenEquation
{
private:
float amplitude;
float period;
bool isAmplitudeSet;
bool isPeriodSet;
public:
~ElasticInOut();
float compute(float t);
const char *toString();
void setAmplitude(float a);
void setPeriod(float p);
};
}
#endif /* defined(__Elastic__) */

View File

@ -0,0 +1,37 @@
//
// Expo.h
//
// This code is derived from Universal Tween Engine
// Licensed under Apache License 2.0 - http://www.apache.org/licenses/LICENSE-2.0
//
#ifndef __Expo__
#define __Expo__
#include <TweenEngine/TweenEquation.h>
namespace TweenEngine
{
class ExpoIn : public TweenEquation
{
~ExpoIn();
float compute(float t);
const char *toString();
};
class ExpoOut : public TweenEquation
{
~ExpoOut();
float compute(float t);
const char *toString();
};
class ExpoInOut : public TweenEquation
{
~ExpoInOut();
float compute(float t);
const char *toString();
};
}
#endif /* defined(__Expo__) */

View File

@ -0,0 +1,24 @@
//
// Linear.h
//
// This code is derived from Universal Tween Engine
// Licensed under Apache License 2.0 - http://www.apache.org/licenses/LICENSE-2.0
//
#ifndef __Linear__
#define __Linear__
#include <TweenEngine/TweenEquation.h>
namespace TweenEngine
{
class LinearInOut : public TweenEquation
{
~LinearInOut();
float compute(float t);
const char *toString();
};
}
#endif /* defined(__Linear__) */

View File

@ -0,0 +1,37 @@
//
// Quad.h
//
// This code is derived from Universal Tween Engine
// Licensed under Apache License 2.0 - http://www.apache.org/licenses/LICENSE-2.0
//
#ifndef __Quad__
#define __Quad__
#include <TweenEngine/TweenEquation.h>
namespace TweenEngine
{
class QuadIn : public TweenEquation
{
~QuadIn();
float compute(float t);
const char *toString();
};
class QuadOut : public TweenEquation
{
~QuadOut();
float compute(float t);
const char *toString();
};
class QuadInOut : public TweenEquation
{
~QuadInOut();
float compute(float t);
const char *toString();
};
}
#endif /* defined(__Quad__) */

View File

@ -0,0 +1,37 @@
//
// Quart.h
//
// This code is derived from Universal Tween Engine
// Licensed under Apache License 2.0 - http://www.apache.org/licenses/LICENSE-2.0
//
#ifndef __Quart__
#define __Quart__
#include <TweenEngine/TweenEquation.h>
namespace TweenEngine
{
class QuartIn : public TweenEquation
{
~QuartIn();
float compute(float t);
const char *toString();
};
class QuartOut : public TweenEquation
{
~QuartOut();
float compute(float t);
const char *toString();
};
class QuartInOut : public TweenEquation
{
~QuartInOut();
float compute(float t);
const char *toString();
};
}
#endif /* defined(__Quart__) */

View File

@ -0,0 +1,37 @@
//
// Quint.h
//
// This code is derived from Universal Tween Engine
// Licensed under Apache License 2.0 - http://www.apache.org/licenses/LICENSE-2.0
//
#ifndef __Quint__
#define __Quint__
#include <TweenEngine/TweenEquation.h>
namespace TweenEngine
{
class QuintIn : public TweenEquation
{
~QuintIn();
float compute(float t);
const char *toString();
};
class QuintOut : public TweenEquation
{
~QuintOut();
float compute(float t);
const char *toString();
};
class QuintInOut : public TweenEquation
{
~QuintInOut();
float compute(float t);
const char *toString();
};
}
#endif /* defined(__Quint__) */

View File

@ -0,0 +1,37 @@
//
// Sine.h
//
// This code is derived from Universal Tween Engine
// Licensed under Apache License 2.0 - http://www.apache.org/licenses/LICENSE-2.0
//
#ifndef __Sine__
#define __Sine__
#include <TweenEngine/TweenEquation.h>
namespace TweenEngine
{
class SineIn : public TweenEquation
{
~SineIn();
float compute(float t);
const char *toString();
};
class SineOut : public TweenEquation
{
~SineOut();
float compute(float t);
const char *toString();
};
class SineInOut : public TweenEquation
{
~SineInOut();
float compute(float t);
const char *toString();
};
}
#endif /* defined(__Sine__) */

View File

@ -0,0 +1,22 @@
//
// CatmullRom.h
//
// This code is derived from Universal Tween Engine
// Licensed under Apache License 2.0 - http://www.apache.org/licenses/LICENSE-2.0
//
#ifndef __CatmullRom__
#define __CatmullRom__
#include <TweenEngine/TweenPath.h>
namespace TweenEngine
{
class CatmullRom : public TweenPath
{
float compute(float t, float *points, int pointsCnt);
float catmullRomSpline(float a, float b, float c, float d, float t);
};
}
#endif /* defined(__CatmullRom__) */

View File

@ -0,0 +1,21 @@
//
// Linear.h
//
// This code is derived from Universal Tween Engine
// Licensed under Apache License 2.0 - http://www.apache.org/licenses/LICENSE-2.0
//
#ifndef __LinearPath__
#define __LinearPath__
#include <TweenEngine/TweenPath.h>
namespace TweenEngine
{
class LinearPath : public TweenPath
{
float compute(float t, float *points, int pointsCnt);
};
}
#endif /* defined(__LinearPath__) */

BIN
external/tween-engine/lib/libtween.a vendored Normal file

Binary file not shown.

525
external/tween-engine/src/BaseTween.cpp vendored Normal file
View File

@ -0,0 +1,525 @@
//
// BaseTween.cpp
//
// This code is derived from Universal Tween Engine
// Licensed under Apache License 2.0 - http://www.apache.org/licenses/LICENSE-2.0
//
//#define NDEBUG
#include <TweenEngine/BaseTween.h>
#include <TweenEngine/TweenManager.h>
namespace TweenEngine
{
void BaseTween::reset()
{
step = -2;
repeatCnt = 0;
isIterationStep = isYoyoFlag = false;
delayStart = duration = repeatDelay = currentTime = deltaTime = 0;
isStartedFlag = isInitializedFlag = isFinishedFlag = isKilledFlag = isPausedFlag = false;
callback = nullptr;
callbackTriggers = TweenCallback::COMPLETE;
userData = nullptr;
callbacks.clear();
isAutoRemoveEnabled = isAutoStartEnabled = true;
}
// API
/**
* Builds and validates the object. Only needed if you want to finalize a
* tween or timeline without starting it, since a call to ".start()" also
* calls this method.
*
* @return The current object, for chaining instructions.
*/
BaseTween &BaseTween::build()
{
return *this;
}
/**
* Starts or restarts the object unmanaged. You will need to take care of
* its life-cycle. If you want the tween to be managed for you, use a
* {@link TweenManager}.
*
* @return The current object, for chaining instructions.
*/
BaseTween &BaseTween::start()
{
build();
currentTime = 0;
isStartedFlag = true;
return *this;
}
/**
* Convenience method to add an object to a manager. Its life-cycle will be
* handled for you. Relax and enjoy the animation.
*
* @return The current object, for chaining instructions.
*/
BaseTween &BaseTween::start(TweenManager &manager) {
manager.add(*this);
return *this;
}
/**
* Adds a delay to the tween or timeline.
*
* @param delay A duration.
* @return The current object, for chaining instructions.
*/
BaseTween &BaseTween::delay(float delay)
{
this->delayStart += delay;
return *this;
}
/**
* Kills the tween or timeline. If you are using a TweenManager, this object
* will be removed automatically.
*/
void BaseTween::kill()
{
isKilledFlag = true;
}
/**
* Stops and resets the tween or timeline, and sends it to its pool, for
+ * later reuse. Note that if you use a {@link TweenManager}, this method
+ * is automatically called once the animation is finished.
*/
void BaseTween::free()
{
}
/**
* Pauses the tween or timeline. Further update calls won't have any effect.
*/
void BaseTween::pause()
{
isPausedFlag = true;
}
/**
* Resumes the tween or timeline. Has no effect is it was no already paused.
*/
void BaseTween::resume()
{
isPausedFlag = false;
}
/**
* Repeats the tween or timeline for a given number of times.
* @param count The number of repetitions. For infinite repetition,
* use Tween.INFINITY, or a negative number.
*
* @param delay A delay between each iteration.
* @return The current tween or timeline, for chaining instructions.
*/
BaseTween &BaseTween::repeat(int count, float delay)
{
if (isStartedFlag)
{
//throw new RuntimeException("You can't change the repetitions of a tween or timeline once it is started");
}
else
{
repeatCnt = count;
repeatDelay = delay >= 0 ? delay : 0;
isYoyoFlag = false;
}
return *this;
}
/**
* Repeats the tween or timeline for a given number of times.
* Every two iterations, it will be played backwards.
*
* @param count The number of repetitions. For infinite repetition,
* use Tween.INFINITY, or '-1'.
* @param delay A delay before each repetition.
* @return The current tween or timeline, for chaining instructions.
*/
BaseTween &BaseTween::repeatYoyo(int count, float delay)
{
if (isStartedFlag)
{
//throw new RuntimeException("You can't change the repetitions of a tween or timeline once it is started");
}
else
{
repeatCnt = count;
repeatDelay = delay >= 0 ? delay : 0;
isYoyoFlag = true;
}
return *this;
}
/**
* Sets the callback. By default, it will be fired at the completion of the
* tween or timeline (event COMPLETE). If you want to change this behavior
* and add more triggers, use the {@link setCallbackTriggers()} method.
*
* @see TweenCallback
*/
BaseTween &BaseTween::setCallback(TweenCallback *callback)
{
this->callback = callback;
return *this;
}
BaseTween &BaseTween::setCallback(int type, const TweenCallbackFunction& callback)
{
callbacks[type] = callback;
return *this;
}
/**
* Changes the triggers of the callback. The available triggers, listed as
* members of the {@link TweenCallback} interface, are:
* <p/>
*
* <b>BEGIN</b>: right after the delay (if any)<br/>
* <b>START</b>: at each iteration beginning<br/>
* <b>END</b>: at each iteration ending, before the repeat delay<br/>
* <b>COMPLETE</b>: at last END event<br/>
* <b>BACK_BEGIN</b>: at the beginning of the first backward iteration<br/>
* <b>BACK_START</b>: at each backward iteration beginning, after the repeat delay<br/>
* <b>BACK_END</b>: at each backward iteration ending<br/>
* <b>BACK_COMPLETE</b>: at last BACK_END event
* <p/>
*
* <pre> {@code
* forward : BEGIN COMPLETE
* forward : START END START END START END
* |--------------[XXXXXXXXXX]------[XXXXXXXXXX]------[XXXXXXXXXX]
* backward: bEND bSTART bEND bSTART bEND bSTART
* backward: bCOMPLETE bBEGIN
* }</pre>
*
* @param flags one or more triggers, separated by the '|' operator.
* @see TweenCallback
*/
BaseTween &BaseTween::setCallbackTriggers(int flags)
{
this->callbackTriggers = flags;
return *this;
}
/**
* Attaches an object to this tween or timeline. It can be useful in order
* to retrieve some data from a TweenCallback.
*
* @param data Any kind of object.
* @return The current tween or timeline, for chaining instructions.
*/
BaseTween &BaseTween::setUserData(void *data)
{
userData = data;
return *this;
}
// -------------------------------------------------------------------------
// Getters
// -------------------------------------------------------------------------
/**
* Gets the delay of the tween or timeline. Nothing will happen before
* this delay.
*/
float BaseTween::getDelay() { return delayStart; }
/**
* Gets the duration of a single iteration.
*/
float BaseTween::getDuration() { return duration; }
/**
* Gets the number of iterations that will be played.
*/
int BaseTween::getRepeatCount() { return repeatCnt; }
/**
* Gets the delay occuring between two iterations.
*/
float BaseTween::getRepeatDelay() { return repeatDelay; }
/**
* Returns the complete duration, including initial delay and repetitions.
* The formula is as follows:
* <pre>
* fullDuration = delay + duration + (repeatDelay + duration) * repeatCnt
* </pre>
*/
float BaseTween::getFullDuration()
{
if (repeatCnt < 0) return -1;
return delayStart + duration + (repeatDelay + duration) * repeatCnt;
}
/**
* Gets the attached data, or null if none.
*/
void *BaseTween::getUserData() { return userData; }
/**
* Gets the id of the current step. Values are as follows:<br/>
* <ul>
* <li>even numbers mean that an iteration is playing,<br/>
* <li>odd numbers mean that we are between two iterations,<br/>
* <li>-2 means that the initial delay has not ended,<br/>
* <li>-1 means that we are before the first iteration,<br/>
* <li>repeatCount*2 + 1 means that we are after the last iteration
*/
int BaseTween::getStep() { return step; }
/**
* Gets the local time.
*/
float BaseTween::getCurrentTime() { return currentTime; }
/**
* Returns true if the tween or timeline has been started.
*/
bool BaseTween::isStarted() { return isStartedFlag; }
/**
* Returns true if the tween or timeline has been initialized. Starting
* values for tweens are stored at initialization time. This initialization
* takes place right after the initial delay, if any.
*/
bool BaseTween::isInitialized() { return isInitializedFlag; }
/**
* Returns true if the tween is finished (i.e. if the tween has reached
* its end or has been killed). If you don't use a TweenManager, you may
* want to call {@link free()} to reuse the object later.
*/
bool BaseTween::isFinished() { return isFinishedFlag || isKilledFlag; }
/**
* Returns true if the iterations are played as yoyo. Yoyo means that
* every two iterations, the animation will be played backwards.
*/
bool BaseTween::isYoyo() { return isYoyoFlag; }
/**
* Returns true if the tween or timeline is currently paused.
*/
bool BaseTween::isPaused() { return isPausedFlag; }
void BaseTween::initializeOverride() {}
void BaseTween::updateOverride(int step, int lastStep, bool isIterationStep, float delta) {}
void BaseTween::forceToStart()
{
currentTime = -delayStart;
step = -1;
isIterationStep = false;
if (isReverse(0)) forceEndValues();
else forceStartValues();
}
void BaseTween::forceToEnd(float time)
{
currentTime = time - getFullDuration();
step = repeatCnt*2 + 1;
isIterationStep = false;
if (isReverse(repeatCnt*2)) forceStartValues();
else forceEndValues();
}
void BaseTween::callCallback(int type)
{
auto callback = callbacks.find(type);
if (callback != callbacks.end()) {
callback->second(this);
}
// if (callback != nullptr && (callbackTriggers & type) > 0) callback->onEvent(type, this);
}
bool BaseTween::isReverse(int step)
{
return isYoyoFlag && abs(step%4) == 2;
}
bool BaseTween::isValid(int step)
{
return (step >= 0 && step <= repeatCnt*2) || repeatCnt < 0;
}
// -------------------------------------------------------------------------
// Update engine
// -------------------------------------------------------------------------
/**
* Updates the tween or timeline state. <b>You may want to use a
* TweenManager to update objects for you.</b>
*
* Slow motion, fast motion and backward play can be easily achieved by
* tweaking this delta time. Multiply it by -1 to play the animation
* backward, or by 0.5 to play it twice slower than its normal speed.
*
* @param delta A delta time between now and the last call.
*/
void BaseTween::update(float delta)
{
if (!isStartedFlag || isPausedFlag || isKilledFlag) return;
deltaTime = delta;
if (!isInitializedFlag) initialize();
if (isInitializedFlag)
{
testRelaunch();
updateStep();
testCompletion();
}
currentTime += deltaTime;
deltaTime = 0;
}
void BaseTween::initialize() {
if (currentTime+deltaTime >= delayStart)
{
initializeOverride();
isInitializedFlag = true;
isIterationStep = true;
step = 0;
deltaTime -= delayStart-currentTime;
currentTime = 0;
callCallback(TweenCallback::BEGIN);
callCallback(TweenCallback::START);
}
}
void BaseTween::testRelaunch()
{
if (!isIterationStep && repeatCnt >= 0 && step < 0 && currentTime+deltaTime >= 0)
{
// assert(step == -1);
isIterationStep = true;
step = 0;
float delta = 0-currentTime;
deltaTime -= delta;
currentTime = 0;
callCallback(TweenCallback::BEGIN);
callCallback(TweenCallback::START);
updateOverride(step, step-1, isIterationStep, delta);
}
else if (!isIterationStep && repeatCnt >= 0 && step > repeatCnt*2 && currentTime+deltaTime < 0)
{
// assert(step == repeatCnt*2 + 1);
isIterationStep = true;
step = repeatCnt*2;
float delta = 0-currentTime;
deltaTime -= delta;
currentTime = duration;
callCallback(TweenCallback::BACK_BEGIN);
callCallback(TweenCallback::BACK_START);
updateOverride(step, step+1, isIterationStep, delta);
}
}
void BaseTween::updateStep()
{
while (isValid(step))
{
if (!isIterationStep && currentTime+deltaTime <= 0)
{
isIterationStep = true;
step -= 1;
float delta = 0-currentTime;
deltaTime -= delta;
currentTime = duration;
if (isReverse(step)) forceStartValues();
else forceEndValues();
callCallback(TweenCallback::BACK_START);
updateOverride(step, step+1, isIterationStep, delta);
}
else if (!isIterationStep && currentTime+deltaTime >= repeatDelay)
{
isIterationStep = true;
step += 1;
float delta = repeatDelay-currentTime;
deltaTime -= delta;
currentTime = 0;
if (isReverse(step)) forceEndValues(); else forceStartValues();
callCallback(TweenCallback::START);
updateOverride(step, step-1, isIterationStep, delta);
}
else if (isIterationStep && currentTime+deltaTime < 0)
{
isIterationStep = false;
step -= 1;
float delta = 0-currentTime;
deltaTime -= delta;
currentTime = 0;
updateOverride(step, step+1, isIterationStep, delta);
callCallback(TweenCallback::BACK_END);
if (step < 0 && repeatCnt >= 0) callCallback(TweenCallback::BACK_COMPLETE);
else currentTime = repeatDelay;
}
else if (isIterationStep && currentTime+deltaTime > duration)
{
isIterationStep = false;
step += 1;
float delta = duration-currentTime;
deltaTime -= delta;
currentTime = duration;
updateOverride(step, step-1, isIterationStep, delta);
callCallback(TweenCallback::END);
if (step > repeatCnt*2 && repeatCnt >= 0) callCallback(TweenCallback::COMPLETE);
currentTime = 0;
}
else if (isIterationStep)
{
float delta = deltaTime;
deltaTime -= delta;
currentTime += delta;
updateOverride(step, step, isIterationStep, delta);
break;
}
else
{
float delta = deltaTime;
deltaTime -= delta;
currentTime += delta;
break;
}
}
}
void BaseTween::testCompletion()
{
isFinishedFlag = repeatCnt >= 0 && (step > repeatCnt*2 || step < 0);
}
}

796
external/tween-engine/src/Tween.cpp vendored Normal file
View File

@ -0,0 +1,796 @@
//
// Tween.cpp
//
// This code is derived from Universal Tween Engine
// Licensed under Apache License 2.0 - http://www.apache.org/licenses/LICENSE-2.0
//
/**
* Core class of the Tween Engine. A Tween is basically an interpolation
* between two values of an object attribute. However, the main interest of a
* Tween is that you can apply an easing formula on this interpolation, in
* order to smooth the transitions or to achieve cool effects like springs or
* bounces.
* <p/>
*
* The Universal Tween Engine is called "universal" because it is able to apply
* interpolations on every attribute from every possible object. Therefore,
* every object in your application can be animated with cool effects: it does
* not matter if your application is a game, a desktop interface or even a
* console program! If it makes sense to animate something, then it can be
* animated through this engine.
* <p/>
*
* This class contains many static factory methods to create and instantiate
* new interpolations easily. The common way to create a Tween is by using one
* of these factories:
* <p/>
*
* - Tween.to(...)<br/>
* - Tween.from(...)<br/>
* - Tween.set(...)<br/>
* - Tween.call(...)
* <p/>
*
* <h2>Example - firing a Tween</h2>
*
* The following example will move the target horizontal position from its
* current value to x=200 and y=300, during 500ms, but only after a delay of
* 1000ms. The animation will also be repeated 2 times (the starting position
* is registered at the end of the delay, so the animation will automatically
* restart from this registered position).
* <p/>
*
* <pre> {@code
* Tween.to(myObject, POSITION_XY, 0.5f)
* .target(200, 300)
* .ease(Quad.INOUT)
* .delay(1.0f)
* .repeat(2, 0.2f)
* .start(myManager);
* }</pre>
*
* Tween life-cycles can be automatically managed for you, thanks to the
* {@link TweenManager} class. If you choose to manage your tween when you start
* it, then you don't need to care about it anymore. <b>Tweens are
* <i>fire-and-forget</i>: don't think about them anymore once you started
* them (if they are managed of course).</b>
* <p/>
*
* You need to periodicaly update the tween engine, in order to compute the new
* values. If your tweens are managed, only update the manager; else you need
* to call {@link #update()} on your tweens periodically.
* <p/>
*
* <h2>Example - setting up the engine</h2>
*
* The engine cannot directly change your objects attributes, since it doesn't
* know them. Therefore, you need to tell him how to get and set the different
* attributes of your objects: <b>you need to implement the {@link
* TweenAccessor} interface for each object class you will animate</b>. Once
* done, don't forget to register these implementations, using the static method
* {@link registerAccessor()}, when you start your application.
*
* @see TweenAccessor
* @see TweenManager
* @see TweenEquation
* @see Timeline
* @author Aurelien Ribon | http://www.aurelienribon.com/
*/
//#define NDEBUG
#include <TweenEngine/Tween.h>
#include <TweenEngine/TweenPool.h>
namespace TweenEngine
{
int Tween::combinedAttrsLimit = 3;
int Tween::waypointsLimit = 0;
/**
* Changes the limit for combined attributes. Defaults to 3 to reduce
* memory footprint.
*/
void Tween::setCombinedAttributesLimit(int limit) { Tween::combinedAttrsLimit = limit; }
/**
* Changes the limit of allowed waypoints for each tween. Defaults to 0 to
* reduce memory footprint.
*/
void Tween::setWaypointsLimit(int limit) { Tween::waypointsLimit = limit; }
/**
* Gets the version number of the library.
*/
const char *Tween::getVersion() { return "6.3.3"; }
/**
* Used for debug purpose. Gets the current number of objects that are
* waiting in the Tween pool.
*/
int Tween::getPoolSize() { return pool.size(); }
/**
* Increases the minimum capacity of the pool. Capacity defaults to 20.
*/
void Tween::ensurePoolCapacity(int minCapacity) { pool.ensureCapacity(minCapacity); }
TweenPool &Tween::pool = *(new TweenPool());
// -------------------------------------------------------------------------
// Static -- factories
// -------------------------------------------------------------------------
/**
* Factory creating a new standard interpolation. This is the most common
* type of interpolation. The starting values are retrieved automatically
* after the delay (if any).
* <br/><br/>
*
* <b>You need to set the target values of the interpolation by using one
* of the target() methods</b>. The interpolation will run from the
* starting values to these target values.
* <br/><br/>
*
* The common use of Tweens is "fire-and-forget": you do not need to care
* for tweens once you added them to a TweenManager, they will be updated
* automatically, and cleaned once finished. Common call:
* <br/><br/>
*
* <pre> {@code
* Tween.to(myObject, POSITION, 1.0f)
* .target(50, 70)
* .ease(Quad.INOUT)
* .start(myManager);
* }</pre>
*
* Several options such as delay, repetitions and callbacks can be added to
* the tween.
*
* @param target The target object of the interpolation.
* @param tweenType The desired type of interpolation.
* @param duration The duration of the interpolation, in milliseconds.
* @return The generated Tween.
*/
Tween &Tween::to(Tweenable& target, int tweenType, float duration)
{
Tween &tween = *(pool.get());
tween.setup(&target, tweenType, duration);
tween.ease(TweenEquations::easeInOutQuad);
tween.path(TweenPaths::catmullRom);
return tween;
}
/**
* Factory creating a new reversed interpolation. The ending values are
* retrieved automatically after the delay (if any).
* <br/><br/>
*
* <b>You need to set the starting values of the interpolation by using one
* of the target() methods</b>. The interpolation will run from the
* starting values to these target values.
* <br/><br/>
*
* The common use of Tweens is "fire-and-forget": you do not need to care
* for tweens once you added them to a TweenManager, they will be updated
* automatically, and cleaned once finished. Common call:
* <br/><br/>
*
* <pre> {@code
* Tween.from(myObject, POSITION, 1.0f)
* .target(0, 0)
* .ease(Quad.INOUT)
* .start(myManager);
* }</pre>
*
* Several options such as delay, repetitions and callbacks can be added to
* the tween.
*
* @param target The target object of the interpolation.
* @param tweenType The desired type of interpolation.
* @param duration The duration of the interpolation, in milliseconds.
* @return The generated Tween.
*/
Tween &Tween::from(Tweenable& target, int tweenType, float duration)
{
Tween &tween = *(pool.get());
tween.setup(&target, tweenType, duration);
tween.ease(TweenEquations::easeInOutQuad);
tween.path(TweenPaths::catmullRom);
tween.isFrom = true;
return tween;
}
/**
* Factory creating a new instantaneous interpolation (thus this is not
* really an interpolation).
* <br/><br/>
*
* <b>You need to set the target values of the interpolation by using one
* of the target() methods</b>. The interpolation will set the target
* attribute to these values after the delay (if any).
* <br/><br/>
*
* The common use of Tweens is "fire-and-forget": you do not need to care
* for tweens once you added them to a TweenManager, they will be updated
* automatically, and cleaned once finished. Common call:
* <br/><br/>
*
* <pre> {@code
* Tween.set(myObject, POSITION)
* .target(50, 70)
* .delay(1.0f)
* .start(myManager);
* }</pre>
*
* Several options such as delay, repetitions and callbacks can be added to
* the tween.
*
* @param target The target object of the interpolation.
* @param tweenType The desired type of interpolation.
* @return The generated Tween.
*/
Tween &Tween::set(Tweenable& target, int tweenType)
{
Tween &tween = *(pool.get());
tween.setup(&target, tweenType, 0);
tween.ease(TweenEquations::easeInOutQuad);
return tween;
}
/**
* Factory creating a new timer. The given callback will be triggered on
* each iteration start, after the delay.
* <br/><br/>
*
* The common use of Tweens is "fire-and-forget": you do not need to care
* for tweens once you added them to a TweenManager, they will be updated
* automatically, and cleaned once finished. Common call:
* <br/><br/>
*
* <pre> {@code
* Tween.call(myCallback)
* .delay(1.0f)
* .repeat(10, 1000)
* .start(myManager);
* }</pre>
*
* @param callback The callback that will be triggered on each iteration
* start.
* @return The generated Tween.
* @see TweenCallback
*/
Tween &Tween::call(TweenCallback &callback)
{
Tween &tween = *(pool.get());
tween.setup(nullptr, -1, 0);
tween.setCallback(&callback);
tween.setCallbackTriggers(TweenCallback::START);
return tween;
}
/**
* Convenience method to create an empty tween. Such object is only useful
* when placed inside animation sequences (see {@link Timeline}), in which
* it may act as a beacon, so you can set a callback on it in order to
* trigger some action at the right moment.
*
* @return The generated Tween.
* @see Timeline
*/
Tween &Tween::mark()
{
Tween &tween = *(pool.get());
tween.setup(nullptr, -1, 0);
return tween;
}
// -------------------------------------------------------------------------
// Setup
// -------------------------------------------------------------------------
Tween::Tween()
{
startValues = new float[combinedAttrsLimit];
targetValues = new float[combinedAttrsLimit];
waypoints = new float[waypointsLimit*combinedAttrsLimit];
accessorBuffer = new float[combinedAttrsLimit];
accessorBufferSize = combinedAttrsLimit;
pathBuffer = new float[(2+waypointsLimit)*combinedAttrsLimit];
pathBufferSize = (2+waypointsLimit)*combinedAttrsLimit;
targetObj = nullptr;
}
Tween::~Tween()
{
delete startValues;
delete targetValues;
delete waypoints;
delete accessorBuffer;
delete pathBuffer;
// if (accessor != nullptr) Block_release(accessor);
}
void Tween::reset()
{
BaseTween::reset();
equation = nullptr;
pathAlgorithm = nullptr;
isFrom = isRelative = false;
combinedAttrsCnt = waypointsCnt = 0;
if (accessorBufferSize != combinedAttrsLimit) {
accessorBuffer = new float[combinedAttrsLimit];
}
if (pathBufferSize != (2+waypointsLimit)*combinedAttrsLimit) {
pathBuffer = new float[(2+waypointsLimit)*combinedAttrsLimit];
}
// if (accessor != nullptr)
// {
// Block_release(accessor);
targetObj = nullptr;
// }
type = -1;
}
void Tween::setup(Tweenable *target, int tweenType, float duration)
{
// assert(duration >= 0);
this->targetObj = target;
this->type = tweenType;
this->duration = duration;
}
// -------------------------------------------------------------------------
// Public API
// -------------------------------------------------------------------------
/**
* Sets the easing equation of the tween. Existing equations are located in
* <i>aurelienribon.tweenengine.equations</i> package, but you can of course
* implement your owns, see {@link TweenEquation}. You can also use the
* {@link TweenEquations} static instances to quickly access all the
* equations. Default equation is Quad.INOUT.
* <p/>
*
* <b>Proposed equations are:</b><br/>
* - Linear.INOUT,<br/>
* - Quad.IN | OUT | INOUT,<br/>
* - Cubic.IN | OUT | INOUT,<br/>
* - Quart.IN | OUT | INOUT,<br/>
* - Quint.IN | OUT | INOUT,<br/>
* - Circ.IN | OUT | INOUT,<br/>
* - Sine.IN | OUT | INOUT,<br/>
* - Expo.IN | OUT | INOUT,<br/>
* - Back.IN | OUT | INOUT,<br/>
* - Bounce.IN | OUT | INOUT,<br/>
* - Elastic.IN | OUT | INOUT
*
* @return The current tween, for chaining instructions.
* @see TweenEquation
* @see TweenEquations
*/
Tween &Tween::ease(TweenEquation &easeEquation)
{
this->equation = &easeEquation;
return *this;
}
/**
* Sets the target value of the interpolation. The interpolation will run
* from the <b>value at start time (after the delay, if any)</b> to this
* target value.
* <p/>
*
* To sum-up:<br/>
* - start value: value at start time, after delay<br/>
* - end value: param
*
* @param targetValue The target value of the interpolation.
* @return The current tween, for chaining instructions.
*/
Tween &Tween::target(float targetValue)
{
targetValues[0] = targetValue;
return *this;
}
/**
* Sets the target values of the interpolation. The interpolation will run
* from the <b>values at start time (after the delay, if any)</b> to these
* target values.
* <p/>
*
* To sum-up:<br/>
* - start values: values at start time, after delay<br/>
* - end values: params
*
* @param targetValue1 The 1st target value of the interpolation.
* @param targetValue2 The 2nd target value of the interpolation.
* @return The current tween, for chaining instructions.
*/
Tween &Tween::target(float targetValue1, float targetValue2)
{
targetValues[0] = targetValue1;
targetValues[1] = targetValue2;
return *this;
}
/**
* Sets the target values of the interpolation. The interpolation will run
* from the <b>values at start time (after the delay, if any)</b> to these
* target values.
* <p/>
*
* To sum-up:<br/>
* - start values: values at start time, after delay<br/>
* - end values: params
*
* @param targetValue1 The 1st target value of the interpolation.
* @param targetValue2 The 2nd target value of the interpolation.
* @param targetValue3 The 3rd target value of the interpolation.
* @return The current tween, for chaining instructions.
*/
Tween &Tween::target(float targetValue1, float targetValue2, float targetValue3)
{
targetValues[0] = targetValue1;
targetValues[1] = targetValue2;
targetValues[2] = targetValue3;
return *this;
}
Tween &Tween::target(float *targetValues, int len)
{
if (len <= combinedAttrsLimit)
{
for (int i=0; i<len; i++)
this->targetValues[i] = targetValues[i];
}
return *this;
}
/**
* Sets the target value of the interpolation, relatively to the <b>value
* at start time (after the delay, if any)</b>.
* <p/>
*
* To sum-up:<br/>
* - start value: value at start time, after delay<br/>
* - end value: param + value at start time, after delay
*
* @param targetValue The relative target value of the interpolation.
* @return The current tween, for chaining instructions.
*/
Tween &Tween::targetRelative(float targetValue)
{
isRelative = true;
targetValues[0] = isInitialized() ? targetValue + startValues[0] : targetValue;
return *this;
}
/**
* Sets the target values of the interpolation, relatively to the <b>values
* at start time (after the delay, if any)</b>.
* <p/>
*
* To sum-up:<br/>
* - start values: values at start time, after delay<br/>
* - end values: params + values at start time, after delay
*
* @param targetValue1 The 1st relative target value of the interpolation.
* @param targetValue2 The 2nd relative target value of the interpolation.
* @return The current tween, for chaining instructions.
*/
Tween &Tween::targetRelative(float targetValue1, float targetValue2)
{
isRelative = true;
targetValues[0] = isInitialized() ? targetValue1 + startValues[0] : targetValue1;
targetValues[1] = isInitialized() ? targetValue2 + startValues[1] : targetValue2;
return *this;
}
/**
* Sets the target values of the interpolation, relatively to the <b>values
* at start time (after the delay, if any)</b>.
* <p/>
*
* To sum-up:<br/>
* - start values: values at start time, after delay<br/>
* - end values: params + values at start time, after delay
*
* @param targetValue1 The 1st relative target value of the interpolation.
* @param targetValue2 The 2nd relative target value of the interpolation.
* @param targetValue3 The 3rd relative target value of the interpolation.
* @return The current tween, for chaining instructions.
*/
Tween &Tween::targetRelative(float targetValue1, float targetValue2, float targetValue3)
{
isRelative = true;
targetValues[0] = isInitialized() ? targetValue1 + startValues[0] : targetValue1;
targetValues[1] = isInitialized() ? targetValue2 + startValues[1] : targetValue2;
targetValues[2] = isInitialized() ? targetValue3 + startValues[2] : targetValue3;
return *this;
}
/**
* Sets the target values of the interpolation, relatively to the <b>values
* at start time (after the delay, if any)</b>.
* <p/>
*
* To sum-up:<br/>
* - start values: values at start time, after delay<br/>
* - end values: params + values at start time, after delay
*
* @param targetValues The relative target values of the interpolation.
* @return The current tween, for chaining instructions.
*/
Tween &Tween::targetRelative(float *targetValues, int len)
{
if (len <= combinedAttrsLimit)
{
for (int i=0; i<len; i++)
this->targetValues[i] = isInitialized() ? targetValues[i] + startValues[i] : targetValues[i];
}
isRelative = true;
return *this;
}
/**
* Adds a waypoint to the path. The default path runs from the start values
* to the end values linearly. If you add waypoints, the default path will
* use a smooth catmull-rom spline to navigate between the waypoints, but
* you can change this behavior by using the {@link #path(TweenPath)}
* method.
* <p/>
* Note that if you want waypoints relative to the start values, use one of
* the .targetRelative() methods to define your target.
*
* @param targetValue The target of this waypoint.
* @return The current tween, for chaining instructions.
*/
Tween &Tween::waypoint(float targetValue)
{
if (waypointsCnt < waypointsLimit)
{
waypoints[waypointsCnt] = targetValue;
waypointsCnt += 1;
}
return *this;
}
/**
* Adds a waypoint to the path. The default path runs from the start values
* to the end values linearly. If you add waypoints, the default path will
* use a smooth catmull-rom spline to navigate between the waypoints, but
* you can change this behavior by using the {@link #path(TweenPath)}
* method.
* <p/>
* Note that if you want waypoints relative to the start values, use one of
* the .targetRelative() methods to define your target.
*
* @param targetValue1 The 1st target of this waypoint.
* @param targetValue2 The 2nd target of this waypoint.
* @return The current tween, for chaining instructions.
*/
Tween &Tween::waypoint(float targetValue1, float targetValue2)
{
if (waypointsCnt < waypointsLimit)
{
waypoints[waypointsCnt*2] = targetValue1;
waypoints[waypointsCnt*2+1] = targetValue2;
waypointsCnt += 1;
}
return *this;
}
/**
* Adds a waypoint to the path. The default path runs from the start values
* to the end values linearly. If you add waypoints, the default path will
* use a smooth catmull-rom spline to navigate between the waypoints, but
* you can change this behavior by using the {@link #path(TweenPath)}
* method.
* <p/>
* Note that if you want waypoints relative to the start values, use one of
* the .targetRelative() methods to define your target.
*
* @param targetValue1 The 1st target of this waypoint.
* @param targetValue2 The 2nd target of this waypoint.
* @param targetValue3 The 3rd target of this waypoint.
* @return The current tween, for chaining instructions.
*/
Tween &Tween::waypoint(float targetValue1, float targetValue2, float targetValue3)
{
if (waypointsCnt < waypointsLimit)
{
waypoints[waypointsCnt*3] = targetValue1;
waypoints[waypointsCnt*3+1] = targetValue2;
waypoints[waypointsCnt*3+2] = targetValue3;
waypointsCnt += 1;
}
return *this;
}
/**
* Adds a waypoint to the path. The default path runs from the start values
* to the end values linearly. If you add waypoints, the default path will
* use a smooth catmull-rom spline to navigate between the waypoints, but
* you can change this behavior by using the {@link #path(TweenPath)}
* method.
* <p/>
* Note that if you want waypoints relative to the start values, use one of
* the .targetRelative() methods to define your target.
*
* @param targetValues The targets of this waypoint.
* @return The current tween, for chaining instructions.
*/
Tween &Tween::waypoint(float *targetValues, int len)
{
if (waypointsCnt < waypointsLimit)
{
for (int i=0; i<len; i++)
this->waypoints[waypointsCnt*len+i] = targetValues[i];
waypointsCnt += 1;
}
return *this;
}
/**
* Sets the algorithm that will be used to navigate through the waypoints,
* from the start values to the end values. Default is a catmull-rom spline,
* but you can find other paths in the {@link TweenPaths} class.
*
* @param path A TweenPath implementation.
* @return The current tween, for chaining instructions.
* @see TweenPath
* @see TweenPaths
*/
Tween &Tween::path(TweenPath &path)
{
this->pathAlgorithm = &path;
return *this;
}
// -------------------------------------------------------------------------
// Getters
// -------------------------------------------------------------------------
/**
* Gets the easing equation.
*/
TweenEquation *Tween::getEasing() { return equation; }
/**
* Gets the target values. The returned buffer is as long as the maximum
* allowed combined values. Therefore, you're surely not interested in all
* its content. Use {@link #getCombinedTweenCount()} to get the number of
* interesting slots.
*/
float *Tween::getTargetValues() { return targetValues; }
/**
* Gets the number of combined animations.
*/
int Tween::getCombinedAttributesCount() { return combinedAttrsCnt; }
// -------------------------------------------------------------------------
// Base Class
// -------------------------------------------------------------------------
Tween &Tween::build()
{
if (targetObj != nullptr) {
combinedAttrsCnt = targetObj->getValues(type, accessorBuffer);
}
// assert(combinedAttrsCnt <= combinedAttrsLimit);
return *this;
}
void Tween::free() { pool.free(this); }
void Tween::initializeOverride()
{
targetObj->getValues(type, startValues);
for (int i=0; i<combinedAttrsCnt; i++) {
targetValues[i] += isRelative ? startValues[i] : 0;
for (int ii=0; ii<waypointsCnt; ii++) {
waypoints[ii*combinedAttrsCnt+i] += isRelative ? startValues[i] : 0;
}
if (isFrom) {
float tmp = startValues[i];
startValues[i] = targetValues[i];
targetValues[i] = tmp;
}
}
}
void Tween::updateOverride(int step, int lastStep, bool isIterationStep, float delta)
{
if (equation == nullptr) return;
// Case iteration end has been reached
if (!isIterationStep && step > lastStep)
{
targetObj->setValues(type, isReverse(lastStep) ? startValues : targetValues);
return;
}
if (!isIterationStep && step < lastStep)
{
targetObj->setValues(type, isReverse(lastStep) ? targetValues : startValues);
return;
}
// Validation
// assert(isIterationStep);
// assert(getCurrentTime() >= 0);
// assert(getCurrentTime() <= duration);
// Case duration equals zero
if (duration < 0.00000000001f && delta > -0.00000000001f)
{
targetObj->setValues(type, isReverse(step) ? targetValues : startValues);
return;
}
if (duration < 0.00000000001f && delta < 0.00000000001f) {
targetObj->setValues(type, isReverse(step) ? startValues : targetValues);
return;
}
// Normal behavior
float time = isReverse(step) ? duration - getCurrentTime() : getCurrentTime();
float t = equation->compute(time/duration);
if (waypointsCnt == 0 || pathAlgorithm == nullptr)
{
for (int i=0; i<combinedAttrsCnt; i++)
{
accessorBuffer[i] = startValues[i] + t * (targetValues[i] - startValues[i]);
}
}
else
{
for (int i=0; i<combinedAttrsCnt; i++)
{
pathBuffer[0] = startValues[i];
pathBuffer[1+waypointsCnt] = targetValues[i];
for (int ii=0; ii<waypointsCnt; ii++)
{
pathBuffer[ii+1] = waypoints[ii*combinedAttrsCnt+i];
}
accessorBuffer[i] = pathAlgorithm->compute(t, pathBuffer, waypointsCnt+2);
}
}
targetObj->setValues(type, accessorBuffer);
}
void Tween::forceStartValues(){
targetObj->setValues(type, startValues);
}
void Tween::forceEndValues(){
targetObj->setValues(type, targetValues);
}
int Tween::getTweenCount() { return 1; }
int Tween::getTimelineCount() { return 0; }
}

View File

@ -0,0 +1,53 @@
//
// Equations.cpp
//
// This code is derived from Universal Tween Engine
// Licensed under Apache License 2.0 - http://www.apache.org/licenses/LICENSE-2.0
//
#include <TweenEngine/TweenEquations.h>
namespace TweenEngine
{
TweenEquation &TweenEquations::easeInQuad = *(new QuadIn());
TweenEquation &TweenEquations::easeOutQuad = *(new QuadOut());
TweenEquation &TweenEquations::easeInOutQuad = *(new QuadInOut());
TweenEquation &TweenEquations::easeInOutLinear = *(new LinearInOut());
TweenEquation &TweenEquations::easeInBack = *(new BackIn());
TweenEquation &TweenEquations::easeOutBack = *(new BackOut());
TweenEquation &TweenEquations::easeInOutBack = *(new BackInOut());
TweenEquation &TweenEquations::easeInBounce = *(new BounceIn());
TweenEquation &TweenEquations::easeOutBounce = *(new BounceOut());
TweenEquation &TweenEquations::easeInOutBounce = *(new BounceInOut());
TweenEquation &TweenEquations::easeInCirc = *(new CircIn());
TweenEquation &TweenEquations::easeOutCirc = *(new CircOut());
TweenEquation &TweenEquations::easeInOutCirc = *(new CircInOut());
TweenEquation &TweenEquations::easeInCubic = *(new CubicIn());
TweenEquation &TweenEquations::easeOutCubic = *(new CubicOut());
TweenEquation &TweenEquations::easeInOutCubic = *(new CubicInOut());
TweenEquation &TweenEquations::easeInElastic = *(new ElasticIn());
TweenEquation &TweenEquations::easeOutElastic = *(new ElasticOut());
TweenEquation &TweenEquations::easeInOutElastic = *(new ElasticInOut());
TweenEquation &TweenEquations::easeInExpo = *(new ExpoIn());
TweenEquation &TweenEquations::easeOutExpo = *(new ExpoOut());
TweenEquation &TweenEquations::easeInOutExpo = *(new ExpoInOut());
TweenEquation &TweenEquations::easeInQuart = *(new QuartIn());
TweenEquation &TweenEquations::easeOutQuart = *(new QuartOut());
TweenEquation &TweenEquations::easeInOutQuart = *(new QuartInOut());
TweenEquation &TweenEquations::easeInQuint = *(new QuintIn());
TweenEquation &TweenEquations::easeOutQuint = *(new QuintOut());
TweenEquation &TweenEquations::easeInOutQuint = *(new QuintInOut());
TweenEquation &TweenEquations::easeInSine = *(new SineIn());
TweenEquation &TweenEquations::easeOutSine = *(new SineOut());
TweenEquation &TweenEquations::easeInOutSine = *(new SineInOut());
}

View File

@ -0,0 +1,186 @@
//
// TweenManager.cpp
//
// This code is derived from Universal Tween Engine
// Licensed under Apache License 2.0 - http://www.apache.org/licenses/LICENSE-2.0
//
#include <TweenEngine/TweenManager.h>
#include <TweenEngine/BaseTween.h>
namespace TweenEngine
{
// -------------------------------------------------------------------------
// Static API
// -------------------------------------------------------------------------
/**
* Disables or enables the "auto remove" mode of any tween manager for a
* particular tween or timeline. This mode is activated by default. The
* interest of desactivating it is to prevent some tweens or timelines from
* being automatically removed from a manager once they are finished.
* Therefore, if you update a manager backwards, the tweens or timelines
* will be played again, even if they were finished.
*/
void TweenManager::setAutoRemove(BaseTween &object, bool value)
{
object.isAutoRemoveEnabled = value;
}
/**
* Disables or enables the "auto start" mode of any tween manager for a
* particular tween or timeline. This mode is activated by default. If it
* is not enabled, add a tween or timeline to any manager won't start it
* automatically, and you'll need to call .start() manually on your object.
*/
void TweenManager::setAutoStart(BaseTween &object, bool value)
{
object.isAutoStartEnabled = value;
}
int getTweensCount(std::vector<BaseTween *> objs)
{
int cnt = 0;
for (int i=0, n=objs.size(); i<n; i++)
{
cnt += objs[i]->getTweenCount();
}
return cnt;
}
int getTimelinesCount(std::vector<BaseTween *> objs)
{
int cnt = 0;
for (int i=0, n=objs.size(); i<n; i++)
{
cnt += objs[i]->getTimelineCount();
}
return cnt;
}
bool isTweenFinished(BaseTween *obj)
{
if (obj->isFinished() && obj->isAutoRemoveEnabled)
{
obj->free();
return true;
}
return false;
}
// -------------------------------------------------------------------------
// API
// -------------------------------------------------------------------------
TweenManager::TweenManager() : objects()
{
objects.reserve(20);
}
/**
* Adds a tween or timeline to the manager and starts or restarts it.
*
* @return The manager, for instruction chaining.
*/
TweenManager &TweenManager::add(BaseTween &object)
{
bool isPresent = (std::find(objects.begin(), objects.end(), &object) != objects.end());
if (!isPresent) objects.push_back(&object);
if (object.isAutoStartEnabled) object.start();
return *this;
}
/**
* Kills every managed tweens and timelines.
*/
void TweenManager::killAll()
{
for (int i=0, n=objects.size(); i<n; i++)
{
BaseTween *obj = objects[i];
obj->kill();
}
}
/**
* Increases the minimum capacity of the manager. Defaults to 20.
*/
void TweenManager::ensureCapacity(int minCapacity) { objects.reserve(minCapacity); }
/**
* Pauses the manager. Further update calls won't have any effect.
*/
void TweenManager::pause() { isPaused = true; }
/**
* Resumes the manager, if paused.
*/
void TweenManager::resume() { isPaused = false; }
/**
* Updates every tweens with a delta time ang handles the tween life-cycles
* automatically. If a tween is finished, it will be removed from the
* manager. The delta time represents the elapsed time between now and the
* last update call. Each tween or timeline manages its local time, and adds
* this delta to its local time to update itself.
* <p/>
*
* Slow motion, fast motion and backward play can be easily achieved by
* tweaking this delta time. Multiply it by -1 to play the animation
* backward, or by 0.5 to play it twice slower than its normal speed.
*/
void TweenManager::update(float delta)
{
// Remove tweens that are finished
objects.erase(std::remove_if(objects.begin(),objects.end(),isTweenFinished), objects.end());
if (!isPaused)
{
if (delta >= 0)
{
for (int i=0, n=objects.size(); i<n; i++) objects[i]->update(delta);
}
else
{
for (int i=objects.size()-1; i>=0; i--) objects[i]->update(delta);
}
}
}
/**
* Gets the number of managed objects. An object may be a tween or a
* timeline. Note that a timeline only counts for 1 object, since it
* manages its children itself.
* <p/>
* To get the count of running tweens, see {@link #getRunningTweensCount()}.
*/
int TweenManager::size() { return objects.size(); }
/**
* Gets the number of running tweens. This number includes the tweens
* located inside timelines (and nested timelines).
* <p/>
* <b>Provided for debug purpose only.</b>
*/
int TweenManager::getRunningTweensCount() { return getTweensCount(objects); }
/**
* Gets the number of running timelines. This number includes the timelines
* nested inside other timelines.
* <p/>
* <b>Provided for debug purpose only.</b>
*/
int TweenManager::getRunningTimelinesCount() { return getTimelinesCount(objects); }
/**
* Gets a list of every managed object.
* <p/>
* <b>Provided for debug purpose only.</b>
*/
std::vector<BaseTween *> &TweenManager::getObjects()
{
return objects;
}
}

View File

@ -0,0 +1,17 @@
//
// TweenPaths.cpp
//
// This code is derived from Universal Tween Engine
// Licensed under Apache License 2.0 - http://www.apache.org/licenses/LICENSE-2.0
//
#include <TweenEngine/TweenPaths.h>
#include <TweenEngine/paths/LinearPath.h>
#include <TweenEngine/paths/CatmullRom.h>
namespace TweenEngine
{
TweenPath &TweenPaths::linear = *(new LinearPath());
TweenPath &TweenPaths::catmullRom = *(new CatmullRom());
}

39
external/tween-engine/src/TweenPool.cpp vendored Normal file
View File

@ -0,0 +1,39 @@
//
// TweenPool.cpp
//
// This code is derived from Universal Tween Engine
// Licensed under Apache License 2.0 - http://www.apache.org/licenses/LICENSE-2.0
//
#include <TweenEngine/TweenPool.h>
#include <TweenEngine/Tween.h>
namespace TweenEngine
{
void TweenPoolCallback::onPool(Tween *obj)
{
obj->reset();
}
void TweenPoolCallback::onUnPool(Tween *obj)
{
obj->reset();
}
TweenPool::TweenPool() : Pool<TweenEngine::Tween>(20, new TweenPoolCallback())
{
}
Tween *TweenPool::create() { return new Tween(); }
//TweenPoolCallback *Tween::poolCallback = new TweenPoolCallback();
//TweenPool *Tween::pool = new TweenPool(20, Tween::poolCallback);
/*
private static final Pool<Tween> pool = new Pool<Tween>(20, poolCallback) {
@Override protected Tween create() {return new Tween();}
};
*/
}

View File

@ -0,0 +1,34 @@
//
// Back.cpp
//
// This code is derived from Universal Tween Engine
// Licensed under Apache License 2.0 - http://www.apache.org/licenses/LICENSE-2.0
//
#include <TweenEngine/equations/Back.h>
#define S (1.70158f)
namespace TweenEngine
{
float BackIn::compute(float t) { return t*t*((S+1)*t - S); }
const char *BackIn::toString() { return "Back.IN"; }
float BackOut::compute(float t) {
t -= 1;
return (t*t*((S+1)*t + S) + 1);
}
const char *BackOut::toString() { return "Back.OUT"; }
float BackInOut::compute(float t) {
float s=S*1.525;
t*=2;
if (t < 1) {
return 0.5f*(t*t*((s+1)*t - s));
} else {
t -= 2;
return 0.5f*(t*t*((s+1)*t + s) + 2);
}
}
const char *BackInOut::toString() { return "Back.INOUT"; }
}

View File

@ -0,0 +1,42 @@
//
// Bounce.cpp
//
// This code is derived from Universal Tween Engine
// Licensed under Apache License 2.0 - http://www.apache.org/licenses/LICENSE-2.0
//
#include <TweenEngine/equations/Bounce.h>
namespace TweenEngine
{
inline float outBounce(float t) {
if (t < (1/2.75)) {
return 7.5625f*t*t;
} else if (t < (2/2.75)) {
t = t - (1.5 / 2.75);
return (7.5625 * t * t + 0.75);
} else if (t < (2.5/2.75)) {
t = t - (2.25 / 2.75);
return (7.5625 * t * t + 0.9375);
} else {
t = t - (2.625 / 2.75);
return (7.5625 * t * t + 0.984375);
}
}
inline float inBounce(float t) {
return 1 - outBounce(1-t);
}
float BounceIn::compute(float t) { return inBounce(t); }
const char *BounceIn::toString() { return "Bounce.IN"; }
float BounceOut::compute(float t) { return outBounce(t); }
const char *BounceOut::toString() { return "Bounce.OUT"; }
float BounceInOut::compute(float t) {
if (t < 0.5f) return (inBounce(t*2) * 0.5f);
else return (outBounce(t*2-1) * 0.5f + 0.5f);
}
const char *BounceInOut::toString() { return "Bounce.INOUT"; }
}

View File

@ -0,0 +1,30 @@
//
// Circ.cpp
//
// This code is derived from Universal Tween Engine
// Licensed under Apache License 2.0 - http://www.apache.org/licenses/LICENSE-2.0
//
#include <math.h>
#include <TweenEngine/equations/Circ.h>
namespace TweenEngine
{
float CircIn::compute(float t) { return (float) -sqrt(1 - t*t) - 1; }
const char *CircIn::toString() { return "Circ.IN"; }
float CircOut::compute(float t) { return (float) sqrt(1 - (t-1)*(t-1)); }
const char *CircOut::toString() { return "Circ.OUT"; }
float CircInOut::compute(float t) {
t *= 2;
if (t < 1) {
return (-0.5 * (sqrt(1 - t*t) - 1));
} else {
t -= 2;
return (0.5 * (sqrt(1 - t*t) + 1));
}
}
const char *CircInOut::toString() { return "Circ.INOUT"; }
}

View File

@ -0,0 +1,31 @@
//
// Cubic.cpp
//
// This code is derived from Universal Tween Engine
// Licensed under Apache License 2.0 - http://www.apache.org/licenses/LICENSE-2.0
//
#include <TweenEngine/equations/Cubic.h>
namespace TweenEngine
{
float CubicIn::compute(float t) { return t*t*t; }
const char *CubicIn::toString() { return "Cubic.IN"; }
float CubicOut::compute(float t) {
t -= 1;
return t*t*t + 1;
}
const char *CubicOut::toString() { return "Cubic.OUT"; }
float CubicInOut::compute(float t) {
t *= 2;
if (t < 1) {
return 0.5f * t*t*t;
} else {
t -= 2;
return 0.5f * (t*t*t + 2);
}
}
const char *CubicInOut::toString() { return "Cubic.INOUT"; }
}

View File

@ -0,0 +1,80 @@
//
// Elastic.cpp
//
// This code is derived from Universal Tween Engine
// Licensed under Apache License 2.0 - http://www.apache.org/licenses/LICENSE-2.0
//
#include <math.h>
#include <TweenEngine/equations/Elastic.h>
#define M_PI 3.14159265358979323846
#define M_TWOPI (M_PI * 2.0)
namespace TweenEngine
{
float ElasticIn::compute(float t) {
float a = amplitude;
float p = period;
if (t == 0) return 0;
if (t == 1) return 1;
if (!isPeriodSet) p = 0.3;
float s;
if (!isAmplitudeSet || a < 1) {
a = 1;
s = p/4.0;
} else {
s = p/(M_TWOPI) * (float)asin(1/a);
}
t -= 1;
return -(a*(float)pow(2,10*t) * (float)sin((t-s)*(M_TWOPI)/p ));
}
const char *ElasticIn::toString() { return "Elastic.IN"; }
void ElasticIn::setAmplitude(float a) { this->amplitude = a; this->isAmplitudeSet = true; }
void ElasticIn::setPeriod(float p) { this->period = p; this->isPeriodSet = true; }
float ElasticOut::compute(float t) {
float a = amplitude;
float p = period;
if (t==0) return 0;
if (t==1) return 1;
if (!isPeriodSet) p = 0.3f;
float s;
if (!isAmplitudeSet || a < 1) {
a = 1;
s = p/4.0;
} else {
s = p/(M_TWOPI) * (float)asin(1/a);
}
return a*(float)pow(2,-10*t) * (float)sin((t-s)*(M_TWOPI)/p ) + 1;
}
const char *ElasticOut::toString() { return "Elastic.OUT"; }
void ElasticOut::setAmplitude(float a) { this->amplitude = a; this->isAmplitudeSet = true; }
void ElasticOut::setPeriod(float p) { this->period = p; this->isPeriodSet = true; }
float ElasticInOut::compute(float t) {
float a = amplitude;
float p = period;
if (t==0) return 0;
t *= 2;
if (t==2) return 1;
if (!isPeriodSet) p = 0.3f*1.5f;
float s;
if (!isAmplitudeSet || a < 1) {
a = 1;
s = p/4.0;
} else {
s = p/(M_TWOPI) * (float)asin(1/a);
}
if (t < 1) {
t -= 1;
return -0.5f*(a*(float)pow(2,10*t) * (float)sin((t-s)*(M_TWOPI)/p));
} else {
t -= 1;
return a*(float)pow(2,-10*t) * (float)sin((t-s)*(M_TWOPI)/p)*0.5f + 1;
}
}
const char *ElasticInOut::toString() { return "Elastic.INOUT"; }
void ElasticInOut::setAmplitude(float a) { this->amplitude = a; this->isAmplitudeSet = true; }
void ElasticInOut::setPeriod(float p) { this->period = p; this->isPeriodSet = true; }
}

View File

@ -0,0 +1,35 @@
//
// Expo.cpp
//
// This code is derived from Universal Tween Engine
// Licensed under Apache License 2.0 - http://www.apache.org/licenses/LICENSE-2.0
//
#include <math.h>
#include <TweenEngine/equations/Expo.h>
namespace TweenEngine
{
float ExpoIn::compute(float t) {
return (t==0) ? 0 : (float)pow(2,10*(t-1));
}
const char *ExpoIn::toString() { return "Expo.IN"; }
float ExpoOut::compute(float t) {
return (t==1) ? 1 : -(float)pow(2,-10*t) + 1;
}
const char *ExpoOut::toString() { return "Expo.OUT"; }
float ExpoInOut::compute(float t) {
if (t==0) return 0;
if (t==1) return 1;
t *= 2;
if (t < 1) {
return 0.5f * (float)pow(2,10*(t-1));
} else {
t -= 1;
return 0.5f * (-(float)pow(2,-10*t) + 2);
}
}
const char *ExpoInOut::toString() { return "Expo.INOUT"; }
}

View File

@ -0,0 +1,20 @@
//
// Linear.cpp
// This code is derived from Universal Tween Engine
// Licensed under Apache License 2.0 - http://www.apache.org/licenses/LICENSE-2.0
//
/**
* Easing equation based on Robert Penner's work:
* http://robertpenner.com/easing/
* @author Aurelien Ribon | http://www.aurelienribon.com/
*/
#include <TweenEngine/equations/Linear.h>
namespace TweenEngine
{
float LinearInOut::compute(float t) { return t; }
const char *LinearInOut::toString() { return "Linear.INOUT"; }
}

View File

@ -0,0 +1,31 @@
//
// Quad.cpp
//
// This code is derived from Universal Tween Engine
// Licensed under Apache License 2.0 - http://www.apache.org/licenses/LICENSE-2.0
//
/**
* Easing equation based on Robert Penner's work:
* http://robertpenner.com/easing/
* @author Aurelien Ribon | http://www.aurelienribon.com/
*/
#include <TweenEngine/equations/Quad.h>
namespace TweenEngine
{
float QuadIn::compute(float t) { return t*t; }
const char *QuadIn::toString() { return "Quad.IN"; }
float QuadOut::compute(float t) { return -t*(t-2); }
const char *QuadOut::toString() { return "Quad.OUT"; }
float QuadInOut::compute(float t)
{
t*=2;
if (t < 1) return 0.5f*t*t;
return -0.5f * ((t-1)*(t-3) - 1);
}
const char *QuadInOut::toString() { return "Quad.INOUT"; }
}

View File

@ -0,0 +1,31 @@
//
// Quart.cpp
//
// This code is derived from Universal Tween Engine
// Licensed under Apache License 2.0 - http://www.apache.org/licenses/LICENSE-2.0
//
#include <TweenEngine/equations/Quart.h>
namespace TweenEngine
{
float QuartIn::compute(float t) { return t*t*t*t; }
const char *QuartIn::toString() { return "Quart.IN"; }
float QuartOut::compute(float t) {
t-=1;
return -(t*t*t*t - 1);
}
const char *QuartOut::toString() { return "Quart.OUT"; }
float QuartInOut::compute(float t) {
t *= 2;
if (t < 1) {
return 0.5f*t*t*t*t;
} else {
t -= 2;
return -0.5f * (t*t*t*t - 2);
}
}
const char *QuartInOut::toString() { return "Quart.INOUT"; }
}

View File

@ -0,0 +1,31 @@
//
// Quint.cpp
//
// This code is derived from Universal Tween Engine
// Licensed under Apache License 2.0 - http://www.apache.org/licenses/LICENSE-2.0
//
#include <TweenEngine/equations/Quint.h>
namespace TweenEngine
{
float QuintIn::compute(float t) { return t*t*t*t*t; }
const char *QuintIn::toString() { return "Quint.IN"; }
float QuintOut::compute(float t) {
t-=1;
return -(t*t*t*t*t - 1);
}
const char *QuintOut::toString() { return "Quint.OUT"; }
float QuintInOut::compute(float t) {
t *= 2;
if (t < 1) {
return 0.5f*t*t*t*t*t;
} else {
t -= 2;
return -0.5f * (t*t*t*t*t - 2);
}
}
const char *QuintInOut::toString() { return "Quint.INOUT"; }
}

View File

@ -0,0 +1,24 @@
//
// Sine.cpp
//
// This code is derived from Universal Tween Engine
// Licensed under Apache License 2.0 - http://www.apache.org/licenses/LICENSE-2.0
//
#include <math.h>
#include <TweenEngine/equations/Sine.h>
#define M_PI 3.14159265358979323846
#define M_PI_2 1.57079632679489661923
namespace TweenEngine
{
float SineIn::compute(float t) { return (float)-cos(t * (M_PI_2)) + 1; }
const char *SineIn::toString() { return "Sine.IN"; }
float SineOut::compute(float t) { return (float)sin(t * (M_PI_2)); }
const char *SineOut::toString() { return "Sine.OUT"; }
float SineInOut::compute(float t) { return -0.5f * ((float)cos(M_PI*t) - 1); }
const char *SineInOut::toString() { return "Sine.INOUT"; }
}

View File

@ -0,0 +1,47 @@
//
// CatmullRom.cpp
//
// This code is derived from Universal Tween Engine
// Licensed under Apache License 2.0 - http://www.apache.org/licenses/LICENSE-2.0
//
#include <math.h>
#include <TweenEngine/paths/CatmullRom.h>
namespace TweenEngine
{
float CatmullRom::compute(float t, float *points, int pointsCnt)
{
int segment = (int) floor((pointsCnt-1) * t);
segment = segment > 0 ? segment : 0;
segment = segment < (pointsCnt-2) ? segment : pointsCnt-2;
t = t * (pointsCnt-1) - segment;
if (segment == 0)
{
return catmullRomSpline(points[0], points[0], points[1], points[2], t);
}
if (segment == pointsCnt-2)
{
return catmullRomSpline(points[pointsCnt-3], points[pointsCnt-2], points[pointsCnt-1], points[pointsCnt-1], t);
}
return catmullRomSpline(points[segment-1], points[segment], points[segment+1], points[segment+2], t);
}
float CatmullRom::catmullRomSpline(float a, float b, float c, float d, float t)
{
float t1 = (c - a) * 0.5f;
float t2 = (d - b) * 0.5f;
float h1 = +2 * t * t * t - 3 * t * t + 1;
float h2 = -2 * t * t * t + 3 * t * t;
float h3 = t * t * t - 2 * t * t + t;
float h4 = t * t * t - t * t;
return b * h1 + c * h2 + t1 * h3 + t2 * h4;
}
}

View File

@ -0,0 +1,23 @@
//
// Linear.cpp
//
// This code is derived from Universal Tween Engine
// Licensed under Apache License 2.0 - http://www.apache.org/licenses/LICENSE-2.0
//
#include <math.h>
#include <TweenEngine/paths/LinearPath.h>
namespace TweenEngine
{
float LinearPath::compute(float t, float *points, int pointsCnt)
{
int segment = (int) floor((pointsCnt-1) * t);
segment = segment > 0 ? segment : 0;
segment = segment < (pointsCnt-2) ? segment : pointsCnt-2;
t = t * (pointsCnt-1) - segment;
return points[segment] + t * (points[segment+1] - points[segment]);
}
}

679
internal/ini.hpp Normal file
View File

@ -0,0 +1,679 @@
#ifndef INI_INI_H_
#define INI_INI_H_
#include <string>
#include <sstream>
#include <algorithm>
#include <utility>
#include <unordered_map>
#include <vector>
#include <memory>
#include <fstream>
#include <sys/stat.h>
#include <cctype>
namespace INI
{
namespace INIStringUtil
{
const char* const whitespaceDelimiters = " \t\n\r\f\v";
inline void trim(std::string& str)
{
str.erase(str.find_last_not_of(whitespaceDelimiters) + 1);
str.erase(0, str.find_first_not_of(whitespaceDelimiters));
}
#ifndef INI_CASE_SENSITIVE
inline void toLower(std::string& str)
{
std::transform(str.begin(), str.end(), str.begin(), [](const char c) {
return static_cast<const char>(std::tolower(c));
});
}
#endif
inline void replace(std::string& str, std::string const& a, std::string const& b)
{
if (!a.empty())
{
std::size_t pos = 0;
while ((pos = str.find(a, pos)) != std::string::npos)
{
str.replace(pos, a.size(), b);
pos += b.size();
}
}
}
#ifdef _WIN32
const char* const endl = "\r\n";
#else
const char* const endl = "\n";
#endif
};
template<typename T>
class INIMap
{
private:
using T_DataIndexMap = std::unordered_map<std::string, std::size_t>;
using T_DataItem = std::pair<std::string, T>;
using T_DataContainer = std::vector<T_DataItem>;
using T_MultiArgs = typename std::vector<std::pair<std::string, T>>;
T_DataIndexMap dataIndexMap;
T_DataContainer data;
inline std::size_t setEmpty(std::string& key)
{
std::size_t index = data.size();
dataIndexMap[key] = index;
data.emplace_back(key, T());
return index;
}
public:
using const_iterator = typename T_DataContainer::const_iterator;
INIMap() { }
INIMap(INIMap const& other)
{
std::size_t data_size = other.data.size();
for (std::size_t i = 0; i < data_size; ++i)
{
auto const& key = other.data[i].first;
auto const& obj = other.data[i].second;
data.emplace_back(key, obj);
}
dataIndexMap = T_DataIndexMap(other.dataIndexMap);
}
T& operator[](std::string key)
{
INIStringUtil::trim(key);
#ifndef INI_CASE_SENSITIVE
INIStringUtil::toLower(key);
#endif
auto it = dataIndexMap.find(key);
bool hasIt = (it != dataIndexMap.end());
std::size_t index = (hasIt) ? it->second : setEmpty(key);
return data[index].second;
}
T get(std::string key) const
{
INIStringUtil::trim(key);
#ifndef INI_CASE_SENSITIVE
INIStringUtil::toLower(key);
#endif
auto it = dataIndexMap.find(key);
if (it == dataIndexMap.end())
{
return T();
}
return T(data[it->second].second);
}
bool has(std::string key) const
{
INIStringUtil::trim(key);
#ifndef INI_CASE_SENSITIVE
INIStringUtil::toLower(key);
#endif
return (dataIndexMap.count(key) == 1);
}
void set(std::string key, T obj)
{
INIStringUtil::trim(key);
#ifndef INI_CASE_SENSITIVE
INIStringUtil::toLower(key);
#endif
auto it = dataIndexMap.find(key);
if (it != dataIndexMap.end())
{
data[it->second].second = obj;
}
else
{
dataIndexMap[key] = data.size();
data.emplace_back(key, obj);
}
}
void set(T_MultiArgs const& multiArgs)
{
for (auto const& it : multiArgs)
{
auto const& key = it.first;
auto const& obj = it.second;
set(key, obj);
}
}
bool remove(std::string key)
{
INIStringUtil::trim(key);
#ifndef INI_CASE_SENSITIVE
INIStringUtil::toLower(key);
#endif
auto it = dataIndexMap.find(key);
if (it != dataIndexMap.end())
{
std::size_t index = it->second;
data.erase(data.begin() + index);
dataIndexMap.erase(it);
for (auto& it2 : dataIndexMap)
{
auto& vi = it2.second;
if (vi > index)
{
vi--;
}
}
return true;
}
return false;
}
void clear()
{
data.clear();
dataIndexMap.clear();
}
std::size_t size() const
{
return data.size();
}
const_iterator begin() const { return data.begin(); }
const_iterator end() const { return data.end(); }
};
using INIStructure = INIMap<INIMap<std::string>>;
namespace INIParser
{
using T_ParseValues = std::pair<std::string, std::string>;
enum class PDataType : char
{
PDATA_NONE,
PDATA_COMMENT,
PDATA_SECTION,
PDATA_KEYVALUE,
PDATA_UNKNOWN
};
inline PDataType parseLine(std::string line, T_ParseValues& parseData)
{
parseData.first.clear();
parseData.second.clear();
INIStringUtil::trim(line);
if (line.empty())
{
return PDataType::PDATA_NONE;
}
char firstCharacter = line[0];
if (firstCharacter == ';')
{
return PDataType::PDATA_COMMENT;
}
if (firstCharacter == '[')
{
auto commentAt = line.find_first_of(';');
if (commentAt != std::string::npos)
{
line = line.substr(0, commentAt);
}
auto closingBracketAt = line.find_last_of(']');
if (closingBracketAt != std::string::npos)
{
auto section = line.substr(1, closingBracketAt - 1);
INIStringUtil::trim(section);
parseData.first = section;
return PDataType::PDATA_SECTION;
}
}
auto lineNorm = line;
INIStringUtil::replace(lineNorm, "\\=", " ");
auto equalsAt = lineNorm.find_first_of('=');
if (equalsAt != std::string::npos)
{
auto key = line.substr(0, equalsAt);
INIStringUtil::trim(key);
INIStringUtil::replace(key, "\\=", "=");
auto value = line.substr(equalsAt + 1);
INIStringUtil::trim(value);
parseData.first = key;
parseData.second = value;
return PDataType::PDATA_KEYVALUE;
}
return PDataType::PDATA_UNKNOWN;
}
};
class INIReader
{
public:
using T_LineData = std::vector<std::string>;
using T_LineDataPtr = std::shared_ptr<T_LineData>;
private:
std::ifstream fileReadStream;
T_LineDataPtr lineData;
T_LineData readFile()
{
std::string fileContents;
fileReadStream.seekg(0, std::ios::end);
fileContents.resize(fileReadStream.tellg());
fileReadStream.seekg(0, std::ios::beg);
std::size_t fileSize = fileContents.size();
fileReadStream.read(&fileContents[0], fileSize);
fileReadStream.close();
T_LineData output;
if (fileSize == 0)
{
return output;
}
std::string buffer;
buffer.reserve(50);
for (std::size_t i = 0; i < fileSize; ++i)
{
char& c = fileContents[i];
if (c == '\n')
{
output.emplace_back(buffer);
buffer.clear();
continue;
}
if (c != '\0' && c != '\r')
{
buffer += c;
}
}
output.emplace_back(buffer);
return output;
}
public:
INIReader(std::string const& filename, bool keepLineData = false)
{
fileReadStream.open(filename, std::ios::in | std::ios::binary);
if (keepLineData)
{
lineData = std::make_shared<T_LineData>();
}
}
~INIReader() { }
bool operator>>(INIStructure& data)
{
if (!fileReadStream.is_open())
{
return false;
}
T_LineData fileLines = readFile();
std::string section;
bool inSection = false;
INIParser::T_ParseValues parseData;
for (auto const& line : fileLines)
{
auto parseResult = INIParser::parseLine(line, parseData);
if (parseResult == INIParser::PDataType::PDATA_SECTION)
{
inSection = true;
data[section = parseData.first];
}
else if (inSection && parseResult == INIParser::PDataType::PDATA_KEYVALUE)
{
auto const& key = parseData.first;
auto const& value = parseData.second;
data[section][key] = value;
}
if (lineData && parseResult != INIParser::PDataType::PDATA_UNKNOWN)
{
if (parseResult == INIParser::PDataType::PDATA_KEYVALUE && !inSection)
{
continue;
}
lineData->emplace_back(line);
}
}
return true;
}
T_LineDataPtr getLines()
{
return lineData;
}
};
class INIGenerator
{
private:
std::ofstream fileWriteStream;
public:
bool prettyPrint = false;
INIGenerator(std::string const& filename)
{
fileWriteStream.open(filename, std::ios::out | std::ios::binary);
}
~INIGenerator() { }
bool operator<<(INIStructure const& data)
{
if (!fileWriteStream.is_open())
{
return false;
}
if (!data.size())
{
return true;
}
auto it = data.begin();
for (;;)
{
auto const& section = it->first;
auto const& collection = it->second;
fileWriteStream
<< "["
<< section
<< "]";
if (collection.size())
{
fileWriteStream << INIStringUtil::endl;
auto it2 = collection.begin();
for (;;)
{
auto key = it2->first;
INIStringUtil::replace(key, "=", "\\=");
auto value = it2->second;
INIStringUtil::trim(value);
fileWriteStream
<< key
<< ((prettyPrint) ? " = " : "=")
<< value;
if (++it2 == collection.end())
{
break;
}
fileWriteStream << INIStringUtil::endl;
}
}
if (++it == data.end())
{
break;
}
fileWriteStream << INIStringUtil::endl;
if (prettyPrint)
{
fileWriteStream << INIStringUtil::endl;
}
}
return true;
}
};
class INIWriter
{
private:
using T_LineData = std::vector<std::string>;
using T_LineDataPtr = std::shared_ptr<T_LineData>;
std::string filename;
T_LineData getLazyOutput(T_LineDataPtr const& lineData, INIStructure& data, INIStructure& original)
{
T_LineData output;
INIParser::T_ParseValues parseData;
std::string sectionCurrent;
bool parsingSection = false;
bool continueToNextSection = false;
bool discardNextEmpty = false;
bool writeNewKeys = false;
std::size_t lastKeyLine = 0;
for (auto line = lineData->begin(); line != lineData->end(); ++line)
{
if (!writeNewKeys)
{
auto parseResult = INIParser::parseLine(*line, parseData);
if (parseResult == INIParser::PDataType::PDATA_SECTION)
{
if (parsingSection)
{
writeNewKeys = true;
parsingSection = false;
--line;
continue;
}
sectionCurrent = parseData.first;
if (data.has(sectionCurrent))
{
parsingSection = true;
continueToNextSection = false;
discardNextEmpty = false;
output.emplace_back(*line);
lastKeyLine = output.size();
}
else
{
continueToNextSection = true;
discardNextEmpty = true;
continue;
}
}
else if (parseResult == INIParser::PDataType::PDATA_KEYVALUE)
{
if (continueToNextSection)
{
continue;
}
if (data.has(sectionCurrent))
{
auto& collection = data[sectionCurrent];
auto const& key = parseData.first;
auto const& value = parseData.second;
if (collection.has(key))
{
auto outputValue = collection[key];
if (value == outputValue)
{
output.emplace_back(*line);
}
else
{
INIStringUtil::trim(outputValue);
auto lineNorm = *line;
INIStringUtil::replace(lineNorm, "\\=", " ");
auto equalsAt = lineNorm.find_first_of('=');
auto valueAt = lineNorm.find_first_not_of(
INIStringUtil::whitespaceDelimiters,
equalsAt + 1
);
std::string outputLine = line->substr(0, valueAt);
if (prettyPrint && equalsAt + 1 == valueAt)
{
outputLine += " ";
}
outputLine += outputValue;
output.emplace_back(outputLine);
}
lastKeyLine = output.size();
}
}
}
else
{
if (discardNextEmpty && line->empty())
{
discardNextEmpty = false;
}
else if (parseResult != INIParser::PDataType::PDATA_UNKNOWN)
{
output.emplace_back(*line);
}
}
}
if (writeNewKeys || std::next(line) == lineData->end())
{
T_LineData linesToAdd;
if (data.has(sectionCurrent) && original.has(sectionCurrent))
{
auto const& collection = data[sectionCurrent];
auto const& collectionOriginal = original[sectionCurrent];
for (auto const& it : collection)
{
auto key = it.first;
if (collectionOriginal.has(key))
{
continue;
}
auto value = it.second;
INIStringUtil::replace(key, "=", "\\=");
INIStringUtil::trim(value);
linesToAdd.emplace_back(
key + ((prettyPrint) ? " = " : "=") + value
);
}
}
if (!linesToAdd.empty())
{
output.insert(
output.begin() + lastKeyLine,
linesToAdd.begin(),
linesToAdd.end()
);
}
if (writeNewKeys)
{
writeNewKeys = false;
--line;
}
}
}
for (auto const& it : data)
{
auto const& section = it.first;
if (original.has(section))
{
continue;
}
if (prettyPrint && output.size() > 0 && !output.back().empty())
{
output.emplace_back();
}
output.emplace_back("[" + section + "]");
auto const& collection = it.second;
for (auto const& it2 : collection)
{
auto key = it2.first;
auto value = it2.second;
INIStringUtil::replace(key, "=", "\\=");
INIStringUtil::trim(value);
output.emplace_back(
key + ((prettyPrint) ? " = " : "=") + value
);
}
}
return output;
}
public:
bool prettyPrint = false;
INIWriter(std::string const& filename)
: filename(filename)
{
}
~INIWriter() { }
bool operator<<(INIStructure& data)
{
struct stat buf;
bool fileExists = (stat(filename.c_str(), &buf) == 0);
if (!fileExists)
{
INIGenerator generator(filename);
generator.prettyPrint = prettyPrint;
return generator << data;
}
INIStructure originalData;
T_LineDataPtr lineData;
bool readSuccess = false;
{
INIReader reader(filename, true);
if ((readSuccess = reader >> originalData))
{
lineData = reader.getLines();
}
}
if (!readSuccess)
{
return false;
}
T_LineData output = getLazyOutput(lineData, data, originalData);
std::ofstream fileWriteStream(filename, std::ios::out | std::ios::binary);
if (fileWriteStream.is_open())
{
if (output.size())
{
auto line = output.begin();
for (;;)
{
fileWriteStream << *line;
if (++line == output.end())
{
break;
}
fileWriteStream << INIStringUtil::endl;
}
}
return true;
}
return false;
}
};
class INIFile
{
private:
std::string filename;
public:
INIFile(std::string const& filename)
: filename(filename)
{ }
~INIFile() { }
bool read(INIStructure& data) const
{
if (data.size())
{
data.clear();
}
if (filename.empty())
{
return false;
}
INIReader reader(filename);
return reader >> data;
}
bool generate(INIStructure const& data, bool pretty = false) const
{
if (filename.empty())
{
return false;
}
INIGenerator generator(filename);
generator.prettyPrint = pretty;
return generator << data;
}
bool write(INIStructure& data, bool pretty = false) const
{
if (filename.empty())
{
return false;
}
INIWriter writer(filename);
writer.prettyPrint = pretty;
return writer << data;
}
};
}
#endif

98
internal/lang.cpp Normal file
View File

@ -0,0 +1,98 @@
#include "lang.hpp"
#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>
#include <3ds.h>
static nlohmann::json appJson;
std::string RenderD7::Lang::getSys()
{
u8 language = 1;
CFGU_GetSystemLanguage(&language);
switch(language) {
case 0:
return "jp"; // Japanese
break;
case 1:
return "en"; // English
break;
case 2:
return "fr"; // French
break;
case 3:
return "de"; // German
break;
case 4:
return "it"; // Italian
break;
case 5:
return "es"; // Spanish
break;
case 6:
return "zh-CN"; // Chinese (Simplified)
break;
// case 7:
// return "ko"; // Korean
// break;
// case 8:
// return "nl"; // Dutch
// break;
case 9:
return "pt"; // Portuguese
break;
case 10:
return "ru"; // Russian
break;
case 11:
return "zh-TW"; // Chinese (Traditional)
break;
default:
return "en"; // Fall back to English if missing
break;
}
}
std::string RenderD7::Lang::get(const std::string &key) {
if (!appJson.contains(key)) return key;
return appJson.at(key).get_ref<const std::string&>();
}
void RenderD7::Lang::load(const std::string &lang) {
FILE *values;
if (access(("romfs:/lang/" + lang + "/app.json").c_str(), F_OK) == 0) {
values = fopen(("romfs:/lang/" + lang + "/app.json").c_str(), "rt");
if (values) {
appJson = nlohmann::json::parse(values, nullptr, false);
fclose(values);
}
if (appJson.is_discarded())
appJson = { };
return;
} else {
values = fopen("romfs:/lang/en/app.json", "rt");
if (values) {
appJson = nlohmann::json::parse(values, nullptr, false);
fclose(values);
}
if (appJson.is_discarded())
appJson = { };
return;
}
}

11
internal/lang.hpp Normal file
View File

@ -0,0 +1,11 @@
#pragma once
#include <string>
#include "json.hpp"
namespace RenderD7::Lang
{
std::string getSys();
std::string get(const std::string &key);
void load(const std::string &lang);
}

112
internal/parameter.hpp Normal file
View File

@ -0,0 +1,112 @@
#pragma once
#include <tuple>
namespace RenderD7{
class Parameter
{
private:
using id = size_t;
template<typename T>
struct type { static void id() { } };
template<typename T>
static id type_id() { return reinterpret_cast<id>(&type<T>::id); }
template<typename T>
using decay = typename std::decay<T>::type;
template<typename T>
using none = typename std::enable_if<!std::is_same<Parameter, T>::value>::type;
struct base
{
virtual ~base() { }
virtual bool is(id) const = 0;
virtual base *copy() const = 0;
} *p = nullptr;
template<typename T>
struct data : base, std::tuple<T>
{
using std::tuple<T>::tuple;
T &get() & { return std::get<0>(*this); }
T const &get() const& { return std::get<0>(*this); }
bool is(id i) const override { return i == type_id<T>(); }
base *copy() const override { return new data{get()}; }
};
template<typename T>
T &stat() { return static_cast<data<T>&>(*p).get(); }
template<typename T>
T const &stat() const { return static_cast<data<T> const&>(*p).get(); }
template<typename T>
T &dyn() { return dynamic_cast<data<T>&>(*p).get(); }
template<typename T>
T const &dyn() const { return dynamic_cast<data<T> const&>(*p).get(); }
public:
/**
* @brief Default constructor
*/
Parameter() { }
/**
* @brief Destructs the Parameter
*/
~Parameter() { delete p; }
/**
* @brief Copy constructor
* @param s The Parameter to copy
*/
Parameter(Parameter &&s) : p{s.p} { s.p = nullptr; }
/**
* @brief Const copy constructor
* @param s The Parameter to copy
*/
Parameter(Parameter const &s) : p{s.p->copy()} { }
/**
* @brief Initializes the Parameter with the given value
* @param x The value to initialize the Parameter with
*/
template<typename T, typename U = decay<T>, typename = none<U>>
Parameter(T &&x) : p{new data<U>{std::forward<T>(x)}} { }
/**
* @brief Overloads the assignment operator
* @param s The value to set the Parameter to
*/
Parameter &operator=(Parameter s) { swap(*this, s); return *this; }
friend void swap(Parameter &s, Parameter &r) { std::swap(s.p, r.p); }
/**
* @brief Clears the Parameter
*/
void clear() { delete p; p = nullptr; }
/**
* @brief Checks whether the Parameter is the given type
* @tparam T The type to check
* @return Whether the Parameter has the given type or not
*/
template<typename T>
bool is() const { return p ? p->is(type_id<T>()) : false; }
/**
* @brief Returns the value of the Parameter
* @tparam T The type of the Parameter
* @return The value of the Parameter
* @warning If the type of the Parameter doesn't match the type of it's stored value, it will result in undefined behaviour.
*/
template<typename T> T &get() & { return stat<T>(); }
};
}

81
internal/thread.cpp Normal file
View File

@ -0,0 +1,81 @@
#include "thread.hpp"
namespace RenderD7 {
void Threads::Exit()
{
}
Thread::Thread() :
m_started(false),
m_running(false) { /* do nothing */ }
Thread::Thread(std::function<void(RenderD7::Parameter)> t_function, RenderD7::Parameter t_parameter, bool t_autostart, bool t_detached, unsigned long long int t_stackSize) :
m_started(false),
m_running(false) {
initialize(t_function, t_parameter, t_autostart, t_detached, t_stackSize);
}
Thread::~Thread() {
join();
if (m_started) threadFree(m_thread);
}
void Thread::initialize(std::function<void(RenderD7::Parameter)> t_function, RenderD7::Parameter t_parameter, bool t_autostart, bool t_detached, unsigned long long int t_stackSize) {
m_stackSize = t_stackSize;
m_data.m_parameter = t_parameter;
m_data.m_function = t_function;
m_data.m_running = &m_running;
if (t_autostart) {
start(t_detached);
}
}
void Thread::setStackSize(unsigned long long int t_stackSize) {
m_stackSize = t_stackSize;
}
void Thread::start(bool t_detached) {
if (!m_running) {
m_started = true;
m_running = true;
s32 prio;
svcGetThreadPriority(&prio, CUR_THREAD_HANDLE);
m_thread = threadCreate(threadFunction, &m_data, m_stackSize, prio + 1, -2, t_detached);
}
}
void Thread::detach() {
threadDetach(m_thread);
m_running = false;
m_started = false;
}
void Thread::join(long long unsigned int t_timeout) {
if (m_running) {
threadJoin(m_thread, t_timeout);
threadFree(m_thread);
m_running = false;
m_started = false;
}
}
bool Thread::isRunning() {
return m_running;
}
void Thread::sleep() {
svcSleepThread(0);
}
void Thread::sleep(int t_milliseconds) {
svcSleepThread(1000000 * t_milliseconds);
}
// private methods
void Thread::threadFunction(void* arg) {
RenderD7::Thread::ThreadData data = *static_cast<RenderD7::Thread::ThreadData*>(arg);
data.m_function(data.m_parameter);
*data.m_running = false;
}
}

119
internal/thread.hpp Normal file
View File

@ -0,0 +1,119 @@
#pragma once
#include <3ds.h>
#include <atomic>
#include <functional>
#include <string>
#include "parameter.hpp"
using CTRU_Thread = Thread;
#define THREAD_STACK_SIZE 0x1000
namespace RenderD7 {
namespace Threads
{
inline bool threadrunning = false;
struct Thread
{
Handle handle;
void (*ep)(void);
bool finished;
void* stacktop;
};
bool Create();
bool Join();
void Exit();
}
class Thread {
public:
/**
* @brief Default constructor
* @note This should only be called when calling m3d::Thread::initialize() before calling m3d::Thread::start()
*/
Thread();
/**
* @brief Constructs the thread
* @param t_function The thread function
* @param t_parameter The parameter to pass to the function
* @param t_autostart Whether the thread should start instantly
* @param t_detached Whether the thread starts detached or not
* @param t_stackSize The stacksize allocated for the thread in bytes (rounded to multiples of 8 bytes)
* @note t_function needs to be of type `void` and take one (and only one) parameter of type m3d::Parameter
* @warning If the thread priority is lower than the priority of the calling thread, the thread will never get executed. Use m3d::Thread::getCurrentPriority() to get the priority of the current thread
*/
Thread(std::function<void(RenderD7::Parameter)> t_function, RenderD7::Parameter t_parameter = nullptr, bool t_autostart = false, bool t_detached = false, unsigned long long int t_stackSize = 4 * 1024);
/**
* @brief Destructs the thread
*/
virtual ~Thread();
/**
* @brief Initializes the thread
* @param t_function The thread function
* @param t_parameter The parameter to pass to the function
* @param t_autostart Whether the thread should start instantly
* @param t_detached Whether the thread starts detached or not
* @param t_stackSize The stacksize allocated for the thread in bytes (rounded to multiples of 8 bytes)
* @note t_function needs to be of type `void` and take one (and only one) parameter of type m3d::Parameter
* @warning If the thread priority is lower than the priority of the calling thread, the thread will never get executed. Use m3d::Thread::getCurrentPriority() to get the priority of the current thread
*/
void initialize(std::function<void(RenderD7::Parameter)> t_function, RenderD7::Parameter t_parameter = nullptr, bool t_autostart = false, bool t_detached = false, unsigned long long int t_stackSize = 4 * 1024);
/**
* @brief Sets the size of the stack that gets allocated for the next thread that get's started
* @param t_stackSize The allocated space in bytes (rounded to multiples of 8 bytes)
*/
void setStackSize(unsigned long long int t_stackSize);
/**
* @brief Starts the thread. To restart it, call Thread::join() before
* @param t_detached Whether the thread should start detached or not
*/
void start(bool t_detached = false);
/**
* @brief Detaches the thread
*/
void detach();
/**
* @brief Waits for the thread to finish
* @param t_timeout The timeout in nanoseconds. Leave it for no timeout
*/
void join(long long unsigned int t_timeout = U64_MAX);
bool isRunning();
/**
* @brief Puts the thread to sleep
*
* This is needed if you have multiple threads running at the same time. It doesn't affect the execution-time of the thread, it just makes it possible for the other threads to get their chance to shine.
*/
static void sleep();
/**
* @brief Sleeps for the given time
* @param t_milliseconds The time to sleep in milliseconds
*/
static void sleep(int t_milliseconds);
private:
struct ThreadData {
RenderD7::Parameter m_parameter;
std::function<void(RenderD7::Parameter)> m_function;
std::atomic<bool>* m_running;
};
static void threadFunction(void* t_arg);
/* data */
int m_priority, m_stackSize;
bool m_started;
std::atomic<bool> m_running;
RenderD7::Thread::ThreadData m_data;
CTRU_Thread m_thread;
};
}

60
log.cpp Normal file
View File

@ -0,0 +1,60 @@
#include "log.hpp"
#include <memory>
std::string Log::format(const std::string& fmt_str, ...)
{
va_list ap;
char* fp = NULL;
va_start(ap, fmt_str);
vasprintf(&fp, fmt_str.c_str(), ap);
va_end(ap);
std::unique_ptr<char, decltype(free)*> formatted(fp, free);
return std::string(formatted.get());
}
std::string Log::logDate(void)
{
time_t unixTime;
struct tm timeStruct;
time(&unixTime);
localtime_r(&unixTime, &timeStruct);
return format("%04i-%02i-%02i %02i:%02i:%02i", timeStruct.tm_year + 1900, timeStruct.tm_mon + 1, timeStruct.tm_mday,
timeStruct.tm_hour, timeStruct.tm_min, timeStruct.tm_sec);
}
Log::Log()
{
}
void Log::Init(const char *filename)
{
std::string name = "logs/Log_" + Log::logDate() + filename + ".txt";
this->filename = name.c_str();
if ((access(name.c_str(), F_OK) == 0))
{
}
else
{
FILE* logfile = fopen((name.c_str()), "w");
fclose(logfile);
}
}
void Log::Write(std::string debug_text)
{
std::ofstream logFile;
logFile.open((this->filename), std::ofstream::app);
std::string writeDebug = "[";
writeDebug += logDate();
writeDebug += "] ";
writeDebug += debug_text.c_str();
logFile << writeDebug << std::endl;
logFile.close();
}
Log::~Log()
{
}

19
log.hpp Normal file
View File

@ -0,0 +1,19 @@
#pragma once
#include <fstream>
#include <stdarg.h>
#include <string>
#include <time.h>
#include <unistd.h>
class Log
{
public:
Log();
~Log();
void Init(const char *filename);
void Write(std::string debug_text);
std::string logDate(void);
std::string format(const std::string& fmt_str, ...);
private:
std::string filename;
};

777
renderd7.cpp Normal file
View File

@ -0,0 +1,777 @@
#include "renderd7.hpp"
#include "log.hpp"
#include <regex>
#define RGBA8(r, g, b, a) ((((r) & 0xFF) << 0) | (((g) & 0xFF) << 8) | (((b) & 0xFF) << 16) | (((a) & 0xFF) << 24))
#define D7_NOTHING C2D_Color32(0, 0, 0, 0)
#define CFGVER "0"
Log renderd7log;
float animtime;
bool isndspinit = false;
bool running = true;
std::stack<std::unique_ptr<RenderD7::Scene>> RenderD7::Scene::scenes;
bool usedbgmsg = false;
std::string dspststus = "Not Initialisized!";
//INI::INIFile cfgfile;
std::unique_ptr<INI::INIFile> cfgfile = nullptr;
INI::INIStructure cfgstruct;
u32 d7_hDown;
u32 d7_hHeld;
u32 d7_hUp;
touchPosition d7_touch;
C2D_TextBuf TextBuf;
C2D_Font Font;
// Fps Calc
static float current_fps = 0.0f;
static unsigned int frames = 0;
static u64 last_time = 0;
float d11framerate = 0;
//-----------------
//Metrik-------------------------------------
u32 mt_color;
//-------------------------------------------
bool currentScreen = false;
bool metrikd = false;
C3D_RenderTarget* Top;
C3D_RenderTarget* TopRight;
C3D_RenderTarget* Bottom;
#define DSEVENBLACK C2D_Color32(0, 0 ,0, 255)
#define DSEVENWHITE C2D_Color32(255, 255, 255, 255)
RenderD7::SpriteSheetAnimation::SpriteSheetAnimation()
{
renderd7log.Write("SpriteSheetAnimation createt!");
}
RenderD7::SpriteSheetAnimation::~SpriteSheetAnimation()
{
//
}
bool RenderD7::DrawImageFromSheet(RenderD7::Sheet* sheet, size_t index, float x, float y, float scaleX, float scaleY)
{
if (sheet->spritesheet != nullptr)
{
if (C2D_SpriteSheetCount(sheet->spritesheet) >= index)
{
return C2D_DrawImageAt(C2D_SpriteSheetGetImage(sheet->spritesheet, index), x, y, 0.5f, nullptr, scaleX, scaleY);
}
}
return false;
}
void RenderD7::Init::NdspFirm(bool useit)
{
if (useit)
{
if ( access( "sdmc:/3ds/dspfirm.cdc", F_OK ) != -1 )
{
ndspInit();
isndspinit = true;
dspststus = "Initialisized success!";
}
else
{
dspststus = "Not found: dspfirm.cdc";
renderd7log.Write("RenderD7: SoundEngine Error! ndspfirm not found!");
}
}
}
void RenderD7::Exit::NdspFirm()
{
if (isndspinit)
{
ndspExit();
}
}
void RenderD7::Msg::Display(std::string titletxt, std::string subtext, C3D_RenderTarget *target)
{
C3D_FrameBegin(C3D_FRAME_SYNCDRAW);
C2D_TargetClear(Top, DSEVENBLACK);
C2D_TargetClear(Bottom, DSEVENBLACK);
RenderD7::ClearTextBufs();
RenderD7::OnScreen(Top);
RenderD7::DrawRect(0, 0, 400, 240, RenderD7::Color::Hex("#111111"));
RenderD7::OnScreen(Bottom);
RenderD7::DrawRect(0, 0, 320, 240, RenderD7::Color::Hex("#111111"));
RenderD7::OnScreen(target);
RenderD7::DrawRect(0, 0, 400, 26, RenderD7::Color::Hex("#333333", 200));
RenderD7::DrawText(5, 2, 0.7f, DSEVENWHITE, titletxt);
RenderD7::DrawText(5, 30, 0.6f, DSEVENWHITE, subtext);
C3D_FrameEnd(0);
}
void RenderD7::Msg::DisplayWithProgress(std::string titletext, std::string subtext, float current, float total, u32 prgbarcolor)
{
RenderD7::ClearTextBufs();
C3D_FrameBegin(C3D_FRAME_SYNCDRAW);
C2D_TargetClear(Top, DSEVENBLACK);
C2D_TargetClear(Bottom, DSEVENBLACK);
char str[256];
snprintf(str, sizeof(str), "(%.2f%%)", ((float)current/(float)total) * 100.0f);
RenderD7::OnScreen(Top);
RenderD7::DrawRect(0, 0, 400, 240, RenderD7::Color::Hex("#111111"));
RenderD7::DrawRect(0, 0, 400, 26, RenderD7::Color::Hex("#333333", 200));
RenderD7::DrawText(5, 2, 0.7f, DSEVENWHITE, titletext);
RenderD7::DrawText(5, 30, 0.6f, DSEVENWHITE, subtext);
RenderD7::DrawRect(30, 120, 342, 30, RenderD7::Color::Hex("#333333"));
RenderD7::DrawRect(31, 121, (int)(((float)current / (float)total) * 338.0f), 28, prgbarcolor);
RenderD7::DrawTextCentered(5, 124, 0.7f, RenderD7::Color::Hex("#111111"), str, 390);
RenderD7::OnScreen(Bottom);
RenderD7::DrawRect(0, 0, 320, 240, RenderD7::Color::Hex("#111111"));
C3D_FrameEnd(0);
}
void RenderD7::SetupLog()
{
renderd7log.Init("sdmc:/Flappy-Bird-RenderD7.log");
}
void RenderD7::SpriteSheetAnimation::Setup(RenderD7::Sheet *sheet, size_t imagecount, size_t startimage, float frame_begin, float frame_finish)
{
D_totaltime = frame_begin;
renderd7log.Write("frame_begin success");
this->images = imagecount;
renderd7log.Write("imagecount success");
this->sheet = sheet;
renderd7log.Write("sheet success");
this->time = frame_finish;
renderd7log.Write("frame_finish success");
RenderD7::SpriteSheetAnimation::FromSheet(this->sheet, startimage);
}
void RenderD7::SpriteSheetAnimation::Play(float timespeed)
{
D_totaltime += timespeed;
if (D_totaltime >= time)
{
D_totaltime -= time;
imgs++;
if (imgs == images)
{
imgs = 0;
}
}
RenderD7::SpriteSheetAnimation::FromSheet(sheet, imgs);
//RenderD7::SpriteSheetAnimation::Draw();
}
void RenderD7::Error::DisplayError(std::string toptext, std::string errortext)
{
RenderD7::ClearTextBufs();
C3D_FrameBegin(C3D_FRAME_SYNCDRAW);
C2D_TargetClear(Top, DSEVENBLACK);
C2D_TargetClear(Bottom, DSEVENBLACK);
RenderD7::OnScreen(Top);
RenderD7::DrawTextCentered(0, 0, 0.7f, DSEVENWHITE, toptext, 400);
RenderD7::DrawTextCentered(0, 100, 0.6f, DSEVENWHITE, errortext, 400);
C3D_FrameEnd(0);
int time = 60*5;
for (int i = 0; i < 60*5; i++) {
RenderD7::Msg::DisplayWithProgress("", "\n\n\n" + std::to_string(i) + " / " + std::to_string(time), i, 60*5, RenderD7::Color::Hex("#00EE11"));
gspWaitForVBlank();
}
}
void RenderD7::Error::DisplayFatalError(std::string toptext, std::string errortext)
{
bool error___ = true;
RenderD7::ClearTextBufs();
C3D_FrameBegin(C3D_FRAME_SYNCDRAW);
C2D_TargetClear(Top, DSEVENBLACK);
C2D_TargetClear(Bottom, DSEVENBLACK);
RenderD7::OnScreen(Top);
RenderD7::DrawTextCentered(0, 0, 0.7f, DSEVENWHITE, toptext, 400);
RenderD7::DrawTextCentered(0, 100, 0.6f, DSEVENWHITE, errortext, 400);
RenderD7::DrawTextCentered(0, 200, 0.6f, DSEVENWHITE, "Press Start to Exit!", 400);
C3D_FrameEnd(0);
while (error___)
{
if(d7_hDown & KEY_START)
{
RenderD7::ExitApp();
}
}
}
u32 RenderD7::Color::Hex(const std::string color, u8 a)
{
if (color.length() < 7 || std::regex_search(color.substr(1), std::regex("[^0-9A-Fa-f]"))) { // invalid color.
return D7_NOTHING;
}
int r = std::stoi(color.substr(1, 2), nullptr, 16);
int g = std::stoi(color.substr(3, 2), nullptr, 16);
int b = std::stoi(color.substr(5, 2), nullptr, 16);
return RGBA8(r, g, b, a);
}
void RenderD7::Scene::doDraw() {
if(!RenderD7::Scene::scenes.empty())
RenderD7::Scene::scenes.top()->Draw();
}
void RenderD7::Scene::doLogic(u32 hDown, u32 hHeld, u32 hUp, touchPosition touch) {
if(!RenderD7::Scene::scenes.empty())
RenderD7::Scene::scenes.top()->Logic(hDown, hHeld, hUp, touch);
}
void RenderD7::Scene::Load(std::unique_ptr<Scene> scene)
{
Scene::scenes.push(std::move(scene));
}
void RenderD7::Scene::Back() {
if(RenderD7::Scene::scenes.size() > 0)
RenderD7::Scene::scenes.pop();
}
void RenderD7::OnScreen(C3D_RenderTarget *target)
{
C2D_SceneBegin(target);
}
void frameloop()
{
frames++;
u64 delta_time = osGetTime() - last_time;
if (delta_time >= 1000) {
current_fps = frames/(delta_time/1000.0f)+1;
frames = 0;
last_time = osGetTime();
}
d11framerate = current_fps;
}
float getframerate()
{
return d11framerate;
}
std::string RenderD7::GetFramerate()
{
return (std::to_string((int)d11framerate).substr(0, 2));
}
bool RenderD7::MainLoop()
{
if (!aptMainLoop()) return false;
hidScanInput();
d7_hDown = hidKeysDown();
d7_hUp = hidKeysUp();
d7_hHeld = hidKeysHeld();
hidTouchRead(&d7_touch);
RenderD7::ClearTextBufs();
C3D_FrameBegin(C3D_FRAME_SYNCDRAW);
C2D_TargetClear(Top, C2D_Color32(0, 0, 0, 0));
C2D_TargetClear(Bottom, C2D_Color32(0, 0, 0, 0));
frameloop();
if (metrikd)RenderD7::DrawMetrikOvl();
return running;
}
RenderD7::Sheet::Sheet()
{
//
}
RenderD7::Sheet::~Sheet()
{
//
}
Result RenderD7::Sheet::Load(const char *path)
{
this->spritesheet = C2D_SpriteSheetLoad(path);
return 0;
}
void RenderD7::Sheet::Free()
{
C2D_SpriteSheetFree(this->spritesheet);
}
RenderD7::Sprite::Sprite()
{
//
}
RenderD7::Sprite::~Sprite()
{
//
}
void RenderD7::Sprite::FromSheet(RenderD7::Sheet *sheet, size_t index)
{
C2D_SpriteFromSheet(&this->sprite, sheet->spritesheet, index);
}
bool RenderD7::Sprite::Draw()
{
return C2D_DrawSprite(&this->sprite);
}
void RenderD7::Sprite::SetCenter(float x, float y)
{
C2D_SpriteSetCenter(&this->sprite, x, y);
}
void RenderD7::Sprite::SetPos(float x, float y)
{
C2D_SpriteSetPos(&this->sprite, x, y);
}
void RenderD7::Sprite::SetRotation(float rotation)
{
C2D_SpriteSetRotation(&this->sprite, rotation);
}
void RenderD7::Sprite::Rotate(float speed)
{
C2D_SpriteRotateDegrees(&this->sprite, speed);
}
float RenderD7::Sprite::getHeigh()
{
return this->sprite.params.pos.h;
}
float RenderD7::Sprite::getWidth()
{
return this->sprite.params.pos.w;
}
float RenderD7::Sprite::getPosX()
{
return this->sprite.params.pos.x;
}
float RenderD7::Sprite::getPosY()
{
return this->sprite.params.pos.y;
}
void RenderD7::Sprite::FromImage(RenderD7::Image *img)
{
C2D_SpriteFromImage(&this->sprite, img->img);
}
void RenderD7::Sprite::SetScale(float x, float y)
{
C2D_SpriteScale(&this->sprite, x, y);
}
void RenderD7::ClearTextBufs(void)
{
C2D_TextBufClear(TextBuf);
}
bool RenderD7::DrawRect(float x, float y, float w, float h, u32 color)
{
return C2D_DrawRectSolid(x, y, 0.5f, w, h, color);
}
void RenderD7::DrawTextCentered(float x, float y, float size, u32 color, std::string Text, int maxWidth, int maxHeight, C2D_Font fnt) {
float lineHeight, widthScale;
// Check for the lineHeight.
if (fnt != nullptr) {
lineHeight = RenderD7::GetTextHeight(size, " ", fnt);
} else {
lineHeight = RenderD7::GetTextHeight(size, " ");
}
int line = 0;
while(Text.find('\n') != Text.npos) {
if (maxWidth == 0) {
// Do the widthScale.
if (fnt != nullptr) {
widthScale = RenderD7::GetTextWidth(size, Text.substr(0, Text.find('\n')), fnt);
} else {
widthScale = RenderD7::GetTextWidth(size, Text.substr(0, Text.find('\n')));
}
} else {
// Do the widthScale 2.
if (fnt != nullptr) {
widthScale = std::min((float)maxWidth, RenderD7::GetTextWidth(size, Text.substr(0, Text.find('\n')), fnt));
} else {
widthScale = std::min((float)maxWidth, RenderD7::GetTextWidth(size, Text.substr(0, Text.find('\n'))));
}
}
if (fnt != nullptr) {
RenderD7::DrawText((currentScreen ? 200 : 160)+x-(widthScale/2), y+(lineHeight*line), size, color, Text.substr(0, Text.find('\n')), maxWidth, maxHeight, fnt);
} else {
RenderD7::DrawText((currentScreen ? 200 : 160)+x-(widthScale/2), y+(lineHeight*line), size, color, Text.substr(0, Text.find('\n')), maxWidth, maxHeight);
}
Text = Text.substr(Text.find('\n')+1);
line++;
}
if (maxWidth == 0) {
// Do the next WidthScale.
if (fnt != nullptr) {
widthScale = RenderD7::GetTextWidth(size, Text.substr(0, Text.find('\n')), fnt);
} else {
widthScale = RenderD7::GetTextWidth(size, Text.substr(0, Text.find('\n')));
}
} else {
// And again.
if (fnt != nullptr) {
widthScale = std::min((float)maxWidth, RenderD7::GetTextWidth(size, Text.substr(0, Text.find('\n')), fnt));
} else {
widthScale = std::min((float)maxWidth, RenderD7::GetTextWidth(size, Text.substr(0, Text.find('\n'))));
}
}
if (fnt != nullptr) {
RenderD7::DrawText((currentScreen ? 200 : 160)+x-(widthScale/2), y+(lineHeight*line), size, color, Text.substr(0, Text.find('\n')), maxWidth, maxHeight, fnt);
} else {
RenderD7::DrawText((currentScreen ? 200 : 160)+x-(widthScale/2), y+(lineHeight*line), size, color, Text.substr(0, Text.find('\n')), maxWidth, maxHeight);
}
}
// Draw String or Text.
void RenderD7::DrawText(float x, float y, float size, u32 color, std::string Text, int maxWidth, int maxHeight, C2D_Font fnt) {
C2D_Text c2d_text;
if (fnt != nullptr) {
C2D_TextFontParse(&c2d_text, fnt, TextBuf, Text.c_str());
} else {
C2D_TextFontParse(&c2d_text, Font, TextBuf, Text.c_str());
}
C2D_TextOptimize(&c2d_text);
float heightScale;
if (maxHeight == 0) {
heightScale = size;
} else {
if (fnt != nullptr) {
heightScale = std::min(size, size*(maxHeight/RenderD7::GetTextHeight(size, Text, fnt)));
} else {
heightScale = std::min(size, size*(maxHeight/RenderD7::GetTextHeight(size, Text)));
}
}
if (maxWidth == 0) {
C2D_DrawText(&c2d_text, C2D_WithColor, x, y, 0.5f, size, heightScale, color);
} else {
if (fnt != nullptr) {
C2D_DrawText(&c2d_text, C2D_WithColor, x, y, 0.5f, std::min(size, size*(maxWidth/RenderD7::GetTextWidth(size, Text, fnt))), heightScale, color);
} else {
C2D_DrawText(&c2d_text, C2D_WithColor, x, y, 0.5f, std::min(size, size*(maxWidth/RenderD7::GetTextWidth(size, Text))), heightScale, color);
}
}
}
void RenderD7::DrawTextLeft(float x, float y, float size, u32 color, std::string Text, int maxWidth, int maxHeight, C2D_Font fnt)
{
RenderD7::DrawText(x - RenderD7::GetTextWidth(size, Text, fnt), y, size, color, Text, maxWidth, maxHeight, fnt);
}
// Get String or Text Width.
float RenderD7::GetTextWidth(float size, std::string Text, C2D_Font fnt) {
float width = 0;
if (fnt != nullptr) {
GetTextSize(size, &width, NULL, Text, fnt);
} else {
GetTextSize(size, &width, NULL, Text);
}
return width;
}
// Get String or Text Size.
void RenderD7::GetTextSize(float size, float *width, float *height, std::string Text, C2D_Font fnt) {
C2D_Text c2d_text;
if (fnt != nullptr) {
C2D_TextFontParse(&c2d_text, fnt, TextBuf, Text.c_str());
} else {
C2D_TextFontParse(&c2d_text, Font, TextBuf, Text.c_str());
}
C2D_TextGetDimensions(&c2d_text, size, size, width, height);
}
// Get String or Text Height.
float RenderD7::GetTextHeight(float size, std::string Text, C2D_Font fnt) {
float height = 0;
if (fnt != nullptr) {
GetTextSize(size, NULL, &height, Text.c_str(), fnt);
} else {
GetTextSize(size, NULL, &height, Text.c_str());
}
return height;
}
Result RenderD7::loadFont(C2D_Font &fnt, const char* Path) {
fnt = C2D_FontLoad(Path); // Only load if found.
return 0;
}
// Unload a Font.
Result RenderD7::unloadFont(C2D_Font &fnt) {
if (fnt != nullptr) {
C2D_FontFree(fnt); // Make sure to only unload if not nullptr.
}
return 0;
}
bool RenderD7::DrawCircle(float x, float y, float radius, u32 color)
{
return C2D_DrawCircleSolid(x, y, 0.5f, radius, color);
}
void MetrikThread(RenderD7::Parameter param) {
while (true) {
RenderD7::DrawMetrikOvl();
RenderD7::Thread::sleep(1000 * 1); // wait; also, this is needed to allow for concurrency (refer to the documentation for m3d::Thread::sleep())
}
}
Result RenderD7::Init::Main()
{
gfxInitDefault();
aptInit();
romfsInit();
cfguInit();
mkdir("sdmc:/RenderD7/", 0777);
if (!FS::FileExist("sdmc:/RenderD7/config.ini"))
{
cfgfile = std::make_unique<INI::INIFile>("sdmc:/RenderD7/config.ini");
cfgfile->read(cfgstruct);
cfgstruct["info"]["version"] = CFGVER;
cfgstruct["info"]["renderd7ver"] = RENDERD7VSTRING;
cfgstruct["settings"]["doscreentimeout"] = "0";
cfgstruct["settings"]["forcetimeoutLB"] = "1";
cfgstruct["settings"]["forceFrameRate"] = "60";
cfgstruct["settings"]["super-reselution"] = "0";
cfgstruct["metrik-settings"]["enableoverlay"] = "0";
cfgstruct["metrik-settings"]["Screen"] = "0";
cfgstruct["metrik-settings"]["Color"] = "#ffffff";
cfgstruct["metrik-settings"]["ColorA"] = "255";
cfgfile->write(cfgstruct);
}
cfgfile = std::make_unique<INI::INIFile>("sdmc:/RenderD7/config.ini");
cfgfile->read(cfgstruct);
std::string Fps = cfgstruct["settings"]["forceFrameRate"];
C3D_FrameRate(RenderD7::Convert::StringtoFloat(Fps));
metrikd = RenderD7::Convert::FloatToBool(RenderD7::Convert::StringtoFloat(cfgstruct["metrik-settings"]["enableoverlay"]));
mt_color = RenderD7::Color::Hex(cfgstruct["metrik-settings"]["Color"], (u8)RenderD7::Convert::StringtoFloat(cfgstruct["metrik-settings"]["ColorA"]));
osSetSpeedupEnable(true);
/*if(metrikd)
{
RenderD7::Thread tr(MetrikThread);
tr.start();
}*/
C3D_Init(C3D_DEFAULT_CMDBUF_SIZE);
C2D_Init(C2D_DEFAULT_MAX_OBJECTS);
C2D_Prepare();
Top = C2D_CreateScreenTarget(GFX_TOP, GFX_LEFT);
TopRight = C2D_CreateScreenTarget(GFX_TOP, GFX_RIGHT);
Bottom = C2D_CreateScreenTarget(GFX_BOTTOM, GFX_LEFT);
TextBuf = C2D_TextBufNew(4096);
Font = C2D_FontLoadSystem(CFG_REGION_USA);
return 0;
}
void RenderD7::Exit::Main()
{
cfgfile->write(cfgstruct);
if (RenderD7::Threads::threadrunning) RenderD7::Threads::Exit();
C2D_TextBufDelete(TextBuf);
C2D_Fini();
C3D_Fini();
aptExit();
romfsExit();
cfguExit();
}
void RenderD7::DrawTObjects(std::vector<RenderD7::TObject> tobjects, u32 color, u32 txtcolor, int selection, u32 selbgcolor, u32 selcolor)
{
for(int i = 0; i < (int)tobjects.size(); i++)
{
if (selection == i)
{
RenderD7::DrawRect(tobjects[i].x - 2, tobjects[i].y - 2, tobjects[i].w + 4, tobjects[i].h + 4, selbgcolor);
RenderD7::DrawRect(tobjects[i].x, tobjects[i].y, tobjects[i].w, tobjects[i].h, color);
RenderD7::DrawRect(tobjects[i].x, tobjects[i].y, tobjects[i].w, tobjects[i].h, selcolor);
RenderD7::DrawText(tobjects[i].x + (tobjects[i].w/2) - RenderD7::GetTextHeight(tobjects[i].txtsize , tobjects[i].text) + tobjects[i].correctx, tobjects[i].y + (tobjects[i].h/2) - RenderD7::GetTextHeight(tobjects[i].txtsize, tobjects[i].text) + tobjects[i].correcty, tobjects[i].txtsize, txtcolor, tobjects[i].text);
}
else
{
RenderD7::DrawRect(tobjects[i].x, tobjects[i].y - 1, tobjects[i].w, tobjects[i].h, color);
RenderD7::DrawText(tobjects[i].x + (tobjects[i].w/2) - RenderD7::GetTextHeight(tobjects[i].txtsize , tobjects[i].text) + tobjects[i].correctx, tobjects[i].y + (tobjects[i].h/2) - RenderD7::GetTextHeight(tobjects[i].txtsize, tobjects[i].text) + tobjects[i].correcty, tobjects[i].txtsize, txtcolor, tobjects[i].text);
}
}
}
void RenderD7::ExitApp()
{
running = false;
}
bool RenderD7::touchTObj(touchPosition touch, RenderD7::TObject button)
{
if (touch.px >= button.x && touch.px <= (button.x + button.w) && touch.py >= button.y && touch.py <= (button.y + button.h)) return true;
else return false;
}
void RenderD7::DrawSTObject(std::vector<RenderD7::TObject> tobject, int tobjectindex, u32 color, u32 txtcolor)
{
RenderD7::DrawRect(tobject[tobjectindex].x, tobject[tobjectindex].y, tobject[tobjectindex].w, tobject[tobjectindex].h, color);
RenderD7::DrawText(tobject[tobjectindex].x + (tobject[tobjectindex].w/2) - RenderD7::GetTextHeight(tobject[tobjectindex].txtsize , tobject[tobjectindex].text) + tobject[tobjectindex].correctx, tobject[tobjectindex].y + (tobject[tobjectindex].h/2) - RenderD7::GetTextHeight(tobject[tobjectindex].txtsize, tobject[tobjectindex].text) + tobject[tobjectindex].correcty, tobject[tobjectindex].txtsize, txtcolor, tobject[tobjectindex].text);
}
bool RenderD7::NameIsEndingWith(const std::string &name, const std::vector<std::string> &extensions) {
if (name.substr(0, 2) == "._") return false;
if (name.size() == 0) return false;
if (extensions.size() == 0) return true;
for(int i = 0; i < (int)extensions.size(); i++) {
const std::string ext = extensions.at(i);
if (strcasecmp(name.c_str() + name.size() - ext.size(), ext.c_str()) == 0) return true;
}
return false;
}
bool dirEntryPredicate(const RenderD7::DirContent &lhs, const RenderD7::DirContent &rhs) {
if (!lhs.isDir && rhs.isDir) return false;
if (lhs.isDir && !rhs.isDir) return true;
return strcasecmp(lhs.name.c_str(), rhs.name.c_str()) < 0;
}
void RenderD7::GetDirContentsExt(std::vector<RenderD7::DirContent> &dircontent, const std::vector<std::string> &extensions) {
struct stat st;
dircontent.clear();
DIR *pdir = opendir(".");
if (pdir != nullptr) {
while(true) {
RenderD7::DirContent dirEntry;
struct dirent *pent = readdir(pdir);
if (pent == NULL) break;
stat(pent->d_name, &st);
dirEntry.name = pent->d_name;
dirEntry.isDir = (st.st_mode & S_IFDIR) ? true : false;
if (dirEntry.name.compare(".") != 0 && (dirEntry.isDir || RenderD7::NameIsEndingWith(dirEntry.name, extensions))) {
dircontent.push_back(dirEntry);
}
}
closedir(pdir);
}
sort(dircontent.begin(), dircontent.end(), dirEntryPredicate);
}
void RenderD7::GetDirContents(std::vector<RenderD7::DirContent> &dircontent) {
RenderD7::GetDirContentsExt(dircontent, {});
}
void RenderD7::Image::LoadPng(const std::string path)
{
if (usedbgmsg)
{
RenderD7::Msg::Display("RenderD7", "Loading Png:" + path, Top);
}
std::vector<u8> ImageBuffer;
unsigned width, height;
if (loadet)
{
C3D_TexDelete(this->img.tex);
}
lodepng::decode(ImageBuffer, width, height, path);
this->img.tex = new C3D_Tex;
this->img.subtex = new Tex3DS_SubTexture({(u16)width, (u16)height, 0.0f, 1.0f, width / 1024.0f, 1.0f - (height / 1024.0f)});
C3D_TexInit(this->img.tex, 1024, 1024, GPU_RGBA8);
C3D_TexSetFilter(this->img.tex, GPU_LINEAR, GPU_LINEAR);
this->img.tex->border = 0xFFFFFFFF;
C3D_TexSetWrap(this->img.tex, GPU_CLAMP_TO_BORDER, GPU_CLAMP_TO_BORDER);
for (u32 x = 0; x < width && x < 1024; x++) {
for (u32 y = 0; y < height && y < 1024; y++) {
const u32 dstPos = ((((y >> 3) * (1024 >> 3) + (x >> 3)) << 6) +
((x & 1) | ((y & 1) << 1) | ((x & 2) << 1) | ((y & 2) << 2) |
((x & 4) << 2) | ((y & 4) << 3))) * 4;
const u32 srcPos = (y * width + x) * 4;
((uint8_t *)this->img.tex->data)[dstPos + 0] = ImageBuffer.data()[srcPos + 3];
((uint8_t *)this->img.tex->data)[dstPos + 1] = ImageBuffer.data()[srcPos + 2];
((uint8_t *)this->img.tex->data)[dstPos + 2] = ImageBuffer.data()[srcPos + 1];
((uint8_t *)this->img.tex->data)[dstPos + 3] = ImageBuffer.data()[srcPos + 0];
}
}
loadet = true;
}
void RenderD7::Image::LoadPFromBuffer(const std::vector<u8> &buffer)
{
std::vector<u8> ImageBuffer;
if (loadet)
{
C3D_TexDelete(this->img.tex);
}
unsigned width, height;
lodepng::decode(ImageBuffer, width, height, buffer);
img.tex = new C3D_Tex;
img.subtex = new Tex3DS_SubTexture({(u16)width, (u16)height, 0.0f, 1.0f, width / 512.0f, 1.0f - (height / 512.0f)});
C3D_TexInit(img.tex, 512, 512, GPU_RGBA8);
C3D_TexSetFilter(img.tex, GPU_LINEAR, GPU_LINEAR);
img.tex->border = 0xFFFFFFFF;
C3D_TexSetWrap(img.tex, GPU_CLAMP_TO_BORDER, GPU_CLAMP_TO_BORDER);
for (u32 x = 0; x < width && x < 512; x++) {
for (u32 y = 0; y < height && y < 512; y++) {
const u32 dstPos = ((((y >> 3) * (512 >> 3) + (x >> 3)) << 6) +
((x & 1) | ((y & 1) << 1) | ((x & 2) << 1) | ((y & 2) << 2) |
((x & 4) << 2) | ((y & 4) << 3))) * 4;
const u32 srcPos = (y * width + x) * 4;
((uint8_t *)img.tex->data)[dstPos + 0] = ImageBuffer.data()[srcPos + 3];
((uint8_t *)img.tex->data)[dstPos + 1] = ImageBuffer.data()[srcPos + 2];
((uint8_t *)img.tex->data)[dstPos + 2] = ImageBuffer.data()[srcPos + 1];
((uint8_t *)img.tex->data)[dstPos + 3] = ImageBuffer.data()[srcPos + 0];
}
}
}
bool RenderD7::DrawImage(C2D_Image img, float x, float y, float scaleX, float scaleY)
{
return C2D_DrawImageAt(img, x, y, 0.5f, nullptr, scaleX, scaleY);
}
bool RenderD7::Image::Draw(float x, float y, float scaleX, float scaleY)
{
return C2D_DrawImageAt(this->img, x, y, 0.5f, nullptr, scaleX, scaleY);
}
bool RenderD7::FS::FileExist(const std::string& path)
{
FILE *test = fopen(path.c_str(), "r");
if(test != NULL)
{
fclose(test);
return true;
}
return false;
}
bool RenderD7::IsNdspInit()
{
if (isndspinit)
{
return true;
}
else
{
return false;
}
}
void RenderD7::DrawList1(RenderD7::ScrollList1 &l, float txtsize, C3D_RenderTarget *t)
{
RenderD7::OnScreen(t);
RenderD7::DrawRect(0, 0, 400, 240, RenderD7::Color::Hex("#dddddd"));
RenderD7::DrawText(0, 0, 0.8f, RenderD7::Color::Hex("#ffffff"), l.Text);
}
void RenderD7::DrawMetrikOvl()
{
RenderD7::OnScreen(Top);
RenderD7::DrawText(0, 0, 0.6f, mt_color, "HI");
}

212
renderd7.hpp Normal file
View File

@ -0,0 +1,212 @@
#pragma once
#include <3ds.h>
#include <citro2d.h>
#include <citro3d.h>
#include <memory>
#include <stack>
#include <string>
#include <functional>
#include <vector>
#include <dirent.h>
#include <unistd.h>
#include <stdio.h>
#include <cstring>
#include <sys/stat.h>
#include <algorithm>
#include <iostream>
#include "external/lodepng.h"
#include "external/fs.h"
#include <codecvt>
#include "lang.hpp"
#include "parameter.hpp"
#include "thread.hpp"
#include "ini.hpp"
#define RENDERD7VSTRING "6.1.0"
#define CHANGELOG "6.1.0: rewrite Threadsystem, Improve framerate/n6.0.2: Fix Code in lang.hpp\nadd Draw Text Left Function.\nadd changelog\n6.0.1: add Threading system."
#define DEFAULT_CENTER 0.5f
extern C3D_RenderTarget* Top;
extern C3D_RenderTarget* TopRight;
extern C3D_RenderTarget* Bottom;
extern u32 d7_hDown;
extern u32 d7_hHeld;
extern u32 d7_hUp;
extern touchPosition d7_touch;
extern std::string dspststus;
namespace RenderD7
{
void OnScreen(C3D_RenderTarget *target);
class Sheet
{
public:
Sheet();
~Sheet();
Result Load(const char *path);
void Free();
C2D_SpriteSheet spritesheet;
};
class Image
{
public:
void LoadPng(const std::string path);
void LoadPFromBuffer(const std::vector<u8> &buffer);
bool Draw(float x, float y, float scaleX = 1.0f, float scaleY = 1.0f);
C2D_Image Get(){return this->img;}
C2D_Image img;
bool loadet = false;
};
class Sprite
{
public:
Sprite();
~Sprite();
void FromSheet(RenderD7::Sheet *sheet, size_t index);
void FromImage(RenderD7::Image *img);
bool Draw();
void SetCenter(float x, float y);
void SetPos(float x, float y);
void SetScale(float x, float y);
void SetRotation(float rotation);
void Rotate(float speed);
float getWidth();
float getHeigh();
float getPosX();
float getPosY();
private:
C2D_ImageTint tint;
C2D_Sprite sprite;
};
class Scene {
public:
static std::stack<std::unique_ptr<Scene>> scenes;
virtual ~Scene() {}
virtual void Logic(u32 hDown, u32 hHeld, u32 hUp, touchPosition touch) = 0;
virtual void Draw() const = 0;
static void Load(std::unique_ptr<Scene> scene);
static void Back();
static void doDraw();
static void doLogic(u32 hDown, u32 hHeld, u32 hUp, touchPosition touch);
};
namespace Color
{
u32 Hex(const std::string color, u8 a = 255);
}
void DrawMetrikOvl();
bool DrawImageFromSheet(RenderD7::Sheet* sheet, size_t index, float x, float y, float scaleX = 1.0, float scaleY = 1.0);
namespace Error
{
void DisplayError(std::string toptext, std::string errortext);
void DisplayFatalError(std::string toptext, std::string errortext);
}
namespace Init
{
Result Main();
void NdspFirm(bool useit = false);
}
namespace Exit
{
void Main();
void NdspFirm();
}
namespace Msg
{
void Display(std::string titletxt, std::string subtext, C3D_RenderTarget *target);
void DisplayWithProgress(std::string titletext, std::string subtext, float current, float total, u32 prgbarcolor);
}
namespace Convert
{
inline float StringtoFloat(std::string inp){return std::atof(inp.c_str());}
inline bool FloatToBool(float inp){if(inp == 1)return true; else return false;}
}
namespace FS
{
bool FileExist(const std::string& path);
}
bool IsNdspInit();
void SetupLog(void);
std::string GetFramerate();
bool MainLoop();
void ExitApp();
void ClearTextBufs(void);
bool DrawRect(float x, float y, float w, float h, u32 color);
void DrawTextCentered(float x, float y, float size, u32 color, std::string Text, int maxWidth = 0, int maxHeight = 0, C2D_Font fnt = nullptr);
void DrawText(float x, float y, float size, u32 color, std::string Text, int maxWidth = 0, int maxHeight = 0, C2D_Font fnt = nullptr);
void DrawTextLeft(float x, float y, float size, u32 color, std::string Text, int maxWidth = 0, int maxHeight = 0, C2D_Font fnt = nullptr);
float GetTextWidth(float size, std::string Text, C2D_Font fnt = nullptr);
void GetTextSize(float size, float *width, float *height, std::string Text, C2D_Font fnt = nullptr);
float GetTextHeight(float size, std::string Text, C2D_Font fnt = nullptr);
Result loadFont(C2D_Font &fnt, const char * Path = "");
Result unloadFont(C2D_Font &fnt);
bool DrawCircle(float x, float y, float radius, u32 color);
bool DrawImage(C2D_Image img, float x, float y, float scaleX = 1.0f, float scaleY = 1.0f);
class SpriteSheetAnimation : public RenderD7::Sprite
{
public:
SpriteSheetAnimation();
~SpriteSheetAnimation();
void Setup(RenderD7::Sheet *sheet, size_t imagecount, size_t startimage, float frame_begin, float frame_finish);
void Play(float timespeed);
private:
size_t images;
size_t imgs = 0;
float D_totaltime;
RenderD7::Sheet *sheet;
float time;
};
struct TObject
{
int x; //Position X
int y; //Position Y
int w; //Button Width
int h; //Button Height
std::string text = ""; //Text
float correctx = 0; //Correct X Position
float correcty = 0; //Correct Y Position
float txtsize = 0.7f; //Set Text Size
};
struct ScrollList1
{
std::string Text = "";
};
struct ScrollList2
{
float x;
float y;
float w;
float h;
std::string Text = "";
};
/*enum ListType
{
ONE,
TWO
};*/
void DrawList1(RenderD7::ScrollList1 &l, float txtsize, C3D_RenderTarget *t);
void DrawTObjects(std::vector<RenderD7::TObject> tobjects, u32 color, u32 txtcolor, int selection = -1, u32 selbgcolor = RenderD7::Color::Hex("#2D98AF"), u32 selcolor = RenderD7::Color::Hex("#000000"));
void DrawSTObject(std::vector<RenderD7::TObject> tobject, int tobjectindex, u32 color, u32 txtcolor);
bool touchTObj(touchPosition touch, RenderD7::TObject button);
struct DirContent
{
std::string name;
std::string path;
bool isDir;
};
bool NameIsEndingWith(const std::string &name, const std::vector<std::string> &extensions);
void GetDirContentsExt(std::vector<RenderD7::DirContent> &dircontent, const std::vector<std::string> &extensions);
void GetDirContents(std::vector<RenderD7::DirContent> &dircontent);
}

125
sound.cpp Normal file
View File

@ -0,0 +1,125 @@
#include "sound.hpp"
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <string>
using std::string;
// Reference: http://yannesposito.com/Scratch/en/blog/2010-10-14-Fun-with-wav/
typedef struct _WavHeader {
char magic[4]; // "RIFF"
u32 totallength; // Total file length, minus 8.
char wavefmt[8]; // Should be "WAVEfmt "
u32 format; // 16 for PCM format
u16 pcm; // 1 for PCM format
u16 channels; // Channels
u32 frequency; // Sampling frequency
u32 bytes_per_second;
u16 bytes_by_capture;
u16 bits_per_sample;
char data[4]; // "data"
u32 bytes_in_data;
} WavHeader;
static_assert(sizeof(WavHeader) == 44, "WavHeader size is not 44 bytes.");
sound::sound(const string& path, int channel, bool toloop) {
ndspSetOutputMode(NDSP_OUTPUT_STEREO);
ndspSetOutputCount(2); // Num of buffers
// Reading wav file
FILE* fp = fopen(path.c_str(), "rb");
if (!fp) {
printf("Could not open the WAV file: %s\n", path.c_str());
return;
}
WavHeader wavHeader;
size_t read = fread(&wavHeader, 1, sizeof(wavHeader), fp);
if (read != sizeof(wavHeader)) {
// Short read.
printf("WAV file header is too short: %s\n", path.c_str());
fclose(fp);
return;
}
// Verify the header.
static const char RIFF_magic[4] = {'R','I','F','F'};
if (memcmp(wavHeader.magic, RIFF_magic, sizeof(wavHeader.magic)) != 0) {
// Incorrect magic number.
printf("Wrong file format.\n");
fclose(fp);
return;
}
if (wavHeader.totallength == 0 ||
(wavHeader.channels != 1 && wavHeader.channels != 2) ||
(wavHeader.bits_per_sample != 8 && wavHeader.bits_per_sample != 16)) {
// Unsupported WAV file.
printf("Corrupted wav file.\n");
fclose(fp);
return;
}
// Get the file size.
fseek(fp, 0, SEEK_END);
dataSize = ftell(fp) - sizeof(wavHeader);
// Allocating and reading samples
data = static_cast<u8*>(linearAlloc(dataSize));
fseek(fp, 44, SEEK_SET);
fread(data, 1, dataSize, fp);
fclose(fp);
dataSize /= 2; // FIXME: 16-bit or stereo?
// Find the right format
u16 ndspFormat;
if (wavHeader.bits_per_sample == 8) {
ndspFormat = (wavHeader.channels == 1) ?
NDSP_FORMAT_MONO_PCM8 :
NDSP_FORMAT_STEREO_PCM8;
} else {
ndspFormat = (wavHeader.channels == 1) ?
NDSP_FORMAT_MONO_PCM16 :
NDSP_FORMAT_STEREO_PCM16;
}
ndspChnReset(channel);
ndspChnSetInterp(channel, NDSP_INTERP_NONE);
ndspChnSetRate(channel, float(wavHeader.frequency));
ndspChnSetFormat(channel, ndspFormat);
// Create and play a wav buffer
memset(&waveBuf, 0, sizeof(waveBuf));
waveBuf.data_vaddr = reinterpret_cast<u32*>(data);
waveBuf.nsamples = dataSize / (wavHeader.bits_per_sample >> 3);
waveBuf.looping = toloop;
waveBuf.status = NDSP_WBUF_FREE;
chnl = channel;
}
sound::~sound() {
waveBuf.data_vaddr = 0;
waveBuf.nsamples = 0;
waveBuf.looping = false;
waveBuf.status = 0;
ndspChnWaveBufClear(chnl);
if (data) {
linearFree(data);
}
}
void sound::play() {
if (!data) return;
DSP_FlushDataCache(data, dataSize);
ndspChnWaveBufAdd(chnl, &waveBuf);
}
void sound::stop() {
if (!data) return;
ndspChnWaveBufClear(chnl);
}

Some files were not shown because too many files have changed in this diff Show More