Skip to content

Commit

Permalink
Update: Upgrade Sonolus.h
Browse files Browse the repository at this point in the history
  • Loading branch information
LittleYang0531 committed Aug 8, 2024
1 parent e46c828 commit dbab69f
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 57 deletions.
2 changes: 1 addition & 1 deletion engine/play/InputManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ class ClaimManager {
ClaimInfo getInfo(let index) {
auto note = EntityDataArray[index];
auto judgeline = EntitySharedMemoryArray[
note.get(If(EntityInfoArray[index].get(1) == 12, 9, 8))
note.get(If(EntityInfoArray[index].get(1) == getArchetypeId(HoldNote), 9, 8))
];
let dx = note.get(1) * stage.w * 0.05625;
let jx = judgeline.get(1), jy = judgeline.get(2);
Expand Down
2 changes: 1 addition & 1 deletion engine/watch/StageController.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class StageController: public Archetype {
var head = headNoteId.get();
IF (isReplay) {
FOR (i, 0, noteNumber, 1) {
var index = If(EntityInfoArray[head].get(1) == 10, 12, 11);
var index = If(EntityInfoArray[head].get(1) == getArchetypeId(HoldNote), 12, 11);
IF (EntityDataArray[head].get(index) != 0) combo = combo + 1;
ELSE combo = 0; FI
EntitySharedMemoryArray[head].set(2, combo);
Expand Down
57 changes: 16 additions & 41 deletions main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,6 @@ using namespace std;
const string dist = "./dist";
#include"engine/engine.cpp"

vector<string> explode(const char* seperator, const char* source) {
string src = source; vector<string> res;
while (src.find(seperator) != string::npos) {
int wh = src.find(seperator);
res.push_back(src.substr(0, src.find(seperator)));
src = src.substr(wh + string(seperator).size());
} res.push_back(src);
return res;
}

string readFile(string path) {
ifstream fin(path);
fin.seekg(0, ios::end);
Expand Down Expand Up @@ -86,9 +76,9 @@ int main(int argc, char** argv) {

engineConfiguration.ui = configurationUI;
#ifdef play
buffer data, configuration;
build<
// Replace with your archetypes here
build(
dist + "/EngineConfiguration",
dist + "/EngineData",
Initialization,
StageController,
InputManager,
Expand All @@ -107,33 +97,22 @@ int main(int argc, char** argv) {
FakeDragNote,
FakeHoldNote,
FakeFlickNote
>(configuration, data);
ofstream fout((dist + "/EngineConfiguration"));
for (int i = 0; i < configuration.size(); i++) fout << configuration.v[i];
fout.close(); fout.open((dist + "/EngineData"));
// ofstream fout((dist + "/EngineData"));
for (int i = 0; i < data.size(); i++) fout << data.v[i];
);
#elif tutorial
buffer data, configuration;
build(configuration, data);
ofstream fout((dist + "/EngineConfiguration"));
for (int i = 0; i < configuration.size(); i++) fout << configuration.v[i];
fout.close(); fout.open((dist + "/EngineTutorialData"));
for (int i = 0; i < data.size(); i++) fout << data.v[i];
build(
dist + "/EngineConfiguration",
dist + "/EngineTutorialData"
);
#elif preview
buffer data, configuration;
build<
// Replace with your archetypes here
build(
dist + "/EngineConfiguration",
dist + "/EnginePreviewData",
Initialization
>(configuration, data);
ofstream fout((dist + "/EngineConfiguration"));
for (int i = 0; i < configuration.size(); i++) fout << configuration.v[i];
fout.close(); fout.open((dist + "/EnginePreviewData"));
for (int i = 0; i < data.size(); i++) fout << data.v[i];
);
#elif watch
buffer data, configuration;
build<
// Replace with your archetypes here
build(
dist + "/EngineConfiguration",
dist + "/EngineWatchData",
Initialization,
StageController,
Judgeline,
Expand All @@ -151,11 +130,7 @@ int main(int argc, char** argv) {
FakeHoldNote,
FakeFlickNote,
UpdateJudgment
>(configuration, data);
ofstream fout((dist + "/EngineConfiguration"));
for (int i = 0; i < configuration.size(); i++) fout << configuration.v[i];
fout.close(); fout.open((dist + "/EngineWatchData"));
for (int i = 0; i < data.size(); i++) fout << data.v[i];
);
#endif

// 生成 Skin
Expand Down
44 changes: 30 additions & 14 deletions sonolus/sonolus.h
Original file line number Diff line number Diff line change
Expand Up @@ -229,26 +229,34 @@ void buildArchetype() {
if constexpr (sizeof...(Args)) buildArchetype<Args...>();
}

vector<string> explode(const char* seperator, const char* source) {
string src = source; vector<string> res;
while (src.find(seperator) != string::npos) {
int wh = src.find(seperator);
res.push_back(src.substr(0, src.find(seperator)));
src = src.substr(wh + string(seperator).size());
} res.push_back(src);
return res;
}

int allocatedArchetypeCount = 0;
map<string, int> archetypeId;
template<typename T, typename... Args>
void allocateArchetypeId() {
archetypeId[typeid(T).name()] = allocatedArchetypeCount++;
if constexpr (sizeof...(Args)) allocateArchetypeId<Args...>();
void allocateArchetypeId(string s) {
auto name = explode(", ", s.c_str());
for (auto i : name) archetypeId[i] = allocatedArchetypeCount++;
}

template<typename... Args>
void build(buffer& configurationBuffer, buffer& dataBuffer) {
void build(string configurationPath, string dataPath) {
Run(1 + 1 == 2); // 防止空函数爆炸
preloadElement = nodesContainer.top(); mergeNodeContainer();
createAllocatorBackup();
Json::Value configuration = engineConfiguration.toJsonObject();
configurationBuffer = compress_gzip(json_encode(configuration));
buffer configurationBuffer = compress_gzip(json_encode(configuration));
#ifdef play
allocateArchetypeId<Args...>();
buildArchetype<Args...>();
engineData.nodes = dataContainer;
dataBuffer = compress_gzip(json_encode(engineData.toJsonObject()));
buffer data = compress_gzip(json_encode(engineData.toJsonObject()));
#elif tutorial
cout << "Solving Archetype \"Sonolus Tutorial Default\"..." << endl;
time_t st = millitime();
Expand All @@ -267,24 +275,32 @@ void build(buffer& configurationBuffer, buffer& dataBuffer) {
<< fixed << setprecision(0)
<< 1.0 * (globalCounter - lastGlobalCounter) / (1.0 * d / 1000) << " nodes/s. Total: "
<< (globalCounter - lastGlobalCounter) << " nodes." << endl;
dataBuffer = compress_gzip(json_encode(engineTutorialData.toJsonObject()));
buffer data = compress_gzip(json_encode(engineTutorialData.toJsonObject()));
#elif preview
allocateArchetypeId<Args...>();
buildArchetype<Args...>();
enginePreviewData.nodes = dataContainer;
dataBuffer = compress_gzip(json_encode(enginePreviewData.toJsonObject()));
buffer data = compress_gzip(json_encode(enginePreviewData.toJsonObject()));
#elif watch
allocateArchetypeId<Args...>();
buildArchetype<Args...>();
createNodeContainer(); auto tmpres = engineWatchData_updateSpawn();
if (nodesContainer.top().size() == 0) Return(tmpres);
engineWatchData.updateSpawn = mergeNodeContainer().getNodeId();
engineWatchData.nodes = dataContainer;
dataBuffer = compress_gzip(json_encode(engineWatchData.toJsonObject()));
buffer data = compress_gzip(json_encode(engineWatchData.toJsonObject()));
#endif
ofstream fout(configurationPath);
for (int i = 0; i < configurationBuffer.size(); i++) fout << configurationBuffer.v[i];
fout.close(); fout.open(dataPath);
for (int i = 0; i < data.size(); i++) fout << data.v[i];
}

#define getArchetypeId(T) archetypeId[typeid(T).name()]
#define getArchetypeId(T) archetypeId[#T]

#ifdef tutorial
#define build(configurationPath, dataPath) { build(configurationPath, dataPath); }
#else
#define build(configurationPath, dataPath, args...) { allocateArchetypeId(#args); build<args>(configurationPath, dataPath); }
#endif

// int ForPtIterator = 0;
#define IF(cond) e1e1d3d40573127e9ee0480caf1283d6(If(cond, [&](){ NONFUNCBEGIN
Expand Down

0 comments on commit dbab69f

Please sign in to comment.