Skip to content
/ pong Public

馃彄 Classic Pong game recreation with online playing mode.

License

Notifications You must be signed in to change notification settings

joecarl/pong

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Repository files navigation

PONG

Recreaci贸n del cl谩sico juego PONG desarrollado en C++, adem谩s incluye opci贸n de juego online. El objetivo de este proyecto es aprender los pricipios b谩sicos de la programaci贸n de videojuegos, as铆 como del desarrollo de aplicaciones online cliente/servidor.

El proyecto intenta mantener la mayor simpleza posible pero con una infraestructura principal que pueda servir como base para proyectos m谩s grandes.

Este proyecto tiene dos dependencias principales:

  • Allego v5.2.6+ (s贸lo para el cliente)
  • Boost v1.75+ (utilizado principalmente para la comunicaci贸n entre sockets TCP/IP)

Preparar entorno de desarrollo

Actualmente la forma m谩s sencilla es abrir el proyecto en un devcontainer de VSCode, pues esto configurar谩 todo automaticamente para poder trabajar, compilar y depurar. Si se est谩 trabajando bajo windows es necesario instalar WSL + Docker

Compilar en Windows

  1. Instalar GIT for windows (solamente si se pretende participar en el desarrollo).
  2. Instalar MSYS2 de 64 bits descargado de https://www.msys2.org/.
  3. Desde MSYS2-MSYS actualizar los paquetes con pacman -Syuu hasta que no se pueda m谩s (mirar el tutorial de instalaci贸n por si acaso).
  4. Desde MSYS2-MSYS navegar al directorio del proyecto y ejecutar bash scripts/installdeps.sh.
  5. Ejecutar bash scripts/win-build.sh (esto se puede hacer desde Git Bash).
  6. Para lanzar la aplicaci贸n utilizar bash scripts/win-run.sh (tambi茅n se puede hacer desde Git Bash).

Si tratamos de ejecutar la aplicaci贸n compilada haciendo doble click en ella nos dar谩 error por falta de DLLs. Este 煤ltimo comando incluye en el PATH la carpeta bin de mingw64, lo que soluciona este problema. Por ahora, para distribuir la aplicaci贸n ser铆a necesario copiar una gran cantidad de DLLs de dicha carpeta.

Compilar el servidor en Linux

Prerequisitos

  1. Instalar el compilador de C++17 o superior.
  2. Instalar las libs de Boost v1.75 o superior.

Compilaci贸n

  1. Ir a la carpeta del repositorio.

    Si aun no tenemos el repositorio en nuestro sistema:

    git clone https://github.com/joecarl/pong.git
    cd pong

    Si ya tenemos el repositorio en nuestro sistema simplemente, navegamos a 茅l y lo actualizamos con:

    git pull
  2. Finalmente ejecutar:

    bash scripts/build-server.sh

Ejecutar el servidor en Linux

  1. El servidor se compila en la carpeta ./build/server, podemos navegar a esa carpeta y ejecutar:

    ./pongserver -p <DESIRED_PORT>

Indicaciones para Ubuntu

  • Para instalar el compilador de C++ se puede hacer con:

     apt install build-essential
    
  • En caso de que las dependencias NO se hayan instalado en el directorio por defecto ser谩 necesario especificar d贸nde se han instalado antes de compilar:

     export LIBRARY_PATH=/path/to/dep1/lib:/path/to/dep2/lib
     export CPATH=/path/to/dep1/include:/path/to/dep2/include
    

Indicaciones para CentOS 7

  • Para instalar el compilador de C++ se puede hacer con:

    yum install devtoolset-7-gcc-c++ --enablerepo='centos-sclo-rh'
  • Siempre que abramos una nueva sesi贸n de consola ser谩 necesario ejecutar:

    Para habilitar g++:

    scl enable devtoolset-7 'bash'

    Para poder ejecutar la aplicaci贸n:

    export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/lib

    Cambiando /usr/local/lib por el directorio donde se haya instalado boost si es necesario.


