From 8fadbfa9ee3f6b91ef411b6afd2456985c7e0298 Mon Sep 17 00:00:00 2001 From: Armin <armin.co@hs-bochum.de> Date: Sat, 9 Jan 2021 16:37:30 +0100 Subject: [PATCH] Reset master for new QPong version. --- .gitignore | 2 - .gitmodules | 13 - CMakeLists.txt | 51 -- LICENSE | 674 ------------------ README.md | 50 -- gtk_qpong_app/CMakeLists.txt | 30 - gtk_qpong_app/ParticleImage.cpp | 34 - gtk_qpong_app/ParticleImage.hpp | 32 - gtk_qpong_app/QDrawingArea.cpp | 39 - gtk_qpong_app/QDrawingArea.hpp | 48 -- gtk_qpong_app/QWindow.cpp | 236 ------ gtk_qpong_app/QWindow.hpp | 84 --- gtk_qpong_app/main.cpp | 41 -- imgui_glfw_app/CMakeLists.txt | 83 --- imgui_glfw_app/LoadShaders.cpp | 96 --- imgui_glfw_app/LoadShaders.hpp | 7 - imgui_glfw_app/imgui_glfw_playground.cpp | 348 --------- imgui_glfw_app/shaders/FragmentShader.glsl | 8 - .../shaders/SimpleVertexShader.glsl | 13 - imgui_sdl_app/CMakeLists.txt | 71 -- imgui_sdl_app/imgui_playground.cpp | 194 ----- libs/CMakeLists.txt | 0 libs/cpp_starter_project | 1 - libs/googletest | 1 - libs/imgui | 1 - libs/spdlog | 1 - qpong_core/CMakeLists.txt | 8 - qpong_core/Common.hpp | 30 - qpong_core/ImageBuffer.cpp | 50 -- qpong_core/ImageBuffer.hpp | 51 -- qpong_core/Particle.cpp | 297 -------- qpong_core/Particle.hpp | 93 --- qpong_core/Player.cpp | 101 --- qpong_core/Player.hpp | 58 -- tests/CMakeLists.txt | 23 - tests/test_qpong.cpp | 65 -- 36 files changed, 2934 deletions(-) delete mode 100644 .gitignore delete mode 100644 .gitmodules delete mode 100644 CMakeLists.txt delete mode 100644 LICENSE delete mode 100644 README.md delete mode 100644 gtk_qpong_app/CMakeLists.txt delete mode 100644 gtk_qpong_app/ParticleImage.cpp delete mode 100644 gtk_qpong_app/ParticleImage.hpp delete mode 100644 gtk_qpong_app/QDrawingArea.cpp delete mode 100644 gtk_qpong_app/QDrawingArea.hpp delete mode 100644 gtk_qpong_app/QWindow.cpp delete mode 100644 gtk_qpong_app/QWindow.hpp delete mode 100644 gtk_qpong_app/main.cpp delete mode 100644 imgui_glfw_app/CMakeLists.txt delete mode 100644 imgui_glfw_app/LoadShaders.cpp delete mode 100644 imgui_glfw_app/LoadShaders.hpp delete mode 100644 imgui_glfw_app/imgui_glfw_playground.cpp delete mode 100644 imgui_glfw_app/shaders/FragmentShader.glsl delete mode 100644 imgui_glfw_app/shaders/SimpleVertexShader.glsl delete mode 100644 imgui_sdl_app/CMakeLists.txt delete mode 100644 imgui_sdl_app/imgui_playground.cpp delete mode 100644 libs/CMakeLists.txt delete mode 160000 libs/cpp_starter_project delete mode 160000 libs/googletest delete mode 160000 libs/imgui delete mode 160000 libs/spdlog delete mode 100644 qpong_core/CMakeLists.txt delete mode 100644 qpong_core/Common.hpp delete mode 100644 qpong_core/ImageBuffer.cpp delete mode 100644 qpong_core/ImageBuffer.hpp delete mode 100644 qpong_core/Particle.cpp delete mode 100644 qpong_core/Particle.hpp delete mode 100644 qpong_core/Player.cpp delete mode 100644 qpong_core/Player.hpp delete mode 100644 tests/CMakeLists.txt delete mode 100644 tests/test_qpong.cpp diff --git a/.gitignore b/.gitignore deleted file mode 100644 index 1899660..0000000 --- a/.gitignore +++ /dev/null @@ -1,2 +0,0 @@ -build -.vscode \ No newline at end of file diff --git a/.gitmodules b/.gitmodules deleted file mode 100644 index 6a9e6ef..0000000 --- a/.gitmodules +++ /dev/null @@ -1,13 +0,0 @@ -[submodule "libs/googletest"] - path = libs/googletest - url = https://github.com/google/googletest.git -[submodule "libs/imgui"] - path = libs/imgui - url = https://github.com/armin-co/imgui.git -[submodule "libs/cpp_starter_project"] - path = libs/cpp_starter_project - url = https://github.com/armin-co/cpp_starter_project.git - # -[submodule "libs/spdlog"] - path = libs/spdlog - url = https://github.com/gabime/spdlog diff --git a/CMakeLists.txt b/CMakeLists.txt deleted file mode 100644 index a20287e..0000000 --- a/CMakeLists.txt +++ /dev/null @@ -1,51 +0,0 @@ -# CMake file for the QPong project. -project(QPong) -cmake_minimum_required(VERSION 3.10) - - -# Options -option(create_test "Build all tests." OFF) - -# Use modern C++! -set(CMAKE_CXX_STANDARD 17) -# @todo It will not run in debug mode only in release mode. -set(CMAKE_BUILD_TYPE Release) - - -# PkgConfig -find_package(PkgConfig REQUIRED) - -# On macOS some things are different ^^ -if(APPLE) - link_directories(/usr/local/lib) - include_directories(/usr/local/include) - - # This may be necessary on some systems. - message("ATTENTION: You probably have to export the PKG_CONFIG_PATH.") - message("For example: $ export PKG_CONFIG_PATH=\"/usr/local/lib:/usr/local/opt/zlib/lib/pkgconfig\"") -endif() - - -# logging library spdlog -add_subdirectory(libs/spdlog) - -# Add qpong lib for core qpong functionality -add_subdirectory(qpong_core) -include_directories(qpong_core) - -# Dear ImGui and SDL based application -add_subdirectory(imgui_sdl_app) - -# Dear ImGui and GLFW based application -add_subdirectory(imgui_glfw_app) - -# Add dir with gtk qpong app -add_subdirectory(gtk_qpong_app) - - -# Add some unit tests -# not many yet ^^ -if (create_test) - add_subdirectory(libs/googletest) - add_subdirectory(tests) -endif() diff --git a/LICENSE b/LICENSE deleted file mode 100644 index 13752e4..0000000 --- a/LICENSE +++ /dev/null @@ -1,674 +0,0 @@ - GNU GENERAL PUBLIC LICENSE - Version 3, 29 June 2007 - - Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/> - Everyone is permitted to copy and distribute verbatim copies - of this license document, but changing it is not allowed. - - Preamble - - The GNU General Public License is a free, copyleft license for -software and other kinds of works. - - The licenses for most software and other practical works are designed -to take away your freedom to share and change the works. By contrast, -the GNU General Public License is intended to guarantee your freedom to -share and change all versions of a program--to make sure it remains free -software for all its users. We, the Free Software Foundation, use the -GNU General Public License for most of our software; it applies also to -any other work released this way by its authors. You can apply it to -your programs, too. - - When we speak of free software, we are referring to freedom, not -price. Our General Public Licenses are designed to make sure that you -have the freedom to distribute copies of free software (and charge for -them if you wish), that you receive source code or can get it if you -want it, that you can change the software or use pieces of it in new -free programs, and that you know you can do these things. - - To protect your rights, we need to prevent others from denying you -these rights or asking you to surrender the rights. Therefore, you have -certain responsibilities if you distribute copies of the software, or if -you modify it: responsibilities to respect the freedom of others. - - For example, if you distribute copies of such a program, whether -gratis or for a fee, you must pass on to the recipients the same -freedoms that you received. You must make sure that they, too, receive -or can get the source code. And you must show them these terms so they -know their rights. - - Developers that use the GNU GPL protect your rights with two steps: -(1) assert copyright on the software, and (2) offer you this License -giving you legal permission to copy, distribute and/or modify it. - - For the developers' and authors' protection, the GPL clearly explains -that there is no warranty for this free software. For both users' and -authors' sake, the GPL requires that modified versions be marked as -changed, so that their problems will not be attributed erroneously to -authors of previous versions. - - Some devices are designed to deny users access to install or run -modified versions of the software inside them, although the manufacturer -can do so. This is fundamentally incompatible with the aim of -protecting users' freedom to change the software. The systematic -pattern of such abuse occurs in the area of products for individuals to -use, which is precisely where it is most unacceptable. Therefore, we -have designed this version of the GPL to prohibit the practice for those -products. If such problems arise substantially in other domains, we -stand ready to extend this provision to those domains in future versions -of the GPL, as needed to protect the freedom of users. - - Finally, every program is threatened constantly by software patents. -States should not allow patents to restrict development and use of -software on general-purpose computers, but in those that do, we wish to -avoid the special danger that patents applied to a free program could -make it effectively proprietary. To prevent this, the GPL assures that -patents cannot be used to render the program non-free. - - The precise terms and conditions for copying, distribution and -modification follow. - - TERMS AND CONDITIONS - - 0. Definitions. - - "This License" refers to version 3 of the GNU General Public License. - - "Copyright" also means copyright-like laws that apply to other kinds of -works, such as semiconductor masks. - - "The Program" refers to any copyrightable work licensed under this -License. Each licensee is addressed as "you". "Licensees" and -"recipients" may be individuals or organizations. - - To "modify" a work means to copy from or adapt all or part of the work -in a fashion requiring copyright permission, other than the making of an -exact copy. The resulting work is called a "modified version" of the -earlier work or a work "based on" the earlier work. - - A "covered work" means either the unmodified Program or a work based -on the Program. - - To "propagate" a work means to do anything with it that, without -permission, would make you directly or secondarily liable for -infringement under applicable copyright law, except executing it on a -computer or modifying a private copy. Propagation includes copying, -distribution (with or without modification), making available to the -public, and in some countries other activities as well. - - To "convey" a work means any kind of propagation that enables other -parties to make or receive copies. Mere interaction with a user through -a computer network, with no transfer of a copy, is not conveying. - - An interactive user interface displays "Appropriate Legal Notices" -to the extent that it includes a convenient and prominently visible -feature that (1) displays an appropriate copyright notice, and (2) -tells the user that there is no warranty for the work (except to the -extent that warranties are provided), that licensees may convey the -work under this License, and how to view a copy of this License. If -the interface presents a list of user commands or options, such as a -menu, a prominent item in the list meets this criterion. - - 1. Source Code. - - The "source code" for a work means the preferred form of the work -for making modifications to it. "Object code" means any non-source -form of a work. - - A "Standard Interface" means an interface that either is an official -standard defined by a recognized standards body, or, in the case of -interfaces specified for a particular programming language, one that -is widely used among developers working in that language. - - The "System Libraries" of an executable work include anything, other -than the work as a whole, that (a) is included in the normal form of -packaging a Major Component, but which is not part of that Major -Component, and (b) serves only to enable use of the work with that -Major Component, or to implement a Standard Interface for which an -implementation is available to the public in source code form. A -"Major Component", in this context, means a major essential component -(kernel, window system, and so on) of the specific operating system -(if any) on which the executable work runs, or a compiler used to -produce the work, or an object code interpreter used to run it. - - The "Corresponding Source" for a work in object code form means all -the source code needed to generate, install, and (for an executable -work) run the object code and to modify the work, including scripts to -control those activities. However, it does not include the work's -System Libraries, or general-purpose tools or generally available free -programs which are used unmodified in performing those activities but -which are not part of the work. For example, Corresponding Source -includes interface definition files associated with source files for -the work, and the source code for shared libraries and dynamically -linked subprograms that the work is specifically designed to require, -such as by intimate data communication or control flow between those -subprograms and other parts of the work. - - The Corresponding Source need not include anything that users -can regenerate automatically from other parts of the Corresponding -Source. - - The Corresponding Source for a work in source code form is that -same work. - - 2. Basic Permissions. - - All rights granted under this License are granted for the term of -copyright on the Program, and are irrevocable provided the stated -conditions are met. This License explicitly affirms your unlimited -permission to run the unmodified Program. The output from running a -covered work is covered by this License only if the output, given its -content, constitutes a covered work. This License acknowledges your -rights of fair use or other equivalent, as provided by copyright law. - - You may make, run and propagate covered works that you do not -convey, without conditions so long as your license otherwise remains -in force. You may convey covered works to others for the sole purpose -of having them make modifications exclusively for you, or provide you -with facilities for running those works, provided that you comply with -the terms of this License in conveying all material for which you do -not control copyright. Those thus making or running the covered works -for you must do so exclusively on your behalf, under your direction -and control, on terms that prohibit them from making any copies of -your copyrighted material outside their relationship with you. - - Conveying under any other circumstances is permitted solely under -the conditions stated below. Sublicensing is not allowed; section 10 -makes it unnecessary. - - 3. Protecting Users' Legal Rights From Anti-Circumvention Law. - - No covered work shall be deemed part of an effective technological -measure under any applicable law fulfilling obligations under article -11 of the WIPO copyright treaty adopted on 20 December 1996, or -similar laws prohibiting or restricting circumvention of such -measures. - - When you convey a covered work, you waive any legal power to forbid -circumvention of technological measures to the extent such circumvention -is effected by exercising rights under this License with respect to -the covered work, and you disclaim any intention to limit operation or -modification of the work as a means of enforcing, against the work's -users, your or third parties' legal rights to forbid circumvention of -technological measures. - - 4. Conveying Verbatim Copies. - - You may convey verbatim copies of the Program's source code as you -receive it, in any medium, provided that you conspicuously and -appropriately publish on each copy an appropriate copyright notice; -keep intact all notices stating that this License and any -non-permissive terms added in accord with section 7 apply to the code; -keep intact all notices of the absence of any warranty; and give all -recipients a copy of this License along with the Program. - - You may charge any price or no price for each copy that you convey, -and you may offer support or warranty protection for a fee. - - 5. Conveying Modified Source Versions. - - You may convey a work based on the Program, or the modifications to -produce it from the Program, in the form of source code under the -terms of section 4, provided that you also meet all of these conditions: - - a) The work must carry prominent notices stating that you modified - it, and giving a relevant date. - - b) The work must carry prominent notices stating that it is - released under this License and any conditions added under section - 7. This requirement modifies the requirement in section 4 to - "keep intact all notices". - - c) You must license the entire work, as a whole, under this - License to anyone who comes into possession of a copy. This - License will therefore apply, along with any applicable section 7 - additional terms, to the whole of the work, and all its parts, - regardless of how they are packaged. This License gives no - permission to license the work in any other way, but it does not - invalidate such permission if you have separately received it. - - d) If the work has interactive user interfaces, each must display - Appropriate Legal Notices; however, if the Program has interactive - interfaces that do not display Appropriate Legal Notices, your - work need not make them do so. - - A compilation of a covered work with other separate and independent -works, which are not by their nature extensions of the covered work, -and which are not combined with it such as to form a larger program, -in or on a volume of a storage or distribution medium, is called an -"aggregate" if the compilation and its resulting copyright are not -used to limit the access or legal rights of the compilation's users -beyond what the individual works permit. Inclusion of a covered work -in an aggregate does not cause this License to apply to the other -parts of the aggregate. - - 6. Conveying Non-Source Forms. - - You may convey a covered work in object code form under the terms -of sections 4 and 5, provided that you also convey the -machine-readable Corresponding Source under the terms of this License, -in one of these ways: - - a) Convey the object code in, or embodied in, a physical product - (including a physical distribution medium), accompanied by the - Corresponding Source fixed on a durable physical medium - customarily used for software interchange. - - b) Convey the object code in, or embodied in, a physical product - (including a physical distribution medium), accompanied by a - written offer, valid for at least three years and valid for as - long as you offer spare parts or customer support for that product - model, to give anyone who possesses the object code either (1) a - copy of the Corresponding Source for all the software in the - product that is covered by this License, on a durable physical - medium customarily used for software interchange, for a price no - more than your reasonable cost of physically performing this - conveying of source, or (2) access to copy the - Corresponding Source from a network server at no charge. - - c) Convey individual copies of the object code with a copy of the - written offer to provide the Corresponding Source. This - alternative is allowed only occasionally and noncommercially, and - only if you received the object code with such an offer, in accord - with subsection 6b. - - d) Convey the object code by offering access from a designated - place (gratis or for a charge), and offer equivalent access to the - Corresponding Source in the same way through the same place at no - further charge. You need not require recipients to copy the - Corresponding Source along with the object code. If the place to - copy the object code is a network server, the Corresponding Source - may be on a different server (operated by you or a third party) - that supports equivalent copying facilities, provided you maintain - clear directions next to the object code saying where to find the - Corresponding Source. Regardless of what server hosts the - Corresponding Source, you remain obligated to ensure that it is - available for as long as needed to satisfy these requirements. - - e) Convey the object code using peer-to-peer transmission, provided - you inform other peers where the object code and Corresponding - Source of the work are being offered to the general public at no - charge under subsection 6d. - - A separable portion of the object code, whose source code is excluded -from the Corresponding Source as a System Library, need not be -included in conveying the object code work. - - A "User Product" is either (1) a "consumer product", which means any -tangible personal property which is normally used for personal, family, -or household purposes, or (2) anything designed or sold for incorporation -into a dwelling. In determining whether a product is a consumer product, -doubtful cases shall be resolved in favor of coverage. For a particular -product received by a particular user, "normally used" refers to a -typical or common use of that class of product, regardless of the status -of the particular user or of the way in which the particular user -actually uses, or expects or is expected to use, the product. A product -is a consumer product regardless of whether the product has substantial -commercial, industrial or non-consumer uses, unless such uses represent -the only significant mode of use of the product. - - "Installation Information" for a User Product means any methods, -procedures, authorization keys, or other information required to install -and execute modified versions of a covered work in that User Product from -a modified version of its Corresponding Source. The information must -suffice to ensure that the continued functioning of the modified object -code is in no case prevented or interfered with solely because -modification has been made. - - If you convey an object code work under this section in, or with, or -specifically for use in, a User Product, and the conveying occurs as -part of a transaction in which the right of possession and use of the -User Product is transferred to the recipient in perpetuity or for a -fixed term (regardless of how the transaction is characterized), the -Corresponding Source conveyed under this section must be accompanied -by the Installation Information. But this requirement does not apply -if neither you nor any third party retains the ability to install -modified object code on the User Product (for example, the work has -been installed in ROM). - - The requirement to provide Installation Information does not include a -requirement to continue to provide support service, warranty, or updates -for a work that has been modified or installed by the recipient, or for -the User Product in which it has been modified or installed. Access to a -network may be denied when the modification itself materially and -adversely affects the operation of the network or violates the rules and -protocols for communication across the network. - - Corresponding Source conveyed, and Installation Information provided, -in accord with this section must be in a format that is publicly -documented (and with an implementation available to the public in -source code form), and must require no special password or key for -unpacking, reading or copying. - - 7. Additional Terms. - - "Additional permissions" are terms that supplement the terms of this -License by making exceptions from one or more of its conditions. -Additional permissions that are applicable to the entire Program shall -be treated as though they were included in this License, to the extent -that they are valid under applicable law. If additional permissions -apply only to part of the Program, that part may be used separately -under those permissions, but the entire Program remains governed by -this License without regard to the additional permissions. - - When you convey a copy of a covered work, you may at your option -remove any additional permissions from that copy, or from any part of -it. (Additional permissions may be written to require their own -removal in certain cases when you modify the work.) You may place -additional permissions on material, added by you to a covered work, -for which you have or can give appropriate copyright permission. - - Notwithstanding any other provision of this License, for material you -add to a covered work, you may (if authorized by the copyright holders of -that material) supplement the terms of this License with terms: - - a) Disclaiming warranty or limiting liability differently from the - terms of sections 15 and 16 of this License; or - - b) Requiring preservation of specified reasonable legal notices or - author attributions in that material or in the Appropriate Legal - Notices displayed by works containing it; or - - c) Prohibiting misrepresentation of the origin of that material, or - requiring that modified versions of such material be marked in - reasonable ways as different from the original version; or - - d) Limiting the use for publicity purposes of names of licensors or - authors of the material; or - - e) Declining to grant rights under trademark law for use of some - trade names, trademarks, or service marks; or - - f) Requiring indemnification of licensors and authors of that - material by anyone who conveys the material (or modified versions of - it) with contractual assumptions of liability to the recipient, for - any liability that these contractual assumptions directly impose on - those licensors and authors. - - All other non-permissive additional terms are considered "further -restrictions" within the meaning of section 10. If the Program as you -received it, or any part of it, contains a notice stating that it is -governed by this License along with a term that is a further -restriction, you may remove that term. If a license document contains -a further restriction but permits relicensing or conveying under this -License, you may add to a covered work material governed by the terms -of that license document, provided that the further restriction does -not survive such relicensing or conveying. - - If you add terms to a covered work in accord with this section, you -must place, in the relevant source files, a statement of the -additional terms that apply to those files, or a notice indicating -where to find the applicable terms. - - Additional terms, permissive or non-permissive, may be stated in the -form of a separately written license, or stated as exceptions; -the above requirements apply either way. - - 8. Termination. - - You may not propagate or modify a covered work except as expressly -provided under this License. Any attempt otherwise to propagate or -modify it is void, and will automatically terminate your rights under -this License (including any patent licenses granted under the third -paragraph of section 11). - - However, if you cease all violation of this License, then your -license from a particular copyright holder is reinstated (a) -provisionally, unless and until the copyright holder explicitly and -finally terminates your license, and (b) permanently, if the copyright -holder fails to notify you of the violation by some reasonable means -prior to 60 days after the cessation. - - Moreover, your license from a particular copyright holder is -reinstated permanently if the copyright holder notifies you of the -violation by some reasonable means, this is the first time you have -received notice of violation of this License (for any work) from that -copyright holder, and you cure the violation prior to 30 days after -your receipt of the notice. - - Termination of your rights under this section does not terminate the -licenses of parties who have received copies or rights from you under -this License. If your rights have been terminated and not permanently -reinstated, you do not qualify to receive new licenses for the same -material under section 10. - - 9. Acceptance Not Required for Having Copies. - - You are not required to accept this License in order to receive or -run a copy of the Program. Ancillary propagation of a covered work -occurring solely as a consequence of using peer-to-peer transmission -to receive a copy likewise does not require acceptance. However, -nothing other than this License grants you permission to propagate or -modify any covered work. These actions infringe copyright if you do -not accept this License. Therefore, by modifying or propagating a -covered work, you indicate your acceptance of this License to do so. - - 10. Automatic Licensing of Downstream Recipients. - - Each time you convey a covered work, the recipient automatically -receives a license from the original licensors, to run, modify and -propagate that work, subject to this License. You are not responsible -for enforcing compliance by third parties with this License. - - An "entity transaction" is a transaction transferring control of an -organization, or substantially all assets of one, or subdividing an -organization, or merging organizations. If propagation of a covered -work results from an entity transaction, each party to that -transaction who receives a copy of the work also receives whatever -licenses to the work the party's predecessor in interest had or could -give under the previous paragraph, plus a right to possession of the -Corresponding Source of the work from the predecessor in interest, if -the predecessor has it or can get it with reasonable efforts. - - You may not impose any further restrictions on the exercise of the -rights granted or affirmed under this License. For example, you may -not impose a license fee, royalty, or other charge for exercise of -rights granted under this License, and you may not initiate litigation -(including a cross-claim or counterclaim in a lawsuit) alleging that -any patent claim is infringed by making, using, selling, offering for -sale, or importing the Program or any portion of it. - - 11. Patents. - - A "contributor" is a copyright holder who authorizes use under this -License of the Program or a work on which the Program is based. The -work thus licensed is called the contributor's "contributor version". - - A contributor's "essential patent claims" are all patent claims -owned or controlled by the contributor, whether already acquired or -hereafter acquired, that would be infringed by some manner, permitted -by this License, of making, using, or selling its contributor version, -but do not include claims that would be infringed only as a -consequence of further modification of the contributor version. For -purposes of this definition, "control" includes the right to grant -patent sublicenses in a manner consistent with the requirements of -this License. - - Each contributor grants you a non-exclusive, worldwide, royalty-free -patent license under the contributor's essential patent claims, to -make, use, sell, offer for sale, import and otherwise run, modify and -propagate the contents of its contributor version. - - In the following three paragraphs, a "patent license" is any express -agreement or commitment, however denominated, not to enforce a patent -(such as an express permission to practice a patent or covenant not to -sue for patent infringement). To "grant" such a patent license to a -party means to make such an agreement or commitment not to enforce a -patent against the party. - - If you convey a covered work, knowingly relying on a patent license, -and the Corresponding Source of the work is not available for anyone -to copy, free of charge and under the terms of this License, through a -publicly available network server or other readily accessible means, -then you must either (1) cause the Corresponding Source to be so -available, or (2) arrange to deprive yourself of the benefit of the -patent license for this particular work, or (3) arrange, in a manner -consistent with the requirements of this License, to extend the patent -license to downstream recipients. "Knowingly relying" means you have -actual knowledge that, but for the patent license, your conveying the -covered work in a country, or your recipient's use of the covered work -in a country, would infringe one or more identifiable patents in that -country that you have reason to believe are valid. - - If, pursuant to or in connection with a single transaction or -arrangement, you convey, or propagate by procuring conveyance of, a -covered work, and grant a patent license to some of the parties -receiving the covered work authorizing them to use, propagate, modify -or convey a specific copy of the covered work, then the patent license -you grant is automatically extended to all recipients of the covered -work and works based on it. - - A patent license is "discriminatory" if it does not include within -the scope of its coverage, prohibits the exercise of, or is -conditioned on the non-exercise of one or more of the rights that are -specifically granted under this License. You may not convey a covered -work if you are a party to an arrangement with a third party that is -in the business of distributing software, under which you make payment -to the third party based on the extent of your activity of conveying -the work, and under which the third party grants, to any of the -parties who would receive the covered work from you, a discriminatory -patent license (a) in connection with copies of the covered work -conveyed by you (or copies made from those copies), or (b) primarily -for and in connection with specific products or compilations that -contain the covered work, unless you entered into that arrangement, -or that patent license was granted, prior to 28 March 2007. - - Nothing in this License shall be construed as excluding or limiting -any implied license or other defenses to infringement that may -otherwise be available to you under applicable patent law. - - 12. No Surrender of Others' Freedom. - - If conditions are imposed on you (whether by court order, agreement or -otherwise) that contradict the conditions of this License, they do not -excuse you from the conditions of this License. If you cannot convey a -covered work so as to satisfy simultaneously your obligations under this -License and any other pertinent obligations, then as a consequence you may -not convey it at all. For example, if you agree to terms that obligate you -to collect a royalty for further conveying from those to whom you convey -the Program, the only way you could satisfy both those terms and this -License would be to refrain entirely from conveying the Program. - - 13. Use with the GNU Affero General Public License. - - Notwithstanding any other provision of this License, you have -permission to link or combine any covered work with a work licensed -under version 3 of the GNU Affero General Public License into a single -combined work, and to convey the resulting work. The terms of this -License will continue to apply to the part which is the covered work, -but the special requirements of the GNU Affero General Public License, -section 13, concerning interaction through a network will apply to the -combination as such. - - 14. Revised Versions of this License. - - The Free Software Foundation may publish revised and/or new versions of -the GNU General Public License from time to time. Such new versions will -be similar in spirit to the present version, but may differ in detail to -address new problems or concerns. - - Each version is given a distinguishing version number. If the -Program specifies that a certain numbered version of the GNU General -Public License "or any later version" applies to it, you have the -option of following the terms and conditions either of that numbered -version or of any later version published by the Free Software -Foundation. If the Program does not specify a version number of the -GNU General Public License, you may choose any version ever published -by the Free Software Foundation. - - If the Program specifies that a proxy can decide which future -versions of the GNU General Public License can be used, that proxy's -public statement of acceptance of a version permanently authorizes you -to choose that version for the Program. - - Later license versions may give you additional or different -permissions. However, no additional obligations are imposed on any -author or copyright holder as a result of your choosing to follow a -later version. - - 15. Disclaimer of Warranty. - - THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY -APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT -HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY -OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, -THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR -PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM -IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF -ALL NECESSARY SERVICING, REPAIR OR CORRECTION. - - 16. Limitation of Liability. - - IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING -WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS -THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY -GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE -USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF -DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD -PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), -EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF -SUCH DAMAGES. - - 17. Interpretation of Sections 15 and 16. - - If the disclaimer of warranty and limitation of liability provided -above cannot be given local legal effect according to their terms, -reviewing courts shall apply local law that most closely approximates -an absolute waiver of all civil liability in connection with the -Program, unless a warranty or assumption of liability accompanies a -copy of the Program in return for a fee. - - END OF TERMS AND CONDITIONS - - How to Apply These Terms to Your New Programs - - If you develop a new program, and you want it to be of the greatest -possible use to the public, the best way to achieve this is to make it -free software which everyone can redistribute and change under these terms. - - To do so, attach the following notices to the program. It is safest -to attach them to the start of each source file to most effectively -state the exclusion of warranty; and each file should have at least -the "copyright" line and a pointer to where the full notice is found. - - qpong - Copyright (C) 2019 Armin Co - - This program is free software: you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program. If not, see <http://www.gnu.org/licenses/>. - -Also add information on how to contact you by electronic and paper mail. - - If the program does terminal interaction, make it output a short -notice like this when it starts in an interactive mode: - - qpong Copyright (C) 2019 Armin Co - This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. - This is free software, and you are welcome to redistribute it - under certain conditions; type `show c' for details. - -The hypothetical commands `show w' and `show c' should show the appropriate -parts of the General Public License. Of course, your program's commands -might be different; for a GUI interface, you would use an "about box". - - You should also get your employer (if you work as a programmer) or school, -if any, to sign a "copyright disclaimer" for the program, if necessary. -For more information on this, and how to apply and follow the GNU GPL, see -<http://www.gnu.org/licenses/>. - - The GNU General Public License does not permit incorporating your program -into proprietary programs. If your program is a subroutine library, you -may consider it more useful to permit linking proprietary applications with -the library. If this is what you want to do, use the GNU Lesser General -Public License instead of this License. But first, please read -<http://www.gnu.org/philosophy/why-not-lgpl.html>. diff --git a/README.md b/README.md deleted file mode 100644 index e4d4f8d..0000000 --- a/README.md +++ /dev/null @@ -1,50 +0,0 @@ -# QPong – Quanten-Pong - -#### This is the new pong ;) - -A new kind of pong. It will feel familiar but different. -If you want two know more about what is happening behind the scenes visit [https://gitlab.cvh-server.de/pgerwinski/diss](https://gitlab.cvh-server.de/pgerwinski/diss). - -If youu play the game you will have to control bats as in the original pong game. But instead of a ball there is a quantum particle that you will have to hit. -The image on the left handside is where you play in it shows the particles "position". The image on the right handside shows the impulse of the particle. -Have fun! - -Controls for Player 1: A & Q and for Player two P & L. - - ---- - -Dependencies: - * cmake - * libgtkmm-3.0-dev - * libfftw3-dev - * libsdl2-dev - * libglfw3-dev - * libglm-dev - - ---- - -### Build and run -```` -mkdir build && cd build - -cmake .. - -make -j6 - -./gtk_qpong_app/qpong.app - -```` - -## TODOS - - ImageBuffer in die Klasse Particle ziehen, - - Methoden bereitstellen zum Abrufen der ImageBuffer - - ParticleImage muss das Particle Objekt kennen, um die ImageBuffer abrufen zu können. - - Umbauen der Klasse Particle zu einer Klasse Simulation Environemnt - -## Erweiterungsideen - - Konfiguration über die GUI, evt. mit speichern - - Spalt & Interferenz - - Controller-Schnittstelle (für z.B. Mikrofon, Joysticks oder Potis) - - Einfangen des Teilchens verhindern durch eine Vignette im Impulsraum. \ No newline at end of file diff --git a/gtk_qpong_app/CMakeLists.txt b/gtk_qpong_app/CMakeLists.txt deleted file mode 100644 index 714aeac..0000000 --- a/gtk_qpong_app/CMakeLists.txt +++ /dev/null @@ -1,30 +0,0 @@ - -# Setup GTK configuration -pkg_check_modules(GTKMM gtkmm-3.0) -link_directories(${GTKMM_LIBRARY_DIRS}) - - -# get all GTKMM dependencies and configuration -include_directories(${GTKMM_INCLUDE_DIRS}) - - -# create the application -add_executable( qpong.app - main.cpp - QWindow.cpp - QDrawingArea.cpp - ParticleImage.cpp -) - -find_package(Threads) - -# link all necessary libs to the target -target_link_libraries( qpong.app - qpong_core - spdlog - ${CMAKE_THREAD_LIBS_INIT} - ${GTKMM_LIBRARIES} - fftw3 - fftw3_omp - m # math -) diff --git a/gtk_qpong_app/ParticleImage.cpp b/gtk_qpong_app/ParticleImage.cpp deleted file mode 100644 index e51aa72..0000000 --- a/gtk_qpong_app/ParticleImage.cpp +++ /dev/null @@ -1,34 +0,0 @@ -/// -/// @file ParticleImage.cpp -/// @author Armin Co -/// - -#include "ParticleImage.hpp" -#include "Common.hpp" - -using namespace QPong; - -constexpr int bytesPerPixel = 3; -constexpr int bitsPerSample = 8; - -ParticleImage::ParticleImage() - : ImageBuffer() -{ - - m_pixbuf = new uChar[QPong::arraySize * bytesPerPixel]; -} - -Glib::RefPtr<Gdk::Pixbuf> ParticleImage::getPixbuf() -{ - for (unsigned i = 0; i < QPong::arraySize * bytesPerPixel;) - { - QColor c = getValue(i/bytesPerPixel); - m_pixbuf[i++] = static_cast<uChar>(c.r * 255); - m_pixbuf[i++] = static_cast<uChar>(c.g * 255); - m_pixbuf[i++] = static_cast<uChar>(c.b * 255); - } - - Glib::RefPtr<Gdk::Pixbuf> pb = Gdk::Pixbuf::create_from_data(m_pixbuf, Gdk::Colorspace::COLORSPACE_RGB, false, bitsPerSample, QPong::arrayWidth, QPong::arrayHeight, QPong::arrayWidth * bytesPerPixel); - pb = pb->scale_simple(768, 768, Gdk::InterpType::INTERP_NEAREST); - return pb; -} \ No newline at end of file diff --git a/gtk_qpong_app/ParticleImage.hpp b/gtk_qpong_app/ParticleImage.hpp deleted file mode 100644 index 8d8ab97..0000000 --- a/gtk_qpong_app/ParticleImage.hpp +++ /dev/null @@ -1,32 +0,0 @@ -/// -/// @file ParticleImage.hpp -/// @author Armin Co -/// -/// @brief Class to wrap one dimensional array. -/// - -#ifndef QPONG_PARTICLE_IMAGE_HPP -#define QPONG_PARTICLE_IMAGE_HPP - -#include <gtkmm.h> - -#include "ImageBuffer.hpp" - - - -/// @brief Wraps an one dimensional array. -/// Values can be accessed as in 2D. -/// -class ParticleImage : public QPong::ImageBuffer -{ -public: - ParticleImage(); - - Glib::RefPtr<Gdk::Pixbuf> getPixbuf(); - -private: - using uChar = unsigned char; - uChar* m_pixbuf; -}; - -#endif \ No newline at end of file diff --git a/gtk_qpong_app/QDrawingArea.cpp b/gtk_qpong_app/QDrawingArea.cpp deleted file mode 100644 index 674092c..0000000 --- a/gtk_qpong_app/QDrawingArea.cpp +++ /dev/null @@ -1,39 +0,0 @@ -/// -/// @file QDrawingArea.cpp -/// @author Armin Co -/// - -#include "QDrawingArea.hpp" - - -QDrawingArea::QDrawingArea() -{ - m_dispatcher.connect(sigc::mem_fun(*this, &QDrawingArea::queue_draw)); -} - - -void QDrawingArea::redraw() -{ - m_dispatcher.emit(); -} - - -void QDrawingArea::setPixbuf(Glib::RefPtr<Gdk::Pixbuf> pixbuf) -{ - m_image = pixbuf; -} - - -bool QDrawingArea::on_draw(const Cairo::RefPtr<Cairo::Context> &cr) -{ - cr->save(); - if (!m_image) - { - return true; - } - - Gdk::Cairo::set_source_pixbuf(cr, m_image, 0, 0); - cr->paint(); - cr->restore(); - return true; -} diff --git a/gtk_qpong_app/QDrawingArea.hpp b/gtk_qpong_app/QDrawingArea.hpp deleted file mode 100644 index e1d524a..0000000 --- a/gtk_qpong_app/QDrawingArea.hpp +++ /dev/null @@ -1,48 +0,0 @@ -/// -/// @file QDrawingArea.hpp -/// @author Armin Co -/// -/// @brief QDrawingArea is a class which can show a Gdk::Pixbuf. -/// - -#ifndef QPONG_DRAWING_AREA_HPP -#define QPONG_DRAWING_AREA_HPP - -#include <gtkmm.h> -#include <gdkmm.h> - - -/// @brief QDrawingArea is derived from Gtk::DrawingArea. -/// An object of this class stores a reference to Gdk::Pixbuf which can be shown and updated. -/// -class QDrawingArea : public Gtk::DrawingArea -{ -public: - QDrawingArea(); - - - virtual ~QDrawingArea(){}; - - - /// @brief Request a redraw of the drawing area. - /// - void redraw(); - - - /// @brief Set a new pixbuf reference. - /// - void setPixbuf(Glib::RefPtr<Gdk::Pixbuf> pixbuf); - - -protected: - /// @brief Signal handler which is called when a redraw of the drawing area is requested. - /// - bool on_draw(const Cairo::RefPtr<Cairo::Context> &cr) override; - - -private: - Glib::RefPtr<Gdk::Pixbuf> m_image; ///< Reference a pixbuf. - Glib::Dispatcher m_dispatcher; ///< Dispatcher is used to trigger thread safe redraws. -}; - -#endif \ No newline at end of file diff --git a/gtk_qpong_app/QWindow.cpp b/gtk_qpong_app/QWindow.cpp deleted file mode 100644 index f759a31..0000000 --- a/gtk_qpong_app/QWindow.cpp +++ /dev/null @@ -1,236 +0,0 @@ -#include <iostream> -#include <iomanip> -#include <chrono> - -#include "QWindow.hpp" - -using namespace QPong; - -bool propagating = true; -int propRate = 0; -int renderRate = 0; - -bool qPressed = false; -bool aPressed = false; -bool upPressed = false; -bool downPressed = false; - -/// @brief This functino has to run in its own thread and propagates the particle as fast as possible. -/// -void QWindow::simulation() -{ - do - { - auto start = std::chrono::system_clock::now(); - - m_particle->propagate(); - propRate = std::chrono::duration_cast<std::chrono::milliseconds>(std::chrono::system_clock::now() - start).count(); - - if (qPressed) - m_players[Player::Id::One]->move(Player::Direction::Up); - - if (aPressed) - m_players[Player::Id::One]->move(Player::Direction::Down); - - if (upPressed) - m_players[Player::Id::Two]->move(Player::Direction::Up); - - if (downPressed) - m_players[Player::Id::Two]->move(Player::Direction::Down); - - // Limit the speed of the simulation. - auto dt = std::chrono::system_clock::now() - start; - auto dtMillis = std::chrono::duration_cast<std::chrono::milliseconds>(dt).count(); - constexpr int propTime = 6; - if (dtMillis < propTime) - { - std::this_thread::sleep_for(std::chrono::milliseconds(propTime - dtMillis)); - } - } - while (propagating); -} - -/// @brief This function has to run in its own thread an will redraw the canvas every ~25ms. -/// -void render(QWindow *w) -{ - do - { - using namespace std::chrono_literals; - auto start = std::chrono::system_clock::now(); - std::this_thread::sleep_for(15ms); - w->updateView(); - renderRate = std::chrono::duration_cast<std::chrono::milliseconds>(std::chrono::system_clock::now() - start).count(); - } while (true); -} - -QWindow::QWindow() - : m_button{"Initialise Particle"} - , m_label("Hi, you are playing QPong and this is a label!") - , m_scorePlayerOne("0") - , m_scorePlayerTwo("0") -{ - set_border_width(5); - - constexpr double playerOneStartX = -0.7; - constexpr double playerTwoStartX = 0.7; - m_players.insert(std::make_pair<Player::Id, std::shared_ptr<Player>>(Player::Id::One, std::make_shared<Player>(Player::Id::One, Player::Position{-0.7, 0}))); - m_players.insert(std::make_pair<Player::Id, std::shared_ptr<Player>>(Player::Id::Two, std::make_shared<Player>(Player::Id::Two, Player::Position{ 0.7, 0.4}))); - - m_momentum = new ParticleImage; - m_position = new ParticleImage; - m_particle = new Particle(m_momentum, m_position, m_players); - - add(m_box); - m_box.pack_start(m_vBox); - m_vBox.pack_start(m_button, Gtk::PACK_SHRINK); - m_vBox.pack_start(m_label, Gtk::PACK_SHRINK); - - m_fpsBox.pack_start(m_renderRate, Gtk::PACK_EXPAND_WIDGET); - m_fpsBox.pack_start(m_proppergatingRate, Gtk::PACK_EXPAND_WIDGET); - m_vBox.pack_start(m_fpsBox, Gtk::PACK_SHRINK); - - m_scoreBox.pack_start(m_scorePlayerOne, Gtk::PACK_EXPAND_WIDGET); - m_scoreBox.pack_start(m_scorePlayerTwo, Gtk::PACK_EXPAND_WIDGET); - m_vBox.pack_start(m_scoreBox, Gtk::PACK_SHRINK); - - m_hBox.pack_start(m_positionArea, Gtk::PACK_EXPAND_WIDGET); - m_hBox.pack_start(m_momentumArea, Gtk::PACK_EXPAND_WIDGET); - m_vBox.pack_start(m_hBox); - - m_label.set_margin_top(5); - m_label.set_margin_bottom(5); - m_proppergatingRate.set_text("0"); - m_renderRate.set_text("0"); - m_renderRate.set_margin_top(5); - m_renderRate.set_margin_bottom(5); - m_proppergatingRate.set_margin_top(5); - m_proppergatingRate.set_margin_bottom(5); - - m_button.signal_clicked().connect(sigc::mem_fun(*this, &QWindow::onButtonPress)); - - this->signal_key_press_event().connect( sigc::mem_fun( *this, &QWindow::onKeyPress)); - this->signal_key_release_event().connect(sigc::mem_fun(*this, &QWindow::onKeyPress)); - - m_guiDispatcher.connect(sigc::mem_fun(*this, &QWindow::updateGui)); - m_areaDispatcher.connect(sigc::mem_fun(*this, &QWindow::updateImage)); - - while (m_particle->notReady()) - { - std::this_thread::sleep_for(std::chrono::milliseconds(1)); - } - - m_propagatingThread = std::thread(&QWindow::simulation, this); - m_propagatingThread.detach(); - - std::thread rendering(render, this); - rendering.detach(); - - m_box.show_all(); -} - -unsigned guiUpdates = 0; -void QWindow::updateGui() -{ - guiUpdates++; - if (guiUpdates % 10 == 0) - { - std::stringstream ss; - ss << "image update rate: "; - ss << 1000 / renderRate; - m_renderRate.set_text(ss.str()); - ss = std::stringstream(); - ss << "simulation rate: "; - ss << 1000 / propRate; - m_proppergatingRate.set_text(ss.str()); - - ss = std::stringstream(); - ss << "Score Player 1: "; - auto score = m_players[Player::Id::One]->getScore(); - ss << std::setprecision(2) << std::setw(7) << score << "%"; - if (score > 50.0) - { - ss << std::endl << "GEWONNEN!"; - ss << std::endl << "Zum Neustarten Partikel neu initialisieren"; - } - m_scorePlayerOne.set_text(ss.str()); - - ss = std::stringstream(); - ss << "Score Player 2: "; - score = m_players[Player::Id::Two]->getScore(); - ss << std::setprecision(2) << std::setw(7) << score << "%"; - if (score > 50.0) - { - ss << std::endl << "GEWONNEN!"; - ss << std::endl << "Zum Neustarten Partikel neu initialisieren"; - } - m_scorePlayerTwo.set_text(ss.str()); - } -} - - -bool QWindow::onKeyPress(GdkEventKey* event) -{ - constexpr int q = 113; - constexpr int a = 97; - constexpr int ue = 252; - constexpr int oe = 246; - constexpr int p = 112; - constexpr int l = 108; - - if (event->type == GdkEventType::GDK_KEY_PRESS) - { - if (event->keyval == q) - qPressed = true; - if (event->keyval == a) - aPressed = true; - if (event->keyval == p) - upPressed = true; - if (event->keyval == l) - downPressed = true; - } - else if (event->type == GdkEventType::GDK_KEY_RELEASE) - { - if (event->keyval == q) - qPressed = false; - if (event->keyval == a) - aPressed = false; - if (event->keyval == p) - upPressed = false; - if (event->keyval == l) - downPressed = false; - } - return true; -} - -void QWindow::updateView() -{ - m_areaDispatcher.emit(); - m_guiDispatcher.emit(); -} - -void QWindow::updateImage() -{ - m_positionArea.setPixbuf(m_position->getPixbuf()); - m_momentumArea.setPixbuf(m_momentum->getPixbuf()); - m_positionArea.redraw(); - m_momentumArea.redraw(); -} - -void QWindow::onButtonPress() -{ - propagating = false; - - std::this_thread::sleep_for((std::chrono::seconds)1); - m_particle->initMomentum(); - - for (auto player : m_players) - { - player.second->reset(); - } - - m_propagatingThread = std::thread(&QWindow::simulation, this); - - propagating = true; - m_propagatingThread.detach(); -} \ No newline at end of file diff --git a/gtk_qpong_app/QWindow.hpp b/gtk_qpong_app/QWindow.hpp deleted file mode 100644 index b9a610d..0000000 --- a/gtk_qpong_app/QWindow.hpp +++ /dev/null @@ -1,84 +0,0 @@ -/// -/// @file QWindow.hpp -/// @author Armin Co -/// - -#ifndef Q_WINDOW_HPP -#define Q_WINDOW_HPP - -#include <thread> -#include <map> -#include <memory> -#include <gtkmm.h> - -#include "Particle.hpp" -#include "ParticleImage.hpp" -#include "QDrawingArea.hpp" - -/// @brief Definition of the QPong window -/// -class QWindow : public Gtk::Window -{ -public: - - /// @brief Constructor of the window - /// - QWindow(); - - /// @brief Virtual destructor of the window. - /// - virtual ~QWindow(){} - - /// @brief Sends a signal to GTK to update drawing areas. - void updateView(); - -protected: - /// @brief signal handlers - /// - void onButtonPress(); - bool onKeyPress(GdkEventKey* event); - -private: - /// @brief Updates the QDrawingArea for position and momentum. - /// - void updateImage(); - - /// @brief Update all labels from the gui. - /// - void updateGui(); - - /// @brief Loop throug iteratins of the simulation - /// - void simulation(); - - Gtk::Box m_box; - Gtk::VBox m_vBox; - Gtk::HBox m_hBox; - Gtk::Box m_fpsBox; - - Gtk::Label m_label; - Gtk::Button m_button; - - Gtk::Label m_renderRate; - Gtk::Label m_proppergatingRate; - - Gtk::Box m_scoreBox; - Gtk::Label m_scorePlayerOne; - Gtk::Label m_scorePlayerTwo; - - Glib::Dispatcher m_guiDispatcher; - Glib::Dispatcher m_areaDispatcher; - - QDrawingArea m_positionArea; - QDrawingArea m_momentumArea; - - QPong::Particle *m_particle; - std::thread m_propagatingThread; - ParticleImage *m_momentum; - ParticleImage *m_position; - ParticleImage *m_obstacle; - - std::map<QPong::Player::Id, std::shared_ptr<QPong::Player>> m_players; -}; - -#endif \ No newline at end of file diff --git a/gtk_qpong_app/main.cpp b/gtk_qpong_app/main.cpp deleted file mode 100644 index f74f466..0000000 --- a/gtk_qpong_app/main.cpp +++ /dev/null @@ -1,41 +0,0 @@ -/// -/// @file main.cpp -/// @author Armin Co -/// -/// @brief The QPong game. -/// - -#include <iostream> -#include <thread> -#include <spdlog/spdlog.h> - -#include <gtkmm.h> - -#include "QWindow.hpp" - -/// @brief MAIN -/// -int main(int argc, char* argv[]) -{ - spdlog::info("QPong - Let's play quantum pong ;)"); - - spdlog::info("How To:"); - spdlog::info("The bats of player one and two must be moved manually. They can be moved eather up or down."); - spdlog::info("Controls player 1:"); - spdlog::info(" up: Q"); - spdlog::info(" down: A"); - spdlog::info("Controls player 2:"); - spdlog::info(" up: P"); - spdlog::info(" down: L"); - std::cout << std::endl; - spdlog::info("starting in two seconds - get ready!"); - spdlog::info("two restart the game: press 'enter', the 'space bar' or click the button 'Initialise Paritcle' with the mouse pointer."); - std::this_thread::sleep_for(std::chrono::seconds{2}); - - auto app = Gtk::Application::create(argc, argv, "de.armin-co.qpong"); - - QWindow window; - window.set_default_size(1920, 1080); - - return app->run(window); -} diff --git a/imgui_glfw_app/CMakeLists.txt b/imgui_glfw_app/CMakeLists.txt deleted file mode 100644 index a4bee75..0000000 --- a/imgui_glfw_app/CMakeLists.txt +++ /dev/null @@ -1,83 +0,0 @@ - -# Dear ImGui include dirs -include_directories( - ../libs/imgui - ../libs/imgui/examples - ../libs/imgui/examples/libs/gl3w -) - -# Main Dear ImGui src files. -set( - dear_im_gui_srcs - ../libs/imgui/imgui.cpp - ../libs/imgui/imgui_draw.cpp - ../libs/imgui/imgui_widgets.cpp -) - -# Impl files from Dear ImGui. -set( - dear_im_gui_impl_srcs - ../libs/imgui/examples/imgui_impl_glfw.cpp - ../libs/imgui/examples/imgui_impl_opengl3.cpp -) - -# Dear ImGui lib -add_library( - dear_im_gui_glfw - ${dear_im_gui_srcs} - ${dear_im_gui_impl_srcs} - ../libs/imgui/examples/libs/gl3w/GL/gl3w.c -) - -# Application base on Dear ImGui -add_executable( - imgui_glfw_playground.app - imgui_glfw_playground.cpp - LoadShaders.cpp -) - -add_custom_command(TARGET imgui_glfw_playground.app PRE_BUILD - COMMAND ${CMAKE_COMMAND} -E copy_directory - ${CMAKE_SOURCE_DIR}/imgui_glfw_app/shaders $<TARGET_FILE_DIR:imgui_glfw_playground.app>) - - -pkg_check_modules(GLFW glfw3) -include_directories(${GLFW_INCLUDE_DIRS}) -message(${GLFW_LIBRARIES}) - -# Link everything together -target_link_libraries( - imgui_glfw_playground.app - dear_im_gui_glfw - qpong_core - ${GLFW_LIBRARIES} -) - -# Include macOS specific things. -if(APPLE) - # dependencies for macOS - # brew install glfw - # brew install glm - find_library(COCOA_LIBRARY Cocoa REQUIRED) - find_library(IOKIT_LIBRARY IOKit REQUIRED) - find_library(COREVID_LIBRARY CoreVideo REQUIRED) - find_library(OPENGL_LIBRARY OpenGL REQUIRED) - - message(${COCOA_LIBRARY}) - message(${IOKIT_LIBRARY}) - message(${COREVID_LIBRARY}) - message(${OPENGL_LIBRARY}) - - target_link_libraries( - imgui_glfw_playground.app - ${COCOA_LIBRARY} - ${IOKIT_LIBRARY} - ${COREVID_LIBRARY} - ${OPENGL_LIBRARY} - ) -else(APPLE) - find_package(OpenGL REQUIRED) - target_link_libraries(imgui_glfw_playground.app OpenGL::GL ${CMAKE_DL_LIBS}) -endif() - - diff --git a/imgui_glfw_app/LoadShaders.cpp b/imgui_glfw_app/LoadShaders.cpp deleted file mode 100644 index 36feb49..0000000 --- a/imgui_glfw_app/LoadShaders.cpp +++ /dev/null @@ -1,96 +0,0 @@ -#include "LoadShaders.hpp" - -#include <iostream> -#include <fstream> -#include <string> -#include <sstream> -#include <vector> -#include <GL/gl3w.h> - -unsigned int LoadShaders(const char * vertex_file_path,const char * fragment_file_path){ - - // Create the shaders - unsigned int VertexShaderID = glCreateShader(GL_VERTEX_SHADER); - unsigned int FragmentShaderID = glCreateShader(GL_FRAGMENT_SHADER); - - // Read the Vertex Shader code from the file - std::string VertexShaderCode; - std::ifstream VertexShaderStream(vertex_file_path, std::ios::in); - if(VertexShaderStream.is_open()){ - std::stringstream sstr; - sstr << VertexShaderStream.rdbuf(); - VertexShaderCode = sstr.str(); - VertexShaderStream.close(); - }else{ - printf("Impossible to open %s. Are you in the right directory ? Don't forget to read the FAQ !\n", vertex_file_path); - getchar(); - return 0; - } - - // Read the Fragment Shader code from the file - std::string FragmentShaderCode; - std::ifstream FragmentShaderStream(fragment_file_path, std::ios::in); - if(FragmentShaderStream.is_open()){ - std::stringstream sstr; - sstr << FragmentShaderStream.rdbuf(); - FragmentShaderCode = sstr.str(); - FragmentShaderStream.close(); - } - - GLint Result = GL_FALSE; - int InfoLogLength; - - // Compile Vertex Shader - printf("Compiling shader : %s\n", vertex_file_path); - char const * VertexSourcePointer = VertexShaderCode.c_str(); - glShaderSource(VertexShaderID, 1, &VertexSourcePointer , NULL); - glCompileShader(VertexShaderID); - - // Check Vertex Shader - glGetShaderiv(VertexShaderID, GL_COMPILE_STATUS, &Result); - glGetShaderiv(VertexShaderID, GL_INFO_LOG_LENGTH, &InfoLogLength); - if ( InfoLogLength > 0 ){ - std::vector<char> VertexShaderErrorMessage(InfoLogLength+1); - glGetShaderInfoLog(VertexShaderID, InfoLogLength, NULL, &VertexShaderErrorMessage[0]); - printf("%s\n", &VertexShaderErrorMessage[0]); - } - - // Compile Fragment Shader - printf("Compiling shader : %s\n", fragment_file_path); - char const * FragmentSourcePointer = FragmentShaderCode.c_str(); - glShaderSource(FragmentShaderID, 1, &FragmentSourcePointer , NULL); - glCompileShader(FragmentShaderID); - - // Check Fragment Shader - glGetShaderiv(FragmentShaderID, GL_COMPILE_STATUS, &Result); - glGetShaderiv(FragmentShaderID, GL_INFO_LOG_LENGTH, &InfoLogLength); - if ( InfoLogLength > 0 ){ - std::vector<char> FragmentShaderErrorMessage(InfoLogLength+1); - glGetShaderInfoLog(FragmentShaderID, InfoLogLength, NULL, &FragmentShaderErrorMessage[0]); - printf("%s\n", &FragmentShaderErrorMessage[0]); - } - - // Link the program - printf("Linking program\n"); - GLuint ProgramID = glCreateProgram(); - glAttachShader(ProgramID, VertexShaderID); - glAttachShader(ProgramID, FragmentShaderID); - glLinkProgram(ProgramID); - - // Check the program - glGetProgramiv(ProgramID, GL_LINK_STATUS, &Result); - glGetProgramiv(ProgramID, GL_INFO_LOG_LENGTH, &InfoLogLength); - if ( InfoLogLength > 0 ){ - std::vector<char> ProgramErrorMessage(InfoLogLength+1); - glGetProgramInfoLog(ProgramID, InfoLogLength, NULL, &ProgramErrorMessage[0]); - printf("%s\n", &ProgramErrorMessage[0]); - } - - glDetachShader(ProgramID, VertexShaderID); - glDetachShader(ProgramID, FragmentShaderID); - - glDeleteShader(VertexShaderID); - glDeleteShader(FragmentShaderID); - - return ProgramID; -} diff --git a/imgui_glfw_app/LoadShaders.hpp b/imgui_glfw_app/LoadShaders.hpp deleted file mode 100644 index 69b61c6..0000000 --- a/imgui_glfw_app/LoadShaders.hpp +++ /dev/null @@ -1,7 +0,0 @@ -/// @brief LoadShader from filesystem. -/// -/// @param vertex_file_path Path to the vertex shader file -/// @param fragment_file_path Path to the fragment shader file -/// @return Returns the id of the shader -/// -unsigned int LoadShaders(const char * vertex_file_path,const char * fragment_file_path); \ No newline at end of file diff --git a/imgui_glfw_app/imgui_glfw_playground.cpp b/imgui_glfw_app/imgui_glfw_playground.cpp deleted file mode 100644 index 04a49d6..0000000 --- a/imgui_glfw_app/imgui_glfw_playground.cpp +++ /dev/null @@ -1,348 +0,0 @@ -#include "imgui.h" -#include "imgui_impl_glfw.h" -#include "imgui_impl_opengl3.h" -#include <stdio.h> - -#include <GL/gl3w.h> // Initialize with gl3wInit() -#include <GLFW/glfw3.h> - -#include <iostream> - -#include "LoadShaders.hpp" -#include <glm/glm.hpp> -#include <glm/gtc/matrix_transform.hpp> - -static void glfw_error_callback(int error, const char* description) -{ - fprintf(stderr, "Glfw Error %d: %s\n", error, description); -} - -void drawGui() -{ - ImVec4 clear_color = ImVec4(0.45f, 0.55f, 0.60f, 1.00f); - - static float f = 0.0f; - static int counter = 0; - - ImGui::Begin("Hello, world!"); // Create a window called "Hello, world!" and append into it. - - ImGui::Text("This is some useful text."); // Display some text (you can use a format strings too) - - ImGui::SliderFloat("float", &f, 0.0f, 1.0f); // Edit 1 float using a slider from 0.0f to 1.0f - ImGui::ColorEdit3("clear color", (float*)&clear_color); // Edit 3 floats representing a color - - if (ImGui::Button("Button")){ // Buttons return true when clicked (most widgets return true when edited/activated) - counter++; - } - ImGui::SameLine(); - ImGui::Text("counter = %d", counter); - - ImGui::Text("Application average %.3f ms/frame (%.1f FPS)", 1000.0f / ImGui::GetIO().Framerate, ImGui::GetIO().Framerate); - ImGui::End(); -} - -int main(int, char**) -{ - // Setup window - glfwSetErrorCallback(glfw_error_callback); - if (!glfwInit()) - return 1; - - // Decide GL+GLSL versions -#if __APPLE__ - // GL 3.2 + GLSL 150 - const char* glsl_version = "#version 150"; - glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3); - glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 2); - glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE); // 3.2+ only - glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE); // Required on Mac -#else - // GL 3.0 + GLSL 130 - const char* glsl_version = "#version 130"; - glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3); - glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 0); -#endif - - // Create window with graphics context - GLFWwindow* window = glfwCreateWindow(1280, 720, "Dear ImGui GLFW+OpenGL3 example", NULL, NULL); - if (window == NULL) - return 1; - glfwMakeContextCurrent(window); - glfwSwapInterval(1); // Enable vsync - - // Initialize OpenGL loader - bool err = gl3wInit() != 0; - if (err) - { - fprintf(stderr, "Failed to initialize OpenGL loader!\n"); - return 1; - } - - // Setup Dear ImGui context - IMGUI_CHECKVERSION(); - ImGui::CreateContext(); - ImGuiIO& io = ImGui::GetIO(); (void)io; - - // Setup Dear ImGui style - ImGui::StyleColorsDark(); - - // Setup Platform/Renderer bindings - ImGui_ImplGlfw_InitForOpenGL(window, true); - ImGui_ImplOpenGL3_Init(glsl_version); - - - // unsigned int vertexArrayId {}; // Store a vertex array id. - // glGenVertexArrays(1, &vertexArrayId); // Receive a id. - // glBindVertexArray(vertexArrayId); // Bind that id. - - static const float g_vertex_buffer_data_triangle[] = { - -1.0f, -1.0f, 0.0f, - 1.0f, -1.0f, 0.0f, - 0.0f, 1.0f, 0.0f, - }; - - static GLfloat g_color_buffer_data_triangle[12*3*3]; - for (int v = 0; v < 12*3 ; v++){ - g_color_buffer_data_triangle[3*v+0] = 0.1f; - g_color_buffer_data_triangle[3*v+1] = 0.5f; - g_color_buffer_data_triangle[3*v+2] = 0.7f; - } - - static const GLfloat g_vertex_buffer_data_cube[] = { - -1.0f,-1.0f,-1.0f, // triangle 1 : begin - -1.0f,-1.0f, 1.0f, - -1.0f, 1.0f, 1.0f, // triangle 1 : end - 1.0f, 1.0f,-1.0f, // triangle 2 : begin - -1.0f,-1.0f,-1.0f, - -1.0f, 1.0f,-1.0f, // triangle 2 : end - 1.0f,-1.0f, 1.0f, - -1.0f,-1.0f,-1.0f, - 1.0f,-1.0f,-1.0f, - 1.0f, 1.0f,-1.0f, - 1.0f,-1.0f,-1.0f, - -1.0f,-1.0f,-1.0f, - -1.0f,-1.0f,-1.0f, - -1.0f, 1.0f, 1.0f, - -1.0f, 1.0f,-1.0f, - 1.0f,-1.0f, 1.0f, - -1.0f,-1.0f, 1.0f, - -1.0f,-1.0f,-1.0f, - -1.0f, 1.0f, 1.0f, - -1.0f,-1.0f, 1.0f, - 1.0f,-1.0f, 1.0f, - 1.0f, 1.0f, 1.0f, - 1.0f,-1.0f,-1.0f, - 1.0f, 1.0f,-1.0f, - 1.0f,-1.0f,-1.0f, - 1.0f, 1.0f, 1.0f, - 1.0f,-1.0f, 1.0f, - 1.0f, 1.0f, 1.0f, - 1.0f, 1.0f,-1.0f, - -1.0f, 1.0f,-1.0f, - 1.0f, 1.0f, 1.0f, - -1.0f, 1.0f,-1.0f, - -1.0f, 1.0f, 1.0f, - 1.0f, 1.0f, 1.0f, - -1.0f, 1.0f, 1.0f, - 1.0f,-1.0f, 1.0f -}; - -static const GLfloat g_color_buffer_data_cube[] = { - 0.583f, 0.771f, 0.014f, - 0.609f, 0.115f, 0.436f, - 0.327f, 0.483f, 0.844f, - 0.822f, 0.569f, 0.201f, - 0.435f, 0.602f, 0.223f, - 0.310f, 0.747f, 0.185f, - 0.597f, 0.770f, 0.761f, - 0.559f, 0.436f, 0.730f, - 0.359f, 0.583f, 0.152f, - 0.483f, 0.596f, 0.789f, - 0.559f, 0.861f, 0.639f, - 0.195f, 0.548f, 0.859f, - 0.014f, 0.184f, 0.576f, - 0.771f, 0.328f, 0.970f, - 0.406f, 0.615f, 0.116f, - 0.676f, 0.977f, 0.133f, - 0.971f, 0.572f, 0.833f, - 0.140f, 0.616f, 0.489f, - 0.997f, 0.513f, 0.064f, - 0.945f, 0.719f, 0.592f, - 0.543f, 0.021f, 0.978f, - 0.279f, 0.317f, 0.505f, - 0.167f, 0.620f, 0.077f, - 0.347f, 0.857f, 0.137f, - 0.055f, 0.953f, 0.042f, - 0.714f, 0.505f, 0.345f, - 0.783f, 0.290f, 0.734f, - 0.722f, 0.645f, 0.174f, - 0.302f, 0.455f, 0.848f, - 0.225f, 0.587f, 0.040f, - 0.517f, 0.713f, 0.338f, - 0.053f, 0.959f, 0.120f, - 0.393f, 0.621f, 0.362f, - 0.673f, 0.211f, 0.457f, - 0.820f, 0.883f, 0.371f, - 0.982f, 0.099f, 0.879f -}; - - unsigned int vertexBufferCube {}; - glGenBuffers(1, &vertexBufferCube); - glBindBuffer(GL_ARRAY_BUFFER, vertexBufferCube); - glBufferData(GL_ARRAY_BUFFER, sizeof(g_vertex_buffer_data_cube), g_vertex_buffer_data_cube, GL_STATIC_DRAW); - - unsigned int colorBufferCube {}; - glGenBuffers(1, &colorBufferCube); - glBindBuffer(GL_ARRAY_BUFFER, colorBufferCube); - glBufferData(GL_ARRAY_BUFFER, sizeof(g_color_buffer_data_cube), g_color_buffer_data_cube, GL_STATIC_DRAW); - - unsigned int vertexBufferTriangle {}; - glGenBuffers(1, &vertexBufferTriangle); - glBindBuffer(GL_ARRAY_BUFFER, vertexBufferTriangle); - glBufferData(GL_ARRAY_BUFFER, sizeof(g_vertex_buffer_data_triangle), g_vertex_buffer_data_triangle, GL_STATIC_DRAW); - - unsigned int colorBufferTriangle {}; - glGenBuffers(1, &colorBufferTriangle); - glBindBuffer(GL_ARRAY_BUFFER, colorBufferTriangle); - glBufferData(GL_ARRAY_BUFFER, sizeof(g_color_buffer_data_triangle), g_color_buffer_data_triangle, GL_STATIC_DRAW); - - unsigned int shaderId = LoadShaders("SimpleVertexShader.glsl", "FragmentShader.glsl"); - - glEnable(GL_DEPTH_TEST); - glDepthFunc(GL_LESS); - - - int width, height; - glfwGetFramebufferSize(window, &width, &height); - - // Projection matrix : 45° Field of View, 4:3 ratio, display range : 0.1 unit <-> 100 units - glm::mat4 Projection = glm::perspective(glm::radians(150.0f), (float) width / (float)height, 0.1f, 100.0f); - glm::mat4 ProjectionTriangle = glm::perspective(glm::radians(30.0f), (float) width / (float)height, 0.1f, 100.0f); - - // Camera matrix - glm::mat4 View = glm::lookAt( - glm::vec3(4,3,3), // Camera is at (4,3,3), in World Space - glm::vec3(0,0,0), // and looks at the origin - glm::vec3(0,1,0) // Head is up (set to 0,-1,0 to look upside-down) - ); - - // Model matrix : an identity matrix (model will be at the origin) - glm::mat4 Model = glm::mat4(1.0f); - // Our ModelViewProjection : multiplication of our 3 matrices - glm::mat4 mvp = Projection * View * Model; // Remember, matrix multiplication is the other way around - glm::mat4 mvpTriangle = ProjectionTriangle * View * Model; - - // Get a handle for our "MVP" uniform - // Only during the initialisation - // GLuint MatrixID = glGetUniformLocation(shaderId, "MVP"); - // GLuint MatrixIDT = glGetUniformLocation(shaderId, "MVPT"); - - - unsigned int MatrixIDCube = glGetUniformLocation(shaderId, "MVP"); - unsigned int MatrixIDTriangle = glGetUniformLocation(shaderId, "MVPT"); - - // Main loop - while (!glfwWindowShouldClose(window)) - { - glfwPollEvents(); - - // Start the Dear ImGui frame - ImGui_ImplOpenGL3_NewFrame(); - ImGui_ImplGlfw_NewFrame(); - ImGui::NewFrame(); - - // Draw GUI with Dear ImGui. - drawGui(); - - // Rendering - ImGui::Render(); - { - // int width, height; - glfwGetFramebufferSize(window, &width, &height); - glViewport(0, 0, width, height); - glClearColor(0.1f, 0.2f, 0.2f, 1.0f); - glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); - - // Send our transformation to the currently bound shader, in the "MVP" uniform - // This is done in the main loop since each model will have a different MVP matrix (At least for the M part) - glUniformMatrix4fv(MatrixIDCube, 1, GL_FALSE, &mvp[0][0]); - glUseProgram(shaderId); - - glEnableVertexAttribArray(0); - glBindBuffer(GL_ARRAY_BUFFER, vertexBufferCube); - glVertexAttribPointer( - 0, - 3, - GL_FLOAT, - GL_FALSE, - 0, - (void*)0 - ); - - glEnableVertexAttribArray(1); - glBindBuffer(GL_ARRAY_BUFFER, colorBufferCube); - glVertexAttribPointer( - 1, - 3, - GL_FLOAT, - GL_FALSE, - 0, - (void*)0 - ); - - // glUniformMatrix4fv(MatrixIDCube, 1, GL_FALSE, &mvp[0][0]); - glDrawArrays(GL_TRIANGLES, 0, sizeof(g_vertex_buffer_data_cube)/3); - - - // glDisableVertexAttribArray(0); - // glDisableVertexAttribArray(1); - - - // glUniformMatrix4fv(MatrixIDTriangle, 1, GL_FALSE, &mvpTriangle[0][0]); - // glUseProgram(shaderId); - // glEnableVertexAttribArray(0); - - // glBindBuffer(GL_ARRAY_BUFFER, vertexBufferTriangle); - // glVertexAttribPointer( - // 0, - // 3, - // GL_FLOAT, - // GL_FALSE, - // 0, - // (void*)0 - // ); - // glEnableVertexAttribArray(1); - - // glBindBuffer(GL_ARRAY_BUFFER, colorBufferTriangle); - // glVertexAttribPointer( - // 1, - // 3, - // GL_FLOAT, - // GL_FALSE, - // 0, - // (void*)0 - // ); - - - // glDrawArrays(GL_TRIANGLES, 0, sizeof(g_vertex_buffer_data_triangle)/3); - - glDisableVertexAttribArray(0); - glDisableVertexAttribArray(1); - - } - - - ImGui_ImplOpenGL3_RenderDrawData(ImGui::GetDrawData()); - glfwSwapBuffers(window); - } - - // Cleanup - ImGui_ImplOpenGL3_Shutdown(); - ImGui_ImplGlfw_Shutdown(); - ImGui::DestroyContext(); - - glfwDestroyWindow(window); - glfwTerminate(); - - return 0; -} diff --git a/imgui_glfw_app/shaders/FragmentShader.glsl b/imgui_glfw_app/shaders/FragmentShader.glsl deleted file mode 100644 index 9ed28d8..0000000 --- a/imgui_glfw_app/shaders/FragmentShader.glsl +++ /dev/null @@ -1,8 +0,0 @@ -#version 330 - -in vec3 fragmentColor; -out vec3 outColor; - -void main(){ - outColor = fragmentColor; -} \ No newline at end of file diff --git a/imgui_glfw_app/shaders/SimpleVertexShader.glsl b/imgui_glfw_app/shaders/SimpleVertexShader.glsl deleted file mode 100644 index 0aca2df..0000000 --- a/imgui_glfw_app/shaders/SimpleVertexShader.glsl +++ /dev/null @@ -1,13 +0,0 @@ -#version 330 core - -layout(location = 0) in vec3 vertexPosition_modelspace; -layout(location = 1) in vec3 vertexColor; - -out vec3 fragmentColor; - -uniform mat4 MVP; - -void main(){ - gl_Position = MVP * vec4(vertexPosition_modelspace, 1); - fragmentColor = vertexColor; -} \ No newline at end of file diff --git a/imgui_sdl_app/CMakeLists.txt b/imgui_sdl_app/CMakeLists.txt deleted file mode 100644 index dcbb8a8..0000000 --- a/imgui_sdl_app/CMakeLists.txt +++ /dev/null @@ -1,71 +0,0 @@ - -# Dear ImGui include dirs -include_directories( - ../libs/imgui - ../libs/imgui/examples - ../libs/imgui/examples/libs/gl3w -) - -# Main Dear ImGui src files. -set( - dear_im_gui_srcs - ../libs/imgui/imgui.cpp - ../libs/imgui/imgui_draw.cpp - ../libs/imgui/imgui_widgets.cpp -) - -# Impl files from Dear ImGui. -set( - dear_im_gui_impl_srcs - ../libs/imgui/examples/imgui_impl_sdl.cpp - ../libs/imgui/examples/imgui_impl_opengl3.cpp -) - -# Dear ImGui lib -add_library( - dear_im_gui - ${dear_im_gui_srcs} - ${dear_im_gui_impl_srcs} - ../libs/imgui/examples/libs/gl3w/GL/gl3w.c -) - -# Application base on Dear ImGui -add_executable( - imgui_playground.app - imgui_playground.cpp -) - - -# Add all SDL2 dependencies. -find_package(SDL2 REQUIRED) -include_directories(${SDL2_INCLUDE_DIRS}) - -# Link everything together -target_link_libraries( - imgui_playground.app - dear_im_gui - ${SDL2_LIBRARIES} - qpong_core -) - -# Include macOS specific things. -if(APPLE) - find_library(COCOA_LIBRARY Cocoa REQUIRED) - find_library(IOKIT_LIBRARY IOKit REQUIRED) - find_library(COREVID_LIBRARY CoreVideo REQUIRED) - message(${COCOA_LIBRARY}) - message(${IOKIT_LIBRARY}) - message(${COREVID_LIBRARY}) - - target_link_libraries( - imgui_playground.app - ${COCOA_LIBRARY} - ${IOKIT_LIBRARY} - ${COREVID_LIBRARY} - ) -else(APPLE) - find_package(OpenGL REQUIRED) - target_link_libraries(imgui_playground.app OpenGL::GL ${CMAKE_DL_LIBS}) -endif() - - diff --git a/imgui_sdl_app/imgui_playground.cpp b/imgui_sdl_app/imgui_playground.cpp deleted file mode 100644 index 368f368..0000000 --- a/imgui_sdl_app/imgui_playground.cpp +++ /dev/null @@ -1,194 +0,0 @@ -/// @file imgui_playground.cppp -/// @author Armin Co -/// @brief Working example for Dear ImGui with OpenGL3 and SDL2 -/// - -#include<iostream> - -#include <SDL.h> -#include <GL/gl3w.h> - -#include "imgui.h" -#include "imgui_impl_sdl.h" -#include "imgui_impl_opengl3.h" - - -void setSdlGlAttributesApple() -{ - SDL_GL_SetAttribute(SDL_GL_CONTEXT_FLAGS, SDL_GL_CONTEXT_FORWARD_COMPATIBLE_FLAG); // Always required on Mac - SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_CORE); - SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 3); - SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 2); -} - -void setSdlGlAttributesLinux() -{ - SDL_GL_SetAttribute(SDL_GL_CONTEXT_FLAGS, 0); - SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_CORE); - SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 3); - SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 0); -} - -void setSdlGlAttributesCommon() -{ - // Create window with graphics context - SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1); - SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 24); - SDL_GL_SetAttribute(SDL_GL_STENCIL_SIZE, 8); -} - -#include <vector> -#include "ImageBuffer.hpp" -const std::vector<QPong::QColor> colors { - {0.3f, 0.2f, 0.4f}, - {0.3f, 0.2f, 0.4f}, - {0.3f, 0.2f, 0.4f}, - {0.3f, 0.2f, 0.4f}, - {0.3f, 0.2f, 0.4f}, - {0.3f, 0.2f, 0.4f}, - {0.3f, 0.2f, 0.4f}, - {0.3f, 0.2f, 0.4f}, - {0.3f, 0.2f, 0.4f}, - {0.3f, 0.2f, 0.4f}, - {0.3f, 0.2f, 0.4f}, - {0.3f, 0.2f, 0.4f}, - {0.3f, 0.2f, 0.4f}, - {0.3f, 0.2f, 0.4f}, - {0.3f, 0.2f, 0.4f}, - {0.3f, 0.2f, 0.4f}, - {0.3f, 0.2f, 0.4f}, - {0.3f, 0.2f, 0.4f}, - {0.3f, 0.2f, 0.4f}, - {0.3f, 0.2f, 0.4f}, - {0.3f, 0.2f, 0.4f} -}; - -const std::vector<ImVec2> positions { - {0.0f, 0.0f}, - {0.1f, 0.0f}, - {0.2f, 0.0f}, - {0.3f, 0.0f}, - {0.4f, 0.0f}, - {0.5f, 0.0f}, - {0.6f, 0.0f}, - {0.7f, 0.0f}, - {0.8f, 0.0f}, - {0.9f, 0.0f}, - {0.0f, 0.1f}, - {0.0f, 0.2f}, - {0.0f, 0.3f}, - {0.0f, 0.4f}, - {0.0f, 0.5f}, - {0.0f, 0.6f}, - {0.0f, 0.7f}, - {0.0f, 0.8f}, - {0.0f, 0.9f}, - {0.0f, 0.9f}, - {0.5f, 0.5f} -}; - -void displayPoints() -{ -} - -int main(void) -{ - if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_TIMER | SDL_INIT_GAMECONTROLLER) != 0) - { - std::cerr << "Error: " << SDL_GetError() << '\n'; - return -1; - } - - // Decide GL+GLSL versions - #if __APPLE__ - // GL 3.2 Core + GLSL 150 - const char* glsl_version = "#version 150"; - setSdlGlAttributesApple(); - #else - // GL 3.0 + GLSL 130 - const char* glsl_version = "#version 130"; - setSdlGlAttributesLinux(); - #endif - - setSdlGlAttributesCommon(); - - SDL_WindowFlags window_flags = static_cast<SDL_WindowFlags>(SDL_WINDOW_OPENGL | SDL_WINDOW_RESIZABLE | SDL_WINDOW_ALLOW_HIGHDPI); - SDL_Window* window = SDL_CreateWindow("Dear ImGui SDL2+OpenGL3 example", SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, 1280, 720, window_flags); - SDL_GLContext gl_context = SDL_GL_CreateContext(window); - SDL_GL_MakeCurrent(window, gl_context); - SDL_GL_SetSwapInterval(1); // Enable vsync - - // Initialize OpenGL loader - if (gl3wInit() != 0) - { - std::cerr << "Failed to initialize OpenGL loader!\n"; - return 1; - } - - IMGUI_CHECKVERSION(); - ImGui::CreateContext(); - ImGuiIO& io = ImGui::GetIO(); (void)io; - ImGui::StyleColorsDark(); - ImGui_ImplSDL2_InitForOpenGL(window, gl_context); - ImGui_ImplOpenGL3_Init(glsl_version); - - ImVec4 clear_color = ImVec4(0.45f, 0.55f, 0.60f, 1.00f); - bool done = false; - while (!done) - { - SDL_Event event {}; - while (SDL_PollEvent(&event)) - { - ImGui_ImplSDL2_ProcessEvent(&event); - if (event.type == SDL_QUIT){ - done = true; - } - else if (event.type == SDL_WINDOWEVENT && event.window.event == SDL_WINDOWEVENT_CLOSE && event.window.windowID == SDL_GetWindowID(window)){ - done = true; - } - } - - ImGui_ImplOpenGL3_NewFrame(); - ImGui_ImplSDL2_NewFrame(window); - ImGui::NewFrame(); - - { // Config GUI - static float f = 0.0f; - static int counter = 0; - - ImGui::Begin("Hello, world!"); // Create a window called "Hello, world!" and append into it. - ImGui::Text("This is some useful text."); // Display some text (you can use a format strings too) - ImGui::SliderFloat("float", &f, 0.0f, 1.0f); // Edit 1 float using a slider from 0.0f to 1.0f - ImGui::ColorEdit3("clear color", (float*)&clear_color); // Edit 3 floats representing a color - if (ImGui::Button("Button")){ // Buttons return true when clicked (most widgets return true when edited/activated) - counter++; - } - ImGui::SameLine(); - ImGui::Text("counter = %d", counter); - ImGui::Text("Application average %.3f ms/frame (%.1f FPS)", 1000.0f / ImGui::GetIO().Framerate, ImGui::GetIO().Framerate); - ImGui::End(); - } - - // Rendering - ImGui::Render(); - - { // own OpenGL code goes here like this background clearing. - glViewport(0, 0, (int)io.DisplaySize.x, (int)io.DisplaySize.y); - glClearColor(clear_color.x, clear_color.y, clear_color.z, clear_color.w); - glClear(GL_COLOR_BUFFER_BIT); - } - - ImGui_ImplOpenGL3_RenderDrawData(ImGui::GetDrawData()); - SDL_GL_SwapWindow(window); - } - - ImGui_ImplOpenGL3_Shutdown(); - ImGui_ImplSDL2_Shutdown(); - ImGui::DestroyContext(); - - SDL_GL_DeleteContext(gl_context); - SDL_DestroyWindow(window); - SDL_Quit(); - - return 0; -} \ No newline at end of file diff --git a/libs/CMakeLists.txt b/libs/CMakeLists.txt deleted file mode 100644 index e69de29..0000000 diff --git a/libs/cpp_starter_project b/libs/cpp_starter_project deleted file mode 160000 index d7a2b6b..0000000 --- a/libs/cpp_starter_project +++ /dev/null @@ -1 +0,0 @@ -Subproject commit d7a2b6b891d75edc68c9d88dca7e24cd73e378b8 diff --git a/libs/googletest b/libs/googletest deleted file mode 160000 index fe4d5f1..0000000 --- a/libs/googletest +++ /dev/null @@ -1 +0,0 @@ -Subproject commit fe4d5f10840c5f62b984364a4d41719f1bc079a2 diff --git a/libs/imgui b/libs/imgui deleted file mode 160000 index ae93691..0000000 --- a/libs/imgui +++ /dev/null @@ -1 +0,0 @@ -Subproject commit ae93691360ad28e6c217138ead55c874dda26f80 diff --git a/libs/spdlog b/libs/spdlog deleted file mode 160000 index 9799eca..0000000 --- a/libs/spdlog +++ /dev/null @@ -1 +0,0 @@ -Subproject commit 9799ecac6a0b64df16f9c6e0e8ebcedbd22d8432 diff --git a/qpong_core/CMakeLists.txt b/qpong_core/CMakeLists.txt deleted file mode 100644 index 0776bfa..0000000 --- a/qpong_core/CMakeLists.txt +++ /dev/null @@ -1,8 +0,0 @@ - -# Core QPong library -add_library( - qpong_core - Particle.cpp - ImageBuffer.cpp - Player.cpp -) diff --git a/qpong_core/Common.hpp b/qpong_core/Common.hpp deleted file mode 100644 index 1e0a6c6..0000000 --- a/qpong_core/Common.hpp +++ /dev/null @@ -1,30 +0,0 @@ -/// -/// @file Common.hpp -/// @author Armin Co -/// - -#ifndef QPONG_COMMON_HPP -#define QPONG_COMMON_HPP - -namespace QPong -{ - -constexpr int arrayWidth = 384 * 1; -constexpr int arrayHeight = 384 * 1; -constexpr int numberOfThreads = 8; - -constexpr unsigned arraySize = arrayWidth * arrayHeight; - -static_assert(arraySize % numberOfThreads == 0, "Number of threads and array size doesn't match!"); - - -/// @brief Calc square of a number. -/// -template <typename T> -const T sqr(const T n) -{ - return n * n; -} - -} -#endif \ No newline at end of file diff --git a/qpong_core/ImageBuffer.cpp b/qpong_core/ImageBuffer.cpp deleted file mode 100644 index 7f4aa82..0000000 --- a/qpong_core/ImageBuffer.cpp +++ /dev/null @@ -1,50 +0,0 @@ -/// -/// @file ImageBuffer.cpp -/// - -#include "Common.hpp" -#include "ImageBuffer.hpp" - -using namespace QPong; - -ImageBuffer::ImageBuffer() -{ - m_potbuf = new double[QPong::arraySize]; - m_complexBuffer = new std::complex<double>[QPong::arraySize]; -} - - -void ImageBuffer::updateAt(unsigned index, std::complex<double> v, double obs) -{ - m_potbuf[index] = obs; - m_complexBuffer[index] = v; -} - - -const QColor ImageBuffer::getValue(unsigned index) -{ - std::complex<double> val = m_complexBuffer[index]; - double r {real(val)}; - double i {imag(val)}; - double obs {m_potbuf[index]}; - - QColor c { - static_cast<float>(obs + r*r), // red - static_cast<float>(r*r + i*i + obs/1.5f), // green - static_cast<float>(i*i) // blue - }; - - constexpr double max = 0.81; - if (c.r > max){ - c.r = max; - } - - if (c.g > max){ - c.g = max; - } - - if (c.b > max){ - c.b = max; - } - return c; -} diff --git a/qpong_core/ImageBuffer.hpp b/qpong_core/ImageBuffer.hpp deleted file mode 100644 index d7b58e9..0000000 --- a/qpong_core/ImageBuffer.hpp +++ /dev/null @@ -1,51 +0,0 @@ -/// -/// @file ImageBuffer.hpp -/// @author Armin Co -/// @brief An imagebuffer object stores an image as an array of color (RGB) values. -/// - -#ifndef QPONG_IMAGE_BUFFER_HPP -#define QPONG_IMAGE_BUFFER_HPP - -#include <complex> - -namespace QPong -{ - -/// @brief Convinient conatiner to store a RGB value. -/// {r, g, b} -struct QColor -{ - float r = 0.0f; - float g = 0.0f; - float b = 0.0f; -}; - -/// @brief Class ImageBuffer -/// -class ImageBuffer -{ -public: - /// @brief Constructor for ImageBuffer. - /// - ImageBuffer(); - - /// @brief Update the buffer at the given position. - /// @param index Index of the value that should be changed. - /// @param v The value as a complex number which will be interpreted as a color. - /// @param pot Potential at position. - /// - void updateAt(unsigned index, std::complex<double> v, double pot); - - /// @return Get color value from particle at array index. - /// - const QColor getValue(unsigned index); - -private: - double *m_potbuf; - std::complex<double> *m_complexBuffer; -}; - -} // namespace QPong - -#endif diff --git a/qpong_core/Particle.cpp b/qpong_core/Particle.cpp deleted file mode 100644 index 87203bc..0000000 --- a/qpong_core/Particle.cpp +++ /dev/null @@ -1,297 +0,0 @@ -/// -/// @file Particle.cpp -/// @author Armin Co -/// -/// @brief Particle class implemantation and main(). -/// - -#include <iostream> -#include <thread> -#include <vector> - -#include "Common.hpp" -#include "Particle.hpp" - -using namespace QPong; - -/// @brief Planck constant. -/// -constexpr double hbar = 0.0002; - -const std::complex<double> Ci(0.0, 1.0); - - -/// @brief Takes the row index of an array and turns it -/// into a position. -/// -const double xAt(int x) -{ - return 2.0 * x / QPong::arrayWidth - 1.0; -} - - -/// @brief Takes the line index of an array and turns it -/// into a position. -/// -const double yAt(int y) -{ - return 2.0 * y / QPong::arrayHeight - 1.0; -} - - -void Particle::initMomentum() -{ - double sumAtInit = 0.0; - for (unsigned iy = 0; iy < QPong::arrayHeight; iy++) - { - double y = yAt(iy); - for (unsigned ix = 0; ix < QPong::arrayWidth; ix++) - { - double x = xAt(ix); - unsigned index = QPong::arrayWidth * iy + ix; - constexpr double k_px0 = 0.063; - constexpr double k_py0 = 0.042; - constexpr double k_x0 = 0.0; - constexpr double k_y0 = -0.0; - constexpr double lambda = 60.0; - constexpr double A0 = 0.5; - m_psi[index] = A0 * exp(Ci / hbar * (x * k_px0 + y * k_py0) - lambda * (sqr(x - k_x0) + sqr(y - k_y0))); - sumAtInit += sqr(real(m_psi[index])) + sqr(imag(m_psi[index])); - } - } - for (unsigned iy = 0; iy < QPong::arrayHeight; iy++) - { - double y = yAt(iy); - for (unsigned ix = 0; ix < QPong::arrayWidth; ix++) - { - double x = xAt(ix); - unsigned index = QPong::arrayWidth * iy + ix; - m_psi[index] *= 1.0 / sqrt(sumAtInit); - } - } -} - - -Particle::Particle(ImageBuffer *momentum, ImageBuffer *position, std::map<Player::Id, std::shared_ptr<Player>> players) - : m_bufMomentumRepresentation{momentum} - , m_bufPositionRepresentation{position} - , m_ready{false} - , m_players {players} -{ - fftw_init_threads(); - fftw_plan_with_nthreads(QPong::numberOfThreads); - m_psi = static_cast<std::complex<double> *>(fftw_malloc(sizeof(fftw_complex) * QPong::arraySize)); - m_planForward = fftw_plan_dft_2d(QPong::arrayHeight, QPong::arrayWidth, (fftw_complex *)m_psi, (fftw_complex *)m_psi, FFTW_FORWARD, FFTW_MEASURE); - m_planBackward = fftw_plan_dft_2d(QPong::arrayHeight, QPong::arrayWidth, (fftw_complex *)m_psi, (fftw_complex *)m_psi, FFTW_BACKWARD, FFTW_MEASURE); - initMomentum(); - m_ready = true; -} - - -Particle::~Particle() -{ - fftw_free((fftw_complex *)m_psi); - fftw_destroy_plan(m_planForward); - fftw_destroy_plan(m_planBackward); -} - - -bool Particle::notReady() -{ - return !m_ready; -} - - -double Particle::removeParticle(int index, double cx) -{ - double normPre = sqr(std::real(m_psi[index])) + sqr(std::imag(m_psi[index])); - double e = sqr(cos(cx)); - m_psi[index] *= e; - double dif = normPre - (sqr(std::real(m_psi[index])) + sqr(std::imag(m_psi[index]))); - return dif; -} - - -const double batPotential(double x, double y, Player::Position pos) -{ - y -= pos.y; - double E = 0.0; - constexpr double scale = 0.000015; - constexpr double height = 0.31; - constexpr double cutoff = 0.0015; - if (y >= height) - { - double d = sqr(x-pos.x) + sqr(y-height) + cutoff; - E = 1.0 / d * scale; - } - else if (y <= (-height)) - { - double d = sqr(x-pos.x) + sqr((-y)-height) + cutoff; - E = 1.0 / d * scale; - } - else - { - double d = sqr(pos.x-x) + cutoff; - E = 1.0 / d * scale; - } - return E; -} - - -constexpr double dt = 0.1; -void Particle::manipulateParticleInPosition(int indexFrom, int indexTo) -{ - auto pOneX = m_players[Player::Id::One]->getPosition().x; - auto pTwoX = m_players[Player::Id::Two]->getPosition().x; - float sumScorePlayerOne = 0.0; - float sumScorePlayerTwo = 0.0; - - for (int index = indexFrom; index < indexTo; index++) - { - double x = xAt(index % QPong::arrayWidth); - double y = yAt(index / QPong::arrayWidth); - if (x < pOneX) //< expects p1.x < 0 - { - double cx = -pOneX + x; - cx = cx * (M_PI / 2.0) / (1.0 + pOneX); - double dif = removeParticle(index, cx); - sumScorePlayerTwo += dif; - } - if (x > pTwoX) //< expects p2.x > 0 - { - double cx = x - pTwoX; - cx = cx * (M_PI / 2.0) / (1.0 - pTwoX); - double dif = removeParticle(index, cx); - sumScorePlayerOne += dif; - } - double playerOneBat = batPotential(x, y, m_players[Player::Id::One]->getPosition()); - double playerTwoBat = batPotential(x, y, m_players[Player::Id::Two]->getPosition()); - double horizontalBorders = sqr(y) * sqr(y) * sqr(y) * sqr(y) * 0.01; - auto potentialSum = playerOneBat + playerTwoBat + horizontalBorders; - auto tmpPsi = m_psi[index] * exp(-Ci * dt / hbar * potentialSum); - m_psi[index] = tmpPsi; - m_bufPositionRepresentation->updateAt(index, tmpPsi * 125.0, potentialSum * 150); - } - m_players[Player::Id::One]->addScore(sumScorePlayerOne); - m_players[Player::Id::Two]->addScore(sumScorePlayerTwo); -} - - -double flattenMomentum(double x, double y) -{ - double distanceToCenter = sqr(x) + sqr(y); - constexpr double offset = 0.012; - if (distanceToCenter > offset) - { - return 1.0 / (1.0 + (distanceToCenter * 2.5)); - } - else - { - return 1.0; - } -} - - -const double pxAt(int ix) -{ - if (ix > QPong::arrayWidth / 2) - { - ix -= QPong::arrayWidth; - } - return ix * M_PI * hbar; -} - - -const double pyAt(int iy) -{ - if (iy > QPong::arrayHeight / 2) - { - iy -= QPong::arrayHeight; - } - return iy * M_PI * hbar; -} - - -void Particle::moveStep(int indexFrom, int indexTo) -{ - for (int i = indexFrom; i < indexTo; i++) - { - double py = pyAt(i / QPong::arrayWidth); - double px = pxAt(i % QPong::arrayWidth); - constexpr double m = 1.0; - constexpr double N = 1.0 / QPong::arraySize; - double E = (sqr(px) + sqr(py)) / (2.0 * m); - auto f = flattenMomentum(px, py); - m_psi[i] *= exp(-Ci * dt / hbar * E) * N * f; - // m_psi[i] = flattenMomentum(px, py) * 0.00001; - } -} - - -void Particle::propagate() -{ - for (auto &player : m_players) - { - player.second->update(dt); - } - - std::vector<std::thread> positionThreads; - for (int i = 0; i < QPong::numberOfThreads; i++) - { - int from = i * (QPong::arraySize/QPong::numberOfThreads); - int to = (i+1) * (QPong::arraySize/QPong::numberOfThreads); - positionThreads.emplace_back(&Particle::manipulateParticleInPosition, this, i * (QPong::arraySize/QPong::numberOfThreads), (i+1) * (QPong::arraySize/QPong::numberOfThreads)); - } - for (auto &thread : positionThreads) - { - thread.join(); - } - fftw_execute (m_planForward); // transform into momentum repr. - - std::vector<std::thread> momentumThreads; - for (int i = 0; i < QPong::numberOfThreads; i++) - { - momentumThreads.emplace_back(&Particle::moveStep, this, i * (QPong::arraySize / QPong::numberOfThreads), (i + 1) * (QPong::arraySize / QPong::numberOfThreads)); - } - for (auto &thread : momentumThreads) - { - thread.join(); - } - /// @todo Pull update Momentum image into moveStep() - updateMomentumImage(); //momentum - fftw_execute(m_planBackward); // transform into position repr. -} - - -void Particle::updateMomentumImage() -{ - for (int index = 0; index < QPong::arraySize; index++) - { - auto y = index / QPong::arrayWidth; - unsigned py = 0; - if (y >= QPong::arrayHeight / 2) - { - py = y - QPong::arrayHeight / 2; - } - else - { - py = y + QPong::arrayHeight / 2; - } - - auto x = index % QPong::arrayWidth; - unsigned px = 0; - if (x >= QPong::arrayWidth / 2) - { - px = x - QPong::arrayWidth / 2; - } - else - { - px = x + QPong::arrayWidth / 2; - } - - constexpr double scale = 55580.0;; - auto array_index = y * QPong::arrayWidth + x; - auto momentum_index = py * QPong::arrayWidth + px; - m_bufMomentumRepresentation->updateAt(array_index, (m_psi[momentum_index] * scale), 0.0); - } -} diff --git a/qpong_core/Particle.hpp b/qpong_core/Particle.hpp deleted file mode 100644 index 0477612..0000000 --- a/qpong_core/Particle.hpp +++ /dev/null @@ -1,93 +0,0 @@ -/// -/// @file Particle.hpp -/// @author Armin Co -/// @brief Particle class header. -/// - -#ifndef QPONG_PARTICLE_HPP -#define QPONG_PARTICLE_HPP - -#include <complex> -#include <memory> -#include <map> - -#include <math.h> -#include <fftw3.h> - -#include "ImageBuffer.hpp" -#include "Player.hpp" - -namespace QPong { - -class Particle -{ -public: - - /// @brief Contructor - /// - Particle(ImageBuffer *momentum, ImageBuffer *position, std::map<Player::Id, std::shared_ptr<Player>> players); - - - /// @brief Destructor - /// - ~Particle(); - - - /// @brief Execute one step of the simulation. - /// - void propagate(); - - - /// @brief Init the array with initial momentum. - /// Representation is in position representation. - /// - void initMomentum(); - - - /// @brief Check if everything is initialised. - /// - bool notReady(); - - -private: - /// @brief Update the array at the ArrayCanvas - /// - void updateMomentumImage(); - - - /// @brief Manipulate particle in position representation - /// For bats and borders potentials are used. - /// Removing the particle behind the bat with a cos2 - /// - void manipulateParticleInPosition(int from, int to); - - - /// @brief Move the particle one step forward in momentum representation - /// - void moveStep(int indexFrom, int indexTo); - - - /// @brief Remove parts of the particle that are behind the bat. - /// - double removeParticle(int index, double cx); - - - std::complex<double> *m_psi; - fftw_plan m_planForward; - fftw_plan m_planBackward; - bool m_ready; - - std::map<Player::Id, std::shared_ptr<Player>> m_players; - - ImageBuffer *m_bufPositionRepresentation; - ImageBuffer *m_bufMomentumRepresentation; - - - - - Particle() = delete; -}; - -} // namespace QPong - -#endif \ No newline at end of file diff --git a/qpong_core/Player.cpp b/qpong_core/Player.cpp deleted file mode 100644 index 31db213..0000000 --- a/qpong_core/Player.cpp +++ /dev/null @@ -1,101 +0,0 @@ -/// -/// @file QPlayer.cpp -/// @author Armin Co -/// - - -#include <mutex> -#include "Player.hpp" - -using namespace QPong; - -constexpr double speedStepSize = 0.0005; - - -Player::Player(Player::Id pl, Player::Position pos) - : m_id {pl} - , m_x {pos.x} - , m_y {pos.y} -{ -} - - -void Player::update(double dt) -{ - constexpr double negativeAccelScale = 1.5; - m_y += (m_vy * dt * 4); - - if (m_vy > 0.0) - { - m_vy -= speedStepSize * negativeAccelScale; - } - if (m_vy < 0.0) - { - m_vy += speedStepSize * negativeAccelScale; - } - if (m_vy < speedStepSize*negativeAccelScale && m_vy > -speedStepSize * negativeAccelScale) - { - m_vy = 0.0; - } - - constexpr double maxY = 1.3; - if (m_y > maxY) - { - m_y = maxY; - } - if (m_y < -maxY) - { - m_y = -maxY; - } -} - - -void Player::move(Direction direction) -{ - constexpr double addSpped = 3; - switch (direction) - { - case Direction::Up: - m_vy -= speedStepSize * addSpped; - break; - case Direction::Down: - m_vy += speedStepSize * addSpped; - break; - } - - constexpr double maxSpeedScale = 45; - if (m_vy > speedStepSize * maxSpeedScale) - { - m_vy = speedStepSize * maxSpeedScale; - } - if (m_vy < -speedStepSize * maxSpeedScale) - { - m_vy = -speedStepSize * maxSpeedScale; - } -} - - -float Player::getScore() -{ - return m_score * 100; -} - - -std::mutex scoreMtx; -void Player::addScore(float score) -{ - std::lock_guard<std::mutex> lockScore(scoreMtx); - m_score += score; -} - - -Player::Position Player::getPosition() -{ - return {m_x, m_y}; -} - - -void Player::reset() -{ - m_score = 0; -} \ No newline at end of file diff --git a/qpong_core/Player.hpp b/qpong_core/Player.hpp deleted file mode 100644 index 7154bc9..0000000 --- a/qpong_core/Player.hpp +++ /dev/null @@ -1,58 +0,0 @@ -/// -/// @file Qlayer.hpp -/// @author Armin Co -/// -/// @brief Player class. -/// - -#ifndef QPONG_QPLAYER_HPP -#define QPONG_QPLAYER_HPP - -namespace QPong { - -/// @brief Class wraps all values of one Player. -/// -class Player -{ -public: - enum class Id - { - One, - Two - }; - - - struct Position - { - double x; - double y; - }; - - - enum class Direction - { - Up, - Down - }; - - - Player(Id pl, Position pos); - void update(double dt); - void move(Direction d); - void addScore(float score); - void reset(); - float getScore(); - Position getPosition(); - -private: - Id m_id; - double m_x; - double m_y; - double m_vx = 0; - double m_vy = 0; - double m_score = 0; -}; - -} // namespace QPong - -#endif \ No newline at end of file diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt deleted file mode 100644 index 0f98b33..0000000 --- a/tests/CMakeLists.txt +++ /dev/null @@ -1,23 +0,0 @@ - -enable_testing() - -include_directories( - ${gtest_SOURCE_DIR}/include - ${gtest_SOURCE_DIR} -) - -add_executable( - runUnitTests - test_qpong.cpp -) - -target_link_libraries( - runUnitTests - gtest - gtest_main -) - -target_link_libraries( - runUnitTests - qpong_core -) diff --git a/tests/test_qpong.cpp b/tests/test_qpong.cpp deleted file mode 100644 index 203e84f..0000000 --- a/tests/test_qpong.cpp +++ /dev/null @@ -1,65 +0,0 @@ -#include <iostream> -#include "gtest/gtest.h" - -#include "ImageBuffer.hpp" - - -/// @brief Creating a test fixture frequently used objects for tests -/// -class QPongLib : public testing::Test -{ - protected: - ImageBuffer *momentumImage; - ImageBuffer *positionImage; - // members - - // called before any test - void SetUp() override - { - - } - - virtual void TearDown() - { - - } - -}; - -/// @brief A simple function to test -/// -int addInts(int a, int b) -{ - return a + b; -} - - -TEST(ImageBuffer, getValue) -{ - const ImageBuffer imbf; - const ImageBuffer imbff; - const ImageBuffer imbfff; - -} - - -TEST(addInts, positiveValues) -{ - int a {1}; - int b {3}; - - ASSERT_EQ(addInts(a, b), 4); -} - -TEST(addInts, shouldBreak) -{ - EXPECT_NE(3+1, 0) << "Yes yes, because it is just a test!"; -} - -TEST(addInts, negativeValues) -{ - ASSERT_EQ(-3 + -5, -8); -} - -/// @todo Example for mocks and an explanation what they are. -/// \ No newline at end of file -- GitLab