mirror of
https://github.com/zoriya/Bomberman.git
synced 2025-12-20 13:25:10 +00:00
Merge branch 'develop' into height_map_generator
This commit is contained in:
20
.github/workflows/build_web.yml
vendored
Normal file
20
.github/workflows/build_web.yml
vendored
Normal file
@@ -0,0 +1,20 @@
|
|||||||
|
name: Web Build (Emscripten)
|
||||||
|
on: [push, pull_request]
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
Build:
|
||||||
|
if: github.event_name == 'push' || github.event.pull_request.head.repo.full_name != github.repository
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v1
|
||||||
|
with:
|
||||||
|
submodules: true
|
||||||
|
- name: Exec
|
||||||
|
shell: bash
|
||||||
|
run: ./build_web.sh
|
||||||
|
- name: Check files creation
|
||||||
|
run: |
|
||||||
|
test -f build_web/bomberman.html
|
||||||
|
test -f build_web/bomberman.js
|
||||||
|
test -f build_web/bomberman.wasm
|
||||||
|
test -f build_web/bomberman.data
|
||||||
3
.gitignore
vendored
3
.gitignore
vendored
@@ -4,3 +4,6 @@ cmake-build-debug
|
|||||||
.vscode
|
.vscode
|
||||||
build/*
|
build/*
|
||||||
docs/*
|
docs/*
|
||||||
|
emsdk/
|
||||||
|
build_web/*
|
||||||
|
wasm-python.py
|
||||||
@@ -10,6 +10,13 @@ include_directories(bomberman sources)
|
|||||||
add_subdirectory(${PROJECT_SOURCE_DIR}/lib/wal)
|
add_subdirectory(${PROJECT_SOURCE_DIR}/lib/wal)
|
||||||
add_subdirectory(${PROJECT_SOURCE_DIR}/lib/Ray)
|
add_subdirectory(${PROJECT_SOURCE_DIR}/lib/Ray)
|
||||||
|
|
||||||
|
if (EMSCRIPTEN)
|
||||||
|
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -s USE_GLFW=3 -s ASSERTIONS=1 -s WASM=1 -s ASYNCIFY")
|
||||||
|
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -s USE_GLFW=3 -s ASSERTIONS=1 -s WASM=1 -s ASYNCIFY")
|
||||||
|
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -s NO_DISABLE_EXCEPTION_CATCHING --shell-file ../sources/wasm/frontend.html --preload-file ../assets")
|
||||||
|
set(CMAKE_EXECUTABLE_SUFFIX ".html")
|
||||||
|
endif ()
|
||||||
|
|
||||||
set(SOURCES
|
set(SOURCES
|
||||||
sources/Models/GameState.hpp
|
sources/Models/GameState.hpp
|
||||||
sources/Runner/Runner.cpp
|
sources/Runner/Runner.cpp
|
||||||
@@ -46,25 +53,25 @@ set(SOURCES
|
|||||||
sources/System/GridCentered/GridCenteredSystem.cpp
|
sources/System/GridCentered/GridCenteredSystem.cpp
|
||||||
sources/System/GridCentered/GridCenteredSystem.hpp
|
sources/System/GridCentered/GridCenteredSystem.hpp
|
||||||
sources/Models/Vector2.hpp
|
sources/Models/Vector2.hpp
|
||||||
sources/Component/Renderer/Drawable3DComponent.hpp
|
|
||||||
sources/Component/Renderer/Drawable2DComponent.hpp
|
sources/Component/Renderer/Drawable2DComponent.hpp
|
||||||
sources/System/Renderer/Renderer3DSystem.hpp
|
sources/Component/Renderer/Drawable3DComponent.hpp
|
||||||
sources/System/Renderer/Renderer2DSystem.hpp
|
sources/System/Renderer/RenderSystem.hpp
|
||||||
sources/System/Renderer/RenderScreenSystem.hpp
|
sources/System/Renderer/RenderSystem.cpp
|
||||||
sources/System/Renderer/RenderScreenSystem.cpp
|
|
||||||
sources/Component/Renderer/CameraComponent.cpp
|
sources/Component/Renderer/CameraComponent.cpp
|
||||||
sources/Component/Renderer/CameraComponent.hpp
|
sources/Component/Renderer/CameraComponent.hpp
|
||||||
sources/System/Renderer/Render2DScreenSystem.cpp
|
sources/Component/Animation/AnimationsComponent.cpp
|
||||||
sources/System/Renderer/Render2DScreenSystem.hpp
|
sources/Component/Animation/AnimationsComponent.hpp
|
||||||
|
sources/System/Animation/AnimationsSystem.cpp
|
||||||
|
sources/System/Animation/AnimationsSystem.hpp
|
||||||
sources/Component/Collision/CollisionComponent.cpp
|
sources/Component/Collision/CollisionComponent.cpp
|
||||||
sources/Component/Collision/CollisionComponent.hpp
|
sources/Component/Collision/CollisionComponent.hpp
|
||||||
sources/System/Collision/CollisionSystem.hpp
|
sources/System/Collision/CollisionSystem.hpp
|
||||||
sources/System/Collision/CollisionSystem.cpp
|
sources/System/Collision/CollisionSystem.cpp
|
||||||
)
|
)
|
||||||
|
|
||||||
add_executable(bomberman
|
add_executable(bomberman
|
||||||
sources/main.cpp
|
sources/main.cpp
|
||||||
${SOURCES})
|
${SOURCES}
|
||||||
|
)
|
||||||
target_include_directories(bomberman PUBLIC sources)
|
target_include_directories(bomberman PUBLIC sources)
|
||||||
target_link_libraries(bomberman PUBLIC wal ray)
|
target_link_libraries(bomberman PUBLIC wal ray)
|
||||||
|
|
||||||
@@ -75,9 +82,9 @@ add_executable(unit_tests EXCLUDE_FROM_ALL
|
|||||||
tests/MainTest.cpp
|
tests/MainTest.cpp
|
||||||
tests/EngineTests.cpp
|
tests/EngineTests.cpp
|
||||||
tests/CallbackTest.cpp
|
tests/CallbackTest.cpp
|
||||||
tests/CollisionTest.cpp
|
|
||||||
tests/MoveTests.cpp
|
tests/MoveTests.cpp
|
||||||
)
|
tests/CollisionTest.cpp
|
||||||
|
)
|
||||||
target_include_directories(unit_tests PUBLIC sources)
|
target_include_directories(unit_tests PUBLIC sources)
|
||||||
target_link_libraries(unit_tests PUBLIC wal ray)
|
target_link_libraries(unit_tests PUBLIC wal ray)
|
||||||
|
|
||||||
|
|||||||
@@ -40,12 +40,13 @@ mkdir build
|
|||||||
cd build
|
cd build
|
||||||
cmake ..
|
cmake ..
|
||||||
cmake --build .
|
cmake --build .
|
||||||
|
cd ..
|
||||||
```
|
```
|
||||||
|
|
||||||
Enjoy !
|
Enjoy !
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
./bomberman
|
./build/bomberman
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
11
build_web.sh
Executable file
11
build_web.sh
Executable file
@@ -0,0 +1,11 @@
|
|||||||
|
#! /bin/bash
|
||||||
|
EMSDK_PATH=./emsdk
|
||||||
|
if [[ ! -d ./emsdk ]]; then
|
||||||
|
git clone https://github.com/emscripten-core/emsdk.git
|
||||||
|
fi
|
||||||
|
./emsdk/emsdk install latest
|
||||||
|
./emsdk/emsdk activate latest
|
||||||
|
source ./emsdk/emsdk_env.sh
|
||||||
|
mkdir -p build_web
|
||||||
|
emcmake cmake -S . -B build_web -DPLATFORM=Web &&
|
||||||
|
cmake --build build_web
|
||||||
@@ -9,6 +9,7 @@
|
|||||||
#define RAYERROR_HPP_
|
#define RAYERROR_HPP_
|
||||||
|
|
||||||
#include <stdexcept>
|
#include <stdexcept>
|
||||||
|
#include <string>
|
||||||
|
|
||||||
namespace RAY::Exception {
|
namespace RAY::Exception {
|
||||||
//! @brief base exception class for RAY lib
|
//! @brief base exception class for RAY lib
|
||||||
|
|||||||
@@ -10,12 +10,13 @@
|
|||||||
RAY::Cache<::ModelAnimation> RAY::ModelAnimations::_animationsCache(LoadModelAnimations, UnloadModelAnimations);
|
RAY::Cache<::ModelAnimation> RAY::ModelAnimations::_animationsCache(LoadModelAnimations, UnloadModelAnimations);
|
||||||
|
|
||||||
RAY::ModelAnimations::ModelAnimations(const std::string &filePath):
|
RAY::ModelAnimations::ModelAnimations(const std::string &filePath):
|
||||||
_animationsPtr(_animationsCache.fetch(filePath, &this->_animationCount))
|
_animationsPtr(_animationsCache.fetch(filePath, &this->_animationCount)),
|
||||||
|
_filePath(filePath)
|
||||||
{
|
{
|
||||||
::ModelAnimation *ptr = this->_animationsPtr.get();
|
::ModelAnimation *ptr = this->_animationsPtr.get();
|
||||||
|
|
||||||
for (int i = 0; i < this->_animationCount; i++)
|
for (int i = 0; i < this->_animationCount; i++)
|
||||||
this->_animations.push_back(RAY::ModelAnimation(ptr[i]));
|
this->_animations.emplace_back(ptr[i]);
|
||||||
}
|
}
|
||||||
|
|
||||||
RAY::ModelAnimation &RAY::ModelAnimations::operator[](int index)
|
RAY::ModelAnimation &RAY::ModelAnimations::operator[](int index)
|
||||||
@@ -28,3 +29,22 @@ size_t RAY::ModelAnimations::getAnimationsCount() const
|
|||||||
return this->_animationCount;
|
return this->_animationCount;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::string RAY::ModelAnimations::getFilePath() const
|
||||||
|
{
|
||||||
|
return this->_filePath;
|
||||||
|
}
|
||||||
|
|
||||||
|
const RAY::ModelAnimation &RAY::ModelAnimations::at(int index) const
|
||||||
|
{
|
||||||
|
return this->_animations.at(index);
|
||||||
|
}
|
||||||
|
|
||||||
|
const RAY::ModelAnimation &RAY::ModelAnimations::operator[](int index) const
|
||||||
|
{
|
||||||
|
return this->_animations[index];
|
||||||
|
}
|
||||||
|
|
||||||
|
RAY::ModelAnimation &RAY::ModelAnimations::at(int index)
|
||||||
|
{
|
||||||
|
return this->_animations.at(index);
|
||||||
|
}
|
||||||
|
|||||||
@@ -21,21 +21,33 @@ namespace RAY {
|
|||||||
//! @param filePath Path to the file containing animations
|
//! @param filePath Path to the file containing animations
|
||||||
ModelAnimations(const std::string &filePath);
|
ModelAnimations(const std::string &filePath);
|
||||||
|
|
||||||
//! @brief Only single entity can hold these animations pointers
|
//! @brief default copy ctor
|
||||||
ModelAnimations(const ModelAnimations &) = delete;
|
ModelAnimations(const ModelAnimations &) = default;
|
||||||
|
|
||||||
//! @brief Default constructor
|
//! @brief Default constructor
|
||||||
~ModelAnimations() = default;
|
~ModelAnimations() = default;
|
||||||
|
|
||||||
//! @brief Only single entity can hold these animations pointers
|
//! @brief Default assignment operator
|
||||||
ModelAnimations &operator=(const ModelAnimations &) = delete;
|
ModelAnimations &operator=(const ModelAnimations &) = default;
|
||||||
|
|
||||||
//! @brief Castin Object to raw model animation pointer
|
//! @brief Castin Object to raw model animation pointer
|
||||||
ModelAnimation &operator[](int index);
|
ModelAnimation &operator[](int index);
|
||||||
|
|
||||||
|
//! @brief std [] const
|
||||||
|
const ModelAnimation &operator[](int index) const;
|
||||||
|
|
||||||
|
//! @brief std at const
|
||||||
|
const ModelAnimation &at(int index) const;
|
||||||
|
|
||||||
|
//! @brief std at
|
||||||
|
ModelAnimation &at(int index);
|
||||||
|
|
||||||
//! @return the number of loaded animations
|
//! @return the number of loaded animations
|
||||||
size_t getAnimationsCount() const;
|
size_t getAnimationsCount() const;
|
||||||
|
|
||||||
|
//! @brief Get the creation file
|
||||||
|
std::string getFilePath() const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
//! @brief Holds the pointer returned by the loading function
|
//! @brief Holds the pointer returned by the loading function
|
||||||
std::shared_ptr<::ModelAnimation> _animationsPtr;
|
std::shared_ptr<::ModelAnimation> _animationsPtr;
|
||||||
@@ -46,6 +58,9 @@ namespace RAY {
|
|||||||
//! @brief the number of loaded animations
|
//! @brief the number of loaded animations
|
||||||
int _animationCount;
|
int _animationCount;
|
||||||
|
|
||||||
|
//! @brief The file where the animations were loaded (used to create a copy of this class)
|
||||||
|
const std::string _filePath;
|
||||||
|
|
||||||
static Cache<::ModelAnimation> _animationsCache;
|
static Cache<::ModelAnimation> _animationsCache;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -60,13 +60,17 @@ namespace RAY {
|
|||||||
{};
|
{};
|
||||||
std::shared_ptr<::ModelAnimation> fetch(const std::string &path, int *counter)
|
std::shared_ptr<::ModelAnimation> fetch(const std::string &path, int *counter)
|
||||||
{
|
{
|
||||||
if (this->_cache.find(path) == this->_cache.end())
|
if (this->_cache.find(path) != this->_cache.end())
|
||||||
|
return this->_cache[path];
|
||||||
|
|
||||||
|
::ModelAnimation *animations = this->_dataLoader(path.c_str(), counter);
|
||||||
|
unsigned int animCount = *counter;
|
||||||
|
|
||||||
this->_cache.emplace(path, std::shared_ptr<::ModelAnimation>(
|
this->_cache.emplace(path, std::shared_ptr<::ModelAnimation>(
|
||||||
this->_dataLoader(path.c_str(), counter), [this, counter](::ModelAnimation *p) {
|
animations, [this, animCount](::ModelAnimation *p) {
|
||||||
this->_dataUnloader(p, *counter);
|
this->_dataUnloader(p, animCount);
|
||||||
delete p;
|
|
||||||
}));
|
}));
|
||||||
return _cache[path];
|
return this->_cache[path];
|
||||||
};
|
};
|
||||||
private:
|
private:
|
||||||
//! @brief function to call to load data
|
//! @brief function to call to load data
|
||||||
|
|||||||
@@ -108,10 +108,14 @@ void RAY::Window::clear(RAY::Color color)
|
|||||||
ClearBackground(color);
|
ClearBackground(color);
|
||||||
}
|
}
|
||||||
|
|
||||||
void RAY::Window::draw()
|
void RAY::Window::beginDrawing()
|
||||||
|
{
|
||||||
|
BeginDrawing();
|
||||||
|
}
|
||||||
|
|
||||||
|
void RAY::Window::endDrawing()
|
||||||
{
|
{
|
||||||
EndDrawing();
|
EndDrawing();
|
||||||
BeginDrawing();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void RAY::Window::useCamera(RAY::Camera::Camera2D &camera)
|
void RAY::Window::useCamera(RAY::Camera::Camera2D &camera)
|
||||||
@@ -168,3 +172,8 @@ void RAY::Window::setIcon(RAY::Image &img)
|
|||||||
{
|
{
|
||||||
SetWindowIcon(img);
|
SetWindowIcon(img);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool RAY::Window::isReady() const
|
||||||
|
{
|
||||||
|
return IsWindowReady();
|
||||||
|
}
|
||||||
@@ -102,8 +102,10 @@ namespace RAY {
|
|||||||
NONE,
|
NONE,
|
||||||
};
|
};
|
||||||
|
|
||||||
//! @brief Draw the content of the buffer on the screen.
|
//! @brief Setup canvas (framebuffer) to start drawing
|
||||||
void draw();
|
void beginDrawing();
|
||||||
|
//! @brief End canvas drawing and swap buffers (double buffering)
|
||||||
|
void endDrawing();
|
||||||
|
|
||||||
//! @brief Initialize 2D mode with custom camera (2D)
|
//! @brief Initialize 2D mode with custom camera (2D)
|
||||||
void useCamera(Camera::Camera2D &camera);
|
void useCamera(Camera::Camera2D &camera);
|
||||||
@@ -131,6 +133,9 @@ namespace RAY {
|
|||||||
//! @brief Draw a 3d mesh with material and transform
|
//! @brief Draw a 3d mesh with material and transform
|
||||||
void draw(const Mesh &mesh, const Material &material, const Matrix &transform);
|
void draw(const Mesh &mesh, const Material &material, const Matrix &transform);
|
||||||
|
|
||||||
|
//! @return true if the window's context has been correctly initialized
|
||||||
|
bool isReady() const;
|
||||||
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
//! @brief Creates window, and opens it if openNow is set to true
|
//! @brief Creates window, and opens it if openNow is set to true
|
||||||
|
|||||||
@@ -14,6 +14,9 @@ if (NOT raylib_FOUND)
|
|||||||
SET(FETCHCONTENT_QUIET NO)
|
SET(FETCHCONTENT_QUIET NO)
|
||||||
FetchContent_Populate(raylib)
|
FetchContent_Populate(raylib)
|
||||||
SET(BUILD_EXAMPLES OFF CACHE BOOL "" FORCE)
|
SET(BUILD_EXAMPLES OFF CACHE BOOL "" FORCE)
|
||||||
|
if (EMSCRIPTEN)
|
||||||
|
SET(PLATFORM Web)
|
||||||
|
endif()
|
||||||
ADD_SUBDIRECTORY(${raylib_SOURCE_DIR} ${raylib_BINARY_DIR})
|
ADD_SUBDIRECTORY(${raylib_SOURCE_DIR} ${raylib_BINARY_DIR})
|
||||||
SET(raylib_FOUND TRUE)
|
SET(raylib_FOUND TRUE)
|
||||||
endif()
|
endif()
|
||||||
|
|||||||
@@ -17,6 +17,6 @@ add_library(wal
|
|||||||
sources/Component/Component.cpp
|
sources/Component/Component.cpp
|
||||||
sources/System/System.cpp
|
sources/System/System.cpp
|
||||||
sources/Models/Callback.hpp
|
sources/Models/Callback.hpp
|
||||||
)
|
sources/Models/TypeHolder.hpp)
|
||||||
|
|
||||||
target_include_directories(wal PUBLIC sources)
|
target_include_directories(wal PUBLIC sources)
|
||||||
@@ -10,6 +10,7 @@
|
|||||||
#include <memory>
|
#include <memory>
|
||||||
#include "Component/Component.hpp"
|
#include "Component/Component.hpp"
|
||||||
#include "Exception/WalError.hpp"
|
#include "Exception/WalError.hpp"
|
||||||
|
#include "Models/TypeHolder.hpp"
|
||||||
|
|
||||||
namespace WAL
|
namespace WAL
|
||||||
{
|
{
|
||||||
@@ -83,6 +84,18 @@ namespace WAL
|
|||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//! @brief Add a component to this entity. The component is constructed in place.
|
||||||
|
//! @throw DuplicateError is thrown if a component with the same type already exist.
|
||||||
|
//! @return This entity is returned
|
||||||
|
template<typename T, typename TNested, typename ...Types>
|
||||||
|
Entity &addComponent(Types &&...params)
|
||||||
|
{
|
||||||
|
if (this->hasComponent<T>())
|
||||||
|
throw DuplicateError("A component of the type \"" + std::string(typeid(T).name()) + "\" already exists.");
|
||||||
|
this->_components.push_back(std::make_unique<T>(*this, TypeHolder<TNested>(), std::forward<Types>(params)...));
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
//! @brief Copy a component to this entity.
|
//! @brief Copy a component to this entity.
|
||||||
//! @return This entity is returned.
|
//! @return This entity is returned.
|
||||||
Entity &addComponent(const Component &component);
|
Entity &addComponent(const Component &component);
|
||||||
|
|||||||
13
lib/wal/sources/Models/TypeHolder.hpp
Normal file
13
lib/wal/sources/Models/TypeHolder.hpp
Normal file
@@ -0,0 +1,13 @@
|
|||||||
|
//
|
||||||
|
// Created by Zoe Roux on 2021-06-02.
|
||||||
|
//
|
||||||
|
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
namespace WAL
|
||||||
|
{
|
||||||
|
//! @brief A class only used to specify template arguments.
|
||||||
|
template<typename T>
|
||||||
|
class TypeHolder {};
|
||||||
|
}
|
||||||
@@ -41,8 +41,10 @@ namespace WAL
|
|||||||
{
|
{
|
||||||
// TODO use an hashmap to cache results.
|
// TODO use an hashmap to cache results.
|
||||||
const auto &dependency = system.getDependencies();
|
const auto &dependency = system.getDependencies();
|
||||||
return std::ranges::all_of(dependency.begin(), dependency.end(), [&entity](const auto &dependency) {
|
for (const auto &dependency : system.getDependencies()) {
|
||||||
return entity.hasComponent(dependency);
|
if (!entity.hasComponent(dependency))
|
||||||
});
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
} // namespace WAL
|
} // namespace WAL
|
||||||
@@ -15,6 +15,10 @@
|
|||||||
#include "System/System.hpp"
|
#include "System/System.hpp"
|
||||||
#include "Models/Callback.hpp"
|
#include "Models/Callback.hpp"
|
||||||
|
|
||||||
|
#if defined(PLATFORM_WEB)
|
||||||
|
#include <emscripten/emscripten.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
namespace WAL
|
namespace WAL
|
||||||
{
|
{
|
||||||
//! @brief The main WAL class, it is used to setup and run the ECS.
|
//! @brief The main WAL class, it is used to setup and run the ECS.
|
||||||
@@ -109,7 +113,13 @@ namespace WAL
|
|||||||
void run(const std::function<void (Wal &, T &)> &callback, T state = T())
|
void run(const std::function<void (Wal &, T &)> &callback, T state = T())
|
||||||
{
|
{
|
||||||
Callback<Wal &, T &> update(callback);
|
Callback<Wal &, T &> update(callback);
|
||||||
|
|
||||||
|
#if defined(PLATFORM_WEB)
|
||||||
|
std::tuple iterationParams(this, &update, &state);
|
||||||
|
return emscripten_set_main_loop_arg((em_arg_callback_func)runIteration<T>, (void *)&iterationParams, 0, 1);
|
||||||
|
#else
|
||||||
return this->run(update, state);
|
return this->run(update, state);
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
//! @brief Start the game loop
|
//! @brief Start the game loop
|
||||||
@@ -137,6 +147,30 @@ namespace WAL
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if defined(PLATFORM_WEB)
|
||||||
|
template<typename T>
|
||||||
|
static void runIteration(void *param)
|
||||||
|
{
|
||||||
|
static auto iterationParams = reinterpret_cast<std::tuple<Wal *, Callback<Wal &, T &> *, T *> *>(param);
|
||||||
|
static const Callback<Wal &, T &> callback = *((Callback<Wal &, T &> *)std::get<1>(*iterationParams));
|
||||||
|
static T *state = (T *)std::get<2>(*iterationParams);
|
||||||
|
static Wal *wal = (Wal *)std::get<0>(*iterationParams);
|
||||||
|
static auto lastTick = std::chrono::steady_clock::now();
|
||||||
|
static std::chrono::nanoseconds fBehind(0);
|
||||||
|
|
||||||
|
auto now = std::chrono::steady_clock::now();
|
||||||
|
std::chrono::nanoseconds dtime = now - lastTick;
|
||||||
|
fBehind += dtime;
|
||||||
|
lastTick = now;
|
||||||
|
while (fBehind > Wal::timestep) {
|
||||||
|
fBehind -= Wal::timestep;
|
||||||
|
wal->_fixedUpdate();
|
||||||
|
}
|
||||||
|
wal->_update(dtime);
|
||||||
|
callback(*wal, *state);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
//! @brief A default constructor
|
//! @brief A default constructor
|
||||||
Wal() = default;
|
Wal() = default;
|
||||||
//! @brief A WAL can't be copy constructed
|
//! @brief A WAL can't be copy constructed
|
||||||
|
|||||||
71
sources/Component/Animation/AnimationsComponent.cpp
Normal file
71
sources/Component/Animation/AnimationsComponent.cpp
Normal file
@@ -0,0 +1,71 @@
|
|||||||
|
//
|
||||||
|
// Created by cbihan on 01/06/2021.
|
||||||
|
//
|
||||||
|
|
||||||
|
#include "AnimationsComponent.hpp"
|
||||||
|
#include "Entity/Entity.hpp"
|
||||||
|
#include "Model/ModelAnimations.hpp"
|
||||||
|
|
||||||
|
namespace BBM
|
||||||
|
{
|
||||||
|
AnimationsComponent::AnimationsComponent(WAL::Entity &entity, RAY::ModelAnimations modelAnimation, int animIndex, bool play)
|
||||||
|
: WAL::Component(entity),
|
||||||
|
_modelAnimation(std::move(modelAnimation)),
|
||||||
|
_currentAnimIndex(animIndex),
|
||||||
|
_animDisabled(play)
|
||||||
|
{
|
||||||
|
this->_modelAnimation[this->_currentAnimIndex].setFrameCounter(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
WAL::Component *AnimationsComponent::clone(WAL::Entity &entity) const
|
||||||
|
{
|
||||||
|
return new AnimationsComponent(entity,
|
||||||
|
RAY::ModelAnimations(this->_modelAnimation.getFilePath()),
|
||||||
|
this->_currentAnimIndex);
|
||||||
|
}
|
||||||
|
|
||||||
|
size_t AnimationsComponent::getCurrentAnimFrameCounter() const
|
||||||
|
{
|
||||||
|
return this->_modelAnimation.at(this->_currentAnimIndex).getFrameCounter();
|
||||||
|
}
|
||||||
|
|
||||||
|
RAY::ModelAnimation AnimationsComponent::getCurrentModelAnim()
|
||||||
|
{
|
||||||
|
return this->_modelAnimation[this->_currentAnimIndex];
|
||||||
|
}
|
||||||
|
|
||||||
|
void AnimationsComponent::setCurrentAnimFrameCounter(size_t animFrameCounter)
|
||||||
|
{
|
||||||
|
this->_modelAnimation[this->_currentAnimIndex].setFrameCounter(animFrameCounter);
|
||||||
|
}
|
||||||
|
|
||||||
|
void AnimationsComponent::resetCurrentAnimFrameCounter()
|
||||||
|
{
|
||||||
|
this->_modelAnimation[this->_currentAnimIndex].setFrameCounter(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
size_t AnimationsComponent::getCurrentAnimIndex() const
|
||||||
|
{
|
||||||
|
return this->_currentAnimIndex;
|
||||||
|
}
|
||||||
|
|
||||||
|
void AnimationsComponent::setAnimIndex(int animIndex)
|
||||||
|
{
|
||||||
|
this->_currentAnimIndex = animIndex % static_cast<int>(this->_modelAnimation.getAnimationsCount());
|
||||||
|
}
|
||||||
|
|
||||||
|
void AnimationsComponent::incCurrentAnimFrameCounter()
|
||||||
|
{
|
||||||
|
this->_modelAnimation[this->_currentAnimIndex].incrementFrameCounter();
|
||||||
|
}
|
||||||
|
|
||||||
|
void AnimationsComponent::setAnimDisabled(bool disable)
|
||||||
|
{
|
||||||
|
this->_animDisabled = disable;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool AnimationsComponent::isAnimDisabled() const
|
||||||
|
{
|
||||||
|
return this->_animDisabled;
|
||||||
|
}
|
||||||
|
}
|
||||||
63
sources/Component/Animation/AnimationsComponent.hpp
Normal file
63
sources/Component/Animation/AnimationsComponent.hpp
Normal file
@@ -0,0 +1,63 @@
|
|||||||
|
//
|
||||||
|
// Created by cbihan on 01/06/2021.
|
||||||
|
//
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <string>
|
||||||
|
#include <Model/ModelAnimations.hpp>
|
||||||
|
#include <Component/Component.hpp>
|
||||||
|
#include <Entity/Entity.hpp>
|
||||||
|
|
||||||
|
namespace BBM
|
||||||
|
{
|
||||||
|
class AnimationsComponent : public WAL::Component
|
||||||
|
{
|
||||||
|
private:
|
||||||
|
//! @brief To get the animation data
|
||||||
|
RAY::ModelAnimations _modelAnimation;
|
||||||
|
//! @brief The index of the
|
||||||
|
int _currentAnimIndex;
|
||||||
|
//! @brief Bool allowing to play pause an animation
|
||||||
|
bool _animDisabled;
|
||||||
|
public:
|
||||||
|
//! @inherit
|
||||||
|
WAL::Component *clone(WAL::Entity &entity) const override;
|
||||||
|
|
||||||
|
//! @brief get the current animation index
|
||||||
|
size_t getCurrentAnimIndex() const;
|
||||||
|
|
||||||
|
//! @brief Set the animation index to use
|
||||||
|
void setAnimIndex(int animIndex);
|
||||||
|
|
||||||
|
//! @brief get animation frame counter
|
||||||
|
size_t getCurrentAnimFrameCounter() const;
|
||||||
|
|
||||||
|
//! @brief get the current
|
||||||
|
RAY::ModelAnimation getCurrentModelAnim();
|
||||||
|
|
||||||
|
//! @brief set the anim frame counter
|
||||||
|
void setCurrentAnimFrameCounter(size_t animFrameCounter);
|
||||||
|
|
||||||
|
//! @brief Set the internal anim counter to 0
|
||||||
|
void resetCurrentAnimFrameCounter();
|
||||||
|
|
||||||
|
//! @brief Increment the internal anim counter
|
||||||
|
void incCurrentAnimFrameCounter();
|
||||||
|
|
||||||
|
//! @brief Allow to play pause animations
|
||||||
|
void setAnimDisabled(bool disable);
|
||||||
|
|
||||||
|
//! @brief To know if the animation will be updated or not
|
||||||
|
bool isAnimDisabled() const;
|
||||||
|
|
||||||
|
//! @brief ctor entity and the path of the animation file
|
||||||
|
explicit AnimationsComponent(WAL::Entity &entity, RAY::ModelAnimations modelAnimation, int animIndex, bool play = true);
|
||||||
|
//! @brief copy ctor
|
||||||
|
AnimationsComponent(const AnimationsComponent &) = default;
|
||||||
|
//! @brief dtor
|
||||||
|
~AnimationsComponent() override = default;
|
||||||
|
//! @brief assignment operator
|
||||||
|
AnimationsComponent &operator=(const AnimationsComponent &) = delete;
|
||||||
|
};
|
||||||
|
}
|
||||||
@@ -4,36 +4,37 @@
|
|||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
#include <Models/TypeHolder.hpp>
|
||||||
#include "Component/Component.hpp"
|
#include "Component/Component.hpp"
|
||||||
#include "Drawables/ADrawable2D.hpp"
|
#include "Drawables/ADrawable2D.hpp"
|
||||||
|
#include "Model/Model.hpp"
|
||||||
|
|
||||||
namespace BBM
|
namespace BBM
|
||||||
{
|
{
|
||||||
template <class T>
|
|
||||||
class Drawable2DComponent : public WAL::Component
|
class Drawable2DComponent : public WAL::Component
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
//! @brief The type of the component
|
//! @brief The type of the component
|
||||||
T member;
|
std::shared_ptr<RAY::Drawables::ADrawable2D> drawable;
|
||||||
|
|
||||||
//! ctor
|
//! @brief ctor
|
||||||
Drawable2DComponent(WAL::Entity &entity, T member)
|
Drawable2DComponent(WAL::Entity &entity, std::shared_ptr<RAY::Drawables::ADrawable2D> drawable)
|
||||||
: WAL::Component(entity),
|
: WAL::Component(entity),
|
||||||
member(std::move(member))
|
drawable(std::move(drawable))
|
||||||
{}
|
{}
|
||||||
|
|
||||||
//! ctor
|
//! ctor
|
||||||
template<typename ...Params>
|
template<typename T, typename ...Params>
|
||||||
explicit Drawable2DComponent(WAL::Entity &entity, Params &&...params)
|
explicit Drawable2DComponent(WAL::Entity &entity, WAL::TypeHolder<T>, Params &&...params)
|
||||||
: WAL::Component(entity),
|
: WAL::Component(entity),
|
||||||
member(std::forward<Params>(params)...)
|
drawable(new T(std::forward<Params>(params)...))
|
||||||
{}
|
{}
|
||||||
|
|
||||||
//! @brief Clone a component for another or the same entity.
|
//! @brief Clone a component for another or the same entity.
|
||||||
//! @param entity The entity that owns the ne component.
|
//! @param entity The entity that owns the ne component.
|
||||||
WAL::Component *clone(WAL::Entity &entity) const override
|
WAL::Component *clone(WAL::Entity &entity) const override
|
||||||
{
|
{
|
||||||
return new Drawable2DComponent(entity, this->member);
|
return new Drawable2DComponent(entity, this->drawable);
|
||||||
}
|
}
|
||||||
|
|
||||||
//! @brief Default copy ctor
|
//! @brief Default copy ctor
|
||||||
@@ -42,7 +43,5 @@ namespace BBM
|
|||||||
~Drawable2DComponent() override = default;
|
~Drawable2DComponent() override = default;
|
||||||
//! @brief Default assignment operator
|
//! @brief Default assignment operator
|
||||||
Drawable2DComponent &operator=(const Drawable2DComponent &) = delete;
|
Drawable2DComponent &operator=(const Drawable2DComponent &) = delete;
|
||||||
|
|
||||||
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
@@ -4,37 +4,37 @@
|
|||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
#include <Models/TypeHolder.hpp>
|
||||||
#include "Component/Component.hpp"
|
#include "Component/Component.hpp"
|
||||||
#include "Drawables/ADrawable3D.hpp"
|
#include "Drawables/ADrawable3D.hpp"
|
||||||
#include "Model/Model.hpp"
|
#include "Model/Model.hpp"
|
||||||
|
|
||||||
namespace BBM
|
namespace BBM
|
||||||
{
|
{
|
||||||
template <class T>
|
|
||||||
class Drawable3DComponent : public WAL::Component
|
class Drawable3DComponent : public WAL::Component
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
//! @brief The type of the component
|
//! @brief The type of the component
|
||||||
T member;
|
std::shared_ptr<RAY::Drawables::ADrawable3D> drawable;
|
||||||
|
|
||||||
//! @brief ctor
|
//! @brief ctor
|
||||||
Drawable3DComponent(WAL::Entity &entity, T member)
|
Drawable3DComponent(WAL::Entity &entity, std::shared_ptr<RAY::Drawables::ADrawable3D> drawable)
|
||||||
: WAL::Component(entity),
|
: WAL::Component(entity),
|
||||||
member(std::move(member))
|
drawable(std::move(drawable))
|
||||||
{}
|
{}
|
||||||
|
|
||||||
//! ctor
|
//! ctor
|
||||||
template<typename ...Params>
|
template<typename T, typename ...Params>
|
||||||
explicit Drawable3DComponent(WAL::Entity &entity, Params &&...params)
|
explicit Drawable3DComponent(WAL::Entity &entity, WAL::TypeHolder<T>, Params &&...params)
|
||||||
: WAL::Component(entity),
|
: WAL::Component(entity),
|
||||||
member(std::forward<Params>(params)...)
|
drawable(new T(std::forward<Params>(params)...))
|
||||||
{}
|
{}
|
||||||
|
|
||||||
//! @brief Clone a component for another or the same entity.
|
//! @brief Clone a component for another or the same entity.
|
||||||
//! @param entity The entity that owns the ne component.
|
//! @param entity The entity that owns the ne component.
|
||||||
WAL::Component *clone(WAL::Entity &entity) const override
|
WAL::Component *clone(WAL::Entity &entity) const override
|
||||||
{
|
{
|
||||||
return new Drawable3DComponent(entity, this->member);
|
return new Drawable3DComponent(entity, this->drawable);
|
||||||
}
|
}
|
||||||
|
|
||||||
//! @brief Default copy ctor
|
//! @brief Default copy ctor
|
||||||
|
|||||||
@@ -151,7 +151,7 @@ namespace BBM
|
|||||||
scene->addEntity("Hole Block")
|
scene->addEntity("Hole Block")
|
||||||
.addComponent<PositionComponent>(Vector3f(coords.x, coords.y - 1, coords.z))
|
.addComponent<PositionComponent>(Vector3f(coords.x, coords.y - 1, coords.z))
|
||||||
.addComponent<Drawable3DComponent, RAY3D::Model>(holeObj, std::make_pair(MAP_DIFFUSE, holePng));
|
.addComponent<Drawable3DComponent, RAY3D::Model>(holeObj, std::make_pair(MAP_DIFFUSE, holePng));
|
||||||
/* .addComponent<CollisionComponent>([](WAL::Entity &other, const WAL::Entity &entity) {
|
/*.addComponent<CollisionComponent>([](WAL::Entity &other, const WAL::Entity &entity) {
|
||||||
if (other.hasComponent<HealthComponent>()) {
|
if (other.hasComponent<HealthComponent>()) {
|
||||||
auto &health = other.getComponent<HealthComponent>();
|
auto &health = other.getComponent<HealthComponent>();
|
||||||
health.takeDmg(health.getHealthPoint());
|
health.takeDmg(health.getHealthPoint());
|
||||||
|
|||||||
@@ -14,7 +14,7 @@
|
|||||||
#include <tuple>
|
#include <tuple>
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
#include "Component/Renderer/Drawable3DComponent.hpp"
|
#include "Component/Renderer/Drawable3DComponent.hpp"
|
||||||
#include "System/Renderer/Renderer3DSystem.hpp"
|
#include "System/Renderer/RenderSystem.hpp"
|
||||||
#include "Scene/Scene.hpp"
|
#include "Scene/Scene.hpp"
|
||||||
#include "Model/Model.hpp"
|
#include "Model/Model.hpp"
|
||||||
#include "Component/Component.hpp"
|
#include "Component/Component.hpp"
|
||||||
|
|||||||
@@ -4,15 +4,13 @@
|
|||||||
|
|
||||||
#include <Wal.hpp>
|
#include <Wal.hpp>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <System/Movable/MovableSystem.hpp>
|
#include "System/Movable/MovableSystem.hpp"
|
||||||
#include <System/Renderer/RenderScreenSystem.hpp>
|
#include "System/Renderer/RenderSystem.hpp"
|
||||||
#include <System/Renderer/Render2DScreenSystem.hpp>
|
|
||||||
#include <System/Renderer/Renderer2DSystem.hpp>
|
|
||||||
#include <Model/Model.hpp>
|
#include <Model/Model.hpp>
|
||||||
|
#include <Drawables/3D/Cube.hpp>
|
||||||
#include <Drawables/2D/Rectangle.hpp>
|
#include <Drawables/2D/Rectangle.hpp>
|
||||||
#include <Drawables/3D/Cube.hpp>
|
#include <Drawables/3D/Cube.hpp>
|
||||||
#include <TraceLog.hpp>
|
#include <TraceLog.hpp>
|
||||||
#include <System/Renderer/Renderer3DSystem.hpp>
|
|
||||||
#include <System/Keyboard/KeyboardSystem.hpp>
|
#include <System/Keyboard/KeyboardSystem.hpp>
|
||||||
#include <System/Controllable/ControllableSystem.hpp>
|
#include <System/Controllable/ControllableSystem.hpp>
|
||||||
#include <System/Collision/CollisionSystem.hpp>
|
#include <System/Collision/CollisionSystem.hpp>
|
||||||
@@ -23,8 +21,13 @@
|
|||||||
#include <System/Gamepad/GamepadSystem.hpp>
|
#include <System/Gamepad/GamepadSystem.hpp>
|
||||||
#include "Models/Vector2.hpp"
|
#include "Models/Vector2.hpp"
|
||||||
#include "Component/Renderer/CameraComponent.hpp"
|
#include "Component/Renderer/CameraComponent.hpp"
|
||||||
|
#include "Component/Renderer/Drawable2DComponent.hpp"
|
||||||
|
#include "Component/Renderer/Drawable3DComponent.hpp"
|
||||||
#include "Runner.hpp"
|
#include "Runner.hpp"
|
||||||
#include "Models/GameState.hpp"
|
#include "Models/GameState.hpp"
|
||||||
|
#include <Model/ModelAnimations.hpp>
|
||||||
|
#include "Component/Animation/AnimationsComponent.hpp"
|
||||||
|
#include "System/Animation/AnimationsSystem.hpp"
|
||||||
#include "Map/Map.hpp"
|
#include "Map/Map.hpp"
|
||||||
|
|
||||||
namespace RAY2D = RAY::Drawables::Drawables2D;
|
namespace RAY2D = RAY::Drawables::Drawables2D;
|
||||||
@@ -55,13 +58,7 @@ namespace BBM
|
|||||||
{
|
{
|
||||||
RAY::TraceLog::setLevel(LOG_WARNING);
|
RAY::TraceLog::setLevel(LOG_WARNING);
|
||||||
RAY::Window &window = RAY::Window::getInstance(600, 400, "Bomberman", FLAG_WINDOW_RESIZABLE);
|
RAY::Window &window = RAY::Window::getInstance(600, 400, "Bomberman", FLAG_WINDOW_RESIZABLE);
|
||||||
|
wal.addSystem<RenderSystem>(wal, window);
|
||||||
wal.addSystem<Renderer3DSystem<RAY3D::Model>>();
|
|
||||||
wal.addSystem<Renderer3DSystem<RAY3D::Cube>>();
|
|
||||||
|
|
||||||
wal.addSystem<Render2DScreenSystem>(window)
|
|
||||||
.addSystem<Renderer2DSystem<RAY2D::Rectangle>>();
|
|
||||||
wal.addSystem<RenderScreenSystem>(window);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
std::shared_ptr<WAL::Scene> loadGameScene()
|
std::shared_ptr<WAL::Scene> loadGameScene()
|
||||||
@@ -69,14 +66,15 @@ namespace BBM
|
|||||||
auto scene = std::make_shared<WAL::Scene>();
|
auto scene = std::make_shared<WAL::Scene>();
|
||||||
scene->addEntity("player")
|
scene->addEntity("player")
|
||||||
.addComponent<PositionComponent>()
|
.addComponent<PositionComponent>()
|
||||||
.addComponent<Drawable3DComponent<RAY3D::Model>>("assets/player/player.iqm", std::make_pair(MAP_DIFFUSE, "assets/player/blue.png"))
|
.addComponent<Drawable3DComponent, RAY3D::Model>("assets/player/player.iqm", std::make_pair(MAP_DIFFUSE, "assets/player/blue.png"))
|
||||||
.addComponent<ControllableComponent>()
|
.addComponent<ControllableComponent>()
|
||||||
.addComponent<KeyboardComponent>()
|
.addComponent<KeyboardComponent>()
|
||||||
|
.addComponent<AnimationsComponent>(RAY::ModelAnimations("assets/player/player.iqm"), 1)
|
||||||
.addComponent<CollisionComponent>(2)
|
.addComponent<CollisionComponent>(2)
|
||||||
.addComponent<MovableComponent>();
|
.addComponent<MovableComponent>();
|
||||||
scene->addEntity("cube")
|
scene->addEntity("cube")
|
||||||
.addComponent<PositionComponent>(-5, 0, -5)
|
.addComponent<PositionComponent>(-5, 0, -5)
|
||||||
.addComponent<Drawable3DComponent<RAY3D::Cube>>(Vector3f(-5, 0, -5), Vector3f(3, 3, 3), RED)
|
.addComponent<Drawable3DComponent, RAY3D::Cube>(Vector3f(-5, 0, -5), Vector3f(3, 3, 3), RED)
|
||||||
.addComponent<ControllableComponent>()
|
.addComponent<ControllableComponent>()
|
||||||
.addComponent<KeyboardComponent>()
|
.addComponent<KeyboardComponent>()
|
||||||
.addComponent<CollisionComponent>([](WAL::Entity &, const WAL::Entity &){},
|
.addComponent<CollisionComponent>([](WAL::Entity &, const WAL::Entity &){},
|
||||||
|
|||||||
35
sources/System/Animation/AnimationsSystem.cpp
Normal file
35
sources/System/Animation/AnimationsSystem.cpp
Normal file
@@ -0,0 +1,35 @@
|
|||||||
|
//
|
||||||
|
// Created by cbihan on 01/06/2021.
|
||||||
|
//
|
||||||
|
|
||||||
|
#include <iostream>
|
||||||
|
#include "AnimationsSystem.hpp"
|
||||||
|
#include "Component/Animation/AnimationsComponent.hpp"
|
||||||
|
#include "Model/Model.hpp"
|
||||||
|
#include "Component/Renderer/Drawable3DComponent.hpp"
|
||||||
|
|
||||||
|
namespace BBM
|
||||||
|
{
|
||||||
|
|
||||||
|
AnimationsSystem::AnimationsSystem()
|
||||||
|
: WAL::System({
|
||||||
|
typeid(Drawable3DComponent),
|
||||||
|
typeid(AnimationsComponent)
|
||||||
|
})
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
void AnimationsSystem::onUpdate(WAL::Entity &entity, std::chrono::nanoseconds)
|
||||||
|
{
|
||||||
|
auto &model = entity.getComponent<Drawable3DComponent>();
|
||||||
|
auto &anim = entity.getComponent<AnimationsComponent>();
|
||||||
|
|
||||||
|
if (anim.isDisabled())
|
||||||
|
return;
|
||||||
|
auto modelPtr = std::dynamic_pointer_cast<RAY::Drawables::Drawables3D::Model>(model.drawable);
|
||||||
|
if (modelPtr) {
|
||||||
|
modelPtr->setAnimation(anim.getCurrentModelAnim());
|
||||||
|
anim.incCurrentAnimFrameCounter();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
26
sources/System/Animation/AnimationsSystem.hpp
Normal file
26
sources/System/Animation/AnimationsSystem.hpp
Normal file
@@ -0,0 +1,26 @@
|
|||||||
|
//
|
||||||
|
// Created by cbihan on 01/06/2021.
|
||||||
|
//
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <System/System.hpp>
|
||||||
|
|
||||||
|
namespace BBM
|
||||||
|
{
|
||||||
|
class AnimationsSystem : public WAL::System
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
//! @inherit
|
||||||
|
void onUpdate(WAL::Entity &entity, std::chrono::nanoseconds) override;
|
||||||
|
|
||||||
|
//! @brief A default constructor
|
||||||
|
AnimationsSystem();
|
||||||
|
//! @brief A Controllable system is copy constructable
|
||||||
|
AnimationsSystem(const AnimationsSystem &) = default;
|
||||||
|
//! @brief A default destructor
|
||||||
|
~AnimationsSystem() override = default;
|
||||||
|
//! @brief A Controllable system is assignable.
|
||||||
|
AnimationsSystem &operator=(const AnimationsSystem &) = default;
|
||||||
|
};
|
||||||
|
}
|
||||||
@@ -8,6 +8,7 @@
|
|||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
#include "Wal.hpp"
|
#include "Wal.hpp"
|
||||||
#include "System/System.hpp"
|
#include "System/System.hpp"
|
||||||
|
#include "Models/Vector3.hpp"
|
||||||
|
|
||||||
namespace BBM
|
namespace BBM
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -10,8 +10,6 @@
|
|||||||
|
|
||||||
namespace BBM
|
namespace BBM
|
||||||
{
|
{
|
||||||
float ControllableSystem::speed = .25f;
|
|
||||||
|
|
||||||
ControllableSystem::ControllableSystem()
|
ControllableSystem::ControllableSystem()
|
||||||
: WAL::System({
|
: WAL::System({
|
||||||
typeid(ControllableComponent),
|
typeid(ControllableComponent),
|
||||||
|
|||||||
@@ -14,7 +14,7 @@ namespace BBM
|
|||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
//! @brief The speed applied to every controllable entities.
|
//! @brief The speed applied to every controllable entities.
|
||||||
static float speed;
|
static constexpr const float speed = .25f;
|
||||||
|
|
||||||
//! @inherit
|
//! @inherit
|
||||||
void onFixedUpdate(WAL::Entity &entity) override;
|
void onFixedUpdate(WAL::Entity &entity) override;
|
||||||
|
|||||||
@@ -1,19 +0,0 @@
|
|||||||
//
|
|
||||||
// Created by Zoe Roux on 5/27/21.
|
|
||||||
//
|
|
||||||
|
|
||||||
#include "Render2DScreenSystem.hpp"
|
|
||||||
|
|
||||||
namespace BBM
|
|
||||||
{
|
|
||||||
Render2DScreenSystem::Render2DScreenSystem(RAY::Window &window)
|
|
||||||
: WAL::System({}),
|
|
||||||
_window(window),
|
|
||||||
_camera(RAY::Vector2(10, 10), RAY::Vector2(), 0)
|
|
||||||
{}
|
|
||||||
|
|
||||||
void Render2DScreenSystem::onSelfUpdate()
|
|
||||||
{
|
|
||||||
this->_window.useCamera(this->_camera);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,33 +0,0 @@
|
|||||||
//
|
|
||||||
// Created by Zoe Roux on 5/27/21.
|
|
||||||
//
|
|
||||||
|
|
||||||
#pragma once
|
|
||||||
|
|
||||||
#include <System/System.hpp>
|
|
||||||
#include <Window.hpp>
|
|
||||||
|
|
||||||
namespace BBM
|
|
||||||
{
|
|
||||||
class Render2DScreenSystem : public WAL::System
|
|
||||||
{
|
|
||||||
//! @brief The window to render on
|
|
||||||
RAY::Window &_window;
|
|
||||||
|
|
||||||
//! @brief The camera used to render.
|
|
||||||
RAY::Camera::Camera2D _camera;
|
|
||||||
public:
|
|
||||||
//! @brief A method called after all entities that this system manage has been updated.
|
|
||||||
//! @note render on screen here
|
|
||||||
void onSelfUpdate() override;
|
|
||||||
|
|
||||||
//! @brief ctor
|
|
||||||
explicit Render2DScreenSystem(RAY::Window &window);
|
|
||||||
//! @brief Default copy ctor
|
|
||||||
Render2DScreenSystem(const Render2DScreenSystem &) = default;
|
|
||||||
//! @brief Default dtor
|
|
||||||
~Render2DScreenSystem() override = default;
|
|
||||||
//! @brief A render screen system can't be assigned.
|
|
||||||
Render2DScreenSystem &operator=(const Render2DScreenSystem &) = delete;
|
|
||||||
};
|
|
||||||
}
|
|
||||||
@@ -1,36 +0,0 @@
|
|||||||
//
|
|
||||||
// Created by Zoe Roux on 5/27/21.
|
|
||||||
//
|
|
||||||
|
|
||||||
#include "RenderScreenSystem.hpp"
|
|
||||||
#include "Component/Renderer/CameraComponent.hpp"
|
|
||||||
#include "Component/Position/PositionComponent.hpp"
|
|
||||||
|
|
||||||
namespace BBM
|
|
||||||
{
|
|
||||||
RenderScreenSystem::RenderScreenSystem(RAY::Window &window)
|
|
||||||
: WAL::System({
|
|
||||||
typeid(CameraComponent),
|
|
||||||
typeid(PositionComponent)
|
|
||||||
}),
|
|
||||||
_window(window),
|
|
||||||
_camera(Vector3f(), Vector3f(), Vector3f(0, 1, 0), 50, CAMERA_PERSPECTIVE)
|
|
||||||
{
|
|
||||||
this->_window.setFPS(60);
|
|
||||||
}
|
|
||||||
|
|
||||||
void RenderScreenSystem::onSelfUpdate()
|
|
||||||
{
|
|
||||||
this->_window.draw();
|
|
||||||
this->_window.clear();
|
|
||||||
this->_window.useCamera(this->_camera);
|
|
||||||
}
|
|
||||||
|
|
||||||
void RenderScreenSystem::onUpdate(WAL::Entity &entity, std::chrono::nanoseconds dtime)
|
|
||||||
{
|
|
||||||
const auto &pos = entity.getComponent<PositionComponent>();
|
|
||||||
const auto &cam = entity.getComponent<CameraComponent>();
|
|
||||||
_camera.setPosition(pos.position);
|
|
||||||
_camera.setTarget(cam.target);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
66
sources/System/Renderer/RenderSystem.cpp
Normal file
66
sources/System/Renderer/RenderSystem.cpp
Normal file
@@ -0,0 +1,66 @@
|
|||||||
|
//
|
||||||
|
// Created by Zoe Roux on 5/27/21.
|
||||||
|
//
|
||||||
|
|
||||||
|
#include <Component/Renderer/Drawable3DComponent.hpp>
|
||||||
|
#include "Models/Vector2.hpp"
|
||||||
|
#include "RenderSystem.hpp"
|
||||||
|
#include "Component/Renderer/CameraComponent.hpp"
|
||||||
|
#include "Component/Position/PositionComponent.hpp"
|
||||||
|
#include "Component/Renderer/Drawable2DComponent.hpp"
|
||||||
|
#include "Drawables/ADrawable2D.hpp"
|
||||||
|
#include "Drawables/ADrawable3D.hpp"
|
||||||
|
|
||||||
|
namespace BBM
|
||||||
|
{
|
||||||
|
RenderSystem::RenderSystem(WAL::Wal &wal, RAY::Window &window)
|
||||||
|
: WAL::System({
|
||||||
|
typeid(CameraComponent),
|
||||||
|
typeid(PositionComponent)
|
||||||
|
}),
|
||||||
|
_wal(wal),
|
||||||
|
_window(window),
|
||||||
|
_camera(Vector3f(), Vector3f(), Vector3f(0, 1, 0), 50, CAMERA_PERSPECTIVE)
|
||||||
|
{}
|
||||||
|
|
||||||
|
void RenderSystem::onSelfUpdate()
|
||||||
|
{
|
||||||
|
this->_camera.update();
|
||||||
|
this->_window.beginDrawing();
|
||||||
|
this->_window.clear();
|
||||||
|
|
||||||
|
this->_window.useCamera(this->_camera);
|
||||||
|
for (auto &entity : this->_wal.scene->getEntities()) {
|
||||||
|
if (!entity.hasComponent<Drawable3DComponent>()
|
||||||
|
|| !entity.hasComponent<PositionComponent>())
|
||||||
|
continue;
|
||||||
|
auto &drawable = entity.getComponent<Drawable3DComponent>();
|
||||||
|
auto &pos = entity.getComponent<PositionComponent>();
|
||||||
|
|
||||||
|
drawable.drawable->setPosition(pos.position);
|
||||||
|
drawable.drawable->drawOn(this->_window);
|
||||||
|
}
|
||||||
|
this->_window.unuseCamera();
|
||||||
|
|
||||||
|
// TODO sort entities based on the Z axis
|
||||||
|
for (auto &entity : this->_wal.scene->getEntities()) {
|
||||||
|
if (!entity.hasComponent<Drawable2DComponent>()
|
||||||
|
|| !entity.hasComponent<PositionComponent>())
|
||||||
|
continue;
|
||||||
|
auto &drawable = entity.getComponent<Drawable2DComponent>();
|
||||||
|
auto &pos = entity.getComponent<PositionComponent>();
|
||||||
|
|
||||||
|
drawable.drawable->setPosition(Vector2f(pos.position.x, pos.position.y));
|
||||||
|
drawable.drawable->drawOn(this->_window);
|
||||||
|
}
|
||||||
|
this->_window.endDrawing();
|
||||||
|
}
|
||||||
|
|
||||||
|
void RenderSystem::onUpdate(WAL::Entity &entity, std::chrono::nanoseconds dtime)
|
||||||
|
{
|
||||||
|
const auto &pos = entity.getComponent<PositionComponent>();
|
||||||
|
const auto &cam = entity.getComponent<CameraComponent>();
|
||||||
|
_camera.setPosition(pos.position);
|
||||||
|
_camera.setTarget(cam.target);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -7,11 +7,15 @@
|
|||||||
#include "System/System.hpp"
|
#include "System/System.hpp"
|
||||||
#include "Camera/Camera2D.hpp"
|
#include "Camera/Camera2D.hpp"
|
||||||
#include "Window.hpp"
|
#include "Window.hpp"
|
||||||
|
#include "Wal.hpp"
|
||||||
|
|
||||||
namespace BBM
|
namespace BBM
|
||||||
{
|
{
|
||||||
class RenderScreenSystem : public WAL::System
|
class RenderSystem : public WAL::System
|
||||||
{
|
{
|
||||||
|
//! @brief The ECS to update.
|
||||||
|
WAL::Wal &_wal;
|
||||||
|
|
||||||
//! @brief The window to render on
|
//! @brief The window to render on
|
||||||
RAY::Window &_window;
|
RAY::Window &_window;
|
||||||
|
|
||||||
@@ -26,12 +30,12 @@ namespace BBM
|
|||||||
void onUpdate(WAL::Entity &entity, std::chrono::nanoseconds dtime) override;
|
void onUpdate(WAL::Entity &entity, std::chrono::nanoseconds dtime) override;
|
||||||
|
|
||||||
//! @brief ctor
|
//! @brief ctor
|
||||||
explicit RenderScreenSystem(RAY::Window &window);
|
RenderSystem(WAL::Wal &wal, RAY::Window &window);
|
||||||
//! @brief Default copy ctor
|
//! @brief Default copy ctor
|
||||||
RenderScreenSystem(const RenderScreenSystem &) = default;
|
RenderSystem(const RenderSystem &) = default;
|
||||||
//! @brief Default dtor
|
//! @brief Default dtor
|
||||||
~RenderScreenSystem() override = default;
|
~RenderSystem() override = default;
|
||||||
//! @brief A render screen system can't be assigned.
|
//! @brief A render screen system can't be assigned.
|
||||||
RenderScreenSystem &operator=(const RenderScreenSystem &) = delete;
|
RenderSystem &operator=(const RenderSystem &) = delete;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
@@ -1,48 +0,0 @@
|
|||||||
//
|
|
||||||
// Created by cbihan on 24/05/2021.
|
|
||||||
//
|
|
||||||
|
|
||||||
#pragma once
|
|
||||||
|
|
||||||
#include <type_traits>
|
|
||||||
#include "System/System.hpp"
|
|
||||||
#include "Entity/Entity.hpp"
|
|
||||||
#include "Component/Position/PositionComponent.hpp"
|
|
||||||
#include "Component/Renderer/Drawable2DComponent.hpp"
|
|
||||||
#include "Window.hpp"
|
|
||||||
|
|
||||||
namespace BBM
|
|
||||||
{
|
|
||||||
template <class T>
|
|
||||||
class Renderer2DSystem : public WAL::System
|
|
||||||
{
|
|
||||||
private:
|
|
||||||
//! @brief The class to render
|
|
||||||
RAY::Window &_window;
|
|
||||||
public:
|
|
||||||
explicit Renderer2DSystem()
|
|
||||||
: WAL::System({typeid(PositionComponent), typeid(Drawable2DComponent<T>)}),
|
|
||||||
_window(RAY::Window::getInstance())
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
//! @brief Update the corresponding component of the given entity
|
|
||||||
//! @param entity The entity to update.
|
|
||||||
//! @param dtime The delta time.
|
|
||||||
void onUpdate(WAL::Entity &entity, std::chrono::nanoseconds) override
|
|
||||||
{
|
|
||||||
auto &comp = entity.getComponent<Drawable2DComponent<T>>();
|
|
||||||
auto &pos = entity.getComponent<PositionComponent>();
|
|
||||||
|
|
||||||
comp.member.setPosition({pos.getX(), pos.getY()});
|
|
||||||
comp.member.drawOn(this->_window);
|
|
||||||
}
|
|
||||||
|
|
||||||
//! @brief default copy ctor
|
|
||||||
Renderer2DSystem(const Renderer2DSystem &) = default;
|
|
||||||
//! @brief default dtor
|
|
||||||
~Renderer2DSystem() override = default;
|
|
||||||
//! @brief Default assignment operator
|
|
||||||
Renderer2DSystem &operator=(const Renderer2DSystem &) = delete;
|
|
||||||
};
|
|
||||||
}
|
|
||||||
@@ -1,48 +0,0 @@
|
|||||||
//
|
|
||||||
// Created by cbihan on 24/05/2021.
|
|
||||||
//
|
|
||||||
|
|
||||||
#pragma once
|
|
||||||
|
|
||||||
#include <type_traits>
|
|
||||||
#include "System/System.hpp"
|
|
||||||
#include "Entity/Entity.hpp"
|
|
||||||
#include "Component/Position/PositionComponent.hpp"
|
|
||||||
#include "Component/Renderer/Drawable3DComponent.hpp"
|
|
||||||
#include "Window.hpp"
|
|
||||||
|
|
||||||
namespace BBM
|
|
||||||
{
|
|
||||||
template <class T>
|
|
||||||
class Renderer3DSystem : public WAL::System
|
|
||||||
{
|
|
||||||
private:
|
|
||||||
//! @brief The class to render
|
|
||||||
RAY::Window &_window;
|
|
||||||
public:
|
|
||||||
//! @brief ctor
|
|
||||||
explicit Renderer3DSystem()
|
|
||||||
: WAL::System({typeid(PositionComponent), typeid(Drawable3DComponent<T>)}),
|
|
||||||
_window(RAY::Window::getInstance())
|
|
||||||
{}
|
|
||||||
|
|
||||||
//! @brief Update the corresponding component of the given entity
|
|
||||||
//! @param entity The entity to update.
|
|
||||||
//! @param dtime The delta time.
|
|
||||||
void onUpdate(WAL::Entity &entity, std::chrono::nanoseconds) override
|
|
||||||
{
|
|
||||||
auto &comp = entity.getComponent<Drawable3DComponent<T>>();
|
|
||||||
auto &pos = entity.getComponent<PositionComponent>();
|
|
||||||
|
|
||||||
comp.member.setPosition(static_cast<RAY::Vector3>(pos.position));
|
|
||||||
comp.member.drawOn(this->_window);
|
|
||||||
}
|
|
||||||
|
|
||||||
//! @brief Default copy ctor
|
|
||||||
Renderer3DSystem(const Renderer3DSystem &) = default;
|
|
||||||
//! @brief Default dtor
|
|
||||||
~Renderer3DSystem() override = default;
|
|
||||||
//! @brief Default assignment operator
|
|
||||||
Renderer3DSystem &operator=(const Renderer3DSystem &) = delete;
|
|
||||||
};
|
|
||||||
}
|
|
||||||
@@ -9,50 +9,6 @@
|
|||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include "Runner/Runner.hpp"
|
#include "Runner/Runner.hpp"
|
||||||
|
|
||||||
// Dependencies of the demo
|
|
||||||
#include "Camera/Camera3D.hpp"
|
|
||||||
#include "Controllers/Keyboard.hpp"
|
|
||||||
#include "Drawables/2D/Text.hpp"
|
|
||||||
#include "Drawables/Image.hpp"
|
|
||||||
#include "Drawables/3D/Grid.hpp"
|
|
||||||
#include "Drawables/Texture.hpp"
|
|
||||||
#include "Drawables/3D/Circle.hpp"
|
|
||||||
#include "Drawables/2D/Circle.hpp"
|
|
||||||
#include "Drawables/3D/Cube.hpp"
|
|
||||||
#include "Drawables/3D/Sphere.hpp"
|
|
||||||
#include "Model/Model.hpp"
|
|
||||||
#include "Model/ModelAnimations.hpp"
|
|
||||||
#include <System/Renderer/RenderScreenSystem.hpp>
|
|
||||||
#include <System/Renderer/Render2DScreenSystem.hpp>
|
|
||||||
#include <System/Renderer/Renderer2DSystem.hpp>
|
|
||||||
#include <System/Renderer/Renderer3DSystem.hpp>
|
|
||||||
#include "Component/Renderer/Drawable3DComponent.hpp"
|
|
||||||
#include "Component/Renderer/Drawable2DComponent.hpp"
|
|
||||||
#include "System/Renderer/RenderScreenSystem.hpp"
|
|
||||||
#include "Vector/Vector3.hpp"
|
|
||||||
#include "Window.hpp"
|
|
||||||
#include "TraceLog.hpp"
|
|
||||||
#include "Wal.hpp"
|
|
||||||
|
|
||||||
const std::vector<std::string>textures = {
|
|
||||||
"blue", "cyan", "green", "purple", "red", "yellow"
|
|
||||||
};
|
|
||||||
|
|
||||||
std::string get_full_path(const std::string &color)
|
|
||||||
{
|
|
||||||
std::string path = "assets/player/";
|
|
||||||
|
|
||||||
path += color;
|
|
||||||
path += ".png";
|
|
||||||
return path;
|
|
||||||
}
|
|
||||||
|
|
||||||
int demo(void)
|
|
||||||
{
|
|
||||||
|
|
||||||
return (0);
|
|
||||||
}
|
|
||||||
|
|
||||||
void usage(const std::string &bin)
|
void usage(const std::string &bin)
|
||||||
{
|
{
|
||||||
std::cout << "Bomberman." << std::endl
|
std::cout << "Bomberman." << std::endl
|
||||||
@@ -67,6 +23,5 @@ int main(int argc, char **argv)
|
|||||||
usage(argv[0]);
|
usage(argv[0]);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
//return demo();
|
|
||||||
return BBM::run();
|
return BBM::run();
|
||||||
}
|
}
|
||||||
|
|||||||
147
sources/wasm/frontend.html
Normal file
147
sources/wasm/frontend.html
Normal file
@@ -0,0 +1,147 @@
|
|||||||
|
<!doctype html>
|
||||||
|
<html lang="en-us">
|
||||||
|
<head>
|
||||||
|
<meta charset="utf-8">
|
||||||
|
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
|
||||||
|
<title>Emscripten-Generated Code</title>
|
||||||
|
<style>
|
||||||
|
.emscripten { padding-right: 0; margin-left: auto; margin-right: auto; display: block; }
|
||||||
|
textarea.emscripten { font-family: monospace; width: 80%; }
|
||||||
|
div.emscripten { text-align: center; }
|
||||||
|
div.emscripten_border { border: 1px solid black; }
|
||||||
|
/* the canvas *must not* have any border or padding, or mouse coords will be wrong */
|
||||||
|
canvas.emscripten { border: 0px none; background-color: black; }
|
||||||
|
|
||||||
|
.spinner {
|
||||||
|
height: 50px;
|
||||||
|
width: 50px;
|
||||||
|
margin: 0px auto;
|
||||||
|
-webkit-animation: rotation .8s linear infinite;
|
||||||
|
-moz-animation: rotation .8s linear infinite;
|
||||||
|
-o-animation: rotation .8s linear infinite;
|
||||||
|
animation: rotation 0.8s linear infinite;
|
||||||
|
border-left: 10px solid rgb(0,150,240);
|
||||||
|
border-right: 10px solid rgb(0,150,240);
|
||||||
|
border-bottom: 10px solid rgb(0,150,240);
|
||||||
|
border-top: 10px solid rgb(100,0,200);
|
||||||
|
border-radius: 100%;
|
||||||
|
background-color: rgb(200,100,250);
|
||||||
|
}
|
||||||
|
@-webkit-keyframes rotation {
|
||||||
|
from {-webkit-transform: rotate(0deg);}
|
||||||
|
to {-webkit-transform: rotate(360deg);}
|
||||||
|
}
|
||||||
|
@-moz-keyframes rotation {
|
||||||
|
from {-moz-transform: rotate(0deg);}
|
||||||
|
to {-moz-transform: rotate(360deg);}
|
||||||
|
}
|
||||||
|
@-o-keyframes rotation {
|
||||||
|
from {-o-transform: rotate(0deg);}
|
||||||
|
to {-o-transform: rotate(360deg);}
|
||||||
|
}
|
||||||
|
@keyframes rotation {
|
||||||
|
from {transform: rotate(0deg);}
|
||||||
|
to {transform: rotate(360deg);}
|
||||||
|
}
|
||||||
|
|
||||||
|
</style>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<hr/>
|
||||||
|
<figure style="overflow:visible;" id="spinner"><div class="spinner"></div><center style="margin-top:0.5em"><strong>emscripten</strong></center></figure>
|
||||||
|
<div class="emscripten" id="status">Downloading...</div>
|
||||||
|
<div class="emscripten">
|
||||||
|
<progress value="0" max="100" id="progress" hidden=1></progress>
|
||||||
|
</div>
|
||||||
|
<div class="emscripten">
|
||||||
|
<canvas class="emscripten" id="canvas" oncontextmenu="event.preventDefault()" tabindex=-1></canvas>
|
||||||
|
</div>
|
||||||
|
<hr/>
|
||||||
|
<div class="emscripten">
|
||||||
|
<input type="checkbox" id="resize">Resize canvas
|
||||||
|
<input type="checkbox" id="pointerLock" checked>Lock/hide mouse pointer
|
||||||
|
|
||||||
|
<input type="button" value="Fullscreen" onclick="Module.requestFullscreen(document.getElementById('pointerLock').checked,
|
||||||
|
document.getElementById('resize').checked)">
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<hr/>
|
||||||
|
<script type='text/javascript'>
|
||||||
|
var statusElement = document.getElementById('status');
|
||||||
|
var progressElement = document.getElementById('progress');
|
||||||
|
var spinnerElement = document.getElementById('spinner');
|
||||||
|
|
||||||
|
var Module = {
|
||||||
|
preRun: [],
|
||||||
|
postRun: [],
|
||||||
|
print: (function() {
|
||||||
|
var element = document.getElementById('output');
|
||||||
|
if (element) element.value = ''; // clear browser cache
|
||||||
|
return function(text) {
|
||||||
|
if (arguments.length > 1) text = Array.prototype.slice.call(arguments).join(' ');
|
||||||
|
// These replacements are necessary if you render to raw HTML
|
||||||
|
//text = text.replace(/&/g, "&");
|
||||||
|
//text = text.replace(/</g, "<");
|
||||||
|
//text = text.replace(/>/g, ">");
|
||||||
|
//text = text.replace('\n', '<br>', 'g');
|
||||||
|
console.log(text);
|
||||||
|
if (element) {
|
||||||
|
element.value += text + "\n";
|
||||||
|
element.scrollTop = element.scrollHeight; // focus on bottom
|
||||||
|
}
|
||||||
|
};
|
||||||
|
})(),
|
||||||
|
printErr: function(text) {
|
||||||
|
if (arguments.length > 1) text = Array.prototype.slice.call(arguments).join(' ');
|
||||||
|
console.error(text);
|
||||||
|
},
|
||||||
|
canvas: (function() {
|
||||||
|
var canvas = document.getElementById('canvas');
|
||||||
|
|
||||||
|
// As a default initial behavior, pop up an alert when webgl context is lost. To make your
|
||||||
|
// application robust, you may want to override this behavior before shipping!
|
||||||
|
// See http://www.khronos.org/registry/webgl/specs/latest/1.0/#5.15.2
|
||||||
|
canvas.addEventListener("webglcontextlost", function(e) { alert('WebGL context lost. You will need to reload the page.'); e.preventDefault(); }, false);
|
||||||
|
|
||||||
|
return canvas;
|
||||||
|
})(),
|
||||||
|
setStatus: function(text) {
|
||||||
|
if (!Module.setStatus.last) Module.setStatus.last = { time: Date.now(), text: '' };
|
||||||
|
if (text === Module.setStatus.last.text) return;
|
||||||
|
var m = text.match(/([^(]+)\((\d+(\.\d+)?)\/(\d+)\)/);
|
||||||
|
var now = Date.now();
|
||||||
|
if (m && now - Module.setStatus.last.time < 30) return; // if this is a progress update, skip it if too soon
|
||||||
|
Module.setStatus.last.time = now;
|
||||||
|
Module.setStatus.last.text = text;
|
||||||
|
if (m) {
|
||||||
|
text = m[1];
|
||||||
|
progressElement.value = parseInt(m[2])*100;
|
||||||
|
progressElement.max = parseInt(m[4])*100;
|
||||||
|
progressElement.hidden = false;
|
||||||
|
spinnerElement.hidden = false;
|
||||||
|
} else {
|
||||||
|
progressElement.value = null;
|
||||||
|
progressElement.max = null;
|
||||||
|
progressElement.hidden = true;
|
||||||
|
if (!text) spinnerElement.hidden = true;
|
||||||
|
}
|
||||||
|
statusElement.innerHTML = text;
|
||||||
|
},
|
||||||
|
totalDependencies: 0,
|
||||||
|
monitorRunDependencies: function(left) {
|
||||||
|
this.totalDependencies = Math.max(this.totalDependencies, left);
|
||||||
|
Module.setStatus(left ? 'Preparing... (' + (this.totalDependencies-left) + '/' + this.totalDependencies + ')' : 'All downloads complete.');
|
||||||
|
}
|
||||||
|
};
|
||||||
|
Module.setStatus('Downloading...');
|
||||||
|
window.onerror = function() {
|
||||||
|
Module.setStatus('Exception thrown, see JavaScript console');
|
||||||
|
spinnerElement.style.display = 'none';
|
||||||
|
Module.setStatus = function(text) {
|
||||||
|
if (text) Module.printErr('[post-exception status] ' + text);
|
||||||
|
};
|
||||||
|
};
|
||||||
|
</script>
|
||||||
|
{{{ SCRIPT }}}
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
Reference in New Issue
Block a user