From 46c1254a4d253e514187552334c0b2cd8db45799 Mon Sep 17 00:00:00 2001 From: Joseph Walton-Rivers <joseph@walton-rivers.uk> Date: Mon, 6 Sep 2021 22:14:02 +0100 Subject: [PATCH] vim code autoformat --- build.sh | 17 ++-- demo/main.cpp | 234 +++++++++++++++++++++++++------------------------- 2 files changed, 127 insertions(+), 124 deletions(-) diff --git a/build.sh b/build.sh index a71fe6a..9e20a96 100755 --- a/build.sh +++ b/build.sh @@ -31,18 +31,17 @@ popd # # gamemoderun -#if [ -x "$(command -v gamemoderun)" ]; then -# EXE="gamemoderun $EXE" -#fi +if [ -x "$(command -v gamemoderun)" ]; then + EXE="gamemoderun $EXE" +fi # mangohud -#if [ -x "$(command -v mangohud)" ]; then -# EXE="mangohud --dlsym $EXE" -#fi +if [ -x "$(command -v mangohud)" ]; then + EXE="mangohud --dlsym $EXE" +fi -EXE="gdb $EXE" +#EXE="gdb $EXE" pushd demo -#$EXE ../build/demo/FgglDemo > /tmp/fggl.log 2>&1 -$EXE +$EXE ../build/demo/FgglDemo > /tmp/fggl.log 2>&1 popd diff --git a/demo/main.cpp b/demo/main.cpp index fa44249..f885428 100644 --- a/demo/main.cpp +++ b/demo/main.cpp @@ -24,7 +24,7 @@ constexpr bool showNormals = false; template <typename T> int sgn(T val) { - return (T(0) < val) - (val < T(0)); + return (T(0) < val) - (val < T(0)); } // prototype of resource discovery @@ -40,7 +40,7 @@ void discover(std::filesystem::path base) { contentPacks.push_back( item.path() ); } } - + } // what did we find? @@ -65,17 +65,17 @@ void process_camera(fggl::gfx::Window& window, fggl::ecs2::World& ecs, fggl::gfx } /* - auto camTransform = ecs.getComponent<fggl::math::Transform>(cam); - auto camComp = ecs.getComponent<fggl::gfx::Camera>(cam); + auto camTransform = ecs.getComponent<fggl::math::Transform>(cam); + auto camComp = ecs.getComponent<fggl::gfx::Camera>(cam); - const glm::vec3 dir = ( camTransform->origin() - camComp->target ); - const glm::vec3 forward = glm::normalize( dir ); + const glm::vec3 dir = ( camTransform->origin() - camComp->target ); + const glm::vec3 forward = glm::normalize( dir ); // scroll wheel glm::vec3 motion(0.0f); float delta = (float)input.scrollDeltaY(); if ( (glm::length( dir ) < 25.0f && delta < 0.0f) || (glm::length( dir ) > 2.5f && delta > 0.0f) ) - motion -= (forward * delta); + motion -= (forward * delta); camTransform->origin( camTransform->origin() + motion ); */ @@ -225,7 +225,7 @@ int main(int argc, char* argv[]) { configPhong.name = "phong"; configPhong.vertex = configPhong.name + "_vert.glsl"; configPhong.fragment = configPhong.name + "_frag.glsl"; -// configPhong.fragment = configPhong.name + "_normals_frag.glsl"; + // configPhong.fragment = configPhong.name + "_normals_frag.glsl"; auto shaderPhong = cache.load(configPhong); fggl::gfx::ShaderConfig configNormals; @@ -308,36 +308,36 @@ int main(int argc, char* argv[]) { // rendering systems - Game/OpenGL auto matSys = world.ecs().system<const fggl::components::Transform, fggl::components::GfxMat>() .iter([&world](flecs::iter& it, const fggl::components::Transform* t, fggl::components::GfxMat* mats) { - // there is probably a more ECS-friendly way of doing this... - auto cam = world.ecs().lookup("camera"); - const auto camComp = cam.get< fggl::components::Camera >(); - const auto camTrans = cam.get< fggl::components::Transform >(); + // there is probably a more ECS-friendly way of doing this... + auto cam = world.ecs().lookup("camera"); + const auto camComp = cam.get< fggl::components::Camera >(); + const auto camTrans = cam.get< fggl::components::Transform >(); - // build the two matrices from the camera - const fggl::math::mat4 proj = glm::perspective( camComp->fov, camComp->aspectRatio, camComp->nearPlane, camComp->farPlane); - const fggl::math::mat4 view = glm::lookAt( camTrans->origin(), camComp->target, camTrans->up() ); + // build the two matrices from the camera + const fggl::math::mat4 proj = glm::perspective( camComp->fov, camComp->aspectRatio, camComp->nearPlane, camComp->farPlane); + const fggl::math::mat4 view = glm::lookAt( camTrans->origin(), camComp->target, camTrans->up() ); - // splat component data into mesh data - for ( auto i : it ) { + // splat component data into mesh data + for ( auto i : it ) { mats[i].proj = proj; mats[i].view = view; mats[i].model = t[i].model(); - } - }); + } + }); - glm::vec3 lightPos(20.0f, 20.0f, 15.0f); + glm::vec3 lightPos(20.0f, 20.0f, 15.0f); auto drawSys = world.ecs().system<>("DrawSys", "gfx.mat,SHARED:gfx.token") .iter([lightPos](flecs::iter& it) { - auto t = it.column<const fggl::components::GfxMat>(1); - auto mesh = it.column<const fggl::components::GfxToken>(2); + auto t = it.column<const fggl::components::GfxMat>(1); + auto mesh = it.column<const fggl::components::GfxToken>(2); - glEnable(GL_CULL_FACE); - glCullFace(GL_BACK); + glEnable(GL_CULL_FACE); + glCullFace(GL_BACK); - glEnable(GL_DEPTH_TEST); + glEnable(GL_DEPTH_TEST); - for ( auto i : it ) { + for ( auto i : it ) { auto shader = mesh->pipeline; glUseProgram( shader ); @@ -352,17 +352,17 @@ int main(int argc, char* argv[]) { glBindVertexArray( mesh->vao ); glDrawElements( GL_TRIANGLES, mesh->idxSize, GL_UNSIGNED_INT, reinterpret_cast<void*>(mesh->idxOffset) ); - } + } }); - + fggl::gfx::Input& input = fggl::gfx::Input::instance(); world.ecs().system<fggl::components::Transform, fggl::components::Camera>() .ctx( &hacks ) .iter( CameraArcball ); - bool joystickWindow = false; - bool gamepadWindow = false; + bool joystickWindow = true; + bool gamepadWindow = true; float time = 0.0f; float dt = 16.0f; @@ -375,120 +375,124 @@ int main(int argc, char* argv[]) { // update step time += dt; - + //process_camera(win, ecs, input, camEnt); if ( cam_mode == cam_arcball ) { if ( input.mouseDown( fggl::gfx::MOUSE_2 ) ) { -// process_arcball(win, ecs, input, camEnt); + // process_arcball(win, ecs, input, camEnt); } }/* else if ( cam_mode == cam_free ) { - process_freecam(win, ecs, input, camEnt); - }*/ + process_freecam(win, ecs, input, camEnt); + }*/ // imgui joystick debug - ImGui::Begin("Joysticks", &joystickWindow); - for ( int i=0; i<16; i++ ) { - bool present = input.hasJoystick(i); - std::string title = "Joystick " + std::to_string(i); - - if ( ImGui::TreeNode(title.c_str()) ) { - ImGui::Text("present: %s", present ? "yes" : "no" ); - - if ( present ) { - const fggl::gfx::Joystick& joyData = input.joystick(i); - ImGui::Text( "%s", joyData.name ); - ImGui::Text( "gamepad: %s", joyData.gamepad ? "yes" : "no" ); - ImGui::Text( "axes: %d, buttons: %d, hats: %d", - joyData.axisCount, - joyData.buttonCount, - joyData.hatCount); - - if (ImGui::TreeNode("axis##2")) { - // dump data - for ( int axid = 0; axid < joyData.axisCount; axid++ ) { - ImGui::Text("axis %d, value: %f", - axid, joyData.axes[axid] ); + if ( joystickWindow ) { + ImGui::Begin("Joysticks", &joystickWindow); + for ( int i=0; i<16; i++ ) { + bool present = input.hasJoystick(i); + std::string title = "Joystick " + std::to_string(i); + + if ( ImGui::TreeNode(title.c_str()) ) { + ImGui::Text("present: %s", present ? "yes" : "no" ); + + if ( present ) { + const fggl::gfx::Joystick& joyData = input.joystick(i); + ImGui::Text( "%s", joyData.name ); + ImGui::Text( "gamepad: %s", joyData.gamepad ? "yes" : "no" ); + ImGui::Text( "axes: %d, buttons: %d, hats: %d", + joyData.axisCount, + joyData.buttonCount, + joyData.hatCount); + + if (ImGui::TreeNode("axis##2")) { + // dump data + for ( int axid = 0; axid < joyData.axisCount; axid++ ) { + ImGui::Text("axis %d, value: %f", + axid, joyData.axes[axid] ); + } + ImGui::TreePop(); } - ImGui::TreePop(); - } - if (ImGui::TreeNode("buttons##2")) { - // dump data - for ( int btnid = 0; btnid < joyData.buttonCount; btnid++ ) { - ImGui::Text("button %d, value: %s", btnid, - joyData.buttons[btnid] == GLFW_PRESS - ? "down" : "up" ); + if (ImGui::TreeNode("buttons##2")) { + // dump data + for ( int btnid = 0; btnid < joyData.buttonCount; btnid++ ) { + ImGui::Text("button %d, value: %s", btnid, + joyData.buttons[btnid] == GLFW_PRESS + ? "down" : "up" ); + } + ImGui::TreePop(); } - ImGui::TreePop(); - } - if (ImGui::TreeNode("hats##2")) { - // dump data - for ( int btnid = 0; btnid < joyData.hatCount; btnid++ ) { - ImGui::Text("button %d, value: %d", - btnid, joyData.hats[btnid] ); + if (ImGui::TreeNode("hats##2")) { + // dump data + for ( int btnid = 0; btnid < joyData.hatCount; btnid++ ) { + ImGui::Text("button %d, value: %d", + btnid, joyData.hats[btnid] ); + } + ImGui::TreePop(); } - ImGui::TreePop(); } + + ImGui::TreePop(); + ImGui::Separator(); } - ImGui::TreePop(); - ImGui::Separator(); } - + ImGui::End(); } - ImGui::End(); // imgui gamepad debug - ImGui::Begin("GamePad", &gamepadWindow); - for ( int i=0; i<16; i++ ) { - std::string title = "GamePad " + std::to_string(i); - - bool present = input.hasJoystick(i); - if ( ImGui::TreeNode(title.c_str()) ) { - ImGui::Text("present: %s", present ? "yes" : "no" ); - - if ( present ) { - - if ( ImGui::TreeNode("buttons##2") ) { - for ( auto& btn : fggl::gfx::PadButtons ) { - auto label = fggl::gfx::PadButtonLabels[ (int) btn ]; - ImGui::Text( "%s: %i %i %i", label.c_str(), - input.padDown(i, btn), - input.padPressed(i, btn), - input.padReleased(i, btn) - ); + if ( gamepadWindow ) { + ImGui::Begin("GamePad", &gamepadWindow); + for ( int i=0; i<16; i++ ) { + std::string title = "GamePad " + std::to_string(i); + + bool present = input.hasJoystick(i); + if ( ImGui::TreeNode(title.c_str()) ) { + ImGui::Text("present: %s", present ? "yes" : "no" ); + + if ( present ) { + + if ( ImGui::TreeNode("buttons##2") ) { + for ( auto& btn : fggl::gfx::PadButtons ) { + auto label = fggl::gfx::PadButtonLabels[ (int) btn ]; + ImGui::Text( "%s: %i %i %i", label.c_str(), + input.padDown(i, btn), + input.padPressed(i, btn), + input.padReleased(i, btn) + ); + } + ImGui::TreePop(); } - ImGui::TreePop(); - } - if ( ImGui::TreeNode("axes##2") ) { - for ( auto& axis : fggl::gfx::PadAxes ) { - auto label = fggl::gfx::PadAxisLabels[ (int) axis ]; - ImGui::Text("%s: %f %f", label.c_str(), - input.padAxis(i, axis), - input.padAxisDelta(i, axis) - ); + if ( ImGui::TreeNode("axes##2") ) { + for ( auto& axis : fggl::gfx::PadAxes ) { + auto label = fggl::gfx::PadAxisLabels[ (int) axis ]; + ImGui::Text("%s: %f %f", label.c_str(), + input.padAxis(i, axis), + input.padAxisDelta(i, axis) + ); + } + ImGui::TreePop(); } - ImGui::TreePop(); + } + ImGui::TreePop(); + ImGui::Separator(); } - ImGui::TreePop(); - ImGui::Separator(); } - + ImGui::End(); } - ImGui::End(); - -/* float amount = glm::radians( time / 2048.0f * 360.0f ); - auto spinners = ecs.getEntityWith<fggl::math::Transform>(); - for ( auto entity : spinners ) { - auto transform = ecs.getComponent<fggl::math::Transform>(entity); - transform->euler(glm::vec3(0.0f, amount, 0.0f)); - }*/ + + /* float amount = glm::radians( time / 2048.0f * 360.0f ); + auto spinners = ecs.getEntityWith<fggl::math::Transform>(); + for ( auto entity : spinners ) { + auto transform = ecs.getComponent<fggl::math::Transform>(entity); + transform->euler(glm::vec3(0.0f, amount, 0.0f)); + }*/ // render step ogl.clear(); -- GitLab