mirror of
https://github.com/zoriya/Bomberman.git
synced 2026-06-01 09:45:42 +00:00
Merge branch 'renderer' of github.com:AnonymusRaccoon/Bomberman into renderer
This commit is contained in:
@@ -8,10 +8,20 @@
|
||||
#include "Model/Model.hpp"
|
||||
#include "Exceptions/RayError.hpp"
|
||||
|
||||
RAY::Drawables::Drawables3D::Model::Model(const std::string &filename, const RAY::Vector3 &position, const RAY::Vector3 &rotationAxis, float rotationAngle, const RAY::Vector3 &scale):
|
||||
ADrawable3D(position, WHITE), _model(LoadModel(filename.c_str())),
|
||||
_rotationAxis(rotationAxis), _rotationAngle(rotationAngle), _scale(scale)
|
||||
RAY::Drawables::Drawables3D::Model::Model(const std::string &filename,
|
||||
std::optional<std::pair<MaterialType, std::string>> texture,
|
||||
const RAY::Vector3 &position,
|
||||
const RAY::Vector3 &rotationAxis,
|
||||
float rotationAngle,
|
||||
const RAY::Vector3 &scale)
|
||||
: ADrawable3D(position, WHITE),
|
||||
_model(LoadModel(filename.c_str())),
|
||||
_rotationAxis(rotationAxis),
|
||||
_rotationAngle(rotationAngle),
|
||||
_scale(scale)
|
||||
{
|
||||
if (texture.has_value())
|
||||
this->setTextureToMaterial(texture->first, texture->second);
|
||||
}
|
||||
|
||||
RAY::Drawables::Drawables3D::Model::Model(const Mesh &mesh)
|
||||
@@ -58,7 +68,15 @@ bool RAY::Drawables::Drawables3D::Model::setAnimation(const RAY::ModelAnimation
|
||||
|
||||
bool RAY::Drawables::Drawables3D::Model::setTextureToMaterial(RAY::Drawables::Drawables3D::Model::MaterialType materialType, const RAY::Texture &texture)
|
||||
{
|
||||
SetMaterialTexture(&this->_model.materials[materialType], materialType, texture);
|
||||
this->_textureList[materialType] = texture;
|
||||
SetMaterialTexture(&this->_model.materials[materialType], materialType, this->_textureList[materialType]);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool RAY::Drawables::Drawables3D::Model::setTextureToMaterial(RAY::Drawables::Drawables3D::Model::MaterialType materialType, const std::string &texturePath)
|
||||
{
|
||||
this->_textureList.emplace(materialType, texturePath);
|
||||
SetMaterialTexture(&this->_model.materials[materialType], materialType, this->_textureList[materialType]);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@@ -14,6 +14,8 @@
|
||||
#include "Model/ModelAnimation.hpp"
|
||||
#include <raylib.h>
|
||||
#include <vector>
|
||||
#include <optional>
|
||||
#include <map>
|
||||
|
||||
namespace RAY::Drawables::Drawables3D {
|
||||
//! @brief Basic 3D Model type
|
||||
@@ -24,7 +26,12 @@ namespace RAY::Drawables::Drawables3D {
|
||||
|
||||
//! @brief Create an model, loading a file
|
||||
//! @param filePath: path to file to load
|
||||
Model(const std::string &filePath, const RAY::Vector3 &position = {0, 0, 0}, const RAY::Vector3 &rotationAxis = RAY::Vector3(0, 1, 0), float rotationAngle = 0, const RAY::Vector3 &scale = RAY::Vector3(1, 1, 1));
|
||||
Model(const std::string &filePath,
|
||||
std::optional<std::pair<MaterialType, std::string>> texture = std::nullopt,
|
||||
const RAY::Vector3 &position = {0, 0, 0},
|
||||
const RAY::Vector3 &rotationAxis = RAY::Vector3(0, 1, 0),
|
||||
float rotationAngle = 0,
|
||||
const RAY::Vector3 &scale = RAY::Vector3(1, 1, 1));
|
||||
|
||||
//! @brief Create an model, loading a file
|
||||
//! @param mesh: mesh to load
|
||||
@@ -58,6 +65,7 @@ namespace RAY::Drawables::Drawables3D {
|
||||
//! @param materielIndex The type of material to apply the texture to (serves as an index)
|
||||
//! @param texture the texture to apply
|
||||
bool setTextureToMaterial(MaterialType materialType, const RAY::Texture &texture);
|
||||
bool setTextureToMaterial(MaterialType materialType, const std::string &texture);
|
||||
|
||||
//! @return The number of bones in the model
|
||||
int getBoneCount() const;
|
||||
@@ -85,6 +93,8 @@ namespace RAY::Drawables::Drawables3D {
|
||||
private:
|
||||
//! @brief Raw data from raylib
|
||||
::Model _model;
|
||||
//! @brief The list of textures that can be applied to this model.
|
||||
std::map<MaterialType, Texture> _textureList;
|
||||
//! @brief Rotation property
|
||||
RAY::Vector3 _rotationAxis;
|
||||
//! @brief Rotation property
|
||||
|
||||
@@ -23,8 +23,6 @@ namespace WAL
|
||||
private:
|
||||
//! @brief The list of registered systems
|
||||
std::vector<std::unique_ptr<System>> _systems = {};
|
||||
//! @brief True if the engine should close after the end of the current tick.
|
||||
bool _shouldClose = false;
|
||||
|
||||
//! @brief Call the onUpdate of every system with every component
|
||||
void _update(std::chrono::nanoseconds dtime);
|
||||
@@ -40,6 +38,8 @@ namespace WAL
|
||||
public:
|
||||
//! @brief The scene that contains entities.
|
||||
std::shared_ptr<Scene> scene;
|
||||
//! @brief True if the engine should close after the end of the current tick.
|
||||
bool shouldClose = false;
|
||||
//! @brief The time between each fixed update.
|
||||
static std::chrono::nanoseconds timestep;
|
||||
|
||||
@@ -122,7 +122,7 @@ namespace WAL
|
||||
auto lastTick = std::chrono::steady_clock::now();
|
||||
std::chrono::nanoseconds fBehind(0);
|
||||
|
||||
while (!this->_shouldClose) {
|
||||
while (!this->shouldClose) {
|
||||
auto now = std::chrono::steady_clock::now();
|
||||
std::chrono::nanoseconds dtime = now - lastTick;
|
||||
fBehind += dtime;
|
||||
|
||||
+19
-13
@@ -8,13 +8,18 @@
|
||||
#include <System/Renderer/RenderScreenSystem.hpp>
|
||||
#include <System/Renderer/Render2DScreenSystem.hpp>
|
||||
#include <System/Renderer/Renderer2DSystem.hpp>
|
||||
#include <Model/Model.hpp>
|
||||
#include <Drawables/2D/Rectangle.hpp>
|
||||
#include <TraceLog.hpp>
|
||||
#include <System/Renderer/Renderer3DSystem.hpp>
|
||||
#include "Models/Vector2.hpp"
|
||||
#include "Component/Renderer/CameraComponent.hpp"
|
||||
#include "Runner.hpp"
|
||||
#include "Models/GameState.hpp"
|
||||
|
||||
namespace RAY2D = RAY::Drawables::Drawables2D;
|
||||
namespace RAY3D = RAY::Drawables::Drawables3D;
|
||||
|
||||
namespace BBM
|
||||
{
|
||||
void updateState(WAL::Wal &engine, GameState &state)
|
||||
@@ -23,26 +28,32 @@ namespace BBM
|
||||
|
||||
// If you want to keep a scene loaded but not running, store it in the state.loadedScenes.
|
||||
// If you don't need the scene anymore, remember to remove it from the loadedScene array.
|
||||
if (RAY::Window::getInstance().shouldClose())
|
||||
engine.shouldClose = true;
|
||||
}
|
||||
|
||||
void enableRaylib(WAL::Wal &wal)
|
||||
{
|
||||
RAY::TraceLog::setLevel(LOG_WARNING);
|
||||
RAY::Window &window = RAY::Window::getInstance(600, 400, "Bomberman", FLAG_WINDOW_RESIZABLE);
|
||||
|
||||
// wal.addSystem<Renderer3DSystem<RAY::Drawables::Drawables3D::Model>>();
|
||||
wal.addSystem<Renderer3DSystem<RAY3D::Model>>();
|
||||
|
||||
wal.addSystem<Render2DScreenSystem>(window)
|
||||
.addSystem<Renderer2DSystem<RAY::Drawables::Drawables2D::Rectangle>>();
|
||||
.addSystem<Renderer2DSystem<RAY2D::Rectangle>>();
|
||||
wal.addSystem<RenderScreenSystem>(window);
|
||||
}
|
||||
|
||||
WAL::Scene loadGameScene()
|
||||
std::shared_ptr<WAL::Scene> loadGameScene()
|
||||
{
|
||||
WAL::Scene scene;
|
||||
scene.addEntity("cube")
|
||||
auto scene = std::make_shared<WAL::Scene>();
|
||||
scene->addEntity("cube")
|
||||
.addComponent<PositionComponent>()
|
||||
.addComponent<Drawable2DComponent<RAY::Drawables::Drawables2D::Rectangle>>(Vector2f(), Vector2f(10, 10), RED);
|
||||
scene.addEntity("camera")
|
||||
.addComponent<Drawable2DComponent<RAY2D::Rectangle>>(Vector2f(), Vector2f(10, 10), RED);
|
||||
scene->addEntity("player")
|
||||
.addComponent<PositionComponent>()
|
||||
.addComponent<Drawable3DComponent<RAY3D::Model>>("assets/player/player.iqm", std::make_pair(MAP_DIFFUSE, "assets/player/blue.png"));
|
||||
scene->addEntity("camera")
|
||||
.addComponent<PositionComponent>(10, 10, 10)
|
||||
.addComponent<CameraComponent>();
|
||||
return scene;
|
||||
@@ -50,15 +61,10 @@ namespace BBM
|
||||
|
||||
int run()
|
||||
{
|
||||
WAL::Scene gameScene = loadGameScene();
|
||||
WAL::Wal wal;
|
||||
wal.addSystem<MovableSystem>();
|
||||
enableRaylib(wal);
|
||||
WAL::Scene scene = loadGameScene();
|
||||
wal.scene = std::make_shared<WAL::Scene>(scene);
|
||||
|
||||
|
||||
// wal.scene = loadGameScene();
|
||||
wal.scene = loadGameScene();
|
||||
|
||||
try {
|
||||
wal.run<GameState>(updateState);
|
||||
|
||||
@@ -21,11 +21,10 @@ namespace BBM
|
||||
RAY::Window &_window;
|
||||
public:
|
||||
//! @brief ctor
|
||||
explicit Renderer3DSystem(RAY::Window &window)
|
||||
explicit Renderer3DSystem()
|
||||
: WAL::System({typeid(PositionComponent), typeid(Drawable3DComponent<T>)}),
|
||||
_window(window)
|
||||
{
|
||||
}
|
||||
_window(RAY::Window::getInstance())
|
||||
{}
|
||||
|
||||
//! @brief Update the corresponding component of the given entity
|
||||
//! @param entity The entity to update.
|
||||
|
||||
+18
-18
@@ -50,13 +50,12 @@ int demo()
|
||||
WAL::Wal wal;
|
||||
const int screenWidth = 800;
|
||||
const int screenHeight = 450;
|
||||
std::vector<std::string>::const_iterator iterator = textures.begin();
|
||||
auto iterator = textures.begin();
|
||||
const std::string modelPath = "assets/player/player.iqm";
|
||||
RAY::TraceLog::setLevel(LOG_WARNING);
|
||||
RAY::Window &window = RAY::Window::getInstance(screenWidth, screenHeight, "Bidibidibop", FLAG_WINDOW_RESIZABLE);
|
||||
RAY::Image icon("assets/icon.png");
|
||||
RAY::Vector3 position(0.0f, 0.0f, 0.0f); // Set model position
|
||||
RAY::Drawables::Drawables3D::Model model(modelPath, position, RAY::Vector3(1.0f, 20, 0.0f), -180.0f, RAY::Vector3( 3.0f, 3.0f, 3.0f ));
|
||||
RAY::Drawables::Drawables3D::Model model(modelPath, std::pair(MAP_DIFFUSE, "assets/player/blue.png"));
|
||||
RAY::Camera::Camera3D camera(RAY::Vector3(10.0f, 10.0f, 10.0f),
|
||||
RAY::Vector3(0.0f, 0.0f, 0.0f),
|
||||
RAY::Vector3(0.0f, 1.0f, 0.0f),
|
||||
@@ -66,18 +65,19 @@ int demo()
|
||||
RAY::Drawables::Drawables3D::Circle circle({0, 0, 0}, 5, MAROON, {0, 0, 0}, 0);
|
||||
BBM::Drawable3DComponent<RAY::Drawables::Drawables3D::Circle> circleComponent(entityPlayer, circle);
|
||||
|
||||
BBM::Renderer3DSystem<RAY::Drawables::Drawables3D::Circle> circleSystem(window);
|
||||
BBM::Renderer3DSystem<RAY::Drawables::Drawables3D::Circle> circleSystem;
|
||||
|
||||
wal.addSystem(circleSystem);
|
||||
entityPlayer.addComponent(circleComponent);
|
||||
|
||||
RAY::Texture texture(get_full_path(*iterator));
|
||||
// RAY::Texture texture(get_full_path(*iterator));
|
||||
RAY::ModelAnimations animations(modelPath);
|
||||
RAY::Drawables::Drawables3D::Grid grid(10, 1.0f);
|
||||
RAY::Drawables::Drawables2D::Text instructionText("PRESS SPACE to PLAY MODEL ANIMATION", 10, {10, 20} , MAROON);
|
||||
size_t animationIndex = 0;
|
||||
RAY::Vector3 position(0.0f, 0.0f, 0.0f); // Set model position
|
||||
|
||||
model.setTextureToMaterial(MAP_DIFFUSE, texture);
|
||||
// model.setTextureToMaterial(MAP_DIFFUSE, texture);
|
||||
window.setIcon(icon);
|
||||
camera.setMode(CAMERA_FREE); // Set free camera mode
|
||||
|
||||
@@ -99,9 +99,9 @@ int demo()
|
||||
++iterator;
|
||||
if (iterator == textures.end())
|
||||
iterator = textures.begin();
|
||||
texture.unload();
|
||||
texture.load(get_full_path(*iterator));
|
||||
model.setTextureToMaterial(MAP_DIFFUSE, texture);
|
||||
// texture.unload();
|
||||
// texture.load(get_full_path(*iterator));
|
||||
// model.setTextureToMaterial(MAP_DIFFUSE, texture);
|
||||
}
|
||||
if (RAY::Controller::Keyboard::isReleased(KEY_LEFT))
|
||||
{
|
||||
@@ -113,17 +113,17 @@ int demo()
|
||||
animationIndex = ++animationIndex % animations.getAnimationsCount();
|
||||
model.setAnimation(animations[animationIndex]);
|
||||
}
|
||||
// window.setDrawingState(RAY::Window::DRAWING);
|
||||
window.clear();
|
||||
window.useCamera(camera);
|
||||
window.draw();
|
||||
window.clear();
|
||||
window.useCamera(camera);
|
||||
|
||||
window.draw(model);
|
||||
model.drawOn(window);//, position, RAY::Vector3(1.0f, 20, 0.0f), -180.0f, RAY::Vector3( 3.0f, 3.0f, 3.0f ));
|
||||
|
||||
window.draw(grid);
|
||||
window.draw(circle);
|
||||
window.unuseCamera();
|
||||
window.draw(instructionText);
|
||||
// window.setDrawingState(RAY::Window::IDLE);
|
||||
window.draw(grid);
|
||||
window.draw(circle);
|
||||
window.unuseCamera();
|
||||
window.draw(instructionText);
|
||||
window.draw();
|
||||
}
|
||||
window.close();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user