Skip to content

Commit

Permalink
Merge pull request #13 from jonylu7/new
Browse files Browse the repository at this point in the history
Update PTSD engine
  • Loading branch information
jonylu7 authored Mar 8, 2024
2 parents cd80b1a + 75004e8 commit 5fbea84
Show file tree
Hide file tree
Showing 32 changed files with 369 additions and 223 deletions.
22 changes: 9 additions & 13 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ jobs:
- os: windows-latest
build_type: Release
binary: windows-binary
- os: macos-latest
build_type: Release

steps:
- if: matrix.os == 'ubuntu-latest'
Expand All @@ -29,16 +31,10 @@ jobs:
sudo apt-get -y install ${{ matrix.compiler.cc }} cmake ninja-build libglu1-mesa-dev mesa-common-dev xorg-dev
- name: Checkout Repository
uses: actions/checkout@v3
uses: actions/checkout@v4
with:
submodules: recursive

- name: Check Format
if: matrix.os == 'ubuntu-latest' && matrix.compiler == 'clang'
run: |
find src/ include/ test/ assets/shaders/ -name "*.*" -print0 | \
xargs -0 clang-format --dry-run --Werror --ferror-limit=15
- name: Building Project
if: matrix.os == 'ubuntu-latest'
env:
Expand All @@ -48,14 +44,14 @@ jobs:
cmake -B build -G "Ninja" -DCMAKE_BUILD_TYPE=${{ matrix.build_type }}
cmake --build build
- name: Run Linter
if: matrix.os == 'ubuntu-latest' && matrix.compiler == 'clang'
run: |
find src/ include/ test/ -name "*.*" -print0 | \
xargs -0 run-clang-tidy true -p build
- name: Building Project
if: matrix.os == 'windows-latest'
run: |
cmake -B build -DCMAKE_BUILD_TYPE=${{ matrix.build_type }}
cmake --build build --config ${{ matrix.build_type }}
- name: Building Project
if: matrix.os == 'macos-latest'
run: |
cmake -B build -DCMAKE_BUILD_TYPE=${{ matrix.build_type }}
cmake --build build
36 changes: 36 additions & 0 deletions .github/workflows/check.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
name: check

on:
workflow_dispatch:
pull_request:
branches:
- main

jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Checkout Repository
uses: actions/checkout@v4
with:
submodules: recursive

- name: Check Format
uses: jidicula/[email protected]
with:
clang-format-version: '17'
check-path: src include test assets/shaders
include-regex: ^.*\.((((c|C)(c|pp|xx|\+\+)?$)|((h|H)h?(pp|xx|\+\+)?$))|(vert|frag))$

- name: Run Linter
uses: ZedThree/[email protected]
with:
apt_packages: ninja-build,libglu1-mesa-dev,mesa-common-dev,xorg-dev
cmake_command: cmake -B build -G Ninja -DCMAKE_EXPORT_COMPILE_COMMANDS=on
build_dir: build
exclude: lib
split_workflow: true
config_file: .clang-tidy

- name: Upload Result
uses: ZedThree/clang-tidy-review/[email protected]
16 changes: 16 additions & 0 deletions .github/workflows/post.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
name: post

on:
workflow_run:
workflows: ["check"]
types:
- completed

jobs:
build:
runs-on: ubuntu-latest

steps:
- uses: ZedThree/clang-tidy-review/[email protected]
with:
annotations: false
14 changes: 11 additions & 3 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,11 @@ else ()
)
endif ()

