Skip to content

Commit

Permalink
Add: Emscripten Compiler
Browse files Browse the repository at this point in the history
  • Loading branch information
LittleYang0531 committed Aug 16, 2024
1 parent 196aa81 commit f69ce25
Show file tree
Hide file tree
Showing 12 changed files with 80 additions and 16 deletions.
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,6 @@ make
*.json
test*
!LevelData.h
*.pec
*.pec
emsdk
libphigros*
6 changes: 3 additions & 3 deletions convert.h
Original file line number Diff line number Diff line change
Expand Up @@ -630,7 +630,7 @@ string fromPGS(string json, double bgmOffset = 0) {

// ========================================================================================
//
// PEC Format Chart --> Official Phigros Format Chart
// PEC Format Chart --> Official Phigros Format Chart (Modded)
//
// ========================================================================================

Expand Down Expand Up @@ -807,7 +807,7 @@ string fromPEC(string txt, double bgmOffset = 0) {

// ========================================================================================
//
// RPE Format Chart --> Official Phigros Format Chart
// RPE Format Chart --> Official Phigros Format Chart (Modded)
//
// ========================================================================================

Expand Down Expand Up @@ -1131,7 +1131,7 @@ string fromRPE(string json, double bgmOffset = 0) {
note["isFake"].asBool(),
note["speed"].asDouble(),
note["size"].asDouble(),
note["yOffset"].asDouble(),
note["yOffset"].asDouble() / 900.0,
note["visibleTime"].asDouble(),
note["alpha"].asDouble() / 255.0,
0
Expand Down
7 changes: 7 additions & 0 deletions emake
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
emcc emscripten.cpp -o libphigros.js -s MODULARIZE -s EXPORT_ES6=1\
-sDEFAULT_LIBRARY_FUNCS_TO_INCLUDE=['$stringToNewUTF8','$UTF8ToString']\
-sEXPORTED_RUNTIME_METHODS=['stringToNewUTF8','UTF8ToString']\
-fwasm-exceptions -sASSERTIONS\
-I./emsdk/include -L./emsdk/lib \
-ljsoncpp \
-sALLOW_MEMORY_GROWTH -g -O3
55 changes: 55 additions & 0 deletions emscripten.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
// 将 convert.h 中的代码转为 js 用于 PhiStore
#include<jsoncpp/json/json.h>
#include<iostream>
#include<iomanip>
#include<vector>
#include<map>
#include<cstring>
#include<set>
#include<queue>
#include<assert.h>
#include<sstream>
#include<algorithm>
using namespace std;
void throwWarning(string s) { cerr << "Warning: " << s << endl; }
#include"sonolus/items/LevelData.h"
#include"sonolus/modules/json.h"
#include"convert.h"

#ifndef EM_PORT_API
# if defined(__EMSCRIPTEN__)
# include <emscripten.h>
# if defined(__cplusplus)
# define EM_PORT_API(rettype) extern "C" rettype EMSCRIPTEN_KEEPALIVE
# else
# define EM_PORT_API(rettype) rettype EMSCRIPTEN_KEEPALIVE
# endif
# else
# if defined(__cplusplus)
# define EM_PORT_API(rettype) extern "C" rettype
# else
# define EM_PORT_API(rettype) rettype
# endif
# endif
#endif

extern "C" EMSCRIPTEN_KEEPALIVE char* json2data(char* input) {
string data; data = string(input, strlen(input));
string res = fromPGS(data, 0);
char* result = const_cast<char*>(res.c_str());
return result;
}

extern "C" EMSCRIPTEN_KEEPALIVE char* pec2json(char* input) {
string data; data = string(input, strlen(input));
string res = fromPEC(data, 0);
char* result = const_cast<char*>(res.c_str());
return result;
}

extern "C" EMSCRIPTEN_KEEPALIVE char* rpe2json(char* input) {
string data; data = string(input, strlen(input));
string res = fromRPE(data, 0);
char* result = const_cast<char*>(res.c_str());
return result;
}
2 changes: 1 addition & 1 deletion engine/play/notes/DragNote.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ class DragNote: public Archetype {
IF (times.now < time && currentFloorPosition < floorPositionLimit) Return(0); FI
IF (currentFloorPosition * speed > 10 / 3 * 5.85) Return(0); FI
var dx = positionX * stage.w * 0.05625;
var dy = positionY * speed * stage.h * 0.6;
var dy = If(isAbove, positionY + yOffset, positionY - yOffset) * speed * stage.h * 0.6;

var rotate = line.get(3);
var r = Power({dx * dx + dy * dy, 0.5});
Expand Down
2 changes: 1 addition & 1 deletion engine/play/notes/FlickNote.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ class FlickNote: public Archetype {
IF (times.now < time && currentFloorPosition < floorPositionLimit) Return(0); FI
IF (currentFloorPosition * speed > 10 / 3 * 5.85) Return(0); FI
var dx = positionX * stage.w * 0.05625;
var dy = positionY * speed * stage.h * 0.6;
var dy = If(isAbove, positionY + yOffset, positionY - yOffset) * speed * stage.h * 0.6;

var rotate = line.get(3);
var r = Power({dx * dx + dy * dy, 0.5});
Expand Down
6 changes: 3 additions & 3 deletions engine/play/notes/HoldNote.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -183,9 +183,9 @@ class HoldNote: public Archetype {
IF (times.now < time && currentFloorPosition < floorPositionLimit) Return(0); FI
IF (currentFloorPosition * 1 > 10 / 3 * 5.85) Return(0); FI
var dx = positionX * stage.w * 0.05625;
var dy = positionY * stage.h * 0.6;
IF (times.now > time) dy = 0; FI
var dy2 = If(isAbove, endFloorPosition - line.get(5), endFloorPosition + line.get(5)) * stage.h * 0.6;
var dy = If(isAbove, positionY + yOffset, positionY - yOffset) * stage.h * 0.6;
IF (times.now > time) dy = If(isAbove, yOffset, -1 * yOffset); FI
var dy2 = If(isAbove, endFloorPosition - line.get(5) + yOffset, endFloorPosition + line.get(5) - yOffset) * stage.h * 0.6;

var rotate = line.get(3);
var r = Power({dx * dx + dy * dy, 0.5});
Expand Down
2 changes: 1 addition & 1 deletion engine/play/notes/NormalNote.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ class NormalNote: public Archetype {
IF (times.now < time && currentFloorPosition < floorPositionLimit) Return(0); FI
IF (currentFloorPosition * speed > 10 / 3 * 5.85) Return(0); FI
var dx = positionX * stage.w * 0.05625;
var dy = positionY * speed * stage.h * 0.6;
var dy = If(isAbove, positionY + yOffset, positionY - yOffset) * speed * stage.h * 0.6;

var rotate = line.get(3);
var r = Power({dx * dx + dy * dy, 0.5});
Expand Down
2 changes: 1 addition & 1 deletion engine/watch/notes/DragNote.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ class DragNote: public Archetype {
IF (times.now < time && currentFloorPosition < floorPositionLimit) Return(0); FI
IF (currentFloorPosition * speed > 10 / 3 * 5.85) Return(0); FI
var dx = positionX * stage.w * 0.05625;
var dy = positionY * speed * stage.h * 0.6;
var dy = If(isAbove, positionY + yOffset, positionY - yOffset) * speed * stage.h * 0.6;

var rotate = line.get(3);
var r = Power({dx * dx + dy * dy, 0.5});
Expand Down
2 changes: 1 addition & 1 deletion engine/watch/notes/FlickNote.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ class FlickNote: public Archetype {
IF (times.now < time && currentFloorPosition < floorPositionLimit) Return(0); FI
IF (currentFloorPosition * speed > 10 / 3 * 5.85) Return(0); FI
var dx = positionX * stage.w * 0.05625;
var dy = positionY * speed * stage.h * 0.6;
var dy = If(isAbove, positionY + yOffset, positionY - yOffset) * speed * stage.h * 0.6;

var rotate = line.get(3);
var r = Power({dx * dx + dy * dy, 0.5});
Expand Down
6 changes: 3 additions & 3 deletions engine/watch/notes/HoldNote.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -130,9 +130,9 @@ class HoldNote: public Archetype {
IF (times.now < time && currentFloorPosition < floorPositionLimit) Return(0); FI
IF (currentFloorPosition * 1 > 10 / 3 * 5.85) Return(0); FI
var dx = positionX * stage.w * 0.05625;
var dy = positionY * stage.h * 0.6;
IF (times.now > time) dy = 0; FI
var dy2 = If(isAbove, endFloorPosition - line.get(5), endFloorPosition + line.get(5)) * stage.h * 0.6;
var dy = If(isAbove, positionY + yOffset, positionY - yOffset) * stage.h * 0.6;
IF (times.now > time) dy = If(isAbove, yOffset, -1 * yOffset); FI
var dy2 = If(isAbove, endFloorPosition - line.get(5) + yOffset, endFloorPosition + line.get(5) - yOffset) * stage.h * 0.6;

var rotate = line.get(3);
var r = Power({dx * dx + dy * dy, 0.5});
Expand Down
2 changes: 1 addition & 1 deletion engine/watch/notes/NormalNote.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ class NormalNote: public Archetype {
IF (currentFloorPosition * speed > 10 / 3 * 5.85) Return(0); FI
// IF (time == 9194 * timeMagic / bpm) Debuglog(positionY); FI
var dx = positionX * stage.w * 0.05625;
var dy = positionY * speed * stage.h * 0.6;
var dy = If(isAbove, positionY + yOffset, positionY - yOffset) * speed * stage.h * 0.6;

var rotate = line.get(3);
var r = Power({dx * dx + dy * dy, 0.5});
Expand Down

0 comments on commit f69ce25

Please sign in to comment.