From 27ce798730ddaeb34eb263b31fe75738d2902dea Mon Sep 17 00:00:00 2001 From: adafcaefc Date: Fri, 6 Dec 2024 17:16:41 +0700 Subject: [PATCH] fixed dual mode --- Geome3Dash/Geome3Dash.vcxproj | 6 +- Geome3Dash/Geome3Dash.vcxproj.filters | 10 +- Geome3Dash/dllmain.cpp | 2 +- .../src/{Entries.cpp => Geome3DashEntry.cpp} | 2 +- .../src/{Entries.h => Geome3DashEntry.h} | 0 .../editor/G3DCameraKeyframeEditorPopup.cpp | 3 +- Geome3Dash/src/game/playing/G3DPlayLayer.cpp | 2 +- .../src/game/test/G3DModelPreviewLayer.cpp | 191 ------------------ .../src/game/test/G3DModelPreviewLayer.h | 42 ---- 9 files changed, 9 insertions(+), 249 deletions(-) rename Geome3Dash/src/{Entries.cpp => Geome3DashEntry.cpp} (95%) rename Geome3Dash/src/{Entries.h => Geome3DashEntry.h} (100%) delete mode 100644 Geome3Dash/src/game/test/G3DModelPreviewLayer.cpp delete mode 100644 Geome3Dash/src/game/test/G3DModelPreviewLayer.h diff --git a/Geome3Dash/Geome3Dash.vcxproj b/Geome3Dash/Geome3Dash.vcxproj index 1fcb9abb..34ded0ef 100644 --- a/Geome3Dash/Geome3Dash.vcxproj +++ b/Geome3Dash/Geome3Dash.vcxproj @@ -72,7 +72,6 @@ - @@ -90,7 +89,7 @@ - + @@ -139,10 +138,9 @@ - - + diff --git a/Geome3Dash/Geome3Dash.vcxproj.filters b/Geome3Dash/Geome3Dash.vcxproj.filters index 5659f95f..aac1d19e 100644 --- a/Geome3Dash/Geome3Dash.vcxproj.filters +++ b/Geome3Dash/Geome3Dash.vcxproj.filters @@ -21,7 +21,7 @@ Frameworks - + Source Files @@ -93,9 +93,6 @@ Source Files - - Source Files - Source Files @@ -212,7 +209,7 @@ Header Files - + Header Files @@ -278,9 +275,6 @@ Header Files - - Header Files - Header Files diff --git a/Geome3Dash/dllmain.cpp b/Geome3Dash/dllmain.cpp index 3f67bda6..3f1ff3e4 100644 --- a/Geome3Dash/dllmain.cpp +++ b/Geome3Dash/dllmain.cpp @@ -1,5 +1,5 @@ #include "pch.h" -#include "src/Entries.h" +#include "src/Geome3DashEntry.h" static DWORD WINAPI mainThread(LPVOID lpParam) { diff --git a/Geome3Dash/src/Entries.cpp b/Geome3Dash/src/Geome3DashEntry.cpp similarity index 95% rename from Geome3Dash/src/Entries.cpp rename to Geome3Dash/src/Geome3DashEntry.cpp index 21b38cd3..575bd0fa 100644 --- a/Geome3Dash/src/Entries.cpp +++ b/Geome3Dash/src/Geome3DashEntry.cpp @@ -1,6 +1,6 @@ #include "pch.h" -#include "Entries.h" +#include "Geome3DashEntry.h" namespace g3d { diff --git a/Geome3Dash/src/Entries.h b/Geome3Dash/src/Geome3DashEntry.h similarity index 100% rename from Geome3Dash/src/Entries.h rename to Geome3Dash/src/Geome3DashEntry.h diff --git a/Geome3Dash/src/game/editor/G3DCameraKeyframeEditorPopup.cpp b/Geome3Dash/src/game/editor/G3DCameraKeyframeEditorPopup.cpp index 29b1ba04..6555a9d7 100644 --- a/Geome3Dash/src/game/editor/G3DCameraKeyframeEditorPopup.cpp +++ b/Geome3Dash/src/game/editor/G3DCameraKeyframeEditorPopup.cpp @@ -234,7 +234,8 @@ namespace g3d glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); player1.render(ckel->blockShaderProgram, ckel->layer3d->camera, ckel->layer3d->light); - player2.render(ckel->blockShaderProgram, ckel->layer3d->camera, ckel->layer3d->light); + if (ckel->lel->m_gameState.m_isDualMode) { player2.render(ckel->blockShaderProgram, ckel->layer3d->camera, ckel->layer3d->light); } + for (auto& block : blocks) { block.render(ckel->blockShaderProgram, ckel->layer3d->camera, ckel->layer3d->light); } glDisable(GL_DEPTH_TEST); diff --git a/Geome3Dash/src/game/playing/G3DPlayLayer.cpp b/Geome3Dash/src/game/playing/G3DPlayLayer.cpp index 4d579d53..593105a4 100644 --- a/Geome3Dash/src/game/playing/G3DPlayLayer.cpp +++ b/Geome3Dash/src/game/playing/G3DPlayLayer.cpp @@ -92,7 +92,7 @@ namespace g3d void G3DPlayLayer::drawPlayers() { player1.render(shaderProgram, camera, light); - player2.render(shaderProgram, camera, light); + if (playLayer->m_gameState.m_isDualMode) { player2.render(shaderProgram, camera, light); } } void G3DPlayLayer::draw() diff --git a/Geome3Dash/src/game/test/G3DModelPreviewLayer.cpp b/Geome3Dash/src/game/test/G3DModelPreviewLayer.cpp deleted file mode 100644 index b3f58d34..00000000 --- a/Geome3Dash/src/game/test/G3DModelPreviewLayer.cpp +++ /dev/null @@ -1,191 +0,0 @@ -#include "pch.h" - -#include "game/test/G3DModelPreviewLayer.h" -#include "game/component/G3DBaseNode.h" -#include "game/component/G3DFragmentShaderLayer.h" - -#include "CocosShaderProgram.h" -#include "BlockModelStorage.h" - -#include "engine/sus3d/Shader.h" -#include "engine/sus3d/Shaders.h" -#include "engine/sus3d/Model.h" -#include "engine/sus3d/Mesh.h" - -#include "helper/OpenGLStateHelper.h" -#include "helper/CommonHelper.h" - -#include "lib/tinyfiledialogs/tinyfiledialogs.h" - -namespace g3d -{ - void G3DModelPreviewLayer::onGLFWMouseCallBack(GLFWwindow* window, int button, int action, int mods) { - if (button == GLFW_MOUSE_BUTTON_RIGHT) { - if (action == GLFW_PRESS) { - isRightClicking = true; - isRightClickingGetPos = false; - } - else if (action == GLFW_RELEASE) { - isRightClicking = false; - } - } - } - - void G3DModelPreviewLayer::onGLFWMouseMoveCallBack(GLFWwindow* window, double x, double y) { - if (isRightClicking) { - if (!isRightClickingGetPos) { - lastMouseX = static_cast(x); - lastMouseY = static_cast(y); - isRightClickingGetPos = true; - } - else { - float deltaX = static_cast(x) - lastMouseX; - float deltaY = static_cast(y) - lastMouseY; - if (isPressingControl) { - float sensitivity = 0.032f; - layer3d->camera.setPosition(layer3d->camera.getPosition() + layer3d->camera.getUp() * deltaY * sensitivity); - layer3d->camera.setPosition(layer3d->camera.getPosition() + glm::normalize(glm::cross(layer3d->camera.getFront(), layer3d->camera.getUp())) * deltaX * -sensitivity); - } - else { - float sensitivity = 0.05f; - float yaw = layer3d->camera.getYaw() - deltaX * sensitivity; - float pitch = layer3d->camera.getPitch() - deltaY * sensitivity; - // Clamp pitch to prevent flipping - pitch = std::clamp(pitch, -89.0f, 89.0f); - layer3d->camera.setYaw(yaw); - layer3d->camera.setPitch(pitch); - } - lastMouseX = static_cast(x); - lastMouseY = static_cast(y); - } - } - } - - void G3DModelPreviewLayer::scrollWheel(float y, float x) { - // Adjust the camera zoom level using the scroll wheel - float zoomSensitivity = -0.128f; - layer3d->camera.setPosition(layer3d->camera.getPosition() + layer3d->camera.getFront() * y * zoomSensitivity); - } - - void G3DModelPreviewLayer::onKey(enumKeyCodes key, bool pressed, bool holding) { - switch (key) { - case KEY_Control: - isPressingControl = pressed; - break; - default: - break; - } - } - - std::optional G3DModelPreviewLayer::openModelSelectModal() { - const char* title = "select model"; - const char* filterPatterns[] = { "*.obj" }; - const char* filePath = tinyfd_openFileDialog( - title, - nullptr, - 1, - filterPatterns, - "OBJ", - 0 - ); - - if (filePath) - return std::string(filePath); - return std::nullopt; - } - - bool G3DModelPreviewLayer::init() { - //FMODAudioEngine::get()->playMusic("A145 - A Newborn Spirit.mp3", true, 1, 0); - CCLayer::init(); - - setKeyboardEnabled(true); - OpenGLStateHelper::saveState(); - auto vertexShader = sus3d::Shader::createWithString(sus3d::shaders::vertexShaderSource, sus3d::ShaderType::kVertexShader); - auto fragmentShader = sus3d::Shader::createWithString(sus3d::shaders::fragmentShaderSource, sus3d::ShaderType::kFragmentShader); - shaderProgram = CocosShaderProgram::create(vertexShader, fragmentShader); - delete vertexShader; - delete fragmentShader; - OpenGLStateHelper::pushState(); - - layer3d = G3DBaseNode::create(); - layer3d->light.setPosition(glm::vec3(50, 100, 50)); - layer3d->setZOrder(10); - this->addChild(layer3d); - - auto size = CCDirector::sharedDirector()->getWinSize(); - - auto testLayer = G3DFragmentShaderLayer::create(BlockModelStorage::get()->getBP() / "planet" / "shader" / "space.fsh"); - this->addChild(testLayer); - - auto bg = CCSprite::create("GJ_gradientBG.png"); - bg->setScaleX(size.width / bg->getContentSize().width); - bg->setScaleY(size.height / bg->getContentSize().height); - bg->setColor({ 0, 75, 110 }); - bg->setZOrder(-5); - - bg->setPosition(size / 2); - - this->addChild(bg); - - auto backButtonSprite = CCSprite::createWithSpriteFrameName("GJ_arrow_03_001.png"); - auto backButton = CCMenuItemSpriteExtra::create(backButtonSprite, this, menu_selector(G3DModelPreviewLayer::onBack)); - auto backButtonMenu = CCMenu::create(); - backButtonMenu->setPosition(25, size.height - 25); - backButtonMenu->addChild(backButton); - this->addChild(backButtonMenu); - - - auto selectModelButtonSprite = CCSprite::createWithSpriteFrameName("accountBtn_myLevels_001.png"); - auto selectModelButton = CCMenuItemSpriteExtra::create(selectModelButtonSprite, this, menu_selector(G3DModelPreviewLayer::onSelectModel)); - auto selectModelMenu = CCMenu::create(); - selectModelMenu->setPosition(size.width - 25, size.height - 25); - selectModelMenu->addChild(selectModelButton); - this->addChild(selectModelMenu); - - return true; - } - - void G3DModelPreviewLayer::onBack(CCObject*) { - keyBackClicked(); - } - - void G3DModelPreviewLayer::keyBackClicked(void) { - CCDirector::sharedDirector()->popSceneWithTransition(0.3f, PopTransition::kPopTransitionFade); - //FMODAudioEngine::get()->stopAllMusic(true); - } - - void G3DModelPreviewLayer::draw() { - CCLayer::draw(); - layer3d->light.setPosition(layer3d->camera.getPosition()); - - auto selected = layer3d->getObjectIDByMousePosition(); - - for (int modelIndex = 0; modelIndex < layer3d->models.size(); modelIndex++) { - for (size_t meshIndex = 0; meshIndex < layer3d->models[modelIndex]->meshes.size(); meshIndex++) { - if (modelIndex == selected.first && meshIndex == selected.second) - layer3d->models[modelIndex]->meshes[meshIndex]->setCustomKa(glm::vec3(1, 0, 0)); - else - layer3d->models[modelIndex]->meshes[meshIndex]->disableKa(); - } - } - } - - void G3DModelPreviewLayer::onSelectModel(CCObject*) - { - auto path = openModelSelectModal(); - if (!path.has_value()) { return; } - const auto obj_path = std::filesystem::path(path.value()); - layer3d->models.push_back(BlockModelStorage::get()->getModel(path.value())); - } - - G3DModelPreviewLayer* G3DModelPreviewLayer::create() { - auto node = new G3DModelPreviewLayer; - if (node->init()) { - node->autorelease(); - } - else { - CC_SAFE_DELETE(node); - } - return node; - } -} diff --git a/Geome3Dash/src/game/test/G3DModelPreviewLayer.h b/Geome3Dash/src/game/test/G3DModelPreviewLayer.h deleted file mode 100644 index 7ccc0770..00000000 --- a/Geome3Dash/src/game/test/G3DModelPreviewLayer.h +++ /dev/null @@ -1,42 +0,0 @@ -#pragma once - -#include "delegate/CustomKeyboard.h" -#include "delegate/CustomMouse.h" -#include "delegate/CustomTouch.h" - -namespace g3d -{ - class G3DBaseNode; - class CocosShaderProgram; - - class G3DModelPreviewLayer - : public CCLayer - , public CustomKeyboardDelegate - , public CustomMouseDelegate - , public CustomTouchDelegate - { - G3DBaseNode* layer3d; - CocosShaderProgram* shaderProgram; - - bool isPressingControl = false; - bool isRightClicking = false; - bool isRightClickingGetPos = false; - float lastMouseX = 0.0; - float lastMouseY = 0.0; - - virtual void onGLFWMouseCallBack(GLFWwindow* window, int button, int action, int mods); - virtual void onGLFWMouseMoveCallBack(GLFWwindow* window, double x, double y); - virtual void scrollWheel(float y, float x); - virtual void onKey(enumKeyCodes key, bool pressed, bool holding); - private: - bool init(); - virtual void draw(); - void onBack(CCObject*); - virtual void keyBackClicked(void); - - std::optional openModelSelectModal(); - void onSelectModel(CCObject*); - public: - static G3DModelPreviewLayer* create(); - }; -}