From 440a89ffae71faab8dbde2b283e0044bd4c00a97 Mon Sep 17 00:00:00 2001 From: Knaapchen Date: Fri, 11 Nov 2022 23:53:44 +0100 Subject: [PATCH] Just some dumb refactoring --- flyff-api/src/item/ItemKind2.h | 6 + flyff-api/src/item/ItemKind3.h | 7 + fugg-client/src/Client.cpp | 119 +++++--- fugg-client/src/export/gl.cpp | 431 ++++++++++++++-------------- fugg-client/src/export/platform.cpp | 15 +- fugg-client/src/main.cpp | 2 +- 6 files changed, 316 insertions(+), 264 deletions(-) diff --git a/flyff-api/src/item/ItemKind2.h b/flyff-api/src/item/ItemKind2.h index 0b31e97..9c1369b 100644 --- a/flyff-api/src/item/ItemKind2.h +++ b/flyff-api/src/item/ItemKind2.h @@ -37,6 +37,12 @@ namespace flyff { Recovery = 14, Quest = 25, }; + + + static std::ostream &operator<<(std::ostream &os, const ItemKind2 &kind) { + os << "ItemKind2(" << static_cast(kind) << ")"; + return os; + } }; diff --git a/flyff-api/src/item/ItemKind3.h b/flyff-api/src/item/ItemKind3.h index d20fd95..5335566 100644 --- a/flyff-api/src/item/ItemKind3.h +++ b/flyff-api/src/item/ItemKind3.h @@ -80,7 +80,14 @@ namespace flyff { Knuckle = 203, Shield = 300, + + HealthPill = 1404 }; + + static std::ostream &operator<<(std::ostream &os, const ItemKind3 &kind) { + os << "ItemKind3(" << static_cast(kind) << ")"; + return os; + } }; diff --git a/fugg-client/src/Client.cpp b/fugg-client/src/Client.cpp index e8ede2a..2ef3d89 100644 --- a/fugg-client/src/Client.cpp +++ b/fugg-client/src/Client.cpp @@ -418,34 +418,36 @@ void on_keyup_hook(int event_type, const EmscriptenKeyboardEvent *event, void *u // client.show_announcement("Hello world!", {0xFF, 0, 0}); - std::cout << "Player object ID: " << std::hex << client.player->object_id << std::dec << std::endl; - auto current = client.movers.first; - do { - const auto &mover = current->mover; - - if (mover->type == flyff::ObjectType::Item) { - std::cout << "Item " - << std::hex << mover->object_id << std::dec - << " at " << mover->position - << " (" << std::hex << static_cast(mover) << std::dec << ")" - << std::endl; - } - - current = current->next; - } while (current); - -// auto items = client.player->inventory.begin(); -// std::cout << "Player has " << client.player->get_inventory_slots() << " slots" << std::endl; -// for (auto i = 0; i < client.player->get_inventory_slots(); i++) { -// if (items[i].property) { -// const auto &item = items[i].property; +// std::cout << "Player object ID: " << std::hex << client.player->object_id << std::dec << std::endl; +// auto current = client.movers.first; +// do { +// const auto &mover = current->mover; // -// std::cout << client.get_text(item->name) << ": " -// << reinterpret_cast(static_cast(item)) << ", " +// if (mover->type == flyff::ObjectType::Item) { +// std::cout << "Item " +// << std::hex << mover->object_id << std::dec +// << " at " << mover->position +// << " (" << std::hex << static_cast(mover) << std::dec << ")" // << std::endl; -// // } -// } +// +// current = current->next; +// } while (current); + + auto items = client.player->inventory.begin(); + std::cout << "Player has " << client.player->get_inventory_slots() << " slots" << std::endl; + for (auto i = 0; i < client.player->get_inventory_slots(); i++) { + if (items[i].property) { + const auto &item = items[i].property; + + std::cout << client.get_text(item->name) << ": " + << reinterpret_cast(static_cast(item)) << ", " + << "Ik2: " << item->item_kind2 << ", " + << "Ik3: " << item->item_kind3 << ", " + << std::endl; + + } + } } } } @@ -578,23 +580,24 @@ void attacker_script() { // attack_target() if (neuz.player->get_hp_percent() != 100) { - - auto items = player->inventory.begin(); - int32_t smallest_difference = std::numeric_limits::max(); auto food_item = flyff::Pointer(nullptr); - for (auto i = 0; i < player->get_inventory_slots(); i++) { - const auto &item_property = items[i].property; - if (item_property && - player->can_use_item(item_property) && - item_property->is_food()) { - auto hp = client.player->get_hp(); - auto max_hp = client.player->get_max_hp(); - // How much HP is left over after healing with this item. - int32_t difference = max_hp - (hp + item_property->heal_hp); + { + auto items = player->inventory.begin(); + int32_t smallest_difference = std::numeric_limits::max(); + for (auto i = 0; i < player->get_inventory_slots(); i++) { + const auto &item_property = items[i].property; + if (item_property && + player->can_use_item(item_property) && + item_property->is_food()) { + auto hp = client.player->get_hp(); + auto max_hp = client.player->get_max_hp(); + // How much HP is left over after healing with this item. + int32_t difference = max_hp - (hp + item_property->heal_hp); - if (difference >= 0 && std::abs(difference) < std::abs(smallest_difference)) { - food_item = flyff::Pointer(&items[i]); - smallest_difference = difference; + if (difference >= 0 && std::abs(difference) < std::abs(smallest_difference)) { + food_item = flyff::Pointer(&items[i]); + smallest_difference = difference; + } } } } @@ -602,13 +605,45 @@ void attacker_script() { if (food_item) { std::string str = "Eating "; str.append(neuz.get_text(food_item->property->name)); - str.append(" because it has the smallest difference of "); - str.append(std::to_string(smallest_difference)); neuz.show_message(str); client.send_use_item_in_inventory(food_item->index); + } else { + // HP is not full but no food item found. + auto pill_item = flyff::Pointer(nullptr); + { + auto items = player->inventory.begin(); + int32_t smallest_difference = std::numeric_limits::max(); + for (auto i = 0; i < player->get_inventory_slots(); i++) { + const auto &item_property = items[i].property; + if (item_property && + player->can_use_item(item_property) && + item_property->item_kind3 == flyff::ItemKind3::HealthPill) { + auto hp = client.player->get_hp(); + auto max_hp = client.player->get_max_hp(); + // How much HP is left over after healing with this item. + int32_t difference = max_hp - (hp + item_property->heal_hp); + + if (difference >= 0 && std::abs(difference) < std::abs(smallest_difference)) { + pill_item = flyff::Pointer(&items[i]); + smallest_difference = difference; + } + } + } + } + + if(pill_item) { + std::string str = "Eating "; + str.append(neuz.get_text(pill_item->property->name)); + str.append(" because food item was not ready."); + + neuz.show_message(str); + + client.send_use_item_in_inventory(pill_item->index); + } } + } if (neuz.player->get_move_state() == flyff::Object::MoveState::Stand && diff --git a/fugg-client/src/export/gl.cpp b/fugg-client/src/export/gl.cpp index 5572a2f..c784ed4 100644 --- a/fugg-client/src/export/gl.cpp +++ b/fugg-client/src/export/gl.cpp @@ -13,7 +13,7 @@ /* import: 'a' 'i' */ // "i": "_glDisableVertexAttribArray", WASM_IMPORT_IMPL(env, _glDisableVertexAttribArray) = [](u32 a) { - const auto& index = reinterpret_cast(a); + const auto &index = reinterpret_cast(a); #if TRACE_GL_CALLS std::cout << "_glDisableVertexAttribArray(" @@ -25,10 +25,10 @@ WASM_IMPORT_IMPL(env, _glDisableVertexAttribArray) = [](u32 a) { /* import: 'a' 'j' */ // "j": "_glUniformMatrix4fv", WASM_IMPORT_IMPL(env, _glUniformMatrix4fv) = [](u32 a, u32 b, u32 c, u32 d) { - const auto& location = reinterpret_cast(a); - const auto& count = static_cast(b); - const auto& transpose = static_cast(c); - const auto& value = fugg::ModulePointer(d); + const auto &location = reinterpret_cast(a); + const auto &count = static_cast(b); + const auto &transpose = static_cast(c); + const auto &value = fugg::ModulePointer(d); #if TRACE_GL_CALLS std::cout << "_glUniformMatrix4fv(" @@ -45,8 +45,8 @@ WASM_IMPORT_IMPL(env, _glUniformMatrix4fv) = [](u32 a, u32 b, u32 c, u32 d) { /* import: 'a' 'd' */ // "d": "_glActiveTexture", /* _glActiveTexture */ -WASM_IMPORT_IMPL(env, _glActiveTexture) = [](u32 a) { - const auto& texture = reinterpret_cast(a); +WASM_IMPORT_IMPL(env, _glActiveTexture) = [](u32 a) { + const auto &texture = reinterpret_cast(a); #if TRACE_GL_CALLS std::cout << "_glActiveTexture(" @@ -60,8 +60,8 @@ WASM_IMPORT_IMPL(env, _glActiveTexture) = [](u32 a) { // "e": "_glBindTexture", /* _glBindTexture */ WASM_IMPORT_IMPL(env, _glBindTexture) = [](u32 a, u32 b) { - const auto& target = reinterpret_cast(a); - const auto& texture = reinterpret_cast(b); + const auto &target = reinterpret_cast(a); + const auto &texture = reinterpret_cast(b); #if TRACE_GL_CALLS std::cout << "_glBindTexture(" @@ -75,14 +75,14 @@ WASM_IMPORT_IMPL(env, _glBindTexture) = [](u32 a, u32 b) { /* import: 'a' 'f' */ // "f": "_glVertexAttribPointer", WASM_IMPORT_IMPL(env, _glVertexAttribPointer) = [](u32 a, u32 b, u32 c, u32 d, u32 e, u32 f) { - const auto& index = reinterpret_cast(a); - const auto& size = static_cast(b); - const auto& type = reinterpret_cast(c); - const auto& normalized = static_cast(d); - const auto& stride = static_cast(e); + const auto &index = reinterpret_cast(a); + const auto &size = static_cast(b); + const auto &type = reinterpret_cast(c); + const auto &normalized = static_cast(d); + const auto &stride = static_cast(e); // Specifies a offset of the first component, so although it's a pointer, // it's doesn't need to be transformed. - const auto& pointer = reinterpret_cast(f); + const auto &pointer = reinterpret_cast(f); #if TRACE_GL_CALLS std::cout << "_glVertexAttribPointer(" @@ -100,8 +100,8 @@ WASM_IMPORT_IMPL(env, _glVertexAttribPointer) = [](u32 a, u32 b, u32 c, u32 d, u // "m": "_glBindBuffer", WASM_IMPORT_IMPL(env, _glBindBuffer) = [](u32 a, u32 b) { - const auto& target = reinterpret_cast(a); - const auto& buffer = reinterpret_cast(b); + const auto &target = reinterpret_cast(a); + const auto &buffer = reinterpret_cast(b); #if TRACE_GL_CALLS std::cout << "_glBindBuffer(" @@ -115,7 +115,7 @@ WASM_IMPORT_IMPL(env, _glBindBuffer) = [](u32 a, u32 b) { // "n": "_glDisable", WASM_IMPORT_IMPL(env, _glDisable) = [](u32 a) { - const auto& cap = reinterpret_cast(a); + const auto &cap = reinterpret_cast(a); #if TRACE_GL_CALLS std::cout << "_glDisable(" @@ -138,8 +138,8 @@ WASM_IMPORT_IMPL(env, _glUniform1f) = [](u32 a, f32 b) { #endif glUniform1f( - a, - b + a, + b ); }; // "r": "_glEnable", @@ -164,9 +164,9 @@ WASM_IMPORT_IMPL(env, _glTexParameteri) = [](u32 a, u32 b, u32 c) { #endif glTexParameteri( - a, - b, - c + a, + b, + c ); }; /* import: 'a' 'v' */ @@ -226,14 +226,14 @@ WASM_IMPORT_IMPL(env, _glBindFramebuffer) = [](u32 a, u32 b) { #endif glBindFramebuffer( - a, - b + a, + b ); }; /* import: 'a' 'D' */ /* _glDrawElements */ WASM_IMPORT_IMPL(env, _glDrawElements) = [](u32 a, u32 b, u32 c, u32 d) { - const auto& indices = reinterpret_cast(d); + const auto &indices = reinterpret_cast(d); #if TRACE_GL_CALLS std::cout << "_glDrawElements(" @@ -245,17 +245,17 @@ WASM_IMPORT_IMPL(env, _glDrawElements) = [](u32 a, u32 b, u32 c, u32 d) { #endif glDrawElements( - a, - b, - c, - indices + a, + b, + c, + indices ); }; /* import: 'a' 'I' */ /* "I": "_glUniform3fv" */ WASM_IMPORT_IMPL(env, _glUniform3fv) = [](u32 a, u32 b, u32 c) { - const auto& value = fugg::ModulePointer(c); + const auto &value = fugg::ModulePointer(c); #if TRACE_GL_CALLS std::cout << "_glUniform3fv(" @@ -266,16 +266,17 @@ WASM_IMPORT_IMPL(env, _glUniform3fv) = [](u32 a, u32 b, u32 c) { #endif glUniform3fv( - a, - b, - value + a, + b, + value ); }; /* import: 'a' 'K' */ // "K": "_glTexImage2D", -WASM_IMPORT_IMPL(env, _glTexImage2D) = [](u32 target, u32 level, u32 internalformat, u32 d, u32 e, u32 f, u32 g, u32 h, u32 i) { - const auto& pixels = fugg::ModulePointer(i); +WASM_IMPORT_IMPL(env, _glTexImage2D) = [](u32 target, u32 level, u32 internalformat, u32 d, u32 e, u32 f, u32 g, u32 h, + u32 i) { + const auto &pixels = fugg::ModulePointer(i); #if TRACE_GL_CALLS std::cout << "_glTexImage2D(" @@ -292,15 +293,15 @@ WASM_IMPORT_IMPL(env, _glTexImage2D) = [](u32 target, u32 level, u32 internalfor #endif glTexImage2D( - target, - level, - internalformat, - d, - e, - f, - g, - h, - pixels + target, + level, + internalformat, + d, + e, + f, + g, + h, + pixels ); }; @@ -317,10 +318,10 @@ WASM_IMPORT_IMPL(env, _glViewport) = [](u32 a, u32 b, u32 c, u32 d) { #endif glViewport( - a, - b, - c, - d + a, + b, + c, + d ); }; // "N": "_glGetError", @@ -333,7 +334,7 @@ WASM_IMPORT_IMPL(env, _glGetError) = []() { }; // "O": "_glDeleteFramebuffers", WASM_IMPORT_IMPL(env, _glDeleteFramebuffers) = [](u32 a, u32 b) { - const auto& framebuffers = fugg::ModulePointer(b); + const auto &framebuffers = fugg::ModulePointer(b); #if TRACE_GL_CALLS std::cout << "_glDeleteFramebuffers(" @@ -343,8 +344,8 @@ WASM_IMPORT_IMPL(env, _glDeleteFramebuffers) = [](u32 a, u32 b) { #endif glDeleteFramebuffers( - a, - framebuffers + a, + framebuffers ); }; /* import: 'a' 'P' */ @@ -360,16 +361,16 @@ WASM_IMPORT_IMPL(env, _glColorMask) = [](u32 a, u32 b, u32 c, u32 d) { #endif glColorMask( - a, - b, - c, - d + a, + b, + c, + d ); }; // "R": "_glDeleteBuffers", WASM_IMPORT_IMPL(env, _glDeleteBuffers) = [](u32 a, u32 b) { - const auto& n = static_cast(a); - const auto& buffers = fugg::ModulePointer(b); + const auto &n = static_cast(a); + const auto &buffers = fugg::ModulePointer(b); #if TRACE_GL_CALLS std::cout << "_glDeleteBuffers(" @@ -382,8 +383,8 @@ WASM_IMPORT_IMPL(env, _glDeleteBuffers) = [](u32 a, u32 b) { }; // "S": "_glBufferData", WASM_IMPORT_IMPL(env, _glBufferData) = [](u32 a, u32 b, u32 c, u32 d) { - const auto& size = static_cast(b); - const auto& data = fugg::ModulePointer(c); + const auto &size = static_cast(b); + const auto &data = fugg::ModulePointer(c); #if TRACE_GL_CALLS std::cout << "_glBufferData(" @@ -395,17 +396,17 @@ WASM_IMPORT_IMPL(env, _glBufferData) = [](u32 a, u32 b, u32 c, u32 d) { #endif glBufferData( - a, - size, - data, - d + a, + size, + data, + d ); }; /* import: 'a' 'T' */ // "T": "_glGenBuffers", WASM_IMPORT_IMPL(env, _glGenBuffers) = [](u32 a, u32 b) { - const auto& n = static_cast(a); - const auto& buffers = fugg::ModulePointer(b); + const auto &n = static_cast(a); + const auto &buffers = fugg::ModulePointer(b); #if TRACE_GL_CALLS std::cout << "_glGenBuffers(" @@ -415,8 +416,8 @@ WASM_IMPORT_IMPL(env, _glGenBuffers) = [](u32 a, u32 b) { #endif glGenBuffers( - a, - buffers + a, + buffers ); }; /* import: 'a' 'U' */ @@ -432,10 +433,10 @@ WASM_IMPORT_IMPL(env, _glScissor) = [](u32 a, u32 b, u32 c, u32 d) { #endif glScissor( - a, - b, - c, - d + a, + b, + c, + d ); }; /* import: 'a' 'V' */ @@ -453,8 +454,8 @@ WASM_IMPORT_IMPL(env, _glStencilMask) = [](u32 a) { /* import: 'a' 'Z' */ // "Z": "_glGenTextures", WASM_IMPORT_IMPL(env, _glGenTextures) = [](u32 a, u32 b) { - const auto& n = static_cast(a); - const auto& textures = fugg::ModulePointer(b); + const auto &n = static_cast(a); + const auto &textures = fugg::ModulePointer(b); #if TRACE_GL_CALLS std::cout << "_glGenTextures(" @@ -477,15 +478,15 @@ WASM_IMPORT_IMPL(env, _glUniform2f) = [](u32 a, f32 b, f32 c) { #endif glUniform2f( - a, - b, - c + a, + b, + c ); }; /* import: 'a' '$' */ /* _glUniform2fv */ WASM_IMPORT_IMPL(env, _glUniform2fv) = [](u32 a, u32 b, u32 c) { - const auto& value = fugg::ModulePointer(c); + const auto &value = fugg::ModulePointer(c); #if TRACE_GL_CALLS std::cout << "_glUniform2fv(" @@ -496,9 +497,9 @@ WASM_IMPORT_IMPL(env, _glUniform2fv) = [](u32 a, u32 b, u32 c) { #endif glUniform2fv( - a, - b, - value + a, + b, + value ); }; // "aa": "_glFrontFace", @@ -524,17 +525,17 @@ WASM_IMPORT_IMPL(env, _glFramebufferTexture2D) = [](u32 a, u32 b, u32 c, u32 d, #endif glFramebufferTexture2D( - a, - b, - c, - d, - e + a, + b, + c, + d, + e ); }; /* import: 'a' 'ea' */ // "ea": "_glGetProgramiv", WASM_IMPORT_IMPL(env, _glGetProgramiv) = [](u32 a, u32 b, u32 c) { - const auto& params = fugg::ModulePointer(c); + const auto ¶ms = fugg::ModulePointer(c); #if TRACE_GL_CALLS std::cout << "_glGetProgramiv(" @@ -545,9 +546,9 @@ WASM_IMPORT_IMPL(env, _glGetProgramiv) = [](u32 a, u32 b, u32 c) { #endif glGetProgramiv( - a, - b, - params + a, + b, + params ); }; /* import: 'a' 'fa' */ @@ -562,15 +563,15 @@ WASM_IMPORT_IMPL(env, _glStencilFunc) = [](u32 a, u32 b, u32 c) { #endif glStencilFunc( - a, - b, - c + a, + b, + c ); }; /* import: 'a' 'ga' */ // "ga": "_glGenFramebuffers", WASM_IMPORT_IMPL(env, _glGenFramebuffers) = [](u32 a, u32 b) { - const auto& framebuffers = fugg::ModulePointer(b); + const auto &framebuffers = fugg::ModulePointer(b); #if TRACE_GL_CALLS std::cout << "_glGenFramebuffers(" @@ -580,15 +581,15 @@ WASM_IMPORT_IMPL(env, _glGenFramebuffers) = [](u32 a, u32 b) { #endif glGenFramebuffers( - a, - framebuffers + a, + framebuffers ); }; /* import: 'a' 'ia' */ // "ia": "_glGetIntegerv", WASM_IMPORT_IMPL(env, _glGetIntegerv) = [](u32 a, u32 b) { - const auto& data = fugg::ModulePointer(b); + const auto &data = fugg::ModulePointer(b); #if TRACE_GL_CALLS std::cout << "_glGetIntegerv(" @@ -598,8 +599,8 @@ WASM_IMPORT_IMPL(env, _glGetIntegerv) = [](u32 a, u32 b) { #endif glGetIntegerv( - a, - data + a, + data ); }; /* import: 'a' 'ja' */ @@ -613,8 +614,8 @@ WASM_IMPORT_IMPL(env, _glUniform1i) = [](u32 a, u32 b) { #endif glUniform1i( - a, - b + a, + b ); }; @@ -626,7 +627,7 @@ WASM_IMPORT_IMPL(env, _glClear) = [](u32 a) { << a << ")" << std::endl; #endif - + glClear(a); }; @@ -678,19 +679,19 @@ WASM_IMPORT_IMPL(env, _glClearColor) = [](f32 a, f32 b, f32 c, f32 d) { #endif glClearColor( - a, - b, - c, - d + a, + b, + c, + d ); }; /* import: 'a' 'Ta' */ // "Ta": "_glGetProgramInfoLog", WASM_IMPORT_IMPL(env, _glGetProgramInfoLog) = [](u32 a, u32 b, u32 c, u32 d) { - const auto& program = reinterpret_cast(a); - const auto& buf_size = static_cast(b); - const auto& length = fugg::ModulePointer(c); - const auto& infolog = fugg::ModulePointer(d); + const auto &program = reinterpret_cast(a); + const auto &buf_size = static_cast(b); + const auto &length = fugg::ModulePointer(c); + const auto &infolog = fugg::ModulePointer(d); #if TRACE_GL_CALLS std::cout << "_glGetProgramInfoLog(" @@ -702,10 +703,10 @@ WASM_IMPORT_IMPL(env, _glGetProgramInfoLog) = [](u32 a, u32 b, u32 c, u32 d) { #endif glGetProgramInfoLog( - a, - b, - length, - infolog + a, + b, + length, + infolog ); }; /* import: 'a' 'Ua' */ @@ -730,14 +731,14 @@ WASM_IMPORT_IMPL(env, _glAttachShader) = [](u32 a, u32 b) { #endif glAttachShader( - a, - b + a, + b ); }; /* import: 'a' 'Wa' */ // "Wa": "_glGetShaderiv", WASM_IMPORT_IMPL(env, _glGetShaderiv) = [](u32 a, u32 b, u32 c) { - const auto& params = fugg::ModulePointer(c); + const auto ¶ms = fugg::ModulePointer(c); #if TRACE_GL_CALLS std::cout << "_glGetShaderiv(" @@ -748,9 +749,9 @@ WASM_IMPORT_IMPL(env, _glGetShaderiv) = [](u32 a, u32 b, u32 c) { #endif glGetShaderiv( - a, - b, - params + a, + b, + params ); }; /* import: 'a' 'Xa' */ @@ -779,17 +780,18 @@ WASM_IMPORT_IMPL(env, _glUniform4f) = [](u32 a, f32 b, f32 c, f32 d, f32 e) { #endif glUniform4f( - a, - b, - c, - d, - e + a, + b, + c, + d, + e ); }; /* import: 'a' 'lb' */ // "lb": "_glCompressedTexImage2D", -WASM_IMPORT_IMPL(env, _glCompressedTexImage2D) = [](u32 target, u32 level, u32 internalformat, u32 width, u32 height, u32 border, u32 image_size, u32 h) { - const auto& data = fugg::ModulePointer(h); +WASM_IMPORT_IMPL(env, _glCompressedTexImage2D) = [](u32 target, u32 level, u32 internalformat, u32 width, u32 height, + u32 border, u32 image_size, u32 h) { + const auto &data = fugg::ModulePointer(h); #if TRACE_GL_CALLS std::cout << "_glCompressedTexImage2D(" @@ -805,20 +807,20 @@ WASM_IMPORT_IMPL(env, _glCompressedTexImage2D) = [](u32 target, u32 level, u32 i #endif glCompressedTexImage2D( - target, - level, - internalformat, - width, - height, - border, - image_size, - data + target, + level, + internalformat, + width, + height, + border, + image_size, + data ); }; /* import: 'a' 'mb' */ // "mb": "_glBindAttribLocation", WASM_IMPORT_IMPL(env, _glBindAttribLocation) = [](u32 a, u32 b, u32 c) { - const auto& name = fugg::ModulePointer(c); + const auto &name = fugg::ModulePointer(c); #if TRACE_GL_CALLS std::cout << "_glBindAttribLocation(" @@ -829,18 +831,18 @@ WASM_IMPORT_IMPL(env, _glBindAttribLocation) = [](u32 a, u32 b, u32 c) { #endif glBindAttribLocation( - a, - b, - name + a, + b, + name ); }; /* import: 'a' 'nb' */ // "nb": "_glGetActiveAttrib", WASM_IMPORT_IMPL(env, _glGetActiveAttrib) = [](u32 a, u32 b, u32 c, u32 d, u32 e, u32 f, u32 g) { - const auto& length = fugg::ModulePointer(d); - const auto& size = fugg::ModulePointer(e); - const auto& type = fugg::ModulePointer(f); - const auto& name = fugg::ModulePointer(g); + const auto &length = fugg::ModulePointer(d); + const auto &size = fugg::ModulePointer(e); + const auto &type = fugg::ModulePointer(f); + const auto &name = fugg::ModulePointer(g); #if TRACE_GL_CALLS std::cout << "_glGetActiveAttrib(" @@ -855,20 +857,20 @@ WASM_IMPORT_IMPL(env, _glGetActiveAttrib) = [](u32 a, u32 b, u32 c, u32 d, u32 e #endif glGetActiveAttrib( - a, - b, - c, - length, - size, - type, - name + a, + b, + c, + length, + size, + type, + name ); }; /* import: 'a' 'pb' */ // "pb": "_glCreateProgram", WASM_IMPORT_IMPL(env, _glCreateProgram) = []() { - const auto& result = glCreateProgram(); + const auto &result = glCreateProgram(); #if TRACE_GL_CALLS std::cout << "_glCreateProgram() = " << result << std::endl; @@ -879,10 +881,10 @@ WASM_IMPORT_IMPL(env, _glCreateProgram) = []() { /* import: 'a' 'qb' */ // "qb": "_glGetShaderInfoLog", WASM_IMPORT_IMPL(env, _glGetShaderInfoLog) = [](u32 a, u32 b, u32 c, u32 d) { - const auto& shader = reinterpret_cast(a); - const auto& buf_size = static_cast(b); - const auto& length = fugg::ModulePointer(c); - const auto& infolog = fugg::ModulePointer(d); + const auto &shader = reinterpret_cast(a); + const auto &buf_size = static_cast(b); + const auto &length = fugg::ModulePointer(c); + const auto &infolog = fugg::ModulePointer(d); #if TRACE_GL_CALLS std::cout << "_glGetShaderInfoLog(" @@ -915,25 +917,25 @@ WASM_IMPORT_IMPL(env, _glShaderSource) = [](u32 shader, u32 count, u32 string_, // to allow multiple shaders to be compiled. // We need to fix the pointers to point into the WASM runtime. - const auto& string = fugg::ModulePointer(string_); - const auto& length = fugg::ModulePointer(length_); + const auto &string = fugg::ModulePointer(string_); + const auto &length = fugg::ModulePointer(length_); - for(unsigned int i = 0; i < count; i++) { - string[i] = fugg::ModulePointer { string[i] }; + for (unsigned int i = 0; i < count; i++) { + string[i] = fugg::ModulePointer{string[i]}; } glShaderSource( - shader, - count, - // Lastly, convert the string_ pointer to be readable outside the WASM runtime. - string, - length + shader, + count, + // Lastly, convert the string_ pointer to be readable outside the WASM runtime. + string, + length ); }; /* import: 'a' 'tb' */ // "tb": "_glCreateShader", WASM_IMPORT_IMPL(env, _glCreateShader) = [](u32 a) { - const auto& result = glCreateShader(a); + const auto &result = glCreateShader(a); #if TRACE_GL_CALLS std::cout << "_glCreateShader(" << a << ") = " << result << std::endl; @@ -956,7 +958,7 @@ WASM_IMPORT_IMPL(env, _glCullFace) = [](u32 a) { /* import: 'a' 'wb' */ // "wb": "_glGetString", WASM_IMPORT_IMPL(env, _glGetString) = [](u32 a) { - const auto& result = glGetString(a); + const auto &result = glGetString(a); #if TRACE_GL_CALLS std::cout << "_glGetString(" @@ -965,7 +967,7 @@ WASM_IMPORT_IMPL(env, _glGetString) = [](u32 a) { #endif return static_cast( - fugg::RuntimePointer { result }.as_raw() + fugg::RuntimePointer{result}.as_raw() ); }; /* import: 'a' 'xb' */ @@ -980,16 +982,16 @@ WASM_IMPORT_IMPL(env, _glStencilOp) = [](u32 a, u32 b, u32 c) { #endif glStencilOp( - a, - b, - c + a, + b, + c ); }; /* import: 'a' 'zb' */ // "zb": "_glDeleteTextures", WASM_IMPORT_IMPL(env, _glDeleteTextures) = [](u32 a, u32 b) { - const auto& textures = fugg::ModulePointer(b); + const auto &textures = fugg::ModulePointer(b); #if TRACE_GL_CALLS std::cout << "_glDeleteTextures(" @@ -999,8 +1001,8 @@ WASM_IMPORT_IMPL(env, _glDeleteTextures) = [](u32 a, u32 b) { #endif glDeleteTextures( - a, - textures + a, + textures ); }; @@ -1022,21 +1024,21 @@ WASM_IMPORT_IMPL(env, _glCopyTexSubImage2D) = [](u32 a, u32 b, u32 c, u32 d, u32 glCopyTexSubImage2D( - a, - b, - c, - d, - e, - f, - g, - h + a, + b, + c, + d, + e, + f, + g, + h ); }; /* import: 'a' 'dc' */ // "dc": "_glTexSubImage2D", WASM_IMPORT_IMPL(env, _glTexSubImage2D) = [](u32 a, u32 b, u32 c, u32 d, u32 e, u32 f, u32 g, u32 h, u32 i) { - const auto& pixels = fugg::ModulePointer(i); + const auto &pixels = fugg::ModulePointer(i); #if TRACE_GL_CALLS std::cout << "_glTexSubImage2D(" @@ -1053,15 +1055,15 @@ WASM_IMPORT_IMPL(env, _glTexSubImage2D) = [](u32 a, u32 b, u32 c, u32 d, u32 e, #endif glTexSubImage2D( - a, - b, - c, - d, - e, - f, - g, - h, - pixels + a, + b, + c, + d, + e, + f, + g, + h, + pixels ); }; @@ -1077,15 +1079,15 @@ WASM_IMPORT_IMPL(env, _glDrawArrays) = [](u32 a, u32 b, u32 c) { #endif glDrawArrays( - a, - b, - c + a, + b, + c ); }; /* import: 'a' 'G' */ /* _glGetUniformLocation */ WASM_IMPORT_IMPL(env, _glGetUniformLocation) = [](u32 a, u32 b) { - const auto& name = fugg::ModulePointer(b); + const auto &name = fugg::ModulePointer(b); #if TRACE_GL_CALLS std::cout << "_glGetUniformLocation(" @@ -1095,16 +1097,16 @@ WASM_IMPORT_IMPL(env, _glGetUniformLocation) = [](u32 a, u32 b) { #endif return static_cast( - glGetUniformLocation( - a, - name - ) + glGetUniformLocation( + a, + name + ) ); }; /* import: 'a' 'ka' */ // "ka": "_glCheckFramebufferStatus", WASM_IMPORT_IMPL(env, _glCheckFramebufferStatus) = [](u32 a) { - const auto& result = glCheckFramebufferStatus(a); + const auto &result = glCheckFramebufferStatus(a); #if TRACE_GL_CALLS std::cout << "_glCheckFramebufferStatus(" @@ -1128,24 +1130,24 @@ WASM_IMPORT_IMPL(env, _glDetachShader) = [](u32 a, u32 b) { #endif glDetachShader( - a, - b + a, + b ); }; /* import: 'a' 'hb' */ // "hb": "_emscripten_webgl_make_context_current", WASM_IMPORT_IMPL(env, _emscripten_webgl_make_context_current) = [](u32 a) { return static_cast( - emscripten_webgl_make_context_current( - static_cast(a) - ) + emscripten_webgl_make_context_current( + static_cast(a) + ) ); }; /* import: 'a' 'ib' */ // "ib": "_emscripten_webgl_create_context", WASM_IMPORT_IMPL(env, _emscripten_webgl_create_context) = [](u32 a, u32 b) { - const auto& target = fugg::ModulePointer(a); - const auto& attributes = fugg::ModulePointer(b); + const auto &target = fugg::ModulePointer(a); + const auto &attributes = fugg::ModulePointer(b); #if TRACE_EM_CALLS std::cout << "_emscripten_webgl_create_context(" @@ -1154,30 +1156,31 @@ WASM_IMPORT_IMPL(env, _emscripten_webgl_create_context) = [](u32 a, u32 b) { << ")" << std::endl; #endif - auto attr = static_cast(attributes); - std::cout << "Trying to create a context with version " << attr->majorVersion << "." << attr->minorVersion << std::endl; + auto attr = static_cast(attributes); + std::cout << "Trying to create a context with version " << attr->majorVersion << "." << attr->minorVersion + << std::endl; return static_cast( - emscripten_webgl_create_context(target, attributes) + emscripten_webgl_create_context(target, attributes) ); }; /* import: 'a' 'jb' */ // "jb": "_emscripten_webgl_init_context_attributes", WASM_IMPORT_IMPL(env, _emscripten_webgl_init_context_attributes) = [](u32 a) { - const auto& attributes = fugg::ModulePointer(a); + const auto &attributes = fugg::ModulePointer(a); #if TRACE_EM_CALLS std::cout << "_emscripten_webgl_init_context_attributes(" << attributes << ")" << std::endl; #endif - + emscripten_webgl_init_context_attributes(attributes); }; /* import: 'a' 'vb' */ // "vb": "_emscripten_webgl_enable_extension", WASM_IMPORT_IMPL(env, _emscripten_webgl_enable_extension) = [](u32 a, u32 b) { - const auto& extension = fugg::ModulePointer(b); + const auto &extension = fugg::ModulePointer(b); #if TRACE_GL_CALLS std::cout << "_emscripten_webgl_enable_extension(" @@ -1187,6 +1190,6 @@ WASM_IMPORT_IMPL(env, _emscripten_webgl_enable_extension) = [](u32 a, u32 b) { #endif return static_cast( - emscripten_webgl_enable_extension(a, extension) + emscripten_webgl_enable_extension(a, extension) ); }; \ No newline at end of file diff --git a/fugg-client/src/export/platform.cpp b/fugg-client/src/export/platform.cpp index 1978b43..7300bb5 100644 --- a/fugg-client/src/export/platform.cpp +++ b/fugg-client/src/export/platform.cpp @@ -1,10 +1,12 @@ #include #include #include +#include #include #include +#include #include "embind.h" @@ -24,7 +26,7 @@ void platform_text_edited_hook(u32 ptr, u32 selection_start, u32 selection_end) } void platform_got_devicemotion_permission_hook() { - using PlatformGotDeviceMotionPermissionFn = void (*)(void); + using PlatformGotDeviceMotionPermissionFn = void (*)(); auto platform_got_devicemotion_permission = fugg::function_ref( fugg::embind::kFunctionMap["platform_got_devicemotion_permission"]->fn ); @@ -32,13 +34,13 @@ void platform_got_devicemotion_permission_hook() { platform_got_devicemotion_permission(); } -void platform_captcha_completed_hook(std::string token) { +void platform_captcha_completed_hook(const std::string& token) { struct WireType { size_t length; char data[1]; }; - WireType* wt = (WireType*)malloc(sizeof(size_t) + token.length()); + auto* wt = (WireType*)malloc(sizeof(size_t) + token.length()); wt->length = token.length(); memcpy(wt->data, token.data(), token.length()); @@ -57,7 +59,6 @@ void platform_captcha_completed_hook(std::string token) { platform_captcha_completed, fugg::RuntimePointer(wt) ); - } using PlatformWebsocketFn = void (*)(emscripten::val event); @@ -69,7 +70,7 @@ void platform_websocket_open_hook(emscripten::val event) { fugg::embind::kFunctionMap["platform_websocket_open"]->fn ); - platform_websocket_open(event); + platform_websocket_open(std::move(event)); } void platform_websocket_close_hook(emscripten::val event) { @@ -79,10 +80,10 @@ void platform_websocket_close_hook(emscripten::val event) { fugg::embind::kFunctionMap["platform_websocket_close"]->fn ); - platform_websocket_close(event); + platform_websocket_close(std::move(event)); } -void platform_websocket_message_hook(emscripten::val event) { +void platform_websocket_message_hook(const emscripten::val& event) { // std::cout << "platform_websocket_message: Got " << event["data"]["byteLength"].as() << " bytes" << std::endl; struct Test { diff --git a/fugg-client/src/main.cpp b/fugg-client/src/main.cpp index 5e2c937..ebad226 100644 --- a/fugg-client/src/main.cpp +++ b/fugg-client/src/main.cpp @@ -54,7 +54,7 @@ void free(void *ptr_) { emscripten_builtin_free(ptr_); #if TRACE_ALLOC - std::cout << "FUGG: Free'd OUTSIDE pointer at " << reinterpret_cast(ptr) << std::endl; + std::cout << "FUGG: Free'd OUTSIDE pointer at " << reinterpret_cast(ptr_) << std::endl; #endif } }