Indicaciones para portar el cliente a Android

  1. Compilar Allegro (seguir las indicaciones de este repositorio: https://github.com/liballeg/android)

  2. Compilar Boost (seguir las indicaciones del apartado Compiling de este repositorio: https://github.com/moritz-wundke/Boost-for-Android). Es posible que haya que ejecutar el script de compilaci贸n en Linux.

  3. A帽adir los siguientes atributos a AndroidManifest.xml:

    <manifest ...>
        <uses-permission android:name="android.permission.INTERNET" />
        <application 
            android:isGame="true"
            android:appCategory="game"
            ...>
            <activity
                android:configChanges="orientation|keyboardHidden|screenLayout|uiMode|screenSize"
                ...>
                ...
            </activity>
        </application>
    </manifest>

    El primero es necesario para poder hacer uso de internet, los dos siguientes sirven para indicar que el tipo de aplicaci贸n es un juego y el 煤ltimo es para que la aplicaci贸n no se reinicie al cambiar la orientaci贸n del dispositivo.

  4. Editar el archivo CMakeLists.txt para establecer el siguiente contenido:

    # Sets the minimum version of CMake required to build the native library.
    
    cmake_minimum_required(VERSION 3.10.2)
    
    # Declares and names the project.
    
    project("pong")
    
    # Creates and names a library, sets it as either STATIC
    # or SHARED, and provides the relative paths to its source code.
    # You can define multiple libraries, and CMake builds them for you.
    # Gradle automatically packages shared libraries with your APK.
    
    add_library( # Sets the name of the library.
            pong
    
            # Sets the library as a shared library.
            SHARED
    
            # Provides a relative path to your source file(s).
            client/main.cpp
            client/hengine.cpp
            ...)
    
    # Searches for a specified prebuilt library and stores the path as a
    # variable. Because CMake includes system libraries in the search path by
    # default, you only need to specify the name of the public NDK library
    # you want to add. CMake verifies that the library exists before
    # completing its build.
    
    find_library( # Sets the name of the path variable.
            log-lib
    
            # Specifies the name of the NDK library that
            # you want CMake to locate.
            log)
    
    # Specifies libraries CMake should link to your target library. You
    # can link multiple libraries, such as libraries you define in this
    # build script, prebuilt third-party libraries, or system libraries.
    
    target_link_libraries( # Specifies the target library.
            pong
    
            # Links the target library to the log library
            # included in the NDK.
            ${log-lib})
    
    set(NATIVE_LIB pong)
    
    set(JNI_FOLDER ${PROJECT_SOURCE_DIR}/../jni/allegro) # or wherever you put it
    include(${JNI_FOLDER}/allegro.cmake)
    
    
    set(BOOST_JNI_FOLDER ${PROJECT_SOURCE_DIR}/../jni/boost) # or wherever you put it
    
    include_directories(${BOOST_JNI_FOLDER}/${ABI}/include/boost-1_76)
    
    macro(boost_library NAME)
        string(TOUPPER ${NAME} UNAME)
        set(path ${BOOST_JNI_FOLDER}/${ABI}/lib/lib${NAME})
    
        if(EXISTS "${path}-clang-mt-x32-1_76.a")
            set(LIB_${UNAME} ${path}-clang-mt-x32-1_76.a)
        elseif(EXISTS "${path}-clang-mt-x64-1_76.a")
            set(LIB_${UNAME} ${path}-clang-mt-x64-1_76.a)
        elseif(EXISTS "${path}-clang-mt-a64-1_76.a")
            set(LIB_${UNAME} ${path}-clang-mt-a64-1_76.a)
        elseif(EXISTS "${path}-clang-mt-a32-1_76.a")
            set(LIB_${UNAME} ${path}-clang-mt-a32-1_76.a)
        else()
            message(SEND_ERROR "${path}*.a does not exist")
        endif()
        target_link_libraries(${NATIVE_LIB} ${LIB_${UNAME}})
    endmacro()
    
    boost_library(boost_chrono)
    boost_library(boost_system)
    boost_library(boost_thread)
    boost_library(boost_json)

    Cambiando las rutas que sean necesarias y a帽adiendo los archivos .cpp necesarios a la lista de add_library.

About

馃彄 Classic Pong game recreation with online playing mode.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published