if (WIN32 AND CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
# see https://github.com/ntut-open-source-club/practical-tools-for-simple-design/issues/22
set(CMAKE_RC_FLAGS="-C 1252")
endif ()

option(PTSD_ENABLE_PCH "Turn on PCH to increase compilation speed" OFF)

include(cmake/Dependencies.cmake)
Expand Down Expand Up @@ -44,9 +49,10 @@ set(SRC_FILES
${SRC_DIR}/Util/Text.cpp
${SRC_DIR}/Util/TransformUtils.cpp
${SRC_DIR}/Util/GameObject.cpp
${SRC_DIR}/Util/Root.cpp
${SRC_DIR}/Util/Renderer.cpp
${SRC_DIR}/Util/Color.cpp
${SRC_DIR}/Util/Animation.cpp
${SRC_DIR}/Util/MissingTexture.cpp

${SRC_DIR}/Util/ImageArray.cpp
${SRC_DIR}/Util/CustomizableImage.cpp
Expand All @@ -61,7 +67,6 @@ set(SRC_FILES
${SRC_DIR}/imgui/imgui_impl_opengl3.cpp

${SRC_DIR}/App.cpp
${SRC_DIR}/Rectangle.cpp
${SRC_DIR}/Grid.cpp

${SRC_DIR}/Structure/Structure.cpp
Expand Down Expand Up @@ -113,12 +118,15 @@ set(INCLUDE_FILES
${INCLUDE_DIR}/Util/Transform.hpp
${INCLUDE_DIR}/Util/TransformUtils.hpp
${INCLUDE_DIR}/Util/GameObject.hpp
${INCLUDE_DIR}/Util/Root.hpp
${INCLUDE_DIR}/Util/Renderer.hpp
${INCLUDE_DIR}/Util/Color.hpp
${INCLUDE_DIR}/Util/Animation.hpp
${INCLUDE_DIR}/Util/MissingTexture.hpp

${INCLUDE_DIR}/Util/ImageArray.hpp
${INCLUDE_DIR}/Util/CustomizableImage.hpp


${INCLUDE_DIR}/UI.hpp
${INCLUDE_DIR}/App.hpp
${INCLUDE_DIR}/Tile.hpp
Expand Down
3 changes: 2 additions & 1 deletion assets/shaders/Base.vert
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ layout(std140) uniform Matrices {
};

void main() {
// Reference from https://github.com/NOOBDY/Indigo/blob/f31c7ef82c610d8e91214892a7a1e3f860ba4aaa/assets/shaders/base_pass.vert#L21-L22
// Reference from
// https://github.com/NOOBDY/Indigo/blob/f31c7ef82c610d8e91214892a7a1e3f860ba4aaa/assets/shaders/base_pass.vert#L21-L22
gl_Position = viewProjection * model * vec4(vertPosition, 0, 1);

uv = vertUv;
Expand Down
Binary file added assets/sprites/ICON_Allied Infantry.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/sprites/ICON_Allied Vehicles.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/sprites/ICON_Soviet Infantry.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/sprites/ICON_Soviet Vehicles.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
9 changes: 1 addition & 8 deletions include/App.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,7 @@
#include "Scene/DefaultScene.hpp"
#include "pch.hpp" // IWYU pragma: export


#include "Util/Root.hpp"


#include "Util/Renderer.hpp"

class App {
public:
Expand All @@ -24,11 +21,7 @@ class App {
private:
State m_CurrentState = State::START;


Util::Root m_Root;

DefaultScene testScene;

};

#endif
24 changes: 24 additions & 0 deletions include/Core/MissingTextureBase64.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#ifndef CORE_MISSING_TEXTURE_BASE64_HPP
#define CORE_MISSING_TEXTURE_BASE64_HPP

// A transparent image base64 string.
// Since we want to hardcode the image, we have such a long string here.
// The original image should find in here: https://i.imgur.com/zS4sPCN.png
static constexpr const char *MISSING_TEXTURE =
"iVBORw0KGgoAAAANSUhEUgAAAQAAAAEABAMAAACuXLVVAAAAIGNIUk0AAHomAACAhAAA+"
"gAAAIDoAAB1MAAA6mAAADqYAAAXcJy6UTwAAAAhUExURf8A3P8A3uEAwh4AGgAAAP8A3+"
"IAwx0AGcoArjUALv///"
"xhkxvUAAAABYktHRApo0PRWAAAAB3RJTUUH5wwZEiAsl4pL0QAAAQlJREFUeNrt2rENAjEMBVC"
"vcGzArRA2IBIbsAESA9CwACuwLrVDnfiK5/"
"YX9xRdY+tH5DldeprreW7eAwAAAAAAAAAAAAAAAACgHLDlub9yfnvMzXvseZ7flub9mZu3aGs/"
"OOZ79LVPPubbCJj90415AAAAAAAAAAAAAAAAABwOsH45LV/"
"Pyw8U5SeaWPvTHfBKBgAAAAAAAAAAAAAAAFC+nJav5+"
"UHir72yfUHAAAAAAAAAAAAAAAAAPQH9Af0BwAAAAAAAAAAAAAAAAD0B/"
"QH9AcAAAAAAAAAAAAAAAAA9Af0B/"
"QHAAAAAAAAAAAAAAAAAPQH9Af0BwAAAAAAAAAAAAAAAAAA/gA/"
"YLVKK0nwuR8AAAAldEVYdGRhdGU6Y3JlYXRlADIwMjMtMTItMjVUMTg6MzI6MzcrMDA6MDCbYQ"
"aeAAAAJXRFWHRkYXRlOm1vZGlmeQAyMDIzLTEyLTI1VDE4OjMyOjM3KzAwOjAw6jy+"
"IgAAACh0RVh0ZGF0ZTp0aW1lc3RhbXAAMjAyMy0xMi0yNVQxODozMjo0NCswMDowMIYEjHkAAA"
"AASUVORK5CYII=";

#endif // CORE_MISSING_TEXTURE_BASE64_HPP
6 changes: 2 additions & 4 deletions include/Scene/DefaultScene.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,13 @@
#include "Core/Context.hpp"
#include "Grid.hpp"
#include "Map.hpp"
#include "Rectangle.hpp"
#include "SpriteSheet.hpp"
#include "UI.hpp"
#include "Util/Image.hpp"
#include "Util/Input.hpp"
#include "Util/Keycode.hpp"
#include "Util/Logger.hpp"
#include "Util/Root.hpp"
#include "Util/Renderer.hpp"

#include "Structure/AdvencePowerPlants.hpp"
#include "Structure/Barracks.hpp"
Expand All @@ -42,7 +41,6 @@ class DefaultScene {
std::make_shared<Capybara>(), std::make_shared<Capybara>(),
std::make_shared<Barracks>()};
*/
Rectangle rect;
/*
std::shared_ptr<Infantry> m_Inf = std::make_shared<Infantry>();
*/
Expand All @@ -51,7 +49,7 @@ class DefaultScene {
CameraClass m_SceneCamera;
Grid testGrid;

Util::Root m_Renderer;
Util::Renderer m_Renderer;
UIClass m_UI;
MapClass m_Map;
std::map<int, TileClass> m_tileSets;
Expand Down
9 changes: 4 additions & 5 deletions include/UI.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@
#define PRACTICALTOOLSFORSIMPLEDESIGN_UI_HPP
#include "Camera.hpp"
#include "SpriteSheet.hpp"
#include "UIScriptProcess.h"
#include "imgui/imgui.h"
#include "imgui/imgui_impl_opengl3.h"
#include "imgui/imgui_impl_sdl2.h"
#include "pch.hpp"
#include "UIScriptProcess.h"

// not sure how does it work commented by Lu
enum class ButtonClicked {
Expand Down Expand Up @@ -43,22 +43,21 @@ class UIClass {
ImGuiMouseButton mouse_button);
void ShowPlayerConstructionMenu();


std::vector<ImVec2> getSpriteSheetCoordByIndex(int index);
bool getImageButtonBySpriteSheetIndex(int index);

private:
SpriteSheet m_SpriteSheet;

Grid m_Grid;
glm::vec2 m_GridSize={100,100};
glm::vec2 m_GridSize = {100, 100};
UIScriptProcess ButtonScript;
std::shared_ptr<Structure> barracks = std::make_shared<Barracks>();
std::shared_ptr<Structure> oreRefinery = std::make_shared<OreRefinery>();
std::shared_ptr<Structure> powerPlant = std::make_shared<PowerPlants>();
std::shared_ptr<Structure> warFactory = std::make_shared<WarFactory>();
std::shared_ptr<Structure> advPowerPlant = std::make_shared<ADVPowerPlants>();

std::shared_ptr<Structure> advPowerPlant =
std::make_shared<ADVPowerPlants>();
};

#endif // PRACTICALTOOLSFORSIMPLEDESIGN_UI_HPP
43 changes: 14 additions & 29 deletions include/Util/Animation.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,10 @@ class Animation : public Core::Drawable {
* @brief Enum representing the state of the animation.
*/
enum class State {
PLAY, /**< Animation is playing. */
PAUSE, /**< Animation is paused. */
/**
* Animation is in cooldown
* @todo This state is not implemented yet
*/
COOLDOWN,
ENDED, /**< Animation has ended. */
PLAY, /**< Animation is playing. */
PAUSE, /**< Animation is paused. */
COOLDOWN, /**< Animation is COOLDOWN. */
ENDED /**< Animation is Ended(looping == false && Animate end.). */
};

/**
Expand Down Expand Up @@ -77,12 +73,7 @@ class Animation : public Core::Drawable {
* @brief Get the current state of the animation
* @return The current state of the animation
*/
State GetState() const {
if (m_HasEnded) {
return State::ENDED;
}
return m_State;
}
State GetState() const { return m_State; }

/**
* @brief Get the size of the current frame.
Expand Down Expand Up @@ -132,19 +123,13 @@ class Animation : public Core::Drawable {
* If the animation has ended and `looping` is set to `false`, this would
* replay the animation once.
*/
void Play() {
m_State = State::PLAY;
if (m_HasEnded) {
m_Index = 0;
m_HasEnded = false;
}
}
void Play();

/**
* @brief Pause the animation.
* If the animation has already been paused, this method won't do anything.
*/
void Pause() { m_State = State::PAUSE; }
void Pause();

private:
/**
Expand All @@ -153,17 +138,17 @@ class Animation : public Core::Drawable {
void Update();

private:
std::vector<std::shared_ptr<Util::Image>> m_Frames;
State m_State;

unsigned long m_BaseTime;

std::size_t m_Interval;
double m_Interval;
bool m_Looping;
std::size_t m_Cooldown;
bool m_HasEnded = false;
bool m_IsChangeFrame = false;

std::vector<std::shared_ptr<Util::Image>> m_Frames;
std::size_t m_Index;
unsigned long m_CooldownEndTime = 0;
double m_TimeBetweenFrameUpdate = 0;

std::size_t m_Index = 0;
};
} // namespace Util

Expand Down
Loading

0 comments on commit 5fbea84

Please sign in to comment.